@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
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"ParameterHistoryItem.js","names":[],"sources":["../../src/admin/ParameterHistoryItem.tsx"],"sourcesContent":["import * as React from \"react\";\n\nimport TimeAgo from \"../core/TimeAgo.tsx\";\n\nvoid React;\n\nimport type { AdminParameterController } from \"alepha/api/parameters\";\nimport { useI18n } from \"alepha/react/i18n\";\nimport { useRouter } from \"alepha/react/router\";\nimport {\n Archive,\n ChevronRight,\n CircleCheck,\n Clock,\n Eye,\n GitCompare,\n MoreVertical,\n RotateCcw,\n Tag,\n} from \"lucide-react\";\nimport { useState } from \"react\";\n\nimport { Badge } from \"../core/Badge.tsx\";\nimport { Button } from \"../core/Button.tsx\";\nimport {\n DropdownMenu,\n DropdownMenuContent,\n DropdownMenuItem,\n DropdownMenuSeparator,\n DropdownMenuTrigger,\n} from \"../core/DropdownMenu.tsx\";\nimport { cn } from \"../core/utils.ts\";\nimport { ParameterDiffDialog } from \"./ParameterDiffDialog.tsx\";\nimport { ParameterJsonDialog } from \"./ParameterJsonDialog.tsx\";\n\ntype HistoryVersion = Awaited<\n ReturnType<AdminParameterController[\"getHistory\"]>\n>[\"versions\"][number];\n\nexport interface ParameterHistoryItemProps {\n version: HistoryVersion;\n onRollback: (version: number) => void | Promise<void>;\n}\n\n/**\n * One parameter version, rendered as a flush, square row in the history stack.\n *\n * The whole header row toggles the body (version / created-at / created-by /\n * tags). The `…` menu (View JSON / Diff with previous / Rollback) stops click\n * propagation so using it never toggles the row.\n */\nexport const ParameterHistoryItem = (props: ParameterHistoryItemProps) => {\n const { l, tr } = useI18n();\n const router = useRouter();\n const v = props.version;\n const [open, setOpen] = useState(false);\n const [jsonOpen, setJsonOpen] = useState(false);\n const [diffOpen, setDiffOpen] = useState(false);\n\n const hasPrevious = v.previousContent != null;\n const isCurrent = v.status === \"current\";\n const toggle = () => setOpen((o) => !o);\n\n return (\n <div className=\"border-b\">\n <div\n role=\"button\"\n tabIndex={0}\n onClick={toggle}\n onKeyDown={(e) => {\n if (e.key === \"Enter\" || e.key === \" \") {\n e.preventDefault();\n toggle();\n }\n }}\n className=\"hover:bg-hover flex items-center gap-2 px-3 py-2.5 transition-colors select-none\"\n >\n <span className=\"text-muted-foreground flex size-4 shrink-0 items-center justify-center\">\n {statusIcon(v.status)}\n </span>\n <div className=\"ml-1 flex min-w-0 flex-1 flex-col gap-0.5\">\n <span className=\"text-sm leading-tight font-semibold capitalize\">\n {v.status}\n </span>\n <span className=\"text-muted-foreground flex items-center gap-1 text-xs leading-tight\">\n <Clock className=\"size-3\" />\n <TimeAgo value={v.activationDate} />\n </span>\n </div>\n {/* Actions: intercept clicks so the menu never toggles the row. */}\n {/* Row expander; the toggle button inside is the control. */}\n {/* oxlint-disable-next-line jsx-a11y/no-static-element-interactions -- a row expander, the toggle button inside is the control */}\n <div\n className=\"shrink-0\"\n onClick={(e) => e.stopPropagation()}\n onKeyDown={(e) => e.stopPropagation()}\n >\n <DropdownMenu>\n <DropdownMenuTrigger\n render={\n <Button\n variant=\"minimal\"\n size=\"icon\"\n className=\"size-6\"\n aria-label={tr(\"admin.parameters.versionActions\", {\n default: \"Version actions\",\n })}\n />\n }\n >\n <MoreVertical className=\"size-4\" />\n </DropdownMenuTrigger>\n <DropdownMenuContent align=\"end\">\n <DropdownMenuItem onClick={() => setJsonOpen(true)}>\n <Eye className=\"mr-2 size-4\" />\n {tr(\"admin.parameters.view\", { default: \"View\" })}\n </DropdownMenuItem>\n {hasPrevious && (\n <DropdownMenuItem onClick={() => setDiffOpen(true)}>\n <GitCompare className=\"mr-2 size-4\" />\n {tr(\"admin.parameters.diffWithPrevious\", {\n default: \"Diff with previous\",\n })}\n </DropdownMenuItem>\n )}\n {!isCurrent && (\n <>\n <DropdownMenuSeparator />\n <DropdownMenuItem onClick={() => props.onRollback(v.version)}>\n <RotateCcw className=\"mr-2 size-4\" />\n {tr(\"admin.parameters.rollback\", { default: \"Rollback\" })}\n </DropdownMenuItem>\n </>\n )}\n </DropdownMenuContent>\n </DropdownMenu>\n </div>\n <span className=\"text-muted-foreground flex size-4 shrink-0 items-center justify-center\">\n <ChevronRight\n className={cn(\n \"size-4 transition-transform duration-200\",\n open && \"rotate-90\",\n )}\n />\n </span>\n </div>\n\n {/* Animated collapse: grid-rows 0fr→1fr smoothly interpolates height\n without measuring. The body stays mounted so the transition runs. */}\n <div\n className={cn(\n \"grid transition-[grid-template-rows] duration-200 ease-out\",\n open ? \"grid-rows-[1fr]\" : \"grid-rows-[0fr]\",\n )}\n >\n <div className=\"overflow-hidden\">\n <div className=\"border-t px-3 py-2.5\">\n <dl className=\"grid grid-cols-[auto_1fr] gap-x-3 gap-y-1.5 text-xs\">\n <dt className=\"text-muted-foreground\">\n {tr(\"admin.parameters.fieldVersion\", { default: \"Version\" })}\n </dt>\n <dd className=\"font-mono font-medium\">v{v.version}</dd>\n\n <dt className=\"text-muted-foreground\">\n {tr(\"admin.parameters.fieldCreatedAt\", {\n default: \"Created at\",\n })}\n </dt>\n <dd>{l(v.createdAt, { date: \"lll\" })}</dd>\n\n <dt className=\"text-muted-foreground\">\n {tr(\"admin.parameters.fieldCreatedBy\", {\n default: \"Created by\",\n })}\n </dt>\n <dd className=\"truncate\">\n {v.creatorId ? (\n <button\n type=\"button\"\n className=\"text-primary truncate hover:underline\"\n onClick={() => router.push(`/admin/users/${v.creatorId}`)}\n >\n {v.creator?.username ??\n v.creator?.email ??\n v.creatorName ??\n v.creatorId}\n </button>\n ) : (\n (v.creatorName ?? \"—\")\n )}\n </dd>\n\n {v.changeDescription && (\n <>\n <dt className=\"text-muted-foreground\">\n {tr(\"admin.parameters.fieldNote\", { default: \"Note\" })}\n </dt>\n <dd className=\"leading-snug\">{v.changeDescription}</dd>\n </>\n )}\n\n {v.tags && v.tags.length > 0 && (\n <>\n <dt className=\"text-muted-foreground flex items-center gap-1\">\n <Tag className=\"size-3\" />\n {tr(\"admin.parameters.fieldTags\", { default: \"Tags\" })}\n </dt>\n <dd className=\"flex flex-wrap gap-1\">\n {v.tags.map((tag) => (\n <Badge\n key={tag}\n variant=\"outline\"\n className=\"text-[10px]\"\n >\n {tag}\n </Badge>\n ))}\n </dd>\n </>\n )}\n </dl>\n </div>\n </div>\n </div>\n\n <ParameterJsonDialog\n open={jsonOpen}\n onOpenChange={setJsonOpen}\n title={`v${v.version} — ${v.name}`}\n content={v.content}\n />\n {hasPrevious && (\n <ParameterDiffDialog\n open={diffOpen}\n onOpenChange={setDiffOpen}\n title={`v${v.version} — ${v.name}`}\n previous={v.previousContent}\n current={v.content}\n />\n )}\n </div>\n );\n};\n\nconst statusIcon = (status: HistoryVersion[\"status\"]) => {\n if (status === \"current\") {\n return (\n <CircleCheck className=\"size-4 text-emerald-600 dark:text-emerald-400\" />\n );\n }\n if (status === \"expired\") return <Archive className=\"size-4\" />;\n return <Clock className=\"size-4\" />;\n};\n"],"mappings":";;;;;;;;;;;;;;;;;;;;AAmDA,MAAa,wBAAwB,UAAqC;CACxE,MAAM,EAAE,GAAG,OAAO,QAAQ;CAC1B,MAAM,SAAS,UAAU;CACzB,MAAM,IAAI,MAAM;CAChB,MAAM,CAAC,MAAM,WAAW,SAAS,KAAK;CACtC,MAAM,CAAC,UAAU,eAAe,SAAS,KAAK;CAC9C,MAAM,CAAC,UAAU,eAAe,SAAS,KAAK;CAE9C,MAAM,cAAc,EAAE,mBAAmB;CACzC,MAAM,YAAY,EAAE,WAAW;CAC/B,MAAM,eAAe,SAAS,MAAM,CAAC,CAAC;CAEtC,OACE,qBAAC,OAAD;EAAK,WAAU;EAAf,UAA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E,eAAe;QAElB,CAAA;QAEH,EAAE,qBACD,qBAAA,YAAA,EAAA,UAAA,CACE,oBAAC,MAAD;SAAI,WAAU;SACX,UAAA,GAAG,8BAA8B,EAAE,SAAS,OAAO,CAAC;QACnD,CAAA,GACJ,oBAAC,MAAD;SAAI,WAAU;SAAgB,UAAA,EAAE;QAAsB,CAAA,CACtD,EAAA,CAAA;QAGH,EAAE,QAAQ,EAAE,KAAK,SAAS,KACzB,qBAAA,YAAA,EAAA,UAAA,CACE,qBAAC,MAAD;SAAI,WAAU;SAAd,UAAA,CACE,oBAAC,KAAD,EAAK,WAAU,SAAU,CAAA,GACxB,GAAG,8BAA8B,EAAE,SAAS,OAAO,CAAC,CACnD;QACJ,CAAA,GAAA,oBAAC,MAAD;SAAI,WAAU;SACX,UAAA,EAAE,KAAK,KAAK,QACX,oBAAC,OAAD;UAEE,SAAQ;UACR,WAAU;UAET,UAAA;SACI,GALA,GAKA,CACR;QACC,CAAA,CACJ,EAAA,CAAA;OAEF;;KACD,CAAA;IACF,CAAA;GACF,CAAA;GAEL,oBAAC,qBAAD;IACE,MAAM;IACN,cAAc;IACd,OAAO,IAAI,EAAE,QAAQ,KAAK,EAAE;IAC5B,SAAS,EAAE;GACZ,CAAA;GACA,eACC,oBAAC,qBAAD;IACE,MAAM;IACN,cAAc;IACd,OAAO,IAAI,EAAE,QAAQ,KAAK,EAAE;IAC5B,UAAU,EAAE;IACZ,SAAS,EAAE;GACZ,CAAA;EAEA;;AAET;AAEA,MAAM,cAAc,WAAqC;CACvD,IAAI,WAAW,WACb,OACE,oBAAC,aAAD,EAAa,WAAU,gDAAiD,CAAA;CAG5E,IAAI,WAAW,WAAW,OAAO,oBAAC,SAAD,EAAS,WAAU,SAAU,CAAA;CAC9D,OAAO,oBAAC,OAAD,EAAO,WAAU,SAAU,CAAA;AACpC"}
|
|
1
|
+
{"version":3,"file":"ParameterHistoryItem.js","names":[],"sources":["../../src/admin/ParameterHistoryItem.tsx"],"sourcesContent":["import * as React from \"react\";\n\nimport TimeAgo from \"../core/TimeAgo.tsx\";\n\nvoid React;\n\nimport type { AdminParameterController } from \"alepha/api/parameters\";\nimport { useI18n } from \"alepha/react/i18n\";\nimport { useRouter } from \"alepha/react/router\";\nimport {\n Archive,\n ChevronRight,\n CircleCheck,\n Clock,\n Eye,\n GitCompare,\n MoreVertical,\n RotateCcw,\n Tag,\n} from \"lucide-react\";\nimport { useState } from \"react\";\n\nimport { Badge } from \"../core/Badge.tsx\";\nimport { Button } from \"../core/Button.tsx\";\nimport {\n DropdownMenu,\n DropdownMenuContent,\n DropdownMenuItem,\n DropdownMenuSeparator,\n DropdownMenuTrigger,\n} from \"../core/DropdownMenu.tsx\";\nimport { cn } from \"../core/utils.ts\";\nimport { ParameterDiffDialog } from \"./ParameterDiffDialog.tsx\";\nimport { ParameterJsonDialog } from \"./ParameterJsonDialog.tsx\";\n\ntype HistoryVersion = Awaited<\n ReturnType<AdminParameterController[\"getHistory\"]>\n>[\"versions\"][number];\n\nexport interface ParameterHistoryItemProps {\n version: HistoryVersion;\n onRollback: (version: number) => void | Promise<void>;\n}\n\n/**\n * One parameter version, rendered as a flush, square row in the history stack.\n *\n * The whole header row toggles the body (version / created-at / created-by /\n * tags). The `…` menu (View JSON / Diff with previous / Rollback) stops click\n * propagation so using it never toggles the row.\n */\nexport const ParameterHistoryItem = (props: ParameterHistoryItemProps) => {\n const { l, tr } = useI18n();\n const router = useRouter<any>();\n const v = props.version;\n const [open, setOpen] = useState(false);\n const [jsonOpen, setJsonOpen] = useState(false);\n const [diffOpen, setDiffOpen] = useState(false);\n\n const hasPrevious = v.previousContent != null;\n const isCurrent = v.status === \"current\";\n const toggle = () => setOpen((o) => !o);\n\n return (\n <div className=\"border-b\">\n <div\n role=\"button\"\n tabIndex={0}\n onClick={toggle}\n onKeyDown={(e) => {\n if (e.key === \"Enter\" || e.key === \" \") {\n e.preventDefault();\n toggle();\n }\n }}\n className=\"hover:bg-hover flex items-center gap-2 px-3 py-2.5 transition-colors select-none\"\n >\n <span className=\"text-muted-foreground flex size-4 shrink-0 items-center justify-center\">\n {statusIcon(v.status)}\n </span>\n <div className=\"ml-1 flex min-w-0 flex-1 flex-col gap-0.5\">\n <span className=\"text-sm leading-tight font-semibold capitalize\">\n {v.status}\n </span>\n <span className=\"text-muted-foreground flex items-center gap-1 text-xs leading-tight\">\n <Clock className=\"size-3\" />\n <TimeAgo value={v.activationDate} />\n </span>\n </div>\n {/* Actions: intercept clicks so the menu never toggles the row. */}\n {/* Row expander; the toggle button inside is the control. */}\n {/* oxlint-disable-next-line jsx-a11y/no-static-element-interactions -- a row expander, the toggle button inside is the control */}\n <div\n className=\"shrink-0\"\n onClick={(e) => e.stopPropagation()}\n onKeyDown={(e) => e.stopPropagation()}\n >\n <DropdownMenu>\n <DropdownMenuTrigger\n render={\n <Button\n variant=\"minimal\"\n size=\"icon\"\n className=\"size-6\"\n aria-label={tr(\"admin.parameters.versionActions\", {\n default: \"Version actions\",\n })}\n />\n }\n >\n <MoreVertical className=\"size-4\" />\n </DropdownMenuTrigger>\n <DropdownMenuContent align=\"end\">\n <DropdownMenuItem onClick={() => setJsonOpen(true)}>\n <Eye className=\"mr-2 size-4\" />\n {tr(\"admin.parameters.view\", { default: \"View\" })}\n </DropdownMenuItem>\n {hasPrevious && (\n <DropdownMenuItem onClick={() => setDiffOpen(true)}>\n <GitCompare className=\"mr-2 size-4\" />\n {tr(\"admin.parameters.diffWithPrevious\", {\n default: \"Diff with previous\",\n })}\n </DropdownMenuItem>\n )}\n {!isCurrent && (\n <>\n <DropdownMenuSeparator />\n <DropdownMenuItem onClick={() => props.onRollback(v.version)}>\n <RotateCcw className=\"mr-2 size-4\" />\n {tr(\"admin.parameters.rollback\", { default: \"Rollback\" })}\n </DropdownMenuItem>\n </>\n )}\n </DropdownMenuContent>\n </DropdownMenu>\n </div>\n <span className=\"text-muted-foreground flex size-4 shrink-0 items-center justify-center\">\n <ChevronRight\n className={cn(\n \"size-4 transition-transform duration-200\",\n open && \"rotate-90\",\n )}\n />\n </span>\n </div>\n\n {/* Animated collapse: grid-rows 0fr→1fr smoothly interpolates height\n without measuring. The body stays mounted so the transition runs. */}\n <div\n className={cn(\n \"grid transition-[grid-template-rows] duration-200 ease-out\",\n open ? \"grid-rows-[1fr]\" : \"grid-rows-[0fr]\",\n )}\n >\n <div className=\"overflow-hidden\">\n <div className=\"border-t px-3 py-2.5\">\n <dl className=\"grid grid-cols-[auto_1fr] gap-x-3 gap-y-1.5 text-xs\">\n <dt className=\"text-muted-foreground\">\n {tr(\"admin.parameters.fieldVersion\", { default: \"Version\" })}\n </dt>\n <dd className=\"font-mono font-medium\">v{v.version}</dd>\n\n <dt className=\"text-muted-foreground\">\n {tr(\"admin.parameters.fieldCreatedAt\", {\n default: \"Created at\",\n })}\n </dt>\n <dd>{l(v.createdAt, { date: \"lll\" })}</dd>\n\n <dt className=\"text-muted-foreground\">\n {tr(\"admin.parameters.fieldCreatedBy\", {\n default: \"Created by\",\n })}\n </dt>\n <dd className=\"truncate\">\n {v.creatorId ? (\n <button\n type=\"button\"\n className=\"text-primary truncate hover:underline\"\n onClick={() => router.push(`/admin/users/${v.creatorId}`)}\n >\n {v.creator?.username ??\n v.creator?.email ??\n v.creatorName ??\n v.creatorId}\n </button>\n ) : (\n (v.creatorName ?? \"—\")\n )}\n </dd>\n\n {v.changeDescription && (\n <>\n <dt className=\"text-muted-foreground\">\n {tr(\"admin.parameters.fieldNote\", { default: \"Note\" })}\n </dt>\n <dd className=\"leading-snug\">{v.changeDescription}</dd>\n </>\n )}\n\n {v.tags && v.tags.length > 0 && (\n <>\n <dt className=\"text-muted-foreground flex items-center gap-1\">\n <Tag className=\"size-3\" />\n {tr(\"admin.parameters.fieldTags\", { default: \"Tags\" })}\n </dt>\n <dd className=\"flex flex-wrap gap-1\">\n {v.tags.map((tag) => (\n <Badge\n key={tag}\n variant=\"outline\"\n className=\"text-[10px]\"\n >\n {tag}\n </Badge>\n ))}\n </dd>\n </>\n )}\n </dl>\n </div>\n </div>\n </div>\n\n <ParameterJsonDialog\n open={jsonOpen}\n onOpenChange={setJsonOpen}\n title={`v${v.version} — ${v.name}`}\n content={v.content}\n />\n {hasPrevious && (\n <ParameterDiffDialog\n open={diffOpen}\n onOpenChange={setDiffOpen}\n title={`v${v.version} — ${v.name}`}\n previous={v.previousContent}\n current={v.content}\n />\n )}\n </div>\n );\n};\n\nconst statusIcon = (status: HistoryVersion[\"status\"]) => {\n if (status === \"current\") {\n return (\n <CircleCheck className=\"size-4 text-emerald-600 dark:text-emerald-400\" />\n );\n }\n if (status === \"expired\") return <Archive className=\"size-4\" />;\n return <Clock className=\"size-4\" />;\n};\n"],"mappings":";;;;;;;;;;;;;;;;;;;;AAmDA,MAAa,wBAAwB,UAAqC;CACxE,MAAM,EAAE,GAAG,OAAO,QAAQ;CAC1B,MAAM,SAAS,UAAe;CAC9B,MAAM,IAAI,MAAM;CAChB,MAAM,CAAC,MAAM,WAAW,SAAS,KAAK;CACtC,MAAM,CAAC,UAAU,eAAe,SAAS,KAAK;CAC9C,MAAM,CAAC,UAAU,eAAe,SAAS,KAAK;CAE9C,MAAM,cAAc,EAAE,mBAAmB;CACzC,MAAM,YAAY,EAAE,WAAW;CAC/B,MAAM,eAAe,SAAS,MAAM,CAAC,CAAC;CAEtC,OACE,qBAAC,OAAD;EAAK,WAAU;EAAf,UAAA;GACE,qBAAC,OAAD;IACE,MAAK;IACL,UAAU;IACV,SAAS;IACT,YAAY,MAAM;KAChB,IAAI,EAAE,QAAQ,WAAW,EAAE,QAAQ,KAAK;MACtC,EAAE,eAAe;MACjB,OAAO;KACT;IACF;IACA,WAAU;IAVZ,UAAA;KAYE,oBAAC,QAAD;MAAM,WAAU;MACb,UAAA,WAAW,EAAE,MAAM;KAChB,CAAA;KACN,qBAAC,OAAD;MAAK,WAAU;MAAf,UAAA,CACE,oBAAC,QAAD;OAAM,WAAU;OACb,UAAA,EAAE;MACC,CAAA,GACN,qBAAC,QAAD;OAAM,WAAU;OAAh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ACxB,GAAG,8BAA8B,EAAE,SAAS,OAAO,CAAC,CACnD;QACJ,CAAA,GAAA,oBAAC,MAAD;SAAI,WAAU;SACX,UAAA,EAAE,KAAK,KAAK,QACX,oBAAC,OAAD;UAEE,SAAQ;UACR,WAAU;UAET,UAAA;SACI,GALA,GAKA,CACR;QACC,CAAA,CACJ,EAAA,CAAA;OAEF;;KACD,CAAA;IACF,CAAA;GACF,CAAA;GAEL,oBAAC,qBAAD;IACE,MAAM;IACN,cAAc;IACd,OAAO,IAAI,EAAE,QAAQ,KAAK,EAAE;IAC5B,SAAS,EAAE;GACZ,CAAA;GACA,eACC,oBAAC,qBAAD;IACE,MAAM;IACN,cAAc;IACd,OAAO,IAAI,EAAE,QAAQ,KAAK,EAAE;IAC5B,UAAU,EAAE;IACZ,SAAS,EAAE;GACZ,CAAA;EAEA;;AAET;AAEA,MAAM,cAAc,WAAqC;CACvD,IAAI,WAAW,WACb,OACE,oBAAC,aAAD,EAAa,WAAU,gDAAiD,CAAA;CAG5E,IAAI,WAAW,WAAW,OAAO,oBAAC,SAAD,EAAS,WAAU,SAAU,CAAA;CAC9D,OAAO,oBAAC,OAAD,EAAO,WAAU,SAAU,CAAA;AACpC"}
|
package/dist/ai/AiChat.d.ts
CHANGED
|
@@ -1,60 +1,47 @@
|
|
|
1
|
-
import { type
|
|
2
|
-
import { type MarkdownLinkRenderer } from "../markdown/MarkdownView.tsx";
|
|
3
|
-
import { type AiChatConfirmCardProps } from "./AiChatConfirmCard.tsx";
|
|
4
|
-
import { type AiChatSuggestion } from "./AiChatEmpty.tsx";
|
|
5
|
-
import { type AiChatToolLabel } from "./AiChatMessage.tsx";
|
|
1
|
+
import { type AiChatViewProps } from "./AiChatPanel.tsx";
|
|
6
2
|
import { type UseAiChatOptions } from "./useAiChat.ts";
|
|
7
|
-
|
|
3
|
+
/**
|
|
4
|
+
* Where the conversation sits.
|
|
5
|
+
* - `drawer`: a modal drawer from the right, over a dimmed page.
|
|
6
|
+
* - `dock`: a panel beside the page, which stays readable and usable
|
|
7
|
+
* (see `AiChatDock`), and folds into a pill.
|
|
8
|
+
* - `auto`: the dock from 1024px up, the drawer below, where a page has no
|
|
9
|
+
* width to give.
|
|
10
|
+
*/
|
|
11
|
+
export type AiChatMode = "auto" | "dock" | "drawer";
|
|
12
|
+
export interface AiChatProps extends UseAiChatOptions, AiChatViewProps {
|
|
8
13
|
open: boolean;
|
|
9
14
|
onOpenChange: (open: boolean) => void;
|
|
10
15
|
/**
|
|
11
|
-
*
|
|
12
|
-
*/
|
|
13
|
-
title?: string;
|
|
14
|
-
/**
|
|
15
|
-
* Offer the list of past conversations, in a header menu. Default true.
|
|
16
|
+
* Where the conversation sits. Defaults to `drawer`.
|
|
16
17
|
*/
|
|
17
|
-
|
|
18
|
-
/**
|
|
19
|
-
* Questions a new conversation offers to start from.
|
|
20
|
-
*/
|
|
21
|
-
suggestions?: AiChatSuggestion[];
|
|
22
|
-
/**
|
|
23
|
-
* Names each tool step in the user's words ("Searched clients"), running
|
|
24
|
-
* and done. Without it a step shows the tool's own name.
|
|
25
|
-
*/
|
|
26
|
-
toolLabel?: AiChatToolLabel;
|
|
27
|
-
/**
|
|
28
|
-
* A confirmation card per tool name, in place of the generic field list:
|
|
29
|
-
* an app shows a booking as a booking. It gets the pending call as the
|
|
30
|
-
* server stored it, and the approve and deny callbacks.
|
|
31
|
-
*/
|
|
32
|
-
confirmCards?: Record<string, ComponentType<AiChatConfirmCardProps>>;
|
|
33
|
-
/**
|
|
34
|
-
* How links in the assistant's replies render (`MarkdownView`'s
|
|
35
|
-
* `renderLink`): route the paths the app knows, leave the rest as text.
|
|
36
|
-
*/
|
|
37
|
-
renderLink?: MarkdownLinkRenderer;
|
|
18
|
+
mode?: AiChatMode;
|
|
38
19
|
}
|
|
39
20
|
/**
|
|
40
|
-
* The assistant in a drawer
|
|
41
|
-
*
|
|
42
|
-
*
|
|
43
|
-
*
|
|
44
|
-
*
|
|
21
|
+
* The assistant: the conversation of `AiChatPanel`, in a drawer or a dock.
|
|
22
|
+
* It knows the page through `useAiContext()`, and runs `navigate` and
|
|
23
|
+
* `fillForm` for the model. The conversation lives here, so it survives a
|
|
24
|
+
* close, a minimize and a switch between drawer and dock.
|
|
25
|
+
*
|
|
26
|
+
* A docked chat minimizes into a pill (`AiChatLauncher`): it reports itself
|
|
27
|
+
* closed through `onOpenChange(false)`, so the app's own button opens it
|
|
28
|
+
* again, and the pill does too.
|
|
45
29
|
*
|
|
46
|
-
* Needs `AlephaApiAi` on the server and a `$ai` declared by the app.
|
|
30
|
+
* Needs `AlephaApiAi` on the server and a `$ai` declared by the app. A dock
|
|
31
|
+
* needs an `AiChatDockSlot` in the layout to make room for it (`AppShell`'s
|
|
32
|
+
* `aside`); without one it floats over the page's right edge.
|
|
47
33
|
*
|
|
48
34
|
* @example
|
|
49
35
|
* ```tsx
|
|
50
36
|
* const [open, setOpen] = useState(false);
|
|
51
37
|
* <Button onClick={() => setOpen(true)}>Ask</Button>
|
|
52
38
|
* <AiChat
|
|
39
|
+
* mode="auto"
|
|
53
40
|
* open={open}
|
|
54
41
|
* onOpenChange={setOpen}
|
|
55
42
|
* suggestions={[{ label: "Who still owes today?" }]}
|
|
56
43
|
* />
|
|
57
44
|
* ```
|
|
58
45
|
*/
|
|
59
|
-
export declare const AiChat: (props: AiChatProps) => import("react").JSX.Element;
|
|
46
|
+
export declare const AiChat: (props: AiChatProps) => import("react").JSX.Element | null;
|
|
60
47
|
//# sourceMappingURL=AiChat.d.ts.map
|
package/dist/ai/AiChat.d.ts.map
CHANGED
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"AiChat.d.ts","sourceRoot":"","sources":["../../src/ai/AiChat.tsx"],"names":[],"mappings":"
|
|
1
|
+
{"version":3,"file":"AiChat.d.ts","sourceRoot":"","sources":["../../src/ai/AiChat.tsx"],"names":[],"mappings":"AAKA,OAAO,EAAe,KAAK,eAAe,EAAE,MAAM,mBAAmB,CAAC;AACtE,OAAO,EAAE,KAAK,gBAAgB,EAAa,MAAM,gBAAgB,CAAC;AAElE;;;;;;;GAOG;AACH,MAAM,MAAM,UAAU,GAAG,MAAM,GAAG,MAAM,GAAG,QAAQ,CAAC;AAEpD,MAAM,WAAW,WAAY,SAAQ,gBAAgB,EAAE,eAAe;IACpE,IAAI,EAAE,OAAO,CAAC;IACd,YAAY,EAAE,CAAC,IAAI,EAAE,OAAO,KAAK,IAAI,CAAC;IACtC;;OAEG;IACH,IAAI,CAAC,EAAE,UAAU,CAAC;CACnB;AAqBD;;;;;;;;;;;;;;;;;;;;;;;;;GAyBG;AACH,eAAO,MAAM,MAAM,UAAW,WAAW,uCAmExC,CAAC"}
|
package/dist/ai/AiChat.js
CHANGED
|
@@ -1,33 +1,42 @@
|
|
|
1
|
-
import {
|
|
2
|
-
import {
|
|
3
|
-
import {
|
|
4
|
-
import {
|
|
5
|
-
import { MarkdownView } from "../markdown/MarkdownView.js";
|
|
6
|
-
import { AiChatComposer } from "./AiChatComposer.js";
|
|
7
|
-
import { AiChatConfirmCard } from "./AiChatConfirmCard.js";
|
|
8
|
-
import { AiChatEmpty } from "./AiChatEmpty.js";
|
|
9
|
-
import { AiChatHistory } from "./AiChatHistory.js";
|
|
10
|
-
import { AiChatMessage } from "./AiChatMessage.js";
|
|
1
|
+
import { Drawer, DrawerContent, DrawerTitle } from "../core/Drawer.js";
|
|
2
|
+
import { AiChatDock } from "./AiChatDock.js";
|
|
3
|
+
import { AiChatLauncher } from "./AiChatLauncher.js";
|
|
4
|
+
import { AiChatPanel } from "./AiChatPanel.js";
|
|
11
5
|
import { useAiChat } from "./useAiChat.js";
|
|
12
|
-
import {
|
|
13
|
-
import {
|
|
14
|
-
import { useEffect, useRef } from "react";
|
|
15
|
-
import { Fragment as Fragment$1, jsx, jsxs } from "react/jsx-runtime";
|
|
6
|
+
import { useEffect, useState, useSyncExternalStore } from "react";
|
|
7
|
+
import { jsx } from "react/jsx-runtime";
|
|
16
8
|
// src/ai/AiChat.tsx
|
|
9
|
+
const DOCK_QUERY = "(min-width: 1024px)";
|
|
10
|
+
const subscribe = (onChange) => {
|
|
11
|
+
const mql = window.matchMedia?.(DOCK_QUERY);
|
|
12
|
+
mql?.addEventListener("change", onChange);
|
|
13
|
+
return () => mql?.removeEventListener("change", onChange);
|
|
14
|
+
};
|
|
15
|
+
/**
|
|
16
|
+
* True where `auto` docks. The server snapshot is false, which is also what
|
|
17
|
+
* the hydration render reads, and the chat is closed on the server anyway.
|
|
18
|
+
*/
|
|
19
|
+
const useWideScreen = () => useSyncExternalStore(subscribe, () => window.matchMedia?.(DOCK_QUERY).matches ?? false, () => false);
|
|
17
20
|
/**
|
|
18
|
-
* The assistant in a drawer
|
|
19
|
-
*
|
|
20
|
-
*
|
|
21
|
-
*
|
|
22
|
-
*
|
|
21
|
+
* The assistant: the conversation of `AiChatPanel`, in a drawer or a dock.
|
|
22
|
+
* It knows the page through `useAiContext()`, and runs `navigate` and
|
|
23
|
+
* `fillForm` for the model. The conversation lives here, so it survives a
|
|
24
|
+
* close, a minimize and a switch between drawer and dock.
|
|
25
|
+
*
|
|
26
|
+
* A docked chat minimizes into a pill (`AiChatLauncher`): it reports itself
|
|
27
|
+
* closed through `onOpenChange(false)`, so the app's own button opens it
|
|
28
|
+
* again, and the pill does too.
|
|
23
29
|
*
|
|
24
|
-
* Needs `AlephaApiAi` on the server and a `$ai` declared by the app.
|
|
30
|
+
* Needs `AlephaApiAi` on the server and a `$ai` declared by the app. A dock
|
|
31
|
+
* needs an `AiChatDockSlot` in the layout to make room for it (`AppShell`'s
|
|
32
|
+
* `aside`); without one it floats over the page's right edge.
|
|
25
33
|
*
|
|
26
34
|
* @example
|
|
27
35
|
* ```tsx
|
|
28
36
|
* const [open, setOpen] = useState(false);
|
|
29
37
|
* <Button onClick={() => setOpen(true)}>Ask</Button>
|
|
30
38
|
* <AiChat
|
|
39
|
+
* mode="auto"
|
|
31
40
|
* open={open}
|
|
32
41
|
* onOpenChange={setOpen}
|
|
33
42
|
* suggestions={[{ label: "Who still owes today?" }]}
|
|
@@ -35,116 +44,49 @@ import { Fragment as Fragment$1, jsx, jsxs } from "react/jsx-runtime";
|
|
|
35
44
|
* ```
|
|
36
45
|
*/
|
|
37
46
|
const AiChat = (props) => {
|
|
38
|
-
const { tr } = useI18n();
|
|
39
47
|
const chat = useAiChat(props);
|
|
40
|
-
const
|
|
41
|
-
const
|
|
42
|
-
const
|
|
48
|
+
const wide = useWideScreen();
|
|
49
|
+
const [minimized, setMinimized] = useState(false);
|
|
50
|
+
const mode = props.mode ?? "drawer";
|
|
51
|
+
const docked = mode === "dock" || mode === "auto" && wide;
|
|
43
52
|
useEffect(() => {
|
|
44
|
-
|
|
45
|
-
|
|
46
|
-
|
|
47
|
-
|
|
48
|
-
|
|
49
|
-
|
|
50
|
-
|
|
51
|
-
|
|
52
|
-
|
|
53
|
-
|
|
54
|
-
|
|
55
|
-
|
|
56
|
-
|
|
53
|
+
if (props.open) setMinimized(false);
|
|
54
|
+
}, [props.open]);
|
|
55
|
+
const close = () => {
|
|
56
|
+
setMinimized(false);
|
|
57
|
+
props.onOpenChange(false);
|
|
58
|
+
};
|
|
59
|
+
if (docked) {
|
|
60
|
+
if (props.open) return /* @__PURE__ */ jsx(AiChatDock, { children: /* @__PURE__ */ jsx(AiChatPanel, {
|
|
61
|
+
...props,
|
|
62
|
+
chat,
|
|
63
|
+
onClose: close,
|
|
64
|
+
onMinimize: () => {
|
|
65
|
+
setMinimized(true);
|
|
66
|
+
props.onOpenChange(false);
|
|
67
|
+
}
|
|
68
|
+
}) });
|
|
69
|
+
return minimized ? /* @__PURE__ */ jsx(AiChatLauncher, {
|
|
70
|
+
chat,
|
|
71
|
+
title: props.title,
|
|
72
|
+
onRestore: () => props.onOpenChange(true)
|
|
73
|
+
}) : null;
|
|
74
|
+
}
|
|
57
75
|
return /* @__PURE__ */ jsx(Drawer, {
|
|
58
76
|
open: props.open,
|
|
59
|
-
onOpenChange: (open) => props.onOpenChange(
|
|
77
|
+
onOpenChange: (open) => open ? props.onOpenChange(true) : close(),
|
|
60
78
|
swipeDirection: "right",
|
|
61
|
-
children: /* @__PURE__ */
|
|
62
|
-
"data-testid": "ai-chat",
|
|
79
|
+
children: /* @__PURE__ */ jsx(DrawerContent, {
|
|
63
80
|
className: "flex h-full w-full flex-col gap-0 p-0 sm:h-[calc(100dvh-1.5rem)] sm:max-w-md sm:[--drawer-inset:0.75rem] sm:after:hidden sm:data-[swipe-direction=right]:rounded-2xl sm:data-[swipe-direction=right]:border sm:data-[swipe-direction=right]:shadow-2xl",
|
|
64
|
-
children:
|
|
65
|
-
|
|
66
|
-
|
|
67
|
-
|
|
68
|
-
|
|
69
|
-
|
|
70
|
-
|
|
71
|
-
children: props.title ?? tr("ai.chat.title", { default: "Assistant" })
|
|
72
|
-
}),
|
|
73
|
-
props.history !== false && /* @__PURE__ */ jsx(AiChatHistory, {
|
|
74
|
-
current: chat.conversationId,
|
|
75
|
-
disabled: chat.loading,
|
|
76
|
-
onOpen: (id) => chat.open(id)
|
|
77
|
-
}),
|
|
78
|
-
/* @__PURE__ */ jsx(Button, {
|
|
79
|
-
size: "icon-sm",
|
|
80
|
-
variant: "minimal",
|
|
81
|
-
disabled: chat.loading || empty,
|
|
82
|
-
"aria-label": tr("ai.chat.new", { default: "New conversation" }),
|
|
83
|
-
onClick: () => chat.open(void 0),
|
|
84
|
-
children: /* @__PURE__ */ jsx(SquarePen, { className: "size-4" })
|
|
85
|
-
}),
|
|
86
|
-
/* @__PURE__ */ jsx(DrawerClose, {
|
|
87
|
-
render: /* @__PURE__ */ jsx(Button, {
|
|
88
|
-
size: "icon-sm",
|
|
89
|
-
variant: "minimal",
|
|
90
|
-
"aria-label": tr("ai.chat.close", { default: "Close" })
|
|
91
|
-
}),
|
|
92
|
-
children: /* @__PURE__ */ jsx(X, { className: "size-4" })
|
|
93
|
-
})
|
|
94
|
-
]
|
|
95
|
-
}),
|
|
96
|
-
/* @__PURE__ */ jsxs("div", {
|
|
97
|
-
ref: thread,
|
|
98
|
-
className: "flex min-h-0 flex-1 flex-col gap-3 overflow-y-auto px-4 py-4 *:shrink-0",
|
|
99
|
-
children: [empty ? /* @__PURE__ */ jsx(AiChatEmpty, {
|
|
100
|
-
suggestions: props.suggestions,
|
|
101
|
-
disabled: chat.loading,
|
|
102
|
-
onPick: (prompt) => chat.send(prompt)
|
|
103
|
-
}) : /* @__PURE__ */ jsxs(Fragment$1, { children: [
|
|
104
|
-
chat.items.map((item) => /* @__PURE__ */ jsx(AiChatMessage, {
|
|
105
|
-
item,
|
|
106
|
-
renderLink: props.renderLink,
|
|
107
|
-
toolLabel: props.toolLabel
|
|
108
|
-
}, item.id)),
|
|
109
|
-
chat.streaming && /* @__PURE__ */ jsx("div", {
|
|
110
|
-
"data-testid": "ai-chat-streaming",
|
|
111
|
-
className: "mr-4 self-start text-sm leading-relaxed",
|
|
112
|
-
children: /* @__PURE__ */ jsx(MarkdownView, {
|
|
113
|
-
content: chat.streaming,
|
|
114
|
-
renderLink: props.renderLink
|
|
115
|
-
})
|
|
116
|
-
}),
|
|
117
|
-
running && /* @__PURE__ */ jsxs("div", {
|
|
118
|
-
className: "text-muted-foreground flex items-center gap-1.5 px-0.5 text-xs",
|
|
119
|
-
children: [/* @__PURE__ */ jsx(Spinner, { className: "size-3.5" }), running]
|
|
120
|
-
}),
|
|
121
|
-
busy && !running && !chat.streaming && /* @__PURE__ */ jsxs("div", {
|
|
122
|
-
className: "text-muted-foreground flex items-center gap-1.5 px-0.5 text-xs",
|
|
123
|
-
"aria-live": "polite",
|
|
124
|
-
children: [/* @__PURE__ */ jsx(Spinner, { className: "size-3.5" }), tr("ai.chat.thinking", { default: "Thinking…" })]
|
|
125
|
-
}),
|
|
126
|
-
chat.pending?.kind === "confirm" && Card && /* @__PURE__ */ jsx(Card, {
|
|
127
|
-
pending: chat.pending,
|
|
128
|
-
loading: chat.loading,
|
|
129
|
-
onApprove: () => chat.approve(),
|
|
130
|
-
onDeny: () => chat.deny()
|
|
131
|
-
})
|
|
132
|
-
] }), chat.error && /* @__PURE__ */ jsx(Alert, {
|
|
133
|
-
variant: "destructive",
|
|
134
|
-
"data-testid": "ai-chat-error",
|
|
135
|
-
children: /* @__PURE__ */ jsx(AlertDescription, { children: chat.error })
|
|
136
|
-
})]
|
|
137
|
-
}),
|
|
138
|
-
/* @__PURE__ */ jsx("div", {
|
|
139
|
-
className: "border-border border-t px-3 pt-3 pb-2.5",
|
|
140
|
-
children: /* @__PURE__ */ jsx(AiChatComposer, {
|
|
141
|
-
busy,
|
|
142
|
-
waiting: chat.pending?.kind === "confirm",
|
|
143
|
-
onSend: (message) => chat.send(message),
|
|
144
|
-
onStop: () => chat.stop()
|
|
145
|
-
})
|
|
81
|
+
children: /* @__PURE__ */ jsx(AiChatPanel, {
|
|
82
|
+
...props,
|
|
83
|
+
chat,
|
|
84
|
+
onClose: close,
|
|
85
|
+
renderTitle: (title, className) => /* @__PURE__ */ jsx(DrawerTitle, {
|
|
86
|
+
className,
|
|
87
|
+
children: title
|
|
146
88
|
})
|
|
147
|
-
|
|
89
|
+
})
|
|
148
90
|
})
|
|
149
91
|
});
|
|
150
92
|
};
|
package/dist/ai/AiChat.js.map
CHANGED
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"AiChat.js","names":[],"sources":["../../src/ai/AiChat.tsx"],"sourcesContent":["import { useI18n } from \"alepha/react/i18n\";\nimport { SquarePen, Sparkles, X } from \"lucide-react\";\nimport { type ComponentType, useEffect, useRef } from \"react\";\n\nimport { Alert, AlertDescription } from \"../core/Alert.tsx\";\nimport { Button } from \"../core/Button.tsx\";\nimport {\n Drawer,\n DrawerClose,\n DrawerContent,\n DrawerTitle,\n} from \"../core/Drawer.tsx\";\nimport { Spinner } from \"../core/Spinner.tsx\";\nimport {\n type MarkdownLinkRenderer,\n MarkdownView,\n} from \"../markdown/MarkdownView.tsx\";\nimport { AiChatComposer } from \"./AiChatComposer.tsx\";\nimport {\n AiChatConfirmCard,\n type AiChatConfirmCardProps,\n} from \"./AiChatConfirmCard.tsx\";\nimport { AiChatEmpty, type AiChatSuggestion } from \"./AiChatEmpty.tsx\";\nimport { AiChatHistory } from \"./AiChatHistory.tsx\";\nimport { AiChatMessage, type AiChatToolLabel } from \"./AiChatMessage.tsx\";\nimport { type UseAiChatOptions, useAiChat } from \"./useAiChat.ts\";\n\nexport interface AiChatProps extends UseAiChatOptions {\n open: boolean;\n onOpenChange: (open: boolean) => void;\n /**\n * The drawer's title. Defaults to \"Assistant\".\n */\n title?: string;\n /**\n * Offer the list of past conversations, in a header menu. Default true.\n */\n history?: boolean;\n /**\n * Questions a new conversation offers to start from.\n */\n suggestions?: AiChatSuggestion[];\n /**\n * Names each tool step in the user's words (\"Searched clients\"), running\n * and done. Without it a step shows the tool's own name.\n */\n toolLabel?: AiChatToolLabel;\n /**\n * A confirmation card per tool name, in place of the generic field list:\n * an app shows a booking as a booking. It gets the pending call as the\n * server stored it, and the approve and deny callbacks.\n */\n confirmCards?: Record<string, ComponentType<AiChatConfirmCardProps>>;\n /**\n * How links in the assistant's replies render (`MarkdownView`'s\n * `renderLink`): route the paths the app knows, leave the rest as text.\n */\n renderLink?: MarkdownLinkRenderer;\n}\n\n/**\n * The assistant in a drawer: a quiet header (history menu, new\n * conversation, close), the conversation with its tool steps and a\n * confirmation card for every mutation the assistant wants to run, and a\n * composer that sends on Enter and stops a running turn. It knows the page\n * through `useAiContext()`, and runs `navigate` and `fillForm` for the model.\n *\n * Needs `AlephaApiAi` on the server and a `$ai` declared by the app.\n *\n * @example\n * ```tsx\n * const [open, setOpen] = useState(false);\n * <Button onClick={() => setOpen(true)}>Ask</Button>\n * <AiChat\n * open={open}\n * onOpenChange={setOpen}\n * suggestions={[{ label: \"Who still owes today?\" }]}\n * />\n * ```\n */\nexport const AiChat = (props: AiChatProps) => {\n const { tr } = useI18n();\n const chat = useAiChat(props);\n const thread = useRef<HTMLDivElement>(null);\n const busy = chat.loading && !chat.pending;\n const empty = chat.items.length === 0 && !chat.streaming && !busy;\n\n // Keep the newest line in view as the conversation grows.\n useEffect(() => {\n const node = thread.current;\n if (node) {\n node.scrollTop = node.scrollHeight;\n }\n }, [chat.items.length, chat.streaming, chat.activity, chat.pending]);\n\n const running = chat.activity\n ? (props.toolLabel?.(chat.activity, \"running\") ??\n tr(\"ai.chat.running\", {\n default: \"Running $1\",\n args: [chat.activity],\n }))\n : undefined;\n\n const Card = chat.pending\n ? (props.confirmCards?.[chat.pending.name] ?? AiChatConfirmCard)\n : undefined;\n\n return (\n <Drawer\n open={props.open}\n onOpenChange={(open) => props.onOpenChange(open)}\n swipeDirection=\"right\"\n >\n <DrawerContent\n data-testid=\"ai-chat\"\n // From `sm` up the panel floats: a gap from the page's edges, every\n // corner rounded, a shadow, and no bleed strip past its edge.\n className=\"flex h-full w-full flex-col gap-0 p-0 sm:h-[calc(100dvh-1.5rem)] sm:max-w-md sm:[--drawer-inset:0.75rem] sm:after:hidden sm:data-[swipe-direction=right]:rounded-2xl sm:data-[swipe-direction=right]:border sm:data-[swipe-direction=right]:shadow-2xl\"\n >\n <div className=\"border-border flex items-center gap-2 border-b py-2.5 pr-2.5 pl-4\">\n <Sparkles className=\"text-primary size-4 shrink-0\" />\n <DrawerTitle className=\"flex-1 truncate text-base font-medium\">\n {props.title ?? tr(\"ai.chat.title\", { default: \"Assistant\" })}\n </DrawerTitle>\n {props.history !== false && (\n <AiChatHistory\n current={chat.conversationId}\n disabled={chat.loading}\n onOpen={(id) => chat.open(id)}\n />\n )}\n <Button\n size=\"icon-sm\"\n variant=\"minimal\"\n disabled={chat.loading || empty}\n aria-label={tr(\"ai.chat.new\", { default: \"New conversation\" })}\n onClick={() => chat.open(undefined)}\n >\n <SquarePen className=\"size-4\" />\n </Button>\n <DrawerClose\n render={\n <Button\n size=\"icon-sm\"\n variant=\"minimal\"\n aria-label={tr(\"ai.chat.close\", { default: \"Close\" })}\n />\n }\n >\n <X className=\"size-4\" />\n </DrawerClose>\n </div>\n <div\n ref={thread}\n // `shrink-0` on every line: in a scrolling column a card (overflow\n // hidden, so no content minimum) would shrink to its border once\n // the thread outgrows the drawer (#Q3174).\n className=\"flex min-h-0 flex-1 flex-col gap-3 overflow-y-auto px-4 py-4 *:shrink-0\"\n >\n {empty ? (\n <AiChatEmpty\n suggestions={props.suggestions}\n disabled={chat.loading}\n onPick={(prompt) => chat.send(prompt)}\n />\n ) : (\n <>\n {chat.items.map((item) => (\n <AiChatMessage\n key={item.id}\n item={item}\n renderLink={props.renderLink}\n toolLabel={props.toolLabel}\n />\n ))}\n {chat.streaming && (\n <div\n data-testid=\"ai-chat-streaming\"\n className=\"mr-4 self-start text-sm leading-relaxed\"\n >\n <MarkdownView\n content={chat.streaming}\n renderLink={props.renderLink}\n />\n </div>\n )}\n {running && (\n <div className=\"text-muted-foreground flex items-center gap-1.5 px-0.5 text-xs\">\n <Spinner className=\"size-3.5\" />\n {running}\n </div>\n )}\n {busy && !running && !chat.streaming && (\n <div\n className=\"text-muted-foreground flex items-center gap-1.5 px-0.5 text-xs\"\n aria-live=\"polite\"\n >\n <Spinner className=\"size-3.5\" />\n {tr(\"ai.chat.thinking\", { default: \"Thinking…\" })}\n </div>\n )}\n {chat.pending?.kind === \"confirm\" && Card && (\n <Card\n pending={chat.pending}\n loading={chat.loading}\n onApprove={() => chat.approve()}\n onDeny={() => chat.deny()}\n />\n )}\n </>\n )}\n {chat.error && (\n <Alert variant=\"destructive\" data-testid=\"ai-chat-error\">\n <AlertDescription>{chat.error}</AlertDescription>\n </Alert>\n )}\n </div>\n <div className=\"border-border border-t px-3 pt-3 pb-2.5\">\n <AiChatComposer\n busy={busy}\n waiting={chat.pending?.kind === \"confirm\"}\n onSend={(message) => chat.send(message)}\n onStop={() => chat.stop()}\n />\n </div>\n </DrawerContent>\n </Drawer>\n );\n};\n"],"mappings":";;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;AAgFA,MAAa,UAAU,UAAuB;CAC5C,MAAM,EAAE,OAAO,QAAQ;CACvB,MAAM,OAAO,UAAU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ACb,UAAA,oBAAC,gBAAD;MACQ;MACN,SAAS,KAAK,SAAS,SAAS;MAChC,SAAS,YAAY,KAAK,KAAK,OAAO;MACtC,cAAc,KAAK,KAAK;KACzB,CAAA;IACE,CAAA;GACQ;;CACT,CAAA;AAEZ"}
|
|
1
|
+
{"version":3,"file":"AiChat.js","names":[],"sources":["../../src/ai/AiChat.tsx"],"sourcesContent":["import { useEffect, useState, useSyncExternalStore } from \"react\";\n\nimport { Drawer, DrawerContent, DrawerTitle } from \"../core/Drawer.tsx\";\nimport { AiChatDock } from \"./AiChatDock.tsx\";\nimport { AiChatLauncher } from \"./AiChatLauncher.tsx\";\nimport { AiChatPanel, type AiChatViewProps } from \"./AiChatPanel.tsx\";\nimport { type UseAiChatOptions, useAiChat } from \"./useAiChat.ts\";\n\n/**\n * Where the conversation sits.\n * - `drawer`: a modal drawer from the right, over a dimmed page.\n * - `dock`: a panel beside the page, which stays readable and usable\n * (see `AiChatDock`), and folds into a pill.\n * - `auto`: the dock from 1024px up, the drawer below, where a page has no\n * width to give.\n */\nexport type AiChatMode = \"auto\" | \"dock\" | \"drawer\";\n\nexport interface AiChatProps extends UseAiChatOptions, AiChatViewProps {\n open: boolean;\n onOpenChange: (open: boolean) => void;\n /**\n * Where the conversation sits. Defaults to `drawer`.\n */\n mode?: AiChatMode;\n}\n\nconst DOCK_QUERY = \"(min-width: 1024px)\";\n\nconst subscribe = (onChange: () => void) => {\n const mql = window.matchMedia?.(DOCK_QUERY);\n mql?.addEventListener(\"change\", onChange);\n return () => mql?.removeEventListener(\"change\", onChange);\n};\n\n/**\n * True where `auto` docks. The server snapshot is false, which is also what\n * the hydration render reads, and the chat is closed on the server anyway.\n */\nconst useWideScreen = () =>\n useSyncExternalStore(\n subscribe,\n () => window.matchMedia?.(DOCK_QUERY).matches ?? false,\n () => false,\n );\n\n/**\n * The assistant: the conversation of `AiChatPanel`, in a drawer or a dock.\n * It knows the page through `useAiContext()`, and runs `navigate` and\n * `fillForm` for the model. The conversation lives here, so it survives a\n * close, a minimize and a switch between drawer and dock.\n *\n * A docked chat minimizes into a pill (`AiChatLauncher`): it reports itself\n * closed through `onOpenChange(false)`, so the app's own button opens it\n * again, and the pill does too.\n *\n * Needs `AlephaApiAi` on the server and a `$ai` declared by the app. A dock\n * needs an `AiChatDockSlot` in the layout to make room for it (`AppShell`'s\n * `aside`); without one it floats over the page's right edge.\n *\n * @example\n * ```tsx\n * const [open, setOpen] = useState(false);\n * <Button onClick={() => setOpen(true)}>Ask</Button>\n * <AiChat\n * mode=\"auto\"\n * open={open}\n * onOpenChange={setOpen}\n * suggestions={[{ label: \"Who still owes today?\" }]}\n * />\n * ```\n */\nexport const AiChat = (props: AiChatProps) => {\n const chat = useAiChat(props);\n const wide = useWideScreen();\n const [minimized, setMinimized] = useState(false);\n const mode = props.mode ?? \"drawer\";\n const docked = mode === \"dock\" || (mode === \"auto\" && wide);\n\n // Opened again, from the pill or from the app's own button: the pill goes.\n useEffect(() => {\n if (props.open) {\n // oxlint-disable-next-line react/set-state-in-effect -- `open` is the app's state; the pill follows it\n setMinimized(false);\n }\n }, [props.open]);\n\n const close = () => {\n setMinimized(false);\n props.onOpenChange(false);\n };\n\n if (docked) {\n if (props.open) {\n return (\n <AiChatDock>\n <AiChatPanel\n {...props}\n chat={chat}\n onClose={close}\n onMinimize={() => {\n setMinimized(true);\n props.onOpenChange(false);\n }}\n />\n </AiChatDock>\n );\n }\n return minimized ? (\n <AiChatLauncher\n chat={chat}\n title={props.title}\n onRestore={() => props.onOpenChange(true)}\n />\n ) : null;\n }\n\n return (\n <Drawer\n open={props.open}\n onOpenChange={(open) => (open ? props.onOpenChange(true) : close())}\n swipeDirection=\"right\"\n >\n <DrawerContent\n // From `sm` up the panel floats: a gap from the page's edges, every\n // corner rounded, a shadow, and no bleed strip past its edge.\n className=\"flex h-full w-full flex-col gap-0 p-0 sm:h-[calc(100dvh-1.5rem)] sm:max-w-md sm:[--drawer-inset:0.75rem] sm:after:hidden sm:data-[swipe-direction=right]:rounded-2xl sm:data-[swipe-direction=right]:border sm:data-[swipe-direction=right]:shadow-2xl\"\n >\n <AiChatPanel\n {...props}\n chat={chat}\n onClose={close}\n renderTitle={(title, className) => (\n <DrawerTitle className={className}>{title}</DrawerTitle>\n )}\n />\n </DrawerContent>\n </Drawer>\n );\n};\n"],"mappings":";;;;;;;;AA2BA,MAAM,aAAa;AAEnB,MAAM,aAAa,aAAyB;CAC1C,MAAM,MAAM,OAAO,aAAa,UAAU;CAC1C,KAAK,iBAAiB,UAAU,QAAQ;CACxC,aAAa,KAAK,oBAAoB,UAAU,QAAQ;AAC1D;;;;;AAMA,MAAM,sBACJ,qBACE,iBACM,OAAO,aAAa,UAAU,CAAC,CAAC,WAAW,aAC3C,KACR;;;;;;;;;;;;;;;;;;;;;;;;;;;AA4BF,MAAa,UAAU,UAAuB;CAC5C,MAAM,OAAO,UAAU,KAAK;CAC5B,MAAM,OAAO,cAAc;CAC3B,MAAM,CAAC,WAAW,gBAAgB,SAAS,KAAK;CAChD,MAAM,OAAO,MAAM,QAAQ;CAC3B,MAAM,SAAS,SAAS,UAAW,SAAS,UAAU;CAGtD,gBAAgB;EACd,IAAI,MAAM,MAER,aAAa,KAAK;CAEtB,GAAG,CAAC,MAAM,IAAI,CAAC;CAEf,MAAM,cAAc;EAClB,aAAa,KAAK;EAClB,MAAM,aAAa,KAAK;CAC1B;CAEA,IAAI,QAAQ;EACV,IAAI,MAAM,MACR,OACE,oBAAC,YAAD,EAAA,UACE,oBAAC,aAAD;GACE,GAAI;GACE;GACN,SAAS;GACT,kBAAkB;IAChB,aAAa,IAAI;IACjB,MAAM,aAAa,KAAK;GAC1B;EACD,CAAA,EACS,CAAA;EAGhB,OAAO,YACL,oBAAC,gBAAD;GACQ;GACN,OAAO,MAAM;GACb,iBAAiB,MAAM,aAAa,IAAI;EACzC,CAAA,IACC;CACN;CAEA,OACE,oBAAC,QAAD;EACE,MAAM,MAAM;EACZ,eAAe,SAAU,OAAO,MAAM,aAAa,IAAI,IAAI,MAAM;EACjE,gBAAe;EAEf,UAAA,oBAAC,eAAD;GAGE,WAAU;GAEV,UAAA,oBAAC,aAAD;IACE,GAAI;IACE;IACN,SAAS;IACT,cAAc,OAAO,cACnB,oBAAC,aAAD;KAAwB;KAAY,UAAA;IAAmB,CAAA;GAE1D,CAAA;EACY,CAAA;CACT,CAAA;AAEZ"}
|
|
@@ -0,0 +1,23 @@
|
|
|
1
|
+
import { type ReactNode } from "react";
|
|
2
|
+
/**
|
|
3
|
+
* The clamp on the dock's width. Narrower than 320px and a confirmation card
|
|
4
|
+
* wraps every field; wider than 640px and the page it sits beside is what
|
|
5
|
+
* suffers.
|
|
6
|
+
*/
|
|
7
|
+
export declare const AI_CHAT_DOCK_MIN = 320;
|
|
8
|
+
export declare const AI_CHAT_DOCK_MAX = 640;
|
|
9
|
+
export declare const AI_CHAT_DOCK_DEFAULT = 384;
|
|
10
|
+
export interface AiChatDockProps {
|
|
11
|
+
children: ReactNode;
|
|
12
|
+
className?: string;
|
|
13
|
+
}
|
|
14
|
+
/**
|
|
15
|
+
* The assistant beside the page, not over it: no backdrop, no focus trap,
|
|
16
|
+
* nothing that closes it on a click elsewhere, so the page stays readable
|
|
17
|
+
* and usable while the conversation goes on, and a link in a reply changes
|
|
18
|
+
* the page next to it. It renders into the layout's `AiChatDockSlot`, which
|
|
19
|
+
* narrows the page to make room, and its left edge drags to resize; the
|
|
20
|
+
* width is remembered in this browser.
|
|
21
|
+
*/
|
|
22
|
+
export declare const AiChatDock: (props: AiChatDockProps) => import("react").ReactPortal | null;
|
|
23
|
+
//# sourceMappingURL=AiChatDock.d.ts.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"AiChatDock.d.ts","sourceRoot":"","sources":["../../src/ai/AiChatDock.tsx"],"names":[],"mappings":"AACA,OAAO,EAEL,KAAK,SAAS,EAKf,MAAM,OAAO,CAAC;AAMf;;;;GAIG;AACH,eAAO,MAAM,gBAAgB,MAAM,CAAC;AACpC,eAAO,MAAM,gBAAgB,MAAM,CAAC;AACpC,eAAO,MAAM,oBAAoB,MAAM,CAAC;AAOxC,MAAM,WAAW,eAAe;IAC9B,QAAQ,EAAE,SAAS,CAAC;IACpB,SAAS,CAAC,EAAE,MAAM,CAAC;CACpB;AAED;;;;;;;GAOG;AACH,eAAO,MAAM,UAAU,UAAW,eAAe,uCAuFhD,CAAC"}
|
|
@@ -0,0 +1,90 @@
|
|
|
1
|
+
import { cn } from "../core/utils.js";
|
|
2
|
+
import { AI_CHAT_DOCK_SLOT } from "./AiChatDockSlot.js";
|
|
3
|
+
import { useI18n } from "alepha/react/i18n";
|
|
4
|
+
import { useCallback, useEffect, useRef, useState } from "react";
|
|
5
|
+
import { jsx, jsxs } from "react/jsx-runtime";
|
|
6
|
+
import { createPortal } from "react-dom";
|
|
7
|
+
// src/ai/AiChatDock.tsx
|
|
8
|
+
/**
|
|
9
|
+
* The clamp on the dock's width. Narrower than 320px and a confirmation card
|
|
10
|
+
* wraps every field; wider than 640px and the page it sits beside is what
|
|
11
|
+
* suffers.
|
|
12
|
+
*/
|
|
13
|
+
const AI_CHAT_DOCK_MIN = 320;
|
|
14
|
+
const AI_CHAT_DOCK_MAX = 640;
|
|
15
|
+
const AI_CHAT_DOCK_DEFAULT = 384;
|
|
16
|
+
const STORAGE_KEY = "alepha.ui.ai.dockWidth";
|
|
17
|
+
const clamp = (value) => Math.max(320, Math.min(640, Math.round(value)));
|
|
18
|
+
/**
|
|
19
|
+
* The assistant beside the page, not over it: no backdrop, no focus trap,
|
|
20
|
+
* nothing that closes it on a click elsewhere, so the page stays readable
|
|
21
|
+
* and usable while the conversation goes on, and a link in a reply changes
|
|
22
|
+
* the page next to it. It renders into the layout's `AiChatDockSlot`, which
|
|
23
|
+
* narrows the page to make room, and its left edge drags to resize; the
|
|
24
|
+
* width is remembered in this browser.
|
|
25
|
+
*/
|
|
26
|
+
const AiChatDock = (props) => {
|
|
27
|
+
const { tr } = useI18n();
|
|
28
|
+
const [target, setTarget] = useState();
|
|
29
|
+
const [width, setWidth] = useState(384);
|
|
30
|
+
const drag = useRef(null);
|
|
31
|
+
useEffect(() => {
|
|
32
|
+
const slot = document.querySelector(`[data-slot="${AI_CHAT_DOCK_SLOT}"]`);
|
|
33
|
+
setTarget(slot ? {
|
|
34
|
+
node: slot,
|
|
35
|
+
slot: true
|
|
36
|
+
} : {
|
|
37
|
+
node: document.body,
|
|
38
|
+
slot: false
|
|
39
|
+
});
|
|
40
|
+
try {
|
|
41
|
+
const stored = window.localStorage.getItem(STORAGE_KEY);
|
|
42
|
+
if (stored) setWidth(clamp(Number(stored)));
|
|
43
|
+
} catch {}
|
|
44
|
+
}, []);
|
|
45
|
+
useEffect(() => {
|
|
46
|
+
const onMove = (event) => {
|
|
47
|
+
if (!drag.current) return;
|
|
48
|
+
setWidth(clamp(drag.current.width - (event.clientX - drag.current.x)));
|
|
49
|
+
};
|
|
50
|
+
const onUp = () => {
|
|
51
|
+
if (!drag.current) return;
|
|
52
|
+
drag.current = null;
|
|
53
|
+
document.body.style.removeProperty("cursor");
|
|
54
|
+
try {
|
|
55
|
+
window.localStorage.setItem(STORAGE_KEY, String(width));
|
|
56
|
+
} catch {}
|
|
57
|
+
};
|
|
58
|
+
document.addEventListener("pointermove", onMove);
|
|
59
|
+
document.addEventListener("pointerup", onUp);
|
|
60
|
+
return () => {
|
|
61
|
+
document.removeEventListener("pointermove", onMove);
|
|
62
|
+
document.removeEventListener("pointerup", onUp);
|
|
63
|
+
};
|
|
64
|
+
}, [width]);
|
|
65
|
+
const startResize = useCallback((event) => {
|
|
66
|
+
drag.current = {
|
|
67
|
+
x: event.clientX,
|
|
68
|
+
width
|
|
69
|
+
};
|
|
70
|
+
document.body.style.cursor = "col-resize";
|
|
71
|
+
event.preventDefault();
|
|
72
|
+
}, [width]);
|
|
73
|
+
if (!target) return null;
|
|
74
|
+
return createPortal(/* @__PURE__ */ jsxs("aside", {
|
|
75
|
+
"data-testid": "ai-chat-dock",
|
|
76
|
+
"aria-label": tr("ai.chat.title", { default: "Assistant" }),
|
|
77
|
+
style: { width },
|
|
78
|
+
className: cn("bg-card text-card-foreground relative flex flex-col overflow-hidden rounded-xl border text-sm shadow-sm", target.slot ? "sticky top-2 my-2 me-2 h-[calc(100%-1rem)] max-h-[calc(100svh-1rem)]" : "fixed inset-y-2 end-2 z-40 shadow-2xl", props.className),
|
|
79
|
+
children: [/* @__PURE__ */ jsx("div", {
|
|
80
|
+
role: "separator",
|
|
81
|
+
"aria-orientation": "vertical",
|
|
82
|
+
"aria-label": tr("ai.chat.resize", { default: "Resize the assistant" }),
|
|
83
|
+
onPointerDown: startResize,
|
|
84
|
+
className: "hover:bg-primary/20 absolute inset-y-0 start-0 z-10 w-1.5 cursor-col-resize transition-colors"
|
|
85
|
+
}), props.children]
|
|
86
|
+
}), target.node);
|
|
87
|
+
};
|
|
88
|
+
export { AI_CHAT_DOCK_DEFAULT, AI_CHAT_DOCK_MAX, AI_CHAT_DOCK_MIN, AiChatDock };
|
|
89
|
+
|
|
90
|
+
//# sourceMappingURL=AiChatDock.js.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"AiChatDock.js","names":[],"sources":["../../src/ai/AiChatDock.tsx"],"sourcesContent":["import { useI18n } from \"alepha/react/i18n\";\nimport {\n type PointerEvent as ReactPointerEvent,\n type ReactNode,\n useCallback,\n useEffect,\n useRef,\n useState,\n} from \"react\";\nimport { createPortal } from \"react-dom\";\n\nimport { cn } from \"../core/utils.ts\";\nimport { AI_CHAT_DOCK_SLOT } from \"./AiChatDockSlot.tsx\";\n\n/**\n * The clamp on the dock's width. Narrower than 320px and a confirmation card\n * wraps every field; wider than 640px and the page it sits beside is what\n * suffers.\n */\nexport const AI_CHAT_DOCK_MIN = 320;\nexport const AI_CHAT_DOCK_MAX = 640;\nexport const AI_CHAT_DOCK_DEFAULT = 384;\n\nconst STORAGE_KEY = \"alepha.ui.ai.dockWidth\";\n\nconst clamp = (value: number): number =>\n Math.max(AI_CHAT_DOCK_MIN, Math.min(AI_CHAT_DOCK_MAX, Math.round(value)));\n\nexport interface AiChatDockProps {\n children: ReactNode;\n className?: string;\n}\n\n/**\n * The assistant beside the page, not over it: no backdrop, no focus trap,\n * nothing that closes it on a click elsewhere, so the page stays readable\n * and usable while the conversation goes on, and a link in a reply changes\n * the page next to it. It renders into the layout's `AiChatDockSlot`, which\n * narrows the page to make room, and its left edge drags to resize; the\n * width is remembered in this browser.\n */\nexport const AiChatDock = (props: AiChatDockProps) => {\n const { tr } = useI18n();\n const [target, setTarget] = useState<{ node: Element; slot: boolean }>();\n const [width, setWidth] = useState(AI_CHAT_DOCK_DEFAULT);\n const drag = useRef<{ x: number; width: number } | null>(null);\n\n useEffect(() => {\n // After the commit, not in an initializer: the server has no document,\n // and the slot is a sibling the same commit mounts.\n const slot = document.querySelector(`[data-slot=\"${AI_CHAT_DOCK_SLOT}\"]`);\n // oxlint-disable-next-line react/set-state-in-effect -- the portal target only exists after the commit, see above\n setTarget(\n slot ? { node: slot, slot: true } : { node: document.body, slot: false },\n );\n try {\n const stored = window.localStorage.getItem(STORAGE_KEY);\n if (stored) setWidth(clamp(Number(stored)));\n } catch {\n // Private mode, or storage denied: the default width is a fine answer.\n }\n }, []);\n\n useEffect(() => {\n const onMove = (event: PointerEvent) => {\n if (!drag.current) return;\n // The handle is on the left edge: dragging left widens the dock.\n setWidth(clamp(drag.current.width - (event.clientX - drag.current.x)));\n };\n const onUp = () => {\n if (!drag.current) return;\n drag.current = null;\n document.body.style.removeProperty(\"cursor\");\n try {\n window.localStorage.setItem(STORAGE_KEY, String(width));\n } catch {\n // Losing the preference is not worth an error.\n }\n };\n document.addEventListener(\"pointermove\", onMove);\n document.addEventListener(\"pointerup\", onUp);\n return () => {\n document.removeEventListener(\"pointermove\", onMove);\n document.removeEventListener(\"pointerup\", onUp);\n };\n }, [width]);\n\n const startResize = useCallback(\n (event: ReactPointerEvent) => {\n drag.current = { x: event.clientX, width };\n // Keeps the resize cursor while the pointer outruns the strip.\n document.body.style.cursor = \"col-resize\";\n event.preventDefault();\n },\n [width],\n );\n\n if (!target) {\n return null;\n }\n\n return createPortal(\n <aside\n data-testid=\"ai-chat-dock\"\n aria-label={tr(\"ai.chat.title\", { default: \"Assistant\" })}\n style={{ width }}\n className={cn(\n \"bg-card text-card-foreground relative flex flex-col overflow-hidden rounded-xl border text-sm shadow-sm\",\n target.slot\n ? // In the layout's column: a card the page narrows for, kept in\n // view when the page itself scrolls.\n \"sticky top-2 my-2 me-2 h-[calc(100%-1rem)] max-h-[calc(100svh-1rem)]\"\n : // No slot: over the page's right edge, still without a backdrop.\n \"fixed inset-y-2 end-2 z-40 shadow-2xl\",\n props.className,\n )}\n >\n <div\n role=\"separator\"\n aria-orientation=\"vertical\"\n aria-label={tr(\"ai.chat.resize\", { default: \"Resize the assistant\" })}\n onPointerDown={startResize}\n className=\"hover:bg-primary/20 absolute inset-y-0 start-0 z-10 w-1.5 cursor-col-resize transition-colors\"\n />\n {props.children}\n </aside>,\n target.node,\n );\n};\n"],"mappings":";;;;;;;;;;;;AAmBA,MAAa,mBAAmB;AAChC,MAAa,mBAAmB;AAChC,MAAa,uBAAuB;AAEpC,MAAM,cAAc;AAEpB,MAAM,SAAS,UACb,KAAK,IAAA,KAAsB,KAAK,IAAA,KAAsB,KAAK,MAAM,KAAK,CAAC,CAAC;;;;;;;;;AAe1E,MAAa,cAAc,UAA2B;CACpD,MAAM,EAAE,OAAO,QAAQ;CACvB,MAAM,CAAC,QAAQ,aAAa,SAA2C;CACvE,MAAM,CAAC,OAAO,YAAY,SAAA,GAA6B;CACvD,MAAM,OAAO,OAA4C,IAAI;CAE7D,gBAAgB;EAGd,MAAM,OAAO,SAAS,cAAc,eAAe,kBAAkB,GAAG;EAExE,UACE,OAAO;GAAE,MAAM;GAAM,MAAM;EAAK,IAAI;GAAE,MAAM,SAAS;GAAM,MAAM;EAAM,CACzE;EACA,IAAI;GACF,MAAM,SAAS,OAAO,aAAa,QAAQ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slot` that marks the column an `AiChatDock` renders into.
|
|
3
|
+
*/
|
|
4
|
+
export declare const AI_CHAT_DOCK_SLOT = "ai-chat-dock";
|
|
5
|
+
export interface AiChatDockSlotProps {
|
|
6
|
+
className?: string;
|
|
7
|
+
}
|
|
8
|
+
/**
|
|
9
|
+
* Where a layout makes room for the assistant's dock: a column beside the
|
|
10
|
+
* page, empty and zero-wide until the dock opens. Pass it to `AppShell` as
|
|
11
|
+
* `aside`; any other layout puts it as a flex sibling of its content. Without one, the dock floats over the page's right edge
|
|
12
|
+
* instead, still without a backdrop.
|
|
13
|
+
*/
|
|
14
|
+
export declare const AiChatDockSlot: (props: AiChatDockSlotProps) => import("react").JSX.Element;
|
|
15
|
+
//# sourceMappingURL=AiChatDockSlot.d.ts.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"AiChatDockSlot.d.ts","sourceRoot":"","sources":["../../src/ai/AiChatDockSlot.tsx"],"names":[],"mappings":"AAEA;;GAEG;AACH,eAAO,MAAM,iBAAiB,iBAAiB,CAAC;AAEhD,MAAM,WAAW,mBAAmB;IAClC,SAAS,CAAC,EAAE,MAAM,CAAC;CACpB;AAED;;;;;GAKG;AACH,eAAO,MAAM,cAAc,UAAW,mBAAmB,gCAKxD,CAAC"}
|
|
@@ -0,0 +1,20 @@
|
|
|
1
|
+
import { cn } from "../core/utils.js";
|
|
2
|
+
import { jsx } from "react/jsx-runtime";
|
|
3
|
+
// src/ai/AiChatDockSlot.tsx
|
|
4
|
+
/**
|
|
5
|
+
* The `data-slot` that marks the column an `AiChatDock` renders into.
|
|
6
|
+
*/
|
|
7
|
+
const AI_CHAT_DOCK_SLOT = "ai-chat-dock";
|
|
8
|
+
/**
|
|
9
|
+
* Where a layout makes room for the assistant's dock: a column beside the
|
|
10
|
+
* page, empty and zero-wide until the dock opens. Pass it to `AppShell` as
|
|
11
|
+
* `aside`; any other layout puts it as a flex sibling of its content. Without one, the dock floats over the page's right edge
|
|
12
|
+
* instead, still without a backdrop.
|
|
13
|
+
*/
|
|
14
|
+
const AiChatDockSlot = (props) => /* @__PURE__ */ jsx("div", {
|
|
15
|
+
"data-slot": AI_CHAT_DOCK_SLOT,
|
|
16
|
+
className: cn("flex min-h-0 shrink-0", props.className)
|
|
17
|
+
});
|
|
18
|
+
export { AI_CHAT_DOCK_SLOT, AiChatDockSlot };
|
|
19
|
+
|
|
20
|
+
//# sourceMappingURL=AiChatDockSlot.js.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"AiChatDockSlot.js","names":[],"sources":["../../src/ai/AiChatDockSlot.tsx"],"sourcesContent":["import { cn } from \"../core/utils.ts\";\n\n/**\n * The `data-slot` that marks the column an `AiChatDock` renders into.\n */\nexport const AI_CHAT_DOCK_SLOT = \"ai-chat-dock\";\n\nexport interface AiChatDockSlotProps {\n className?: string;\n}\n\n/**\n * Where a layout makes room for the assistant's dock: a column beside the\n * page, empty and zero-wide until the dock opens. Pass it to `AppShell` as\n * `aside`; any other layout puts it as a flex sibling of its content. Without one, the dock floats over the page's right edge\n * instead, still without a backdrop.\n */\nexport const AiChatDockSlot = (props: AiChatDockSlotProps) => (\n <div\n data-slot={AI_CHAT_DOCK_SLOT}\n className={cn(\"flex min-h-0 shrink-0\", props.className)}\n />\n);\n"],"mappings":";;;;;;AAKA,MAAa,oBAAoB;;;;;;;AAYjC,MAAa,kBAAkB,UAC7B,oBAAC,OAAD;CACE,aAAW;CACX,WAAW,GAAG,yBAAyB,MAAM,SAAS;AACvD,CAAA"}
|
|
@@ -0,0 +1,17 @@
|
|
|
1
|
+
import type { UseAiChat } from "./useAiChat.ts";
|
|
2
|
+
export interface AiChatLauncherProps {
|
|
3
|
+
/**
|
|
4
|
+
* The conversation the pill speaks for.
|
|
5
|
+
*/
|
|
6
|
+
chat: UseAiChat;
|
|
7
|
+
title?: string;
|
|
8
|
+
onRestore: () => void;
|
|
9
|
+
className?: string;
|
|
10
|
+
}
|
|
11
|
+
/**
|
|
12
|
+
* A minimized assistant: a pill at the bottom corner that brings the panel
|
|
13
|
+
* back, and still says what the conversation is doing, so folding it away
|
|
14
|
+
* never hides an action waiting for the user's approval.
|
|
15
|
+
*/
|
|
16
|
+
export declare const AiChatLauncher: (props: AiChatLauncherProps) => import("react").JSX.Element;
|
|
17
|
+
//# sourceMappingURL=AiChatLauncher.d.ts.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"AiChatLauncher.d.ts","sourceRoot":"","sources":["../../src/ai/AiChatLauncher.tsx"],"names":[],"mappings":"AAMA,OAAO,KAAK,EAAE,SAAS,EAAE,MAAM,gBAAgB,CAAC;AAEhD,MAAM,WAAW,mBAAmB;IAClC;;OAEG;IACH,IAAI,EAAE,SAAS,CAAC;IAChB,KAAK,CAAC,EAAE,MAAM,CAAC;IACf,SAAS,EAAE,MAAM,IAAI,CAAC;IACtB,SAAS,CAAC,EAAE,MAAM,CAAC;CACpB;AAED;;;;GAIG;AACH,eAAO,MAAM,cAAc,UAAW,mBAAmB,gCAkCxD,CAAC"}
|