@alepha/ui 0.36.1 → 0.37.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/account/$pageAccount.d.ts +1 -1
- package/dist/account/$pageAccount.d.ts.map +1 -1
- package/dist/account/$pageAccount.js.map +1 -1
- package/dist/account/AccountDisplay.d.ts +13 -0
- package/dist/account/AccountDisplay.d.ts.map +1 -0
- package/dist/account/AccountDisplay.js +48 -0
- package/dist/account/AccountDisplay.js.map +1 -0
- package/dist/account/AccountProfile.d.ts.map +1 -1
- package/dist/account/AccountProfile.js +14 -10
- package/dist/account/AccountProfile.js.map +1 -1
- package/dist/account/AccountRouter.d.ts +6 -6
- package/dist/account/AccountRouter.d.ts.map +1 -1
- package/dist/account/index.d.ts +5 -0
- package/dist/account/index.d.ts.map +1 -1
- package/dist/account/index.js +2 -1
- package/dist/admin/$pageAdmin.d.ts +1 -1
- package/dist/admin/$pageAdmin.d.ts.map +1 -1
- package/dist/admin/$pageAdmin.js.map +1 -1
- package/dist/admin/AdminAudits.js.map +1 -1
- package/dist/admin/AdminJobDetail.js.map +1 -1
- package/dist/admin/AdminJobs.js.map +1 -1
- package/dist/admin/AdminNotifications.js.map +1 -1
- package/dist/admin/AdminRouter.d.ts +14 -14
- package/dist/admin/AdminRouter.d.ts.map +1 -1
- package/dist/admin/AdminUserDetail.js.map +1 -1
- package/dist/admin/AdminUsers.js.map +1 -1
- package/dist/admin/ParameterHistoryItem.js.map +1 -1
- package/dist/ai/AiChat.d.ts +26 -39
- package/dist/ai/AiChat.d.ts.map +1 -1
- package/dist/ai/AiChat.js +65 -123
- package/dist/ai/AiChat.js.map +1 -1
- package/dist/ai/AiChatDock.d.ts +23 -0
- package/dist/ai/AiChatDock.d.ts.map +1 -0
- package/dist/ai/AiChatDock.js +90 -0
- package/dist/ai/AiChatDock.js.map +1 -0
- package/dist/ai/AiChatDockSlot.d.ts +15 -0
- package/dist/ai/AiChatDockSlot.d.ts.map +1 -0
- package/dist/ai/AiChatDockSlot.js +20 -0
- package/dist/ai/AiChatDockSlot.js.map +1 -0
- package/dist/ai/AiChatLauncher.d.ts +17 -0
- package/dist/ai/AiChatLauncher.d.ts.map +1 -0
- package/dist/ai/AiChatLauncher.js +42 -0
- package/dist/ai/AiChatLauncher.js.map +1 -0
- package/dist/ai/AiChatMessage.d.ts +6 -0
- package/dist/ai/AiChatMessage.d.ts.map +1 -1
- package/dist/ai/AiChatMessage.js +20 -4
- package/dist/ai/AiChatMessage.js.map +1 -1
- package/dist/ai/AiChatPanel.d.ts +71 -0
- package/dist/ai/AiChatPanel.d.ts.map +1 -0
- package/dist/ai/AiChatPanel.js +143 -0
- package/dist/ai/AiChatPanel.js.map +1 -0
- package/dist/ai/index.d.ts +8 -4
- package/dist/ai/index.d.ts.map +1 -1
- package/dist/ai/index.js +5 -1
- package/dist/ai/useAiChat.d.ts +12 -0
- package/dist/ai/useAiChat.d.ts.map +1 -1
- package/dist/ai/useAiChat.js +32 -15
- package/dist/ai/useAiChat.js.map +1 -1
- package/dist/auth/AuthLogin.d.ts +9 -0
- package/dist/auth/AuthLogin.d.ts.map +1 -1
- package/dist/auth/AuthLogin.js +2 -2
- package/dist/auth/AuthLogin.js.map +1 -1
- package/dist/auth/AuthRegister.d.ts +4 -1
- package/dist/auth/AuthRegister.d.ts.map +1 -1
- package/dist/auth/AuthRegister.js +1 -1
- package/dist/auth/AuthRegister.js.map +1 -1
- package/dist/auth/AuthResetPassword.d.ts +8 -0
- package/dist/auth/AuthResetPassword.d.ts.map +1 -1
- package/dist/auth/AuthResetPassword.js +2 -2
- package/dist/auth/AuthResetPassword.js.map +1 -1
- package/dist/auth/AuthRouter.d.ts +4 -4
- package/dist/auth/AuthRouter.d.ts.map +1 -1
- package/dist/core/Badge.d.ts.map +1 -1
- package/dist/core/Badge.js +7 -3
- package/dist/core/Badge.js.map +1 -1
- package/dist/core/Collapsible.d.ts +50 -0
- package/dist/core/Collapsible.d.ts.map +1 -0
- package/dist/core/Collapsible.js +70 -0
- package/dist/core/Collapsible.js.map +1 -0
- package/dist/core/Combobox.d.ts +7 -1
- package/dist/core/Combobox.d.ts.map +1 -1
- package/dist/core/Combobox.js +2 -2
- package/dist/core/Combobox.js.map +1 -1
- package/dist/core/PaneRail.d.ts +24 -7
- package/dist/core/PaneRail.d.ts.map +1 -1
- package/dist/core/PaneRail.js +24 -19
- package/dist/core/PaneRail.js.map +1 -1
- package/dist/core/Stepper.d.ts +36 -0
- package/dist/core/Stepper.d.ts.map +1 -0
- package/dist/core/Stepper.js +54 -0
- package/dist/core/Stepper.js.map +1 -0
- package/dist/core/index.d.ts +2 -0
- package/dist/core/index.d.ts.map +1 -1
- package/dist/core/index.js +3 -1
- package/dist/core/useToast.js +13 -13
- package/dist/core/useToast.js.map +1 -1
- package/dist/form/AutoForm.d.ts.map +1 -1
- package/dist/form/AutoForm.js +29 -0
- package/dist/form/AutoForm.js.map +1 -1
- package/dist/form/AutoFormErrorPopover.js +13 -3
- package/dist/form/AutoFormErrorPopover.js.map +1 -1
- package/dist/form/Control.d.ts +14 -1
- package/dist/form/Control.d.ts.map +1 -1
- package/dist/form/Control.js +12 -2
- package/dist/form/Control.js.map +1 -1
- package/dist/form/ControlDate.d.ts.map +1 -1
- package/dist/form/ControlDate.js +3 -0
- package/dist/form/ControlDate.js.map +1 -1
- package/dist/form/ControlDateRange.d.ts +12 -1
- package/dist/form/ControlDateRange.d.ts.map +1 -1
- package/dist/form/ControlDateRange.js +11 -1
- package/dist/form/ControlDateRange.js.map +1 -1
- package/dist/form/ControlNumber.d.ts.map +1 -1
- package/dist/form/ControlNumber.js +2 -0
- package/dist/form/ControlNumber.js.map +1 -1
- package/dist/form/ControlObject.d.ts.map +1 -1
- package/dist/form/ControlObject.js +15 -1
- package/dist/form/ControlObject.js.map +1 -1
- package/dist/form/ControlPassword.d.ts +4 -0
- package/dist/form/ControlPassword.d.ts.map +1 -1
- package/dist/form/ControlPassword.js +1 -0
- package/dist/form/ControlPassword.js.map +1 -1
- package/dist/form/ControlSelect.d.ts +23 -1
- package/dist/form/ControlSelect.d.ts.map +1 -1
- package/dist/form/ControlSelect.js +5 -0
- package/dist/form/ControlSelect.js.map +1 -1
- package/dist/form/ControlSelectCombobox.d.ts +11 -1
- package/dist/form/ControlSelectCombobox.d.ts.map +1 -1
- package/dist/form/ControlSelectCombobox.js +9 -1
- package/dist/form/ControlSelectCombobox.js.map +1 -1
- package/dist/form/ControlUpload.d.ts.map +1 -1
- package/dist/form/ControlUpload.js +1 -0
- package/dist/form/ControlUpload.js.map +1 -1
- package/dist/form/FormField.d.ts +5 -0
- package/dist/form/FormField.d.ts.map +1 -1
- package/dist/form/FormField.js +7 -0
- package/dist/form/FormField.js.map +1 -1
- package/dist/i18n/fr/uiFr.d.ts.map +1 -1
- package/dist/i18n/fr/uiFr.js +14 -0
- package/dist/i18n/fr/uiFr.js.map +1 -1
- package/dist/shell/$pageNav.d.ts +2 -2
- package/dist/shell/$pageNav.d.ts.map +1 -1
- package/dist/shell/$pageNav.js.map +1 -1
- package/dist/shell/AppShell.d.ts +6 -0
- package/dist/shell/AppShell.d.ts.map +1 -1
- package/dist/shell/AppShell.js +31 -27
- package/dist/shell/AppShell.js.map +1 -1
- package/dist/shell/ButtonSettings.d.ts +6 -2
- package/dist/shell/ButtonSettings.d.ts.map +1 -1
- package/dist/shell/ButtonSettings.js +17 -3
- package/dist/shell/ButtonSettings.js.map +1 -1
- package/dist/shell/ButtonSettingsVisionMenuItem.d.ts +16 -0
- package/dist/shell/ButtonSettingsVisionMenuItem.d.ts.map +1 -0
- package/dist/shell/ButtonSettingsVisionMenuItem.js +24 -0
- package/dist/shell/ButtonSettingsVisionMenuItem.js.map +1 -0
- package/dist/shell/ButtonVision.d.ts +28 -0
- package/dist/shell/ButtonVision.d.ts.map +1 -0
- package/dist/shell/ButtonVision.js +46 -0
- package/dist/shell/ButtonVision.js.map +1 -0
- package/dist/shell/index.d.ts +6 -3
- package/dist/shell/index.d.ts.map +1 -1
- package/dist/shell/index.js +2 -1
- package/dist/styles.css +57 -0
- package/dist/table/DataTable.d.ts.map +1 -1
- package/dist/table/DataTable.js +29 -4
- package/dist/table/DataTable.js.map +1 -1
- package/dist/table/DataTableColumnPicker.d.ts.map +1 -1
- package/dist/table/DataTableColumnPicker.js +1 -0
- package/dist/table/DataTableColumnPicker.js.map +1 -1
- package/dist/table/DataTableFilterBar.d.ts +1 -1
- package/dist/table/DataTableFilterBar.d.ts.map +1 -1
- package/dist/table/DataTableFilterBar.js +5 -108
- package/dist/table/DataTableFilterBar.js.map +1 -1
- package/dist/table/DataTableHeaderFilter.d.ts +51 -0
- package/dist/table/DataTableHeaderFilter.d.ts.map +1 -0
- package/dist/table/DataTableHeaderFilter.js +113 -0
- package/dist/table/DataTableHeaderFilter.js.map +1 -0
- package/dist/table/DataTableHeaderRow.d.ts +7 -0
- package/dist/table/DataTableHeaderRow.d.ts.map +1 -1
- package/dist/table/DataTableHeaderRow.js +92 -74
- package/dist/table/DataTableHeaderRow.js.map +1 -1
- package/dist/table/DataTableTabs.d.ts +42 -0
- package/dist/table/DataTableTabs.d.ts.map +1 -0
- package/dist/table/DataTableTabs.js +55 -0
- package/dist/table/DataTableTabs.js.map +1 -0
- package/dist/table/dataTableBaseProps.d.ts +12 -0
- package/dist/table/dataTableBaseProps.d.ts.map +1 -1
- package/dist/table/dataTablePersistence.d.ts.map +1 -1
- package/dist/table/dataTablePersistence.js +4 -2
- package/dist/table/dataTablePersistence.js.map +1 -1
- package/dist/table/dataTableTypes.d.ts +18 -0
- package/dist/table/dataTableTypes.d.ts.map +1 -1
- package/dist/table/index.d.ts +5 -2
- package/dist/table/index.d.ts.map +1 -1
- package/dist/table/index.js +2 -1
- package/dist/table/useDataTableColumns.d.ts.map +1 -1
- package/dist/table/useDataTableColumns.js +1 -0
- package/dist/table/useDataTableColumns.js.map +1 -1
- package/dist/table/useDataTableFilterModel.d.ts +110 -0
- package/dist/table/useDataTableFilterModel.d.ts.map +1 -0
- package/dist/table/useDataTableFilterModel.js +154 -0
- package/dist/table/useDataTableFilterModel.js.map +1 -0
- package/docs/packages-alepha-ui-account.md +4 -0
- package/docs/packages-alepha-ui-ai.md +5 -5
- package/docs/packages-alepha-ui-shell.md +4 -3
- package/docs/packages-alepha-ui-table.md +4 -2
- package/package.json +8 -8
- package/src/account/$pageAccount.tsx +5 -4
- package/src/account/AccountDisplay.tsx +58 -0
- package/src/account/AccountProfile.tsx +30 -42
- package/src/account/__tests__/AccountProfile.browser.spec.tsx +141 -0
- package/src/account/__tests__/AccountRecoveryCodes.browser.spec.tsx +1 -1
- package/src/account/index.ts +5 -0
- package/src/admin/$pageAdmin.tsx +5 -4
- package/src/admin/AdminAudits.tsx +1 -1
- package/src/admin/AdminJobDetail.tsx +1 -1
- package/src/admin/AdminJobs.tsx +1 -1
- package/src/admin/AdminNotifications.tsx +1 -1
- package/src/admin/AdminUserDetail.tsx +1 -1
- package/src/admin/AdminUsers.tsx +1 -1
- package/src/admin/ParameterHistoryItem.tsx +1 -1
- package/src/admin/__tests__/AdminFilesUsageCard.browser.spec.tsx +17 -9
- package/src/ai/AiChat.tsx +94 -183
- package/src/ai/AiChatDock.tsx +129 -0
- package/src/ai/AiChatDockSlot.tsx +23 -0
- package/src/ai/AiChatLauncher.tsx +58 -0
- package/src/ai/AiChatMessage.tsx +36 -2
- package/src/ai/AiChatPanel.tsx +252 -0
- package/src/ai/__tests__/AiChat.browser.spec.tsx +187 -5
- package/src/ai/index.ts +8 -4
- package/src/ai/useAiChat.ts +63 -14
- package/src/auth/AuthLogin.tsx +19 -4
- package/src/auth/AuthRegister.tsx +6 -3
- package/src/auth/AuthResetPassword.tsx +18 -8
- package/src/auth/__tests__/AuthCancel.browser.spec.tsx +129 -0
- package/src/core/Badge.tsx +7 -3
- package/src/core/Collapsible.tsx +95 -0
- package/src/core/Combobox.tsx +11 -3
- package/src/core/PaneRail.tsx +36 -20
- package/src/core/Stepper.tsx +118 -0
- package/src/core/__tests__/Badge.browser.spec.tsx +5 -5
- package/src/core/__tests__/Collapsible.browser.spec.tsx +88 -0
- package/src/core/__tests__/PaneRail.browser.spec.tsx +48 -0
- package/src/core/__tests__/Stepper.browser.spec.tsx +39 -0
- package/src/core/__tests__/primitiveSlots.spec.ts +7 -0
- package/src/core/index.ts +15 -0
- package/src/form/AutoForm.tsx +32 -0
- package/src/form/AutoFormErrorPopover.tsx +27 -6
- package/src/form/Control.tsx +22 -0
- package/src/form/ControlDate.tsx +3 -0
- package/src/form/ControlDateRange.tsx +87 -58
- package/src/form/ControlNumber.tsx +2 -0
- package/src/form/ControlObject.tsx +20 -1
- package/src/form/ControlPassword.tsx +5 -0
- package/src/form/ControlSelect.tsx +32 -1
- package/src/form/ControlSelectCombobox.tsx +82 -56
- package/src/form/ControlUpload.tsx +1 -0
- package/src/form/FormField.tsx +23 -1
- package/src/form/__tests__/ControlFieldErrors.browser.spec.tsx +253 -0
- package/src/form/__tests__/ControlValidateMode.browser.spec.tsx +217 -0
- package/src/form/__tests__/ControlVariantErrors.browser.spec.tsx +133 -0
- package/src/i18n/fr/uiFr.ts +18 -1
- package/src/markdown/css.d.ts +11 -0
- package/src/shell/$pageNav.tsx +6 -4
- package/src/shell/AppShell.tsx +7 -0
- package/src/shell/ButtonSettings.tsx +20 -5
- package/src/shell/ButtonSettingsVisionMenuItem.tsx +40 -0
- package/src/shell/ButtonVision.tsx +73 -0
- package/src/shell/__tests__/ButtonSettings.browser.spec.tsx +42 -2
- package/src/shell/__tests__/ButtonVision.browser.spec.tsx +73 -0
- package/src/shell/__tests__/visionTokens.spec.ts +104 -0
- package/src/shell/index.ts +6 -3
- package/src/styles.css +57 -0
- package/src/table/DataTable.tsx +52 -4
- package/src/table/DataTableColumnPicker.tsx +3 -0
- package/src/table/DataTableFilterBar.tsx +18 -191
- package/src/table/DataTableHeaderFilter.tsx +156 -0
- package/src/table/DataTableHeaderRow.tsx +78 -40
- package/src/table/DataTableTabs.tsx +114 -0
- package/src/table/__tests__/DataTableHeaderFilter.browser.spec.tsx +174 -0
- package/src/table/__tests__/DataTableStaleColumns.browser.spec.tsx +80 -0
- package/src/table/__tests__/DataTableTabs.browser.spec.tsx +72 -0
- package/src/table/dataTableBaseProps.ts +12 -0
- package/src/table/dataTablePersistence.ts +11 -5
- package/src/table/dataTableTypes.ts +18 -0
- package/src/table/index.ts +9 -2
- package/src/table/useDataTableColumns.ts +1 -0
- package/src/table/useDataTableFilterModel.tsx +240 -0
package/src/ai/useAiChat.ts
CHANGED
|
@@ -60,6 +60,21 @@ export const useAiChat = (options: UseAiChatOptions = {}): UseAiChat => {
|
|
|
60
60
|
setItems((current) => [...current, { id, ...item }]);
|
|
61
61
|
}, []);
|
|
62
62
|
|
|
63
|
+
/**
|
|
64
|
+
* The page context a turn carries: the route, and the innermost page's
|
|
65
|
+
* name and data. Sent on a chat and on every resume, since the server's
|
|
66
|
+
* `allow` reads it to decide what the assistant is offered.
|
|
67
|
+
*/
|
|
68
|
+
const pageContext = useCallback(() => {
|
|
69
|
+
const stack = alepha.store.get(aiContextAtom) ?? [];
|
|
70
|
+
const innermost = stack[stack.length - 1];
|
|
71
|
+
return {
|
|
72
|
+
route: router.pathname,
|
|
73
|
+
page: innermost?.page,
|
|
74
|
+
data: innermost?.data,
|
|
75
|
+
};
|
|
76
|
+
}, [alepha, router]);
|
|
77
|
+
|
|
63
78
|
/**
|
|
64
79
|
* Run a client tool the turn paused on, and return its result. A failure
|
|
65
80
|
* is a result too: the model reads it and recovers.
|
|
@@ -117,6 +132,7 @@ export const useAiChat = (options: UseAiChatOptions = {}): UseAiChat => {
|
|
|
117
132
|
): Promise<void> => {
|
|
118
133
|
let stream: AsyncIterable<AiStreamEvent> | undefined = first;
|
|
119
134
|
let ranTools = false;
|
|
135
|
+
const succeeded: string[] = [];
|
|
120
136
|
while (stream) {
|
|
121
137
|
let text = "";
|
|
122
138
|
let clientCall: AiPendingCallResource | undefined;
|
|
@@ -131,6 +147,9 @@ export const useAiChat = (options: UseAiChatOptions = {}): UseAiChat => {
|
|
|
131
147
|
setActivity(event.name);
|
|
132
148
|
} else if (event.type === "tool_result") {
|
|
133
149
|
ranTools = true;
|
|
150
|
+
if (!event.isError && event.name) {
|
|
151
|
+
succeeded.push(event.name);
|
|
152
|
+
}
|
|
134
153
|
setActivity(undefined);
|
|
135
154
|
push({
|
|
136
155
|
role: "tool",
|
|
@@ -158,8 +177,14 @@ export const useAiChat = (options: UseAiChatOptions = {}): UseAiChat => {
|
|
|
158
177
|
} else if (event.type === "error") {
|
|
159
178
|
setError(event.message ?? event.name ?? "The assistant failed");
|
|
160
179
|
}
|
|
161
|
-
|
|
162
|
-
|
|
180
|
+
// The model ran out of output tokens (or of steps): the reply is
|
|
181
|
+
// marked, so it reads as cut short and not as a finished answer.
|
|
182
|
+
const cut = event.type === "end" && event.reason === "length";
|
|
183
|
+
if (
|
|
184
|
+
(text && (event.type === "tool_call" || event.type === "end")) ||
|
|
185
|
+
cut
|
|
186
|
+
) {
|
|
187
|
+
push({ role: "assistant", content: text, ...(cut ? { cut } : {}) });
|
|
163
188
|
text = "";
|
|
164
189
|
setStreaming("");
|
|
165
190
|
}
|
|
@@ -171,6 +196,9 @@ export const useAiChat = (options: UseAiChatOptions = {}): UseAiChat => {
|
|
|
171
196
|
for (const key of options.invalidates ?? []) {
|
|
172
197
|
queries.invalidate(key);
|
|
173
198
|
}
|
|
199
|
+
if (succeeded.length) {
|
|
200
|
+
options.onToolsRan?.(succeeded.splice(0));
|
|
201
|
+
}
|
|
174
202
|
ranTools = false;
|
|
175
203
|
}
|
|
176
204
|
if (clientCall && idRef.current) {
|
|
@@ -178,14 +206,26 @@ export const useAiChat = (options: UseAiChatOptions = {}): UseAiChat => {
|
|
|
178
206
|
stream = await api.resume(
|
|
179
207
|
{
|
|
180
208
|
params: { id: idRef.current },
|
|
181
|
-
body: {
|
|
209
|
+
body: {
|
|
210
|
+
callId: clientCall.callId,
|
|
211
|
+
result,
|
|
212
|
+
context: pageContext(),
|
|
213
|
+
},
|
|
182
214
|
},
|
|
183
215
|
{ request: { signal } },
|
|
184
216
|
);
|
|
185
217
|
}
|
|
186
218
|
}
|
|
187
219
|
},
|
|
188
|
-
[
|
|
220
|
+
[
|
|
221
|
+
api,
|
|
222
|
+
push,
|
|
223
|
+
runClientTool,
|
|
224
|
+
queries,
|
|
225
|
+
options.invalidates,
|
|
226
|
+
options.onToolsRan,
|
|
227
|
+
pageContext,
|
|
228
|
+
],
|
|
189
229
|
);
|
|
190
230
|
|
|
191
231
|
const send = useAction<[message: string]>(
|
|
@@ -193,19 +233,13 @@ export const useAiChat = (options: UseAiChatOptions = {}): UseAiChat => {
|
|
|
193
233
|
handler: async ({ signal }, message) => {
|
|
194
234
|
setError(undefined);
|
|
195
235
|
push({ role: "user", content: message });
|
|
196
|
-
const stack = alepha.store.get(aiContextAtom) ?? [];
|
|
197
|
-
const innermost = stack[stack.length - 1];
|
|
198
236
|
const stream = await api.chat(
|
|
199
237
|
{
|
|
200
238
|
body: {
|
|
201
239
|
conversationId: idRef.current,
|
|
202
240
|
message,
|
|
203
241
|
assistant: options.assistant,
|
|
204
|
-
context:
|
|
205
|
-
route: router.pathname,
|
|
206
|
-
page: innermost?.page,
|
|
207
|
-
data: innermost?.data,
|
|
208
|
-
},
|
|
242
|
+
context: pageContext(),
|
|
209
243
|
},
|
|
210
244
|
},
|
|
211
245
|
{ request: { signal } },
|
|
@@ -214,7 +248,7 @@ export const useAiChat = (options: UseAiChatOptions = {}): UseAiChat => {
|
|
|
214
248
|
},
|
|
215
249
|
onError: (cause) => setError(cause.message),
|
|
216
250
|
},
|
|
217
|
-
[api,
|
|
251
|
+
[api, consume, options.assistant, push, pageContext],
|
|
218
252
|
);
|
|
219
253
|
|
|
220
254
|
const answer = useAction<[decision: "approve" | "deny"]>(
|
|
@@ -230,14 +264,17 @@ export const useAiChat = (options: UseAiChatOptions = {}): UseAiChat => {
|
|
|
230
264
|
}
|
|
231
265
|
setPending(undefined);
|
|
232
266
|
const stream = await api.resume(
|
|
233
|
-
{
|
|
267
|
+
{
|
|
268
|
+
params: { id: idRef.current },
|
|
269
|
+
body: { callId, decision, context: pageContext() },
|
|
270
|
+
},
|
|
234
271
|
{ request: { signal } },
|
|
235
272
|
);
|
|
236
273
|
await consume(stream, signal);
|
|
237
274
|
},
|
|
238
275
|
onError: (cause) => setError(cause.message),
|
|
239
276
|
},
|
|
240
|
-
[api, consume, pending],
|
|
277
|
+
[api, consume, pending, pageContext],
|
|
241
278
|
);
|
|
242
279
|
|
|
243
280
|
const open = useAction<[id?: string]>(
|
|
@@ -321,6 +358,12 @@ export interface UseAiChatOptions {
|
|
|
321
358
|
* what the assistant may have changed (`[["notes"]]`).
|
|
322
359
|
*/
|
|
323
360
|
invalidates?: unknown[][];
|
|
361
|
+
/**
|
|
362
|
+
* Called after a stream in which tools ran, with the names of those that
|
|
363
|
+
* succeeded, for what `invalidates` cannot reach: a page whose data its
|
|
364
|
+
* route loaders fill re-runs them (`router.invalidate()`) after a write.
|
|
365
|
+
*/
|
|
366
|
+
onToolsRan?: (names: string[]) => void;
|
|
324
367
|
/**
|
|
325
368
|
* The app's own client tools, by name, beside `navigate` and `fillForm`.
|
|
326
369
|
* The result goes back to the model.
|
|
@@ -345,6 +388,12 @@ export interface AiChatItem {
|
|
|
345
388
|
* model, a cancellation to the user.
|
|
346
389
|
*/
|
|
347
390
|
denied?: boolean;
|
|
391
|
+
/**
|
|
392
|
+
* An `assistant` line the model did not finish: the turn ended on its
|
|
393
|
+
* output limit (`reason: "length"`). Known for a reply streamed in this
|
|
394
|
+
* session only; a stored conversation does not keep it.
|
|
395
|
+
*/
|
|
396
|
+
cut?: boolean;
|
|
348
397
|
}
|
|
349
398
|
|
|
350
399
|
/**
|
package/src/auth/AuthLogin.tsx
CHANGED
|
@@ -59,11 +59,20 @@ export interface AuthLoginProps {
|
|
|
59
59
|
* component (e.g. with light/dark variants or an animation).
|
|
60
60
|
*/
|
|
61
61
|
logo?: ReactNode;
|
|
62
|
+
/**
|
|
63
|
+
* Where the "Cancel" link under the form leads. Defaults to "/".
|
|
64
|
+
*
|
|
65
|
+
* Pass `false` to hide the link, for an application where every page
|
|
66
|
+
* needs an account: there "/" only leads back to this page. It is
|
|
67
|
+
* intentionally decoupled from the post-auth `?redirect=` target, which is
|
|
68
|
+
* a protected destination the visitor has not reached yet.
|
|
69
|
+
*/
|
|
70
|
+
cancelPath?: string | false;
|
|
62
71
|
}
|
|
63
72
|
|
|
64
73
|
export const AuthLogin = (props: AuthLoginProps) => {
|
|
65
74
|
const auth = useAuth();
|
|
66
|
-
const router = useRouter();
|
|
75
|
+
const router = useRouter<any>();
|
|
67
76
|
const { tr } = useI18n();
|
|
68
77
|
const redirect = safeRedirect(router.query.redirect);
|
|
69
78
|
const error = router.query.error;
|
|
@@ -348,9 +357,15 @@ export const AuthLogin = (props: AuthLoginProps) => {
|
|
|
348
357
|
)}
|
|
349
358
|
</CardContent>
|
|
350
359
|
</Card>
|
|
351
|
-
|
|
352
|
-
|
|
353
|
-
|
|
360
|
+
{props.cancelPath !== false && (
|
|
361
|
+
<Button
|
|
362
|
+
variant="minimal"
|
|
363
|
+
nativeButton={false}
|
|
364
|
+
render={<a href={props.cancelPath ?? "/"} />}
|
|
365
|
+
>
|
|
366
|
+
{tr("auth.login.cancel", { default: "Cancel" })}
|
|
367
|
+
</Button>
|
|
368
|
+
)}
|
|
354
369
|
</div>
|
|
355
370
|
);
|
|
356
371
|
|
|
@@ -66,8 +66,11 @@ export interface AuthRegisterProps {
|
|
|
66
66
|
* an unauthenticated registration must land somewhere public (home), not the
|
|
67
67
|
* protected destination the user was *heading* to — which would only bounce
|
|
68
68
|
* them back to this page.
|
|
69
|
+
*
|
|
70
|
+
* Pass `false` to hide the link, for an application where every page
|
|
71
|
+
* needs an account.
|
|
69
72
|
*/
|
|
70
|
-
cancelPath?: string;
|
|
73
|
+
cancelPath?: string | false;
|
|
71
74
|
/**
|
|
72
75
|
* Render the form even though `settings.registrationAllowed` is `false`.
|
|
73
76
|
*
|
|
@@ -108,7 +111,7 @@ export interface AuthRegisterProps {
|
|
|
108
111
|
export const AuthRegister = (props: AuthRegisterProps) => {
|
|
109
112
|
const auth = useAuth();
|
|
110
113
|
const userCtrl = useClient<UserController>();
|
|
111
|
-
const router = useRouter();
|
|
114
|
+
const router = useRouter<any>();
|
|
112
115
|
const { tr } = useI18n();
|
|
113
116
|
const redirect = safeRedirect(props.redirect ?? router.query.redirect);
|
|
114
117
|
// Surface upstream auth errors (e.g. failed OAuth callback redirects with
|
|
@@ -492,7 +495,7 @@ export const AuthRegister = (props: AuthRegisterProps) => {
|
|
|
492
495
|
</div>
|
|
493
496
|
</CardContent>
|
|
494
497
|
</Card>
|
|
495
|
-
{!isVerifying && (
|
|
498
|
+
{!isVerifying && props.cancelPath !== false && (
|
|
496
499
|
<Button
|
|
497
500
|
variant="minimal"
|
|
498
501
|
nativeButton={false}
|
|
@@ -44,6 +44,14 @@ export interface AuthResetPasswordProps {
|
|
|
44
44
|
* component (e.g. with light/dark variants or an animation).
|
|
45
45
|
*/
|
|
46
46
|
logo?: ReactNode;
|
|
47
|
+
/**
|
|
48
|
+
* Where the "Cancel" link under the form leads. Defaults to the
|
|
49
|
+
* `?redirect=` target of the URL, else "/".
|
|
50
|
+
*
|
|
51
|
+
* Pass `false` to hide the link, for an application where every page
|
|
52
|
+
* needs an account: there the default only leads back to sign-in.
|
|
53
|
+
*/
|
|
54
|
+
cancelPath?: string | false;
|
|
47
55
|
}
|
|
48
56
|
|
|
49
57
|
type Step = "email" | "code" | "password" | "success";
|
|
@@ -56,7 +64,7 @@ interface State {
|
|
|
56
64
|
}
|
|
57
65
|
|
|
58
66
|
export const AuthResetPassword = (props: AuthResetPasswordProps) => {
|
|
59
|
-
const router = useRouter();
|
|
67
|
+
const router = useRouter<any>();
|
|
60
68
|
const { tr } = useI18n();
|
|
61
69
|
const userCtrl = useClient<UserController>();
|
|
62
70
|
const [state, setState] = useState<State>({ step: "email" });
|
|
@@ -420,13 +428,15 @@ export const AuthResetPassword = (props: AuthResetPasswordProps) => {
|
|
|
420
428
|
)}
|
|
421
429
|
</CardContent>
|
|
422
430
|
</Card>
|
|
423
|
-
|
|
424
|
-
|
|
425
|
-
|
|
426
|
-
|
|
427
|
-
|
|
428
|
-
|
|
429
|
-
|
|
431
|
+
{props.cancelPath !== false && (
|
|
432
|
+
<Button
|
|
433
|
+
variant="minimal"
|
|
434
|
+
nativeButton={false}
|
|
435
|
+
render={<a href={props.cancelPath ?? redirect} />}
|
|
436
|
+
>
|
|
437
|
+
{tr("auth.reset.cancel", { default: "Cancel" })}
|
|
438
|
+
</Button>
|
|
439
|
+
)}
|
|
430
440
|
</div>
|
|
431
441
|
</div>
|
|
432
442
|
);
|
|
@@ -0,0 +1,129 @@
|
|
|
1
|
+
import { render, screen } from "@testing-library/react";
|
|
2
|
+
import { Alepha } from "alepha";
|
|
3
|
+
import type { RealmConfig } from "alepha/api/users";
|
|
4
|
+
import { AlephaContext } from "alepha/react";
|
|
5
|
+
import { AlephaReactAuth } from "alepha/react/auth";
|
|
6
|
+
import { AlephaReactI18n } from "alepha/react/i18n";
|
|
7
|
+
import { AlephaReactRouter } from "alepha/react/router";
|
|
8
|
+
import { AlephaServerLinks } from "alepha/server/links";
|
|
9
|
+
import { setupJsdomMocks } from "alepha/testing/react";
|
|
10
|
+
import type { ReactNode } from "react";
|
|
11
|
+
import { afterEach, beforeAll, describe, expect, it } from "vitest";
|
|
12
|
+
|
|
13
|
+
import { DialogProvider } from "../../core/useDialog.tsx";
|
|
14
|
+
import { AuthLogin } from "../AuthLogin.tsx";
|
|
15
|
+
import { AuthRegister } from "../AuthRegister.tsx";
|
|
16
|
+
import { AuthResetPassword } from "../AuthResetPassword.tsx";
|
|
17
|
+
|
|
18
|
+
/**
|
|
19
|
+
* The "Cancel" link under the sign-in, registration and password-reset forms.
|
|
20
|
+
*
|
|
21
|
+
* It leads to "/" by default, which is right for an application with public
|
|
22
|
+
* pages. In an application where every page needs an account, "/" sends the
|
|
23
|
+
* visitor straight back to sign-in, so `cancelPath={false}` hides the link and
|
|
24
|
+
* a string points it elsewhere.
|
|
25
|
+
*/
|
|
26
|
+
describe("Auth forms - the Cancel link", () => {
|
|
27
|
+
let alepha: Alepha | undefined;
|
|
28
|
+
|
|
29
|
+
beforeAll(() => {
|
|
30
|
+
setupJsdomMocks();
|
|
31
|
+
});
|
|
32
|
+
|
|
33
|
+
afterEach(async () => {
|
|
34
|
+
await alepha?.stop();
|
|
35
|
+
alepha = undefined;
|
|
36
|
+
});
|
|
37
|
+
|
|
38
|
+
const realmConfig = {
|
|
39
|
+
realmName: "default",
|
|
40
|
+
authenticationMethods: [{ type: "CREDENTIALS", name: "credentials" }],
|
|
41
|
+
settings: {
|
|
42
|
+
username: "none",
|
|
43
|
+
email: "required",
|
|
44
|
+
phoneNumber: "none",
|
|
45
|
+
registrationAllowed: true,
|
|
46
|
+
resetPasswordAllowed: true,
|
|
47
|
+
},
|
|
48
|
+
} as unknown as RealmConfig;
|
|
49
|
+
|
|
50
|
+
const mount = async (node: ReactNode) => {
|
|
51
|
+
alepha = Alepha.create()
|
|
52
|
+
.with(AlephaReactRouter)
|
|
53
|
+
.with(AlephaReactI18n)
|
|
54
|
+
.with(AlephaReactAuth)
|
|
55
|
+
.with(AlephaServerLinks);
|
|
56
|
+
await alepha.start();
|
|
57
|
+
return render(
|
|
58
|
+
<AlephaContext.Provider value={alepha}>
|
|
59
|
+
<DialogProvider>{node}</DialogProvider>
|
|
60
|
+
</AlephaContext.Provider>,
|
|
61
|
+
);
|
|
62
|
+
};
|
|
63
|
+
|
|
64
|
+
/**
|
|
65
|
+
* The kit's `Button` rendered as an anchor keeps `role="button"`.
|
|
66
|
+
*/
|
|
67
|
+
const cancelLink = () => screen.queryByRole("button", { name: "Cancel" });
|
|
68
|
+
|
|
69
|
+
describe("AuthLogin", () => {
|
|
70
|
+
it("should lead to / by default", async () => {
|
|
71
|
+
await mount(<AuthLogin realmConfig={realmConfig} />);
|
|
72
|
+
|
|
73
|
+
expect(cancelLink()?.getAttribute("href")).toBe("/");
|
|
74
|
+
});
|
|
75
|
+
|
|
76
|
+
it("should lead to the given cancelPath", async () => {
|
|
77
|
+
await mount(<AuthLogin realmConfig={realmConfig} cancelPath="/home" />);
|
|
78
|
+
|
|
79
|
+
expect(cancelLink()?.getAttribute("href")).toBe("/home");
|
|
80
|
+
});
|
|
81
|
+
|
|
82
|
+
it("should hide the link when cancelPath is false", async () => {
|
|
83
|
+
await mount(<AuthLogin realmConfig={realmConfig} cancelPath={false} />);
|
|
84
|
+
|
|
85
|
+
expect(screen.queryByText("Sign up")).toBeTruthy();
|
|
86
|
+
expect(cancelLink()).toBeNull();
|
|
87
|
+
});
|
|
88
|
+
});
|
|
89
|
+
|
|
90
|
+
describe("AuthRegister", () => {
|
|
91
|
+
it("should lead to / by default", async () => {
|
|
92
|
+
await mount(<AuthRegister realmConfig={realmConfig} />);
|
|
93
|
+
|
|
94
|
+
expect(cancelLink()?.getAttribute("href")).toBe("/");
|
|
95
|
+
});
|
|
96
|
+
|
|
97
|
+
it("should hide the link when cancelPath is false", async () => {
|
|
98
|
+
await mount(
|
|
99
|
+
<AuthRegister realmConfig={realmConfig} cancelPath={false} />,
|
|
100
|
+
);
|
|
101
|
+
|
|
102
|
+
expect(cancelLink()).toBeNull();
|
|
103
|
+
});
|
|
104
|
+
});
|
|
105
|
+
|
|
106
|
+
describe("AuthResetPassword", () => {
|
|
107
|
+
it("should lead to / by default", async () => {
|
|
108
|
+
await mount(<AuthResetPassword realmConfig={realmConfig} />);
|
|
109
|
+
|
|
110
|
+
expect(cancelLink()?.getAttribute("href")).toBe("/");
|
|
111
|
+
});
|
|
112
|
+
|
|
113
|
+
it("should lead to the given cancelPath", async () => {
|
|
114
|
+
await mount(
|
|
115
|
+
<AuthResetPassword realmConfig={realmConfig} cancelPath="/home" />,
|
|
116
|
+
);
|
|
117
|
+
|
|
118
|
+
expect(cancelLink()?.getAttribute("href")).toBe("/home");
|
|
119
|
+
});
|
|
120
|
+
|
|
121
|
+
it("should hide the link when cancelPath is false", async () => {
|
|
122
|
+
await mount(
|
|
123
|
+
<AuthResetPassword realmConfig={realmConfig} cancelPath={false} />,
|
|
124
|
+
);
|
|
125
|
+
|
|
126
|
+
expect(cancelLink()).toBeNull();
|
|
127
|
+
});
|
|
128
|
+
});
|
|
129
|
+
});
|
package/src/core/Badge.tsx
CHANGED
|
@@ -47,6 +47,10 @@ const badgeVariants = cva(
|
|
|
47
47
|
* would fight them: before this was enforced, a `default` badge given a
|
|
48
48
|
* tone lost its primary fill to the tone's wash, since tailwind-merge
|
|
49
49
|
* keeps the last `bg-*`.
|
|
50
|
+
*
|
|
51
|
+
* success, warning and danger paint from the signal tokens, not fixed
|
|
52
|
+
* Tailwind hues, so colour-blind mode (`:root.cvd`) repaints them.
|
|
53
|
+
* info stays blue: blue is already safe under every common deficiency.
|
|
50
54
|
*/
|
|
51
55
|
tone: {
|
|
52
56
|
neutral: "",
|
|
@@ -70,17 +74,17 @@ const badgeVariants = cva(
|
|
|
70
74
|
{
|
|
71
75
|
variant: "tint",
|
|
72
76
|
tone: "success",
|
|
73
|
-
class: "border-
|
|
77
|
+
class: "border-success/40 bg-success/15",
|
|
74
78
|
},
|
|
75
79
|
{
|
|
76
80
|
variant: "tint",
|
|
77
81
|
tone: "warning",
|
|
78
|
-
class: "border-
|
|
82
|
+
class: "border-warning/40 bg-warning/15",
|
|
79
83
|
},
|
|
80
84
|
{
|
|
81
85
|
variant: "tint",
|
|
82
86
|
tone: "danger",
|
|
83
|
-
class: "border-
|
|
87
|
+
class: "border-danger/40 bg-danger/15",
|
|
84
88
|
},
|
|
85
89
|
],
|
|
86
90
|
defaultVariants: {
|
|
@@ -0,0 +1,95 @@
|
|
|
1
|
+
import { Collapsible as CollapsiblePrimitive } from "@base-ui/react/collapsible";
|
|
2
|
+
import { ChevronDownIcon } from "lucide-react";
|
|
3
|
+
|
|
4
|
+
import { cn } from "./utils.ts";
|
|
5
|
+
|
|
6
|
+
export type CollapsibleProps = CollapsiblePrimitive.Root.Props;
|
|
7
|
+
|
|
8
|
+
/**
|
|
9
|
+
* A disclosure: a trigger that opens and closes a panel, its height
|
|
10
|
+
* animated. Uncontrolled with `defaultOpen`, controlled with `open` and
|
|
11
|
+
* `onOpenChange`.
|
|
12
|
+
*
|
|
13
|
+
* ```tsx
|
|
14
|
+
* <Collapsible>
|
|
15
|
+
* <CollapsibleTrigger chevron>Advanced options</CollapsibleTrigger>
|
|
16
|
+
* <CollapsiblePanel>...</CollapsiblePanel>
|
|
17
|
+
* </Collapsible>
|
|
18
|
+
* ```
|
|
19
|
+
*
|
|
20
|
+
* The root and the panel carry `data-open` or `data-closed`, and the trigger
|
|
21
|
+
* `data-panel-open` while the panel is open, for the caller's own styles.
|
|
22
|
+
*/
|
|
23
|
+
const Collapsible = (props: CollapsibleProps) => {
|
|
24
|
+
return <CollapsiblePrimitive.Root data-slot="collapsible" {...props} />;
|
|
25
|
+
};
|
|
26
|
+
|
|
27
|
+
export interface CollapsibleTriggerProps
|
|
28
|
+
extends CollapsiblePrimitive.Trigger.Props {
|
|
29
|
+
/**
|
|
30
|
+
* Draw a chevron after the children, pointing down while closed and up
|
|
31
|
+
* while open. Defaults to `false`.
|
|
32
|
+
*/
|
|
33
|
+
chevron?: boolean;
|
|
34
|
+
}
|
|
35
|
+
|
|
36
|
+
/**
|
|
37
|
+
* The button that opens and closes the panel. It carries `aria-expanded` and
|
|
38
|
+
* `aria-controls`. Its own styles are minimal (a row of its children, a focus
|
|
39
|
+
* ring): pass `render={<Button variant="ghost" />}` for a button look.
|
|
40
|
+
*/
|
|
41
|
+
const CollapsibleTrigger = (props: CollapsibleTriggerProps) => {
|
|
42
|
+
const { className, chevron = false, children, ...rest } = props;
|
|
43
|
+
return (
|
|
44
|
+
<CollapsiblePrimitive.Trigger
|
|
45
|
+
data-slot="collapsible-trigger"
|
|
46
|
+
className={cn(
|
|
47
|
+
"group/collapsible-trigger focus-visible:ring-ring/50 inline-flex items-center gap-1.5 rounded-md text-sm font-medium outline-none focus-visible:ring-3 disabled:pointer-events-none disabled:opacity-50",
|
|
48
|
+
className,
|
|
49
|
+
)}
|
|
50
|
+
{...rest}
|
|
51
|
+
>
|
|
52
|
+
{children}
|
|
53
|
+
{chevron && (
|
|
54
|
+
<ChevronDownIcon
|
|
55
|
+
aria-hidden
|
|
56
|
+
data-slot="collapsible-chevron"
|
|
57
|
+
className="text-muted-foreground size-4 shrink-0 transition-transform duration-200 group-data-[panel-open]/collapsible-trigger:rotate-180 motion-reduce:transition-none"
|
|
58
|
+
/>
|
|
59
|
+
)}
|
|
60
|
+
</CollapsiblePrimitive.Trigger>
|
|
61
|
+
);
|
|
62
|
+
};
|
|
63
|
+
|
|
64
|
+
export type CollapsiblePanelProps = CollapsiblePrimitive.Panel.Props;
|
|
65
|
+
|
|
66
|
+
/**
|
|
67
|
+
* The panel the trigger opens. Its height runs from 0 to its content's
|
|
68
|
+
* through `--collapsible-panel-height`, which Base UI measures, and the
|
|
69
|
+
* transition is dropped under `prefers-reduced-motion`.
|
|
70
|
+
*
|
|
71
|
+
* Closed, it is not rendered, so nothing in it can take focus; on the server
|
|
72
|
+
* it renders open or not at all, per `defaultOpen`, and opens at its natural
|
|
73
|
+
* height, with no animation on the first paint. `keepMounted` keeps it in the
|
|
74
|
+
* DOM while closed (hidden), and `hiddenUntilFound` lets the browser's page
|
|
75
|
+
* search find and open it.
|
|
76
|
+
*
|
|
77
|
+
* It clips its content while it moves (`overflow-hidden`): give the content
|
|
78
|
+
* its own padding rather than the panel, so the height runs to the padding's
|
|
79
|
+
* edge too.
|
|
80
|
+
*/
|
|
81
|
+
const CollapsiblePanel = (props: CollapsiblePanelProps) => {
|
|
82
|
+
const { className, ...rest } = props;
|
|
83
|
+
return (
|
|
84
|
+
<CollapsiblePrimitive.Panel
|
|
85
|
+
data-slot="collapsible-panel"
|
|
86
|
+
className={cn(
|
|
87
|
+
"h-(--collapsible-panel-height) overflow-hidden transition-[height] duration-200 ease-out data-ending-style:h-0 data-starting-style:h-0 motion-reduce:transition-none",
|
|
88
|
+
className,
|
|
89
|
+
)}
|
|
90
|
+
{...rest}
|
|
91
|
+
/>
|
|
92
|
+
);
|
|
93
|
+
};
|
|
94
|
+
|
|
95
|
+
export { Collapsible, CollapsiblePanel, CollapsibleTrigger };
|
package/src/core/Combobox.tsx
CHANGED
|
@@ -19,10 +19,16 @@ const ComboboxValue = (props: ComboboxValueProps) => {
|
|
|
19
19
|
return <ComboboxPrimitive.Value data-slot="combobox-value" {...props} />;
|
|
20
20
|
};
|
|
21
21
|
|
|
22
|
-
export type ComboboxTriggerProps = ComboboxPrimitive.Trigger.Props
|
|
22
|
+
export type ComboboxTriggerProps = ComboboxPrimitive.Trigger.Props & {
|
|
23
|
+
/**
|
|
24
|
+
* Draw the trailing caret. Defaults to true; off for a trigger that is not
|
|
25
|
+
* a field, such as a table header's funnel button.
|
|
26
|
+
*/
|
|
27
|
+
chevron?: boolean;
|
|
28
|
+
};
|
|
23
29
|
|
|
24
30
|
const ComboboxTrigger = (props: ComboboxTriggerProps) => {
|
|
25
|
-
const { className, children, ...rest } = props;
|
|
31
|
+
const { className, children, chevron = true, ...rest } = props;
|
|
26
32
|
return (
|
|
27
33
|
<ComboboxPrimitive.Trigger
|
|
28
34
|
data-slot="combobox-trigger"
|
|
@@ -30,7 +36,9 @@ const ComboboxTrigger = (props: ComboboxTriggerProps) => {
|
|
|
30
36
|
{...rest}
|
|
31
37
|
>
|
|
32
38
|
{children}
|
|
33
|
-
|
|
39
|
+
{chevron && (
|
|
40
|
+
<ChevronDownIcon className="text-muted-foreground pointer-events-none size-4" />
|
|
41
|
+
)}
|
|
34
42
|
</ComboboxPrimitive.Trigger>
|
|
35
43
|
);
|
|
36
44
|
};
|
package/src/core/PaneRail.tsx
CHANGED
|
@@ -1,4 +1,5 @@
|
|
|
1
1
|
import { PanelLeftOpen, PanelRightOpen } from "lucide-react";
|
|
2
|
+
import type { ReactNode } from "react";
|
|
2
3
|
|
|
3
4
|
import { cn } from "./utils.ts";
|
|
4
5
|
|
|
@@ -13,48 +14,63 @@ export interface PaneRailProps {
|
|
|
13
14
|
*/
|
|
14
15
|
label: string;
|
|
15
16
|
onExpand: () => void;
|
|
17
|
+
/**
|
|
18
|
+
* The pane's own icon, at the top of the strip. Given one, the rail names
|
|
19
|
+
* WHAT it reopens, and the open-panel arrow moves to the strip's foot so
|
|
20
|
+
* the strip still says it opens something. Without one the arrow is the
|
|
21
|
+
* only mark, at the top.
|
|
22
|
+
*/
|
|
23
|
+
icon?: ReactNode;
|
|
24
|
+
/**
|
|
25
|
+
* Shown under the top icon: a count badge, say. Not separately
|
|
26
|
+
* actionable, since the whole strip is the button.
|
|
27
|
+
*/
|
|
28
|
+
children?: ReactNode;
|
|
16
29
|
className?: string;
|
|
30
|
+
"data-testid"?: string;
|
|
17
31
|
}
|
|
18
32
|
|
|
19
33
|
/**
|
|
20
|
-
* What a collapsible pane leaves behind once it is closed: a 36px strip
|
|
21
|
-
* the
|
|
34
|
+
* What a collapsible pane leaves behind once it is closed: a 36px strip that
|
|
35
|
+
* is, all of it, the button that brings the pane back.
|
|
22
36
|
*
|
|
23
37
|
* A pane closed with a click has to say how to reopen it. Collapsing to
|
|
24
38
|
* nothing strands the reader: the only routes back left are a keyboard
|
|
25
39
|
* shortcut and a menu that does not advertise itself, for a pane they just
|
|
26
40
|
* closed with a click.
|
|
27
41
|
*
|
|
28
|
-
*
|
|
29
|
-
*
|
|
30
|
-
*
|
|
31
|
-
*
|
|
32
|
-
*
|
|
42
|
+
* The whole strip is the hit area, hover included, rather than a small
|
|
43
|
+
* button at its top: the strip has no other use, and a 28px target inside a
|
|
44
|
+
* full-height column reads as broken when a click below it does nothing.
|
|
45
|
+
*
|
|
46
|
+
* It moved from Lore into the kit with #Q2265 and became one full-height
|
|
47
|
+
* button with #Q3206, so the admin Parameters History panel, Lore's folio
|
|
48
|
+
* tree and inspector, and Lore's Quest Log (`icon` plus a count as
|
|
49
|
+
* `children`) share one strip and cannot drift apart.
|
|
33
50
|
*
|
|
34
51
|
* ⚠️ Render it only where the pane would otherwise be a COLUMN. Where a
|
|
35
52
|
* layout stacks its panes or turns one into an overlay, a strip frees no
|
|
36
53
|
* width and only changes the default layout.
|
|
37
54
|
*/
|
|
38
55
|
export const PaneRail = (props: PaneRailProps) => {
|
|
39
|
-
const
|
|
56
|
+
const Arrow = props.side === "left" ? PanelLeftOpen : PanelRightOpen;
|
|
40
57
|
|
|
41
58
|
return (
|
|
42
|
-
<
|
|
59
|
+
<button
|
|
60
|
+
type="button"
|
|
61
|
+
onClick={props.onExpand}
|
|
62
|
+
aria-label={props.label}
|
|
63
|
+
title={props.label}
|
|
64
|
+
data-testid={props["data-testid"]}
|
|
43
65
|
className={cn(
|
|
44
|
-
"border-border flex w-9 flex-none flex-col items-center pt-
|
|
66
|
+
"border-border text-muted-foreground hover:text-foreground hover:bg-hover focus-visible:ring-ring/50 flex w-9 flex-none cursor-pointer flex-col items-center gap-2 pt-3 transition-colors outline-none focus-visible:ring-3 focus-visible:ring-inset",
|
|
45
67
|
props.side === "left" ? "border-r" : "border-l",
|
|
46
68
|
props.className,
|
|
47
69
|
)}
|
|
48
70
|
>
|
|
49
|
-
<
|
|
50
|
-
|
|
51
|
-
|
|
52
|
-
|
|
53
|
-
title={props.label}
|
|
54
|
-
className="text-muted-foreground hover:text-foreground hover:bg-hover flex size-7 items-center justify-center rounded-md transition-colors"
|
|
55
|
-
>
|
|
56
|
-
<Icon className="size-4" />
|
|
57
|
-
</button>
|
|
58
|
-
</div>
|
|
71
|
+
{props.icon ?? <Arrow className="size-4 shrink-0" />}
|
|
72
|
+
{props.children}
|
|
73
|
+
{props.icon && <Arrow className="mt-auto mb-3 size-3.5 shrink-0" />}
|
|
74
|
+
</button>
|
|
59
75
|
);
|
|
60
76
|
};
|