@azrico/reactgrid 1.2.0 → 1.2.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.
package/dist/index.js CHANGED
@@ -1,21 +1,3 @@
1
- "use strict";
2
-
3
- Object.defineProperty(exports, "__esModule", {
4
- value: true
5
- });
6
- var _exportNames = {};
7
- exports.default = void 0;
8
- var _src = require("./src");
9
- Object.keys(_src).forEach(function (key) {
10
- if (key === "default" || key === "__esModule") return;
11
- if (Object.prototype.hasOwnProperty.call(_exportNames, key)) return;
12
- if (key in exports && exports[key] === _src[key]) return;
13
- Object.defineProperty(exports, key, {
14
- enumerable: true,
15
- get: function () {
16
- return _src[key];
17
- }
18
- });
19
- });
20
- var _default = _src.AzGrid;
21
- exports.default = _default;
1
+ export * from './src';
2
+ import { AzGrid } from './src';
3
+ export default AzGrid;
@@ -1,150 +1,113 @@
1
- "use strict";
2
-
3
- Object.defineProperty(exports, "__esModule", {
4
- value: true
5
- });
6
- var _exportNames = {
7
- ExampleGrid: true
8
- };
9
- exports.ExampleGrid = ExampleGrid;
10
- exports.default = void 0;
11
- var _DataGrid = _interopRequireWildcard(require("./views/DataGrid"));
12
- Object.keys(_DataGrid).forEach(function (key) {
13
- if (key === "default" || key === "__esModule") return;
14
- if (Object.prototype.hasOwnProperty.call(_exportNames, key)) return;
15
- if (key in exports && exports[key] === _DataGrid[key]) return;
16
- Object.defineProperty(exports, key, {
17
- enumerable: true,
18
- get: function () {
19
- return _DataGrid[key];
20
- }
21
- });
22
- });
23
- var _react = _interopRequireDefault(require("react"));
24
- function _interopRequireDefault(obj) { return obj && obj.__esModule ? obj : { default: obj }; }
25
- function _getRequireWildcardCache(nodeInterop) { if (typeof WeakMap !== "function") return null; var cacheBabelInterop = new WeakMap(); var cacheNodeInterop = new WeakMap(); return (_getRequireWildcardCache = function (nodeInterop) { return nodeInterop ? cacheNodeInterop : cacheBabelInterop; })(nodeInterop); }
26
- function _interopRequireWildcard(obj, nodeInterop) { if (!nodeInterop && obj && obj.__esModule) { return obj; } if (obj === null || typeof obj !== "object" && typeof obj !== "function") { return { default: obj }; } var cache = _getRequireWildcardCache(nodeInterop); if (cache && cache.has(obj)) { return cache.get(obj); } var newObj = {}; var hasPropertyDescriptor = Object.defineProperty && Object.getOwnPropertyDescriptor; for (var key in obj) { if (key !== "default" && Object.prototype.hasOwnProperty.call(obj, key)) { var desc = hasPropertyDescriptor ? Object.getOwnPropertyDescriptor(obj, key) : null; if (desc && (desc.get || desc.set)) { Object.defineProperty(newObj, key, desc); } else { newObj[key] = obj[key]; } } } newObj.default = obj; if (cache) { cache.set(obj, newObj); } return newObj; }
27
- const columns = [{
28
- name: 'name',
29
- title: 'Category',
30
- defaultFlex: 1
31
- }, {
32
- name: 'job',
33
- title: 'Job',
34
- type: 'combo',
35
- items: ['None', 'Engineer', 'Doctor'],
36
- defaultFlex: 1
37
- }, {
38
- name: 'age',
39
- title: 'Age',
40
- defaultFlex: 1
41
- }];
42
- const editableColumns = ['job', 'age'];
43
- const contextMenuItems = ['test'];
44
- function getData(delta) {
45
- const fd = [];
46
- console.log('Delta:', delta);
47
- for (let index = 0; index < 200; index++) {
48
- const currentObject = {
49
- __table_id: String(index),
50
- name: 'user-' + index,
51
- age: 20,
52
- job: 'None'
53
- };
54
- if (delta[index] && typeof delta[index] === 'object') {
55
- for (const key in delta[index]) {
56
- currentObject[key] = delta[index][key];
57
- }
58
- }
59
- fd.push(currentObject);
60
- //if (index % 5 == 0) {
61
- // const sub_selfid = 's' + index;
62
- // fd.push({
63
- // __table_id: sub_selfid,
64
- // __parent__table_id: String(index),
65
- // name: 'sub-' + index,
66
- // age: 20,
67
- // });
68
- // if (index % 2 == 0) {
69
- // const sub2_selfid = 'ss' + index;
70
- // fd.push({
71
- // __table_id: sub2_selfid,
72
- // __parent__table_id: sub_selfid,
73
- // name: 'sub2-' + index,
74
- // age: 20,
75
- // });
76
- // }
77
- //}
78
- }
79
-
80
- return fd;
81
- }
82
- function ExampleGrid() {
83
- const [ds_reset, set_ds_reset] = _react.default.useState(0);
84
- const [delta, set_delta] = _react.default.useState({});
85
- const dataSource = _react.default.useCallback(async dt => {
86
- //console.log('Start loading');
87
- return await new Promise(resolve => {
88
- setTimeout(() => {
89
- resolve(getData(delta));
90
- }, 1000);
91
- });
92
- }, [ds_reset, delta]);
93
- function onEditComplete(params) {
94
- const {
95
- value,
96
- columnId,
97
- rowId,
98
- ...rest
99
- } = params;
100
- let new_rd = delta[rowId];
101
- if (!new_rd) new_rd = {};
102
- new_rd[columnId] = value;
103
- set_delta(d => {
104
- return {
105
- ...d,
106
- [rowId]: new_rd
107
- };
108
- });
109
- }
110
- const onRowDoubleClick = _react.default.useCallback((index, rowdata) => {
111
- console.log('dbl', (rowdata === null || rowdata === void 0 ? void 0 : rowdata.data) || rowdata);
112
- }, []);
113
- const onRowClick = _react.default.useCallback((index, rowdata) => {
114
- //console.log(rowdata?.data || rowdata);
115
- }, []);
116
- function rst_ds() {
117
- //console.log('rst_ds');
118
- set_ds_reset(s => s + 1);
119
- }
120
- return _react.default.createElement(_DataGrid.default, {
121
- dark: true,
122
- delayedSize: true,
123
- onRowClick: onRowClick,
124
- onRowDoubleClick: onRowDoubleClick,
125
- // allowChildRows
126
- // onSelectionChange={onSelectionChange}
127
- // selected={selected}
128
- contextMenuItems: contextMenuItems,
129
- // customColumns={customColumns}
130
- columns: columns,
131
- editableColumns: editableColumns,
132
- editable: true,
133
- onEditComplete: onEditComplete,
134
- // leftColumns={leftColumns}
135
- gridOptions: {
136
- // defaultFilterValue: filterValue,
137
- // remoteFilter: false,
138
- // multiSelect: true,
139
- // pagination: 'local',
140
- // defaultLimit: 100,
141
- // limit: 100,
142
- // pageSizes: [100],
143
- // rowIndexColumn: true,
144
- // checkboxColumn: true,
145
- },
146
- dataSource: dataSource
147
- });
148
- }
149
- var _default = ExampleGrid;
150
- exports.default = _default;
1
+ export * from './views/DataGrid';
2
+ import AzGrid from './views/DataGrid';
3
+ import React from 'react';
4
+ const columns = [
5
+ {
6
+ name: 'name',
7
+ title: 'Category',
8
+ defaultFlex: 1,
9
+ },
10
+ {
11
+ name: 'job',
12
+ title: 'Job',
13
+ type: 'combo',
14
+ items: ['None', 'Engineer', 'Doctor'],
15
+ defaultFlex: 1,
16
+ },
17
+ {
18
+ name: 'age',
19
+ title: 'Age',
20
+ defaultFlex: 1,
21
+ },
22
+ ];
23
+ const editableColumns = ['job', 'age'];
24
+ const contextMenuItems = ['test'];
25
+ function getData(delta) {
26
+ const fd = [];
27
+ console.log('Delta:', delta);
28
+ for (let index = 0; index < 200; index++) {
29
+ const currentObject = {
30
+ __table_id: String(index),
31
+ name: 'user-' + index,
32
+ age: 20,
33
+ job: 'None',
34
+ };
35
+ if (delta[index] && typeof delta[index] === 'object') {
36
+ for (const key in delta[index]) {
37
+ currentObject[key] = delta[index][key];
38
+ }
39
+ }
40
+ fd.push(currentObject);
41
+ //if (index % 5 == 0) {
42
+ // const sub_selfid = 's' + index;
43
+ // fd.push({
44
+ // __table_id: sub_selfid,
45
+ // __parent__table_id: String(index),
46
+ // name: 'sub-' + index,
47
+ // age: 20,
48
+ // });
49
+ // if (index % 2 == 0) {
50
+ // const sub2_selfid = 'ss' + index;
51
+ // fd.push({
52
+ // __table_id: sub2_selfid,
53
+ // __parent__table_id: sub_selfid,
54
+ // name: 'sub2-' + index,
55
+ // age: 20,
56
+ // });
57
+ // }
58
+ //}
59
+ }
60
+ return fd;
61
+ }
62
+ export function ExampleGrid() {
63
+ const [ds_reset, set_ds_reset] = React.useState(0);
64
+ const [delta, set_delta] = React.useState({});
65
+ const dataSource = React.useCallback(async (dt) => {
66
+ //console.log('Start loading');
67
+ return await new Promise((resolve) => {
68
+ setTimeout(() => {
69
+ resolve(getData(delta));
70
+ }, 1000);
71
+ });
72
+ }, [ds_reset, delta]);
73
+ function onEditComplete(params) {
74
+ const { value, columnId, rowId, ...rest } = params;
75
+ let new_rd = delta[rowId];
76
+ if (!new_rd)
77
+ new_rd = {};
78
+ new_rd[columnId] = value;
79
+ set_delta((d) => {
80
+ return { ...d, [rowId]: new_rd };
81
+ });
82
+ }
83
+ const onRowDoubleClick = React.useCallback((index, rowdata) => {
84
+ console.log('dbl', rowdata?.data || rowdata);
85
+ }, []);
86
+ const onRowClick = React.useCallback((index, rowdata) => {
87
+ //console.log(rowdata?.data || rowdata);
88
+ }, []);
89
+ function rst_ds() {
90
+ //console.log('rst_ds');
91
+ set_ds_reset((s) => s + 1);
92
+ }
93
+ return (React.createElement(AzGrid, { dark: true, delayedSize: true, onRowClick: onRowClick, onRowDoubleClick: onRowDoubleClick,
94
+ // allowChildRows
95
+ // onSelectionChange={onSelectionChange}
96
+ // selected={selected}
97
+ contextMenuItems: contextMenuItems,
98
+ // customColumns={customColumns}
99
+ columns: columns, editableColumns: editableColumns, editable: true, onEditComplete: onEditComplete,
100
+ // leftColumns={leftColumns}
101
+ gridOptions: {
102
+ // defaultFilterValue: filterValue,
103
+ // remoteFilter: false,
104
+ // multiSelect: true,
105
+ // pagination: 'local',
106
+ // defaultLimit: 100,
107
+ // limit: 100,
108
+ // pageSizes: [100],
109
+ // rowIndexColumn: true,
110
+ // checkboxColumn: true,
111
+ }, dataSource: dataSource }));
112
+ }
113
+ export default ExampleGrid;
@@ -1,80 +1,75 @@
1
- "use strict";
2
-
3
- Object.defineProperty(exports, "__esModule", {
4
- value: true
5
- });
6
- exports.fix_parent_child_relations = fix_parent_child_relations;
7
- exports.func_selection = void 0;
8
- function get_parentId(obj) {
9
- return obj.__parent__table_id || obj.parent;
10
- }
11
- function get_selfId(obj) {
12
- return obj.__table_id;
13
- }
14
- //given an array of rows, fixes parent,child relations
15
- function fix_parent_child_relations(rows) {
16
- if (!Array.isArray(rows)) rows = [];
17
- const converted_rows = rows.filter(r => r != null).map(r => {
18
- return {
19
- parent: get_parentId(r),
20
- self: get_selfId(r),
21
- data: r
22
- };
23
- });
24
- const top_level_rows = converted_rows.filter(r => !r.parent);
25
- //find children of top-level parents:
26
- for (let index = 0; index < top_level_rows.length; index++) {
27
- const mrow = top_level_rows[index];
28
- assign_children(mrow, converted_rows);
29
- }
30
- const result = top_level_rows.map(r => r.data);
31
- //console.log(result);
32
- return result;
33
- }
34
- function assign_children(row, all_rows) {
35
- const my_children = all_rows.filter(s => row.self == s.parent);
36
- if (my_children.length > 0) {
37
- //find children of my children:
38
- for (let index = 0; index < my_children.length; index++) {
39
- const child = my_children[index];
40
- assign_children(child, all_rows);
41
- }
42
- row.data.__children = my_children.map(r => r.data);
43
- } else if (!Array.isArray(row.data.__children) || row.data.__children.length == 0) row.data.__children = undefined;
44
- }
45
- class func_selection {
46
- static getVirtualElement(x = 0, y = 0) {
47
- return () => ({
48
- getBoundingClientRect: func_selection.generateGetBoundingClientRect(x, y)
49
- });
50
- }
51
- static generateGetBoundingClientRect(x = 0, y = 0) {
52
- return () => ({
53
- width: 0,
54
- height: 0,
55
- top: y,
56
- right: x,
57
- bottom: y,
58
- left: x
59
- });
60
- }
61
- static get_selectedText() {
62
- var text = '';
63
- if (window.getSelection) {
64
- var _window$getSelection;
65
- text = (_window$getSelection = window.getSelection()) === null || _window$getSelection === void 0 ? void 0 : _window$getSelection.toString();
66
- } else if (document.selection && document.selection.type != 'Control') {
67
- var _document$selection$c;
68
- text = (_document$selection$c = document.selection.createRange()) === null || _document$selection$c === void 0 ? void 0 : _document$selection$c.text;
69
- }
70
- return text || '';
71
- }
72
- static has_selection() {
73
- const slct = window.getSelection();
74
- if (slct == null) return false;
75
- if (slct.type == null) return func_selection.get_selectedText().length !== 0;
76
- if (slct.type === 'Range') return true;
77
- return false;
78
- }
79
- }
80
- exports.func_selection = func_selection;
1
+ function get_parentId(obj) {
2
+ return obj.__parent__table_id || obj.parent;
3
+ }
4
+ function get_selfId(obj) {
5
+ return obj.__table_id;
6
+ }
7
+ //given an array of rows, fixes parent,child relations
8
+ export function fix_parent_child_relations(rows) {
9
+ if (!Array.isArray(rows))
10
+ rows = [];
11
+ const converted_rows = rows
12
+ .filter((r) => r != null)
13
+ .map((r) => {
14
+ return { parent: get_parentId(r), self: get_selfId(r), data: r };
15
+ });
16
+ const top_level_rows = converted_rows.filter((r) => !r.parent);
17
+ //find children of top-level parents:
18
+ for (let index = 0; index < top_level_rows.length; index++) {
19
+ const mrow = top_level_rows[index];
20
+ assign_children(mrow, converted_rows);
21
+ }
22
+ const result = top_level_rows.map((r) => r.data);
23
+ //console.log(result);
24
+ return result;
25
+ }
26
+ function assign_children(row, all_rows) {
27
+ const my_children = all_rows.filter((s) => row.self == s.parent);
28
+ if (my_children.length > 0) {
29
+ //find children of my children:
30
+ for (let index = 0; index < my_children.length; index++) {
31
+ const child = my_children[index];
32
+ assign_children(child, all_rows);
33
+ }
34
+ row.data.__children = my_children.map((r) => r.data);
35
+ }
36
+ else if (!Array.isArray(row.data.__children) || row.data.__children.length == 0)
37
+ row.data.__children = undefined;
38
+ }
39
+ export class func_selection {
40
+ static getVirtualElement(x = 0, y = 0) {
41
+ return () => ({
42
+ getBoundingClientRect: func_selection.generateGetBoundingClientRect(x, y),
43
+ });
44
+ }
45
+ static generateGetBoundingClientRect(x = 0, y = 0) {
46
+ return () => ({
47
+ width: 0,
48
+ height: 0,
49
+ top: y,
50
+ right: x,
51
+ bottom: y,
52
+ left: x,
53
+ });
54
+ }
55
+ static get_selectedText() {
56
+ var text = '';
57
+ if (window.getSelection) {
58
+ text = window.getSelection()?.toString();
59
+ }
60
+ else if (document.selection && document.selection.type != 'Control') {
61
+ text = document.selection.createRange()?.text;
62
+ }
63
+ return text || '';
64
+ }
65
+ static has_selection() {
66
+ const slct = window.getSelection();
67
+ if (slct == null)
68
+ return false;
69
+ if (slct.type == null)
70
+ return func_selection.get_selectedText().length !== 0;
71
+ if (slct.type === 'Range')
72
+ return true;
73
+ return false;
74
+ }
75
+ }
package/dist/src/index.js CHANGED
@@ -1,25 +1,9 @@
1
- "use strict";
2
-
3
- Object.defineProperty(exports, "__esModule", {
4
- value: true
5
- });
6
- var _exportNames = {};
7
- exports.default = void 0;
8
- var _DataGrid = _interopRequireWildcard(require("./views/DataGrid"));
9
- Object.keys(_DataGrid).forEach(function (key) {
10
- if (key === "default" || key === "__esModule") return;
11
- if (Object.prototype.hasOwnProperty.call(_exportNames, key)) return;
12
- if (key in exports && exports[key] === _DataGrid[key]) return;
13
- Object.defineProperty(exports, key, {
14
- enumerable: true,
15
- get: function () {
16
- return _DataGrid[key];
17
- }
18
- });
19
- });
20
- function _getRequireWildcardCache(nodeInterop) { if (typeof WeakMap !== "function") return null; var cacheBabelInterop = new WeakMap(); var cacheNodeInterop = new WeakMap(); return (_getRequireWildcardCache = function (nodeInterop) { return nodeInterop ? cacheNodeInterop : cacheBabelInterop; })(nodeInterop); }
21
- function _interopRequireWildcard(obj, nodeInterop) { if (!nodeInterop && obj && obj.__esModule) { return obj; } if (obj === null || typeof obj !== "object" && typeof obj !== "function") { return { default: obj }; } var cache = _getRequireWildcardCache(nodeInterop); if (cache && cache.has(obj)) { return cache.get(obj); } var newObj = {}; var hasPropertyDescriptor = Object.defineProperty && Object.getOwnPropertyDescriptor; for (var key in obj) { if (key !== "default" && Object.prototype.hasOwnProperty.call(obj, key)) { var desc = hasPropertyDescriptor ? Object.getOwnPropertyDescriptor(obj, key) : null; if (desc && (desc.get || desc.set)) { Object.defineProperty(newObj, key, desc); } else { newObj[key] = obj[key]; } } } newObj.default = obj; if (cache) { cache.set(obj, newObj); } return newObj; }
22
- /* -------------------------------------------------------------------------- */
23
- var _default = _DataGrid.default; // const root = ReactDOM.createRoot(document.getElementById('testroot') as HTMLElement);
24
- // root.render(<ExampleGrid />);
25
- exports.default = _default;
1
+ export * from './views/DataGrid';
2
+ import AzGrid from './views/DataGrid';
3
+ // import ExampleGrid from './example';
4
+ // import React from 'react';
5
+ // import ReactDOM from 'react-dom/client';
6
+ /* -------------------------------------------------------------------------- */
7
+ export default AzGrid;
8
+ // const root = ReactDOM.createRoot(document.getElementById('testroot') as HTMLElement);
9
+ // root.render(<ExampleGrid />);
@@ -44,7 +44,7 @@ export type AzGridProps = {
44
44
  leftColumns?: string[];
45
45
  rightColumns?: string[];
46
46
  customColumns?: customColumnData[];
47
- contextMenuItems?: ConvertableToMenuItem[];
47
+ contextMenuItems?: ConvertableToMenuItem | ConvertableToMenuItem[];
48
48
  highlightedRow?: any;
49
49
  RowDetail?: RowDetailsFunc;
50
50
  selected?: RowSelectionValue;
@@ -65,4 +65,16 @@ export type AzGridProps = {
65
65
  className?: string;
66
66
  };
67
67
  export declare function AzGrid(props: AzGridProps): JSX.Element;
68
+ /**
69
+ * Gets name of a column from its column object
70
+ * @param obj
71
+ * @returns
72
+ */
73
+ export declare function get_col_name(obj: any): string;
74
+ /**
75
+ * Gets header of a column
76
+ * @param obj
77
+ * @returns
78
+ */
79
+ export declare function get_col_header(obj: any): string;
68
80
  export default AzGrid;