@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
|
@@ -23,7 +23,19 @@ export interface SidebarResourceMenuControls {
|
|
|
23
23
|
rename: () => void
|
|
24
24
|
}
|
|
25
25
|
|
|
26
|
-
|
|
26
|
+
/** Key for one sidebar's state in the store. Any stable string;
|
|
27
|
+
* `useAISidebar` generates one when you don't pass it. */
|
|
28
|
+
export type AISidebarInstanceId = string
|
|
29
|
+
|
|
30
|
+
/** Options for `useAISidebar`. `items`, `activeId` and `expandedIds` are
|
|
31
|
+
* each controlled when passed and hook-owned via their `default*` twin
|
|
32
|
+
* otherwise. */
|
|
33
|
+
export interface UseAISidebarOptions {
|
|
34
|
+
/** Key this sidebar's state under a name your app can address —
|
|
35
|
+
* `useAISidebarState("app-resources")` / `useAISidebarActions(...)` reach
|
|
36
|
+
* it from anywhere under `ExegiaProvider`. Without one the hook generates
|
|
37
|
+
* a key and the state is dropped when the component unmounts. */
|
|
38
|
+
sidebarId?: AISidebarInstanceId
|
|
27
39
|
items?: SidebarResource[]
|
|
28
40
|
defaultItems?: SidebarResource[]
|
|
29
41
|
onItemsChange?: (items: SidebarResource[]) => void
|
|
@@ -34,7 +46,103 @@ export interface AISidebarProps {
|
|
|
34
46
|
activeId?: string | null
|
|
35
47
|
defaultActiveId?: string | null
|
|
36
48
|
onActiveChange?: (id: string) => void
|
|
49
|
+
expandedIds?: string[]
|
|
37
50
|
defaultExpandedIds?: string[]
|
|
51
|
+
onExpandedChange?: (ids: string[]) => void
|
|
52
|
+
}
|
|
53
|
+
|
|
54
|
+
/** Everything the sidebar can do, callable from outside the block — a
|
|
55
|
+
* toolbar, a command palette, a route change. Returned by `useAISidebar`
|
|
56
|
+
* and accepted by `<AISidebar controller={…} />`. */
|
|
57
|
+
export interface AISidebarController {
|
|
58
|
+
/** The key this sidebar's state is stored under. */
|
|
59
|
+
sidebarId: AISidebarInstanceId
|
|
60
|
+
items: SidebarResource[]
|
|
61
|
+
/** Visible rows in order, each with its depth and parent id. */
|
|
62
|
+
flat: FlatResource[]
|
|
63
|
+
getItem: (id: string) => SidebarResource | undefined
|
|
64
|
+
|
|
65
|
+
selectedId: string | null
|
|
66
|
+
select: (id: string) => void
|
|
67
|
+
|
|
68
|
+
expandedIds: ReadonlySet<string>
|
|
69
|
+
isExpanded: (id: string) => boolean
|
|
70
|
+
expand: (id: string) => void
|
|
71
|
+
collapse: (id: string) => void
|
|
72
|
+
toggleExpanded: (id: string) => void
|
|
73
|
+
expandAll: () => void
|
|
74
|
+
collapseAll: () => void
|
|
75
|
+
/** Open every ancestor of `id`, leaving the rest of the tree alone. */
|
|
76
|
+
reveal: (id: string) => void
|
|
77
|
+
|
|
78
|
+
/** Roving-focus target. `focus` also moves DOM focus to the row. */
|
|
79
|
+
focusedId: string | null
|
|
80
|
+
focus: (id: string) => void
|
|
81
|
+
|
|
82
|
+
renamingId: string | null
|
|
83
|
+
startRename: (id: string) => void
|
|
84
|
+
cancelRename: () => void
|
|
85
|
+
/** Commit a rename and leave rename mode. Applied optimistically and
|
|
86
|
+
* rolled back if `onRename` rejects. Blank and unchanged labels are
|
|
87
|
+
* dropped. */
|
|
88
|
+
rename: (id: string, label: string) => void
|
|
89
|
+
|
|
90
|
+
menuOpenId: string | null
|
|
91
|
+
openMenu: (id: string) => void
|
|
92
|
+
closeMenu: () => void
|
|
93
|
+
|
|
94
|
+
/** Reorder, applied optimistically and rolled back if `onMove` rejects.
|
|
95
|
+
* Refuses moves the data forbids (into itself, into a non-container). */
|
|
96
|
+
move: (move: SidebarResourceMove) => Promise<void>
|
|
97
|
+
/** A move is in flight — further moves are refused until it settles. */
|
|
98
|
+
movePending: boolean
|
|
99
|
+
|
|
100
|
+
/** Live-region text for the last move or rename outcome. */
|
|
101
|
+
announcement: string
|
|
102
|
+
|
|
103
|
+
/** Back to the values the sidebar mounted with. */
|
|
104
|
+
reset: () => void
|
|
105
|
+
|
|
106
|
+
/** @internal Row wiring the view threads through — drag state, the
|
|
107
|
+
* hover pill and roving keyboard nav all belong to the rendering. */
|
|
108
|
+
dnd: AISidebarDndState
|
|
109
|
+
hover: AISidebarHoverState
|
|
110
|
+
onRowKeyDown: (
|
|
111
|
+
event: KeyboardEvent<HTMLDivElement>,
|
|
112
|
+
row: FlatResource
|
|
113
|
+
) => void
|
|
114
|
+
setRowRef: (id: string, node: HTMLDivElement | null) => void
|
|
115
|
+
}
|
|
116
|
+
|
|
117
|
+
/** @internal */
|
|
118
|
+
export interface AISidebarDndState extends AISidebarRowDndHandlers {
|
|
119
|
+
draggingId: string | null
|
|
120
|
+
dropTarget: DropTarget | null
|
|
121
|
+
onRootDragOver: (event: DragEvent<HTMLDivElement>) => void
|
|
122
|
+
}
|
|
123
|
+
|
|
124
|
+
/** @internal The drag handlers a row needs, stable for the life of the
|
|
125
|
+
* sidebar — they read drag state out of the store when they run instead of
|
|
126
|
+
* closing over it, so handing them to every row costs no re-renders. */
|
|
127
|
+
export interface AISidebarRowDndHandlers {
|
|
128
|
+
onDrop: (event: DragEvent<HTMLDivElement>) => void
|
|
129
|
+
onRowDragStart: (event: DragEvent<HTMLDivElement>, id: string) => void
|
|
130
|
+
onRowDragEnd: () => void
|
|
131
|
+
onRowDragOver: (event: DragEvent<HTMLDivElement>, row: FlatResource) => void
|
|
132
|
+
}
|
|
133
|
+
|
|
134
|
+
/** @internal */
|
|
135
|
+
export interface AISidebarHoverState {
|
|
136
|
+
hoveredId: string | null
|
|
137
|
+
/** Shared motion layoutId that lets the pill travel between rows. */
|
|
138
|
+
layoutId: string
|
|
139
|
+
onRowHover: (id: string, hovered: boolean) => void
|
|
140
|
+
clear: () => void
|
|
141
|
+
}
|
|
142
|
+
|
|
143
|
+
export interface AISidebarProps extends UseAISidebarOptions {
|
|
144
|
+
/** Never set on the data form — `controller` selects the other one. */
|
|
145
|
+
controller?: never
|
|
38
146
|
renderIcon?: (item: SidebarResource) => ReactNode
|
|
39
147
|
renderMenu?: (
|
|
40
148
|
item: SidebarResource,
|
|
@@ -49,6 +157,25 @@ export interface AISidebarProps {
|
|
|
49
157
|
className?: string
|
|
50
158
|
}
|
|
51
159
|
|
|
160
|
+
/** Presentational props, shared by both forms of `<AISidebar>`. */
|
|
161
|
+
export type AISidebarViewProps = Pick<
|
|
162
|
+
AISidebarProps,
|
|
163
|
+
| "renderIcon"
|
|
164
|
+
| "renderMenu"
|
|
165
|
+
| "renderActionsTrigger"
|
|
166
|
+
| "ariaLabel"
|
|
167
|
+
| "className"
|
|
168
|
+
>
|
|
169
|
+
|
|
170
|
+
/** Drive the block from a `useAISidebar` controller instead of raw props —
|
|
171
|
+
* the controller carries the data and every handler. */
|
|
172
|
+
export interface AISidebarControllerProps extends AISidebarViewProps {
|
|
173
|
+
controller: AISidebarController
|
|
174
|
+
}
|
|
175
|
+
|
|
176
|
+
/** Either form: raw props, or a `useAISidebar` controller. */
|
|
177
|
+
export type AISidebarComponentProps = AISidebarProps | AISidebarControllerProps
|
|
178
|
+
|
|
52
179
|
export interface FlatResource {
|
|
53
180
|
item: SidebarResource
|
|
54
181
|
depth: number
|
|
@@ -60,36 +187,108 @@ export interface DropTarget {
|
|
|
60
187
|
position: SidebarResourceDropPosition
|
|
61
188
|
}
|
|
62
189
|
|
|
190
|
+
/** A row takes its place in the tree and nothing else: selection,
|
|
191
|
+
* expansion, focus, rename, drag and hover state all arrive through its own
|
|
192
|
+
* atoms, and the rendering options through the sidebar context. */
|
|
63
193
|
export interface ResourceRowProps {
|
|
64
194
|
row: FlatResource
|
|
65
|
-
|
|
66
|
-
|
|
67
|
-
|
|
68
|
-
|
|
69
|
-
|
|
70
|
-
|
|
71
|
-
|
|
72
|
-
|
|
73
|
-
|
|
74
|
-
|
|
75
|
-
|
|
76
|
-
|
|
77
|
-
|
|
78
|
-
|
|
79
|
-
onRenameCancel: () => void
|
|
80
|
-
onRenameCommit: (label: string) => void
|
|
81
|
-
onRenameStart: () => void
|
|
82
|
-
onSelect: () => void
|
|
83
|
-
onToggle: () => void
|
|
84
|
-
/** Some row in the tree is hovered — mounts the pill fade wrapper. */
|
|
85
|
-
hoverActive?: boolean
|
|
86
|
-
/** This row owns the sliding hover pill. */
|
|
87
|
-
hoverPill?: boolean
|
|
88
|
-
/** Shared motion layoutId that lets the pill travel between rows. */
|
|
89
|
-
hoverLayoutId?: string
|
|
90
|
-
onHoverChange?: (hovered: boolean) => void
|
|
91
|
-
renderIcon?: (item: SidebarResource) => ReactNode
|
|
195
|
+
}
|
|
196
|
+
|
|
197
|
+
/** @internal What a row needs from the block, threaded through context so
|
|
198
|
+
* the rows stay prop-light.
|
|
199
|
+
*
|
|
200
|
+
* Deliberately free of sidebar state and of the controller. Rows read state
|
|
201
|
+
* from per-row atoms, so this value keeps its identity for the life of the
|
|
202
|
+
* sidebar and hovering or expanding one row no longer re-renders every row
|
|
203
|
+
* through context. */
|
|
204
|
+
export interface AISidebarContextValue {
|
|
205
|
+
sidebarId: AISidebarInstanceId
|
|
206
|
+
/** Shared motion layoutId that lets the hover pill travel between rows. */
|
|
207
|
+
hoverLayoutId: string
|
|
208
|
+
renderIcon?: AISidebarProps["renderIcon"]
|
|
92
209
|
renderMenu?: AISidebarProps["renderMenu"]
|
|
93
210
|
renderActionsTrigger?: AISidebarProps["renderActionsTrigger"]
|
|
94
|
-
|
|
211
|
+
/** Registers the row's DOM node with the block, which owns the ref map —
|
|
212
|
+
* DOM nodes never go in the store. */
|
|
213
|
+
setRowRef: (id: string, node: HTMLDivElement | null) => void
|
|
214
|
+
onRowKeyDown: (
|
|
215
|
+
event: KeyboardEvent<HTMLDivElement>,
|
|
216
|
+
row: FlatResource
|
|
217
|
+
) => void
|
|
218
|
+
onRowHover: (id: string, hovered: boolean) => void
|
|
219
|
+
/** Closing returns DOM focus to the row that owned the menu, so it goes
|
|
220
|
+
* through the block rather than the store. */
|
|
221
|
+
closeMenu: () => void
|
|
222
|
+
dnd: AISidebarRowDndHandlers
|
|
223
|
+
}
|
|
224
|
+
|
|
225
|
+
/** Everything observable about one sidebar, for consumers reading it by id. */
|
|
226
|
+
export interface AISidebarState {
|
|
227
|
+
items: SidebarResource[]
|
|
228
|
+
/** Visible rows in order, each with its depth and parent id. */
|
|
229
|
+
flat: FlatResource[]
|
|
230
|
+
selectedId: string | null
|
|
231
|
+
expandedIds: ReadonlySet<string>
|
|
232
|
+
focusedId: string | null
|
|
233
|
+
renamingId: string | null
|
|
234
|
+
menuOpenId: string | null
|
|
235
|
+
draggingId: string | null
|
|
236
|
+
dropTarget: DropTarget | null
|
|
237
|
+
hoveredId: string | null
|
|
238
|
+
/** A move is in flight — further moves are refused until it settles. */
|
|
239
|
+
movePending: boolean
|
|
240
|
+
/** Live-region text for the last move or rename outcome. */
|
|
241
|
+
announcement: string
|
|
242
|
+
}
|
|
243
|
+
|
|
244
|
+
/** Everything doable to one sidebar from outside its component. */
|
|
245
|
+
export interface AISidebarActions {
|
|
246
|
+
select: (id: string) => void
|
|
247
|
+
expand: (id: string) => void
|
|
248
|
+
collapse: (id: string) => void
|
|
249
|
+
toggleExpanded: (id: string) => void
|
|
250
|
+
expandAll: () => void
|
|
251
|
+
collapseAll: () => void
|
|
252
|
+
reveal: (id: string) => void
|
|
253
|
+
/** Moves the roving-focus target. DOM focus follows only for callers that
|
|
254
|
+
* hold the controller — the ref map lives in the block, not the store. */
|
|
255
|
+
focus: (id: string) => void
|
|
256
|
+
startRename: (id: string) => void
|
|
257
|
+
cancelRename: () => void
|
|
258
|
+
rename: (id: string, label: string) => void
|
|
259
|
+
openMenu: (id: string) => void
|
|
260
|
+
closeMenu: () => void
|
|
261
|
+
move: (move: SidebarResourceMove) => Promise<void>
|
|
262
|
+
setItems: (items: SidebarResource[]) => void
|
|
263
|
+
reset: () => void
|
|
264
|
+
}
|
|
265
|
+
|
|
266
|
+
/** @internal Projection of `useAISidebar`'s options — primitives only, so
|
|
267
|
+
* the store write runs once per real change instead of once per render. */
|
|
268
|
+
export interface AISidebarConfig {
|
|
269
|
+
controlsItems: boolean
|
|
270
|
+
controlsActiveId: boolean
|
|
271
|
+
controlsExpandedIds: boolean
|
|
272
|
+
}
|
|
273
|
+
|
|
274
|
+
/** @internal Latest option callbacks. Only write atoms read this, so it can
|
|
275
|
+
* be refreshed every commit without re-rendering anything. */
|
|
276
|
+
export interface AISidebarHandlers {
|
|
277
|
+
onItemsChange?: (items: SidebarResource[]) => void
|
|
278
|
+
onMove?: (move: SidebarResourceMove) => void | Promise<void>
|
|
279
|
+
onMoveError?: (error: unknown, move: SidebarResourceMove) => void
|
|
280
|
+
onRename?: (item: SidebarResource, label: string) => void | Promise<void>
|
|
281
|
+
onActiveChange?: (id: string) => void
|
|
282
|
+
onExpandedChange?: (ids: string[]) => void
|
|
283
|
+
}
|
|
284
|
+
|
|
285
|
+
/** @internal What an instance starts from, replayed by
|
|
286
|
+
* `resetAISidebarAtom`. */
|
|
287
|
+
export interface AISidebarSeed {
|
|
288
|
+
items: SidebarResource[]
|
|
289
|
+
/** Hook-owned selection — the `defaultActiveId`, never the controlled
|
|
290
|
+
* `activeId`. */
|
|
291
|
+
activeId: string | null
|
|
292
|
+
focusedId: string | null
|
|
293
|
+
expandedIds: string[]
|
|
95
294
|
}
|
|
@@ -0,0 +1,123 @@
|
|
|
1
|
+
"use client";
|
|
2
|
+
|
|
3
|
+
import { useMemo } from "react";
|
|
4
|
+
import { useAtomValue, useSetAtom } from "jotai";
|
|
5
|
+
|
|
6
|
+
import {
|
|
7
|
+
aiSidebarStateAtom,
|
|
8
|
+
cancelAISidebarRenameAtom,
|
|
9
|
+
closeAISidebarMenuAtom,
|
|
10
|
+
collapseAISidebarRowAtom,
|
|
11
|
+
collapseAllAISidebarRowsAtom,
|
|
12
|
+
expandAISidebarRowAtom,
|
|
13
|
+
expandAllAISidebarRowsAtom,
|
|
14
|
+
focusAISidebarRowAtom,
|
|
15
|
+
moveAISidebarRowAtom,
|
|
16
|
+
openAISidebarMenuAtom,
|
|
17
|
+
renameAISidebarRowAtom,
|
|
18
|
+
resetAISidebarAtom,
|
|
19
|
+
revealAISidebarRowAtom,
|
|
20
|
+
selectAISidebarRowAtom,
|
|
21
|
+
setAISidebarItemsAtom,
|
|
22
|
+
startAISidebarRenameAtom,
|
|
23
|
+
toggleAISidebarRowAtom,
|
|
24
|
+
} from "./ai-sidebar-atom.ts";
|
|
25
|
+
import type {
|
|
26
|
+
AISidebarActions,
|
|
27
|
+
AISidebarInstanceId,
|
|
28
|
+
AISidebarState,
|
|
29
|
+
} from "./type.ts";
|
|
30
|
+
|
|
31
|
+
/**
|
|
32
|
+
* Read the sidebar registered under `sidebarId` from anywhere below
|
|
33
|
+
* `ExegiaProvider` — no controller, no props, no provider of its own.
|
|
34
|
+
*
|
|
35
|
+
* ```tsx
|
|
36
|
+
* const { selectedId, movePending } = useAISidebarState("app-resources")
|
|
37
|
+
* ```
|
|
38
|
+
*
|
|
39
|
+
* This returns the whole state object, so the caller re-renders on any
|
|
40
|
+
* change. A component that reads one field should subscribe to that field's
|
|
41
|
+
* atom instead: `useAtomValue(aiSidebarActiveIdAtom("app-resources"))`.
|
|
42
|
+
*/
|
|
43
|
+
export function useAISidebarState(
|
|
44
|
+
sidebarId: AISidebarInstanceId
|
|
45
|
+
): AISidebarState {
|
|
46
|
+
return useAtomValue(aiSidebarStateAtom(sidebarId));
|
|
47
|
+
}
|
|
48
|
+
|
|
49
|
+
/**
|
|
50
|
+
* Drive the sidebar registered under `sidebarId` from anywhere. Writes only —
|
|
51
|
+
* the caller never re-renders when the sidebar changes, so this is what a
|
|
52
|
+
* command palette, a keyboard shortcut or a route guard should reach for.
|
|
53
|
+
*
|
|
54
|
+
* `focus` and `closeMenu` move the store's roving target; DOM focus follows
|
|
55
|
+
* only for callers that hold the controller, because the row refs live in
|
|
56
|
+
* the block rather than the store.
|
|
57
|
+
*
|
|
58
|
+
* ```tsx
|
|
59
|
+
* const resources = useAISidebarActions("app-resources")
|
|
60
|
+
* <Button onClick={resources.collapseAll}>Collapse all</Button>
|
|
61
|
+
* ```
|
|
62
|
+
*/
|
|
63
|
+
export function useAISidebarActions(
|
|
64
|
+
sidebarId: AISidebarInstanceId
|
|
65
|
+
): AISidebarActions {
|
|
66
|
+
const select = useSetAtom(selectAISidebarRowAtom(sidebarId));
|
|
67
|
+
const expand = useSetAtom(expandAISidebarRowAtom(sidebarId));
|
|
68
|
+
const collapse = useSetAtom(collapseAISidebarRowAtom(sidebarId));
|
|
69
|
+
const toggleExpanded = useSetAtom(toggleAISidebarRowAtom(sidebarId));
|
|
70
|
+
const expandAll = useSetAtom(expandAllAISidebarRowsAtom(sidebarId));
|
|
71
|
+
const collapseAll = useSetAtom(collapseAllAISidebarRowsAtom(sidebarId));
|
|
72
|
+
const reveal = useSetAtom(revealAISidebarRowAtom(sidebarId));
|
|
73
|
+
const focus = useSetAtom(focusAISidebarRowAtom(sidebarId));
|
|
74
|
+
const startRename = useSetAtom(startAISidebarRenameAtom(sidebarId));
|
|
75
|
+
const cancelRename = useSetAtom(cancelAISidebarRenameAtom(sidebarId));
|
|
76
|
+
const rename = useSetAtom(renameAISidebarRowAtom(sidebarId));
|
|
77
|
+
const openMenu = useSetAtom(openAISidebarMenuAtom(sidebarId));
|
|
78
|
+
const closeMenuInStore = useSetAtom(closeAISidebarMenuAtom(sidebarId));
|
|
79
|
+
const move = useSetAtom(moveAISidebarRowAtom(sidebarId));
|
|
80
|
+
const setItems = useSetAtom(setAISidebarItemsAtom(sidebarId));
|
|
81
|
+
const reset = useSetAtom(resetAISidebarAtom(sidebarId));
|
|
82
|
+
|
|
83
|
+
return useMemo(
|
|
84
|
+
() => ({
|
|
85
|
+
select,
|
|
86
|
+
expand,
|
|
87
|
+
collapse,
|
|
88
|
+
toggleExpanded,
|
|
89
|
+
expandAll,
|
|
90
|
+
collapseAll,
|
|
91
|
+
reveal,
|
|
92
|
+
focus,
|
|
93
|
+
startRename,
|
|
94
|
+
cancelRename,
|
|
95
|
+
rename,
|
|
96
|
+
openMenu,
|
|
97
|
+
// The atom returns the id it closed so the block can move DOM focus;
|
|
98
|
+
// remote callers have no refs, so the return value is dropped here.
|
|
99
|
+
closeMenu: () => void closeMenuInStore(),
|
|
100
|
+
move,
|
|
101
|
+
setItems,
|
|
102
|
+
reset,
|
|
103
|
+
}),
|
|
104
|
+
[
|
|
105
|
+
select,
|
|
106
|
+
expand,
|
|
107
|
+
collapse,
|
|
108
|
+
toggleExpanded,
|
|
109
|
+
expandAll,
|
|
110
|
+
collapseAll,
|
|
111
|
+
reveal,
|
|
112
|
+
focus,
|
|
113
|
+
startRename,
|
|
114
|
+
cancelRename,
|
|
115
|
+
rename,
|
|
116
|
+
openMenu,
|
|
117
|
+
closeMenuInStore,
|
|
118
|
+
move,
|
|
119
|
+
setItems,
|
|
120
|
+
reset,
|
|
121
|
+
]
|
|
122
|
+
);
|
|
123
|
+
}
|