@linxin666/dsh-client-ui-task-board 0.1.11 → 0.1.13
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 +6 -0
- package/README.md +92 -174
- package/README.zh.md +132 -0
- package/lib/client.js +158 -109
- package/lib/client.js.map +1 -1
- package/lib/types/client/index.d.ts +13 -1
- package/lib/types/core/store.d.ts +29 -1
- package/package.json +2 -6
- package/src/client/PluginSettingsCard.tsx +30 -5
- package/src/client/board-mount.tsx +6 -3
- package/src/client/board.module.css +13 -3
- package/src/client/index.ts +15 -2
- package/src/client/settings-card.module.css +146 -116
- package/src/core/controller.ts +19 -4
- package/src/core/store.ts +41 -0
|
@@ -1,60 +1,83 @@
|
|
|
1
|
+
/* Plugin settings card chrome + staged form fields.
|
|
2
|
+
* Aligned with the official ui-settings-plugins PluginCard / fields CSS:
|
|
3
|
+
* same semantic tokens, radius, typography and states so family cards read
|
|
4
|
+
* as siblings of the built-in Shell / Agent loop / Web search cards. */
|
|
5
|
+
|
|
1
6
|
.card {
|
|
2
|
-
list-style: none;
|
|
3
7
|
border: 1px solid var(--dsw-alias-border-l2);
|
|
4
|
-
border-radius: 8px;
|
|
5
8
|
background: var(--dsw-alias-bg-layer-3);
|
|
6
|
-
|
|
9
|
+
border-radius: 12px;
|
|
10
|
+
list-style: none;
|
|
7
11
|
transition: border-color 0.16s, background 0.16s;
|
|
8
12
|
}
|
|
9
13
|
|
|
14
|
+
.card:hover {
|
|
15
|
+
border-color: var(--dsw-alias-label-dimmed);
|
|
16
|
+
}
|
|
17
|
+
|
|
10
18
|
.cardOpen {
|
|
11
19
|
background: var(--dsw-alias-bg-layer-2);
|
|
12
20
|
border-color: var(--dsw-alias-label-dimmed);
|
|
13
21
|
}
|
|
14
22
|
|
|
15
23
|
.header {
|
|
16
|
-
|
|
17
|
-
align-items: center;
|
|
18
|
-
gap: 8px;
|
|
24
|
+
appearance: none;
|
|
19
25
|
width: 100%;
|
|
20
|
-
padding: 10px 14px;
|
|
21
|
-
border: 0;
|
|
22
|
-
background: transparent;
|
|
23
|
-
cursor: pointer;
|
|
24
|
-
text-align: left;
|
|
25
26
|
font: inherit;
|
|
27
|
+
color: inherit;
|
|
28
|
+
text-align: left;
|
|
29
|
+
cursor: pointer;
|
|
30
|
+
background: transparent;
|
|
31
|
+
border: 0;
|
|
32
|
+
border-radius: 12px;
|
|
33
|
+
align-items: center;
|
|
34
|
+
gap: 12px;
|
|
35
|
+
padding: 14px 16px;
|
|
36
|
+
display: flex;
|
|
26
37
|
}
|
|
27
38
|
|
|
28
|
-
.header:
|
|
29
|
-
|
|
39
|
+
.header:focus-visible {
|
|
40
|
+
outline: 2px solid var(--dsw-alias-brand-primary);
|
|
41
|
+
outline-offset: -2px;
|
|
30
42
|
}
|
|
31
43
|
|
|
32
44
|
.headText {
|
|
33
|
-
display: flex;
|
|
34
45
|
flex-direction: column;
|
|
35
|
-
gap: 2px;
|
|
36
46
|
flex: 1;
|
|
47
|
+
gap: 4px;
|
|
37
48
|
min-width: 0;
|
|
49
|
+
display: flex;
|
|
38
50
|
}
|
|
39
51
|
|
|
40
52
|
.name {
|
|
41
|
-
font-weight: 600;
|
|
42
53
|
color: var(--dsw-alias-label-primary);
|
|
54
|
+
font-size: 15px;
|
|
55
|
+
font-weight: 600;
|
|
56
|
+
line-height: 1.4;
|
|
43
57
|
}
|
|
44
58
|
|
|
45
59
|
.description {
|
|
46
|
-
font-size: 12px;
|
|
47
60
|
color: var(--dsw-alias-label-tertiary);
|
|
61
|
+
font-size: 13px;
|
|
62
|
+
line-height: 1.5;
|
|
48
63
|
}
|
|
49
64
|
|
|
50
65
|
.pending {
|
|
51
|
-
|
|
52
|
-
|
|
66
|
+
white-space: nowrap;
|
|
67
|
+
background: var(--dsw-alias-bg-module-platform);
|
|
68
|
+
color: var(--dsw-alias-label-secondary);
|
|
69
|
+
border-radius: 999px;
|
|
70
|
+
flex: none;
|
|
71
|
+
padding: 1px 8px;
|
|
72
|
+
font-size: 11px;
|
|
73
|
+
font-weight: 500;
|
|
74
|
+
line-height: 17px;
|
|
53
75
|
}
|
|
54
76
|
|
|
55
77
|
.chevron {
|
|
56
|
-
transition: transform 120ms ease;
|
|
57
78
|
color: var(--dsw-alias-label-tertiary);
|
|
79
|
+
flex: none;
|
|
80
|
+
transition: transform 0.16s;
|
|
58
81
|
}
|
|
59
82
|
|
|
60
83
|
.chevronOpen {
|
|
@@ -62,51 +85,59 @@
|
|
|
62
85
|
}
|
|
63
86
|
|
|
64
87
|
.body {
|
|
65
|
-
|
|
66
|
-
|
|
67
|
-
|
|
68
|
-
gap: 14px;
|
|
88
|
+
border-top: 1px solid var(--dsw-alias-border-l2);
|
|
89
|
+
margin: 0 16px;
|
|
90
|
+
padding-bottom: 8px;
|
|
69
91
|
}
|
|
70
92
|
|
|
71
93
|
.readOnly {
|
|
72
|
-
margin: 0;
|
|
73
|
-
font-size: 12px;
|
|
74
94
|
color: var(--dsw-alias-label-tertiary);
|
|
95
|
+
margin: 12px 0 0;
|
|
96
|
+
font-size: 12px;
|
|
97
|
+
line-height: 1.5;
|
|
75
98
|
}
|
|
76
99
|
|
|
77
100
|
.notExposed {
|
|
78
|
-
|
|
101
|
+
color: var(--dsw-alias-state-warn-primary);
|
|
102
|
+
margin: 12px 0 0;
|
|
79
103
|
font-size: 12px;
|
|
80
104
|
line-height: 1.5;
|
|
81
|
-
color: var(--dsw-alias-state-warn-primary);
|
|
82
105
|
}
|
|
83
106
|
|
|
84
107
|
.footer {
|
|
85
|
-
|
|
86
|
-
align-items: center;
|
|
108
|
+
border-top: 1px solid var(--dsw-alias-border-l2);
|
|
87
109
|
justify-content: flex-end;
|
|
110
|
+
align-items: center;
|
|
88
111
|
gap: 8px;
|
|
112
|
+
padding: 12px 0 4px;
|
|
113
|
+
display: flex;
|
|
89
114
|
}
|
|
90
115
|
|
|
91
116
|
.failed {
|
|
92
|
-
|
|
117
|
+
min-width: 0;
|
|
118
|
+
color: var(--dsw-alias-label-error);
|
|
119
|
+
flex: 1;
|
|
120
|
+
margin: 0;
|
|
93
121
|
font-size: 12px;
|
|
94
|
-
|
|
122
|
+
line-height: 1.5;
|
|
95
123
|
}
|
|
96
124
|
|
|
97
125
|
.discard,
|
|
98
126
|
.save {
|
|
99
|
-
|
|
100
|
-
border-radius: 6px;
|
|
127
|
+
appearance: none;
|
|
101
128
|
font: inherit;
|
|
102
|
-
font-size: 13px;
|
|
103
129
|
cursor: pointer;
|
|
130
|
+
border: 1px solid transparent;
|
|
131
|
+
border-radius: 8px;
|
|
132
|
+
padding: 5px 14px;
|
|
133
|
+
font-size: 13px;
|
|
134
|
+
line-height: 1.5;
|
|
104
135
|
}
|
|
105
136
|
|
|
106
137
|
.discard {
|
|
107
|
-
border:
|
|
108
|
-
background: transparent;
|
|
138
|
+
border-color: var(--dsw-alias-border-l2);
|
|
109
139
|
color: var(--dsw-alias-label-secondary);
|
|
140
|
+
background: transparent;
|
|
110
141
|
}
|
|
111
142
|
|
|
112
143
|
.discard:hover:not(:disabled) {
|
|
@@ -115,154 +146,153 @@
|
|
|
115
146
|
}
|
|
116
147
|
|
|
117
148
|
.save {
|
|
118
|
-
|
|
119
|
-
|
|
120
|
-
color: var(--dsw-alias-label-primary-foreground);
|
|
121
|
-
}
|
|
122
|
-
|
|
123
|
-
.save:hover:not(:disabled) {
|
|
124
|
-
border-color: var(--dsw-alias-button-info-hover);
|
|
125
|
-
background: var(--dsw-alias-button-info-hover);
|
|
126
|
-
}
|
|
127
|
-
|
|
128
|
-
.discard:active:not(:disabled),
|
|
129
|
-
.save:active:not(:disabled) {
|
|
130
|
-
transform: translateY(1px);
|
|
131
|
-
}
|
|
132
|
-
|
|
133
|
-
.discard:focus-visible:not(:disabled),
|
|
134
|
-
.save:focus-visible:not(:disabled) {
|
|
135
|
-
outline: 2px solid var(--dsw-alias-state-business-primary);
|
|
136
|
-
outline-offset: -2px;
|
|
149
|
+
background: var(--dsw-alias-label-primary);
|
|
150
|
+
color: var(--dsw-alias-bg-layer-3);
|
|
137
151
|
}
|
|
138
152
|
|
|
139
153
|
.discard:disabled,
|
|
140
154
|
.save:disabled {
|
|
141
|
-
opacity: 0.
|
|
155
|
+
opacity: 0.4;
|
|
142
156
|
cursor: default;
|
|
143
157
|
}
|
|
144
158
|
|
|
159
|
+
.discard:focus-visible,
|
|
160
|
+
.save:focus-visible {
|
|
161
|
+
outline: 2px solid var(--dsw-alias-brand-primary);
|
|
162
|
+
outline-offset: 1px;
|
|
163
|
+
}
|
|
164
|
+
|
|
145
165
|
.field {
|
|
146
|
-
display: flex;
|
|
147
166
|
flex-direction: column;
|
|
148
|
-
gap:
|
|
167
|
+
gap: 6px;
|
|
168
|
+
padding: 12px 0;
|
|
169
|
+
display: flex;
|
|
170
|
+
}
|
|
171
|
+
|
|
172
|
+
.field + .field {
|
|
173
|
+
border-top: 1px solid var(--dsw-alias-border-l2);
|
|
149
174
|
}
|
|
150
175
|
|
|
151
176
|
.head {
|
|
152
|
-
display: flex;
|
|
153
177
|
align-items: center;
|
|
154
178
|
gap: 8px;
|
|
179
|
+
display: flex;
|
|
155
180
|
}
|
|
156
181
|
|
|
157
182
|
.label {
|
|
183
|
+
min-width: 0;
|
|
184
|
+
color: var(--dsw-alias-label-primary);
|
|
185
|
+
flex: 1;
|
|
158
186
|
font-size: 13px;
|
|
159
187
|
font-weight: 500;
|
|
160
|
-
|
|
188
|
+
line-height: 1.5;
|
|
161
189
|
}
|
|
162
190
|
|
|
163
191
|
.badges {
|
|
164
|
-
display: flex;
|
|
165
192
|
align-items: center;
|
|
166
|
-
gap:
|
|
193
|
+
gap: 8px;
|
|
194
|
+
display: inline-flex;
|
|
167
195
|
}
|
|
168
196
|
|
|
169
197
|
.badge {
|
|
170
|
-
|
|
171
|
-
|
|
198
|
+
white-space: nowrap;
|
|
199
|
+
background: var(--dsw-alias-bg-module-platform);
|
|
200
|
+
color: var(--dsw-alias-label-secondary);
|
|
172
201
|
border-radius: 999px;
|
|
173
|
-
|
|
174
|
-
|
|
202
|
+
padding: 1px 8px;
|
|
203
|
+
font-size: 11px;
|
|
204
|
+
font-weight: 500;
|
|
205
|
+
line-height: 17px;
|
|
175
206
|
}
|
|
176
207
|
|
|
177
208
|
.reset {
|
|
178
|
-
font
|
|
179
|
-
|
|
180
|
-
background: transparent;
|
|
181
|
-
color: var(--dsw-alias-state-business-primary);
|
|
209
|
+
font: inherit;
|
|
210
|
+
color: var(--dsw-alias-label-secondary);
|
|
182
211
|
cursor: pointer;
|
|
212
|
+
background: transparent;
|
|
213
|
+
border: none;
|
|
183
214
|
padding: 0;
|
|
215
|
+
font-size: 12px;
|
|
216
|
+
line-height: 1.5;
|
|
184
217
|
}
|
|
185
218
|
|
|
186
219
|
.reset:hover:not(:disabled) {
|
|
187
|
-
|
|
220
|
+
color: var(--dsw-alias-label-primary);
|
|
188
221
|
}
|
|
189
222
|
|
|
190
|
-
.reset:
|
|
191
|
-
|
|
192
|
-
opacity: 0.8;
|
|
223
|
+
.reset:disabled {
|
|
224
|
+
cursor: default;
|
|
193
225
|
}
|
|
194
226
|
|
|
195
227
|
.reset:focus-visible {
|
|
196
|
-
outline: 2px solid var(--dsw-alias-
|
|
197
|
-
outline-offset:
|
|
198
|
-
}
|
|
199
|
-
|
|
200
|
-
.reset:disabled {
|
|
201
|
-
opacity: 0.5;
|
|
202
|
-
cursor: default;
|
|
228
|
+
outline: 2px solid var(--dsw-alias-brand-primary);
|
|
229
|
+
outline-offset: 2px;
|
|
203
230
|
}
|
|
204
231
|
|
|
205
232
|
.input,
|
|
206
233
|
.select {
|
|
207
|
-
padding: 6px 8px;
|
|
208
234
|
border: 1px solid var(--dsw-alias-border-l2);
|
|
209
|
-
|
|
235
|
+
background: var(--dsw-alias-bg-layer-3);
|
|
236
|
+
height: 34px;
|
|
210
237
|
font: inherit;
|
|
211
|
-
font-size: 13px;
|
|
212
238
|
color: var(--dsw-alias-label-primary);
|
|
213
|
-
|
|
239
|
+
border-radius: 8px;
|
|
240
|
+
padding: 0 12px;
|
|
241
|
+
font-size: 13px;
|
|
242
|
+
line-height: 1.5;
|
|
214
243
|
}
|
|
215
244
|
|
|
216
|
-
.
|
|
217
|
-
|
|
218
|
-
border:
|
|
219
|
-
|
|
220
|
-
font: inherit;
|
|
221
|
-
font-size: 13px;
|
|
222
|
-
color: var(--dsw-alias-label-primary);
|
|
245
|
+
.input:focus-visible,
|
|
246
|
+
.select:focus-visible {
|
|
247
|
+
border-color: var(--dsw-alias-brand-primary);
|
|
248
|
+
outline: none;
|
|
223
249
|
}
|
|
224
250
|
|
|
225
251
|
.input:disabled,
|
|
226
252
|
.select:disabled {
|
|
227
|
-
|
|
253
|
+
color: var(--dsw-alias-label-tertiary);
|
|
254
|
+
cursor: default;
|
|
228
255
|
}
|
|
229
256
|
|
|
230
|
-
.
|
|
231
|
-
|
|
232
|
-
|
|
233
|
-
|
|
257
|
+
.inputInvalid {
|
|
258
|
+
border: 1px solid var(--dsw-alias-label-error);
|
|
259
|
+
background: var(--dsw-alias-bg-layer-3);
|
|
260
|
+
height: 34px;
|
|
261
|
+
font: inherit;
|
|
262
|
+
color: var(--dsw-alias-label-primary);
|
|
263
|
+
border-radius: 8px;
|
|
264
|
+
padding: 0 12px;
|
|
265
|
+
font-size: 13px;
|
|
266
|
+
line-height: 1.5;
|
|
267
|
+
}
|
|
268
|
+
|
|
269
|
+
.inputInvalid:focus-visible {
|
|
270
|
+
outline: 2px solid var(--dsw-alias-label-error);
|
|
271
|
+
outline-offset: 1px;
|
|
272
|
+
border-color: var(--dsw-alias-label-error);
|
|
234
273
|
}
|
|
235
274
|
|
|
236
275
|
.invalid {
|
|
276
|
+
color: var(--dsw-alias-label-error);
|
|
237
277
|
margin: 0;
|
|
238
278
|
font-size: 12px;
|
|
239
|
-
|
|
240
|
-
}
|
|
241
|
-
|
|
242
|
-
/* --- polish: header keyboard focus / press, unified motion, reduced-motion --- */
|
|
243
|
-
.header:focus-visible {
|
|
244
|
-
outline: 2px solid var(--dsw-alias-state-business-primary);
|
|
245
|
-
outline-offset: -2px;
|
|
246
|
-
}
|
|
247
|
-
|
|
248
|
-
.header:active {
|
|
249
|
-
background: var(--dsw-alias-interactive-bg-hover);
|
|
279
|
+
line-height: 1.5;
|
|
250
280
|
}
|
|
251
281
|
|
|
252
|
-
.
|
|
253
|
-
|
|
254
|
-
|
|
255
|
-
|
|
256
|
-
|
|
282
|
+
.hint {
|
|
283
|
+
color: var(--dsw-alias-label-tertiary);
|
|
284
|
+
margin: 0;
|
|
285
|
+
font-size: 12px;
|
|
286
|
+
line-height: 1.5;
|
|
257
287
|
}
|
|
258
288
|
|
|
259
289
|
@media (prefers-reduced-motion: reduce) {
|
|
260
290
|
.card,
|
|
261
291
|
.header,
|
|
262
292
|
.chevron,
|
|
293
|
+
.chevronOpen,
|
|
263
294
|
.discard,
|
|
264
|
-
.save
|
|
265
|
-
.reset {
|
|
295
|
+
.save {
|
|
266
296
|
transition: none;
|
|
267
297
|
}
|
|
268
298
|
}
|
package/src/core/controller.ts
CHANGED
|
@@ -94,6 +94,15 @@ export class BoardController {
|
|
|
94
94
|
start(): void {
|
|
95
95
|
this.tasks = this.deps.store.load()
|
|
96
96
|
void this.reconcileRunningTasks()
|
|
97
|
+
// A sibling tab may have edited or deleted the ledger (same origin,
|
|
98
|
+
// storage events). Reload on external change so a task deleted in
|
|
99
|
+
// another tab stops firing here — and is never written back by this
|
|
100
|
+
// tab's stale copy (scheduler roll-forward, execution settlement).
|
|
101
|
+
const unsubscribeExternal = this.deps.store.subscribeExternal?.(() => {
|
|
102
|
+
this.tasks = this.deps.store.load()
|
|
103
|
+
this.notify()
|
|
104
|
+
})
|
|
105
|
+
if (unsubscribeExternal !== undefined) this.disposers.push(unsubscribeExternal)
|
|
97
106
|
this.disposers.push(this.deps.sessions.list.subscribe(() => {
|
|
98
107
|
this.onSessionsChanged()
|
|
99
108
|
}))
|
|
@@ -329,7 +338,7 @@ export class BoardController {
|
|
|
329
338
|
this.reconcileInFlight = true
|
|
330
339
|
try {
|
|
331
340
|
type Settled = Extract<ExecutionEvent, { kind: 'settled' }>
|
|
332
|
-
const events: Array<{
|
|
341
|
+
const events: Array<{ taskId: string; event: Settled }> = []
|
|
333
342
|
for (const task of this.tasks) {
|
|
334
343
|
if (task.status !== 'running') continue
|
|
335
344
|
const execution = task.executions[task.executions.length - 1]
|
|
@@ -337,14 +346,20 @@ export class BoardController {
|
|
|
337
346
|
// boundary); reconciliation exists for background/leftover runs.
|
|
338
347
|
if (execution !== undefined && this.activeExecutionIds.has(execution.id)) continue
|
|
339
348
|
const event = await this.deps.exec.reconcile(task)
|
|
340
|
-
if (event !== undefined && event.kind === 'settled') events.push({ task, event })
|
|
349
|
+
if (event !== undefined && event.kind === 'settled') events.push({ taskId: task.id, event })
|
|
341
350
|
}
|
|
342
351
|
if (events.length === 0) return
|
|
343
352
|
let changed = false
|
|
344
|
-
for (const {
|
|
353
|
+
for (const { taskId, event } of events) {
|
|
354
|
+
// The reconcile call above awaited: a sibling tab may have rewritten
|
|
355
|
+
// the ledger (storage event reload) meanwhile. Re-read the freshest
|
|
356
|
+
// record now so the stale task captured before the await can never
|
|
357
|
+
// overwrite fields the sibling wrote.
|
|
358
|
+
const task = this.tasks.find(candidate => candidate.id === taskId)
|
|
359
|
+
if (task === undefined) continue
|
|
345
360
|
const next = settleExecution(task, event.executionId, event.outcome, this.now(), event.error)
|
|
346
361
|
if (next === task) continue
|
|
347
|
-
this.tasks = this.tasks.map(candidate => candidate.id ===
|
|
362
|
+
this.tasks = this.tasks.map(candidate => candidate.id === taskId ? next : candidate)
|
|
348
363
|
changed = true
|
|
349
364
|
}
|
|
350
365
|
if (changed) this.persistAndNotify()
|
package/src/core/store.ts
CHANGED
|
@@ -25,11 +25,30 @@ export interface TaskStore {
|
|
|
25
25
|
save(tasks: readonly TaskRecord[]): void
|
|
26
26
|
/** Drop the persisted ledger (leaves the in-memory state alone). */
|
|
27
27
|
clear(): void
|
|
28
|
+
/**
|
|
29
|
+
* Subscribe to ledger changes written by ANOTHER tab of the same origin
|
|
30
|
+
* (browser storage events). The board controller reloads the ledger on
|
|
31
|
+
* such a change, so a task deleted in one tab cannot keep firing (or be
|
|
32
|
+
* written back) from the stale in-memory copy of another tab. No-op when
|
|
33
|
+
* the backend has no cross-instance channel (in-memory store).
|
|
34
|
+
*/
|
|
35
|
+
subscribeExternal?(listener: () => void): () => void
|
|
28
36
|
}
|
|
29
37
|
|
|
30
38
|
/** Storage key for the task ledger document. */
|
|
31
39
|
export const DEFAULT_STORAGE_KEY = 'dsh.taskBoard.v1'
|
|
32
40
|
|
|
41
|
+
/** Structural shape of the storage event fired in sibling tabs (DOM-free). */
|
|
42
|
+
export interface StorageChangeEvent {
|
|
43
|
+
key: string | null
|
|
44
|
+
}
|
|
45
|
+
|
|
46
|
+
/** The event-target face the store needs for cross-tab notifications. */
|
|
47
|
+
export interface StorageEvents {
|
|
48
|
+
addEventListener(type: 'storage', listener: (event: StorageChangeEvent) => void): void
|
|
49
|
+
removeEventListener(type: 'storage', listener: (event: StorageChangeEvent) => void): void
|
|
50
|
+
}
|
|
51
|
+
|
|
33
52
|
/**
|
|
34
53
|
* Structural row check with the status left unvalidated (see {@link parseLedger}).
|
|
35
54
|
* The `schedule` field is deliberately NOT checked here: a malformed schedule
|
|
@@ -127,10 +146,16 @@ export class LocalStorageTaskStore implements TaskStore {
|
|
|
127
146
|
/**
|
|
128
147
|
* @param key - storage key for the ledger document.
|
|
129
148
|
* @param storage - storage backend (defaults to the global localStorage; tests inject fakes).
|
|
149
|
+
* @param events - storage-event target for cross-tab notifications (defaults
|
|
150
|
+
* to the browser global; undefined in non-browser runtimes, where the
|
|
151
|
+
* subscription becomes a no-op).
|
|
130
152
|
*/
|
|
131
153
|
constructor(
|
|
132
154
|
private readonly key: string = DEFAULT_STORAGE_KEY,
|
|
133
155
|
private readonly storage: Pick<Storage, 'getItem' | 'setItem' | 'removeItem'> | undefined = globalThis.localStorage,
|
|
156
|
+
private readonly events: StorageEvents | undefined = typeof (globalThis as { addEventListener?: unknown }).addEventListener === 'function'
|
|
157
|
+
? (globalThis as unknown as StorageEvents)
|
|
158
|
+
: undefined,
|
|
134
159
|
) {}
|
|
135
160
|
|
|
136
161
|
load(): TaskRecord[] {
|
|
@@ -163,6 +188,22 @@ export class LocalStorageTaskStore implements TaskStore {
|
|
|
163
188
|
console.error('[dsh-task-board] task ledger clear failed', error)
|
|
164
189
|
}
|
|
165
190
|
}
|
|
191
|
+
|
|
192
|
+
/**
|
|
193
|
+
* Cross-tab change subscription (see {@link TaskStore.subscribeExternal}).
|
|
194
|
+
* The browser fires the storage event in every OTHER tab of the same origin
|
|
195
|
+
* when one tab writes; a null key means the whole storage was cleared. Both
|
|
196
|
+
* cases reload the ledger here; unrelated keys are ignored.
|
|
197
|
+
*/
|
|
198
|
+
subscribeExternal(listener: () => void): () => void {
|
|
199
|
+
if (this.events === undefined) return () => {}
|
|
200
|
+
const onStorage = (event: StorageChangeEvent): void => {
|
|
201
|
+
if (event.key !== null && event.key !== this.key) return
|
|
202
|
+
listener()
|
|
203
|
+
}
|
|
204
|
+
this.events.addEventListener('storage', onStorage)
|
|
205
|
+
return () => { this.events?.removeEventListener('storage', onStorage) }
|
|
206
|
+
}
|
|
166
207
|
}
|
|
167
208
|
|
|
168
209
|
/** In-memory backend (tests, and a fallback when storage is unavailable). */
|