@react-fabric/data 1.0.0-beta.0

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 (94) hide show
  1. package/LICENSE +21 -0
  2. package/README.md +10 -0
  3. package/dist/cjs/histogram/Histogram.js +89 -0
  4. package/dist/cjs/histogram/Histogram.module.css +1 -0
  5. package/dist/cjs/hooks/useFilteredList.js +56 -0
  6. package/dist/cjs/hooks/usePagination.js +85 -0
  7. package/dist/cjs/i18n/ar.json.js +56 -0
  8. package/dist/cjs/i18n/en.json.js +56 -0
  9. package/dist/cjs/i18n/index.js +33 -0
  10. package/dist/cjs/index.js +24 -0
  11. package/dist/cjs/json/JsonViewer.js +246 -0
  12. package/dist/cjs/pagination/Pagination.js +100 -0
  13. package/dist/cjs/table/BodyCell.js +47 -0
  14. package/dist/cjs/table/HeaderCell.js +79 -0
  15. package/dist/cjs/table/Table.js +133 -0
  16. package/dist/cjs/table/useTableColumns.js +26 -0
  17. package/dist/cjs/table/useVirtualTable.js +56 -0
  18. package/dist/cjs/tree/TreeNode.js +107 -0
  19. package/dist/cjs/tree/TreePanel.js +136 -0
  20. package/dist/cjs/tree/types.js +30 -0
  21. package/dist/cjs/tree/useTree.js +181 -0
  22. package/dist/cjs/tree/utils.js +145 -0
  23. package/dist/cjs/virtual/Gallery.js +229 -0
  24. package/dist/cjs/virtual/List.js +218 -0
  25. package/dist/cjs/virtual/Scroller.js +77 -0
  26. package/dist/esm/histogram/Histogram.js +89 -0
  27. package/dist/esm/histogram/Histogram.module.css +1 -0
  28. package/dist/esm/hooks/useFilteredList.js +56 -0
  29. package/dist/esm/hooks/usePagination.js +85 -0
  30. package/dist/esm/i18n/ar.json.js +47 -0
  31. package/dist/esm/i18n/en.json.js +47 -0
  32. package/dist/esm/i18n/index.js +33 -0
  33. package/dist/esm/index.js +12 -0
  34. package/dist/esm/json/JsonViewer.js +246 -0
  35. package/dist/esm/pagination/Pagination.js +100 -0
  36. package/dist/esm/table/BodyCell.js +47 -0
  37. package/dist/esm/table/HeaderCell.js +79 -0
  38. package/dist/esm/table/Table.js +133 -0
  39. package/dist/esm/table/useTableColumns.js +26 -0
  40. package/dist/esm/table/useVirtualTable.js +56 -0
  41. package/dist/esm/tree/TreeNode.js +107 -0
  42. package/dist/esm/tree/TreePanel.js +136 -0
  43. package/dist/esm/tree/types.js +29 -0
  44. package/dist/esm/tree/useTree.js +181 -0
  45. package/dist/esm/tree/utils.js +140 -0
  46. package/dist/esm/virtual/Gallery.js +229 -0
  47. package/dist/esm/virtual/List.js +218 -0
  48. package/dist/esm/virtual/Scroller.js +77 -0
  49. package/dist/types/histogram/Histogram.d.ts +41 -0
  50. package/dist/types/hooks/useFilteredList.d.ts +7 -0
  51. package/dist/types/hooks/usePagination.d.ts +25 -0
  52. package/dist/types/i18n/index.d.ts +1 -0
  53. package/dist/types/index.d.ts +10 -0
  54. package/dist/types/json/JsonViewer.d.ts +59 -0
  55. package/dist/types/pagination/Pagination.d.ts +24 -0
  56. package/dist/types/table/BodyCell.d.ts +5 -0
  57. package/dist/types/table/HeaderCell.d.ts +2 -0
  58. package/dist/types/table/Table.d.ts +2 -0
  59. package/dist/types/table/types.d.ts +26 -0
  60. package/dist/types/table/useTableColumns.d.ts +8 -0
  61. package/dist/types/table/useVirtualTable.d.ts +8 -0
  62. package/dist/types/tree/TreeNode.d.ts +2 -0
  63. package/dist/types/tree/TreePanel.d.ts +2 -0
  64. package/dist/types/tree/types.d.ts +138 -0
  65. package/dist/types/tree/useTree.d.ts +20 -0
  66. package/dist/types/tree/utils.d.ts +10 -0
  67. package/dist/types/virtual/Gallery.d.ts +55 -0
  68. package/dist/types/virtual/List.d.ts +59 -0
  69. package/dist/types/virtual/Scroller.d.ts +8 -0
  70. package/package.json +55 -0
  71. package/src/histogram/Histogram.module.css +57 -0
  72. package/src/histogram/Histogram.tsx +176 -0
  73. package/src/hooks/useFilteredList.tsx +78 -0
  74. package/src/hooks/usePagination.tsx +135 -0
  75. package/src/i18n/ar.json +36 -0
  76. package/src/i18n/en.json +36 -0
  77. package/src/i18n/index.ts +28 -0
  78. package/src/index.ts +35 -0
  79. package/src/json/JsonViewer.tsx +381 -0
  80. package/src/pagination/Pagination.tsx +157 -0
  81. package/src/table/BodyCell.tsx +54 -0
  82. package/src/table/HeaderCell.tsx +70 -0
  83. package/src/table/Table.tsx +143 -0
  84. package/src/table/types.ts +65 -0
  85. package/src/table/useTableColumns.ts +52 -0
  86. package/src/table/useVirtualTable.ts +54 -0
  87. package/src/tree/TreeNode.tsx +163 -0
  88. package/src/tree/TreePanel.tsx +157 -0
  89. package/src/tree/types.ts +181 -0
  90. package/src/tree/useTree.ts +227 -0
  91. package/src/tree/utils.ts +185 -0
  92. package/src/virtual/Gallery.tsx +349 -0
  93. package/src/virtual/List.tsx +351 -0
  94. package/src/virtual/Scroller.tsx +81 -0
@@ -0,0 +1,79 @@
1
+ 'use client';
2
+
3
+ import { Icon, Dropdown, CoreIcons, Menu, MenuItem } from '@react-fabric/core';
4
+ import { jsxs, jsx } from 'react/jsx-runtime';
5
+
6
+ /*
7
+ * React Fabric
8
+ * @version: 1.0.0
9
+ *
10
+ *
11
+ * The MIT License (MIT)
12
+ * Copyright (c) 2024 Adarsh Pastakia
13
+ *
14
+ * Permission is hereby granted, free of charge, to any person obtaining a copy of this software
15
+ * and associated documentation files (the "Software"), to deal in the Software without restriction,
16
+ * including without limitation the rights to use, copy, modify, merge, publish, distribute, sublicense,
17
+ * and/or sell copies of the Software, and to permit persons to whom the Software is furnished to do so,
18
+ * subject to the following conditions:
19
+ *
20
+ * The above copyright notice and this permission notice shall be included in all copies or substantial
21
+ * portions of the Software.
22
+ *
23
+ * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED
24
+ * TO THE WARRANTIES OF MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL
25
+ * THE AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION OF CONTRACT,
26
+ * TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.
27
+ */
28
+
29
+ var HeaderCell = function HeaderCell(_ref) {
30
+ var label = _ref.label,
31
+ icon = _ref.icon,
32
+ iconBg = _ref.iconBg,
33
+ iconColor = _ref.iconColor,
34
+ rtlFlip = _ref.rtlFlip;
35
+ _ref.actions;
36
+ _ref.locked;
37
+ var resizable = _ref.resizable,
38
+ width = _ref.width,
39
+ maxWidth = _ref.maxWidth,
40
+ minWidth = _ref.minWidth;
41
+ return /*#__PURE__*/jsxs("div", {
42
+ className: "group font-medium border-e flex flex-nowrap text-start items-center",
43
+ style: {
44
+ width: width !== null && width !== void 0 ? width : "12rem",
45
+ minWidth: minWidth !== null && minWidth !== void 0 ? minWidth : "2rem",
46
+ maxWidth: maxWidth !== null && maxWidth !== void 0 ? maxWidth : "32rem"
47
+ },
48
+ children: [/*#__PURE__*/jsxs("div", {
49
+ className: "flex-1 px-2 py-1 text-sm truncate sticky start-0",
50
+ children: [icon && /*#__PURE__*/jsx(Icon, {
51
+ icon: icon,
52
+ bg: iconBg,
53
+ color: iconColor,
54
+ rtlFlip: rtlFlip
55
+ }), /*#__PURE__*/jsx("span", {
56
+ children: label !== null && label !== void 0 ? label : " "
57
+ })]
58
+ }), /*#__PURE__*/jsxs(Dropdown, {
59
+ placement: "bottom-start",
60
+ children: [/*#__PURE__*/jsx(Icon, {
61
+ icon: CoreIcons.caretDown,
62
+ className: "outline bg-base me-0.5 flex-content hidden group-hover:inline-block data-[dropdown-open]:inline-block"
63
+ }), /*#__PURE__*/jsxs(Menu, {
64
+ className: "text-sm",
65
+ children: [/*#__PURE__*/jsx(MenuItem, {
66
+ label: "Sort ascending",
67
+ icon: CoreIcons.sortAsc
68
+ }), /*#__PURE__*/jsx(MenuItem, {
69
+ label: "Sort descending",
70
+ icon: CoreIcons.sortDesc
71
+ })]
72
+ })]
73
+ }), resizable && /*#__PURE__*/jsx("div", {
74
+ className: "cursor-col-resize border-e bg-transparent border-tint-200 w-[5px] self-stretch"
75
+ })]
76
+ });
77
+ };
78
+
79
+ export { HeaderCell };
@@ -0,0 +1,133 @@
1
+ 'use client';
2
+
3
+ import _defineProperty from '@babel/runtime/helpers/defineProperty';
4
+ import { useMemo, useCallback } from 'react';
5
+ import { BodyCell } from './BodyCell.js';
6
+ import { HeaderCell } from './HeaderCell.js';
7
+ import { useTableColumns } from './useTableColumns.js';
8
+ import { useVirtualTable } from './useVirtualTable.js';
9
+ import classNames from 'classnames';
10
+ import { jsx, jsxs } from 'react/jsx-runtime';
11
+
12
+ 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; }
13
+ 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; }
14
+ var Table = function Table(_ref) {
15
+ var _columnMap$start, _columnMap$cols, _columnMap$end, _items$, _columnMap$start3, _columnMap$cols3, _columnMap$end3, _columnMap$start4, _columnMap$cols4, _columnMap$end4;
16
+ var data = _ref.data,
17
+ columns = _ref.columns;
18
+ var _useTableColumns = useTableColumns(columns),
19
+ columnMap = _useTableColumns.columnMap;
20
+ var _useVirtualTable = useVirtualTable(data),
21
+ scrollerRef = _useVirtualTable.scrollerRef,
22
+ items = _useVirtualTable.items,
23
+ getData = _useVirtualTable.getData,
24
+ totalSize = _useVirtualTable.totalSize,
25
+ measureElement = _useVirtualTable.measureElement;
26
+ var wrapperStart = useMemo(function () {
27
+ return "bg-inherit sticky start-0 flex flex-nowrap z-1";
28
+ }, []);
29
+ var wrapperEnd = useMemo(function () {
30
+ return "bg-inherit sticky end-0 flex flex-nowrap z-1 border-s -ms-px";
31
+ }, []);
32
+ var emptyCol = useCallback(function (col, idc) {
33
+ var _col$width, _col$minWidth, _col$maxWidth;
34
+ return /*#__PURE__*/jsx("div", {
35
+ className: "overflow-hidden border-e",
36
+ style: {
37
+ width: (_col$width = col.width) !== null && _col$width !== void 0 ? _col$width : "12rem",
38
+ minWidth: (_col$minWidth = col.minWidth) !== null && _col$minWidth !== void 0 ? _col$minWidth : "2rem",
39
+ maxWidth: (_col$maxWidth = col.maxWidth) !== null && _col$maxWidth !== void 0 ? _col$maxWidth : "32rem"
40
+ }
41
+ }, "blank:".concat(idc));
42
+ }, []);
43
+ return /*#__PURE__*/jsxs("div", {
44
+ className: "grid area-content overflow-auto relative",
45
+ style: {
46
+ gridTemplate: "\"head\" auto \"content\" 1fr \"foot\" auto/1fr"
47
+ },
48
+ ref: scrollerRef,
49
+ children: [/*#__PURE__*/jsxs("div", {
50
+ className: "bg-base font-medium sticky top-0 area-head border-b select-none flex flex-nowrap z-2",
51
+ children: [/*#__PURE__*/jsx("div", {
52
+ className: wrapperStart,
53
+ children: (_columnMap$start = columnMap.start) === null || _columnMap$start === void 0 ? void 0 : _columnMap$start.map(function (col, idx) {
54
+ return /*#__PURE__*/jsx(HeaderCell, _objectSpread({}, col), idx);
55
+ })
56
+ }), (_columnMap$cols = columnMap.cols) === null || _columnMap$cols === void 0 ? void 0 : _columnMap$cols.map(function (col, idx) {
57
+ return /*#__PURE__*/jsx(HeaderCell, _objectSpread({}, col), idx);
58
+ }), /*#__PURE__*/jsx("div", {
59
+ className: wrapperEnd,
60
+ children: (_columnMap$end = columnMap.end) === null || _columnMap$end === void 0 ? void 0 : _columnMap$end.map(function (col, idx) {
61
+ return /*#__PURE__*/jsx(HeaderCell, _objectSpread({}, col), idx);
62
+ })
63
+ })]
64
+ }), /*#__PURE__*/jsxs("div", {
65
+ className: "area-content flex flex-col flex-nowrap",
66
+ style: {
67
+ height: totalSize()
68
+ },
69
+ children: [/*#__PURE__*/jsx("div", {
70
+ style: {
71
+ height: (_items$ = items[0]) === null || _items$ === void 0 ? void 0 : _items$.start
72
+ }
73
+ }), items.map(function (_ref2) {
74
+ var _columnMap$start2, _columnMap$cols2, _columnMap$end2;
75
+ var index = _ref2.index,
76
+ key = _ref2.key;
77
+ return /*#__PURE__*/jsxs("div", {
78
+ className: classNames("flex flex-nowrap", index % 2 ? "bg-even" : "bg-odd"),
79
+ "data-index": index,
80
+ ref: measureElement,
81
+ children: [/*#__PURE__*/jsx("div", {
82
+ className: wrapperStart,
83
+ children: (_columnMap$start2 = columnMap.start) === null || _columnMap$start2 === void 0 ? void 0 : _columnMap$start2.map(function (col, ids) {
84
+ return /*#__PURE__*/jsx(BodyCell, {
85
+ column: col,
86
+ item: getData(index)
87
+ }, "".concat(key, ":").concat(ids));
88
+ })
89
+ }), (_columnMap$cols2 = columnMap.cols) === null || _columnMap$cols2 === void 0 ? void 0 : _columnMap$cols2.map(function (col, idc) {
90
+ return /*#__PURE__*/jsx(BodyCell, {
91
+ column: col,
92
+ item: getData(index)
93
+ }, "".concat(key, ":").concat(idc));
94
+ }), /*#__PURE__*/jsx("div", {
95
+ className: wrapperEnd,
96
+ children: (_columnMap$end2 = columnMap.end) === null || _columnMap$end2 === void 0 ? void 0 : _columnMap$end2.map(function (col, ide) {
97
+ return /*#__PURE__*/jsx(BodyCell, {
98
+ column: col,
99
+ item: getData(index)
100
+ }, "".concat(key, ":").concat(ide));
101
+ })
102
+ })]
103
+ }, key);
104
+ }), /*#__PURE__*/jsxs("div", {
105
+ className: "flex-1 flex flex-nowrap",
106
+ children: [/*#__PURE__*/jsx("div", {
107
+ className: wrapperStart,
108
+ children: (_columnMap$start3 = columnMap.start) === null || _columnMap$start3 === void 0 ? void 0 : _columnMap$start3.map(emptyCol)
109
+ }), (_columnMap$cols3 = columnMap.cols) === null || _columnMap$cols3 === void 0 ? void 0 : _columnMap$cols3.map(emptyCol), /*#__PURE__*/jsx("div", {
110
+ className: wrapperEnd,
111
+ children: (_columnMap$end3 = columnMap.end) === null || _columnMap$end3 === void 0 ? void 0 : _columnMap$end3.map(emptyCol)
112
+ })]
113
+ })]
114
+ }), /*#__PURE__*/jsxs("div", {
115
+ className: "area-foot bg-dimmed border-t sticky bottom-0 flex flex-nowrap z-2",
116
+ children: [/*#__PURE__*/jsx("div", {
117
+ className: wrapperStart,
118
+ children: (_columnMap$start4 = columnMap.start) === null || _columnMap$start4 === void 0 ? void 0 : _columnMap$start4.map(function (col, idx) {
119
+ return /*#__PURE__*/jsx(HeaderCell, _objectSpread({}, col), idx);
120
+ })
121
+ }), (_columnMap$cols4 = columnMap.cols) === null || _columnMap$cols4 === void 0 ? void 0 : _columnMap$cols4.map(function (col, idx) {
122
+ return /*#__PURE__*/jsx(HeaderCell, _objectSpread({}, col), idx);
123
+ }), /*#__PURE__*/jsx("div", {
124
+ className: wrapperEnd,
125
+ children: (_columnMap$end4 = columnMap.end) === null || _columnMap$end4 === void 0 ? void 0 : _columnMap$end4.map(function (col, idx) {
126
+ return /*#__PURE__*/jsx(HeaderCell, _objectSpread({}, col), idx);
127
+ })
128
+ })]
129
+ })]
130
+ });
131
+ };
132
+
133
+ export { Table };
@@ -0,0 +1,26 @@
1
+ 'use client';
2
+
3
+ import _slicedToArray from '@babel/runtime/helpers/slicedToArray';
4
+ import { groupBy } from '@react-fabric/utilities';
5
+ import { useState, useEffect } from 'react';
6
+
7
+ var useTableColumns = function useTableColumns(columns) {
8
+ var _useState = useState({
9
+ start: [],
10
+ end: [],
11
+ cols: []
12
+ }),
13
+ _useState2 = _slicedToArray(_useState, 2),
14
+ columnMap = _useState2[0],
15
+ setColumnMap = _useState2[1];
16
+ useEffect(function () {
17
+ setColumnMap(groupBy(columns.filter(function (col) {
18
+ return !(col.hideable && col.hidden);
19
+ }), "locked", "cols"));
20
+ }, [columns]);
21
+ return {
22
+ columnMap: columnMap
23
+ };
24
+ };
25
+
26
+ export { useTableColumns };
@@ -0,0 +1,56 @@
1
+ 'use client';
2
+
3
+ import { useVirtualizer } from '@tanstack/react-virtual';
4
+ import { useRef, useCallback } from 'react';
5
+
6
+ /*
7
+ * React Fabric
8
+ * @version: 1.0.0
9
+ *
10
+ *
11
+ * The MIT License (MIT)
12
+ * Copyright (c) 2024 Adarsh Pastakia
13
+ *
14
+ * Permission is hereby granted, free of charge, to any person obtaining a copy of this software
15
+ * and associated documentation files (the "Software"), to deal in the Software without restriction,
16
+ * including without limitation the rights to use, copy, modify, merge, publish, distribute, sublicense,
17
+ * and/or sell copies of the Software, and to permit persons to whom the Software is furnished to do so,
18
+ * subject to the following conditions:
19
+ *
20
+ * The above copyright notice and this permission notice shall be included in all copies or substantial
21
+ * portions of the Software.
22
+ *
23
+ * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED
24
+ * TO THE WARRANTIES OF MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL
25
+ * THE AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION OF CONTRACT,
26
+ * TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.
27
+ */
28
+
29
+ var useVirtualTable = function useVirtualTable(data) {
30
+ // TODO: refactor data into item list, apply grouping if groupColumn provided
31
+ // TODO: when grouping maintain map of group with children, {___GROUP___:true, label, items, open}
32
+
33
+ var scrollerRef = useRef(null);
34
+ var virtualizer = useVirtualizer({
35
+ count: data.length,
36
+ getScrollElement: function getScrollElement() {
37
+ return scrollerRef.current;
38
+ },
39
+ estimateSize: function estimateSize() {
40
+ return 24;
41
+ }
42
+ });
43
+ var virtualItems = virtualizer.getVirtualItems();
44
+ var getData = useCallback(function (index) {
45
+ return data[index];
46
+ }, [data]);
47
+ return {
48
+ scrollerRef: scrollerRef,
49
+ items: virtualItems,
50
+ getData: getData,
51
+ totalSize: virtualizer.getTotalSize,
52
+ measureElement: virtualizer.measureElement
53
+ };
54
+ };
55
+
56
+ export { useVirtualTable };
@@ -0,0 +1,107 @@
1
+ 'use client';
2
+
3
+ import _defineProperty from '@babel/runtime/helpers/defineProperty';
4
+ import { getBadgeProps, Icon, CoreIcons, Badge } from '@react-fabric/core';
5
+ import classNames from 'classnames';
6
+ import { useMemo } from 'react';
7
+ import { jsxs, jsx } from 'react/jsx-runtime';
8
+
9
+ 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; }
10
+ 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; }
11
+ var TreeNode = function TreeNode(_ref) {
12
+ var node = _ref.node,
13
+ noLines = _ref.noLines,
14
+ expanders = _ref.expanders,
15
+ checkable = _ref.checkable,
16
+ selectable = _ref.selectable,
17
+ defaultLeafIcon = _ref.defaultLeafIcon,
18
+ defaultNodeIcon = _ref.defaultNodeIcon,
19
+ onToggle = _ref.onToggle,
20
+ onSelect = _ref.onSelect,
21
+ onChecked = _ref.onChecked,
22
+ children = _ref.children;
23
+ var badgeProps = useMemo(function () {
24
+ return getBadgeProps(node.badge);
25
+ }, [node.badge]);
26
+ var filler = useMemo(function () {
27
+ return node.lines.slice(noLines ? 1 : 0).map(function (line, idx) {
28
+ return /*#__PURE__*/jsxs("svg", {
29
+ viewBox: "0 0 24 24",
30
+ className: "flex-initial w-6 fill-tint-200",
31
+ children: [line === 0 && /*#__PURE__*/jsx("path", {
32
+ d: ""
33
+ }), !noLines && line === 1 && /*#__PURE__*/jsx("path", {
34
+ d: "M7.45 26.1v-28.2h1.1v28.2h-1.1z"
35
+ }), !noLines && line === 2 && /*#__PURE__*/jsx("path", {
36
+ d: "M14.989 12.389l0.161-0.389-0.161-0.389-0.389-0.161h-6.050v-13.55h-1.1v14.1l0.161 0.389 0.389 0.161h6.6z"
37
+ }), !noLines && line === 3 && /*#__PURE__*/jsx("path", {
38
+ d: "M8.55 12.55h6.050l0.389-0.161 0.161-0.389-0.161-0.389-0.389-0.161h-6.050v-13.55h-1.1v28.2h1.1z"
39
+ })]
40
+ }, idx);
41
+ });
42
+ }, [noLines, node.lines]);
43
+ var nodeIcon = useMemo(function () {
44
+ if (node.icon) return node.icon;
45
+ return node.leaf ? defaultLeafIcon : defaultNodeIcon;
46
+ }, [defaultLeafIcon, defaultNodeIcon, node.icon]);
47
+ var canCheck = useMemo(function () {
48
+ return checkable === true || checkable === "leafOnly" && node.leaf;
49
+ }, [node.leaf, checkable]);
50
+ var canSelect = useMemo(function () {
51
+ return !node.disabled && (selectable === true || selectable === "leafOnly" && node.leaf);
52
+ }, [node.leaf, node.disabled, selectable]);
53
+ return /*#__PURE__*/jsxs("div", {
54
+ role: "treeitem",
55
+ "aria-selected": node.selected,
56
+ className: "flex flex-nowrap",
57
+ "data-testid": node["data-testid"],
58
+ "data-test-value": node["data-test-value"],
59
+ children: [filler, !node.leaf && !node.childFiltered && /*#__PURE__*/jsx("div", {
60
+ className: "flex-initial w-6",
61
+ children: /*#__PURE__*/jsx(Icon, {
62
+ rtlFlip: true,
63
+ onClick: function onClick() {
64
+ return !node.leaf && onToggle(node.id);
65
+ },
66
+ icon: node.open ? expanders[1] : expanders[0],
67
+ className: "text-tint-600 hover:text-primary-600"
68
+ })
69
+ }), canCheck && /*#__PURE__*/jsx("div", {
70
+ className: "flex-initial w-6",
71
+ children: /*#__PURE__*/jsx(Icon, {
72
+ onClick: function onClick() {
73
+ return !node.disabled && onChecked(node.id);
74
+ },
75
+ icon: node.checked === 2 ? CoreIcons.checkboxInt : node.checked === 1 ? CoreIcons.checkboxOn : CoreIcons.checkboxOff,
76
+ className: classNames(node.disabled ? "text-muted" : "text-primary-500 hover:text-primary-600")
77
+ })
78
+ }), /*#__PURE__*/jsxs("div", {
79
+ role: "none",
80
+ className: classNames("group data-[selected]:bg-primary-100 flex flex-nowrap flex-1 items-center overflow-hidden select-none", node.childSelected && "font-medium", canSelect && "hover:bg-primary-50 cursor-pointer"),
81
+ "data-selected": node.selected,
82
+ onClick: function onClick() {
83
+ return canSelect ? onSelect(node.id) : canCheck ? onChecked(node.id) : onToggle(node.id);
84
+ },
85
+ children: [nodeIcon && /*#__PURE__*/jsx("div", {
86
+ className: "flex-content w-6",
87
+ children: /*#__PURE__*/jsx(Icon, {
88
+ icon: nodeIcon,
89
+ bg: node.iconBg,
90
+ color: node.iconColor,
91
+ rtlFlip: node.rtlFlip
92
+ })
93
+ }), node.childSelected && !node.open && /*#__PURE__*/jsx("span", {
94
+ className: " flex-content text-primary-500",
95
+ children: "\u2022"
96
+ }), /*#__PURE__*/jsx("div", {
97
+ role: "none",
98
+ className: "flex-1 truncate",
99
+ children: children
100
+ }), node.badge && /*#__PURE__*/jsx(Badge, _objectSpread(_objectSpread({}, badgeProps), {}, {
101
+ className: classNames("me-1 self-center flex-content bg-opacity-50", badgeProps.className)
102
+ }))]
103
+ })]
104
+ });
105
+ };
106
+
107
+ export { TreeNode };
@@ -0,0 +1,136 @@
1
+ 'use client';
2
+
3
+ import _defineProperty from '@babel/runtime/helpers/defineProperty';
4
+ import _objectWithoutProperties from '@babel/runtime/helpers/objectWithoutProperties';
5
+ import { CoreIcons, Section, Header, Icon, ButtonGroup, Button } from '@react-fabric/core';
6
+ import { Search } from '@react-fabric/form';
7
+ import { useVirtualizer } from '@tanstack/react-virtual';
8
+ import { useRef, useMemo } from 'react';
9
+ import { TreeNode } from './TreeNode.js';
10
+ import { iconExpandAll, iconCollapseAll } from './types.js';
11
+ import { useTree } from './useTree.js';
12
+ import { jsxs, jsx } from 'react/jsx-runtime';
13
+
14
+ var _excluded = ["items", "selected", "checked", "checkable", "noLines", "renderer", "searchable", "selectable", "matcher", "filterPlaceholder", "defaultLeafIcon", "defaultNodeIcon", "expander", "onChecked", "onLoad", "onSelect"];
15
+ 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; }
16
+ 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; }
17
+ var TreePanel = function TreePanel(_ref) {
18
+ var _virtualItems$;
19
+ var items = _ref.items,
20
+ selected = _ref.selected,
21
+ checked = _ref.checked,
22
+ checkable = _ref.checkable,
23
+ noLines = _ref.noLines,
24
+ renderer = _ref.renderer,
25
+ searchable = _ref.searchable,
26
+ selectable = _ref.selectable,
27
+ matcher = _ref.matcher,
28
+ filterPlaceholder = _ref.filterPlaceholder,
29
+ defaultLeafIcon = _ref.defaultLeafIcon,
30
+ defaultNodeIcon = _ref.defaultNodeIcon,
31
+ _ref$expander = _ref.expander,
32
+ expander = _ref$expander === void 0 ? "box" : _ref$expander,
33
+ onChecked = _ref.onChecked;
34
+ _ref.onLoad;
35
+ var onSelect = _ref.onSelect,
36
+ aria = _objectWithoutProperties(_ref, _excluded);
37
+ var _useTree = useTree({
38
+ items: items,
39
+ checked: checked,
40
+ selected: selected,
41
+ matcher: matcher,
42
+ onSelect: onSelect,
43
+ onChecked: onChecked
44
+ }),
45
+ tree = _useTree.tree,
46
+ toggleExpand = _useTree.toggleExpand,
47
+ toggleCheck = _useTree.toggleCheck,
48
+ expandAll = _useTree.expandAll,
49
+ collapseAll = _useTree.collapseAll,
50
+ select = _useTree.select,
51
+ onFilter = _useTree.onFilter;
52
+ var scrollerRef = useRef(null);
53
+ var virtualizer = useVirtualizer({
54
+ count: tree.length,
55
+ getScrollElement: function getScrollElement() {
56
+ return scrollerRef.current;
57
+ },
58
+ estimateSize: function estimateSize() {
59
+ return 24;
60
+ }
61
+ });
62
+ var virtualItems = virtualizer.getVirtualItems();
63
+ var expanders = useMemo(function () {
64
+ if (expander === "caret") return [CoreIcons.caretRight, CoreIcons.caretDown];
65
+ if (expander === "chevron") return [CoreIcons.chevronRight, CoreIcons.chevronDown];
66
+ if (expander === "folder") return [CoreIcons.folderClosed, CoreIcons.folderOpen];
67
+ return [CoreIcons.expand, CoreIcons.collapse];
68
+ }, [expander]);
69
+ return /*#__PURE__*/jsxs(Section, {
70
+ children: [/*#__PURE__*/jsxs(Header, {
71
+ flex: true,
72
+ className: "items-center p-px justify-end overflow-hidden border-b",
73
+ children: [searchable && /*#__PURE__*/jsx(Search, {
74
+ onSearch: onFilter,
75
+ allowClear: true,
76
+ placeholder: filterPlaceholder,
77
+ noBorder: true,
78
+ decorateStart: /*#__PURE__*/jsx(Icon, {
79
+ icon: CoreIcons.filter,
80
+ className: "p-1"
81
+ })
82
+ }), /*#__PURE__*/jsxs(ButtonGroup, {
83
+ variant: "link",
84
+ className: "m-0",
85
+ children: [/*#__PURE__*/jsx(Button, {
86
+ size: "sm",
87
+ "aria-label": "expand all",
88
+ icon: iconExpandAll,
89
+ onClick: expandAll
90
+ }), /*#__PURE__*/jsx(Button, {
91
+ size: "sm",
92
+ "aria-label": "collapse all",
93
+ icon: iconCollapseAll,
94
+ onClick: collapseAll
95
+ })]
96
+ })]
97
+ }), /*#__PURE__*/jsx("div", _objectSpread(_objectSpread({
98
+ ref: scrollerRef,
99
+ role: "tree",
100
+ className: "area-content overflow-auto p-1"
101
+ }, aria), {}, {
102
+ children: /*#__PURE__*/jsxs("div", {
103
+ style: {
104
+ height: virtualizer.getTotalSize()
105
+ },
106
+ children: [/*#__PURE__*/jsx("div", {
107
+ style: {
108
+ height: (_virtualItems$ = virtualItems[0]) === null || _virtualItems$ === void 0 ? void 0 : _virtualItems$.start
109
+ }
110
+ }), virtualItems.map(function (_ref2) {
111
+ var index = _ref2.index,
112
+ key = _ref2.key;
113
+ return /*#__PURE__*/jsx("div", {
114
+ "data-index": index,
115
+ ref: virtualizer.measureElement,
116
+ children: /*#__PURE__*/jsx(TreeNode, {
117
+ node: tree[index],
118
+ noLines: noLines,
119
+ expanders: expanders,
120
+ checkable: checkable,
121
+ selectable: selectable,
122
+ defaultLeafIcon: defaultLeafIcon,
123
+ defaultNodeIcon: defaultNodeIcon,
124
+ onToggle: toggleExpand,
125
+ onChecked: toggleCheck,
126
+ onSelect: select,
127
+ children: tree[index].data && (renderer === null || renderer === void 0 ? void 0 : renderer(tree[index].data)) || tree[index].label
128
+ })
129
+ }, key);
130
+ })]
131
+ })
132
+ }))]
133
+ });
134
+ };
135
+
136
+ export { TreePanel };
@@ -0,0 +1,29 @@
1
+ 'use client';
2
+
3
+ /*
4
+ * React Fabric
5
+ * @version: 1.0.0
6
+ *
7
+ *
8
+ * The MIT License (MIT)
9
+ * Copyright (c) 2024 Adarsh Pastakia
10
+ *
11
+ * Permission is hereby granted, free of charge, to any person obtaining a copy of this software
12
+ * and associated documentation files (the "Software"), to deal in the Software without restriction,
13
+ * including without limitation the rights to use, copy, modify, merge, publish, distribute, sublicense,
14
+ * and/or sell copies of the Software, and to permit persons to whom the Software is furnished to do so,
15
+ * subject to the following conditions:
16
+ *
17
+ * The above copyright notice and this permission notice shall be included in all copies or substantial
18
+ * portions of the Software.
19
+ *
20
+ * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED
21
+ * TO THE WARRANTIES OF MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL
22
+ * THE AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION OF CONTRACT,
23
+ * TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.
24
+ */
25
+
26
+ var iconExpandAll = "M12.984 9v6h3l-3.984 3.984-3.984-3.984h3v-6h-3l3.984-3.984 3.984 3.984h-3zM3.984 2.016h16.031v1.969h-16.031v-1.969zM3.984 20.016h16.031v1.969h-16.031v-1.969z";
27
+ var iconCollapseAll = "M3.984 11.016h16.031v1.969h-16.031v-1.969zM15.984 5.016l-3.984 3.984-3.984-3.984h3v-4.031h1.969v4.031h3zM8.016 18.984l3.984-3.984 3.984 3.984h-3v4.031h-1.969v-4.031h-3z";
28
+
29
+ export { iconCollapseAll, iconExpandAll };