@exegia/corpora-ui 0.19.0 → 0.21.0
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-lib/components/blocks/auth/__tests__/auth-state-atom.test.d.ts +1 -0
- package/dist-lib/components/blocks/auth/auth-flow-atom.d.ts +77 -0
- package/dist-lib/components/blocks/auth/auth-session-atom.d.ts +28 -0
- package/dist-lib/components/blocks/auth/auth-state-type.d.ts +71 -0
- package/dist-lib/components/blocks/auth/auth-state.d.ts +9 -0
- package/dist-lib/components/blocks/auth/use-auth-state.d.ts +52 -0
- package/dist-lib/components/blocks/nav/sidebar/__tests__/ai-sidebar-atom.test.d.ts +1 -0
- package/dist-lib/components/blocks/nav/sidebar/__tests__/use-ai-sidebar.test.d.ts +1 -0
- package/dist-lib/components/blocks/nav/sidebar/ai-sidebar-atom.d.ts +217 -0
- package/dist-lib/components/blocks/nav/sidebar/ai-sidebar.d.ts +11 -2
- package/dist-lib/components/blocks/nav/sidebar/index.d.ts +3 -1
- package/dist-lib/components/blocks/nav/sidebar/sidebar-context.d.ts +3 -0
- package/dist-lib/components/blocks/nav/sidebar/sidebar-row.d.ts +3 -1
- package/dist-lib/components/blocks/nav/sidebar/type.d.ts +191 -29
- package/dist-lib/components/blocks/nav/sidebar/use-ai-sidebar-state.d.ts +29 -0
- package/dist-lib/components/blocks/nav/sidebar/use-ai-sidebar.d.ts +27 -31
- package/dist-lib/components/blocks/nav/sidebar/utils.d.ts +6 -1
- package/dist-lib/components/blocks/profile/index.d.ts +7 -0
- package/dist-lib/components/blocks/profile/profile-card-atom.d.ts +68 -0
- package/dist-lib/components/blocks/profile/profile-card-block.d.ts +28 -39
- package/dist-lib/components/blocks/profile/type.d.ts +80 -0
- package/dist-lib/components/blocks/profile/use-profile-card-state.d.ts +24 -0
- package/dist-lib/components/blocks/profile/use-profile-card.d.ts +34 -0
- package/dist-lib/components/blocks/scaffold/constants.d.ts +5 -0
- package/dist-lib/components/blocks/scaffold/scaffold-canvas.d.ts +2 -0
- package/dist-lib/components/blocks/scaffold/scaffold-panel.d.ts +1 -1
- package/dist-lib/components/blocks/scaffold/scaffold-tab.d.ts +6 -1
- package/dist-lib/components/blocks/scaffold/type.d.ts +28 -0
- package/dist-lib/components/blocks/scaffold/use-panel-visibility.d.ts +19 -0
- package/dist-lib/components/blocks/scaffold/utils.d.ts +6 -0
- package/dist-lib/components/blocks/shell/__tests__/shell-fit-atom.test.d.ts +1 -0
- package/dist-lib/components/blocks/shell/__tests__/shell-metrics.test.d.ts +1 -0
- package/dist-lib/components/blocks/shell/animated-panel-provider.d.ts +1 -1
- package/dist-lib/components/blocks/shell/animated-panel.d.ts +1 -1
- package/dist-lib/components/blocks/shell/index.d.ts +4 -0
- package/dist-lib/components/blocks/shell/shell-fit-atom.d.ts +68 -0
- package/dist-lib/components/blocks/shell/shell-metrics.d.ts +54 -0
- package/dist-lib/components/blocks/shell/type.d.ts +115 -3
- package/dist-lib/components/blocks/shell/use-shell-fit-state.d.ts +25 -0
- package/dist-lib/components/blocks/shell/use-shell-fit.d.ts +14 -0
- package/dist-lib/components/blocks/shell/use-shell-panels.d.ts +12 -1
- package/dist-lib/components/blocks/shell/utils.d.ts +32 -0
- package/dist-lib/components/composed/tree/__tests__/tree-atom.test.d.ts +1 -0
- package/dist-lib/components/composed/tree/__tests__/tree.test.d.ts +1 -0
- package/dist-lib/components/composed/tree/__tests__/use-tree.test.d.ts +1 -0
- package/dist-lib/components/composed/tree/constants.d.ts +35 -0
- package/dist-lib/components/composed/tree/index.d.ts +6 -0
- package/dist-lib/components/composed/tree/tree-atom.d.ts +160 -0
- package/dist-lib/components/composed/tree/tree-context.d.ts +4 -0
- package/dist-lib/components/composed/tree/tree-node.d.ts +12 -0
- package/dist-lib/components/composed/tree/tree.d.ts +19 -0
- package/dist-lib/components/composed/tree/type.d.ts +290 -0
- package/dist-lib/components/composed/tree/use-tree-dnd.d.ts +18 -0
- package/dist-lib/components/composed/tree/use-tree-state.d.ts +25 -0
- package/dist-lib/components/composed/tree/use-tree.d.ts +24 -0
- package/dist-lib/components/composed/tree/utils.d.ts +28 -0
- package/dist-lib/components/composed/user-avatar.d.ts +5 -28
- package/dist-lib/components/user-avatar/__tests__/user-avatar.test.d.ts +1 -0
- package/dist-lib/components/user-avatar/audio-wave.d.ts +2 -0
- package/dist-lib/components/user-avatar/component.d.ts +3 -0
- package/dist-lib/components/user-avatar/fallback.d.ts +5 -0
- package/dist-lib/components/user-avatar/index.d.ts +18 -0
- package/dist-lib/components/user-avatar/presence-badge.d.ts +16 -0
- package/dist-lib/components/user-avatar/type.d.ts +71 -0
- package/dist-lib/components/user-avatar/use-user-avatar-state.d.ts +26 -0
- package/dist-lib/components/user-avatar/use-user-avatar.d.ts +32 -0
- package/dist-lib/components/user-avatar/user-avatar-atom.d.ts +55 -0
- package/dist-lib/components/user-avatar/utils.d.ts +2 -0
- package/dist-lib/index.d.ts +6 -2
- package/dist-lib/index.js +3576 -1366
- package/dist-lib/index.js.map +1 -1
- package/dist-lib/state/exegia-provider.d.ts +51 -0
- package/dist-lib/state/index.d.ts +4 -0
- package/dist-lib/state/store.d.ts +17 -0
- package/package.json +16 -12
- package/src/components/beste/piece/browser-frame.tsx +9 -6
- package/src/components/blocks/auth/__tests__/auth-state-atom.test.tsx +247 -0
- package/src/components/blocks/auth/auth-flow-atom.ts +238 -0
- package/src/components/blocks/auth/auth-session-atom.ts +82 -0
- package/src/components/blocks/auth/auth-state-type.ts +97 -0
- package/src/components/blocks/auth/auth-state.ts +52 -0
- package/src/components/blocks/auth/use-auth-state.ts +127 -0
- package/src/components/blocks/nav/sidebar/__tests__/ai-sidebar-atom.test.tsx +325 -0
- package/src/components/blocks/nav/sidebar/__tests__/use-ai-sidebar.test.tsx +310 -0
- package/src/components/blocks/nav/sidebar/ai-sidebar-atom.ts +698 -0
- package/src/components/blocks/nav/sidebar/ai-sidebar.tsx +112 -76
- package/src/components/blocks/nav/sidebar/index.ts +53 -1
- package/src/components/blocks/nav/sidebar/sidebar-context.ts +15 -0
- package/src/components/blocks/nav/sidebar/sidebar-row.tsx +119 -50
- package/src/components/blocks/nav/sidebar/type.ts +228 -29
- package/src/components/blocks/nav/sidebar/use-ai-sidebar-state.ts +123 -0
- package/src/components/blocks/nav/sidebar/use-ai-sidebar.ts +455 -225
- package/src/components/blocks/nav/sidebar/utils.ts +29 -1
- package/src/components/blocks/profile/__tests__/profile-card-block.test.tsx +194 -0
- package/src/components/blocks/profile/index.ts +28 -0
- package/src/components/blocks/profile/profile-card-atom.ts +247 -0
- package/src/components/blocks/profile/profile-card-block.tsx +153 -74
- package/src/components/blocks/profile/type.ts +95 -0
- package/src/components/blocks/profile/use-profile-card-state.ts +67 -0
- package/src/components/blocks/profile/use-profile-card.ts +126 -0
- package/src/components/blocks/scaffold/__tests__/scaffold.test.tsx +160 -1
- package/src/components/blocks/scaffold/constants.ts +7 -0
- package/src/components/blocks/scaffold/panel-menu-button.tsx +3 -0
- package/src/components/blocks/scaffold/scaffold-canvas.tsx +48 -5
- package/src/components/blocks/scaffold/scaffold-inspector.tsx +3 -2
- package/src/components/blocks/scaffold/scaffold-main.tsx +1 -1
- package/src/components/blocks/scaffold/scaffold-panel.tsx +41 -5
- package/src/components/blocks/scaffold/scaffold-root.tsx +18 -3
- package/src/components/blocks/scaffold/scaffold-sidebar.tsx +1 -1
- package/src/components/blocks/scaffold/scaffold-tab.tsx +45 -7
- package/src/components/blocks/scaffold/type.ts +28 -0
- package/src/components/blocks/scaffold/use-panel-visibility.ts +180 -0
- package/src/components/blocks/scaffold/utils.ts +19 -0
- package/src/components/blocks/shell/__tests__/shell-fit-atom.test.tsx +360 -0
- package/src/components/blocks/shell/__tests__/shell-layout.test.tsx +192 -3
- package/src/components/blocks/shell/__tests__/shell-metrics.test.ts +108 -0
- package/src/components/blocks/shell/animated-panel-inset.tsx +5 -1
- package/src/components/blocks/shell/animated-panel-provider.tsx +77 -11
- package/src/components/blocks/shell/animated-panel-trigger.tsx +4 -0
- package/src/components/blocks/shell/animated-panel.tsx +126 -29
- package/src/components/blocks/shell/index.ts +18 -0
- package/src/components/blocks/shell/shell-fit-atom.ts +243 -0
- package/src/components/blocks/shell/shell-layout.tsx +55 -53
- package/src/components/blocks/shell/shell-metrics.ts +79 -0
- package/src/components/blocks/shell/type.ts +130 -3
- package/src/components/blocks/shell/use-shell-fit-state.ts +49 -0
- package/src/components/blocks/shell/use-shell-fit.ts +135 -0
- package/src/components/blocks/shell/use-shell-panels.ts +57 -4
- package/src/components/blocks/shell/utils.ts +44 -4
- package/src/components/composed/tree/CLAUDE.md +132 -0
- package/src/components/composed/tree/__tests__/tree-atom.test.tsx +217 -0
- package/src/components/composed/tree/__tests__/tree.test.tsx +525 -0
- package/src/components/composed/tree/__tests__/use-tree.test.tsx +333 -0
- package/src/components/composed/tree/constants.ts +60 -0
- package/src/components/composed/tree/index.ts +51 -0
- package/src/components/composed/tree/tree-atom.ts +590 -0
- package/src/components/composed/tree/tree-context.ts +13 -0
- package/src/components/composed/tree/tree-node.tsx +490 -0
- package/src/components/composed/tree/tree.tsx +286 -0
- package/src/components/composed/tree/type.ts +322 -0
- package/src/components/composed/tree/use-tree-dnd.ts +179 -0
- package/src/components/composed/tree/use-tree-state.ts +105 -0
- package/src/components/composed/tree/use-tree.ts +307 -0
- package/src/components/composed/tree/utils.ts +172 -0
- package/src/components/composed/user-avatar.tsx +11 -96
- package/src/components/docs/component-preview.tsx +11 -11
- package/src/components/user-avatar/__tests__/user-avatar.test.tsx +245 -0
- package/src/components/user-avatar/audio-wave.tsx +22 -0
- package/src/components/user-avatar/component.tsx +152 -0
- package/src/components/user-avatar/fallback.tsx +26 -0
- package/src/components/user-avatar/index.ts +34 -0
- package/src/components/user-avatar/presence-badge.tsx +56 -0
- package/src/components/user-avatar/type.ts +85 -0
- package/src/components/user-avatar/use-user-avatar-state.ts +60 -0
- package/src/components/user-avatar/use-user-avatar.ts +144 -0
- package/src/components/user-avatar/user-avatar-atom.ts +198 -0
- package/src/components/user-avatar/utils.ts +8 -0
- package/src/index.css +211 -153
- package/src/index.ts +35 -2
- package/src/state/exegia-provider.tsx +79 -0
- package/src/state/index.ts +4 -0
- package/src/state/store.ts +19 -0
|
@@ -17,7 +17,18 @@ export interface SidebarResourceMenuControls {
|
|
|
17
17
|
close: () => void;
|
|
18
18
|
rename: () => void;
|
|
19
19
|
}
|
|
20
|
-
|
|
20
|
+
/** Key for one sidebar's state in the store. Any stable string;
|
|
21
|
+
* `useAISidebar` generates one when you don't pass it. */
|
|
22
|
+
export type AISidebarInstanceId = string;
|
|
23
|
+
/** Options for `useAISidebar`. `items`, `activeId` and `expandedIds` are
|
|
24
|
+
* each controlled when passed and hook-owned via their `default*` twin
|
|
25
|
+
* otherwise. */
|
|
26
|
+
export interface UseAISidebarOptions {
|
|
27
|
+
/** Key this sidebar's state under a name your app can address —
|
|
28
|
+
* `useAISidebarState("app-resources")` / `useAISidebarActions(...)` reach
|
|
29
|
+
* it from anywhere under `ExegiaProvider`. Without one the hook generates
|
|
30
|
+
* a key and the state is dropped when the component unmounts. */
|
|
31
|
+
sidebarId?: AISidebarInstanceId;
|
|
21
32
|
items?: SidebarResource[];
|
|
22
33
|
defaultItems?: SidebarResource[];
|
|
23
34
|
onItemsChange?: (items: SidebarResource[]) => void;
|
|
@@ -28,7 +39,86 @@ export interface AISidebarProps {
|
|
|
28
39
|
activeId?: string | null;
|
|
29
40
|
defaultActiveId?: string | null;
|
|
30
41
|
onActiveChange?: (id: string) => void;
|
|
42
|
+
expandedIds?: string[];
|
|
31
43
|
defaultExpandedIds?: string[];
|
|
44
|
+
onExpandedChange?: (ids: string[]) => void;
|
|
45
|
+
}
|
|
46
|
+
/** Everything the sidebar can do, callable from outside the block — a
|
|
47
|
+
* toolbar, a command palette, a route change. Returned by `useAISidebar`
|
|
48
|
+
* and accepted by `<AISidebar controller={…} />`. */
|
|
49
|
+
export interface AISidebarController {
|
|
50
|
+
/** The key this sidebar's state is stored under. */
|
|
51
|
+
sidebarId: AISidebarInstanceId;
|
|
52
|
+
items: SidebarResource[];
|
|
53
|
+
/** Visible rows in order, each with its depth and parent id. */
|
|
54
|
+
flat: FlatResource[];
|
|
55
|
+
getItem: (id: string) => SidebarResource | undefined;
|
|
56
|
+
selectedId: string | null;
|
|
57
|
+
select: (id: string) => void;
|
|
58
|
+
expandedIds: ReadonlySet<string>;
|
|
59
|
+
isExpanded: (id: string) => boolean;
|
|
60
|
+
expand: (id: string) => void;
|
|
61
|
+
collapse: (id: string) => void;
|
|
62
|
+
toggleExpanded: (id: string) => void;
|
|
63
|
+
expandAll: () => void;
|
|
64
|
+
collapseAll: () => void;
|
|
65
|
+
/** Open every ancestor of `id`, leaving the rest of the tree alone. */
|
|
66
|
+
reveal: (id: string) => void;
|
|
67
|
+
/** Roving-focus target. `focus` also moves DOM focus to the row. */
|
|
68
|
+
focusedId: string | null;
|
|
69
|
+
focus: (id: string) => void;
|
|
70
|
+
renamingId: string | null;
|
|
71
|
+
startRename: (id: string) => void;
|
|
72
|
+
cancelRename: () => void;
|
|
73
|
+
/** Commit a rename and leave rename mode. Applied optimistically and
|
|
74
|
+
* rolled back if `onRename` rejects. Blank and unchanged labels are
|
|
75
|
+
* dropped. */
|
|
76
|
+
rename: (id: string, label: string) => void;
|
|
77
|
+
menuOpenId: string | null;
|
|
78
|
+
openMenu: (id: string) => void;
|
|
79
|
+
closeMenu: () => void;
|
|
80
|
+
/** Reorder, applied optimistically and rolled back if `onMove` rejects.
|
|
81
|
+
* Refuses moves the data forbids (into itself, into a non-container). */
|
|
82
|
+
move: (move: SidebarResourceMove) => Promise<void>;
|
|
83
|
+
/** A move is in flight — further moves are refused until it settles. */
|
|
84
|
+
movePending: boolean;
|
|
85
|
+
/** Live-region text for the last move or rename outcome. */
|
|
86
|
+
announcement: string;
|
|
87
|
+
/** Back to the values the sidebar mounted with. */
|
|
88
|
+
reset: () => void;
|
|
89
|
+
/** @internal Row wiring the view threads through — drag state, the
|
|
90
|
+
* hover pill and roving keyboard nav all belong to the rendering. */
|
|
91
|
+
dnd: AISidebarDndState;
|
|
92
|
+
hover: AISidebarHoverState;
|
|
93
|
+
onRowKeyDown: (event: KeyboardEvent<HTMLDivElement>, row: FlatResource) => void;
|
|
94
|
+
setRowRef: (id: string, node: HTMLDivElement | null) => void;
|
|
95
|
+
}
|
|
96
|
+
/** @internal */
|
|
97
|
+
export interface AISidebarDndState extends AISidebarRowDndHandlers {
|
|
98
|
+
draggingId: string | null;
|
|
99
|
+
dropTarget: DropTarget | null;
|
|
100
|
+
onRootDragOver: (event: DragEvent<HTMLDivElement>) => void;
|
|
101
|
+
}
|
|
102
|
+
/** @internal The drag handlers a row needs, stable for the life of the
|
|
103
|
+
* sidebar — they read drag state out of the store when they run instead of
|
|
104
|
+
* closing over it, so handing them to every row costs no re-renders. */
|
|
105
|
+
export interface AISidebarRowDndHandlers {
|
|
106
|
+
onDrop: (event: DragEvent<HTMLDivElement>) => void;
|
|
107
|
+
onRowDragStart: (event: DragEvent<HTMLDivElement>, id: string) => void;
|
|
108
|
+
onRowDragEnd: () => void;
|
|
109
|
+
onRowDragOver: (event: DragEvent<HTMLDivElement>, row: FlatResource) => void;
|
|
110
|
+
}
|
|
111
|
+
/** @internal */
|
|
112
|
+
export interface AISidebarHoverState {
|
|
113
|
+
hoveredId: string | null;
|
|
114
|
+
/** Shared motion layoutId that lets the pill travel between rows. */
|
|
115
|
+
layoutId: string;
|
|
116
|
+
onRowHover: (id: string, hovered: boolean) => void;
|
|
117
|
+
clear: () => void;
|
|
118
|
+
}
|
|
119
|
+
export interface AISidebarProps extends UseAISidebarOptions {
|
|
120
|
+
/** Never set on the data form — `controller` selects the other one. */
|
|
121
|
+
controller?: never;
|
|
32
122
|
renderIcon?: (item: SidebarResource) => ReactNode;
|
|
33
123
|
renderMenu?: (item: SidebarResource, controls: SidebarResourceMenuControls) => ReactNode;
|
|
34
124
|
/**
|
|
@@ -39,6 +129,15 @@ export interface AISidebarProps {
|
|
|
39
129
|
ariaLabel?: string;
|
|
40
130
|
className?: string;
|
|
41
131
|
}
|
|
132
|
+
/** Presentational props, shared by both forms of `<AISidebar>`. */
|
|
133
|
+
export type AISidebarViewProps = Pick<AISidebarProps, "renderIcon" | "renderMenu" | "renderActionsTrigger" | "ariaLabel" | "className">;
|
|
134
|
+
/** Drive the block from a `useAISidebar` controller instead of raw props —
|
|
135
|
+
* the controller carries the data and every handler. */
|
|
136
|
+
export interface AISidebarControllerProps extends AISidebarViewProps {
|
|
137
|
+
controller: AISidebarController;
|
|
138
|
+
}
|
|
139
|
+
/** Either form: raw props, or a `useAISidebar` controller. */
|
|
140
|
+
export type AISidebarComponentProps = AISidebarProps | AISidebarControllerProps;
|
|
42
141
|
export interface FlatResource {
|
|
43
142
|
item: SidebarResource;
|
|
44
143
|
depth: number;
|
|
@@ -48,36 +147,99 @@ export interface DropTarget {
|
|
|
48
147
|
id: string | null;
|
|
49
148
|
position: SidebarResourceDropPosition;
|
|
50
149
|
}
|
|
150
|
+
/** A row takes its place in the tree and nothing else: selection,
|
|
151
|
+
* expansion, focus, rename, drag and hover state all arrive through its own
|
|
152
|
+
* atoms, and the rendering options through the sidebar context. */
|
|
51
153
|
export interface ResourceRowProps {
|
|
52
154
|
row: FlatResource;
|
|
53
|
-
|
|
54
|
-
|
|
55
|
-
|
|
56
|
-
|
|
57
|
-
|
|
58
|
-
|
|
59
|
-
|
|
60
|
-
|
|
61
|
-
|
|
62
|
-
|
|
63
|
-
|
|
64
|
-
|
|
65
|
-
|
|
66
|
-
onMenuOpenChange: (open: boolean) => void;
|
|
67
|
-
onRenameCancel: () => void;
|
|
68
|
-
onRenameCommit: (label: string) => void;
|
|
69
|
-
onRenameStart: () => void;
|
|
70
|
-
onSelect: () => void;
|
|
71
|
-
onToggle: () => void;
|
|
72
|
-
/** Some row in the tree is hovered — mounts the pill fade wrapper. */
|
|
73
|
-
hoverActive?: boolean;
|
|
74
|
-
/** This row owns the sliding hover pill. */
|
|
75
|
-
hoverPill?: boolean;
|
|
76
|
-
/** Shared motion layoutId that lets the pill travel between rows. */
|
|
77
|
-
hoverLayoutId?: string;
|
|
78
|
-
onHoverChange?: (hovered: boolean) => void;
|
|
79
|
-
renderIcon?: (item: SidebarResource) => ReactNode;
|
|
155
|
+
}
|
|
156
|
+
/** @internal What a row needs from the block, threaded through context so
|
|
157
|
+
* the rows stay prop-light.
|
|
158
|
+
*
|
|
159
|
+
* Deliberately free of sidebar state and of the controller. Rows read state
|
|
160
|
+
* from per-row atoms, so this value keeps its identity for the life of the
|
|
161
|
+
* sidebar and hovering or expanding one row no longer re-renders every row
|
|
162
|
+
* through context. */
|
|
163
|
+
export interface AISidebarContextValue {
|
|
164
|
+
sidebarId: AISidebarInstanceId;
|
|
165
|
+
/** Shared motion layoutId that lets the hover pill travel between rows. */
|
|
166
|
+
hoverLayoutId: string;
|
|
167
|
+
renderIcon?: AISidebarProps["renderIcon"];
|
|
80
168
|
renderMenu?: AISidebarProps["renderMenu"];
|
|
81
169
|
renderActionsTrigger?: AISidebarProps["renderActionsTrigger"];
|
|
82
|
-
|
|
170
|
+
/** Registers the row's DOM node with the block, which owns the ref map —
|
|
171
|
+
* DOM nodes never go in the store. */
|
|
172
|
+
setRowRef: (id: string, node: HTMLDivElement | null) => void;
|
|
173
|
+
onRowKeyDown: (event: KeyboardEvent<HTMLDivElement>, row: FlatResource) => void;
|
|
174
|
+
onRowHover: (id: string, hovered: boolean) => void;
|
|
175
|
+
/** Closing returns DOM focus to the row that owned the menu, so it goes
|
|
176
|
+
* through the block rather than the store. */
|
|
177
|
+
closeMenu: () => void;
|
|
178
|
+
dnd: AISidebarRowDndHandlers;
|
|
179
|
+
}
|
|
180
|
+
/** Everything observable about one sidebar, for consumers reading it by id. */
|
|
181
|
+
export interface AISidebarState {
|
|
182
|
+
items: SidebarResource[];
|
|
183
|
+
/** Visible rows in order, each with its depth and parent id. */
|
|
184
|
+
flat: FlatResource[];
|
|
185
|
+
selectedId: string | null;
|
|
186
|
+
expandedIds: ReadonlySet<string>;
|
|
187
|
+
focusedId: string | null;
|
|
188
|
+
renamingId: string | null;
|
|
189
|
+
menuOpenId: string | null;
|
|
190
|
+
draggingId: string | null;
|
|
191
|
+
dropTarget: DropTarget | null;
|
|
192
|
+
hoveredId: string | null;
|
|
193
|
+
/** A move is in flight — further moves are refused until it settles. */
|
|
194
|
+
movePending: boolean;
|
|
195
|
+
/** Live-region text for the last move or rename outcome. */
|
|
196
|
+
announcement: string;
|
|
197
|
+
}
|
|
198
|
+
/** Everything doable to one sidebar from outside its component. */
|
|
199
|
+
export interface AISidebarActions {
|
|
200
|
+
select: (id: string) => void;
|
|
201
|
+
expand: (id: string) => void;
|
|
202
|
+
collapse: (id: string) => void;
|
|
203
|
+
toggleExpanded: (id: string) => void;
|
|
204
|
+
expandAll: () => void;
|
|
205
|
+
collapseAll: () => void;
|
|
206
|
+
reveal: (id: string) => void;
|
|
207
|
+
/** Moves the roving-focus target. DOM focus follows only for callers that
|
|
208
|
+
* hold the controller — the ref map lives in the block, not the store. */
|
|
209
|
+
focus: (id: string) => void;
|
|
210
|
+
startRename: (id: string) => void;
|
|
211
|
+
cancelRename: () => void;
|
|
212
|
+
rename: (id: string, label: string) => void;
|
|
213
|
+
openMenu: (id: string) => void;
|
|
214
|
+
closeMenu: () => void;
|
|
215
|
+
move: (move: SidebarResourceMove) => Promise<void>;
|
|
216
|
+
setItems: (items: SidebarResource[]) => void;
|
|
217
|
+
reset: () => void;
|
|
218
|
+
}
|
|
219
|
+
/** @internal Projection of `useAISidebar`'s options — primitives only, so
|
|
220
|
+
* the store write runs once per real change instead of once per render. */
|
|
221
|
+
export interface AISidebarConfig {
|
|
222
|
+
controlsItems: boolean;
|
|
223
|
+
controlsActiveId: boolean;
|
|
224
|
+
controlsExpandedIds: boolean;
|
|
225
|
+
}
|
|
226
|
+
/** @internal Latest option callbacks. Only write atoms read this, so it can
|
|
227
|
+
* be refreshed every commit without re-rendering anything. */
|
|
228
|
+
export interface AISidebarHandlers {
|
|
229
|
+
onItemsChange?: (items: SidebarResource[]) => void;
|
|
230
|
+
onMove?: (move: SidebarResourceMove) => void | Promise<void>;
|
|
231
|
+
onMoveError?: (error: unknown, move: SidebarResourceMove) => void;
|
|
232
|
+
onRename?: (item: SidebarResource, label: string) => void | Promise<void>;
|
|
233
|
+
onActiveChange?: (id: string) => void;
|
|
234
|
+
onExpandedChange?: (ids: string[]) => void;
|
|
235
|
+
}
|
|
236
|
+
/** @internal What an instance starts from, replayed by
|
|
237
|
+
* `resetAISidebarAtom`. */
|
|
238
|
+
export interface AISidebarSeed {
|
|
239
|
+
items: SidebarResource[];
|
|
240
|
+
/** Hook-owned selection — the `defaultActiveId`, never the controlled
|
|
241
|
+
* `activeId`. */
|
|
242
|
+
activeId: string | null;
|
|
243
|
+
focusedId: string | null;
|
|
244
|
+
expandedIds: string[];
|
|
83
245
|
}
|
|
@@ -0,0 +1,29 @@
|
|
|
1
|
+
import { AISidebarActions, AISidebarInstanceId, AISidebarState } from './type.ts';
|
|
2
|
+
/**
|
|
3
|
+
* Read the sidebar registered under `sidebarId` from anywhere below
|
|
4
|
+
* `ExegiaProvider` — no controller, no props, no provider of its own.
|
|
5
|
+
*
|
|
6
|
+
* ```tsx
|
|
7
|
+
* const { selectedId, movePending } = useAISidebarState("app-resources")
|
|
8
|
+
* ```
|
|
9
|
+
*
|
|
10
|
+
* This returns the whole state object, so the caller re-renders on any
|
|
11
|
+
* change. A component that reads one field should subscribe to that field's
|
|
12
|
+
* atom instead: `useAtomValue(aiSidebarActiveIdAtom("app-resources"))`.
|
|
13
|
+
*/
|
|
14
|
+
export declare function useAISidebarState(sidebarId: AISidebarInstanceId): AISidebarState;
|
|
15
|
+
/**
|
|
16
|
+
* Drive the sidebar registered under `sidebarId` from anywhere. Writes only —
|
|
17
|
+
* the caller never re-renders when the sidebar changes, so this is what a
|
|
18
|
+
* command palette, a keyboard shortcut or a route guard should reach for.
|
|
19
|
+
*
|
|
20
|
+
* `focus` and `closeMenu` move the store's roving target; DOM focus follows
|
|
21
|
+
* only for callers that hold the controller, because the row refs live in
|
|
22
|
+
* the block rather than the store.
|
|
23
|
+
*
|
|
24
|
+
* ```tsx
|
|
25
|
+
* const resources = useAISidebarActions("app-resources")
|
|
26
|
+
* <Button onClick={resources.collapseAll}>Collapse all</Button>
|
|
27
|
+
* ```
|
|
28
|
+
*/
|
|
29
|
+
export declare function useAISidebarActions(sidebarId: AISidebarInstanceId): AISidebarActions;
|
|
@@ -1,31 +1,27 @@
|
|
|
1
|
-
import {
|
|
2
|
-
|
|
3
|
-
|
|
4
|
-
|
|
5
|
-
|
|
6
|
-
|
|
7
|
-
|
|
8
|
-
|
|
9
|
-
|
|
10
|
-
|
|
11
|
-
|
|
12
|
-
|
|
13
|
-
|
|
14
|
-
|
|
15
|
-
|
|
16
|
-
|
|
17
|
-
|
|
18
|
-
|
|
19
|
-
|
|
20
|
-
|
|
21
|
-
|
|
22
|
-
|
|
23
|
-
|
|
24
|
-
|
|
25
|
-
|
|
26
|
-
|
|
27
|
-
|
|
28
|
-
commitRename: (row: FlatResource, label: string) => void;
|
|
29
|
-
handleMenuOpenChange: (row: FlatResource, open: boolean) => void;
|
|
30
|
-
setRowRef: (id: string, node: HTMLDivElement | null) => void;
|
|
31
|
-
};
|
|
1
|
+
import { AISidebarController, UseAISidebarOptions } from './type.ts';
|
|
2
|
+
export type { UseAISidebarOptions };
|
|
3
|
+
/**
|
|
4
|
+
* The AI sidebar's headless controller — every behaviour the block
|
|
5
|
+
* performs, callable from outside it: select, expand/collapse (one row,
|
|
6
|
+
* every row, or just the ancestors of one), move focus, rename, open a
|
|
7
|
+
* row's action menu, reorder.
|
|
8
|
+
*
|
|
9
|
+
* `items`, `activeId` and `expandedIds` are each controlled when passed
|
|
10
|
+
* and hook-owned via their `default*` twin otherwise. Reorder and rename
|
|
11
|
+
* are applied to the data optimistically and rolled back if
|
|
12
|
+
* `onMove`/`onRename` rejects, so a consumer never reduces the tree
|
|
13
|
+
* itself — `moveResource` and `renameResource` are exported for the ones
|
|
14
|
+
* who keep their data elsewhere.
|
|
15
|
+
*
|
|
16
|
+
* ```tsx
|
|
17
|
+
* const sidebar = useAISidebar({ defaultItems: resources })
|
|
18
|
+
* <AISidebar controller={sidebar} />
|
|
19
|
+
* <Button onClick={sidebar.collapseAll}>Collapse all</Button>
|
|
20
|
+
* ```
|
|
21
|
+
*
|
|
22
|
+
* State lives in Jotai atoms keyed by `sidebarId`, so anything under
|
|
23
|
+
* `ExegiaProvider` can drive this sidebar without the controller — name it
|
|
24
|
+
* and reach for `useAISidebarState(sidebarId)` /
|
|
25
|
+
* `useAISidebarActions(sidebarId)` elsewhere.
|
|
26
|
+
*/
|
|
27
|
+
export declare function useAISidebar(options: UseAISidebarOptions): AISidebarController;
|
|
@@ -4,8 +4,13 @@ export declare const ROW_REVEAL: {
|
|
|
4
4
|
readonly ease: readonly [0.16, 1, 0.3, 1];
|
|
5
5
|
};
|
|
6
6
|
export declare function canContain(item: SidebarResource): boolean;
|
|
7
|
-
export declare function flattenResources(items: SidebarResource[], expanded:
|
|
7
|
+
export declare function flattenResources(items: SidebarResource[], expanded: ReadonlySet<string>, depth?: number, parentId?: string | null): FlatResource[];
|
|
8
8
|
export declare function findResource(items: SidebarResource[], id: string): SidebarResource | undefined;
|
|
9
|
+
/** Ids of every ancestor of `id` (nearest last); empty when absent. */
|
|
10
|
+
export declare function ancestorIdsOf(items: SidebarResource[], id: string): string[];
|
|
11
|
+
/** Ids of every row that can hold children and has some — the set
|
|
12
|
+
* `expandAll` opens. */
|
|
13
|
+
export declare function expandableIdsOf(items: SidebarResource[]): string[];
|
|
9
14
|
export declare function containsResource(item: SidebarResource, id: string): boolean;
|
|
10
15
|
export declare function removeResource(items: SidebarResource[], id: string): {
|
|
11
16
|
items: SidebarResource[];
|
|
@@ -0,0 +1,7 @@
|
|
|
1
|
+
export { ProfileCardBlock, defaultProfileCardItems, } from './profile-card-block';
|
|
2
|
+
export type { ProfileCardBlockProps } from './profile-card-block';
|
|
3
|
+
export { useProfileCard } from './use-profile-card';
|
|
4
|
+
export type { ProfileCardBinding, UseProfileCardOptions } from './use-profile-card';
|
|
5
|
+
export { useProfileCardActions, useProfileCardState, } from './use-profile-card-state';
|
|
6
|
+
export { profileCardBusyAtom, profileCardCollapsedAtom, profileCardMenuOpenAtom, profileCardPendingActionIdAtom, profileCardStateAtom, profileCardVariantAtom, removeProfileCardInstance, resetProfileCardAtom, selectProfileCardActionAtom, setProfileCardMenuOpenAtom, setProfileCardVariantAtom, toggleProfileCardVariantAtom, } from './profile-card-atom';
|
|
7
|
+
export type * from './type';
|
|
@@ -0,0 +1,68 @@
|
|
|
1
|
+
import { ProfileCardAction, ProfileCardConfig, ProfileCardHandlers, ProfileCardInstanceId, ProfileCardState, ProfileCardVariant } from './type';
|
|
2
|
+
type Family<AtomType> = ((id: ProfileCardInstanceId) => AtomType) & {
|
|
3
|
+
remove: (id: ProfileCardInstanceId) => void;
|
|
4
|
+
};
|
|
5
|
+
export declare const profileCardVariantAtom: Family<import('jotai').PrimitiveAtom<ProfileCardVariant> & {
|
|
6
|
+
init: ProfileCardVariant;
|
|
7
|
+
}>;
|
|
8
|
+
export declare const profileCardMenuOpenAtom: Family<import('jotai').PrimitiveAtom<boolean> & {
|
|
9
|
+
init: boolean;
|
|
10
|
+
}>;
|
|
11
|
+
export declare const profileCardPendingActionIdAtom: Family<import('jotai').PrimitiveAtom<string | null> & {
|
|
12
|
+
init: string | null;
|
|
13
|
+
}>;
|
|
14
|
+
/** @internal */
|
|
15
|
+
export declare const profileCardConfigAtom: Family<import('jotai').PrimitiveAtom<ProfileCardConfig> & {
|
|
16
|
+
init: ProfileCardConfig;
|
|
17
|
+
}>;
|
|
18
|
+
/** @internal */
|
|
19
|
+
export declare const profileCardHandlersAtom: Family<import('jotai').PrimitiveAtom<ProfileCardHandlers> & {
|
|
20
|
+
init: ProfileCardHandlers;
|
|
21
|
+
}>;
|
|
22
|
+
export declare const profileCardCollapsedAtom: Family<import('jotai').Atom<boolean>>;
|
|
23
|
+
export declare const profileCardBusyAtom: Family<import('jotai').Atom<boolean>>;
|
|
24
|
+
/** Whole-state read for callers that want the object; the field atoms are
|
|
25
|
+
* cheaper for components that watch one thing. */
|
|
26
|
+
export declare const profileCardStateAtom: Family<import('jotai').Atom<ProfileCardState>>;
|
|
27
|
+
/** Reports through `onVariantChange` always; writes the store only when no
|
|
28
|
+
* `variant` prop controls the card — the prop is truth then. */
|
|
29
|
+
export declare const setProfileCardVariantAtom: Family<import('jotai').WritableAtom<null, [variant: ProfileCardVariant], void> & {
|
|
30
|
+
init: null;
|
|
31
|
+
}>;
|
|
32
|
+
export declare const toggleProfileCardVariantAtom: Family<import('jotai').WritableAtom<null, [], void> & {
|
|
33
|
+
init: null;
|
|
34
|
+
}>;
|
|
35
|
+
/** Inert while an `open` prop controls the menu. */
|
|
36
|
+
export declare const setProfileCardMenuOpenAtom: Family<import('jotai').WritableAtom<null, [open: boolean], void> & {
|
|
37
|
+
init: null;
|
|
38
|
+
}>;
|
|
39
|
+
/**
|
|
40
|
+
* Run an action's `onSelect`. A returned promise marks the card busy until it
|
|
41
|
+
* settles; a rejection goes to `onError` and the card leaves its busy state
|
|
42
|
+
* either way. Because the pending id is a store value, it survives the card
|
|
43
|
+
* unmounting mid-flight (sign-out typically unmounts it) — the settle just
|
|
44
|
+
* writes to an instance nobody renders any more.
|
|
45
|
+
*/
|
|
46
|
+
export declare const selectProfileCardActionAtom: Family<import('jotai').WritableAtom<null, [action: ProfileCardAction], void> & {
|
|
47
|
+
init: null;
|
|
48
|
+
}>;
|
|
49
|
+
/** @internal Projection of the mounted component's controlled props. */
|
|
50
|
+
export declare const projectProfileCardPropsAtom: Family<import('jotai').WritableAtom<null, [config: ProfileCardConfig, variant: ProfileCardVariant | undefined, menuOpen: boolean | undefined], void> & {
|
|
51
|
+
init: null;
|
|
52
|
+
}>;
|
|
53
|
+
/** @internal */
|
|
54
|
+
export declare const setProfileCardHandlersAtom: Family<import('jotai').WritableAtom<null, [handlers: ProfileCardHandlers], void> & {
|
|
55
|
+
init: null;
|
|
56
|
+
}>;
|
|
57
|
+
/** @internal Seed the uncontrolled variant on mount without firing
|
|
58
|
+
* `onVariantChange`. */
|
|
59
|
+
export declare const seedProfileCardVariantAtom: Family<import('jotai').WritableAtom<null, [variant: ProfileCardVariant], void> & {
|
|
60
|
+
init: null;
|
|
61
|
+
}>;
|
|
62
|
+
export declare const resetProfileCardAtom: Family<import('jotai').WritableAtom<null, [], void> & {
|
|
63
|
+
init: null;
|
|
64
|
+
}>;
|
|
65
|
+
/** Forget a card entirely — every family drops the key so the store can
|
|
66
|
+
* release its state. Call on teardown of a named instance. */
|
|
67
|
+
export declare function removeProfileCardInstance(id: ProfileCardInstanceId): void;
|
|
68
|
+
export {};
|
|
@@ -1,42 +1,7 @@
|
|
|
1
1
|
import { DropdownMenuContent, MenuPrimitive } from '../../ui/menu';
|
|
2
|
+
import { ProfileCardItem, ProfileCardUser, ProfileCardVariant } from './type';
|
|
2
3
|
import * as React from "react";
|
|
3
|
-
|
|
4
|
-
export interface ProfileCardUser {
|
|
5
|
-
name: string;
|
|
6
|
-
/** Secondary line under the name — a handle, an email, a role. */
|
|
7
|
-
username?: string;
|
|
8
|
-
/** Avatar image URL. Falls back to the initials when absent or broken. */
|
|
9
|
-
avatar?: string;
|
|
10
|
-
/** Fallback initials. Derived from `name` when omitted. */
|
|
11
|
-
initials?: string;
|
|
12
|
-
}
|
|
13
|
-
/** An actionable row of the menu. */
|
|
14
|
-
export interface ProfileCardAction {
|
|
15
|
-
type?: "item";
|
|
16
|
-
id: string;
|
|
17
|
-
label: string;
|
|
18
|
-
icon?: React.ReactNode;
|
|
19
|
-
/** Right-aligned hint, e.g. "⌘K". Purely decorative — bind the key yourself. */
|
|
20
|
-
shortcut?: string;
|
|
21
|
-
disabled?: boolean;
|
|
22
|
-
variant?: "default" | "destructive";
|
|
23
|
-
/** Returning a promise puts the card in its loading state until it settles. */
|
|
24
|
-
onSelect?: () => void | Promise<void>;
|
|
25
|
-
}
|
|
26
|
-
/** A heading over the rows that follow it, up to the next separator. */
|
|
27
|
-
export interface ProfileCardLabel {
|
|
28
|
-
type: "label";
|
|
29
|
-
label: string;
|
|
30
|
-
}
|
|
31
|
-
/** A rule between two sections. */
|
|
32
|
-
export interface ProfileCardSeparator {
|
|
33
|
-
type: "separator";
|
|
34
|
-
}
|
|
35
|
-
/**
|
|
36
|
-
* One entry of `items`. Authored flat; the block renders each run between
|
|
37
|
-
* separators as its own menu group so a label actually names its section.
|
|
38
|
-
*/
|
|
39
|
-
export type ProfileCardItem = ProfileCardAction | ProfileCardLabel | ProfileCardSeparator;
|
|
4
|
+
export type { ProfileCardAction, ProfileCardActions, ProfileCardInstanceId, ProfileCardItem, ProfileCardLabel, ProfileCardSeparator, ProfileCardState, ProfileCardUser, ProfileCardVariant, } from './type';
|
|
40
5
|
/**
|
|
41
6
|
* The menu the card ships with. Spread it to keep the shape and attach your
|
|
42
7
|
* own handlers, or ignore it and pass `items` of your own.
|
|
@@ -62,6 +27,31 @@ export interface ProfileCardBlockProps {
|
|
|
62
27
|
* width, so `align` stops mattering horizontally.
|
|
63
28
|
*/
|
|
64
29
|
menuWidth?: "content" | "card";
|
|
30
|
+
/**
|
|
31
|
+
* `expanded` shows avatar, name and handle; `collapsed` folds the card to
|
|
32
|
+
* its avatar — for an icon-collapsed sidebar rail. The fold animates: the
|
|
33
|
+
* identity lines and chevron slide to zero width, the avatar stays put.
|
|
34
|
+
* Controlled when passed. Left unset, the card follows the `AnimatedPanel`
|
|
35
|
+
* it sits in (a `SidebarBlock` footer folds with the rail on its own), and
|
|
36
|
+
* outside a panel starts from `defaultVariant`.
|
|
37
|
+
*/
|
|
38
|
+
variant?: ProfileCardVariant;
|
|
39
|
+
defaultVariant?: ProfileCardVariant;
|
|
40
|
+
onVariantChange?: (variant: ProfileCardVariant) => void;
|
|
41
|
+
/**
|
|
42
|
+
* Name this card's slice of the store so `useProfileCardState(id)` /
|
|
43
|
+
* `useProfileCardActions(id)` can read or drive it (fold it, open its
|
|
44
|
+
* menu) from anywhere under `ExegiaProvider`. Unnamed cards key off
|
|
45
|
+
* `useId` and are dropped on unmount.
|
|
46
|
+
*/
|
|
47
|
+
profileCardId?: string;
|
|
48
|
+
/**
|
|
49
|
+
* Presence badge on the avatar — overrides `user.presence`. Name the avatar
|
|
50
|
+
* with `avatarId` and `useUserAvatarActions(id).setPresence()` can flip it
|
|
51
|
+
* from a socket handler instead.
|
|
52
|
+
*/
|
|
53
|
+
presence?: ProfileCardUser["presence"];
|
|
54
|
+
avatarId?: string;
|
|
65
55
|
/**
|
|
66
56
|
* Emit cuelume press/release on the card and play the open/close cues.
|
|
67
57
|
* Inert unless the app opts into interaction sound via `bindSounds()`.
|
|
@@ -78,5 +68,4 @@ export interface ProfileCardBlockProps {
|
|
|
78
68
|
* popup is a plain action menu. `items` is the whole menu — a flat list of
|
|
79
69
|
* actions, separators and labels — defaulting to `defaultProfileCardItems`.
|
|
80
70
|
*/
|
|
81
|
-
export declare function ProfileCardBlock({ user, items, align, side, sideOffset, menuWidth, open, defaultOpen, onOpenChange, sound, onError, className, }: ProfileCardBlockProps): React.ReactElement;
|
|
82
|
-
export {};
|
|
71
|
+
export declare function ProfileCardBlock({ user, items, align, side, sideOffset, menuWidth, variant: variantProp, defaultVariant, onVariantChange, profileCardId, presence, avatarId, open, defaultOpen, onOpenChange, sound, onError, className, }: ProfileCardBlockProps): React.ReactElement;
|
|
@@ -0,0 +1,80 @@
|
|
|
1
|
+
import { UserPresence } from '../../user-avatar';
|
|
2
|
+
import type * as React from "react";
|
|
3
|
+
/** The identity shown on the card. */
|
|
4
|
+
export interface ProfileCardUser {
|
|
5
|
+
name: string;
|
|
6
|
+
/** Secondary line under the name — a handle, an email, a role. */
|
|
7
|
+
username?: string;
|
|
8
|
+
/** Avatar image URL. Falls back to the initials when absent or broken. */
|
|
9
|
+
avatar?: string;
|
|
10
|
+
/** Fallback initials. Derived from `name` when omitted. */
|
|
11
|
+
initials?: string;
|
|
12
|
+
/** Presence badge on the avatar. Omitted, no badge. */
|
|
13
|
+
presence?: UserPresence;
|
|
14
|
+
}
|
|
15
|
+
/** An actionable row of the menu. */
|
|
16
|
+
export interface ProfileCardAction {
|
|
17
|
+
type?: "item";
|
|
18
|
+
id: string;
|
|
19
|
+
label: string;
|
|
20
|
+
icon?: React.ReactNode;
|
|
21
|
+
/** Right-aligned hint, e.g. "⌘K". Purely decorative — bind the key yourself. */
|
|
22
|
+
shortcut?: string;
|
|
23
|
+
disabled?: boolean;
|
|
24
|
+
variant?: "default" | "destructive";
|
|
25
|
+
/** Returning a promise puts the card in its loading state until it settles. */
|
|
26
|
+
onSelect?: () => void | Promise<void>;
|
|
27
|
+
}
|
|
28
|
+
/** A heading over the rows that follow it, up to the next separator. */
|
|
29
|
+
export interface ProfileCardLabel {
|
|
30
|
+
type: "label";
|
|
31
|
+
label: string;
|
|
32
|
+
}
|
|
33
|
+
/** A rule between two sections. */
|
|
34
|
+
export interface ProfileCardSeparator {
|
|
35
|
+
type: "separator";
|
|
36
|
+
}
|
|
37
|
+
/**
|
|
38
|
+
* One entry of `items`. Authored flat; the block renders each run between
|
|
39
|
+
* separators as its own menu group so a label actually names its section.
|
|
40
|
+
*/
|
|
41
|
+
export type ProfileCardItem = ProfileCardAction | ProfileCardLabel | ProfileCardSeparator;
|
|
42
|
+
/** `expanded` shows avatar, name and handle; `collapsed` folds to the avatar
|
|
43
|
+
* alone — for an icon-collapsed sidebar rail. */
|
|
44
|
+
export type ProfileCardVariant = "expanded" | "collapsed";
|
|
45
|
+
/** Key for one card's state in the store. Any stable string; `useProfileCard`
|
|
46
|
+
* generates one when the component does not name itself. */
|
|
47
|
+
export type ProfileCardInstanceId = string;
|
|
48
|
+
/** Everything the store knows about one card. */
|
|
49
|
+
export interface ProfileCardState {
|
|
50
|
+
variant: ProfileCardVariant;
|
|
51
|
+
menuOpen: boolean;
|
|
52
|
+
/** Id of the action whose promise is in flight, `null` while idle. */
|
|
53
|
+
pendingActionId: string | null;
|
|
54
|
+
/** `pendingActionId !== null` — the trigger is disabled and shows a spinner. */
|
|
55
|
+
busy: boolean;
|
|
56
|
+
}
|
|
57
|
+
/** Write-only handles onto one card. Nothing here re-renders the caller. */
|
|
58
|
+
export interface ProfileCardActions {
|
|
59
|
+
setVariant: (variant: ProfileCardVariant) => void;
|
|
60
|
+
toggleVariant: () => void;
|
|
61
|
+
/** Convenience over `setVariant`. */
|
|
62
|
+
collapse: () => void;
|
|
63
|
+
expand: () => void;
|
|
64
|
+
setMenuOpen: (open: boolean) => void;
|
|
65
|
+
openMenu: () => void;
|
|
66
|
+
closeMenu: () => void;
|
|
67
|
+
reset: () => void;
|
|
68
|
+
}
|
|
69
|
+
/** @internal Which fields the mounted component controls from props. The
|
|
70
|
+
* store must never overwrite a controlled value. */
|
|
71
|
+
export interface ProfileCardConfig {
|
|
72
|
+
controlsVariant: boolean;
|
|
73
|
+
controlsMenuOpen: boolean;
|
|
74
|
+
}
|
|
75
|
+
/** @internal Latest option callbacks. Only write atoms read this, so it can
|
|
76
|
+
* be refreshed every commit without re-rendering anything. */
|
|
77
|
+
export interface ProfileCardHandlers {
|
|
78
|
+
onVariantChange?: (variant: ProfileCardVariant) => void;
|
|
79
|
+
onError?: (error: unknown) => void;
|
|
80
|
+
}
|
|
@@ -0,0 +1,24 @@
|
|
|
1
|
+
import { ProfileCardActions, ProfileCardInstanceId, ProfileCardState } from './type';
|
|
2
|
+
/**
|
|
3
|
+
* Read the card registered under `profileCardId` from anywhere below
|
|
4
|
+
* `ExegiaProvider` — no props, no ref, no provider of its own.
|
|
5
|
+
*
|
|
6
|
+
* ```tsx
|
|
7
|
+
* const { variant, busy } = useProfileCardState("account")
|
|
8
|
+
* ```
|
|
9
|
+
*
|
|
10
|
+
* Returns the whole state object, so the caller re-renders on any change. A
|
|
11
|
+
* component that watches one field should subscribe to that atom instead:
|
|
12
|
+
* `useAtomValue(profileCardVariantAtom("account"))`.
|
|
13
|
+
*/
|
|
14
|
+
export declare function useProfileCardState(profileCardId: ProfileCardInstanceId): ProfileCardState;
|
|
15
|
+
/**
|
|
16
|
+
* Write-only handles onto the card registered under `profileCardId`. Nothing
|
|
17
|
+
* here subscribes, so a rail toggle can fold the card without re-rendering
|
|
18
|
+
* when the card changes.
|
|
19
|
+
*
|
|
20
|
+
* ```tsx
|
|
21
|
+
* const { collapse, expand } = useProfileCardActions("account")
|
|
22
|
+
* ```
|
|
23
|
+
*/
|
|
24
|
+
export declare function useProfileCardActions(profileCardId: ProfileCardInstanceId): ProfileCardActions;
|
|
@@ -0,0 +1,34 @@
|
|
|
1
|
+
import { ProfileCardAction, ProfileCardInstanceId, ProfileCardVariant } from './type';
|
|
2
|
+
export interface UseProfileCardOptions {
|
|
3
|
+
profileCardId?: ProfileCardInstanceId;
|
|
4
|
+
/** Controlled fold. `undefined` leaves the store (and `defaultVariant`) in charge. */
|
|
5
|
+
variant?: ProfileCardVariant;
|
|
6
|
+
defaultVariant?: ProfileCardVariant;
|
|
7
|
+
onVariantChange?: (variant: ProfileCardVariant) => void;
|
|
8
|
+
/** Controlled menu. */
|
|
9
|
+
open?: boolean;
|
|
10
|
+
defaultOpen?: boolean;
|
|
11
|
+
onError?: (error: unknown) => void;
|
|
12
|
+
}
|
|
13
|
+
export interface ProfileCardBinding {
|
|
14
|
+
profileCardId: ProfileCardInstanceId;
|
|
15
|
+
variant: ProfileCardVariant;
|
|
16
|
+
collapsed: boolean;
|
|
17
|
+
menuOpen: boolean;
|
|
18
|
+
busy: boolean;
|
|
19
|
+
/** Hand to the menu's `onOpenChange` (first argument). Stable. */
|
|
20
|
+
setMenuOpen: (open: boolean) => void;
|
|
21
|
+
/** Run an action: `onSelect`, promise → busy, rejection → `onError`. Stable. */
|
|
22
|
+
select: (action: ProfileCardAction) => void;
|
|
23
|
+
}
|
|
24
|
+
/**
|
|
25
|
+
* Binds one profile card to its slice of the store: projects the controlled
|
|
26
|
+
* `variant` / `open` props (one-way, with write gates so the store never
|
|
27
|
+
* overwrites a prop), publishes the latest handlers, and returns the values
|
|
28
|
+
* the component renders from.
|
|
29
|
+
*
|
|
30
|
+
* Unnamed cards key off `useId` and are dropped on unmount; a named
|
|
31
|
+
* `profileCardId` outlives its component, so a fold set from elsewhere
|
|
32
|
+
* (`useProfileCardActions(id).collapse()`) survives a route change.
|
|
33
|
+
*/
|
|
34
|
+
export declare function useProfileCard(options: UseProfileCardOptions): ProfileCardBinding;
|