@portnet/ui 6.0.2 → 6.0.3
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/CHANGELOG.md +652 -0
- package/dist/esm/index.js +72 -3
- package/dist/esm/index.js.map +1 -1
- package/dist/esm/v2/__tests__/AppMain.test.js +130 -0
- package/dist/esm/v2/__tests__/AppMain.test.js.map +1 -0
- package/dist/esm/v2/__tests__/ChartFigure.test.js +180 -0
- package/dist/esm/v2/__tests__/ChartFigure.test.js.map +1 -0
- package/dist/esm/v2/__tests__/DataGridRowActionsPropagation.test.js +150 -0
- package/dist/esm/v2/__tests__/DataGridRowActionsPropagation.test.js.map +1 -0
- package/dist/esm/v2/__tests__/DrawerTactileTargets.test.js +93 -0
- package/dist/esm/v2/__tests__/DrawerTactileTargets.test.js.map +1 -0
- package/dist/esm/v2/__tests__/FieldError.test.js +71 -38
- package/dist/esm/v2/__tests__/FieldError.test.js.map +1 -1
- package/dist/esm/v2/__tests__/FieldNaming.test.js +160 -0
- package/dist/esm/v2/__tests__/FieldNaming.test.js.map +1 -0
- package/dist/esm/v2/__tests__/FieldWidth.test.js +11 -11
- package/dist/esm/v2/__tests__/FieldWidth.test.js.map +1 -1
- package/dist/esm/v2/__tests__/FileCard.test.js +18 -17
- package/dist/esm/v2/__tests__/FileCard.test.js.map +1 -1
- package/dist/esm/v2/__tests__/FormikCheckbox.test.js +87 -179
- package/dist/esm/v2/__tests__/FormikCheckbox.test.js.map +1 -1
- package/dist/esm/v2/__tests__/FormikDateTimePicker.test.js +32 -44
- package/dist/esm/v2/__tests__/FormikDateTimePicker.test.js.map +1 -1
- package/dist/esm/v2/__tests__/FormikDisplayWidth.test.js +101 -0
- package/dist/esm/v2/__tests__/FormikDisplayWidth.test.js.map +1 -0
- package/dist/esm/v2/__tests__/FormikRadioGroup.test.js +118 -199
- package/dist/esm/v2/__tests__/FormikRadioGroup.test.js.map +1 -1
- package/dist/esm/v2/__tests__/MobileRowCard.test.js +44 -42
- package/dist/esm/v2/__tests__/MobileRowCard.test.js.map +1 -1
- package/dist/esm/v2/__tests__/PreviewDrawer.test.js +165 -0
- package/dist/esm/v2/__tests__/PreviewDrawer.test.js.map +1 -0
- package/dist/esm/v2/__tests__/ReferentielFieldContainer.test.js +156 -0
- package/dist/esm/v2/__tests__/ReferentielFieldContainer.test.js.map +1 -0
- package/dist/esm/v2/__tests__/SectionErrorBoundary.test.js +37 -52
- package/dist/esm/v2/__tests__/SectionErrorBoundary.test.js.map +1 -1
- package/dist/esm/v2/__tests__/apiError.test.js +50 -69
- package/dist/esm/v2/__tests__/apiError.test.js.map +1 -1
- package/dist/esm/v2/__tests__/banned-patterns.test.js +41 -122
- package/dist/esm/v2/__tests__/banned-patterns.test.js.map +1 -1
- package/dist/esm/v2/__tests__/chart-palette.test.js +204 -0
- package/dist/esm/v2/__tests__/chart-palette.test.js.map +1 -0
- package/dist/esm/v2/__tests__/contrast-palette.test.js +42 -74
- package/dist/esm/v2/__tests__/contrast-palette.test.js.map +1 -1
- package/dist/esm/v2/__tests__/cssVariables.test.js +44 -51
- package/dist/esm/v2/__tests__/cssVariables.test.js.map +1 -1
- package/dist/esm/v2/__tests__/fileValidation.test.js +134 -0
- package/dist/esm/v2/__tests__/fileValidation.test.js.map +1 -0
- package/dist/esm/v2/__tests__/filterCriteria.test.js +321 -0
- package/dist/esm/v2/__tests__/filterCriteria.test.js.map +1 -0
- package/dist/esm/v2/__tests__/fmtDate.test.js +68 -0
- package/dist/esm/v2/__tests__/fmtDate.test.js.map +1 -0
- package/dist/esm/v2/__tests__/gap-leakage-refonte.test.js +218 -0
- package/dist/esm/v2/__tests__/gap-leakage-refonte.test.js.map +1 -0
- package/dist/esm/v2/__tests__/labels-merge.test.js +17 -21
- package/dist/esm/v2/__tests__/labels-merge.test.js.map +1 -1
- package/dist/esm/v2/__tests__/locale-fallback.test.js +35 -40
- package/dist/esm/v2/__tests__/locale-fallback.test.js.map +1 -1
- package/dist/esm/v2/__tests__/reviveSavedCriteria.test.js +143 -0
- package/dist/esm/v2/__tests__/reviveSavedCriteria.test.js.map +1 -0
- package/dist/esm/v2/__tests__/rowActions.test.js +182 -0
- package/dist/esm/v2/__tests__/rowActions.test.js.map +1 -0
- package/dist/esm/v2/__tests__/useFocusOnRouteChange.test.js +155 -0
- package/dist/esm/v2/__tests__/useFocusOnRouteChange.test.js.map +1 -0
- package/dist/esm/v2/__tests__/useFocusTrap.test.js +266 -402
- package/dist/esm/v2/__tests__/useFocusTrap.test.js.map +1 -1
- package/dist/esm/v2/__tests__/usePrefersReducedMotion.test.js +120 -0
- package/dist/esm/v2/__tests__/usePrefersReducedMotion.test.js.map +1 -0
- package/dist/esm/v2/components/Accordion.js +48 -70
- package/dist/esm/v2/components/Accordion.js.map +1 -1
- package/dist/esm/v2/components/ActionStrip.js +31 -43
- package/dist/esm/v2/components/ActionStrip.js.map +1 -1
- package/dist/esm/v2/components/Banner.js +25 -22
- package/dist/esm/v2/components/Banner.js.map +1 -1
- package/dist/esm/v2/components/Busy.js +14 -19
- package/dist/esm/v2/components/Busy.js.map +1 -1
- package/dist/esm/v2/components/Button.js +34 -45
- package/dist/esm/v2/components/Button.js.map +1 -1
- package/dist/esm/v2/components/CategoryTag.js +44 -27
- package/dist/esm/v2/components/CategoryTag.js.map +1 -1
- package/dist/esm/v2/components/Checkbox.js +32 -38
- package/dist/esm/v2/components/Checkbox.js.map +1 -1
- package/dist/esm/v2/components/Chip.js +23 -36
- package/dist/esm/v2/components/Chip.js.map +1 -1
- package/dist/esm/v2/components/Combobox.js +112 -136
- package/dist/esm/v2/components/Combobox.js.map +1 -1
- package/dist/esm/v2/components/CommandPalette.js +113 -198
- package/dist/esm/v2/components/CommandPalette.js.map +1 -1
- package/dist/esm/v2/components/ConfirmDialog.js +36 -45
- package/dist/esm/v2/components/ConfirmDialog.js.map +1 -1
- package/dist/esm/v2/components/DatePicker.js +78 -81
- package/dist/esm/v2/components/DatePicker.js.map +1 -1
- package/dist/esm/v2/components/DateRangePicker.js +63 -74
- package/dist/esm/v2/components/DateRangePicker.js.map +1 -1
- package/dist/esm/v2/components/DateTimePicker.js +81 -86
- package/dist/esm/v2/components/DateTimePicker.js.map +1 -1
- package/dist/esm/v2/components/Drawer.js +71 -65
- package/dist/esm/v2/components/Drawer.js.map +1 -1
- package/dist/esm/v2/components/Dropzone.js +130 -177
- package/dist/esm/v2/components/Dropzone.js.map +1 -1
- package/dist/esm/v2/components/EmptyState.js +9 -9
- package/dist/esm/v2/components/EmptyState.js.map +1 -1
- package/dist/esm/v2/components/FavoriteToggle.js +24 -33
- package/dist/esm/v2/components/FavoriteToggle.js.map +1 -1
- package/dist/esm/v2/components/Field.js +155 -59
- package/dist/esm/v2/components/Field.js.map +1 -1
- package/dist/esm/v2/components/FieldError.js +9 -13
- package/dist/esm/v2/components/FieldError.js.map +1 -1
- package/dist/esm/v2/components/FieldHelp.js +28 -49
- package/dist/esm/v2/components/FieldHelp.js.map +1 -1
- package/dist/esm/v2/components/FileCard.js +14 -19
- package/dist/esm/v2/components/FileCard.js.map +1 -1
- package/dist/esm/v2/components/FilterTab.js +22 -31
- package/dist/esm/v2/components/FilterTab.js.map +1 -1
- package/dist/esm/v2/components/ForbiddenPage.js +28 -8
- package/dist/esm/v2/components/ForbiddenPage.js.map +1 -1
- package/dist/esm/v2/components/FormGrid.js +48 -54
- package/dist/esm/v2/components/FormGrid.js.map +1 -1
- package/dist/esm/v2/components/FormikDisplay.js +98 -24
- package/dist/esm/v2/components/FormikDisplay.js.map +1 -1
- package/dist/esm/v2/components/Input.js +75 -34
- package/dist/esm/v2/components/Input.js.map +1 -1
- package/dist/esm/v2/components/KPICard.js +42 -51
- package/dist/esm/v2/components/KPICard.js.map +1 -1
- package/dist/esm/v2/components/KPIStrip.js +9 -15
- package/dist/esm/v2/components/KPIStrip.js.map +1 -1
- package/dist/esm/v2/components/KV.js +16 -23
- package/dist/esm/v2/components/KV.js.map +1 -1
- package/dist/esm/v2/components/KVGrid.js +15 -23
- package/dist/esm/v2/components/KVGrid.js.map +1 -1
- package/dist/esm/v2/components/Layout.js +81 -117
- package/dist/esm/v2/components/Layout.js.map +1 -1
- package/dist/esm/v2/components/MobileRowCard.js +64 -75
- package/dist/esm/v2/components/MobileRowCard.js.map +1 -1
- package/dist/esm/v2/components/Modal.js +44 -53
- package/dist/esm/v2/components/Modal.js.map +1 -1
- package/dist/esm/v2/components/NetworkErrorPage.js +28 -11
- package/dist/esm/v2/components/NetworkErrorPage.js.map +1 -1
- package/dist/esm/v2/components/NotFoundPage.js +28 -9
- package/dist/esm/v2/components/NotFoundPage.js.map +1 -1
- package/dist/esm/v2/components/NumberInput.js +77 -107
- package/dist/esm/v2/components/NumberInput.js.map +1 -1
- package/dist/esm/v2/components/OverflowMenu.js +24 -42
- package/dist/esm/v2/components/OverflowMenu.js.map +1 -1
- package/dist/esm/v2/components/PdfViewer.js +24 -33
- package/dist/esm/v2/components/PdfViewer.js.map +1 -1
- package/dist/esm/v2/components/ProgressBar.js +28 -36
- package/dist/esm/v2/components/ProgressBar.js.map +1 -1
- package/dist/esm/v2/components/Radio.js +49 -57
- package/dist/esm/v2/components/Radio.js.map +1 -1
- package/dist/esm/v2/components/SectionErrorBoundary.js +84 -130
- package/dist/esm/v2/components/SectionErrorBoundary.js.map +1 -1
- package/dist/esm/v2/components/SectionHeader.js +24 -31
- package/dist/esm/v2/components/SectionHeader.js.map +1 -1
- package/dist/esm/v2/components/Segmented.js +59 -84
- package/dist/esm/v2/components/Segmented.js.map +1 -1
- package/dist/esm/v2/components/Select.js +100 -138
- package/dist/esm/v2/components/Select.js.map +1 -1
- package/dist/esm/v2/components/ServerErrorPage.js +27 -10
- package/dist/esm/v2/components/ServerErrorPage.js.map +1 -1
- package/dist/esm/v2/components/Skeleton.js +81 -96
- package/dist/esm/v2/components/Skeleton.js.map +1 -1
- package/dist/esm/v2/components/SkipLink.js +6 -7
- package/dist/esm/v2/components/SkipLink.js.map +1 -1
- package/dist/esm/v2/components/Spinner.js +13 -22
- package/dist/esm/v2/components/Spinner.js.map +1 -1
- package/dist/esm/v2/components/Status.js +14 -25
- package/dist/esm/v2/components/Status.js.map +1 -1
- package/dist/esm/v2/components/Stepper.js +68 -71
- package/dist/esm/v2/components/Stepper.js.map +1 -1
- package/dist/esm/v2/components/Surface.js +25 -44
- package/dist/esm/v2/components/Surface.js.map +1 -1
- package/dist/esm/v2/components/Switch.js +21 -29
- package/dist/esm/v2/components/Switch.js.map +1 -1
- package/dist/esm/v2/components/TabPanel.js +84 -0
- package/dist/esm/v2/components/TabPanel.js.map +1 -0
- package/dist/esm/v2/components/Tabs.js +43 -19
- package/dist/esm/v2/components/Tabs.js.map +1 -1
- package/dist/esm/v2/components/TelInput.js +75 -108
- package/dist/esm/v2/components/TelInput.js.map +1 -1
- package/dist/esm/v2/components/Textarea.js +21 -30
- package/dist/esm/v2/components/Textarea.js.map +1 -1
- package/dist/esm/v2/components/TimePicker.js +59 -69
- package/dist/esm/v2/components/TimePicker.js.map +1 -1
- package/dist/esm/v2/components/Toast.js +109 -163
- package/dist/esm/v2/components/Toast.js.map +1 -1
- package/dist/esm/v2/components/Tooltip.js +18 -31
- package/dist/esm/v2/components/Tooltip.js.map +1 -1
- package/dist/esm/v2/components/_ErrorPageBody.js +6 -5
- package/dist/esm/v2/components/_ErrorPageBody.js.map +1 -1
- package/dist/esm/v2/components/_pickerShared.js +2 -2
- package/dist/esm/v2/components/_pickerShared.js.map +1 -1
- package/dist/esm/v2/components/index.js +37 -0
- package/dist/esm/v2/components/index.js.map +1 -1
- package/dist/esm/v2/hooks/index.js +62 -0
- package/dist/esm/v2/hooks/index.js.map +1 -1
- package/dist/esm/v2/hooks/useAppliedFilters.js +112 -0
- package/dist/esm/v2/hooks/useAppliedFilters.js.map +1 -0
- package/dist/esm/v2/hooks/useDebouncedCallback.js +82 -0
- package/dist/esm/v2/hooks/useDebouncedCallback.js.map +1 -0
- package/dist/esm/v2/hooks/useDelayedFlag.js +5 -19
- package/dist/esm/v2/hooks/useDelayedFlag.js.map +1 -1
- package/dist/esm/v2/hooks/useDensity.js +13 -17
- package/dist/esm/v2/hooks/useDensity.js.map +1 -1
- package/dist/esm/v2/hooks/useFocusFirstError.js +25 -33
- package/dist/esm/v2/hooks/useFocusFirstError.js.map +1 -1
- package/dist/esm/v2/hooks/useFocusOnRouteChange.js +81 -0
- package/dist/esm/v2/hooks/useFocusOnRouteChange.js.map +1 -0
- package/dist/esm/v2/hooks/useFocusTrap.js +19 -23
- package/dist/esm/v2/hooks/useFocusTrap.js.map +1 -1
- package/dist/esm/v2/hooks/useFormAutoSave.js +38 -53
- package/dist/esm/v2/hooks/useFormAutoSave.js.map +1 -1
- package/dist/esm/v2/hooks/useFormCompletionProgress.js +32 -51
- package/dist/esm/v2/hooks/useFormCompletionProgress.js.map +1 -1
- package/dist/esm/v2/hooks/useKeyboardShortcuts.js +125 -0
- package/dist/esm/v2/hooks/useKeyboardShortcuts.js.map +1 -0
- package/dist/esm/v2/hooks/usePrefersReducedMotion.js +99 -0
- package/dist/esm/v2/hooks/usePrefersReducedMotion.js.map +1 -0
- package/dist/esm/v2/hooks/useResolvedDensity.js +2 -10
- package/dist/esm/v2/hooks/useResolvedDensity.js.map +1 -1
- package/dist/esm/v2/hooks/useSortedRows.js +3 -5
- package/dist/esm/v2/hooks/useSortedRows.js.map +1 -1
- package/dist/esm/v2/hooks/useTabLoading.js +6 -21
- package/dist/esm/v2/hooks/useTabLoading.js.map +1 -1
- package/dist/esm/v2/index.js +2 -3
- package/dist/esm/v2/index.js.map +1 -1
- package/dist/esm/v2/modalContext.js +2 -2
- package/dist/esm/v2/modalContext.js.map +1 -1
- package/dist/esm/v2/models/favorite.js.map +1 -1
- package/dist/esm/v2/models/personalization.js.map +1 -1
- package/dist/esm/v2/models/referentiel.js.map +1 -1
- package/dist/esm/v2/models/savedFilter.js.map +1 -1
- package/dist/esm/v2/patterns/ActionBar.js +115 -159
- package/dist/esm/v2/patterns/ActionBar.js.map +1 -1
- package/dist/esm/v2/patterns/AppMain.js +108 -0
- package/dist/esm/v2/patterns/AppMain.js.map +1 -0
- package/dist/esm/v2/patterns/BulkActionBar.js +31 -34
- package/dist/esm/v2/patterns/BulkActionBar.js.map +1 -1
- package/dist/esm/v2/patterns/ChartFigure.js +151 -0
- package/dist/esm/v2/patterns/ChartFigure.js.map +1 -0
- package/dist/esm/v2/patterns/CollapsibleDataGrid.js +111 -152
- package/dist/esm/v2/patterns/CollapsibleDataGrid.js.map +1 -1
- package/dist/esm/v2/patterns/ColumnsToggle.js +43 -77
- package/dist/esm/v2/patterns/ColumnsToggle.js.map +1 -1
- package/dist/esm/v2/patterns/DataGrid.js +221 -255
- package/dist/esm/v2/patterns/DataGrid.js.map +1 -1
- package/dist/esm/v2/patterns/DataGridSettingsMenu.js +76 -94
- package/dist/esm/v2/patterns/DataGridSettingsMenu.js.map +1 -1
- package/dist/esm/v2/patterns/DataGridToolbar.js +85 -89
- package/dist/esm/v2/patterns/DataGridToolbar.js.map +1 -1
- package/dist/esm/v2/patterns/DataGridVirtualized.js +141 -182
- package/dist/esm/v2/patterns/DataGridVirtualized.js.map +1 -1
- package/dist/esm/v2/patterns/DeleteResourceConfirmDialog.js +26 -30
- package/dist/esm/v2/patterns/DeleteResourceConfirmDialog.js.map +1 -1
- package/dist/esm/v2/patterns/DetailSplit.js +108 -0
- package/dist/esm/v2/patterns/DetailSplit.js.map +1 -0
- package/dist/esm/v2/patterns/FavoriteColumn.js +15 -17
- package/dist/esm/v2/patterns/FavoriteColumn.js.map +1 -1
- package/dist/esm/v2/patterns/FavoritesFilter.js +30 -39
- package/dist/esm/v2/patterns/FavoritesFilter.js.map +1 -1
- package/dist/esm/v2/patterns/FilterTabBar.js +112 -0
- package/dist/esm/v2/patterns/FilterTabBar.js.map +1 -0
- package/dist/esm/v2/patterns/FormErrorSummary.js +12 -13
- package/dist/esm/v2/patterns/FormErrorSummary.js.map +1 -1
- package/dist/esm/v2/patterns/FormPageShell.js +43 -41
- package/dist/esm/v2/patterns/FormPageShell.js.map +1 -1
- package/dist/esm/v2/patterns/FormSection.js +30 -38
- package/dist/esm/v2/patterns/FormSection.js.map +1 -1
- package/dist/esm/v2/patterns/FormikCheckbox.js +29 -39
- package/dist/esm/v2/patterns/FormikCheckbox.js.map +1 -1
- package/dist/esm/v2/patterns/FormikCheckboxGroup.js +56 -60
- package/dist/esm/v2/patterns/FormikCheckboxGroup.js.map +1 -1
- package/dist/esm/v2/patterns/FormikCombobox.js +51 -69
- package/dist/esm/v2/patterns/FormikCombobox.js.map +1 -1
- package/dist/esm/v2/patterns/FormikDatePicker.js +44 -58
- package/dist/esm/v2/patterns/FormikDatePicker.js.map +1 -1
- package/dist/esm/v2/patterns/FormikDateTimePicker.js +44 -58
- package/dist/esm/v2/patterns/FormikDateTimePicker.js.map +1 -1
- package/dist/esm/v2/patterns/FormikErrorFocus.js +22 -23
- package/dist/esm/v2/patterns/FormikErrorFocus.js.map +1 -1
- package/dist/esm/v2/patterns/FormikErrorSummary.js +89 -0
- package/dist/esm/v2/patterns/FormikErrorSummary.js.map +1 -0
- package/dist/esm/v2/patterns/FormikFile.js +94 -78
- package/dist/esm/v2/patterns/FormikFile.js.map +1 -1
- package/dist/esm/v2/patterns/FormikInput.js +40 -53
- package/dist/esm/v2/patterns/FormikInput.js.map +1 -1
- package/dist/esm/v2/patterns/FormikRadioGroup.js +39 -51
- package/dist/esm/v2/patterns/FormikRadioGroup.js.map +1 -1
- package/dist/esm/v2/patterns/FormikReferentielField.js +49 -59
- package/dist/esm/v2/patterns/FormikReferentielField.js.map +1 -1
- package/dist/esm/v2/patterns/FormikSelect.js +64 -87
- package/dist/esm/v2/patterns/FormikSelect.js.map +1 -1
- package/dist/esm/v2/patterns/FormikTextarea.js +30 -46
- package/dist/esm/v2/patterns/FormikTextarea.js.map +1 -1
- package/dist/esm/v2/patterns/KeyboardShortcutsHelp.js +53 -71
- package/dist/esm/v2/patterns/KeyboardShortcutsHelp.js.map +1 -1
- package/dist/esm/v2/patterns/NetworkErrorBanner.js +6 -7
- package/dist/esm/v2/patterns/NetworkErrorBanner.js.map +1 -1
- package/dist/esm/v2/patterns/PageContent.js +10 -14
- package/dist/esm/v2/patterns/PageContent.js.map +1 -1
- package/dist/esm/v2/patterns/PreviewDrawer.js +153 -0
- package/dist/esm/v2/patterns/PreviewDrawer.js.map +1 -0
- package/dist/esm/v2/patterns/ReferentielField.js +327 -312
- package/dist/esm/v2/patterns/ReferentielField.js.map +1 -1
- package/dist/esm/v2/patterns/RowFavoriteToggle.js +27 -22
- package/dist/esm/v2/patterns/RowFavoriteToggle.js.map +1 -1
- package/dist/esm/v2/patterns/SaveFilterDialog.js +38 -66
- package/dist/esm/v2/patterns/SaveFilterDialog.js.map +1 -1
- package/dist/esm/v2/patterns/SavedFiltersMenu.js +62 -81
- package/dist/esm/v2/patterns/SavedFiltersMenu.js.map +1 -1
- package/dist/esm/v2/patterns/SkeletonPageShell.js +106 -129
- package/dist/esm/v2/patterns/SkeletonPageShell.js.map +1 -1
- package/dist/esm/v2/patterns/SortableHeader.js +22 -45
- package/dist/esm/v2/patterns/SortableHeader.js.map +1 -1
- package/dist/esm/v2/patterns/Tour.js +94 -120
- package/dist/esm/v2/patterns/Tour.js.map +1 -1
- package/dist/esm/v2/patterns/_dataGridShared.js +107 -128
- package/dist/esm/v2/patterns/_dataGridShared.js.map +1 -1
- package/dist/esm/v2/patterns/_pickerSerialisation.js +6 -8
- package/dist/esm/v2/patterns/_pickerSerialisation.js.map +1 -1
- package/dist/esm/v2/patterns/_sort.js +17 -33
- package/dist/esm/v2/patterns/_sort.js.map +1 -1
- package/dist/esm/v2/patterns/_useColumnReorder.js +122 -160
- package/dist/esm/v2/patterns/_useColumnReorder.js.map +1 -1
- package/dist/esm/v2/patterns/_useColumnResize.js +78 -96
- package/dist/esm/v2/patterns/_useColumnResize.js.map +1 -1
- package/dist/esm/v2/patterns/filterCriteria.js +102 -0
- package/dist/esm/v2/patterns/filterCriteria.js.map +1 -0
- package/dist/esm/v2/patterns/index.js +152 -0
- package/dist/esm/v2/patterns/index.js.map +1 -1
- package/dist/esm/v2/patterns/rowActions.js +223 -0
- package/dist/esm/v2/patterns/rowActions.js.map +1 -0
- package/dist/esm/v2/personalization/PersonalizationProvider.js +50 -47
- package/dist/esm/v2/personalization/PersonalizationProvider.js.map +1 -1
- package/dist/esm/v2/personalization/adapters/_storageKey.js +5 -5
- package/dist/esm/v2/personalization/adapters/_storageKey.js.map +1 -1
- package/dist/esm/v2/personalization/adapters/createLocalStorageAdapter.js +22 -23
- package/dist/esm/v2/personalization/adapters/createLocalStorageAdapter.js.map +1 -1
- package/dist/esm/v2/personalization/adapters/createMemoryAdapter.js +13 -13
- package/dist/esm/v2/personalization/adapters/createMemoryAdapter.js.map +1 -1
- package/dist/esm/v2/personalization/capabilities/favorites.js +36 -60
- package/dist/esm/v2/personalization/capabilities/favorites.js.map +1 -1
- package/dist/esm/v2/personalization/capabilities/favoritesView.js +22 -34
- package/dist/esm/v2/personalization/capabilities/favoritesView.js.map +1 -1
- package/dist/esm/v2/personalization/capabilities/gridPreferences.js +28 -34
- package/dist/esm/v2/personalization/capabilities/gridPreferences.js.map +1 -1
- package/dist/esm/v2/personalization/capabilities/reviveSavedCriteria.js +119 -0
- package/dist/esm/v2/personalization/capabilities/reviveSavedCriteria.js.map +1 -0
- package/dist/esm/v2/personalization/capabilities/savedFilters.js +90 -98
- package/dist/esm/v2/personalization/capabilities/savedFilters.js.map +1 -1
- package/dist/esm/v2/personalization/createPersonalizationStore.js +78 -181
- package/dist/esm/v2/personalization/createPersonalizationStore.js.map +1 -1
- package/dist/esm/v2/personalization/index.js +17 -0
- package/dist/esm/v2/personalization/index.js.map +1 -1
- package/dist/esm/v2/personalization/personalizationContext.js +9 -9
- package/dist/esm/v2/personalization/personalizationContext.js.map +1 -1
- package/dist/esm/v2/personalization/schema.js +8 -9
- package/dist/esm/v2/personalization/schema.js.map +1 -1
- package/dist/esm/v2/referentiel/ReferentielProvider.js +27 -42
- package/dist/esm/v2/referentiel/ReferentielProvider.js.map +1 -1
- package/dist/esm/v2/referentiel/types.js +2 -0
- package/dist/esm/v2/referentiel/types.js.map +1 -0
- package/dist/esm/v2/referentiel/useReferentielClient.js +10 -11
- package/dist/esm/v2/referentiel/useReferentielClient.js.map +1 -1
- package/dist/esm/v2/referentiel/useReferentielOptions.js +60 -117
- package/dist/esm/v2/referentiel/useReferentielOptions.js.map +1 -1
- package/dist/esm/v2/referentiel/useReferentielSearch.js +37 -91
- package/dist/esm/v2/referentiel/useReferentielSearch.js.map +1 -1
- package/dist/esm/v2/theme/_brand.js +8 -24
- package/dist/esm/v2/theme/_brand.js.map +1 -1
- package/dist/esm/v2/theme/_brandSecondary.js +8 -24
- package/dist/esm/v2/theme/_brandSecondary.js.map +1 -1
- package/dist/esm/v2/theme/createPortnetTheme.js +51 -61
- package/dist/esm/v2/theme/createPortnetTheme.js.map +1 -1
- package/dist/esm/v2/theme/cssVariables.js +62 -69
- package/dist/esm/v2/theme/cssVariables.js.map +1 -1
- package/dist/esm/v2/theme/index.js +5 -5
- package/dist/esm/v2/theme/index.js.map +1 -1
- package/dist/esm/v2/tokens/breakpoints.js +14 -14
- package/dist/esm/v2/tokens/breakpoints.js.map +1 -1
- package/dist/esm/v2/tokens/chart.js +261 -0
- package/dist/esm/v2/tokens/chart.js.map +1 -0
- package/dist/esm/v2/tokens/colors.js +22 -22
- package/dist/esm/v2/tokens/colors.js.map +1 -1
- package/dist/esm/v2/tokens/density.js +62 -7
- package/dist/esm/v2/tokens/density.js.map +1 -1
- package/dist/esm/v2/tokens/index.js +49 -34
- package/dist/esm/v2/tokens/index.js.map +1 -1
- package/dist/esm/v2/tokens/motion.js +12 -20
- package/dist/esm/v2/tokens/motion.js.map +1 -1
- package/dist/esm/v2/tokens/radius.js +1 -1
- package/dist/esm/v2/tokens/radius.js.map +1 -1
- package/dist/esm/v2/tokens/shadows.js +6 -6
- package/dist/esm/v2/tokens/shadows.js.map +1 -1
- package/dist/esm/v2/tokens/spacing.js +2 -2
- package/dist/esm/v2/tokens/spacing.js.map +1 -1
- package/dist/esm/v2/tokens/state.js +1 -1
- package/dist/esm/v2/tokens/state.js.map +1 -1
- package/dist/esm/v2/tokens/statusPalette.js +17 -21
- package/dist/esm/v2/tokens/statusPalette.js.map +1 -1
- package/dist/esm/v2/tokens/tokens.json +6 -1
- package/dist/esm/v2/tokens/typography.js +13 -13
- package/dist/esm/v2/tokens/typography.js.map +1 -1
- package/dist/esm/v2/tokens/zIndex.js +1 -1
- package/dist/esm/v2/tokens/zIndex.js.map +1 -1
- package/dist/esm/v2/types/datagrid.js.map +1 -1
- package/dist/esm/v2/utils/apiError.js +16 -37
- package/dist/esm/v2/utils/apiError.js.map +1 -1
- package/dist/esm/v2/utils/contrast.js +31 -32
- package/dist/esm/v2/utils/contrast.js.map +1 -1
- package/dist/esm/v2/utils/cx.js +5 -25
- package/dist/esm/v2/utils/cx.js.map +1 -1
- package/dist/esm/v2/utils/fileDownload.js +23 -26
- package/dist/esm/v2/utils/fileDownload.js.map +1 -1
- package/dist/esm/v2/utils/fileValidation.js +209 -0
- package/dist/esm/v2/utils/fileValidation.js.map +1 -0
- package/dist/esm/v2/utils/fmtDate.js +111 -0
- package/dist/esm/v2/utils/fmtDate.js.map +1 -0
- package/dist/esm/v2/utils/fmtMoney.js +8 -10
- package/dist/esm/v2/utils/fmtMoney.js.map +1 -1
- package/dist/esm/v2/utils/formikErrors.js +78 -0
- package/dist/esm/v2/utils/formikErrors.js.map +1 -0
- package/dist/esm/v2/utils/index.js +35 -2
- package/dist/esm/v2/utils/index.js.map +1 -1
- package/dist/esm/v2/utils/mergeLabels.js +7 -12
- package/dist/esm/v2/utils/mergeLabels.js.map +1 -1
- package/dist/esm/v2/utils/networkStatus.js +12 -12
- package/dist/esm/v2/utils/networkStatus.js.map +1 -1
- package/dist/index.d.ts +7 -1
- package/dist/index.d.ts.map +1 -1
- package/dist/index.js +110 -49
- package/dist/index.js.map +1 -1
- package/dist/v2/__tests__/AppMain.test.js +133 -0
- package/dist/v2/__tests__/AppMain.test.js.map +1 -0
- package/dist/v2/__tests__/ChartFigure.test.js +183 -0
- package/dist/v2/__tests__/ChartFigure.test.js.map +1 -0
- package/dist/v2/__tests__/DataGridRowActionsPropagation.test.js +153 -0
- package/dist/v2/__tests__/DataGridRowActionsPropagation.test.js.map +1 -0
- package/dist/v2/__tests__/DrawerTactileTargets.test.js +94 -0
- package/dist/v2/__tests__/DrawerTactileTargets.test.js.map +1 -0
- package/dist/v2/__tests__/FieldError.test.js +82 -49
- package/dist/v2/__tests__/FieldError.test.js.map +1 -1
- package/dist/v2/__tests__/FieldNaming.test.js +161 -0
- package/dist/v2/__tests__/FieldNaming.test.js.map +1 -0
- package/dist/v2/__tests__/FieldWidth.test.js +23 -25
- package/dist/v2/__tests__/FieldWidth.test.js.map +1 -1
- package/dist/v2/__tests__/FileCard.test.js +29 -28
- package/dist/v2/__tests__/FileCard.test.js.map +1 -1
- package/dist/v2/__tests__/FormikCheckbox.test.js +90 -183
- package/dist/v2/__tests__/FormikCheckbox.test.js.map +1 -1
- package/dist/v2/__tests__/FormikDateTimePicker.test.js +38 -48
- package/dist/v2/__tests__/FormikDateTimePicker.test.js.map +1 -1
- package/dist/v2/__tests__/FormikDisplayWidth.test.js +102 -0
- package/dist/v2/__tests__/FormikDisplayWidth.test.js.map +1 -0
- package/dist/v2/__tests__/FormikRadioGroup.test.js +123 -204
- package/dist/v2/__tests__/FormikRadioGroup.test.js.map +1 -1
- package/dist/v2/__tests__/MobileRowCard.test.js +63 -61
- package/dist/v2/__tests__/MobileRowCard.test.js.map +1 -1
- package/dist/v2/__tests__/PreviewDrawer.test.js +169 -0
- package/dist/v2/__tests__/PreviewDrawer.test.js.map +1 -0
- package/dist/v2/__tests__/ReferentielFieldContainer.test.js +159 -0
- package/dist/v2/__tests__/ReferentielFieldContainer.test.js.map +1 -0
- package/dist/v2/__tests__/SectionErrorBoundary.test.js +53 -68
- package/dist/v2/__tests__/SectionErrorBoundary.test.js.map +1 -1
- package/dist/v2/__tests__/apiError.test.js +50 -69
- package/dist/v2/__tests__/apiError.test.js.map +1 -1
- package/dist/v2/__tests__/banned-patterns.test.js +42 -123
- package/dist/v2/__tests__/banned-patterns.test.js.map +1 -1
- package/dist/v2/__tests__/chart-palette.test.js +205 -0
- package/dist/v2/__tests__/chart-palette.test.js.map +1 -0
- package/dist/v2/__tests__/contrast-palette.test.js +42 -74
- package/dist/v2/__tests__/contrast-palette.test.js.map +1 -1
- package/dist/v2/__tests__/cssVariables.test.js +44 -51
- package/dist/v2/__tests__/cssVariables.test.js.map +1 -1
- package/dist/v2/__tests__/fileValidation.test.js +136 -0
- package/dist/v2/__tests__/fileValidation.test.js.map +1 -0
- package/dist/v2/__tests__/filterCriteria.test.js +324 -0
- package/dist/v2/__tests__/filterCriteria.test.js.map +1 -0
- package/dist/v2/__tests__/fmtDate.test.js +69 -0
- package/dist/v2/__tests__/fmtDate.test.js.map +1 -0
- package/dist/v2/__tests__/gap-leakage-refonte.test.js +221 -0
- package/dist/v2/__tests__/gap-leakage-refonte.test.js.map +1 -0
- package/dist/v2/__tests__/labels-merge.test.js +23 -27
- package/dist/v2/__tests__/labels-merge.test.js.map +1 -1
- package/dist/v2/__tests__/locale-fallback.test.js +47 -52
- package/dist/v2/__tests__/locale-fallback.test.js.map +1 -1
- package/dist/v2/__tests__/reviveSavedCriteria.test.js +144 -0
- package/dist/v2/__tests__/reviveSavedCriteria.test.js.map +1 -0
- package/dist/v2/__tests__/rowActions.test.js +186 -0
- package/dist/v2/__tests__/rowActions.test.js.map +1 -0
- package/dist/v2/__tests__/useFocusOnRouteChange.test.js +156 -0
- package/dist/v2/__tests__/useFocusOnRouteChange.test.js.map +1 -0
- package/dist/v2/__tests__/useFocusTrap.test.js +270 -407
- package/dist/v2/__tests__/useFocusTrap.test.js.map +1 -1
- package/dist/v2/__tests__/usePrefersReducedMotion.test.js +123 -0
- package/dist/v2/__tests__/usePrefersReducedMotion.test.js.map +1 -0
- package/dist/v2/components/Accordion.js +60 -82
- package/dist/v2/components/Accordion.js.map +1 -1
- package/dist/v2/components/ActionStrip.js +40 -52
- package/dist/v2/components/ActionStrip.js.map +1 -1
- package/dist/v2/components/Banner.js +42 -41
- package/dist/v2/components/Banner.js.map +1 -1
- package/dist/v2/components/Busy.js +22 -27
- package/dist/v2/components/Busy.js.map +1 -1
- package/dist/v2/components/Button.js +39 -50
- package/dist/v2/components/Button.js.map +1 -1
- package/dist/v2/components/CategoryTag.d.ts.map +1 -1
- package/dist/v2/components/CategoryTag.js +49 -32
- package/dist/v2/components/CategoryTag.js.map +1 -1
- package/dist/v2/components/Checkbox.js +39 -45
- package/dist/v2/components/Checkbox.js.map +1 -1
- package/dist/v2/components/Chip.js +29 -42
- package/dist/v2/components/Chip.js.map +1 -1
- package/dist/v2/components/Combobox.js +122 -144
- package/dist/v2/components/Combobox.js.map +1 -1
- package/dist/v2/components/CommandPalette.js +138 -225
- package/dist/v2/components/CommandPalette.js.map +1 -1
- package/dist/v2/components/ConfirmDialog.js +46 -56
- package/dist/v2/components/ConfirmDialog.js.map +1 -1
- package/dist/v2/components/DatePicker.js +81 -86
- package/dist/v2/components/DatePicker.js.map +1 -1
- package/dist/v2/components/DateRangePicker.js +77 -87
- package/dist/v2/components/DateRangePicker.js.map +1 -1
- package/dist/v2/components/DateTimePicker.js +84 -91
- package/dist/v2/components/DateTimePicker.js.map +1 -1
- package/dist/v2/components/Drawer.d.ts.map +1 -1
- package/dist/v2/components/Drawer.js +93 -88
- package/dist/v2/components/Drawer.js.map +1 -1
- package/dist/v2/components/Dropzone.js +150 -196
- package/dist/v2/components/Dropzone.js.map +1 -1
- package/dist/v2/components/EmptyState.js +18 -20
- package/dist/v2/components/EmptyState.js.map +1 -1
- package/dist/v2/components/FavoriteToggle.js +28 -39
- package/dist/v2/components/FavoriteToggle.js.map +1 -1
- package/dist/v2/components/Field.d.ts +62 -4
- package/dist/v2/components/Field.d.ts.map +1 -1
- package/dist/v2/components/Field.js +169 -70
- package/dist/v2/components/Field.js.map +1 -1
- package/dist/v2/components/FieldError.js +18 -21
- package/dist/v2/components/FieldError.js.map +1 -1
- package/dist/v2/components/FieldHelp.js +40 -60
- package/dist/v2/components/FieldHelp.js.map +1 -1
- package/dist/v2/components/FileCard.js +27 -31
- package/dist/v2/components/FileCard.js.map +1 -1
- package/dist/v2/components/FilterTab.js +30 -38
- package/dist/v2/components/FilterTab.js.map +1 -1
- package/dist/v2/components/ForbiddenPage.d.ts +25 -1
- package/dist/v2/components/ForbiddenPage.d.ts.map +1 -1
- package/dist/v2/components/ForbiddenPage.js +37 -17
- package/dist/v2/components/ForbiddenPage.js.map +1 -1
- package/dist/v2/components/FormGrid.js +53 -59
- package/dist/v2/components/FormGrid.js.map +1 -1
- package/dist/v2/components/FormikDisplay.d.ts +50 -1
- package/dist/v2/components/FormikDisplay.d.ts.map +1 -1
- package/dist/v2/components/FormikDisplay.js +108 -33
- package/dist/v2/components/FormikDisplay.js.map +1 -1
- package/dist/v2/components/Input.d.ts +40 -0
- package/dist/v2/components/Input.d.ts.map +1 -1
- package/dist/v2/components/Input.js +81 -41
- package/dist/v2/components/Input.js.map +1 -1
- package/dist/v2/components/KPICard.js +57 -67
- package/dist/v2/components/KPICard.js.map +1 -1
- package/dist/v2/components/KPIStrip.js +16 -22
- package/dist/v2/components/KPIStrip.js.map +1 -1
- package/dist/v2/components/KV.js +25 -31
- package/dist/v2/components/KV.js.map +1 -1
- package/dist/v2/components/KVGrid.js +19 -26
- package/dist/v2/components/KVGrid.js.map +1 -1
- package/dist/v2/components/Layout.js +91 -120
- package/dist/v2/components/Layout.js.map +1 -1
- package/dist/v2/components/MobileRowCard.js +79 -91
- package/dist/v2/components/MobileRowCard.js.map +1 -1
- package/dist/v2/components/Modal.js +61 -69
- package/dist/v2/components/Modal.js.map +1 -1
- package/dist/v2/components/NetworkErrorPage.d.ts +19 -1
- package/dist/v2/components/NetworkErrorPage.d.ts.map +1 -1
- package/dist/v2/components/NetworkErrorPage.js +38 -21
- package/dist/v2/components/NetworkErrorPage.js.map +1 -1
- package/dist/v2/components/NotFoundPage.d.ts +17 -1
- package/dist/v2/components/NotFoundPage.d.ts.map +1 -1
- package/dist/v2/components/NotFoundPage.js +37 -18
- package/dist/v2/components/NotFoundPage.js.map +1 -1
- package/dist/v2/components/NumberInput.js +88 -118
- package/dist/v2/components/NumberInput.js.map +1 -1
- package/dist/v2/components/OverflowMenu.js +38 -56
- package/dist/v2/components/OverflowMenu.js.map +1 -1
- package/dist/v2/components/PdfViewer.js +34 -45
- package/dist/v2/components/PdfViewer.js.map +1 -1
- package/dist/v2/components/ProgressBar.js +42 -49
- package/dist/v2/components/ProgressBar.js.map +1 -1
- package/dist/v2/components/Radio.js +59 -67
- package/dist/v2/components/Radio.js.map +1 -1
- package/dist/v2/components/SectionErrorBoundary.js +90 -135
- package/dist/v2/components/SectionErrorBoundary.js.map +1 -1
- package/dist/v2/components/SectionHeader.js +34 -41
- package/dist/v2/components/SectionHeader.js.map +1 -1
- package/dist/v2/components/Segmented.js +69 -93
- package/dist/v2/components/Segmented.js.map +1 -1
- package/dist/v2/components/Select.d.ts +26 -2
- package/dist/v2/components/Select.d.ts.map +1 -1
- package/dist/v2/components/Select.js +120 -155
- package/dist/v2/components/Select.js.map +1 -1
- package/dist/v2/components/ServerErrorPage.d.ts +27 -1
- package/dist/v2/components/ServerErrorPage.d.ts.map +1 -1
- package/dist/v2/components/ServerErrorPage.js +37 -20
- package/dist/v2/components/ServerErrorPage.js.map +1 -1
- package/dist/v2/components/Skeleton.js +86 -100
- package/dist/v2/components/Skeleton.js.map +1 -1
- package/dist/v2/components/SkipLink.js +9 -12
- package/dist/v2/components/SkipLink.js.map +1 -1
- package/dist/v2/components/Spinner.js +16 -25
- package/dist/v2/components/Spinner.js.map +1 -1
- package/dist/v2/components/Status.js +18 -29
- package/dist/v2/components/Status.js.map +1 -1
- package/dist/v2/components/Stepper.js +80 -82
- package/dist/v2/components/Stepper.js.map +1 -1
- package/dist/v2/components/Surface.js +34 -49
- package/dist/v2/components/Surface.js.map +1 -1
- package/dist/v2/components/Switch.js +29 -37
- package/dist/v2/components/Switch.js.map +1 -1
- package/dist/v2/components/TabPanel.d.ts +17 -0
- package/dist/v2/components/TabPanel.d.ts.map +1 -0
- package/dist/v2/components/TabPanel.js +90 -0
- package/dist/v2/components/TabPanel.js.map +1 -0
- package/dist/v2/components/Tabs.d.ts +25 -0
- package/dist/v2/components/Tabs.d.ts.map +1 -1
- package/dist/v2/components/Tabs.js +53 -29
- package/dist/v2/components/Tabs.js.map +1 -1
- package/dist/v2/components/TelInput.js +80 -115
- package/dist/v2/components/TelInput.js.map +1 -1
- package/dist/v2/components/Textarea.js +26 -35
- package/dist/v2/components/Textarea.js.map +1 -1
- package/dist/v2/components/TimePicker.js +62 -74
- package/dist/v2/components/TimePicker.js.map +1 -1
- package/dist/v2/components/Toast.js +119 -174
- package/dist/v2/components/Toast.js.map +1 -1
- package/dist/v2/components/Tooltip.js +23 -38
- package/dist/v2/components/Tooltip.js.map +1 -1
- package/dist/v2/components/_ErrorPageBody.js +15 -16
- package/dist/v2/components/_ErrorPageBody.js.map +1 -1
- package/dist/v2/components/_pickerShared.js +5 -5
- package/dist/v2/components/_pickerShared.js.map +1 -1
- package/dist/v2/components/index.d.ts +40 -1
- package/dist/v2/components/index.d.ts.map +1 -1
- package/dist/v2/components/index.js +153 -136
- package/dist/v2/components/index.js.map +1 -1
- package/dist/v2/hooks/index.d.ts +65 -0
- package/dist/v2/hooks/index.d.ts.map +1 -1
- package/dist/v2/hooks/index.js +63 -24
- package/dist/v2/hooks/index.js.map +1 -1
- package/dist/v2/hooks/useAppliedFilters.d.ts +102 -0
- package/dist/v2/hooks/useAppliedFilters.d.ts.map +1 -0
- package/dist/v2/hooks/useAppliedFilters.js +117 -0
- package/dist/v2/hooks/useAppliedFilters.js.map +1 -0
- package/dist/v2/hooks/useDebouncedCallback.d.ts +64 -0
- package/dist/v2/hooks/useDebouncedCallback.d.ts.map +1 -0
- package/dist/v2/hooks/useDebouncedCallback.js +87 -0
- package/dist/v2/hooks/useDebouncedCallback.js.map +1 -0
- package/dist/v2/hooks/useDelayedFlag.js +6 -20
- package/dist/v2/hooks/useDelayedFlag.js.map +1 -1
- package/dist/v2/hooks/useDensity.d.ts.map +1 -1
- package/dist/v2/hooks/useDensity.js +14 -18
- package/dist/v2/hooks/useDensity.js.map +1 -1
- package/dist/v2/hooks/useFocusFirstError.js +26 -34
- package/dist/v2/hooks/useFocusFirstError.js.map +1 -1
- package/dist/v2/hooks/useFocusOnRouteChange.d.ts +65 -0
- package/dist/v2/hooks/useFocusOnRouteChange.d.ts.map +1 -0
- package/dist/v2/hooks/useFocusOnRouteChange.js +88 -0
- package/dist/v2/hooks/useFocusOnRouteChange.js.map +1 -0
- package/dist/v2/hooks/useFocusTrap.js +20 -24
- package/dist/v2/hooks/useFocusTrap.js.map +1 -1
- package/dist/v2/hooks/useFormAutoSave.d.ts +4 -4
- package/dist/v2/hooks/useFormAutoSave.d.ts.map +1 -1
- package/dist/v2/hooks/useFormAutoSave.js +39 -54
- package/dist/v2/hooks/useFormAutoSave.js.map +1 -1
- package/dist/v2/hooks/useFormCompletionProgress.d.ts +1 -1
- package/dist/v2/hooks/useFormCompletionProgress.d.ts.map +1 -1
- package/dist/v2/hooks/useFormCompletionProgress.js +33 -52
- package/dist/v2/hooks/useFormCompletionProgress.js.map +1 -1
- package/dist/v2/hooks/useKeyboardShortcuts.d.ts +25 -0
- package/dist/v2/hooks/useKeyboardShortcuts.d.ts.map +1 -0
- package/dist/v2/hooks/useKeyboardShortcuts.js +132 -0
- package/dist/v2/hooks/useKeyboardShortcuts.js.map +1 -0
- package/dist/v2/hooks/usePrefersReducedMotion.d.ts +56 -0
- package/dist/v2/hooks/usePrefersReducedMotion.d.ts.map +1 -0
- package/dist/v2/hooks/usePrefersReducedMotion.js +105 -0
- package/dist/v2/hooks/usePrefersReducedMotion.js.map +1 -0
- package/dist/v2/hooks/useResolvedDensity.js +5 -13
- package/dist/v2/hooks/useResolvedDensity.js.map +1 -1
- package/dist/v2/hooks/useSortedRows.js +4 -6
- package/dist/v2/hooks/useSortedRows.js.map +1 -1
- package/dist/v2/hooks/useTabLoading.js +7 -22
- package/dist/v2/hooks/useTabLoading.js.map +1 -1
- package/dist/v2/index.js +143 -145
- package/dist/v2/index.js.map +1 -1
- package/dist/v2/modalContext.js +2 -2
- package/dist/v2/modalContext.js.map +1 -1
- package/dist/v2/models/favorite.d.ts +8 -9
- package/dist/v2/models/favorite.d.ts.map +1 -1
- package/dist/v2/models/favorite.js.map +1 -1
- package/dist/v2/models/index.js +4 -4
- package/dist/v2/models/index.js.map +1 -1
- package/dist/v2/models/personalization.d.ts +44 -48
- package/dist/v2/models/personalization.d.ts.map +1 -1
- package/dist/v2/models/personalization.js.map +1 -1
- package/dist/v2/models/referentiel.d.ts +32 -50
- package/dist/v2/models/referentiel.d.ts.map +1 -1
- package/dist/v2/models/referentiel.js.map +1 -1
- package/dist/v2/models/savedFilter.d.ts +8 -17
- package/dist/v2/models/savedFilter.d.ts.map +1 -1
- package/dist/v2/models/savedFilter.js.map +1 -1
- package/dist/v2/patterns/ActionBar.js +152 -187
- package/dist/v2/patterns/ActionBar.js.map +1 -1
- package/dist/v2/patterns/AppMain.d.ts +109 -0
- package/dist/v2/patterns/AppMain.d.ts.map +1 -0
- package/dist/v2/patterns/AppMain.js +115 -0
- package/dist/v2/patterns/AppMain.js.map +1 -0
- package/dist/v2/patterns/BulkActionBar.js +40 -42
- package/dist/v2/patterns/BulkActionBar.js.map +1 -1
- package/dist/v2/patterns/ChartFigure.d.ts +124 -0
- package/dist/v2/patterns/ChartFigure.d.ts.map +1 -0
- package/dist/v2/patterns/ChartFigure.js +159 -0
- package/dist/v2/patterns/ChartFigure.js.map +1 -0
- package/dist/v2/patterns/CollapsibleDataGrid.js +138 -174
- package/dist/v2/patterns/CollapsibleDataGrid.js.map +1 -1
- package/dist/v2/patterns/ColumnsToggle.js +60 -94
- package/dist/v2/patterns/ColumnsToggle.js.map +1 -1
- package/dist/v2/patterns/DataGrid.d.ts.map +1 -1
- package/dist/v2/patterns/DataGrid.js +262 -297
- package/dist/v2/patterns/DataGrid.js.map +1 -1
- package/dist/v2/patterns/DataGridSettingsMenu.d.ts +12 -0
- package/dist/v2/patterns/DataGridSettingsMenu.d.ts.map +1 -1
- package/dist/v2/patterns/DataGridSettingsMenu.js +104 -121
- package/dist/v2/patterns/DataGridSettingsMenu.js.map +1 -1
- package/dist/v2/patterns/DataGridToolbar.js +103 -106
- package/dist/v2/patterns/DataGridToolbar.js.map +1 -1
- package/dist/v2/patterns/DataGridVirtualized.js +179 -217
- package/dist/v2/patterns/DataGridVirtualized.js.map +1 -1
- package/dist/v2/patterns/DeleteResourceConfirmDialog.js +32 -35
- package/dist/v2/patterns/DeleteResourceConfirmDialog.js.map +1 -1
- package/dist/v2/patterns/DetailSplit.d.ts +87 -0
- package/dist/v2/patterns/DetailSplit.d.ts.map +1 -0
- package/dist/v2/patterns/DetailSplit.js +116 -0
- package/dist/v2/patterns/DetailSplit.js.map +1 -0
- package/dist/v2/patterns/FavoriteColumn.js +22 -23
- package/dist/v2/patterns/FavoriteColumn.js.map +1 -1
- package/dist/v2/patterns/FavoritesFilter.js +36 -44
- package/dist/v2/patterns/FavoritesFilter.js.map +1 -1
- package/dist/v2/patterns/FilterTabBar.d.ts +28 -0
- package/dist/v2/patterns/FilterTabBar.d.ts.map +1 -0
- package/dist/v2/patterns/FilterTabBar.js +120 -0
- package/dist/v2/patterns/FilterTabBar.js.map +1 -0
- package/dist/v2/patterns/FormErrorSummary.js +20 -23
- package/dist/v2/patterns/FormErrorSummary.js.map +1 -1
- package/dist/v2/patterns/FormPageShell.js +53 -50
- package/dist/v2/patterns/FormPageShell.js.map +1 -1
- package/dist/v2/patterns/FormSection.d.ts +8 -3
- package/dist/v2/patterns/FormSection.d.ts.map +1 -1
- package/dist/v2/patterns/FormSection.js +44 -51
- package/dist/v2/patterns/FormSection.js.map +1 -1
- package/dist/v2/patterns/FormikCheckbox.js +36 -45
- package/dist/v2/patterns/FormikCheckbox.js.map +1 -1
- package/dist/v2/patterns/FormikCheckboxGroup.d.ts +17 -1
- package/dist/v2/patterns/FormikCheckboxGroup.d.ts.map +1 -1
- package/dist/v2/patterns/FormikCheckboxGroup.js +62 -65
- package/dist/v2/patterns/FormikCheckboxGroup.js.map +1 -1
- package/dist/v2/patterns/FormikCombobox.js +55 -72
- package/dist/v2/patterns/FormikCombobox.js.map +1 -1
- package/dist/v2/patterns/FormikDatePicker.js +50 -64
- package/dist/v2/patterns/FormikDatePicker.js.map +1 -1
- package/dist/v2/patterns/FormikDateTimePicker.js +50 -64
- package/dist/v2/patterns/FormikDateTimePicker.js.map +1 -1
- package/dist/v2/patterns/FormikErrorFocus.js +25 -26
- package/dist/v2/patterns/FormikErrorFocus.js.map +1 -1
- package/dist/v2/patterns/FormikErrorSummary.d.ts +74 -0
- package/dist/v2/patterns/FormikErrorSummary.d.ts.map +1 -0
- package/dist/v2/patterns/FormikErrorSummary.js +97 -0
- package/dist/v2/patterns/FormikErrorSummary.js.map +1 -0
- package/dist/v2/patterns/FormikFile.d.ts +14 -1
- package/dist/v2/patterns/FormikFile.d.ts.map +1 -1
- package/dist/v2/patterns/FormikFile.js +99 -83
- package/dist/v2/patterns/FormikFile.js.map +1 -1
- package/dist/v2/patterns/FormikInput.js +45 -58
- package/dist/v2/patterns/FormikInput.js.map +1 -1
- package/dist/v2/patterns/FormikRadioGroup.js +45 -56
- package/dist/v2/patterns/FormikRadioGroup.js.map +1 -1
- package/dist/v2/patterns/FormikReferentielField.d.ts +12 -1
- package/dist/v2/patterns/FormikReferentielField.d.ts.map +1 -1
- package/dist/v2/patterns/FormikReferentielField.js +54 -64
- package/dist/v2/patterns/FormikReferentielField.js.map +1 -1
- package/dist/v2/patterns/FormikSelect.js +70 -92
- package/dist/v2/patterns/FormikSelect.js.map +1 -1
- package/dist/v2/patterns/FormikTextarea.js +35 -51
- package/dist/v2/patterns/FormikTextarea.js.map +1 -1
- package/dist/v2/patterns/KeyboardShortcutsHelp.js +60 -80
- package/dist/v2/patterns/KeyboardShortcutsHelp.js.map +1 -1
- package/dist/v2/patterns/NetworkErrorBanner.js +13 -16
- package/dist/v2/patterns/NetworkErrorBanner.js.map +1 -1
- package/dist/v2/patterns/PageContent.js +17 -20
- package/dist/v2/patterns/PageContent.js.map +1 -1
- package/dist/v2/patterns/PreviewDrawer.d.ts +49 -0
- package/dist/v2/patterns/PreviewDrawer.d.ts.map +1 -0
- package/dist/v2/patterns/PreviewDrawer.js +159 -0
- package/dist/v2/patterns/PreviewDrawer.js.map +1 -0
- package/dist/v2/patterns/ReferentielField.d.ts +86 -2
- package/dist/v2/patterns/ReferentielField.d.ts.map +1 -1
- package/dist/v2/patterns/ReferentielField.js +347 -327
- package/dist/v2/patterns/ReferentielField.js.map +1 -1
- package/dist/v2/patterns/RowFavoriteToggle.d.ts +6 -0
- package/dist/v2/patterns/RowFavoriteToggle.d.ts.map +1 -1
- package/dist/v2/patterns/RowFavoriteToggle.js +38 -30
- package/dist/v2/patterns/RowFavoriteToggle.js.map +1 -1
- package/dist/v2/patterns/SaveFilterDialog.js +50 -77
- package/dist/v2/patterns/SaveFilterDialog.js.map +1 -1
- package/dist/v2/patterns/SavedFiltersMenu.js +89 -107
- package/dist/v2/patterns/SavedFiltersMenu.js.map +1 -1
- package/dist/v2/patterns/SkeletonPageShell.js +122 -143
- package/dist/v2/patterns/SkeletonPageShell.js.map +1 -1
- package/dist/v2/patterns/SortableHeader.js +35 -57
- package/dist/v2/patterns/SortableHeader.js.map +1 -1
- package/dist/v2/patterns/Tour.js +121 -142
- package/dist/v2/patterns/Tour.js.map +1 -1
- package/dist/v2/patterns/_dataGridShared.d.ts.map +1 -1
- package/dist/v2/patterns/_dataGridShared.js +131 -147
- package/dist/v2/patterns/_dataGridShared.js.map +1 -1
- package/dist/v2/patterns/_pickerSerialisation.js +9 -10
- package/dist/v2/patterns/_pickerSerialisation.js.map +1 -1
- package/dist/v2/patterns/_sort.js +17 -33
- package/dist/v2/patterns/_sort.js.map +1 -1
- package/dist/v2/patterns/_useColumnReorder.js +124 -163
- package/dist/v2/patterns/_useColumnReorder.js.map +1 -1
- package/dist/v2/patterns/_useColumnResize.js +80 -99
- package/dist/v2/patterns/_useColumnResize.js.map +1 -1
- package/dist/v2/patterns/filterCriteria.d.ts +78 -0
- package/dist/v2/patterns/filterCriteria.d.ts.map +1 -0
- package/dist/v2/patterns/filterCriteria.js +110 -0
- package/dist/v2/patterns/filterCriteria.js.map +1 -0
- package/dist/v2/patterns/index.d.ts +160 -0
- package/dist/v2/patterns/index.d.ts.map +1 -1
- package/dist/v2/patterns/index.js +157 -79
- package/dist/v2/patterns/index.js.map +1 -1
- package/dist/v2/patterns/rowActions.d.ts +150 -0
- package/dist/v2/patterns/rowActions.d.ts.map +1 -0
- package/dist/v2/patterns/rowActions.js +232 -0
- package/dist/v2/patterns/rowActions.js.map +1 -0
- package/dist/v2/personalization/PersonalizationProvider.d.ts.map +1 -1
- package/dist/v2/personalization/PersonalizationProvider.js +57 -53
- package/dist/v2/personalization/PersonalizationProvider.js.map +1 -1
- package/dist/v2/personalization/adapters/_storageKey.js +5 -5
- package/dist/v2/personalization/adapters/_storageKey.js.map +1 -1
- package/dist/v2/personalization/adapters/createLocalStorageAdapter.js +25 -24
- package/dist/v2/personalization/adapters/createLocalStorageAdapter.js.map +1 -1
- package/dist/v2/personalization/adapters/createMemoryAdapter.js +14 -14
- package/dist/v2/personalization/adapters/createMemoryAdapter.js.map +1 -1
- package/dist/v2/personalization/adapters/index.js +5 -5
- package/dist/v2/personalization/adapters/index.js.map +1 -1
- package/dist/v2/personalization/capabilities/favorites.js +39 -62
- package/dist/v2/personalization/capabilities/favorites.js.map +1 -1
- package/dist/v2/personalization/capabilities/favoritesView.js +25 -37
- package/dist/v2/personalization/capabilities/favoritesView.js.map +1 -1
- package/dist/v2/personalization/capabilities/gridPreferences.js +31 -36
- package/dist/v2/personalization/capabilities/gridPreferences.js.map +1 -1
- package/dist/v2/personalization/capabilities/index.js +12 -12
- package/dist/v2/personalization/capabilities/reviveSavedCriteria.d.ts +88 -0
- package/dist/v2/personalization/capabilities/reviveSavedCriteria.d.ts.map +1 -0
- package/dist/v2/personalization/capabilities/reviveSavedCriteria.js +126 -0
- package/dist/v2/personalization/capabilities/reviveSavedCriteria.js.map +1 -0
- package/dist/v2/personalization/capabilities/savedFilters.js +93 -100
- package/dist/v2/personalization/capabilities/savedFilters.js.map +1 -1
- package/dist/v2/personalization/createPersonalizationStore.d.ts.map +1 -1
- package/dist/v2/personalization/createPersonalizationStore.js +81 -182
- package/dist/v2/personalization/createPersonalizationStore.js.map +1 -1
- package/dist/v2/personalization/index.d.ts +16 -0
- package/dist/v2/personalization/index.d.ts.map +1 -1
- package/dist/v2/personalization/index.js +30 -23
- package/dist/v2/personalization/index.js.map +1 -1
- package/dist/v2/personalization/personalizationContext.js +10 -12
- package/dist/v2/personalization/personalizationContext.js.map +1 -1
- package/dist/v2/personalization/schema.js +8 -9
- package/dist/v2/personalization/schema.js.map +1 -1
- package/dist/v2/referentiel/ReferentielProvider.js +31 -45
- package/dist/v2/referentiel/ReferentielProvider.js.map +1 -1
- package/dist/v2/referentiel/index.js +11 -13
- package/dist/v2/referentiel/index.js.map +1 -1
- package/dist/v2/referentiel/types.d.ts +105 -0
- package/dist/v2/referentiel/types.d.ts.map +1 -0
- package/dist/v2/referentiel/types.js +6 -0
- package/dist/v2/referentiel/types.js.map +1 -0
- package/dist/v2/referentiel/useReferentielClient.js +13 -16
- package/dist/v2/referentiel/useReferentielClient.js.map +1 -1
- package/dist/v2/referentiel/useReferentielOptions.d.ts +7 -17
- package/dist/v2/referentiel/useReferentielOptions.d.ts.map +1 -1
- package/dist/v2/referentiel/useReferentielOptions.js +63 -120
- package/dist/v2/referentiel/useReferentielOptions.js.map +1 -1
- package/dist/v2/referentiel/useReferentielSearch.d.ts +7 -48
- package/dist/v2/referentiel/useReferentielSearch.d.ts.map +1 -1
- package/dist/v2/referentiel/useReferentielSearch.js +40 -95
- package/dist/v2/referentiel/useReferentielSearch.js.map +1 -1
- package/dist/v2/theme/_brand.js +12 -26
- package/dist/v2/theme/_brand.js.map +1 -1
- package/dist/v2/theme/_brandSecondary.js +12 -26
- package/dist/v2/theme/_brandSecondary.js.map +1 -1
- package/dist/v2/theme/createPortnetTheme.js +41 -49
- package/dist/v2/theme/createPortnetTheme.js.map +1 -1
- package/dist/v2/theme/cssVariables.d.ts +3 -3
- package/dist/v2/theme/cssVariables.d.ts.map +1 -1
- package/dist/v2/theme/cssVariables.js +65 -70
- package/dist/v2/theme/cssVariables.js.map +1 -1
- package/dist/v2/theme/index.js +10 -10
- package/dist/v2/theme/index.js.map +1 -1
- package/dist/v2/tokens/breakpoints.js +16 -16
- package/dist/v2/tokens/breakpoints.js.map +1 -1
- package/dist/v2/tokens/chart.d.ts +103 -0
- package/dist/v2/tokens/chart.d.ts.map +1 -0
- package/dist/v2/tokens/chart.js +270 -0
- package/dist/v2/tokens/chart.js.map +1 -0
- package/dist/v2/tokens/colors.js +24 -24
- package/dist/v2/tokens/colors.js.map +1 -1
- package/dist/v2/tokens/density.d.ts +104 -0
- package/dist/v2/tokens/density.d.ts.map +1 -1
- package/dist/v2/tokens/density.js +67 -12
- package/dist/v2/tokens/density.js.map +1 -1
- package/dist/v2/tokens/index.d.ts +50 -1
- package/dist/v2/tokens/index.d.ts.map +1 -1
- package/dist/v2/tokens/index.js +116 -68
- package/dist/v2/tokens/index.js.map +1 -1
- package/dist/v2/tokens/motion.js +16 -22
- package/dist/v2/tokens/motion.js.map +1 -1
- package/dist/v2/tokens/radius.js +3 -3
- package/dist/v2/tokens/radius.js.map +1 -1
- package/dist/v2/tokens/shadows.js +8 -8
- package/dist/v2/tokens/shadows.js.map +1 -1
- package/dist/v2/tokens/spacing.js +4 -4
- package/dist/v2/tokens/spacing.js.map +1 -1
- package/dist/v2/tokens/state.js +3 -3
- package/dist/v2/tokens/state.js.map +1 -1
- package/dist/v2/tokens/statusPalette.js +21 -23
- package/dist/v2/tokens/statusPalette.js.map +1 -1
- package/dist/v2/tokens/tokens.json +6 -1
- package/dist/v2/tokens/typography.js +15 -15
- package/dist/v2/tokens/typography.js.map +1 -1
- package/dist/v2/tokens/zIndex.js +3 -3
- package/dist/v2/tokens/zIndex.js.map +1 -1
- package/dist/v2/types/datagrid.d.ts +9 -1
- package/dist/v2/types/datagrid.d.ts.map +1 -1
- package/dist/v2/types/datagrid.js.map +1 -1
- package/dist/v2/types/index.js +2 -2
- package/dist/v2/types/index.js.map +1 -1
- package/dist/v2/utils/apiError.js +16 -37
- package/dist/v2/utils/apiError.js.map +1 -1
- package/dist/v2/utils/contrast.js +31 -32
- package/dist/v2/utils/contrast.js.map +1 -1
- package/dist/v2/utils/cx.js +7 -27
- package/dist/v2/utils/cx.js.map +1 -1
- package/dist/v2/utils/fileDownload.js +25 -28
- package/dist/v2/utils/fileDownload.js.map +1 -1
- package/dist/v2/utils/fileValidation.d.ts +116 -0
- package/dist/v2/utils/fileValidation.d.ts.map +1 -0
- package/dist/v2/utils/fileValidation.js +220 -0
- package/dist/v2/utils/fileValidation.js.map +1 -0
- package/dist/v2/utils/fmtDate.d.ts +103 -0
- package/dist/v2/utils/fmtDate.d.ts.map +1 -0
- package/dist/v2/utils/fmtDate.js +119 -0
- package/dist/v2/utils/fmtDate.js.map +1 -0
- package/dist/v2/utils/fmtMoney.d.ts +3 -3
- package/dist/v2/utils/fmtMoney.d.ts.map +1 -1
- package/dist/v2/utils/fmtMoney.js +9 -11
- package/dist/v2/utils/fmtMoney.js.map +1 -1
- package/dist/v2/utils/formikErrors.d.ts +67 -0
- package/dist/v2/utils/formikErrors.d.ts.map +1 -0
- package/dist/v2/utils/formikErrors.js +85 -0
- package/dist/v2/utils/formikErrors.js.map +1 -0
- package/dist/v2/utils/index.d.ts +5 -0
- package/dist/v2/utils/index.d.ts.map +1 -1
- package/dist/v2/utils/index.js +67 -18
- package/dist/v2/utils/index.js.map +1 -1
- package/dist/v2/utils/mergeLabels.js +9 -14
- package/dist/v2/utils/mergeLabels.js.map +1 -1
- package/dist/v2/utils/networkStatus.js +14 -14
- package/dist/v2/utils/networkStatus.js.map +1 -1
- package/package.json +26 -9
|
@@ -0,0 +1,65 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* useFocusOnRouteChange — move focus to the main landmark when the page changes
|
|
3
|
+
*
|
|
4
|
+
* ─────────────────────────────────────────────────────────────────────────────
|
|
5
|
+
* WHY THIS EXISTS (capability gap G-60)
|
|
6
|
+
*
|
|
7
|
+
* In a single-page application, navigating does NOT move focus. The browser
|
|
8
|
+
* only does that on a real document load. So after a route change the focus
|
|
9
|
+
* stays on whatever was clicked — or, when that element is unmounted by the
|
|
10
|
+
* very navigation it triggered, falls to `document.body`.
|
|
11
|
+
*
|
|
12
|
+
* From `document.body`, a keyboard user's next Tab starts at the top of the
|
|
13
|
+
* BROWSER, not of the page: they walk the address bar and the toolbar again on
|
|
14
|
+
* every screen. A screen-reader user gets no announcement at all — the new page
|
|
15
|
+
* simply exists, silently, and they must go looking for it. WCAG 2.4.3 (Focus
|
|
16
|
+
* Order) is what this fails, and nothing on screen shows it: the pixels are
|
|
17
|
+
* perfect.
|
|
18
|
+
*
|
|
19
|
+
* The failure is at its worst where a navigation follows an ACTION, because the
|
|
20
|
+
* trigger is gone by the time focus would return to it. Observed in
|
|
21
|
+
* `autorisation-admis-pour-conforme-fe` (Area 10): archiving a dossier closes a
|
|
22
|
+
* confirmation dialog and navigates back, so the dialog's focus trap restores
|
|
23
|
+
* focus to a button that no longer exists.
|
|
24
|
+
*
|
|
25
|
+
* The library is the right home even though it knows nothing about routers:
|
|
26
|
+
* `AppMain` — the landmark this hook targets — is the library's, and it is
|
|
27
|
+
* `AppMain` that carries the `tabIndex={-1}` making the region focusable at
|
|
28
|
+
* all. A host wiring this by hand would be reimplementing the pairing that
|
|
29
|
+
* `SkipLink` + `AppMain` already own.
|
|
30
|
+
* ─────────────────────────────────────────────────────────────────────────────
|
|
31
|
+
*
|
|
32
|
+
* ROUTER-AGNOSTIC BY CONSTRUCTION. No router is imported; the host passes the
|
|
33
|
+
* key it wants to watch:
|
|
34
|
+
*
|
|
35
|
+
* const { pathname } = useLocation();
|
|
36
|
+
* useFocusOnRouteChange(pathname);
|
|
37
|
+
*
|
|
38
|
+
* PASS THE PATHNAME, NOT `location.key` NOR THE FULL URL. A list screen writes
|
|
39
|
+
* its filters, its page number and its sort into the query string, and each of
|
|
40
|
+
* those is a new `key`: watching it would steal focus from the input the user
|
|
41
|
+
* is typing in, mid-search. What deserves a focus move is a change of PAGE, not
|
|
42
|
+
* a change of page state.
|
|
43
|
+
*
|
|
44
|
+
* THE FIRST RENDER IS SKIPPED. On initial load the browser has already placed
|
|
45
|
+
* focus at the start of the document, which is where a user expects it —
|
|
46
|
+
* moving it then would fight the browser and, worse, scroll a deep-linked page
|
|
47
|
+
* away from its anchor.
|
|
48
|
+
*/
|
|
49
|
+
export interface UseFocusOnRouteChangeOptions {
|
|
50
|
+
/**
|
|
51
|
+
* Id of the element to focus. Defaults to `"main-content"` — `AppMain`'s
|
|
52
|
+
* default id, which is also `SkipLink`'s default target. Change all three
|
|
53
|
+
* together or none.
|
|
54
|
+
*/
|
|
55
|
+
targetId?: string | undefined;
|
|
56
|
+
/**
|
|
57
|
+
* Set to `false` to suspend the behaviour. Exists for the host that owns a
|
|
58
|
+
* screen where a deliberate focus placement must survive a route change
|
|
59
|
+
* (an embedded wizard step, say) — not as a global off switch.
|
|
60
|
+
*/
|
|
61
|
+
enabled?: boolean | undefined;
|
|
62
|
+
}
|
|
63
|
+
export declare function useFocusOnRouteChange(routeKey: string | undefined, options?: UseFocusOnRouteChangeOptions): void;
|
|
64
|
+
export default useFocusOnRouteChange;
|
|
65
|
+
//# sourceMappingURL=useFocusOnRouteChange.d.ts.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"useFocusOnRouteChange.d.ts","sourceRoot":"","sources":["../../../src/lib/v2/hooks/useFocusOnRouteChange.ts"],"names":[],"mappings":"AAEA;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;GA+CG;AAEH,MAAM,WAAW,4BAA4B;IAC3C;;;;OAIG;IACH,QAAQ,CAAC,EAAE,MAAM,GAAG,SAAS,CAAC;IAC9B;;;;OAIG;IACH,OAAO,CAAC,EAAE,OAAO,GAAG,SAAS,CAAC;CAC/B;AAED,wBAAgB,qBAAqB,CACnC,QAAQ,EAAE,MAAM,GAAG,SAAS,EAC5B,OAAO,GAAE,4BAAiC,GACzC,IAAI,CA0BN;AAED,eAAe,qBAAqB,CAAC"}
|
|
@@ -0,0 +1,88 @@
|
|
|
1
|
+
"use strict";
|
|
2
|
+
|
|
3
|
+
Object.defineProperty(exports, "__esModule", {
|
|
4
|
+
value: true
|
|
5
|
+
});
|
|
6
|
+
exports.default = void 0;
|
|
7
|
+
exports.useFocusOnRouteChange = useFocusOnRouteChange;
|
|
8
|
+
var React = _interopRequireWildcard(require("react"));
|
|
9
|
+
function _interopRequireWildcard(e, t) { if ("function" == typeof WeakMap) var r = new WeakMap(), n = new WeakMap(); return (_interopRequireWildcard = function (e, t) { if (!t && e && e.__esModule) return e; var o, i, f = { __proto__: null, default: e }; if (null === e || "object" != typeof e && "function" != typeof e) return f; if (o = t ? n : r) { if (o.has(e)) return o.get(e); o.set(e, f); } for (const t in e) "default" !== t && {}.hasOwnProperty.call(e, t) && ((i = (o = Object.defineProperty) && Object.getOwnPropertyDescriptor(e, t)) && (i.get || i.set) ? o(f, t, i) : f[t] = e[t]); return f; })(e, t); }
|
|
10
|
+
/**
|
|
11
|
+
* useFocusOnRouteChange — move focus to the main landmark when the page changes
|
|
12
|
+
*
|
|
13
|
+
* ─────────────────────────────────────────────────────────────────────────────
|
|
14
|
+
* WHY THIS EXISTS (capability gap G-60)
|
|
15
|
+
*
|
|
16
|
+
* In a single-page application, navigating does NOT move focus. The browser
|
|
17
|
+
* only does that on a real document load. So after a route change the focus
|
|
18
|
+
* stays on whatever was clicked — or, when that element is unmounted by the
|
|
19
|
+
* very navigation it triggered, falls to `document.body`.
|
|
20
|
+
*
|
|
21
|
+
* From `document.body`, a keyboard user's next Tab starts at the top of the
|
|
22
|
+
* BROWSER, not of the page: they walk the address bar and the toolbar again on
|
|
23
|
+
* every screen. A screen-reader user gets no announcement at all — the new page
|
|
24
|
+
* simply exists, silently, and they must go looking for it. WCAG 2.4.3 (Focus
|
|
25
|
+
* Order) is what this fails, and nothing on screen shows it: the pixels are
|
|
26
|
+
* perfect.
|
|
27
|
+
*
|
|
28
|
+
* The failure is at its worst where a navigation follows an ACTION, because the
|
|
29
|
+
* trigger is gone by the time focus would return to it. Observed in
|
|
30
|
+
* `autorisation-admis-pour-conforme-fe` (Area 10): archiving a dossier closes a
|
|
31
|
+
* confirmation dialog and navigates back, so the dialog's focus trap restores
|
|
32
|
+
* focus to a button that no longer exists.
|
|
33
|
+
*
|
|
34
|
+
* The library is the right home even though it knows nothing about routers:
|
|
35
|
+
* `AppMain` — the landmark this hook targets — is the library's, and it is
|
|
36
|
+
* `AppMain` that carries the `tabIndex={-1}` making the region focusable at
|
|
37
|
+
* all. A host wiring this by hand would be reimplementing the pairing that
|
|
38
|
+
* `SkipLink` + `AppMain` already own.
|
|
39
|
+
* ─────────────────────────────────────────────────────────────────────────────
|
|
40
|
+
*
|
|
41
|
+
* ROUTER-AGNOSTIC BY CONSTRUCTION. No router is imported; the host passes the
|
|
42
|
+
* key it wants to watch:
|
|
43
|
+
*
|
|
44
|
+
* const { pathname } = useLocation();
|
|
45
|
+
* useFocusOnRouteChange(pathname);
|
|
46
|
+
*
|
|
47
|
+
* PASS THE PATHNAME, NOT `location.key` NOR THE FULL URL. A list screen writes
|
|
48
|
+
* its filters, its page number and its sort into the query string, and each of
|
|
49
|
+
* those is a new `key`: watching it would steal focus from the input the user
|
|
50
|
+
* is typing in, mid-search. What deserves a focus move is a change of PAGE, not
|
|
51
|
+
* a change of page state.
|
|
52
|
+
*
|
|
53
|
+
* THE FIRST RENDER IS SKIPPED. On initial load the browser has already placed
|
|
54
|
+
* focus at the start of the document, which is where a user expects it —
|
|
55
|
+
* moving it then would fight the browser and, worse, scroll a deep-linked page
|
|
56
|
+
* away from its anchor.
|
|
57
|
+
*/
|
|
58
|
+
|
|
59
|
+
function useFocusOnRouteChange(routeKey, options = {}) {
|
|
60
|
+
const {
|
|
61
|
+
targetId = "main-content",
|
|
62
|
+
enabled = true
|
|
63
|
+
} = options;
|
|
64
|
+
|
|
65
|
+
/* The previous key, NOT a boolean "has mounted": comparing keys is what lets
|
|
66
|
+
the effect run once per actual change, and skip the first render without a
|
|
67
|
+
second piece of state. */
|
|
68
|
+
const previousKeyRef = React.useRef(routeKey);
|
|
69
|
+
React.useEffect(() => {
|
|
70
|
+
if (!enabled) return;
|
|
71
|
+
if (previousKeyRef.current === routeKey) return;
|
|
72
|
+
previousKeyRef.current = routeKey;
|
|
73
|
+
const target = document.getElementById(targetId);
|
|
74
|
+
/* Silently doing nothing is deliberate: a host may render this hook on a
|
|
75
|
+
shell that mounts BEFORE its landmark (a pre-auth screen, an error
|
|
76
|
+
boundary). Throwing there would replace a missing focus move with a
|
|
77
|
+
crash. */
|
|
78
|
+
if (target === null) return;
|
|
79
|
+
|
|
80
|
+
/* `preventScroll` is NOT set: bringing the top of the region into view is
|
|
81
|
+
part of what the user expects from a page change, and suppressing it
|
|
82
|
+
would leave a long list scrolled where the previous page had left it
|
|
83
|
+
while the focus ring sits off-screen. */
|
|
84
|
+
target.focus();
|
|
85
|
+
}, [routeKey, targetId, enabled]);
|
|
86
|
+
}
|
|
87
|
+
var _default = exports.default = useFocusOnRouteChange;
|
|
88
|
+
//# sourceMappingURL=useFocusOnRouteChange.js.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"useFocusOnRouteChange.js","names":["React","_interopRequireWildcard","require","e","t","WeakMap","r","n","__esModule","o","i","f","__proto__","default","has","get","set","hasOwnProperty","call","Object","defineProperty","getOwnPropertyDescriptor","useFocusOnRouteChange","routeKey","options","targetId","enabled","previousKeyRef","useRef","useEffect","current","target","document","getElementById","focus","_default","exports"],"sources":["../../../src/lib/v2/hooks/useFocusOnRouteChange.ts"],"sourcesContent":["import * as React from \"react\";\r\n\r\n/**\r\n * useFocusOnRouteChange — move focus to the main landmark when the page changes\r\n *\r\n * ─────────────────────────────────────────────────────────────────────────────\r\n * WHY THIS EXISTS (capability gap G-60)\r\n *\r\n * In a single-page application, navigating does NOT move focus. The browser\r\n * only does that on a real document load. So after a route change the focus\r\n * stays on whatever was clicked — or, when that element is unmounted by the\r\n * very navigation it triggered, falls to `document.body`.\r\n *\r\n * From `document.body`, a keyboard user's next Tab starts at the top of the\r\n * BROWSER, not of the page: they walk the address bar and the toolbar again on\r\n * every screen. A screen-reader user gets no announcement at all — the new page\r\n * simply exists, silently, and they must go looking for it. WCAG 2.4.3 (Focus\r\n * Order) is what this fails, and nothing on screen shows it: the pixels are\r\n * perfect.\r\n *\r\n * The failure is at its worst where a navigation follows an ACTION, because the\r\n * trigger is gone by the time focus would return to it. Observed in\r\n * `autorisation-admis-pour-conforme-fe` (Area 10): archiving a dossier closes a\r\n * confirmation dialog and navigates back, so the dialog's focus trap restores\r\n * focus to a button that no longer exists.\r\n *\r\n * The library is the right home even though it knows nothing about routers:\r\n * `AppMain` — the landmark this hook targets — is the library's, and it is\r\n * `AppMain` that carries the `tabIndex={-1}` making the region focusable at\r\n * all. A host wiring this by hand would be reimplementing the pairing that\r\n * `SkipLink` + `AppMain` already own.\r\n * ─────────────────────────────────────────────────────────────────────────────\r\n *\r\n * ROUTER-AGNOSTIC BY CONSTRUCTION. No router is imported; the host passes the\r\n * key it wants to watch:\r\n *\r\n * const { pathname } = useLocation();\r\n * useFocusOnRouteChange(pathname);\r\n *\r\n * PASS THE PATHNAME, NOT `location.key` NOR THE FULL URL. A list screen writes\r\n * its filters, its page number and its sort into the query string, and each of\r\n * those is a new `key`: watching it would steal focus from the input the user\r\n * is typing in, mid-search. What deserves a focus move is a change of PAGE, not\r\n * a change of page state.\r\n *\r\n * THE FIRST RENDER IS SKIPPED. On initial load the browser has already placed\r\n * focus at the start of the document, which is where a user expects it —\r\n * moving it then would fight the browser and, worse, scroll a deep-linked page\r\n * away from its anchor.\r\n */\r\n\r\nexport interface UseFocusOnRouteChangeOptions {\r\n /**\r\n * Id of the element to focus. Defaults to `\"main-content\"` — `AppMain`'s\r\n * default id, which is also `SkipLink`'s default target. Change all three\r\n * together or none.\r\n */\r\n targetId?: string | undefined;\r\n /**\r\n * Set to `false` to suspend the behaviour. Exists for the host that owns a\r\n * screen where a deliberate focus placement must survive a route change\r\n * (an embedded wizard step, say) — not as a global off switch.\r\n */\r\n enabled?: boolean | undefined;\r\n}\r\n\r\nexport function useFocusOnRouteChange(\r\n routeKey: string | undefined,\r\n options: UseFocusOnRouteChangeOptions = {}\r\n): void {\r\n const { targetId = \"main-content\", enabled = true } = options;\r\n\r\n /* The previous key, NOT a boolean \"has mounted\": comparing keys is what lets\r\n the effect run once per actual change, and skip the first render without a\r\n second piece of state. */\r\n const previousKeyRef = React.useRef<string | undefined>(routeKey);\r\n\r\n React.useEffect(() => {\r\n if (!enabled) return;\r\n if (previousKeyRef.current === routeKey) return;\r\n previousKeyRef.current = routeKey;\r\n\r\n const target = document.getElementById(targetId);\r\n /* Silently doing nothing is deliberate: a host may render this hook on a\r\n shell that mounts BEFORE its landmark (a pre-auth screen, an error\r\n boundary). Throwing there would replace a missing focus move with a\r\n crash. */\r\n if (target === null) return;\r\n\r\n /* `preventScroll` is NOT set: bringing the top of the region into view is\r\n part of what the user expects from a page change, and suppressing it\r\n would leave a long list scrolled where the previous page had left it\r\n while the focus ring sits off-screen. */\r\n target.focus();\r\n }, [routeKey, targetId, enabled]);\r\n}\r\n\r\nexport default useFocusOnRouteChange;\r\n"],"mappings":";;;;;;;AAAA,IAAAA,KAAA,GAAAC,uBAAA,CAAAC,OAAA;AAA+B,SAAAD,wBAAAE,CAAA,EAAAC,CAAA,6BAAAC,OAAA,MAAAC,CAAA,OAAAD,OAAA,IAAAE,CAAA,OAAAF,OAAA,YAAAJ,uBAAA,YAAAA,CAAAE,CAAA,EAAAC,CAAA,SAAAA,CAAA,IAAAD,CAAA,IAAAA,CAAA,CAAAK,UAAA,SAAAL,CAAA,MAAAM,CAAA,EAAAC,CAAA,EAAAC,CAAA,KAAAC,SAAA,QAAAC,OAAA,EAAAV,CAAA,iBAAAA,CAAA,uBAAAA,CAAA,yBAAAA,CAAA,SAAAQ,CAAA,MAAAF,CAAA,GAAAL,CAAA,GAAAG,CAAA,GAAAD,CAAA,QAAAG,CAAA,CAAAK,GAAA,CAAAX,CAAA,UAAAM,CAAA,CAAAM,GAAA,CAAAZ,CAAA,GAAAM,CAAA,CAAAO,GAAA,CAAAb,CAAA,EAAAQ,CAAA,gBAAAP,CAAA,IAAAD,CAAA,gBAAAC,CAAA,OAAAa,cAAA,CAAAC,IAAA,CAAAf,CAAA,EAAAC,CAAA,OAAAM,CAAA,IAAAD,CAAA,GAAAU,MAAA,CAAAC,cAAA,KAAAD,MAAA,CAAAE,wBAAA,CAAAlB,CAAA,EAAAC,CAAA,OAAAM,CAAA,CAAAK,GAAA,IAAAL,CAAA,CAAAM,GAAA,IAAAP,CAAA,CAAAE,CAAA,EAAAP,CAAA,EAAAM,CAAA,IAAAC,CAAA,CAAAP,CAAA,IAAAD,CAAA,CAAAC,CAAA,WAAAO,CAAA,KAAAR,CAAA,EAAAC,CAAA;AAE/B;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;;AAiBO,SAASkB,qBAAqBA,CACnCC,QAA4B,EAC5BC,OAAqC,GAAG,CAAC,CAAC,EACpC;EACN,MAAM;IAAEC,QAAQ,GAAG,cAAc;IAAEC,OAAO,GAAG;EAAK,CAAC,GAAGF,OAAO;;EAE7D;AACF;AACA;EACE,MAAMG,cAAc,GAAG3B,KAAK,CAAC4B,MAAM,CAAqBL,QAAQ,CAAC;EAEjEvB,KAAK,CAAC6B,SAAS,CAAC,MAAM;IACpB,IAAI,CAACH,OAAO,EAAE;IACd,IAAIC,cAAc,CAACG,OAAO,KAAKP,QAAQ,EAAE;IACzCI,cAAc,CAACG,OAAO,GAAGP,QAAQ;IAEjC,MAAMQ,MAAM,GAAGC,QAAQ,CAACC,cAAc,CAACR,QAAQ,CAAC;IAChD;AACJ;AACA;AACA;IACI,IAAIM,MAAM,KAAK,IAAI,EAAE;;IAErB;AACJ;AACA;AACA;IACIA,MAAM,CAACG,KAAK,CAAC,CAAC;EAChB,CAAC,EAAE,CAACX,QAAQ,EAAEE,QAAQ,EAAEC,OAAO,CAAC,CAAC;AACnC;AAAC,IAAAS,QAAA,GAAAC,OAAA,CAAAvB,OAAA,GAEcS,qBAAqB","ignoreList":[]}
|
|
@@ -3,7 +3,7 @@
|
|
|
3
3
|
Object.defineProperty(exports, "__esModule", {
|
|
4
4
|
value: true
|
|
5
5
|
});
|
|
6
|
-
exports
|
|
6
|
+
exports.default = useFocusTrap;
|
|
7
7
|
var _react = require("react");
|
|
8
8
|
/**
|
|
9
9
|
* useFocusTrap — Portnet UI v2
|
|
@@ -62,8 +62,8 @@ var _react = require("react");
|
|
|
62
62
|
* @param isActive Whether the trap is currently on.
|
|
63
63
|
*/
|
|
64
64
|
|
|
65
|
-
|
|
66
|
-
|
|
65
|
+
const FOCUSABLE_SELECTORS = ["a[href]", "button:not(:disabled)", "input:not(:disabled)", "select:not(:disabled)", "textarea:not(:disabled)", '[tabindex]:not([tabindex="-1"])', '[contenteditable]:not([contenteditable="false"])', "audio[controls]", "video[controls]"].join(", ");
|
|
66
|
+
const AUTOFOCUS_SELECTORS = "[autofocus], [data-autofocus]";
|
|
67
67
|
|
|
68
68
|
/**
|
|
69
69
|
* Module-level stack of active trap containers. Only the LAST entry
|
|
@@ -71,7 +71,7 @@ var AUTOFOCUS_SELECTORS = "[autofocus], [data-autofocus]";
|
|
|
71
71
|
* pass-through. Cleanup pops by reference to tolerate out-of-order
|
|
72
72
|
* unmount sequences (portal teardown, hot-replace).
|
|
73
73
|
*/
|
|
74
|
-
|
|
74
|
+
const trapStack = [];
|
|
75
75
|
|
|
76
76
|
/**
|
|
77
77
|
* Is `container` the INNERMOST active trap?
|
|
@@ -94,9 +94,7 @@ var trapStack = [];
|
|
|
94
94
|
* the inner trap pops, the outer contains nothing and resumes duty.
|
|
95
95
|
*/
|
|
96
96
|
function isInnermostTrap(container) {
|
|
97
|
-
return !trapStack.some(
|
|
98
|
-
return other !== container && container.contains(other);
|
|
99
|
-
});
|
|
97
|
+
return !trapStack.some(other => other !== container && container.contains(other));
|
|
100
98
|
}
|
|
101
99
|
|
|
102
100
|
/**
|
|
@@ -116,7 +114,7 @@ function isVisuallyFocusable(el) {
|
|
|
116
114
|
return false;
|
|
117
115
|
}
|
|
118
116
|
// Walk ancestors for hidden / aria-hidden / inert.
|
|
119
|
-
|
|
117
|
+
let node = el;
|
|
120
118
|
while (node && node !== document.body) {
|
|
121
119
|
if (node.hasAttribute && (node.hasAttribute("inert") || node.hasAttribute("hidden") || node.getAttribute("aria-hidden") === "true")) {
|
|
122
120
|
return false;
|
|
@@ -126,19 +124,17 @@ function isVisuallyFocusable(el) {
|
|
|
126
124
|
return true;
|
|
127
125
|
}
|
|
128
126
|
function useFocusTrap(ref, isActive) {
|
|
129
|
-
(0, _react.useEffect)(
|
|
127
|
+
(0, _react.useEffect)(() => {
|
|
130
128
|
if (!isActive || !ref.current) return undefined;
|
|
131
|
-
|
|
129
|
+
const container = ref.current;
|
|
132
130
|
trapStack.push(container);
|
|
133
|
-
|
|
134
|
-
|
|
135
|
-
};
|
|
136
|
-
var trigger = document.activeElement;
|
|
131
|
+
const getFocusable = () => Array.from(container.querySelectorAll(FOCUSABLE_SELECTORS)).filter(isVisuallyFocusable);
|
|
132
|
+
const trigger = document.activeElement;
|
|
137
133
|
|
|
138
134
|
// Initial focus, deferred to next frame so React has finished
|
|
139
135
|
// painting any conditional content. Cancellation handle stored
|
|
140
136
|
// so unmount-within-same-frame cannot leak a stale .focus() call.
|
|
141
|
-
|
|
137
|
+
const rafId = requestAnimationFrame(() => {
|
|
142
138
|
/* Only the innermost trap claims initial focus — same predicate as `trap()`
|
|
143
139
|
* below, so keyboard duty and initial focus can never disagree.
|
|
144
140
|
*
|
|
@@ -146,26 +142,26 @@ function useFocusTrap(ref, isActive) {
|
|
|
146
142
|
* activation regardless of nesting, so on simultaneous mount the outer
|
|
147
143
|
* trap's rAF fired last and overwrote the inner trap's focus. */
|
|
148
144
|
if (!isInnermostTrap(container)) return;
|
|
149
|
-
|
|
150
|
-
|
|
145
|
+
const explicit = container.querySelector(AUTOFOCUS_SELECTORS);
|
|
146
|
+
const target = explicit && isVisuallyFocusable(explicit) ? explicit : getFocusable()[0];
|
|
151
147
|
if (target && typeof target.focus === "function") target.focus();
|
|
152
148
|
});
|
|
153
|
-
|
|
149
|
+
const trap = e => {
|
|
154
150
|
if (e.key !== "Tab") return;
|
|
155
151
|
// Only the innermost trap acts. Outer traps stay registered and defer.
|
|
156
152
|
// Containment, NOT stack position — see isInnermostTrap.
|
|
157
153
|
if (!isInnermostTrap(container)) return;
|
|
158
|
-
|
|
154
|
+
const els = getFocusable();
|
|
159
155
|
if (!els.length) {
|
|
160
156
|
// Pathological case (no focusable inside): swallow Tab so
|
|
161
157
|
// focus cannot escape into the page behind the trap.
|
|
162
158
|
e.preventDefault();
|
|
163
159
|
return;
|
|
164
160
|
}
|
|
165
|
-
|
|
166
|
-
|
|
161
|
+
const first = els[0];
|
|
162
|
+
const last = els[els.length - 1];
|
|
167
163
|
if (!first || !last) return;
|
|
168
|
-
|
|
164
|
+
const active = document.activeElement;
|
|
169
165
|
|
|
170
166
|
// Recovery: if focus is currently OUTSIDE the container, warp it
|
|
171
167
|
// back to the first focusable. Without this, an escaped focus
|
|
@@ -185,12 +181,12 @@ function useFocusTrap(ref, isActive) {
|
|
|
185
181
|
}
|
|
186
182
|
};
|
|
187
183
|
document.addEventListener("keydown", trap, true);
|
|
188
|
-
return
|
|
184
|
+
return () => {
|
|
189
185
|
cancelAnimationFrame(rafId);
|
|
190
186
|
|
|
191
187
|
// Pop by reference (NOT by index) — tolerates out-of-order
|
|
192
188
|
// unmount sequences during portal teardown or hot-replace.
|
|
193
|
-
|
|
189
|
+
const idx = trapStack.lastIndexOf(container);
|
|
194
190
|
if (idx >= 0) trapStack.splice(idx, 1);
|
|
195
191
|
document.removeEventListener("keydown", trap, true);
|
|
196
192
|
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"useFocusTrap.js","names":["_react","require","FOCUSABLE_SELECTORS","join","AUTOFOCUS_SELECTORS","trapStack","isInnermostTrap","container","some","other","contains","isVisuallyFocusable","el","disabled","getAttribute","getClientRects","length","node","document","body","hasAttribute","parentElement","useFocusTrap","ref","isActive","useEffect","current","undefined","push","getFocusable","Array","from","querySelectorAll","filter","trigger","activeElement","rafId","requestAnimationFrame","explicit","querySelector","target","focus","trap","e","key","els","preventDefault","first","last","active","shiftKey","addEventListener","cancelAnimationFrame","idx","lastIndexOf","splice","removeEventListener"],"sources":["../../../src/lib/v2/hooks/useFocusTrap.ts"],"sourcesContent":["import { useEffect, type RefObject } from \"react\";\r\n\r\n/**\r\n * useFocusTrap — Portnet UI v2\r\n *\r\n * Traps Tab / Shift+Tab inside `ref` while `isActive`.\r\n * On activation, focuses the first `[autofocus]` / `[data-autofocus]`\r\n * descendant if present, otherwise the first focusable child.\r\n * On deactivation, restores focus to the element that previously held\r\n * it (only if still in the DOM).\r\n *\r\n * WCAG 2.4.3, charter R-F.2.\r\n *\r\n * Implementation notes\r\n * - Keydown listener attached to `document` in capture phase. If\r\n * focus has somehow escaped the container, the next Tab is caught\r\n * and warped back inside.\r\n * - NESTED TRAPS — only the topmost trap on `trapStack` intercepts\r\n * Tab. Outer traps stay registered and resume duty when the inner\r\n * trap unmounts. This makes ConfirmDialog-in-Drawer-in-Modal\r\n * flows behave correctly.\r\n * - Focusable elements are filtered to exclude those inside\r\n * aria-hidden / inert / hidden / display:none subtrees, even\r\n * though querySelectorAll happily returns them.\r\n * - BOUNDARY SCOPE — Tab is intercepted only at the cycle edges\r\n * (Tab on `last`, Shift+Tab on `first`) plus the escaped-focus\r\n * recovery path. Mid-cycle moves are deliberately left to the\r\n * browser's native tab order.\r\n *\r\n * Consequence worth knowing: the filter above decides what counts\r\n * as `first` / `last`, so the trap never DELIVERS focus into a\r\n * filtered element — but it cannot stop the browser tabbing into\r\n * one mid-cycle. `hidden` and `inert` are unaffected (both remove\r\n * an element from the native tab order); `aria-hidden` is NOT, as\r\n * per spec it annotates only the accessibility tree. So a\r\n * focusable control inside `aria-hidden=\"true\"` IS still reachable\r\n * by Tab — that is a content defect (axe `aria-hidden-focus`), and\r\n * the fix is `inert` on the subtree, not more interception here.\r\n *\r\n * Full per-Tab interception would close that gap, at the cost of\r\n * taking over native traversal for every Modal / Drawer /\r\n * ConfirmDialog in the fleet — which also breaks radio-group\r\n * roving tabindex and any positive `tabindex` ordering. Not done\r\n * without a browser-level test bed. See the aria-hidden case in\r\n * __tests__/useFocusTrap.test.tsx.\r\n * - Cleanup never calls focus() on an unmounted or detached\r\n * trigger and cancels the initial-focus rAF.\r\n *\r\n * Escape handling is INTENTIONALLY OUT OF SCOPE — the consumer (Modal,\r\n * Drawer, ConfirmDialog) is responsible for closing on Escape per\r\n * R-F.1. Mixing concerns here would force every trap user to opt out.\r\n *\r\n * @param ref The container ref to trap focus inside. Accepts a\r\n * nullable `current` (`RefObject<T | null>`) so callers\r\n * can pass `useRef<HTMLElement>(null)` directly without a\r\n * cast — the effect no-ops until `current` is populated.\r\n * @param isActive Whether the trap is currently on.\r\n */\r\n\r\nconst FOCUSABLE_SELECTORS = [\r\n \"a[href]\",\r\n \"button:not(:disabled)\",\r\n \"input:not(:disabled)\",\r\n \"select:not(:disabled)\",\r\n \"textarea:not(:disabled)\",\r\n '[tabindex]:not([tabindex=\"-1\"])',\r\n '[contenteditable]:not([contenteditable=\"false\"])',\r\n \"audio[controls]\",\r\n \"video[controls]\",\r\n].join(\", \");\r\n\r\nconst AUTOFOCUS_SELECTORS = \"[autofocus], [data-autofocus]\";\r\n\r\n/**\r\n * Module-level stack of active trap containers. Only the LAST entry\r\n * (innermost trap) intercepts Tab; outer traps stay registered but\r\n * pass-through. Cleanup pops by reference to tolerate out-of-order\r\n * unmount sequences (portal teardown, hot-replace).\r\n */\r\nconst trapStack: HTMLElement[] = [];\r\n\r\n/**\r\n * Is `container` the INNERMOST active trap?\r\n *\r\n * ⚠ DO NOT REPLACE THIS WITH `trapStack[trapStack.length - 1] === container`.\r\n *\r\n * Stack POSITION does not track nesting depth. React runs CHILD effects before\r\n * PARENT effects, so when an outer and an inner trap mount in the SAME commit\r\n * (Modal rendering a ConfirmDialog, Drawer with a nested trap) the INNER trap is\r\n * pushed FIRST and the OUTER one LAST — making the last entry the OUTERMOST trap,\r\n * the exact opposite of the intent.\r\n *\r\n * Push order only happens to match nesting when the traps mount at different\r\n * times, which is the common case and why the bug stayed hidden. The\r\n * simultaneous-mount path gave Tab duty to the trap BEHIND the dialog the user\r\n * was looking at (R-M.2 / R-F.2).\r\n *\r\n * Containment is order-independent: a trap is innermost when no other active\r\n * trap lives inside it. Correct for both mount orderings, and for unmount — once\r\n * the inner trap pops, the outer contains nothing and resumes duty.\r\n */\r\nfunction isInnermostTrap(container: HTMLElement): boolean {\r\n return !trapStack.some(\r\n (other) => other !== container && container.contains(other)\r\n );\r\n}\r\n\r\n/**\r\n * True iff the element is rendered AND not inside an aria-hidden /\r\n * inert / hidden / display:none ancestor. querySelectorAll picks\r\n * those up indiscriminately, so re-filter at use time.\r\n */\r\nfunction isVisuallyFocusable(el: Element | null): el is HTMLElement {\r\n if (!el) return false;\r\n if (\"disabled\" in el && el.disabled) return false;\r\n if (el.getAttribute && el.getAttribute(\"aria-disabled\") === \"true\") return false;\r\n // Cheap visibility test — covers display:none and visibility:hidden.\r\n // Note: elements with `display: contents` may report 0 rects but have\r\n // focusable descendants; the descendants themselves still match if\r\n // they have their own boxes, so this filter is a reasonable trade-off.\r\n if (typeof el.getClientRects === \"function\" && el.getClientRects().length === 0) {\r\n return false;\r\n }\r\n // Walk ancestors for hidden / aria-hidden / inert.\r\n let node: Element | null = el;\r\n while (node && node !== document.body) {\r\n if (node.hasAttribute && (\r\n node.hasAttribute(\"inert\") ||\r\n node.hasAttribute(\"hidden\") ||\r\n node.getAttribute(\"aria-hidden\") === \"true\"\r\n )) {\r\n return false;\r\n }\r\n node = node.parentElement;\r\n }\r\n return true;\r\n}\r\n\r\nexport default function useFocusTrap<T extends HTMLElement = HTMLElement>(\r\n ref: RefObject<T | null>,\r\n isActive: boolean\r\n): void {\r\n useEffect(() => {\r\n if (!isActive || !ref.current) return undefined;\r\n\r\n const container = ref.current;\r\n trapStack.push(container);\r\n\r\n const getFocusable = (): HTMLElement[] =>\r\n Array.from(container.querySelectorAll(FOCUSABLE_SELECTORS)).filter(isVisuallyFocusable);\r\n\r\n const trigger = document.activeElement;\r\n\r\n // Initial focus, deferred to next frame so React has finished\r\n // painting any conditional content. Cancellation handle stored\r\n // so unmount-within-same-frame cannot leak a stale .focus() call.\r\n const rafId = requestAnimationFrame(() => {\r\n /* Only the innermost trap claims initial focus — same predicate as `trap()`\r\n * below, so keyboard duty and initial focus can never disagree.\r\n *\r\n * Initial focus was previously unguarded: every trap focused on\r\n * activation regardless of nesting, so on simultaneous mount the outer\r\n * trap's rAF fired last and overwrote the inner trap's focus. */\r\n if (!isInnermostTrap(container)) return;\r\n\r\n const explicit = container.querySelector(AUTOFOCUS_SELECTORS);\r\n const target = (explicit && isVisuallyFocusable(explicit))\r\n ? explicit\r\n : getFocusable()[0];\r\n if (target && typeof target.focus === \"function\") target.focus();\r\n });\r\n\r\n const trap = (e: KeyboardEvent): void => {\r\n if (e.key !== \"Tab\") return;\r\n // Only the innermost trap acts. Outer traps stay registered and defer.\r\n // Containment, NOT stack position — see isInnermostTrap.\r\n if (!isInnermostTrap(container)) return;\r\n\r\n const els = getFocusable();\r\n if (!els.length) {\r\n // Pathological case (no focusable inside): swallow Tab so\r\n // focus cannot escape into the page behind the trap.\r\n e.preventDefault();\r\n return;\r\n }\r\n const first = els[0];\r\n const last = els[els.length - 1];\r\n if (!first || !last) return;\r\n const active = document.activeElement;\r\n\r\n // Recovery: if focus is currently OUTSIDE the container, warp it\r\n // back to the first focusable. Without this, an escaped focus\r\n // (mount race, programmatic blur, SR virtual cursor) leaks Tab\r\n // navigation to the page behind the trap.\r\n if (!container.contains(active)) {\r\n e.preventDefault();\r\n first.focus();\r\n return;\r\n }\r\n\r\n if (e.shiftKey && active === first) {\r\n e.preventDefault();\r\n last.focus();\r\n } else if (!e.shiftKey && active === last) {\r\n e.preventDefault();\r\n first.focus();\r\n }\r\n };\r\n\r\n document.addEventListener(\"keydown\", trap, true);\r\n\r\n return () => {\r\n cancelAnimationFrame(rafId);\r\n\r\n // Pop by reference (NOT by index) — tolerates out-of-order\r\n // unmount sequences during portal teardown or hot-replace.\r\n const idx = trapStack.lastIndexOf(container);\r\n if (idx >= 0) trapStack.splice(idx, 1);\r\n\r\n document.removeEventListener(\"keydown\", trap, true);\r\n\r\n // Restore focus only if the trigger is still mounted, focusable,\r\n // and not currently disabled. Calling .focus() on a detached or\r\n // disabled node silently leaves focus on <body> with no visible\r\n // indicator — actively user-hostile.\r\n if (\r\n trigger &&\r\n trigger !== document.body &&\r\n \"focus\" in trigger &&\r\n typeof trigger.focus === \"function\" &&\r\n document.body.contains(trigger) &&\r\n !(\"disabled\" in trigger && trigger.disabled)\r\n ) {\r\n trigger.focus();\r\n }\r\n };\r\n }, [isActive, ref]);\r\n}\r\n"],"mappings":";;;;;;AAAA,IAAAA,MAAA,GAAAC,OAAA;AAEA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;;AAEA,IAAMC,mBAAmB,GAAG,CAC1B,SAAS,EACT,uBAAuB,EACvB,sBAAsB,EACtB,uBAAuB,EACvB,yBAAyB,EACzB,iCAAiC,EACjC,kDAAkD,EAClD,iBAAiB,EACjB,iBAAiB,CAClB,CAACC,IAAI,CAAC,IAAI,CAAC;AAEZ,IAAMC,mBAAmB,GAAG,+BAA+B;;AAE3D;AACA;AACA;AACA;AACA;AACA;AACA,IAAMC,SAAwB,GAAG,EAAE;;AAEnC;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA,SAASC,eAAeA,CAACC,SAAsB,EAAW;EACxD,OAAO,CAACF,SAAS,CAACG,IAAI,CACpB,UAACC,KAAK;IAAA,OAAKA,KAAK,KAAKF,SAAS,IAAIA,SAAS,CAACG,QAAQ,CAACD,KAAK,CAAC;EAAA,CAC7D,CAAC;AACH;;AAEA;AACA;AACA;AACA;AACA;AACA,SAASE,mBAAmBA,CAACC,EAAkB,EAAqB;EAClE,IAAI,CAACA,EAAE,EAAE,OAAO,KAAK;EACrB,IAAI,UAAU,IAAIA,EAAE,IAAIA,EAAE,CAACC,QAAQ,EAAE,OAAO,KAAK;EACjD,IAAID,EAAE,CAACE,YAAY,IAAIF,EAAE,CAACE,YAAY,CAAC,eAAe,CAAC,KAAK,MAAM,EAAE,OAAO,KAAK;EAChF;EACA;EACA;EACA;EACA,IAAI,OAAOF,EAAE,CAACG,cAAc,KAAK,UAAU,IAAIH,EAAE,CAACG,cAAc,CAAC,CAAC,CAACC,M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","ignoreList":[]}
|
|
1
|
+
{"version":3,"file":"useFocusTrap.js","names":["_react","require","FOCUSABLE_SELECTORS","join","AUTOFOCUS_SELECTORS","trapStack","isInnermostTrap","container","some","other","contains","isVisuallyFocusable","el","disabled","getAttribute","getClientRects","length","node","document","body","hasAttribute","parentElement","useFocusTrap","ref","isActive","useEffect","current","undefined","push","getFocusable","Array","from","querySelectorAll","filter","trigger","activeElement","rafId","requestAnimationFrame","explicit","querySelector","target","focus","trap","e","key","els","preventDefault","first","last","active","shiftKey","addEventListener","cancelAnimationFrame","idx","lastIndexOf","splice","removeEventListener"],"sources":["../../../src/lib/v2/hooks/useFocusTrap.ts"],"sourcesContent":["import { useEffect, type RefObject } from \"react\";\r\n\r\n/**\r\n * useFocusTrap — Portnet UI v2\r\n *\r\n * Traps Tab / Shift+Tab inside `ref` while `isActive`.\r\n * On activation, focuses the first `[autofocus]` / `[data-autofocus]`\r\n * descendant if present, otherwise the first focusable child.\r\n * On deactivation, restores focus to the element that previously held\r\n * it (only if still in the DOM).\r\n *\r\n * WCAG 2.4.3, charter R-F.2.\r\n *\r\n * Implementation notes\r\n * - Keydown listener attached to `document` in capture phase. If\r\n * focus has somehow escaped the container, the next Tab is caught\r\n * and warped back inside.\r\n * - NESTED TRAPS — only the topmost trap on `trapStack` intercepts\r\n * Tab. Outer traps stay registered and resume duty when the inner\r\n * trap unmounts. This makes ConfirmDialog-in-Drawer-in-Modal\r\n * flows behave correctly.\r\n * - Focusable elements are filtered to exclude those inside\r\n * aria-hidden / inert / hidden / display:none subtrees, even\r\n * though querySelectorAll happily returns them.\r\n * - BOUNDARY SCOPE — Tab is intercepted only at the cycle edges\r\n * (Tab on `last`, Shift+Tab on `first`) plus the escaped-focus\r\n * recovery path. Mid-cycle moves are deliberately left to the\r\n * browser's native tab order.\r\n *\r\n * Consequence worth knowing: the filter above decides what counts\r\n * as `first` / `last`, so the trap never DELIVERS focus into a\r\n * filtered element — but it cannot stop the browser tabbing into\r\n * one mid-cycle. `hidden` and `inert` are unaffected (both remove\r\n * an element from the native tab order); `aria-hidden` is NOT, as\r\n * per spec it annotates only the accessibility tree. So a\r\n * focusable control inside `aria-hidden=\"true\"` IS still reachable\r\n * by Tab — that is a content defect (axe `aria-hidden-focus`), and\r\n * the fix is `inert` on the subtree, not more interception here.\r\n *\r\n * Full per-Tab interception would close that gap, at the cost of\r\n * taking over native traversal for every Modal / Drawer /\r\n * ConfirmDialog in the fleet — which also breaks radio-group\r\n * roving tabindex and any positive `tabindex` ordering. Not done\r\n * without a browser-level test bed. See the aria-hidden case in\r\n * __tests__/useFocusTrap.test.tsx.\r\n * - Cleanup never calls focus() on an unmounted or detached\r\n * trigger and cancels the initial-focus rAF.\r\n *\r\n * Escape handling is INTENTIONALLY OUT OF SCOPE — the consumer (Modal,\r\n * Drawer, ConfirmDialog) is responsible for closing on Escape per\r\n * R-F.1. Mixing concerns here would force every trap user to opt out.\r\n *\r\n * @param ref The container ref to trap focus inside. Accepts a\r\n * nullable `current` (`RefObject<T | null>`) so callers\r\n * can pass `useRef<HTMLElement>(null)` directly without a\r\n * cast — the effect no-ops until `current` is populated.\r\n * @param isActive Whether the trap is currently on.\r\n */\r\n\r\nconst FOCUSABLE_SELECTORS = [\r\n \"a[href]\",\r\n \"button:not(:disabled)\",\r\n \"input:not(:disabled)\",\r\n \"select:not(:disabled)\",\r\n \"textarea:not(:disabled)\",\r\n '[tabindex]:not([tabindex=\"-1\"])',\r\n '[contenteditable]:not([contenteditable=\"false\"])',\r\n \"audio[controls]\",\r\n \"video[controls]\",\r\n].join(\", \");\r\n\r\nconst AUTOFOCUS_SELECTORS = \"[autofocus], [data-autofocus]\";\r\n\r\n/**\r\n * Module-level stack of active trap containers. Only the LAST entry\r\n * (innermost trap) intercepts Tab; outer traps stay registered but\r\n * pass-through. Cleanup pops by reference to tolerate out-of-order\r\n * unmount sequences (portal teardown, hot-replace).\r\n */\r\nconst trapStack: HTMLElement[] = [];\r\n\r\n/**\r\n * Is `container` the INNERMOST active trap?\r\n *\r\n * ⚠ DO NOT REPLACE THIS WITH `trapStack[trapStack.length - 1] === container`.\r\n *\r\n * Stack POSITION does not track nesting depth. React runs CHILD effects before\r\n * PARENT effects, so when an outer and an inner trap mount in the SAME commit\r\n * (Modal rendering a ConfirmDialog, Drawer with a nested trap) the INNER trap is\r\n * pushed FIRST and the OUTER one LAST — making the last entry the OUTERMOST trap,\r\n * the exact opposite of the intent.\r\n *\r\n * Push order only happens to match nesting when the traps mount at different\r\n * times, which is the common case and why the bug stayed hidden. The\r\n * simultaneous-mount path gave Tab duty to the trap BEHIND the dialog the user\r\n * was looking at (R-M.2 / R-F.2).\r\n *\r\n * Containment is order-independent: a trap is innermost when no other active\r\n * trap lives inside it. Correct for both mount orderings, and for unmount — once\r\n * the inner trap pops, the outer contains nothing and resumes duty.\r\n */\r\nfunction isInnermostTrap(container: HTMLElement): boolean {\r\n return !trapStack.some(\r\n (other) => other !== container && container.contains(other)\r\n );\r\n}\r\n\r\n/**\r\n * True iff the element is rendered AND not inside an aria-hidden /\r\n * inert / hidden / display:none ancestor. querySelectorAll picks\r\n * those up indiscriminately, so re-filter at use time.\r\n */\r\nfunction isVisuallyFocusable(el: Element | null): el is HTMLElement {\r\n if (!el) return false;\r\n if (\"disabled\" in el && el.disabled) return false;\r\n if (el.getAttribute && el.getAttribute(\"aria-disabled\") === \"true\") return false;\r\n // Cheap visibility test — covers display:none and visibility:hidden.\r\n // Note: elements with `display: contents` may report 0 rects but have\r\n // focusable descendants; the descendants themselves still match if\r\n // they have their own boxes, so this filter is a reasonable trade-off.\r\n if (typeof el.getClientRects === \"function\" && el.getClientRects().length === 0) {\r\n return false;\r\n }\r\n // Walk ancestors for hidden / aria-hidden / inert.\r\n let node: Element | null = el;\r\n while (node && node !== document.body) {\r\n if (node.hasAttribute && (\r\n node.hasAttribute(\"inert\") ||\r\n node.hasAttribute(\"hidden\") ||\r\n node.getAttribute(\"aria-hidden\") === \"true\"\r\n )) {\r\n return false;\r\n }\r\n node = node.parentElement;\r\n }\r\n return true;\r\n}\r\n\r\nexport default function useFocusTrap<T extends HTMLElement = HTMLElement>(\r\n ref: RefObject<T | null>,\r\n isActive: boolean\r\n): void {\r\n useEffect(() => {\r\n if (!isActive || !ref.current) return undefined;\r\n\r\n const container = ref.current;\r\n trapStack.push(container);\r\n\r\n const getFocusable = (): HTMLElement[] =>\r\n Array.from(container.querySelectorAll(FOCUSABLE_SELECTORS)).filter(isVisuallyFocusable);\r\n\r\n const trigger = document.activeElement;\r\n\r\n // Initial focus, deferred to next frame so React has finished\r\n // painting any conditional content. Cancellation handle stored\r\n // so unmount-within-same-frame cannot leak a stale .focus() call.\r\n const rafId = requestAnimationFrame(() => {\r\n /* Only the innermost trap claims initial focus — same predicate as `trap()`\r\n * below, so keyboard duty and initial focus can never disagree.\r\n *\r\n * Initial focus was previously unguarded: every trap focused on\r\n * activation regardless of nesting, so on simultaneous mount the outer\r\n * trap's rAF fired last and overwrote the inner trap's focus. */\r\n if (!isInnermostTrap(container)) return;\r\n\r\n const explicit = container.querySelector(AUTOFOCUS_SELECTORS);\r\n const target = (explicit && isVisuallyFocusable(explicit))\r\n ? explicit\r\n : getFocusable()[0];\r\n if (target && typeof target.focus === \"function\") target.focus();\r\n });\r\n\r\n const trap = (e: KeyboardEvent): void => {\r\n if (e.key !== \"Tab\") return;\r\n // Only the innermost trap acts. Outer traps stay registered and defer.\r\n // Containment, NOT stack position — see isInnermostTrap.\r\n if (!isInnermostTrap(container)) return;\r\n\r\n const els = getFocusable();\r\n if (!els.length) {\r\n // Pathological case (no focusable inside): swallow Tab so\r\n // focus cannot escape into the page behind the trap.\r\n e.preventDefault();\r\n return;\r\n }\r\n const first = els[0];\r\n const last = els[els.length - 1];\r\n if (!first || !last) return;\r\n const active = document.activeElement;\r\n\r\n // Recovery: if focus is currently OUTSIDE the container, warp it\r\n // back to the first focusable. Without this, an escaped focus\r\n // (mount race, programmatic blur, SR virtual cursor) leaks Tab\r\n // navigation to the page behind the trap.\r\n if (!container.contains(active)) {\r\n e.preventDefault();\r\n first.focus();\r\n return;\r\n }\r\n\r\n if (e.shiftKey && active === first) {\r\n e.preventDefault();\r\n last.focus();\r\n } else if (!e.shiftKey && active === last) {\r\n e.preventDefault();\r\n first.focus();\r\n }\r\n };\r\n\r\n document.addEventListener(\"keydown\", trap, true);\r\n\r\n return () => {\r\n cancelAnimationFrame(rafId);\r\n\r\n // Pop by reference (NOT by index) — tolerates out-of-order\r\n // unmount sequences during portal teardown or hot-replace.\r\n const idx = trapStack.lastIndexOf(container);\r\n if (idx >= 0) trapStack.splice(idx, 1);\r\n\r\n document.removeEventListener(\"keydown\", trap, true);\r\n\r\n // Restore focus only if the trigger is still mounted, focusable,\r\n // and not currently disabled. Calling .focus() on a detached or\r\n // disabled node silently leaves focus on <body> with no visible\r\n // indicator — actively user-hostile.\r\n if (\r\n trigger &&\r\n trigger !== document.body &&\r\n \"focus\" in trigger &&\r\n typeof trigger.focus === \"function\" &&\r\n document.body.contains(trigger) &&\r\n !(\"disabled\" in trigger && trigger.disabled)\r\n ) {\r\n trigger.focus();\r\n }\r\n };\r\n }, [isActive, ref]);\r\n}\r\n"],"mappings":";;;;;;AAAA,IAAAA,MAAA,GAAAC,OAAA;AAEA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;;AAEA,MAAMC,mBAAmB,GAAG,CAC1B,SAAS,EACT,uBAAuB,EACvB,sBAAsB,EACtB,uBAAuB,EACvB,yBAAyB,EACzB,iCAAiC,EACjC,kDAAkD,EAClD,iBAAiB,EACjB,iBAAiB,CAClB,CAACC,IAAI,CAAC,IAAI,CAAC;AAEZ,MAAMC,mBAAmB,GAAG,+BAA+B;;AAE3D;AACA;AACA;AACA;AACA;AACA;AACA,MAAMC,SAAwB,GAAG,EAAE;;AAEnC;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA,SAASC,eAAeA,CAACC,SAAsB,EAAW;EACxD,OAAO,CAACF,SAAS,CAACG,IAAI,CACnBC,KAAK,IAAKA,KAAK,KAAKF,SAAS,IAAIA,SAAS,CAACG,QAAQ,CAACD,KAAK,CAC5D,CAAC;AACH;;AAEA;AACA;AACA;AACA;AACA;AACA,SAASE,mBAAmBA,CAACC,EAAkB,EAAqB;EAClE,IAAI,CAACA,EAAE,EAAE,OAAO,KAAK;EACrB,IAAI,UAAU,IAAIA,EAAE,IAAIA,EAAE,CAACC,QAAQ,EAAE,OAAO,KAAK;EACjD,IAAID,EAAE,CAACE,YAAY,IAAIF,EAAE,CAACE,YAAY,CAAC,eAAe,CAAC,KAAK,MAAM,EAAE,OAAO,KAAK;EAChF;EACA;EACA;EACA;EACA,IAAI,OAAOF,EAAE,CAACG,cAAc,KAAK,UAAU,IAAIH,EAAE,CAACG,cAAc,CAAC,CAAC,CAACC,MAAM,KAAK,CAAC,EAAE;I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","ignoreList":[]}
|
|
@@ -26,10 +26,10 @@ type FormAutoSaveOptions<Values> = {
|
|
|
26
26
|
storageKey: string;
|
|
27
27
|
values: Values;
|
|
28
28
|
/** Required if you call restoreDraft(). */
|
|
29
|
-
setValues?: (values: Values) => void;
|
|
30
|
-
enabled?: boolean;
|
|
31
|
-
debounceMs?: number;
|
|
32
|
-
initialEmptyCheck?: (values: Values) => boolean;
|
|
29
|
+
setValues?: ((values: Values) => void) | undefined;
|
|
30
|
+
enabled?: boolean | undefined;
|
|
31
|
+
debounceMs?: number | undefined;
|
|
32
|
+
initialEmptyCheck?: ((values: Values) => boolean) | undefined;
|
|
33
33
|
};
|
|
34
34
|
type FormAutoSaveResult = {
|
|
35
35
|
hasDraft: boolean;
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"useFormAutoSave.d.ts","sourceRoot":"","sources":["../../../src/lib/v2/hooks/useFormAutoSave.ts"],"names":[],"mappings":"AAEA;;;;;;;;;;;;;;;;;;;;;;;GAuBG;AAEH,KAAK,mBAAmB,CAAC,MAAM,IAAI;IACjC,UAAU,EAAE,MAAM,CAAC;IACnB,MAAM,EAAE,MAAM,CAAC;IACf,2CAA2C;IAC3C,SAAS,CAAC,EAAE,CAAC,MAAM,EAAE,MAAM,KAAK,IAAI,CAAC;
|
|
1
|
+
{"version":3,"file":"useFormAutoSave.d.ts","sourceRoot":"","sources":["../../../src/lib/v2/hooks/useFormAutoSave.ts"],"names":[],"mappings":"AAEA;;;;;;;;;;;;;;;;;;;;;;;GAuBG;AAEH,KAAK,mBAAmB,CAAC,MAAM,IAAI;IACjC,UAAU,EAAE,MAAM,CAAC;IACnB,MAAM,EAAE,MAAM,CAAC;IACf,2CAA2C;IAC3C,SAAS,CAAC,EAAE,CAAC,CAAC,MAAM,EAAE,MAAM,KAAK,IAAI,CAAC,GAAG,SAAS,CAAC;IACnD,OAAO,CAAC,EAAE,OAAO,GAAG,SAAS,CAAC;IAC9B,UAAU,CAAC,EAAE,MAAM,GAAG,SAAS,CAAC;IAChC,iBAAiB,CAAC,EAAE,CAAC,CAAC,MAAM,EAAE,MAAM,KAAK,OAAO,CAAC,GAAG,SAAS,CAAC;CAC/D,CAAC;AAEF,KAAK,kBAAkB,GAAG;IACxB,QAAQ,EAAE,OAAO,CAAC;IAClB,WAAW,EAAE,IAAI,GAAG,IAAI,CAAC;IACzB,YAAY,EAAE,MAAM,OAAO,CAAC;IAC5B,UAAU,EAAE,MAAM,IAAI,CAAC;CACxB,CAAC;AAEF,MAAM,CAAC,OAAO,UAAU,eAAe,CAAC,MAAM,EAAE,EAC9C,UAAU,EACV,MAAM,EACN,SAAS,EACT,OAAc,EACd,UAAgB,EAChB,iBAAqC,GACtC,EAAE,mBAAmB,CAAC,MAAM,CAAC,GAAG,kBAAkB,CA+HlD"}
|
|
@@ -3,15 +3,8 @@
|
|
|
3
3
|
Object.defineProperty(exports, "__esModule", {
|
|
4
4
|
value: true
|
|
5
5
|
});
|
|
6
|
-
exports
|
|
6
|
+
exports.default = useFormAutoSave;
|
|
7
7
|
var _react = require("react");
|
|
8
|
-
function _typeof(obj) { "@babel/helpers - typeof"; return _typeof = "function" == typeof Symbol && "symbol" == typeof Symbol.iterator ? function (obj) { return typeof obj; } : function (obj) { return obj && "function" == typeof Symbol && obj.constructor === Symbol && obj !== Symbol.prototype ? "symbol" : typeof obj; }, _typeof(obj); }
|
|
9
|
-
function _slicedToArray(arr, i) { return _arrayWithHoles(arr) || _iterableToArrayLimit(arr, i) || _unsupportedIterableToArray(arr, i) || _nonIterableRest(); }
|
|
10
|
-
function _nonIterableRest() { throw new TypeError("Invalid attempt to destructure non-iterable instance.\nIn order to be iterable, non-array objects must have a [Symbol.iterator]() method."); }
|
|
11
|
-
function _unsupportedIterableToArray(o, minLen) { if (!o) return; if (typeof o === "string") return _arrayLikeToArray(o, minLen); var n = Object.prototype.toString.call(o).slice(8, -1); if (n === "Object" && o.constructor) n = o.constructor.name; if (n === "Map" || n === "Set") return Array.from(o); if (n === "Arguments" || /^(?:Ui|I)nt(?:8|16|32)(?:Clamped)?Array$/.test(n)) return _arrayLikeToArray(o, minLen); }
|
|
12
|
-
function _arrayLikeToArray(arr, len) { if (len == null || len > arr.length) len = arr.length; for (var i = 0, arr2 = new Array(len); i < len; i++) { arr2[i] = arr[i]; } return arr2; }
|
|
13
|
-
function _iterableToArrayLimit(arr, i) { var _i = null == arr ? null : "undefined" != typeof Symbol && arr[Symbol.iterator] || arr["@@iterator"]; if (null != _i) { var _s, _e, _x, _r, _arr = [], _n = !0, _d = !1; try { if (_x = (_i = _i.call(arr)).next, 0 === i) { if (Object(_i) !== _i) return; _n = !1; } else for (; !(_n = (_s = _x.call(_i)).done) && (_arr.push(_s.value), _arr.length !== i); _n = !0) { ; } } catch (err) { _d = !0, _e = err; } finally { try { if (!_n && null != _i["return"] && (_r = _i["return"](), Object(_r) !== _r)) return; } finally { if (_d) throw _e; } } return _arr; } }
|
|
14
|
-
function _arrayWithHoles(arr) { if (Array.isArray(arr)) return arr; }
|
|
15
8
|
/**
|
|
16
9
|
* useFormAutoSave — persist Formik (or any form) values to
|
|
17
10
|
* localStorage with debounced writes, and expose draft-restore
|
|
@@ -37,49 +30,41 @@ function _arrayWithHoles(arr) { if (Array.isArray(arr)) return arr; }
|
|
|
37
30
|
* with empty initial values before the user decides to restore/ignore.
|
|
38
31
|
*/
|
|
39
32
|
|
|
40
|
-
function useFormAutoSave(
|
|
41
|
-
|
|
42
|
-
|
|
43
|
-
|
|
44
|
-
|
|
45
|
-
|
|
46
|
-
|
|
47
|
-
|
|
48
|
-
|
|
49
|
-
|
|
50
|
-
|
|
51
|
-
|
|
52
|
-
hasDraft = _useState2[0],
|
|
53
|
-
setHasDraft = _useState2[1];
|
|
54
|
-
var _useState3 = (0, _react.useState)(null),
|
|
55
|
-
_useState4 = _slicedToArray(_useState3, 2),
|
|
56
|
-
lastSavedAt = _useState4[0],
|
|
57
|
-
setLastSavedAt = _useState4[1];
|
|
58
|
-
var debounceTimerRef = (0, _react.useRef)(null);
|
|
59
|
-
var mountedRef = (0, _react.useRef)(false);
|
|
33
|
+
function useFormAutoSave({
|
|
34
|
+
storageKey,
|
|
35
|
+
values,
|
|
36
|
+
setValues,
|
|
37
|
+
enabled = true,
|
|
38
|
+
debounceMs = 800,
|
|
39
|
+
initialEmptyCheck = defaultEmptyCheck
|
|
40
|
+
}) {
|
|
41
|
+
const [hasDraft, setHasDraft] = (0, _react.useState)(false);
|
|
42
|
+
const [lastSavedAt, setLastSavedAt] = (0, _react.useState)(null);
|
|
43
|
+
const debounceTimerRef = (0, _react.useRef)(null);
|
|
44
|
+
const mountedRef = (0, _react.useRef)(false);
|
|
60
45
|
|
|
61
46
|
/* ── Mount-time draft detection ────────────────── */
|
|
62
|
-
(0, _react.useEffect)(
|
|
47
|
+
(0, _react.useEffect)(() => {
|
|
63
48
|
if (!enabled) return;
|
|
64
49
|
if (mountedRef.current) return;
|
|
65
50
|
mountedRef.current = true;
|
|
66
51
|
try {
|
|
67
|
-
|
|
52
|
+
const raw = localStorage.getItem(storageKey);
|
|
68
53
|
if (!raw) return;
|
|
69
|
-
|
|
70
|
-
if (parsed &&
|
|
54
|
+
const parsed = JSON.parse(raw);
|
|
55
|
+
if (parsed && typeof parsed === "object" && "values" in parsed && parsed.values && typeof parsed.values === "object") {
|
|
71
56
|
setHasDraft(true);
|
|
72
57
|
if ("savedAt" in parsed && typeof parsed.savedAt === "string") {
|
|
73
|
-
|
|
58
|
+
const d = new Date(parsed.savedAt);
|
|
74
59
|
if (!Number.isNaN(d.getTime())) setLastSavedAt(d);
|
|
75
60
|
}
|
|
76
61
|
} else {
|
|
77
62
|
localStorage.removeItem(storageKey);
|
|
78
63
|
}
|
|
79
|
-
} catch
|
|
64
|
+
} catch {
|
|
80
65
|
try {
|
|
81
66
|
localStorage.removeItem(storageKey);
|
|
82
|
-
} catch
|
|
67
|
+
} catch {
|
|
83
68
|
/* ignore */
|
|
84
69
|
}
|
|
85
70
|
}
|
|
@@ -100,26 +85,26 @@ function useFormAutoSave(_ref) {
|
|
|
100
85
|
* - clearDraft() is called (user chose to ignore)
|
|
101
86
|
* - No draft existed on mount (hasDraft was never set to true)
|
|
102
87
|
*/
|
|
103
|
-
(0, _react.useEffect)(
|
|
88
|
+
(0, _react.useEffect)(() => {
|
|
104
89
|
if (!enabled) return undefined;
|
|
105
90
|
if (hasDraft) return undefined; // ← PAUSE: preserve existing draft
|
|
106
91
|
if (initialEmptyCheck(values)) return undefined;
|
|
107
92
|
if (debounceTimerRef.current) {
|
|
108
93
|
clearTimeout(debounceTimerRef.current);
|
|
109
94
|
}
|
|
110
|
-
debounceTimerRef.current = setTimeout(
|
|
95
|
+
debounceTimerRef.current = setTimeout(() => {
|
|
111
96
|
try {
|
|
112
|
-
|
|
97
|
+
const now = new Date();
|
|
113
98
|
localStorage.setItem(storageKey, JSON.stringify({
|
|
114
|
-
values
|
|
99
|
+
values,
|
|
115
100
|
savedAt: now.toISOString()
|
|
116
101
|
}));
|
|
117
102
|
setLastSavedAt(now);
|
|
118
|
-
} catch
|
|
103
|
+
} catch {
|
|
119
104
|
// Quota full / private mode — no-op.
|
|
120
105
|
}
|
|
121
106
|
}, debounceMs);
|
|
122
|
-
return
|
|
107
|
+
return () => {
|
|
123
108
|
if (debounceTimerRef.current) {
|
|
124
109
|
clearTimeout(debounceTimerRef.current);
|
|
125
110
|
}
|
|
@@ -127,7 +112,7 @@ function useFormAutoSave(_ref) {
|
|
|
127
112
|
}, [values, enabled, hasDraft, storageKey, debounceMs, initialEmptyCheck]);
|
|
128
113
|
|
|
129
114
|
/* ── Restore draft ─────────────────────── */
|
|
130
|
-
|
|
115
|
+
const restoreDraft = (0, _react.useCallback)(() => {
|
|
131
116
|
if (!setValues) {
|
|
132
117
|
if (process.env["NODE_ENV"] !== "production") {
|
|
133
118
|
// eslint-disable-next-line no-console
|
|
@@ -136,10 +121,10 @@ function useFormAutoSave(_ref) {
|
|
|
136
121
|
return false;
|
|
137
122
|
}
|
|
138
123
|
try {
|
|
139
|
-
|
|
124
|
+
const raw = localStorage.getItem(storageKey);
|
|
140
125
|
if (!raw) return false;
|
|
141
|
-
|
|
142
|
-
if (!parsed ||
|
|
126
|
+
const parsed = JSON.parse(raw);
|
|
127
|
+
if (!parsed || typeof parsed !== "object" || !("values" in parsed) || !parsed.values) {
|
|
143
128
|
return false;
|
|
144
129
|
}
|
|
145
130
|
// Persisted draft payload is the form's Values, round-tripped
|
|
@@ -147,26 +132,26 @@ function useFormAutoSave(_ref) {
|
|
|
147
132
|
setValues(parsed.values);
|
|
148
133
|
setHasDraft(false); // ← resumes auto-save with restored values
|
|
149
134
|
return true;
|
|
150
|
-
} catch
|
|
135
|
+
} catch {
|
|
151
136
|
return false;
|
|
152
137
|
}
|
|
153
138
|
}, [storageKey, setValues]);
|
|
154
139
|
|
|
155
140
|
/* ── Clear draft ─────────────────────── */
|
|
156
|
-
|
|
141
|
+
const clearDraft = (0, _react.useCallback)(() => {
|
|
157
142
|
try {
|
|
158
143
|
localStorage.removeItem(storageKey);
|
|
159
|
-
} catch
|
|
144
|
+
} catch {
|
|
160
145
|
/* ignore */
|
|
161
146
|
}
|
|
162
147
|
setHasDraft(false); // ← resumes auto-save for new input
|
|
163
148
|
setLastSavedAt(null);
|
|
164
149
|
}, [storageKey]);
|
|
165
150
|
return {
|
|
166
|
-
hasDraft
|
|
167
|
-
lastSavedAt
|
|
168
|
-
restoreDraft
|
|
169
|
-
clearDraft
|
|
151
|
+
hasDraft,
|
|
152
|
+
lastSavedAt,
|
|
153
|
+
restoreDraft,
|
|
154
|
+
clearDraft
|
|
170
155
|
};
|
|
171
156
|
}
|
|
172
157
|
|
|
@@ -176,11 +161,11 @@ function isEmptyValue(v) {
|
|
|
176
161
|
if (v === null || v === undefined) return true;
|
|
177
162
|
if (typeof v === "string") return v.trim().length === 0;
|
|
178
163
|
if (Array.isArray(v)) return v.length === 0;
|
|
179
|
-
if (
|
|
164
|
+
if (typeof v === "object") return Object.keys(v).length === 0;
|
|
180
165
|
return false;
|
|
181
166
|
}
|
|
182
167
|
function defaultEmptyCheck(values) {
|
|
183
|
-
if (!values ||
|
|
168
|
+
if (!values || typeof values !== "object") return true;
|
|
184
169
|
return Object.values(values).every(isEmptyValue);
|
|
185
170
|
}
|
|
186
171
|
//# sourceMappingURL=useFormAutoSave.js.map
|