@economic/taco 2.48.2 → 2.48.4

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
Files changed (37) hide show
  1. package/dist/components/Calendar/Calendar.d.ts +0 -1
  2. package/dist/esm/packages/taco/src/components/Calendar/Calendar.js +10 -11
  3. package/dist/esm/packages/taco/src/components/Calendar/Calendar.js.map +1 -1
  4. package/dist/esm/packages/taco/src/components/Datepicker/useDatepicker.js +6 -13
  5. package/dist/esm/packages/taco/src/components/Datepicker/useDatepicker.js.map +1 -1
  6. package/dist/esm/packages/taco/src/components/Menu/components/Content.js +6 -1
  7. package/dist/esm/packages/taco/src/components/Menu/components/Content.js.map +1 -1
  8. package/dist/esm/packages/taco/src/components/Table3/components/Columns/Cell/EditingControlCell.js +6 -6
  9. package/dist/esm/packages/taco/src/components/Table3/components/Columns/Cell/EditingControlCell.js.map +1 -1
  10. package/dist/esm/packages/taco/src/hooks/useGlobalKeyDown.js +2 -2
  11. package/dist/esm/packages/taco/src/hooks/useGlobalKeyDown.js.map +1 -1
  12. package/dist/esm/packages/taco/src/index.js +1 -1
  13. package/dist/esm/packages/taco/src/primitives/Button.js +6 -1
  14. package/dist/esm/packages/taco/src/primitives/Button.js.map +1 -1
  15. package/dist/esm/packages/taco/src/primitives/Table/Core/components/Columns/Internal/Selection.js +1 -2
  16. package/dist/esm/packages/taco/src/primitives/Table/Core/components/Columns/Internal/Selection.js.map +1 -1
  17. package/dist/esm/packages/taco/src/primitives/Table/Core/components/Toolbar/components/Search/Search.js +1 -2
  18. package/dist/esm/packages/taco/src/primitives/Table/Core/components/Toolbar/components/Search/Search.js.map +1 -1
  19. package/dist/esm/packages/taco/src/primitives/Table/types.js +1 -7
  20. package/dist/esm/packages/taco/src/primitives/Table/types.js.map +1 -1
  21. package/dist/esm/packages/taco/src/primitives/Table/useTableManager/features/useTableServerLoading.js +12 -8
  22. package/dist/esm/packages/taco/src/primitives/Table/useTableManager/features/useTableServerLoading.js.map +1 -1
  23. package/dist/esm/packages/taco/src/primitives/Table/useTableManager/listeners/useTableSearchListener.js +1 -1
  24. package/dist/esm/packages/taco/src/primitives/Table/useTableManager/listeners/useTableSearchListener.js.map +1 -1
  25. package/dist/esm/packages/taco/src/primitives/Table/useTableManager/useTableManager.js +1 -1
  26. package/dist/esm/packages/taco/src/primitives/Table/useTableManager/useTableManager.js.map +1 -1
  27. package/dist/esm/packages/taco/src/utils/keyboard.js +2 -5
  28. package/dist/esm/packages/taco/src/utils/keyboard.js.map +1 -1
  29. package/dist/hooks/useGlobalKeyDown.d.ts +1 -1
  30. package/dist/primitives/Table/types.d.ts +0 -5
  31. package/dist/primitives/Table/useTableManager/features/useTableServerLoading.d.ts +3 -3
  32. package/dist/taco.cjs.development.js +54 -55
  33. package/dist/taco.cjs.development.js.map +1 -1
  34. package/dist/taco.cjs.production.min.js +1 -1
  35. package/dist/taco.cjs.production.min.js.map +1 -1
  36. package/dist/utils/keyboard.d.ts +1 -1
  37. package/package.json +2 -2
@@ -4395,12 +4395,9 @@ function shouldTriggerShortcut(event, key) {
4395
4395
  }
4396
4396
  return event.key.toLowerCase() === keyOptions.key.toLowerCase();
4397
4397
  }
4398
- function createShortcutKeyDownHandler(key, handler, stopPropagation = true, element) {
4398
+ function createShortcutKeyDownHandler(key, handler, stopPropagation = true) {
4399
4399
  return function (event) {
4400
- const dialog = document.querySelector('[role="dialog"]');
4401
- const isOutsideDialog = element && dialog && !dialog.contains(element);
4402
- if (event.target !== event.currentTarget && isElementInteractive(event.target) && !isPressingMetaKey(event) || isOutsideDialog // Avoid triggering shortcut if dialog is open and element is outside the dialog
4403
- ) {
4400
+ if (event.target !== event.currentTarget && isElementInteractive(event.target) && !isPressingMetaKey(event)) {
4404
4401
  return;
4405
4402
  }
4406
4403
  const condition = shouldTriggerShortcut(event, key);
@@ -4421,11 +4418,11 @@ const isMacOs = () => {
4421
4418
  return (_window = window) === null || _window === void 0 ? void 0 : _window.navigator.userAgent.includes('Mac');
4422
4419
  };
4423
4420
 
4424
- const useGlobalKeyDown = (shortcut, handler, element) => {
4421
+ const useGlobalKeyDown = (shortcut, handler) => {
4425
4422
  React__default.useEffect(() => {
4426
4423
  let handleKeyDown;
4427
4424
  if (shortcut) {
4428
- handleKeyDown = createShortcutKeyDownHandler(shortcut, handler, false, element);
4425
+ handleKeyDown = createShortcutKeyDownHandler(shortcut, handler, false);
4429
4426
  document.addEventListener('keydown', handleKeyDown);
4430
4427
  }
4431
4428
  return () => {
@@ -4448,8 +4445,13 @@ const Button = /*#__PURE__*/React.forwardRef(function Button(props, ref) {
4448
4445
  useGlobalKeyDown(shortcut, event => {
4449
4446
  var _internalRef$current;
4450
4447
  event === null || event === void 0 ? void 0 : event.preventDefault();
4448
+ const dialog = document.querySelector('[role="dialog"]');
4449
+ // Don't trigger the click on the button if it is outside of the dialog
4450
+ if (dialog && !(dialog !== null && dialog !== void 0 && dialog.contains(internalRef.current))) {
4451
+ return;
4452
+ }
4451
4453
  (_internalRef$current = internalRef.current) === null || _internalRef$current === void 0 ? void 0 : _internalRef$current.click();
4452
- }, internalRef.current);
4454
+ });
4453
4455
  const Tag = props.href ? 'a' : 'button';
4454
4456
  return /*#__PURE__*/React.createElement(Tag, Object.assign({}, otherProps, {
4455
4457
  href: disabled ? undefined : props.href,
@@ -5100,23 +5102,22 @@ const TodayButton = ({
5100
5102
  }, texts.calendar.actions.today);
5101
5103
  };
5102
5104
  const Calendar$1 = props => {
5103
- var _ref;
5104
5105
  const {
5105
5106
  onChange: handleChange,
5106
5107
  value,
5107
5108
  disabledDays,
5108
- visibleMonth,
5109
5109
  ...otherProps
5110
5110
  } = props;
5111
- const [internalVisibleMonth, setInternalVisibleMonth] = React.useState((_ref = visibleMonth !== null && visibleMonth !== void 0 ? visibleMonth : value) !== null && _ref !== void 0 ? _ref : new Date());
5111
+ const [visibleMonth, setVisibleMonth] = React.useState(value !== null && value !== void 0 ? value : new Date());
5112
5112
  const {
5113
5113
  texts
5114
5114
  } = useLocalization();
5115
5115
  React.useEffect(() => {
5116
- if (visibleMonth && visibleMonth !== internalVisibleMonth) {
5117
- setInternalVisibleMonth(visibleMonth);
5116
+ if (visibleMonth !== value) {
5117
+ setVisibleMonth(value !== null && value !== void 0 ? value : new Date());
5118
5118
  }
5119
- }, [visibleMonth]);
5119
+ // visibleMonth in deps array breaking month switching logic. It should not be in deps array.
5120
+ }, [value]);
5120
5121
  const handleDayClick = (date, modifiers, event) => {
5121
5122
  if (modifiers.outside || modifiers.disabled) {
5122
5123
  return;
@@ -5130,13 +5131,13 @@ const Calendar$1 = props => {
5130
5131
  className: className,
5131
5132
  captionLayout: "dropdown-buttons",
5132
5133
  weekStartsOn: 1,
5133
- month: internalVisibleMonth,
5134
+ month: visibleMonth,
5134
5135
  numberOfMonths: 1,
5135
5136
  components: {
5136
- Caption: props => (/*#__PURE__*/React.createElement(Navbar, Object.assign({}, props, {
5137
- onMonthChange: setInternalVisibleMonth,
5138
- value: internalVisibleMonth
5139
- }))),
5137
+ Caption: props => /*#__PURE__*/React.createElement(Navbar, Object.assign({}, props, {
5138
+ onMonthChange: setVisibleMonth,
5139
+ value: visibleMonth
5140
+ })),
5140
5141
  Footer: () => (/*#__PURE__*/React.createElement("tfoot", null, /*#__PURE__*/React.createElement("tr", null, /*#__PURE__*/React.createElement("td", {
5141
5142
  colSpan: 7,
5142
5143
  className: "text-center"
@@ -6391,18 +6392,14 @@ const useDatepicker = ({
6391
6392
  } = useLocalization();
6392
6393
  const [internalValue, setInternalValue] = React.useState((_format = format(value, formatting.date)) !== null && _format !== void 0 ? _format : '');
6393
6394
  const originalValueAsDate = parse(value);
6394
- // Track the current view date (month/year) in the calendar
6395
- const [calendarViewDate, setCalendarViewDate] = React.useState(originalValueAsDate || new Date());
6395
+ // update internal value if it changed 'externally'
6396
6396
  React.useEffect(() => {
6397
- // Only update the internal value when the input is not focused
6398
- // This prevents the input value from being reset while user is typing
6399
- if (inputRef.current !== document.activeElement) {
6400
- const formattedValue = format(value, formatting.date);
6401
- if (formattedValue !== internalValue) {
6402
- setInternalValue(formattedValue !== null && formattedValue !== void 0 ? formattedValue : '');
6403
- }
6397
+ const formattedValue = format(value, formatting.date);
6398
+ if (formattedValue !== internalValue) {
6399
+ setInternalValue(formattedValue !== null && formattedValue !== void 0 ? formattedValue : '');
6404
6400
  }
6405
6401
  }, [value]);
6402
+ // event handlers
6406
6403
  const handleInputBlur = event => {
6407
6404
  event.persist();
6408
6405
  const valueAsDate = parseFromCustomString(event.target.value, 'dd.mm.yy', originalValueAsDate === null || originalValueAsDate === void 0 ? void 0 : originalValueAsDate.getMonth(), originalValueAsDate === null || originalValueAsDate === void 0 ? void 0 : originalValueAsDate.getFullYear());
@@ -6423,8 +6420,6 @@ const useDatepicker = ({
6423
6420
  setInternalValue(event.target.value);
6424
6421
  };
6425
6422
  const handleChange = date => {
6426
- // Update both the input value and calendar view date when selecting a date
6427
- setCalendarViewDate(date);
6428
6423
  setInputValueByRef(inputRef.current, format(date, formatting.date), 'focusout');
6429
6424
  };
6430
6425
  const handleKeyDown = event => {
@@ -6450,8 +6445,7 @@ const useDatepicker = ({
6450
6445
  const calendarProps = {
6451
6446
  ...calendar,
6452
6447
  onChange: handleChange,
6453
- value: originalValueAsDate,
6454
- visibleMonth: calendarViewDate
6448
+ value: originalValueAsDate
6455
6449
  };
6456
6450
  return {
6457
6451
  input: inputProps,
@@ -8335,12 +8329,17 @@ const Content$8 = /*#__PURE__*/React.forwardRef(function MenuContent(props, ref)
8335
8329
  if (child.props.shortcut) {
8336
8330
  shortcuts.push(createShortcutKeyDownHandler(child.props.shortcut, event => {
8337
8331
  event.preventDefault();
8332
+ const dialog = document.querySelector('[role="dialog"]');
8333
+ // Don't trigger the shortcut if it is outside of the dialog
8334
+ if (dialog && !(dialog !== null && dialog !== void 0 && dialog.contains(internalRef.current))) {
8335
+ return;
8336
+ }
8338
8337
  menu === null || menu === void 0 ? void 0 : menu.open();
8339
8338
  setTimeout(() => {
8340
8339
  var _childrenRefs$current, _childrenRefs$current2;
8341
8340
  return (_childrenRefs$current = childrenRefs.current[index]) === null || _childrenRefs$current === void 0 ? void 0 : (_childrenRefs$current2 = _childrenRefs$current.current) === null || _childrenRefs$current2 === void 0 ? void 0 : _childrenRefs$current2.click();
8342
8341
  }, 1);
8343
- }, true, childrenRefs.current[index].current));
8342
+ }));
8344
8343
  }
8345
8344
  });
8346
8345
  shortcuts.forEach(handler => document.addEventListener('keydown', handler));
@@ -9949,11 +9948,6 @@ const fixedForwardRef = React__default.forwardRef;
9949
9948
  TableFilterComparator[TableFilterComparator["HasAllOf"] = 12] = "HasAllOf";
9950
9949
  TableFilterComparator[TableFilterComparator["HasNoneOf"] = 13] = "HasNoneOf";
9951
9950
  })(exports.TableFilterComparator || (exports.TableFilterComparator = {}));
9952
- (function (TableServerLoadAllState) {
9953
- TableServerLoadAllState[TableServerLoadAllState["Incomplete"] = 0] = "Incomplete";
9954
- TableServerLoadAllState[TableServerLoadAllState["Loading"] = 1] = "Loading";
9955
- TableServerLoadAllState[TableServerLoadAllState["Completed"] = 2] = "Completed";
9956
- })(exports.TableServerLoadAllState || (exports.TableServerLoadAllState = {}));
9957
9951
 
9958
9952
  const dataTypes = {
9959
9953
  auto: {
@@ -11496,10 +11490,16 @@ function useTableDataLoader(fetchPage, fetchAll, options = {
11496
11490
  }, invalidate];
11497
11491
  }
11498
11492
 
11499
- function useTableServerLoading(loadPage, loadAll, pageSize = DEFAULT_PAGE_SIZE) {
11493
+ function useTableServerLoading(length, data, loadPage, loadAll, pageSize = DEFAULT_PAGE_SIZE) {
11500
11494
  const isEnabled = !!loadPage && !!loadAll;
11501
11495
  const [isReady, setReady] = React__default.useState(false);
11502
- const [loadAllStatus, setLoadedStatus] = React__default.useState(exports.TableServerLoadAllState.Incomplete);
11496
+ const [loading, setLoading] = React__default.useState(false);
11497
+ const hasLoadedAll = React__default.useMemo(() => {
11498
+ if (data.length !== length || data.some(x => x === undefined)) {
11499
+ return false;
11500
+ }
11501
+ return true;
11502
+ }, [data, length]);
11503
11503
  let _loadPage;
11504
11504
  let _loadAll;
11505
11505
  let _loadAllIfNeeded;
@@ -11509,7 +11509,6 @@ function useTableServerLoading(loadPage, loadAll, pageSize = DEFAULT_PAGE_SIZE)
11509
11509
  const _temp = function () {
11510
11510
  if (typeof loadPage === 'function') {
11511
11511
  return Promise.resolve(loadPage(...args)).then(function () {
11512
- setLoadedStatus(exports.TableServerLoadAllState.Incomplete);
11513
11512
  setReady(true);
11514
11513
  });
11515
11514
  }
@@ -11525,9 +11524,9 @@ function useTableServerLoading(loadPage, loadAll, pageSize = DEFAULT_PAGE_SIZE)
11525
11524
  try {
11526
11525
  const _temp2 = function () {
11527
11526
  if (typeof loadAll === 'function') {
11528
- setLoadedStatus(exports.TableServerLoadAllState.Loading);
11527
+ setLoading(true);
11529
11528
  return Promise.resolve(loadAll(...args)).then(function () {
11530
- setLoadedStatus(exports.TableServerLoadAllState.Completed);
11529
+ setLoading(false);
11531
11530
  setReady(true);
11532
11531
  });
11533
11532
  }
@@ -11540,7 +11539,7 @@ function useTableServerLoading(loadPage, loadAll, pageSize = DEFAULT_PAGE_SIZE)
11540
11539
  _loadAllIfNeeded = function (...args) {
11541
11540
  try {
11542
11541
  const _temp3 = function () {
11543
- if (loadAllStatus === exports.TableServerLoadAllState.Incomplete) {
11542
+ if (!hasLoadedAll) {
11544
11543
  var _loadAll2;
11545
11544
  return Promise.resolve((_loadAll2 = _loadAll) === null || _loadAll2 === void 0 ? void 0 : _loadAll2(...args)).then(function () {});
11546
11545
  }
@@ -11557,7 +11556,7 @@ function useTableServerLoading(loadPage, loadAll, pageSize = DEFAULT_PAGE_SIZE)
11557
11556
  loadPage: _loadPage,
11558
11557
  loadAll: _loadAll,
11559
11558
  loadAllIfNeeded: _loadAllIfNeeded,
11560
- loadAllStatus,
11559
+ loading,
11561
11560
  pageSize
11562
11561
  };
11563
11562
  }
@@ -11752,7 +11751,7 @@ function useTableSearchListener(table, onChangeSearch) {
11752
11751
  onChangeSearch(query);
11753
11752
  }
11754
11753
  }
11755
- }, [meta.server.loadAllStatus, meta.search.isEnabled, meta.search.enableGlobalFilter, table.getRowModel().rows.length, table.getState().globalFilter, JSON.stringify(table.getState().sorting), onChangeSearch]);
11754
+ }, [meta.server.loading, meta.search.isEnabled, meta.search.enableGlobalFilter, table.getRowModel().rows.length, table.getState().globalFilter, JSON.stringify(table.getState().sorting), onChangeSearch]);
11756
11755
  }
11757
11756
 
11758
11757
  function useTableSettingsListener(table, onChangeSettings) {
@@ -11894,7 +11893,7 @@ function useTableManager(props, meta, internalColumns) {
11894
11893
  const rowHeight = useTableRowHeight(options.enableRowHeight, settings.rowHeight);
11895
11894
  const rowSelection = useTableRowSelection(!!options.enableRowSelection);
11896
11895
  const search = useTableSearch(options.enableSearch, settings.excludeUnmatchedRecordsInSearch);
11897
- const server = useTableServerLoading(props.loadPage, props.loadAll, props.pageSize);
11896
+ const server = useTableServerLoading(length, data, props.loadPage, props.loadAll, props.pageSize);
11898
11897
  // TODO: memoise
11899
11898
  // convert jsx column components into valid table columns
11900
11899
  const {
@@ -12732,7 +12731,7 @@ function Header$4(context) {
12732
12731
  className: "hover:border-blue !-mt-px",
12733
12732
  checked: isAllRowsSelected,
12734
12733
  indeterminate: isSomeRowsSelected && !isAllRowsSelected,
12735
- loading: tableMeta.server.loadAllStatus === exports.TableServerLoadAllState.Loading,
12734
+ loading: tableMeta.server.loading,
12736
12735
  onChange: handleChange
12737
12736
  }));
12738
12737
  }
@@ -14291,7 +14290,7 @@ function Search$1(props) {
14291
14290
  return /*#__PURE__*/React__default.createElement(React__default.Fragment, null, /*#__PURE__*/React__default.createElement(SearchInput2, {
14292
14291
  findCurrent: tableMeta.search.currentHighlightColumnIndex !== undefined ? tableMeta.search.currentHighlightColumnIndex + 1 : null,
14293
14292
  findTotal: (_tableMeta$search$hig = (_tableMeta$search$hig2 = tableMeta.search.highlightedColumnIndexes) === null || _tableMeta$search$hig2 === void 0 ? void 0 : _tableMeta$search$hig2.length) !== null && _tableMeta$search$hig !== void 0 ? _tableMeta$search$hig : null,
14294
- loading: tableMeta.server.loadAllStatus === exports.TableServerLoadAllState.Loading,
14293
+ loading: tableMeta.server.loading,
14295
14294
  name: "table-search",
14296
14295
  onClickFindPrevious: handlePreviousResult,
14297
14296
  onClickFindNext: handleNextResult,
@@ -19644,24 +19643,24 @@ function EditingControlCell(props) {
19644
19643
  var _cellRef$current;
19645
19644
  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"]'));
19646
19645
  }, [cellRef.current]);
19647
- const handleChange = nextValue => {
19646
+ const handleChange = React__default.useCallback(nextValue => {
19648
19647
  if (nextValue !== value) {
19649
19648
  tableMeta.editing.setCellValue(cell, nextValue);
19650
19649
  if (hasNonTextControl) {
19651
19650
  requestAnimationFrame(() => tableMeta.editing.onCellChanged(cell, rowIndex, nextValue));
19652
19651
  }
19653
19652
  }
19654
- };
19655
- function blur() {
19653
+ }, [hasNonTextControl, cell.row.id, cell.column.id, cell.row.original, rowIndex, value]);
19654
+ const blur = React__default.useCallback(function blur() {
19656
19655
  tableMeta.editing.toggleDetailedMode(false);
19657
19656
  tableMeta.editing.onCellChanged(cell, rowIndex, undefined, !hasNonTextControl);
19658
- }
19659
- const handleBlur = event => {
19657
+ }, [hasNonTextControl, cell.row.id, cell.column.id, cell.row.original, rowIndex]);
19658
+ const handleBlur = React__default.useCallback(event => {
19660
19659
  if (isElementInsideOrTriggeredFromContainer(event.relatedTarget, event.currentTarget)) {
19661
19660
  return;
19662
19661
  }
19663
19662
  blur();
19664
- };
19663
+ }, [blur]);
19665
19664
  // ensure that blur runs when the cell gets unmounted (when vertically arrow key navigating)
19666
19665
  React__default.useEffect(() => {
19667
19666
  const ref = cellRef.current;