@alepha/ui 0.28.0 → 0.29.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 +31 -2
- package/dist/components/account/account-connections.d.ts.map +1 -1
- package/dist/components/account/account-connections.js +4 -1
- package/dist/components/account/account-connections.js.map +1 -1
- package/dist/components/account/account-delete-dialog.d.ts.map +1 -1
- package/dist/components/account/account-delete-dialog.js +12 -15
- package/dist/components/account/account-delete-dialog.js.map +1 -1
- package/dist/components/account/account-keys.d.ts.map +1 -1
- package/dist/components/account/account-keys.js +22 -28
- package/dist/components/account/account-keys.js.map +1 -1
- package/dist/components/account/account-mfa-dialog.js +1 -4
- package/dist/components/account/account-mfa-dialog.js.map +1 -1
- package/dist/components/account/account-password-dialog.d.ts.map +1 -1
- package/dist/components/account/account-password-dialog.js +11 -14
- package/dist/components/account/account-password-dialog.js.map +1 -1
- package/dist/components/account/account-profile.js +3 -2
- package/dist/components/account/account-profile.js.map +1 -1
- package/dist/components/account/account-router-options.d.ts +38 -0
- 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 +11 -1
- package/dist/components/account/account-router-page.d.ts.map +1 -1
- package/dist/components/account/account-router-page.js +11 -1
- package/dist/components/account/account-router-page.js.map +1 -1
- package/dist/components/account/account-router.d.ts +11 -0
- package/dist/components/account/account-router.d.ts.map +1 -1
- package/dist/components/account/account-router.js +16 -5
- package/dist/components/account/account-router.js.map +1 -1
- package/dist/components/admin/admin-audits.d.ts.map +1 -1
- package/dist/components/admin/admin-audits.js +91 -34
- package/dist/components/admin/admin-audits.js.map +1 -1
- package/dist/components/admin/admin-files.d.ts.map +1 -1
- package/dist/components/admin/admin-files.js +6 -17
- package/dist/components/admin/admin-files.js.map +1 -1
- package/dist/components/admin/admin-jobs-executions-panel.d.ts.map +1 -1
- package/dist/components/admin/admin-jobs-executions-panel.js +39 -8
- package/dist/components/admin/admin-jobs-executions-panel.js.map +1 -1
- package/dist/components/admin/admin-jobs-payload-dialog.d.ts +19 -0
- package/dist/components/admin/admin-jobs-payload-dialog.d.ts.map +1 -0
- package/dist/components/admin/admin-jobs-payload-dialog.js +33 -0
- package/dist/components/admin/admin-jobs-payload-dialog.js.map +1 -0
- package/dist/components/admin/admin-keys.d.ts.map +1 -1
- package/dist/components/admin/admin-keys.js +5 -4
- package/dist/components/admin/admin-keys.js.map +1 -1
- package/dist/components/admin/admin-notifications-channel-label.d.ts +14 -0
- package/dist/components/admin/admin-notifications-channel-label.d.ts.map +1 -0
- package/dist/components/admin/admin-notifications-channel-label.js +26 -0
- package/dist/components/admin/admin-notifications-channel-label.js.map +1 -0
- package/dist/components/admin/admin-notifications-preview-body.d.ts.map +1 -1
- package/dist/components/admin/admin-notifications-preview-body.js +23 -13
- package/dist/components/admin/admin-notifications-preview-body.js.map +1 -1
- package/dist/components/admin/admin-notifications.d.ts.map +1 -1
- package/dist/components/admin/admin-notifications.js +11 -12
- package/dist/components/admin/admin-notifications.js.map +1 -1
- package/dist/components/admin/admin-payments.d.ts.map +1 -1
- package/dist/components/admin/admin-payments.js +9 -7
- package/dist/components/admin/admin-payments.js.map +1 -1
- package/dist/components/admin/admin-router-options.d.ts +12 -0
- 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.d.ts +5 -8
- package/dist/components/admin/admin-router.d.ts.map +1 -1
- package/dist/components/admin/admin-router.js +6 -29
- package/dist/components/admin/admin-router.js.map +1 -1
- package/dist/components/admin/admin-sessions.d.ts.map +1 -1
- package/dist/components/admin/admin-sessions.js +9 -7
- package/dist/components/admin/admin-sessions.js.map +1 -1
- package/dist/components/admin/admin-user-detail-audits-tab.d.ts.map +1 -1
- package/dist/components/admin/admin-user-detail-audits-tab.js +5 -4
- package/dist/components/admin/admin-user-detail-audits-tab.js.map +1 -1
- package/dist/components/admin/admin-user-detail-sessions-tab.d.ts.map +1 -1
- package/dist/components/admin/admin-user-detail-sessions-tab.js +7 -5
- package/dist/components/admin/admin-user-detail-sessions-tab.js.map +1 -1
- package/dist/components/admin/admin-user-detail.js +3 -2
- package/dist/components/admin/admin-user-detail.js.map +1 -1
- package/dist/components/admin/admin-users-roles-picker.d.ts.map +1 -1
- 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 +6 -4
- package/dist/components/admin/admin-users.js.map +1 -1
- package/dist/components/admin/analytics/AnalyticsChartBars.js +2 -1
- package/dist/components/admin/analytics/AnalyticsChartBars.js.map +1 -1
- package/dist/components/admin/parameter-history-item.d.ts.map +1 -1
- package/dist/components/admin/parameter-history-item.js +3 -2
- package/dist/components/admin/parameter-history-item.js.map +1 -1
- package/dist/components/alepha-table/alepha-table-bulk-menu.js +2 -1
- package/dist/components/alepha-table/alepha-table-bulk-menu.js.map +1 -1
- package/dist/components/alepha-table/alepha-table-filter-dialog.d.ts +60 -0
- package/dist/components/alepha-table/alepha-table-filter-dialog.d.ts.map +1 -0
- package/dist/components/alepha-table/alepha-table-filter-dialog.js +88 -0
- package/dist/components/alepha-table/alepha-table-filter-dialog.js.map +1 -0
- package/dist/components/alepha-table/alepha-table-filter-menu.d.ts +35 -0
- package/dist/components/alepha-table/alepha-table-filter-menu.d.ts.map +1 -0
- package/dist/components/alepha-table/alepha-table-filter-menu.js +54 -0
- package/dist/components/alepha-table/alepha-table-filter-menu.js.map +1 -0
- package/dist/components/alepha-table/alepha-table.d.ts +188 -3
- package/dist/components/alepha-table/alepha-table.d.ts.map +1 -1
- package/dist/components/alepha-table/alepha-table.js +551 -162
- package/dist/components/alepha-table/alepha-table.js.map +1 -1
- package/dist/components/alepha-table/query-filters.d.ts +73 -0
- package/dist/components/alepha-table/query-filters.d.ts.map +1 -0
- package/dist/components/alepha-table/query-filters.js +118 -0
- package/dist/components/alepha-table/query-filters.js.map +1 -0
- package/dist/components/app-actions/app-actions.d.ts +21 -0
- package/dist/components/app-actions/app-actions.d.ts.map +1 -1
- package/dist/components/app-actions/app-actions.js +11 -5
- package/dist/components/app-actions/app-actions.js.map +1 -1
- package/dist/components/app-shell/app-shell.d.ts +45 -0
- package/dist/components/app-shell/app-shell.d.ts.map +1 -1
- package/dist/components/app-shell/app-shell.js +119 -16
- package/dist/components/app-shell/app-shell.js.map +1 -1
- package/dist/components/auth/auth-register.js +31 -30
- package/dist/components/auth/auth-register.js.map +1 -1
- package/dist/components/auto-form/auto-form.d.ts.map +1 -1
- package/dist/components/auto-form/auto-form.js +68 -30
- package/dist/components/auto-form/auto-form.js.map +1 -1
- package/dist/components/button-dark/button-dark.d.ts.map +1 -1
- package/dist/components/button-dark/button-dark.js +39 -8
- package/dist/components/button-dark/button-dark.js.map +1 -1
- package/dist/components/button-inbox/button-inbox.d.ts +66 -0
- package/dist/components/button-inbox/button-inbox.d.ts.map +1 -0
- package/dist/components/button-inbox/button-inbox.js +167 -0
- package/dist/components/button-inbox/button-inbox.js.map +1 -0
- package/dist/components/button-inbox/inbox-unread-atom.d.ts +22 -0
- package/dist/components/button-inbox/inbox-unread-atom.d.ts.map +1 -0
- package/dist/components/button-inbox/inbox-unread-atom.js +29 -0
- package/dist/components/button-inbox/inbox-unread-atom.js.map +1 -0
- package/dist/components/button-theme/button-theme.d.ts +4 -3
- package/dist/components/button-theme/button-theme.d.ts.map +1 -1
- package/dist/components/button-theme/button-theme.js +8 -25
- package/dist/components/button-theme/button-theme.js.map +1 -1
- package/dist/components/button-user/button-user.d.ts +19 -0
- package/dist/components/button-user/button-user.d.ts.map +1 -1
- package/dist/components/button-user/button-user.js +1 -1
- package/dist/components/button-user/button-user.js.map +1 -1
- package/dist/components/control/control.d.ts +51 -0
- package/dist/components/control/control.d.ts.map +1 -1
- package/dist/components/control/control.js +49 -5
- package/dist/components/control/control.js.map +1 -1
- package/dist/components/control-array/control-array.js +2 -1
- package/dist/components/control-array/control-array.js.map +1 -1
- package/dist/components/control-date/control-date.d.ts +27 -0
- package/dist/components/control-date/control-date.d.ts.map +1 -1
- package/dist/components/control-date/control-date.js +15 -19
- package/dist/components/control-date/control-date.js.map +1 -1
- package/dist/components/control-date/date-only.d.ts +18 -0
- package/dist/components/control-date/date-only.d.ts.map +1 -0
- package/dist/components/control-date/date-only.js +29 -0
- package/dist/components/control-date/date-only.js.map +1 -0
- package/dist/components/control-date-range/control-date-range.d.ts +56 -0
- package/dist/components/control-date-range/control-date-range.d.ts.map +1 -0
- package/dist/components/control-date-range/control-date-range.js +148 -0
- package/dist/components/control-date-range/control-date-range.js.map +1 -0
- package/dist/components/control-object/control-object.js +2 -1
- package/dist/components/control-object/control-object.js.map +1 -1
- package/dist/components/control-select/control-select.d.ts.map +1 -1
- package/dist/components/control-select/control-select.js +177 -37
- package/dist/components/control-select/control-select.js.map +1 -1
- package/dist/components/control-upload/control-upload.d.ts.map +1 -1
- package/dist/components/control-upload/control-upload.js +1 -11
- package/dist/components/control-upload/control-upload.js.map +1 -1
- package/dist/components/detail/detail-aside.d.ts.map +1 -1
- package/dist/components/detail/detail-aside.js +4 -3
- package/dist/components/detail/detail-aside.js.map +1 -1
- package/dist/components/file-image/file-image.js +2 -1
- package/dist/components/file-image/file-image.js.map +1 -1
- package/dist/components/markdown-view/SpoilerSpan.d.ts +28 -0
- package/dist/components/markdown-view/SpoilerSpan.d.ts.map +1 -0
- package/dist/components/markdown-view/SpoilerSpan.js +53 -0
- package/dist/components/markdown-view/SpoilerSpan.js.map +1 -0
- package/dist/components/markdown-view/diagram/layoutSequence.js +13 -23
- package/dist/components/markdown-view/diagram/layoutSequence.js.map +1 -1
- package/dist/components/markdown-view/diagram/textMetrics.js +2 -2
- package/dist/components/markdown-view/diagram/textMetrics.js.map +1 -1
- package/dist/components/markdown-view/markdown-view.css +44 -0
- package/dist/components/markdown-view/markdown-view.d.ts +12 -0
- package/dist/components/markdown-view/markdown-view.d.ts.map +1 -1
- package/dist/components/markdown-view/markdown-view.js +22 -1
- package/dist/components/markdown-view/markdown-view.js.map +1 -1
- package/dist/components/markdown-view/remarkSpoiler.d.ts +17 -0
- package/dist/components/markdown-view/remarkSpoiler.d.ts.map +1 -0
- package/dist/components/markdown-view/remarkSpoiler.js +117 -0
- package/dist/components/markdown-view/remarkSpoiler.js.map +1 -0
- package/dist/components/permission-matrix/permission-matrix-group-rows.d.ts +34 -0
- package/dist/components/permission-matrix/permission-matrix-group-rows.d.ts.map +1 -0
- package/dist/components/permission-matrix/permission-matrix-group-rows.js +109 -0
- package/dist/components/permission-matrix/permission-matrix-group-rows.js.map +1 -0
- package/dist/components/permission-matrix/permission-matrix.d.ts +145 -0
- package/dist/components/permission-matrix/permission-matrix.d.ts.map +1 -0
- package/dist/components/permission-matrix/permission-matrix.js +113 -0
- package/dist/components/permission-matrix/permission-matrix.js.map +1 -0
- package/dist/components/plate-layout/plate-layout.d.ts +5 -0
- package/dist/components/plate-layout/plate-layout.d.ts.map +1 -1
- package/dist/components/plate-layout/plate-layout.js +2 -1
- package/dist/components/plate-layout/plate-layout.js.map +1 -1
- package/dist/components/plate-layout/plate-tab-bar.d.ts +10 -0
- package/dist/components/plate-layout/plate-tab-bar.d.ts.map +1 -1
- package/dist/components/plate-layout/plate-tab-bar.js +1 -1
- package/dist/components/plate-layout/plate-tab-bar.js.map +1 -1
- package/dist/components/settings/settings-nav.js +2 -1
- package/dist/components/settings/settings-nav.js.map +1 -1
- package/dist/components/time-ago/time-ago.d.ts +57 -0
- package/dist/components/time-ago/time-ago.d.ts.map +1 -0
- package/dist/components/time-ago/time-ago.js +60 -0
- package/dist/components/time-ago/time-ago.js.map +1 -0
- package/dist/components/tree-view/tree-model.d.ts +128 -0
- package/dist/components/tree-view/tree-model.d.ts.map +1 -0
- package/dist/components/tree-view/tree-model.js +226 -0
- package/dist/components/tree-view/tree-model.js.map +1 -0
- package/dist/components/tree-view/tree-view-rename-input.d.ts +31 -0
- package/dist/components/tree-view/tree-view-rename-input.d.ts.map +1 -0
- package/dist/components/tree-view/tree-view-rename-input.js +68 -0
- package/dist/components/tree-view/tree-view-rename-input.js.map +1 -0
- package/dist/components/tree-view/tree-view-resizer.d.ts +38 -0
- package/dist/components/tree-view/tree-view-resizer.d.ts.map +1 -0
- package/dist/components/tree-view/tree-view-resizer.js +73 -0
- package/dist/components/tree-view/tree-view-resizer.js.map +1 -0
- package/dist/components/tree-view/tree-view-row.d.ts +177 -0
- package/dist/components/tree-view/tree-view-row.d.ts.map +1 -0
- package/dist/components/tree-view/tree-view-row.js +241 -0
- package/dist/components/tree-view/tree-view-row.js.map +1 -0
- package/dist/components/tree-view/tree-view.d.ts +186 -0
- package/dist/components/tree-view/tree-view.d.ts.map +1 -0
- package/dist/components/tree-view/tree-view.js +112 -0
- package/dist/components/tree-view/tree-view.js.map +1 -0
- package/dist/components/tree-view/use-tree-state.d.ts +79 -0
- package/dist/components/tree-view/use-tree-state.d.ts.map +1 -0
- package/dist/components/tree-view/use-tree-state.js +93 -0
- package/dist/components/tree-view/use-tree-state.js.map +1 -0
- package/dist/components/ui/button.d.ts.map +1 -1
- package/dist/components/ui/button.js +1 -1
- package/dist/components/ui/button.js.map +1 -1
- package/dist/components/ui/dropdown-menu.js.map +1 -1
- package/dist/components/ui/select.d.ts +7 -0
- package/dist/components/ui/select.d.ts.map +1 -1
- package/dist/components/ui/select.js +7 -0
- package/dist/components/ui/select.js.map +1 -1
- package/dist/components/ui/sidebar.js +1 -1
- package/dist/components/ui/sidebar.js.map +1 -1
- package/dist/components/ui/table.js.map +1 -1
- package/dist/components/ui/tooltip.js.map +1 -1
- package/dist/lib/i18n-fr.d.ts.map +1 -1
- package/dist/lib/i18n-fr.js +31 -47
- package/dist/lib/i18n-fr.js.map +1 -1
- package/dist/lib/utils.d.ts +22 -2
- package/dist/lib/utils.d.ts.map +1 -1
- package/dist/lib/utils.js +29 -5
- package/dist/lib/utils.js.map +1 -1
- package/dist/styles.css +255 -0
- package/package.json +13 -14
- package/src/components/account/__tests__/account-router.spec.ts +95 -0
- package/src/components/account/account-connections.tsx +14 -1
- package/src/components/account/account-delete-dialog.tsx +3 -2
- package/src/components/account/account-keys.tsx +11 -4
- package/src/components/account/account-mfa-dialog.tsx +1 -1
- package/src/components/account/account-password-dialog.tsx +3 -2
- package/src/components/account/account-profile.tsx +1 -1
- package/src/components/account/account-router-options.tsx +45 -0
- package/src/components/account/account-router-page.tsx +11 -1
- package/src/components/account/account-router.tsx +23 -6
- package/src/components/admin/__tests__/admin-jobs-payload-dialog.browser.spec.tsx +68 -0
- package/src/components/admin/__tests__/admin-notifications-preview-body.browser.spec.tsx +20 -4
- package/src/components/admin/__tests__/admin-status-labels.browser.spec.tsx +0 -31
- package/src/components/admin/admin-audits.tsx +99 -5
- package/src/components/admin/admin-files.tsx +7 -16
- package/src/components/admin/admin-jobs-executions-panel.tsx +152 -114
- package/src/components/admin/admin-jobs-payload-dialog.tsx +57 -0
- package/src/components/admin/admin-keys.tsx +7 -4
- package/src/components/admin/admin-notifications-channel-label.ts +18 -0
- package/src/components/admin/admin-notifications-preview-body.tsx +7 -2
- package/src/components/admin/admin-notifications.tsx +19 -8
- package/src/components/admin/admin-payments.tsx +7 -4
- package/src/components/admin/admin-router-options.tsx +12 -0
- package/src/components/admin/admin-router.tsx +5 -27
- package/src/components/admin/admin-sessions.tsx +10 -6
- package/src/components/admin/admin-user-detail-audits-tab.tsx +7 -4
- package/src/components/admin/admin-user-detail-sessions-tab.tsx +7 -4
- package/src/components/admin/admin-users-roles-picker.tsx +4 -0
- package/src/components/admin/admin-users.tsx +6 -3
- package/src/components/admin/parameter-history-item.tsx +4 -2
- package/src/components/alepha-table/__tests__/alepha-table-default-hidden.browser.spec.tsx +108 -0
- package/src/components/alepha-table/__tests__/alepha-table-empty-state.browser.spec.tsx +233 -0
- package/src/components/alepha-table/__tests__/alepha-table-persist-facets.browser.spec.tsx +177 -0
- package/src/components/alepha-table/__tests__/alepha-table-persisted-filters.browser.spec.tsx +182 -0
- package/src/components/alepha-table/__tests__/alepha-table-query-seed.browser.spec.tsx +170 -0
- package/src/components/alepha-table/__tests__/alepha-table-row-action-checked.browser.spec.tsx +210 -0
- package/src/components/alepha-table/__tests__/alepha-table-row-action-group.browser.spec.tsx +202 -0
- package/src/components/alepha-table/__tests__/alepha-table-scope.browser.spec.tsx +161 -0
- package/src/components/alepha-table/__tests__/alepha-table-share-filters.browser.spec.tsx +309 -0
- package/src/components/alepha-table/__tests__/query-filters.spec.ts +212 -0
- package/src/components/alepha-table/alepha-table-filter-dialog.tsx +162 -0
- package/src/components/alepha-table/alepha-table-filter-menu.tsx +77 -0
- package/src/components/alepha-table/alepha-table.tsx +1113 -207
- package/src/components/alepha-table/query-filters.ts +159 -0
- package/src/components/app-actions/app-actions.tsx +32 -3
- package/src/components/app-shell/__tests__/sidebar-nav-accordion.browser.spec.tsx +163 -0
- package/src/components/app-shell/app-shell.tsx +255 -12
- package/src/components/auto-form/__tests__/auto-form-settings-card.browser.spec.tsx +1 -1
- package/src/components/auto-form/auto-form.tsx +98 -30
- package/src/components/button-dark/button-dark.tsx +47 -8
- package/src/components/button-inbox/__tests__/button-inbox.browser.spec.tsx +247 -0
- package/src/components/button-inbox/button-inbox.tsx +303 -0
- package/src/components/button-inbox/inbox-unread-atom.ts +27 -0
- package/src/components/button-theme/button-theme.tsx +16 -29
- package/src/components/button-user/__tests__/button-user-avatar.browser.spec.tsx +88 -0
- package/src/components/button-user/button-user.tsx +24 -1
- package/src/components/control/__tests__/control-date-range.browser.spec.tsx +177 -0
- package/src/components/control/control.tsx +119 -12
- package/src/components/control-date/control-date.tsx +117 -22
- package/src/components/control-date/date-only.ts +26 -0
- package/src/components/control-date-range/control-date-range.tsx +250 -0
- package/src/components/control-select/__tests__/control-select-clear-label.browser.spec.tsx +129 -15
- package/src/components/control-select/__tests__/control-select-deselect.browser.spec.tsx +27 -6
- package/src/components/control-select/__tests__/control-select-multi.browser.spec.tsx +204 -1
- package/src/components/control-select/__tests__/control-select-size-minimal.browser.spec.tsx +77 -1
- package/src/components/control-select/control-select.tsx +317 -83
- package/src/components/control-upload/control-upload.tsx +1 -10
- package/src/components/detail/detail-aside.tsx +30 -6
- package/src/components/markdown-view/SpoilerSpan.tsx +66 -0
- package/src/components/markdown-view/__tests__/markdown-view-spoiler.browser.spec.tsx +165 -0
- package/src/components/markdown-view/diagram/textMetrics.spec.ts +1 -1
- package/src/components/markdown-view/diagram/textMetrics.ts +2 -2
- package/src/components/markdown-view/markdown-view.css +44 -0
- package/src/components/markdown-view/markdown-view.tsx +37 -1
- package/src/components/markdown-view/remarkSpoiler.ts +150 -0
- package/src/components/permission-matrix/__tests__/permission-matrix.browser.spec.tsx +237 -0
- package/src/components/permission-matrix/permission-matrix-group-rows.tsx +240 -0
- package/src/components/permission-matrix/permission-matrix.tsx +286 -0
- package/src/components/plate-layout/__tests__/plate-layout.browser.spec.tsx +22 -0
- package/src/components/plate-layout/plate-layout.tsx +6 -0
- package/src/components/plate-layout/plate-tab-bar.tsx +27 -1
- package/src/components/time-ago/time-ago.browser.spec.tsx +110 -0
- package/src/components/time-ago/time-ago.tsx +80 -0
- package/src/components/tree-view/__tests__/tree-model.spec.ts +441 -0
- package/src/components/tree-view/__tests__/tree-view-drag.browser.spec.tsx +295 -0
- package/src/components/tree-view/__tests__/tree-view-rename.browser.spec.tsx +278 -0
- package/src/components/tree-view/__tests__/tree-view-resizer.browser.spec.tsx +112 -0
- package/src/components/tree-view/__tests__/tree-view.browser.spec.tsx +260 -0
- package/src/components/tree-view/__tests__/use-tree-state.browser.spec.tsx +238 -0
- package/src/components/tree-view/tree-model.ts +369 -0
- package/src/components/tree-view/tree-view-rename-input.tsx +95 -0
- package/src/components/tree-view/tree-view-resizer.tsx +83 -0
- package/src/components/tree-view/tree-view-row.tsx +414 -0
- package/src/components/tree-view/tree-view.tsx +300 -0
- package/src/components/tree-view/use-tree-state.ts +184 -0
- package/src/components/ui/button.tsx +79 -1
- package/src/components/ui/dropdown-menu.tsx +1 -1
- package/src/components/ui/select.tsx +7 -0
- package/src/components/ui/table.tsx +1 -1
- package/src/components/ui/tooltip.tsx +1 -1
- package/src/lib/i18n-fr.ts +34 -51
- package/src/lib/utils.ts +32 -4
- package/src/styles.css +255 -0
- package/dist/components/admin/admin-workflows-execution-sheet.d.ts +0 -11
- package/dist/components/admin/admin-workflows-execution-sheet.d.ts.map +0 -1
- package/dist/components/admin/admin-workflows-execution-sheet.js +0 -190
- package/dist/components/admin/admin-workflows-execution-sheet.js.map +0 -1
- package/dist/components/admin/admin-workflows-executions-panel.d.ts +0 -9
- package/dist/components/admin/admin-workflows-executions-panel.d.ts.map +0 -1
- package/dist/components/admin/admin-workflows-executions-panel.js +0 -121
- package/dist/components/admin/admin-workflows-executions-panel.js.map +0 -1
- package/dist/components/admin/admin-workflows-status-badge.d.ts +0 -12
- package/dist/components/admin/admin-workflows-status-badge.d.ts.map +0 -1
- package/dist/components/admin/admin-workflows-status-badge.js +0 -30
- package/dist/components/admin/admin-workflows-status-badge.js.map +0 -1
- package/dist/components/admin/admin-workflows-status-labels.d.ts +0 -19
- package/dist/components/admin/admin-workflows-status-labels.d.ts.map +0 -1
- package/dist/components/admin/admin-workflows-status-labels.js +0 -48
- package/dist/components/admin/admin-workflows-status-labels.js.map +0 -1
- package/dist/components/admin/admin-workflows.d.ts +0 -4
- package/dist/components/admin/admin-workflows.d.ts.map +0 -1
- package/dist/components/admin/admin-workflows.js +0 -145
- package/dist/components/admin/admin-workflows.js.map +0 -1
- package/src/components/admin/admin-workflows-execution-sheet.tsx +0 -285
- package/src/components/admin/admin-workflows-executions-panel.tsx +0 -169
- package/src/components/admin/admin-workflows-status-badge.tsx +0 -41
- package/src/components/admin/admin-workflows-status-labels.ts +0 -51
- package/src/components/admin/admin-workflows.tsx +0 -209
|
@@ -4,6 +4,7 @@ import { FormField, formFieldAriaProps, useFormFieldAutoSave, useFormFieldLayout
|
|
|
4
4
|
import { ControlPassword } from "../control-password/control-password.js";
|
|
5
5
|
import { iconFor } from "../control-base/icon-hint.js";
|
|
6
6
|
import { ControlArray } from "../control-array/control-array.js";
|
|
7
|
+
import { ControlDateRange } from "../control-date-range/control-date-range.js";
|
|
7
8
|
import { ControlDate } from "../control-date/control-date.js";
|
|
8
9
|
import { ControlNumber } from "../control-number/control-number.js";
|
|
9
10
|
import { ControlObject } from "../control-object/control-object.js";
|
|
@@ -40,7 +41,7 @@ const Control = (props) => {
|
|
|
40
41
|
form: props.input.form,
|
|
41
42
|
value
|
|
42
43
|
});
|
|
43
|
-
if (resolved === null) return null;
|
|
44
|
+
if (resolved === null || resolved.hidden) return null;
|
|
44
45
|
const merged = {
|
|
45
46
|
...props,
|
|
46
47
|
...resolved
|
|
@@ -102,6 +103,15 @@ const Control = (props) => {
|
|
|
102
103
|
disabled: merged.disabled,
|
|
103
104
|
autoFocus: merged.autoFocus
|
|
104
105
|
}));
|
|
106
|
+
if (merged.dateRange || meta.format === "date-range") return wrapWithSlots(merged, /* @__PURE__ */ jsx(ControlDateRange, {
|
|
107
|
+
input: props.input,
|
|
108
|
+
label: merged.label ?? props.label,
|
|
109
|
+
description: merged.description ?? props.description,
|
|
110
|
+
disabled: merged.disabled,
|
|
111
|
+
clearable: merged.clearable,
|
|
112
|
+
placeholder: merged.placeholder,
|
|
113
|
+
triggerClassName: merged.triggerClassName
|
|
114
|
+
}));
|
|
105
115
|
if (merged.select || merged.combobox || merged.segmented || meta.isEnum || meta.isArray && !meta.isArrayOfObjects || items != null) return wrapWithSlots(merged, /* @__PURE__ */ jsx(ControlSelect, {
|
|
106
116
|
input: props.input,
|
|
107
117
|
label: merged.label ?? props.label,
|
|
@@ -147,7 +157,11 @@ const Control = (props) => {
|
|
|
147
157
|
datetime: merged.datetime,
|
|
148
158
|
time: merged.time,
|
|
149
159
|
disabled: merged.disabled,
|
|
150
|
-
clearable: merged.clearable
|
|
160
|
+
clearable: merged.clearable,
|
|
161
|
+
captionLayout: merged.captionLayout,
|
|
162
|
+
startMonth: merged.startMonth,
|
|
163
|
+
endMonth: merged.endMonth,
|
|
164
|
+
birthdate: merged.birthdate
|
|
151
165
|
}));
|
|
152
166
|
if (merged.file) return wrapWithSlots(merged, /* @__PURE__ */ jsx(FormField, {
|
|
153
167
|
id: meta.id,
|
|
@@ -246,7 +260,14 @@ const Control = (props) => {
|
|
|
246
260
|
maxLength: meta.constraints.maxLength,
|
|
247
261
|
pattern: meta.constraints.pattern,
|
|
248
262
|
className: cn(rowLayout && "sm:w-64", merged.inputProps?.className, Icon && "pl-9", reserveGutter && "pr-9"),
|
|
249
|
-
onChange: (e) => setValue(e.target.value)
|
|
263
|
+
onChange: (e) => setValue(e.target.value),
|
|
264
|
+
onKeyDown: (e) => {
|
|
265
|
+
merged.inputProps?.onKeyDown?.(e);
|
|
266
|
+
if (e.defaultPrevented || e.key !== "Enter") return;
|
|
267
|
+
if (!showSave) return;
|
|
268
|
+
e.preventDefault();
|
|
269
|
+
props.input.form.submit();
|
|
270
|
+
}
|
|
250
271
|
}),
|
|
251
272
|
showSave && /* @__PURE__ */ jsx("button", {
|
|
252
273
|
type: "button",
|
|
@@ -266,10 +287,33 @@ const Control = (props) => {
|
|
|
266
287
|
})
|
|
267
288
|
}));
|
|
268
289
|
};
|
|
290
|
+
/**
|
|
291
|
+
* The raw `$control` a field declares, object form or function form.
|
|
292
|
+
*
|
|
293
|
+
* It rides on zod's `.meta()` registry rather than being a plain schema
|
|
294
|
+
* property, and the field may be wrapped (optional / nullable / default), so
|
|
295
|
+
* the wrapper has to be peeled before the meta is readable.
|
|
296
|
+
*
|
|
297
|
+
* Exported because the LAYOUT needs it too: `AutoForm` sizes a grid cell from
|
|
298
|
+
* the width `$control` asks for, and a function-form `$control` has no `.width`
|
|
299
|
+
* to read off the function itself. Pair it with {@link resolveSchemaControl}.
|
|
300
|
+
*/
|
|
301
|
+
const readSchemaControl = (input) => {
|
|
302
|
+
return (input?.schema ? z.schema.unwrap(input.schema) : void 0)?.meta?.()?.$control;
|
|
303
|
+
};
|
|
304
|
+
/**
|
|
305
|
+
* Re-render when a function-form `$control` may have changed its mind, which
|
|
306
|
+
* is on any change to a field OTHER than this one. An object-form `$control`
|
|
307
|
+
* is static and needs no subscription.
|
|
308
|
+
*
|
|
309
|
+
* Exported alongside {@link readSchemaControl}, and for the same reason: a
|
|
310
|
+
* consumer that resolves `$control` itself has to re-resolve on the same
|
|
311
|
+
* events, or it renders a stale answer.
|
|
312
|
+
*/
|
|
269
313
|
const useDynamicControlRefresh = (input) => {
|
|
270
314
|
const alepha = useAlepha();
|
|
271
315
|
const [, bump] = useState(0);
|
|
272
|
-
const isDynamic = typeof (input
|
|
316
|
+
const isDynamic = typeof readSchemaControl(input) === "function";
|
|
273
317
|
useEffect(() => {
|
|
274
318
|
if (!isDynamic || !input?.form) return;
|
|
275
319
|
const formId = input.form.id;
|
|
@@ -303,6 +347,6 @@ const wrapWithSlots = (props, body) => {
|
|
|
303
347
|
});
|
|
304
348
|
};
|
|
305
349
|
//#endregion
|
|
306
|
-
export { Control };
|
|
350
|
+
export { Control, readSchemaControl, useDynamicControlRefresh };
|
|
307
351
|
|
|
308
352
|
//# sourceMappingURL=control.js.map
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"control.js","names":[],"sources":["../../../src/components/control/control.tsx"],"sourcesContent":["import * as React from \"react\";\n\nvoid React;\n\nimport {\n ControlArray,\n type ControlArrayProps,\n} from \"@alepha/ui/components/control-array/control-array\";\nimport {\n FormField,\n formFieldAriaProps,\n useFormFieldAutoSave,\n useFormFieldLayout,\n} from \"@alepha/ui/components/control-base/form-field\";\nimport {\n type IconComponent,\n iconFor,\n} from \"@alepha/ui/components/control-base/icon-hint\";\nimport { ControlDate } from \"@alepha/ui/components/control-date/control-date\";\nimport { ControlNumber } from \"@alepha/ui/components/control-number/control-number\";\nimport { ControlObject } from \"@alepha/ui/components/control-object/control-object\";\nimport { ControlPassword } from \"@alepha/ui/components/control-password/control-password\";\nimport {\n ControlSelect,\n type ControlSelectSize,\n type SelectOption,\n} from \"@alepha/ui/components/control-select/control-select\";\nimport {\n ControlUpload,\n type ControlUploadProps,\n} from \"@alepha/ui/components/control-upload/control-upload\";\nimport { Input } from \"@alepha/ui/components/ui/input\";\nimport { Switch } from \"@alepha/ui/components/ui/switch\";\nimport { Textarea } from \"@alepha/ui/components/ui/textarea\";\nimport { cn } from \"@alepha/ui/lib/utils\";\nimport { z } from \"alepha\";\nimport { useAlepha } from \"alepha/react\";\nimport {\n type BaseInputField,\n parseField,\n useFieldValue,\n useFormState,\n} from \"alepha/react/form\";\nimport { resolveSchemaControl, type SchemaControl } from \"alepha/react/ui\";\nimport { Check, X } from \"lucide-react\";\nimport {\n type ComponentType,\n type HTMLAttributes,\n type ReactNode,\n useEffect,\n useState,\n} from \"react\";\n\nexport interface ControlProps {\n /**\n * Bound `InputField` from `useForm`. Carries value, schema, and error state.\n */\n input: BaseInputField;\n /**\n * Field label. Falls back to schema `title` or the field name.\n */\n label?: string;\n /**\n * Helper text shown below the control. Falls back to schema `description`.\n */\n description?: string;\n /**\n * Force a specific input variant — renders a single-line text input.\n */\n text?: boolean;\n /**\n * Force a textarea.\n */\n area?: boolean;\n /**\n * Force a masked password input.\n */\n password?: boolean;\n /**\n * Force a `<Switch>` (boolean toggle).\n */\n switch?: boolean;\n /**\n * Force a numeric input.\n */\n number?: boolean;\n /**\n * Force the file-upload control (alias for `upload`).\n */\n file?: boolean;\n /**\n * Force a date picker.\n */\n date?: boolean;\n /**\n * Force a date-time picker.\n */\n datetime?: boolean;\n /**\n * Force a time picker.\n */\n time?: boolean;\n /**\n * Force a `<Select>`.\n */\n select?: boolean;\n /**\n * Force a combobox (searchable select). Alias for `searchable: true`.\n */\n combobox?: boolean;\n /**\n * Force the select's search input on or off. Defaults to \"auto\" — on for an\n * async list, when `createNewEntry` is set, or above ~50 options.\n */\n searchable?: boolean;\n /**\n * Force a `<Segmented>` control (one option visible at a time).\n */\n segmented?: boolean;\n /**\n * Force a slider (numeric only).\n */\n slider?: boolean;\n /**\n * Force a nested `<ControlObject>` for object-typed schemas.\n */\n object?: boolean;\n /**\n * Force a nested `<ControlArray>` for array-typed schemas.\n */\n array?: boolean;\n /**\n * Props forwarded to the nested `<ControlObject>`, keyed by child field name.\n * This is the only way to reach INSIDE an object field — without it a caller\n * can style/override the object as a whole but never one of its children\n * (e.g. attaching a `custom` widget to `payg.zoneFareCents`).\n */\n /**\n * Dictionary prefix for schema-generated labels/help: this field reads\n * `<prefix>.<name>` and `<prefix>.<name>.desc`, and passes the extended\n * prefix down into nested objects and array items.\n */\n i18nPrefix?: string;\n objectProps?: {\n controlProps?: Record<string, Partial<Omit<ControlProps, \"input\">>>;\n variant?: \"fieldset\" | \"plain\";\n defaultExpanded?: boolean;\n };\n /**\n * Custom render component receiving `{value, onChange}`.\n */\n custom?: ComponentType<{ value: unknown; onChange: (v: unknown) => void }>;\n /**\n * Override icon — pass `null` to remove the schema-inferred icon.\n */\n icon?: IconComponent | string | null;\n /**\n * Disable the control.\n */\n disabled?: boolean;\n /**\n * Render slot before the control.\n */\n top?: ReactNode;\n /**\n * Render slot after the control.\n */\n bottom?: ReactNode;\n /**\n * Width slot inside an `<AutoForm>` group (mapped to a CSS grid column\n * span). Read by the parent group; ignored when rendering standalone.\n */\n width?: 100 | 75 | 66 | 50 | 33 | 25;\n /**\n * HTML `autocomplete` hint passed to the underlying input.\n */\n autoComplete?: string;\n /**\n * Placeholder text. On a text-shaped control this is the HTML\n * `placeholder`; on a select it is the trigger text shown while nothing is\n * picked.\n */\n placeholder?: string;\n /**\n * Autofocus the control on mount. Forwarded to the text, number, password\n * or textarea input the control renders. Ignored by the variants that are\n * not a single focusable field (select, date, upload, array, object).\n *\n * Every forward site carries an `oxlint-disable-next-line\n * jsx-a11y/no-autofocus`. That rule is right about a page that grabs focus\n * unbidden and wrong here: nothing focuses unless a caller passed this prop,\n * and it is the caller the rule should be asking. Left to fire, it did real\n * damage once - a lint pass deleted the forwarding and left the prop\n * declared, so login and dialog forms silently stopped focusing their first\n * field and two components grew `getElementById(...).focus()` workarounds.\n */\n autoFocus?: boolean;\n /**\n * Visible row count for the textarea variant. Overrides the value\n * auto-derived from the schema's `maxLength`. Ignored by other variants.\n */\n rows?: number;\n /**\n * Escape hatch — extra native attributes (event handlers, `className`,\n * `aria-*`, `data-*`, `style`, …) forwarded to whichever element the\n * control actually renders (text input / textarea / password input). The\n * form bindings (`value`, `onChange`, `id`, `name`) always win and cannot\n * be overridden here.\n *\n * `data-*` is spelled out because `HTMLAttributes` does not carry it:\n * TypeScript special-cases dashed attributes in JSX only, so an object\n * literal `{ \"data-testid\": … }` is an excess property and fails to\n * compile. Without this a control cannot carry a test hook, which meant a\n * surface with an e2e had to keep a raw `<input>` rather than adopt the\n * shared control.\n */\n inputProps?: HTMLAttributes<HTMLElement> & {\n [attribute: `data-${string}`]: string | number | boolean | undefined;\n };\n /**\n * Allow user to create new entries in select / multi-select.\n */\n createNewEntry?: boolean | ((query: string) => unknown);\n /**\n * Inline option list for select / combobox controls. Infer array or\n * async loader. Overrides schema-derived `enum` when present.\n */\n items?:\n | SelectOption[]\n | ((query: string) => SelectOption[] | Promise<SelectOption[]>);\n /**\n * Whether the field offers a way back to empty.\n *\n * On a `ControlSelect`, `true` adds a synthetic \"none\" row that resets the\n * field to `undefined` — use it for optional filter chips.\n *\n * On a text field the affordance is the opposite way round: an optional\n * field already shows a clear (×) button whenever it holds a value, and\n * `false` takes it away. Pass `false` when emptying the field is not\n * something the API can honour — a username has no \"unset\" on the server,\n * so offering the button would promise an edit that silently does nothing.\n */\n clearable?: boolean;\n /**\n * Forwarded to `ControlSelect` — label of the `clearable` row, also\n * used as the empty-state trigger placeholder. Defaults to \"None\".\n */\n clearLabel?: string;\n /**\n * Trigger text for a multi-select holding two or more values, e.g.\n * `(n) => \\`${n} status\\``. One selection always shows the value itself, so\n * this is only ever asked for the collapsed case. Defaults to\n * `\"{n} selected\"`.\n */\n countLabel?: (count: number) => string;\n /**\n * Forwarded to `ControlSelect` — extra className on the trigger.\n * Useful for sizing filter chips inline.\n */\n triggerClassName?: string;\n /**\n * Trigger height and type scale, for the select-shaped controls. Defaults\n * to `default`; `xs` is for a control that sits ON a row of text rather\n * than in a form.\n */\n size?: ControlSelectSize;\n /**\n * Render the select trigger borderless and transparent, so it reads as the\n * row it sits on rather than as a form field. Pairs with `size=\"xs\"`.\n */\n minimal?: boolean;\n /**\n * Render a managed upload control (image preview, multi, drag-drop)\n * that calls `FileController.uploadFile` and stores the file ID(s) in\n * the form value. Pass `true` for defaults or an options object.\n */\n upload?:\n | boolean\n | Pick<\n ControlUploadProps,\n \"multi\" | \"accept\" | \"maxSize\" | \"bucket\" | \"image\"\n >;\n}\n\n/**\n * Schema-driven form field renderer. Inspects the bound `InputField` from\n * `useForm`, evaluates `schema.$control` (object or function), merges the\n * result with explicit props, and dispatches to the right sub-control.\n */\nexport const Control = (props: ControlProps) => {\n const form = useFormState(props.input, [\"error\", \"dirty\"]);\n const autoSaveEnabled = useFormFieldAutoSave();\n const rowLayout = useFormFieldLayout() === \"row\";\n const [value, setValue] = useFieldValue(props.input);\n\n // Function-form `$control` reads other fields → re-render on any\n // change. Infer `$control` (object) does not need this subscription.\n useDynamicControlRefresh(props.input);\n\n if (!props.input?.props) return null;\n\n const meta = parseField(props.input, {\n label: props.label,\n description: props.description,\n error: form.error,\n });\n\n // ── Resolve $control (object | function | false) ─────────────────\n const resolved = resolveSchemaControl(meta.control, {\n form: props.input.form,\n value,\n });\n if (resolved === null) return null;\n\n const merged = {\n ...props,\n ...(resolved as Partial<ControlProps>),\n } as ControlProps & Partial<SchemaControl>;\n\n // ── Custom escape hatch ──────────────────────────────────────────\n if (merged.custom) {\n const Custom = merged.custom;\n return wrapWithSlots(\n merged,\n <FormField\n id={meta.id}\n label={merged.label ?? meta.label}\n description={merged.description ?? meta.description}\n error={meta.error}\n required={meta.required}\n >\n <Custom value={value} onChange={(v) => setValue(v)} />\n </FormField>,\n );\n }\n\n // ── Recursive: object / array of objects ─────────────────────────\n if (merged.object || meta.isObject) {\n return wrapWithSlots(\n merged,\n <ControlObject\n input={props.input}\n label={merged.label ?? props.label}\n description={merged.description ?? props.description}\n disabled={merged.disabled}\n i18nPrefix={merged.i18nPrefix}\n controlProps={merged.objectProps?.controlProps}\n variant={merged.objectProps?.variant}\n defaultExpanded={merged.objectProps?.defaultExpanded}\n clearable={merged.clearable}\n />,\n );\n }\n if (merged.array || meta.isArrayOfObjects) {\n const arrayProps = (merged as { arrayProps?: Record<string, unknown> })\n .arrayProps;\n return wrapWithSlots(\n merged,\n <ControlArray\n input={props.input}\n i18nPrefix={merged.i18nPrefix}\n label={merged.label ?? props.label}\n description={merged.description ?? props.description}\n disabled={merged.disabled}\n confirmDelete={\n arrayProps?.confirmDelete as ControlArrayProps[\"confirmDelete\"]\n }\n renderTabName={\n arrayProps?.renderTabName as ControlArrayProps[\"renderTabName\"]\n }\n forceTabs={arrayProps?.forceTabs as boolean | undefined}\n />,\n );\n }\n\n // ── File: managed upload (image preview, multi, drag-drop) ──────\n // Checked early so it wins over the array→combobox branch below\n // when the schema is `z.array(z.string())` with $control.upload.\n if (merged.upload) {\n const uploadOpts =\n typeof merged.upload === \"object\"\n ? (merged.upload as Partial<ControlUploadProps>)\n : {};\n return wrapWithSlots(\n merged,\n <ControlUpload\n input={props.input}\n label={merged.label ?? props.label}\n description={merged.description ?? props.description}\n disabled={merged.disabled}\n {...uploadOpts}\n />,\n );\n }\n\n // ── Items provided → select / multi / combobox ───────────────────\n // Read before the numeric branch, because that branch owns every numeric\n // schema by default and `ControlNumber` has nowhere to put an option list:\n // a `z.number()` field handed `items` used to render a bare spinner and drop\n // the rows on the floor, silently. An explicit list is an explicit request\n // for a select, so it wins - `slider` / `number` still override it below.\n const items = (merged as Record<string, unknown>).items as\n | undefined\n | unknown[]\n | ((q: string) => unknown);\n\n // ── Number / slider ──────────────────────────────────────────────\n if (\n merged.slider ||\n merged.number ||\n (!merged.select &&\n !merged.segmented &&\n !merged.combobox &&\n items == null &&\n (meta.type === \"number\" || meta.type === \"integer\"))\n ) {\n return wrapWithSlots(\n merged,\n <ControlNumber\n input={props.input}\n label={merged.label ?? props.label}\n description={merged.description ?? props.description}\n slider={merged.slider}\n disabled={merged.disabled}\n // oxlint-disable-next-line jsx-a11y/no-autofocus\n autoFocus={merged.autoFocus}\n />,\n );\n }\n\n if (\n merged.select ||\n merged.combobox ||\n merged.segmented ||\n meta.isEnum ||\n (meta.isArray && !meta.isArrayOfObjects) ||\n items != null\n ) {\n return wrapWithSlots(\n merged,\n <ControlSelect\n input={props.input}\n label={merged.label ?? props.label}\n description={merged.description ?? props.description}\n segmented={merged.segmented}\n combobox={merged.combobox}\n searchable={merged.searchable}\n items={items as never}\n icon={resolveIcon(merged.icon)}\n disabled={merged.disabled}\n createNewEntry={\n merged.createNewEntry as boolean | ((q: string) => never) | undefined\n }\n clearable={merged.clearable}\n clearLabel={merged.clearLabel}\n countLabel={merged.countLabel}\n // Dropped here until now, so a picker that needed to name its own\n // empty state (\"Pick an epic…\") could not be a `Control` at all.\n placeholder={merged.placeholder}\n triggerClassName={merged.triggerClassName}\n size={merged.size}\n minimal={merged.minimal}\n // Used to be dropped here, silently: every `inputProps={{ \"aria-label\"\n // }}` on a select-shaped Control (the epics and quests status filters\n // among them) named nothing at all, because the trigger is a button\n // with no visible label to borrow a name from.\n triggerProps={merged.inputProps}\n />,\n );\n }\n\n // ── Boolean → switch ─────────────────────────────────────────────\n if (meta.type === \"boolean\" && merged.switch !== false) {\n return wrapWithSlots(\n merged,\n <FormField\n id={meta.id}\n label={merged.label ?? meta.label}\n description={merged.description ?? meta.description}\n error={meta.error}\n required={meta.required}\n >\n <div className=\"flex h-9 items-center\">\n <Switch\n id={meta.id}\n // Same omission as the numeric control had: without a name the\n // toggle is invisible to `[name=\"…\"]` lookups, including\n // `AutoForm`'s scroll-to-first-error.\n name={props.input.props.name}\n disabled={merged.disabled}\n checked={Boolean(value)}\n onCheckedChange={(v) => setValue(v)}\n />\n </div>\n </FormField>,\n );\n }\n\n // ── Date / time ──────────────────────────────────────────────────\n if (\n merged.date ||\n merged.datetime ||\n merged.time ||\n meta.format === \"date\" ||\n meta.format === \"date-time\" ||\n meta.format === \"time\"\n ) {\n return wrapWithSlots(\n merged,\n <ControlDate\n input={props.input}\n label={merged.label ?? props.label}\n description={merged.description ?? props.description}\n date={merged.date}\n datetime={merged.datetime}\n time={merged.time}\n disabled={merged.disabled}\n clearable={merged.clearable}\n />,\n );\n }\n\n // ── File (raw) ───────────────────────────────────────────────────\n if (merged.file) {\n return wrapWithSlots(\n merged,\n <FormField\n id={meta.id}\n label={merged.label ?? meta.label}\n description={merged.description ?? meta.description}\n error={meta.error}\n required={meta.required}\n >\n <Input\n id={meta.id}\n name={props.input.props.name}\n type=\"file\"\n disabled={merged.disabled}\n onChange={(e) => setValue(e.target.files?.[0])}\n />\n </FormField>,\n );\n }\n\n // ── Auto-textarea: explicit `area` or maxLength > 256 ────────────\n const maxLength = meta.constraints.maxLength ?? 0;\n if (merged.area || maxLength > 256) {\n const rows =\n merged.rows ?? (maxLength > 1024 ? 6 : maxLength > 512 ? 4 : 2);\n return wrapWithSlots(\n merged,\n <FormField\n id={meta.id}\n label={merged.label ?? meta.label}\n description={merged.description ?? meta.description}\n error={meta.error}\n required={meta.required}\n >\n <Textarea\n {...merged.inputProps}\n {...formFieldAriaProps({\n id: meta.id,\n error: meta.error,\n description: merged.description ?? meta.description,\n required: meta.required,\n })}\n id={meta.id}\n name={props.input.props.name}\n rows={rows}\n disabled={merged.disabled}\n maxLength={maxLength || undefined}\n autoComplete={merged.autoComplete}\n // oxlint-disable-next-line jsx-a11y/no-autofocus\n autoFocus={merged.autoFocus}\n placeholder={merged.placeholder}\n value={String(value ?? \"\")}\n onChange={(e) => setValue(e.target.value)}\n />\n </FormField>,\n );\n }\n\n // ── Password ─────────────────────────────────────────────────────\n const isPassword =\n merged.password ||\n meta.iconHint === \"password\" ||\n meta.format === \"password\";\n if (isPassword) {\n return wrapWithSlots(\n merged,\n <ControlPassword\n id={meta.id}\n name={props.input.props.name}\n label={merged.label ?? meta.label}\n description={merged.description ?? meta.description}\n error={meta.error}\n required={meta.required}\n disabled={merged.disabled}\n autoComplete={merged.autoComplete}\n // oxlint-disable-next-line jsx-a11y/no-autofocus\n autoFocus={merged.autoFocus}\n inputProps={merged.inputProps}\n icon={resolveIcon(merged.icon, \"password\")}\n value={String(value ?? \"\")}\n onChange={(v) => setValue(v)}\n />,\n );\n }\n\n // ── Default text input with format-driven HTML5 type + icon ──────\n const Icon = resolveIcon(merged.icon, meta.iconHint);\n const htmlType =\n meta.format === \"email\"\n ? \"email\"\n : meta.format === \"url\" || meta.format === \"uri\"\n ? \"url\"\n : meta.format === \"tel\" || meta.format === \"phone\"\n ? \"tel\"\n : \"text\";\n\n // Derive a sensible HTML `autocomplete` hint from the schema format so\n // password managers and browser autofill behave correctly out of the box.\n // Explicit `autoComplete` prop always wins.\n const autoCompleteFromFormat =\n meta.format === \"email\"\n ? \"email\"\n : meta.format === \"tel\" || meta.format === \"phone\"\n ? \"tel\"\n : meta.format === \"url\" || meta.format === \"uri\"\n ? \"url\"\n : undefined;\n const autoComplete = merged.autoComplete ?? autoCompleteFromFormat;\n\n // ── Right-side affordance: tick (when dirty) or clear (when nullable) ─\n // Tick only renders inside an `<AutoForm autoSave>` tree (or any caller\n // that explicitly wraps with `<FormFieldAutoSaveProvider value>`).\n const showSave = autoSaveEnabled && !!form.dirty && !merged.disabled;\n const isNullable =\n !meta.required && value != null && value !== \"\" && !merged.disabled;\n // `clearable !== false`, not `clearable === true`: an optional text field\n // offers the button by default and a caller opts *out* of it. See the prop.\n const showClear = !showSave && isNullable && merged.clearable !== false;\n // Reserve a fixed right gutter for any editable field so the tick/clear\n // can swap in without nudging the input width.\n const reserveGutter = !merged.disabled;\n\n return wrapWithSlots(\n merged,\n <FormField\n id={meta.id}\n label={merged.label ?? meta.label}\n description={merged.description ?? meta.description}\n error={meta.error}\n required={meta.required}\n >\n <div className=\"relative\">\n {Icon && (\n <Icon className=\"text-muted-foreground pointer-events-none absolute top-1/2 left-3 size-4 -translate-y-1/2\" />\n )}\n <Input\n {...merged.inputProps}\n {...formFieldAriaProps({\n id: meta.id,\n error: meta.error,\n description: merged.description ?? meta.description,\n required: meta.required,\n })}\n id={meta.id}\n name={props.input.props.name}\n type={htmlType}\n disabled={merged.disabled}\n autoComplete={autoComplete}\n // oxlint-disable-next-line jsx-a11y/no-autofocus\n autoFocus={merged.autoFocus}\n placeholder={merged.placeholder}\n value={String(value ?? \"\")}\n minLength={meta.constraints.minLength}\n maxLength={meta.constraints.maxLength}\n pattern={meta.constraints.pattern}\n // `cn`, not a plain join: the settings width below has to be\n // overridable by the caller, and only tailwind-merge can decide\n // that `sm:w-96` beats `sm:w-64` rather than both landing on the\n // element. Order is precedence — later wins.\n className={cn(\n // Row layout is the settings-card shape, whose right-hand cell is\n // an `auto` grid column: `w-full` there resolves against the\n // input's own intrinsic size (~172px), so every card would get a\n // slightly different control column. 256px is the width every\n // hand-written `SettingsRow` already passes; encoded once here.\n // Below `sm` the row stacks, and `w-full` from `<Input>` is right.\n rowLayout && \"sm:w-64\",\n merged.inputProps?.className,\n Icon && \"pl-9\",\n reserveGutter && \"pr-9\",\n )}\n onChange={(e) => setValue(e.target.value)}\n />\n {showSave && (\n <button\n type=\"button\"\n onClick={() => props.input.form.submit()}\n aria-label=\"Save\"\n className=\"text-primary hover:text-primary/80 absolute top-1/2 right-2 -translate-y-1/2 p-1\"\n >\n <Check className=\"size-3.5\" />\n </button>\n )}\n {showClear && (\n <button\n type=\"button\"\n onClick={() => setValue(undefined)}\n aria-label=\"Clear\"\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 </FormField>,\n );\n};\n\nconst useDynamicControlRefresh = (input: BaseInputField | undefined) => {\n const alepha = useAlepha();\n const [, bump] = useState(0);\n // Function-form `$control` rides on zod's `.meta()` registry (not a plain\n // schema property), and the field may be wrapped (optional/nullable), so peel\n // to the inner schema before reading its meta to detect the dynamic case.\n const base = input?.schema ? z.schema.unwrap(input.schema) : undefined;\n const rawControl = (\n base as { meta?: () => { $control?: unknown } } | undefined\n )?.meta?.()?.$control;\n const isDynamic = typeof rawControl === \"function\";\n useEffect(() => {\n if (!isDynamic || !input?.form) return;\n const formId = input.form.id;\n return alepha.events.on(\"form:change\", (e) => {\n if (e.id === formId && e.path !== input.path) bump((n) => n + 1);\n });\n }, [alepha, input?.form, input?.path, isDynamic]);\n};\n\nconst resolveIcon = (\n icon: ControlProps[\"icon\"],\n fallback?: string | null,\n): IconComponent | undefined => {\n if (icon === null) return undefined;\n if (typeof icon === \"string\") return iconFor(icon);\n if (icon) return icon;\n return iconFor(fallback);\n};\n\nconst wrapWithSlots = (\n props: ControlProps & Partial<SchemaControl>,\n body: ReactNode,\n): ReactNode => {\n const top = (props.top as ReactNode) ?? null;\n const bottom = (props.bottom as ReactNode) ?? null;\n if (!top && !bottom) return body;\n return (\n <div className=\"flex flex-col gap-1\">\n {top}\n {body}\n {bottom}\n </div>\n );\n};\n"],"mappings":";;;;;;;;;;;;;;;;;;;;;;;;;;AAiSA,MAAa,WAAW,UAAwB;CAC9C,MAAM,OAAO,aAAa,MAAM,OAAO,CAAC,SAAS,OAAO,CAAC;CACzD,MAAM,kBAAkB,qBAAqB;CAC7C,MAAM,YAAY,mBAAmB,MAAM;CAC3C,MAAM,CAAC,OAAO,YAAY,cAAc,MAAM,KAAK;CAInD,yBAAyB,MAAM,KAAK;CAEpC,IAAI,CAAC,MAAM,OAAO,OAAO,OAAO;CAEhC,MAAM,OAAO,WAAW,MAAM,OAAO;EACnC,OAAO,MAAM;EACb,aAAa,MAAM;EACnB,OAAO,KAAK;CACd,CAAC;CAGD,MAAM,WAAW,qBAAqB,KAAK,SAAS;EAClD,MAAM,MAAM,MAAM;EAClB;CACF,CAAC;CACD,IAAI,aAAa,MAAM,OAAO;CAE9B,MAAM,SAAS;EACb,GAAG;EACH,GAA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MAAM,IAAI,CAAC;EACjE,CAAC;CACH,GAAG;EAAC;EAAQ,OAAO;EAAM,OAAO;EAAM;CAAS,CAAC;AAClD;AAEA,MAAM,eACJ,MACA,aAC8B;CAC9B,IAAI,SAAS,MAAM,OAAO,KAAA;CAC1B,IAAI,OAAO,SAAS,UAAU,OAAO,QAAQ,IAAI;CACjD,IAAI,MAAM,OAAO;CACjB,OAAO,QAAQ,QAAQ;AACzB;AAEA,MAAM,iBACJ,OACA,SACc;CACd,MAAM,MAAO,MAAM,OAAqB;CACxC,MAAM,SAAU,MAAM,UAAwB;CAC9C,IAAI,CAAC,OAAO,CAAC,QAAQ,OAAO;CAC5B,OACE,qBAAC,OAAD;EAAK,WAAU;EAAf,UAAA;GACG;GACA;GACA;EACE;;AAET"}
|
|
1
|
+
{"version":3,"file":"control.js","names":[],"sources":["../../../src/components/control/control.tsx"],"sourcesContent":["import * as React from \"react\";\n\nvoid React;\n\nimport {\n ControlArray,\n type ControlArrayProps,\n} from \"@alepha/ui/components/control-array/control-array\";\nimport {\n FormField,\n formFieldAriaProps,\n useFormFieldAutoSave,\n useFormFieldLayout,\n} from \"@alepha/ui/components/control-base/form-field\";\nimport {\n type IconComponent,\n iconFor,\n} from \"@alepha/ui/components/control-base/icon-hint\";\nimport { ControlDateRange } from \"@alepha/ui/components/control-date-range/control-date-range\";\nimport {\n ControlDate,\n type ControlDateProps,\n} from \"@alepha/ui/components/control-date/control-date\";\nimport { ControlNumber } from \"@alepha/ui/components/control-number/control-number\";\nimport { ControlObject } from \"@alepha/ui/components/control-object/control-object\";\nimport { ControlPassword } from \"@alepha/ui/components/control-password/control-password\";\nimport {\n ControlSelect,\n type ControlSelectSize,\n type SelectOption,\n} from \"@alepha/ui/components/control-select/control-select\";\nimport {\n ControlUpload,\n type ControlUploadProps,\n} from \"@alepha/ui/components/control-upload/control-upload\";\nimport { Input } from \"@alepha/ui/components/ui/input\";\nimport { Switch } from \"@alepha/ui/components/ui/switch\";\nimport { Textarea } from \"@alepha/ui/components/ui/textarea\";\nimport { cn } from \"@alepha/ui/lib/utils\";\nimport { z } from \"alepha\";\nimport { useAlepha } from \"alepha/react\";\nimport {\n type BaseInputField,\n parseField,\n useFieldValue,\n useFormState,\n} from \"alepha/react/form\";\nimport { resolveSchemaControl, type SchemaControl } from \"alepha/react/ui\";\nimport { Check, X } from \"lucide-react\";\nimport {\n type ComponentType,\n type HTMLAttributes,\n type ReactNode,\n useEffect,\n useState,\n} from \"react\";\n\nexport interface ControlProps {\n /**\n * Bound `InputField` from `useForm`. Carries value, schema, and error state.\n */\n input: BaseInputField;\n /**\n * Field label. Falls back to schema `title` or the field name.\n */\n label?: string;\n /**\n * Helper text shown below the control. Falls back to schema `description`.\n */\n description?: string;\n /**\n * Force a specific input variant — renders a single-line text input.\n */\n text?: boolean;\n /**\n * Force a textarea.\n */\n area?: boolean;\n /**\n * Force a masked password input.\n */\n password?: boolean;\n /**\n * Force a `<Switch>` (boolean toggle).\n */\n switch?: boolean;\n /**\n * Force a numeric input.\n */\n number?: boolean;\n /**\n * Force the file-upload control (alias for `upload`).\n */\n file?: boolean;\n /**\n * Force a date picker.\n */\n date?: boolean;\n /**\n * Force a date-time picker.\n */\n datetime?: boolean;\n /**\n * Force a date-range picker, regardless of the schema's format.\n *\n * Rarely needed: `z.dateRange()` tags the array itself, so the control\n * selects itself. Here for the same reason `date` and `datetime` are - a\n * field whose schema is a plain pair of strings can still ask for it.\n */\n dateRange?: boolean;\n /**\n * Force a time picker.\n */\n time?: boolean;\n /**\n * Date picker caption style — `\"dropdown\"` swaps the month arrows for\n * month/year selects. See {@link ControlDateProps.captionLayout}.\n */\n captionLayout?: ControlDateProps[\"captionLayout\"];\n /** First selectable month of a date picker. */\n startMonth?: Date;\n /** Last selectable month of a date picker. */\n endMonth?: Date;\n /**\n * Date-of-birth shorthand: a year dropdown covering the last 120 years.\n * See {@link ControlDateProps.birthdate}.\n */\n birthdate?: boolean;\n /**\n * Force a `<Select>`.\n */\n select?: boolean;\n /**\n * Force a combobox (searchable select). Alias for `searchable: true`.\n */\n combobox?: boolean;\n /**\n * Force the select's search input on or off. Defaults to \"auto\" — on for an\n * async list, when `createNewEntry` is set, or above ~50 options.\n */\n searchable?: boolean;\n /**\n * Force a `<Segmented>` control (one option visible at a time).\n */\n segmented?: boolean;\n /**\n * Force a slider (numeric only).\n */\n slider?: boolean;\n /**\n * Force a nested `<ControlObject>` for object-typed schemas.\n */\n object?: boolean;\n /**\n * Force a nested `<ControlArray>` for array-typed schemas.\n */\n array?: boolean;\n /**\n * Props forwarded to the nested `<ControlObject>`, keyed by child field name.\n * This is the only way to reach INSIDE an object field — without it a caller\n * can style/override the object as a whole but never one of its children\n * (e.g. attaching a `custom` widget to `payg.zoneFareCents`).\n */\n /**\n * Dictionary prefix for schema-generated labels/help: this field reads\n * `<prefix>.<name>` and `<prefix>.<name>.desc`, and passes the extended\n * prefix down into nested objects and array items.\n */\n i18nPrefix?: string;\n objectProps?: {\n controlProps?: Record<string, Partial<Omit<ControlProps, \"input\">>>;\n variant?: \"fieldset\" | \"plain\";\n defaultExpanded?: boolean;\n };\n /**\n * Custom render component receiving `{value, onChange}`.\n */\n custom?: ComponentType<{ value: unknown; onChange: (v: unknown) => void }>;\n /**\n * Override icon — pass `null` to remove the schema-inferred icon.\n */\n icon?: IconComponent | string | null;\n /**\n * Disable the control.\n */\n disabled?: boolean;\n /**\n * Render slot before the control.\n */\n top?: ReactNode;\n /**\n * Render slot after the control.\n */\n bottom?: ReactNode;\n /**\n * Width slot inside an `<AutoForm>` group (mapped to a CSS grid column\n * span). Read by the parent group; ignored when rendering standalone.\n */\n width?: 100 | 75 | 66 | 50 | 33 | 25;\n /**\n * HTML `autocomplete` hint passed to the underlying input.\n */\n autoComplete?: string;\n /**\n * Placeholder text. On a text-shaped control this is the HTML\n * `placeholder`; on a select it is the trigger text shown while nothing is\n * picked.\n */\n placeholder?: string;\n /**\n * Autofocus the control on mount. Forwarded to the text, number, password\n * or textarea input the control renders. Ignored by the variants that are\n * not a single focusable field (select, date, upload, array, object).\n *\n * Every forward site carries an `oxlint-disable-next-line\n * jsx-a11y/no-autofocus`. That rule is right about a page that grabs focus\n * unbidden and wrong here: nothing focuses unless a caller passed this prop,\n * and it is the caller the rule should be asking. Left to fire, it did real\n * damage once - a lint pass deleted the forwarding and left the prop\n * declared, so login and dialog forms silently stopped focusing their first\n * field and two components grew `getElementById(...).focus()` workarounds.\n */\n autoFocus?: boolean;\n /**\n * Visible row count for the textarea variant. Overrides the value\n * auto-derived from the schema's `maxLength`. Ignored by other variants.\n */\n rows?: number;\n /**\n * Escape hatch — extra native attributes (event handlers, `className`,\n * `aria-*`, `data-*`, `style`, …) forwarded to whichever element the\n * control actually renders (text input / textarea / password input). The\n * form bindings (`value`, `onChange`, `id`, `name`) always win and cannot\n * be overridden here.\n *\n * `data-*` is spelled out because `HTMLAttributes` does not carry it:\n * TypeScript special-cases dashed attributes in JSX only, so an object\n * literal `{ \"data-testid\": … }` is an excess property and fails to\n * compile. Without this a control cannot carry a test hook, which meant a\n * surface with an e2e had to keep a raw `<input>` rather than adopt the\n * shared control.\n *\n * ⚠️ **`autoComplete` does not go here.** `Control` takes it as a\n * first-class prop, and `ControlPassword` writes its own after spreading\n * this object - so a value passed through `inputProps` is silently\n * replaced by `\"current-password\"`, which on a field holding a deploy\n * token is the password-manager prompt the masking exists to avoid.\n */\n inputProps?: HTMLAttributes<HTMLElement> & {\n [attribute: `data-${string}`]: string | number | boolean | undefined;\n };\n /**\n * Allow user to create new entries in select / multi-select.\n */\n createNewEntry?: boolean | ((query: string) => unknown);\n /**\n * Inline option list for select / combobox controls. Infer array or\n * async loader. Overrides schema-derived `enum` when present.\n */\n items?:\n | SelectOption[]\n | ((query: string) => SelectOption[] | Promise<SelectOption[]>);\n /**\n * Whether the field offers a way back to empty.\n *\n * On a `ControlSelect`, `true` adds a synthetic \"none\" row that resets the\n * field to `undefined` — use it for optional filter chips.\n *\n * On a text field the affordance is the opposite way round: an optional\n * field already shows a clear (×) button whenever it holds a value, and\n * `false` takes it away. Pass `false` when emptying the field is not\n * something the API can honour — a username has no \"unset\" on the server,\n * so offering the button would promise an edit that silently does nothing.\n */\n clearable?: boolean;\n /**\n * Forwarded to `ControlSelect` — label of the `clearable` row, also\n * used as the empty-state trigger placeholder. Defaults to \"None\".\n */\n clearLabel?: string;\n /**\n * Trigger text for a multi-select holding two or more values, e.g.\n * `(n) => \\`${n} status\\``. One selection always shows the value itself, so\n * this is only ever asked for the collapsed case. Defaults to\n * `\"{n} selected\"`.\n */\n countLabel?: (count: number) => string;\n /**\n * Forwarded to `ControlSelect` — extra className on the trigger.\n * Useful for sizing filter chips inline.\n */\n triggerClassName?: string;\n /**\n * Trigger height and type scale, for the select-shaped controls. Defaults\n * to `default`; `xs` is for a control that sits ON a row of text rather\n * than in a form.\n */\n size?: ControlSelectSize;\n /**\n * Render the select trigger borderless and transparent, so it reads as the\n * row it sits on rather than as a form field. Pairs with `size=\"xs\"`.\n */\n minimal?: boolean;\n /**\n * Render a managed upload control (image preview, multi, drag-drop)\n * that calls `FileController.uploadFile` and stores the file ID(s) in\n * the form value. Pass `true` for defaults or an options object.\n */\n upload?:\n | boolean\n | Pick<\n ControlUploadProps,\n \"multi\" | \"accept\" | \"maxSize\" | \"bucket\" | \"image\"\n >;\n}\n\n/**\n * Schema-driven form field renderer. Inspects the bound `InputField` from\n * `useForm`, evaluates `schema.$control` (object or function), merges the\n * result with explicit props, and dispatches to the right sub-control.\n */\nexport const Control = (props: ControlProps) => {\n const form = useFormState(props.input, [\"error\", \"dirty\"]);\n const autoSaveEnabled = useFormFieldAutoSave();\n const rowLayout = useFormFieldLayout() === \"row\";\n const [value, setValue] = useFieldValue(props.input);\n\n // Function-form `$control` reads other fields → re-render on any\n // change. Infer `$control` (object) does not need this subscription.\n useDynamicControlRefresh(props.input);\n\n if (!props.input?.props) return null;\n\n const meta = parseField(props.input, {\n label: props.label,\n description: props.description,\n error: form.error,\n });\n\n // ── Resolve $control (object | function | false) ─────────────────\n const resolved = resolveSchemaControl(meta.control, {\n form: props.input.form,\n value,\n });\n // `null` is gone, `hidden` is present-but-invisible. A control renders\n // nothing for either; only the LAYOUT tells them apart.\n if (resolved === null || resolved.hidden) return null;\n\n const merged = {\n ...props,\n ...(resolved as Partial<ControlProps>),\n } as ControlProps & Partial<SchemaControl>;\n\n // ── Custom escape hatch ──────────────────────────────────────────\n if (merged.custom) {\n const Custom = merged.custom;\n return wrapWithSlots(\n merged,\n <FormField\n id={meta.id}\n label={merged.label ?? meta.label}\n description={merged.description ?? meta.description}\n error={meta.error}\n required={meta.required}\n >\n <Custom value={value} onChange={(v) => setValue(v)} />\n </FormField>,\n );\n }\n\n // ── Recursive: object / array of objects ─────────────────────────\n if (merged.object || meta.isObject) {\n return wrapWithSlots(\n merged,\n <ControlObject\n input={props.input}\n label={merged.label ?? props.label}\n description={merged.description ?? props.description}\n disabled={merged.disabled}\n i18nPrefix={merged.i18nPrefix}\n controlProps={merged.objectProps?.controlProps}\n variant={merged.objectProps?.variant}\n defaultExpanded={merged.objectProps?.defaultExpanded}\n clearable={merged.clearable}\n />,\n );\n }\n if (merged.array || meta.isArrayOfObjects) {\n const arrayProps = (merged as { arrayProps?: Record<string, unknown> })\n .arrayProps;\n return wrapWithSlots(\n merged,\n <ControlArray\n input={props.input}\n i18nPrefix={merged.i18nPrefix}\n label={merged.label ?? props.label}\n description={merged.description ?? props.description}\n disabled={merged.disabled}\n confirmDelete={\n arrayProps?.confirmDelete as ControlArrayProps[\"confirmDelete\"]\n }\n renderTabName={\n arrayProps?.renderTabName as ControlArrayProps[\"renderTabName\"]\n }\n forceTabs={arrayProps?.forceTabs as boolean | undefined}\n />,\n );\n }\n\n // ── File: managed upload (image preview, multi, drag-drop) ──────\n // Checked early so it wins over the array→combobox branch below\n // when the schema is `z.array(z.string())` with $control.upload.\n if (merged.upload) {\n const uploadOpts =\n typeof merged.upload === \"object\"\n ? (merged.upload as Partial<ControlUploadProps>)\n : {};\n return wrapWithSlots(\n merged,\n <ControlUpload\n input={props.input}\n label={merged.label ?? props.label}\n description={merged.description ?? props.description}\n disabled={merged.disabled}\n {...uploadOpts}\n />,\n );\n }\n\n // ── Items provided → select / multi / combobox ───────────────────\n // Read before the numeric branch, because that branch owns every numeric\n // schema by default and `ControlNumber` has nowhere to put an option list:\n // a `z.number()` field handed `items` used to render a bare spinner and drop\n // the rows on the floor, silently. An explicit list is an explicit request\n // for a select, so it wins - `slider` / `number` still override it below.\n const items = (merged as Record<string, unknown>).items as\n | undefined\n | unknown[]\n | ((q: string) => unknown);\n\n // ── Number / slider ──────────────────────────────────────────────\n if (\n merged.slider ||\n merged.number ||\n (!merged.select &&\n !merged.segmented &&\n !merged.combobox &&\n items == null &&\n (meta.type === \"number\" || meta.type === \"integer\"))\n ) {\n return wrapWithSlots(\n merged,\n <ControlNumber\n input={props.input}\n label={merged.label ?? props.label}\n description={merged.description ?? props.description}\n slider={merged.slider}\n disabled={merged.disabled}\n // oxlint-disable-next-line jsx-a11y/no-autofocus\n autoFocus={merged.autoFocus}\n />,\n );\n }\n\n // ── Date range ───────────────────────────────────────────────────\n //\n // ⚠️ ABOVE the array branch below, and that placement is the whole of it.\n // `z.dateRange()` IS an array, so the `meta.isArray` test twenty lines down\n // matches it first and renders a range as a multi-select combobox - which\n // looks like a deliberate control and is silently the wrong one. Sitting\n // this beside the date branch further down, where it reads as though it\n // belongs, is exactly the mistake.\n //\n // Keyed on the format LITERAL, never on \"array whose items are dates\": that\n // second test cannot tell a range from an ordinary list of two days, and it\n // is what would make a later `date-time-range` a rewrite rather than one\n // more literal plus a `withTime` prop.\n if (merged.dateRange || meta.format === \"date-range\") {\n return wrapWithSlots(\n merged,\n <ControlDateRange\n input={props.input}\n label={merged.label ?? props.label}\n description={merged.description ?? props.description}\n disabled={merged.disabled}\n clearable={merged.clearable}\n placeholder={merged.placeholder}\n triggerClassName={merged.triggerClassName}\n />,\n );\n }\n\n if (\n merged.select ||\n merged.combobox ||\n merged.segmented ||\n meta.isEnum ||\n (meta.isArray && !meta.isArrayOfObjects) ||\n items != null\n ) {\n return wrapWithSlots(\n merged,\n <ControlSelect\n input={props.input}\n label={merged.label ?? props.label}\n description={merged.description ?? props.description}\n segmented={merged.segmented}\n combobox={merged.combobox}\n searchable={merged.searchable}\n items={items as never}\n icon={resolveIcon(merged.icon)}\n disabled={merged.disabled}\n createNewEntry={\n merged.createNewEntry as boolean | ((q: string) => never) | undefined\n }\n clearable={merged.clearable}\n clearLabel={merged.clearLabel}\n countLabel={merged.countLabel}\n // Dropped here until now, so a picker that needed to name its own\n // empty state (\"Pick an epic…\") could not be a `Control` at all.\n placeholder={merged.placeholder}\n triggerClassName={merged.triggerClassName}\n size={merged.size}\n minimal={merged.minimal}\n // Used to be dropped here, silently: every `inputProps={{ \"aria-label\"\n // }}` on a select-shaped Control (the epics and quests status filters\n // among them) named nothing at all, because the trigger is a button\n // with no visible label to borrow a name from.\n triggerProps={merged.inputProps}\n />,\n );\n }\n\n // ── Boolean → switch ─────────────────────────────────────────────\n if (meta.type === \"boolean\" && merged.switch !== false) {\n return wrapWithSlots(\n merged,\n <FormField\n id={meta.id}\n label={merged.label ?? meta.label}\n description={merged.description ?? meta.description}\n error={meta.error}\n required={meta.required}\n >\n <div className=\"flex h-9 items-center\">\n <Switch\n id={meta.id}\n // Same omission as the numeric control had: without a name the\n // toggle is invisible to `[name=\"…\"]` lookups, including\n // `AutoForm`'s scroll-to-first-error.\n name={props.input.props.name}\n disabled={merged.disabled}\n checked={Boolean(value)}\n onCheckedChange={(v) => setValue(v)}\n />\n </div>\n </FormField>,\n );\n }\n\n // ── Date / time ──────────────────────────────────────────────────\n if (\n merged.date ||\n merged.datetime ||\n merged.time ||\n meta.format === \"date\" ||\n meta.format === \"date-time\" ||\n meta.format === \"time\"\n ) {\n return wrapWithSlots(\n merged,\n <ControlDate\n input={props.input}\n label={merged.label ?? props.label}\n description={merged.description ?? props.description}\n date={merged.date}\n datetime={merged.datetime}\n time={merged.time}\n disabled={merged.disabled}\n clearable={merged.clearable}\n captionLayout={merged.captionLayout}\n startMonth={merged.startMonth}\n endMonth={merged.endMonth}\n birthdate={merged.birthdate}\n />,\n );\n }\n\n // ── File (raw) ───────────────────────────────────────────────────\n if (merged.file) {\n return wrapWithSlots(\n merged,\n <FormField\n id={meta.id}\n label={merged.label ?? meta.label}\n description={merged.description ?? meta.description}\n error={meta.error}\n required={meta.required}\n >\n <Input\n id={meta.id}\n name={props.input.props.name}\n type=\"file\"\n disabled={merged.disabled}\n onChange={(e) => setValue(e.target.files?.[0])}\n />\n </FormField>,\n );\n }\n\n // ── Auto-textarea: explicit `area` or maxLength > 256 ────────────\n const maxLength = meta.constraints.maxLength ?? 0;\n if (merged.area || maxLength > 256) {\n const rows =\n merged.rows ?? (maxLength > 1024 ? 6 : maxLength > 512 ? 4 : 2);\n return wrapWithSlots(\n merged,\n <FormField\n id={meta.id}\n label={merged.label ?? meta.label}\n description={merged.description ?? meta.description}\n error={meta.error}\n required={meta.required}\n >\n <Textarea\n {...merged.inputProps}\n {...formFieldAriaProps({\n id: meta.id,\n error: meta.error,\n description: merged.description ?? meta.description,\n required: meta.required,\n })}\n id={meta.id}\n name={props.input.props.name}\n rows={rows}\n disabled={merged.disabled}\n maxLength={maxLength || undefined}\n autoComplete={merged.autoComplete}\n // oxlint-disable-next-line jsx-a11y/no-autofocus\n autoFocus={merged.autoFocus}\n placeholder={merged.placeholder}\n value={String(value ?? \"\")}\n onChange={(e) => setValue(e.target.value)}\n />\n </FormField>,\n );\n }\n\n // ── Password ─────────────────────────────────────────────────────\n const isPassword =\n merged.password ||\n meta.iconHint === \"password\" ||\n meta.format === \"password\";\n if (isPassword) {\n return wrapWithSlots(\n merged,\n <ControlPassword\n id={meta.id}\n name={props.input.props.name}\n label={merged.label ?? meta.label}\n description={merged.description ?? meta.description}\n error={meta.error}\n required={meta.required}\n disabled={merged.disabled}\n autoComplete={merged.autoComplete}\n // oxlint-disable-next-line jsx-a11y/no-autofocus\n autoFocus={merged.autoFocus}\n inputProps={merged.inputProps}\n icon={resolveIcon(merged.icon, \"password\")}\n value={String(value ?? \"\")}\n onChange={(v) => setValue(v)}\n />,\n );\n }\n\n // ── Default text input with format-driven HTML5 type + icon ──────\n const Icon = resolveIcon(merged.icon, meta.iconHint);\n const htmlType =\n meta.format === \"email\"\n ? \"email\"\n : meta.format === \"url\" || meta.format === \"uri\"\n ? \"url\"\n : meta.format === \"tel\" || meta.format === \"phone\"\n ? \"tel\"\n : \"text\";\n\n // Derive a sensible HTML `autocomplete` hint from the schema format so\n // password managers and browser autofill behave correctly out of the box.\n // Explicit `autoComplete` prop always wins.\n const autoCompleteFromFormat =\n meta.format === \"email\"\n ? \"email\"\n : meta.format === \"tel\" || meta.format === \"phone\"\n ? \"tel\"\n : meta.format === \"url\" || meta.format === \"uri\"\n ? \"url\"\n : undefined;\n const autoComplete = merged.autoComplete ?? autoCompleteFromFormat;\n\n // ── Right-side affordance: tick (when dirty) or clear (when nullable) ─\n // Tick only renders inside an `<AutoForm autoSave>` tree (or any caller\n // that explicitly wraps with `<FormFieldAutoSaveProvider value>`).\n const showSave = autoSaveEnabled && !!form.dirty && !merged.disabled;\n const isNullable =\n !meta.required && value != null && value !== \"\" && !merged.disabled;\n // `clearable !== false`, not `clearable === true`: an optional text field\n // offers the button by default and a caller opts *out* of it. See the prop.\n const showClear = !showSave && isNullable && merged.clearable !== false;\n // Reserve a fixed right gutter for any editable field so the tick/clear\n // can swap in without nudging the input width.\n const reserveGutter = !merged.disabled;\n\n return wrapWithSlots(\n merged,\n <FormField\n id={meta.id}\n label={merged.label ?? meta.label}\n description={merged.description ?? meta.description}\n error={meta.error}\n required={meta.required}\n >\n <div className=\"relative\">\n {Icon && (\n <Icon className=\"text-muted-foreground pointer-events-none absolute top-1/2 left-3 size-4 -translate-y-1/2\" />\n )}\n <Input\n {...merged.inputProps}\n {...formFieldAriaProps({\n id: meta.id,\n error: meta.error,\n description: merged.description ?? meta.description,\n required: meta.required,\n })}\n id={meta.id}\n name={props.input.props.name}\n type={htmlType}\n disabled={merged.disabled}\n autoComplete={autoComplete}\n // oxlint-disable-next-line jsx-a11y/no-autofocus\n autoFocus={merged.autoFocus}\n placeholder={merged.placeholder}\n value={String(value ?? \"\")}\n minLength={meta.constraints.minLength}\n maxLength={meta.constraints.maxLength}\n pattern={meta.constraints.pattern}\n // `cn`, not a plain join: the settings width below has to be\n // overridable by the caller, and only `cn`'s merge can decide\n // that `sm:w-96` beats `sm:w-64` rather than both landing on the\n // element. Order is precedence — later wins.\n className={cn(\n // Row layout is the settings-card shape, whose right-hand cell is\n // an `auto` grid column: `w-full` there resolves against the\n // input's own intrinsic size (~172px), so every card would get a\n // slightly different control column. 256px is the width every\n // hand-written `SettingsRow` already passes; encoded once here.\n // Below `sm` the row stacks, and `w-full` from `<Input>` is right.\n rowLayout && \"sm:w-64\",\n merged.inputProps?.className,\n Icon && \"pl-9\",\n reserveGutter && \"pr-9\",\n )}\n onChange={(e) => setValue(e.target.value)}\n onKeyDown={(e) => {\n merged.inputProps?.onKeyDown?.(e);\n if (e.defaultPrevented || e.key !== \"Enter\") return;\n // The commit the auto-save effect deliberately withholds from a\n // text field on every keystroke. Its comment offers \"Enter or the\n // inline tick button\" as the two ways to commit - and only the\n // tick ever existed. `AutoForm` in auto-save mode renders no\n // submit button, so the browser's implicit submission never fires\n // and Enter did nothing at all, on every text field in every\n // auto-saving form.\n //\n // Guarded on `showSave` so it is inert outside auto-save mode and\n // on a pristine field, where a normal form's own Enter handling\n // must keep working.\n if (!showSave) return;\n e.preventDefault();\n // `props.input.form`, the same handle the tick button submits\n // through. The local `form` is only the `dirty` / `error` slice.\n void props.input.form.submit();\n }}\n />\n {showSave && (\n <button\n type=\"button\"\n onClick={() => props.input.form.submit()}\n aria-label=\"Save\"\n className=\"text-primary hover:text-primary/80 absolute top-1/2 right-2 -translate-y-1/2 p-1\"\n >\n <Check className=\"size-3.5\" />\n </button>\n )}\n {showClear && (\n <button\n type=\"button\"\n onClick={() => setValue(undefined)}\n aria-label=\"Clear\"\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 </FormField>,\n );\n};\n\n/**\n * The raw `$control` a field declares, object form or function form.\n *\n * It rides on zod's `.meta()` registry rather than being a plain schema\n * property, and the field may be wrapped (optional / nullable / default), so\n * the wrapper has to be peeled before the meta is readable.\n *\n * Exported because the LAYOUT needs it too: `AutoForm` sizes a grid cell from\n * the width `$control` asks for, and a function-form `$control` has no `.width`\n * to read off the function itself. Pair it with {@link resolveSchemaControl}.\n */\nexport const readSchemaControl = (\n input: BaseInputField | undefined,\n): unknown => {\n const base = input?.schema ? z.schema.unwrap(input.schema) : undefined;\n return (base as { meta?: () => { $control?: unknown } } | undefined)?.meta?.()\n ?.$control;\n};\n\n/**\n * Re-render when a function-form `$control` may have changed its mind, which\n * is on any change to a field OTHER than this one. An object-form `$control`\n * is static and needs no subscription.\n *\n * Exported alongside {@link readSchemaControl}, and for the same reason: a\n * consumer that resolves `$control` itself has to re-resolve on the same\n * events, or it renders a stale answer.\n */\nexport const useDynamicControlRefresh = (input: BaseInputField | undefined) => {\n const alepha = useAlepha();\n const [, bump] = useState(0);\n const isDynamic = typeof readSchemaControl(input) === \"function\";\n useEffect(() => {\n if (!isDynamic || !input?.form) return;\n const formId = input.form.id;\n return alepha.events.on(\"form:change\", (e) => {\n if (e.id === formId && e.path !== input.path) bump((n) => n + 1);\n });\n }, [alepha, input?.form, input?.path, isDynamic]);\n};\n\nconst resolveIcon = (\n icon: ControlProps[\"icon\"],\n fallback?: string | null,\n): IconComponent | undefined => {\n if (icon === null) return undefined;\n if (typeof icon === \"string\") return iconFor(icon);\n if (icon) return icon;\n return iconFor(fallback);\n};\n\nconst wrapWithSlots = (\n props: ControlProps & Partial<SchemaControl>,\n body: ReactNode,\n): ReactNode => {\n const top = (props.top as ReactNode) ?? null;\n const bottom = (props.bottom as ReactNode) ?? null;\n if (!top && !bottom) return body;\n return (\n <div className=\"flex flex-col gap-1\">\n {top}\n {body}\n {bottom}\n </div>\n );\n};\n"],"mappings":";;;;;;;;;;;;;;;;;;;;;;;;;;;AAiUA,MAAa,WAAW,UAAwB;CAC9C,MAAM,OAAO,aAAa,MAAM,OAAO,CAAC,SAAS,OAAO,CAAC;CACzD,MAAM,kBAAkB,qBAAqB;CAC7C,MAAM,YAAY,mBAAmB,MAAM;CAC3C,MAAM,CAAC,OAAO,YAAY,cAAc,MAAM,KAAK;CAInD,yBAAyB,MAAM,KAAK;CAEpC,IAAI,CAAC,MAAM,OAAO,OAAO,OAAO;CAEhC,MAAM,OAAO,WAAW,MAAM,OAAO;EACnC,OAAO,MAAM;EACb,aAAa,MAAM;EACnB,OAAO,KAAK;CACd,CAAC;CAGD,MAAM,WAAW,qBAAqB,KAAK,SAAS;EAClD,MAAM,MAAM,MAAM;EAClB;CACF,CAAC;CAGD,IAAI,aAAa,QAAQ,SAAS,QAAQ,OAAO;CAEjD,MAAM,SAAS;EACb,GAAG;EACH,GAAI;CACN;CAGA,IAAI,OAAO,QAAQ;EACjB,MAAM,SAAS,OAAO;EACtB,OAAO,cACL,QACA,oBAAC,WAAD;GACE,IAAI,KAAK;GACT,OAAO,OAAO,SAAS,KAAK;GAC5B,aAAa,OAAO,eAAe,KAAK;GACxC,OAAO,KAAK;GACZ,UAAU,KAAK;GAEf,UAAA,oBAAC,QAAD;IAAe;IAAO,WAAW,MAAM,SAAS,CAAC;GAAI,CAAA;EAC5C,CAAA,CACb;CACF;CAGA,IAAI,OAAO,UAAU,KAAK,UACxB,OAAO,cACL,QACA,oBAAC,eAAD;EACE,OAAO,MAAM;EACb,OAAO,OAAO,SAAS,MAAM;EAC7B,aAAa,OAAO,eAAe,MAAM;EACzC,UAAU,OAAO;EACjB,YAAY,OAAO;EACnB,cAAc,OAAO,aAAa;EAClC,SAAS,OAAO,aAAa;EAC7B,iBAAiB,OAAO,aAAa;EACrC,WAAW,OAAO;CAC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,CAAC;EACjE,CAAC;CACH,GAAG;EAAC;EAAQ,OAAO;EAAM,OAAO;EAAM;CAAS,CAAC;AAClD;AAEA,MAAM,eACJ,MACA,aAC8B;CAC9B,IAAI,SAAS,MAAM,OAAO,KAAA;CAC1B,IAAI,OAAO,SAAS,UAAU,OAAO,QAAQ,IAAI;CACjD,IAAI,MAAM,OAAO;CACjB,OAAO,QAAQ,QAAQ;AACzB;AAEA,MAAM,iBACJ,OACA,SACc;CACd,MAAM,MAAO,MAAM,OAAqB;CACxC,MAAM,SAAU,MAAM,UAAwB;CAC9C,IAAI,CAAC,OAAO,CAAC,QAAQ,OAAO;CAC5B,OACE,qBAAC,OAAD;EAAK,WAAU;EAAf,UAAA;GACG;GACA;GACA;EACE;;AAET"}
|
|
@@ -302,8 +302,9 @@ const ControlArray = (props) => {
|
|
|
302
302
|
i18nPrefix: childI18nPrefix(props.i18nPrefix, name)
|
|
303
303
|
};
|
|
304
304
|
const isDiscriminant = !!variants && name === discriminant;
|
|
305
|
+
const fieldInput = buildFieldInput(props.input, itemObjectSchema, name, index, item.value, (f, v) => updateField(index, f, v));
|
|
305
306
|
return /* @__PURE__ */ jsx(Control, {
|
|
306
|
-
input:
|
|
307
|
+
input: fieldInput,
|
|
307
308
|
disabled: props.disabled || isDiscriminant,
|
|
308
309
|
...fieldProps
|
|
309
310
|
}, name);
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"control-array.js","names":[],"sources":["../../../src/components/control-array/control-array.tsx"],"sourcesContent":["import * as React from \"react\";\n\nvoid React;\n\nimport {\n Control,\n type ControlProps,\n} from \"@alepha/ui/components/control/control\";\nimport { Button } from \"@alepha/ui/components/ui/button\";\nimport {\n Dialog,\n DialogContent,\n DialogDescription,\n DialogFooter,\n DialogHeader,\n DialogTitle,\n} from \"@alepha/ui/components/ui/dialog\";\nimport { type ZObject, type ZType, z } from \"alepha\";\nimport { useAlepha } from \"alepha/react\";\nimport {\n type BaseInputField,\n parseField,\n unionVariants,\n useFormState,\n} from \"alepha/react/form\";\nimport { useI18n } from \"alepha/react/i18n\";\nimport {\n ArrowDown,\n ArrowUp,\n ChevronDown,\n ChevronRight,\n Plus,\n Trash2,\n} from \"lucide-react\";\nimport { useCallback, useEffect, useRef, useState } from \"react\";\n\nimport {\n childI18nPrefix,\n resolveFieldI18n,\n} from \"../control-base/field-i18n.ts\";\n\ninterface ArrayItem {\n key: number;\n value: unknown;\n}\n\nexport interface ControlArrayProps {\n /**\n * Bound array `InputField` from `useForm`.\n */\n input: BaseInputField;\n /**\n * Dictionary prefix for the item fields: each reads `<prefix>.<field>` and\n * `<prefix>.<field>.desc` (the index is not part of the key — every row of\n * the list shares one label).\n */\n i18nPrefix?: string;\n /**\n * Field label. Falls back to schema `title`.\n */\n label?: string;\n /**\n * Helper text shown below the array.\n */\n description?: string;\n /**\n * Minimum number of items (Add button disables when reached).\n */\n min?: number;\n /**\n * Maximum number of items (Add button disables when reached).\n */\n max?: number;\n /**\n * Override the \"Add item\" button label.\n */\n addLabel?: string;\n /**\n * Number of grid columns for each item's inner fields.\n */\n columns?: 1 | 2 | 3 | 4;\n /**\n * \"fieldset\" wraps in a bordered container with legend; \"plain\" renders items only.\n */\n variant?: \"fieldset\" | \"plain\";\n /**\n * Per-field `<Control>` overrides for items, keyed by inner field name.\n */\n controlProps?: Record<string, Partial<Omit<ControlProps, \"input\">>>;\n /**\n * Override props applied to every item (when items are primitive, not objects).\n */\n itemControlProps?: Partial<Omit<ControlProps, \"input\">>;\n /**\n * Disable add/remove and all inner controls.\n */\n disabled?: boolean;\n\n /**\n * Default expanded state. @default true\n */\n defaultExpanded?: boolean;\n\n /**\n * Confirm before deleting an item. Pass `true` for default copy or an\n * object to override title/message.\n */\n confirmDelete?: boolean | { title?: string; message?: string };\n\n /**\n * Compute the visible label for each item header (and tab name in tabs mode).\n */\n renderTabName?: (i: number, value: unknown) => string;\n\n /**\n * Force tabs mode even for short arrays. Default heuristic: items > 4 OR nested object/array fields.\n */\n forceTabs?: boolean;\n}\n\nconst colsClass: Record<number, string> = {\n 1: \"grid-cols-1\",\n 2: \"grid-cols-2\",\n 3: \"grid-cols-3\",\n 4: \"grid-cols-4\",\n};\n\n/**\n * The keys of a plain object, or nothing.\n *\n * An item that is not an object has no per-field inputs, so there is nothing\n * below it to notify.\n */\nconst objectKeys = (value: unknown): string[] =>\n value && typeof value === \"object\" && !Array.isArray(value)\n ? Object.keys(value as Record<string, unknown>)\n : [];\n\nconst useArrayItems = (input: BaseInputField | undefined) => {\n const alepha = useAlepha();\n const counter = useRef(0);\n const [items, setItemsState] = useState<ArrayItem[]>(() => {\n const initial = input?.initialValue;\n return Array.isArray(initial)\n ? initial.map((value) => ({ key: counter.current++, value }))\n : [];\n });\n\n // The list as last rendered, so a write can diff against it without\n // `setItems` depending on `items` (which would rebuild the callback, and\n // with it every row, on each keystroke).\n const itemsRef = useRef(items);\n itemsRef.current = items;\n\n /**\n * Tell the CHILD paths what changed.\n *\n * `input.set()` writes the whole array and `FormModel` emits `form:change`\n * for the array's own path only. The per-item and per-field inputs this\n * component builds carry paths of their own (`.../2/name`), so a child\n * subscribed through `useFieldValue` never heard about its own edit and\n * kept re-rendering the value it had at mount.\n *\n * Only what actually differs is emitted: this event is how a row avoids\n * re-rendering when a sibling changes, and announcing every path on every\n * keystroke would give that up.\n */\n const emitChanged = useCallback(\n (prev: ArrayItem[], next: ArrayItem[]) => {\n const form = input?.form;\n if (!form || !input) return;\n\n const emit = (path: string, value: unknown) =>\n void alepha.events.emit(\n \"form:change\",\n { id: form.id, path, value },\n { catch: true },\n );\n\n for (let i = 0; i < Math.max(prev.length, next.length); i++) {\n const before = prev[i]?.value;\n const after = next[i]?.value;\n if (before === after) continue;\n\n emit(`${input.path}/${i}`, after);\n\n for (const key of new Set([\n ...objectKeys(before),\n ...objectKeys(after),\n ])) {\n const beforeField = (before as Record<string, unknown>)?.[key];\n const afterField = (after as Record<string, unknown>)?.[key];\n if (beforeField !== afterField) {\n emit(`${input.path}/${i}/${key}`, afterField);\n }\n }\n }\n },\n [alepha, input],\n );\n\n const sync = useCallback(\n (next: unknown[] | undefined) => {\n if (!Array.isArray(next)) {\n emitChanged(itemsRef.current, []);\n setItemsState([]);\n return;\n }\n if (\n itemsRef.current.length === next.length &&\n itemsRef.current.every((it, i) => it.value === next[i])\n ) {\n return;\n }\n counter.current = 0;\n const rebuilt = next.map((value) => ({ key: counter.current++, value }));\n // A reset or a `setInitialValues` writes the array whole, so the child\n // paths need telling here too - same reason as an edit.\n emitChanged(itemsRef.current, rebuilt);\n setItemsState(rebuilt);\n },\n [emitChanged],\n );\n\n useEffect(() => {\n if (!input?.form) return;\n const formId = input.form.id;\n const path = input.path;\n return alepha.events.on(\"form:change\", (e) => {\n if (e.id === formId && e.path === path) sync(e.value as unknown[]);\n });\n }, [alepha, input, sync]);\n\n const setItems = useCallback(\n (next: ArrayItem[]) => {\n const prev = itemsRef.current;\n setItemsState(next);\n input?.set(next.map((it) => it.value));\n emitChanged(prev, next);\n },\n [input, emitChanged],\n );\n\n return { items, setItems, nextKey: () => counter.current++ };\n};\n\n/**\n * Discriminated-union support for item schemas.\n *\n * `z.array(z.union([...objects]))` is how a heterogeneous list is spelled. The\n * variants almost always differ by one literal property (`kind`, `type`, …),\n * which is enough to (a) tell which variant an existing item is and (b) label\n * the choice offered when adding one. Everything below degrades quietly: no\n * union, or no discriminant, and the array behaves exactly as before.\n */\nconst objectVariants = (itemSchema: ZType): ZObject[] | null => {\n const variants = unionVariants(itemSchema);\n if (!variants?.length) return null;\n const objects = variants\n .map((variant) => z.schema.unwrap(variant))\n .filter((variant) => z.schema.isObject(variant)) as ZObject[];\n return objects.length === variants.length ? objects : null;\n};\n\n/**\n * The property whose value identifies the variant (a literal in every variant).\n */\nconst discriminantOf = (variants: ZObject[]): string | null => {\n const [first] = variants;\n if (!first) return null;\n for (const name of Object.keys(z.schema.shape(first))) {\n const values = variants.map((variant) =>\n literalValueOf(z.schema.shape(variant)[name]),\n );\n if (values.every((value) => typeof value === \"string\")) {\n const unique = new Set(values as string[]);\n if (unique.size === variants.length) return name;\n }\n }\n return null;\n};\n\n/**\n * The single allowed value of a literal/const schema, if it is one.\n */\nconst literalValueOf = (schema: unknown): unknown => {\n if (!schema) return undefined;\n const inner = z.schema.unwrap(schema as ZType) as {\n const?: unknown;\n values?: unknown[] | Set<unknown>;\n _zod?: { def?: { values?: unknown[] } };\n };\n if (inner?.const !== undefined) return inner.const;\n // zod spells a literal's allowed values as `_zod.def.values` (an array);\n // the public `.values` is a Set, so normalise both.\n const raw = inner?._zod?.def?.values ?? inner?.values;\n const values =\n raw instanceof Set ? [...raw] : Array.isArray(raw) ? raw : undefined;\n return values?.length === 1 ? values[0] : undefined;\n};\n\n/**\n * Label for a variant: its discriminant value, else its index.\n */\nconst variantLabel = (\n variant: ZObject,\n discriminant: string | null,\n index: number,\n): string => {\n const value = discriminant\n ? literalValueOf(z.schema.shape(variant)[discriminant])\n : undefined;\n return typeof value === \"string\" ? value : `#${index + 1}`;\n};\n\nconst buildItemInput = (\n parent: BaseInputField,\n schema: ZType,\n index: number,\n value: unknown,\n onChange: (v: unknown) => void,\n): BaseInputField => ({\n schema,\n path: `${parent.path}/${index}`,\n required: false,\n form: parent.form,\n initialValue: value,\n props: {\n id: `${parent.props.id}-${index}`,\n name: `${parent.props.name}[${index}]`,\n },\n set: onChange,\n});\n\nconst buildFieldInput = (\n parent: BaseInputField,\n itemSchema: ZObject,\n fieldName: string,\n index: number,\n itemValue: Record<string, unknown> | undefined,\n onFieldChange: (field: string, value: unknown) => void,\n): BaseInputField => ({\n schema: z.schema.shape(itemSchema)[fieldName],\n path: `${parent.path}/${index}/${fieldName}`,\n required: z.schema.requiredKeys(itemSchema).includes(fieldName),\n form: parent.form,\n initialValue: itemValue?.[fieldName],\n props: {\n id: `${parent.props.id}-${index}-${fieldName}`,\n name: `${parent.props.name}[${index}].${fieldName}`,\n },\n set: (v: unknown) => onFieldChange(fieldName, v),\n});\n\nexport const ControlArray = (props: ControlArrayProps) => {\n const form = useFormState(props.input, [\"error\"]);\n const { tr } = useI18n();\n const { items, setItems, nextKey } = useArrayItems(props.input);\n const [expanded, setExpanded] = useState(props.defaultExpanded ?? true);\n const [activeTab, setActiveTab] = useState(0);\n const [pendingDelete, setPendingDelete] = useState<number | null>(null);\n\n if (!props.input?.props) return null;\n\n const meta = parseField(props.input, {\n label: props.label,\n description: props.description,\n error: form.error,\n });\n\n const schema = props.input.schema;\n // `isArray`, not `\"items\" in schema`: that spelling tested for a prototype\n // alias rather than for an array schema, so it answered false once the alias\n // went away — and the whole control rendered nothing, Add button included.\n if (!z.schema.isArray(schema)) return null;\n\n // `z.schema.element`, not `.items`: the latter only ever resolved through a\n // prototype alias on ZodArray, so it silently became `undefined` — and with\n // no item schema the control renders neither fields nor tabs.\n const itemSchema = z.schema.element(schema) as ZType;\n const variants = objectVariants(itemSchema);\n const discriminant = variants ? discriminantOf(variants) : null;\n\n /**\n * The object schema to edit an item with. For a union that is the variant the\n * item's discriminant points at (first variant as a fallback, e.g. a freshly\n * added item), so each row renders exactly its own fields.\n */\n const schemaForValue = (value: unknown): ZObject | null => {\n if (!variants) {\n // `isObject`, not `\"properties\" in itemSchema`: the latter tested for a\n // prototype alias, so it answered false as soon as the alias went away.\n return z.schema.isObject(itemSchema) ? (itemSchema as ZObject) : null;\n }\n if (discriminant && value && typeof value === \"object\") {\n const tag = (value as Record<string, unknown>)[discriminant];\n const match = variants.find(\n (variant) =>\n literalValueOf(z.schema.shape(variant)[discriminant]) === tag,\n );\n if (match) return match;\n }\n return variants[0] ?? null;\n };\n\n const objectItemSchema = schemaForValue(items[0]?.value);\n const fieldNames = objectItemSchema\n ? Object.keys(z.schema.shape(objectItemSchema))\n : [];\n\n // Schema-driven max/min if present: `z.array().max(3)` lands in zod's\n // constraint bag, the JSON-schema `maxItems` names never existed here.\n const bounds =\n (z.schema.unwrap(schema) as { _zod?: { bag?: Record<string, unknown> } })\n ._zod?.bag ?? {};\n const schemaMax =\n typeof bounds.maximum === \"number\" ? bounds.maximum : undefined;\n const schemaMin =\n typeof bounds.minimum === \"number\" ? bounds.minimum : undefined;\n const min = props.min ?? schemaMin ?? 0;\n const max = props.max ?? schemaMax ?? Number.POSITIVE_INFINITY;\n const columns = props.columns ?? 1;\n\n // Tabs heuristic: forced or nested complex item or many items\n const hasComplexFields = objectItemSchema\n ? fieldNames.some((n) => {\n const inner = z.schema.unwrap(z.schema.shape(objectItemSchema)[n]);\n return z.schema.isObject(inner) || z.schema.isArray(inner);\n })\n : false;\n const useTabs =\n props.forceTabs ||\n (objectItemSchema && (items.length > 4 || hasComplexFields));\n\n const handleAdd = (variantIndex = 0) => {\n if (items.length >= max) return;\n const shape = variants ? variants[variantIndex] : objectItemSchema;\n let value: unknown;\n if (shape) {\n value = {};\n for (const [k, p] of Object.entries(z.schema.shape(shape))) {\n const def = z.schema.getDefault(p);\n if (def !== undefined) (value as Record<string, unknown>)[k] = def;\n // Stamp the discriminant so the new item resolves to its variant.\n const literal = literalValueOf(p);\n if (literal !== undefined)\n (value as Record<string, unknown>)[k] = literal;\n }\n } else {\n value = \"\";\n }\n setItems([...items, { key: nextKey(), value }]);\n if (useTabs) setActiveTab(items.length);\n };\n\n const handleRemove = (index: number) => {\n if (items.length <= min) return;\n if (props.confirmDelete) {\n setPendingDelete(index);\n return;\n }\n doRemove(index);\n };\n\n const doRemove = (index: number) => {\n setItems(items.filter((_, i) => i !== index));\n if (useTabs)\n setActiveTab(Math.max(0, Math.min(activeTab, items.length - 2)));\n };\n\n const handleMove = (index: number, direction: -1 | 1) => {\n const target = index + direction;\n if (target < 0 || target >= items.length) return;\n const next = [...items];\n [next[index], next[target]] = [next[target], next[index]];\n setItems(next);\n if (useTabs) setActiveTab(target);\n };\n\n const updateItem = (index: number, value: unknown) => {\n const next = [...items];\n next[index] = { ...next[index], value };\n setItems(next);\n };\n\n const updateField = (index: number, field: string, value: unknown) => {\n const next = [...items];\n const current = (next[index].value as Record<string, unknown>) ?? {};\n next[index] = { ...next[index], value: { ...current, [field]: value } };\n setItems(next);\n };\n\n const tabName = (i: number): string => {\n if (props.renderTabName) {\n try {\n return props.renderTabName(i, items[i]?.value);\n } catch {\n // fall through\n }\n }\n const value = items[i]?.value as Record<string, unknown> | undefined;\n const tag = discriminant ? value?.[discriminant] : undefined;\n if (typeof tag === \"string\") return `${tag} #${i + 1}`;\n return `${meta.label} #${i + 1}`;\n };\n\n const renderItemBody = (item: ArrayItem, index: number) => {\n // Resolved per item: in a union each row may be a different variant.\n const itemObjectSchema = schemaForValue(item.value);\n const itemFieldNames = itemObjectSchema\n ? Object.keys(z.schema.shape(itemObjectSchema))\n : [];\n return itemObjectSchema ? (\n <div className={`grid gap-3 ${colsClass[columns]}`}>\n {itemFieldNames.map((name) => {\n const fieldProps = {\n ...props.controlProps?.[name],\n ...resolveFieldI18n(\n tr as never,\n props.i18nPrefix,\n name,\n props.controlProps?.[name] ?? {},\n ),\n i18nPrefix: childI18nPrefix(props.i18nPrefix, name),\n };\n // The discriminant decides the item's SHAPE — editing it would\n // invalidate every sibling field, so it is shown read-only.\n const isDiscriminant = !!variants && name === discriminant;\n const fieldInput = buildFieldInput(\n props.input,\n itemObjectSchema,\n name,\n index,\n item.value as Record<string, unknown>,\n (f, v) => updateField(index, f, v),\n );\n return (\n <Control\n key={name}\n input={fieldInput}\n disabled={props.disabled || isDiscriminant}\n {...fieldProps}\n />\n );\n })}\n </div>\n ) : (\n <Control\n input={buildItemInput(props.input, itemSchema, index, item.value, (v) =>\n updateItem(index, v),\n )}\n disabled={props.disabled}\n {...props.itemControlProps}\n />\n );\n };\n\n const itemActions = (index: number) => (\n <div className=\"flex shrink-0 flex-col gap-1\">\n <Button\n type=\"button\"\n variant=\"ghost\"\n size=\"icon\"\n className=\"size-7\"\n disabled={props.disabled || index === 0 || items.length < 2}\n onClick={() => handleMove(index, -1)}\n aria-label={tr(\"controlArray.moveUp\", { default: \"Move up\" })}\n >\n <ArrowUp className=\"size-3.5\" />\n </Button>\n <Button\n type=\"button\"\n variant=\"ghost\"\n size=\"icon\"\n className=\"size-7\"\n disabled={props.disabled || items.length <= min}\n onClick={() => handleRemove(index)}\n aria-label={tr(\"controlArray.remove\", { default: \"Remove\" })}\n >\n <Trash2 className=\"size-3.5\" />\n </Button>\n <Button\n type=\"button\"\n variant=\"ghost\"\n size=\"icon\"\n className=\"size-7\"\n disabled={\n props.disabled || index === items.length - 1 || items.length < 2\n }\n onClick={() => handleMove(index, 1)}\n aria-label={tr(\"controlArray.moveDown\", { default: \"Move down\" })}\n >\n <ArrowDown className=\"size-3.5\" />\n </Button>\n </div>\n );\n\n const flatList = (\n <div className=\"flex flex-col gap-2\">\n {items.map((item, index) => (\n <div\n key={item.key}\n className=\"bg-muted/30 flex items-start gap-2 rounded-md border p-3\"\n >\n <div className=\"min-w-0 flex-1\">{renderItemBody(item, index)}</div>\n {itemActions(index)}\n </div>\n ))}\n </div>\n );\n\n const tabs = useTabs && items.length > 0 && (\n <div className=\"flex flex-col gap-2\">\n <div className=\"flex flex-wrap gap-1 border-b pb-1\">\n {items.map((item, i) => (\n <Button\n key={item.key}\n type=\"button\"\n variant={i === activeTab ? \"default\" : \"ghost\"}\n size=\"sm\"\n onClick={() => setActiveTab(i)}\n >\n {tabName(i)}\n </Button>\n ))}\n </div>\n {items[activeTab] && (\n <div className=\"bg-muted/30 flex items-start gap-2 rounded-md border p-3\">\n <div className=\"min-w-0 flex-1\">\n {renderItemBody(items[activeTab], activeTab)}\n </div>\n {itemActions(activeTab)}\n </div>\n )}\n </div>\n );\n\n const list = (\n <div className=\"flex flex-col gap-2\">{useTabs ? tabs : flatList}</div>\n );\n\n const headerControls = (\n <div className=\"flex items-start gap-3\">\n {variants && variants.length > 1 ? (\n // A union offers a choice of shapes: one Add button per variant,\n // labelled by its discriminant (\"single\", \"period_pass\", …).\n <div className=\"flex shrink-0 flex-wrap gap-1\">\n {variants.map((variant, index) => (\n <Button\n key={variantLabel(variant, discriminant, index)}\n type=\"button\"\n variant=\"outline\"\n size=\"sm\"\n className=\"h-8\"\n disabled={props.disabled || items.length >= max}\n onClick={() => handleAdd(index)}\n >\n <Plus className=\"size-3.5\" />\n {variantLabel(variant, discriminant, index)}\n </Button>\n ))}\n </div>\n ) : (\n <Button\n type=\"button\"\n variant=\"outline\"\n size=\"icon\"\n className=\"size-8 shrink-0\"\n disabled={props.disabled || items.length >= max}\n onClick={() => handleAdd()}\n aria-label={\n props.addLabel ?? tr(\"controlArray.add\", { default: \"Add\" })\n }\n >\n <Plus className=\"size-4\" />\n </Button>\n )}\n <div className=\"flex min-w-0 flex-1 flex-col\">\n <div className=\"text-sm leading-tight font-medium\">\n {meta.label}\n {meta.required && <span className=\"text-destructive ml-0.5\">*</span>}\n <span className=\"text-muted-foreground ml-2 text-xs\">\n ({items.length})\n </span>\n </div>\n {meta.description && (\n <p className=\"text-muted-foreground text-xs leading-tight\">\n {meta.description}\n </p>\n )}\n {meta.error && (\n <p className=\"text-destructive text-xs leading-tight\">{meta.error}</p>\n )}\n </div>\n {items.length > 0 && (\n <Button\n type=\"button\"\n variant=\"ghost\"\n size=\"icon\"\n className=\"size-8 shrink-0\"\n aria-label={\n expanded\n ? tr(\"controlArray.collapse\", { default: \"Collapse\" })\n : tr(\"controlArray.expand\", { default: \"Expand\" })\n }\n onClick={() => setExpanded((e) => !e)}\n >\n {expanded ? (\n <ChevronDown className=\"size-4\" />\n ) : (\n <ChevronRight className=\"size-4\" />\n )}\n </Button>\n )}\n </div>\n );\n\n const confirmContent = (() => {\n if (pendingDelete == null) return null;\n const cd = props.confirmDelete;\n const title =\n typeof cd === \"object\"\n ? (cd.title ??\n tr(\"controlArray.deleteTitle\", { default: \"Delete item\" }))\n : tr(\"controlArray.deleteTitle\", { default: \"Delete item\" });\n const message =\n typeof cd === \"object\"\n ? (cd.message ??\n tr(\"controlArray.deleteConfirm\", {\n default: \"Are you sure you want to delete this item?\",\n }))\n : tr(\"controlArray.deleteConfirm\", {\n default: \"Are you sure you want to delete this item?\",\n });\n return (\n <Dialog\n open={pendingDelete != null}\n onOpenChange={(v) => !v && setPendingDelete(null)}\n >\n <DialogContent>\n <DialogHeader>\n <DialogTitle>{title}</DialogTitle>\n <DialogDescription>{message}</DialogDescription>\n </DialogHeader>\n <DialogFooter>\n <Button variant=\"ghost\" onClick={() => setPendingDelete(null)}>\n {tr(\"controlArray.cancel\", { default: \"Cancel\" })}\n </Button>\n <Button\n variant=\"destructive\"\n onClick={() => {\n doRemove(pendingDelete);\n setPendingDelete(null);\n }}\n >\n {tr(\"controlArray.delete\", { default: \"Delete\" })}\n </Button>\n </DialogFooter>\n </DialogContent>\n </Dialog>\n );\n })();\n\n if (props.variant === \"plain\") {\n return (\n <div className=\"flex flex-col gap-2\">\n {headerControls}\n {expanded && items.length > 0 && list}\n {confirmContent}\n </div>\n );\n }\n\n return (\n <fieldset\n className={`rounded-md border p-3 ${\n meta.error ? \"border-destructive\" : \"border-border\"\n }`}\n >\n {headerControls}\n {expanded && items.length > 0 && <div className=\"mt-3\">{list}</div>}\n {confirmContent}\n </fieldset>\n );\n};\n"],"mappings":";;;;;;;;;;;;AAwHA,MAAM,YAAoC;CACxC,GAAG;CACH,GAAG;CACH,GAAG;CACH,GAAG;AACL;;;;;;;AAQA,MAAM,cAAc,UAClB,SAAS,OAAO,UAAU,YAAY,CAAC,MAAM,QAAQ,KAAK,IACtD,OAAO,KAAK,KAAgC,IAC5C,CAAC;AAEP,MAAM,iBAAiB,UAAsC;CAC3D,MAAM,SAAS,UAAU;CACzB,MAAM,UAAU,OAAO,CAAC;CACxB,MAAM,CAAC,OAAO,iBAAiB,eAA4B;EACzD,MAAM,UAAU,OAAO;EACvB,OAAO,MAAM,QAAQ,OAAO,IACxB,QAAQ,KAAK,WAAW;GAAE,KAAK,QAAQ;GAAW;EAAM,EAAE,IAC1D,CAAC;CACP,CAAC;CAKD,MAAM,WAAW,OAAO,KAAK;CAC7B,SAAS,UAAU;;;;;;;;;;;;;;CAenB,MAAM,cAAc,aACjB,MAAmB,S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,GAAG,8BAA8B,EAC/B,SAAS,6CACX,CAAC,IACD,GAAG,8BAA8B,EAC/B,SAAS,6CACX,CAAC;EACP,OACE,oBAAC,QAAD;GACE,MAAM,iBAAiB;GACvB,eAAe,MAAM,CAAC,KAAK,iBAAiB,IAAI;GAEhD,UAAA,qBAAC,eAAD,EAAA,UAAA,CACE,qBAAC,cAAD,EAAA,UAAA,CACE,oBAAC,aAAD,EAAA,UAAc,MAAmB,CAAA,GACjC,oBAAC,mBAAD,EAAA,UAAoB,QAA2B,CAAA,CACnC,EAAA,CAAA,GACd,qBAAC,cAAD,EAAA,UAAA,CACE,oBAAC,QAAD;IAAQ,SAAQ;IAAQ,eAAe,iBAAiB,IAAI;IACzD,UAAA,GAAG,uBAAuB,EAAE,SAAS,SAAS,CAAC;GAC1C,CAAA,GACR,oBAAC,QAAD;IACE,SAAQ;IACR,eAAe;KACb,SAAS,aAAa;KACtB,iBAAiB,IAAI;IACvB;IAEC,UAAA,GAAG,uBAAuB,EAAE,SAAS,SAAS,CAAC;GAC1C,CAAA,CACI,EAAA,CAAA,CACD,EAAA,CAAA;EACT,CAAA;CAEZ,EAAA,CAAG;CAEH,IAAI,MAAM,YAAY,SACpB,OACE,qBAAC,OAAD;EAAK,WAAU;EAAf,UAAA;GACG;GACA,YAAY,MAAM,SAAS,KAAK;GAChC;EACE;;CAIT,OACE,qBAAC,YAAD;EACE,WAAW,yBACT,KAAK,QAAQ,uBAAuB;EAFxC,UAAA;GAKG;GACA,YAAY,MAAM,SAAS,KAAK,oBAAC,OAAD;IAAK,WAAU;IAAQ,UAAA;GAAU,CAAA;GACjE;EACO;;AAEd"}
|
|
1
|
+
{"version":3,"file":"control-array.js","names":[],"sources":["../../../src/components/control-array/control-array.tsx"],"sourcesContent":["import * as React from \"react\";\n\nvoid React;\n\nimport {\n Control,\n type ControlProps,\n} from \"@alepha/ui/components/control/control\";\nimport { Button } from \"@alepha/ui/components/ui/button\";\nimport {\n Dialog,\n DialogContent,\n DialogDescription,\n DialogFooter,\n DialogHeader,\n DialogTitle,\n} from \"@alepha/ui/components/ui/dialog\";\nimport { type ZObject, type ZType, z } from \"alepha\";\nimport { useAlepha } from \"alepha/react\";\nimport {\n type BaseInputField,\n parseField,\n unionVariants,\n useFormState,\n} from \"alepha/react/form\";\nimport { useI18n } from \"alepha/react/i18n\";\nimport {\n ArrowDown,\n ArrowUp,\n ChevronDown,\n ChevronRight,\n Plus,\n Trash2,\n} from \"lucide-react\";\nimport { useCallback, useEffect, useRef, useState } from \"react\";\n\nimport {\n childI18nPrefix,\n resolveFieldI18n,\n} from \"../control-base/field-i18n.ts\";\n\ninterface ArrayItem {\n key: number;\n value: unknown;\n}\n\nexport interface ControlArrayProps {\n /**\n * Bound array `InputField` from `useForm`.\n */\n input: BaseInputField;\n /**\n * Dictionary prefix for the item fields: each reads `<prefix>.<field>` and\n * `<prefix>.<field>.desc` (the index is not part of the key — every row of\n * the list shares one label).\n */\n i18nPrefix?: string;\n /**\n * Field label. Falls back to schema `title`.\n */\n label?: string;\n /**\n * Helper text shown below the array.\n */\n description?: string;\n /**\n * Minimum number of items (Add button disables when reached).\n */\n min?: number;\n /**\n * Maximum number of items (Add button disables when reached).\n */\n max?: number;\n /**\n * Override the \"Add item\" button label.\n */\n addLabel?: string;\n /**\n * Number of grid columns for each item's inner fields.\n */\n columns?: 1 | 2 | 3 | 4;\n /**\n * \"fieldset\" wraps in a bordered container with legend; \"plain\" renders items only.\n */\n variant?: \"fieldset\" | \"plain\";\n /**\n * Per-field `<Control>` overrides for items, keyed by inner field name.\n */\n controlProps?: Record<string, Partial<Omit<ControlProps, \"input\">>>;\n /**\n * Override props applied to every item (when items are primitive, not objects).\n */\n itemControlProps?: Partial<Omit<ControlProps, \"input\">>;\n /**\n * Disable add/remove and all inner controls.\n */\n disabled?: boolean;\n\n /**\n * Default expanded state. @default true\n */\n defaultExpanded?: boolean;\n\n /**\n * Confirm before deleting an item. Pass `true` for default copy or an\n * object to override title/message.\n */\n confirmDelete?: boolean | { title?: string; message?: string };\n\n /**\n * Compute the visible label for each item header (and tab name in tabs mode).\n */\n renderTabName?: (i: number, value: unknown) => string;\n\n /**\n * Force tabs mode even for short arrays. Default heuristic: items > 4 OR nested object/array fields.\n */\n forceTabs?: boolean;\n}\n\nconst colsClass: Record<number, string> = {\n 1: \"grid-cols-1\",\n 2: \"grid-cols-2\",\n 3: \"grid-cols-3\",\n 4: \"grid-cols-4\",\n};\n\n/**\n * The keys of a plain object, or nothing.\n *\n * An item that is not an object has no per-field inputs, so there is nothing\n * below it to notify.\n */\nconst objectKeys = (value: unknown): string[] =>\n value && typeof value === \"object\" && !Array.isArray(value)\n ? Object.keys(value as Record<string, unknown>)\n : [];\n\nconst useArrayItems = (input: BaseInputField | undefined) => {\n const alepha = useAlepha();\n const counter = useRef(0);\n const [items, setItemsState] = useState<ArrayItem[]>(() => {\n const initial = input?.initialValue;\n return Array.isArray(initial)\n ? initial.map((value) => ({ key: counter.current++, value }))\n : [];\n });\n\n // The list as last rendered, so a write can diff against it without\n // `setItems` depending on `items` (which would rebuild the callback, and\n // with it every row, on each keystroke).\n const itemsRef = useRef(items);\n itemsRef.current = items;\n\n /**\n * Tell the CHILD paths what changed.\n *\n * `input.set()` writes the whole array and `FormModel` emits `form:change`\n * for the array's own path only. The per-item and per-field inputs this\n * component builds carry paths of their own (`.../2/name`), so a child\n * subscribed through `useFieldValue` never heard about its own edit and\n * kept re-rendering the value it had at mount.\n *\n * Only what actually differs is emitted: this event is how a row avoids\n * re-rendering when a sibling changes, and announcing every path on every\n * keystroke would give that up.\n */\n const emitChanged = useCallback(\n (prev: ArrayItem[], next: ArrayItem[]) => {\n const form = input?.form;\n if (!form || !input) return;\n\n const emit = (path: string, value: unknown) =>\n void alepha.events.emit(\n \"form:change\",\n { id: form.id, path, value },\n { catch: true },\n );\n\n for (let i = 0; i < Math.max(prev.length, next.length); i++) {\n const before = prev[i]?.value;\n const after = next[i]?.value;\n if (before === after) continue;\n\n emit(`${input.path}/${i}`, after);\n\n for (const key of new Set([\n ...objectKeys(before),\n ...objectKeys(after),\n ])) {\n const beforeField = (before as Record<string, unknown>)?.[key];\n const afterField = (after as Record<string, unknown>)?.[key];\n if (beforeField !== afterField) {\n emit(`${input.path}/${i}/${key}`, afterField);\n }\n }\n }\n },\n [alepha, input],\n );\n\n const sync = useCallback(\n (next: unknown[] | undefined) => {\n if (!Array.isArray(next)) {\n emitChanged(itemsRef.current, []);\n setItemsState([]);\n return;\n }\n if (\n itemsRef.current.length === next.length &&\n itemsRef.current.every((it, i) => it.value === next[i])\n ) {\n return;\n }\n counter.current = 0;\n const rebuilt = next.map((value) => ({ key: counter.current++, value }));\n // A reset or a `setInitialValues` writes the array whole, so the child\n // paths need telling here too - same reason as an edit.\n emitChanged(itemsRef.current, rebuilt);\n setItemsState(rebuilt);\n },\n [emitChanged],\n );\n\n useEffect(() => {\n if (!input?.form) return;\n const formId = input.form.id;\n const path = input.path;\n return alepha.events.on(\"form:change\", (e) => {\n if (e.id === formId && e.path === path) sync(e.value as unknown[]);\n });\n }, [alepha, input, sync]);\n\n const setItems = useCallback(\n (next: ArrayItem[]) => {\n const prev = itemsRef.current;\n setItemsState(next);\n input?.set(next.map((it) => it.value));\n emitChanged(prev, next);\n },\n [input, emitChanged],\n );\n\n return { items, setItems, nextKey: () => counter.current++ };\n};\n\n/**\n * Discriminated-union support for item schemas.\n *\n * `z.array(z.union([...objects]))` is how a heterogeneous list is spelled. The\n * variants almost always differ by one literal property (`kind`, `type`, …),\n * which is enough to (a) tell which variant an existing item is and (b) label\n * the choice offered when adding one. Everything below degrades quietly: no\n * union, or no discriminant, and the array behaves exactly as before.\n */\nconst objectVariants = (itemSchema: ZType): ZObject[] | null => {\n const variants = unionVariants(itemSchema);\n if (!variants?.length) return null;\n const objects = variants\n .map((variant) => z.schema.unwrap(variant))\n .filter((variant) => z.schema.isObject(variant)) as ZObject[];\n return objects.length === variants.length ? objects : null;\n};\n\n/**\n * The property whose value identifies the variant (a literal in every variant).\n */\nconst discriminantOf = (variants: ZObject[]): string | null => {\n const [first] = variants;\n if (!first) return null;\n for (const name of Object.keys(z.schema.shape(first))) {\n const values = variants.map((variant) =>\n literalValueOf(z.schema.shape(variant)[name]),\n );\n if (values.every((value) => typeof value === \"string\")) {\n const unique = new Set(values as string[]);\n if (unique.size === variants.length) return name;\n }\n }\n return null;\n};\n\n/**\n * The single allowed value of a literal/const schema, if it is one.\n */\nconst literalValueOf = (schema: unknown): unknown => {\n if (!schema) return undefined;\n const inner = z.schema.unwrap(schema as ZType) as {\n const?: unknown;\n values?: unknown[] | Set<unknown>;\n _zod?: { def?: { values?: unknown[] } };\n };\n if (inner?.const !== undefined) return inner.const;\n // zod spells a literal's allowed values as `_zod.def.values` (an array);\n // the public `.values` is a Set, so normalise both.\n const raw = inner?._zod?.def?.values ?? inner?.values;\n const values =\n raw instanceof Set ? [...raw] : Array.isArray(raw) ? raw : undefined;\n return values?.length === 1 ? values[0] : undefined;\n};\n\n/**\n * Label for a variant: its discriminant value, else its index.\n */\nconst variantLabel = (\n variant: ZObject,\n discriminant: string | null,\n index: number,\n): string => {\n const value = discriminant\n ? literalValueOf(z.schema.shape(variant)[discriminant])\n : undefined;\n return typeof value === \"string\" ? value : `#${index + 1}`;\n};\n\nconst buildItemInput = (\n parent: BaseInputField,\n schema: ZType,\n index: number,\n value: unknown,\n onChange: (v: unknown) => void,\n): BaseInputField => ({\n schema,\n path: `${parent.path}/${index}`,\n required: false,\n form: parent.form,\n initialValue: value,\n props: {\n id: `${parent.props.id}-${index}`,\n name: `${parent.props.name}[${index}]`,\n },\n set: onChange,\n});\n\nconst buildFieldInput = (\n parent: BaseInputField,\n itemSchema: ZObject,\n fieldName: string,\n index: number,\n itemValue: Record<string, unknown> | undefined,\n onFieldChange: (field: string, value: unknown) => void,\n): BaseInputField => ({\n schema: z.schema.shape(itemSchema)[fieldName],\n path: `${parent.path}/${index}/${fieldName}`,\n required: z.schema.requiredKeys(itemSchema).includes(fieldName),\n form: parent.form,\n initialValue: itemValue?.[fieldName],\n props: {\n id: `${parent.props.id}-${index}-${fieldName}`,\n name: `${parent.props.name}[${index}].${fieldName}`,\n },\n set: (v: unknown) => onFieldChange(fieldName, v),\n});\n\nexport const ControlArray = (props: ControlArrayProps) => {\n const form = useFormState(props.input, [\"error\"]);\n const { tr } = useI18n();\n const { items, setItems, nextKey } = useArrayItems(props.input);\n const [expanded, setExpanded] = useState(props.defaultExpanded ?? true);\n const [activeTab, setActiveTab] = useState(0);\n const [pendingDelete, setPendingDelete] = useState<number | null>(null);\n\n if (!props.input?.props) return null;\n\n const meta = parseField(props.input, {\n label: props.label,\n description: props.description,\n error: form.error,\n });\n\n const schema = props.input.schema;\n // `isArray`, not `\"items\" in schema`: that spelling tested for a prototype\n // alias rather than for an array schema, so it answered false once the alias\n // went away — and the whole control rendered nothing, Add button included.\n if (!z.schema.isArray(schema)) return null;\n\n // `z.schema.element`, not `.items`: the latter only ever resolved through a\n // prototype alias on ZodArray, so it silently became `undefined` — and with\n // no item schema the control renders neither fields nor tabs.\n const itemSchema = z.schema.element(schema) as ZType;\n const variants = objectVariants(itemSchema);\n const discriminant = variants ? discriminantOf(variants) : null;\n\n /**\n * The object schema to edit an item with. For a union that is the variant the\n * item's discriminant points at (first variant as a fallback, e.g. a freshly\n * added item), so each row renders exactly its own fields.\n */\n const schemaForValue = (value: unknown): ZObject | null => {\n if (!variants) {\n // `isObject`, not `\"properties\" in itemSchema`: the latter tested for a\n // prototype alias, so it answered false as soon as the alias went away.\n return z.schema.isObject(itemSchema) ? (itemSchema as ZObject) : null;\n }\n if (discriminant && value && typeof value === \"object\") {\n const tag = (value as Record<string, unknown>)[discriminant];\n const match = variants.find(\n (variant) =>\n literalValueOf(z.schema.shape(variant)[discriminant]) === tag,\n );\n if (match) return match;\n }\n return variants[0] ?? null;\n };\n\n const objectItemSchema = schemaForValue(items[0]?.value);\n const fieldNames = objectItemSchema\n ? Object.keys(z.schema.shape(objectItemSchema))\n : [];\n\n // Schema-driven max/min if present: `z.array().max(3)` lands in zod's\n // constraint bag, the JSON-schema `maxItems` names never existed here.\n const bounds =\n (z.schema.unwrap(schema) as { _zod?: { bag?: Record<string, unknown> } })\n ._zod?.bag ?? {};\n const schemaMax =\n typeof bounds.maximum === \"number\" ? bounds.maximum : undefined;\n const schemaMin =\n typeof bounds.minimum === \"number\" ? bounds.minimum : undefined;\n const min = props.min ?? schemaMin ?? 0;\n const max = props.max ?? schemaMax ?? Number.POSITIVE_INFINITY;\n const columns = props.columns ?? 1;\n\n // Tabs heuristic: forced or nested complex item or many items\n const hasComplexFields = objectItemSchema\n ? fieldNames.some((n) => {\n const inner = z.schema.unwrap(z.schema.shape(objectItemSchema)[n]);\n return z.schema.isObject(inner) || z.schema.isArray(inner);\n })\n : false;\n const useTabs =\n props.forceTabs ||\n (objectItemSchema && (items.length > 4 || hasComplexFields));\n\n const handleAdd = (variantIndex = 0) => {\n if (items.length >= max) return;\n const shape = variants ? variants[variantIndex] : objectItemSchema;\n let value: unknown;\n if (shape) {\n value = {};\n for (const [k, p] of Object.entries(z.schema.shape(shape))) {\n const def = z.schema.getDefault(p);\n if (def !== undefined) (value as Record<string, unknown>)[k] = def;\n // Stamp the discriminant so the new item resolves to its variant.\n const literal = literalValueOf(p);\n if (literal !== undefined)\n (value as Record<string, unknown>)[k] = literal;\n }\n } else {\n value = \"\";\n }\n setItems([...items, { key: nextKey(), value }]);\n if (useTabs) setActiveTab(items.length);\n };\n\n const handleRemove = (index: number) => {\n if (items.length <= min) return;\n if (props.confirmDelete) {\n setPendingDelete(index);\n return;\n }\n doRemove(index);\n };\n\n const doRemove = (index: number) => {\n setItems(items.filter((_, i) => i !== index));\n if (useTabs)\n setActiveTab(Math.max(0, Math.min(activeTab, items.length - 2)));\n };\n\n const handleMove = (index: number, direction: -1 | 1) => {\n const target = index + direction;\n if (target < 0 || target >= items.length) return;\n const next = [...items];\n [next[index], next[target]] = [next[target], next[index]];\n setItems(next);\n if (useTabs) setActiveTab(target);\n };\n\n const updateItem = (index: number, value: unknown) => {\n const next = [...items];\n next[index] = { ...next[index], value };\n setItems(next);\n };\n\n const updateField = (index: number, field: string, value: unknown) => {\n const next = [...items];\n const current = (next[index].value as Record<string, unknown>) ?? {};\n next[index] = { ...next[index], value: { ...current, [field]: value } };\n setItems(next);\n };\n\n const tabName = (i: number): string => {\n if (props.renderTabName) {\n try {\n return props.renderTabName(i, items[i]?.value);\n } catch {\n // fall through\n }\n }\n const value = items[i]?.value as Record<string, unknown> | undefined;\n const tag = discriminant ? value?.[discriminant] : undefined;\n if (typeof tag === \"string\") return `${tag} #${i + 1}`;\n return `${meta.label} #${i + 1}`;\n };\n\n const renderItemBody = (item: ArrayItem, index: number) => {\n // Resolved per item: in a union each row may be a different variant.\n const itemObjectSchema = schemaForValue(item.value);\n const itemFieldNames = itemObjectSchema\n ? Object.keys(z.schema.shape(itemObjectSchema))\n : [];\n return itemObjectSchema ? (\n <div className={`grid gap-3 ${colsClass[columns]}`}>\n {itemFieldNames.map((name) => {\n const fieldProps = {\n ...props.controlProps?.[name],\n ...resolveFieldI18n(\n tr as never,\n props.i18nPrefix,\n name,\n props.controlProps?.[name] ?? {},\n ),\n i18nPrefix: childI18nPrefix(props.i18nPrefix, name),\n };\n // The discriminant decides the item's SHAPE — editing it would\n // invalidate every sibling field, so it is shown read-only.\n const isDiscriminant = !!variants && name === discriminant;\n const fieldInput = buildFieldInput(\n props.input,\n itemObjectSchema,\n name,\n index,\n item.value as Record<string, unknown>,\n (f, v) => updateField(index, f, v),\n );\n return (\n <Control\n key={name}\n input={fieldInput}\n disabled={props.disabled || isDiscriminant}\n {...fieldProps}\n />\n );\n })}\n </div>\n ) : (\n <Control\n input={buildItemInput(props.input, itemSchema, index, item.value, (v) =>\n updateItem(index, v),\n )}\n disabled={props.disabled}\n {...props.itemControlProps}\n />\n );\n };\n\n const itemActions = (index: number) => (\n <div className=\"flex shrink-0 flex-col gap-1\">\n <Button\n type=\"button\"\n variant=\"ghost\"\n size=\"icon\"\n className=\"size-7\"\n disabled={props.disabled || index === 0 || items.length < 2}\n onClick={() => handleMove(index, -1)}\n aria-label={tr(\"controlArray.moveUp\", { default: \"Move up\" })}\n >\n <ArrowUp className=\"size-3.5\" />\n </Button>\n <Button\n type=\"button\"\n variant=\"ghost\"\n size=\"icon\"\n className=\"size-7\"\n disabled={props.disabled || items.length <= min}\n onClick={() => handleRemove(index)}\n aria-label={tr(\"controlArray.remove\", { default: \"Remove\" })}\n >\n <Trash2 className=\"size-3.5\" />\n </Button>\n <Button\n type=\"button\"\n variant=\"ghost\"\n size=\"icon\"\n className=\"size-7\"\n disabled={\n props.disabled || index === items.length - 1 || items.length < 2\n }\n onClick={() => handleMove(index, 1)}\n aria-label={tr(\"controlArray.moveDown\", { default: \"Move down\" })}\n >\n <ArrowDown className=\"size-3.5\" />\n </Button>\n </div>\n );\n\n const flatList = (\n <div className=\"flex flex-col gap-2\">\n {items.map((item, index) => (\n <div\n key={item.key}\n className=\"bg-muted/30 flex items-start gap-2 rounded-md border p-3\"\n >\n <div className=\"min-w-0 flex-1\">{renderItemBody(item, index)}</div>\n {itemActions(index)}\n </div>\n ))}\n </div>\n );\n\n const tabs = useTabs && items.length > 0 && (\n <div className=\"flex flex-col gap-2\">\n <div className=\"flex flex-wrap gap-1 border-b pb-1\">\n {items.map((item, i) => (\n <Button\n key={item.key}\n type=\"button\"\n variant={i === activeTab ? \"default\" : \"ghost\"}\n size=\"sm\"\n onClick={() => setActiveTab(i)}\n >\n {tabName(i)}\n </Button>\n ))}\n </div>\n {items[activeTab] && (\n <div className=\"bg-muted/30 flex items-start gap-2 rounded-md border p-3\">\n <div className=\"min-w-0 flex-1\">\n {renderItemBody(items[activeTab], activeTab)}\n </div>\n {itemActions(activeTab)}\n </div>\n )}\n </div>\n );\n\n const list = (\n <div className=\"flex flex-col gap-2\">{useTabs ? tabs : flatList}</div>\n );\n\n const headerControls = (\n <div className=\"flex items-start gap-3\">\n {variants && variants.length > 1 ? (\n // A union offers a choice of shapes: one Add button per variant,\n // labelled by its discriminant (\"single\", \"period_pass\", …).\n <div className=\"flex shrink-0 flex-wrap gap-1\">\n {variants.map((variant, index) => (\n <Button\n key={variantLabel(variant, discriminant, index)}\n type=\"button\"\n variant=\"outline\"\n size=\"sm\"\n className=\"h-8\"\n disabled={props.disabled || items.length >= max}\n onClick={() => handleAdd(index)}\n >\n <Plus className=\"size-3.5\" />\n {variantLabel(variant, discriminant, index)}\n </Button>\n ))}\n </div>\n ) : (\n <Button\n type=\"button\"\n variant=\"outline\"\n size=\"icon\"\n className=\"size-8 shrink-0\"\n disabled={props.disabled || items.length >= max}\n onClick={() => handleAdd()}\n aria-label={\n props.addLabel ?? tr(\"controlArray.add\", { default: \"Add\" })\n }\n >\n <Plus className=\"size-4\" />\n </Button>\n )}\n <div className=\"flex min-w-0 flex-1 flex-col\">\n <div className=\"text-sm leading-tight font-medium\">\n {meta.label}\n {meta.required && <span className=\"text-destructive ml-0.5\">*</span>}\n <span className=\"text-muted-foreground ml-2 text-xs\">\n ({items.length})\n </span>\n </div>\n {meta.description && (\n <p className=\"text-muted-foreground text-xs leading-tight\">\n {meta.description}\n </p>\n )}\n {meta.error && (\n <p className=\"text-destructive text-xs leading-tight\">{meta.error}</p>\n )}\n </div>\n {items.length > 0 && (\n <Button\n type=\"button\"\n variant=\"ghost\"\n size=\"icon\"\n className=\"size-8 shrink-0\"\n aria-label={\n expanded\n ? tr(\"controlArray.collapse\", { default: \"Collapse\" })\n : tr(\"controlArray.expand\", { default: \"Expand\" })\n }\n onClick={() => setExpanded((e) => !e)}\n >\n {expanded ? (\n <ChevronDown className=\"size-4\" />\n ) : (\n <ChevronRight className=\"size-4\" />\n )}\n </Button>\n )}\n </div>\n );\n\n const confirmContent = (() => {\n if (pendingDelete == null) return null;\n const cd = props.confirmDelete;\n const title =\n typeof cd === \"object\"\n ? (cd.title ??\n tr(\"controlArray.deleteTitle\", { default: \"Delete item\" }))\n : tr(\"controlArray.deleteTitle\", { default: \"Delete item\" });\n const message =\n typeof cd === \"object\"\n ? (cd.message ??\n tr(\"controlArray.deleteConfirm\", {\n default: \"Are you sure you want to delete this item?\",\n }))\n : tr(\"controlArray.deleteConfirm\", {\n default: \"Are you sure you want to delete this item?\",\n });\n return (\n <Dialog\n open={pendingDelete != null}\n onOpenChange={(v) => !v && setPendingDelete(null)}\n >\n <DialogContent>\n <DialogHeader>\n <DialogTitle>{title}</DialogTitle>\n <DialogDescription>{message}</DialogDescription>\n </DialogHeader>\n <DialogFooter>\n <Button variant=\"ghost\" onClick={() => setPendingDelete(null)}>\n {tr(\"controlArray.cancel\", { default: \"Cancel\" })}\n </Button>\n <Button\n variant=\"destructive\"\n onClick={() => {\n doRemove(pendingDelete);\n setPendingDelete(null);\n }}\n >\n {tr(\"controlArray.delete\", { default: \"Delete\" })}\n </Button>\n </DialogFooter>\n </DialogContent>\n </Dialog>\n );\n })();\n\n if (props.variant === \"plain\") {\n return (\n <div className=\"flex flex-col gap-2\">\n {headerControls}\n {expanded && items.length > 0 && list}\n {confirmContent}\n </div>\n );\n }\n\n return (\n <fieldset\n className={`rounded-md border p-3 ${\n meta.error ? \"border-destructive\" : \"border-border\"\n }`}\n >\n {headerControls}\n {expanded && items.length > 0 && <div className=\"mt-3\">{list}</div>}\n {confirmContent}\n </fieldset>\n );\n};\n"],"mappings":";;;;;;;;;;;;AAwHA,MAAM,YAAoC;CACxC,GAAG;CACH,GAAG;CACH,GAAG;CACH,GAAG;AACL;;;;;;;AAQA,MAAM,cAAc,UAClB,SAAS,OAAO,UAAU,YAAY,CAAC,MAAM,QAAQ,KAAK,IACtD,OAAO,KAAK,KAAgC,IAC5C,CAAC;AAEP,MAAM,iBAAiB,UAAsC;CAC3D,MAAM,SAAS,UAAU;CACzB,MAAM,UAAU,OAAO,CAAC;CACxB,MAAM,CAAC,OAAO,iBAAiB,eAA4B;EACzD,MAAM,UAAU,OAAO;EACvB,OAAO,MAAM,QAAQ,OAAO,IACxB,QAAQ,KAAK,WAAW;GAAE,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|
|
2
2
|
import { type BaseInputField } from "alepha/react/form";
|
|
3
|
+
import type { DayPickerProps } from "react-day-picker";
|
|
3
4
|
export interface ControlDateProps {
|
|
4
5
|
/**
|
|
5
6
|
* Bound `InputField` from `useForm`. Stores an ISO string.
|
|
@@ -37,6 +38,32 @@ export interface ControlDateProps {
|
|
|
37
38
|
* control in the kit spells this `clearable`, so this one does too.
|
|
38
39
|
*/
|
|
39
40
|
clearable?: boolean;
|
|
41
|
+
/**
|
|
42
|
+
* Caption style. `"label"` (the default) shows the month name with
|
|
43
|
+
* previous/next arrows; `"dropdown"` swaps both for month and year selects.
|
|
44
|
+
*
|
|
45
|
+
* Arrows are fine for a date near today and hopeless for one that is not:
|
|
46
|
+
* reaching a 1988 birthday costs about 450 clicks on `<`. Pair `"dropdown"`
|
|
47
|
+
* with {@link startMonth} / {@link endMonth}, or use {@link birthdate},
|
|
48
|
+
* which sets both.
|
|
49
|
+
*/
|
|
50
|
+
captionLayout?: DayPickerProps["captionLayout"];
|
|
51
|
+
/**
|
|
52
|
+
* First selectable month. Also bounds the year dropdown, which otherwise
|
|
53
|
+
* offers a narrow range around today.
|
|
54
|
+
*/
|
|
55
|
+
startMonth?: Date;
|
|
56
|
+
/** Last selectable month. */
|
|
57
|
+
endMonth?: Date;
|
|
58
|
+
/**
|
|
59
|
+
* Shorthand for a date of birth: a year dropdown covering the last
|
|
60
|
+
* {@link BIRTHDATE_YEARS} years, ending this year.
|
|
61
|
+
*
|
|
62
|
+
* Sugar over `captionLayout` + `startMonth` / `endMonth`, which stay
|
|
63
|
+
* available for any other historical field. An explicit value for one of
|
|
64
|
+
* those wins over what this sets.
|
|
65
|
+
*/
|
|
66
|
+
birthdate?: boolean;
|
|
40
67
|
}
|
|
41
68
|
export declare const ControlDate: (props: ControlDateProps) => React.JSX.Element | null;
|
|
42
69
|
//# sourceMappingURL=control-date.d.ts.map
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"control-date.d.ts","sourceRoot":"","sources":["../../../src/components/control-date/control-date.tsx"],"names":[],"mappings":"AAAA,OAAO,KAAK,KAAK,MAAM,OAAO,CAAC;
|
|
1
|
+
{"version":3,"file":"control-date.d.ts","sourceRoot":"","sources":["../../../src/components/control-date/control-date.tsx"],"names":[],"mappings":"AAAA,OAAO,KAAK,KAAK,MAAM,OAAO,CAAC;AAmB/B,OAAO,EACL,KAAK,cAAc,EAIpB,MAAM,mBAAmB,CAAC;AAQ3B,OAAO,KAAK,EAAE,cAAc,EAAE,MAAM,kBAAkB,CAAC;AAMvD,MAAM,WAAW,gBAAgB;IAC/B;;OAEG;IACH,KAAK,EAAE,cAAc,CAAC;IACtB;;OAEG;IACH,KAAK,CAAC,EAAE,MAAM,CAAC;IACf;;OAEG;IACH,WAAW,CAAC,EAAE,MAAM,CAAC;IACrB;;OAEG;IACH,IAAI,CAAC,EAAE,OAAO,CAAC;IACf;;OAEG;IACH,QAAQ,CAAC,EAAE,OAAO,CAAC;IACnB;;OAEG;IACH,IAAI,CAAC,EAAE,OAAO,CAAC;IACf;;OAEG;IACH,QAAQ,CAAC,EAAE,OAAO,CAAC;IACnB;;;;;;OAMG;IACH,SAAS,CAAC,EAAE,OAAO,CAAC;IACpB;;;;;;;;OAQG;IACH,aAAa,CAAC,EAAE,cAAc,CAAC,eAAe,CAAC,CAAC;IAChD;;;OAGG;IACH,UAAU,CAAC,EAAE,IAAI,CAAC;IAClB,6BAA6B;IAC7B,QAAQ,CAAC,EAAE,IAAI,CAAC;IAChB;;;;;;;OAOG;IACH,SAAS,CAAC,EAAE,OAAO,CAAC;CACrB;AAED,eAAO,MAAM,WAAW,UAAW,gBAAgB,6BAyElD,CAAC"}
|
|
@@ -2,6 +2,7 @@ import { cn } from "../../lib/utils.js";
|
|
|
2
2
|
import { Button } from "../ui/button.js";
|
|
3
3
|
import { Input } from "../ui/input.js";
|
|
4
4
|
import { FormField } from "../control-base/form-field.js";
|
|
5
|
+
import { DATE_ONLY, formatDateOnly, parseDateOnly } from "./date-only.js";
|
|
5
6
|
import { Calendar as Calendar$1 } from "../ui/calendar.js";
|
|
6
7
|
import { Popover, PopoverContent, PopoverTrigger } from "../ui/popover.js";
|
|
7
8
|
import { useState } from "react";
|
|
@@ -9,6 +10,9 @@ import { jsx, jsxs } from "react/jsx-runtime";
|
|
|
9
10
|
import { Calendar, ChevronDown, Clock, X } from "lucide-react";
|
|
10
11
|
import { parseField, useFieldValue, useFormState } from "alepha/react/form";
|
|
11
12
|
//#region src/components/control-date/control-date.tsx
|
|
13
|
+
/** How many years back a `birthdate` picker offers. Covers every living
|
|
14
|
+
* person; the oldest verified human reached 122. */
|
|
15
|
+
const BIRTHDATE_YEARS = 120;
|
|
12
16
|
const ControlDate = (props) => {
|
|
13
17
|
const form = useFormState(props.input, ["error"]);
|
|
14
18
|
const [value, setValue] = useFieldValue(props.input);
|
|
@@ -38,6 +42,7 @@ const ControlDate = (props) => {
|
|
|
38
42
|
})]
|
|
39
43
|
})
|
|
40
44
|
});
|
|
45
|
+
const thisYear = (/* @__PURE__ */ new Date()).getFullYear();
|
|
41
46
|
return /* @__PURE__ */ jsx(FormField, {
|
|
42
47
|
id: meta.id,
|
|
43
48
|
label: meta.label,
|
|
@@ -50,26 +55,13 @@ const ControlDate = (props) => {
|
|
|
50
55
|
withTime: isDateTime,
|
|
51
56
|
disabled: props.disabled,
|
|
52
57
|
clearable: props.clearable,
|
|
58
|
+
captionLayout: props.captionLayout ?? (props.birthdate ? "dropdown" : void 0),
|
|
59
|
+
startMonth: props.startMonth ?? (props.birthdate ? new Date(thisYear - BIRTHDATE_YEARS, 0, 1) : void 0),
|
|
60
|
+
endMonth: props.endMonth ?? (props.birthdate ? new Date(thisYear, 11, 31) : void 0),
|
|
53
61
|
onChange: (v) => setValue(v)
|
|
54
62
|
})
|
|
55
63
|
});
|
|
56
64
|
};
|
|
57
|
-
/**
|
|
58
|
-
* A date-only value (`YYYY-MM-DD`) names a calendar day, so it is parsed
|
|
59
|
-
* and formatted in local parts: `new Date("2026-08-23")` is UTC midnight,
|
|
60
|
-
* which displays as the 22nd west of Greenwich, and `toISOString()` on a
|
|
61
|
-
* local midnight stores the previous day east of it.
|
|
62
|
-
*/
|
|
63
|
-
const parseDateOnly = (value) => {
|
|
64
|
-
const [year, month, day] = value.split("-").map(Number);
|
|
65
|
-
return new Date(year, month - 1, day);
|
|
66
|
-
};
|
|
67
|
-
const formatDateOnly = (date) => {
|
|
68
|
-
const month = String(date.getMonth() + 1).padStart(2, "0");
|
|
69
|
-
const day = String(date.getDate()).padStart(2, "0");
|
|
70
|
-
return `${date.getFullYear()}-${month}-${day}`;
|
|
71
|
-
};
|
|
72
|
-
const DATE_ONLY = /^\d{4}-\d{2}-\d{2}$/;
|
|
73
65
|
const DatePopover = (props) => {
|
|
74
66
|
const [open, setOpen] = useState(false);
|
|
75
67
|
const date = props.value ? !props.withTime && DATE_ONLY.test(props.value) ? parseDateOnly(props.value) : new Date(props.value) : void 0;
|
|
@@ -102,12 +94,13 @@ const DatePopover = (props) => {
|
|
|
102
94
|
children: [/* @__PURE__ */ jsxs(PopoverTrigger, {
|
|
103
95
|
render: /* @__PURE__ */ jsx(Button, {
|
|
104
96
|
id: props.id,
|
|
97
|
+
"data-slot": "date-trigger",
|
|
105
98
|
variant: "outline",
|
|
106
99
|
disabled: props.disabled,
|
|
107
|
-
className: cn("flex-1 justify-start text-left font-normal", !date && "text-muted-foreground")
|
|
100
|
+
className: cn("flex-1 justify-start text-left font-normal", "border-input", "hover:bg-background aria-expanded:bg-background", !date && "text-muted-foreground hover:text-muted-foreground aria-expanded:text-muted-foreground")
|
|
108
101
|
}),
|
|
109
102
|
children: [
|
|
110
|
-
/* @__PURE__ */ jsx(Calendar, { className: "mr-2 size-4" }),
|
|
103
|
+
/* @__PURE__ */ jsx(Calendar, { className: "text-muted-foreground mr-2 size-4" }),
|
|
111
104
|
formatted || "Pick a date",
|
|
112
105
|
/* @__PURE__ */ jsx(ChevronDown, { className: "text-muted-foreground pointer-events-none ml-auto size-4 shrink-0" })
|
|
113
106
|
]
|
|
@@ -125,7 +118,10 @@ const DatePopover = (props) => {
|
|
|
125
118
|
children: [/* @__PURE__ */ jsx(Calendar$1, {
|
|
126
119
|
mode: "single",
|
|
127
120
|
selected: date,
|
|
128
|
-
onSelect: handleDate
|
|
121
|
+
onSelect: handleDate,
|
|
122
|
+
captionLayout: props.captionLayout,
|
|
123
|
+
startMonth: props.startMonth,
|
|
124
|
+
endMonth: props.endMonth
|
|
129
125
|
}), props.withTime && /* @__PURE__ */ jsx("div", {
|
|
130
126
|
className: "border-t p-3",
|
|
131
127
|
children: /* @__PURE__ */ jsx(Input, {
|