@povio/ui 0.0.8 → 0.0.9
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/dist/assets/icons/AlignCenter.js +21 -0
- package/dist/assets/icons/AlignLeft.js +21 -0
- package/dist/assets/icons/AlignLeftRight.js +21 -0
- package/dist/assets/icons/AlignRight.js +21 -0
- package/dist/assets/icons/ArrowDropDown.js +21 -0
- package/dist/assets/icons/ArrowDropUp.js +21 -0
- package/dist/assets/icons/ArrowLeft.js +21 -0
- package/dist/assets/icons/ArrowRight.js +21 -0
- package/dist/assets/icons/Bold.js +21 -0
- package/dist/assets/icons/BulletedList.js +21 -0
- package/dist/assets/icons/Calendar.js +23 -0
- package/dist/assets/icons/Check.js +23 -0
- package/dist/assets/icons/CheckCircle.js +21 -0
- package/dist/assets/icons/CheckboxCheckmark.js +24 -0
- package/dist/assets/icons/CheckboxIndeterminate.js +24 -0
- package/dist/assets/icons/ChevronDown.js +23 -0
- package/dist/assets/icons/ChevronLeft.js +23 -0
- package/dist/assets/icons/ChevronRight.js +23 -0
- package/dist/assets/icons/ChevronUp.js +23 -0
- package/dist/assets/icons/ChevronsLeft.js +23 -0
- package/dist/assets/icons/ChevronsRight.js +23 -0
- package/dist/assets/icons/Clock.js +21 -0
- package/dist/assets/icons/Close.js +21 -0
- package/dist/assets/icons/DateTime.js +32 -0
- package/dist/assets/icons/Drag.js +21 -0
- package/dist/assets/icons/File.js +23 -0
- package/dist/assets/icons/Highlight.js +21 -0
- package/dist/assets/icons/HighlightOn.js +30 -0
- package/dist/assets/icons/Info.js +32 -0
- package/dist/assets/icons/Italic.js +21 -0
- package/dist/assets/icons/Link.js +21 -0
- package/dist/assets/icons/Menu.js +21 -0
- package/dist/assets/icons/NumberedList.js +21 -0
- package/dist/assets/icons/PointerHorizontal.js +21 -0
- package/dist/assets/icons/PointerVertical.js +21 -0
- package/dist/assets/icons/Send.js +23 -0
- package/dist/assets/icons/Strikethrough.js +21 -0
- package/dist/assets/icons/TextColor.js +30 -0
- package/dist/assets/icons/Today.js +21 -0
- package/dist/assets/icons/Underlined.js +23 -0
- package/dist/assets/icons/Upload.js +30 -0
- package/dist/assets/icons/View.js +18 -0
- package/dist/assets/icons/ViewOff.js +18 -0
- package/dist/assets/icons/WarningFilled.js +23 -0
- package/dist/assets/locales/en/translation.json.js +14 -0
- package/dist/assets/locales/sl/translation.json.js +14 -0
- package/dist/components/Menu/Menu.js +14 -0
- package/{src → dist}/components/Menu/MenuDesktop.d.ts +1 -1
- package/dist/components/Menu/MenuDesktop.js +68 -0
- package/{src → dist}/components/Menu/MenuItem.d.ts +1 -1
- package/dist/components/Menu/MenuItem.js +33 -0
- package/{src → dist}/components/Menu/MenuMobile.d.ts +1 -1
- package/dist/components/Menu/MenuMobile.js +78 -0
- package/{src → dist}/components/Menu/MenuPopover.d.ts +1 -1
- package/dist/components/Menu/MenuPopover.js +38 -0
- package/{src → dist}/components/buttons/Button/Button.d.ts +1 -1
- package/dist/components/buttons/Button/Button.js +68 -0
- package/{src → dist}/components/buttons/Button/button.cva.d.ts +1 -1
- package/dist/components/buttons/Button/button.cva.js +672 -0
- package/{src → dist}/components/buttons/IconButton/IconButton.d.ts +1 -1
- package/dist/components/buttons/IconButton/IconButton.js +17 -0
- package/{src → dist}/components/buttons/InlineIconButton/InlineIconButton.d.ts +1 -1
- package/dist/components/buttons/InlineIconButton/InlineIconButton.js +18 -0
- package/{src → dist}/components/buttons/PillButton/PillButton.d.ts +2 -2
- package/dist/components/buttons/PillButton/PillButton.js +44 -0
- package/{src → dist}/components/buttons/PillButton/pillButton.cva.d.ts +1 -1
- package/dist/components/buttons/PillButton/pillButton.cva.js +86 -0
- package/{src → dist}/components/buttons/SplitButton/SplitButton.d.ts +2 -2
- package/dist/components/buttons/SplitButton/SplitButton.js +62 -0
- package/{src → dist}/components/buttons/TextButton/TextButton.d.ts +3 -3
- package/dist/components/buttons/TextButton/TextButton.js +18 -0
- package/{src → dist}/components/buttons/ToggleButton/ToggleButton.d.ts +3 -3
- package/dist/components/buttons/ToggleButton/ToggleButton.js +21 -0
- package/{src → dist}/components/buttons/shared/ButtonContent.d.ts +3 -3
- package/dist/components/buttons/shared/ButtonContent.js +53 -0
- package/dist/components/buttons/shared/buttonContent.cva.js +16 -0
- package/{src → dist}/components/inputs/Checkbox/Checkbox.d.ts +3 -3
- package/dist/components/inputs/Checkbox/Checkbox.js +81 -0
- package/{src → dist}/components/inputs/Checkbox/CheckboxCheckmark.d.ts +1 -1
- package/dist/components/inputs/Checkbox/CheckboxCheckmark.js +49 -0
- package/{src → dist}/components/inputs/Checkbox/checkbox.cva.d.ts +1 -1
- package/dist/components/inputs/Checkbox/checkbox.cva.js +47 -0
- package/{src → dist}/components/inputs/DateTime/DatePicker/DatePicker.d.ts +3 -3
- package/dist/components/inputs/DateTime/DatePicker/DatePicker.js +237 -0
- package/{src → dist}/components/inputs/DateTime/DateRangePicker/DateRangePicker.d.ts +3 -3
- package/dist/components/inputs/DateTime/DateRangePicker/DateRangePicker.js +674 -0
- package/{src → dist}/components/inputs/DateTime/DateTimePicker/DateTimePicker.d.ts +3 -3
- package/dist/components/inputs/DateTime/DateTimePicker/DateTimePicker.js +251 -0
- package/{src → dist}/components/inputs/DateTime/TimePicker/TimePicker.d.ts +3 -3
- package/dist/components/inputs/DateTime/TimePicker/TimePicker.js +224 -0
- package/dist/components/inputs/DateTime/shared/Calendar.js +85 -0
- package/dist/components/inputs/DateTime/shared/CalendarCell.js +160 -0
- package/dist/components/inputs/DateTime/shared/CalendarGrid.js +67 -0
- package/{src → dist}/components/inputs/DateTime/shared/CalendarHeader.d.ts +1 -1
- package/dist/components/inputs/DateTime/shared/CalendarHeader.js +89 -0
- package/dist/components/inputs/DateTime/shared/CalendarSelectHeader.js +203 -0
- package/dist/components/inputs/DateTime/shared/DateField.js +62 -0
- package/{src → dist}/components/inputs/DateTime/shared/DatePickerInput.d.ts +2 -2
- package/dist/components/inputs/DateTime/shared/DatePickerInput.js +174 -0
- package/dist/components/inputs/DateTime/shared/DateSegmentItem.js +55 -0
- package/dist/components/inputs/DateTime/shared/DateTimeDialog.js +76 -0
- package/dist/components/inputs/DateTime/shared/DateTimeDialogFooter.js +41 -0
- package/dist/components/inputs/DateTime/shared/MonthPicker.js +82 -0
- package/dist/components/inputs/DateTime/shared/RangeCalendar.js +131 -0
- package/dist/components/inputs/DateTime/shared/TimeField.js +26 -0
- package/dist/components/inputs/DateTime/shared/TimePickerForm.js +186 -0
- package/{src → dist}/components/inputs/DateTime/shared/TimePickerInput.d.ts +2 -2
- package/dist/components/inputs/DateTime/shared/TimePickerInput.js +114 -0
- package/dist/components/inputs/DateTime/shared/YearPicker.js +89 -0
- package/dist/components/inputs/File/FileUpload.js +254 -0
- package/dist/components/inputs/File/FileUploadContainer.js +17 -0
- package/dist/components/inputs/File/InputUpload.js +176 -0
- package/{src → dist}/components/inputs/File/fileUpload.types.d.ts +3 -3
- package/{src → dist}/components/inputs/File/inputUpload.types.d.ts +2 -2
- package/{src → dist}/components/inputs/File/shared/FileCard.d.ts +1 -1
- package/dist/components/inputs/File/shared/FileCard.js +67 -0
- package/{src → dist}/components/inputs/File/shared/FileCardList.d.ts +1 -1
- package/dist/components/inputs/File/shared/FileCardList.js +20 -0
- package/dist/components/inputs/File/shared/FileProgressBar.js +32 -0
- package/{src → dist}/components/inputs/File/shared/FileUploadContent.d.ts +1 -1
- package/dist/components/inputs/File/shared/FileUploadContent.js +92 -0
- package/{src → dist}/components/inputs/File/shared/FileUploadContentEmpty.d.ts +1 -1
- package/dist/components/inputs/File/shared/FileUploadContentEmpty.js +92 -0
- package/{src → dist}/components/inputs/File/shared/FileUploadContentError.d.ts +1 -1
- package/dist/components/inputs/File/shared/FileUploadContentError.js +167 -0
- package/{src → dist}/components/inputs/File/shared/FileUploadContentFilled.d.ts +1 -1
- package/dist/components/inputs/File/shared/FileUploadContentFilled.js +176 -0
- package/{src → dist}/components/inputs/File/shared/FileUploadContentLoading.d.ts +1 -1
- package/dist/components/inputs/File/shared/FileUploadContentLoading.js +128 -0
- package/{src → dist}/components/inputs/File/shared/InputUploadContent.d.ts +1 -1
- package/dist/components/inputs/File/shared/InputUploadContent.js +74 -0
- package/dist/components/inputs/File/shared/InputUploadFilled.js +45 -0
- package/dist/components/inputs/File/shared/fileUpload.cva.js +58 -0
- package/dist/components/inputs/File/shared/inputUploadButton.cva.js +49 -0
- package/{src → dist}/components/inputs/FormField/FormField.d.ts +3 -3
- package/dist/components/inputs/FormField/FormField.js +54 -0
- package/dist/components/inputs/FormField/FormFieldError.js +16 -0
- package/dist/components/inputs/FormField/FormFieldHeader.js +57 -0
- package/dist/components/inputs/FormField/FormFieldHeaderClose.js +20 -0
- package/{src → dist}/components/inputs/FormField/FormFieldLabel.d.ts +2 -2
- package/dist/components/inputs/FormField/FormFieldLabel.js +37 -0
- package/{src → dist}/components/inputs/Input/NumberInput/NumberInput.d.ts +4 -4
- package/dist/components/inputs/Input/NumberInput/NumberInput.js +157 -0
- package/{src → dist}/components/inputs/Input/PasswordInput/PasswordInput.d.ts +2 -2
- package/dist/components/inputs/Input/PasswordInput/PasswordInput.js +26 -0
- package/{src → dist}/components/inputs/Input/TextArea/TextArea.d.ts +3 -3
- package/dist/components/inputs/Input/TextArea/TextArea.js +146 -0
- package/{src → dist}/components/inputs/Input/TextInput/TextInput.d.ts +4 -4
- package/dist/components/inputs/Input/TextInput/TextInput.js +170 -0
- package/{src → dist}/components/inputs/Input/shared/InputContent.d.ts +3 -3
- package/dist/components/inputs/Input/shared/InputContent.js +114 -0
- package/{src → dist}/components/inputs/Inputs/Form.d.ts +2 -2
- package/dist/components/inputs/Inputs/Form.js +68 -0
- package/{src → dist}/components/inputs/Inputs/InputItem.d.ts +16 -16
- package/dist/components/inputs/Inputs/InputItem.js +63 -0
- package/dist/components/inputs/Inputs/Inputs.js +32 -0
- package/{src → dist}/components/inputs/RadioGroup/RadioGroup.d.ts +3 -3
- package/dist/components/inputs/RadioGroup/RadioGroup.js +113 -0
- package/{src → dist}/components/inputs/RadioGroup/radio.cva.d.ts +1 -1
- package/dist/components/inputs/RadioGroup/radio.cva.js +47 -0
- package/{src → dist}/components/inputs/Selection/Autocomplete/Autocomplete.d.ts +3 -3
- package/dist/components/inputs/Selection/Autocomplete/Autocomplete.js +39 -0
- package/{src → dist}/components/inputs/Selection/Autocomplete/QueryAutocomplete.d.ts +3 -3
- package/dist/components/inputs/Selection/Autocomplete/QueryAutocomplete.js +25 -0
- package/{src → dist}/components/inputs/Selection/Select/Select.d.ts +3 -3
- package/dist/components/inputs/Selection/Select/Select.js +32 -0
- package/{src → dist}/components/inputs/Selection/shared/SelectBase.d.ts +3 -3
- package/dist/components/inputs/Selection/shared/SelectBase.js +25 -0
- package/{src → dist}/components/inputs/Selection/shared/SelectDesktop.d.ts +1 -1
- package/dist/components/inputs/Selection/shared/SelectDesktop.js +211 -0
- package/{src → dist}/components/inputs/Selection/shared/SelectInput.d.ts +4 -4
- package/dist/components/inputs/Selection/shared/SelectInput.js +231 -0
- package/{src → dist}/components/inputs/Selection/shared/SelectInputTags.d.ts +2 -2
- package/dist/components/inputs/Selection/shared/SelectInputTags.js +22 -0
- package/{src → dist}/components/inputs/Selection/shared/SelectListBox.d.ts +2 -2
- package/dist/components/inputs/Selection/shared/SelectListBox.js +108 -0
- package/{src → dist}/components/inputs/Selection/shared/SelectListBoxItem.d.ts +2 -2
- package/dist/components/inputs/Selection/shared/SelectListBoxItem.js +78 -0
- package/{src → dist}/components/inputs/Selection/shared/SelectListBoxItemSelectAll.d.ts +1 -1
- package/dist/components/inputs/Selection/shared/SelectListBoxItemSelectAll.js +45 -0
- package/{src → dist}/components/inputs/Selection/shared/SelectListBoxLoadingItem.d.ts +1 -1
- package/dist/components/inputs/Selection/shared/SelectListBoxLoadingItem.js +47 -0
- package/dist/components/inputs/Selection/shared/SelectListBoxSelectionBar.js +42 -0
- package/{src → dist}/components/inputs/Selection/shared/SelectMobile.d.ts +1 -1
- package/dist/components/inputs/Selection/shared/SelectMobile.js +161 -0
- package/{src → dist}/components/inputs/Selection/shared/select.context.d.ts +2 -2
- package/dist/components/inputs/Selection/shared/select.context.js +244 -0
- package/{src → dist}/components/inputs/Selection/shared/select.types.d.ts +1 -1
- package/{src → dist}/components/inputs/Selection/shared/useSelectItems.d.ts +2 -2
- package/dist/components/inputs/Selection/shared/useSelectItems.js +94 -0
- package/{src → dist}/components/inputs/Slider/Slider.d.ts +2 -2
- package/dist/components/inputs/Slider/Slider.js +137 -0
- package/{src → dist}/components/inputs/TextEditor/TextEditor.d.ts +2 -2
- package/dist/components/inputs/TextEditor/TextEditor.js +223 -0
- package/dist/components/inputs/TextEditor/Toolbar/ColorPicker.js +34 -0
- package/dist/components/inputs/TextEditor/Toolbar/ColorPickerDropdown.js +80 -0
- package/{src → dist}/components/inputs/TextEditor/Toolbar/HyperlinkAction.d.ts +1 -1
- package/dist/components/inputs/TextEditor/Toolbar/HyperlinkAction.js +92 -0
- package/{src → dist}/components/inputs/TextEditor/Toolbar/TextAlignSelect.d.ts +1 -1
- package/dist/components/inputs/TextEditor/Toolbar/TextAlignSelect.js +56 -0
- package/{src → dist}/components/inputs/TextEditor/Toolbar/TextColorSelect.d.ts +1 -1
- package/dist/components/inputs/TextEditor/Toolbar/TextColorSelect.js +33 -0
- package/dist/components/inputs/TextEditor/Toolbar/TextEditorToolbar.js +31 -0
- package/{src → dist}/components/inputs/TextEditor/Toolbar/TextHighlightSelect.d.ts +1 -1
- package/dist/components/inputs/TextEditor/Toolbar/TextHighlightSelect.js +37 -0
- package/{src → dist}/components/inputs/TextEditor/Toolbar/TextListActions.d.ts +1 -1
- package/dist/components/inputs/TextEditor/Toolbar/TextListActions.js +51 -0
- package/{src → dist}/components/inputs/TextEditor/Toolbar/TextMarksActions.d.ts +1 -1
- package/dist/components/inputs/TextEditor/Toolbar/TextMarksActions.js +73 -0
- package/{src → dist}/components/inputs/TextEditor/Toolbar/TextStyleSelect.d.ts +1 -1
- package/dist/components/inputs/TextEditor/Toolbar/TextStyleSelect.js +61 -0
- package/dist/components/inputs/TextEditor/textEditor.types.js +40 -0
- package/{src → dist}/components/inputs/Toggle/Toggle.d.ts +3 -3
- package/dist/components/inputs/Toggle/Toggle.js +65 -0
- package/{src → dist}/components/inputs/Toggle/toggle.cva.d.ts +1 -1
- package/dist/components/inputs/Toggle/toggle.cva.js +44 -0
- package/{src → dist}/components/inputs/shared/CheckContent.d.ts +1 -1
- package/dist/components/inputs/shared/CheckContent.js +22 -0
- package/dist/components/inputs/shared/InputClear.js +27 -0
- package/dist/components/inputs/shared/input.cva.js +168 -0
- package/{src → dist}/components/inputs/shared/label.cva.d.ts +1 -1
- package/dist/components/inputs/shared/label.cva.js +133 -0
- package/dist/components/outline.clsx.js +11 -0
- package/{src → dist}/components/overlays/ActionModal/ActionModal.d.ts +2 -2
- package/dist/components/overlays/ActionModal/ActionModal.js +80 -0
- package/dist/components/overlays/BottomSheet/BottomSheet.js +261 -0
- package/dist/components/overlays/Drawer/Drawer.js +84 -0
- package/{src → dist}/components/overlays/Modal/Modal.d.ts +1 -1
- package/dist/components/overlays/Modal/Modal.js +53 -0
- package/dist/components/overlays/Modal/modal.cva.js +53 -0
- package/dist/components/overlays/ResponsivePopover/ResponsivePopover.js +71 -0
- package/{src → dist}/components/overlays/Tooltip/Tooltip.d.ts +1 -1
- package/dist/components/overlays/Tooltip/Tooltip.js +70 -0
- package/dist/components/overlays/Tooltip/TooltipEllipsis.js +27 -0
- package/dist/components/overlays/Tooltip/tooltip.cva.js +60 -0
- package/dist/components/segment/Segment.js +119 -0
- package/dist/components/segment/SegmentItem.js +43 -0
- package/{src → dist}/components/segment/segment.types.d.ts +1 -1
- package/dist/components/shared/pagination/Pagination.js +75 -0
- package/{src → dist}/components/shared/pagination/PaginationList.d.ts +1 -1
- package/dist/components/shared/pagination/PaginationList.js +145 -0
- package/dist/components/shared/pagination/minWidth.cva.js +15 -0
- package/{src → dist}/components/status/Alert/Alert.d.ts +1 -1
- package/dist/components/status/Alert/Alert.js +41 -0
- package/dist/components/status/Alert/alert.cva.js +64 -0
- package/{src → dist}/components/status/Loader/Loader.d.ts +1 -1
- package/dist/components/status/Loader/Loader.js +37 -0
- package/dist/components/status/Loader/loader.cva.js +27 -0
- package/{src → dist}/components/status/Toast/Toast.d.ts +1 -1
- package/dist/components/status/Toast/Toast.js +64 -0
- package/{src → dist}/components/status/Toast/toast.cva.d.ts +1 -1
- package/dist/components/status/Toast/toast.cva.js +150 -0
- package/dist/components/status/Toast/useToast.js +83 -0
- package/dist/components/status/shared/status.cva.js +62 -0
- package/dist/components/table/CellText.js +18 -0
- package/dist/components/table/ColumnConfig.js +124 -0
- package/dist/components/table/HeaderText.js +15 -0
- package/dist/components/table/InfiniteTable.js +40 -0
- package/dist/components/table/PaginatedTable.js +33 -0
- package/dist/components/table/Table.js +370 -0
- package/dist/components/table/table.cva.js +63 -0
- package/{src → dist}/components/text/Link/Link.d.ts +1 -1
- package/dist/components/text/Link/Link.js +18 -0
- package/dist/components/text/Link/link.cva.js +18 -0
- package/{src → dist}/components/text/Tag/Tag.d.ts +1 -1
- package/dist/components/text/Tag/Tag.js +49 -0
- package/dist/components/text/Tag/tag.cva.js +59 -0
- package/{src → dist}/components/text/Typography/Typography.d.ts +1 -1
- package/dist/components/text/Typography/Typography.js +22 -0
- package/dist/components/text/Typography/typography.cva.js +100 -0
- package/{src → dist}/config/confirmation.context.d.ts +1 -1
- package/dist/config/confirmation.context.js +107 -0
- package/dist/config/i18n.js +15 -0
- package/dist/config/router.context.js +43 -0
- package/{src → dist}/config/uiConfig.context.d.ts +8 -8
- package/dist/config/uiConfig.context.js +67 -0
- package/{src → dist}/config/uiStyle.context.d.ts +14 -14
- package/dist/config/uiStyle.context.js +16 -0
- package/dist/helpers/dynamicColumns.js +359 -0
- package/{src → dist}/helpers/dynamicInputs.d.ts +2 -2
- package/dist/helpers/dynamicInputs.js +216 -0
- package/dist/hooks/useAutosave.js +83 -0
- package/dist/hooks/useBreakpoint.js +20 -0
- package/dist/hooks/useDebounceCallback.js +29 -0
- package/dist/hooks/useDeepCompare.js +25 -0
- package/dist/hooks/useFilters.js +120 -0
- package/dist/hooks/useForm.js +22 -0
- package/{src → dist}/hooks/useFormAutosave.d.ts +2 -2
- package/dist/hooks/useFormAutosave.js +67 -0
- package/dist/hooks/useIntersectionObserver.js +27 -0
- package/dist/hooks/useLocalStorage.js +63 -0
- package/dist/hooks/useLongPressRepeat.js +33 -0
- package/dist/hooks/usePagination.js +35 -0
- package/dist/hooks/useScrollableListBox.js +30 -0
- package/dist/hooks/useSorting.js +30 -0
- package/dist/hooks/useStateAndRef.js +17 -0
- package/dist/hooks/useTableColumnConfig.js +63 -0
- package/dist/hooks/useTableNav.js +409 -0
- package/dist/hooks/useTranslationMemo.js +14 -0
- package/dist/index.js +284 -0
- package/{src → dist}/types/react-query.d.ts +1 -1
- package/dist/utils/array.utils.js +12 -0
- package/dist/utils/compoundMapper.js +14 -0
- package/dist/utils/date-time.utils.js +77 -0
- package/dist/utils/date.utils.js +12 -0
- package/dist/utils/dom.utils.js +13 -0
- package/dist/utils/file.utils.js +63 -0
- package/dist/utils/isEqual.js +95 -0
- package/dist/utils/logger.js +19 -0
- package/dist/utils/object.utils.js +53 -0
- package/dist/utils/queries.utils.js +9 -0
- package/dist/utils/rest.utils.js +51 -0
- package/dist/utils/routing.utils.js +15 -0
- package/dist/utils/string.utils.js +12 -0
- package/{src → dist}/utils/vendor/acl/AclGuard.d.ts +1 -1
- package/dist/utils/vendor/acl/AclGuard.js +15 -0
- package/dist/utils/vendor/acl/Can.js +18 -0
- package/dist/utils/vendor/acl/ability.context.js +37 -0
- package/dist/utils/vendor/auth/AuthGuard.js +26 -0
- package/dist/utils/vendor/auth/auth.context.js +36 -0
- package/{src → dist}/utils/vendor/auth/withPrivateAuthGuard.d.ts +1 -1
- package/dist/utils/vendor/auth/withPrivateAuthGuard.js +17 -0
- package/dist/utils/vendor/error-handling.js +119 -0
- package/dist/utils/vendor/rest-interceptor.js +21 -0
- package/dist/utils/zod.utils.js +25 -0
- package/package.json +57 -5
- package/index.js +0 -62585
- package/povio-ui-0.0.8.tgz +0 -0
- package/vite.config.d.ts +0 -2
- /package/{src → dist}/assets/icons/AlignCenter.d.ts +0 -0
- /package/{src → dist}/assets/icons/AlignLeft.d.ts +0 -0
- /package/{src → dist}/assets/icons/AlignLeftRight.d.ts +0 -0
- /package/{src → dist}/assets/icons/AlignRight.d.ts +0 -0
- /package/{src → dist}/assets/icons/ArrowDropDown.d.ts +0 -0
- /package/{src → dist}/assets/icons/ArrowDropUp.d.ts +0 -0
- /package/{src → dist}/assets/icons/ArrowLeft.d.ts +0 -0
- /package/{src → dist}/assets/icons/ArrowRight.d.ts +0 -0
- /package/{src → dist}/assets/icons/Bold.d.ts +0 -0
- /package/{src → dist}/assets/icons/BulletedList.d.ts +0 -0
- /package/{src → dist}/assets/icons/Calendar.d.ts +0 -0
- /package/{src → dist}/assets/icons/Check.d.ts +0 -0
- /package/{src → dist}/assets/icons/CheckCircle.d.ts +0 -0
- /package/{src → dist}/assets/icons/CheckboxCheckmark.d.ts +0 -0
- /package/{src → dist}/assets/icons/CheckboxIndeterminate.d.ts +0 -0
- /package/{src → dist}/assets/icons/ChevronDown.d.ts +0 -0
- /package/{src → dist}/assets/icons/ChevronLeft.d.ts +0 -0
- /package/{src → dist}/assets/icons/ChevronRight.d.ts +0 -0
- /package/{src → dist}/assets/icons/ChevronUp.d.ts +0 -0
- /package/{src → dist}/assets/icons/ChevronsLeft.d.ts +0 -0
- /package/{src → dist}/assets/icons/ChevronsRight.d.ts +0 -0
- /package/{src → dist}/assets/icons/Clock.d.ts +0 -0
- /package/{src → dist}/assets/icons/Close.d.ts +0 -0
- /package/{src → dist}/assets/icons/DateTime.d.ts +0 -0
- /package/{src → dist}/assets/icons/Drag.d.ts +0 -0
- /package/{src → dist}/assets/icons/File.d.ts +0 -0
- /package/{src → dist}/assets/icons/Highlight.d.ts +0 -0
- /package/{src → dist}/assets/icons/HighlightOn.d.ts +0 -0
- /package/{src → dist}/assets/icons/Info.d.ts +0 -0
- /package/{src → dist}/assets/icons/Italic.d.ts +0 -0
- /package/{src → dist}/assets/icons/Link.d.ts +0 -0
- /package/{src → dist}/assets/icons/Menu.d.ts +0 -0
- /package/{src → dist}/assets/icons/NumberedList.d.ts +0 -0
- /package/{src → dist}/assets/icons/PointerHorizontal.d.ts +0 -0
- /package/{src → dist}/assets/icons/PointerVertical.d.ts +0 -0
- /package/{src → dist}/assets/icons/Send.d.ts +0 -0
- /package/{src → dist}/assets/icons/Strikethrough.d.ts +0 -0
- /package/{src → dist}/assets/icons/TextColor.d.ts +0 -0
- /package/{src → dist}/assets/icons/Today.d.ts +0 -0
- /package/{src → dist}/assets/icons/Underlined.d.ts +0 -0
- /package/{src → dist}/assets/icons/Upload.d.ts +0 -0
- /package/{src → dist}/assets/icons/View.d.ts +0 -0
- /package/{src → dist}/assets/icons/ViewOff.d.ts +0 -0
- /package/{src → dist}/assets/icons/WarningFilled.d.ts +0 -0
- /package/{src → dist}/components/Menu/Menu.d.ts +0 -0
- /package/{src → dist}/components/buttons/shared/buttonContent.cva.d.ts +0 -0
- /package/{src → dist}/components/inputs/DateTime/shared/Calendar.d.ts +0 -0
- /package/{src → dist}/components/inputs/DateTime/shared/CalendarCell.d.ts +0 -0
- /package/{src → dist}/components/inputs/DateTime/shared/CalendarGrid.d.ts +0 -0
- /package/{src → dist}/components/inputs/DateTime/shared/CalendarSelectHeader.d.ts +0 -0
- /package/{src → dist}/components/inputs/DateTime/shared/DateField.d.ts +0 -0
- /package/{src → dist}/components/inputs/DateTime/shared/DateSegmentItem.d.ts +0 -0
- /package/{src → dist}/components/inputs/DateTime/shared/DateTimeDialog.d.ts +0 -0
- /package/{src → dist}/components/inputs/DateTime/shared/DateTimeDialogFooter.d.ts +0 -0
- /package/{src → dist}/components/inputs/DateTime/shared/MonthPicker.d.ts +0 -0
- /package/{src → dist}/components/inputs/DateTime/shared/RangeCalendar.d.ts +0 -0
- /package/{src → dist}/components/inputs/DateTime/shared/TimeField.d.ts +0 -0
- /package/{src → dist}/components/inputs/DateTime/shared/TimePickerForm.d.ts +0 -0
- /package/{src → dist}/components/inputs/DateTime/shared/YearPicker.d.ts +0 -0
- /package/{src → dist}/components/inputs/File/FileUpload.d.ts +0 -0
- /package/{src → dist}/components/inputs/File/FileUploadContainer.d.ts +0 -0
- /package/{src → dist}/components/inputs/File/InputUpload.d.ts +0 -0
- /package/{src → dist}/components/inputs/File/index.d.ts +0 -0
- /package/{src → dist}/components/inputs/File/shared/FileProgressBar.d.ts +0 -0
- /package/{src → dist}/components/inputs/File/shared/InputUploadFilled.d.ts +0 -0
- /package/{src → dist}/components/inputs/File/shared/fileUpload.cva.d.ts +0 -0
- /package/{src → dist}/components/inputs/File/shared/inputUploadButton.cva.d.ts +0 -0
- /package/{src → dist}/components/inputs/FormField/FormFieldError.d.ts +0 -0
- /package/{src → dist}/components/inputs/FormField/FormFieldHeader.d.ts +0 -0
- /package/{src → dist}/components/inputs/FormField/FormFieldHeaderClose.d.ts +0 -0
- /package/{src → dist}/components/inputs/Inputs/Inputs.d.ts +0 -0
- /package/{src → dist}/components/inputs/Selection/shared/SelectListBoxSelectionBar.d.ts +0 -0
- /package/{src → dist}/components/inputs/TextEditor/Toolbar/ColorPicker.d.ts +0 -0
- /package/{src → dist}/components/inputs/TextEditor/Toolbar/ColorPickerDropdown.d.ts +0 -0
- /package/{src → dist}/components/inputs/TextEditor/Toolbar/TextEditorToolbar.d.ts +0 -0
- /package/{src → dist}/components/inputs/TextEditor/textEditor.types.d.ts +0 -0
- /package/{src → dist}/components/inputs/shared/InputClear.d.ts +0 -0
- /package/{src → dist}/components/inputs/shared/form.types.d.ts +0 -0
- /package/{src → dist}/components/inputs/shared/input.cva.d.ts +0 -0
- /package/{src → dist}/components/outline.clsx.d.ts +0 -0
- /package/{src → dist}/components/overlays/BottomSheet/BottomSheet.d.ts +0 -0
- /package/{src → dist}/components/overlays/Drawer/Drawer.d.ts +0 -0
- /package/{src → dist}/components/overlays/Modal/modal.cva.d.ts +0 -0
- /package/{src → dist}/components/overlays/ResponsivePopover/ResponsivePopover.d.ts +0 -0
- /package/{src → dist}/components/overlays/Tooltip/TooltipEllipsis.d.ts +0 -0
- /package/{src → dist}/components/overlays/Tooltip/tooltip.cva.d.ts +0 -0
- /package/{src → dist}/components/segment/Segment.d.ts +0 -0
- /package/{src → dist}/components/segment/SegmentItem.d.ts +0 -0
- /package/{src → dist}/components/shared/pagination/Pagination.d.ts +0 -0
- /package/{src → dist}/components/shared/pagination/minWidth.cva.d.ts +0 -0
- /package/{src → dist}/components/status/Alert/alert.cva.d.ts +0 -0
- /package/{src → dist}/components/status/Loader/loader.cva.d.ts +0 -0
- /package/{src → dist}/components/status/Toast/useToast.d.ts +0 -0
- /package/{src → dist}/components/status/shared/status.cva.d.ts +0 -0
- /package/{src → dist}/components/table/CellText.d.ts +0 -0
- /package/{src → dist}/components/table/ColumnConfig.d.ts +0 -0
- /package/{src → dist}/components/table/HeaderText.d.ts +0 -0
- /package/{src → dist}/components/table/InfiniteTable.d.ts +0 -0
- /package/{src → dist}/components/table/PaginatedTable.d.ts +0 -0
- /package/{src → dist}/components/table/Table.d.ts +0 -0
- /package/{src → dist}/components/table/table.cva.d.ts +0 -0
- /package/{src → dist}/components/text/Link/link.cva.d.ts +0 -0
- /package/{src → dist}/components/text/Tag/tag.cva.d.ts +0 -0
- /package/{src → dist}/components/text/Typography/typography.cva.d.ts +0 -0
- /package/{src → dist}/config/i18n.d.ts +0 -0
- /package/{src → dist}/config/router.context.d.ts +0 -0
- /package/{src → dist}/helpers/dynamicColumns.d.ts +0 -0
- /package/{src → dist}/hooks/useAutosave.d.ts +0 -0
- /package/{src → dist}/hooks/useBreakpoint.d.ts +0 -0
- /package/{src → dist}/hooks/useDebounceCallback.d.ts +0 -0
- /package/{src → dist}/hooks/useDeepCompare.d.ts +0 -0
- /package/{src → dist}/hooks/useFilters.d.ts +0 -0
- /package/{src → dist}/hooks/useForm.d.ts +0 -0
- /package/{src → dist}/hooks/useIntersectionObserver.d.ts +0 -0
- /package/{src → dist}/hooks/useLocalStorage.d.ts +0 -0
- /package/{src → dist}/hooks/useLongPressRepeat.d.ts +0 -0
- /package/{src → dist}/hooks/usePagination.d.ts +0 -0
- /package/{src → dist}/hooks/useScrollableListBox.d.ts +0 -0
- /package/{src → dist}/hooks/useSorting.d.ts +0 -0
- /package/{src → dist}/hooks/useStateAndRef.d.ts +0 -0
- /package/{src → dist}/hooks/useTableColumnConfig.d.ts +0 -0
- /package/{src → dist}/hooks/useTableNav.d.ts +0 -0
- /package/{src → dist}/hooks/useTranslationMemo.d.ts +0 -0
- /package/{src → dist}/index.d.ts +0 -0
- /package/{styles → dist/styles}/editor.css +0 -0
- /package/{styles → dist/styles}/index.css +0 -0
- /package/{src → dist}/types/common.d.ts +0 -0
- /package/{src → dist}/utils/array.utils.d.ts +0 -0
- /package/{src → dist}/utils/array.utils.spec.d.ts +0 -0
- /package/{src → dist}/utils/compoundMapper.d.ts +0 -0
- /package/{src → dist}/utils/compoundMapper.spec.d.ts +0 -0
- /package/{src → dist}/utils/date-time.utils.d.ts +0 -0
- /package/{src → dist}/utils/date-time.utils.spec.d.ts +0 -0
- /package/{src → dist}/utils/date.utils.d.ts +0 -0
- /package/{src → dist}/utils/date.utils.spec.d.ts +0 -0
- /package/{src → dist}/utils/dom.utils.d.ts +0 -0
- /package/{src → dist}/utils/file.utils.d.ts +0 -0
- /package/{src → dist}/utils/isEqual.d.ts +0 -0
- /package/{src → dist}/utils/logger.d.ts +0 -0
- /package/{src → dist}/utils/object.utils.d.ts +0 -0
- /package/{src → dist}/utils/queries.utils.d.ts +0 -0
- /package/{src → dist}/utils/rest.utils.d.ts +0 -0
- /package/{src → dist}/utils/routing.utils.d.ts +0 -0
- /package/{src → dist}/utils/string.utils.d.ts +0 -0
- /package/{src → dist}/utils/vendor/acl/Can.d.ts +0 -0
- /package/{src → dist}/utils/vendor/acl/ability.context.d.ts +0 -0
- /package/{src → dist}/utils/vendor/acl/appAbility.types.d.ts +0 -0
- /package/{src → dist}/utils/vendor/auth/AuthGuard.d.ts +0 -0
- /package/{src → dist}/utils/vendor/auth/auth.context.d.ts +0 -0
- /package/{src → dist}/utils/vendor/error-handling.d.ts +0 -0
- /package/{src → dist}/utils/vendor/rest-client.types.d.ts +0 -0
- /package/{src → dist}/utils/vendor/rest-interceptor.d.ts +0 -0
- /package/{src → dist}/utils/zod.utils.d.ts +0 -0
|
@@ -0,0 +1,359 @@
|
|
|
1
|
+
import i18next from "i18next";
|
|
2
|
+
import { z } from "zod";
|
|
3
|
+
import { DateUtils } from "../utils/date.utils.js";
|
|
4
|
+
import { StringUtils } from "../utils/string.utils.js";
|
|
5
|
+
import { ZodUtils } from "../utils/zod.utils.js";
|
|
6
|
+
const DEFAULT_NAMESPACE = "dynamicColumns";
|
|
7
|
+
const FORMAT_MAP = {
|
|
8
|
+
datetime: (value) => DateUtils.formatDate(new Date(value)),
|
|
9
|
+
dateRange: (value) => {
|
|
10
|
+
const startDate = DateUtils.formatDate(new Date(value.start));
|
|
11
|
+
const endDate = DateUtils.formatDate(new Date(value.end));
|
|
12
|
+
return `${startDate} - ${endDate}`;
|
|
13
|
+
},
|
|
14
|
+
enum: (value) => StringUtils.capitalize(value),
|
|
15
|
+
number: (value) => value.toLocaleString(i18next.language),
|
|
16
|
+
string: (value) => String(value),
|
|
17
|
+
boolean: (value) => {
|
|
18
|
+
const key = `${DEFAULT_NAMESPACE}.${value ? "yes" : "no"}`;
|
|
19
|
+
if (i18next.exists(key)) {
|
|
20
|
+
return String(i18next.t(key));
|
|
21
|
+
}
|
|
22
|
+
return value ? "Yes" : "No";
|
|
23
|
+
}
|
|
24
|
+
};
|
|
25
|
+
const ZOD_TYPE_FORMAT_MAP = [
|
|
26
|
+
[z.ZodEnum, FORMAT_MAP.enum],
|
|
27
|
+
[z.ZodNumber, FORMAT_MAP.number],
|
|
28
|
+
[z.ZodString, FORMAT_MAP.string],
|
|
29
|
+
[z.ZodBoolean, FORMAT_MAP.boolean],
|
|
30
|
+
[z.ZodISODateTime, FORMAT_MAP.datetime]
|
|
31
|
+
];
|
|
32
|
+
const configValueToColumnDef = (value) => {
|
|
33
|
+
if (typeof value === "function" || typeof value === "string") {
|
|
34
|
+
return {
|
|
35
|
+
cell: value
|
|
36
|
+
};
|
|
37
|
+
}
|
|
38
|
+
if (typeof value === "boolean" || value === void 0) {
|
|
39
|
+
return {};
|
|
40
|
+
}
|
|
41
|
+
return value;
|
|
42
|
+
};
|
|
43
|
+
const convertEntriesToColumnDefs = (entries) => {
|
|
44
|
+
return entries.map(([key, value]) => [key, configValueToColumnDef(value)]);
|
|
45
|
+
};
|
|
46
|
+
const customConfigValueToColumnDef = (value) => {
|
|
47
|
+
if (typeof value === "string") {
|
|
48
|
+
return {
|
|
49
|
+
accessorKey: value,
|
|
50
|
+
cell: value
|
|
51
|
+
};
|
|
52
|
+
}
|
|
53
|
+
if (typeof value === "function") {
|
|
54
|
+
return {
|
|
55
|
+
cell: value
|
|
56
|
+
};
|
|
57
|
+
}
|
|
58
|
+
return value;
|
|
59
|
+
};
|
|
60
|
+
const convertCustomEntriesToColumnDefs = (entries) => {
|
|
61
|
+
return entries.map(([key, value]) => [key, customConfigValueToColumnDef(value)]);
|
|
62
|
+
};
|
|
63
|
+
const excludeEntries = (entries) => {
|
|
64
|
+
return entries.filter(([, value]) => value !== false && value !== void 0);
|
|
65
|
+
};
|
|
66
|
+
const sortColumns = (columns, orderKeys) => {
|
|
67
|
+
if (!orderKeys) {
|
|
68
|
+
return columns;
|
|
69
|
+
}
|
|
70
|
+
const wildcardIndex = orderKeys.indexOf("*");
|
|
71
|
+
if (wildcardIndex === -1) {
|
|
72
|
+
return columns.sort((columnA, columnB) => {
|
|
73
|
+
const idA = columnA.id;
|
|
74
|
+
const idB = columnB.id;
|
|
75
|
+
const orderMap = new Map(orderKeys.map((key, index) => [String(key), index]));
|
|
76
|
+
const orderA = orderMap.get(String(idA));
|
|
77
|
+
const orderB = orderMap.get(String(idB));
|
|
78
|
+
if (orderA !== void 0 && orderB !== void 0) {
|
|
79
|
+
return orderA - orderB;
|
|
80
|
+
}
|
|
81
|
+
if (orderA !== void 0 && orderB === void 0) {
|
|
82
|
+
return -1;
|
|
83
|
+
}
|
|
84
|
+
if (orderA === void 0 && orderB !== void 0) {
|
|
85
|
+
return 1;
|
|
86
|
+
}
|
|
87
|
+
return 0;
|
|
88
|
+
});
|
|
89
|
+
}
|
|
90
|
+
const beforeWildcard = orderKeys.slice(0, wildcardIndex);
|
|
91
|
+
const afterWildcard = orderKeys.slice(wildcardIndex + 1);
|
|
92
|
+
const beforeMap = new Map(beforeWildcard.map((key, index) => [String(key), index]));
|
|
93
|
+
const afterMap = new Map(afterWildcard.map((key, index) => [String(key), index]));
|
|
94
|
+
const before = [];
|
|
95
|
+
const middle = [];
|
|
96
|
+
const after = [];
|
|
97
|
+
columns.forEach((column) => {
|
|
98
|
+
const id = String(column.id);
|
|
99
|
+
if (beforeMap.has(id)) {
|
|
100
|
+
before.push(column);
|
|
101
|
+
} else if (afterMap.has(id)) {
|
|
102
|
+
after.push(column);
|
|
103
|
+
} else {
|
|
104
|
+
middle.push(column);
|
|
105
|
+
}
|
|
106
|
+
});
|
|
107
|
+
before.sort((a, b) => beforeMap.get(String(a.id)) - beforeMap.get(String(b.id)));
|
|
108
|
+
after.sort((a, b) => afterMap.get(String(a.id)) - afterMap.get(String(b.id)));
|
|
109
|
+
return [...before, ...middle, ...after];
|
|
110
|
+
};
|
|
111
|
+
const formatValueByType = (value, schemaType) => {
|
|
112
|
+
if (value === null || value === void 0) {
|
|
113
|
+
return null;
|
|
114
|
+
}
|
|
115
|
+
if (ZodUtils.isDateRange(schemaType)) {
|
|
116
|
+
return FORMAT_MAP.dateRange(value);
|
|
117
|
+
}
|
|
118
|
+
const unwrappedType = ZodUtils.unwrapZodType(schemaType);
|
|
119
|
+
if (unwrappedType instanceof z.ZodArray) {
|
|
120
|
+
if (!Array.isArray(value)) {
|
|
121
|
+
return null;
|
|
122
|
+
}
|
|
123
|
+
const elementType = unwrappedType.element;
|
|
124
|
+
const formattedElements = value.map((element) => formatValueByType(element, elementType));
|
|
125
|
+
return formattedElements.join(", ");
|
|
126
|
+
}
|
|
127
|
+
const formatFunction = ZOD_TYPE_FORMAT_MAP.find(([zodType]) => unwrappedType instanceof zodType)?.[1];
|
|
128
|
+
if (formatFunction) {
|
|
129
|
+
return formatFunction(value);
|
|
130
|
+
}
|
|
131
|
+
return String(value);
|
|
132
|
+
};
|
|
133
|
+
const getNestedValue = (obj, path) => {
|
|
134
|
+
return path.split(".").reduce((current, key) => {
|
|
135
|
+
return current && typeof current === "object" ? current[key] : void 0;
|
|
136
|
+
}, obj);
|
|
137
|
+
};
|
|
138
|
+
const getKeyType = (schema, key) => {
|
|
139
|
+
const pathParts = key.split(".");
|
|
140
|
+
let currentType = schema.shape[pathParts[0]];
|
|
141
|
+
for (let i = 1; i < pathParts.length; i++) {
|
|
142
|
+
if (currentType instanceof z.ZodObject) {
|
|
143
|
+
currentType = currentType.shape[pathParts[i]];
|
|
144
|
+
} else {
|
|
145
|
+
currentType = schema.shape[key];
|
|
146
|
+
break;
|
|
147
|
+
}
|
|
148
|
+
}
|
|
149
|
+
return currentType;
|
|
150
|
+
};
|
|
151
|
+
const getCellFunction = (schema, schemaKey, columnDef, options) => {
|
|
152
|
+
const { cell } = columnDef;
|
|
153
|
+
if (typeof cell === "function") {
|
|
154
|
+
return cell;
|
|
155
|
+
}
|
|
156
|
+
return ({ data }) => {
|
|
157
|
+
const isCellKeyString = typeof cell === "string";
|
|
158
|
+
const key = isCellKeyString ? cell : schemaKey;
|
|
159
|
+
const value = getNestedValue(data, key);
|
|
160
|
+
const keyType = getKeyType(schema, key);
|
|
161
|
+
const shouldFormat = !options.disableFormatting?.includes(key);
|
|
162
|
+
const formattedValue = shouldFormat ? formatValueByType(value, keyType) : value;
|
|
163
|
+
let finalValue = formattedValue;
|
|
164
|
+
if (options.emptyValue && !finalValue) {
|
|
165
|
+
finalValue = options.emptyValue;
|
|
166
|
+
}
|
|
167
|
+
if (options.globalWrapper) {
|
|
168
|
+
return options.globalWrapper(finalValue);
|
|
169
|
+
}
|
|
170
|
+
return finalValue;
|
|
171
|
+
};
|
|
172
|
+
};
|
|
173
|
+
const normalizeSortable = (sortable) => {
|
|
174
|
+
if (!sortable) {
|
|
175
|
+
return void 0;
|
|
176
|
+
}
|
|
177
|
+
if (Array.isArray(sortable)) {
|
|
178
|
+
return sortable;
|
|
179
|
+
}
|
|
180
|
+
if (sortable instanceof z.ZodEnum) {
|
|
181
|
+
return Object.values(sortable.enum);
|
|
182
|
+
}
|
|
183
|
+
return void 0;
|
|
184
|
+
};
|
|
185
|
+
const getDefaultColumnHeader = (key, options) => {
|
|
186
|
+
const namespace = options.namespace ?? DEFAULT_NAMESPACE;
|
|
187
|
+
const localeKey = `${namespace}.${key}`;
|
|
188
|
+
if (i18next.exists(localeKey)) {
|
|
189
|
+
return String(i18next.t(localeKey));
|
|
190
|
+
}
|
|
191
|
+
return StringUtils.capitalize(key);
|
|
192
|
+
};
|
|
193
|
+
const overridePresetColumnsHeaders = (presetColumns, options) => {
|
|
194
|
+
const namespace = options.namespace ?? DEFAULT_NAMESPACE;
|
|
195
|
+
return presetColumns.map((columnDef) => {
|
|
196
|
+
const localeKey = `${namespace}.${columnDef.id}`;
|
|
197
|
+
const header = i18next.exists(localeKey) ? i18next.t(localeKey) : columnDef.header;
|
|
198
|
+
return {
|
|
199
|
+
...columnDef,
|
|
200
|
+
header: typeof header === "string" ? header : columnDef.header
|
|
201
|
+
};
|
|
202
|
+
});
|
|
203
|
+
};
|
|
204
|
+
const populateColumnDef = (schema, key, columnDef, options, sortableKeys) => {
|
|
205
|
+
const id = columnDef.id ?? key;
|
|
206
|
+
const enableSorting = columnDef.enableSorting ?? sortableKeys?.includes(id) ?? false;
|
|
207
|
+
const header = columnDef.header ?? getDefaultColumnHeader(key, options);
|
|
208
|
+
const cell = getCellFunction(schema, key, columnDef, options);
|
|
209
|
+
return {
|
|
210
|
+
...columnDef,
|
|
211
|
+
id,
|
|
212
|
+
accessorKey: key,
|
|
213
|
+
meta: {
|
|
214
|
+
width: "flex-1",
|
|
215
|
+
...options.globalMeta,
|
|
216
|
+
...columnDef.meta
|
|
217
|
+
},
|
|
218
|
+
header,
|
|
219
|
+
enableSorting,
|
|
220
|
+
cell
|
|
221
|
+
};
|
|
222
|
+
};
|
|
223
|
+
const populateCustomColumnDef = (schema, key, columnDef, options, sortableKeys) => {
|
|
224
|
+
const id = columnDef.id ?? key;
|
|
225
|
+
const accessorKey = columnDef.accessorKey ?? id;
|
|
226
|
+
const enableSorting = columnDef.enableSorting ?? sortableKeys?.includes(id) ?? false;
|
|
227
|
+
const header = columnDef.header ?? getDefaultColumnHeader(key, options);
|
|
228
|
+
const cell = getCellFunction(schema, key, columnDef, options);
|
|
229
|
+
return {
|
|
230
|
+
...columnDef,
|
|
231
|
+
id,
|
|
232
|
+
accessorKey,
|
|
233
|
+
meta: {
|
|
234
|
+
width: "flex-1",
|
|
235
|
+
...options.globalMeta,
|
|
236
|
+
...columnDef.meta
|
|
237
|
+
},
|
|
238
|
+
header,
|
|
239
|
+
enableSorting,
|
|
240
|
+
cell
|
|
241
|
+
};
|
|
242
|
+
};
|
|
243
|
+
const addMissingSchemaFields = (schema, existingColumns, options, sortableKeys) => {
|
|
244
|
+
const schemaFields = getAllSchemaKeys(schema);
|
|
245
|
+
const definedFields = new Set(existingColumns.map((col) => col.id));
|
|
246
|
+
const missingFields = schemaFields.filter((field) => !definedFields.has(field));
|
|
247
|
+
const additionalColumns = missingFields.map((field) => {
|
|
248
|
+
return populateColumnDef(schema, field, {}, options, sortableKeys);
|
|
249
|
+
});
|
|
250
|
+
return [...existingColumns, ...additionalColumns];
|
|
251
|
+
};
|
|
252
|
+
const removeOverriddenPresetColumns = (presetColumns, options) => {
|
|
253
|
+
if (presetColumns.length === 0) {
|
|
254
|
+
return presetColumns;
|
|
255
|
+
}
|
|
256
|
+
const usedColumnsIds = Object.entries(options.columns ?? {}).map(([key, value]) => {
|
|
257
|
+
const columnDef = value;
|
|
258
|
+
return columnDef.id ?? key;
|
|
259
|
+
});
|
|
260
|
+
const usedCustomColumnsIds = Object.entries(options.customColumns ?? {}).map(([key, value]) => {
|
|
261
|
+
const columnDef = value;
|
|
262
|
+
return columnDef.id ?? key;
|
|
263
|
+
});
|
|
264
|
+
const usedIds = /* @__PURE__ */ new Set([...usedColumnsIds, ...usedCustomColumnsIds]);
|
|
265
|
+
return presetColumns.filter((column) => {
|
|
266
|
+
if (!column.id) {
|
|
267
|
+
return true;
|
|
268
|
+
}
|
|
269
|
+
return !usedIds.has(column.id);
|
|
270
|
+
});
|
|
271
|
+
};
|
|
272
|
+
const getAllSchemaKeys = (schema) => {
|
|
273
|
+
const keys = [];
|
|
274
|
+
const { shape } = schema;
|
|
275
|
+
const traverse = (obj, prefix = "") => {
|
|
276
|
+
Object.entries(obj).forEach(([key, value]) => {
|
|
277
|
+
const currentPath = prefix ? `${prefix}.${key}` : key;
|
|
278
|
+
keys.push(currentPath);
|
|
279
|
+
if (value instanceof z.ZodObject) {
|
|
280
|
+
traverse(value.shape, currentPath);
|
|
281
|
+
}
|
|
282
|
+
});
|
|
283
|
+
};
|
|
284
|
+
traverse(shape);
|
|
285
|
+
return keys;
|
|
286
|
+
};
|
|
287
|
+
const validateCustomColumnKeys = (schema, customColumnKeys) => {
|
|
288
|
+
const schemaKeys = getAllSchemaKeys(schema);
|
|
289
|
+
const invalidCustomColumnKeys = customColumnKeys.filter(
|
|
290
|
+
(key) => schemaKeys.includes(key)
|
|
291
|
+
);
|
|
292
|
+
if (invalidCustomColumnKeys.length > 0) {
|
|
293
|
+
throw new Error(
|
|
294
|
+
`Invalid custom column keys: [${invalidCustomColumnKeys.join(", ")}]. Custom column keys cannot be part of the schema. Define these columns in the "columns" property instead.`
|
|
295
|
+
);
|
|
296
|
+
}
|
|
297
|
+
};
|
|
298
|
+
const validateOptionKeyArray = (usedKeys, optionKeys, optionName) => {
|
|
299
|
+
if (!optionKeys) {
|
|
300
|
+
return;
|
|
301
|
+
}
|
|
302
|
+
const extraUnusedKeys = optionKeys.filter((key) => !usedKeys.has(key));
|
|
303
|
+
if (extraUnusedKeys.length > 0) {
|
|
304
|
+
throw new Error(
|
|
305
|
+
`Found unnecessary keys in "${optionName}": [${extraUnusedKeys.join(", ")}].
|
|
306
|
+
|
|
307
|
+
All available options are: [${Array.from(usedKeys).join(", ")}].`
|
|
308
|
+
);
|
|
309
|
+
}
|
|
310
|
+
};
|
|
311
|
+
const validateParams = (schema, presetColumns, options) => {
|
|
312
|
+
const { columns, customColumns, sortable, order, disableFormatting, includeAll } = options;
|
|
313
|
+
const columnKeys = Object.keys(columns ?? {});
|
|
314
|
+
const customColumnKeys = customColumns ? Object.keys(customColumns) : [];
|
|
315
|
+
const usedKeys = /* @__PURE__ */ new Set([...columnKeys, ...customColumnKeys]);
|
|
316
|
+
const presetKeys = presetColumns.map((column) => column.id).filter((id) => id !== void 0);
|
|
317
|
+
const schemaKeys = includeAll ? getAllSchemaKeys(schema) : [];
|
|
318
|
+
const allKeys = /* @__PURE__ */ new Set([...presetKeys, ...usedKeys, ...schemaKeys, "*"]);
|
|
319
|
+
if (customColumns) {
|
|
320
|
+
validateCustomColumnKeys(schema, customColumnKeys);
|
|
321
|
+
}
|
|
322
|
+
if (Array.isArray(sortable)) {
|
|
323
|
+
validateOptionKeyArray(usedKeys, sortable, "sortable");
|
|
324
|
+
}
|
|
325
|
+
validateOptionKeyArray(allKeys, order, "order");
|
|
326
|
+
validateOptionKeyArray(usedKeys, disableFormatting, "disableFormatting");
|
|
327
|
+
};
|
|
328
|
+
const dynamicColumns = ({
|
|
329
|
+
schema,
|
|
330
|
+
preset = [],
|
|
331
|
+
options
|
|
332
|
+
}) => {
|
|
333
|
+
validateParams(schema, preset, options);
|
|
334
|
+
const sortableKeys = normalizeSortable(options.sortable);
|
|
335
|
+
let entries = Object.entries(options.columns ?? {});
|
|
336
|
+
entries = excludeEntries(entries);
|
|
337
|
+
entries = convertEntriesToColumnDefs(entries);
|
|
338
|
+
const columns = entries.map(([key, value]) => {
|
|
339
|
+
const columnDef = value;
|
|
340
|
+
return populateColumnDef(schema, key, columnDef, options, sortableKeys);
|
|
341
|
+
});
|
|
342
|
+
let customEntries = Object.entries(options.customColumns ?? {});
|
|
343
|
+
customEntries = convertCustomEntriesToColumnDefs(customEntries);
|
|
344
|
+
const customColumns = customEntries.map(([key, value]) => {
|
|
345
|
+
const columnDef = value;
|
|
346
|
+
return populateCustomColumnDef(schema, key, columnDef, options, sortableKeys);
|
|
347
|
+
});
|
|
348
|
+
let presetColumns = removeOverriddenPresetColumns(preset, options);
|
|
349
|
+
if (options.overridePresetLocales) {
|
|
350
|
+
presetColumns = overridePresetColumnsHeaders(presetColumns, options);
|
|
351
|
+
}
|
|
352
|
+
const mergedColumns = [...presetColumns, ...columns, ...customColumns];
|
|
353
|
+
const allColumns = options.includeAll ? addMissingSchemaFields(schema, mergedColumns, options, sortableKeys) : mergedColumns;
|
|
354
|
+
return sortColumns(allColumns, options.order);
|
|
355
|
+
};
|
|
356
|
+
export {
|
|
357
|
+
dynamicColumns,
|
|
358
|
+
sortColumns
|
|
359
|
+
};
|
|
@@ -1,8 +1,8 @@
|
|
|
1
1
|
import { ReactElement } from 'react';
|
|
2
2
|
import { Control, UseFormReturn } from 'react-hook-form';
|
|
3
3
|
import { z } from 'zod';
|
|
4
|
-
import { InputComponentProps, InputComponentType, InputDef, InputDefBaseProps, InputWrapperType } from '
|
|
5
|
-
import { ZodUtils } from '
|
|
4
|
+
import { InputComponentProps, InputComponentType, InputDef, InputDefBaseProps, InputWrapperType } from '../components/inputs/Inputs/InputItem';
|
|
5
|
+
import { ZodUtils } from '../utils/zod.utils';
|
|
6
6
|
declare const defaultComponentTypes: {
|
|
7
7
|
readonly datetime: "datePicker";
|
|
8
8
|
readonly dateRange: "dateRangePicker";
|
|
@@ -0,0 +1,216 @@
|
|
|
1
|
+
import i18next from "i18next";
|
|
2
|
+
import { z } from "zod";
|
|
3
|
+
import { StringUtils } from "../utils/string.utils.js";
|
|
4
|
+
import { ZodUtils } from "../utils/zod.utils.js";
|
|
5
|
+
const defaultComponentTypes = {
|
|
6
|
+
datetime: "datePicker",
|
|
7
|
+
dateRange: "dateRangePicker",
|
|
8
|
+
textEditor: "textEditor",
|
|
9
|
+
boolean: "toggle",
|
|
10
|
+
number: "numberInput",
|
|
11
|
+
enum: "select",
|
|
12
|
+
string: "textInput",
|
|
13
|
+
email: "textInput",
|
|
14
|
+
object: "unknown",
|
|
15
|
+
array: "select",
|
|
16
|
+
uuid: "select",
|
|
17
|
+
unknown: "unknown"
|
|
18
|
+
};
|
|
19
|
+
const ZOD_TYPE_COMPONENT_TYPE = [
|
|
20
|
+
[z.ZodBoolean, defaultComponentTypes.boolean],
|
|
21
|
+
[z.ZodNumber, defaultComponentTypes.number],
|
|
22
|
+
[z.ZodEnum, defaultComponentTypes.enum],
|
|
23
|
+
[z.ZodISODateTime, defaultComponentTypes.datetime],
|
|
24
|
+
[z.ZodString, defaultComponentTypes.string],
|
|
25
|
+
[z.ZodEmail, defaultComponentTypes.email],
|
|
26
|
+
[z.ZodObject, defaultComponentTypes.object],
|
|
27
|
+
[z.ZodArray, defaultComponentTypes.array],
|
|
28
|
+
[z.ZodUUID, defaultComponentTypes.uuid]
|
|
29
|
+
];
|
|
30
|
+
const DEFAULT_NAMESPACE = "dynamicInputs";
|
|
31
|
+
const sortInputDefs = (inputDefs, orderKeys) => {
|
|
32
|
+
if (!orderKeys) {
|
|
33
|
+
return inputDefs;
|
|
34
|
+
}
|
|
35
|
+
return inputDefs.sort((a, b) => {
|
|
36
|
+
const orderMap = new Map(orderKeys.map((key, index) => [key, index]));
|
|
37
|
+
const orderA = orderMap.get(a.name);
|
|
38
|
+
const orderB = orderMap.get(b.name);
|
|
39
|
+
if (orderA !== void 0 && orderB !== void 0) {
|
|
40
|
+
return orderA - orderB;
|
|
41
|
+
}
|
|
42
|
+
if (orderA !== void 0 && orderB === void 0) {
|
|
43
|
+
return -1;
|
|
44
|
+
}
|
|
45
|
+
if (orderA === void 0 && orderB !== void 0) {
|
|
46
|
+
return 1;
|
|
47
|
+
}
|
|
48
|
+
return 0;
|
|
49
|
+
});
|
|
50
|
+
};
|
|
51
|
+
const excludeEntries = (entries) => {
|
|
52
|
+
return entries.filter(([, value]) => value !== false && value !== void 0);
|
|
53
|
+
};
|
|
54
|
+
const inputConfigToObjectDefinition = (value) => {
|
|
55
|
+
if (typeof value === "object") {
|
|
56
|
+
return value;
|
|
57
|
+
}
|
|
58
|
+
if (typeof value === "function") {
|
|
59
|
+
return { render: value };
|
|
60
|
+
}
|
|
61
|
+
return {};
|
|
62
|
+
};
|
|
63
|
+
const convertInputsConfigToObjectDefinitions = (entries) => {
|
|
64
|
+
return entries.map(([key, value]) => {
|
|
65
|
+
const k = key;
|
|
66
|
+
return [k, inputConfigToObjectDefinition(value)];
|
|
67
|
+
});
|
|
68
|
+
};
|
|
69
|
+
const getDefaultInputComponentType = (schemaType) => {
|
|
70
|
+
if (ZodUtils.isDateRange(schemaType)) {
|
|
71
|
+
return defaultComponentTypes.dateRange;
|
|
72
|
+
}
|
|
73
|
+
if (ZodUtils.isTextEditor(schemaType)) {
|
|
74
|
+
return defaultComponentTypes.textEditor;
|
|
75
|
+
}
|
|
76
|
+
const unwrappedType = ZodUtils.unwrapZodType(schemaType);
|
|
77
|
+
const componentType = ZOD_TYPE_COMPONENT_TYPE.find(([zodType]) => unwrappedType instanceof zodType)?.[1];
|
|
78
|
+
if (componentType) {
|
|
79
|
+
return componentType;
|
|
80
|
+
}
|
|
81
|
+
return defaultComponentTypes.unknown;
|
|
82
|
+
};
|
|
83
|
+
const getDefaultSelectionItems = (keyType) => {
|
|
84
|
+
const unwrappedType = ZodUtils.unwrapZodType(keyType instanceof z.ZodArray ? keyType.element : keyType);
|
|
85
|
+
if (unwrappedType instanceof z.ZodEnum) {
|
|
86
|
+
return Object.values(unwrappedType.options).filter((value) => typeof value === "string").map((value) => ({ id: value, label: StringUtils.capitalize(value) }));
|
|
87
|
+
}
|
|
88
|
+
return [];
|
|
89
|
+
};
|
|
90
|
+
const getDefaultSelectionMode = (keyType) => {
|
|
91
|
+
return keyType instanceof z.ZodArray ? "multiple" : "single";
|
|
92
|
+
};
|
|
93
|
+
const getDefaultProps = (componentType, keyType) => {
|
|
94
|
+
const props = {};
|
|
95
|
+
const unwrappedType = ZodUtils.unwrapZodType(keyType);
|
|
96
|
+
if (["select", "autocomplete", "segment"].includes(componentType)) {
|
|
97
|
+
props.items = getDefaultSelectionItems(unwrappedType);
|
|
98
|
+
}
|
|
99
|
+
if (["select", "autocomplete", "queryAutocomplete", "segment"].includes(componentType)) {
|
|
100
|
+
props.selectionMode = getDefaultSelectionMode(unwrappedType);
|
|
101
|
+
}
|
|
102
|
+
return props;
|
|
103
|
+
};
|
|
104
|
+
const getLabelAndPlaceholder = (value, options, schemaKey) => {
|
|
105
|
+
const namespace = options.namespace ?? DEFAULT_NAMESPACE;
|
|
106
|
+
const stringKey = String(schemaKey);
|
|
107
|
+
let { label, placeholder } = value;
|
|
108
|
+
if (!label) {
|
|
109
|
+
const key = `${namespace}.${stringKey}.label`;
|
|
110
|
+
const translation = i18next.exists(key) ? i18next.t(key) : null;
|
|
111
|
+
label = typeof translation === "string" ? translation : StringUtils.capitalize(stringKey);
|
|
112
|
+
}
|
|
113
|
+
if (!placeholder) {
|
|
114
|
+
const key = `${namespace}.${stringKey}.placeholder`;
|
|
115
|
+
const translation = i18next.exists(key) ? i18next.t(key) : null;
|
|
116
|
+
placeholder = typeof translation === "string" ? translation : void 0;
|
|
117
|
+
}
|
|
118
|
+
return { label, placeholder };
|
|
119
|
+
};
|
|
120
|
+
const overridePresetLabelsAndPlaceholders = (presetInputDefs, options) => {
|
|
121
|
+
const namespace = options.namespace ?? DEFAULT_NAMESPACE;
|
|
122
|
+
return presetInputDefs.map((inputDef) => {
|
|
123
|
+
const labelName = String(inputDef.name);
|
|
124
|
+
const labelKey = `${namespace}.${labelName}.label`;
|
|
125
|
+
const placeholderKey = `${namespace}.${labelName}.placeholder`;
|
|
126
|
+
const labelTranslation = i18next.exists(labelKey) ? i18next.t(labelKey) : null;
|
|
127
|
+
const placeholderTranslation = i18next.exists(placeholderKey) ? i18next.t(placeholderKey) : null;
|
|
128
|
+
return {
|
|
129
|
+
...inputDef,
|
|
130
|
+
label: typeof labelTranslation === "string" ? labelTranslation : inputDef.label,
|
|
131
|
+
placeholder: typeof placeholderTranslation === "string" ? placeholderTranslation : inputDef.placeholder
|
|
132
|
+
};
|
|
133
|
+
});
|
|
134
|
+
};
|
|
135
|
+
const removeOverriddenPresetInputs = (presetInputs, options) => {
|
|
136
|
+
if (presetInputs.length === 0) {
|
|
137
|
+
return presetInputs;
|
|
138
|
+
}
|
|
139
|
+
const usedKeys = new Set(Object.keys(options.inputs ?? {}).map(String));
|
|
140
|
+
return presetInputs.filter((input) => !usedKeys.has(String(input.name)));
|
|
141
|
+
};
|
|
142
|
+
const validateParams = (schema, presetInputs, options) => {
|
|
143
|
+
const { inputs, order, includeAll } = options;
|
|
144
|
+
if (!order) {
|
|
145
|
+
return;
|
|
146
|
+
}
|
|
147
|
+
const inputKeys = Object.keys(inputs ?? {});
|
|
148
|
+
const presetKeys = presetInputs.map((input) => input.name).filter((name) => name !== void 0);
|
|
149
|
+
const schemaKeys = includeAll ? Object.keys(schema.shape) : [];
|
|
150
|
+
const allInputKeys = /* @__PURE__ */ new Set([...inputKeys, ...presetKeys, ...schemaKeys]);
|
|
151
|
+
const unnecessaryOrderKeys = order.filter((key) => !allInputKeys.has(key));
|
|
152
|
+
if (unnecessaryOrderKeys.length > 0) {
|
|
153
|
+
throw new Error(
|
|
154
|
+
`Found unnecessary keys in "order": [${unnecessaryOrderKeys.join(", ")}]. These keys are not found in any of the input definitions.
|
|
155
|
+
All defined input keys are: [${Array.from(allInputKeys).join(", ")}].
|
|
156
|
+
In the case of a preset input definition, the key is the name attribute.`
|
|
157
|
+
);
|
|
158
|
+
}
|
|
159
|
+
};
|
|
160
|
+
const populateInputDef = (schema, schemaKey, value, options) => {
|
|
161
|
+
const name = String(schemaKey);
|
|
162
|
+
const { label, placeholder } = getLabelAndPlaceholder(value, options, schemaKey);
|
|
163
|
+
const inputWrapper = value.inputWrapper ?? options.globalInputWrapper;
|
|
164
|
+
if ("render" in value) {
|
|
165
|
+
return {
|
|
166
|
+
name,
|
|
167
|
+
render: value.render
|
|
168
|
+
};
|
|
169
|
+
}
|
|
170
|
+
const schemaKeyType = schema.shape[schemaKey];
|
|
171
|
+
const componentType = "type" in value ? value.type : getDefaultInputComponentType(schemaKeyType);
|
|
172
|
+
const defaultProps = componentType ? getDefaultProps(componentType, schemaKeyType) : {};
|
|
173
|
+
const props = { ...defaultProps, ...options.globalProps, ...value.props };
|
|
174
|
+
return {
|
|
175
|
+
type: componentType === "unknown" ? null : componentType,
|
|
176
|
+
name,
|
|
177
|
+
label,
|
|
178
|
+
placeholder,
|
|
179
|
+
inputWrapper,
|
|
180
|
+
props
|
|
181
|
+
};
|
|
182
|
+
};
|
|
183
|
+
const addMissingSchemaFields = (schema, existingInputDefs, options) => {
|
|
184
|
+
const schemaFields = Object.keys(schema.shape);
|
|
185
|
+
const definedFields = new Set(existingInputDefs.map((def) => def.name));
|
|
186
|
+
const missingFields = schemaFields.filter((field) => !definedFields.has(field));
|
|
187
|
+
const additionalInputDefs = missingFields.map((field) => {
|
|
188
|
+
return populateInputDef(schema, field, {}, options);
|
|
189
|
+
});
|
|
190
|
+
return [...existingInputDefs, ...additionalInputDefs];
|
|
191
|
+
};
|
|
192
|
+
const dynamicInputs = ({
|
|
193
|
+
schema,
|
|
194
|
+
preset = [],
|
|
195
|
+
options
|
|
196
|
+
}) => {
|
|
197
|
+
validateParams(schema, preset, options);
|
|
198
|
+
let entries = Object.entries(options.inputs ?? {});
|
|
199
|
+
entries = excludeEntries(entries);
|
|
200
|
+
const dynamicInputDefs = convertInputsConfigToObjectDefinitions(entries);
|
|
201
|
+
const inputDefs = dynamicInputDefs.map(([key, value]) => {
|
|
202
|
+
return populateInputDef(schema, key, value, options);
|
|
203
|
+
});
|
|
204
|
+
let presetInputDefs = removeOverriddenPresetInputs(preset, options);
|
|
205
|
+
if (options.overridePresetLocales) {
|
|
206
|
+
presetInputDefs = overridePresetLabelsAndPlaceholders(presetInputDefs, options);
|
|
207
|
+
}
|
|
208
|
+
const mergedInputDefs = [...presetInputDefs, ...inputDefs];
|
|
209
|
+
const allInputDefs = options.includeAll ? addMissingSchemaFields(schema, mergedInputDefs, options) : mergedInputDefs;
|
|
210
|
+
return sortInputDefs(allInputDefs, options.order);
|
|
211
|
+
};
|
|
212
|
+
export {
|
|
213
|
+
dynamicInputs,
|
|
214
|
+
getDefaultInputComponentType,
|
|
215
|
+
getDefaultSelectionMode
|
|
216
|
+
};
|
|
@@ -0,0 +1,83 @@
|
|
|
1
|
+
import { useRef, useEffect } from "react";
|
|
2
|
+
import { useFormState, useWatch } from "react-hook-form";
|
|
3
|
+
import { isEqual } from "../utils/isEqual.js";
|
|
4
|
+
import { ObjectUtils } from "../utils/object.utils.js";
|
|
5
|
+
function isNilOrEqual(left, right) {
|
|
6
|
+
if (ObjectUtils.isNil(left) && ObjectUtils.isNil(right)) {
|
|
7
|
+
return true;
|
|
8
|
+
}
|
|
9
|
+
return isEqual(left, right);
|
|
10
|
+
}
|
|
11
|
+
function diffLeftOnly(left, right, shallowKeys) {
|
|
12
|
+
if (!ObjectUtils.isObject(left) || ObjectUtils.isDate(left) || ObjectUtils.isRegExp(left)) {
|
|
13
|
+
return !isNilOrEqual(left, right) ? left : void 0;
|
|
14
|
+
}
|
|
15
|
+
if (Array.isArray(left)) {
|
|
16
|
+
return !isNilOrEqual(left, right) ? left : void 0;
|
|
17
|
+
}
|
|
18
|
+
const result = Object.entries(left).reduce((acc, [key, value]) => {
|
|
19
|
+
const shallowSubtree = shallowKeys?.[key];
|
|
20
|
+
if (shallowSubtree === true) {
|
|
21
|
+
if (!isNilOrEqual(value, right?.[key])) {
|
|
22
|
+
acc[key] = value;
|
|
23
|
+
}
|
|
24
|
+
return acc;
|
|
25
|
+
}
|
|
26
|
+
const diff = diffLeftOnly(value, right?.[key], shallowSubtree);
|
|
27
|
+
if (diff !== void 0 && (!ObjectUtils.isObject(diff) || !ObjectUtils.isEmpty(diff))) {
|
|
28
|
+
acc[key] = diff;
|
|
29
|
+
}
|
|
30
|
+
return acc;
|
|
31
|
+
}, {});
|
|
32
|
+
return ObjectUtils.isEmpty(result) ? void 0 : result;
|
|
33
|
+
}
|
|
34
|
+
function useAutosave({
|
|
35
|
+
form,
|
|
36
|
+
delay = 500,
|
|
37
|
+
enabled = true,
|
|
38
|
+
onSave,
|
|
39
|
+
onSaveSuccess
|
|
40
|
+
}) {
|
|
41
|
+
const timeoutRef = useRef(void 0);
|
|
42
|
+
const { control, reset, handleSubmit } = form;
|
|
43
|
+
const { dirtyFields, defaultValues } = useFormState({ control });
|
|
44
|
+
const formData = useWatch({ control });
|
|
45
|
+
useEffect(() => {
|
|
46
|
+
if (!enabled || Object.keys(dirtyFields).length === 0) {
|
|
47
|
+
return void 0;
|
|
48
|
+
}
|
|
49
|
+
if (timeoutRef.current) {
|
|
50
|
+
clearTimeout(timeoutRef.current);
|
|
51
|
+
}
|
|
52
|
+
timeoutRef.current = setTimeout(() => {
|
|
53
|
+
handleSubmit(async (data) => {
|
|
54
|
+
const dirtyData = Object.entries(dirtyFields).filter(([, value]) => value).reduce((acc, [key]) => {
|
|
55
|
+
acc[key] = data[key];
|
|
56
|
+
return acc;
|
|
57
|
+
}, {});
|
|
58
|
+
const changedData = diffLeftOnly(dirtyData, defaultValues, dirtyFields) ?? {};
|
|
59
|
+
if (Object.keys(changedData).length === 0) {
|
|
60
|
+
return void 0;
|
|
61
|
+
}
|
|
62
|
+
try {
|
|
63
|
+
reset(void 0, { keepValues: true });
|
|
64
|
+
await onSave(changedData);
|
|
65
|
+
onSaveSuccess?.();
|
|
66
|
+
} catch {
|
|
67
|
+
reset(defaultValues);
|
|
68
|
+
return void 0;
|
|
69
|
+
}
|
|
70
|
+
return void 0;
|
|
71
|
+
})();
|
|
72
|
+
return void 0;
|
|
73
|
+
}, delay);
|
|
74
|
+
return () => {
|
|
75
|
+
if (timeoutRef.current) {
|
|
76
|
+
clearTimeout(timeoutRef.current);
|
|
77
|
+
}
|
|
78
|
+
};
|
|
79
|
+
}, [defaultValues, dirtyFields, formData, delay, onSave, handleSubmit, enabled, reset]);
|
|
80
|
+
}
|
|
81
|
+
export {
|
|
82
|
+
useAutosave
|
|
83
|
+
};
|
|
@@ -0,0 +1,20 @@
|
|
|
1
|
+
import { useMemo } from "react";
|
|
2
|
+
import { useMediaQuery } from "react-responsive";
|
|
3
|
+
function getBreakpoints() {
|
|
4
|
+
const cs = getComputedStyle(document.documentElement);
|
|
5
|
+
const entries = ["sm", "md", "lg", "xl", "2xl"].map((k) => [k, cs.getPropertyValue(`--breakpoint-${k}`).trim()]).filter(([, v]) => !!v);
|
|
6
|
+
return Object.fromEntries(entries);
|
|
7
|
+
}
|
|
8
|
+
function useBreakpoint(breakpointKey) {
|
|
9
|
+
const breakpoints = useMemo(() => getBreakpoints(), []);
|
|
10
|
+
if (!breakpoints) {
|
|
11
|
+
throw new Error("Tailwind config is missing theme.screens");
|
|
12
|
+
}
|
|
13
|
+
const bool = useMediaQuery({
|
|
14
|
+
query: `(min-width: ${breakpoints[breakpointKey]})`
|
|
15
|
+
});
|
|
16
|
+
return bool;
|
|
17
|
+
}
|
|
18
|
+
export {
|
|
19
|
+
useBreakpoint
|
|
20
|
+
};
|