diff --git a/README.md b/README.md
index 7d09808..ddefb70 100644
--- a/README.md
+++ b/README.md
@@ -32,12 +32,16 @@ php start.php start
## 页面与站点设计
- 在「页面」新建空白草稿或从整页模板创建。画布支持编辑、媒体拖拽调整宽度、移动端预览、区块复制与删除。
-- 「图层」中可定位、移动或移除独立区块,保存页面后生效。选中元素可编辑四边的内外边距。选择一段文字后可修改字号、粗体、斜体和删除线。Enter 或 Shift+Enter 在原区块内换行。画布支持撤销与重做,快捷键为 Ctrl/⌘+Z 和 Ctrl/⌘+Shift+Z。
+- 「图层」可定位或移除首屏,也可调整独立区块的顺序。保存页面后生效。移除的首屏可通过撤销或「页面设置 → 页面显示」恢复。
+- 选中元素可编辑四边的内外边距。选中文字后可修改字号、粗体、斜体和删除线。Enter 或 Shift+Enter 在当前元素内换行。正文用 Ctrl+Enter(macOS 上为 ⌘+Enter)或工具栏「换段」新建段落,列表中则新增列表项。
+- 画布支持 Ctrl/⌘+Z 撤销和 Ctrl/⌘+Shift+Z 重做。页面设置的输入框保留浏览器原生撤销。
- 选中按钮后可复制。在「属性」中选择纯色填充、线框、下划线或无样式,并选择是否在新标签页打开。首屏支持最多八个按钮。
- 「站点设计」中可以保存多套页头、页脚和配色。选择布局模板后,可以勾选并排序标识、导航、按钮、文字、版权或用户区组件,填入各组件内容。页头和页脚可以设为站点默认。每页可覆盖这两个默认项、选择配色,或独立隐藏页头和页脚。
- 媒体库和媒体选择器只列出用户上传文件。编辑器图标、示例资产、字体、模板缩略图和产品标识随程序发布。
- 发布后的站点具备独立标题、描述、canonical、Open Graph、站点地图和 robots.txt。可在「站点设置」配置站点名称和静态资源 CDN。
+画布样式以白名单 CSS 类保存。间距与字号使用限定范围内的整数,服务端生成带版本指纹的样式表,画布和使用这些类的公开页按需加载。内容经过 HTML 清理,内联 `style` 属性会被移除。
+
### 会员页头
在「站点设计 → 页头」选择「会员导航」并勾选「用户区」,即可设置认证。将配置好的页头用作默认,或应用于需要登录的页面。
diff --git a/app/Content/CanvasStyle.php b/app/Content/CanvasStyle.php
index 4b0766c..a28bfaa 100644
--- a/app/Content/CanvasStyle.php
+++ b/app/Content/CanvasStyle.php
@@ -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) {
diff --git a/app/Content/Repository.php b/app/Content/Repository.php
index 527966f..b19d3e8 100644
--- a/app/Content/Repository.php
+++ b/app/Content/Repository.php
@@ -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
diff --git a/app/Content/SiteBackup.php b/app/Content/SiteBackup.php
index f177b09..73dfb64 100644
--- a/app/Content/SiteBackup.php
+++ b/app/Content/SiteBackup.php
@@ -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)
diff --git a/app/Controller/AdminController.php b/app/Controller/AdminController.php
index 1288784..50f1fbd 100644
--- a/app/Controller/AdminController.php
+++ b/app/Controller/AdminController.php
@@ -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'])) {
diff --git a/app/view/admin-page.php b/app/view/admin-page.php
index 57e3b34..3c62964 100644
--- a/app/view/admin-page.php
+++ b/app/view/admin-page.php
@@ -1,5 +1,6 @@
+
@@ -140,7 +142,7 @@ $previewUrl = '/admin/pages/' . $slug . '/preview';
-
+
首屏与目录
diff --git a/app/view/layout.php b/app/view/layout.php
index b2b9e79..d69bfe8 100644
--- a/app/view/layout.php
+++ b/app/view/layout.php
@@ -1,6 +1,7 @@
-
+
diff --git a/app/view/page.php b/app/view/page.php
index 5cbe92a..f3791de 100644
--- a/app/view/page.php
+++ b/app/view/page.php
@@ -17,7 +17,7 @@ $field = static fn (string $name): string => $canvas ? ' data-studio-field="' .
?>
= $e($page['name']) ?>
->
+= $styleField('hero') ?>>
= $showHero ? '' : ' hidden' ?>>
diff --git a/public/assets/studio.js b/public/assets/studio.js
index 8e8cbfd..8c4cdfd 100644
--- a/public/assets/studio.js
+++ b/public/assets/studio.js
@@ -779,7 +779,7 @@ jQuery(function ($) {
});
});
} else {
- const commands = {heading: ['formatBlock', 'h3'], list: ['insertUnorderedList']};
+ const commands = {heading: ['formatBlock', 'h3'], paragraph: ['insertParagraph'], list: ['insertUnorderedList']};
edit(...commands[command]);
}
});
@@ -1214,10 +1214,11 @@ jQuery(function ($) {
syncAlignmentButtons(aligned);
$elementTools.find('[data-element-copy]').prop('hidden', !canCopy);
const sectionRoot = node.hasAttribute('data-studio-section');
- const deleteLabel = node.dataset.studioField === 'heading' ? '删除首屏'
+ const hero = node.hasAttribute('data-studio-hero') && isHeroVisible();
+ const deleteLabel = hero || node.dataset.studioField === 'heading' ? '删除首屏'
: node.dataset.studioPart === 'title' || sectionRoot ? '删除区块' : '删除';
$elementTools.find('[data-element-delete]').attr({'aria-label': deleteLabel, title: deleteLabel})
- .prop('hidden', !sectionRoot && !inBody && !selectedMedia && !node.matches(canvasFields));
+ .prop('hidden', !hero && !sectionRoot && !inBody && !selectedMedia && !node.matches(canvasFields));
$elementTools.find('[data-element-properties]').prop('hidden', !hasProperties);
if (target) showMediaWidth(currentMediaWidth(target));
selectionObserver?.observe(target || aligned || node);
@@ -1234,9 +1235,8 @@ jQuery(function ($) {
return;
}
const {studioField, studioAction, studioNavIndex} = node.dataset;
- if (!copy && studioField === 'heading') {
- pageInput('show_hero').val('0').trigger('change');
- $studio.find('[data-canvas-status]').text('首屏已移除,可在页面设置中恢复。');
+ if (!copy && (studioField === 'heading' || node.hasAttribute('data-studio-hero'))) {
+ removeHero();
return;
}
if (!copy && node.dataset.studioPart === 'title') {
@@ -1352,6 +1352,30 @@ jQuery(function ($) {
$layers.children().filter((_, node) => node.dataset.layerKey === section.key).find('[data-layer-title]').text(title);
}
+ function isHeroVisible() {
+ return pageInput('show_hero').val() === '1';
+ }
+
+ function removeHero() {
+ if (!isHeroVisible()) return;
+ selectBody(null);
+ textHost = null;
+ textRange = null;
+ doc.getSelection().removeAllRanges();
+ pageInput('show_hero').val('0').trigger('change');
+ $studio.find('[data-canvas-status]').text('首屏已移除,可撤销或在页面设置中恢复。');
+ }
+
+ function locateLayer(node, body = null) {
+ doc.getSelection().removeAllRanges();
+ textRange = null;
+ textHost = null;
+ selectBody(body);
+ $studio.get(0).scrollIntoView({block: 'start'});
+ node.scrollIntoView({block: 'start'});
+ selectElement(node);
+ }
+
function renderLayers() {
const eligible = sections.filter(({fixed}) => !fixed);
const button = (label, operation, disabled = false) => $('