fix(ui): 取色板自动确认 + 停靠栏图标按可用面板过滤(v3.25.84)
Verify (Gitea) / gate (build · unit · facts) (push) Failing after 27s
Verify (Gitea) / gate (build · unit · facts) (push) Failing after 27s
This commit is contained in:
1 parent
611cd8f1b9
commit
bbb763c2cf
12 files changed
+99
-24
No files matched your search
+27
-4
@@ -152,6 +152,7 @@
|
||||
const [open, setOpen] = React.useState(false)
|
||||
const [hsv, setHsv] = React.useState(() => { const c = hexToRgb(value); return rgbToHsv(c.r, c.g, c.b) })
|
||||
const boxRef = React.useRef(null)
|
||||
const popRef = React.useRef(null)
|
||||
|
||||
React.useEffect(() => {
|
||||
const c = hexToRgb(value)
|
||||
@@ -179,6 +180,27 @@
|
||||
onChange(rgbToHex(c.r, c.g, c.b))
|
||||
}
|
||||
const hueColor = 'hsl(' + Math.round(hsv.h) + ',100%,50%)'
|
||||
// v3.25.84:拖完自动确认 —— 松手 120ms 后自动收起取色板(不需要点「完成」);
|
||||
// 正在输入 hex/RGB 时不自动收(输入过程中松手会误关)。
|
||||
const closeTimer = React.useRef(null)
|
||||
const armAutoClose = () => {
|
||||
try { if (closeTimer.current) clearTimeout(closeTimer.current) } catch (e) { /* ignore */ }
|
||||
closeTimer.current = setTimeout(() => { setOpen(false) }, 120)
|
||||
}
|
||||
const cancelAutoClose = () => { try { if (closeTimer.current) clearTimeout(closeTimer.current) } catch (e) { /* ignore */ } }
|
||||
React.useEffect(() => {
|
||||
if (!open) return undefined
|
||||
const onDocDown = (e) => {
|
||||
try {
|
||||
const host = popRef.current
|
||||
if (host && host.contains(e.target)) return
|
||||
setOpen(false)
|
||||
} catch (err) { /* ignore */ }
|
||||
}
|
||||
document.addEventListener('pointerdown', onDocDown, true)
|
||||
return () => document.removeEventListener('pointerdown', onDocDown, true)
|
||||
}, [open])
|
||||
React.useEffect(() => () => cancelAutoClose(), [])
|
||||
|
||||
return el('div', { className: 'iwb-cpick' },
|
||||
el('button', {
|
||||
@@ -186,19 +208,20 @@
|
||||
onClick: () => setOpen((v) => !v),
|
||||
style: { background: value, color: readableOn(value) },
|
||||
}, el('span', { className: 'iwb-cpick-hex' }, value.toUpperCase())),
|
||||
open ? el('div', { className: 'iwb-cpick-pop', onPointerDown: (e) => e.stopPropagation() },
|
||||
open ? el('div', { className: 'iwb-cpick-pop', ref: popRef, onPointerDown: (e) => e.stopPropagation(), onKeyDown: cancelAutoClose },
|
||||
el('div', {
|
||||
className: 'iwb-cpick-box', ref: boxRef,
|
||||
onPointerDown: (e) => { e.currentTarget.setPointerCapture && e.currentTarget.setPointerCapture(e.pointerId); pick(e) },
|
||||
onPointerDown: (e) => { cancelAutoClose(); e.currentTarget.setPointerCapture && e.currentTarget.setPointerCapture(e.pointerId); pick(e) },
|
||||
onPointerMove: (e) => { if (e.buttons === 1) pick(e) },
|
||||
onPointerUp: () => armAutoClose(),
|
||||
style: { background: 'linear-gradient(to top, #000, rgba(0,0,0,0)), linear-gradient(to right, #fff, ' + hueColor + ')' },
|
||||
}, el('div', { className: 'iwb-cpick-dot', style: { left: (hsv.s * 100) + '%', top: ((1 - hsv.v) * 100) + '%', background: value } })),
|
||||
el('input', { type: 'range', min: 0, max: 360, value: Math.round(hsv.h), onChange: hue, className: 'iwb-cpick-hue', style: { background: 'linear-gradient(to right,#f00,#ff0,#0f0,#0ff,#00f,#f0f,#f00)' } }),
|
||||
el('input', { type: 'range', min: 0, max: 360, value: Math.round(hsv.h), onChange: (e) => { hue(e); armAutoClose() }, onPointerDown: cancelAutoClose, className: 'iwb-cpick-hue', style: { background: 'linear-gradient(to right,#f00,#ff0,#0f0,#0ff,#00f,#f0f,#f00)' } }),
|
||||
el('div', { className: 'iwb-cpick-rgb' }, ['r', 'g', 'b'].map((k) => el('label', { key: k, className: 'iwb-cpick-chan' },
|
||||
el('input', { type: 'number', min: 0, max: 255, value: rgb[k], onChange: setChannel(k) }),
|
||||
el('span', null, k.toUpperCase())))),
|
||||
el('div', { className: 'iwb-cpick-foot' },
|
||||
el('input', { className: 'iwb-input iwb-cpick-input', value: value, onChange: (e) => { const v = normHex(e.target.value); if (v) onChange(v) }, title: '支持 #rgb / #rrggbb' }),
|
||||
el('input', { className: 'iwb-input iwb-cpick-input', value: value, onFocus: cancelAutoClose, onChange: (e) => { cancelAutoClose(); const v = normHex(e.target.value); if (v) onChange(v) }, title: '支持 #rgb / #rrggbb' }),
|
||||
g.EyeDropper ? el('button', { type: 'button', className: 'iwb-btn iwb-btn-sm', title: '从屏幕取色', onClick: () => { try { new g.EyeDropper().open().then((r) => { const v = normHex(r && r.sRGBHex); if (v) onChange(v) }).catch(() => {}) } catch (e) { /* ignore */ } } }, '吸管') : null,
|
||||
el('button', { type: 'button', className: 'iwb-btn iwb-btn-sm', onClick: () => setOpen(false) }, '完成')),
|
||||
) : null,
|
||||
|
||||
+20
-1
@@ -139,6 +139,24 @@
|
||||
return function () { clearTimeout(t) }
|
||||
}, [dock])
|
||||
|
||||
// v3.25.84:插件启停后面板集合会变 —— 清掉已不存在的 id,active 失效时回退到第一个可用面板
|
||||
useEffect(function () {
|
||||
setDock(function (d) {
|
||||
let changed = false
|
||||
const next = Object.assign({}, d)
|
||||
for (const side of ['left', 'right']) {
|
||||
const s0 = d[side]
|
||||
const list = (s0.list || []).filter(function (id) { return !!panels[id] })
|
||||
const active = panels[s0.active] ? s0.active : (list[0] || '')
|
||||
if (list.length !== (s0.list || []).length || active !== s0.active) {
|
||||
next[side] = Object.assign({}, s0, { list: list, active: active })
|
||||
changed = true
|
||||
}
|
||||
}
|
||||
return changed ? next : d
|
||||
})
|
||||
}, [panels])
|
||||
|
||||
// 把两侧实际占位宽度写给 CSS(画布不动,只让其它浮层让位)
|
||||
useEffect(function () {
|
||||
const r = global.document && global.document.documentElement
|
||||
@@ -294,7 +312,8 @@
|
||||
const renderHead = function (side) {
|
||||
const s = dock[side]
|
||||
const isLeft = side === 'left'
|
||||
const icons = s.list.map(function (id) {
|
||||
// v3.25.84:只画「当前可用」的面板(插件关掉后不再残留图标)
|
||||
const icons = s.list.filter(function (id) { return !!panels[id] }).map(function (id) {
|
||||
const p = panels[id]
|
||||
return el('button', {
|
||||
key: id,
|
||||
|
||||
Reference in new issue
Block a user