feat(vault): 浏览窗口固定/可拖拽 + 复制不闪(v3.26.269)
Verify (Gitea) / gate (build · unit · facts) (push) Failing after 1m42s
Verify (Gitea) / gate (build · unit · facts) (push) Failing after 1m42s
- 窗口固定 860×620;右下角拖拽调整、双击复位、尺寸持久化;切换分类不再改窗口高度 - 面板加载 effect 只依赖 open+源库路径(actions 用 ref),复制不再触发重新读库 - 批量复制:延迟 setWorkspaces(deferState),结束后一次 commitList(一次渲染+一次写索引) - 修复 268 接线:app 端 createBoard(b, opts) 之前只传 b,silent/defer 未生效 - 记住上次分类/排序
This commit is contained in:
1 parent
35495df424
commit
ec7933e2e5
10 files changed
+98
-30
No files matched your search
+70
-18
@@ -1,5 +1,6 @@
|
||||
/* ui-vault-browse.js —— 跨库浏览(只读)+ 一键复制(v3.26.267)
|
||||
* 样式按已确认稿:筛选胶囊 / 搜索 / 排序菜单 / 时间分组 / 多选批量 / 页脚说明。
|
||||
/* ui-vault-browse.js —— 跨库浏览(只读)+ 一键复制(v3.26.267/269)
|
||||
* 样式按已确认稿;269 起固定窗口大小(右下角可拖拽、双击复位、尺寸持久化),
|
||||
* 复制过程不再重建列表(加载副作用只依赖 open + 源库路径)。
|
||||
*/
|
||||
;(function (global) {
|
||||
'use strict'
|
||||
@@ -7,13 +8,25 @@
|
||||
const ReactDOM = global.ReactDOM || {}
|
||||
const el = (t, p, ...c) => React.createElement(t, p, ...c)
|
||||
|
||||
const DEF = { w: 860, h: 620 }
|
||||
const MIN = { w: 640, h: 420 }
|
||||
const SIZE_KEY = 'iwb.browseSize.v1'
|
||||
const PREF_KEY = 'iwb.browsePrefs.v1'
|
||||
|
||||
const loadJSON = (k, fb) => { try { const v = global.localStorage.getItem(k); return v ? JSON.parse(v) : fb } catch (e) { return fb } }
|
||||
const saveJSON = (k, v) => { try { global.localStorage.setItem(k, JSON.stringify(v)) } catch (e) { /* ignore */ } }
|
||||
const clampSize = (w, h) => {
|
||||
const vw = (global.innerWidth || 1440), vh = (global.innerHeight || 900)
|
||||
return { w: Math.max(MIN.w, Math.min(Number(w) || DEF.w, vw - 32)), h: Math.max(MIN.h, Math.min(Number(h) || DEF.h, vh - 32)) }
|
||||
}
|
||||
const centerOf = (s) => ({ x: Math.max(8, Math.round(((global.innerWidth || 1440) - s.w) / 2)), y: Math.max(8, Math.round(((global.innerHeight || 900) - s.h) / 2)) })
|
||||
|
||||
const S = {
|
||||
mask: { position: 'fixed', inset: '0', background: 'rgba(0,0,0,.28)', zIndex: 2147483000, display: 'flex', alignItems: 'center', justifyContent: 'center' },
|
||||
modal: { width: '820px', maxWidth: '94vw', maxHeight: '88vh', background: '#fefefe', border: '1px solid #c2c2c2', borderRadius: '14px', boxShadow: '0 24px 60px rgba(0,0,0,.22)', overflow: 'hidden', display: 'flex', flexDirection: 'column' },
|
||||
mask: { position: 'fixed', inset: '0', background: 'rgba(0,0,0,.32)', zIndex: 2147483000 },
|
||||
modal: { position: 'fixed', background: '#fefefe', border: '1px solid #c2c2c2', borderRadius: '14px', boxShadow: '0 24px 60px rgba(0,0,0,.22)', overflow: 'hidden', display: 'flex', flexDirection: 'column' },
|
||||
head: { display: 'flex', alignItems: 'flex-start', justifyContent: 'space-between', padding: '14px 16px 10px', flexShrink: 0 },
|
||||
title: { fontSize: '14px', fontWeight: 700 },
|
||||
sub: { fontSize: '11px', color: '#5c5c5c', marginTop: '3px', wordBreak: 'break-all' },
|
||||
// 分类胶囊换行展示(不横向滚动);极端多分类时只做纵向滚动,最多约 5 行
|
||||
filters: { display: 'flex', flexWrap: 'wrap', gap: '6px 6px', padding: '0 16px 10px', overflowY: 'auto', maxHeight: '7.5em', flexShrink: 0 },
|
||||
chip: { display: 'inline-flex', alignItems: 'center', flex: '0 0 auto', fontSize: '11px', lineHeight: '18px', minHeight: '22px', padding: '0 9px', borderRadius: '999px', border: '1px solid #c2c2c2', background: '#fff', color: '#5c5c5c', cursor: 'pointer', whiteSpace: 'nowrap' },
|
||||
chipOn: { background: 'rgba(59,130,246,.12)', borderColor: '#bcd3f7', color: '#2f5fa8', fontWeight: 600 },
|
||||
@@ -23,7 +36,7 @@
|
||||
sort: { height: '34px', display: 'flex', alignItems: 'center', gap: '6px', padding: '0 10px', border: '1px solid #c2c2c2', borderRadius: '8px', background: '#fff', fontSize: '12px', color: '#5c5c5c', cursor: 'pointer' },
|
||||
sortMenu: { position: 'absolute', right: 0, top: '38px', zIndex: 6, background: '#fff', border: '1px solid #c2c2c2', borderRadius: '8px', boxShadow: '0 10px 24px rgba(0,0,0,.14)', padding: '4px', minWidth: '170px' },
|
||||
sortItem: { display: 'block', width: '100%', textAlign: 'left', fontSize: '12px', padding: '6px 8px', border: 0, background: 'transparent', borderRadius: '6px', color: '#404040', cursor: 'pointer' },
|
||||
list: { padding: '2px 8px 8px', overflow: 'auto', flex: 1, minHeight: '120px' },
|
||||
list: { padding: '2px 8px 8px', overflow: 'auto', flex: 1, minHeight: '0' },
|
||||
sec: { fontSize: '11px', fontWeight: 700, color: '#5c5c5c', padding: '8px 8px 4px', letterSpacing: '.4px' },
|
||||
row: { display: 'flex', alignItems: 'center', gap: '10px', padding: '9px 8px', borderRadius: '8px' },
|
||||
cb: { width: '15px', height: '15px', border: '1px solid #c2c2c2', borderRadius: '4px', background: '#fff', flex: '0 0 auto', display: 'flex', alignItems: 'center', justifyContent: 'center', color: '#fff', fontSize: '11px', cursor: 'pointer' },
|
||||
@@ -41,21 +54,33 @@
|
||||
const [analysis, setAnalysis] = React.useState(null)
|
||||
const [err, setErr] = React.useState('')
|
||||
const [q, setQ] = React.useState('')
|
||||
const [filter, setFilter] = React.useState('all')
|
||||
const [sort, setSort] = React.useState('recent')
|
||||
const [filter, setFilter] = React.useState(() => loadJSON(PREF_KEY, {}).filter || 'all')
|
||||
const [sort, setSort] = React.useState(() => loadJSON(PREF_KEY, {}).sort || 'recent')
|
||||
const [sortOpen, setSortOpen] = React.useState(false)
|
||||
const [sel, setSel] = React.useState(() => new Set())
|
||||
const [busy, setBusy] = React.useState('')
|
||||
const [msg, setMsg] = React.useState('')
|
||||
const [size, setSize] = React.useState(() => clampSize(loadJSON(SIZE_KEY, DEF).w, loadJSON(SIZE_KEY, DEF).h))
|
||||
const [pos, setPos] = React.useState(() => centerOf(clampSize(loadJSON(SIZE_KEY, DEF).w, loadJSON(SIZE_KEY, DEF).h)))
|
||||
const actionsRef = React.useRef(actions)
|
||||
actionsRef.current = actions
|
||||
const sizeRef = React.useRef(size)
|
||||
sizeRef.current = size
|
||||
|
||||
// 加载:只依赖 open + 源库路径(actions 用 ref),复制/状态更新不会重新读库
|
||||
React.useEffect(() => {
|
||||
if (!open || !vault || !actions) return
|
||||
if (!open || !vault || !vault.path) return
|
||||
let live = true
|
||||
setErr(''); setMsg(''); setAnalysis(null); setSel(new Set()); setQ(''); setFilter('all'); setSort('recent')
|
||||
setBusy('load')
|
||||
actions.readVault(vault.path).then((a) => { if (live) { setAnalysis(a); setBusy('') } }).catch((e) => { if (live) { setErr('读取失败:' + String((e && e.message) || e)); setBusy('') } })
|
||||
const A = actionsRef.current
|
||||
setErr(''); setMsg(''); setAnalysis(null); setSel(new Set()); setQ(''); setBusy('load')
|
||||
const s = clampSize(loadJSON(SIZE_KEY, DEF).w, loadJSON(SIZE_KEY, DEF).h)
|
||||
setSize(s); setPos(centerOf(s))
|
||||
A.readVault(vault.path).then((a) => { if (live) { setAnalysis(a); setBusy('') } }).catch((e) => { if (live) { setErr('读取失败:' + String((e && e.message) || e)); setBusy('') } })
|
||||
return () => { live = false }
|
||||
}, [open, vault, actions])
|
||||
}, [open, vault && vault.path])
|
||||
|
||||
// 记住分类/排序
|
||||
React.useEffect(() => { saveJSON(PREF_KEY, { filter: filter, sort: sort }) }, [filter, sort])
|
||||
|
||||
React.useEffect(() => {
|
||||
if (!open) return undefined
|
||||
@@ -79,8 +104,8 @@
|
||||
setBusy('copy'); setMsg('')
|
||||
try {
|
||||
const r = await actions.copyOne(vault.path, b.id, b.name)
|
||||
setMsg('已复制「' + r.name + '」· ' + r.nodes + ' 节点' + (r.missing ? ' · ' + r.missing + ' 张图片缺失' : ''))
|
||||
onClose && onClose()
|
||||
return r
|
||||
} catch (e) { setMsg('复制失败:' + String((e && e.message) || e)) }
|
||||
setBusy('')
|
||||
}
|
||||
@@ -98,6 +123,21 @@
|
||||
setBusy('')
|
||||
}
|
||||
|
||||
const startResize = (e) => {
|
||||
try { e.preventDefault(); e.stopPropagation() } catch (err) { /* ignore */ }
|
||||
const start = { x: e.clientX, y: e.clientY, w: sizeRef.current.w, h: sizeRef.current.h }
|
||||
const move = (ev) => { setSize(clampSize(start.w + (ev.clientX - start.x), start.h + (ev.clientY - start.y))) }
|
||||
const up = () => {
|
||||
try { global.removeEventListener('pointermove', move) } catch (err) { /* ignore */ }
|
||||
try { global.removeEventListener('pointerup', up) } catch (err) { /* ignore */ }
|
||||
const s = sizeRef.current
|
||||
saveJSON(SIZE_KEY, { w: s.w, h: s.h })
|
||||
}
|
||||
global.addEventListener('pointermove', move)
|
||||
global.addEventListener('pointerup', up)
|
||||
}
|
||||
const resetSize = () => { const s = clampSize(DEF.w, DEF.h); setSize(s); setPos(centerOf(s)); saveJSON(SIZE_KEY, { w: s.w, h: s.h }) }
|
||||
|
||||
const filterChip = (key, label, count) => el('button', {
|
||||
style: Object.assign({}, S.chip, filter === key ? S.chipOn : null),
|
||||
onClick: () => setFilter(key),
|
||||
@@ -122,7 +162,10 @@
|
||||
|
||||
return ReactDOM.createPortal(
|
||||
el('div', { style: S.mask, onPointerDown: (e) => { if (e.target === e.currentTarget) onClose && onClose() } },
|
||||
el('div', { style: S.modal, onPointerDown: (e) => e.stopPropagation() },
|
||||
el('div', {
|
||||
style: Object.assign({}, S.modal, { left: pos.x + 'px', top: pos.y + 'px', width: size.w + 'px', height: size.h + 'px' }),
|
||||
onPointerDown: (e) => e.stopPropagation(),
|
||||
},
|
||||
el('div', { style: S.head },
|
||||
el('div', { style: { minWidth: 0 } },
|
||||
el('div', { style: S.title }, '浏览「' + (vault.name || '库') + '」的画板'),
|
||||
@@ -130,7 +173,7 @@
|
||||
),
|
||||
el('div', { style: { display: 'flex', alignItems: 'center', gap: '8px', fontSize: '11px', color: '#5c5c5c' } },
|
||||
el('span', null, (analysis && analysis.boards.length || 0) + ' 个画板'),
|
||||
el('button', { style: Object.assign({}, S.btn(false), { borderColor: 'transparent', background: 'transparent' }), onClick: () => { setBusy('load'); actions.readVault(vault.path).then((a) => { setAnalysis(a); setBusy('') }).catch((e) => { setErr(String((e && e.message) || e)); setBusy('') }) } }, '↻ 刷新'),
|
||||
el('button', { style: Object.assign({}, S.btn(false), { borderColor: 'transparent', background: 'transparent' }), onClick: () => { const A = actionsRef.current; setBusy('load'); A.readVault(vault.path).then((a) => { setAnalysis(a); setBusy('') }).catch((e) => { setErr(String((e && e.message) || e)); setBusy('') }) } }, '↻ 刷新'),
|
||||
el('button', { style: Object.assign({}, S.btn(false), { borderColor: 'transparent', background: 'transparent' }), onClick: () => onClose && onClose() }, '✕'),
|
||||
),
|
||||
),
|
||||
@@ -159,11 +202,20 @@
|
||||
el('button', { style: Object.assign({}, S.btn(false), { borderColor: 'transparent', background: 'transparent' }), onClick: () => setSel(new Set()) }, '取消选择'),
|
||||
),
|
||||
) : null,
|
||||
msg ? el('div', { style: { padding: '0 16px 8px', fontSize: '11px', color: '#2f5fa8' } }, msg) : null,
|
||||
msg ? el('div', { style: { padding: '0 16px 8px', fontSize: '11px', color: '#2f5fa8', flexShrink: 0 } }, msg) : null,
|
||||
el('div', { style: S.foot },
|
||||
el('span', null, '复制会在当前库新建画板;源库保持不变;名称冲突自动加 (2)'),
|
||||
el('span', null, view.groups ? '按「' + ({ recent: '最近修改', name: '名称', nodes: '节点数', category: '分类' })[sort] + '」分组显示' : ''),
|
||||
el('span', null, '右下角可拖拽调整大小 · 双击复位'),
|
||||
),
|
||||
// 右下角拖拽握把
|
||||
el('div', {
|
||||
title: '拖拽调整窗口大小(双击复位)',
|
||||
onPointerDown: startResize,
|
||||
onDoubleClick: resetSize,
|
||||
style: { position: 'absolute', right: '2px', bottom: '2px', width: '18px', height: '18px', cursor: 'nwse-resize', display: 'flex', alignItems: 'flex-end', justifyContent: 'flex-end', color: '#9a9a9a' },
|
||||
}, el('svg', { viewBox: '0 0 16 16', width: 14, height: 14, fill: 'none', stroke: 'currentColor', strokeWidth: 1.2, strokeLinecap: 'round' },
|
||||
el('path', { d: 'M15 9 9 15' }, null), el('path', { d: 'M15 13 13 15' }, null), el('path', { d: 'M15 5 5 15' }, null),
|
||||
)),
|
||||
),
|
||||
),
|
||||
global.document.body,
|
||||
|
||||
Reference in new issue
Block a user