@linxin666/dsh-client-ui-task-board 0.4.1 → 0.4.3
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 +28 -3
- package/README.zh.md +28 -3
- package/lib/client.js +1142 -467
- package/lib/client.js.map +1 -1
- package/lib/index.js +2066 -1475
- package/lib/types/client/TaskBoardSettingsCard.d.ts +4 -0
- package/lib/types/client/board/LinkSubtaskModal.d.ts +11 -0
- package/lib/types/client/board/NewTaskModal.d.ts +7 -1
- package/lib/types/client/board/TaskCard.d.ts +11 -1
- package/lib/types/client/index.d.ts +15 -1
- package/lib/types/client/locales.d.ts +33 -0
- package/lib/types/client/native-panel.d.ts +62 -0
- package/lib/types/client/settings-entry-form.d.ts +49 -0
- package/lib/types/core/controller.d.ts +71 -3
- package/lib/types/core/subtask.d.ts +122 -0
- package/lib/types/core/tasks.d.ts +46 -3
- package/lib/types/core/use-cases/task-archive.d.ts +10 -13
- package/lib/types/core/use-cases/task-create.d.ts +13 -4
- package/lib/types/core/use-cases/task-delete.d.ts +7 -1
- package/lib/types/core/use-cases/task-parent.d.ts +21 -0
- package/lib/types/core/use-cases/task-update.d.ts +1 -1
- package/lib/types/host/agent-tools.d.ts +27 -0
- package/lib/types/host-ledger.d.ts +97 -4
- package/lib/types/host-runner.d.ts +39 -1
- package/lib/types/host-service.d.ts +98 -5
- package/lib/types/index.d.ts +93 -5
- package/lib/types/mount-once.d.ts +38 -7
- package/lib/types/protocol.d.ts +14 -0
- package/package.json +26 -21
- package/src/client/TaskBoardSettingsCard.tsx +48 -3
- package/src/client/board/LinkSubtaskModal.tsx +82 -0
- package/src/client/board/NewTaskModal.tsx +40 -6
- package/src/client/board/TaskBoard.tsx +88 -8
- package/src/client/board/TaskCard.tsx +52 -2
- package/src/client/board/TaskDetail.tsx +124 -1
- package/src/client/board.module.css +112 -131
- package/src/client/host-api.ts +14 -4
- package/src/client/index.ts +56 -18
- package/src/client/locales.ts +70 -2
- package/src/client/native-panel.tsx +124 -0
- package/src/client/settings-entry-form.ts +142 -0
- package/src/core/controller.ts +128 -10
- package/src/core/store.ts +15 -0
- package/src/core/subtask.ts +286 -0
- package/src/core/tasks.ts +50 -2
- package/src/core/use-cases/task-archive.ts +46 -12
- package/src/core/use-cases/task-create.ts +42 -7
- package/src/core/use-cases/task-delete.ts +11 -1
- package/src/core/use-cases/task-parent.ts +64 -0
- package/src/core/use-cases/task-update.ts +3 -1
- package/src/host/agent-tools.ts +643 -0
- package/src/host-ledger.ts +343 -45
- package/src/host-routes.ts +37 -1
- package/src/host-runner.ts +141 -12
- package/src/host-service.ts +265 -32
- package/src/index.ts +203 -9
- package/src/mount-once.ts +107 -13
- package/src/protocol.ts +26 -2
- package/lib/types/client/board-mount.d.ts +0 -23
- package/lib/types/client/body-mutations.d.ts +0 -45
- package/lib/types/client/panel-mount-core.d.ts +0 -56
- package/lib/types/client/sidebar-entry-core.d.ts +0 -55
- package/lib/types/client/sidebar-entry.d.ts +0 -29
- package/src/client/board-mount.tsx +0 -43
- package/src/client/body-mutations.ts +0 -133
- package/src/client/panel-mount-core.ts +0 -155
- package/src/client/sidebar-entry-core.ts +0 -237
- package/src/client/sidebar-entry.ts +0 -53
|
@@ -1,56 +0,0 @@
|
|
|
1
|
-
/**
|
|
2
|
-
* Center-column panel takeover lifecycle.
|
|
3
|
-
*
|
|
4
|
-
* The `conversation` slot is single-occupant (ui-conversation) and external
|
|
5
|
-
* plugins cannot declare slots, so a family panel takes over the center
|
|
6
|
-
* column at the DOM level: a container is appended inside the center column
|
|
7
|
-
* (`[class*="centerCol"]`, the 0.1.0-rc.6+ AppFrame layout; previously
|
|
8
|
-
* `[data-pane="conversation"]` on older shells — the mount selector keeps
|
|
9
|
-
* both, ssh #243 / task-board #107) as an extra trailing child React never
|
|
10
|
-
* manages, and a stylesheet rule hides the conversation content while the
|
|
11
|
-
* panel is active. Toggling is a data attribute on <html> — no React
|
|
12
|
-
* involvement, so the conversation subtree underneath stays mounted and
|
|
13
|
-
* stateful.
|
|
14
|
-
*
|
|
15
|
-
* Consuming plugins keep a thin wrapper that supplies the panel tree,
|
|
16
|
-
* container attribute names, and stylesheet class; those names are pinned by
|
|
17
|
-
* each package's CSS, skins, and the semantic-attributes contract. The
|
|
18
|
-
* sidebar row toggling the panel shares its core the same way
|
|
19
|
-
* (shared/client/sidebar-entry-core.ts, synced copy).
|
|
20
|
-
*/
|
|
21
|
-
import { type Root } from 'react-dom/client';
|
|
22
|
-
/** Options for mountCenterPanel; dsh-ssh mount.tsx and dsh-task-board board-mount.tsx are the canonical consumers. */
|
|
23
|
-
export interface CenterPanelMountOptions {
|
|
24
|
-
/** Render the panel tree (first open, remount while open, locale refresh). */
|
|
25
|
-
render: (root: Root) => void;
|
|
26
|
-
/** dataset key of the injected container's view attribute, e.g. `dshSshView` for `data-dsh-ssh-view`. */
|
|
27
|
-
viewDatasetKey: string;
|
|
28
|
-
/** value of the container's L2 `data-dsh-plugin` semantic attribute. */
|
|
29
|
-
pluginName: string;
|
|
30
|
-
/** stylesheet class applied to the injected container. */
|
|
31
|
-
viewClassName: string;
|
|
32
|
-
/** <html> attribute set while this panel is active. */
|
|
33
|
-
activeAttribute: string;
|
|
34
|
-
/** the sibling panel's active attribute, removed from <html> when this panel opens. */
|
|
35
|
-
siblingActiveAttribute: string;
|
|
36
|
-
/** detail value this panel broadcasts on the cross-plugin activation event. */
|
|
37
|
-
panelName: string;
|
|
38
|
-
/** sibling detail value whose activation closes this panel. */
|
|
39
|
-
siblingPanelName: string;
|
|
40
|
-
/** open flag of the owning controller. */
|
|
41
|
-
isOpen: () => boolean;
|
|
42
|
-
/** close the panel, handing the center column back to the conversation. */
|
|
43
|
-
close: () => void;
|
|
44
|
-
/** subscribe to the owning controller's open-state changes; returns an unsubscriber. */
|
|
45
|
-
subscribe: (listener: () => void) => () => void;
|
|
46
|
-
/** locale-change source; when given, re-renders an open panel on a Language switch. */
|
|
47
|
-
locale?: {
|
|
48
|
-
subscribe(listener: () => void): () => void;
|
|
49
|
-
};
|
|
50
|
-
}
|
|
51
|
-
/**
|
|
52
|
-
* Mount a family panel into the center column and bind its visibility to the
|
|
53
|
-
* owning controller's open state.
|
|
54
|
-
* @returns disposer unmounting the tree and restoring the column.
|
|
55
|
-
*/
|
|
56
|
-
export declare function mountCenterPanel(options: CenterPanelMountOptions): () => void;
|
|
@@ -1,55 +0,0 @@
|
|
|
1
|
-
/** Per-package configuration for one sidebar entry row. */
|
|
2
|
-
export interface SidebarEntryOptions {
|
|
3
|
-
/** Full attribute name identifying the injected row (idempotency key), e.g. 'data-dsh-ssh-entry'. */
|
|
4
|
-
rowAttribute: string;
|
|
5
|
-
/** CSS selector matching the injected row, e.g. '[data-dsh-ssh-entry]'. */
|
|
6
|
-
rowSelector: string;
|
|
7
|
-
/**
|
|
8
|
-
* L2 semantic-attribute plugin id (issue #506, enum table:
|
|
9
|
-
* skins/skin-center/contracts/semantic-attrs-v1.md). When set, the row also
|
|
10
|
-
* outputs data-dsh-plugin="<id>" and data-dsh-part="sidebar-entry"; unset
|
|
11
|
-
* leaves the row without semantic attributes.
|
|
12
|
-
*/
|
|
13
|
-
plugin?: string;
|
|
14
|
-
/** Inline icon markup (matches the shell's 16px nav-icon look). */
|
|
15
|
-
icon: string;
|
|
16
|
-
/** CSS module class names for the row and its two spans (entry / entryIcon / entryLabel). */
|
|
17
|
-
css: Record<string, string>;
|
|
18
|
-
/** Localized row label (aria-label + visible text). */
|
|
19
|
-
label(): string;
|
|
20
|
-
/** Optional localized tooltip (title attribute). */
|
|
21
|
-
tooltip?(): string;
|
|
22
|
-
/**
|
|
23
|
-
* Optional locale-change subscription: re-applies label / aria-label /
|
|
24
|
-
* tooltip whenever the active locale changes. Plain-DOM rows would
|
|
25
|
-
* otherwise keep the label captured at mount; pass the SDK locale runtime
|
|
26
|
-
* subscription (ctx.locale.subscribe) so the row follows the language
|
|
27
|
-
* switch without a reload.
|
|
28
|
-
*/
|
|
29
|
-
refresh?: {
|
|
30
|
-
subscribe(listener: () => void): () => void;
|
|
31
|
-
};
|
|
32
|
-
/** Click action (open/toggle the owning panel). */
|
|
33
|
-
onToggle(): void;
|
|
34
|
-
/** Family-block position: 'before' inserts ahead of sibling plugin rows, 'after' behind them. */
|
|
35
|
-
position: 'before' | 'after';
|
|
36
|
-
/**
|
|
37
|
-
* Selectors of the sibling plugin entry rows this package orders against
|
|
38
|
-
* (its own row included — the placement guard excludes a row that is
|
|
39
|
-
* already inside the root). Each package passes the same list it used
|
|
40
|
-
* before the consolidation so the rendered order stays stable.
|
|
41
|
-
*/
|
|
42
|
-
familySelectors: readonly string[];
|
|
43
|
-
/** Optional active-state bridge; highlights the row while the panel is open. */
|
|
44
|
-
active?: {
|
|
45
|
-
subscribe(listener: () => void): () => void;
|
|
46
|
-
isOpen(): boolean;
|
|
47
|
-
};
|
|
48
|
-
}
|
|
49
|
-
/**
|
|
50
|
-
* Mount the sidebar entry, waiting for the shell to render and self-healing
|
|
51
|
-
* on later React re-renders.
|
|
52
|
-
* @param options - the row's attribute/icon/copy/action/ordering configuration.
|
|
53
|
-
* @returns disposer removing the entry and its observers.
|
|
54
|
-
*/
|
|
55
|
-
export declare function mountSidebarEntry(options: SidebarEntryOptions): () => void;
|
|
@@ -1,29 +0,0 @@
|
|
|
1
|
-
/**
|
|
2
|
-
* Sidebar entry injection — package-specific wiring over the shared core.
|
|
3
|
-
*
|
|
4
|
-
* dsh's sidebar shell exposes no slot an external plugin can register into
|
|
5
|
-
* (`sidebar.workspaces` / `sidebar.settings` are single-occupant and already
|
|
6
|
-
* taken), so the entry row is injected between the shell's New Session button
|
|
7
|
-
* and the workspace browser. The DOM injection / self-healing / idempotency
|
|
8
|
-
* logic lives exactly once in shared/client/sidebar-entry-core.ts (synced
|
|
9
|
-
* copy); this wrapper supplies the task-board icon, copy, CSS module, and the
|
|
10
|
-
* board toggle. The row is plain DOM (no React tree); the board view it
|
|
11
|
-
* toggles is a separate React root mounted in the center column
|
|
12
|
-
* (see board-mount.ts).
|
|
13
|
-
*/
|
|
14
|
-
import type { BoardController } from '../core/controller.ts';
|
|
15
|
-
/** Stable data attribute identifying the injected entry row. */
|
|
16
|
-
export declare const ENTRY_SELECTOR = "[data-dsh-taskboard-entry]";
|
|
17
|
-
/** Locale-change subscription the shared core asks for (ctx.locale.subscribe shape). */
|
|
18
|
-
export interface LocaleRefreshSource {
|
|
19
|
-
subscribe(listener: () => void): () => void;
|
|
20
|
-
}
|
|
21
|
-
/**
|
|
22
|
-
* Mount the sidebar entry, waiting for the shell to render and self-healing
|
|
23
|
-
* on later React re-renders.
|
|
24
|
-
* @param controller - the board controller the entry toggles.
|
|
25
|
-
* @param locale - locale-change source; when given, re-applies the label on
|
|
26
|
-
* a Language switch (the plain-DOM row otherwise keeps the mount-time copy).
|
|
27
|
-
* @returns disposer removing the entry and its observers.
|
|
28
|
-
*/
|
|
29
|
-
export declare function mountSidebarEntry(controller: BoardController, locale?: LocaleRefreshSource): () => void;
|
|
@@ -1,43 +0,0 @@
|
|
|
1
|
-
/**
|
|
2
|
-
* Board view mounting (dsh-task-board wrapper).
|
|
3
|
-
*
|
|
4
|
-
* The single-occupant takeover lifecycle — container injection into the
|
|
5
|
-
* center column, sibling eviction, remount resilience, sidebar click-out —
|
|
6
|
-
* lives exactly once in shared/client/panel-mount-core.ts (synced copy); this
|
|
7
|
-
* wrapper supplies the board tree, view dataset key, CSS module, and the html
|
|
8
|
-
* attribute names. Those names are pinned by board.module.css, skins, and the
|
|
9
|
-
* semantic attributes contract.
|
|
10
|
-
*/
|
|
11
|
-
import type { BoardController } from '../core/controller.ts'
|
|
12
|
-
import { TaskBoard } from './board/TaskBoard.tsx'
|
|
13
|
-
import { mountCenterPanel } from './panel-mount-core.ts'
|
|
14
|
-
import type { LocaleRefreshSource } from './sidebar-entry.ts'
|
|
15
|
-
import css from './board.module.css'
|
|
16
|
-
|
|
17
|
-
/** The injected board container (kept in the DOM, hidden when inactive). */
|
|
18
|
-
export const BOARD_VIEW_SELECTOR = '[data-dsh-taskboard-view]'
|
|
19
|
-
|
|
20
|
-
/**
|
|
21
|
-
* Mount the board React tree into the center column and bind its visibility
|
|
22
|
-
* to the controller's boardOpen state.
|
|
23
|
-
* @param controller - the board controller driving the view.
|
|
24
|
-
* @param locale - locale-change source; when given, re-renders a mounted board
|
|
25
|
-
* on a Language switch.
|
|
26
|
-
* @returns disposer unmounting the tree and restoring the column.
|
|
27
|
-
*/
|
|
28
|
-
export function mountBoard(controller: BoardController, locale?: LocaleRefreshSource): () => void {
|
|
29
|
-
return mountCenterPanel({
|
|
30
|
-
render: root => root.render(<TaskBoard controller={controller} />),
|
|
31
|
-
viewDatasetKey: 'dshTaskboardView',
|
|
32
|
-
pluginName: 'task-board',
|
|
33
|
-
viewClassName: css.boardView,
|
|
34
|
-
activeAttribute: 'data-dsh-taskboard-active',
|
|
35
|
-
siblingActiveAttribute: 'data-dsh-ssh-active',
|
|
36
|
-
panelName: 'taskboard',
|
|
37
|
-
siblingPanelName: 'ssh',
|
|
38
|
-
isOpen: () => controller.getSnapshot().boardOpen,
|
|
39
|
-
close: () => controller.closeBoard(),
|
|
40
|
-
subscribe: listener => controller.subscribe(listener),
|
|
41
|
-
locale,
|
|
42
|
-
})
|
|
43
|
-
}
|
|
@@ -1,133 +0,0 @@
|
|
|
1
|
-
// Generated by scripts/sync-shared.mjs from shared/client/body-mutations.ts. Do not edit this copy; edit the shared source and run "node scripts/sync-shared.mjs".
|
|
2
|
-
/**
|
|
3
|
-
* One `document.body` MutationObserver per page, shared by every family
|
|
4
|
-
* plugin bundle.
|
|
5
|
-
*
|
|
6
|
-
* Family plugins that inject at the DOM level must notice when the shell
|
|
7
|
-
* re-renders around their injected node: the sidebar entry rows
|
|
8
|
-
* (sidebar-entry-core), the center-column panel containers
|
|
9
|
-
* (panel-mount-core), and the aggregate shell's column shims. Each consumer
|
|
10
|
-
* used to install its OWN `MutationObserver` on `document.body` with
|
|
11
|
-
* `{ childList: true, subtree: true }`, so a page carrying N family plugins
|
|
12
|
-
* paid N native observers and N callback invocations for EVERY mutation batch
|
|
13
|
-
* the app produced — chat token streaming alone produces many per second, and
|
|
14
|
-
* the count grows with the number of installed plugins.
|
|
15
|
-
*
|
|
16
|
-
* This module keeps exactly ONE body observer per page. The registry lives on
|
|
17
|
-
* `globalThis` under a `Symbol.for` key, so the per-package generated copies
|
|
18
|
-
* of this file (scripts/sync-shared.mjs) and separately bundled plugins all
|
|
19
|
-
* reach the same hub at runtime instead of one hub per module instance.
|
|
20
|
-
* Record subscribers receive the mutations accumulated since the last flush.
|
|
21
|
-
* Consumers that only re-check their DOM use subscribeBodyInvalidations:
|
|
22
|
-
* when all subscribers use that path, the hub retains no mutation records
|
|
23
|
-
* (or detached subtrees) while a background page's animation frames pause.
|
|
24
|
-
* Both paths run at most once per frame. The last subscriber disconnects the
|
|
25
|
-
* observer, cancels the pending frame and releases its records.
|
|
26
|
-
*
|
|
27
|
-
* Failure policy: without a DOM or `MutationObserver` the subscription is a
|
|
28
|
-
* no-op disposer (the same silence the per-consumer observers had), and when
|
|
29
|
-
* `requestAnimationFrame` is unavailable the flush runs synchronously so a
|
|
30
|
-
* subscriber is never silently dropped. A throwing subscriber cannot stop the
|
|
31
|
-
* others.
|
|
32
|
-
*/
|
|
33
|
-
|
|
34
|
-
/** The page-wide hub: one observer plus its subscribers and pending records. */
|
|
35
|
-
interface BodyMutationHub {
|
|
36
|
-
observer: MutationObserver
|
|
37
|
-
subscribers: Set<(records: MutationRecord[]) => void>
|
|
38
|
-
pending: MutationRecord[]
|
|
39
|
-
scheduled: boolean
|
|
40
|
-
frame?: number
|
|
41
|
-
}
|
|
42
|
-
|
|
43
|
-
/** Cross-bundle registry key; `Symbol.for` so every module copy agrees. */
|
|
44
|
-
const HUB_KEY = Symbol.for('dsh-web.body-mutation-hub')
|
|
45
|
-
const INVALIDATION_ONLY = Symbol.for('dsh-web.body-mutation-invalidation')
|
|
46
|
-
type Subscriber = ((records: MutationRecord[]) => void) & { [INVALIDATION_ONLY]?: true }
|
|
47
|
-
|
|
48
|
-
function needsRecords(subscribers: Set<(records: MutationRecord[]) => void>): boolean {
|
|
49
|
-
for (const listener of subscribers) {
|
|
50
|
-
if (!(listener as Subscriber)[INVALIDATION_ONLY]) return true
|
|
51
|
-
}
|
|
52
|
-
return false
|
|
53
|
-
}
|
|
54
|
-
|
|
55
|
-
/**
|
|
56
|
-
* Subscribe to a coalesced DOM re-check without retaining mutation records.
|
|
57
|
-
* The marked wrapper also works with an older hub, which delivers records
|
|
58
|
-
* that it simply ignores until a page reload picks up the updated hub.
|
|
59
|
-
*/
|
|
60
|
-
export function subscribeBodyInvalidations(subscriber: () => void): () => void {
|
|
61
|
-
const listener: Subscriber = () => { subscriber() }
|
|
62
|
-
listener[INVALIDATION_ONLY] = true
|
|
63
|
-
return subscribeBodyMutations(listener)
|
|
64
|
-
}
|
|
65
|
-
|
|
66
|
-
/**
|
|
67
|
-
* Subscribe to body-level childList mutations.
|
|
68
|
-
* @param subscriber - called at most once per animation frame with the records
|
|
69
|
-
* collected since the previous flush; must be safe to run repeatedly.
|
|
70
|
-
* @returns the disposer removing this subscriber (and the observer when it was
|
|
71
|
-
* the last one).
|
|
72
|
-
*/
|
|
73
|
-
export function subscribeBodyMutations(subscriber: (records: MutationRecord[]) => void): () => void {
|
|
74
|
-
if (typeof globalThis === 'undefined' || typeof document === 'undefined') return () => {}
|
|
75
|
-
if (typeof MutationObserver !== 'function') return () => {}
|
|
76
|
-
const registry = globalThis as unknown as Record<symbol, unknown>
|
|
77
|
-
let hub = registry[HUB_KEY] as BodyMutationHub | undefined
|
|
78
|
-
if (hub === undefined) {
|
|
79
|
-
const subscribers = new Set<(records: MutationRecord[]) => void>()
|
|
80
|
-
const created: BodyMutationHub = {
|
|
81
|
-
observer: undefined as unknown as MutationObserver,
|
|
82
|
-
subscribers,
|
|
83
|
-
pending: [],
|
|
84
|
-
scheduled: false,
|
|
85
|
-
}
|
|
86
|
-
const flush = (): void => {
|
|
87
|
-
created.frame = undefined
|
|
88
|
-
created.scheduled = false
|
|
89
|
-
const batch = created.pending
|
|
90
|
-
created.pending = []
|
|
91
|
-
for (const listener of [...subscribers]) {
|
|
92
|
-
if (!subscribers.has(listener)) continue
|
|
93
|
-
try {
|
|
94
|
-
listener(batch)
|
|
95
|
-
} catch {
|
|
96
|
-
// One subscriber must never break the others; the next flush retries it.
|
|
97
|
-
}
|
|
98
|
-
}
|
|
99
|
-
}
|
|
100
|
-
const schedule = (): void => {
|
|
101
|
-
if (created.scheduled) return
|
|
102
|
-
created.scheduled = true
|
|
103
|
-
if (typeof requestAnimationFrame === 'function') created.frame = requestAnimationFrame(flush)
|
|
104
|
-
else flush()
|
|
105
|
-
}
|
|
106
|
-
created.observer = new MutationObserver((records) => {
|
|
107
|
-
if (needsRecords(subscribers)) {
|
|
108
|
-
for (const record of records) created.pending.push(record)
|
|
109
|
-
}
|
|
110
|
-
schedule()
|
|
111
|
-
})
|
|
112
|
-
created.observer.observe(document.body ?? document.documentElement, { childList: true, subtree: true })
|
|
113
|
-
registry[HUB_KEY] = created
|
|
114
|
-
hub = created
|
|
115
|
-
}
|
|
116
|
-
const active = hub
|
|
117
|
-
active.subscribers.add(subscriber)
|
|
118
|
-
let subscribed = true
|
|
119
|
-
return () => {
|
|
120
|
-
if (!subscribed) return
|
|
121
|
-
subscribed = false
|
|
122
|
-
active.subscribers.delete(subscriber)
|
|
123
|
-
if (!needsRecords(active.subscribers)) active.pending = []
|
|
124
|
-
if (active.subscribers.size === 0 && registry[HUB_KEY] === active) {
|
|
125
|
-
active.observer.disconnect()
|
|
126
|
-
if (active.frame !== undefined && typeof cancelAnimationFrame === 'function') cancelAnimationFrame(active.frame)
|
|
127
|
-
active.frame = undefined
|
|
128
|
-
active.pending = []
|
|
129
|
-
active.scheduled = false
|
|
130
|
-
delete registry[HUB_KEY]
|
|
131
|
-
}
|
|
132
|
-
}
|
|
133
|
-
}
|
|
@@ -1,155 +0,0 @@
|
|
|
1
|
-
// Generated by scripts/sync-shared.mjs from shared/client/panel-mount-core.ts. Do not edit this copy; edit the shared source and run "node scripts/sync-shared.mjs".
|
|
2
|
-
/**
|
|
3
|
-
* Center-column panel takeover lifecycle.
|
|
4
|
-
*
|
|
5
|
-
* The `conversation` slot is single-occupant (ui-conversation) and external
|
|
6
|
-
* plugins cannot declare slots, so a family panel takes over the center
|
|
7
|
-
* column at the DOM level: a container is appended inside the center column
|
|
8
|
-
* (`[class*="centerCol"]`, the 0.1.0-rc.6+ AppFrame layout; previously
|
|
9
|
-
* `[data-pane="conversation"]` on older shells — the mount selector keeps
|
|
10
|
-
* both, ssh #243 / task-board #107) as an extra trailing child React never
|
|
11
|
-
* manages, and a stylesheet rule hides the conversation content while the
|
|
12
|
-
* panel is active. Toggling is a data attribute on <html> — no React
|
|
13
|
-
* involvement, so the conversation subtree underneath stays mounted and
|
|
14
|
-
* stateful.
|
|
15
|
-
*
|
|
16
|
-
* Consuming plugins keep a thin wrapper that supplies the panel tree,
|
|
17
|
-
* container attribute names, and stylesheet class; those names are pinned by
|
|
18
|
-
* each package's CSS, skins, and the semantic-attributes contract. The
|
|
19
|
-
* sidebar row toggling the panel shares its core the same way
|
|
20
|
-
* (shared/client/sidebar-entry-core.ts, synced copy).
|
|
21
|
-
*/
|
|
22
|
-
import { createRoot, type Root } from 'react-dom/client'
|
|
23
|
-
import { subscribeBodyInvalidations } from './body-mutations.ts'
|
|
24
|
-
|
|
25
|
-
/** Options for mountCenterPanel; dsh-ssh mount.tsx and dsh-task-board board-mount.tsx are the canonical consumers. */
|
|
26
|
-
export interface CenterPanelMountOptions {
|
|
27
|
-
/** Render the panel tree (first open, remount while open, locale refresh). */
|
|
28
|
-
render: (root: Root) => void
|
|
29
|
-
/** dataset key of the injected container's view attribute, e.g. `dshSshView` for `data-dsh-ssh-view`. */
|
|
30
|
-
viewDatasetKey: string
|
|
31
|
-
/** value of the container's L2 `data-dsh-plugin` semantic attribute. */
|
|
32
|
-
pluginName: string
|
|
33
|
-
/** stylesheet class applied to the injected container. */
|
|
34
|
-
viewClassName: string
|
|
35
|
-
/** <html> attribute set while this panel is active. */
|
|
36
|
-
activeAttribute: string
|
|
37
|
-
/** the sibling panel's active attribute, removed from <html> when this panel opens. */
|
|
38
|
-
siblingActiveAttribute: string
|
|
39
|
-
/** detail value this panel broadcasts on the cross-plugin activation event. */
|
|
40
|
-
panelName: string
|
|
41
|
-
/** sibling detail value whose activation closes this panel. */
|
|
42
|
-
siblingPanelName: string
|
|
43
|
-
/** open flag of the owning controller. */
|
|
44
|
-
isOpen: () => boolean
|
|
45
|
-
/** close the panel, handing the center column back to the conversation. */
|
|
46
|
-
close: () => void
|
|
47
|
-
/** subscribe to the owning controller's open-state changes; returns an unsubscriber. */
|
|
48
|
-
subscribe: (listener: () => void) => () => void
|
|
49
|
-
/** locale-change source; when given, re-renders an open panel on a Language switch. */
|
|
50
|
-
locale?: { subscribe(listener: () => void): () => void }
|
|
51
|
-
}
|
|
52
|
-
|
|
53
|
-
const CONVERSATION_COLUMN_SELECTOR = '[data-pane="conversation"], [class*="centerCol"]'
|
|
54
|
-
/** Cross-plugin activation event; detail is the activating panel name. */
|
|
55
|
-
const ACTIVATE_EVENT = 'dsh-panel-activate'
|
|
56
|
-
// Sidebar rows whose clicks hand the center column back to the conversation
|
|
57
|
-
// (including the already-current row, which produces no session-change
|
|
58
|
-
// event). Capture phase, so the panel closes before the shell processes the
|
|
59
|
-
// click.
|
|
60
|
-
const SIDEBAR_ROW_SELECTOR = '[class*="sessionRow"], [class*="projectRow"], [class*="searchResultRow"], [class*="searchResultWorkspace"], [class*="newSession"]'
|
|
61
|
-
|
|
62
|
-
/** Find the center column, or undefined while the frame is not mounted. */
|
|
63
|
-
function conversationColumn(): HTMLElement | undefined {
|
|
64
|
-
return document.querySelector<HTMLElement>(CONVERSATION_COLUMN_SELECTOR) ?? undefined
|
|
65
|
-
}
|
|
66
|
-
|
|
67
|
-
/**
|
|
68
|
-
* Mount a family panel into the center column and bind its visibility to the
|
|
69
|
-
* owning controller's open state.
|
|
70
|
-
* @returns disposer unmounting the tree and restoring the column.
|
|
71
|
-
*/
|
|
72
|
-
export function mountCenterPanel(options: CenterPanelMountOptions): () => void {
|
|
73
|
-
let root: Root | undefined
|
|
74
|
-
let container: HTMLDivElement | undefined
|
|
75
|
-
let unsubscribeLocale: (() => void) | undefined
|
|
76
|
-
try {
|
|
77
|
-
unsubscribeLocale = options.locale?.subscribe(() => {
|
|
78
|
-
if (root !== undefined) options.render(root)
|
|
79
|
-
})
|
|
80
|
-
} catch { /* locale service absent: the panel follows its next natural re-render */ }
|
|
81
|
-
|
|
82
|
-
const ensure = (): void => {
|
|
83
|
-
if (container !== undefined && !container.isConnected) {
|
|
84
|
-
// The conversation pane was replaced; drop the stale tree and remount.
|
|
85
|
-
root?.unmount()
|
|
86
|
-
root = undefined
|
|
87
|
-
container.remove()
|
|
88
|
-
container = undefined
|
|
89
|
-
}
|
|
90
|
-
if (container === undefined) {
|
|
91
|
-
const column = conversationColumn()
|
|
92
|
-
if (column === undefined) return
|
|
93
|
-
container = document.createElement('div')
|
|
94
|
-
container.dataset[options.viewDatasetKey] = ''
|
|
95
|
-
container.dataset.dshPlugin = options.pluginName
|
|
96
|
-
container.className = options.viewClassName
|
|
97
|
-
column.appendChild(container)
|
|
98
|
-
}
|
|
99
|
-
// Keep a visited tree mounted so drafts and terminal sessions survive
|
|
100
|
-
// close/reopen; an unused panel needs neither a React root nor effects.
|
|
101
|
-
if (root !== undefined || !options.isOpen()) return
|
|
102
|
-
root = createRoot(container)
|
|
103
|
-
options.render(root)
|
|
104
|
-
}
|
|
105
|
-
|
|
106
|
-
// The frame mounts after boot settlement; watch for the column's arrival.
|
|
107
|
-
// The observation is the page-wide hub (shared/client/body-mutations.ts):
|
|
108
|
-
// every family panel used to hold its own document.body subtree observer, so
|
|
109
|
-
// the per-mutation cost grew with the number of installed plugins.
|
|
110
|
-
const unsubscribeBody = subscribeBodyInvalidations(() => { ensure() })
|
|
111
|
-
|
|
112
|
-
const applyActive = (): void => {
|
|
113
|
-
if (options.isOpen()) {
|
|
114
|
-
ensure()
|
|
115
|
-
// Single-occupant center column: opening this panel must evict the
|
|
116
|
-
// sibling panel, both its html attribute and its controller state,
|
|
117
|
-
// otherwise the two panels' visibility rules fight and the second
|
|
118
|
-
// click appears dead.
|
|
119
|
-
document.documentElement.removeAttribute(options.siblingActiveAttribute)
|
|
120
|
-
document.documentElement.setAttribute(options.activeAttribute, '')
|
|
121
|
-
document.dispatchEvent(new CustomEvent(ACTIVATE_EVENT, { detail: options.panelName }))
|
|
122
|
-
} else {
|
|
123
|
-
document.documentElement.removeAttribute(options.activeAttribute)
|
|
124
|
-
}
|
|
125
|
-
}
|
|
126
|
-
const onOtherActivate = (event: Event): void => {
|
|
127
|
-
if ((event as CustomEvent).detail === options.siblingPanelName && options.isOpen()) {
|
|
128
|
-
options.close()
|
|
129
|
-
}
|
|
130
|
-
}
|
|
131
|
-
const onClickSidebarRow = (event: MouseEvent): void => {
|
|
132
|
-
if (!options.isOpen()) return
|
|
133
|
-
const target = event.target as HTMLElement | null
|
|
134
|
-
if (target === null) return
|
|
135
|
-
if (target.closest(SIDEBAR_ROW_SELECTOR) !== null) options.close()
|
|
136
|
-
}
|
|
137
|
-
document.addEventListener('click', onClickSidebarRow, true)
|
|
138
|
-
document.addEventListener(ACTIVATE_EVENT, onOtherActivate)
|
|
139
|
-
const unsubscribe = options.subscribe(applyActive)
|
|
140
|
-
applyActive()
|
|
141
|
-
ensure()
|
|
142
|
-
|
|
143
|
-
return () => {
|
|
144
|
-
document.removeEventListener('click', onClickSidebarRow, true)
|
|
145
|
-
document.removeEventListener(ACTIVATE_EVENT, onOtherActivate)
|
|
146
|
-
unsubscribeBody()
|
|
147
|
-
unsubscribe()
|
|
148
|
-
unsubscribeLocale?.()
|
|
149
|
-
document.documentElement.removeAttribute(options.activeAttribute)
|
|
150
|
-
root?.unmount()
|
|
151
|
-
root = undefined
|
|
152
|
-
container?.remove()
|
|
153
|
-
container = undefined
|
|
154
|
-
}
|
|
155
|
-
}
|