mctable-react 1.0.0 → 1.0.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/LICENSE.md +30 -0
- package/README.md +2 -0
- package/dist/index.d.ts +7 -1
- package/dist/index.js +86 -11
- package/package.json +3 -3
package/LICENSE.md
ADDED
|
@@ -0,0 +1,30 @@
|
|
|
1
|
+
# mctable-react License
|
|
2
|
+
|
|
3
|
+
**By using this software, you agree to the terms and conditions outlined below.**
|
|
4
|
+
|
|
5
|
+
You are not allowed to modify, distribute, or reverse-engineer the software.
|
|
6
|
+
Free usage is permitted only for non-commercial purposes.
|
|
7
|
+
For commercial use, please contact sales@mormitech.com for licensing information.
|
|
8
|
+
|
|
9
|
+
THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR IMPLIED,
|
|
10
|
+
INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, FITNESS FOR A PARTICULAR
|
|
11
|
+
PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHOR BE LIABLE FOR ANY SPECIAL,
|
|
12
|
+
DIRECT, INDIRECT, OR CONSEQUENTIAL DAMAGES OR ANY DAMAGES WHATSOEVER RESULTING FROM
|
|
13
|
+
LOSS OF USE, DATA OR PROFITS, WHETHER IN AN ACTION OF CONTRACT, NEGLIGENCE OR OTHER
|
|
14
|
+
TORTIOUS ACTION, ARISING OUT OF OR IN CONNECTION WITH THE USE OR PERFORMANCE OF THIS SOFTWARE.
|
|
15
|
+
|
|
16
|
+
> Copyright (c) 2025-2026 Mormitech. All rights reserved.
|
|
17
|
+
|
|
18
|
+
[mormitech.com/mctable/react](mormitech.com/mctable/react)
|
|
19
|
+
|
|
20
|
+
## Dependencies
|
|
21
|
+
|
|
22
|
+
This project uses the following dependencies:
|
|
23
|
+
|
|
24
|
+
- mctable - [LICENSE](https://mormitech.com/mctable/license)
|
|
25
|
+
|
|
26
|
+
Copyright 2019 JS Foundation and other contributors
|
|
27
|
+
|
|
28
|
+
Permission is hereby granted, free of charge, to any person obtaining a copy of this software and associated documentation files (the "Software"), to deal in the Software without restriction, including without limitation the rights to use, copy, modify, merge, publish, distribute, sublicense, and/or sell copies of the Software, and to permit persons to whom the Software is furnished to do so, subject to the following conditions:
|
|
29
|
+
|
|
30
|
+
The above copyright notice and this permission notice shall be included in all copies or substantial portions of the Software.
|
package/README.md
CHANGED
package/dist/index.d.ts
CHANGED
|
@@ -1,5 +1,5 @@
|
|
|
1
1
|
import * as React from 'react';
|
|
2
|
-
import { MctColumn, MctInitSettings, MctLicense, McTable, MctApi } from 'mctable';
|
|
2
|
+
import { MctColumn, MctInitSettings, MctLicense, McTable, MctRow, MctApi } from 'mctable';
|
|
3
3
|
export { McTableCtor, MctApi, MctColumn, MctColumnData, MctInitSettings, MctLicense, MctRow, MctScrollPosition } from 'mctable';
|
|
4
4
|
|
|
5
5
|
type McTableReactHandle = {
|
|
@@ -12,6 +12,12 @@ type McTableReactProps = {
|
|
|
12
12
|
settings?: MctInitSettings;
|
|
13
13
|
license?: MctLicense;
|
|
14
14
|
onReady?: (table: McTable) => void;
|
|
15
|
+
onColumnResizeStart?: (currentColumnWidth: number, column: MctColumn) => void;
|
|
16
|
+
onColumnResizing?: (currentColumnWidth: number, column: MctColumn) => void;
|
|
17
|
+
onColumnResizeEnd?: (newColumnWidth: number, column: MctColumn) => void;
|
|
18
|
+
onRowResizeStart?: (currentRowHeight: number, row: MctRow) => void;
|
|
19
|
+
onRowResizing?: (currentRowHeight: number, row: MctRow) => void;
|
|
20
|
+
onRowResizeEnd?: (newRowHeight: number, row: MctRow) => void;
|
|
15
21
|
className?: string;
|
|
16
22
|
style?: React.CSSProperties;
|
|
17
23
|
};
|
package/dist/index.js
CHANGED
|
@@ -42,6 +42,33 @@ function __stableSignature(value) {
|
|
|
42
42
|
return "[unserializable]";
|
|
43
43
|
}
|
|
44
44
|
}
|
|
45
|
+
function __getInitialWidthOnlyChanges({
|
|
46
|
+
prevRecords,
|
|
47
|
+
prevColumns,
|
|
48
|
+
nextRecords,
|
|
49
|
+
nextColumns
|
|
50
|
+
}) {
|
|
51
|
+
if (__stableSignature(prevRecords) !== __stableSignature(nextRecords)) return null;
|
|
52
|
+
if (prevColumns.length !== nextColumns.length) return null;
|
|
53
|
+
const widthChanges = [];
|
|
54
|
+
for (let index = 0; index < prevColumns.length; index++) {
|
|
55
|
+
const prevColumn = prevColumns[index];
|
|
56
|
+
const nextColumn = nextColumns[index];
|
|
57
|
+
const { initialWidth: _prevInitialWidth, ...prevColumnWithoutInitialWidth } = prevColumn;
|
|
58
|
+
const { initialWidth: _nextInitialWidth, ...nextColumnWithoutInitialWidth } = nextColumn;
|
|
59
|
+
if (__stableSignature(prevColumnWithoutInitialWidth) !== __stableSignature(nextColumnWithoutInitialWidth)) {
|
|
60
|
+
return null;
|
|
61
|
+
}
|
|
62
|
+
if (prevColumn.initialWidth !== nextColumn.initialWidth) {
|
|
63
|
+
widthChanges.push({
|
|
64
|
+
position: index + 1,
|
|
65
|
+
width: nextColumn.initialWidth ?? "reset"
|
|
66
|
+
});
|
|
67
|
+
}
|
|
68
|
+
}
|
|
69
|
+
if (widthChanges.length === 0) return null;
|
|
70
|
+
return widthChanges;
|
|
71
|
+
}
|
|
45
72
|
var __nextInstanceId = 1;
|
|
46
73
|
var useIsomorphicLayoutEffect = typeof window !== "undefined" ? React.useLayoutEffect : React.useEffect;
|
|
47
74
|
var McTableReact = React.forwardRef(
|
|
@@ -51,6 +78,12 @@ var McTableReact = React.forwardRef(
|
|
|
51
78
|
settings,
|
|
52
79
|
license,
|
|
53
80
|
onReady,
|
|
81
|
+
onColumnResizeStart,
|
|
82
|
+
onColumnResizing,
|
|
83
|
+
onColumnResizeEnd,
|
|
84
|
+
onRowResizeStart,
|
|
85
|
+
onRowResizing,
|
|
86
|
+
onRowResizeEnd,
|
|
54
87
|
className,
|
|
55
88
|
style
|
|
56
89
|
}, ref) => {
|
|
@@ -67,6 +100,32 @@ var McTableReact = React.forwardRef(
|
|
|
67
100
|
columnsSig: __stableSignature(columns ?? [])
|
|
68
101
|
});
|
|
69
102
|
const [readyTick, setReadyTick] = React.useState(0);
|
|
103
|
+
const effectiveSettings = React.useMemo(() => {
|
|
104
|
+
const hasAnyResizeCallback = onColumnResizeStart !== void 0 || onColumnResizing !== void 0 || onColumnResizeEnd !== void 0 || onRowResizeStart !== void 0 || onRowResizing !== void 0 || onRowResizeEnd !== void 0;
|
|
105
|
+
if (!settings && !hasAnyResizeCallback) return void 0;
|
|
106
|
+
if (!hasAnyResizeCallback) return settings;
|
|
107
|
+
const nextEvents = {
|
|
108
|
+
...settings?.events ?? {}
|
|
109
|
+
};
|
|
110
|
+
if (onColumnResizeStart !== void 0) nextEvents.onColumnResizeStart = onColumnResizeStart;
|
|
111
|
+
if (onColumnResizing !== void 0) nextEvents.onColumnResizing = onColumnResizing;
|
|
112
|
+
if (onColumnResizeEnd !== void 0) nextEvents.onColumnResizeEnd = onColumnResizeEnd;
|
|
113
|
+
if (onRowResizeStart !== void 0) nextEvents.onRowResizeStart = onRowResizeStart;
|
|
114
|
+
if (onRowResizing !== void 0) nextEvents.onRowResizing = onRowResizing;
|
|
115
|
+
if (onRowResizeEnd !== void 0) nextEvents.onRowResizeEnd = onRowResizeEnd;
|
|
116
|
+
return {
|
|
117
|
+
...settings ?? {},
|
|
118
|
+
events: nextEvents
|
|
119
|
+
};
|
|
120
|
+
}, [
|
|
121
|
+
settings,
|
|
122
|
+
onColumnResizeStart,
|
|
123
|
+
onColumnResizing,
|
|
124
|
+
onColumnResizeEnd,
|
|
125
|
+
onRowResizeStart,
|
|
126
|
+
onRowResizing,
|
|
127
|
+
onRowResizeEnd
|
|
128
|
+
]);
|
|
70
129
|
React.useImperativeHandle(
|
|
71
130
|
ref,
|
|
72
131
|
() => ({
|
|
@@ -92,7 +151,7 @@ var McTableReact = React.forwardRef(
|
|
|
92
151
|
container,
|
|
93
152
|
records: initialRecords,
|
|
94
153
|
columns: initialColumns,
|
|
95
|
-
settings,
|
|
154
|
+
settings: effectiveSettings,
|
|
96
155
|
license
|
|
97
156
|
});
|
|
98
157
|
tableRef.current = instance;
|
|
@@ -120,6 +179,10 @@ var McTableReact = React.forwardRef(
|
|
|
120
179
|
if (!table) {
|
|
121
180
|
return;
|
|
122
181
|
}
|
|
182
|
+
const prevRecords = lastDataRef.current.records;
|
|
183
|
+
const prevColumns = lastDataRef.current.columns;
|
|
184
|
+
const nextRecords = records !== void 0 ? records : prevRecords;
|
|
185
|
+
const nextColumns = columns !== void 0 ? columns : prevColumns;
|
|
123
186
|
const prevSig = lastSigRef.current;
|
|
124
187
|
const nextRecordCount = records !== void 0 ? records.length : prevSig.recordCount;
|
|
125
188
|
const nextColumnsCount = columns !== void 0 ? columns.length : prevSig.columnsCount;
|
|
@@ -128,10 +191,10 @@ var McTableReact = React.forwardRef(
|
|
|
128
191
|
const columnsChanged = columns !== void 0 && (nextColumnsCount !== prevSig.columnsCount || nextColumnsSig !== prevSig.columnsSig);
|
|
129
192
|
const didChange = recordCountChanged || columnsChanged;
|
|
130
193
|
if (records !== void 0) {
|
|
131
|
-
lastDataRef.current.records =
|
|
194
|
+
lastDataRef.current.records = nextRecords;
|
|
132
195
|
}
|
|
133
196
|
if (columns !== void 0) {
|
|
134
|
-
lastDataRef.current.columns =
|
|
197
|
+
lastDataRef.current.columns = nextColumns;
|
|
135
198
|
}
|
|
136
199
|
if (!didChange) {
|
|
137
200
|
return;
|
|
@@ -141,19 +204,31 @@ var McTableReact = React.forwardRef(
|
|
|
141
204
|
columnsCount: nextColumnsCount,
|
|
142
205
|
columnsSig: nextColumnsSig
|
|
143
206
|
};
|
|
144
|
-
|
|
145
|
-
|
|
146
|
-
|
|
147
|
-
|
|
148
|
-
|
|
207
|
+
const initialWidthOnlyChanges = __getInitialWidthOnlyChanges({
|
|
208
|
+
prevRecords,
|
|
209
|
+
prevColumns,
|
|
210
|
+
nextRecords,
|
|
211
|
+
nextColumns
|
|
149
212
|
});
|
|
213
|
+
if (initialWidthOnlyChanges) {
|
|
214
|
+
for (const change of initialWidthOnlyChanges) {
|
|
215
|
+
table.api.setContentColumnWidth(change);
|
|
216
|
+
}
|
|
217
|
+
} else {
|
|
218
|
+
table.api.setData({
|
|
219
|
+
data: {
|
|
220
|
+
records: lastDataRef.current.records,
|
|
221
|
+
columns: lastDataRef.current.columns
|
|
222
|
+
}
|
|
223
|
+
});
|
|
224
|
+
}
|
|
150
225
|
}, [records, columns]);
|
|
151
226
|
React.useEffect(() => {
|
|
152
227
|
const table = tableRef.current;
|
|
153
228
|
if (!table) return;
|
|
154
|
-
if (!
|
|
155
|
-
table.api.updateSettings(
|
|
156
|
-
}, [
|
|
229
|
+
if (!effectiveSettings) return;
|
|
230
|
+
table.api.updateSettings(effectiveSettings);
|
|
231
|
+
}, [effectiveSettings]);
|
|
157
232
|
const combinedClassName = ["mctable-react", className].filter(Boolean).join(" ");
|
|
158
233
|
const combinedStyle = {
|
|
159
234
|
width: "100%",
|
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "mctable-react",
|
|
3
|
-
"version": "1.0.
|
|
3
|
+
"version": "1.0.2",
|
|
4
4
|
"description": "",
|
|
5
5
|
"type": "module",
|
|
6
6
|
"main": "./dist/index.js",
|
|
@@ -27,7 +27,7 @@
|
|
|
27
27
|
},
|
|
28
28
|
"keywords": [],
|
|
29
29
|
"author": "",
|
|
30
|
-
"license": "
|
|
30
|
+
"license": "SEE LICENSE.md",
|
|
31
31
|
"peerDependencies": {
|
|
32
32
|
"react": "^18.0.0",
|
|
33
33
|
"react-dom": "^18.0.0"
|
|
@@ -44,6 +44,6 @@
|
|
|
44
44
|
"vite": "^5.4.12"
|
|
45
45
|
},
|
|
46
46
|
"dependencies": {
|
|
47
|
-
"mctable": "^1.2.
|
|
47
|
+
"mctable": "^1.2.2"
|
|
48
48
|
}
|
|
49
49
|
}
|