@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
@@ -1,26 +1,71 @@
|
|
1
1
|
import React__default from 'react';
|
2
|
-
import { getSettings } from '../util/settings.js';
|
2
|
+
import { getSettings, getSettingsId } from '../util/settings.js';
|
3
|
+
import { useTaco } from '../../../../hooks/useTaco.js';
|
3
4
|
|
4
|
-
function useTableSettingsListener(table,
|
5
|
+
function useTableSettingsListener(table, tableId, isEnabled = false) {
|
6
|
+
const [enabledSettings, hasSomeEnabledSettings] = useEnabledSettings(isEnabled);
|
7
|
+
const taco = useTaco();
|
5
8
|
const meta = table.options.meta;
|
6
9
|
const state = table.getState();
|
7
10
|
React__default.useEffect(() => {
|
8
|
-
|
9
|
-
|
10
|
-
|
11
|
+
const handler = setTimeout(() => {
|
12
|
+
if (!hasSomeEnabledSettings) {
|
13
|
+
return;
|
14
|
+
}
|
15
|
+
const settings = removeDisabledSettings(getSettings(table), enabledSettings);
|
16
|
+
if (Object.keys(settings).length) {
|
11
17
|
// some settings shouldn't be persisted, but we comment them out here to highlight the intention
|
12
|
-
|
13
|
-
}
|
14
|
-
}
|
18
|
+
taco.settings.saveSetting(getSettingsId(tableId), settings);
|
19
|
+
}
|
20
|
+
}, 100);
|
15
21
|
return () => clearTimeout(handler);
|
16
22
|
}, [
|
17
23
|
//state.columnFilters,
|
18
24
|
state.columnOrder, state.columnPinning, state.columnSizing, state.columnVisibility, table.options.enableGlobalFilter, meta.fontSize.size,
|
19
25
|
//state.grouping,
|
20
|
-
meta.rowHeight.height,
|
26
|
+
meta.printing.settings, meta.rowHeight.height,
|
21
27
|
//state.globalFilter,
|
22
28
|
state.sorting]);
|
23
29
|
}
|
30
|
+
const DEFAULT_ENABLED_OPTIONS = {
|
31
|
+
columnOrder: true,
|
32
|
+
columnPinning: true,
|
33
|
+
columnSizing: true,
|
34
|
+
columnVisibility: true,
|
35
|
+
excludeUnmatchedRecordsInSearch: true,
|
36
|
+
fontSize: true,
|
37
|
+
grouping: true,
|
38
|
+
rowHeight: true,
|
39
|
+
sorting: true
|
40
|
+
};
|
41
|
+
function useEnabledSettings(isEnabled) {
|
42
|
+
return React__default.useMemo(() => {
|
43
|
+
if (isEnabled === false) {
|
44
|
+
return [Object.keys(DEFAULT_ENABLED_OPTIONS).reduce((o, key) => ({
|
45
|
+
...o,
|
46
|
+
[key]: false
|
47
|
+
}), {}), false];
|
48
|
+
} else if (isEnabled === true) {
|
49
|
+
return [DEFAULT_ENABLED_OPTIONS, true];
|
50
|
+
}
|
51
|
+
const options = {
|
52
|
+
...DEFAULT_ENABLED_OPTIONS,
|
53
|
+
...isEnabled
|
54
|
+
};
|
55
|
+
return [options, Object.values(options).some(o => o === true)];
|
56
|
+
}, [isEnabled]);
|
57
|
+
}
|
58
|
+
function removeDisabledSettings(settings, enabledSettings) {
|
59
|
+
const sanitizedSettings = {
|
60
|
+
...settings
|
61
|
+
};
|
62
|
+
Object.keys(enabledSettings).forEach(setting => {
|
63
|
+
if (!enabledSettings[setting]) {
|
64
|
+
delete sanitizedSettings[setting];
|
65
|
+
}
|
66
|
+
});
|
67
|
+
return sanitizedSettings;
|
68
|
+
}
|
24
69
|
|
25
70
|
export { useTableSettingsListener };
|
26
71
|
//# sourceMappingURL=useTableSettingsListener.js.map
|
@@ -1 +1 @@
|
|
1
|
-
{"version":3,"file":"useTableSettingsListener.js","sources":["../../../../../../../../../src/primitives/Table/useTableManager/listeners/useTableSettingsListener.ts"],"sourcesContent":["import React from 'react';\nimport { Table as ReactTable, TableMeta as ReactTableMeta } from '@tanstack/react-table';\nimport {
|
1
|
+
{"version":3,"file":"useTableSettingsListener.js","sources":["../../../../../../../../../src/primitives/Table/useTableManager/listeners/useTableSettingsListener.ts"],"sourcesContent":["import React from 'react';\nimport { Table as ReactTable, TableMeta as ReactTableMeta } from '@tanstack/react-table';\nimport { getSettings, getSettingsId } from '../util/settings';\nimport { useTaco } from '../../../../hooks/useTaco';\nimport { TableEnableSettingsOptions, TableSettings } from '../../types';\n\nexport function useTableSettingsListener<TType = unknown>(\n table: ReactTable<TType>,\n tableId: string,\n isEnabled: boolean | Partial<TableEnableSettingsOptions> = false\n) {\n const [enabledSettings, hasSomeEnabledSettings] = useEnabledSettings(isEnabled);\n const taco = useTaco();\n const meta = table.options.meta as ReactTableMeta<TType>;\n const state = table.getState();\n\n React.useEffect(() => {\n const handler = setTimeout(() => {\n if (!hasSomeEnabledSettings) {\n return;\n }\n\n const settings = removeDisabledSettings(getSettings(table), enabledSettings);\n\n if (Object.keys(settings).length) {\n // some settings shouldn't be persisted, but we comment them out here to highlight the intention\n taco.settings.saveSetting(getSettingsId(tableId), settings);\n }\n }, 100);\n\n return () => clearTimeout(handler);\n }, [\n //state.columnFilters,\n state.columnOrder,\n state.columnPinning,\n state.columnSizing,\n state.columnVisibility,\n table.options.enableGlobalFilter,\n meta.fontSize.size,\n //state.grouping,\n meta.printing.settings,\n meta.rowHeight.height,\n //state.globalFilter,\n state.sorting,\n ]);\n}\n\nconst DEFAULT_ENABLED_OPTIONS = {\n columnOrder: true,\n columnPinning: true,\n columnSizing: true,\n columnVisibility: true,\n excludeUnmatchedRecordsInSearch: true,\n fontSize: true,\n grouping: true,\n rowHeight: true,\n sorting: true,\n};\n\nfunction useEnabledSettings(isEnabled: boolean | Partial<TableEnableSettingsOptions>): [TableEnableSettingsOptions, boolean] {\n return React.useMemo(() => {\n if (isEnabled === false) {\n return [\n Object.keys(DEFAULT_ENABLED_OPTIONS).reduce(\n (o, key) => ({ ...o, [key]: false }),\n {}\n ) as TableEnableSettingsOptions,\n false,\n ];\n } else if (isEnabled === true) {\n return [DEFAULT_ENABLED_OPTIONS, true];\n }\n\n const options = { ...DEFAULT_ENABLED_OPTIONS, ...isEnabled };\n return [options, Object.values(options).some(o => o === true)];\n }, [isEnabled]);\n}\n\nfunction removeDisabledSettings(settings: TableSettings, enabledSettings: TableEnableSettingsOptions) {\n const sanitizedSettings: TableSettings = { ...settings };\n\n Object.keys(enabledSettings).forEach(setting => {\n if (!enabledSettings[setting]) {\n delete sanitizedSettings[setting];\n }\n });\n\n return sanitizedSettings;\n}\n"],"names":["useTableSettingsListener","table","tableId","isEnabled","enabledSettings","hasSomeEnabledSettings","useEnabledSettings","taco","useTaco","meta","options","state","getState","React","useEffect","handler","setTimeout","settings","removeDisabledSettings","getSettings","Object","keys","length","saveSetting","getSettingsId","clearTimeout","columnOrder","columnPinning","columnSizing","columnVisibility","enableGlobalFilter","fontSize","size","printing","rowHeight","height","sorting","DEFAULT_ENABLED_OPTIONS","excludeUnmatchedRecordsInSearch","grouping","useMemo","reduce","o","key","values","some","sanitizedSettings","forEach","setting"],"mappings":";;;;SAMgBA,wBAAwBA,CACpCC,KAAwB,EACxBC,OAAe,EACfC,YAA2D,KAAK;EAEhE,MAAM,CAACC,eAAe,EAAEC,sBAAsB,CAAC,GAAGC,kBAAkB,CAACH,SAAS,CAAC;EAC/E,MAAMI,IAAI,GAAGC,OAAO,EAAE;EACtB,MAAMC,IAAI,GAAGR,KAAK,CAACS,OAAO,CAACD,IAA6B;EACxD,MAAME,KAAK,GAAGV,KAAK,CAACW,QAAQ,EAAE;EAE9BC,cAAK,CAACC,SAAS,CAAC;IACZ,MAAMC,OAAO,GAAGC,UAAU,CAAC;MACvB,IAAI,CAACX,sBAAsB,EAAE;QACzB;;MAGJ,MAAMY,QAAQ,GAAGC,sBAAsB,CAACC,WAAW,CAAClB,KAAK,CAAC,EAAEG,eAAe,CAAC;MAE5E,IAAIgB,MAAM,CAACC,IAAI,CAACJ,QAAQ,CAAC,CAACK,MAAM,EAAE;;QAE9Bf,IAAI,CAACU,QAAQ,CAACM,WAAW,CAACC,aAAa,CAACtB,OAAO,CAAC,EAAEe,QAAQ,CAAC;;KAElE,EAAE,GAAG,CAAC;IAEP,OAAO,MAAMQ,YAAY,CAACV,OAAO,CAAC;GACrC,EAAE;;EAECJ,KAAK,CAACe,WAAW,EACjBf,KAAK,CAACgB,aAAa,EACnBhB,KAAK,CAACiB,YAAY,EAClBjB,KAAK,CAACkB,gBAAgB,EACtB5B,KAAK,CAACS,OAAO,CAACoB,kBAAkB,EAChCrB,IAAI,CAACsB,QAAQ,CAACC,IAAI;;EAElBvB,IAAI,CAACwB,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,CAAC,EAAE;MAC3B,OAAOF,iBAAiB,CAACE,OAAO,CAAC;;GAExC,CAAC;EAEF,OAAOF,iBAAiB;AAC5B;;;;"}
|
@@ -1,11 +1,13 @@
|
|
1
1
|
import { useLocalization } from '../../../components/Provider/Localization.js';
|
2
2
|
import { useReactTable, getCoreRowModel } from '@tanstack/react-table';
|
3
|
+
import { getSettingsId } from './util/settings.js';
|
3
4
|
import { mapTableChildrenToColumns, useReactTableInitialState, configureReactTableOptions } from './util/setup.js';
|
4
5
|
import { getTableFeaturePreset } from './util/presets.js';
|
5
6
|
import { useTableColumnFreezing } from './features/useTableColumnFreezing.js';
|
6
7
|
import { useTableColumnOrdering } from './features/useTableColumnOrdering.js';
|
7
8
|
import { useTableFooter } from './features/useTableFooter.js';
|
8
9
|
import { useTableFontSize } from './features/useTableFontSize.js';
|
10
|
+
import { useTaco } from '../../../hooks/useTaco.js';
|
9
11
|
import { useTablePrinting } from './features/useTablePrinting.js';
|
10
12
|
import { useTableRowActions } from './features/useTableRowActions.js';
|
11
13
|
import { useTableRowActive } from './features/useTableRowActive.js';
|
@@ -17,7 +19,6 @@ import { useTableRowHeight } from './features/useTableRowHeight.js';
|
|
17
19
|
import { useTableRowSelection } from './features/useTableRowSelection.js';
|
18
20
|
import { useTableSearch } from './features/useTableSearch.js';
|
19
21
|
import { useTableServerLoading } from './features/useTableServerLoading.js';
|
20
|
-
import { useTableSettings } from './features/useTableSettings.js';
|
21
22
|
import { useTableDataListener } from './listeners/useTableDataListener.js';
|
22
23
|
import { useTableFilterListener } from './listeners/useTableFilterListener.js';
|
23
24
|
import { useTableFontSizeListener } from './listeners/useTableFontSizeListener.js';
|
@@ -34,14 +35,15 @@ import { useTableRowDrop } from './features/useTableRowDrop.js';
|
|
34
35
|
// Placed this array outside the hook to avoid creating a new array reference on each hook re-render
|
35
36
|
const DEFAULT_EMPTY_ARRAY = [];
|
36
37
|
function useTableManager(props, meta, internalColumns) {
|
37
|
-
var _props$data, _props$length, _meta$editing, _instance$options$met;
|
38
|
+
var _ref, _taco$settings$getSet, _props$data, _props$length, _meta$editing, _instance$options$met;
|
39
|
+
const taco = useTaco();
|
38
40
|
const localization = useLocalization();
|
39
41
|
// CSS.escape would be best here, but it doesn't seem to work very well
|
40
42
|
const safeId = props.id.replace('.', '_');
|
41
43
|
// configure table options, merging props with presets
|
42
44
|
const options = getTableFeaturePreset(props);
|
43
45
|
// load any persisted table settings and merge them with any defaults
|
44
|
-
const
|
46
|
+
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 : {};
|
45
47
|
// ensure data is always valid
|
46
48
|
const data = (_props$data = props.data) !== null && _props$data !== void 0 ? _props$data : DEFAULT_EMPTY_ARRAY;
|
47
49
|
const length = (_props$length = props.length) !== null && _props$length !== void 0 ? _props$length : data.length;
|
@@ -116,7 +118,7 @@ function useTableManager(props, meta, internalColumns) {
|
|
116
118
|
useTableRowSelectionListener(instance, props.onRowSelect);
|
117
119
|
useTableSearchListener(instance);
|
118
120
|
useTableServerLoadingListener(instance, server.loadPage);
|
119
|
-
useTableSettingsListener(instance,
|
121
|
+
useTableSettingsListener(instance, safeId, options.enableSaveSettings);
|
120
122
|
useTableShortcutsListener(instance, props.shortcuts);
|
121
123
|
useTableSortingListener(instance, props.onChangeSort);
|
122
124
|
return {
|
@@ -1 +1 @@
|
|
1
|
-
{"version":3,"file":"useTableManager.js","sources":["../../../../../../../../src/primitives/Table/useTableManager/useTableManager.ts"],"sourcesContent":["import { useReactTable, TableMeta as ReactTableMeta, RowData, getCoreRowModel } from '@tanstack/react-table';\nimport {\n TableColumnAlignment,\n TableColumnClassNameHandler,\n TableColumnDataType,\n TableColumnMenu,\n TableColumnRenderer,\n TableColumnRendererControl,\n TableEventHandler,\n TableFilterComparator,\n TableProps,\n} from '../types';\nimport { useReactTableInitialState, configureReactTableOptions, mapTableChildrenToColumns } from './util/setup';\nimport { getTableFeaturePreset } from './util/presets';\nimport { useTableColumnFreezing } from './features/useTableColumnFreezing';\nimport { useTableColumnOrdering } from './features/useTableColumnOrdering';\nimport { useTableFooter } from './features/useTableFooter';\nimport { useTableFontSize } from './features/useTableFontSize';\nimport { useTablePrinting } from './features/useTablePrinting';\nimport { useTableRowActions } from './features/useTableRowActions';\nimport { useTableRowActive } from './features/useTableRowActive';\nimport { useTableRowClick } from './features/useTableRowClick';\nimport { useTableRowExpansion } from './features/useTableRowExpansion';\nimport { useTableRowGoto } from './features/useTableRowGoto';\nimport { useTableRowGroups } from './features/useTableRowGroups';\nimport { useTableRowHeight } from './features/useTableRowHeight';\nimport { useTableRowSelection } from './features/useTableRowSelection';\nimport { useTableSearch } from './features/useTableSearch';\nimport { useTableServerLoading } from './features/useTableServerLoading';\nimport { useTableSettings } from './features/useTableSettings';\nimport { useTableDataListener } from './listeners/useTableDataListener';\nimport { useTableFilterListener } from './listeners/useTableFilterListener';\nimport { useTableFontSizeListener } from './listeners/useTableFontSizeListener';\nimport { useTableRowHeightListener } from './listeners/useTableRowHeightListener';\nimport { useTableRowSelectionListener } from './listeners/useTableRowSelectionListener';\nimport { useTableSearchListener } from './listeners/useTableSearchListener';\nimport { useTableSettingsListener } from './listeners/useTableSettingsListener';\nimport { useTableShortcutsListener } from './listeners/useTableShortcutsListener';\nimport { useTableSortingListener } from './listeners/useTableSortingListener';\nimport { useTableServerLoadingListener } from './listeners/useTableServerLoadingListener';\nimport { useTableManagerInternalColumns } from './types';\nimport { useTableRowDrag } from './features/useTableRowDrag';\nimport { useTableRowDrop } from './features/useTableRowDrop';\nimport { useLocalization } from '../../../components/Provider/Localization';\n\n/*\n EDITING THIS FILE? READ ME FIRST!\n\n This is a shared, common hook for multiple tables. It's feature set is specifically chosen to support features\n common across those tables. If you are adding a new feature or changing an existing one, before writing any code\n in this file ask yourself the question - is this specific to a given table, or is it common to all of them.\n If you are unsure, ask your team first.\n*/\n\ndeclare module '@tanstack/table-core' {\n interface TableMeta<TData extends RowData> {\n columnFreezing: ReturnType<typeof useTableColumnFreezing>;\n columnOrdering: ReturnType<typeof useTableColumnOrdering>;\n fontSize: ReturnType<typeof useTableFontSize>;\n footer: ReturnType<typeof useTableFooter>;\n length: number;\n onEvent: TableEventHandler;\n printing: ReturnType<typeof useTablePrinting>;\n rowActions: ReturnType<typeof useTableRowActions>;\n rowActive: ReturnType<typeof useTableRowActive>;\n rowClick: ReturnType<typeof useTableRowClick>;\n rowDrag: ReturnType<typeof useTableRowDrag>;\n rowDrop: ReturnType<typeof useTableRowDrop>;\n rowExpansion: ReturnType<typeof useTableRowExpansion>;\n rowGoto: ReturnType<typeof useTableRowGoto>;\n rowGroups: ReturnType<typeof useTableRowGroups>;\n rowHeight: ReturnType<typeof useTableRowHeight>;\n rowIdentityAccessor: keyof TData;\n rowSelection: ReturnType<typeof useTableRowSelection>;\n search: ReturnType<typeof useTableSearch>;\n server: ReturnType<typeof useTableServerLoading>;\n }\n\n interface ColumnMeta<TData extends RowData, TValue> {\n align?: TableColumnAlignment;\n className?: TableColumnClassNameHandler<TData>;\n control?: TableColumnRendererControl<TData>;\n dataType?: TableColumnDataType;\n defaultWidth?: number;\n enableEditing?: boolean;\n enableOrdering?: boolean;\n enablePrinting?: boolean;\n enableSearch?: boolean;\n enableTruncate?: boolean;\n filters?: TableFilterComparator[];\n header: string;\n headerClassName?: string;\n menu?: TableColumnMenu;\n renderer?: TableColumnRenderer<TValue, TData>;\n tooltip?: string;\n }\n}\n\n// Placed this array outside the hook to avoid creating a new array reference on each hook re-render\nconst DEFAULT_EMPTY_ARRAY = [];\n\nexport function useTableManager<TType = unknown, TMeta = {}>(\n props: TableProps<TType>,\n meta?: Partial<ReactTableMeta<TType>> & TMeta,\n internalColumns?: useTableManagerInternalColumns<TType>\n) {\n const localization = useLocalization();\n // CSS.escape would be best here, but it doesn't seem to work very well\n const safeId = props.id.replace('.', '_');\n // configure table options, merging props with presets\n const options = getTableFeaturePreset(props);\n\n // load any persisted table settings and merge them with any defaults\n const [settings, setSettings] = useTableSettings(\n options.enableSaveSettings,\n safeId,\n props.defaultSettings,\n props.onChangeSettings\n );\n\n // ensure data is always valid\n const data = props.data ?? DEFAULT_EMPTY_ARRAY;\n const length = props.length ?? data.length;\n\n // configure common custom features\n const columnFreezing = useTableColumnFreezing(options.enableColumnFreezing);\n const columnOrdering = useTableColumnOrdering(options.enableColumnOrdering);\n const fontSize = useTableFontSize(options.enableFontSize, settings.fontSize);\n const footer = useTableFooter(options.enableFooter);\n const printing = useTablePrinting(options.enablePrinting, safeId);\n const rowActive = useTableRowActive(options.enableRowActive, props.defaultRowActiveIndex);\n const rowActions = useTableRowActions<TType>(options.enableRowActions, props.rowActions, props.rowActionsLength);\n const rowClick = useTableRowClick<TType>(options.enableRowClick, props.onRowClick);\n const rowDrag = useTableRowDrag<TType>(options.enableRowDrag && !meta?.editing?.isEditing, props.onRowDrag);\n const rowDrop = useTableRowDrop<TType>(options.enableRowDrop, props.onRowDrop);\n const rowExpansion = useTableRowExpansion<TType>(\n options.enableRowExpansion,\n options.enableRowExpansionAll,\n props.rowExpansionRenderer\n );\n const rowGoto = useTableRowGoto(options.enableRowGoto, props.onRowGoto);\n const rowGroups = useTableRowGroups(props.rowActionsForGroup);\n const rowHeight = useTableRowHeight(options.enableRowHeight, settings.rowHeight);\n const rowSelection = useTableRowSelection(!!options.enableRowSelection);\n const search = useTableSearch(options.enableSearch, props.onChangeSearch, settings.excludeUnmatchedRecordsInSearch);\n const server = useTableServerLoading(\n length,\n data,\n props.loadPage,\n props.loadAll,\n props.pages,\n props.pageSize,\n props._experimentalDataLoader2\n );\n\n // TODO: memoise\n // convert jsx column components into valid table columns\n const { columns, ...defaultState } = mapTableChildrenToColumns<TType>(\n props,\n settings,\n options,\n internalColumns,\n localization\n );\n\n // configure initial table state\n const initialState = useReactTableInitialState<TType>(props, columns, settings, defaultState);\n\n // create a react-table instance\n const instance = useReactTable<TType>({\n data,\n columns,\n // configure initial table state\n initialState,\n getCoreRowModel: getCoreRowModel<TType>(),\n // configure react-table built-in features\n ...configureReactTableOptions<TType>(options, props, localization),\n // settings that can be toggled by the user, and therefore require our own state\n enableGlobalFilter: search.enableGlobalFilter,\n // custom context\n meta: {\n // spread features from specific implementations\n ...meta,\n columnFreezing,\n columnOrdering,\n fontSize,\n footer,\n length,\n onEvent: props.onEvent,\n printing,\n rowActions: rowActions as any, // no other way around ReturnType<typeof X> not supporting generics\n rowActive,\n rowClick: rowClick as any, // no other way around ReturnType<typeof X> not supporting generics\n rowDrag,\n rowDrop: rowDrop as any, // no other way around ReturnType<typeof X> not supporting generics\n rowExpansion: rowExpansion as any, // no other way around ReturnType<typeof X> not supporting generics\n rowIdentityAccessor: props.rowIdentityAccessor,\n rowGoto,\n rowGroups: rowGroups as any, // no other way around ReturnType<typeof X> not supporting generics\n rowHeight,\n rowSelection,\n search,\n server,\n } as ReactTableMeta<TType> & TMeta,\n });\n\n // state listeners - we have these so that we don't have to control state outside the table\n useTableDataListener(instance, length);\n useTableFilterListener(instance, props.onChangeFilter);\n useTableFontSizeListener(instance);\n useTableRowHeightListener(instance);\n useTableRowSelectionListener(instance, props.onRowSelect);\n useTableSearchListener(instance);\n useTableServerLoadingListener(instance, server.loadPage);\n useTableSettingsListener(instance, setSettings);\n useTableShortcutsListener(instance, props.shortcuts);\n useTableSortingListener(instance, props.onChangeSort);\n\n return {\n id: safeId,\n instance,\n meta: (instance.options.meta ?? {}) as ReactTableMeta<TType> & TMeta,\n state: instance.getState(),\n };\n}\n"],"names":["DEFAULT_EMPTY_ARRAY","useTableManager","props","meta","internalColumns","localization","useLocalization","safeId","id","replace","options","getTableFeaturePreset","settings","setSettings","useTableSettings","enableSaveSettings","defaultSettings","onChangeSettings","data","_props$data","length","_props$length","columnFreezing","useTableColumnFreezing","enableColumnFreezing","columnOrdering","useTableColumnOrdering","enableColumnOrdering","fontSize","useTableFontSize","enableFontSize","footer","useTableFooter","enableFooter","printing","useTablePrinting","enablePrinting","rowActive","useTableRowActive","enableRowActive","defaultRowActiveIndex","rowActions","useTableRowActions","enableRowActions","rowActionsLength","rowClick","useTableRowClick","enableRowClick","onRowClick","rowDrag","useTableRowDrag","enableRowDrag","_meta$editing","editing","isEditing","onRowDrag","rowDrop","useTableRowDrop","enableRowDrop","onRowDrop","rowExpansion","useTableRowExpansion","enableRowExpansion","enableRowExpansionAll","rowExpansionRenderer","rowGoto","useTableRowGoto","enableRowGoto","onRowGoto","rowGroups","useTableRowGroups","rowActionsForGroup","rowHeight","useTableRowHeight","enableRowHeight","rowSelection","useTableRowSelection","enableRowSelection","search","useTableSearch","enableSearch","onChangeSearch","excludeUnmatchedRecordsInSearch","server","useTableServerLoading","loadPage","loadAll","pages","pageSize","_experimentalDataLoader2","columns","defaultState","mapTableChildrenToColumns","initialState","useReactTableInitialState","instance","useReactTable","getCoreRowModel","configureReactTableOptions","enableGlobalFilter","onEvent","rowIdentityAccessor","useTableDataListener","useTableFilterListener","onChangeFilter","useTableFontSizeListener","useTableRowHeightListener","useTableRowSelectionListener","onRowSelect","useTableSearchListener","useTableServerLoadingListener","useTableSettingsListener","useTableShortcutsListener","shortcuts","useTableSortingListener","onChangeSort","_instance$options$met","state","getState"],"mappings":";;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;AAkGA;AACA,MAAMA,mBAAmB,GAAG,EAAE;SAEdC,eAAeA,CAC3BC,KAAwB,EACxBC,IAA6C,EAC7CC,eAAuD;;EAEvD,MAAMC,YAAY,GAAGC,eAAe,EAAE;;EAEtC,MAAMC,MAAM,GAAGL,KAAK,CAACM,EAAE,CAACC,OAAO,CAAC,GAAG,EAAE,GAAG,CAAC;;EAEzC,MAAMC,OAAO,GAAGC,qBAAqB,CAACT,KAAK,CAAC;;EAG5C,MAAM,CAACU,QAAQ,EAAEC,WAAW,CAAC,GAAGC,gBAAgB,CAC5CJ,OAAO,CAACK,kBAAkB,EAC1BR,MAAM,EACNL,KAAK,CAACc,eAAe,EACrBd,KAAK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,QAAQ,CAACuB,QAAQ;GAC3B;AACL;;;;"}
|
1
|
+
{"version":3,"file":"useTableManager.js","sources":["../../../../../../../../src/primitives/Table/useTableManager/useTableManager.ts"],"sourcesContent":["import { useReactTable, TableMeta as ReactTableMeta, RowData, getCoreRowModel } from '@tanstack/react-table';\nimport {\n TableColumnAlignment,\n TableColumnClassNameHandler,\n TableColumnDataType,\n TableColumnMenu,\n TableColumnRenderer,\n TableColumnRendererControl,\n TableEventHandler,\n TableFilterComparator,\n TableProps,\n TableSettings,\n} from '../types';\nimport { useReactTableInitialState, configureReactTableOptions, mapTableChildrenToColumns } from './util/setup';\nimport { getTableFeaturePreset } from './util/presets';\nimport { useTableColumnFreezing } from './features/useTableColumnFreezing';\nimport { useTableColumnOrdering } from './features/useTableColumnOrdering';\nimport { useTableFooter } from './features/useTableFooter';\nimport { useTableFontSize } from './features/useTableFontSize';\nimport { useTablePrinting } from './features/useTablePrinting';\nimport { useTableRowActions } from './features/useTableRowActions';\nimport { useTableRowActive } from './features/useTableRowActive';\nimport { useTableRowClick } from './features/useTableRowClick';\nimport { useTableRowExpansion } from './features/useTableRowExpansion';\nimport { useTableRowGoto } from './features/useTableRowGoto';\nimport { useTableRowGroups } from './features/useTableRowGroups';\nimport { useTableRowHeight } from './features/useTableRowHeight';\nimport { useTableRowSelection } from './features/useTableRowSelection';\nimport { useTableSearch } from './features/useTableSearch';\nimport { useTableServerLoading } from './features/useTableServerLoading';\nimport { useTableDataListener } from './listeners/useTableDataListener';\nimport { useTableFilterListener } from './listeners/useTableFilterListener';\nimport { useTableFontSizeListener } from './listeners/useTableFontSizeListener';\nimport { useTableRowHeightListener } from './listeners/useTableRowHeightListener';\nimport { useTableRowSelectionListener } from './listeners/useTableRowSelectionListener';\nimport { useTableSearchListener } from './listeners/useTableSearchListener';\nimport { useTableSettingsListener } from './listeners/useTableSettingsListener';\nimport { useTableShortcutsListener } from './listeners/useTableShortcutsListener';\nimport { useTableSortingListener } from './listeners/useTableSortingListener';\nimport { useTableServerLoadingListener } from './listeners/useTableServerLoadingListener';\nimport { useTableManagerInternalColumns } from './types';\nimport { useTableRowDrag } from './features/useTableRowDrag';\nimport { useTableRowDrop } from './features/useTableRowDrop';\nimport { useLocalization } from '../../../components/Provider/Localization';\nimport { useTaco } from '../../../hooks/useTaco';\nimport { getSettingsId } from './util/settings';\n\n/*\n EDITING THIS FILE? READ ME FIRST!\n\n This is a shared, common hook for multiple tables. It's feature set is specifically chosen to support features\n common across those tables. If you are adding a new feature or changing an existing one, before writing any code\n in this file ask yourself the question - is this specific to a given table, or is it common to all of them.\n If you are unsure, ask your team first.\n*/\n\ndeclare module '@tanstack/table-core' {\n interface TableMeta<TData extends RowData> {\n columnFreezing: ReturnType<typeof useTableColumnFreezing>;\n columnOrdering: ReturnType<typeof useTableColumnOrdering>;\n fontSize: ReturnType<typeof useTableFontSize>;\n footer: ReturnType<typeof useTableFooter>;\n length: number;\n onEvent: TableEventHandler;\n printing: ReturnType<typeof useTablePrinting>;\n rowActions: ReturnType<typeof useTableRowActions>;\n rowActive: ReturnType<typeof useTableRowActive>;\n rowClick: ReturnType<typeof useTableRowClick>;\n rowDrag: ReturnType<typeof useTableRowDrag>;\n rowDrop: ReturnType<typeof useTableRowDrop>;\n rowExpansion: ReturnType<typeof useTableRowExpansion>;\n rowGoto: ReturnType<typeof useTableRowGoto>;\n rowGroups: ReturnType<typeof useTableRowGroups>;\n rowHeight: ReturnType<typeof useTableRowHeight>;\n rowIdentityAccessor: keyof TData;\n rowSelection: ReturnType<typeof useTableRowSelection>;\n search: ReturnType<typeof useTableSearch>;\n server: ReturnType<typeof useTableServerLoading>;\n }\n\n interface ColumnMeta<TData extends RowData, TValue> {\n align?: TableColumnAlignment;\n className?: TableColumnClassNameHandler<TData>;\n control?: TableColumnRendererControl<TData>;\n dataType?: TableColumnDataType;\n defaultWidth?: number;\n enableEditing?: boolean;\n enableOrdering?: boolean;\n enablePrinting?: boolean;\n enableSearch?: boolean;\n enableTruncate?: boolean;\n filters?: TableFilterComparator[];\n header: string;\n headerClassName?: string;\n menu?: TableColumnMenu;\n renderer?: TableColumnRenderer<TValue, TData>;\n tooltip?: string;\n }\n}\n\n// Placed this array outside the hook to avoid creating a new array reference on each hook re-render\nconst DEFAULT_EMPTY_ARRAY = [];\n\nexport function useTableManager<TType = unknown, TMeta = {}>(\n props: TableProps<TType>,\n meta?: Partial<ReactTableMeta<TType>> & TMeta,\n internalColumns?: useTableManagerInternalColumns<TType>\n) {\n const taco = useTaco();\n const localization = useLocalization();\n // CSS.escape would be best here, but it doesn't seem to work very well\n const safeId = props.id.replace('.', '_');\n // configure table options, merging props with presets\n const options = getTableFeaturePreset(props);\n\n // load any persisted table settings and merge them with any defaults\n const settings = taco.settings.getSetting<TableSettings>(getSettingsId(safeId)) ?? props.defaultSettings ?? {};\n\n // ensure data is always valid\n const data = props.data ?? DEFAULT_EMPTY_ARRAY;\n const length = props.length ?? data.length;\n\n // configure common custom features\n const columnFreezing = useTableColumnFreezing(options.enableColumnFreezing);\n const columnOrdering = useTableColumnOrdering(options.enableColumnOrdering);\n const fontSize = useTableFontSize(options.enableFontSize, settings.fontSize);\n const footer = useTableFooter(options.enableFooter);\n const printing = useTablePrinting(options.enablePrinting, safeId);\n const rowActive = useTableRowActive(options.enableRowActive, props.defaultRowActiveIndex);\n const rowActions = useTableRowActions<TType>(options.enableRowActions, props.rowActions, props.rowActionsLength);\n const rowClick = useTableRowClick<TType>(options.enableRowClick, props.onRowClick);\n const rowDrag = useTableRowDrag<TType>(options.enableRowDrag && !meta?.editing?.isEditing, props.onRowDrag);\n const rowDrop = useTableRowDrop<TType>(options.enableRowDrop, props.onRowDrop);\n const rowExpansion = useTableRowExpansion<TType>(\n options.enableRowExpansion,\n options.enableRowExpansionAll,\n props.rowExpansionRenderer\n );\n const rowGoto = useTableRowGoto(options.enableRowGoto, props.onRowGoto);\n const rowGroups = useTableRowGroups(props.rowActionsForGroup);\n const rowHeight = useTableRowHeight(options.enableRowHeight, settings.rowHeight);\n const rowSelection = useTableRowSelection(!!options.enableRowSelection);\n const search = useTableSearch(options.enableSearch, props.onChangeSearch, settings.excludeUnmatchedRecordsInSearch);\n const server = useTableServerLoading(\n length,\n data,\n props.loadPage,\n props.loadAll,\n props.pages,\n props.pageSize,\n props._experimentalDataLoader2\n );\n\n // TODO: memoise\n // convert jsx column components into valid table columns\n const { columns, ...defaultState } = mapTableChildrenToColumns<TType>(\n props,\n settings,\n options,\n internalColumns,\n localization\n );\n\n // configure initial table state\n const initialState = useReactTableInitialState<TType>(props, columns, settings, defaultState);\n\n // create a react-table instance\n const instance = useReactTable<TType>({\n data,\n columns,\n // configure initial table state\n initialState,\n getCoreRowModel: getCoreRowModel<TType>(),\n // configure react-table built-in features\n ...configureReactTableOptions<TType>(options, props, localization),\n // settings that can be toggled by the user, and therefore require our own state\n enableGlobalFilter: search.enableGlobalFilter,\n // custom context\n meta: {\n // spread features from specific implementations\n ...meta,\n columnFreezing,\n columnOrdering,\n fontSize,\n footer,\n length,\n onEvent: props.onEvent,\n printing,\n rowActions: rowActions as any, // no other way around ReturnType<typeof X> not supporting generics\n rowActive,\n rowClick: rowClick as any, // no other way around ReturnType<typeof X> not supporting generics\n rowDrag,\n rowDrop: rowDrop as any, // no other way around ReturnType<typeof X> not supporting generics\n rowExpansion: rowExpansion as any, // no other way around ReturnType<typeof X> not supporting generics\n rowIdentityAccessor: props.rowIdentityAccessor,\n rowGoto,\n rowGroups: rowGroups as any, // no other way around ReturnType<typeof X> not supporting generics\n rowHeight,\n rowSelection,\n search,\n server,\n } as ReactTableMeta<TType> & TMeta,\n });\n\n // state listeners - we have these so that we don't have to control state outside the table\n useTableDataListener(instance, length);\n useTableFilterListener(instance, props.onChangeFilter);\n useTableFontSizeListener(instance);\n useTableRowHeightListener(instance);\n useTableRowSelectionListener(instance, props.onRowSelect);\n useTableSearchListener(instance);\n useTableServerLoadingListener(instance, server.loadPage);\n useTableSettingsListener(instance, safeId, options.enableSaveSettings);\n useTableShortcutsListener(instance, props.shortcuts);\n useTableSortingListener(instance, props.onChangeSort);\n\n return {\n id: safeId,\n instance,\n meta: (instance.options.meta ?? {}) as ReactTableMeta<TType> & TMeta,\n state: instance.getState(),\n };\n}\n"],"names":["DEFAULT_EMPTY_ARRAY","useTableManager","props","meta","internalColumns","taco","useTaco","localization","useLocalization","safeId","id","replace","options","getTableFeaturePreset","settings","_ref","_taco$settings$getSet","getSetting","getSettingsId","defaultSettings","data","_props$data","length","_props$length","columnFreezing","useTableColumnFreezing","enableColumnFreezing","columnOrdering","useTableColumnOrdering","enableColumnOrdering","fontSize","useTableFontSize","enableFontSize","footer","useTableFooter","enableFooter","printing","useTablePrinting","enablePrinting","rowActive","useTableRowActive","enableRowActive","defaultRowActiveIndex","rowActions","useTableRowActions","enableRowActions","rowActionsLength","rowClick","useTableRowClick","enableRowClick","onRowClick","rowDrag","useTableRowDrag","enableRowDrag","_meta$editing","editing","isEditing","onRowDrag","rowDrop","useTableRowDrop","enableRowDrop","onRowDrop","rowExpansion","useTableRowExpansion","enableRowExpansion","enableRowExpansionAll","rowExpansionRenderer","rowGoto","useTableRowGoto","enableRowGoto","onRowGoto","rowGroups","useTableRowGroups","rowActionsForGroup","rowHeight","useTableRowHeight","enableRowHeight","rowSelection","useTableRowSelection","enableRowSelection","search","useTableSearch","enableSearch","onChangeSearch","excludeUnmatchedRecordsInSearch","server","useTableServerLoading","loadPage","loadAll","pages","pageSize","_experimentalDataLoader2","columns","defaultState","mapTableChildrenToColumns","initialState","useReactTableInitialState","instance","useReactTable","getCoreRowModel","configureReactTableOptions","enableGlobalFilter","onEvent","rowIdentityAccessor","useTableDataListener","useTableFilterListener","onChangeFilter","useTableFontSizeListener","useTableRowHeightListener","useTableRowSelectionListener","onRowSelect","useTableSearchListener","useTableServerLoadingListener","useTableSettingsListener","enableSaveSettings","useTableShortcutsListener","shortcuts","useTableSortingListener","onChangeSort","_instance$options$met","state","getState"],"mappings":";;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;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C;EACnCY,4BAA4B,CAACZ,QAAQ,EAAE/F,KAAK,CAAC4G,WAAW,CAAC;EACzDC,sBAAsB,CAACd,QAAQ,CAAC;EAChCe,6BAA6B,CAACf,QAAQ,EAAEZ,MAAM,CAACE,QAAQ,CAAC;EACxD0B,wBAAwB,CAAChB,QAAQ,EAAExF,MAAM,EAAEG,OAAO,CAACsG,kBAAkB,CAAC;EACtEC,yBAAyB,CAAClB,QAAQ,EAAE/F,KAAK,CAACkH,SAAS,CAAC;EACpDC,uBAAuB,CAACpB,QAAQ,EAAE/F,KAAK,CAACoH,YAAY,CAAC;EAErD,OAAO;IACH5G,EAAE,EAAED,MAAM;IACVwF,QAAQ;IACR9F,IAAI,GAAAoH,qBAAA,GAAGtB,QAAQ,CAACrF,OAAO,CAACT,IAAI,cAAAoH,qBAAA,cAAAA,qBAAA,GAAI,EAAoC;IACpEC,KAAK,EAAEvB,QAAQ,CAACwB,QAAQ;GAC3B;AACL;;;;"}
|
package/dist/esm/packages/taco/src/primitives/Table/useTableManager/useTableSettingsPreloader.js
ADDED
@@ -0,0 +1,44 @@
|
|
1
|
+
import React__default from 'react';
|
2
|
+
import { getSettingsId } from './util/settings.js';
|
3
|
+
import { useTaco } from '../../../hooks/useTaco.js';
|
4
|
+
|
5
|
+
function getLegacySetting(currentKey) {
|
6
|
+
try {
|
7
|
+
const localStorageValue = localStorage.getItem(currentKey);
|
8
|
+
if (localStorageValue) {
|
9
|
+
const value = JSON.parse(localStorageValue || 'null');
|
10
|
+
if (value !== null) {
|
11
|
+
localStorage.removeItem(currentKey);
|
12
|
+
return value;
|
13
|
+
}
|
14
|
+
}
|
15
|
+
} catch {
|
16
|
+
// If user is in private mode or has storage restriction
|
17
|
+
// localStorage can throw. JSON.parse can throw, too.
|
18
|
+
}
|
19
|
+
return undefined;
|
20
|
+
}
|
21
|
+
function useTableSettingsPreloader(tableId) {
|
22
|
+
const taco = useTaco();
|
23
|
+
const [loading, setLoading] = React__default.useState(true);
|
24
|
+
React__default.useLayoutEffect(() => {
|
25
|
+
const key = getSettingsId(tableId);
|
26
|
+
// migrate legacy settings if they exist, can be removed in the future
|
27
|
+
const legacySettings = getLegacySetting(`taco.${taco.userId}.table.${tableId}.settings`);
|
28
|
+
if (legacySettings) {
|
29
|
+
const legacyPrintSettings = getLegacySetting(`taco.${taco.userId}.table.${tableId}.print.settings`);
|
30
|
+
taco.settings.saveSetting(getSettingsId(tableId), {
|
31
|
+
...legacySettings,
|
32
|
+
print: legacyPrintSettings !== null && legacyPrintSettings !== void 0 ? legacyPrintSettings : {}
|
33
|
+
}).finally(() => setLoading(false));
|
34
|
+
} else {
|
35
|
+
taco.settings.loadSetting(key).finally(() => setLoading(false));
|
36
|
+
}
|
37
|
+
}, []);
|
38
|
+
return {
|
39
|
+
loading
|
40
|
+
};
|
41
|
+
}
|
42
|
+
|
43
|
+
export { useTableSettingsPreloader };
|
44
|
+
//# sourceMappingURL=useTableSettingsPreloader.js.map
|
package/dist/esm/packages/taco/src/primitives/Table/useTableManager/useTableSettingsPreloader.js.map
ADDED
@@ -0,0 +1 @@
|
|
1
|
+
{"version":3,"file":"useTableSettingsPreloader.js","sources":["../../../../../../../../src/primitives/Table/useTableManager/useTableSettingsPreloader.ts"],"sourcesContent":["import React from 'react';\nimport { useTaco } from '../../../hooks/useTaco';\nimport { TablePrintSettings, TableSettings } from '../types';\nimport { getSettingsId } from './util/settings';\n\nfunction getLegacySetting<TType = unknown>(currentKey: string): TType | undefined {\n try {\n const localStorageValue = localStorage.getItem(currentKey);\n\n if (localStorageValue) {\n const value = JSON.parse(localStorageValue || 'null');\n\n if (value !== null) {\n localStorage.removeItem(currentKey);\n return value;\n }\n }\n } catch {\n // If user is in private mode or has storage restriction\n // localStorage can throw. JSON.parse can throw, too.\n }\n\n return undefined;\n}\n\nexport function useTableSettingsPreloader(tableId: string) {\n const taco = useTaco();\n const [loading, setLoading] = React.useState(true);\n\n React.useLayoutEffect(() => {\n const key = getSettingsId(tableId);\n\n // migrate legacy settings if they exist, can be removed in the future\n const legacySettings = getLegacySetting<TableSettings>(`taco.${taco.userId}.table.${tableId}.settings`);\n\n if (legacySettings) {\n const legacyPrintSettings = getLegacySetting<TablePrintSettings>(\n `taco.${taco.userId}.table.${tableId}.print.settings`\n );\n\n taco.settings\n .saveSetting(getSettingsId(tableId), {\n ...legacySettings,\n print: legacyPrintSettings ?? {},\n })\n .finally(() => setLoading(false));\n } else {\n taco.settings.loadSetting<TableSettings>(key).finally(() => setLoading(false));\n }\n }, []);\n\n return { loading };\n}\n"],"names":["getLegacySetting","currentKey","localStorageValue","localStorage","getItem","value","JSON","parse","removeItem","undefined","useTableSettingsPreloader","tableId","taco","useTaco","loading","setLoading","React","useState","useLayoutEffect","key","getSettingsId","legacySettings","userId","legacyPrintSettings","settings","saveSetting","print","finally","loadSetting"],"mappings":";;;;AAKA,SAASA,gBAAgBA,CAAkBC,UAAkB;EACzD,IAAI;IACA,MAAMC,iBAAiB,GAAGC,YAAY,CAACC,OAAO,CAACH,UAAU,CAAC;IAE1D,IAAIC,iBAAiB,EAAE;MACnB,MAAMG,KAAK,GAAGC,IAAI,CAACC,KAAK,CAACL,iBAAiB,IAAI,MAAM,CAAC;MAErD,IAAIG,KAAK,KAAK,IAAI,EAAE;QAChBF,YAAY,CAACK,UAAU,CAACP,UAAU,CAAC;QACnC,OAAOI,KAAK;;;GAGvB,CAAC,MAAM;;;;EAKR,OAAOI,SAAS;AACpB;SAEgBC,yBAAyBA,CAACC,OAAe;EACrD,MAAMC,IAAI,GAAGC,OAAO,EAAE;EACtB,MAAM,CAACC,OAAO,EAAEC,UAAU,CAAC,GAAGC,cAAK,CAACC,QAAQ,CAAC,IAAI,CAAC;EAElDD,cAAK,CAACE,eAAe,CAAC;IAClB,MAAMC,GAAG,GAAGC,aAAa,CAACT,OAAO,CAAC;;IAGlC,MAAMU,cAAc,GAAGrB,gBAAgB,CAAgB,QAAQY,IAAI,CAACU,MAAM,UAAUX,OAAO,WAAW,CAAC;IAEvG,IAAIU,cAAc,EAAE;MAChB,MAAME,mBAAmB,GAAGvB,gBAAgB,CACxC,QAAQY,IAAI,CAACU,MAAM,UAAUX,OAAO,iBAAiB,CACxD;MAEDC,IAAI,CAACY,QAAQ,CACRC,WAAW,CAACL,aAAa,CAACT,OAAO,CAAC,EAAE;QACjC,GAAGU,cAAc;QACjBK,KAAK,EAAEH,mBAAmB,aAAnBA,mBAAmB,cAAnBA,mBAAmB,GAAI;OACjC,CAAC,CACDI,OAAO,CAAC,MAAMZ,UAAU,CAAC,KAAK,CAAC,CAAC;KACxC,MAAM;MACHH,IAAI,CAACY,QAAQ,CAACI,WAAW,CAAgBT,GAAG,CAAC,CAACQ,OAAO,CAAC,MAAMZ,UAAU,CAAC,KAAK,CAAC,CAAC;;GAErF,EAAE,EAAE,CAAC;EAEN,OAAO;IAAED;GAAS;AACtB;;;;"}
|
@@ -1,5 +1,6 @@
|
|
1
1
|
import { isInternalColumn } from './columns.js';
|
2
2
|
|
3
|
+
const getSettingsId = tableId => `table.${tableId.replace('.', '_')}`;
|
3
4
|
function getSettings(table) {
|
4
5
|
const meta = table.options.meta;
|
5
6
|
const state = table.getState();
|
@@ -13,6 +14,7 @@ function getSettings(table) {
|
|
13
14
|
excludeUnmatchedRecordsInSearch: table.options.enableGlobalFilter,
|
14
15
|
fontSize: meta.fontSize.isEnabled ? meta.fontSize.size : undefined,
|
15
16
|
//grouping: table.options.enableGrouping ? state.grouping : undefined,
|
17
|
+
print: meta.printing.settings,
|
16
18
|
rowHeight: meta.rowHeight.isEnabled ? meta.rowHeight.height : undefined,
|
17
19
|
//searchQuery: table.options.enableGlobalFilter ? state.globalFilter : undefined,
|
18
20
|
sorting: state.sorting
|
@@ -30,5 +32,5 @@ function ignoreInternalColumns(data) {
|
|
30
32
|
}, {});
|
31
33
|
}
|
32
34
|
|
33
|
-
export { getSettings, ignoreInternalColumns };
|
35
|
+
export { getSettings, getSettingsId, ignoreInternalColumns };
|
34
36
|
//# sourceMappingURL=settings.js.map
|
@@ -1 +1 @@
|
|
1
|
-
{"version":3,"file":"settings.js","sources":["../../../../../../../../../src/primitives/Table/useTableManager/util/settings.ts"],"sourcesContent":["import { Table as ReactTable, TableMeta as ReactTableMeta } from '@tanstack/react-table';\nimport { isInternalColumn } from './columns';\n\nexport function getSettings<TType = unknown>(table: ReactTable<TType>) {\n const meta = table.options.meta as ReactTableMeta<TType>;\n const state = table.getState();\n\n return {\n // commented out properties are here to highlight things we explicitly don't want them saved\n //columnFilters: table.options.enableColumnFilters ? state.columnFilters : undefined,\n columnOrder: meta.columnOrdering.isEnabled ? state.columnOrder : undefined,\n columnPinning: state.columnPinning,\n columnSizing: ignoreInternalColumns(state.columnSizing),\n columnVisibility: table.options.enableHiding ? state.columnVisibility : undefined,\n excludeUnmatchedRecordsInSearch: table.options.enableGlobalFilter,\n fontSize: meta.fontSize.isEnabled ? meta.fontSize.size : undefined,\n //grouping: table.options.enableGrouping ? state.grouping : undefined,\n rowHeight: meta.rowHeight.isEnabled ? meta.rowHeight.height : undefined,\n //searchQuery: table.options.enableGlobalFilter ? state.globalFilter : undefined,\n sorting: state.sorting,\n };\n}\n\nexport function ignoreInternalColumns(data: object) {\n return Object.keys(data).reduce((accum, key) => {\n if (isInternalColumn(key)) {\n return accum;\n }\n\n return {\n ...accum,\n [key]: data[key],\n };\n }, {});\n}\n"],"names":["getSettings","table","meta","options","state","getState","columnOrder","columnOrdering","isEnabled","undefined","columnPinning","columnSizing","ignoreInternalColumns","columnVisibility","enableHiding","excludeUnmatchedRecordsInSearch","enableGlobalFilter","fontSize","size","rowHeight","height","sorting","data","Object","keys","reduce","accum","key","isInternalColumn"],"mappings":";;
|
1
|
+
{"version":3,"file":"settings.js","sources":["../../../../../../../../../src/primitives/Table/useTableManager/util/settings.ts"],"sourcesContent":["import { Table as ReactTable, TableMeta as ReactTableMeta } from '@tanstack/react-table';\nimport { isInternalColumn } from './columns';\n\nexport const getSettingsId = (tableId: string) => `table.${tableId.replace('.', '_')}`;\n\nexport function getSettings<TType = unknown>(table: ReactTable<TType>) {\n const meta = table.options.meta as ReactTableMeta<TType>;\n const state = table.getState();\n\n return {\n // commented out properties are here to highlight things we explicitly don't want them saved\n //columnFilters: table.options.enableColumnFilters ? state.columnFilters : undefined,\n columnOrder: meta.columnOrdering.isEnabled ? state.columnOrder : undefined,\n columnPinning: state.columnPinning,\n columnSizing: ignoreInternalColumns(state.columnSizing),\n columnVisibility: table.options.enableHiding ? state.columnVisibility : undefined,\n excludeUnmatchedRecordsInSearch: table.options.enableGlobalFilter,\n fontSize: meta.fontSize.isEnabled ? meta.fontSize.size : undefined,\n //grouping: table.options.enableGrouping ? state.grouping : undefined,\n print: meta.printing.settings,\n rowHeight: meta.rowHeight.isEnabled ? meta.rowHeight.height : undefined,\n //searchQuery: table.options.enableGlobalFilter ? state.globalFilter : undefined,\n sorting: state.sorting,\n };\n}\n\nexport function ignoreInternalColumns(data: object) {\n return Object.keys(data).reduce((accum, key) => {\n if (isInternalColumn(key)) {\n return accum;\n }\n\n return {\n ...accum,\n [key]: data[key],\n };\n }, {});\n}\n"],"names":["getSettingsId","tableId","replace","getSettings","table","meta","options","state","getState","columnOrder","columnOrdering","isEnabled","undefined","columnPinning","columnSizing","ignoreInternalColumns","columnVisibility","enableHiding","excludeUnmatchedRecordsInSearch","enableGlobalFilter","fontSize","size","print","printing","settings","rowHeight","height","sorting","data","Object","keys","reduce","accum","key","isInternalColumn"],"mappings":";;MAGaA,aAAa,GAAIC,OAAe,IAAK,SAASA,OAAO,CAACC,OAAO,CAAC,GAAG,EAAE,GAAG,CAAC;SAEpEC,WAAWA,CAAkBC,KAAwB;EACjE,MAAMC,IAAI,GAAGD,KAAK,CAACE,OAAO,CAACD,IAA6B;EACxD,MAAME,KAAK,GAAGH,KAAK,CAACI,QAAQ,EAAE;EAE9B,OAAO;;;IAGHC,WAAW,EAAEJ,IAAI,CAACK,cAAc,CAACC,SAAS,GAAGJ,KAAK,CAACE,WAAW,GAAGG,SAAS;IAC1EC,aAAa,EAAEN,KAAK,CAACM,aAAa;IAClCC,YAAY,EAAEC,qBAAqB,CAACR,KAAK,CAACO,YAAY,CAAC;IACvDE,gBAAgB,EAAEZ,KAAK,CAACE,OAAO,CAACW,YAAY,GAAGV,KAAK,CAACS,gBAAgB,GAAGJ,SAAS;IACjFM,+BAA+B,EAAEd,KAAK,CAACE,OAAO,CAACa,kBAAkB;IACjEC,QAAQ,EAAEf,IAAI,CAACe,QAAQ,CAACT,SAAS,GAAGN,IAAI,CAACe,QAAQ,CAACC,IAAI,GAAGT,SAAS;;IAElEU,KAAK,EAAEjB,IAAI,CAACkB,QAAQ,CAACC,QAAQ;IAC7BC,SAAS,EAAEpB,IAAI,CAACoB,SAAS,CAACd,SAAS,GAAGN,IAAI,CAACoB,SAAS,CAACC,MAAM,GAAGd,SAAS;;IAEvEe,OAAO,EAAEpB,KAAK,CAACoB;GAClB;AACL;SAEgBZ,qBAAqBA,CAACa,IAAY;EAC9C,OAAOC,MAAM,CAACC,IAAI,CAACF,IAAI,CAAC,CAACG,MAAM,CAAC,CAACC,KAAK,EAAEC,GAAG;IACvC,IAAIC,gBAAgB,CAACD,GAAG,CAAC,EAAE;MACvB,OAAOD,KAAK;;IAGhB,OAAO;MACH,GAAGA,KAAK;MACR,CAACC,GAAG,GAAGL,IAAI,CAACK,GAAG;KAClB;GACJ,EAAE,EAAE,CAAC;AACV;;;;"}
|
@@ -0,0 +1 @@
|
|
1
|
+
export declare function useTaco(): import("../components/Provider/TacoContext").Taco;
|
@@ -1,7 +1,7 @@
|
|
1
1
|
/// <reference types="react" />
|
2
2
|
import { Table as ReactTable, TableMeta as ReactTableMeta, TableState as ReactTableState } from '@tanstack/react-table';
|
3
3
|
import { ScrollToOptions as ReactVirtualScrollToOptions } from '@tanstack/react-virtual';
|
4
|
-
import { TableCustomSettingsRenderer, TableEmptyStateRenderer, TableProps } from '../types';
|
4
|
+
import { TableCustomSettingsRenderer, TableEmptyStateRenderer, TableProps, TableToolbarRenderer } from '../types';
|
5
5
|
import { TableRef } from '../types';
|
6
6
|
import { useTableRenderers, useTableRenderOptions } from './types';
|
7
7
|
export declare type useTableReturnValue<TType = unknown> = {
|
@@ -11,9 +11,9 @@ export declare type useTableReturnValue<TType = unknown> = {
|
|
11
11
|
props: {
|
12
12
|
customSettings: TableCustomSettingsRenderer | undefined;
|
13
13
|
emptyState: TableEmptyStateRenderer | undefined;
|
14
|
-
toolbarLeft:
|
15
|
-
toolbarPanel:
|
16
|
-
toolbarRight:
|
14
|
+
toolbarLeft: TableToolbarRenderer | undefined;
|
15
|
+
toolbarPanel: TableToolbarRenderer | undefined;
|
16
|
+
toolbarRight: TableToolbarRenderer | undefined;
|
17
17
|
};
|
18
18
|
ref: React.RefObject<TableRef>;
|
19
19
|
renderer: {
|
@@ -102,6 +102,12 @@ export declare type TableEmptyStateRenderer = (props: {
|
|
102
102
|
}) => JSX.Element | null;
|
103
103
|
export declare type TableEvent = 'editing-mode';
|
104
104
|
export declare type TableEventHandler = (event: TableEvent, data?: object) => void;
|
105
|
+
export declare type TablePrintSettings = {
|
106
|
+
allRows: boolean;
|
107
|
+
orientation: 'portrait' | 'landscape';
|
108
|
+
size: 'A3' | 'A4' | 'A5' | 'letter' | 'legal';
|
109
|
+
splitGroups: boolean;
|
110
|
+
};
|
105
111
|
export declare type TableSettings = {
|
106
112
|
columnFilters?: ReactTableColumnFilterState;
|
107
113
|
columnOrder?: ReactTableColumnOrderState;
|
@@ -110,6 +116,7 @@ export declare type TableSettings = {
|
|
110
116
|
columnVisibility?: ReactTableColumnVisibilityState;
|
111
117
|
excludeUnmatchedRecordsInSearch?: boolean;
|
112
118
|
fontSize?: TableFontSize;
|
119
|
+
print?: TablePrintSettings;
|
113
120
|
rowHeight?: TableRowHeight;
|
114
121
|
searchQuery?: string;
|
115
122
|
sorting?: ReactTableSortingState;
|
@@ -150,6 +157,7 @@ export declare type TableFeatureProps<TType = unknown> = {
|
|
150
157
|
enableSaveSettings?: boolean | Partial<TableEnableSettingsOptions>;
|
151
158
|
};
|
152
159
|
export declare type TableChild = JSX.Element | boolean | null | undefined;
|
160
|
+
export declare type TableToolbarRenderer = JSX.Element | ((settings: TableSettings) => JSX.Element);
|
153
161
|
export declare type TableCommonProps<TType = unknown> = TableFeatureProps<TType> & {
|
154
162
|
children: TableChild | TableChild[];
|
155
163
|
data: TType[];
|
@@ -167,9 +175,9 @@ export declare type TableCommonProps<TType = unknown> = TableFeatureProps<TType>
|
|
167
175
|
rowExpansionRenderer?: TableRowExpansionRenderer<TType>;
|
168
176
|
rowIdentityAccessor?: keyof TType;
|
169
177
|
shortcuts?: TableShortcuts<TType>;
|
170
|
-
toolbarLeft?:
|
171
|
-
toolbarRight?:
|
172
|
-
toolbarPanel?:
|
178
|
+
toolbarLeft?: TableToolbarRenderer;
|
179
|
+
toolbarRight?: TableToolbarRenderer;
|
180
|
+
toolbarPanel?: TableToolbarRenderer;
|
173
181
|
onEvent?: TableEventHandler;
|
174
182
|
onRowClick?: TableRowClickHandler<TType>;
|
175
183
|
onRowDrag?: TableRowDragHandler<TType>;
|
@@ -178,7 +186,6 @@ export declare type TableCommonProps<TType = unknown> = TableFeatureProps<TType>
|
|
178
186
|
onRowSelect?: TableRowSelectHandler<TType>;
|
179
187
|
onChangeFilter?: TableFilterHandler;
|
180
188
|
onChangeSearch?: TableSearchHandler;
|
181
|
-
onChangeSettings?: TableSettingsHandler;
|
182
189
|
onChangeSort?: TableSortHandler;
|
183
190
|
};
|
184
191
|
export interface TableClientProps<TType = unknown> extends TableCommonProps<TType> {
|
@@ -1,15 +1,9 @@
|
|
1
1
|
import React from 'react';
|
2
|
-
|
3
|
-
allRows: boolean;
|
4
|
-
orientation: 'portrait' | 'landscape';
|
5
|
-
size: 'A3' | 'A4' | 'A5' | 'letter' | 'legal';
|
6
|
-
splitGroups: boolean;
|
7
|
-
};
|
2
|
+
import { TablePrintSettings } from '../../types';
|
8
3
|
export declare function useTablePrinting(isEnabled: boolean | undefined, tableId: string): {
|
9
4
|
isEnabled: boolean;
|
10
5
|
isPrinting: boolean;
|
11
6
|
setIsPrinting: React.Dispatch<React.SetStateAction<boolean>>;
|
12
7
|
settings: TablePrintSettings;
|
13
|
-
setSetting: (
|
8
|
+
setSetting: (path: keyof TablePrintSettings, value: any) => void;
|
14
9
|
};
|
15
|
-
export {};
|
@@ -1,3 +1,3 @@
|
|
1
1
|
import { Table as ReactTable } from '@tanstack/react-table';
|
2
|
-
import {
|
3
|
-
export declare function useTableSettingsListener<TType = unknown>(table: ReactTable<TType>,
|
2
|
+
import { TableEnableSettingsOptions } from '../../types';
|
3
|
+
export declare function useTableSettingsListener<TType = unknown>(table: ReactTable<TType>, tableId: string, isEnabled?: boolean | Partial<TableEnableSettingsOptions>): void;
|
@@ -1,4 +1,5 @@
|
|
1
1
|
import { Table as ReactTable } from '@tanstack/react-table';
|
2
|
+
export declare const getSettingsId: (tableId: string) => string;
|
2
3
|
export declare function getSettings<TType = unknown>(table: ReactTable<TType>): {
|
3
4
|
columnOrder: import("@tanstack/react-table").ColumnOrderState | undefined;
|
4
5
|
columnPinning: import("@tanstack/react-table").ColumnPinningState;
|
@@ -6,6 +7,7 @@ export declare function getSettings<TType = unknown>(table: ReactTable<TType>):
|
|
6
7
|
columnVisibility: Record<string, boolean> | undefined;
|
7
8
|
excludeUnmatchedRecordsInSearch: boolean | undefined;
|
8
9
|
fontSize: "small" | "medium" | "large" | undefined;
|
10
|
+
print: import("../../types").TablePrintSettings;
|
9
11
|
rowHeight: "medium" | "short" | "tall" | "extra-tall" | undefined;
|
10
12
|
sorting: import("@tanstack/react-table").SortingState;
|
11
13
|
};
|