@economic/taco 2.53.0-alpha.1 → 2.53.0-settings.1
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/features/useTableRenderer.js +3 -1
- package/dist/esm/packages/taco/src/primitives/Table/Core/features/useTableRenderer.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/features/useTableRowActive.js +2 -2
- package/dist/esm/packages/taco/src/primitives/Table/useTableManager/features/useTableRowActive.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 +7 -5
- 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/esm/packages/taco/src/primitives/Table/useTableManager/util/setup.js +2 -1
- package/dist/esm/packages/taco/src/primitives/Table/useTableManager/util/setup.js.map +1 -1
- package/dist/hooks/useTaco.d.ts +1 -0
- package/dist/primitives/Table/Core/features/useTableRenderer.d.ts +2 -2
- package/dist/primitives/Table/Core/useTable.d.ts +4 -4
- package/dist/primitives/Table/types.d.ts +15 -6
- package/dist/primitives/Table/useTableManager/features/useTablePrinting.d.ts +2 -8
- package/dist/primitives/Table/useTableManager/features/useTableRowActive.d.ts +2 -2
- 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 +183 -148
- 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
|
@@ -10689,7 +10733,8 @@ function useReactTableInitialState(props, columns, persistedSettings, defaults)
|
|
10689
10733
|
columnPinning.left = freezeUptoExternalColumn(columnOrder.indexOf(columnPinning.left[columnPinning.left.length - 1]), columnOrder);
|
10690
10734
|
} else {
|
10691
10735
|
if (props.defaultColumnFreezingIndex) {
|
10692
|
-
|
10736
|
+
const index = typeof props.defaultColumnFreezingIndex === 'function' ? props.defaultColumnFreezingIndex(persistedSettings) : props.defaultColumnFreezingIndex;
|
10737
|
+
columnPinning.left = freezeUptoExternalColumn(index, columnOrder);
|
10693
10738
|
} else {
|
10694
10739
|
columnPinning.left = unfreezeAllExternalColumns(columnOrder);
|
10695
10740
|
}
|
@@ -10895,53 +10940,28 @@ function useTableFontSize(isEnabled = false, defaultFontSize = 'medium') {
|
|
10895
10940
|
};
|
10896
10941
|
}
|
10897
10942
|
|
10898
|
-
function
|
10943
|
+
function useTaco() {
|
10899
10944
|
return React__default.useContext(TacoContext);
|
10900
10945
|
}
|
10901
10946
|
|
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];
|
10947
|
+
const DEFAULT_PRINT_SETTINGS = {
|
10948
|
+
size: 'A4',
|
10949
|
+
orientation: 'portrait',
|
10950
|
+
allRows: true,
|
10951
|
+
splitGroups: true
|
10940
10952
|
};
|
10941
|
-
|
10942
10953
|
function useTablePrinting(isEnabled = false, tableId) {
|
10954
|
+
var _taco$settings$getSet, _taco$settings$getSet2;
|
10943
10955
|
const [isPrinting, setIsPrinting] = React__default.useState(false);
|
10944
|
-
const
|
10956
|
+
const taco = useTaco();
|
10957
|
+
const key = getSettingsId(tableId);
|
10958
|
+
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);
|
10959
|
+
function setSetting(path, value) {
|
10960
|
+
_setSettings(currentSettings => ({
|
10961
|
+
...currentSettings,
|
10962
|
+
[path]: value
|
10963
|
+
}));
|
10964
|
+
}
|
10945
10965
|
return {
|
10946
10966
|
isEnabled,
|
10947
10967
|
isPrinting,
|
@@ -10950,24 +10970,6 @@ function useTablePrinting(isEnabled = false, tableId) {
|
|
10950
10970
|
setSetting
|
10951
10971
|
};
|
10952
10972
|
}
|
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
10973
|
|
10972
10974
|
const DEFAULT_ROW_ACTIONS_LENGTH = 4;
|
10973
10975
|
function useTableRowActions(isEnabled = false, rowActions, rowActionsLength = DEFAULT_ROW_ACTIONS_LENGTH) {
|
@@ -11002,8 +11004,8 @@ const useIsHoverStatePaused = () => {
|
|
11002
11004
|
return [shouldPauseHoverState, setShouldPauseHoverState];
|
11003
11005
|
};
|
11004
11006
|
|
11005
|
-
function useTableRowActive(isEnabled = false, initialRowActiveIndex) {
|
11006
|
-
const [rowActiveIndex, setRowActiveIndex] = React__default.useState(initialRowActiveIndex);
|
11007
|
+
function useTableRowActive(isEnabled = false, tableSettings, initialRowActiveIndex) {
|
11008
|
+
const [rowActiveIndex, setRowActiveIndex] = React__default.useState(typeof initialRowActiveIndex === 'function' ? initialRowActiveIndex(tableSettings) : initialRowActiveIndex);
|
11007
11009
|
const [rowHoverIndex, setRowHoverIndex] = React__default.useState(undefined);
|
11008
11010
|
const [isHoverStatePaused, setHoverStatePaused] = useIsHoverStatePaused();
|
11009
11011
|
const move = (direction, length, scrollToIndex) => {
|
@@ -11637,69 +11639,6 @@ function useTableServerLoading(length, data, loadPage, loadAll, pages, pageSize
|
|
11637
11639
|
};
|
11638
11640
|
}
|
11639
11641
|
|
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
11642
|
// augments useEffect to not run on the initial mount
|
11704
11643
|
function useLazyEffect(effect, deps) {
|
11705
11644
|
const readyRef = React__default.useRef(false);
|
@@ -11831,26 +11770,70 @@ function useTableSearchListener(table) {
|
|
11831
11770
|
}, [meta.server.loading, meta.search.isEnabled, meta.search.enableGlobalFilter, table.getRowModel().rows.length, query, JSON.stringify(table.getState().sorting)]);
|
11832
11771
|
}
|
11833
11772
|
|
11834
|
-
function useTableSettingsListener(table,
|
11773
|
+
function useTableSettingsListener(table, tableId, isEnabled = false) {
|
11774
|
+
const [enabledSettings, hasSomeEnabledSettings] = useEnabledSettings(isEnabled);
|
11775
|
+
const taco = useTaco();
|
11835
11776
|
const meta = table.options.meta;
|
11836
11777
|
const state = table.getState();
|
11837
11778
|
React__default.useEffect(() => {
|
11838
|
-
|
11839
|
-
|
11840
|
-
|
11779
|
+
const handler = setTimeout(() => {
|
11780
|
+
if (!hasSomeEnabledSettings) {
|
11781
|
+
return;
|
11782
|
+
}
|
11783
|
+
const settings = removeDisabledSettings(getSettings(table), enabledSettings);
|
11784
|
+
if (Object.keys(settings).length) {
|
11841
11785
|
// some settings shouldn't be persisted, but we comment them out here to highlight the intention
|
11842
|
-
|
11843
|
-
}
|
11844
|
-
}
|
11786
|
+
taco.settings.saveSetting(getSettingsId(tableId), settings);
|
11787
|
+
}
|
11788
|
+
}, 100);
|
11845
11789
|
return () => clearTimeout(handler);
|
11846
11790
|
}, [
|
11847
11791
|
//state.columnFilters,
|
11848
11792
|
state.columnOrder, state.columnPinning, state.columnSizing, state.columnVisibility, table.options.enableGlobalFilter, meta.fontSize.size,
|
11849
11793
|
//state.grouping,
|
11850
|
-
meta.rowHeight.height,
|
11794
|
+
meta.printing.settings, meta.rowHeight.height,
|
11851
11795
|
//state.globalFilter,
|
11852
11796
|
state.sorting]);
|
11853
11797
|
}
|
11798
|
+
const DEFAULT_ENABLED_OPTIONS = {
|
11799
|
+
columnOrder: true,
|
11800
|
+
columnPinning: true,
|
11801
|
+
columnSizing: true,
|
11802
|
+
columnVisibility: true,
|
11803
|
+
excludeUnmatchedRecordsInSearch: true,
|
11804
|
+
fontSize: true,
|
11805
|
+
grouping: true,
|
11806
|
+
rowHeight: true,
|
11807
|
+
sorting: true
|
11808
|
+
};
|
11809
|
+
function useEnabledSettings(isEnabled) {
|
11810
|
+
return React__default.useMemo(() => {
|
11811
|
+
if (isEnabled === false) {
|
11812
|
+
return [Object.keys(DEFAULT_ENABLED_OPTIONS).reduce((o, key) => ({
|
11813
|
+
...o,
|
11814
|
+
[key]: false
|
11815
|
+
}), {}), false];
|
11816
|
+
} else if (isEnabled === true) {
|
11817
|
+
return [DEFAULT_ENABLED_OPTIONS, true];
|
11818
|
+
}
|
11819
|
+
const options = {
|
11820
|
+
...DEFAULT_ENABLED_OPTIONS,
|
11821
|
+
...isEnabled
|
11822
|
+
};
|
11823
|
+
return [options, Object.values(options).some(o => o === true)];
|
11824
|
+
}, [isEnabled]);
|
11825
|
+
}
|
11826
|
+
function removeDisabledSettings(settings, enabledSettings) {
|
11827
|
+
const sanitizedSettings = {
|
11828
|
+
...settings
|
11829
|
+
};
|
11830
|
+
Object.keys(enabledSettings).forEach(setting => {
|
11831
|
+
if (!enabledSettings[setting]) {
|
11832
|
+
delete sanitizedSettings[setting];
|
11833
|
+
}
|
11834
|
+
});
|
11835
|
+
return sanitizedSettings;
|
11836
|
+
}
|
11854
11837
|
|
11855
11838
|
function useTableShortcutsListener(table, shortcuts) {
|
11856
11839
|
const meta = table.options.meta;
|
@@ -11945,14 +11928,15 @@ function useTableRowDrop(isEnabled = false, onRowDrop) {
|
|
11945
11928
|
// Placed this array outside the hook to avoid creating a new array reference on each hook re-render
|
11946
11929
|
const DEFAULT_EMPTY_ARRAY = [];
|
11947
11930
|
function useTableManager(props, meta, internalColumns) {
|
11948
|
-
var _props$data, _props$length, _meta$editing, _instance$options$met;
|
11931
|
+
var _ref, _taco$settings$getSet, _props$data, _props$length, _meta$editing, _instance$options$met;
|
11932
|
+
const taco = useTaco();
|
11949
11933
|
const localization = useLocalization();
|
11950
11934
|
// CSS.escape would be best here, but it doesn't seem to work very well
|
11951
11935
|
const safeId = props.id.replace('.', '_');
|
11952
11936
|
// configure table options, merging props with presets
|
11953
11937
|
const options = getTableFeaturePreset(props);
|
11954
11938
|
// load any persisted table settings and merge them with any defaults
|
11955
|
-
const
|
11939
|
+
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
11940
|
// ensure data is always valid
|
11957
11941
|
const data = (_props$data = props.data) !== null && _props$data !== void 0 ? _props$data : DEFAULT_EMPTY_ARRAY;
|
11958
11942
|
const length = (_props$length = props.length) !== null && _props$length !== void 0 ? _props$length : data.length;
|
@@ -11962,7 +11946,7 @@ function useTableManager(props, meta, internalColumns) {
|
|
11962
11946
|
const fontSize = useTableFontSize(options.enableFontSize, settings.fontSize);
|
11963
11947
|
const footer = useTableFooter(options.enableFooter);
|
11964
11948
|
const printing = useTablePrinting(options.enablePrinting, safeId);
|
11965
|
-
const rowActive = useTableRowActive(options.enableRowActive, props.defaultRowActiveIndex);
|
11949
|
+
const rowActive = useTableRowActive(options.enableRowActive, settings, props.defaultRowActiveIndex);
|
11966
11950
|
const rowActions = useTableRowActions(options.enableRowActions, props.rowActions, props.rowActionsLength);
|
11967
11951
|
const rowClick = useTableRowClick(options.enableRowClick, props.onRowClick);
|
11968
11952
|
const rowDrag = useTableRowDrag(options.enableRowDrag && !(meta !== null && meta !== void 0 && (_meta$editing = meta.editing) !== null && _meta$editing !== void 0 && _meta$editing.isEditing), props.onRowDrag);
|
@@ -12027,7 +12011,7 @@ function useTableManager(props, meta, internalColumns) {
|
|
12027
12011
|
useTableRowSelectionListener(instance, props.onRowSelect);
|
12028
12012
|
useTableSearchListener(instance);
|
12029
12013
|
useTableServerLoadingListener(instance, server.loadPage);
|
12030
|
-
useTableSettingsListener(instance,
|
12014
|
+
useTableSettingsListener(instance, safeId, options.enableSaveSettings);
|
12031
12015
|
useTableShortcutsListener(instance, props.shortcuts);
|
12032
12016
|
useTableSortingListener(instance, props.onChangeSort);
|
12033
12017
|
return {
|
@@ -12499,7 +12483,8 @@ function useTableRenderer(renderers, table, tableRef, length, defaultRowActiveIn
|
|
12499
12483
|
// ensure default active rows are scrolled to
|
12500
12484
|
React__default.useEffect(() => {
|
12501
12485
|
if (defaultRowActiveIndex) {
|
12502
|
-
|
12486
|
+
const index = typeof defaultRowActiveIndex === 'function' ? defaultRowActiveIndex(getSettings(table)) : defaultRowActiveIndex;
|
12487
|
+
scrollToIndex(index, {
|
12503
12488
|
align: 'center',
|
12504
12489
|
behavior: 'auto'
|
12505
12490
|
});
|
@@ -17221,15 +17206,16 @@ function TableToolbar(props) {
|
|
17221
17206
|
const canPrint = table.meta.printing.isEnabled;
|
17222
17207
|
const canSettings = canChangeSettings(table.instance, table.props.customSettings);
|
17223
17208
|
const canSearch = table.meta.search.isEnabled;
|
17209
|
+
const settings = getSettings(table.instance);
|
17224
17210
|
return /*#__PURE__*/React__default.createElement(React__default.Fragment, null, /*#__PURE__*/React__default.createElement("div", Object.assign({}, attributes, {
|
17225
17211
|
className: "mb-4 flex flex-shrink flex-grow-0 flex-wrap gap-2 print:hidden",
|
17226
17212
|
"data-taco": "table-toolbar"
|
17227
|
-
}), table.props.toolbarLeft, /*#__PURE__*/React__default.createElement(Group, {
|
17213
|
+
}), typeof table.props.toolbarLeft === 'function' ? table.props.toolbarLeft(settings) : table.props.toolbarLeft, /*#__PURE__*/React__default.createElement(Group, {
|
17228
17214
|
className: "ml-auto flex-shrink-0 items-center print:hidden"
|
17229
17215
|
}, customTools, canFilter ? /*#__PURE__*/React__default.createElement(Filters, {
|
17230
17216
|
length: table.meta.length,
|
17231
17217
|
table: table.instance
|
17232
|
-
}) : null, table.props.toolbarRight, canPrint ? /*#__PURE__*/React__default.createElement(Print$1, {
|
17218
|
+
}) : null, typeof table.props.toolbarRight === 'function' ? table.props.toolbarRight(settings) : table.props.toolbarRight, canPrint ? /*#__PURE__*/React__default.createElement(Print$1, {
|
17233
17219
|
table: table.instance,
|
17234
17220
|
tableId: table.id,
|
17235
17221
|
tableRef: table.ref
|
@@ -17240,9 +17226,9 @@ function TableToolbar(props) {
|
|
17240
17226
|
scrollToIndex: table.renderer.scrollToIndex,
|
17241
17227
|
table: table.instance,
|
17242
17228
|
tableRef: table.ref
|
17243
|
-
})) : null)), table.props.toolbarPanel ? /*#__PURE__*/React__default.createElement("div", {
|
17229
|
+
})) : null)), table.props.toolbarPanel ? (/*#__PURE__*/React__default.createElement("div", {
|
17244
17230
|
className: "mb-4"
|
17245
|
-
}, table.props.toolbarPanel) : undefined);
|
17231
|
+
}, typeof table.props.toolbarPanel === 'function' ? table.props.toolbarPanel(settings) : table.props.toolbarPanel)) : undefined);
|
17246
17232
|
}
|
17247
17233
|
function canChangeSettings(table, customSettings) {
|
17248
17234
|
const tableMeta = table.options.meta;
|
@@ -17321,6 +17307,44 @@ function TableGrid(props) {
|
|
17321
17307
|
}, footerRows) : null)))));
|
17322
17308
|
}
|
17323
17309
|
|
17310
|
+
function getLegacySetting(currentKey) {
|
17311
|
+
try {
|
17312
|
+
const localStorageValue = localStorage.getItem(currentKey);
|
17313
|
+
if (localStorageValue) {
|
17314
|
+
const value = JSON.parse(localStorageValue || 'null');
|
17315
|
+
if (value !== null) {
|
17316
|
+
localStorage.removeItem(currentKey);
|
17317
|
+
return value;
|
17318
|
+
}
|
17319
|
+
}
|
17320
|
+
} catch {
|
17321
|
+
// If user is in private mode or has storage restriction
|
17322
|
+
// localStorage can throw. JSON.parse can throw, too.
|
17323
|
+
}
|
17324
|
+
return undefined;
|
17325
|
+
}
|
17326
|
+
function useTableSettingsPreloader(tableId) {
|
17327
|
+
const taco = useTaco();
|
17328
|
+
const [loading, setLoading] = React__default.useState(true);
|
17329
|
+
React__default.useLayoutEffect(() => {
|
17330
|
+
const key = getSettingsId(tableId);
|
17331
|
+
// migrate legacy settings if they exist, can be removed in the future
|
17332
|
+
const legacySettings = getLegacySetting(`taco.${taco.userId}.table.${tableId}.settings`);
|
17333
|
+
if (legacySettings) {
|
17334
|
+
const legacyPrintSettings = getLegacySetting(`taco.${taco.userId}.table.${tableId}.print.settings`);
|
17335
|
+
taco.settings.saveSetting(getSettingsId(tableId), {
|
17336
|
+
...legacySettings,
|
17337
|
+
print: legacyPrintSettings !== null && legacyPrintSettings !== void 0 ? legacyPrintSettings : {}
|
17338
|
+
}).finally(() => setLoading(false));
|
17339
|
+
} else {
|
17340
|
+
taco.settings.loadSetting(key).finally(() => setLoading(false));
|
17341
|
+
}
|
17342
|
+
}, []);
|
17343
|
+
return {
|
17344
|
+
loading
|
17345
|
+
};
|
17346
|
+
}
|
17347
|
+
|
17324
17348
|
function Column$1(_) {
|
17325
17349
|
return null;
|
17326
17350
|
}
|
@@ -17341,6 +17365,12 @@ const Report$1 = /*#__PURE__*/fixedForwardRef(function Report(props, ref) {
|
|
17341
17365
|
// we force a remount (using key) when the child columns change because there are too many places to add children as an effect
|
17342
17366
|
// this is cheaper from a complexity perspective, and probably performance wise as well
|
17343
17367
|
const key = React__default.useMemo(() => String('tableKey_' + stringifiedChildren), [stringifiedChildren]);
|
17368
|
+
const {
|
17369
|
+
loading
|
17370
|
+
} = useTableSettingsPreloader(props.id);
|
17371
|
+
if (loading) {
|
17372
|
+
return /*#__PURE__*/React__default.createElement(Spinner, null);
|
17373
|
+
}
|
17344
17374
|
return /*#__PURE__*/React__default.createElement(BaseReport, Object.assign({}, props, {
|
17345
17375
|
key: key,
|
17346
17376
|
ref: ref
|
@@ -20719,6 +20749,12 @@ const Table3 = /*#__PURE__*/fixedForwardRef(function Table3(props, ref) {
|
|
20719
20749
|
// we force a remount (using key) when the child columns change because there are too many places to add children as an effect
|
20720
20750
|
// this is cheaper from a complexity perspective, and probably performance wise as well
|
20721
20751
|
const key = React__default.useMemo(() => String('tableKey_' + stringifiedChildren), [stringifiedChildren]);
|
20752
|
+
const {
|
20753
|
+
loading
|
20754
|
+
} = useTableSettingsPreloader(props.id);
|
20755
|
+
if (loading) {
|
20756
|
+
return /*#__PURE__*/React__default.createElement(Spinner, null);
|
20757
|
+
}
|
20722
20758
|
return /*#__PURE__*/React__default.createElement(BaseTable3, Object.assign({}, props, {
|
20723
20759
|
key: key,
|
20724
20760
|
ref: ref
|
@@ -22755,7 +22791,6 @@ exports.Switch = Switch;
|
|
22755
22791
|
exports.Table = Table$1;
|
22756
22792
|
exports.Table3 = Table3;
|
22757
22793
|
exports.Tabs = Tabs;
|
22758
|
-
exports.TacoContext = TacoContext;
|
22759
22794
|
exports.Tag = Tag$1;
|
22760
22795
|
exports.Textarea = Textarea;
|
22761
22796
|
exports.Title = Title$3;
|