dsh-gufa-code 1.0.1 → 1.1.0
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 +3 -0
- package/client.js +575 -35
- package/host/fs.js +95 -0
- package/host/git.js +0 -112
- package/package.json +1 -1
- package/scripts/test-editor.mjs +4 -13
- package/src/client/00-core.js +57 -0
- package/src/client/20-editor.js +54 -9
- package/src/client/50-panels.js +96 -0
- package/src/client/58-insert-ref.js +156 -0
- package/src/client/90-app.js +168 -26
- package/src/client/99-main.js +41 -0
- package/vendor/monaco/vs/worker-bootstrap.js +16 -0
package/host/fs.js
CHANGED
|
@@ -240,6 +240,101 @@ export function register(router, env) {
|
|
|
240
240
|
return { copied }
|
|
241
241
|
})
|
|
242
242
|
|
|
243
|
+
/** 把系统剪贴板里的文件匹配回项目内已有文件(供聊天框「粘贴文件→@引用」使用)。 */
|
|
244
|
+
router.method('fs.matchFiles', async (body) => {
|
|
245
|
+
const root = await projectOf(env, body)
|
|
246
|
+
const wanted = Array.isArray(body.files)
|
|
247
|
+
? body.files.filter((file) => file !== null && typeof file === 'object'
|
|
248
|
+
&& typeof file.name === 'string' && file.name !== ''
|
|
249
|
+
&& Number.isFinite(file.size) && typeof file.sha256 === 'string' && file.sha256 !== '')
|
|
250
|
+
: []
|
|
251
|
+
if (wanted.length === 0) return { matches: [] }
|
|
252
|
+
const EXCLUDED = new Set(['node_modules', '.git', 'dist', 'build', 'out', '.next', 'vendor', 'target', '.venv', 'venv', '__pycache__', '.idea', '.cache'])
|
|
253
|
+
const byName = new Map()
|
|
254
|
+
const stack = ['']
|
|
255
|
+
let scanned = 0
|
|
256
|
+
while (stack.length > 0 && scanned < 40000) {
|
|
257
|
+
const dirRel = stack.pop()
|
|
258
|
+
let entries
|
|
259
|
+
try {
|
|
260
|
+
entries = await readdir(join(root, dirRel), { withFileTypes: true })
|
|
261
|
+
} catch {
|
|
262
|
+
continue
|
|
263
|
+
}
|
|
264
|
+
for (const entry of entries) {
|
|
265
|
+
const childRel = dirRel === '' ? entry.name : `${dirRel}/${entry.name}`
|
|
266
|
+
if (entry.isDirectory()) {
|
|
267
|
+
if (!EXCLUDED.has(entry.name)) stack.push(childRel)
|
|
268
|
+
continue
|
|
269
|
+
}
|
|
270
|
+
if (!entry.isFile()) continue
|
|
271
|
+
scanned += 1
|
|
272
|
+
const list = byName.get(entry.name) ?? []
|
|
273
|
+
if (list.length < 200) list.push(childRel)
|
|
274
|
+
byName.set(entry.name, list)
|
|
275
|
+
}
|
|
276
|
+
}
|
|
277
|
+
const hashFile = (absolute) => new Promise((resolve) => {
|
|
278
|
+
try {
|
|
279
|
+
const hash = createHash('sha256')
|
|
280
|
+
const stream = createReadStream(absolute)
|
|
281
|
+
stream.on('data', (chunk) => hash.update(chunk))
|
|
282
|
+
stream.on('error', () => resolve(''))
|
|
283
|
+
stream.on('end', () => resolve(hash.digest('hex')))
|
|
284
|
+
} catch {
|
|
285
|
+
resolve('')
|
|
286
|
+
}
|
|
287
|
+
})
|
|
288
|
+
const matches = []
|
|
289
|
+
for (const want of wanted) {
|
|
290
|
+
let hit = null
|
|
291
|
+
for (const rel of byName.get(want.name) ?? []) {
|
|
292
|
+
const absolute = join(root, rel)
|
|
293
|
+
const info = await stat(absolute).catch(() => undefined)
|
|
294
|
+
if (info === undefined || !info.isFile() || info.size !== want.size) continue
|
|
295
|
+
const digest = await hashFile(absolute)
|
|
296
|
+
if (digest === want.sha256) {
|
|
297
|
+
hit = rel
|
|
298
|
+
break
|
|
299
|
+
}
|
|
300
|
+
}
|
|
301
|
+
matches.push({ name: want.name, path: hit })
|
|
302
|
+
}
|
|
303
|
+
return { matches }
|
|
304
|
+
})
|
|
305
|
+
|
|
306
|
+
/** 上传文件到项目目录(系统剪贴板粘贴 / 从 Finder 拖入资源管理器)。 */
|
|
307
|
+
router.method('fs.upload', async (body) => {
|
|
308
|
+
const root = await projectOf(env, body)
|
|
309
|
+
const dirRel = typeof body.dir === 'string' ? body.dir : ''
|
|
310
|
+
const dir = await resolveProjectPath(root, dirRel)
|
|
311
|
+
const dirInfo = await stat(dir).catch(() => undefined)
|
|
312
|
+
if (dirInfo === undefined || !dirInfo.isDirectory()) throw new ApiError('not-dir', '目标不是目录', 400)
|
|
313
|
+
if (!Array.isArray(body.files) || body.files.length === 0) throw badRequest('files is required')
|
|
314
|
+
const written = []
|
|
315
|
+
for (const file of body.files) {
|
|
316
|
+
if (file === null || typeof file !== 'object') continue
|
|
317
|
+
const rawName = typeof file.name === 'string' ? file.name : ''
|
|
318
|
+
const base = rawName.split(/[/\\]/).filter(Boolean).pop() || 'file'
|
|
319
|
+
const safeBase = base.replace(/[\u0000-\u001f\u007f]/g, '').trim() || 'file'
|
|
320
|
+
const data = Buffer.from(typeof file.data === 'string' ? file.data : '', 'base64')
|
|
321
|
+
if (data.length > 300 * 1024 * 1024) throw new ApiError('too-large', `文件过大:${safeBase}`, 400)
|
|
322
|
+
let target = join(dir, safeBase)
|
|
323
|
+
let suffix = 1
|
|
324
|
+
while (await stat(target).then(() => true, () => false)) {
|
|
325
|
+
const dot = safeBase.lastIndexOf('.')
|
|
326
|
+
const stem = dot > 0 ? safeBase.slice(0, dot) : safeBase
|
|
327
|
+
const ext = dot > 0 ? safeBase.slice(dot) : ''
|
|
328
|
+
target = join(dir, `${stem} 副本${suffix > 1 ? ` ${suffix}` : ''}${ext}`)
|
|
329
|
+
suffix += 1
|
|
330
|
+
if (suffix > 500) throw new ApiError('upload-name-failed', '无法生成目标文件名', 500)
|
|
331
|
+
}
|
|
332
|
+
await writeFile(target, data, { flag: 'wx' })
|
|
333
|
+
written.push({ path: relativePath(root, target), size: data.length })
|
|
334
|
+
}
|
|
335
|
+
return { written }
|
|
336
|
+
})
|
|
337
|
+
|
|
243
338
|
/** 软删除:移动到系统临时目录,返回可撤销的 id(资源管理器删除后用 ⌘Z 恢复)。 */
|
|
244
339
|
router.method('fs.trash', async (body) => {
|
|
245
340
|
const root = await projectOf(env, body)
|
package/host/git.js
CHANGED
|
@@ -234,118 +234,6 @@ export function register(router, env) {
|
|
|
234
234
|
})
|
|
235
235
|
|
|
236
236
|
/** 撤销指定文件的未暂存改动(git restore --worktree,等价 VS Code 行内还原)。 */
|
|
237
|
-
/** 撤销指定文件的未暂存改动(git restore --worktree,等价 VS Code 行内还原)。 */
|
|
238
|
-
/** 解析 unified diff 文本为:文件头 + 逐 hunk 列表。 */
|
|
239
|
-
function parseUnifiedDiff(text) {
|
|
240
|
-
const lines = String(text).split('\n')
|
|
241
|
-
const headerLines = []
|
|
242
|
-
const hunks = []
|
|
243
|
-
let current = null
|
|
244
|
-
for (const line of lines) {
|
|
245
|
-
if (line.startsWith('@@')) {
|
|
246
|
-
current = { header: line, lines: [line] }
|
|
247
|
-
hunks.push(current)
|
|
248
|
-
continue
|
|
249
|
-
}
|
|
250
|
-
if (current === null) {
|
|
251
|
-
if (line !== '' || headerLines.length > 0) headerLines.push(line)
|
|
252
|
-
continue
|
|
253
|
-
}
|
|
254
|
-
current.lines.push(line)
|
|
255
|
-
}
|
|
256
|
-
/* 去掉末尾空行,避免构造 patch 时出问题 */
|
|
257
|
-
while (hunks.length > 0) {
|
|
258
|
-
const last = hunks[hunks.length - 1]
|
|
259
|
-
while (last.lines.length > 1 && last.lines[last.lines.length - 1] === '') last.lines.pop()
|
|
260
|
-
break
|
|
261
|
-
}
|
|
262
|
-
return { headerLines, hunks }
|
|
263
|
-
}
|
|
264
|
-
|
|
265
|
-
/** 用 stdin 把 patch 交给 git apply(支持 -R)。 */
|
|
266
|
-
function gitApplyWithStdin(root, args, patchText) {
|
|
267
|
-
return new Promise((resolve, reject) => {
|
|
268
|
-
const child = spawn('git', ['-C', root, 'apply', ...args], { stdio: ['pipe', 'pipe', 'pipe'] })
|
|
269
|
-
let stderr = ''
|
|
270
|
-
let stdout = ''
|
|
271
|
-
child.stdout.on('data', (chunk) => { stdout += String(chunk) })
|
|
272
|
-
child.stderr.on('data', (chunk) => { stderr += String(chunk) })
|
|
273
|
-
child.on('error', reject)
|
|
274
|
-
child.on('close', (code) => {
|
|
275
|
-
if (code === 0) resolve(stdout)
|
|
276
|
-
else reject(new Error(stderr.trim() || `git apply 失败(exit ${code})`))
|
|
277
|
-
})
|
|
278
|
-
try {
|
|
279
|
-
child.stdin.end(patchText)
|
|
280
|
-
} catch (error) {
|
|
281
|
-
reject(error)
|
|
282
|
-
}
|
|
283
|
-
})
|
|
284
|
-
}
|
|
285
|
-
|
|
286
|
-
/** 读取文件改动的逐块信息(供「逐块接受/拒绝」)。 */
|
|
287
|
-
router.method('git.hunks', async (body) => {
|
|
288
|
-
const project = await projectOf(env, body)
|
|
289
|
-
const path = typeof body.path === 'string' ? body.path : ''
|
|
290
|
-
if (path === '' || path.startsWith('/') || path.includes('..')) throw badRequest('path is invalid')
|
|
291
|
-
/* 未跟踪的新文件:整文件当作一个新增块 */
|
|
292
|
-
const status = await git(project.root, ['status', '--porcelain=v1', '-z', '--', path]).catch(() => '')
|
|
293
|
-
const classified = parseStatusZ(status)
|
|
294
|
-
const untracked = classified.changes.some((change) => change.untracked === true)
|
|
295
|
-
if (untracked) {
|
|
296
|
-
let content = ''
|
|
297
|
-
try {
|
|
298
|
-
content = await git(project.root, ['show', `:${path}`]).catch(() => '')
|
|
299
|
-
} catch {
|
|
300
|
-
content = ''
|
|
301
|
-
}
|
|
302
|
-
try {
|
|
303
|
-
const { readFile } = await import('node:fs/promises')
|
|
304
|
-
const { join } = await import('node:path')
|
|
305
|
-
content = await readFile(join(project.root, path), 'utf8')
|
|
306
|
-
} catch {
|
|
307
|
-
/* ignore */
|
|
308
|
-
}
|
|
309
|
-
const lines = content.split('\n')
|
|
310
|
-
return {
|
|
311
|
-
untracked: true,
|
|
312
|
-
hunks: [{ id: 'h0', header: '@@ 新文件 @@', lines: lines.map((line) => `+${line}`) }],
|
|
313
|
-
count: 1,
|
|
314
|
-
}
|
|
315
|
-
}
|
|
316
|
-
const patch = await git(project.root, ['diff', '-U3', '--no-color', '--', path], 60_000)
|
|
317
|
-
const parsed = parseUnifiedDiff(patch)
|
|
318
|
-
const hunks = parsed.hunks.map((hunk, index) => ({ id: `h${index}`, header: hunk.header, lines: hunk.lines }))
|
|
319
|
-
return { untracked: false, hunks, count: hunks.length }
|
|
320
|
-
})
|
|
321
|
-
|
|
322
|
-
/** 拒绝指定块(git apply -R 只回滚选中的 hunk)。 */
|
|
323
|
-
router.method('git.rejectHunks', async (body) => {
|
|
324
|
-
const project = await projectOf(env, body)
|
|
325
|
-
const path = typeof body.path === 'string' ? body.path : ''
|
|
326
|
-
if (path === '' || path.startsWith('/') || path.includes('..')) throw badRequest('path is invalid')
|
|
327
|
-
const ids = Array.isArray(body.hunkIds) ? body.hunkIds.filter((item) => typeof item === 'string') : []
|
|
328
|
-
if (ids.length === 0) throw badRequest('hunkIds is required')
|
|
329
|
-
const status = await git(project.root, ['status', '--porcelain=v1', '-z', '--', path]).catch(() => '')
|
|
330
|
-
const classified = parseStatusZ(status)
|
|
331
|
-
const untracked = classified.changes.some((change) => change.untracked === true)
|
|
332
|
-
if (untracked) {
|
|
333
|
-
if (ids.includes('h0')) {
|
|
334
|
-
const { rm } = await import('node:fs/promises')
|
|
335
|
-
const { join } = await import('node:path')
|
|
336
|
-
await rm(join(project.root, path), { force: true })
|
|
337
|
-
}
|
|
338
|
-
return { ok: true }
|
|
339
|
-
}
|
|
340
|
-
const patch = await git(project.root, ['diff', '-U3', '--no-color', '--', path], 60_000)
|
|
341
|
-
const parsed = parseUnifiedDiff(patch)
|
|
342
|
-
const selected = parsed.hunks.filter((hunk, index) => ids.includes(`h${index}`))
|
|
343
|
-
if (selected.length === 0) throw new ApiError('no-hunks', '没有匹配的改动块', 400)
|
|
344
|
-
const subPatch = `${parsed.headerLines.join('\n')}\n${selected.map((hunk) => hunk.lines.join('\n')).join('\n')}\n`
|
|
345
|
-
await gitApplyWithStdin(project.root, ['-R', '--whitespace=nowarn'], subPatch)
|
|
346
|
-
return { ok: true }
|
|
347
|
-
})
|
|
348
|
-
|
|
349
237
|
router.method('git.discard', async (body) => {
|
|
350
238
|
const project = await projectOf(env, body)
|
|
351
239
|
const paths = Array.isArray(body.paths) ? body.paths.filter((item) => typeof item === 'string' && item !== '' && !item.includes('..') && !item.startsWith('/')) : []
|
package/package.json
CHANGED
package/scripts/test-editor.mjs
CHANGED
|
@@ -449,14 +449,9 @@ test('window.require 被非 Monaco 的 AMD loader 占用:拒载,不注入脚
|
|
|
449
449
|
assert.equal(scripts.length, 0)
|
|
450
450
|
})
|
|
451
451
|
|
|
452
|
-
test('worker
|
|
452
|
+
test('worker 工厂用同源 worker-bootstrap.js 作为 Worker 入口', () => {
|
|
453
453
|
const blobs = []
|
|
454
454
|
const workers = []
|
|
455
|
-
class FakeBlob {
|
|
456
|
-
constructor(parts) {
|
|
457
|
-
this.parts = parts
|
|
458
|
-
}
|
|
459
|
-
}
|
|
460
455
|
const fakeURL = {
|
|
461
456
|
createObjectURL(blob) {
|
|
462
457
|
blobs.push(blob)
|
|
@@ -470,10 +465,10 @@ test('worker 工厂在 worker 内先加载 loader、配置 paths.vs,再执行
|
|
|
470
465
|
this.options = options
|
|
471
466
|
workers.push(this)
|
|
472
467
|
}
|
|
468
|
+
addEventListener() {}
|
|
473
469
|
}
|
|
474
470
|
const module = createGufaModule({
|
|
475
471
|
window: { ...createFakeWindow(), MonacoEnvironment: undefined },
|
|
476
|
-
Blob: FakeBlob,
|
|
477
472
|
URL: fakeURL,
|
|
478
473
|
Worker: FakeWorker,
|
|
479
474
|
})
|
|
@@ -484,13 +479,9 @@ test('worker 工厂在 worker 内先加载 loader、配置 paths.vs,再执行
|
|
|
484
479
|
const environment = fakeWindow.MonacoEnvironment
|
|
485
480
|
assert.equal(typeof environment.getWorker, 'function')
|
|
486
481
|
const worker = environment.getWorker('workerMain.js', 'typescript')
|
|
487
|
-
assert.equal(worker.url, '
|
|
482
|
+
assert.equal(worker.url, '/gufa-code/asset/monaco/worker-bootstrap.js?v=3')
|
|
488
483
|
assert.equal(worker.options.name, 'typescript')
|
|
489
|
-
assert.equal(blobs.length,
|
|
490
|
-
const text = blobs[0].parts.join('\n')
|
|
491
|
-
assert.ok(text.includes('/gufa-code/asset/monaco/loader.js'), 'worker 内应加载 loader.js')
|
|
492
|
-
assert.ok(text.includes(`require.config({ paths: { vs: ${JSON.stringify('/gufa-code/asset/monaco')} } })`))
|
|
493
|
-
assert.ok(text.includes('/gufa-code/asset/monaco/base/worker/workerMain.js'))
|
|
484
|
+
assert.equal(blobs.length, 0, '同源 bootstrap 可用时不应再创建 blob worker')
|
|
494
485
|
})
|
|
495
486
|
})
|
|
496
487
|
|
package/src/client/00-core.js
CHANGED
|
@@ -1078,6 +1078,19 @@ html[data-gufa-ide] [role="dialog"] {
|
|
|
1078
1078
|
.gufa-session-group-count{font-size:10.5px;opacity:.6;font-variant-numeric:tabular-nums}
|
|
1079
1079
|
.gufa-session-group[data-current] .gufa-session-group-head{color:var(--gufa-text)}
|
|
1080
1080
|
.gufa-session-group .gufa-session-row{margin-left:10px}
|
|
1081
|
+
.gufa-session-workspace-btn{display:inline-flex;align-items:center;gap:4px;border:1px solid var(--gufa-border);background:var(--gufa-layer2);
|
|
1082
|
+
color:var(--gufa-text-dim);border-radius:7px;padding:2px 8px;font:inherit;font-size:11.5px;cursor:pointer;max-width:260px}
|
|
1083
|
+
.gufa-session-workspace-btn:hover{background:var(--gufa-hover);color:var(--gufa-text)}
|
|
1084
|
+
.gufa-session-workspace-btn span{overflow:hidden;text-overflow:ellipsis;white-space:nowrap}
|
|
1085
|
+
.gufa-session-workspace-picker{display:flex;flex-direction:column;gap:2px;padding:6px 10px;max-height:220px;overflow:auto;
|
|
1086
|
+
border-top:1px solid var(--gufa-border);border-bottom:1px solid var(--gufa-border);background:var(--gufa-layer)}
|
|
1087
|
+
.gufa-session-workspace-option{display:flex;align-items:center;gap:8px;width:100%;padding:6px 8px;border:0;border-radius:7px;
|
|
1088
|
+
background:transparent;color:var(--gufa-text);font:inherit;font-size:12px;cursor:pointer;text-align:left}
|
|
1089
|
+
.gufa-session-workspace-option:hover{background:var(--gufa-hover)}
|
|
1090
|
+
.gufa-session-workspace-option[data-current]{background:var(--gufa-active)}
|
|
1091
|
+
.gufa-session-workspace-option-title{flex:0 0 auto;font-weight:550}
|
|
1092
|
+
.gufa-session-workspace-option-path{flex:1 1 auto;min-width:0;overflow:hidden;text-overflow:ellipsis;white-space:nowrap;
|
|
1093
|
+
color:var(--gufa-text-dim);font-size:10.5px;text-align:right}
|
|
1081
1094
|
.gufa-session-workspace{font-size:11px;color:var(--gufa-text-dim);max-width:40%;overflow:hidden;text-overflow:ellipsis;white-space:nowrap}
|
|
1082
1095
|
.gufa-session-row-title{flex:1 1 auto;overflow:hidden;text-overflow:ellipsis}
|
|
1083
1096
|
.gufa-session-row-when{flex:0 0 auto;font-size:10.5px;color:var(--gufa-solid-text-dim, var(--dsw-alias-label-secondary));font-variant-numeric:tabular-nums}
|
|
@@ -1121,6 +1134,19 @@ html[data-gufa-ide] [role="dialog"] {
|
|
|
1121
1134
|
.gufa-session-group-count{font-size:10.5px;opacity:.6;font-variant-numeric:tabular-nums}
|
|
1122
1135
|
.gufa-session-group[data-current] .gufa-session-group-head{color:var(--gufa-text)}
|
|
1123
1136
|
.gufa-session-group .gufa-session-row{margin-left:10px}
|
|
1137
|
+
.gufa-session-workspace-btn{display:inline-flex;align-items:center;gap:4px;border:1px solid var(--gufa-border);background:var(--gufa-layer2);
|
|
1138
|
+
color:var(--gufa-text-dim);border-radius:7px;padding:2px 8px;font:inherit;font-size:11.5px;cursor:pointer;max-width:260px}
|
|
1139
|
+
.gufa-session-workspace-btn:hover{background:var(--gufa-hover);color:var(--gufa-text)}
|
|
1140
|
+
.gufa-session-workspace-btn span{overflow:hidden;text-overflow:ellipsis;white-space:nowrap}
|
|
1141
|
+
.gufa-session-workspace-picker{display:flex;flex-direction:column;gap:2px;padding:6px 10px;max-height:220px;overflow:auto;
|
|
1142
|
+
border-top:1px solid var(--gufa-border);border-bottom:1px solid var(--gufa-border);background:var(--gufa-layer)}
|
|
1143
|
+
.gufa-session-workspace-option{display:flex;align-items:center;gap:8px;width:100%;padding:6px 8px;border:0;border-radius:7px;
|
|
1144
|
+
background:transparent;color:var(--gufa-text);font:inherit;font-size:12px;cursor:pointer;text-align:left}
|
|
1145
|
+
.gufa-session-workspace-option:hover{background:var(--gufa-hover)}
|
|
1146
|
+
.gufa-session-workspace-option[data-current]{background:var(--gufa-active)}
|
|
1147
|
+
.gufa-session-workspace-option-title{flex:0 0 auto;font-weight:550}
|
|
1148
|
+
.gufa-session-workspace-option-path{flex:1 1 auto;min-width:0;overflow:hidden;text-overflow:ellipsis;white-space:nowrap;
|
|
1149
|
+
color:var(--gufa-text-dim);font-size:10.5px;text-align:right}
|
|
1124
1150
|
.gufa-session-workspace{font-size:11px;color:var(--gufa-text-dim);max-width:40%;overflow:hidden;text-overflow:ellipsis;white-space:nowrap}
|
|
1125
1151
|
.gufa-session-row-title{flex:1 1 auto;overflow:hidden;text-overflow:ellipsis}
|
|
1126
1152
|
.gufa-session-row-when{flex:0 0 auto;font-size:10.5px;color:var(--gufa-solid-text-dim, var(--dsw-alias-label-secondary));font-variant-numeric:tabular-nums}
|
|
@@ -1164,6 +1190,19 @@ html[data-gufa-ide] [role="dialog"] {
|
|
|
1164
1190
|
.gufa-session-group-count{font-size:10.5px;opacity:.6;font-variant-numeric:tabular-nums}
|
|
1165
1191
|
.gufa-session-group[data-current] .gufa-session-group-head{color:var(--gufa-text)}
|
|
1166
1192
|
.gufa-session-group .gufa-session-row{margin-left:10px}
|
|
1193
|
+
.gufa-session-workspace-btn{display:inline-flex;align-items:center;gap:4px;border:1px solid var(--gufa-border);background:var(--gufa-layer2);
|
|
1194
|
+
color:var(--gufa-text-dim);border-radius:7px;padding:2px 8px;font:inherit;font-size:11.5px;cursor:pointer;max-width:260px}
|
|
1195
|
+
.gufa-session-workspace-btn:hover{background:var(--gufa-hover);color:var(--gufa-text)}
|
|
1196
|
+
.gufa-session-workspace-btn span{overflow:hidden;text-overflow:ellipsis;white-space:nowrap}
|
|
1197
|
+
.gufa-session-workspace-picker{display:flex;flex-direction:column;gap:2px;padding:6px 10px;max-height:220px;overflow:auto;
|
|
1198
|
+
border-top:1px solid var(--gufa-border);border-bottom:1px solid var(--gufa-border);background:var(--gufa-layer)}
|
|
1199
|
+
.gufa-session-workspace-option{display:flex;align-items:center;gap:8px;width:100%;padding:6px 8px;border:0;border-radius:7px;
|
|
1200
|
+
background:transparent;color:var(--gufa-text);font:inherit;font-size:12px;cursor:pointer;text-align:left}
|
|
1201
|
+
.gufa-session-workspace-option:hover{background:var(--gufa-hover)}
|
|
1202
|
+
.gufa-session-workspace-option[data-current]{background:var(--gufa-active)}
|
|
1203
|
+
.gufa-session-workspace-option-title{flex:0 0 auto;font-weight:550}
|
|
1204
|
+
.gufa-session-workspace-option-path{flex:1 1 auto;min-width:0;overflow:hidden;text-overflow:ellipsis;white-space:nowrap;
|
|
1205
|
+
color:var(--gufa-text-dim);font-size:10.5px;text-align:right}
|
|
1167
1206
|
.gufa-session-workspace{font-size:11px;color:var(--gufa-text-dim);max-width:40%;overflow:hidden;text-overflow:ellipsis;white-space:nowrap}
|
|
1168
1207
|
.gufa-session-row-title{flex:1 1 auto;overflow:hidden;text-overflow:ellipsis}
|
|
1169
1208
|
.gufa-session-row-when{flex:0 0 auto;font-size:10.5px;color:var(--gufa-solid-text-dim, var(--dsw-alias-label-secondary));font-variant-numeric:tabular-nums}
|
|
@@ -1207,6 +1246,19 @@ html[data-gufa-ide] [role="dialog"] {
|
|
|
1207
1246
|
.gufa-session-group-count{font-size:10.5px;opacity:.6;font-variant-numeric:tabular-nums}
|
|
1208
1247
|
.gufa-session-group[data-current] .gufa-session-group-head{color:var(--gufa-text)}
|
|
1209
1248
|
.gufa-session-group .gufa-session-row{margin-left:10px}
|
|
1249
|
+
.gufa-session-workspace-btn{display:inline-flex;align-items:center;gap:4px;border:1px solid var(--gufa-border);background:var(--gufa-layer2);
|
|
1250
|
+
color:var(--gufa-text-dim);border-radius:7px;padding:2px 8px;font:inherit;font-size:11.5px;cursor:pointer;max-width:260px}
|
|
1251
|
+
.gufa-session-workspace-btn:hover{background:var(--gufa-hover);color:var(--gufa-text)}
|
|
1252
|
+
.gufa-session-workspace-btn span{overflow:hidden;text-overflow:ellipsis;white-space:nowrap}
|
|
1253
|
+
.gufa-session-workspace-picker{display:flex;flex-direction:column;gap:2px;padding:6px 10px;max-height:220px;overflow:auto;
|
|
1254
|
+
border-top:1px solid var(--gufa-border);border-bottom:1px solid var(--gufa-border);background:var(--gufa-layer)}
|
|
1255
|
+
.gufa-session-workspace-option{display:flex;align-items:center;gap:8px;width:100%;padding:6px 8px;border:0;border-radius:7px;
|
|
1256
|
+
background:transparent;color:var(--gufa-text);font:inherit;font-size:12px;cursor:pointer;text-align:left}
|
|
1257
|
+
.gufa-session-workspace-option:hover{background:var(--gufa-hover)}
|
|
1258
|
+
.gufa-session-workspace-option[data-current]{background:var(--gufa-active)}
|
|
1259
|
+
.gufa-session-workspace-option-title{flex:0 0 auto;font-weight:550}
|
|
1260
|
+
.gufa-session-workspace-option-path{flex:1 1 auto;min-width:0;overflow:hidden;text-overflow:ellipsis;white-space:nowrap;
|
|
1261
|
+
color:var(--gufa-text-dim);font-size:10.5px;text-align:right}
|
|
1210
1262
|
.gufa-session-workspace{font-size:11px;color:var(--gufa-text-dim);max-width:40%;overflow:hidden;text-overflow:ellipsis;white-space:nowrap}
|
|
1211
1263
|
.gufa-session-row-title{flex:1 1 auto;overflow:hidden;text-overflow:ellipsis}
|
|
1212
1264
|
.gufa-session-row-when{flex:0 0 auto;font-size:10.5px;color:var(--gufa-solid-text-dim, var(--dsw-alias-label-secondary));font-variant-numeric:tabular-nums}
|
|
@@ -1241,6 +1293,8 @@ html[data-platform=darwin][data-fullscreen] .gufa-titlebar{height:44px;padding-l
|
|
|
1241
1293
|
.gufa-project{appearance:none;border:0;background:transparent;font:inherit;color:inherit;cursor:pointer}
|
|
1242
1294
|
.gufa-project:hover{background:var(--gufa-hover)}
|
|
1243
1295
|
.gufa-workspace-row{height:auto;min-height:38px;padding:5px 8px}
|
|
1296
|
+
.gufa-workspace-row-wrap{display:flex;align-items:center;gap:4px}
|
|
1297
|
+
.gufa-workspace-row-wrap .gufa-workspace-row{flex:1 1 auto;min-width:0}
|
|
1244
1298
|
.gufa-workspace-title{display:block;font-size:12px;line-height:1.3}
|
|
1245
1299
|
.gufa-workspace-path{display:block;font-size:10.5px;color:var(--gufa-text-dim);overflow:hidden;text-overflow:ellipsis;white-space:nowrap}
|
|
1246
1300
|
.gufa-project{display:flex;align-items:center;gap:6px;min-width:0;margin-left:6px;padding:3px 9px;border-radius:7px;
|
|
@@ -1319,6 +1373,9 @@ html[data-platform=darwin][data-fullscreen] .gufa-titlebar{height:44px;padding-l
|
|
|
1319
1373
|
.gufa-tree-row[data-selected]{background:var(--gufa-active)}
|
|
1320
1374
|
.gufa-tree-row[data-kind="dir"]{color:var(--gufa-text)}
|
|
1321
1375
|
.gufa-tree-name{overflow:hidden;text-overflow:ellipsis;flex:1 1 auto;min-width:0}
|
|
1376
|
+
.gufa-explorer-notice{margin:4px 10px 0;padding:3px 8px;border-radius:6px;font-size:11px;line-height:1.5;color:var(--gufa-text);
|
|
1377
|
+
background:color-mix(in srgb, var(--gufa-accent) 14%, transparent);border:0.5px solid color-mix(in srgb, var(--gufa-accent) 40%, transparent);
|
|
1378
|
+
overflow:hidden;text-overflow:ellipsis;white-space:nowrap}
|
|
1322
1379
|
.gufa-tree-chevron{width:14px;flex:0 0 auto;opacity:.7;display:flex;align-items:center;justify-content:center}
|
|
1323
1380
|
.gufa-tree-icon{width:15px;flex:0 0 auto;opacity:.85;display:flex;align-items:center;justify-content:center}
|
|
1324
1381
|
.gufa-tree-badge{font-size:10px;color:var(--gufa-accent);flex:0 0 auto;font-weight:600}
|
package/src/client/20-editor.js
CHANGED
|
@@ -234,7 +234,14 @@
|
|
|
234
234
|
) {
|
|
235
235
|
return
|
|
236
236
|
}
|
|
237
|
-
const
|
|
237
|
+
const workerBase = (() => {
|
|
238
|
+
try {
|
|
239
|
+
return new URL(G.asset('monaco'), G.serverBase()).href
|
|
240
|
+
} catch {
|
|
241
|
+
return G.asset('monaco')
|
|
242
|
+
}
|
|
243
|
+
})()
|
|
244
|
+
const getWorker = (moduleId, label) => gufaCreateMonacoWorker(workerBase, label)
|
|
238
245
|
if (existing !== undefined && existing !== null && typeof existing === 'object') {
|
|
239
246
|
existing.getWorker = getWorker
|
|
240
247
|
return
|
|
@@ -253,13 +260,35 @@
|
|
|
253
260
|
}
|
|
254
261
|
|
|
255
262
|
function gufaCreateMonacoWorker(base, label) {
|
|
256
|
-
const
|
|
257
|
-
const
|
|
263
|
+
const name = typeof label === 'string' && label !== '' ? label : 'gufa-monaco-worker'
|
|
264
|
+
const watch = (worker, sourceUrl) => {
|
|
265
|
+
try {
|
|
266
|
+
worker.addEventListener('error', (event) => {
|
|
267
|
+
void G.api('dev.log', {
|
|
268
|
+
message: `monaco-worker-error src=${sourceUrl} message=${String(event && event.message)} file=${String(event && event.filename)} line=${String(event && event.lineno)}`,
|
|
269
|
+
}).catch(() => {})
|
|
270
|
+
})
|
|
271
|
+
worker.addEventListener('messageerror', () => {
|
|
272
|
+
void G.api('dev.log', { message: `monaco-worker-messageerror src=${sourceUrl}` }).catch(() => {})
|
|
273
|
+
})
|
|
274
|
+
void G.api('dev.log', { message: `monaco-worker-created src=${sourceUrl}` }).catch(() => {})
|
|
275
|
+
} catch {
|
|
276
|
+
/* ignore */
|
|
277
|
+
}
|
|
278
|
+
return worker
|
|
279
|
+
}
|
|
258
280
|
try {
|
|
259
|
-
|
|
260
|
-
|
|
261
|
-
|
|
262
|
-
|
|
281
|
+
const url = `${G.asset('monaco')}/worker-bootstrap.js?v=3`
|
|
282
|
+
return watch(new Worker(url, { name }), url)
|
|
283
|
+
} catch (error) {
|
|
284
|
+
const blob = new Blob([gufaWorkerScript(base)], { type: 'text/javascript' })
|
|
285
|
+
const url = URL.createObjectURL(blob)
|
|
286
|
+
void G.api('dev.log', { message: `monaco-worker-construct-failed ${String(error && error.message)} fallback=blob` }).catch(() => {})
|
|
287
|
+
try {
|
|
288
|
+
return watch(new Worker(url, { name }), url)
|
|
289
|
+
} finally {
|
|
290
|
+
window.setTimeout(() => URL.revokeObjectURL(url), 10000)
|
|
291
|
+
}
|
|
263
292
|
}
|
|
264
293
|
}
|
|
265
294
|
|
|
@@ -492,6 +521,8 @@
|
|
|
492
521
|
const diffEditorRef = useRef(null)
|
|
493
522
|
const diffModelsRef = useRef([])
|
|
494
523
|
const diffSignatureRef = useRef(null)
|
|
524
|
+
const diffAnchorsRef = useRef([])
|
|
525
|
+
const diffZoneIdsRef = useRef([])
|
|
495
526
|
const monacoRef = useRef(null)
|
|
496
527
|
const modelsRef = useRef(new Map()) /* path -> ITextModel */
|
|
497
528
|
const viewStatesRef = useRef(new Map()) /* path -> editor view state(滚动/光标) */
|
|
@@ -956,6 +987,8 @@
|
|
|
956
987
|
}
|
|
957
988
|
diffModelsRef.current = []
|
|
958
989
|
diffSignatureRef.current = null
|
|
990
|
+
diffAnchorsRef.current = []
|
|
991
|
+
diffZoneIdsRef.current = []
|
|
959
992
|
}
|
|
960
993
|
if (status !== 'ready' || activeIsDiff !== true) {
|
|
961
994
|
disposeDiff()
|
|
@@ -979,7 +1012,7 @@
|
|
|
979
1012
|
const language = typeof tab.language === 'string' && tab.language !== '' ? tab.language : 'plaintext'
|
|
980
1013
|
const key = encodeURIComponent(String(tab.path))
|
|
981
1014
|
const suffix = String(Date.now())
|
|
982
|
-
const leftText = tab.diff.compare === true && typeof tab.compareLeft === 'string' ? tab.compareLeft : tab.diff.left
|
|
1015
|
+
const leftText = tab.diff.compare === true && typeof tab.compareLeft === 'string' ? tab.compareLeft : String(tab.diff.left ?? '')
|
|
983
1016
|
const originalModel = monaco.editor.createModel(String(leftText ?? ''), language, monaco.Uri.parse(`gufa-diff://original/${key}/${suffix}`))
|
|
984
1017
|
const modifiedModel = monaco.editor.createModel(String(tab.content ?? ''), language, monaco.Uri.parse(`gufa-diff://modified/${key}/${suffix}`))
|
|
985
1018
|
let instance
|
|
@@ -1066,6 +1099,17 @@
|
|
|
1066
1099
|
} catch {
|
|
1067
1100
|
/* ignore */
|
|
1068
1101
|
}
|
|
1102
|
+
/* 诊断:2 秒后如果差异仍然是 null,说明 Monaco worker 没起来(dsh-app:// 下的 worker 限制) */
|
|
1103
|
+
window.setTimeout(() => {
|
|
1104
|
+
try {
|
|
1105
|
+
const changes = typeof instance.getLineChanges === 'function' ? instance.getLineChanges() : null
|
|
1106
|
+
void G.api('dev.log', {
|
|
1107
|
+
message: `diff-open path=${tab.path} leftLen=${String(leftText ?? '').length} rightLen=${String(tab.content ?? '').length} hostW=${host !== null ? host.clientWidth : -1} changes=${Array.isArray(changes) ? changes.length : String(changes)}`,
|
|
1108
|
+
}).catch(() => {})
|
|
1109
|
+
} catch {
|
|
1110
|
+
/* ignore */
|
|
1111
|
+
}
|
|
1112
|
+
}, 2000)
|
|
1069
1113
|
return () => {
|
|
1070
1114
|
try {
|
|
1071
1115
|
sub.dispose()
|
|
@@ -1188,7 +1232,8 @@
|
|
|
1188
1232
|
const changes = typeof instance.getLineChanges === 'function' ? instance.getLineChanges() : null
|
|
1189
1233
|
if (changes === null || changes === undefined || changes.length === 0) return
|
|
1190
1234
|
const editor = instance.getModifiedEditor()
|
|
1191
|
-
const
|
|
1235
|
+
const position = editor.getPosition()
|
|
1236
|
+
const line = position === null ? 0 : position.lineNumber
|
|
1192
1237
|
let target = direction > 0 ? changes.find((item) => item.modifiedStartLineNumber > line) : [...changes].reverse().find((item) => item.modifiedEndLineNumber < line)
|
|
1193
1238
|
if (target === undefined) target = direction > 0 ? changes[0] : changes[changes.length - 1]
|
|
1194
1239
|
if (target === undefined) return
|
package/src/client/50-panels.js
CHANGED
|
@@ -14,6 +14,8 @@ G.Explorer = function Explorer(props) {
|
|
|
14
14
|
const [clipboard, setClipboard] = useState(null)
|
|
15
15
|
const [menu, setMenu] = useState(null)
|
|
16
16
|
const [menuError, setMenuError] = useState('')
|
|
17
|
+
const [notice, setNotice] = useState('')
|
|
18
|
+
const containerRef = useRef(null)
|
|
17
19
|
const flatRows = []
|
|
18
20
|
const kindByPathRef = useRef(new Map())
|
|
19
21
|
const problems = G.useProblems()
|
|
@@ -120,6 +122,69 @@ G.Explorer = function Explorer(props) {
|
|
|
120
122
|
}
|
|
121
123
|
}
|
|
122
124
|
|
|
125
|
+
const noticeRef = useRef(0)
|
|
126
|
+
const showNotice = (text) => {
|
|
127
|
+
setNotice(text)
|
|
128
|
+
noticeRef.current += 1
|
|
129
|
+
const token = noticeRef.current
|
|
130
|
+
window.setTimeout(() => {
|
|
131
|
+
if (noticeRef.current === token) setNotice('')
|
|
132
|
+
}, 3200)
|
|
133
|
+
}
|
|
134
|
+
|
|
135
|
+
const readFileBase64 = (file) => new Promise((resolve, reject) => {
|
|
136
|
+
const reader = new FileReader()
|
|
137
|
+
reader.onload = () => {
|
|
138
|
+
const text = String(reader.result ?? '')
|
|
139
|
+
const comma = text.indexOf(',')
|
|
140
|
+
resolve(comma >= 0 ? text.slice(comma + 1) : '')
|
|
141
|
+
}
|
|
142
|
+
reader.onerror = () => reject(reader.error ?? new Error('读取文件失败'))
|
|
143
|
+
reader.readAsDataURL(file)
|
|
144
|
+
})
|
|
145
|
+
|
|
146
|
+
/** 把系统剪贴板 / Finder 拖入的文件写入目标目录。@returns 是否接管了这次事件 */
|
|
147
|
+
const uploadFiles = async (fileList, dir) => {
|
|
148
|
+
const files = Array.from(fileList ?? []).filter((file) => file !== null && typeof file === 'object' && typeof file.size === 'number')
|
|
149
|
+
if (files.length === 0) return false
|
|
150
|
+
const total = files.reduce((sum, file) => sum + (file.size || 0), 0)
|
|
151
|
+
if (total <= 0) {
|
|
152
|
+
showNotice('这个剪贴板项没有可读取的文件内容(文件夹暂不支持,请拖入文件)')
|
|
153
|
+
return true
|
|
154
|
+
}
|
|
155
|
+
if (total > 300 * 1024 * 1024) {
|
|
156
|
+
showNotice(`文件太大(${Math.round(total / 1024 / 1024)}MB),超过 300MB 上限`)
|
|
157
|
+
return true
|
|
158
|
+
}
|
|
159
|
+
const targetDir = typeof dir === 'string' ? dir : ''
|
|
160
|
+
showNotice(`正在写入 ${files.length} 个文件…`)
|
|
161
|
+
try {
|
|
162
|
+
const payload = []
|
|
163
|
+
for (const file of files) {
|
|
164
|
+
payload.push({ name: file.name !== '' ? file.name : 'file', data: await readFileBase64(file) })
|
|
165
|
+
}
|
|
166
|
+
const result = await G.api('fs.upload', { root, dir: targetDir, files: payload })
|
|
167
|
+
const written = Array.isArray(result?.written) ? result.written : []
|
|
168
|
+
await loadDir(targetDir)
|
|
169
|
+
await loadDir('')
|
|
170
|
+
props.onChanged?.()
|
|
171
|
+
showNotice(`已粘贴 ${written.length} 个文件到 ${targetDir === '' ? '项目根目录' : targetDir}`)
|
|
172
|
+
} catch (error) {
|
|
173
|
+
showNotice(`粘贴失败:${G.errorText(error)}`)
|
|
174
|
+
}
|
|
175
|
+
return true
|
|
176
|
+
}
|
|
177
|
+
|
|
178
|
+
/** 拖放目标所在的目录(拖到文件行 → 其父目录;拖到文件夹行 → 该文件夹)。 */
|
|
179
|
+
const dropTargetDir = (target) => {
|
|
180
|
+
const element = target instanceof Element ? target.closest('[data-edrv-path]') : null
|
|
181
|
+
if (element === null) return selectedDir()
|
|
182
|
+
const path = element.getAttribute('data-edrv-path') ?? ''
|
|
183
|
+
if (path === '') return ''
|
|
184
|
+
const kind = element.getAttribute('data-kind')
|
|
185
|
+
return kind === 'dir' ? path : projectDirOf(path)
|
|
186
|
+
}
|
|
187
|
+
|
|
123
188
|
const revealPath = (path) => {
|
|
124
189
|
void G.api('fs.reveal', { root, path }).catch((error) => setMenuError(G.errorText(error)))
|
|
125
190
|
}
|
|
@@ -208,9 +273,12 @@ G.Explorer = function Explorer(props) {
|
|
|
208
273
|
'data-selected': multi.length > 0 ? (multi.includes(entry.path) ? '' : undefined) : selected !== null && selected.path === entry.path ? '' : undefined,
|
|
209
274
|
'data-kind': entry.kind,
|
|
210
275
|
'data-git-status': status !== undefined ? status : undefined,
|
|
276
|
+
/* 给 dsh-drag-ref 用:把资源管理器行变成可拖拽的 @ 引用来源 */
|
|
277
|
+
'data-edrv-path': entry.path,
|
|
211
278
|
style: { paddingLeft: 8 + depth * 14 },
|
|
212
279
|
title: entry.path,
|
|
213
280
|
onClick: (event) => {
|
|
281
|
+
containerRef.current?.focus?.()
|
|
214
282
|
rememberKind(entry)
|
|
215
283
|
if (event.metaKey || event.ctrlKey) {
|
|
216
284
|
event.preventDefault()
|
|
@@ -234,6 +302,8 @@ G.Explorer = function Explorer(props) {
|
|
|
234
302
|
{ className: 'gufa-tree-chevron' },
|
|
235
303
|
isDir ? h(G.Icon, { name: isExpanded ? 'chevron-down' : 'chevron-right', size: 12 }) : null,
|
|
236
304
|
),
|
|
305
|
+
/* dsh-drag-ref 用非空的 .edrv-tree-chev 文本判断「这是文件夹」 */
|
|
306
|
+
isDir ? h('span', { className: 'edrv-tree-chev', style: { display: 'none' } }, '▸') : null,
|
|
237
307
|
h('span', { className: 'gufa-tree-icon' }, h(G.Icon, { name: isDir ? (isExpanded ? 'folder-open' : 'folder') : 'file', size: 14 })),
|
|
238
308
|
h('span', { className: 'gufa-tree-name' }, entry.name),
|
|
239
309
|
isDir && changedDirs.has(entry.path) ? h('span', { className: 'gufa-tree-problem', 'data-level': 'dir', title: t('explorer.changedDir') }) : null,
|
|
@@ -255,8 +325,31 @@ G.Explorer = function Explorer(props) {
|
|
|
255
325
|
return h(
|
|
256
326
|
'div',
|
|
257
327
|
{
|
|
328
|
+
ref: containerRef,
|
|
258
329
|
style: { display: 'flex', flexDirection: 'column', height: '100%', minHeight: 0, outline: 'none' },
|
|
259
330
|
tabIndex: 0,
|
|
331
|
+
onPaste: (event) => {
|
|
332
|
+
const files = event.clipboardData?.files
|
|
333
|
+
if (files !== undefined && files !== null && files.length > 0) {
|
|
334
|
+
event.preventDefault()
|
|
335
|
+
event.stopPropagation()
|
|
336
|
+
void uploadFiles(files, selectedDir())
|
|
337
|
+
}
|
|
338
|
+
},
|
|
339
|
+
onDragOver: (event) => {
|
|
340
|
+
const types = event.dataTransfer?.types
|
|
341
|
+
if (types === undefined || types === null || !Array.from(types).includes('Files')) return
|
|
342
|
+
event.preventDefault()
|
|
343
|
+
event.stopPropagation()
|
|
344
|
+
event.dataTransfer.dropEffect = 'copy'
|
|
345
|
+
},
|
|
346
|
+
onDrop: (event) => {
|
|
347
|
+
const files = event.dataTransfer?.files
|
|
348
|
+
if (files === undefined || files === null || files.length === 0) return
|
|
349
|
+
event.preventDefault()
|
|
350
|
+
event.stopPropagation()
|
|
351
|
+
void uploadFiles(files, dropTargetDir(event.target))
|
|
352
|
+
},
|
|
260
353
|
onKeyDown: (event) => {
|
|
261
354
|
if (event.key === 'Enter') {
|
|
262
355
|
if (selected === null) return
|
|
@@ -294,6 +387,9 @@ G.Explorer = function Explorer(props) {
|
|
|
294
387
|
h(G.IconButton, { title: t('explorer.newFolder'), onClick: () => props.onNewFolder?.(selectedDir()) }, h(G.Icon, { name: 'folder', size: 14 })),
|
|
295
388
|
h(G.IconButton, { title: t('explorer.refresh'), onClick: () => void loadDir('') }, h(G.Icon, { name: 'refresh', size: 13 })),
|
|
296
389
|
),
|
|
390
|
+
notice !== ''
|
|
391
|
+
? h('div', { className: 'gufa-explorer-notice', title: notice }, notice)
|
|
392
|
+
: null,
|
|
297
393
|
h(
|
|
298
394
|
'div',
|
|
299
395
|
{ className: 'gufa-panel-body gufa-scroll' },
|