Address LaySite 1.4.5 editor and release review suggestions

This commit is contained in:
2026-11-27 22:14:02 +08:00
parent 00e8a70e06
commit 074591d34f
16 changed files with 159 additions and 48 deletions
+2 -1
View File
@@ -113,7 +113,7 @@
.canvas-font-combo { gap: 0; }
.canvas-font-combo input { border-start-end-radius: 0; border-end-end-radius: 0; }
.canvas-font-combo select {
appearance: none; text-align: center; width: 2.15rem; min-height: 2.45rem; padding: 0;
width: 3.1rem; min-height: 2.45rem; padding: 0 .15rem;
color: var(--ink); background: var(--white); border: 1px solid var(--line); border-inline-start: 0;
border-start-end-radius: .35rem; border-end-end-radius: .35rem; cursor: pointer;
}
@@ -446,6 +446,7 @@
:is(.canvas-source, .head-settings) .CodeMirror-focused { outline: 2px solid var(--accent); outline-offset: 1px; }
.head-settings-fields { display: grid; gap: .65rem; margin-block-start: .6rem; }
.head-settings .CodeMirror { height: clamp(13rem, 38vh, 22rem); margin: 0; }
.mcp-token { font-family: var(--mono); }
.favicon-editor-row { display: flex; flex-wrap: wrap; gap: 1rem; align-items: center; }
.favicon-preview {
display: grid; place-items: center; inline-size: 6rem; block-size: 6rem;
+13 -1
View File
@@ -4,6 +4,15 @@ jQuery(function ($) {
$('[data-head-settings]').each(function () {
const $details = $(this);
const source = $details.find('[data-head-source]').get(0);
const $limit = $details.find('[data-head-limit]');
const encoder = new TextEncoder();
const size = (value) => encoder.encode(value).length;
function fits(current, removed, added) {
const original = size(current);
const next = original - size(removed) + size(added);
$limit.prop('hidden', next <= source.maxLength);
return next <= source.maxLength || next < original;
}
let editor;
$details.on('toggle', () => {
if (!this.open || !window.CodeMirror) return;
@@ -12,6 +21,9 @@ jQuery(function ($) {
mode: 'htmlmixed', lineNumbers: true, lineWrapping: true, indentUnit: 2, tabSize: 2,
});
editor.getInputField().setAttribute('aria-labelledby', 'head-source-label');
editor.on('beforeChange', (cm, change) => {
if (!fits(cm.getValue(), cm.getRange(change.from, change.to), change.text.join('\n'))) change.cancel();
});
editor.on('change', () => editor.save());
}
editor.refresh();
@@ -26,7 +38,7 @@ jQuery(function ($) {
if (editor) {
editor.replaceSelection(value);
editor.focus();
} else {
} else if (fits(source.value, source.value.slice(source.selectionStart, source.selectionEnd), value)) {
source.setRangeText(value, source.selectionStart, source.selectionEnd, 'end');
source.focus();
}
+9 -5
View File
@@ -753,8 +753,13 @@ jQuery(function ($) {
const target = doc && formatTarget();
$format.add($fontSize).add($fontPreset).prop('disabled', !target);
const sample = target && (selectedText()[0]?.node || target);
const computed = sample ? doc.defaultView.getComputedStyle(sample.nodeType === 1 ? sample : sample.parentElement) : null;
if (!$fontSize.is(':focus')) $fontSize.val(computed ? Math.round(parseFloat(computed.fontSize)) : '');
const element = sample?.nodeType === 1 ? sample : sample?.parentElement;
const computed = element ? doc.defaultView.getComputedStyle(element) : null;
const sizeClass = element && classesOf(element).size;
const size = sizeClass ? sizeClass.slice('studio-style-size-'.length)
: (computed ? String(Math.round(parseFloat(computed.fontSize))) : '');
if (!$fontSize.is(':focus')) $fontSize.val(size);
$fontPreset.val($fontPreset.find('option').toArray().some((option) => option.value === size) ? size : '');
$color.add($clearColor).prop('disabled', !target);
const rgb = computed?.color.match(/^rgba?\((\d+), (\d+), (\d+)(?:, [\d.]+)?\)$/);
if (rgb && !$color.is(':focus')) $color.val('#' + rgb.slice(1).map((channel) => Number(channel).toString(16).padStart(2, '0')).join(''));
@@ -815,7 +820,6 @@ jQuery(function ($) {
$format.on('click', function () { applyTextStyle(this.dataset.canvasFormat); });
$fontPreset.on('change', function () {
applyTextStyle('size', this.value);
this.value = '';
});
$fontSize.on('change', function () {
if (this.validity.valid) applyTextStyle('size', this.value === '' ? '' : String(this.valueAsNumber));
@@ -833,7 +837,7 @@ jQuery(function ($) {
const presets = $preset.data('spacingPreset');
const index = same && values[0] !== '' ? presets.indexOf(Number(values[0])) : -1;
const label = !same ? '自定义' : (values[0] === '' ? '默认' : values[0] + ' px');
$preset.val(index === -1 ? $preset.prop('defaultValue') : index).attr('aria-valuetext', label);
$preset.val(index).attr('aria-valuetext', label);
$fields.find('[data-spacing-readout]').text(label);
}
@@ -850,7 +854,7 @@ jQuery(function ($) {
$spacingForm.on('input', '[data-spacing-preset]', function () {
const $preset = $(this);
const $fields = $preset.closest('fieldset');
$fields.find('[data-spacing-side]').val($preset.data('spacingPreset')[this.valueAsNumber]);
$fields.find('[data-spacing-side]').val($preset.data('spacingPreset')[this.valueAsNumber] ?? '');
syncSpacingPreset($fields);
}).on('input', '[data-spacing-side]', function () {
syncSpacingPreset($(this).closest('fieldset'));