dsh-gufa-code 1.3.118 → 1.3.173
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/README.md +2 -2
- package/client.js +826 -108
- package/desktop/float/bin/gufa-float-macos-arm64 +0 -0
- package/desktop/float/bin/gufa-float-macos-universal +0 -0
- package/desktop/float/bin/gufa-float-macos-x64 +0 -0
- package/desktop/float//345/217/244/346/263/225/347/274/226/347/250/213/346/202/254/346/265/256/345/261/202.app/Contents/Info.plist +2 -2
- package/desktop/float//345/217/244/346/263/225/347/274/226/347/250/213/346/202/254/346/265/256/345/261/202.app/Contents/MacOS/gufa-float +0 -0
- package/docs/KNOWN-PITFALLS.md +76 -0
- package/docs/RELEASE.md +14 -5
- package/host/code.js +41 -0
- package/host/fs.js +35 -0
- package/host/lint.js +152 -2
- package/host/ts-definition.js +212 -0
- package/package.json +2 -1
- package/scripts/selftest-host.mjs +54 -2
- package/scripts/test-editor.mjs +3 -3
- package/src/client/00-core.js +13 -0
- package/src/client/20-editor.js +383 -86
- package/src/client/30-terminal.js +10 -1
- package/src/client/55-backdrop.js +51 -0
- package/src/client/60-dock.js +199 -6
- package/src/client/90-app.js +169 -14
|
@@ -504,6 +504,57 @@ G.BackdropParticles = function BackdropParticles(props) {
|
|
|
504
504
|
return h('canvas', { ref: canvasRef, className: 'gufa-backdrop-particles', 'aria-hidden': 'true', style: { mixBlendMode: 'screen' } })
|
|
505
505
|
}
|
|
506
506
|
|
|
507
|
+
/** 进入古法 IDE 时临时关掉皮肤自身的粒子/动效(它们会在覆盖层下面持续跑 WebGL/rAF);
|
|
508
|
+
* 退出时恢复用户原设置,不改变用户偏好。 */
|
|
509
|
+
let gufaSkinEffectsSaved = null
|
|
510
|
+
G.suspendSkinEffects = function suspendSkinEffects() {
|
|
511
|
+
try {
|
|
512
|
+
if (gufaSkinEffectsSaved !== null) return
|
|
513
|
+
const raw = localStorage.getItem(SKIN_SETTINGS_KEY)
|
|
514
|
+
if (raw === null || raw === '') return
|
|
515
|
+
const record = JSON.parse(raw)
|
|
516
|
+
if (record === null || typeof record !== 'object' || record.values === null || typeof record.values !== 'object') return
|
|
517
|
+
const values = record.values
|
|
518
|
+
if (values.particlesEnabled !== true && values.motionEnabled !== true) return
|
|
519
|
+
gufaSkinEffectsSaved = raw
|
|
520
|
+
const next = { ...record, values: { ...values, particlesEnabled: false, motionEnabled: false } }
|
|
521
|
+
const payload = JSON.stringify(next)
|
|
522
|
+
localStorage.setItem(SKIN_SETTINGS_KEY, payload)
|
|
523
|
+
try {
|
|
524
|
+
window.dispatchEvent(new StorageEvent('storage', {
|
|
525
|
+
key: SKIN_SETTINGS_KEY,
|
|
526
|
+
oldValue: raw,
|
|
527
|
+
newValue: payload,
|
|
528
|
+
storageArea: localStorage,
|
|
529
|
+
}))
|
|
530
|
+
} catch {
|
|
531
|
+
/* ignore */
|
|
532
|
+
}
|
|
533
|
+
} catch {
|
|
534
|
+
gufaSkinEffectsSaved = null
|
|
535
|
+
}
|
|
536
|
+
}
|
|
537
|
+
G.resumeSkinEffects = function resumeSkinEffects() {
|
|
538
|
+
try {
|
|
539
|
+
if (gufaSkinEffectsSaved === null) return
|
|
540
|
+
const raw = gufaSkinEffectsSaved
|
|
541
|
+
gufaSkinEffectsSaved = null
|
|
542
|
+
localStorage.setItem(SKIN_SETTINGS_KEY, raw)
|
|
543
|
+
try {
|
|
544
|
+
window.dispatchEvent(new StorageEvent('storage', {
|
|
545
|
+
key: SKIN_SETTINGS_KEY,
|
|
546
|
+
oldValue: null,
|
|
547
|
+
newValue: raw,
|
|
548
|
+
storageArea: localStorage,
|
|
549
|
+
}))
|
|
550
|
+
} catch {
|
|
551
|
+
/* ignore */
|
|
552
|
+
}
|
|
553
|
+
} catch {
|
|
554
|
+
/* ignore */
|
|
555
|
+
}
|
|
556
|
+
}
|
|
557
|
+
|
|
507
558
|
/** 背景浓度滑杆(无级、连续;双击恢复「跟随皮肤」)。 */
|
|
508
559
|
G.BackdropStrengthSlider = function BackdropStrengthSlider(props) {
|
|
509
560
|
const t = G.useT()
|
package/src/client/60-dock.js
CHANGED
|
@@ -52,6 +52,8 @@ function gufaRestoreDockTarget(node, saved) {
|
|
|
52
52
|
}
|
|
53
53
|
}
|
|
54
54
|
|
|
55
|
+
G.findConversationRoot = gufaFindConversationRoot
|
|
56
|
+
|
|
55
57
|
/**
|
|
56
58
|
* 把会话根浮到停靠区的位置与尺寸;返回是否成功。
|
|
57
59
|
*
|
|
@@ -63,6 +65,7 @@ function gufaRestoreDockTarget(node, saved) {
|
|
|
63
65
|
* 用「测实际位置 → 补偿差值」迭代 2 次把会话对齐到停靠区。
|
|
64
66
|
*/
|
|
65
67
|
function gufaPlaceDockedConversation(root, host, options) {
|
|
68
|
+
try { root.removeAttribute('data-gufa-hide') } catch { /* ignore */ }
|
|
66
69
|
const rect = host.getBoundingClientRect()
|
|
67
70
|
if (!(rect.width >= 80 && rect.height >= 80)) return false
|
|
68
71
|
const target = { left: Math.round(rect.left), top: Math.round(rect.top), width: Math.round(rect.width), height: Math.round(rect.height) }
|
|
@@ -88,10 +91,20 @@ function gufaPlaceDockedConversation(root, host, options) {
|
|
|
88
91
|
let floatMode = false
|
|
89
92
|
try { floatMode = document.documentElement.hasAttribute('data-gufa-float') } catch { floatMode = false }
|
|
90
93
|
if (floatMode) root.style.background = dockBackground === '' ? 'rgba(13, 15, 19, 0.55)' : `color-mix(in srgb, ${dockBackground} 45%, transparent)`
|
|
91
|
-
else if (backdropMode
|
|
94
|
+
else if (backdropMode) {
|
|
95
|
+
/* 背景模式下必须半透明:解析不到实色时也用 color-mix + 变量兜底,
|
|
96
|
+
不能掉进不透明实色分支(之前右侧对话背景变实色就是这个原因)。 */
|
|
97
|
+
root.style.background = dockBackground === ''
|
|
98
|
+
? 'color-mix(in srgb, var(--gufa-solid-bg, #1a1b1f) 34%, transparent)'
|
|
99
|
+
: `color-mix(in srgb, ${dockBackground} 34%, transparent)`
|
|
100
|
+
}
|
|
92
101
|
else root.style.background = dockBackground === '' ? 'var(--gufa-solid-bg, #1a1b1f)' : dockBackground
|
|
93
102
|
root.style.borderLeft = '1px solid var(--dsw-alias-border-l1)'
|
|
94
103
|
root.style.boxSizing = 'border-box'
|
|
104
|
+
/* 注意:不要给会话根加 will-change/contain——实测会增加每次滚动时的样式/布局成本 */
|
|
105
|
+
try {
|
|
106
|
+
root.style.contain = 'layout paint'
|
|
107
|
+
} catch { /* ignore */ }
|
|
95
108
|
root.style.setProperty('--dsh-chat-user-width', 'calc(100% - 24px)')
|
|
96
109
|
root.style.setProperty('--dsh-conversation-column-width', `${target.width}px`)
|
|
97
110
|
root.setAttribute('data-gufa-dock', '1')
|
|
@@ -416,6 +429,68 @@ G.__dock = {
|
|
|
416
429
|
restore: gufaRestoreDockTarget,
|
|
417
430
|
}
|
|
418
431
|
|
|
432
|
+
/** 从 DSH 会话里的文件引用按钮提取路径/行号,然后在古法编辑器里打开。 */
|
|
433
|
+
function gufaParseMentionButton(button) {
|
|
434
|
+
if (button === null || button === undefined || typeof button.closest !== 'function') return null
|
|
435
|
+
const className = typeof button.className === 'string' ? button.className : ''
|
|
436
|
+
const dataRef = typeof button.getAttribute === 'function' ? (button.getAttribute('data-ref-chip') ?? '') : ''
|
|
437
|
+
const isMention = className.includes('fileMention') || className.includes('fileLink') || dataRef !== ''
|
|
438
|
+
if (!isMention) return null
|
|
439
|
+
const title = typeof button.getAttribute === 'function' ? (button.getAttribute('title') ?? '').trim() : ''
|
|
440
|
+
const text = String(button.textContent ?? '').replace(/\s+/g, ' ').trim()
|
|
441
|
+
const parseRef = (value) => {
|
|
442
|
+
const source = String(value ?? '').trim()
|
|
443
|
+
if (source === '') return null
|
|
444
|
+
const match = /^(.*?)(?::(\d+)(?:\s*[-,]\s*\d+)*|#L(\d+)(?:-L?\d+)?)$/.exec(source)
|
|
445
|
+
if (match === null) return { path: source, line: 0 }
|
|
446
|
+
return { path: match[1].trim(), line: Number(match[2] ?? match[3]) || 0 }
|
|
447
|
+
}
|
|
448
|
+
const titleLooksPath = /[\\/]/.test(title) || /\.[A-Za-z0-9]{1,8}$/.test(title)
|
|
449
|
+
const fromTitle = titleLooksPath ? parseRef(title) : null
|
|
450
|
+
const fromText = parseRef(text)
|
|
451
|
+
/* 关键:title 通常只有完整路径(无行号),行号在按钮文本 `xxx.js:165` 里;
|
|
452
|
+
两者要合并,不能 title 命中就忽略文本的行号。 */
|
|
453
|
+
let path = fromTitle !== null && fromTitle.path !== '' ? fromTitle.path : (fromText !== null ? fromText.path : '')
|
|
454
|
+
let line = (fromTitle !== null ? fromTitle.line : 0) || (fromText !== null ? fromText.line : 0)
|
|
455
|
+
if (path === '') return null
|
|
456
|
+
if (dataRef !== '') {
|
|
457
|
+
let dataPath = ''
|
|
458
|
+
let dataLine = 0
|
|
459
|
+
if (dataRef.trim().startsWith('{')) {
|
|
460
|
+
try {
|
|
461
|
+
const parsedData = JSON.parse(dataRef)
|
|
462
|
+
dataPath = typeof parsedData?.path === 'string' ? parsedData.path : ''
|
|
463
|
+
dataLine = Number(parsedData?.line) || 0
|
|
464
|
+
} catch {
|
|
465
|
+
/* ignore */
|
|
466
|
+
}
|
|
467
|
+
}
|
|
468
|
+
if (dataPath !== '') {
|
|
469
|
+
path = dataPath
|
|
470
|
+
if (dataLine > 0) line = dataLine
|
|
471
|
+
}
|
|
472
|
+
}
|
|
473
|
+
return { path: path.replace(/^\.\//, ''), line }
|
|
474
|
+
}
|
|
475
|
+
|
|
476
|
+
async function gufaOpenMention(mention) {
|
|
477
|
+
if (mention === null || mention === undefined || typeof mention.path !== 'string' || mention.path === '') return
|
|
478
|
+
const root = typeof G.projectRoot === 'string' ? G.projectRoot.replace(/\\/g, '/').replace(/\/+$/, '') : ''
|
|
479
|
+
if (root === '') return
|
|
480
|
+
let resolved = null
|
|
481
|
+
try {
|
|
482
|
+
resolved = await G.api('code.resolvePath', { root, path: mention.path })
|
|
483
|
+
} catch {
|
|
484
|
+
return
|
|
485
|
+
}
|
|
486
|
+
if (resolved === null || resolved === undefined || typeof resolved.path !== 'string' || resolved.path === '') return
|
|
487
|
+
try {
|
|
488
|
+
G.bus.emit('editor:open-at', { path: resolved.path, line: Math.max(1, Number(mention.line) || 1), column: 1 })
|
|
489
|
+
} catch {
|
|
490
|
+
/* ignore */
|
|
491
|
+
}
|
|
492
|
+
}
|
|
493
|
+
|
|
419
494
|
/**
|
|
420
495
|
* 停靠栏:官方会话本体(浮动) + 顶部工具条(新建会话 / 打开完整对话 / 收起)。
|
|
421
496
|
* props = { project, activeFile, selection, theme, width, onInsertCode, backdrop, active, sessionTitle, sessions, onOpenSession }
|
|
@@ -429,11 +504,56 @@ G.ChatDock = function ChatDock(props) {
|
|
|
429
504
|
if (followRef.current === null) followRef.current = gufaCreateChatFollowKeeper()
|
|
430
505
|
const tickRef = useRef(null)
|
|
431
506
|
const startedRef = useRef(0)
|
|
507
|
+
const mentionRootRef = useRef(null)
|
|
508
|
+
const mentionHandlerRef = useRef(null)
|
|
509
|
+
const detachMentionRef = useRef(null)
|
|
432
510
|
const [phase, setPhase] = useState('searching')
|
|
433
511
|
const [error, setError] = useState('')
|
|
434
512
|
const active = props.active !== false && props.paused !== true
|
|
435
513
|
|
|
514
|
+
const detachMention = useCallback(() => {
|
|
515
|
+
const root = mentionRootRef.current
|
|
516
|
+
const handler = mentionHandlerRef.current
|
|
517
|
+
if (root !== null && handler !== null) {
|
|
518
|
+
try { root.removeEventListener('click', handler, true) } catch { /* ignore */ }
|
|
519
|
+
}
|
|
520
|
+
mentionRootRef.current = null
|
|
521
|
+
mentionHandlerRef.current = null
|
|
522
|
+
}, [])
|
|
523
|
+
detachMentionRef.current = detachMention
|
|
524
|
+
|
|
525
|
+
const ensureMentionHandler = useCallback((root) => {
|
|
526
|
+
if (root === null) {
|
|
527
|
+
detachMention()
|
|
528
|
+
return
|
|
529
|
+
}
|
|
530
|
+
if (mentionRootRef.current === root && mentionHandlerRef.current !== null) return
|
|
531
|
+
detachMention()
|
|
532
|
+
const handler = (event) => {
|
|
533
|
+
try {
|
|
534
|
+
if (event.button !== 0 || event.defaultPrevented === true) return
|
|
535
|
+
const target = event.target instanceof Element ? event.target.closest('button, [data-ref-chip]') : null
|
|
536
|
+
if (target === null) return
|
|
537
|
+
const mention = gufaParseMentionButton(target)
|
|
538
|
+
if (mention === null) return
|
|
539
|
+
event.preventDefault()
|
|
540
|
+
event.stopPropagation()
|
|
541
|
+
void gufaOpenMention(mention)
|
|
542
|
+
} catch {
|
|
543
|
+
/* ignore */
|
|
544
|
+
}
|
|
545
|
+
}
|
|
546
|
+
try {
|
|
547
|
+
root.addEventListener('click', handler, true)
|
|
548
|
+
mentionRootRef.current = root
|
|
549
|
+
mentionHandlerRef.current = handler
|
|
550
|
+
} catch {
|
|
551
|
+
/* ignore */
|
|
552
|
+
}
|
|
553
|
+
}, [detachMention])
|
|
554
|
+
|
|
436
555
|
const undock = useCallback(() => {
|
|
556
|
+
detachMentionRef.current?.()
|
|
437
557
|
const current = dockRef.current
|
|
438
558
|
if (current.root !== null) gufaRestoreDockTarget(current.root, current.saved)
|
|
439
559
|
dockRef.current = { root: null, saved: null }
|
|
@@ -459,6 +579,7 @@ G.ChatDock = function ChatDock(props) {
|
|
|
459
579
|
dockRef.current = { root, saved: gufaSnapshotDockTarget(root) }
|
|
460
580
|
}
|
|
461
581
|
if (gufaPlaceDockedConversation(root, host, { translucent: props.backdrop === true })) {
|
|
582
|
+
ensureMentionHandler(root)
|
|
462
583
|
try {
|
|
463
584
|
const scroller = root.querySelector(GUFA_CONVERSATION_SCROLL_SELECTOR)
|
|
464
585
|
if (scroller !== null && scroller !== undefined) followRef.current?.attach(scroller)
|
|
@@ -467,7 +588,32 @@ G.ChatDock = function ChatDock(props) {
|
|
|
467
588
|
}
|
|
468
589
|
setPhase((previous) => (previous === 'docked' ? previous : 'docked'))
|
|
469
590
|
}
|
|
470
|
-
}, [active, undock, props.backdrop])
|
|
591
|
+
}, [active, undock, props.backdrop, ensureMentionHandler])
|
|
592
|
+
|
|
593
|
+
/* 拖拽分割条时的轻量重定位:只改宿主几何,不 getComputedStyle、不读自身 rect、不 setState。
|
|
594
|
+
完整 tick 每次都会 getComputedStyle + 最多两次 getBoundingClientRect,按帧跑会把拖拽拖卡。 */
|
|
595
|
+
const lightTickRef = useRef(null)
|
|
596
|
+
const lightTick = useCallback(() => {
|
|
597
|
+
const host = hostRef.current
|
|
598
|
+
if (host === null) return
|
|
599
|
+
const root = dockRef.current.root
|
|
600
|
+
if (root === null) return
|
|
601
|
+
try {
|
|
602
|
+
const rect = host.getBoundingClientRect()
|
|
603
|
+
if (!(rect.width >= 80 && rect.height >= 80)) return
|
|
604
|
+
root.style.position = 'fixed'
|
|
605
|
+
root.style.left = `${Math.round(rect.left)}px`
|
|
606
|
+
root.style.top = `${Math.round(rect.top)}px`
|
|
607
|
+
root.style.width = `${Math.round(rect.width)}px`
|
|
608
|
+
root.style.height = `${Math.round(rect.height)}px`
|
|
609
|
+
root.style.setProperty('--dsh-conversation-column-width', `${Math.round(rect.width)}px`)
|
|
610
|
+
} catch {
|
|
611
|
+
/* ignore */
|
|
612
|
+
}
|
|
613
|
+
}, [])
|
|
614
|
+
useEffect(() => {
|
|
615
|
+
lightTickRef.current = lightTick
|
|
616
|
+
}, [lightTick])
|
|
471
617
|
|
|
472
618
|
useEffect(() => {
|
|
473
619
|
tickRef.current = tick
|
|
@@ -482,13 +628,30 @@ G.ChatDock = function ChatDock(props) {
|
|
|
482
628
|
startedRef.current = Date.now()
|
|
483
629
|
setPhase((previous) => (previous === 'docked' ? previous : 'searching'))
|
|
484
630
|
let disposed = false
|
|
631
|
+
/* dock 住之后彻底断开 body MutationObserver:Monaco 滚动会不断增删行 DOM,
|
|
632
|
+
observer 即使不跑 tick,浏览器也要为整棵 body 维护/遍历 mutation record,依然拖慢滚动。
|
|
633
|
+
发现/替换会话根交给 300ms 轮询(未 dock 时才观察)。 */
|
|
634
|
+
let observer = typeof MutationObserver === 'function' ? new MutationObserver(() => { run() }) : null
|
|
635
|
+
let observing = false
|
|
636
|
+
const setObserving = (next) => {
|
|
637
|
+
if (observer === null || observing === next) return
|
|
638
|
+
observing = next
|
|
639
|
+
try {
|
|
640
|
+
if (next) observer.observe(document.body, { childList: true, subtree: true })
|
|
641
|
+
else observer.disconnect()
|
|
642
|
+
} catch {
|
|
643
|
+
/* ignore */
|
|
644
|
+
}
|
|
645
|
+
}
|
|
485
646
|
const run = () => {
|
|
486
|
-
if (
|
|
647
|
+
if (disposed) return
|
|
648
|
+
tickRef.current?.()
|
|
649
|
+
const current = dockRef.current.root
|
|
650
|
+
setObserving(!(current !== null && current.isConnected === true))
|
|
487
651
|
}
|
|
652
|
+
setObserving(true)
|
|
488
653
|
run()
|
|
489
|
-
const timer = window.setInterval(run,
|
|
490
|
-
const observer = typeof MutationObserver === 'function' ? new MutationObserver(run) : null
|
|
491
|
-
if (observer !== null) observer.observe(document.body, { childList: true, subtree: true })
|
|
654
|
+
const timer = window.setInterval(run, 300)
|
|
492
655
|
let resizeObserver = null
|
|
493
656
|
if (typeof ResizeObserver === 'function') {
|
|
494
657
|
resizeObserver = new ResizeObserver(run)
|
|
@@ -513,6 +676,36 @@ G.ChatDock = function ChatDock(props) {
|
|
|
513
676
|
tickRef.current?.()
|
|
514
677
|
}, [props.width, props.backdrop])
|
|
515
678
|
|
|
679
|
+
// 拖拽过程中宽高每帧变化(App 不重渲染),DSH 浮层需要跟着宿主矩形逐帧重定位
|
|
680
|
+
useEffect(() => {
|
|
681
|
+
if (G.bus === undefined || G.bus === null || typeof G.bus.on !== 'function') return undefined
|
|
682
|
+
let frame = 0
|
|
683
|
+
let lastTickAt = 0
|
|
684
|
+
const off = G.bus.on('layout:resize', (detail) => {
|
|
685
|
+
/* 只有横向聊天栏/宽度变化才需要动 DSH 浮层;终端高度拖拽不用每帧重定位 */
|
|
686
|
+
const varName = detail !== null && detail !== undefined && typeof detail.varName === 'string' ? detail.varName : ''
|
|
687
|
+
if (varName !== '' && varName !== '--gufa-w-chat') return
|
|
688
|
+
/* 拖拽中 20fps 足够跟上视觉;每帧 getBoundingClientRect 会强制布局,反而拖慢分割条 */
|
|
689
|
+
const now = Date.now()
|
|
690
|
+
if (now - lastTickAt < 45) return
|
|
691
|
+
lastTickAt = now
|
|
692
|
+
if (frame !== 0) return
|
|
693
|
+
frame = typeof requestAnimationFrame === 'function' ? requestAnimationFrame(() => {
|
|
694
|
+
frame = 0
|
|
695
|
+
lightTickRef.current?.()
|
|
696
|
+
}) : window.setTimeout(() => { frame = 0; lightTickRef.current?.() }, 16)
|
|
697
|
+
})
|
|
698
|
+
return () => {
|
|
699
|
+
try { off?.() } catch { /* ignore */ }
|
|
700
|
+
if (frame !== 0) {
|
|
701
|
+
try {
|
|
702
|
+
if (typeof cancelAnimationFrame === 'function') cancelAnimationFrame(frame)
|
|
703
|
+
else window.clearTimeout(frame)
|
|
704
|
+
} catch { /* ignore */ }
|
|
705
|
+
}
|
|
706
|
+
}
|
|
707
|
+
}, [])
|
|
708
|
+
|
|
516
709
|
const newSession = useCallback(() => {
|
|
517
710
|
const ui = G.ctx === null || G.ctx === undefined ? undefined : G.ctx.get('uiWorkspace')
|
|
518
711
|
if (ui === undefined || ui === null || typeof ui.startSession !== 'function') {
|
package/src/client/90-app.js
CHANGED
|
@@ -81,30 +81,106 @@ function selectSessionCwd(state) {
|
|
|
81
81
|
return picked?.projectionValues?.workingDirectory ?? picked?.cwd ?? null
|
|
82
82
|
}
|
|
83
83
|
|
|
84
|
-
/** 可拖拽尺寸 hook:返回 [size, onMouseDown, setSize]。
|
|
84
|
+
/** 可拖拽尺寸 hook:返回 [size, onMouseDown, setSize]。
|
|
85
|
+
* 拖拽过程只改根节点 CSS 变量(rAF 合帧),不触发 GufaApp 整棵树重渲染;
|
|
86
|
+
* 松手时才 setSize 一次,避免拖边框卡顿。 */
|
|
85
87
|
G.useSplitter = function useSplitter(options) {
|
|
86
|
-
const { initial, min, max, axis = 'x', invert = false, storageKey } = options
|
|
88
|
+
const { initial, min, max, axis = 'x', invert = false, storageKey, cssVar, targetSelector } = options
|
|
87
89
|
const [size, setSize] = useState(() => {
|
|
88
90
|
const stored = storageKey === undefined ? null : Number(localStorage.getItem(storageKey))
|
|
89
91
|
return Number.isFinite(stored) && stored > 0 ? Math.min(max, Math.max(min, stored)) : initial
|
|
90
92
|
})
|
|
93
|
+
const findTarget = () => {
|
|
94
|
+
if (typeof targetSelector !== 'string' || targetSelector === '') return null
|
|
95
|
+
try {
|
|
96
|
+
return typeof document !== 'undefined' ? document.querySelector(targetSelector) : null
|
|
97
|
+
} catch {
|
|
98
|
+
return null
|
|
99
|
+
}
|
|
100
|
+
}
|
|
101
|
+
const applyToTarget = (target, value) => {
|
|
102
|
+
if (target === null || target === undefined) return false
|
|
103
|
+
try {
|
|
104
|
+
if (axis === 'x') target.style.width = `${value}px`
|
|
105
|
+
else target.style.height = `${value}px`
|
|
106
|
+
return true
|
|
107
|
+
} catch {
|
|
108
|
+
return false
|
|
109
|
+
}
|
|
110
|
+
}
|
|
111
|
+
/* 初始/恢复持久化尺寸:直接写目标元素,不往 documentElement 挂 CSS 变量
|
|
112
|
+
(根节点自定义属性变化会让整棵文档(含 Monaco/DSH)样式重算,拖拽时非常伤) */
|
|
113
|
+
React.useLayoutEffect(() => {
|
|
114
|
+
const target = findTarget()
|
|
115
|
+
if (!applyToTarget(target, size)) {
|
|
116
|
+
if (typeof cssVar !== 'string' || cssVar === '') return
|
|
117
|
+
try {
|
|
118
|
+
document.documentElement.style.setProperty(cssVar, `${size}px`)
|
|
119
|
+
} catch {
|
|
120
|
+
/* ignore */
|
|
121
|
+
}
|
|
122
|
+
}
|
|
123
|
+
return undefined
|
|
124
|
+
}, [cssVar, size])
|
|
91
125
|
const onMouseDown = useCallback((event) => {
|
|
92
126
|
if (event.button !== 0) return
|
|
93
127
|
event.preventDefault()
|
|
128
|
+
const splitter = event.currentTarget
|
|
129
|
+
const target = findTarget()
|
|
94
130
|
const startPosition = axis === 'x' ? event.clientX : event.clientY
|
|
95
131
|
const startSize = size
|
|
96
132
|
let latest = size
|
|
97
|
-
|
|
98
|
-
|
|
99
|
-
|
|
133
|
+
let frame = 0
|
|
134
|
+
let pendingPosition = null
|
|
135
|
+
const applySize = () => {
|
|
136
|
+
frame = 0
|
|
137
|
+
if (pendingPosition === null) return
|
|
138
|
+
const delta = (pendingPosition - startPosition) * (invert ? -1 : 1)
|
|
100
139
|
latest = Math.min(max, Math.max(min, startSize + delta))
|
|
101
|
-
|
|
140
|
+
pendingPosition = null
|
|
141
|
+
/* 只改目标元素自身的 width/height:不发散到整个 root 的 CSS 变量 */
|
|
142
|
+
if (!applyToTarget(target, latest)) {
|
|
143
|
+
try {
|
|
144
|
+
if (typeof cssVar === 'string' && cssVar !== '') document.documentElement.style.setProperty(cssVar, `${latest}px`)
|
|
145
|
+
} catch {
|
|
146
|
+
/* ignore */
|
|
147
|
+
}
|
|
148
|
+
}
|
|
149
|
+
/* 聊天栏是 DSH 原生浮层,需要跟着宿主矩形重新定位;终端/Monaco 各自有 ResizeObserver */
|
|
150
|
+
try {
|
|
151
|
+
G.bus.emit('layout:resize', { varName: cssVar ?? '', size: latest })
|
|
152
|
+
} catch {
|
|
153
|
+
/* ignore */
|
|
154
|
+
}
|
|
155
|
+
}
|
|
156
|
+
const onMove = (moveEvent) => {
|
|
157
|
+
pendingPosition = axis === 'x' ? moveEvent.clientX : moveEvent.clientY
|
|
158
|
+
if (frame === 0) {
|
|
159
|
+
frame = typeof requestAnimationFrame === 'function' ? requestAnimationFrame(applySize) : window.setTimeout(applySize, 16)
|
|
160
|
+
}
|
|
102
161
|
}
|
|
103
162
|
const onUp = () => {
|
|
104
163
|
window.removeEventListener('mousemove', onMove)
|
|
105
164
|
window.removeEventListener('mouseup', onUp)
|
|
165
|
+
window.removeEventListener('blur', onUp)
|
|
166
|
+
if (frame !== 0) {
|
|
167
|
+
try {
|
|
168
|
+
if (typeof cancelAnimationFrame === 'function') cancelAnimationFrame(frame)
|
|
169
|
+
else window.clearTimeout(frame)
|
|
170
|
+
} catch {
|
|
171
|
+
/* ignore */
|
|
172
|
+
}
|
|
173
|
+
frame = 0
|
|
174
|
+
}
|
|
175
|
+
if (pendingPosition !== null) applySize()
|
|
176
|
+
setSize(latest)
|
|
106
177
|
document.body.style.cursor = ''
|
|
107
178
|
document.body.style.userSelect = ''
|
|
179
|
+
try {
|
|
180
|
+
if (splitter !== null && splitter !== undefined && typeof splitter.removeAttribute === 'function') splitter.removeAttribute('data-dragging')
|
|
181
|
+
} catch {
|
|
182
|
+
/* ignore */
|
|
183
|
+
}
|
|
108
184
|
if (storageKey !== undefined) {
|
|
109
185
|
try {
|
|
110
186
|
localStorage.setItem(storageKey, String(latest))
|
|
@@ -112,16 +188,35 @@ G.useSplitter = function useSplitter(options) {
|
|
|
112
188
|
/* ignore */
|
|
113
189
|
}
|
|
114
190
|
}
|
|
191
|
+
G.__gufaSplitterDragging = false
|
|
192
|
+
try {
|
|
193
|
+
G.bus.emit('layout:resize-end', { varName: cssVar ?? '', size: latest })
|
|
194
|
+
} catch {
|
|
195
|
+
/* ignore */
|
|
196
|
+
}
|
|
197
|
+
}
|
|
198
|
+
try {
|
|
199
|
+
if (splitter !== null && splitter !== undefined && typeof splitter.setAttribute === 'function') splitter.setAttribute('data-dragging', '')
|
|
200
|
+
} catch {
|
|
201
|
+
/* ignore */
|
|
115
202
|
}
|
|
116
203
|
document.body.style.cursor = axis === 'x' ? 'col-resize' : 'row-resize'
|
|
117
204
|
document.body.style.userSelect = 'none'
|
|
205
|
+
G.__gufaSplitterDragging = true
|
|
206
|
+
try {
|
|
207
|
+
G.bus.emit('layout:resize-start', { varName: cssVar ?? '' })
|
|
208
|
+
} catch {
|
|
209
|
+
/* ignore */
|
|
210
|
+
}
|
|
118
211
|
window.addEventListener('mousemove', onMove)
|
|
119
212
|
window.addEventListener('mouseup', onUp)
|
|
120
|
-
|
|
213
|
+
window.addEventListener('blur', onUp)
|
|
214
|
+
}, [axis, cssVar, invert, max, min, size, storageKey])
|
|
121
215
|
return [size, onMouseDown, setSize]
|
|
122
216
|
}
|
|
123
217
|
|
|
124
|
-
|
|
218
|
+
|
|
219
|
+
|
|
125
220
|
G.GufaApp = function GufaApp(props) {
|
|
126
221
|
const t = G.useT()
|
|
127
222
|
const theme = G.useTheme()
|
|
@@ -281,9 +376,9 @@ G.GufaApp = function GufaApp(props) {
|
|
|
281
376
|
const [modalPending, setModalPending] = useState(false)
|
|
282
377
|
const [modalError, setModalError] = useState('')
|
|
283
378
|
const bootedRef = useRef(false)
|
|
284
|
-
const [explorerWidth, explorerDrag] = G.useSplitter({ initial: 260, min: 190, max: 520, storageKey: 'gufa-code:w:explorer' })
|
|
285
|
-
const [chatWidth, chatDrag] = G.useSplitter({ initial: 430, min: 320, max: 780, axis: 'x', invert: true, storageKey: 'gufa-code:w:chat' })
|
|
286
|
-
const [terminalHeight, terminalDrag] = G.useSplitter({ initial: 230, min: 120, max: 560, axis: 'y', invert: true, storageKey: 'gufa-code:h:terminal' })
|
|
379
|
+
const [explorerWidth, explorerDrag] = G.useSplitter({ initial: 260, min: 190, max: 520, storageKey: 'gufa-code:w:explorer', cssVar: '--gufa-w-explorer', targetSelector: '.gufa-sidepanel' })
|
|
380
|
+
const [chatWidth, chatDrag] = G.useSplitter({ initial: 430, min: 320, max: 780, axis: 'x', invert: true, storageKey: 'gufa-code:w:chat', cssVar: '--gufa-w-chat', targetSelector: '.gufa-chatpane' })
|
|
381
|
+
const [terminalHeight, terminalDrag] = G.useSplitter({ initial: 230, min: 120, max: 560, axis: 'y', invert: true, storageKey: 'gufa-code:h:terminal', cssVar: '--gufa-h-terminal', targetSelector: '.gufa-termpane' })
|
|
287
382
|
useEffect(() => {
|
|
288
383
|
tabsRef.current = tabs
|
|
289
384
|
}, [tabs])
|
|
@@ -710,6 +805,7 @@ G.GufaApp = function GufaApp(props) {
|
|
|
710
805
|
if (project === null) return
|
|
711
806
|
const tab = tabsRef.current.find((item) => item !== null && item.path === path)
|
|
712
807
|
if (tab === undefined) return
|
|
808
|
+
if (tab.external === true) return
|
|
713
809
|
/* 缓冲里可能有比 tabs 更新的内容(按键后 300ms 内保存/自动保存) */
|
|
714
810
|
const content = editorBuffersRef.current.has(path) ? editorBuffersRef.current.get(path) : tab.content
|
|
715
811
|
if (content === tab.savedContent) {
|
|
@@ -1161,6 +1257,65 @@ G.GufaApp = function GufaApp(props) {
|
|
|
1161
1257
|
}
|
|
1162
1258
|
}, [project, tabs, patchTab, refreshGit, t])
|
|
1163
1259
|
|
|
1260
|
+
/* TS 内置 lib 定义(parseInt/Promise 等):以只读标签打开 */
|
|
1261
|
+
const openExternalTab = useCallback(async (detail) => {
|
|
1262
|
+
if (detail === null || detail === undefined) return
|
|
1263
|
+
const absolutePath = typeof detail.absolutePath === 'string' ? detail.absolutePath : ''
|
|
1264
|
+
const libName = typeof detail.libName === 'string' ? detail.libName : ''
|
|
1265
|
+
if (absolutePath === '' && libName === '') return
|
|
1266
|
+
const relative = libName !== ''
|
|
1267
|
+
? libName
|
|
1268
|
+
: (typeof detail.path === 'string' && detail.path !== '' ? detail.path.replace(/^\/+/, '') : 'lib.d.ts')
|
|
1269
|
+
const pseudoPath = `~typescript/${relative}`
|
|
1270
|
+
flushBuffersRef.current?.()
|
|
1271
|
+
const existing = (tabsRef.current ?? []).find((tab) => tab !== null && tab !== undefined && tab.path === pseudoPath)
|
|
1272
|
+
if (existing !== undefined) {
|
|
1273
|
+
setActivePath(pseudoPath)
|
|
1274
|
+
window.setTimeout(() => {
|
|
1275
|
+
try {
|
|
1276
|
+
G.bus.emit('editor:reveal', { path: pseudoPath, line: Number(detail.line) || 1, column: Number(detail.column) || 1 })
|
|
1277
|
+
} catch {
|
|
1278
|
+
/* ignore */
|
|
1279
|
+
}
|
|
1280
|
+
}, 120)
|
|
1281
|
+
return
|
|
1282
|
+
}
|
|
1283
|
+
const doc = await G.api('code.readTsLib', libName !== '' ? { libName } : { absolutePath })
|
|
1284
|
+
const content = doc !== null && doc !== undefined && typeof doc.content === 'string' ? doc.content : ''
|
|
1285
|
+
const tab = {
|
|
1286
|
+
path: pseudoPath,
|
|
1287
|
+
content,
|
|
1288
|
+
savedContent: content,
|
|
1289
|
+
revision: 'external',
|
|
1290
|
+
savedRevision: 'external',
|
|
1291
|
+
dirty: false,
|
|
1292
|
+
size: content.length,
|
|
1293
|
+
language: doc !== null && doc !== undefined && typeof doc.language === 'string' ? doc.language : 'typescript',
|
|
1294
|
+
external: true,
|
|
1295
|
+
absolutePath: detail.absolutePath,
|
|
1296
|
+
name: doc !== null && doc !== undefined && typeof doc.name === 'string' ? doc.name : pseudoPath,
|
|
1297
|
+
}
|
|
1298
|
+
setTabs((current) => (current.some((item) => item !== null && item !== undefined && item.path === pseudoPath) ? current : [...current, tab]))
|
|
1299
|
+
setActivePath(pseudoPath)
|
|
1300
|
+
window.setTimeout(() => {
|
|
1301
|
+
try {
|
|
1302
|
+
G.bus.emit('editor:reveal', { path: pseudoPath, line: Number(detail.line) || 1, column: Number(detail.column) || 1 })
|
|
1303
|
+
} catch {
|
|
1304
|
+
/* ignore */
|
|
1305
|
+
}
|
|
1306
|
+
}, 120)
|
|
1307
|
+
}, [])
|
|
1308
|
+
|
|
1309
|
+
useEffect(() => {
|
|
1310
|
+
if (G.bus === null || G.bus === undefined || typeof G.bus.on !== 'function') return undefined
|
|
1311
|
+
const offExternal = G.bus.on('editor:open-external', (detail) => {
|
|
1312
|
+
void openExternalTab(detail).catch((error) => setBanner(G.errorText(error)))
|
|
1313
|
+
})
|
|
1314
|
+
return () => {
|
|
1315
|
+
offExternal?.()
|
|
1316
|
+
}
|
|
1317
|
+
}, [openExternalTab])
|
|
1318
|
+
|
|
1164
1319
|
/* 自动保存:dirty 后 700ms 静默保存(普通文件 / 工作树 diff / 两文件对比) */
|
|
1165
1320
|
const saveFileRef = useRef(null)
|
|
1166
1321
|
const saveCompareRef = useRef(null)
|
|
@@ -2460,7 +2615,7 @@ G.GufaApp = function GufaApp(props) {
|
|
|
2460
2615
|
{
|
|
2461
2616
|
className: 'gufa-root',
|
|
2462
2617
|
'data-backdrop': backdropActive ? 'on' : undefined,
|
|
2463
|
-
style: { '--gufa-dock-width': ui.chatOpen ?
|
|
2618
|
+
style: { '--gufa-dock-width': ui.chatOpen ? `var(--gufa-w-chat, ${Math.round(chatWidth)}px)` : '0px' },
|
|
2464
2619
|
},
|
|
2465
2620
|
backdropActive ? h(G.SkinBackdrop, { meta: skinBackdrop, enabled: true, strength: backdropStrength }) : null,
|
|
2466
2621
|
h(
|
|
@@ -2595,7 +2750,7 @@ G.GufaApp = function GufaApp(props) {
|
|
|
2595
2750
|
? null
|
|
2596
2751
|
: h(
|
|
2597
2752
|
'div',
|
|
2598
|
-
{ className: 'gufa-sidepanel', style: { width: explorerWidth } },
|
|
2753
|
+
{ className: 'gufa-sidepanel', style: { width: `var(--gufa-w-explorer, ${explorerWidth}px)` } },
|
|
2599
2754
|
h('div', { style: { flex: '1 1 auto', minHeight: 0, display: 'flex', flexDirection: 'column' } }, leftPanel),
|
|
2600
2755
|
),
|
|
2601
2756
|
ui.sidebarOpen === false ? null : h('div', { className: 'gufa-splitter', onMouseDown: explorerDrag, title: '' }),
|
|
@@ -2677,7 +2832,7 @@ G.GufaApp = function GufaApp(props) {
|
|
|
2677
2832
|
h('div', { className: 'gufa-splitter', onMouseDown: chatDrag }),
|
|
2678
2833
|
h(
|
|
2679
2834
|
'div',
|
|
2680
|
-
{ className: 'gufa-chatpane', style: { width: chatWidth } },
|
|
2835
|
+
{ className: 'gufa-chatpane', style: { width: `var(--gufa-w-chat, ${chatWidth}px)` } },
|
|
2681
2836
|
h(G.ChatDock, {
|
|
2682
2837
|
project,
|
|
2683
2838
|
activeFile: activeFileForChat,
|