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
+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() {