dsh-ris-ide 1.7.2 → 1.8.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 +43 -4
- package/bin/check-listing.mjs +247 -0
- package/bin/proxy-janitor.mjs +183 -0
- package/bin/risd.mjs +287 -0
- package/bin/run-with-log.ps1 +43 -5
- package/lib/client-codemirror.js +92 -66
- package/lib/client.js +774 -89
- package/lib/index.js +2256 -21
- package/lib/janitor.js +377 -0
- package/lib/proxy.js +1577 -0
- package/lib/proxybridge-bundle.js +798 -0
- package/lib/redirector.js +2558 -0
- package/lib/risd/build.js +91 -0
- package/lib/risd/debug.js +374 -0
- package/lib/risd/git.js +207 -0
- package/lib/risd/leases.js +124 -0
- package/lib/risd/lifecycle.js +148 -0
- package/lib/risd/log.js +59 -0
- package/lib/risd/ping.js +94 -0
- package/lib/risd/programs.js +348 -0
- package/lib/risd/server.js +1478 -0
- package/lib/risd/state.js +137 -0
- package/lib/risd/ui.js +1705 -0
- package/lib/risd/view.js +79 -0
- package/lib/risd-client.js +282 -0
- package/lib/standalone/window.html +14 -16
- package/lib/startup.js +114 -0
- package/package.json +7 -2
- package/skills/dsh-ris-ide-debug/SKILL.md +37 -2
- package/test/client-build.test.mjs +113 -0
- package/test/client-viewer.test.mjs +314 -20
- package/test/companion.test.mjs +65 -0
- package/test/dsh-origin.test.mjs +140 -0
- package/test/dsh-window-refresh.test.mjs +100 -0
- package/test/harness.test.mjs +9 -0
- package/test/host-noloop.test.mjs +74 -0
- package/test/host-tail.test.mjs +54 -5
- package/test/host-window.test.mjs +4 -4
- package/test/inherit-engine.test.mjs +175 -0
- package/test/install-phase.test.mjs +36 -0
- package/test/janitor.test.mjs +172 -0
- package/test/lifecycle.test.mjs +109 -0
- package/test/merge-owners.test.mjs +155 -0
- package/test/proxy-restart.test.mjs +37 -0
- package/test/proxy-route.test.mjs +599 -0
- package/test/proxy-window.test.mjs +45 -0
- package/test/proxy.test.mjs +914 -0
- package/test/proxybridge-bundle.test.mjs +687 -0
- package/test/redirector-bundle.test.mjs +391 -0
- package/test/redirector.test.mjs +571 -0
- package/test/risd-api.test.mjs +470 -0
- package/test/risd-bridge-degrade.test.mjs +101 -0
- package/test/risd-build.test.mjs +20 -0
- package/test/risd-cli-home.test.mjs +50 -0
- package/test/risd-client.test.mjs +130 -0
- package/test/risd-debug.test.mjs +261 -0
- package/test/risd-election.test.mjs +104 -0
- package/test/risd-engine.test.mjs +132 -0
- package/test/risd-entry.test.mjs +118 -0
- package/test/risd-git.test.mjs +109 -0
- package/test/risd-handoff.test.mjs +116 -0
- package/test/risd-heal.test.mjs +50 -0
- package/test/risd-helpers.mjs +108 -0
- package/test/risd-host-p2.test.mjs +147 -0
- package/test/risd-janitor-guard.test.mjs +46 -0
- package/test/risd-lease.test.mjs +83 -0
- package/test/risd-lifecycle.test.mjs +210 -0
- package/test/risd-log-follow.test.mjs +227 -0
- package/test/risd-mode.test.mjs +161 -0
- package/test/risd-ping.test.mjs +99 -0
- package/test/risd-programs.test.mjs +169 -0
- package/test/risd-review-p2.test.mjs +217 -0
- package/test/risd-shutdown.test.mjs +97 -0
- package/test/risd-teardown.test.mjs +87 -0
- package/test/risd-tools.test.mjs +211 -0
- package/test/risd-ui.test.mjs +445 -0
- package/test/risd-write.test.mjs +170 -0
- package/test/startup-reconcile.test.mjs +100 -0
- package/test/windows.test.mjs +37 -2
package/lib/client.js
CHANGED
|
@@ -110,6 +110,123 @@ window.__ModuleLoader__.load({
|
|
|
110
110
|
return typeof window !== 'undefined' && window.__dshRisIdeWindow === true
|
|
111
111
|
}
|
|
112
112
|
|
|
113
|
+
/**
|
|
114
|
+
* The client bundle this page is running, as the host told us when the page
|
|
115
|
+
* booted. `null` until the first hello/build answer (see `watchClientBuild`).
|
|
116
|
+
*/
|
|
117
|
+
var pageBuildId = null
|
|
118
|
+
var buildWatcherInstalled = false
|
|
119
|
+
/** How often an open page re-asks the host which bundle it serves. */
|
|
120
|
+
var BUILD_POLL_MS = 30000
|
|
121
|
+
/** The build a hint was raised for, and the one the user closed it for. */
|
|
122
|
+
var staleNoticeBuild = null
|
|
123
|
+
var staleNoticeDismissedFor = null
|
|
124
|
+
|
|
125
|
+
/**
|
|
126
|
+
* Tell the user that the IDE code changed under the open page.
|
|
127
|
+
*
|
|
128
|
+
* Neither page shape reloads itself: the standalone window owns an editor that
|
|
129
|
+
* can hold unsaved buffers, and a DSH page would drop the conversation view. The
|
|
130
|
+
* bar carries the refresh button and is idempotent — later hellos/focus polls
|
|
131
|
+
* reuse the same node instead of stacking bars.
|
|
132
|
+
* @param {string} build - the build id the hint is for.
|
|
133
|
+
*/
|
|
134
|
+
function showStaleBuildNotice(build) {
|
|
135
|
+
staleNoticeBuild = typeof build === 'string' ? build : null
|
|
136
|
+
if (typeof document === 'undefined') return
|
|
137
|
+
var existing = document.getElementById('dsh-ris-ide-build-stale')
|
|
138
|
+
if (existing !== null) { existing.hidden = false; return }
|
|
139
|
+
var bar = document.createElement('div')
|
|
140
|
+
bar.id = 'dsh-ris-ide-build-stale'
|
|
141
|
+
bar.setAttribute('role', 'status')
|
|
142
|
+
bar.style.cssText = 'position:fixed;right:16px;bottom:16px;z-index:2147483000;display:flex;align-items:center;gap:10px;'
|
|
143
|
+
+ 'padding:8px 12px;border-radius:8px;background:#eef4ff;border:1px solid #d7e4ff;color:#1d4ed8;'
|
|
144
|
+
+ 'font:13px/1.4 -apple-system,BlinkMacSystemFont,"Segoe UI",Roboto,"PingFang SC","Microsoft YaHei",sans-serif;'
|
|
145
|
+
+ 'box-shadow:0 6px 20px rgba(15,23,42,.12)'
|
|
146
|
+
var text = document.createElement('span')
|
|
147
|
+
text.textContent = 'IDE 界面已更新:刷新页面后生效'
|
|
148
|
+
var reload = document.createElement('button')
|
|
149
|
+
reload.type = 'button'
|
|
150
|
+
reload.textContent = '刷新'
|
|
151
|
+
reload.style.cssText = 'border:1px solid #bcd3ff;background:#fff;color:#1d4ed8;border-radius:6px;padding:2px 10px;cursor:pointer;font:inherit'
|
|
152
|
+
reload.addEventListener('click', function () { location.reload() })
|
|
153
|
+
var close = document.createElement('button')
|
|
154
|
+
close.type = 'button'
|
|
155
|
+
close.textContent = '×'
|
|
156
|
+
close.title = '关闭提示'
|
|
157
|
+
close.setAttribute('aria-label', '关闭提示')
|
|
158
|
+
close.style.cssText = 'border:0;background:transparent;color:inherit;cursor:pointer;font:inherit;padding:0 2px'
|
|
159
|
+
close.addEventListener('click', function () {
|
|
160
|
+
// Remember which build was dismissed: the 30s poll must not re-open the bar
|
|
161
|
+
// for the same stale bundle, but a NEWER build still has to warn.
|
|
162
|
+
staleNoticeDismissedFor = staleNoticeBuild
|
|
163
|
+
bar.hidden = true
|
|
164
|
+
})
|
|
165
|
+
bar.appendChild(text)
|
|
166
|
+
bar.appendChild(reload)
|
|
167
|
+
bar.appendChild(close)
|
|
168
|
+
document.body.appendChild(bar)
|
|
169
|
+
}
|
|
170
|
+
|
|
171
|
+
/**
|
|
172
|
+
* Keep this page on the client bundle the host is serving.
|
|
173
|
+
*
|
|
174
|
+
* Plugin bundles are served with `immutable` caching and a revision-baked URL,
|
|
175
|
+
* so a reload already gets the new build — the stale thing is the ALREADY OPEN
|
|
176
|
+
* page, which keeps executing the bundle it booted. The host stamps the build
|
|
177
|
+
* into the stream's hello and serves it at `/dsh-ris-ide/build`; this watcher
|
|
178
|
+
* takes the first answer as "what this page runs" and, when a later answer
|
|
179
|
+
* differs, raises the refresh hint. It never reloads by itself, and it keeps
|
|
180
|
+
* `pageBuildId` on the bundle this page actually runs, so a cancelled or missed
|
|
181
|
+
* reload keeps the hint up (review C3-P1-2).
|
|
182
|
+
*
|
|
183
|
+
* Rides the existing stream hub for the push case, plus a slow visibility-aware
|
|
184
|
+
* poll for pages that stay in the foreground (a hello only arrives when the
|
|
185
|
+
* stream (re)connects). A hub that is not connected yet is fine — the first
|
|
186
|
+
* answer becomes the baseline.
|
|
187
|
+
*/
|
|
188
|
+
function watchClientBuild() {
|
|
189
|
+
if (buildWatcherInstalled || typeof window === 'undefined') return
|
|
190
|
+
// A real browser page always has EventSource; a Node test harness that imports
|
|
191
|
+
// this file does not, and must not start a stream (or a fetch to a relative
|
|
192
|
+
// URL, or a timer) just because `apply` ran — that surfaced as an async
|
|
193
|
+
// "EventSource is not defined" after the test had already ended.
|
|
194
|
+
if (typeof EventSource !== 'function') return
|
|
195
|
+
buildWatcherInstalled = true
|
|
196
|
+
function note(build) {
|
|
197
|
+
if (typeof build !== 'string' || build === '') return
|
|
198
|
+
if (pageBuildId === null) { pageBuildId = build; return }
|
|
199
|
+
if (build === pageBuildId) return
|
|
200
|
+
// A dismissed hint stays dismissed for THAT build; a newer bundle re-warns.
|
|
201
|
+
if (build === staleNoticeDismissedFor) return
|
|
202
|
+
showStaleBuildNotice(build)
|
|
203
|
+
}
|
|
204
|
+
function pollBuild() {
|
|
205
|
+
if (typeof document !== 'undefined' && document.hidden === true) return
|
|
206
|
+
void fetch(routeUrl('dsh-ris-ide/build').href, { headers: { accept: 'application/json' } })
|
|
207
|
+
.then(function (response) { return response.ok === true ? response.json() : null })
|
|
208
|
+
.then(function (body) { if (body !== null && body !== undefined) note(body.build) })
|
|
209
|
+
.catch(function () { /* host unreachable: keep the build we already know */ })
|
|
210
|
+
}
|
|
211
|
+
try {
|
|
212
|
+
var hub = risStreamHub()
|
|
213
|
+
hub.subscribe({
|
|
214
|
+
topics: ['hello'],
|
|
215
|
+
handlers: {
|
|
216
|
+
hello: function (payload) {
|
|
217
|
+
if (payload === null || payload === undefined || payload.ok !== true) return
|
|
218
|
+
note(payload.build)
|
|
219
|
+
},
|
|
220
|
+
},
|
|
221
|
+
})
|
|
222
|
+
} catch { /* no hub (old host): the fetch below still seeds the baseline */ }
|
|
223
|
+
// Seed the baseline even when the stream is not up yet, so a page opened
|
|
224
|
+
// before the first hello can still notice the change.
|
|
225
|
+
pollBuild()
|
|
226
|
+
setInterval(pollBuild, BUILD_POLL_MS)
|
|
227
|
+
if (typeof window.addEventListener === 'function') window.addEventListener('focus', pollBuild)
|
|
228
|
+
}
|
|
229
|
+
|
|
113
230
|
/** Point the RIS-IDE tab at one program (consumed by the panel). */
|
|
114
231
|
function selectProgram(program) {
|
|
115
232
|
pendingProgram = program === null || program === undefined ? null : program
|
|
@@ -179,6 +296,101 @@ window.__ModuleLoader__.load({
|
|
|
179
296
|
return knownWorkspaceCwd()
|
|
180
297
|
}
|
|
181
298
|
|
|
299
|
+
/**
|
|
300
|
+
* The workspace of ONE session, read through the slot's standard `useSessions`
|
|
301
|
+
* hook.
|
|
302
|
+
*
|
|
303
|
+
* Every slot entry receives `useSessions` (the session store) and, inside a
|
|
304
|
+
* session-scoped slot, that session's `sessionId`. Asking the store is the only
|
|
305
|
+
* way to learn the CURRENT session's workspace: `knownWorkspaceCwd()` is
|
|
306
|
+
* whatever the last host answer happened to mention, i.e. possibly the
|
|
307
|
+
* PREVIOUS session's workspace. A missing hook (an older host, the standalone
|
|
308
|
+
* window page, a bare render) or an unknown session answers `undefined`, so
|
|
309
|
+
* callers keep their own fallback.
|
|
310
|
+
* @param {Function|undefined} useSessions - standard slot prop, `useSessions(select)`.
|
|
311
|
+
* @param {string} sessionId - this session's id.
|
|
312
|
+
* @returns {string|undefined} the session's workspace path.
|
|
313
|
+
*/
|
|
314
|
+
function sessionWorkspaceCwd(useSessions, sessionId) {
|
|
315
|
+
if (typeof useSessions !== 'function' || typeof sessionId !== 'string' || sessionId === '') return undefined
|
|
316
|
+
return useSessions(function (state) {
|
|
317
|
+
var rows = state !== null && state !== undefined ? state.byId : undefined
|
|
318
|
+
var row = rows !== null && rows !== undefined && typeof rows === 'object' ? rows[sessionId] : undefined
|
|
319
|
+
var cwd = row !== null && row !== undefined ? row.cwd : undefined
|
|
320
|
+
return typeof cwd === 'string' && cwd !== '' ? cwd : undefined
|
|
321
|
+
})
|
|
322
|
+
}
|
|
323
|
+
|
|
324
|
+
/**
|
|
325
|
+
* Which Session the right Sidebar is drawn for RIGHT NOW, read from the DOM.
|
|
326
|
+
*
|
|
327
|
+
* `keepMounted: true` deliberately keeps a visited tab body alive "through
|
|
328
|
+
* hiding, Session changes and docking", so its props keep the session it was
|
|
329
|
+
* OPENED in. Switching workspace then left the console listing the previous
|
|
330
|
+
* project. DSH already marks the live one for its own focus logic
|
|
331
|
+
* (`data-sidebar-right-session`), and reading that attribute needs no extra
|
|
332
|
+
* plugin dependency and no host round trip.
|
|
333
|
+
* @returns {string|undefined} the live session id, or undefined off-DOM.
|
|
334
|
+
*/
|
|
335
|
+
/**
|
|
336
|
+
* The Session whose right Sidebar is on screen right now.
|
|
337
|
+
*
|
|
338
|
+
* The tab body outlives Session switches (`keepMounted`), so its injected
|
|
339
|
+
* `sessionId` keeps naming the Session it was opened in. The sidebar marks
|
|
340
|
+
* its DOM with `data-sidebar-right-session`: the panel element carries the
|
|
341
|
+
* live Session, while retained `SessionView` wrappers each carry their own
|
|
342
|
+
* and sit hidden. Taking the first match therefore returns a stale hidden
|
|
343
|
+
* wrapper, so the panel is preferred and visibility is required.
|
|
344
|
+
* @returns the live Session id, or undefined when no sidebar is mounted.
|
|
345
|
+
*/
|
|
346
|
+
function liveSidebarSessionId(origin) {
|
|
347
|
+
if (typeof document === 'undefined') return undefined
|
|
348
|
+
/**
|
|
349
|
+
* Whether the marker sits in what the reader can see right now.
|
|
350
|
+
* @param {Element} node - element carrying `data-sidebar-right-session`.
|
|
351
|
+
* @returns {boolean} true when it is rendered and not inside a hidden tree.
|
|
352
|
+
*/
|
|
353
|
+
function shown(node) {
|
|
354
|
+
if (node.hidden === true) return false
|
|
355
|
+
if (typeof node.closest === 'function' && node.closest('[hidden]') !== null) return false
|
|
356
|
+
if (typeof node.getClientRects === 'function' && node.getClientRects().length === 0) return false
|
|
357
|
+
return true
|
|
358
|
+
}
|
|
359
|
+
/**
|
|
360
|
+
* @param {Element|undefined} node - candidate marker.
|
|
361
|
+
* @returns {string|undefined} its Session id.
|
|
362
|
+
*/
|
|
363
|
+
function valueOf(node) {
|
|
364
|
+
if (node === null || node === undefined || typeof node.getAttribute !== 'function') return undefined
|
|
365
|
+
var value = node.getAttribute('data-sidebar-right-session')
|
|
366
|
+
return typeof value === 'string' && value !== '' ? value : undefined
|
|
367
|
+
}
|
|
368
|
+
// 1. The body's own ancestor, when it is on screen: DSH re-parents a retained
|
|
369
|
+
// tab body into the Session that is showing now, so this is the truth.
|
|
370
|
+
if (origin !== null && origin !== undefined && typeof origin.closest === 'function') {
|
|
371
|
+
var nearest = origin.closest('[data-sidebar-right-session]')
|
|
372
|
+
var nearestId = valueOf(nearest)
|
|
373
|
+
if (nearestId !== undefined && shown(nearest)) return nearestId
|
|
374
|
+
}
|
|
375
|
+
if (typeof document.querySelectorAll !== 'function') return undefined
|
|
376
|
+
// 2. Otherwise the sidebar PANEL element, which always names the live
|
|
377
|
+
// Session, then any other visible marker (a floating pane inside a
|
|
378
|
+
// SessionView). Retained wrappers are hidden, so they never win here.
|
|
379
|
+
var nodes = document.querySelectorAll('[data-sidebar-right-session]')
|
|
380
|
+
var fallback
|
|
381
|
+
for (var i = 0; i < nodes.length; i += 1) {
|
|
382
|
+
var node = nodes[i]
|
|
383
|
+
var value = valueOf(node)
|
|
384
|
+
if (value === undefined) continue
|
|
385
|
+
if (!shown(node)) continue
|
|
386
|
+
if (typeof node.hasAttribute === 'function' && node.hasAttribute('data-sidebar-right-panel')) return value
|
|
387
|
+
if (fallback === undefined) fallback = value
|
|
388
|
+
}
|
|
389
|
+
// 3. Nothing visible (collapsed sidebar): no opinion, the caller keeps its
|
|
390
|
+
// last good answer rather than falling back to the stale injected one.
|
|
391
|
+
return fallback
|
|
392
|
+
}
|
|
393
|
+
|
|
182
394
|
/**
|
|
183
395
|
* The log pane of ONE plugin instance (sidebar console or standalone window)
|
|
184
396
|
* has no idea that another instance just started/debugged a program. A storage
|
|
@@ -1129,6 +1341,16 @@ window.__ModuleLoader__.load({
|
|
|
1129
1341
|
var PREF_FONT_SIZE = 'dsh-ris-ide.fontSize'
|
|
1130
1342
|
/** The theme's mono token first, then what a Linux desktop actually has. */
|
|
1131
1343
|
var MONO_FAMILY = "var(--dsw-font-mono, 'Ubuntu Sans Mono', 'Ubuntu Mono', 'JetBrains Mono', 'Fira Code', 'Noto Sans Mono', 'DejaVu Sans Mono', ui-monospace, SFMono-Regular, Menlo, Consolas, monospace)"
|
|
1344
|
+
/**
|
|
1345
|
+
* The chrome font the IDE window renders with.
|
|
1346
|
+
*
|
|
1347
|
+
* The IDE page defines `--dsw-font-mono` (this theme maps it to a system UI
|
|
1348
|
+
* stack), but the DSH sidebar does not, so a sidebar dialog that repeated the
|
|
1349
|
+
* mono list fell back to a real monospace face and measured wider than the
|
|
1350
|
+
* same dialog in the IDE window — rule rows wrapped only in the sidebar. The
|
|
1351
|
+
* fallback is therefore the stack the token resolves to, not a mono list.
|
|
1352
|
+
*/
|
|
1353
|
+
var CHROME_FAMILY = "var(--dsw-font-mono, system-ui, -apple-system, 'Segoe UI', 'Microsoft YaHei', sans-serif)"
|
|
1132
1354
|
|
|
1133
1355
|
var BASE_STYLES = {
|
|
1134
1356
|
root: {
|
|
@@ -1789,6 +2011,18 @@ window.__ModuleLoader__.load({
|
|
|
1789
2011
|
/** The unscaled set: components outside the IDE (the sidebar's own viewers). */
|
|
1790
2012
|
var S = stylesFor(1)
|
|
1791
2013
|
|
|
2014
|
+
/**
|
|
2015
|
+
* The 「代理」 dialog: the upstream SOCKS address on top, the rule table below.
|
|
2016
|
+
*
|
|
2017
|
+
* Rules are the contract with the engine (`lib/proxy.js`): each row names a
|
|
2018
|
+
* PROGRAM (display only for now), an IP allow-list (`1.1.1.*`, comma lists) and
|
|
2019
|
+
* a PORT allow-list (`5432`, `1000-1010`). An empty host or port cell means
|
|
2020
|
+
* "this axis is unrestricted", which the host route reports back so the table
|
|
2021
|
+
* can colour the row instead of silently allowing the world.
|
|
2022
|
+
*
|
|
2023
|
+
* Editing is local until 保存: the engine keeps its listeners until restarted,
|
|
2024
|
+
* so the dialog says so out loud instead of pretending a save took effect.
|
|
2025
|
+
*/
|
|
1792
2026
|
/** Scaled CSS for viewers that paint their own font (CodeMirror pins 13px). */
|
|
1793
2027
|
function viewerFontCss(size) {
|
|
1794
2028
|
return '[data-workbench="ris-ide"] .cm-editor{font-size:' + size + 'px !important}'
|
|
@@ -3121,32 +3355,68 @@ window.__ModuleLoader__.load({
|
|
|
3121
3355
|
]
|
|
3122
3356
|
}
|
|
3123
3357
|
|
|
3124
|
-
/**
|
|
3358
|
+
/**
|
|
3359
|
+
* Copy text through the async clipboard API, with a legacy fallback.
|
|
3360
|
+
*
|
|
3361
|
+
* `writeText` can REJECT even in a click handler: when the workbench page is
|
|
3362
|
+
* embedded in the risd maintenance iframe, the parent's permissions policy may
|
|
3363
|
+
* block clipboard-write, and an unhandled rejection here used to surface as
|
|
3364
|
+
* 「后台任务出错」 with the copy silently lost (m09396 ③). So every failure —
|
|
3365
|
+
* missing API, rejected promise, denied permission — falls back to the
|
|
3366
|
+
* textarea + execCommand trick, which only needs the click's user activation.
|
|
3367
|
+
* @param {string} text - the text to copy.
|
|
3368
|
+
* @returns {Promise<boolean>} true when the clipboard (or the fallback) took it.
|
|
3369
|
+
*/
|
|
3125
3370
|
function copyText(text) {
|
|
3126
3371
|
var value = String(text === undefined || text === null ? '' : text)
|
|
3372
|
+
function legacy() {
|
|
3373
|
+
var previousFocus = null
|
|
3374
|
+
var previousRange = null
|
|
3375
|
+
try {
|
|
3376
|
+
previousFocus = document.activeElement
|
|
3377
|
+
var selection = typeof window.getSelection === 'function' ? window.getSelection() : null
|
|
3378
|
+
if (selection !== null && selection.rangeCount > 0) previousRange = selection.getRangeAt(0).cloneRange()
|
|
3379
|
+
} catch { /* no selection API: nothing to restore */ }
|
|
3380
|
+
try {
|
|
3381
|
+
var area = document.createElement('textarea')
|
|
3382
|
+
area.value = value
|
|
3383
|
+
area.setAttribute('readonly', '1')
|
|
3384
|
+
area.style.position = 'fixed'
|
|
3385
|
+
area.style.opacity = '0'
|
|
3386
|
+
document.body.appendChild(area)
|
|
3387
|
+
area.select()
|
|
3388
|
+
var ok = document.execCommand('copy')
|
|
3389
|
+
document.body.removeChild(area)
|
|
3390
|
+
return ok === true
|
|
3391
|
+
} catch {
|
|
3392
|
+
return false
|
|
3393
|
+
} finally {
|
|
3394
|
+
// The textarea stole focus (and the selection): put the user back where
|
|
3395
|
+
// they were, or the next keystroke lands on the body (review C3-P2-13).
|
|
3396
|
+
try {
|
|
3397
|
+
if (previousFocus !== null && typeof previousFocus.focus === 'function') {
|
|
3398
|
+
previousFocus.focus({ preventScroll: true })
|
|
3399
|
+
}
|
|
3400
|
+
if (previousRange !== null) {
|
|
3401
|
+
var restored = window.getSelection()
|
|
3402
|
+
restored.removeAllRanges()
|
|
3403
|
+
restored.addRange(previousRange)
|
|
3404
|
+
}
|
|
3405
|
+
} catch { /* best effort */ }
|
|
3406
|
+
}
|
|
3407
|
+
}
|
|
3127
3408
|
try {
|
|
3128
3409
|
if (typeof navigator !== 'undefined' && navigator !== null
|
|
3129
3410
|
&& navigator.clipboard !== undefined && typeof navigator.clipboard.writeText === 'function') {
|
|
3130
|
-
|
|
3131
|
-
|
|
3411
|
+
return Promise.resolve(navigator.clipboard.writeText(value)).then(
|
|
3412
|
+
function () { return true },
|
|
3413
|
+
function () { return legacy() },
|
|
3414
|
+
)
|
|
3132
3415
|
}
|
|
3133
3416
|
} catch {
|
|
3134
3417
|
// fall through to the textarea trick
|
|
3135
3418
|
}
|
|
3136
|
-
|
|
3137
|
-
var area = document.createElement('textarea')
|
|
3138
|
-
area.value = value
|
|
3139
|
-
area.setAttribute('readonly', '1')
|
|
3140
|
-
area.style.position = 'fixed'
|
|
3141
|
-
area.style.opacity = '0'
|
|
3142
|
-
document.body.appendChild(area)
|
|
3143
|
-
area.select()
|
|
3144
|
-
var ok = document.execCommand('copy')
|
|
3145
|
-
document.body.removeChild(area)
|
|
3146
|
-
return ok === true
|
|
3147
|
-
} catch {
|
|
3148
|
-
return false
|
|
3149
|
-
}
|
|
3419
|
+
return Promise.resolve(legacy())
|
|
3150
3420
|
}
|
|
3151
3421
|
|
|
3152
3422
|
/** Basename of a slash path ('' when empty). */
|
|
@@ -5926,7 +6196,9 @@ window.__ModuleLoader__.load({
|
|
|
5926
6196
|
onClick: function () {
|
|
5927
6197
|
var entry = treeMenu.entry
|
|
5928
6198
|
setTreeMenu(null)
|
|
5929
|
-
|
|
6199
|
+
void copyText(fileBaseName(entry.path)).then(function (ok) {
|
|
6200
|
+
notify(ok ? '已复制文件名:' + fileBaseName(entry.path) : '复制失败:剪贴板不可用')
|
|
6201
|
+
})
|
|
5930
6202
|
},
|
|
5931
6203
|
}, '复制文件名'),
|
|
5932
6204
|
h('button', {
|
|
@@ -5934,7 +6206,9 @@ window.__ModuleLoader__.load({
|
|
|
5934
6206
|
onClick: function () {
|
|
5935
6207
|
var entry = treeMenu.entry
|
|
5936
6208
|
setTreeMenu(null)
|
|
5937
|
-
|
|
6209
|
+
void copyText(entry.path).then(function (ok) {
|
|
6210
|
+
notify(ok ? '已复制路径:' + entry.path : '复制失败:剪贴板不可用')
|
|
6211
|
+
})
|
|
5938
6212
|
},
|
|
5939
6213
|
}, '复制文件路径'),
|
|
5940
6214
|
h('button', {
|
|
@@ -6311,7 +6585,12 @@ window.__ModuleLoader__.load({
|
|
|
6311
6585
|
var findInput = findInputRef.current
|
|
6312
6586
|
if (findInput !== null && findInput !== undefined) {
|
|
6313
6587
|
findInput.focus()
|
|
6314
|
-
|
|
6588
|
+
// Caret at the END, never a selection: the bar searches on every
|
|
6589
|
+
// keystroke below, and a selected term would be replaced by the first
|
|
6590
|
+
// one (the same bug the CodeMirror panel had).
|
|
6591
|
+
if (typeof findInput.setSelectionRange === 'function') {
|
|
6592
|
+
findInput.setSelectionRange(findInput.value.length, findInput.value.length)
|
|
6593
|
+
}
|
|
6315
6594
|
}
|
|
6316
6595
|
return
|
|
6317
6596
|
}
|
|
@@ -6583,6 +6862,21 @@ window.__ModuleLoader__.load({
|
|
|
6583
6862
|
+ '@supports not selector(::-webkit-scrollbar){'
|
|
6584
6863
|
+ '[data-workbench="ris-ide"] *{scrollbar-width:thin;scrollbar-color:rgba(140,140,140,0.55) rgba(127,127,127,0.10)}}'
|
|
6585
6864
|
|
|
6865
|
+
/**
|
|
6866
|
+
* File-tree hover affordance: a faint grey row background under the pointer.
|
|
6867
|
+
*
|
|
6868
|
+
* A background changes no metrics, so the row and every sibling stay put —
|
|
6869
|
+
* padding/height hacks would make the tree jump under the mouse. The selected
|
|
6870
|
+
* rows (S.treeRowOn / treeRowMulti) carry their tint as an INLINE style, so
|
|
6871
|
+
* this stylesheet-level hover always loses to them: 「优先级低于选中后的背景色」
|
|
6872
|
+
* holds without extra rules (user口径: hover 用浅灰背景,别比选中色重). Underline
|
|
6873
|
+
* was tried first and was too subtle at a 14px row height.
|
|
6874
|
+
*/
|
|
6875
|
+
var TREE_HOVER_CSS = '[data-workbench="ris-ide"] [data-tree-path]:hover'
|
|
6876
|
+
// The plain rgba line is the fallback for engines without `color-mix`
|
|
6877
|
+
// (Chromium < 111): without it the hover rule would be dropped entirely.
|
|
6878
|
+
+ '{background:rgba(0,0,0,0.05);background:color-mix(in srgb, currentColor 7%, transparent)}'
|
|
6879
|
+
|
|
6586
6880
|
/**
|
|
6587
6881
|
* The editor's find panel, restyled to belong to the IDE (user口径: 美化一下
|
|
6588
6882
|
* 编辑器的搜索面板,风格和整体不一致). CodeMirror ships a 2018-looking strip:
|
|
@@ -7188,6 +7482,13 @@ var [ui, setUi] = useState(function () {
|
|
|
7188
7482
|
* query (or the `git grep` output) away, so the same row can be reopened.
|
|
7189
7483
|
*/
|
|
7190
7484
|
var searchCacheRef = useRef(new Map())
|
|
7485
|
+
/**
|
|
7486
|
+
* Bumped when the cached results for the CURRENT query must be thrown away
|
|
7487
|
+
* (Ctrl+R, or a save in this window). `searchCacheRef` is keyed by query text
|
|
7488
|
+
* only, while its payload is `git grep` output captured at one moment — so
|
|
7489
|
+
* without a kick an edited file kept showing the old hits forever.
|
|
7490
|
+
*/
|
|
7491
|
+
var [searchReload, setSearchReload] = useState(0)
|
|
7191
7492
|
/** A shortcut asked for the box: focus AND select its text once mounted. */
|
|
7192
7493
|
var [searchFocusNonce, setSearchFocusNonce] = useState(0)
|
|
7193
7494
|
var searchFocusPendingRef = useRef(false)
|
|
@@ -7681,8 +7982,6 @@ var [ui, setUi] = useState(function () {
|
|
|
7681
7982
|
}
|
|
7682
7983
|
return String(logPathValue).split('/').pop().replace(/\.log$/, '')
|
|
7683
7984
|
}
|
|
7684
|
-
/** Basename of a file path. */
|
|
7685
|
-
function shortName(path) { return String(path === undefined || path === null ? '' : path).split('/').pop() }
|
|
7686
7985
|
|
|
7687
7986
|
// The debug/log target follows the SELECTED debug tab, not "the first
|
|
7688
7987
|
// program": the workbench is workspace-level, several programs coexist.
|
|
@@ -8086,7 +8385,7 @@ var [ui, setUi] = useState(function () {
|
|
|
8086
8385
|
}
|
|
8087
8386
|
var next = capOpenFiles(openFiles, path, FILE_LIMIT, isDirty)
|
|
8088
8387
|
if (next === null) {
|
|
8089
|
-
note('已打开 ' + FILE_LIMIT + ' 个文件且都有未保存修改,请先关闭一个再打开 ' +
|
|
8388
|
+
note('已打开 ' + FILE_LIMIT + ' 个文件且都有未保存修改,请先关闭一个再打开 ' + fileBaseName(path))
|
|
8090
8389
|
return
|
|
8091
8390
|
}
|
|
8092
8391
|
// A path that is NOT already open must be read from disk: a document or
|
|
@@ -8109,7 +8408,7 @@ var [ui, setUi] = useState(function () {
|
|
|
8109
8408
|
if (request === null || typeof request !== 'object') return
|
|
8110
8409
|
if (typeof request.path !== 'string' || request.path === '') return
|
|
8111
8410
|
openPath(request.path)
|
|
8112
|
-
note('已在编辑器打开 ' +
|
|
8411
|
+
note('已在编辑器打开 ' + fileBaseName(request.path) + '(改完保存即生效)')
|
|
8113
8412
|
}, [configOpenNonce])
|
|
8114
8413
|
function closePath(path) {
|
|
8115
8414
|
debugOpenedRef.current = debugOpenedRef.current.filter(function (item) { return item !== path })
|
|
@@ -8133,7 +8432,7 @@ var [ui, setUi] = useState(function () {
|
|
|
8133
8432
|
setRecentFiles(function (previous) {
|
|
8134
8433
|
return previous.filter(function (item) { return item !== path })
|
|
8135
8434
|
})
|
|
8136
|
-
note('文件不存在,已从最近历史移除:' +
|
|
8435
|
+
note('文件不存在,已从最近历史移除:' + fileBaseName(path))
|
|
8137
8436
|
return
|
|
8138
8437
|
}
|
|
8139
8438
|
openPath(path)
|
|
@@ -8161,6 +8460,9 @@ var [ui, setUi] = useState(function () {
|
|
|
8161
8460
|
if (doc === undefined || doc.kind !== 'text') return Promise.resolve(true)
|
|
8162
8461
|
setSavingPath(path)
|
|
8163
8462
|
return fsWrite(scopeRef.current, path, docTextForDisk(doc)).then(function () {
|
|
8463
|
+
// The file on disk just changed, so any cached `git grep` payload for the
|
|
8464
|
+
// query in the box is stale; refresh it (a no-op when nothing is cached).
|
|
8465
|
+
reloadWorkspaceSearch(treeQuery)
|
|
8164
8466
|
setDocs(function (prev) {
|
|
8165
8467
|
var next = Object.assign({}, prev)
|
|
8166
8468
|
var current = next[path]
|
|
@@ -8219,7 +8521,7 @@ var [ui, setUi] = useState(function () {
|
|
|
8219
8521
|
try {
|
|
8220
8522
|
await fsWrite(scopeRef.current, path, docTextForDisk(doc))
|
|
8221
8523
|
} catch (problem) {
|
|
8222
|
-
note('保存失败:' +
|
|
8524
|
+
note('保存失败:' + fileBaseName(path) + ' ' + messageOf(problem))
|
|
8223
8525
|
return false
|
|
8224
8526
|
}
|
|
8225
8527
|
setDocs(function (previous) {
|
|
@@ -8231,6 +8533,46 @@ var [ui, setUi] = useState(function () {
|
|
|
8231
8533
|
}
|
|
8232
8534
|
return true
|
|
8233
8535
|
}
|
|
8536
|
+
/**
|
|
8537
|
+
* Answer the maintenance page's questions about unsaved buffers, and save
|
|
8538
|
+
* them all on request (m10900).
|
|
8539
|
+
*
|
|
8540
|
+
* The page embeds this window in an iframe on a different origin (daemon
|
|
8541
|
+
* port vs the dsh web port), so it cannot read `docs`; it asks over
|
|
8542
|
+
* postMessage before it reloads itself. Only the immediate parent is served,
|
|
8543
|
+
* and only these two message shapes, so another opener cannot drive the
|
|
8544
|
+
* editor. A page that predates the bridge simply never asks.
|
|
8545
|
+
*/
|
|
8546
|
+
useEffect(function () {
|
|
8547
|
+
var reply = function (payload) {
|
|
8548
|
+
try { window.parent.postMessage(payload, '*') } catch { /* parent gone */ }
|
|
8549
|
+
}
|
|
8550
|
+
var onMessage = function (event) {
|
|
8551
|
+
if (event.source !== window.parent) return
|
|
8552
|
+
var data = event.data
|
|
8553
|
+
if (data === null || typeof data !== 'object') return
|
|
8554
|
+
if (data.type === 'dsh-ris-ide:probe-dirty') {
|
|
8555
|
+
var dirty = openFiles.filter(function (path) { return isDirty(path) === true })
|
|
8556
|
+
reply({
|
|
8557
|
+
type: 'dsh-ris-ide:dirty-report',
|
|
8558
|
+
requestId: data.requestId,
|
|
8559
|
+
count: dirty.length,
|
|
8560
|
+
names: dirty.slice(0, 5).map(fileBaseName),
|
|
8561
|
+
})
|
|
8562
|
+
return
|
|
8563
|
+
}
|
|
8564
|
+
if (data.type === 'dsh-ris-ide:save-all') {
|
|
8565
|
+
var pending = openFiles.filter(function (path) { return isDirty(path) === true })
|
|
8566
|
+
Promise.resolve(saveBulk(pending)).then(function (ok) {
|
|
8567
|
+
reply({ type: 'dsh-ris-ide:save-all-done', requestId: data.requestId, ok: ok === true })
|
|
8568
|
+
}, function () {
|
|
8569
|
+
reply({ type: 'dsh-ris-ide:save-all-done', requestId: data.requestId, ok: false })
|
|
8570
|
+
})
|
|
8571
|
+
}
|
|
8572
|
+
}
|
|
8573
|
+
window.addEventListener('message', onMessage)
|
|
8574
|
+
return function () { window.removeEventListener('message', onMessage) }
|
|
8575
|
+
}, [openFiles, docs, viewerStates])
|
|
8234
8576
|
/**
|
|
8235
8577
|
* Bulk close (right-click → 关闭其他/全部关闭). Dirty tabs are never dropped
|
|
8236
8578
|
* silently: one prompt offers save-all / discard-all / cancel for the batch.
|
|
@@ -8955,6 +9297,30 @@ var [ui, setUi] = useState(function () {
|
|
|
8955
9297
|
return function () { window.removeEventListener('mousedown', onDown); window.removeEventListener('keydown', onKey) }
|
|
8956
9298
|
}, [tabMenu])
|
|
8957
9299
|
|
|
9300
|
+
/**
|
|
9301
|
+
* Re-reads the workspace for the current query instead of replaying the cache.
|
|
9302
|
+
*
|
|
9303
|
+
* `searchCacheRef` holds `git grep`/name-search payloads keyed by the query
|
|
9304
|
+
* TEXT, and it is what lets a picked row be reopened without re-running the
|
|
9305
|
+
* search. The price is that file contents are not part of the key: after an
|
|
9306
|
+
* edit the same query kept returning the old hits (reported bug). Any
|
|
9307
|
+
* explicit "search again" — Ctrl+R or a save in this window — drops the two
|
|
9308
|
+
* entries for the query and bumps `searchReload`, which the effects depend on.
|
|
9309
|
+
* @param {string} [text] - the query to refresh; defaults to the box's value.
|
|
9310
|
+
*/
|
|
9311
|
+
function reloadWorkspaceSearch(text) {
|
|
9312
|
+
var raw = typeof text === 'string' ? text : treeQuery
|
|
9313
|
+
var query = String(raw === undefined || raw === null ? '' : raw).trim()
|
|
9314
|
+
var dropped = false
|
|
9315
|
+
if (query !== '') {
|
|
9316
|
+
dropped = searchCacheRef.current.delete('content:' + query) || dropped
|
|
9317
|
+
dropped = searchCacheRef.current.delete('name:' + query) || dropped
|
|
9318
|
+
}
|
|
9319
|
+
// Nothing cached: whatever is on screen came from a run that is still
|
|
9320
|
+
// fresh (or is already in flight), so a second kick would only abort it.
|
|
9321
|
+
if (dropped) setSearchReload(function (value) { return value + 1 })
|
|
9322
|
+
}
|
|
9323
|
+
|
|
8958
9324
|
/** Toolbar search: debounce, then stream matches page by page from the host route. */
|
|
8959
9325
|
useEffect(function () {
|
|
8960
9326
|
var text = treeQuery.trim()
|
|
@@ -8996,7 +9362,7 @@ var [ui, setUi] = useState(function () {
|
|
|
8996
9362
|
clearTimeout(timer)
|
|
8997
9363
|
if (controller !== null) controller.abort()
|
|
8998
9364
|
}
|
|
8999
|
-
}, [treeQuery, cwd])
|
|
9365
|
+
}, [treeQuery, cwd, searchReload])
|
|
9000
9366
|
|
|
9001
9367
|
/**
|
|
9002
9368
|
* Content search for the same query: slower than the name search (one
|
|
@@ -9041,12 +9407,17 @@ var [ui, setUi] = useState(function () {
|
|
|
9041
9407
|
clearTimeout(timer)
|
|
9042
9408
|
if (controller !== null) controller.abort()
|
|
9043
9409
|
}
|
|
9044
|
-
}, [treeQuery, cwd])
|
|
9410
|
+
}, [treeQuery, cwd, searchReload])
|
|
9045
9411
|
|
|
9046
9412
|
/**
|
|
9047
9413
|
* A shortcut (Ctrl+R / Ctrl+Shift+R / F3) focused the box: select its text
|
|
9048
9414
|
* once React has painted the value, otherwise the controlled update resets
|
|
9049
9415
|
* the selection to the end and the highlight the user asked for is lost.
|
|
9416
|
+
*
|
|
9417
|
+
* The same shortcut is also the user's "search again" gesture (the standalone
|
|
9418
|
+
* window never lets it reload the page), so it re-reads the workspace: the
|
|
9419
|
+
* query text did not change, and without this the cache would replay the hits
|
|
9420
|
+
* from before the file was edited.
|
|
9050
9421
|
*/
|
|
9051
9422
|
useEffect(function () {
|
|
9052
9423
|
if (searchFocusPendingRef.current !== true) return
|
|
@@ -9055,6 +9426,7 @@ var [ui, setUi] = useState(function () {
|
|
|
9055
9426
|
searchFocusPendingRef.current = false
|
|
9056
9427
|
input.focus()
|
|
9057
9428
|
input.select()
|
|
9429
|
+
reloadWorkspaceSearch(treeQuery)
|
|
9058
9430
|
}, [searchFocusNonce, treeQuery])
|
|
9059
9431
|
|
|
9060
9432
|
/**
|
|
@@ -9119,24 +9491,9 @@ var [ui, setUi] = useState(function () {
|
|
|
9119
9491
|
applyFind(0)
|
|
9120
9492
|
}
|
|
9121
9493
|
}
|
|
9122
|
-
|
|
9123
|
-
|
|
9124
|
-
|
|
9125
|
-
// First load with no explicit target: pick the first RUNNING service (else the
|
|
9126
|
-
// first program) so both panes show something instead of a blank placeholder.
|
|
9127
|
-
useEffect(function () {
|
|
9128
|
-
var running = programs.filter(function (program) {
|
|
9129
|
-
return program.running !== null && program.running !== undefined && program.running.alive === true
|
|
9130
|
-
})
|
|
9131
|
-
if (running.length === 0) return
|
|
9132
|
-
if (activePathRef.current !== '') return
|
|
9133
|
-
var preferred = running.filter(function (program) { return program.kind === 'spring' })[0] || running[0]
|
|
9134
|
-
if (preferred !== undefined) {
|
|
9135
|
-
setActivePath(preferred.logPath)
|
|
9136
|
-
activePathRef.current = preferred.logPath
|
|
9137
|
-
}
|
|
9138
|
-
}, [runningSignature, sessionId])
|
|
9139
|
-
|
|
9494
|
+
// No auto-pick on first load (m07431): the console starts with no selected row,
|
|
9495
|
+
// so the log pane must stay parked on its placeholder instead of loading and
|
|
9496
|
+
// locating a file the user never asked for. A click on a row is the only way in.
|
|
9140
9497
|
/** Finish a "save then close": the viewer's saveState is the signal. */
|
|
9141
9498
|
useEffect(function () {
|
|
9142
9499
|
if (pendingSaveClose === undefined) return
|
|
@@ -9362,6 +9719,7 @@ var [ui, setUi] = useState(function () {
|
|
|
9362
9719
|
var style = Object.assign({}, base)
|
|
9363
9720
|
if (opts.icon === true) Object.assign(style, { width: 22, minWidth: 22, padding: '1px 0', textAlign: 'center' })
|
|
9364
9721
|
if (typeof opts.width === 'number') Object.assign(style, { width: opts.width, minWidth: opts.width })
|
|
9722
|
+
if (typeof opts.color === 'string') Object.assign(style, { color: opts.color })
|
|
9365
9723
|
if (typeof opts.height === 'number') {
|
|
9366
9724
|
// One fixed row height: the top bar mixes glyph buttons (📄 ⚙ ⟲) with
|
|
9367
9725
|
// two-character ones (A- A+), and padding-only sizing made them differ
|
|
@@ -9696,7 +10054,7 @@ var [ui, setUi] = useState(function () {
|
|
|
9696
10054
|
scope: scopeRef.current,
|
|
9697
10055
|
path: path,
|
|
9698
10056
|
fontRatio: fontRatio,
|
|
9699
|
-
title:
|
|
10057
|
+
title: fileBaseName(path),
|
|
9700
10058
|
text: doc.text,
|
|
9701
10059
|
savedText: doc.saved,
|
|
9702
10060
|
onEditorMenu: setEditorMenu,
|
|
@@ -9762,7 +10120,7 @@ var [ui, setUi] = useState(function () {
|
|
|
9762
10120
|
} else if (/\.html?$/i.test(openFile)) {
|
|
9763
10121
|
content = h('iframe', {
|
|
9764
10122
|
style: S.previewFrame, sandbox: '', srcDoc: doc.text,
|
|
9765
|
-
title: 'HTML 预览:' +
|
|
10123
|
+
title: 'HTML 预览:' + fileBaseName(openFile), 'data-preview-frame': '1',
|
|
9766
10124
|
})
|
|
9767
10125
|
} else {
|
|
9768
10126
|
content = h('div', {
|
|
@@ -9791,8 +10149,8 @@ var [ui, setUi] = useState(function () {
|
|
|
9791
10149
|
type: 'button', style: Object.assign({}, S.buttonOff, { padding: '0 8px' }),
|
|
9792
10150
|
'data-action': previewing ? 'preview-exit' : 'preview-enter',
|
|
9793
10151
|
title: previewing
|
|
9794
|
-
? '返回编辑 ' +
|
|
9795
|
-
: '预览 ' +
|
|
10152
|
+
? '返回编辑 ' + fileBaseName(openFile)
|
|
10153
|
+
: '预览 ' + fileBaseName(openFile) + '(Markdown/HTML 在编辑器区域内渲染,显示当前内容)',
|
|
9796
10154
|
onClick: function () { togglePreview() },
|
|
9797
10155
|
}, previewing ? '编辑' : '预览'))
|
|
9798
10156
|
}
|
|
@@ -9818,7 +10176,7 @@ var [ui, setUi] = useState(function () {
|
|
|
9818
10176
|
onClick: function () { setOpenFile(path) },
|
|
9819
10177
|
onContextMenu: function (event) { openTabMenu('source', event) },
|
|
9820
10178
|
},
|
|
9821
|
-
|
|
10179
|
+
fileBaseName(path) + (isDirty(path) ? '*' : ''),
|
|
9822
10180
|
h('span', {
|
|
9823
10181
|
style: S.tabClose, title: '关闭', 'data-tab-close': 'source',
|
|
9824
10182
|
onClick: function (event) { event.stopPropagation(); requestClose(path) },
|
|
@@ -9847,7 +10205,7 @@ var [ui, setUi] = useState(function () {
|
|
|
9847
10205
|
}, '▾'))
|
|
9848
10206
|
var prompt = pendingClose !== undefined
|
|
9849
10207
|
? h('div', { style: Object.assign({}, S.notice, { display: 'flex', alignItems: 'center', gap: 6 }), 'data-close-prompt': '1' },
|
|
9850
|
-
h('span', { style: { flex: '1 1 auto', minWidth: 0 } }, '「' +
|
|
10208
|
+
h('span', { style: { flex: '1 1 auto', minWidth: 0 } }, '「' + fileBaseName(pendingClose) + '」有未保存的修改:'),
|
|
9851
10209
|
h('button', {
|
|
9852
10210
|
type: 'button', style: S.button, 'data-action': 'save-close', title: '保存后关闭',
|
|
9853
10211
|
onClick: function () {
|
|
@@ -9886,7 +10244,7 @@ var [ui, setUi] = useState(function () {
|
|
|
9886
10244
|
? h('div', { style: Object.assign({}, S.notice, { display: 'flex', alignItems: 'center', gap: 6 }), 'data-bulk-prompt': '1' },
|
|
9887
10245
|
h('span', { style: { flex: '1 1 auto', minWidth: 0 } },
|
|
9888
10246
|
pendingBulk.dirty.length + ' 个页签有未保存的修改('
|
|
9889
|
-
+ pendingBulk.dirty.slice(0, 2).map(
|
|
10247
|
+
+ pendingBulk.dirty.slice(0, 2).map(fileBaseName).join('、')
|
|
9890
10248
|
+ (pendingBulk.dirty.length > 2 ? ' 等' : '') + '):'),
|
|
9891
10249
|
h('button', {
|
|
9892
10250
|
type: 'button', style: S.button, 'data-action': 'bulk-save-close', title: '全部保存后关闭',
|
|
@@ -9955,7 +10313,7 @@ var [ui, setUi] = useState(function () {
|
|
|
9955
10313
|
h('span', { style: { opacity: 0.7, flex: '0 0 auto' } }, row.open === true ? '●' : '·'),
|
|
9956
10314
|
h('span', {
|
|
9957
10315
|
style: { flex: '1 1 auto', minWidth: 0, overflow: 'hidden', textOverflow: 'ellipsis', whiteSpace: 'nowrap' },
|
|
9958
|
-
},
|
|
10316
|
+
}, fileBaseName(row.path) + (dirty ? '*' : '')),
|
|
9959
10317
|
row.open === true ? null : h('span', { style: { opacity: 0.5, fontSize: 10, flex: '0 0 auto' } }, '历史'))
|
|
9960
10318
|
return header === null ? item : [header, item]
|
|
9961
10319
|
}))
|
|
@@ -9973,7 +10331,7 @@ var [ui, setUi] = useState(function () {
|
|
|
9973
10331
|
return h('div', { style: S.paneOverlay, 'data-editor-diff': openFile },
|
|
9974
10332
|
h('div', { style: Object.assign({}, S.notice, { display: 'flex', alignItems: 'center', gap: 6 }), 'data-diff-head': '1' },
|
|
9975
10333
|
h('span', { style: { flex: '1 1 auto', minWidth: 0 } },
|
|
9976
|
-
'与磁盘版本对比:' +
|
|
10334
|
+
'与磁盘版本对比:' + fileBaseName(openFile) + '(' + changed + ' 行变化;+ 新增 / − 删除)'),
|
|
9977
10335
|
h('button', {
|
|
9978
10336
|
type: 'button', style: S.button, 'data-action': 'diff-close',
|
|
9979
10337
|
onClick: function () { setDiffPath(null) },
|
|
@@ -10147,11 +10505,25 @@ var [ui, setUi] = useState(function () {
|
|
|
10147
10505
|
placeholder: '在工作空间中检索文件…',
|
|
10148
10506
|
title: '全工作空间文件名检索(结果在搜索框下方,点击直接打开/定位)',
|
|
10149
10507
|
'data-action': 'tree-search',
|
|
10150
|
-
onChange: function (event) {
|
|
10508
|
+
onChange: function (event) {
|
|
10509
|
+
var value = event.target.value
|
|
10510
|
+
setTreeQuery(value)
|
|
10511
|
+
// The dropdown is focus-gated; an edit that lands while the box is
|
|
10512
|
+
// already focused must still bring it back (no focus event fires).
|
|
10513
|
+
if (value.trim() !== '') setSearchFocused(true)
|
|
10514
|
+
},
|
|
10151
10515
|
onFocus: function () { setSearchFocused(true) },
|
|
10152
10516
|
onBlur: function () { setSearchFocused(false) },
|
|
10153
10517
|
onKeyDown: function (event) {
|
|
10154
|
-
if (event.key === 'Escape') {
|
|
10518
|
+
if (event.key === 'Escape') {
|
|
10519
|
+
event.preventDefault()
|
|
10520
|
+
// Escape only gives the caret back: the query and its results stay, so
|
|
10521
|
+
// refocusing the box shows them again. Clearing here used to throw the
|
|
10522
|
+
// typed query away for a key that reads as "leave the box".
|
|
10523
|
+
if (searchInputRef.current !== null) searchInputRef.current.blur()
|
|
10524
|
+
else setSearchFocused(false)
|
|
10525
|
+
return
|
|
10526
|
+
}
|
|
10155
10527
|
// Whichever dropdown is open is the walkable list: the recent-file list
|
|
10156
10528
|
// while the box is empty, the results once a query is typed.
|
|
10157
10529
|
var matches = searchHits !== null && searchHits !== undefined && Array.isArray(searchHits.matches) ? searchHits.matches : []
|
|
@@ -10518,7 +10890,7 @@ var [ui, setUi] = useState(function () {
|
|
|
10518
10890
|
},
|
|
10519
10891
|
// The sidebar's CodeMirror theme pins 13px, so the embedded viewer needs
|
|
10520
10892
|
// this rule, not inheritance, to follow A−/A+.
|
|
10521
|
-
h('style', { key: 'ide-font' }, viewerFontCss(uiFont) + viewerThemeCss(pageDark) + DEBUG_LINE_CSS + PREVIEW_CSS + SELECTION_CSS + SCROLLBAR_CSS + SEARCH_PANEL_CSS + TOAST_CSS + PROGRAM_LOADING_CSS),
|
|
10893
|
+
h('style', { key: 'ide-font' }, viewerFontCss(uiFont) + viewerThemeCss(pageDark) + DEBUG_LINE_CSS + PREVIEW_CSS + SELECTION_CSS + SCROLLBAR_CSS + SEARCH_PANEL_CSS + TOAST_CSS + PROGRAM_LOADING_CSS + TREE_HOVER_CSS),
|
|
10522
10894
|
(function () {
|
|
10523
10895
|
var panes = {
|
|
10524
10896
|
tree: h(IdeTree, {
|
|
@@ -10978,6 +11350,7 @@ var [ui, setUi] = useState(function () {
|
|
|
10978
11350
|
*/
|
|
10979
11351
|
function apply(ctx) {
|
|
10980
11352
|
guardWindowErrors(false)
|
|
11353
|
+
watchClientBuild()
|
|
10981
11354
|
if (typeof window !== 'undefined') window.__dshRisIdeWindow = false
|
|
10982
11355
|
// The IDE is a DSH right-Sidebar tab: a tab TYPE (stage one) plus its body
|
|
10983
11356
|
// and chip title (stage two), all through the official registry — no other
|
|
@@ -11025,16 +11398,16 @@ var [ui, setUi] = useState(function () {
|
|
|
11025
11398
|
}, 'dsh-ris-ide: right-sidebar tab title')
|
|
11026
11399
|
// A SECOND entry point for the same panel: a header button in the Session
|
|
11027
11400
|
// header, immediately to the right of DSH's own "open in app" action
|
|
11028
|
-
// (order -10), so it reads as "open this workspace's IDE". It opens the
|
|
11029
|
-
//
|
|
11030
|
-
//
|
|
11401
|
+
// (order -10), so it reads as "open this workspace's IDE". It opens the risd
|
|
11402
|
+
// maintenance page (which embeds the IDE and can switch workspace); when no
|
|
11403
|
+
// daemon is leased it falls back to the plugin's standalone window.
|
|
11031
11404
|
ctx.effect(function () {
|
|
11032
11405
|
return ctx.slots.inject('conversation.session.header.utilities', function () {
|
|
11033
11406
|
return ctx.slots.register({
|
|
11034
11407
|
name: 'conversation.session.header.utilities',
|
|
11035
11408
|
id: 'ris-ide-window',
|
|
11036
11409
|
order: -8,
|
|
11037
|
-
label: function () { return '
|
|
11410
|
+
label: function () { return '打开 risd 维护页(IDE 内嵌)' },
|
|
11038
11411
|
}, RisIdeWindowAction)
|
|
11039
11412
|
})
|
|
11040
11413
|
}, 'dsh-ris-ide: session-header window button')
|
|
@@ -11178,14 +11551,11 @@ var [ui, setUi] = useState(function () {
|
|
|
11178
11551
|
// the single-window notice with a manual choice.
|
|
11179
11552
|
await requestStandaloneWindowClose(windowName)
|
|
11180
11553
|
}
|
|
11181
|
-
// A browser
|
|
11182
|
-
//
|
|
11183
|
-
//
|
|
11184
|
-
|
|
11185
|
-
var
|
|
11186
|
-
var workHeight = screenInfo !== null && typeof screenInfo.availHeight === 'number' && screenInfo.availHeight > 0 ? screenInfo.availHeight : 960
|
|
11187
|
-
var features = 'popup=yes,width=' + workWidth + ',height=' + workHeight + ',left=0,top=0'
|
|
11188
|
-
var handle = window.open(url.href, windowName, features)
|
|
11554
|
+
// A normal browser window/tab: no `popup=…` feature string. Asking for a popup
|
|
11555
|
+
// produced a chromeless window the user could not tab through or maximise like
|
|
11556
|
+
// every other page, and browsers ignore size hints in tabs anyway. The NAME
|
|
11557
|
+
// still keeps one window per workspace: re-opening the same name reuses it.
|
|
11558
|
+
var handle = window.open(url.href, windowName)
|
|
11189
11559
|
if (handle === null || handle === undefined) {
|
|
11190
11560
|
throw new Error('独立窗口被拦截:请允许本站弹窗后重试')
|
|
11191
11561
|
}
|
|
@@ -11271,6 +11641,7 @@ var [ui, setUi] = useState(function () {
|
|
|
11271
11641
|
* @param {{sessionId: string, cwd: string}} props - scope taken from the URL.
|
|
11272
11642
|
* @returns {object} the panel tree.
|
|
11273
11643
|
*/
|
|
11644
|
+
|
|
11274
11645
|
function StandaloneWindow(props) {
|
|
11275
11646
|
var initial = props.sessionId
|
|
11276
11647
|
var scopeState = useState(initial)
|
|
@@ -11314,6 +11685,7 @@ var [ui, setUi] = useState(function () {
|
|
|
11314
11685
|
// instead of letting the browser/dsh treat them as a fatal load failure.
|
|
11315
11686
|
guardWindowErrors(true)
|
|
11316
11687
|
if (typeof window !== 'undefined') window.__dshRisIdeWindow = true
|
|
11688
|
+
watchClientBuild()
|
|
11317
11689
|
var opts = options === null || options === undefined ? {} : options
|
|
11318
11690
|
var sessionId = typeof opts.sessionId === 'string' && opts.sessionId !== '' ? opts.sessionId : STANDALONE_SESSION
|
|
11319
11691
|
var cwd = typeof opts.cwd === 'string' && opts.cwd !== '' ? opts.cwd : knownWorkspaceCwd()
|
|
@@ -11367,46 +11739,263 @@ var [ui, setUi] = useState(function () {
|
|
|
11367
11739
|
}
|
|
11368
11740
|
}
|
|
11369
11741
|
|
|
11742
|
+
/** How long a prefetched daemon address stays fresh (ms). */
|
|
11743
|
+
var RISD_PREFETCH_TTL_MS = 20000
|
|
11744
|
+
|
|
11745
|
+
/**
|
|
11746
|
+
* Warm cache for the daemon address behind ⧉. The header button and the
|
|
11747
|
+
* sidebar console prefetch it on mount, so the click path usually only has to
|
|
11748
|
+
* call `window.open` — the visible delay was the on-demand spawn, but the host
|
|
11749
|
+
* view read is not free either and it sat in front of every click.
|
|
11750
|
+
*
|
|
11751
|
+
* A failed prefetch stays silent: the click then pays one round trip and can
|
|
11752
|
+
* still ask for `ensure`.
|
|
11753
|
+
* @type {{at: number, risd: {available: boolean, url: string}|null, pending: Promise|null}}
|
|
11754
|
+
*/
|
|
11755
|
+
var risdPrefetch = { at: 0, risd: null, pending: null }
|
|
11756
|
+
/** The ⧉ open in flight, so a double click cannot open two tabs. */
|
|
11757
|
+
var risdOpenPending = null
|
|
11758
|
+
|
|
11759
|
+
/** Test seam: forget the warm cache and any open in flight. */
|
|
11760
|
+
function resetRisdPrefetch() {
|
|
11761
|
+
risdPrefetch.at = 0
|
|
11762
|
+
risdPrefetch.risd = null
|
|
11763
|
+
risdPrefetch.pending = null
|
|
11764
|
+
risdOpenPending = null
|
|
11765
|
+
}
|
|
11766
|
+
|
|
11767
|
+
/**
|
|
11768
|
+
* The daemon address inside a host reply, or null when it is unavailable.
|
|
11769
|
+
* @param {object|null} body - parsed reply from the host (`{risd: {...}}`).
|
|
11770
|
+
* @returns {{available: boolean, url: string}|null} the address, or null.
|
|
11771
|
+
*/
|
|
11772
|
+
function risdAddressOf(body) {
|
|
11773
|
+
var risd = body !== null && body !== undefined ? body.risd : null
|
|
11774
|
+
if (risd !== null && risd !== undefined && risd.available === true && typeof risd.url === 'string' && risd.url !== '') {
|
|
11775
|
+
return { available: true, url: risd.url }
|
|
11776
|
+
}
|
|
11777
|
+
return null
|
|
11778
|
+
}
|
|
11779
|
+
|
|
11780
|
+
/**
|
|
11781
|
+
* The cached address while it is younger than the TTL.
|
|
11782
|
+
* @returns {{available: boolean, url: string}|null} the address, or null.
|
|
11783
|
+
*/
|
|
11784
|
+
function risdCachedAddress() {
|
|
11785
|
+
if (risdPrefetch.risd === null) return null
|
|
11786
|
+
if (Date.now() - risdPrefetch.at >= RISD_PREFETCH_TTL_MS) return null
|
|
11787
|
+
return risdPrefetch.risd
|
|
11788
|
+
}
|
|
11789
|
+
|
|
11790
|
+
/**
|
|
11791
|
+
* Remember a fresh answer; the empty one is never cached.
|
|
11792
|
+
* @param {{available: boolean, url: string}|null} risd - the address, or null.
|
|
11793
|
+
* @returns {{available: boolean, url: string}|null} the same value.
|
|
11794
|
+
*/
|
|
11795
|
+
function rememberRisdAddress(risd) {
|
|
11796
|
+
if (risd === null || risd === undefined) return null
|
|
11797
|
+
risdPrefetch.risd = risd
|
|
11798
|
+
risdPrefetch.at = Date.now()
|
|
11799
|
+
return risd
|
|
11800
|
+
}
|
|
11801
|
+
|
|
11802
|
+
/**
|
|
11803
|
+
* `GET /dsh-ris-ide/proxy`, reduced to the daemon address.
|
|
11804
|
+
* @param {{sessionId?: string, cwd?: string}} scope - owning session.
|
|
11805
|
+
* @returns {Promise<{available: boolean, url: string}|null>} the address, or null.
|
|
11806
|
+
*/
|
|
11807
|
+
async function fetchRisdAddress(scope) {
|
|
11808
|
+
var url = routeUrl('dsh-ris-ide/proxy')
|
|
11809
|
+
var sessionId = scope !== null && scope !== undefined && typeof scope.sessionId === 'string' ? scope.sessionId : ''
|
|
11810
|
+
var cwd = scope !== null && scope !== undefined && typeof scope.cwd === 'string' ? scope.cwd : ''
|
|
11811
|
+
if (sessionId !== '') url.searchParams.set('sessionId', sessionId)
|
|
11812
|
+
if (cwd !== '') url.searchParams.set('cwd', cwd)
|
|
11813
|
+
var response = await fetch(url.href, { headers: { accept: 'application/json' } })
|
|
11814
|
+
var body = await response.json().catch(function () { return null })
|
|
11815
|
+
return risdAddressOf(body)
|
|
11816
|
+
}
|
|
11817
|
+
|
|
11818
|
+
/**
|
|
11819
|
+
* The daemon address, from the warm cache when possible.
|
|
11820
|
+
*
|
|
11821
|
+
* In-flight requests are shared, so two mounts (header + console) cost one
|
|
11822
|
+
* request. Failures are silent: the click path falls back to `ensure`.
|
|
11823
|
+
* @param {{sessionId?: string, cwd?: string}} scope - owning session.
|
|
11824
|
+
* @returns {Promise<{available: boolean, url: string}|null>} the address, or null.
|
|
11825
|
+
*/
|
|
11826
|
+
function prefetchRisd(scope) {
|
|
11827
|
+
var cached = risdCachedAddress()
|
|
11828
|
+
if (cached !== null) return Promise.resolve(cached)
|
|
11829
|
+
if (risdPrefetch.pending !== null) return risdPrefetch.pending
|
|
11830
|
+
var pending = fetchRisdAddress(scope).then(function (risd) {
|
|
11831
|
+
risdPrefetch.pending = null
|
|
11832
|
+
return rememberRisdAddress(risd)
|
|
11833
|
+
}, function () {
|
|
11834
|
+
risdPrefetch.pending = null
|
|
11835
|
+
return null
|
|
11836
|
+
})
|
|
11837
|
+
risdPrefetch.pending = pending
|
|
11838
|
+
return pending
|
|
11839
|
+
}
|
|
11840
|
+
|
|
11841
|
+
/**
|
|
11842
|
+
* Put the maintenance page in its tab, on the IDE view, then focus it.
|
|
11843
|
+
*
|
|
11844
|
+
* Called synchronously from the click when the address is already cached, so
|
|
11845
|
+
* the popup stays inside the user gesture (browsers only allow it there).
|
|
11846
|
+
* @param {{url: string}} risd - the daemon address.
|
|
11847
|
+
* @param {string} cwd - workspace to preselect ('' = the daemon's own choice).
|
|
11848
|
+
* @returns {Window} the opened tab.
|
|
11849
|
+
* @throws {Error} when the browser blocked the popup.
|
|
11850
|
+
*/
|
|
11851
|
+
function openRisdTab(risd, cwd) {
|
|
11852
|
+
// Preselect this workspace but keep the user's own tab: ⧉ says "open the
|
|
11853
|
+
// maintenance page for this workspace", not "switch me to 开发环境" (m11345).
|
|
11854
|
+
// The page remembers the last tab, so an explicit `tab=` here would override
|
|
11855
|
+
// that choice and feel like a menu switch.
|
|
11856
|
+
var query = cwd !== '' ? '?cwd=' + encodeURIComponent(cwd) : ''
|
|
11857
|
+
var target = risd.url + '/ui' + query
|
|
11858
|
+
var handle = window.open(target, 'dsh-risd-ui')
|
|
11859
|
+
if (handle === null) throw new Error('维护页被拦截:请允许本站弹窗后重试')
|
|
11860
|
+
if (typeof handle.focus === 'function') handle.focus()
|
|
11861
|
+
return handle
|
|
11862
|
+
}
|
|
11863
|
+
|
|
11864
|
+
/**
|
|
11865
|
+
* Open the risd maintenance page, which embeds the IDE (and can switch
|
|
11866
|
+
* workspace), instead of spawning one window per workspace.
|
|
11867
|
+
*
|
|
11868
|
+
* The page lives on the daemon origin, so the client cannot guess it: the
|
|
11869
|
+
* host view (`GET /dsh-ris-ide/proxy`) reports `risd.url` while a daemon is
|
|
11870
|
+
* leased — prefetched on mount (see `prefetchRisd`), so ⧉ normally opens
|
|
11871
|
+
* without waiting. A cold click asks the host once and then `ensure`s the
|
|
11872
|
+
* daemon; when daemonMode is off (or the daemon stays unreachable) the
|
|
11873
|
+
* fallback keeps today's behaviour — the standalone window.
|
|
11874
|
+
*
|
|
11875
|
+
* One open at a time: a second click joins the promise in flight instead of
|
|
11876
|
+
* opening a second tab.
|
|
11877
|
+
* @param {{sessionId?: string, cwd?: string}} scope - owning session.
|
|
11878
|
+
* @param {Function} fallback - opens the standalone window when no daemon.
|
|
11879
|
+
* @returns {Promise<'risd'|'window'>} which entry point was used.
|
|
11880
|
+
*/
|
|
11881
|
+
async function openRisdPage(scope, fallback) {
|
|
11882
|
+
var cwd = scope !== null && scope !== undefined && typeof scope.cwd === 'string' ? scope.cwd : ''
|
|
11883
|
+
var sessionId = scope !== null && scope !== undefined && typeof scope.sessionId === 'string' ? scope.sessionId : ''
|
|
11884
|
+
if (risdOpenPending !== null) return risdOpenPending
|
|
11885
|
+
var cached = risdCachedAddress()
|
|
11886
|
+
if (cached !== null) {
|
|
11887
|
+
// No await before the popup: the cached address is the whole answer.
|
|
11888
|
+
openRisdTab(cached, cwd)
|
|
11889
|
+
return 'risd'
|
|
11890
|
+
}
|
|
11891
|
+
var pending = openRisdPageSlow({ sessionId: sessionId, cwd: cwd }, fallback).then(function (result) {
|
|
11892
|
+
risdOpenPending = null
|
|
11893
|
+
return result
|
|
11894
|
+
}, function (error) {
|
|
11895
|
+
risdOpenPending = null
|
|
11896
|
+
throw error
|
|
11897
|
+
})
|
|
11898
|
+
risdOpenPending = pending
|
|
11899
|
+
return pending
|
|
11900
|
+
}
|
|
11901
|
+
|
|
11902
|
+
/**
|
|
11903
|
+
* The cold half of `openRisdPage`: one host round trip, then `ensure`.
|
|
11904
|
+
* @param {{sessionId: string, cwd: string}} scope - owning session.
|
|
11905
|
+
* @param {Function} fallback - opens the standalone window when no daemon.
|
|
11906
|
+
* @returns {Promise<'risd'|'window'>} which entry point was used.
|
|
11907
|
+
*/
|
|
11908
|
+
async function openRisdPageSlow(scope, fallback) {
|
|
11909
|
+
var risd = null
|
|
11910
|
+
try {
|
|
11911
|
+
risd = await prefetchRisd(scope)
|
|
11912
|
+
if (risd === null) {
|
|
11913
|
+
// Stopped or crashed: clicking ⧉ is also the "bring it back" gesture, so
|
|
11914
|
+
// ask the host to spawn the daemon on demand instead of silently falling
|
|
11915
|
+
// back to the old standalone window.
|
|
11916
|
+
var response = await fetch(routeUrl('dsh-ris-ide/risd/ensure').href, { method: 'POST' })
|
|
11917
|
+
var body = await response.json().catch(function () { return null })
|
|
11918
|
+
risd = rememberRisdAddress(risdAddressOf(body))
|
|
11919
|
+
}
|
|
11920
|
+
} catch { /* daemonMode=off or host unreachable: fall back to the window */ }
|
|
11921
|
+
if (risd !== null) {
|
|
11922
|
+
openRisdTab(risd, scope.cwd)
|
|
11923
|
+
return 'risd'
|
|
11924
|
+
}
|
|
11925
|
+
if (typeof fallback === 'function') await fallback()
|
|
11926
|
+
return 'window'
|
|
11927
|
+
}
|
|
11928
|
+
|
|
11370
11929
|
/**
|
|
11371
11930
|
* Session-header action: open the IDE in its own window.
|
|
11372
11931
|
*
|
|
11373
11932
|
* Registered in `conversation.session.header.utilities` with order -8, i.e.
|
|
11374
11933
|
* immediately to the RIGHT of DSH's own "open in app" action (-10) and left of
|
|
11375
|
-
* the schedule / log buttons. `sessionId`
|
|
11376
|
-
*
|
|
11934
|
+
* the schedule / log buttons. `sessionId` and `useSessions` arrive as standard
|
|
11935
|
+
* slot props.
|
|
11936
|
+
*
|
|
11937
|
+
* The window follows THIS SESSION's workspace, never the remembered one: after
|
|
11938
|
+
* a session switch `knownWorkspaceCwd()` still names the previous session's
|
|
11939
|
+
* workspace (and its single-instance window name), so the button used to bring
|
|
11940
|
+
* back the previous workspace's IDE. The store the slot hands us has the
|
|
11941
|
+
* current session's `cwd`; the fallback only matters on hosts without it.
|
|
11942
|
+
* @param {{sessionId?: string, useSessions?: Function}} props - standard slot props.
|
|
11377
11943
|
* @returns {object} the button element.
|
|
11378
11944
|
*/
|
|
11379
11945
|
function RisIdeWindowAction(props) {
|
|
11380
11946
|
var sessionId = props !== null && props !== undefined && typeof props.sessionId === 'string' ? props.sessionId : ''
|
|
11947
|
+
var sessionCwd = sessionWorkspaceCwd(props !== null && props !== undefined ? props.useSessions : undefined, sessionId)
|
|
11381
11948
|
var [blocked, setBlocked] = useState(false)
|
|
11949
|
+
var [opening, setOpening] = useState(false)
|
|
11382
11950
|
useEffect(function () {
|
|
11383
11951
|
if (blocked !== true) return undefined
|
|
11384
11952
|
var timer = setTimeout(function () { setBlocked(false) }, 4000)
|
|
11385
11953
|
return function () { clearTimeout(timer) }
|
|
11386
11954
|
}, [blocked])
|
|
11955
|
+
/** Warm the daemon address; `prefetchRisd` is a no-op while the cache is fresh. */
|
|
11956
|
+
function warmRisdAddress() {
|
|
11957
|
+
void prefetchRisd({ sessionId: sessionId, cwd: sessionCwd })
|
|
11958
|
+
}
|
|
11959
|
+
useEffect(function () {
|
|
11960
|
+
// Warm the daemon address before the click; ⧉ then opens without a wait.
|
|
11961
|
+
warmRisdAddress()
|
|
11962
|
+
}, [sessionId, sessionCwd])
|
|
11387
11963
|
if (blocked === true) {
|
|
11388
11964
|
return h('span', { style: S.windowButtonError, role: 'status', title: '允许本站弹窗后重试' }, '窗口被拦截')
|
|
11389
11965
|
}
|
|
11390
11966
|
async function onClick(event) {
|
|
11391
11967
|
if (event !== undefined && typeof event.preventDefault === 'function') event.preventDefault()
|
|
11968
|
+
if (opening === true) return
|
|
11969
|
+
setOpening(true)
|
|
11392
11970
|
try {
|
|
11393
|
-
|
|
11394
|
-
|
|
11971
|
+
await openRisdPage({ sessionId: sessionId, cwd: sessionCwd }, async function () {
|
|
11972
|
+
var handle = await openStandaloneWindow({ sessionId: sessionId, cwd: sessionCwd, windowCwd: sessionCwd })
|
|
11973
|
+
if (handle !== null && handle !== undefined && typeof handle.focus === 'function') handle.focus()
|
|
11974
|
+
})
|
|
11395
11975
|
} catch (error) {
|
|
11396
11976
|
console.warn('dsh-ris-ide: 独立窗口打开失败:' + messageOf(error))
|
|
11397
11977
|
setBlocked(true)
|
|
11978
|
+
} finally {
|
|
11979
|
+
setOpening(false)
|
|
11398
11980
|
}
|
|
11399
11981
|
}
|
|
11400
11982
|
return h('button', {
|
|
11401
11983
|
type: 'button',
|
|
11402
|
-
style: S.windowButton,
|
|
11403
|
-
|
|
11404
|
-
'aria-
|
|
11984
|
+
style: opening === true ? Object.assign({}, S.windowButton, { opacity: 0.62, cursor: 'default' }) : S.windowButton,
|
|
11985
|
+
disabled: opening === true,
|
|
11986
|
+
'aria-busy': opening === true ? 'true' : 'false',
|
|
11987
|
+
title: opening === true ? '正在打开 risd 维护页…' : '打开 risd 维护页(概览 / 代理 / IDE):IDE 内嵌其中,可按工作区切换',
|
|
11988
|
+
'aria-label': opening === true ? '正在打开 risd 维护页' : '打开 risd 维护页(IDE 内嵌,可按工作区切换)',
|
|
11405
11989
|
'data-action': 'ris-ide-window',
|
|
11990
|
+
// Pointer intent is the earliest reliable "about to click" signal: the
|
|
11991
|
+
// address is usually already cached from mount, and this covers a stale
|
|
11992
|
+
// 20 s window without waiting for the click itself.
|
|
11993
|
+
onPointerEnter: warmRisdAddress,
|
|
11994
|
+
onFocus: warmRisdAddress,
|
|
11406
11995
|
onClick: onClick,
|
|
11407
11996
|
},
|
|
11408
|
-
h('span', { style: S.windowButtonIcon, 'aria-hidden': 'true' }, '⧉'),
|
|
11409
|
-
h('span', null, 'RIS-IDE'))
|
|
11997
|
+
h('span', { style: S.windowButtonIcon, 'aria-hidden': 'true' }, opening === true ? '…' : '⧉'),
|
|
11998
|
+
h('span', null, opening === true ? '打开中' : 'RIS-IDE'))
|
|
11410
11999
|
}
|
|
11411
12000
|
|
|
11412
12001
|
/**
|
|
@@ -13091,9 +13680,72 @@ var [ui, setUi] = useState(function () {
|
|
|
13091
13680
|
// call sites pass the whole scope object.
|
|
13092
13681
|
var scope = props ? props.scope : undefined
|
|
13093
13682
|
var sessionId = scope !== undefined && scope !== null ? scope.sessionId : (props ? props.sessionId : undefined)
|
|
13683
|
+
// The tab body outlives Session switches, so its `sessionId` can name the
|
|
13684
|
+
// Session it was opened in. The sidebar's own marker is the live answer.
|
|
13685
|
+
var rootRef = useRef(null)
|
|
13686
|
+
var [liveSessionId, setLiveSessionId] = useState(function () { return liveSidebarSessionId() })
|
|
13687
|
+
useEffect(function () {
|
|
13688
|
+
function sync() {
|
|
13689
|
+
var live = liveSidebarSessionId(rootRef.current)
|
|
13690
|
+
// A collapsed sidebar renders no visible marker: keep the last good
|
|
13691
|
+
// answer instead of falling back to the stale injected session.
|
|
13692
|
+
if (typeof live !== 'string' || live === '') return
|
|
13693
|
+
setLiveSessionId(function (prev) { return prev === live ? prev : live })
|
|
13694
|
+
}
|
|
13695
|
+
sync()
|
|
13696
|
+
var cleanups = []
|
|
13697
|
+
// A Session switch rewrites the sidebar's markers, so attribute mutations
|
|
13698
|
+
// catch it; `hidden` flips catch the retained wrappers being shown.
|
|
13699
|
+
if (typeof MutationObserver === 'function' && typeof document !== 'undefined') {
|
|
13700
|
+
var observer = new MutationObserver(sync)
|
|
13701
|
+
observer.observe(document.documentElement, { subtree: true, attributes: true, attributeFilter: ['data-sidebar-right-session', 'data-sidebar-right-panel', 'hidden'] })
|
|
13702
|
+
cleanups.push(function () { observer.disconnect() })
|
|
13703
|
+
}
|
|
13704
|
+
// Belt and braces: some switches only repaint, and returning to the window
|
|
13705
|
+
// is the moment a stale panel is most visible.
|
|
13706
|
+
if (typeof setInterval === 'function') {
|
|
13707
|
+
var timer = setInterval(sync, 1500)
|
|
13708
|
+
cleanups.push(function () { clearInterval(timer) })
|
|
13709
|
+
}
|
|
13710
|
+
if (typeof window !== 'undefined' && typeof window.addEventListener === 'function') {
|
|
13711
|
+
window.addEventListener('focus', sync)
|
|
13712
|
+
cleanups.push(function () { window.removeEventListener('focus', sync) })
|
|
13713
|
+
if (typeof document !== 'undefined') {
|
|
13714
|
+
document.addEventListener('visibilitychange', sync)
|
|
13715
|
+
cleanups.push(function () { document.removeEventListener('visibilitychange', sync) })
|
|
13716
|
+
}
|
|
13717
|
+
}
|
|
13718
|
+
return function () { for (var i = 0; i < cleanups.length; i += 1) cleanups[i]() }
|
|
13719
|
+
}, [])
|
|
13720
|
+
if (typeof liveSessionId === 'string' && liveSessionId !== '') sessionId = liveSessionId
|
|
13094
13721
|
var cwd = scope !== undefined && scope !== null ? scope.cwd : (props ? props.cwd : undefined)
|
|
13722
|
+
// The tab outlives session switches (`keepMounted`): the remembered workspace
|
|
13723
|
+
// can still name the PREVIOUS session, so the store's value wins when the
|
|
13724
|
+
// slot hands us `useSessions`.
|
|
13725
|
+
var storeCwd = sessionWorkspaceCwd(props ? props.useSessions : undefined, sessionId)
|
|
13726
|
+
if (typeof storeCwd === 'string' && storeCwd !== '') cwd = storeCwd
|
|
13095
13727
|
// A stale session id must not blank the panel: the host still accepts a cwd.
|
|
13096
13728
|
if (typeof cwd !== 'string' || cwd === '') cwd = knownWorkspaceCwd()
|
|
13729
|
+
// Selections and the followed log belong to the workspace they were made in,
|
|
13730
|
+
// so a Session switch drops them instead of showing another project's log.
|
|
13731
|
+
var sessionIdentity = typeof sessionId === 'string' ? sessionId : ''
|
|
13732
|
+
useEffect(function () {
|
|
13733
|
+
setCompactPick(undefined)
|
|
13734
|
+
setActive(undefined)
|
|
13735
|
+
}, [sessionIdentity])
|
|
13736
|
+
/** Warm the compact ⧉'s address; a fresh cache makes the click synchronous. */
|
|
13737
|
+
function warmCompactRisd() {
|
|
13738
|
+
if (typeof sessionId !== 'string' || sessionId === '') return
|
|
13739
|
+
void prefetchRisd({ sessionId: sessionId, cwd: cwd })
|
|
13740
|
+
}
|
|
13741
|
+
useEffect(function () {
|
|
13742
|
+
// The compact ⧉ shares the header button's warm cache: prefetch while the
|
|
13743
|
+
// user is reading the panel, so the click only has to open the tab. The
|
|
13744
|
+
// host view needs a session id, so a tab whose session is not known yet
|
|
13745
|
+
// waits for the live one instead of earning a 400.
|
|
13746
|
+
warmCompactRisd()
|
|
13747
|
+
return undefined
|
|
13748
|
+
}, [sessionIdentity])
|
|
13097
13749
|
// COMPACT mode is the sidebar panel: console rows on top, ONE program's
|
|
13098
13750
|
// live log below. The full IDE (tree/editor/debug) lives only in the
|
|
13099
13751
|
// standalone window, so the sidebar stays cheap and readable.
|
|
@@ -13142,6 +13794,8 @@ var [ui, setUi] = useState(function () {
|
|
|
13142
13794
|
}, [state.note])
|
|
13143
13795
|
|
|
13144
13796
|
var [busyId, setBusyId] = useState(undefined)
|
|
13797
|
+
/** The compact ⧉ is opening the page: disable it and show progress. */
|
|
13798
|
+
var [openingIde, setOpeningIde] = useState(false)
|
|
13145
13799
|
/** Which action `busyId` is running, for the row mask's wording. */
|
|
13146
13800
|
var [busyKind, setBusyKind] = useState('')
|
|
13147
13801
|
var busyRef = useRef(false)
|
|
@@ -13390,7 +14044,7 @@ var [ui, setUi] = useState(function () {
|
|
|
13390
14044
|
if (sidebar !== undefined && sidebar !== null && typeof sidebar.openResource === 'function') {
|
|
13391
14045
|
try {
|
|
13392
14046
|
sidebar.openResource(officialPreviewAddress({ sessionId: sessionId, cwd: cwd }, path))
|
|
13393
|
-
setState(function (prev) { return Object.assign({}, prev, { note: '已在右侧栏打开 ' +
|
|
14047
|
+
setState(function (prev) { return Object.assign({}, prev, { note: '已在右侧栏打开 ' + fileBaseName(path) + '(改完保存即生效)' }) })
|
|
13394
14048
|
} catch (error) {
|
|
13395
14049
|
setState(function (prev) { return Object.assign({}, prev, { note: '打开配置失败:' + messageOf(error) }) })
|
|
13396
14050
|
}
|
|
@@ -13508,16 +14162,22 @@ var [ui, setUi] = useState(function () {
|
|
|
13508
14162
|
|
|
13509
14163
|
/** Open the standalone window on the picked program (or on the workspace). */
|
|
13510
14164
|
function openCompactWindow() {
|
|
14165
|
+
if (openingIde === true) return
|
|
13511
14166
|
var picked = compactProgram()
|
|
14167
|
+
setOpeningIde(true)
|
|
13512
14168
|
void (async function () {
|
|
13513
14169
|
try {
|
|
13514
|
-
//
|
|
13515
|
-
//
|
|
13516
|
-
|
|
13517
|
-
|
|
13518
|
-
|
|
14170
|
+
// Prefer the risd maintenance page (one tab, all workspaces). Without a
|
|
14171
|
+
// daemon, keep the one-window-per-workspace behaviour.
|
|
14172
|
+
await openRisdPage({ sessionId: sessionId, cwd: cwd }, async function () {
|
|
14173
|
+
var handle = await openStandaloneWindow({ sessionId: sessionId, cwd: cwd, programId: picked !== undefined ? picked.id : undefined })
|
|
14174
|
+
if (handle !== null && handle !== undefined && typeof handle.focus === 'function') handle.focus()
|
|
14175
|
+
else setState(function (prev) { return Object.assign({}, prev, { note: '已切到本工作空间的 IDE 窗口' }) })
|
|
14176
|
+
})
|
|
13519
14177
|
} catch (error) {
|
|
13520
14178
|
setState(function (prev) { return Object.assign({}, prev, { note: '打开 IDE 窗口失败:' + messageOf(error) }) })
|
|
14179
|
+
} finally {
|
|
14180
|
+
setOpeningIde(false)
|
|
13521
14181
|
}
|
|
13522
14182
|
})()
|
|
13523
14183
|
}
|
|
@@ -13682,7 +14342,7 @@ var [ui, setUi] = useState(function () {
|
|
|
13682
14342
|
onClick: function () { toggleCompactMax(section) },
|
|
13683
14343
|
}, isMaxed ? '⤡' : '⤢')
|
|
13684
14344
|
}
|
|
13685
|
-
return h('div', { style: S.root, 'data-panel': 'compact' },
|
|
14345
|
+
return h('div', { ref: rootRef, style: S.root, 'data-panel': 'compact' },
|
|
13686
14346
|
h('style', { key: 'compact-loading-css' }, PROGRAM_LOADING_CSS),
|
|
13687
14347
|
h('div', { style: S.bar, 'data-compact-bar': '1' },
|
|
13688
14348
|
h('span', { style: S.status }, state.loading ? '扫描中…' : (state.programs.length + ' 个项目')),
|
|
@@ -13707,10 +14367,23 @@ var [ui, setUi] = useState(function () {
|
|
|
13707
14367
|
onClick: function () { generateConfigFile(configExists ? 'update' : undefined) },
|
|
13708
14368
|
}, busyId === '__config__' ? '…' : '⚙'),
|
|
13709
14369
|
h('button', {
|
|
13710
|
-
type: 'button',
|
|
13711
|
-
|
|
14370
|
+
type: 'button',
|
|
14371
|
+
style: openingIde === true ? Object.assign({}, S.paneButton, { opacity: 0.62, cursor: 'default' }) : S.paneButton,
|
|
14372
|
+
disabled: openingIde === true,
|
|
14373
|
+
'aria-busy': openingIde === true ? 'true' : 'false',
|
|
14374
|
+
'data-action': 'ide-window',
|
|
14375
|
+
title: openingIde === true
|
|
14376
|
+
? '正在打开 risd 维护页…'
|
|
14377
|
+
: '打开 risd 维护页(IDE 内嵌,可按工作区切换)' + (picked !== undefined ? ':' + picked.name : ''),
|
|
14378
|
+
// Icon only: the console title bar is tight, and the ⧉ is already the
|
|
14379
|
+
// IDE's mark everywhere else in the panel (aria-label keeps the text).
|
|
14380
|
+
'aria-label': openingIde === true
|
|
14381
|
+
? '正在打开 risd 维护页'
|
|
14382
|
+
: '打开 risd 维护页(IDE 内嵌)' + (picked !== undefined ? ':' + picked.name : ''),
|
|
14383
|
+
onPointerEnter: warmCompactRisd,
|
|
14384
|
+
onFocus: warmCompactRisd,
|
|
13712
14385
|
onClick: openCompactWindow,
|
|
13713
|
-
}, '
|
|
14386
|
+
}, openingIde === true ? '…' : '⧉'),
|
|
13714
14387
|
h('button', {
|
|
13715
14388
|
type: 'button', style: state.loading ? S.paneIconOff : S.paneIcon,
|
|
13716
14389
|
disabled: state.loading, 'data-action': 'compact-rescan',
|
|
@@ -14025,6 +14698,8 @@ var [ui, setUi] = useState(function () {
|
|
|
14025
14698
|
// The standalone window: the header button, the popup helper and the
|
|
14026
14699
|
// mount entry the window's own page calls (none of them needs DSH's ctx).
|
|
14027
14700
|
RisIdeWindowAction: RisIdeWindowAction,
|
|
14701
|
+
/** The header button's cwd source: the session store, never the remembered one. */
|
|
14702
|
+
sessionWorkspaceCwd: sessionWorkspaceCwd,
|
|
14028
14703
|
openStandaloneWindow: openStandaloneWindow,
|
|
14029
14704
|
mountStandalone: mountStandalone,
|
|
14030
14705
|
StandaloneWindow: StandaloneWindow,
|
|
@@ -14035,11 +14710,21 @@ var [ui, setUi] = useState(function () {
|
|
|
14035
14710
|
standaloneWindowName: standaloneWindowName,
|
|
14036
14711
|
STANDALONE_SESSION: STANDALONE_SESSION,
|
|
14037
14712
|
openInstanceLog: openInstanceLog,
|
|
14713
|
+
// The risd page opener: the prefetch cache, the address picker and the
|
|
14714
|
+
// open-at-most-once guard are what keep ⧉ from waiting (and from opening
|
|
14715
|
+
// two tabs); the tests drive them against a fake fetch/window.
|
|
14716
|
+
openRisdPage: openRisdPage,
|
|
14717
|
+
prefetchRisd: prefetchRisd,
|
|
14718
|
+
risdCachedAddress: risdCachedAddress,
|
|
14719
|
+
risdAddressOf: risdAddressOf,
|
|
14720
|
+
resetRisdPrefetch: resetRisdPrefetch,
|
|
14721
|
+
RISD_PREFETCH_TTL_MS: RISD_PREFETCH_TTL_MS,
|
|
14038
14722
|
requestStart: requestStart,
|
|
14039
14723
|
generateConfig: generateConfig,
|
|
14040
14724
|
drainOpenRequests: drainOpenRequests,
|
|
14041
14725
|
ProgramWorkbench: ProgramWorkbench,
|
|
14042
14726
|
ProgramsPanel: ProgramsPanel,
|
|
14727
|
+
// Proxy dialog (address + rule table), rendered from both console shapes.
|
|
14043
14728
|
IdeErrorBoundary: IdeErrorBoundary,
|
|
14044
14729
|
PROGRAM_TAB_ID: PROGRAM_TAB_ID,
|
|
14045
14730
|
// The compact sidebar shape: its default log-pane height (240px) and the
|