Fix palette choices, template drawer, and canvas layer labels

This commit is contained in:
2026-11-28 11:59:15 +08:00
parent 5c37952bca
commit f9af7af86c
16 changed files with 141 additions and 81 deletions
+15 -6
View File
@@ -477,14 +477,21 @@
.studio-layer-row[data-drop=before] { border-block-start-color: var(--accent); }
.studio-layer-row[data-drop=after] { border-block-end-color: var(--accent); }
.studio-layer-row[data-drop=inside], .studio-layer-row[aria-current=true] { background: var(--accent-light); }
.studio-layer-label { min-width: 0; overflow-wrap: anywhere; }
.studio-layer-caption { font-weight: 620; display: flex; align-items: baseline; gap: .3rem; }
.studio-layer-caption small { font: .7rem var(--mono); color: var(--muted); }
.studio-layer-label { min-width: 0; overflow-wrap: anywhere; font: 650 .8rem var(--mono); }
.studio-layer-caption { display: flex; align-items: center; gap: .3rem; }
button.studio-layer-label {
display: inline-flex; align-items: center; gap: .4rem; padding: .2rem .35rem;
border: 0; border-radius: .25rem; background: transparent; color: inherit; cursor: pointer; text-align: start;
}
button.studio-layer-label::before {
content: ""; display: block; flex: none; inline-size: .38rem; block-size: .38rem;
border-block-end: 1.5px solid currentColor; border-inline-end: 1.5px solid currentColor; transform: rotate(-45deg);
}
button.studio-layer-label[aria-expanded=true]::before { transform: rotate(45deg); }
.studio-layer-row[draggable=true] { cursor: grab; }
.studio-layers .studio-layer-actions { display: flex; flex-wrap: wrap; gap: .16rem; margin-block-end: .25rem; }
.studio-layers .studio-layer-actions .button { min-height: 1.7rem; padding: .18rem .26rem; }
.studio-layer-actions .button svg { width: 1rem; height: 1rem; }
.studio-layer-details > summary { font-weight: 500; font-size: .8rem; color: var(--muted); }
.studio-canvas-toolbar { align-items: center; justify-content: flex-start; }
.studio-canvas-toolbar button:not(.button) {
@@ -497,7 +504,7 @@
.canvas-format-tools { align-items: center; }
.canvas-format-tools input { font-variant-numeric: tabular-nums; }
.studio-settings-grid, .studio-settings-content { display: grid; gap: .85rem; align-content: start; min-inline-size: 0; }
.studio-settings-grid > fieldset { min-inline-size: 0; align-content: start; margin: 0; }
.studio-settings-grid > fieldset { min-inline-size: 0; align-content: start; align-items: start; margin: 0; }
@media (min-width: 72rem) {
.studio-settings-grid { grid-template-columns: repeat(2, minmax(0, 1fr)); }
}
@@ -517,8 +524,10 @@
.palette-picker summary::-webkit-details-marker { display: none; }
.palette-picker summary > svg { flex: none; }
.palette-picker-options {
position: absolute; z-index: 4; inset: calc(100% + .3rem) 0 auto;
display: grid; gap: .25rem; max-height: 13rem; overflow: auto;
margin-top: .3rem; padding: .3rem; background: var(--paper); border: 1px solid var(--line); border-radius: .5rem;
padding: .3rem; background: var(--paper); border: 1px solid var(--line); border-radius: .5rem;
box-shadow: 0 .22rem .85rem #16305220;
}
.palette-picker-options button { font: inherit; text-align: start; }
.palette-picker-options button:hover, .palette-picker-options button[aria-pressed=true], .canvas-fill [aria-selected=true] {
+3
View File
@@ -57,6 +57,9 @@ jQuery(function ($) {
$details.prop('open', false).find('summary').trigger('focus');
}
});
$(document).on('click', (event) => {
if (!$picker.get(0).contains(event.target)) $details.prop('open', false);
});
updatePalette();
});
$('[data-provider-settings]').each(function () {
+2 -1
View File
@@ -7,6 +7,7 @@
height: 100dvh;
max-height: none;
overflow: auto;
scrollbar-gutter: stable;
overscroll-behavior: contain;
border: 0;
padding: 0;
@@ -33,7 +34,7 @@
.page-template-content h3:focus { outline: none; }
.page-template-back { margin-bottom: 1.15rem; }
.page-template-groups, .page-template-pages { display: grid; gap: .75rem; }
.page-template-groups { grid-template-columns: repeat(auto-fit, minmax(min(100%, 18rem), 1fr)); }
.page-template-groups { grid-template-columns: repeat(auto-fit, minmax(min(100%, 17rem), 1fr)); }
.page-template-pages { grid-template-columns: repeat(2, minmax(0, 1fr)); }
.page-template-detail { display: grid; gap: clamp(1rem, 3vw, 2rem); align-items: start; }
.page-template-card {
+23 -35
View File
@@ -428,7 +428,7 @@ jQuery(function ($) {
const propertyInput = (name) => $propertyForm.find('[name="' + name + '"]');
const pageInput = (name) => $settings.find('[name="' + name + '"]');
const settingsSnapshot = (includeHead = false) => $settings.serializeArray()
.filter(({name}) => !['csrf', 'version', 'canvas_sections', 'canvas_order', 'provider_secret'].includes(name)
.filter(({name}) => !['csrf', 'version', 'canvas_sections', 'canvas_order', 'provider_secret', 'original_header_id', 'original_footer_id'].includes(name)
&& (includeHead || name !== 'head_html'));
let savedSettings = JSON.stringify(settingsSnapshot(true));
let dialogAction;
@@ -718,6 +718,9 @@ jQuery(function ($) {
deletedSections = [];
initialOrder = canvasOrder();
pageInput('version').val(saved.version);
for (const [field, id] of Object.entries(saved.layoutIds || {})) {
pageInput('original_' + field).val(id ?? '');
}
pageInput('provider_secret').val('');
pageInput('canvas_sections').val('');
pageInput('canvas_order').val('');
@@ -1912,7 +1915,7 @@ jQuery(function ($) {
function refreshLayerTitle(section) {
const title = plainText(section.fields.title.node) || '未命名区块';
$layers.find('.studio-layer-row').filter((_, row) => $(row).data('canvasNode') === section.node)
.find('.studio-layer-label').text(title);
.find('.studio-layer-label').attr('title', title);
}
function isHeroVisible() {
@@ -2076,6 +2079,7 @@ jQuery(function ($) {
let draggedLayer;
let dropHint;
let layerTimer;
let layerBranchId = 0;
const layerActions = {
jump: ['target', '定位'], up: ['up', '上移'], down: ['down', '下移'],
delete: ['delete', '删除'], source: ['code', '编辑 HTML'],
@@ -2094,18 +2098,6 @@ jQuery(function ($) {
&& !child.matches('meta, template, [data-studio-module-note]') && (authored || !child.matches('[aria-hidden="true"]')));
}
function layerName(node) {
const structure = {'wrap': '内容宽度容器', 'section-heading': '标题与简介', 'hero-copy': '首屏文案',
'hero-inner': '首屏布局', 'hero-actions': '首屏按钮', 'section-nav-inner': '目录链接'};
if (node.dataset.studioPart === 'body') return '区块正文';
const group = Object.keys(structure).find((name) => node.classList.contains(name));
if (group) return structure[group];
const tag = node.localName;
const authoredLabel = node.matches('img') ? node.alt : node.firstChild?.nodeType === 3 ? node.firstChild.textContent.trim() : '';
const types = {img: '图片', a: '链接', nav: '导航', div: '容器', section: '分区', p: '段落', br: '换行'};
return (authoredLabel || node.getAttribute('aria-label') || types[tag] || tag).slice(0, 38);
}
function layerContext(node) {
if (!node?.isConnected) return null;
const entry = sections.find((section) => section.node === node);
@@ -2194,9 +2186,10 @@ jQuery(function ($) {
.data('canvasNode', node).appendTo($item);
if (node === selectedElement) $row.attr('aria-current', 'true');
const $caption = $('<div>', {class: 'studio-layer-caption'}).appendTo($row);
if (node.hidden) $('<small>', {text: '隐藏'}).appendTo($caption);
$('<span>', {class: 'studio-layer-label', text: label || layerName(node)}).appendTo($caption);
if (!root) $('<small>').text(node.localName).appendTo($caption);
const children = layerChildren(node).filter((child) => !child.hasAttribute('data-studio-section'));
const $tag = $(children.length ? '<button>' : '<span>', {
class: 'studio-layer-label', text: '<' + node.localName + '>', title: label || node.getAttribute('aria-label') || '',
}).appendTo($caption);
if (entry && entry.feed !== null) $('<span>', {class: 'studio-dynamic-badge', text: '动态'}).appendTo($caption);
const $actions = $('<div>', {class: 'studio-layer-actions'}).appendTo($row);
$actions.append(layerButton('jump'));
@@ -2211,33 +2204,28 @@ jQuery(function ($) {
$('<a>', {class: 'button button-outline', href: $settings.attr('action') + '/' + entry.key,
title: '区块设置', 'aria-label': '区块设置'}).append(icon).appendTo($actions);
}
const children = layerChildren(node).filter((child) => !child.hasAttribute('data-studio-section'));
if (!children.length) return;
const $details = $('<details>', {class: 'studio-layer-details',
open: expandedLayers.has(node) || root && !closedLayers.has(node)}).appendTo($item);
const $summary = $('<summary>').text('子图层 · ' + children.length).appendTo($details);
function showChildren() {
if ($details.children('ul').length) return;
const $children = $('<ul>', {class: 'studio-layer-tree'}).appendTo($details);
for (const child of children) layerRow($children, child);
const branchId = 'studio-layer-branch-' + ++layerBranchId;
const $branch = $('<ul>', {id: branchId, class: 'studio-layer-tree', hidden: true}).appendTo($item);
function disclose(open) {
$tag.attr('aria-expanded', String(open));
$branch.prop('hidden', !open);
if (open && !$branch.children().length) {
for (const child of children) layerRow($branch, child);
}
}
function syncDisclosure() {
if ($details.prop('open')) {
$tag.attr({type: 'button', 'aria-controls': branchId}).on('click', () => {
const open = $branch.prop('hidden');
if (open) {
expandedLayers.add(node);
closedLayers.delete(node);
showChildren();
} else {
expandedLayers.delete(node);
closedLayers.add(node);
}
}
$summary.on('click', (event) => {
event.preventDefault();
$details.prop('open', !$details.prop('open'));
syncDisclosure();
disclose(open);
});
$details.on('toggle', () => { if ($details.get(0).isConnected) syncDisclosure(); });
if ($details.prop('open')) showChildren();
disclose(expandedLayers.has(node) || root && !closedLayers.has(node));
}
function renderLayers() {