@infinite-table/infinite-react 3.3.1 → 3.3.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.
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.2"
18758
18777
  });
18759
18778
  if (!licenseKey && !valid2 && isInsidePlayground) {
18760
18779
  return true;
@@ -19526,46 +19545,141 @@ 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 KeyAliases = {
19553
+ esc: "escape"
19554
+ };
19555
+ var keyModifierChecker = {
19556
+ cmd: (event) => event.metaKey,
19557
+ alt: (event) => event.altKey,
19558
+ ctrl: (event) => event.ctrlKey,
19559
+ shift: (event) => event.shiftKey
19560
+ };
19561
+ var keyModifierNames = Object.keys(keyModifierChecker);
19562
+ var keyModifierSet = new Set(keyModifierNames);
19563
+ function eventMatchesKeyboardShortcut(event, keyDescriptors) {
19564
+ if (!Array.isArray(keyDescriptors)) {
19565
+ return eventMatchesSingleShortcut(event, keyDescriptors);
19566
+ }
19567
+ return keyDescriptors.some(
19568
+ (keyDescriptor) => eventMatchesSingleShortcut(event, keyDescriptor)
19569
+ );
19570
+ }
19571
+ function eventMatchesSingleShortcut(event, keyDescriptor) {
19572
+ const keyLowercase = event.key.toLowerCase();
19573
+ const parts = keyDescriptor.split("+").map((part) => part.toLowerCase().trim()).map((part) => KeyModifierAliases[part] || KeyAliases[part] || part);
19574
+ const expectedModifiers = parts.filter(
19575
+ (part) => keyModifierSet.has(part)
19576
+ );
19577
+ const nonModifierParts = parts.filter(
19578
+ (part) => !keyModifierSet.has(part)
19579
+ );
19580
+ const currentModifierMatches = keyModifierNames.reduce((acc, modifier) => {
19581
+ acc[modifier] = keyModifierChecker[modifier](event);
19582
+ return acc;
19583
+ }, {});
19584
+ const currentModifierMatchesList = Object.keys(currentModifierMatches).filter(
19585
+ (key) => currentModifierMatches[key]
19586
+ );
19587
+ const hasAllModifiers = expectedModifiers.every(
19588
+ (modifier) => currentModifierMatches[modifier] === true
19589
+ );
19590
+ if (!hasAllModifiers) {
19591
+ return false;
19592
+ }
19593
+ if (expectedModifiers.length != currentModifierMatchesList.length) {
19594
+ return false;
19595
+ }
19596
+ if (!nonModifierParts.length) {
19597
+ return false;
19598
+ }
19599
+ if (keyModifierSet.has(keyLowercase)) {
19600
+ return false;
19601
+ }
19602
+ return nonModifierParts.reduce((acc, part) => {
19603
+ if (!acc) {
19604
+ return false;
19605
+ }
19606
+ const res = part === "*" || keyLowercase === part;
19607
+ return res;
19608
+ }, true);
19609
+ }
19610
+
19529
19611
  // src/components/InfiniteTable/eventHandlers/onKeyDown.ts
19530
19612
  function onKeyDown(context, event) {
19531
- var _a, _b;
19532
- const keyboardHandlerContext = __spreadProps(__spreadValues({}, context), {
19533
- cloneRowSelection: (rowSelection) => {
19534
- return cloneRowSelection(rowSelection, context.getDataSourceState);
19613
+ return __async(this, null, function* () {
19614
+ var _a, _b;
19615
+ const keyboardHandlerContext = __spreadProps(__spreadValues({}, context), {
19616
+ cloneRowSelection: (rowSelection) => {
19617
+ return cloneRowSelection(rowSelection, context.getDataSourceState);
19618
+ }
19619
+ });
19620
+ if (handleKeyboardSelection(keyboardHandlerContext, event)) {
19621
+ event.preventDefault();
19535
19622
  }
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)) {
19623
+ if (handleBrowserFocusChangeOnKeyboardNavigation(keyboardHandlerContext, event)) {
19544
19624
  event.preventDefault();
19625
+ } else {
19626
+ if (!context.getState().focusedWithin && handleKeyboardNavigation(keyboardHandlerContext, event)) {
19627
+ event.preventDefault();
19628
+ }
19545
19629
  }
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
- });
19630
+ if (event.key === "Enter" && !context.api.isEditInProgress()) {
19631
+ const { activeCellIndex } = context.getState();
19632
+ if (activeCellIndex) {
19633
+ const [rowIndex, colIndex] = activeCellIndex;
19634
+ const column = context.getComputed().computedVisibleColumns[colIndex];
19635
+ if (column.computedEditable) {
19636
+ context.api.startEdit({
19637
+ rowIndex,
19638
+ columnId: column.id
19639
+ });
19640
+ }
19557
19641
  }
19558
19642
  }
19559
- }
19560
- if (context.api.isEditInProgress()) {
19561
- if (event.key === "Escape") {
19562
- context.api.stopEdit({ cancel: true });
19643
+ if (context.api.isEditInProgress()) {
19644
+ if (event.key === "Escape") {
19645
+ context.api.stopEdit({ cancel: true });
19646
+ }
19647
+ if (event.key === "Tab") {
19648
+ event.preventDefault();
19649
+ }
19563
19650
  }
19564
- if (event.key === "Tab") {
19565
- event.preventDefault();
19651
+ (_b = (_a = context.getState()).onKeyDown) == null ? void 0 : _b.call(_a, context, event);
19652
+ const { keyboardShortcuts: keyboardShortcuts2 } = context.getState();
19653
+ if (keyboardShortcuts2) {
19654
+ try {
19655
+ for (var iter = __forAwait(keyboardShortcuts2), more, temp, error2; more = !(temp = yield iter.next()).done; more = false) {
19656
+ const shortcut = temp.value;
19657
+ if (!eventMatchesKeyboardShortcut(event, shortcut.key)) {
19658
+ continue;
19659
+ }
19660
+ if (shortcut.when) {
19661
+ const result = yield shortcut.when(context);
19662
+ if (!result) {
19663
+ continue;
19664
+ }
19665
+ }
19666
+ const maybeStopNext = yield shortcut.handler(context, event);
19667
+ if (maybeStopNext && maybeStopNext.stopNext) {
19668
+ break;
19669
+ }
19670
+ }
19671
+ } catch (temp) {
19672
+ error2 = [temp];
19673
+ } finally {
19674
+ try {
19675
+ more && (temp = iter.return) && (yield temp.call(iter));
19676
+ } finally {
19677
+ if (error2)
19678
+ throw error2[0];
19679
+ }
19680
+ }
19566
19681
  }
19567
- }
19568
- (_b = (_a = context.getState()).onKeyDown) == null ? void 0 : _b.call(_a, context, event);
19682
+ });
19569
19683
  }
19570
19684
 
19571
19685
  // src/components/InfiniteTable/eventHandlers/index.ts
@@ -22508,6 +22622,50 @@ var InfiniteTable = function(props) {
22508
22622
  return table;
22509
22623
  };
22510
22624
 
22625
+ // src/components/InfiniteTable/eventHandlers/keyboardShortcuts.ts
22626
+ var instantEdit = {
22627
+ key: "*",
22628
+ when: (context) => {
22629
+ const { activeCellIndex } = context.getState();
22630
+ if (activeCellIndex) {
22631
+ const [rowIndex, colIndex] = activeCellIndex;
22632
+ const column = context.api.getColumnAtIndex(colIndex);
22633
+ if (!column) {
22634
+ return false;
22635
+ }
22636
+ return context.api.isCellEditable({
22637
+ rowIndex,
22638
+ columnId: column.id
22639
+ });
22640
+ }
22641
+ return false;
22642
+ },
22643
+ handler: (context, event) => {
22644
+ const { key } = event;
22645
+ if (key != "Escape" && key.length === 1) {
22646
+ const { activeCellIndex } = context.getState();
22647
+ if (activeCellIndex) {
22648
+ const [rowIndex, colIndex] = activeCellIndex;
22649
+ const column = context.api.getColumnAtIndex(colIndex);
22650
+ if (!column) {
22651
+ return;
22652
+ }
22653
+ requestAnimationFrame(() => {
22654
+ context.api.startEdit({
22655
+ rowIndex,
22656
+ // value: '',
22657
+ value: key,
22658
+ columnId: column.id
22659
+ });
22660
+ });
22661
+ }
22662
+ }
22663
+ }
22664
+ };
22665
+ var keyboardShortcuts = {
22666
+ instantEdit
22667
+ };
22668
+
22511
22669
  // src/utils/FixedSizeSet.ts
22512
22670
  var _FixedSizeSet = class {
22513
22671
  constructor(clone, size) {
@@ -22654,11 +22812,13 @@ export {
22654
22812
  debounce,
22655
22813
  debug,
22656
22814
  defaultFilterTypes2 as defaultFilterTypes,
22815
+ eventMatchesKeyboardShortcut,
22657
22816
  defaultFilterTypes2 as filterTypes,
22658
22817
  flatten,
22659
22818
  getComponentStateRoot,
22660
22819
  group,
22661
22820
  interceptMap,
22821
+ keyboardShortcuts,
22662
22822
  multisort,
22663
22823
  useComponentState,
22664
22824
  useDataSource,