Address LaySite 1.5.0 audit feedback

This commit is contained in:
2026-11-28 01:52:37 +08:00
parent 044da13a8c
commit 268a278ec1
3 changed files with 57 additions and 31 deletions
+26 -12
View File
@@ -688,20 +688,23 @@ jQuery(function ($) {
}
$settings.on('studio:saved', (_event, saved, submitter) => {
if (!Array.isArray(saved?.sections)) return;
const versions = new Map(saved.sections.map((section) => [section.key, section]));
const dynamic = [];
for (const entry of sections) {
const revision = versions.get(entry.key);
if (!revision) continue;
if (entry.feed && (Object.hasOwn(revision, 'feed') || submitter?.name === 'status'
const committed = Object.hasOwn(revision, 'body');
// A receipt for an untouched section does not replace its canvas contents.
if (!committed && revision.version !== entry.version) continue;
if (entry.feed && (committed || submitter?.name === 'status'
|| entry.node.querySelector('[data-studio-module-note]'))) dynamic.push(entry.key);
if (!committed) continue;
entry.version = revision.version;
entry.node.dataset.studioSection = revision.version;
if (Object.hasOwn(revision, 'body')) entry.source = revision.body;
if (Object.hasOwn(revision, 'feed')) {
entry.feed = revision.feed ? JSON.parse(revision.feed) : null;
if (entry.node.classList.contains('section')) entry.node.classList.toggle('network', entry.feed?.mode === 'network');
}
entry.source = revision.body;
entry.feed = revision.feed ? JSON.parse(revision.feed) : null;
if (entry.node.classList.contains('section')) entry.node.classList.toggle('network', entry.feed?.mode === 'network');
entry.initialFeed = JSON.stringify(entry.feed);
for (const [field, state] of Object.entries(entry.fields)) {
state.initial = field === 'body' ? cleanBody(state.node) : plainText(state.node);
@@ -869,12 +872,22 @@ jQuery(function ($) {
return textTarget(selectedElement);
}
function backgroundTarget(node) {
function backgroundTarget() {
const node = selectedElement || (textHost?.matches('[data-studio-part="title"]') && doc.activeElement === textHost ? textHost : activeBody);
if (!node || node.matches(mediaTargets)) return null;
if (node.matches('[data-studio-part="title"], [data-studio-part="body"]')) {
return node.closest('[data-studio-section], [data-studio-hero]') || styleTarget(node);
}
const target = styleTarget(node);
return target?.matches(fillElements) ? target : null;
}
function backgroundLabel(target) {
if (target?.hasAttribute('data-studio-section')) return '区块背景填充';
if (target?.hasAttribute('data-studio-hero')) return '首屏背景填充';
return '背景填充';
}
function insertionBody() {
if (activeBody?.isConnected) return activeBody;
return selectedElement?.closest('[data-studio-section]')?.querySelector('[data-studio-part="body"]') || null;
@@ -909,12 +922,13 @@ jQuery(function ($) {
const target = doc && formatTarget();
const canInsertText = Boolean(target && activeBody);
const canInsertMedia = Boolean(insertionBody());
const canFill = Boolean(backgroundTarget(selectedElement));
const fill = backgroundTarget();
const fillLabel = backgroundLabel(fill);
$textTools.prop('hidden', !target);
$format.add($fontSize).add($fontPreset).prop('disabled', !target);
$textCommands.prop('hidden', !canInsertText);
$insertTools.prop('hidden', !canInsertMedia && !canFill);
$background.prop('hidden', !canFill);
$insertTools.prop('hidden', !canInsertMedia && !fill);
$background.prop('hidden', !fill).attr({title: fillLabel, 'aria-label': fillLabel});
$insertMedia.prop('hidden', !canInsertMedia);
const sample = target && (selectedText()[0]?.node || target);
const element = sample?.nodeType === 1 ? sample : sample?.parentElement;
@@ -1011,7 +1025,7 @@ jQuery(function ($) {
}
function openFill(text) {
fillTarget = text ? formatTarget() : backgroundTarget(selectedElement);
fillTarget = text ? formatTarget() : backgroundTarget();
if (!fillTarget?.isConnected) return;
textColorDialog = text;
const computed = doc.defaultView.getComputedStyle(fillTarget);
@@ -1025,7 +1039,7 @@ jQuery(function ($) {
fillInput('end').val(type === 'gradient' ? '#' + parts[2] : '#214ed7');
fillInput('angle').val(type === 'gradient' ? parts[0] : '90');
fillInput('image').val(type === 'image' ? decodeImage(parts.join('-')) : '');
$fill.find('[data-fill-title]').text(text ? '文字颜色' : '背景填充');
$fill.find('[data-fill-title]').text(text ? '文字颜色' : backgroundLabel(fillTarget));
$fill.find('[data-fill-tabs]').prop('hidden', text);
$fill.find('[data-fill-panel="solid"]').attr('aria-labelledby', text ? 'canvas-fill-title' : 'fill-tab-solid');
$fillError.prop('hidden', true);