@linxin666/dsh-client-ui-task-board 0.1.15 → 0.1.16
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.
|
@@ -18,6 +18,14 @@ export type FieldWrite = {
|
|
|
18
18
|
export interface FieldSpec {
|
|
19
19
|
/** Field name inside the namespace section. */
|
|
20
20
|
field: string;
|
|
21
|
+
/**
|
|
22
|
+
* Whether the Host treats this field as a secret and redacts its value from
|
|
23
|
+
* the read-back (role('secret') in the section schema). Redacted secrets are
|
|
24
|
+
* never compared against the draft on save; the field lands when the scope
|
|
25
|
+
* reports the write succeeded (its secret-set marker under the bridge), so
|
|
26
|
+
* a successful secret save is not misreported as failed.
|
|
27
|
+
*/
|
|
28
|
+
secret?: boolean;
|
|
21
29
|
/** Render a stored value as draft text; the empty string when the section carries none. */
|
|
22
30
|
format: (value: unknown) => string;
|
|
23
31
|
/**
|
|
@@ -57,6 +65,12 @@ export interface CardShell {
|
|
|
57
65
|
saving: boolean;
|
|
58
66
|
/** Whether the last save did not land as staged; cleared by the next edit or save. */
|
|
59
67
|
failed: boolean;
|
|
68
|
+
/**
|
|
69
|
+
* The rejection code/message the Host returned for the last failed save,
|
|
70
|
+
* surfaced next to the generic failure text. Undefined while no save has
|
|
71
|
+
* failed (or the failure carried no server reason).
|
|
72
|
+
*/
|
|
73
|
+
failedReason?: string;
|
|
60
74
|
}
|
|
61
75
|
/** The write actions the card's slot entry injects. */
|
|
62
76
|
export interface CardActions {
|
|
@@ -69,6 +83,37 @@ export interface CardActions {
|
|
|
69
83
|
/** Drop every staged edit. */
|
|
70
84
|
discard: () => void;
|
|
71
85
|
}
|
|
86
|
+
/** One durable write a batched settings scope performs. */
|
|
87
|
+
export interface BatchedWrite {
|
|
88
|
+
/** Field this entry writes. */
|
|
89
|
+
field: string;
|
|
90
|
+
/** set stores a value; unset drops the leaf. */
|
|
91
|
+
op: 'set' | 'unset';
|
|
92
|
+
/** Value for op set (absent for unset). */
|
|
93
|
+
value?: unknown;
|
|
94
|
+
}
|
|
95
|
+
/** Per-field outcome of one batched scope write. */
|
|
96
|
+
export interface BatchedFieldResult {
|
|
97
|
+
/** Field this entry writes. */
|
|
98
|
+
field: string;
|
|
99
|
+
/** Whether the Host accepted this field's write (per the read-back view). */
|
|
100
|
+
landed: boolean;
|
|
101
|
+
}
|
|
102
|
+
/**
|
|
103
|
+
* Result of a batched scope write. The bridge scope posts every planned write
|
|
104
|
+
* in one /mutate so the Host validate hook judges baseURL+model together; a
|
|
105
|
+
* batched refusal fails the whole save rather than per-field.
|
|
106
|
+
*/
|
|
107
|
+
export interface BatchResult {
|
|
108
|
+
/** Whether the whole mutate was accepted. */
|
|
109
|
+
ok: boolean;
|
|
110
|
+
/** Per-field success, in the request order (always present when ok). */
|
|
111
|
+
fields: BatchedFieldResult[];
|
|
112
|
+
/** Host rejection code (mutate refused). */
|
|
113
|
+
code?: string;
|
|
114
|
+
/** Host rejection message (mutate refused). */
|
|
115
|
+
message?: string;
|
|
116
|
+
}
|
|
72
117
|
/** Constraints a numeric field's accepted drafts must satisfy, mirroring the host schema. */
|
|
73
118
|
export interface NumberConstraints {
|
|
74
119
|
/** The accepted value must be a whole number. */
|
|
@@ -80,6 +125,13 @@ export interface NumberConstraints {
|
|
|
80
125
|
export declare function numberField(field: string, constraints?: NumberConstraints): FieldSpec;
|
|
81
126
|
/** A free-text field. An empty draft clears the field. */
|
|
82
127
|
export declare function textField(field: string): FieldSpec;
|
|
128
|
+
/**
|
|
129
|
+
* A free-text field the Host treats as a secret and redacts from the read-back
|
|
130
|
+
* (role('secret') in the section schema). The card still edits it like text,
|
|
131
|
+
* but a save never compares the redacted value back and relies on the scope
|
|
132
|
+
* reporting the write landed.
|
|
133
|
+
*/
|
|
134
|
+
export declare function secretField(field: string): FieldSpec;
|
|
83
135
|
/** A boolean field, edited through true/false draft text. */
|
|
84
136
|
export declare function booleanField(field: string): FieldSpec;
|
|
85
137
|
/** An enumerated string field; only the listed choices are accepted. An empty draft clears the field. */
|
|
@@ -99,6 +151,7 @@ export declare class CardForm<T> {
|
|
|
99
151
|
private readonly listeners;
|
|
100
152
|
private saving;
|
|
101
153
|
private failed;
|
|
154
|
+
private failedReason;
|
|
102
155
|
/** @param scope - the bound settings scope for this card's namespace. */
|
|
103
156
|
constructor(scope: SettingsScope<T>, specs: FieldSpec[]);
|
|
104
157
|
/** Publish a projection of this form, rebuilt whenever the scope or a draft changes. */
|
|
@@ -111,9 +164,18 @@ export declare class CardForm<T> {
|
|
|
111
164
|
actions(): CardActions;
|
|
112
165
|
/**
|
|
113
166
|
* Write every staged edit, then re-seed from what the Host accepted.
|
|
167
|
+
*
|
|
168
|
+
* When the scope carries the optional batch surface (the dsh-web-ui
|
|
169
|
+
* bridge scope), every planned write rides one mutation so cross-field
|
|
170
|
+
* validate hooks (baseURL+model) judge the batch as a unit instead of
|
|
171
|
+
* deadlocking on per-field writes. Otherwise the per-field loop runs.
|
|
172
|
+
* A field lands only when the Host reports it held the staged value; a
|
|
173
|
+
* landed field's draft is dropped, a failed one stays staged for the user.
|
|
114
174
|
* @returns settlement after every write and the read-back.
|
|
115
175
|
*/
|
|
116
176
|
save(): Promise<void>;
|
|
177
|
+
/** The scope's batch surface when it supports one; undefined conservatively otherwise. */
|
|
178
|
+
private batchedScope;
|
|
117
179
|
/**
|
|
118
180
|
* Every staged edit a save would write. An entry whose draft is not a value
|
|
119
181
|
* its field accepts carries no write: the form is still dirty, and the save
|
package/package.json
CHANGED
|
@@ -1,7 +1,7 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@linxin666/dsh-client-ui-task-board",
|
|
3
3
|
"description": "Task board for the dsh web GUI: a sidebar entry plus a multi-column kanban view with local persistence, task details, and real execution through dsh sessions (session.prompt). Hot-pluggable — mounted via ~/.dsh/cordis.patch.yml + a profile node_modules symlink, no dsh source changes.",
|
|
4
|
-
"version": "0.1.
|
|
4
|
+
"version": "0.1.16",
|
|
5
5
|
"type": "module",
|
|
6
6
|
"main": "lib/index.js",
|
|
7
7
|
"types": "lib/types/index.d.ts",
|
|
@@ -138,7 +138,13 @@ export function PluginSettingsCard<TKey extends string = string>(props: PluginSe
|
|
|
138
138
|
{!state.writable ? <p className={css.readOnly} role="status">{props.t('settings.readOnly')}</p> : null}
|
|
139
139
|
{props.children}
|
|
140
140
|
<div className={css.footer}>
|
|
141
|
-
{state.failed
|
|
141
|
+
{state.failed
|
|
142
|
+
? (
|
|
143
|
+
<p className={css.failed} role="status">
|
|
144
|
+
{props.t('settings.saveFailed')}{state.failedReason ? ' - ' + state.failedReason : ''}
|
|
145
|
+
</p>
|
|
146
|
+
)
|
|
147
|
+
: null}
|
|
142
148
|
<button
|
|
143
149
|
type="button"
|
|
144
150
|
className={css.discard}
|
|
@@ -20,6 +20,14 @@ export type FieldWrite =
|
|
|
20
20
|
export interface FieldSpec {
|
|
21
21
|
/** Field name inside the namespace section. */
|
|
22
22
|
field: string
|
|
23
|
+
/**
|
|
24
|
+
* Whether the Host treats this field as a secret and redacts its value from
|
|
25
|
+
* the read-back (role('secret') in the section schema). Redacted secrets are
|
|
26
|
+
* never compared against the draft on save; the field lands when the scope
|
|
27
|
+
* reports the write succeeded (its secret-set marker under the bridge), so
|
|
28
|
+
* a successful secret save is not misreported as failed.
|
|
29
|
+
*/
|
|
30
|
+
secret?: boolean
|
|
23
31
|
/** Render a stored value as draft text; the empty string when the section carries none. */
|
|
24
32
|
format: (value: unknown) => string
|
|
25
33
|
/**
|
|
@@ -61,6 +69,12 @@ export interface CardShell {
|
|
|
61
69
|
saving: boolean
|
|
62
70
|
/** Whether the last save did not land as staged; cleared by the next edit or save. */
|
|
63
71
|
failed: boolean
|
|
72
|
+
/**
|
|
73
|
+
* The rejection code/message the Host returned for the last failed save,
|
|
74
|
+
* surfaced next to the generic failure text. Undefined while no save has
|
|
75
|
+
* failed (or the failure carried no server reason).
|
|
76
|
+
*/
|
|
77
|
+
failedReason?: string
|
|
64
78
|
}
|
|
65
79
|
|
|
66
80
|
/** The write actions the card's slot entry injects. */
|
|
@@ -87,10 +101,52 @@ interface StagedEdit {
|
|
|
87
101
|
interface PlannedWrite {
|
|
88
102
|
/** Field this entry writes. */
|
|
89
103
|
field: string
|
|
104
|
+
/** The durable write this entry performs, described for a batched scope. */
|
|
105
|
+
op: BatchedWrite
|
|
90
106
|
/** Perform the write and report whether the Host holds the staged value afterwards. */
|
|
91
107
|
run: (() => Promise<boolean>) | undefined
|
|
92
108
|
}
|
|
93
109
|
|
|
110
|
+
/** One durable write a batched settings scope performs. */
|
|
111
|
+
export interface BatchedWrite {
|
|
112
|
+
/** Field this entry writes. */
|
|
113
|
+
field: string
|
|
114
|
+
/** set stores a value; unset drops the leaf. */
|
|
115
|
+
op: 'set' | 'unset'
|
|
116
|
+
/** Value for op set (absent for unset). */
|
|
117
|
+
value?: unknown
|
|
118
|
+
}
|
|
119
|
+
|
|
120
|
+
/** Per-field outcome of one batched scope write. */
|
|
121
|
+
export interface BatchedFieldResult {
|
|
122
|
+
/** Field this entry writes. */
|
|
123
|
+
field: string
|
|
124
|
+
/** Whether the Host accepted this field's write (per the read-back view). */
|
|
125
|
+
landed: boolean
|
|
126
|
+
}
|
|
127
|
+
|
|
128
|
+
/**
|
|
129
|
+
* Result of a batched scope write. The bridge scope posts every planned write
|
|
130
|
+
* in one /mutate so the Host validate hook judges baseURL+model together; a
|
|
131
|
+
* batched refusal fails the whole save rather than per-field.
|
|
132
|
+
*/
|
|
133
|
+
export interface BatchResult {
|
|
134
|
+
/** Whether the whole mutate was accepted. */
|
|
135
|
+
ok: boolean
|
|
136
|
+
/** Per-field success, in the request order (always present when ok). */
|
|
137
|
+
fields: BatchedFieldResult[]
|
|
138
|
+
/** Host rejection code (mutate refused). */
|
|
139
|
+
code?: string
|
|
140
|
+
/** Host rejection message (mutate refused). */
|
|
141
|
+
message?: string
|
|
142
|
+
}
|
|
143
|
+
|
|
144
|
+
/** The optional batch surface the bridge scope adds over the SettingsScope contract. */
|
|
145
|
+
interface BatchedSettingsScope {
|
|
146
|
+
/** Write every operation in one scope mutation, reporting per-field success. */
|
|
147
|
+
mutate: (writes: BatchedWrite[]) => Promise<BatchResult>
|
|
148
|
+
}
|
|
149
|
+
|
|
94
150
|
/** Constraints a numeric field's accepted drafts must satisfy, mirroring the host schema. */
|
|
95
151
|
export interface NumberConstraints {
|
|
96
152
|
/** The accepted value must be a whole number. */
|
|
@@ -129,6 +185,16 @@ export function textField(field: string): FieldSpec {
|
|
|
129
185
|
}
|
|
130
186
|
}
|
|
131
187
|
|
|
188
|
+
/**
|
|
189
|
+
* A free-text field the Host treats as a secret and redacts from the read-back
|
|
190
|
+
* (role('secret') in the section schema). The card still edits it like text,
|
|
191
|
+
* but a save never compares the redacted value back and relies on the scope
|
|
192
|
+
* reporting the write landed.
|
|
193
|
+
*/
|
|
194
|
+
export function secretField(field: string): FieldSpec {
|
|
195
|
+
return { ...textField(field), secret: true }
|
|
196
|
+
}
|
|
197
|
+
|
|
132
198
|
/** A boolean field, edited through true/false draft text. */
|
|
133
199
|
export function booleanField(field: string): FieldSpec {
|
|
134
200
|
return {
|
|
@@ -170,6 +236,7 @@ export class CardForm<T> {
|
|
|
170
236
|
private readonly listeners = new Set<() => void>()
|
|
171
237
|
private saving = false
|
|
172
238
|
private failed = false
|
|
239
|
+
private failedReason: string | undefined
|
|
173
240
|
|
|
174
241
|
/** @param scope - the bound settings scope for this card's namespace. */
|
|
175
242
|
constructor(
|
|
@@ -199,6 +266,7 @@ export class CardForm<T> {
|
|
|
199
266
|
invalid: plan.some(item => item.run === undefined),
|
|
200
267
|
saving: this.saving,
|
|
201
268
|
failed: this.failed,
|
|
269
|
+
...this.failedReason === undefined ? {} : { failedReason: this.failedReason },
|
|
202
270
|
}
|
|
203
271
|
}
|
|
204
272
|
|
|
@@ -229,6 +297,7 @@ export class CardForm<T> {
|
|
|
229
297
|
if (this.staged.size === 0 && !this.failed) return
|
|
230
298
|
this.staged.clear()
|
|
231
299
|
this.failed = false
|
|
300
|
+
this.failedReason = undefined
|
|
232
301
|
this.publish()
|
|
233
302
|
},
|
|
234
303
|
}
|
|
@@ -236,30 +305,57 @@ export class CardForm<T> {
|
|
|
236
305
|
|
|
237
306
|
/**
|
|
238
307
|
* Write every staged edit, then re-seed from what the Host accepted.
|
|
308
|
+
*
|
|
309
|
+
* When the scope carries the optional batch surface (the dsh-web-ui
|
|
310
|
+
* bridge scope), every planned write rides one mutation so cross-field
|
|
311
|
+
* validate hooks (baseURL+model) judge the batch as a unit instead of
|
|
312
|
+
* deadlocking on per-field writes. Otherwise the per-field loop runs.
|
|
313
|
+
* A field lands only when the Host reports it held the staged value; a
|
|
314
|
+
* landed field's draft is dropped, a failed one stays staged for the user.
|
|
239
315
|
* @returns settlement after every write and the read-back.
|
|
240
316
|
*/
|
|
241
317
|
async save(): Promise<void> {
|
|
242
318
|
const plan = this.plan()
|
|
243
|
-
const
|
|
244
|
-
if (plan.length === 0 || this.saving ||
|
|
319
|
+
const valid = plan.filter(item => item.run !== undefined)
|
|
320
|
+
if (plan.length === 0 || this.saving || valid.length !== plan.length) return
|
|
321
|
+
const plannedWrites = valid.map(item => item.op)
|
|
245
322
|
// Snapshot the fields this save writes, so edits staged while it is in
|
|
246
323
|
// flight survive: only the staged keys this save actually wrote are cleared.
|
|
247
324
|
const fields = new Set(plan.map(item => item.field))
|
|
248
325
|
this.saving = true
|
|
249
326
|
this.failed = false
|
|
327
|
+
this.failedReason = undefined
|
|
250
328
|
this.publish()
|
|
251
|
-
|
|
252
|
-
|
|
253
|
-
|
|
329
|
+
const landed = new Set<string>()
|
|
330
|
+
const batch = this.batchedScope()
|
|
331
|
+
if (batch !== undefined) {
|
|
332
|
+
const result = await batch.mutate(plannedWrites)
|
|
333
|
+
if (result.ok) {
|
|
334
|
+
for (const field of result.fields) {
|
|
335
|
+
if (field.landed) landed.add(field.field)
|
|
336
|
+
}
|
|
337
|
+
} else {
|
|
338
|
+
this.failedReason = result.message
|
|
339
|
+
}
|
|
340
|
+
} else {
|
|
341
|
+
for (const item of valid) {
|
|
342
|
+
if (await item.run!()) landed.add(item.field)
|
|
343
|
+
}
|
|
254
344
|
}
|
|
255
|
-
|
|
256
|
-
|
|
345
|
+
for (const field of fields) {
|
|
346
|
+
if (landed.has(field)) this.staged.delete(field)
|
|
257
347
|
}
|
|
258
348
|
this.saving = false
|
|
259
|
-
this.failed =
|
|
349
|
+
this.failed = landed.size !== fields.size
|
|
260
350
|
this.publish()
|
|
261
351
|
}
|
|
262
352
|
|
|
353
|
+
/** The scope's batch surface when it supports one; undefined conservatively otherwise. */
|
|
354
|
+
private batchedScope(): BatchedSettingsScope | undefined {
|
|
355
|
+
const candidate = this.scope as unknown as BatchedSettingsScope | undefined
|
|
356
|
+
return typeof candidate?.mutate === 'function' ? candidate : undefined
|
|
357
|
+
}
|
|
358
|
+
|
|
263
359
|
/**
|
|
264
360
|
* Every staged edit a save would write. An entry whose draft is not a value
|
|
265
361
|
* its field accepts carries no write: the form is still dirty, and the save
|
|
@@ -272,14 +368,14 @@ export class CardForm<T> {
|
|
|
272
368
|
for (const [field, staged] of this.staged) {
|
|
273
369
|
const spec = this.specOf(field)
|
|
274
370
|
if (staged.clear) {
|
|
275
|
-
if (this.stored(field)) plan.push({ field, run: () => this.clear(field) })
|
|
371
|
+
if (this.stored(field)) plan.push({ field, op: { field, op: 'unset' }, run: () => this.clear(field) })
|
|
276
372
|
continue
|
|
277
373
|
}
|
|
278
374
|
if (staged.text === spec.format(this.sectionValue(field))) continue
|
|
279
375
|
const write = spec.parse(staged.text)
|
|
280
|
-
if (write === undefined) plan.push({ field, run: undefined })
|
|
281
|
-
else if (write.kind === 'clear') plan.push({ field, run: () => this.clear(field) })
|
|
282
|
-
else plan.push({ field, run: () => this.store(field, write.value) })
|
|
376
|
+
if (write === undefined) plan.push({ field, op: { field, op: 'unset' }, run: undefined })
|
|
377
|
+
else if (write.kind === 'clear') plan.push({ field, op: { field, op: 'unset' }, run: () => this.clear(field) })
|
|
378
|
+
else plan.push({ field, op: { field, op: 'set', value: write.value }, run: () => this.store(field, write.value) })
|
|
283
379
|
}
|
|
284
380
|
return plan
|
|
285
381
|
}
|
|
@@ -291,12 +387,18 @@ export class CardForm<T> {
|
|
|
291
387
|
|
|
292
388
|
private async store(field: string, value: unknown): Promise<boolean> {
|
|
293
389
|
await this.scope.set(field, value)
|
|
390
|
+
// A redacted secret never appears in the user layer read-back; judging it
|
|
391
|
+
// by value would misreport a successful secret save as failed. The bridge
|
|
392
|
+
// reports secret writes through its secret-set markers (batch path); on
|
|
393
|
+
// the per-field path the scope resolved, so the write is landed.
|
|
394
|
+
if (this.specOf(field).secret) return true
|
|
294
395
|
return this.userLayer()?.[field] === value
|
|
295
396
|
}
|
|
296
397
|
|
|
297
398
|
private stage(field: string, edit: StagedEdit): void {
|
|
298
399
|
this.staged.set(field, edit)
|
|
299
400
|
this.failed = false
|
|
401
|
+
this.failedReason = undefined
|
|
300
402
|
this.publish()
|
|
301
403
|
}
|
|
302
404
|
|