mctable-react 1.0.1 → 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.
Files changed (2) hide show
  1. package/dist/index.js +50 -7
  2. package/package.json +1 -1
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(
@@ -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 = records;
194
+ lastDataRef.current.records = nextRecords;
164
195
  }
165
196
  if (columns !== void 0) {
166
- lastDataRef.current.columns = 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
- table.api.setData({
177
- data: {
178
- records: lastDataRef.current.records,
179
- columns: lastDataRef.current.columns
180
- }
207
+ const initialWidthOnlyChanges = __getInitialWidthOnlyChanges({
208
+ prevRecords,
209
+ prevColumns,
210
+ nextRecords,
211
+ nextColumns
181
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
+ }
182
225
  }, [records, columns]);
183
226
  React.useEffect(() => {
184
227
  const table = tableRef.current;
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "mctable-react",
3
- "version": "1.0.1",
3
+ "version": "1.0.2",
4
4
  "description": "",
5
5
  "type": "module",
6
6
  "main": "./dist/index.js",