react-restyle-components 0.4.39 → 0.4.41
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/lib/index.js +3 -1
- package/lib/src/core-components/index.js +1 -1
- package/lib/src/core-components/src/components/Accordion/AccordionSection/Accordion.js +15 -1
- package/lib/src/core-components/src/components/Accordion/AccordionSection/AccordionContext.js +6 -1
- package/lib/src/core-components/src/components/Accordion/AccordionSection/AccordionSection.js +39 -1
- package/lib/src/core-components/src/components/Accordion/AccordionSection/Header.js +39 -1
- package/lib/src/core-components/src/components/Accordion/AccordionSection/elements.js +94 -57
- package/lib/src/core-components/src/components/Accordion/AccordionSection/hooks/useCurrentAccordionIndex.js +13 -1
- package/lib/src/core-components/src/components/Accordion/AccordionSection/index.js +3 -1
- package/lib/src/core-components/src/components/Accordion/AccordionSection/types.js +9 -1
- package/lib/src/core-components/src/components/Accordion/Collapsible/Collapsible2.component.js +249 -1
- package/lib/src/core-components/src/components/Action/types.js +8 -1
- package/lib/src/core-components/src/components/AlertBanner/AlertBanner.js +45 -1
- package/lib/src/core-components/src/components/AlertBanner/elements.js +120 -45
- package/lib/src/core-components/src/components/AlertBanner/index.js +2 -1
- package/lib/src/core-components/src/components/AlertBanner/types.js +10 -1
- package/lib/src/core-components/src/components/AutoComplete/auto-complete-filter-group-by-multiple-select-multiple-fields-display/auto-complete-filter-group-by-multiple-select-multiple-fields-display.component.js +334 -1
- package/lib/src/core-components/src/components/AutoComplete/auto-complete-filter-multi-select-multi-fields-display-drag-drop/auto-complete-filter-multi-select-multi-fields-display-drag-drop.component.js +229 -1
- package/lib/src/core-components/src/components/AutoComplete/auto-complete-filter-multi-select-selected-top-display/auto-complete-filter-multi-select-selected-top-display.component.js +174 -1
- package/lib/src/core-components/src/components/AutoComplete/auto-complete-filter-multiple-select-multiple-fields-display/auto-complete-filter-multiple-select-multiple-fields-display.component.js +129 -2
- package/lib/src/core-components/src/components/AutoComplete/auto-complete-filter-single-select/auto-complete-filter-single-select.component.js +55 -1
- package/lib/src/core-components/src/components/AutoComplete/auto-complete-filter-single-select-multiple-fields-display/auto-complete-filter-single-select-multiple-fields-display.component.js +308 -2
- package/lib/src/core-components/src/components/AutoComplete/auto-complete-group-by/auto-complete-group-by.component.js +115 -1
- package/lib/src/core-components/src/components/AutoComplete/autocomplete/autocomplete.js +442 -2
- package/lib/src/core-components/src/components/AutoComplete/index.js +8 -1
- package/lib/src/core-components/src/components/Avatar/Avatar.js +148 -14
- package/lib/src/core-components/src/components/Badge/Badge.js +25 -2
- package/lib/src/core-components/src/components/Badge/InnerBadge/Inline.js +25 -1
- package/lib/src/core-components/src/components/Badge/InnerBadge/InnerBadge.js +25 -1
- package/lib/src/core-components/src/components/Badge/InnerBadge/elements.js +78 -32
- package/lib/src/core-components/src/components/Badge/InnerBadge/index.js +1 -1
- package/lib/src/core-components/src/components/Badge/index.js +1 -1
- package/lib/src/core-components/src/components/Badge/types.js +5 -1
- package/lib/src/core-components/src/components/Breadcrumb/Breadcrumb.js +83 -1
- package/lib/src/core-components/src/components/Breadcrumb/elements.js +166 -94
- package/lib/src/core-components/src/components/Breadcrumb/index.js +3 -1
- package/lib/src/core-components/src/components/Breadcrumb/types.js +3 -1
- package/lib/src/core-components/src/components/Button/button.component.js +18 -1
- package/lib/src/core-components/src/components/Button/buttonGroup/buttonGroup.component.js +4 -1
- package/lib/src/core-components/src/components/Button/index.js +2 -1
- package/lib/src/core-components/src/components/Button/types.js +1 -1
- package/lib/src/core-components/src/components/Chip/Chip.js +64 -1
- package/lib/src/core-components/src/components/Chip/elements.js +148 -48
- package/lib/src/core-components/src/components/Chip/index.js +2 -1
- package/lib/src/core-components/src/components/Chip/types.js +4 -1
- package/lib/src/core-components/src/components/Divider/Divider.js +25 -1
- package/lib/src/core-components/src/components/Divider/elements.js +68 -31
- package/lib/src/core-components/src/components/Divider/index.js +2 -1
- package/lib/src/core-components/src/components/Divider/types.js +4 -1
- package/lib/src/core-components/src/components/DynamicGrid/DynamicGrid.js +147 -1
- package/lib/src/core-components/src/components/DynamicGrid/GridContainer.js +24 -17
- package/lib/src/core-components/src/components/DynamicGrid/elements.js +162 -100
- package/lib/src/core-components/src/components/DynamicGrid/index.js +3 -1
- package/lib/src/core-components/src/components/DynamicGrid/types.js +28 -1
- package/lib/src/core-components/src/components/DynamicGrid/utils.js +193 -1
- package/lib/src/core-components/src/components/FormField/FormField.js +103 -1
- package/lib/src/core-components/src/components/FormField/components/CheckboxGroupInput.js +37 -1
- package/lib/src/core-components/src/components/FormField/components/CheckboxInput.js +8 -1
- package/lib/src/core-components/src/components/FormField/components/CssMultilineInput.js +192 -1
- package/lib/src/core-components/src/components/FormField/components/DatePickerInput.js +99 -1
- package/lib/src/core-components/src/components/FormField/components/DropdownInput.js +70 -1
- package/lib/src/core-components/src/components/FormField/components/OtpInput.js +81 -1
- package/lib/src/core-components/src/components/FormField/components/PasswordInput.js +40 -1
- package/lib/src/core-components/src/components/FormField/components/PinInput.js +75 -1
- package/lib/src/core-components/src/components/FormField/components/RadioInput.js +54 -1
- package/lib/src/core-components/src/components/FormField/components/TextDropdownInput.js +94 -1
- package/lib/src/core-components/src/components/FormField/components/ToggleInput.js +36 -1
- package/lib/src/core-components/src/components/FormField/components/index.js +11 -1
- package/lib/src/core-components/src/components/FormField/css-properties.js +161 -1
- package/lib/src/core-components/src/components/FormField/index.js +2 -1
- package/lib/src/core-components/src/components/Icon/Icon.js +79 -1
- package/lib/src/core-components/src/components/Icon/index.js +2 -1
- package/lib/src/core-components/src/components/Icon/types.js +9 -1
- package/lib/src/core-components/src/components/Loader/loader.component.js +215 -2
- package/lib/src/core-components/src/components/Masonry/Masonry.js +73 -1
- package/lib/src/core-components/src/components/Masonry/elements.js +46 -29
- package/lib/src/core-components/src/components/Masonry/hooks.js +100 -1
- package/lib/src/core-components/src/components/Masonry/index.js +3 -1
- package/lib/src/core-components/src/components/Masonry/types.js +1 -1
- package/lib/src/core-components/src/components/Modal/BasicModal/modal.component.js +116 -1
- package/lib/src/core-components/src/components/Modal/index.js +2 -1
- package/lib/src/core-components/src/components/Modal/modal-confirm/modal-confirm.component.js +147 -1
- package/lib/src/core-components/src/components/Picker/color-picker/color-picker.component.js +12 -1
- package/lib/src/core-components/src/components/Picker/color-picker-modal/color-picker-modal.component.js +40 -1
- package/lib/src/core-components/src/components/Picker/index.js +2 -1
- package/lib/src/core-components/src/components/Selection/index.js +4 -1
- package/lib/src/core-components/src/components/Selection/multi-select/multi-select.component.js +49 -1
- package/lib/src/core-components/src/components/Selection/multi-select-with-field/multi-select-with-field.component.js +58 -1
- package/lib/src/core-components/src/components/Selection/multi-selection-dropdown/multi-selection-dropdown.component.js +43 -1
- package/lib/src/core-components/src/components/Selection/single-select/single-select.component.js +87 -1
- package/lib/src/core-components/src/components/Skeleton/Skeleton.js +51 -1
- package/lib/src/core-components/src/components/Skeleton/elements.js +143 -54
- package/lib/src/core-components/src/components/Skeleton/index.js +2 -1
- package/lib/src/core-components/src/components/Skeleton/types.js +4 -1
- package/lib/src/core-components/src/components/SpeedDial/SpeedDial.js +128 -1
- package/lib/src/core-components/src/components/SpeedDial/elements.js +132 -62
- package/lib/src/core-components/src/components/SpeedDial/index.js +2 -1
- package/lib/src/core-components/src/components/SpeedDial/types.js +3 -1
- package/lib/src/core-components/src/components/Stepper2/stepper.component.js +139 -1
- package/lib/src/core-components/src/components/Switch/Switch.js +26 -1
- package/lib/src/core-components/src/components/Switch/elements.js +103 -34
- package/lib/src/core-components/src/components/Switch/index.js +2 -1
- package/lib/src/core-components/src/components/Switch/types.js +3 -1
- package/lib/src/core-components/src/components/Table/Table.js +1357 -1
- package/lib/src/core-components/src/components/Table/columnReorder.d.ts +128 -0
- package/lib/src/core-components/src/components/Table/columnReorder.js +530 -0
- package/lib/src/core-components/src/components/Table/columnResize.d.ts +99 -0
- package/lib/src/core-components/src/components/Table/columnResize.js +399 -0
- package/lib/src/core-components/src/components/Table/elements.d.ts +9 -1
- package/lib/src/core-components/src/components/Table/elements.js +324 -155
- package/lib/src/core-components/src/components/Table/filters.js +555 -30
- package/lib/src/core-components/src/components/Table/hooks.js +536 -2
- package/lib/src/core-components/src/components/Table/index.d.ts +4 -0
- package/lib/src/core-components/src/components/Table/index.js +6 -1
- package/lib/src/core-components/src/components/Table/types.d.ts +58 -0
- package/lib/src/core-components/src/components/Table/types.js +1 -1
- package/lib/src/core-components/src/components/Tabs/tabs.component.js +22 -1
- package/lib/src/core-components/src/components/Tags1/Tags.component.js +118 -1
- package/lib/src/core-components/src/components/Tags1/types.js +20 -1
- package/lib/src/core-components/src/components/Timer1/timer.component.js +76 -1
- package/lib/src/core-components/src/components/Toast/Toast.js +50 -1
- package/lib/src/core-components/src/components/Toast/elements.js +122 -41
- package/lib/src/core-components/src/components/Toast/index.js +2 -1
- package/lib/src/core-components/src/components/Toast/types.js +9 -1
- package/lib/src/core-components/src/components/Tooltip/Tooltip.js +200 -1
- package/lib/src/core-components/src/components/Tooltip/elements.js +117 -55
- package/lib/src/core-components/src/components/Tooltip/index.js +2 -1
- package/lib/src/core-components/src/components/Tooltip/types.js +17 -1
- package/lib/src/core-components/src/components/Tooltip/utils.js +140 -1
- package/lib/src/core-components/src/components/TreeSelect/TreeSelect.js +303 -1
- package/lib/src/core-components/src/components/TreeSelect/elements.js +216 -117
- package/lib/src/core-components/src/components/TreeSelect/hooks.js +252 -1
- package/lib/src/core-components/src/components/TreeSelect/index.js +3 -1
- package/lib/src/core-components/src/components/TreeSelect/types.js +1 -1
- package/lib/src/core-components/src/components/ag-grid/AgGrid.d.ts +11 -0
- package/lib/src/core-components/src/components/ag-grid/AgGrid.js +733 -0
- package/lib/src/core-components/src/components/ag-grid/elements.d.ts +246 -0
- package/lib/src/core-components/src/components/ag-grid/elements.js +1156 -0
- package/lib/src/core-components/src/components/ag-grid/hooks.d.ts +196 -0
- package/lib/src/core-components/src/components/ag-grid/hooks.js +943 -0
- package/lib/src/core-components/src/components/ag-grid/index.d.ts +9 -0
- package/lib/src/core-components/src/components/ag-grid/index.js +13 -0
- package/lib/src/core-components/src/components/ag-grid/types.d.ts +1367 -0
- package/lib/src/core-components/src/components/ag-grid/types.js +6 -0
- package/lib/src/core-components/src/components/index.d.ts +1 -0
- package/lib/src/core-components/src/components/index.js +31 -1
- package/lib/src/core-components/src/components/pdf/pdf-images.components.js +7 -1
- package/lib/src/core-components/src/components/pdf/pdf-table.components.js +48 -5
- package/lib/src/core-components/src/components/pdf/pdf-typography.components.js +70 -1
- package/lib/src/core-components/src/components/pdf/pdf-wrapped-view.components.js +50 -1
- package/lib/src/core-components/src/core-components/Avatar.js +33 -4
- package/lib/src/core-components/src/core-components/CoreButton/CoreButton.js +10 -1
- package/lib/src/core-components/src/core-components/CoreButton/elements.js +176 -67
- package/lib/src/core-components/src/core-components/CoreButton/index.js +3 -1
- package/lib/src/core-components/src/core-components/CoreButton/types.js +6 -1
- package/lib/src/core-components/src/core-components/CoreButton/utils.js +12 -1
- package/lib/src/core-components/src/core-components/Divider/Divider.js +19 -4
- package/lib/src/core-components/src/core-components/Divider/index.js +1 -1
- package/lib/src/core-components/src/core-components/SelectionCardStrip/index.js +1 -1
- package/lib/src/core-components/src/core-components/SelectionCardStrip/selectionCardStrip.js +33 -10
- package/lib/src/core-components/src/core-components/StateLayer.js +5 -3
- package/lib/src/core-components/src/core-components/ToggleCore/elements.js +50 -25
- package/lib/src/core-components/src/core-components/ToggleCore/index.js +2 -1
- package/lib/src/core-components/src/core-components/ToggleCore/toggleCore.js +14 -1
- package/lib/src/core-components/src/core-components/atoms/Input/Input.js +22 -1
- package/lib/src/core-components/src/core-components/atoms/Label/Label.js +21 -1
- package/lib/src/core-components/src/core-components/atoms/Textarea/Textarea.js +19 -1
- package/lib/src/core-components/src/core-components/index.js +3 -1
- package/lib/src/core-components/src/helpers/constants.js +11 -1
- package/lib/src/core-components/src/hooks/index.js +1 -1
- package/lib/src/core-components/src/hooks/outside.hook.js +28 -1
- package/lib/src/core-components/src/index.js +12 -1
- package/lib/src/core-components/src/tc.global.css +16 -3
- package/lib/src/core-components/src/tc.module.css +2 -2
- package/lib/src/core-components/src/utils/abstracts/breakpoints/index.js +28 -1
- package/lib/src/core-components/src/utils/abstracts/colors/index.js +49 -1
- package/lib/src/core-components/src/utils/abstracts/index.js +5 -1
- package/lib/src/core-components/src/utils/abstracts/space/index.js +26 -1
- package/lib/src/core-components/src/utils/abstracts/theme/ThemeBoundary.js +8 -1
- package/lib/src/core-components/src/utils/abstracts/theme/default-themes.js +30 -1
- package/lib/src/core-components/src/utils/abstracts/theme/index.js +3 -1
- package/lib/src/core-components/src/utils/abstracts/theme/theme.js +30 -1
- package/lib/src/core-components/src/utils/abstracts/theme/types.js +1 -1
- package/lib/src/core-components/src/utils/abstracts/theme/useTheme.js +17 -1
- package/lib/src/core-components/src/utils/abstracts/typography/index.js +25 -1
- package/lib/src/core-components/src/utils/context/DefaultsProvider.js +8 -1
- package/lib/src/core-components/src/utils/context/InternalProvider.js +24 -1
- package/lib/src/core-components/src/utils/context/index.js +2 -1
- package/lib/src/core-components/src/utils/designTokens.js +125 -1
- package/lib/src/core-components/src/utils/helpers/attachSubComponents.js +23 -1
- package/lib/src/core-components/src/utils/helpers/flattenChildren.js +11 -1
- package/lib/src/core-components/src/utils/helpers/getChildByType.js +3 -1
- package/lib/src/core-components/src/utils/helpers/index.js +5 -1
- package/lib/src/core-components/src/utils/helpers/isComponentType.js +16 -1
- package/lib/src/core-components/src/utils/helpers/separateChildrenByType.js +12 -1
- package/lib/src/core-components/src/utils/hooks/index.js +18 -1
- package/lib/src/core-components/src/utils/hooks/useClickOutside.js +18 -1
- package/lib/src/core-components/src/utils/hooks/useCombinedRefs.js +17 -1
- package/lib/src/core-components/src/utils/hooks/useDebouncedCallback.js +12 -1
- package/lib/src/core-components/src/utils/hooks/useDebouncedValue.js +20 -1
- package/lib/src/core-components/src/utils/hooks/useDeprecation.js +40 -1
- package/lib/src/core-components/src/utils/hooks/useDeviceDetect.js +10 -1
- package/lib/src/core-components/src/utils/hooks/useDeviceForm.js +24 -1
- package/lib/src/core-components/src/utils/hooks/useDisableBodyScroll.js +16 -1
- package/lib/src/core-components/src/utils/hooks/useHoverState.js +36 -1
- package/lib/src/core-components/src/utils/hooks/useId.js +7 -1
- package/lib/src/core-components/src/utils/hooks/useIsBrowser.js +11 -1
- package/lib/src/core-components/src/utils/hooks/useMediaQuery.js +16 -1
- package/lib/src/core-components/src/utils/hooks/useOverflow.js +22 -1
- package/lib/src/core-components/src/utils/hooks/useSafeLayoutEffect.js +5 -1
- package/lib/src/core-components/src/utils/hooks/useScrollingUp.js +18 -1
- package/lib/src/core-components/src/utils/hooks/useTrapFocus.js +30 -1
- package/lib/src/core-components/src/utils/hooks/useWindowDimensions.js +23 -1
- package/lib/src/core-components/src/utils/index.js +9 -1
- package/lib/src/core-components/src/utils/stories/Wrappers.js +23 -8
- package/lib/src/core-components/src/utils/stories/cleanProps.js +5 -1
- package/lib/src/core-components/src/utils/stories/index.js +4 -1
- package/lib/src/core-components/src/utils/stories/sleep.js +4 -1
- package/lib/src/core-components/src/utils/stories/view-ports.js +50 -1
- package/lib/src/core-components/src/utils/styling/calcWidthOfColumns.js +5 -1
- package/lib/src/core-components/src/utils/styling/createGridContainer.js +12 -6
- package/lib/src/core-components/src/utils/styling/createTransition.js +7 -2
- package/lib/src/core-components/src/utils/styling/forwardProps.js +10 -1
- package/lib/src/core-components/src/utils/styling/index.js +5 -1
- package/lib/src/core-components/src/utils/styling/pxToRem.js +6 -1
- package/lib/src/core-components/src/utils/testing/getComputedStyle.js +3 -1
- package/lib/src/core-components/src/utils/testing/index.js +1 -1
- package/lib/src/core-components/src/utils/utility.util.js +14 -1
- package/lib/src/core-components/tailwind.config.js +233 -1
- package/lib/src/core-hooks/index.js +3 -1
- package/lib/src/core-hooks/src/useClickOutside/useClickOutside.hook.js +46 -1
- package/lib/src/core-hooks/src/useDebounce/useDebounce.hook.js +30 -1
- package/lib/src/core-hooks/src/usePreventEKey/usePreventEKey.hook.js +8 -1
- package/lib/src/core-utils/index.js +7 -1
- package/lib/src/core-utils/src/calculation/calculation.util.js +89 -1
- package/lib/src/core-utils/src/colors/color.util.js +15 -1
- package/lib/src/core-utils/src/convert/numberToWords/numToWords.util.js +145 -1
- package/lib/src/core-utils/src/convert/typography/camelCaseToTitleCase.util.js +5 -1
- package/lib/src/core-utils/src/form-helper/form-helper.util.js +82 -1
- package/lib/src/core-utils/src/index.js +7 -1
- package/lib/src/core-utils/src/utility/utility.util.js +12 -1
- package/lib/src/core-utils/src/uuid/uuid.util.js +8 -1
- package/package.json +1 -1
|
@@ -1 +1,1357 @@
|
|
|
1
|
-
"use strict";"use client";import{jsx as t,jsxs as s}from"react/jsx-runtime";import Yn,{forwardRef as Un,useState as O,useCallback as u,useMemo as me,useEffect as _,useRef as $}from"react";import{TableRoot as Qn,Toolbar as _n,ToolbarGroup as Ie,SearchInput as qn,ToolbarButton as K,TableWrapper as Gn,StyledTable as Xn,TableHeader as Zn,HeaderRow as er,HeaderCell as we,TableBody as tr,TableRow as nr,TableCell as ve,Checkbox as Et,ExpandButton as rr,ExpandedRow as or,ExpandedCell as ir,TableFooter as lr,FooterRow as ar,FooterCell as Re,PaginationWrapper as sr,PaginationInfo as dr,PaginationControls as cr,PageButton as q,PageSizeSelect as hr,QuickJumper as fr,EmptyState as pr,LoadingOverlay as ur,LoadingSpinner as gr,EditableCell as Cr,CellEditor as yr,ColumnTogglePanel as Tt,ColumnToggleHeader as Nt,ColumnToggleSearch as Lt,ColumnToggleList as Mt,ColumnToggleItem as Je,SelectionIndicator as br,SelectionCount as kr}from"./elements";import{useSortState as Sr,useFilterState as Fr,usePaginationState as xr,useRowSelection as mr,useRowExpansion as wr,useColumnVisibility as vr,useTableDebounce as Rr,sortData as $r,filterData as Ye,paginateData as Er,getNestedValue as G,exportToCSV as Tr,exportToExcel as Nr}from"./hooks";import{getFilterComponent as Lr}from"./filters";import{Tooltip as Mr}from"../Tooltip";const Pr=()=>s("svg",{viewBox:"0 0 24 24",fill:"none",stroke:"currentColor",strokeWidth:"2",children:[t("circle",{cx:"11",cy:"11",r:"8"}),t("path",{d:"M21 21l-4.35-4.35",strokeLinecap:"round"})]}),jr=({size:M=14})=>t("svg",{viewBox:"0 0 24 24",fill:"none",stroke:"currentColor",strokeWidth:"2.5",strokeLinecap:"round",strokeLinejoin:"round",style:{width:M,height:M},children:t("path",{d:"M12 19V5M5 12l7-7 7 7"})}),Br=({size:M=14})=>t("svg",{viewBox:"0 0 24 24",fill:"none",stroke:"currentColor",strokeWidth:"2.5",strokeLinecap:"round",strokeLinejoin:"round",style:{width:M,height:M},children:t("path",{d:"M12 5v14M5 12l7 7 7-7"})}),Lo=()=>t("svg",{viewBox:"0 0 10 10",fill:"currentColor",children:t("path",{d:"M5 0L10 6H0L5 0z"})}),Mo=()=>t("svg",{viewBox:"0 0 10 10",fill:"currentColor",children:t("path",{d:"M5 10L0 4h10L5 10z"})}),Pt=({order:M})=>{const $e=()=>{switch(M){case"asc":return{up:16,down:10};case"desc":return{up:10,down:16};default:return{up:14,down:14}}},{up:I,down:de}=$e();return s("div",{style:{display:"flex",flexDirection:"row",alignItems:"center",justifyContent:"center",gap:2,color:"white"},children:[t(jr,{size:I}),t(Br,{size:de})]})},Wr=()=>t("svg",{viewBox:"0 0 24 24",fill:"none",stroke:"currentColor",strokeWidth:"2",children:t("path",{d:"M15 18l-6-6 6-6",strokeLinecap:"round",strokeLinejoin:"round"})}),Dr=()=>t("svg",{viewBox:"0 0 24 24",fill:"none",stroke:"currentColor",strokeWidth:"2",children:t("path",{d:"M9 18l6-6-6-6",strokeLinecap:"round",strokeLinejoin:"round"})}),Vr=()=>t("svg",{viewBox:"0 0 24 24",fill:"none",stroke:"currentColor",strokeWidth:"2",children:t("path",{d:"M11 17l-5-5 5-5M18 17l-5-5 5-5",strokeLinecap:"round",strokeLinejoin:"round"})}),zr=()=>t("svg",{viewBox:"0 0 24 24",fill:"none",stroke:"currentColor",strokeWidth:"2",children:t("path",{d:"M13 7l5 5-5 5M6 7l5 5-5 5",strokeLinecap:"round",strokeLinejoin:"round"})}),Hr=()=>t("svg",{viewBox:"0 0 24 24",fill:"none",stroke:"currentColor",strokeWidth:"2",children:t("path",{d:"M9 18l6-6-6-6",strokeLinecap:"round",strokeLinejoin:"round"})}),jt=()=>t("svg",{viewBox:"0 0 24 24",fill:"none",stroke:"currentColor",strokeWidth:"2",children:t("path",{d:"M18 6L6 18M6 6l12 12",strokeLinecap:"round",strokeLinejoin:"round"})}),Ar=()=>t("svg",{viewBox:"0 0 24 24",fill:"none",stroke:"currentColor",strokeWidth:"2",children:t("path",{d:"M22 3H2l8 9.46V19l4 2v-8.54L22 3z",strokeLinecap:"round",strokeLinejoin:"round"})}),Or=()=>t("svg",{viewBox:"0 0 24 24",fill:"none",stroke:"currentColor",strokeWidth:"2",children:t("path",{d:"M21 15v4a2 2 0 01-2 2H5a2 2 0 01-2-2v-4M7 10l5 5 5-5M12 15V3",strokeLinecap:"round",strokeLinejoin:"round"})}),Kr=()=>s("svg",{viewBox:"0 0 24 24",fill:"none",stroke:"currentColor",strokeWidth:"2",children:[t("rect",{x:"3",y:"3",width:"7",height:"18",rx:"1"}),t("rect",{x:"14",y:"3",width:"7",height:"18",rx:"1"})]}),Ir=()=>s("svg",{viewBox:"0 0 24 24",fill:"none",stroke:"currentColor",strokeWidth:"1.5",children:[t("rect",{x:"3",y:"3",width:"18",height:"18",rx:"2"}),t("path",{d:"M3 9h18M9 3v18",strokeLinecap:"round"})]}),Jr=()=>s("svg",{viewBox:"0 0 24 24",fill:"none",stroke:"currentColor",strokeWidth:"2",children:[t("path",{d:"M23 4v6h-6M1 20v-6h6",strokeLinecap:"round",strokeLinejoin:"round"}),t("path",{d:"M3.51 9a9 9 0 0114.85-3.36L23 10M1 14l4.64 4.36A9 9 0 0020.49 15",strokeLinecap:"round",strokeLinejoin:"round"})]}),Yr=()=>s("svg",{viewBox:"0 0 24 24",fill:"none",stroke:"currentColor",strokeWidth:"2",children:[t("path",{d:"M6 9V2h12v7M6 18H4a2 2 0 01-2-2v-5a2 2 0 012-2h16a2 2 0 012 2v5a2 2 0 01-2 2h-2",strokeLinecap:"round",strokeLinejoin:"round"}),t("rect",{x:"6",y:"14",width:"12",height:"8"})]}),Po=()=>s("svg",{viewBox:"0 0 24 24",fill:"none",stroke:"currentColor",strokeWidth:"2",children:[t("circle",{cx:"12",cy:"12",r:"10"}),t("path",{d:"M12 8v4M12 16h.01",strokeLinecap:"round",strokeLinejoin:"round"})]});export const Table=Un(function($e,I){const{id:de,data:g,columns:R,keyField:E="_id",loading:Bt=!1,loadingIndicator:Wt,pagination:ce=!0,paginationConfig:Ue,totalSize:N,remote:Qe=!0,defaultSort:Dt,sort:Vt,filterable:zt=!1,defaultFilters:Ht,filters:At,defaultShowFilters:Ot=!0,showFilters:_e,onShowFiltersChange:qe,showFilterToggle:Ge=!0,searchable:Xe=!0,searchPlaceholder:Kt="Search...",defaultSearchValue:It="",searchValue:Jt,searchDebounce:Yt=300,rowSelection:P,expandable:p,editMode:J="dblclick",showEditIcon:Ut=!1,onCellEdit:Ze,exportable:Qt=!0,exportFileName:_t="table_export",exportFormat:Ee="csv",columnToggle:qt=!1,bordered:Gt=!0,striped:Xt=!1,hover:Zt=!0,compact:x=!1,cellPadding:he,stickyHeader:et=!1,maxHeight:en,rowClassName:Te,rowStyle:Ne,classNames:b={},styles:k={},className:tn,style:nn,emptyText:rn="No data available",onChange:w,onPageChange:fe,onSortChange:tt,onFilterChange:pe,onSearch:nt,onRowClick:Le,onRowDoubleClick:Me,onClearFilters:rt,toolbar:ue,hideToolbar:on=!1,showFooter:ln=!1,caption:ot,isDelete:Ur=!1,isEditModify:Qr,isUpdate:_r,isExport:an,isSelectRow:it,getNonSelectableRows:sn,nonSelectableStyle:dn,isView:qr=!1,fileName:cn,hideExcelSheet:ge=!1,onSelectedRow:hn,selectedRowStyle:fn,selectedRowClassName:pn,onUpdateItem:X,onPageSizeChange:Ce,onFilter:Pe,clearAllFilter:un,onDelete:Gr,onEdit:Xr,onView:Zr,dynamicStylingFields:eo,fieldTypeConfig:Y,showRowNumber:Z=!1,rowNumberWidth:lt=50,rowNumberTitle:gn="#",rowNumberRender:at,toolbarPosition:to="top",toolbarLeft:Cn,toolbarRight:yn,toolbarCenter:bn,refreshable:kn=!1,onRefresh:Sn,printable:Fn=!1,onPrint:xn,size:no="medium",error:ro,onRetry:oo,skeletonLoading:io=!1,skeletonRowCount:lo=5,hideHeader:ao=!1,highlightedRowKeys:so=[],highlightRowStyle:co,highlightRowClassName:ho,onRowMouseEnter:fo,onRowMouseLeave:po,onCellClick:uo,onHeaderClick:go,...st}=$e,mn=an??Qt,je=cn??_t,D=me(()=>N!==void 0&&N>0&&N<=g.length?!1:Qe,[Qe,N,g.length]),f=it?{mode:"checkbox",selectedRowStyle:fn||P?.selectedRowStyle,selectedRowClassName:pn||P?.selectedRowClassName,...P,getCheckboxProps:e=>{const n=e[E],r=sn?.includes(n),o=P?.getCheckboxProps?.(e);return{...o,disabled:r||o?.disabled}},onChange:(e,n)=>{P?.onChange?.(e,n)}}:P,j=ce?{page:0,pageSize:10,showSizeChanger:!0,showQuickJumper:!0,showTotal:!0,pageSizeOptions:[10,20,30,50],...Ue}:Ue,Co={small:{padding:"4px 8px",fontSize:"12px"},medium:{padding:"8px 12px",fontSize:"14px"},large:{padding:"12px 16px",fontSize:"16px"}},wn=$(null),ye=$(null),dt=$(0),[vn,ct]=O(It),[Rn,$n]=O(Ot),[B,ee]=O(!1),[be,ht]=O(""),[En,Be]=O("none");_(()=>{if(!B)return;const e=n=>{ye.current&&!ye.current.contains(n.target)&&ee(!1)};return document.addEventListener("mousedown",e),()=>{document.removeEventListener("mousedown",e)}},[B]);const We=_e!==void 0,De=We?_e:Rn,yo=u(()=>{const e=!De;We||$n(e),qe?.(e)},[De,We,qe]),[V,L]=O(null),[T,ke]=O(null),U=Jt??vn,v=Rr(U,Yt),{sort:S,handleSort:ft}=Sr(Dt,Vt),{filters:F,setFilter:pt,clearFilters:ut}=Fr(Ht,At),te=$(!1),Se=$("filter"),gt=$(Pe),Tn=$(null),ne=$(null),re=$(null);_(()=>{const e=n=>{re.current&&!re.current.contains(n.target)&&(ne.current=null)};return document.addEventListener("mousedown",e),()=>{document.removeEventListener("mousedown",e)}},[]),_(()=>{const e=()=>{if(ne.current&&re.current){const r=re.current.querySelector(`[data-filter-field="${ne.current}"]`);if(r&&document.activeElement!==r){r.focus();const o=r.value?.length||0;r.setSelectionRange(o,o)}}},n=[requestAnimationFrame(()=>e()),setTimeout(()=>e(),50),setTimeout(()=>e(),150)];return()=>{n.forEach(r=>{typeof r=="number"&&(cancelAnimationFrame(r),clearTimeout(r))})}},[g]);const{page:C,pageSize:m,totalPages:bo,goToPage:Ct,goToNextPage:ko,goToPrevPage:So,goToFirstPage:Fo,goToLastPage:xo,changePageSize:yt}=xr(j?.page||0,j?.pageSize||10,N??g.length),{selectedKeys:z,isSelected:Nn,toggleRow:Fe,toggleAll:bt,isAllSelected:Ve,isIndeterminate:Ln}=mr(g,f?.keyField||E,f?.mode||"none",f?.selectedRowKeys,f?.getCheckboxProps),{expandedKeys:mo,isExpanded:Mn,toggleExpand:oe}=wr(p?.keyField||E,p?.defaultExpandedRowKeys,p?.expandedRowKeys,p?.accordion),{visibleColumns:H,toggleColumn:xe,isColumnHidden:ie}=vr(R,de);_(()=>{gt.current=Pe},[Pe]);const kt=$(v),St=$(JSON.stringify(F));_(()=>{if(!te.current)return;const e=JSON.stringify(F),n=kt.current!==v,r=St.current!==e;if(!n&&!r){te.current=!1;return}kt.current=v,St.current=e;const o={};Object.keys(F).forEach(i=>{const d=F[i];d!=null&&d!==""&&(o[i]=d)});const a=Object.keys(o).length>0,c={...o};Se.current==="search"&&v&&(c.srText=v),gt.current?.(Se.current,c,C,m),te.current=!1},[v,F,C,m]),_(()=>{const e=z.size,n=dt.current;e>n?Be("up"):e<n&&Be("down"),dt.current=e;const r=setTimeout(()=>{Be("none")},300);return()=>clearTimeout(r)},[z.size]);const ze=me(()=>{if(D)return g;let e=[...g];return e=Ye(e,F,R,v),e=$r(e,S,R),ce&&(e=Er(e,C,m)),e},[g,F,S,C,m,v,D,ce,R]),le=me(()=>N!==void 0&&N>0?N:D?g.length:Ye(g,F,R,v).length,[g,F,R,v,D,N]),He=u(e=>{ct(e),nt?.(e),te.current=!0,Se.current="search",w?.({type:"search",search:e})},[nt,w]),Ae=u(e=>{if(!e.sort)return;const n=ft(e.dataField,S.order);tt?.(n),w?.({type:"sort",sort:n})},[S,ft,tt,w]),Ft=u((e,n)=>{pt(e,n);const r={...F,[e]:n};pe?.(r),te.current=!0,Se.current="filter",w?.({type:"filter",filters:r})},[F,pt,pe,w]),xt=u(()=>{ut(),ct(""),rt?.(),un?.(),pe?.({}),w?.({type:"filter",filters:{}}),Tn.current=null},[ut,rt,pe,w]),Q=u(e=>{Ct(e);const n=e+1;Ce?.(n,m),fe?.(n,m),w?.({type:"pagination",pagination:{page:n,pageSize:m}})},[Ct,m,Ce,fe,w]),Pn=u(e=>{yt(e),Ce?.(1,e),fe?.(1,e),w?.({type:"pagination",pagination:{page:1,pageSize:e}})},[yt,Ce,fe,w]),jn=u((e,n,r)=>{if(f?.mode==="single"){const o=Fe(e);o&&f?.onChange?.(o.selectedKeys,o.selectedRows)}if(p?.expandRowByClick){const o=oe(e);o&&p.onExpandChange?.(o.expandedKeys,o.expanded,e)}Le?.(e,n,r)},[P,p,Fe,oe,Le]),ae=u((e,n,r,o)=>{const a=!!e.editorRenderer;if(e.editable===void 0)return{isEditable:a};if(e.editable===!1)return{isEditable:!1};if(e.editable===!0)return{isEditable:!0};const c=G(n,e.dataField),i=e.editable(c,n,r,o);return typeof i=="boolean"?{isEditable:i}:{isEditable:!0,customEditor:i}},[]),Bn=u((e,n,r,o,a)=>{if(r.events?.onDoubleClick?.(a,e,n,r,o),J!=="none"){const{isEditable:c}=ae(r,e,n,o);c&&J==="dblclick"&&(L({row:n,field:r.dataField}),ke(G(e,r.dataField)))}Me?.(e,n,a)},[J,Me,ae]),Wn=u((e,n,r,o,a)=>{if(a&&r.events?.onClick?.(a,e,n,r,o),J==="click"){const{isEditable:c}=ae(r,e,n,o);c&&(L({row:n,field:r.dataField}),ke(G(e,r.dataField)))}},[J,ae]),Oe=u((e,n,r)=>{if(V){if(r.validator){const a=r.validator(T,e);if(a!==!0){alert(typeof a=="string"?a:"Invalid value"),L(null);return}}const o=e[E];Ze?.(T,r.dataField,e,n),X?.(T,r.dataField,o)}L(null)},[V,T,Ze,X,E]),Dn=(e,n)=>n.split(".").reduce((r,o)=>r?.[o],e),mt=u((e,n,r)=>{const o=Y?.[n],a=typeof o=="string"?{type:o}:o;switch(a?.type||"string"){case"array":return a?.fields&&a.fields.length>0?Array.isArray(e)?e.slice(0,a.maxItems||e.length).map(l=>typeof l=="object"&&a.fields?a.fields.map(y=>l[y]).filter(Boolean).join(", "):typeof l=="string"?l:"").filter(Boolean).join(a.separator||"; "):e||"":Array.isArray(e)?e.map(l=>typeof l=="object"?JSON.stringify(l):l).join("; "):e||"";case"object":if(!e||typeof e!="object")return"";const i=a?.fields||a?.keys||[],d=a?.labelMap||{};return i.length>0?i.map(l=>{const y=Dn(e,l);return y!=null?`${d[l]||l}: ${y}`:null}).filter(Boolean).join(", "):Object.entries(e).map(([l,y])=>typeof y=="boolean"?`${l}: ${y?"Yes":"No"}`:`${l}: ${y}`).join(", ");case"date":if(!e)return"";try{const l=new Date(e),y=a?.dateFormat||"YYYY-MM-DD HH:mm:ss";return l.toISOString().slice(0,19).replace("T"," ")}catch{return String(e)}case"number":return e!=null?String(Number(e)):"";case"boolean":return typeof e=="boolean"?e?"Yes":"No":"";default:return typeof e=="boolean"?e?"Yes":"No":e!=null?String(e):""}},[Y]),wt=u(async()=>{const e=D?g:Ye(g,F,R,v);let n=H.filter(o=>o.csvExport!==!1);Array.isArray(ge)&&(n=n.filter(o=>!ge.includes(o.dataField))),Y&&(n=n.filter(o=>{const a=Y[o.dataField],c=typeof a=="string"?{type:a}:a;return!(c?.hideFromExport||c?.csvExport===!1)}));const r=n.map(o=>{const a=Y?.[o.dataField],c=typeof a=="string"?{type:a}:a;return o.csvFormatter?o:c?.exportFormatter?{...o,csvFormatter:c.exportFormatter}:c?.type?{...o,csvFormatter:(i,d)=>mt(i,o.dataField,d)}:o});Ee==="excel"?await Nr(e,r,je):Tr(e,r,je)},[g,F,R,v,H,ge,Y,mt,je,D,Ee]),Vn=u((e,n)=>{n.stopPropagation();const r=Fe(e);r&&f?.onChange?.(r.selectedKeys,r.selectedRows)},[Fe,P]),zn=u(()=>{const e=bt(!Ve);e&&f?.onChange?.(e.selectedKeys,e.selectedRows)},[bt,Ve,f]),Hn=u((e,n)=>{n.stopPropagation();const r=oe(e);p?.onExpandChange?.(r.expandedKeys,r.expanded,e)},[oe,p]),se=me(()=>R.filter(e=>e.dataField!==E&&e.text.toLowerCase().includes(be.toLowerCase())),[R,E,be]),vt=u(e=>e[E],[E]),Rt=u((e,n,r,o)=>{const a=G(e,n.dataField);if(V?.row===r&&V?.field===n.dataField){if(n.editorRenderer){const i=e[E],d={value:T,onUpdate:l=>{ke(l),X?.(l,n.dataField,i),L(null)},onCancel:()=>L(null),onBlur:()=>{T!==a&&X?.(T,n.dataField,i),L(null)},row:e,column:n,rowIndex:r,columnIndex:o,rowId:i,dataField:n.dataField,onUpdateItem:l=>{X?.(l,n.dataField,i),L(null)}};return n.editorRenderer(d,T,e,n,r,o)}return t(yr,{type:n.editorType==="number"?"number":"text",value:T??"",onChange:i=>ke(i.target.value),onBlur:()=>Oe(e,r,n),onKeyDown:i=>{i.key==="Enter"&&Oe(e,r,n),i.key==="Escape"&&L(null)},className:n.editorClasses,style:n.editorStyle,autoFocus:!0})}return n.formatter?n.formatter(a,e,r,o):a==null?"":typeof a=="boolean"?a?"Yes":"No":typeof a=="object"?JSON.stringify(a):String(a)},[V,T,Oe]),An=()=>{if(on)return null;if(typeof ue=="function")return ue({searchValue:U,onSearch:He,onClearFilters:xt,onExport:wt});if(ue)return ue;const e=Object.keys(F).length>0||U;return s(_n,{className:b.toolbar,style:k.toolbar,children:[s(Ie,{children:[Cn,Xe&&s(qn,{children:[t(Pr,{}),t("input",{type:"text",value:U,onChange:n=>He(n.target.value),onFocus:()=>{ne.current=null},placeholder:Kt})]}),Xe&&t(K,{onClick:()=>He(""),disabled:!U,style:{opacity:U?1:.6},children:"Clear"}),t(K,{onClick:xt,disabled:!e,style:{opacity:e?1:.6},children:"Clear all filters"}),mn&&ge!==!0&&s(K,{onClick:wt,children:[t(Or,{}),Ee==="excel"?"Export Excel":"Export CSV"]}),Ge&&s("div",{ref:ye,style:{position:"relative"},children:[t(Mr,{content:"Show/Hide Columns",position:"bottom",children:t(K,{$active:B,onClick:()=>ee(!B),"aria-label":"Toggle column visibility",style:{padding:"0 8px"},children:t(Ar,{})})}),B&&s(Tt,{children:[s(Nt,{children:[t("span",{children:"Show/Hide Columns"}),t("button",{onClick:()=>ee(!1),children:t(jt,{})})]}),t(Lt,{children:t("input",{type:"text",value:be,onChange:n=>ht(n.target.value),placeholder:"Search columns..."})}),s(Mt,{children:[s(Je,{style:{borderBottom:"1px solid #e5e7eb",paddingBottom:8,marginBottom:4},children:[t("input",{type:"checkbox",checked:se.length>0&&se.every(n=>!ie(n.dataField)),onChange:n=>{se.forEach(r=>{n.target.checked?ie(r.dataField)&&xe(r.dataField):ie(r.dataField)||xe(r.dataField)})}}),t("span",{style:{fontWeight:600},children:"Select All"})]}),se.map(n=>s(Je,{children:[t("input",{type:"checkbox",checked:!ie(n.dataField),onChange:()=>xe(n.dataField)}),t("span",{children:n.text})]},n.dataField))]})]})]})]}),bn,s(Ie,{children:[kn&&s(K,{onClick:Sn,children:[t(Jr,{}),"Refresh"]}),Fn&&s(K,{onClick:xn,children:[t(Yr,{}),"Print"]}),qt&&s("div",{ref:Ge?void 0:ye,style:{position:"relative"},children:[s(K,{$active:B,onClick:()=>ee(!B),children:[t(Kr,{}),"Columns"]}),B&&s(Tt,{children:[s(Nt,{children:[t("span",{children:"Toggle Columns"}),t("button",{onClick:()=>ee(!1),children:t(jt,{})})]}),t(Lt,{children:t("input",{type:"text",value:be,onChange:n=>ht(n.target.value),placeholder:"Search columns..."})}),t(Mt,{children:se.map(n=>s(Je,{children:[t("input",{type:"checkbox",checked:!ie(n.dataField),onChange:()=>xe(n.dataField)}),t("span",{children:n.text})]},n.dataField))})]})]}),yn]})]})},On=()=>{if(!ce)return null;const e=Math.ceil(le/m)||1,n=le>0?C*m+1:0,r=D?g.length:ze.length,o=Math.min(C*m+r,le),a=j?.showTotal===!0?`Showing ${n} to ${o} of ${le} Results`:typeof j?.showTotal=="function"?j.showTotal(le,[n,o]):null,c=()=>{const i=[];if(e<=5)for(let l=0;l<e;l++)i.push(l);else if(C<3){for(let l=0;l<4;l++)i.push(l);i.push("..."),i.push(e-1)}else if(C>e-4){i.push(0),i.push("...");for(let l=e-4;l<e;l++)i.push(l)}else{i.push(0),i.push("...");for(let l=C-1;l<=C+1;l++)i.push(l);i.push("..."),i.push(e-1)}return i};return s(sr,{className:b.pagination,style:k.pagination,children:[s(Ie,{children:[(f?.mode==="checkbox"||it)&&z.size>0&&s(br,{onClick:()=>{const i=g.filter(d=>z.has(vt(d)));f?.onChange?.(Array.from(z),i),hn?.(i)},children:[t(kr,{$animate:En,children:z.size},z.size),t("span",{children:"Selected"})]}),j?.showSizeChanger!==!1&&t(hr,{value:m,onChange:i=>Pn(Number(i.target.value)),children:(j?.pageSizeOptions||[10,20,30,50]).map(i=>t("option",{value:i,children:i},i))})]}),s(cr,{children:[t(q,{onClick:()=>Q(0),disabled:C===0,children:t(Vr,{})}),t(q,{onClick:()=>Q(C-1),disabled:C===0,children:t(Wr,{})}),c().map((i,d)=>typeof i=="string"?t("span",{style:{padding:"0 4px",color:"white"},children:i},`ellipsis-${d}`):t(q,{$active:i===C,onClick:()=>Q(i),children:i+1},i)),t(q,{onClick:()=>Q(C+1),disabled:C>=e-1,children:t(Dr,{})}),t(q,{onClick:()=>Q(e-1),disabled:C>=e-1,children:t(zr,{})})]}),a&&t(dr,{children:a}),j?.showQuickJumper&&(()=>{const i=d=>{const l=parseInt(d.value,10);return!isNaN(l)&&l>=1&&l<=e?(Q(l-1),d.value="",!0):!1};return s(fr,{children:["Go to",t("input",{type:"number",min:1,max:e,placeholder:`1-${e}`,onKeyDown:d=>{if(d.key==="Enter"){d.preventDefault();const l=d.target;i(l)&&l.blur()}},onBlur:d=>{const l=d.target;i(l)}}),t(q,{onClick:()=>{const d=document.querySelector(`#${de} input[type="number"]`);d&&(i(d),d.blur())},style:{marginLeft:"4px",padding:"2px 8px"},children:"Go"})]})})()]})},Kn=(zt||R.some(e=>typeof e.filter=="function"||e.filterComponent||e.filter===!0))&&De;return s(Qn,{ref:e=>{typeof I=="function"?I(e):I&&(I.current=e),re.current=e},$bordered:Gt,$compact:x,className:tn||b.root,style:{...k.root,...nn,position:"relative"},"aria-label":st["aria-label"],"aria-labelledby":st["aria-labelledby"],children:[Bt&&t(ur,{className:b.loading,style:k.loading,children:Wt||t(gr,{})}),An(),t(Gn,{$maxHeight:en,$stickyHeader:et,className:b.wrapper,style:k.wrapper,children:s(Xn,{ref:wn,$striped:Xt,$hover:Zt,$compact:x,role:"grid",children:[ot&&t("caption",{className:"sr-only",children:ot}),t(Zn,{$sticky:et,className:b.header,style:k.header,children:s(er,{className:b.headerRow,style:k.headerRow,children:[f?.mode==="checkbox"&&t(we,{$align:"center",$sortable:!1,$compact:x,$width:f.columnWidth||40,children:!f.hideSelectAll&&t(Et,{checked:Ve,ref:e=>{e&&(e.indeterminate=Ln)},onChange:zn})}),p&&t(we,{$align:"center",$sortable:!1,$compact:x,$width:p.columnWidth||40}),Z&&t(we,{$align:"center",$sortable:!1,$compact:x,$width:lt,children:gn}),H.map((e,n)=>{const r=typeof e.filter=="function"||e.filter===!0||e.filterComponent||e.filterRenderer,o=r?(typeof e.filter=="function"?e.filter:null)||e.filterComponent||Lr(e.filterType||"text"):null,a=c=>Ft(e.dataField,c);return t(we,{$align:e.headerAlign||e.align||"left",$sortable:!!e.sort,$compact:x,$width:e.width,$minWidth:e.minWidth,$pinned:e.pinned,$customClass:!!e.headerClasses,className:[e.headerClasses,b.headerCell].filter(Boolean).join(" "),style:typeof e.headerStyle=="function"?e.headerStyle(e):e.headerStyle||k.headerCell,role:"columnheader","aria-sort":S.field===e.dataField?S.order==="asc"?"ascending":S.order==="desc"?"descending":"none":void 0,children:(()=>{const c=typeof e.headerStyle=="function"?e.headerStyle(e):e.headerStyle,i=e.isHeaderTitle!==!1&&e.hideHeaderText!==!0&&!(c&&c.fontSize===0),d=e.isHeaderFilterComp!==!1&&Kn&&r&&o,l=e.isHeaderSort!==!1&&e.sort;return d?s("div",{style:{display:"flex",flexDirection:"column",gap:4,width:"100%"},children:[i&&t("span",{style:{color:"white",fontWeight:600,fontSize:12,whiteSpace:"nowrap",cursor:l?"pointer":"default"},onClick:()=>l&&Ae(e),children:e.headerFormatter?e.headerFormatter(e,n):e.headerText||e.text}),s("div",{style:{display:"flex",alignItems:"center",justifyContent:"center",gap:6,width:"100%",minHeight:24},children:[t("div",{style:{width:l?"80%":"100%",minWidth:0,flexShrink:1,display:"flex",alignItems:"center"},onClick:y=>y.stopPropagation(),children:e.filterRenderer?e.filterRenderer(a,e):t("div",{onFocusCapture:()=>{ne.current=e.dataField},"data-filter-wrapper":e.dataField,children:t(o,{column:e,value:F[e.dataField],onChange:a,onClear:()=>Ft(e.dataField,null)},`filter-${e.dataField}`)})}),l&&t("div",{style:{width:"20%",minWidth:24,height:24,display:"flex",alignItems:"center",justifyContent:"center",flexShrink:0,cursor:"pointer"},onClick:()=>Ae(e),children:e.sortCaret?e.sortCaret(S.field===e.dataField?S.order:null,e):t(Pt,{order:S.field===e.dataField?S.order:null,column:e})})]})]}):s("div",{style:{display:"flex",alignItems:"center",justifyContent:e.headerAlign||e.align||"left",gap:6,width:"100%",cursor:l?"pointer":"default"},onClick:()=>l&&Ae(e),children:[i&&t("span",{style:{color:"white",fontWeight:600,fontSize:12,whiteSpace:"nowrap"},children:e.headerFormatter?e.headerFormatter(e,n):e.headerText||e.text}),l&&t("div",{style:{display:"flex",alignItems:"center",justifyContent:"center",flexShrink:0},children:e.sortCaret?e.sortCaret(S.field===e.dataField?S.order:null,e):t(Pt,{order:S.field===e.dataField?S.order:null,column:e})})]})})()},e.dataField)})]})}),t(tr,{className:b.body,style:k.body,children:ze.length===0?t("tr",{children:t("td",{colSpan:H.length+(f?.mode==="checkbox"?1:0)+(p?1:0)+(Z?1:0),children:s(pr,{className:b.empty,style:k.empty,children:[t(Ir,{}),t("span",{children:rn})]})})}):ze.map((e,n)=>{const r=vt(e),o=Nn(r),a=Mn(r),c=f?.getCheckboxProps?.(e),i=p?.rowExpandable?.(e)??!0,d=typeof Te=="function"?Te(e,n):Te,l=typeof Ne=="function"?Ne(e,n):Ne,y=o?typeof f?.selectedRowStyle=="function"?f.selectedRowStyle(e):f?.selectedRowStyle:void 0,Ke=o&&y&&(y.backgroundColor||y.background),In=c?.disabled?dn||{backgroundColor:"#f3f4f6",opacity:.7}:void 0;return s(Yn.Fragment,{children:[s(nr,{$selected:o,$clickable:!!Le||f?.mode==="single"||p?.expandRowByClick===!0,$disabled:!!c?.disabled,$hasCustomSelectedStyle:!!Ke,"data-custom-selected":Ke?"true":void 0,className:`${b.row||""} ${d||""} ${o?typeof f?.selectedRowClassName=="function"?f.selectedRowClassName(e):f?.selectedRowClassName||"":""}`,style:{...k.row,...l,...y,...In},onClick:h=>jn(e,n,h),onDoubleClick:h=>{Me?.(e,n,h)},role:"row","aria-selected":o,children:[f?.mode==="checkbox"&&t(ve,{$align:"center",$compact:x,$padding:he,children:t(Et,{checked:o,disabled:c?.disabled,onChange:h=>Vn(e,h),onClick:h=>h.stopPropagation()})}),p&&t(ve,{$align:"center",$compact:x,$padding:he,children:i&&t(rr,{$expanded:a,onClick:h=>Hn(e,h),children:p.expandIcon?p.expandIcon({expanded:a,row:e,onExpand:()=>oe(e)}):t(Hr,{})})}),Z&&t(ve,{$align:"center",$compact:x,$padding:he,style:{width:lt,color:"#6b7280",fontWeight:500},children:at?at(n+1,e):n+1+C*m}),H.map((h,A)=>{const $t=typeof h.classes=="function"?h.classes(G(e,h.dataField),e,n,A):h.classes,Jn=typeof h.style=="function"?h.style(G(e,h.dataField),e,n,A):h.style;return t(ve,{$align:h.align||"left",$compact:x,$padding:he,$pinned:h.pinned,$hasCustomClass:!!$t,className:$t||b.cell,style:{...k.cell,...Jn},onClick:W=>Wn(e,n,h,A,W),onDoubleClick:W=>{W.stopPropagation(),Bn(e,n,h,A,W)},role:"gridcell",children:(()=>{const W=ae(h,e,n,A);return W.isEditable&&J!=="none"?W.customEditor?W.customEditor:t(Cr,{$editing:V?.row===n&&V?.field===h.dataField,$showEditIcon:Ut,children:Rt(e,h,n,A)}):Rt(e,h,n,A)})()},h.dataField)})]}),p&&a&&i&&t(or,{children:t(ir,{colSpan:H.length+(f?.mode==="checkbox"?1:0)+(p?1:0)+(Z?1:0),children:p.expandedRowRender?.(e,n,a)})})]},r)})}),ln&&t(lr,{className:b.footer,style:k.footer,children:s(ar,{className:b.footerRow,style:k.footerRow,children:[f?.mode==="checkbox"&&t(Re,{$align:"center",$compact:x}),p&&t(Re,{$align:"center",$compact:x}),Z&&t(Re,{$align:"center",$compact:x}),H.map(e=>t(Re,{$align:e.align||"left",$compact:x,className:b.footerCell,style:k.footerCell,children:typeof e.footer=="function"?e.footer(e,g):e.footerFormatter?e.footerFormatter(e,g):e.footer},e.dataField))]})})]})}),On()]})});Table.displayName="Table";export default Table;
|
|
1
|
+
'use client';
|
|
2
|
+
import { jsx as _jsx, jsxs as _jsxs } from "react/jsx-runtime";
|
|
3
|
+
import React, { forwardRef, useState, useCallback, useMemo, useEffect, useRef, } from 'react';
|
|
4
|
+
import { TableRoot, Toolbar, ToolbarGroup, SearchInput, ToolbarButton, TableWrapper, StyledTable, TableHeader, HeaderRow, HeaderCell, TableBody, TableRow, TableCell, Checkbox, ExpandButton, ExpandedRow, ExpandedCell, TableFooter, FooterRow, FooterCell, PaginationWrapper, PaginationInfo, PaginationControls, PageButton, PageSizeSelect, QuickJumper, EmptyState, LoadingOverlay, LoadingSpinner, EditableCell, CellEditor, ColumnTogglePanel, ColumnToggleHeader, ColumnToggleSearch, ColumnToggleList, ColumnToggleItem, ColumnToggleDragHandle, SelectionIndicator, SelectionCount, } from './elements';
|
|
5
|
+
import { useSortState, useFilterState, usePaginationState, useRowSelection, useRowExpansion, useColumnVisibility, useTableDebounce, sortData, filterData, paginateData, getNestedValue, exportToCSV, exportToExcel, } from './hooks';
|
|
6
|
+
import { getFilterComponent } from './filters';
|
|
7
|
+
import { Tooltip } from '../Tooltip';
|
|
8
|
+
import { useColumnResize, getColumnStyle } from './columnResize';
|
|
9
|
+
// Column reorder is handled internally via popup drag & drop
|
|
10
|
+
// Icons
|
|
11
|
+
const SearchIcon = () => (_jsxs("svg", { viewBox: "0 0 24 24", fill: "none", stroke: "currentColor", strokeWidth: "2", children: [_jsx("circle", { cx: "11", cy: "11", r: "8" }), _jsx("path", { d: "M21 21l-4.35-4.35", strokeLinecap: "round" })] }));
|
|
12
|
+
// Arrow Up Icon with configurable size
|
|
13
|
+
// Arrow Up Icon - stroke-based arrow pointing up (like BsArrowUp)
|
|
14
|
+
const ArrowUpIcon = ({ size = 16, color = 'white', }) => (_jsx("svg", { viewBox: "0 0 16 16", fill: color, style: { width: size, height: size, display: 'block' }, children: _jsx("path", { fillRule: "evenodd", d: "M8 15a.5.5 0 0 0 .5-.5V2.707l3.146 3.147a.5.5 0 0 0 .708-.708l-4-4a.5.5 0 0 0-.708 0l-4 4a.5.5 0 1 0 .708.708L7.5 2.707V14.5a.5.5 0 0 0 .5.5z" }) }));
|
|
15
|
+
// Arrow Down Icon - stroke-based arrow pointing down (like BsArrowDown)
|
|
16
|
+
const ArrowDownIcon = ({ size = 16, color = 'white', }) => (_jsx("svg", { viewBox: "0 0 16 16", fill: color, style: { width: size, height: size, display: 'block' }, children: _jsx("path", { fillRule: "evenodd", d: "M8 1a.5.5 0 0 1 .5.5v11.793l3.146-3.147a.5.5 0 0 1 .708.708l-4 4a.5.5 0 0 1-.708 0l-4-4a.5.5 0 0 1 .708-.708L7.5 13.293V1.5A.5.5 0 0 1 8 1z" }) }));
|
|
17
|
+
// Default sort caret component with arrow icons (matches BsArrowUp/BsArrowDown style)
|
|
18
|
+
const DefaultSortCaret = ({ order, }) => {
|
|
19
|
+
// Size configuration based on sort order (like your custom sortCaret)
|
|
20
|
+
const getSizeConfig = () => {
|
|
21
|
+
switch (order) {
|
|
22
|
+
case 'asc':
|
|
23
|
+
return { up: 18, down: 12 };
|
|
24
|
+
case 'desc':
|
|
25
|
+
return { up: 12, down: 18 };
|
|
26
|
+
default:
|
|
27
|
+
return { up: 16, down: 16 };
|
|
28
|
+
}
|
|
29
|
+
};
|
|
30
|
+
const { up, down } = getSizeConfig();
|
|
31
|
+
return (_jsxs("div", { style: {
|
|
32
|
+
display: 'flex',
|
|
33
|
+
flexDirection: 'row',
|
|
34
|
+
alignItems: 'center',
|
|
35
|
+
justifyContent: 'center',
|
|
36
|
+
gap: 0,
|
|
37
|
+
}, children: [_jsx(ArrowUpIcon, { size: up, color: "white" }), _jsx(ArrowDownIcon, { size: down, color: "white" })] }));
|
|
38
|
+
};
|
|
39
|
+
const ChevronLeftIcon = () => (_jsx("svg", { viewBox: "0 0 24 24", fill: "none", stroke: "currentColor", strokeWidth: "2", children: _jsx("path", { d: "M15 18l-6-6 6-6", strokeLinecap: "round", strokeLinejoin: "round" }) }));
|
|
40
|
+
const ChevronRightIcon = () => (_jsx("svg", { viewBox: "0 0 24 24", fill: "none", stroke: "currentColor", strokeWidth: "2", children: _jsx("path", { d: "M9 18l6-6-6-6", strokeLinecap: "round", strokeLinejoin: "round" }) }));
|
|
41
|
+
const ChevronsLeftIcon = () => (_jsx("svg", { viewBox: "0 0 24 24", fill: "none", stroke: "currentColor", strokeWidth: "2", children: _jsx("path", { d: "M11 17l-5-5 5-5M18 17l-5-5 5-5", strokeLinecap: "round", strokeLinejoin: "round" }) }));
|
|
42
|
+
const ChevronsRightIcon = () => (_jsx("svg", { viewBox: "0 0 24 24", fill: "none", stroke: "currentColor", strokeWidth: "2", children: _jsx("path", { d: "M13 7l5 5-5 5M6 7l5 5-5 5", strokeLinecap: "round", strokeLinejoin: "round" }) }));
|
|
43
|
+
const ExpandIcon = () => (_jsx("svg", { viewBox: "0 0 24 24", fill: "none", stroke: "currentColor", strokeWidth: "2", children: _jsx("path", { d: "M9 18l6-6-6-6", strokeLinecap: "round", strokeLinejoin: "round" }) }));
|
|
44
|
+
const CloseIcon = () => (_jsx("svg", { viewBox: "0 0 24 24", fill: "none", stroke: "currentColor", strokeWidth: "2", children: _jsx("path", { d: "M18 6L6 18M6 6l12 12", strokeLinecap: "round", strokeLinejoin: "round" }) }));
|
|
45
|
+
const FilterIcon = () => (_jsx("svg", { viewBox: "0 0 24 24", fill: "none", stroke: "currentColor", strokeWidth: "2", children: _jsx("path", { d: "M22 3H2l8 9.46V19l4 2v-8.54L22 3z", strokeLinecap: "round", strokeLinejoin: "round" }) }));
|
|
46
|
+
const DownloadIcon = () => (_jsx("svg", { viewBox: "0 0 24 24", fill: "none", stroke: "currentColor", strokeWidth: "2", children: _jsx("path", { d: "M21 15v4a2 2 0 01-2 2H5a2 2 0 01-2-2v-4M7 10l5 5 5-5M12 15V3", strokeLinecap: "round", strokeLinejoin: "round" }) }));
|
|
47
|
+
const ColumnsIcon = () => (_jsxs("svg", { viewBox: "0 0 24 24", fill: "none", stroke: "currentColor", strokeWidth: "2", children: [_jsx("rect", { x: "3", y: "3", width: "7", height: "18", rx: "1" }), _jsx("rect", { x: "14", y: "3", width: "7", height: "18", rx: "1" })] }));
|
|
48
|
+
const EmptyIcon = () => (_jsxs("svg", { viewBox: "0 0 24 24", fill: "none", stroke: "currentColor", strokeWidth: "1.5", children: [_jsx("rect", { x: "3", y: "3", width: "18", height: "18", rx: "2" }), _jsx("path", { d: "M3 9h18M9 3v18", strokeLinecap: "round" })] }));
|
|
49
|
+
const RefreshIcon = () => (_jsxs("svg", { viewBox: "0 0 24 24", fill: "none", stroke: "currentColor", strokeWidth: "2", children: [_jsx("path", { d: "M23 4v6h-6M1 20v-6h6", strokeLinecap: "round", strokeLinejoin: "round" }), _jsx("path", { d: "M3.51 9a9 9 0 0114.85-3.36L23 10M1 14l4.64 4.36A9 9 0 0020.49 15", strokeLinecap: "round", strokeLinejoin: "round" })] }));
|
|
50
|
+
const PrintIcon = () => (_jsxs("svg", { viewBox: "0 0 24 24", fill: "none", stroke: "currentColor", strokeWidth: "2", children: [_jsx("path", { d: "M6 9V2h12v7M6 18H4a2 2 0 01-2-2v-5a2 2 0 012-2h16a2 2 0 012 2v5a2 2 0 01-2 2h-2", strokeLinecap: "round", strokeLinejoin: "round" }), _jsx("rect", { x: "6", y: "14", width: "12", height: "8" })] }));
|
|
51
|
+
const ErrorIcon = () => (_jsxs("svg", { viewBox: "0 0 24 24", fill: "none", stroke: "currentColor", strokeWidth: "2", children: [_jsx("circle", { cx: "12", cy: "12", r: "10" }), _jsx("path", { d: "M12 8v4M12 16h.01", strokeLinecap: "round", strokeLinejoin: "round" })] }));
|
|
52
|
+
export const Table = forwardRef(function TableComponent(props, ref) {
|
|
53
|
+
const { id, data, columns, keyField = '_id', loading = false, loadingIndicator, pagination = true, paginationConfig, totalSize, remote = true, defaultSort, sort: controlledSort, filterable = false, defaultFilters, filters: controlledFilters, defaultShowFilters = true, showFilters: controlledShowFilters, onShowFiltersChange, showFilterToggle = true, searchable = true, searchPlaceholder = 'Search...', defaultSearchValue = '', searchValue: controlledSearchValue, searchDebounce = 300, rowSelection, expandable, editMode = 'dblclick', showEditIcon = false, onCellEdit, exportable = true, exportFileName = 'table_export', exportFormat = 'csv', columnToggle = false, bordered = true, striped = false, hover = true, compact = false, cellPadding, stickyHeader = false, maxHeight, rowClassName, rowStyle, classNames = {}, styles = {}, className, style, emptyText = 'No data available', onChange, onPageChange, onSortChange, onFilterChange, onSearch, onRowClick, onRowDoubleClick, onClearFilters, toolbar, hideToolbar = false, showFooter = false, caption,
|
|
54
|
+
// Quick configuration props
|
|
55
|
+
isDelete = false, isEditModify, isUpdate, isExport, isSelectRow, getNonSelectableRows, nonSelectableStyle, isView = false, fileName, hideExcelSheet = false,
|
|
56
|
+
// Quick callbacks
|
|
57
|
+
onSelectedRow, selectedRowStyle, selectedRowClassName, onUpdateItem, onPageSizeChange, onFilter, clearAllFilter, onDelete, onEdit, onView,
|
|
58
|
+
// Dynamic configuration
|
|
59
|
+
dynamicStylingFields, fieldTypeConfig,
|
|
60
|
+
// Row number
|
|
61
|
+
showRowNumber = false, rowNumberWidth = 50, rowNumberTitle = '#', rowNumberRender,
|
|
62
|
+
// Toolbar customization
|
|
63
|
+
toolbarPosition = 'top', toolbarLeft, toolbarRight, toolbarCenter,
|
|
64
|
+
// Refresh
|
|
65
|
+
refreshable = false, onRefresh,
|
|
66
|
+
// Print
|
|
67
|
+
printable = false, onPrint,
|
|
68
|
+
// Size
|
|
69
|
+
size = 'medium',
|
|
70
|
+
// Error state
|
|
71
|
+
error, onRetry,
|
|
72
|
+
// Skeleton loading
|
|
73
|
+
skeletonLoading = false, skeletonRowCount = 5,
|
|
74
|
+
// Hide header
|
|
75
|
+
hideHeader = false,
|
|
76
|
+
// Highlighted rows
|
|
77
|
+
highlightedRowKeys = [], highlightRowStyle, highlightRowClassName,
|
|
78
|
+
// Events
|
|
79
|
+
onRowMouseEnter, onRowMouseLeave, onCellClick, onHeaderClick,
|
|
80
|
+
// Column Resizing
|
|
81
|
+
resizable = true, resizeConfig,
|
|
82
|
+
// Column Reordering
|
|
83
|
+
reorderable = true, reorderConfig, ...rest } = props;
|
|
84
|
+
// Resolve aliases
|
|
85
|
+
const resolvedExportable = isExport ?? exportable;
|
|
86
|
+
const resolvedExportFileName = fileName ?? exportFileName;
|
|
87
|
+
// Auto-detect remote mode: if totalSize <= data.length, use client-side (remote=false)
|
|
88
|
+
const resolvedRemote = useMemo(() => {
|
|
89
|
+
// If totalSize is provided and is <= data.length, all data is loaded - use client-side
|
|
90
|
+
if (totalSize !== undefined &&
|
|
91
|
+
totalSize > 0 &&
|
|
92
|
+
totalSize <= data.length) {
|
|
93
|
+
return false;
|
|
94
|
+
}
|
|
95
|
+
// Otherwise use the prop value (default: true)
|
|
96
|
+
return remote;
|
|
97
|
+
}, [remote, totalSize, data.length]);
|
|
98
|
+
// Handle isSelectRow shorthand
|
|
99
|
+
const resolvedRowSelection = isSelectRow
|
|
100
|
+
? {
|
|
101
|
+
mode: 'checkbox',
|
|
102
|
+
selectedRowStyle: selectedRowStyle || rowSelection?.selectedRowStyle,
|
|
103
|
+
selectedRowClassName: selectedRowClassName || rowSelection?.selectedRowClassName,
|
|
104
|
+
...rowSelection,
|
|
105
|
+
// Merge getNonSelectableRows with existing getCheckboxProps
|
|
106
|
+
getCheckboxProps: (row) => {
|
|
107
|
+
const rowKey = row[keyField];
|
|
108
|
+
const isNonSelectable = getNonSelectableRows?.includes(rowKey);
|
|
109
|
+
const existingProps = rowSelection?.getCheckboxProps?.(row);
|
|
110
|
+
return {
|
|
111
|
+
...existingProps,
|
|
112
|
+
disabled: isNonSelectable || existingProps?.disabled,
|
|
113
|
+
};
|
|
114
|
+
},
|
|
115
|
+
onChange: (keys, rows) => {
|
|
116
|
+
rowSelection?.onChange?.(keys, rows);
|
|
117
|
+
// Note: onSelectedRow is only called when user clicks the "X Selected" button
|
|
118
|
+
},
|
|
119
|
+
}
|
|
120
|
+
: rowSelection;
|
|
121
|
+
// Default pagination config - users don't need to pass these
|
|
122
|
+
const resolvedPaginationConfig = pagination
|
|
123
|
+
? {
|
|
124
|
+
page: 0,
|
|
125
|
+
pageSize: 10,
|
|
126
|
+
showSizeChanger: true,
|
|
127
|
+
showQuickJumper: true,
|
|
128
|
+
showTotal: true,
|
|
129
|
+
pageSizeOptions: [10, 20, 30, 50],
|
|
130
|
+
...paginationConfig,
|
|
131
|
+
}
|
|
132
|
+
: paginationConfig;
|
|
133
|
+
// Size configuration
|
|
134
|
+
const sizeConfig = {
|
|
135
|
+
small: { padding: '4px 8px', fontSize: '12px' },
|
|
136
|
+
medium: { padding: '8px 12px', fontSize: '14px' },
|
|
137
|
+
large: { padding: '12px 16px', fontSize: '16px' },
|
|
138
|
+
};
|
|
139
|
+
// Refs
|
|
140
|
+
const tableRef = useRef(null);
|
|
141
|
+
const columnToggleRef = useRef(null);
|
|
142
|
+
const prevSelectionCountRef = useRef(0);
|
|
143
|
+
// State
|
|
144
|
+
const [internalSearchValue, setInternalSearchValue] = useState(defaultSearchValue);
|
|
145
|
+
const [internalShowFilters, setInternalShowFilters] = useState(defaultShowFilters);
|
|
146
|
+
const [columnToggleOpen, setColumnToggleOpen] = useState(false);
|
|
147
|
+
const [columnSearch, setColumnSearch] = useState('');
|
|
148
|
+
const [selectionAnimation, setSelectionAnimation] = useState('none');
|
|
149
|
+
// Column toggle reorder state
|
|
150
|
+
const [toggleDraggingColumn, setToggleDraggingColumn] = useState(null);
|
|
151
|
+
const [toggleDragOverColumn, setToggleDragOverColumn] = useState(null);
|
|
152
|
+
// Internal state for reordered columns (used in popup and for rendering)
|
|
153
|
+
const [reorderedColumns, setReorderedColumns] = useState(columns);
|
|
154
|
+
// Sync reorderedColumns when columns prop structure changes (columns added/removed)
|
|
155
|
+
// We only reset when the actual column dataFields change, not on every reference change
|
|
156
|
+
useEffect(() => {
|
|
157
|
+
const currentDataFields = reorderedColumns
|
|
158
|
+
.map((c) => c.dataField)
|
|
159
|
+
.sort()
|
|
160
|
+
.join(',');
|
|
161
|
+
const newDataFields = columns
|
|
162
|
+
.map((c) => c.dataField)
|
|
163
|
+
.sort()
|
|
164
|
+
.join(',');
|
|
165
|
+
if (currentDataFields !== newDataFields) {
|
|
166
|
+
// Columns structure changed - merge new columns while preserving order where possible
|
|
167
|
+
const newColumnMap = new Map(columns.map((c) => [c.dataField, c]));
|
|
168
|
+
const existingDataFields = new Set(reorderedColumns.map((c) => c.dataField));
|
|
169
|
+
// Keep existing order for columns that still exist, update their data
|
|
170
|
+
const preserved = reorderedColumns
|
|
171
|
+
.filter((c) => newColumnMap.has(c.dataField))
|
|
172
|
+
.map((c) => newColumnMap.get(c.dataField));
|
|
173
|
+
// Add new columns at the end
|
|
174
|
+
const added = columns.filter((c) => !existingDataFields.has(c.dataField));
|
|
175
|
+
setReorderedColumns([...preserved, ...added]);
|
|
176
|
+
}
|
|
177
|
+
else {
|
|
178
|
+
// Same columns but maybe different data - update column data while preserving order
|
|
179
|
+
const columnMap = new Map(columns.map((c) => [c.dataField, c]));
|
|
180
|
+
setReorderedColumns(reorderedColumns.map((c) => columnMap.get(c.dataField) || c));
|
|
181
|
+
}
|
|
182
|
+
}, [columns]);
|
|
183
|
+
// Close column toggle panel on outside click
|
|
184
|
+
useEffect(() => {
|
|
185
|
+
if (!columnToggleOpen)
|
|
186
|
+
return;
|
|
187
|
+
const handleClickOutside = (event) => {
|
|
188
|
+
if (columnToggleRef.current &&
|
|
189
|
+
!columnToggleRef.current.contains(event.target)) {
|
|
190
|
+
setColumnToggleOpen(false);
|
|
191
|
+
}
|
|
192
|
+
};
|
|
193
|
+
document.addEventListener('mousedown', handleClickOutside);
|
|
194
|
+
return () => {
|
|
195
|
+
document.removeEventListener('mousedown', handleClickOutside);
|
|
196
|
+
};
|
|
197
|
+
}, [columnToggleOpen]);
|
|
198
|
+
// Filter visibility (controlled or uncontrolled)
|
|
199
|
+
const isFilterVisibilityControlled = controlledShowFilters !== undefined;
|
|
200
|
+
const showFilterRow = isFilterVisibilityControlled
|
|
201
|
+
? controlledShowFilters
|
|
202
|
+
: internalShowFilters;
|
|
203
|
+
const handleToggleFilters = useCallback(() => {
|
|
204
|
+
const newValue = !showFilterRow;
|
|
205
|
+
if (!isFilterVisibilityControlled) {
|
|
206
|
+
setInternalShowFilters(newValue);
|
|
207
|
+
}
|
|
208
|
+
onShowFiltersChange?.(newValue);
|
|
209
|
+
}, [showFilterRow, isFilterVisibilityControlled, onShowFiltersChange]);
|
|
210
|
+
const [editingCell, setEditingCell] = useState(null);
|
|
211
|
+
const [editValue, setEditValue] = useState(null);
|
|
212
|
+
const searchValue = controlledSearchValue ?? internalSearchValue;
|
|
213
|
+
const debouncedSearchValue = useTableDebounce(searchValue, searchDebounce);
|
|
214
|
+
// Sort state
|
|
215
|
+
const { sort, handleSort } = useSortState(defaultSort, controlledSort);
|
|
216
|
+
// Filter state
|
|
217
|
+
const { filters, setFilter, clearFilters } = useFilterState(defaultFilters, controlledFilters);
|
|
218
|
+
// Track if onFilter should be called (only after user interaction)
|
|
219
|
+
const shouldCallOnFilter = useRef(false);
|
|
220
|
+
const filterTypeRef = useRef('filter');
|
|
221
|
+
const onFilterRef = useRef(onFilter);
|
|
222
|
+
// Track last called values to prevent duplicate calls
|
|
223
|
+
const lastOnFilterCallRef = useRef(null);
|
|
224
|
+
// Track focused filter field to restore focus after data changes
|
|
225
|
+
const focusedFilterFieldRef = useRef(null);
|
|
226
|
+
const tableContainerRef = useRef(null);
|
|
227
|
+
// Clear focus ref when clicking outside the table
|
|
228
|
+
useEffect(() => {
|
|
229
|
+
const handleClickOutside = (event) => {
|
|
230
|
+
if (tableContainerRef.current &&
|
|
231
|
+
!tableContainerRef.current.contains(event.target)) {
|
|
232
|
+
focusedFilterFieldRef.current = null;
|
|
233
|
+
}
|
|
234
|
+
};
|
|
235
|
+
document.addEventListener('mousedown', handleClickOutside);
|
|
236
|
+
return () => {
|
|
237
|
+
document.removeEventListener('mousedown', handleClickOutside);
|
|
238
|
+
};
|
|
239
|
+
}, []);
|
|
240
|
+
// Restore filter focus after data changes
|
|
241
|
+
useEffect(() => {
|
|
242
|
+
const restoreFocus = () => {
|
|
243
|
+
if (focusedFilterFieldRef.current && tableContainerRef.current) {
|
|
244
|
+
const filterInput = tableContainerRef.current.querySelector(`[data-filter-field="${focusedFilterFieldRef.current}"]`);
|
|
245
|
+
if (filterInput && document.activeElement !== filterInput) {
|
|
246
|
+
filterInput.focus();
|
|
247
|
+
// Move cursor to end of input
|
|
248
|
+
const len = filterInput.value?.length || 0;
|
|
249
|
+
filterInput.setSelectionRange(len, len);
|
|
250
|
+
}
|
|
251
|
+
}
|
|
252
|
+
};
|
|
253
|
+
// Try multiple times with increasing delays to handle async renders
|
|
254
|
+
const timers = [
|
|
255
|
+
requestAnimationFrame(() => restoreFocus()),
|
|
256
|
+
setTimeout(() => restoreFocus(), 50),
|
|
257
|
+
setTimeout(() => restoreFocus(), 150),
|
|
258
|
+
];
|
|
259
|
+
return () => {
|
|
260
|
+
timers.forEach((timer) => {
|
|
261
|
+
if (typeof timer === 'number') {
|
|
262
|
+
cancelAnimationFrame(timer);
|
|
263
|
+
clearTimeout(timer);
|
|
264
|
+
}
|
|
265
|
+
});
|
|
266
|
+
};
|
|
267
|
+
}, [data]);
|
|
268
|
+
// Pagination state
|
|
269
|
+
const { page, pageSize, totalPages, goToPage, goToNextPage, goToPrevPage, goToFirstPage, goToLastPage, changePageSize, } = usePaginationState(resolvedPaginationConfig?.page || 0, resolvedPaginationConfig?.pageSize || 10, totalSize ?? data.length);
|
|
270
|
+
// Row selection
|
|
271
|
+
const { selectedKeys, isSelected, toggleRow, toggleAll, isAllSelected, isIndeterminate, } = useRowSelection(data, resolvedRowSelection?.keyField || keyField, resolvedRowSelection?.mode || 'none', resolvedRowSelection?.selectedRowKeys, resolvedRowSelection?.getCheckboxProps);
|
|
272
|
+
// Row expansion
|
|
273
|
+
const { expandedKeys, isExpanded, toggleExpand } = useRowExpansion(expandable?.keyField || keyField, expandable?.defaultExpandedRowKeys, expandable?.expandedRowKeys, expandable?.accordion);
|
|
274
|
+
// Column visibility
|
|
275
|
+
const { visibleColumns, toggleColumn, isColumnHidden } = useColumnVisibility(columns, id);
|
|
276
|
+
// Column resizing hook
|
|
277
|
+
const { columnWidths, getResizeHandle, resetWidths: resetColumnWidths, isResizing, } = useColumnResize({
|
|
278
|
+
columns: visibleColumns,
|
|
279
|
+
config: resizeConfig,
|
|
280
|
+
enabled: resizable,
|
|
281
|
+
tableId: id,
|
|
282
|
+
});
|
|
283
|
+
// Get visible columns from reordered columns (filter hidden ones)
|
|
284
|
+
const visibleRereorderedColumns = useMemo(() => {
|
|
285
|
+
return reorderedColumns.filter((col) => !isColumnHidden(col.dataField));
|
|
286
|
+
}, [reorderedColumns, isColumnHidden]);
|
|
287
|
+
// Use reordered visible columns for rendering
|
|
288
|
+
const renderColumns = reorderable
|
|
289
|
+
? visibleRereorderedColumns
|
|
290
|
+
: visibleColumns;
|
|
291
|
+
// Keep onFilter ref updated
|
|
292
|
+
useEffect(() => {
|
|
293
|
+
onFilterRef.current = onFilter;
|
|
294
|
+
}, [onFilter]);
|
|
295
|
+
// Track previous values to detect actual changes
|
|
296
|
+
const prevSearchRef = useRef(debouncedSearchValue);
|
|
297
|
+
const prevFiltersRef = useRef(JSON.stringify(filters));
|
|
298
|
+
// Call onFilter when filter/search values actually change
|
|
299
|
+
// Note: filter components already debounce internally, so we use filters directly
|
|
300
|
+
useEffect(() => {
|
|
301
|
+
if (!shouldCallOnFilter.current)
|
|
302
|
+
return;
|
|
303
|
+
const currentFiltersStr = JSON.stringify(filters);
|
|
304
|
+
const searchChanged = prevSearchRef.current !== debouncedSearchValue;
|
|
305
|
+
const filtersChanged = prevFiltersRef.current !== currentFiltersStr;
|
|
306
|
+
// Only proceed if search or filters actually changed
|
|
307
|
+
if (!searchChanged && !filtersChanged) {
|
|
308
|
+
shouldCallOnFilter.current = false;
|
|
309
|
+
return;
|
|
310
|
+
}
|
|
311
|
+
// Update previous values
|
|
312
|
+
prevSearchRef.current = debouncedSearchValue;
|
|
313
|
+
prevFiltersRef.current = currentFiltersStr;
|
|
314
|
+
// Clean up filters - remove null, undefined, and empty string values
|
|
315
|
+
const cleanFilters = {};
|
|
316
|
+
Object.keys(filters).forEach((key) => {
|
|
317
|
+
const value = filters[key];
|
|
318
|
+
if (value !== null && value !== undefined && value !== '') {
|
|
319
|
+
cleanFilters[key] = value;
|
|
320
|
+
}
|
|
321
|
+
});
|
|
322
|
+
const hasFilters = Object.keys(cleanFilters).length > 0;
|
|
323
|
+
// Build filter data based on what type of filter changed
|
|
324
|
+
// For 'search' type, include srText if not empty; for 'filter' type, only pass filters
|
|
325
|
+
const filterData = { ...cleanFilters };
|
|
326
|
+
if (filterTypeRef.current === 'search' && debouncedSearchValue) {
|
|
327
|
+
filterData.srText = debouncedSearchValue;
|
|
328
|
+
}
|
|
329
|
+
// Always call onFilter when filters change (including when cleared)
|
|
330
|
+
// Case 1: Global search cleared, column filters exist → filters only
|
|
331
|
+
// Case 2: Global search cleared, no column filters → empty filters (reload all)
|
|
332
|
+
// Case 3: Specific column cleared → remaining filters
|
|
333
|
+
onFilterRef.current?.(filterTypeRef.current, filterData, page, pageSize);
|
|
334
|
+
// Reset the flag after processing to prevent duplicate calls
|
|
335
|
+
shouldCallOnFilter.current = false;
|
|
336
|
+
}, [debouncedSearchValue, filters, page, pageSize]);
|
|
337
|
+
// Track selection count changes for animation
|
|
338
|
+
useEffect(() => {
|
|
339
|
+
const currentCount = selectedKeys.size;
|
|
340
|
+
const prevCount = prevSelectionCountRef.current;
|
|
341
|
+
if (currentCount > prevCount) {
|
|
342
|
+
setSelectionAnimation('up');
|
|
343
|
+
}
|
|
344
|
+
else if (currentCount < prevCount) {
|
|
345
|
+
setSelectionAnimation('down');
|
|
346
|
+
}
|
|
347
|
+
prevSelectionCountRef.current = currentCount;
|
|
348
|
+
// Reset animation after it completes
|
|
349
|
+
const timer = setTimeout(() => {
|
|
350
|
+
setSelectionAnimation('none');
|
|
351
|
+
}, 300);
|
|
352
|
+
return () => clearTimeout(timer);
|
|
353
|
+
}, [selectedKeys.size]);
|
|
354
|
+
// Process data (filter, sort, paginate)
|
|
355
|
+
const processedData = useMemo(() => {
|
|
356
|
+
if (resolvedRemote) {
|
|
357
|
+
// Server-side processing - data is already processed
|
|
358
|
+
return data;
|
|
359
|
+
}
|
|
360
|
+
let result = [...data];
|
|
361
|
+
// Filter
|
|
362
|
+
result = filterData(result, filters, columns, debouncedSearchValue);
|
|
363
|
+
// Sort
|
|
364
|
+
result = sortData(result, sort, columns);
|
|
365
|
+
// Paginate
|
|
366
|
+
if (pagination) {
|
|
367
|
+
result = paginateData(result, page, pageSize);
|
|
368
|
+
}
|
|
369
|
+
return result;
|
|
370
|
+
}, [
|
|
371
|
+
data,
|
|
372
|
+
filters,
|
|
373
|
+
sort,
|
|
374
|
+
page,
|
|
375
|
+
pageSize,
|
|
376
|
+
debouncedSearchValue,
|
|
377
|
+
resolvedRemote,
|
|
378
|
+
pagination,
|
|
379
|
+
columns,
|
|
380
|
+
]);
|
|
381
|
+
// Calculate total for pagination
|
|
382
|
+
const calculatedTotal = useMemo(() => {
|
|
383
|
+
// If totalSize is explicitly provided, use it for server-side pagination
|
|
384
|
+
if (totalSize !== undefined && totalSize > 0)
|
|
385
|
+
return totalSize;
|
|
386
|
+
if (resolvedRemote)
|
|
387
|
+
return data.length;
|
|
388
|
+
return filterData(data, filters, columns, debouncedSearchValue).length;
|
|
389
|
+
}, [
|
|
390
|
+
data,
|
|
391
|
+
filters,
|
|
392
|
+
columns,
|
|
393
|
+
debouncedSearchValue,
|
|
394
|
+
resolvedRemote,
|
|
395
|
+
totalSize,
|
|
396
|
+
]);
|
|
397
|
+
// Handle search
|
|
398
|
+
const handleSearchChange = useCallback((value) => {
|
|
399
|
+
setInternalSearchValue(value);
|
|
400
|
+
onSearch?.(value);
|
|
401
|
+
// Enable debounced onFilter callback with 'search' type
|
|
402
|
+
shouldCallOnFilter.current = true;
|
|
403
|
+
filterTypeRef.current = 'search';
|
|
404
|
+
onChange?.({ type: 'search', search: value });
|
|
405
|
+
}, [onSearch, onChange]);
|
|
406
|
+
// Handle sort
|
|
407
|
+
const handleSortClick = useCallback((column) => {
|
|
408
|
+
if (!column.sort)
|
|
409
|
+
return;
|
|
410
|
+
const newSort = handleSort(column.dataField, sort.order);
|
|
411
|
+
onSortChange?.(newSort);
|
|
412
|
+
onChange?.({ type: 'sort', sort: newSort });
|
|
413
|
+
}, [sort, handleSort, onSortChange, onChange]);
|
|
414
|
+
// Handle filter
|
|
415
|
+
const handleFilterChange = useCallback((field, value) => {
|
|
416
|
+
setFilter(field, value);
|
|
417
|
+
const newFilters = { ...filters, [field]: value };
|
|
418
|
+
onFilterChange?.(newFilters);
|
|
419
|
+
// Enable debounced onFilter callback with 'filter' type
|
|
420
|
+
shouldCallOnFilter.current = true;
|
|
421
|
+
filterTypeRef.current = 'filter';
|
|
422
|
+
onChange?.({ type: 'filter', filters: newFilters });
|
|
423
|
+
}, [filters, setFilter, onFilterChange, onChange]);
|
|
424
|
+
// Handle clear all filters
|
|
425
|
+
const handleClearFilters = useCallback(() => {
|
|
426
|
+
clearFilters();
|
|
427
|
+
setInternalSearchValue('');
|
|
428
|
+
onClearFilters?.();
|
|
429
|
+
clearAllFilter?.();
|
|
430
|
+
onFilterChange?.({});
|
|
431
|
+
onChange?.({ type: 'filter', filters: {} });
|
|
432
|
+
// Reset the tracking ref so subsequent filters can trigger onFilter
|
|
433
|
+
lastOnFilterCallRef.current = null;
|
|
434
|
+
}, [clearFilters, onClearFilters, onFilterChange, onChange]);
|
|
435
|
+
// Handle page change
|
|
436
|
+
const handlePageChange = useCallback((newPage) => {
|
|
437
|
+
goToPage(newPage);
|
|
438
|
+
// Pass 1-indexed page number to callbacks (user-friendly)
|
|
439
|
+
const displayPage = newPage + 1;
|
|
440
|
+
// onPageSizeChange is the primary callback
|
|
441
|
+
onPageSizeChange?.(displayPage, pageSize);
|
|
442
|
+
onPageChange?.(displayPage, pageSize);
|
|
443
|
+
onChange?.({
|
|
444
|
+
type: 'pagination',
|
|
445
|
+
pagination: { page: displayPage, pageSize },
|
|
446
|
+
});
|
|
447
|
+
}, [goToPage, pageSize, onPageSizeChange, onPageChange, onChange]);
|
|
448
|
+
// Handle page size change
|
|
449
|
+
const handlePageSizeChange = useCallback((newSize) => {
|
|
450
|
+
changePageSize(newSize);
|
|
451
|
+
// Pass 1-indexed page number to callbacks (page 1 after size change)
|
|
452
|
+
onPageSizeChange?.(1, newSize);
|
|
453
|
+
onPageChange?.(1, newSize);
|
|
454
|
+
onChange?.({
|
|
455
|
+
type: 'pagination',
|
|
456
|
+
pagination: { page: 1, pageSize: newSize },
|
|
457
|
+
});
|
|
458
|
+
}, [changePageSize, onPageSizeChange, onPageChange, onChange]);
|
|
459
|
+
// Handle row click
|
|
460
|
+
const handleRowClick = useCallback((row, rowIndex, e) => {
|
|
461
|
+
// Selection handling - only for 'single' mode (checkbox mode uses checkbox click only)
|
|
462
|
+
if (resolvedRowSelection?.mode === 'single') {
|
|
463
|
+
const result = toggleRow(row);
|
|
464
|
+
if (result) {
|
|
465
|
+
resolvedRowSelection?.onChange?.(result.selectedKeys, result.selectedRows);
|
|
466
|
+
}
|
|
467
|
+
}
|
|
468
|
+
// Expand by click
|
|
469
|
+
if (expandable?.expandRowByClick) {
|
|
470
|
+
const result = toggleExpand(row);
|
|
471
|
+
if (result) {
|
|
472
|
+
expandable.onExpandChange?.(result.expandedKeys, result.expanded, row);
|
|
473
|
+
}
|
|
474
|
+
}
|
|
475
|
+
onRowClick?.(row, rowIndex, e);
|
|
476
|
+
}, [rowSelection, expandable, toggleRow, toggleExpand, onRowClick]);
|
|
477
|
+
// Helper to check if cell is editable and get custom editor
|
|
478
|
+
const getCellEditableInfo = useCallback((column, row, rowIndex, colIndex) => {
|
|
479
|
+
// If editorRenderer is provided, column is editable by default (unless editable explicitly returns false)
|
|
480
|
+
const hasEditorRenderer = !!column.editorRenderer;
|
|
481
|
+
if (column.editable === undefined) {
|
|
482
|
+
// No editable prop - editable if has editorRenderer
|
|
483
|
+
return { isEditable: hasEditorRenderer };
|
|
484
|
+
}
|
|
485
|
+
if (column.editable === false) {
|
|
486
|
+
return { isEditable: false };
|
|
487
|
+
}
|
|
488
|
+
if (column.editable === true) {
|
|
489
|
+
return { isEditable: true };
|
|
490
|
+
}
|
|
491
|
+
// It's a function
|
|
492
|
+
const cellValue = getNestedValue(row, column.dataField);
|
|
493
|
+
const result = column.editable(cellValue, row, rowIndex, colIndex);
|
|
494
|
+
if (typeof result === 'boolean') {
|
|
495
|
+
return { isEditable: result };
|
|
496
|
+
}
|
|
497
|
+
// Result is a custom editor (ReactNode)
|
|
498
|
+
return { isEditable: true, customEditor: result };
|
|
499
|
+
}, []);
|
|
500
|
+
// Handle cell edit
|
|
501
|
+
const handleCellDoubleClick = useCallback((row, rowIndex, column, colIndex, e) => {
|
|
502
|
+
// Call column's onDoubleClick event if defined
|
|
503
|
+
column.events?.onDoubleClick?.(e, row, rowIndex, column, colIndex);
|
|
504
|
+
// Handle cell editing
|
|
505
|
+
if (editMode !== 'none') {
|
|
506
|
+
const { isEditable } = getCellEditableInfo(column, row, rowIndex, colIndex);
|
|
507
|
+
if (isEditable && editMode === 'dblclick') {
|
|
508
|
+
setEditingCell({ row: rowIndex, field: column.dataField });
|
|
509
|
+
setEditValue(getNestedValue(row, column.dataField));
|
|
510
|
+
}
|
|
511
|
+
}
|
|
512
|
+
// Call row double click callback
|
|
513
|
+
onRowDoubleClick?.(row, rowIndex, e);
|
|
514
|
+
}, [editMode, onRowDoubleClick, getCellEditableInfo]);
|
|
515
|
+
const handleCellClick = useCallback((row, rowIndex, column, colIndex, e) => {
|
|
516
|
+
// Call column's onClick event if defined
|
|
517
|
+
if (e) {
|
|
518
|
+
column.events?.onClick?.(e, row, rowIndex, column, colIndex);
|
|
519
|
+
}
|
|
520
|
+
// Handle cell editing on click
|
|
521
|
+
if (editMode === 'click') {
|
|
522
|
+
const { isEditable } = getCellEditableInfo(column, row, rowIndex, colIndex);
|
|
523
|
+
if (isEditable) {
|
|
524
|
+
setEditingCell({ row: rowIndex, field: column.dataField });
|
|
525
|
+
setEditValue(getNestedValue(row, column.dataField));
|
|
526
|
+
}
|
|
527
|
+
}
|
|
528
|
+
}, [editMode, getCellEditableInfo]);
|
|
529
|
+
const handleCellEditComplete = useCallback((row, rowIndex, column) => {
|
|
530
|
+
if (editingCell) {
|
|
531
|
+
// Validate
|
|
532
|
+
if (column.validator) {
|
|
533
|
+
const result = column.validator(editValue, row);
|
|
534
|
+
if (result !== true) {
|
|
535
|
+
alert(typeof result === 'string' ? result : 'Invalid value');
|
|
536
|
+
setEditingCell(null);
|
|
537
|
+
return;
|
|
538
|
+
}
|
|
539
|
+
}
|
|
540
|
+
const rowId = row[keyField];
|
|
541
|
+
onCellEdit?.(editValue, column.dataField, row, rowIndex);
|
|
542
|
+
onUpdateItem?.(editValue, column.dataField, rowId);
|
|
543
|
+
}
|
|
544
|
+
setEditingCell(null);
|
|
545
|
+
}, [editingCell, editValue, onCellEdit, onUpdateItem, keyField]);
|
|
546
|
+
// Helper to get nested value from object
|
|
547
|
+
const getNestedValueLocal = (obj, path) => {
|
|
548
|
+
return path.split('.').reduce((acc, key) => acc?.[key], obj);
|
|
549
|
+
};
|
|
550
|
+
// Process field value based on fieldTypeConfig (matching reference implementation)
|
|
551
|
+
const processFieldValue = useCallback((value, dataField, row) => {
|
|
552
|
+
const configOrType = fieldTypeConfig?.[dataField];
|
|
553
|
+
// Handle both object config and string shorthand (e.g., 'boolean', 'date')
|
|
554
|
+
const config = typeof configOrType === 'string'
|
|
555
|
+
? { type: configOrType }
|
|
556
|
+
: configOrType;
|
|
557
|
+
const fieldType = config?.type || 'string';
|
|
558
|
+
switch (fieldType) {
|
|
559
|
+
case 'array':
|
|
560
|
+
if (config?.fields && config.fields.length > 0) {
|
|
561
|
+
// Array of objects with specific fields to extract
|
|
562
|
+
if (!Array.isArray(value))
|
|
563
|
+
return value || '';
|
|
564
|
+
return value
|
|
565
|
+
.slice(0, config.maxItems || value.length)
|
|
566
|
+
.map((item) => {
|
|
567
|
+
if (typeof item === 'object' && config.fields) {
|
|
568
|
+
// Extract only specified fields from the object
|
|
569
|
+
return config.fields
|
|
570
|
+
.map((field) => item[field])
|
|
571
|
+
.filter(Boolean)
|
|
572
|
+
.join(', ');
|
|
573
|
+
}
|
|
574
|
+
else if (typeof item === 'string') {
|
|
575
|
+
return item;
|
|
576
|
+
}
|
|
577
|
+
return '';
|
|
578
|
+
})
|
|
579
|
+
.filter(Boolean)
|
|
580
|
+
.join(config.separator || '; ');
|
|
581
|
+
}
|
|
582
|
+
else {
|
|
583
|
+
// Default array handling
|
|
584
|
+
if (!Array.isArray(value))
|
|
585
|
+
return value || '';
|
|
586
|
+
return value
|
|
587
|
+
.map((item) => typeof item === 'object' ? JSON.stringify(item) : item)
|
|
588
|
+
.join('; ');
|
|
589
|
+
}
|
|
590
|
+
case 'object':
|
|
591
|
+
if (!value || typeof value !== 'object')
|
|
592
|
+
return '';
|
|
593
|
+
const fields = config?.fields || config?.keys || [];
|
|
594
|
+
const labelMap = config?.labelMap || {};
|
|
595
|
+
if (fields.length > 0) {
|
|
596
|
+
// Extract specific fields with optional label mapping
|
|
597
|
+
return fields
|
|
598
|
+
.map((field) => {
|
|
599
|
+
const nestedValue = getNestedValueLocal(value, field);
|
|
600
|
+
if (nestedValue !== undefined && nestedValue !== null) {
|
|
601
|
+
const label = labelMap[field] || field;
|
|
602
|
+
return `${label}: ${nestedValue}`;
|
|
603
|
+
}
|
|
604
|
+
return null;
|
|
605
|
+
})
|
|
606
|
+
.filter(Boolean)
|
|
607
|
+
.join(', ');
|
|
608
|
+
}
|
|
609
|
+
else {
|
|
610
|
+
// Default object handling
|
|
611
|
+
return Object.entries(value)
|
|
612
|
+
.map(([key, val]) => typeof val === 'boolean'
|
|
613
|
+
? `${key}: ${val ? 'Yes' : 'No'}`
|
|
614
|
+
: `${key}: ${val}`)
|
|
615
|
+
.join(', ');
|
|
616
|
+
}
|
|
617
|
+
case 'date':
|
|
618
|
+
if (!value)
|
|
619
|
+
return '';
|
|
620
|
+
try {
|
|
621
|
+
const date = new Date(value);
|
|
622
|
+
const format = config?.dateFormat || 'YYYY-MM-DD HH:mm:ss';
|
|
623
|
+
// Simple date formatting
|
|
624
|
+
return date.toISOString().slice(0, 19).replace('T', ' ');
|
|
625
|
+
}
|
|
626
|
+
catch {
|
|
627
|
+
return String(value);
|
|
628
|
+
}
|
|
629
|
+
case 'number':
|
|
630
|
+
return value !== undefined && value !== null
|
|
631
|
+
? String(Number(value))
|
|
632
|
+
: '';
|
|
633
|
+
case 'boolean':
|
|
634
|
+
return typeof value === 'boolean' ? (value ? 'Yes' : 'No') : '';
|
|
635
|
+
case 'string':
|
|
636
|
+
case 'text':
|
|
637
|
+
default:
|
|
638
|
+
if (typeof value === 'boolean')
|
|
639
|
+
return value ? 'Yes' : 'No';
|
|
640
|
+
return value !== undefined && value !== null ? String(value) : '';
|
|
641
|
+
}
|
|
642
|
+
}, [fieldTypeConfig]);
|
|
643
|
+
// Handle export
|
|
644
|
+
const handleExport = useCallback(async () => {
|
|
645
|
+
const exportData = resolvedRemote
|
|
646
|
+
? data
|
|
647
|
+
: filterData(data, filters, columns, debouncedSearchValue);
|
|
648
|
+
// Filter columns based on hideExcelSheet array and csvExport !== false
|
|
649
|
+
let exportColumns = visibleColumns.filter((col) => col.csvExport !== false);
|
|
650
|
+
if (Array.isArray(hideExcelSheet)) {
|
|
651
|
+
exportColumns = exportColumns.filter((col) => !hideExcelSheet.includes(col.dataField));
|
|
652
|
+
}
|
|
653
|
+
// Also filter based on fieldTypeConfig hideFromExport or csvExport
|
|
654
|
+
if (fieldTypeConfig) {
|
|
655
|
+
exportColumns = exportColumns.filter((col) => {
|
|
656
|
+
const configOrType = fieldTypeConfig[col.dataField];
|
|
657
|
+
const config = typeof configOrType === 'string'
|
|
658
|
+
? { type: configOrType }
|
|
659
|
+
: configOrType;
|
|
660
|
+
if (config?.hideFromExport)
|
|
661
|
+
return false;
|
|
662
|
+
if (config?.csvExport === false)
|
|
663
|
+
return false;
|
|
664
|
+
return true;
|
|
665
|
+
});
|
|
666
|
+
}
|
|
667
|
+
// Create enhanced columns with export formatters
|
|
668
|
+
const enhancedColumns = exportColumns.map((col) => {
|
|
669
|
+
const configOrType = fieldTypeConfig?.[col.dataField];
|
|
670
|
+
const config = typeof configOrType === 'string'
|
|
671
|
+
? { type: configOrType }
|
|
672
|
+
: configOrType;
|
|
673
|
+
// If column already has csvFormatter, use it
|
|
674
|
+
if (col.csvFormatter) {
|
|
675
|
+
return col;
|
|
676
|
+
}
|
|
677
|
+
// If config has exportFormatter, use it
|
|
678
|
+
if (config?.exportFormatter) {
|
|
679
|
+
return { ...col, csvFormatter: config.exportFormatter };
|
|
680
|
+
}
|
|
681
|
+
// If config has type, create formatter based on type
|
|
682
|
+
if (config?.type) {
|
|
683
|
+
return {
|
|
684
|
+
...col,
|
|
685
|
+
csvFormatter: (cell, row) => processFieldValue(cell, col.dataField, row),
|
|
686
|
+
};
|
|
687
|
+
}
|
|
688
|
+
return col;
|
|
689
|
+
});
|
|
690
|
+
// Export based on format
|
|
691
|
+
if (exportFormat === 'excel') {
|
|
692
|
+
await exportToExcel(exportData, enhancedColumns, resolvedExportFileName);
|
|
693
|
+
}
|
|
694
|
+
else {
|
|
695
|
+
exportToCSV(exportData, enhancedColumns, resolvedExportFileName);
|
|
696
|
+
}
|
|
697
|
+
}, [
|
|
698
|
+
data,
|
|
699
|
+
filters,
|
|
700
|
+
columns,
|
|
701
|
+
debouncedSearchValue,
|
|
702
|
+
visibleColumns,
|
|
703
|
+
hideExcelSheet,
|
|
704
|
+
fieldTypeConfig,
|
|
705
|
+
processFieldValue,
|
|
706
|
+
resolvedExportFileName,
|
|
707
|
+
resolvedRemote,
|
|
708
|
+
exportFormat,
|
|
709
|
+
]);
|
|
710
|
+
// Handle checkbox change
|
|
711
|
+
const handleCheckboxChange = useCallback((row, e) => {
|
|
712
|
+
e.stopPropagation();
|
|
713
|
+
const result = toggleRow(row);
|
|
714
|
+
if (result) {
|
|
715
|
+
resolvedRowSelection?.onChange?.(result.selectedKeys, result.selectedRows);
|
|
716
|
+
}
|
|
717
|
+
}, [toggleRow, rowSelection]);
|
|
718
|
+
// Handle select all
|
|
719
|
+
const handleSelectAllChange = useCallback(() => {
|
|
720
|
+
const result = toggleAll(!isAllSelected);
|
|
721
|
+
if (result) {
|
|
722
|
+
resolvedRowSelection?.onChange?.(result.selectedKeys, result.selectedRows);
|
|
723
|
+
}
|
|
724
|
+
}, [toggleAll, isAllSelected, resolvedRowSelection]);
|
|
725
|
+
// Handle expand toggle
|
|
726
|
+
const handleExpandClick = useCallback((row, e) => {
|
|
727
|
+
e.stopPropagation();
|
|
728
|
+
const result = toggleExpand(row);
|
|
729
|
+
expandable?.onExpandChange?.(result.expandedKeys, result.expanded, row);
|
|
730
|
+
}, [toggleExpand, expandable]);
|
|
731
|
+
// Filtered column list for toggle panel - use reorderedColumns to preserve reorder state
|
|
732
|
+
const filteredToggleColumns = useMemo(() => {
|
|
733
|
+
return reorderedColumns.filter((c) => c.dataField !== keyField &&
|
|
734
|
+
c.text.toLowerCase().includes(columnSearch.toLowerCase()));
|
|
735
|
+
}, [reorderedColumns, keyField, columnSearch]);
|
|
736
|
+
// Get row key
|
|
737
|
+
const getRowKey = useCallback((row) => row[keyField], [keyField]);
|
|
738
|
+
// Render cell content
|
|
739
|
+
const renderCellContent = useCallback((row, column, rowIndex, colIndex) => {
|
|
740
|
+
const value = getNestedValue(row, column.dataField);
|
|
741
|
+
const isEditing = editingCell?.row === rowIndex &&
|
|
742
|
+
editingCell?.field === column.dataField;
|
|
743
|
+
if (isEditing) {
|
|
744
|
+
// Check for custom editorRenderer
|
|
745
|
+
if (column.editorRenderer) {
|
|
746
|
+
const rowId = row[keyField];
|
|
747
|
+
const editorProps = {
|
|
748
|
+
value: editValue,
|
|
749
|
+
onUpdate: (newValue) => {
|
|
750
|
+
setEditValue(newValue);
|
|
751
|
+
// Call onUpdateItem directly for custom editors
|
|
752
|
+
onUpdateItem?.(newValue, column.dataField, rowId);
|
|
753
|
+
setEditingCell(null);
|
|
754
|
+
},
|
|
755
|
+
onCancel: () => setEditingCell(null),
|
|
756
|
+
onBlur: () => {
|
|
757
|
+
// Only complete if value changed
|
|
758
|
+
if (editValue !== value) {
|
|
759
|
+
onUpdateItem?.(editValue, column.dataField, rowId);
|
|
760
|
+
}
|
|
761
|
+
setEditingCell(null);
|
|
762
|
+
},
|
|
763
|
+
row,
|
|
764
|
+
column,
|
|
765
|
+
rowIndex,
|
|
766
|
+
columnIndex: colIndex,
|
|
767
|
+
// Additional helpers for direct update
|
|
768
|
+
rowId,
|
|
769
|
+
dataField: column.dataField,
|
|
770
|
+
onUpdateItem: (newValue) => {
|
|
771
|
+
onUpdateItem?.(newValue, column.dataField, rowId);
|
|
772
|
+
setEditingCell(null);
|
|
773
|
+
},
|
|
774
|
+
};
|
|
775
|
+
return column.editorRenderer(editorProps, editValue, row, column, rowIndex, colIndex);
|
|
776
|
+
}
|
|
777
|
+
// Default editor
|
|
778
|
+
return (_jsx(CellEditor, { type: column.editorType === 'number' ? 'number' : 'text', value: editValue ?? '', onChange: (e) => setEditValue(e.target.value), onBlur: () => handleCellEditComplete(row, rowIndex, column), onKeyDown: (e) => {
|
|
779
|
+
if (e.key === 'Enter') {
|
|
780
|
+
handleCellEditComplete(row, rowIndex, column);
|
|
781
|
+
}
|
|
782
|
+
if (e.key === 'Escape') {
|
|
783
|
+
setEditingCell(null);
|
|
784
|
+
}
|
|
785
|
+
}, className: column.editorClasses, style: column.editorStyle, autoFocus: true }));
|
|
786
|
+
}
|
|
787
|
+
if (column.formatter) {
|
|
788
|
+
return column.formatter(value, row, rowIndex, colIndex);
|
|
789
|
+
}
|
|
790
|
+
if (value === null || value === undefined)
|
|
791
|
+
return '';
|
|
792
|
+
if (typeof value === 'boolean')
|
|
793
|
+
return value ? 'Yes' : 'No';
|
|
794
|
+
if (typeof value === 'object')
|
|
795
|
+
return JSON.stringify(value);
|
|
796
|
+
return String(value);
|
|
797
|
+
}, [editingCell, editValue, handleCellEditComplete]);
|
|
798
|
+
// Render toolbar
|
|
799
|
+
const renderToolbar = () => {
|
|
800
|
+
if (hideToolbar)
|
|
801
|
+
return null;
|
|
802
|
+
if (typeof toolbar === 'function') {
|
|
803
|
+
return toolbar({
|
|
804
|
+
searchValue,
|
|
805
|
+
onSearch: handleSearchChange,
|
|
806
|
+
onClearFilters: handleClearFilters,
|
|
807
|
+
onExport: handleExport,
|
|
808
|
+
});
|
|
809
|
+
}
|
|
810
|
+
if (toolbar)
|
|
811
|
+
return toolbar;
|
|
812
|
+
const hasFilters = Object.keys(filters).length > 0 || searchValue;
|
|
813
|
+
return (_jsxs(Toolbar, { className: classNames.toolbar, style: styles.toolbar, children: [_jsxs(ToolbarGroup, { children: [toolbarLeft, searchable && (_jsxs(SearchInput, { children: [_jsx(SearchIcon, {}), _jsx("input", { type: "text", value: searchValue, onChange: (e) => handleSearchChange(e.target.value), onFocus: () => {
|
|
814
|
+
// Clear column filter focus when global search is focused
|
|
815
|
+
focusedFilterFieldRef.current = null;
|
|
816
|
+
}, placeholder: searchPlaceholder })] })), searchable && (_jsx(ToolbarButton, { onClick: () => handleSearchChange(''), disabled: !searchValue, style: { opacity: searchValue ? 1 : 0.6 }, children: "Clear" })), _jsx(ToolbarButton, { onClick: handleClearFilters, disabled: !hasFilters, style: { opacity: hasFilters ? 1 : 0.6 }, children: "Clear all filters" }), resolvedExportable && hideExcelSheet !== true && (_jsxs(ToolbarButton, { onClick: handleExport, children: [_jsx(DownloadIcon, {}), exportFormat === 'excel' ? 'Export Excel' : 'Export CSV'] })), showFilterToggle && (_jsxs("div", { ref: columnToggleRef, style: { position: 'relative' }, children: [_jsx(Tooltip, { content: "Show/Hide Columns", position: "bottom", children: _jsx(ToolbarButton, { "$active": columnToggleOpen, onClick: () => setColumnToggleOpen(!columnToggleOpen), "aria-label": "Toggle column visibility", style: { padding: '0 8px' }, children: _jsx(FilterIcon, {}) }) }), columnToggleOpen && (_jsxs(ColumnTogglePanel, { children: [_jsxs(ColumnToggleHeader, { children: [_jsx("span", { children: "Show/Hide Columns" }), _jsx("button", { onClick: () => setColumnToggleOpen(false), children: _jsx(CloseIcon, {}) })] }), _jsx(ColumnToggleSearch, { children: _jsx("input", { type: "text", value: columnSearch, onChange: (e) => setColumnSearch(e.target.value), placeholder: "Search columns..." }) }), _jsxs(ColumnToggleList, { children: [_jsxs(ColumnToggleItem, { style: {
|
|
817
|
+
borderBottom: '1px solid #e5e7eb',
|
|
818
|
+
paddingBottom: 8,
|
|
819
|
+
marginBottom: 4,
|
|
820
|
+
}, children: [_jsx("input", { type: "checkbox", checked: filteredToggleColumns.length > 0 &&
|
|
821
|
+
filteredToggleColumns.every((col) => !isColumnHidden(col.dataField)), onChange: (e) => {
|
|
822
|
+
filteredToggleColumns.forEach((col) => {
|
|
823
|
+
if (e.target.checked) {
|
|
824
|
+
if (isColumnHidden(col.dataField)) {
|
|
825
|
+
toggleColumn(col.dataField);
|
|
826
|
+
}
|
|
827
|
+
}
|
|
828
|
+
else {
|
|
829
|
+
if (!isColumnHidden(col.dataField)) {
|
|
830
|
+
toggleColumn(col.dataField);
|
|
831
|
+
}
|
|
832
|
+
}
|
|
833
|
+
});
|
|
834
|
+
} }), _jsx("span", { style: { fontWeight: 600 }, children: "Select All" })] }), filteredToggleColumns.map((column, index) => (_jsxs(ColumnToggleItem, { "$reorderable": reorderable, "$isDragging": toggleDraggingColumn === column.dataField, "$isDragOver": toggleDragOverColumn === column.dataField, draggable: reorderable, onDragStart: (e) => {
|
|
835
|
+
if (!reorderable)
|
|
836
|
+
return;
|
|
837
|
+
setToggleDraggingColumn(column.dataField);
|
|
838
|
+
e.dataTransfer.effectAllowed = 'move';
|
|
839
|
+
e.dataTransfer.setData('text/plain', column.dataField);
|
|
840
|
+
}, onDragEnd: () => {
|
|
841
|
+
setToggleDraggingColumn(null);
|
|
842
|
+
setToggleDragOverColumn(null);
|
|
843
|
+
}, onDragOver: (e) => {
|
|
844
|
+
if (!reorderable)
|
|
845
|
+
return;
|
|
846
|
+
e.preventDefault();
|
|
847
|
+
if (toggleDraggingColumn &&
|
|
848
|
+
toggleDraggingColumn !== column.dataField) {
|
|
849
|
+
setToggleDragOverColumn(column.dataField);
|
|
850
|
+
}
|
|
851
|
+
}, onDragLeave: () => {
|
|
852
|
+
setToggleDragOverColumn(null);
|
|
853
|
+
}, onDrop: (e) => {
|
|
854
|
+
if (!reorderable)
|
|
855
|
+
return;
|
|
856
|
+
e.preventDefault();
|
|
857
|
+
const draggedField = e.dataTransfer.getData('text/plain');
|
|
858
|
+
if (draggedField &&
|
|
859
|
+
draggedField !== column.dataField) {
|
|
860
|
+
// Find indices
|
|
861
|
+
const fromIdx = reorderedColumns.findIndex((c) => c.dataField === draggedField);
|
|
862
|
+
const toIdx = reorderedColumns.findIndex((c) => c.dataField === column.dataField);
|
|
863
|
+
if (fromIdx !== -1 && toIdx !== -1) {
|
|
864
|
+
// Reorder columns
|
|
865
|
+
const newColumns = [...reorderedColumns];
|
|
866
|
+
const [removed] = newColumns.splice(fromIdx, 1);
|
|
867
|
+
newColumns.splice(toIdx, 0, removed);
|
|
868
|
+
// Update local state
|
|
869
|
+
setReorderedColumns(newColumns);
|
|
870
|
+
// Call reorder callback
|
|
871
|
+
reorderConfig?.onReorder?.(newColumns, fromIdx, toIdx);
|
|
872
|
+
}
|
|
873
|
+
}
|
|
874
|
+
setToggleDraggingColumn(null);
|
|
875
|
+
setToggleDragOverColumn(null);
|
|
876
|
+
}, children: [_jsx("input", { type: "checkbox", checked: !isColumnHidden(column.dataField), onChange: () => toggleColumn(column.dataField), onClick: (e) => e.stopPropagation() }), _jsx("span", { children: column.text }), reorderable && (_jsx(ColumnToggleDragHandle, { "$isDragging": toggleDraggingColumn === column.dataField, title: "Drag to reorder" }))] }, column.dataField)))] })] }))] }))] }), toolbarCenter, _jsxs(ToolbarGroup, { children: [refreshable && (_jsxs(ToolbarButton, { onClick: onRefresh, children: [_jsx(RefreshIcon, {}), "Refresh"] })), printable && (_jsxs(ToolbarButton, { onClick: onPrint, children: [_jsx(PrintIcon, {}), "Print"] })), columnToggle && (_jsxs("div", { ref: !showFilterToggle ? columnToggleRef : undefined, style: { position: 'relative' }, children: [_jsxs(ToolbarButton, { "$active": columnToggleOpen, onClick: () => setColumnToggleOpen(!columnToggleOpen), children: [_jsx(ColumnsIcon, {}), "Columns"] }), columnToggleOpen && (_jsxs(ColumnTogglePanel, { children: [_jsxs(ColumnToggleHeader, { children: [_jsx("span", { children: "Toggle Columns" }), _jsx("button", { onClick: () => setColumnToggleOpen(false), children: _jsx(CloseIcon, {}) })] }), _jsx(ColumnToggleSearch, { children: _jsx("input", { type: "text", value: columnSearch, onChange: (e) => setColumnSearch(e.target.value), placeholder: "Search columns..." }) }), _jsx(ColumnToggleList, { children: filteredToggleColumns.map((column, index) => (_jsxs(ColumnToggleItem, { "$reorderable": reorderable, "$isDragging": toggleDraggingColumn === column.dataField, "$isDragOver": toggleDragOverColumn === column.dataField, draggable: reorderable, onDragStart: (e) => {
|
|
877
|
+
if (!reorderable)
|
|
878
|
+
return;
|
|
879
|
+
setToggleDraggingColumn(column.dataField);
|
|
880
|
+
e.dataTransfer.effectAllowed = 'move';
|
|
881
|
+
e.dataTransfer.setData('text/plain', column.dataField);
|
|
882
|
+
}, onDragEnd: () => {
|
|
883
|
+
setToggleDraggingColumn(null);
|
|
884
|
+
setToggleDragOverColumn(null);
|
|
885
|
+
}, onDragOver: (e) => {
|
|
886
|
+
if (!reorderable)
|
|
887
|
+
return;
|
|
888
|
+
e.preventDefault();
|
|
889
|
+
if (toggleDraggingColumn &&
|
|
890
|
+
toggleDraggingColumn !== column.dataField) {
|
|
891
|
+
setToggleDragOverColumn(column.dataField);
|
|
892
|
+
}
|
|
893
|
+
}, onDragLeave: () => {
|
|
894
|
+
setToggleDragOverColumn(null);
|
|
895
|
+
}, onDrop: (e) => {
|
|
896
|
+
if (!reorderable)
|
|
897
|
+
return;
|
|
898
|
+
e.preventDefault();
|
|
899
|
+
const draggedField = e.dataTransfer.getData('text/plain');
|
|
900
|
+
if (draggedField &&
|
|
901
|
+
draggedField !== column.dataField) {
|
|
902
|
+
const fromIdx = reorderedColumns.findIndex((c) => c.dataField === draggedField);
|
|
903
|
+
const toIdx = reorderedColumns.findIndex((c) => c.dataField === column.dataField);
|
|
904
|
+
if (fromIdx !== -1 && toIdx !== -1) {
|
|
905
|
+
const newColumns = [...reorderedColumns];
|
|
906
|
+
const [removed] = newColumns.splice(fromIdx, 1);
|
|
907
|
+
newColumns.splice(toIdx, 0, removed);
|
|
908
|
+
// Update local state
|
|
909
|
+
setReorderedColumns(newColumns);
|
|
910
|
+
reorderConfig?.onReorder?.(newColumns, fromIdx, toIdx);
|
|
911
|
+
}
|
|
912
|
+
}
|
|
913
|
+
setToggleDraggingColumn(null);
|
|
914
|
+
setToggleDragOverColumn(null);
|
|
915
|
+
}, children: [_jsx("input", { type: "checkbox", checked: !isColumnHidden(column.dataField), onChange: () => toggleColumn(column.dataField), onClick: (e) => e.stopPropagation() }), _jsx("span", { children: column.text }), reorderable && (_jsx(ColumnToggleDragHandle, { "$isDragging": toggleDraggingColumn === column.dataField, title: "Drag to reorder" }))] }, column.dataField))) })] }))] })), toolbarRight] })] }));
|
|
916
|
+
};
|
|
917
|
+
// Render pagination
|
|
918
|
+
const renderPagination = () => {
|
|
919
|
+
if (!pagination)
|
|
920
|
+
return null;
|
|
921
|
+
const actualTotalPages = Math.ceil(calculatedTotal / pageSize) || 1;
|
|
922
|
+
const startItem = calculatedTotal > 0 ? page * pageSize + 1 : 0;
|
|
923
|
+
// Use actual data length for endItem to show correct count
|
|
924
|
+
const actualDataCount = resolvedRemote
|
|
925
|
+
? data.length
|
|
926
|
+
: processedData.length;
|
|
927
|
+
const endItem = Math.min(page * pageSize + actualDataCount, calculatedTotal);
|
|
928
|
+
const showTotal = resolvedPaginationConfig?.showTotal === true
|
|
929
|
+
? `Showing ${startItem} to ${endItem} of ${calculatedTotal} Results`
|
|
930
|
+
: typeof resolvedPaginationConfig?.showTotal === 'function'
|
|
931
|
+
? resolvedPaginationConfig.showTotal(calculatedTotal, [
|
|
932
|
+
startItem,
|
|
933
|
+
endItem,
|
|
934
|
+
])
|
|
935
|
+
: null;
|
|
936
|
+
// Generate page numbers
|
|
937
|
+
const getPageNumbers = () => {
|
|
938
|
+
const pages = [];
|
|
939
|
+
const maxVisible = 5;
|
|
940
|
+
if (actualTotalPages <= maxVisible) {
|
|
941
|
+
for (let i = 0; i < actualTotalPages; i++)
|
|
942
|
+
pages.push(i);
|
|
943
|
+
}
|
|
944
|
+
else {
|
|
945
|
+
if (page < 3) {
|
|
946
|
+
for (let i = 0; i < 4; i++)
|
|
947
|
+
pages.push(i);
|
|
948
|
+
pages.push('...');
|
|
949
|
+
pages.push(actualTotalPages - 1);
|
|
950
|
+
}
|
|
951
|
+
else if (page > actualTotalPages - 4) {
|
|
952
|
+
pages.push(0);
|
|
953
|
+
pages.push('...');
|
|
954
|
+
for (let i = actualTotalPages - 4; i < actualTotalPages; i++)
|
|
955
|
+
pages.push(i);
|
|
956
|
+
}
|
|
957
|
+
else {
|
|
958
|
+
pages.push(0);
|
|
959
|
+
pages.push('...');
|
|
960
|
+
for (let i = page - 1; i <= page + 1; i++)
|
|
961
|
+
pages.push(i);
|
|
962
|
+
pages.push('...');
|
|
963
|
+
pages.push(actualTotalPages - 1);
|
|
964
|
+
}
|
|
965
|
+
}
|
|
966
|
+
return pages;
|
|
967
|
+
};
|
|
968
|
+
return (_jsxs(PaginationWrapper, { className: classNames.pagination, style: styles.pagination, children: [_jsxs(ToolbarGroup, { children: [(resolvedRowSelection?.mode === 'checkbox' || isSelectRow) &&
|
|
969
|
+
selectedKeys.size > 0 && (_jsxs(SelectionIndicator, { onClick: () => {
|
|
970
|
+
const selectedRows = data.filter((row) => selectedKeys.has(getRowKey(row)));
|
|
971
|
+
resolvedRowSelection?.onChange?.(Array.from(selectedKeys), selectedRows);
|
|
972
|
+
// Call onSelectedRow only when user clicks this button
|
|
973
|
+
onSelectedRow?.(selectedRows);
|
|
974
|
+
}, children: [_jsx(SelectionCount, { "$animate": selectionAnimation, children: selectedKeys.size }, selectedKeys.size), _jsx("span", { children: "Selected" })] })), resolvedPaginationConfig?.showSizeChanger !== false && (_jsx(PageSizeSelect, { value: pageSize, onChange: (e) => handlePageSizeChange(Number(e.target.value)), children: (resolvedPaginationConfig?.pageSizeOptions || [10, 20, 30, 50]).map((size) => (_jsx("option", { value: size, children: size }, size))) }))] }), _jsxs(PaginationControls, { children: [_jsx(PageButton, { onClick: () => handlePageChange(0), disabled: page === 0, children: _jsx(ChevronsLeftIcon, {}) }), _jsx(PageButton, { onClick: () => handlePageChange(page - 1), disabled: page === 0, children: _jsx(ChevronLeftIcon, {}) }), getPageNumbers().map((p, i) => typeof p === 'string' ? (_jsx("span", { style: { padding: '0 4px', color: 'white' }, children: p }, `ellipsis-${i}`)) : (_jsx(PageButton, { "$active": p === page, onClick: () => handlePageChange(p), children: p + 1 }, p))), _jsx(PageButton, { onClick: () => handlePageChange(page + 1), disabled: page >= actualTotalPages - 1, children: _jsx(ChevronRightIcon, {}) }), _jsx(PageButton, { onClick: () => handlePageChange(actualTotalPages - 1), disabled: page >= actualTotalPages - 1, children: _jsx(ChevronsRightIcon, {}) })] }), showTotal && _jsx(PaginationInfo, { children: showTotal }), resolvedPaginationConfig?.showQuickJumper &&
|
|
975
|
+
(() => {
|
|
976
|
+
const handleQuickJump = (input) => {
|
|
977
|
+
const pageNum = parseInt(input.value, 10);
|
|
978
|
+
if (!isNaN(pageNum) &&
|
|
979
|
+
pageNum >= 1 &&
|
|
980
|
+
pageNum <= actualTotalPages) {
|
|
981
|
+
handlePageChange(pageNum - 1); // Convert to 0-indexed
|
|
982
|
+
input.value = '';
|
|
983
|
+
return true;
|
|
984
|
+
}
|
|
985
|
+
return false;
|
|
986
|
+
};
|
|
987
|
+
return (_jsxs(QuickJumper, { children: ["Go to", _jsx("input", { type: "number", min: 1, max: actualTotalPages, placeholder: `1-${actualTotalPages}`, onKeyDown: (e) => {
|
|
988
|
+
if (e.key === 'Enter') {
|
|
989
|
+
e.preventDefault();
|
|
990
|
+
const target = e.target;
|
|
991
|
+
if (handleQuickJump(target)) {
|
|
992
|
+
target.blur();
|
|
993
|
+
}
|
|
994
|
+
}
|
|
995
|
+
}, onBlur: (e) => {
|
|
996
|
+
const target = e.target;
|
|
997
|
+
handleQuickJump(target);
|
|
998
|
+
} }), _jsx(PageButton, { onClick: () => {
|
|
999
|
+
const input = document.querySelector(`#${id} input[type="number"]`);
|
|
1000
|
+
if (input) {
|
|
1001
|
+
handleQuickJump(input);
|
|
1002
|
+
input.blur();
|
|
1003
|
+
}
|
|
1004
|
+
}, style: { marginLeft: '4px', padding: '2px 8px' }, children: "Go" })] }));
|
|
1005
|
+
})()] }));
|
|
1006
|
+
};
|
|
1007
|
+
// Check if any columns have filters
|
|
1008
|
+
const hasFilterableColumns = filterable ||
|
|
1009
|
+
columns.some((c) => typeof c.filter === 'function' ||
|
|
1010
|
+
c.filterComponent ||
|
|
1011
|
+
c.filter === true);
|
|
1012
|
+
// Should show filter row - check if there are filterable columns AND filters are visible
|
|
1013
|
+
const shouldShowFilterRow = hasFilterableColumns && showFilterRow;
|
|
1014
|
+
return (_jsxs(TableRoot, { ref: (node) => {
|
|
1015
|
+
// Handle forwarded ref
|
|
1016
|
+
if (typeof ref === 'function') {
|
|
1017
|
+
ref(node);
|
|
1018
|
+
}
|
|
1019
|
+
else if (ref) {
|
|
1020
|
+
ref.current = node;
|
|
1021
|
+
}
|
|
1022
|
+
// Also store in our container ref
|
|
1023
|
+
tableContainerRef.current = node;
|
|
1024
|
+
}, "$bordered": bordered, "$compact": compact, className: className || classNames.root, style: { ...styles.root, ...style, position: 'relative' }, "aria-label": rest['aria-label'], "aria-labelledby": rest['aria-labelledby'], children: [loading && (_jsx(LoadingOverlay, { className: classNames.loading, style: styles.loading, children: loadingIndicator || _jsx(LoadingSpinner, {}) })), renderToolbar(), _jsx(TableWrapper, { "$maxHeight": maxHeight, "$stickyHeader": stickyHeader, className: classNames.wrapper, style: styles.wrapper, children: _jsxs(StyledTable, { ref: tableRef, "$striped": striped, "$hover": hover, "$compact": compact, role: "grid", children: [caption && _jsx("caption", { className: "sr-only", children: caption }), _jsx(TableHeader, { "$sticky": stickyHeader, className: classNames.header, style: styles.header, children: _jsxs(HeaderRow, { className: classNames.headerRow, style: styles.headerRow, children: [resolvedRowSelection?.mode === 'checkbox' && (_jsx(HeaderCell, { "$align": "center", "$sortable": false, "$compact": compact, "$width": resolvedRowSelection.columnWidth || 40, children: !resolvedRowSelection.hideSelectAll && (_jsx(Checkbox, { checked: isAllSelected, ref: (el) => {
|
|
1025
|
+
if (el)
|
|
1026
|
+
el.indeterminate = isIndeterminate;
|
|
1027
|
+
}, onChange: handleSelectAllChange })) })), expandable && (_jsx(HeaderCell, { "$align": "center", "$sortable": false, "$compact": compact, "$width": expandable.columnWidth || 40 })), showRowNumber && (_jsx(HeaderCell, { "$align": "center", "$sortable": false, "$compact": compact, "$width": rowNumberWidth, children: rowNumberTitle })), renderColumns.map((column, colIndex) => {
|
|
1028
|
+
// Determine if column has a filter
|
|
1029
|
+
const hasColumnFilter = typeof column.filter === 'function' ||
|
|
1030
|
+
column.filter === true ||
|
|
1031
|
+
column.filterComponent ||
|
|
1032
|
+
column.filterRenderer;
|
|
1033
|
+
// Get the filter component
|
|
1034
|
+
const FilterComponent = hasColumnFilter
|
|
1035
|
+
? (typeof column.filter === 'function'
|
|
1036
|
+
? column.filter
|
|
1037
|
+
: null) ||
|
|
1038
|
+
column.filterComponent ||
|
|
1039
|
+
getFilterComponent(column.filterType || 'text')
|
|
1040
|
+
: null;
|
|
1041
|
+
const onFilter = (value) => handleFilterChange(column.dataField, value);
|
|
1042
|
+
// Get resized column style
|
|
1043
|
+
const resizeStyle = resizable
|
|
1044
|
+
? getColumnStyle(column, columnWidths, resizable, isResizing)
|
|
1045
|
+
: {};
|
|
1046
|
+
// Render header cell with resize handle
|
|
1047
|
+
// Note: Using callback ref pattern for resize functionality
|
|
1048
|
+
const headerCellRef = (node) => {
|
|
1049
|
+
if (node && resizable) {
|
|
1050
|
+
// Store ref for resize handle
|
|
1051
|
+
const refObj = {
|
|
1052
|
+
current: node,
|
|
1053
|
+
};
|
|
1054
|
+
// Attach resize handle via DOM if needed
|
|
1055
|
+
}
|
|
1056
|
+
};
|
|
1057
|
+
return (_jsxs(HeaderCell, { ref: headerCellRef, "$align": column.headerAlign || column.align || 'left', "$sortable": !!column.sort, "$compact": compact, "$width": resizable && columnWidths[column.dataField]
|
|
1058
|
+
? columnWidths[column.dataField]
|
|
1059
|
+
: column.width, "$minWidth": column.minWidth, "$pinned": column.pinned, "$customClass": !!column.headerClasses, className: [column.headerClasses, classNames.headerCell]
|
|
1060
|
+
.filter(Boolean)
|
|
1061
|
+
.join(' '), style: {
|
|
1062
|
+
...(typeof column.headerStyle === 'function'
|
|
1063
|
+
? column.headerStyle(column)
|
|
1064
|
+
: column.headerStyle || styles.headerCell),
|
|
1065
|
+
...resizeStyle,
|
|
1066
|
+
position: 'relative',
|
|
1067
|
+
}, role: "columnheader", "aria-sort": sort.field === column.dataField
|
|
1068
|
+
? sort.order === 'asc'
|
|
1069
|
+
? 'ascending'
|
|
1070
|
+
: sort.order === 'desc'
|
|
1071
|
+
? 'descending'
|
|
1072
|
+
: 'none'
|
|
1073
|
+
: undefined, "data-column": column.dataField, children: [(() => {
|
|
1074
|
+
// Check visibility props (default to true if not specified)
|
|
1075
|
+
const headerStyleObj = typeof column.headerStyle === 'function'
|
|
1076
|
+
? column.headerStyle(column)
|
|
1077
|
+
: column.headerStyle;
|
|
1078
|
+
// isHeaderTitle: show title (default true, false to hide)
|
|
1079
|
+
const showTitle = column.isHeaderTitle !== false &&
|
|
1080
|
+
column.hideHeaderText !== true &&
|
|
1081
|
+
!(headerStyleObj && headerStyleObj.fontSize === 0);
|
|
1082
|
+
// isHeaderFilterComp: show filter (default true)
|
|
1083
|
+
const showFilter = column.isHeaderFilterComp !== false &&
|
|
1084
|
+
shouldShowFilterRow &&
|
|
1085
|
+
hasColumnFilter &&
|
|
1086
|
+
FilterComponent;
|
|
1087
|
+
// isHeaderSort: show sort icon (default true)
|
|
1088
|
+
const showSort = column.isHeaderSort !== false && column.sort;
|
|
1089
|
+
// If no filter, show title and sort on single line
|
|
1090
|
+
if (!showFilter) {
|
|
1091
|
+
return (_jsxs("div", { style: {
|
|
1092
|
+
display: 'flex',
|
|
1093
|
+
alignItems: 'center',
|
|
1094
|
+
justifyContent: column.headerAlign || column.align || 'left',
|
|
1095
|
+
gap: 6,
|
|
1096
|
+
width: '100%',
|
|
1097
|
+
cursor: showSort ? 'pointer' : 'default',
|
|
1098
|
+
paddingRight: resizable ? 12 : 0,
|
|
1099
|
+
position: 'relative',
|
|
1100
|
+
zIndex: 2, // Above resize handle
|
|
1101
|
+
}, onClick: () => showSort && handleSortClick(column), children: [showTitle && (_jsx("span", { style: {
|
|
1102
|
+
color: 'white',
|
|
1103
|
+
fontWeight: 600,
|
|
1104
|
+
fontSize: 12,
|
|
1105
|
+
whiteSpace: 'nowrap',
|
|
1106
|
+
flex: 1,
|
|
1107
|
+
}, children: column.headerFormatter
|
|
1108
|
+
? column.headerFormatter(column, colIndex)
|
|
1109
|
+
: column.headerText || column.text })), showSort && (_jsx("div", { style: {
|
|
1110
|
+
display: 'flex',
|
|
1111
|
+
alignItems: 'center',
|
|
1112
|
+
justifyContent: 'center',
|
|
1113
|
+
flexShrink: 0,
|
|
1114
|
+
minWidth: 40,
|
|
1115
|
+
minHeight: 24,
|
|
1116
|
+
position: 'relative',
|
|
1117
|
+
overflow: 'visible',
|
|
1118
|
+
}, title: `Sort by ${column.text}`, children: column.sortCaret ? (column.sortCaret(sort.field === column.dataField
|
|
1119
|
+
? sort.order
|
|
1120
|
+
: null, column)) : (_jsx(DefaultSortCaret, { order: sort.field === column.dataField
|
|
1121
|
+
? sort.order
|
|
1122
|
+
: null, column: column })) }))] }));
|
|
1123
|
+
}
|
|
1124
|
+
// With filter: layout with filter + sort
|
|
1125
|
+
return (_jsxs("div", { style: {
|
|
1126
|
+
display: 'flex',
|
|
1127
|
+
flexDirection: 'column',
|
|
1128
|
+
gap: showTitle ? 4 : 0,
|
|
1129
|
+
width: '100%',
|
|
1130
|
+
paddingRight: resizable ? 12 : 0,
|
|
1131
|
+
position: 'relative',
|
|
1132
|
+
zIndex: 2, // Above resize handle
|
|
1133
|
+
}, children: [showTitle && (_jsx("div", { style: {
|
|
1134
|
+
display: 'flex',
|
|
1135
|
+
alignItems: 'center',
|
|
1136
|
+
justifyContent: 'space-between',
|
|
1137
|
+
gap: 4,
|
|
1138
|
+
}, children: _jsx("span", { style: {
|
|
1139
|
+
color: 'white',
|
|
1140
|
+
fontWeight: 600,
|
|
1141
|
+
fontSize: 12,
|
|
1142
|
+
whiteSpace: 'nowrap',
|
|
1143
|
+
cursor: showSort ? 'pointer' : 'default',
|
|
1144
|
+
flex: 1,
|
|
1145
|
+
}, onClick: () => showSort && handleSortClick(column), children: column.headerFormatter
|
|
1146
|
+
? column.headerFormatter(column, colIndex)
|
|
1147
|
+
: column.headerText || column.text }) })), _jsxs("div", { style: {
|
|
1148
|
+
display: 'flex',
|
|
1149
|
+
alignItems: 'center',
|
|
1150
|
+
justifyContent: 'flex-start',
|
|
1151
|
+
gap: 4,
|
|
1152
|
+
width: '100%',
|
|
1153
|
+
minHeight: 24,
|
|
1154
|
+
}, children: [_jsx("div", { style: {
|
|
1155
|
+
flex: showSort ? '0 1 auto' : 1,
|
|
1156
|
+
width: showSort
|
|
1157
|
+
? 'calc(100% - 48px)'
|
|
1158
|
+
: '100%',
|
|
1159
|
+
minWidth: 0,
|
|
1160
|
+
maxWidth: showSort
|
|
1161
|
+
? 'calc(100% - 48px)'
|
|
1162
|
+
: '100%',
|
|
1163
|
+
display: 'flex',
|
|
1164
|
+
alignItems: 'center',
|
|
1165
|
+
overflow: 'hidden',
|
|
1166
|
+
}, onClick: (e) => e.stopPropagation(), children: column.filterRenderer ? (column.filterRenderer(onFilter, column)) : (_jsx("div", { onFocusCapture: () => {
|
|
1167
|
+
focusedFilterFieldRef.current =
|
|
1168
|
+
column.dataField;
|
|
1169
|
+
}, "data-filter-wrapper": column.dataField, style: { width: '100%' }, children: _jsx(FilterComponent, { column: column, value: filters[column.dataField], onChange: onFilter, onClear: () => handleFilterChange(column.dataField, null) }, `filter-${column.dataField}`) })) }), showSort && (_jsx("div", { style: {
|
|
1170
|
+
minWidth: 40,
|
|
1171
|
+
minHeight: 24,
|
|
1172
|
+
display: 'flex',
|
|
1173
|
+
alignItems: 'center',
|
|
1174
|
+
justifyContent: 'center',
|
|
1175
|
+
flexShrink: 0,
|
|
1176
|
+
flexGrow: 0,
|
|
1177
|
+
cursor: 'pointer',
|
|
1178
|
+
marginLeft: 'auto',
|
|
1179
|
+
position: 'relative',
|
|
1180
|
+
overflow: 'visible',
|
|
1181
|
+
}, onClick: (e) => {
|
|
1182
|
+
e.stopPropagation();
|
|
1183
|
+
handleSortClick(column);
|
|
1184
|
+
}, title: `Sort by ${column.text}`, children: column.sortCaret ? (column.sortCaret(sort.field === column.dataField
|
|
1185
|
+
? sort.order
|
|
1186
|
+
: null, column)) : (_jsx(DefaultSortCaret, { order: sort.field === column.dataField
|
|
1187
|
+
? sort.order
|
|
1188
|
+
: null, column: column })) }))] })] }));
|
|
1189
|
+
})(), resizable && (_jsx("div", { style: {
|
|
1190
|
+
position: 'absolute',
|
|
1191
|
+
top: 0,
|
|
1192
|
+
right: 0,
|
|
1193
|
+
bottom: 0,
|
|
1194
|
+
width: 6,
|
|
1195
|
+
cursor: 'col-resize',
|
|
1196
|
+
zIndex: 1,
|
|
1197
|
+
display: 'flex',
|
|
1198
|
+
alignItems: 'center',
|
|
1199
|
+
justifyContent: 'center',
|
|
1200
|
+
}, onMouseDown: (e) => {
|
|
1201
|
+
e.preventDefault();
|
|
1202
|
+
e.stopPropagation();
|
|
1203
|
+
const cell = e.currentTarget
|
|
1204
|
+
.parentElement;
|
|
1205
|
+
if (cell) {
|
|
1206
|
+
const startX = e.clientX;
|
|
1207
|
+
const startWidth = cell.offsetWidth;
|
|
1208
|
+
const dataField = column.dataField;
|
|
1209
|
+
const handleMouseMove = (moveEvent) => {
|
|
1210
|
+
const deltaX = moveEvent.clientX - startX;
|
|
1211
|
+
const newWidth = Math.max(50, Math.min(800, startWidth + deltaX));
|
|
1212
|
+
// Update via CSS for smooth resize
|
|
1213
|
+
cell.style.width = `${newWidth}px`;
|
|
1214
|
+
cell.style.minWidth = `${newWidth}px`;
|
|
1215
|
+
cell.style.maxWidth = `${newWidth}px`;
|
|
1216
|
+
// Update body cells too
|
|
1217
|
+
document
|
|
1218
|
+
.querySelectorAll(`[data-column="${dataField}"]`)
|
|
1219
|
+
.forEach((el) => {
|
|
1220
|
+
el.style.width =
|
|
1221
|
+
`${newWidth}px`;
|
|
1222
|
+
el.style.minWidth =
|
|
1223
|
+
`${newWidth}px`;
|
|
1224
|
+
el.style.maxWidth =
|
|
1225
|
+
`${newWidth}px`;
|
|
1226
|
+
});
|
|
1227
|
+
};
|
|
1228
|
+
const handleMouseUp = () => {
|
|
1229
|
+
document.removeEventListener('mousemove', handleMouseMove);
|
|
1230
|
+
document.removeEventListener('mouseup', handleMouseUp);
|
|
1231
|
+
document.body.style.cursor = '';
|
|
1232
|
+
document.body.style.userSelect = '';
|
|
1233
|
+
// Trigger resize callback
|
|
1234
|
+
const finalWidth = cell.offsetWidth;
|
|
1235
|
+
resizeConfig?.onResizeEnd?.(dataField, finalWidth);
|
|
1236
|
+
};
|
|
1237
|
+
document.addEventListener('mousemove', handleMouseMove);
|
|
1238
|
+
document.addEventListener('mouseup', handleMouseUp);
|
|
1239
|
+
document.body.style.cursor = 'col-resize';
|
|
1240
|
+
document.body.style.userSelect = 'none';
|
|
1241
|
+
resizeConfig?.onResizeStart?.(dataField, startWidth);
|
|
1242
|
+
}
|
|
1243
|
+
}, children: _jsx("div", { style: {
|
|
1244
|
+
width: 3,
|
|
1245
|
+
height: '60%',
|
|
1246
|
+
background: 'rgba(255,255,255,0.3)',
|
|
1247
|
+
borderRadius: 2,
|
|
1248
|
+
transition: 'background 0.2s',
|
|
1249
|
+
}, onMouseEnter: (e) => {
|
|
1250
|
+
e.currentTarget.style.background =
|
|
1251
|
+
resizeConfig?.handleHoverColor || '#3b82f6';
|
|
1252
|
+
}, onMouseLeave: (e) => {
|
|
1253
|
+
e.currentTarget.style.background = 'rgba(255,255,255,0.3)';
|
|
1254
|
+
} }) }))] }, column.dataField));
|
|
1255
|
+
})] }) }), _jsx(TableBody, { className: classNames.body, style: styles.body, children: processedData.length === 0 ? (_jsx("tr", { children: _jsx("td", { colSpan: visibleColumns.length +
|
|
1256
|
+
(resolvedRowSelection?.mode === 'checkbox' ? 1 : 0) +
|
|
1257
|
+
(expandable ? 1 : 0) +
|
|
1258
|
+
(showRowNumber ? 1 : 0), children: _jsxs(EmptyState, { className: classNames.empty, style: styles.empty, children: [_jsx(EmptyIcon, {}), _jsx("span", { children: emptyText })] }) }) })) : (processedData.map((row, rowIndex) => {
|
|
1259
|
+
const rowKey = getRowKey(row);
|
|
1260
|
+
const rowSelected = isSelected(rowKey);
|
|
1261
|
+
const rowExpanded = isExpanded(rowKey);
|
|
1262
|
+
const checkboxProps = resolvedRowSelection?.getCheckboxProps?.(row);
|
|
1263
|
+
const isExpandable = expandable?.rowExpandable?.(row) ?? true;
|
|
1264
|
+
const rowClass = typeof rowClassName === 'function'
|
|
1265
|
+
? rowClassName(row, rowIndex)
|
|
1266
|
+
: rowClassName;
|
|
1267
|
+
const rowStyles = typeof rowStyle === 'function'
|
|
1268
|
+
? rowStyle(row, rowIndex)
|
|
1269
|
+
: rowStyle;
|
|
1270
|
+
const selectedStyle = rowSelected
|
|
1271
|
+
? typeof resolvedRowSelection?.selectedRowStyle ===
|
|
1272
|
+
'function'
|
|
1273
|
+
? resolvedRowSelection.selectedRowStyle(row)
|
|
1274
|
+
: resolvedRowSelection?.selectedRowStyle
|
|
1275
|
+
: undefined;
|
|
1276
|
+
// Check if custom selected style has a background color
|
|
1277
|
+
const hasCustomBgColor = rowSelected &&
|
|
1278
|
+
selectedStyle &&
|
|
1279
|
+
(selectedStyle.backgroundColor || selectedStyle.background);
|
|
1280
|
+
// Apply non-selectable style if row is disabled
|
|
1281
|
+
const disabledStyle = checkboxProps?.disabled
|
|
1282
|
+
? nonSelectableStyle || {
|
|
1283
|
+
backgroundColor: '#f3f4f6',
|
|
1284
|
+
opacity: 0.7,
|
|
1285
|
+
}
|
|
1286
|
+
: undefined;
|
|
1287
|
+
return (_jsxs(React.Fragment, { children: [_jsxs(TableRow, { "$selected": rowSelected, "$clickable": !!onRowClick ||
|
|
1288
|
+
resolvedRowSelection?.mode === 'single' ||
|
|
1289
|
+
expandable?.expandRowByClick === true, "$disabled": !!checkboxProps?.disabled, "$hasCustomSelectedStyle": !!hasCustomBgColor, "data-custom-selected": hasCustomBgColor ? 'true' : undefined, className: `${classNames.row || ''} ${rowClass || ''} ${rowSelected
|
|
1290
|
+
? typeof resolvedRowSelection?.selectedRowClassName ===
|
|
1291
|
+
'function'
|
|
1292
|
+
? resolvedRowSelection.selectedRowClassName(row)
|
|
1293
|
+
: resolvedRowSelection?.selectedRowClassName || ''
|
|
1294
|
+
: ''}`, style: {
|
|
1295
|
+
...styles.row,
|
|
1296
|
+
...rowStyles,
|
|
1297
|
+
...selectedStyle,
|
|
1298
|
+
...disabledStyle,
|
|
1299
|
+
}, onClick: (e) => handleRowClick(row, rowIndex, e), onDoubleClick: (e) => {
|
|
1300
|
+
// Only trigger row-level double click if not handled by a cell
|
|
1301
|
+
// Cells handle their own double-clicks for editing
|
|
1302
|
+
onRowDoubleClick?.(row, rowIndex, e);
|
|
1303
|
+
}, role: "row", "aria-selected": rowSelected, children: [resolvedRowSelection?.mode === 'checkbox' && (_jsx(TableCell, { "$align": "center", "$compact": compact, "$padding": cellPadding, children: _jsx(Checkbox, { checked: rowSelected, disabled: checkboxProps?.disabled, onChange: (e) => handleCheckboxChange(row, e), onClick: (e) => e.stopPropagation() }) })), expandable && (_jsx(TableCell, { "$align": "center", "$compact": compact, "$padding": cellPadding, children: isExpandable && (_jsx(ExpandButton, { "$expanded": rowExpanded, onClick: (e) => handleExpandClick(row, e), children: expandable.expandIcon ? (expandable.expandIcon({
|
|
1304
|
+
expanded: rowExpanded,
|
|
1305
|
+
row,
|
|
1306
|
+
onExpand: () => toggleExpand(row),
|
|
1307
|
+
})) : (_jsx(ExpandIcon, {})) })) })), showRowNumber && (_jsx(TableCell, { "$align": "center", "$compact": compact, "$padding": cellPadding, style: {
|
|
1308
|
+
width: rowNumberWidth,
|
|
1309
|
+
color: '#6b7280',
|
|
1310
|
+
fontWeight: 500,
|
|
1311
|
+
}, children: rowNumberRender
|
|
1312
|
+
? rowNumberRender(rowIndex + 1, row)
|
|
1313
|
+
: rowIndex + 1 + page * pageSize })), renderColumns.map((column, colIndex) => {
|
|
1314
|
+
const cellClass = typeof column.classes === 'function'
|
|
1315
|
+
? column.classes(getNestedValue(row, column.dataField), row, rowIndex, colIndex)
|
|
1316
|
+
: column.classes;
|
|
1317
|
+
const cellStyle = typeof column.style === 'function'
|
|
1318
|
+
? column.style(getNestedValue(row, column.dataField), row, rowIndex, colIndex)
|
|
1319
|
+
: column.style;
|
|
1320
|
+
// Get resized column style for body cells
|
|
1321
|
+
const cellResizeStyle = resizable
|
|
1322
|
+
? getColumnStyle(column, columnWidths, resizable, isResizing)
|
|
1323
|
+
: {};
|
|
1324
|
+
return (_jsx(TableCell, { "$align": column.align || 'left', "$compact": compact, "$padding": cellPadding, "$pinned": column.pinned, "$hasCustomClass": !!cellClass, className: cellClass || classNames.cell, style: {
|
|
1325
|
+
...styles.cell,
|
|
1326
|
+
...cellStyle,
|
|
1327
|
+
...cellResizeStyle,
|
|
1328
|
+
}, "data-column": column.dataField, onClick: (e) => handleCellClick(row, rowIndex, column, colIndex, e), onDoubleClick: (e) => {
|
|
1329
|
+
e.stopPropagation(); // Prevent row-level double-click from interfering
|
|
1330
|
+
handleCellDoubleClick(row, rowIndex, column, colIndex, e);
|
|
1331
|
+
}, role: "gridcell", children: (() => {
|
|
1332
|
+
const editInfo = getCellEditableInfo(column, row, rowIndex, colIndex);
|
|
1333
|
+
if (editInfo.isEditable &&
|
|
1334
|
+
editMode !== 'none') {
|
|
1335
|
+
// Check for custom editor
|
|
1336
|
+
if (editInfo.customEditor) {
|
|
1337
|
+
return editInfo.customEditor;
|
|
1338
|
+
}
|
|
1339
|
+
return (_jsx(EditableCell, { "$editing": editingCell?.row === rowIndex &&
|
|
1340
|
+
editingCell?.field === column.dataField, "$showEditIcon": showEditIcon, children: renderCellContent(row, column, rowIndex, colIndex) }));
|
|
1341
|
+
}
|
|
1342
|
+
return renderCellContent(row, column, rowIndex, colIndex);
|
|
1343
|
+
})() }, column.dataField));
|
|
1344
|
+
})] }), expandable && rowExpanded && isExpandable && (_jsx(ExpandedRow, { children: _jsx(ExpandedCell, { colSpan: visibleColumns.length +
|
|
1345
|
+
(resolvedRowSelection?.mode === 'checkbox'
|
|
1346
|
+
? 1
|
|
1347
|
+
: 0) +
|
|
1348
|
+
(expandable ? 1 : 0) +
|
|
1349
|
+
(showRowNumber ? 1 : 0), children: expandable.expandedRowRender?.(row, rowIndex, rowExpanded) }) }))] }, rowKey));
|
|
1350
|
+
})) }), showFooter && (_jsx(TableFooter, { className: classNames.footer, style: styles.footer, children: _jsxs(FooterRow, { className: classNames.footerRow, style: styles.footerRow, children: [resolvedRowSelection?.mode === 'checkbox' && (_jsx(FooterCell, { "$align": "center", "$compact": compact })), expandable && (_jsx(FooterCell, { "$align": "center", "$compact": compact })), showRowNumber && (_jsx(FooterCell, { "$align": "center", "$compact": compact })), renderColumns.map((column) => (_jsx(FooterCell, { "$align": column.align || 'left', "$compact": compact, className: classNames.footerCell, style: styles.footerCell, children: typeof column.footer === 'function'
|
|
1351
|
+
? column.footer(column, data)
|
|
1352
|
+
: column.footerFormatter
|
|
1353
|
+
? column.footerFormatter(column, data)
|
|
1354
|
+
: column.footer }, column.dataField)))] }) }))] }) }), renderPagination()] }));
|
|
1355
|
+
});
|
|
1356
|
+
Table.displayName = 'Table';
|
|
1357
|
+
export default Table;
|