feat(settings): 设置窗可拖动 + 外观实时预览(v3.25.76)
Verify (Gitea) / gate (build · unit · facts) (push) Failing after 32s

This commit is contained in:
qiqi committed 2026-11-21 07:24:33 +08:00
1 parent f6d104fd95
commit f02b3dcec2
20 files changed
+307 -108

No files matched your search

+17 -8
View File
@@ -16,10 +16,11 @@
const cache = new Map() // key: gap|dot|color → dataURL
function createTile (gap, dot, color) {
function createTile (gap, dot, color, style) {
if (typeof document === 'undefined') return null
const g = Math.max(4, Math.round(gap))
const key = g + '|' + dot + '|' + color
const st = (style === 'lines') ? 'lines' : 'dots'
const key = g + '|' + dot + '|' + color + '|' + st
const hit = cache.get(key)
if (hit) return hit
try {
@@ -29,9 +30,16 @@
const ctx = cv.getContext('2d')
if (!ctx) return null
ctx.fillStyle = color
ctx.beginPath()
ctx.arc(g / 2, g / 2, Math.max(0.5, dot), 0, Math.PI * 2)
ctx.fill()
if (st === 'lines') {
// 网格线:画右/下两条 1px 线,平铺后即连续网格(v3.25.75)
const w = Math.max(1, Math.round(Math.min(2, dot * 0.6)))
ctx.fillRect(g - w, 0, w, g)
ctx.fillRect(0, g - w, g, w)
} else {
ctx.beginPath()
ctx.arc(g / 2, g / 2, Math.max(0.5, dot), 0, Math.PI * 2)
ctx.fill()
}
const url = cv.toDataURL('image/png')
if (cache.size > 24) cache.clear()
cache.set(key, url)
@@ -44,7 +52,7 @@
const o = opts || {}
const base = Math.max(4, Number(o.base) || 28)
const gap = Math.max(4, base * (Number(scale) > 0 ? Number(scale) : 1))
const url = createTile(gap, o.dot || 1.2, o.color || 'rgba(120,128,140,0.55)')
const url = createTile(gap, o.dot || 1.2, o.color || 'rgba(120,128,140,0.55)', o.style)
if (!url) return null
return {
backgroundImage: 'url(' + url + ')',
@@ -59,12 +67,13 @@
const o = opts || {}
const base = Math.max(4, Number(o.base) || 28)
const gap = Math.max(4, base * (Number(scale) > 0 ? Number(scale) : 1))
const url = createTile(gap, o.dot || 1.2, o.color || 'rgba(120,128,140,0.55)')
const url = createTile(gap, o.dot || 1.2, o.color || 'rgba(120,128,140,0.55)', o.style)
if (url) {
if (el.dataset.gap !== String(gap)) {
if (el.dataset.gap !== String(gap) || el.dataset.style !== String(o.style || 'dots')) {
el.style.backgroundImage = 'url(' + url + ')'
el.style.backgroundSize = gap + 'px ' + gap + 'px'
el.dataset.gap = String(gap)
el.dataset.style = String(o.style || 'dots')
}
el.style.transform = 'translate(' + (x % gap) + 'px, ' + (y % gap) + 'px)'
}
+106 -71
View File
@@ -14,7 +14,7 @@
const DEFAULTS = Object.freeze({
canvasBgLight: '#d9dbde', canvasBgDark: '#6f6f6f',
gridDotLight: '#c9ccd6', gridDotDark: '#8f8f8f', gridSize: 1.4, gridGap: 22, gridOn: true,
gridDotLight: '#c9ccd6', gridDotDark: '#8f8f8f', gridSize: 1.4, gridGap: 22, gridOn: true, gridStyle: 'dots',
edgeColorLight: '#b9bfca', edgeColorDark: '#7a7a7a',
edgeWidth: 1.8, edgeDash: 'dashed',
edgeHotLight: '#6b7280', edgeHotDark: '#ffffff',
@@ -49,6 +49,11 @@
gridSize: clamp(c.gridSize, 0.8, 2.6, DEFAULTS.gridSize),
gridGap: clamp(c.gridGap, 16, 40, DEFAULTS.gridGap),
gridOn: c.gridOn !== false,
gridStyle: (function () {
const st = String(c.gridStyle || '')
if (st === 'dots' || st === 'lines' || st === 'blank') return st
return (c.gridOn === false) ? 'blank' : 'dots'
})(),
edgeColorLight: hex('edgeColorLight'), edgeColorDark: hex('edgeColorDark'),
edgeWidth: clamp(c.edgeWidth, 1, 4, DEFAULTS.edgeWidth),
edgeDash: DASH[c.edgeDash] ? c.edgeDash : DEFAULTS.edgeDash,
@@ -73,7 +78,9 @@
set('--iwb-grid-dot', dark ? a.gridDotDark : a.gridDotLight)
set('--iwb-grid-size', a.gridSize + 'px')
set('--iwb-grid-gap', a.gridGap + 'px')
set('--iwb-grid-on', a.gridOn ? '1' : '0')
const gs = a.gridStyle || 'dots'
set('--iwb-grid-on', (gs !== 'blank' && a.gridOn !== false) ? '1' : '0')
try { root.setAttribute('data-iwb-grid', gs) } catch (e) { /* ignore */ }
set('--iwb-edge', dark ? a.edgeColorDark : a.edgeColorLight)
set('--iwb-edge-w', a.edgeWidth + 'px')
set('--iwb-edge-dash', DASH[a.edgeDash] || DASH.dashed)
@@ -201,6 +208,10 @@
{ name: '纸质', values: { canvasBgLight: '#efe7d7', canvasBgDark: '#3b3227', gridDotLight: '#d8cbb4', gridDotDark: '#5a4c3d', edgeColorLight: '#b9a88c', edgeColorDark: '#a2917a', edgeDash: 'solid', accent: '#8a6f4a', edgeHotLight: '#8a6f4a', edgeHotDark: '#e0c9a0', nodeBgLight: '#faf6ee', nodeBgDark: '#4a4034', nodeBorderLight: '#ddd0b8', nodeBorderDark: '#6b5c49' } },
]
// ── 外观面板(v3.25.75 重构)───────────────────────────────────────────────
// 用户反馈:分组混乱、颜色字段看不出可点、网格三项无效、对比度警告刷屏。
// 现在:4 个分组(主题 / 画布 / 连线 / 节点),统一两栏网格(标签 120px + 控件),
// 每组组头右侧「恢复本组默认」;颜色统一为「色块 + hex + ▾」;警告收进行尾。
function AppearanceTab (props) {
const draft = (props && props.draft) || {}
const setDraft = (props && props.setDraft) || function () {}
@@ -211,14 +222,56 @@
const set = (patch) => setDraft((d) => Object.assign({}, d, {
canvas: Object.assign({}, d.canvas, { appearance: Object.assign({}, normalize(d), patch) }),
}))
const setMany = (patch) => set(patch)
const resetGroup = (keys) => { const p = {}; for (const k of keys) p[k] = DEFAULTS[k]; set(p) }
const warnEdge = (edge, bg) => {
const r = contrast(edge, bg)
return r < 1.5 ? el('div', { className: 'iwb-hint iwb-hint-warn' }, '连线与画布底色对比度仅 ' + r.toFixed(1) + ':1,可能看不清') : null
}
const importRef = React.useRef(null)
const Row = function (label, control, note) {
return el('div', { className: 'iwb-appear-row' + (note ? ' iwb-appear-row-note' : '') },
el('span', { className: 'iwb-appear-label', title: label }, label),
el('div', { className: 'iwb-appear-ctrl' }, control),
note ? el('span', { className: 'iwb-appear-note' }, note) : null)
}
const Group = function (title, rows, keys) {
return el('section', { className: 'iwb-appear-group' },
el('div', { className: 'iwb-appear-ghead' },
el('span', { className: 'iwb-appear-gtitle' }, title),
keys ? el('button', { className: 'iwb-btn iwb-btn-sm', onClick: () => resetGroup(keys) }, '恢复本组默认') : null),
rows)
}
const Seg = function (val, onChange, items) {
return el('div', { className: 'iwb-seg' }, (items || []).map((item) => el('button', {
key: item.value,
type: 'button',
className: 'iwb-seg-item' + (val === item.value ? ' on' : ''),
onClick: () => onChange(item.value),
}, item.label)))
}
const warnOf = function (edge, bg) {
const r = contrast(edge, bg)
return r < 1.5 ? ('⚠ 对比度 ' + r.toFixed(1) + ':1,可能看不清') : ''
}
// 主题下拉:配色模式 + 全部预设合并(用户裁定:合并)
const themeOptions = [{ value: 'theme:light', label: '亮色(节点灰底 + 内容白)' }, { value: 'theme:dark', label: '暗色' }, { value: 'theme:system', label: '跟随系统' }]
const presetOptions = PRESETS.map((p) => ({ value: 'preset:' + p.name, label: '预设 · ' + p.name }))
.concat(value.presets.map((p, i) => ({ value: 'preset-c:' + i, label: '预设 · ' + p.name })))
const onThemePick = (raw) => {
if (raw.indexOf('theme:') === 0) {
const t = raw.slice(6)
const v = (t === 'dark' || t === 'system') ? t : 'light'
setTheme(v); applyTheme(v); return
}
if (raw.indexOf('preset-c:') === 0) {
const p = value.presets[Number(raw.slice(9)) || 0]
if (p && p.values) set(normalize({ canvas: { appearance: p.values } }))
return
}
if (raw.indexOf('preset:') === 0) {
const name = raw.slice(7)
const p = PRESETS.find((x) => x.name === name)
if (p) set(Object.assign({}, DEFAULTS, p.values))
}
}
const exportPresets = () => {
try {
const doc = { version: 1, appearance: Object.assign({}, value, { presets: undefined }) }
@@ -245,25 +298,14 @@
} catch (e) { /* ignore */ }
}
return el('div', null,
el('div', { className: 'iwb-section-sub' }, '界面主题'),
el('div', { className: 'iwb-row' },
el('span', { className: 'iwb-label' }, '配色模式'),
el('select', {
className: 'iwb-input', title: '界面配色(亮色保证文字清晰)', value: theme,
onChange: (e) => { const t = e.target.value; const v = (t === 'dark' || t === 'system') ? t : 'light'; setTheme(v); applyTheme(v) },
},
el('option', { value: 'light' }, '亮色(默认:节点灰底 + 内容白)'),
el('option', { value: 'dark' }, '暗色'),
el('option', { value: 'system' }, '跟随系统'),
)),
el('div', { className: 'iwb-section-sub' }, '预设'),
el('div', { className: 'iwb-appear-presets' },
PRESETS.map((p) => el('button', { key: p.name, className: 'iwb-btn iwb-btn-sm', onClick: () => setMany(Object.assign({}, DEFAULTS, p.values)), title: '套用「' + p.name + '」' }, p.name)),
value.presets.map((p, i) => el('button', { key: 'c' + i, className: 'iwb-btn iwb-btn-sm', onClick: () => set(normalize({ canvas: { appearance: p.values } })), title: '套用自定义预设' }, p.name || ('自定义 ' + (i + 1)))),
),
el('div', { className: 'iwb-row' },
const themeGroup = Group('主题', [
Row('主题', el('select', {
className: 'iwb-input iwb-appear-select', value: 'theme:' + theme,
onChange: (e) => onThemePick(e.target.value),
}, themeOptions.concat(presetOptions).map((o) => el('option', { key: o.value, value: o.value }, o.label))),
'切换配色模式或直接套用预设'),
Row('主题色', el(ColorPicker, { value: value.accent, onChange: (v) => set({ accent: v }) }), '按钮 / 端口 / 选中框'),
Row('预设', el('div', { className: 'iwb-appear-btns' },
el('button', {
className: 'iwb-btn iwb-btn-sm',
onClick: () => {
@@ -273,55 +315,48 @@
set({ presets: value.presets.concat([{ name: String(name).slice(0, 20), values: snap }]).slice(0, 12) })
},
}, '保存当前为预设'),
el('button', { className: 'iwb-btn iwb-btn-sm', onClick: exportPresets }, '导出外观'),
el('button', { className: 'iwb-btn iwb-btn-sm', onClick: () => importRef.current && importRef.current.click() }, '导入外观'),
el('input', { ref: importRef, type: 'file', accept: 'application/json', style: { display: 'none' }, onChange: (e) => { const f = e.target.files && e.target.files[0]; if (f) importFile(f); e.target.value = '' } }),
),
el('button', { className: 'iwb-btn iwb-btn-sm', onClick: exportPresets }, '导出'),
el('button', { className: 'iwb-btn iwb-btn-sm', onClick: () => importRef.current && importRef.current.click() }, '导入'),
el('input', { ref: importRef, type: 'file', accept: 'application/json', style: { display: 'none' }, onChange: (e) => { const f = e.target.files && e.target.files[0]; if (f) importFile(f) } }))),
], null)
el('div', { className: 'iwb-section-sub' }, '画布'),
el('div', { className: 'iwb-row' }, el('span', { className: 'iwb-label' }, '底色(亮)'), el(ColorPicker, { value: value.canvasBgLight, onChange: (v) => set({ canvasBgLight: v }) })),
el('div', { className: 'iwb-row' }, el('span', { className: 'iwb-label' }, '底色(暗)'), el(ColorPicker, { value: value.canvasBgDark, onChange: (v) => set({ canvasBgDark: v }) })),
el('div', { className: 'iwb-row' }, el('span', { className: 'iwb-label' }, '网格点(亮)'), el(ColorPicker, { value: value.gridDotLight, onChange: (v) => set({ gridDotLight: v }) })),
el('div', { className: 'iwb-row' }, el('span', { className: 'iwb-label' }, '网格点(暗)'), el(ColorPicker, { value: value.gridDotDark, onChange: (v) => set({ gridDotDark: v }) })),
el(NumberRow, { label: '网格点大小', value: value.gridSize, min: 0.8, max: 2.6, step: 0.1, unit: 'px', onChange: (v) => set({ gridSize: v }) }),
el(NumberRow, { label: '网格间距', value: value.gridGap, min: 16, max: 40, step: 1, unit: 'px', onChange: (v) => set({ gridGap: v }) }),
el('label', { className: 'iwb-check' }, el('input', { type: 'checkbox', checked: value.gridOn, onChange: (e) => set({ gridOn: e.target.checked }) }, null), ' 显示网格'),
el('div', { className: 'iwb-row' }, el('button', { className: 'iwb-btn iwb-btn-sm', onClick: () => resetGroup(['canvasBgLight', 'canvasBgDark', 'gridDotLight', 'gridDotDark', 'gridSize', 'gridGap', 'gridOn']) }, '恢复本组默认')),
const canvasGroup = Group('画布', [
Row('网格样式', Seg(value.gridStyle, (v) => set({ gridStyle: v, gridOn: v !== 'blank' }), [
{ value: 'dots', label: '点' }, { value: 'lines', label: '线' }, { value: 'blank', label: '空白' },
]), '空白 = 不显示背景网格'),
Row('底色(亮)', el(ColorPicker, { value: value.canvasBgLight, onChange: (v) => set({ canvasBgLight: v }) })),
Row('底色(暗)', el(ColorPicker, { value: value.canvasBgDark, onChange: (v) => set({ canvasBgDark: v }) })),
Row(value.gridStyle === 'lines' ? '网格线色(亮)' : '网格点(亮)', el(ColorPicker, { value: value.gridDotLight, onChange: (v) => set({ gridDotLight: v }) })),
Row(value.gridStyle === 'lines' ? '网格线色(暗)' : '网格点(暗)', el(ColorPicker, { value: value.gridDotDark, onChange: (v) => set({ gridDotDark: v }) })),
Row(value.gridStyle === 'lines' ? '网格线粗细' : '网格点大小', el('input', { type: 'range', min: 0.8, max: 2.6, step: 0.1, value: value.gridSize, className: 'iwb-appear-range', onChange: (e) => set({ gridSize: Number(e.target.value) }) }),
String(value.gridSize) + 'px'),
Row('网格间距', el('input', { type: 'range', min: 16, max: 40, step: 1, value: value.gridGap, className: 'iwb-appear-range', onChange: (e) => set({ gridGap: Number(e.target.value) }) }),
String(value.gridGap) + 'px'),
], ['canvasBgLight', 'canvasBgDark', 'gridDotLight', 'gridDotDark', 'gridSize', 'gridGap', 'gridOn', 'gridStyle'])
el('div', { className: 'iwb-section-sub' }, '连线'),
el('div', { className: 'iwb-row' }, el('span', { className: 'iwb-label' }, '默认色(亮)'), el(ColorPicker, { value: value.edgeColorLight, onChange: (v) => set({ edgeColorLight: v }) })),
warnEdge(value.edgeColorLight, value.canvasBgLight),
el('div', { className: 'iwb-row' }, el('span', { className: 'iwb-label' }, '默认色(暗)'), el(ColorPicker, { value: value.edgeColorDark, onChange: (v) => set({ edgeColorDark: v }) })),
warnEdge(value.edgeColorDark, value.canvasBgDark),
el(NumberRow, { label: '默认粗细', value: value.edgeWidth, min: 1, max: 4, step: 0.1, unit: 'px', onChange: (v) => set({ edgeWidth: v }) }),
el('div', { className: 'iwb-row' },
el('span', { className: 'iwb-label' }, '线型'),
el('select', { className: 'iwb-input', value: value.edgeDash, onChange: (e) => set({ edgeDash: e.target.value }) },
el('option', { value: 'solid' }, '实线'),
el('option', { value: 'dashed' }, '虚线'),
el('option', { value: 'dotted' }, '点线'),
)),
el('div', { className: 'iwb-row' }, el('span', { className: 'iwb-label' }, '高亮色(亮)'), el(ColorPicker, { value: value.edgeHotLight, onChange: (v) => set({ edgeHotLight: v }) })),
el('div', { className: 'iwb-row' }, el('span', { className: 'iwb-label' }, '高亮色(暗)'), el(ColorPicker, { value: value.edgeHotDark, onChange: (v) => set({ edgeHotDark: v }) })),
el('div', { className: 'iwb-hint' }, '高亮色只用于选中节点的上下游连线、悬停连线与临时连线;默认连线永远用上面的「默认色」。'),
el('div', { className: 'iwb-row' }, el('button', { className: 'iwb-btn iwb-btn-sm', onClick: () => resetGroup(['edgeColorLight', 'edgeColorDark', 'edgeWidth', 'edgeDash', 'edgeHotLight', 'edgeHotDark']) }, '恢复本组默认')),
const edgeGroup = Group('连线', [
Row('默认色(亮)', el(ColorPicker, { value: value.edgeColorLight, onChange: (v) => set({ edgeColorLight: v }) }), warnOf(value.edgeColorLight, value.canvasBgLight)),
Row('默认色(暗)', el(ColorPicker, { value: value.edgeColorDark, onChange: (v) => set({ edgeColorDark: v }) }), warnOf(value.edgeColorDark, value.canvasBgDark)),
Row('粗细', el('input', { type: 'range', min: 1, max: 4, step: 0.1, value: value.edgeWidth, className: 'iwb-appear-range', onChange: (e) => set({ edgeWidth: Number(e.target.value) }) }), String(value.edgeWidth) + 'px'),
Row('线型', el('select', { className: 'iwb-input iwb-appear-select', value: value.edgeDash, onChange: (e) => set({ edgeDash: e.target.value }) },
el('option', { value: 'solid' }, '实线'), el('option', { value: 'dashed' }, '虚线'), el('option', { value: 'dotted' }, '点线'))),
Row('高亮色(亮)', el(ColorPicker, { value: value.edgeHotLight, onChange: (v) => set({ edgeHotLight: v }) }), '仅选中/悬停/临时连线'),
Row('高亮色(暗)', el(ColorPicker, { value: value.edgeHotDark, onChange: (v) => set({ edgeHotDark: v }) })),
], ['edgeColorLight', 'edgeColorDark', 'edgeWidth', 'edgeDash', 'edgeHotLight', 'edgeHotDark'])
el('div', { className: 'iwb-section-sub' }, '节点'),
el('div', { className: 'iwb-row' }, el('span', { className: 'iwb-label' }, '节点底色(亮)'), el(ColorPicker, { value: value.nodeBgLight, onChange: (v) => set({ nodeBgLight: v }) })),
el('div', { className: 'iwb-row' }, el('span', { className: 'iwb-label' }, '节点底色(暗)'), el(ColorPicker, { value: value.nodeBgDark, onChange: (v) => set({ nodeBgDark: v }) })),
el('div', { className: 'iwb-row' }, el('span', { className: 'iwb-label' }, '边框色(亮)'), el(ColorPicker, { value: value.nodeBorderLight, onChange: (v) => set({ nodeBorderLight: v }) })),
el('div', { className: 'iwb-row' }, el('span', { className: 'iwb-label' }, '边框色(暗)'), el(ColorPicker, { value: value.nodeBorderDark, onChange: (v) => set({ nodeBorderDark: v }) })),
el(NumberRow, { label: '节点圆角', value: value.nodeRadius, min: 6, max: 20, step: 1, unit: 'px', onChange: (v) => set({ nodeRadius: v }) }),
el(NumberRow, { label: '选中描边', value: value.nodeSelWidth, min: 1, max: 4, step: 0.5, unit: 'px', onChange: (v) => set({ nodeSelWidth: v }) }),
el('div', { className: 'iwb-row' }, el('button', { className: 'iwb-btn iwb-btn-sm', onClick: () => resetGroup(['nodeBgLight', 'nodeBgDark', 'nodeBorderLight', 'nodeBorderDark', 'nodeRadius', 'nodeSelWidth']) }, '恢复本组默认')),
el('div', { className: 'iwb-section-sub' }, '主题色'),
el('div', { className: 'iwb-row' }, el('span', { className: 'iwb-label' }, '按钮 / 端口 / 选中框'), el(ColorPicker, { value: value.accent, onChange: (v) => set({ accent: v }) })),
el('div', { className: 'iwb-hint' }, '主题色同时用于亮色与暗色主题;作用在按钮、端口、选中框与进度动画上。连线用上面的「连线」分组。'),
const nodeGroup = Group('节点', [
Row('节点底色(亮)', el(ColorPicker, { value: value.nodeBgLight, onChange: (v) => set({ nodeBgLight: v }) })),
Row('节点底色(暗)', el(ColorPicker, { value: value.nodeBgDark, onChange: (v) => set({ nodeBgDark: v }) })),
Row('边框色(亮)', el(ColorPicker, { value: value.nodeBorderLight, onChange: (v) => set({ nodeBorderLight: v }) })),
Row('边框色(暗)', el(ColorPicker, { value: value.nodeBorderDark, onChange: (v) => set({ nodeBorderDark: v }) })),
Row('节点圆角', el('input', { type: 'range', min: 6, max: 20, step: 1, value: value.nodeRadius, className: 'iwb-appear-range', onChange: (e) => set({ nodeRadius: Number(e.target.value) }) }), String(value.nodeRadius) + 'px'),
Row('选中描边', el('input', { type: 'range', min: 1, max: 4, step: 0.5, value: value.nodeSelWidth, className: 'iwb-appear-range', onChange: (e) => set({ nodeSelWidth: Number(e.target.value) }) }), String(value.nodeSelWidth) + 'px'),
], ['nodeBgLight', 'nodeBgDark', 'nodeBorderLight', 'nodeBorderDark', 'nodeRadius', 'nodeSelWidth'])
return el('div', { className: 'iwb-appear' },
themeGroup, canvasGroup, edgeGroup, nodeGroup,
el('div', { className: 'iwb-row', style: { marginTop: 12 } },
el('button', { className: 'iwb-btn iwb-btn-sm', onClick: () => setMany(Object.assign({}, DEFAULTS, { presets: value.presets })) }, '全部恢复默认')),
)
el('button', { className: 'iwb-btn iwb-btn-sm', onClick: () => set(Object.assign({}, DEFAULTS, { presets: value.presets })) }, '全部恢复默认')))
}
g.IWBUIApearance = Object.freeze({ DEFAULTS, PRESETS, DASH, normalize, apply, contrast, ColorPicker, AppearanceTab })
+64
View File
@@ -0,0 +1,64 @@
/* ui-modal-drag.js —— 弹窗拖动 + 外观实时预览(v3.25.76)
*
* 为什么单独成模块:src 里单组件行数有上限(SettingsModal 已接近上限),
* 这两个都是与具体弹窗无关的通用行为,抽出来也便于别处复用。
*/
;(function (global) {
'use strict'
const React = global.React || {}
const el = (t, p, ...c) => React.createElement(t, p, ...c)
// 拖动标题栏移动弹窗;位置限制在视口内(至少留 120×60 可见)
function useDraggableModal () {
const [pos, setPos] = React.useState(null)
const dragRef = React.useRef(null)
const onHeadPointerDown = (e) => {
if (e.button !== 0) return
const host = e.currentTarget && e.currentTarget.closest ? e.currentTarget.closest('.iwb-modal') : null
if (!host) return
const r = host.getBoundingClientRect()
dragRef.current = { x: e.clientX, y: e.clientY, left: r.left, top: r.top }
const move = (ev) => {
const d = dragRef.current
if (!d) return
const left = Math.max(8, Math.min((global.innerWidth || 1200) - 120, d.left + (ev.clientX - d.x)))
const top = Math.max(8, Math.min((global.innerHeight || 800) - 60, d.top + (ev.clientY - d.y)))
setPos({ left, top })
}
const up = () => {
dragRef.current = null
global.removeEventListener('pointermove', move)
global.removeEventListener('pointerup', up)
}
global.addEventListener('pointermove', move)
global.addEventListener('pointerup', up)
e.preventDefault()
}
const style = pos ? { position: 'fixed', left: pos.left + 'px', top: pos.top + 'px', margin: 0, transform: 'none' } : undefined
return { pos, style, onHeadPointerDown }
}
// 外观实时预览:draft 变化 → 立刻写 CSS 变量 + 通知画布重渲染;关闭未保存则回滚
function useAppearancePreview (opts) {
const o = opts || {}
const savedRef = React.useRef((o.savedConfig && o.savedConfig.canvas && o.savedConfig.canvas.appearance) || null)
const themeRef = React.useRef(o.dark ? 'dark' : 'light')
React.useEffect(() => { themeRef.current = o.dark ? 'dark' : 'light' }, [o.dark])
React.useEffect(() => {
if (!o.enabled) return
const A = global.IWBUIApearance
if (!A || typeof A.apply !== 'function') return
try { A.apply(o.appearance, !!(o.dark)) } catch (e) { /* ignore */ }
try { global.dispatchEvent(new Event('iwb:appearance')) } catch (e) { /* ignore */ }
}, [o.enabled, o.dark, o.appearance])
React.useEffect(() => () => {
const A = global.IWBUIApearance
if (!A || typeof A.apply !== 'function') return
try { A.apply(savedRef.current, themeRef.current === 'dark') } catch (e) { /* ignore */ }
try { global.dispatchEvent(new Event('iwb:appearance')) } catch (e) { /* ignore */ }
}, [])
return { markSaved: () => { savedRef.current = o.appearance || null } }
}
global.IWBUIModalDrag = { useDraggableModal, useAppearancePreview }
})(typeof window !== 'undefined' ? window : globalThis)
+9 -3
View File
@@ -559,11 +559,17 @@ function SettingsModal(props) {
isDesk() ? null : autoBackupSection,
)
// 可拖动窗口 + 外观实时预览(实现见 src/ui-modal-drag.js)
const MD = (typeof window !== 'undefined') ? window.IWBUIModalDrag : null
const dragKit = (MD && MD.useDraggableModal) ? MD.useDraggableModal() : null
const appearanceKit = (MD && MD.useAppearancePreview) ? MD.useAppearancePreview({ enabled: tab === 'appearance', appearance: draft && draft.canvas ? draft.canvas.appearance : null, dark: theme === 'dark', savedConfig: props.config || null }) : null
const winStyle = dragKit ? dragKit.style : undefined
const onHeadPointerDown = dragKit ? dragKit.onHeadPointerDown : null
// 顺序:通用放最前(最常用:目录/外观/图片图库/生成),其它按使用频率排
const tabs = [['general', '通用'], ['appearance', '外观'], ['gen', '生图服务'], ['llm', 'LLM 服务'], ['img', '图片传输'], ['sizes', '尺寸预设'], ['hotkeys', '快捷键'], ['backup', '备份与还原'], ['diag', '诊断'], ['plugins', '插件']]
return el('div', { className: 'iwb-modal-mask', onWheel: (e) => e.stopPropagation(), onPointerDown: (e) => { if (e.target === e.currentTarget) props.onClose() } },
el('div', { className: 'iwb-modal iwb-settings-modal' },
el('div', { className: 'iwb-modal-head' },
el('div', { className: 'iwb-modal iwb-settings-modal' + ((dragKit && dragKit.pos) ? ' iwb-modal-floating' : ''), style: winStyle },
el('div', { className: 'iwb-modal-head iwb-modal-draghead', onPointerDown: onHeadPointerDown, title: '按住拖动窗口' },
el('span', { className: 'iwb-toolbar-title' }, '⚙️ 设置'),
el('button', { className: 'iwb-btn iwb-btn-sm', title: '关闭', onClick: props.onClose }, I('x')),
),
@@ -584,7 +590,7 @@ function SettingsModal(props) {
),
),
el('div', { className: 'iwb-modal-foot' },
el('button', { className: 'iwb-btn iwb-btn-primary', disabled: saving, onClick: save }, saving ? '保存中…' : '保存配置'),
el('button', { className: 'iwb-btn iwb-btn-primary', disabled: saving, onClick: () => { try { if (appearanceKit) appearanceKit.markSaved() } catch (e) { /* ignore */ } ; if (save) save() } }, saving ? '保存中…' : '保存配置'),
),
),
)