@linxin666/dsh-client-ui-task-board 0.1.1

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.
Files changed (50) hide show
  1. package/LICENSE +29 -0
  2. package/README.md +211 -0
  3. package/cordis.patch.yml +12 -0
  4. package/lib/client.js +2592 -0
  5. package/lib/index.js +54 -0
  6. package/lib/invariant.js +6 -0
  7. package/lib/types/client/PluginSettingsCard.d.ts +77 -0
  8. package/lib/types/client/TaskBoardSettingsCard.d.ts +51 -0
  9. package/lib/types/client/board/ConfirmDialog.d.ts +12 -0
  10. package/lib/types/client/board/NewTaskModal.d.ts +6 -0
  11. package/lib/types/client/board/TaskBoard.d.ts +5 -0
  12. package/lib/types/client/board/TaskCard.d.ts +12 -0
  13. package/lib/types/client/board/TaskDetail.d.ts +7 -0
  14. package/lib/types/client/board-mount.d.ts +10 -0
  15. package/lib/types/client/index.d.ts +43 -0
  16. package/lib/types/client/locales.d.ts +105 -0
  17. package/lib/types/client/settings-form.d.ts +118 -0
  18. package/lib/types/client/sidebar-entry.d.ts +25 -0
  19. package/lib/types/core/controller.d.ts +129 -0
  20. package/lib/types/core/execution.d.ts +136 -0
  21. package/lib/types/core/schedule.d.ts +40 -0
  22. package/lib/types/core/scheduler.d.ts +49 -0
  23. package/lib/types/core/store.d.ts +36 -0
  24. package/lib/types/core/tasks.d.ts +111 -0
  25. package/lib/types/index.d.ts +44 -0
  26. package/lib/types/invariant.d.ts +3 -0
  27. package/package.json +85 -0
  28. package/src/client/PluginSettingsCard.tsx +207 -0
  29. package/src/client/TaskBoardSettingsCard.tsx +124 -0
  30. package/src/client/board/ConfirmDialog.tsx +40 -0
  31. package/src/client/board/NewTaskModal.tsx +82 -0
  32. package/src/client/board/TaskBoard.tsx +107 -0
  33. package/src/client/board/TaskCard.tsx +62 -0
  34. package/src/client/board/TaskDetail.tsx +286 -0
  35. package/src/client/board-mount.tsx +74 -0
  36. package/src/client/board.module.css +849 -0
  37. package/src/client/css-modules.d.ts +5 -0
  38. package/src/client/index.ts +167 -0
  39. package/src/client/locales.ts +211 -0
  40. package/src/client/settings-card.module.css +261 -0
  41. package/src/client/settings-form.ts +294 -0
  42. package/src/client/sidebar-entry.ts +118 -0
  43. package/src/core/controller.ts +379 -0
  44. package/src/core/execution.ts +259 -0
  45. package/src/core/schedule.ts +140 -0
  46. package/src/core/scheduler.ts +104 -0
  47. package/src/core/store.ts +183 -0
  48. package/src/core/tasks.ts +204 -0
  49. package/src/index.ts +94 -0
  50. package/src/invariant.ts +4 -0
@@ -0,0 +1,294 @@
1
+ /**
2
+ * Staged form model behind the plugin settings card. A card stages what the
3
+ * user types and writes it only when they save — the settings write is a
4
+ * durable, revision-fenced document mutation, so staging keeps what is on
5
+ * screen exactly what a save would store. Mirrors the official
6
+ * ui-plugin-config card-store pattern in a self-contained slice: this
7
+ * package must not depend on a sibling UI package.
8
+ */
9
+
10
+ import type { SettingsScope, SettingsScopeSnapshot, SnapshotStore } from '@deepseek-ai/dsh-client-runtime/client'
11
+ import { createSnapshotStore } from '@deepseek-ai/dsh-client-runtime/client'
12
+
13
+ /** The write one field's staged text performs when the card is saved. */
14
+ export type FieldWrite =
15
+ | { kind: 'set'; value: unknown }
16
+ | { kind: 'clear' }
17
+
18
+ /** How one field converts between its stored value and its draft text. */
19
+ export interface FieldSpec {
20
+ /** Field name inside the namespace section. */
21
+ field: string
22
+ /** Render a stored value as draft text; the empty string when the section carries none. */
23
+ format: (value: unknown) => string
24
+ /**
25
+ * The write this draft text stages, or undefined when the text is not a
26
+ * value this field accepts — which blocks the save rather than discarding it.
27
+ */
28
+ parse: (text: string) => FieldWrite | undefined
29
+ }
30
+
31
+ /** One field as the card renders it. */
32
+ export interface FieldState {
33
+ /** Draft text the control renders. */
34
+ text: string
35
+ /** Whether saving would leave a user-layer entry for this field. */
36
+ overridden: boolean
37
+ /** Whether the draft is not a value this field accepts, which blocks saving. */
38
+ invalid: boolean
39
+ }
40
+
41
+ /** Form state every plugin settings card shares. */
42
+ export interface CardShell {
43
+ /** False while the namespace is not served to this client; the card renders nothing. */
44
+ available: boolean
45
+ /** Whether the Host document accepts writes. */
46
+ writable: boolean
47
+ /** Whether the form holds edits that a save would write. */
48
+ dirty: boolean
49
+ /** Whether any staged draft is invalid, which blocks the save. */
50
+ invalid: boolean
51
+ /** Whether a save is crossing the wire. */
52
+ saving: boolean
53
+ /** Whether the last save did not land as staged; cleared by the next edit or save. */
54
+ failed: boolean
55
+ }
56
+
57
+ /** The write actions the card's slot entry injects. */
58
+ export interface CardActions {
59
+ /** Stage draft text for one field. */
60
+ edit: (field: string, text: string) => void
61
+ /** Stage a clear, so saving lets the field re-inherit the composition layer. */
62
+ resetField: (field: string) => void
63
+ /** Write every staged edit, then re-seed from what the Host accepted. */
64
+ save: () => void
65
+ /** Drop every staged edit. */
66
+ discard: () => void
67
+ }
68
+
69
+ /** One field's staged edit. */
70
+ interface StagedEdit {
71
+ /** Draft text the control renders. */
72
+ text: string
73
+ /** True when this edit clears the field whatever text it shows. */
74
+ clear: boolean
75
+ }
76
+
77
+ /** One staged edit resolved into the write a save performs. */
78
+ interface PlannedWrite {
79
+ /** Field this entry writes. */
80
+ field: string
81
+ /** Perform the write and report whether the Host holds the staged value afterwards. */
82
+ run: (() => Promise<boolean>) | undefined
83
+ }
84
+
85
+ /** A whole-number field. An empty draft clears the field; any other draft that is not a finite number blocks the save. */
86
+ export function numberField(field: string): FieldSpec {
87
+ return {
88
+ field,
89
+ format: value => typeof value === 'number' ? String(value) : '',
90
+ parse: (text) => {
91
+ const trimmed = text.trim()
92
+ if (trimmed === '') return { kind: 'clear' }
93
+ const parsed = Number(trimmed)
94
+ return Number.isFinite(parsed) ? { kind: 'set', value: parsed } : undefined
95
+ },
96
+ }
97
+ }
98
+
99
+ /** A free-text field. An empty draft clears the field. */
100
+ export function textField(field: string): FieldSpec {
101
+ return {
102
+ field,
103
+ format: value => typeof value === 'string' ? value : '',
104
+ parse: (text) => {
105
+ const trimmed = text.trim()
106
+ return trimmed === '' ? { kind: 'clear' } : { kind: 'set', value: trimmed }
107
+ },
108
+ }
109
+ }
110
+
111
+ /** A boolean field, edited through true/false draft text. */
112
+ export function booleanField(field: string): FieldSpec {
113
+ return {
114
+ field,
115
+ format: value => typeof value === 'boolean' ? String(value) : '',
116
+ parse: (text) => {
117
+ if (text === 'true') return { kind: 'set', value: true }
118
+ if (text === 'false') return { kind: 'set', value: false }
119
+ return undefined
120
+ },
121
+ }
122
+ }
123
+
124
+ /**
125
+ * Stages one card's edits over one settings namespace and writes them on save.
126
+ *
127
+ * The Host is the only authority on whether a value was accepted — its
128
+ * validators own the constraints no schema can express — so the outcome is
129
+ * read back from the section rather than predicted here. A save that did not
130
+ * land keeps its drafts, so the user can correct them instead of retyping.
131
+ */
132
+ export class CardForm<T> {
133
+ private readonly specs: Map<string, FieldSpec>
134
+ private readonly staged = new Map<string, StagedEdit>()
135
+ private readonly listeners = new Set<() => void>()
136
+ private saving = false
137
+ private failed = false
138
+
139
+ /** @param scope - the bound settings scope for this card's namespace. */
140
+ constructor(
141
+ private readonly scope: SettingsScope<T>,
142
+ specs: FieldSpec[],
143
+ ) {
144
+ this.specs = new Map(specs.map(spec => [spec.field, spec]))
145
+ scope.subscribe(() => { this.publish() })
146
+ }
147
+
148
+ /** Publish a projection of this form, rebuilt whenever the scope or a draft changes. */
149
+ bind<S>(project: () => S): SnapshotStore<S> {
150
+ const store = createSnapshotStore(project())
151
+ this.listeners.add(() => { store.set(project()) })
152
+ return store
153
+ }
154
+
155
+ /** Read the card-level state: what the Host serves, and what a save would do. */
156
+ shell(): CardShell {
157
+ const snapshot = this.scope.getSnapshot()
158
+ const plan = this.plan()
159
+ return {
160
+ available: snapshot.status === 'ready',
161
+ writable: snapshot.writable,
162
+ dirty: plan.length > 0,
163
+ invalid: plan.some(item => item.run === undefined),
164
+ saving: this.saving,
165
+ failed: this.failed,
166
+ }
167
+ }
168
+
169
+ /** Read one field's state from the effective section and its staged draft. */
170
+ field(field: string): FieldState {
171
+ const spec = this.specOf(field)
172
+ const staged = this.staged.get(field)
173
+ if (staged === undefined) {
174
+ return { text: spec.format(this.sectionValue(field)), overridden: this.stored(field), invalid: false }
175
+ }
176
+ const write = staged.clear ? { kind: 'clear' as const } : spec.parse(staged.text)
177
+ return {
178
+ text: staged.text,
179
+ overridden: write?.kind === 'set',
180
+ invalid: write === undefined,
181
+ }
182
+ }
183
+
184
+ /** The actions the card's slot registration injects. */
185
+ actions(): CardActions {
186
+ return {
187
+ edit: (field, text) => { this.stage(field, { text, clear: false }) },
188
+ resetField: (field) => {
189
+ this.stage(field, { text: this.specOf(field).format(this.baseValue(field)), clear: true })
190
+ },
191
+ save: () => { void this.save() },
192
+ discard: () => {
193
+ if (this.staged.size === 0 && !this.failed) return
194
+ this.staged.clear()
195
+ this.failed = false
196
+ this.publish()
197
+ },
198
+ }
199
+ }
200
+
201
+ /**
202
+ * Write every staged edit, then re-seed from what the Host accepted.
203
+ * @returns settlement after every write and the read-back.
204
+ */
205
+ async save(): Promise<void> {
206
+ const plan = this.plan()
207
+ const writes = plan.flatMap(item => item.run === undefined ? [] : [item.run])
208
+ if (plan.length === 0 || this.saving || writes.length !== plan.length) return
209
+ this.saving = true
210
+ this.failed = false
211
+ this.publish()
212
+ let landed = true
213
+ for (const write of writes) {
214
+ landed = await write() && landed
215
+ }
216
+ if (landed) this.staged.clear()
217
+ this.saving = false
218
+ this.failed = !landed
219
+ this.publish()
220
+ }
221
+
222
+ /**
223
+ * Every staged edit a save would write. An entry whose draft is not a value
224
+ * its field accepts carries no write: the form is still dirty, and the save
225
+ * refuses rather than dropping the edit. A staged edit that matches the
226
+ * effective section is not a write at all.
227
+ * @returns the planned writes, in the order the fields were staged.
228
+ */
229
+ private plan(): PlannedWrite[] {
230
+ const plan: PlannedWrite[] = []
231
+ for (const [field, staged] of this.staged) {
232
+ const spec = this.specOf(field)
233
+ if (staged.clear) {
234
+ if (this.stored(field)) plan.push({ field, run: () => this.clear(field) })
235
+ continue
236
+ }
237
+ if (staged.text === spec.format(this.sectionValue(field))) continue
238
+ const write = spec.parse(staged.text)
239
+ if (write === undefined) plan.push({ field, run: undefined })
240
+ else if (write.kind === 'clear') plan.push({ field, run: () => this.clear(field) })
241
+ else plan.push({ field, run: () => this.store(field, write.value) })
242
+ }
243
+ return plan
244
+ }
245
+
246
+ private async clear(field: string): Promise<boolean> {
247
+ await this.scope.unset(field)
248
+ return !this.stored(field)
249
+ }
250
+
251
+ private async store(field: string, value: unknown): Promise<boolean> {
252
+ await this.scope.set(field, value)
253
+ return this.userLayer()?.[field] === value
254
+ }
255
+
256
+ private stage(field: string, edit: StagedEdit): void {
257
+ this.staged.set(field, edit)
258
+ this.failed = false
259
+ this.publish()
260
+ }
261
+
262
+ private specOf(field: string): FieldSpec {
263
+ const spec = this.specs.get(field)
264
+ // Every call site names a field this card declared; a missing one is a
265
+ // wiring mistake that must not degrade into a silently inert control.
266
+ if (spec === undefined) throw new Error(`settings card has no field ${field}`)
267
+ return spec
268
+ }
269
+
270
+ private snapshotOf(): SettingsScopeSnapshot<T> {
271
+ return this.scope.getSnapshot()
272
+ }
273
+
274
+ private sectionValue(field: string): unknown {
275
+ return (this.snapshotOf().value as Record<string, unknown> | undefined)?.[field]
276
+ }
277
+
278
+ private baseValue(field: string): unknown {
279
+ return (this.snapshotOf().base as Record<string, unknown> | undefined)?.[field]
280
+ }
281
+
282
+ private userLayer(): Record<string, unknown> | undefined {
283
+ return this.snapshotOf().user as Record<string, unknown> | undefined
284
+ }
285
+
286
+ private stored(field: string): boolean {
287
+ const user = this.userLayer()
288
+ return user !== undefined && Object.hasOwn(user, field)
289
+ }
290
+
291
+ private publish(): void {
292
+ for (const listener of this.listeners) listener()
293
+ }
294
+ }
@@ -0,0 +1,118 @@
1
+ /**
2
+ * Sidebar entry injection.
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 — following the skin precedent of DOM-level extension — the
7
+ * entry row is injected between the shell's New Session button and the
8
+ * workspace browser. The injection self-heals: a MutationObserver watches the
9
+ * sidebar root and re-inserts the row whenever a React re-render displaces it
10
+ * (re-insertion happens in the same frame, before paint, so no flicker).
11
+ *
12
+ * The row is plain DOM (no React tree) so it can never disturb the shell's
13
+ * reconciliation; the board view it toggles is a separate React root mounted
14
+ * in the center column (see board-mount.ts).
15
+ */
16
+ import type { BoardController } from '../core/controller.ts'
17
+ import { t } from './locales.ts'
18
+ import css from './board.module.css'
19
+
20
+ /** Stable data attribute identifying the injected entry row. */
21
+ export const ENTRY_SELECTOR = '[data-dsh-taskboard-entry]'
22
+
23
+ /** The sidebar column is the grid item AppFrame renders with this pane marker. */
24
+ const SIDEBAR_COLUMN_SELECTOR = '[data-pane="sidebar"]'
25
+
26
+ /** Inline icon (matches the shell's 16px nav-icon look). */
27
+ const ICON = `<svg viewBox="0 0 16 16" width="14" height="14" fill="none" stroke="currentColor" stroke-width="1.3" stroke-linecap="round" stroke-linejoin="round" aria-hidden="true"><rect x="2" y="2.5" width="12" height="11" rx="1.5"/><path d="M2 6.5h12M6.5 6.5v7"/></svg>`
28
+
29
+ /** Find the sidebar shell root element, or undefined while not yet mounted. */
30
+ function sidebarRoot(): HTMLElement | undefined {
31
+ const column = document.querySelector<HTMLElement>(SIDEBAR_COLUMN_SELECTOR)
32
+ const root = column?.firstElementChild as HTMLElement | undefined
33
+ return root ?? undefined
34
+ }
35
+
36
+ /** The New Session button: the shell's only direct-child button of the root. */
37
+ function newSessionButton(root: HTMLElement): HTMLButtonElement | undefined {
38
+ for (const child of root.children) {
39
+ if (child.tagName === 'BUTTON') return child as HTMLButtonElement
40
+ }
41
+ return undefined
42
+ }
43
+
44
+ /** Build the entry row (a detached button; insert once the shell is up). */
45
+ function createEntry(controller: BoardController): HTMLButtonElement {
46
+ const entry = document.createElement('button')
47
+ entry.type = 'button'
48
+ entry.dataset.dshTaskboardEntry = ''
49
+ entry.className = css.entry
50
+ entry.setAttribute('aria-label', t('entry.label'))
51
+ entry.innerHTML = `<span class="${css.entryIcon}">${ICON}</span><span class="${css.entryLabel}">${t('entry.label')}</span>`
52
+ entry.addEventListener('click', () => { controller.toggleBoard() })
53
+ return entry
54
+ }
55
+
56
+ /** Re-insert the entry after the New Session button (before the browser region). */
57
+ function placeEntry(root: HTMLElement, entry: HTMLButtonElement): boolean {
58
+ const button = newSessionButton(root)
59
+ if (button === undefined) return false
60
+ if (entry.parentElement !== root) {
61
+ // Insert after the button: React never manages this node, and the shell
62
+ // keeps its own child order intact around it.
63
+ root.insertBefore(entry, button.nextElementSibling)
64
+ }
65
+ return true
66
+ }
67
+
68
+ /**
69
+ * Mount the sidebar entry, waiting for the shell to render and self-healing
70
+ * on later React re-renders.
71
+ * @param controller - the board controller the entry toggles.
72
+ * @returns disposer removing the entry and its observers.
73
+ */
74
+ export function mountSidebarEntry(controller: BoardController): () => void {
75
+ const entry = createEntry(controller)
76
+ let root: HTMLElement | undefined
77
+ let placed = false
78
+
79
+ const tryPlace = (): void => {
80
+ if (placed) return
81
+ root ??= sidebarRoot()
82
+ if (root === undefined) return
83
+ placed = placeEntry(root, entry)
84
+ if (placed) rootObserver.observe(root, { childList: true, subtree: true })
85
+ }
86
+
87
+ // The shell renders after boot settlement; watch for its arrival.
88
+ const waitObserver = new MutationObserver(() => { tryPlace() })
89
+ waitObserver.observe(document.body, { childList: true, subtree: true })
90
+
91
+ // Self-heal: if a React re-render displaces the row, re-insert it in the
92
+ // same frame (microtask before paint → no visible flicker).
93
+ const rootObserver = new MutationObserver(() => {
94
+ if (root === undefined || !root.isConnected) {
95
+ placed = false
96
+ tryPlace()
97
+ return
98
+ }
99
+ if (!root.contains(entry)) {
100
+ placed = placeEntry(root, entry)
101
+ }
102
+ })
103
+
104
+ // Reflect the board's open state on the row (active highlight).
105
+ const unsubscribe = controller.subscribe(() => {
106
+ entry.dataset.active = controller.getSnapshot().boardOpen ? 'true' : undefined
107
+ })
108
+ entry.dataset.active = controller.getSnapshot().boardOpen ? 'true' : undefined
109
+
110
+ tryPlace()
111
+
112
+ return () => {
113
+ waitObserver.disconnect()
114
+ rootObserver.disconnect()
115
+ unsubscribe()
116
+ entry.remove()
117
+ }
118
+ }