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; }