@infinite-table/infinite-react 0.2.6 → 0.2.9

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 (4) hide show
  1. package/index.d.ts +951 -3213
  2. package/index.esm.js +146 -84
  3. package/index.js +130 -68
  4. package/package.json +2 -2
package/index.js CHANGED
@@ -198,11 +198,11 @@ var require_common = __commonJS({
198
198
  let enableOverride = null;
199
199
  let namespacesCache;
200
200
  let enabledCache;
201
- function debug6(...args) {
202
- if (!debug6.enabled) {
201
+ function debug7(...args) {
202
+ if (!debug7.enabled) {
203
203
  return;
204
204
  }
205
- const self = debug6;
205
+ const self = debug7;
206
206
  const curr = Number(new Date());
207
207
  const ms = curr - (prevTime || curr);
208
208
  self.diff = ms;
@@ -232,12 +232,12 @@ var require_common = __commonJS({
232
232
  const logFn = self.log || createDebug.log;
233
233
  logFn.apply(self, args);
234
234
  }
235
- debug6.namespace = namespace;
236
- debug6.useColors = createDebug.useColors();
237
- debug6.color = createDebug.selectColor(namespace);
238
- debug6.extend = extend;
239
- debug6.destroy = createDebug.destroy;
240
- Object.defineProperty(debug6, "enabled", {
235
+ debug7.namespace = namespace;
236
+ debug7.useColors = createDebug.useColors();
237
+ debug7.color = createDebug.selectColor(namespace);
238
+ debug7.extend = extend;
239
+ debug7.destroy = createDebug.destroy;
240
+ Object.defineProperty(debug7, "enabled", {
241
241
  enumerable: true,
242
242
  configurable: false,
243
243
  get: () => {
@@ -255,9 +255,9 @@ var require_common = __commonJS({
255
255
  }
256
256
  });
257
257
  if (typeof createDebug.init === "function") {
258
- createDebug.init(debug6);
258
+ createDebug.init(debug7);
259
259
  }
260
- return debug6;
260
+ return debug7;
261
261
  }
262
262
  function extend(namespace, delimiter) {
263
263
  const newDebug = createDebug(this.namespace + (typeof delimiter === "undefined" ? ":" : delimiter) + namespace);
@@ -2843,6 +2843,7 @@ function getEnhancedGroupData(options, deepMapValue) {
2843
2843
  id: `${groupKeys}`,
2844
2844
  collapsed,
2845
2845
  parents,
2846
+ flatRowInfoList: [],
2846
2847
  collapsedChildrenCount: 0,
2847
2848
  collapsedGroupsCount: 0,
2848
2849
  indexInParentGroups: options.indexInParentGroups,
@@ -2905,9 +2906,14 @@ function enhancedFlatten(param) {
2905
2906
  }
2906
2907
  if (collapsed) {
2907
2908
  parents.forEach((parent) => {
2909
+ parent.flatRowInfoList.push(enhancedGroupData);
2908
2910
  parent.collapsedChildrenCount += enhancedGroupData.groupCount;
2909
2911
  parent.collapsedGroupsCount += 1;
2910
2912
  });
2913
+ } else {
2914
+ parents.forEach((parent) => {
2915
+ parent.flatRowInfoList.push(enhancedGroupData);
2916
+ });
2911
2917
  }
2912
2918
  indexInParentGroups.push(indexInGroup);
2913
2919
  parents.push(enhancedGroupData);
@@ -2916,7 +2922,7 @@ function enhancedFlatten(param) {
2916
2922
  if (!pivot) {
2917
2923
  const startIndex = result.length;
2918
2924
  result.push(...items.map((item, index) => {
2919
- return {
2925
+ const rowInfo = {
2920
2926
  id: item ? toPrimaryKey(item) : `${groupKeys}-${index}`,
2921
2927
  data: item,
2922
2928
  isGroupRow: false,
@@ -2930,6 +2936,10 @@ function enhancedFlatten(param) {
2930
2936
  groupNesting,
2931
2937
  groupCount: enhancedGroupData.groupCount
2932
2938
  };
2939
+ parents.forEach((parent) => {
2940
+ parent.flatRowInfoList.push(rowInfo);
2941
+ });
2942
+ return rowInfo;
2933
2943
  }));
2934
2944
  }
2935
2945
  } else {
@@ -4208,13 +4218,43 @@ function useHideColumns(groupByMap) {
4208
4218
  componentState: {
4209
4219
  columnTypes,
4210
4220
  computedColumns,
4211
- columnsWhenGrouping: generatedColumns,
4212
4221
  hideEmptyGroupColumns,
4213
4222
  groupRenderStrategy
4214
4223
  }
4215
4224
  } = useComponentState();
4225
+ const prevHideEmptyGroupColumns = usePrevious(hideEmptyGroupColumns);
4216
4226
  (0, import_react17.useEffect)(() => {
4217
- if (groupRenderStrategy !== "multi-column" || !hideEmptyGroupColumns) {
4227
+ if (groupRenderStrategy !== "multi-column") {
4228
+ return;
4229
+ }
4230
+ const currentState = getComponentState();
4231
+ const computedGroupColumns = new Map();
4232
+ computedColumns.forEach((column, colId) => {
4233
+ if (typeof column.groupByField !== "string") {
4234
+ return;
4235
+ }
4236
+ const { groupByField } = column;
4237
+ const field = groupByField;
4238
+ const groupInfoForColumn = groupByMap.get(field);
4239
+ if (!groupInfoForColumn) {
4240
+ return;
4241
+ }
4242
+ computedGroupColumns.set(colId, column);
4243
+ });
4244
+ if (!hideEmptyGroupColumns) {
4245
+ if (prevHideEmptyGroupColumns) {
4246
+ let updated2 = false;
4247
+ const columnVisibility2 = __spreadValues({}, currentState.columnVisibility);
4248
+ computedGroupColumns.forEach((_column, colId) => {
4249
+ if (columnVisibility2[colId] === false) {
4250
+ updated2 = true;
4251
+ delete columnVisibility2[colId];
4252
+ }
4253
+ });
4254
+ if (updated2) {
4255
+ componentActions.columnVisibility = columnVisibility2;
4256
+ }
4257
+ }
4218
4258
  return;
4219
4259
  }
4220
4260
  const groupsLength = groupBy.length;
@@ -4227,23 +4267,24 @@ function useHideColumns(groupByMap) {
4227
4267
  break;
4228
4268
  }
4229
4269
  }
4230
- const currentState = getComponentState();
4231
- const { computedColumns: computedColumns2 } = currentState;
4232
4270
  let updated = false;
4233
4271
  const columnVisibility = __spreadValues({}, currentState.columnVisibility);
4234
- const cols = computedColumns2;
4235
- groupBy.forEach(({ field, column: groupColumn }, index) => {
4236
- const colId = (groupColumn == null ? void 0 : groupColumn.id) || `group-by-${field}`;
4237
- let col = cols.get(colId);
4238
- if (!col) {
4239
- return;
4240
- }
4272
+ computedGroupColumns.forEach((column, colId) => {
4273
+ const { groupByField } = column;
4274
+ const field = groupByField;
4275
+ const groupInfoForColumn = groupByMap.get(field);
4276
+ const index = groupInfoForColumn.groupIndex;
4241
4277
  const shouldBeHidden = index > expandedGroupsLevel && hideEmptyGroupColumns;
4242
- updated = true;
4243
4278
  if (shouldBeHidden) {
4244
- columnVisibility[colId] = false;
4279
+ if (columnVisibility[colId] !== false) {
4280
+ updated = true;
4281
+ columnVisibility[colId] = false;
4282
+ }
4245
4283
  } else {
4246
- delete columnVisibility[colId];
4284
+ if (columnVisibility.hasOwnProperty(colId)) {
4285
+ updated = true;
4286
+ delete columnVisibility[colId];
4287
+ }
4247
4288
  }
4248
4289
  });
4249
4290
  if (updated) {
@@ -4252,9 +4293,10 @@ function useHideColumns(groupByMap) {
4252
4293
  }, [
4253
4294
  getDataSourceState,
4254
4295
  groupRenderStrategy,
4255
- generatedColumns,
4256
4296
  originalLazyGroupDataChangeDetect,
4257
4297
  groupBy,
4298
+ groupByMap,
4299
+ computedColumns,
4258
4300
  hideEmptyGroupColumns ? dataArray : null,
4259
4301
  hideEmptyGroupColumns ? groupRowsState : null,
4260
4302
  hideEmptyGroupColumns
@@ -4434,6 +4476,31 @@ function useComputed() {
4434
4476
  columnSizing,
4435
4477
  columnTypes
4436
4478
  });
4479
+ const rowSpan = (0, import_react18.useMemo)(() => {
4480
+ const colsWithRowspan = computedVisibleColumns.filter((col) => typeof col.rowspan === "function");
4481
+ return colsWithRowspan.length ? ({ itemIndex }) => {
4482
+ let maxSpan = 1;
4483
+ const dataArray = getDataSourceState().dataArray;
4484
+ const rowInfo = dataArray[itemIndex];
4485
+ const data = rowInfo.data;
4486
+ colsWithRowspan.forEach((column) => {
4487
+ if (!column.rowspan) {
4488
+ return;
4489
+ }
4490
+ const span = column.rowspan({
4491
+ column,
4492
+ data,
4493
+ dataArray,
4494
+ rowInfo,
4495
+ rowIndex: itemIndex
4496
+ });
4497
+ if (span > maxSpan) {
4498
+ maxSpan = span;
4499
+ }
4500
+ });
4501
+ return maxSpan;
4502
+ } : void 0;
4503
+ }, [computedVisibleColumns]);
4437
4504
  const unpinnedColumnWidths = computedUnpinnedColumns.map((c) => c.computedWidth);
4438
4505
  let sortedUnpinnedColumnWidths = [...unpinnedColumnWidths].sort(sortAscending);
4439
4506
  let unpinnedColumnRenderCount = 0;
@@ -4460,6 +4527,7 @@ function useComputed() {
4460
4527
  const computedPinnedStartOverflow = computedPinnedStartWidth ? computedPinnedStartColumnsWidth > computedPinnedStartWidth : false;
4461
4528
  const computedPinnedEndOverflow = computedPinnedEndWidth ? computedPinnedEndColumnsWidth > computedPinnedEndWidth : false;
4462
4529
  return {
4530
+ rowSpan,
4463
4531
  toggleGroupRow,
4464
4532
  computedPinnedStartOverflow,
4465
4533
  computedPinnedEndOverflow,
@@ -6064,7 +6132,6 @@ function InfiniteTableColumnCellFn(props) {
6064
6132
  dataArray: getData(),
6065
6133
  column,
6066
6134
  rowInfo,
6067
- groupRowInfo,
6068
6135
  rowIndex,
6069
6136
  data: rowInfo.data
6070
6137
  });
@@ -6112,7 +6179,8 @@ function useRowDOMProps(props, rowProps, rowStyle, rowClassName, groupRenderStra
6112
6179
  showHoverRows = false,
6113
6180
  rowIndex,
6114
6181
  domRef: domRefFromProps,
6115
- rowInfo
6182
+ rowInfo,
6183
+ rowSpan
6116
6184
  } = props;
6117
6185
  const domRef = (0, import_react31.useRef)(null);
6118
6186
  const rowDOMRef = (0, import_react31.useCallback)((node) => {
@@ -6132,7 +6200,7 @@ function useRowDOMProps(props, rowProps, rowStyle, rowClassName, groupRenderStra
6132
6200
  if (rowStyle) {
6133
6201
  style = typeof rowStyle === "function" ? __spreadValues(__spreadValues({}, style), rowStyle(rowPropsAndStyleArgs)) : __spreadValues(__spreadValues({}, style), rowStyle);
6134
6202
  }
6135
- if (inlineGroupRoot) {
6203
+ if (inlineGroupRoot || rowSpan) {
6136
6204
  style = style || {};
6137
6205
  style.zIndex = 2e6 - rowInfo.indexInAll;
6138
6206
  }
@@ -6316,6 +6384,7 @@ function useUnpinnedRendering(params) {
6316
6384
  computedPinnedStartWidth,
6317
6385
  computedPinnedEndWidth,
6318
6386
  computedUnpinnedColumns,
6387
+ rowSpan,
6319
6388
  getState
6320
6389
  } = params;
6321
6390
  const { virtualizeColumns } = getState();
@@ -6329,6 +6398,7 @@ function useUnpinnedRendering(params) {
6329
6398
  showZebraRows,
6330
6399
  showHoverRows,
6331
6400
  getData,
6401
+ rowSpan,
6332
6402
  toggleGroupRow,
6333
6403
  virtualizeColumns: shouldVirtualizeColumns,
6334
6404
  brain: null,
@@ -6345,6 +6415,7 @@ function useUnpinnedRendering(params) {
6345
6415
  }, [
6346
6416
  repaintId,
6347
6417
  rowHeight,
6418
+ rowSpan,
6348
6419
  computedUnpinnedColumns,
6349
6420
  computedUnpinnedColumnsWidth,
6350
6421
  shouldVirtualizeColumns,
@@ -6667,7 +6738,7 @@ function PinnedRowsContainer(props) {
6667
6738
  return /* @__PURE__ */ React30.createElement(RowListWithExternalScrolling, __spreadValues({}, rowListProps));
6668
6739
  }
6669
6740
  function useRenderPinnedRow(params) {
6670
- const { getData, getState, columnsWidth, columns, verticalBrain } = params;
6741
+ const { getData, getState, columnsWidth, columns, rowSpan, verticalBrain } = params;
6671
6742
  const renderPinnedRow = (0, import_react37.useCallback)((rowParams) => {
6672
6743
  const dataArray = getData();
6673
6744
  const rowInfo = dataArray[rowParams.rowIndex];
@@ -6681,6 +6752,7 @@ function useRenderPinnedRow(params) {
6681
6752
  virtualizeColumns: false,
6682
6753
  verticalBrain,
6683
6754
  brain: null,
6755
+ rowSpan,
6684
6756
  rowWidth: columnsWidth,
6685
6757
  columns
6686
6758
  }, rowParams);
@@ -6705,6 +6777,7 @@ function usePinnedRenderingForSide(side, params) {
6705
6777
  computedPinnedStartOverflow,
6706
6778
  pinnedStartScrollListener,
6707
6779
  pinnedEndScrollListener,
6780
+ rowSpan,
6708
6781
  repaintId,
6709
6782
  toggleGroupRow,
6710
6783
  scrollbars: {
@@ -6723,6 +6796,7 @@ function usePinnedRenderingForSide(side, params) {
6723
6796
  getData,
6724
6797
  getState,
6725
6798
  toggleGroupRow,
6799
+ rowSpan,
6726
6800
  verticalBrain: verticalVirtualBrain,
6727
6801
  columns,
6728
6802
  columnsWidth
@@ -7086,7 +7160,7 @@ var VirtualBrain = class extends Logger {
7086
7160
  this.computeCacheFor(lastSizeIndex);
7087
7161
  _prev = lastOffset;
7088
7162
  lastOffset = this.itemOffsetCache[lastSizeIndex];
7089
- if (_prev === lastOffset) {
7163
+ if (_prev === lastOffset && _prev != 0) {
7090
7164
  return count - 1;
7091
7165
  }
7092
7166
  }
@@ -7230,11 +7304,12 @@ var VirtualBrain = class extends Logger {
7230
7304
 
7231
7305
  // src/components/InfiniteTable/hooks/useColumnSizeFn.ts
7232
7306
  var import_react39 = __toModule(require("react"));
7307
+ var debug5 = dbg("useColumnSizeFn");
7233
7308
  function useColumnSizeFn(computedUnpinnedColumns) {
7234
7309
  const columnSize = (0, import_react39.useCallback)((index) => {
7235
7310
  const column = computedUnpinnedColumns[index];
7236
7311
  if (!column) {
7237
- console.log("cannot find column at index", index, computedUnpinnedColumns);
7312
+ debug5("cannot find column at index", index, computedUnpinnedColumns);
7238
7313
  }
7239
7314
  return column ? column.computedWidth : 0;
7240
7315
  }, [computedUnpinnedColumns]);
@@ -7278,6 +7353,10 @@ function useYourBrain(param) {
7278
7353
  }, []);
7279
7354
  horizontalVirtualBrain.update(computedUnpinnedColumns.length, columnSize);
7280
7355
  verticalVirtualBrain.update(dataArray.length, rowHeight, rowSpan);
7356
+ if (true) {
7357
+ globalThis.verticalVirtualBrain = verticalVirtualBrain;
7358
+ globalThis.horizontalVirtualBrain = horizontalVirtualBrain;
7359
+ }
7281
7360
  (0, import_react40.useEffect)(() => {
7282
7361
  verticalVirtualBrain.setAvailableSize({
7283
7362
  height: bodySize.height,
@@ -7309,7 +7388,7 @@ function useListRendering(param) {
7309
7388
  computedUnpinnedColumnsWidth,
7310
7389
  computedPinnedStartOverflow,
7311
7390
  computedPinnedEndOverflow,
7312
- computedVisibleColumns,
7391
+ rowSpan,
7313
7392
  toggleGroupRow
7314
7393
  } = computed;
7315
7394
  const { componentState: dataSourceState, getState: getDataSourceState } = useDataSourceContextValue();
@@ -7328,32 +7407,6 @@ function useListRendering(param) {
7328
7407
  repaintIdRef.current++;
7329
7408
  }
7330
7409
  const repaintId = repaintIdRef.current;
7331
- const rowSpan = (0, import_react41.useMemo)(() => {
7332
- const colsWithRowspan = computedVisibleColumns.filter((col) => typeof col.rowspan === "function");
7333
- return colsWithRowspan.length ? ({ itemIndex }) => {
7334
- let maxSpan = 1;
7335
- const dataArray2 = getData();
7336
- const rowInfo = dataArray2[itemIndex];
7337
- const data = rowInfo.data;
7338
- colsWithRowspan.forEach((column) => {
7339
- if (!column.rowspan) {
7340
- return;
7341
- }
7342
- const span = column.rowspan({
7343
- column,
7344
- data,
7345
- dataArray: dataArray2,
7346
- groupRowInfo: null,
7347
- rowInfo,
7348
- rowIndex: itemIndex
7349
- });
7350
- if (span > maxSpan) {
7351
- maxSpan = span;
7352
- }
7353
- });
7354
- return maxSpan;
7355
- } : void 0;
7356
- }, [computedVisibleColumns]);
7357
7410
  const { horizontalVirtualBrain, verticalVirtualBrain } = useYourBrain({
7358
7411
  computedPinnedStartWidth: computed.computedPinnedStartWidth,
7359
7412
  computedPinnedEndWidth: computed.computedPinnedEndWidth,
@@ -7414,7 +7467,8 @@ function useListRendering(param) {
7414
7467
  rowHeight,
7415
7468
  verticalVirtualBrain,
7416
7469
  pinnedStartScrollListener,
7417
- pinnedEndScrollListener
7470
+ pinnedEndScrollListener,
7471
+ rowSpan
7418
7472
  };
7419
7473
  const centerRenderingParams = __spreadProps(__spreadValues({}, pinnedRenderingParams), {
7420
7474
  columnShifts,
@@ -7670,17 +7724,25 @@ var decode = (licenseKey) => {
7670
7724
  };
7671
7725
 
7672
7726
  // src/components/InfiniteTable/hooks/useLicense/useLicense.ts
7673
- var SANDBOX_REGEX = /(https):\/\/\d+\-\d+\-\d\-(sandpack\.codesandbox\.io)/g;
7727
+ var SANDPACK_REGEX = /(https):\/\/\d+\-\d+\-\d+\-(sandpack\.codesandbox\.io)/g;
7728
+ var SANDBOX_REGEX = /(https):\/\/\S+(\.csb\.app)/g;
7674
7729
  var origin = typeof window !== "undefined" ? window.location.origin : "";
7675
- var [_fullUrl, protocol, sandboxUrl] = Array.from(SANDBOX_REGEX.exec(origin) || []);
7676
- var isInsideSandbox = protocol === "https" && sandboxUrl === "sandpack.codesandbox.io";
7730
+ var isInsideSandpack = () => {
7731
+ const [_fullUrl, protocol, sandpackUrl] = Array.from(SANDPACK_REGEX.exec(origin) || []);
7732
+ return protocol === "https" && sandpackUrl === "sandpack.codesandbox.io";
7733
+ };
7734
+ var isInsideSandbox = () => {
7735
+ const [_fullUrl, protocol, sandboxUrl] = Array.from(SANDBOX_REGEX.exec(origin) || []);
7736
+ return protocol === "https" && sandboxUrl === ".csb.app";
7737
+ };
7738
+ var isInsidePlayground = isInsideSandbox() || isInsideSandpack();
7677
7739
  var useLicense = (licenseKey = "") => {
7678
7740
  const valid = (0, import_react43.useMemo)(() => {
7679
7741
  let valid2 = isValidLicense(licenseKey, {
7680
7742
  publishedAt: 1624970570587,
7681
- version: "0.2.6"
7743
+ version: "0.2.9"
7682
7744
  });
7683
- if (!licenseKey && !valid2 && isInsideSandbox) {
7745
+ if (!licenseKey && !valid2 && isInsidePlayground) {
7684
7746
  return true;
7685
7747
  }
7686
7748
  return valid2;
@@ -7692,7 +7754,7 @@ var useLicense = (licenseKey = "") => {
7692
7754
  var React32 = __toModule(require("react"));
7693
7755
  var import_react44 = __toModule(require("react"));
7694
7756
  var error = err("CSSVariableWatch");
7695
- var debug5 = dbg("CSSVariableWatch");
7757
+ var debug6 = dbg("CSSVariableWatch");
7696
7758
  var WRAPPER_STYLE = {
7697
7759
  position: "absolute",
7698
7760
  pointerEvents: "none",
@@ -7715,7 +7777,7 @@ var useCSSVariableWatch = (params) => {
7715
7777
  const value = params.ref.current.getBoundingClientRect().height;
7716
7778
  if (value) {
7717
7779
  lastValueRef.current = value;
7718
- debug5(`Variable ${params.varName} found and equals ${value}.`);
7780
+ debug6(`Variable ${params.varName} found and equals ${value}.`);
7719
7781
  params.onChange(value);
7720
7782
  } else {
7721
7783
  error(`Specified variable ${params.varName} not found or does not have a numeric value.`);
package/package.json CHANGED
@@ -1,7 +1,7 @@
1
1
  {
2
2
  "name": "@infinite-table/infinite-react",
3
3
  "description": "Infinite Table for React",
4
- "version": "0.2.6",
4
+ "version": "0.2.9",
5
5
  "main": "index.js",
6
6
  "module": "index.esm.js",
7
7
  "typings": "index.d.ts",
@@ -14,5 +14,5 @@
14
14
  },
15
15
  "license": "Commercial & Open Source",
16
16
  "//": "will be updated at build time",
17
- "publishedAt": 1644931690394
17
+ "publishedAt": 1646311895842
18
18
  }