flexi-datagrid 1.1.0 → 1.2.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/README.md +151 -0
- package/dist/flexi-datagrid.css +1 -1
- package/dist/index.es.js +247 -217
- package/dist/index.umd.js +1 -1
- package/package.json +1 -2
package/README.md
ADDED
|
@@ -0,0 +1,151 @@
|
|
|
1
|
+
# Flexi-Datagrid
|
|
2
|
+
|
|
3
|
+
A modern, highly customizable, and feature-rich React data grid component designed for speed and flexibility.
|
|
4
|
+
|
|
5
|
+
## ✨ Features
|
|
6
|
+
|
|
7
|
+
- **Column Pinning:** Easily pin important columns to the left side of the grid.
|
|
8
|
+
- **Multi-State Sorting:** Clickable column headers that support Ascending (asc), Descending (desc), and Unsorted states.
|
|
9
|
+
- **Built-in Filtering:** Filter rows instantly with a clean popup search and multi-select dropdown for unique column values. The popup renders through a portal so it always floats above your grid content instead of being clipped by the table's scroll container.
|
|
10
|
+
- **Row Grouping (Drag-and-Drop):** Drag column headers into the grouping zone to group your dataset hierarchically with expand/collapse support.
|
|
11
|
+
- **Nested/Grouped Headers:** Columns can be nested via `children` to render multi-level header rows.
|
|
12
|
+
- **Sticky Actions:** Optional custom row actions column locked to the right side.
|
|
13
|
+
- **Custom Cell Rendering:** Full control over how each cell is rendered via a `render` function.
|
|
14
|
+
- **Full TypeScript Support:** Strongly typed configurations for robust developer experience.
|
|
15
|
+
|
|
16
|
+
---
|
|
17
|
+
|
|
18
|
+
## 📦 Installation
|
|
19
|
+
|
|
20
|
+
Install the package via npm:
|
|
21
|
+
|
|
22
|
+
```bash
|
|
23
|
+
npm install flexi-datagrid
|
|
24
|
+
```
|
|
25
|
+
|
|
26
|
+
`react`, `react-dom`, and `lucide-react` are peer dependencies — make sure they're installed in your project.
|
|
27
|
+
|
|
28
|
+
Don't forget to import the required CSS file in your main entry file (e.g. `main.tsx` or `App.tsx`):
|
|
29
|
+
|
|
30
|
+
```tsx
|
|
31
|
+
import 'flexi-datagrid/dist/flexi-datagrid.css';
|
|
32
|
+
```
|
|
33
|
+
|
|
34
|
+
---
|
|
35
|
+
|
|
36
|
+
## 🚀 Quick Start
|
|
37
|
+
|
|
38
|
+
```tsx
|
|
39
|
+
import { DataTable, type ColumnConfig } from 'flexi-datagrid';
|
|
40
|
+
import 'flexi-datagrid/dist/flexi-datagrid.css';
|
|
41
|
+
|
|
42
|
+
interface Employee {
|
|
43
|
+
id: number;
|
|
44
|
+
name: string;
|
|
45
|
+
department: string;
|
|
46
|
+
role: string;
|
|
47
|
+
salary: number;
|
|
48
|
+
}
|
|
49
|
+
|
|
50
|
+
const data: Employee[] = [
|
|
51
|
+
{ id: 1, name: 'Ava Thompson', department: 'Engineering', role: 'Frontend Developer', salary: 95000 },
|
|
52
|
+
{ id: 2, name: 'Liam Carter', department: 'Engineering', role: 'Backend Developer', salary: 102000 },
|
|
53
|
+
{ id: 3, name: 'Sofia Ramirez', department: 'Design', role: 'Product Designer', salary: 88000 },
|
|
54
|
+
{ id: 4, name: 'Noah Patel', department: 'Sales', role: 'Account Executive', salary: 76000 },
|
|
55
|
+
];
|
|
56
|
+
|
|
57
|
+
const columns: ColumnConfig<Employee>[] = [
|
|
58
|
+
{ key: 'name', header: 'Name', sortable: true, filterable: true, pinned: true },
|
|
59
|
+
{ key: 'department', header: 'Department', sortable: true, filterable: true },
|
|
60
|
+
{ key: 'role', header: 'Role', sortable: true, filterable: true },
|
|
61
|
+
{
|
|
62
|
+
key: 'salary',
|
|
63
|
+
header: 'Salary',
|
|
64
|
+
sortable: true,
|
|
65
|
+
render: (value) => `$${value.toLocaleString()}`,
|
|
66
|
+
},
|
|
67
|
+
];
|
|
68
|
+
|
|
69
|
+
export default function EmployeeTable() {
|
|
70
|
+
return (
|
|
71
|
+
<DataTable<Employee>
|
|
72
|
+
columns={columns}
|
|
73
|
+
data={data}
|
|
74
|
+
rowKey="id"
|
|
75
|
+
groupBy
|
|
76
|
+
defaultGroupBy={['department']}
|
|
77
|
+
actions={(record) => (
|
|
78
|
+
<button onClick={() => console.log('Edit', record.id)}>Edit</button>
|
|
79
|
+
)}
|
|
80
|
+
/>
|
|
81
|
+
);
|
|
82
|
+
}
|
|
83
|
+
```
|
|
84
|
+
|
|
85
|
+
---
|
|
86
|
+
|
|
87
|
+
## ⚙️ How It Works
|
|
88
|
+
|
|
89
|
+
`DataTable` is a single, self-contained component: pass it `columns` and `data`, and it manages sorting, filtering, pinning, and grouping state internally.
|
|
90
|
+
|
|
91
|
+
### Columns (`ColumnConfig<T>`)
|
|
92
|
+
|
|
93
|
+
Each entry in `columns` describes one column (or a group of columns, via `children`):
|
|
94
|
+
|
|
95
|
+
| Prop | Type | Description |
|
|
96
|
+
| --- | --- | --- |
|
|
97
|
+
| `key` | `string` | Unique identifier for the column. Used to read values off each row (`record[key]`) unless `getValue` is provided. |
|
|
98
|
+
| `header` | `string` | Text shown in the column header. |
|
|
99
|
+
| `className` / `headerClassName` | `string` | Extra classes applied to body cells / the header cell. |
|
|
100
|
+
| `style` / `headerStyle` | `CSSProperties` | Inline styles for body cells / the header cell (e.g. fixed `width`). |
|
|
101
|
+
| `render` | `(value, record) => ReactNode` | Custom cell renderer. Falls back to the raw value if omitted. |
|
|
102
|
+
| `getValue` | `(record) => any` | Custom accessor used for sorting, filtering, and grouping when the value isn't a simple `record[key]` lookup. |
|
|
103
|
+
| `filterable` | `boolean` | Shows a filter icon in the header that opens a multi-select popup of unique column values. |
|
|
104
|
+
| `sortable` | `boolean` | Makes the header clickable, cycling through ascending → descending → unsorted. |
|
|
105
|
+
| `pinned` | `boolean` | Pins the column to the left edge by default (still toggleable per-column from the UI). |
|
|
106
|
+
| `children` | `ColumnConfig<T>[]` | Nest columns to render a grouped, multi-row header. Only leaf columns are sortable/filterable/pinnable. |
|
|
107
|
+
|
|
108
|
+
### Grid props (`DataTableProps<T>`)
|
|
109
|
+
|
|
110
|
+
| Prop | Type | Description |
|
|
111
|
+
| --- | --- | --- |
|
|
112
|
+
| `columns` | `ColumnConfig<T>[]` | Column definitions (see above). |
|
|
113
|
+
| `data` | `T[]` | Row data to render. |
|
|
114
|
+
| `rowKey` | `keyof T \| (record: T) => string` | Field name or function used to derive a unique React key per row. |
|
|
115
|
+
| `actions` | `(record: T) => ReactNode` | Renders a sticky, right-aligned actions cell per row (e.g. edit/delete buttons). |
|
|
116
|
+
| `isLoading` | `boolean` | Shows a loading state in place of rows. |
|
|
117
|
+
| `groupBy` | `boolean` | Enables drag-and-drop row grouping — drag a column header into the grouping zone above the grid. |
|
|
118
|
+
| `defaultGroupBy` | `string[]` | Column keys the grid is grouped by on initial render (requires `groupBy`). |
|
|
119
|
+
| `onPinChange` | `(columnKey, isPinned) => void` | Called whenever a column is pinned/unpinned. |
|
|
120
|
+
| `onGroupChange` | `(groupedKeys: string[]) => void` | Called whenever the set of grouped columns changes. |
|
|
121
|
+
| `containerStyle` | `CSSProperties` | Inline styles for the scrollable table container. |
|
|
122
|
+
| `tableStyle` | `CSSProperties` | Inline styles for the `<table>` element itself. |
|
|
123
|
+
|
|
124
|
+
### Filtering
|
|
125
|
+
|
|
126
|
+
Any column with `filterable: true` gets a filter icon in its header. Clicking it opens a searchable, multi-select popup listing the column's unique values (derived from `data`, via `getValue` if provided). Selected values are combined with AND across columns and OR within a column's own selected values. The popup is rendered through a portal anchored to the grid's own root element, so it overlays the grid instead of being clipped by the table's horizontal scroll container — similar to an Excel-style filter panel.
|
|
127
|
+
|
|
128
|
+
### Sorting
|
|
129
|
+
|
|
130
|
+
Clicking a `sortable` column header cycles through ascending → descending → unsorted. Only one column can be actively sorted at a time.
|
|
131
|
+
|
|
132
|
+
### Row Grouping
|
|
133
|
+
|
|
134
|
+
Set `groupBy` to enable a drop zone above the table. Dragging a sortable/leaf column header into it groups rows by that column's value, with collapsible group rows and per-group row counts. Multiple columns can be stacked to create nested groups; use `defaultGroupBy` to pre-group on mount.
|
|
135
|
+
|
|
136
|
+
### Column Pinning
|
|
137
|
+
|
|
138
|
+
Hovering a header reveals a pin icon; pinning locks that column to the left with a sticky position and shadow so it stays visible while scrolling horizontally. Columns marked `pinned: true` start pinned.
|
|
139
|
+
|
|
140
|
+
---
|
|
141
|
+
|
|
142
|
+
## 🛠 Local Development
|
|
143
|
+
|
|
144
|
+
```bash
|
|
145
|
+
npm install
|
|
146
|
+
npm run build # bundles the library to dist/ and emits type declarations
|
|
147
|
+
```
|
|
148
|
+
|
|
149
|
+
## 📄 License
|
|
150
|
+
|
|
151
|
+
ISC
|
package/dist/flexi-datagrid.css
CHANGED
|
@@ -1,2 +1,2 @@
|
|
|
1
|
-
*,:before,:after,::backdrop{--tw-border-spacing-x:0;--tw-border-spacing-y:0;--tw-translate-x:0;--tw-translate-y:0;--tw-rotate:0;--tw-skew-x:0;--tw-skew-y:0;--tw-scale-x:1;--tw-scale-y:1;--tw-pan-x: ;--tw-pan-y: ;--tw-pinch-zoom: ;--tw-scroll-snap-strictness:proximity;--tw-gradient-from-position: ;--tw-gradient-via-position: ;--tw-gradient-to-position: ;--tw-ordinal: ;--tw-slashed-zero: ;--tw-numeric-figure: ;--tw-numeric-spacing: ;--tw-numeric-fraction: ;--tw-ring-inset: ;--tw-ring-offset-width:0px;--tw-ring-offset-color:#fff;--tw-ring-color:#3b82f680;--tw-ring-offset-shadow:0 0 #0000;--tw-ring-shadow:0 0 #0000;--tw-shadow:0 0 #0000;--tw-shadow-colored:0 0 #0000;--tw-blur: ;--tw-brightness: ;--tw-contrast: ;--tw-grayscale: ;--tw-hue-rotate: ;--tw-invert: ;--tw-saturate: ;--tw-sepia: ;--tw-drop-shadow: ;--tw-backdrop-blur: ;--tw-backdrop-brightness: ;--tw-backdrop-contrast: ;--tw-backdrop-grayscale: ;--tw-backdrop-hue-rotate: ;--tw-backdrop-invert: ;--tw-backdrop-opacity: ;--tw-backdrop-saturate: ;--tw-backdrop-sepia: ;--tw-contain-size: ;--tw-contain-layout: ;--tw-contain-paint: ;--tw-contain-style: }*,:before,:after{box-sizing:border-box;border:0 solid #e5e7eb}:before,:after{--tw-content:""}html,:host{-webkit-text-size-adjust:100%;tab-size:4;font-feature-settings:normal;font-variation-settings:normal;-webkit-tap-highlight-color:transparent;font-family:ui-sans-serif,system-ui,sans-serif,Apple Color Emoji,Segoe UI Emoji,Segoe UI Symbol,Noto Color Emoji;line-height:1.5}body{line-height:inherit;margin:0}hr{height:0;color:inherit;border-top-width:1px}abbr:where([title]){-webkit-text-decoration:underline dotted;text-decoration:underline dotted}h1,h2,h3,h4,h5,h6{font-size:inherit;font-weight:inherit}a{color:inherit;-webkit-text-decoration:inherit;text-decoration:inherit}b,strong{font-weight:bolder}code,kbd,samp,pre{font-feature-settings:normal;font-variation-settings:normal;font-family:ui-monospace,SFMono-Regular,Menlo,Monaco,Consolas,Liberation Mono,Courier New,monospace;font-size:1em}small{font-size:80%}sub,sup{vertical-align:baseline;font-size:75%;line-height:0;position:relative}sub{bottom:-.25em}sup{top:-.5em}table{text-indent:0;border-color:inherit;border-collapse:collapse}button,input,optgroup,select,textarea{font-feature-settings:inherit;font-variation-settings:inherit;font-family:inherit;font-size:100%;font-weight:inherit;line-height:inherit;letter-spacing:inherit;color:inherit;margin:0;padding:0}button,select{text-transform:none}button,input:where([type=button]),input:where([type=reset]),input:where([type=submit]){-webkit-appearance:button;background-color:#0000;background-image:none}:-moz-focusring{outline:auto}:-moz-ui-invalid{box-shadow:none}progress{vertical-align:baseline}::-webkit-inner-spin-button{height:auto}::-webkit-outer-spin-button{height:auto}[type=search]{-webkit-appearance:textfield;outline-offset:-2px}::-webkit-search-decoration{-webkit-appearance:none}::-webkit-file-upload-button{-webkit-appearance:button;font:inherit}summary{display:list-item}blockquote,dl,dd,h1,h2,h3,h4,h5,h6,hr,figure,p,pre{margin:0}fieldset{margin:0;padding:0}legend{padding:0}ol,ul,menu{margin:0;padding:0;list-style:none}dialog{padding:0}textarea{resize:vertical}input::-moz-placeholder{opacity:1;color:#9ca3af}textarea::-moz-placeholder{opacity:1;color:#9ca3af}input::placeholder,textarea::placeholder{opacity:1;color:#9ca3af}button,[role=button]{cursor:pointer}:disabled{cursor:default}img,svg,video,canvas,audio,iframe,embed,object{vertical-align:middle;display:block}img,video{max-width:100%;height:auto}[hidden]:where(:not([hidden=until-found])){display:none}.absolute{position:absolute}.relative{position:relative}.sticky{position:sticky}.left-4{left:1rem}.top-10{top:2.5rem}.z-50{z-index:50}.mb-1{margin-bottom:.25rem}.ml-1{margin-left:.25rem}.mr-1{margin-right:.25rem}.mt-2{margin-top:.5rem}.block{display:block}.flex{display:flex}.table{display:table}.h-12{height:3rem}.h-3{height:.75rem}.h-3\.5{height:.875rem}.h-4{height:1rem}.max-h-40{max-height:10rem}.min-h-\[52px\]{min-height:52px}.w-12{width:3rem}.w-3{width:.75rem}.w-3\.5{width:.875rem}.w-4{width:1rem}.w-40{width:10rem}.w-52{width:13rem}.w-full{width:100%}.table-fixed{table-layout:fixed}.caption-bottom{caption-side:bottom}.border-collapse{border-collapse:collapse}.scale-\[0\.99\]{--tw-scale-x:.99;--tw-scale-y:.99;transform:translate(var(--tw-translate-x), var(--tw-translate-y)) rotate(var(--tw-rotate)) skewX(var(--tw-skew-x)) skewY(var(--tw-skew-y)) scaleX(var(--tw-scale-x)) scaleY(var(--tw-scale-y))}.cursor-grab{cursor:grab}.cursor-pointer{cursor:pointer}.select-none{-webkit-user-select:none;user-select:none}.flex-col{flex-direction:column}.flex-wrap{flex-wrap:wrap}.items-center{align-items:center}.justify-end{justify-content:flex-end}.justify-between{justify-content:space-between}.gap-1{gap:.25rem}.gap-1\.5{gap:.375rem}.gap-2{gap:.5rem}.space-y-1>:not([hidden])~:not([hidden]){--tw-space-y-reverse:0;margin-top:calc(.25rem * calc(1 - var(--tw-space-y-reverse)));margin-bottom:calc(.25rem * var(--tw-space-y-reverse))}.space-y-3>:not([hidden])~:not([hidden]){--tw-space-y-reverse:0;margin-top:calc(.75rem * calc(1 - var(--tw-space-y-reverse)));margin-bottom:calc(.75rem * var(--tw-space-y-reverse))}.divide-y>:not([hidden])~:not([hidden]){--tw-divide-y-reverse:0;border-top-width:calc(1px * calc(1 - var(--tw-divide-y-reverse)));border-bottom-width:calc(1px * var(--tw-divide-y-reverse))}.divide-slate-100>:not([hidden])~:not([hidden]){--tw-divide-opacity:1;border-color:rgb(241 245 249/var(--tw-divide-opacity,1))}.overflow-x-auto{overflow-x:auto}.overflow-y-auto{overflow-y:auto}.truncate{text-overflow:ellipsis;white-space:nowrap;overflow:hidden}.rounded{border-radius:.25rem}.rounded-full{border-radius:9999px}.rounded-lg{border-radius:.5rem}.rounded-md{border-radius:.375rem}.rounded-xl{border-radius:.75rem}.border{border-width:1px}.border-b{border-bottom-width:1px}.border-r{border-right-width:1px}.border-t{border-top-width:1px}.border-dashed{border-style:dashed}.border-blue-500{--tw-border-opacity:1;border-color:rgb(59 130 246/var(--tw-border-opacity,1))}.border-slate-100{--tw-border-opacity:1;border-color:rgb(241 245 249/var(--tw-border-opacity,1))}.border-slate-200{--tw-border-opacity:1;border-color:rgb(226 232 240/var(--tw-border-opacity,1))}.border-slate-300{--tw-border-opacity:1;border-color:rgb(203 213 225/var(--tw-border-opacity,1))}.bg-blue-50\/50{background-color:#eff6ff80}.bg-slate-200\/70{background-color:#e2e8f0b3}.bg-slate-50{--tw-bg-opacity:1;background-color:rgb(248 250 252/var(--tw-bg-opacity,1))}.bg-slate-50\/30{background-color:#f8fafc4d}.bg-slate-50\/50{background-color:#f8fafc80}.bg-slate-50\/60{background-color:#f8fafc99}.bg-slate-50\/90{background-color:#f8fafce6}.bg-white{--tw-bg-opacity:1;background-color:rgb(255 255 255/var(--tw-bg-opacity,1))}.p-0\.5{padding:.125rem}.p-2{padding:.5rem}.p-3{padding:.75rem}.p-4{padding:1rem}.p-8{padding:2rem}.px-1\.5{padding-left:.375rem;padding-right:.375rem}.px-2{padding-left:.5rem;padding-right:.5rem}.px-4{padding-left:1rem;padding-right:1rem}.py-0\.5{padding-top:.125rem;padding-bottom:.125rem}.py-1{padding-top:.25rem;padding-bottom:.25rem}.py-1\.5{padding-top:.375rem;padding-bottom:.375rem}.py-2{padding-top:.5rem;padding-bottom:.5rem}.pb-2{padding-bottom:.5rem}.pl-2{padding-left:.5rem}.pl-4{padding-left:1rem}.pr-1{padding-right:.25rem}.pt-1{padding-top:.25rem}.text-left{text-align:left}.text-center{text-align:center}.text-right{text-align:right}.align-middle{vertical-align:middle}.text-\[10px\]{font-size:10px}.text-\[11px\]{font-size:11px}.text-\[12px\]{font-size:12px}.text-sm{font-size:.875rem;line-height:1.25rem}.font-bold{font-weight:700}.font-medium{font-weight:500}.font-normal{font-weight:400}.font-semibold{font-weight:600}.uppercase{text-transform:uppercase}.tracking-wider{letter-spacing:.05em}.text-blue-500{--tw-text-opacity:1;color:rgb(59 130 246/var(--tw-text-opacity,1))}.text-blue-600{--tw-text-opacity:1;color:rgb(37 99 235/var(--tw-text-opacity,1))}.text-red-500{--tw-text-opacity:1;color:rgb(239 68 68/var(--tw-text-opacity,1))}.text-slate-300{--tw-text-opacity:1;color:rgb(203 213 225/var(--tw-text-opacity,1))}.text-slate-400{--tw-text-opacity:1;color:rgb(148 163 184/var(--tw-text-opacity,1))}.text-slate-500{--tw-text-opacity:1;color:rgb(100 116 139/var(--tw-text-opacity,1))}.text-slate-600{--tw-text-opacity:1;color:rgb(71 85 105/var(--tw-text-opacity,1))}.text-slate-700{--tw-text-opacity:1;color:rgb(51 65 85/var(--tw-text-opacity,1))}.text-slate-800{--tw-text-opacity:1;color:rgb(30 41 59/var(--tw-text-opacity,1))}.opacity-0{opacity:0}.opacity-100{opacity:1}.shadow-\[-1px_0_0_rgba\(226\,232\,240\,1\)\]{--tw-shadow:-1px 0 0 #e2e8f0;--tw-shadow-colored:-1px 0 0 var(--tw-shadow-color);box-shadow:var(--tw-ring-offset-shadow,0 0 #0000), var(--tw-ring-shadow,0 0 #0000), var(--tw-shadow)}.shadow-lg{--tw-shadow:0 10px 15px -3px #0000001a, 0 4px 6px -4px #0000001a;--tw-shadow-colored:0 10px 15px -3px var(--tw-shadow-color), 0 4px 6px -4px var(--tw-shadow-color);box-shadow:var(--tw-ring-offset-shadow,0 0 #0000), var(--tw-ring-shadow,0 0 #0000), var(--tw-shadow)}.shadow-sm{--tw-shadow:0 1px 2px 0 #0000000d;--tw-shadow-colored:0 1px 2px 0 var(--tw-shadow-color);box-shadow:var(--tw-ring-offset-shadow,0 0 #0000), var(--tw-ring-shadow,0 0 #0000), var(--tw-shadow)}.filter{filter:var(--tw-blur) var(--tw-brightness) var(--tw-contrast) var(--tw-grayscale) var(--tw-hue-rotate) var(--tw-invert) var(--tw-saturate) var(--tw-sepia) var(--tw-drop-shadow)}.transition-all{transition-property:all;transition-duration:.15s;transition-timing-function:cubic-bezier(.4,0,.2,1)}.transition-colors{transition-property:color,background-color,border-color,text-decoration-color,fill,stroke;transition-duration:.15s;transition-timing-function:cubic-bezier(.4,0,.2,1)}.transition-opacity{transition-property:opacity;transition-duration:.15s;transition-timing-function:cubic-bezier(.4,0,.2,1)}.duration-150{transition-duration:.15s}.duration-200{transition-duration:.2s}.hover\:bg-slate-100:hover{--tw-bg-opacity:1;background-color:rgb(241 245 249/var(--tw-bg-opacity,1))}.hover\:bg-slate-100\/80:hover{background-color:#f1f5f9cc}.hover\:bg-slate-200:hover{--tw-bg-opacity:1;background-color:rgb(226 232 240/var(--tw-bg-opacity,1))}.hover\:bg-slate-50:hover{--tw-bg-opacity:1;background-color:rgb(248 250 252/var(--tw-bg-opacity,1))}.hover\:bg-slate-50\/80:hover{background-color:#f8fafccc}.hover\:text-blue-600:hover{--tw-text-opacity:1;color:rgb(37 99 235/var(--tw-text-opacity,1))}.hover\:underline:hover{text-decoration-line:underline}.focus\:border-blue-500:focus{--tw-border-opacity:1;border-color:rgb(59 130 246/var(--tw-border-opacity,1))}.focus\:outline-none:focus{outline-offset:2px;outline:2px solid #0000}.focus\:ring-1:focus{--tw-ring-offset-shadow:var(--tw-ring-inset) 0 0 0 var(--tw-ring-offset-width) var(--tw-ring-offset-color);--tw-ring-shadow:var(--tw-ring-inset) 0 0 0 calc(1px + var(--tw-ring-offset-width)) var(--tw-ring-color);box-shadow:var(--tw-ring-offset-shadow), var(--tw-ring-shadow), var(--tw-shadow,0 0 #0000)}.focus\:ring-blue-400:focus{--tw-ring-opacity:1;--tw-ring-color:rgb(96 165 250/var(--tw-ring-opacity,1))}.focus\:ring-blue-500:focus{--tw-ring-opacity:1;--tw-ring-color:rgb(59 130 246/var(--tw-ring-opacity,1))}.active\:cursor-grabbing:active{cursor:grabbing}.group:hover .group-hover\:bg-slate-100{--tw-bg-opacity:1;background-color:rgb(241 245 249/var(--tw-bg-opacity,1))}.group:hover .group-hover\:bg-slate-50\/80{background-color:#f8fafccc}.group\/header:hover .group-hover\/header\:opacity-100,.group:hover .group-hover\:opacity-100{opacity:1}
|
|
1
|
+
.flexi-root{width:100%;position:relative}.flexi-root>*+*{margin-top:.75rem}.flexi-groupzone{box-sizing:border-box;background-color:#f8fafc80;border:1px dashed #e2e8f0;border-radius:.75rem;align-items:center;gap:.5rem;width:100%;min-height:52px;padding:.5rem 1rem;transition:all .2s;display:flex}.flexi-groupzone--dragover{background-color:#eff6ff80;border:1px solid #3b82f6;transform:scale(.99)}.flexi-groupzone-hint{color:#64748b;-webkit-user-select:none;user-select:none;font-size:12px;font-weight:500}.flexi-groupzone-chips{flex-wrap:wrap;align-items:center;gap:.375rem;display:flex}.flexi-groupzone-label{text-transform:uppercase;letter-spacing:.05em;color:#64748b;margin-right:.25rem;font-size:11px;font-weight:700}.flexi-chip{color:#64748b;background-color:#fff;border:1px solid #e2e8f0;border-radius:.5rem;align-items:center;gap:.375rem;padding:.25rem .25rem .25rem .5rem;font-size:12px;font-weight:600;display:flex;box-shadow:0 1px 2px #0000000d}.flexi-chip-remove{border-radius:5px;width:18px;height:18px}.flexi-table-wrap{box-sizing:border-box;background-color:#fff;border:1px solid #f1f5f9;border-radius:.75rem;width:100%;overflow-x:auto;box-shadow:0 1px 2px #0000000d}.flexi-table{caption-side:bottom;border-collapse:collapse;border-spacing:0;table-layout:fixed;width:100%;font-size:.875rem}.flexi-thead{-webkit-user-select:none;user-select:none;background-color:#f8fafc}.flexi-header-row{border-bottom:1px solid #f1f5f9}.flexi-group-spacer-th{border-right:1px solid #f1f5f9;width:48px}.flexi-th{text-align:center;vertical-align:middle;border-bottom:1px solid #f1f5f9;border-right:1px solid #f1f5f9;height:48px;padding:0 1rem;font-size:12px;font-weight:700;position:relative}.flexi-th--draggable{cursor:grab}.flexi-th--draggable:active{cursor:grabbing}.flexi-th--pinned{background-color:#f8fafce6}.flexi-th-inner{justify-content:space-between;align-items:center;gap:.25rem;width:100%;display:flex}.flexi-th-label{white-space:nowrap;text-overflow:ellipsis;align-items:center;gap:.375rem;width:100%;display:flex;overflow:hidden}.flexi-th-label--sortable{cursor:pointer;-webkit-user-select:none;user-select:none}.flexi-th-label--sortable:hover{color:#2563eb}.flexi-th-text{white-space:nowrap;text-overflow:ellipsis;overflow:hidden}.flexi-sort-icon{color:#94a3b8;opacity:0;transition:color .15s,opacity .15s}.flexi-sort-icon--active{color:#2563eb;opacity:1}.flexi-th-inner:hover .flexi-sort-icon{opacity:1}.flexi-th-actions{align-items:center;gap:2px;display:flex}.flexi-icon-btn{color:#64748b;background-color:#0000;border-radius:6px;justify-content:center;align-items:center;width:22px;height:22px;margin:0;padding:0;transition:background-color .15s,color .15s,transform .1s;display:inline-flex}.flexi-icon-btn:hover{color:#334155;background-color:#e2e8f0}.flexi-icon-btn:active{background-color:#cbd5e1;transform:scale(.92)}.flexi-icon-btn:focus-visible{outline-offset:1px;outline:2px solid #93c5fd}.flexi-filter-btn{color:#64748b;opacity:0}.flexi-filter-btn--active{color:#2563eb;opacity:1}.flexi-filter-btn--active:hover{color:#2563eb;background-color:#dbeafe}.flexi-pin-btn{color:#cbd5e1;opacity:0}.flexi-pin-btn--pinned{color:#3b82f6;opacity:1}.flexi-pin-btn--pinned:hover{color:#2563eb;background-color:#dbeafe}.flexi-th-inner:hover .flexi-filter-btn,.flexi-th-inner:hover .flexi-pin-btn{opacity:1}.flexi-actions-th{vertical-align:middle;text-align:right;height:48px;padding:0 1rem;font-size:12px;font-weight:700;box-shadow:-1px 0 #e2e8f0}.flexi-filter-dropdown{color:#334155;text-align:left;pointer-events:auto;background-color:#fff;border:1px solid #e2e8f0;border-radius:.5rem;flex-direction:column;width:13rem;padding:.5rem 0;font-weight:400;display:flex;position:absolute;box-shadow:0 10px 15px -3px #0000001a,0 4px 6px -4px #0000001a}.flexi-filter-search{border-bottom:1px solid #f1f5f9;margin-bottom:.25rem;padding:0 .5rem .5rem}.flexi-input{color:#475569;box-sizing:border-box;border:1px solid #e2e8f0;border-radius:.25rem;width:100%;padding:.25rem .5rem;font-size:12px;font-weight:500}.flexi-input:focus{border-color:#3b82f6;outline:none}.flexi-filter-list{flex-direction:column;gap:.25rem;max-height:10rem;padding:0 .5rem;display:flex;overflow-y:auto}.flexi-filter-empty{color:#64748b;text-align:center;padding:.5rem;font-size:11px}.flexi-filter-option{cursor:pointer;-webkit-user-select:none;user-select:none;border-radius:.25rem;align-items:center;gap:.5rem;padding:.375rem .5rem;font-size:12px;display:flex}.flexi-filter-option:hover{background-color:#f8fafc}.flexi-filter-option-text{white-space:nowrap;text-overflow:ellipsis;overflow:hidden}.flexi-checkbox{accent-color:#2563eb;border:1px solid #cbd5e1;border-radius:.25rem;width:.875rem;height:.875rem}.flexi-checkbox:focus{outline-offset:1px;outline:2px solid #3b82f6}.flexi-filter-footer{border-top:1px solid #f1f5f9;justify-content:flex-end;margin-top:.5rem;padding:.25rem .5rem 0;display:flex}.flexi-filter-clear{color:#ef4444;padding:.125rem .5rem;font-size:11px;font-weight:500}.flexi-filter-clear:hover{text-decoration:underline}.flexi-tbody{display:table-row-group}.flexi-tbody tr+tr{border-top:1px solid #f1f5f9}.flexi-empty-cell{text-align:center;color:#64748b;padding:2rem;font-size:12px;font-weight:500}.flexi-group-row{-webkit-user-select:none;user-select:none;background-color:#f8fafc99;transition:background-color .15s}.flexi-group-row:hover{background-color:#f1f5f9cc}.flexi-group-cell{color:#334155;border-right:1px solid #f1f5f9;padding:.75rem 1rem;font-size:12px;font-weight:600}.flexi-group-toggle{text-align:left;border-radius:6px;align-items:center;gap:.375rem;margin:-4px -8px -4px -4px;padding:4px 8px 4px 4px;transition:background-color .15s;display:flex}.flexi-group-toggle:hover{background-color:#e2e8f099}.flexi-group-toggle:focus-visible{outline-offset:1px;outline:2px solid #93c5fd}.flexi-icon-muted{color:#64748b}.flexi-group-value{color:#1e293b;white-space:nowrap;text-overflow:ellipsis;width:10rem;font-weight:700;overflow:hidden}.flexi-group-count{color:#64748b;background-color:#e2e8f0b3;border-radius:9999px;margin-left:.25rem;padding:.05rem .375rem;font-size:10px;font-weight:500}.flexi-group-filler{background-color:#f8fafc4d}.flexi-row{border-bottom:1px solid #f1f5f9;height:48px;transition:background-color .15s}.flexi-row:hover{background-color:#f8fafccc}.flexi-row-indent-cell{background-color:#fff;border-right:1px solid #f1f5f9;width:48px}.flexi-cell{vertical-align:middle;padding:.25rem 1rem;transition:background-color .15s}.flexi-row:hover .flexi-cell--pinned{background-color:#f1f5f9}.flexi-cell-text{color:#64748b;white-space:nowrap;text-overflow:ellipsis;font-size:12px;font-weight:500;display:block;overflow:hidden}.flexi-actions-cell{vertical-align:middle;text-align:right;background-color:#fff;padding:.25rem 1rem;box-shadow:-1px 0 #e2e8f0}.flexi-row:hover .flexi-actions-cell{background-color:#f8fafccc}.flexi-actions-inner{opacity:0;justify-content:flex-end;gap:.25rem;transition:opacity .15s;display:flex}.flexi-row:hover .flexi-actions-inner{opacity:1}.flexi-icon-xs{width:.75rem;height:.75rem}.flexi-icon-sm{width:.875rem;height:.875rem}.flexi-icon-md{width:1rem;height:1rem}.flexi-root button{appearance:none;cursor:pointer;font:inherit;color:inherit;background:0 0;border:none;margin:0;padding:0;line-height:normal}.flexi-root input{font:inherit}.flexi-root table{border-collapse:collapse;border-spacing:0}
|
|
2
2
|
/*$vite$:1*/
|
package/dist/index.es.js
CHANGED
|
@@ -1,68 +1,84 @@
|
|
|
1
|
-
import { ArrowDown as e, ArrowUp as t, ArrowUpDown as n, ChevronDown as r, ChevronRight as i,
|
|
2
|
-
import { useEffect as
|
|
3
|
-
import {
|
|
1
|
+
import { ArrowDown as e, ArrowUp as t, ArrowUpDown as n, ChevronDown as r, ChevronRight as i, Filter as a, Pin as o, PinOff as s, X as c } from "lucide-react";
|
|
2
|
+
import { useEffect as l, useMemo as u, useRef as d, useState as f } from "react";
|
|
3
|
+
import { createPortal as p } from "react-dom";
|
|
4
|
+
import { jsx as m, jsxs as h } from "react/jsx-runtime";
|
|
4
5
|
//#region src/DataTable.tsx
|
|
5
|
-
var
|
|
6
|
+
var g = (e) => {
|
|
6
7
|
let t = [];
|
|
7
8
|
return e.forEach((e) => {
|
|
8
|
-
e.children && e.children.length > 0 ? t.push(...
|
|
9
|
+
e.children && e.children.length > 0 ? t.push(...g(e.children)) : t.push(e);
|
|
9
10
|
}), t;
|
|
10
|
-
};
|
|
11
|
-
function
|
|
12
|
-
let [
|
|
11
|
+
}, _ = (...e) => e.filter(Boolean).join(" ");
|
|
12
|
+
function v({ columns: v, data: y, rowKey: b, actions: x, isLoading: ee, groupBy: S = !1, defaultGroupBy: C = [], onPinChange: w, onGroupChange: T, containerStyle: te, tableStyle: ne }) {
|
|
13
|
+
let [E, D] = f(null), [O, k] = f({}), [A, j] = f(""), [M, re] = f(null), N = d(/* @__PURE__ */ new Map()), [P, F] = f(C), [I, L] = f({}), [ie, R] = f(!1), [z, B] = f({
|
|
13
14
|
key: null,
|
|
14
15
|
direction: null
|
|
15
|
-
}),
|
|
16
|
+
}), V = u(() => g(v), [v]), [H, ae] = f(V.filter((e) => e.pinned).map((e) => e.key)), U = u(() => {
|
|
16
17
|
let e = (t) => [...t].sort((e, t) => {
|
|
17
|
-
let n =
|
|
18
|
+
let n = H.includes(e.key), r = H.includes(t.key);
|
|
18
19
|
return n && !r ? -1 : !n && r ? 1 : 0;
|
|
19
20
|
}).map((t) => t.children && t.children.length > 0 ? {
|
|
20
21
|
...t,
|
|
21
22
|
children: e(t.children)
|
|
22
23
|
} : t);
|
|
23
|
-
return e(
|
|
24
|
-
}, [
|
|
25
|
-
let e =
|
|
24
|
+
return e(v);
|
|
25
|
+
}, [v, H]), W = u(() => {
|
|
26
|
+
let e = g(U), t = S ? P : [];
|
|
26
27
|
return e.filter((e) => !t.includes(e.key));
|
|
27
28
|
}, [
|
|
28
|
-
|
|
29
|
-
|
|
30
|
-
|
|
31
|
-
]),
|
|
32
|
-
|
|
29
|
+
U,
|
|
30
|
+
P,
|
|
31
|
+
S
|
|
32
|
+
]), G = d(null), K = d(null);
|
|
33
|
+
l(() => {
|
|
33
34
|
function e(e) {
|
|
34
|
-
|
|
35
|
+
let t = e.target, n = E ? N.current.get(E) : null;
|
|
36
|
+
K.current && !K.current.contains(t) && !(n && n.contains(t)) && (D(null), j(""));
|
|
35
37
|
}
|
|
36
38
|
return document.addEventListener("mousedown", e), () => document.removeEventListener("mousedown", e);
|
|
37
|
-
}, [])
|
|
38
|
-
|
|
39
|
-
let
|
|
40
|
-
|
|
41
|
-
|
|
39
|
+
}, [E]), l(() => {
|
|
40
|
+
if (!E) return;
|
|
41
|
+
let e = () => {
|
|
42
|
+
let e = N.current.get(E), t = G.current;
|
|
43
|
+
if (!e || !t) return;
|
|
44
|
+
let n = e.getBoundingClientRect(), r = t.getBoundingClientRect();
|
|
45
|
+
re({
|
|
46
|
+
top: n.bottom - r.top + 4,
|
|
47
|
+
left: n.left - r.left
|
|
48
|
+
});
|
|
49
|
+
};
|
|
50
|
+
return e(), window.addEventListener("scroll", e, !0), window.addEventListener("resize", e), () => {
|
|
51
|
+
window.removeEventListener("scroll", e, !0), window.removeEventListener("resize", e);
|
|
52
|
+
};
|
|
53
|
+
}, [E]);
|
|
54
|
+
let oe = (e) => typeof b == "function" ? b(e) : String(e[b]), se = (e) => {
|
|
55
|
+
let t = H.includes(e);
|
|
56
|
+
ae(t ? H.filter((t) => t !== e) : [...H, e]), w && w(e, !t);
|
|
57
|
+
}, ce = (e) => {
|
|
42
58
|
let t = "asc";
|
|
43
|
-
|
|
59
|
+
z.key === e && (t = z.direction === "asc" ? "desc" : z.direction === "desc" ? null : "asc"), B({
|
|
44
60
|
key: t ? e : null,
|
|
45
61
|
direction: t
|
|
46
62
|
});
|
|
47
|
-
},
|
|
48
|
-
|
|
49
|
-
},
|
|
50
|
-
e.preventDefault(),
|
|
63
|
+
}, le = (e, t) => {
|
|
64
|
+
S && (e.dataTransfer.setData("text/plain", t), e.dataTransfer.effectAllowed = "move");
|
|
65
|
+
}, ue = (e) => {
|
|
66
|
+
e.preventDefault(), R(!1);
|
|
51
67
|
let t = e.dataTransfer.getData("text/plain");
|
|
52
|
-
if (t && !
|
|
53
|
-
let e = [...
|
|
54
|
-
|
|
68
|
+
if (t && !P.includes(t)) {
|
|
69
|
+
let e = [...P, t];
|
|
70
|
+
F(e), T && T(e);
|
|
55
71
|
}
|
|
56
|
-
},
|
|
57
|
-
let t =
|
|
58
|
-
|
|
59
|
-
}, q =
|
|
72
|
+
}, de = (e) => {
|
|
73
|
+
let t = P.filter((t) => t !== e);
|
|
74
|
+
F(t), L({}), T && T(t);
|
|
75
|
+
}, q = u(() => {
|
|
60
76
|
let e = (t) => {
|
|
61
77
|
let n = 0;
|
|
62
78
|
return t.forEach((t) => {
|
|
63
79
|
n = t.children && t.children.length > 0 ? Math.max(n, 1 + e(t.children)) : Math.max(n, 1);
|
|
64
80
|
}), n;
|
|
65
|
-
}, t = e(
|
|
81
|
+
}, t = e(U), n = Array.from({ length: t }, () => []), r = (e) => !e.children || e.children.length === 0 ? P.includes(e.key) && S ? 0 : 1 : e.children.reduce((e, t) => e + r(t), 0), i = S ? P : [], a = (e, o) => {
|
|
66
82
|
e.forEach((e) => {
|
|
67
83
|
if (i.includes(e.key)) return;
|
|
68
84
|
let s = r(e);
|
|
@@ -77,55 +93,55 @@ function h({ columns: h, data: g, rowKey: _, actions: v, isLoading: ee, groupBy:
|
|
|
77
93
|
}));
|
|
78
94
|
});
|
|
79
95
|
};
|
|
80
|
-
return a(
|
|
96
|
+
return a(U, 0), n.filter((e) => e.length > 0);
|
|
81
97
|
}, [
|
|
82
|
-
|
|
83
|
-
|
|
84
|
-
|
|
85
|
-
]),
|
|
98
|
+
U,
|
|
99
|
+
P,
|
|
100
|
+
S
|
|
101
|
+
]), fe = u(() => {
|
|
86
102
|
let e = {}, t = 0;
|
|
87
|
-
return
|
|
88
|
-
if (
|
|
103
|
+
return S && P.length > 0 && (t += 48), W.forEach((n) => {
|
|
104
|
+
if (H.includes(n.key)) {
|
|
89
105
|
e[n.key] = t;
|
|
90
106
|
let r = n.style?.width || n.headerStyle?.width || "150px";
|
|
91
107
|
t += typeof r == "number" ? r : parseInt(String(r), 10) || 150;
|
|
92
108
|
}
|
|
93
109
|
}), e;
|
|
94
110
|
}, [
|
|
95
|
-
|
|
96
|
-
|
|
97
|
-
|
|
98
|
-
|
|
99
|
-
]),
|
|
100
|
-
|
|
111
|
+
W,
|
|
112
|
+
H,
|
|
113
|
+
P,
|
|
114
|
+
S
|
|
115
|
+
]), pe = (e, t) => {
|
|
116
|
+
k((n) => {
|
|
101
117
|
let r = n[e] || [], i = r.includes(t) ? r.filter((e) => e !== t) : [...r, t], a = {
|
|
102
118
|
...n,
|
|
103
119
|
[e]: i
|
|
104
120
|
};
|
|
105
121
|
return a[e].length === 0 && delete a[e], a;
|
|
106
122
|
});
|
|
107
|
-
},
|
|
108
|
-
|
|
123
|
+
}, me = (e) => {
|
|
124
|
+
k((t) => {
|
|
109
125
|
let n = { ...t };
|
|
110
126
|
return delete n[e], n;
|
|
111
127
|
});
|
|
112
|
-
}, J =
|
|
113
|
-
if (!
|
|
114
|
-
let e =
|
|
115
|
-
return
|
|
128
|
+
}, J = u(() => {
|
|
129
|
+
if (!E) return [];
|
|
130
|
+
let e = V.find((e) => e.key === E), t = y.map((t) => e?.getValue ? e.getValue(t) : t[E]), n = Array.from(new Set(t)).filter((e) => e != null);
|
|
131
|
+
return A.trim() ? n.filter((e) => String(e).toLowerCase().includes(A.toLowerCase())) : n;
|
|
116
132
|
}, [
|
|
117
|
-
|
|
118
|
-
|
|
119
|
-
|
|
120
|
-
|
|
121
|
-
]), Y =
|
|
122
|
-
let e =
|
|
133
|
+
y,
|
|
134
|
+
E,
|
|
135
|
+
A,
|
|
136
|
+
V
|
|
137
|
+
]), Y = u(() => {
|
|
138
|
+
let e = y.filter((e) => Object.entries(O).every(([t, n]) => {
|
|
123
139
|
if (!n || n.length === 0) return !0;
|
|
124
|
-
let r =
|
|
140
|
+
let r = V.find((e) => e.key === t), i = r?.getValue ? r.getValue(e) : e[t];
|
|
125
141
|
return n.includes(i);
|
|
126
142
|
}));
|
|
127
|
-
if (
|
|
128
|
-
let { key: t, direction: n } =
|
|
143
|
+
if (z.key && z.direction) {
|
|
144
|
+
let { key: t, direction: n } = z, r = V.find((e) => e.key === t);
|
|
129
145
|
e = [...e].sort((e, i) => {
|
|
130
146
|
let a = r?.getValue ? r.getValue(e) : e[t], o = r?.getValue ? r.getValue(i) : i[t];
|
|
131
147
|
if (a === o) return 0;
|
|
@@ -140,15 +156,15 @@ function h({ columns: h, data: g, rowKey: _, actions: v, isLoading: ee, groupBy:
|
|
|
140
156
|
}
|
|
141
157
|
return e;
|
|
142
158
|
}, [
|
|
143
|
-
|
|
144
|
-
|
|
145
|
-
|
|
146
|
-
|
|
147
|
-
]), X =
|
|
148
|
-
if (!
|
|
159
|
+
y,
|
|
160
|
+
O,
|
|
161
|
+
z,
|
|
162
|
+
V
|
|
163
|
+
]), X = u(() => {
|
|
164
|
+
if (!S || P.length === 0) return Y;
|
|
149
165
|
let e = (t, n, r = "") => {
|
|
150
|
-
if (n >=
|
|
151
|
-
let i =
|
|
166
|
+
if (n >= P.length) return t;
|
|
167
|
+
let i = P[n], a = V.find((e) => e.key === i), o = {};
|
|
152
168
|
return t.forEach((e) => {
|
|
153
169
|
let t = a?.getValue ? a.getValue(e) : e[i], n = String(t ?? "N/A");
|
|
154
170
|
o[n] || (o[n] = []), o[n].push(e);
|
|
@@ -168,84 +184,86 @@ function h({ columns: h, data: g, rowKey: _, actions: v, isLoading: ee, groupBy:
|
|
|
168
184
|
return e(Y, 0);
|
|
169
185
|
}, [
|
|
170
186
|
Y,
|
|
171
|
-
|
|
172
|
-
|
|
173
|
-
|
|
174
|
-
]),
|
|
175
|
-
|
|
187
|
+
P,
|
|
188
|
+
S,
|
|
189
|
+
V
|
|
190
|
+
]), he = (e) => {
|
|
191
|
+
L((t) => {
|
|
176
192
|
let n = t[e] !== !1;
|
|
177
193
|
return {
|
|
178
194
|
...t,
|
|
179
195
|
[e]: !n
|
|
180
196
|
};
|
|
181
197
|
});
|
|
182
|
-
}, Z =
|
|
183
|
-
if (!
|
|
198
|
+
}, Z = u(() => {
|
|
199
|
+
if (!S || P.length === 0) return X;
|
|
184
200
|
let e = [], t = (n) => {
|
|
185
201
|
n.forEach((n) => {
|
|
186
|
-
n.isGroupRow ? (e.push(n),
|
|
202
|
+
n.isGroupRow ? (e.push(n), I[n.path] !== !1 && t(n.children)) : e.push(n);
|
|
187
203
|
});
|
|
188
204
|
};
|
|
189
205
|
return t(X), e;
|
|
190
206
|
}, [
|
|
191
207
|
X,
|
|
192
|
-
|
|
193
|
-
|
|
194
|
-
|
|
195
|
-
]), Q = (e, t = !1, n) =>
|
|
208
|
+
I,
|
|
209
|
+
P,
|
|
210
|
+
S
|
|
211
|
+
]), Q = (e, t = !1, n) => H.includes(e) ? {
|
|
196
212
|
position: "sticky",
|
|
197
|
-
left: `${
|
|
213
|
+
left: `${fe[e]}px`,
|
|
198
214
|
zIndex: t ? 30 : 20,
|
|
199
215
|
backgroundColor: "#fff",
|
|
200
216
|
boxShadow: "2px 0 5px -2px rgba(0,0,0,0.1)",
|
|
201
217
|
...n
|
|
202
|
-
} : n || {}, $ =
|
|
203
|
-
return /* @__PURE__ */
|
|
204
|
-
|
|
205
|
-
|
|
218
|
+
} : n || {}, $ = W.length + +!!x + (S && P.length > 0 ? 1 : 0);
|
|
219
|
+
return /* @__PURE__ */ h("div", {
|
|
220
|
+
ref: G,
|
|
221
|
+
className: "flexi-root",
|
|
222
|
+
children: [S && /* @__PURE__ */ m("div", {
|
|
206
223
|
onDragOver: (e) => {
|
|
207
|
-
e.preventDefault(),
|
|
224
|
+
e.preventDefault(), R(!0);
|
|
208
225
|
},
|
|
209
|
-
onDragLeave: () =>
|
|
210
|
-
onDrop:
|
|
211
|
-
className:
|
|
212
|
-
children:
|
|
213
|
-
className: "
|
|
226
|
+
onDragLeave: () => R(!1),
|
|
227
|
+
onDrop: ue,
|
|
228
|
+
className: _("flexi-groupzone", ie && "flexi-groupzone--dragover"),
|
|
229
|
+
children: P.length === 0 ? /* @__PURE__ */ m("span", {
|
|
230
|
+
className: "flexi-groupzone-hint",
|
|
214
231
|
children: "Drag a column header here to group your records by that field"
|
|
215
|
-
}) : /* @__PURE__ */
|
|
216
|
-
className: "
|
|
217
|
-
children: [/* @__PURE__ */
|
|
218
|
-
className: "
|
|
232
|
+
}) : /* @__PURE__ */ h("div", {
|
|
233
|
+
className: "flexi-groupzone-chips",
|
|
234
|
+
children: [/* @__PURE__ */ m("span", {
|
|
235
|
+
className: "flexi-groupzone-label",
|
|
219
236
|
children: "Grouped By:"
|
|
220
|
-
}),
|
|
221
|
-
className: "
|
|
222
|
-
children: [/* @__PURE__ */
|
|
223
|
-
|
|
224
|
-
|
|
225
|
-
|
|
237
|
+
}), P.map((e) => /* @__PURE__ */ h("div", {
|
|
238
|
+
className: "flexi-chip",
|
|
239
|
+
children: [/* @__PURE__ */ m("span", { children: V.find((t) => t.key === e)?.header || e }), /* @__PURE__ */ m("button", {
|
|
240
|
+
type: "button",
|
|
241
|
+
onClick: () => de(e),
|
|
242
|
+
className: "flexi-icon-btn flexi-chip-remove",
|
|
243
|
+
children: /* @__PURE__ */ m(c, { className: "flexi-icon-xs" })
|
|
226
244
|
})]
|
|
227
245
|
}, e))]
|
|
228
246
|
})
|
|
229
|
-
}), /* @__PURE__ */
|
|
230
|
-
className: "
|
|
231
|
-
style:
|
|
232
|
-
children: /* @__PURE__ */
|
|
233
|
-
className: "
|
|
234
|
-
style:
|
|
247
|
+
}), /* @__PURE__ */ m("div", {
|
|
248
|
+
className: "flexi-table-wrap",
|
|
249
|
+
style: te,
|
|
250
|
+
children: /* @__PURE__ */ h("table", {
|
|
251
|
+
className: "flexi-table",
|
|
252
|
+
style: ne,
|
|
235
253
|
children: [
|
|
236
|
-
/* @__PURE__ */
|
|
237
|
-
|
|
238
|
-
|
|
239
|
-
|
|
254
|
+
/* @__PURE__ */ h("colgroup", { children: [
|
|
255
|
+
S && P.length > 0 && /* @__PURE__ */ m("col", { style: { width: "48px" } }),
|
|
256
|
+
W.map((e) => /* @__PURE__ */ m("col", { style: e.style }, e.key)),
|
|
257
|
+
x && /* @__PURE__ */ m("col", { style: { width: "100px" } })
|
|
240
258
|
] }),
|
|
241
|
-
/* @__PURE__ */
|
|
242
|
-
className: "
|
|
243
|
-
children: q.map((r, i) => /* @__PURE__ */
|
|
244
|
-
className: "
|
|
259
|
+
/* @__PURE__ */ m("thead", {
|
|
260
|
+
className: "flexi-thead",
|
|
261
|
+
children: q.map((r, i) => /* @__PURE__ */ h("tr", {
|
|
262
|
+
className: "flexi-header-row",
|
|
245
263
|
children: [
|
|
246
|
-
i === 0 &&
|
|
264
|
+
i === 0 && S && P.length > 0 && /* @__PURE__ */ m("th", {
|
|
247
265
|
rowSpan: q.length,
|
|
248
|
-
className: "
|
|
266
|
+
className: "flexi-group-spacer-th",
|
|
249
267
|
style: {
|
|
250
268
|
position: "sticky",
|
|
251
269
|
left: 0,
|
|
@@ -253,98 +271,109 @@ function h({ columns: h, data: g, rowKey: _, actions: v, isLoading: ee, groupBy:
|
|
|
253
271
|
backgroundColor: "rgb(248, 250, 252)"
|
|
254
272
|
}
|
|
255
273
|
}),
|
|
256
|
-
r.map(({ col: r, rowSpan: i, colSpan:
|
|
257
|
-
let
|
|
258
|
-
return /* @__PURE__ */
|
|
274
|
+
r.map(({ col: r, rowSpan: i, colSpan: c }) => {
|
|
275
|
+
let l = (O[r.key]?.length || 0) > 0, u = H.includes(r.key), d = Q(r.key, !0, r.headerStyle), f = !r.children || r.children.length === 0, g = z.key === r.key, v = !!(S && f);
|
|
276
|
+
return /* @__PURE__ */ m("th", {
|
|
259
277
|
rowSpan: i,
|
|
260
|
-
colSpan:
|
|
261
|
-
...
|
|
278
|
+
colSpan: c,
|
|
279
|
+
...v ? {
|
|
262
280
|
draggable: !0,
|
|
263
|
-
onDragStart: (e) =>
|
|
281
|
+
onDragStart: (e) => le(e, r.key)
|
|
264
282
|
} : {},
|
|
265
|
-
className:
|
|
266
|
-
style:
|
|
267
|
-
children: /* @__PURE__ */
|
|
268
|
-
className: "
|
|
283
|
+
className: _("flexi-th", v && "flexi-th--draggable", u && "flexi-th--pinned", r.className),
|
|
284
|
+
style: d,
|
|
285
|
+
children: /* @__PURE__ */ h("div", {
|
|
286
|
+
className: "flexi-th-inner",
|
|
269
287
|
children: [
|
|
270
|
-
/* @__PURE__ */
|
|
271
|
-
className:
|
|
272
|
-
onClick: () => r.sortable &&
|
|
273
|
-
children: [/* @__PURE__ */
|
|
274
|
-
className: "
|
|
288
|
+
/* @__PURE__ */ h("div", {
|
|
289
|
+
className: _("flexi-th-label", r.sortable && f && "flexi-th-label--sortable"),
|
|
290
|
+
onClick: () => r.sortable && f && ce(r.key),
|
|
291
|
+
children: [/* @__PURE__ */ m("span", {
|
|
292
|
+
className: "flexi-th-text",
|
|
275
293
|
children: r.header
|
|
276
|
-
}),
|
|
277
|
-
className:
|
|
278
|
-
children:
|
|
294
|
+
}), f && r.sortable && /* @__PURE__ */ m("span", {
|
|
295
|
+
className: _("flexi-sort-icon", g && "flexi-sort-icon--active"),
|
|
296
|
+
children: g && z.direction === "asc" ? /* @__PURE__ */ m(t, { className: "flexi-icon-sm" }) : g && z.direction === "desc" ? /* @__PURE__ */ m(e, { className: "flexi-icon-sm" }) : /* @__PURE__ */ m(n, { className: "flexi-icon-sm" })
|
|
279
297
|
})]
|
|
280
298
|
}),
|
|
281
|
-
/* @__PURE__ */
|
|
282
|
-
className: "
|
|
283
|
-
children: [
|
|
299
|
+
/* @__PURE__ */ h("div", {
|
|
300
|
+
className: "flexi-th-actions",
|
|
301
|
+
children: [f && r.filterable && /* @__PURE__ */ m("button", {
|
|
302
|
+
type: "button",
|
|
303
|
+
ref: (e) => {
|
|
304
|
+
e ? N.current.set(r.key, e) : N.current.delete(r.key);
|
|
305
|
+
},
|
|
284
306
|
onClick: (e) => {
|
|
285
|
-
e.stopPropagation(),
|
|
307
|
+
e.stopPropagation(), j(""), D(E === r.key ? null : r.key);
|
|
286
308
|
},
|
|
287
|
-
className:
|
|
288
|
-
children: "
|
|
289
|
-
}),
|
|
309
|
+
className: _("flexi-icon-btn", "flexi-filter-btn", l && "flexi-filter-btn--active"),
|
|
310
|
+
children: /* @__PURE__ */ m(a, { className: "flexi-icon-sm" })
|
|
311
|
+
}), f && /* @__PURE__ */ m("button", {
|
|
312
|
+
type: "button",
|
|
290
313
|
onClick: (e) => {
|
|
291
|
-
e.stopPropagation(),
|
|
314
|
+
e.stopPropagation(), se(r.key);
|
|
292
315
|
},
|
|
293
|
-
className:
|
|
294
|
-
title:
|
|
295
|
-
children:
|
|
316
|
+
className: _("flexi-icon-btn", "flexi-pin-btn", u && "flexi-pin-btn--pinned"),
|
|
317
|
+
title: u ? "Unpin column" : "Pin column",
|
|
318
|
+
children: m(u ? s : o, { className: "flexi-icon-sm" })
|
|
296
319
|
})]
|
|
297
320
|
}),
|
|
298
|
-
|
|
299
|
-
ref:
|
|
300
|
-
className: "
|
|
321
|
+
E === r.key && f && M && G.current && p(/* @__PURE__ */ h("div", {
|
|
322
|
+
ref: K,
|
|
323
|
+
className: "flexi-filter-dropdown",
|
|
324
|
+
style: {
|
|
325
|
+
top: M.top,
|
|
326
|
+
left: M.left,
|
|
327
|
+
zIndex: 9999
|
|
328
|
+
},
|
|
301
329
|
children: [
|
|
302
|
-
/* @__PURE__ */
|
|
303
|
-
className: "
|
|
304
|
-
children: /* @__PURE__ */
|
|
330
|
+
/* @__PURE__ */ m("div", {
|
|
331
|
+
className: "flexi-filter-search",
|
|
332
|
+
children: /* @__PURE__ */ m("input", {
|
|
305
333
|
type: "text",
|
|
306
334
|
placeholder: "Search values...",
|
|
307
|
-
value:
|
|
308
|
-
onChange: (e) =>
|
|
309
|
-
className: "
|
|
335
|
+
value: A,
|
|
336
|
+
onChange: (e) => j(e.target.value),
|
|
337
|
+
className: "flexi-input",
|
|
310
338
|
onClick: (e) => e.stopPropagation()
|
|
311
339
|
})
|
|
312
340
|
}),
|
|
313
|
-
/* @__PURE__ */
|
|
314
|
-
className: "
|
|
315
|
-
children: J.length === 0 ? /* @__PURE__ */
|
|
316
|
-
className: "
|
|
341
|
+
/* @__PURE__ */ m("div", {
|
|
342
|
+
className: "flexi-filter-list",
|
|
343
|
+
children: J.length === 0 ? /* @__PURE__ */ m("div", {
|
|
344
|
+
className: "flexi-filter-empty",
|
|
317
345
|
children: "No results found"
|
|
318
|
-
}) : J.map((e, t) => /* @__PURE__ */
|
|
319
|
-
className: "
|
|
320
|
-
children: [/* @__PURE__ */
|
|
346
|
+
}) : J.map((e, t) => /* @__PURE__ */ h("label", {
|
|
347
|
+
className: "flexi-filter-option",
|
|
348
|
+
children: [/* @__PURE__ */ m("input", {
|
|
321
349
|
type: "checkbox",
|
|
322
|
-
className: "
|
|
323
|
-
checked:
|
|
324
|
-
onChange: () =>
|
|
325
|
-
}), /* @__PURE__ */
|
|
326
|
-
className: "
|
|
350
|
+
className: "flexi-checkbox",
|
|
351
|
+
checked: O[r.key]?.includes(e) || !1,
|
|
352
|
+
onChange: () => pe(r.key, e)
|
|
353
|
+
}), /* @__PURE__ */ m("span", {
|
|
354
|
+
className: "flexi-filter-option-text",
|
|
327
355
|
children: String(e)
|
|
328
356
|
})]
|
|
329
357
|
}, t))
|
|
330
358
|
}),
|
|
331
|
-
|
|
332
|
-
className: "
|
|
333
|
-
children: /* @__PURE__ */
|
|
334
|
-
|
|
335
|
-
|
|
359
|
+
l && /* @__PURE__ */ m("div", {
|
|
360
|
+
className: "flexi-filter-footer",
|
|
361
|
+
children: /* @__PURE__ */ m("button", {
|
|
362
|
+
type: "button",
|
|
363
|
+
onClick: () => me(r.key),
|
|
364
|
+
className: "flexi-filter-clear",
|
|
336
365
|
children: "Clear Filter"
|
|
337
366
|
})
|
|
338
367
|
})
|
|
339
368
|
]
|
|
340
|
-
})
|
|
369
|
+
}), G.current)
|
|
341
370
|
]
|
|
342
371
|
})
|
|
343
372
|
}, r.key);
|
|
344
373
|
}),
|
|
345
|
-
i === 0 &&
|
|
374
|
+
i === 0 && x && /* @__PURE__ */ m("th", {
|
|
346
375
|
rowSpan: q.length,
|
|
347
|
-
className: "
|
|
376
|
+
className: "flexi-actions-th",
|
|
348
377
|
style: {
|
|
349
378
|
position: "sticky",
|
|
350
379
|
right: 0,
|
|
@@ -355,23 +384,23 @@ function h({ columns: h, data: g, rowKey: _, actions: v, isLoading: ee, groupBy:
|
|
|
355
384
|
]
|
|
356
385
|
}, `header-row-${i}`))
|
|
357
386
|
}),
|
|
358
|
-
/* @__PURE__ */
|
|
359
|
-
className: "
|
|
360
|
-
children: ee ? /* @__PURE__ */
|
|
387
|
+
/* @__PURE__ */ m("tbody", {
|
|
388
|
+
className: "flexi-tbody",
|
|
389
|
+
children: ee ? /* @__PURE__ */ m("tr", { children: /* @__PURE__ */ m("td", {
|
|
361
390
|
colSpan: $,
|
|
362
|
-
className: "
|
|
391
|
+
className: "flexi-empty-cell",
|
|
363
392
|
children: "Loading records..."
|
|
364
|
-
}) }) : Z.length === 0 ? /* @__PURE__ */
|
|
393
|
+
}) }) : Z.length === 0 ? /* @__PURE__ */ m("tr", { children: /* @__PURE__ */ m("td", {
|
|
365
394
|
colSpan: $,
|
|
366
|
-
className: "
|
|
395
|
+
className: "flexi-empty-cell",
|
|
367
396
|
children: "No records found matching criteria."
|
|
368
397
|
}) }) : Z.map((e, t) => {
|
|
369
398
|
if (e.isGroupRow) {
|
|
370
|
-
let n =
|
|
371
|
-
return /* @__PURE__ */
|
|
372
|
-
className: "
|
|
373
|
-
children: [/* @__PURE__ */
|
|
374
|
-
className: "
|
|
399
|
+
let n = I[e.path] !== !1;
|
|
400
|
+
return /* @__PURE__ */ h("tr", {
|
|
401
|
+
className: "flexi-group-row",
|
|
402
|
+
children: [/* @__PURE__ */ m("td", {
|
|
403
|
+
className: "flexi-group-cell",
|
|
375
404
|
style: {
|
|
376
405
|
position: "sticky",
|
|
377
406
|
left: 0,
|
|
@@ -379,63 +408,64 @@ function h({ columns: h, data: g, rowKey: _, actions: v, isLoading: ee, groupBy:
|
|
|
379
408
|
backgroundColor: "rgba(248, 250, 252, 0.9)",
|
|
380
409
|
paddingLeft: `${e.depth * 12 + 16}px`
|
|
381
410
|
},
|
|
382
|
-
children: /* @__PURE__ */
|
|
383
|
-
|
|
384
|
-
|
|
411
|
+
children: /* @__PURE__ */ h("button", {
|
|
412
|
+
type: "button",
|
|
413
|
+
onClick: () => he(e.path),
|
|
414
|
+
className: "flexi-group-toggle",
|
|
385
415
|
children: [
|
|
386
|
-
|
|
387
|
-
/* @__PURE__ */
|
|
388
|
-
className: "
|
|
416
|
+
m(n ? r : i, { className: "flexi-icon-md flexi-icon-muted" }),
|
|
417
|
+
/* @__PURE__ */ m("span", {
|
|
418
|
+
className: "flexi-group-value",
|
|
389
419
|
children: e.groupValue
|
|
390
420
|
}),
|
|
391
|
-
/* @__PURE__ */
|
|
392
|
-
className: "
|
|
421
|
+
/* @__PURE__ */ m("span", {
|
|
422
|
+
className: "flexi-group-count",
|
|
393
423
|
children: e.totalItemsCount
|
|
394
424
|
})
|
|
395
425
|
]
|
|
396
426
|
})
|
|
397
|
-
}), /* @__PURE__ */
|
|
427
|
+
}), /* @__PURE__ */ m("td", {
|
|
398
428
|
colSpan: $ - 1,
|
|
399
|
-
className: "
|
|
429
|
+
className: "flexi-group-filler"
|
|
400
430
|
})]
|
|
401
431
|
}, `group-header-${e.path}-${t}`);
|
|
402
432
|
}
|
|
403
|
-
return /* @__PURE__ */
|
|
404
|
-
className: "
|
|
433
|
+
return /* @__PURE__ */ h("tr", {
|
|
434
|
+
className: "flexi-row",
|
|
405
435
|
children: [
|
|
406
|
-
|
|
407
|
-
className: "
|
|
436
|
+
S && P?.length > 0 && /* @__PURE__ */ m("td", {
|
|
437
|
+
className: "flexi-row-indent-cell",
|
|
408
438
|
style: {
|
|
409
439
|
position: "sticky",
|
|
410
440
|
left: 0,
|
|
411
441
|
zIndex: 10
|
|
412
442
|
}
|
|
413
443
|
}),
|
|
414
|
-
|
|
444
|
+
W?.map((t) => {
|
|
415
445
|
let n = e[t.key], r = Q(t.key, !1, t.style);
|
|
416
|
-
return /* @__PURE__ */
|
|
417
|
-
className:
|
|
446
|
+
return /* @__PURE__ */ m("td", {
|
|
447
|
+
className: _("flexi-cell", H.includes(t.key) && "flexi-cell--pinned", t.className),
|
|
418
448
|
style: r,
|
|
419
|
-
children: t.render ? t.render(n, e) : /* @__PURE__ */
|
|
420
|
-
className: "
|
|
449
|
+
children: t.render ? t.render(n, e) : /* @__PURE__ */ m("span", {
|
|
450
|
+
className: "flexi-cell-text",
|
|
421
451
|
children: n
|
|
422
452
|
})
|
|
423
453
|
}, t.key);
|
|
424
454
|
}),
|
|
425
|
-
|
|
426
|
-
className: "
|
|
455
|
+
x && /* @__PURE__ */ m("td", {
|
|
456
|
+
className: "flexi-actions-cell",
|
|
427
457
|
style: {
|
|
428
458
|
position: "sticky",
|
|
429
459
|
right: 0,
|
|
430
460
|
zIndex: 20
|
|
431
461
|
},
|
|
432
|
-
children: /* @__PURE__ */
|
|
433
|
-
className: "
|
|
434
|
-
children:
|
|
462
|
+
children: /* @__PURE__ */ m("div", {
|
|
463
|
+
className: "flexi-actions-inner",
|
|
464
|
+
children: x(e)
|
|
435
465
|
})
|
|
436
466
|
})
|
|
437
467
|
]
|
|
438
|
-
},
|
|
468
|
+
}, oe(e) ?? `row-${t}`);
|
|
439
469
|
})
|
|
440
470
|
})
|
|
441
471
|
]
|
|
@@ -444,4 +474,4 @@ function h({ columns: h, data: g, rowKey: _, actions: v, isLoading: ee, groupBy:
|
|
|
444
474
|
});
|
|
445
475
|
}
|
|
446
476
|
//#endregion
|
|
447
|
-
export {
|
|
477
|
+
export { v as DataTable };
|
package/dist/index.umd.js
CHANGED
|
@@ -1 +1 @@
|
|
|
1
|
-
(function(e,t){typeof exports==`object`&&typeof module<`u`?t(exports,require("lucide-react"),require("react"),require("react/jsx-runtime")):typeof define==`function`&&define.amd?define([`exports`,`lucide-react`,`react`,`react/jsx-runtime`],t):(e=typeof globalThis<`u`?globalThis:e||self,t(e.FlexiDataGrid={},e.LucideReact,e.React,e.JSX))})(this,function(e,t,n,r){Object.defineProperty(e,Symbol.toStringTag,{value:`Module`});var i=Object.create,a=Object.defineProperty,o=Object.getOwnPropertyDescriptor,s=Object.getOwnPropertyNames,c=Object.getPrototypeOf,l=Object.prototype.hasOwnProperty,u=(e,t,n,r)=>{if(t&&typeof t==`object`||typeof t==`function`)for(var i=s(t),c=0,u=i.length,d;c<u;c++)d=i[c],!l.call(e,d)&&d!==n&&a(e,d,{get:(e=>t[e]).bind(null,d),enumerable:!(r=o(t,d))||r.enumerable});return e};n=((e,t,n)=>(n=e==null?{}:i(c(e)),u(t||!e||!e.__esModule?a(n,`default`,{value:e,enumerable:!0}):n,e)))(n,1);var d=e=>{let t=[];return e.forEach(e=>{e.children&&e.children.length>0?t.push(...d(e.children)):t.push(e)}),t};function f({columns:e,data:i,rowKey:a,actions:o,isLoading:s,groupBy:c=!1,defaultGroupBy:l=[],onPinChange:u,onGroupChange:f,containerStyle:p,tableStyle:m}){let[h,g]=(0,n.useState)(null),[_,v]=(0,n.useState)({}),[y,b]=(0,n.useState)(``),[x,S]=(0,n.useState)(l),[C,w]=(0,n.useState)({}),[T,E]=(0,n.useState)(!1),[D,O]=(0,n.useState)({key:null,direction:null}),k=(0,n.useMemo)(()=>d(e),[e]),[A,j]=(0,n.useState)(k.filter(e=>e.pinned).map(e=>e.key)),M=(0,n.useMemo)(()=>{let t=e=>[...e].sort((e,t)=>{let n=A.includes(e.key),r=A.includes(t.key);return n&&!r?-1:!n&&r?1:0}).map(e=>e.children&&e.children.length>0?{...e,children:t(e.children)}:e);return t(e)},[e,A]),N=(0,n.useMemo)(()=>{let e=d(M),t=c?x:[];return e.filter(e=>!t.includes(e.key))},[M,x,c]),P=(0,n.useRef)(null);(0,n.useEffect)(()=>{function e(e){P.current&&!P.current.contains(e.target)&&(g(null),b(``))}return document.addEventListener(`mousedown`,e),()=>document.removeEventListener(`mousedown`,e)},[]);let F=e=>typeof a==`function`?a(e):String(e[a]),I=e=>{let t=A.includes(e);j(t?A.filter(t=>t!==e):[...A,e]),u&&u(e,!t)},L=e=>{let t=`asc`;D.key===e&&(t=D.direction===`asc`?`desc`:D.direction===`desc`?null:`asc`),O({key:t?e:null,direction:t})},R=(e,t)=>{c&&(e.dataTransfer.setData(`text/plain`,t),e.dataTransfer.effectAllowed=`move`)},z=e=>{e.preventDefault(),E(!1);let t=e.dataTransfer.getData(`text/plain`);if(t&&!x.includes(t)){let e=[...x,t];S(e),f&&f(e)}},B=e=>{let t=x.filter(t=>t!==e);S(t),w({}),f&&f(t)},V=(0,n.useMemo)(()=>{let e=t=>{let n=0;return t.forEach(t=>{n=t.children&&t.children.length>0?Math.max(n,1+e(t.children)):Math.max(n,1)}),n},t=e(M),n=Array.from({length:t},()=>[]),r=e=>!e.children||e.children.length===0?x.includes(e.key)&&c?0:1:e.children.reduce((e,t)=>e+r(t),0),i=c?x:[],a=(e,o)=>{e.forEach(e=>{if(i.includes(e.key))return;let s=r(e);s!==0&&(e.children&&e.children.length>0?(n[o].push({col:e,rowSpan:1,colSpan:s}),a(e.children,o+1)):n[o].push({col:e,rowSpan:t-o,colSpan:1}))})};return a(M,0),n.filter(e=>e.length>0)},[M,x,c]),H=(0,n.useMemo)(()=>{let e={},t=0;return c&&x.length>0&&(t+=48),N.forEach(n=>{if(A.includes(n.key)){e[n.key]=t;let r=n.style?.width||n.headerStyle?.width||`150px`;t+=typeof r==`number`?r:parseInt(String(r),10)||150}}),e},[N,A,x,c]),U=(e,t)=>{v(n=>{let r=n[e]||[],i=r.includes(t)?r.filter(e=>e!==t):[...r,t],a={...n,[e]:i};return a[e].length===0&&delete a[e],a})},W=e=>{v(t=>{let n={...t};return delete n[e],n})},G=(0,n.useMemo)(()=>{if(!h)return[];let e=k.find(e=>e.key===h),t=i.map(t=>e?.getValue?e.getValue(t):t[h]),n=Array.from(new Set(t)).filter(e=>e!=null);return y.trim()?n.filter(e=>String(e).toLowerCase().includes(y.toLowerCase())):n},[i,h,y,k]),K=(0,n.useMemo)(()=>{let e=i.filter(e=>Object.entries(_).every(([t,n])=>{if(!n||n.length===0)return!0;let r=k.find(e=>e.key===t),i=r?.getValue?r.getValue(e):e[t];return n.includes(i)}));if(D.key&&D.direction){let{key:t,direction:n}=D,r=k.find(e=>e.key===t);e=[...e].sort((e,i)=>{let a=r?.getValue?r.getValue(e):e[t],o=r?.getValue?r.getValue(i):i[t];if(a===o)return 0;if(a==null)return 1;if(o==null)return-1;let s=0;return s=typeof a==`number`&&typeof o==`number`?a-o:String(a).localeCompare(String(o),void 0,{numeric:!0,sensitivity:`base`}),n===`asc`?s:-s})}return e},[i,_,D,k]),q=(0,n.useMemo)(()=>{if(!c||x.length===0)return K;let e=(t,n,r=``)=>{if(n>=x.length)return t;let i=x[n],a=k.find(e=>e.key===i),o={};return t.forEach(e=>{let t=a?.getValue?a.getValue(e):e[i],n=String(t??`N/A`);o[n]||(o[n]=[]),o[n].push(e)}),Object.entries(o).map(([t,a])=>{let o=r?`${r}➔${t}`:t;return{isGroupRow:!0,groupKey:i,groupValue:t,path:o,depth:n,children:e(a,n+1,o),totalItemsCount:a.length}})};return e(K,0)},[K,x,c,k]),J=e=>{w(t=>{let n=t[e]!==!1;return{...t,[e]:!n}})},Y=(0,n.useMemo)(()=>{if(!c||x.length===0)return q;let e=[],t=n=>{n.forEach(n=>{n.isGroupRow?(e.push(n),C[n.path]!==!1&&t(n.children)):e.push(n)})};return t(q),e},[q,C,x,c]),X=(e,t=!1,n)=>A.includes(e)?{position:`sticky`,left:`${H[e]}px`,zIndex:t?30:20,backgroundColor:`#fff`,boxShadow:`2px 0 5px -2px rgba(0,0,0,0.1)`,...n}:n||{},Z=N.length+ +!!o+(c&&x.length>0?1:0);return(0,r.jsxs)(`div`,{className:`w-full space-y-3`,children:[c&&(0,r.jsx)(`div`,{onDragOver:e=>{e.preventDefault(),E(!0)},onDragLeave:()=>E(!1),onDrop:z,className:`w-full min-h-[52px] px-4 py-2 border rounded-xl flex items-center gap-2 transition-all duration-200 ${T?`border-blue-500 bg-blue-50/50 scale-[0.99]`:`border-dashed border-slate-200 bg-slate-50/50`}`,children:x.length===0?(0,r.jsx)(`span`,{className:`text-[12px] text-muted-foreground font-medium select-none`,children:`Drag a column header here to group your records by that field`}):(0,r.jsxs)(`div`,{className:`flex flex-wrap items-center gap-1.5`,children:[(0,r.jsx)(`span`,{className:`text-[11px] font-bold uppercase tracking-wider text-muted-foreground mr-1`,children:`Grouped By:`}),x.map(e=>(0,r.jsxs)(`div`,{className:`flex items-center gap-1.5 pl-2 pr-1 py-1 bg-white border border-slate-200 rounded-lg shadow-sm text-[12px] font-semibold text-muted-foreground`,children:[(0,r.jsx)(`span`,{children:k.find(t=>t.key===e)?.header||e}),(0,r.jsx)(`button`,{onClick:()=>B(e),className:`p-0.5 rounded-md hover:bg-slate-100 text-muted-foreground transition-colors`,children:(0,r.jsx)(t.X,{className:`w-3 h-3`})})]},e))]})}),(0,r.jsx)(`div`,{className:`w-full overflow-x-auto border border-slate-100 rounded-xl bg-white shadow-sm`,style:p,children:(0,r.jsxs)(`table`,{className:`w-full caption-bottom text-sm border-collapse table-fixed`,style:m,children:[(0,r.jsxs)(`colgroup`,{children:[c&&x.length>0&&(0,r.jsx)(`col`,{style:{width:`48px`}}),N.map(e=>(0,r.jsx)(`col`,{style:e.style},e.key)),o&&(0,r.jsx)(`col`,{style:{width:`100px`}})]}),(0,r.jsx)(`thead`,{className:`bg-slate-50 select-none`,children:V.map((e,n)=>(0,r.jsxs)(`tr`,{className:`border-b border-slate-100`,children:[n===0&&c&&x.length>0&&(0,r.jsx)(`th`,{rowSpan:V.length,className:`w-12 border-r border-slate-100`,style:{position:`sticky`,left:0,zIndex:35,backgroundColor:`rgb(248, 250, 252)`}}),e.map(({col:e,rowSpan:n,colSpan:i})=>{let a=(_[e.key]?.length||0)>0,o=A.includes(e.key),s=X(e.key,!0,e.headerStyle),l=!e.children||e.children.length===0,u=D.key===e.key;return(0,r.jsx)(`th`,{rowSpan:n,colSpan:i,...c&&l?{draggable:!0,onDragStart:t=>R(t,e.key)}:{},className:`h-12 text-center align-middle font-bold text-[12px] px-4 border-r border-b border-slate-100 relative ${c&&l?`cursor-grab active:cursor-grabbing`:``} ${o?`bg-slate-50/90`:``} ${e.className||``}`,style:s,children:(0,r.jsxs)(`div`,{className:`flex items-center gap-1 group/header w-full justify-between`,children:[(0,r.jsxs)(`div`,{className:`flex items-center gap-1.5 truncate w-full ${e.sortable&&l?`cursor-pointer select-none hover:text-blue-600`:``}`,onClick:()=>e.sortable&&l&&L(e.key),children:[(0,r.jsx)(`span`,{className:`truncate`,children:e.header}),l&&e.sortable&&(0,r.jsx)(`span`,{className:`text-slate-400 transition-colors ${u?`text-blue-600`:`opacity-0 group-hover/header:opacity-100`}`,children:u&&D.direction===`asc`?(0,r.jsx)(t.ArrowUp,{className:`w-3.5 h-3.5`}):u&&D.direction===`desc`?(0,r.jsx)(t.ArrowDown,{className:`w-3.5 h-3.5`}):(0,r.jsx)(t.ArrowUpDown,{className:`w-3.5 h-3.5`})})]}),(0,r.jsxs)(`div`,{className:`flex items-center gap-1`,children:[l&&e.filterable&&(0,r.jsx)(`button`,{onClick:t=>{t.stopPropagation(),b(``),g(h===e.key?null:e.key)},className:`p-0.5 rounded hover:bg-slate-200 transition-colors ${a?`text-blue-600`:`text-muted-foreground opacity-0 group-hover/header:opacity-100`}`,children:`Filter`}),l&&(0,r.jsx)(`button`,{onClick:t=>{t.stopPropagation(),I(e.key)},className:`p-0.5 rounded hover:bg-slate-200 transition-colors opacity-0 group-hover/header:opacity-100 ${o?`text-blue-500 opacity-100`:`text-slate-300`}`,title:o?`Unpin column`:`Pin column`,children:o?(0,r.jsx)(t.PinOff,{className:`w-3.5 h-3.5`}):(0,r.jsx)(t.Pin,{className:`w-3.5 h-3.5`})})]}),h===e.key&&l&&(0,r.jsxs)(`div`,{ref:P,className:`absolute left-4 top-10 z-50 w-52 bg-white border border-slate-200 rounded-lg shadow-lg py-2 flex flex-col font-normal text-slate-700 text-left`,children:[(0,r.jsx)(`div`,{className:`px-2 pb-2 mb-1 border-b border-slate-100`,children:(0,r.jsx)(`input`,{type:`text`,placeholder:`Search values...`,value:y,onChange:e=>b(e.target.value),className:`w-full px-2 py-1 text-[12px] border border-slate-200 rounded focus:outline-none focus:border-blue-500 font-medium text-slate-600`,onClick:e=>e.stopPropagation()})}),(0,r.jsx)(`div`,{className:`max-h-40 overflow-y-auto px-2 space-y-1`,children:G.length===0?(0,r.jsx)(`div`,{className:`text-[11px] text-muted-foreground p-2 text-center`,children:`No results found`}):G.map((t,n)=>(0,r.jsxs)(`label`,{className:`flex items-center gap-2 px-2 py-1.5 text-[12px] rounded hover:bg-slate-50 cursor-pointer select-none`,children:[(0,r.jsx)(`input`,{type:`checkbox`,className:`rounded border-slate-300 text-blue-600 focus:ring-blue-500 w-3.5 h-3.5`,checked:_[e.key]?.includes(t)||!1,onChange:()=>U(e.key,t)}),(0,r.jsx)(`span`,{className:`truncate`,children:String(t)})]},n))}),a&&(0,r.jsx)(`div`,{className:`border-t border-slate-100 mt-2 pt-1 px-2 flex justify-end`,children:(0,r.jsx)(`button`,{onClick:()=>W(e.key),className:`text-[11px] text-red-500 hover:underline font-medium px-2 py-0.5`,children:`Clear Filter`})})]})]})},e.key)}),n===0&&o&&(0,r.jsx)(`th`,{rowSpan:V.length,className:`h-12 align-middle font-bold text-[12px] px-4 text-right shadow-[-1px_0_0_rgba(226,232,240,1)]`,style:{position:`sticky`,right:0,zIndex:35,backgroundColor:`rgb(248, 250, 252)`}})]},`header-row-${n}`))}),(0,r.jsx)(`tbody`,{className:`divide-y divide-slate-100`,children:s?(0,r.jsx)(`tr`,{children:(0,r.jsx)(`td`,{colSpan:Z,className:`p-8 text-center text-muted-foreground text-[12px] font-medium`,children:`Loading records...`})}):Y.length===0?(0,r.jsx)(`tr`,{children:(0,r.jsx)(`td`,{colSpan:Z,className:`p-8 text-center text-muted-foreground text-[12px] font-medium`,children:`No records found matching criteria.`})}):Y.map((e,n)=>{if(e.isGroupRow){let i=C[e.path]!==!1;return(0,r.jsxs)(`tr`,{className:`bg-slate-50/60 hover:bg-slate-100/80 transition-colors select-none`,children:[(0,r.jsx)(`td`,{className:`p-3 pl-4 font-semibold text-slate-700 text-[12px] border-r border-slate-100`,style:{position:`sticky`,left:0,zIndex:20,backgroundColor:`rgba(248, 250, 252, 0.9)`,paddingLeft:`${e.depth*12+16}px`},children:(0,r.jsxs)(`button`,{onClick:()=>J(e.path),className:`flex items-center gap-1.5 text-left focus:outline-none focus:ring-1 focus:ring-blue-400 rounded p-0.5`,children:[i?(0,r.jsx)(t.ChevronDown,{className:`w-4 h-4 text-slate-500`}):(0,r.jsx)(t.ChevronRight,{className:`w-4 h-4 text-slate-500`}),(0,r.jsx)(`span`,{className:`text-slate-800 font-bold w-40 truncate`,children:e.groupValue}),(0,r.jsx)(`span`,{className:`bg-slate-200/70 text-muted-foreground font-medium text-[10px] px-1.5 py-0.2 rounded-full ml-1`,children:e.totalItemsCount})]})}),(0,r.jsx)(`td`,{colSpan:Z-1,className:`bg-slate-50/30`})]},`group-header-${e.path}-${n}`)}return(0,r.jsxs)(`tr`,{className:`border-b border-slate-100 h-12 hover:bg-slate-50/80 transition-colors group`,children:[c&&x?.length>0&&(0,r.jsx)(`td`,{className:`w-12 bg-white border-r border-slate-100`,style:{position:`sticky`,left:0,zIndex:10}}),N?.map(t=>{let n=e[t.key],i=X(t.key,!1,t.style);return(0,r.jsx)(`td`,{className:`p-4 align-middle py-1 px-4 transition-colors ${A.includes(t.key)?`group-hover:bg-slate-100`:``} ${t.className||``}`,style:i,children:t.render?t.render(n,e):(0,r.jsx)(`span`,{className:`text-[12px] text-muted-foreground font-medium truncate block`,children:n})},t.key)}),o&&(0,r.jsx)(`td`,{className:`p-4 align-middle py-1 px-4 text-right bg-white shadow-[-1px_0_0_rgba(226,232,240,1)] group-hover:bg-slate-50/80`,style:{position:`sticky`,right:0,zIndex:20},children:(0,r.jsx)(`div`,{className:`flex justify-end gap-1 opacity-0 group-hover:opacity-100 transition-opacity duration-150`,children:o(e)})})]},F(e)??`row-${n}`)})})]})})]})}e.DataTable=f});
|
|
1
|
+
(function(e,t){typeof exports==`object`&&typeof module<`u`?t(exports,require("lucide-react"),require("react"),require("react-dom"),require("react/jsx-runtime")):typeof define==`function`&&define.amd?define([`exports`,`lucide-react`,`react`,`react-dom`,`react/jsx-runtime`],t):(e=typeof globalThis<`u`?globalThis:e||self,t(e.FlexiDataGrid={},e.LucideReact,e.React,e.ReactDOM,e.JSX))})(this,function(e,t,n,r,i){Object.defineProperty(e,Symbol.toStringTag,{value:`Module`});var a=Object.create,o=Object.defineProperty,s=Object.getOwnPropertyDescriptor,c=Object.getOwnPropertyNames,l=Object.getPrototypeOf,u=Object.prototype.hasOwnProperty,d=(e,t,n,r)=>{if(t&&typeof t==`object`||typeof t==`function`)for(var i=c(t),a=0,l=i.length,d;a<l;a++)d=i[a],!u.call(e,d)&&d!==n&&o(e,d,{get:(e=>t[e]).bind(null,d),enumerable:!(r=s(t,d))||r.enumerable});return e};n=((e,t,n)=>(n=e==null?{}:a(l(e)),d(t||!e||!e.__esModule?o(n,`default`,{value:e,enumerable:!0}):n,e)))(n,1);var f=e=>{let t=[];return e.forEach(e=>{e.children&&e.children.length>0?t.push(...f(e.children)):t.push(e)}),t},p=(...e)=>e.filter(Boolean).join(` `);function m({columns:e,data:a,rowKey:o,actions:s,isLoading:c,groupBy:l=!1,defaultGroupBy:u=[],onPinChange:d,onGroupChange:m,containerStyle:h,tableStyle:g}){let[_,v]=(0,n.useState)(null),[y,b]=(0,n.useState)({}),[x,S]=(0,n.useState)(``),[C,w]=(0,n.useState)(null),T=(0,n.useRef)(new Map),[E,D]=(0,n.useState)(u),[O,k]=(0,n.useState)({}),[A,j]=(0,n.useState)(!1),[M,N]=(0,n.useState)({key:null,direction:null}),P=(0,n.useMemo)(()=>f(e),[e]),[F,I]=(0,n.useState)(P.filter(e=>e.pinned).map(e=>e.key)),L=(0,n.useMemo)(()=>{let t=e=>[...e].sort((e,t)=>{let n=F.includes(e.key),r=F.includes(t.key);return n&&!r?-1:!n&&r?1:0}).map(e=>e.children&&e.children.length>0?{...e,children:t(e.children)}:e);return t(e)},[e,F]),R=(0,n.useMemo)(()=>{let e=f(L),t=l?E:[];return e.filter(e=>!t.includes(e.key))},[L,E,l]),z=(0,n.useRef)(null),B=(0,n.useRef)(null);(0,n.useEffect)(()=>{function e(e){let t=e.target,n=_?T.current.get(_):null;B.current&&!B.current.contains(t)&&!(n&&n.contains(t))&&(v(null),S(``))}return document.addEventListener(`mousedown`,e),()=>document.removeEventListener(`mousedown`,e)},[_]),(0,n.useEffect)(()=>{if(!_)return;let e=()=>{let e=T.current.get(_),t=z.current;if(!e||!t)return;let n=e.getBoundingClientRect(),r=t.getBoundingClientRect();w({top:n.bottom-r.top+4,left:n.left-r.left})};return e(),window.addEventListener(`scroll`,e,!0),window.addEventListener(`resize`,e),()=>{window.removeEventListener(`scroll`,e,!0),window.removeEventListener(`resize`,e)}},[_]);let V=e=>typeof o==`function`?o(e):String(e[o]),H=e=>{let t=F.includes(e);I(t?F.filter(t=>t!==e):[...F,e]),d&&d(e,!t)},U=e=>{let t=`asc`;M.key===e&&(t=M.direction===`asc`?`desc`:M.direction===`desc`?null:`asc`),N({key:t?e:null,direction:t})},W=(e,t)=>{l&&(e.dataTransfer.setData(`text/plain`,t),e.dataTransfer.effectAllowed=`move`)},G=e=>{e.preventDefault(),j(!1);let t=e.dataTransfer.getData(`text/plain`);if(t&&!E.includes(t)){let e=[...E,t];D(e),m&&m(e)}},K=e=>{let t=E.filter(t=>t!==e);D(t),k({}),m&&m(t)},q=(0,n.useMemo)(()=>{let e=t=>{let n=0;return t.forEach(t=>{n=t.children&&t.children.length>0?Math.max(n,1+e(t.children)):Math.max(n,1)}),n},t=e(L),n=Array.from({length:t},()=>[]),r=e=>!e.children||e.children.length===0?E.includes(e.key)&&l?0:1:e.children.reduce((e,t)=>e+r(t),0),i=l?E:[],a=(e,o)=>{e.forEach(e=>{if(i.includes(e.key))return;let s=r(e);s!==0&&(e.children&&e.children.length>0?(n[o].push({col:e,rowSpan:1,colSpan:s}),a(e.children,o+1)):n[o].push({col:e,rowSpan:t-o,colSpan:1}))})};return a(L,0),n.filter(e=>e.length>0)},[L,E,l]),ee=(0,n.useMemo)(()=>{let e={},t=0;return l&&E.length>0&&(t+=48),R.forEach(n=>{if(F.includes(n.key)){e[n.key]=t;let r=n.style?.width||n.headerStyle?.width||`150px`;t+=typeof r==`number`?r:parseInt(String(r),10)||150}}),e},[R,F,E,l]),te=(e,t)=>{b(n=>{let r=n[e]||[],i=r.includes(t)?r.filter(e=>e!==t):[...r,t],a={...n,[e]:i};return a[e].length===0&&delete a[e],a})},ne=e=>{b(t=>{let n={...t};return delete n[e],n})},J=(0,n.useMemo)(()=>{if(!_)return[];let e=P.find(e=>e.key===_),t=a.map(t=>e?.getValue?e.getValue(t):t[_]),n=Array.from(new Set(t)).filter(e=>e!=null);return x.trim()?n.filter(e=>String(e).toLowerCase().includes(x.toLowerCase())):n},[a,_,x,P]),Y=(0,n.useMemo)(()=>{let e=a.filter(e=>Object.entries(y).every(([t,n])=>{if(!n||n.length===0)return!0;let r=P.find(e=>e.key===t),i=r?.getValue?r.getValue(e):e[t];return n.includes(i)}));if(M.key&&M.direction){let{key:t,direction:n}=M,r=P.find(e=>e.key===t);e=[...e].sort((e,i)=>{let a=r?.getValue?r.getValue(e):e[t],o=r?.getValue?r.getValue(i):i[t];if(a===o)return 0;if(a==null)return 1;if(o==null)return-1;let s=0;return s=typeof a==`number`&&typeof o==`number`?a-o:String(a).localeCompare(String(o),void 0,{numeric:!0,sensitivity:`base`}),n===`asc`?s:-s})}return e},[a,y,M,P]),X=(0,n.useMemo)(()=>{if(!l||E.length===0)return Y;let e=(t,n,r=``)=>{if(n>=E.length)return t;let i=E[n],a=P.find(e=>e.key===i),o={};return t.forEach(e=>{let t=a?.getValue?a.getValue(e):e[i],n=String(t??`N/A`);o[n]||(o[n]=[]),o[n].push(e)}),Object.entries(o).map(([t,a])=>{let o=r?`${r}➔${t}`:t;return{isGroupRow:!0,groupKey:i,groupValue:t,path:o,depth:n,children:e(a,n+1,o),totalItemsCount:a.length}})};return e(Y,0)},[Y,E,l,P]),re=e=>{k(t=>{let n=t[e]!==!1;return{...t,[e]:!n}})},Z=(0,n.useMemo)(()=>{if(!l||E.length===0)return X;let e=[],t=n=>{n.forEach(n=>{n.isGroupRow?(e.push(n),O[n.path]!==!1&&t(n.children)):e.push(n)})};return t(X),e},[X,O,E,l]),Q=(e,t=!1,n)=>F.includes(e)?{position:`sticky`,left:`${ee[e]}px`,zIndex:t?30:20,backgroundColor:`#fff`,boxShadow:`2px 0 5px -2px rgba(0,0,0,0.1)`,...n}:n||{},$=R.length+ +!!s+(l&&E.length>0?1:0);return(0,i.jsxs)(`div`,{ref:z,className:`flexi-root`,children:[l&&(0,i.jsx)(`div`,{onDragOver:e=>{e.preventDefault(),j(!0)},onDragLeave:()=>j(!1),onDrop:G,className:p(`flexi-groupzone`,A&&`flexi-groupzone--dragover`),children:E.length===0?(0,i.jsx)(`span`,{className:`flexi-groupzone-hint`,children:`Drag a column header here to group your records by that field`}):(0,i.jsxs)(`div`,{className:`flexi-groupzone-chips`,children:[(0,i.jsx)(`span`,{className:`flexi-groupzone-label`,children:`Grouped By:`}),E.map(e=>(0,i.jsxs)(`div`,{className:`flexi-chip`,children:[(0,i.jsx)(`span`,{children:P.find(t=>t.key===e)?.header||e}),(0,i.jsx)(`button`,{type:`button`,onClick:()=>K(e),className:`flexi-icon-btn flexi-chip-remove`,children:(0,i.jsx)(t.X,{className:`flexi-icon-xs`})})]},e))]})}),(0,i.jsx)(`div`,{className:`flexi-table-wrap`,style:h,children:(0,i.jsxs)(`table`,{className:`flexi-table`,style:g,children:[(0,i.jsxs)(`colgroup`,{children:[l&&E.length>0&&(0,i.jsx)(`col`,{style:{width:`48px`}}),R.map(e=>(0,i.jsx)(`col`,{style:e.style},e.key)),s&&(0,i.jsx)(`col`,{style:{width:`100px`}})]}),(0,i.jsx)(`thead`,{className:`flexi-thead`,children:q.map((e,n)=>(0,i.jsxs)(`tr`,{className:`flexi-header-row`,children:[n===0&&l&&E.length>0&&(0,i.jsx)(`th`,{rowSpan:q.length,className:`flexi-group-spacer-th`,style:{position:`sticky`,left:0,zIndex:35,backgroundColor:`rgb(248, 250, 252)`}}),e.map(({col:e,rowSpan:n,colSpan:a})=>{let o=(y[e.key]?.length||0)>0,s=F.includes(e.key),c=Q(e.key,!0,e.headerStyle),u=!e.children||e.children.length===0,d=M.key===e.key,f=!!(l&&u);return(0,i.jsx)(`th`,{rowSpan:n,colSpan:a,...f?{draggable:!0,onDragStart:t=>W(t,e.key)}:{},className:p(`flexi-th`,f&&`flexi-th--draggable`,s&&`flexi-th--pinned`,e.className),style:c,children:(0,i.jsxs)(`div`,{className:`flexi-th-inner`,children:[(0,i.jsxs)(`div`,{className:p(`flexi-th-label`,e.sortable&&u&&`flexi-th-label--sortable`),onClick:()=>e.sortable&&u&&U(e.key),children:[(0,i.jsx)(`span`,{className:`flexi-th-text`,children:e.header}),u&&e.sortable&&(0,i.jsx)(`span`,{className:p(`flexi-sort-icon`,d&&`flexi-sort-icon--active`),children:d&&M.direction===`asc`?(0,i.jsx)(t.ArrowUp,{className:`flexi-icon-sm`}):d&&M.direction===`desc`?(0,i.jsx)(t.ArrowDown,{className:`flexi-icon-sm`}):(0,i.jsx)(t.ArrowUpDown,{className:`flexi-icon-sm`})})]}),(0,i.jsxs)(`div`,{className:`flexi-th-actions`,children:[u&&e.filterable&&(0,i.jsx)(`button`,{type:`button`,ref:t=>{t?T.current.set(e.key,t):T.current.delete(e.key)},onClick:t=>{t.stopPropagation(),S(``),v(_===e.key?null:e.key)},className:p(`flexi-icon-btn`,`flexi-filter-btn`,o&&`flexi-filter-btn--active`),children:(0,i.jsx)(t.Filter,{className:`flexi-icon-sm`})}),u&&(0,i.jsx)(`button`,{type:`button`,onClick:t=>{t.stopPropagation(),H(e.key)},className:p(`flexi-icon-btn`,`flexi-pin-btn`,s&&`flexi-pin-btn--pinned`),title:s?`Unpin column`:`Pin column`,children:s?(0,i.jsx)(t.PinOff,{className:`flexi-icon-sm`}):(0,i.jsx)(t.Pin,{className:`flexi-icon-sm`})})]}),_===e.key&&u&&C&&z.current&&(0,r.createPortal)((0,i.jsxs)(`div`,{ref:B,className:`flexi-filter-dropdown`,style:{top:C.top,left:C.left,zIndex:9999},children:[(0,i.jsx)(`div`,{className:`flexi-filter-search`,children:(0,i.jsx)(`input`,{type:`text`,placeholder:`Search values...`,value:x,onChange:e=>S(e.target.value),className:`flexi-input`,onClick:e=>e.stopPropagation()})}),(0,i.jsx)(`div`,{className:`flexi-filter-list`,children:J.length===0?(0,i.jsx)(`div`,{className:`flexi-filter-empty`,children:`No results found`}):J.map((t,n)=>(0,i.jsxs)(`label`,{className:`flexi-filter-option`,children:[(0,i.jsx)(`input`,{type:`checkbox`,className:`flexi-checkbox`,checked:y[e.key]?.includes(t)||!1,onChange:()=>te(e.key,t)}),(0,i.jsx)(`span`,{className:`flexi-filter-option-text`,children:String(t)})]},n))}),o&&(0,i.jsx)(`div`,{className:`flexi-filter-footer`,children:(0,i.jsx)(`button`,{type:`button`,onClick:()=>ne(e.key),className:`flexi-filter-clear`,children:`Clear Filter`})})]}),z.current)]})},e.key)}),n===0&&s&&(0,i.jsx)(`th`,{rowSpan:q.length,className:`flexi-actions-th`,style:{position:`sticky`,right:0,zIndex:35,backgroundColor:`rgb(248, 250, 252)`}})]},`header-row-${n}`))}),(0,i.jsx)(`tbody`,{className:`flexi-tbody`,children:c?(0,i.jsx)(`tr`,{children:(0,i.jsx)(`td`,{colSpan:$,className:`flexi-empty-cell`,children:`Loading records...`})}):Z.length===0?(0,i.jsx)(`tr`,{children:(0,i.jsx)(`td`,{colSpan:$,className:`flexi-empty-cell`,children:`No records found matching criteria.`})}):Z.map((e,n)=>{if(e.isGroupRow){let r=O[e.path]!==!1;return(0,i.jsxs)(`tr`,{className:`flexi-group-row`,children:[(0,i.jsx)(`td`,{className:`flexi-group-cell`,style:{position:`sticky`,left:0,zIndex:20,backgroundColor:`rgba(248, 250, 252, 0.9)`,paddingLeft:`${e.depth*12+16}px`},children:(0,i.jsxs)(`button`,{type:`button`,onClick:()=>re(e.path),className:`flexi-group-toggle`,children:[r?(0,i.jsx)(t.ChevronDown,{className:`flexi-icon-md flexi-icon-muted`}):(0,i.jsx)(t.ChevronRight,{className:`flexi-icon-md flexi-icon-muted`}),(0,i.jsx)(`span`,{className:`flexi-group-value`,children:e.groupValue}),(0,i.jsx)(`span`,{className:`flexi-group-count`,children:e.totalItemsCount})]})}),(0,i.jsx)(`td`,{colSpan:$-1,className:`flexi-group-filler`})]},`group-header-${e.path}-${n}`)}return(0,i.jsxs)(`tr`,{className:`flexi-row`,children:[l&&E?.length>0&&(0,i.jsx)(`td`,{className:`flexi-row-indent-cell`,style:{position:`sticky`,left:0,zIndex:10}}),R?.map(t=>{let n=e[t.key],r=Q(t.key,!1,t.style);return(0,i.jsx)(`td`,{className:p(`flexi-cell`,F.includes(t.key)&&`flexi-cell--pinned`,t.className),style:r,children:t.render?t.render(n,e):(0,i.jsx)(`span`,{className:`flexi-cell-text`,children:n})},t.key)}),s&&(0,i.jsx)(`td`,{className:`flexi-actions-cell`,style:{position:`sticky`,right:0,zIndex:20},children:(0,i.jsx)(`div`,{className:`flexi-actions-inner`,children:s(e)})})]},V(e)??`row-${n}`)})})]})})]})}e.DataTable=m});
|
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "flexi-datagrid",
|
|
3
|
-
"version": "1.1
|
|
3
|
+
"version": "1.2.1",
|
|
4
4
|
"description": "A powerful universal datagrid with tree-grouping, column pinning, and drag-and-drop.",
|
|
5
5
|
"type": "module",
|
|
6
6
|
"main": "./dist/index.umd.js",
|
|
@@ -46,7 +46,6 @@
|
|
|
46
46
|
"@vitejs/plugin-react": "^4.3.4",
|
|
47
47
|
"autoprefixer": "^10.4.20",
|
|
48
48
|
"postcss": "^8.5.1",
|
|
49
|
-
"tailwindcss": "^3.4.17",
|
|
50
49
|
"typescript": "^6.0.3",
|
|
51
50
|
"vite": "^8.0.16",
|
|
52
51
|
"vite-plugin-dts": "^4.5.0",
|