@economic/taco 2.53.0-alpha.0 → 2.53.0-settings.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/Provider/Provider.d.ts +7 -6
- package/dist/components/Provider/TacoContext.d.ts +7 -0
- package/dist/components/Provider/useTacoSettings.d.ts +8 -0
- package/dist/components/Report/Report.d.ts +1 -1
- package/dist/esm/packages/taco/src/components/Provider/Provider.js +14 -7
- package/dist/esm/packages/taco/src/components/Provider/Provider.js.map +1 -1
- package/dist/esm/packages/taco/src/components/Provider/TacoContext.js +6 -0
- package/dist/esm/packages/taco/src/components/Provider/TacoContext.js.map +1 -0
- package/dist/esm/packages/taco/src/components/Provider/useTacoSettings.js +39 -0
- package/dist/esm/packages/taco/src/components/Provider/useTacoSettings.js.map +1 -0
- package/dist/esm/packages/taco/src/components/Report/Report.js +8 -0
- package/dist/esm/packages/taco/src/components/Report/Report.js.map +1 -1
- package/dist/esm/packages/taco/src/components/Table3/Table3.js +8 -0
- package/dist/esm/packages/taco/src/components/Table3/Table3.js.map +1 -1
- package/dist/esm/packages/taco/src/hooks/useTaco.js +9 -0
- package/dist/esm/packages/taco/src/hooks/useTaco.js.map +1 -0
- package/dist/esm/packages/taco/src/index.js +1 -1
- package/dist/esm/packages/taco/src/primitives/Table/Core/components/Toolbar/Toolbar.js +6 -4
- package/dist/esm/packages/taco/src/primitives/Table/Core/components/Toolbar/Toolbar.js.map +1 -1
- package/dist/esm/packages/taco/src/primitives/Table/Core/useTable.js.map +1 -1
- package/dist/esm/packages/taco/src/primitives/Table/types.js.map +1 -1
- package/dist/esm/packages/taco/src/primitives/Table/useTableManager/features/useTablePrinting.js +18 -21
- package/dist/esm/packages/taco/src/primitives/Table/useTableManager/features/useTablePrinting.js.map +1 -1
- package/dist/esm/packages/taco/src/primitives/Table/useTableManager/listeners/useTableSettingsListener.js +54 -9
- package/dist/esm/packages/taco/src/primitives/Table/useTableManager/listeners/useTableSettingsListener.js.map +1 -1
- package/dist/esm/packages/taco/src/primitives/Table/useTableManager/useTableManager.js +6 -4
- package/dist/esm/packages/taco/src/primitives/Table/useTableManager/useTableManager.js.map +1 -1
- package/dist/esm/packages/taco/src/primitives/Table/useTableManager/useTableSettingsPreloader.js +44 -0
- package/dist/esm/packages/taco/src/primitives/Table/useTableManager/useTableSettingsPreloader.js.map +1 -0
- package/dist/esm/packages/taco/src/primitives/Table/useTableManager/util/settings.js +3 -1
- package/dist/esm/packages/taco/src/primitives/Table/useTableManager/util/settings.js.map +1 -1
- package/dist/hooks/useTaco.d.ts +1 -0
- package/dist/primitives/Table/Core/useTable.d.ts +4 -4
- package/dist/primitives/Table/types.d.ts +11 -4
- package/dist/primitives/Table/useTableManager/features/useTablePrinting.d.ts +2 -8
- package/dist/primitives/Table/useTableManager/listeners/useTableSettingsListener.d.ts +2 -2
- package/dist/primitives/Table/useTableManager/useTableSettingsPreloader.d.ts +3 -0
- package/dist/primitives/Table/useTableManager/util/settings.d.ts +2 -0
- package/dist/taco.cjs.development.js +176 -143
- 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 +2 -2
- package/dist/esm/packages/taco/src/hooks/useLocalStorage.js +0 -44
- package/dist/esm/packages/taco/src/hooks/useLocalStorage.js.map +0 -1
- package/dist/esm/packages/taco/src/hooks/useTacoSettings.js +0 -9
- package/dist/esm/packages/taco/src/hooks/useTacoSettings.js.map +0 -1
- package/dist/esm/packages/taco/src/primitives/Table/useTableManager/features/useTableSettings.js +0 -69
- package/dist/esm/packages/taco/src/primitives/Table/useTableManager/features/useTableSettings.js.map +0 -1
- package/dist/hooks/useLocalStorage.d.ts +0 -2
- package/dist/hooks/useTacoSettings.d.ts +0 -1
- package/dist/primitives/Table/useTableManager/features/useTableSettings.d.ts +0 -3
@@ -28,6 +28,7 @@ var PrimitiveSwitch = require('@radix-ui/react-switch');
|
|
28
28
|
var DropdownMenuPrimitive = require('@radix-ui/react-dropdown-menu');
|
29
29
|
var RadioGroupPrimitive = require('@radix-ui/react-radio-group');
|
30
30
|
var ReactDOM = _interopDefault(require('react-dom'));
|
31
|
+
var lodash = require('lodash');
|
31
32
|
var reactTable = require('@tanstack/react-table');
|
32
33
|
var get = _interopDefault(require('lodash/get'));
|
33
34
|
var reactVirtual = require('@tanstack/react-virtual');
|
@@ -9946,16 +9947,57 @@ const ToastProvider = ({
|
|
9946
9947
|
};
|
9947
9948
|
const useToast = () => React.useContext(ToastContext);
|
9948
9949
|
|
9949
|
-
const TacoContext = /*#__PURE__*/React.createContext({
|
9950
|
-
|
9951
|
-
|
9950
|
+
const TacoContext = /*#__PURE__*/React.createContext({});
|
9951
|
+
|
9952
|
+
function useTacoSettings(load, save) {
|
9953
|
+
const saveSetting = function (path, value) {
|
9954
|
+
try {
|
9955
|
+
setState(currentState => lodash.setWith(currentState, path, value, Object));
|
9956
|
+
return Promise.resolve(save(path, value)); // don't block, since we have local state
|
9957
|
+
} catch (e) {
|
9958
|
+
return Promise.reject(e);
|
9959
|
+
}
|
9960
|
+
};
|
9961
|
+
const loadSetting = function (path) {
|
9962
|
+
try {
|
9963
|
+
const currentValue = lodash.get(state, path);
|
9964
|
+
if (currentValue) {
|
9965
|
+
return Promise.resolve(currentValue);
|
9966
|
+
}
|
9967
|
+
return Promise.resolve(load(path)).then(function (value) {
|
9968
|
+
setState(currentState => lodash.setWith(currentState, path, value, Object));
|
9969
|
+
return value;
|
9970
|
+
});
|
9971
|
+
} catch (e) {
|
9972
|
+
return Promise.reject(e);
|
9973
|
+
}
|
9974
|
+
};
|
9975
|
+
const [state, setState] = React.useState({});
|
9976
|
+
function getSetting(path) {
|
9977
|
+
return lodash.get(state, path);
|
9978
|
+
}
|
9979
|
+
return {
|
9980
|
+
getSetting,
|
9981
|
+
loadSetting,
|
9982
|
+
saveSetting
|
9983
|
+
};
|
9984
|
+
}
|
9985
|
+
|
9952
9986
|
const Provider = props => {
|
9953
9987
|
const {
|
9954
9988
|
children,
|
9955
9989
|
localization,
|
9956
|
-
|
9990
|
+
loadSetting,
|
9991
|
+
saveSetting,
|
9992
|
+
userId
|
9957
9993
|
} = props;
|
9958
|
-
const
|
9994
|
+
const settings = useTacoSettings(loadSetting, saveSetting);
|
9995
|
+
const context = React.useMemo(() => {
|
9996
|
+
return {
|
9997
|
+
settings,
|
9998
|
+
userId
|
9999
|
+
};
|
10000
|
+
}, []);
|
9959
10001
|
return /*#__PURE__*/React.createElement(LocalizationProvider, {
|
9960
10002
|
localization: localization
|
9961
10003
|
}, /*#__PURE__*/React.createElement(TacoContext.Provider, {
|
@@ -10369,6 +10411,7 @@ function getHiddenColumns(columnVisibility = {}) {
|
|
10369
10411
|
return Object.keys(columnVisibility).filter(c => columnVisibility[c] === false);
|
10370
10412
|
}
|
10371
10413
|
|
10414
|
+
const getSettingsId = tableId => `table.${tableId.replace('.', '_')}`;
|
10372
10415
|
function getSettings(table) {
|
10373
10416
|
const meta = table.options.meta;
|
10374
10417
|
const state = table.getState();
|
@@ -10382,6 +10425,7 @@ function getSettings(table) {
|
|
10382
10425
|
excludeUnmatchedRecordsInSearch: table.options.enableGlobalFilter,
|
10383
10426
|
fontSize: meta.fontSize.isEnabled ? meta.fontSize.size : undefined,
|
10384
10427
|
//grouping: table.options.enableGrouping ? state.grouping : undefined,
|
10428
|
+
print: meta.printing.settings,
|
10385
10429
|
rowHeight: meta.rowHeight.isEnabled ? meta.rowHeight.height : undefined,
|
10386
10430
|
//searchQuery: table.options.enableGlobalFilter ? state.globalFilter : undefined,
|
10387
10431
|
sorting: state.sorting
|
@@ -10895,53 +10939,28 @@ function useTableFontSize(isEnabled = false, defaultFontSize = 'medium') {
|
|
10895
10939
|
};
|
10896
10940
|
}
|
10897
10941
|
|
10898
|
-
function
|
10942
|
+
function useTaco() {
|
10899
10943
|
return React__default.useContext(TacoContext);
|
10900
10944
|
}
|
10901
10945
|
|
10902
|
-
const
|
10903
|
-
|
10904
|
-
|
10905
|
-
|
10906
|
-
|
10907
|
-
try {
|
10908
|
-
const localStorageValue = localStorage.getItem(key);
|
10909
|
-
if (typeof localStorageValue !== 'string') {
|
10910
|
-
localStorage.setItem(key, JSON.stringify(initialValue));
|
10911
|
-
return initialValue;
|
10912
|
-
} else {
|
10913
|
-
return JSON.parse(localStorageValue || 'null');
|
10914
|
-
}
|
10915
|
-
} catch {
|
10916
|
-
// If user is in private mode or has storage restriction
|
10917
|
-
// localStorage can throw. JSON.parse and JSON.stringify
|
10918
|
-
// can throw, too.
|
10919
|
-
return initialValue;
|
10920
|
-
}
|
10921
|
-
});
|
10922
|
-
React__default.useEffect(() => {
|
10923
|
-
if (!key) {
|
10924
|
-
return;
|
10925
|
-
}
|
10926
|
-
try {
|
10927
|
-
const serializedState = JSON.stringify(state);
|
10928
|
-
localStorage.setItem(key, serializedState);
|
10929
|
-
} catch {
|
10930
|
-
// If user is in private mode or has storage restriction
|
10931
|
-
// localStorage can throw. Also JSON.stringify can throw.
|
10932
|
-
}
|
10933
|
-
}, [key, state]);
|
10934
|
-
const clear = () => {
|
10935
|
-
if (key) {
|
10936
|
-
localStorage.removeItem(key);
|
10937
|
-
}
|
10938
|
-
};
|
10939
|
-
return [state, setState, clear];
|
10946
|
+
const DEFAULT_PRINT_SETTINGS = {
|
10947
|
+
size: 'A4',
|
10948
|
+
orientation: 'portrait',
|
10949
|
+
allRows: true,
|
10950
|
+
splitGroups: true
|
10940
10951
|
};
|
10941
|
-
|
10942
10952
|
function useTablePrinting(isEnabled = false, tableId) {
|
10953
|
+
var _taco$settings$getSet, _taco$settings$getSet2;
|
10943
10954
|
const [isPrinting, setIsPrinting] = React__default.useState(false);
|
10944
|
-
const
|
10955
|
+
const taco = useTaco();
|
10956
|
+
const key = getSettingsId(tableId);
|
10957
|
+
const [settings, _setSettings] = React__default.useState((_taco$settings$getSet = (_taco$settings$getSet2 = taco.settings.getSetting(key)) === null || _taco$settings$getSet2 === void 0 ? void 0 : _taco$settings$getSet2.print) !== null && _taco$settings$getSet !== void 0 ? _taco$settings$getSet : DEFAULT_PRINT_SETTINGS);
|
10958
|
+
function setSetting(path, value) {
|
10959
|
+
_setSettings(currentSettings => ({
|
10960
|
+
...currentSettings,
|
10961
|
+
[path]: value
|
10962
|
+
}));
|
10963
|
+
}
|
10945
10964
|
return {
|
10946
10965
|
isEnabled,
|
10947
10966
|
isPrinting,
|
@@ -10950,24 +10969,6 @@ function useTablePrinting(isEnabled = false, tableId) {
|
|
10950
10969
|
setSetting
|
10951
10970
|
};
|
10952
10971
|
}
|
10953
|
-
const DEFAULT_PRINT_SETTINGS = {
|
10954
|
-
size: 'A4',
|
10955
|
-
orientation: 'portrait',
|
10956
|
-
allRows: true,
|
10957
|
-
splitGroups: true
|
10958
|
-
};
|
10959
|
-
function useTablePrintingSettings(tableId) {
|
10960
|
-
const tacoSettings = useTacoSettings();
|
10961
|
-
const uniqueId = `taco.${tacoSettings.uniqueUserIdentifier}.table.${tableId}.print.settings`;
|
10962
|
-
const [persistedSettings, setPersistedSettings] = useLocalStorage(uniqueId, DEFAULT_PRINT_SETTINGS);
|
10963
|
-
function setSetting(key, value) {
|
10964
|
-
setPersistedSettings(currentSettings => ({
|
10965
|
-
...currentSettings,
|
10966
|
-
[key]: value
|
10967
|
-
}));
|
10968
|
-
}
|
10969
|
-
return [persistedSettings, setSetting];
|
10970
|
-
}
|
10971
10972
|
|
10972
10973
|
const DEFAULT_ROW_ACTIONS_LENGTH = 4;
|
10973
10974
|
function useTableRowActions(isEnabled = false, rowActions, rowActionsLength = DEFAULT_ROW_ACTIONS_LENGTH) {
|
@@ -11637,69 +11638,6 @@ function useTableServerLoading(length, data, loadPage, loadAll, pages, pageSize
|
|
11637
11638
|
};
|
11638
11639
|
}
|
11639
11640
|
|
11640
|
-
const DEFAULT_ENABLED_OPTIONS = {
|
11641
|
-
columnOrder: true,
|
11642
|
-
columnPinning: true,
|
11643
|
-
columnSizing: true,
|
11644
|
-
columnVisibility: true,
|
11645
|
-
excludeUnmatchedRecordsInSearch: true,
|
11646
|
-
fontSize: true,
|
11647
|
-
grouping: true,
|
11648
|
-
rowHeight: true,
|
11649
|
-
sorting: true
|
11650
|
-
};
|
11651
|
-
function useUniqueTableId(tableId) {
|
11652
|
-
const tacoSettings = useTacoSettings();
|
11653
|
-
return `taco.${tacoSettings.uniqueUserIdentifier}.table.${tableId}.settings`;
|
11654
|
-
}
|
11655
|
-
function useEnabledSettings(isEnabled) {
|
11656
|
-
return React__default.useMemo(() => {
|
11657
|
-
if (isEnabled === false) {
|
11658
|
-
return [Object.keys(DEFAULT_ENABLED_OPTIONS).reduce((o, key) => ({
|
11659
|
-
...o,
|
11660
|
-
[key]: false
|
11661
|
-
}), {}), false];
|
11662
|
-
} else if (isEnabled === true) {
|
11663
|
-
return [DEFAULT_ENABLED_OPTIONS, true];
|
11664
|
-
}
|
11665
|
-
const options = {
|
11666
|
-
...DEFAULT_ENABLED_OPTIONS,
|
11667
|
-
...isEnabled
|
11668
|
-
};
|
11669
|
-
return [options, Object.values(options).some(o => o === true)];
|
11670
|
-
}, [isEnabled]);
|
11671
|
-
}
|
11672
|
-
function useTableSettings(isEnabled = false, id, defaultSettings = {}, onChangeSettings) {
|
11673
|
-
const uniqueId = useUniqueTableId(id);
|
11674
|
-
const [enabledSettings, hasSomeEnabledSettings] = useEnabledSettings(isEnabled);
|
11675
|
-
const [persistedSettings, _setPersistedSettings] = useLocalStorage(hasSomeEnabledSettings ? uniqueId : undefined, removeDisabledSettings(defaultSettings, enabledSettings));
|
11676
|
-
const setPersistedSettings = React__default.useCallback(value => {
|
11677
|
-
if (!hasSomeEnabledSettings) {
|
11678
|
-
return;
|
11679
|
-
}
|
11680
|
-
const sanitizedSettings = removeDisabledSettings(value, enabledSettings);
|
11681
|
-
_setPersistedSettings(sanitizedSettings);
|
11682
|
-
if (typeof onChangeSettings === 'function') {
|
11683
|
-
onChangeSettings(sanitizedSettings);
|
11684
|
-
}
|
11685
|
-
}, [hasSomeEnabledSettings, onChangeSettings, JSON.stringify(enabledSettings)]);
|
11686
|
-
if (!hasSomeEnabledSettings) {
|
11687
|
-
return [defaultSettings, () => undefined];
|
11688
|
-
}
|
11689
|
-
return [persistedSettings, setPersistedSettings];
|
11690
|
-
}
|
11691
|
-
function removeDisabledSettings(settings, enabledSettings) {
|
11692
|
-
const sanitizedSettings = {
|
11693
|
-
...settings
|
11694
|
-
};
|
11695
|
-
Object.keys(enabledSettings).forEach(setting => {
|
11696
|
-
if (!enabledSettings[setting]) {
|
11697
|
-
delete sanitizedSettings[setting];
|
11698
|
-
}
|
11699
|
-
});
|
11700
|
-
return sanitizedSettings;
|
11701
|
-
}
|
11702
|
-
|
11703
11641
|
// augments useEffect to not run on the initial mount
|
11704
11642
|
function useLazyEffect(effect, deps) {
|
11705
11643
|
const readyRef = React__default.useRef(false);
|
@@ -11831,26 +11769,70 @@ function useTableSearchListener(table) {
|
|
11831
11769
|
}, [meta.server.loading, meta.search.isEnabled, meta.search.enableGlobalFilter, table.getRowModel().rows.length, query, JSON.stringify(table.getState().sorting)]);
|
11832
11770
|
}
|
11833
11771
|
|
11834
|
-
function useTableSettingsListener(table,
|
11772
|
+
function useTableSettingsListener(table, tableId, isEnabled = false) {
|
11773
|
+
const [enabledSettings, hasSomeEnabledSettings] = useEnabledSettings(isEnabled);
|
11774
|
+
const taco = useTaco();
|
11835
11775
|
const meta = table.options.meta;
|
11836
11776
|
const state = table.getState();
|
11837
11777
|
React__default.useEffect(() => {
|
11838
|
-
|
11839
|
-
|
11840
|
-
|
11778
|
+
const handler = setTimeout(() => {
|
11779
|
+
if (!hasSomeEnabledSettings) {
|
11780
|
+
return;
|
11781
|
+
}
|
11782
|
+
const settings = removeDisabledSettings(getSettings(table), enabledSettings);
|
11783
|
+
if (Object.keys(settings).length) {
|
11841
11784
|
// some settings shouldn't be persisted, but we comment them out here to highlight the intention
|
11842
|
-
|
11843
|
-
}
|
11844
|
-
}
|
11785
|
+
taco.settings.saveSetting(getSettingsId(tableId), settings);
|
11786
|
+
}
|
11787
|
+
}, 100);
|
11845
11788
|
return () => clearTimeout(handler);
|
11846
11789
|
}, [
|
11847
11790
|
//state.columnFilters,
|
11848
11791
|
state.columnOrder, state.columnPinning, state.columnSizing, state.columnVisibility, table.options.enableGlobalFilter, meta.fontSize.size,
|
11849
11792
|
//state.grouping,
|
11850
|
-
meta.rowHeight.height,
|
11793
|
+
meta.printing.settings, meta.rowHeight.height,
|
11851
11794
|
//state.globalFilter,
|
11852
11795
|
state.sorting]);
|
11853
11796
|
}
|
11797
|
+
const DEFAULT_ENABLED_OPTIONS = {
|
11798
|
+
columnOrder: true,
|
11799
|
+
columnPinning: true,
|
11800
|
+
columnSizing: true,
|
11801
|
+
columnVisibility: true,
|
11802
|
+
excludeUnmatchedRecordsInSearch: true,
|
11803
|
+
fontSize: true,
|
11804
|
+
grouping: true,
|
11805
|
+
rowHeight: true,
|
11806
|
+
sorting: true
|
11807
|
+
};
|
11808
|
+
function useEnabledSettings(isEnabled) {
|
11809
|
+
return React__default.useMemo(() => {
|
11810
|
+
if (isEnabled === false) {
|
11811
|
+
return [Object.keys(DEFAULT_ENABLED_OPTIONS).reduce((o, key) => ({
|
11812
|
+
...o,
|
11813
|
+
[key]: false
|
11814
|
+
}), {}), false];
|
11815
|
+
} else if (isEnabled === true) {
|
11816
|
+
return [DEFAULT_ENABLED_OPTIONS, true];
|
11817
|
+
}
|
11818
|
+
const options = {
|
11819
|
+
...DEFAULT_ENABLED_OPTIONS,
|
11820
|
+
...isEnabled
|
11821
|
+
};
|
11822
|
+
return [options, Object.values(options).some(o => o === true)];
|
11823
|
+
}, [isEnabled]);
|
11824
|
+
}
|
11825
|
+
function removeDisabledSettings(settings, enabledSettings) {
|
11826
|
+
const sanitizedSettings = {
|
11827
|
+
...settings
|
11828
|
+
};
|
11829
|
+
Object.keys(enabledSettings).forEach(setting => {
|
11830
|
+
if (!enabledSettings[setting]) {
|
11831
|
+
delete sanitizedSettings[setting];
|
11832
|
+
}
|
11833
|
+
});
|
11834
|
+
return sanitizedSettings;
|
11835
|
+
}
|
11854
11836
|
|
11855
11837
|
function useTableShortcutsListener(table, shortcuts) {
|
11856
11838
|
const meta = table.options.meta;
|
@@ -11945,14 +11927,15 @@ function useTableRowDrop(isEnabled = false, onRowDrop) {
|
|
11945
11927
|
// Placed this array outside the hook to avoid creating a new array reference on each hook re-render
|
11946
11928
|
const DEFAULT_EMPTY_ARRAY = [];
|
11947
11929
|
function useTableManager(props, meta, internalColumns) {
|
11948
|
-
var _props$data, _props$length, _meta$editing, _instance$options$met;
|
11930
|
+
var _ref, _taco$settings$getSet, _props$data, _props$length, _meta$editing, _instance$options$met;
|
11931
|
+
const taco = useTaco();
|
11949
11932
|
const localization = useLocalization();
|
11950
11933
|
// CSS.escape would be best here, but it doesn't seem to work very well
|
11951
11934
|
const safeId = props.id.replace('.', '_');
|
11952
11935
|
// configure table options, merging props with presets
|
11953
11936
|
const options = getTableFeaturePreset(props);
|
11954
11937
|
// load any persisted table settings and merge them with any defaults
|
11955
|
-
const
|
11938
|
+
const settings = (_ref = (_taco$settings$getSet = taco.settings.getSetting(getSettingsId(safeId))) !== null && _taco$settings$getSet !== void 0 ? _taco$settings$getSet : props.defaultSettings) !== null && _ref !== void 0 ? _ref : {};
|
11956
11939
|
// ensure data is always valid
|
11957
11940
|
const data = (_props$data = props.data) !== null && _props$data !== void 0 ? _props$data : DEFAULT_EMPTY_ARRAY;
|
11958
11941
|
const length = (_props$length = props.length) !== null && _props$length !== void 0 ? _props$length : data.length;
|
@@ -12027,7 +12010,7 @@ function useTableManager(props, meta, internalColumns) {
|
|
12027
12010
|
useTableRowSelectionListener(instance, props.onRowSelect);
|
12028
12011
|
useTableSearchListener(instance);
|
12029
12012
|
useTableServerLoadingListener(instance, server.loadPage);
|
12030
|
-
useTableSettingsListener(instance,
|
12013
|
+
useTableSettingsListener(instance, safeId, options.enableSaveSettings);
|
12031
12014
|
useTableShortcutsListener(instance, props.shortcuts);
|
12032
12015
|
useTableSortingListener(instance, props.onChangeSort);
|
12033
12016
|
return {
|
@@ -17221,15 +17204,16 @@ function TableToolbar(props) {
|
|
17221
17204
|
const canPrint = table.meta.printing.isEnabled;
|
17222
17205
|
const canSettings = canChangeSettings(table.instance, table.props.customSettings);
|
17223
17206
|
const canSearch = table.meta.search.isEnabled;
|
17207
|
+
const settings = getSettings(table.instance);
|
17224
17208
|
return /*#__PURE__*/React__default.createElement(React__default.Fragment, null, /*#__PURE__*/React__default.createElement("div", Object.assign({}, attributes, {
|
17225
17209
|
className: "mb-4 flex flex-shrink flex-grow-0 flex-wrap gap-2 print:hidden",
|
17226
17210
|
"data-taco": "table-toolbar"
|
17227
|
-
}), table.props.toolbarLeft, /*#__PURE__*/React__default.createElement(Group, {
|
17211
|
+
}), typeof table.props.toolbarLeft === 'function' ? table.props.toolbarLeft(settings) : table.props.toolbarLeft, /*#__PURE__*/React__default.createElement(Group, {
|
17228
17212
|
className: "ml-auto flex-shrink-0 items-center print:hidden"
|
17229
17213
|
}, customTools, canFilter ? /*#__PURE__*/React__default.createElement(Filters, {
|
17230
17214
|
length: table.meta.length,
|
17231
17215
|
table: table.instance
|
17232
|
-
}) : null, table.props.toolbarRight, canPrint ? /*#__PURE__*/React__default.createElement(Print$1, {
|
17216
|
+
}) : null, typeof table.props.toolbarRight === 'function' ? table.props.toolbarRight(settings) : table.props.toolbarRight, canPrint ? /*#__PURE__*/React__default.createElement(Print$1, {
|
17233
17217
|
table: table.instance,
|
17234
17218
|
tableId: table.id,
|
17235
17219
|
tableRef: table.ref
|
@@ -17240,9 +17224,9 @@ function TableToolbar(props) {
|
|
17240
17224
|
scrollToIndex: table.renderer.scrollToIndex,
|
17241
17225
|
table: table.instance,
|
17242
17226
|
tableRef: table.ref
|
17243
|
-
})) : null)), table.props.toolbarPanel ? /*#__PURE__*/React__default.createElement("div", {
|
17227
|
+
})) : null)), table.props.toolbarPanel ? (/*#__PURE__*/React__default.createElement("div", {
|
17244
17228
|
className: "mb-4"
|
17245
|
-
}, table.props.toolbarPanel) : undefined);
|
17229
|
+
}, typeof table.props.toolbarPanel === 'function' ? table.props.toolbarPanel(settings) : table.props.toolbarPanel)) : undefined);
|
17246
17230
|
}
|
17247
17231
|
function canChangeSettings(table, customSettings) {
|
17248
17232
|
const tableMeta = table.options.meta;
|
@@ -17321,6 +17305,44 @@ function TableGrid(props) {
|
|
17321
17305
|
}, footerRows) : null)))));
|
17322
17306
|
}
|
17323
17307
|
|
17308
|
+
function getLegacySetting(currentKey) {
|
17309
|
+
try {
|
17310
|
+
const localStorageValue = localStorage.getItem(currentKey);
|
17311
|
+
if (localStorageValue) {
|
17312
|
+
const value = JSON.parse(localStorageValue || 'null');
|
17313
|
+
if (value !== null) {
|
17314
|
+
localStorage.removeItem(currentKey);
|
17315
|
+
return value;
|
17316
|
+
}
|
17317
|
+
}
|
17318
|
+
} catch {
|
17319
|
+
// If user is in private mode or has storage restriction
|
17320
|
+
// localStorage can throw. JSON.parse can throw, too.
|
17321
|
+
}
|
17322
|
+
return undefined;
|
17323
|
+
}
|
17324
|
+
function useTableSettingsPreloader(tableId) {
|
17325
|
+
const taco = useTaco();
|
17326
|
+
const [loading, setLoading] = React__default.useState(true);
|
17327
|
+
React__default.useLayoutEffect(() => {
|
17328
|
+
const key = getSettingsId(tableId);
|
17329
|
+
// migrate legacy settings if they exist, can be removed in the future
|
17330
|
+
const legacySettings = getLegacySetting(`taco.${taco.userId}.table.${tableId}.settings`);
|
17331
|
+
if (legacySettings) {
|
17332
|
+
const legacyPrintSettings = getLegacySetting(`taco.${taco.userId}.table.${tableId}.print.settings`);
|
17333
|
+
taco.settings.saveSetting(getSettingsId(tableId), {
|
17334
|
+
...legacySettings,
|
17335
|
+
print: legacyPrintSettings !== null && legacyPrintSettings !== void 0 ? legacyPrintSettings : {}
|
17336
|
+
}).finally(() => setLoading(false));
|
17337
|
+
} else {
|
17338
|
+
taco.settings.loadSetting(key).finally(() => setLoading(false));
|
17339
|
+
}
|
17340
|
+
}, []);
|
17341
|
+
return {
|
17342
|
+
loading
|
17343
|
+
};
|
17344
|
+
}
|
17345
|
+
|
17324
17346
|
function Column$1(_) {
|
17325
17347
|
return null;
|
17326
17348
|
}
|
@@ -17341,6 +17363,12 @@ const Report$1 = /*#__PURE__*/fixedForwardRef(function Report(props, ref) {
|
|
17341
17363
|
// we force a remount (using key) when the child columns change because there are too many places to add children as an effect
|
17342
17364
|
// this is cheaper from a complexity perspective, and probably performance wise as well
|
17343
17365
|
const key = React__default.useMemo(() => String('tableKey_' + stringifiedChildren), [stringifiedChildren]);
|
17366
|
+
const {
|
17367
|
+
loading
|
17368
|
+
} = useTableSettingsPreloader(props.id);
|
17369
|
+
if (loading) {
|
17370
|
+
return /*#__PURE__*/React__default.createElement(Spinner, null);
|
17371
|
+
}
|
17344
17372
|
return /*#__PURE__*/React__default.createElement(BaseReport, Object.assign({}, props, {
|
17345
17373
|
key: key,
|
17346
17374
|
ref: ref
|
@@ -20719,6 +20747,12 @@ const Table3 = /*#__PURE__*/fixedForwardRef(function Table3(props, ref) {
|
|
20719
20747
|
// we force a remount (using key) when the child columns change because there are too many places to add children as an effect
|
20720
20748
|
// this is cheaper from a complexity perspective, and probably performance wise as well
|
20721
20749
|
const key = React__default.useMemo(() => String('tableKey_' + stringifiedChildren), [stringifiedChildren]);
|
20750
|
+
const {
|
20751
|
+
loading
|
20752
|
+
} = useTableSettingsPreloader(props.id);
|
20753
|
+
if (loading) {
|
20754
|
+
return /*#__PURE__*/React__default.createElement(Spinner, null);
|
20755
|
+
}
|
20722
20756
|
return /*#__PURE__*/React__default.createElement(BaseTable3, Object.assign({}, props, {
|
20723
20757
|
key: key,
|
20724
20758
|
ref: ref
|
@@ -22755,7 +22789,6 @@ exports.Switch = Switch;
|
|
22755
22789
|
exports.Table = Table$1;
|
22756
22790
|
exports.Table3 = Table3;
|
22757
22791
|
exports.Tabs = Tabs;
|
22758
|
-
exports.TacoContext = TacoContext;
|
22759
22792
|
exports.Tag = Tag$1;
|
22760
22793
|
exports.Textarea = Textarea;
|
22761
22794
|
exports.Title = Title$3;
|