@infinite-table/infinite-react 6.0.18 → 6.0.19

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.dev.js CHANGED
@@ -16266,12 +16266,82 @@ function toRowInfo(data, id, index, isRowSelected, isRowDisabled, cellSelectionS
16266
16266
  }
16267
16267
  return rowInfo;
16268
16268
  }
16269
+ var warnIncorrectTreeFilterOnce = once(() => {
16270
+ console.warn(`Your "treeFilterFunction" should NOT MUTATE the data object. You're probably mutating the node children.
16271
+
16272
+ Your filtering function probably looks like this:
16273
+
16274
+ function treeFilterFunction({ data }) {
16275
+ data.children = data.children.filter(...) // <-- THIS MUTATION IS NOT SUPPORTED!
16276
+ return data
16277
+ }
16278
+
16279
+ Make sure you avoid mutations.
16280
+
16281
+ `);
16282
+ });
16283
+ function filterTreeDataSource(params) {
16284
+ const {
16285
+ dataArray,
16286
+ treeFilterFunction,
16287
+ toPrimaryKey,
16288
+ getNodeChildren,
16289
+ isLeafNode,
16290
+ nodesKey
16291
+ } = params;
16292
+ let treeDataArray = [];
16293
+ const filterTreeNode = (data) => {
16294
+ const children = getNodeChildren(data);
16295
+ if (isLeafNode(data) || !Array.isArray(children)) {
16296
+ return data;
16297
+ }
16298
+ const newChildren = filterTreeDataSource({
16299
+ ...params,
16300
+ dataArray: children
16301
+ });
16302
+ if (newChildren.length === 0) {
16303
+ return false;
16304
+ }
16305
+ data = {
16306
+ ...data,
16307
+ [nodesKey]: newChildren
16308
+ };
16309
+ return data;
16310
+ };
16311
+ for (let i = 0, len = dataArray.length; i < len; i++) {
16312
+ const data = dataArray[i];
16313
+ const initialChildren = getNodeChildren(data);
16314
+ let res = treeFilterFunction({
16315
+ data,
16316
+ index: i,
16317
+ dataArray,
16318
+ primaryKey: toPrimaryKey(data, i),
16319
+ filterTreeNode
16320
+ });
16321
+ if (!res) {
16322
+ continue;
16323
+ }
16324
+ if (res === true) {
16325
+ res = data;
16326
+ } else if (typeof res === "object") {
16327
+ if (res === data && initialChildren !== getNodeChildren(res)) {
16328
+ warnIncorrectTreeFilterOnce();
16329
+ }
16330
+ }
16331
+ treeDataArray.push(res);
16332
+ }
16333
+ return treeDataArray;
16334
+ }
16269
16335
  function filterDataSource(params) {
16270
16336
  const {
16271
16337
  filterTypes,
16272
16338
  operatorsByFilterType,
16273
16339
  filterFunction,
16274
- toPrimaryKey
16340
+ toPrimaryKey,
16341
+ treeFilterFunction,
16342
+ getNodeChildren,
16343
+ nodesKey,
16344
+ isLeafNode
16275
16345
  } = params;
16276
16346
  let { dataArray } = params;
16277
16347
  if (filterFunction) {
@@ -16284,6 +16354,15 @@ function filterDataSource(params) {
16284
16354
  })
16285
16355
  );
16286
16356
  }
16357
+ if (treeFilterFunction) {
16358
+ dataArray = filterTreeDataSource({
16359
+ ...params,
16360
+ treeFilterFunction,
16361
+ getNodeChildren,
16362
+ nodesKey,
16363
+ isLeafNode
16364
+ });
16365
+ }
16287
16366
  const filterValueArray = cleanupEmptyFilterValues(params.filterValue, filterTypes) || [];
16288
16367
  if (filterValueArray && filterValueArray.length) {
16289
16368
  return dataArray.filter((data, index, arr) => {
@@ -16398,11 +16477,18 @@ function concludeReducer(params) {
16398
16477
  cache.clear();
16399
16478
  state.cache = void 0;
16400
16479
  }
16401
- const { filterFunction, filterValue, filterTypes, operatorsByFilterType } = state;
16402
- const shouldFilter = !!filterFunction || Array.isArray(filterValue) && filterValue.length;
16480
+ const {
16481
+ filterFunction,
16482
+ treeFilterFunction,
16483
+ filterValue,
16484
+ filterTypes,
16485
+ operatorsByFilterType
16486
+ } = state;
16487
+ const shouldFilter = !!filterFunction || !!treeFilterFunction || Array.isArray(filterValue) && filterValue.length;
16403
16488
  const shouldFilterClientSide = shouldFilter && state.filterMode === "local";
16404
16489
  const filterDepsChanged = haveDepsChanged(previousState, state, [
16405
16490
  "filterFunction",
16491
+ "treeFilterFunction",
16406
16492
  "filterValue",
16407
16493
  "filterTypes"
16408
16494
  ]);
@@ -16468,6 +16554,12 @@ function concludeReducer(params) {
16468
16554
  if (shouldFilterClientSide) {
16469
16555
  state.unfilteredCount = dataArray.length;
16470
16556
  dataArray = shouldFilterAgain ? filterDataSource({
16557
+ // tree-related stuff
16558
+ getNodeChildren,
16559
+ isLeafNode,
16560
+ nodesKey,
16561
+ treeFilterFunction,
16562
+ // ---
16471
16563
  dataArray,
16472
16564
  toPrimaryKey,
16473
16565
  filterTypes,
@@ -17594,6 +17686,7 @@ var forwardProps3 = (setupState, props) => {
17594
17686
  treeSelection: 1,
17595
17687
  refetchKey: (refetchKey) => refetchKey ?? "",
17596
17688
  filterFunction: 1,
17689
+ treeFilterFunction: 1,
17597
17690
  filterValue: 1,
17598
17691
  useGroupKeysForMultiRowSelection: (useGroupKeysForMultiRowSelection) => useGroupKeysForMultiRowSelection ?? false,
17599
17692
  filterDelay: (filterDelay) => filterDelay ?? 200,
@@ -17881,7 +17974,7 @@ function deriveStateFromProps(params) {
17881
17974
  }
17882
17975
  const groupMode = typeof props.data === "function" ? propsGroupMode ?? "local" : "local";
17883
17976
  const sortMode = props.sortFunction ? "local" : propsSortMode ?? (controlledSort ? "remote" : "local");
17884
- const filterMode = typeof props.filterFunction === "function" ? "local" : propsFilterMode ?? (typeof props.data === "function" ? "remote" : "local");
17977
+ const filterMode = typeof props.filterFunction === "function" || typeof props.treeFilterFunction === "function" ? "local" : propsFilterMode ?? (typeof props.data === "function" ? "remote" : "local");
17885
17978
  const pivotMode = shouldReloadData.pivotBy ? "remote" : "local";
17886
17979
  const rowDisabledState = state.rowDisabledState;
17887
17980
  let isRowDisabled = props.isRowDisabled;
@@ -21108,6 +21201,7 @@ var forwardProps4 = (_setupState) => {
21108
21201
  debugMode: 1,
21109
21202
  onKeyDown: 1,
21110
21203
  onCellClick: 1,
21204
+ onCellDoubleClick: 1,
21111
21205
  focusedClassName: 1,
21112
21206
  focusedWithinClassName: 1,
21113
21207
  focusedStyle: 1,
@@ -22516,7 +22610,7 @@ var useLicense = (licenseKey = "") => {
22516
22610
  }
22517
22611
  let valid2 = isValidLicense(licenseKey, {
22518
22612
  publishedAt: 1624970570587,
22519
- version: "6.0.18"
22613
+ version: "6.0.19"
22520
22614
  });
22521
22615
  if (!licenseKey && !valid2 && isInsidePlayground) {
22522
22616
  return true;
@@ -22617,7 +22711,20 @@ function onCellClick(context, event) {
22617
22711
  }
22618
22712
  context.getState().onCellClick?.(context, event);
22619
22713
  }
22620
- function onCellDoubleClick(context, _event) {
22714
+ function onCellDoubleClick(context, event) {
22715
+ const { onCellDoubleClick: onCellDoubleClick2 } = context.getState();
22716
+ let dblClickResult = {
22717
+ preventEdit: false
22718
+ };
22719
+ if (onCellDoubleClick2) {
22720
+ const result = onCellDoubleClick2(context, event);
22721
+ if (result && typeof result === "object") {
22722
+ dblClickResult = { ...dblClickResult, ...result };
22723
+ }
22724
+ }
22725
+ if (dblClickResult.preventEdit) {
22726
+ return;
22727
+ }
22621
22728
  const computed = context.getComputed();
22622
22729
  const column = computed.computedVisibleColumns[context.colIndex];
22623
22730
  context.api.startEdit({
@@ -23495,7 +23602,21 @@ async function onKeyDown(context, event) {
23495
23602
  return cloneTreeSelection(treeSelection2, context.getDataSourceState);
23496
23603
  }
23497
23604
  };
23498
- if (handleKeyboardSelection(keyboardHandlerContext, event)) {
23605
+ const { onKeyDown: onKeyDownProp } = context.getState();
23606
+ let keyDownResult = {
23607
+ preventEdit: false,
23608
+ preventEditStop: false,
23609
+ preventDefaultForTabKeyWhenEditing: true,
23610
+ preventSelection: false,
23611
+ preventNavigation: false
23612
+ };
23613
+ if (onKeyDownProp) {
23614
+ const result = onKeyDownProp(context, event);
23615
+ if (result && typeof result === "object") {
23616
+ keyDownResult = { ...keyDownResult, ...result };
23617
+ }
23618
+ }
23619
+ if (!keyDownResult.preventSelection && handleKeyboardSelection(keyboardHandlerContext, event)) {
23499
23620
  event.preventDefault();
23500
23621
  }
23501
23622
  if (handleBrowserFocusChangeOnKeyboardNavigation(keyboardHandlerContext, event)) {
@@ -23505,7 +23626,7 @@ async function onKeyDown(context, event) {
23505
23626
  event.preventDefault();
23506
23627
  }
23507
23628
  }
23508
- if (event.key === "Enter" && !context.api.isEditInProgress()) {
23629
+ if (!keyDownResult.preventEdit && event.key === "Enter" && !context.api.isEditInProgress()) {
23509
23630
  const { activeCellIndex } = context.getState();
23510
23631
  if (activeCellIndex) {
23511
23632
  const [rowIndex, colIndex] = activeCellIndex;
@@ -23519,14 +23640,13 @@ async function onKeyDown(context, event) {
23519
23640
  }
23520
23641
  }
23521
23642
  if (context.api.isEditInProgress()) {
23522
- if (event.key === "Escape") {
23643
+ if (event.key === "Escape" && !keyDownResult.preventEditStop) {
23523
23644
  context.api.stopEdit({ cancel: true });
23524
23645
  }
23525
- if (event.key === "Tab") {
23646
+ if (event.key === "Tab" && keyDownResult.preventDefaultForTabKeyWhenEditing) {
23526
23647
  event.preventDefault();
23527
23648
  }
23528
23649
  }
23529
- context.getState().onKeyDown?.(context, event);
23530
23650
  const { keyboardShortcuts: keyboardShortcuts2 } = context.getState();
23531
23651
  if (keyboardShortcuts2) {
23532
23652
  for await (const shortcut of keyboardShortcuts2) {
package/index.dev.mjs CHANGED
@@ -16215,12 +16215,82 @@ function toRowInfo(data, id, index, isRowSelected, isRowDisabled, cellSelectionS
16215
16215
  }
16216
16216
  return rowInfo;
16217
16217
  }
16218
+ var warnIncorrectTreeFilterOnce = once(() => {
16219
+ console.warn(`Your "treeFilterFunction" should NOT MUTATE the data object. You're probably mutating the node children.
16220
+
16221
+ Your filtering function probably looks like this:
16222
+
16223
+ function treeFilterFunction({ data }) {
16224
+ data.children = data.children.filter(...) // <-- THIS MUTATION IS NOT SUPPORTED!
16225
+ return data
16226
+ }
16227
+
16228
+ Make sure you avoid mutations.
16229
+
16230
+ `);
16231
+ });
16232
+ function filterTreeDataSource(params) {
16233
+ const {
16234
+ dataArray,
16235
+ treeFilterFunction,
16236
+ toPrimaryKey,
16237
+ getNodeChildren,
16238
+ isLeafNode,
16239
+ nodesKey
16240
+ } = params;
16241
+ let treeDataArray = [];
16242
+ const filterTreeNode = (data) => {
16243
+ const children = getNodeChildren(data);
16244
+ if (isLeafNode(data) || !Array.isArray(children)) {
16245
+ return data;
16246
+ }
16247
+ const newChildren = filterTreeDataSource({
16248
+ ...params,
16249
+ dataArray: children
16250
+ });
16251
+ if (newChildren.length === 0) {
16252
+ return false;
16253
+ }
16254
+ data = {
16255
+ ...data,
16256
+ [nodesKey]: newChildren
16257
+ };
16258
+ return data;
16259
+ };
16260
+ for (let i = 0, len = dataArray.length; i < len; i++) {
16261
+ const data = dataArray[i];
16262
+ const initialChildren = getNodeChildren(data);
16263
+ let res = treeFilterFunction({
16264
+ data,
16265
+ index: i,
16266
+ dataArray,
16267
+ primaryKey: toPrimaryKey(data, i),
16268
+ filterTreeNode
16269
+ });
16270
+ if (!res) {
16271
+ continue;
16272
+ }
16273
+ if (res === true) {
16274
+ res = data;
16275
+ } else if (typeof res === "object") {
16276
+ if (res === data && initialChildren !== getNodeChildren(res)) {
16277
+ warnIncorrectTreeFilterOnce();
16278
+ }
16279
+ }
16280
+ treeDataArray.push(res);
16281
+ }
16282
+ return treeDataArray;
16283
+ }
16218
16284
  function filterDataSource(params) {
16219
16285
  const {
16220
16286
  filterTypes,
16221
16287
  operatorsByFilterType,
16222
16288
  filterFunction,
16223
- toPrimaryKey
16289
+ toPrimaryKey,
16290
+ treeFilterFunction,
16291
+ getNodeChildren,
16292
+ nodesKey,
16293
+ isLeafNode
16224
16294
  } = params;
16225
16295
  let { dataArray } = params;
16226
16296
  if (filterFunction) {
@@ -16233,6 +16303,15 @@ function filterDataSource(params) {
16233
16303
  })
16234
16304
  );
16235
16305
  }
16306
+ if (treeFilterFunction) {
16307
+ dataArray = filterTreeDataSource({
16308
+ ...params,
16309
+ treeFilterFunction,
16310
+ getNodeChildren,
16311
+ nodesKey,
16312
+ isLeafNode
16313
+ });
16314
+ }
16236
16315
  const filterValueArray = cleanupEmptyFilterValues(params.filterValue, filterTypes) || [];
16237
16316
  if (filterValueArray && filterValueArray.length) {
16238
16317
  return dataArray.filter((data, index, arr) => {
@@ -16347,11 +16426,18 @@ function concludeReducer(params) {
16347
16426
  cache.clear();
16348
16427
  state.cache = void 0;
16349
16428
  }
16350
- const { filterFunction, filterValue, filterTypes, operatorsByFilterType } = state;
16351
- const shouldFilter = !!filterFunction || Array.isArray(filterValue) && filterValue.length;
16429
+ const {
16430
+ filterFunction,
16431
+ treeFilterFunction,
16432
+ filterValue,
16433
+ filterTypes,
16434
+ operatorsByFilterType
16435
+ } = state;
16436
+ const shouldFilter = !!filterFunction || !!treeFilterFunction || Array.isArray(filterValue) && filterValue.length;
16352
16437
  const shouldFilterClientSide = shouldFilter && state.filterMode === "local";
16353
16438
  const filterDepsChanged = haveDepsChanged(previousState, state, [
16354
16439
  "filterFunction",
16440
+ "treeFilterFunction",
16355
16441
  "filterValue",
16356
16442
  "filterTypes"
16357
16443
  ]);
@@ -16417,6 +16503,12 @@ function concludeReducer(params) {
16417
16503
  if (shouldFilterClientSide) {
16418
16504
  state.unfilteredCount = dataArray.length;
16419
16505
  dataArray = shouldFilterAgain ? filterDataSource({
16506
+ // tree-related stuff
16507
+ getNodeChildren,
16508
+ isLeafNode,
16509
+ nodesKey,
16510
+ treeFilterFunction,
16511
+ // ---
16420
16512
  dataArray,
16421
16513
  toPrimaryKey,
16422
16514
  filterTypes,
@@ -17543,6 +17635,7 @@ var forwardProps3 = (setupState, props) => {
17543
17635
  treeSelection: 1,
17544
17636
  refetchKey: (refetchKey) => refetchKey ?? "",
17545
17637
  filterFunction: 1,
17638
+ treeFilterFunction: 1,
17546
17639
  filterValue: 1,
17547
17640
  useGroupKeysForMultiRowSelection: (useGroupKeysForMultiRowSelection) => useGroupKeysForMultiRowSelection ?? false,
17548
17641
  filterDelay: (filterDelay) => filterDelay ?? 200,
@@ -17830,7 +17923,7 @@ function deriveStateFromProps(params) {
17830
17923
  }
17831
17924
  const groupMode = typeof props.data === "function" ? propsGroupMode ?? "local" : "local";
17832
17925
  const sortMode = props.sortFunction ? "local" : propsSortMode ?? (controlledSort ? "remote" : "local");
17833
- const filterMode = typeof props.filterFunction === "function" ? "local" : propsFilterMode ?? (typeof props.data === "function" ? "remote" : "local");
17926
+ const filterMode = typeof props.filterFunction === "function" || typeof props.treeFilterFunction === "function" ? "local" : propsFilterMode ?? (typeof props.data === "function" ? "remote" : "local");
17834
17927
  const pivotMode = shouldReloadData.pivotBy ? "remote" : "local";
17835
17928
  const rowDisabledState = state.rowDisabledState;
17836
17929
  let isRowDisabled = props.isRowDisabled;
@@ -21066,6 +21159,7 @@ var forwardProps4 = (_setupState) => {
21066
21159
  debugMode: 1,
21067
21160
  onKeyDown: 1,
21068
21161
  onCellClick: 1,
21162
+ onCellDoubleClick: 1,
21069
21163
  focusedClassName: 1,
21070
21164
  focusedWithinClassName: 1,
21071
21165
  focusedStyle: 1,
@@ -22474,7 +22568,7 @@ var useLicense = (licenseKey = "") => {
22474
22568
  }
22475
22569
  let valid2 = isValidLicense(licenseKey, {
22476
22570
  publishedAt: 1624970570587,
22477
- version: "6.0.18"
22571
+ version: "6.0.19"
22478
22572
  });
22479
22573
  if (!licenseKey && !valid2 && isInsidePlayground) {
22480
22574
  return true;
@@ -22575,7 +22669,20 @@ function onCellClick(context, event) {
22575
22669
  }
22576
22670
  context.getState().onCellClick?.(context, event);
22577
22671
  }
22578
- function onCellDoubleClick(context, _event) {
22672
+ function onCellDoubleClick(context, event) {
22673
+ const { onCellDoubleClick: onCellDoubleClick2 } = context.getState();
22674
+ let dblClickResult = {
22675
+ preventEdit: false
22676
+ };
22677
+ if (onCellDoubleClick2) {
22678
+ const result = onCellDoubleClick2(context, event);
22679
+ if (result && typeof result === "object") {
22680
+ dblClickResult = { ...dblClickResult, ...result };
22681
+ }
22682
+ }
22683
+ if (dblClickResult.preventEdit) {
22684
+ return;
22685
+ }
22579
22686
  const computed = context.getComputed();
22580
22687
  const column = computed.computedVisibleColumns[context.colIndex];
22581
22688
  context.api.startEdit({
@@ -23453,7 +23560,21 @@ async function onKeyDown(context, event) {
23453
23560
  return cloneTreeSelection(treeSelection2, context.getDataSourceState);
23454
23561
  }
23455
23562
  };
23456
- if (handleKeyboardSelection(keyboardHandlerContext, event)) {
23563
+ const { onKeyDown: onKeyDownProp } = context.getState();
23564
+ let keyDownResult = {
23565
+ preventEdit: false,
23566
+ preventEditStop: false,
23567
+ preventDefaultForTabKeyWhenEditing: true,
23568
+ preventSelection: false,
23569
+ preventNavigation: false
23570
+ };
23571
+ if (onKeyDownProp) {
23572
+ const result = onKeyDownProp(context, event);
23573
+ if (result && typeof result === "object") {
23574
+ keyDownResult = { ...keyDownResult, ...result };
23575
+ }
23576
+ }
23577
+ if (!keyDownResult.preventSelection && handleKeyboardSelection(keyboardHandlerContext, event)) {
23457
23578
  event.preventDefault();
23458
23579
  }
23459
23580
  if (handleBrowserFocusChangeOnKeyboardNavigation(keyboardHandlerContext, event)) {
@@ -23463,7 +23584,7 @@ async function onKeyDown(context, event) {
23463
23584
  event.preventDefault();
23464
23585
  }
23465
23586
  }
23466
- if (event.key === "Enter" && !context.api.isEditInProgress()) {
23587
+ if (!keyDownResult.preventEdit && event.key === "Enter" && !context.api.isEditInProgress()) {
23467
23588
  const { activeCellIndex } = context.getState();
23468
23589
  if (activeCellIndex) {
23469
23590
  const [rowIndex, colIndex] = activeCellIndex;
@@ -23477,14 +23598,13 @@ async function onKeyDown(context, event) {
23477
23598
  }
23478
23599
  }
23479
23600
  if (context.api.isEditInProgress()) {
23480
- if (event.key === "Escape") {
23601
+ if (event.key === "Escape" && !keyDownResult.preventEditStop) {
23481
23602
  context.api.stopEdit({ cancel: true });
23482
23603
  }
23483
- if (event.key === "Tab") {
23604
+ if (event.key === "Tab" && keyDownResult.preventDefaultForTabKeyWhenEditing) {
23484
23605
  event.preventDefault();
23485
23606
  }
23486
23607
  }
23487
- context.getState().onKeyDown?.(context, event);
23488
23608
  const { keyboardShortcuts: keyboardShortcuts2 } = context.getState();
23489
23609
  if (keyboardShortcuts2) {
23490
23610
  for await (const shortcut of keyboardShortcuts2) {