mctable-react 1.0.1 → 1.0.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/README.md +11 -4
- package/dist/index.js +55 -7
- package/package.json +30 -9
package/README.md
CHANGED
|
@@ -1,10 +1,10 @@
|
|
|
1
1
|
# mctable-react
|
|
2
2
|
|
|
3
|
-
React wrapper for the `mctable` package.
|
|
3
|
+
React wrapper for the [`mctable`](https://www.npmjs.com/package/mctable) package.
|
|
4
4
|
|
|
5
|
-
|
|
5
|
+
mctable home page, docs, usage and demo: https://mormitech.com/mctable/
|
|
6
6
|
|
|
7
|
-
mctable-react: https://mormitech.com/mctable/react
|
|
7
|
+
mctable-react home page: https://mormitech.com/mctable/react
|
|
8
8
|
|
|
9
9
|
## Install
|
|
10
10
|
|
|
@@ -21,7 +21,6 @@ Make sure the table container has an explicit size (height/width) so the table c
|
|
|
21
21
|
```tsx
|
|
22
22
|
import * as React from "react";
|
|
23
23
|
import { McTable } from "mctable-react";
|
|
24
|
-
import "mctable-react/McTable.less";
|
|
25
24
|
|
|
26
25
|
const columns = [
|
|
27
26
|
{ name: "id", title: "ID", type: "number" },
|
|
@@ -51,3 +50,11 @@ export function UsersTable() {
|
|
|
51
50
|
```
|
|
52
51
|
|
|
53
52
|
You can also pass `settings`, `license`, or `onReady` if you need deeper access to the underlying `mctable` instance.
|
|
53
|
+
|
|
54
|
+
|
|
55
|
+
## Changelog
|
|
56
|
+
|
|
57
|
+
```
|
|
58
|
+
v1.0.3
|
|
59
|
+
- Aligned with `mctable` core library `v1.2.3`
|
|
60
|
+
```
|
package/dist/index.js
CHANGED
|
@@ -42,6 +42,33 @@ function __stableSignature(value) {
|
|
|
42
42
|
return "[unserializable]";
|
|
43
43
|
}
|
|
44
44
|
}
|
|
45
|
+
function __getWidthOnlyChanges({
|
|
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 { width: _prevWidth, ...prevColumnWithoutWidth } = prevColumn;
|
|
58
|
+
const { width: _nextWidth, ...nextColumnWithoutWidth } = nextColumn;
|
|
59
|
+
if (__stableSignature(prevColumnWithoutWidth) !== __stableSignature(nextColumnWithoutWidth)) {
|
|
60
|
+
return null;
|
|
61
|
+
}
|
|
62
|
+
if (prevColumn.width !== nextColumn.width) {
|
|
63
|
+
widthChanges.push({
|
|
64
|
+
position: index + 1,
|
|
65
|
+
width: nextColumn.width ?? "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(
|
|
@@ -152,6 +179,10 @@ var McTableReact = React.forwardRef(
|
|
|
152
179
|
if (!table) {
|
|
153
180
|
return;
|
|
154
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;
|
|
155
186
|
const prevSig = lastSigRef.current;
|
|
156
187
|
const nextRecordCount = records !== void 0 ? records.length : prevSig.recordCount;
|
|
157
188
|
const nextColumnsCount = columns !== void 0 ? columns.length : prevSig.columnsCount;
|
|
@@ -160,10 +191,10 @@ var McTableReact = React.forwardRef(
|
|
|
160
191
|
const columnsChanged = columns !== void 0 && (nextColumnsCount !== prevSig.columnsCount || nextColumnsSig !== prevSig.columnsSig);
|
|
161
192
|
const didChange = recordCountChanged || columnsChanged;
|
|
162
193
|
if (records !== void 0) {
|
|
163
|
-
lastDataRef.current.records =
|
|
194
|
+
lastDataRef.current.records = nextRecords;
|
|
164
195
|
}
|
|
165
196
|
if (columns !== void 0) {
|
|
166
|
-
lastDataRef.current.columns =
|
|
197
|
+
lastDataRef.current.columns = nextColumns;
|
|
167
198
|
}
|
|
168
199
|
if (!didChange) {
|
|
169
200
|
return;
|
|
@@ -173,12 +204,24 @@ var McTableReact = React.forwardRef(
|
|
|
173
204
|
columnsCount: nextColumnsCount,
|
|
174
205
|
columnsSig: nextColumnsSig
|
|
175
206
|
};
|
|
176
|
-
|
|
177
|
-
|
|
178
|
-
|
|
179
|
-
|
|
180
|
-
|
|
207
|
+
const widthOnlyChanges = __getWidthOnlyChanges({
|
|
208
|
+
prevRecords,
|
|
209
|
+
prevColumns,
|
|
210
|
+
nextRecords,
|
|
211
|
+
nextColumns
|
|
181
212
|
});
|
|
213
|
+
if (widthOnlyChanges) {
|
|
214
|
+
for (const change of widthOnlyChanges) {
|
|
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
|
+
}
|
|
182
225
|
}, [records, columns]);
|
|
183
226
|
React.useEffect(() => {
|
|
184
227
|
const table = tableRef.current;
|
|
@@ -190,6 +233,11 @@ var McTableReact = React.forwardRef(
|
|
|
190
233
|
const combinedStyle = {
|
|
191
234
|
width: "100%",
|
|
192
235
|
height: "100%",
|
|
236
|
+
display: "flex",
|
|
237
|
+
flex: "1 1 auto",
|
|
238
|
+
minWidth: 0,
|
|
239
|
+
minHeight: 0,
|
|
240
|
+
alignItems: "stretch",
|
|
193
241
|
...style
|
|
194
242
|
};
|
|
195
243
|
return /* @__PURE__ */ jsx("div", { ref: containerRef, className: combinedClassName, style: combinedStyle });
|
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "mctable-react",
|
|
3
|
-
"version": "1.0.
|
|
3
|
+
"version": "1.0.3",
|
|
4
4
|
"description": "",
|
|
5
5
|
"type": "module",
|
|
6
6
|
"main": "./dist/index.js",
|
|
@@ -9,13 +9,10 @@
|
|
|
9
9
|
".": {
|
|
10
10
|
"types": "./dist/index.d.ts",
|
|
11
11
|
"import": "./dist/index.js"
|
|
12
|
-
}
|
|
13
|
-
"./McTable.less": "./McTable.less"
|
|
12
|
+
}
|
|
14
13
|
},
|
|
15
14
|
"files": [
|
|
16
|
-
"dist"
|
|
17
|
-
"README.md",
|
|
18
|
-
"McTable.less"
|
|
15
|
+
"dist"
|
|
19
16
|
],
|
|
20
17
|
"scripts": {
|
|
21
18
|
"test": "echo \"Error: no test specified\" && exit 1",
|
|
@@ -25,8 +22,32 @@
|
|
|
25
22
|
"prepare": "npm run build",
|
|
26
23
|
"prepack": "npm run build"
|
|
27
24
|
},
|
|
28
|
-
"keywords": [
|
|
29
|
-
|
|
25
|
+
"keywords": [
|
|
26
|
+
"canvas",
|
|
27
|
+
"table",
|
|
28
|
+
"grid",
|
|
29
|
+
"html5",
|
|
30
|
+
"excel",
|
|
31
|
+
"spreadsheet",
|
|
32
|
+
"editable",
|
|
33
|
+
"table editor",
|
|
34
|
+
"writeback",
|
|
35
|
+
"validation",
|
|
36
|
+
"performance",
|
|
37
|
+
"customizable",
|
|
38
|
+
"change tracking",
|
|
39
|
+
"Power BI",
|
|
40
|
+
"typescript",
|
|
41
|
+
"javascript",
|
|
42
|
+
"API",
|
|
43
|
+
"fetch more",
|
|
44
|
+
"dropdown",
|
|
45
|
+
"undo",
|
|
46
|
+
"redo",
|
|
47
|
+
"filter",
|
|
48
|
+
"filtering"
|
|
49
|
+
],
|
|
50
|
+
"author": "Mormitech",
|
|
30
51
|
"license": "SEE LICENSE.md",
|
|
31
52
|
"peerDependencies": {
|
|
32
53
|
"react": "^18.0.0",
|
|
@@ -44,6 +65,6 @@
|
|
|
44
65
|
"vite": "^5.4.12"
|
|
45
66
|
},
|
|
46
67
|
"dependencies": {
|
|
47
|
-
"mctable": "^1.2.
|
|
68
|
+
"mctable": "^1.2.3"
|
|
48
69
|
}
|
|
49
70
|
}
|