@steerable/agent-ui 0.12.8 → 0.13.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.
- package/dist/cards/FactChainDrawer.d.ts +53 -0
- package/dist/cards/FactChainDrawer.js +12 -0
- package/dist/cards/OutcomeReconcileCard.d.ts +30 -0
- package/dist/cards/OutcomeReconcileCard.js +30 -0
- package/dist/cards/UiSurfaceCard.d.ts +17 -0
- package/dist/cards/UiSurfaceCard.js +48 -0
- package/dist/cards/UiSurfaceWorkbench.d.ts +36 -0
- package/dist/cards/UiSurfaceWorkbench.js +186 -0
- package/dist/cards/index.d.ts +10 -0
- package/dist/cards/index.js +5 -0
- package/dist/cards/ui-surface-draft.d.ts +16 -0
- package/dist/cards/ui-surface-draft.js +67 -0
- package/package.json +2 -2
- package/src/cards/FactChainDrawer.tsx +203 -0
- package/src/cards/OutcomeReconcileCard.test.tsx +61 -0
- package/src/cards/OutcomeReconcileCard.tsx +139 -0
- package/src/cards/UiSurfaceAndFactChain.test.tsx +205 -0
- package/src/cards/UiSurfaceCard.tsx +133 -0
- package/src/cards/UiSurfaceWorkbench.tsx +523 -0
- package/src/cards/index.ts +33 -0
- package/src/cards/ui-surface-draft.ts +93 -0
|
@@ -0,0 +1,93 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* Session-scoped draft state shared between `<UiSurfaceCard />` (inline) and
|
|
3
|
+
* `<UiSurfaceWorkbench />` (right-panel workbench) so collapsing or switching
|
|
4
|
+
* workbench tabs never discards user row selections, form edits, or notes.
|
|
5
|
+
*/
|
|
6
|
+
|
|
7
|
+
export interface UiSurfaceDraftState {
|
|
8
|
+
readonly selectedRowIds: readonly string[];
|
|
9
|
+
readonly formValues: Readonly<Record<string, string | number | boolean>>;
|
|
10
|
+
readonly kvDiffOverrides: Readonly<Record<string, string>>;
|
|
11
|
+
readonly note: string;
|
|
12
|
+
}
|
|
13
|
+
|
|
14
|
+
const EMPTY_DRAFT: UiSurfaceDraftState = Object.freeze({
|
|
15
|
+
selectedRowIds: [],
|
|
16
|
+
formValues: {},
|
|
17
|
+
kvDiffOverrides: {},
|
|
18
|
+
note: '',
|
|
19
|
+
});
|
|
20
|
+
|
|
21
|
+
const drafts = new Map<string, UiSurfaceDraftState>();
|
|
22
|
+
const listeners = new Map<string, Set<() => void>>();
|
|
23
|
+
|
|
24
|
+
function makeKey(chatId: string | undefined, surfaceId: string): string {
|
|
25
|
+
return `${chatId || 'default'}::${surfaceId}`;
|
|
26
|
+
}
|
|
27
|
+
|
|
28
|
+
export function getUiSurfaceDraft(
|
|
29
|
+
chatId: string | undefined,
|
|
30
|
+
surfaceId: string,
|
|
31
|
+
): UiSurfaceDraftState {
|
|
32
|
+
return drafts.get(makeKey(chatId, surfaceId)) ?? EMPTY_DRAFT;
|
|
33
|
+
}
|
|
34
|
+
|
|
35
|
+
export function patchUiSurfaceDraft(
|
|
36
|
+
chatId: string | undefined,
|
|
37
|
+
surfaceId: string,
|
|
38
|
+
patch: Partial<UiSurfaceDraftState>,
|
|
39
|
+
): UiSurfaceDraftState {
|
|
40
|
+
const key = makeKey(chatId, surfaceId);
|
|
41
|
+
const prev = drafts.get(key) ?? EMPTY_DRAFT;
|
|
42
|
+
const next: UiSurfaceDraftState = {
|
|
43
|
+
selectedRowIds: patch.selectedRowIds ?? prev.selectedRowIds,
|
|
44
|
+
formValues: patch.formValues
|
|
45
|
+
? { ...prev.formValues, ...patch.formValues }
|
|
46
|
+
: prev.formValues,
|
|
47
|
+
kvDiffOverrides: patch.kvDiffOverrides
|
|
48
|
+
? { ...prev.kvDiffOverrides, ...patch.kvDiffOverrides }
|
|
49
|
+
: prev.kvDiffOverrides,
|
|
50
|
+
note: patch.note !== undefined ? patch.note : prev.note,
|
|
51
|
+
};
|
|
52
|
+
drafts.set(key, next);
|
|
53
|
+
const subs = listeners.get(key);
|
|
54
|
+
if (subs) {
|
|
55
|
+
for (const fn of subs) fn();
|
|
56
|
+
}
|
|
57
|
+
return next;
|
|
58
|
+
}
|
|
59
|
+
|
|
60
|
+
export function clearUiSurfaceDraft(
|
|
61
|
+
chatId: string | undefined,
|
|
62
|
+
surfaceId: string,
|
|
63
|
+
): void {
|
|
64
|
+
const key = makeKey(chatId, surfaceId);
|
|
65
|
+
drafts.delete(key);
|
|
66
|
+
const subs = listeners.get(key);
|
|
67
|
+
if (subs) {
|
|
68
|
+
for (const fn of subs) fn();
|
|
69
|
+
}
|
|
70
|
+
}
|
|
71
|
+
|
|
72
|
+
export function resetAllUiSurfaceDraftsForTests(): void {
|
|
73
|
+
drafts.clear();
|
|
74
|
+
listeners.clear();
|
|
75
|
+
}
|
|
76
|
+
|
|
77
|
+
export function subscribeUiSurfaceDraft(
|
|
78
|
+
chatId: string | undefined,
|
|
79
|
+
surfaceId: string,
|
|
80
|
+
listener: () => void,
|
|
81
|
+
): () => void {
|
|
82
|
+
const key = makeKey(chatId, surfaceId);
|
|
83
|
+
let set = listeners.get(key);
|
|
84
|
+
if (!set) {
|
|
85
|
+
set = new Set();
|
|
86
|
+
listeners.set(key, set);
|
|
87
|
+
}
|
|
88
|
+
set.add(listener);
|
|
89
|
+
return () => {
|
|
90
|
+
set?.delete(listener);
|
|
91
|
+
if (set && set.size === 0) listeners.delete(key);
|
|
92
|
+
};
|
|
93
|
+
}
|