create-emsgrid 0.1.0 → 0.1.3
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/index.js +32 -0
- package/package.json +6 -47
- package/template/package.json +60 -0
- package/{src → template/src}/components/Grid/core/Grid.tsx +28 -9
- package/{src → template/src}/components/Grid/ui/Cell.tsx +5 -2
- package/{src → template/src}/components/Grid/ui/Header.tsx +3 -2
- package/{src → template/src}/components/Grid/ui/Row.tsx +4 -1
- package/{src → template/src}/styles.css +5 -0
- package/template/yarn.lock +2938 -0
- /package/{.husky → template/.husky}/pre-commit +0 -0
- /package/{.prettierignore → template/.prettierignore} +0 -0
- /package/{.prettierrc → template/.prettierrc} +0 -0
- /package/{README.md → template/README.md} +0 -0
- /package/{eslint.config.js → template/eslint.config.js} +0 -0
- /package/{index.html → template/index.html} +0 -0
- /package/{plan.md → template/plan.md} +0 -0
- /package/{src → template/src}/App.tsx +0 -0
- /package/{src → template/src}/components/Grid/core/createTable.ts +0 -0
- /package/{src → template/src}/components/Grid/core/settings.ts +0 -0
- /package/{src → template/src}/components/Grid/core/types.ts +0 -0
- /package/{src → template/src}/components/Grid/features/columns/useColumnReorder.ts +0 -0
- /package/{src → template/src}/components/Grid/features/contextMenu/index.ts +0 -0
- /package/{src → template/src}/components/Grid/features/export/exportXlsx.ts +0 -0
- /package/{src → template/src}/components/Grid/features/filtering/FilterInput.tsx +0 -0
- /package/{src → template/src}/components/Grid/features/pagination/index.ts +0 -0
- /package/{src → template/src}/components/Grid/features/selection/index.ts +0 -0
- /package/{src → template/src}/components/Grid/features/sorting/SortIndicator.tsx +0 -0
- /package/{src → template/src}/components/Grid/features/toolbar/index.ts +0 -0
- /package/{src → template/src}/components/Grid/features/tree/buildParentTree.ts +0 -0
- /package/{src → template/src}/components/Grid/features/tree/index.ts +0 -0
- /package/{src → template/src}/components/Grid/features/virtualization/useRowVirtualizer.ts +0 -0
- /package/{src → template/src}/components/Grid/ui/ContextMenu.tsx +0 -0
- /package/{src → template/src}/components/Grid/ui/Pagination.tsx +0 -0
- /package/{src → template/src}/components/Grid/ui/Panels/ColumnsPanel.tsx +0 -0
- /package/{src → template/src}/components/Grid/ui/Panels/FiltersPanel.tsx +0 -0
- /package/{src → template/src}/components/Grid/ui/Panels/GroupingPanel.tsx +0 -0
- /package/{src → template/src}/components/Grid/ui/columns/SelectColumn.tsx +0 -0
- /package/{src → template/src}/components/Grid/ui/index.ts +0 -0
- /package/{src → template/src}/main.tsx +0 -0
- /package/{src → template/src}/mocks/people.ts +0 -0
- /package/{src → template/src}/store/gridApi.ts +0 -0
- /package/{src → template/src}/store/store.ts +0 -0
- /package/{tsconfig.json → template/tsconfig.json} +0 -0
- /package/{vite.config.ts → template/vite.config.ts} +0 -0
package/index.js
ADDED
|
@@ -0,0 +1,32 @@
|
|
|
1
|
+
#!/usr/bin/env node
|
|
2
|
+
import fs from 'node:fs';
|
|
3
|
+
import path from 'node:path';
|
|
4
|
+
import { fileURLToPath } from 'node:url';
|
|
5
|
+
|
|
6
|
+
const targetDir = process.argv[2] || 'ems-grid';
|
|
7
|
+
const resolvedTarget = path.resolve(process.cwd(), targetDir);
|
|
8
|
+
|
|
9
|
+
if (fs.existsSync(resolvedTarget) && fs.readdirSync(resolvedTarget).length > 0) {
|
|
10
|
+
console.error(`Target directory is not empty: ${resolvedTarget}`);
|
|
11
|
+
process.exit(1);
|
|
12
|
+
}
|
|
13
|
+
|
|
14
|
+
const __filename = fileURLToPath(import.meta.url);
|
|
15
|
+
const __dirname = path.dirname(__filename);
|
|
16
|
+
const templateDir = path.join(__dirname, 'template');
|
|
17
|
+
|
|
18
|
+
try {
|
|
19
|
+
fs.mkdirSync(resolvedTarget, { recursive: true });
|
|
20
|
+
fs.cpSync(templateDir, resolvedTarget, {
|
|
21
|
+
recursive: true,
|
|
22
|
+
filter: (src) => {
|
|
23
|
+
const base = path.basename(src);
|
|
24
|
+
return base !== 'node_modules' && base !== 'dist' && base !== '.git';
|
|
25
|
+
},
|
|
26
|
+
});
|
|
27
|
+
|
|
28
|
+
console.log(`\nDone. Run:\n cd ${targetDir}\n yarn\n yarn dev\n`);
|
|
29
|
+
} catch (err) {
|
|
30
|
+
console.error(err?.message ?? 'Failed to create project.');
|
|
31
|
+
process.exit(1);
|
|
32
|
+
}
|
package/package.json
CHANGED
|
@@ -1,12 +1,17 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "create-emsgrid",
|
|
3
|
+
"version": "0.1.3",
|
|
3
4
|
"private": false,
|
|
4
|
-
"version": "0.1.0",
|
|
5
5
|
"description": "Create an EMS Grid project",
|
|
6
6
|
"license": "MIT",
|
|
7
|
+
"type": "module",
|
|
7
8
|
"bin": {
|
|
8
9
|
"create-emsgrid": "index.js"
|
|
9
10
|
},
|
|
11
|
+
"files": [
|
|
12
|
+
"index.js",
|
|
13
|
+
"template"
|
|
14
|
+
],
|
|
10
15
|
"repository": {
|
|
11
16
|
"type": "git",
|
|
12
17
|
"url": "https://github.com/Resg/table.git"
|
|
@@ -17,51 +22,5 @@
|
|
|
17
22
|
},
|
|
18
23
|
"engines": {
|
|
19
24
|
"node": ">=18"
|
|
20
|
-
},
|
|
21
|
-
"type": "module",
|
|
22
|
-
"scripts": {
|
|
23
|
-
"dev": "vite",
|
|
24
|
-
"build": "tsc -b && vite build",
|
|
25
|
-
"preview": "vite preview",
|
|
26
|
-
"lint": "eslint \"src/**/*.{ts,tsx}\"",
|
|
27
|
-
"format": "prettier --check .",
|
|
28
|
-
"format:write": "prettier --write .",
|
|
29
|
-
"lint-staged": "lint-staged",
|
|
30
|
-
"prepare": "husky"
|
|
31
|
-
},
|
|
32
|
-
"lint-staged": {
|
|
33
|
-
"*.{ts,tsx}": [
|
|
34
|
-
"eslint --fix",
|
|
35
|
-
"prettier --write"
|
|
36
|
-
],
|
|
37
|
-
"*.{js,jsx,cjs,mjs,css,md,json,yml,yaml}": [
|
|
38
|
-
"prettier --write"
|
|
39
|
-
]
|
|
40
|
-
},
|
|
41
|
-
"dependencies": {
|
|
42
|
-
"@reduxjs/toolkit": "^2.2.7",
|
|
43
|
-
"@tanstack/react-table": "^8.20.5",
|
|
44
|
-
"@tanstack/react-virtual": "^3.10.8",
|
|
45
|
-
"react": "^18.3.1",
|
|
46
|
-
"react-dom": "^18.3.1",
|
|
47
|
-
"react-redux": "^9.1.2",
|
|
48
|
-
"xlsx": "^0.18.5"
|
|
49
|
-
},
|
|
50
|
-
"devDependencies": {
|
|
51
|
-
"@types/node": "^25.0.9",
|
|
52
|
-
"@types/react": "^18.3.3",
|
|
53
|
-
"@types/react-dom": "^18.3.0",
|
|
54
|
-
"@typescript-eslint/eslint-plugin": "^8.53.1",
|
|
55
|
-
"@typescript-eslint/parser": "^8.53.1",
|
|
56
|
-
"@vitejs/plugin-react": "^4.3.1",
|
|
57
|
-
"eslint": "^9.39.2",
|
|
58
|
-
"eslint-plugin-react": "^7.37.5",
|
|
59
|
-
"eslint-plugin-react-hooks": "^7.0.1",
|
|
60
|
-
"eslint-plugin-react-refresh": "^0.4.26",
|
|
61
|
-
"husky": "^9.1.7",
|
|
62
|
-
"lint-staged": "^16.2.7",
|
|
63
|
-
"prettier": "^3.8.0",
|
|
64
|
-
"typescript": "^5.5.4",
|
|
65
|
-
"vite": "^5.4.2"
|
|
66
25
|
}
|
|
67
26
|
}
|
|
@@ -0,0 +1,60 @@
|
|
|
1
|
+
{
|
|
2
|
+
"name": "ems-grid",
|
|
3
|
+
"private": false,
|
|
4
|
+
"version": "0.1.0",
|
|
5
|
+
"license": "MIT",
|
|
6
|
+
"repository": {
|
|
7
|
+
"type": "git",
|
|
8
|
+
"url": "https://github.com/Resg/table.git"
|
|
9
|
+
},
|
|
10
|
+
"homepage": "https://github.com/Resg/table",
|
|
11
|
+
"bugs": {
|
|
12
|
+
"url": "https://github.com/Resg/table/issues"
|
|
13
|
+
},
|
|
14
|
+
"type": "module",
|
|
15
|
+
"scripts": {
|
|
16
|
+
"dev": "vite",
|
|
17
|
+
"build": "tsc -b && vite build",
|
|
18
|
+
"preview": "vite preview",
|
|
19
|
+
"lint": "eslint \"src/**/*.{ts,tsx}\"",
|
|
20
|
+
"format": "prettier --check .",
|
|
21
|
+
"format:write": "prettier --write .",
|
|
22
|
+
"lint-staged": "lint-staged",
|
|
23
|
+
"prepare": "husky"
|
|
24
|
+
},
|
|
25
|
+
"lint-staged": {
|
|
26
|
+
"*.{ts,tsx}": [
|
|
27
|
+
"eslint --fix",
|
|
28
|
+
"prettier --write"
|
|
29
|
+
],
|
|
30
|
+
"*.{js,jsx,cjs,mjs,css,md,json,yml,yaml}": [
|
|
31
|
+
"prettier --write"
|
|
32
|
+
]
|
|
33
|
+
},
|
|
34
|
+
"dependencies": {
|
|
35
|
+
"@reduxjs/toolkit": "^2.2.7",
|
|
36
|
+
"@tanstack/react-table": "^8.20.5",
|
|
37
|
+
"@tanstack/react-virtual": "^3.10.8",
|
|
38
|
+
"react": "^18.3.1",
|
|
39
|
+
"react-dom": "^18.3.1",
|
|
40
|
+
"react-redux": "^9.1.2",
|
|
41
|
+
"xlsx": "^0.18.5"
|
|
42
|
+
},
|
|
43
|
+
"devDependencies": {
|
|
44
|
+
"@types/node": "^25.0.9",
|
|
45
|
+
"@types/react": "^18.3.3",
|
|
46
|
+
"@types/react-dom": "^18.3.0",
|
|
47
|
+
"@typescript-eslint/eslint-plugin": "^8.53.1",
|
|
48
|
+
"@typescript-eslint/parser": "^8.53.1",
|
|
49
|
+
"@vitejs/plugin-react": "^4.3.1",
|
|
50
|
+
"eslint": "^9.39.2",
|
|
51
|
+
"eslint-plugin-react": "^7.37.5",
|
|
52
|
+
"eslint-plugin-react-hooks": "^7.0.1",
|
|
53
|
+
"eslint-plugin-react-refresh": "^0.4.26",
|
|
54
|
+
"husky": "^9.1.7",
|
|
55
|
+
"lint-staged": "^16.2.7",
|
|
56
|
+
"prettier": "^3.8.0",
|
|
57
|
+
"typescript": "^5.5.4",
|
|
58
|
+
"vite": "^5.4.2"
|
|
59
|
+
}
|
|
60
|
+
}
|
|
@@ -74,7 +74,19 @@ export function Grid<TData>(props: GridProps<TData>) {
|
|
|
74
74
|
rowHeight,
|
|
75
75
|
overscan,
|
|
76
76
|
});
|
|
77
|
+
const tableWidth = table.getTotalSize();
|
|
77
78
|
const firstContentColumnId = table.getVisibleLeafColumns().find((col) => col.id !== 'select')?.id;
|
|
79
|
+
const headerRef = React.useRef<HTMLDivElement | null>(null);
|
|
80
|
+
const syncHorizontalScroll = React.useCallback(
|
|
81
|
+
(source: HTMLDivElement | null, target: HTMLDivElement | null) => {
|
|
82
|
+
if (!source || !target) return;
|
|
83
|
+
const nextLeft = source.scrollLeft;
|
|
84
|
+
if (target.scrollLeft !== nextLeft) {
|
|
85
|
+
target.scrollLeft = nextLeft;
|
|
86
|
+
}
|
|
87
|
+
},
|
|
88
|
+
[]
|
|
89
|
+
);
|
|
78
90
|
const [menu, setMenu] = React.useState<{
|
|
79
91
|
open: boolean;
|
|
80
92
|
x: number;
|
|
@@ -95,16 +107,22 @@ export function Grid<TData>(props: GridProps<TData>) {
|
|
|
95
107
|
|
|
96
108
|
return (
|
|
97
109
|
<div className="grid-shell">
|
|
98
|
-
<
|
|
99
|
-
|
|
100
|
-
|
|
101
|
-
|
|
102
|
-
|
|
103
|
-
|
|
104
|
-
|
|
110
|
+
<div ref={headerRef} className="scroll-header">
|
|
111
|
+
<Header
|
|
112
|
+
table={table}
|
|
113
|
+
showFilters={showFilters}
|
|
114
|
+
onHeaderDragStart={handleHeaderDragStart}
|
|
115
|
+
onHeaderDrop={handleHeaderDrop}
|
|
116
|
+
isReorderableColumn={isReorderable}
|
|
117
|
+
/>
|
|
118
|
+
</div>
|
|
105
119
|
|
|
106
|
-
<div
|
|
107
|
-
|
|
120
|
+
<div
|
|
121
|
+
ref={parentRef}
|
|
122
|
+
className="scroll"
|
|
123
|
+
onScroll={() => syncHorizontalScroll(parentRef.current, headerRef.current)}
|
|
124
|
+
>
|
|
125
|
+
<div style={{ height: totalSize, position: 'relative', width: tableWidth, minWidth: '100%' }}>
|
|
108
126
|
{isLoading ? (
|
|
109
127
|
<div style={{ padding: 12, opacity: 0.8 }}>Загрузка…</div>
|
|
110
128
|
) : (
|
|
@@ -117,6 +135,7 @@ export function Grid<TData>(props: GridProps<TData>) {
|
|
|
117
135
|
row={row}
|
|
118
136
|
top={vi.start}
|
|
119
137
|
rowHeight={rowHeight}
|
|
138
|
+
tableWidth={tableWidth}
|
|
120
139
|
firstContentColumnId={firstContentColumnId}
|
|
121
140
|
renderAggregatedCell={renderAggregatedCell}
|
|
122
141
|
isGroupMode={isGroupMode}
|
|
@@ -16,6 +16,7 @@ export function Cell<TData>({
|
|
|
16
16
|
isGroupMode = false,
|
|
17
17
|
}: CellProps<TData>) {
|
|
18
18
|
const depth = cell.row.depth;
|
|
19
|
+
const isGroupedCell = isGroupMode ? (cell.getIsGrouped?.() ?? false) : false;
|
|
19
20
|
const canExpand = isExpanderCell && cell.row.getCanExpand();
|
|
20
21
|
const isExpanded = canExpand ? cell.row.getIsExpanded() : false;
|
|
21
22
|
const paddingLeft = isExpanderCell ? 10 + depth * 14 : undefined;
|
|
@@ -58,11 +59,13 @@ export function Cell<TData>({
|
|
|
58
59
|
);
|
|
59
60
|
} else if (isAggregatedCell) {
|
|
60
61
|
content = aggregatedRenderer(cell);
|
|
61
|
-
} else {
|
|
62
|
+
} else if (isPlaceholder || isGroupedCell) {
|
|
62
63
|
content = null;
|
|
64
|
+
} else {
|
|
65
|
+
content = defaultRenderer;
|
|
63
66
|
}
|
|
64
67
|
} else if (isPlaceholder) {
|
|
65
|
-
content =
|
|
68
|
+
content = defaultRenderer;
|
|
66
69
|
} else if (isExpanderCell && canExpand) {
|
|
67
70
|
content = (
|
|
68
71
|
<>
|
|
@@ -14,11 +14,12 @@ type HeaderProps<TData> = {
|
|
|
14
14
|
|
|
15
15
|
export function Header<TData>(props: HeaderProps<TData>) {
|
|
16
16
|
const { table, showFilters, onHeaderDragStart, onHeaderDrop, isReorderableColumn } = props;
|
|
17
|
+
const tableWidth = table.getTotalSize();
|
|
17
18
|
|
|
18
19
|
return (
|
|
19
|
-
<div className="grid-header">
|
|
20
|
+
<div className="grid-header" style={{ width: tableWidth, minWidth: '100%' }}>
|
|
20
21
|
{table.getHeaderGroups().map((hg) => (
|
|
21
|
-
<div key={hg.id} className="row">
|
|
22
|
+
<div key={hg.id} className="row" style={{ width: tableWidth, minWidth: '100%' }}>
|
|
22
23
|
{hg.headers.map((header) => {
|
|
23
24
|
const col = header.column;
|
|
24
25
|
const size = col.getSize();
|
|
@@ -6,6 +6,7 @@ type RowProps<TData> = {
|
|
|
6
6
|
row: TableRow<TData>;
|
|
7
7
|
top: number;
|
|
8
8
|
rowHeight: number;
|
|
9
|
+
tableWidth: number;
|
|
9
10
|
firstContentColumnId?: string;
|
|
10
11
|
renderAggregatedCell?: (cell: TableCell<TData, unknown>) => React.ReactNode;
|
|
11
12
|
isGroupMode?: boolean;
|
|
@@ -16,6 +17,7 @@ export function Row<TData>({
|
|
|
16
17
|
row,
|
|
17
18
|
top,
|
|
18
19
|
rowHeight,
|
|
20
|
+
tableWidth,
|
|
19
21
|
firstContentColumnId,
|
|
20
22
|
renderAggregatedCell,
|
|
21
23
|
isGroupMode,
|
|
@@ -28,7 +30,8 @@ export function Row<TData>({
|
|
|
28
30
|
position: 'absolute',
|
|
29
31
|
top,
|
|
30
32
|
left: 0,
|
|
31
|
-
|
|
33
|
+
width: tableWidth,
|
|
34
|
+
minWidth: '100%',
|
|
32
35
|
height: rowHeight,
|
|
33
36
|
}}
|
|
34
37
|
onContextMenu={onContextMenu}
|