@infinite-table/infinite-react 3.3.1 → 3.3.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/index.dev.mjs CHANGED
@@ -73,6 +73,15 @@ var __async = (__this, __arguments, generator) => {
73
73
  step((generator = generator.apply(__this, __arguments)).next());
74
74
  });
75
75
  };
76
+ var __forAwait = (obj, it, method) => {
77
+ it = obj[Symbol.asyncIterator];
78
+ method = (key, fn) => (fn = obj[key]) && (it[key] = (arg) => new Promise((resolve, reject, done) => {
79
+ arg = fn.call(obj, arg);
80
+ done = arg.done;
81
+ return Promise.resolve(arg.value).then((value) => resolve({ value, done }), reject);
82
+ }));
83
+ return it ? it.call(obj) : (obj = obj[Symbol.iterator](), it = {}, method("next"), method("return"), it);
84
+ };
76
85
 
77
86
  // ../node_modules/binary-search/index.js
78
87
  var require_binary_search = __commonJS({
@@ -15609,6 +15618,10 @@ var InfiniteTableApiImpl = class {
15609
15618
  this.rejectEdit = (reason) => {
15610
15619
  return this.stopEdit({ reject: reason });
15611
15620
  };
15621
+ this.getColumnAtIndex = (index) => {
15622
+ var _a;
15623
+ return (_a = this.getComputed().computedVisibleColumns[index]) != null ? _a : null;
15624
+ };
15612
15625
  this.isCellEditable = (params) => {
15613
15626
  const { rowIndex: index, primaryKey, columnId } = params;
15614
15627
  const rowIndex = index != null ? index : this.context.dataSourceApi.getIndexByPrimaryKey(primaryKey);
@@ -15867,7 +15880,12 @@ var InfiniteTableApiImpl = class {
15867
15880
  }
15868
15881
  startEdit(params) {
15869
15882
  return __async(this, null, function* () {
15870
- const { columnId, rowIndex: index, primaryKey } = params;
15883
+ const {
15884
+ columnId,
15885
+ rowIndex: index,
15886
+ primaryKey,
15887
+ value: valueToSetInitially
15888
+ } = params;
15871
15889
  const rowIndex = index != null ? index : this.context.dataSourceApi.getIndexByPrimaryKey(primaryKey);
15872
15890
  return this.isCellEditable({
15873
15891
  rowIndex,
@@ -15879,7 +15897,7 @@ var InfiniteTableApiImpl = class {
15879
15897
  const columnsMap = this.getComputed().computedColumnsMap;
15880
15898
  const column = columnsMap.get(columnId);
15881
15899
  const rowInfo = dataArray[rowIndex];
15882
- let value = getColumnValueToEdit({
15900
+ let value = valueToSetInitially != null ? valueToSetInitially : getColumnValueToEdit({
15883
15901
  column,
15884
15902
  rowInfo
15885
15903
  // columnsMap,
@@ -17394,6 +17412,7 @@ var forwardProps4 = (setupState) => {
17394
17412
  columnDefaultEditable: 1,
17395
17413
  columnDefaultFilterable: 1,
17396
17414
  columnDefaultSortable: 1,
17415
+ keyboardShortcuts: 1,
17397
17416
  rowStyle: 1,
17398
17417
  cellStyle: 1,
17399
17418
  rowProps: 1,
@@ -18754,7 +18773,7 @@ var useLicense = (licenseKey = "") => {
18754
18773
  }
18755
18774
  let valid2 = isValidLicense(licenseKey, {
18756
18775
  publishedAt: 1624970570587,
18757
- version: "3.3.1"
18776
+ version: "3.3.3"
18758
18777
  });
18759
18778
  if (!licenseKey && !valid2 && isInsidePlayground) {
18760
18779
  return true;
@@ -19526,46 +19545,171 @@ function handleBrowserFocusChangeOnKeyboardNavigation(context, event) {
19526
19545
  return true;
19527
19546
  }
19528
19547
 
19548
+ // src/components/utils/hotkey.ts
19549
+ var KeyModifierAliases = {
19550
+ control: "ctrl"
19551
+ };
19552
+ var CmdOrCtrlAliases = {
19553
+ "control|cmd": "ctrl",
19554
+ "cmd|control": "ctrl",
19555
+ "ctrl|cmd": "ctrl",
19556
+ "cmd|ctrl": "ctrl"
19557
+ };
19558
+ var KeyAliases = {
19559
+ esc: "escape"
19560
+ };
19561
+ var keyModifierChecker = {
19562
+ cmd: (event) => event.metaKey,
19563
+ alt: (event) => event.altKey,
19564
+ ctrl: (event) => event.ctrlKey,
19565
+ shift: (event) => event.shiftKey
19566
+ };
19567
+ var keyModifierNames = Object.keys(keyModifierChecker);
19568
+ var keyModifierSet = new Set(keyModifierNames);
19569
+ var allowedStarModifiers = /* @__PURE__ */ new Set(["shift", "alt"]);
19570
+ function eventMatchesKeyboardShortcut(event, keyDescriptors) {
19571
+ if (!Array.isArray(keyDescriptors)) {
19572
+ return eventMatchesSingleShortcut(event, keyDescriptors);
19573
+ }
19574
+ return keyDescriptors.some(
19575
+ (keyDescriptor) => eventMatchesSingleShortcut(event, keyDescriptor)
19576
+ );
19577
+ }
19578
+ function eventMatchesSingleShortcut(event, keyDescriptor) {
19579
+ const keyLowercase = event.key.toLowerCase();
19580
+ const splitPartsLowercase = keyDescriptor.split("+").map((part) => part.toLowerCase().trim());
19581
+ const hasCmdOrCtrlAlias = splitPartsLowercase.find(
19582
+ (part) => CmdOrCtrlAliases[part]
19583
+ );
19584
+ const parts = splitPartsLowercase.map(
19585
+ (part) => KeyModifierAliases[part] || CmdOrCtrlAliases[part] || KeyAliases[part] || part
19586
+ );
19587
+ const expectedModifiers = parts.filter(
19588
+ (part) => keyModifierSet.has(part)
19589
+ );
19590
+ const nonModifierParts = parts.filter(
19591
+ (part) => !keyModifierSet.has(part)
19592
+ );
19593
+ const currentModifierMatches = keyModifierNames.reduce((acc, modifier) => {
19594
+ acc[modifier] = keyModifierChecker[modifier](event);
19595
+ return acc;
19596
+ }, {});
19597
+ if (hasCmdOrCtrlAlias && currentModifierMatches.cmd) {
19598
+ currentModifierMatches.cmd = false;
19599
+ currentModifierMatches.ctrl = true;
19600
+ }
19601
+ const currentModifierMatchesList = Object.keys(currentModifierMatches).filter(
19602
+ (key) => currentModifierMatches[key]
19603
+ );
19604
+ const hasAllModifiers = expectedModifiers.every(
19605
+ (modifier) => currentModifierMatches[modifier] === true
19606
+ );
19607
+ if (!hasAllModifiers) {
19608
+ return false;
19609
+ }
19610
+ const hasStar = nonModifierParts.includes("*");
19611
+ if (!hasStar) {
19612
+ if (expectedModifiers.length != currentModifierMatchesList.length) {
19613
+ return false;
19614
+ }
19615
+ } else {
19616
+ if (currentModifierMatchesList.length < expectedModifiers.length) {
19617
+ return false;
19618
+ }
19619
+ const nonAllowedModifiers = currentModifierMatchesList.filter(
19620
+ (modifier) => !allowedStarModifiers.has(modifier)
19621
+ );
19622
+ if (nonAllowedModifiers.length) {
19623
+ return false;
19624
+ }
19625
+ }
19626
+ if (!nonModifierParts.length) {
19627
+ return false;
19628
+ }
19629
+ if (keyModifierSet.has(keyLowercase) || keyLowercase === "meta" || KeyModifierAliases[keyLowercase]) {
19630
+ return false;
19631
+ }
19632
+ return nonModifierParts.reduce((acc, part) => {
19633
+ if (!acc) {
19634
+ return false;
19635
+ }
19636
+ const res = part === "*" || keyLowercase === part;
19637
+ return res;
19638
+ }, true);
19639
+ }
19640
+
19529
19641
  // src/components/InfiniteTable/eventHandlers/onKeyDown.ts
19530
19642
  function onKeyDown(context, event) {
19531
- var _a, _b;
19532
- const keyboardHandlerContext = __spreadProps(__spreadValues({}, context), {
19533
- cloneRowSelection: (rowSelection) => {
19534
- return cloneRowSelection(rowSelection, context.getDataSourceState);
19643
+ return __async(this, null, function* () {
19644
+ var _a, _b;
19645
+ const keyboardHandlerContext = __spreadProps(__spreadValues({}, context), {
19646
+ cloneRowSelection: (rowSelection) => {
19647
+ return cloneRowSelection(rowSelection, context.getDataSourceState);
19648
+ }
19649
+ });
19650
+ if (handleKeyboardSelection(keyboardHandlerContext, event)) {
19651
+ event.preventDefault();
19535
19652
  }
19536
- });
19537
- if (handleKeyboardSelection(keyboardHandlerContext, event)) {
19538
- event.preventDefault();
19539
- }
19540
- if (handleBrowserFocusChangeOnKeyboardNavigation(keyboardHandlerContext, event)) {
19541
- event.preventDefault();
19542
- } else {
19543
- if (!context.getState().focusedWithin && handleKeyboardNavigation(keyboardHandlerContext, event)) {
19653
+ if (handleBrowserFocusChangeOnKeyboardNavigation(keyboardHandlerContext, event)) {
19544
19654
  event.preventDefault();
19655
+ } else {
19656
+ if (!context.getState().focusedWithin && handleKeyboardNavigation(keyboardHandlerContext, event)) {
19657
+ event.preventDefault();
19658
+ }
19545
19659
  }
19546
- }
19547
- if (event.key === "Enter") {
19548
- const { activeCellIndex } = context.getState();
19549
- if (activeCellIndex) {
19550
- const [rowIndex, colIndex] = activeCellIndex;
19551
- const column = context.getComputed().computedVisibleColumns[colIndex];
19552
- if (column.computedEditable) {
19553
- context.api.startEdit({
19554
- rowIndex,
19555
- columnId: column.id
19556
- });
19660
+ if (event.key === "Enter" && !context.api.isEditInProgress()) {
19661
+ const { activeCellIndex } = context.getState();
19662
+ if (activeCellIndex) {
19663
+ const [rowIndex, colIndex] = activeCellIndex;
19664
+ const column = context.getComputed().computedVisibleColumns[colIndex];
19665
+ if (column.computedEditable) {
19666
+ context.api.startEdit({
19667
+ rowIndex,
19668
+ columnId: column.id
19669
+ });
19670
+ }
19557
19671
  }
19558
19672
  }
19559
- }
19560
- if (context.api.isEditInProgress()) {
19561
- if (event.key === "Escape") {
19562
- context.api.stopEdit({ cancel: true });
19673
+ if (context.api.isEditInProgress()) {
19674
+ if (event.key === "Escape") {
19675
+ context.api.stopEdit({ cancel: true });
19676
+ }
19677
+ if (event.key === "Tab") {
19678
+ event.preventDefault();
19679
+ }
19563
19680
  }
19564
- if (event.key === "Tab") {
19565
- event.preventDefault();
19681
+ (_b = (_a = context.getState()).onKeyDown) == null ? void 0 : _b.call(_a, context, event);
19682
+ const { keyboardShortcuts: keyboardShortcuts2 } = context.getState();
19683
+ if (keyboardShortcuts2) {
19684
+ try {
19685
+ for (var iter = __forAwait(keyboardShortcuts2), more, temp, error2; more = !(temp = yield iter.next()).done; more = false) {
19686
+ const shortcut = temp.value;
19687
+ if (!eventMatchesKeyboardShortcut(event, shortcut.key)) {
19688
+ continue;
19689
+ }
19690
+ if (shortcut.when) {
19691
+ const result = yield shortcut.when(context);
19692
+ if (!result) {
19693
+ continue;
19694
+ }
19695
+ }
19696
+ const maybeStopNext = yield shortcut.handler(context, event);
19697
+ if (maybeStopNext && maybeStopNext.stopNext) {
19698
+ break;
19699
+ }
19700
+ }
19701
+ } catch (temp) {
19702
+ error2 = [temp];
19703
+ } finally {
19704
+ try {
19705
+ more && (temp = iter.return) && (yield temp.call(iter));
19706
+ } finally {
19707
+ if (error2)
19708
+ throw error2[0];
19709
+ }
19710
+ }
19566
19711
  }
19567
- }
19568
- (_b = (_a = context.getState()).onKeyDown) == null ? void 0 : _b.call(_a, context, event);
19712
+ });
19569
19713
  }
19570
19714
 
19571
19715
  // src/components/InfiniteTable/eventHandlers/index.ts
@@ -22508,6 +22652,50 @@ var InfiniteTable = function(props) {
22508
22652
  return table;
22509
22653
  };
22510
22654
 
22655
+ // src/components/InfiniteTable/eventHandlers/keyboardShortcuts.ts
22656
+ var instantEdit = {
22657
+ key: "*",
22658
+ when: (context) => {
22659
+ const { activeCellIndex } = context.getState();
22660
+ if (activeCellIndex) {
22661
+ const [rowIndex, colIndex] = activeCellIndex;
22662
+ const column = context.api.getColumnAtIndex(colIndex);
22663
+ if (!column) {
22664
+ return false;
22665
+ }
22666
+ return context.api.isCellEditable({
22667
+ rowIndex,
22668
+ columnId: column.id
22669
+ });
22670
+ }
22671
+ return false;
22672
+ },
22673
+ handler: (context, event) => {
22674
+ const { key } = event;
22675
+ if (key != "Escape" && key.length === 1) {
22676
+ const { activeCellIndex } = context.getState();
22677
+ if (activeCellIndex) {
22678
+ const [rowIndex, colIndex] = activeCellIndex;
22679
+ const column = context.api.getColumnAtIndex(colIndex);
22680
+ if (!column) {
22681
+ return;
22682
+ }
22683
+ requestAnimationFrame(() => {
22684
+ context.api.startEdit({
22685
+ rowIndex,
22686
+ // value: '',
22687
+ value: key,
22688
+ columnId: column.id
22689
+ });
22690
+ });
22691
+ }
22692
+ }
22693
+ }
22694
+ };
22695
+ var keyboardShortcuts = {
22696
+ instantEdit
22697
+ };
22698
+
22511
22699
  // src/utils/FixedSizeSet.ts
22512
22700
  var _FixedSizeSet = class {
22513
22701
  constructor(clone, size) {
@@ -22654,11 +22842,13 @@ export {
22654
22842
  debounce,
22655
22843
  debug,
22656
22844
  defaultFilterTypes2 as defaultFilterTypes,
22845
+ eventMatchesKeyboardShortcut,
22657
22846
  defaultFilterTypes2 as filterTypes,
22658
22847
  flatten,
22659
22848
  getComponentStateRoot,
22660
22849
  group,
22661
22850
  interceptMap,
22851
+ keyboardShortcuts,
22662
22852
  multisort,
22663
22853
  useComponentState,
22664
22854
  useDataSource,