@react-fabric/data 1.0.0-beta.1 → 1.0.0-beta.3

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.
@@ -19,7 +19,8 @@ function ownKeys(e, r) { var t = Object.keys(e); if (Object.getOwnPropertySymbol
19
19
  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; }
20
20
  var Table = function Table(_ref) {
21
21
  var _state$start, _state$cols, _state$end, _items$, _state$start3, _state$cols3, _state$end3;
22
- var data = _ref.data,
22
+ var ref = _ref.ref,
23
+ data = _ref.data,
23
24
  columns = _ref.columns,
24
25
  keyProperty = _ref.keyProperty,
25
26
  checkableRows = _ref.checkableRows,
@@ -46,12 +47,42 @@ var Table = function Table(_ref) {
46
47
  getData = _useVirtualTable.getData,
47
48
  totalSize = _useVirtualTable.totalSize,
48
49
  measureElement = _useVirtualTable.measureElement;
50
+ var refBody = react.useRef(null);
49
51
  var wrapperStart = react.useMemo(function () {
50
52
  return "bg-inherit sticky start-0 flex flex-nowrap z-1";
51
53
  }, []);
52
54
  var wrapperEnd = react.useMemo(function () {
53
55
  return "bg-inherit sticky end-0 flex flex-nowrap z-1 border-s -ms-px";
54
56
  }, []);
57
+ react.useImperativeHandle(ref, function () {
58
+ return {
59
+ hilight: function hilight(row) {
60
+ var _refBody$current, _refBody$current2;
61
+ (_refBody$current = refBody.current) === null || _refBody$current === void 0 || _refBody$current.querySelectorAll(".datatable-row[data-hilight=\"true\"]").forEach(function (el) {
62
+ return el && (el.dataset.hilight = undefined);
63
+ });
64
+ var el = (_refBody$current2 = refBody.current) === null || _refBody$current2 === void 0 ? void 0 : _refBody$current2.querySelector("[data-row=\"".concat(row, "\"]"));
65
+ el === null || el === void 0 || el.scrollIntoView({
66
+ behavior: "smooth",
67
+ block: "center"
68
+ });
69
+ el && (el.dataset.hilight = "true");
70
+ },
71
+ unhilight: function unhilight() {
72
+ var _refBody$current3;
73
+ (_refBody$current3 = refBody.current) === null || _refBody$current3 === void 0 || _refBody$current3.querySelectorAll(".datatable-row[data-hilight=\"true\"]").forEach(function (el) {
74
+ return el && (el.dataset.hilight = undefined);
75
+ });
76
+ },
77
+ scrollTo: function scrollTo(row) {
78
+ var _refBody$current4;
79
+ var el = (_refBody$current4 = refBody.current) === null || _refBody$current4 === void 0 ? void 0 : _refBody$current4.querySelector("[data-row=\"".concat(row, "\"]"));
80
+ el === null || el === void 0 || el.scrollIntoView({
81
+ behavior: "smooth"
82
+ });
83
+ }
84
+ };
85
+ }, []);
55
86
  return /*#__PURE__*/jsxRuntime.jsx(Context.TableProvider, {
56
87
  children: /*#__PURE__*/jsxRuntime.jsxs("div", {
57
88
  className: "grid area-content overflow-auto relative",
@@ -96,6 +127,7 @@ var Table = function Table(_ref) {
96
127
  style: {
97
128
  height: totalSize()
98
129
  },
130
+ ref: refBody,
99
131
  children: [/*#__PURE__*/jsxRuntime.jsx("div", {
100
132
  style: {
101
133
  height: (_items$ = items[0]) === null || _items$ === void 0 ? void 0 : _items$.start
@@ -107,7 +139,8 @@ var Table = function Table(_ref) {
107
139
  var data = getData(index);
108
140
  return /*#__PURE__*/jsxRuntime.jsxs("div", {
109
141
  role: "none",
110
- className: classNames("flex flex-nowrap", index % 2 ? "bg-even" : "bg-odd", onRowClick && "hover:bg-primary-50 active:bg-primary-100"),
142
+ "data-row": index,
143
+ className: classNames("flex flex-nowrap datatable-row data-[hilight]:outline-1 -outline-offset-1 outline-primary-500", index % 2 ? "bg-even" : "bg-odd", onRowClick && "hover:bg-primary-50 active:bg-primary-100"),
111
144
  onClick: function onClick() {
112
145
  return checkableRows && !onRowClick ? toggleChecked(data[keyProperty]) : onRowClick === null || onRowClick === void 0 ? void 0 : onRowClick(data);
113
146
  },
@@ -11,12 +11,13 @@ var types = require('./types.js');
11
11
  var useTree = require('./useTree.js');
12
12
  var jsxRuntime = require('react/jsx-runtime');
13
13
 
14
- var _excluded = ["items", "selected", "checked", "checkable", "noLines", "renderer", "searchable", "selectable", "matcher", "filterPlaceholder", "defaultLeafIcon", "defaultNodeIcon", "expander", "onChecked", "onLoad", "onSelect"];
14
+ var _excluded = ["ref", "items", "selected", "checked", "checkable", "noLines", "renderer", "searchable", "selectable", "matcher", "filterPlaceholder", "defaultLeafIcon", "defaultNodeIcon", "expander", "onChecked", "onLoad", "onSelect"];
15
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
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
17
  var TreePanel = function TreePanel(_ref) {
18
18
  var _virtualItems$;
19
- var items = _ref.items,
19
+ var ref = _ref.ref,
20
+ items = _ref.items,
20
21
  selected = _ref.selected,
21
22
  checked = _ref.checked,
22
23
  checkable = _ref.checkable,
@@ -48,6 +49,7 @@ var TreePanel = function TreePanel(_ref) {
48
49
  expandAll = _useTree.expandAll,
49
50
  collapseAll = _useTree.collapseAll,
50
51
  select = _useTree.select,
52
+ expand = _useTree.expand,
51
53
  onFilter = _useTree.onFilter;
52
54
  var scrollerRef = react.useRef(null);
53
55
  var virtualizer = reactVirtual.useVirtualizer({
@@ -66,6 +68,16 @@ var TreePanel = function TreePanel(_ref) {
66
68
  if (expander === "folder") return [core.CoreIcons.folderClosed, core.CoreIcons.folderOpen];
67
69
  return [core.CoreIcons.expand, core.CoreIcons.collapse];
68
70
  }, [expander]);
71
+ react.useImperativeHandle(ref, function () {
72
+ return {
73
+ open: function open(id) {
74
+ return expand(id);
75
+ },
76
+ select: function select(id) {
77
+ return expand(id);
78
+ }
79
+ };
80
+ }, []);
69
81
  return /*#__PURE__*/jsxRuntime.jsxs(core.Section, {
70
82
  children: [/*#__PURE__*/jsxRuntime.jsxs(core.Header, {
71
83
  flex: true,
@@ -151,6 +151,12 @@ var useTree = function useTree(_ref) {
151
151
  id: id
152
152
  });
153
153
  }, []);
154
+ var expand = react.useCallback(function (id) {
155
+ dispatch({
156
+ type: "expand",
157
+ id: id
158
+ });
159
+ }, []);
154
160
  var expandAll = react.useCallback(function () {
155
161
  dispatch({
156
162
  type: "expandAll"
@@ -174,6 +180,7 @@ var useTree = function useTree(_ref) {
174
180
  collapseAll: collapseAll,
175
181
  toggleCheck: toggleCheck,
176
182
  select: select,
183
+ expand: expand,
177
184
  onFilter: onFilter
178
185
  };
179
186
  };
@@ -3,7 +3,7 @@
3
3
  import _defineProperty from '@babel/runtime/helpers/defineProperty';
4
4
  import { useDebounce, Loading, EmptyContent } from '@react-fabric/core';
5
5
  import classNames from 'classnames';
6
- import { useMemo } from 'react';
6
+ import { useRef, useMemo, useImperativeHandle } from 'react';
7
7
  import { useTranslation } from 'react-i18next';
8
8
  import { AddColumn } from './AddColumn.js';
9
9
  import { BodyCell } from './BodyCell.js';
@@ -19,7 +19,8 @@ function ownKeys(e, r) { var t = Object.keys(e); if (Object.getOwnPropertySymbol
19
19
  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; }
20
20
  var Table = function Table(_ref) {
21
21
  var _state$start, _state$cols, _state$end, _items$, _state$start3, _state$cols3, _state$end3;
22
- var data = _ref.data,
22
+ var ref = _ref.ref,
23
+ data = _ref.data,
23
24
  columns = _ref.columns,
24
25
  keyProperty = _ref.keyProperty,
25
26
  checkableRows = _ref.checkableRows,
@@ -46,12 +47,42 @@ var Table = function Table(_ref) {
46
47
  getData = _useVirtualTable.getData,
47
48
  totalSize = _useVirtualTable.totalSize,
48
49
  measureElement = _useVirtualTable.measureElement;
50
+ var refBody = useRef(null);
49
51
  var wrapperStart = useMemo(function () {
50
52
  return "bg-inherit sticky start-0 flex flex-nowrap z-1";
51
53
  }, []);
52
54
  var wrapperEnd = useMemo(function () {
53
55
  return "bg-inherit sticky end-0 flex flex-nowrap z-1 border-s -ms-px";
54
56
  }, []);
57
+ useImperativeHandle(ref, function () {
58
+ return {
59
+ hilight: function hilight(row) {
60
+ var _refBody$current, _refBody$current2;
61
+ (_refBody$current = refBody.current) === null || _refBody$current === void 0 || _refBody$current.querySelectorAll(".datatable-row[data-hilight=\"true\"]").forEach(function (el) {
62
+ return el && (el.dataset.hilight = undefined);
63
+ });
64
+ var el = (_refBody$current2 = refBody.current) === null || _refBody$current2 === void 0 ? void 0 : _refBody$current2.querySelector("[data-row=\"".concat(row, "\"]"));
65
+ el === null || el === void 0 || el.scrollIntoView({
66
+ behavior: "smooth",
67
+ block: "center"
68
+ });
69
+ el && (el.dataset.hilight = "true");
70
+ },
71
+ unhilight: function unhilight() {
72
+ var _refBody$current3;
73
+ (_refBody$current3 = refBody.current) === null || _refBody$current3 === void 0 || _refBody$current3.querySelectorAll(".datatable-row[data-hilight=\"true\"]").forEach(function (el) {
74
+ return el && (el.dataset.hilight = undefined);
75
+ });
76
+ },
77
+ scrollTo: function scrollTo(row) {
78
+ var _refBody$current4;
79
+ var el = (_refBody$current4 = refBody.current) === null || _refBody$current4 === void 0 ? void 0 : _refBody$current4.querySelector("[data-row=\"".concat(row, "\"]"));
80
+ el === null || el === void 0 || el.scrollIntoView({
81
+ behavior: "smooth"
82
+ });
83
+ }
84
+ };
85
+ }, []);
55
86
  return /*#__PURE__*/jsx(TableProvider, {
56
87
  children: /*#__PURE__*/jsxs("div", {
57
88
  className: "grid area-content overflow-auto relative",
@@ -96,6 +127,7 @@ var Table = function Table(_ref) {
96
127
  style: {
97
128
  height: totalSize()
98
129
  },
130
+ ref: refBody,
99
131
  children: [/*#__PURE__*/jsx("div", {
100
132
  style: {
101
133
  height: (_items$ = items[0]) === null || _items$ === void 0 ? void 0 : _items$.start
@@ -107,7 +139,8 @@ var Table = function Table(_ref) {
107
139
  var data = getData(index);
108
140
  return /*#__PURE__*/jsxs("div", {
109
141
  role: "none",
110
- className: classNames("flex flex-nowrap", index % 2 ? "bg-even" : "bg-odd", onRowClick && "hover:bg-primary-50 active:bg-primary-100"),
142
+ "data-row": index,
143
+ className: classNames("flex flex-nowrap datatable-row data-[hilight]:outline-1 -outline-offset-1 outline-primary-500", index % 2 ? "bg-even" : "bg-odd", onRowClick && "hover:bg-primary-50 active:bg-primary-100"),
111
144
  onClick: function onClick() {
112
145
  return checkableRows && !onRowClick ? toggleChecked(data[keyProperty]) : onRowClick === null || onRowClick === void 0 ? void 0 : onRowClick(data);
113
146
  },
@@ -5,18 +5,19 @@ import _objectWithoutProperties from '@babel/runtime/helpers/objectWithoutProper
5
5
  import { CoreIcons, Section, Header, Icon, ButtonGroup, Button } from '@react-fabric/core';
6
6
  import { Search } from '@react-fabric/form';
7
7
  import { useVirtualizer } from '@tanstack/react-virtual';
8
- import { useRef, useMemo } from 'react';
8
+ import { useRef, useMemo, useImperativeHandle } from 'react';
9
9
  import { TreeNode } from './TreeNode.js';
10
10
  import { iconExpandAll, iconCollapseAll } from './types.js';
11
11
  import { useTree } from './useTree.js';
12
12
  import { jsxs, jsx } from 'react/jsx-runtime';
13
13
 
14
- var _excluded = ["items", "selected", "checked", "checkable", "noLines", "renderer", "searchable", "selectable", "matcher", "filterPlaceholder", "defaultLeafIcon", "defaultNodeIcon", "expander", "onChecked", "onLoad", "onSelect"];
14
+ var _excluded = ["ref", "items", "selected", "checked", "checkable", "noLines", "renderer", "searchable", "selectable", "matcher", "filterPlaceholder", "defaultLeafIcon", "defaultNodeIcon", "expander", "onChecked", "onLoad", "onSelect"];
15
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
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
17
  var TreePanel = function TreePanel(_ref) {
18
18
  var _virtualItems$;
19
- var items = _ref.items,
19
+ var ref = _ref.ref,
20
+ items = _ref.items,
20
21
  selected = _ref.selected,
21
22
  checked = _ref.checked,
22
23
  checkable = _ref.checkable,
@@ -48,6 +49,7 @@ var TreePanel = function TreePanel(_ref) {
48
49
  expandAll = _useTree.expandAll,
49
50
  collapseAll = _useTree.collapseAll,
50
51
  select = _useTree.select,
52
+ expand = _useTree.expand,
51
53
  onFilter = _useTree.onFilter;
52
54
  var scrollerRef = useRef(null);
53
55
  var virtualizer = useVirtualizer({
@@ -66,6 +68,16 @@ var TreePanel = function TreePanel(_ref) {
66
68
  if (expander === "folder") return [CoreIcons.folderClosed, CoreIcons.folderOpen];
67
69
  return [CoreIcons.expand, CoreIcons.collapse];
68
70
  }, [expander]);
71
+ useImperativeHandle(ref, function () {
72
+ return {
73
+ open: function open(id) {
74
+ return expand(id);
75
+ },
76
+ select: function select(id) {
77
+ return expand(id);
78
+ }
79
+ };
80
+ }, []);
69
81
  return /*#__PURE__*/jsxs(Section, {
70
82
  children: [/*#__PURE__*/jsxs(Header, {
71
83
  flex: true,
@@ -151,6 +151,12 @@ var useTree = function useTree(_ref) {
151
151
  id: id
152
152
  });
153
153
  }, []);
154
+ var expand = useCallback(function (id) {
155
+ dispatch({
156
+ type: "expand",
157
+ id: id
158
+ });
159
+ }, []);
154
160
  var expandAll = useCallback(function () {
155
161
  dispatch({
156
162
  type: "expandAll"
@@ -174,6 +180,7 @@ var useTree = function useTree(_ref) {
174
180
  collapseAll: collapseAll,
175
181
  toggleCheck: toggleCheck,
176
182
  select: select,
183
+ expand: expand,
177
184
  onFilter: onFilter
178
185
  };
179
186
  };
@@ -3,7 +3,9 @@ export { Histogram } from "./histogram/Histogram";
3
3
  export { JsonViewer } from "./json/JsonViewer";
4
4
  export { Pagination } from "./pagination/Pagination";
5
5
  export { Table } from "./table/Table";
6
+ export { type TableRef } from "./table/types";
6
7
  export { TreePanel } from "./tree/TreePanel";
8
+ export { type TreeNodeType as TreeNode } from "./tree/types";
7
9
  export { VirtualGallery, type VirtualGalleryRef } from "./virtual/Gallery";
8
10
  export { VirtualList, type VirtualListRef } from "./virtual/List";
9
11
  export * from "./hooks/useFilteredList";
@@ -1,2 +1,2 @@
1
1
  import { type TableProps } from "./types";
2
- export declare const Table: <T extends KeyValue<any> = KeyValue<any>>({ data, columns, keyProperty, checkableRows, hideableColumns, sort, loading, onSort, onRowClick, onCheckedChanged, }: TableProps<T>) => import("react/jsx-runtime").JSX.Element;
2
+ export declare const Table: <T extends KeyValue<any> = KeyValue<any>>({ ref, data, columns, keyProperty, checkableRows, hideableColumns, sort, loading, onSort, onRowClick, onCheckedChanged, }: TableProps<T>) => import("react/jsx-runtime").JSX.Element;
@@ -1,4 +1,4 @@
1
- import { type CssProp, type IconProps, type TestProps } from "@react-fabric/core/dist/types/types";
1
+ import { type CssProp, type IconProps, type RefProp, type TestProps } from "@react-fabric/core/dist/types/types";
2
2
  import { type ReactElement } from "react";
3
3
  export declare const COL_MIN_WIDTH = "3rem";
4
4
  export declare const COL_MAX_WIDTH = "64rem";
@@ -22,7 +22,12 @@ export interface ColumnType<T = KeyValue> extends CssProp, IconProps, TestProps
22
22
  format?: string;
23
23
  renderer?: (value: AnyObject, data: T) => void;
24
24
  }
25
- export interface TableProps<T = KeyValue> {
25
+ export interface TableRef {
26
+ hilight: (row: number) => void;
27
+ unhilight: () => void;
28
+ scrollTo: (row: number) => void;
29
+ }
30
+ export interface TableProps<T = KeyValue> extends RefProp<TableRef> {
26
31
  columns: Array<ColumnType<T>>;
27
32
  data: T[];
28
33
  keyProperty: keyof T;
@@ -1,2 +1,2 @@
1
1
  import { type TreePanelProps } from "./types";
2
- export declare const TreePanel: <T extends KeyValue<any>>({ items, selected, checked, checkable, noLines, renderer, searchable, selectable, matcher, filterPlaceholder, defaultLeafIcon, defaultNodeIcon, expander, onChecked, onLoad, onSelect, ...aria }: TreePanelProps<T>) => import("react/jsx-runtime").JSX.Element;
2
+ export declare const TreePanel: <T extends KeyValue<any>>({ ref, items, selected, checked, checkable, noLines, renderer, searchable, selectable, matcher, filterPlaceholder, defaultLeafIcon, defaultNodeIcon, expander, onChecked, onLoad, onSelect, ...aria }: TreePanelProps<T>) => import("react/jsx-runtime").JSX.Element;
@@ -1,5 +1,5 @@
1
1
  /// <reference types="react" />
2
- import { type BadgeType, type ChildProp, type CssProp, type Elements, type IconProps, type TestProps } from "@react-fabric/core/dist/types/types";
2
+ import { type BadgeType, type ChildProp, type CssProp, type Elements, type IconProps, type RefProp, type TestProps } from "@react-fabric/core/dist/types/types";
3
3
  interface TreeBaseNode<T> extends IconProps, CssProp, TestProps {
4
4
  id: string;
5
5
  /**
@@ -70,7 +70,11 @@ export interface TreeNodeProps extends ChildProp {
70
70
  onSelect: (id: string) => void;
71
71
  onChecked: (id: string) => void;
72
72
  }
73
- export interface TreePanelProps<T extends KeyValue = KeyValue> extends TestProps {
73
+ export interface TreeRef {
74
+ select: (id: string) => void;
75
+ open: (id: string) => void;
76
+ }
77
+ export interface TreePanelProps<T extends KeyValue = KeyValue> extends TestProps, RefProp<TreeRef> {
74
78
  items?: Array<TreeNodeType<T>>;
75
79
  /**
76
80
  * make tree searchable
@@ -13,6 +13,7 @@ export declare const useTree: <T extends KeyValue<any>>({ items, checked, select
13
13
  collapseAll: () => void;
14
14
  toggleCheck: (id: string) => void;
15
15
  select: (id: string) => void;
16
+ expand: (id: string) => void;
16
17
  onFilter: {
17
18
  (...args: any): void;
18
19
  cancel(): void;
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@react-fabric/data",
3
- "version": "1.0.0-beta.1",
3
+ "version": "1.0.0-beta.3",
4
4
  "description": "RUF: Data package",
5
5
  "author": "Adarsh Pastakia <adarshpastakia@outlook.com>",
6
6
  "license": "MIT",
@@ -33,8 +33,8 @@
33
33
  "watch": "npm-run-all -p watch:rollup watch:dts"
34
34
  },
35
35
  "dependencies": {
36
- "@react-fabric/core": "^1.0.0-beta.1",
37
- "@react-fabric/form": "^1.0.0-beta.1",
36
+ "@react-fabric/core": "^1.0.0-beta.3",
37
+ "@react-fabric/form": "^1.0.0-beta.3",
38
38
  "@react-fabric/utilities": "^1.0.0-beta.1",
39
39
  "@tanstack/react-virtual": "^3.8.6",
40
40
  "classnames": "^2.5.1",
@@ -51,5 +51,5 @@
51
51
  "node": ">=18.12.0",
52
52
  "npm": ">=8.19.0"
53
53
  },
54
- "gitHead": "e0712d7ea2c945de876bef813b5d2dcec1218ed7"
54
+ "gitHead": "2ce2a968f48d6ffc338f5da3a0cf67232d0c6864"
55
55
  }
package/src/index.ts CHANGED
@@ -27,7 +27,9 @@ export { Histogram } from "./histogram/Histogram";
27
27
  export { JsonViewer } from "./json/JsonViewer";
28
28
  export { Pagination } from "./pagination/Pagination";
29
29
  export { Table } from "./table/Table";
30
+ export { type TableRef } from "./table/types";
30
31
  export { TreePanel } from "./tree/TreePanel";
32
+ export { type TreeNodeType as TreeNode } from "./tree/types";
31
33
  export { VirtualGallery, type VirtualGalleryRef } from "./virtual/Gallery";
32
34
  export { VirtualList, type VirtualListRef } from "./virtual/List";
33
35
 
@@ -23,7 +23,7 @@
23
23
 
24
24
  import { EmptyContent, Loading, useDebounce } from "@react-fabric/core";
25
25
  import classNames from "classnames";
26
- import { useMemo } from "react";
26
+ import { useImperativeHandle, useMemo, useRef } from "react";
27
27
  import { useTranslation } from "react-i18next";
28
28
  import { AddColumn } from "./AddColumn";
29
29
  import { BodyCell } from "./BodyCell";
@@ -36,6 +36,7 @@ import { useTableColumns } from "./useTableColumns";
36
36
  import { useVirtualTable } from "./useVirtualTable";
37
37
 
38
38
  export const Table = <T extends KeyValue = KeyValue>({
39
+ ref,
39
40
  data,
40
41
  columns,
41
42
  keyProperty,
@@ -64,6 +65,7 @@ export const Table = <T extends KeyValue = KeyValue>({
64
65
  totalSize,
65
66
  measureElement,
66
67
  } = useVirtualTable(data, keyProperty, fireCheckChanged);
68
+ const refBody = useRef<HTMLDivElement>(null);
67
69
 
68
70
  const wrapperStart = useMemo(
69
71
  () => "bg-inherit sticky start-0 flex flex-nowrap z-1",
@@ -74,6 +76,32 @@ export const Table = <T extends KeyValue = KeyValue>({
74
76
  [],
75
77
  );
76
78
 
79
+ useImperativeHandle(
80
+ ref,
81
+ () => ({
82
+ hilight: (row: number) => {
83
+ refBody.current
84
+ ?.querySelectorAll<HTMLElement>(`.datatable-row[data-hilight="true"]`)
85
+ .forEach((el) => el && (el.dataset.hilight = undefined));
86
+ const el = refBody.current?.querySelector<HTMLElement>(
87
+ `[data-row="${row}"]`,
88
+ );
89
+ el?.scrollIntoView({ behavior: "smooth", block: "center" });
90
+ el && (el.dataset.hilight = "true");
91
+ },
92
+ unhilight: () => {
93
+ refBody.current
94
+ ?.querySelectorAll<HTMLElement>(`.datatable-row[data-hilight="true"]`)
95
+ .forEach((el) => el && (el.dataset.hilight = undefined));
96
+ },
97
+ scrollTo: (row: number) => {
98
+ const el = refBody.current?.querySelector(`[data-row="${row}"]`);
99
+ el?.scrollIntoView({ behavior: "smooth" });
100
+ },
101
+ }),
102
+ [],
103
+ );
104
+
77
105
  return (
78
106
  <TableProvider>
79
107
  <div
@@ -116,6 +144,7 @@ export const Table = <T extends KeyValue = KeyValue>({
116
144
  <div
117
145
  className="area-content flex flex-col flex-nowrap"
118
146
  style={{ height: totalSize() }}
147
+ ref={refBody}
119
148
  >
120
149
  <div style={{ height: items[0]?.start }} />
121
150
  {items.map(({ index, key }) => {
@@ -124,8 +153,9 @@ export const Table = <T extends KeyValue = KeyValue>({
124
153
  <div
125
154
  key={key}
126
155
  role="none"
156
+ data-row={index}
127
157
  className={classNames(
128
- "flex flex-nowrap",
158
+ "flex flex-nowrap datatable-row data-[hilight]:outline-1 -outline-offset-1 outline-primary-500",
129
159
  index % 2 ? "bg-even" : "bg-odd",
130
160
  onRowClick && "hover:bg-primary-50 active:bg-primary-100",
131
161
  )}
@@ -24,6 +24,7 @@
24
24
  import {
25
25
  type CssProp,
26
26
  type IconProps,
27
+ type RefProp,
27
28
  type TestProps,
28
29
  } from "@react-fabric/core/dist/types/types";
29
30
  import { type ReactElement } from "react";
@@ -62,7 +63,13 @@ export interface ColumnType<T = KeyValue>
62
63
  renderer?: (value: AnyObject, data: T) => void;
63
64
  }
64
65
 
65
- export interface TableProps<T = KeyValue> {
66
+ export interface TableRef {
67
+ hilight: (row: number) => void;
68
+ unhilight: () => void;
69
+ scrollTo: (row: number) => void;
70
+ }
71
+
72
+ export interface TableProps<T = KeyValue> extends RefProp<TableRef> {
66
73
  columns: Array<ColumnType<T>>;
67
74
  data: T[];
68
75
  keyProperty: keyof T;
@@ -31,7 +31,7 @@ import {
31
31
  } from "@react-fabric/core";
32
32
  import { Search } from "@react-fabric/form";
33
33
  import { useVirtualizer } from "@tanstack/react-virtual";
34
- import { useMemo, useRef } from "react";
34
+ import { useImperativeHandle, useMemo, useRef } from "react";
35
35
  import { TreeNode } from "./TreeNode";
36
36
  import { iconCollapseAll, iconExpandAll, type TreePanelProps } from "./types";
37
37
  import { useTree } from "./useTree";
@@ -39,6 +39,7 @@ import { useTree } from "./useTree";
39
39
  // TODO: implement keyboard handler for navigating tree
40
40
 
41
41
  export const TreePanel = <T extends KeyValue>({
42
+ ref,
42
43
  items,
43
44
  selected,
44
45
  checked,
@@ -64,6 +65,7 @@ export const TreePanel = <T extends KeyValue>({
64
65
  expandAll,
65
66
  collapseAll,
66
67
  select,
68
+ expand,
67
69
  onFilter,
68
70
  } = useTree({
69
71
  items,
@@ -93,6 +95,15 @@ export const TreePanel = <T extends KeyValue>({
93
95
  return [CoreIcons.expand, CoreIcons.collapse];
94
96
  }, [expander]);
95
97
 
98
+ useImperativeHandle(
99
+ ref,
100
+ () => ({
101
+ open: (id: string) => expand(id),
102
+ select: (id: string) => expand(id),
103
+ }),
104
+ [],
105
+ );
106
+
96
107
  return (
97
108
  <Section>
98
109
  <Header
package/src/tree/types.ts CHANGED
@@ -27,6 +27,7 @@ import {
27
27
  type CssProp,
28
28
  type Elements,
29
29
  type IconProps,
30
+ type RefProp,
30
31
  type TestProps,
31
32
  } from "@react-fabric/core/dist/types/types";
32
33
 
@@ -105,8 +106,14 @@ export interface TreeNodeProps extends ChildProp {
105
106
  onChecked: (id: string) => void;
106
107
  }
107
108
 
109
+ export interface TreeRef {
110
+ select: (id: string) => void;
111
+ open: (id: string) => void;
112
+ }
113
+
108
114
  export interface TreePanelProps<T extends KeyValue = KeyValue>
109
- extends TestProps {
115
+ extends TestProps,
116
+ RefProp<TreeRef> {
110
117
  items?: Array<TreeNodeType<T>>;
111
118
  /**
112
119
  * make tree searchable
@@ -203,6 +203,10 @@ export const useTree = <T extends KeyValue>({
203
203
  dispatch({ type: "select", id });
204
204
  }, []);
205
205
 
206
+ const expand = useCallback((id: string) => {
207
+ dispatch({ type: "expand", id });
208
+ }, []);
209
+
206
210
  const expandAll = useCallback(() => {
207
211
  dispatch({ type: "expandAll" });
208
212
  }, []);
@@ -222,6 +226,7 @@ export const useTree = <T extends KeyValue>({
222
226
  collapseAll,
223
227
  toggleCheck,
224
228
  select,
229
+ expand,
225
230
  onFilter,
226
231
  };
227
232
  };