@linxin666/dsh-client-ui-task-board 0.4.13 → 0.4.14
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.i18n.yaml +2 -2
- package/README.md +2 -2
- package/README.zh.md +2 -2
- package/lib/client.js +242 -12
- package/lib/client.js.map +1 -1
- package/lib/index.js +36 -11
- package/lib/types/client/board/source-group.d.ts +27 -0
- package/lib/types/client/locales.d.ts +1 -0
- package/lib/types/client/pending-verify.d.ts +47 -0
- package/lib/types/client/service.d.ts +4 -1
- package/lib/types/core/controller.d.ts +7 -1
- package/lib/types/core/extension.d.ts +14 -0
- package/lib/types/host-routes.d.ts +6 -0
- package/package.json +1 -1
- package/src/client/board/TaskBoard.tsx +47 -10
- package/src/client/board/source-group.ts +94 -0
- package/src/client/board.module.css +17 -0
- package/src/client/host-api.ts +7 -0
- package/src/client/index.ts +11 -0
- package/src/client/locales.ts +2 -0
- package/src/client/pending-verify.ts +90 -0
- package/src/client/service.ts +24 -0
- package/src/core/controller.ts +18 -0
- package/src/core/extension.ts +16 -0
- package/src/host-routes.ts +46 -11
package/src/client/service.ts
CHANGED
|
@@ -14,16 +14,25 @@ import type {
|
|
|
14
14
|
TaskBoardClientFace,
|
|
15
15
|
TaskBoardClientMirror,
|
|
16
16
|
TaskBoardExtensionActionRequest,
|
|
17
|
+
TaskBoardGroupingSelector,
|
|
17
18
|
TaskBoardVisibilityPredicate,
|
|
18
19
|
} from '../core/extension.ts'
|
|
19
20
|
import type { TaskRecord } from '../core/tasks.ts'
|
|
20
21
|
|
|
22
|
+
interface PendingGroupingRegistration {
|
|
23
|
+
selector: TaskBoardGroupingSelector
|
|
24
|
+
active: boolean
|
|
25
|
+
dispose?: () => void
|
|
26
|
+
}
|
|
27
|
+
|
|
21
28
|
export class TaskBoardClientService implements TaskBoardClientFace {
|
|
22
29
|
private controller: BoardController | undefined
|
|
23
30
|
private enabled = false
|
|
24
31
|
private unsubscribeController: (() => void) | undefined
|
|
25
32
|
/** Predicates registered before the controller exists, replayed on attach. */
|
|
26
33
|
private readonly pendingVisibility: TaskBoardVisibilityPredicate[] = []
|
|
34
|
+
/** Source selectors registered before the controller exists, replayed on attach. */
|
|
35
|
+
private readonly pendingGrouping: PendingGroupingRegistration[] = []
|
|
27
36
|
private readonly listeners = new Set<(mirror: TaskBoardClientMirror) => void>()
|
|
28
37
|
|
|
29
38
|
/** Bind the live board controller (called when the UI mounts). */
|
|
@@ -33,6 +42,9 @@ export class TaskBoardClientService implements TaskBoardClientFace {
|
|
|
33
42
|
this.controller = controller
|
|
34
43
|
this.unsubscribeController = controller.subscribe(() => { this.notify() })
|
|
35
44
|
for (const predicate of this.pendingVisibility.splice(0)) controller.registerVisibility(predicate)
|
|
45
|
+
for (const registration of this.pendingGrouping.splice(0)) {
|
|
46
|
+
if (registration.active) registration.dispose = controller.registerGrouping(registration.selector)
|
|
47
|
+
}
|
|
36
48
|
this.notify()
|
|
37
49
|
}
|
|
38
50
|
|
|
@@ -66,6 +78,18 @@ export class TaskBoardClientService implements TaskBoardClientFace {
|
|
|
66
78
|
}
|
|
67
79
|
}
|
|
68
80
|
|
|
81
|
+
registerGrouping(selector: TaskBoardGroupingSelector): () => void {
|
|
82
|
+
if (this.controller !== undefined) return this.controller.registerGrouping(selector)
|
|
83
|
+
const registration: PendingGroupingRegistration = { selector, active: true }
|
|
84
|
+
this.pendingGrouping.push(registration)
|
|
85
|
+
return () => {
|
|
86
|
+
registration.active = false
|
|
87
|
+
registration.dispose?.()
|
|
88
|
+
const index = this.pendingGrouping.indexOf(registration)
|
|
89
|
+
if (index !== -1) this.pendingGrouping.splice(index, 1)
|
|
90
|
+
}
|
|
91
|
+
}
|
|
92
|
+
|
|
69
93
|
subscribe(callback: (mirror: TaskBoardClientMirror) => void): () => void {
|
|
70
94
|
this.listeners.add(callback)
|
|
71
95
|
return () => { this.listeners.delete(callback) }
|
package/src/core/controller.ts
CHANGED
|
@@ -32,6 +32,7 @@ import type {
|
|
|
32
32
|
} from '../protocol.ts'
|
|
33
33
|
import type {
|
|
34
34
|
TaskBoardExtensionActionRequest,
|
|
35
|
+
TaskBoardGroupingSelector,
|
|
35
36
|
TaskBoardVisibilityPredicate,
|
|
36
37
|
} from './extension.ts'
|
|
37
38
|
|
|
@@ -184,6 +185,8 @@ export interface ControllerSnapshot {
|
|
|
184
185
|
* hand-built snapshot (tests, a shell-less composition) defaults to visible.
|
|
185
186
|
*/
|
|
186
187
|
visibility?: readonly TaskBoardVisibilityPredicate[]
|
|
188
|
+
/** Provider source-group selectors, in registration order; browser-only functions. */
|
|
189
|
+
grouping?: readonly TaskBoardGroupingSelector[]
|
|
187
190
|
/** Read-only summaries published by running extensions, keyed by extension id. */
|
|
188
191
|
extensions?: Readonly<Record<string, unknown>>
|
|
189
192
|
}
|
|
@@ -235,6 +238,8 @@ export class BoardController {
|
|
|
235
238
|
private hostState: HostMirror | undefined
|
|
236
239
|
/** Provider visibility predicates (immutable array; replaced on change). */
|
|
237
240
|
private visibility: readonly TaskBoardVisibilityPredicate[] = []
|
|
241
|
+
/** Provider source-group selectors (immutable array; replaced on change). */
|
|
242
|
+
private grouping: readonly TaskBoardGroupingSelector[] = []
|
|
238
243
|
private remoteSubscribed = false
|
|
239
244
|
private remoteInitialization: Promise<boolean> | undefined
|
|
240
245
|
|
|
@@ -286,6 +291,7 @@ export class BoardController {
|
|
|
286
291
|
...(this.transportError === undefined ? {} : { transportError: this.transportError }),
|
|
287
292
|
...(this.hostState === undefined ? {} : { host: this.hostState }),
|
|
288
293
|
visibility: this.visibility,
|
|
294
|
+
grouping: this.grouping,
|
|
289
295
|
...(this.hostState?.extensions === undefined ? {} : { extensions: this.hostState.extensions }),
|
|
290
296
|
}
|
|
291
297
|
}
|
|
@@ -305,6 +311,18 @@ export class BoardController {
|
|
|
305
311
|
}
|
|
306
312
|
}
|
|
307
313
|
|
|
314
|
+
/** Register one source-group selector; registration order breaks ownership ties. */
|
|
315
|
+
registerGrouping(selector: TaskBoardGroupingSelector): () => void {
|
|
316
|
+
this.grouping = [...this.grouping, selector]
|
|
317
|
+
this.notify()
|
|
318
|
+
return () => {
|
|
319
|
+
const next = this.grouping.filter(candidate => candidate !== selector)
|
|
320
|
+
if (next.length === this.grouping.length) return
|
|
321
|
+
this.grouping = next
|
|
322
|
+
this.notify()
|
|
323
|
+
}
|
|
324
|
+
}
|
|
325
|
+
|
|
308
326
|
/**
|
|
309
327
|
* Deliver one provider action through the board's same-origin channel. A
|
|
310
328
|
* board without a Host transport (the legacy in-memory path) refuses it.
|
package/src/core/extension.ts
CHANGED
|
@@ -364,6 +364,17 @@ export interface TaskBoardClientMirror {
|
|
|
364
364
|
/** Whether a task should be shown on the board; false hides it. */
|
|
365
365
|
export type TaskBoardVisibilityPredicate = (task: TaskRecord) => boolean
|
|
366
366
|
|
|
367
|
+
/** Generic source bucket a provider assigns to one card. */
|
|
368
|
+
export interface TaskBoardSourceGroup {
|
|
369
|
+
/** Stable, provider-namespaced identity used for ordering and fold persistence. */
|
|
370
|
+
id: string
|
|
371
|
+
/** Full human-readable source label, such as an owner/repository pair. */
|
|
372
|
+
label: string
|
|
373
|
+
}
|
|
374
|
+
|
|
375
|
+
/** Return a card's source group, or undefined when this provider does not own it. */
|
|
376
|
+
export type TaskBoardGroupingSelector = (task: TaskRecord) => TaskBoardSourceGroup | undefined
|
|
377
|
+
|
|
367
378
|
/**
|
|
368
379
|
* Client capability face the board's browser half provides. A provider's
|
|
369
380
|
* browser half resolves it from the shared cordis service name; it never
|
|
@@ -374,6 +385,11 @@ export interface TaskBoardClientFace {
|
|
|
374
385
|
dispatch(request: TaskBoardExtensionActionRequest): Promise<boolean>
|
|
375
386
|
/** Register one card visibility predicate; the returned disposer removes it. */
|
|
376
387
|
registerVisibility(predicate: TaskBoardVisibilityPredicate): () => void
|
|
388
|
+
/**
|
|
389
|
+
* Register one source-group selector; the first selector returning a group
|
|
390
|
+
* wins. Optional so an older board can serve the same API version.
|
|
391
|
+
*/
|
|
392
|
+
registerGrouping?(selector: TaskBoardGroupingSelector): () => void
|
|
377
393
|
/** Subscribe to the board mirror. */
|
|
378
394
|
subscribe(callback: (mirror: TaskBoardClientMirror) => void): () => void
|
|
379
395
|
/** Read the current board mirror. */
|
package/src/host-routes.ts
CHANGED
|
@@ -27,7 +27,12 @@ import {
|
|
|
27
27
|
|
|
28
28
|
const ACTION_LIMIT = 64 * 1024
|
|
29
29
|
const IMPORT_LIMIT = 2 * 1024 * 1024
|
|
30
|
-
|
|
30
|
+
/**
|
|
31
|
+
* Comment-frame cadence on the event stream. It keeps the connection alive
|
|
32
|
+
* through intermediaries that would close an idle one; it is not a frame the
|
|
33
|
+
* browser reports to the panel (an SSE comment is invisible to EventSource).
|
|
34
|
+
*/
|
|
35
|
+
export const HEARTBEAT_MS = 15_000
|
|
31
36
|
|
|
32
37
|
/** Header replaced by an authenticated same-host reverse proxy. */
|
|
33
38
|
export const TASK_BOARD_PROXY_TOKEN_HEADER = 'x-dsh-task-board-proxy-token'
|
|
@@ -334,18 +339,48 @@ export function makeTaskBoardRoutes(
|
|
|
334
339
|
'cache-control': 'no-cache',
|
|
335
340
|
connection: 'keep-alive',
|
|
336
341
|
})
|
|
337
|
-
|
|
338
|
-
|
|
339
|
-
|
|
342
|
+
// The stream is the board's only live signal, so it also has to be able to
|
|
343
|
+
// STOP being one. A connection can stop accepting bytes while neither end
|
|
344
|
+
// has closed it (a half-open socket, an intermediary that stopped
|
|
345
|
+
// reading); from then on every frame is written into nothing, the browser's
|
|
346
|
+
// EventSource sees an open stream that never speaks, and the panel keeps
|
|
347
|
+
// the snapshot it last applied with no error to react to. A failed write is
|
|
348
|
+
// the one report of that state, so it ends the connection here: the browser
|
|
349
|
+
// then reports the closed stream, and a closed stream makes the panel read
|
|
350
|
+
// the state again.
|
|
351
|
+
let heartbeat: ReturnType<typeof setInterval> | undefined
|
|
352
|
+
let release: (() => void) | undefined
|
|
353
|
+
const stop = (): void => {
|
|
354
|
+
if (heartbeat !== undefined) {
|
|
355
|
+
clearInterval(heartbeat)
|
|
356
|
+
heartbeat = undefined
|
|
357
|
+
}
|
|
358
|
+
const unsubscribe = release
|
|
359
|
+
release = undefined
|
|
360
|
+
unsubscribe?.()
|
|
340
361
|
}
|
|
341
|
-
const
|
|
342
|
-
|
|
343
|
-
|
|
344
|
-
|
|
345
|
-
|
|
362
|
+
const drop = (): void => {
|
|
363
|
+
if (release === undefined) return
|
|
364
|
+
stop()
|
|
365
|
+
res.destroy()
|
|
366
|
+
}
|
|
367
|
+
const write = (chunk: string): void => {
|
|
368
|
+
if (release === undefined || res.writableEnded || res.destroyed) return
|
|
369
|
+
// The callback is the only place Node reports a write that never landed;
|
|
370
|
+
// its result (backpressure) is not an error and is ignored.
|
|
371
|
+
res.write(chunk, (error) => { if (error !== null && error !== undefined) drop() })
|
|
372
|
+
}
|
|
373
|
+
const push = (): void => {
|
|
374
|
+
write(`data: ${JSON.stringify(service.eventPayload())}\n\n`)
|
|
346
375
|
}
|
|
347
|
-
|
|
348
|
-
|
|
376
|
+
release = service.subscribe(push)
|
|
377
|
+
heartbeat = setInterval(() => { write(': ping\n\n') }, HEARTBEAT_MS)
|
|
378
|
+
req.once('close', stop)
|
|
379
|
+
res.once('close', stop)
|
|
380
|
+
// A reset socket reports the same fact as a failed write. Without this
|
|
381
|
+
// listener Node treats a response error as unhandled, so the connection is
|
|
382
|
+
// released here instead of being left behind.
|
|
383
|
+
res.on('error', () => { drop() })
|
|
349
384
|
push()
|
|
350
385
|
},
|
|
351
386
|
}
|