@azrico/reactgrid 1.1.11 → 1.1.13
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/README.md +3 -3
- package/index.ts +4 -4
- package/package.json +62 -62
- package/public/index.html +19 -19
- package/public/manifest.json +9 -9
- package/src/example.tsx +117 -117
- package/src/func/helpers.ts +74 -74
- package/src/index.tsx +11 -11
- package/src/themes/base_styles.css +26 -26
- package/src/themes/grid.css +20 -20
- package/src/views/DataGrid.tsx +519 -478
- package/src/views/index.ts +4 -4
- package/yarn-error.log +79 -79
- package/dist/index.d.ts +0 -3
- package/dist/index.js +0 -21
- package/dist/src/example.d.ts +0 -4
- package/dist/src/example.js +0 -123
- package/dist/src/func/helpers.d.ts +0 -29
- package/dist/src/func/helpers.js +0 -80
- package/dist/src/index.d.ts +0 -3
- package/dist/src/index.js +0 -24
- package/dist/src/themes/base_styles.css +0 -26
- package/dist/src/themes/grid.css +0 -20
- package/dist/src/views/DataGrid.d.ts +0 -66
- package/dist/src/views/DataGrid.js +0 -355
- package/dist/src/views/index.d.ts +0 -3
- package/dist/src/views/index.js +0 -23
package/README.md
CHANGED
|
@@ -1,3 +1,3 @@
|
|
|
1
|
-
**DISCLAIMER :**
|
|
2
|
-
DO NOT USE THIS PACKAGE FOR ANY REASON
|
|
3
|
-
THIS IS A PRIVATE PACKAGE
|
|
1
|
+
**DISCLAIMER :**
|
|
2
|
+
DO NOT USE THIS PACKAGE FOR ANY REASON
|
|
3
|
+
THIS IS A PRIVATE PACKAGE
|
package/index.ts
CHANGED
|
@@ -1,4 +1,4 @@
|
|
|
1
|
-
export * from './src';
|
|
2
|
-
|
|
3
|
-
import { AzGrid } from './src';
|
|
4
|
-
export default AzGrid;
|
|
1
|
+
export * from './src';
|
|
2
|
+
|
|
3
|
+
import { AzGrid } from './src';
|
|
4
|
+
export default AzGrid;
|
package/package.json
CHANGED
|
@@ -1,62 +1,62 @@
|
|
|
1
|
-
{
|
|
2
|
-
"name": "@azrico/reactgrid",
|
|
3
|
-
"version": "1.1.
|
|
4
|
-
"main": "dist/index.js",
|
|
5
|
-
"description": "React Datagrid",
|
|
6
|
-
"author": "Azrideus <MehrdadTavangar@gmail.com>",
|
|
7
|
-
"homepage": ".",
|
|
8
|
-
"scripts": {
|
|
9
|
-
"start": "react-scripts start",
|
|
10
|
-
"build": "tsc && yarn cp_themes && babel dist --out-dir dist",
|
|
11
|
-
"test": "rem",
|
|
12
|
-
"cp_themes": "copyfiles ./src/themes/* ./dist/"
|
|
13
|
-
},
|
|
14
|
-
"config-overrides-path": "../../config/config-overrides.js",
|
|
15
|
-
"devDependencies": {
|
|
16
|
-
"@babel/cli": "^7.13.14",
|
|
17
|
-
"@babel/core": "^7.13.15",
|
|
18
|
-
"@babel/eslint-parser": "^7.12.17",
|
|
19
|
-
"@babel/node": "^7.13.13",
|
|
20
|
-
"@babel/plugin-proposal-class-properties": "^7.12.13",
|
|
21
|
-
"@babel/plugin-proposal-nullish-coalescing-operator": "^7.14.5",
|
|
22
|
-
"@babel/preset-env": "^7.13.15",
|
|
23
|
-
"@babel/preset-typescript": "^7.14.5",
|
|
24
|
-
"@mui/material": "*",
|
|
25
|
-
"@types/react": "^18.0.25",
|
|
26
|
-
"@types/react-dom": "^18.0.8",
|
|
27
|
-
"react-dom": "^18.2.0",
|
|
28
|
-
"react-scripts": "^5.0.1",
|
|
29
|
-
"typescript": "^4.8.4"
|
|
30
|
-
},
|
|
31
|
-
"dependencies": {
|
|
32
|
-
"@azrico/controls": "1.3.6",
|
|
33
|
-
"@azrico/object": "^1.3.1",
|
|
34
|
-
"@emotion/react": "^11.9.3",
|
|
35
|
-
"@emotion/styled": "^11.9.3",
|
|
36
|
-
"@inovua/reactdatagrid-enterprise": "^5.8.0",
|
|
37
|
-
"clsx": "^1.2.1",
|
|
38
|
-
"react": "^18.2.0",
|
|
39
|
-
"react-resize-detector": "^7.1.2"
|
|
40
|
-
},
|
|
41
|
-
"peerDependencies": {
|
|
42
|
-
"@azrico/controls": "*",
|
|
43
|
-
"@emotion/react": "*",
|
|
44
|
-
"@emotion/styled": "*",
|
|
45
|
-
"@inovua/reactdatagrid-enterprise": "*",
|
|
46
|
-
"clsx": "*",
|
|
47
|
-
"react": "*",
|
|
48
|
-
"react-resize-detector": "*"
|
|
49
|
-
},
|
|
50
|
-
"browserslist": {
|
|
51
|
-
"production": [
|
|
52
|
-
">0.2%",
|
|
53
|
-
"not dead",
|
|
54
|
-
"not op_mini all"
|
|
55
|
-
],
|
|
56
|
-
"development": [
|
|
57
|
-
"last 1 chrome version",
|
|
58
|
-
"last 1 firefox version",
|
|
59
|
-
"last 1 safari version"
|
|
60
|
-
]
|
|
61
|
-
}
|
|
62
|
-
}
|
|
1
|
+
{
|
|
2
|
+
"name": "@azrico/reactgrid",
|
|
3
|
+
"version": "1.1.13",
|
|
4
|
+
"main": "dist/index.js",
|
|
5
|
+
"description": "React Datagrid",
|
|
6
|
+
"author": "Azrideus <MehrdadTavangar@gmail.com>",
|
|
7
|
+
"homepage": ".",
|
|
8
|
+
"scripts": {
|
|
9
|
+
"start": "react-scripts start",
|
|
10
|
+
"build": "tsc && yarn cp_themes && babel dist --out-dir dist",
|
|
11
|
+
"test": "rem",
|
|
12
|
+
"cp_themes": "copyfiles ./src/themes/* ./dist/"
|
|
13
|
+
},
|
|
14
|
+
"config-overrides-path": "../../config/config-overrides.js",
|
|
15
|
+
"devDependencies": {
|
|
16
|
+
"@babel/cli": "^7.13.14",
|
|
17
|
+
"@babel/core": "^7.13.15",
|
|
18
|
+
"@babel/eslint-parser": "^7.12.17",
|
|
19
|
+
"@babel/node": "^7.13.13",
|
|
20
|
+
"@babel/plugin-proposal-class-properties": "^7.12.13",
|
|
21
|
+
"@babel/plugin-proposal-nullish-coalescing-operator": "^7.14.5",
|
|
22
|
+
"@babel/preset-env": "^7.13.15",
|
|
23
|
+
"@babel/preset-typescript": "^7.14.5",
|
|
24
|
+
"@mui/material": "*",
|
|
25
|
+
"@types/react": "^18.0.25",
|
|
26
|
+
"@types/react-dom": "^18.0.8",
|
|
27
|
+
"react-dom": "^18.2.0",
|
|
28
|
+
"react-scripts": "^5.0.1",
|
|
29
|
+
"typescript": "^4.8.4"
|
|
30
|
+
},
|
|
31
|
+
"dependencies": {
|
|
32
|
+
"@azrico/controls": "1.3.6",
|
|
33
|
+
"@azrico/object": "^1.3.1",
|
|
34
|
+
"@emotion/react": "^11.9.3",
|
|
35
|
+
"@emotion/styled": "^11.9.3",
|
|
36
|
+
"@inovua/reactdatagrid-enterprise": "^5.8.0",
|
|
37
|
+
"clsx": "^1.2.1",
|
|
38
|
+
"react": "^18.2.0",
|
|
39
|
+
"react-resize-detector": "^7.1.2"
|
|
40
|
+
},
|
|
41
|
+
"peerDependencies": {
|
|
42
|
+
"@azrico/controls": "*",
|
|
43
|
+
"@emotion/react": "*",
|
|
44
|
+
"@emotion/styled": "*",
|
|
45
|
+
"@inovua/reactdatagrid-enterprise": "*",
|
|
46
|
+
"clsx": "*",
|
|
47
|
+
"react": "*",
|
|
48
|
+
"react-resize-detector": "*"
|
|
49
|
+
},
|
|
50
|
+
"browserslist": {
|
|
51
|
+
"production": [
|
|
52
|
+
">0.2%",
|
|
53
|
+
"not dead",
|
|
54
|
+
"not op_mini all"
|
|
55
|
+
],
|
|
56
|
+
"development": [
|
|
57
|
+
"last 1 chrome version",
|
|
58
|
+
"last 1 firefox version",
|
|
59
|
+
"last 1 safari version"
|
|
60
|
+
]
|
|
61
|
+
}
|
|
62
|
+
}
|
package/public/index.html
CHANGED
|
@@ -1,20 +1,20 @@
|
|
|
1
|
-
<!doctype html>
|
|
2
|
-
<html lang="en" class="azgrid-filler azgrid-borderbox azgrid-nopad azgrid-nomargin">
|
|
3
|
-
|
|
4
|
-
<head>
|
|
5
|
-
<meta charset="utf-8">
|
|
6
|
-
<meta name="viewport" content="width=device-width, user-scalable=no">
|
|
7
|
-
<link rel="manifest" href="%PUBLIC_URL%/manifest.json">
|
|
8
|
-
<link rel="shortcut icon" href="%PUBLIC_URL%/favicon.ico">
|
|
9
|
-
|
|
10
|
-
<title>Azriel's React Grid</title>
|
|
11
|
-
</head>
|
|
12
|
-
|
|
13
|
-
<body class="azgrid-nomargin azgrid-filler azgrid-borderbox">
|
|
14
|
-
<noscript>
|
|
15
|
-
You need to enable JavaScript to run this app.
|
|
16
|
-
</noscript>
|
|
17
|
-
<div id="testroot" class="azgrid-filler azgrid-testborder azgrid-borderbox azgrid-nopad azgrid-nomargin"></div>
|
|
18
|
-
</body>
|
|
19
|
-
|
|
1
|
+
<!doctype html>
|
|
2
|
+
<html lang="en" class="azgrid-filler azgrid-borderbox azgrid-nopad azgrid-nomargin">
|
|
3
|
+
|
|
4
|
+
<head>
|
|
5
|
+
<meta charset="utf-8">
|
|
6
|
+
<meta name="viewport" content="width=device-width, user-scalable=no">
|
|
7
|
+
<link rel="manifest" href="%PUBLIC_URL%/manifest.json">
|
|
8
|
+
<link rel="shortcut icon" href="%PUBLIC_URL%/favicon.ico">
|
|
9
|
+
|
|
10
|
+
<title>Azriel's React Grid</title>
|
|
11
|
+
</head>
|
|
12
|
+
|
|
13
|
+
<body class="azgrid-nomargin azgrid-filler azgrid-borderbox">
|
|
14
|
+
<noscript>
|
|
15
|
+
You need to enable JavaScript to run this app.
|
|
16
|
+
</noscript>
|
|
17
|
+
<div id="testroot" class="azgrid-filler azgrid-testborder azgrid-borderbox azgrid-nopad azgrid-nomargin"></div>
|
|
18
|
+
</body>
|
|
19
|
+
|
|
20
20
|
</html>
|
package/public/manifest.json
CHANGED
|
@@ -1,9 +1,9 @@
|
|
|
1
|
-
{
|
|
2
|
-
"short_name": "AzGrid",
|
|
3
|
-
"name": "React Grid Wrapper",
|
|
4
|
-
"icons": [],
|
|
5
|
-
"start_url": "./index.html",
|
|
6
|
-
"display": "standalone",
|
|
7
|
-
"theme_color": "#000000",
|
|
8
|
-
"background_color": "#ffffff"
|
|
9
|
-
}
|
|
1
|
+
{
|
|
2
|
+
"short_name": "AzGrid",
|
|
3
|
+
"name": "React Grid Wrapper",
|
|
4
|
+
"icons": [],
|
|
5
|
+
"start_url": "./index.html",
|
|
6
|
+
"display": "standalone",
|
|
7
|
+
"theme_color": "#000000",
|
|
8
|
+
"background_color": "#ffffff"
|
|
9
|
+
}
|
package/src/example.tsx
CHANGED
|
@@ -1,117 +1,117 @@
|
|
|
1
|
-
export * from './views/DataGrid';
|
|
2
|
-
|
|
3
|
-
import AzGrid from './views/DataGrid';
|
|
4
|
-
import { LooseColumnDefinition } from './views/DataGrid';
|
|
5
|
-
import React from 'react';
|
|
6
|
-
import ReactDOM from 'react-dom/client';
|
|
7
|
-
|
|
8
|
-
const columns = [
|
|
9
|
-
{
|
|
10
|
-
name: 'name',
|
|
11
|
-
title: 'Category',
|
|
12
|
-
defaultFlex: 1,
|
|
13
|
-
},
|
|
14
|
-
];
|
|
15
|
-
const leftColumns = ['username', 'row'];
|
|
16
|
-
const customColumns = [
|
|
17
|
-
{
|
|
18
|
-
name: 'job',
|
|
19
|
-
render: () => {
|
|
20
|
-
return <div>test</div>;
|
|
21
|
-
},
|
|
22
|
-
},
|
|
23
|
-
];
|
|
24
|
-
const filterValue = [
|
|
25
|
-
{
|
|
26
|
-
name: 'name',
|
|
27
|
-
operator: 'contains',
|
|
28
|
-
type: 'string',
|
|
29
|
-
value: '',
|
|
30
|
-
},
|
|
31
|
-
];
|
|
32
|
-
|
|
33
|
-
const contextMenuItems = ['test'];
|
|
34
|
-
function getData() {
|
|
35
|
-
const fd: any[] = [];
|
|
36
|
-
for (let index = 0; index < 200; index++) {
|
|
37
|
-
fd.push({ __table_id: String(index), name: 'user-' + index, age: 20 });
|
|
38
|
-
//if (index % 5 == 0) {
|
|
39
|
-
// const sub_selfid = 's' + index;
|
|
40
|
-
// fd.push({
|
|
41
|
-
// __table_id: sub_selfid,
|
|
42
|
-
// __parent__table_id: String(index),
|
|
43
|
-
// name: 'sub-' + index,
|
|
44
|
-
// age: 20,
|
|
45
|
-
// });
|
|
46
|
-
// if (index % 2 == 0) {
|
|
47
|
-
// const sub2_selfid = 'ss' + index;
|
|
48
|
-
// fd.push({
|
|
49
|
-
// __table_id: sub2_selfid,
|
|
50
|
-
// __parent__table_id: sub_selfid,
|
|
51
|
-
// name: 'sub2-' + index,
|
|
52
|
-
// age: 20,
|
|
53
|
-
// });
|
|
54
|
-
// }
|
|
55
|
-
//}
|
|
56
|
-
}
|
|
57
|
-
return fd;
|
|
58
|
-
}
|
|
59
|
-
|
|
60
|
-
export function ExampleGrid() {
|
|
61
|
-
const [ds_reset, set_ds_reset] = React.useState(0);
|
|
62
|
-
|
|
63
|
-
const dataSource = React.useCallback(
|
|
64
|
-
async (dt) => {
|
|
65
|
-
//console.log('Start loading');
|
|
66
|
-
return await new Promise((resolve) => {
|
|
67
|
-
setTimeout(() => {
|
|
68
|
-
//console.log('end loading');
|
|
69
|
-
resolve(getData());
|
|
70
|
-
}, 1000);
|
|
71
|
-
});
|
|
72
|
-
},
|
|
73
|
-
[ds_reset]
|
|
74
|
-
);
|
|
75
|
-
|
|
76
|
-
const onRowDoubleClick = React.useCallback((index: number, rowdata: any) => {
|
|
77
|
-
console.log(rowdata?.data || rowdata);
|
|
78
|
-
}, []);
|
|
79
|
-
const onRowClick = React.useCallback((index: number, rowdata: any) => {
|
|
80
|
-
//console.log(rowdata?.data || rowdata);
|
|
81
|
-
}, []);
|
|
82
|
-
|
|
83
|
-
function rst_ds() {
|
|
84
|
-
//console.log('rst_ds');
|
|
85
|
-
set_ds_reset((s) => s + 1);
|
|
86
|
-
}
|
|
87
|
-
|
|
88
|
-
return (
|
|
89
|
-
<AzGrid
|
|
90
|
-
dark
|
|
91
|
-
onRowClick={onRowClick}
|
|
92
|
-
onRowDoubleClick={onRowDoubleClick}
|
|
93
|
-
// allowChildRows
|
|
94
|
-
// onSelectionChange={onSelectionChange}
|
|
95
|
-
// selected={selected}
|
|
96
|
-
contextMenuItems={contextMenuItems}
|
|
97
|
-
// customColumns={customColumns}
|
|
98
|
-
columns={columns}
|
|
99
|
-
// leftColumns={leftColumns}
|
|
100
|
-
gridOptions={
|
|
101
|
-
{
|
|
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
|
-
}
|
|
112
|
-
}
|
|
113
|
-
dataSource={dataSource}
|
|
114
|
-
/>
|
|
115
|
-
);
|
|
116
|
-
}
|
|
117
|
-
export default ExampleGrid;
|
|
1
|
+
export * from './views/DataGrid';
|
|
2
|
+
|
|
3
|
+
import AzGrid from './views/DataGrid';
|
|
4
|
+
import { LooseColumnDefinition } from './views/DataGrid';
|
|
5
|
+
import React from 'react';
|
|
6
|
+
import ReactDOM from 'react-dom/client';
|
|
7
|
+
|
|
8
|
+
const columns = [
|
|
9
|
+
{
|
|
10
|
+
name: 'name',
|
|
11
|
+
title: 'Category',
|
|
12
|
+
defaultFlex: 1,
|
|
13
|
+
},
|
|
14
|
+
];
|
|
15
|
+
const leftColumns = ['username', 'row'];
|
|
16
|
+
const customColumns = [
|
|
17
|
+
{
|
|
18
|
+
name: 'job',
|
|
19
|
+
render: () => {
|
|
20
|
+
return <div>test</div>;
|
|
21
|
+
},
|
|
22
|
+
},
|
|
23
|
+
];
|
|
24
|
+
const filterValue = [
|
|
25
|
+
{
|
|
26
|
+
name: 'name',
|
|
27
|
+
operator: 'contains',
|
|
28
|
+
type: 'string',
|
|
29
|
+
value: '',
|
|
30
|
+
},
|
|
31
|
+
];
|
|
32
|
+
|
|
33
|
+
const contextMenuItems = ['test'];
|
|
34
|
+
function getData() {
|
|
35
|
+
const fd: any[] = [];
|
|
36
|
+
for (let index = 0; index < 200; index++) {
|
|
37
|
+
fd.push({ __table_id: String(index), name: 'user-' + index, age: 20 });
|
|
38
|
+
//if (index % 5 == 0) {
|
|
39
|
+
// const sub_selfid = 's' + index;
|
|
40
|
+
// fd.push({
|
|
41
|
+
// __table_id: sub_selfid,
|
|
42
|
+
// __parent__table_id: String(index),
|
|
43
|
+
// name: 'sub-' + index,
|
|
44
|
+
// age: 20,
|
|
45
|
+
// });
|
|
46
|
+
// if (index % 2 == 0) {
|
|
47
|
+
// const sub2_selfid = 'ss' + index;
|
|
48
|
+
// fd.push({
|
|
49
|
+
// __table_id: sub2_selfid,
|
|
50
|
+
// __parent__table_id: sub_selfid,
|
|
51
|
+
// name: 'sub2-' + index,
|
|
52
|
+
// age: 20,
|
|
53
|
+
// });
|
|
54
|
+
// }
|
|
55
|
+
//}
|
|
56
|
+
}
|
|
57
|
+
return fd;
|
|
58
|
+
}
|
|
59
|
+
|
|
60
|
+
export function ExampleGrid() {
|
|
61
|
+
const [ds_reset, set_ds_reset] = React.useState(0);
|
|
62
|
+
|
|
63
|
+
const dataSource = React.useCallback(
|
|
64
|
+
async (dt) => {
|
|
65
|
+
//console.log('Start loading');
|
|
66
|
+
return await new Promise((resolve) => {
|
|
67
|
+
setTimeout(() => {
|
|
68
|
+
//console.log('end loading');
|
|
69
|
+
resolve(getData());
|
|
70
|
+
}, 1000);
|
|
71
|
+
});
|
|
72
|
+
},
|
|
73
|
+
[ds_reset]
|
|
74
|
+
);
|
|
75
|
+
|
|
76
|
+
const onRowDoubleClick = React.useCallback((index: number, rowdata: any) => {
|
|
77
|
+
console.log(rowdata?.data || rowdata);
|
|
78
|
+
}, []);
|
|
79
|
+
const onRowClick = React.useCallback((index: number, rowdata: any) => {
|
|
80
|
+
//console.log(rowdata?.data || rowdata);
|
|
81
|
+
}, []);
|
|
82
|
+
|
|
83
|
+
function rst_ds() {
|
|
84
|
+
//console.log('rst_ds');
|
|
85
|
+
set_ds_reset((s) => s + 1);
|
|
86
|
+
}
|
|
87
|
+
|
|
88
|
+
return (
|
|
89
|
+
<AzGrid
|
|
90
|
+
dark
|
|
91
|
+
onRowClick={onRowClick}
|
|
92
|
+
onRowDoubleClick={onRowDoubleClick}
|
|
93
|
+
// allowChildRows
|
|
94
|
+
// onSelectionChange={onSelectionChange}
|
|
95
|
+
// selected={selected}
|
|
96
|
+
contextMenuItems={contextMenuItems}
|
|
97
|
+
// customColumns={customColumns}
|
|
98
|
+
columns={columns}
|
|
99
|
+
// leftColumns={leftColumns}
|
|
100
|
+
gridOptions={
|
|
101
|
+
{
|
|
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
|
+
}
|
|
112
|
+
}
|
|
113
|
+
dataSource={dataSource}
|
|
114
|
+
/>
|
|
115
|
+
);
|
|
116
|
+
}
|
|
117
|
+
export default ExampleGrid;
|
package/src/func/helpers.ts
CHANGED
|
@@ -1,74 +1,74 @@
|
|
|
1
|
-
type mrow = { __parent__table_id: any; __table_id: any; __children?: any[] };
|
|
2
|
-
type converted_row = { parent: any; self: any; data: mrow };
|
|
3
|
-
|
|
4
|
-
function get_parentId(obj) {
|
|
5
|
-
return obj.__parent__table_id || obj.parent;
|
|
6
|
-
}
|
|
7
|
-
function get_selfId(obj) {
|
|
8
|
-
return obj.__table_id;
|
|
9
|
-
}
|
|
10
|
-
//given an array of rows, fixes parent,child relations
|
|
11
|
-
export function fix_parent_child_relations<T extends mrow>(rows: T[]): T[] {
|
|
12
|
-
if (!Array.isArray(rows)) rows = [];
|
|
13
|
-
|
|
14
|
-
const converted_rows: converted_row[] = rows
|
|
15
|
-
.filter((r) => r != null)
|
|
16
|
-
.map((r) => {
|
|
17
|
-
return { parent: get_parentId(r), self: get_selfId(r), data: r };
|
|
18
|
-
});
|
|
19
|
-
const top_level_rows: converted_row[] = converted_rows.filter((r) => !r.parent);
|
|
20
|
-
|
|
21
|
-
//find children of top-level parents:
|
|
22
|
-
for (let index = 0; index < top_level_rows.length; index++) {
|
|
23
|
-
const mrow = top_level_rows[index];
|
|
24
|
-
assign_children(mrow, converted_rows);
|
|
25
|
-
}
|
|
26
|
-
const result = top_level_rows.map((r) => r.data) as T[];
|
|
27
|
-
//console.log(result);
|
|
28
|
-
return result;
|
|
29
|
-
}
|
|
30
|
-
|
|
31
|
-
function assign_children(row: converted_row, all_rows: converted_row[]) {
|
|
32
|
-
const my_children = all_rows.filter((s) => row.self == s.parent);
|
|
33
|
-
if (my_children.length > 0) {
|
|
34
|
-
//find children of my children:
|
|
35
|
-
for (let index = 0; index < my_children.length; index++) {
|
|
36
|
-
const child = my_children[index];
|
|
37
|
-
assign_children(child, all_rows);
|
|
38
|
-
}
|
|
39
|
-
row.data.__children = my_children.map((r) => r.data);
|
|
40
|
-
} else if (!Array.isArray(row.data.__children) || row.data.__children.length == 0) row.data.__children = undefined;
|
|
41
|
-
}
|
|
42
|
-
export class func_selection {
|
|
43
|
-
static getVirtualElement(x = 0, y = 0) {
|
|
44
|
-
return () => ({
|
|
45
|
-
getBoundingClientRect: func_selection.generateGetBoundingClientRect(x, y),
|
|
46
|
-
});
|
|
47
|
-
}
|
|
48
|
-
static generateGetBoundingClientRect(x = 0, y = 0) {
|
|
49
|
-
return () => ({
|
|
50
|
-
width: 0,
|
|
51
|
-
height: 0,
|
|
52
|
-
top: y,
|
|
53
|
-
right: x,
|
|
54
|
-
bottom: y,
|
|
55
|
-
left: x,
|
|
56
|
-
});
|
|
57
|
-
}
|
|
58
|
-
static get_selectedText(): string {
|
|
59
|
-
var text: any = '';
|
|
60
|
-
if (window.getSelection) {
|
|
61
|
-
text = window.getSelection()?.toString();
|
|
62
|
-
} else if ((document as any).selection && (document as any).selection.type != 'Control') {
|
|
63
|
-
text = (document as any).selection.createRange()?.text;
|
|
64
|
-
}
|
|
65
|
-
return text || '';
|
|
66
|
-
}
|
|
67
|
-
static has_selection(): boolean {
|
|
68
|
-
const slct = window.getSelection();
|
|
69
|
-
if (slct == null) return false;
|
|
70
|
-
if (slct.type == null) return func_selection.get_selectedText().length !== 0;
|
|
71
|
-
if (slct.type === 'Range') return true;
|
|
72
|
-
return false;
|
|
73
|
-
}
|
|
74
|
-
}
|
|
1
|
+
type mrow = { __parent__table_id: any; __table_id: any; __children?: any[] };
|
|
2
|
+
type converted_row = { parent: any; self: any; data: mrow };
|
|
3
|
+
|
|
4
|
+
function get_parentId(obj) {
|
|
5
|
+
return obj.__parent__table_id || obj.parent;
|
|
6
|
+
}
|
|
7
|
+
function get_selfId(obj) {
|
|
8
|
+
return obj.__table_id;
|
|
9
|
+
}
|
|
10
|
+
//given an array of rows, fixes parent,child relations
|
|
11
|
+
export function fix_parent_child_relations<T extends mrow>(rows: T[]): T[] {
|
|
12
|
+
if (!Array.isArray(rows)) rows = [];
|
|
13
|
+
|
|
14
|
+
const converted_rows: converted_row[] = rows
|
|
15
|
+
.filter((r) => r != null)
|
|
16
|
+
.map((r) => {
|
|
17
|
+
return { parent: get_parentId(r), self: get_selfId(r), data: r };
|
|
18
|
+
});
|
|
19
|
+
const top_level_rows: converted_row[] = converted_rows.filter((r) => !r.parent);
|
|
20
|
+
|
|
21
|
+
//find children of top-level parents:
|
|
22
|
+
for (let index = 0; index < top_level_rows.length; index++) {
|
|
23
|
+
const mrow = top_level_rows[index];
|
|
24
|
+
assign_children(mrow, converted_rows);
|
|
25
|
+
}
|
|
26
|
+
const result = top_level_rows.map((r) => r.data) as T[];
|
|
27
|
+
//console.log(result);
|
|
28
|
+
return result;
|
|
29
|
+
}
|
|
30
|
+
|
|
31
|
+
function assign_children(row: converted_row, all_rows: converted_row[]) {
|
|
32
|
+
const my_children = all_rows.filter((s) => row.self == s.parent);
|
|
33
|
+
if (my_children.length > 0) {
|
|
34
|
+
//find children of my children:
|
|
35
|
+
for (let index = 0; index < my_children.length; index++) {
|
|
36
|
+
const child = my_children[index];
|
|
37
|
+
assign_children(child, all_rows);
|
|
38
|
+
}
|
|
39
|
+
row.data.__children = my_children.map((r) => r.data);
|
|
40
|
+
} else if (!Array.isArray(row.data.__children) || row.data.__children.length == 0) row.data.__children = undefined;
|
|
41
|
+
}
|
|
42
|
+
export class func_selection {
|
|
43
|
+
static getVirtualElement(x = 0, y = 0) {
|
|
44
|
+
return () => ({
|
|
45
|
+
getBoundingClientRect: func_selection.generateGetBoundingClientRect(x, y),
|
|
46
|
+
});
|
|
47
|
+
}
|
|
48
|
+
static generateGetBoundingClientRect(x = 0, y = 0) {
|
|
49
|
+
return () => ({
|
|
50
|
+
width: 0,
|
|
51
|
+
height: 0,
|
|
52
|
+
top: y,
|
|
53
|
+
right: x,
|
|
54
|
+
bottom: y,
|
|
55
|
+
left: x,
|
|
56
|
+
});
|
|
57
|
+
}
|
|
58
|
+
static get_selectedText(): string {
|
|
59
|
+
var text: any = '';
|
|
60
|
+
if (window.getSelection) {
|
|
61
|
+
text = window.getSelection()?.toString();
|
|
62
|
+
} else if ((document as any).selection && (document as any).selection.type != 'Control') {
|
|
63
|
+
text = (document as any).selection.createRange()?.text;
|
|
64
|
+
}
|
|
65
|
+
return text || '';
|
|
66
|
+
}
|
|
67
|
+
static has_selection(): boolean {
|
|
68
|
+
const slct = window.getSelection();
|
|
69
|
+
if (slct == null) return false;
|
|
70
|
+
if (slct.type == null) return func_selection.get_selectedText().length !== 0;
|
|
71
|
+
if (slct.type === 'Range') return true;
|
|
72
|
+
return false;
|
|
73
|
+
}
|
|
74
|
+
}
|
package/src/index.tsx
CHANGED
|
@@ -1,11 +1,11 @@
|
|
|
1
|
-
export * from './views/DataGrid';
|
|
2
|
-
|
|
3
|
-
import AzGrid from './views/DataGrid';
|
|
4
|
-
/* -------------------------------------------------------------------------- */
|
|
5
|
-
import ExampleGrid from './example';
|
|
6
|
-
import React from 'react';
|
|
7
|
-
import ReactDOM from 'react-dom/client';
|
|
8
|
-
export default AzGrid;
|
|
9
|
-
|
|
10
|
-
// const root = ReactDOM.createRoot(document.getElementById('testroot') as HTMLElement);
|
|
11
|
-
// root.render(<ExampleGrid />);
|
|
1
|
+
export * from './views/DataGrid';
|
|
2
|
+
|
|
3
|
+
import AzGrid from './views/DataGrid';
|
|
4
|
+
/* -------------------------------------------------------------------------- */
|
|
5
|
+
import ExampleGrid from './example';
|
|
6
|
+
import React from 'react';
|
|
7
|
+
import ReactDOM from 'react-dom/client';
|
|
8
|
+
export default AzGrid;
|
|
9
|
+
|
|
10
|
+
// const root = ReactDOM.createRoot(document.getElementById('testroot') as HTMLElement);
|
|
11
|
+
// root.render(<ExampleGrid />);
|
|
@@ -1,26 +1,26 @@
|
|
|
1
|
-
.azgrid-container {
|
|
2
|
-
height: 100%;
|
|
3
|
-
width: 100%;
|
|
4
|
-
}
|
|
5
|
-
.azgrid-borderbox {
|
|
6
|
-
box-sizing: border-box;
|
|
7
|
-
}
|
|
8
|
-
.azgrid-filler {
|
|
9
|
-
height: 100%;
|
|
10
|
-
width: 100%;
|
|
11
|
-
}
|
|
12
|
-
.azgrid-nooverflow {
|
|
13
|
-
overflow: hidden;
|
|
14
|
-
}
|
|
15
|
-
.azgrid-testborder {
|
|
16
|
-
border: 3px solid red;
|
|
17
|
-
}
|
|
18
|
-
.azgrid-pad50px {
|
|
19
|
-
padding: 50px;
|
|
20
|
-
}
|
|
21
|
-
.azgrid-nopad {
|
|
22
|
-
padding: 0;
|
|
23
|
-
}
|
|
24
|
-
.azgrid-nomargin {
|
|
25
|
-
margin: 0;
|
|
26
|
-
}
|
|
1
|
+
.azgrid-container {
|
|
2
|
+
height: 100%;
|
|
3
|
+
width: 100%;
|
|
4
|
+
}
|
|
5
|
+
.azgrid-borderbox {
|
|
6
|
+
box-sizing: border-box;
|
|
7
|
+
}
|
|
8
|
+
.azgrid-filler {
|
|
9
|
+
height: 100%;
|
|
10
|
+
width: 100%;
|
|
11
|
+
}
|
|
12
|
+
.azgrid-nooverflow {
|
|
13
|
+
overflow: hidden;
|
|
14
|
+
}
|
|
15
|
+
.azgrid-testborder {
|
|
16
|
+
border: 3px solid red;
|
|
17
|
+
}
|
|
18
|
+
.azgrid-pad50px {
|
|
19
|
+
padding: 50px;
|
|
20
|
+
}
|
|
21
|
+
.azgrid-nopad {
|
|
22
|
+
padding: 0;
|
|
23
|
+
}
|
|
24
|
+
.azgrid-nomargin {
|
|
25
|
+
margin: 0;
|
|
26
|
+
}
|