@grampro/kit 0.0.0-stage → 2.4.1
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/.gbs/skills/gbs-components/SKILL.md +190 -0
- package/.gbs/skills/gbs-components/references/accessibility.md +102 -0
- package/.gbs/skills/gbs-components/references/data-display.md +185 -0
- package/.gbs/skills/gbs-components/references/data-grid.md +116 -0
- package/.gbs/skills/gbs-components/references/forms.md +202 -0
- package/.gbs/skills/gbs-components/references/install.md +211 -0
- package/.gbs/skills/gbs-components/references/overlays.md +206 -0
- package/.gbs/skills/gbs-components/references/pickers.md +83 -0
- package/.gbs/skills/gbs-components/references/styling.md +246 -0
- package/.gbs/skills/gbs-components/references/toaster.md +57 -0
- package/CHANGELOG.md +173 -0
- package/LICENSE +15 -0
- package/README.md +193 -2
- package/index.cjs +1410 -0
- package/package.json +77 -6
- package/schema/passport-v1.schema.json +204 -0
- package/source/components/accordion/README.md +45 -0
- package/source/components/accordion/core/index.ts +2 -0
- package/source/components/accordion/core/open.ts +56 -0
- package/source/components/accordion/core/types.ts +17 -0
- package/source/components/accordion/index.ts +8 -0
- package/source/components/accordion/passport.json +259 -0
- package/source/components/accordion/react/Accordion.tsx +133 -0
- package/source/components/accordion/react/AccordionItem.tsx +120 -0
- package/source/components/accordion/react/context.ts +20 -0
- package/source/components/accordion/react/props.ts +13 -0
- package/source/components/accordion/styles.css +207 -0
- package/source/components/alert/README.md +39 -0
- package/source/components/alert/core/index.ts +2 -0
- package/source/components/alert/core/live.ts +25 -0
- package/source/components/alert/core/types.ts +7 -0
- package/source/components/alert/index.ts +5 -0
- package/source/components/alert/passport.json +250 -0
- package/source/components/alert/react/Alert.tsx +113 -0
- package/source/components/alert/react/icons.tsx +21 -0
- package/source/components/alert/react/locale.ts +5 -0
- package/source/components/alert/react/props.ts +11 -0
- package/source/components/alert/styles.css +154 -0
- package/source/components/avatar/core/identity.ts +103 -0
- package/source/components/avatar/core/index.ts +2 -0
- package/source/components/avatar/core/types.ts +12 -0
- package/source/components/avatar/index.ts +7 -0
- package/source/components/avatar/passport.json +294 -0
- package/source/components/avatar/react/Avatar.tsx +118 -0
- package/source/components/avatar/react/AvatarGroup.tsx +74 -0
- package/source/components/avatar/react/locale.ts +11 -0
- package/source/components/avatar/react/props.ts +6 -0
- package/source/components/avatar/styles.css +225 -0
- package/source/components/badge/README.md +37 -0
- package/source/components/badge/core/count.ts +37 -0
- package/source/components/badge/core/index.ts +2 -0
- package/source/components/badge/core/types.ts +11 -0
- package/source/components/badge/index.ts +7 -0
- package/source/components/badge/passport.json +332 -0
- package/source/components/badge/react/Badge.tsx +89 -0
- package/source/components/badge/react/Tag.tsx +82 -0
- package/source/components/badge/react/locale.ts +5 -0
- package/source/components/badge/react/props.ts +6 -0
- package/source/components/badge/styles.css +203 -0
- package/source/components/breadcrumb/README.md +34 -0
- package/source/components/breadcrumb/core/index.ts +4 -0
- package/source/components/breadcrumb/core/trail.ts +42 -0
- package/source/components/breadcrumb/core/types.ts +20 -0
- package/source/components/breadcrumb/index.ts +5 -0
- package/source/components/breadcrumb/passport.json +243 -0
- package/source/components/breadcrumb/react/Breadcrumb.tsx +177 -0
- package/source/components/breadcrumb/react/locale.ts +6 -0
- package/source/components/breadcrumb/react/props.ts +14 -0
- package/source/components/breadcrumb/styles.css +138 -0
- package/source/components/button/README.md +32 -0
- package/source/components/button/core/index.ts +3 -0
- package/source/components/button/core/state.ts +16 -0
- package/source/components/button/core/types.ts +28 -0
- package/source/components/button/index.ts +5 -0
- package/source/components/button/passport.json +402 -0
- package/source/components/button/passport.manual.json +31 -0
- package/source/components/button/react/Button.tsx +173 -0
- package/source/components/button/react/locale.ts +5 -0
- package/source/components/button/react/props.ts +23 -0
- package/source/components/button/styles.css +232 -0
- package/source/components/card/README.md +60 -0
- package/source/components/card/core/index.ts +4 -0
- package/source/components/card/core/trend.ts +32 -0
- package/source/components/card/core/types.ts +5 -0
- package/source/components/card/index.ts +5 -0
- package/source/components/card/passport.json +337 -0
- package/source/components/card/react/Card.tsx +133 -0
- package/source/components/card/react/Stat.tsx +127 -0
- package/source/components/card/react/props.ts +4 -0
- package/source/components/card/styles.css +230 -0
- package/source/components/checkbox/README.md +36 -0
- package/source/components/checkbox/core/group.ts +30 -0
- package/source/components/checkbox/core/index.ts +3 -0
- package/source/components/checkbox/core/types.ts +17 -0
- package/source/components/checkbox/index.ts +9 -0
- package/source/components/checkbox/passport.json +456 -0
- package/source/components/checkbox/react/Checkbox.tsx +147 -0
- package/source/components/checkbox/react/CheckboxGroup.tsx +149 -0
- package/source/components/checkbox/react/context.ts +16 -0
- package/source/components/checkbox/react/locale.ts +5 -0
- package/source/components/checkbox/react/props.ts +6 -0
- package/source/components/checkbox/styles.css +211 -0
- package/source/components/combobox/README.md +170 -0
- package/source/components/combobox/core/filter.ts +155 -0
- package/source/components/combobox/core/index.ts +16 -0
- package/source/components/combobox/core/types.ts +48 -0
- package/source/components/combobox/core/virtual.ts +67 -0
- package/source/components/combobox/index.ts +13 -0
- package/source/components/combobox/passport.json +456 -0
- package/source/components/combobox/react/Listbox.tsx +310 -0
- package/source/components/combobox/react/MultiSelect.tsx +265 -0
- package/source/components/combobox/react/Popover.tsx +38 -0
- package/source/components/combobox/react/Select.tsx +200 -0
- package/source/components/combobox/react/icons.tsx +11 -0
- package/source/components/combobox/react/locale.ts +16 -0
- package/source/components/combobox/react/props.ts +88 -0
- package/source/components/combobox/react/useCombobox.ts +409 -0
- package/source/components/combobox/styles.css +419 -0
- package/source/components/data-grid/README.md +233 -0
- package/source/components/data-grid/agent/coerce.ts +368 -0
- package/source/components/data-grid/agent/contract.ts +410 -0
- package/source/components/data-grid/agent/dataset.ts +92 -0
- package/source/components/data-grid/agent/engine.ts +470 -0
- package/source/components/data-grid/agent/executors.ts +155 -0
- package/source/components/data-grid/agent/index.ts +79 -0
- package/source/components/data-grid/agent/intent.ts +324 -0
- package/source/components/data-grid/agent/operations.ts +335 -0
- package/source/components/data-grid/agent/validate.ts +630 -0
- package/source/components/data-grid/agent/webmcp.ts +107 -0
- package/source/components/data-grid/core/columnHelper.ts +21 -0
- package/source/components/data-grid/core/columns.ts +288 -0
- package/source/components/data-grid/core/filtering.ts +237 -0
- package/source/components/data-grid/core/grid.ts +638 -0
- package/source/components/data-grid/core/index.ts +14 -0
- package/source/components/data-grid/core/rows.ts +64 -0
- package/source/components/data-grid/core/sorting.ts +133 -0
- package/source/components/data-grid/core/state.ts +82 -0
- package/source/components/data-grid/core/store.ts +52 -0
- package/source/components/data-grid/core/types.ts +302 -0
- package/source/components/data-grid/core/values.ts +98 -0
- package/source/components/data-grid/core/virtual.ts +85 -0
- package/source/components/data-grid/export/csv.ts +32 -0
- package/source/components/data-grid/export/download.ts +12 -0
- package/source/components/data-grid/export/pdf-font.ts +139 -0
- package/source/components/data-grid/export/pdf-writer.ts +113 -0
- package/source/components/data-grid/export/pdf.ts +379 -0
- package/source/components/data-grid/export/table.ts +73 -0
- package/source/components/data-grid/export/xlsx.ts +145 -0
- package/source/components/data-grid/export/zip.ts +87 -0
- package/source/components/data-grid/index.ts +14 -0
- package/source/components/data-grid/passport.json +1051 -0
- package/source/components/data-grid/passport.manual.json +255 -0
- package/source/components/data-grid/react/AskGrid.tsx +164 -0
- package/source/components/data-grid/react/Cell.tsx +282 -0
- package/source/components/data-grid/react/ColumnMenu.tsx +135 -0
- package/source/components/data-grid/react/DataGrid.tsx +335 -0
- package/source/components/data-grid/react/FilterForm.tsx +142 -0
- package/source/components/data-grid/react/HeaderRow.tsx +332 -0
- package/source/components/data-grid/react/Pagination.tsx +107 -0
- package/source/components/data-grid/react/Popover.tsx +35 -0
- package/source/components/data-grid/react/Row.tsx +85 -0
- package/source/components/data-grid/react/Toolbar.tsx +267 -0
- package/source/components/data-grid/react/Viewport.tsx +167 -0
- package/source/components/data-grid/react/context.ts +57 -0
- package/source/components/data-grid/react/hooks.ts +83 -0
- package/source/components/data-grid/react/icons.tsx +45 -0
- package/source/components/data-grid/react/keyboard.ts +110 -0
- package/source/components/data-grid/react/locale.ts +130 -0
- package/source/components/data-grid/styles.css +874 -0
- package/source/components/date-picker/README.md +141 -0
- package/source/components/date-picker/core/calendar.ts +266 -0
- package/source/components/date-picker/core/format.ts +170 -0
- package/source/components/date-picker/core/index.ts +41 -0
- package/source/components/date-picker/core/today.ts +72 -0
- package/source/components/date-picker/core/types.ts +68 -0
- package/source/components/date-picker/index.ts +16 -0
- package/source/components/date-picker/passport.json +407 -0
- package/source/components/date-picker/react/Calendar.tsx +160 -0
- package/source/components/date-picker/react/CalendarPanel.tsx +170 -0
- package/source/components/date-picker/react/DatePicker.tsx +249 -0
- package/source/components/date-picker/react/DateRangePicker.tsx +291 -0
- package/source/components/date-picker/react/MonthYearPanels.tsx +123 -0
- package/source/components/date-picker/react/Popover.tsx +45 -0
- package/source/components/date-picker/react/icons.tsx +15 -0
- package/source/components/date-picker/react/locale.ts +23 -0
- package/source/components/date-picker/react/props.ts +76 -0
- package/source/components/date-picker/react/useDatePicker.ts +557 -0
- package/source/components/date-picker/styles.css +445 -0
- package/source/components/dialog/README.md +39 -0
- package/source/components/dialog/core/api.ts +34 -0
- package/source/components/dialog/core/dialog.ts +11 -0
- package/source/components/dialog/core/index.ts +7 -0
- package/source/components/dialog/core/store.ts +81 -0
- package/source/components/dialog/core/types.ts +59 -0
- package/source/components/dialog/index.ts +7 -0
- package/source/components/dialog/passport.json +344 -0
- package/source/components/dialog/react/Dialog.tsx +279 -0
- package/source/components/dialog/react/DialogHost.tsx +45 -0
- package/source/components/dialog/react/icons.tsx +20 -0
- package/source/components/dialog/react/locale.ts +8 -0
- package/source/components/dialog/react/props.ts +13 -0
- package/source/components/dialog/styles.css +280 -0
- package/source/components/file-uploader/README.md +99 -0
- package/source/components/file-uploader/core/format.ts +79 -0
- package/source/components/file-uploader/core/index.ts +26 -0
- package/source/components/file-uploader/core/store.ts +432 -0
- package/source/components/file-uploader/core/transport.ts +154 -0
- package/source/components/file-uploader/core/types.ts +126 -0
- package/source/components/file-uploader/core/validate.ts +83 -0
- package/source/components/file-uploader/index.ts +7 -0
- package/source/components/file-uploader/passport.json +518 -0
- package/source/components/file-uploader/react/FileRow.tsx +268 -0
- package/source/components/file-uploader/react/FileUploader.tsx +511 -0
- package/source/components/file-uploader/react/icons.tsx +60 -0
- package/source/components/file-uploader/react/locale.ts +33 -0
- package/source/components/file-uploader/react/props.ts +31 -0
- package/source/components/file-uploader/react/useFileUploader.ts +32 -0
- package/source/components/file-uploader/styles.css +394 -0
- package/source/components/input/README.md +44 -0
- package/source/components/input/core/count.ts +5 -0
- package/source/components/input/core/index.ts +11 -0
- package/source/components/input/core/otp.ts +64 -0
- package/source/components/input/core/types.ts +14 -0
- package/source/components/input/index.ts +8 -0
- package/source/components/input/passport.json +536 -0
- package/source/components/input/react/Input.tsx +219 -0
- package/source/components/input/react/OtpInput.tsx +256 -0
- package/source/components/input/react/dom.ts +10 -0
- package/source/components/input/react/icons.tsx +17 -0
- package/source/components/input/react/locale.ts +9 -0
- package/source/components/input/react/props.ts +6 -0
- package/source/components/input/styles.css +295 -0
- package/source/components/menu/README.md +68 -0
- package/source/components/menu/core/index.ts +11 -0
- package/source/components/menu/core/navigation.ts +84 -0
- package/source/components/menu/core/types.ts +32 -0
- package/source/components/menu/index.ts +19 -0
- package/source/components/menu/passport.json +322 -0
- package/source/components/menu/react/Menu.tsx +371 -0
- package/source/components/menu/react/context.ts +31 -0
- package/source/components/menu/react/items.tsx +268 -0
- package/source/components/menu/react/locale.ts +6 -0
- package/source/components/menu/react/props.ts +4 -0
- package/source/components/menu/react/useMenuKeys.ts +124 -0
- package/source/components/menu/styles.css +224 -0
- package/source/components/modal/README.md +51 -0
- package/source/components/modal/core/dismiss.ts +29 -0
- package/source/components/modal/core/index.ts +3 -0
- package/source/components/modal/core/types.ts +27 -0
- package/source/components/modal/index.ts +5 -0
- package/source/components/modal/passport.json +289 -0
- package/source/components/modal/react/Modal.tsx +242 -0
- package/source/components/modal/react/icons.tsx +1 -0
- package/source/components/modal/react/locale.ts +5 -0
- package/source/components/modal/react/props.ts +17 -0
- package/source/components/modal/styles.css +241 -0
- package/source/components/number-input/README.md +53 -0
- package/source/components/number-input/core/format.ts +37 -0
- package/source/components/number-input/core/index.ts +4 -0
- package/source/components/number-input/core/parse.ts +118 -0
- package/source/components/number-input/core/step.ts +73 -0
- package/source/components/number-input/core/types.ts +32 -0
- package/source/components/number-input/index.ts +5 -0
- package/source/components/number-input/passport.json +541 -0
- package/source/components/number-input/react/NumberInput.tsx +465 -0
- package/source/components/number-input/react/icons.tsx +17 -0
- package/source/components/number-input/react/locale.ts +7 -0
- package/source/components/number-input/react/props.ts +11 -0
- package/source/components/number-input/styles.css +230 -0
- package/source/components/popover/README.md +44 -0
- package/source/components/popover/core/index.ts +2 -0
- package/source/components/popover/core/types.ts +12 -0
- package/source/components/popover/index.ts +4 -0
- package/source/components/popover/passport.json +238 -0
- package/source/components/popover/react/Popover.tsx +202 -0
- package/source/components/popover/react/locale.ts +5 -0
- package/source/components/popover/react/props.ts +4 -0
- package/source/components/popover/styles.css +148 -0
- package/source/components/progress/README.md +38 -0
- package/source/components/progress/core/index.ts +2 -0
- package/source/components/progress/core/progress.ts +40 -0
- package/source/components/progress/core/types.ts +23 -0
- package/source/components/progress/index.ts +7 -0
- package/source/components/progress/passport.json +270 -0
- package/source/components/progress/react/CircularProgress.tsx +106 -0
- package/source/components/progress/react/Progress.tsx +113 -0
- package/source/components/progress/react/locale.ts +7 -0
- package/source/components/progress/react/props.ts +6 -0
- package/source/components/progress/styles.css +200 -0
- package/source/components/radio-group/README.md +58 -0
- package/source/components/radio-group/core/group.ts +36 -0
- package/source/components/radio-group/core/index.ts +2 -0
- package/source/components/radio-group/core/types.ts +20 -0
- package/source/components/radio-group/index.ts +9 -0
- package/source/components/radio-group/passport.json +477 -0
- package/source/components/radio-group/react/Radio.tsx +144 -0
- package/source/components/radio-group/react/RadioGroup.tsx +179 -0
- package/source/components/radio-group/react/context.ts +18 -0
- package/source/components/radio-group/react/locale.ts +5 -0
- package/source/components/radio-group/react/props.ts +12 -0
- package/source/components/radio-group/styles.css +269 -0
- package/source/components/shared/README.md +54 -0
- package/source/components/shared/core/agent/adapter.ts +65 -0
- package/source/components/shared/core/agent/history.ts +120 -0
- package/source/components/shared/core/agent/index.ts +46 -0
- package/source/components/shared/core/agent/numbers.ts +217 -0
- package/source/components/shared/core/agent/schema.ts +180 -0
- package/source/components/shared/core/agent/types.ts +169 -0
- package/source/components/shared/core/agent/webmcp.ts +328 -0
- package/source/components/shared/core/cx.ts +9 -0
- package/source/components/shared/core/field.ts +35 -0
- package/source/components/shared/core/position.ts +124 -0
- package/source/components/shared/core/text.ts +14 -0
- package/source/components/shared/index.ts +17 -0
- package/source/components/shared/react/GramproAIProvider.tsx +50 -0
- package/source/components/shared/react/Popover.tsx +189 -0
- package/source/components/shared/react/icons.tsx +74 -0
- package/source/components/shared/react/useAskAgent.ts +217 -0
- package/source/components/shared/react/useControllableState.ts +42 -0
- package/source/components/shared/styles.css +79 -0
- package/source/components/shared/version.json +4 -0
- package/source/components/shared/version.ts +6 -0
- package/source/components/skeleton/README.md +58 -0
- package/source/components/skeleton/core/index.ts +3 -0
- package/source/components/skeleton/core/lines.ts +25 -0
- package/source/components/skeleton/core/types.ts +5 -0
- package/source/components/skeleton/index.ts +5 -0
- package/source/components/skeleton/passport.json +251 -0
- package/source/components/skeleton/react/Empty.tsx +51 -0
- package/source/components/skeleton/react/Skeleton.tsx +92 -0
- package/source/components/skeleton/react/props.ts +4 -0
- package/source/components/skeleton/styles.css +185 -0
- package/source/components/spinner/README.md +29 -0
- package/source/components/spinner/core/index.ts +3 -0
- package/source/components/spinner/core/types.ts +28 -0
- package/source/components/spinner/core/visibility.ts +34 -0
- package/source/components/spinner/index.ts +6 -0
- package/source/components/spinner/passport.json +245 -0
- package/source/components/spinner/react/Spinner.tsx +96 -0
- package/source/components/spinner/react/locale.ts +5 -0
- package/source/components/spinner/react/props.ts +4 -0
- package/source/components/spinner/react/useDelayedLoading.ts +39 -0
- package/source/components/spinner/styles.css +173 -0
- package/source/components/switch/README.md +46 -0
- package/source/components/switch/core/index.ts +2 -0
- package/source/components/switch/core/toggle.ts +54 -0
- package/source/components/switch/core/types.ts +9 -0
- package/source/components/switch/index.ts +5 -0
- package/source/components/switch/passport.json +421 -0
- package/source/components/switch/react/Switch.tsx +219 -0
- package/source/components/switch/react/locale.ts +5 -0
- package/source/components/switch/react/props.ts +12 -0
- package/source/components/switch/styles.css +227 -0
- package/source/components/tabs/README.md +32 -0
- package/source/components/tabs/core/index.ts +3 -0
- package/source/components/tabs/core/navigation.ts +54 -0
- package/source/components/tabs/core/types.ts +16 -0
- package/source/components/tabs/index.ts +5 -0
- package/source/components/tabs/passport.json +315 -0
- package/source/components/tabs/react/Tabs.tsx +306 -0
- package/source/components/tabs/react/context.ts +21 -0
- package/source/components/tabs/styles.css +263 -0
- package/source/components/textarea/README.md +39 -0
- package/source/components/textarea/core/count.ts +5 -0
- package/source/components/textarea/core/index.ts +4 -0
- package/source/components/textarea/core/size.ts +23 -0
- package/source/components/textarea/core/types.ts +17 -0
- package/source/components/textarea/index.ts +5 -0
- package/source/components/textarea/passport.json +382 -0
- package/source/components/textarea/react/Textarea.tsx +208 -0
- package/source/components/textarea/react/locale.ts +5 -0
- package/source/components/textarea/react/props.ts +4 -0
- package/source/components/textarea/styles.css +158 -0
- package/source/components/toaster/README.md +128 -0
- package/source/components/toaster/core/api.ts +87 -0
- package/source/components/toaster/core/index.ts +14 -0
- package/source/components/toaster/core/store.ts +211 -0
- package/source/components/toaster/core/toast.ts +12 -0
- package/source/components/toaster/core/types.ts +78 -0
- package/source/components/toaster/index.ts +6 -0
- package/source/components/toaster/passport.json +221 -0
- package/source/components/toaster/react/ToastItem.tsx +164 -0
- package/source/components/toaster/react/Toaster.tsx +187 -0
- package/source/components/toaster/react/icons.tsx +23 -0
- package/source/components/toaster/react/locale.ts +6 -0
- package/source/components/toaster/react/props.ts +15 -0
- package/source/components/toaster/react/useToasts.ts +11 -0
- package/source/components/toaster/styles.css +282 -0
- package/source/components/tooltip/README.md +43 -0
- package/source/components/tooltip/core/index.ts +4 -0
- package/source/components/tooltip/core/types.ts +4 -0
- package/source/components/tooltip/core/visibility.ts +34 -0
- package/source/components/tooltip/index.ts +3 -0
- package/source/components/tooltip/passport.json +170 -0
- package/source/components/tooltip/react/Tooltip.tsx +196 -0
- package/source/components/tooltip/react/props.ts +4 -0
- package/source/components/tooltip/styles.css +71 -0
- package/source/fallback/index.tsx +11 -0
- package/source/globalStyle.ts +74 -0
- package/source/hooks/SelectionHooks/type.ts +4 -0
- package/source/hooks/SelectionHooks/useClickOutside.ts +22 -0
- package/source/hooks/SelectionHooks/useMultiSelectState.ts +64 -0
- package/source/hooks/SelectionHooks/useSelectData.ts +58 -0
- package/source/hooks/SelectionHooks/useSelectState.ts +36 -0
- package/source/icon/Icon.tsx +102 -0
- package/source/icon/iconPaths.ts +206 -0
- package/source/legacy-components/bargraph/index.tsx +95 -0
- package/source/legacy-components/bargraph/type.ts +12 -0
- package/source/legacy-components/breadcrumb/index.tsx +66 -0
- package/source/legacy-components/breadcrumb/types.ts +10 -0
- package/source/legacy-components/button/index.tsx +42 -0
- package/source/legacy-components/card/index.tsx +31 -0
- package/source/legacy-components/checkbox/index.tsx +25 -0
- package/source/legacy-components/contextmenu/ContextMenu.tsx +87 -0
- package/source/legacy-components/contextmenu/ContextMenuItem.tsx +30 -0
- package/source/legacy-components/contextmenu/index.ts +2 -0
- package/source/legacy-components/contextmenu/types.ts +19 -0
- package/source/legacy-components/darkmode/index.tsx +55 -0
- package/source/legacy-components/datagrid/context/GridContext.tsx +215 -0
- package/source/legacy-components/datagrid/createTemplate.tsx +82 -0
- package/source/legacy-components/datagrid/hooks/index.ts +6 -0
- package/source/legacy-components/datagrid/hooks/useColumns.ts +33 -0
- package/source/legacy-components/datagrid/hooks/useDataSource.ts +54 -0
- package/source/legacy-components/datagrid/hooks/useFiltering.ts +169 -0
- package/source/legacy-components/datagrid/hooks/usePagination.ts +112 -0
- package/source/legacy-components/datagrid/hooks/useRowSelection.ts +48 -0
- package/source/legacy-components/datagrid/hooks/useSearch.ts +90 -0
- package/source/legacy-components/datagrid/index.tsx +28 -0
- package/source/legacy-components/datagrid/layout/FilterPopup.tsx +92 -0
- package/source/legacy-components/datagrid/layout/GridBody.tsx +184 -0
- package/source/legacy-components/datagrid/layout/GridPagination.tsx +119 -0
- package/source/legacy-components/datagrid/layout/GridToolbar.tsx +109 -0
- package/source/legacy-components/datagrid/layout/index.tsx +68 -0
- package/source/legacy-components/datagrid/type.ts +198 -0
- package/source/legacy-components/datepicker/index.tsx +365 -0
- package/source/legacy-components/datepicker/types.ts +12 -0
- package/source/legacy-components/dialog/index.tsx +44 -0
- package/source/legacy-components/dialog/types.ts +12 -0
- package/source/legacy-components/formrenderer/componentHandles/CheckBoxHandles.tsx +80 -0
- package/source/legacy-components/formrenderer/componentHandles/DatePickerHandles.tsx +93 -0
- package/source/legacy-components/formrenderer/componentHandles/InputHandles.tsx +106 -0
- package/source/legacy-components/formrenderer/componentHandles/MultiHandles.tsx +93 -0
- package/source/legacy-components/formrenderer/componentHandles/SelectHandles.tsx +95 -0
- package/source/legacy-components/formrenderer/helperFunctions.ts +72 -0
- package/source/legacy-components/formrenderer/index.tsx +93 -0
- package/source/legacy-components/formrenderer/types.ts +127 -0
- package/source/legacy-components/input/index.tsx +142 -0
- package/source/legacy-components/input/types.ts +10 -0
- package/source/legacy-components/materialInput/index.tsx +138 -0
- package/source/legacy-components/materialInput/types.ts +16 -0
- package/source/legacy-components/modal/index.tsx +152 -0
- package/source/legacy-components/modal/types.ts +19 -0
- package/source/legacy-components/multiselect/PortalDropDown.tsx +44 -0
- package/source/legacy-components/multiselect/index.tsx +269 -0
- package/source/legacy-components/multiselect/types.ts +26 -0
- package/source/legacy-components/navbar/AuthSection.tsx +98 -0
- package/source/legacy-components/navbar/MobileToggle.tsx +31 -0
- package/source/legacy-components/navbar/NavItemComponent.tsx +119 -0
- package/source/legacy-components/navbar/SearchBar.tsx +55 -0
- package/source/legacy-components/navbar/helperFunctions.ts +27 -0
- package/source/legacy-components/navbar/index.tsx +156 -0
- package/source/legacy-components/navbar/types.ts +69 -0
- package/source/legacy-components/select/PortalDropDown.tsx +59 -0
- package/source/legacy-components/select/index.tsx +249 -0
- package/source/legacy-components/select/types.ts +29 -0
- package/source/legacy-components/sidebar/components/MenuItem.tsx +101 -0
- package/source/legacy-components/sidebar/components/MenuSection.tsx +34 -0
- package/source/legacy-components/sidebar/components/SidebarFooter.tsx +50 -0
- package/source/legacy-components/sidebar/components/SidebarLogo.tsx +24 -0
- package/source/legacy-components/sidebar/components/SidebarMenu.tsx +29 -0
- package/source/legacy-components/sidebar/components/UserProfile.tsx +31 -0
- package/source/legacy-components/sidebar/hooks/useSidebarState.ts +41 -0
- package/source/legacy-components/sidebar/index.tsx +77 -0
- package/source/legacy-components/sidebar/type.ts +42 -0
- package/source/legacy-components/spinner/Stroke.tsx +89 -0
- package/source/legacy-components/spinner/index.tsx +54 -0
- package/source/legacy-components/spinner/types.ts +9 -0
- package/source/legacy-components/tabs/index.tsx +71 -0
- package/source/legacy-components/tabs/types.ts +16 -0
- package/source/legacy-components/textarea/index.tsx +123 -0
- package/source/legacy-components/textarea/types.ts +15 -0
- package/source/legacy-components/toast/ToastComponent.tsx +101 -0
- package/source/legacy-components/toast/ToastIcon.tsx +61 -0
- package/source/legacy-components/toast/index.tsx +42 -0
- package/source/legacy-components/toast/toastStore.ts +42 -0
- package/source/legacy-components/toast/types.ts +18 -0
- package/source/legacy-components/toast/useToast.ts +12 -0
- package/source/legacy-components/uploader/ProgressAnimation.tsx +50 -0
- package/source/legacy-components/uploader/UploadedFilePreview.tsx +130 -0
- package/source/legacy-components/uploader/index.tsx +311 -0
- package/source/legacy-components/uploader/types.ts +30 -0
- package/source/legacy-components/uploader/uploaderIcon.tsx +72 -0
- package/source/legacy-components/uploader/uploaderService.ts +134 -0
- package/source/legacy-components/useUploader/useUploader.tsx +310 -0
- package/source/legacy-components/usepaginateddata/usePaginatedData.ts +174 -0
- package/source/theme.ts +40 -0
- package/source/utils.ts +10 -0
- package/tools/env.cjs +61 -0
- package/tools/passport/cli.cjs +79 -0
- package/tools/passport/extract.cjs +493 -0
- package/tools/passport/index.cjs +185 -0
- package/tools/passport/merge.cjs +131 -0
- package/tools/passport/policy.cjs +65 -0
- package/tools/passport/validate.cjs +277 -0
- package/tools/ts-require.cjs +79 -0
|
@@ -0,0 +1,215 @@
|
|
|
1
|
+
import React, { createContext, useContext } from "react";
|
|
2
|
+
import type { GridContextType, GridProps } from "../type";
|
|
3
|
+
import { gridStyles } from "../../globalStyle";
|
|
4
|
+
import {
|
|
5
|
+
useDataSource,
|
|
6
|
+
useColumns,
|
|
7
|
+
usePagination,
|
|
8
|
+
useSearch,
|
|
9
|
+
useFiltering,
|
|
10
|
+
useRowSelection,
|
|
11
|
+
} from "../hooks";
|
|
12
|
+
|
|
13
|
+
const GridContext = createContext<GridContextType | undefined>(undefined);
|
|
14
|
+
|
|
15
|
+
export const GridProvider: React.FC<{
|
|
16
|
+
children: React.ReactNode;
|
|
17
|
+
props: GridProps;
|
|
18
|
+
}> = ({ children, props }) => {
|
|
19
|
+
const {
|
|
20
|
+
dataSource,
|
|
21
|
+
columns = [],
|
|
22
|
+
enableSearch = false,
|
|
23
|
+
lazy = false,
|
|
24
|
+
enableExcelExport = false,
|
|
25
|
+
excelName = "data",
|
|
26
|
+
enablePdfExport = false,
|
|
27
|
+
pdfName = "data",
|
|
28
|
+
pdfOptions = {},
|
|
29
|
+
selectAll = false,
|
|
30
|
+
onSelectRow,
|
|
31
|
+
isFetching,
|
|
32
|
+
gridColumnStyleSelectAll = "px-4 text-xs",
|
|
33
|
+
gridColumnStyle = "p-2 text-xs",
|
|
34
|
+
showTotalPages = false,
|
|
35
|
+
onSearch = () => {},
|
|
36
|
+
onToolbarButtonClick = () => {},
|
|
37
|
+
initialFilters = [],
|
|
38
|
+
initialSearchParam = "",
|
|
39
|
+
} = props;
|
|
40
|
+
|
|
41
|
+
// Resolve pageSize with fallbacks
|
|
42
|
+
const resolvedPageSize = props.pageSize || props.pageSettings?.pageNumber || 10;
|
|
43
|
+
const resolvedPageSettings = {
|
|
44
|
+
pageNumber: resolvedPageSize,
|
|
45
|
+
totalCount: props.pageSettings?.totalCount,
|
|
46
|
+
};
|
|
47
|
+
|
|
48
|
+
// Resolve callback aliases
|
|
49
|
+
const resolvedRowChange = props.onRowClick || props.rowChange || (() => {});
|
|
50
|
+
const resolvedPageStatus = props.onPageChange || props.pageStatus || (() => {});
|
|
51
|
+
const resolvedActiveFilterArrayValue = props.onFilterChange || props.activeFilterArrayValue;
|
|
52
|
+
const resolvedSearchParamValue = props.onSearchChange || props.searchParamValue || (() => {});
|
|
53
|
+
|
|
54
|
+
// Resolve CSS classes using design tokens from theme presets
|
|
55
|
+
const gridContainerClass = props.gridContainerClass || gridStyles.container;
|
|
56
|
+
const gridButtonClass = props.gridButtonClass || gridStyles.button;
|
|
57
|
+
const tableHeaderStyle = props.tableHeaderStyle || gridStyles.tableHeader;
|
|
58
|
+
const gridToolbarClass = props.gridToolbarClass || gridStyles.toolbar;
|
|
59
|
+
const gridPaginationClass = props.gridPaginationClass || gridStyles.pagination;
|
|
60
|
+
const gridRowEvenClass = props.gridRowEvenClass || gridStyles.rowEven;
|
|
61
|
+
const gridRowOddClass = props.gridRowOddClass || gridStyles.rowOdd;
|
|
62
|
+
const gridRowSelectedClass = props.gridRowSelectedClass || gridStyles.rowSelected;
|
|
63
|
+
|
|
64
|
+
// Data source management
|
|
65
|
+
const {
|
|
66
|
+
workingDataSource,
|
|
67
|
+
setWorkingDataSource,
|
|
68
|
+
fallbackSourceData,
|
|
69
|
+
totalPages,
|
|
70
|
+
setTotalPages,
|
|
71
|
+
} = useDataSource(dataSource, resolvedPageSettings, lazy);
|
|
72
|
+
|
|
73
|
+
// Column management
|
|
74
|
+
const { workingColumns, setWorkingColumns } = useColumns(
|
|
75
|
+
columns,
|
|
76
|
+
workingDataSource,
|
|
77
|
+
);
|
|
78
|
+
|
|
79
|
+
// Pagination management
|
|
80
|
+
const {
|
|
81
|
+
currentPage,
|
|
82
|
+
pageStart,
|
|
83
|
+
pageEnd,
|
|
84
|
+
nextPage,
|
|
85
|
+
prevPage,
|
|
86
|
+
goToEndPage,
|
|
87
|
+
goToFirstPage,
|
|
88
|
+
goToPage,
|
|
89
|
+
resetPage,
|
|
90
|
+
} = usePagination(
|
|
91
|
+
totalPages,
|
|
92
|
+
lazy,
|
|
93
|
+
workingDataSource,
|
|
94
|
+
resolvedPageStatus,
|
|
95
|
+
);
|
|
96
|
+
|
|
97
|
+
// Search functionality
|
|
98
|
+
const { searchParam, handleSearchInput, handleSearch } = useSearch({
|
|
99
|
+
workingDataSource,
|
|
100
|
+
setWorkingDataSource,
|
|
101
|
+
fallbackSourceData,
|
|
102
|
+
dataSource,
|
|
103
|
+
lazy,
|
|
104
|
+
pageSettings: resolvedPageSettings,
|
|
105
|
+
resetPage,
|
|
106
|
+
setTotalPages,
|
|
107
|
+
searchParamValue: resolvedSearchParamValue,
|
|
108
|
+
initialSearchParam,
|
|
109
|
+
});
|
|
110
|
+
|
|
111
|
+
// Filtering functionality
|
|
112
|
+
const {
|
|
113
|
+
activeFilterArray,
|
|
114
|
+
toggleFilterPopup,
|
|
115
|
+
handleApplyFilter,
|
|
116
|
+
clearFilter,
|
|
117
|
+
handleFilterAction,
|
|
118
|
+
} = useFiltering({
|
|
119
|
+
columns,
|
|
120
|
+
workingColumns,
|
|
121
|
+
setWorkingColumns,
|
|
122
|
+
workingDataSource,
|
|
123
|
+
setWorkingDataSource,
|
|
124
|
+
dataSource,
|
|
125
|
+
fallbackSourceData,
|
|
126
|
+
resetPage,
|
|
127
|
+
setTotalPages,
|
|
128
|
+
pageSettings: resolvedPageSettings,
|
|
129
|
+
activeFilterArrayValue: resolvedActiveFilterArrayValue,
|
|
130
|
+
lazy,
|
|
131
|
+
initialFilters,
|
|
132
|
+
});
|
|
133
|
+
|
|
134
|
+
// Row selection functionality
|
|
135
|
+
const { selectedRows, handleSelectAll, handleSelect, isRowSelected } =
|
|
136
|
+
useRowSelection(workingDataSource, onSelectRow);
|
|
137
|
+
|
|
138
|
+
// Context value
|
|
139
|
+
const contextValue: GridContextType = {
|
|
140
|
+
// State
|
|
141
|
+
workingDataSource,
|
|
142
|
+
fallbackSourceData,
|
|
143
|
+
workingColumns,
|
|
144
|
+
currentPage,
|
|
145
|
+
pageStart,
|
|
146
|
+
pageEnd,
|
|
147
|
+
totalPages,
|
|
148
|
+
searchParam,
|
|
149
|
+
activeFilterArray,
|
|
150
|
+
selectedRows,
|
|
151
|
+
isFetching,
|
|
152
|
+
|
|
153
|
+
// Navigation methods
|
|
154
|
+
nextPage,
|
|
155
|
+
prevPage,
|
|
156
|
+
goToEndPage,
|
|
157
|
+
goToFirstPage,
|
|
158
|
+
goToPage,
|
|
159
|
+
lazy,
|
|
160
|
+
|
|
161
|
+
// Search methods
|
|
162
|
+
handleSearchInput,
|
|
163
|
+
handleSearch,
|
|
164
|
+
|
|
165
|
+
// Filter methods
|
|
166
|
+
toggleFilterPopup,
|
|
167
|
+
handleApplyFilter,
|
|
168
|
+
clearFilter,
|
|
169
|
+
handleFilterAction,
|
|
170
|
+
|
|
171
|
+
// Row selection methods
|
|
172
|
+
handleSelectAll,
|
|
173
|
+
handleSelect,
|
|
174
|
+
isRowSelected,
|
|
175
|
+
|
|
176
|
+
// Grid settings
|
|
177
|
+
columns,
|
|
178
|
+
pageSettings: resolvedPageSettings,
|
|
179
|
+
pageSize: resolvedPageSize,
|
|
180
|
+
enableSearch,
|
|
181
|
+
enableExcelExport,
|
|
182
|
+
enablePdfExport,
|
|
183
|
+
excelName,
|
|
184
|
+
pdfName,
|
|
185
|
+
pdfOptions,
|
|
186
|
+
gridButtonClass,
|
|
187
|
+
selectAll,
|
|
188
|
+
tableHeaderStyle,
|
|
189
|
+
gridContainerClass,
|
|
190
|
+
gridToolbarClass,
|
|
191
|
+
gridPaginationClass,
|
|
192
|
+
gridRowEvenClass,
|
|
193
|
+
gridRowOddClass,
|
|
194
|
+
gridRowSelectedClass,
|
|
195
|
+
gridColumnStyleSelectAll,
|
|
196
|
+
gridColumnStyle,
|
|
197
|
+
rowChange: resolvedRowChange,
|
|
198
|
+
showTotalPages,
|
|
199
|
+
onSearch,
|
|
200
|
+
onToolbarButtonClick,
|
|
201
|
+
};
|
|
202
|
+
|
|
203
|
+
return (
|
|
204
|
+
<GridContext.Provider value={contextValue}>{children}</GridContext.Provider>
|
|
205
|
+
);
|
|
206
|
+
};
|
|
207
|
+
|
|
208
|
+
// Base context hook
|
|
209
|
+
export const useGridContext = () => {
|
|
210
|
+
const context = useContext(GridContext);
|
|
211
|
+
if (context === undefined) {
|
|
212
|
+
throw new Error("useGridContext must be used within a GridProvider");
|
|
213
|
+
}
|
|
214
|
+
return context;
|
|
215
|
+
};
|
|
@@ -0,0 +1,82 @@
|
|
|
1
|
+
export const createTemplate = (
|
|
2
|
+
type: string,
|
|
3
|
+
config: any = {},
|
|
4
|
+
CustomTemplate?: any
|
|
5
|
+
) => {
|
|
6
|
+
return ({ rowData }: { rowData: any }) => {
|
|
7
|
+
const field = config.field || "unknown";
|
|
8
|
+
|
|
9
|
+
const handleInputChange = (e: React.ChangeEvent<HTMLInputElement>) => {
|
|
10
|
+
const value =
|
|
11
|
+
config.type === "number" ? Number(e.target.value) : e.target.value;
|
|
12
|
+
rowData[field] = value;
|
|
13
|
+
config.onDataChange?.(rowData.id, field, value);
|
|
14
|
+
};
|
|
15
|
+
|
|
16
|
+
const handleSelectChange = (e: React.ChangeEvent<HTMLSelectElement>) => {
|
|
17
|
+
rowData[field] = e.target.value;
|
|
18
|
+
config.onDataChange?.(rowData.id, field, e.target.value);
|
|
19
|
+
};
|
|
20
|
+
|
|
21
|
+
switch (type) {
|
|
22
|
+
case "input":
|
|
23
|
+
return (
|
|
24
|
+
<input
|
|
25
|
+
key={`${field}-${rowData.id}`}
|
|
26
|
+
type={config.type || "text"}
|
|
27
|
+
className={
|
|
28
|
+
config.className ||
|
|
29
|
+
"p-1 text-xs outline-none w-full rounded focus:border-b-2 border-black dark:border-white dark:bg-zinc-900"
|
|
30
|
+
}
|
|
31
|
+
placeholder={config.placeholder || `Enter ${field}`}
|
|
32
|
+
defaultValue={rowData[field]}
|
|
33
|
+
onChange={handleInputChange}
|
|
34
|
+
onBlur={handleInputChange}
|
|
35
|
+
/>
|
|
36
|
+
);
|
|
37
|
+
|
|
38
|
+
case "select":
|
|
39
|
+
return (
|
|
40
|
+
<select
|
|
41
|
+
key={`${field}-${rowData.id}`}
|
|
42
|
+
className={
|
|
43
|
+
config.className ||
|
|
44
|
+
"p-1 w-full text-xs rounded outline-none focus:border-b-2 border-black dark:border-white dark:bg-zinc-900"
|
|
45
|
+
}
|
|
46
|
+
defaultValue={rowData[field]}
|
|
47
|
+
onChange={handleSelectChange}
|
|
48
|
+
>
|
|
49
|
+
{config.options?.map((option: any, i: number) => (
|
|
50
|
+
<option key={i} value={option.value || option}>
|
|
51
|
+
{option.label || option}
|
|
52
|
+
</option>
|
|
53
|
+
))}
|
|
54
|
+
</select>
|
|
55
|
+
);
|
|
56
|
+
|
|
57
|
+
case "button":
|
|
58
|
+
return (
|
|
59
|
+
<button
|
|
60
|
+
key={`${field}-${rowData.id}`}
|
|
61
|
+
className={config.className || "border rounded-2xl p-1"}
|
|
62
|
+
onClick={() => config.onClick?.(rowData)}
|
|
63
|
+
>
|
|
64
|
+
{config.text || "Action"}
|
|
65
|
+
</button>
|
|
66
|
+
);
|
|
67
|
+
|
|
68
|
+
case "custom":
|
|
69
|
+
return (
|
|
70
|
+
<CustomTemplate
|
|
71
|
+
rowData={rowData}
|
|
72
|
+
field={field}
|
|
73
|
+
config={config}
|
|
74
|
+
{...config}
|
|
75
|
+
/>
|
|
76
|
+
);
|
|
77
|
+
|
|
78
|
+
default:
|
|
79
|
+
return <span>{rowData[field]}</span>;
|
|
80
|
+
}
|
|
81
|
+
};
|
|
82
|
+
};
|
|
@@ -0,0 +1,6 @@
|
|
|
1
|
+
export { useDataSource } from "./useDataSource";
|
|
2
|
+
export { useColumns } from "./useColumns";
|
|
3
|
+
export { usePagination } from "./usePagination";
|
|
4
|
+
export { useSearch } from "./useSearch";
|
|
5
|
+
export { useFiltering } from "./useFiltering";
|
|
6
|
+
export { useRowSelection } from "./useRowSelection";
|
|
@@ -0,0 +1,33 @@
|
|
|
1
|
+
import { useState, useEffect } from "react";
|
|
2
|
+
|
|
3
|
+
export const useColumns = (columns: any[], workingDataSource: any[]) => {
|
|
4
|
+
const [workingColumns, setWorkingColumns] = useState<any>([]);
|
|
5
|
+
|
|
6
|
+
useEffect(() => {
|
|
7
|
+
if (columns && columns.length > 0) {
|
|
8
|
+
const filteredColumns = columns.map((column) => ({
|
|
9
|
+
...column,
|
|
10
|
+
showFilterPopup: false,
|
|
11
|
+
isFilterActive: false,
|
|
12
|
+
}));
|
|
13
|
+
setWorkingColumns(filteredColumns);
|
|
14
|
+
} else if (
|
|
15
|
+
workingDataSource.length > 0 &&
|
|
16
|
+
Object.keys(workingDataSource[0]).length > 0
|
|
17
|
+
) {
|
|
18
|
+
const inferredColumns = Object.keys(workingDataSource[0]).map((key) => ({
|
|
19
|
+
field: key,
|
|
20
|
+
headerText: key.charAt(0).toUpperCase() + key.slice(1),
|
|
21
|
+
width: 150,
|
|
22
|
+
}));
|
|
23
|
+
setWorkingColumns((prevColumns: any) => {
|
|
24
|
+
if (JSON.stringify(prevColumns) !== JSON.stringify(inferredColumns)) {
|
|
25
|
+
return inferredColumns;
|
|
26
|
+
}
|
|
27
|
+
return prevColumns;
|
|
28
|
+
});
|
|
29
|
+
}
|
|
30
|
+
}, [columns]); // Remove workingDataSource from dependencies to prevent reset on data fetch
|
|
31
|
+
|
|
32
|
+
return { workingColumns, setWorkingColumns };
|
|
33
|
+
};
|
|
@@ -0,0 +1,54 @@
|
|
|
1
|
+
import { useState, useCallback, useEffect } from "react";
|
|
2
|
+
import { getSourceData } from "../../utils";
|
|
3
|
+
|
|
4
|
+
export const useDataSource = (
|
|
5
|
+
dataSource: any,
|
|
6
|
+
pageSettings: any,
|
|
7
|
+
lazy: boolean
|
|
8
|
+
) => {
|
|
9
|
+
const [workingDataSource, setWorkingDataSource] = useState<any>([]);
|
|
10
|
+
const [fallbackSourceData, setFallbackSourceData] = useState([]);
|
|
11
|
+
const [totalPages, setTotalPages] = useState(0);
|
|
12
|
+
|
|
13
|
+
const getGridData = useCallback(async () => {
|
|
14
|
+
try {
|
|
15
|
+
const sourceData = await getSourceData(dataSource);
|
|
16
|
+
const gridData = sourceData.sourcedata;
|
|
17
|
+
setFallbackSourceData(gridData);
|
|
18
|
+
setWorkingDataSource(gridData);
|
|
19
|
+
const totalPages = Math.ceil(gridData.length / pageSettings.pageNumber);
|
|
20
|
+
setTotalPages(totalPages);
|
|
21
|
+
return totalPages;
|
|
22
|
+
} catch (error) {
|
|
23
|
+
console.error("Error fetching grid source data:", error);
|
|
24
|
+
return 0;
|
|
25
|
+
}
|
|
26
|
+
}, [dataSource, pageSettings.pageNumber]);
|
|
27
|
+
|
|
28
|
+
useEffect(() => {
|
|
29
|
+
const handleDataSource = async () => {
|
|
30
|
+
if (Array.isArray(dataSource)) {
|
|
31
|
+
setWorkingDataSource(dataSource);
|
|
32
|
+
|
|
33
|
+
const totalPages =
|
|
34
|
+
lazy && pageSettings.totalCount
|
|
35
|
+
? Math.ceil(pageSettings.totalCount / pageSettings.pageNumber)
|
|
36
|
+
: Math.ceil(dataSource.length / pageSettings.pageNumber);
|
|
37
|
+
|
|
38
|
+
setTotalPages(totalPages);
|
|
39
|
+
} else if (typeof dataSource === "string") {
|
|
40
|
+
await getGridData();
|
|
41
|
+
}
|
|
42
|
+
};
|
|
43
|
+
|
|
44
|
+
handleDataSource();
|
|
45
|
+
}, [dataSource, pageSettings, lazy, getGridData]);
|
|
46
|
+
|
|
47
|
+
return {
|
|
48
|
+
workingDataSource,
|
|
49
|
+
setWorkingDataSource,
|
|
50
|
+
fallbackSourceData,
|
|
51
|
+
totalPages,
|
|
52
|
+
setTotalPages,
|
|
53
|
+
};
|
|
54
|
+
};
|
|
@@ -0,0 +1,169 @@
|
|
|
1
|
+
import { useState, useCallback } from "react";
|
|
2
|
+
import {
|
|
3
|
+
clearFilterHelper,
|
|
4
|
+
handleApplyFilterHelper,
|
|
5
|
+
} from "@grampro/headless-helpers";
|
|
6
|
+
import type { ActiveFilterArrayValue } from "../type";
|
|
7
|
+
|
|
8
|
+
interface UseFilteringProps {
|
|
9
|
+
columns: any[];
|
|
10
|
+
workingColumns: any[];
|
|
11
|
+
setWorkingColumns: (columns: any[]) => void;
|
|
12
|
+
workingDataSource: any[];
|
|
13
|
+
setWorkingDataSource: (data: any[]) => void;
|
|
14
|
+
dataSource: any;
|
|
15
|
+
fallbackSourceData: any[];
|
|
16
|
+
resetPage: (data: any[], settings: any) => number;
|
|
17
|
+
setTotalPages: (pages: number) => void;
|
|
18
|
+
pageSettings: any;
|
|
19
|
+
activeFilterArrayValue?: (filters: ActiveFilterArrayValue[]) => void;
|
|
20
|
+
lazy: boolean;
|
|
21
|
+
initialFilters?: any[];
|
|
22
|
+
}
|
|
23
|
+
|
|
24
|
+
export const useFiltering = ({
|
|
25
|
+
columns,
|
|
26
|
+
workingColumns,
|
|
27
|
+
setWorkingColumns,
|
|
28
|
+
workingDataSource,
|
|
29
|
+
setWorkingDataSource,
|
|
30
|
+
dataSource,
|
|
31
|
+
fallbackSourceData,
|
|
32
|
+
resetPage,
|
|
33
|
+
setTotalPages,
|
|
34
|
+
pageSettings,
|
|
35
|
+
activeFilterArrayValue,
|
|
36
|
+
lazy,
|
|
37
|
+
initialFilters = [],
|
|
38
|
+
}: UseFilteringProps) => {
|
|
39
|
+
const [activeFilterArray, setActiveFilterArray] = useState<any>(initialFilters);
|
|
40
|
+
|
|
41
|
+
const toggleFilterPopup = useCallback(
|
|
42
|
+
(index: number) => {
|
|
43
|
+
setWorkingColumns(
|
|
44
|
+
workingColumns.map((column: any, i: any) =>
|
|
45
|
+
i === index
|
|
46
|
+
? { ...column, showFilterPopup: !column.showFilterPopup }
|
|
47
|
+
: column
|
|
48
|
+
)
|
|
49
|
+
);
|
|
50
|
+
},
|
|
51
|
+
[workingColumns, setWorkingColumns]
|
|
52
|
+
);
|
|
53
|
+
|
|
54
|
+
const handleApplyFilter = useCallback(
|
|
55
|
+
(event: any) => {
|
|
56
|
+
const {
|
|
57
|
+
columns: updatedColumns,
|
|
58
|
+
workingDataSource: updatedFullDataSource,
|
|
59
|
+
activeFilterArray: updatedActiveFilterArray,
|
|
60
|
+
} = handleApplyFilterHelper(event, columns, workingDataSource);
|
|
61
|
+
|
|
62
|
+
setWorkingColumns(updatedColumns);
|
|
63
|
+
|
|
64
|
+
const newActiveFilters = updatedActiveFilterArray;
|
|
65
|
+
setActiveFilterArray(newActiveFilters);
|
|
66
|
+
|
|
67
|
+
if (!lazy) {
|
|
68
|
+
setWorkingDataSource(updatedFullDataSource);
|
|
69
|
+
const totalPages = resetPage(updatedFullDataSource, pageSettings);
|
|
70
|
+
setTotalPages(totalPages);
|
|
71
|
+
} else {
|
|
72
|
+
// In lazy mode, we reset page to 0 but keep totalPages from pageSettings
|
|
73
|
+
resetPage(workingDataSource, pageSettings);
|
|
74
|
+
}
|
|
75
|
+
|
|
76
|
+
if (activeFilterArrayValue)
|
|
77
|
+
activeFilterArrayValue?.(newActiveFilters);
|
|
78
|
+
},
|
|
79
|
+
[
|
|
80
|
+
columns,
|
|
81
|
+
workingDataSource,
|
|
82
|
+
setWorkingColumns,
|
|
83
|
+
setWorkingDataSource,
|
|
84
|
+
activeFilterArrayValue,
|
|
85
|
+
resetPage,
|
|
86
|
+
pageSettings,
|
|
87
|
+
setTotalPages,
|
|
88
|
+
lazy,
|
|
89
|
+
activeFilterArray,
|
|
90
|
+
]
|
|
91
|
+
);
|
|
92
|
+
|
|
93
|
+
const clearFilter = useCallback(
|
|
94
|
+
(event: any) => {
|
|
95
|
+
const clearDataSource = Array.isArray(dataSource)
|
|
96
|
+
? dataSource
|
|
97
|
+
: fallbackSourceData;
|
|
98
|
+
const {
|
|
99
|
+
columns: updatedColumns,
|
|
100
|
+
workingDataSource: updatedDataSource,
|
|
101
|
+
activeFilterArray: updatedActiveFilterArray,
|
|
102
|
+
} = clearFilterHelper(event, workingColumns, clearDataSource);
|
|
103
|
+
|
|
104
|
+
setWorkingColumns(updatedColumns);
|
|
105
|
+
|
|
106
|
+
// Manual fallback: ensure the filter is removed from the active array
|
|
107
|
+
let newActiveFilters = updatedActiveFilterArray;
|
|
108
|
+
if (event.type === "clearFilter" && event.columnHeader) {
|
|
109
|
+
newActiveFilters = activeFilterArray.filter(
|
|
110
|
+
(f: any) => f.filterColumn !== event.columnHeader
|
|
111
|
+
);
|
|
112
|
+
}
|
|
113
|
+
|
|
114
|
+
setActiveFilterArray(newActiveFilters);
|
|
115
|
+
|
|
116
|
+
if (!lazy) {
|
|
117
|
+
setWorkingDataSource(updatedDataSource);
|
|
118
|
+
const totalPages = resetPage(updatedDataSource, pageSettings);
|
|
119
|
+
setTotalPages(totalPages);
|
|
120
|
+
} else {
|
|
121
|
+
// In lazy mode, we reset page to 0 but keep totalPages from pageSettings
|
|
122
|
+
resetPage(workingDataSource, pageSettings);
|
|
123
|
+
}
|
|
124
|
+
|
|
125
|
+
if (activeFilterArrayValue)
|
|
126
|
+
activeFilterArrayValue?.(newActiveFilters);
|
|
127
|
+
},
|
|
128
|
+
[
|
|
129
|
+
dataSource,
|
|
130
|
+
fallbackSourceData,
|
|
131
|
+
workingColumns,
|
|
132
|
+
setWorkingColumns,
|
|
133
|
+
setWorkingDataSource,
|
|
134
|
+
activeFilterArrayValue,
|
|
135
|
+
resetPage,
|
|
136
|
+
pageSettings,
|
|
137
|
+
setTotalPages,
|
|
138
|
+
lazy,
|
|
139
|
+
activeFilterArray,
|
|
140
|
+
]
|
|
141
|
+
);
|
|
142
|
+
|
|
143
|
+
const handleFilterAction = useCallback(
|
|
144
|
+
(action: any, colIndex: number) => {
|
|
145
|
+
switch (action.type) {
|
|
146
|
+
case "cancel":
|
|
147
|
+
toggleFilterPopup(colIndex);
|
|
148
|
+
break;
|
|
149
|
+
case "applyFilter":
|
|
150
|
+
handleApplyFilter(action);
|
|
151
|
+
break;
|
|
152
|
+
case "clearFilter":
|
|
153
|
+
clearFilter(action);
|
|
154
|
+
break;
|
|
155
|
+
default:
|
|
156
|
+
break;
|
|
157
|
+
}
|
|
158
|
+
},
|
|
159
|
+
[toggleFilterPopup, handleApplyFilter, clearFilter]
|
|
160
|
+
);
|
|
161
|
+
|
|
162
|
+
return {
|
|
163
|
+
activeFilterArray,
|
|
164
|
+
toggleFilterPopup,
|
|
165
|
+
handleApplyFilter,
|
|
166
|
+
clearFilter,
|
|
167
|
+
handleFilterAction,
|
|
168
|
+
};
|
|
169
|
+
};
|
|
@@ -0,0 +1,112 @@
|
|
|
1
|
+
import { useState, useCallback, useEffect } from "react";
|
|
2
|
+
|
|
3
|
+
export const usePagination = (
|
|
4
|
+
totalPages: number,
|
|
5
|
+
lazy: boolean,
|
|
6
|
+
dataSource?: any[],
|
|
7
|
+
pageStatus?: ({ currentPage }: { currentPage: number }) => void
|
|
8
|
+
) => {
|
|
9
|
+
const [currentPage, setCurrentPage] = useState(0);
|
|
10
|
+
const [pageStart, setPageStart] = useState(0);
|
|
11
|
+
const [pageEnd, setPageEnd] = useState(10);
|
|
12
|
+
|
|
13
|
+
// Update page range based on current page
|
|
14
|
+
const updatePageRange = useCallback(
|
|
15
|
+
(page: number) => {
|
|
16
|
+
const start = Math.floor(page / 10) * 10;
|
|
17
|
+
setPageStart(start);
|
|
18
|
+
setPageEnd(Math.min(start + 10, totalPages));
|
|
19
|
+
},
|
|
20
|
+
[totalPages]
|
|
21
|
+
);
|
|
22
|
+
|
|
23
|
+
// Initialize page range based on total pages
|
|
24
|
+
useEffect(() => {
|
|
25
|
+
if (!lazy) {
|
|
26
|
+
setPageEnd(Math.min(10, totalPages));
|
|
27
|
+
} else {
|
|
28
|
+
setPageEnd(Math.min(pageStart + 10, totalPages));
|
|
29
|
+
}
|
|
30
|
+
}, [totalPages, lazy, pageStart]);
|
|
31
|
+
|
|
32
|
+
// Update page status if provided
|
|
33
|
+
useEffect(() => {
|
|
34
|
+
if (pageStatus) {
|
|
35
|
+
pageStatus({ currentPage });
|
|
36
|
+
}
|
|
37
|
+
}, [currentPage, pageStatus]);
|
|
38
|
+
|
|
39
|
+
// Defensive check: if current page is out of bounds due to totalPages shrinking, reset to 0
|
|
40
|
+
useEffect(() => {
|
|
41
|
+
if (totalPages > 0 && currentPage >= totalPages) {
|
|
42
|
+
setCurrentPage(0);
|
|
43
|
+
updatePageRange(0);
|
|
44
|
+
}
|
|
45
|
+
}, [totalPages, currentPage, updatePageRange]);
|
|
46
|
+
|
|
47
|
+
const nextPage = useCallback(() => {
|
|
48
|
+
setCurrentPage((prevPage) => {
|
|
49
|
+
if (prevPage < totalPages - 1) {
|
|
50
|
+
const newPage = prevPage + 1;
|
|
51
|
+
updatePageRange(newPage);
|
|
52
|
+
return newPage;
|
|
53
|
+
}
|
|
54
|
+
return prevPage;
|
|
55
|
+
});
|
|
56
|
+
}, [totalPages, updatePageRange]);
|
|
57
|
+
|
|
58
|
+
const prevPage = useCallback(() => {
|
|
59
|
+
setCurrentPage((prevPage) => {
|
|
60
|
+
if (prevPage > 0) {
|
|
61
|
+
const newPage = prevPage - 1;
|
|
62
|
+
updatePageRange(newPage);
|
|
63
|
+
return newPage;
|
|
64
|
+
}
|
|
65
|
+
return prevPage;
|
|
66
|
+
});
|
|
67
|
+
}, [updatePageRange]);
|
|
68
|
+
|
|
69
|
+
const goToEndPage = useCallback(() => {
|
|
70
|
+
const lastPage = totalPages - 1;
|
|
71
|
+
setCurrentPage(lastPage);
|
|
72
|
+
updatePageRange(lastPage);
|
|
73
|
+
}, [totalPages, updatePageRange]);
|
|
74
|
+
|
|
75
|
+
const goToFirstPage = useCallback(() => {
|
|
76
|
+
setCurrentPage(0);
|
|
77
|
+
updatePageRange(0);
|
|
78
|
+
}, [updatePageRange]);
|
|
79
|
+
|
|
80
|
+
const goToPage = useCallback(
|
|
81
|
+
(page: number) => {
|
|
82
|
+
setCurrentPage(page);
|
|
83
|
+
updatePageRange(page);
|
|
84
|
+
},
|
|
85
|
+
[updatePageRange]
|
|
86
|
+
);
|
|
87
|
+
|
|
88
|
+
const resetPage = useCallback((dataSource: any, pageSettings: any) => {
|
|
89
|
+
const newTotalPages =
|
|
90
|
+
lazy && pageSettings?.totalCount
|
|
91
|
+
? Math.ceil(pageSettings.totalCount / pageSettings.pageNumber)
|
|
92
|
+
: Math.ceil((dataSource?.length || 0) / (pageSettings?.pageNumber || 10));
|
|
93
|
+
|
|
94
|
+
setCurrentPage(0);
|
|
95
|
+
setPageStart(0);
|
|
96
|
+
setPageEnd(Math.min(10, newTotalPages));
|
|
97
|
+
return newTotalPages;
|
|
98
|
+
}, [lazy]);
|
|
99
|
+
|
|
100
|
+
return {
|
|
101
|
+
currentPage,
|
|
102
|
+
pageStart,
|
|
103
|
+
pageEnd,
|
|
104
|
+
nextPage,
|
|
105
|
+
prevPage,
|
|
106
|
+
goToEndPage,
|
|
107
|
+
goToFirstPage,
|
|
108
|
+
goToPage,
|
|
109
|
+
resetPage,
|
|
110
|
+
updatePageRange,
|
|
111
|
+
};
|
|
112
|
+
};
|