pixelize-design-library 1.0.99 → 1.1.2

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.
@@ -1,4 +1,15 @@
1
1
  "use strict";
2
+ var __assign = (this && this.__assign) || function () {
3
+ __assign = Object.assign || function(t) {
4
+ for (var s, i = 1, n = arguments.length; i < n; i++) {
5
+ s = arguments[i];
6
+ for (var p in s) if (Object.prototype.hasOwnProperty.call(s, p))
7
+ t[p] = s[p];
8
+ }
9
+ return t;
10
+ };
11
+ return __assign.apply(this, arguments);
12
+ };
2
13
  var __createBinding = (this && this.__createBinding) || (Object.create ? (function(o, m, k, k2) {
3
14
  if (k2 === undefined) k2 = k;
4
15
  var desc = Object.getOwnPropertyDescriptor(m, k);
@@ -22,12 +33,21 @@ var __importStar = (this && this.__importStar) || function (mod) {
22
33
  __setModuleDefault(result, mod);
23
34
  return result;
24
35
  };
36
+ var __spreadArray = (this && this.__spreadArray) || function (to, from, pack) {
37
+ if (pack || arguments.length === 2) for (var i = 0, l = from.length, ar; i < l; i++) {
38
+ if (ar || !(i in from)) {
39
+ if (!ar) ar = Array.prototype.slice.call(from, 0, i);
40
+ ar[i] = from[i];
41
+ }
42
+ }
43
+ return to.concat(ar || Array.prototype.slice.call(from));
44
+ };
25
45
  var __importDefault = (this && this.__importDefault) || function (mod) {
26
46
  return (mod && mod.__esModule) ? mod : { "default": mod };
27
47
  };
28
48
  Object.defineProperty(exports, "__esModule", { value: true });
29
- exports.TableProps = exports.TableActionCreator = exports.TableEnums = void 0;
30
- var react_1 = __importDefault(require("react"));
49
+ exports.TableFun = exports.TableUtils = exports.TableModel = exports.TableProps = exports.TableActionCreator = exports.TableEnums = void 0;
50
+ var react_1 = __importStar(require("react"));
31
51
  var ka_table_1 = require("ka-table");
32
52
  var TableEnums = __importStar(require("ka-table/enums"));
33
53
  exports.TableEnums = TableEnums;
@@ -35,9 +55,172 @@ var TableProps = __importStar(require("ka-table/props"));
35
55
  exports.TableProps = TableProps;
36
56
  var TableActionCreator = __importStar(require("ka-table/actionCreators"));
37
57
  exports.TableActionCreator = TableActionCreator;
58
+ var TableModel = __importStar(require("ka-table/models"));
59
+ exports.TableModel = TableModel;
60
+ var TableUtils = __importStar(require("ka-table/utils"));
61
+ exports.TableUtils = TableUtils;
62
+ var TableFun = __importStar(require("ka-table"));
63
+ exports.TableFun = TableFun;
38
64
  require("ka-table/style.css");
65
+ require("./ka-table.css");
66
+ var CustomHeader_1 = __importDefault(require("./CustomHeader"));
39
67
  var KaTable = function (_a) {
40
- var columns = _a.columns, data = _a.data, _b = _a.rowKey, rowKey = _b === void 0 ? 'id' : _b, Edit = _a.Edit, shorting = _a.shorting, format = _a.format, paging = _a.paging, filter = _a.filter, childComponents = _a.childComponents, columnReorder = _a.columnReorder, columnResizing = _a.columnResizing, editableCells = _a.editableCells, validation = _a.validation, loading = _a.loading;
41
- return (react_1.default.createElement(ka_table_1.Table, { columns: columns, data: data, rowKeyField: rowKey, editingMode: Edit, sortingMode: shorting, format: format, paging: paging, filteringMode: filter, childComponents: childComponents, columnReordering: columnReorder, columnResizing: columnResizing, editableCells: editableCells, validation: validation, loading: loading }));
68
+ var columns = _a.columns, data = _a.data, _b = _a.rowKey, rowKey = _b === void 0 ? "id" : _b, Edit = _a.Edit, sorting = _a.sorting, format = _a.format, paging = _a.paging, filter = _a.filter, childComponents = _a.childComponents, columnReorder = _a.columnReorder, columnResizing = _a.columnResizing, editableCells = _a.editableCells, validation = _a.validation, loading = _a.loading, checkSelect = _a.checkSelect, onRowClick = _a.onRowClick, onSelectionChange = _a.onSelectionChange, onSortChange = _a.onSortChange, onMenuItemClick = _a.onMenuItemClick, menuItems = _a.menuItems;
69
+ var SelectionHeader = function () {
70
+ var _a;
71
+ var table = TableFun.useTableInstance();
72
+ var areAllRowsSelected = TableUtils.kaPropsUtils.areAllFilteredRowsSelected(table.props);
73
+ var selectedRows = ((_a = table.props.data) !== null && _a !== void 0 ? _a : []).filter(function (row) { var _a; return ((_a = table.props.selectedRows) !== null && _a !== void 0 ? _a : []).includes(row[rowKey]); });
74
+ var areSomeRowsSelected = selectedRows.length > 0 && !areAllRowsSelected;
75
+ var selectAllRef = (0, react_1.useRef)(null);
76
+ var prevSelectedRowsRef = (0, react_1.useRef)([]);
77
+ (0, react_1.useEffect)(function () {
78
+ if (selectAllRef.current) {
79
+ selectAllRef.current.indeterminate = areSomeRowsSelected;
80
+ }
81
+ }, [areSomeRowsSelected]);
82
+ (0, react_1.useEffect)(function () {
83
+ var prevSelectedRows = prevSelectedRowsRef.current;
84
+ if (onSelectionChange &&
85
+ selectedRows &&
86
+ JSON.stringify(prevSelectedRows) !== JSON.stringify(selectedRows)) {
87
+ var selectedRowIds = selectedRows.map(function (row) { return row[rowKey]; });
88
+ onSelectionChange(selectedRowIds);
89
+ prevSelectedRowsRef.current = selectedRows;
90
+ }
91
+ }, [selectedRows]);
92
+ return (react_1.default.createElement("input", { ref: selectAllRef, type: "checkbox", checked: areAllRowsSelected, onChange: function (event) {
93
+ if (event.currentTarget.checked) {
94
+ table.selectAllFilteredRows();
95
+ }
96
+ else {
97
+ table.deselectAllFilteredRows();
98
+ }
99
+ } }));
100
+ };
101
+ var SelectionCell = function (_a) {
102
+ var rowKeyValue = _a.rowKeyValue, isSelectedRow = _a.isSelectedRow, selectedRows = _a.selectedRows, onSelectionChange = _a.onSelectionChange, rowKey = _a.rowKey;
103
+ var table = TableFun.useTableInstance();
104
+ var prevSelectedRowsRef = (0, react_1.useRef)([]);
105
+ (0, react_1.useEffect)(function () {
106
+ var prevSelectedRows = prevSelectedRowsRef.current;
107
+ if (onSelectionChange &&
108
+ selectedRows &&
109
+ JSON.stringify(prevSelectedRows) !== JSON.stringify(selectedRows)) {
110
+ var selectedRowIds = selectedRows
111
+ .filter(function (row) { return row && row[rowKey] !== undefined; })
112
+ .map(function (row) { return row[rowKey]; });
113
+ onSelectionChange(selectedRowIds);
114
+ prevSelectedRowsRef.current = selectedRows;
115
+ }
116
+ }, [selectedRows, onSelectionChange, rowKey]);
117
+ return (react_1.default.createElement("input", { type: "checkbox", checked: isSelectedRow, onChange: function (event) {
118
+ if (event.nativeEvent.shiftKey) {
119
+ table.selectRowsRange(rowKeyValue, __spreadArray([], selectedRows, true).pop());
120
+ }
121
+ else if (event.currentTarget.checked) {
122
+ table.selectRow(rowKeyValue);
123
+ }
124
+ else {
125
+ table.deselectRow(rowKeyValue);
126
+ }
127
+ } }));
128
+ };
129
+ var selectionCellColumn = {
130
+ key: "selection-cell",
131
+ isFilterable: false,
132
+ width: 50,
133
+ columnFreeze: true,
134
+ customHeader: false,
135
+ };
136
+ if (checkSelect &&
137
+ !columns.some(function (column) { return column.key === "selection-cell"; })) {
138
+ columns.unshift(selectionCellColumn);
139
+ }
140
+ var getPreviousColumnWidth = function (key) {
141
+ var index = columns.findIndex(function (column) { return column.key === key; });
142
+ if (index > 0) {
143
+ return columns[index - 1].width;
144
+ }
145
+ return 0;
146
+ };
147
+ var mergedChildComponents = __assign(__assign({}, childComponents), { headCell: {
148
+ content: function (props) {
149
+ var _a;
150
+ var existingContent = (_a = childComponents.headCell) === null || _a === void 0 ? void 0 : _a.content;
151
+ if (existingContent) {
152
+ var result = existingContent(props);
153
+ if (result) {
154
+ return result;
155
+ }
156
+ }
157
+ if (props.column.customHeader === undefined ||
158
+ props.column.customHeader === true) {
159
+ return (react_1.default.createElement(CustomHeader_1.default, __assign({}, props, { onSortChange: onSortChange, onMenuItemClick: onMenuItemClick, menuItems: menuItems })));
160
+ }
161
+ if (props.column.key === "selection-cell") {
162
+ return react_1.default.createElement(SelectionHeader, null);
163
+ }
164
+ },
165
+ elementAttributes: function (props) {
166
+ var _a;
167
+ var existingElementAttributes = (_a = childComponents.headCell) === null || _a === void 0 ? void 0 : _a.elementAttributes;
168
+ if (existingElementAttributes) {
169
+ var result = existingElementAttributes(props);
170
+ if (result) {
171
+ return result;
172
+ }
173
+ }
174
+ if (props.column.columnFreeze) {
175
+ var stickyLeft = getPreviousColumnWidth(props.column.key);
176
+ return {
177
+ style: __assign(__assign({}, props.column.style), { position: "sticky", left: stickyLeft, zIndex: 3, backgroundColor: "#d9d9db" }),
178
+ };
179
+ }
180
+ },
181
+ }, cell: {
182
+ elementAttributes: function (props) {
183
+ var _a;
184
+ var existingElementAttributes = (_a = childComponents.cell) === null || _a === void 0 ? void 0 : _a.elementAttributes;
185
+ if (existingElementAttributes) {
186
+ var result = existingElementAttributes(props);
187
+ if (result) {
188
+ return result;
189
+ }
190
+ }
191
+ if (props.column.columnFreeze) {
192
+ var stickyLeft = getPreviousColumnWidth(props.column.key);
193
+ return {
194
+ style: __assign(__assign({}, props.column.style), { position: "sticky", left: stickyLeft, zIndex: 2, backgroundColor: "#d9d9db" }),
195
+ };
196
+ }
197
+ return {
198
+ onClick: function () {
199
+ if (onRowClick) {
200
+ onRowClick(props.rowData, props.column.key);
201
+ }
202
+ },
203
+ };
204
+ },
205
+ }, tableWrapper: {
206
+ elementAttributes: function () { return ({ style: { maxHeight: 600 } }); },
207
+ }, cellText: {
208
+ content: function (props) {
209
+ var _a;
210
+ var existingContent = (_a = childComponents.cellText) === null || _a === void 0 ? void 0 : _a.content;
211
+ if (existingContent) {
212
+ var result = existingContent(props);
213
+ if (result) {
214
+ return result;
215
+ }
216
+ }
217
+ if (props.column.key === "selection-cell") {
218
+ return react_1.default.createElement(SelectionCell, __assign({}, props));
219
+ }
220
+ },
221
+ } });
222
+ return (react_1.default.createElement(ka_table_1.Table, { columns: columns, data: data, rowKeyField: rowKey, editingMode: Edit, sortingMode: sorting, format: format, paging: paging, filteringMode: filter, childComponents: mergedChildComponents, columnReordering: columnReorder, columnResizing: columnResizing, editableCells: editableCells, validation: validation, loading: loading, virtualScrolling: {
223
+ enabled: true,
224
+ } }));
42
225
  };
43
226
  exports.default = KaTable;
@@ -3,7 +3,7 @@ export type KaTableProps = {
3
3
  data: any;
4
4
  rowKey?: any;
5
5
  Edit?: any;
6
- shorting?: any;
6
+ sorting?: any;
7
7
  format?: (props: any) => void;
8
8
  validation?: (props: any) => void;
9
9
  paging?: any;
@@ -13,4 +13,10 @@ export type KaTableProps = {
13
13
  columnResizing?: any;
14
14
  editableCells?: any;
15
15
  loading?: any;
16
+ checkSelect?: any;
17
+ onRowClick?: (rowData: any, column: any) => void;
18
+ onSelectionChange?: (selectedIds: any[]) => void;
19
+ onSortChange?: (newSortState: string, columnName: string) => void;
20
+ onMenuItemClick?: (action: string, columnName: string) => void;
21
+ menuItems?: any;
16
22
  };