@azrico/reactgrid 1.2.1 → 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 +3 -21
- package/dist/src/example.js +113 -150
- package/dist/src/func/helpers.js +75 -80
- package/dist/src/index.js +9 -25
- package/dist/src/views/DataGrid.d.ts +1 -1
- package/dist/src/views/DataGrid.js +457 -469
- package/dist/src/views/index.js +3 -23
- package/package.json +2 -2
- package/src/index.tsx +3 -3
- package/src/views/DataGrid.tsx +1 -1
- package/dist/src/themes/base_styles.css +0 -30
- package/dist/src/themes/grid.css +0 -20
package/dist/index.js
CHANGED
|
@@ -1,21 +1,3 @@
|
|
|
1
|
-
|
|
2
|
-
|
|
3
|
-
|
|
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;
|
package/dist/src/example.js
CHANGED
|
@@ -1,150 +1,113 @@
|
|
|
1
|
-
|
|
2
|
-
|
|
3
|
-
|
|
4
|
-
|
|
5
|
-
|
|
6
|
-
|
|
7
|
-
|
|
8
|
-
|
|
9
|
-
|
|
10
|
-
|
|
11
|
-
|
|
12
|
-
|
|
13
|
-
|
|
14
|
-
|
|
15
|
-
|
|
16
|
-
|
|
17
|
-
|
|
18
|
-
|
|
19
|
-
|
|
20
|
-
|
|
21
|
-
|
|
22
|
-
|
|
23
|
-
|
|
24
|
-
|
|
25
|
-
function
|
|
26
|
-
|
|
27
|
-
|
|
28
|
-
|
|
29
|
-
|
|
30
|
-
|
|
31
|
-
|
|
32
|
-
|
|
33
|
-
|
|
34
|
-
|
|
35
|
-
|
|
36
|
-
|
|
37
|
-
|
|
38
|
-
|
|
39
|
-
|
|
40
|
-
|
|
41
|
-
|
|
42
|
-
const
|
|
43
|
-
|
|
44
|
-
|
|
45
|
-
|
|
46
|
-
|
|
47
|
-
|
|
48
|
-
|
|
49
|
-
|
|
50
|
-
|
|
51
|
-
|
|
52
|
-
|
|
53
|
-
|
|
54
|
-
|
|
55
|
-
|
|
56
|
-
|
|
57
|
-
|
|
58
|
-
|
|
59
|
-
|
|
60
|
-
|
|
61
|
-
|
|
62
|
-
|
|
63
|
-
|
|
64
|
-
|
|
65
|
-
|
|
66
|
-
|
|
67
|
-
|
|
68
|
-
|
|
69
|
-
|
|
70
|
-
|
|
71
|
-
|
|
72
|
-
|
|
73
|
-
|
|
74
|
-
|
|
75
|
-
|
|
76
|
-
|
|
77
|
-
|
|
78
|
-
|
|
79
|
-
|
|
80
|
-
|
|
81
|
-
}
|
|
82
|
-
|
|
83
|
-
|
|
84
|
-
|
|
85
|
-
|
|
86
|
-
|
|
87
|
-
|
|
88
|
-
|
|
89
|
-
|
|
90
|
-
|
|
91
|
-
|
|
92
|
-
|
|
93
|
-
|
|
94
|
-
|
|
95
|
-
|
|
96
|
-
|
|
97
|
-
|
|
98
|
-
|
|
99
|
-
|
|
100
|
-
|
|
101
|
-
|
|
102
|
-
|
|
103
|
-
|
|
104
|
-
|
|
105
|
-
|
|
106
|
-
|
|
107
|
-
|
|
108
|
-
|
|
109
|
-
|
|
110
|
-
|
|
111
|
-
|
|
112
|
-
|
|
113
|
-
|
|
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;
|
package/dist/src/func/helpers.js
CHANGED
|
@@ -1,80 +1,75 @@
|
|
|
1
|
-
|
|
2
|
-
|
|
3
|
-
|
|
4
|
-
|
|
5
|
-
|
|
6
|
-
|
|
7
|
-
|
|
8
|
-
function
|
|
9
|
-
|
|
10
|
-
|
|
11
|
-
|
|
12
|
-
|
|
13
|
-
|
|
14
|
-
|
|
15
|
-
|
|
16
|
-
|
|
17
|
-
|
|
18
|
-
|
|
19
|
-
|
|
20
|
-
|
|
21
|
-
|
|
22
|
-
|
|
23
|
-
|
|
24
|
-
|
|
25
|
-
|
|
26
|
-
|
|
27
|
-
const
|
|
28
|
-
|
|
29
|
-
|
|
30
|
-
|
|
31
|
-
|
|
32
|
-
|
|
33
|
-
}
|
|
34
|
-
|
|
35
|
-
|
|
36
|
-
|
|
37
|
-
|
|
38
|
-
|
|
39
|
-
|
|
40
|
-
|
|
41
|
-
|
|
42
|
-
|
|
43
|
-
|
|
44
|
-
}
|
|
45
|
-
|
|
46
|
-
|
|
47
|
-
|
|
48
|
-
|
|
49
|
-
|
|
50
|
-
|
|
51
|
-
|
|
52
|
-
|
|
53
|
-
|
|
54
|
-
|
|
55
|
-
|
|
56
|
-
|
|
57
|
-
|
|
58
|
-
|
|
59
|
-
|
|
60
|
-
|
|
61
|
-
|
|
62
|
-
|
|
63
|
-
|
|
64
|
-
|
|
65
|
-
|
|
66
|
-
|
|
67
|
-
|
|
68
|
-
|
|
69
|
-
|
|
70
|
-
|
|
71
|
-
|
|
72
|
-
|
|
73
|
-
|
|
74
|
-
|
|
75
|
-
|
|
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
|
-
|
|
2
|
-
|
|
3
|
-
|
|
4
|
-
|
|
5
|
-
|
|
6
|
-
|
|
7
|
-
|
|
8
|
-
|
|
9
|
-
|
|
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;
|