@react-fabric/data 1.0.0-beta.6 → 1.0.0-beta.61

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.
Files changed (104) hide show
  1. package/{src/histogram/Histogram.module.css → css/_histogram.css} +16 -13
  2. package/{dist/esm/tree/types.js → css/styles.css} +2 -7
  3. package/dist/cjs/checklist/CheckList.js +27 -4
  4. package/dist/cjs/histogram/Histogram.js +39 -9
  5. package/dist/cjs/hooks/useFilteredList.js +88 -10
  6. package/dist/cjs/hooks/usePagination.js +27 -4
  7. package/dist/cjs/hooks/useSelectableList.js +29 -0
  8. package/dist/cjs/i18n/ar.json.js +8 -1
  9. package/dist/cjs/i18n/en.json.js +8 -1
  10. package/dist/cjs/json/JsonViewer.js +68 -28
  11. package/dist/cjs/pagination/Pagination.js +14 -4
  12. package/dist/cjs/table/AddColumn.js +3 -3
  13. package/dist/cjs/table/BodyCell.js +14 -6
  14. package/dist/cjs/table/BodyRow.js +4 -4
  15. package/dist/cjs/table/CheckboxCell.js +2 -2
  16. package/dist/cjs/table/ColumnFilters.js +97 -0
  17. package/dist/cjs/table/HeaderCell.js +71 -43
  18. package/dist/cjs/table/Table.js +62 -13
  19. package/dist/cjs/table/types.js +29 -0
  20. package/dist/cjs/table/useResizer.js +4 -4
  21. package/dist/cjs/table/useVirtualTable.js +127 -19
  22. package/dist/cjs/tree/TreeNode.js +50 -32
  23. package/dist/cjs/tree/TreePanel.js +52 -19
  24. package/dist/cjs/tree/useTree.js +199 -38
  25. package/dist/cjs/tree/utils.js +39 -12
  26. package/dist/cjs/virtual/Gallery.js +97 -45
  27. package/dist/cjs/virtual/List.js +93 -39
  28. package/dist/cjs/virtual/Scroller.js +16 -8
  29. package/dist/esm/checklist/CheckList.js +28 -5
  30. package/dist/esm/histogram/Histogram.js +41 -11
  31. package/dist/esm/hooks/useFilteredList.js +89 -11
  32. package/dist/esm/hooks/usePagination.js +27 -4
  33. package/dist/esm/hooks/useSelectableList.js +29 -0
  34. package/dist/esm/i18n/ar.json.js +8 -2
  35. package/dist/esm/i18n/en.json.js +8 -2
  36. package/dist/esm/json/JsonViewer.js +69 -29
  37. package/dist/esm/pagination/Pagination.js +15 -5
  38. package/dist/esm/table/AddColumn.js +4 -4
  39. package/dist/esm/table/BodyCell.js +15 -7
  40. package/dist/esm/table/BodyRow.js +4 -4
  41. package/dist/esm/table/CheckboxCell.js +3 -3
  42. package/dist/esm/table/ColumnFilters.js +97 -0
  43. package/dist/esm/table/HeaderCell.js +72 -44
  44. package/dist/esm/table/Table.js +63 -14
  45. package/dist/esm/table/types.js +29 -0
  46. package/dist/esm/table/useResizer.js +4 -4
  47. package/dist/esm/table/useVirtualTable.js +129 -21
  48. package/dist/esm/tree/TreeNode.js +53 -35
  49. package/dist/esm/tree/TreePanel.js +54 -21
  50. package/dist/esm/tree/useTree.js +202 -41
  51. package/dist/esm/tree/utils.js +40 -13
  52. package/dist/esm/virtual/Gallery.js +97 -45
  53. package/dist/esm/virtual/List.js +93 -39
  54. package/dist/esm/virtual/Scroller.js +17 -9
  55. package/dist/types/checklist/CheckList.d.ts +22 -0
  56. package/dist/types/histogram/Histogram.d.ts +28 -1
  57. package/dist/types/hooks/useFilteredList.d.ts +66 -5
  58. package/dist/types/hooks/usePagination.d.ts +19 -0
  59. package/dist/types/hooks/useSelectableList.d.ts +29 -0
  60. package/dist/types/json/JsonViewer.d.ts +27 -2
  61. package/dist/types/pagination/Pagination.d.ts +10 -1
  62. package/dist/types/table/ColumnFilters.d.ts +9 -0
  63. package/dist/types/table/HeaderCell.d.ts +1 -1
  64. package/dist/types/table/Table.d.ts +14 -1
  65. package/dist/types/table/types.d.ts +46 -7
  66. package/dist/types/table/useVirtualTable.d.ts +23 -9
  67. package/dist/types/tree/TreeNode.d.ts +1 -1
  68. package/dist/types/tree/TreePanel.d.ts +42 -1
  69. package/dist/types/tree/types.d.ts +65 -21
  70. package/dist/types/tree/useTree.d.ts +9 -10
  71. package/dist/types/tree/utils.d.ts +10 -3
  72. package/dist/types/virtual/Gallery.d.ts +42 -3
  73. package/dist/types/virtual/List.d.ts +42 -3
  74. package/package.json +16 -14
  75. package/src/checklist/CheckList.tsx +39 -7
  76. package/src/histogram/Histogram.tsx +43 -19
  77. package/src/hooks/useFilteredList.tsx +109 -9
  78. package/src/hooks/usePagination.tsx +32 -7
  79. package/src/hooks/useSelectableList.ts +29 -0
  80. package/src/i18n/ar.json +5 -0
  81. package/src/i18n/en.json +5 -0
  82. package/src/json/JsonViewer.tsx +76 -37
  83. package/src/pagination/Pagination.tsx +15 -5
  84. package/src/table/AddColumn.tsx +4 -4
  85. package/src/table/BodyCell.tsx +24 -7
  86. package/src/table/BodyRow.tsx +7 -4
  87. package/src/table/CheckboxCell.tsx +5 -5
  88. package/src/table/ColumnFilters.tsx +105 -0
  89. package/src/table/HeaderCell.tsx +74 -21
  90. package/src/table/Table.tsx +107 -12
  91. package/src/table/types.ts +49 -10
  92. package/src/table/useResizer.ts +5 -3
  93. package/src/table/useVirtualTable.ts +158 -27
  94. package/src/tree/TreeNode.tsx +96 -62
  95. package/src/tree/TreePanel.tsx +88 -22
  96. package/src/tree/types.ts +73 -23
  97. package/src/tree/useTree.ts +220 -44
  98. package/src/tree/utils.ts +58 -20
  99. package/src/virtual/Gallery.tsx +118 -54
  100. package/src/virtual/List.tsx +99 -39
  101. package/src/virtual/Scroller.tsx +25 -9
  102. package/dist/cjs/histogram/Histogram.module.css +0 -1
  103. package/dist/cjs/tree/types.js +0 -30
  104. package/dist/esm/histogram/Histogram.module.css +0 -1
@@ -99,6 +99,11 @@ var JsonEntry = function JsonEntry(_ref3) {
99
99
  clamp: 3,
100
100
  children: ret
101
101
  });
102
+ } else {
103
+ ret = /*#__PURE__*/jsxRuntime.jsx("div", {
104
+ className: "break-words",
105
+ children: ret
106
+ });
102
107
  }
103
108
  return /*#__PURE__*/jsxRuntime.jsxs(react.Fragment, {
104
109
  children: [ret, utilities.isObject(value) && value._score_ > 0 && /*#__PURE__*/jsxRuntime.jsx(core.Meter, {
@@ -120,28 +125,30 @@ var JsonEntry = function JsonEntry(_ref3) {
120
125
  }, [filters, path, pathWithoutOrdinal]);
121
126
  var labelDisplay = react.useMemo(function () {
122
127
  var _labeler;
123
- return /*#__PURE__*/jsxRuntime.jsx(core.ActionLabel, {
124
- className: "text-dimmed text-sm px-2 flex-1 truncate",
125
- actions: !canExpand && canFilter ? [/*#__PURE__*/jsxRuntime.jsx(core.Button, {
126
- color: "danger",
127
- size: "sm",
128
- variant: "link",
129
- icon: core.CoreIcons.funnelMinus,
130
- "aria-label": "Filter Negative",
131
- onClick: function onClick() {
132
- return onFilter === null || onFilter === void 0 ? void 0 : onFilter(pathWithoutOrdinal, actualValue, true);
133
- }
134
- }, "negative"), /*#__PURE__*/jsxRuntime.jsx(core.Button, {
135
- color: "primary",
136
- size: "sm",
137
- variant: "link",
138
- icon: core.CoreIcons.funnelPlus,
139
- "aria-label": "Filter",
140
- onClick: function onClick() {
141
- return onFilter === null || onFilter === void 0 ? void 0 : onFilter(pathWithoutOrdinal, actualValue);
142
- }
143
- }, "positive")] : [],
144
- children: (_labeler = labeler === null || labeler === void 0 ? void 0 : labeler(path)) !== null && _labeler !== void 0 ? _labeler : field
128
+ return /*#__PURE__*/jsxRuntime.jsxs("div", {
129
+ className: classNames("text-dimmed text-sm px-2 flex-1 group", inline ? "truncate" : "break-words"),
130
+ children: [!canExpand && canFilter && /*#__PURE__*/jsxRuntime.jsxs("div", {
131
+ className: "hidden pe-1 group-hover:inline-block",
132
+ children: [/*#__PURE__*/jsxRuntime.jsx(core.Button, {
133
+ color: "danger",
134
+ size: "xs",
135
+ variant: "link",
136
+ icon: "icon-[mdi--filter-minus]",
137
+ "aria-label": "Filter Negative",
138
+ onClick: function onClick() {
139
+ return onFilter === null || onFilter === void 0 ? void 0 : onFilter(pathWithoutOrdinal, actualValue, true);
140
+ }
141
+ }, "negative"), /*#__PURE__*/jsxRuntime.jsx(core.Button, {
142
+ color: "primary",
143
+ size: "xs",
144
+ variant: "link",
145
+ icon: "icon-[mdi--filter-plus]",
146
+ "aria-label": "Filter",
147
+ onClick: function onClick() {
148
+ return onFilter === null || onFilter === void 0 ? void 0 : onFilter(pathWithoutOrdinal, actualValue);
149
+ }
150
+ }, "positive")]
151
+ }), (_labeler = labeler === null || labeler === void 0 ? void 0 : labeler(path)) !== null && _labeler !== void 0 ? _labeler : field]
145
152
  });
146
153
  }, [field, labeler, pathWithoutOrdinal, actualValue, canExpand, canFilter]);
147
154
  return /*#__PURE__*/jsxRuntime.jsxs(react.Fragment, {
@@ -161,14 +168,17 @@ var JsonEntry = function JsonEntry(_ref3) {
161
168
  },
162
169
  children: [canExpand && /*#__PURE__*/jsxRuntime.jsx(core.Icon, {
163
170
  rtlFlip: true,
164
- icon: expanded ? core.CoreIcons.chevronDown : core.CoreIcons.chevronRight
171
+ icon: expanded ? "icon-[mdi--chevron-down]" : "icon-[mdi--chevron-right]"
165
172
  }), labelDisplay]
166
173
  }), display && /*#__PURE__*/jsxRuntime.jsxs("div", {
167
- className: classNames("px-2", inline && "flex-1"),
174
+ className: classNames("px-2 flex flex-nowrap overflow-hidden", inline && "flex-1"),
168
175
  children: [canCopy && /*#__PURE__*/jsxRuntime.jsx(core.Copy, {
169
176
  size: "xs",
170
177
  text: actualValue
171
- }), display]
178
+ }), /*#__PURE__*/jsxRuntime.jsx("div", {
179
+ className: "flex-1",
180
+ children: display
181
+ })]
172
182
  })]
173
183
  }), !showPropertyTree && !children && /*#__PURE__*/jsxRuntime.jsxs("div", {
174
184
  className: classNames("py-2", inline && "flex flex-nowrap items-center"),
@@ -180,11 +190,14 @@ var JsonEntry = function JsonEntry(_ref3) {
180
190
  },
181
191
  children: labelDisplay
182
192
  }), /*#__PURE__*/jsxRuntime.jsxs("div", {
183
- className: classNames("px-2", inline && "flex-1"),
193
+ className: classNames("px-2 flex flex-nowrap overflow-hidden", inline && "flex-1"),
184
194
  children: [canCopy && /*#__PURE__*/jsxRuntime.jsx(core.Copy, {
185
195
  size: "xs",
186
196
  text: value
187
- }), display]
197
+ }), /*#__PURE__*/jsxRuntime.jsx("div", {
198
+ className: "flex-1",
199
+ children: display
200
+ })]
188
201
  })]
189
202
  }), expanded && (children === null || children === void 0 ? void 0 : children.map(function (item) {
190
203
  return /*#__PURE__*/jsxRuntime.jsx(JsonEntry, _objectSpread(_objectSpread({}, item), {}, {
@@ -202,6 +215,33 @@ var JsonEntry = function JsonEntry(_ref3) {
202
215
  }))]
203
216
  });
204
217
  };
218
+
219
+ /**
220
+ * JsonViewer component to display JSON data in a structured format.
221
+ * It supports inline display, property filtering, and custom formatting.
222
+ * The component can handle nested objects and arrays, displaying them in a tree-like structure.
223
+ * It also provides options for copying values and filtering properties.
224
+ *
225
+ * @param {JsonViewProps<T>} props - The properties for the JsonViewer component.
226
+ * @returns {JSX.Element} The rendered JsonViewer component.
227
+ *
228
+ * @example
229
+ * ```jsx
230
+ * <JsonViewer
231
+ * json={{ name: "John", age: 30, address: { city: "New York", zip: "10001" } }}
232
+ * copy={true}
233
+ * filters={true}
234
+ * propertyScheme={{ date: ["createdAt"], phone: ["contact"] }}
235
+ * inline={true}
236
+ * labelWidth="25%"
237
+ * formatter={(path, value) => (path === "age" ? `${value} years` : value)}
238
+ * labeler={(path) => path.replace(/_/g, " ").toUpperCase()}
239
+ * onFilter={(path, value, negate) => console.log(`Filter ${negate ? "negate" : ""} on ${path}:`, value)}
240
+ * />
241
+ * ```
242
+ *
243
+ * @see {@link https://adarshpastakia.github.io/react-fabric/?path=/docs/data-jsonviewer--docs}
244
+ */
205
245
  var JsonViewer = function JsonViewer(_ref5) {
206
246
  var className = _ref5.className,
207
247
  json = _ref5.json,
@@ -223,7 +263,7 @@ var JsonViewer = function JsonViewer(_ref5) {
223
263
  return reduceObject(json);
224
264
  }, [json]);
225
265
  return /*#__PURE__*/jsxRuntime.jsx("div", _objectSpread(_objectSpread({}, rest), {}, {
226
- className: classNames(className, "p-4 bg-alternate"),
266
+ className: classNames(className, "bg-alternate"),
227
267
  children: !utilities.isEmpty(json) ? list.map(function (item) {
228
268
  return /*#__PURE__*/jsxRuntime.jsx(JsonEntry, _objectSpread(_objectSpread({}, item), {}, {
229
269
  copy: copy,
@@ -6,6 +6,16 @@ var classNames = require('classnames');
6
6
  var react = require('react');
7
7
  var jsxRuntime = require('react/jsx-runtime');
8
8
 
9
+ /**
10
+ * Pagination component to navigate through pages of data.
11
+ * It displays buttons for navigating to the first, previous, next, and last pages,
12
+ * as well as buttons for specific page numbers based on the provided ranges.
13
+ * The component supports a minimal view that shows the current page and total pages.
14
+ * It uses memoization to optimize rendering performance.
15
+ *
16
+ * @param {PaginationProps} props - The properties for the Pagination component.
17
+ * @returns {JSX.Element} The rendered Pagination component.
18
+ */
9
19
  var Pagination = /*#__PURE__*/react.memo(function (_ref) {
10
20
  var page = _ref.page,
11
21
  ranges = _ref.ranges,
@@ -59,7 +69,7 @@ var Pagination = /*#__PURE__*/react.memo(function (_ref) {
59
69
  },
60
70
  className: classNames("leading-none text-sm hover:bg-primary-200 w-8 h-6 rounded-full", page === 0 && "pointer-events-none text-tint-300"),
61
71
  children: /*#__PURE__*/jsxRuntime.jsx(core.Icon, {
62
- icon: core.CoreIcons.chevronsLeft,
72
+ icon: "icon-[mdi--chevron-double-left]",
63
73
  rtlFlip: true
64
74
  })
65
75
  }), /*#__PURE__*/jsxRuntime.jsx("button", {
@@ -68,7 +78,7 @@ var Pagination = /*#__PURE__*/react.memo(function (_ref) {
68
78
  },
69
79
  className: classNames("leading-none text-sm hover:bg-primary-200 w-8 h-6 rounded-full", page === 0 && "pointer-events-none text-tint-300"),
70
80
  children: /*#__PURE__*/jsxRuntime.jsx(core.Icon, {
71
- icon: core.CoreIcons.chevronLeft,
81
+ icon: "icon-[mdi--chevron-left]",
72
82
  rtlFlip: true
73
83
  })
74
84
  }), !minimal && pageBody, minimal && /*#__PURE__*/jsxRuntime.jsxs("label", {
@@ -80,7 +90,7 @@ var Pagination = /*#__PURE__*/react.memo(function (_ref) {
80
90
  },
81
91
  className: classNames("leading-none text-sm hover:bg-primary-200 w-8 h-6 rounded-full", page + 1 >= totalPages && "pointer-events-none text-tint-300"),
82
92
  children: /*#__PURE__*/jsxRuntime.jsx(core.Icon, {
83
- icon: core.CoreIcons.chevronRight,
93
+ icon: "icon-[mdi--chevron-right]",
84
94
  rtlFlip: true
85
95
  })
86
96
  }), /*#__PURE__*/jsxRuntime.jsx("button", {
@@ -89,7 +99,7 @@ var Pagination = /*#__PURE__*/react.memo(function (_ref) {
89
99
  },
90
100
  className: classNames("leading-none text-sm hover:bg-primary-200 w-8 h-6 rounded-full", page + 1 >= totalPages && "pointer-events-none text-tint-300"),
91
101
  children: /*#__PURE__*/jsxRuntime.jsx(core.Icon, {
92
- icon: core.CoreIcons.chevronsRight,
102
+ icon: "icon-[mdi--chevron-double-right]",
93
103
  rtlFlip: true
94
104
  })
95
105
  })]
@@ -30,11 +30,11 @@ var AddColumn = function AddColumn(_ref) {
30
30
  var columns = _ref.columns,
31
31
  onClick = _ref.onClick;
32
32
  return /*#__PURE__*/jsxRuntime.jsx("div", {
33
- className: "group font-medium w-6 flex flex-nowrap text-start items-end",
33
+ className: "group font-medium w-6 flex flex-nowrap text-start items-center",
34
34
  children: /*#__PURE__*/jsxRuntime.jsxs(core.Dropdown, {
35
35
  placement: "bottom-end",
36
36
  children: [/*#__PURE__*/jsxRuntime.jsx(core.Icon, {
37
- icon: core.CoreIcons.insert,
37
+ icon: "icon-[mdi--plus-circle-outline]",
38
38
  className: "p-1 rounded-t rounded-b-none hover:outline"
39
39
  }), /*#__PURE__*/jsxRuntime.jsx(core.Menu, {
40
40
  className: "text-sm",
@@ -45,7 +45,7 @@ var AddColumn = function AddColumn(_ref) {
45
45
  id: String(col.id),
46
46
  "data-dropdown-dismiss": "false",
47
47
  label: "".concat((_col$label = col.label) !== null && _col$label !== void 0 ? _col$label : String(col.id)),
48
- icon: !col.hidden ? core.CoreIcons.tick : ""
48
+ icon: !col.hidden ? "icon-[mdi--check]" : ""
49
49
  }, String(col.id));
50
50
  })
51
51
  })]
@@ -43,24 +43,26 @@ var BodyCell = function BodyCell(_ref) {
43
43
  return (_widths$get = widths.get(column.id.toString())) !== null && _widths$get !== void 0 ? _widths$get : column.width;
44
44
  }, [widths, column]);
45
45
  var content = react.useMemo(function () {
46
+ var _column$dataType2;
46
47
  var value = utilities.getByPath(item, column.id.toString());
47
48
  if (column.renderer != null) {
48
- return column.renderer(item[column.id], item, index);
49
+ return column.renderer(value, item, index);
49
50
  }
50
51
  if (column.dataType === "boolean") {
51
52
  var _column$valueMap;
52
53
  var map = (_column$valueMap = column.valueMap) !== null && _column$valueMap !== void 0 ? _column$valueMap : {
53
54
  "true": "Yes",
54
- "false": "no"
55
+ "false": "No"
55
56
  };
56
57
  return map["".concat(utilities.isTrue(value) ? "true" : "false")];
57
58
  }
58
59
  if (column.valueMap != null) {
59
- if (column.dataType === "string" && value in column.valueMap) {
60
+ var _column$dataType;
61
+ if (["number", "string"].includes((_column$dataType = column.dataType) !== null && _column$dataType !== void 0 ? _column$dataType : "string") && value in column.valueMap) {
60
62
  return column.valueMap[value];
61
63
  }
62
64
  }
63
- if (column.dataType === "date") {
65
+ if (["date", "time", "datetime"].includes((_column$dataType2 = column.dataType) !== null && _column$dataType2 !== void 0 ? _column$dataType2 : "")) {
64
66
  return /*#__PURE__*/jsxRuntime.jsx(date.DateDisplay, {
65
67
  date: value,
66
68
  format: column.format
@@ -69,17 +71,23 @@ var BodyCell = function BodyCell(_ref) {
69
71
  if (column.dataType === "number") {
70
72
  return utilities.Format.number(value, column.format);
71
73
  }
74
+ if (utilities.isObject(value)) {
75
+ return JSON.stringify(value);
76
+ }
77
+ if (utilities.isArray(value)) {
78
+ return value.join(", ");
79
+ }
72
80
  return value !== null && value !== void 0 ? value : "";
73
81
  }, [item, column]);
74
82
  return /*#__PURE__*/jsxRuntime.jsx("div", {
75
- className: "overflow-hidden bg-inherit start-0",
83
+ className: "overflow-hidden bg-inherit start-0 border-e group/table-col",
76
84
  style: {
77
85
  width: width !== null && width !== void 0 ? width : types.COL_DEFAULT_WIDTH,
78
86
  minWidth: (_column$minWidth = column.minWidth) !== null && _column$minWidth !== void 0 ? _column$minWidth : types.COL_MIN_WIDTH,
79
87
  maxWidth: (_column$maxWidth = column.maxWidth) !== null && _column$maxWidth !== void 0 ? _column$maxWidth : types.COL_MAX_WIDTH
80
88
  },
81
89
  children: /*#__PURE__*/jsxRuntime.jsx("div", {
82
- className: classNames("px-2 py-1 border-e truncate", column.align === "center" && "text-center", column.align === "end" && "text-end"),
90
+ className: classNames("px-2 py-1", column.className, column.truncate && "truncate", column.align === "center" && "text-center", column.align === "end" && "text-end"),
83
91
  children: content
84
92
  })
85
93
  });
@@ -1,9 +1,9 @@
1
1
  'use strict';
2
2
 
3
+ var core = require('@react-fabric/core');
3
4
  var classNames = require('classnames');
4
5
  var BodyCell = require('./BodyCell.js');
5
6
  var CheckboxCell = require('./CheckboxCell.js');
6
- var core = require('@react-fabric/core');
7
7
  var jsxRuntime = require('react/jsx-runtime');
8
8
 
9
9
  /*
@@ -55,17 +55,17 @@ var BodyRow = function BodyRow(_ref) {
55
55
  children: [/*#__PURE__*/jsxRuntime.jsxs("div", {
56
56
  role: "none",
57
57
  "data-row": index,
58
- className: classNames("flex flex-nowrap datatable-row data-[hilight]:outline-1 -outline-offset-1 outline-primary-500", onRowClick && "hover:bg-primary-50 active:bg-primary-100"),
58
+ className: classNames("flex flex-nowrap datatable-row data-hilight:outline-1 -outline-offset-1 outline-primary-500 group/table-row", onRowClick && "hover:bg-primary-50 active:bg-primary-100", index % 2 ? "bg-even" : "bg-odd"),
59
59
  onClick: function onClick() {
60
60
  return checkableRows && keyProperty && !onRowClick ? toggleChecked(data[keyProperty]) : onRowClick === null || onRowClick === void 0 ? void 0 : onRowClick(data);
61
61
  },
62
62
  children: [/*#__PURE__*/jsxRuntime.jsxs("div", {
63
63
  className: wrapperStart,
64
64
  children: [!!canExpand && /*#__PURE__*/jsxRuntime.jsx("div", {
65
- className: classNames("group font-medium w-6 flex flex-nowrap text-start items-center", !canExpand(data) && "pointer-events-none opacity-35"),
65
+ className: classNames("group font-medium w-6 flex flex-nowrap text-start py-1", !canExpand(data) && "pointer-events-none opacity-35"),
66
66
  children: /*#__PURE__*/jsxRuntime.jsx(core.Icon, {
67
67
  className: "p-1 text-tint-700 hover:text-primary-600",
68
- icon: expanded ? core.CoreIcons.collapse : core.CoreIcons.expand,
68
+ icon: expanded ? "icon-[mdi--minus-box]" : "icon-[mdi--plus-box]",
69
69
  onClick: function onClick(e) {
70
70
  return [keyProperty && toggleExpand(data[keyProperty]), e.stopPropagation()];
71
71
  }
@@ -30,9 +30,9 @@ var CheckboxCell = function CheckboxCell(_ref) {
30
30
  var state = _ref.state,
31
31
  _onClick = _ref.onClick;
32
32
  return /*#__PURE__*/jsxRuntime.jsx("div", {
33
- className: "group font-medium border-e w-6 flex flex-nowrap text-start items-center",
33
+ className: "group font-medium border-e w-6 flex flex-nowrap text-start py-1",
34
34
  children: /*#__PURE__*/jsxRuntime.jsx(core.Icon, {
35
- icon: state === 2 ? core.CoreIcons.checkboxInt : state === 1 ? core.CoreIcons.checkboxOn : core.CoreIcons.checkboxOff,
35
+ icon: state === 2 ? "icon-[mdi--checkbox-intermediate]" : state === 1 ? "icon-[mdi--checkbox-marked]" : "icon-[mdi--checkbox-blank-outline]",
36
36
  className: "p-1 text-tint-700 hover:text-primary-600",
37
37
  onClick: function onClick(e) {
38
38
  return [_onClick === null || _onClick === void 0 ? void 0 : _onClick(), e.stopPropagation()];
@@ -0,0 +1,97 @@
1
+ 'use strict';
2
+
3
+ var _slicedToArray = require('@babel/runtime/helpers/slicedToArray');
4
+ var core = require('@react-fabric/core');
5
+ var form = require('@react-fabric/form');
6
+ var utilities = require('@react-fabric/utilities');
7
+ var react = require('react');
8
+ var useFilteredList = require('../hooks/useFilteredList.js');
9
+ var jsxRuntime = require('react/jsx-runtime');
10
+
11
+ var ListFilter = function ListFilter(_ref) {
12
+ var _ref$list = _ref.list,
13
+ list = _ref$list === void 0 ? utilities.EMPTY_ARRAY : _ref$list,
14
+ filter = _ref.filter,
15
+ onFilter = _ref.onFilter;
16
+ var _useState = react.useState(new Set(filter)),
17
+ _useState2 = _slicedToArray(_useState, 2),
18
+ selected = _useState2[0],
19
+ setSelected = _useState2[1];
20
+ var _useFilteredList = useFilteredList.useFilteredList(list, function (item, query) {
21
+ var _item$id;
22
+ return utilities.matchString((_item$id = item.id) !== null && _item$id !== void 0 ? _item$id : item, query);
23
+ }),
24
+ filteredList = _useFilteredList.filteredList,
25
+ query = _useFilteredList.query,
26
+ onSearch = _useFilteredList.onSearch;
27
+ return /*#__PURE__*/jsxRuntime.jsxs("div", {
28
+ className: "flex flex-col",
29
+ children: [/*#__PURE__*/jsxRuntime.jsx("div", {
30
+ children: /*#__PURE__*/jsxRuntime.jsx(form.Search, {
31
+ autoFocus: true,
32
+ value: query,
33
+ onSearch: onSearch,
34
+ searchOnChange: true
35
+ })
36
+ }), /*#__PURE__*/jsxRuntime.jsxs("div", {
37
+ className: "flex-1 overflow-auto scroll-thin",
38
+ children: [filteredList.map(function (v, idx) {
39
+ var _v$id, _v$label;
40
+ return /*#__PURE__*/jsxRuntime.jsx("div", {
41
+ className: "flex gap-x-1 text-xs items-center",
42
+ children: /*#__PURE__*/jsxRuntime.jsx(form.Checkbox, {
43
+ checked: selected.has((_v$id = v.id) !== null && _v$id !== void 0 ? _v$id : v),
44
+ onChange: function onChange(b) {
45
+ var _v$id2, _v$id3;
46
+ var set = new Set(Array.from(selected.values()));
47
+ b ? set.add((_v$id2 = v.id) !== null && _v$id2 !== void 0 ? _v$id2 : v) : set["delete"]((_v$id3 = v.id) !== null && _v$id3 !== void 0 ? _v$id3 : v);
48
+ setSelected(set);
49
+ },
50
+ label: /*#__PURE__*/jsxRuntime.jsx("span", {
51
+ className: "truncate",
52
+ children: (_v$label = v.label) !== null && _v$label !== void 0 ? _v$label : v
53
+ })
54
+ })
55
+ }, idx);
56
+ }), filteredList.length === 0 && /*#__PURE__*/jsxRuntime.jsx("span", {
57
+ className: "text-muted text-xs",
58
+ children: "No items found"
59
+ })]
60
+ }), /*#__PURE__*/jsxRuntime.jsx("div", {
61
+ className: "flex justify-end",
62
+ children: /*#__PURE__*/jsxRuntime.jsx(core.DropdownDismiss, {
63
+ children: /*#__PURE__*/jsxRuntime.jsx(core.Button, {
64
+ size: "xs",
65
+ onClick: function onClick() {
66
+ return onFilter === null || onFilter === void 0 ? void 0 : onFilter(Array.from(selected));
67
+ },
68
+ children: "Apply"
69
+ })
70
+ })
71
+ })]
72
+ });
73
+ };
74
+ var ColumnFilters = function ColumnFilters(_ref2) {
75
+ var type = _ref2.type,
76
+ list = _ref2.list,
77
+ filter = _ref2.filter,
78
+ onFilter = _ref2.onFilter;
79
+ return /*#__PURE__*/jsxRuntime.jsxs("div", {
80
+ className: "flex flex-col min-w-[16rem]",
81
+ children: [list && /*#__PURE__*/jsxRuntime.jsx(ListFilter, {
82
+ list: list,
83
+ filter: filter,
84
+ onFilter: onFilter
85
+ }), !list && type === "string" && /*#__PURE__*/jsxRuntime.jsx(form.Input, {
86
+ autoFocus: true,
87
+ allowClear: true,
88
+ value: filter,
89
+ onEnterPressed: function onEnterPressed(e) {
90
+ var _e$target$value;
91
+ return onFilter((_e$target$value = e.target.value) !== null && _e$target$value !== void 0 ? _e$target$value : "");
92
+ }
93
+ })]
94
+ });
95
+ };
96
+
97
+ exports.ColumnFilters = ColumnFilters;
@@ -1,51 +1,37 @@
1
1
  'use strict';
2
2
 
3
+ var _defineProperty = require('@babel/runtime/helpers/defineProperty');
4
+ var _toConsumableArray = require('@babel/runtime/helpers/toConsumableArray');
3
5
  var core = require('@react-fabric/core');
6
+ var utilities = require('@react-fabric/utilities');
4
7
  var react = require('react');
8
+ var ColumnFilters = require('./ColumnFilters.js');
5
9
  var Context = require('./Context.js');
6
10
  var types = require('./types.js');
7
11
  var jsxRuntime = require('react/jsx-runtime');
8
12
 
9
- /*
10
- * React Fabric
11
- * @version: 1.0.0
12
- *
13
- *
14
- * The MIT License (MIT)
15
- * Copyright (c) 2024 Adarsh Pastakia
16
- *
17
- * Permission is hereby granted, free of charge, to any person obtaining a copy of this software
18
- * and associated documentation files (the "Software"), to deal in the Software without restriction,
19
- * including without limitation the rights to use, copy, modify, merge, publish, distribute, sublicense,
20
- * and/or sell copies of the Software, and to permit persons to whom the Software is furnished to do so,
21
- * subject to the following conditions:
22
- *
23
- * The above copyright notice and this permission notice shall be included in all copies or substantial
24
- * portions of the Software.
25
- *
26
- * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED
27
- * TO THE WARRANTIES OF MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL
28
- * THE AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION OF CONTRACT,
29
- * TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.
30
- */
31
-
13
+ function ownKeys(e, r) { var t = Object.keys(e); if (Object.getOwnPropertySymbols) { var o = Object.getOwnPropertySymbols(e); r && (o = o.filter(function (r) { return Object.getOwnPropertyDescriptor(e, r).enumerable; })), t.push.apply(t, o); } return t; }
14
+ function _objectSpread(e) { for (var r = 1; r < arguments.length; r++) { var t = null != arguments[r] ? arguments[r] : {}; r % 2 ? ownKeys(Object(t), !0).forEach(function (r) { _defineProperty(e, r, t[r]); }) : Object.getOwnPropertyDescriptors ? Object.defineProperties(e, Object.getOwnPropertyDescriptors(t)) : ownKeys(Object(t)).forEach(function (r) { Object.defineProperty(e, r, Object.getOwnPropertyDescriptor(t, r)); }); } return e; }
32
15
  var HeaderCell = function HeaderCell(_ref) {
33
16
  var id = _ref.id,
17
+ field = _ref.field,
18
+ dataType = _ref.dataType,
34
19
  label = _ref.label,
35
20
  icon = _ref.icon,
36
- iconBg = _ref.iconBg,
37
- iconColor = _ref.iconColor,
38
- rtlFlip = _ref.rtlFlip;
39
- _ref.actions;
21
+ actions = _ref.actions;
40
22
  _ref.locked;
41
- var tooltip = _ref.tooltip,
23
+ var filter = _ref.filter,
24
+ filterable = _ref.filterable,
25
+ filterOptions = _ref.filterOptions,
26
+ tooltip = _ref.tooltip,
42
27
  sortable = _ref.sortable,
43
28
  resizable = _ref.resizable,
44
29
  _width = _ref.width,
45
30
  maxWidth = _ref.maxWidth,
46
31
  minWidth = _ref.minWidth,
47
32
  sort = _ref.sort,
48
- onSort = _ref.onSort;
33
+ onSort = _ref.onSort,
34
+ _onFilter = _ref.onFilter;
49
35
  var _useTableContext = Context.useTableContext(),
50
36
  startResize = _useTableContext.startResize,
51
37
  widths = _useTableContext.widths;
@@ -53,30 +39,68 @@ var HeaderCell = function HeaderCell(_ref) {
53
39
  var _widths$get;
54
40
  return (_widths$get = widths.get(id.toString())) !== null && _widths$get !== void 0 ? _widths$get : _width;
55
41
  }, [widths, _width, id]);
56
- var handleSort = react.useCallback(function () {
42
+ var handleSort = react.useCallback(function (order) {
57
43
  sortable && (onSort === null || onSort === void 0 ? void 0 : onSort({
58
44
  id: id.toString(),
59
- order: (sort === null || sort === void 0 ? void 0 : sort.id) === id && sort.order === "asc" ? "desc" : "asc"
45
+ order: order !== null && order !== void 0 ? order : (sort === null || sort === void 0 ? void 0 : sort.id) === id && sort.order === "asc" ? "desc" : "asc"
60
46
  }));
61
- }, [onSort, name, sort, sortable]);
47
+ }, [onSort, sort, sortable]);
62
48
  var menus = react.useMemo(function () {
63
49
  var ret = [];
50
+ if (filterable && (dataType !== null && dataType !== void 0 ? dataType : filterOptions)) {
51
+ ret.push( /*#__PURE__*/jsxRuntime.jsx(core.Menu, {
52
+ label: "Filter",
53
+ icon: filter ? "icon-[mdi--check]" : "",
54
+ trigger: "click",
55
+ children: /*#__PURE__*/jsxRuntime.jsx(ColumnFilters.ColumnFilters, {
56
+ type: dataType,
57
+ list: filterOptions,
58
+ filter: filter,
59
+ onFilter: function onFilter(value) {
60
+ return _onFilter === null || _onFilter === void 0 ? void 0 : _onFilter(field !== null && field !== void 0 ? field : id, value);
61
+ }
62
+ })
63
+ }, "filters"));
64
+ }
64
65
  if (sortable) {
65
66
  ret.push( /*#__PURE__*/jsxRuntime.jsx(core.MenuItem, {
66
67
  label: "Sort ascending",
67
- icon: core.CoreIcons.sortAsc
68
+ icon: "icon-[mdi--sort-ascending]",
69
+ onClick: function onClick() {
70
+ return handleSort("asc");
71
+ }
68
72
  }, "sort-asc"), /*#__PURE__*/jsxRuntime.jsx(core.MenuItem, {
69
73
  label: "Sort descending",
70
- icon: core.CoreIcons.sortDesc
74
+ icon: "icon-[mdi--sort-descending]",
75
+ onClick: function onClick() {
76
+ return handleSort("desc");
77
+ }
71
78
  }, "sort-desc"));
72
79
  }
80
+ if (actions) {
81
+ var _ret;
82
+ ret.push( /*#__PURE__*/jsxRuntime.jsx(core.Divider, {}, "div"));
83
+ (_ret = ret).push.apply(_ret, _toConsumableArray(actions));
84
+ }
85
+ if (ret.length === 1) {
86
+ ret = [/*#__PURE__*/jsxRuntime.jsx(ColumnFilters.ColumnFilters, {
87
+ type: dataType,
88
+ list: filterOptions,
89
+ filter: filter,
90
+ onFilter: function onFilter(value) {
91
+ return _onFilter === null || _onFilter === void 0 ? void 0 : _onFilter(field !== null && field !== void 0 ? field : id, value);
92
+ }
93
+ }, "filters")];
94
+ }
73
95
  return ret;
74
- }, [sortable]);
96
+ }, [sortable, actions, _onFilter, handleSort]);
75
97
  return /*#__PURE__*/jsxRuntime.jsxs("div", {
76
98
  role: "none",
77
99
  "data-id": id,
78
- onClick: handleSort,
79
- className: "group font-medium border-e flex flex-nowrap text-start items-center table-header-cell",
100
+ onClick: function onClick() {
101
+ return handleSort();
102
+ },
103
+ className: "group/tool font-medium border-e flex flex-nowrap text-start items-center table-header-cell",
80
104
  style: {
81
105
  width: width !== null && width !== void 0 ? width : types.COL_DEFAULT_WIDTH,
82
106
  minWidth: minWidth !== null && minWidth !== void 0 ? minWidth : types.COL_MIN_WIDTH,
@@ -87,12 +111,7 @@ var HeaderCell = function HeaderCell(_ref) {
87
111
  disabled: !(tooltip !== null && tooltip !== void 0 ? tooltip : label),
88
112
  children: /*#__PURE__*/jsxRuntime.jsxs("div", {
89
113
  className: "flex-initial px-2 py-1 text-sm truncate sticky start-0",
90
- children: [icon && /*#__PURE__*/jsxRuntime.jsx(core.Icon, {
91
- icon: icon,
92
- bg: iconBg,
93
- color: iconColor,
94
- rtlFlip: rtlFlip
95
- }), /*#__PURE__*/jsxRuntime.jsx("span", {
114
+ children: [icon && /*#__PURE__*/jsxRuntime.jsx(core.Icon, _objectSpread({}, core.getIconProps(icon))), /*#__PURE__*/jsxRuntime.jsx("span", {
96
115
  children: label !== null && label !== void 0 ? label : " "
97
116
  })]
98
117
  })
@@ -112,6 +131,15 @@ var HeaderCell = function HeaderCell(_ref) {
112
131
  className: "text-sm",
113
132
  children: menus
114
133
  })
134
+ }), filterable && !utilities.isEmpty(filter) && /*#__PURE__*/jsxRuntime.jsx(core.Button, {
135
+ size: "sm",
136
+ variant: "link",
137
+ "aria-label": "clear filter",
138
+ stopPropagation: true,
139
+ icon: "icon-[mdi--filter-remove]",
140
+ onClick: function onClick() {
141
+ return _onFilter === null || _onFilter === void 0 ? void 0 : _onFilter(id);
142
+ }
115
143
  }), resizable && /*#__PURE__*/jsxRuntime.jsx("div", {
116
144
  role: "none",
117
145
  className: "cursor-col-resize border-e bg-transparent border-tint-200 w-[5px] self-stretch",