@economic/taco 2.1.2 → 2.2.0

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 (29) hide show
  1. package/dist/components/Provider/Localization.d.ts +7 -0
  2. package/dist/components/Table3/components/toolbar/PrintButton/WarningDialog.d.ts +8 -0
  3. package/dist/components/Table3/hooks/features/usePrinting.d.ts +4 -1
  4. package/dist/components/Table3/types.d.ts +8 -0
  5. package/dist/esm/packages/taco/src/components/Provider/Localization.js +8 -1
  6. package/dist/esm/packages/taco/src/components/Provider/Localization.js.map +1 -1
  7. package/dist/esm/packages/taco/src/components/SearchInput2/SearchInput2.js +3 -1
  8. package/dist/esm/packages/taco/src/components/SearchInput2/SearchInput2.js.map +1 -1
  9. package/dist/esm/packages/taco/src/components/Table3/components/toolbar/PrintButton/PrintButton.js +48 -6
  10. package/dist/esm/packages/taco/src/components/Table3/components/toolbar/PrintButton/PrintButton.js.map +1 -1
  11. package/dist/esm/packages/taco/src/components/Table3/components/toolbar/PrintButton/WarningDialog.js +56 -0
  12. package/dist/esm/packages/taco/src/components/Table3/components/toolbar/PrintButton/WarningDialog.js.map +1 -0
  13. package/dist/esm/packages/taco/src/components/Table3/components/toolbar/PrintButton/hooks/useParentStylesheets.js +2 -2
  14. package/dist/esm/packages/taco/src/components/Table3/components/toolbar/PrintButton/hooks/useParentStylesheets.js.map +1 -1
  15. package/dist/esm/packages/taco/src/components/Table3/hooks/features/usePrinting.js +7 -2
  16. package/dist/esm/packages/taco/src/components/Table3/hooks/features/usePrinting.js.map +1 -1
  17. package/dist/esm/packages/taco/src/components/Table3/hooks/listeners/useSettingsStateListener.js +2 -1
  18. package/dist/esm/packages/taco/src/components/Table3/hooks/listeners/useSettingsStateListener.js.map +1 -1
  19. package/dist/esm/packages/taco/src/components/Table3/hooks/useTable.js +9 -9
  20. package/dist/esm/packages/taco/src/components/Table3/hooks/useTable.js.map +1 -1
  21. package/dist/esm/packages/taco/src/components/Table3/types.js.map +1 -1
  22. package/dist/esm/packages/taco/src/utils/keyboard.js +11 -11
  23. package/dist/esm/packages/taco/src/utils/keyboard.js.map +1 -1
  24. package/dist/taco.cjs.development.js +133 -33
  25. package/dist/taco.cjs.development.js.map +1 -1
  26. package/dist/taco.cjs.production.min.js +1 -1
  27. package/dist/taco.cjs.production.min.js.map +1 -1
  28. package/package.json +2 -2
  29. package/types.json +6076 -5318
@@ -3710,21 +3710,21 @@ const useMergedRef = ref => {
3710
3710
  const WHITELISTED_ELEMENTS = ['INPUT', 'TEXTAREA', 'SELECT'];
3711
3711
  function createShortcutKeyDownHandler(key, handler) {
3712
3712
  return function (event) {
3713
- let condition = false;
3713
+ const keyOptions = typeof key === 'string' ? {
3714
+ key,
3715
+ meta: false,
3716
+ shift: false
3717
+ } : key;
3714
3718
  if (event.target !== event.currentTarget && WHITELISTED_ELEMENTS.includes(event.target.tagName)) {
3715
3719
  return;
3716
3720
  }
3717
- if (typeof key === 'string') {
3718
- condition = event.key.toLowerCase() === key.toLowerCase();
3719
- } else {
3720
- if (key.meta && (isMacOs() ? !event.metaKey : !event.ctrlKey) || !key.meta && (isMacOs() ? event.metaKey : event.ctrlKey)) {
3721
- return;
3722
- }
3723
- if (key.shift && !event.shiftKey || key.shift === false && event.shiftKey) {
3724
- return;
3725
- }
3726
- condition = event.key.toLowerCase() === key.key.toLowerCase();
3721
+ if (keyOptions.meta && (isMacOs() ? !event.metaKey : !event.ctrlKey) || !keyOptions.meta && (isMacOs() ? event.metaKey : event.ctrlKey)) {
3722
+ return;
3727
3723
  }
3724
+ if (keyOptions.shift && !event.shiftKey || keyOptions.shift === false && event.shiftKey) {
3725
+ return;
3726
+ }
3727
+ const condition = event.key.toLowerCase() === keyOptions.key.toLowerCase();
3728
3728
  if (condition) {
3729
3729
  var _event$stopImmediateP;
3730
3730
  // stops react handlers bubbling up to global
@@ -4210,7 +4210,14 @@ const defaultLocalisationTexts = {
4210
4210
  print: {
4211
4211
  error: 'An error occurred while creating a print preview',
4212
4212
  loading: 'Creating a print preview',
4213
- tooltip: 'Print'
4213
+ tooltip: 'Print',
4214
+ warningDialog: {
4215
+ title: 'Extra loading time',
4216
+ description: 'Please note that printing a large amount of data may result in a slightly longer waiting time due to data loading.',
4217
+ checkboxVisibilityLabel: "Don't show again",
4218
+ cancelButtonText: 'Cancel',
4219
+ printButtonText: 'Print'
4220
+ }
4214
4221
  },
4215
4222
  rowHeight: {
4216
4223
  tooltip: 'Row height',
@@ -8956,7 +8963,9 @@ const SearchInput2 = /*#__PURE__*/React__default.forwardRef(function SearchInput
8956
8963
  setFocused(false);
8957
8964
  };
8958
8965
  return /*#__PURE__*/React__default.createElement("div", {
8959
- className: "relative [&_[data-taco='input-container']]:z-20",
8966
+ className: cn('relative', {
8967
+ "[&_[data-taco='input-container']]:z-20": focused
8968
+ }),
8960
8969
  onBlur: handleSettingsBlur,
8961
8970
  ref: settingsRef
8962
8971
  }, input, focused ? /*#__PURE__*/React__default.createElement("div", {
@@ -16562,12 +16571,13 @@ function useSettingsStateListener$1(table, onChangeSettings) {
16562
16571
  columnVisibility: state.columnVisibility,
16563
16572
  excludeUnmatchedRecordsInSearch: meta.search.excludeUnmatchedResults,
16564
16573
  fontSize: meta.fontSize.size,
16574
+ showWarningWhenPrintingLargeDataset: meta.printing.printWarningDialogVisibility,
16565
16575
  rowHeight: meta.rowHeight.height,
16566
16576
  sorting: state.sorting
16567
16577
  }), 250);
16568
16578
  }
16569
16579
  return () => clearTimeout(handler);
16570
- }, [onChangeSettings, meta.columnFreezing.frozenColumnIndex, state.columnOrder, state.columnPinning, state.columnSizing, state.columnVisibility, meta.search.excludeUnmatchedResults, meta.fontSize.size, meta.rowHeight.height, state.sorting]);
16580
+ }, [onChangeSettings, meta.columnFreezing.frozenColumnIndex, state.columnOrder, state.columnPinning, state.columnSizing, state.columnVisibility, meta.search.excludeUnmatchedResults, meta.fontSize.size, meta.rowHeight.height, meta.printing.printWarningDialogVisibility, state.sorting]);
16571
16581
  }
16572
16582
 
16573
16583
  var Table3FilterComparator;
@@ -18010,10 +18020,13 @@ function useConvertChildrenToColumns(props, options, editing) {
18010
18020
  };
18011
18021
  }
18012
18022
 
18013
- function usePrinting(isEnabled, loadAll) {
18023
+ function usePrinting(isEnabled, loadAll, showWarningWhenPrintingLargeDataset = true) {
18024
+ const [printWarningDialogVisibility, setPrintWarningDialogVisibility] = React__default.useState(showWarningWhenPrintingLargeDataset);
18014
18025
  return {
18015
18026
  isEnabled,
18016
- loadAll
18027
+ loadAll,
18028
+ printWarningDialogVisibility,
18029
+ setPrintWarningDialogVisibility: isEnabled ? setPrintWarningDialogVisibility : () => undefined
18017
18030
  };
18018
18031
  }
18019
18032
 
@@ -18124,7 +18137,7 @@ function useSearch(isEnabled, excludeUnmatchedResultsInSearch = false, loadAll)
18124
18137
  }
18125
18138
 
18126
18139
  function useTable$2(props) {
18127
- var _ref, _props$defaultSetting, _props$defaultSetting2, _props$defaultSetting3, _props$defaultSetting4, _props$defaultSetting5, _props$defaultSetting6, _props$defaultSetting7, _props$defaultSetting8, _props$length;
18140
+ var _ref, _props$defaultSetting, _props$defaultSetting2, _props$defaultSetting3, _props$defaultSetting4, _props$defaultSetting5, _props$defaultSetting6, _props$defaultSetting7, _props$defaultSetting8, _props$defaultSetting9, _props$length;
18128
18141
  // options
18129
18142
  const options = useTablePreset(props);
18130
18143
  const tableOptions = {
@@ -18180,15 +18193,15 @@ function useTable$2(props) {
18180
18193
  const editing = useEditing(options.enableEditing, props.onSave);
18181
18194
  const fontSize = useFontSize(options.enableFontSize, (_props$defaultSetting4 = props.defaultSettings) === null || _props$defaultSetting4 === void 0 ? void 0 : _props$defaultSetting4.fontSize);
18182
18195
  const hoverState = usePauseHoverState();
18183
- const printing = usePrinting(options.enablePrinting, props.loadAll);
18196
+ const printing = usePrinting(options.enablePrinting, props.loadAll, (_props$defaultSetting5 = props.defaultSettings) === null || _props$defaultSetting5 === void 0 ? void 0 : _props$defaultSetting5.showWarningWhenPrintingLargeDataset);
18184
18197
  const rowClick = useRowClick(props.onRowClick);
18185
18198
  const rowDrag = useRowDrag(options.enableRowDrag);
18186
18199
  const rowDrop = useRowDrop(options.enableRowDrop, props.onRowDrop);
18187
18200
  const rowGoto = useRowGoto(options.enableRowGoto, props.onRowGoto);
18188
18201
  const rowHeight = useRowHeight(options.enableRowHeight, // temporarily see if deprecated rowDensity is there
18189
- (_props$defaultSetting5 = (_props$defaultSetting6 = props.defaultSettings) === null || _props$defaultSetting6 === void 0 ? void 0 : _props$defaultSetting6.rowHeight) !== null && _props$defaultSetting5 !== void 0 ? _props$defaultSetting5 : (_props$defaultSetting7 = props.defaultSettings) === null || _props$defaultSetting7 === void 0 ? void 0 : _props$defaultSetting7.rowDensity);
18202
+ (_props$defaultSetting6 = (_props$defaultSetting7 = props.defaultSettings) === null || _props$defaultSetting7 === void 0 ? void 0 : _props$defaultSetting7.rowHeight) !== null && _props$defaultSetting6 !== void 0 ? _props$defaultSetting6 : (_props$defaultSetting8 = props.defaultSettings) === null || _props$defaultSetting8 === void 0 ? void 0 : _props$defaultSetting8.rowDensity);
18190
18203
  const rowSelection = useRowSelection();
18191
- const search = useSearch(options.enableSearch, (_props$defaultSetting8 = props.defaultSettings) === null || _props$defaultSetting8 === void 0 ? void 0 : _props$defaultSetting8.excludeUnmatchedRecordsInSearch, props.loadAll);
18204
+ const search = useSearch(options.enableSearch, (_props$defaultSetting9 = props.defaultSettings) === null || _props$defaultSetting9 === void 0 ? void 0 : _props$defaultSetting9.excludeUnmatchedRecordsInSearch, props.loadAll);
18192
18205
  // columns
18193
18206
  const {
18194
18207
  columns,
@@ -18198,13 +18211,13 @@ function useTable$2(props) {
18198
18211
  } = useConvertChildrenToColumns(props, options, editing);
18199
18212
  // built-in features
18200
18213
  const initialState = React__default.useMemo(() => {
18201
- var _props$defaultSetting9, _props$defaultSetting10, _props$defaultSetting11, _props$defaultSetting12, _props$defaultSetting13, _props$defaultSetting14, _props$defaultSetting15;
18214
+ var _props$defaultSetting10, _props$defaultSetting11, _props$defaultSetting12, _props$defaultSetting13, _props$defaultSetting14, _props$defaultSetting15, _props$defaultSetting16;
18202
18215
  const sanitizeSortedColumns = column => columns.find(definedColumn => definedColumn.id === column.id);
18203
18216
  return {
18204
- columnOrder: ensureOrdering$1(columns, (_props$defaultSetting9 = props.defaultSettings) === null || _props$defaultSetting9 === void 0 ? void 0 : _props$defaultSetting9.columnOrder),
18205
- columnSizing: (_props$defaultSetting10 = (_props$defaultSetting11 = props.defaultSettings) === null || _props$defaultSetting11 === void 0 ? void 0 : _props$defaultSetting11.columnSizing) !== null && _props$defaultSetting10 !== void 0 ? _props$defaultSetting10 : defaultColumnSizing,
18206
- columnVisibility: (_props$defaultSetting12 = (_props$defaultSetting13 = props.defaultSettings) === null || _props$defaultSetting13 === void 0 ? void 0 : _props$defaultSetting13.columnVisibility) !== null && _props$defaultSetting12 !== void 0 ? _props$defaultSetting12 : defaultColumnVisibility,
18207
- sorting: (_props$defaultSetting14 = props.defaultSettings) !== null && _props$defaultSetting14 !== void 0 && _props$defaultSetting14.sorting ? (_props$defaultSetting15 = props.defaultSettings) === null || _props$defaultSetting15 === void 0 ? void 0 : _props$defaultSetting15.sorting.filter(sanitizeSortedColumns) : defaultSorting
18217
+ columnOrder: ensureOrdering$1(columns, (_props$defaultSetting10 = props.defaultSettings) === null || _props$defaultSetting10 === void 0 ? void 0 : _props$defaultSetting10.columnOrder),
18218
+ columnSizing: (_props$defaultSetting11 = (_props$defaultSetting12 = props.defaultSettings) === null || _props$defaultSetting12 === void 0 ? void 0 : _props$defaultSetting12.columnSizing) !== null && _props$defaultSetting11 !== void 0 ? _props$defaultSetting11 : defaultColumnSizing,
18219
+ columnVisibility: (_props$defaultSetting13 = (_props$defaultSetting14 = props.defaultSettings) === null || _props$defaultSetting14 === void 0 ? void 0 : _props$defaultSetting14.columnVisibility) !== null && _props$defaultSetting13 !== void 0 ? _props$defaultSetting13 : defaultColumnVisibility,
18220
+ sorting: (_props$defaultSetting15 = props.defaultSettings) !== null && _props$defaultSetting15 !== void 0 && _props$defaultSetting15.sorting ? (_props$defaultSetting16 = props.defaultSettings) === null || _props$defaultSetting16 === void 0 ? void 0 : _props$defaultSetting16.sorting.filter(sanitizeSortedColumns) : defaultSorting
18208
18221
  };
18209
18222
  }, []);
18210
18223
  const table = reactTable$1.useReactTable({
@@ -19373,7 +19386,7 @@ const PRINT_STYLES = `
19373
19386
  }
19374
19387
 
19375
19388
  @media print {
19376
- #root, html, body {
19389
+ html, body, #root {
19377
19390
  overflow: auto !important;
19378
19391
  height: auto !important;
19379
19392
  width: auto !important;
@@ -19392,7 +19405,7 @@ const PRINT_STYLES = `
19392
19405
  * Summary row cells
19393
19406
  */
19394
19407
  [role="table"] [role="rowgroup"]:last-child [role="cell"] {
19395
- border-top-width: 1px !important;
19408
+ border-width: 0 !important;
19396
19409
  }
19397
19410
 
19398
19411
  [role="table"] a {
@@ -19592,6 +19605,53 @@ function PrintIFrame({
19592
19605
  }, mountNode && stylesReady ? /*#__PURE__*/ReactDOM.createPortal( /*#__PURE__*/React__default.createElement(Table3, Object.assign({}, printTableProps)), mountNode) : null);
19593
19606
  }
19594
19607
 
19608
+ const WarningDialog = ({
19609
+ onAccept,
19610
+ onClose,
19611
+ onVisibilityChange,
19612
+ ...props
19613
+ }) => {
19614
+ const [hideWarningDialog, setHideWarningDialog] = React__default.useState(false);
19615
+ const {
19616
+ texts
19617
+ } = useLocalization();
19618
+ const handleClose = () => {
19619
+ onClose();
19620
+ // Change visibility state when the dialog is closing
19621
+ onVisibilityChange === null || onVisibilityChange === void 0 ? void 0 : onVisibilityChange(!hideWarningDialog);
19622
+ };
19623
+ return /*#__PURE__*/React__default.createElement(Dialog, Object.assign({}, props, {
19624
+ closeOnEscape: true,
19625
+ onClose: handleClose,
19626
+ showCloseButton: false,
19627
+ size: "xs"
19628
+ }), /*#__PURE__*/React__default.createElement(Dialog.Content, {
19629
+ "aria-label": texts.table3.print.warningDialog.title
19630
+ }, /*#__PURE__*/React__default.createElement(Dialog.Title, {
19631
+ className: "text-center"
19632
+ }, /*#__PURE__*/React__default.createElement(BadgeIcon, {
19633
+ icon: "warning",
19634
+ color: "yellow",
19635
+ className: "mr-2"
19636
+ }), texts.table3.print.warningDialog.title), /*#__PURE__*/React__default.createElement("p", null, texts.table3.print.warningDialog.description), /*#__PURE__*/React__default.createElement(Dialog.Footer, {
19637
+ className: "flex items-center justify-between"
19638
+ }, /*#__PURE__*/React__default.createElement(Checkbox, {
19639
+ label: texts.table3.print.warningDialog.checkboxVisibilityLabel,
19640
+ checked: hideWarningDialog,
19641
+ onChange: setHideWarningDialog
19642
+ }), /*#__PURE__*/React__default.createElement(Group, null, /*#__PURE__*/React__default.createElement(Button$1, {
19643
+ onClick: handleClose
19644
+ }, texts.table3.print.warningDialog.cancelButtonText), /*#__PURE__*/React__default.createElement(Button$1, {
19645
+ appearance: "primary",
19646
+ autoFocus: true,
19647
+ onClick: () => {
19648
+ handleClose();
19649
+ onAccept();
19650
+ }
19651
+ }, texts.table3.print.warningDialog.printButtonText)))));
19652
+ };
19653
+
19654
+ const SAFE_PRINT_CELL_COUNT = 10000;
19595
19655
  function PrintButton(props) {
19596
19656
  const {
19597
19657
  table,
@@ -19602,10 +19662,14 @@ function PrintButton(props) {
19602
19662
  } = useLocalization();
19603
19663
  const toast = useToast();
19604
19664
  const [isPrinting, setIsPrinting] = React__default.useState(false);
19665
+ const [showWarningDialog, setShowWarningDialog] = React__default.useState(false);
19605
19666
  const loadingToastRef = React__default.useRef(null);
19606
19667
  const buttonRef = React__default.useRef(null);
19607
19668
  const tableMeta = table.options.meta;
19608
19669
  const state = table.getState();
19670
+ const {
19671
+ printWarningDialogVisibility
19672
+ } = tableMeta.printing;
19609
19673
  const settings = React__default.useMemo(() => ({
19610
19674
  columnFilters: state.columnFilters,
19611
19675
  columnOrder: state.columnOrder,
@@ -19618,7 +19682,6 @@ function PrintButton(props) {
19618
19682
  }), [state.columnFilters, state.columnOrder, state.columnPinning, state.columnSizing, state.columnVisibility, state.sorting, tableMeta.rowHeight.height, tableMeta.columnFreezing.frozenColumnIndex]);
19619
19683
  const iframeTableProps = {
19620
19684
  ...tableProps,
19621
- data: tableProps.data,
19622
19685
  defaultSettings: settings
19623
19686
  };
19624
19687
  useGlobalKeyDown({
@@ -19642,31 +19705,63 @@ function PrintButton(props) {
19642
19705
  };
19643
19706
  const handlePrint = function () {
19644
19707
  try {
19708
+ let _exit = false;
19709
+ function _temp3(_result2) {
19710
+ if (_exit) return _result2;
19711
+ if (hasNonSafeCellCount && printWarningDialogVisibility) {
19712
+ setShowWarningDialog(true);
19713
+ } else {
19714
+ // only set printing (mount the iframe) when the data has loaded, it prevents repaint performance slow downs
19715
+ setIsPrinting(true);
19716
+ }
19717
+ }
19645
19718
  loadingToastRef.current = toast.loading(texts.table3.print.loading);
19719
+ const getCellCount = data => data.length ? data.length * Object.keys(data[0]).length : 0;
19720
+ let hasNonSafeCellCount = false;
19646
19721
  // if loadAll is not defined, just print with what we've got
19647
19722
  // don't compare length to data.length because the api might be choosing not to return all for performance
19648
- return Promise.resolve(function () {
19723
+ const _temp2 = function () {
19649
19724
  if (!tableMeta.printing.loadAll) {
19650
- setIsPrinting(true);
19725
+ const {
19726
+ data
19727
+ } = tableProps;
19728
+ const cellCount = getCellCount(data);
19729
+ hasNonSafeCellCount = cellCount > SAFE_PRINT_CELL_COUNT;
19651
19730
  } else {
19652
19731
  const _temp = _catch(function () {
19653
19732
  return Promise.resolve(tableMeta.printing.loadAll(table.getState().sorting, table.getState().columnFilters, tableMeta.search.query)).then(function () {
19654
- // only set printing (mount the iframe) when the data has loaded, it prevents repaint performance slow downs
19655
- setIsPrinting(true);
19733
+ // After the loadAll call above, the data changes. Hence, it becomes essential to acquire the data after
19734
+ // this call rather than before it.
19735
+ const {
19736
+ data
19737
+ } = tableProps;
19738
+ const cellCount = getCellCount(data);
19739
+ hasNonSafeCellCount = cellCount > SAFE_PRINT_CELL_COUNT;
19656
19740
  });
19657
19741
  }, function (error) {
19658
19742
  var _loadingToastRef$curr3;
19659
19743
  const errorMessage = `${texts.table3.print.error}: ${error}`;
19660
19744
  console.error(errorMessage);
19661
19745
  (_loadingToastRef$curr3 = loadingToastRef.current) === null || _loadingToastRef$curr3 === void 0 ? void 0 : _loadingToastRef$curr3.error(errorMessage);
19746
+ // in case of error, we return early
19747
+ _exit = true;
19662
19748
  });
19663
19749
  if (_temp && _temp.then) return _temp.then(function () {});
19664
19750
  }
19665
- }());
19751
+ }();
19752
+ return Promise.resolve(_temp2 && _temp2.then ? _temp2.then(_temp3) : _temp3(_temp2));
19666
19753
  } catch (e) {
19667
19754
  return Promise.reject(e);
19668
19755
  }
19669
19756
  };
19757
+ const handleWarningDialogAccept = () => {
19758
+ setIsPrinting(true);
19759
+ };
19760
+ const handleWarningDialogClose = () => {
19761
+ var _loadingToastRef$curr4;
19762
+ (_loadingToastRef$curr4 = loadingToastRef.current) === null || _loadingToastRef$curr4 === void 0 ? void 0 : _loadingToastRef$curr4.close();
19763
+ setShowWarningDialog(false);
19764
+ };
19670
19765
  return /*#__PURE__*/React__default.createElement(React__default.Fragment, null, /*#__PURE__*/React__default.createElement(IconButton, {
19671
19766
  disabled: isPrinting,
19672
19767
  icon: "print",
@@ -19678,6 +19773,11 @@ function PrintButton(props) {
19678
19773
  onAfterPrint: handleAfterPrint,
19679
19774
  onBeforePrint: handleBeforePrint,
19680
19775
  tableProps: iframeTableProps
19776
+ }), /*#__PURE__*/React__default.createElement(WarningDialog, {
19777
+ open: showWarningDialog,
19778
+ onAccept: handleWarningDialogAccept,
19779
+ onClose: handleWarningDialogClose,
19780
+ onVisibilityChange: tableMeta.printing.setPrintWarningDialogVisibility
19681
19781
  }));
19682
19782
  }
19683
19783