dsh-gufa-code 1.3.215 → 1.3.218
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 +59 -20
- package/client.js +216 -28
- package/docs/screenshot-git.jpg +0 -0
- package/docs/screenshot-main.jpg +0 -0
- package/docs/screenshot-moyu.jpg +0 -0
- package/host/code.js +86 -5
- package/host/fs.js +98 -3
- package/package.json +1 -1
- package/screenshots.json +3 -1
- package/scripts/selftest-host.mjs +47 -0
- package/src/client/00-core.js +2 -0
- package/src/client/20-editor.js +68 -15
- package/src/client/50-panels.js +116 -5
- package/src/client/58b-drag-ref.js +3 -0
- package/src/client/90-app.js +26 -7
package/src/client/50-panels.js
CHANGED
|
@@ -3,6 +3,8 @@
|
|
|
3
3
|
* 纯展示 + 直接调用 Host API,状态自持;容器在 90-app.js。
|
|
4
4
|
*/
|
|
5
5
|
|
|
6
|
+
const GUFA_EXPLORER_MOVE_TYPE = 'application/x-gufa-explorer-move'
|
|
7
|
+
|
|
6
8
|
/* ── 资源管理器 ────────────────────────────────────────────────────────── */
|
|
7
9
|
G.Explorer = function Explorer(props) {
|
|
8
10
|
const t = G.useT()
|
|
@@ -12,6 +14,8 @@ G.Explorer = function Explorer(props) {
|
|
|
12
14
|
const [selected, setSelected] = useState(() => (props.activePath ? { path: props.activePath, kind: 'file' } : null))
|
|
13
15
|
const [multi, setMulti] = useState([])
|
|
14
16
|
const [clipboard, setClipboard] = useState(null)
|
|
17
|
+
const [dragTarget, setDragTarget] = useState(null)
|
|
18
|
+
const internalDragRef = useRef(null)
|
|
15
19
|
const [menu, setMenu] = useState(null)
|
|
16
20
|
const [menuError, setMenuError] = useState('')
|
|
17
21
|
const [notice, setNotice] = useState('')
|
|
@@ -135,8 +139,12 @@ G.Explorer = function Explorer(props) {
|
|
|
135
139
|
|
|
136
140
|
const copySelection = (paths) => {
|
|
137
141
|
if (!Array.isArray(paths) || paths.length === 0) return
|
|
138
|
-
|
|
142
|
+
const entries = paths.filter((path) => typeof path === 'string' && path !== '')
|
|
143
|
+
if (entries.length === 0) return
|
|
144
|
+
setClipboard({ entries })
|
|
139
145
|
setMenuError('')
|
|
146
|
+
/* 同时写入系统剪贴板(file URL / alias 列表):另一个古法编程实例或 Finder 可以直接粘贴 */
|
|
147
|
+
void G.api('fs.copyToSystemClipboard', { root, from: entries }).catch(() => {})
|
|
140
148
|
}
|
|
141
149
|
|
|
142
150
|
/* 内置剪贴板(IDE 内复制/剪切)优先;没有时读系统剪贴板里的文件/文件夹路径(Finder/资源管理器复制)。 */
|
|
@@ -180,6 +188,59 @@ G.Explorer = function Explorer(props) {
|
|
|
180
188
|
return () => window.removeEventListener('blur', clear)
|
|
181
189
|
}, [])
|
|
182
190
|
|
|
191
|
+
const selectRoot = () => {
|
|
192
|
+
containerRef.current?.focus?.()
|
|
193
|
+
setMulti([])
|
|
194
|
+
setSelected({ path: '', kind: 'dir' })
|
|
195
|
+
}
|
|
196
|
+
|
|
197
|
+
/** 内部拖拽目标目录:拖到文件行 = 其父目录;拖到文件夹/空白 = 文件夹/根目录。 */
|
|
198
|
+
const internalDropTargetDir = (target) => {
|
|
199
|
+
const row = target instanceof Element ? target.closest('[data-edrv-path]') : null
|
|
200
|
+
if (row === null) return ''
|
|
201
|
+
const path = row.getAttribute('data-edrv-path') ?? ''
|
|
202
|
+
const kind = row.getAttribute('data-kind')
|
|
203
|
+
return kind === 'dir' ? path : projectDirOf(path)
|
|
204
|
+
}
|
|
205
|
+
|
|
206
|
+
/** 把资源管理器里拖拽的条目移动到目标目录(根目录传 '')。 */
|
|
207
|
+
const moveEntries = async (paths, targetDir) => {
|
|
208
|
+
const list = (Array.isArray(paths) ? paths : []).filter((path) => typeof path === 'string' && path !== '')
|
|
209
|
+
const movable = list.filter((path) => {
|
|
210
|
+
if (path === targetDir) return false
|
|
211
|
+
if (targetDir !== '' && targetDir.startsWith(`${path}/`)) return false
|
|
212
|
+
return true
|
|
213
|
+
})
|
|
214
|
+
if (movable.length === 0) return
|
|
215
|
+
showNotice(`正在移动 ${movable.length} 项…`)
|
|
216
|
+
const failed = []
|
|
217
|
+
let moved = 0
|
|
218
|
+
let last = null
|
|
219
|
+
for (const path of movable) {
|
|
220
|
+
const base = path.split('/').filter(Boolean).pop() ?? path
|
|
221
|
+
const nextPath = targetDir === '' ? base : `${targetDir}/${base}`
|
|
222
|
+
if (nextPath === path) continue
|
|
223
|
+
try {
|
|
224
|
+
await G.api('fs.rename', { root, path, nextPath })
|
|
225
|
+
moved += 1
|
|
226
|
+
last = { path: nextPath, kind: kindByPathRef.current.get(path) ?? 'file' }
|
|
227
|
+
} catch (error) {
|
|
228
|
+
failed.push(`${path}:${G.errorText(error)}`)
|
|
229
|
+
}
|
|
230
|
+
}
|
|
231
|
+
const dirsToRefresh = new Set(['', targetDir])
|
|
232
|
+
for (const path of movable) dirsToRefresh.add(projectDirOf(path))
|
|
233
|
+
for (const dir of dirsToRefresh) void loadDir(dir)
|
|
234
|
+
props.onChanged?.()
|
|
235
|
+
if (last !== null) {
|
|
236
|
+
setMulti([])
|
|
237
|
+
setSelected(last)
|
|
238
|
+
if (last.kind === 'dir') setExpanded((current) => ({ ...current, [last.path]: true }))
|
|
239
|
+
}
|
|
240
|
+
if (moved > 0) showNotice(`已移动 ${moved} 项${failed.length > 0 ? `,${failed.length} 项失败` : ''}`)
|
|
241
|
+
else if (failed.length > 0) showNotice(`移动失败:${failed[0]}`)
|
|
242
|
+
}
|
|
243
|
+
|
|
183
244
|
const noticeRef = useRef(0)
|
|
184
245
|
const showNotice = (text) => {
|
|
185
246
|
setNotice(text)
|
|
@@ -332,6 +393,8 @@ G.Explorer = function Explorer(props) {
|
|
|
332
393
|
'data-git-status': status !== undefined ? status : undefined,
|
|
333
394
|
/* 给 dsh-drag-ref 用:把资源管理器行变成可拖拽的 @ 引用来源 */
|
|
334
395
|
'data-edrv-path': entry.path,
|
|
396
|
+
'data-drop': isDir && dragTarget === entry.path ? '' : undefined,
|
|
397
|
+
draggable: true,
|
|
335
398
|
style: { paddingLeft: 8 + depth * 14 },
|
|
336
399
|
title: entry.path,
|
|
337
400
|
onClick: (event) => {
|
|
@@ -355,6 +418,22 @@ G.Explorer = function Explorer(props) {
|
|
|
355
418
|
onDoubleClick: () => {
|
|
356
419
|
if (!isDir) props.onOpenFile?.(entry.path, { preview: false })
|
|
357
420
|
},
|
|
421
|
+
onDragStart: (event) => {
|
|
422
|
+
const dragPaths = multi.length > 0 && multi.includes(entry.path) ? multi.slice() : [entry.path]
|
|
423
|
+
internalDragRef.current = dragPaths
|
|
424
|
+
try {
|
|
425
|
+
if (event.dataTransfer !== null && event.dataTransfer !== undefined) {
|
|
426
|
+
event.dataTransfer.effectAllowed = 'copyMove'
|
|
427
|
+
event.dataTransfer.setData(GUFA_EXPLORER_MOVE_TYPE, JSON.stringify({ paths: dragPaths }))
|
|
428
|
+
}
|
|
429
|
+
} catch {
|
|
430
|
+
/* ignore */
|
|
431
|
+
}
|
|
432
|
+
},
|
|
433
|
+
onDragEnd: () => {
|
|
434
|
+
internalDragRef.current = null
|
|
435
|
+
setDragTarget(null)
|
|
436
|
+
},
|
|
358
437
|
onContextMenu: (event) => openContextMenu(event, entry),
|
|
359
438
|
},
|
|
360
439
|
h(
|
|
@@ -406,28 +485,59 @@ G.Explorer = function Explorer(props) {
|
|
|
406
485
|
},
|
|
407
486
|
onDragOver: (event) => {
|
|
408
487
|
const types = event.dataTransfer?.types
|
|
409
|
-
if (types === undefined || types === null
|
|
488
|
+
if (types === undefined || types === null) return
|
|
489
|
+
const list = Array.from(types)
|
|
490
|
+
if (list.includes(GUFA_EXPLORER_MOVE_TYPE)) {
|
|
491
|
+
event.preventDefault()
|
|
492
|
+
event.stopPropagation()
|
|
493
|
+
if (event.dataTransfer !== null && event.dataTransfer !== undefined) event.dataTransfer.dropEffect = 'move'
|
|
494
|
+
setDragTarget(internalDropTargetDir(event.target))
|
|
495
|
+
return
|
|
496
|
+
}
|
|
497
|
+
if (!list.includes('Files')) return
|
|
410
498
|
event.preventDefault()
|
|
411
499
|
event.stopPropagation()
|
|
412
500
|
event.dataTransfer.dropEffect = 'copy'
|
|
413
501
|
},
|
|
502
|
+
onDragLeave: (event) => {
|
|
503
|
+
if (event.currentTarget instanceof Node && event.relatedTarget instanceof Node && event.currentTarget.contains(event.relatedTarget)) return
|
|
504
|
+
setDragTarget(null)
|
|
505
|
+
},
|
|
414
506
|
onDrop: (event) => {
|
|
507
|
+
const types = event.dataTransfer?.types
|
|
508
|
+
if (types !== undefined && types !== null && Array.from(types).includes(GUFA_EXPLORER_MOVE_TYPE)) {
|
|
509
|
+
event.preventDefault()
|
|
510
|
+
event.stopPropagation()
|
|
511
|
+
const paths = internalDragRef.current
|
|
512
|
+
internalDragRef.current = null
|
|
513
|
+
const targetDir = internalDropTargetDir(event.target)
|
|
514
|
+
setDragTarget(null)
|
|
515
|
+
void moveEntries(paths, targetDir)
|
|
516
|
+
return
|
|
517
|
+
}
|
|
415
518
|
const files = event.dataTransfer?.files
|
|
416
519
|
if (files === undefined || files === null || files.length === 0) return
|
|
417
520
|
event.preventDefault()
|
|
418
521
|
event.stopPropagation()
|
|
419
522
|
void uploadFiles(files, dropTargetDir(event.target))
|
|
420
523
|
},
|
|
524
|
+
onClick: (event) => {
|
|
525
|
+
/* 点击资源管理器空白处:选中根目录,而不是保留上一次选中的文件/文件夹 */
|
|
526
|
+
if (!(event.target instanceof Element)) return
|
|
527
|
+
if (event.target.closest('[data-edrv-path]') !== null) return
|
|
528
|
+
if (event.target.closest('.gufa-panel-head, button, input, textarea, [role="menu"]') !== null) return
|
|
529
|
+
selectRoot()
|
|
530
|
+
},
|
|
421
531
|
onKeyDown: (event) => {
|
|
422
532
|
if (event.key === 'Enter') {
|
|
423
|
-
if (selected === null) return
|
|
533
|
+
if (selected === null || selected.path === '') return
|
|
424
534
|
event.preventDefault()
|
|
425
535
|
props.onRename?.(selected.path)
|
|
426
536
|
return
|
|
427
537
|
}
|
|
428
538
|
const mod = event.metaKey || event.ctrlKey
|
|
429
539
|
if (!mod || event.altKey) {
|
|
430
|
-
if (event.key === 'Delete' && selected !== null) {
|
|
540
|
+
if (event.key === 'Delete' && selected !== null && selected.path !== '') {
|
|
431
541
|
event.preventDefault()
|
|
432
542
|
props.onDelete?.(selected.path)
|
|
433
543
|
}
|
|
@@ -442,7 +552,7 @@ G.Explorer = function Explorer(props) {
|
|
|
442
552
|
void pasteInto(selectedDir())
|
|
443
553
|
} else if (key === 'backspace' || event.key === 'Delete') {
|
|
444
554
|
event.preventDefault()
|
|
445
|
-
if (selected !== null) props.onDelete?.(selected.path)
|
|
555
|
+
if (selected !== null && selected.path !== '') props.onDelete?.(selected.path)
|
|
446
556
|
}
|
|
447
557
|
},
|
|
448
558
|
},
|
|
@@ -462,6 +572,7 @@ G.Explorer = function Explorer(props) {
|
|
|
462
572
|
'div',
|
|
463
573
|
{
|
|
464
574
|
className: 'gufa-panel-body gufa-scroll',
|
|
575
|
+
'data-drop-root': dragTarget === '' ? '' : undefined,
|
|
465
576
|
onContextMenu: (event) => {
|
|
466
577
|
try {
|
|
467
578
|
if (event.target !== null && event.target !== undefined && typeof event.target.closest === 'function' && event.target.closest('.gufa-tree-row') !== null) return
|
|
@@ -261,6 +261,9 @@ function install(ctx) {
|
|
|
261
261
|
};
|
|
262
262
|
const onDrop = (event) => {
|
|
263
263
|
if (!isOurs(event.dataTransfer)) return;
|
|
264
|
+
/* 资源管理器内部拖拽移动文件:交给 Explorer 自己的 drop 处理,不当作 @ 引用插入 */
|
|
265
|
+
if (event.dataTransfer !== null && Array.prototype.indexOf.call(event.dataTransfer.types, "application/x-gufa-explorer-move") !== -1
|
|
266
|
+
&& event.target instanceof Element && event.target.closest(".gufa-sidepanel") !== null) return;
|
|
264
267
|
if (dropZoneOf(event.target) === null) {
|
|
265
268
|
toast("松手位置不在输入框内,未插入", "err");
|
|
266
269
|
return;
|
package/src/client/90-app.js
CHANGED
|
@@ -351,6 +351,9 @@ G.GufaApp = function GufaApp(props) {
|
|
|
351
351
|
const [banner, setBanner] = useState('')
|
|
352
352
|
const [tabs, setTabs] = useState([])
|
|
353
353
|
const [activePath, setActivePath] = useState(null)
|
|
354
|
+
const activePathRef = useRef(activePath)
|
|
355
|
+
activePathRef.current = activePath
|
|
356
|
+
const pendingOpenAtRef = useRef(null)
|
|
354
357
|
/* 选区(给右侧 AI 用)单独更新;光标位置/行数走 G.cursorStore,避免每次按键重渲染整个 IDE。 */
|
|
355
358
|
const [selection, setSelection] = useState(null)
|
|
356
359
|
/* 编辑器内容缓冲:Monaco 每次按键只写这里,300ms 停顿后才同步进 tabs(保存/自动保存直接读缓冲)。 */
|
|
@@ -693,15 +696,31 @@ G.GufaApp = function GufaApp(props) {
|
|
|
693
696
|
await openFile(path)
|
|
694
697
|
const targetLine = Number.isFinite(Number(line)) ? Math.max(1, Math.trunc(Number(line))) : 1
|
|
695
698
|
const targetColumn = Number.isFinite(Number(column)) ? Math.max(1, Math.trunc(Number(column))) : 1
|
|
696
|
-
|
|
697
|
-
|
|
698
|
-
|
|
699
|
-
|
|
700
|
-
|
|
701
|
-
|
|
702
|
-
|
|
699
|
+
const target = { path, line: targetLine, column: targetColumn }
|
|
700
|
+
const currentActive = activePathRef.current === null ? null : gufaNormalizeProjectPath(activePathRef.current)
|
|
701
|
+
if (currentActive === path) {
|
|
702
|
+
/* 文件本来就打开着:编辑器/model 已就绪,延迟一帧即可 */
|
|
703
|
+
window.setTimeout(() => {
|
|
704
|
+
try { G.bus.emit('editor:reveal', target) } catch { /* ignore */ }
|
|
705
|
+
}, 80)
|
|
706
|
+
return
|
|
707
|
+
}
|
|
708
|
+
/* 文件未打开:交给 activePath effect,在 tab 真正切过去之后再 reveal(避免固定 120ms 的竞态) */
|
|
709
|
+
pendingOpenAtRef.current = target
|
|
703
710
|
}, [openFile])
|
|
704
711
|
|
|
712
|
+
/* 未打开文件跳转:activePath 切到目标文件后(子组件编辑器 effect 已先行)再发 reveal */
|
|
713
|
+
useEffect(() => {
|
|
714
|
+
const pending = pendingOpenAtRef.current
|
|
715
|
+
if (pending === null || pending === undefined) return undefined
|
|
716
|
+
if (activePath === null || gufaNormalizeProjectPath(activePath) !== gufaNormalizeProjectPath(pending.path)) return undefined
|
|
717
|
+
pendingOpenAtRef.current = null
|
|
718
|
+
const timer = window.setTimeout(() => {
|
|
719
|
+
try { G.bus.emit('editor:reveal', pending) } catch { /* ignore */ }
|
|
720
|
+
}, 40)
|
|
721
|
+
return () => window.clearTimeout(timer)
|
|
722
|
+
}, [activePath])
|
|
723
|
+
|
|
705
724
|
/* Cmd/Ctrl+点击定义:编辑器 → App 跳转 / 多结果选择(兜底搜索在 host/code.js) */
|
|
706
725
|
useEffect(() => {
|
|
707
726
|
if (G.bus === null || G.bus === undefined || typeof G.bus.on !== 'function') return undefined
|