forked from laysense/laysite
Add visual header and footer layout editors
This commit is contained in:
@@ -36,7 +36,7 @@ php start.php start
|
|||||||
- 选中元素可编辑四边的内外边距。选中文字后可修改字号、粗体、斜体和删除线。Enter 或 Shift+Enter 在当前元素内换行。正文用 Ctrl+Enter(macOS 上为 ⌘+Enter)或工具栏「换段」新建段落,列表中则新增列表项。
|
- 选中元素可编辑四边的内外边距。选中文字后可修改字号、粗体、斜体和删除线。Enter 或 Shift+Enter 在当前元素内换行。正文用 Ctrl+Enter(macOS 上为 ⌘+Enter)或工具栏「换段」新建段落,列表中则新增列表项。
|
||||||
- 画布支持 Ctrl/⌘+Z 撤销和 Ctrl/⌘+Shift+Z 重做。页面设置的输入框保留浏览器原生撤销。
|
- 画布支持 Ctrl/⌘+Z 撤销和 Ctrl/⌘+Shift+Z 重做。页面设置的输入框保留浏览器原生撤销。
|
||||||
- 选中按钮后可复制。在「属性」中选择纯色填充、线框、下划线或无样式,并选择是否在新标签页打开。首屏支持最多八个按钮。
|
- 选中按钮后可复制。在「属性」中选择纯色填充、线框、下划线或无样式,并选择是否在新标签页打开。首屏支持最多八个按钮。
|
||||||
- 「站点设计」中可以保存多套页头、页脚和配色。选择布局模板后,可以勾选并排序标识、导航、按钮、文字、版权或用户区组件,填入各组件内容。页头和页脚可以设为站点默认。每页可覆盖这两个默认项、选择配色,或独立隐藏页头和页脚。
|
- 「站点设计」中可以保存多套页头、页脚和配色。页头页脚编辑器提供布局预览卡和桌面、手机画布。可直接修改画布文字,在组件面板开启或排序组件,设置图片、链接和用户区。页头和页脚可以设为站点默认。每页可覆盖默认项、选择配色,或独立隐藏页头和页脚。页面编辑器里的「编辑页头/编辑页脚」会打开当前方案的画布。
|
||||||
- 媒体库和媒体选择器只列出用户上传文件。编辑器图标、示例资产、字体、模板缩略图和产品标识随程序发布。
|
- 媒体库和媒体选择器只列出用户上传文件。编辑器图标、示例资产、字体、模板缩略图和产品标识随程序发布。
|
||||||
- 发布后的站点具备独立标题、描述、canonical、Open Graph、站点地图和 robots.txt。可在「站点设置」配置站点名称和静态资源 CDN。
|
- 发布后的站点具备独立标题、描述、canonical、Open Graph、站点地图和 robots.txt。可在「站点设置」配置站点名称和静态资源 CDN。
|
||||||
|
|
||||||
|
|||||||
@@ -125,7 +125,11 @@ final class DesignLibrary
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
$clean['components'] = array_values(array_unique($components));
|
$clean['components'] = array_values(array_unique($components));
|
||||||
|
try {
|
||||||
$clean['links'] = Buttons::validate($data['links'] ?? $clean['links'], 20);
|
$clean['links'] = Buttons::validate($data['links'] ?? $clean['links'], 20);
|
||||||
|
} catch (RuntimeException $error) {
|
||||||
|
throw new DesignFieldError('links', $error->getMessage());
|
||||||
|
}
|
||||||
try {
|
try {
|
||||||
$clean['action'] = Buttons::validate($data['action'] ?? []);
|
$clean['action'] = Buttons::validate($data['action'] ?? []);
|
||||||
} catch (RuntimeException $error) {
|
} catch (RuntimeException $error) {
|
||||||
|
|||||||
@@ -319,6 +319,7 @@ class AdminController
|
|||||||
return $this->render($request, 'admin-page', [
|
return $this->render($request, 'admin-page', [
|
||||||
'title' => '编辑 ' . $page['name'], 'page' => $page, 'categories' => $repo->categories(), 'wideAdmin' => true, 'error' => $error, 'saved' => $request->get('saved') === '1',
|
'title' => '编辑 ' . $page['name'], 'page' => $page, 'categories' => $repo->categories(), 'wideAdmin' => true, 'error' => $error, 'saved' => $request->get('saved') === '1',
|
||||||
'pageTemplateDrawer' => true, 'designs' => DesignLibrary::all(),
|
'pageTemplateDrawer' => true, 'designs' => DesignLibrary::all(),
|
||||||
|
'layoutDefaults' => array_intersect_key($repo->site(), ['header_id' => true, 'footer_id' => true]),
|
||||||
], $error !== '' ? 422 : 200);
|
], $error !== '' ? 422 : 200);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|||||||
@@ -43,7 +43,8 @@ final class DesignController extends AdminController
|
|||||||
$field = '';
|
$field = '';
|
||||||
$secret = '';
|
$secret = '';
|
||||||
$links = SiteDesign::linkText($item['payload']['links'] ?? []);
|
$links = SiteDesign::linkText($item['payload']['links'] ?? []);
|
||||||
$default = $id !== null && ((new Repository())->site()[$kind . '_id'] ?? null) === $id;
|
$site = (new Repository())->site();
|
||||||
|
$default = $id === null ? $request->get('default') === '1' : ($site[$kind . '_id'] ?? null) === $id;
|
||||||
if ($request->method() === 'POST') {
|
if ($request->method() === 'POST') {
|
||||||
try {
|
try {
|
||||||
$savedProvider = $item['payload']['provider'] ?? [];
|
$savedProvider = $item['payload']['provider'] ?? [];
|
||||||
@@ -73,12 +74,21 @@ final class DesignController extends AdminController
|
|||||||
}
|
}
|
||||||
$secret = $this->input($request, 'provider_secret', trimValue: false);
|
$secret = $this->input($request, 'provider_secret', trimValue: false);
|
||||||
}
|
}
|
||||||
|
if ($request->post('canvas_links') !== null) {
|
||||||
|
$draftLinks = json_decode($this->input($request, 'canvas_links'), true);
|
||||||
|
if (!is_array($draftLinks) || !array_is_list($draftLinks)
|
||||||
|
|| array_filter($draftLinks, 'is_array') !== $draftLinks) {
|
||||||
|
throw new DesignFieldError('links', '导航链接格式无效。');
|
||||||
|
}
|
||||||
|
$item['payload']['links'] = $draftLinks;
|
||||||
|
} else {
|
||||||
try {
|
try {
|
||||||
$item['payload']['links'] = SiteDesign::parseLinks($links);
|
$item['payload']['links'] = SiteDesign::parseLinks($links);
|
||||||
} catch (RuntimeException $ex) {
|
} catch (RuntimeException $ex) {
|
||||||
throw new DesignFieldError('links', $ex->getMessage());
|
throw new DesignFieldError('links', $ex->getMessage());
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
}
|
||||||
$id = DesignLibrary::save($kind, $id, $item['name'], $item['preset'], $item['payload'], $item['version'], $default, $secret);
|
$id = DesignLibrary::save($kind, $id, $item['name'], $item['preset'], $item['payload'], $item['version'], $default, $secret);
|
||||||
|
|
||||||
return $this->success($request, "/admin/design/$kind/$id?saved=1");
|
return $this->success($request, "/admin/design/$kind/$id?saved=1");
|
||||||
@@ -98,6 +108,7 @@ final class DesignController extends AdminController
|
|||||||
return $this->render($request, 'admin-design-edit', [
|
return $this->render($request, 'admin-design-edit', [
|
||||||
'title' => '设计配置', 'kind' => $kind, 'key' => $key, 'item' => $item, 'default' => $default,
|
'title' => '设计配置', 'kind' => $kind, 'key' => $key, 'item' => $item, 'default' => $default,
|
||||||
'error' => $error, 'field' => $field, 'links' => $links, 'reenterSecret' => $error !== '' && $secret !== '',
|
'error' => $error, 'field' => $field, 'links' => $links, 'reenterSecret' => $error !== '' && $secret !== '',
|
||||||
|
'layoutEditor' => $kind !== 'palette', 'wideAdmin' => $kind !== 'palette', 'siteName' => $site['name'],
|
||||||
'saved' => $error === '' && $request->get('saved') === '1',
|
'saved' => $error === '' && $request->get('saved') === '1',
|
||||||
], $error === '' ? 200 : 422);
|
], $error === '' ? 200 : 422);
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -1,5 +1,6 @@
|
|||||||
<?php
|
<?php
|
||||||
use App\Content\Buttons;
|
use App\Content\Buttons;
|
||||||
|
use App\Content\Database;
|
||||||
use App\Content\DesignLibrary;
|
use App\Content\DesignLibrary;
|
||||||
use App\Content\View;
|
use App\Content\View;
|
||||||
|
|
||||||
@@ -23,80 +24,133 @@ $fieldError = static function (string $name) use ($errorId, $field, $error, $e):
|
|||||||
<?php if ($key !== 'new'): ?><a class="button button-outline" href="/admin/design/<?= $e($kind) ?>/<?= $e($key) ?>/preview" target="_blank" rel="noopener noreferrer">预览已保存的配置</a><?php endif ?>
|
<?php if ($key !== 'new'): ?><a class="button button-outline" href="/admin/design/<?= $e($kind) ?>/<?= $e($key) ?>/preview" target="_blank" rel="noopener noreferrer">预览已保存的配置</a><?php endif ?>
|
||||||
</header>
|
</header>
|
||||||
<?= View::fragment('admin-feedback', ['error' => $field === '' ? $error : '', 'saved' => $saved]) ?>
|
<?= View::fragment('admin-feedback', ['error' => $field === '' ? $error : '', 'saved' => $saved]) ?>
|
||||||
<form class="admin-form admin-panel" method="post" action="/admin/design/<?= $e($kind) ?>/<?= $e($key) ?>">
|
<form class="admin-form<?= $layoutEditor ? ' design-editor' : ' admin-panel' ?>" method="post"
|
||||||
|
action="/admin/design/<?= $e($kind) ?>/<?= $e($key) ?>"<?= $layoutEditor ? ' data-layout-editor="' . $e($kind) . '" data-site-name="' . $e($siteName) . '"' : '' ?>>
|
||||||
<input type="hidden" name="csrf" value="<?= $e($token) ?>">
|
<input type="hidden" name="csrf" value="<?= $e($token) ?>">
|
||||||
<input type="hidden" name="version" value="<?= $e($item['version']) ?>">
|
<input type="hidden" name="version" value="<?= $e($item['version']) ?>">
|
||||||
<label>配置名称<input name="name" maxlength="100" value="<?= $e($item['name']) ?>" required<?= $describe('name') ?>><?php $fieldError('name'); ?></label>
|
|
||||||
<label>布局模板<select name="preset" data-layout-preset<?= $describe('preset') ?>>
|
|
||||||
<?php foreach (DesignLibrary::PRESETS[$kind] as $preset => $label): ?>
|
|
||||||
<option value="<?= $e($preset) ?>" <?= $preset === $item['preset'] ? 'selected' : '' ?>><?= $e($label) ?></option>
|
|
||||||
<?php endforeach ?>
|
|
||||||
</select><?php $fieldError('preset'); ?></label>
|
|
||||||
<?php if ($kind === 'palette'): ?>
|
<?php if ($kind === 'palette'): ?>
|
||||||
|
<label>配置名称<input name="name" maxlength="100" value="<?= $e($item['name']) ?>" required<?= $describe('name') ?>><?php $fieldError('name'); ?></label>
|
||||||
|
<input type="hidden" name="preset" value="custom">
|
||||||
|
<?php $fieldError('preset'); ?>
|
||||||
<div class="palette-fields">
|
<div class="palette-fields">
|
||||||
<?php foreach (DesignLibrary::COLORS as $color => [$label, $fallback]): ?>
|
<?php foreach (DesignLibrary::COLORS as $color => [$label, $fallback]): ?>
|
||||||
<label><?= $e($label) ?><input type="<?= $field === $color ? 'text' : 'color' ?>" name="<?= $e($color) ?>" value="<?= $e($data[$color] ?? $fallback) ?>"<?= $describe($color) ?>><?php $fieldError($color); ?></label>
|
<label><?= $e($label) ?><input type="<?= $field === $color ? 'text' : 'color' ?>" name="<?= $e($color) ?>" value="<?= $e($data[$color] ?? $fallback) ?>"<?= $describe($color) ?>><?php $fieldError($color); ?></label>
|
||||||
<?php endforeach ?>
|
<?php endforeach ?>
|
||||||
</div>
|
</div>
|
||||||
|
<div class="form-submit"><button type="submit" class="button button-primary">保存配置</button></div>
|
||||||
<?php else: ?>
|
<?php else: ?>
|
||||||
<fieldset class="admin-options"<?= $describe('components') ?>><legend>组件及顺序</legend>
|
<div class="admin-panel design-editor-bar">
|
||||||
|
<label>配置名称<input name="name" maxlength="100" value="<?= $e($item['name']) ?>" required<?= $describe('name') ?>><?php $fieldError('name'); ?></label>
|
||||||
|
<label><input type="checkbox" name="make_default" value="1" <?= $default ? 'checked' : '' ?>> 用作站点默认<?= $kind === 'header' ? '页头' : '页脚' ?></label>
|
||||||
|
<button type="submit" class="button button-primary">保存配置</button>
|
||||||
|
</div>
|
||||||
|
<div class="design-editor-grid">
|
||||||
|
<div class="design-editor-main">
|
||||||
|
<section class="admin-panel design-canvas" data-layout-workspace hidden aria-labelledby="design-canvas-title">
|
||||||
|
<div class="admin-heading compact">
|
||||||
|
<h2 id="design-canvas-title">编辑画布</h2>
|
||||||
|
<div class="preview-selector" role="group" aria-label="预览尺寸">
|
||||||
|
<button type="button" class="button button-outline" data-layout-viewport="desktop" aria-pressed="true">桌面</button>
|
||||||
|
<button type="button" class="button button-outline" data-layout-viewport="phone" aria-pressed="false">手机</button>
|
||||||
|
</div>
|
||||||
|
</div>
|
||||||
|
<div class="design-canvas-stage">
|
||||||
|
<div class="design-canvas-viewport">
|
||||||
|
<iframe data-layout-frame sandbox="allow-same-origin" title="可编辑的<?= $kind === 'header' ? '页头' : '页脚' ?>画布"
|
||||||
|
srcdoc="<?= $e(View::fragment('design-layout-document', ['kind' => $kind, 'preset' => array_key_first(DesignLibrary::PRESETS[$kind]), 'layoutEditor' => true])) ?>"></iframe>
|
||||||
|
</div>
|
||||||
|
<p class="field-note" data-layout-empty hidden>勾选组件,添加到画布。</p>
|
||||||
|
</div>
|
||||||
|
<p class="field-note">点击画布中的文字可直接修改。链接、图片和用户区在组件面板设置。</p>
|
||||||
|
</section>
|
||||||
|
<fieldset class="admin-panel design-templates"<?= $describe('preset') ?>>
|
||||||
|
<legend>布局模板</legend>
|
||||||
|
<div class="design-template-grid">
|
||||||
|
<?php foreach (DesignLibrary::PRESETS[$kind] as $preset => $label): ?>
|
||||||
|
<label class="design-template-choice">
|
||||||
|
<span class="design-template-image">
|
||||||
|
<iframe aria-hidden="true" tabindex="-1" inert title="<?= $e($label) ?>缩略预览" sandbox
|
||||||
|
srcdoc="<?= $e(View::fragment('design-layout-document', ['kind' => $kind, 'preset' => $preset, 'layoutEditor' => false])) ?>"></iframe>
|
||||||
|
</span>
|
||||||
|
<span class="design-template-caption"><input type="radio" name="preset" value="<?= $e($preset) ?>" data-layout-preset required <?= $preset === $item['preset'] ? 'checked' : '' ?>><?= $e($label) ?></span>
|
||||||
|
</label>
|
||||||
|
<?php endforeach ?>
|
||||||
|
</div>
|
||||||
|
<?php $fieldError('preset'); ?>
|
||||||
|
</fieldset>
|
||||||
|
</div>
|
||||||
|
<aside class="admin-panel design-editor-inspector" aria-label="组件和属性">
|
||||||
|
<fieldset class="admin-options design-component-panel"<?= $describe('components') ?>>
|
||||||
|
<legend>组件</legend>
|
||||||
<ul class="admin-list layout-components" data-layout-components>
|
<ul class="admin-list layout-components" data-layout-components>
|
||||||
<?php foreach (array_unique([...$data['components'], ...array_keys(DesignLibrary::COMPONENTS[$kind])]) as $component): ?>
|
<?php foreach (array_unique([...$data['components'], ...array_keys(DesignLibrary::COMPONENTS[$kind])]) as $component): ?>
|
||||||
<li><label><input type="checkbox" name="components[]" value="<?= $e($component) ?>" <?= in_array($component, $data['components'], true) ? 'checked' : '' ?>><?= $e(DesignLibrary::COMPONENTS[$kind][$component]) ?></label>
|
<li data-layout-layer="<?= $e($component) ?>">
|
||||||
<div class="actions"><button type="button" class="button button-outline" data-component-move="-1">上移</button><button type="button" class="button button-outline" data-component-move="1">下移</button></div></li>
|
<label><input type="checkbox" name="components[]" value="<?= $e($component) ?>" <?= in_array($component, $data['components'], true) ? 'checked' : '' ?>><?= $e(DesignLibrary::COMPONENTS[$kind][$component]) ?></label>
|
||||||
|
<div class="actions">
|
||||||
|
<button type="button" class="button button-outline" data-layout-select="<?= $e($component) ?>" aria-label="编辑<?= $e(DesignLibrary::COMPONENTS[$kind][$component]) ?>" title="编辑<?= $e(DesignLibrary::COMPONENTS[$kind][$component]) ?>" hidden><?= View::fragment('studio-icon', ['icon' => 'edit']) ?></button>
|
||||||
|
<button type="button" class="button button-outline" data-component-move="-1" aria-label="上移<?= $e(DesignLibrary::COMPONENTS[$kind][$component]) ?>" title="上移">↑</button>
|
||||||
|
<button type="button" class="button button-outline" data-component-move="1" aria-label="下移<?= $e(DesignLibrary::COMPONENTS[$kind][$component]) ?>" title="下移">↓</button>
|
||||||
|
</div>
|
||||||
|
</li>
|
||||||
<?php endforeach ?>
|
<?php endforeach ?>
|
||||||
</ul>
|
</ul>
|
||||||
<?php $fieldError('components'); ?>
|
<?php $fieldError('components'); ?>
|
||||||
</fieldset>
|
</fieldset>
|
||||||
<div class="form-grid">
|
<fieldset class="admin-options design-properties" data-layout-panel="brand">
|
||||||
|
<legend>站点标识</legend>
|
||||||
<label>品牌名称<input name="brand" maxlength="100" value="<?= $e($data['brand']) ?>"<?= $describe('brand') ?>><?php $fieldError('brand'); ?></label>
|
<label>品牌名称<input name="brand" maxlength="100" value="<?= $e($data['brand']) ?>"<?= $describe('brand') ?>><?php $fieldError('brand'); ?></label>
|
||||||
<div>
|
<div>
|
||||||
<?= View::fragment('studio-asset-field', ['name' => 'logo', 'label' => '品牌图片', 'value' => $data['logo'],
|
<?= View::fragment('studio-asset-field', ['name' => 'logo', 'label' => '品牌图片', 'value' => $data['logo'],
|
||||||
'describedBy' => $errorId('logo'), 'invalid' => $field === 'logo']) ?>
|
'describedBy' => $errorId('logo'), 'invalid' => $field === 'logo']) ?>
|
||||||
<?php $fieldError('logo'); ?>
|
<?php $fieldError('logo'); ?>
|
||||||
</div>
|
</div>
|
||||||
|
</fieldset>
|
||||||
|
<fieldset class="admin-options design-properties" data-layout-panel="links"<?= $describe('links') ?>>
|
||||||
|
<legend><?= $kind === 'header' ? '导航链接' : '页脚链接' ?></legend>
|
||||||
|
<label data-layout-legacy-links>链接列表<textarea name="links" rows="4"<?= $describe('links') ?>><?= $e($links) ?></textarea><small>每行填写「名称 | 链接」。</small></label>
|
||||||
|
<input type="hidden" name="canvas_links" value="<?= $e(Database::json($data['links'] ?? [])) ?>" disabled>
|
||||||
|
<div data-layout-link-editor hidden>
|
||||||
|
<div class="design-link-rows" data-layout-link-rows></div>
|
||||||
|
<button class="button button-outline" type="button" data-layout-link-add>添加链接</button>
|
||||||
|
<template data-layout-link-template>
|
||||||
|
<div class="design-link-row">
|
||||||
|
<label>文案<input maxlength="70" data-layout-link-field="1"></label>
|
||||||
|
<label>地址<input maxlength="1000" data-layout-link-field="0" placeholder="/articles"></label>
|
||||||
|
<div class="design-link-controls">
|
||||||
|
<button class="button button-outline" type="button" data-layout-link-move="-1" title="上移链接" aria-label="上移链接">↑</button>
|
||||||
|
<button class="button button-outline" type="button" data-layout-link-move="1" title="下移链接" aria-label="下移链接">↓</button>
|
||||||
|
<button class="button button-outline" type="button" data-layout-link-remove title="删除链接" aria-label="删除链接"><?= View::fragment('studio-icon', ['icon' => 'delete']) ?></button>
|
||||||
</div>
|
</div>
|
||||||
<label>链接列表<textarea name="links" rows="4"<?= $describe('links') ?>><?= $e($links) ?></textarea><small>每行填写「名称 | 链接」。</small><?php $fieldError('links'); ?></label>
|
</div>
|
||||||
|
</template>
|
||||||
|
</div>
|
||||||
|
<?php $fieldError('links'); ?>
|
||||||
|
</fieldset>
|
||||||
<?php if ($kind === 'header'): ?>
|
<?php if ($kind === 'header'): ?>
|
||||||
<fieldset class="admin-options form-grid"<?= $describe('action') ?>><legend>行动按钮</legend>
|
<fieldset class="admin-options design-properties" data-layout-panel="action"<?= $describe('action') ?>>
|
||||||
|
<legend>行动按钮</legend>
|
||||||
<label>文案<input name="action_label" maxlength="70" value="<?= $e($action[1] ?? '') ?>"></label>
|
<label>文案<input name="action_label" maxlength="70" value="<?= $e($action[1] ?? '') ?>"></label>
|
||||||
<label>链接<input name="action_url" maxlength="1000" value="<?= $e($action[0] ?? '') ?>"></label>
|
<label>链接<input name="action_url" maxlength="1000" value="<?= $e($action[0] ?? '') ?>"></label>
|
||||||
<label>样式<select name="action_style"><?php foreach (Buttons::STYLES as $style => $label): ?>
|
<label>样式<select name="action_style"><?php foreach (Buttons::STYLES as $style => $label): ?>
|
||||||
<option value="<?= $e($style) ?>" <?= ($action[2] ?? 'outline') === $style ? 'selected' : '' ?>><?= $e($label) ?></option>
|
<option value="<?= $e($style) ?>" <?= ($action[2] ?? 'outline') === $style ? 'selected' : '' ?>><?= $e($label) ?></option>
|
||||||
<?php endforeach ?></select></label>
|
<?php endforeach ?></select></label>
|
||||||
<label><span><input type="checkbox" name="action_blank" value="1" <?= !empty($action[3]) ? 'checked' : '' ?>> 在新标签页打开</span></label>
|
<label><input type="checkbox" name="action_blank" value="1" <?= !empty($action[3]) ? 'checked' : '' ?>> 在新标签页打开</label>
|
||||||
<?php $fieldError('action'); ?>
|
<?php $fieldError('action'); ?>
|
||||||
</fieldset>
|
</fieldset>
|
||||||
<fieldset class="admin-options form-grid" data-provider-settings<?= DesignLibrary::hasAccount($item['preset'], $data['components']) ? '' : ' hidden' ?>><legend>用户区认证</legend>
|
<div data-layout-panel="account">
|
||||||
<label>认证方式<select name="provider_mode"<?= $describe('provider_mode') ?>><option value="">关闭</option>
|
<?= View::fragment('design-provider-fields', compact('item', 'provider', 'e', 'describe', 'fieldError', 'reenterSecret', 'field') + ['components' => $data['components']]) ?>
|
||||||
<?php foreach (['oidc' => 'OpenID Connect', 'oauth2' => 'OAuth 2.0 + 用户资料'] as $mode => $label): ?>
|
</div>
|
||||||
<option value="<?= $e($mode) ?>" <?= ($provider['mode'] ?? '') === $mode ? 'selected' : '' ?>><?= $e($label) ?></option>
|
|
||||||
<?php endforeach ?>
|
|
||||||
</select><?php $fieldError('provider_mode'); ?></label>
|
|
||||||
<label data-provider-field>客户端 ID<input name="provider_client_id" value="<?= $e($provider['client_id'] ?? '') ?>"<?= $describe('provider_client_id') ?>><?php $fieldError('provider_client_id'); ?></label>
|
|
||||||
<label data-provider-field>客户端密钥
|
|
||||||
<input type="password" name="provider_secret" maxlength="4096" autocomplete="new-password"<?= $describe('provider_secret') ?>>
|
|
||||||
<?php $fieldError('provider_secret'); ?>
|
|
||||||
<?php if ($reenterSecret && $field !== 'provider_secret'): ?><small>请重新输入本次提交的客户端密钥。</small><?php endif ?>
|
|
||||||
<?php if (!empty($item['credential_revision'])): ?><small>留空会保留已保存的密钥。</small><?php endif ?>
|
|
||||||
</label>
|
|
||||||
<label data-provider-field>令牌端点认证<select name="provider_token_auth"<?= $describe('provider_token_auth') ?>>
|
|
||||||
<?php foreach (['' => '自动', 'client_secret_basic' => 'HTTP Basic', 'client_secret_post' => '表单客户端密钥'] as $method => $label): ?>
|
|
||||||
<option value="<?= $e($method) ?>" <?= ($provider['token_auth'] ?? '') === $method ? 'selected' : '' ?>><?= $e($label) ?></option>
|
|
||||||
<?php endforeach ?>
|
|
||||||
</select><?php $fieldError('provider_token_auth'); ?></label>
|
|
||||||
<label data-provider-field>权限范围<input name="provider_scope" value="<?= $e($provider['scope'] ?? '') ?>" placeholder="openid profile email"<?= $describe('provider_scope') ?>><?php $fieldError('provider_scope'); ?></label>
|
|
||||||
<label data-provider-mode="oidc">OIDC Issuer<input name="provider_issuer" value="<?= $e($provider['issuer'] ?? '') ?>" placeholder="https://id.example.com"<?= $describe('provider_issuer') ?>><?php $fieldError('provider_issuer'); ?></label>
|
|
||||||
<?php foreach (['authorization' => '授权端点', 'token' => '令牌端点', 'userinfo' => '用户资料端点', 'subject_field' => '用户 ID 字段', 'name_field' => '名称字段', 'avatar_field' => '头像字段'] as $providerField => $label): ?>
|
|
||||||
<label data-provider-mode="oauth2"><?= $e($label) ?><input name="provider_<?= $e($providerField) ?>" value="<?= $e($provider[$providerField] ?? '') ?>"<?= $describe('provider_' . $providerField) ?>><?php $fieldError('provider_' . $providerField); ?></label>
|
|
||||||
<?php endforeach ?>
|
|
||||||
<p class="field-note" data-provider-field>回调地址 <code><?= $e(View::absolute('/account/callback')) ?></code></p>
|
|
||||||
</fieldset>
|
|
||||||
<?php else: ?>
|
<?php else: ?>
|
||||||
<label>说明文字<textarea name="text" rows="3"<?= $describe('text') ?>><?= $e($data['text']) ?></textarea><?php $fieldError('text'); ?></label>
|
<fieldset class="admin-options design-properties" data-layout-panel="text">
|
||||||
<label>版权文字<input name="legal" value="<?= $e($data['legal']) ?>"<?= $describe('legal') ?>><?php $fieldError('legal'); ?></label>
|
<legend>说明文字</legend>
|
||||||
|
<label>内容<textarea name="text" rows="3" maxlength="1200"<?= $describe('text') ?>><?= $e($data['text']) ?></textarea><?php $fieldError('text'); ?></label>
|
||||||
|
</fieldset>
|
||||||
|
<fieldset class="admin-options design-properties" data-layout-panel="legal">
|
||||||
|
<legend>版权文字</legend>
|
||||||
|
<label>内容<input name="legal" maxlength="300" value="<?= $e($data['legal']) ?>"<?= $describe('legal') ?>><?php $fieldError('legal'); ?></label>
|
||||||
|
</fieldset>
|
||||||
<?php endif ?>
|
<?php endif ?>
|
||||||
<label><span><input type="checkbox" name="make_default" value="1" <?= $default ? 'checked' : '' ?>> 用作站点默认<?= $kind === 'header' ? '页头' : '页脚' ?></span></label>
|
</aside>
|
||||||
|
</div>
|
||||||
<?php endif ?>
|
<?php endif ?>
|
||||||
<button type="submit" class="button button-primary">保存配置</button>
|
|
||||||
</form>
|
</form>
|
||||||
|
|||||||
@@ -24,6 +24,10 @@ $active = match (true) {
|
|||||||
<script src="/assets/jquery-4.0.0.min.js" defer></script>
|
<script src="/assets/jquery-4.0.0.min.js" defer></script>
|
||||||
<script src="/assets/admin.js" defer></script>
|
<script src="/assets/admin.js" defer></script>
|
||||||
<script src="/assets/studio.js" defer></script>
|
<script src="/assets/studio.js" defer></script>
|
||||||
|
<?php if (!empty($layoutEditor)): ?>
|
||||||
|
<link rel="stylesheet" href="/assets/design-editor.css">
|
||||||
|
<script src="/assets/design-editor.js" defer></script>
|
||||||
|
<?php endif ?>
|
||||||
<?php if (!empty($pageTemplateDrawer)): ?>
|
<?php if (!empty($pageTemplateDrawer)): ?>
|
||||||
<link rel="stylesheet" href="/assets/page-template-drawer.css">
|
<link rel="stylesheet" href="/assets/page-template-drawer.css">
|
||||||
<script src="/assets/page-template-drawer.js" defer></script>
|
<script src="/assets/page-template-drawer.js" defer></script>
|
||||||
|
|||||||
@@ -16,6 +16,11 @@ $previewUrl = '/admin/pages/' . $slug . '/preview';
|
|||||||
<span class="dashboard-page-state" data-published="<?= $page['status'] === 'published' ? 'true' : 'false' ?>"><?= $page['status'] === 'draft' ? '草稿' : '已发布' ?></span></p></div>
|
<span class="dashboard-page-state" data-published="<?= $page['status'] === 'published' ? 'true' : 'false' ?>"><?= $page['status'] === 'draft' ? '草稿' : '已发布' ?></span></p></div>
|
||||||
<div class="actions">
|
<div class="actions">
|
||||||
<a class="button button-outline" href="#studio-page-settings">页面设置</a>
|
<a class="button button-outline" href="#studio-page-settings">页面设置</a>
|
||||||
|
<?php foreach (['header' => '编辑页头', 'footer' => '编辑页脚'] as $kind => $label): ?>
|
||||||
|
<?php $default = $layoutDefaults[$kind . '_id'] ?? ''; $id = $page[$kind . '_id'] ?? $default; ?>
|
||||||
|
<a class="button button-outline" data-page-layout-editor="<?= $kind ?>" data-default-id="<?= $e($default) ?>"
|
||||||
|
href="/admin/design/<?= $kind ?>/<?= $id ? $e($id) : 'new?default=1' ?>" target="_blank" rel="noopener"><?= $label ?></a>
|
||||||
|
<?php endforeach ?>
|
||||||
<button type="button" class="button button-outline" data-open-page-templates hidden>整页模板</button>
|
<button type="button" class="button button-outline" data-open-page-templates hidden>整页模板</button>
|
||||||
<?php if ($page['status'] === 'published'): ?><a class="button button-outline" href="<?= $e($path) ?>">公开页面</a><?php endif ?>
|
<?php if ($page['status'] === 'published'): ?><a class="button button-outline" href="<?= $e($path) ?>">公开页面</a><?php endif ?>
|
||||||
<a class="button button-outline" href="<?= $e($previewUrl) ?>" target="_blank" rel="noopener">打开预览</a>
|
<a class="button button-outline" href="<?= $e($previewUrl) ?>" target="_blank" rel="noopener">打开预览</a>
|
||||||
|
|||||||
@@ -0,0 +1,31 @@
|
|||||||
|
<?php
|
||||||
|
use App\Content\DesignLibrary;
|
||||||
|
use App\Content\View;
|
||||||
|
|
||||||
|
$layout = [
|
||||||
|
'id' => 0,
|
||||||
|
'preset' => $preset,
|
||||||
|
'payload' => array_replace(DesignLibrary::defaults($kind), [
|
||||||
|
'brand' => '品牌名称',
|
||||||
|
'text' => '关于网站的一句话介绍。',
|
||||||
|
'links' => $layoutEditor ? [] : [['/', '首页'], ['/articles', '文章']],
|
||||||
|
'legal' => '© 品牌名称',
|
||||||
|
'action' => [['/articles', '了解更多', 'solid', false]],
|
||||||
|
]),
|
||||||
|
];
|
||||||
|
?>
|
||||||
|
<!doctype html>
|
||||||
|
<html lang="zh-CN">
|
||||||
|
<head>
|
||||||
|
<meta charset="utf-8">
|
||||||
|
<meta name="viewport" content="width=device-width, initial-scale=1">
|
||||||
|
<link rel="stylesheet" href="/assets/site.css">
|
||||||
|
<link rel="stylesheet" href="/assets/design-editor.css">
|
||||||
|
</head>
|
||||||
|
<body class="design-frame <?= $layoutEditor ? 'design-frame-editing' : 'design-frame-sample' ?>">
|
||||||
|
<?= View::fragment($kind, [
|
||||||
|
$kind => $layout, 'site' => ['name' => '品牌名称'], 'showHeader' => true, 'showFooter' => true,
|
||||||
|
'path' => '/', 'visitor' => null, 'member' => $preset === 'member', 'layoutEditor' => $layoutEditor,
|
||||||
|
]) ?>
|
||||||
|
</body>
|
||||||
|
</html>
|
||||||
@@ -0,0 +1,29 @@
|
|||||||
|
<?php
|
||||||
|
use App\Content\DesignLibrary;
|
||||||
|
use App\Content\View;
|
||||||
|
?>
|
||||||
|
<fieldset class="admin-options design-properties" data-provider-settings<?= DesignLibrary::hasAccount($item['preset'], $components) ? '' : ' hidden' ?>><legend>用户区认证</legend>
|
||||||
|
<label>认证方式<select name="provider_mode"<?= $describe('provider_mode') ?>><option value="">关闭</option>
|
||||||
|
<?php foreach (['oidc' => 'OpenID Connect', 'oauth2' => 'OAuth 2.0 + 用户资料'] as $mode => $label): ?>
|
||||||
|
<option value="<?= $e($mode) ?>" <?= ($provider['mode'] ?? '') === $mode ? 'selected' : '' ?>><?= $e($label) ?></option>
|
||||||
|
<?php endforeach ?>
|
||||||
|
</select><?php $fieldError('provider_mode'); ?></label>
|
||||||
|
<label data-provider-field>客户端 ID<input name="provider_client_id" value="<?= $e($provider['client_id'] ?? '') ?>"<?= $describe('provider_client_id') ?>><?php $fieldError('provider_client_id'); ?></label>
|
||||||
|
<label data-provider-field>客户端密钥
|
||||||
|
<input type="password" name="provider_secret" maxlength="4096" autocomplete="new-password"<?= $describe('provider_secret') ?>>
|
||||||
|
<?php $fieldError('provider_secret'); ?>
|
||||||
|
<?php if ($reenterSecret && $field !== 'provider_secret'): ?><small>请重新输入本次提交的客户端密钥。</small><?php endif ?>
|
||||||
|
<?php if (!empty($item['credential_revision'])): ?><small>留空会保留已保存的密钥。</small><?php endif ?>
|
||||||
|
</label>
|
||||||
|
<label data-provider-field>令牌端点认证<select name="provider_token_auth"<?= $describe('provider_token_auth') ?>>
|
||||||
|
<?php foreach (['' => '自动', 'client_secret_basic' => 'HTTP Basic', 'client_secret_post' => '表单客户端密钥'] as $method => $label): ?>
|
||||||
|
<option value="<?= $e($method) ?>" <?= ($provider['token_auth'] ?? '') === $method ? 'selected' : '' ?>><?= $e($label) ?></option>
|
||||||
|
<?php endforeach ?>
|
||||||
|
</select><?php $fieldError('provider_token_auth'); ?></label>
|
||||||
|
<label data-provider-field>权限范围<input name="provider_scope" value="<?= $e($provider['scope'] ?? '') ?>" placeholder="openid profile email"<?= $describe('provider_scope') ?>><?php $fieldError('provider_scope'); ?></label>
|
||||||
|
<label data-provider-mode="oidc">OIDC Issuer<input name="provider_issuer" value="<?= $e($provider['issuer'] ?? '') ?>" placeholder="https://id.example.com"<?= $describe('provider_issuer') ?>><?php $fieldError('provider_issuer'); ?></label>
|
||||||
|
<?php foreach (['authorization' => '授权端点', 'token' => '令牌端点', 'userinfo' => '用户资料端点', 'subject_field' => '用户 ID 字段', 'name_field' => '名称字段', 'avatar_field' => '头像字段'] as $providerField => $label): ?>
|
||||||
|
<label data-provider-mode="oauth2"><?= $e($label) ?><input name="provider_<?= $e($providerField) ?>" value="<?= $e($provider[$providerField] ?? '') ?>"<?= $describe('provider_' . $providerField) ?>><?php $fieldError('provider_' . $providerField); ?></label>
|
||||||
|
<?php endforeach ?>
|
||||||
|
<p class="field-note" data-provider-field>回调地址 <code><?= $e(View::absolute('/account/callback')) ?></code></p>
|
||||||
|
</fieldset>
|
||||||
+11
-8
@@ -4,22 +4,25 @@ use App\Content\View;
|
|||||||
$e = View::escape(...);
|
$e = View::escape(...);
|
||||||
$data = $footer['payload'];
|
$data = $footer['payload'];
|
||||||
$brand = $data['brand'] ?: $site['name'];
|
$brand = $data['brand'] ?: $site['name'];
|
||||||
|
$layoutEditor ??= false;
|
||||||
|
$part = static fn (string $component): string => $layoutEditor ? ' data-layout-component="' . $component . '"' : '';
|
||||||
?>
|
?>
|
||||||
<footer class="site-footer site-footer-<?= $e($footer['preset']) ?>" id="contact"<?= $showFooter ? '' : ' hidden' ?>>
|
<footer class="site-footer site-footer-<?= $e($footer['preset']) ?>" id="contact"<?= $showFooter ? '' : ' hidden' ?>>
|
||||||
<div class="wrap site-footer-components">
|
<div class="wrap site-footer-components">
|
||||||
<?php foreach ($data['components'] as $component): ?>
|
<?php foreach ($data['components'] as $component): ?>
|
||||||
<?php if ($component === 'brand'): ?>
|
<?php if ($component === 'brand'): ?>
|
||||||
<a class="wordmark site-brand" href="/" aria-label="<?= $e($brand) ?>,首页">
|
<a class="wordmark site-brand" href="/" aria-label="<?= $e($brand) ?>,首页"<?= $part('brand') ?>>
|
||||||
<?php if ($data['logo'] !== ''): ?><img src="<?= $e($data['logo']) ?>" alt="<?= $e($brand) ?>" loading="lazy"><?php else: ?><?= $e($brand) ?><?php endif ?>
|
<?php if ($layoutEditor): ?><img alt="" hidden><span data-layout-text="brand"></span>
|
||||||
|
<?php elseif ($data['logo'] !== ''): ?><img src="<?= $e($data['logo']) ?>" alt="<?= $e($brand) ?>" loading="lazy"><?php else: ?><?= $e($brand) ?><?php endif ?>
|
||||||
</a>
|
</a>
|
||||||
<?php elseif ($component === 'text' && $data['text'] !== ''): ?>
|
<?php elseif ($component === 'text' && ($layoutEditor || $data['text'] !== '')): ?>
|
||||||
<p class="site-footer-text"><?= $e($data['text']) ?></p>
|
<p class="site-footer-text"<?= $part('text') ?><?= $layoutEditor ? ' data-layout-text="text"' : '' ?>><?= $e($data['text']) ?></p>
|
||||||
<?php elseif ($component === 'links' && $data['links']): ?>
|
<?php elseif ($component === 'links' && ($layoutEditor || $data['links'])): ?>
|
||||||
<nav class="site-footer-nav" aria-label="页脚导航">
|
<nav class="site-footer-nav" aria-label="页脚导航"<?= $part('links') ?>>
|
||||||
<?php foreach ($data['links'] as [$url, $label]): ?><a href="<?= $e($url) ?>"><?= $e($label) ?></a><?php endforeach ?>
|
<?php foreach ($data['links'] as [$url, $label]): ?><a href="<?= $e($url) ?>"><?= $e($label) ?></a><?php endforeach ?>
|
||||||
</nav>
|
</nav>
|
||||||
<?php elseif ($component === 'legal' && $data['legal'] !== ''): ?>
|
<?php elseif ($component === 'legal' && ($layoutEditor || $data['legal'] !== '')): ?>
|
||||||
<small><?= $e($data['legal']) ?></small>
|
<small<?= $part('legal') ?><?= $layoutEditor ? ' data-layout-text="legal"' : '' ?>><?= $e($data['legal']) ?></small>
|
||||||
<?php endif ?>
|
<?php endif ?>
|
||||||
<?php endforeach ?>
|
<?php endforeach ?>
|
||||||
</div>
|
</div>
|
||||||
|
|||||||
+14
-9
@@ -5,27 +5,32 @@ use App\Content\View;
|
|||||||
$e = View::escape(...);
|
$e = View::escape(...);
|
||||||
$data = $header['payload'];
|
$data = $header['payload'];
|
||||||
$brand = $data['brand'] ?: $site['name'];
|
$brand = $data['brand'] ?: $site['name'];
|
||||||
|
$layoutEditor ??= false;
|
||||||
|
$part = static fn (string $component): string => $layoutEditor ? ' data-layout-component="' . $component . '"' : '';
|
||||||
?>
|
?>
|
||||||
<header class="masthead masthead-<?= $e($header['preset']) ?>"<?= $showHeader ? '' : ' hidden' ?>>
|
<header class="masthead masthead-<?= $e($header['preset']) ?>"<?= $showHeader ? '' : ' hidden' ?>>
|
||||||
<div class="wrap masthead-inner">
|
<div class="wrap masthead-inner">
|
||||||
<?php foreach ($data['components'] as $component): ?>
|
<?php foreach ($data['components'] as $component): ?>
|
||||||
<?php if ($component === 'brand'): ?>
|
<?php if ($component === 'brand'): ?>
|
||||||
<a class="wordmark site-brand" href="/" aria-label="<?= $e($brand) ?>,首页">
|
<a class="wordmark site-brand" href="/" aria-label="<?= $e($brand) ?>,首页"<?= $part('brand') ?>>
|
||||||
<?php if ($data['logo'] !== ''): ?><img src="<?= $e($data['logo']) ?>" alt="<?= $e($brand) ?>"><?php else: ?><?= $e($brand) ?><?php endif ?>
|
<?php if ($layoutEditor): ?><img alt="" hidden><span data-layout-text="brand"></span>
|
||||||
|
<?php elseif ($data['logo'] !== ''): ?><img src="<?= $e($data['logo']) ?>" alt="<?= $e($brand) ?>"><?php else: ?><?= $e($brand) ?><?php endif ?>
|
||||||
</a>
|
</a>
|
||||||
<?php elseif ($component === 'links' && $data['links']): ?>
|
<?php elseif ($component === 'links' && ($layoutEditor || $data['links'])): ?>
|
||||||
|
<?php if (!$layoutEditor): ?>
|
||||||
<button class="menu-toggle" type="button" aria-expanded="false" aria-controls="primary-navigation" hidden>
|
<button class="menu-toggle" type="button" aria-expanded="false" aria-controls="primary-navigation" hidden>
|
||||||
<span></span><span></span><span class="sr-only">菜单</span>
|
<span></span><span></span><span class="sr-only">菜单</span>
|
||||||
</button>
|
</button>
|
||||||
<nav id="primary-navigation" class="primary-nav" aria-label="主导航">
|
<?php endif ?>
|
||||||
|
<nav id="primary-navigation" class="primary-nav" aria-label="主导航"<?= $part('links') ?>>
|
||||||
<?php foreach ($data['links'] as [$url, $label]): ?>
|
<?php foreach ($data['links'] as [$url, $label]): ?>
|
||||||
<a href="<?= $e($url) ?>"<?= $url === $path ? ' aria-current="page"' : '' ?>><?= $e($label) ?></a>
|
<a href="<?= $e($url) ?>"<?= $url === $path ? ' aria-current="page"' : '' ?>><?= $e($label) ?></a>
|
||||||
<?php endforeach ?>
|
<?php endforeach ?>
|
||||||
</nav>
|
</nav>
|
||||||
<?php elseif ($component === 'action' && $data['action']): ?>
|
<?php elseif ($component === 'action' && ($layoutEditor || $data['action'])): ?>
|
||||||
<?php [$url, $label, $style, $blank] = $data['action'][0]; ?>
|
<?php [$url, $label, $style, $blank] = $data['action'][0] ?? ['/', '', 'outline', false]; ?>
|
||||||
<a class="<?= $e(Buttons::css($style)) ?> masthead-action" href="<?= $e($url) ?>"<?= Buttons::target($blank) ?>><?= $e($label) ?></a>
|
<a class="<?= $e(Buttons::css($style)) ?> masthead-action" href="<?= $e($url) ?>"<?= Buttons::target($blank) ?><?= $part('action') ?><?= $layoutEditor ? ' data-layout-text="action_label"' : '' ?>><?= $e($label) ?></a>
|
||||||
<?php elseif ($component === 'account' && $member): ?>
|
<?php elseif ($component === 'account' && ($layoutEditor || $member)): ?>
|
||||||
<?php if ($visitor): ?>
|
<?php if ($visitor): ?>
|
||||||
<a class="site-account" href="/account" aria-label="打开用户中心">
|
<a class="site-account" href="/account" aria-label="打开用户中心">
|
||||||
<?php if ($visitor['avatar'] !== ''): ?><img class="account-avatar" src="<?= $e($visitor['avatar']) ?>" alt="" width="36" height="36"><?php else: ?>
|
<?php if ($visitor['avatar'] !== ''): ?><img class="account-avatar" src="<?= $e($visitor['avatar']) ?>" alt="" width="36" height="36"><?php else: ?>
|
||||||
@@ -33,7 +38,7 @@ $brand = $data['brand'] ?: $site['name'];
|
|||||||
<?php endif ?>
|
<?php endif ?>
|
||||||
</a>
|
</a>
|
||||||
<?php else: ?>
|
<?php else: ?>
|
||||||
<a class="button button-outline site-account" href="/account/login/<?= $e($header['id']) ?>">登录</a>
|
<a class="button button-outline site-account" href="/account/login/<?= $e($header['id']) ?>"<?= $part('account') ?>>登录</a>
|
||||||
<?php endif ?>
|
<?php endif ?>
|
||||||
<?php endif ?>
|
<?php endif ?>
|
||||||
<?php endforeach ?>
|
<?php endforeach ?>
|
||||||
|
|||||||
+20
-3
@@ -15,7 +15,7 @@
|
|||||||
.login-box p { margin-block: .6rem 1.25rem; }
|
.login-box p { margin-block: .6rem 1.25rem; }
|
||||||
.admin-form { display: grid; gap: 1rem; }
|
.admin-form { display: grid; gap: 1rem; }
|
||||||
.admin-form label { display: grid; gap: .4rem; font-weight: 570; color: var(--ink); }
|
.admin-form label { display: grid; gap: .4rem; font-weight: 570; color: var(--ink); }
|
||||||
.admin-form :where(input:not([type=hidden]), select, textarea) {
|
.admin-form :where(input:not([type=hidden], [type=checkbox], [type=radio]), select, textarea) {
|
||||||
background: white;
|
background: white;
|
||||||
color: var(--ink);
|
color: var(--ink);
|
||||||
width: 100%;
|
width: 100%;
|
||||||
@@ -26,6 +26,25 @@
|
|||||||
font-weight: 400;
|
font-weight: 400;
|
||||||
min-height: 44px;
|
min-height: 44px;
|
||||||
}
|
}
|
||||||
|
.admin-body :where(input[type=checkbox], input[type=radio]) {
|
||||||
|
flex: 0 0 auto;
|
||||||
|
inline-size: 1rem;
|
||||||
|
block-size: 1rem;
|
||||||
|
min-block-size: 0;
|
||||||
|
margin: 0;
|
||||||
|
padding: 0;
|
||||||
|
accent-color: var(--accent);
|
||||||
|
vertical-align: middle;
|
||||||
|
}
|
||||||
|
.admin-body :where(label:has(> input[type=checkbox]), label:has(> span > input[type=checkbox]), label > span:has(> input[type=checkbox])) {
|
||||||
|
display: flex;
|
||||||
|
align-items: center;
|
||||||
|
gap: .5rem;
|
||||||
|
}
|
||||||
|
.admin-form label:has(> input[type=checkbox]), .admin-form label:has(> span > input[type=checkbox]) {
|
||||||
|
display: flex;
|
||||||
|
align-items: center;
|
||||||
|
}
|
||||||
.admin-form textarea { resize: vertical; }
|
.admin-form textarea { resize: vertical; }
|
||||||
.admin-form small, .field-note { color: var(--muted); font-size: .875rem; font-weight: 400; }
|
.admin-form small, .field-note { color: var(--muted); font-size: .875rem; font-weight: 400; }
|
||||||
.admin-form .design-field-error { color: #9c252a; grid-column: 1 / -1; }
|
.admin-form .design-field-error { color: #9c252a; grid-column: 1 / -1; }
|
||||||
@@ -324,8 +343,6 @@
|
|||||||
|
|
||||||
.design-overview, .palette-fields { display: grid; gap: 1rem; grid-template-columns: repeat(auto-fit, minmax(min(100%, 14rem), 1fr)); }
|
.design-overview, .palette-fields { display: grid; gap: 1rem; grid-template-columns: repeat(auto-fit, minmax(min(100%, 14rem), 1fr)); }
|
||||||
.palette-fields input[type=color] { padding: .25rem; }
|
.palette-fields input[type=color] { padding: .25rem; }
|
||||||
.layout-components input[type=checkbox] { width: auto; min-height: auto; }
|
|
||||||
.layout-components label { display: flex; align-items: center; }
|
|
||||||
|
|
||||||
.admin-bar .wordmark { display: inline-flex; gap: .5rem; align-items: center; font-size: 1.26rem; font-weight: 700; color: var(--ink); text-decoration: none; }
|
.admin-bar .wordmark { display: inline-flex; gap: .5rem; align-items: center; font-size: 1.26rem; font-weight: 700; color: var(--ink); text-decoration: none; }
|
||||||
.admin-bar .laysite-mark { width: 2.6rem; height: 2.6rem; max-width: 2.6rem; max-height: 2.6rem; object-fit: contain; }
|
.admin-bar .laysite-mark { width: 2.6rem; height: 2.6rem; max-width: 2.6rem; max-height: 2.6rem; object-fit: contain; }
|
||||||
|
|||||||
+12
-3
@@ -3,10 +3,18 @@
|
|||||||
jQuery(function ($) {
|
jQuery(function ($) {
|
||||||
$('[data-layout-components]').on('click', '[data-component-move]', function () {
|
$('[data-layout-components]').on('click', '[data-component-move]', function () {
|
||||||
const $item = $(this).closest('li');
|
const $item = $(this).closest('li');
|
||||||
if (this.dataset.componentMove === '-1') $item.prev().before($item);
|
if (this.dataset.componentMove === '-1') $item.prevAll(':visible').first().before($item);
|
||||||
else $item.next().after($item);
|
else $item.nextAll(':visible').first().after($item);
|
||||||
|
$(this).closest('[data-layout-components]').trigger('layout:order');
|
||||||
$(this).trigger('focus');
|
$(this).trigger('focus');
|
||||||
});
|
});
|
||||||
|
$('[data-page-layout-editor]').each(function () {
|
||||||
|
const {pageLayoutEditor: kind, defaultId} = this.dataset;
|
||||||
|
const $link = $(this);
|
||||||
|
$('#studio-page-settings').on('change', '[name="' + kind + '_id"]', function () {
|
||||||
|
$link.attr('href', '/admin/design/' + kind + '/' + (this.value || defaultId || 'new?default=1'));
|
||||||
|
});
|
||||||
|
});
|
||||||
$('[data-provider-settings]').each(function () {
|
$('[data-provider-settings]').each(function () {
|
||||||
const $settings = $(this);
|
const $settings = $(this);
|
||||||
const $form = $settings.closest('form');
|
const $form = $settings.closest('form');
|
||||||
@@ -15,7 +23,7 @@ jQuery(function ($) {
|
|||||||
const $mode = $settings.find('[name=provider_mode]');
|
const $mode = $settings.find('[name=provider_mode]');
|
||||||
const sync = () => {
|
const sync = () => {
|
||||||
const mode = $mode.val();
|
const mode = $mode.val();
|
||||||
const active = $preset.val() === 'member' && $account.is(':checked');
|
const active = $preset.filter(':checked').val() === 'member' && $account.is(':checked');
|
||||||
$settings.prop({hidden: !active, disabled: !active});
|
$settings.prop({hidden: !active, disabled: !active});
|
||||||
$settings.find('[data-provider-field]').prop('hidden', !mode);
|
$settings.find('[data-provider-field]').prop('hidden', !mode);
|
||||||
$settings.find('[data-provider-mode]').each(function () {
|
$settings.find('[data-provider-mode]').each(function () {
|
||||||
@@ -165,6 +173,7 @@ jQuery(function ($) {
|
|||||||
return;
|
return;
|
||||||
}
|
}
|
||||||
finish();
|
finish();
|
||||||
|
if (response?.field) $form.triggerHandler('studio:invalid', [response.field]);
|
||||||
if (!designFieldError($form, response)) {
|
if (!designFieldError($form, response)) {
|
||||||
formError($form, response?.message || '请求未完成,请稍后重试。', request.status);
|
formError($form, response?.message || '请求未完成,请稍后重试。', request.status);
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -0,0 +1,167 @@
|
|||||||
|
.design-editor-bar {
|
||||||
|
display: grid;
|
||||||
|
grid-template-columns: minmax(12rem, 1fr) auto auto;
|
||||||
|
align-items: end;
|
||||||
|
gap: .85rem 1.25rem;
|
||||||
|
margin: 0;
|
||||||
|
}
|
||||||
|
.design-editor-bar > label:has(input[type=checkbox]) { min-height: 46px; }
|
||||||
|
.design-editor-grid {
|
||||||
|
display: grid;
|
||||||
|
grid-template-columns: minmax(0, 1fr) minmax(18.5rem, 23rem);
|
||||||
|
align-items: start;
|
||||||
|
gap: 1.1rem;
|
||||||
|
}
|
||||||
|
.design-editor-grid > * { min-width: 0; }
|
||||||
|
.design-editor .admin-panel { padding: clamp(.85rem, 2vw, 1.5rem); }
|
||||||
|
.design-canvas-stage {
|
||||||
|
display: grid;
|
||||||
|
justify-items: center;
|
||||||
|
align-content: center;
|
||||||
|
min-height: 15.5rem;
|
||||||
|
padding: clamp(.4rem, 2.3vw, 1.45rem);
|
||||||
|
border: 1px solid var(--line);
|
||||||
|
border-radius: .65rem;
|
||||||
|
background-color: var(--paper);
|
||||||
|
background-image: radial-gradient(var(--line) 1px, transparent 1px);
|
||||||
|
background-size: 13px 13px;
|
||||||
|
}
|
||||||
|
.design-canvas-viewport {
|
||||||
|
position: relative;
|
||||||
|
max-width: 100%;
|
||||||
|
}
|
||||||
|
.design-canvas-viewport iframe {
|
||||||
|
display: block;
|
||||||
|
position: absolute;
|
||||||
|
top: 0;
|
||||||
|
left: 0;
|
||||||
|
border: 1px solid var(--line);
|
||||||
|
border-radius: .45rem;
|
||||||
|
background: var(--white);
|
||||||
|
box-shadow: 0 8px 28px rgb(20 36 70 / 9%);
|
||||||
|
transform-origin: top left;
|
||||||
|
}
|
||||||
|
.design-canvas-stage > p { margin: 0; }
|
||||||
|
.design-canvas-stage:has([data-layout-empty]:not([hidden])) .design-canvas-viewport { display: none; }
|
||||||
|
.design-canvas > .field-note { margin-top: .65rem; }
|
||||||
|
|
||||||
|
.design-templates { min-inline-size: 0; }
|
||||||
|
.design-templates legend, .design-component-panel legend, .design-properties legend {
|
||||||
|
padding-inline: .35rem;
|
||||||
|
color: var(--ink);
|
||||||
|
font-weight: 660;
|
||||||
|
}
|
||||||
|
.design-template-grid { display: grid; grid-template-columns: repeat(auto-fit, minmax(min(100%, 12rem), 1fr)); gap: .75rem; }
|
||||||
|
.design-editor label.design-template-choice {
|
||||||
|
gap: 0;
|
||||||
|
min-width: 0;
|
||||||
|
overflow: hidden;
|
||||||
|
border: 1px solid var(--line);
|
||||||
|
border-radius: .6rem;
|
||||||
|
cursor: pointer;
|
||||||
|
transition: border-color .16s, transform .16s, box-shadow .16s;
|
||||||
|
}
|
||||||
|
.design-template-choice:hover { transform: translateY(-2px); border-color: var(--accent); }
|
||||||
|
.design-template-choice:has(input:checked) { border-color: var(--accent); box-shadow: 0 0 0 1px var(--accent); }
|
||||||
|
.design-template-choice:focus-within { outline: 2px solid var(--accent); outline-offset: 3px; }
|
||||||
|
.design-template-image {
|
||||||
|
position: relative;
|
||||||
|
height: 6rem;
|
||||||
|
overflow: hidden;
|
||||||
|
background: var(--paper);
|
||||||
|
border-bottom: 1px solid var(--line);
|
||||||
|
}
|
||||||
|
.design-template-image iframe {
|
||||||
|
position: absolute;
|
||||||
|
inset: 0 auto auto 0;
|
||||||
|
width: calc(100% / .42);
|
||||||
|
height: calc(100% / .42);
|
||||||
|
border: 0;
|
||||||
|
transform: scale(.42);
|
||||||
|
transform-origin: top left;
|
||||||
|
pointer-events: none;
|
||||||
|
}
|
||||||
|
.design-template-caption {
|
||||||
|
display: flex;
|
||||||
|
align-items: center;
|
||||||
|
gap: .55rem;
|
||||||
|
min-height: 2.8rem;
|
||||||
|
padding: .45rem .65rem;
|
||||||
|
font-size: .92rem;
|
||||||
|
}
|
||||||
|
.design-editor-inspector { display: grid; gap: 1rem; }
|
||||||
|
.design-component-panel { min-inline-size: 0; padding: .25rem .65rem .55rem; }
|
||||||
|
.design-component-panel .layout-components li {
|
||||||
|
min-height: 2.7rem;
|
||||||
|
border: 0;
|
||||||
|
border-radius: .4rem;
|
||||||
|
padding: .35rem .45rem;
|
||||||
|
gap: .35rem;
|
||||||
|
}
|
||||||
|
.design-component-panel .layout-components li + li { margin-block-start: .2rem; }
|
||||||
|
.design-component-panel .layout-components li.is-selected { background: var(--accent-light); }
|
||||||
|
.design-component-panel .layout-components .actions { gap: .22rem; }
|
||||||
|
.design-component-panel .button, .design-link-row .button {
|
||||||
|
min-height: 2rem;
|
||||||
|
width: 2rem;
|
||||||
|
padding: 0;
|
||||||
|
background: var(--white);
|
||||||
|
}
|
||||||
|
.design-component-panel .button svg, .design-link-row .button svg { width: 1rem; height: 1rem; }
|
||||||
|
.design-component-panel .button:disabled, .design-link-row .button:disabled { opacity: .45; cursor: default; transform: none; }
|
||||||
|
.design-properties {
|
||||||
|
display: grid;
|
||||||
|
gap: .8rem;
|
||||||
|
min-inline-size: 0;
|
||||||
|
margin: 0;
|
||||||
|
padding: .5rem .7rem .8rem;
|
||||||
|
}
|
||||||
|
.design-properties .asset-field { grid-template-columns: minmax(0, 1fr); }
|
||||||
|
.design-properties .asset-field button { justify-self: start; }
|
||||||
|
.design-link-rows { display: grid; gap: .5rem; margin-bottom: .65rem; }
|
||||||
|
.design-link-row {
|
||||||
|
display: grid;
|
||||||
|
grid-template-columns: minmax(0, 1fr) auto;
|
||||||
|
gap: .4rem .55rem;
|
||||||
|
padding: .55rem;
|
||||||
|
border: 1px solid var(--line);
|
||||||
|
border-radius: .45rem;
|
||||||
|
}
|
||||||
|
.design-link-row label { grid-column: 1; }
|
||||||
|
.design-link-controls { display: grid; grid-column: 2; grid-row: 1 / span 2; align-content: center; gap: .25rem; }
|
||||||
|
.design-link-row input { min-height: 2.2rem; padding: .3rem .45rem; }
|
||||||
|
|
||||||
|
.design-frame { display: flow-root; margin: 0; background: transparent; }
|
||||||
|
.design-frame-sample { display: grid; align-content: center; min-height: 100vh; background: var(--paper); }
|
||||||
|
.design-frame .masthead { position: static; }
|
||||||
|
.design-frame-sample .masthead .primary-nav { width: auto; order: 0; }
|
||||||
|
.design-frame-editing :is([data-layout-component], [data-layout-text], [data-layout-link-text]) {
|
||||||
|
outline: 1px dashed transparent;
|
||||||
|
outline-offset: 3px;
|
||||||
|
}
|
||||||
|
.design-frame-editing :is([data-layout-component]:hover, [data-layout-component].is-selected) { outline-color: var(--accent); }
|
||||||
|
.design-frame-editing [contenteditable] { cursor: text; overflow-wrap: anywhere; min-inline-size: .4em; }
|
||||||
|
.design-frame-editing [contenteditable]:focus { outline: 2px solid var(--accent); }
|
||||||
|
.design-frame-editing [contenteditable]:empty::before {
|
||||||
|
content: attr(data-layout-placeholder);
|
||||||
|
opacity: .72;
|
||||||
|
pointer-events: none;
|
||||||
|
}
|
||||||
|
.design-frame-editing .site-footer-text { white-space: pre-wrap; }
|
||||||
|
.design-frame-editing .primary-nav { align-items: center; }
|
||||||
|
|
||||||
|
@media (max-width: 55rem) {
|
||||||
|
.design-editor-grid { grid-template-columns: minmax(0, 1fr); }
|
||||||
|
.design-editor-main { display: contents; }
|
||||||
|
.design-editor-inspector { grid-row: 2; }
|
||||||
|
}
|
||||||
|
@media (max-width: 39rem) {
|
||||||
|
.design-editor-bar { grid-template-columns: 1fr auto; align-items: center; }
|
||||||
|
.design-editor-bar > label:first-child { grid-column: 1 / -1; }
|
||||||
|
.design-editor-bar > button { justify-self: end; }
|
||||||
|
.design-canvas-stage { min-height: 12rem; }
|
||||||
|
}
|
||||||
|
@media (prefers-reduced-motion: reduce) {
|
||||||
|
.design-template-choice { transition: none; }
|
||||||
|
.design-template-choice:hover { transform: none; }
|
||||||
|
}
|
||||||
@@ -0,0 +1,277 @@
|
|||||||
|
'use strict';
|
||||||
|
|
||||||
|
jQuery(function ($) {
|
||||||
|
$('[data-layout-editor]').each(function () {
|
||||||
|
const $form = $(this);
|
||||||
|
const $frame = $form.find('[data-layout-frame]');
|
||||||
|
const $viewport = $frame.parent();
|
||||||
|
const $stage = $viewport.parent();
|
||||||
|
const $list = $form.find('[data-layout-components]');
|
||||||
|
const $rows = $form.find('[data-layout-link-rows]');
|
||||||
|
const $linkInput = $form.find('[name=canvas_links]');
|
||||||
|
const kind = this.dataset.layoutEditor;
|
||||||
|
const siteName = this.dataset.siteName;
|
||||||
|
const $presets = $form.find('[name=preset]');
|
||||||
|
const field = (name) => $form.find('[name="' + name + '"]');
|
||||||
|
const placeholder = {
|
||||||
|
brand: siteName, action_label: '按钮文案', text: '添加说明文字', legal: '添加版权文字'
|
||||||
|
};
|
||||||
|
const buttonStyles = {solid: 'button-primary', outline: 'button-outline', underline: 'button-underline', plain: 'button-plain'};
|
||||||
|
let links = JSON.parse($linkInput.val()).filter((link) =>
|
||||||
|
Array.isArray(link) && typeof link[0] === 'string' && typeof link[1] === 'string');
|
||||||
|
let selected = '';
|
||||||
|
let doc;
|
||||||
|
let parts;
|
||||||
|
let host;
|
||||||
|
let observer;
|
||||||
|
let phone = window.matchMedia('(max-width: 44rem)').matches;
|
||||||
|
|
||||||
|
function part(name) {
|
||||||
|
return parts.get(name);
|
||||||
|
}
|
||||||
|
|
||||||
|
function selectComponent(name) {
|
||||||
|
selected = name;
|
||||||
|
$form.find('[data-layout-panel]').each(function () {
|
||||||
|
this.hidden = this.dataset.layoutPanel !== name;
|
||||||
|
});
|
||||||
|
$list.children().each(function () {
|
||||||
|
const active = this.dataset.layoutLayer === name;
|
||||||
|
$(this).toggleClass('is-selected', active).find('[data-layout-select]').attr('aria-pressed', String(active));
|
||||||
|
});
|
||||||
|
for (const [key, node] of parts) {
|
||||||
|
node.classList.toggle('is-selected', key === name);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
function syncLayers() {
|
||||||
|
const preset = $presets.filter(':checked').val();
|
||||||
|
const base = kind === 'header' ? 'masthead' : 'site-footer';
|
||||||
|
const root = host.parentElement;
|
||||||
|
root.className = base + ' ' + base + '-' + preset;
|
||||||
|
const $available = $list.children().each(function () {
|
||||||
|
this.hidden = this.dataset.layoutLayer === 'account' && preset !== 'member';
|
||||||
|
}).filter(function () { return !this.hidden; });
|
||||||
|
$available.each(function (index) {
|
||||||
|
const $item = $(this);
|
||||||
|
$item.find('[data-component-move="-1"]').prop('disabled', index === 0);
|
||||||
|
$item.find('[data-component-move="1"]').prop('disabled', index === $available.length - 1);
|
||||||
|
});
|
||||||
|
|
||||||
|
const ordered = $available.find('input:checked').map((_, input) => input.value).get();
|
||||||
|
for (const [name, node] of parts) {
|
||||||
|
node.hidden = !ordered.includes(name);
|
||||||
|
}
|
||||||
|
for (const name of ordered) host.append(part(name));
|
||||||
|
root.hidden = ordered.length === 0;
|
||||||
|
$form.find('[data-layout-empty]').prop('hidden', ordered.length > 0);
|
||||||
|
if (!$available.filter(function () { return this.dataset.layoutLayer === selected; }).length) {
|
||||||
|
selectComponent(ordered[0] || $available.first().attr('data-layout-layer') || '');
|
||||||
|
}
|
||||||
|
syncFrameSize();
|
||||||
|
}
|
||||||
|
|
||||||
|
function setInlineText(node, label, fallback) {
|
||||||
|
node.contentEditable = 'plaintext-only';
|
||||||
|
node.setAttribute('aria-label', label);
|
||||||
|
node.dataset.layoutPlaceholder = fallback;
|
||||||
|
}
|
||||||
|
|
||||||
|
function syncBrand() {
|
||||||
|
const image = part('brand').querySelector('img');
|
||||||
|
const label = part('brand').querySelector('[data-layout-text]');
|
||||||
|
const url = field('logo').val().trim();
|
||||||
|
const safeImage = /^(?:\/(?!\/)|https:\/\/)[^\s\\]+$/i.test(url);
|
||||||
|
if (safeImage) image.setAttribute('src', url);
|
||||||
|
else image.removeAttribute('src');
|
||||||
|
image.alt = field('brand').val() || siteName;
|
||||||
|
image.hidden = !safeImage;
|
||||||
|
label.hidden = safeImage;
|
||||||
|
}
|
||||||
|
|
||||||
|
function renderLinks() {
|
||||||
|
const nav = part('links');
|
||||||
|
nav.replaceChildren();
|
||||||
|
if (links.length === 0) {
|
||||||
|
$('<button>', {type: 'button', class: 'button button-outline', 'data-layout-add-in-canvas': '', text: '添加链接'}).appendTo(nav);
|
||||||
|
return;
|
||||||
|
}
|
||||||
|
links.forEach((link, index) => {
|
||||||
|
const item = doc.createElement('a');
|
||||||
|
item.href = '#';
|
||||||
|
item.dataset.layoutLinkText = index;
|
||||||
|
item.textContent = link[1];
|
||||||
|
setInlineText(item, '链接文案', '链接文案');
|
||||||
|
nav.append(item);
|
||||||
|
});
|
||||||
|
}
|
||||||
|
|
||||||
|
function renderLinkRows() {
|
||||||
|
const template = $form.find('[data-layout-link-template]').get(0);
|
||||||
|
$rows.empty();
|
||||||
|
links.forEach((link, index) => {
|
||||||
|
const $row = $(template.content.firstElementChild.cloneNode(true));
|
||||||
|
$row.attr('data-layout-link-index', index).find('[data-layout-link-field]').each(function () {
|
||||||
|
this.value = link[Number(this.dataset.layoutLinkField)];
|
||||||
|
});
|
||||||
|
$row.find('[data-layout-link-move="-1"]').prop('disabled', index === 0);
|
||||||
|
$row.find('[data-layout-link-move="1"]').prop('disabled', index === links.length - 1);
|
||||||
|
$rows.append($row);
|
||||||
|
});
|
||||||
|
$form.find('[data-layout-link-add]').prop('disabled', links.length >= 20);
|
||||||
|
}
|
||||||
|
|
||||||
|
function updateLinkInput() {
|
||||||
|
$linkInput.val(JSON.stringify(links));
|
||||||
|
}
|
||||||
|
|
||||||
|
function rebuildLinks() {
|
||||||
|
updateLinkInput();
|
||||||
|
renderLinks();
|
||||||
|
renderLinkRows();
|
||||||
|
}
|
||||||
|
|
||||||
|
function addLink() {
|
||||||
|
if (links.length >= 20) return;
|
||||||
|
links.push(['', '']);
|
||||||
|
rebuildLinks();
|
||||||
|
$rows.children().last().find('[data-layout-link-field="1"]').trigger('focus');
|
||||||
|
}
|
||||||
|
|
||||||
|
function syncFrameSize() {
|
||||||
|
if (!doc) return;
|
||||||
|
const available = $stage.width();
|
||||||
|
if (!available) return;
|
||||||
|
const width = phone ? 390 : Math.max(960, available);
|
||||||
|
const scale = Math.min(1, available / width);
|
||||||
|
$frame.css({width, transform: 'scale(' + scale + ')'});
|
||||||
|
const height = Math.ceil(doc.body.getBoundingClientRect().height) + 2;
|
||||||
|
$frame.css('height', height);
|
||||||
|
$viewport.css({width: width * scale, height: height * scale});
|
||||||
|
}
|
||||||
|
|
||||||
|
function mount() {
|
||||||
|
const next = $frame.get(0).contentDocument;
|
||||||
|
if (!next?.body?.classList.contains('design-frame-editing') || next === doc) return;
|
||||||
|
doc = next;
|
||||||
|
parts = new Map($(doc).find('[data-layout-component]').map((_, node) => [[node.dataset.layoutComponent, node]]).get());
|
||||||
|
host = part('brand').parentElement;
|
||||||
|
const $doc = $(doc);
|
||||||
|
|
||||||
|
$doc.find('[data-layout-text]').each(function () {
|
||||||
|
const name = this.dataset.layoutText;
|
||||||
|
const input = field(name).get(0);
|
||||||
|
this.textContent = input.value;
|
||||||
|
setInlineText(this, input.closest('label').firstChild.textContent.trim(), placeholder[name]);
|
||||||
|
});
|
||||||
|
$doc.on('click auxclick', 'a', (event) => event.preventDefault());
|
||||||
|
$doc.on('click focusin', '[data-layout-component]', function () {
|
||||||
|
selectComponent(this.dataset.layoutComponent);
|
||||||
|
});
|
||||||
|
$doc.on('click', '[data-layout-add-in-canvas]', () => {
|
||||||
|
selectComponent('links');
|
||||||
|
addLink();
|
||||||
|
});
|
||||||
|
$doc.on('beforeinput', '[data-layout-text], [data-layout-link-text]', function (event) {
|
||||||
|
if (this.dataset.layoutText !== 'text' && ['insertParagraph', 'insertLineBreak'].includes(event.originalEvent?.inputType)) {
|
||||||
|
event.preventDefault();
|
||||||
|
}
|
||||||
|
});
|
||||||
|
$doc.on('paste drop', '[data-layout-text], [data-layout-link-text]', function (event) {
|
||||||
|
event.preventDefault();
|
||||||
|
if (event.type !== 'paste') return;
|
||||||
|
const text = event.originalEvent.clipboardData.getData('text/plain');
|
||||||
|
doc.execCommand('insertText', false, this.dataset.layoutText === 'text' ? text : text.replace(/\s*\r?\n\s*/g, ' '));
|
||||||
|
});
|
||||||
|
$doc.on('input', '[data-layout-text]', function () {
|
||||||
|
field(this.dataset.layoutText).val(this.innerText);
|
||||||
|
if (this.dataset.layoutText === 'brand') syncBrand();
|
||||||
|
});
|
||||||
|
$doc.on('input', '[data-layout-link-text]', function () {
|
||||||
|
const index = Number(this.dataset.layoutLinkText);
|
||||||
|
links[index][1] = this.innerText;
|
||||||
|
$rows.children().eq(index).find('[data-layout-link-field="1"]').val(this.innerText);
|
||||||
|
updateLinkInput();
|
||||||
|
});
|
||||||
|
|
||||||
|
$form.find('[data-layout-workspace], [data-layout-link-editor], [data-layout-select]').prop('hidden', false);
|
||||||
|
$form.find('[data-layout-viewport]').attr('aria-pressed', 'false')
|
||||||
|
.filter('[data-layout-viewport="' + (phone ? 'phone' : 'desktop') + '"]').attr('aria-pressed', 'true');
|
||||||
|
$form.find('[data-layout-legacy-links]').prop('hidden', true).find(':input').prop('disabled', true);
|
||||||
|
$linkInput.prop('disabled', false);
|
||||||
|
const initialField = $form.find('[data-field-error]:not([hidden])').closest('[data-layout-panel]').attr('data-layout-panel');
|
||||||
|
selectComponent(initialField || 'brand');
|
||||||
|
syncLayers();
|
||||||
|
syncBrand();
|
||||||
|
syncButton();
|
||||||
|
syncAccount();
|
||||||
|
rebuildLinks();
|
||||||
|
observer?.disconnect();
|
||||||
|
if ('ResizeObserver' in window) {
|
||||||
|
observer = new ResizeObserver(syncFrameSize);
|
||||||
|
observer.observe(doc.body);
|
||||||
|
observer.observe($stage.get(0));
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
function syncButton() {
|
||||||
|
const button = part('action');
|
||||||
|
if (!button) return;
|
||||||
|
button.classList.remove(...Object.values(buttonStyles));
|
||||||
|
button.classList.add(buttonStyles[field('action_style').val()] || buttonStyles.outline);
|
||||||
|
}
|
||||||
|
|
||||||
|
function syncAccount() {
|
||||||
|
const account = part('account');
|
||||||
|
if (account) account.textContent = field('provider_mode').val() ? '登录' : '配置登录';
|
||||||
|
}
|
||||||
|
|
||||||
|
$frame.on('load', mount);
|
||||||
|
$presets.on('change', () => { if (doc) syncLayers(); });
|
||||||
|
$list.on('change', 'input', function () {
|
||||||
|
if (!doc) return;
|
||||||
|
syncLayers();
|
||||||
|
if (this.checked) selectComponent(this.value);
|
||||||
|
}).on('layout:order', () => { if (doc) syncLayers(); })
|
||||||
|
.on('click', '[data-layout-select]', function () { selectComponent(this.dataset.layoutSelect); });
|
||||||
|
$form.on('click', '[data-layout-viewport]', function () {
|
||||||
|
$form.find('[data-layout-viewport]').attr('aria-pressed', 'false');
|
||||||
|
$(this).attr('aria-pressed', 'true');
|
||||||
|
phone = this.dataset.layoutViewport === 'phone';
|
||||||
|
syncFrameSize();
|
||||||
|
}).on('input', '[name=brand], [name=action_label], [name=text], [name=legal]', function () {
|
||||||
|
if (!doc) return;
|
||||||
|
$(doc).find('[data-layout-text="' + this.name + '"]').text(this.value);
|
||||||
|
if (this.name === 'brand') syncBrand();
|
||||||
|
}).on('input', '[name=logo]', () => { if (doc) syncBrand(); })
|
||||||
|
.on('change', '[name=action_style]', () => { if (doc) syncButton(); })
|
||||||
|
.on('change', '[name=provider_mode]', () => { if (doc) syncAccount(); })
|
||||||
|
.on('click', '[data-layout-link-add]', addLink)
|
||||||
|
.on('studio:invalid', (_event, name) => {
|
||||||
|
if (!doc) return;
|
||||||
|
const $panel = $form.find('[data-field-error]').filter((_, node) => node.dataset.fieldError === name)
|
||||||
|
.closest('[data-layout-panel]');
|
||||||
|
if ($panel.length) selectComponent($panel.attr('data-layout-panel'));
|
||||||
|
});
|
||||||
|
|
||||||
|
$rows.on('input', '[data-layout-link-field]', function () {
|
||||||
|
const index = Number(this.closest('[data-layout-link-index]').dataset.layoutLinkIndex);
|
||||||
|
const column = Number(this.dataset.layoutLinkField);
|
||||||
|
links[index][column] = this.value;
|
||||||
|
if (column === 1) part('links').children[index].textContent = this.value;
|
||||||
|
updateLinkInput();
|
||||||
|
}).on('click', '[data-layout-link-remove]', function () {
|
||||||
|
links.splice(Number(this.closest('[data-layout-link-index]').dataset.layoutLinkIndex), 1);
|
||||||
|
rebuildLinks();
|
||||||
|
$form.find('[data-layout-link-add]').trigger('focus');
|
||||||
|
}).on('click', '[data-layout-link-move]', function () {
|
||||||
|
const index = Number(this.closest('[data-layout-link-index]').dataset.layoutLinkIndex);
|
||||||
|
const next = index + Number(this.dataset.layoutLinkMove);
|
||||||
|
if (next < 0 || next >= links.length) return;
|
||||||
|
[links[index], links[next]] = [links[next], links[index]];
|
||||||
|
rebuildLinks();
|
||||||
|
$rows.children().eq(next).find('[data-layout-link-field="1"]').trigger('focus');
|
||||||
|
});
|
||||||
|
mount();
|
||||||
|
});
|
||||||
|
});
|
||||||
@@ -633,6 +633,8 @@ progress { width: 100%; height: .8rem; accent-color: var(--accent); }
|
|||||||
.site-footer-columns .site-footer-components { display: grid; align-items: start; grid-template-columns: repeat(auto-fit, minmax(min(100%, 12rem), 1fr)); }
|
.site-footer-columns .site-footer-components { display: grid; align-items: start; grid-template-columns: repeat(auto-fit, minmax(min(100%, 12rem), 1fr)); }
|
||||||
.site-footer-compact { padding-block: 1rem; }
|
.site-footer-compact { padding-block: 1rem; }
|
||||||
.site-footer-band { --paper: #171e2e; --ink: #fff; --muted: #e1e6f1; color: var(--ink); background: var(--paper); }
|
.site-footer-band { --paper: #171e2e; --ink: #fff; --muted: #e1e6f1; color: var(--ink); background: var(--paper); }
|
||||||
|
.site-footer-band .site-footer-nav a { color: var(--muted); }
|
||||||
|
.site-footer-band .site-footer-nav a:hover { color: var(--ink); }
|
||||||
.site-footer-text { max-width: 48ch; white-space: pre-line; margin: 0; }
|
.site-footer-text { max-width: 48ch; white-space: pre-line; margin: 0; }
|
||||||
.site-footer-nav { display: flex; flex-wrap: wrap; gap: .5rem 1rem; }
|
.site-footer-nav { display: flex; flex-wrap: wrap; gap: .5rem 1rem; }
|
||||||
@media (max-width: 44rem) {
|
@media (max-width: 44rem) {
|
||||||
|
|||||||
Reference in New Issue
Block a user