@eifi1/ui-kit 0.51.6 → 0.52.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 +146 -26
- package/dist/account/account-parts.d.ts +10 -8
- package/dist/account/account-parts.js +1 -18
- package/dist/account/account-parts.js.map +1 -1
- package/dist/account/data-export-setting-labels.js +1 -1
- package/dist/account/data-export-setting-labels.js.map +1 -1
- package/dist/account/delete-account-setting-labels.js +1 -1
- package/dist/account/delete-account-setting-labels.js.map +1 -1
- package/dist/account/email-change-setting-labels.js +1 -1
- package/dist/account/email-change-setting-labels.js.map +1 -1
- package/dist/account/passkeys-setting.d.ts +9 -2
- package/dist/account/passkeys-setting.js +41 -29
- package/dist/account/passkeys-setting.js.map +1 -1
- package/dist/account/sessions-setting.d.ts +3 -2
- package/dist/account/sessions-setting.js +10 -8
- package/dist/account/sessions-setting.js.map +1 -1
- package/dist/admin/admin-action-confirm.js +3 -7
- package/dist/admin/admin-action-confirm.js.map +1 -1
- package/dist/admin/admin-parts.d.ts +6 -3
- package/dist/admin/admin-parts.js +6 -21
- package/dist/admin/admin-parts.js.map +1 -1
- package/dist/admin/mail-test-card-labels.js +1 -1
- package/dist/admin/mail-test-card-labels.js.map +1 -1
- package/dist/admin/plan-change-labels.d.ts +2 -2
- package/dist/admin/plan-change-labels.js +1 -17
- package/dist/admin/plan-change-labels.js.map +1 -1
- package/dist/admin/plan-change.d.ts +3 -42
- package/dist/admin/plan-change.js +1 -1
- package/dist/admin/plan-change.js.map +1 -1
- package/dist/admin/reviewer-scope-editor.js +3 -3
- package/dist/admin/reviewer-scope-editor.js.map +1 -1
- package/dist/auth/auth-errors-labels.d.ts +11 -0
- package/dist/auth/auth-errors-labels.js +13 -0
- package/dist/auth/auth-errors-labels.js.map +1 -0
- package/dist/auth/auth-errors.d.ts +7 -23
- package/dist/auth/auth-errors.js +2 -15
- package/dist/auth/auth-errors.js.map +1 -1
- package/dist/auth/complete-name-dialog.d.ts +3 -2
- package/dist/auth/complete-name-dialog.js +3 -5
- package/dist/auth/complete-name-dialog.js.map +1 -1
- package/dist/auth/forgot-password-form-labels.js +1 -1
- package/dist/auth/forgot-password-form-labels.js.map +1 -1
- package/dist/auth/forgot-password-form.js +7 -2
- package/dist/auth/forgot-password-form.js.map +1 -1
- package/dist/auth/register-form-labels.js +1 -1
- package/dist/auth/register-form-labels.js.map +1 -1
- package/dist/auth/reset-password-form-labels.js +1 -1
- package/dist/auth/reset-password-form-labels.js.map +1 -1
- package/dist/auth/reset-password-form.js +5 -1
- package/dist/auth/reset-password-form.js.map +1 -1
- package/dist/auth/sign-in-form-labels.js +1 -1
- package/dist/auth/sign-in-form-labels.js.map +1 -1
- package/dist/auth/status-parts.d.ts +0 -3
- package/dist/auth/status-parts.js +0 -4
- package/dist/auth/status-parts.js.map +1 -1
- package/dist/auth/verify-email-labels.js +1 -1
- package/dist/auth/verify-email-labels.js.map +1 -1
- package/dist/auth/verify-email.js +7 -2
- package/dist/auth/verify-email.js.map +1 -1
- package/dist/billing/cancel-request.d.ts +11 -2
- package/dist/billing/cancel-request.js +15 -3
- package/dist/billing/cancel-request.js.map +1 -1
- package/dist/billing/cancel-subscription.d.ts +22 -10
- package/dist/billing/cancel-subscription.js +8 -11
- package/dist/billing/cancel-subscription.js.map +1 -1
- package/dist/billing/dialog-close.d.ts +29 -0
- package/dist/billing/dialog-close.js +8 -0
- package/dist/billing/dialog-close.js.map +1 -0
- package/dist/billing/plan-card.d.ts +14 -4
- package/dist/billing/plan-card.js +15 -8
- package/dist/billing/plan-card.js.map +1 -1
- package/dist/billing/plan-change-labels.d.ts +42 -0
- package/dist/billing/plan-change-labels.js +22 -0
- package/dist/billing/plan-change-labels.js.map +1 -0
- package/dist/billing/plan-switch.d.ts +21 -9
- package/dist/billing/plan-switch.js +10 -8
- package/dist/billing/plan-switch.js.map +1 -1
- package/dist/chart.d.ts +12 -0
- package/dist/chart.js +16 -1
- package/dist/chart.js.map +1 -1
- package/dist/components/account-chips.d.ts +5 -5
- package/dist/components/account-chips.js +11 -13
- package/dist/components/account-chips.js.map +1 -1
- package/dist/components/alert-banner.d.ts +16 -5
- package/dist/components/alert-banner.js +46 -1
- package/dist/components/alert-banner.js.map +1 -1
- package/dist/components/amount-input.d.ts +22 -4
- package/dist/components/amount-input.js +3 -3
- package/dist/components/amount-input.js.map +1 -1
- package/dist/components/autocomplete.js +57 -65
- package/dist/components/autocomplete.js.map +1 -1
- package/dist/components/bulk-action-bar.d.ts +12 -2
- package/dist/components/bulk-action-bar.js +65 -21
- package/dist/components/bulk-action-bar.js.map +1 -1
- package/dist/components/button-look.d.ts +5 -5
- package/dist/components/button-look.js.map +1 -1
- package/dist/components/button.d.ts +2 -2
- package/dist/components/button.js.map +1 -1
- package/dist/components/calculator.d.ts +21 -2
- package/dist/components/calculator.js +53 -14
- package/dist/components/calculator.js.map +1 -1
- package/dist/components/chart-edge.d.ts +16 -0
- package/dist/components/chart-edge.js +14 -1
- package/dist/components/chart-edge.js.map +1 -1
- package/dist/components/chart-figure.d.ts +13 -0
- package/dist/components/chart-figure.js +15 -0
- package/dist/components/chart-figure.js.map +1 -0
- package/dist/components/chart-zoom-core.js +1 -4
- package/dist/components/chart-zoom-core.js.map +1 -1
- package/dist/components/chart.d.ts +8 -1
- package/dist/components/chart.js +19 -10
- package/dist/components/chart.js.map +1 -1
- package/dist/components/combobox-core.d.ts +119 -7
- package/dist/components/combobox-core.js +151 -46
- package/dist/components/combobox-core.js.map +1 -1
- package/dist/components/combobox.d.ts +1 -1
- package/dist/components/combobox.js +142 -131
- package/dist/components/combobox.js.map +1 -1
- package/dist/components/copy-button.d.ts +6 -5
- package/dist/components/copy-button.js +5 -3
- package/dist/components/copy-button.js.map +1 -1
- package/dist/components/country-select.js +2 -2
- package/dist/components/country-select.js.map +1 -1
- package/dist/components/data-table-column-settings.d.ts +1 -1
- package/dist/components/data-table-column-settings.js +33 -7
- package/dist/components/data-table-column-settings.js.map +1 -1
- package/dist/components/data-table-filters.d.ts +4 -2
- package/dist/components/data-table-filters.js +2 -2
- package/dist/components/data-table-filters.js.map +1 -1
- package/dist/components/data-table-fit.d.ts +6 -4
- package/dist/components/data-table-fit.js +4 -1
- package/dist/components/data-table-fit.js.map +1 -1
- package/dist/components/data-table-groups.d.ts +1 -1
- package/dist/components/data-table-groups.js.map +1 -1
- package/dist/components/data-table-head.d.ts +1 -1
- package/dist/components/data-table-head.js +15 -12
- package/dist/components/data-table-head.js.map +1 -1
- package/dist/components/data-table-mobile.d.ts +36 -7
- package/dist/components/data-table-mobile.js +63 -31
- package/dist/components/data-table-mobile.js.map +1 -1
- package/dist/components/data-table-pagination.js +11 -6
- package/dist/components/data-table-pagination.js.map +1 -1
- package/dist/components/data-table-resize.d.ts +1 -1
- package/dist/components/data-table-resize.js.map +1 -1
- package/dist/components/data-table-row-actions.d.ts +2 -2
- package/dist/components/data-table-row-actions.js.map +1 -1
- package/dist/components/data-table-row.d.ts +6 -2
- package/dist/components/data-table-row.js +17 -10
- package/dist/components/data-table-row.js.map +1 -1
- package/dist/components/data-table-selection.d.ts +1 -1
- package/dist/components/data-table-selection.js.map +1 -1
- package/dist/components/data-table-shared.d.ts +10 -2
- package/dist/components/data-table-shared.js +18 -0
- package/dist/components/data-table-shared.js.map +1 -1
- package/dist/components/data-table-sort.d.ts +21 -2
- package/dist/components/data-table-sort.js +24 -0
- package/dist/components/data-table-sort.js.map +1 -1
- package/dist/components/data-table-virtual.d.ts +1 -1
- package/dist/components/data-table-virtual.js +18 -6
- package/dist/components/data-table-virtual.js.map +1 -1
- package/dist/components/data-table.d.ts +25 -8
- package/dist/components/data-table.js +154 -25
- package/dist/components/data-table.js.map +1 -1
- package/dist/components/date-field.d.ts +24 -2
- package/dist/components/date-field.js +33 -8
- package/dist/components/date-field.js.map +1 -1
- package/dist/components/date-picker.d.ts +15 -2
- package/dist/components/date-picker.js +55 -26
- package/dist/components/date-picker.js.map +1 -1
- package/dist/components/date-range-picker.d.ts +47 -20
- package/dist/components/date-range-picker.js +23 -7
- package/dist/components/date-range-picker.js.map +1 -1
- package/dist/components/dialog-frame.d.ts +2 -1
- package/dist/components/dialog-frame.js.map +1 -1
- package/dist/components/entity-combobox.js +4 -2
- package/dist/components/entity-combobox.js.map +1 -1
- package/dist/components/error-boundary.js +37 -30
- package/dist/components/error-boundary.js.map +1 -1
- package/dist/components/{ui-labels.d.ts → field-base-labels.d.ts} +0 -2
- package/dist/components/{ui-labels.js → field-base-labels.js} +2 -9
- package/dist/components/field-base-labels.js.map +1 -0
- package/dist/components/field-base.d.ts +4 -3
- package/dist/components/field-base.js +3 -3
- package/dist/components/field-base.js.map +1 -1
- package/dist/components/field-sync-labels.d.ts +1 -0
- package/dist/components/field-sync-labels.js.map +1 -1
- package/dist/components/field-sync.d.ts +23 -1
- package/dist/components/field-sync.js.map +1 -1
- package/dist/components/form-actions.js +11 -5
- package/dist/components/form-actions.js.map +1 -1
- package/dist/components/hover-menu.d.ts +3 -0
- package/dist/components/hover-menu.js +5 -3
- package/dist/components/hover-menu.js.map +1 -1
- package/dist/components/icon-button.js +14 -9
- package/dist/components/icon-button.js.map +1 -1
- package/dist/components/inline-confirm.d.ts +43 -0
- package/dist/components/inline-confirm.js +67 -0
- package/dist/components/inline-confirm.js.map +1 -0
- package/dist/components/inline-entity-combobox.d.ts +4 -3
- package/dist/components/inline-entity-combobox.js +150 -141
- package/dist/components/inline-entity-combobox.js.map +1 -1
- package/dist/components/input.js +1 -1
- package/dist/components/input.js.map +1 -1
- package/dist/components/jump-calendar.js +28 -112
- package/dist/components/jump-calendar.js.map +1 -1
- package/dist/components/legal-page.d.ts +3 -1
- package/dist/components/legal-page.js +3 -2
- package/dist/components/legal-page.js.map +1 -1
- package/dist/components/legal.d.ts +4 -2
- package/dist/components/legal.js.map +1 -1
- package/dist/components/lightbox.d.ts +2 -2
- package/dist/components/lightbox.js +17 -6
- package/dist/components/lightbox.js.map +1 -1
- package/dist/components/list.d.ts +6 -2
- package/dist/components/list.js +4 -3
- package/dist/components/list.js.map +1 -1
- package/dist/components/measured-grid.d.ts +1 -1
- package/dist/components/measured-grid.js +2 -1
- package/dist/components/measured-grid.js.map +1 -1
- package/dist/components/mini-calendar.js +3 -5
- package/dist/components/mini-calendar.js.map +1 -1
- package/dist/components/modal.d.ts +24 -0
- package/dist/components/modal.js +12 -4
- package/dist/components/modal.js.map +1 -1
- package/dist/components/money-draft.js +7 -5
- package/dist/components/money-draft.js.map +1 -1
- package/dist/components/money-field.d.ts +2 -2
- package/dist/components/money-field.js.map +1 -1
- package/dist/components/month-grid.d.ts +55 -0
- package/dist/components/month-grid.js +148 -0
- package/dist/components/month-grid.js.map +1 -0
- package/dist/components/month-picker.d.ts +36 -4
- package/dist/components/month-picker.js +123 -146
- package/dist/components/month-picker.js.map +1 -1
- package/dist/components/multi-entity-combobox.js +2 -1
- package/dist/components/multi-entity-combobox.js.map +1 -1
- package/dist/components/multi-select.d.ts +2 -2
- package/dist/components/multi-select.js +11 -6
- package/dist/components/multi-select.js.map +1 -1
- package/dist/components/number-field.d.ts +6 -4
- package/dist/components/number-field.js +3 -2
- package/dist/components/number-field.js.map +1 -1
- package/dist/components/number-input.d.ts +4 -1
- package/dist/components/number-input.js +3 -2
- package/dist/components/number-input.js.map +1 -1
- package/dist/components/numpad-sheet.js.map +1 -1
- package/dist/components/picker-sheet.js +2 -1
- package/dist/components/picker-sheet.js.map +1 -1
- package/dist/components/pie-chart-labels.d.ts +7 -0
- package/dist/components/pie-chart-labels.js +1 -0
- package/dist/components/pie-chart-labels.js.map +1 -1
- package/dist/components/pie-chart.d.ts +5 -3
- package/dist/components/pie-chart.js +7 -22
- package/dist/components/pie-chart.js.map +1 -1
- package/dist/components/popover.d.ts +3 -0
- package/dist/components/popover.js +7 -1
- package/dist/components/popover.js.map +1 -1
- package/dist/components/reauth-dialog.d.ts +4 -5
- package/dist/components/reauth-dialog.js +1 -4
- package/dist/components/reauth-dialog.js.map +1 -1
- package/dist/components/row-actions.js +2 -1
- package/dist/components/row-actions.js.map +1 -1
- package/dist/components/section-nav.d.ts +7 -0
- package/dist/components/section-nav.js.map +1 -1
- package/dist/components/series-chart-axes.d.ts +10 -3
- package/dist/components/series-chart-axes.js +1 -0
- package/dist/components/series-chart-axes.js.map +1 -1
- package/dist/components/series-chart-labels.d.ts +7 -4
- package/dist/components/series-chart-labels.js.map +1 -1
- package/dist/components/series-chart.d.ts +31 -7
- package/dist/components/series-chart.js +72 -29
- package/dist/components/series-chart.js.map +1 -1
- package/dist/components/share-card.js +3 -3
- package/dist/components/share-card.js.map +1 -1
- package/dist/components/sign-chip-labels.d.ts +1 -0
- package/dist/components/sign-chip-labels.js.map +1 -1
- package/dist/components/sign-chip.d.ts +10 -1
- package/dist/components/sign-chip.js.map +1 -1
- package/dist/components/tabs-labels.d.ts +2 -0
- package/dist/components/tabs-labels.js +11 -0
- package/dist/components/tabs-labels.js.map +1 -0
- package/dist/components/tabs.d.ts +1 -1
- package/dist/components/tabs.js +13 -11
- package/dist/components/tabs.js.map +1 -1
- package/dist/components/toggle-legend.d.ts +2 -2
- package/dist/components/toggle-legend.js +6 -6
- package/dist/components/toggle-legend.js.map +1 -1
- package/dist/components/translation-review-editor.d.ts +4 -2
- package/dist/components/translation-review-editor.js +2 -3
- package/dist/components/translation-review-editor.js.map +1 -1
- package/dist/components/translation-review.d.ts +2 -1
- package/dist/components/translation-review.js +2 -2
- package/dist/components/translation-review.js.map +1 -1
- package/dist/components/treemap-labels.d.ts +26 -0
- package/dist/components/treemap-labels.js +10 -0
- package/dist/components/treemap-labels.js.map +1 -0
- package/dist/components/treemap-layout.d.ts +62 -0
- package/dist/components/treemap-layout.js +126 -0
- package/dist/components/treemap-layout.js.map +1 -0
- package/dist/components/treemap.d.ts +140 -17
- package/dist/components/treemap.js +324 -97
- package/dist/components/treemap.js.map +1 -1
- package/dist/components/use-table-state.d.ts +5 -5
- package/dist/components/use-table-state.js +4 -1
- package/dist/components/use-table-state.js.map +1 -1
- package/dist/data-table.d.ts +6 -2
- package/dist/data-table.js +7 -2
- package/dist/data-table.js.map +1 -1
- package/dist/eslint/index.js +1 -1
- package/dist/eslint/role-utilities.d.ts +36 -7
- package/dist/eslint/role-utilities.js +42 -9
- package/dist/eslint/role-utilities.js.map +1 -1
- package/dist/feedback/feedback-dialog.d.ts +25 -16
- package/dist/feedback/feedback-dialog.js +6 -2
- package/dist/feedback/feedback-dialog.js.map +1 -1
- package/dist/feedback/feedback-mutation.d.ts +30 -0
- package/dist/feedback/feedback-mutation.js +16 -0
- package/dist/feedback/feedback-mutation.js.map +1 -0
- package/dist/feedback/feedback-page-link.d.ts +53 -0
- package/dist/feedback/feedback-page-link.js +37 -0
- package/dist/feedback/feedback-page-link.js.map +1 -0
- package/dist/feedback/feedback-public-list.d.ts +12 -3
- package/dist/feedback/feedback-public-list.js +2 -1
- package/dist/feedback/feedback-public-list.js.map +1 -1
- package/dist/feedback/feedback-replies.d.ts +3 -1
- package/dist/feedback/feedback-replies.js +5 -4
- package/dist/feedback/feedback-replies.js.map +1 -1
- package/dist/feedback/feedback-row-detail-labels.js +5 -0
- package/dist/feedback/feedback-row-detail-labels.js.map +1 -1
- package/dist/feedback/feedback-row-detail.d.ts +64 -28
- package/dist/feedback/feedback-row-detail.js +30 -28
- package/dist/feedback/feedback-row-detail.js.map +1 -1
- package/dist/feedback/feedback-status-undo.d.ts +30 -11
- package/dist/feedback/feedback-status-undo.js +10 -15
- package/dist/feedback/feedback-status-undo.js.map +1 -1
- package/dist/feedback/feedback-submit-dialog.d.ts +1 -1
- package/dist/feedback/feedback-submit-dialog.js +1 -1
- package/dist/feedback/feedback-submit-dialog.js.map +1 -1
- package/dist/feedback/feedback-submit.js +9 -3
- package/dist/feedback/feedback-submit.js.map +1 -1
- package/dist/feedback/feedback-swipe.d.ts +1 -1
- package/dist/feedback/feedback-swipe.js.map +1 -1
- package/dist/feedback/feedback-table.d.ts +21 -9
- package/dist/feedback/feedback-table.js +45 -25
- package/dist/feedback/feedback-table.js.map +1 -1
- package/dist/feedback/feedback-thread-labels.d.ts +2 -2
- package/dist/feedback/feedback-thread-labels.js.map +1 -1
- package/dist/feedback/feedback-thread.d.ts +24 -23
- package/dist/feedback/feedback-thread.js +2 -1
- package/dist/feedback/feedback-thread.js.map +1 -1
- package/dist/feedback.d.ts +34 -0
- package/dist/feedback.js +42 -0
- package/dist/feedback.js.map +1 -1
- package/dist/hooks/use-dismiss.js.map +1 -1
- package/dist/hooks/use-focus-trap.d.ts +35 -0
- package/dist/hooks/use-focus-trap.js +6 -4
- package/dist/hooks/use-focus-trap.js.map +1 -1
- package/dist/hooks/use-hotkey.d.ts +5 -2
- package/dist/hooks/use-hotkey.js +5 -4
- package/dist/hooks/use-hotkey.js.map +1 -1
- package/dist/hooks/use-long-press.d.ts +7 -4
- package/dist/hooks/use-long-press.js +3 -0
- package/dist/hooks/use-long-press.js.map +1 -1
- package/dist/hooks/use-media-query.js +12 -4
- package/dist/hooks/use-media-query.js.map +1 -1
- package/dist/hooks/use-mounted.d.ts +22 -0
- package/dist/hooks/use-mounted.js +24 -0
- package/dist/hooks/use-mounted.js.map +1 -0
- package/dist/hooks/use-overlay-history.d.ts +7 -1
- package/dist/hooks/use-overlay-history.js +35 -5
- package/dist/hooks/use-overlay-history.js.map +1 -1
- package/dist/i18n/defaults.js +4 -5
- package/dist/i18n/defaults.js.map +1 -1
- package/dist/i18n/german.js +7 -1
- package/dist/i18n/german.js.map +1 -1
- package/dist/i18n/kit-labels.d.ts +9 -2
- package/dist/i18n/kit-labels.js.map +1 -1
- package/dist/i18n/locales/en.js +20 -41
- package/dist/i18n/locales/en.js.map +3 -3
- package/dist/i18n/locales/es.js +7 -1
- package/dist/i18n/locales/es.js.map +1 -1
- package/dist/i18n/locales/fr.js +20 -10
- package/dist/i18n/locales/fr.js.map +1 -1
- package/dist/i18n/locales/hu.js +9 -1
- package/dist/i18n/locales/hu.js.map +1 -1
- package/dist/i18n/locales/it.js +7 -1
- package/dist/i18n/locales/it.js.map +1 -1
- package/dist/i18n/locales/zh.js +8 -1
- package/dist/i18n/locales/zh.js.map +1 -1
- package/dist/i18n/review.js +5 -0
- package/dist/i18n/review.js.map +1 -1
- package/dist/index.d.ts +64 -17
- package/dist/index.js +77 -12
- package/dist/index.js.map +1 -1
- package/dist/landing/routing.d.ts +3 -1
- package/dist/landing/routing.js +4 -7
- package/dist/landing/routing.js.map +1 -1
- package/dist/lib/broadcast.d.ts +17 -0
- package/dist/lib/broadcast.js +30 -0
- package/dist/lib/broadcast.js.map +1 -0
- package/dist/lib/calc.d.ts +7 -1
- package/dist/lib/calc.js +3 -1
- package/dist/lib/calc.js.map +1 -1
- package/dist/lib/clipboard-minus.d.ts +2 -2
- package/dist/lib/clipboard-minus.js +1 -1
- package/dist/lib/clipboard-minus.js.map +1 -1
- package/dist/lib/date-format.d.ts +37 -2
- package/dist/lib/date-format.js +34 -8
- package/dist/lib/date-format.js.map +1 -1
- package/dist/lib/day-format.d.ts +46 -0
- package/dist/lib/day-format.js +46 -0
- package/dist/lib/day-format.js.map +1 -0
- package/dist/lib/decimal-marks.d.ts +7 -1
- package/dist/lib/decimal-marks.js +5 -2
- package/dist/lib/decimal-marks.js.map +1 -1
- package/dist/lib/describe-failure.d.ts +14 -0
- package/dist/lib/describe-failure.js +9 -0
- package/dist/lib/describe-failure.js.map +1 -0
- package/dist/lib/direction.d.ts +16 -0
- package/dist/lib/direction.js +9 -1
- package/dist/lib/direction.js.map +1 -1
- package/dist/lib/focus-left.d.ts +63 -0
- package/dist/lib/focus-left.js +67 -0
- package/dist/lib/focus-left.js.map +1 -0
- package/dist/lib/format.d.ts +5 -3
- package/dist/lib/format.js +16 -13
- package/dist/lib/format.js.map +1 -1
- package/dist/lib/http-status.d.ts +24 -0
- package/dist/lib/http-status.js +14 -0
- package/dist/lib/http-status.js.map +1 -0
- package/dist/lib/intl-cache.d.ts +14 -0
- package/dist/lib/intl-cache.js +15 -0
- package/dist/lib/intl-cache.js.map +1 -0
- package/dist/lib/isin.d.ts +10 -0
- package/dist/lib/isin.js.map +1 -1
- package/dist/lib/iso-day.d.ts +11 -0
- package/dist/lib/iso-day.js +8 -0
- package/dist/lib/iso-day.js.map +1 -0
- package/dist/lib/lazy-with-fallback.d.ts +31 -0
- package/dist/lib/lazy-with-fallback.js +40 -0
- package/dist/lib/lazy-with-fallback.js.map +1 -0
- package/dist/lib/path-pattern.d.ts +34 -0
- package/dist/lib/path-pattern.js +24 -0
- package/dist/lib/path-pattern.js.map +1 -0
- package/dist/lib/reduced-motion.d.ts +2 -1
- package/dist/lib/reduced-motion.js.map +1 -1
- package/dist/lib/round.d.ts +2 -1
- package/dist/lib/round.js +2 -1
- package/dist/lib/round.js.map +1 -1
- package/dist/lib/safe-storage.d.ts +24 -5
- package/dist/lib/safe-storage.js +27 -2
- package/dist/lib/safe-storage.js.map +1 -1
- package/dist/lib/session-refresh.js +1 -1
- package/dist/lib/session-refresh.js.map +1 -1
- package/dist/lib/share-format.d.ts +13 -0
- package/dist/lib/share-format.js +10 -0
- package/dist/lib/share-format.js.map +1 -0
- package/dist/lib/text-case.d.ts +17 -0
- package/dist/lib/text-case.js +8 -0
- package/dist/lib/text-case.js.map +1 -0
- package/dist/lib/text-match.d.ts +38 -0
- package/dist/lib/text-match.js +24 -2
- package/dist/lib/text-match.js.map +1 -1
- package/dist/lib/thenable.d.ts +13 -0
- package/dist/lib/thenable.js +8 -0
- package/dist/lib/thenable.js.map +1 -0
- package/dist/lib/translation-review.d.ts +7 -2
- package/dist/lib/translation-review.js +4 -4
- package/dist/lib/translation-review.js.map +1 -1
- package/dist/notifications/device-zone-report.js +1 -1
- package/dist/notifications/device-zone-report.js.map +1 -1
- package/dist/notifications/notification-bell.d.ts +2 -1
- package/dist/notifications/notification-bell.js +3 -3
- package/dist/notifications/notification-bell.js.map +1 -1
- package/dist/notifications/notification-inbox.d.ts +10 -6
- package/dist/notifications/notification-inbox.js +26 -48
- package/dist/notifications/notification-inbox.js.map +1 -1
- package/dist/notifications/notification-parts.d.ts +3 -2
- package/dist/notifications/notification-parts.js +1 -3
- package/dist/notifications/notification-parts.js.map +1 -1
- package/dist/notifications/notification-types-setting.js +1 -1
- package/dist/notifications/notification-types-setting.js.map +1 -1
- package/dist/notifications/notifications-labels.d.ts +6 -0
- package/dist/notifications/notifications-labels.js +1 -0
- package/dist/notifications/notifications-labels.js.map +1 -1
- package/dist/notifications/push-device-setting.js +1 -1
- package/dist/notifications/push-device-setting.js.map +1 -1
- package/dist/notifications/push-devices-setting.d.ts +2 -1
- package/dist/notifications/push-devices-setting.js +27 -49
- package/dist/notifications/push-devices-setting.js.map +1 -1
- package/dist/notifications/quiet-hours-setting.d.ts +10 -3
- package/dist/notifications/quiet-hours-setting.js +65 -26
- package/dist/notifications/quiet-hours-setting.js.map +1 -1
- package/dist/notifications/unsubscribe-panel.js +4 -7
- package/dist/notifications/unsubscribe-panel.js.map +1 -1
- package/dist/notifications/use-push-device.d.ts +39 -1
- package/dist/notifications/use-push-device.js +28 -7
- package/dist/notifications/use-push-device.js.map +1 -1
- package/dist/offline/query-persistence.d.ts +3 -1
- package/dist/offline/query-persistence.js +19 -2
- package/dist/offline/query-persistence.js.map +1 -1
- package/dist/rhf/fields.d.ts +11 -4
- package/dist/rhf/fields.js.map +1 -1
- package/dist/search/command-palette.js +1 -1
- package/dist/search/command-palette.js.map +1 -1
- package/dist/search/global-search.js +19 -9
- package/dist/search/global-search.js.map +1 -1
- package/dist/search/use-command-key.d.ts +12 -1
- package/dist/search/use-command-key.js +3 -12
- package/dist/search/use-command-key.js.map +1 -1
- package/dist/search.d.ts +7 -0
- package/dist/search.js +10 -0
- package/dist/search.js.map +1 -1
- package/dist/settings/use-settings-focus.js +1 -0
- package/dist/settings/use-settings-focus.js.map +1 -1
- package/dist/shell/account-menu-language.d.ts +21 -5
- package/dist/shell/account-menu-language.js +3 -1
- package/dist/shell/account-menu-language.js.map +1 -1
- package/dist/shell/account-menu-text-size.d.ts +26 -9
- package/dist/shell/account-menu-text-size.js +3 -2
- package/dist/shell/account-menu-text-size.js.map +1 -1
- package/dist/shell/dev-menu.js +5 -18
- package/dist/shell/dev-menu.js.map +1 -1
- package/dist/shell/role-switcher.d.ts +7 -0
- package/dist/shell/role-switcher.js.map +1 -1
- package/dist/shell/top-bar-actions.d.ts +1 -1
- package/dist/shell/top-bar-actions.js.map +1 -1
- package/dist/shell/top-bar-parts-labels.d.ts +0 -2
- package/dist/shell/top-bar-parts-labels.js +0 -1
- package/dist/shell/top-bar-parts-labels.js.map +1 -1
- package/dist/shell.d.ts +27 -8
- package/dist/shell.js +28 -7
- package/dist/shell.js.map +1 -1
- package/dist/sync/engine.d.ts +30 -4
- package/dist/sync/engine.js +172 -52
- package/dist/sync/engine.js.map +1 -1
- package/dist/sync.d.ts +6 -2
- package/dist/sync.js +6 -1
- package/dist/sync.js.map +1 -1
- package/dist/testing/css-variables.js +3 -8
- package/dist/testing/css-variables.js.map +1 -1
- package/dist/theme/contrast.d.ts +2 -1
- package/dist/theme/contrast.js +3 -8
- package/dist/theme/contrast.js.map +1 -1
- package/dist/theme/palette-store.js +6 -6
- package/dist/theme/palette-store.js.map +1 -1
- package/dist/theme/text-size.js +3 -8
- package/dist/theme/text-size.js.map +1 -1
- package/dist/theme/theme-store.js +3 -6
- package/dist/theme/theme-store.js.map +1 -1
- package/dist/tour/tour-catalogue.d.ts +7 -4
- package/dist/tour/tour-catalogue.js +12 -10
- package/dist/tour/tour-catalogue.js.map +1 -1
- package/dist/tour/tour-dock.d.ts +0 -2
- package/dist/tour/tour-dock.js +0 -2
- package/dist/tour/tour-dock.js.map +1 -1
- package/dist/tour/tour-gates.d.ts +4 -0
- package/dist/tour/tour-gates.js +14 -0
- package/dist/tour/tour-gates.js.map +1 -1
- package/dist/tour/tour-overlay.d.ts +27 -0
- package/dist/tour/tour-overlay.js +741 -0
- package/dist/tour/tour-overlay.js.map +1 -0
- package/dist/tour/tour.d.ts +16 -4
- package/dist/tour/tour.js +62 -778
- package/dist/tour/tour.js.map +1 -1
- package/dist/tour/use-tour-progress.js +1 -1
- package/dist/tour/use-tour-progress.js.map +1 -1
- package/dist/tour/use-tour-url-sync.js +2 -2
- package/dist/tour/use-tour-url-sync.js.map +1 -1
- package/dist/wizard/stepper-nav.d.ts +5 -1
- package/dist/wizard/stepper-nav.js.map +1 -1
- package/dist/wizard/types.d.ts +6 -2
- package/dist/wizard/types.js.map +1 -1
- package/dist/wizard/use-wizard.d.ts +3 -1
- package/dist/wizard/use-wizard.js.map +1 -1
- package/dist/wizard/validation.d.ts +3 -1
- package/dist/wizard/validation.js.map +1 -1
- package/package.json +12 -8
- package/src/account/account-parts.ts +5 -25
- package/src/account/data-export-setting-labels.ts +1 -1
- package/src/account/delete-account-setting-labels.ts +1 -1
- package/src/account/email-change-setting-labels.ts +1 -1
- package/src/account/passkeys-setting.tsx +60 -38
- package/src/account/sessions-setting.tsx +18 -12
- package/src/admin/admin-action-confirm.tsx +5 -10
- package/src/admin/admin-parts.ts +11 -25
- package/src/admin/mail-test-card-labels.ts +1 -1
- package/src/admin/plan-change-labels.ts +5 -23
- package/src/admin/plan-change.tsx +7 -44
- package/src/admin/reviewer-scope-editor.tsx +3 -3
- package/src/auth/auth-errors-labels.ts +23 -0
- package/src/auth/auth-errors.ts +11 -38
- package/src/auth/complete-name-dialog.tsx +9 -8
- package/src/auth/forgot-password-form-labels.ts +1 -1
- package/src/auth/forgot-password-form.tsx +11 -6
- package/src/auth/register-form-labels.ts +1 -1
- package/src/auth/reset-password-form-labels.ts +1 -1
- package/src/auth/reset-password-form.tsx +8 -4
- package/src/auth/sign-in-form-labels.ts +1 -1
- package/src/auth/status-parts.tsx +0 -6
- package/src/auth/verify-email-labels.ts +1 -1
- package/src/auth/verify-email.tsx +11 -6
- package/src/billing/cancel-request.ts +28 -6
- package/src/billing/cancel-subscription.tsx +29 -22
- package/src/billing/dialog-close.ts +34 -0
- package/src/billing/plan-card.tsx +36 -11
- package/src/billing/plan-change-labels.ts +66 -0
- package/src/billing/plan-switch.tsx +31 -20
- package/src/chart.ts +21 -3
- package/src/components/account-chips.tsx +20 -23
- package/src/components/alert-banner.tsx +82 -5
- package/src/components/amount-input.tsx +32 -14
- package/src/components/autocomplete.tsx +64 -70
- package/src/components/bulk-action-bar.tsx +70 -2
- package/src/components/button-look.ts +5 -5
- package/src/components/button.tsx +2 -2
- package/src/components/calculator.tsx +98 -17
- package/src/components/chart-edge.ts +34 -1
- package/src/components/chart-figure.tsx +35 -0
- package/src/components/chart-zoom-core.tsx +6 -5
- package/src/components/chart.tsx +26 -5
- package/src/components/combobox-core.tsx +303 -69
- package/src/components/combobox.tsx +184 -155
- package/src/components/copy-button.tsx +34 -23
- package/src/components/country-select.tsx +16 -11
- package/src/components/data-table-column-settings.tsx +52 -10
- package/src/components/data-table-filters.ts +6 -4
- package/src/components/data-table-fit.ts +19 -5
- package/src/components/data-table-groups.tsx +1 -1
- package/src/components/data-table-head.tsx +32 -22
- package/src/components/data-table-mobile.tsx +110 -27
- package/src/components/data-table-pagination.tsx +21 -6
- package/src/components/data-table-resize.ts +1 -1
- package/src/components/data-table-row-actions.tsx +3 -3
- package/src/components/data-table-row.tsx +25 -14
- package/src/components/data-table-selection.ts +1 -1
- package/src/components/data-table-shared.tsx +33 -1
- package/src/components/data-table-sort.ts +57 -2
- package/src/components/data-table-virtual.ts +32 -8
- package/src/components/data-table.tsx +267 -41
- package/src/components/date-field.tsx +65 -8
- package/src/components/date-picker.tsx +125 -48
- package/src/components/date-range-picker.tsx +82 -31
- package/src/components/dialog-frame.tsx +2 -1
- package/src/components/entity-combobox.tsx +4 -1
- package/src/components/error-boundary.tsx +53 -39
- package/src/components/field-base-labels.ts +20 -0
- package/src/components/field-base.tsx +13 -7
- package/src/components/field-sync-labels.ts +1 -0
- package/src/components/field-sync.tsx +23 -1
- package/src/components/form-actions.tsx +20 -5
- package/src/components/hover-menu.tsx +18 -8
- package/src/components/icon-button.tsx +14 -9
- package/src/components/inline-confirm.tsx +116 -0
- package/src/components/inline-entity-combobox.tsx +198 -152
- package/src/components/input.tsx +1 -1
- package/src/components/jump-calendar.tsx +30 -146
- package/src/components/legal-page.tsx +10 -7
- package/src/components/legal.tsx +4 -2
- package/src/components/lightbox.tsx +21 -8
- package/src/components/list.tsx +14 -5
- package/src/components/measured-grid.tsx +8 -4
- package/src/components/mini-calendar.tsx +6 -5
- package/src/components/modal.tsx +45 -4
- package/src/components/money-draft.ts +16 -5
- package/src/components/money-field.tsx +2 -2
- package/src/components/month-grid.tsx +229 -0
- package/src/components/month-picker.tsx +192 -200
- package/src/components/multi-entity-combobox.tsx +1 -0
- package/src/components/multi-select.tsx +21 -9
- package/src/components/number-field.tsx +14 -7
- package/src/components/number-input.tsx +9 -3
- package/src/components/numpad-sheet.tsx +4 -3
- package/src/components/picker-sheet.tsx +12 -9
- package/src/components/pie-chart-labels.ts +8 -0
- package/src/components/pie-chart.tsx +22 -28
- package/src/components/popover.tsx +18 -1
- package/src/components/reauth-dialog.tsx +6 -10
- package/src/components/row-actions.tsx +2 -1
- package/src/components/section-nav.tsx +7 -0
- package/src/components/series-chart-axes.ts +11 -3
- package/src/components/series-chart-labels.ts +7 -4
- package/src/components/series-chart.tsx +178 -69
- package/src/components/share-card.tsx +6 -6
- package/src/components/sign-chip-labels.ts +1 -0
- package/src/components/sign-chip.tsx +10 -1
- package/src/components/tabs-labels.ts +13 -0
- package/src/components/tabs.tsx +35 -19
- package/src/components/toggle-legend.tsx +16 -11
- package/src/components/translation-review-editor.tsx +6 -5
- package/src/components/translation-review.tsx +4 -3
- package/src/components/treemap-labels.ts +39 -0
- package/src/components/treemap-layout.ts +210 -0
- package/src/components/treemap.tsx +722 -133
- package/src/components/use-table-state.ts +12 -9
- package/src/data-table.ts +9 -2
- package/src/eslint/role-utilities.ts +97 -19
- package/src/feedback/feedback-dialog.tsx +30 -19
- package/src/feedback/feedback-mutation.ts +41 -0
- package/src/feedback/feedback-page-link.ts +90 -0
- package/src/feedback/feedback-public-list.tsx +17 -5
- package/src/feedback/feedback-replies.tsx +13 -6
- package/src/feedback/feedback-row-detail-labels.ts +5 -0
- package/src/feedback/feedback-row-detail.tsx +103 -67
- package/src/feedback/feedback-status-undo.ts +41 -27
- package/src/feedback/feedback-submit-dialog.tsx +2 -2
- package/src/feedback/feedback-submit.tsx +21 -7
- package/src/feedback/feedback-swipe.tsx +1 -1
- package/src/feedback/feedback-table.tsx +86 -38
- package/src/feedback/feedback-thread-labels.ts +2 -2
- package/src/feedback/feedback-thread.tsx +27 -25
- package/src/feedback.ts +42 -0
- package/src/hooks/use-dismiss.ts +3 -2
- package/src/hooks/use-focus-trap.ts +8 -24
- package/src/hooks/use-hotkey.ts +24 -7
- package/src/hooks/use-long-press.ts +16 -2
- package/src/hooks/use-media-query.ts +20 -4
- package/src/hooks/use-mounted.ts +39 -0
- package/src/hooks/use-overlay-history.ts +70 -5
- package/src/i18n/defaults.ts +4 -5
- package/src/i18n/german.ts +8 -2
- package/src/i18n/kit-labels.tsx +9 -2
- package/src/i18n/locales/es.ts +8 -2
- package/src/i18n/locales/fr.ts +21 -13
- package/src/i18n/locales/hu.ts +10 -2
- package/src/i18n/locales/it.ts +8 -2
- package/src/i18n/locales/zh.ts +9 -2
- package/src/i18n/review.ts +5 -0
- package/src/index.ts +103 -13
- package/src/landing/routing.tsx +14 -10
- package/src/lib/broadcast.ts +52 -0
- package/src/lib/calc.ts +13 -2
- package/src/lib/clipboard-minus.ts +14 -4
- package/src/lib/date-format.ts +89 -13
- package/src/lib/day-format.ts +96 -0
- package/src/lib/decimal-marks.ts +12 -3
- package/src/lib/describe-failure.ts +18 -0
- package/src/lib/direction.ts +39 -0
- package/src/lib/focus-left.ts +156 -0
- package/src/lib/format.ts +34 -19
- package/src/lib/http-status.ts +38 -0
- package/src/lib/intl-cache.ts +25 -0
- package/src/lib/isin.ts +10 -0
- package/src/lib/iso-day.ts +13 -0
- package/src/lib/lazy-with-fallback.ts +82 -0
- package/src/lib/path-pattern.ts +55 -0
- package/src/lib/reduced-motion.ts +2 -1
- package/src/lib/round.ts +7 -2
- package/src/lib/safe-storage.ts +48 -6
- package/src/lib/session-refresh.ts +1 -1
- package/src/lib/share-format.ts +18 -0
- package/src/lib/text-case.ts +19 -0
- package/src/lib/text-match.ts +69 -2
- package/src/lib/thenable.ts +19 -0
- package/src/lib/translation-review.ts +13 -5
- package/src/notifications/device-zone-report.ts +1 -1
- package/src/notifications/notification-bell.tsx +7 -4
- package/src/notifications/notification-inbox.tsx +40 -58
- package/src/notifications/notification-parts.tsx +3 -4
- package/src/notifications/notification-types-setting.tsx +1 -1
- package/src/notifications/notifications-labels.ts +7 -0
- package/src/notifications/push-device-setting.tsx +1 -1
- package/src/notifications/push-devices-setting.tsx +30 -55
- package/src/notifications/quiet-hours-setting.tsx +93 -31
- package/src/notifications/unsubscribe-panel.tsx +4 -7
- package/src/notifications/use-push-device.ts +76 -10
- package/src/offline/query-persistence.ts +35 -3
- package/src/rhf/fields.tsx +11 -4
- package/src/search/command-palette.tsx +2 -4
- package/src/search/global-search.tsx +36 -15
- package/src/search/use-command-key.ts +13 -12
- package/src/search.ts +9 -0
- package/src/settings/use-settings-focus.ts +3 -0
- package/src/shell/account-menu-language.tsx +27 -5
- package/src/shell/account-menu-text-size.tsx +32 -10
- package/src/shell/dev-menu.tsx +7 -21
- package/src/shell/role-switcher.tsx +7 -0
- package/src/shell/top-bar-actions.tsx +1 -1
- package/src/shell/top-bar-parts-labels.ts +0 -3
- package/src/shell.ts +40 -9
- package/src/sync/engine.ts +339 -61
- package/src/sync.ts +8 -1
- package/src/testing/css-variables.ts +8 -9
- package/src/theme/contrast.ts +8 -9
- package/src/theme/palette-store.ts +9 -9
- package/src/theme/text-size.ts +6 -8
- package/src/theme/theme-store.ts +7 -9
- package/src/tour/tour-catalogue.tsx +26 -15
- package/src/tour/tour-dock.ts +0 -2
- package/src/tour/tour-gates.ts +23 -0
- package/src/tour/tour-overlay.tsx +1170 -0
- package/src/tour/tour.tsx +116 -1193
- package/src/tour/use-tour-progress.ts +1 -1
- package/src/tour/use-tour-url-sync.ts +7 -3
- package/src/wizard/stepper-nav.tsx +3 -1
- package/src/wizard/types.ts +11 -2
- package/src/wizard/use-wizard.ts +2 -1
- package/src/wizard/validation.ts +8 -2
- package/tokens.css +2 -1
- package/dist/components/ui-labels.js.map +0 -1
- package/dist/shell/dev-switchers.d.ts +0 -6
- package/dist/shell/dev-switchers.js +0 -12
- package/dist/shell/dev-switchers.js.map +0 -1
- package/src/components/ui-labels.ts +0 -24
- package/src/shell/dev-switchers.tsx +0 -18
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"sources":["../../src/hooks/use-dismiss.ts"],"sourcesContent":["import { useCallback, useEffect, useRef, useSyncExternalStore } from \"react\";\nimport type { KeyboardEvent as ReactKeyboardEvent, RefObject } from \"react\";\nimport { isComposing } from \"../lib/ime\";\n\n/*\n * # One Escape stack (round 0.34 Wave 2, DUP-1)\n *\n * Escape closes the TOPMOST thing on screen, and only that: a list open in a dialog\n * closes and the dialog stays; the next press closes the dialog.\n *\n * \"Who owns Escape\" used to be decided five ways. The anchored pickers listened on the\n * document; Modal, FullBleedDialog, PickerSheet and Popover closed in their own panel's\n * `onKeyDown` and stopped the key; CommandPalette closed without stopping it. A dialog's\n * handler sits earlier on the key's path than any document listener, so Escape in an\n * open list inside a Modal closed the MODAL and threw the form away (BUG-1, sev 4,\n * kastlan's lease dialog), and HoverMenu, the numpad and a tooltip could not be\n * dismissed inside a dialog at all. And Modal and FullBleedDialog disagreed on when a\n * child had \"claimed\" the key: a ChipInput clearing its draft kept a Modal open and\n * closed a FullBleedDialog.\n *\n * Now every overlay and picker pushes a layer while it is open ({@link useDismissLayer}),\n * last in, first out, the way `use-overlay-history` stacks the Back gesture. One\n * capture-phase listener on the document notes which layer is on top as each Escape\n * goes down — before any handler on the page runs, so a layer that closes on the way\n * cannot pass the key on to the one beneath it. That layer, and only that one, is\n * handed the key:\n *\n * - at the first layer element the key passes on its way back up ({@link takeEscape},\n * which Modal's panel, a picker's search box and the rest call from their\n * `onKeyDown`). The key is stopped there, so nothing around the layers — a\n * FloatingPanel, an app's own panel — closes with it;\n * - or, when focus is in none of them (a hover menu, a tooltip, the numpad over its\n * field, a press on the page), at the document once the key has been everywhere else.\n *\n * Layers stack in the order they OPEN, which is the order their effects run. Two that\n * open in the same commit stack child first — the one case that order gets wrong, and\n * one no overlay in the kit does: each opens on a press, after whatever it sits in.\n *\n * ## Claiming the key: one rule\n *\n * An Escape that means \"undo this step\" is not a dismissal: ChipInput clearing its\n * draft, InlineEditField cancelling its edit, the date picker's month grid going back to\n * the days. Those call {@link claimEscape}, and no layer is handed the key. The only\n * other claim is the layer owner's OWN handler — a dialog's `onKeyDown` prop calling\n * `preventDefault()` on Escape (a busy reauth dialog holding itself open, Kurvenschmiede's\n * gear wizard asking first), through {@link runOwnKeyDown}. A `preventDefault()`\n * anywhere else claims nothing: a search box keeping Chromium from clearing itself\n * must not hold a dialog open (FullBleedDialog's 0.8.0 fix, which Modal never had).\n *\n * The owner's handler hears Escape only while its own layer is on top (0.35, KS). It\n * runs before the stack is asked, so with a tooltip, a hover menu or a list open over\n * the dialog and focus on the panel, the gear wizard asked \"Discard this gear?\" and the\n * tooltip stayed. Now the layer above takes that press, and the next one is the\n * owner's. Every other key reaches the handler as before.\n *\n * A handler that STOPS the key before it reaches a layer element has taken it too —\n * that is the DOM, and it is what the kit's cell editors and confirm buttons do.\n */\n\n/** A layer's handler, read through a ref so the stack holds one stable entry per open. */\ninterface Layer {\n escape: (e: KeyboardEvent) => void;\n /** Whether it covers the page — a dialog, a sheet, a popover, a list — rather than\n * annotating it (a tooltip). Counted by {@link useOverlayOpen}. */\n overlay: boolean;\n}\n\n/** What {@link useDismissLayer} hands back: its layer while open, for\n * {@link runOwnKeyDown} to tell whether that layer is the one on top. */\nexport type DismissLayer = RefObject<Layer | null>;\n\n/** Open layers, oldest first. Module-level, because the order is ACROSS instances. */\nconst layers: Layer[] = [];\n\n/** Escapes a claimant has taken — see {@link claimEscape}. Weak: an event is garbage\n * once its dispatch is over. */\nconst claimed = new WeakSet<Event>();\n\n/** The Escape on its way through the page: the layer that was topmost as it went down,\n * and whether that layer has been handed it yet. */\nlet inFlight: { event: KeyboardEvent; layer: Layer; done: boolean } | null = null;\n\nfunction nativeOf(e: KeyboardEvent | ReactKeyboardEvent): KeyboardEvent {\n return \"nativeEvent\" in e ? e.nativeEvent : e;\n}\n\nfunction onCapture(e: KeyboardEvent): void {\n if (e.key !== \"Escape\") return;\n // An Escape inside an IME composition cancels the composition and nothing else.\n const top = isComposing(e) ? undefined : layers[layers.length - 1];\n inFlight = top ? { event: e, layer: top, done: false } : null;\n}\n\n/** The fallback: no layer element was on the key's path, or none took it. */\nfunction onBubble(e: KeyboardEvent): void {\n handOver(e, false);\n}\n\nfunction handOver(e: KeyboardEvent | ReactKeyboardEvent, stop: boolean): boolean {\n const native = nativeOf(e);\n const flight = inFlight;\n if (native.key !== \"Escape\" || !flight || flight.event !== native || flight.done) return false;\n if (claimed.has(native)) return false;\n flight.done = true;\n // Consumed: a type=\"search\" box does not clear itself as well, and a handler further\n // out that checks `defaultPrevented` (FloatingPanel, an app's own panel) leaves it.\n e.preventDefault();\n if (stop) e.stopPropagation();\n // A layer that closed on the way, by a handler of its own, has had its Escape.\n if (layers.includes(flight.layer)) flight.layer.escape(native);\n return true;\n}\n\nfunction push(layer: Layer): void {\n if (layers.length === 0) {\n document.addEventListener(\"keydown\", onCapture, true);\n document.addEventListener(\"keydown\", onBubble);\n }\n layers.push(layer);\n if (layer.overlay) notifyOverlays();\n}\n\nfunction pop(layer: Layer): void {\n const at = layers.indexOf(layer);\n if (at >= 0) layers.splice(at, 1);\n if (at >= 0 && layer.overlay) notifyOverlays();\n if (layers.length > 0) return;\n document.removeEventListener(\"keydown\", onCapture, true);\n document.removeEventListener(\"keydown\", onBubble);\n inFlight = null;\n}\n\n/**\n * An Escape layer on the stack while `open`: the topmost layer is handed the next\n * Escape and calls `onEscape`, every layer under it waits its turn. A list opened inside\n * a dialog is above the dialog; a popover opened from a list, above the list.\n *\n * Where focus can be INSIDE the layer, its element's `onKeyDown` calls\n * {@link takeEscape} too, so the key stops there — see the module note. `onEscape` is\n * read live, so it need not be memoised; the layer is pushed and popped only when\n * `open` flips. The layer it returns is for the owner's {@link runOwnKeyDown}.\n */\nexport function useDismissLayer(\n open: boolean,\n onEscape: (e: KeyboardEvent) => void,\n { overlay = true }: { overlay?: boolean } = {},\n): DismissLayer {\n const handlerRef = useRef(onEscape);\n const layerRef = useRef<Layer | null>(null);\n // Written in an effect, not during render, so it satisfies react-hooks/refs: a\n // render that React starts and then discards — a transition, a Suspense retry —\n // would otherwise leave this holding a handler from a tree that never committed,\n // and the stack would go on to call it. Keydown events fire after the commit, so\n // the ref is always current by the time one arrives.\n useEffect(() => {\n handlerRef.current = onEscape;\n });\n useEffect(() => {\n if (!open || typeof document === \"undefined\") return;\n const layer: Layer = { escape: (e) => handlerRef.current(e), overlay };\n layerRef.current = layer;\n push(layer);\n return () => {\n pop(layer);\n layerRef.current = null;\n };\n }, [open, overlay]);\n return layerRef;\n}\n\n/*\n * Whether an overlay is open (0.49 KIT-11): every layer on the stack but a tooltip's is a\n * dialog, a sheet, a popover, a hover menu or a list covering part of the page, so the\n * stack is also the one place that knows. The floating launchers (`hideWhenOverlay`) step\n * aside while one is open instead of floating over it or beside it.\n */\nconst overlayListeners = new Set<() => void>();\n\nfunction notifyOverlays(): void {\n for (const listener of overlayListeners) listener();\n}\n\nfunction subscribeOverlays(listener: () => void): () => void {\n overlayListeners.add(listener);\n return () => {\n overlayListeners.delete(listener);\n };\n}\n\nfunction anyOverlayOpen(): boolean {\n return layers.some((layer) => layer.overlay);\n}\n\n/** True while a kit dialog, sheet, popover, hover menu or list is open (any layer of the\n * Escape stack but a tooltip's). Internal. */\nexport function useOverlayOpen(enabled = true): boolean {\n const open = useSyncExternalStore(subscribeOverlays, anyOverlayOpen, () => false);\n return enabled && open;\n}\n\n/**\n * For a layer's own element, in its `onKeyDown`: hands an Escape on its way up to the\n * topmost layer — this one, unless something opened over it without taking focus (a\n * tooltip, the numpad) — and stops it here. True when it did; false for any other key,\n * a claimed Escape, or one already handed over.\n */\nexport function takeEscape(e: KeyboardEvent | ReactKeyboardEvent): boolean {\n return handOver(e, true);\n}\n\n/**\n * For an Escape that means \"undo this step\", not \"close\": the key is the caller's, and\n * no layer is handed it. `preventDefault()`s it as well, so a handler further out that\n * checks `defaultPrevented` leaves it alone, as before.\n */\nexport function claimEscape(e: KeyboardEvent | ReactKeyboardEvent): void {\n claimed.add(nativeOf(e));\n e.preventDefault();\n}\n\n/**\n * Runs a layer owner's own key handler — a dialog's `onKeyDown` prop — and turns a\n * `preventDefault()` it makes on Escape into a claim: the one way, beside\n * {@link claimEscape}, to keep a layer open.\n *\n * Given the owner's `layer` (what {@link useDismissLayer} returned), an Escape that went\n * down while another layer was above that one skips the handler: the press is the\n * layer's on top, and the owner hears the next (0.35, KS). Without it, or while the\n * owner's layer is not open, the handler sees every key, as before.\n */\nexport function runOwnKeyDown<E extends ReactKeyboardEvent>(\n e: E,\n handler: ((e: E) => void) | undefined,\n layer?: DismissLayer,\n): void {\n if (!handler) return;\n if (layer && aboveOwner(e, layer.current)) return;\n const before = e.defaultPrevented;\n handler(e);\n if (e.key === \"Escape\" && !before && e.defaultPrevented) claimed.add(nativeOf(e));\n}\n\n/** Whether this Escape went down with a layer above `owner` — the topmost one then was\n * another, and `owner` is on the stack. An Escape the stack did not note (one inside an\n * IME composition) is nobody else's. */\nfunction aboveOwner(e: ReactKeyboardEvent, owner: Layer | null): boolean {\n const flight = inFlight;\n if (e.key !== \"Escape\" || !owner || !flight || flight.event !== nativeOf(e)) return false;\n return flight.layer !== owner && layers.includes(owner);\n}\n\n/**\n * Calls `handler` on an Escape while `enabled` — as an Escape layer. Since 0.34 this is\n * {@link useDismissLayer} with its arguments the other way round: it hears the key only\n * while nothing opened above it, and inside a dialog it no longer loses the key to the\n * dialog (Wave 2, DUP-1). `handler` is read live, so it need not be memoised.\n */\nexport function useEscapeKey(handler: () => void, enabled = true): void {\n useDismissLayer(enabled, handler);\n}\n\n/** Called with each native press an owner's React tree saw — see {@link useOutsideClick}. */\ntype PressMark = (press: Event) => void;\n\n/** The outside-click hooks watching each ref, for {@link pressInside}. */\nconst watchers = new WeakMap<RefObject<HTMLElement | null>, Set<PressMark>>();\n\n/** What an `onPointerDownCapture` hands over: a React event, its press inside. */\ntype ReactPress = { nativeEvent: Event };\n\n/**\n * An `onPointerDownCapture` for a panel whose `ref` an outside-click hook watches but\n * whose element the hook's owner does not render — {@link DropdownPanel} and\n * `ComboboxPanel` take `panelRef` from `useDropdown` / `useComboboxCore`. Every press\n * that reaches the panel through the React tree, a portalled list opened inside it\n * included, is marked inside for each hook watching `ref`. See {@link useOutsideClick}.\n */\nexport function pressInside(ref: RefObject<HTMLElement | null> | undefined): ((e: ReactPress) => void) | undefined {\n if (!ref) return undefined;\n return (e) => {\n watchers.get(ref)?.forEach((mark) => mark(e.nativeEvent));\n };\n}\n\n/**\n * Calls `handler` on a press that lands outside every supplied element, while\n * `enabled` — the outside-click-to-close half of the same dismissal story. Pass one\n * ref or several (trigger + panel); a press inside any of them is ignored. Refs and\n * `handler` are read live, so an inline `[triggerRef, panelRef]` array is fine and\n * won't churn the listener.\n *\n * ## A panel opened from inside is inside (0.48, keksdose dev#623)\n *\n * A CurrencySelect in a Popover: the currency list is portalled to `<body>`, so in the\n * DOM it is outside the popover's panel, and the first press on a currency closed the\n * POPOVER at pointerdown — the list went with it and the choice never landed. The same\n * for a combobox, a menu, a date picker's popover, a dropdown, at any depth.\n *\n * In the React tree the portal is still where it was opened from, and React passes a\n * press up that tree, through portals. So the hook hands back an\n * `onPointerDownCapture`: put it on the element the press should count as inside of —\n * the kit's Popover panel, HoverMenu, DropdownPanel and ComboboxPanel do — and every\n * press that travels through that element in React, portalled panels opened inside it\n * included, is not outside. React's listeners sit on the root and on each portal's\n * container, so they hear the press before this document listener does. No owner chain\n * to keep: depth is free, and an app's own portal inside a kit panel is covered too. A\n * panel the hook's owner does not render takes {@link pressInside} with the watched ref.\n *\n * **`pointerdown`, not `mousedown`** — one event covering mouse, touch and pen.\n * This listened for `mousedown` alone, which on a touch platform is a SYNTHESISED\n * event: the browser emits it for most taps, which is why nothing obviously broke,\n * but the synthesis is not guaranteed. A tap that begins a scroll, or one that lands\n * on an element which preventDefaults the touch sequence, may never produce one — and\n * on a phone-first PWA whose pickers, menus and flyouts all dismiss through this hook,\n * inheriting that is worse than choosing it.\n *\n * The one behaviour this changes deliberately: a touch-drag that starts outside an\n * open panel now dismisses it at touch-down, where before it did not dismiss at all\n * (a drag synthesises no mousedown). That matches every other platform surface, and\n * the anchored panels re-measure on scroll precisely because the page moves under\n * them.\n */\nexport function useOutsideClick(\n refs: RefObject<HTMLElement | null> | RefObject<HTMLElement | null>[],\n handler: () => void,\n enabled = true,\n): (e: ReactPress) => void {\n const refsRef = useRef(refs);\n const handlerRef = useRef(handler);\n // The last press this owner's React tree saw: the one the document listener is about\n // to hear, when it went through a panel the owner marked.\n const insideRef = useRef<Event | null>(null);\n // In an effect rather than during render — see the note in useDismissLayer.\n useEffect(() => {\n refsRef.current = refs;\n handlerRef.current = handler;\n });\n const markInside = useCallback((e: ReactPress) => {\n insideRef.current = e.nativeEvent;\n }, []);\n useEffect(() => {\n if (!enabled) return;\n const mark: PressMark = (press) => {\n insideRef.current = press;\n };\n const watched = Array.isArray(refsRef.current) ? refsRef.current : [refsRef.current];\n for (const r of watched) {\n const set = watchers.get(r) ?? new Set<PressMark>();\n set.add(mark);\n watchers.set(r, set);\n }\n const onPointerDown = (e: Event) => {\n const inside = insideRef.current === e;\n insideRef.current = null;\n if (inside) return;\n const target = e.target as Node;\n const list = Array.isArray(refsRef.current) ? refsRef.current : [refsRef.current];\n for (const r of list) {\n if (r.current?.contains(target)) return;\n }\n handlerRef.current();\n };\n document.addEventListener(\"pointerdown\", onPointerDown);\n return () => {\n document.removeEventListener(\"pointerdown\", onPointerDown);\n for (const r of watched) watchers.get(r)?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,IACrB;AACA,UAAM,gBAAgB,CAAC,MAAa;AAClC,YAAM,SAAS,UAAU,YAAY;AACrC,gBAAU,UAAU;AACpB,UAAI,OAAQ;AACZ,YAAM,SAAS,EAAE;AACjB,YAAM,OAAO,MAAM,QAAQ,QAAQ,OAAO,IAAI,QAAQ,UAAU,CAAC,QAAQ,OAAO;AAChF,iBAAW,KAAK,MAAM;AACpB,YAAI,EAAE,SAAS,SAAS,MAAM,EAAG;AAAA,MACnC;AACA,iBAAW,QAAQ;AAAA,IACrB;AACA,aAAS,iBAAiB,eAAe,aAAa;AACtD,WAAO,MAAM;AACX,eAAS,oBAAoB,eAAe,aAAa;AACzD,iBAAW,KAAK,QAAS,UAAS,IAAI,CAAC,GAAG,OAAO,IAAI;AAAA,IACvD;AAAA,EACF,GAAG,CAAC,OAAO,CAAC;AACZ,SAAO;AACT;","names":[]}
|
|
1
|
+
{"version":3,"sources":["../../src/hooks/use-dismiss.ts"],"sourcesContent":["import { useCallback, useEffect, useRef, useSyncExternalStore } from \"react\";\nimport type { KeyboardEvent as ReactKeyboardEvent, RefObject } from \"react\";\nimport { isComposing } from \"../lib/ime\";\n\n/*\n * # One Escape stack (round 0.34 Wave 2, DUP-1)\n *\n * Escape closes the TOPMOST thing on screen, and only that: a list open in a dialog\n * closes and the dialog stays; the next press closes the dialog.\n *\n * \"Who owns Escape\" used to be decided five ways. The anchored pickers listened on the\n * document; Modal, FullBleedDialog, PickerSheet and Popover closed in their own panel's\n * `onKeyDown` and stopped the key; CommandPalette closed without stopping it. A dialog's\n * handler sits earlier on the key's path than any document listener, so Escape in an\n * open list inside a Modal closed the MODAL and threw the form away (BUG-1, sev 4,\n * kastlan's lease dialog), and HoverMenu, the numpad and a tooltip could not be\n * dismissed inside a dialog at all. And Modal and FullBleedDialog disagreed on when a\n * child had \"claimed\" the key: a ChipInput clearing its draft kept a Modal open and\n * closed a FullBleedDialog.\n *\n * Now every overlay and picker pushes a layer while it is open ({@link useDismissLayer}),\n * last in, first out, the way `use-overlay-history` stacks the Back gesture. One\n * capture-phase listener on the document notes which layer is on top as each Escape\n * goes down — before any handler on the page runs, so a layer that closes on the way\n * cannot pass the key on to the one beneath it. That layer, and only that one, is\n * handed the key:\n *\n * - at the first layer element the key passes on its way back up ({@link takeEscape},\n * which Modal's panel, a picker's search box and the rest call from their\n * `onKeyDown`). The key is stopped there, so nothing around the layers — a\n * FloatingPanel, an app's own panel — closes with it;\n * - or, when focus is in none of them (a hover menu, a tooltip, the numpad over its\n * field, a press on the page), at the document once the key has been everywhere else.\n *\n * Layers stack in the order they OPEN, which is the order their effects run. Two that\n * open in the same commit stack child first — the one case that order gets wrong, and\n * one no overlay in the kit does: each opens on a press, after whatever it sits in.\n *\n * ## Claiming the key: one rule\n *\n * An Escape that means \"undo this step\" is not a dismissal: ChipInput clearing its\n * draft, InlineEditField cancelling its edit, the date picker's month grid going back to\n * the days. Those call {@link claimEscape}, and no layer is handed the key. The only\n * other claim is the layer owner's OWN handler — a dialog's `onKeyDown` prop calling\n * `preventDefault()` on Escape (Kurvenschmiede's gear wizard asking first), through\n * {@link runOwnKeyDown}. A dialog holding itself open while its request runs passes\n * Modal's `busy` instead (0.51.7, DUP-3), which holds the backdrop and Back as well. A `preventDefault()`\n * anywhere else claims nothing: a search box keeping Chromium from clearing itself\n * must not hold a dialog open (FullBleedDialog's 0.8.0 fix, which Modal never had).\n *\n * The owner's handler hears Escape only while its own layer is on top (0.35, KS). It\n * runs before the stack is asked, so with a tooltip, a hover menu or a list open over\n * the dialog and focus on the panel, the gear wizard asked \"Discard this gear?\" and the\n * tooltip stayed. Now the layer above takes that press, and the next one is the\n * owner's. Every other key reaches the handler as before.\n *\n * A handler that STOPS the key before it reaches a layer element has taken it too —\n * that is the DOM, and it is what the kit's cell editors and confirm buttons do.\n */\n\n/** A layer's handler, read through a ref so the stack holds one stable entry per open. */\ninterface Layer {\n escape: (e: KeyboardEvent) => void;\n /** Whether it covers the page — a dialog, a sheet, a popover, a list — rather than\n * annotating it (a tooltip). Counted by {@link useOverlayOpen}. */\n overlay: boolean;\n}\n\n/** What {@link useDismissLayer} hands back: its layer while open, for\n * {@link runOwnKeyDown} to tell whether that layer is the one on top. */\nexport type DismissLayer = RefObject<Layer | null>;\n\n/** Open layers, oldest first. Module-level, because the order is ACROSS instances. */\nconst layers: Layer[] = [];\n\n/** Escapes a claimant has taken — see {@link claimEscape}. Weak: an event is garbage\n * once its dispatch is over. */\nconst claimed = new WeakSet<Event>();\n\n/** The Escape on its way through the page: the layer that was topmost as it went down,\n * and whether that layer has been handed it yet. */\nlet inFlight: { event: KeyboardEvent; layer: Layer; done: boolean } | null = null;\n\nfunction nativeOf(e: KeyboardEvent | ReactKeyboardEvent): KeyboardEvent {\n return \"nativeEvent\" in e ? e.nativeEvent : e;\n}\n\nfunction onCapture(e: KeyboardEvent): void {\n if (e.key !== \"Escape\") return;\n // An Escape inside an IME composition cancels the composition and nothing else.\n const top = isComposing(e) ? undefined : layers[layers.length - 1];\n inFlight = top ? { event: e, layer: top, done: false } : null;\n}\n\n/** The fallback: no layer element was on the key's path, or none took it. */\nfunction onBubble(e: KeyboardEvent): void {\n handOver(e, false);\n}\n\nfunction handOver(e: KeyboardEvent | ReactKeyboardEvent, stop: boolean): boolean {\n const native = nativeOf(e);\n const flight = inFlight;\n if (native.key !== \"Escape\" || !flight || flight.event !== native || flight.done) return false;\n if (claimed.has(native)) return false;\n flight.done = true;\n // Consumed: a type=\"search\" box does not clear itself as well, and a handler further\n // out that checks `defaultPrevented` (FloatingPanel, an app's own panel) leaves it.\n e.preventDefault();\n if (stop) e.stopPropagation();\n // A layer that closed on the way, by a handler of its own, has had its Escape.\n if (layers.includes(flight.layer)) flight.layer.escape(native);\n return true;\n}\n\nfunction push(layer: Layer): void {\n if (layers.length === 0) {\n document.addEventListener(\"keydown\", onCapture, true);\n document.addEventListener(\"keydown\", onBubble);\n }\n layers.push(layer);\n if (layer.overlay) notifyOverlays();\n}\n\nfunction pop(layer: Layer): void {\n const at = layers.indexOf(layer);\n if (at >= 0) layers.splice(at, 1);\n if (at >= 0 && layer.overlay) notifyOverlays();\n if (layers.length > 0) return;\n document.removeEventListener(\"keydown\", onCapture, true);\n document.removeEventListener(\"keydown\", onBubble);\n inFlight = null;\n}\n\n/**\n * An Escape layer on the stack while `open`: the topmost layer is handed the next\n * Escape and calls `onEscape`, every layer under it waits its turn. A list opened inside\n * a dialog is above the dialog; a popover opened from a list, above the list.\n *\n * Where focus can be INSIDE the layer, its element's `onKeyDown` calls\n * {@link takeEscape} too, so the key stops there — see the module note. `onEscape` is\n * read live, so it need not be memoised; the layer is pushed and popped only when\n * `open` flips. The layer it returns is for the owner's {@link runOwnKeyDown}.\n */\nexport function useDismissLayer(\n open: boolean,\n onEscape: (e: KeyboardEvent) => void,\n { overlay = true }: { overlay?: boolean } = {},\n): DismissLayer {\n const handlerRef = useRef(onEscape);\n const layerRef = useRef<Layer | null>(null);\n // Written in an effect, not during render, so it satisfies react-hooks/refs: a\n // render that React starts and then discards — a transition, a Suspense retry —\n // would otherwise leave this holding a handler from a tree that never committed,\n // and the stack would go on to call it. Keydown events fire after the commit, so\n // the ref is always current by the time one arrives.\n useEffect(() => {\n handlerRef.current = onEscape;\n });\n useEffect(() => {\n if (!open || typeof document === \"undefined\") return;\n const layer: Layer = { escape: (e) => handlerRef.current(e), overlay };\n layerRef.current = layer;\n push(layer);\n return () => {\n pop(layer);\n layerRef.current = null;\n };\n }, [open, overlay]);\n return layerRef;\n}\n\n/*\n * Whether an overlay is open (0.49 KIT-11): every layer on the stack but a tooltip's is a\n * dialog, a sheet, a popover, a hover menu or a list covering part of the page, so the\n * stack is also the one place that knows. The floating launchers (`hideWhenOverlay`) step\n * aside while one is open instead of floating over it or beside it.\n */\nconst overlayListeners = new Set<() => void>();\n\nfunction notifyOverlays(): void {\n for (const listener of overlayListeners) listener();\n}\n\nfunction subscribeOverlays(listener: () => void): () => void {\n overlayListeners.add(listener);\n return () => {\n overlayListeners.delete(listener);\n };\n}\n\nfunction anyOverlayOpen(): boolean {\n return layers.some((layer) => layer.overlay);\n}\n\n/** True while a kit dialog, sheet, popover, hover menu or list is open (any layer of the\n * Escape stack but a tooltip's). Internal. */\nexport function useOverlayOpen(enabled = true): boolean {\n const open = useSyncExternalStore(subscribeOverlays, anyOverlayOpen, () => false);\n return enabled && open;\n}\n\n/**\n * For a layer's own element, in its `onKeyDown`: hands an Escape on its way up to the\n * topmost layer — this one, unless something opened over it without taking focus (a\n * tooltip, the numpad) — and stops it here. True when it did; false for any other key,\n * a claimed Escape, or one already handed over.\n */\nexport function takeEscape(e: KeyboardEvent | ReactKeyboardEvent): boolean {\n return handOver(e, true);\n}\n\n/**\n * For an Escape that means \"undo this step\", not \"close\": the key is the caller's, and\n * no layer is handed it. `preventDefault()`s it as well, so a handler further out that\n * checks `defaultPrevented` leaves it alone, as before.\n */\nexport function claimEscape(e: KeyboardEvent | ReactKeyboardEvent): void {\n claimed.add(nativeOf(e));\n e.preventDefault();\n}\n\n/**\n * Runs a layer owner's own key handler — a dialog's `onKeyDown` prop — and turns a\n * `preventDefault()` it makes on Escape into a claim: the one way, beside\n * {@link claimEscape}, to keep a layer open.\n *\n * Given the owner's `layer` (what {@link useDismissLayer} returned), an Escape that went\n * down while another layer was above that one skips the handler: the press is the\n * layer's on top, and the owner hears the next (0.35, KS). Without it, or while the\n * owner's layer is not open, the handler sees every key, as before.\n */\nexport function runOwnKeyDown<E extends ReactKeyboardEvent>(\n e: E,\n handler: ((e: E) => void) | undefined,\n layer?: DismissLayer,\n): void {\n if (!handler) return;\n if (layer && aboveOwner(e, layer.current)) return;\n const before = e.defaultPrevented;\n handler(e);\n if (e.key === \"Escape\" && !before && e.defaultPrevented) claimed.add(nativeOf(e));\n}\n\n/** Whether this Escape went down with a layer above `owner` — the topmost one then was\n * another, and `owner` is on the stack. An Escape the stack did not note (one inside an\n * IME composition) is nobody else's. */\nfunction aboveOwner(e: ReactKeyboardEvent, owner: Layer | null): boolean {\n const flight = inFlight;\n if (e.key !== \"Escape\" || !owner || !flight || flight.event !== nativeOf(e)) return false;\n return flight.layer !== owner && layers.includes(owner);\n}\n\n/**\n * Calls `handler` on an Escape while `enabled` — as an Escape layer. Since 0.34 this is\n * {@link useDismissLayer} with its arguments the other way round: it hears the key only\n * while nothing opened above it, and inside a dialog it no longer loses the key to the\n * dialog (Wave 2, DUP-1). `handler` is read live, so it need not be memoised.\n */\nexport function useEscapeKey(handler: () => void, enabled = true): void {\n useDismissLayer(enabled, handler);\n}\n\n/** Called with each native press an owner's React tree saw — see {@link useOutsideClick}. */\ntype PressMark = (press: Event) => void;\n\n/** The outside-click hooks watching each ref, for {@link pressInside}. */\nconst watchers = new WeakMap<RefObject<HTMLElement | null>, Set<PressMark>>();\n\n/** What an `onPointerDownCapture` hands over: a React event, its press inside. */\ntype ReactPress = { nativeEvent: Event };\n\n/**\n * An `onPointerDownCapture` for a panel whose `ref` an outside-click hook watches but\n * whose element the hook's owner does not render — {@link DropdownPanel} and\n * `ComboboxPanel` take `panelRef` from `useDropdown` / `useComboboxCore`. Every press\n * that reaches the panel through the React tree, a portalled list opened inside it\n * included, is marked inside for each hook watching `ref`. See {@link useOutsideClick}.\n */\nexport function pressInside(ref: RefObject<HTMLElement | null> | undefined): ((e: ReactPress) => void) | undefined {\n if (!ref) return undefined;\n return (e) => {\n watchers.get(ref)?.forEach((mark) => mark(e.nativeEvent));\n };\n}\n\n/**\n * Calls `handler` on a press that lands outside every supplied element, while\n * `enabled` — the outside-click-to-close half of the same dismissal story. Pass one\n * ref or several (trigger + panel); a press inside any of them is ignored. Refs and\n * `handler` are read live, so an inline `[triggerRef, panelRef]` array is fine and\n * won't churn the listener.\n *\n * ## A panel opened from inside is inside (0.48, keksdose dev#623)\n *\n * A CurrencySelect in a Popover: the currency list is portalled to `<body>`, so in the\n * DOM it is outside the popover's panel, and the first press on a currency closed the\n * POPOVER at pointerdown — the list went with it and the choice never landed. The same\n * for a combobox, a menu, a date picker's popover, a dropdown, at any depth.\n *\n * In the React tree the portal is still where it was opened from, and React passes a\n * press up that tree, through portals. So the hook hands back an\n * `onPointerDownCapture`: put it on the element the press should count as inside of —\n * the kit's Popover panel, HoverMenu, DropdownPanel and ComboboxPanel do — and every\n * press that travels through that element in React, portalled panels opened inside it\n * included, is not outside. React's listeners sit on the root and on each portal's\n * container, so they hear the press before this document listener does. No owner chain\n * to keep: depth is free, and an app's own portal inside a kit panel is covered too. A\n * panel the hook's owner does not render takes {@link pressInside} with the watched ref.\n *\n * **`pointerdown`, not `mousedown`** — one event covering mouse, touch and pen.\n * This listened for `mousedown` alone, which on a touch platform is a SYNTHESISED\n * event: the browser emits it for most taps, which is why nothing obviously broke,\n * but the synthesis is not guaranteed. A tap that begins a scroll, or one that lands\n * on an element which preventDefaults the touch sequence, may never produce one — and\n * on a phone-first PWA whose pickers, menus and flyouts all dismiss through this hook,\n * inheriting that is worse than choosing it.\n *\n * The one behaviour this changes deliberately: a touch-drag that starts outside an\n * open panel now dismisses it at touch-down, where before it did not dismiss at all\n * (a drag synthesises no mousedown). That matches every other platform surface, and\n * the anchored panels re-measure on scroll precisely because the page moves under\n * them.\n */\nexport function useOutsideClick(\n refs: RefObject<HTMLElement | null> | RefObject<HTMLElement | null>[],\n handler: () => void,\n enabled = true,\n): (e: ReactPress) => void {\n const refsRef = useRef(refs);\n const handlerRef = useRef(handler);\n // The last press this owner's React tree saw: the one the document listener is about\n // to hear, when it went through a panel the owner marked.\n const insideRef = useRef<Event | null>(null);\n // In an effect rather than during render — see the note in useDismissLayer.\n useEffect(() => {\n refsRef.current = refs;\n handlerRef.current = handler;\n });\n const markInside = useCallback((e: ReactPress) => {\n insideRef.current = e.nativeEvent;\n }, []);\n useEffect(() => {\n if (!enabled) return;\n const mark: PressMark = (press) => {\n insideRef.current = press;\n };\n const watched = Array.isArray(refsRef.current) ? refsRef.current : [refsRef.current];\n for (const r of watched) {\n const set = watchers.get(r) ?? new Set<PressMark>();\n set.add(mark);\n watchers.set(r, set);\n }\n const onPointerDown = (e: Event) => {\n const inside = insideRef.current === e;\n insideRef.current = null;\n if (inside) return;\n const target = e.target as Node;\n const list = Array.isArray(refsRef.current) ? refsRef.current : [refsRef.current];\n for (const r of list) {\n if (r.current?.contains(target)) return;\n }\n handlerRef.current();\n };\n document.addEventListener(\"pointerdown\", onPointerDown);\n return () => {\n document.removeEventListener(\"pointerdown\", onPointerDown);\n for (const r of watched) watchers.get(r)?.delete(mark);\n };\n }, [enabled]);\n return markInside;\n}\n"],"mappings":";AAAA,SAAS,aAAa,WAAW,QAAQ,4BAA4B;AAErE,SAAS,mBAAmB;AAuE5B,MAAM,SAAkB,CAAC;AAIzB,MAAM,UAAU,oBAAI,QAAe;AAInC,IAAI,WAAyE;AAE7E,SAAS,SAAS,GAAsD;AACtE,SAAO,iBAAiB,IAAI,EAAE,cAAc;AAC9C;AAEA,SAAS,UAAU,GAAwB;AACzC,MAAI,EAAE,QAAQ,SAAU;AAExB,QAAM,MAAM,YAAY,CAAC,IAAI,SAAY,OAAO,OAAO,SAAS,CAAC;AACjE,aAAW,MAAM,EAAE,OAAO,GAAG,OAAO,KAAK,MAAM,MAAM,IAAI;AAC3D;AAGA,SAAS,SAAS,GAAwB;AACxC,WAAS,GAAG,KAAK;AACnB;AAEA,SAAS,SAAS,GAAuC,MAAwB;AAC/E,QAAM,SAAS,SAAS,CAAC;AACzB,QAAM,SAAS;AACf,MAAI,OAAO,QAAQ,YAAY,CAAC,UAAU,OAAO,UAAU,UAAU,OAAO,KAAM,QAAO;AACzF,MAAI,QAAQ,IAAI,MAAM,EAAG,QAAO;AAChC,SAAO,OAAO;AAGd,IAAE,eAAe;AACjB,MAAI,KAAM,GAAE,gBAAgB;AAE5B,MAAI,OAAO,SAAS,OAAO,KAAK,EAAG,QAAO,MAAM,OAAO,MAAM;AAC7D,SAAO;AACT;AAEA,SAAS,KAAK,OAAoB;AAChC,MAAI,OAAO,WAAW,GAAG;AACvB,aAAS,iBAAiB,WAAW,WAAW,IAAI;AACpD,aAAS,iBA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U;AACjC,gBAAU,UAAU;AAAA,IACtB;AACA,UAAM,UAAU,MAAM,QAAQ,QAAQ,OAAO,IAAI,QAAQ,UAAU,CAAC,QAAQ,OAAO;AACnF,eAAW,KAAK,SAAS;AACvB,YAAM,MAAM,SAAS,IAAI,CAAC,KAAK,oBAAI,IAAe;AAClD,UAAI,IAAI,IAAI;AACZ,eAAS,IAAI,GAAG,GAAG;AAAA,IACrB;AACA,UAAM,gBAAgB,CAAC,MAAa;AAClC,YAAM,SAAS,UAAU,YAAY;AACrC,gBAAU,UAAU;AACpB,UAAI,OAAQ;AACZ,YAAM,SAAS,EAAE;AACjB,YAAM,OAAO,MAAM,QAAQ,QAAQ,OAAO,IAAI,QAAQ,UAAU,CAAC,QAAQ,OAAO;AAChF,iBAAW,KAAK,MAAM;AACpB,YAAI,EAAE,SAAS,SAAS,MAAM,EAAG;AAAA,MACnC;AACA,iBAAW,QAAQ;AAAA,IACrB;AACA,aAAS,iBAAiB,eAAe,aAAa;AACtD,WAAO,MAAM;AACX,eAAS,oBAAoB,eAAe,aAAa;AACzD,iBAAW,KAAK,QAAS,UAAS,IAAI,CAAC,GAAG,OAAO,IAAI;AAAA,IACvD;AAAA,EACF,GAAG,CAAC,OAAO,CAAC;AACZ,SAAO;AACT;","names":[]}
|
|
@@ -1,3 +1,38 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* Keep keyboard focus inside an open overlay, and give it back when it closes.
|
|
3
|
+
*
|
|
4
|
+
* Extracted from `Modal`, which was the ONLY component in this package that did any of
|
|
5
|
+
* this. Every other overlay — the full-bleed dialog a phone's row editor opens, the
|
|
6
|
+
* picker sheet, the numpad, the tour card — declared `role="dialog" aria-modal="true"`
|
|
7
|
+
* and then left focus on the page behind it. That is the worst of the two possible
|
|
8
|
+
* bugs: assistive technology hides the page because of `aria-modal`, while the user's
|
|
9
|
+
* focus is still down there in the part that is now hidden, so Tab walks through
|
|
10
|
+
* controls the screen reader refuses to describe.
|
|
11
|
+
*
|
|
12
|
+
* What this does beyond Modal's original copy:
|
|
13
|
+
*
|
|
14
|
+
* - **Recomputes the tabbable list on every Tab**, not once when the overlay opens.
|
|
15
|
+
* These panels have conditionally-rendered contents — a search box that appears
|
|
16
|
+
* once options load, a "clear" button that exists only while a filter is set — and
|
|
17
|
+
* a list captured at open time traps focus against elements that have since gone.
|
|
18
|
+
* - **Guards the restore target.** The element focused before opening may have left
|
|
19
|
+
* the DOM by the time the overlay closes (the row that owned the button was
|
|
20
|
+
* filtered away). Calling `.focus()` on a detached node silently drops focus to
|
|
21
|
+
* `<body>`, which for a keyboard user means losing their place in the page
|
|
22
|
+
* entirely. When the target is gone, focus falls back to the nearest thing that
|
|
23
|
+
* still exists rather than to nothing.
|
|
24
|
+
* - **Leaves an app's own autofocus alone** (0.33.1). React honours a child's
|
|
25
|
+
* `autoFocus` while it commits, and this hook's effect runs AFTER that commit, so
|
|
26
|
+
* focusing the container there took focus straight back off the field the app had
|
|
27
|
+
* asked for. See `initialFocus`.
|
|
28
|
+
* - **Nests.** An overlay can open another — a picker inside a dialog. Only the
|
|
29
|
+
* innermost trap handles a keystroke, and closing it hands control back to the one
|
|
30
|
+
* underneath. Innermost is decided by DOM containment rather than by mount order;
|
|
31
|
+
* see the note on `TRAP_ATTR` for why the obvious stack is wrong.
|
|
32
|
+
* `use-overlay-history.ts` reasons about the same nesting problem for the back
|
|
33
|
+
* button; this is the focus half of it.
|
|
34
|
+
*/
|
|
35
|
+
export { firstTabStop, tabStops } from "../lib/focus-left.js";
|
|
1
36
|
export interface FocusTrapOptions {
|
|
2
37
|
/** Trap only while this is true. Mount-time `true` is the common case. */
|
|
3
38
|
active?: boolean;
|
|
@@ -1,7 +1,7 @@
|
|
|
1
1
|
"use client";
|
|
2
2
|
import { useEffect, useLayoutEffect, useRef, useState } from "react";
|
|
3
|
-
|
|
4
|
-
|
|
3
|
+
import { tabStops } from "../lib/focus-left.js";
|
|
4
|
+
import { firstTabStop, tabStops as tabStops2 } from "../lib/focus-left.js";
|
|
5
5
|
const TRAP_ATTR = "data-focus-trap";
|
|
6
6
|
function focusedElement() {
|
|
7
7
|
return typeof document === "undefined" ? null : document.activeElement;
|
|
@@ -24,11 +24,11 @@ function useFocusTrap(containerRef, { active = true, restoreFocus = true, initia
|
|
|
24
24
|
const owner = node.closest(`[${TRAP_ATTR}]`);
|
|
25
25
|
return owner !== null && owner !== container;
|
|
26
26
|
};
|
|
27
|
-
const tabbables = () =>
|
|
27
|
+
const tabbables = () => tabStops(container, { includeSelf: false }).filter(
|
|
28
28
|
// A tabbable inside a NESTED open overlay belongs to that overlay's trap, not
|
|
29
29
|
// to this one — otherwise the outer list spans both panels and Tab from the
|
|
30
30
|
// inner panel's last control wraps to the OUTER panel's first.
|
|
31
|
-
(el) =>
|
|
31
|
+
(el) => !inNestedTrap(el)
|
|
32
32
|
);
|
|
33
33
|
const { initialFocus: how } = optsRef.current;
|
|
34
34
|
const focused = document.activeElement;
|
|
@@ -69,6 +69,8 @@ function useFocusTrap(containerRef, { active = true, restoreFocus = true, initia
|
|
|
69
69
|
}, [active, containerRef, opener]);
|
|
70
70
|
}
|
|
71
71
|
export {
|
|
72
|
+
firstTabStop,
|
|
73
|
+
tabStops2 as tabStops,
|
|
72
74
|
useFocusTrap
|
|
73
75
|
};
|
|
74
76
|
//# sourceMappingURL=use-focus-trap.js.map
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"sources":["../../src/hooks/use-focus-trap.ts"],"sourcesContent":["import { useEffect, useLayoutEffect, useRef, useState } from \"react\";\n\n/**\n * Keep keyboard focus inside an open overlay, and give it back when it closes.\n *\n * Extracted from `Modal`, which was the ONLY component in this package that did any of\n * this. Every other overlay — the full-bleed dialog a phone's row editor opens, the\n * picker sheet, the numpad, the tour card — declared `role=\"dialog\" aria-modal=\"true\"`\n * and then left focus on the page behind it. That is the worst of the two possible\n * bugs: assistive technology hides the page because of `aria-modal`, while the user's\n * focus is still down there in the part that is now hidden, so Tab walks through\n * controls the screen reader refuses to describe.\n *\n * What this does beyond Modal's original copy:\n *\n * - **Recomputes the tabbable list on every Tab**, not once when the overlay opens.\n * These panels have conditionally-rendered contents — a search box that appears\n * once options load, a \"clear\" button that exists only while a filter is set — and\n * a list captured at open time traps focus against elements that have since gone.\n * - **Guards the restore target.** The element focused before opening may have left\n * the DOM by the time the overlay closes (the row that owned the button was\n * filtered away). Calling `.focus()` on a detached node silently drops focus to\n * `<body>`, which for a keyboard user means losing their place in the page\n * entirely. When the target is gone, focus falls back to the nearest thing that\n * still exists rather than to nothing.\n * - **Leaves an app's own autofocus alone** (0.33.1). React honours a child's\n * `autoFocus` while it commits, and this hook's effect runs AFTER that commit, so\n * focusing the container there took focus straight back off the field the app had\n * asked for. See `initialFocus`.\n * - **Nests.** An overlay can open another — a picker inside a dialog. Only the\n * innermost trap handles a keystroke, and closing it hands control back to the one\n * underneath. Innermost is decided by DOM containment rather than by mount order;\n * see the note on `TRAP_ATTR` for why the obvious stack is wrong.\n * `use-overlay-history.ts` reasons about the same nesting problem for the back\n * button; this is the focus half of it.\n */\n\n/**\n * Candidate tab stops, in DOM order — narrowed by {@link isTabStop} to the ones a Tab\n * really reaches.\n *\n * The selector is the one `Modal` used. On its own it was not enough (round 0.34\n * BUG-4): only the bare `[tabindex]` clause excluded `-1`, so a `button`, an `input` or\n * a link taken out of the tab order still counted. A panel that ends in a roving grid —\n * the calendar's days, the month grid, the picker sheet's rows, every one of them `-1`\n * but the active cell — then had a \"last\" stop no Tab ever reaches: Tab from the real\n * last stop was not wrapped and walked out of the open panel, and Shift+Tab from the\n * first landed on a cell that is not a stop at all.\n */\nconst FOCUSABLE =\n 'a[href],button:not([disabled]),textarea:not([disabled]),input:not([disabled]),select:not([disabled]),[tabindex]:not([tabindex=\"-1\"])';\n\n/**\n * A stop the browser's own Tab would land on: in the tab order (`tabIndex` ≥ 0) and not\n * inside something `hidden` or `inert`. Removes only elements a native Tab never\n * reaches, so no correct order changes. `visibility: hidden` and closed `<details>` are\n * still not walked — they need layout, which this list has never read.\n */\nconst isTabStop = (el: HTMLElement): boolean => el.tabIndex >= 0 && !el.closest(\"[hidden],[inert]\");\n\n/**\n * Marks a container whose trap is currently active.\n *\n * \"Which trap is innermost?\" is answered by DOM CONTAINMENT, not by mount order. The\n * obvious implementation — a module-level stack pushed in the effect — is wrong, and\n * wrong in a way that passes a casual reading: React runs CHILD effects before PARENT\n * effects, so a nested overlay pushes first and the outer one ends up on top of the\n * stack, claiming to be innermost. The outer trap then handles the keystroke and wraps\n * focus to its own first element, jumping the user out of the picker they had open.\n *\n * An attribute on the live DOM cannot disagree with the DOM.\n */\nconst TRAP_ATTR = \"data-focus-trap\";\n\nexport interface FocusTrapOptions {\n /** Trap only while this is true. Mount-time `true` is the common case. */\n active?: boolean;\n /** Return focus to whatever had it before the trap engaged. Default `true`. */\n restoreFocus?: boolean;\n /**\n * What to focus when the trap engages. Default is the container itself, which is\n * what `Modal` does and why: focusing the first FIELD pops the software keyboard on\n * a phone the moment a dialog opens, before the user has asked to type.\n * The container needs `tabIndex={-1}` for this to work.\n *\n * `\"container\"` and `\"first\"` both step aside when focus is ALREADY inside the\n * container, on something other than the container itself. That is a child the app\n * focused on purpose — an `autoFocus`, which React honours before this hook's effect\n * runs — and the keyboard it brings up is the one the user was promised. Moving focus\n * off it lost keksdose's create card its amount field the instant it got it, and on a\n * phone the numpad sheet with it, which shows only while the field is focused (live\n * #402). A function is the caller's explicit choice and is always followed.\n */\n initialFocus?: \"container\" | \"first\" | (() => HTMLElement | null);\n}\n\n/** Whatever has focus right now; nothing on the server, where there is no document. */\nfunction focusedElement(): Element | null {\n return typeof document === \"undefined\" ? null : document.activeElement;\n}\n\nexport function useFocusTrap(\n containerRef: React.RefObject<HTMLElement | null>,\n { active = true, restoreFocus = true, initialFocus = \"container\" }: FocusTrapOptions = {},\n): void {\n // Latest-ref so a caller passing an inline `initialFocus` thunk — which every caller\n // will — does not tear the trap down and re-engage it on each render, stealing focus\n // back to the top of the panel mid-interaction. Written in a LAYOUT effect so that\n // the trap's cleanup, which runs after the layout effects of the same commit, reads\n // this render's `active` rather than the last one's — see the cleanup for why.\n const optsRef = useRef({ active, restoreFocus, initialFocus });\n useLayoutEffect(() => {\n optsRef.current = { active, restoreFocus, initialFocus };\n });\n\n // Where focus was BEFORE the trap engaged: the element it is given back to on close.\n //\n // Read DURING the render that turns the trap on, and that timing is the point. React\n // honours a child's `autoFocus` while it commits that render, before any effect runs,\n // so the effect below asking `document.activeElement` would get the child, inside the\n // overlay. Restoring to that on close aimed focus at the dialog that was closing —\n // already out of the DOM, so focus fell to <body> rather than going back to the\n // button that opened it.\n //\n // State adjusted during render (the pattern `Modal` uses for `open`) rather than a\n // ref written there: set once per opening and cleared on release, so a re-render\n // while open cannot replace it with something inside, and StrictMode's second render\n // and second effect both see the same element. `undefined` means \"not captured\";\n // `null` is a capture that found nothing.\n const [opener, setOpener] = useState<Element | null | undefined>(undefined);\n if (active && opener === undefined) setOpener(focusedElement());\n else if (!active && opener !== undefined) setOpener(undefined);\n\n useEffect(() => {\n if (!active) return;\n const container = containerRef.current;\n if (!container) return;\n\n container.setAttribute(TRAP_ATTR, \"\");\n\n /** Is `node` inside a trap nested within this one? */\n const inNestedTrap = (node: Element | null) => {\n if (!node) return false;\n const owner = node.closest(`[${TRAP_ATTR}]`);\n return owner !== null && owner !== container;\n };\n\n const tabbables = () =>\n Array.from(container.querySelectorAll<HTMLElement>(FOCUSABLE)).filter(\n // A tabbable inside a NESTED open overlay belongs to that overlay's trap, not\n // to this one — otherwise the outer list spans both panels and Tab from the\n // inner panel's last control wraps to the OUTER panel's first.\n (el) => isTabStop(el) && !inNestedTrap(el),\n );\n\n const { initialFocus: how } = optsRef.current;\n const focused = document.activeElement;\n // A child that already has focus was given it on purpose — see `initialFocus`.\n const childHasFocus = focused !== container && container.contains(focused);\n if (typeof how === \"function\") {\n (how() ?? container).focus();\n } else if (!childHasFocus) {\n (how === \"first\" ? (tabbables()[0] ?? container) : container).focus();\n }\n\n const onKeyDown = (e: KeyboardEvent) => {\n if (e.key !== \"Tab\") return;\n // Only the innermost trap acts. The event bubbles through every ancestor\n // container, so without this an outer dialog and an inner picker both handle one\n // Tab and fight over where focus lands.\n if (inNestedTrap(document.activeElement)) return;\n\n // Recomputed per keystroke — see the note at the top of this file.\n const items = tabbables();\n if (items.length === 0) {\n e.preventDefault();\n container.focus();\n return;\n }\n const first = items[0];\n const last = items[items.length - 1];\n const activeEl = document.activeElement;\n if (e.shiftKey && (activeEl === first || activeEl === container)) {\n e.preventDefault();\n last.focus();\n } else if (!e.shiftKey && activeEl === last) {\n e.preventDefault();\n first.focus();\n }\n };\n\n // On the container, not the document: a portalled child panel (an open dropdown\n // rendered to <body>) is outside this subtree and manages its own focus, which is\n // the behaviour Modal's comment describes and consumers already depend on.\n container.addEventListener(\"keydown\", onKeyDown);\n\n return () => {\n container.removeEventListener(\"keydown\", onKeyDown);\n container.removeAttribute(TRAP_ATTR);\n\n // Only when the trap is really being released: the container has left the page,\n // or `active` has turned false. StrictMode runs this cleanup once more right after\n // mounting, with the overlay still up, and then the effect again — and React does\n // not re-apply `autoFocus` for that second run. Restoring here would pull focus\n // out of the autofocused field for good: live #402 again, in development.\n if (container.isConnected && optsRef.current.active) return;\n if (!optsRef.current.restoreFocus) return;\n // `isConnected` is the whole point: restoring to a node that has been removed\n // sends focus to <body> and the user loses their place entirely. When the\n // original is gone, leave focus where the browser put it rather than moving it\n // somewhere arbitrary — a wrong guess is worse than no move.\n if (opener?.isConnected) (opener as HTMLElement).focus?.();\n };\n }, [active, containerRef, opener]);\n}\n"],"mappings":";AAAA,SAAS,WAAW,iBAAiB,QAAQ,gBAAgB;AAiD7D,MAAM,YACJ;AAQF,MAAM,YAAY,CAAC,OAA6B,GAAG,YAAY,KAAK,CAAC,GAAG,QAAQ,kBAAkB;AAclG,MAAM,YAAY;AAyBlB,SAAS,iBAAiC;AACxC,SAAO,OAAO,aAAa,cAAc,OAAO,SAAS;AAC3D;AAEO,SAAS,aACd,cACA,EAAE,SA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,GAAG;AACtB,UAAE,eAAe;AACjB,kBAAU,MAAM;AAChB;AAAA,MACF;AACA,YAAM,QAAQ,MAAM,CAAC;AACrB,YAAM,OAAO,MAAM,MAAM,SAAS,CAAC;AACnC,YAAM,WAAW,SAAS;AAC1B,UAAI,EAAE,aAAa,aAAa,SAAS,aAAa,YAAY;AAChE,UAAE,eAAe;AACjB,aAAK,MAAM;AAAA,MACb,WAAW,CAAC,EAAE,YAAY,aAAa,MAAM;AAC3C,UAAE,eAAe;AACjB,cAAM,MAAM;AAAA,MACd;AAAA,IACF;AAKA,cAAU,iBAAiB,WAAW,SAAS;AAE/C,WAAO,MAAM;AACX,gBAAU,oBAAoB,WAAW,SAAS;AAClD,gBAAU,gBAAgB,SAAS;AAOnC,UAAI,UAAU,eAAe,QAAQ,QAAQ,OAAQ;AACrD,UAAI,CAAC,QAAQ,QAAQ,aAAc;AAKnC,UAAI,QAAQ,YAAa,CAAC,OAAuB,QAAQ;AAAA,IAC3D;AAAA,EACF,GAAG,CAAC,QAAQ,cAAc,MAAM,CAAC;AACnC;","names":[]}
|
|
1
|
+
{"version":3,"sources":["../../src/hooks/use-focus-trap.ts"],"sourcesContent":["import { useEffect, useLayoutEffect, useRef, useState } from \"react\";\nimport { tabStops } from \"../lib/focus-left\";\n\n/**\n * Keep keyboard focus inside an open overlay, and give it back when it closes.\n *\n * Extracted from `Modal`, which was the ONLY component in this package that did any of\n * this. Every other overlay — the full-bleed dialog a phone's row editor opens, the\n * picker sheet, the numpad, the tour card — declared `role=\"dialog\" aria-modal=\"true\"`\n * and then left focus on the page behind it. That is the worst of the two possible\n * bugs: assistive technology hides the page because of `aria-modal`, while the user's\n * focus is still down there in the part that is now hidden, so Tab walks through\n * controls the screen reader refuses to describe.\n *\n * What this does beyond Modal's original copy:\n *\n * - **Recomputes the tabbable list on every Tab**, not once when the overlay opens.\n * These panels have conditionally-rendered contents — a search box that appears\n * once options load, a \"clear\" button that exists only while a filter is set — and\n * a list captured at open time traps focus against elements that have since gone.\n * - **Guards the restore target.** The element focused before opening may have left\n * the DOM by the time the overlay closes (the row that owned the button was\n * filtered away). Calling `.focus()` on a detached node silently drops focus to\n * `<body>`, which for a keyboard user means losing their place in the page\n * entirely. When the target is gone, focus falls back to the nearest thing that\n * still exists rather than to nothing.\n * - **Leaves an app's own autofocus alone** (0.33.1). React honours a child's\n * `autoFocus` while it commits, and this hook's effect runs AFTER that commit, so\n * focusing the container there took focus straight back off the field the app had\n * asked for. See `initialFocus`.\n * - **Nests.** An overlay can open another — a picker inside a dialog. Only the\n * innermost trap handles a keystroke, and closing it hands control back to the one\n * underneath. Innermost is decided by DOM containment rather than by mount order;\n * see the note on `TRAP_ATTR` for why the obvious stack is wrong.\n * `use-overlay-history.ts` reasons about the same nesting problem for the back\n * button; this is the focus half of it.\n */\n\n// The trap's reading of \"a Tab lands here\" is lib/focus-left's `tabStops` — the kit's one\n// copy of the rule since the 0.52 code review (round 0.34 BUG-4's history is there).\n// Re-exported where refactor audit 2026-10-30, DUP-9 put them, for a part that walks Tab\n// over something that is not a trap (the tour's field + card ring).\nexport { firstTabStop, tabStops } from \"../lib/focus-left\";\n\n/**\n * Marks a container whose trap is currently active.\n *\n * \"Which trap is innermost?\" is answered by DOM CONTAINMENT, not by mount order. The\n * obvious implementation — a module-level stack pushed in the effect — is wrong, and\n * wrong in a way that passes a casual reading: React runs CHILD effects before PARENT\n * effects, so a nested overlay pushes first and the outer one ends up on top of the\n * stack, claiming to be innermost. The outer trap then handles the keystroke and wraps\n * focus to its own first element, jumping the user out of the picker they had open.\n *\n * An attribute on the live DOM cannot disagree with the DOM.\n */\nconst TRAP_ATTR = \"data-focus-trap\";\n\nexport interface FocusTrapOptions {\n /** Trap only while this is true. Mount-time `true` is the common case. */\n active?: boolean;\n /** Return focus to whatever had it before the trap engaged. Default `true`. */\n restoreFocus?: boolean;\n /**\n * What to focus when the trap engages. Default is the container itself, which is\n * what `Modal` does and why: focusing the first FIELD pops the software keyboard on\n * a phone the moment a dialog opens, before the user has asked to type.\n * The container needs `tabIndex={-1}` for this to work.\n *\n * `\"container\"` and `\"first\"` both step aside when focus is ALREADY inside the\n * container, on something other than the container itself. That is a child the app\n * focused on purpose — an `autoFocus`, which React honours before this hook's effect\n * runs — and the keyboard it brings up is the one the user was promised. Moving focus\n * off it lost keksdose's create card its amount field the instant it got it, and on a\n * phone the numpad sheet with it, which shows only while the field is focused (live\n * #402). A function is the caller's explicit choice and is always followed.\n */\n initialFocus?: \"container\" | \"first\" | (() => HTMLElement | null);\n}\n\n/** Whatever has focus right now; nothing on the server, where there is no document. */\nfunction focusedElement(): Element | null {\n return typeof document === \"undefined\" ? null : document.activeElement;\n}\n\nexport function useFocusTrap(\n containerRef: React.RefObject<HTMLElement | null>,\n { active = true, restoreFocus = true, initialFocus = \"container\" }: FocusTrapOptions = {},\n): void {\n // Latest-ref so a caller passing an inline `initialFocus` thunk — which every caller\n // will — does not tear the trap down and re-engage it on each render, stealing focus\n // back to the top of the panel mid-interaction. Written in a LAYOUT effect so that\n // the trap's cleanup, which runs after the layout effects of the same commit, reads\n // this render's `active` rather than the last one's — see the cleanup for why.\n const optsRef = useRef({ active, restoreFocus, initialFocus });\n useLayoutEffect(() => {\n optsRef.current = { active, restoreFocus, initialFocus };\n });\n\n // Where focus was BEFORE the trap engaged: the element it is given back to on close.\n //\n // Read DURING the render that turns the trap on, and that timing is the point. React\n // honours a child's `autoFocus` while it commits that render, before any effect runs,\n // so the effect below asking `document.activeElement` would get the child, inside the\n // overlay. Restoring to that on close aimed focus at the dialog that was closing —\n // already out of the DOM, so focus fell to <body> rather than going back to the\n // button that opened it.\n //\n // State adjusted during render (the pattern `Modal` uses for `open`) rather than a\n // ref written there: set once per opening and cleared on release, so a re-render\n // while open cannot replace it with something inside, and StrictMode's second render\n // and second effect both see the same element. `undefined` means \"not captured\";\n // `null` is a capture that found nothing.\n const [opener, setOpener] = useState<Element | null | undefined>(undefined);\n if (active && opener === undefined) setOpener(focusedElement());\n else if (!active && opener !== undefined) setOpener(undefined);\n\n useEffect(() => {\n if (!active) return;\n const container = containerRef.current;\n if (!container) return;\n\n container.setAttribute(TRAP_ATTR, \"\");\n\n /** Is `node` inside a trap nested within this one? */\n const inNestedTrap = (node: Element | null) => {\n if (!node) return false;\n const owner = node.closest(`[${TRAP_ATTR}]`);\n return owner !== null && owner !== container;\n };\n\n const tabbables = () =>\n tabStops(container, { includeSelf: false }).filter(\n // A tabbable inside a NESTED open overlay belongs to that overlay's trap, not\n // to this one — otherwise the outer list spans both panels and Tab from the\n // inner panel's last control wraps to the OUTER panel's first.\n (el) => !inNestedTrap(el),\n );\n\n const { initialFocus: how } = optsRef.current;\n const focused = document.activeElement;\n // A child that already has focus was given it on purpose — see `initialFocus`.\n const childHasFocus = focused !== container && container.contains(focused);\n if (typeof how === \"function\") {\n (how() ?? container).focus();\n } else if (!childHasFocus) {\n (how === \"first\" ? (tabbables()[0] ?? container) : container).focus();\n }\n\n const onKeyDown = (e: KeyboardEvent) => {\n if (e.key !== \"Tab\") return;\n // Only the innermost trap acts. The event bubbles through every ancestor\n // container, so without this an outer dialog and an inner picker both handle one\n // Tab and fight over where focus lands.\n if (inNestedTrap(document.activeElement)) return;\n\n // Recomputed per keystroke — see the note at the top of this file.\n const items = tabbables();\n if (items.length === 0) {\n e.preventDefault();\n container.focus();\n return;\n }\n const first = items[0];\n const last = items[items.length - 1];\n const activeEl = document.activeElement;\n if (e.shiftKey && (activeEl === first || activeEl === container)) {\n e.preventDefault();\n last.focus();\n } else if (!e.shiftKey && activeEl === last) {\n e.preventDefault();\n first.focus();\n }\n };\n\n // On the container, not the document: a portalled child panel (an open dropdown\n // rendered to <body>) is outside this subtree and manages its own focus, which is\n // the behaviour Modal's comment describes and consumers already depend on.\n container.addEventListener(\"keydown\", onKeyDown);\n\n return () => {\n container.removeEventListener(\"keydown\", onKeyDown);\n container.removeAttribute(TRAP_ATTR);\n\n // Only when the trap is really being released: the container has left the page,\n // or `active` has turned false. StrictMode runs this cleanup once more right after\n // mounting, with the overlay still up, and then the effect again — and React does\n // not re-apply `autoFocus` for that second run. Restoring here would pull focus\n // out of the autofocused field for good: live #402 again, in development.\n if (container.isConnected && optsRef.current.active) return;\n if (!optsRef.current.restoreFocus) return;\n // `isConnected` is the whole point: restoring to a node that has been removed\n // sends focus to <body> and the user loses their place entirely. When the\n // original is gone, leave focus where the browser put it rather than moving it\n // somewhere arbitrary — a wrong guess is worse than no move.\n if (opener?.isConnected) (opener as HTMLElement).focus?.();\n };\n }, [active, containerRef, opener]);\n}\n"],"mappings":";AAAA,SAAS,WAAW,iBAAiB,QAAQ,gBAAgB;AAC7D,SAAS,gBAAgB;AAyCzB,SAAS,cAAc,YAAAA,iBAAgB;AAcvC,MAAM,YAAY;AAyBlB,SAAS,iBAAiC;AACxC,SAAO,OAAO,aAAa,cAAc,OAAO,SAAS;AAC3D;AAEO,SAAS,aACd,cACA,EAAE,SAAS,MAAM,eAAe,MAAM,eAAe,YAAY,IAAsB,CAAC,GAClF;AAMN,QAAM,UAAU,OAAO,EAAE,QAAQ,cAAc,aAAa,CAAC;AAC7D,kBAAgB,MAAM;AACpB,YAAQ,UAAU,EAAE,QAAQ,cAAc,aAAa;AAAA,EACzD,CAAC;AAgBD,QAAM,CAAC,QAAQ,SAAS,IAAI,SAAqC,MAAS;AAC1E,MAAI,UAAU,WAAW,OAAW,WAAU,eAAe,CAAC;AAAA,WACrD,CAAC,UAAU,WAAW,OAAW,WAAU,MAAS;AAE7D,YAAU,MAAM;AACd,QAAI,CAAC,OAAQ;AACb,UAAM,YAAY,aAAa;AAC/B,QAAI,CAAC,UAAW;AAEhB,cAAU,aAAa,WAAW,EAAE;AAGpC,UAAM,eAAe,CAAC,SAAyB;AAC7C,UAAI,CAAC,KAAM,QAAO;AAClB,YAAM,QAAQ,KAAK,QAAQ,IAAI,SAAS,GAAG;AAC3C,aAAO,UAAU,QAAQ,UAAU;AAAA,IACrC;AAEA,UAAM,YAAY,MAChB,SAAS,WAAW,EAAE,aAAa,M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12 @@ export declare function matchesHotkey(e: KeyboardEvent, combo: ParsedHotkey): bo
|
|
|
49
49
|
* - Modifiers match EXACTLY: `"Ctrl+K"` does not fire on Ctrl+Shift+K.
|
|
50
50
|
* - Typing in a field is left alone unless `allowInInputs`, except for a combo with
|
|
51
51
|
* Ctrl / Meta / Alt, which no one types as text.
|
|
52
|
-
* - A key held down fires once, not on every repeat
|
|
52
|
+
* - A key held down fires once, not on every repeat — and its repeats are cancelled as
|
|
53
|
+
* the first press was, or the browser acts on them.
|
|
53
54
|
* - The newest `handler` is always called; changing it does not re-attach the listener.
|
|
54
55
|
*
|
|
55
|
-
* `useCommandKey` (the ⌘K palette hook) is
|
|
56
|
+
* `useCommandKey` (the ⌘K palette hook) is this with `"Mod+K"` and `allowInInputs`
|
|
57
|
+
* since 0.52, and FormActions' Ctrl/Cmd+Enter is {@link matchesHotkey} (refactor audit
|
|
58
|
+
* 2026-10-30, DUP-12): one reading of a chord.
|
|
56
59
|
*/
|
|
57
60
|
export declare function useHotkey(combo: Hotkey | ReadonlyArray<Hotkey>, handler: (event: KeyboardEvent) => void, options?: UseHotkeyOptions): void;
|
package/dist/hooks/use-hotkey.js
CHANGED
|
@@ -46,14 +46,15 @@ const KEY_ALIASES = {
|
|
|
46
46
|
left: "arrowleft",
|
|
47
47
|
right: "arrowright"
|
|
48
48
|
};
|
|
49
|
+
const NON_LATIN_LETTER = /^(?!\p{Script=Latin})\p{L}$/u;
|
|
49
50
|
function matchesHotkey(e, combo) {
|
|
50
51
|
if (e.ctrlKey !== combo.ctrl || e.metaKey !== combo.meta || e.altKey !== combo.alt) return false;
|
|
51
52
|
const want = KEY_ALIASES[combo.key.toLowerCase()] ?? combo.key.toLowerCase();
|
|
52
53
|
const key = (e.key ?? "").toLowerCase();
|
|
53
54
|
const code = (e.code ?? "").toLowerCase();
|
|
54
|
-
const
|
|
55
|
-
if (!
|
|
56
|
-
const symbol = want.length === 1 && !/[a-z0-9]/.test(want);
|
|
55
|
+
const physical = /^[a-z]$/.test(want) && NON_LATIN_LETTER.test(e.key ?? "") && code === `key${want}`;
|
|
56
|
+
if (key !== want && code !== want && !physical) return false;
|
|
57
|
+
const symbol = want.length === 1 && !/[a-z0-9 ]/.test(want);
|
|
57
58
|
return symbol && !combo.shift ? true : e.shiftKey === combo.shift;
|
|
58
59
|
}
|
|
59
60
|
function isTypingTarget(target) {
|
|
@@ -82,7 +83,6 @@ function useHotkey(combo, handler, options = {}) {
|
|
|
82
83
|
const parsed = key.split("\0").map((c) => parseHotkey(c, apple));
|
|
83
84
|
const listener = (raw) => {
|
|
84
85
|
const e = raw;
|
|
85
|
-
if (e.repeat) return;
|
|
86
86
|
const hit = parsed.find((p) => matchesHotkey(e, p));
|
|
87
87
|
if (!hit) return;
|
|
88
88
|
if (allowInInputs !== true && isTypingTarget(e.target)) {
|
|
@@ -90,6 +90,7 @@ function useHotkey(combo, handler, options = {}) {
|
|
|
90
90
|
if (allowInInputs === "never" || !chorded) return;
|
|
91
91
|
}
|
|
92
92
|
if (preventDefault) e.preventDefault();
|
|
93
|
+
if (e.repeat) return;
|
|
93
94
|
handlerRef.current(e);
|
|
94
95
|
};
|
|
95
96
|
node.addEventListener(event, listener);
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"sources":["../../src/hooks/use-hotkey.ts"],"sourcesContent":["import { useEffect, useRef } from \"react\";\n\n/**\n * A key combination: modifiers and one key, joined by \"+\", case-insensitive —\n * `\"Ctrl+Shift+F\"`, `\"Mod+K\"`, `\"Alt+ArrowUp\"`, `\"Escape\"`, `\"?\"`.\n *\n * Modifiers: `Ctrl` (`Control`), `Meta` (`Cmd`, `Command`), `Shift`, `Alt` (`Option`),\n * and `Mod` — Cmd on Apple platforms, Ctrl everywhere else, the one to use for an\n * app shortcut. The key is `KeyboardEvent.key` (\"f\", \"Enter\", \"ArrowUp\", \"/\"), or a\n * `KeyboardEvent.code` (\"KeyF\", \"Digit1\") when the physical key is what matters.\n * Several combos: pass an array.\n */\nexport type Hotkey = string;\n\nexport interface UseHotkeyOptions {\n /** Off while `false` (default `true`). */\n enabled?: boolean;\n /** Call `preventDefault()` on a match (default `true`): Ctrl+Shift+F must not also\n * open the browser's own dialog. */\n preventDefault?: boolean;\n /** Where to listen. Default `document`. A ref, an element, or `window`. */\n target?: EventTarget | null | { current: EventTarget | null };\n /**\n * Fire while the focus is in a text field, select or contenteditable too. Default\n * `false`: a shortcut must not steal the letters someone is typing. A combo with Ctrl,\n * Meta or Alt is not typing — those still fire unless this is `\"never\"`.\n */\n allowInInputs?: boolean | \"never\";\n /** `keydown` (default) or `keyup`. */\n event?: \"keydown\" | \"keyup\";\n}\n\nexport interface ParsedHotkey {\n ctrl: boolean;\n meta: boolean;\n shift: boolean;\n alt: boolean;\n key: string;\n}\n\n/** Whether this is an Apple platform, where `Mod` means Cmd. */\nexport function isApplePlatform(): boolean {\n if (typeof navigator === \"undefined\") return false;\n const nav = navigator as Navigator & { userAgentData?: { platform?: string } };\n return /mac|iphone|ipad|ipod/i.test(nav.userAgentData?.platform || nav.platform || nav.userAgent);\n}\n\n/** Parse one combo. `apple` decides what `Mod` is. Throws on an empty key. */\nexport function parseHotkey(combo: Hotkey, apple = isApplePlatform()): ParsedHotkey {\n const parts = combo\n .split(\"+\")\n .map((p) => p.trim())\n // \"Ctrl++\" is Ctrl and \"+\": an empty part after a \"+\" is the plus key itself.\n .map((p, i, all) => (p === \"\" && i === all.length - 1 ? \"+\" : p))\n .filter((p) => p !== \"\");\n const out: ParsedHotkey = { ctrl: false, meta: false, shift: false, alt: false, key: \"\" };\n for (const part of parts) {\n switch (part.toLowerCase()) {\n case \"ctrl\":\n case \"control\":\n out.ctrl = true;\n break;\n case \"meta\":\n case \"cmd\":\n case \"command\":\n out.meta = true;\n break;\n case \"mod\":\n if (apple) out.meta = true;\n else out.ctrl = true;\n break;\n case \"shift\":\n out.shift = true;\n break;\n case \"alt\":\n case \"option\":\n out.alt = true;\n break;\n default:\n out.key = part;\n }\n }\n if (!out.key) throw new Error(`useHotkey: \"${combo}\" names no key`);\n return out;\n}\n\nconst KEY_ALIASES: Record<string, string> = {\n esc: \"escape\",\n space: \" \",\n del: \"delete\",\n up: \"arrowup\",\n down: \"arrowdown\",\n left: \"arrowleft\",\n right: \"arrowright\",\n};\n\n/** Whether `e` is `combo` — every modifier as named (no more, no fewer), and the key. */\nexport function matchesHotkey(e: KeyboardEvent, combo: ParsedHotkey): boolean {\n if (e.ctrlKey !== combo.ctrl || e.metaKey !== combo.meta || e.altKey !== combo.alt) return false;\n const want = KEY_ALIASES[combo.key.toLowerCase()] ?? combo.key.toLowerCase();\n const key = (e.key ?? \"\").toLowerCase();\n const code = (e.code ?? \"\").toLowerCase();\n const keyMatches = key === want || code === want;\n if (!keyMatches) return false;\n // Shift must match exactly for a letter or a named key; for a symbol it is how the\n // symbol is typed (\"?\" is Shift+/ on a US layout, a plain key on others), so an\n // unnamed Shift is not held against it.\n const symbol = want.length === 1 && !/[a-z0-9]/.test(want);\n return symbol && !combo.shift ? true : e.shiftKey === combo.shift;\n}\n\n/** Is the focus somewhere that takes typed characters? */\nfunction isTypingTarget(target: EventTarget | null): boolean {\n if (!(target instanceof HTMLElement)) return false;\n if (target.isContentEditable) return true;\n if (target instanceof HTMLTextAreaElement || target instanceof HTMLSelectElement) return true;\n if (target instanceof HTMLInputElement) {\n return ![\"button\", \"checkbox\", \"radio\", \"submit\", \"reset\", \"range\", \"color\", \"file\", \"image\"].includes(target.type);\n }\n return false;\n}\n\n/**\n * Call `handler` when `combo` is pressed — kastlan's feedback button (Ctrl+Shift+F,\n * feedback-button:60) wired it by hand, and so will every next shortcut.\n *\n * - `Mod` is Cmd on a Mac and Ctrl elsewhere, read once per mount.\n * - Modifiers match EXACTLY: `\"Ctrl+K\"` does not fire on Ctrl+Shift+K.\n * - Typing in a field is left alone unless `allowInInputs`, except for a combo with\n * Ctrl / Meta / Alt, which no one types as text.\n * - A key held down fires once, not on every repeat.\n * - The newest `handler` is always called; changing it does not re-attach the listener.\n *\n * `useCommandKey` (the ⌘K palette hook) is unchanged; this is its general form.\n */\nexport function useHotkey(\n combo: Hotkey | ReadonlyArray<Hotkey>,\n handler: (event: KeyboardEvent) => void,\n options: UseHotkeyOptions = {},\n): void {\n const { enabled = true, preventDefault = true, target, allowInInputs = false, event = \"keydown\" } = options;\n const handlerRef = useRef(handler);\n useEffect(() => {\n handlerRef.current = handler;\n });\n const key = typeof combo === \"string\" ? combo : combo.join(\"\\u0000\");\n const targetEl = target && \"current\" in target ? undefined : target;\n const targetRef = target && \"current\" in target ? target : undefined;\n\n useEffect(() => {\n if (!enabled) return;\n const node: EventTarget | null =\n targetRef?.current ?? targetEl ?? (typeof document === \"undefined\" ? null : document);\n if (!node) return;\n const apple = isApplePlatform();\n const parsed = key.split(\"\\u0000\").map((c) => parseHotkey(c, apple));\n const listener = (raw: Event) => {\n const e = raw as KeyboardEvent;\n if (e.repeat) return;\n const hit = parsed.find((p) => matchesHotkey(e, p));\n if (!hit) return;\n if (allowInInputs !== true && isTypingTarget(e.target)) {\n const chorded = hit.ctrl || hit.meta || hit.alt;\n if (allowInInputs === \"never\" || !chorded) return;\n }\n if (preventDefault) e.preventDefault();\n handlerRef.current(e);\n };\n node.addEventListener(event, listener);\n return () => node.removeEventListener(event, listener);\n }, [key, enabled, preventDefault, allowInInputs, event, targetEl, targetRef]);\n}\n"],"mappings":";AAAA,SAAS,WAAW,cAAc;AAyC3B,SAAS,kBAA2B;AACzC,MAAI,OAAO,cAAc,YAAa,QAAO;AAC7C,QAAM,MAAM;AACZ,SAAO,wBAAwB,KAAK,IAAI,eAAe,YAAY,IAAI,YAAY,IAAI,SAAS;AAClG;AAGO,SAAS,YAAY,OAAe,QAAQ,gBAAgB,GAAiB;AAClF,QAAM,QAAQ,MACX,MAAM,GAAG,EACT,IAAI,CAAC,MAAM,EAAE,KAAK,CAAC,EAEnB,IAAI,CAAC,GAAG,GAAG,QAAS,MAAM,MAAM,MAAM,IAAI,SAAS,IAAI,MAAM,CAAE,EA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MAC7C;AACA,UAAI,eAAgB,GAAE,eAAe;AACrC,iBAAW,QAAQ,CAAC;AAAA,IACtB;AACA,SAAK,iBAAiB,OAAO,QAAQ;AACrC,WAAO,MAAM,KAAK,oBAAoB,OAAO,QAAQ;AAAA,EACvD,GAAG,CAAC,KAAK,SAAS,gBAAgB,eAAe,OAAO,UAAU,SAAS,CAAC;AAC9E;","names":[]}
|
|
1
|
+
{"version":3,"sources":["../../src/hooks/use-hotkey.ts"],"sourcesContent":["import { useEffect, useRef } from \"react\";\n\n/**\n * A key combination: modifiers and one key, joined by \"+\", case-insensitive —\n * `\"Ctrl+Shift+F\"`, `\"Mod+K\"`, `\"Alt+ArrowUp\"`, `\"Escape\"`, `\"?\"`.\n *\n * Modifiers: `Ctrl` (`Control`), `Meta` (`Cmd`, `Command`), `Shift`, `Alt` (`Option`),\n * and `Mod` — Cmd on Apple platforms, Ctrl everywhere else, the one to use for an\n * app shortcut. The key is `KeyboardEvent.key` (\"f\", \"Enter\", \"ArrowUp\", \"/\"), or a\n * `KeyboardEvent.code` (\"KeyF\", \"Digit1\") when the physical key is what matters.\n * Several combos: pass an array.\n */\nexport type Hotkey = string;\n\nexport interface UseHotkeyOptions {\n /** Off while `false` (default `true`). */\n enabled?: boolean;\n /** Call `preventDefault()` on a match (default `true`): Ctrl+Shift+F must not also\n * open the browser's own dialog. */\n preventDefault?: boolean;\n /** Where to listen. Default `document`. A ref, an element, or `window`. */\n target?: EventTarget | null | { current: EventTarget | null };\n /**\n * Fire while the focus is in a text field, select or contenteditable too. Default\n * `false`: a shortcut must not steal the letters someone is typing. A combo with Ctrl,\n * Meta or Alt is not typing — those still fire unless this is `\"never\"`.\n */\n allowInInputs?: boolean | \"never\";\n /** `keydown` (default) or `keyup`. */\n event?: \"keydown\" | \"keyup\";\n}\n\nexport interface ParsedHotkey {\n ctrl: boolean;\n meta: boolean;\n shift: boolean;\n alt: boolean;\n key: string;\n}\n\n/** Whether this is an Apple platform, where `Mod` means Cmd. */\nexport function isApplePlatform(): boolean {\n if (typeof navigator === \"undefined\") return false;\n const nav = navigator as Navigator & { userAgentData?: { platform?: string } };\n return /mac|iphone|ipad|ipod/i.test(nav.userAgentData?.platform || nav.platform || nav.userAgent);\n}\n\n/** Parse one combo. `apple` decides what `Mod` is. Throws on an empty key. */\nexport function parseHotkey(combo: Hotkey, apple = isApplePlatform()): ParsedHotkey {\n const parts = combo\n .split(\"+\")\n .map((p) => p.trim())\n // \"Ctrl++\" is Ctrl and \"+\": an empty part after a \"+\" is the plus key itself.\n .map((p, i, all) => (p === \"\" && i === all.length - 1 ? \"+\" : p))\n .filter((p) => p !== \"\");\n const out: ParsedHotkey = { ctrl: false, meta: false, shift: false, alt: false, key: \"\" };\n for (const part of parts) {\n switch (part.toLowerCase()) {\n case \"ctrl\":\n case \"control\":\n out.ctrl = true;\n break;\n case \"meta\":\n case \"cmd\":\n case \"command\":\n out.meta = true;\n break;\n case \"mod\":\n if (apple) out.meta = true;\n else out.ctrl = true;\n break;\n case \"shift\":\n out.shift = true;\n break;\n case \"alt\":\n case \"option\":\n out.alt = true;\n break;\n default:\n out.key = part;\n }\n }\n if (!out.key) throw new Error(`useHotkey: \"${combo}\" names no key`);\n return out;\n}\n\nconst KEY_ALIASES: Record<string, string> = {\n esc: \"escape\",\n space: \" \",\n del: \"delete\",\n up: \"arrowup\",\n down: \"arrowdown\",\n left: \"arrowleft\",\n right: \"arrowright\",\n};\n\n/** One letter of a script other than Latin: what a Russian, Greek or Hebrew layout's letter keys type. */\nconst NON_LATIN_LETTER = /^(?!\\p{Script=Latin})\\p{L}$/u;\n\n/** Whether `e` is `combo` — every modifier as named (no more, no fewer), and the key. */\nexport function matchesHotkey(e: KeyboardEvent, combo: ParsedHotkey): boolean {\n if (e.ctrlKey !== combo.ctrl || e.metaKey !== combo.meta || e.altKey !== combo.alt) return false;\n const want = KEY_ALIASES[combo.key.toLowerCase()] ?? combo.key.toLowerCase();\n const key = (e.key ?? \"\").toLowerCase();\n const code = (e.code ?? \"\").toLowerCase();\n // On a non-Latin layout `key` is the local letter — Ctrl+K types \"л\" on a Russian one —\n // so a letter chord never fired there, ⌘K included (0.52 code review, use-hotkey.ts; the\n // hand-written ⌘K listener before 0.52 compared `key` alone and missed it too). The\n // physical key stands in for the letter there, and only there: a Latin layout's letter\n // is wherever it types (Dvorak's K is on QWERTY's V).\n const physical = /^[a-z]$/.test(want) && NON_LATIN_LETTER.test(e.key ?? \"\") && code === `key${want}`;\n if (key !== want && code !== want && !physical) return false;\n // Shift must match exactly for a letter or a named key; for a symbol it is how the\n // symbol is typed (\"?\" is Shift+/ on a US layout, a plain key on others), so an\n // unnamed Shift is not held against it. Space is a named key, not a symbol, though its\n // alias is one character: \"Space\" fired on Shift+Space, the browser's page-up, and\n // cancelled it (0.52 code review, use-hotkey.ts).\n const symbol = want.length === 1 && !/[a-z0-9 ]/.test(want);\n return symbol && !combo.shift ? true : e.shiftKey === combo.shift;\n}\n\n/** Is the focus somewhere that takes typed characters? */\nfunction isTypingTarget(target: EventTarget | null): boolean {\n if (!(target instanceof HTMLElement)) return false;\n if (target.isContentEditable) return true;\n if (target instanceof HTMLTextAreaElement || target instanceof HTMLSelectElement) return true;\n if (target instanceof HTMLInputElement) {\n return ![\"button\", \"checkbox\", \"radio\", \"submit\", \"reset\", \"range\", \"color\", \"file\", \"image\"].includes(target.type);\n }\n return false;\n}\n\n/**\n * Call `handler` when `combo` is pressed — kastlan's feedback button (Ctrl+Shift+F,\n * feedback-button:60) wired it by hand, and so will every next shortcut.\n *\n * - `Mod` is Cmd on a Mac and Ctrl elsewhere, read once per mount.\n * - Modifiers match EXACTLY: `\"Ctrl+K\"` does not fire on Ctrl+Shift+K.\n * - Typing in a field is left alone unless `allowInInputs`, except for a combo with\n * Ctrl / Meta / Alt, which no one types as text.\n * - A key held down fires once, not on every repeat — and its repeats are cancelled as\n * the first press was, or the browser acts on them.\n * - The newest `handler` is always called; changing it does not re-attach the listener.\n *\n * `useCommandKey` (the ⌘K palette hook) is this with `\"Mod+K\"` and `allowInInputs`\n * since 0.52, and FormActions' Ctrl/Cmd+Enter is {@link matchesHotkey} (refactor audit\n * 2026-10-30, DUP-12): one reading of a chord.\n */\nexport function useHotkey(\n combo: Hotkey | ReadonlyArray<Hotkey>,\n handler: (event: KeyboardEvent) => void,\n options: UseHotkeyOptions = {},\n): void {\n const { enabled = true, preventDefault = true, target, allowInInputs = false, event = \"keydown\" } = options;\n const handlerRef = useRef(handler);\n useEffect(() => {\n handlerRef.current = handler;\n });\n const key = typeof combo === \"string\" ? combo : combo.join(\"\\u0000\");\n const targetEl = target && \"current\" in target ? undefined : target;\n const targetRef = target && \"current\" in target ? target : undefined;\n\n useEffect(() => {\n if (!enabled) return;\n const node: EventTarget | null =\n targetRef?.current ?? targetEl ?? (typeof document === \"undefined\" ? null : document);\n if (!node) return;\n const apple = isApplePlatform();\n const parsed = key.split(\"\\u0000\").map((c) => parseHotkey(c, apple));\n const listener = (raw: Event) => {\n const e = raw as KeyboardEvent;\n const hit = parsed.find((p) => matchesHotkey(e, p));\n if (!hit) return;\n if (allowInInputs !== true && isTypingTarget(e.target)) {\n const chorded = hit.ctrl || hit.meta || hit.alt;\n if (allowInInputs === \"never\" || !chorded) return;\n }\n if (preventDefault) e.preventDefault();\n // A held key's repeats are cancelled like its first press, and call nothing. They\n // returned before the `preventDefault` once, so a held Ctrl+K's repeats reached the\n // browser's own Ctrl+K and took the focus out of the palette ⌘K had just opened\n // (0.52 code review, use-hotkey.ts; the hand-written ⌘K listener cancelled them).\n if (e.repeat) return;\n handlerRef.current(e);\n };\n node.addEventListener(event, listener);\n return () => node.removeEventListener(event, listener);\n }, [key, enabled, preventDefault, allowInInputs, event, targetEl, targetRef]);\n}\n"],"mappings":";AAAA,SAAS,WAAW,cAAc;AAyC3B,SAAS,kBAA2B;AACzC,MAAI,OAAO,cAAc,YAAa,QAAO;AAC7C,QAAM,MAAM;AACZ,SAAO,wBAAwB,KAAK,IAAI,eAAe,YAAY,IAAI,YAAY,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C,MAAM,YAAY,GAAG,KAAK,CAAC;AACnE,UAAM,WAAW,CAAC,QAAe;AAC/B,YAAM,IAAI;AACV,YAAM,MAAM,OAAO,KAAK,CAAC,MAAM,cAAc,GAAG,CAAC,CAAC;AAClD,UAAI,CAAC,IAAK;AACV,UAAI,kBAAkB,QAAQ,eAAe,EAAE,MAAM,GAAG;AACtD,cAAM,UAAU,IAAI,QAAQ,IAAI,QAAQ,IAAI;AAC5C,YAAI,kBAAkB,WAAW,CAAC,QAAS;AAAA,MAC7C;AACA,UAAI,eAAgB,GAAE,eAAe;AAKrC,UAAI,EAAE,OAAQ;AACd,iBAAW,QAAQ,CAAC;AAAA,IACtB;AACA,SAAK,iBAAiB,OAAO,QAAQ;AACrC,WAAO,MAAM,KAAK,oBAAoB,OAAO,QAAQ;AAAA,EACvD,GAAG,CAAC,KAAK,SAAS,gBAAgB,eAAe,OAAO,UAAU,SAAS,CAAC;AAC9E;","names":[]}
|
|
@@ -1,4 +1,10 @@
|
|
|
1
1
|
import { type PointerEvent as ReactPointerEvent } from "react";
|
|
2
|
+
export interface LongPressOptions {
|
|
3
|
+
/** Default `true`. Off, a press does nothing and the context menu is the browser's. */
|
|
4
|
+
enabled?: boolean;
|
|
5
|
+
/** How long a press is held, in ms. Default 500. */
|
|
6
|
+
delay?: number;
|
|
7
|
+
}
|
|
2
8
|
export interface LongPressResult {
|
|
3
9
|
handlers: {
|
|
4
10
|
onPointerDown: (e: ReactPointerEvent) => void;
|
|
@@ -24,7 +30,4 @@ export interface LongPressResult {
|
|
|
24
30
|
* with `select-none [-webkit-touch-callout:none]` on the element: iOS's callout
|
|
25
31
|
* only yields to that CSS.
|
|
26
32
|
*/
|
|
27
|
-
export declare function useLongPress(onLongPress: () => void, { enabled, delay }?:
|
|
28
|
-
enabled?: boolean;
|
|
29
|
-
delay?: number;
|
|
30
|
-
}): LongPressResult;
|
|
33
|
+
export declare function useLongPress(onLongPress: () => void, { enabled, delay }?: LongPressOptions): LongPressResult;
|
|
@@ -68,6 +68,9 @@ function useLongPress(onLongPress, { enabled = true, delay = LONG_PRESS_MS } = {
|
|
|
68
68
|
fired.current = false;
|
|
69
69
|
return true;
|
|
70
70
|
}, []);
|
|
71
|
+
useEffect(() => {
|
|
72
|
+
if (!enabled) cancel();
|
|
73
|
+
}, [enabled, cancel]);
|
|
71
74
|
useEffect(() => cancel, [cancel]);
|
|
72
75
|
return { handlers: { onPointerDown, onPointerMove, onContextMenu }, consumeClick };
|
|
73
76
|
}
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"sources":["../../src/hooks/use-long-press.ts"],"sourcesContent":["import { useCallback, useEffect, useRef, type PointerEvent as ReactPointerEvent } from \"react\";\n\n// The press-and-hold that puts DataTable's phone cards into selection mode (0.40,\n// keksdose live #421). Taken over from keksdose's register list\n// (frontend/src/shared/hooks/use-long-press.ts, its feedback #153) so the kit's cards\n// and kk's register answer the same gesture the same way: 500 ms, an 8 px dead zone,\n// cancelled by a scroll, the trailing click swallowed.\n\nconst LONG_PRESS_MS = 500;\n/** The same 8 px dead zone `useRowSwipe` locks its axis at: the press is dead by the\n * time the swipe hook takes pointer capture on its (ancestor) layer. */\nconst SLOP_PX = 8;\n\nconst movedBeyondSlop = (from: { x: number; y: number }, x: number, y: number) =>\n Math.hypot(x - from.x, y - from.y) > SLOP_PX;\n\nexport interface LongPressResult {\n handlers: {\n onPointerDown: (e: ReactPointerEvent) => void;\n onPointerMove: (e: ReactPointerEvent) => void;\n onContextMenu: (e: { preventDefault: () => void }) => void;\n };\n /** True exactly once after a long press fired: call it from an `onClickCapture` to\n * swallow the click the browser still sends when the finger lifts. */\n consumeClick: () => boolean;\n}\n\n/**\n * A press-and-hold on a touch row that may ALSO be swipeable.\n *\n * - The cancel listeners live on `window`: `useRowSwipe` captures the pointer on an\n * ancestor once a drag resolves to the x axis, after which the pressed element's\n * own pointer handlers stop firing, and a timer cancelled only there would fire\n * mid-swipe.\n * - A scroll cancels too (`touch-action: pan-y` hands vertical panning to the\n * browser, which sends `pointercancel`; the capture-phase `scroll` is the backstop).\n * - `contextmenu` is suppressed while enabled — Android fires it at ~500 ms. Pair it\n * with `select-none [-webkit-touch-callout:none]` on the element: iOS's callout\n * only yields to that CSS.\n */\nexport function useLongPress(\n onLongPress: () => void,\n { enabled = true, delay = LONG_PRESS_MS }:
|
|
1
|
+
{"version":3,"sources":["../../src/hooks/use-long-press.ts"],"sourcesContent":["import { useCallback, useEffect, useRef, type PointerEvent as ReactPointerEvent } from \"react\";\n\n// The press-and-hold that puts DataTable's phone cards into selection mode (0.40,\n// keksdose live #421). Taken over from keksdose's register list\n// (frontend/src/shared/hooks/use-long-press.ts, its feedback #153) so the kit's cards\n// and kk's register answer the same gesture the same way: 500 ms, an 8 px dead zone,\n// cancelled by a scroll, the trailing click swallowed. Public since 0.52 (DUP-8, refactor\n// audit 2026-10-30): private, it left keksdose keeping the original beside the copy.\n\nconst LONG_PRESS_MS = 500;\n/** The same 8 px dead zone `useRowSwipe` locks its axis at: the press is dead by the\n * time the swipe hook takes pointer capture on its (ancestor) layer. */\nconst SLOP_PX = 8;\n\nconst movedBeyondSlop = (from: { x: number; y: number }, x: number, y: number) =>\n Math.hypot(x - from.x, y - from.y) > SLOP_PX;\n\nexport interface LongPressOptions {\n /** Default `true`. Off, a press does nothing and the context menu is the browser's. */\n enabled?: boolean;\n /** How long a press is held, in ms. Default 500. */\n delay?: number;\n}\n\nexport interface LongPressResult {\n handlers: {\n onPointerDown: (e: ReactPointerEvent) => void;\n onPointerMove: (e: ReactPointerEvent) => void;\n onContextMenu: (e: { preventDefault: () => void }) => void;\n };\n /** True exactly once after a long press fired: call it from an `onClickCapture` to\n * swallow the click the browser still sends when the finger lifts. */\n consumeClick: () => boolean;\n}\n\n/**\n * A press-and-hold on a touch row that may ALSO be swipeable.\n *\n * - The cancel listeners live on `window`: `useRowSwipe` captures the pointer on an\n * ancestor once a drag resolves to the x axis, after which the pressed element's\n * own pointer handlers stop firing, and a timer cancelled only there would fire\n * mid-swipe.\n * - A scroll cancels too (`touch-action: pan-y` hands vertical panning to the\n * browser, which sends `pointercancel`; the capture-phase `scroll` is the backstop).\n * - `contextmenu` is suppressed while enabled — Android fires it at ~500 ms. Pair it\n * with `select-none [-webkit-touch-callout:none]` on the element: iOS's callout\n * only yields to that CSS.\n */\nexport function useLongPress(\n onLongPress: () => void,\n { enabled = true, delay = LONG_PRESS_MS }: LongPressOptions = {},\n): LongPressResult {\n const timer = useRef<number | null>(null);\n const start = useRef({ x: 0, y: 0 });\n const fired = useRef(false);\n const teardown = useRef<(() => void) | null>(null);\n const cbRef = useRef(onLongPress);\n useEffect(() => {\n cbRef.current = onLongPress;\n });\n\n const cancel = useCallback(() => {\n if (timer.current !== null) {\n window.clearTimeout(timer.current);\n timer.current = null;\n }\n teardown.current?.();\n teardown.current = null;\n }, []);\n\n const onPointerDown = useCallback(\n (e: ReactPointerEvent) => {\n // Cleared above every early return: a press whose trailing click never arrives\n // (the finger lifted over another row) would otherwise leave the latch armed,\n // and it would eat the next real tap once the card has switched modes.\n fired.current = false;\n if (!enabled) return;\n if (e.pointerType === \"mouse\" && e.button !== 0) return;\n cancel();\n start.current = { x: e.clientX, y: e.clientY };\n\n const onEnd = () => cancel();\n const onMove = (ev: PointerEvent) => {\n if (movedBeyondSlop(start.current, ev.clientX, ev.clientY)) cancel();\n };\n window.addEventListener(\"pointerup\", onEnd);\n window.addEventListener(\"pointercancel\", onEnd);\n window.addEventListener(\"pointermove\", onMove);\n window.addEventListener(\"scroll\", onEnd, { capture: true, passive: true });\n teardown.current = () => {\n window.removeEventListener(\"pointerup\", onEnd);\n window.removeEventListener(\"pointercancel\", onEnd);\n window.removeEventListener(\"pointermove\", onMove);\n window.removeEventListener(\"scroll\", onEnd, { capture: true });\n };\n\n timer.current = window.setTimeout(() => {\n cancel();\n fired.current = true;\n // The swipe stages' haptic vocabulary; absent on iOS Safari.\n navigator.vibrate?.(20);\n cbRef.current();\n }, delay);\n },\n [cancel, delay, enabled],\n );\n\n // Also on the element: it still cancels if an ancestor stops the native event\n // before it reaches `window`.\n const onPointerMove = useCallback(\n (e: ReactPointerEvent) => {\n if (timer.current === null) return;\n if (movedBeyondSlop(start.current, e.clientX, e.clientY)) cancel();\n },\n [cancel],\n );\n\n const onContextMenu = useCallback(\n (e: { preventDefault: () => void }) => {\n if (enabled) e.preventDefault();\n },\n [enabled],\n );\n\n const consumeClick = useCallback(() => {\n if (!fired.current) return false;\n fired.current = false;\n return true;\n }, []);\n\n // Turned off mid-press: the armed timer still fired, entering selection mode against the\n // caller's wish and arming `consumeClick` for the next click (0.52 code review).\n useEffect(() => {\n if (!enabled) cancel();\n }, [enabled, cancel]);\n\n useEffect(() => cancel, [cancel]);\n\n return { handlers: { onPointerDown, onPointerMove, onContextMenu }, consumeClick };\n}\n"],"mappings":";AAAA,SAAS,aAAa,WAAW,cAAsD;AASvF,MAAM,gBAAgB;AAGtB,MAAM,UAAU;AAEhB,MAAM,kBAAkB,CAAC,MAAgC,GAAW,MAClE,KAAK,MAAM,IAAI,KAAK,GAAG,IAAI,KAAK,CAAC,IAAI;AAiChC,SAAS,aACd,aACA,EAAE,UAAU,MAAM,QAAQ,cAAc,IAAsB,CAAC,GAC9C;AACjB,QAAM,QAAQ,OAAsB,IAAI;AACxC,QAAM,QAAQ,OAAO,EAAE,GAAG,GAAG,GAAG,EAAE,CAAC;AACnC,QAAM,QAAQ,OAAO,KAAK;AAC1B,QAAM,WAAW,OAA4B,IAAI;AACjD,QAAM,QAAQ,OAAO,WAAW;AAChC,YAAU,MAAM;AACd,UAAM,UAAU;AAAA,EAClB,CAAC;AAED,QAAM,SAAS,YAAY,MAAM;AAC/B,QAAI,MAAM,YAAY,MAAM;AAC1B,aAAO,aAAa,MAAM,OAAO;AACjC,YAAM,UAAU;AAAA,IAClB;AACA,aAAS,UAAU;AACnB,aAAS,UAAU;AAAA,EACrB,GAAG,CAAC,CAAC;AAEL,QAAM,gBAAgB;AAAA,IACpB,CAAC,MAAyB;AAIxB,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AS,QAAO;AAC3B,UAAM,UAAU;AAChB,WAAO;AAAA,EACT,GAAG,CAAC,CAAC;AAIL,YAAU,MAAM;AACd,QAAI,CAAC,QAAS,QAAO;AAAA,EACvB,GAAG,CAAC,SAAS,MAAM,CAAC;AAEpB,YAAU,MAAM,QAAQ,CAAC,MAAM,CAAC;AAEhC,SAAO,EAAE,UAAU,EAAE,eAAe,eAAe,cAAc,GAAG,aAAa;AACnF;","names":[]}
|
|
@@ -1,13 +1,21 @@
|
|
|
1
1
|
"use client";
|
|
2
|
-
import { useEffect, useState } from "react";
|
|
2
|
+
import { useEffect, useEffectEvent, useState } from "react";
|
|
3
3
|
function useMediaQuery(query, fallback) {
|
|
4
4
|
const get = () => typeof window !== "undefined" && typeof window.matchMedia === "function" ? window.matchMedia(query).matches : fallback;
|
|
5
|
-
const [
|
|
5
|
+
const [state, setState] = useState(() => ({ query, matches: get() }));
|
|
6
|
+
let matches = state.matches;
|
|
7
|
+
if (state.query !== query) {
|
|
8
|
+
matches = get();
|
|
9
|
+
setState({ query, matches });
|
|
10
|
+
}
|
|
11
|
+
const answered = useEffectEvent(() => matches);
|
|
6
12
|
useEffect(() => {
|
|
7
13
|
if (typeof window === "undefined" || typeof window.matchMedia !== "function") return;
|
|
8
14
|
const mql = window.matchMedia(query);
|
|
9
|
-
const update = () =>
|
|
10
|
-
|
|
15
|
+
const update = () => setState(
|
|
16
|
+
(prev) => prev.query === query && prev.matches === mql.matches ? prev : { query, matches: mql.matches }
|
|
17
|
+
);
|
|
18
|
+
if (mql.matches !== answered()) update();
|
|
11
19
|
mql.addEventListener("change", update);
|
|
12
20
|
return () => mql.removeEventListener("change", update);
|
|
13
21
|
}, [query]);
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"sources":["../../src/hooks/use-media-query.ts"],"sourcesContent":["import { useEffect, useState } from \"react\";\n\n/**\n * Subscribe to a CSS media query, returning whether it currently matches and\n * re-rendering when it changes. `fallback` is the value used during SSR / when\n * `window.matchMedia` is unavailable.\n */\nexport function useMediaQuery(query: string, fallback: boolean): boolean {\n const get = () =>\n typeof window !== \"undefined\" && typeof window.matchMedia === \"function\"\n ? window.matchMedia(query).matches\n : fallback;\n const [
|
|
1
|
+
{"version":3,"sources":["../../src/hooks/use-media-query.ts"],"sourcesContent":["import { useEffect, useEffectEvent, useState } from \"react\";\n\n/**\n * Subscribe to a CSS media query, returning whether it currently matches and\n * re-rendering when it changes. `fallback` is the value used during SSR / when\n * `window.matchMedia` is unavailable.\n */\nexport function useMediaQuery(query: string, fallback: boolean): boolean {\n const get = () =>\n typeof window !== \"undefined\" && typeof window.matchMedia === \"function\"\n ? window.matchMedia(query).matches\n : fallback;\n // The answer is kept with the query it answers, and a new query is asked during the\n // render that brings it. Read at mount only, the first commit after a new query still\n // answered the OLD one, until the effect corrected it: `useBreakpoint` asks a new query\n // when the text size changes, and at Large in a 700 px window the tour card was drawn\n // un-docked for a frame before it docked (0.52 code review, use-breakpoint.ts).\n const [state, setState] = useState(() => ({ query, matches: get() }));\n let matches = state.matches;\n if (state.query !== query) {\n matches = get();\n setState({ query, matches });\n }\n const answered = useEffectEvent(() => matches);\n useEffect(() => {\n if (typeof window === \"undefined\" || typeof window.matchMedia !== \"function\") return;\n const mql = window.matchMedia(query);\n const update = () =>\n setState((prev) =>\n prev.query === query && prev.matches === mql.matches ? prev : { query, matches: mql.matches },\n );\n // A change between the render and this subscription. Only then: an update that\n // changes nothing still costs a render (and a commit) right after a new query.\n if (mql.matches !== answered()) update();\n mql.addEventListener(\"change\", update);\n return () => mql.removeEventListener(\"change\", update);\n }, [query]);\n return matches;\n}\n"],"mappings":";AAAA,SAAS,WAAW,gBAAgB,gBAAgB;AAO7C,SAAS,cAAc,OAAe,UAA4B;AACvE,QAAM,MAAM,MACV,OAAO,WAAW,eAAe,OAAO,OAAO,eAAe,aAC1D,OAAO,WAAW,KAAK,EAAE,UACzB;AAMN,QAAM,CAAC,OAAO,QAAQ,IAAI,SAAS,OAAO,EAAE,OAAO,SAAS,IAAI,EAAE,EAAE;AACpE,MAAI,UAAU,MAAM;AACpB,MAAI,MAAM,UAAU,OAAO;AACzB,cAAU,IAAI;AACd,aAAS,EAAE,OAAO,QAAQ,CAAC;AAAA,EAC7B;AACA,QAAM,WAAW,eAAe,MAAM,OAAO;AAC7C,YAAU,MAAM;AACd,QAAI,OAAO,WAAW,eAAe,OAAO,OAAO,eAAe,WAAY;AAC9E,UAAM,MAAM,OAAO,WAAW,KAAK;AACnC,UAAM,SAAS,MACb;AAAA,MAAS,CAAC,SACR,KAAK,UAAU,SAAS,KAAK,YAAY,IAAI,UAAU,OAAO,EAAE,OAAO,SAAS,IAAI,QAAQ;AAAA,IAC9F;AAGF,QAAI,IAAI,YAAY,SAAS,EAAG,QAAO;AACvC,QAAI,iBAAiB,UAAU,MAAM;AACrC,WAAO,MAAM,IAAI,oBAAoB,UAAU,MAAM;AAAA,EACvD,GAAG,CAAC,KAAK,CAAC;AACV,SAAO;AACT;","names":[]}
|
|
@@ -0,0 +1,22 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* A mounted guard and a callback-to-promise bridge, for a card that awaits an app's
|
|
3
|
+
* callback and must not set state after the page moved on.
|
|
4
|
+
*
|
|
5
|
+
* Written for the account settings parts (0.34) and then imported by seven notifications
|
|
6
|
+
* modules out of `account/account-parts.ts`: a generic helper living in a feature folder
|
|
7
|
+
* that the folder beside it reached into sideways (refactor audit 2026-10-30, MOD-6).
|
|
8
|
+
* `account-parts.ts` re-exports both, so nothing that imported them there moved, and
|
|
9
|
+
* `admin/admin-parts.ts` re-exports `settle` in place of its own copy (0.52 code review).
|
|
10
|
+
*
|
|
11
|
+
* @internal Not part of the barrel.
|
|
12
|
+
*/
|
|
13
|
+
/** Whether the component is still mounted — a late answer after the app navigated away
|
|
14
|
+
* (the deletion signs out) must not set state. */
|
|
15
|
+
export declare function useMounted(): {
|
|
16
|
+
readonly current: boolean;
|
|
17
|
+
};
|
|
18
|
+
/** Call `call` and hand back a promise, a throw included — a callback may return
|
|
19
|
+
* nothing (done at once), a promise, or throw before it returns one. Typed by what it
|
|
20
|
+
* answers, so the admin parts' copy, which kept the type, could go (0.52 code review,
|
|
21
|
+
* admin/admin-parts.ts). */
|
|
22
|
+
export declare function settle<R>(call: () => R): Promise<Awaited<R>>;
|
|
@@ -0,0 +1,24 @@
|
|
|
1
|
+
"use client";
|
|
2
|
+
import { useEffect, useRef } from "react";
|
|
3
|
+
function useMounted() {
|
|
4
|
+
const mounted = useRef(true);
|
|
5
|
+
useEffect(() => {
|
|
6
|
+
mounted.current = true;
|
|
7
|
+
return () => {
|
|
8
|
+
mounted.current = false;
|
|
9
|
+
};
|
|
10
|
+
}, []);
|
|
11
|
+
return mounted;
|
|
12
|
+
}
|
|
13
|
+
function settle(call) {
|
|
14
|
+
try {
|
|
15
|
+
return Promise.resolve(call());
|
|
16
|
+
} catch (error) {
|
|
17
|
+
return Promise.reject(error);
|
|
18
|
+
}
|
|
19
|
+
}
|
|
20
|
+
export {
|
|
21
|
+
settle,
|
|
22
|
+
useMounted
|
|
23
|
+
};
|
|
24
|
+
//# sourceMappingURL=use-mounted.js.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"sources":["../../src/hooks/use-mounted.ts"],"sourcesContent":["import { useEffect, useRef } from \"react\";\n\n/**\n * A mounted guard and a callback-to-promise bridge, for a card that awaits an app's\n * callback and must not set state after the page moved on.\n *\n * Written for the account settings parts (0.34) and then imported by seven notifications\n * modules out of `account/account-parts.ts`: a generic helper living in a feature folder\n * that the folder beside it reached into sideways (refactor audit 2026-10-30, MOD-6).\n * `account-parts.ts` re-exports both, so nothing that imported them there moved, and\n * `admin/admin-parts.ts` re-exports `settle` in place of its own copy (0.52 code review).\n *\n * @internal Not part of the barrel.\n */\n\n/** Whether the component is still mounted — a late answer after the app navigated away\n * (the deletion signs out) must not set state. */\nexport function useMounted(): { readonly current: boolean } {\n const mounted = useRef(true);\n useEffect(() => {\n mounted.current = true;\n return () => {\n mounted.current = false;\n };\n }, []);\n return mounted;\n}\n\n/** Call `call` and hand back a promise, a throw included — a callback may return\n * nothing (done at once), a promise, or throw before it returns one. Typed by what it\n * answers, so the admin parts' copy, which kept the type, could go (0.52 code review,\n * admin/admin-parts.ts). */\nexport function settle<R>(call: () => R): Promise<Awaited<R>> {\n try {\n return Promise.resolve(call());\n } catch (error) {\n return Promise.reject(error);\n }\n}\n"],"mappings":";AAAA,SAAS,WAAW,cAAc;AAiB3B,SAAS,aAA4C;AAC1D,QAAM,UAAU,OAAO,IAAI;AAC3B,YAAU,MAAM;AACd,YAAQ,UAAU;AAClB,WAAO,MAAM;AACX,cAAQ,UAAU;AAAA,IACpB;AAAA,EACF,GAAG,CAAC,CAAC;AACL,SAAO;AACT;AAMO,SAAS,OAAU,MAAoC;AAC5D,MAAI;AACF,WAAO,QAAQ,QAAQ,KAAK,CAAC;AAAA,EAC/B,SAAS,OAAO;AACd,WAAO,QAAQ,OAAO,KAAK;AAAA,EAC7B;AACF;","names":[]}
|
|
@@ -4,5 +4,11 @@
|
|
|
4
4
|
* @param open whether the overlay is currently showing. Components that mount
|
|
5
5
|
* only while open (the common case) pass `true`.
|
|
6
6
|
* @param onClose the overlay's own close handler — the same one Escape calls.
|
|
7
|
+
* @param options.held the overlay refuses to close right now (a `Modal` whose request
|
|
8
|
+
* is in flight, DUP-3): Back does not call `onClose`, and the entry the
|
|
9
|
+
* press took is put back, so the overlay still has one for the next
|
|
10
|
+
* Back. Read when Back is pressed. Default false.
|
|
7
11
|
*/
|
|
8
|
-
export declare function useOverlayHistory(open: boolean, onClose: () => void
|
|
12
|
+
export declare function useOverlayHistory(open: boolean, onClose: () => void, { held }?: {
|
|
13
|
+
held?: boolean;
|
|
14
|
+
}): void;
|
|
@@ -8,6 +8,7 @@ let lastSeen = null;
|
|
|
8
8
|
const consumed = /* @__PURE__ */ new Set();
|
|
9
9
|
let pendingProgrammatic = 0;
|
|
10
10
|
let listening = false;
|
|
11
|
+
let noting = false;
|
|
11
12
|
let nextId = 0;
|
|
12
13
|
let unwind = null;
|
|
13
14
|
function runUnwind() {
|
|
@@ -170,32 +171,60 @@ function closeOnPop() {
|
|
|
170
171
|
const top = stack[stack.length - 1];
|
|
171
172
|
if (!top) return;
|
|
172
173
|
if (currentSentinel() === top.id) return;
|
|
174
|
+
if (top.held()) {
|
|
175
|
+
putBack(top.id);
|
|
176
|
+
return;
|
|
177
|
+
}
|
|
173
178
|
stack.pop();
|
|
179
|
+
syncGestureListeners();
|
|
174
180
|
consumed.add(top.id);
|
|
175
181
|
const record = pushed.find((p) => p.id === top.id);
|
|
176
182
|
forgetPushed(top.id);
|
|
177
183
|
if (record && !record.dead) carryOnto(record.seen, record);
|
|
178
184
|
top.close();
|
|
179
185
|
}
|
|
186
|
+
function putBack(id) {
|
|
187
|
+
const record = pushed.find((p) => p.id === id);
|
|
188
|
+
if (record && !record.dead) carryOnto(record.seen, record);
|
|
189
|
+
const prev = window.history.state;
|
|
190
|
+
window.history.pushState({ ...prev && typeof prev === "object" ? prev : {}, [SENTINEL_KEY]: id }, "");
|
|
191
|
+
standing = id;
|
|
192
|
+
if (record) record.href = record.seen = currentHref();
|
|
193
|
+
}
|
|
180
194
|
function ensureListening() {
|
|
181
195
|
if (listening || typeof window === "undefined") return;
|
|
182
196
|
window.addEventListener("popstate", handlePop);
|
|
183
|
-
window.addEventListener("pointerdown", noteAddress, true);
|
|
184
|
-
window.addEventListener("keydown", noteAddress, true);
|
|
185
|
-
for (const type of ["click", "keyup", "change", "input"]) window.addEventListener(type, noteSeenNowAndLater);
|
|
186
197
|
listening = true;
|
|
187
198
|
}
|
|
188
|
-
|
|
199
|
+
const SEEN_EVENTS = ["click", "keyup", "change", "input"];
|
|
200
|
+
function syncGestureListeners() {
|
|
201
|
+
const want = stack.length > 0;
|
|
202
|
+
if (want === noting || typeof window === "undefined") return;
|
|
203
|
+
noting = want;
|
|
204
|
+
if (want) {
|
|
205
|
+
window.addEventListener("pointerdown", noteAddress, true);
|
|
206
|
+
window.addEventListener("keydown", noteAddress, true);
|
|
207
|
+
for (const type of SEEN_EVENTS) window.addEventListener(type, noteSeenNowAndLater);
|
|
208
|
+
} else {
|
|
209
|
+
window.removeEventListener("pointerdown", noteAddress, true);
|
|
210
|
+
window.removeEventListener("keydown", noteAddress, true);
|
|
211
|
+
for (const type of SEEN_EVENTS) window.removeEventListener(type, noteSeenNowAndLater);
|
|
212
|
+
}
|
|
213
|
+
}
|
|
214
|
+
function useOverlayHistory(open, onClose, { held = false } = {}) {
|
|
189
215
|
const closeRef = useRef(onClose);
|
|
216
|
+
const heldRef = useRef(held);
|
|
190
217
|
useEffect(() => {
|
|
191
218
|
closeRef.current = onClose;
|
|
219
|
+
heldRef.current = held;
|
|
192
220
|
});
|
|
193
221
|
useEffect(() => {
|
|
194
222
|
if (!open || typeof window === "undefined") return;
|
|
195
223
|
ensureListening();
|
|
196
224
|
const id = `overlay-${nextId += 1}`;
|
|
197
|
-
const entry = { id, close: () => closeRef.current() };
|
|
225
|
+
const entry = { id, close: () => closeRef.current(), held: () => heldRef.current };
|
|
198
226
|
stack.push(entry);
|
|
227
|
+
syncGestureListeners();
|
|
199
228
|
const prev = window.history.state;
|
|
200
229
|
const marked = { ...prev && typeof prev === "object" ? prev : {}, [SENTINEL_KEY]: id };
|
|
201
230
|
const adopting = unwind && unwind.id === currentSentinel() && unwind.href === currentHref();
|
|
@@ -228,6 +257,7 @@ function useOverlayHistory(open, onClose) {
|
|
|
228
257
|
return () => {
|
|
229
258
|
const at = stack.indexOf(entry);
|
|
230
259
|
if (at >= 0) stack.splice(at, 1);
|
|
260
|
+
syncGestureListeners();
|
|
231
261
|
if (consumed.delete(id)) return;
|
|
232
262
|
const mine = pushed.findIndex((p) => p.id === id);
|
|
233
263
|
if (mine >= 0 && currentHref() !== pushed[mine].href) {
|