From b736389d1c90a9e9ddd88d2dac9b8f6d16de1f1f Mon Sep 17 00:00:00 2001 From: qiqi Date: Thu, 19 Nov 2026 09:14:48 +0800 Subject: [PATCH] =?UTF-8?q?feat(settings):=20=E6=8F=92=E4=BB=B6=E8=AE=BE?= =?UTF-8?q?=E7=BD=AE=E6=94=AF=E6=8C=81=20custom=20=E6=B8=B2=E6=9F=93?= =?UTF-8?q?=EF=BC=8C=E6=96=87=E6=9C=AC=E6=8E=A7=E4=BB=B6=E6=94=B9=E6=88=90?= =?UTF-8?q?=E5=B7=A6=E5=AF=B9=E9=BD=90=E4=B8=8A=E4=B8=8B=E5=B8=83=E5=B1=80?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit 浏览器的「书签」从一条「每行一个 名称|网址」的文本框升级成分组管理器, 通用设置行撑不住(需要分组条、多行、拖动排序),所以给 settingsSchema 加一种 type:'custom': - 插件在 settings[key].render({value, commit, spec, pluginId}) 里返回**原生 DOM**, 宿主用 PluginCustomSetting 组件挂载。不给 React 元素是因为插件是运行时下载的 独立脚本,拿不到宿主 React 实例。 - effect 依赖 [value, pluginId, spec]:commit 后带新值重建;同值重渲染(改别的 设置项、开关插件)不重建,否则正在输入的框会被冲掉。 - 插件渲染抛异常时就地降级成一行说明,不把整页设置拖白。 顺带调整布局:text/number 也改成「说明在上、控件在下」左对齐(.iwb-mk-setrow-col), 输入框 260 → 520px。原来 label 在左、控件挤在右侧窄框里,地址这类内容看不全也 改不动。boolean 仍留行末(那是开关,不是填写内容)。 app.js 未改动(行数棘轮无影响);verify:ci 全绿。 --- src/ui-settings-sections.js | 40 ++++++++++++++++++++++++++++++++++--- style.css | 7 +++++++ 2 files changed, 44 insertions(+), 3 deletions(-) diff --git a/src/ui-settings-sections.js b/src/ui-settings-sections.js index 7971aba..710c46d 100644 --- a/src/ui-settings-sections.js +++ b/src/ui-settings-sections.js @@ -706,6 +706,34 @@ return transferSection } + // 插件自定义设置块(2026-11-19):spec.type === 'custom' 时由插件自己渲染一整块 + // DOM(例如浏览器的「分组书签管理器」),宿主只提供挂载点。 + // 为什么不让插件直接返回 React 元素:插件是运行时下载的独立脚本,拿不到宿主的 + // React 实例(也没有共享模块),只能给它一个原生 DOM 容器。 + function PluginCustomSetting (props) { + const boxRef = React.useRef(null) + const spec = props.spec + // 依赖里放 value:commit 之后父组件带着新值重渲染,这里才重建;同值重渲染 + // (别的设置项变更、开关插件)不会重建,避免把正在输入的框冲掉。 + React.useLayoutEffect(function () { + const box = boxRef.current + if (!box) return undefined + box.innerHTML = '' + let node = null + try { + node = spec.render({ value: props.value, commit: props.commit, spec: spec, pluginId: props.pluginId }) + } catch (e) { + node = null + // 插件渲染异常不该把整个设置页拖白:就地降级成一行说明 + if (typeof console !== 'undefined') console.error('[plugin-setting] 自定义设置渲染失败', e) + } + if (node && node.nodeType === 1) box.appendChild(node) + else box.textContent = '该设置项需要更新版本的插件或客户端。' + return function () { box.innerHTML = '' } + }, [props.value, props.pluginId, spec]) + return el('div', { className: 'iwb-plugin-setting-custom', ref: boxRef }) + } + function renderPluginSettingsPage (ctx) { const { PluginHost, activePlugin, setMsg, setPluginsRev, setTab } = ctx const pluginSettingsPage = activePlugin ? el('div', { className: 'iwb-set-page' }, @@ -725,7 +753,11 @@ const spec = activePlugin.settingsSchema[key] || {} const value = activePlugin.settings && activePlugin.settings[key] !== undefined ? activePlugin.settings[key] : spec.default const commit = function (next) { PluginHost.setSetting(activePlugin.id, key, next); setPluginsRev(function (v) { return v + 1 }) } - return el('div', { key: key, className: 'iwb-mk-setrow' }, + const isCustom = spec.type === 'custom' && typeof spec.render === 'function' + // 说明在上、控件在下(左对齐):右侧 260px 的窄框放地址/多行内容既看不全也 + // 改不动;boolean 仍是行末开关(这类是「开/关」而不是填写内容)。 + const stacked = isCustom || spec.type === 'text' || spec.type === 'number' + return el('div', { key: key, className: 'iwb-mk-setrow' + (stacked ? ' iwb-mk-setrow-col' : '') }, el('div', { className: 'iwb-mk-setrow-main' }, el('div', { className: 'iwb-mk-setrow-title' }, spec.label || key), spec.desc ? el('div', { className: 'iwb-hint' }, spec.desc) : null, @@ -735,9 +767,11 @@ el('input', { type: 'checkbox', checked: Boolean(value), onChange: function (e) { commit(e.target.checked) } }), el('span', { className: 'iwb-switch-track' }, el('span', { className: 'iwb-switch-dot' })), ) - : el('input', { + : isCustom + ? el(PluginCustomSetting, { key: 'custom-' + key, spec: spec, value: value, commit: commit, pluginId: activePlugin.id }) + : el('input', { className: 'iwb-input', type: spec.type === 'number' ? 'number' : 'text', - style: { maxWidth: '260px' }, + style: { maxWidth: '520px' }, value: value === undefined ? '' : String(value), onChange: function (e) { commit(spec.type === 'number' ? Number(e.target.value) : e.target.value) }, }), diff --git a/style.css b/style.css index 2e55fd4..bac66dd 100644 --- a/style.css +++ b/style.css @@ -2038,6 +2038,13 @@ html { scrollbar-width: thin; scrollbar-color: var(--iwb-border2) color-mix(in s .iwb-mk-setrow-main { flex: 1 1 auto; min-width: 0; } .iwb-mk-setrow-title { font-weight: 600; font-size: 14px; line-height: 1.4; } .iwb-mk-setrow .iwb-hint { margin-top: 3px; line-height: 1.55; } +/* 插件设置项:说明在上、控件在下(左对齐,2026-11-19)。 + * 原来 label 在左、输入框挤在右边 260px,地址/书签这类内容既看不全也改不动; + * 布尔开关仍留在行末 —— 那是「开/关」,不是要填写的内容。 */ +.iwb-mk-setrow-col { display: block; } +.iwb-mk-setrow-col > .iwb-mk-setrow-main { width: 100%; } +.iwb-mk-setrow-col > .iwb-input, .iwb-mk-setrow-col > .iwb-plugin-setting-custom { margin-top: 10px; } +.iwb-plugin-setting-custom { display: block; min-width: 0; max-width: 100%; } /* 市场页筛选条 */ .iwb-mk-filters { display: flex; gap: 6px; flex-wrap: wrap; margin: 2px 0 12px; align-items: center; }