@economic/taco 2.45.0-create.3 → 2.45.1

Sign up to get free protection for your applications and to get access to all the features.
Files changed (111) hide show
  1. package/dist/components/AlertDialog/AlertDialog.d.ts +2 -1
  2. package/dist/components/AlertDialog/components/Content.d.ts +2 -0
  3. package/dist/components/Menu/components/Content.d.ts +1 -1
  4. package/dist/components/Menu/components/SubMenu.d.ts +1 -1
  5. package/dist/components/Popover/Popover.d.ts +1 -1
  6. package/dist/components/Provider/Localization.d.ts +0 -2
  7. package/dist/components/Report/Report.d.ts +1 -1
  8. package/dist/components/Select2/components/Search.d.ts +0 -6
  9. package/dist/components/Table3/Table3.d.ts +14 -2
  10. package/dist/components/Table3/components/Columns/Internal/EditingActionsMenu.d.ts +2 -1
  11. package/dist/components/Table3/components/Row/Editing/CreateRowButton.d.ts +11 -0
  12. package/dist/components/Table3/features/useTableEditing.d.ts +36 -24
  13. package/dist/components/Table3/types.d.ts +8 -23
  14. package/dist/components/Table3/useTable3.d.ts +0 -6
  15. package/dist/components/Table3/util/editing.d.ts +1 -0
  16. package/dist/esm/index.css +2 -6
  17. package/dist/esm/node_modules/babel-plugin-transform-async-to-promises/helpers.mjs.js +17 -17
  18. package/dist/esm/node_modules/babel-plugin-transform-async-to-promises/helpers.mjs.js.map +1 -1
  19. package/dist/esm/packages/taco/src/components/AlertDialog/AlertDialog.js +2 -1
  20. package/dist/esm/packages/taco/src/components/AlertDialog/AlertDialog.js.map +1 -1
  21. package/dist/esm/packages/taco/src/components/AlertDialog/components/Content.js +7 -2
  22. package/dist/esm/packages/taco/src/components/AlertDialog/components/Content.js.map +1 -1
  23. package/dist/esm/packages/taco/src/components/Dialog/components/Content.js +1 -0
  24. package/dist/esm/packages/taco/src/components/Dialog/components/Content.js.map +1 -1
  25. package/dist/esm/packages/taco/src/components/Drawer/components/Content.js +1 -0
  26. package/dist/esm/packages/taco/src/components/Drawer/components/Content.js.map +1 -1
  27. package/dist/esm/packages/taco/src/components/ModeSwitch/ModeSwitch.js +2 -2
  28. package/dist/esm/packages/taco/src/components/ModeSwitch/ModeSwitch.js.map +1 -1
  29. package/dist/esm/packages/taco/src/components/Popover/Popover.js.map +1 -1
  30. package/dist/esm/packages/taco/src/components/Provider/Localization.js +3 -5
  31. package/dist/esm/packages/taco/src/components/Provider/Localization.js.map +1 -1
  32. package/dist/esm/packages/taco/src/components/Select2/Select2.js +20 -39
  33. package/dist/esm/packages/taco/src/components/Select2/Select2.js.map +1 -1
  34. package/dist/esm/packages/taco/src/components/Select2/components/Search.js +2 -12
  35. package/dist/esm/packages/taco/src/components/Select2/components/Search.js.map +1 -1
  36. package/dist/esm/packages/taco/src/components/Select2/components/Trigger.js +19 -1
  37. package/dist/esm/packages/taco/src/components/Select2/components/Trigger.js.map +1 -1
  38. package/dist/esm/packages/taco/src/components/Switch/Switch.js +1 -1
  39. package/dist/esm/packages/taco/src/components/Switch/Switch.js.map +1 -1
  40. package/dist/esm/packages/taco/src/components/Table3/Table3.js +7 -21
  41. package/dist/esm/packages/taco/src/components/Table3/Table3.js.map +1 -1
  42. package/dist/esm/packages/taco/src/components/Table3/components/Columns/Cell/EditingControlCell.js +18 -24
  43. package/dist/esm/packages/taco/src/components/Table3/components/Columns/Cell/EditingControlCell.js.map +1 -1
  44. package/dist/esm/packages/taco/src/components/Table3/components/Columns/Internal/EditingActionsMenu.js +36 -5
  45. package/dist/esm/packages/taco/src/components/Table3/components/Columns/Internal/EditingActionsMenu.js.map +1 -1
  46. package/dist/esm/packages/taco/src/components/Table3/components/Editing/Alert.js +12 -17
  47. package/dist/esm/packages/taco/src/components/Table3/components/Editing/Alert.js.map +1 -1
  48. package/dist/esm/packages/taco/src/components/Table3/components/Row/Editing/CreateRowButton.js +90 -0
  49. package/dist/esm/packages/taco/src/components/Table3/components/Row/Editing/CreateRowButton.js.map +1 -0
  50. package/dist/esm/packages/taco/src/components/Table3/components/Row/Editing/SaveStatus.js +14 -2
  51. package/dist/esm/packages/taco/src/components/Table3/components/Row/Editing/SaveStatus.js.map +1 -1
  52. package/dist/esm/packages/taco/src/components/Table3/components/Row/Row.js +3 -4
  53. package/dist/esm/packages/taco/src/components/Table3/components/Row/Row.js.map +1 -1
  54. package/dist/esm/packages/taco/src/components/Table3/components/Toolbar/Editing/Editing.js +2 -7
  55. package/dist/esm/packages/taco/src/components/Table3/components/Toolbar/Editing/Editing.js.map +1 -1
  56. package/dist/esm/packages/taco/src/components/Table3/features/useTableEditing.js +406 -16
  57. package/dist/esm/packages/taco/src/components/Table3/features/useTableEditing.js.map +1 -1
  58. package/dist/esm/packages/taco/src/components/Table3/listeners/useTableEditingListener.js +32 -37
  59. package/dist/esm/packages/taco/src/components/Table3/listeners/useTableEditingListener.js.map +1 -1
  60. package/dist/esm/packages/taco/src/components/Table3/useTable3.js +7 -21
  61. package/dist/esm/packages/taco/src/components/Table3/useTable3.js.map +1 -1
  62. package/dist/esm/packages/taco/src/components/Table3/util/editing.js +25 -1
  63. package/dist/esm/packages/taco/src/components/Table3/util/editing.js.map +1 -1
  64. package/dist/esm/packages/taco/src/primitives/Listbox2/components/Option.js +0 -4
  65. package/dist/esm/packages/taco/src/primitives/Listbox2/components/Option.js.map +1 -1
  66. package/dist/esm/packages/taco/src/primitives/Table/Core/Table.js +4 -3
  67. package/dist/esm/packages/taco/src/primitives/Table/Core/Table.js.map +1 -1
  68. package/dist/esm/packages/taco/src/primitives/Table/Core/components/Columns/Cell/BuiltIns/GroupedCell.js +3 -9
  69. package/dist/esm/packages/taco/src/primitives/Table/Core/components/Columns/Cell/BuiltIns/GroupedCell.js.map +1 -1
  70. package/dist/esm/packages/taco/src/primitives/Table/Core/components/Columns/Internal/Actions.js +3 -6
  71. package/dist/esm/packages/taco/src/primitives/Table/Core/components/Columns/Internal/Actions.js.map +1 -1
  72. package/dist/esm/packages/taco/src/primitives/Table/Core/components/Footer/Footer.js +1 -1
  73. package/dist/esm/packages/taco/src/primitives/Table/Core/components/Footer/Footer.js.map +1 -1
  74. package/dist/esm/packages/taco/src/primitives/Table/Core/components/Row/BuiltIns/DisplayRow.js +1 -1
  75. package/dist/esm/packages/taco/src/primitives/Table/Core/components/Row/BuiltIns/DisplayRow.js.map +1 -1
  76. package/dist/esm/packages/taco/src/primitives/Table/Core/components/Toolbar/components/Filters/components/FilterValue.js +8 -1
  77. package/dist/esm/packages/taco/src/primitives/Table/Core/components/Toolbar/components/Filters/components/FilterValue.js.map +1 -1
  78. package/dist/esm/packages/taco/src/primitives/Table/Core/features/useTableRenderer.js +1 -1
  79. package/dist/esm/packages/taco/src/primitives/Table/Core/features/useTableRenderer.js.map +1 -1
  80. package/dist/esm/packages/taco/src/primitives/Table/types.js.map +1 -1
  81. package/dist/esm/packages/taco/src/primitives/Table/useTableManager/useTableManager.js +1 -1
  82. package/dist/esm/packages/taco/src/primitives/Table/useTableManager/useTableManager.js.map +1 -1
  83. package/dist/esm/packages/taco/src/primitives/Table/useTableManager/util/setup.js +0 -11
  84. package/dist/esm/packages/taco/src/primitives/Table/useTableManager/util/setup.js.map +1 -1
  85. package/dist/esm/packages/taco/src/utils/dom.js +17 -13
  86. package/dist/esm/packages/taco/src/utils/dom.js.map +1 -1
  87. package/dist/index.css +2 -6
  88. package/dist/primitives/Table/Core/Table.d.ts +0 -1
  89. package/dist/primitives/Table/Core/components/Columns/Internal/Actions.d.ts +1 -3
  90. package/dist/primitives/Table/Core/components/Footer/Footer.d.ts +2 -2
  91. package/dist/primitives/Table/Core/features/useTableStyle.d.ts +3 -3
  92. package/dist/primitives/Table/types.d.ts +2 -2
  93. package/dist/primitives/Table/useTableManager/useTableManager.d.ts +1 -1
  94. package/dist/taco.cjs.development.js +691 -921
  95. package/dist/taco.cjs.development.js.map +1 -1
  96. package/dist/taco.cjs.production.min.js +1 -1
  97. package/dist/taco.cjs.production.min.js.map +1 -1
  98. package/dist/utils/dom.d.ts +0 -1
  99. package/package.json +17 -16
  100. package/dist/components/Table3/components/Editing/DiscardChangesConfirmationDialog.d.ts +0 -7
  101. package/dist/components/Table3/components/Row/Editing/CreateNewRow.d.ts +0 -13
  102. package/dist/components/Table3/components/Row/Editing/TemporaryRow.d.ts +0 -12
  103. package/dist/components/Table3/features/useEditingState.d.ts +0 -29
  104. package/dist/esm/packages/taco/src/components/Table3/components/Editing/DiscardChangesConfirmationDialog.js +0 -34
  105. package/dist/esm/packages/taco/src/components/Table3/components/Editing/DiscardChangesConfirmationDialog.js.map +0 -1
  106. package/dist/esm/packages/taco/src/components/Table3/components/Row/Editing/CreateNewRow.js +0 -88
  107. package/dist/esm/packages/taco/src/components/Table3/components/Row/Editing/CreateNewRow.js.map +0 -1
  108. package/dist/esm/packages/taco/src/components/Table3/components/Row/Editing/TemporaryRow.js +0 -93
  109. package/dist/esm/packages/taco/src/components/Table3/components/Row/Editing/TemporaryRow.js.map +0 -1
  110. package/dist/esm/packages/taco/src/components/Table3/features/useEditingState.js +0 -514
  111. package/dist/esm/packages/taco/src/components/Table3/features/useEditingState.js.map +0 -1
@@ -43,8 +43,7 @@ var set = _interopDefault(require('lodash/set'));
43
43
  var unset = _interopDefault(require('lodash/unset'));
44
44
  var compact = _interopDefault(require('lodash/compact'));
45
45
  var pullAt = _interopDefault(require('lodash/pullAt'));
46
- var omit = _interopDefault(require('lodash/omit'));
47
- var setWith = _interopDefault(require('lodash/setWith'));
46
+ var lodash = require('lodash');
48
47
  var TabsPrimitive = require('@radix-ui/react-tabs');
49
48
  var Joyride = require('react-joyride');
50
49
  var Joyride__default = _interopDefault(Joyride);
@@ -3945,6 +3944,11 @@ const Title = /*#__PURE__*/React.forwardRef(function AlertDialogTitle(props, ref
3945
3944
  className: "mr-2"
3946
3945
  })) : undefined, props.children);
3947
3946
  });
3947
+ const Description = /*#__PURE__*/React.forwardRef(function AlertDialogDescription(props, ref) {
3948
+ return /*#__PURE__*/React.createElement(AlertDialogPrimitive.Description, Object.assign({
3949
+ ref: ref
3950
+ }, props));
3951
+ });
3948
3952
  const Content = /*#__PURE__*/React.forwardRef(function AlertDialogContent(props, ref) {
3949
3953
  const className = cn('p-6', getDialogPositionClassnames(), getDialogStylingClassnames(), getDialogSizeClassnames('dialog'));
3950
3954
  return /*#__PURE__*/React.createElement(AlertDialogPrimitive.Portal, null, /*#__PURE__*/React.createElement(AlertDialogPrimitive.Overlay, {
@@ -3979,6 +3983,7 @@ const AlertDialog = /*#__PURE__*/React.forwardRef(function AlertDialog(props, re
3979
3983
  });
3980
3984
  AlertDialog.Trigger = Trigger;
3981
3985
  AlertDialog.Content = Content;
3986
+ AlertDialog.Description = Description;
3982
3987
  AlertDialog.Title = Title;
3983
3988
  AlertDialog.Cancel = Cancel;
3984
3989
  AlertDialog.Action = Action;
@@ -4162,7 +4167,7 @@ const useMergedRef = ref => {
4162
4167
  };
4163
4168
 
4164
4169
  // taken from react-aria
4165
- const FOCUSABLE_ELEMENTS = ['input:not([disabled]):not([type=hidden])', 'select:not([disabled])', 'textarea:not([disabled])', 'button:not([disabled])', 'a[href]', 'area[href]', 'summary', 'iframe', 'object', 'embed', 'audio[controls]', 'video[controls]', '[contenteditable]', '[tabindex]:not([tabindex="-1"]):not([disabled])', 'details:not([disabled])', 'summary:not(:disabled)'];
4170
+ const FOCUSABLE_ELEMENTS = ['[tabindex]:not([disabled]):not([tabindex="-1"])', 'input:not([disabled]):not([type=hidden]):not([tabindex="-1"])', 'select:not([disabled]):not([tabindex="-1"])', 'textarea:not([disabled]):not([tabindex="-1"])', 'button:not([disabled]):not([tabindex="-1"])', 'a[href]', 'area[href]', 'summary', 'iframe', 'object', 'embed', 'audio[controls]', 'video[controls]', '[contenteditable]', 'details:not([disabled]):not([tabindex="-1"])', 'summary:not(:disabled):not([tabindex="-1"])'];
4166
4171
  const hasFocusableElement = element => {
4167
4172
  if (!element) {
4168
4173
  return null;
@@ -4188,13 +4193,20 @@ const getNextFocussableElement = currentElement => {
4188
4193
  if (!currentElement) {
4189
4194
  return null;
4190
4195
  }
4191
- const focussableElements = [...document.querySelectorAll(FOCUSABLE_ELEMENTS.join(','))];
4196
+ let focussableElements = [...document.querySelectorAll(FOCUSABLE_ELEMENTS.join(','))];
4192
4197
  const currentElementIndex = focussableElements.indexOf(currentElement);
4193
- // If the currentElement is not in the focussable elements list or it is the last element
4194
- if (currentElementIndex !== -1 && currentElementIndex === focussableElements.length - 1) {
4195
- return null;
4198
+ if (currentElementIndex > -1) {
4199
+ focussableElements = focussableElements.slice(currentElementIndex + 1);
4200
+ if (focussableElements.length) {
4201
+ var _focussableElements$;
4202
+ focussableElements = focussableElements.filter(element => {
4203
+ var _element$checkVisibil, _element$checkVisibil2;
4204
+ return (_element$checkVisibil = (_element$checkVisibil2 = element.checkVisibility) === null || _element$checkVisibil2 === void 0 ? void 0 : _element$checkVisibil2.call(element)) !== null && _element$checkVisibil !== void 0 ? _element$checkVisibil : true;
4205
+ });
4206
+ return (_focussableElements$ = focussableElements[0]) !== null && _focussableElements$ !== void 0 ? _focussableElements$ : null;
4207
+ }
4196
4208
  }
4197
- return focussableElements[currentElementIndex + 1];
4209
+ return null;
4198
4210
  };
4199
4211
  const getOverlaySelector = element => {
4200
4212
  switch (element === null || element === void 0 ? void 0 : element.getAttribute('role')) {
@@ -4206,7 +4218,7 @@ const getOverlaySelector = element => {
4206
4218
  return undefined;
4207
4219
  }
4208
4220
  };
4209
- function isElementTriggeredFromContainer(element, container) {
4221
+ function isElementInsideOrTriggeredFromContainer(element, container) {
4210
4222
  var _getOverlaySelector, _element$closest;
4211
4223
  const selector = (_getOverlaySelector = getOverlaySelector(element)) !== null && _getOverlaySelector !== void 0 ? _getOverlaySelector : getOverlaySelector((_element$closest = element === null || element === void 0 ? void 0 : element.closest('[role=dialog],[role=menu]')) !== null && _element$closest !== void 0 ? _element$closest : null);
4212
4224
  if (selector) {
@@ -4216,14 +4228,11 @@ function isElementTriggeredFromContainer(element, container) {
4216
4228
  const elementInDocument = document.querySelector(selector);
4217
4229
  // if the element does exist, see if it is itself connected to somethng that was triggered from the container
4218
4230
  if (elementInDocument) {
4219
- return isElementTriggeredFromContainer(elementInDocument, container);
4231
+ return isElementInsideOrTriggeredFromContainer(elementInDocument, container);
4220
4232
  }
4221
4233
  return false;
4222
4234
  }
4223
- return false;
4224
- }
4225
- function isElementInsideOrTriggeredFromContainer(element, container) {
4226
- return isElementTriggeredFromContainer(element, container) || !!(container !== null && container !== void 0 && container.contains(element));
4235
+ return !!(container !== null && container !== void 0 && container.contains(element));
4227
4236
  }
4228
4237
  function isElementInsideOverlay(element) {
4229
4238
  return !!(element !== null && element !== void 0 && element.closest('[role=dialog],[role=menu]'));
@@ -4717,9 +4726,7 @@ const defaultLocalisationTexts = {
4717
4726
  tooltip: 'Edit table'
4718
4727
  },
4719
4728
  create: {
4720
- label: 'New',
4721
- disabled: 'Existing new row must be saved',
4722
- saving: 'Saving...'
4729
+ label: 'New'
4723
4730
  }
4724
4731
  },
4725
4732
  clearChangesConfirmationDialog: {
@@ -4741,8 +4748,8 @@ const defaultLocalisationTexts = {
4741
4748
  },
4742
4749
  validation: {
4743
4750
  alert: {
4744
- titleOne: '[COUNT] unsaved row:',
4745
- titlePlural: '[COUNT] unsaved rows:',
4751
+ titleOne: '[COUNT] unsaved entry:',
4752
+ titlePlural: '[COUNT] unsaved entries:',
4746
4753
  messageOne: "[COLUMN] [ROW] is incomplete and hasn't been saved.",
4747
4754
  messagePlural: "[COLUMN] [ROW] are incomplete and haven't been saved.",
4748
4755
  messageRow: 'Row',
@@ -6684,6 +6691,7 @@ const Content$4 = /*#__PURE__*/React.forwardRef(function DialogContent(props, re
6684
6691
  return /*#__PURE__*/React.createElement(DialogPrimitive.Portal, null, /*#__PURE__*/React.createElement(DialogPrimitive.Overlay, {
6685
6692
  asChild: true
6686
6693
  }, /*#__PURE__*/React.createElement(Backdrop, null, /*#__PURE__*/React.createElement(DialogPrimitive.Content, Object.assign({}, props, {
6694
+ "aria-describedby": undefined,
6687
6695
  className: className,
6688
6696
  onEscapeKeyDown: handleEscapeKeyDown,
6689
6697
  onInteractOutside: handleInteractOutside,
@@ -7211,6 +7219,7 @@ const DrawerContent = /*#__PURE__*/React__default.forwardRef(function Content(pr
7211
7219
  return focusTrap ? (/*#__PURE__*/React__default.createElement(DialogPrimitive.Content, Object.assign({
7212
7220
  forceMount: true
7213
7221
  }, otherProps, {
7222
+ "aria-describedby": undefined,
7214
7223
  className: contentClassName,
7215
7224
  onEscapeKeyDown: handleEscapeKeyDown,
7216
7225
  onInteractOutside: variant === 'overlay' ? undefined : event => event.preventDefault(),
@@ -7638,7 +7647,7 @@ const Switch = /*#__PURE__*/React.forwardRef(function Switch(props, ref) {
7638
7647
  onCheckedChange: onChange,
7639
7648
  ref: ref
7640
7649
  }), /*#__PURE__*/React.createElement(PrimitiveSwitch.Thumb, {
7641
- className: "pointer-events-none mt-0.5 h-4 w-4 translate-x-[0.15rem] rounded-full bg-white transition-transform will-change-transform group-disabled:opacity-50 group-aria-checked:translate-x-[1.1rem]"
7650
+ className: "'will-change-transform mt-0.5 h-4 w-4 translate-x-[0.15rem] rounded-full bg-white transition-transform group-disabled:opacity-50 group-aria-checked:translate-x-[1.1rem]"
7642
7651
  }));
7643
7652
  if (label) {
7644
7653
  const labelContainerClassName = cn('flex self-start cursor-pointer', {
@@ -8698,10 +8707,10 @@ const ModeSwitch = /*#__PURE__*/React.forwardRef(function ModeSwitch(props, ref)
8698
8707
  onCheckedChange: onChange,
8699
8708
  ref: ref
8700
8709
  }), /*#__PURE__*/React.createElement(PrimitiveSwitch.Thumb, {
8701
- className: "pointer-events-none flex h-6 w-6 items-center justify-center rounded-full bg-white transition-transform will-change-transform group-disabled:opacity-50 group-aria-checked:translate-x-[100%]"
8710
+ className: "'will-change-transform flex h-6 w-6 items-center justify-center rounded-full bg-white transition-transform group-disabled:opacity-50 group-aria-checked:translate-x-[100%]"
8702
8711
  }, /*#__PURE__*/React.createElement(Icon, {
8703
8712
  name: "edit-simple",
8704
- className: "pointer-events-none !h-5 !w-5"
8713
+ className: "!h-5 !w-5"
8705
8714
  })));
8706
8715
  });
8707
8716
  ModeSwitch.displayName = 'ModeSwitch';
@@ -10404,15 +10413,6 @@ function configureReactTableOptions(options, props, localization) {
10404
10413
  // We don't want to expose internal Tanstack Table row, so we need to wrap enableRowSelection callback into additional function,
10405
10414
  // which receives the React Table Row object and passes row.original to a callback.
10406
10415
  const reactTableEnableRowSelection = typeof options.enableRowSelection === 'function' ? row => options.enableRowSelection(row.original) : options.enableRowSelection;
10407
- let getRowId;
10408
- if (props.rowIdentityAccessor) {
10409
- getRowId = (originalRow, index) => {
10410
- if (originalRow) {
10411
- return originalRow[props.rowIdentityAccessor];
10412
- }
10413
- return String(index);
10414
- };
10415
- }
10416
10416
  const tableOptions = {
10417
10417
  defaultColumn: {
10418
10418
  enableColumnFilter: options.enableFiltering || true,
@@ -10431,13 +10431,11 @@ function configureReactTableOptions(options, props, localization) {
10431
10431
  enableGrouping: true,
10432
10432
  enableHiding: (_options$enableColumn2 = options.enableColumnHiding) !== null && _options$enableColumn2 !== void 0 ? _options$enableColumn2 : false,
10433
10433
  enablePinning: (_options$enableColumn3 = options.enableColumnFreezing) !== null && _options$enableColumn3 !== void 0 ? _options$enableColumn3 : false,
10434
- enableRowPinning: true,
10435
10434
  enableRowSelection: reactTableEnableRowSelection !== null && reactTableEnableRowSelection !== void 0 ? reactTableEnableRowSelection : false,
10436
10435
  enableSorting: (_options$enableSortin = options.enableSorting) !== null && _options$enableSortin !== void 0 ? _options$enableSortin : false,
10437
10436
  // models for default features
10438
10437
  getExpandedRowModel: reactTable.getExpandedRowModel(),
10439
10438
  getGroupedRowModel: reactTable.getGroupedRowModel(),
10440
- getRowId,
10441
10439
  groupedColumnMode: false
10442
10440
  };
10443
10441
  if (tableOptions.enableColumnResizing) {
@@ -10981,13 +10979,13 @@ function useTableSearch(isEnabled = false, defaultEnableGlobalFilter = false) {
10981
10979
  }
10982
10980
 
10983
10981
  // A type of promise-like that resolves synchronously and supports only one observer
10984
- var _Pact = /*#__PURE__*/function () {
10982
+ const _Pact = /*#__PURE__*/function () {
10985
10983
  function _Pact() {}
10986
10984
  _Pact.prototype.then = function (onFulfilled, onRejected) {
10987
- var result = new _Pact();
10988
- var state = this.s;
10985
+ const result = new _Pact();
10986
+ const state = this.s;
10989
10987
  if (state) {
10990
- var callback = state & 1 ? onFulfilled : onRejected;
10988
+ const callback = state & 1 ? onFulfilled : onRejected;
10991
10989
  if (callback) {
10992
10990
  try {
10993
10991
  _settle(result, 1, callback(this.v));
@@ -11001,7 +10999,7 @@ var _Pact = /*#__PURE__*/function () {
11001
10999
  }
11002
11000
  this.o = function (_this) {
11003
11001
  try {
11004
- var value = _this.v;
11002
+ const value = _this.v;
11005
11003
  if (_this.s & 1) {
11006
11004
  _settle(result, 1, onFulfilled ? onFulfilled(value) : value);
11007
11005
  } else if (onRejected) {
@@ -11038,7 +11036,7 @@ function _settle(pact, state, value) {
11038
11036
  }
11039
11037
  pact.s = state;
11040
11038
  pact.v = value;
11041
- var observer = pact.o;
11039
+ const observer = pact.o;
11042
11040
  if (observer) {
11043
11041
  observer(pact);
11044
11042
  }
@@ -11078,13 +11076,17 @@ function _forTo(array, body, check) {
11078
11076
  _cycle();
11079
11077
  return pact;
11080
11078
  }
11081
- var _iteratorSymbol = /*#__PURE__*/typeof Symbol !== "undefined" ? Symbol.iterator || (Symbol.iterator = /*#__PURE__*/Symbol("Symbol.iterator")) : "@@iterator";
11079
+ const _iteratorSymbol = /*#__PURE__*/typeof Symbol !== "undefined" ? Symbol.iterator || (Symbol.iterator = /*#__PURE__*/Symbol("Symbol.iterator")) : "@@iterator";
11082
11080
 
11083
11081
  // Asynchronously iterate through an object's values
11084
11082
  // Uses for...of if the runtime supports it, otherwise iterates until length on a copy
11085
11083
  function _forOf(target, body, check) {
11086
11084
  if (typeof target[_iteratorSymbol] === "function") {
11087
- var _cycle = function _cycle(result) {
11085
+ var iterator = target[_iteratorSymbol](),
11086
+ step,
11087
+ pact,
11088
+ reject;
11089
+ function _cycle(result) {
11088
11090
  try {
11089
11091
  while (!(step = iterator.next()).done && (!check || !check())) {
11090
11092
  result = body(step.value);
@@ -11105,17 +11107,13 @@ function _forOf(target, body, check) {
11105
11107
  } catch (e) {
11106
11108
  _settle(pact || (pact = new _Pact()), 2, e);
11107
11109
  }
11108
- };
11109
- var iterator = target[_iteratorSymbol](),
11110
- step,
11111
- pact,
11112
- reject;
11110
+ }
11113
11111
  _cycle();
11114
- if (iterator["return"]) {
11115
- var _fixup = function _fixup(value) {
11112
+ if (iterator.return) {
11113
+ var _fixup = function (value) {
11116
11114
  try {
11117
11115
  if (!step.done) {
11118
- iterator["return"]();
11116
+ iterator.return();
11119
11117
  }
11120
11118
  } catch (e) {}
11121
11119
  return value;
@@ -11142,7 +11140,7 @@ function _forOf(target, body, check) {
11142
11140
  return body(values[i]);
11143
11141
  }, check);
11144
11142
  }
11145
- var _asyncIteratorSymbol = /*#__PURE__*/typeof Symbol !== "undefined" ? Symbol.asyncIterator || (Symbol.asyncIterator = /*#__PURE__*/Symbol("Symbol.asyncIterator")) : "@@asyncIterator";
11143
+ const _asyncIteratorSymbol = /*#__PURE__*/typeof Symbol !== "undefined" ? Symbol.asyncIterator || (Symbol.asyncIterator = /*#__PURE__*/Symbol("Symbol.asyncIterator")) : "@@asyncIterator";
11146
11144
 
11147
11145
  // Asynchronously call a function and send errors to recovery continuation
11148
11146
  function _catch(body, recover) {
@@ -11770,7 +11768,7 @@ function useTableManager(props, meta, internalColumns) {
11770
11768
  rowDrag,
11771
11769
  rowDrop: rowDrop,
11772
11770
  rowExpansion: rowExpansion,
11773
- rowIdentityAccessor: props.rowIdentityAccessor,
11771
+ rowIdentityColumnId: props.rowIdentityColumnId,
11774
11772
  rowGoto,
11775
11773
  rowGroups: rowGroups,
11776
11774
  rowHeight,
@@ -12138,7 +12136,7 @@ function Row(props) {
12138
12136
  function useTableRenderer(renderers, table, tableRef, defaultRowActiveIndex) {
12139
12137
  var _table$getState$group, _virtualItems$padding, _virtualItems$padding2, _virtualItems$padding3, _ref, _virtualItems;
12140
12138
  const tableMeta = table.options.meta;
12141
- const rows = table.getCenterRows();
12139
+ const rows = table.getRowModel().rows;
12142
12140
  const isTableRowGrouped = !!((_table$getState$group = table.getState().grouping) !== null && _table$getState$group !== void 0 && _table$getState$group.length);
12143
12141
  // expanded rows
12144
12142
  const {
@@ -12317,14 +12315,12 @@ function Actions$1(props) {
12317
12315
  actionsLength,
12318
12316
  data,
12319
12317
  isActiveRow,
12320
- rowId,
12321
- table
12318
+ rowId
12322
12319
  } = props;
12323
12320
  const {
12324
12321
  texts
12325
12322
  } = useLocalization();
12326
- // we don't want to document passing table, so it isn't on the type
12327
- const visibleActions = actions.map(action => action(data, rowId, table)).filter(action => !!action);
12323
+ const visibleActions = actions.map(action => action(data, rowId)).filter(action => !!action);
12328
12324
  const actionsOnRow = visibleActions.length === actionsLength ? visibleActions : visibleActions.slice(0, actionsLength - 1);
12329
12325
  const actionsInMenu = visibleActions.slice(visibleActions.length === actionsLength ? actionsLength : actionsLength - 1);
12330
12326
  const className = cn('flex justify-end text-right bg-[inherit] shadow-[-6px_0px_6px_var(--table-row-actions-shadow)] print:hidden');
@@ -12380,8 +12376,7 @@ const Cell = /*#__PURE__*/React__default.memo(function MemoedCell(context) {
12380
12376
  actionsLength: actionsLength,
12381
12377
  data: row.original,
12382
12378
  isActiveRow: isActiveRow,
12383
- rowId: row.id,
12384
- table: table
12379
+ rowId: row.id
12385
12380
  });
12386
12381
  }
12387
12382
  return null;
@@ -12738,10 +12733,7 @@ function GroupedCell(props) {
12738
12733
  index,
12739
12734
  isHighlighted
12740
12735
  } = props;
12741
- const {
12742
- table
12743
- } = cell.getContext();
12744
- const tableMeta = table.options.meta;
12736
+ const tableMeta = cell.getContext().table.options.meta;
12745
12737
  const columnMeta = cell.column.columnDef.meta;
12746
12738
  const attributes = getCellAttributes(cell, index, isHighlighted);
12747
12739
  const {
@@ -12759,8 +12751,7 @@ function GroupedCell(props) {
12759
12751
  colSpan: colSpan,
12760
12752
  rowActions: tableMeta.rowGroups.rowActionsForGroup,
12761
12753
  rowId: cell.row.id,
12762
- subRows: subRows,
12763
- table: table
12754
+ subRows: subRows
12764
12755
  }), content);
12765
12756
  }
12766
12757
  const MemoedGroupedCell = /*#__PURE__*/React__default.memo(function MemoedGroupedCell(props) {
@@ -12772,7 +12763,6 @@ const MemoedGroupedCell = /*#__PURE__*/React__default.memo(function MemoedGroupe
12772
12763
  rowActions,
12773
12764
  rowId,
12774
12765
  subRows,
12775
- table,
12776
12766
  ...attributes
12777
12767
  } = props;
12778
12768
  return /*#__PURE__*/React__default.createElement("td", Object.assign({}, attributes, {
@@ -12787,8 +12777,7 @@ const MemoedGroupedCell = /*#__PURE__*/React__default.memo(function MemoedGroupe
12787
12777
  actionsLength: 4,
12788
12778
  data: subRows,
12789
12779
  isActiveRow: true,
12790
- rowId: rowId,
12791
- table: table
12780
+ rowId: rowId
12792
12781
  })) : null);
12793
12782
  });
12794
12783
 
@@ -12928,7 +12917,7 @@ const DisplayRow = /*#__PURE__*/React__default.memo(function DisplayRow(props) {
12928
12917
  const expansionRef = React__default.useRef(null);
12929
12918
  const isExpanded = !!attributes['data-row-expanded'];
12930
12919
  useSetVirtualisedRowHeight(measureRow, ref.current, expansionRef.current, isExpanded);
12931
- const className = cn('group/row', otherAttributes.className, {
12920
+ const className = cn('group/row', {
12932
12921
  'hover:cursor-grab': tableMeta.rowDrag.isEnabled && typeof attributes.onClick !== 'function',
12933
12922
  'hover:cursor-pointer': typeof attributes.onClick === 'function'
12934
12923
  });
@@ -13722,7 +13711,7 @@ function Summary(props) {
13722
13711
 
13723
13712
  function Foot(props) {
13724
13713
  const nonGroupedHeaders = props.table.getFooterGroups()[0].headers.filter(header => !header.column.getIsGrouped());
13725
- return /*#__PURE__*/React__default.createElement("tfoot", null, props.children, /*#__PURE__*/React__default.createElement("tr", null, nonGroupedHeaders.map((header, index) => (/*#__PURE__*/React__default.createElement(Footer$3, {
13714
+ return /*#__PURE__*/React__default.createElement("tfoot", null, /*#__PURE__*/React__default.createElement("tr", null, nonGroupedHeaders.map((header, index) => (/*#__PURE__*/React__default.createElement(Footer$3, {
13726
13715
  key: header.id,
13727
13716
  header: header,
13728
13717
  index: index
@@ -14672,10 +14661,6 @@ const Option = /*#__PURE__*/React__default.forwardRef(function Listbox2Option(pr
14672
14661
  if (disabled || listboxDisabled || listboxReadOnly) {
14673
14662
  event.stopPropagation();
14674
14663
  return;
14675
- }
14676
- // UX requirement: if tab key is pressed and the current option is selected then keydown event is ignored
14677
- else if (event.key === 'Tab' && selected) {
14678
- return;
14679
14664
  } else if (isAriaSelectionKey(event)) {
14680
14665
  setValue(value);
14681
14666
  }
@@ -15130,7 +15115,9 @@ const Button$3 = /*#__PURE__*/React__default.forwardRef(function Select2TriggerB
15130
15115
  var _props$className;
15131
15116
  const {
15132
15117
  children,
15118
+ onBlur,
15133
15119
  onClick,
15120
+ onFocus,
15134
15121
  tabIndex = 0,
15135
15122
  ...otherProps
15136
15123
  } = props;
@@ -15161,6 +15148,18 @@ const Button$3 = /*#__PURE__*/React__default.forwardRef(function Select2TriggerB
15161
15148
  onClick(event);
15162
15149
  }
15163
15150
  };
15151
+ let handleBlur;
15152
+ if (typeof onBlur === 'function') {
15153
+ // we might be focusing on an input or something inside the dropdown that was triggered by the select
15154
+ // so see if the element gaining focus is inside a portal and look up its controller
15155
+ // if we don't do this, things like validate on blur occur while simply opening the select
15156
+ handleBlur = event => {
15157
+ if (isElementInsideOrTriggeredFromContainer(event.relatedTarget, event.currentTarget)) {
15158
+ return;
15159
+ }
15160
+ onBlur(event);
15161
+ };
15162
+ }
15164
15163
  // select the value text if the select is readonly
15165
15164
  const handleFocus = event => {
15166
15165
  if (readOnly) {
@@ -15170,6 +15169,9 @@ const Button$3 = /*#__PURE__*/React__default.forwardRef(function Select2TriggerB
15170
15169
  (_window$getSelection = window.getSelection()) === null || _window$getSelection === void 0 ? void 0 : (_window$getSelection$ = _window$getSelection.selectAllChildren) === null || _window$getSelection$ === void 0 ? void 0 : _window$getSelection$.call(_window$getSelection, value);
15171
15170
  }
15172
15171
  }
15172
+ if (typeof onFocus === 'function') {
15173
+ onFocus(event);
15174
+ }
15173
15175
  };
15174
15176
  return /*#__PURE__*/React__default.createElement("button", Object.assign({}, otherProps, {
15175
15177
  "aria-invalid": invalid ? true : undefined,
@@ -15177,6 +15179,7 @@ const Button$3 = /*#__PURE__*/React__default.forwardRef(function Select2TriggerB
15177
15179
  className: className,
15178
15180
  disabled: disabled,
15179
15181
  onClick: handleClick,
15182
+ onBlur: handleBlur,
15180
15183
  onFocus: handleFocus,
15181
15184
  ref: ref,
15182
15185
  role: "combobox",
@@ -15439,17 +15442,12 @@ const BubbleSelect = props => {
15439
15442
  };
15440
15443
 
15441
15444
  const Search$2 = /*#__PURE__*/React__default.forwardRef(function ListboxSearch(props, ref) {
15442
- const {
15443
- onTabKeyPress,
15444
- ...otherProps
15445
- } = props;
15446
15445
  const {
15447
15446
  listboxRef,
15448
15447
  searchQuery,
15449
15448
  setSearchQuery,
15450
15449
  setValidationError,
15451
- validationError,
15452
- setOpen
15450
+ validationError
15453
15451
  } = useSelect2Context();
15454
15452
  const handleChange = event => {
15455
15453
  if (validationError) {
@@ -15462,11 +15460,6 @@ const Search$2 = /*#__PURE__*/React__default.forwardRef(function ListboxSearch(p
15462
15460
  if (event.key === ' ') {
15463
15461
  return;
15464
15462
  }
15465
- // Select2 should close dropdown and receive focus, when user press Tab while searching (UX requirement to support better keyboard navigation)
15466
- if (event.key === 'Tab') {
15467
- setOpen(false);
15468
- onTabKeyPress();
15469
- }
15470
15463
  if (isAriaSelectionKey(event) || event.key === 'ArrowDown' || event.key === 'ArrowUp') {
15471
15464
  var _listboxRef$current;
15472
15465
  event.preventDefault();
@@ -15481,7 +15474,7 @@ const Search$2 = /*#__PURE__*/React__default.forwardRef(function ListboxSearch(p
15481
15474
  }),
15482
15475
  invalid: !!validationError,
15483
15476
  message: validationError === null || validationError === void 0 ? void 0 : validationError.message
15484
- }, /*#__PURE__*/React__default.createElement(Input, Object.assign({}, otherProps, {
15477
+ }, /*#__PURE__*/React__default.createElement(Input, Object.assign({}, props, {
15485
15478
  autoFocus: true,
15486
15479
  invalid: !!validationError,
15487
15480
  onChange: handleChange,
@@ -15704,7 +15697,6 @@ const Select2 = /*#__PURE__*/React__default.forwardRef(function Select2(props, r
15704
15697
  // align the listbox min width with the width of the input - it should never be smaller
15705
15698
  const dimensions = useBoundingClientRectListener(internalRef);
15706
15699
  // state
15707
- const [tabTriggeredClose, setTabTriggeredClose] = React__default.useState(false);
15708
15700
  const [open, setOpen] = React__default.useState(false);
15709
15701
  const [value, _setValue] = reactUseControllableState.useControllableState({
15710
15702
  // uncontrolled
@@ -15792,46 +15784,32 @@ const Select2 = /*#__PURE__*/React__default.forwardRef(function Select2(props, r
15792
15784
  // the focus should always remain on the input, so we forward events on to the listbox
15793
15785
  (_listboxRef$current = listboxRef.current) === null || _listboxRef$current === void 0 ? void 0 : _listboxRef$current.dispatchEvent(createCustomKeyboardEvent(event));
15794
15786
  };
15795
- let handleBlur;
15796
- if (otherProps.onBlur) {
15797
- // we might be focusing on an input or something inside the dropdown that was triggered by the select
15798
- // so see if the element gaining focus is inside a portal and look up its controller
15799
- // if we don't do this, things like validate on blur occur while simply opening the select
15800
- handleBlur = event => {
15801
- var _elementGainingFocus$;
15802
- const elementGainingFocus = event.relatedTarget;
15803
- if (elementGainingFocus === undefined) {
15804
- return;
15805
- }
15806
- const portalId = elementGainingFocus === null || elementGainingFocus === void 0 ? void 0 : (_elementGainingFocus$ = elementGainingFocus.closest('[data-radix-popper-content-wrapper] > :first-child')) === null || _elementGainingFocus$ === void 0 ? void 0 : _elementGainingFocus$.id;
15807
- if (!portalId || event.currentTarget.getAttribute(`aria-controls`) !== portalId) {
15808
- var _otherProps$onBlur;
15809
- (_otherProps$onBlur = otherProps.onBlur) === null || _otherProps$onBlur === void 0 ? void 0 : _otherProps$onBlur.call(otherProps, event);
15810
- }
15811
- };
15812
- }
15787
+ const shouldFocusNextRef = React__default.useRef(false);
15813
15788
  const handleListboxKeyDown = event => {
15814
15789
  if (isAriaDirectionKey(event)) {
15815
15790
  setShouldPauseHoverState(true);
15791
+ return;
15816
15792
  }
15793
+ if (event.key === 'Tab') {
15794
+ shouldFocusNextRef.current = true;
15795
+ setOpen(false);
15796
+ return;
15797
+ }
15798
+ // support typeahead to set the value by typing its text
15817
15799
  if (!hasSearch && /^[a-z0-9]$/i.test(event.key)) {
15818
15800
  setValueIfMatched(event.key);
15801
+ return;
15819
15802
  }
15820
15803
  };
15804
+ // popover closes and unmounts before any event can be used to focus next, so prevent focusing the trigger and focus next
15821
15805
  const handleCloseAutoFocus = event => {
15822
- event.preventDefault();
15823
- event.stopPropagation();
15824
- if (tabTriggeredClose) {
15825
- const nextFocussableElement = getNextFocussableElement(internalRef.current);
15826
- if (nextFocussableElement) {
15827
- // UX requirement: move focus to the next focussable element when tab key is pressed to select the value
15828
- nextFocussableElement.focus();
15829
- // Reset the tabTriggeredClose state
15830
- setTabTriggeredClose(false);
15831
- }
15832
- } else {
15833
- var _internalRef$current;
15834
- (_internalRef$current = internalRef.current) === null || _internalRef$current === void 0 ? void 0 : _internalRef$current.focus();
15806
+ if (shouldFocusNextRef.current) {
15807
+ var _otherProps$onBlur, _getNextFocussableEle;
15808
+ event.preventDefault();
15809
+ shouldFocusNextRef.current = false;
15810
+ (_otherProps$onBlur = otherProps.onBlur) === null || _otherProps$onBlur === void 0 ? void 0 : _otherProps$onBlur.call(otherProps, event);
15811
+ (_getNextFocussableEle = getNextFocussableElement(internalRef.current)) === null || _getNextFocussableEle === void 0 ? void 0 : _getNextFocussableEle.focus();
15812
+ return;
15835
15813
  }
15836
15814
  };
15837
15815
  const areAllSelected = Array.isArray(value) && selectOptions.every(option => value.includes(option));
@@ -15880,18 +15858,14 @@ const Select2 = /*#__PURE__*/React__default.forwardRef(function Select2(props, r
15880
15858
  }, /*#__PURE__*/React__default.createElement(Trigger$7, Object.assign({}, otherProps, {
15881
15859
  "aria-haspopup": "listbox",
15882
15860
  emptyValue: emptyValue,
15883
- onBlur: handleBlur,
15884
15861
  onKeyDown: handleKeyDown,
15885
15862
  placeholder: placeholder,
15886
15863
  ref: internalRef
15887
15864
  }), flattenedChildren)), /*#__PURE__*/React__default.createElement(PopoverPrimitive.Portal, null, /*#__PURE__*/React__default.createElement(PopoverPrimitive.Content, {
15888
15865
  asChild: true,
15889
15866
  align: "start",
15890
- onOpenAutoFocus: () => {
15891
- var _internalRef$current2;
15892
- (_internalRef$current2 = internalRef.current) === null || _internalRef$current2 === void 0 ? void 0 : _internalRef$current2.focus();
15893
- },
15894
15867
  onCloseAutoFocus: handleCloseAutoFocus,
15868
+ onPointerDownOutside: otherProps.onBlur,
15895
15869
  sideOffset: 4,
15896
15870
  tabIndex: -1
15897
15871
  }, /*#__PURE__*/React__default.createElement("div", {
@@ -15901,8 +15875,7 @@ const Select2 = /*#__PURE__*/React__default.forwardRef(function Select2(props, r
15901
15875
  }
15902
15876
  }, hasSearch ? (/*#__PURE__*/React__default.createElement(React__default.Fragment, null, /*#__PURE__*/React__default.createElement(Search$2, {
15903
15877
  placeholder: hasInlineCreation ? texts.select2.searchOrCreate : texts.select2.search,
15904
- ref: searchRef,
15905
- onTabKeyPress: () => setTabTriggeredClose(true)
15878
+ ref: searchRef
15906
15879
  }), multiple && selectOptions.length > 1 && (/*#__PURE__*/React__default.createElement(React__default.Fragment, null, /*#__PURE__*/React__default.createElement(Button$1, {
15907
15880
  className: "!justify-start",
15908
15881
  appearance: "discrete",
@@ -15972,6 +15945,7 @@ const ControlledHiddenField = props => {
15972
15945
  key: String(bubbleValue),
15973
15946
  multiple: multiple,
15974
15947
  name: name,
15948
+ tabIndex: -1,
15975
15949
  value: bubbleValue
15976
15950
  }, emptyValue !== undefined ? /*#__PURE__*/React__default.createElement("option", {
15977
15951
  value: emptyValue
@@ -16422,7 +16396,7 @@ function Control(props) {
16422
16396
  const dataType = column === null || column === void 0 ? void 0 : (_column$columnDef$met3 = column.columnDef.meta) === null || _column$columnDef$met3 === void 0 ? void 0 : _column$columnDef$met3.dataType;
16423
16397
  React.useEffect(() => {
16424
16398
  // Set value to false only after first render of the control (when it's undefined) after setting the FilterColumn value, because we don't want to change then the value every time filter is opened
16425
- if (controlRenderer === 'switch' && value === undefined) {
16399
+ if ((controlRenderer === 'switch' || controlRenderer === 'checkbox') && value === undefined) {
16426
16400
  onChange(false);
16427
16401
  }
16428
16402
  }, [controlRenderer]);
@@ -16446,6 +16420,12 @@ function Control(props) {
16446
16420
  checked: Boolean(value),
16447
16421
  onChange: onChange
16448
16422
  }));
16423
+ } else if (controlRenderer === 'checkbox') {
16424
+ return /*#__PURE__*/React__default.createElement(Checkbox, Object.assign({}, attributes, {
16425
+ className: "!m-1.5",
16426
+ checked: Boolean(value),
16427
+ onChange: onChange
16428
+ }));
16449
16429
  } else if ((controlRenderer === 'input' || controlRenderer === undefined) && dataType === 'number') {
16450
16430
  return /*#__PURE__*/React__default.createElement(Input, Object.assign({}, attributes, {
16451
16431
  className: "flex-grow",
@@ -16798,7 +16778,6 @@ function TableGrid(props) {
16798
16778
  var _table$state$grouping;
16799
16779
  const {
16800
16780
  enableHorizontalArrowKeyNavigation,
16801
- rowsForFooter,
16802
16781
  table,
16803
16782
  ...attributes
16804
16783
  } = props;
@@ -16806,6 +16785,8 @@ function TableGrid(props) {
16806
16785
  table.meta.rowActive.handleFocus(event, table.meta.length, table.renderer.scrollToIndex);
16807
16786
  } : undefined;
16808
16787
  const filterReason = getFilterReason(table);
16788
+ const searchNotApplied = !table.state.globalFilter || table.state.globalFilter === '';
16789
+ const filtersNotApplied = !table.state.columnFilters || table.state.columnFilters.length === 0;
16809
16790
  return /*#__PURE__*/React__default.createElement(React__default.Fragment, null, /*#__PURE__*/React__default.createElement("style", null, table.stylesheet), /*#__PURE__*/React__default.createElement(focus.FocusScope, null, /*#__PURE__*/React__default.createElement("table", Object.assign({}, attributes, {
16810
16791
  id: table.id,
16811
16792
  "data-table-font-size": table.meta.fontSize.size,
@@ -16838,9 +16819,9 @@ function TableGrid(props) {
16838
16819
  ...table.renderer.style,
16839
16820
  height: table.renderer.style.height + ROW_HEIGHT_ESTIMATES[table.meta.rowHeight.height]
16840
16821
  } : table.renderer.style
16841
- }, table.renderer.rows, props.children), table.meta.footer.isEnabled ? /*#__PURE__*/React__default.createElement(Foot, {
16822
+ }, table.renderer.rows, searchNotApplied && filtersNotApplied && props.children), table.meta.footer.isEnabled ? /*#__PURE__*/React__default.createElement(Foot, {
16842
16823
  table: table.instance
16843
- }, rowsForFooter) : null)))));
16824
+ }) : null)))));
16844
16825
  }
16845
16826
 
16846
16827
  function Column$1(_) {
@@ -18343,16 +18324,33 @@ const useTableRowCreation = (data, tableRef) => {
18343
18324
 
18344
18325
  function useTableEditingListener(table, tableRef) {
18345
18326
  const tableMeta = table.options.meta;
18327
+ const completedRowsCount = tableMeta.editing.getCompletedRowsCount();
18346
18328
  const localization = useLocalization();
18329
+ const saveChanges = () => {
18330
+ requestAnimationFrame(() => {
18331
+ tableMeta.editing.saveChanges();
18332
+ });
18333
+ };
18347
18334
  // save when the row changes
18348
- // store the last row active index, otherwise everytime tableMeta.editing.saveChanges changes the hook runs again
18349
- const lastRowActiveIndexRef = React__default.useRef(tableMeta.rowActive.rowActiveIndex);
18350
18335
  useLazyEffect(() => {
18351
- if (tableMeta.editing.isEditing && tableMeta.rowActive.rowActiveIndex !== lastRowActiveIndexRef.current) {
18352
- lastRowActiveIndexRef.current = tableMeta.rowActive.rowActiveIndex;
18353
- tableMeta.editing.saveChanges(table);
18336
+ if (tableMeta.editing.isEditing) {
18337
+ saveChanges();
18338
+ }
18339
+ }, [tableMeta.rowActive.rowActiveIndex]);
18340
+ useLazyEffect(() => {
18341
+ if (tableMeta.editing.isEditing) {
18342
+ if (tableMeta.rowActive.rowActiveIndex === undefined) {
18343
+ tableMeta.rowActive.setRowActiveIndex(0);
18344
+ }
18345
+ } else {
18346
+ // save
18347
+ saveChanges();
18348
+ // reset detailed mode
18349
+ tableMeta.editing.toggleDetailedMode(false);
18350
+ // reset the last index back to the first focusable element, when editing gets turned off
18351
+ tableMeta.editing.setLastFocusedCellIndex(undefined);
18354
18352
  }
18355
- }, [tableMeta.rowActive.rowActiveIndex, tableMeta.editing.saveChanges]);
18353
+ }, [tableMeta.editing.isEditing]);
18356
18354
  // show a warning if the user navigates away without triggering save, such as using the browser back/forward button
18357
18355
  const hasChanges = tableMeta.editing.hasChanges();
18358
18356
  React__default.useEffect(() => {
@@ -18368,46 +18366,25 @@ function useTableEditingListener(table, tableRef) {
18368
18366
  window.removeEventListener('beforeunload', showUnsavedChangesWarning);
18369
18367
  };
18370
18368
  }, [tableMeta.editing.isEditing, hasChanges]);
18371
- const hasSavedChanges = tableMeta.editing.hasSaved();
18372
- useLazyEffect(() => {
18373
- if (hasSavedChanges) {
18369
+ React__default.useEffect(() => {
18370
+ if (completedRowsCount > 0) {
18374
18371
  resetHighlightedColumnIndexes(table.getState().globalFilter, table, localization);
18375
18372
  }
18376
- }, [hasSavedChanges]);
18373
+ }, [completedRowsCount]);
18377
18374
  React__default.useEffect(() => {
18378
18375
  const onClickOutside = event => {
18379
18376
  if (tableMeta.editing.isEditing) {
18380
- const element = event.target;
18381
- const insideTable = element.getAttribute('data-taco') === 'backdrop' || element.getAttribute('data-table') === 'editing-toggle' || isElementInsideOrTriggeredFromContainer(element, tableRef.current);
18382
- // users can click the white space below rows which could be inside the table, but a valid scenario to save
18383
- if (!insideTable || element.tagName === 'TABLE' || element.tagName === 'TBODY') {
18384
- tableMeta.editing.saveChanges(table);
18377
+ var _event$target$getAttr, _event$target;
18378
+ const element = (_event$target$getAttr = (_event$target = event.target) === null || _event$target === void 0 ? void 0 : _event$target.getAttribute('data-taco')) !== null && _event$target$getAttr !== void 0 ? _event$target$getAttr : '';
18379
+ const insideTable = isElementInsideOrTriggeredFromContainer(event.target, tableRef.current) || element === 'backdrop';
18380
+ if (!insideTable) {
18381
+ saveChanges();
18385
18382
  }
18386
18383
  }
18387
18384
  };
18388
18385
  document.addEventListener('click', onClickOutside);
18389
18386
  return () => document.removeEventListener('click', onClickOutside);
18390
- }, [tableMeta.editing.isEditing, tableMeta.editing.saveChanges]);
18391
- const rows = table.getRowModel().rows;
18392
- // make sure pending changes are removed for rows that no longer exist
18393
- useLazyEffect(() => {
18394
- const pendingChanges = tableMeta.editing.getErrorsShownInAlert();
18395
- pendingChanges.forEach(pendingChange => {
18396
- try {
18397
- table.getRow(pendingChange.rowId);
18398
- } catch {
18399
- tableMeta.editing.discardChanges(pendingChange.rowId, table);
18400
- }
18401
- });
18402
- }, [rows.length]);
18403
- useGlobalKeyDown(tableMeta.editing.isEditing ? {
18404
- key: 's',
18405
- meta: true,
18406
- shift: false
18407
- } : undefined, event => {
18408
- event.preventDefault();
18409
- tableMeta.editing.saveChanges(table);
18410
- });
18387
+ }, [saveChanges, tableMeta.editing.isEditing]);
18411
18388
  }
18412
18389
 
18413
18390
  function willRowMove(cell, change, rowIndex, localization) {
@@ -18489,539 +18466,444 @@ function willRowMoveAfterSorting(cell, change, rowIndex) {
18489
18466
  }
18490
18467
  return ((_resortedRows$index = resortedRows[index]) === null || _resortedRows$index === void 0 ? void 0 : _resortedRows$index.id) !== cell.row.id;
18491
18468
  }
18492
-
18493
- const TEMPORARY_ROW_ID_PREFIX = 'temp-';
18494
- const DELAY_BEFORE_REMOVING_SAVE_STATUS = 3000;
18495
- function reducer$2(state, action) {
18496
- const {
18497
- type,
18498
- rowId,
18499
- payload
18500
- } = action;
18501
- switch (type) {
18502
- case 'setCellValue':
18503
- {
18504
- const {
18505
- columnId,
18506
- row,
18507
- value
18508
- } = payload;
18509
- return {
18510
- ...state,
18511
- changes: {
18512
- ...state.changes,
18513
- rows: setWith(state.changes.rows, `${rowId}.${columnId}`, value, Object),
18514
- originals: setWith(state.changes.originals, rowId, row, Object)
18515
- }
18516
- };
18517
- }
18518
- case 'removeCellValue':
18519
- {
18520
- const {
18521
- columnId,
18522
- rowIdentityAccessor
18523
- } = payload;
18524
- const changes = omit(state.changes.rows, `${rowId}.${columnId}`);
18525
- // if there are no changes left, remove the row
18526
- if (!Object.keys(changes[rowId]).length) {
18527
- return reducer$2(state, {
18528
- type: 'removeRow',
18529
- rowId,
18530
- payload: {
18531
- rowIdentityAccessor
18532
- }
18533
- });
18534
- }
18535
- return {
18536
- ...state,
18537
- changes: {
18538
- ...state.changes,
18539
- rows: omit(state.changes.rows, `${rowId}.${columnId}`),
18540
- errors: omit(state.changes.errors, `${rowId}.cells.${columnId}`),
18541
- moveReasons: omit(state.changes.moveReasons, `${rowId}.${columnId}`)
18542
- }
18543
- };
18544
- }
18545
- case 'updateRow':
18546
- {
18547
- const {
18548
- cellErrors,
18549
- moveReasons,
18550
- original,
18551
- value
18552
- } = payload;
18553
- return {
18554
- ...state,
18555
- changes: {
18556
- ...state.changes,
18557
- rows: setWith(state.changes.rows, rowId, value, Object),
18558
- errors: setWith(state.changes.errors, `${rowId}.cells`, cellErrors !== null && cellErrors !== void 0 ? cellErrors : state.changes.errors.cells[rowId], Object),
18559
- originals: setWith(state.changes.originals, rowId, original !== null && original !== void 0 ? original : state.changes.originals[rowId], Object),
18560
- moveReasons: setWith(state.changes.moveReasons, rowId, moveReasons !== null && moveReasons !== void 0 ? moveReasons : state.changes.moveReasons[rowId], Object),
18561
- // status can be undefined, so don't use ??
18562
- status: setWith(state.changes.status, rowId, undefined, Object)
18563
- }
18564
- };
18565
- }
18566
- case 'removeRow':
18567
- {
18568
- const {
18569
- rowIdentityAccessor
18570
- } = payload;
18571
- return {
18572
- ...state,
18573
- changes: {
18574
- ...state.changes,
18575
- rows: omit(state.changes.rows, rowId),
18576
- errors: omit(state.changes.errors, rowId),
18577
- moveReasons: omit(state.changes.moveReasons, rowId),
18578
- originals: omit(state.changes.originals, rowId),
18579
- status: omit(state.changes.status, rowId)
18580
- },
18581
- temporaryRows: state.temporaryRows.filter(row => row[rowIdentityAccessor] !== rowId)
18582
- };
18583
- }
18584
- case 'setRowStatus':
18585
- {
18586
- const {
18587
- status
18588
- } = payload;
18589
- return {
18590
- ...state,
18591
- changes: {
18592
- ...state.changes,
18593
- status: status ? setWith(state.changes.status, rowId, status, Object) : omit(state.changes.status, rowId)
18594
- }
18595
- };
18596
- }
18597
- case 'setRowErrors':
18598
- {
18599
- const {
18600
- ...errors
18601
- } = payload;
18602
- return {
18603
- ...state,
18604
- changes: {
18605
- ...state.changes,
18606
- errors: setWith(state.changes.errors, rowId, errors, Object)
18607
- }
18608
- };
18609
- }
18610
- case 'createRow':
18611
- {
18612
- const {
18613
- value
18614
- } = payload;
18615
- return {
18616
- ...state,
18617
- temporaryRows: state.temporaryRows.concat(value),
18618
- changes: {
18619
- ...state.changes,
18620
- rows: setWith(state.changes.rows, rowId, value, Object),
18621
- originals: setWith(state.changes.originals, rowId, value, Object)
18622
- }
18623
- };
18624
- }
18625
- default:
18626
- return state;
18469
+ function animateCreateRow(id) {
18470
+ const templateRow = document.querySelector(`[data-row-id="${id}"]`);
18471
+ if (templateRow) {
18472
+ const firstCell = templateRow.querySelector(':first-child');
18473
+ const checkbox = firstCell === null || firstCell === void 0 ? void 0 : firstCell.querySelector('[data-taco="checkbox"]');
18474
+ firstCell === null || firstCell === void 0 ? void 0 : firstCell.focus();
18475
+ if (checkbox) {
18476
+ setDataFocusAttribute(checkbox);
18477
+ }
18478
+ templateRow.scrollIntoView();
18479
+ const keyframes = [{
18480
+ background: '#b2c7ef'
18481
+ }, {
18482
+ background: '#ebebeb'
18483
+ }];
18484
+ for (const child of templateRow.children) {
18485
+ child.animate(keyframes, {
18486
+ duration: 1000,
18487
+ easing: 'ease-out'
18488
+ });
18489
+ }
18627
18490
  }
18628
18491
  }
18629
- function usePendingChangesState(handleSave, handleChange, rowIdentityAccessor, validator) {
18630
- const saveChanges = function (table, rowId = undefined) {
18492
+
18493
+ function useTableEditing(isEnabled = false, handleSave, handleChange, validator) {
18494
+ // used to switch the table into editing mode
18495
+ const [isEditing, toggleEditing] = React__default.useState(false);
18496
+ // used to switch the editing between "detailed" mode
18497
+ const [isDetailedMode, toggleDetailedMode] = React__default.useState(false);
18498
+ // store the last focused cell, so that up/down arrow key navigation remains in the same column
18499
+ const [lastFocusedCellIndex, setLastFocusedCellIndex] = useLastFocusedCellIndex();
18500
+ // store pending changes for each row
18501
+ // changes are saved as soon as the active row changes, so in most cases this will only contain the active row's changes
18502
+ // but not always - if validation or server requests fail when saving, those rows remain until the failure is resolved
18503
+ const pendingChangesFns = usePendingChanges(isEnabled, handleSave, handleChange, validator);
18504
+ useGlobalKeyDown(isEnabled && isEditing ? {
18505
+ key: 's',
18506
+ meta: true,
18507
+ shift: false
18508
+ } : undefined, event => {
18509
+ event.preventDefault();
18510
+ pendingChangesFns.saveChanges();
18511
+ });
18512
+ return {
18513
+ isEnabled,
18514
+ isEditing,
18515
+ isDetailedMode,
18516
+ toggleDetailedMode: isEnabled ? toggleDetailedMode : () => undefined,
18517
+ toggleEditing: isEnabled ? toggleEditing : () => undefined,
18518
+ lastFocusedCellIndex,
18519
+ setLastFocusedCellIndex,
18520
+ ...pendingChangesFns
18521
+ };
18522
+ }
18523
+ function usePendingChanges(isEnabled, handleSave, handleChange, validator) {
18524
+ const saveChanges = function (rowId = undefined) {
18631
18525
  try {
18632
18526
  let _exit = false;
18633
18527
  if (!handleSave) {
18634
18528
  console.warn('Tried to save, but Table has no onEditingSave handler');
18635
- return Promise.resolve(false);
18529
+ return Promise.resolve();
18636
18530
  }
18637
- // sometimes we only want to save one row
18638
- const changes = rowId ? {
18639
- [rowId]: state.changes.rows[rowId]
18640
- } : state.changes.rows;
18641
- let completed = true;
18642
- const _temp9 = _forOf(Object.keys(changes), function (rowId) {
18643
- const status = getRowStatus(rowId);
18644
- return _catch(function () {
18645
- var _changeSet$rowIdentit;
18646
- function _temp8(_result) {
18647
- return _exit ? _result : Promise.resolve(handleSave(changeSet)).then(function () {
18648
- // cleanup changes, we don't need them after saving
18649
- discardChanges(rowId, table);
18650
- // show the saved status, then remove it after a delay
18651
- setRowStatus(rowId, 'saved');
18652
- setTimeout(() => {
18653
- setRowStatus(rowId, undefined);
18654
- }, DELAY_BEFORE_REMOVING_SAVE_STATUS);
18655
- });
18656
- }
18657
- // don't try to save if - already saving, or there are known errors
18658
- if (status === 'saving' || status === 'errored') {
18659
- return;
18660
- }
18661
- setRowStatus(rowId, 'saving');
18662
- const changeSet = {
18663
- ...state.changes.originals[rowId],
18664
- ...changes[rowId]
18665
- };
18666
- // if we had to create a temporary id, delete it first - it's our data, not theirs
18667
- if ((_changeSet$rowIdentit = changeSet[rowIdentityAccessor]) !== null && _changeSet$rowIdentit !== void 0 && _changeSet$rowIdentit.startsWith(TEMPORARY_ROW_ID_PREFIX)) {
18668
- delete changeSet[rowIdentityAccessor];
18669
- }
18670
- // re-run validation, maybe a cell is already invalid but has never been blurred
18671
- const _temp7 = function () {
18672
- if (validator) {
18673
- return Promise.resolve(validator(changeSet)).then(function (errors) {
18674
- if (errors && Object.keys(errors).length) {
18675
- throw errors;
18531
+ // we save back to pendingChanges, so make a copy of it's state when save was triggered
18532
+ const changesToSave = rowId ? {
18533
+ [rowId]: pendingChanges[rowId]
18534
+ } : {
18535
+ ...pendingChanges
18536
+ };
18537
+ const changes = Object.keys(changesToSave);
18538
+ return Promise.resolve(function () {
18539
+ if (changes.length) {
18540
+ return _forOf(changes, function (rowId) {
18541
+ const pendingChange = changesToSave[rowId];
18542
+ const changeSet = getChangesetFromChanges(pendingChange);
18543
+ return _catch(function () {
18544
+ function _temp3(_result) {
18545
+ return _exit ? _result : Promise.resolve(handleSave(changeSet)).then(function () {
18546
+ // cleanup changes, we don't need them after saving
18547
+ resetChanges(rowId);
18548
+ setRowSaveStatus(rowId, 'complete');
18549
+ });
18550
+ }
18551
+ if (getRowSaveStatus(rowId) === 'pending') {
18552
+ _exit = true;
18553
+ return;
18554
+ }
18555
+ // set saving = true
18556
+ setRowSaveStatus(rowId, 'pending');
18557
+ // re-run validation, maybe a cell is already invalid but has never been blurred
18558
+ const _temp2 = function () {
18559
+ if (validator) {
18560
+ return Promise.resolve(validator(changeSet)).then(function (errors) {
18561
+ if (errors && Object.keys(errors).length) {
18562
+ throw errors;
18563
+ }
18564
+ });
18676
18565
  }
18677
- });
18678
- }
18679
- }();
18680
- return _temp7 && _temp7.then ? _temp7.then(_temp8) : _temp8(_temp7); // send new data to the server
18681
- }, function (error) {
18682
- var _error$response;
18683
- if (error instanceof ReferenceError || error instanceof TypeError || (error === null || error === void 0 ? void 0 : (_error$response = error.response) === null || _error$response === void 0 ? void 0 : _error$response.status) >= 500) {
18684
- console.error(error);
18685
- }
18686
- // the onEditingSave handler should throw errors when something fails, e.g. validation, network errors etc
18687
- // this code handles those errors and maps them either to row errors or cell specific errors
18688
- let rowError;
18689
- let cellErrors;
18690
- if (typeof error === 'string') {
18691
- rowError = error;
18692
- } else if (error instanceof Error) {
18693
- var _error$response2;
18694
- rowError = error.message;
18695
- // most of our apis return error objects within this shape
18696
- if (typeof ((_error$response2 = error.response) === null || _error$response2 === void 0 ? void 0 : _error$response2.data) === 'object') {
18697
- var _error$response3;
18698
- cellErrors = (_error$response3 = error.response) === null || _error$response3 === void 0 ? void 0 : _error$response3.data;
18699
- }
18700
- } else if (typeof error === 'object') {
18701
- cellErrors = error;
18702
- }
18703
- if (rowError || cellErrors) {
18704
- dispatch({
18705
- type: 'setRowErrors',
18706
- rowId,
18707
- payload: {
18708
- row: rowError,
18709
- cells: cellErrors,
18710
- shouldShowErrorAlert: true
18566
+ }();
18567
+ return _temp2 && _temp2.then ? _temp2.then(_temp3) : _temp3(_temp2); // send new data to the server
18568
+ }, function (error) {
18569
+ // the onEditingSave handler should throw errors when something fails, e.g. validation, network errors etc
18570
+ // this code handles those errors and maps them either to row errors or cell specific errors
18571
+ let rowError;
18572
+ let cellErrors;
18573
+ if (typeof error === 'string') {
18574
+ rowError = error;
18575
+ } else if (error instanceof Error) {
18576
+ var _error$response;
18577
+ rowError = error.message;
18578
+ // most of our apis return error objects within this shape
18579
+ if (typeof ((_error$response = error.response) === null || _error$response === void 0 ? void 0 : _error$response.data) === 'object') {
18580
+ var _error$response2;
18581
+ cellErrors = (_error$response2 = error.response) === null || _error$response2 === void 0 ? void 0 : _error$response2.data;
18582
+ }
18583
+ } else if (typeof error === 'object') {
18584
+ cellErrors = error;
18585
+ }
18586
+ if (rowError || cellErrors) {
18587
+ setPendingChanges(currentChanges => {
18588
+ const nextChanges = {
18589
+ ...currentChanges
18590
+ };
18591
+ nextChanges[rowId]._meta.errors = {
18592
+ row: rowError,
18593
+ cells: cellErrors,
18594
+ shouldShowErrorAlert: true
18595
+ };
18596
+ return nextChanges;
18597
+ });
18711
18598
  }
18599
+ setRowSaveStatus(rowId, undefined);
18712
18600
  });
18713
- }
18714
- setRowStatus(rowId, 'errored');
18715
- completed = false;
18716
- });
18717
- }, function () {
18718
- return _exit;
18719
- });
18720
- return Promise.resolve(_temp9 && _temp9.then ? _temp9.then(function (_result3) {
18721
- return _exit ? _result3 : completed;
18722
- }) : _exit ? _temp9 : completed);
18601
+ }, function () {
18602
+ return _exit;
18603
+ });
18604
+ }
18605
+ }());
18723
18606
  } catch (e) {
18724
18607
  return Promise.reject(e);
18725
18608
  }
18726
18609
  };
18727
- const onCellChanged = function (cell, rowIndex) {
18610
+ const validateCell = function (cell) {
18728
18611
  try {
18729
- function _temp6() {
18730
- var _state$changes$errors8;
18731
- function _temp4() {
18732
- // only set errors and move reasons for the cells we're currently acting on
18733
- // why? because the UX is not good if we set them for cells the user hasn't touched yet
18734
- const cellsToActOn = [cell.column.id, ...Object.keys(updatesForOtherCells)];
18735
- const allCells = cell.row._getAllCellsByColumnId();
18736
- cellsToActOn.forEach(accessor => {
18737
- if (validationErrors[accessor]) {
18738
- nextCellErrors[accessor] = validationErrors[accessor];
18739
- // don't show move indicator for cells with errors, they aren't valid and can't be saved
18740
- delete nextMoveReasons[accessor];
18741
- } else {
18742
- var _allCells$accessor;
18743
- // there isn't any error in this run, remove any error set in state
18744
- delete nextCellErrors[accessor];
18745
- if ((_allCells$accessor = allCells[accessor]) !== null && _allCells$accessor !== void 0 && _allCells$accessor.column.getIsSorted()) {
18746
- // run row move determination
18747
- const reason = willRowMove(cell, nextChanges[accessor], rowIndex, localization);
18748
- // if the row will move based on this change save why, otherwise delete any existing state
18749
- if (reason) {
18750
- nextMoveReasons[accessor] = reason;
18751
- } else {
18752
- delete nextMoveReasons[accessor];
18753
- }
18754
- }
18755
- }
18756
- });
18757
- dispatch({
18758
- type: 'updateRow',
18759
- rowId: cell.row.id,
18760
- payload: {
18761
- cellErrors: nextCellErrors,
18762
- moveReasons: nextMoveReasons,
18763
- value: nextChanges
18764
- }
18765
- });
18766
- }
18767
- // create a projection of the next state, so we can act against it
18768
- const nextChanges = {
18769
- ...state.changes.rows[cell.row.id],
18770
- ...updatesForOtherCells
18771
- };
18772
- const nextMoveReasons = {
18773
- ...state.changes.moveReasons[cell.row.id]
18774
- };
18775
- const nextCellErrors = {
18776
- ...((_state$changes$errors8 = state.changes.errors[cell.row.id]) === null || _state$changes$errors8 === void 0 ? void 0 : _state$changes$errors8.cells)
18777
- };
18778
- // run validation
18779
- let validationErrors = {};
18780
- const _temp3 = function () {
18781
- if (validator) {
18782
- const nextRowValue = {
18783
- ...state.changes.originals[cell.row.id],
18784
- ...changes,
18785
- ...updatesForOtherCells
18786
- };
18787
- return Promise.resolve(validator(nextRowValue)).then(function (_validator2) {
18788
- validationErrors = _validator2 !== null && _validator2 !== void 0 ? _validator2 : {};
18789
- });
18790
- }
18791
- }();
18792
- return _temp3 && _temp3.then ? _temp3.then(_temp4) : _temp4(_temp3);
18793
- }
18794
- const changes = state.changes.rows[cell.row.id];
18795
- if (!changes) {
18612
+ if (!validator || !isEnabled) {
18796
18613
  return Promise.resolve();
18797
18614
  }
18798
- let updatesForOtherCells = {};
18799
- // run the updater handler if there is one, to see if there are any other cells to update
18800
- const _temp5 = function () {
18801
- if (typeof handleChange === 'function') {
18802
- const previousRowValue = {
18803
- ...state.changes.originals[cell.row.id]
18804
- };
18805
- const nextRowValue = {
18806
- ...state.changes.originals[cell.row.id],
18807
- ...changes
18808
- };
18809
- return Promise.resolve(handleChange(cell.column.id, changes[cell.column.id], nextRowValue, previousRowValue)).then(function (_handleChange) {
18810
- updatesForOtherCells = _handleChange !== null && _handleChange !== void 0 ? _handleChange : {};
18615
+ const changeSet = getChangesetFromChanges(pendingChanges[cell.row.id]);
18616
+ // only validate if the cell being blurred actually has any changes
18617
+ const _temp = function () {
18618
+ if (cell.column.id in changeSet) {
18619
+ return Promise.resolve(validator(changeSet)).then(function (errors) {
18620
+ setPendingChanges(currentChanges => {
18621
+ const nextChanges = {
18622
+ ...currentChanges
18623
+ };
18624
+ nextChanges[cell.row.id]._meta = {
18625
+ ...nextChanges[cell.row.id]._meta,
18626
+ errors: {
18627
+ ...nextChanges[cell.row.id]._meta.errors,
18628
+ cells: errors,
18629
+ shouldShowErrorAlert: !Object.keys(errors).length ? false : nextChanges[cell.row.id]._meta.errors.shouldShowErrorAlert
18630
+ }
18631
+ };
18632
+ return nextChanges;
18633
+ });
18811
18634
  });
18812
18635
  }
18813
18636
  }();
18814
- return Promise.resolve(_temp5 && _temp5.then ? _temp5.then(_temp6) : _temp6(_temp5));
18637
+ return Promise.resolve(_temp && _temp.then ? _temp.then(function () {}) : void 0);
18815
18638
  } catch (e) {
18816
18639
  return Promise.reject(e);
18817
18640
  }
18818
- }; // general
18819
- const createRow = function (data) {
18641
+ };
18642
+ const setCellValue = function (cell, change, rowIndex) {
18820
18643
  try {
18821
- const newRowId = `${TEMPORARY_ROW_ID_PREFIX}${uuid.v4()}`;
18822
- const value = {
18823
- ...data,
18824
- [rowIdentityAccessor]: newRowId
18644
+ const changes = {
18645
+ [cell.column.id]: change
18825
18646
  };
18826
- dispatch({
18827
- type: 'createRow',
18828
- rowId: newRowId,
18829
- payload: {
18830
- value
18831
- }
18647
+ setPendingChanges(currentChanges => {
18648
+ const nextChanges = createPendingChangesSetter(currentChanges, cell.row, rowIndex, changes, localization);
18649
+ pendingChangesUpdater.syncCellChanges(nextChanges);
18650
+ return nextChanges;
18832
18651
  });
18833
- return Promise.resolve(newRowId);
18652
+ pendingChangesUpdater.runCellUpdates(changes, cell, rowIndex);
18653
+ return Promise.resolve();
18834
18654
  } catch (e) {
18835
18655
  return Promise.reject(e);
18836
18656
  }
18837
- }; // cells
18838
- // rows
18839
- const setRowValue = function (rowId, original, value) {
18657
+ };
18658
+ const addCreatedRowChangeset = function (row) {
18840
18659
  try {
18841
- function _temp2() {
18842
- dispatch({
18843
- type: 'updateRow',
18844
- rowId,
18845
- payload: {
18846
- cellErrors,
18847
- original,
18848
- value
18660
+ const cells = row.getAllCells();
18661
+ setPendingChanges(currentChanges => {
18662
+ return cells.reduce((changes, cell) => {
18663
+ if (cell.getValue()) {
18664
+ var _currentChanges$cell$, _currentChanges$cell$2, _currentChanges$cell$3;
18665
+ return {
18666
+ ...changes,
18667
+ [cell.row.id]: {
18668
+ ...changes[cell.row.id],
18669
+ [cell.column.id]: cell.getValue(),
18670
+ _meta: {
18671
+ ...((_currentChanges$cell$ = currentChanges[cell.row.id]) === null || _currentChanges$cell$ === void 0 ? void 0 : _currentChanges$cell$._meta),
18672
+ original: cell.row.original,
18673
+ moveReason: {
18674
+ ...((_currentChanges$cell$2 = currentChanges[cell.row.id]) === null || _currentChanges$cell$2 === void 0 ? void 0 : _currentChanges$cell$2._meta.moveReason)
18675
+ },
18676
+ errors: {
18677
+ ...((_currentChanges$cell$3 = currentChanges[cell.row.id]) === null || _currentChanges$cell$3 === void 0 ? void 0 : _currentChanges$cell$3._meta.errors)
18678
+ }
18679
+ }
18680
+ }
18681
+ };
18682
+ } else {
18683
+ return changes;
18849
18684
  }
18850
- });
18851
- }
18852
- let cellErrors;
18853
- const _temp = function () {
18854
- if (validator) {
18855
- const row = {
18856
- ...original,
18857
- ...value
18858
- };
18859
- return Promise.resolve(validator(row)).then(function (_validator) {
18860
- cellErrors = _validator !== null && _validator !== void 0 ? _validator : {};
18861
- });
18862
- }
18863
- }();
18864
- return Promise.resolve(_temp && _temp.then ? _temp.then(_temp2) : _temp2(_temp));
18685
+ }, currentChanges);
18686
+ });
18687
+ return Promise.resolve();
18865
18688
  } catch (e) {
18866
18689
  return Promise.reject(e);
18867
18690
  }
18868
18691
  };
18869
18692
  const localization = useLocalization();
18870
- const [state, dispatch] = React__default.useReducer(reducer$2, {
18871
- changes: {
18872
- rows: {},
18873
- errors: {},
18874
- moveReasons: {},
18875
- originals: {},
18876
- status: {}
18877
- },
18878
- temporaryRows: []
18879
- });
18880
- function getRowValue(rowId) {
18881
- var _state$changes$rows$r, _state$changes$rows;
18882
- return (_state$changes$rows$r = (_state$changes$rows = state.changes.rows) === null || _state$changes$rows === void 0 ? void 0 : _state$changes$rows[rowId]) !== null && _state$changes$rows$r !== void 0 ? _state$changes$rows$r : undefined;
18693
+ const [pendingChanges, setPendingChanges] = React__default.useState({});
18694
+ // we maintain save status as separate state because 'complete' needs to briefly show after pendingChanges are deleted
18695
+ const [saveStates, setSaveState] = React__default.useState({});
18696
+ function getCellValue(cell) {
18697
+ var _pendingChanges$cell$;
18698
+ return (_pendingChanges$cell$ = pendingChanges[cell.row.id]) === null || _pendingChanges$cell$ === void 0 ? void 0 : _pendingChanges$cell$[cell.column.id];
18883
18699
  }
18884
- function getRowMoveReason(rowId) {
18885
- var _Object$values$, _state$changes$moveRe, _state$changes$moveRe2;
18886
- return (_Object$values$ = Object.values((_state$changes$moveRe = (_state$changes$moveRe2 = state.changes.moveReasons) === null || _state$changes$moveRe2 === void 0 ? void 0 : _state$changes$moveRe2[rowId]) !== null && _state$changes$moveRe !== void 0 ? _state$changes$moveRe : {})[0]) !== null && _Object$values$ !== void 0 ? _Object$values$ : undefined;
18700
+ function getCellError(cell) {
18701
+ var _pendingChanges$cell$2, _pendingChanges$cell$3, _pendingChanges$cell$4;
18702
+ return (_pendingChanges$cell$2 = pendingChanges[cell.row.id]) === null || _pendingChanges$cell$2 === void 0 ? void 0 : (_pendingChanges$cell$3 = _pendingChanges$cell$2._meta.errors) === null || _pendingChanges$cell$3 === void 0 ? void 0 : (_pendingChanges$cell$4 = _pendingChanges$cell$3.cells) === null || _pendingChanges$cell$4 === void 0 ? void 0 : _pendingChanges$cell$4[cell.column.id];
18887
18703
  }
18704
+ const pendingChangesUpdater = usePendingChangesUpdater(handleChange, setPendingChanges);
18888
18705
  function hasRowErrors(rowId) {
18889
- var _state$changes$errors, _state$changes$errors2, _state$changes$errors3;
18890
- return !!((_state$changes$errors = state.changes.errors[rowId]) !== null && _state$changes$errors !== void 0 && _state$changes$errors.row) || !!Object.keys((_state$changes$errors2 = (_state$changes$errors3 = state.changes.errors[rowId]) === null || _state$changes$errors3 === void 0 ? void 0 : _state$changes$errors3.cells) !== null && _state$changes$errors2 !== void 0 ? _state$changes$errors2 : {}).length;
18706
+ var _pendingChanges$rowId, _pendingChanges$rowId2, _pendingChanges$rowId3, _pendingChanges$rowId4, _pendingChanges$rowId5;
18707
+ if (!isEnabled) {
18708
+ return false;
18709
+ }
18710
+ return !!((_pendingChanges$rowId = pendingChanges[rowId]) !== null && _pendingChanges$rowId !== void 0 && (_pendingChanges$rowId2 = _pendingChanges$rowId._meta.errors) !== null && _pendingChanges$rowId2 !== void 0 && _pendingChanges$rowId2.row) || !!Object.keys((_pendingChanges$rowId3 = (_pendingChanges$rowId4 = pendingChanges[rowId]) === null || _pendingChanges$rowId4 === void 0 ? void 0 : (_pendingChanges$rowId5 = _pendingChanges$rowId4._meta.errors) === null || _pendingChanges$rowId5 === void 0 ? void 0 : _pendingChanges$rowId5.cells) !== null && _pendingChanges$rowId3 !== void 0 ? _pendingChanges$rowId3 : {}).length;
18891
18711
  }
18892
- function hasRowErrorsShownInAlert(rowId) {
18893
- var _state$changes$errors4;
18894
- return hasRowErrors(rowId) && !!((_state$changes$errors4 = state.changes.errors[rowId]) !== null && _state$changes$errors4 !== void 0 && _state$changes$errors4.shouldShowErrorAlert);
18712
+ function hasRowErrorsSeen(rowId) {
18713
+ var _pendingChanges$rowId6;
18714
+ if (!isEnabled) {
18715
+ return false;
18716
+ }
18717
+ return hasRowErrors(rowId) && !!((_pendingChanges$rowId6 = pendingChanges[rowId]._meta.errors) !== null && _pendingChanges$rowId6 !== void 0 && _pendingChanges$rowId6.shouldShowErrorAlert);
18895
18718
  }
18896
- function getRowStatus(rowId) {
18897
- return state.changes.status[rowId];
18719
+ function getRowPendingChange(rowId) {
18720
+ const rowPendingChanges = pendingChanges[rowId];
18721
+ if (rowPendingChanges) {
18722
+ const {
18723
+ _meta,
18724
+ ...pendingChange
18725
+ } = rowPendingChanges;
18726
+ return pendingChange;
18727
+ }
18728
+ return undefined;
18898
18729
  }
18899
- function setRowStatus(rowId, status) {
18900
- dispatch({
18901
- type: 'setRowStatus',
18902
- rowId,
18903
- payload: {
18904
- status
18730
+ function getRowSaveStatus(rowId) {
18731
+ if (!isEnabled) {
18732
+ return false;
18733
+ }
18734
+ return saveStates[rowId];
18735
+ }
18736
+ function setRowSaveStatus(rowId, status) {
18737
+ setSaveState(currentStates => {
18738
+ const nextStates = {
18739
+ ...currentStates
18740
+ };
18741
+ if (status) {
18742
+ nextStates[rowId] = status;
18743
+ } else {
18744
+ delete nextStates[rowId];
18905
18745
  }
18746
+ return nextStates;
18906
18747
  });
18907
18748
  }
18908
- function setCellValue(cell, value) {
18909
- const rowId = cell.row.id;
18910
- const columnId = cell.column.id;
18911
- // update if the change is different to the original value
18912
- if (value !== cell.row.original[columnId]) {
18913
- dispatch({
18914
- type: 'setCellValue',
18915
- rowId,
18916
- payload: {
18917
- columnId,
18918
- row: cell.row.original,
18919
- value
18920
- }
18921
- });
18922
- }
18923
- // otherwise remove any previous change - no point saving the same value
18924
- else if (cell.row.id in state.changes.rows) {
18925
- dispatch({
18926
- type: 'removeCellValue',
18927
- rowId,
18928
- payload: {
18929
- columnId,
18930
- rowIdentityAccessor
18931
- }
18932
- });
18933
- }
18934
- }
18935
- function getCellValue(cell) {
18936
- var _state$changes$rows2, _state$changes$rows2$;
18937
- return (_state$changes$rows2 = state.changes.rows) === null || _state$changes$rows2 === void 0 ? void 0 : (_state$changes$rows2$ = _state$changes$rows2[cell.row.id]) === null || _state$changes$rows2$ === void 0 ? void 0 : _state$changes$rows2$[cell.column.id];
18749
+ function getRowMoveReason(rowId) {
18750
+ var _pendingChanges$rowId7;
18751
+ return (_pendingChanges$rowId7 = pendingChanges[rowId]) !== null && _pendingChanges$rowId7 !== void 0 && _pendingChanges$rowId7._meta.moveReason ? Object.values(pendingChanges[rowId]._meta.moveReason)[0] : undefined;
18938
18752
  }
18939
- function getCellError(cell) {
18940
- var _state$changes$errors5, _state$changes$errors6, _state$changes$errors7;
18941
- return (_state$changes$errors5 = state.changes.errors) === null || _state$changes$errors5 === void 0 ? void 0 : (_state$changes$errors6 = _state$changes$errors5[cell.row.id]) === null || _state$changes$errors6 === void 0 ? void 0 : (_state$changes$errors7 = _state$changes$errors6.cells) === null || _state$changes$errors7 === void 0 ? void 0 : _state$changes$errors7[cell.column.id];
18753
+ function hasChanges(rowId) {
18754
+ if (!isEnabled) {
18755
+ return false;
18756
+ }
18757
+ return rowId ? !!pendingChanges[rowId] : !!Object.keys(pendingChanges).length;
18942
18758
  }
18943
- function getErrorsShownInAlert() {
18944
- const rowsWithErrors = Object.keys(state.changes.errors);
18945
- if (!rowsWithErrors.length) {
18946
- return [];
18759
+ function hasAlertErrors() {
18760
+ if (!isEnabled) {
18761
+ return false;
18947
18762
  }
18948
- return rowsWithErrors.filter(hasRowErrorsShownInAlert).map(rowId => ({
18763
+ return !!getAlertErrors().length;
18764
+ }
18765
+ function getAlertErrors() {
18766
+ return Object.keys(pendingChanges).filter(hasRowErrorsSeen).map(rowId => ({
18949
18767
  rowId,
18950
- changes: state.changes.rows[rowId],
18951
- errors: state.changes.errors[rowId]
18768
+ pendingChange: pendingChanges[rowId]
18952
18769
  }));
18953
18770
  }
18954
- function hasSaved() {
18955
- return !!Object.values(state.changes.status).filter(value => value === 'saved').length;
18956
- }
18957
- function hasChanges(rowId) {
18958
- return rowId ? !!state.changes.rows[rowId] : !!Object.keys(state.changes.rows).length;
18959
- }
18960
- function discardChanges(rowId, table) {
18961
- // remove any new rows from pinned state before discarding them
18962
- table.resetRowPinning(true);
18963
- dispatch({
18964
- type: 'removeRow',
18965
- rowId,
18966
- payload: {
18967
- rowIdentityAccessor
18968
- }
18771
+ function resetChanges(rowId) {
18772
+ setPendingChanges(currentChanges => {
18773
+ const nextChanges = {
18774
+ ...currentChanges
18775
+ };
18776
+ delete nextChanges[rowId];
18777
+ return nextChanges;
18969
18778
  });
18970
18779
  }
18780
+ function getCompletedRowsCount() {
18781
+ return Object.values(saveStates).filter(value => value === 'complete').length;
18782
+ }
18971
18783
  return {
18972
- // row
18973
- setRowValue,
18974
- getRowValue,
18975
- getRowMoveReason,
18976
- hasRowErrors,
18977
- hasRowErrorsShownInAlert,
18978
- getRowStatus,
18979
- setRowStatus,
18980
- // cells
18981
- setCellValue,
18982
18784
  getCellValue,
18983
18785
  getCellError,
18984
- onCellChanged,
18985
- // general
18986
- getErrorsShownInAlert,
18786
+ setCellValue,
18787
+ validateCell,
18788
+ addCreatedRowChangeset,
18987
18789
  hasChanges,
18790
+ hasAlertErrors,
18791
+ getAlertErrors,
18988
18792
  saveChanges,
18989
- discardChanges,
18990
- hasSaved,
18991
- // new rows
18992
- createRow,
18993
- temporaryRows: state.temporaryRows
18793
+ resetChanges,
18794
+ hasRowErrors,
18795
+ hasRowErrorsSeen,
18796
+ getRowPendingChange,
18797
+ getRowSaveStatus,
18798
+ setRowSaveStatus,
18799
+ getRowMoveReason,
18800
+ getCompletedRowsCount
18994
18801
  };
18995
18802
  }
18996
-
18997
- function useTableEditing(isEnabled = false, handleSave, handleChange, rowIdentityAccessor, validator) {
18998
- // used to switch the table into editing mode
18999
- const [isEditing, setEditing] = React__default.useState(false);
19000
- // used to switch the editing between "detailed" mode
19001
- const [isDetailedMode, toggleDetailedMode] = React__default.useState(false);
18803
+ function useLastFocusedCellIndex() {
19002
18804
  // store the last focused cell, so that up/down arrow key navigation remains in the same column
19003
- const [lastFocusedCellIndex, setLastFocusedCellIndex] = React__default.useState(undefined);
19004
- const pendingChangesFns = usePendingChangesState(handleSave, handleChange, rowIdentityAccessor, validator);
19005
- function toggleEditing(enabled, table) {
19006
- if (!enabled) {
19007
- // save
19008
- pendingChangesFns.saveChanges(table);
19009
- // reset detailed mode
19010
- toggleDetailedMode(false);
19011
- // reset the last index back to the first focusable element, when editing gets turned off
19012
- setLastFocusedCellIndex(undefined);
18805
+ const lastFocusedCellIndexRef = React__default.useRef(undefined);
18806
+ const setLastFocusedCellIndex = React__default.useCallback(index => {
18807
+ lastFocusedCellIndexRef.current = index;
18808
+ }, []);
18809
+ return [lastFocusedCellIndexRef.current, setLastFocusedCellIndex];
18810
+ }
18811
+ function usePendingChangesUpdater(handleChange, setPendingChanges) {
18812
+ const localization = useLocalization();
18813
+ const updatersRef = React__default.useRef({});
18814
+ const runCellUpdates = React__default.useCallback(lodash.debounce(function (changes, cell, rowIndex) {
18815
+ try {
18816
+ const _temp4 = function () {
18817
+ if (typeof handleChange === 'function') {
18818
+ const previousValues = {
18819
+ ...cell.row.original,
18820
+ ...getChangesetFromChanges(updatersRef.current[cell.row.id])
18821
+ };
18822
+ const nextValues = {
18823
+ ...previousValues,
18824
+ ...changes
18825
+ };
18826
+ return Promise.resolve(handleChange(cell.column.id, changes[cell.column.id], nextValues, previousValues)).then(function (updates) {
18827
+ if (updates && Object.keys(updates).length) {
18828
+ setPendingChanges(currentChanges => createPendingChangesSetter(currentChanges, cell.row, rowIndex, updates, localization));
18829
+ }
18830
+ });
18831
+ }
18832
+ }();
18833
+ return Promise.resolve(_temp4 && _temp4.then ? _temp4.then(function () {}) : void 0);
18834
+ } catch (e) {
18835
+ return Promise.reject(e);
19013
18836
  }
19014
- setEditing(enabled);
18837
+ }, 250), []);
18838
+ function syncCellChanges(changes) {
18839
+ updatersRef.current = changes;
19015
18840
  }
19016
18841
  return {
19017
- isEnabled,
19018
- isEditing,
19019
- isDetailedMode,
19020
- toggleDetailedMode: isEnabled ? toggleDetailedMode : () => undefined,
19021
- toggleEditing: isEnabled ? toggleEditing : () => undefined,
19022
- lastFocusedCellIndex,
19023
- setLastFocusedCellIndex,
19024
- ...pendingChangesFns
18842
+ syncCellChanges,
18843
+ runCellUpdates
18844
+ };
18845
+ }
18846
+ function createPendingChangesSetter(currentChanges, row, rowIndex, changes, localization) {
18847
+ var _currentChanges$row$i, _currentChanges$row$i2, _currentChanges$row$i3;
18848
+ // prepare
18849
+ const nextChanges = {
18850
+ ...currentChanges
18851
+ };
18852
+ const rowChanges = {
18853
+ ...currentChanges[row.id],
18854
+ _meta: {
18855
+ ...((_currentChanges$row$i = currentChanges[row.id]) === null || _currentChanges$row$i === void 0 ? void 0 : _currentChanges$row$i._meta),
18856
+ original: row.original,
18857
+ moveReason: {
18858
+ ...((_currentChanges$row$i2 = currentChanges[row.id]) === null || _currentChanges$row$i2 === void 0 ? void 0 : _currentChanges$row$i2._meta.moveReason)
18859
+ },
18860
+ errors: {
18861
+ ...((_currentChanges$row$i3 = currentChanges[row.id]) === null || _currentChanges$row$i3 === void 0 ? void 0 : _currentChanges$row$i3._meta.errors)
18862
+ }
18863
+ }
18864
+ };
18865
+ // run changes
18866
+ const cells = row._getAllCellsByColumnId();
18867
+ for (const [accessor, change] of Object.entries(changes)) {
18868
+ // update if the change is different to the original (saved) value,
18869
+ // otherwise remove any change - no point saving the same value
18870
+ if (change !== row.original[accessor]) {
18871
+ rowChanges[accessor] = change;
18872
+ // consumers sometimes include properties in onEditingChange that aren't rendered as columns, we need to guard against that.
18873
+ // eslint-disable-next-line no-prototype-builtins
18874
+ if (cells.hasOwnProperty(accessor)) {
18875
+ // determine if the row will move position based on this change, and save why it will move
18876
+ const reason = willRowMove(cells[accessor], change, rowIndex, localization);
18877
+ if (reason) {
18878
+ rowChanges._meta.moveReason[accessor] = reason;
18879
+ } else {
18880
+ delete rowChanges._meta.moveReason[accessor];
18881
+ }
18882
+ }
18883
+ } else {
18884
+ delete rowChanges[accessor];
18885
+ delete rowChanges._meta.moveReason[accessor];
18886
+ }
18887
+ }
18888
+ // set changes
18889
+ // or delete if there are no changes left, so that we don't store changes with unchanged data
18890
+ if (Object.keys(rowChanges).filter(k => k !== '_meta').length) {
18891
+ nextChanges[row.id] = rowChanges;
18892
+ } else {
18893
+ delete nextChanges[row.id];
18894
+ }
18895
+ return nextChanges;
18896
+ }
18897
+ function getChangesetFromChanges(changes) {
18898
+ // extract the original data from the row changes
18899
+ const {
18900
+ _meta,
18901
+ ...changeset
18902
+ } = changes !== null && changes !== void 0 ? changes : {};
18903
+ // and mix them in with the changes, ready to send to the server
18904
+ return {
18905
+ ...(_meta === null || _meta === void 0 ? void 0 : _meta.original),
18906
+ ...changeset
19025
18907
  };
19026
18908
  }
19027
18909
 
@@ -19263,28 +19145,13 @@ function EditingControlCell(props) {
19263
19145
  const {
19264
19146
  rowIndex
19265
19147
  } = React__default.useContext(RowContext);
19266
- const {
19267
- table
19268
- } = cell.getContext();
19269
- const tableMeta = table.options.meta;
19148
+ const tableMeta = cell.getContext().table.options.meta;
19270
19149
  const columnMeta = cell.column.columnDef.meta;
19271
19150
  const isActiveRow = tableMeta.rowActive.rowActiveIndex === rowIndex;
19272
- const type = (_columnMeta$control = columnMeta.control) !== null && _columnMeta$control !== void 0 ? _columnMeta$control : 'input';
19273
19151
  const handleFocus = useEditingCellAutofocus(props);
19274
- // some controls, like select2, should trigger cell changed (validation, updates) as the value changes
19275
- const hasNonTextControl = React__default.useMemo(() => {
19276
- var _cellRef$current;
19277
- return typeof type === 'function' && !!((_cellRef$current = cellRef.current) !== null && _cellRef$current !== void 0 && _cellRef$current.querySelector('[data-taco="Select2"],[data-taco="switch"],[data-taco="checkbox"]'));
19278
- }, [cellRef.current]);
19279
- const handleChange = value => {
19280
- tableMeta.editing.setCellValue(cell, value);
19281
- if (hasNonTextControl) {
19282
- tableMeta.editing.onCellChanged(cell, rowIndex);
19283
- }
19284
- };
19285
19152
  const handleBlur = () => {
19286
19153
  tableMeta.editing.toggleDetailedMode(false);
19287
- tableMeta.editing.onCellChanged(cell, rowIndex);
19154
+ tableMeta.editing.validateCell(cell);
19288
19155
  };
19289
19156
  // ensure that blur runs when the cell gets unmounted (when vertically arrow key navigating)
19290
19157
  React__default.useEffect(() => {
@@ -19296,9 +19163,6 @@ function EditingControlCell(props) {
19296
19163
  };
19297
19164
  }, []);
19298
19165
  const error = tableMeta.editing.getCellError(cell);
19299
- function toggleEditing(enabled) {
19300
- tableMeta.editing.toggleEditing(enabled, table);
19301
- }
19302
19166
  const controlProps = {
19303
19167
  dataType: columnMeta.dataType,
19304
19168
  fontSize: tableMeta.fontSize.size,
@@ -19307,13 +19171,13 @@ function EditingControlCell(props) {
19307
19171
  isDetailedMode: tableMeta.editing.isDetailedMode,
19308
19172
  isTruncated: !!columnMeta.enableTruncate,
19309
19173
  onBlur: handleBlur,
19310
- onChange: handleChange,
19174
+ onChange: value => tableMeta.editing.setCellValue(cell, value, rowIndex),
19311
19175
  row: cell.row.original,
19312
- rowPendingChanges: tableMeta.editing.getRowValue(cell.row.id),
19176
+ rowPendingChanges: tableMeta.editing.getRowPendingChange(cell.row.id),
19313
19177
  tabIndex: isActiveRow ? 0 : -1,
19314
- toggleEditing,
19178
+ toggleEditing: tableMeta.editing.toggleEditing,
19315
19179
  toggleDetailedMode: tableMeta.editing.toggleDetailedMode,
19316
- type,
19180
+ type: (_columnMeta$control = columnMeta.control) !== null && _columnMeta$control !== void 0 ? _columnMeta$control : 'input',
19317
19181
  value: cell.getValue()
19318
19182
  };
19319
19183
  const cellAttributes = {
@@ -19377,6 +19241,13 @@ const MemoedEditingCell = /*#__PURE__*/React__default.memo(function MemoedEditin
19377
19241
  ref: controlRef
19378
19242
  }));
19379
19243
  }
19244
+ if (type === 'checkbox') {
19245
+ return /*#__PURE__*/React__default.createElement(Checkbox, Object.assign({}, commonProps, {
19246
+ checked: Boolean(value),
19247
+ onChange: onChange,
19248
+ ref: controlRef
19249
+ }));
19250
+ }
19380
19251
  const handleInputKeyDown = event => {
19381
19252
  const target = event.target;
19382
19253
  if (target.readOnly) {
@@ -19421,6 +19292,10 @@ const MemoedEditingCell = /*#__PURE__*/React__default.memo(function MemoedEditin
19421
19292
  }
19422
19293
  return;
19423
19294
  }
19295
+ const shortcutWhitelist = ['f', 'p', 'e']; // f = search, p = print, and e = edit
19296
+ if (isPressingMetaKey(event) && !shortcutWhitelist.some(s => s === event.key)) {
19297
+ event.stopPropagation();
19298
+ }
19424
19299
  // toggle into detailed mode when actually inputting something
19425
19300
  if (!isPressingMetaKey(event) && (/^[a-z0-9]$/i.test(event.key) || event.key === 'Backspace')) {
19426
19301
  toggleDetailedMode(true);
@@ -19516,37 +19391,12 @@ function Cell$5(props) {
19516
19391
  return /*#__PURE__*/React__default.createElement(DisplayCell, Object.assign({}, props));
19517
19392
  }
19518
19393
 
19519
- function DiscardChangesConfirmationDialog(props) {
19520
- const {
19521
- onDiscard: handleDiscard,
19522
- ...dialogProps
19523
- } = props;
19524
- const {
19525
- texts
19526
- } = useLocalization();
19527
- const handleClickInsideDialogContent = event => {
19528
- // Prevents the click event from propagating to the table, ensuring the row isn't saved when a click occurs
19529
- // inside the dialog
19530
- event.stopPropagation();
19531
- };
19532
- return /*#__PURE__*/React__default.createElement(Dialog, Object.assign({}, dialogProps), /*#__PURE__*/React__default.createElement(Dialog.Content, {
19533
- "aria-label": texts.table3.editing.clearChangesConfirmationDialog.title,
19534
- onClick: handleClickInsideDialogContent
19535
- }, /*#__PURE__*/React__default.createElement(Dialog.Title, null, texts.table3.editing.clearChangesConfirmationDialog.title), /*#__PURE__*/React__default.createElement("p", null, texts.table3.editing.clearChangesConfirmationDialog.description), /*#__PURE__*/React__default.createElement(Dialog.Footer, null, /*#__PURE__*/React__default.createElement(Group, null, /*#__PURE__*/React__default.createElement(Dialog.Close, null, /*#__PURE__*/React__default.createElement(Button$1, {
19536
- tabIndex: 0
19537
- }, texts.table3.editing.clearChangesConfirmationDialog.cancel)), /*#__PURE__*/React__default.createElement(Dialog.Close, null, /*#__PURE__*/React__default.createElement(Button$1, {
19538
- autoFocus: true,
19539
- tabIndex: 0,
19540
- appearance: "primary",
19541
- onClick: handleDiscard
19542
- }, texts.table3.editing.clearChangesConfirmationDialog.confirm))))));
19543
- }
19544
-
19545
19394
  function EditingActionMenu(props) {
19546
19395
  const {
19547
19396
  hasChanges,
19548
19397
  hasErrors,
19549
- onDiscard: handleDiscard,
19398
+ onClear: handleClear,
19399
+ onExit: handleExit,
19550
19400
  onEditingSave: handleSave,
19551
19401
  isLastRow
19552
19402
  } = props;
@@ -19580,13 +19430,42 @@ function EditingActionMenu(props) {
19580
19430
  }, texts.table3.editing.actions.save), /*#__PURE__*/React__default.createElement(Menu$1.Item, {
19581
19431
  icon: "close",
19582
19432
  disabled: !hasChanges,
19583
- dialog: props => /*#__PURE__*/React__default.createElement(DiscardChangesConfirmationDialog, Object.assign({}, props, {
19584
- onDiscard: handleDiscard
19433
+ dialog: props => /*#__PURE__*/React__default.createElement(ConfirmClearChangesDialog, Object.assign({}, props, {
19434
+ onClear: handleClear
19585
19435
  }))
19586
- }, texts.table3.editing.actions.clear))))
19436
+ }, texts.table3.editing.actions.clear), /*#__PURE__*/React__default.createElement(Menu$1.Item, {
19437
+ icon: "undo",
19438
+ onClick: handleExit
19439
+ }, texts.table3.editing.actions.exit))))
19587
19440
  });
19588
19441
  }
19442
+ function ConfirmClearChangesDialog(props) {
19443
+ const {
19444
+ onClear: handleClear,
19445
+ ...dialogProps
19446
+ } = props;
19447
+ const {
19448
+ texts
19449
+ } = useLocalization();
19450
+ const handleClickInsideDialogContent = event => {
19451
+ // Prevents the click event from propagating to the table, ensuring the row isn't saved when a click occurs
19452
+ // inside the dialog
19453
+ event.stopPropagation();
19454
+ };
19455
+ return /*#__PURE__*/React__default.createElement(Dialog, Object.assign({}, dialogProps), /*#__PURE__*/React__default.createElement(Dialog.Content, {
19456
+ "aria-label": texts.table3.editing.clearChangesConfirmationDialog.title,
19457
+ onClick: handleClickInsideDialogContent
19458
+ }, /*#__PURE__*/React__default.createElement(Dialog.Title, null, texts.table3.editing.clearChangesConfirmationDialog.title), /*#__PURE__*/React__default.createElement("p", null, texts.table3.editing.clearChangesConfirmationDialog.description), /*#__PURE__*/React__default.createElement(Dialog.Footer, null, /*#__PURE__*/React__default.createElement(Group, null, /*#__PURE__*/React__default.createElement(Dialog.Close, null, /*#__PURE__*/React__default.createElement(Button$1, {
19459
+ tabIndex: 0
19460
+ }, texts.table3.editing.clearChangesConfirmationDialog.cancel)), /*#__PURE__*/React__default.createElement(Dialog.Close, null, /*#__PURE__*/React__default.createElement(Button$1, {
19461
+ autoFocus: true,
19462
+ tabIndex: 0,
19463
+ appearance: "primary",
19464
+ onClick: handleClear
19465
+ }, texts.table3.editing.clearChangesConfirmationDialog.confirm))))));
19466
+ }
19589
19467
 
19468
+ const COMPLETE_INDICATOR_DELAY = 3000;
19590
19469
  function SaveStatus(props) {
19591
19470
  const {
19592
19471
  rowId,
@@ -19596,7 +19475,18 @@ function SaveStatus(props) {
19596
19475
  texts
19597
19476
  } = useLocalization();
19598
19477
  const tableMeta = table.options.meta;
19599
- const status = tableMeta.editing.getRowStatus(rowId);
19478
+ const status = tableMeta.editing.getRowSaveStatus(rowId);
19479
+ React__default.useEffect(() => {
19480
+ let timeout;
19481
+ if (status === 'complete') {
19482
+ timeout = setTimeout(() => {
19483
+ tableMeta.editing.setRowSaveStatus(rowId, undefined);
19484
+ }, COMPLETE_INDICATOR_DELAY);
19485
+ }
19486
+ return () => {
19487
+ clearTimeout(timeout);
19488
+ };
19489
+ }, [status]);
19600
19490
  const className = cn('col-span-full sticky ml-auto right-0 top-0 -mb-[100%] z-10 h-8 bg-[inherit] flex items-center px-1.5 shadow-[-6px_0px_6px_var(--table-row-actions-shadow)]', {
19601
19491
  'mt-0.5': tableMeta.rowHeight.height === 'short',
19602
19492
  'mt-1': tableMeta.rowHeight.height === 'medium',
@@ -19607,7 +19497,7 @@ function SaveStatus(props) {
19607
19497
  className: "!contents"
19608
19498
  }, /*#__PURE__*/React__default.createElement("span", {
19609
19499
  className: className
19610
- }, status === 'saving' ? (/*#__PURE__*/React__default.createElement(Tooltip, {
19500
+ }, status === 'pending' ? (/*#__PURE__*/React__default.createElement(Tooltip, {
19611
19501
  title: texts.table3.editing.saving.progress
19612
19502
  }, /*#__PURE__*/React__default.createElement(Spinner, {
19613
19503
  delay: 0,
@@ -19645,13 +19535,12 @@ function Row$2(props) {
19645
19535
  }
19646
19536
  }
19647
19537
  }, [tableMeta.editing.isEditing, isActiveRow]);
19648
- const rowStatus = tableMeta.editing.getRowStatus(row.id);
19649
19538
  const attributes = {
19650
- 'data-row-editing-invalid': tableMeta.editing.hasRowErrors(row.id) ? !tableMeta.editing.hasRowErrorsShownInAlert(row.id) ? 'unseen' : true : undefined,
19651
- 'data-row-editing-status': rowStatus,
19539
+ 'data-row-editing-invalid': tableMeta.editing.isEnabled && tableMeta.editing.hasRowErrors(row.id) ? !tableMeta.editing.hasRowErrorsSeen(row.id) ? 'unseen' : true : undefined,
19540
+ 'data-row-editing-status': tableMeta.editing.isEnabled && tableMeta.editing.getRowSaveStatus(row.id) ? tableMeta.editing.getRowSaveStatus(row.id) : undefined,
19652
19541
  onFocus: handleFocus
19653
19542
  };
19654
- return /*#__PURE__*/React__default.createElement(DisplayRow, Object.assign({}, props, attributes), rowStatus === 'saving' || rowStatus === 'saved' ? /*#__PURE__*/React__default.createElement(SaveStatus, {
19543
+ return /*#__PURE__*/React__default.createElement(DisplayRow, Object.assign({}, props, attributes), tableMeta.editing.getRowSaveStatus(row.id) ? /*#__PURE__*/React__default.createElement(SaveStatus, {
19655
19544
  rowId: row.id,
19656
19545
  table: table
19657
19546
  }) : null);
@@ -19662,31 +19551,17 @@ const RENDERERS$1 = {
19662
19551
  cell: Cell$5
19663
19552
  };
19664
19553
  function useTable3(props, ref) {
19665
- const editing = useTableEditing(props.enableEditing, props.onEditingSave, props.onEditingChange, props.rowIdentityAccessor, props.validator);
19554
+ const editing = useTableEditing(props.enableEditing, props.onEditingSave, props.onEditingChange, props.validator);
19666
19555
  const creationEnabled = editing.isEnabled && !!props.onEditingCreate;
19667
- // this gives me the performance heeby jeebies, but can't think of a better way to internalise the state
19668
- const data = React__default.useMemo(() => {
19669
- if (editing.isEditing && editing.temporaryRows.length) {
19670
- var _props$data;
19671
- return editing.temporaryRows.concat((_props$data = props.data) !== null && _props$data !== void 0 ? _props$data : []);
19672
- }
19673
- return props.data;
19674
- }, [JSON.stringify(props.data), editing.temporaryRows.length]);
19675
19556
  const extendedProps = {
19676
19557
  ...props,
19677
- data,
19678
19558
  enableRowActions: editing.isEditing ? true : props.enableRowActions,
19679
- rowActions: editing.isEditing ? [(_, rowId, table) => (/*#__PURE__*/React__default.createElement(EditingActionMenu, {
19559
+ rowActions: editing.isEditing ? [(_, rowId) => (/*#__PURE__*/React__default.createElement(EditingActionMenu, {
19680
19560
  hasChanges: editing.hasChanges(rowId),
19681
19561
  hasErrors: editing.hasRowErrors(rowId),
19682
- onDiscard: () => editing.discardChanges(rowId, table),
19683
- onEditingSave: function () {
19684
- try {
19685
- return Promise.resolve(editing.saveChanges(table, rowId)).then(function () {});
19686
- } catch (e) {
19687
- return Promise.reject(e);
19688
- }
19689
- },
19562
+ onClear: () => editing.resetChanges(rowId),
19563
+ onEditingSave: () => editing.saveChanges(rowId),
19564
+ onExit: () => editing.toggleEditing(false),
19690
19565
  isLastRow: !creationEnabled && table.meta.rowActive.rowActiveIndex === table.meta.length - 1
19691
19566
  }))] : props.rowActions
19692
19567
  };
@@ -19698,7 +19573,7 @@ function useTable3(props, ref) {
19698
19573
  useTableEditingListener(table.instance, table.ref);
19699
19574
  React__default.useEffect(() => {
19700
19575
  if (table.ref.current) {
19701
- table.ref.current.instance.toggleEditing = enabled => table.meta.editing.toggleEditing(enabled !== null && enabled !== void 0 ? enabled : editing => !editing, table.instance);
19576
+ table.ref.current.instance.toggleEditing = enabled => table.meta.editing.toggleEditing(enabled !== null && enabled !== void 0 ? enabled : editing => !editing);
19702
19577
  }
19703
19578
  }, [table.ref.current]);
19704
19579
  return table;
@@ -19717,7 +19592,7 @@ function Alert$1(props) {
19717
19592
  const validationTexts = texts.table3.editing.validation;
19718
19593
  const tableMeta = table.options.meta;
19719
19594
  const [showFilterResetDialog, setShowFilterResetDialog] = React__default.useState(false);
19720
- const pendingChangesWithErrors = tableMeta.editing.getErrorsShownInAlert();
19595
+ const pendingChangesWithErrors = tableMeta.editing.getAlertErrors();
19721
19596
  function scrollToRow(rowIndex) {
19722
19597
  tableMeta.rowActive.setRowActiveIndex(rowIndex);
19723
19598
  scrollToIndex(rowIndex, {
@@ -19736,43 +19611,38 @@ function Alert$1(props) {
19736
19611
  const title = (pendingChangesWithErrors.length === 1 ? validationTexts.alert.titleOne : validationTexts.alert.titlePlural).replace('[COUNT]', String(pendingChangesWithErrors.length));
19737
19612
  // generate links to each invalid row, to go into the error message
19738
19613
  const links = [];
19739
- const visibleColumns = table.getVisibleFlatColumns().map(c => c.id);
19740
- const rowIdentityColumn = tableMeta.rowIdentityAccessor && visibleColumns.includes(String(tableMeta.rowIdentityAccessor)) ? table.getColumn(String(tableMeta.rowIdentityAccessor)) : undefined;
19741
- pendingChangesWithErrors.forEach((pendingChangeWithError, index) => {
19614
+ const rowIdentityColumn = tableMeta.rowIdentityColumnId ? table.getColumn(tableMeta.rowIdentityColumnId) : undefined;
19615
+ pendingChangesWithErrors.forEach((error, index) => {
19742
19616
  // if appropriate, concatenate the item with the text "and"
19743
19617
  if (pendingChangesWithErrors.length > 1 && index === pendingChangesWithErrors.length - 1) {
19744
19618
  // Add space before and after `messageAnd` text
19745
19619
  links.push(` ${validationTexts.alert.messageAnd} `);
19746
19620
  }
19747
- const rowIndex = table.getRowModel().rows.findIndex(row => row.id === pendingChangeWithError.rowId);
19621
+ const rowIndex = table.getRowModel().rows.findIndex(row => row.id === error.rowId);
19748
19622
  const handleClick = () => {
19749
- // if row is visible
19750
19623
  if (rowIndex > -1) {
19751
19624
  scrollToRow(rowIndex);
19752
- }
19753
- // if row is filtered out
19754
- else {
19755
- setShowFilterResetDialog(pendingChangeWithError.rowId);
19625
+ } else {
19626
+ setShowFilterResetDialog(error.rowId);
19756
19627
  }
19757
19628
  };
19758
19629
  let tooltip;
19759
- if (pendingChangeWithError.errors.row) {
19760
- tooltip = pendingChangeWithError.errors.row;
19630
+ if (error.pendingChange._meta.errors.row) {
19631
+ tooltip = error.pendingChange._meta.errors.row;
19761
19632
  } else {
19762
19633
  var _table$getAllColumns$, _table$getAllColumns$2;
19763
- const firstCellErrorColumnId = Object.keys(pendingChangeWithError.errors.cells)[0];
19634
+ const firstCellErrorColumnId = Object.keys(error.pendingChange._meta.errors.cells)[0];
19764
19635
  const columnName = (_table$getAllColumns$ = table.getAllColumns().find(column => column.id === firstCellErrorColumnId)) === null || _table$getAllColumns$ === void 0 ? void 0 : (_table$getAllColumns$2 = _table$getAllColumns$.columnDef.meta) === null || _table$getAllColumns$2 === void 0 ? void 0 : _table$getAllColumns$2.header;
19765
- tooltip = `${columnName}: ${pendingChangeWithError.errors.cells[firstCellErrorColumnId]}`;
19636
+ tooltip = `${columnName}: ${error.pendingChange._meta.errors.cells[firstCellErrorColumnId]}`;
19766
19637
  }
19767
- const row = table.getRow(pendingChangeWithError.rowId).original;
19768
19638
  links.push(/*#__PURE__*/React__default.createElement(Tooltip, {
19769
- key: pendingChangeWithError.rowId,
19639
+ key: error.rowId,
19770
19640
  title: tooltip
19771
19641
  }, /*#__PURE__*/React__default.createElement("span", {
19772
19642
  className: "text-blue",
19773
19643
  onClick: handleClick,
19774
19644
  role: "button"
19775
- }, rowIdentityColumn ? row[rowIdentityColumn.id] : rowIndex + 1)));
19645
+ }, rowIdentityColumn ? error.pendingChange._meta.original[rowIdentityColumn.id] : rowIndex + 1)));
19776
19646
  // if appropriate, concatenate the item with the text ","
19777
19647
  if (pendingChangesWithErrors.length > 2 && index < pendingChangesWithErrors.length - 2) {
19778
19648
  links.push(', ');
@@ -19828,6 +19698,89 @@ function FilterResetDialog(props) {
19828
19698
  }, texts.table3.editing.validation.resetFiltersDialog.confirm)))));
19829
19699
  }
19830
19700
 
19701
+ function CreateNewRowButton(props) {
19702
+ const {
19703
+ onEditingCreate,
19704
+ scrollToIndex,
19705
+ table,
19706
+ tableMeta
19707
+ } = props;
19708
+ const {
19709
+ texts
19710
+ } = useLocalization();
19711
+ const rows = table.getCoreRowModel().rows.filter(row => row.original !== undefined);
19712
+ const [rowCreated, setRowCreated] = React__default.useState({
19713
+ rowFinder: undefined
19714
+ });
19715
+ const handleKeyDown = event => {
19716
+ if (!tableMeta.editing.hasChanges() && event.key === 'Tab') {
19717
+ tableMeta.editing.saveChanges();
19718
+ }
19719
+ };
19720
+ const handleCreate = function () {
19721
+ try {
19722
+ if (!onEditingCreate) {
19723
+ return Promise.resolve();
19724
+ }
19725
+ const createdRow = rows.find(row => {
19726
+ var _rowCreated$rowFinder;
19727
+ return rowCreated === null || rowCreated === void 0 ? void 0 : (_rowCreated$rowFinder = rowCreated.rowFinder) === null || _rowCreated$rowFinder === void 0 ? void 0 : _rowCreated$rowFinder.call(rowCreated, row.original);
19728
+ });
19729
+ const _temp = function () {
19730
+ if (createdRow) {
19731
+ return Promise.resolve(tableMeta.editing.saveChanges()).then(function () {
19732
+ if (!tableMeta.editing.hasRowErrors(createdRow.id)) {
19733
+ const rowFinder = onEditingCreate();
19734
+ setRowCreated({
19735
+ rowFinder
19736
+ });
19737
+ }
19738
+ });
19739
+ } else {
19740
+ const rowFinder = onEditingCreate();
19741
+ setRowCreated({
19742
+ rowFinder
19743
+ });
19744
+ }
19745
+ }();
19746
+ return Promise.resolve(_temp && _temp.then ? _temp.then(function () {}) : void 0);
19747
+ } catch (e) {
19748
+ return Promise.reject(e);
19749
+ }
19750
+ };
19751
+ React__default.useEffect(() => {
19752
+ if (typeof (rowCreated === null || rowCreated === void 0 ? void 0 : rowCreated.rowFinder) === 'function') {
19753
+ const createdRow = rows.find(row => {
19754
+ var _rowCreated$rowFinder2;
19755
+ return rowCreated === null || rowCreated === void 0 ? void 0 : (_rowCreated$rowFinder2 = rowCreated.rowFinder) === null || _rowCreated$rowFinder2 === void 0 ? void 0 : _rowCreated$rowFinder2.call(rowCreated, row.original);
19756
+ });
19757
+ if (createdRow) {
19758
+ const rowInTable = table.getRowModel().rows.filter(row => row.original !== undefined).find(row => {
19759
+ var _rowCreated$rowFinder3;
19760
+ return rowCreated === null || rowCreated === void 0 ? void 0 : (_rowCreated$rowFinder3 = rowCreated.rowFinder) === null || _rowCreated$rowFinder3 === void 0 ? void 0 : _rowCreated$rowFinder3.call(rowCreated, row.original);
19761
+ });
19762
+ if (rowInTable) {
19763
+ tableMeta.editing.toggleEditing(true);
19764
+ tableMeta.rowActive.setRowActiveIndex(createdRow.index);
19765
+ scrollToIndex(createdRow.index);
19766
+ requestAnimationFrame(() => animateCreateRow(createdRow.id));
19767
+ }
19768
+ requestAnimationFrame(() => tableMeta.editing.addCreatedRowChangeset(createdRow));
19769
+ }
19770
+ }
19771
+ }, [rowCreated]);
19772
+ return /*#__PURE__*/React__default.createElement("tr", {
19773
+ onClick: handleCreate,
19774
+ className: "border-grey-300 hover:bg-grey-100 group !sticky bottom-10 left-0 z-[21] !block cursor-pointer border-t"
19775
+ }, /*#__PURE__*/React__default.createElement("td", {
19776
+ className: "!border-t-0 !bg-transparent"
19777
+ }, /*#__PURE__*/React__default.createElement(Button$1, {
19778
+ onKeyDown: handleKeyDown,
19779
+ className: "group-hover:bg-grey-200 sticky left-0",
19780
+ appearance: "transparent"
19781
+ }, "+ ", texts.table3.editing.buttons.create.label)));
19782
+ }
19783
+
19831
19784
  function Editing(props) {
19832
19785
  const {
19833
19786
  scrollToIndex,
@@ -19853,191 +19806,21 @@ function Editing(props) {
19853
19806
  (_ref$current = ref.current) === null || _ref$current === void 0 ? void 0 : _ref$current.click();
19854
19807
  });
19855
19808
  const handleChange = enabled => {
19856
- if (enabled && tableMeta.rowActive.rowActiveIndex === undefined) {
19857
- tableMeta.rowActive.setRowActiveIndex(0);
19858
- }
19809
+ tableMeta.editing.toggleEditing(enabled);
19859
19810
  requestAnimationFrame(() => {
19860
19811
  var _tableMeta$rowActive$;
19861
- // wait for an active row to be set so that we don't trigger save
19862
- tableMeta.editing.toggleEditing(enabled, table);
19863
- scrollToIndex((_tableMeta$rowActive$ = tableMeta.rowActive.rowActiveIndex) !== null && _tableMeta$rowActive$ !== void 0 ? _tableMeta$rowActive$ : 0);
19812
+ return scrollToIndex((_tableMeta$rowActive$ = tableMeta.rowActive.rowActiveIndex) !== null && _tableMeta$rowActive$ !== void 0 ? _tableMeta$rowActive$ : 0);
19864
19813
  });
19865
19814
  };
19866
19815
  return /*#__PURE__*/React__default.createElement(Tooltip, {
19867
19816
  title: tooltip
19868
19817
  }, /*#__PURE__*/React__default.createElement(ModeSwitch, {
19869
- "data-table": "editing-toggle",
19870
19818
  checked: tableMeta.editing.isEditing,
19871
19819
  onChange: handleChange,
19872
19820
  ref: ref
19873
19821
  }));
19874
19822
  }
19875
19823
 
19876
- function CreateNewRow(props) {
19877
- var _temporaryRows$0$tabl, _temporaryRows$, _table$getState$colum;
19878
- const {
19879
- buttonRef,
19880
- onEditingCreate: handleEditingCreate,
19881
- table,
19882
- tableMeta
19883
- } = props;
19884
- const {
19885
- texts
19886
- } = useLocalization();
19887
- const temporaryRows = tableMeta.editing.temporaryRows;
19888
- const temporaryRowId = (_temporaryRows$0$tabl = (_temporaryRows$ = temporaryRows[0]) === null || _temporaryRows$ === void 0 ? void 0 : _temporaryRows$[tableMeta.rowIdentityAccessor]) !== null && _temporaryRows$0$tabl !== void 0 ? _temporaryRows$0$tabl : '';
19889
- const isDisabled = !!table.getState().globalFilter || !!((_table$getState$colum = table.getState().columnFilters) !== null && _table$getState$colum !== void 0 && _table$getState$colum.length) || !!temporaryRowId && !!tableMeta.editing.hasRowErrors(temporaryRowId);
19890
- const isSaving = !!temporaryRowId && tableMeta.editing.getRowStatus(temporaryRowId) === 'saving';
19891
- const handleCreate = function (event) {
19892
- try {
19893
- // prevent save being triggered by click outside - TODO: investigate why the button triggers clickoutside
19894
- event === null || event === void 0 ? void 0 : event.stopPropagation();
19895
- if (!handleEditingCreate || isDisabled) {
19896
- return Promise.resolve();
19897
- }
19898
- return Promise.resolve(tableMeta.editing.saveChanges(table)).then(function (saved) {
19899
- if (!saved) {
19900
- return;
19901
- }
19902
- try {
19903
- const changeset = handleEditingCreate();
19904
- if (changeset) {
19905
- // change the row before reating because it triggers a save
19906
- // saving would trigger the validation flow and immediately make the row red
19907
- tableMeta.rowActive.setRowActiveIndex(-1);
19908
- requestAnimationFrame(function () {
19909
- try {
19910
- tableMeta.editing.toggleEditing(true, table);
19911
- return Promise.resolve(tableMeta.editing.createRow(changeset)).then(function (rowId) {
19912
- tableMeta.editing.setLastFocusedCellIndex(0);
19913
- try {
19914
- const row = table.getRow(rowId);
19915
- row.pin('bottom');
19916
- } catch {
19917
- //
19918
- }
19919
- });
19920
- } catch (e) {
19921
- return Promise.reject(e);
19922
- }
19923
- });
19924
- }
19925
- } catch (error) {
19926
- console.error(error);
19927
- }
19928
- });
19929
- } catch (e) {
19930
- return Promise.reject(e);
19931
- }
19932
- };
19933
- let tooltip;
19934
- if (isSaving) {
19935
- tooltip = texts.table3.editing.buttons.create.saving;
19936
- } else if (isDisabled) {
19937
- tooltip = texts.table3.editing.buttons.create.disabled;
19938
- }
19939
- return /*#__PURE__*/React__default.createElement("tr", {
19940
- "data-row-create": true,
19941
- className: "border-grey-300 group/row",
19942
- tabIndex: -1
19943
- }, /*#__PURE__*/React__default.createElement("td", {
19944
- className: "!bg-grey-50 col-span-full !border-b-0 !px-1"
19945
- }, /*#__PURE__*/React__default.createElement(Button$1, {
19946
- appearance: "transparent",
19947
- className: "group-hover:bg-grey-200 sticky left-[4px]",
19948
- disabled: isDisabled,
19949
- onClick: handleCreate,
19950
- ref: buttonRef,
19951
- tooltip: tooltip
19952
- }, /*#__PURE__*/React__default.createElement(Icon, {
19953
- name: "circle-plus"
19954
- }), texts.table3.editing.buttons.create.label)));
19955
- }
19956
-
19957
- function TemporaryRow(props) {
19958
- var _tableRef$current, _tableRef$current2;
19959
- const {
19960
- buttonRef,
19961
- rowIdentityAccessor,
19962
- table,
19963
- tableMeta,
19964
- tableRef
19965
- } = props;
19966
- const temporaryRows = tableMeta.editing.temporaryRows;
19967
- // discard new row
19968
- const [showDiscardDialog, setShowDiscardDialog] = React__default.useState(false);
19969
- function handleDiscard() {
19970
- if (temporaryRows[0]) {
19971
- var _buttonRef$current;
19972
- tableMeta.editing.discardChanges(temporaryRows[0][rowIdentityAccessor], table);
19973
- (_buttonRef$current = buttonRef.current) === null || _buttonRef$current === void 0 ? void 0 : _buttonRef$current.focus();
19974
- }
19975
- }
19976
- const handleKeyDown = function (event) {
19977
- try {
19978
- const _temp2 = function () {
19979
- if (event.key === 'ArrowDown') {
19980
- event.preventDefault();
19981
- const _temp = function () {
19982
- if (!isElementTriggeredFromContainer(event.target, event.currentTarget)) {
19983
- return Promise.resolve(tableMeta.editing.saveChanges(table)).then(function (saved) {
19984
- if (saved) {
19985
- var _buttonRef$current2;
19986
- (_buttonRef$current2 = buttonRef.current) === null || _buttonRef$current2 === void 0 ? void 0 : _buttonRef$current2.focus();
19987
- }
19988
- });
19989
- }
19990
- }();
19991
- if (_temp && _temp.then) return _temp.then(function () {});
19992
- } else if (event.key === 'ArrowUp') {
19993
- event.preventDefault();
19994
- event.stopPropagation();
19995
- }
19996
- }();
19997
- return Promise.resolve(_temp2 && _temp2.then ? _temp2.then(function () {}) : void 0);
19998
- } catch (e) {
19999
- return Promise.reject(e);
20000
- }
20001
- };
20002
- const handleKeyDownCapture = event => {
20003
- if (event.key === 'Escape') {
20004
- event.preventDefault();
20005
- event.stopPropagation();
20006
- setShowDiscardDialog(true);
20007
- } else if (event.key === 'ArrowLeft' && tableMeta.editing.lastFocusedCellIndex === 0) {
20008
- event.preventDefault();
20009
- event.stopPropagation();
20010
- } else if (event.key === 'ArrowRight' && tableMeta.editing.lastFocusedCellIndex) {
20011
- if (tableMeta.editing.lastFocusedCellIndex === table.getVisibleFlatColumns().length - 1) {
20012
- event.preventDefault();
20013
- event.stopPropagation();
20014
- }
20015
- }
20016
- };
20017
- const isScrolled = tableRef.current ? ((_tableRef$current = tableRef.current) === null || _tableRef$current === void 0 ? void 0 : _tableRef$current.scrollHeight) > ((_tableRef$current2 = tableRef.current) === null || _tableRef$current2 === void 0 ? void 0 : _tableRef$current2.clientHeight) : false;
20018
- const className = cn('group/row border-grey-300 !sticky z-[21]', {
20019
- 'bottom-20': tableMeta.footer.isEnabled,
20020
- 'bottom-10': !tableMeta.footer.isEnabled,
20021
- 'border-b border-t-2 shadow-[0px_-5px_20px_0px_rgba(0,0,0,0.1)] border-t-grey-500/[0.5]': isScrolled
20022
- });
20023
- return /*#__PURE__*/React__default.createElement(React__default.Fragment, null, table.getBottomRows().map(row => (/*#__PURE__*/React__default.createElement(Row, {
20024
- key: row.id,
20025
- cellRenderer: RENDERERS$1.cell,
20026
- index: -1,
20027
- measureRow: () => null,
20028
- renderer: RENDERERS$1.row,
20029
- row: row,
20030
- table: table,
20031
- className: className,
20032
- onKeyDown: handleKeyDown,
20033
- onKeyDownCapture: handleKeyDownCapture
20034
- }))), /*#__PURE__*/React__default.createElement(DiscardChangesConfirmationDialog, {
20035
- open: showDiscardDialog,
20036
- onChange: setShowDiscardDialog,
20037
- onDiscard: handleDiscard
20038
- }));
20039
- }
20040
-
20041
19824
  function Column$3(_) {
20042
19825
  return null;
20043
19826
  }
@@ -20049,23 +19832,12 @@ Group$5.displayName = 'Table3Group';
20049
19832
  const BaseTable3 = /*#__PURE__*/fixedForwardRef(function BaseTable3(props, ref) {
20050
19833
  var _table3$meta$editing, _table3$meta$editing2;
20051
19834
  const table3 = useTable3(props, ref);
20052
- const buttonRef = React__default.useRef(null);
20053
19835
  const gridAttributes = {
20054
19836
  'data-table-editing-mode': (_table3$meta$editing = table3.meta.editing) !== null && _table3$meta$editing !== void 0 && _table3$meta$editing.isEditing ? (_table3$meta$editing2 = table3.meta.editing) !== null && _table3$meta$editing2 !== void 0 && _table3$meta$editing2.isDetailedMode ? 'detailed' : 'normal' : undefined,
20055
19837
  enableHorizontalArrowKeyNavigation: table3.meta.editing.isEditing
20056
19838
  };
20057
- const hasAlertErrors = table3.meta.editing.isEditing && table3.meta.editing.getErrorsShownInAlert().length;
20058
- const hasCreateWorkflow = table3.meta.editing.isEnabled && props.onEditingCreate;
20059
- let footerRows;
20060
- if (table3.meta.editing.isEnabled && props.onEditingCreate) {
20061
- footerRows = /*#__PURE__*/React__default.createElement(React__default.Fragment, null, /*#__PURE__*/React__default.createElement(CreateNewRow, {
20062
- buttonRef: buttonRef,
20063
- onEditingCreate: props.onEditingCreate,
20064
- table: table3.instance,
20065
- tableMeta: table3.meta,
20066
- tableRef: table3.ref
20067
- }));
20068
- }
19839
+ const hasAlertErrors = table3.meta.editing.hasAlertErrors();
19840
+ const showCreateRowButton = table3.meta.editing.isEnabled && props.onEditingCreate;
20069
19841
  return /*#__PURE__*/React__default.createElement(Table, null, /*#__PURE__*/React__default.createElement(Table.Toolbar, {
20070
19842
  table: table3
20071
19843
  }, table3.meta.editing.isEnabled ? (/*#__PURE__*/React__default.createElement(Editing, {
@@ -20078,15 +19850,13 @@ const BaseTable3 = /*#__PURE__*/fixedForwardRef(function BaseTable3(props, ref)
20078
19850
  tableRef: table3.ref
20079
19851
  })) : null, /*#__PURE__*/React__default.createElement(Table.Grid, Object.assign({}, gridAttributes, {
20080
19852
  "data-taco": "table3",
20081
- rowsForFooter: footerRows,
20082
19853
  table: table3
20083
- }), hasCreateWorkflow ? (/*#__PURE__*/React__default.createElement(TemporaryRow, {
20084
- buttonRef: buttonRef,
20085
- rowIdentityAccessor: props.rowIdentityAccessor,
19854
+ }), showCreateRowButton && (/*#__PURE__*/React__default.createElement(CreateNewRowButton, {
20086
19855
  table: table3.instance,
20087
19856
  tableMeta: table3.meta,
20088
- tableRef: table3.ref
20089
- })) : null));
19857
+ onEditingCreate: props.onEditingCreate,
19858
+ scrollToIndex: table3.renderer.scrollToIndex
19859
+ }))));
20090
19860
  });
20091
19861
  const Table3 = /*#__PURE__*/fixedForwardRef(function Table3(props, ref) {
20092
19862
  const stringifiedChildren = String(props.children);