@economic/taco 2.8.1 → 2.9.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.
- package/dist/components/Icon/components/Lock.d.ts +3 -0
- package/dist/components/Icon/components/index.d.ts +1 -1
- package/dist/components/Input/Input.d.ts +1 -1
- package/dist/components/Menu/Menu.d.ts +2 -1
- package/dist/components/Menu/components/Content.d.ts +1 -1
- package/dist/components/Menu/components/Item.d.ts +1 -1
- package/dist/components/Menu/components/Link.d.ts +1 -1
- package/dist/components/Menu/components/Separator.d.ts +4 -2
- package/dist/components/Menu/components/SubMenu.d.ts +1 -1
- package/dist/components/Navigation2/components/Link.d.ts +1 -1
- package/dist/components/Select2/components/Option.d.ts +1 -1
- package/dist/components/Select2/components/Search.d.ts +1 -1
- package/dist/components/Table3/components/columns/styles.d.ts +1 -0
- package/dist/components/Table3/components/toolbar/ColumnSettings.d.ts +3 -2
- package/dist/components/Table3/components/toolbar/Filter/filters/Filters.d.ts +1 -1
- package/dist/components/Table3/components/toolbar/PrintButton/WarningDialog.d.ts +2 -1
- package/dist/components/Table3/components/toolbar/Settings.d.ts +6 -0
- package/dist/components/Table3/hooks/features/useCurrentRow.d.ts +3 -3
- package/dist/components/Table3/hooks/useCssGrid.d.ts +1 -1
- package/dist/components/Tag/Tag.d.ts +1 -1
- package/dist/esm/packages/taco/src/components/Header/components/Agreement/Display.js +1 -1
- package/dist/esm/packages/taco/src/components/Icon/components/Lock.js +19 -0
- package/dist/esm/packages/taco/src/components/Icon/components/Lock.js.map +1 -0
- package/dist/esm/packages/taco/src/components/Icon/components/index.js +2 -0
- package/dist/esm/packages/taco/src/components/Icon/components/index.js.map +1 -1
- package/dist/esm/packages/taco/src/components/Layout/components/Sidebar.js +1 -1
- package/dist/esm/packages/taco/src/components/Menu/Menu.js.map +1 -1
- package/dist/esm/packages/taco/src/components/Menu/components/Separator.js +7 -6
- package/dist/esm/packages/taco/src/components/Menu/components/Separator.js.map +1 -1
- package/dist/esm/packages/taco/src/components/Provider/Localization.js +3 -3
- package/dist/esm/packages/taco/src/components/Provider/Localization.js.map +1 -1
- package/dist/esm/packages/taco/src/components/SearchInput2/SearchInput2.js +1 -1
- package/dist/esm/packages/taco/src/components/SearchInput2/SearchInput2.js.map +1 -1
- package/dist/esm/packages/taco/src/components/Table3/Table3.js +3 -1
- package/dist/esm/packages/taco/src/components/Table3/Table3.js.map +1 -1
- package/dist/esm/packages/taco/src/components/Table3/components/columns/cell/Cell.js +3 -2
- package/dist/esm/packages/taco/src/components/Table3/components/columns/cell/Cell.js.map +1 -1
- package/dist/esm/packages/taco/src/components/Table3/components/columns/cell/EditingCell.js +3 -2
- package/dist/esm/packages/taco/src/components/Table3/components/columns/cell/EditingCell.js.map +1 -1
- package/dist/esm/packages/taco/src/components/Table3/components/columns/styles.js +2 -1
- package/dist/esm/packages/taco/src/components/Table3/components/columns/styles.js.map +1 -1
- package/dist/esm/packages/taco/src/components/Table3/components/toolbar/ColumnSettings.js +34 -35
- package/dist/esm/packages/taco/src/components/Table3/components/toolbar/ColumnSettings.js.map +1 -1
- package/dist/esm/packages/taco/src/components/Table3/components/toolbar/Filter/filters/Filters.js +19 -7
- package/dist/esm/packages/taco/src/components/Table3/components/toolbar/Filter/filters/Filters.js.map +1 -1
- package/dist/esm/packages/taco/src/components/Table3/components/toolbar/PrintButton/PrintButton.js +66 -18
- package/dist/esm/packages/taco/src/components/Table3/components/toolbar/PrintButton/PrintButton.js.map +1 -1
- package/dist/esm/packages/taco/src/components/Table3/components/toolbar/PrintButton/PrintIFrame.js +12 -8
- package/dist/esm/packages/taco/src/components/Table3/components/toolbar/PrintButton/PrintIFrame.js.map +1 -1
- package/dist/esm/packages/taco/src/components/Table3/components/toolbar/PrintButton/WarningDialog.js +5 -1
- package/dist/esm/packages/taco/src/components/Table3/components/toolbar/PrintButton/WarningDialog.js.map +1 -1
- package/dist/esm/packages/taco/src/components/Table3/components/toolbar/Search.js +2 -2
- package/dist/esm/packages/taco/src/components/Table3/components/toolbar/Search.js.map +1 -1
- package/dist/esm/packages/taco/src/components/Table3/components/toolbar/Settings.js +61 -0
- package/dist/esm/packages/taco/src/components/Table3/components/toolbar/Settings.js.map +1 -0
- package/dist/esm/packages/taco/src/components/Table3/components/toolbar/Toolbar.js +8 -35
- package/dist/esm/packages/taco/src/components/Table3/components/toolbar/Toolbar.js.map +1 -1
- package/dist/esm/packages/taco/src/components/Table3/hooks/features/useColumnFreezing.js +3 -2
- package/dist/esm/packages/taco/src/components/Table3/hooks/features/useColumnFreezing.js.map +1 -1
- package/dist/esm/packages/taco/src/components/Table3/hooks/features/useCurrentRow.js +1 -1
- package/dist/esm/packages/taco/src/components/Table3/hooks/features/useCurrentRow.js.map +1 -1
- package/dist/esm/packages/taco/src/components/Table3/hooks/features/useRowClick.js +1 -1
- package/dist/esm/packages/taco/src/components/Table3/hooks/features/useRowClick.js.map +1 -1
- package/dist/esm/packages/taco/src/components/Table3/hooks/features/useRowSelection.js +5 -2
- package/dist/esm/packages/taco/src/components/Table3/hooks/features/useRowSelection.js.map +1 -1
- package/dist/esm/packages/taco/src/components/Table3/hooks/listeners/useCurrentRowListener.js +2 -1
- package/dist/esm/packages/taco/src/components/Table3/hooks/listeners/useCurrentRowListener.js.map +1 -1
- package/dist/esm/packages/taco/src/components/Table3/hooks/listeners/useEditingStateListener.js +8 -4
- package/dist/esm/packages/taco/src/components/Table3/hooks/listeners/useEditingStateListener.js.map +1 -1
- package/dist/esm/packages/taco/src/components/Table3/hooks/listeners/useShortcutsListener.js +1 -1
- package/dist/esm/packages/taco/src/components/Table3/hooks/listeners/useShortcutsListener.js.map +1 -1
- package/dist/esm/packages/taco/src/components/Table3/hooks/useCssGrid.js +7 -3
- package/dist/esm/packages/taco/src/components/Table3/hooks/useCssGrid.js.map +1 -1
- package/dist/esm/packages/taco/src/components/Table3/hooks/useTable.js +9 -4
- package/dist/esm/packages/taco/src/components/Table3/hooks/useTable.js.map +1 -1
- package/dist/esm/packages/taco/src/components/Tooltip/Tooltip.js +10 -12
- package/dist/esm/packages/taco/src/components/Tooltip/Tooltip.js.map +1 -1
- package/dist/esm/packages/taco/src/index.js +2 -2
- package/dist/taco.cjs.development.js +368 -234
- package/dist/taco.cjs.development.js.map +1 -1
- package/dist/taco.cjs.production.min.js +1 -1
- package/dist/taco.cjs.production.min.js.map +1 -1
- package/package.json +14 -14
- package/types.json +14106 -11815
package/dist/esm/packages/taco/src/components/Table3/components/toolbar/PrintButton/PrintButton.js
CHANGED
|
@@ -26,20 +26,23 @@ function PrintButton(props) {
|
|
|
26
26
|
const {
|
|
27
27
|
printWarningDialogVisibility
|
|
28
28
|
} = tableMeta.printing;
|
|
29
|
+
// When changing printTableId, update packages/taco/src/components/Table3/Table3.tsx file and other usages where
|
|
30
|
+
// printTableId is used to figure out whether the table is a print table or not.
|
|
29
31
|
const printTableId = `${tableProps.id}_print`;
|
|
32
|
+
const excludeUnmatchedResults = tableMeta.search.excludeUnmatchedResults;
|
|
30
33
|
const defaultSettings = React__default.useMemo(() => ({
|
|
31
34
|
columnFreezingIndex: tableMeta.columnFreezing.frozenColumnIndex,
|
|
32
35
|
columnOrder: state.columnOrder,
|
|
33
36
|
columnSizing: state.columnSizing,
|
|
34
37
|
columnVisibility: state.columnVisibility,
|
|
35
|
-
excludeUnmatchedRecordsInSearch:
|
|
38
|
+
excludeUnmatchedRecordsInSearch: excludeUnmatchedResults,
|
|
36
39
|
fontSize: tableMeta.fontSize.size,
|
|
37
40
|
rowHeight: tableMeta.rowHeight.height,
|
|
38
41
|
sorting: state.sorting,
|
|
39
42
|
// we don't save these, but we must pass them to print
|
|
40
43
|
columnFilters: state.columnFilters,
|
|
41
44
|
globalFilter: state.globalFilter
|
|
42
|
-
}), [tableMeta.columnFreezing.frozenColumnIndex, state.columnOrder, state.columnSizing, state.columnVisibility,
|
|
45
|
+
}), [tableMeta.columnFreezing.frozenColumnIndex, state.columnOrder, state.columnSizing, state.columnVisibility, excludeUnmatchedResults, tableMeta.fontSize.size, tableMeta.rowHeight.height, state.sorting, state.columnFilters, state.globalFilter]);
|
|
43
46
|
const iframeTableProps = {
|
|
44
47
|
...tableProps,
|
|
45
48
|
defaultSettings,
|
|
@@ -55,20 +58,51 @@ function PrintButton(props) {
|
|
|
55
58
|
// Starts custom printing
|
|
56
59
|
(_buttonRef$current = buttonRef.current) === null || _buttonRef$current === void 0 ? void 0 : _buttonRef$current.click();
|
|
57
60
|
});
|
|
58
|
-
const
|
|
61
|
+
const handleLoadingError = error => {
|
|
59
62
|
var _loadingToastRef$curr;
|
|
60
|
-
|
|
61
|
-
|
|
63
|
+
const errorMessage = `${texts.table3.print.error}: ${error}`;
|
|
64
|
+
console.error(errorMessage);
|
|
65
|
+
(_loadingToastRef$curr = loadingToastRef.current) === null || _loadingToastRef$curr === void 0 ? void 0 : _loadingToastRef$curr.error(errorMessage);
|
|
66
|
+
};
|
|
67
|
+
const restoreTableDataWithoutSearch = function () {
|
|
68
|
+
try {
|
|
69
|
+
const _temp = _catch(function () {
|
|
70
|
+
var _tableMeta$printing$l, _tableMeta$printing;
|
|
71
|
+
return Promise.resolve((_tableMeta$printing$l = (_tableMeta$printing = tableMeta.printing).loadAll) === null || _tableMeta$printing$l === void 0 ? void 0 : _tableMeta$printing$l.call(_tableMeta$printing, table.getState().sorting, table.getState().columnFilters, undefined)).then(function () {});
|
|
72
|
+
}, function (error) {
|
|
73
|
+
handleLoadingError(error);
|
|
74
|
+
});
|
|
75
|
+
return Promise.resolve(_temp && _temp.then ? _temp.then(function () {}) : void 0);
|
|
76
|
+
} catch (e) {
|
|
77
|
+
return Promise.reject(e);
|
|
78
|
+
}
|
|
79
|
+
};
|
|
80
|
+
const handleAfterPrint = function () {
|
|
81
|
+
try {
|
|
82
|
+
function _temp3() {
|
|
83
|
+
var _loadingToastRef$curr2;
|
|
84
|
+
setIsPrinting(false);
|
|
85
|
+
(_loadingToastRef$curr2 = loadingToastRef.current) === null || _loadingToastRef$curr2 === void 0 ? void 0 : _loadingToastRef$curr2.close();
|
|
86
|
+
}
|
|
87
|
+
const _temp2 = function () {
|
|
88
|
+
if (tableMeta.printing.loadAll && excludeUnmatchedResults) {
|
|
89
|
+
return Promise.resolve(restoreTableDataWithoutSearch()).then(function () {});
|
|
90
|
+
}
|
|
91
|
+
}();
|
|
92
|
+
return Promise.resolve(_temp2 && _temp2.then ? _temp2.then(_temp3) : _temp3(_temp2));
|
|
93
|
+
} catch (e) {
|
|
94
|
+
return Promise.reject(e);
|
|
95
|
+
}
|
|
62
96
|
};
|
|
63
97
|
const handleBeforePrint = () => {
|
|
64
|
-
var _loadingToastRef$
|
|
65
|
-
(_loadingToastRef$
|
|
98
|
+
var _loadingToastRef$curr3;
|
|
99
|
+
(_loadingToastRef$curr3 = loadingToastRef.current) === null || _loadingToastRef$curr3 === void 0 ? void 0 : _loadingToastRef$curr3.close();
|
|
66
100
|
};
|
|
67
101
|
const handlePrint = function () {
|
|
68
102
|
try {
|
|
69
103
|
let _exit = false;
|
|
70
|
-
function
|
|
71
|
-
if (_exit) return
|
|
104
|
+
function _temp6(_result3) {
|
|
105
|
+
if (_exit) return _result3;
|
|
72
106
|
if (hasNonSafeCellCount && printWarningDialogVisibility) {
|
|
73
107
|
setShowWarningDialog(true);
|
|
74
108
|
} else {
|
|
@@ -81,7 +115,7 @@ function PrintButton(props) {
|
|
|
81
115
|
let hasNonSafeCellCount = false;
|
|
82
116
|
// if loadAll is not defined, just print with what we've got
|
|
83
117
|
// don't compare length to data.length because the api might be choosing not to return all for performance
|
|
84
|
-
const
|
|
118
|
+
const _temp5 = function () {
|
|
85
119
|
if (!tableMeta.printing.loadAll) {
|
|
86
120
|
const {
|
|
87
121
|
data
|
|
@@ -89,8 +123,12 @@ function PrintButton(props) {
|
|
|
89
123
|
const cellCount = getCellCount(data);
|
|
90
124
|
hasNonSafeCellCount = cellCount > SAFE_PRINT_CELL_COUNT;
|
|
91
125
|
} else {
|
|
92
|
-
const
|
|
93
|
-
return Promise.resolve(tableMeta.printing.loadAll(table.getState().sorting, table.getState().columnFilters,
|
|
126
|
+
const _temp4 = _catch(function () {
|
|
127
|
+
return Promise.resolve(tableMeta.printing.loadAll(table.getState().sorting, table.getState().columnFilters,
|
|
128
|
+
// We need to pass search query to the server when printing, to be able to render correct data set in iFrame,
|
|
129
|
+
// But in "display" table, search is performed only on client side, so we'll need to request data again without search query,
|
|
130
|
+
// when printing will be finished.
|
|
131
|
+
excludeUnmatchedResults ? tableMeta.search.query : undefined)).then(function () {
|
|
94
132
|
// After the loadAll call above, the data changes. Hence, it becomes essential to acquire the data after
|
|
95
133
|
// this call rather than before it.
|
|
96
134
|
const {
|
|
@@ -100,17 +138,14 @@ function PrintButton(props) {
|
|
|
100
138
|
hasNonSafeCellCount = cellCount > SAFE_PRINT_CELL_COUNT;
|
|
101
139
|
});
|
|
102
140
|
}, function (error) {
|
|
103
|
-
|
|
104
|
-
const errorMessage = `${texts.table3.print.error}: ${error}`;
|
|
105
|
-
console.error(errorMessage);
|
|
106
|
-
(_loadingToastRef$curr3 = loadingToastRef.current) === null || _loadingToastRef$curr3 === void 0 ? void 0 : _loadingToastRef$curr3.error(errorMessage);
|
|
141
|
+
handleLoadingError(error);
|
|
107
142
|
// in case of error, we return early
|
|
108
143
|
_exit = true;
|
|
109
144
|
});
|
|
110
|
-
if (
|
|
145
|
+
if (_temp4 && _temp4.then) return _temp4.then(function () {});
|
|
111
146
|
}
|
|
112
147
|
}();
|
|
113
|
-
return Promise.resolve(
|
|
148
|
+
return Promise.resolve(_temp5 && _temp5.then ? _temp5.then(_temp6) : _temp6(_temp5));
|
|
114
149
|
} catch (e) {
|
|
115
150
|
return Promise.reject(e);
|
|
116
151
|
}
|
|
@@ -118,6 +153,18 @@ function PrintButton(props) {
|
|
|
118
153
|
const handleWarningDialogAccept = () => {
|
|
119
154
|
setIsPrinting(true);
|
|
120
155
|
};
|
|
156
|
+
const handleWarningDialogCancel = function () {
|
|
157
|
+
try {
|
|
158
|
+
const _temp7 = function () {
|
|
159
|
+
if (tableMeta.printing.loadAll && excludeUnmatchedResults) {
|
|
160
|
+
return Promise.resolve(restoreTableDataWithoutSearch()).then(function () {});
|
|
161
|
+
}
|
|
162
|
+
}();
|
|
163
|
+
return Promise.resolve(_temp7 && _temp7.then ? _temp7.then(function () {}) : void 0);
|
|
164
|
+
} catch (e) {
|
|
165
|
+
return Promise.reject(e);
|
|
166
|
+
}
|
|
167
|
+
};
|
|
121
168
|
const handleWarningDialogClose = () => {
|
|
122
169
|
var _loadingToastRef$curr4;
|
|
123
170
|
(_loadingToastRef$curr4 = loadingToastRef.current) === null || _loadingToastRef$curr4 === void 0 ? void 0 : _loadingToastRef$curr4.close();
|
|
@@ -138,6 +185,7 @@ function PrintButton(props) {
|
|
|
138
185
|
open: showWarningDialog,
|
|
139
186
|
onAccept: handleWarningDialogAccept,
|
|
140
187
|
onClose: handleWarningDialogClose,
|
|
188
|
+
onCancel: handleWarningDialogCancel,
|
|
141
189
|
onVisibilityChange: tableMeta.printing.setPrintWarningDialogVisibility
|
|
142
190
|
}));
|
|
143
191
|
}
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"PrintButton.js","sources":["../../../../../../../../../../src/components/Table3/components/toolbar/PrintButton/PrintButton.tsx"],"sourcesContent":["import React from 'react';\nimport { Table as RTable, TableMeta } from '@tanstack/react-table';\n\nimport { IconButton } from '../../../../IconButton/IconButton';\nimport { useLocalization } from '../../../../Provider/Localization';\nimport { ToastReference, useToast } from '../../../../Toast/Toaster';\nimport { PrintIFrame } from './PrintIFrame';\nimport { Table3Props } from '../../../types';\nimport { useGlobalKeyDown } from '../../../../../hooks/useGlobalKeyDown';\nimport { WarningDialog } from './WarningDialog';\n\nconst SAFE_PRINT_CELL_COUNT = 10000;\n\nexport type PrintButtonProps<TType = unknown> = React.HTMLAttributes<HTMLButtonElement> & {\n table: RTable<TType>;\n tableProps: Table3Props<TType>;\n};\n\nexport function PrintButton<TType = unknown>(props: PrintButtonProps<TType>) {\n const { table, tableProps } = props;\n const { texts } = useLocalization();\n const toast = useToast();\n\n const [isPrinting, setIsPrinting] = React.useState(false);\n const [showWarningDialog, setShowWarningDialog] = React.useState(false);\n const loadingToastRef = React.useRef<ToastReference | null>(null);\n const buttonRef = React.useRef<HTMLButtonElement>(null);\n\n const tableMeta = table.options.meta as TableMeta<TType>;\n const state = table.getState();\n const { printWarningDialogVisibility } = tableMeta.printing;\n\n const printTableId = `${tableProps.id}_print`;\n\n const defaultSettings = React.useMemo(\n () => ({\n columnFreezingIndex: tableMeta.columnFreezing.frozenColumnIndex,\n columnOrder: state.columnOrder,\n columnSizing: state.columnSizing,\n columnVisibility: state.columnVisibility,\n excludeUnmatchedRecordsInSearch: tableMeta.search.excludeUnmatchedResults,\n fontSize: tableMeta.fontSize.size,\n rowHeight: tableMeta.rowHeight.height,\n sorting: state.sorting,\n // we don't save these, but we must pass them to print\n columnFilters: state.columnFilters,\n globalFilter: state.globalFilter,\n }),\n [\n tableMeta.columnFreezing.frozenColumnIndex,\n state.columnOrder,\n state.columnSizing,\n state.columnVisibility,\n tableMeta.search.excludeUnmatchedResults,\n tableMeta.fontSize.size,\n tableMeta.rowHeight.height,\n state.sorting,\n state.columnFilters,\n state.globalFilter,\n ]\n );\n\n const iframeTableProps = { ...tableProps, defaultSettings, id: printTableId };\n\n useGlobalKeyDown({ key: 'p', meta: true, shift: false }, (event: KeyboardEvent) => {\n event.preventDefault();\n // Starts custom printing\n buttonRef.current?.click();\n });\n\n const handleAfterPrint = () => {\n setIsPrinting(false);\n loadingToastRef.current?.close();\n };\n\n const handleBeforePrint = () => {\n loadingToastRef.current?.close();\n };\n\n const handlePrint = async () => {\n loadingToastRef.current = toast.loading(texts.table3.print.loading as any);\n\n const getCellCount = (data: TType[]) => (data.length ? data.length * Object.keys(data[0]).length : 0);\n let hasNonSafeCellCount = false;\n\n // if loadAll is not defined, just print with what we've got\n // don't compare length to data.length because the api might be choosing not to return all for performance\n if (!tableMeta.printing.loadAll) {\n const { data } = tableProps;\n const cellCount = getCellCount(data);\n\n hasNonSafeCellCount = cellCount > SAFE_PRINT_CELL_COUNT;\n } else {\n try {\n await tableMeta.printing.loadAll(\n table.getState().sorting,\n table.getState().columnFilters,\n tableMeta.search.query\n );\n\n // After the loadAll call above, the data changes. Hence, it becomes essential to acquire the data after\n // this call rather than before it.\n const { data } = tableProps;\n const cellCount = getCellCount(data);\n\n hasNonSafeCellCount = cellCount > SAFE_PRINT_CELL_COUNT;\n } catch (error) {\n const errorMessage = `${texts.table3.print.error}: ${error}`;\n\n console.error(errorMessage);\n loadingToastRef.current?.error(errorMessage);\n\n // in case of error, we return early\n return;\n }\n }\n\n if (hasNonSafeCellCount && printWarningDialogVisibility) {\n setShowWarningDialog(true);\n } else {\n // only set printing (mount the iframe) when the data has loaded, it prevents repaint performance slow downs\n setIsPrinting(true);\n }\n };\n\n const handleWarningDialogAccept = () => {\n setIsPrinting(true);\n };\n\n const handleWarningDialogClose = () => {\n loadingToastRef.current?.close();\n setShowWarningDialog(false);\n };\n\n return (\n <>\n <IconButton\n disabled={isPrinting}\n icon=\"print\"\n onClick={handlePrint}\n aria-label={texts.table3.print.tooltip}\n tooltip={texts.table3.print.tooltip}\n ref={buttonRef}\n />\n {isPrinting && iframeTableProps.data !== null && (\n <PrintIFrame\n onAfterPrint={handleAfterPrint}\n onBeforePrint={handleBeforePrint}\n tableProps={iframeTableProps as Table3Props<TType>}\n />\n )}\n <WarningDialog\n open={showWarningDialog}\n onAccept={handleWarningDialogAccept}\n onClose={handleWarningDialogClose}\n onVisibilityChange={tableMeta.printing.setPrintWarningDialogVisibility}\n />\n </>\n );\n}\n"],"names":["SAFE_PRINT_CELL_COUNT","PrintButton","props","table","tableProps","texts","useLocalization","toast","useToast","isPrinting","setIsPrinting","React","useState","showWarningDialog","setShowWarningDialog","loadingToastRef","useRef","buttonRef","tableMeta","options","meta","state","getState","printWarningDialogVisibility","printing","printTableId","id","defaultSettings","useMemo","columnFreezingIndex","columnFreezing","frozenColumnIndex","columnOrder","columnSizing","columnVisibility","excludeUnmatchedRecordsInSearch","search","excludeUnmatchedResults","fontSize","size","rowHeight","height","sorting","columnFilters","globalFilter","iframeTableProps","useGlobalKeyDown","key","shift","event","preventDefault","_buttonRef$current","current","click","handleAfterPrint","_loadingToastRef$curr","close","handleBeforePrint","_loadingToastRef$curr2","handlePrint","hasNonSafeCellCount","loading","table3","print","getCellCount","data","length","Object","keys","_temp2","loadAll","cellCount","_temp","_catch","Promise","resolve","query","then","error","_loadingToastRef$curr3","errorMessage","console","_exit","_temp3","e","reject","handleWarningDialogAccept","handleWarningDialogClose","_loadingToastRef$curr4","IconButton","disabled","icon","onClick","tooltip","ref","PrintIFrame","onAfterPrint","onBeforePrint","WarningDialog","open","onAccept","onClose","onVisibilityChange","setPrintWarningDialogVisibility"],"mappings":";;;;;;;;;AAWA,MAAMA,qBAAqB,GAAG,KAAK;SAOnBC,WAAWA,CAAkBC,KAA8B;EACvE,MAAM;IAAEC,KAAK;IAAEC;GAAY,GAAGF,KAAK;EACnC,MAAM;IAAEG;GAAO,GAAGC,eAAe,EAAE;EACnC,MAAMC,KAAK,GAAGC,QAAQ,EAAE;EAExB,MAAM,CAACC,UAAU,EAAEC,aAAa,CAAC,GAAGC,cAAK,CAACC,QAAQ,CAAC,KAAK,CAAC;EACzD,MAAM,CAACC,iBAAiB,EAAEC,oBAAoB,CAAC,GAAGH,cAAK,CAACC,QAAQ,CAAC,KAAK,CAAC;EACvE,MAAMG,eAAe,GAAGJ,cAAK,CAACK,MAAM,CAAwB,IAAI,CAAC;EACjE,MAAMC,SAAS,GAAGN,cAAK,CAACK,MAAM,CAAoB,IAAI,CAAC;EAEvD,MAAME,SAAS,GAAGf,KAAK,CAACgB,OAAO,CAACC,IAAwB;EACxD,MAAMC,KAAK,GAAGlB,KAAK,CAACmB,QAAQ,EAAE;EAC9B,MAAM;IAAEC;GAA8B,GAAGL,SAAS,CAACM,QAAQ;EAE3D,MAAMC,YAAY,MAAMrB,UAAU,CAACsB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C,GAAG,EAAE7E;IACP,EACDR,UAAU,IAAIoC,gBAAgB,CAACoB,IAAI,KAAK,IAAI,iBACzCtD,6BAACoF,WAAW;IACRC,YAAY,EAAE1C,gBAAgB;IAC9B2C,aAAa,EAAExC,iBAAiB;IAChCrD,UAAU,EAAEyC;IAEnB,eACDlC,6BAACuF,aAAa;IACVC,IAAI,EAAEtF,iBAAiB;IACvBuF,QAAQ,EAAEd,yBAAyB;IACnCe,OAAO,EAAEd,wBAAwB;IACjCe,kBAAkB,EAAEpF,SAAS,CAACM,QAAQ,CAAC+E;IACzC,CACH;AAEX;;;;"}
|
|
1
|
+
{"version":3,"file":"PrintButton.js","sources":["../../../../../../../../../../src/components/Table3/components/toolbar/PrintButton/PrintButton.tsx"],"sourcesContent":["import React from 'react';\nimport { Table as RTable, TableMeta } from '@tanstack/react-table';\n\nimport { IconButton } from '../../../../IconButton/IconButton';\nimport { useLocalization } from '../../../../Provider/Localization';\nimport { ToastReference, useToast } from '../../../../Toast/Toaster';\nimport { PrintIFrame } from './PrintIFrame';\nimport { Table3Props } from '../../../types';\nimport { useGlobalKeyDown } from '../../../../../hooks/useGlobalKeyDown';\nimport { WarningDialog } from './WarningDialog';\n\nconst SAFE_PRINT_CELL_COUNT = 10000;\n\nexport type PrintButtonProps<TType = unknown> = React.HTMLAttributes<HTMLButtonElement> & {\n table: RTable<TType>;\n tableProps: Table3Props<TType>;\n};\n\nexport function PrintButton<TType = unknown>(props: PrintButtonProps<TType>) {\n const { table, tableProps } = props;\n const { texts } = useLocalization();\n const toast = useToast();\n\n const [isPrinting, setIsPrinting] = React.useState(false);\n const [showWarningDialog, setShowWarningDialog] = React.useState(false);\n const loadingToastRef = React.useRef<ToastReference | null>(null);\n const buttonRef = React.useRef<HTMLButtonElement>(null);\n\n const tableMeta = table.options.meta as TableMeta<TType>;\n const state = table.getState();\n const { printWarningDialogVisibility } = tableMeta.printing;\n\n // When changing printTableId, update packages/taco/src/components/Table3/Table3.tsx file and other usages where\n // printTableId is used to figure out whether the table is a print table or not.\n const printTableId = `${tableProps.id}_print`;\n const excludeUnmatchedResults = tableMeta.search.excludeUnmatchedResults;\n\n const defaultSettings = React.useMemo(\n () => ({\n columnFreezingIndex: tableMeta.columnFreezing.frozenColumnIndex,\n columnOrder: state.columnOrder,\n columnSizing: state.columnSizing,\n columnVisibility: state.columnVisibility,\n excludeUnmatchedRecordsInSearch: excludeUnmatchedResults,\n fontSize: tableMeta.fontSize.size,\n rowHeight: tableMeta.rowHeight.height,\n sorting: state.sorting,\n // we don't save these, but we must pass them to print\n columnFilters: state.columnFilters,\n globalFilter: state.globalFilter,\n }),\n [\n tableMeta.columnFreezing.frozenColumnIndex,\n state.columnOrder,\n state.columnSizing,\n state.columnVisibility,\n excludeUnmatchedResults,\n tableMeta.fontSize.size,\n tableMeta.rowHeight.height,\n state.sorting,\n state.columnFilters,\n state.globalFilter,\n ]\n );\n\n const iframeTableProps = { ...tableProps, defaultSettings, id: printTableId };\n\n useGlobalKeyDown({ key: 'p', meta: true, shift: false }, (event: KeyboardEvent) => {\n event.preventDefault();\n // Starts custom printing\n buttonRef.current?.click();\n });\n\n const handleLoadingError = (error: any) => {\n const errorMessage = `${texts.table3.print.error}: ${error}`;\n\n console.error(errorMessage);\n loadingToastRef.current?.error(errorMessage);\n };\n\n const restoreTableDataWithoutSearch = async () => {\n try {\n await tableMeta.printing.loadAll?.(table.getState().sorting, table.getState().columnFilters, undefined);\n } catch (error) {\n handleLoadingError(error);\n return;\n }\n };\n\n const handleAfterPrint = async () => {\n if (tableMeta.printing.loadAll && excludeUnmatchedResults) {\n await restoreTableDataWithoutSearch();\n }\n setIsPrinting(false);\n loadingToastRef.current?.close();\n };\n\n const handleBeforePrint = () => {\n loadingToastRef.current?.close();\n };\n\n const handlePrint = async () => {\n loadingToastRef.current = toast.loading(texts.table3.print.loading as any);\n\n const getCellCount = (data: TType[]) => (data.length ? data.length * Object.keys(data[0]).length : 0);\n let hasNonSafeCellCount = false;\n\n // if loadAll is not defined, just print with what we've got\n // don't compare length to data.length because the api might be choosing not to return all for performance\n if (!tableMeta.printing.loadAll) {\n const { data } = tableProps;\n const cellCount = getCellCount(data);\n\n hasNonSafeCellCount = cellCount > SAFE_PRINT_CELL_COUNT;\n } else {\n try {\n await tableMeta.printing.loadAll(\n table.getState().sorting,\n table.getState().columnFilters,\n // We need to pass search query to the server when printing, to be able to render correct data set in iFrame,\n // But in \"display\" table, search is performed only on client side, so we'll need to request data again without search query,\n // when printing will be finished.\n excludeUnmatchedResults ? tableMeta.search.query : undefined\n );\n\n // After the loadAll call above, the data changes. Hence, it becomes essential to acquire the data after\n // this call rather than before it.\n const { data } = tableProps;\n const cellCount = getCellCount(data);\n\n hasNonSafeCellCount = cellCount > SAFE_PRINT_CELL_COUNT;\n } catch (error) {\n handleLoadingError(error);\n\n // in case of error, we return early\n return;\n }\n }\n\n if (hasNonSafeCellCount && printWarningDialogVisibility) {\n setShowWarningDialog(true);\n } else {\n // only set printing (mount the iframe) when the data has loaded, it prevents repaint performance slow downs\n setIsPrinting(true);\n }\n };\n\n const handleWarningDialogAccept = () => {\n setIsPrinting(true);\n };\n\n const handleWarningDialogCancel = async () => {\n if (tableMeta.printing.loadAll && excludeUnmatchedResults) {\n await restoreTableDataWithoutSearch();\n }\n };\n\n const handleWarningDialogClose = () => {\n loadingToastRef.current?.close();\n setShowWarningDialog(false);\n };\n\n return (\n <>\n <IconButton\n disabled={isPrinting}\n icon=\"print\"\n onClick={handlePrint}\n aria-label={texts.table3.print.tooltip}\n tooltip={texts.table3.print.tooltip}\n ref={buttonRef}\n />\n {isPrinting && iframeTableProps.data !== null && (\n <PrintIFrame\n onAfterPrint={handleAfterPrint}\n onBeforePrint={handleBeforePrint}\n tableProps={iframeTableProps as Table3Props<TType>}\n />\n )}\n <WarningDialog\n open={showWarningDialog}\n onAccept={handleWarningDialogAccept}\n onClose={handleWarningDialogClose}\n onCancel={handleWarningDialogCancel}\n onVisibilityChange={tableMeta.printing.setPrintWarningDialogVisibility}\n />\n </>\n );\n}\n"],"names":["SAFE_PRINT_CELL_COUNT","PrintButton","props","table","tableProps","texts","useLocalization","toast","useToast","isPrinting","setIsPrinting","React","useState","showWarningDialog","setShowWarningDialog","loadingToastRef","useRef","buttonRef","tableMeta","options","meta","state","getState","printWarningDialogVisibility","printing","printTableId","id","excludeUnmatchedResults","search","defaultSettings","useMemo","columnFreezingIndex","columnFreezing","frozenColumnIndex","columnOrder","columnSizing","columnVisibility","excludeUnmatchedRecordsInSearch","fontSize","size","rowHeight","height","sorting","columnFilters","globalFilter","iframeTableProps","useGlobalKeyDown","key","shift","event","preventDefault","_buttonRef$current","current","click","handleLoadingError","error","errorMessage","table3","print","console","_loadingToastRef$curr","restoreTableDataWithoutSearch","_tableMeta$printing$l","_tableMeta$printing","Promise","resolve","loadAll","call","undefined","then","_temp","e","reject","handleAfterPrint","_loadingToastRef$curr2","close","_temp2","_temp3","handleBeforePrint","_loadingToastRef$curr3","handlePrint","hasNonSafeCellCount","loading","getCellCount","data","length","Object","keys","_temp5","cellCount","_temp4","_catch","query","_exit","_temp6","handleWarningDialogAccept","handleWarningDialogCancel","_temp7","handleWarningDialogClose","_loadingToastRef$curr4","IconButton","disabled","icon","onClick","tooltip","ref","PrintIFrame","onAfterPrint","onBeforePrint","WarningDialog","open","onAccept","onClose","onCancel","onVisibilityChange","setPrintWarningDialogVisibility"],"mappings":";;;;;;;;;AAWA,MAAMA,qBAAqB,GAAG,KAAK;SAOnBC,WAAWA,CAAkBC,KAA8B;EACvE,MAAM;IAAEC,KAAK;IAAEC;GAAY,GAAGF,KAAK;EACnC,MAAM;IAAEG;GAAO,GAAGC,eAAe,EAAE;EACnC,MAAMC,KAAK,GAAGC,QAAQ,EAAE;EAExB,MAAM,CAACC,UAAU,EAAEC,aAAa,CAAC,GAAGC,cAAK,CAACC,QAAQ,CAAC,KAAK,CAAC;EACzD,MAAM,CAACC,iBAAiB,EAAEC,oBAAoB,CAAC,GAAGH,cAAK,CAACC,QAAQ,C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AA,IAAAA,MAAA,CAAA5B,IAAA,GAAA4B,MAAA,CAAA5B,IAAA;KAE5C,QAAAE,CAAA;MAAA,OAAAP,OAAA,CAAAQ,MAAA,CAAAD,CAAA;;;EAED,MAAM2B,wBAAwB,GAAGA;;IAC7B,CAAAC,sBAAA,GAAApF,eAAe,CAACqC,OAAO,cAAA+C,sBAAA,uBAAvBA,sBAAA,CAAyBxB,KAAK,EAAE;IAChC7D,oBAAoB,CAAC,KAAK,CAAC;GAC9B;EAED,oBACIH,yEACIA,6BAACyF,UAAU;IACPC,QAAQ,EAAE5F,UAAU;IACpB6F,IAAI,EAAC,OAAO;IACZC,OAAO,EAAEvB,WAAW;kBACR3E,KAAK,CAACoD,MAAM,CAACC,KAAK,CAAC8C,OAAO;IACtCA,OAAO,EAAEnG,KAAK,CAACoD,MAAM,CAACC,KAAK,CAAC8C,OAAO;IACnCC,GAAG,EAAExF;IACP,EACDR,UAAU,IAAIoC,gBAAgB,CAACuC,IAAI,KAAK,IAAI,iBACzCzE,6BAAC+F,WAAW;IACRC,YAAY,EAAElC,gBAAgB;IAC9BmC,aAAa,EAAE9B,iBAAiB;IAChC1E,UAAU,EAAEyC;IAEnB,eACDlC,6BAACkG,aAAa;IACVC,IAAI,EAAEjG,iBAAiB;IACvBkG,QAAQ,EAAEhB,yBAAyB;IACnCiB,OAAO,EAAEd,wBAAwB;IACjCe,QAAQ,EAAEjB,yBAAyB;IACnCkB,kBAAkB,EAAEhG,SAAS,CAACM,QAAQ,CAAC2F;IACzC,CACH;AAEX;;;;"}
|
package/dist/esm/packages/taco/src/components/Table3/components/toolbar/PrintButton/PrintIFrame.js
CHANGED
|
@@ -66,14 +66,14 @@ import '../../../../../hooks/useBoundaryOverflowDetection.js';
|
|
|
66
66
|
import '../../../../Table2/Table2.js';
|
|
67
67
|
import '../../../../../hooks/useLazyEffect.js';
|
|
68
68
|
import '../../../../Textarea/Textarea.js';
|
|
69
|
+
import '../../../../../hooks/useMatchMedia.js';
|
|
70
|
+
import '../../../../../hooks/useIsLargeScreen.js';
|
|
69
71
|
import { useParentStylesheets } from './hooks/useParentStylesheets.js';
|
|
70
72
|
import '../../../hooks/useTableDataLoader.js';
|
|
71
73
|
import { Table3 } from '../../../Table3.js';
|
|
72
74
|
import '../../../../Tabs/Tabs.js';
|
|
73
75
|
import '../../../../Tour/Tour.js';
|
|
74
|
-
import '../../../../../hooks/useMatchMedia.js';
|
|
75
76
|
import '../../../../Header/Header.js';
|
|
76
|
-
import '../../../../../hooks/useIsLargeScreen.js';
|
|
77
77
|
import '../../../../Layout/Layout.js';
|
|
78
78
|
import '../../../../Navigation2/components/Link.js';
|
|
79
79
|
import '../../../../Navigation2/Navigation2.js';
|
|
@@ -87,6 +87,7 @@ function PrintIFrame({
|
|
|
87
87
|
const [contentRef, setContentRef] = React__default.useState(null);
|
|
88
88
|
const [mountNode, setMountNode] = React__default.useState(null);
|
|
89
89
|
const isFirefoxBrowser = React__default.useMemo(() => navigator.userAgent.toLowerCase().includes('firefox'), []);
|
|
90
|
+
const isSafariBrowser = React__default.useMemo(() => navigator.userAgent.toLowerCase().includes('safari') && !navigator.userAgent.toLowerCase().includes('chrome'), []);
|
|
90
91
|
const iframeWindow = contentRef === null || contentRef === void 0 ? void 0 : contentRef.contentWindow;
|
|
91
92
|
const stylesReady = useParentStylesheets(iframeWindow);
|
|
92
93
|
// Calls print method when table has loaded in the iframe.
|
|
@@ -155,13 +156,16 @@ function PrintIFrame({
|
|
|
155
156
|
tableWrapper.classList.add('h-fit');
|
|
156
157
|
tableWrapper.classList.add('[&>[role="table"]]:!h-fit');
|
|
157
158
|
if (isFirefoxBrowser) {
|
|
158
|
-
// Fix for firefox bug which adds page-long whitespace between page's top content and table
|
|
159
|
+
// Fix for firefox bug which adds page-long whitespace between page's top content and table.
|
|
159
160
|
tableWrapper.classList.add('[&>[role="table"]]:!absolute');
|
|
160
161
|
}
|
|
161
|
-
//
|
|
162
|
-
|
|
163
|
-
|
|
164
|
-
|
|
162
|
+
// Makes sure table takes the full screen width.
|
|
163
|
+
if (isSafariBrowser) {
|
|
164
|
+
// Safari browser doesn't apply correct width to the columns when w-screen is used.
|
|
165
|
+
tableWrapper.classList.add('w-full');
|
|
166
|
+
} else {
|
|
167
|
+
tableWrapper.classList.add('w-screen');
|
|
168
|
+
}
|
|
165
169
|
if (tableElement) {
|
|
166
170
|
var _tableElement$parentN;
|
|
167
171
|
(_tableElement$parentN = tableElement.parentNode) === null || _tableElement$parentN === void 0 ? void 0 : _tableElement$parentN.insertBefore(tableWrapper, tableElement);
|
|
@@ -206,7 +210,7 @@ function PrintIFrame({
|
|
|
206
210
|
};
|
|
207
211
|
// -top-60 -left-60 styles make sure that iframe is added outside of the viewport
|
|
208
212
|
return /*#__PURE__*/React__default.createElement("iframe", {
|
|
209
|
-
className: "fixed -left-
|
|
213
|
+
className: "fixed -left-[6000px] -top-[6000px] -z-50 !h-0 !w-0",
|
|
210
214
|
ref: setContentRef,
|
|
211
215
|
// Temporary fix to support printing in firefox: Find another solution while upgrading React
|
|
212
216
|
src: "javascript:void(0);"
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"PrintIFrame.js","sources":["../../../../../../../../../../src/components/Table3/components/toolbar/PrintButton/PrintIFrame.tsx"],"sourcesContent":["import React from 'react';\nimport ReactDOM from 'react-dom';\n\nimport { Table3 } from '../../../../..';\nimport { Table3Props } from '../../../types';\nimport { useParentStylesheets } from './hooks/useParentStylesheets';\n\nexport type PrintIFrameProps<TType = unknown> = {\n onAfterPrint?: () => void;\n onBeforePrint?: () => void;\n tableProps: Table3Props<TType>;\n};\n\nexport function PrintIFrame<TType = unknown>({ onAfterPrint, onBeforePrint, tableProps }: PrintIFrameProps<TType>) {\n const [contentRef, setContentRef] = React.useState<HTMLIFrameElement | null>(null);\n const [mountNode, setMountNode] = React.useState<HTMLElement | null>(null);\n\n const isFirefoxBrowser = React.useMemo(() => navigator.userAgent.toLowerCase().includes('firefox'), []);\n\n const iframeWindow = contentRef?.contentWindow;\n\n const stylesReady = useParentStylesheets(iframeWindow);\n\n // Calls print method when table has loaded in the iframe.\n React.useEffect(() => {\n let intervalId: NodeJS.Timer;\n let timeoutId: NodeJS.Timer;\n\n // Invoke the print functionality on the window once the table has finished rendering and all print styles are\n // added.\n if (mountNode && stylesReady) {\n intervalId = setInterval(async () => {\n const tableWrapper = mountNode;\n const table = tableWrapper.querySelector('[role=\"table\"]') as HTMLElement;\n const hasTableRendered = !!table;\n\n if (hasTableRendered && intervalId) {\n clearInterval(intervalId);\n\n // Calling the onBeforePrint method here as a fallback because certain browsers, like Safari,\n // do not call the beforeprint event.\n // Bug - Even though onBeforePrint is called before printing, the execution doesn't finish before\n // the print dialog shows up, which results into having a visible loading toast.\n onBeforePrint?.();\n\n // By adding height to the tableWrapper, we make sure the content below absolutely positioned table\n // doesn't hide\n if (isFirefoxBrowser) {\n const tableHeight = `${table.offsetHeight}px`;\n tableWrapper.style.height = tableHeight;\n }\n\n contentRef?.contentWindow?.print();\n\n // Calling the onAfterPrint method here as a fallback to do the cleanup, as certain browsers,\n // like Safari, do not trigger the beforeprint or afterprint events when a confirmation dialog\n // asking if the user wants to print the document, is cancelled.\n\n // Added a setTimeout to prevent calling onAfterPrint immediately after the print function\n // to ensure that the print dialog doesn't close abruptly. Although this behavior is uncommon,\n // there are cases where the print function may not run synchronously, causing onAfterPrint to be\n // invoked right after it.\n timeoutId = setTimeout(() => {\n onAfterPrint?.();\n }, 0);\n }\n }, 1000);\n }\n\n return () => {\n clearInterval(intervalId);\n clearTimeout(timeoutId);\n };\n }, [mountNode, stylesReady]);\n\n React.useEffect(() => {\n if (!contentRef || !iframeWindow || !stylesReady) {\n return;\n }\n\n // get the closest parent/container of the table, and the table itself\n const parentElement = contentRef?.closest('[role=dialog], [data-taco=drawer], main') ?? iframeWindow.parent.document.body;\n\n const iframeDocument = iframeWindow.document;\n iframeDocument.body.innerHTML = parentElement?.innerHTML ?? '';\n\n const tableElement = iframeDocument.querySelector('[role=\"table\"]');\n const tableColumnFreezingStyles = iframeDocument.querySelector('[data-taco=\"table3-column-freezing-styles\"]');\n const tableWrapper = iframeDocument.createElement('div');\n\n tableWrapper.setAttribute('data-role', 'table-wrapper');\n // Adding h-fit class makes sure that table is rendered with the whole content.\n tableWrapper.classList.add('h-fit');\n tableWrapper.classList.add('[&>[role=\"table\"]]:!h-fit');\n\n if (isFirefoxBrowser) {\n // Fix for firefox bug which adds page-long whitespace between page's top content and table\n tableWrapper.classList.add('[&>[role=\"table\"]]:!absolute');\n }\n\n // Safari print preview assigns no width to the table when w-screen class is used.\n // By assigning table a big static width and hiding the horizontal scrollbar, the table on chrome\n // and safari will always take full page width.\n tableWrapper.classList.add('w-[10000px]');\n\n if (tableElement) {\n tableElement.parentNode?.insertBefore(tableWrapper, tableElement);\n tableElement.remove();\n } else {\n iframeDocument.body.append(tableWrapper);\n }\n\n // Remove the already existing column freezing styles.\n if (tableColumnFreezingStyles) {\n tableColumnFreezingStyles.remove();\n }\n\n let currentNode = tableWrapper.parentNode as HTMLElement | null;\n\n while (currentNode !== null && currentNode !== iframeDocument.body) {\n // Add the 'h-fit' class to the 'table-wrapper' element's parent chain.\n // This ensures that the table is not cropped and fits within its container.\n currentNode?.classList.add('!h-fit');\n currentNode = currentNode.parentNode as HTMLElement | null;\n }\n\n setMountNode(tableWrapper);\n }, [iframeWindow, stylesReady]);\n\n const printTableProps: Table3Props<TType> = {\n ...tableProps,\n actionsForRow: undefined,\n // Not the best way to remove the active/current row styles, but a temporary solution for now\n defaultCurrentRowIndex: -1,\n defaultSettings: {\n ...tableProps?.defaultSettings,\n rowHeight: 'short',\n },\n enableColumnFreezing: false,\n enableRowHeight: true,\n enableRowSelection: false,\n enableEditing: false,\n enablePrinting: false,\n enableRowDrag: false,\n enableRowDrop: false,\n enableRowSelectionSingle: false,\n preset: undefined,\n // The presence of the onChangeSettings prop ensures that settings won't be stored in local storage.\n onChangeSettings: () => undefined,\n };\n\n // -top-60 -left-60 styles make sure that iframe is added outside of the viewport\n return (\n <iframe\n className=\"fixed -left-60 -top-60 !h-0 !w-0\"\n ref={setContentRef}\n // Temporary fix to support printing in firefox: Find another solution while upgrading React\n src=\"javascript:void(0);\">\n {mountNode && stylesReady ? ReactDOM.createPortal(<Table3 {...printTableProps} />, mountNode) : null}\n </iframe>\n );\n}\n"],"names":["PrintIFrame","onAfterPrint","onBeforePrint","tableProps","contentRef","setContentRef","React","useState","mountNode","setMountNode","isFirefoxBrowser","useMemo","navigator","userAgent","toLowerCase","includes","iframeWindow","contentWindow","stylesReady","useParentStylesheets","useEffect","intervalId","timeoutId","setInterval","tableWrapper","table","querySelector","hasTableRendered","_contentRef$contentWi","clearInterval","tableHeight","offsetHeight","style","height","print","setTimeout","Promise","resolve","e","reject","clearTimeout","parentElement","_contentRef$closest","closest","parent","document","body","iframeDocument","innerHTML","_parentElement$innerH","tableElement","tableColumnFreezingStyles","createElement","setAttribute","classList","add","_tableElement$parentN","parentNode","insertBefore","remove","append","currentNode","_currentNode","printTableProps","actionsForRow","undefined","defaultCurrentRowIndex","defaultSettings","rowHeight","enableColumnFreezing","enableRowHeight","enableRowSelection","enableEditing","enablePrinting","enableRowDrag","enableRowDrop","enableRowSelectionSingle","preset","onChangeSettings","className","ref","src","ReactDOM","createPortal","Table3"],"mappings":";;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;SAagBA,WAAWA,CAAkB;EAAEC,YAAY;EAAEC,aAAa;EAAEC;CAAqC;EAC7G,MAAM,CAACC,UAAU,EAAEC,aAAa,CAAC,GAAGC,cAAK,CAACC,QAAQ,CAA2B,IAAI,CAAC;EAClF,MAAM,CAACC,SAAS,EAAEC,YAAY,CAAC,GAAGH,cAAK,CAACC,QAAQ,CAAqB,IAAI,CAAC;EAE1E,MAAMG,gBAAgB,GAAGJ,cAAK,CAACK,OAAO,CAAC,MAAMC,SAAS,CAACC,SAAS,CAACC,WAAW,EAAE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AKrB,eAAe,EAAI,EAAEvD,SAAS,CAAC,GAAG,IAAI,CAC/F;AAEjB;;;;"}
|
|
1
|
+
{"version":3,"file":"PrintIFrame.js","sources":["../../../../../../../../../../src/components/Table3/components/toolbar/PrintButton/PrintIFrame.tsx"],"sourcesContent":["import React from 'react';\nimport ReactDOM from 'react-dom';\n\nimport { Table3 } from '../../../../..';\nimport { Table3Props } from '../../../types';\nimport { useParentStylesheets } from './hooks/useParentStylesheets';\n\nexport type PrintIFrameProps<TType = unknown> = {\n onAfterPrint?: () => void;\n onBeforePrint?: () => void;\n tableProps: Table3Props<TType>;\n};\n\nexport function PrintIFrame<TType = unknown>({ onAfterPrint, onBeforePrint, tableProps }: PrintIFrameProps<TType>) {\n const [contentRef, setContentRef] = React.useState<HTMLIFrameElement | null>(null);\n const [mountNode, setMountNode] = React.useState<HTMLElement | null>(null);\n\n const isFirefoxBrowser = React.useMemo(() => navigator.userAgent.toLowerCase().includes('firefox'), []);\n const isSafariBrowser = React.useMemo(\n () => navigator.userAgent.toLowerCase().includes('safari') && !navigator.userAgent.toLowerCase().includes('chrome'),\n []\n );\n\n const iframeWindow = contentRef?.contentWindow;\n\n const stylesReady = useParentStylesheets(iframeWindow);\n\n // Calls print method when table has loaded in the iframe.\n React.useEffect(() => {\n let intervalId: NodeJS.Timer;\n let timeoutId: NodeJS.Timer;\n\n // Invoke the print functionality on the window once the table has finished rendering and all print styles are\n // added.\n if (mountNode && stylesReady) {\n intervalId = setInterval(async () => {\n const tableWrapper = mountNode;\n const table = tableWrapper.querySelector('[role=\"table\"]') as HTMLElement;\n const hasTableRendered = !!table;\n\n if (hasTableRendered && intervalId) {\n clearInterval(intervalId);\n\n // Calling the onBeforePrint method here as a fallback because certain browsers, like Safari,\n // do not call the beforeprint event.\n // Bug - Even though onBeforePrint is called before printing, the execution doesn't finish before\n // the print dialog shows up, which results into having a visible loading toast.\n onBeforePrint?.();\n\n // By adding height to the tableWrapper, we make sure the content below absolutely positioned table\n // doesn't hide\n if (isFirefoxBrowser) {\n const tableHeight = `${table.offsetHeight}px`;\n tableWrapper.style.height = tableHeight;\n }\n\n contentRef?.contentWindow?.print();\n\n // Calling the onAfterPrint method here as a fallback to do the cleanup, as certain browsers,\n // like Safari, do not trigger the beforeprint or afterprint events when a confirmation dialog\n // asking if the user wants to print the document, is cancelled.\n\n // Added a setTimeout to prevent calling onAfterPrint immediately after the print function\n // to ensure that the print dialog doesn't close abruptly. Although this behavior is uncommon,\n // there are cases where the print function may not run synchronously, causing onAfterPrint to be\n // invoked right after it.\n timeoutId = setTimeout(() => {\n onAfterPrint?.();\n }, 0);\n }\n }, 1000);\n }\n\n return () => {\n clearInterval(intervalId);\n clearTimeout(timeoutId);\n };\n }, [mountNode, stylesReady]);\n\n React.useEffect(() => {\n if (!contentRef || !iframeWindow || !stylesReady) {\n return;\n }\n\n // get the closest parent/container of the table, and the table itself\n const parentElement = contentRef?.closest('[role=dialog], [data-taco=drawer], main') ?? iframeWindow.parent.document.body;\n\n const iframeDocument = iframeWindow.document;\n iframeDocument.body.innerHTML = parentElement?.innerHTML ?? '';\n\n const tableElement = iframeDocument.querySelector('[role=\"table\"]');\n const tableColumnFreezingStyles = iframeDocument.querySelector('[data-taco=\"table3-column-freezing-styles\"]');\n const tableWrapper = iframeDocument.createElement('div');\n\n tableWrapper.setAttribute('data-role', 'table-wrapper');\n // Adding h-fit class makes sure that table is rendered with the whole content.\n tableWrapper.classList.add('h-fit');\n tableWrapper.classList.add('[&>[role=\"table\"]]:!h-fit');\n\n if (isFirefoxBrowser) {\n // Fix for firefox bug which adds page-long whitespace between page's top content and table.\n tableWrapper.classList.add('[&>[role=\"table\"]]:!absolute');\n }\n\n // Makes sure table takes the full screen width.\n if (isSafariBrowser) {\n // Safari browser doesn't apply correct width to the columns when w-screen is used.\n tableWrapper.classList.add('w-full');\n } else {\n tableWrapper.classList.add('w-screen');\n }\n\n if (tableElement) {\n tableElement.parentNode?.insertBefore(tableWrapper, tableElement);\n tableElement.remove();\n } else {\n iframeDocument.body.append(tableWrapper);\n }\n\n // Remove the already existing column freezing styles.\n if (tableColumnFreezingStyles) {\n tableColumnFreezingStyles.remove();\n }\n\n let currentNode = tableWrapper.parentNode as HTMLElement | null;\n\n while (currentNode !== null && currentNode !== iframeDocument.body) {\n // Add the 'h-fit' class to the 'table-wrapper' element's parent chain.\n // This ensures that the table is not cropped and fits within its container.\n currentNode?.classList.add('!h-fit');\n currentNode = currentNode.parentNode as HTMLElement | null;\n }\n\n setMountNode(tableWrapper);\n }, [iframeWindow, stylesReady]);\n\n const printTableProps: Table3Props<TType> = {\n ...tableProps,\n actionsForRow: undefined,\n // Not the best way to remove the active/current row styles, but a temporary solution for now\n defaultCurrentRowIndex: -1,\n defaultSettings: {\n ...tableProps?.defaultSettings,\n rowHeight: 'short',\n },\n enableColumnFreezing: false,\n enableRowHeight: true,\n enableRowSelection: false,\n enableEditing: false,\n enablePrinting: false,\n enableRowDrag: false,\n enableRowDrop: false,\n enableRowSelectionSingle: false,\n preset: undefined,\n // The presence of the onChangeSettings prop ensures that settings won't be stored in local storage.\n onChangeSettings: () => undefined,\n };\n\n // -top-60 -left-60 styles make sure that iframe is added outside of the viewport\n return (\n <iframe\n className=\"fixed -left-[6000px] -top-[6000px] -z-50 !h-0 !w-0\"\n ref={setContentRef}\n // Temporary fix to support printing in firefox: Find another solution while upgrading React\n src=\"javascript:void(0);\">\n {mountNode && stylesReady ? ReactDOM.createPortal(<Table3 {...printTableProps} />, mountNode) : null}\n </iframe>\n );\n}\n"],"names":["PrintIFrame","onAfterPrint","onBeforePrint","tableProps","contentRef","setContentRef","React","useState","mountNode","setMountNode","isFirefoxBrowser","useMemo","navigator","userAgent","toLowerCase","includes","isSafariBrowser","iframeWindow","contentWindow","stylesReady","useParentStylesheets","useEffect","intervalId","timeoutId","setInterval","tableWrapper","table","querySelector","hasTableRendered","_contentRef$contentWi","clearInterval","tableHeight","offsetHeight","style","height","print","setTimeout","Promise","resolve","e","reject","clearTimeout","parentElement","_contentRef$closest","closest","parent","document","body","iframeDocument","innerHTML","_parentElement$innerH","tableElement","tableColumnFreezingStyles","createElement","setAttribute","classList","add","_tableElement$parentN","parentNode","insertBefore","remove","append","currentNode","_currentNode","printTableProps","actionsForRow","undefined","defaultCurrentRowIndex","defaultSettings","rowHeight","enableColumnFreezing","enableRowHeight","enableRowSelection","enableEditing","enablePrinting","enableRowDrag","enableRowDrop","enableRowSelectionSingle","preset","onChangeSettings","className","ref","src","ReactDOM","createPortal","Table3"],"mappings":";;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;SAagBA,WAAWA,CAAkB;EAAEC,YAAY;EAAEC,aAAa;EAAEC;CAAqC;EAC7G,MAAM,CAACC,UAAU,EAAEC,aAAa,CAAC,GAAGC,cAAK,CAACC,QAAQ,CAA2B,IAAI,CAAC;EAClF,MAAM,CAACC,SAAS,EAAEC,YAAY,CAAC,GAAGH,cAAK,CAACC,QAAQ,CAAqB,IAAI,CAAC;EAE1E,MAAMG,gBAAgB,GAAGJ,cAAK,CAACK,OAAO,CAAC,MAAMC,SAAS,CAACC,SAAS,CAACC,WAAW,EAAE,CAACC,QAAQ,CAAC,SAAS,CAAC,EAAE,EAAE,CAAC;EACvG,MAAMC,eAAe,GAAGV,cAAK,CAACK,OAAO,CACjC,MAAMC,SAAS,CAACC,SAAS,CAACC,WAAW,EAAE,CAACC,QAAQ,CAAC,QAAQ,CAAC,IAAI,CAACH,SAAS,CAACC,SAAS,CAACC,WAAW,EAAE,CAACC,QAAQ,CAAC,QAAQ,CAAC,EACnH,EAAE,CACL;EAED,MAAME,YAAY,GAAGb,UAAU,aAAVA,UAAU,uBAAVA,UAAU,CAAEc,aAAa;EAE9C,MAAMC,WAAW,GAAGC,oBAAoB,CAACH,YAAY,CAAC;;EAGtDX,cAAK,CAACe,SAAS,CAAC;IACZ,IAAIC,UAAwB;IAC5B,IAAIC,SAAuB;;;IA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from '../../../../Group/Group.js';
|
|
|
8
8
|
|
|
9
9
|
const WarningDialog = ({
|
|
10
10
|
onAccept,
|
|
11
|
+
onCancel,
|
|
11
12
|
onClose,
|
|
12
13
|
onVisibilityChange,
|
|
13
14
|
...props
|
|
@@ -41,7 +42,10 @@ const WarningDialog = ({
|
|
|
41
42
|
checked: hideWarningDialog,
|
|
42
43
|
onChange: setHideWarningDialog
|
|
43
44
|
}), /*#__PURE__*/React__default.createElement(Group, null, /*#__PURE__*/React__default.createElement(Button, {
|
|
44
|
-
onClick:
|
|
45
|
+
onClick: () => {
|
|
46
|
+
handleClose();
|
|
47
|
+
onCancel();
|
|
48
|
+
}
|
|
45
49
|
}, texts.table3.print.warningDialog.cancelButtonText), /*#__PURE__*/React__default.createElement(Button, {
|
|
46
50
|
appearance: "primary",
|
|
47
51
|
autoFocus: true,
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"WarningDialog.js","sources":["../../../../../../../../../../src/components/Table3/components/toolbar/PrintButton/WarningDialog.tsx"],"sourcesContent":["import React from 'react';\n\nimport { BadgeIcon } from '../../../../BadgeIcon/BadgeIcon';\nimport { Button } from '../../../../Button/Button';\nimport { Checkbox } from '../../../../Checkbox/Checkbox';\nimport { Dialog, DialogProps } from '../../../../Dialog/Dialog';\nimport { Group } from '../../../../Group/Group';\nimport { useLocalization } from '../../../../Provider/Localization';\n\nexport type WarningDialogProps = Omit<DialogProps, 'children' | 'onClose'> & {\n onAccept: () => void;\n onClose: () => void;\n onVisibilityChange: React.Dispatch<React.SetStateAction<boolean>>;\n};\n\nexport const WarningDialog = ({ onAccept, onClose, onVisibilityChange, ...props }: WarningDialogProps) => {\n const [hideWarningDialog, setHideWarningDialog] = React.useState(false);\n const { texts } = useLocalization();\n const handleClose = () => {\n onClose();\n // Change visibility state when the dialog is closing\n onVisibilityChange?.(!hideWarningDialog);\n };\n\n return (\n <Dialog {...props} closeOnEscape={true} onClose={handleClose} showCloseButton={false} size=\"xs\">\n <Dialog.Content aria-label={texts.table3.print.warningDialog.title}>\n <Dialog.Title className=\"text-center\">\n <BadgeIcon icon=\"warning\" color=\"yellow\" className=\"mr-2\" />\n {texts.table3.print.warningDialog.title}\n </Dialog.Title>\n <p>{texts.table3.print.warningDialog.description}</p>\n <Dialog.Footer className=\"flex items-center justify-between\">\n <Checkbox\n label={texts.table3.print.warningDialog.checkboxVisibilityLabel}\n checked={hideWarningDialog}\n onChange={setHideWarningDialog}\n />\n <Group>\n <Button
|
|
1
|
+
{"version":3,"file":"WarningDialog.js","sources":["../../../../../../../../../../src/components/Table3/components/toolbar/PrintButton/WarningDialog.tsx"],"sourcesContent":["import React from 'react';\n\nimport { BadgeIcon } from '../../../../BadgeIcon/BadgeIcon';\nimport { Button } from '../../../../Button/Button';\nimport { Checkbox } from '../../../../Checkbox/Checkbox';\nimport { Dialog, DialogProps } from '../../../../Dialog/Dialog';\nimport { Group } from '../../../../Group/Group';\nimport { useLocalization } from '../../../../Provider/Localization';\n\nexport type WarningDialogProps = Omit<DialogProps, 'children' | 'onClose'> & {\n onAccept: () => void;\n onCancel: () => void;\n onClose: () => void;\n onVisibilityChange: React.Dispatch<React.SetStateAction<boolean>>;\n};\n\nexport const WarningDialog = ({ onAccept, onCancel, onClose, onVisibilityChange, ...props }: WarningDialogProps) => {\n const [hideWarningDialog, setHideWarningDialog] = React.useState(false);\n const { texts } = useLocalization();\n const handleClose = () => {\n onClose();\n // Change visibility state when the dialog is closing\n onVisibilityChange?.(!hideWarningDialog);\n };\n\n return (\n <Dialog {...props} closeOnEscape={true} onClose={handleClose} showCloseButton={false} size=\"xs\">\n <Dialog.Content aria-label={texts.table3.print.warningDialog.title}>\n <Dialog.Title className=\"text-center\">\n <BadgeIcon icon=\"warning\" color=\"yellow\" className=\"mr-2\" />\n {texts.table3.print.warningDialog.title}\n </Dialog.Title>\n <p>{texts.table3.print.warningDialog.description}</p>\n <Dialog.Footer className=\"flex items-center justify-between\">\n <Checkbox\n label={texts.table3.print.warningDialog.checkboxVisibilityLabel}\n checked={hideWarningDialog}\n onChange={setHideWarningDialog}\n />\n <Group>\n <Button\n onClick={() => {\n handleClose();\n onCancel();\n }}>\n {texts.table3.print.warningDialog.cancelButtonText}\n </Button>\n <Button\n appearance=\"primary\"\n autoFocus\n onClick={() => {\n handleClose();\n onAccept();\n }}>\n {texts.table3.print.warningDialog.printButtonText}\n </Button>\n </Group>\n </Dialog.Footer>\n </Dialog.Content>\n </Dialog>\n );\n};\n"],"names":["WarningDialog","onAccept","onCancel","onClose","onVisibilityChange","props","hideWarningDialog","setHideWarningDialog","React","useState","texts","useLocalization","handleClose","Dialog","closeOnEscape","showCloseButton","size","Content","table3","print","warningDialog","title","Title","className","BadgeIcon","icon","color","description","Footer","Checkbox","label","checkboxVisibilityLabel","checked","onChange","Group","Button","onClick","cancelButtonText","appearance","autoFocus","printButtonText"],"mappings":";;;;;;;;MAgBaA,aAAa,GAAGA,CAAC;EAAEC,QAAQ;EAAEC,QAAQ;EAAEC,OAAO;EAAEC,kBAAkB;EAAE,GAAGC;CAA2B;EAC3G,MAAM,CAACC,iBAAiB,EAAEC,oBAAoB,CAAC,GAAGC,cAAK,CAACC,QAAQ,CAAC,KAAK,CAAC;EACvE,MAAM;IAAEC;GAAO,GAAGC,eAAe,EAAE;EACnC,MAAMC,WAAW,GAAGA;IAChBT,OAAO,EAAE;;IAETC,kBAAkB,aAAlBA,kBAAkB,uBAAlBA,kBAAkB,CAAG,CAACE,iBAAiB,CAAC;GAC3C;EAED,oBACIE,6BAACK,MAAM,oBAAKR,KAAK;IAAES,aAAa,EAAE,IAAI;IAAEX,OAAO,EAAES,WAAW;IAAEG,eAAe,EAAE,KAAK;IAAEC,IAAI,EAAC;mBACvFR,6BAACK,MAAM,CAACI,OAAO;kBAAaP,KAAK,CAACQ,MAAM,CAACC,KAAK,CAACC,aAAa,CAACC;kBACzDb,6BAACK,MAAM,CAACS,KAAK;IAACC,SAAS,EAAC;kBACpBf,6BAACgB,SAAS;IAACC,IAAI,EAAC,SAAS;IAACC,KAAK,EAAC,QAAQ;IAACH,SAAS,EAAC;IAAS,EAC3Db,KAAK,CAACQ,MAAM,CAACC,KAAK,CAACC,aAAa,CAACC,KAAK,CAC5B,eACfb,wCAAIE,KAAK,CAACQ,MAAM,CAACC,KAAK,CAACC,aAAa,CAACO,WAAW,CAAK,eACrDnB,6BAACK,MAAM,CAACe,MAAM;IAACL,SAAS,EAAC;kBACrBf,6BAACqB,QAAQ;IACLC,KAAK,EAAEpB,KAAK,CAACQ,MAAM,CAACC,KAAK,CAACC,aAAa,CAACW,uBAAuB;IAC/DC,OAAO,EAAE1B,iBAAiB;IAC1B2B,QAAQ,EAAE1B;IACZ,eACFC,6BAAC0B,KAAK,qBACF1B,6BAAC2B,MAAM;IACHC,OAAO,EAAEA;MACLxB,WAAW,EAAE;MACbV,QAAQ,EAAE;;KAEbQ,KAAK,CAACQ,MAAM,CAACC,KAAK,CAACC,aAAa,CAACiB,gBAAgB,CAC7C,eACT7B,6BAAC2B,MAAM;IACHG,UAAU,EAAC,SAAS;IACpBC,SAAS;IACTH,OAAO,EAAEA;MACLxB,WAAW,EAAE;MACbX,QAAQ,EAAE;;KAEbS,KAAK,CAACQ,MAAM,CAACC,KAAK,CAACC,aAAa,CAACoB,eAAe,CAC5C,CACL,CACI,CACH,CACZ;AAEjB;;;;"}
|
|
@@ -136,10 +136,10 @@ function resetHighlightedColumnIndexes(enabled, value, table) {
|
|
|
136
136
|
columns.forEach((column, columnIndex) => {
|
|
137
137
|
try {
|
|
138
138
|
var _column$columnDef$met;
|
|
139
|
-
if ((_column$columnDef$met = column.columnDef.meta) !== null && _column$columnDef$met !== void 0 && _column$columnDef$met.enableSearch) {
|
|
139
|
+
if (column.getIsVisible() && (_column$columnDef$met = column.columnDef.meta) !== null && _column$columnDef$met !== void 0 && _column$columnDef$met.enableSearch) {
|
|
140
140
|
var _row$original, _column$columnDef$met2;
|
|
141
141
|
const cellValue = getCellValueAsString((_row$original = row.original) === null || _row$original === void 0 ? void 0 : _row$original[column.id], (_column$columnDef$met2 = column.columnDef.meta) === null || _column$columnDef$met2 === void 0 ? void 0 : _column$columnDef$met2.dataType);
|
|
142
|
-
if (cellValue && globalFilterFn(cellValue, value)) {
|
|
142
|
+
if (cellValue !== undefined && globalFilterFn(cellValue, value)) {
|
|
143
143
|
indexes.push([rowIndex, columnIndex]);
|
|
144
144
|
}
|
|
145
145
|
}
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"Search.js","sources":["../../../../../../../../../src/components/Table3/components/toolbar/Search.tsx"],"sourcesContent":["import React from 'react';\nimport { Table as RTable, TableMeta } from '@tanstack/react-table';\nimport { useLocalization } from '../../../Provider/Localization';\nimport { Switch } from '../../../Switch/Switch';\nimport { globalFilterFn } from '../../util/filtering';\nimport { SearchInput2 } from '../../../SearchInput2/SearchInput2';\nimport { useDebouncedEffect } from '../../../../hooks/useDebouncedEffect';\nimport { getCellValueAsString } from '../../util/columns';\n\ntype SearchProps<TType = unknown> = {\n scrollToIndex: any;\n table: RTable<TType>;\n};\n\nenum LoadingState {\n Incomplete,\n Loading,\n Completed,\n}\n\nexport function Search<TType = unknown>(props: SearchProps<TType>) {\n const { scrollToIndex, table } = props;\n const { texts } = useLocalization();\n const ref = React.useRef<HTMLInputElement>(null);\n const tableMeta = table.options.meta as TableMeta<TType>;\n const [query, setQuery] = React.useState(tableMeta.search.query);\n const [loading, setLoading] = React.useState<LoadingState>(LoadingState.Incomplete);\n\n const scrollTo = (rowIndex: number) => scrollToIndex(rowIndex, { align: 'center' });\n\n // update the indexes if the row length changes (e.g. when filtering)\n React.useEffect(() => {\n const firstRowIndex = resetHighlightedColumnIndexes(tableMeta.search.isHighlightingEnabled, ref.current?.value, table);\n\n if (firstRowIndex) {\n scrollTo(firstRowIndex);\n }\n }, [\n tableMeta.search.query,\n tableMeta.search.excludeUnmatchedResults,\n table.getRowModel().rows.length,\n JSON.stringify(table.getState().sorting),\n JSON.stringify(table.getState().columnVisibility),\n loading,\n ]);\n\n // update the table search and filtering on a debounce\n useDebouncedEffect(() => {\n tableMeta.search.setQuery(query);\n\n if (tableMeta.search.excludeUnmatchedResults) {\n if (query?.length) {\n table.setGlobalFilter(query);\n } else {\n table.resetGlobalFilter();\n }\n }\n }, [query]);\n\n const handleFocus = async () => {\n // load all data if that is possible\n if (tableMeta.search.loadAll && loading === LoadingState.Incomplete) {\n setLoading(LoadingState.Loading);\n // don't pass the search query because we need all data - not filtered data\n await tableMeta.search.loadAll(table.getState().sorting, table.getState().columnFilters, undefined);\n setLoading(LoadingState.Completed);\n }\n };\n\n const handleChange = (query: any) => {\n setQuery(String(query ?? ''));\n };\n\n const handleToggleExcludeUnmatchedResults = (enabled: boolean) => {\n tableMeta.search.toggleExcludeUnmatchedResults(enabled);\n\n if (enabled) {\n if (ref.current?.value) {\n table.setGlobalFilter(ref.current?.value);\n } else {\n table.resetGlobalFilter();\n }\n } else {\n table.resetGlobalFilter();\n }\n\n requestAnimationFrame(() => ref.current?.focus());\n };\n\n const handleNextResult = () => {\n if (!tableMeta.search.highlightedColumnIndexes.length) {\n return;\n }\n\n const nextIndex =\n tableMeta.search.currentHighlightColumnIndex === undefined ||\n tableMeta.search.currentHighlightColumnIndex === tableMeta.search.highlightedColumnIndexes.length - 1\n ? 0\n : tableMeta.search.currentHighlightColumnIndex + 1;\n\n tableMeta.search.setCurrentHighlightColumnIndex(nextIndex);\n // we scroll to the row here, the cell scrolls itself into view\n scrollTo(tableMeta.search.highlightedColumnIndexes[nextIndex][0]);\n };\n\n const handlePreviousResult = () => {\n if (!tableMeta.search.highlightedColumnIndexes.length) {\n return;\n }\n\n const nextIndex =\n tableMeta.search.currentHighlightColumnIndex === undefined\n ? 0\n : tableMeta.search.currentHighlightColumnIndex === 0\n ? tableMeta.search.highlightedColumnIndexes.length - 1\n : tableMeta.search.currentHighlightColumnIndex - 1;\n\n tableMeta.search.setCurrentHighlightColumnIndex(nextIndex);\n // we scroll to the row here, the cell scrolls itself into view\n scrollTo(tableMeta.search.highlightedColumnIndexes[nextIndex][0]);\n };\n\n const settings = (\n <Switch\n label={texts.table3.search.excludeUnmatchedResults}\n checked={tableMeta.search.excludeUnmatchedResults}\n onChange={handleToggleExcludeUnmatchedResults}\n />\n );\n\n return (\n <>\n <SearchInput2\n findCurrent={\n tableMeta.search.currentHighlightColumnIndex !== undefined\n ? tableMeta.search.currentHighlightColumnIndex + 1\n : null\n }\n findTotal={tableMeta.search.highlightedColumnIndexes ? tableMeta.search.highlightedColumnIndexes.length : null}\n loading={loading === LoadingState.Loading}\n onClickFindPrevious={handlePreviousResult}\n onClickFindNext={handleNextResult}\n onChange={handleChange}\n onFocus={handleFocus}\n placeholder={texts.table3.search.placeholder}\n settingsContent={settings}\n ref={ref}\n shortcut={{ key: 'f', meta: true, shift: false }}\n value={query}\n />\n </>\n );\n}\n\nfunction resetHighlightedColumnIndexes<TType = unknown>(enabled: boolean, value: string | undefined, table: RTable<TType>) {\n const tableMeta = table.options.meta as TableMeta<TType>;\n let firstRowIndex: undefined | number;\n\n if (enabled && value) {\n const rowIndexes: number[] = [];\n const indexes: number[][] = [];\n const columns = table.getVisibleLeafColumns();\n\n table.getRowModel().rows.forEach((row, rowIndex) => {\n columns.forEach((column, columnIndex) => {\n try {\n if (column.columnDef.meta?.enableSearch) {\n const cellValue = getCellValueAsString(row.original?.[column.id], column.columnDef.meta?.dataType);\n\n if (cellValue && globalFilterFn(cellValue, value)) {\n indexes.push([rowIndex, columnIndex]);\n }\n }\n } catch (e) {\n //\n }\n });\n\n if (indexes.length) {\n rowIndexes.push(rowIndex);\n }\n });\n\n tableMeta.search.setHighlightedColumnIndexes(indexes);\n\n if (indexes.length) {\n firstRowIndex = indexes[0][0];\n tableMeta.search.setCurrentHighlightColumnIndex(0);\n } else {\n tableMeta.search.setCurrentHighlightColumnIndex(undefined);\n }\n } else {\n tableMeta.search.setHighlightedColumnIndexes([]);\n tableMeta.search.setCurrentHighlightColumnIndex(undefined);\n }\n\n if (firstRowIndex !== undefined) {\n tableMeta.currentRow.setCurrentRowIndex(firstRowIndex);\n }\n\n return firstRowIndex;\n}\n"],"names":["LoadingState","Search","props","scrollToIndex","table","texts","useLocalization","ref","React","useRef","tableMeta","options","meta","query","setQuery","useState","search","loading","setLoading","Incomplete","scrollTo","rowIndex","align","useEffect","firstRowIndex","resetHighlightedColumnIndexes","isHighlightingEnabled","_ref$current","current","value","excludeUnmatchedResults","getRowModel","rows","length","JSON","stringify","getState","sorting","columnVisibility","useDebouncedEffect","setGlobalFilter","resetGlobalFilter","handleFocus","loadAll","Loading","Promise","resolve","columnFilters","undefined","then","Completed","_temp","e","reject","handleChange","String","handleToggleExcludeUnmatchedResults","enabled","toggleExcludeUnmatchedResults","_ref$current2","_ref$current3","requestAnimationFrame","_ref$current4","focus","handleNextResult","highlightedColumnIndexes","nextIndex","currentHighlightColumnIndex","setCurrentHighlightColumnIndex","handlePreviousResult","settings","Switch","label","table3","checked","onChange","SearchInput2","findCurrent","findTotal","onClickFindPrevious","onClickFindNext","onFocus","placeholder","settingsContent","shortcut","key","shift","indexes","columns","getVisibleLeafColumns","forEach","row","column","columnIndex","_column$columnDef$met","columnDef","enableSearch","_row$original","_column$columnDef$met2","cellValue","getCellValueAsString","original","id","dataType","globalFilterFn","push","setHighlightedColumnIndexes","currentRow","setCurrentRowIndex"],"mappings":";;;;;;;;AAcA,IAAKA,YAIJ;AAJD,WAAKA,YAAY;EACbA,2DAAU;EACVA,qDAAO;EACPA,yDAAS;AACb,CAAC,EAJIA,YAAY,KAAZA,YAAY;SAMDC,MAAMA,CAAkBC,KAAyB;EAC7D,MAAM;IAAEC,aAAa;IAAEC;GAAO,GAAGF,KAAK;EACtC,MAAM;IAAEG;GAAO,GAAGC,eAAe,EAAE;EACnC,MAAMC,GAAG,GAAGC,cAAK,CAACC,MAAM,CAAmB,IAAI,CAAC;EAChD,MAAMC,SAAS,GAAGN,KAAK,CAACO,OAAO,CAACC,IAAwB;EACxD,MAAM,CAACC,KAAK,EAA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OAAOA,aAAa;AACxB;;;;"}
|
|
1
|
+
{"version":3,"file":"Search.js","sources":["../../../../../../../../../src/components/Table3/components/toolbar/Search.tsx"],"sourcesContent":["import React from 'react';\nimport { Table as RTable, TableMeta } from '@tanstack/react-table';\nimport { useLocalization } from '../../../Provider/Localization';\nimport { Switch } from '../../../Switch/Switch';\nimport { globalFilterFn } from '../../util/filtering';\nimport { SearchInput2 } from '../../../SearchInput2/SearchInput2';\nimport { useDebouncedEffect } from '../../../../hooks/useDebouncedEffect';\nimport { getCellValueAsString } from '../../util/columns';\n\ntype SearchProps<TType = unknown> = {\n scrollToIndex: any;\n table: RTable<TType>;\n};\n\nenum LoadingState {\n Incomplete,\n Loading,\n Completed,\n}\n\nexport function Search<TType = unknown>(props: SearchProps<TType>) {\n const { scrollToIndex, table } = props;\n const { texts } = useLocalization();\n const ref = React.useRef<HTMLInputElement>(null);\n const tableMeta = table.options.meta as TableMeta<TType>;\n const [query, setQuery] = React.useState(tableMeta.search.query);\n const [loading, setLoading] = React.useState<LoadingState>(LoadingState.Incomplete);\n\n const scrollTo = (rowIndex: number) => scrollToIndex(rowIndex, { align: 'center' });\n\n // update the indexes if the row length changes (e.g. when filtering)\n React.useEffect(() => {\n const firstRowIndex = resetHighlightedColumnIndexes(tableMeta.search.isHighlightingEnabled, ref.current?.value, table);\n\n if (firstRowIndex) {\n scrollTo(firstRowIndex);\n }\n }, [\n tableMeta.search.query,\n tableMeta.search.excludeUnmatchedResults,\n table.getRowModel().rows.length,\n JSON.stringify(table.getState().sorting),\n JSON.stringify(table.getState().columnVisibility),\n loading,\n ]);\n\n // update the table search and filtering on a debounce\n useDebouncedEffect(() => {\n tableMeta.search.setQuery(query);\n\n if (tableMeta.search.excludeUnmatchedResults) {\n if (query?.length) {\n table.setGlobalFilter(query);\n } else {\n table.resetGlobalFilter();\n }\n }\n }, [query]);\n\n const handleFocus = async () => {\n // load all data if that is possible\n if (tableMeta.search.loadAll && loading === LoadingState.Incomplete) {\n setLoading(LoadingState.Loading);\n // don't pass the search query because we need all data - not filtered data\n await tableMeta.search.loadAll(table.getState().sorting, table.getState().columnFilters, undefined);\n setLoading(LoadingState.Completed);\n }\n };\n\n const handleChange = (query: any) => {\n setQuery(String(query ?? ''));\n };\n\n const handleToggleExcludeUnmatchedResults = (enabled: boolean) => {\n tableMeta.search.toggleExcludeUnmatchedResults(enabled);\n\n if (enabled) {\n if (ref.current?.value) {\n table.setGlobalFilter(ref.current?.value);\n } else {\n table.resetGlobalFilter();\n }\n } else {\n table.resetGlobalFilter();\n }\n\n requestAnimationFrame(() => ref.current?.focus());\n };\n\n const handleNextResult = () => {\n if (!tableMeta.search.highlightedColumnIndexes.length) {\n return;\n }\n\n const nextIndex =\n tableMeta.search.currentHighlightColumnIndex === undefined ||\n tableMeta.search.currentHighlightColumnIndex === tableMeta.search.highlightedColumnIndexes.length - 1\n ? 0\n : tableMeta.search.currentHighlightColumnIndex + 1;\n\n tableMeta.search.setCurrentHighlightColumnIndex(nextIndex);\n // we scroll to the row here, the cell scrolls itself into view\n scrollTo(tableMeta.search.highlightedColumnIndexes[nextIndex][0]);\n };\n\n const handlePreviousResult = () => {\n if (!tableMeta.search.highlightedColumnIndexes.length) {\n return;\n }\n\n const nextIndex =\n tableMeta.search.currentHighlightColumnIndex === undefined\n ? 0\n : tableMeta.search.currentHighlightColumnIndex === 0\n ? tableMeta.search.highlightedColumnIndexes.length - 1\n : tableMeta.search.currentHighlightColumnIndex - 1;\n\n tableMeta.search.setCurrentHighlightColumnIndex(nextIndex);\n // we scroll to the row here, the cell scrolls itself into view\n scrollTo(tableMeta.search.highlightedColumnIndexes[nextIndex][0]);\n };\n\n const settings = (\n <Switch\n label={texts.table3.search.excludeUnmatchedResults}\n checked={tableMeta.search.excludeUnmatchedResults}\n onChange={handleToggleExcludeUnmatchedResults}\n />\n );\n\n return (\n <>\n <SearchInput2\n findCurrent={\n tableMeta.search.currentHighlightColumnIndex !== undefined\n ? tableMeta.search.currentHighlightColumnIndex + 1\n : null\n }\n findTotal={tableMeta.search.highlightedColumnIndexes ? tableMeta.search.highlightedColumnIndexes.length : null}\n loading={loading === LoadingState.Loading}\n onClickFindPrevious={handlePreviousResult}\n onClickFindNext={handleNextResult}\n onChange={handleChange}\n onFocus={handleFocus}\n placeholder={texts.table3.search.placeholder}\n settingsContent={settings}\n ref={ref}\n shortcut={{ key: 'f', meta: true, shift: false }}\n value={query}\n />\n </>\n );\n}\n\nfunction resetHighlightedColumnIndexes<TType = unknown>(enabled: boolean, value: string | undefined, table: RTable<TType>) {\n const tableMeta = table.options.meta as TableMeta<TType>;\n let firstRowIndex: undefined | number;\n\n if (enabled && value) {\n const rowIndexes: number[] = [];\n const indexes: number[][] = [];\n const columns = table.getVisibleLeafColumns();\n\n table.getRowModel().rows.forEach((row, rowIndex) => {\n columns.forEach((column, columnIndex) => {\n try {\n if (column.getIsVisible() && column.columnDef.meta?.enableSearch) {\n const cellValue = getCellValueAsString(row.original?.[column.id], column.columnDef.meta?.dataType);\n\n if (cellValue !== undefined && globalFilterFn(cellValue, value)) {\n indexes.push([rowIndex, columnIndex]);\n }\n }\n } catch (e) {\n //\n }\n });\n\n if (indexes.length) {\n rowIndexes.push(rowIndex);\n }\n });\n\n tableMeta.search.setHighlightedColumnIndexes(indexes);\n\n if (indexes.length) {\n firstRowIndex = indexes[0][0];\n tableMeta.search.setCurrentHighlightColumnIndex(0);\n } else {\n tableMeta.search.setCurrentHighlightColumnIndex(undefined);\n }\n } else {\n tableMeta.search.setHighlightedColumnIndexes([]);\n tableMeta.search.setCurrentHighlightColumnIndex(undefined);\n }\n\n if (firstRowIndex !== undefined) {\n tableMeta.currentRow.setCurrentRowIndex(firstRowIndex);\n }\n\n return firstRowIndex;\n}\n"],"names":["LoadingState","Search","props","scrollToIndex","table","texts","useLocalization","ref","React","useRef","tableMeta","options","meta","query","setQuery","useState","search","loading","setLoading","Incomplete","scrollTo","rowIndex","align","useEffect","firstRowIndex","resetHighlightedColumnIndexes","isHighlightingEnabled","_ref$current","current","value","excludeUnmatchedResults","getRowModel","rows","length","JSON","stringify","getState","sorting","columnVisibility","useDebouncedEffect","setGlobalFilter","resetGlobalFilter","handleFocus","loadAll","Loading","Promise","resolve","columnFilters","undefined","then","Completed","_temp","e","reject","handleChange","String","handleToggleExcludeUnmatchedResults","enabled","toggleExcludeUnmatchedResults","_ref$current2","_ref$current3","requestAnimationFrame","_ref$current4","focus","handleNextResult","highlightedColumnIndexes","nextIndex","currentHighlightColumnIndex","setCurrentHighlightColumnIndex","handlePreviousResult","settings","Switch","label","table3","checked","onChange","SearchInput2","findCurrent","findTotal","onClickFindPrevious","onClickFindNext","onFocus","placeholder","settingsContent","shortcut","key","shift","indexes","columns","getVisibleLeafColumns","forEach","row","column","columnIndex","_column$columnDef$met","getIsVisible","columnDef","enableSearch","_row$original","_column$columnDef$met2","cellValue","getCellValueAsString","original","id","dataType","globalFilterFn","push","setHighlightedColumnIndexes","currentRow","setCurrentRowIndex"],"mappings":";;;;;;;;AAcA,IAAKA,YAIJ;AAJD,WAAKA,YAAY;EACbA,2DAAU;EACVA,qDAAO;EACPA,yDAAS;AACb,CAAC,EAJIA,YAAY,KAAZA,YAAY;SAMDC,MAAMA,CAAkBC,KAAyB;EAC7D,MAAM;IAAEC,aAAa;IAAEC;GAAO,GAAGF,KAAK;EACtC,MAAM;IAAEG;GAAO,GAAGC,eAAe,EAAE;EACnC,MAAMC,GAAG,GAAGC,cAAK,CAACC,MAAM,CAAmB,IAAI,CAAC;EAChD,MAAMC,SAAS,GAAGN,KAAK,CAACO,OAAO,CAACC,IAAwB;EACxD,MAAM,CAACC,KAAK,EAAEC,QAAQ,CAAC,GAAGN,cAAK,CAACO,QAAQ,CAACL,SAAS,CAACM,MAAM,CAACH,KAAK,CAAC;EAChE,MAAM,CAACI,OAAO,EAAEC,UAAU,CAAC,GAAGV,cAAK,CAACO,QAAQ,CAAef,YAAY,CAACmB,UAAU,CAAC;EAEnF,MAAMC,QAAQ,GAAIC,QAAgB,IAA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AE;YAAA,IAAAC,aAAA,EAAAC,sBAAA;YAC9D,MAAMC,SAAS,GAAGC,oBAAoB,EAAAH,aAAA,GAACP,GAAG,CAACW,QAAQ,cAAAJ,aAAA,uBAAZA,aAAA,CAAeN,MAAM,CAACW,EAAE,CAAC,GAAAJ,sBAAA,GAAEP,MAAM,CAACI,SAAS,CAACpF,IAAI,cAAAuF,sBAAA,uBAArBA,sBAAA,CAAuBK,QAAQ,CAAC;YAElG,IAAIJ,SAAS,KAAKpD,SAAS,IAAIyD,cAAc,CAACL,SAAS,EAAEvE,KAAK,CAAC,EAAE;cAC7D0D,OAAO,CAACmB,IAAI,CAAC,CAACrF,QAAQ,EAAEwE,WAAW,CAAC,CAAC;;;SAGhD,CAAC,OAAOzC,CAAC,EAAE;;;OAGf,CAAC;KAKL,CAAC;IAEF1C,SAAS,CAACM,MAAM,CAAC2F,2BAA2B,CAACpB,OAAO,CAAC;IAErD,IAAIA,OAAO,CAACtD,MAAM,EAAE;MAChBT,aAAa,GAAG+D,OAAO,CAAC,CAAC,CAAC,CAAC,CAAC,CAAC;MAC7B7E,SAAS,CAACM,MAAM,CAACoD,8BAA8B,CAAC,CAAC,CAAC;KACrD,MAAM;MACH1D,SAAS,CAACM,MAAM,CAACoD,8BAA8B,CAACpB,SAAS,CAAC;;GAEjE,MAAM;IACHtC,SAAS,CAACM,MAAM,CAAC2F,2BAA2B,CAAC,EAAE,CAAC;IAChDjG,SAAS,CAACM,MAAM,CAACoD,8BAA8B,CAACpB,SAAS,CAAC;;EAG9D,IAAIxB,aAAa,KAAKwB,SAAS,EAAE;IAC7BtC,SAAS,CAACkG,UAAU,CAACC,kBAAkB,CAACrF,aAAa,CAAC;;EAG1D,OAAOA,aAAa;AACxB;;;;"}
|
|
@@ -0,0 +1,61 @@
|
|
|
1
|
+
import React__default from 'react';
|
|
2
|
+
import { IconButton } from '../../../IconButton/IconButton.js';
|
|
3
|
+
import { useLocalization } from '../../../Provider/Localization.js';
|
|
4
|
+
import { Menu } from '../../../Menu/Menu.js';
|
|
5
|
+
import { RowHeight } from './RowHeight.js';
|
|
6
|
+
import { ColumnSettingsPopover } from './ColumnSettings.js';
|
|
7
|
+
import { FontSize } from './FontSize.js';
|
|
8
|
+
|
|
9
|
+
function SettingsButton(props) {
|
|
10
|
+
const {
|
|
11
|
+
table
|
|
12
|
+
} = props;
|
|
13
|
+
const {
|
|
14
|
+
texts
|
|
15
|
+
} = useLocalization();
|
|
16
|
+
const [popover, setPopover] = React__default.useState(undefined);
|
|
17
|
+
const tableMeta = table.options.meta;
|
|
18
|
+
const hasColumnSettings = table.options.enableHiding || tableMeta.columnOrdering.isEnabled;
|
|
19
|
+
let popoverElement;
|
|
20
|
+
if (popover) {
|
|
21
|
+
const handleClosePopover = () => setPopover(undefined);
|
|
22
|
+
switch (popover) {
|
|
23
|
+
case 'columnSettings':
|
|
24
|
+
{
|
|
25
|
+
if (hasColumnSettings) {
|
|
26
|
+
popoverElement = props => /*#__PURE__*/React__default.createElement(ColumnSettingsPopover, Object.assign({}, props, {
|
|
27
|
+
open: true,
|
|
28
|
+
onChange: handleClosePopover,
|
|
29
|
+
table: table
|
|
30
|
+
}));
|
|
31
|
+
}
|
|
32
|
+
}
|
|
33
|
+
}
|
|
34
|
+
}
|
|
35
|
+
return /*#__PURE__*/React__default.createElement(IconButton, {
|
|
36
|
+
"aria-label": texts.table3.otherOptions.tooltip,
|
|
37
|
+
icon: "sliders",
|
|
38
|
+
menu: popoverElement ? undefined : menuProps => /*#__PURE__*/React__default.createElement(Menu, Object.assign({}, menuProps), /*#__PURE__*/React__default.createElement(Menu.Content, {
|
|
39
|
+
align: "end"
|
|
40
|
+
}, table.options.enableHiding || tableMeta.columnOrdering.isEnabled ? /*#__PURE__*/React__default.createElement(React__default.Fragment, null, /*#__PURE__*/React__default.createElement(Menu.Item, {
|
|
41
|
+
icon: "columns",
|
|
42
|
+
onClick: () => setPopover('columnSettings')
|
|
43
|
+
}, texts.table3.columnSettings.button), /*#__PURE__*/React__default.createElement(Menu.Separator, null)) : null, tableMeta.rowHeight.isEnabled ? /*#__PURE__*/React__default.createElement(Menu.Item, {
|
|
44
|
+
icon: `height-${tableMeta.rowHeight.height}`,
|
|
45
|
+
subMenu: () => /*#__PURE__*/React__default.createElement(RowHeight, {
|
|
46
|
+
table: table
|
|
47
|
+
})
|
|
48
|
+
}, texts.table3.rowHeight.tooltip) : null, tableMeta.fontSize.isEnabled ? /*#__PURE__*/React__default.createElement(Menu.Item, {
|
|
49
|
+
icon: "font-size",
|
|
50
|
+
subMenu: () => /*#__PURE__*/React__default.createElement(FontSize, {
|
|
51
|
+
table: table
|
|
52
|
+
})
|
|
53
|
+
}, texts.table3.fontSize.tooltip) : null)),
|
|
54
|
+
popover: popoverElement,
|
|
55
|
+
onClickCapture: event => event.preventDefault(),
|
|
56
|
+
tooltip: texts.table3.otherOptions.tooltip
|
|
57
|
+
});
|
|
58
|
+
}
|
|
59
|
+
|
|
60
|
+
export { SettingsButton };
|
|
61
|
+
//# sourceMappingURL=Settings.js.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"Settings.js","sources":["../../../../../../../../../src/components/Table3/components/toolbar/Settings.tsx"],"sourcesContent":["import React from 'react';\nimport { Table as RTable, TableMeta } from '@tanstack/react-table';\nimport { RowHeight } from './RowHeight';\nimport { ColumnSettingsPopover } from './ColumnSettings';\nimport { IconButton } from '../../../IconButton/IconButton';\nimport { Menu } from '../../../Menu/Menu';\nimport { useLocalization } from '../../../Provider/Localization';\nimport { IconName } from '../../../Icon/Icon';\nimport { FontSize } from './FontSize';\n\nexport type SettingsButtonProps<TType = unknown> = {\n table: RTable<TType>;\n};\nexport function SettingsButton<TType = unknown>(props: SettingsButtonProps<TType>) {\n const { table } = props;\n const { texts } = useLocalization();\n const [popover, setPopover] = React.useState<string | undefined>(undefined);\n const tableMeta = table.options.meta as TableMeta<TType>;\n\n const hasColumnSettings = table.options.enableHiding || tableMeta.columnOrdering.isEnabled;\n\n let popoverElement;\n\n if (popover) {\n const handleClosePopover = () => setPopover(undefined);\n\n switch (popover) {\n case 'columnSettings': {\n if (hasColumnSettings) {\n popoverElement = props => (\n <ColumnSettingsPopover {...props} open onChange={handleClosePopover} table={table} />\n );\n }\n }\n }\n }\n\n return (\n <IconButton\n aria-label={texts.table3.otherOptions.tooltip}\n icon=\"sliders\"\n menu={\n popoverElement\n ? undefined\n : menuProps => (\n <Menu {...menuProps}>\n <Menu.Content align=\"end\">\n {table.options.enableHiding || tableMeta.columnOrdering.isEnabled ? (\n <>\n <Menu.Item icon=\"columns\" onClick={() => setPopover('columnSettings')}>\n {texts.table3.columnSettings.button}\n </Menu.Item>\n <Menu.Separator />\n </>\n ) : null}\n {tableMeta.rowHeight.isEnabled ? (\n <Menu.Item\n icon={`height-${tableMeta.rowHeight.height}` as IconName}\n subMenu={() => <RowHeight table={table} />}>\n {texts.table3.rowHeight.tooltip}\n </Menu.Item>\n ) : null}\n {tableMeta.fontSize.isEnabled ? (\n <Menu.Item icon=\"font-size\" subMenu={() => <FontSize table={table} />}>\n {texts.table3.fontSize.tooltip}\n </Menu.Item>\n ) : null}\n </Menu.Content>\n </Menu>\n )\n }\n popover={popoverElement}\n onClickCapture={event => event.preventDefault()}\n tooltip={texts.table3.otherOptions.tooltip}\n />\n );\n}\n"],"names":["SettingsButton","props","table","texts","useLocalization","popover","setPopover","React","useState","undefined","tableMeta","options","meta","hasColumnSettings","enableHiding","columnOrdering","isEnabled","popoverElement","handleClosePopover","ColumnSettingsPopover","open","onChange","IconButton","table3","otherOptions","tooltip","icon","menu","menuProps","Menu","Content","align","Item","onClick","columnSettings","button","Separator","rowHeight","height","subMenu","RowHeight","fontSize","FontSize","onClickCapture","event","preventDefault"],"mappings":";;;;;;;;SAagBA,cAAcA,CAAkBC,KAAiC;EAC7E,MAAM;IAAEC;GAAO,GAAGD,KAAK;EACvB,MAAM;IAAEE;GAAO,GAAGC,eAAe,EAAE;EACnC,MAAM,CAACC,OAAO,EAAEC,UAAU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