@gpa-gemstone/react-table 1.2.51 → 1.2.53

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.
@@ -21,72 +21,52 @@
21
21
  // Generated original version of source code.
22
22
  //
23
23
  // ******************************************************************************************************
24
- var __assign = (this && this.__assign) || function () {
25
- __assign = Object.assign || function(t) {
26
- for (var s, i = 1, n = arguments.length; i < n; i++) {
27
- s = arguments[i];
28
- for (var p in s) if (Object.prototype.hasOwnProperty.call(s, p))
29
- t[p] = s[p];
30
- }
31
- return t;
32
- };
33
- return __assign.apply(this, arguments);
34
- };
35
- var __spreadArray = (this && this.__spreadArray) || function (to, from, pack) {
36
- if (pack || arguments.length === 2) for (var i = 0, l = from.length, ar; i < l; i++) {
37
- if (ar || !(i in from)) {
38
- if (!ar) ar = Array.prototype.slice.call(from, 0, i);
39
- ar[i] = from[i];
40
- }
41
- }
42
- return to.concat(ar || Array.prototype.slice.call(from));
43
- };
44
24
  Object.defineProperty(exports, "__esModule", { value: true });
45
25
  exports.SelectTable = SelectTable;
46
- var React = require("react");
47
- var _ = require("lodash");
48
- var Table_1 = require("./Table");
26
+ const React = require("react");
27
+ const _ = require("lodash");
28
+ const Table_1 = require("./Table");
49
29
  function SelectTable(props) {
50
- var didMountRef = React.useRef(false);
51
- var _a = React.useState(props.data), data = _a[0], setData = _a[1];
52
- var _b = React.useState([]), selected = _b[0], setSelected = _b[1];
53
- var _c = React.useState(props.sortKey), sortKey = _c[0], setSortKey = _c[1];
54
- var _d = React.useState(props.ascending), ascending = _d[0], setAscending = _d[1];
55
- React.useEffect(function () {
30
+ const didMountRef = React.useRef(false);
31
+ const [data, setData] = React.useState(props.data);
32
+ const [selected, setSelected] = React.useState([]);
33
+ const [sortKey, setSortKey] = React.useState(props.sortKey);
34
+ const [ascending, setAscending] = React.useState(props.ascending);
35
+ React.useEffect(() => {
56
36
  if (didMountRef.current)
57
37
  selectAll();
58
38
  else
59
39
  didMountRef.current = true;
60
40
  }, [props.selectAllCounter]);
61
- React.useEffect(function () {
41
+ React.useEffect(() => {
62
42
  if (props.data.length !== data.length)
63
43
  setData(props.data);
64
44
  }, [props.data]);
65
- React.useEffect(function () {
66
- setSelected(function (d) { return d.filter(function (keyItem) { return data.findIndex(function (item) { return item[props.KeyField] === keyItem; }) > -1; }); });
45
+ React.useEffect(() => {
46
+ setSelected((d) => d.filter(keyItem => data.findIndex(item => item[props.KeyField] === keyItem) > -1));
67
47
  }, [data]);
68
- React.useEffect(function () {
69
- var sortColumn = props.cols.filter(function (col) { return col.key === sortKey; })[0];
48
+ React.useEffect(() => {
49
+ const sortColumn = props.cols.filter(col => col.key === sortKey)[0];
70
50
  if (sortColumn === undefined || sortColumn.field === undefined)
71
51
  return;
72
- var sortField = sortColumn.field;
73
- setData(function (lst) { return (_.orderBy(lst, [sortField], [(ascending ? "asc" : "desc")])); });
52
+ const sortField = sortColumn.field;
53
+ setData((lst) => (_.orderBy(lst, [sortField], [(ascending ? "asc" : "desc")])));
74
54
  }, [ascending, sortKey]);
75
- React.useEffect(function () {
76
- props.onSelection(data.filter(function (item) { return selected.findIndex(function (key) { return key === item[props.KeyField]; }) > -1; }));
55
+ React.useEffect(() => {
56
+ props.onSelection(data.filter(item => selected.findIndex(key => key === item[props.KeyField]) > -1));
77
57
  }, [selected]);
78
58
  function handleClick(d) {
79
- var sIndex = selected.findIndex(function (item) { return item === d.row[props.KeyField]; });
59
+ const sIndex = selected.findIndex(item => item === d.row[props.KeyField]);
80
60
  if (sIndex === -1)
81
- setSelected(function (od) { return __spreadArray(__spreadArray([], od, true), [d.row[props.KeyField]], false); });
61
+ setSelected((od) => [...od, d.row[props.KeyField]]);
82
62
  else
83
- setSelected(function (od) { return od.filter(function (item) { return item !== d.row[props.KeyField]; }); });
63
+ setSelected((od) => od.filter(item => item !== d.row[props.KeyField]));
84
64
  }
85
65
  function selectAll() {
86
- setSelected(function (d) { if (d.length === data.length)
66
+ setSelected((d) => { if (d.length === data.length)
87
67
  return [];
88
68
  else
89
- return data.map(function (row) { return row[props.KeyField]; }); });
69
+ return data.map(row => row[props.KeyField]); });
90
70
  }
91
71
  function handleSort(d) {
92
72
  if (d.colKey === sortKey)
@@ -94,19 +74,20 @@ function SelectTable(props) {
94
74
  else
95
75
  setSortKey(d.colKey);
96
76
  }
97
- var tableProps = {
98
- cols: __spreadArray([
99
- { key: 'gemstone-checkbox', field: props.KeyField, label: '', headerStyle: { width: '4em' }, rowStyle: { width: '4em' }, content: function (item) {
100
- var index = selected.findIndex(function (i) { return i === item[props.KeyField]; });
101
- var iconClass = index > -1 ? 'fa-check-square-o' : 'fa-square-o';
77
+ const tableProps = {
78
+ cols: [
79
+ { key: 'gemstone-checkbox', field: props.KeyField, label: '', headerStyle: { width: '4em' }, rowStyle: { width: '4em' }, content: (item) => {
80
+ const index = selected.findIndex(i => i === item[props.KeyField]);
81
+ const iconClass = index > -1 ? 'fa-check-square-o' : 'fa-square-o';
102
82
  return React.createElement("div", { style: { textAlign: 'center', verticalAlign: 'middle' } },
103
- React.createElement("i", { className: "fa ".concat(iconClass, " fa-3x") }));
104
- } }
105
- ], props.cols, true),
106
- data: data,
83
+ React.createElement("i", { className: `fa ${iconClass} fa-3x` }));
84
+ } },
85
+ ...props.cols
86
+ ],
87
+ data,
107
88
  onClick: handleClick,
108
- sortKey: sortKey,
109
- ascending: ascending,
89
+ sortKey,
90
+ ascending,
110
91
  onSort: handleSort,
111
92
  tableClass: props.tableClass,
112
93
  tableStyle: props.tableStyle,
@@ -114,8 +95,8 @@ function SelectTable(props) {
114
95
  theadClass: props.theadClass,
115
96
  tbodyStyle: props.tbodyStyle,
116
97
  tbodyClass: props.tbodyClass,
117
- selected: function (d) { return false; },
98
+ selected: (d) => false,
118
99
  rowStyle: props.rowStyle
119
100
  };
120
- return React.createElement(Table_1.default, __assign({}, tableProps));
101
+ return React.createElement(Table_1.default, Object.assign({}, tableProps));
121
102
  }
package/lib/Table.js CHANGED
@@ -21,28 +21,17 @@
21
21
  // Generated original version of source code.
22
22
  //
23
23
  // ******************************************************************************************************
24
- var __assign = (this && this.__assign) || function () {
25
- __assign = Object.assign || function(t) {
26
- for (var s, i = 1, n = arguments.length; i < n; i++) {
27
- s = arguments[i];
28
- for (var p in s) if (Object.prototype.hasOwnProperty.call(s, p))
29
- t[p] = s[p];
30
- }
31
- return t;
32
- };
33
- return __assign.apply(this, arguments);
34
- };
35
24
  Object.defineProperty(exports, "__esModule", { value: true });
36
25
  exports.default = Table;
37
26
  exports.Rows = Rows;
38
27
  exports.Header = Header;
39
- var gpa_symbols_1 = require("@gpa-gemstone/gpa-symbols");
40
- var React = require("react");
28
+ const gpa_symbols_1 = require("@gpa-gemstone/gpa-symbols");
29
+ const React = require("react");
41
30
  function Table(props) {
42
31
  return (React.createElement("table", { className: props.tableClass !== undefined ? props.tableClass : '', style: props.tableStyle },
43
- React.createElement(Header, { Class: props.theadClass, Style: props.theadStyle, Cols: props.cols, SortKey: props.sortKey, Ascending: props.ascending, Click: function (d, e) { return handleSort(d, e); } }),
44
- React.createElement(Rows, { DragStart: props.onDragStart, Data: props.data, Cols: props.cols, RowStyle: props.rowStyle, BodyStyle: props.tbodyStyle, BodyClass: props.tbodyClass, Click: function (data, e) { return (props.onClick === undefined ? null : props.onClick(data, e)); }, Selected: props.selected, KeySelector: props.keySelector }),
45
- props.lastRow !== undefined ? React.createElement("tr", { style: (props.rowStyle !== undefined) ? __assign({}, props.rowStyle) : {}, key: -1 }, props.lastRow) : null));
32
+ React.createElement(Header, { Class: props.theadClass, Style: props.theadStyle, Cols: props.cols, SortKey: props.sortKey, Ascending: props.ascending, Click: (d, e) => handleSort(d, e) }),
33
+ React.createElement(Rows, { DragStart: props.onDragStart, Data: props.data, Cols: props.cols, RowStyle: props.rowStyle, BodyStyle: props.tbodyStyle, BodyClass: props.tbodyClass, Click: (data, e) => (props.onClick === undefined ? null : props.onClick(data, e)), Selected: props.selected, KeySelector: props.keySelector }),
34
+ props.lastRow !== undefined ? React.createElement("tr", { style: (props.rowStyle !== undefined) ? Object.assign({}, props.rowStyle) : {}, key: -1 }, props.lastRow) : null));
46
35
  function handleSort(data, event) {
47
36
  if (data.colKey !== null)
48
37
  props.onSort(data, event);
@@ -51,11 +40,11 @@ function Table(props) {
51
40
  function Rows(props) {
52
41
  if (props.Data.length === 0)
53
42
  return null;
54
- var rows = props.Data.map(function (item, rowIndex) {
55
- var cells = props.Cols.map(function (colData) {
56
- return React.createElement(Cell, { key: colData.key, Style: colData.rowStyle, DataKey: colData.key, DataField: colData.field, Object: item, RowIndex: rowIndex, Content: colData.content, Click: function (data, e) { return props.Click(data, e); }, DragStart: props.DragStart });
43
+ const rows = props.Data.map((item, rowIndex) => {
44
+ const cells = props.Cols.map((colData) => {
45
+ return React.createElement(Cell, { key: colData.key, Style: colData.rowStyle, DataKey: colData.key, DataField: colData.field, Object: item, RowIndex: rowIndex, Content: colData.content, Click: (data, e) => props.Click(data, e), DragStart: props.DragStart });
57
46
  });
58
- var style = (props.RowStyle !== undefined) ? __assign({}, props.RowStyle) : {};
47
+ const style = (props.RowStyle !== undefined) ? Object.assign({}, props.RowStyle) : {};
59
48
  if (style.cursor === undefined)
60
49
  style.cursor = 'pointer';
61
50
  if (props.Selected !== undefined && props.Selected(item))
@@ -70,32 +59,32 @@ function Rows(props) {
70
59
  return (React.createElement("tbody", { style: props.BodyStyle, className: props.BodyClass }, rows));
71
60
  }
72
61
  function Cell(props) {
73
- var css = (props.Style !== undefined) ? __assign({}, props.Style) : {};
62
+ const css = (props.Style !== undefined) ? Object.assign({}, props.Style) : {};
74
63
  if (props.DragStart !== undefined)
75
64
  css.cursor = "grab";
76
- var getFieldValue = function () { return props.DataField !== undefined ? props.Object[props.DataField] : null; };
77
- var getFieldContent = function () { return props.Content !== undefined ? props.Content(props.Object, props.DataKey, props.DataField, css, props.RowIndex) : getFieldValue(); };
78
- return (React.createElement("td", { style: css, onClick: function (e) { return props.Click({ colKey: props.DataKey, colField: props.DataField, row: props.Object, data: getFieldValue(), index: props.RowIndex }, e); }, draggable: props.DragStart !== undefined, onDragStart: function (e) { if (props.DragStart !== undefined)
65
+ const getFieldValue = () => props.DataField !== undefined ? props.Object[props.DataField] : null;
66
+ const getFieldContent = () => props.Content !== undefined ? props.Content(props.Object, props.DataKey, props.DataField, css, props.RowIndex) : getFieldValue();
67
+ return (React.createElement("td", { style: css, onClick: (e) => props.Click({ colKey: props.DataKey, colField: props.DataField, row: props.Object, data: getFieldValue(), index: props.RowIndex }, e), draggable: props.DragStart !== undefined, onDragStart: (e) => { if (props.DragStart !== undefined)
79
68
  props.DragStart({ colKey: props.DataKey, colField: props.DataField, row: props.Object, data: getFieldValue(), index: props.RowIndex }, e); } }, getFieldContent()));
80
69
  }
81
70
  function Header(props) {
82
71
  return (React.createElement("thead", { className: props.Class, style: props.Style },
83
- React.createElement("tr", null, props.Cols.map(function (col) { return React.createElement(HeaderCell, { key: col.key, HeaderStyle: col.headerStyle, DataKey: col.key, Click: function (e) { return props.Click({ colKey: col.key, colField: col.field, ascending: props.Ascending }, e); }, Label: col.label, SortKey: props.SortKey, Ascending: props.Ascending }); }))));
72
+ React.createElement("tr", null, props.Cols.map((col) => React.createElement(HeaderCell, { key: col.key, HeaderStyle: col.headerStyle, DataKey: col.key, Click: (e) => props.Click({ colKey: col.key, colField: col.field, ascending: props.Ascending }, e), Label: col.label, SortKey: props.SortKey, Ascending: props.Ascending })))));
84
73
  }
85
74
  function HeaderCell(props) {
86
- var style = (props.HeaderStyle !== undefined) ? props.HeaderStyle : {};
75
+ const style = (props.HeaderStyle !== undefined) ? props.HeaderStyle : {};
87
76
  if (style.cursor === undefined && props.DataKey !== null) {
88
77
  style.cursor = 'pointer';
89
78
  }
90
79
  if (style.position === undefined) {
91
80
  style.position = 'relative';
92
81
  }
93
- return (React.createElement("th", { style: style, onClick: function (e) { return props.Click(e); } },
82
+ return (React.createElement("th", { style: style, onClick: (e) => props.Click(e) },
94
83
  React.createElement(RenderAngleIcon, { SortKey: props.SortKey, Key: props.DataKey, Ascending: props.Ascending }),
95
84
  React.createElement("div", { style: { marginLeft: (props.SortKey === props.DataKey ? 25 : 0) } }, props.Label)));
96
85
  }
97
86
  function RenderAngleIcon(props) {
98
- var AngleIcon = function (a) { return a.ascending ? gpa_symbols_1.SVGIcons.ArrowDropUp : gpa_symbols_1.SVGIcons.ArrowDropDown; };
87
+ const AngleIcon = (a) => a.ascending ? gpa_symbols_1.SVGIcons.ArrowDropUp : gpa_symbols_1.SVGIcons.ArrowDropDown;
99
88
  if (props.SortKey === null)
100
89
  return null;
101
90
  if (props.SortKey !== props.Key)
package/lib/index.d.ts CHANGED
@@ -3,13 +3,13 @@ import { SelectTable, ISelectTableProps } from './SelectTable';
3
3
  import { SearchableTable } from './SearchableTable';
4
4
  import { DynamicTableProps, DynamicTable } from './DynamicTable';
5
5
  import Paging from './Paging';
6
- import AdjustableTable from './AdjustableTable/AdjustableTable';
6
+ import AdjustableTable from './AdjustableTable/Table';
7
7
  import UpdatedColumn from './AdjustableTable/Column';
8
- import AdjustableCol from './AdjustableTable/AdjustableColumn';
8
+ import AdjustableColumn from './AdjustableTable/AdjustableColumn';
9
9
  declare const ReactTable: {
10
10
  Table: typeof AdjustableTable;
11
11
  Column: typeof UpdatedColumn;
12
- AdjustableCol: typeof AdjustableCol;
12
+ AdjustableColumn: typeof AdjustableColumn;
13
13
  };
14
14
  export { ReactTable, TableProps, SelectTable, ISelectTableProps, SearchableTable, DynamicTable, DynamicTableProps, Rows, Column, Paging };
15
15
  export default Table;
package/lib/index.js CHANGED
@@ -25,23 +25,23 @@
25
25
  // ******************************************************************************************************
26
26
  Object.defineProperty(exports, "__esModule", { value: true });
27
27
  exports.Paging = exports.Rows = exports.DynamicTable = exports.SearchableTable = exports.SelectTable = exports.ReactTable = void 0;
28
- var Table_1 = require("./Table");
28
+ const Table_1 = require("./Table");
29
29
  Object.defineProperty(exports, "Rows", { enumerable: true, get: function () { return Table_1.Rows; } });
30
- var SelectTable_1 = require("./SelectTable");
30
+ const SelectTable_1 = require("./SelectTable");
31
31
  Object.defineProperty(exports, "SelectTable", { enumerable: true, get: function () { return SelectTable_1.SelectTable; } });
32
- var SearchableTable_1 = require("./SearchableTable");
32
+ const SearchableTable_1 = require("./SearchableTable");
33
33
  Object.defineProperty(exports, "SearchableTable", { enumerable: true, get: function () { return SearchableTable_1.SearchableTable; } });
34
- var DynamicTable_1 = require("./DynamicTable");
34
+ const DynamicTable_1 = require("./DynamicTable");
35
35
  Object.defineProperty(exports, "DynamicTable", { enumerable: true, get: function () { return DynamicTable_1.DynamicTable; } });
36
- var Paging_1 = require("./Paging");
36
+ const Paging_1 = require("./Paging");
37
37
  exports.Paging = Paging_1.default;
38
- var AdjustableTable_1 = require("./AdjustableTable/AdjustableTable");
39
- var Column_1 = require("./AdjustableTable/Column");
40
- var AdjustableColumn_1 = require("./AdjustableTable/AdjustableColumn");
41
- var ReactTable = {
42
- Table: AdjustableTable_1.default,
38
+ const Table_2 = require("./AdjustableTable/Table");
39
+ const Column_1 = require("./AdjustableTable/Column");
40
+ const AdjustableColumn_1 = require("./AdjustableTable/AdjustableColumn");
41
+ const ReactTable = {
42
+ Table: Table_2.default,
43
43
  Column: Column_1.default,
44
- AdjustableCol: AdjustableColumn_1.default,
44
+ AdjustableColumn: AdjustableColumn_1.default,
45
45
  };
46
46
  exports.ReactTable = ReactTable;
47
47
  exports.default = Table_1.default;
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@gpa-gemstone/react-table",
3
- "version": "1.2.51",
3
+ "version": "1.2.53",
4
4
  "description": "Table for GPA web applications",
5
5
  "main": "lib/index.js",
6
6
  "types": "lib/index.d.ts",
@@ -42,8 +42,8 @@
42
42
  "typescript": "5.5.3"
43
43
  },
44
44
  "dependencies": {
45
- "@gpa-gemstone/gpa-symbols": "0.0.40",
46
- "@gpa-gemstone/helper-functions": "0.0.33",
45
+ "@gpa-gemstone/gpa-symbols": "0.0.41",
46
+ "@gpa-gemstone/helper-functions": "0.0.34",
47
47
  "@types/lodash": "^4.14.171",
48
48
  "@types/react": "^17.0.14",
49
49
  "lodash": "^4.17.21",
@@ -1,102 +0,0 @@
1
- import * as React from 'react';
2
- interface TableProps<T> {
3
- /**
4
- * List of T objects used to generate rows
5
- */
6
- Data: T[];
7
- /**
8
- * Callback when the user clicks on a data entry
9
- * @param data contains the data including the columnKey
10
- * @param event the onClick Event to allow propagation as needed
11
- * @returns
12
- */
13
- OnClick?: (data: {
14
- colKey: string;
15
- colField?: keyof T;
16
- row: T;
17
- data: T[keyof T] | null;
18
- index: number;
19
- }, event: any) => void;
20
- /**
21
- * Key of the collumn to sort by
22
- */
23
- SortKey: string;
24
- /**
25
- * Boolen to indicate whether the sort is ascending or descending
26
- */
27
- Ascending: boolean;
28
- /**
29
- * Callback when the data should be sorted
30
- * @param data the information of the collumn including the Key of the collumn
31
- * @param event The onCLick event to allow Propagation as needed
32
- */
33
- OnSort(data: {
34
- colKey: string;
35
- colField?: keyof T;
36
- ascending: boolean;
37
- }, event: any): void;
38
- /**
39
- * Class of the table component
40
- */
41
- TableClass?: string;
42
- /**
43
- * style of the table component
44
- */
45
- TableStyle?: React.CSSProperties;
46
- /**
47
- * style of the thead component
48
- */
49
- TheadStyle?: React.CSSProperties;
50
- /**
51
- * Class of the thead component
52
- */
53
- TheadClass?: string;
54
- /**
55
- * style of the tbody component
56
- */
57
- TbodyStyle?: React.CSSProperties;
58
- /**
59
- * Class of the tbody component
60
- */
61
- TbodyClass?: string;
62
- /**
63
- * determines if a row should be styled as selected
64
- * @param data the item to be checked
65
- * @returns true if the row should be styled as selected
66
- */
67
- Selected?: (data: T, index: number) => boolean;
68
- /**
69
- *
70
- * @param data he information of the row including the item of the row
71
- * @param e the event triggering this
72
- * @returns
73
- */
74
- OnDragStart?: (data: {
75
- colKey: string;
76
- colField?: keyof T;
77
- row: T;
78
- data: T[keyof T] | null;
79
- index: number;
80
- }, e: any) => void;
81
- /**
82
- * The default style for the tr element
83
- */
84
- RowStyle?: React.CSSProperties;
85
- /**
86
- * a Function that retrieves a unique key used for React key properties
87
- * @param data the item to be turned into a key
88
- * @returns a unique Key
89
- */
90
- KeySelector: (data: T, index?: number) => string | number;
91
- /**
92
- * Optional Element to display in the last row of the Table
93
- * use this for displaying warnings when the Table content gets cut off
94
- */
95
- LastRow?: string | React.ReactNode;
96
- /**
97
- * Optional Element to display on upper Right corner
98
- */
99
- LastColumn?: string | React.ReactNode;
100
- }
101
- export default function AdjustableTable<T>(props: React.PropsWithChildren<TableProps<T>>): JSX.Element;
102
- export {};