@alepha/ui 0.26.0 → 0.27.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/README.md +86 -12
- package/dist/components/account/account-connections.js +5 -5
- package/dist/components/account/account-connections.js.map +1 -1
- package/dist/components/account/account-delete-dialog.js +4 -4
- package/dist/components/account/account-header.d.ts.map +1 -1
- package/dist/components/account/account-header.js +3 -1
- package/dist/components/account/account-header.js.map +1 -1
- package/dist/components/account/account-keys.js +7 -7
- package/dist/components/account/account-keys.js.map +1 -1
- package/dist/components/account/account-layout.d.ts.map +1 -1
- package/dist/components/account/account-layout.js +7 -4
- package/dist/components/account/account-layout.js.map +1 -1
- package/dist/components/account/account-password-dialog.js +3 -3
- package/dist/components/account/account-profile.js +8 -8
- package/dist/components/account/account-profile.js.map +1 -1
- package/dist/components/account/account-router-options.d.ts.map +1 -1
- package/dist/components/account/account-router-options.js.map +1 -1
- package/dist/components/account/account-router-page.d.ts.map +1 -1
- package/dist/components/account/account-router-page.js.map +1 -1
- package/dist/components/account/account-router.d.ts +3 -2
- package/dist/components/account/account-router.d.ts.map +1 -1
- package/dist/components/account/account-router.js +4 -3
- package/dist/components/account/account-router.js.map +1 -1
- package/dist/components/account/account-security.d.ts.map +1 -1
- package/dist/components/account/account-security.js +6 -6
- package/dist/components/account/account-security.js.map +1 -1
- package/dist/components/account/account-sessions.d.ts.map +1 -1
- package/dist/components/account/account-sessions.js +19 -6
- package/dist/components/account/account-sessions.js.map +1 -1
- package/dist/components/admin/admin-analytics-query-panel.d.ts +1 -1
- package/dist/components/admin/admin-analytics-query-panel.d.ts.map +1 -1
- package/dist/components/admin/admin-analytics-query-panel.js +5 -5
- package/dist/components/admin/admin-analytics-query-panel.js.map +1 -1
- package/dist/components/admin/admin-analytics-results.d.ts +1 -1
- package/dist/components/admin/admin-analytics-results.d.ts.map +1 -1
- package/dist/components/admin/admin-analytics-results.js +2 -2
- package/dist/components/admin/admin-analytics-results.js.map +1 -1
- package/dist/components/admin/admin-analytics.d.ts +1 -1
- package/dist/components/admin/admin-analytics.d.ts.map +1 -1
- package/dist/components/admin/admin-analytics.js +3 -3
- package/dist/components/admin/admin-analytics.js.map +1 -1
- package/dist/components/admin/admin-audits.d.ts +1 -1
- package/dist/components/admin/admin-audits.d.ts.map +1 -1
- package/dist/components/admin/admin-audits.js +4 -4
- package/dist/components/admin/admin-audits.js.map +1 -1
- package/dist/components/admin/admin-dashboard-card.d.ts +42 -0
- package/dist/components/admin/admin-dashboard-card.d.ts.map +1 -0
- package/dist/components/admin/admin-dashboard-card.js +0 -0
- package/dist/components/admin/admin-dashboard-count-card.d.ts +34 -0
- package/dist/components/admin/admin-dashboard-count-card.d.ts.map +1 -0
- package/dist/components/admin/admin-dashboard-count-card.js +42 -0
- package/dist/components/admin/admin-dashboard-count-card.js.map +1 -0
- package/dist/components/admin/admin-dashboard.d.ts +20 -0
- package/dist/components/admin/admin-dashboard.d.ts.map +1 -0
- package/dist/components/admin/admin-dashboard.js +32 -0
- package/dist/components/admin/admin-dashboard.js.map +1 -0
- package/dist/components/admin/admin-files.d.ts +1 -1
- package/dist/components/admin/admin-files.d.ts.map +1 -1
- package/dist/components/admin/admin-files.js +3 -3
- package/dist/components/admin/admin-files.js.map +1 -1
- package/dist/components/admin/admin-jobs-executions-panel.d.ts +2 -2
- package/dist/components/admin/admin-jobs-executions-panel.d.ts.map +1 -1
- package/dist/components/admin/admin-jobs-executions-panel.js +16 -31
- package/dist/components/admin/admin-jobs-executions-panel.js.map +1 -1
- package/dist/components/admin/admin-jobs-status-badge.d.ts +2 -2
- package/dist/components/admin/admin-jobs-status-badge.d.ts.map +1 -1
- package/dist/components/admin/admin-jobs-status-badge.js +2 -2
- package/dist/components/admin/admin-jobs-status-badge.js.map +1 -1
- package/dist/components/admin/admin-jobs.d.ts +1 -1
- package/dist/components/admin/admin-jobs.d.ts.map +1 -1
- package/dist/components/admin/admin-jobs.js +5 -5
- package/dist/components/admin/admin-jobs.js.map +1 -1
- package/dist/components/admin/admin-keys-token-dialog.js +3 -3
- package/dist/components/admin/admin-keys-token-dialog.js.map +1 -1
- package/dist/components/admin/admin-keys.d.ts +1 -1
- package/dist/components/admin/admin-keys.d.ts.map +1 -1
- package/dist/components/admin/admin-keys.js +4 -4
- package/dist/components/admin/admin-keys.js.map +1 -1
- package/dist/components/admin/admin-layout.d.ts.map +1 -1
- package/dist/components/admin/admin-layout.js +1 -3
- package/dist/components/admin/admin-layout.js.map +1 -1
- package/dist/components/admin/admin-notifications.d.ts +1 -1
- package/dist/components/admin/admin-notifications.d.ts.map +1 -1
- package/dist/components/admin/admin-notifications.js +3 -3
- package/dist/components/admin/admin-notifications.js.map +1 -1
- package/dist/components/admin/admin-parameters.d.ts +1 -1
- package/dist/components/admin/admin-parameters.d.ts.map +1 -1
- package/dist/components/admin/admin-parameters.js +10 -10
- package/dist/components/admin/admin-parameters.js.map +1 -1
- package/dist/components/admin/admin-payments.d.ts +1 -1
- package/dist/components/admin/admin-payments.d.ts.map +1 -1
- package/dist/components/admin/admin-payments.js +3 -3
- package/dist/components/admin/admin-payments.js.map +1 -1
- package/dist/components/admin/admin-router-options.d.ts +13 -10
- package/dist/components/admin/admin-router-options.d.ts.map +1 -1
- package/dist/components/admin/admin-router-options.js.map +1 -1
- package/dist/components/admin/admin-router-page.d.ts +7 -5
- package/dist/components/admin/admin-router-page.d.ts.map +1 -1
- package/dist/components/admin/admin-router-page.js +7 -5
- package/dist/components/admin/admin-router-page.js.map +1 -1
- package/dist/components/admin/admin-router.d.ts +72 -27
- package/dist/components/admin/admin-router.d.ts.map +1 -1
- package/dist/components/admin/admin-router.js +103 -40
- package/dist/components/admin/admin-router.js.map +1 -1
- package/dist/components/admin/admin-sessions.d.ts +1 -1
- package/dist/components/admin/admin-sessions.d.ts.map +1 -1
- package/dist/components/admin/admin-sessions.js +12 -4
- package/dist/components/admin/admin-sessions.js.map +1 -1
- package/dist/components/admin/admin-user-detail-audits-tab.d.ts +2 -2
- package/dist/components/admin/admin-user-detail-audits-tab.d.ts.map +1 -1
- package/dist/components/admin/admin-user-detail-audits-tab.js.map +1 -1
- package/dist/components/admin/admin-user-detail-identity-aside.d.ts +4 -3
- package/dist/components/admin/admin-user-detail-identity-aside.d.ts.map +1 -1
- package/dist/components/admin/admin-user-detail-identity-aside.js +13 -69
- package/dist/components/admin/admin-user-detail-identity-aside.js.map +1 -1
- package/dist/components/admin/admin-user-detail-overview-tab.d.ts.map +1 -1
- package/dist/components/admin/admin-user-detail-overview-tab.js.map +1 -1
- package/dist/components/admin/admin-user-detail-password-dialog.d.ts.map +1 -1
- package/dist/components/admin/admin-user-detail-password-dialog.js.map +1 -1
- package/dist/components/admin/admin-user-detail-profile-policy.d.ts.map +1 -1
- package/dist/components/admin/admin-user-detail-profile-policy.js.map +1 -1
- package/dist/components/admin/admin-user-detail-security-tab.d.ts.map +1 -1
- package/dist/components/admin/admin-user-detail-security-tab.js +2 -2
- package/dist/components/admin/admin-user-detail-security-tab.js.map +1 -1
- package/dist/components/admin/admin-user-detail-sessions-tab.d.ts +2 -2
- package/dist/components/admin/admin-user-detail-sessions-tab.d.ts.map +1 -1
- package/dist/components/admin/admin-user-detail-sessions-tab.js.map +1 -1
- package/dist/components/admin/admin-user-detail.d.ts.map +1 -1
- package/dist/components/admin/admin-user-detail.js +68 -111
- package/dist/components/admin/admin-user-detail.js.map +1 -1
- package/dist/components/admin/admin-users-roles-picker.d.ts +6 -1
- package/dist/components/admin/admin-users-roles-picker.d.ts.map +1 -1
- package/dist/components/admin/admin-users-roles-picker.js +11 -8
- package/dist/components/admin/admin-users-roles-picker.js.map +1 -1
- package/dist/components/admin/admin-users.d.ts.map +1 -1
- package/dist/components/admin/admin-users.js +9 -12
- package/dist/components/admin/admin-users.js.map +1 -1
- package/dist/components/admin/admin-workflows-execution-sheet.d.ts +2 -2
- package/dist/components/admin/admin-workflows-execution-sheet.d.ts.map +1 -1
- package/dist/components/admin/admin-workflows-execution-sheet.js +10 -10
- package/dist/components/admin/admin-workflows-execution-sheet.js.map +1 -1
- package/dist/components/admin/admin-workflows-executions-panel.d.ts +2 -2
- package/dist/components/admin/admin-workflows-executions-panel.d.ts.map +1 -1
- package/dist/components/admin/admin-workflows-executions-panel.js +20 -44
- package/dist/components/admin/admin-workflows-executions-panel.js.map +1 -1
- package/dist/components/admin/admin-workflows-status-badge.d.ts +2 -2
- package/dist/components/admin/admin-workflows-status-badge.d.ts.map +1 -1
- package/dist/components/admin/admin-workflows-status-badge.js +2 -2
- package/dist/components/admin/admin-workflows-status-badge.js.map +1 -1
- package/dist/components/admin/admin-workflows.d.ts +1 -1
- package/dist/components/admin/admin-workflows.d.ts.map +1 -1
- package/dist/components/admin/admin-workflows.js +5 -5
- package/dist/components/admin/admin-workflows.js.map +1 -1
- package/dist/components/admin/diff-lines.js +1 -1
- package/dist/components/admin/diff-lines.js.map +1 -1
- package/dist/components/admin/parameter-diff-dialog.d.ts.map +1 -1
- package/dist/components/admin/parameter-diff-dialog.js +1 -1
- package/dist/components/admin/parameter-diff-dialog.js.map +1 -1
- package/dist/components/admin/parameter-history-item.d.ts.map +1 -1
- package/dist/components/admin/parameter-history-item.js +4 -4
- package/dist/components/admin/parameter-history-item.js.map +1 -1
- package/dist/components/admin/parameter-json-dialog.js +1 -1
- package/dist/components/admin/parameter-save-dialog.js +2 -2
- package/dist/components/admin/use-confirmed-action.js +1 -1
- package/dist/components/alepha-table/alepha-table.d.ts +103 -8
- package/dist/components/alepha-table/alepha-table.d.ts.map +1 -1
- package/dist/components/alepha-table/alepha-table.js +128 -26
- package/dist/components/alepha-table/alepha-table.js.map +1 -1
- package/dist/components/alepha-table/paginate-local.d.ts +43 -0
- package/dist/components/alepha-table/paginate-local.d.ts.map +1 -0
- package/dist/components/alepha-table/paginate-local.js +84 -0
- package/dist/components/alepha-table/paginate-local.js.map +1 -0
- package/dist/components/app-actions/app-actions.js +1 -1
- package/dist/components/app-shell/app-shell.d.ts +10 -1
- package/dist/components/app-shell/app-shell.d.ts.map +1 -1
- package/dist/components/app-shell/app-shell.js +27 -20
- package/dist/components/app-shell/app-shell.js.map +1 -1
- package/dist/components/auth/auth-login.d.ts +1 -1
- package/dist/components/auth/auth-login.d.ts.map +1 -1
- package/dist/components/auth/auth-login.js +7 -18
- package/dist/components/auth/auth-login.js.map +1 -1
- package/dist/components/auth/auth-register.d.ts +1 -1
- package/dist/components/auth/auth-register.d.ts.map +1 -1
- package/dist/components/auth/auth-register.js +20 -21
- package/dist/components/auth/auth-register.js.map +1 -1
- package/dist/components/auth/auth-reset-password.d.ts +1 -1
- package/dist/components/auth/auth-reset-password.d.ts.map +1 -1
- package/dist/components/auth/auth-reset-password.js +16 -13
- package/dist/components/auth/auth-reset-password.js.map +1 -1
- package/dist/components/auth/auth-router.d.ts +3 -3
- package/dist/components/auth/auth-router.d.ts.map +1 -1
- package/dist/components/auth/auth-router.js +3 -3
- package/dist/components/auth/auth-router.js.map +1 -1
- package/dist/components/auth/auth-verify-email.d.ts +1 -1
- package/dist/components/auth/auth-verify-email.d.ts.map +1 -1
- package/dist/components/auth/auth-verify-email.js +8 -8
- package/dist/components/auth/auth-verify-email.js.map +1 -1
- package/dist/components/auth/safe-redirect.d.ts +9 -0
- package/dist/components/auth/safe-redirect.d.ts.map +1 -0
- package/dist/components/auth/safe-redirect.js +19 -0
- package/dist/components/auth/safe-redirect.js.map +1 -0
- package/dist/components/auto-form/auto-form.d.ts.map +1 -1
- package/dist/components/auto-form/auto-form.js +32 -32
- package/dist/components/auto-form/auto-form.js.map +1 -1
- package/dist/components/brand-icon/brand-icon.d.ts +1 -1
- package/dist/components/brand-icon/brand-icon.d.ts.map +1 -1
- package/dist/components/brand-icon/brand-icon.js +2 -2
- package/dist/components/brand-icon/brand-icon.js.map +1 -1
- package/dist/components/button-dark/button-dark.d.ts +1 -1
- package/dist/components/button-dark/button-dark.d.ts.map +1 -1
- package/dist/components/button-dark/button-dark.js +2 -2
- package/dist/components/button-dark/button-dark.js.map +1 -1
- package/dist/components/button-language/button-language.d.ts +1 -1
- package/dist/components/button-language/button-language.d.ts.map +1 -1
- package/dist/components/button-language/button-language.js +2 -2
- package/dist/components/button-language/button-language.js.map +1 -1
- package/dist/components/button-theme/button-theme.d.ts +1 -1
- package/dist/components/button-theme/button-theme.d.ts.map +1 -1
- package/dist/components/button-theme/button-theme.js +3 -3
- package/dist/components/button-theme/button-theme.js.map +1 -1
- package/dist/components/button-user/button-user.d.ts +2 -20
- package/dist/components/button-user/button-user.d.ts.map +1 -1
- package/dist/components/button-user/button-user.js +3 -3
- package/dist/components/button-user/button-user.js.map +1 -1
- package/dist/components/captcha/turnstile-widget.d.ts +2 -2
- package/dist/components/captcha/turnstile-widget.d.ts.map +1 -1
- package/dist/components/captcha/turnstile-widget.js +5 -4
- package/dist/components/captcha/turnstile-widget.js.map +1 -1
- package/dist/components/control/control.d.ts +1 -1
- package/dist/components/control/control.d.ts.map +1 -1
- package/dist/components/control/control.js +8 -11
- package/dist/components/control/control.js.map +1 -1
- package/dist/components/control-array/control-array.d.ts +1 -1
- package/dist/components/control-array/control-array.d.ts.map +1 -1
- package/dist/components/control-array/control-array.js +23 -16
- package/dist/components/control-array/control-array.js.map +1 -1
- package/dist/components/control-base/field-i18n.d.ts +5 -3
- package/dist/components/control-base/field-i18n.d.ts.map +1 -1
- package/dist/components/control-base/field-i18n.js +4 -2
- package/dist/components/control-base/field-i18n.js.map +1 -1
- package/dist/components/control-base/form-field.d.ts +7 -7
- package/dist/components/control-base/form-field.d.ts.map +1 -1
- package/dist/components/control-base/form-field.js +10 -10
- package/dist/components/control-base/form-field.js.map +1 -1
- package/dist/components/control-base/icon-hint.d.ts +1 -1
- package/dist/components/control-base/icon-hint.d.ts.map +1 -1
- package/dist/components/control-base/icon-hint.js.map +1 -1
- package/dist/components/control-date/control-date.d.ts +1 -1
- package/dist/components/control-date/control-date.d.ts.map +1 -1
- package/dist/components/control-date/control-date.js +23 -7
- package/dist/components/control-date/control-date.js.map +1 -1
- package/dist/components/control-number/control-number.d.ts +2 -2
- package/dist/components/control-number/control-number.d.ts.map +1 -1
- package/dist/components/control-number/control-number.js +3 -3
- package/dist/components/control-number/control-number.js.map +1 -1
- package/dist/components/control-object/control-object.d.ts +4 -2
- package/dist/components/control-object/control-object.d.ts.map +1 -1
- package/dist/components/control-object/control-object.js +8 -8
- package/dist/components/control-object/control-object.js.map +1 -1
- package/dist/components/control-password/control-password.js +2 -3
- package/dist/components/control-password/control-password.js.map +1 -1
- package/dist/components/control-select/control-select.d.ts +2 -2
- package/dist/components/control-select/control-select.d.ts.map +1 -1
- package/dist/components/control-select/control-select.js +17 -17
- package/dist/components/control-select/control-select.js.map +1 -1
- package/dist/components/control-upload/control-upload.d.ts +1 -1
- package/dist/components/control-upload/control-upload.d.ts.map +1 -1
- package/dist/components/control-upload/control-upload.js +11 -11
- package/dist/components/control-upload/control-upload.js.map +1 -1
- package/dist/components/detail/detail-aside.d.ts +58 -0
- package/dist/components/detail/detail-aside.d.ts.map +1 -0
- package/dist/components/detail/detail-aside.js +95 -0
- package/dist/components/detail/detail-aside.js.map +1 -0
- package/dist/components/detail/detail-layout.d.ts +90 -0
- package/dist/components/detail/detail-layout.d.ts.map +1 -0
- package/dist/components/detail/detail-layout.js +102 -0
- package/dist/components/detail/detail-layout.js.map +1 -0
- package/dist/components/detail/use-detail-tab.d.ts +15 -0
- package/dist/components/detail/use-detail-tab.d.ts.map +1 -0
- package/dist/components/detail/use-detail-tab.js +37 -0
- package/dist/components/detail/use-detail-tab.js.map +1 -0
- package/dist/components/file-image/file-image.d.ts.map +1 -1
- package/dist/components/file-image/file-image.js.map +1 -1
- package/dist/components/language-toggle/language-toggle.d.ts +1 -1
- package/dist/components/language-toggle/language-toggle.d.ts.map +1 -1
- package/dist/components/language-toggle/language-toggle.js +2 -2
- package/dist/components/language-toggle/language-toggle.js.map +1 -1
- package/dist/components/markdown-view/diagram/DiagramErrorBoundary.d.ts +28 -0
- package/dist/components/markdown-view/diagram/DiagramErrorBoundary.d.ts.map +1 -0
- package/dist/components/markdown-view/diagram/DiagramErrorBoundary.js +25 -0
- package/dist/components/markdown-view/diagram/DiagramErrorBoundary.js.map +1 -0
- package/dist/components/markdown-view/diagram/FlowchartDiagram.d.ts +44 -0
- package/dist/components/markdown-view/diagram/FlowchartDiagram.d.ts.map +1 -0
- package/dist/components/markdown-view/diagram/FlowchartDiagram.js +98 -0
- package/dist/components/markdown-view/diagram/FlowchartDiagram.js.map +1 -0
- package/dist/components/markdown-view/diagram/FlowchartDiagramCluster.d.ts +14 -0
- package/dist/components/markdown-view/diagram/FlowchartDiagramCluster.d.ts.map +1 -0
- package/dist/components/markdown-view/diagram/FlowchartDiagramCluster.js +45 -0
- package/dist/components/markdown-view/diagram/FlowchartDiagramCluster.js.map +1 -0
- package/dist/components/markdown-view/diagram/FlowchartDiagramEdge.d.ts +19 -0
- package/dist/components/markdown-view/diagram/FlowchartDiagramEdge.d.ts.map +1 -0
- package/dist/components/markdown-view/diagram/FlowchartDiagramEdge.js +69 -0
- package/dist/components/markdown-view/diagram/FlowchartDiagramEdge.js.map +1 -0
- package/dist/components/markdown-view/diagram/FlowchartDiagramLabel.d.ts +23 -0
- package/dist/components/markdown-view/diagram/FlowchartDiagramLabel.d.ts.map +1 -0
- package/dist/components/markdown-view/diagram/FlowchartDiagramLabel.js +34 -0
- package/dist/components/markdown-view/diagram/FlowchartDiagramLabel.js.map +1 -0
- package/dist/components/markdown-view/diagram/FlowchartDiagramNode.d.ts +17 -0
- package/dist/components/markdown-view/diagram/FlowchartDiagramNode.d.ts.map +1 -0
- package/dist/components/markdown-view/diagram/FlowchartDiagramNode.js +63 -0
- package/dist/components/markdown-view/diagram/FlowchartDiagramNode.js.map +1 -0
- package/dist/components/markdown-view/diagram/MermaidFence.d.ts +30 -0
- package/dist/components/markdown-view/diagram/MermaidFence.d.ts.map +1 -0
- package/dist/components/markdown-view/diagram/MermaidFence.js +30 -0
- package/dist/components/markdown-view/diagram/MermaidFence.js.map +1 -0
- package/dist/components/markdown-view/diagram/flowchartParser.d.ts +18 -0
- package/dist/components/markdown-view/diagram/flowchartParser.d.ts.map +1 -0
- package/dist/components/markdown-view/diagram/flowchartParser.js +370 -0
- package/dist/components/markdown-view/diagram/flowchartParser.js.map +1 -0
- package/dist/components/markdown-view/diagram/graphModel.d.ts +67 -0
- package/dist/components/markdown-view/diagram/graphModel.d.ts.map +1 -0
- package/dist/components/markdown-view/diagram/graphModel.js +0 -0
- package/dist/components/markdown-view/diagram/layoutFlowchart.d.ts +109 -0
- package/dist/components/markdown-view/diagram/layoutFlowchart.d.ts.map +1 -0
- package/dist/components/markdown-view/diagram/layoutFlowchart.js +185 -0
- package/dist/components/markdown-view/diagram/layoutFlowchart.js.map +1 -0
- package/dist/components/markdown-view/diagram/textMetrics.d.ts +63 -0
- package/dist/components/markdown-view/diagram/textMetrics.d.ts.map +1 -0
- package/dist/components/markdown-view/diagram/textMetrics.js +228 -0
- package/dist/components/markdown-view/diagram/textMetrics.js.map +1 -0
- package/dist/components/markdown-view/markdown-view.d.ts +32 -0
- package/dist/components/markdown-view/markdown-view.d.ts.map +1 -1
- package/dist/components/markdown-view/markdown-view.js +85 -9
- package/dist/components/markdown-view/markdown-view.js.map +1 -1
- package/dist/components/nav-shell/nav-shell.d.ts +1 -1
- package/dist/components/nav-shell/nav-shell.d.ts.map +1 -1
- package/dist/components/nav-shell/nav-shell.js +1 -1
- package/dist/components/nav-shell/nav-shell.js.map +1 -1
- package/dist/components/nav-shell/spotlight.d.ts.map +1 -1
- package/dist/components/nav-shell/spotlight.js.map +1 -1
- package/dist/components/nav-shell/use-nav-breadcrumbs.d.ts.map +1 -1
- package/dist/components/nav-shell/use-nav-breadcrumbs.js.map +1 -1
- package/dist/components/nav-shell/use-nav-entries.d.ts +15 -5
- package/dist/components/nav-shell/use-nav-entries.d.ts.map +1 -1
- package/dist/components/nav-shell/use-nav-entries.js +1 -1
- package/dist/components/nav-shell/use-nav-entries.js.map +1 -1
- package/dist/components/nav-shell/use-nav-tree.d.ts.map +1 -1
- package/dist/components/nav-shell/use-nav-tree.js.map +1 -1
- package/dist/components/settings/settings-card-edge.d.ts +25 -0
- package/dist/components/settings/settings-card-edge.d.ts.map +1 -0
- package/dist/components/settings/settings-card-edge.js +29 -0
- package/dist/components/settings/settings-card-edge.js.map +1 -0
- package/dist/components/settings/settings-danger-section.d.ts.map +1 -1
- package/dist/components/settings/settings-danger-section.js +2 -1
- package/dist/components/settings/settings-danger-section.js.map +1 -1
- package/dist/components/settings/settings-layout.d.ts.map +1 -1
- package/dist/components/settings/settings-layout.js +1 -1
- package/dist/components/settings/settings-layout.js.map +1 -1
- package/dist/components/settings/settings-nav.d.ts.map +1 -1
- package/dist/components/settings/settings-nav.js +3 -3
- package/dist/components/settings/settings-nav.js.map +1 -1
- package/dist/components/settings/settings-row.js +2 -2
- package/dist/components/settings/settings-row.js.map +1 -1
- package/dist/components/settings/settings-section.d.ts.map +1 -1
- package/dist/components/settings/settings-section.js +3 -2
- package/dist/components/settings/settings-section.js.map +1 -1
- package/dist/components/ui/accordion.js +3 -3
- package/dist/components/ui/accordion.js.map +1 -1
- package/dist/components/ui/alert-dialog.js +5 -5
- package/dist/components/ui/alert-dialog.js.map +1 -1
- package/dist/components/ui/alert.js +2 -2
- package/dist/components/ui/alert.js.map +1 -1
- package/dist/components/ui/avatar.js +5 -5
- package/dist/components/ui/avatar.js.map +1 -1
- package/dist/components/ui/badge.d.ts +13 -2
- package/dist/components/ui/badge.d.ts.map +1 -1
- package/dist/components/ui/badge.js +51 -12
- package/dist/components/ui/badge.js.map +1 -1
- package/dist/components/ui/breadcrumb.js +3 -3
- package/dist/components/ui/breadcrumb.js.map +1 -1
- package/dist/components/ui/button-group.js +2 -2
- package/dist/components/ui/button-group.js.map +1 -1
- package/dist/components/ui/button.js +2 -2
- package/dist/components/ui/button.js.map +1 -1
- package/dist/components/ui/calendar.js +8 -8
- package/dist/components/ui/calendar.js.map +1 -1
- package/dist/components/ui/card.js +3 -3
- package/dist/components/ui/card.js.map +1 -1
- package/dist/components/ui/carousel.d.ts.map +1 -1
- package/dist/components/ui/carousel.js +20 -10
- package/dist/components/ui/carousel.js.map +1 -1
- package/dist/components/ui/chart.d.ts.map +1 -1
- package/dist/components/ui/chart.js +7 -6
- package/dist/components/ui/chart.js.map +1 -1
- package/dist/components/ui/checkbox.js +1 -1
- package/dist/components/ui/checkbox.js.map +1 -1
- package/dist/components/ui/combobox.d.ts.map +1 -1
- package/dist/components/ui/combobox.js +8 -8
- package/dist/components/ui/combobox.js.map +1 -1
- package/dist/components/ui/command.d.ts.map +1 -1
- package/dist/components/ui/command.js +6 -6
- package/dist/components/ui/command.js.map +1 -1
- package/dist/components/ui/context-menu.js +8 -8
- package/dist/components/ui/context-menu.js.map +1 -1
- package/dist/components/ui/dialog.js +4 -4
- package/dist/components/ui/dialog.js.map +1 -1
- package/dist/components/ui/drawer.js +4 -4
- package/dist/components/ui/drawer.js.map +1 -1
- package/dist/components/ui/dropdown-menu.js +9 -9
- package/dist/components/ui/dropdown-menu.js.map +1 -1
- package/dist/components/ui/empty.js +2 -2
- package/dist/components/ui/empty.js.map +1 -1
- package/dist/components/ui/hover-card.js +1 -1
- package/dist/components/ui/hover-card.js.map +1 -1
- package/dist/components/ui/input-group.d.ts.map +1 -1
- package/dist/components/ui/input-group.js +3 -3
- package/dist/components/ui/input-group.js.map +1 -1
- package/dist/components/ui/input-otp.js +3 -3
- package/dist/components/ui/input-otp.js.map +1 -1
- package/dist/components/ui/input.js +1 -1
- package/dist/components/ui/input.js.map +1 -1
- package/dist/components/ui/item.js +3 -3
- package/dist/components/ui/item.js.map +1 -1
- package/dist/components/ui/kbd.js +1 -1
- package/dist/components/ui/kbd.js.map +1 -1
- package/dist/components/ui/label.d.ts.map +1 -1
- package/dist/components/ui/label.js.map +1 -1
- package/dist/components/ui/menubar.js +9 -9
- package/dist/components/ui/menubar.js.map +1 -1
- package/dist/components/ui/navigation-menu.js +7 -7
- package/dist/components/ui/navigation-menu.js.map +1 -1
- package/dist/components/ui/pagination.d.ts.map +1 -1
- package/dist/components/ui/pagination.js.map +1 -1
- package/dist/components/ui/popover.js +1 -1
- package/dist/components/ui/popover.js.map +1 -1
- package/dist/components/ui/progress.js +3 -3
- package/dist/components/ui/progress.js.map +1 -1
- package/dist/components/ui/radio-group.js +2 -2
- package/dist/components/ui/radio-group.js.map +1 -1
- package/dist/components/ui/resizable.js +2 -2
- package/dist/components/ui/resizable.js.map +1 -1
- package/dist/components/ui/scroll-area.js +2 -2
- package/dist/components/ui/scroll-area.js.map +1 -1
- package/dist/components/ui/segmented.d.ts.map +1 -1
- package/dist/components/ui/segmented.js +1 -1
- package/dist/components/ui/segmented.js.map +1 -1
- package/dist/components/ui/select.js +8 -8
- package/dist/components/ui/select.js.map +1 -1
- package/dist/components/ui/separator.js +1 -1
- package/dist/components/ui/separator.js.map +1 -1
- package/dist/components/ui/sheet.js +3 -3
- package/dist/components/ui/sheet.js.map +1 -1
- package/dist/components/ui/sidebar.js +17 -17
- package/dist/components/ui/sidebar.js.map +1 -1
- package/dist/components/ui/skeleton.js +1 -1
- package/dist/components/ui/skeleton.js.map +1 -1
- package/dist/components/ui/slider.js +2 -2
- package/dist/components/ui/slider.js.map +1 -1
- package/dist/components/ui/sonner.js +1 -1
- package/dist/components/ui/switch.js +2 -2
- package/dist/components/ui/switch.js.map +1 -1
- package/dist/components/ui/table.d.ts.map +1 -1
- package/dist/components/ui/table.js +5 -5
- package/dist/components/ui/table.js.map +1 -1
- package/dist/components/ui/tabs.js +2 -2
- package/dist/components/ui/tabs.js.map +1 -1
- package/dist/components/ui/textarea.js +1 -1
- package/dist/components/ui/textarea.js.map +1 -1
- package/dist/components/ui/toggle-group.d.ts.map +1 -1
- package/dist/components/ui/toggle-group.js +13 -7
- package/dist/components/ui/toggle-group.js.map +1 -1
- package/dist/components/ui/toggle.js +2 -2
- package/dist/components/ui/toggle.js.map +1 -1
- package/dist/components/ui/tooltip.d.ts +10 -0
- package/dist/components/ui/tooltip.d.ts.map +1 -1
- package/dist/components/ui/tooltip.js +13 -3
- package/dist/components/ui/tooltip.js.map +1 -1
- package/dist/components/use-dialog/use-dialog.d.ts +2 -2
- package/dist/components/use-dialog/use-dialog.d.ts.map +1 -1
- package/dist/components/use-dialog/use-dialog.js +10 -6
- package/dist/components/use-dialog/use-dialog.js.map +1 -1
- package/dist/components/use-toast/use-toast.d.ts +9 -3
- package/dist/components/use-toast/use-toast.d.ts.map +1 -1
- package/dist/components/use-toast/use-toast.js +23 -22
- package/dist/components/use-toast/use-toast.js.map +1 -1
- package/dist/hooks/use-mobile.d.ts +10 -0
- package/dist/hooks/use-mobile.d.ts.map +1 -1
- package/dist/hooks/use-mobile.js +19 -12
- package/dist/hooks/use-mobile.js.map +1 -1
- package/dist/lib/i18n-fr.d.ts +3 -3
- package/dist/lib/i18n-fr.d.ts.map +1 -1
- package/dist/lib/i18n-fr.js +13 -8
- package/dist/lib/i18n-fr.js.map +1 -1
- package/dist/styles.css +5 -5
- package/package.json +46 -45
- package/src/components/account/__tests__/account-router.spec.ts +4 -2
- package/src/components/account/account-connections.tsx +1 -1
- package/src/components/account/account-header.tsx +6 -1
- package/src/components/account/account-keys.tsx +1 -1
- package/src/components/account/account-layout.tsx +8 -1
- package/src/components/account/account-profile.tsx +3 -3
- package/src/components/account/account-router-options.tsx +1 -0
- package/src/components/account/account-router-page.tsx +1 -0
- package/src/components/account/account-router.tsx +4 -2
- package/src/components/account/account-security.tsx +1 -0
- package/src/components/account/account-sessions.tsx +21 -4
- package/src/components/admin/__tests__/admin-keys-token-dialog.browser.spec.tsx +1 -0
- package/src/components/admin/__tests__/admin-layout.browser.spec.tsx +2 -1
- package/src/components/admin/__tests__/admin-router-page.spec.ts +2 -1
- package/src/components/admin/__tests__/admin-router.spec.ts +57 -1
- package/src/components/admin/__tests__/admin-user-cell.browser.spec.tsx +1 -0
- package/src/components/admin/__tests__/admin-user-detail.spec.ts +1 -0
- package/src/components/admin/admin-analytics-query-panel.tsx +4 -3
- package/src/components/admin/admin-analytics-results.tsx +2 -2
- package/src/components/admin/admin-analytics.tsx +3 -3
- package/src/components/admin/admin-audits.tsx +3 -3
- package/src/components/admin/admin-dashboard-card.tsx +45 -0
- package/src/components/admin/admin-dashboard-count-card.tsx +89 -0
- package/src/components/admin/admin-dashboard.tsx +60 -0
- package/src/components/admin/admin-files.tsx +2 -2
- package/src/components/admin/admin-jobs-executions-panel.tsx +19 -12
- package/src/components/admin/admin-jobs-status-badge.tsx +2 -2
- package/src/components/admin/admin-jobs.tsx +4 -4
- package/src/components/admin/admin-keys-token-dialog.tsx +2 -2
- package/src/components/admin/admin-keys.tsx +2 -2
- package/src/components/admin/admin-layout.tsx +1 -2
- package/src/components/admin/admin-notifications.tsx +2 -2
- package/src/components/admin/admin-parameters.tsx +16 -9
- package/src/components/admin/admin-payments.tsx +2 -2
- package/src/components/admin/admin-router-options.tsx +14 -10
- package/src/components/admin/admin-router-page.tsx +8 -5
- package/src/components/admin/admin-router.tsx +112 -40
- package/src/components/admin/admin-sessions.tsx +13 -2
- package/src/components/admin/admin-user-detail-audits-tab.tsx +5 -2
- package/src/components/admin/admin-user-detail-identity-aside.tsx +16 -93
- package/src/components/admin/admin-user-detail-overview-tab.tsx +1 -0
- package/src/components/admin/admin-user-detail-password-dialog.tsx +1 -0
- package/src/components/admin/admin-user-detail-profile-policy.spec.ts +1 -0
- package/src/components/admin/admin-user-detail-profile-policy.ts +1 -0
- package/src/components/admin/admin-user-detail-security-tab.tsx +1 -0
- package/src/components/admin/admin-user-detail-sessions-tab.tsx +5 -2
- package/src/components/admin/admin-user-detail.tsx +49 -87
- package/src/components/admin/admin-users-roles-picker.tsx +22 -15
- package/src/components/admin/admin-users.tsx +8 -14
- package/src/components/admin/admin-workflows-execution-sheet.tsx +18 -10
- package/src/components/admin/admin-workflows-executions-panel.tsx +24 -17
- package/src/components/admin/admin-workflows-status-badge.tsx +4 -2
- package/src/components/admin/admin-workflows.tsx +6 -4
- package/src/components/admin/diff-lines.spec.ts +1 -0
- package/src/components/admin/diff-lines.ts +1 -1
- package/src/components/admin/parameter-diff-dialog.tsx +3 -2
- package/src/components/admin/parameter-history-item.tsx +6 -5
- package/src/components/alepha-table/__tests__/alepha-table-static.browser.spec.tsx +190 -0
- package/src/components/alepha-table/__tests__/paginate-local.spec.ts +286 -0
- package/src/components/alepha-table/__tests__/use-table-selection.browser.spec.tsx +1 -0
- package/src/components/alepha-table/alepha-table.tsx +362 -79
- package/src/components/alepha-table/paginate-local.ts +174 -0
- package/src/components/app-actions/__tests__/app-actions.browser.spec.tsx +1 -0
- package/src/components/app-shell/app-shell.tsx +42 -19
- package/src/components/auth/__tests__/auth-router.spec.ts +2 -1
- package/src/components/auth/auth-login.tsx +5 -16
- package/src/components/auth/auth-register.tsx +26 -25
- package/src/components/auth/auth-reset-password.tsx +24 -17
- package/src/components/auth/auth-router.tsx +4 -3
- package/src/components/auth/auth-verify-email.tsx +7 -7
- package/src/components/auth/safe-redirect.ts +14 -0
- package/src/components/auto-form/__tests__/auto-form-settings-card.browser.spec.tsx +1 -0
- package/src/components/auto-form/auto-form.tsx +60 -39
- package/src/components/brand-icon/brand-icon.tsx +2 -2
- package/src/components/button-dark/button-dark.tsx +2 -2
- package/src/components/button-language/button-language.tsx +2 -2
- package/src/components/button-theme/button-theme.tsx +2 -2
- package/src/components/button-user/button-user.tsx +4 -4
- package/src/components/captcha/turnstile-widget.tsx +6 -5
- package/src/components/control/control.tsx +6 -6
- package/src/components/control-array/control-array.tsx +28 -15
- package/src/components/control-base/__tests__/form-field-a11y.browser.spec.tsx +1 -0
- package/src/components/control-base/field-i18n.ts +5 -3
- package/src/components/control-base/form-field.tsx +13 -13
- package/src/components/control-base/icon-hint.tsx +1 -1
- package/src/components/control-date/control-date.tsx +29 -6
- package/src/components/control-number/control-number.tsx +3 -3
- package/src/components/control-object/control-object.tsx +11 -8
- package/src/components/control-password/control-password.tsx +2 -2
- package/src/components/control-select/__tests__/control-select-clear-label.browser.spec.tsx +1 -0
- package/src/components/control-select/__tests__/control-select-deselect.browser.spec.tsx +1 -0
- package/src/components/control-select/__tests__/control-select-searchable.browser.spec.tsx +1 -0
- package/src/components/control-select/control-select.tsx +32 -18
- package/src/components/control-upload/control-upload.tsx +16 -10
- package/src/components/detail/__tests__/detail-aside.browser.spec.tsx +135 -0
- package/src/components/detail/__tests__/detail-layout.browser.spec.tsx +151 -0
- package/src/components/detail/detail-aside.tsx +198 -0
- package/src/components/detail/detail-layout.tsx +181 -0
- package/src/components/detail/use-detail-tab.tsx +41 -0
- package/src/components/file-image/file-image.tsx +4 -2
- package/src/components/language-toggle/language-toggle.tsx +2 -2
- package/src/components/markdown-view/__tests__/markdown-view-mermaid.browser.spec.tsx +148 -0
- package/src/components/markdown-view/__tests__/markdown-view-raw-html.browser.spec.tsx +1 -0
- package/src/components/markdown-view/diagram/DiagramErrorBoundary.tsx +42 -0
- package/src/components/markdown-view/diagram/FlowchartDiagram.tsx +136 -0
- package/src/components/markdown-view/diagram/FlowchartDiagramCluster.tsx +59 -0
- package/src/components/markdown-view/diagram/FlowchartDiagramEdge.tsx +95 -0
- package/src/components/markdown-view/diagram/FlowchartDiagramLabel.tsx +58 -0
- package/src/components/markdown-view/diagram/FlowchartDiagramNode.tsx +78 -0
- package/src/components/markdown-view/diagram/MermaidFence.tsx +46 -0
- package/src/components/markdown-view/diagram/__tests__/flowchart-diagram.browser.spec.tsx +210 -0
- package/src/components/markdown-view/diagram/flowchartParser.spec.ts +379 -0
- package/src/components/markdown-view/diagram/flowchartParser.ts +475 -0
- package/src/components/markdown-view/diagram/graphModel.ts +72 -0
- package/src/components/markdown-view/diagram/layoutFlowchart.spec.ts +235 -0
- package/src/components/markdown-view/diagram/layoutFlowchart.ts +324 -0
- package/src/components/markdown-view/diagram/textMetrics.spec.ts +128 -0
- package/src/components/markdown-view/diagram/textMetrics.ts +296 -0
- package/src/components/markdown-view/markdown-view.tsx +128 -9
- package/src/components/nav-shell/__tests__/nav-tree-util.spec.ts +1 -0
- package/src/components/nav-shell/nav-shell.tsx +6 -3
- package/src/components/nav-shell/spotlight.tsx +2 -1
- package/src/components/nav-shell/use-nav-breadcrumbs.ts +1 -0
- package/src/components/nav-shell/use-nav-entries.ts +16 -5
- package/src/components/nav-shell/use-nav-tree.ts +1 -0
- package/src/components/settings/__tests__/settings-nav.browser.spec.tsx +1 -0
- package/src/components/settings/__tests__/settings-section.browser.spec.tsx +1 -0
- package/src/components/settings/settings-card-edge.ts +24 -0
- package/src/components/settings/settings-danger-section.tsx +7 -1
- package/src/components/settings/settings-layout.tsx +16 -1
- package/src/components/settings/settings-nav.tsx +12 -3
- package/src/components/settings/settings-row.tsx +2 -2
- package/src/components/settings/settings-section.tsx +2 -1
- package/src/components/ui/accordion.tsx +3 -3
- package/src/components/ui/alert-dialog.tsx +5 -5
- package/src/components/ui/alert.tsx +2 -2
- package/src/components/ui/avatar.tsx +5 -5
- package/src/components/ui/badge.tsx +48 -2
- package/src/components/ui/breadcrumb.tsx +3 -3
- package/src/components/ui/button-group.tsx +2 -2
- package/src/components/ui/button.tsx +2 -2
- package/src/components/ui/calendar.tsx +8 -8
- package/src/components/ui/card.tsx +3 -3
- package/src/components/ui/carousel.tsx +30 -13
- package/src/components/ui/chart.tsx +18 -6
- package/src/components/ui/checkbox.tsx +1 -1
- package/src/components/ui/combobox.tsx +8 -9
- package/src/components/ui/command.tsx +6 -7
- package/src/components/ui/context-menu.tsx +8 -8
- package/src/components/ui/dialog.tsx +4 -4
- package/src/components/ui/drawer.tsx +4 -4
- package/src/components/ui/dropdown-menu.tsx +9 -9
- package/src/components/ui/empty.tsx +2 -2
- package/src/components/ui/hover-card.tsx +1 -1
- package/src/components/ui/input-group.tsx +6 -3
- package/src/components/ui/input-otp.tsx +3 -3
- package/src/components/ui/input.tsx +1 -1
- package/src/components/ui/item.tsx +3 -3
- package/src/components/ui/kbd.tsx +1 -1
- package/src/components/ui/label.tsx +3 -0
- package/src/components/ui/menubar.tsx +9 -9
- package/src/components/ui/navigation-menu.tsx +7 -7
- package/src/components/ui/pagination.tsx +0 -1
- package/src/components/ui/popover.tsx +1 -1
- package/src/components/ui/progress.tsx +3 -3
- package/src/components/ui/radio-group.tsx +2 -2
- package/src/components/ui/resizable.tsx +2 -2
- package/src/components/ui/scroll-area.tsx +2 -2
- package/src/components/ui/segmented.tsx +8 -3
- package/src/components/ui/select.tsx +8 -8
- package/src/components/ui/separator.tsx +1 -1
- package/src/components/ui/sheet.tsx +3 -3
- package/src/components/ui/sidebar.tsx +20 -20
- package/src/components/ui/skeleton.tsx +1 -1
- package/src/components/ui/slider.tsx +2 -2
- package/src/components/ui/switch.tsx +2 -2
- package/src/components/ui/table.tsx +10 -5
- package/src/components/ui/tabs.tsx +3 -3
- package/src/components/ui/textarea.tsx +1 -1
- package/src/components/ui/toggle-group.tsx +9 -4
- package/src/components/ui/toggle.tsx +2 -2
- package/src/components/ui/tooltip.tsx +13 -3
- package/src/components/use-dialog/use-dialog.tsx +19 -6
- package/src/components/use-toast/__tests__/use-toast.browser.spec.tsx +19 -0
- package/src/components/use-toast/use-toast.tsx +38 -26
- package/src/hooks/use-mobile.ts +27 -14
- package/src/lib/__tests__/i18n-fr.spec.ts +5 -1
- package/src/lib/i18n-fr.ts +18 -10
- package/src/styles.css +5 -5
|
@@ -2,12 +2,12 @@ import { cn } from "../../lib/utils.js";
|
|
|
2
2
|
import { FormField } from "../control-base/form-field.js";
|
|
3
3
|
import { Combobox as Combobox$1, ComboboxChip, ComboboxChips, ComboboxChipsInput, ComboboxContent, ComboboxEmpty, ComboboxInput, ComboboxItem, ComboboxList, ComboboxTrigger, useComboboxAnchor } from "../ui/combobox.js";
|
|
4
4
|
import { Segmented } from "../ui/segmented.js";
|
|
5
|
-
import {
|
|
6
|
-
import { useAction } from "alepha/react";
|
|
5
|
+
import { useMemo, useRef, useState } from "react";
|
|
7
6
|
import { Fragment as Fragment$1, jsx, jsxs } from "react/jsx-runtime";
|
|
8
7
|
import { Loader2 } from "lucide-react";
|
|
9
|
-
import { parseField, useFieldValue, useFormState } from "alepha/react/form";
|
|
10
8
|
import { useI18n } from "alepha/react/i18n";
|
|
9
|
+
import { useAction } from "alepha/react";
|
|
10
|
+
import { parseField, useFieldValue, useFormState } from "alepha/react/form";
|
|
11
11
|
//#region src/components/control-select/control-select.tsx
|
|
12
12
|
/**
|
|
13
13
|
* Internal sentinel for the `clearable` row. Picked to be unlikely to
|
|
@@ -34,7 +34,7 @@ const optIcon = (o) => typeof o === "string" ? void 0 : o.icon;
|
|
|
34
34
|
*/
|
|
35
35
|
const titlecase = (s) => s.replace(/[_-]+/g, " ").replace(/\b\w/g, (c) => c.toUpperCase());
|
|
36
36
|
const segmentedLabel = (o) => typeof o === "string" ? titlecase(o) : o.label;
|
|
37
|
-
|
|
37
|
+
const ControlSelect = (props) => {
|
|
38
38
|
const { tr } = useI18n();
|
|
39
39
|
const form = useFormState(props.input, ["error"]);
|
|
40
40
|
const [value, setValue] = useFieldValue(props.input);
|
|
@@ -51,24 +51,24 @@ function ControlSelect(props) {
|
|
|
51
51
|
const enumValues = itemsArray ?? meta.enum ?? [];
|
|
52
52
|
const effectiveLoader = props.loader ?? itemsLoader;
|
|
53
53
|
const { data: asyncData, loading, mode, search } = useAsyncLoader(effectiveLoader, props.loaderThreshold ?? 100, props.loaderDebounce ?? 300, props.input.initialValue);
|
|
54
|
-
const
|
|
55
|
-
const enumKey = enumValues.map(optValue).join("");
|
|
54
|
+
const enumKey = JSON.stringify(enumValues);
|
|
56
55
|
const min = meta.constraints.minimum;
|
|
57
56
|
const max = meta.constraints.maximum;
|
|
58
|
-
|
|
59
|
-
if (effectiveLoader) return;
|
|
60
|
-
if (isBoolean && enumValues.length === 0)
|
|
57
|
+
const staticData = useMemo(() => {
|
|
58
|
+
if (effectiveLoader) return [];
|
|
59
|
+
if (isBoolean && enumValues.length === 0) return [{
|
|
61
60
|
value: "true",
|
|
62
61
|
label: tr("controlSelect.yes", { default: "Yes" })
|
|
63
62
|
}, {
|
|
64
63
|
value: "false",
|
|
65
64
|
label: tr("controlSelect.no", { default: "No" })
|
|
66
|
-
}]
|
|
67
|
-
|
|
65
|
+
}];
|
|
66
|
+
if (isNumeric && enumValues.length === 0 && typeof min === "number" && typeof max === "number" && max - min <= 20) {
|
|
68
67
|
const range = [];
|
|
69
68
|
for (let i = min; i <= max; i++) range.push(String(i));
|
|
70
|
-
|
|
71
|
-
}
|
|
69
|
+
return range;
|
|
70
|
+
}
|
|
71
|
+
return enumValues;
|
|
72
72
|
}, [
|
|
73
73
|
effectiveLoader,
|
|
74
74
|
enumKey,
|
|
@@ -130,7 +130,7 @@ function ControlSelect(props) {
|
|
|
130
130
|
placeholder: props.clearable ? clearLabel : void 0
|
|
131
131
|
})
|
|
132
132
|
});
|
|
133
|
-
}
|
|
133
|
+
};
|
|
134
134
|
/**
|
|
135
135
|
* Searchable single/multi select built on the Base UI `Combobox` primitive.
|
|
136
136
|
*
|
|
@@ -239,14 +239,14 @@ function Combobox(props) {
|
|
|
239
239
|
children: [/* @__PURE__ */ jsxs("div", {
|
|
240
240
|
className: "flex items-center gap-1.5",
|
|
241
241
|
children: [opt.tag && /* @__PURE__ */ jsx("span", {
|
|
242
|
-
className: "bg-muted text-muted-foreground rounded px-1 text-[10px]
|
|
242
|
+
className: "bg-muted text-muted-foreground rounded px-1 text-[10px] tracking-wide uppercase",
|
|
243
243
|
children: opt.tag
|
|
244
244
|
}), /* @__PURE__ */ jsx("span", {
|
|
245
245
|
className: "truncate",
|
|
246
246
|
children: opt.label
|
|
247
247
|
})]
|
|
248
248
|
}), opt.description && /* @__PURE__ */ jsx("span", {
|
|
249
|
-
className: "text-muted-foreground text-xs
|
|
249
|
+
className: "text-muted-foreground truncate text-xs",
|
|
250
250
|
children: opt.description
|
|
251
251
|
})]
|
|
252
252
|
})]
|
|
@@ -282,7 +282,7 @@ function Combobox(props) {
|
|
|
282
282
|
})] }) : /* @__PURE__ */ jsxs(Fragment$1, { children: [/* @__PURE__ */ jsx(ComboboxTrigger, {
|
|
283
283
|
id: props.id,
|
|
284
284
|
disabled: props.disabled,
|
|
285
|
-
className: cn("flex h-8 w-full items-center justify-between gap-1.5 rounded-lg border
|
|
285
|
+
className: cn("border-input focus-visible:border-ring focus-visible:ring-ring/50 dark:bg-input/30 dark:hover:bg-input/50 flex h-8 w-full items-center justify-between gap-1.5 rounded-lg border bg-transparent py-2 pr-2 pl-2.5 text-sm whitespace-nowrap transition-colors outline-none select-none focus-visible:ring-3 disabled:cursor-not-allowed disabled:opacity-50", selected.length === 0 && !props.clearable && "text-muted-foreground", props.triggerClassName),
|
|
286
286
|
children: /* @__PURE__ */ jsxs("span", {
|
|
287
287
|
className: "flex min-w-0 items-center gap-2",
|
|
288
288
|
children: [props.icon && /* @__PURE__ */ jsx(props.icon, { className: "text-muted-foreground size-4 shrink-0" }), /* @__PURE__ */ jsx("span", {
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"control-select.js","names":["ComboboxRoot"],"sources":["../../../src/components/control-select/control-select.tsx"],"sourcesContent":["import * as React from \"react\";\n\nvoid React;\n\nimport { FormField } from \"@alepha/ui/components/control-base/form-field\";\nimport type { IconComponent } from \"@alepha/ui/components/control-base/icon-hint\";\nimport {\n ComboboxChip,\n ComboboxChips,\n ComboboxChipsInput,\n ComboboxContent,\n ComboboxEmpty,\n ComboboxInput,\n ComboboxItem,\n ComboboxList,\n Combobox as ComboboxRoot,\n ComboboxTrigger,\n useComboboxAnchor,\n} from \"@alepha/ui/components/ui/combobox\";\nimport { Segmented } from \"@alepha/ui/components/ui/segmented\";\nimport { cn } from \"@alepha/ui/lib/utils\";\nimport type { Async } from \"alepha\";\nimport { useAction } from \"alepha/react\";\nimport {\n type BaseInputField,\n parseField,\n useFieldValue,\n useFormState,\n} from \"alepha/react/form\";\nimport { useI18n } from \"alepha/react/i18n\";\nimport { Loader2 } from \"lucide-react\";\nimport { type ReactNode, useEffect, useRef, useState } from \"react\";\n\nexport type SelectOption =\n | string\n | {\n value: string;\n label: string;\n /**\n * Optional secondary line shown under the label in the dropdown.\n */\n description?: string;\n /**\n * Optional small badge rendered next to the label.\n */\n tag?: string;\n /**\n * Optional icon/element rendered before the label, in both the\n * dropdown row and (for single-select) the trigger when selected.\n */\n icon?: ReactNode;\n /**\n * When true, the row is non-interactive — can't be selected if\n * not selected, can't be deselected if selected. Useful for\n * default/mandatory entries (e.g. the base \"user\" role).\n */\n disabled?: boolean;\n };\n\ntype LoaderMode = \"static\" | \"short\" | \"long\";\n\nexport interface ControlSelectProps {\n /**\n * Bound `InputField` from `useForm`. Single or multi value depending on schema.\n */\n input: BaseInputField;\n /**\n * Field label. Falls back to schema `title`.\n */\n label?: string;\n /**\n * Helper text shown below the input.\n */\n description?: string;\n /**\n * Render as a `<Segmented>` control (best for 2–4 options).\n */\n segmented?: boolean;\n /**\n * Force the search input on. Kept as the historical name for\n * `searchable: true` — every select is a combobox now, the flag only\n * decides whether it carries a search field.\n */\n combobox?: boolean;\n /**\n * Whether the dropdown carries a search input. Defaults to \"auto\": on for\n * multi-select, for a long-mode `loader`, and for static lists longer than\n * `SEARCH_THRESHOLD`. Set explicitly to search a short list or to drop the\n * search field from a long one.\n */\n searchable?: boolean;\n /**\n * Async option loader. Triggers long-mode (server-side search) above `loaderThreshold` options.\n */\n loader?: (search: string, resolve?: string[]) => Async<SelectOption[]>;\n /**\n * Option count above which `loader` is invoked on every search instead of once. Defaults to ~50.\n */\n loaderThreshold?: number;\n /**\n * Debounce in ms applied to search queries when calling `loader` in long mode.\n */\n loaderDebounce?: number;\n /**\n * Disable the control.\n */\n disabled?: boolean;\n /**\n * Inline option list (overrides schema `enum`). Accepts either a static\n * array or an async function `(query) => SelectOption[]`. The async form\n * is mapped to a long-mode loader.\n */\n items?:\n | SelectOption[]\n | ((query: string) => SelectOption[] | Promise<SelectOption[]>);\n /**\n * Allow the user to add a new option by typing. When `true`, the typed\n * query becomes the value (and label) of a freshly created entry. When a\n * function, the function builds the option from the query.\n *\n * - For multi-select fields: each entry is appended to the value array.\n * - For single fields: behaves like a regular text input with a dropdown\n * suggesting existing options.\n */\n createNewEntry?: boolean | ((query: string) => Exclude<SelectOption, string>);\n /**\n * When true, the dropdown gets a synthetic \"none\" row at the top that\n * resets the field to `undefined`. Useful for optional filter chips\n * (e.g. an admin-table status filter) where the user needs an explicit\n * \"no filter\" option — Base UI's `Select` reserves empty-string values\n * as its internal no-selection sentinel, so a regular `<SelectItem\n * value=\"\">` can't be picked. With `clearable`, ControlSelect uses an\n * internal sentinel and translates it to `undefined` in `onChange`.\n *\n * Currently honored by the static-short `Select` and the searchable\n * Combobox render paths. Ignored by `segmented` (use a real segment\n * for \"all\" there).\n */\n clearable?: boolean;\n /**\n * Label rendered for the \"clear\" row injected by `clearable`. Also\n * used as the trigger placeholder when the field is empty. Defaults to\n * `\"None\"`. Localize at the call site (e.g. `\"All types\"`,\n * `\"All status\"`).\n */\n clearLabel?: string;\n /**\n * Extra className applied to the visible trigger (the `<SelectTrigger>`\n * or combobox `<Button>`). Useful for sizing filter chips\n * (`\"w-40\"`, `\"w-72\"`, etc.) without wrapping the whole `FormField` in\n * an extra div.\n */\n triggerClassName?: string;\n /**\n * Leading icon rendered on the left of the trigger, matching the\n * text-input controls. Resolved by the parent `Control` from its `icon`\n * prop — unlike text inputs there is no schema-hint fallback, so a select\n * only shows an icon when one is explicitly set.\n */\n icon?: IconComponent;\n}\n\n/**\n * Internal sentinel for the `clearable` row. Picked to be unlikely to\n * collide with a real option value; we translate it to `undefined` at\n * the boundary so callers never see it.\n */\nconst CLEAR_VALUE = \"__alepha_clear__\";\n\n/**\n * Static option count above which the dropdown grows a search input. Below it\n * the very same combobox renders without one — the threshold decides whether\n * you can type, never which control you get.\n */\nconst SEARCH_THRESHOLD = 20;\n\nconst optValue = (o: SelectOption) => (typeof o === \"string\" ? o : o.value);\nconst optLabel = (o: SelectOption) => (typeof o === \"string\" ? o : o.label);\nconst optDesc = (o: SelectOption) =>\n typeof o === \"string\" ? undefined : o.description;\nconst optTag = (o: SelectOption) => (typeof o === \"string\" ? undefined : o.tag);\nconst optDisabled = (o: SelectOption) =>\n typeof o === \"string\" ? false : Boolean(o.disabled);\nconst optIcon = (o: SelectOption): ReactNode =>\n typeof o === \"string\" ? undefined : o.icon;\n\n/**\n * Friendly label for plain string options: \"optional\" → \"Optional\",\n * \"in_progress\" → \"In Progress\". Custom `{ value, label }` items pass through\n * untouched.\n */\nconst titlecase = (s: string) =>\n s.replace(/[_-]+/g, \" \").replace(/\\b\\w/g, (c) => c.toUpperCase());\nconst segmentedLabel = (o: SelectOption) =>\n typeof o === \"string\" ? titlecase(o) : o.label;\n\nexport function ControlSelect(props: ControlSelectProps) {\n const { tr } = useI18n();\n const form = useFormState(props.input, [\"error\"]);\n const [value, setValue] = useFieldValue(props.input);\n\n const meta = parseField(props.input, {\n label: props.label,\n description: props.description,\n error: form.error,\n });\n\n const isArray = meta.isArray;\n const isNumeric = meta.type === \"number\" || meta.type === \"integer\";\n const isBoolean = meta.type === \"boolean\";\n\n // Normalize items prop: array → static; function → loader\n const itemsArray = Array.isArray(props.items)\n ? (props.items as SelectOption[])\n : undefined;\n const itemsLoader =\n typeof props.items === \"function\"\n ? (props.items as (q: string) => Async<SelectOption[]>)\n : undefined;\n\n const enumValues =\n itemsArray ?? (meta.enum as SelectOption[] | undefined) ?? [];\n\n const effectiveLoader = props.loader ?? itemsLoader;\n\n const {\n data: asyncData,\n loading,\n mode,\n search,\n } = useAsyncLoader(\n effectiveLoader,\n props.loaderThreshold ?? 100,\n props.loaderDebounce ?? 300,\n props.input.initialValue,\n );\n\n const [staticData, setStaticData] = useState<SelectOption[]>([]);\n const enumKey = enumValues.map(optValue).join(\"\");\n const min = meta.constraints.minimum;\n const max = meta.constraints.maximum;\n useEffect(() => {\n if (effectiveLoader) return;\n if (isBoolean && enumValues.length === 0) {\n setStaticData([\n { value: \"true\", label: tr(\"controlSelect.yes\", { default: \"Yes\" }) },\n { value: \"false\", label: tr(\"controlSelect.no\", { default: \"No\" }) },\n ]);\n } else if (\n isNumeric &&\n enumValues.length === 0 &&\n typeof min === \"number\" &&\n typeof max === \"number\" &&\n max - min <= 20\n ) {\n const range: SelectOption[] = [];\n for (let i = min; i <= max; i++) range.push(String(i));\n setStaticData(range);\n } else {\n setStaticData(enumValues);\n }\n }, [effectiveLoader, enumKey, isBoolean, isNumeric, min, max, tr]);\n\n const data = effectiveLoader ? asyncData : staticData;\n\n if (!props.input?.props) return null;\n\n const coerce = (raw: string): unknown => {\n if (isNumeric) return Number(raw);\n if (isBoolean) return raw === \"true\";\n return raw;\n };\n\n if (props.segmented) {\n return (\n <FormField\n id={meta.id}\n label={meta.label}\n description={meta.description}\n error={meta.error}\n required={meta.required}\n >\n <Segmented\n value={value != null ? String(value) : undefined}\n onChange={(v) => setValue(coerce(v))}\n disabled={props.disabled}\n options={data.slice(0, 10).map((o) => ({\n value: optValue(o),\n label: segmentedLabel(o),\n }))}\n fullWidth\n />\n </FormField>\n );\n }\n\n const clearLabel =\n props.clearLabel ?? tr(\"controlSelect.none\", { default: \"None\" });\n\n // One control for every list. The option count decides whether the popup\n // carries a search field — it no longer decides which primitive renders.\n // The native `Select` path this replaced silently dropped `description`,\n // `tag`, per-option `disabled` and `deselectable`, and styled its trigger\n // differently, purely because a list happened to be short.\n // Multi-select is never search-less: the chips input IS its trigger.\n const searchable =\n isArray ||\n (props.searchable ??\n (props.combobox || mode === \"long\" || data.length > SEARCH_THRESHOLD));\n\n return (\n <FormField\n id={meta.id}\n label={meta.label}\n description={meta.description}\n error={meta.error}\n required={meta.required}\n >\n <Combobox\n id={meta.id}\n data={data}\n loading={loading}\n multi={isArray}\n searchable={searchable}\n disabled={props.disabled}\n value={value}\n onChange={(v) => setValue(v)}\n coerce={coerce}\n onSearch={mode === \"long\" ? search.run : undefined}\n createNewEntry={props.createNewEntry}\n icon={props.icon}\n // Used to be dropped on this path, so a filter chip sized `w-40` lost\n // its width as soon as its list crossed the threshold.\n triggerClassName={props.triggerClassName}\n // `clearable` used to reach this path as a placeholder and nothing\n // else, so a filter chip that had switched to the combobox (>20\n // options) could be set but never put back to \"All …\".\n clearable={props.clearable}\n clearLabel={clearLabel}\n // An optional field must also be able to go back to empty without a\n // dedicated row: Base UI never emits `null`, so re-pressing the\n // selected row deselects (see `handleSingle`). A required field keeps\n // its value — clearing it would only produce a validation error the\n // user cannot see yet.\n deselectable={props.clearable || !meta.required}\n placeholder={props.clearable ? clearLabel : undefined}\n />\n </FormField>\n );\n}\n\ninterface ComboboxProps {\n id?: string;\n data: SelectOption[];\n loading: boolean;\n multi: boolean;\n /**\n * Render the search input. When false the popup is the list alone — the\n * shape a short static list gets. Multi-select ignores it: its input is the\n * chips box itself, and it is the only way to open and type.\n */\n searchable: boolean;\n disabled?: boolean;\n value: unknown;\n onChange: (v: unknown) => void;\n coerce: (v: string) => unknown;\n onSearch?: (q: string) => void;\n createNewEntry?: ControlSelectProps[\"createNewEntry\"];\n icon?: IconComponent;\n triggerClassName?: string;\n /**\n * Trigger text when nothing is selected. Mirrors the native-Select path,\n * where a `clearable` field shows its `clearLabel` (e.g. \"All zones\") as the\n * empty placeholder. Defaults to \"Select…\".\n */\n placeholder?: string;\n /**\n * Prepend a row that resets the field to `undefined` — the combobox\n * equivalent of the native `Select`'s clear row.\n */\n clearable?: boolean;\n /**\n * Label of the `clearable` row (e.g. \"All zones\").\n */\n clearLabel?: string;\n /**\n * Allow the single-select value to be unset by pressing the row that is\n * already selected. Set for optional (and `clearable`) fields only.\n */\n deselectable?: boolean;\n}\n\n/**\n * Normalized option used as the Base UI `Combobox.Item` value. Because the\n * shape is `{ value, label }`, Base UI uses `label` for display/search and\n * `value` for selection automatically — which is what makes the popup search\n * match the visible label rather than the raw id.\n */\ninterface ComboOption {\n value: string;\n label: string;\n description?: string;\n tag?: string;\n icon?: ReactNode;\n disabled?: boolean;\n /**\n * Marks the synthetic \"create new\" row injected by `createNewEntry`.\n */\n create?: boolean;\n /**\n * Marks the synthetic \"clear\" row injected by `clearable`.\n */\n clear?: boolean;\n /**\n * The raw query that produced a `create` row (used as the new entry's label).\n */\n query?: string;\n}\n\n/**\n * Searchable single/multi select built on the Base UI `Combobox` primitive.\n *\n * Composed in the \"select-like\" shape: a button trigger that shows the current\n * value, with the search `<input>` living inside the popup. We disable Base\n * UI's internal filtering (`filter={null}`) and filter in JS so the same code\n * path serves static lists, server-driven (`onSearch`) lists, and the\n * `createNewEntry` affordance.\n */\nfunction Combobox(props: ComboboxProps) {\n const { tr } = useI18n();\n const [query, setQuery] = useState(\"\");\n // Remembers labels for values the user has picked, so the trigger/chips keep\n // a human label even after the source option drops out of a server-filtered\n // `data` set — or for freshly created entries that never existed in `data`.\n const labelCache = useRef(new Map<string, string>());\n // Positioning anchor for the multi-select chips box (the popup is anchored to\n // the chips container rather than the inline input).\n const anchor = useComboboxAnchor();\n\n const options: ComboOption[] = props.data.map((o) => ({\n value: optValue(o),\n label: optLabel(o),\n description: optDesc(o),\n tag: optTag(o),\n icon: optIcon(o),\n disabled: optDisabled(o),\n }));\n\n const selected: string[] = props.multi\n ? Array.isArray(props.value)\n ? (props.value as unknown[]).map(String)\n : []\n : props.value != null\n ? [String(props.value)]\n : [];\n\n const labelFor = (val: string) =>\n options.find((o) => o.value === val)?.label ??\n labelCache.current.get(val) ??\n val;\n\n const disabledFor = (val: string) =>\n options.find((o) => o.value === val)?.disabled ?? false;\n\n // Server mode (`onSearch`) filters upstream; for static lists we filter on\n // the visible label — never the value/id (that was the cmdk bug).\n const serverMode = Boolean(props.onSearch);\n const q = query.trim().toLowerCase();\n const filtered =\n serverMode || !q\n ? options\n : options.filter((o) => o.label.toLowerCase().includes(q));\n\n const showCreate =\n Boolean(props.createNewEntry) &&\n q.length > 0 &&\n !options.some((o) => o.value === query || o.label.toLowerCase() === q) &&\n !selected.includes(query);\n\n const createOption: ComboOption | undefined = showCreate\n ? (() => {\n const built =\n typeof props.createNewEntry === \"function\"\n ? props.createNewEntry(query)\n : { value: query, label: query };\n return {\n value: built.value,\n label: built.label,\n create: true,\n query,\n };\n })()\n : undefined;\n\n // The synthetic \"no selection\" row — \"All zones\", \"All tags\", \"None\". Only\n // meaningful for a single select: the multi path clears by removing chips.\n const clearRow: ComboOption | undefined =\n props.clearable && !props.multi\n ? {\n value: CLEAR_VALUE,\n label:\n props.clearLabel ?? tr(\"controlSelect.none\", { default: \"None\" }),\n clear: true,\n }\n : undefined;\n // Filtered on its own label like any other row, so searching \"zone\" doesn't\n // leave \"All zones\" stranded at the top of a list it doesn't match.\n const showClear = clearRow && clearRow.label.toLowerCase().includes(q);\n\n const items: ComboOption[] = [\n ...(showClear && clearRow ? [clearRow] : []),\n ...filtered,\n ...(createOption ? [createOption] : []),\n ];\n\n // Reconstruct option objects for the controlled value. Base UI matches them\n // back to list items via `isItemEqualToValue` (by `value`), so identity\n // across renders doesn't matter.\n const toValueObject = (val: string): ComboOption =>\n options.find((o) => o.value === val) ?? {\n value: val,\n label: labelFor(val),\n };\n\n const cbValue = props.multi\n ? selected.map(toValueObject)\n : selected[0]\n ? toValueObject(selected[0])\n : // Empty + clearable reads as \"the clear row is what's selected\", so it\n // carries the check mark — same as the native `Select` path.\n (clearRow ?? null);\n\n const remember = (o: ComboOption) => {\n if (o.create) labelCache.current.set(o.value, o.query ?? o.value);\n else labelCache.current.set(o.value, o.label);\n };\n\n const handleSingle = (o: ComboOption | null) => {\n if (!o || o.clear) {\n props.onChange(undefined);\n setQuery(\"\");\n return;\n }\n // Base UI's single-select `Combobox` re-selects on every item press — its\n // `handleSelection` calls `setSelectedValue(itemValue)` unconditionally and\n // never emits `null` — so pressing the checked row was a no-op and an\n // optional field had no way back to empty. Toggle it off here, the way the\n // multi path already does via its chips.\n if (props.deselectable && !o.create && selected[0] === o.value) {\n props.onChange(undefined);\n setQuery(\"\");\n return;\n }\n remember(o);\n props.onChange(props.coerce(o.value));\n setQuery(\"\");\n };\n\n const handleMulti = (list: ComboOption[]) => {\n for (const o of list) remember(o);\n props.onChange(list.map((o) => props.coerce(o.value)));\n setQuery(\"\");\n };\n\n const emptyLabel =\n props.placeholder ?? tr(\"controlSelect.select\", { default: \"Select…\" });\n const triggerLabel = selected[0] ? labelFor(selected[0]) : emptyLabel;\n\n // The list (loading / empty / items) is identical for single and multi — only\n // the trigger differs (button vs. chips box), so render it once.\n const popupBody = props.loading ? (\n <div className=\"text-muted-foreground flex items-center justify-center gap-2 p-4 text-sm\">\n <Loader2 className=\"size-4 animate-spin\" />{\" \"}\n {tr(\"controlSelect.loading\", { default: \"Loading…\" })}\n </div>\n ) : (\n <>\n <ComboboxEmpty>\n {props.createNewEntry\n ? \"\"\n : tr(\"controlSelect.noResults\", { default: \"No results.\" })}\n </ComboboxEmpty>\n <ComboboxList>\n {(opt: ComboOption) =>\n opt.create ? (\n <ComboboxItem key={`__create__${opt.value}`} value={opt}>\n <span className=\"mr-2\">+</span>\n {tr(\"controlSelect.create\", {\n default: `Create \"${opt.query}\"`,\n args: [String(opt.query ?? \"\")],\n })}\n </ComboboxItem>\n ) : (\n <ComboboxItem key={opt.value} value={opt} disabled={opt.disabled}>\n {opt.icon && (\n <span className=\"mr-2 flex shrink-0 items-center\">\n {opt.icon}\n </span>\n )}\n <div className=\"flex min-w-0 flex-1 flex-col\">\n <div className=\"flex items-center gap-1.5\">\n {opt.tag && (\n <span className=\"bg-muted text-muted-foreground rounded px-1 text-[10px] uppercase tracking-wide\">\n {opt.tag}\n </span>\n )}\n <span className=\"truncate\">{opt.label}</span>\n </div>\n {opt.description && (\n <span className=\"text-muted-foreground text-xs truncate\">\n {opt.description}\n </span>\n )}\n </div>\n </ComboboxItem>\n )\n }\n </ComboboxList>\n </>\n );\n\n return (\n <ComboboxRoot\n items={items as never}\n multiple={props.multi}\n disabled={props.disabled}\n value={cbValue as never}\n onValueChange={\n (props.multi\n ? (v: ComboOption[]) => handleMulti(v)\n : (v: ComboOption | null) => handleSingle(v)) as never\n }\n isItemEqualToValue={\n ((a: ComboOption, b: ComboOption) => a.value === b.value) as never\n }\n filter={null}\n // Base UI leaves `autoHighlight` off by default, so nothing is\n // highlighted while typing and Enter has no target — the user has to\n // click a row (including the `createNewEntry` one). Highlighting the\n // first match makes Enter pick it, which is what a search field is\n // expected to do. It only engages while the query is non-empty, so\n // opening the popup still starts with no preselection.\n autoHighlight\n onInputValueChange={(v) => {\n setQuery(v);\n props.onSearch?.(v);\n }}\n >\n {props.multi ? (\n // Multi-select: removable chips for each value with an inline search\n // input, all inside the bordered chips box (Base UI's native shape).\n <>\n <ComboboxChips\n ref={anchor}\n id={props.id}\n className={cn(\n \"w-full\",\n props.disabled && \"pointer-events-none opacity-50\",\n props.triggerClassName,\n )}\n >\n {props.icon && (\n <props.icon className=\"text-muted-foreground ml-1 size-4 shrink-0\" />\n )}\n {selected.map((val) => (\n <ComboboxChip key={val} showRemove={!disabledFor(val)}>\n {labelFor(val)}\n </ComboboxChip>\n ))}\n <ComboboxChipsInput\n placeholder={\n selected.length === 0\n ? (props.placeholder ?? \"Search…\")\n : \"Search…\"\n }\n />\n </ComboboxChips>\n <ComboboxContent anchor={anchor}>{popupBody}</ComboboxContent>\n </>\n ) : (\n // Single-select: a button trigger styled to mirror <SelectTrigger>,\n // with the search input inside the popup.\n <>\n <ComboboxTrigger\n id={props.id}\n disabled={props.disabled}\n className={cn(\n \"flex h-8 w-full items-center justify-between gap-1.5 rounded-lg border border-input bg-transparent py-2 pr-2 pl-2.5 text-sm whitespace-nowrap transition-colors outline-none select-none focus-visible:border-ring focus-visible:ring-3 focus-visible:ring-ring/50 disabled:cursor-not-allowed disabled:opacity-50 dark:bg-input/30 dark:hover:bg-input/50\",\n // Muted means \"nothing chosen yet\", which is only true without\n // a clear row. WITH one, empty is a selected value — the popup\n // already puts the check mark on it (see `cbValue`), and the\n // native `Select` path renders the same state in full contrast\n // because it makes the clear label a genuine `selectedValue`.\n // Muting here made one `clearable` filter look unset and its\n // neighbour look set for the same meaning, purely because the\n // option count crossed the 20 that picks between the two paths.\n selected.length === 0 &&\n !props.clearable &&\n \"text-muted-foreground\",\n props.triggerClassName,\n )}\n >\n <span className=\"flex min-w-0 items-center gap-2\">\n {props.icon && (\n <props.icon className=\"text-muted-foreground size-4 shrink-0\" />\n )}\n <span className=\"truncate\">{triggerLabel}</span>\n </span>\n </ComboboxTrigger>\n <ComboboxContent>\n {props.searchable && (\n <ComboboxInput showTrigger={false} placeholder=\"Search…\" />\n )}\n {popupBody}\n </ComboboxContent>\n </>\n )}\n </ComboboxRoot>\n );\n}\n\nconst useAsyncLoader = (\n loader: ControlSelectProps[\"loader\"],\n threshold: number,\n debounceMs: number,\n defaultValue: unknown,\n) => {\n const [data, setData] = useState<SelectOption[]>([]);\n const [loading, setLoading] = useState(false);\n const [mode, setMode] = useState<LoaderMode>(\"static\");\n const cache = useRef(new Map<string, SelectOption[]>());\n\n useAction(\n {\n // `id`, not `name`: `id` is what useAction threads into its\n // react:action:* events. `name` was accepted and never read, so this\n // identifier reached nothing.\n id: \"select:loader:init\",\n runOnInit: true,\n handler: async () => {\n if (!loader) {\n setMode(\"static\");\n return;\n }\n setLoading(true);\n try {\n const result = await loader(\"\");\n const isShort = result.length <= threshold;\n setMode(isShort ? \"short\" : \"long\");\n cache.current.set(\"\", result);\n setData(result);\n\n if (!isShort && defaultValue != null && String(defaultValue) !== \"\") {\n const resolved = await loader(\"\", [String(defaultValue)]);\n if (resolved.length > 0) {\n setData((prev) => {\n const existing = new Set(prev.map(optValue));\n const fresh = resolved.filter(\n (r) => !existing.has(optValue(r)),\n );\n return [...prev, ...fresh];\n });\n }\n }\n } finally {\n setLoading(false);\n }\n },\n },\n [loader, threshold],\n );\n\n const search = useAction<[string]>(\n {\n debounce: debounceMs,\n handler: async (text) => {\n if (!loader || mode !== \"long\") return;\n if (cache.current.has(text)) {\n setData(cache.current.get(text)!);\n return;\n }\n setLoading(true);\n try {\n const result = await loader(text);\n cache.current.set(text, result);\n setData(result);\n } finally {\n setLoading(false);\n }\n },\n },\n [loader, mode, debounceMs],\n );\n\n return { data, loading, mode, search };\n};\n"],"mappings":";;;;;;;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M,UAAU,OAAO,UAAU;IACjC,QAAQ,UAAU,UAAU,MAAM;IAClC,MAAM,QAAQ,IAAI,IAAI,MAAM;IAC5B,QAAQ,MAAM;IAEd,IAAI,CAAC,WAAW,gBAAgB,QAAQ,OAAO,YAAY,MAAM,IAAI;KACnE,MAAM,WAAW,MAAM,OAAO,IAAI,CAAC,OAAO,YAAY,CAAC,CAAC;KACxD,IAAI,SAAS,SAAS,GACpB,SAAS,SAAS;MAChB,MAAM,WAAW,IAAI,IAAI,KAAK,IAAI,QAAQ,CAAC;MAC3C,MAAM,QAAQ,SAAS,QACpB,MAAM,CAAC,SAAS,IAAI,SAAS,CAAC,CAAC,CAClC;MACA,OAAO,CAAC,GAAG,MAAM,GAAG,KAAK;KAC3B,CAAC;IAEL;GACF,UAAU;IACR,WAAW,KAAK;GAClB;EACF;CACF,GACA,CAAC,QAAQ,SAAS,CACpB;CAwBA,OAAO;EAAE;EAAM;EAAS;EAAM,QAtBf,UACb;GACE,UAAU;GACV,SAAS,OAAO,SAAS;IACvB,IAAI,CAAC,UAAU,SAAS,QAAQ;IAChC,IAAI,MAAM,QAAQ,IAAI,IAAI,GAAG;KAC3B,QAAQ,MAAM,QAAQ,IAAI,IAAI,CAAE;KAChC;IACF;IACA,WAAW,IAAI;IACf,IAAI;KACF,MAAM,SAAS,MAAM,OAAO,IAAI;KAChC,MAAM,QAAQ,IAAI,MAAM,MAAM;KAC9B,QAAQ,MAAM;IAChB,UAAU;KACR,WAAW,KAAK;IAClB;GACF;EACF,GACA;GAAC;GAAQ;GAAM;EAAU,CAGQ;CAAE;AACvC"}
|
|
1
|
+
{"version":3,"file":"control-select.js","names":["ComboboxRoot"],"sources":["../../../src/components/control-select/control-select.tsx"],"sourcesContent":["import * as React from \"react\";\n\nvoid React;\n\nimport { FormField } from \"@alepha/ui/components/control-base/form-field\";\nimport type { IconComponent } from \"@alepha/ui/components/control-base/icon-hint\";\nimport {\n ComboboxChip,\n ComboboxChips,\n ComboboxChipsInput,\n ComboboxContent,\n ComboboxEmpty,\n ComboboxInput,\n ComboboxItem,\n ComboboxList,\n Combobox as ComboboxRoot,\n ComboboxTrigger,\n useComboboxAnchor,\n} from \"@alepha/ui/components/ui/combobox\";\nimport { Segmented } from \"@alepha/ui/components/ui/segmented\";\nimport { cn } from \"@alepha/ui/lib/utils\";\nimport type { Async } from \"alepha\";\nimport { useAction } from \"alepha/react\";\nimport {\n type BaseInputField,\n parseField,\n useFieldValue,\n useFormState,\n} from \"alepha/react/form\";\nimport { useI18n } from \"alepha/react/i18n\";\nimport { Loader2 } from \"lucide-react\";\nimport { type ReactNode, useMemo, useRef, useState } from \"react\";\n\nexport type SelectOption =\n | string\n | {\n value: string;\n label: string;\n /**\n * Optional secondary line shown under the label in the dropdown.\n */\n description?: string;\n /**\n * Optional small badge rendered next to the label.\n */\n tag?: string;\n /**\n * Optional icon/element rendered before the label, in both the\n * dropdown row and (for single-select) the trigger when selected.\n */\n icon?: ReactNode;\n /**\n * When true, the row is non-interactive — can't be selected if\n * not selected, can't be deselected if selected. Useful for\n * default/mandatory entries (e.g. the base \"user\" role).\n */\n disabled?: boolean;\n };\n\ntype LoaderMode = \"static\" | \"short\" | \"long\";\n\nexport interface ControlSelectProps {\n /**\n * Bound `InputField` from `useForm`. Single or multi value depending on schema.\n */\n input: BaseInputField;\n /**\n * Field label. Falls back to schema `title`.\n */\n label?: string;\n /**\n * Helper text shown below the input.\n */\n description?: string;\n /**\n * Render as a `<Segmented>` control (best for 2–4 options).\n */\n segmented?: boolean;\n /**\n * Force the search input on. Kept as the historical name for\n * `searchable: true` — every select is a combobox now, the flag only\n * decides whether it carries a search field.\n */\n combobox?: boolean;\n /**\n * Whether the dropdown carries a search input. Defaults to \"auto\": on for\n * multi-select, for a long-mode `loader`, and for static lists longer than\n * `SEARCH_THRESHOLD`. Set explicitly to search a short list or to drop the\n * search field from a long one.\n */\n searchable?: boolean;\n /**\n * Async option loader. Triggers long-mode (server-side search) above `loaderThreshold` options.\n */\n loader?: (search: string, resolve?: string[]) => Async<SelectOption[]>;\n /**\n * Option count above which `loader` is invoked on every search instead of once. Defaults to 100.\n */\n loaderThreshold?: number;\n /**\n * Debounce in ms applied to search queries when calling `loader` in long mode.\n */\n loaderDebounce?: number;\n /**\n * Disable the control.\n */\n disabled?: boolean;\n /**\n * Inline option list (overrides schema `enum`). Accepts either a static\n * array or an async function `(query) => SelectOption[]`. The async form\n * is mapped to a long-mode loader.\n */\n items?:\n | SelectOption[]\n | ((query: string) => SelectOption[] | Promise<SelectOption[]>);\n /**\n * Allow the user to add a new option by typing. When `true`, the typed\n * query becomes the value (and label) of a freshly created entry. When a\n * function, the function builds the option from the query.\n *\n * - For multi-select fields: each entry is appended to the value array.\n * - For single fields: behaves like a regular text input with a dropdown\n * suggesting existing options.\n */\n createNewEntry?: boolean | ((query: string) => Exclude<SelectOption, string>);\n /**\n * When true, the dropdown gets a synthetic \"none\" row at the top that\n * resets the field to `undefined`. Useful for optional filter chips\n * (e.g. an admin-table status filter) where the user needs an explicit\n * \"no filter\" option — Base UI's `Select` reserves empty-string values\n * as its internal no-selection sentinel, so a regular `<SelectItem\n * value=\"\">` can't be picked. With `clearable`, ControlSelect uses an\n * internal sentinel and translates it to `undefined` in `onChange`.\n *\n * Currently honored by the static-short `Select` and the searchable\n * Combobox render paths. Ignored by `segmented` (use a real segment\n * for \"all\" there).\n */\n clearable?: boolean;\n /**\n * Label rendered for the \"clear\" row injected by `clearable`. Also\n * used as the trigger placeholder when the field is empty. Defaults to\n * `\"None\"`. Localize at the call site (e.g. `\"All types\"`,\n * `\"All status\"`).\n */\n clearLabel?: string;\n /**\n * Extra className applied to the visible trigger (the `<SelectTrigger>`\n * or combobox `<Button>`). Useful for sizing filter chips\n * (`\"w-40\"`, `\"w-72\"`, etc.) without wrapping the whole `FormField` in\n * an extra div.\n */\n triggerClassName?: string;\n /**\n * Leading icon rendered on the left of the trigger, matching the\n * text-input controls. Resolved by the parent `Control` from its `icon`\n * prop — unlike text inputs there is no schema-hint fallback, so a select\n * only shows an icon when one is explicitly set.\n */\n icon?: IconComponent;\n}\n\n/**\n * Internal sentinel for the `clearable` row. Picked to be unlikely to\n * collide with a real option value; we translate it to `undefined` at\n * the boundary so callers never see it.\n */\nconst CLEAR_VALUE = \"__alepha_clear__\";\n\n/**\n * Static option count above which the dropdown grows a search input. Below it\n * the very same combobox renders without one — the threshold decides whether\n * you can type, never which control you get.\n */\nconst SEARCH_THRESHOLD = 20;\n\nconst optValue = (o: SelectOption) => (typeof o === \"string\" ? o : o.value);\nconst optLabel = (o: SelectOption) => (typeof o === \"string\" ? o : o.label);\nconst optDesc = (o: SelectOption) =>\n typeof o === \"string\" ? undefined : o.description;\nconst optTag = (o: SelectOption) => (typeof o === \"string\" ? undefined : o.tag);\nconst optDisabled = (o: SelectOption) =>\n typeof o === \"string\" ? false : Boolean(o.disabled);\nconst optIcon = (o: SelectOption): ReactNode =>\n typeof o === \"string\" ? undefined : o.icon;\n\n/**\n * Friendly label for plain string options: \"optional\" → \"Optional\",\n * \"in_progress\" → \"In Progress\". Custom `{ value, label }` items pass through\n * untouched.\n */\nconst titlecase = (s: string) =>\n s.replace(/[_-]+/g, \" \").replace(/\\b\\w/g, (c) => c.toUpperCase());\nconst segmentedLabel = (o: SelectOption) =>\n typeof o === \"string\" ? titlecase(o) : o.label;\n\nexport const ControlSelect = (props: ControlSelectProps) => {\n const { tr } = useI18n();\n const form = useFormState(props.input, [\"error\"]);\n const [value, setValue] = useFieldValue(props.input);\n\n const meta = parseField(props.input, {\n label: props.label,\n description: props.description,\n error: form.error,\n });\n\n const isArray = meta.isArray;\n const isNumeric = meta.type === \"number\" || meta.type === \"integer\";\n const isBoolean = meta.type === \"boolean\";\n\n // Normalize items prop: array → static; function → loader\n const itemsArray = Array.isArray(props.items)\n ? (props.items as SelectOption[])\n : undefined;\n const itemsLoader =\n typeof props.items === \"function\"\n ? (props.items as (q: string) => Async<SelectOption[]>)\n : undefined;\n\n const enumValues =\n itemsArray ?? (meta.enum as SelectOption[] | undefined) ?? [];\n\n const effectiveLoader = props.loader ?? itemsLoader;\n\n const {\n data: asyncData,\n loading,\n mode,\n search,\n } = useAsyncLoader(\n effectiveLoader,\n props.loaderThreshold ?? 100,\n props.loaderDebounce ?? 300,\n props.input.initialValue,\n );\n\n // Labels and `disabled` flags are part of the identity: keying on the\n // joined values alone collided (`[\"ab\",\"c\"]` vs `[\"a\",\"bc\"]`) and kept a\n // stale list when only the labels changed.\n const enumKey = JSON.stringify(enumValues);\n const min = meta.constraints.minimum;\n const max = meta.constraints.maximum;\n // Derived, not stored: this is a pure function of the schema. As state\n // filled in by an effect, the first paint of every boolean or ranged select\n // was an EMPTY list, corrected one render later.\n const staticData = useMemo<SelectOption[]>(() => {\n if (effectiveLoader) return [];\n if (isBoolean && enumValues.length === 0) {\n return [\n { value: \"true\", label: tr(\"controlSelect.yes\", { default: \"Yes\" }) },\n { value: \"false\", label: tr(\"controlSelect.no\", { default: \"No\" }) },\n ];\n }\n if (\n isNumeric &&\n enumValues.length === 0 &&\n typeof min === \"number\" &&\n typeof max === \"number\" &&\n max - min <= 20\n ) {\n const range: SelectOption[] = [];\n for (let i = min; i <= max; i++) range.push(String(i));\n return range;\n }\n return enumValues;\n }, [effectiveLoader, enumKey, isBoolean, isNumeric, min, max, tr]);\n\n const data = effectiveLoader ? asyncData : staticData;\n\n if (!props.input?.props) return null;\n\n const coerce = (raw: string): unknown => {\n if (isNumeric) return Number(raw);\n if (isBoolean) return raw === \"true\";\n return raw;\n };\n\n if (props.segmented) {\n return (\n <FormField\n id={meta.id}\n label={meta.label}\n description={meta.description}\n error={meta.error}\n required={meta.required}\n >\n <Segmented\n value={value != null ? String(value) : undefined}\n onChange={(v) => setValue(coerce(v))}\n disabled={props.disabled}\n options={data.slice(0, 10).map((o) => ({\n value: optValue(o),\n label: segmentedLabel(o),\n }))}\n fullWidth\n />\n </FormField>\n );\n }\n\n const clearLabel =\n props.clearLabel ?? tr(\"controlSelect.none\", { default: \"None\" });\n\n // One control for every list. The option count decides whether the popup\n // carries a search field — it no longer decides which primitive renders.\n // The native `Select` path this replaced silently dropped `description`,\n // `tag`, per-option `disabled` and `deselectable`, and styled its trigger\n // differently, purely because a list happened to be short.\n // Multi-select is never search-less: the chips input IS its trigger.\n const searchable =\n isArray ||\n (props.searchable ??\n (props.combobox || mode === \"long\" || data.length > SEARCH_THRESHOLD));\n\n return (\n <FormField\n id={meta.id}\n label={meta.label}\n description={meta.description}\n error={meta.error}\n required={meta.required}\n >\n <Combobox\n id={meta.id}\n data={data}\n loading={loading}\n multi={isArray}\n searchable={searchable}\n disabled={props.disabled}\n value={value}\n onChange={(v) => setValue(v)}\n coerce={coerce}\n onSearch={mode === \"long\" ? search.run : undefined}\n createNewEntry={props.createNewEntry}\n icon={props.icon}\n // Used to be dropped on this path, so a filter chip sized `w-40` lost\n // its width as soon as its list crossed the threshold.\n triggerClassName={props.triggerClassName}\n // `clearable` used to reach this path as a placeholder and nothing\n // else, so a filter chip that had switched to the combobox (>20\n // options) could be set but never put back to \"All …\".\n clearable={props.clearable}\n clearLabel={clearLabel}\n // An optional field must also be able to go back to empty without a\n // dedicated row: Base UI never emits `null`, so re-pressing the\n // selected row deselects (see `handleSingle`). A required field keeps\n // its value — clearing it would only produce a validation error the\n // user cannot see yet.\n deselectable={props.clearable || !meta.required}\n placeholder={props.clearable ? clearLabel : undefined}\n />\n </FormField>\n );\n};\n\ninterface ComboboxProps {\n id?: string;\n data: SelectOption[];\n loading: boolean;\n multi: boolean;\n /**\n * Render the search input. When false the popup is the list alone — the\n * shape a short static list gets. Multi-select ignores it: its input is the\n * chips box itself, and it is the only way to open and type.\n */\n searchable: boolean;\n disabled?: boolean;\n value: unknown;\n onChange: (v: unknown) => void;\n coerce: (v: string) => unknown;\n onSearch?: (q: string) => void;\n createNewEntry?: ControlSelectProps[\"createNewEntry\"];\n icon?: IconComponent;\n triggerClassName?: string;\n /**\n * Trigger text when nothing is selected. Mirrors the native-Select path,\n * where a `clearable` field shows its `clearLabel` (e.g. \"All zones\") as the\n * empty placeholder. Defaults to \"Select…\".\n */\n placeholder?: string;\n /**\n * Prepend a row that resets the field to `undefined` — the combobox\n * equivalent of the native `Select`'s clear row.\n */\n clearable?: boolean;\n /**\n * Label of the `clearable` row (e.g. \"All zones\").\n */\n clearLabel?: string;\n /**\n * Allow the single-select value to be unset by pressing the row that is\n * already selected. Set for optional (and `clearable`) fields only.\n */\n deselectable?: boolean;\n}\n\n/**\n * Normalized option used as the Base UI `Combobox.Item` value. Because the\n * shape is `{ value, label }`, Base UI uses `label` for display/search and\n * `value` for selection automatically — which is what makes the popup search\n * match the visible label rather than the raw id.\n */\ninterface ComboOption {\n value: string;\n label: string;\n description?: string;\n tag?: string;\n icon?: ReactNode;\n disabled?: boolean;\n /**\n * Marks the synthetic \"create new\" row injected by `createNewEntry`.\n */\n create?: boolean;\n /**\n * Marks the synthetic \"clear\" row injected by `clearable`.\n */\n clear?: boolean;\n /**\n * The raw query that produced a `create` row (used as the new entry's label).\n */\n query?: string;\n}\n\n/**\n * Searchable single/multi select built on the Base UI `Combobox` primitive.\n *\n * Composed in the \"select-like\" shape: a button trigger that shows the current\n * value, with the search `<input>` living inside the popup. We disable Base\n * UI's internal filtering (`filter={null}`) and filter in JS so the same code\n * path serves static lists, server-driven (`onSearch`) lists, and the\n * `createNewEntry` affordance.\n */\nfunction Combobox(props: ComboboxProps) {\n const { tr } = useI18n();\n const [query, setQuery] = useState(\"\");\n // Remembers labels for values the user has picked, so the trigger/chips keep\n // a human label even after the source option drops out of a server-filtered\n // `data` set — or for freshly created entries that never existed in `data`.\n const labelCache = useRef(new Map<string, string>());\n // Positioning anchor for the multi-select chips box (the popup is anchored to\n // the chips container rather than the inline input).\n const anchor = useComboboxAnchor();\n\n const options: ComboOption[] = props.data.map((o) => ({\n value: optValue(o),\n label: optLabel(o),\n description: optDesc(o),\n tag: optTag(o),\n icon: optIcon(o),\n disabled: optDisabled(o),\n }));\n\n const selected: string[] = props.multi\n ? Array.isArray(props.value)\n ? (props.value as unknown[]).map(String)\n : []\n : props.value != null\n ? // Coercion at a boundary: the value is a form/route/chart primitive whose\n // declared type is wider than what can reach here.\n // oxlint-disable-next-line typescript/no-base-to-string\n [String(props.value)]\n : [];\n\n const labelFor = (val: string) =>\n options.find((o) => o.value === val)?.label ??\n labelCache.current.get(val) ??\n val;\n\n const disabledFor = (val: string) =>\n options.find((o) => o.value === val)?.disabled ?? false;\n\n // Server mode (`onSearch`) filters upstream; for static lists we filter on\n // the visible label — never the value/id (that was the cmdk bug).\n const serverMode = Boolean(props.onSearch);\n const q = query.trim().toLowerCase();\n const filtered =\n serverMode || !q\n ? options\n : options.filter((o) => o.label.toLowerCase().includes(q));\n\n const showCreate =\n Boolean(props.createNewEntry) &&\n q.length > 0 &&\n !options.some((o) => o.value === query || o.label.toLowerCase() === q) &&\n !selected.includes(query);\n\n const createOption: ComboOption | undefined = showCreate\n ? (() => {\n const built =\n typeof props.createNewEntry === \"function\"\n ? props.createNewEntry(query)\n : { value: query, label: query };\n return {\n value: built.value,\n label: built.label,\n create: true,\n query,\n };\n })()\n : undefined;\n\n // The synthetic \"no selection\" row — \"All zones\", \"All tags\", \"None\". Only\n // meaningful for a single select: the multi path clears by removing chips.\n const clearRow: ComboOption | undefined =\n props.clearable && !props.multi\n ? {\n value: CLEAR_VALUE,\n label:\n props.clearLabel ?? tr(\"controlSelect.none\", { default: \"None\" }),\n clear: true,\n }\n : undefined;\n // Filtered on its own label like any other row, so searching \"zone\" doesn't\n // leave \"All zones\" stranded at the top of a list it doesn't match.\n const showClear = clearRow && clearRow.label.toLowerCase().includes(q);\n\n const items: ComboOption[] = [\n ...(showClear && clearRow ? [clearRow] : []),\n ...filtered,\n ...(createOption ? [createOption] : []),\n ];\n\n // Reconstruct option objects for the controlled value. Base UI matches them\n // back to list items via `isItemEqualToValue` (by `value`), so identity\n // across renders doesn't matter.\n const toValueObject = (val: string): ComboOption =>\n options.find((o) => o.value === val) ?? {\n value: val,\n label: labelFor(val),\n };\n\n const cbValue = props.multi\n ? selected.map(toValueObject)\n : selected[0]\n ? toValueObject(selected[0])\n : // Empty + clearable reads as \"the clear row is what's selected\", so it\n // carries the check mark — same as the native `Select` path.\n (clearRow ?? null);\n\n const remember = (o: ComboOption) => {\n if (o.create) labelCache.current.set(o.value, o.query ?? o.value);\n else labelCache.current.set(o.value, o.label);\n };\n\n const handleSingle = (o: ComboOption | null) => {\n if (!o || o.clear) {\n props.onChange(undefined);\n setQuery(\"\");\n return;\n }\n // Base UI's single-select `Combobox` re-selects on every item press — its\n // `handleSelection` calls `setSelectedValue(itemValue)` unconditionally and\n // never emits `null` — so pressing the checked row was a no-op and an\n // optional field had no way back to empty. Toggle it off here, the way the\n // multi path already does via its chips.\n if (props.deselectable && !o.create && selected[0] === o.value) {\n props.onChange(undefined);\n setQuery(\"\");\n return;\n }\n remember(o);\n props.onChange(props.coerce(o.value));\n setQuery(\"\");\n };\n\n const handleMulti = (list: ComboOption[]) => {\n for (const o of list) remember(o);\n props.onChange(list.map((o) => props.coerce(o.value)));\n setQuery(\"\");\n };\n\n const emptyLabel =\n props.placeholder ?? tr(\"controlSelect.select\", { default: \"Select…\" });\n const triggerLabel = selected[0] ? labelFor(selected[0]) : emptyLabel;\n\n // The list (loading / empty / items) is identical for single and multi — only\n // the trigger differs (button vs. chips box), so render it once.\n const popupBody = props.loading ? (\n <div className=\"text-muted-foreground flex items-center justify-center gap-2 p-4 text-sm\">\n <Loader2 className=\"size-4 animate-spin\" />{\" \"}\n {tr(\"controlSelect.loading\", { default: \"Loading…\" })}\n </div>\n ) : (\n <>\n <ComboboxEmpty>\n {props.createNewEntry\n ? \"\"\n : tr(\"controlSelect.noResults\", { default: \"No results.\" })}\n </ComboboxEmpty>\n <ComboboxList>\n {(opt: ComboOption) =>\n opt.create ? (\n <ComboboxItem key={`__create__${opt.value}`} value={opt}>\n <span className=\"mr-2\">+</span>\n {tr(\"controlSelect.create\", {\n default: `Create \"${opt.query}\"`,\n args: [String(opt.query ?? \"\")],\n })}\n </ComboboxItem>\n ) : (\n <ComboboxItem key={opt.value} value={opt} disabled={opt.disabled}>\n {opt.icon && (\n <span className=\"mr-2 flex shrink-0 items-center\">\n {opt.icon}\n </span>\n )}\n <div className=\"flex min-w-0 flex-1 flex-col\">\n <div className=\"flex items-center gap-1.5\">\n {opt.tag && (\n <span className=\"bg-muted text-muted-foreground rounded px-1 text-[10px] tracking-wide uppercase\">\n {opt.tag}\n </span>\n )}\n <span className=\"truncate\">{opt.label}</span>\n </div>\n {opt.description && (\n <span className=\"text-muted-foreground truncate text-xs\">\n {opt.description}\n </span>\n )}\n </div>\n </ComboboxItem>\n )\n }\n </ComboboxList>\n </>\n );\n\n return (\n <ComboboxRoot\n items={items as never}\n multiple={props.multi}\n disabled={props.disabled}\n value={cbValue as never}\n onValueChange={\n (props.multi\n ? (v: ComboOption[]) => handleMulti(v)\n : (v: ComboOption | null) => handleSingle(v)) as never\n }\n isItemEqualToValue={\n ((a: ComboOption, b: ComboOption) => a.value === b.value) as never\n }\n filter={null}\n // Base UI leaves `autoHighlight` off by default, so nothing is\n // highlighted while typing and Enter has no target — the user has to\n // click a row (including the `createNewEntry` one). Highlighting the\n // first match makes Enter pick it, which is what a search field is\n // expected to do. It only engages while the query is non-empty, so\n // opening the popup still starts with no preselection.\n autoHighlight\n onInputValueChange={(v) => {\n setQuery(v);\n props.onSearch?.(v);\n }}\n >\n {props.multi ? (\n // Multi-select: removable chips for each value with an inline search\n // input, all inside the bordered chips box (Base UI's native shape).\n <>\n <ComboboxChips\n ref={anchor}\n id={props.id}\n className={cn(\n \"w-full\",\n props.disabled && \"pointer-events-none opacity-50\",\n props.triggerClassName,\n )}\n >\n {props.icon && (\n <props.icon className=\"text-muted-foreground ml-1 size-4 shrink-0\" />\n )}\n {selected.map((val) => (\n <ComboboxChip key={val} showRemove={!disabledFor(val)}>\n {labelFor(val)}\n </ComboboxChip>\n ))}\n <ComboboxChipsInput\n placeholder={\n selected.length === 0\n ? (props.placeholder ?? \"Search…\")\n : \"Search…\"\n }\n />\n </ComboboxChips>\n <ComboboxContent anchor={anchor}>{popupBody}</ComboboxContent>\n </>\n ) : (\n // Single-select: a button trigger styled to mirror <SelectTrigger>,\n // with the search input inside the popup.\n <>\n <ComboboxTrigger\n id={props.id}\n disabled={props.disabled}\n className={cn(\n \"border-input focus-visible:border-ring focus-visible:ring-ring/50 dark:bg-input/30 dark:hover:bg-input/50 flex h-8 w-full items-center justify-between gap-1.5 rounded-lg border bg-transparent py-2 pr-2 pl-2.5 text-sm whitespace-nowrap transition-colors outline-none select-none focus-visible:ring-3 disabled:cursor-not-allowed disabled:opacity-50\",\n // Muted means \"nothing chosen yet\", which is only true without\n // a clear row. WITH one, empty is a selected value — the popup\n // already puts the check mark on it (see `cbValue`), and the\n // native `Select` path renders the same state in full contrast\n // because it makes the clear label a genuine `selectedValue`.\n // Muting here made one `clearable` filter look unset and its\n // neighbour look set for the same meaning, purely because the\n // option count crossed the 20 that picks between the two paths.\n selected.length === 0 &&\n !props.clearable &&\n \"text-muted-foreground\",\n props.triggerClassName,\n )}\n >\n <span className=\"flex min-w-0 items-center gap-2\">\n {props.icon && (\n <props.icon className=\"text-muted-foreground size-4 shrink-0\" />\n )}\n <span className=\"truncate\">{triggerLabel}</span>\n </span>\n </ComboboxTrigger>\n <ComboboxContent>\n {props.searchable && (\n <ComboboxInput showTrigger={false} placeholder=\"Search…\" />\n )}\n {popupBody}\n </ComboboxContent>\n </>\n )}\n </ComboboxRoot>\n );\n}\n\nconst useAsyncLoader = (\n loader: ControlSelectProps[\"loader\"],\n threshold: number,\n debounceMs: number,\n defaultValue: unknown,\n) => {\n const [data, setData] = useState<SelectOption[]>([]);\n const [loading, setLoading] = useState(false);\n const [mode, setMode] = useState<LoaderMode>(\"static\");\n const cache = useRef(new Map<string, SelectOption[]>());\n\n useAction(\n {\n // `id`, not `name`: `id` is what useAction threads into its\n // react:action:* events. `name` was accepted and never read, so this\n // identifier reached nothing.\n id: \"select:loader:init\",\n runOnInit: true,\n handler: async () => {\n if (!loader) {\n setMode(\"static\");\n return;\n }\n setLoading(true);\n try {\n const result = await loader(\"\");\n const isShort = result.length <= threshold;\n setMode(isShort ? \"short\" : \"long\");\n cache.current.set(\"\", result);\n setData(result);\n\n // Coercion at a boundary: the value is a form/route/chart primitive whose\n // declared type is wider than what can reach here.\n // oxlint-disable-next-line typescript/no-base-to-string\n if (!isShort && defaultValue != null && String(defaultValue) !== \"\") {\n // Coercion at a boundary: the value is a form/route/chart primitive whose\n // declared type is wider than what can reach here.\n // oxlint-disable-next-line typescript/no-base-to-string\n const resolved = await loader(\"\", [String(defaultValue)]);\n if (resolved.length > 0) {\n setData((prev) => {\n const existing = new Set(prev.map(optValue));\n const fresh = resolved.filter(\n (r) => !existing.has(optValue(r)),\n );\n return [...prev, ...fresh];\n });\n }\n }\n } finally {\n setLoading(false);\n }\n },\n },\n [loader, threshold],\n );\n\n const search = useAction<[string]>(\n {\n debounce: debounceMs,\n handler: async (text) => {\n if (!loader || mode !== \"long\") return;\n if (cache.current.has(text)) {\n setData(cache.current.get(text)!);\n return;\n }\n setLoading(true);\n try {\n const result = await loader(text);\n cache.current.set(text, result);\n setData(result);\n } finally {\n setLoading(false);\n }\n },\n },\n [loader, mode, debounceMs],\n );\n\n return { data, loading, mode, search };\n};\n"],"mappings":";;;;;;;;;;;;;;;;AAuKA,MAAM,cAAc;;;;;;AAOpB,MAAM,mBAAmB;AAEzB,MAAM,YAAY,MAAqB,OAAO,MAAM,WAAW,IAAI,EAAE;AACrE,MAAM,YAAY,MAAqB,OAAO,MAAM,WAAW,IAAI,EAAE;AACrE,MAAM,WAAW,MACf,OAAO,MAAM,WAAW,KAAA,IAAY,EAAE;AACxC,MAAM,UAAU,MAAqB,OAAO,MAAM,WAAW,KAAA,IAAY,EAAE;AAC3E,MAAM,eAAe,MACnB,OAAO,MAAM,WAAW,QAAQ,QAAQ,EAAE,QAAQ;AACpD,MAAM,WAAW,MACf,OAAO,MAAM,WAA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C;IAEL;GACF,UAAU;IACR,WAAW,KAAK;GAClB;EACF;CACF,GACA,CAAC,QAAQ,SAAS,CACpB;CAwBA,OAAO;EAAE;EAAM;EAAS;EAAM,QAtBf,UACb;GACE,UAAU;GACV,SAAS,OAAO,SAAS;IACvB,IAAI,CAAC,UAAU,SAAS,QAAQ;IAChC,IAAI,MAAM,QAAQ,IAAI,IAAI,GAAG;KAC3B,QAAQ,MAAM,QAAQ,IAAI,IAAI,CAAE;KAChC;IACF;IACA,WAAW,IAAI;IACf,IAAI;KACF,MAAM,SAAS,MAAM,OAAO,IAAI;KAChC,MAAM,QAAQ,IAAI,MAAM,MAAM;KAC9B,QAAQ,MAAM;IAChB,UAAU;KACR,WAAW,KAAK;IAClB;GACF;EACF,GACA;GAAC;GAAQ;GAAM;EAAU,CAGQ;CAAE;AACvC"}
|
|
@@ -63,5 +63,5 @@ export interface ControlUploadProps {
|
|
|
63
63
|
* Single-file: form value is a uuid string.
|
|
64
64
|
* Multi-file: form value is an array of uuid strings.
|
|
65
65
|
*/
|
|
66
|
-
export declare
|
|
66
|
+
export declare const ControlUpload: (props: ControlUploadProps) => React.JSX.Element | null;
|
|
67
67
|
//# sourceMappingURL=control-upload.d.ts.map
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"control-upload.d.ts","sourceRoot":"","sources":["../../../src/components/control-upload/control-upload.tsx"],"names":[],"mappings":"AAAA,OAAO,KAAK,KAAK,MAAM,OAAO,CAAC;AAqB/B,OAAO,EACL,KAAK,cAAc,EAIpB,MAAM,mBAAmB,CAAC;
|
|
1
|
+
{"version":3,"file":"control-upload.d.ts","sourceRoot":"","sources":["../../../src/components/control-upload/control-upload.tsx"],"names":[],"mappings":"AAAA,OAAO,KAAK,KAAK,MAAM,OAAO,CAAC;AAqB/B,OAAO,EACL,KAAK,cAAc,EAIpB,MAAM,mBAAmB,CAAC;AAY3B,OAAO,EACL,KAAK,kBAAkB,EAExB,MAAM,2BAA2B,CAAC;AAEnC,MAAM,WAAW,kBAAkB;IACjC;;OAEG;IACH,KAAK,EAAE,cAAc,CAAC;IACtB;;OAEG;IACH,KAAK,CAAC,EAAE,MAAM,CAAC;IACf;;OAEG;IACH,WAAW,CAAC,EAAE,MAAM,CAAC;IACrB;;;OAGG;IACH,KAAK,CAAC,EAAE,OAAO,CAAC;IAChB;;;OAGG;IACH,MAAM,CAAC,EAAE,MAAM,CAAC;IAChB;;OAEG;IACH,OAAO,CAAC,EAAE,MAAM,CAAC;IACjB;;;;;;;;;;;;;;;;OAgBG;IACH,KAAK,CAAC,EAAE,kBAAkB,CAAC;IAC3B;;OAEG;IACH,MAAM,CAAC,EAAE,MAAM,CAAC;IAChB;;OAEG;IACH,QAAQ,CAAC,EAAE,OAAO,CAAC;CACpB;AAaD;;;;;;;GAOG;AACH,eAAO,MAAM,aAAa,UAAW,kBAAkB,6BAwWtD,CAAC"}
|
|
@@ -1,15 +1,15 @@
|
|
|
1
1
|
import { resizeImage } from "../../lib/resize-image.js";
|
|
2
|
-
import { useToast } from "../use-toast/use-toast.js";
|
|
3
2
|
import { Button } from "../ui/button.js";
|
|
4
|
-
import {
|
|
3
|
+
import { useToast } from "../use-toast/use-toast.js";
|
|
5
4
|
import { FormField } from "../control-base/form-field.js";
|
|
5
|
+
import { Dialog, DialogContent, DialogDescription, DialogHeader, DialogTitle } from "../ui/dialog.js";
|
|
6
6
|
import { Tooltip, TooltipContent, TooltipTrigger } from "../ui/tooltip.js";
|
|
7
7
|
import { useEffect, useId, useRef, useState } from "react";
|
|
8
|
-
import { useClient } from "alepha/react";
|
|
9
8
|
import { Fragment as Fragment$1, jsx, jsxs } from "react/jsx-runtime";
|
|
10
9
|
import { File, Loader2, Upload, X } from "lucide-react";
|
|
11
|
-
import { parseField, useFieldValue, useFormState } from "alepha/react/form";
|
|
12
10
|
import { useI18n } from "alepha/react/i18n";
|
|
11
|
+
import { useClient } from "alepha/react";
|
|
12
|
+
import { parseField, useFieldValue, useFormState } from "alepha/react/form";
|
|
13
13
|
//#region src/components/control-upload/control-upload.tsx
|
|
14
14
|
/**
|
|
15
15
|
* File upload control. Wraps `FileController.uploadFile`, stores the
|
|
@@ -19,7 +19,7 @@ import { useI18n } from "alepha/react/i18n";
|
|
|
19
19
|
* Single-file: form value is a uuid string.
|
|
20
20
|
* Multi-file: form value is an array of uuid strings.
|
|
21
21
|
*/
|
|
22
|
-
|
|
22
|
+
const ControlUpload = (props) => {
|
|
23
23
|
const form = useFormState(props.input, ["error"]);
|
|
24
24
|
const [value, setValue] = useFieldValue(props.input);
|
|
25
25
|
const client = useClient();
|
|
@@ -140,7 +140,7 @@ function ControlUpload(props) {
|
|
|
140
140
|
const isImage = item?.mimeType?.startsWith("image/") || acceptsImage && !!item?.previewUrl && !item?.mimeType;
|
|
141
141
|
const canClear = !props.disabled && !fieldMeta.required;
|
|
142
142
|
return /* @__PURE__ */ jsxs("div", {
|
|
143
|
-
className: `relative flex h-9 cursor-zoom-in items-center rounded-md border
|
|
143
|
+
className: `border-input dark:bg-input/30 relative flex h-9 cursor-zoom-in items-center rounded-md border bg-transparent pl-1 ${canClear ? "pr-9" : "pr-2"}`,
|
|
144
144
|
onClick: () => setPreviewId(id),
|
|
145
145
|
onKeyDown: (e) => {
|
|
146
146
|
if (e.key === "Enter" || e.key === " ") {
|
|
@@ -190,7 +190,7 @@ function ControlUpload(props) {
|
|
|
190
190
|
onDrop: handleDrop,
|
|
191
191
|
className: dragOver ? "border-primary bg-primary/5" : ""
|
|
192
192
|
}),
|
|
193
|
-
children: uploading ? /* @__PURE__ */ jsxs(Fragment$1, { children: [/* @__PURE__ */ jsx(Loader2, { className: "size-4
|
|
193
|
+
children: uploading ? /* @__PURE__ */ jsxs(Fragment$1, { children: [/* @__PURE__ */ jsx(Loader2, { className: "mr-1 size-4 animate-spin" }), tr("controlUpload.uploading", { default: "Uploading…" })] }) : /* @__PURE__ */ jsxs(Fragment$1, { children: [/* @__PURE__ */ jsx(Upload, { className: "mr-1 size-4" }), props.multi ? tr("controlUpload.chooseFiles", { default: "Choose files" }) : tr("controlUpload.chooseFile", { default: "Choose a file" })] })
|
|
194
194
|
}), /* @__PURE__ */ jsx(TooltipContent, { children: dragDropHint })] });
|
|
195
195
|
return /* @__PURE__ */ jsxs(FormField, {
|
|
196
196
|
id: inputId,
|
|
@@ -249,7 +249,7 @@ function ControlUpload(props) {
|
|
|
249
249
|
})
|
|
250
250
|
}),
|
|
251
251
|
(previewHasName || previewItem?.mimeType) && /* @__PURE__ */ jsxs("div", {
|
|
252
|
-
className: "flex flex-col gap-0 border-t
|
|
252
|
+
className: "bg-muted/30 flex flex-col gap-0 border-t px-4 py-2",
|
|
253
253
|
children: [previewHasName && /* @__PURE__ */ jsx("span", {
|
|
254
254
|
className: "truncate text-sm font-medium",
|
|
255
255
|
children: previewItem?.name
|
|
@@ -263,8 +263,8 @@ function ControlUpload(props) {
|
|
|
263
263
|
})
|
|
264
264
|
]
|
|
265
265
|
});
|
|
266
|
-
}
|
|
267
|
-
|
|
266
|
+
};
|
|
267
|
+
const ItemThumb = (props) => {
|
|
268
268
|
const [broken, setBroken] = useState(false);
|
|
269
269
|
if (broken) return /* @__PURE__ */ jsx("div", {
|
|
270
270
|
className: "bg-muted text-muted-foreground flex size-7 shrink-0 items-center justify-center rounded",
|
|
@@ -276,7 +276,7 @@ function ItemThumb(props) {
|
|
|
276
276
|
className: "size-7 shrink-0 rounded object-cover",
|
|
277
277
|
onError: () => setBroken(true)
|
|
278
278
|
});
|
|
279
|
-
}
|
|
279
|
+
};
|
|
280
280
|
const formatBytes = (n) => {
|
|
281
281
|
if (!n) return "0 B";
|
|
282
282
|
const units = [
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"control-upload.js","names":["FileIcon"],"sources":["../../../src/components/control-upload/control-upload.tsx"],"sourcesContent":["import * as React from \"react\";\n\nvoid React;\n\nimport { FormField } from \"@alepha/ui/components/control-base/form-field\";\nimport { Button } from \"@alepha/ui/components/ui/button\";\nimport {\n Dialog,\n DialogContent,\n DialogDescription,\n DialogHeader,\n DialogTitle,\n} from \"@alepha/ui/components/ui/dialog\";\nimport {\n Tooltip,\n TooltipContent,\n TooltipTrigger,\n} from \"@alepha/ui/components/ui/tooltip\";\nimport { useToast } from \"@alepha/ui/components/use-toast/use-toast\";\nimport type { FileController } from \"alepha/api/files\";\nimport { useClient } from \"alepha/react\";\nimport {\n type BaseInputField,\n parseField,\n useFieldValue,\n useFormState,\n} from \"alepha/react/form\";\nimport { useI18n } from \"alepha/react/i18n\";\nimport { File as FileIcon, Loader2, Upload, X } from \"lucide-react\";\nimport {\n type ChangeEvent,\n type DragEvent,\n useEffect,\n useId,\n useRef,\n useState,\n} from \"react\";\nimport {\n type ResizeImageOptions,\n resizeImage,\n} from \"../../lib/resize-image.ts\";\n\nexport interface ControlUploadProps {\n /**\n * Bound `InputField` from `useForm`. Stores the uploaded file ID(s).\n */\n input: BaseInputField;\n /**\n * Field label. Falls back to schema `title`.\n */\n label?: string;\n /**\n * Helper text shown below the dropzone.\n */\n description?: string;\n /**\n * Multi-file mode. The form value becomes an `Array<string>` of file\n * IDs. Single mode (default) stores a bare UUID string.\n */\n multi?: boolean;\n /**\n * HTML `accept` filter on the file picker (e.g. `\"image/*\"`,\n * `\".pdf,.docx\"`).\n */\n accept?: string;\n /**\n * Max size per file (bytes). Files over the limit are rejected.\n */\n maxSize?: number;\n /**\n * Downscale images to these bounds before uploading.\n *\n * Set it wherever the result is rendered small — the bytes never leave the\n * machine, so it speeds up the upload as well as every later fetch. Applied\n * before {@link maxSize}, so a photo that would have been rejected for being\n * too large is resized and accepted instead.\n *\n * Best-effort by design: a browser without `OffscreenCanvas`, an SVG, or an\n * image the decoder chokes on is uploaded as-is, and the storage's own\n * `maxSize` remains what actually bounds it. That trade is deliberate — a\n * server-side codec able to close the gap costs more bundle than the case is\n * worth on an edge runtime, and encodes worse (see `files:beforeUpload` in\n * `alepha/api/files` for where it would attach if you want it anyway).\n *\n * @example { maxWidth: 256 }\n */\n image?: ResizeImageOptions;\n /**\n * Bucket name passed to the upload endpoint.\n */\n bucket?: string;\n /**\n * Disable the dropzone.\n */\n disabled?: boolean;\n}\n\ninterface UploadedFileMeta {\n id: string;\n name: string;\n mimeType?: string;\n size?: number;\n /**\n * Object URL for image preview, when applicable.\n */\n previewUrl?: string;\n}\n\n/**\n * File upload control. Wraps `FileController.uploadFile`, stores the\n * resulting file ID(s) in the form, and renders a thumbnail preview for\n * images and a chip-style summary for everything else.\n *\n * Single-file: form value is a uuid string.\n * Multi-file: form value is an array of uuid strings.\n */\nexport function ControlUpload(props: ControlUploadProps) {\n const form = useFormState(props.input, [\"error\"]);\n const [value, setValue] = useFieldValue(props.input);\n const client = useClient<FileController>();\n const { tr } = useI18n();\n const toast = useToast();\n const inputId = useId();\n const fileInputRef = useRef<HTMLInputElement>(null);\n const [uploading, setUploading] = useState(false);\n const [progress, setProgress] = useState(0);\n const [meta, setMeta] = useState<Map<string, UploadedFileMeta>>(new Map());\n const [dragOver, setDragOver] = useState(false);\n const [previewId, setPreviewId] = useState<string | null>(null);\n\n /**\n * Backfill `meta` for ids that arrived from form state (e.g. after a page\n * reload) so the renderer can show a thumbnail / chip instead of the raw\n * uuid. We can't infer the real mime type without an extra request, so we\n * fall back to a stub entry pointing at `/api/files/:id` and let the\n * `<img>` `onError` swap to the generic file chip.\n */\n useEffect(() => {\n const ids: string[] = props.multi\n ? Array.isArray(value)\n ? (value as string[])\n : []\n : value\n ? [value as string]\n : [];\n setMeta((current) => {\n let changed = false;\n const next = new Map(current);\n for (const id of ids) {\n if (!next.has(id)) {\n next.set(id, {\n id,\n name: id,\n previewUrl: `/api/files/${id}`,\n });\n changed = true;\n }\n }\n return changed ? next : current;\n });\n }, [Array.isArray(value) ? value.join(\",\") : value, props.multi]);\n\n if (!props.input?.props) return null;\n\n const fieldMeta = parseField(props.input, {\n label: props.label,\n description: props.description,\n error: form.error,\n });\n\n const ids: string[] = props.multi\n ? Array.isArray(value)\n ? (value as string[])\n : []\n : value\n ? [value as string]\n : [];\n\n const handleFiles = async (files: FileList) => {\n if (!files.length) return;\n if (!props.multi && files.length > 1) {\n toast.error(\n tr(\"controlUpload.singleOnly\", { default: \"Only one file allowed\" }),\n );\n return;\n }\n\n setUploading(true);\n setProgress(0);\n const next = new Map(meta);\n const newIds: string[] = [];\n\n try {\n for (let i = 0; i < files.length; i++) {\n // Ahead of the size check on purpose: a 4 MB photo destined for a 32px\n // avatar should become a few kilobytes, not an error.\n const file = props.image\n ? await resizeImage(files[i], props.image)\n : files[i];\n\n if (props.maxSize && file.size > props.maxSize) {\n toast.error(\n tr(\"controlUpload.tooBig\", {\n default: `${file.name} exceeds ${formatBytes(props.maxSize)}`,\n args: [file.name, formatBytes(props.maxSize)],\n }),\n );\n continue;\n }\n\n const resource = await client.uploadFile({\n body: { file },\n query: props.bucket ? { bucket: props.bucket } : ({} as never),\n });\n\n const previewUrl = file.type.startsWith(\"image/\")\n ? URL.createObjectURL(file)\n : undefined;\n\n next.set(resource.id, {\n id: resource.id,\n name: resource.name ?? file.name,\n mimeType: resource.mimeType ?? file.type,\n size: resource.size ?? file.size,\n previewUrl,\n });\n newIds.push(resource.id);\n setProgress(Math.round(((i + 1) / files.length) * 100));\n }\n\n setMeta(next);\n if (props.multi) {\n setValue([...ids, ...newIds]);\n } else if (newIds[0]) {\n setValue(newIds[0]);\n }\n if (newIds.length) {\n toast.success(\n newIds.length === 1\n ? tr(\"controlUpload.uploadedOne\", { default: \"File uploaded\" })\n : tr(\"controlUpload.uploadedMany\", {\n default: `${newIds.length} files uploaded`,\n args: [String(newIds.length)],\n }),\n );\n }\n } catch (e) {\n const msg = (e as Error).message;\n toast.error(\n tr(\"controlUpload.failed\", {\n default: `Upload failed: ${msg}`,\n args: [msg],\n }),\n );\n } finally {\n setUploading(false);\n setProgress(0);\n if (fileInputRef.current) fileInputRef.current.value = \"\";\n }\n };\n\n const handleInputChange = (e: ChangeEvent<HTMLInputElement>) => {\n if (e.target.files) handleFiles(e.target.files);\n };\n\n const handleDrop = (e: DragEvent) => {\n e.preventDefault();\n setDragOver(false);\n if (props.disabled) return;\n if (e.dataTransfer.files) handleFiles(e.dataTransfer.files);\n };\n\n const removeOne = (id: string) => {\n const next = new Map(meta);\n const item = next.get(id);\n if (item?.previewUrl) URL.revokeObjectURL(item.previewUrl);\n next.delete(id);\n setMeta(next);\n\n if (props.multi) {\n setValue(ids.filter((it) => it !== id));\n } else {\n setValue(undefined);\n }\n };\n\n const renderItem = (id: string) => {\n const item = meta.get(id);\n const acceptsImage = (props.accept ?? \"\").includes(\"image\");\n const mimeIsImage = item?.mimeType?.startsWith(\"image/\");\n const isImage =\n mimeIsImage || (acceptsImage && !!item?.previewUrl && !item?.mimeType);\n\n const canClear = !props.disabled && !fieldMeta.required;\n\n return (\n <div\n key={id}\n className={`relative flex h-9 cursor-zoom-in items-center rounded-md border border-input bg-transparent pl-1 dark:bg-input/30 ${canClear ? \"pr-9\" : \"pr-2\"}`}\n onClick={() => setPreviewId(id)}\n onKeyDown={(e) => {\n if (e.key === \"Enter\" || e.key === \" \") {\n e.preventDefault();\n setPreviewId(id);\n }\n }}\n role=\"button\"\n tabIndex={0}\n >\n {isImage && item?.previewUrl ? (\n <ItemThumb url={item.previewUrl} alt={item.name ?? id} />\n ) : (\n <div className=\"bg-muted text-muted-foreground flex size-7 shrink-0 items-center justify-center rounded\">\n <FileIcon className=\"size-4\" />\n </div>\n )}\n {canClear && (\n <button\n type=\"button\"\n onClick={(e) => {\n e.stopPropagation();\n removeOne(id);\n }}\n aria-label={tr(\"controlUpload.remove\", { default: \"Remove\" })}\n className=\"text-muted-foreground hover:text-foreground absolute top-1/2 right-2 -translate-y-1/2 p-1\"\n >\n <X className=\"size-3.5\" />\n </button>\n )}\n </div>\n );\n };\n\n const previewItem = previewId ? meta.get(previewId) : undefined;\n const previewIsImage = previewItem\n ? previewItem.mimeType?.startsWith(\"image/\") ||\n ((props.accept ?? \"\").includes(\"image\") &&\n !!previewItem.previewUrl &&\n !previewItem.mimeType)\n : false;\n const previewHasName =\n !!previewItem?.name && previewItem.name !== previewItem.id;\n\n const dragDropHint =\n tr(\"controlUpload.dragDrop\", { default: \"Upload or drag and drop here\" }) +\n (props.maxSize\n ? ` · ${tr(\"controlUpload.max\", {\n default: `max ${formatBytes(props.maxSize)}`,\n args: [formatBytes(props.maxSize)],\n })}`\n : \"\");\n\n const dropZone = (\n <Tooltip>\n <TooltipTrigger\n render={\n <Button\n type=\"button\"\n variant=\"outline\"\n size=\"sm\"\n disabled={props.disabled || uploading}\n onClick={() => fileInputRef.current?.click()}\n onDragOver={(e) => {\n e.preventDefault();\n setDragOver(true);\n }}\n onDragLeave={() => setDragOver(false)}\n onDrop={handleDrop}\n className={dragOver ? \"border-primary bg-primary/5\" : \"\"}\n />\n }\n >\n {uploading ? (\n <>\n <Loader2 className=\"size-4 mr-1 animate-spin\" />\n {tr(\"controlUpload.uploading\", { default: \"Uploading…\" })}\n </>\n ) : (\n <>\n <Upload className=\"size-4 mr-1\" />\n {props.multi\n ? tr(\"controlUpload.chooseFiles\", { default: \"Choose files\" })\n : tr(\"controlUpload.chooseFile\", { default: \"Choose a file\" })}\n </>\n )}\n </TooltipTrigger>\n <TooltipContent>{dragDropHint}</TooltipContent>\n </Tooltip>\n );\n\n return (\n <FormField\n id={inputId}\n label={fieldMeta.label}\n description={fieldMeta.description}\n error={fieldMeta.error}\n required={fieldMeta.required}\n >\n <input\n ref={fileInputRef}\n type=\"file\"\n id={inputId}\n name={props.input.props.name}\n className=\"hidden\"\n accept={props.accept}\n multiple={props.multi}\n disabled={props.disabled}\n onChange={handleInputChange}\n />\n\n <div className=\"flex flex-col gap-2\">\n {ids.length > 0 && (\n <div className=\"flex flex-col gap-2\">{ids.map(renderItem)}</div>\n )}\n {(props.multi || ids.length === 0) && dropZone}\n {uploading && (\n <div className=\"bg-muted h-1 w-full overflow-hidden rounded\">\n <div\n className=\"bg-primary h-full transition-all\"\n style={{ width: `${progress}%` }}\n />\n </div>\n )}\n </div>\n\n <Dialog\n open={previewId !== null}\n onOpenChange={(o) => !o && setPreviewId(null)}\n >\n <DialogContent className=\"w-fit max-w-fit p-0\">\n <DialogHeader className=\"sr-only\">\n <DialogTitle>\n {previewHasName\n ? previewItem?.name\n : tr(\"controlUpload.savedFile\", { default: \"Saved file\" })}\n </DialogTitle>\n <DialogDescription>\n {previewItem?.mimeType ?? \"uploaded\"}\n </DialogDescription>\n </DialogHeader>\n <div className=\"p-4\">\n {previewIsImage && previewItem?.previewUrl ? (\n <img\n src={previewItem.previewUrl}\n alt={previewItem.name ?? \"\"}\n className=\"size-72 rounded object-contain\"\n />\n ) : (\n <div className=\"bg-muted text-muted-foreground flex size-72 items-center justify-center rounded\">\n <FileIcon className=\"size-16\" />\n </div>\n )}\n </div>\n {(previewHasName || previewItem?.mimeType) && (\n <div className=\"flex flex-col gap-0 border-t bg-muted/30 px-4 py-2\">\n {previewHasName && (\n <span className=\"truncate text-sm font-medium\">\n {previewItem?.name}\n </span>\n )}\n {previewItem?.mimeType && (\n <span className=\"text-muted-foreground truncate text-xs\">\n {previewItem.mimeType}\n </span>\n )}\n </div>\n )}\n </DialogContent>\n </Dialog>\n </FormField>\n );\n}\n\nfunction ItemThumb(props: { url: string; alt: string }) {\n const [broken, setBroken] = useState(false);\n if (broken) {\n return (\n <div className=\"bg-muted text-muted-foreground flex size-7 shrink-0 items-center justify-center rounded\">\n <FileIcon className=\"size-4\" />\n </div>\n );\n }\n return (\n <img\n src={props.url}\n alt={props.alt}\n className=\"size-7 shrink-0 rounded object-cover\"\n onError={() => setBroken(true)}\n />\n );\n}\n\nconst formatBytes = (n: number): string => {\n if (!n) return \"0 B\";\n const units = [\"B\", \"KB\", \"MB\", \"GB\"];\n const i = Math.min(\n units.length - 1,\n Math.floor(Math.log(n) / Math.log(1024)),\n );\n return `${(n / 1024 ** i).toFixed(1)} ${units[i]}`;\n};\n"],"mappings":";;;;;;;;;;;;;;;;;;;;;AAoHA,SAAgB,cAAc,OAA2B;CACvD,M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,IAAI,KAAK,IAAI,IAAI,CAAC,CACzC;CACA,OAAO,IAAI,IAAI,QAAQ,EAAA,CAAG,QAAQ,CAAC,EAAE,GAAG,MAAM;AAChD"}
|
|
1
|
+
{"version":3,"file":"control-upload.js","names":["FileIcon"],"sources":["../../../src/components/control-upload/control-upload.tsx"],"sourcesContent":["import * as React from \"react\";\n\nvoid React;\n\nimport { FormField } from \"@alepha/ui/components/control-base/form-field\";\nimport { Button } from \"@alepha/ui/components/ui/button\";\nimport {\n Dialog,\n DialogContent,\n DialogDescription,\n DialogHeader,\n DialogTitle,\n} from \"@alepha/ui/components/ui/dialog\";\nimport {\n Tooltip,\n TooltipContent,\n TooltipTrigger,\n} from \"@alepha/ui/components/ui/tooltip\";\nimport { useToast } from \"@alepha/ui/components/use-toast/use-toast\";\nimport type { FileController } from \"alepha/api/files\";\nimport { useClient } from \"alepha/react\";\nimport {\n type BaseInputField,\n parseField,\n useFieldValue,\n useFormState,\n} from \"alepha/react/form\";\nimport { useI18n } from \"alepha/react/i18n\";\nimport { File as FileIcon, Loader2, Upload, X } from \"lucide-react\";\nimport {\n type ChangeEvent,\n type DragEvent,\n useEffect,\n useId,\n useRef,\n useState,\n} from \"react\";\n\nimport {\n type ResizeImageOptions,\n resizeImage,\n} from \"../../lib/resize-image.ts\";\n\nexport interface ControlUploadProps {\n /**\n * Bound `InputField` from `useForm`. Stores the uploaded file ID(s).\n */\n input: BaseInputField;\n /**\n * Field label. Falls back to schema `title`.\n */\n label?: string;\n /**\n * Helper text shown below the dropzone.\n */\n description?: string;\n /**\n * Multi-file mode. The form value becomes an `Array<string>` of file\n * IDs. Single mode (default) stores a bare UUID string.\n */\n multi?: boolean;\n /**\n * HTML `accept` filter on the file picker (e.g. `\"image/*\"`,\n * `\".pdf,.docx\"`).\n */\n accept?: string;\n /**\n * Max size per file (bytes). Files over the limit are rejected.\n */\n maxSize?: number;\n /**\n * Downscale images to these bounds before uploading.\n *\n * Set it wherever the result is rendered small — the bytes never leave the\n * machine, so it speeds up the upload as well as every later fetch. Applied\n * before {@link maxSize}, so a photo that would have been rejected for being\n * too large is resized and accepted instead.\n *\n * Best-effort by design: a browser without `OffscreenCanvas`, an SVG, or an\n * image the decoder chokes on is uploaded as-is, and the storage's own\n * `maxSize` remains what actually bounds it. That trade is deliberate — a\n * server-side codec able to close the gap costs more bundle than the case is\n * worth on an edge runtime, and encodes worse (see `files:beforeUpload` in\n * `alepha/api/files` for where it would attach if you want it anyway).\n *\n * @example { maxWidth: 256 }\n */\n image?: ResizeImageOptions;\n /**\n * Bucket name passed to the upload endpoint.\n */\n bucket?: string;\n /**\n * Disable the dropzone.\n */\n disabled?: boolean;\n}\n\ninterface UploadedFileMeta {\n id: string;\n name: string;\n mimeType?: string;\n size?: number;\n /**\n * Object URL for image preview, when applicable.\n */\n previewUrl?: string;\n}\n\n/**\n * File upload control. Wraps `FileController.uploadFile`, stores the\n * resulting file ID(s) in the form, and renders a thumbnail preview for\n * images and a chip-style summary for everything else.\n *\n * Single-file: form value is a uuid string.\n * Multi-file: form value is an array of uuid strings.\n */\nexport const ControlUpload = (props: ControlUploadProps) => {\n const form = useFormState(props.input, [\"error\"]);\n const [value, setValue] = useFieldValue(props.input);\n const client = useClient<FileController>();\n const { tr } = useI18n();\n const toast = useToast();\n const inputId = useId();\n const fileInputRef = useRef<HTMLInputElement>(null);\n const [uploading, setUploading] = useState(false);\n const [progress, setProgress] = useState(0);\n const [meta, setMeta] = useState<Map<string, UploadedFileMeta>>(new Map());\n const [dragOver, setDragOver] = useState(false);\n const [previewId, setPreviewId] = useState<string | null>(null);\n\n /**\n * Backfill `meta` for ids that arrived from form state (e.g. after a page\n * reload) so the renderer can show a thumbnail / chip instead of the raw\n * uuid. We can't infer the real mime type without an extra request, so we\n * fall back to a stub entry pointing at `/api/files/:id` and let the\n * `<img>` `onError` swap to the generic file chip.\n */\n useEffect(() => {\n const ids: string[] = props.multi\n ? Array.isArray(value)\n ? (value as string[])\n : []\n : value\n ? [value as string]\n : [];\n // Reconciles a cache of per-file metadata against the ids the field now\n // holds, and the entries it keeps were filled in by the upload requests this\n // same effect issues. It is the cache for an external system, not derived\n // state; the updater already no-ops when nothing changed.\n // oxlint-disable-next-line react/set-state-in-effect\n setMeta((current) => {\n let changed = false;\n const next = new Map(current);\n for (const id of ids) {\n if (!next.has(id)) {\n next.set(id, {\n id,\n name: id,\n previewUrl: `/api/files/${id}`,\n });\n changed = true;\n }\n }\n return changed ? next : current;\n });\n }, [Array.isArray(value) ? value.join(\",\") : value, props.multi]);\n\n if (!props.input?.props) return null;\n\n const fieldMeta = parseField(props.input, {\n label: props.label,\n description: props.description,\n error: form.error,\n });\n\n const ids: string[] = props.multi\n ? Array.isArray(value)\n ? (value as string[])\n : []\n : value\n ? [value as string]\n : [];\n\n const handleFiles = async (files: FileList) => {\n if (!files.length) return;\n if (!props.multi && files.length > 1) {\n toast.error(\n tr(\"controlUpload.singleOnly\", { default: \"Only one file allowed\" }),\n );\n return;\n }\n\n setUploading(true);\n setProgress(0);\n const next = new Map(meta);\n const newIds: string[] = [];\n\n try {\n for (let i = 0; i < files.length; i++) {\n // Ahead of the size check on purpose: a 4 MB photo destined for a 32px\n // avatar should become a few kilobytes, not an error.\n const file = props.image\n ? await resizeImage(files[i], props.image)\n : files[i];\n\n if (props.maxSize && file.size > props.maxSize) {\n toast.error(\n tr(\"controlUpload.tooBig\", {\n default: `${file.name} exceeds ${formatBytes(props.maxSize)}`,\n args: [file.name, formatBytes(props.maxSize)],\n }),\n );\n continue;\n }\n\n const resource = await client.uploadFile({\n body: { file },\n query: props.bucket ? { bucket: props.bucket } : ({} as never),\n });\n\n const previewUrl = file.type.startsWith(\"image/\")\n ? URL.createObjectURL(file)\n : undefined;\n\n next.set(resource.id, {\n id: resource.id,\n name: resource.name ?? file.name,\n mimeType: resource.mimeType ?? file.type,\n size: resource.size ?? file.size,\n previewUrl,\n });\n newIds.push(resource.id);\n setProgress(Math.round(((i + 1) / files.length) * 100));\n }\n\n setMeta(next);\n if (props.multi) {\n setValue([...ids, ...newIds]);\n } else if (newIds[0]) {\n setValue(newIds[0]);\n }\n if (newIds.length) {\n toast.success(\n newIds.length === 1\n ? tr(\"controlUpload.uploadedOne\", { default: \"File uploaded\" })\n : tr(\"controlUpload.uploadedMany\", {\n default: `${newIds.length} files uploaded`,\n args: [String(newIds.length)],\n }),\n );\n }\n } catch (e) {\n const msg = (e as Error).message;\n toast.error(\n tr(\"controlUpload.failed\", {\n default: `Upload failed: ${msg}`,\n args: [msg],\n }),\n );\n } finally {\n setUploading(false);\n setProgress(0);\n if (fileInputRef.current) fileInputRef.current.value = \"\";\n }\n };\n\n const handleInputChange = (e: ChangeEvent<HTMLInputElement>) => {\n if (e.target.files) void handleFiles(e.target.files);\n };\n\n const handleDrop = (e: DragEvent) => {\n e.preventDefault();\n setDragOver(false);\n if (props.disabled) return;\n if (e.dataTransfer.files) void handleFiles(e.dataTransfer.files);\n };\n\n const removeOne = (id: string) => {\n const next = new Map(meta);\n const item = next.get(id);\n if (item?.previewUrl) URL.revokeObjectURL(item.previewUrl);\n next.delete(id);\n setMeta(next);\n\n if (props.multi) {\n setValue(ids.filter((it) => it !== id));\n } else {\n setValue(undefined);\n }\n };\n\n const renderItem = (id: string) => {\n const item = meta.get(id);\n const acceptsImage = (props.accept ?? \"\").includes(\"image\");\n const mimeIsImage = item?.mimeType?.startsWith(\"image/\");\n const isImage =\n mimeIsImage || (acceptsImage && !!item?.previewUrl && !item?.mimeType);\n\n const canClear = !props.disabled && !fieldMeta.required;\n\n return (\n <div\n key={id}\n className={`border-input dark:bg-input/30 relative flex h-9 cursor-zoom-in items-center rounded-md border bg-transparent pl-1 ${canClear ? \"pr-9\" : \"pr-2\"}`}\n onClick={() => setPreviewId(id)}\n onKeyDown={(e) => {\n if (e.key === \"Enter\" || e.key === \" \") {\n e.preventDefault();\n setPreviewId(id);\n }\n }}\n role=\"button\"\n tabIndex={0}\n >\n {isImage && item?.previewUrl ? (\n <ItemThumb url={item.previewUrl} alt={item.name ?? id} />\n ) : (\n <div className=\"bg-muted text-muted-foreground flex size-7 shrink-0 items-center justify-center rounded\">\n <FileIcon className=\"size-4\" />\n </div>\n )}\n {canClear && (\n <button\n type=\"button\"\n onClick={(e) => {\n e.stopPropagation();\n removeOne(id);\n }}\n aria-label={tr(\"controlUpload.remove\", { default: \"Remove\" })}\n className=\"text-muted-foreground hover:text-foreground absolute top-1/2 right-2 -translate-y-1/2 p-1\"\n >\n <X className=\"size-3.5\" />\n </button>\n )}\n </div>\n );\n };\n\n const previewItem = previewId ? meta.get(previewId) : undefined;\n const previewIsImage = previewItem\n ? previewItem.mimeType?.startsWith(\"image/\") ||\n ((props.accept ?? \"\").includes(\"image\") &&\n !!previewItem.previewUrl &&\n !previewItem.mimeType)\n : false;\n const previewHasName =\n !!previewItem?.name && previewItem.name !== previewItem.id;\n\n const dragDropHint =\n tr(\"controlUpload.dragDrop\", { default: \"Upload or drag and drop here\" }) +\n (props.maxSize\n ? ` · ${tr(\"controlUpload.max\", {\n default: `max ${formatBytes(props.maxSize)}`,\n args: [formatBytes(props.maxSize)],\n })}`\n : \"\");\n\n const dropZone = (\n <Tooltip>\n <TooltipTrigger\n render={\n <Button\n type=\"button\"\n variant=\"outline\"\n size=\"sm\"\n disabled={props.disabled || uploading}\n onClick={() => fileInputRef.current?.click()}\n onDragOver={(e) => {\n e.preventDefault();\n setDragOver(true);\n }}\n onDragLeave={() => setDragOver(false)}\n onDrop={handleDrop}\n className={dragOver ? \"border-primary bg-primary/5\" : \"\"}\n />\n }\n >\n {uploading ? (\n <>\n <Loader2 className=\"mr-1 size-4 animate-spin\" />\n {tr(\"controlUpload.uploading\", { default: \"Uploading…\" })}\n </>\n ) : (\n <>\n <Upload className=\"mr-1 size-4\" />\n {props.multi\n ? tr(\"controlUpload.chooseFiles\", { default: \"Choose files\" })\n : tr(\"controlUpload.chooseFile\", { default: \"Choose a file\" })}\n </>\n )}\n </TooltipTrigger>\n <TooltipContent>{dragDropHint}</TooltipContent>\n </Tooltip>\n );\n\n return (\n <FormField\n id={inputId}\n label={fieldMeta.label}\n description={fieldMeta.description}\n error={fieldMeta.error}\n required={fieldMeta.required}\n >\n <input\n ref={fileInputRef}\n type=\"file\"\n id={inputId}\n name={props.input.props.name}\n className=\"hidden\"\n accept={props.accept}\n multiple={props.multi}\n disabled={props.disabled}\n onChange={handleInputChange}\n />\n\n <div className=\"flex flex-col gap-2\">\n {ids.length > 0 && (\n <div className=\"flex flex-col gap-2\">{ids.map(renderItem)}</div>\n )}\n {(props.multi || ids.length === 0) && dropZone}\n {uploading && (\n <div className=\"bg-muted h-1 w-full overflow-hidden rounded\">\n <div\n className=\"bg-primary h-full transition-all\"\n style={{ width: `${progress}%` }}\n />\n </div>\n )}\n </div>\n\n <Dialog\n open={previewId !== null}\n onOpenChange={(o) => !o && setPreviewId(null)}\n >\n <DialogContent className=\"w-fit max-w-fit p-0\">\n <DialogHeader className=\"sr-only\">\n <DialogTitle>\n {previewHasName\n ? previewItem?.name\n : tr(\"controlUpload.savedFile\", { default: \"Saved file\" })}\n </DialogTitle>\n <DialogDescription>\n {previewItem?.mimeType ?? \"uploaded\"}\n </DialogDescription>\n </DialogHeader>\n <div className=\"p-4\">\n {previewIsImage && previewItem?.previewUrl ? (\n <img\n src={previewItem.previewUrl}\n alt={previewItem.name ?? \"\"}\n className=\"size-72 rounded object-contain\"\n />\n ) : (\n <div className=\"bg-muted text-muted-foreground flex size-72 items-center justify-center rounded\">\n <FileIcon className=\"size-16\" />\n </div>\n )}\n </div>\n {(previewHasName || previewItem?.mimeType) && (\n <div className=\"bg-muted/30 flex flex-col gap-0 border-t px-4 py-2\">\n {previewHasName && (\n <span className=\"truncate text-sm font-medium\">\n {previewItem?.name}\n </span>\n )}\n {previewItem?.mimeType && (\n <span className=\"text-muted-foreground truncate text-xs\">\n {previewItem.mimeType}\n </span>\n )}\n </div>\n )}\n </DialogContent>\n </Dialog>\n </FormField>\n );\n};\n\nconst ItemThumb = (props: { url: string; alt: string }) => {\n const [broken, setBroken] = useState(false);\n if (broken) {\n return (\n <div className=\"bg-muted text-muted-foreground flex size-7 shrink-0 items-center justify-center rounded\">\n <FileIcon className=\"size-4\" />\n </div>\n );\n }\n return (\n <img\n src={props.url}\n alt={props.alt}\n className=\"size-7 shrink-0 rounded object-cover\"\n onError={() => setBroken(true)}\n />\n );\n};\n\nconst formatBytes = (n: number): string => {\n if (!n) return \"0 B\";\n const units = [\"B\", \"KB\", \"MB\", \"GB\"];\n const i = Math.min(\n units.length - 1,\n Math.floor(Math.log(n) / Math.log(1024)),\n );\n return `${(n / 1024 ** i).toFixed(1)} ${units[i]}`;\n};\n"],"mappings":";;;;;;;;;;;;;;;;;;;;;AAqHA,MAAa,iBAAiB,UAA8B;CAC1D,MAAM,OAAO,aAAa,MAAM,OAAO,CAAC,OAAO,CAAC;CAChD,MAAM,CAAC,OAAO,YAAY,cAAc,MAAM,KAAK;CACnD,MAAM,SAAS,UAA0B;CACzC,MAAM,EAAE,OAAO,QAAQ;CACvB,MAAM,QAAQ,SAAS;CACvB,MAAM,UAAU,MAAM;CACtB,MAAM,eAAe,OAAyB,IAAI;CAClD,MAAM,CAAC,WAAW,gBAAgB,SAAS,KAAK;CAChD,MAAM,CAAC,UAAU,eAAe,SAAS,CAAC;CAC1C,MAAM,CAAC,MAAM,WAAW,yBAAwC,IAAI,IAAI,CAAC;CACzE,MAAM,CAAC,UAAU,eAAe,SAAS,KAAK;CAC9C,MAAM,CAAC,WAAW,gBAAgB,SAAwB,IAAI;;;;;;;;CAS9D,gBAAgB;EACd,MAAM,MAAgB,MAAM,QACxB,MAAM,QAAQ,KAAK,IAChB,QACD,CAAC,IACH,QACE,CAAC,KAAe,IAChB,CAAC;EAMP,SAAS,YAAY;GACnB,IAAI,UAAU;GACd,MAAM,OAAO,IAAI,IAAI,OAAO;GAC5B,KAAK,MAAM,MAAM,KACf,IAAI,CAAC,KAAK,IAAI,EAAE,GAAG;IACjB,KAAK,IAAI,IAAI;KACX;KACA,MA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AEf;AAEA,MAAM,aAAa,UAAwC;CACzD,MAAM,CAAC,QAAQ,aAAa,SAAS,KAAK;CAC1C,IAAI,QACF,OACE,oBAAC,OAAD;EAAK,WAAU;EACb,UAAA,oBAACA,MAAD,EAAU,WAAU,SAAU,CAAA;CAC3B,CAAA;CAGT,OACE,oBAAC,OAAD;EACE,KAAK,MAAM;EACX,KAAK,MAAM;EACX,WAAU;EACV,eAAe,UAAU,IAAI;CAC9B,CAAA;AAEL;AAEA,MAAM,eAAe,MAAsB;CACzC,IAAI,CAAC,GAAG,OAAO;CACf,MAAM,QAAQ;EAAC;EAAK;EAAM;EAAM;CAAI;CACpC,MAAM,IAAI,KAAK,IACb,MAAM,SAAS,GACf,KAAK,MAAM,KAAK,IAAI,CAAC,IAAI,KAAK,IAAI,IAAI,CAAC,CACzC;CACA,OAAO,IAAI,IAAI,QAAQ,EAAA,CAAG,QAAQ,CAAC,EAAE,GAAG,MAAM;AAChD"}
|
|
@@ -0,0 +1,58 @@
|
|
|
1
|
+
import * as React from "react";
|
|
2
|
+
export interface DetailAsideRow {
|
|
3
|
+
/**
|
|
4
|
+
* Doubles as the React key, so two rows in one aside must not share a label.
|
|
5
|
+
*/
|
|
6
|
+
label: string;
|
|
7
|
+
value?: React.ReactNode;
|
|
8
|
+
/**
|
|
9
|
+
* Renders a copy-to-clipboard button beside the value. When `value` is
|
|
10
|
+
* omitted the row renders this text as the value, in mono — the shape an id
|
|
11
|
+
* row wants.
|
|
12
|
+
*/
|
|
13
|
+
copy?: string;
|
|
14
|
+
}
|
|
15
|
+
export interface DetailAsideProps {
|
|
16
|
+
/**
|
|
17
|
+
* Omit when something else on screen already names the thing — a
|
|
18
|
+
* breadcrumb leaf, most often. With no title and no avatar the header
|
|
19
|
+
* block is not rendered at all and the list starts at the top edge.
|
|
20
|
+
*/
|
|
21
|
+
title?: string;
|
|
22
|
+
/**
|
|
23
|
+
* Thumbnail or avatar source. Falls back to {@link fallback}.
|
|
24
|
+
*/
|
|
25
|
+
image?: string;
|
|
26
|
+
/**
|
|
27
|
+
* Shown in place of a missing image. Defaults to the title's initial.
|
|
28
|
+
*/
|
|
29
|
+
fallback?: string;
|
|
30
|
+
/**
|
|
31
|
+
* Set `false` for an entity that has no avatar concept at all, and the
|
|
32
|
+
* title stands alone.
|
|
33
|
+
*
|
|
34
|
+
* The letter fallback earns its place when the thing *has* a picture and
|
|
35
|
+
* happens to be missing one — a user without an uploaded photo is still a
|
|
36
|
+
* face-shaped hole. For something that could never have had one, a large
|
|
37
|
+
* square holding the first letter of a title printed beside it is the same
|
|
38
|
+
* character twice at two sizes.
|
|
39
|
+
*/
|
|
40
|
+
avatar?: boolean;
|
|
41
|
+
rows: DetailAsideRow[];
|
|
42
|
+
}
|
|
43
|
+
/**
|
|
44
|
+
* The identity panel of a detail page: a thumbnail and title above a dense
|
|
45
|
+
* label/value list.
|
|
46
|
+
*
|
|
47
|
+
* Dense rather than a marketing hero — the list is what a reader scans, so it
|
|
48
|
+
* is a `<dl>` of small caps labels over their values, and a row with nothing
|
|
49
|
+
* to say is left out by the caller rather than rendered empty.
|
|
50
|
+
*
|
|
51
|
+
* Extracted from the admin user detail page and shared by every detail page
|
|
52
|
+
* since, which is why the clipboard behaviour lives here: each of them wants
|
|
53
|
+
* a copyable id, and each of them had reimplemented it. It moved out of
|
|
54
|
+
* `components/admin/` alongside {@link DetailLayout} once a non-admin page
|
|
55
|
+
* (Lore's Epic view) became a consumer.
|
|
56
|
+
*/
|
|
57
|
+
export declare const DetailAside: (props: DetailAsideProps) => React.JSX.Element;
|
|
58
|
+
//# sourceMappingURL=detail-aside.d.ts.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"detail-aside.d.ts","sourceRoot":"","sources":["../../../src/components/detail/detail-aside.tsx"],"names":[],"mappings":"AAAA,OAAO,KAAK,KAAK,MAAM,OAAO,CAAC;AAc/B,MAAM,WAAW,cAAc;IAC7B;;OAEG;IACH,KAAK,EAAE,MAAM,CAAC;IACd,KAAK,CAAC,EAAE,KAAK,CAAC,SAAS,CAAC;IACxB;;;;OAIG;IACH,IAAI,CAAC,EAAE,MAAM,CAAC;CACf;AAED,MAAM,WAAW,gBAAgB;IAC/B;;;;OAIG;IACH,KAAK,CAAC,EAAE,MAAM,CAAC;IACf;;OAEG;IACH,KAAK,CAAC,EAAE,MAAM,CAAC;IACf;;OAEG;IACH,QAAQ,CAAC,EAAE,MAAM,CAAC;IAClB;;;;;;;;;OASG;IACH,MAAM,CAAC,EAAE,OAAO,CAAC;IACjB,IAAI,EAAE,cAAc,EAAE,CAAC;CACxB;AAED;;;;;;;;;;;;;GAaG;AACH,eAAO,MAAM,WAAW,UAAW,gBAAgB,sBA8HlD,CAAC"}
|