@economic/taco 2.22.2 → 2.24.0
Sign up to get free protection for your applications and to get access to all the features.
- package/dist/components/Card/Card.d.ts +1 -0
- package/dist/components/Checkbox/Checkbox.d.ts +2 -0
- package/dist/components/OverflowGroup/OverflowGroup.d.ts +1 -1
- package/dist/components/Provider/Localization.d.ts +4 -0
- package/dist/components/Report/Report.d.ts +2 -0
- package/dist/components/Report/components/Body/Body.d.ts +0 -1
- package/dist/components/Report/components/Body/EmptyStateBody.d.ts +7 -0
- package/dist/components/Report/components/Cell/util.d.ts +1 -1
- package/dist/components/Report/components/Footer/Summary.d.ts +0 -1
- package/dist/components/Report/components/Toolbar/components/Filters/components/Filter.d.ts +2 -2
- package/dist/components/Report/components/Toolbar/components/Filters/components/FilterColumn.d.ts +5 -2
- package/dist/components/Report/types.d.ts +2 -0
- package/dist/components/Report/useReport.d.ts +1 -1
- package/dist/components/Select2/Select2.d.ts +4 -0
- package/dist/components/Select2/components/Trigger.d.ts +1 -0
- package/dist/components/Select2/hooks/useChildren.d.ts +1 -0
- package/dist/components/Table3/components/toolbar/Filter/filters/components/Filter.d.ts +2 -2
- package/dist/components/Table3/components/toolbar/Filter/filters/components/FilterColumn.d.ts +5 -2
- package/dist/components/Truncate/Truncate.d.ts +2 -2
- package/dist/esm/index.css +128 -121
- package/dist/esm/packages/taco/src/components/Button/util.js +8 -8
- package/dist/esm/packages/taco/src/components/Button/util.js.map +1 -1
- package/dist/esm/packages/taco/src/components/Card/Card.js +8 -4
- package/dist/esm/packages/taco/src/components/Card/Card.js.map +1 -1
- package/dist/esm/packages/taco/src/components/Checkbox/Checkbox.js +11 -2
- package/dist/esm/packages/taco/src/components/Checkbox/Checkbox.js.map +1 -1
- package/dist/esm/packages/taco/src/components/Field/Field.js +4 -15
- package/dist/esm/packages/taco/src/components/Field/Field.js.map +1 -1
- package/dist/esm/packages/taco/src/components/Header/components/PrimaryNavigation.js +2 -2
- package/dist/esm/packages/taco/src/components/Header/components/PrimaryNavigation.js.map +1 -1
- package/dist/esm/packages/taco/src/components/Listbox/ScrollableList.js +1 -1
- package/dist/esm/packages/taco/src/components/OverflowGroup/OverflowGroup.js +13 -6
- package/dist/esm/packages/taco/src/components/OverflowGroup/OverflowGroup.js.map +1 -1
- package/dist/esm/packages/taco/src/components/Provider/Localization.js +5 -1
- package/dist/esm/packages/taco/src/components/Provider/Localization.js.map +1 -1
- package/dist/esm/packages/taco/src/components/Report/Report.js +11 -13
- package/dist/esm/packages/taco/src/components/Report/Report.js.map +1 -1
- package/dist/esm/packages/taco/src/components/Report/components/Body/Body.js +1 -2
- package/dist/esm/packages/taco/src/components/Report/components/Body/Body.js.map +1 -1
- package/dist/esm/packages/taco/src/components/Report/components/Body/EmptyStateBody.js +18 -0
- package/dist/esm/packages/taco/src/components/Report/components/Body/EmptyStateBody.js.map +1 -0
- package/dist/esm/packages/taco/src/components/Report/components/Cell/util.js +6 -2
- package/dist/esm/packages/taco/src/components/Report/components/Cell/util.js.map +1 -1
- package/dist/esm/packages/taco/src/components/Report/components/Footer/Footer.js +14 -2
- package/dist/esm/packages/taco/src/components/Report/components/Footer/Footer.js.map +1 -1
- package/dist/esm/packages/taco/src/components/Report/components/Footer/Summary.js +2 -2
- package/dist/esm/packages/taco/src/components/Report/components/Footer/Summary.js.map +1 -1
- package/dist/esm/packages/taco/src/components/Report/components/Internal/Selection.js +47 -11
- package/dist/esm/packages/taco/src/components/Report/components/Internal/Selection.js.map +1 -1
- package/dist/esm/packages/taco/src/components/Report/components/Toolbar/components/Filters/ManageFiltersPopover.js +28 -43
- package/dist/esm/packages/taco/src/components/Report/components/Toolbar/components/Filters/ManageFiltersPopover.js.map +1 -1
- package/dist/esm/packages/taco/src/components/Report/components/Toolbar/components/Filters/components/Filter.js +14 -7
- package/dist/esm/packages/taco/src/components/Report/components/Toolbar/components/Filters/components/Filter.js.map +1 -1
- package/dist/esm/packages/taco/src/components/Report/components/Toolbar/components/Filters/components/FilterColumn.js +4 -3
- package/dist/esm/packages/taco/src/components/Report/components/Toolbar/components/Filters/components/FilterColumn.js.map +1 -1
- package/dist/esm/packages/taco/src/components/Report/components/Toolbar/components/Print/Print.js +10 -8
- package/dist/esm/packages/taco/src/components/Report/components/Toolbar/components/Print/Print.js.map +1 -1
- package/dist/esm/packages/taco/src/components/Report/listeners/useTableRowActiveListener.js +2 -2
- package/dist/esm/packages/taco/src/components/Report/listeners/useTableRowActiveListener.js.map +1 -1
- package/dist/esm/packages/taco/src/components/Report/styles/useCssGridStylesheet.js +10 -6
- package/dist/esm/packages/taco/src/components/Report/styles/useCssGridStylesheet.js.map +1 -1
- package/dist/esm/packages/taco/src/components/Report/util/useTableGlobalShortcuts.js +3 -10
- package/dist/esm/packages/taco/src/components/Report/util/useTableGlobalShortcuts.js.map +1 -1
- package/dist/esm/packages/taco/src/components/SearchInput2/SearchInput2.js +2 -1
- package/dist/esm/packages/taco/src/components/SearchInput2/SearchInput2.js.map +1 -1
- package/dist/esm/packages/taco/src/components/Select2/Select2.js +44 -4
- package/dist/esm/packages/taco/src/components/Select2/Select2.js.map +1 -1
- package/dist/esm/packages/taco/src/components/Select2/components/Trigger.js +9 -4
- package/dist/esm/packages/taco/src/components/Select2/components/Trigger.js.map +1 -1
- package/dist/esm/packages/taco/src/components/Select2/hooks/useChildren.js +1 -1
- package/dist/esm/packages/taco/src/components/Select2/hooks/useChildren.js.map +1 -1
- package/dist/esm/packages/taco/src/components/Table3/Table3.js +4 -6
- package/dist/esm/packages/taco/src/components/Table3/Table3.js.map +1 -1
- package/dist/esm/packages/taco/src/components/Table3/components/columns/cell/EditingCell.js +2 -2
- package/dist/esm/packages/taco/src/components/Table3/components/columns/cell/EditingCell.js.map +1 -1
- package/dist/esm/packages/taco/src/components/Table3/components/columns/internal/Selection.js +66 -14
- package/dist/esm/packages/taco/src/components/Table3/components/columns/internal/Selection.js.map +1 -1
- package/dist/esm/packages/taco/src/components/Table3/components/toolbar/Filter/filters/Filters.js +27 -44
- package/dist/esm/packages/taco/src/components/Table3/components/toolbar/Filter/filters/Filters.js.map +1 -1
- package/dist/esm/packages/taco/src/components/Table3/components/toolbar/Filter/filters/components/Filter.js +14 -7
- package/dist/esm/packages/taco/src/components/Table3/components/toolbar/Filter/filters/components/Filter.js.map +1 -1
- package/dist/esm/packages/taco/src/components/Table3/components/toolbar/Filter/filters/components/FilterColumn.js +4 -3
- package/dist/esm/packages/taco/src/components/Table3/components/toolbar/Filter/filters/components/FilterColumn.js.map +1 -1
- package/dist/esm/packages/taco/src/components/Table3/components/toolbar/Filter/filters/components/FilterComparator.js +1 -1
- package/dist/esm/packages/taco/src/components/Table3/components/toolbar/Filter/filters/components/FilterComparator.js.map +1 -1
- package/dist/esm/packages/taco/src/components/Table3/components/toolbar/PrintButton/PrintButton.js +2 -0
- package/dist/esm/packages/taco/src/components/Table3/components/toolbar/PrintButton/PrintButton.js.map +1 -1
- package/dist/esm/packages/taco/src/components/Table3/components/toolbar/PrintButton/PrintIFrame.js +2 -1
- package/dist/esm/packages/taco/src/components/Table3/components/toolbar/PrintButton/PrintIFrame.js.map +1 -1
- package/dist/esm/packages/taco/src/components/Table3/hooks/features/useSettings.js +1 -1
- package/dist/esm/packages/taco/src/components/Table3/hooks/listeners/useSettingsStateListener.js +3 -1
- package/dist/esm/packages/taco/src/components/Table3/hooks/listeners/useSettingsStateListener.js.map +1 -1
- package/dist/esm/packages/taco/src/components/Table3/hooks/useTable.js +10 -3
- package/dist/esm/packages/taco/src/components/Table3/hooks/useTable.js.map +1 -1
- package/dist/esm/packages/taco/src/components/Toast/Toaster.js +4 -3
- package/dist/esm/packages/taco/src/components/Toast/Toaster.js.map +1 -1
- package/dist/esm/packages/taco/src/components/Truncate/Truncate.js +34 -0
- package/dist/esm/packages/taco/src/components/Truncate/Truncate.js.map +1 -0
- package/dist/esm/packages/taco/src/hooks/useLocalStorage.js.map +1 -1
- package/dist/esm/packages/taco/src/index.js +2 -1
- package/dist/esm/packages/taco/src/index.js.map +1 -1
- package/dist/esm/packages/taco/src/primitives/Button.js +1 -0
- package/dist/esm/packages/taco/src/primitives/Button.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/useTable/features/useTablePrinting.js +24 -4
- package/dist/esm/packages/taco/src/primitives/Table/useTable/features/useTablePrinting.js.map +1 -1
- package/dist/esm/packages/taco/src/primitives/Table/useTable/features/useTableSettings.js +48 -7
- package/dist/esm/packages/taco/src/primitives/Table/useTable/features/useTableSettings.js.map +1 -1
- package/dist/esm/packages/taco/src/primitives/Table/useTable/listeners/useTableSettingsListener.js +1 -1
- package/dist/esm/packages/taco/src/primitives/Table/useTable/listeners/useTableSettingsListener.js.map +1 -1
- package/dist/esm/packages/taco/src/primitives/Table/useTable/useTable.js +11 -6
- package/dist/esm/packages/taco/src/primitives/Table/useTable/useTable.js.map +1 -1
- package/dist/esm/packages/taco/src/primitives/Table/useTable/util/columns.js +33 -7
- package/dist/esm/packages/taco/src/primitives/Table/useTable/util/columns.js.map +1 -1
- package/dist/esm/packages/taco/src/primitives/Table/useTable/util/presets.js +5 -5
- package/dist/esm/packages/taco/src/primitives/Table/useTable/util/presets.js.map +1 -1
- package/dist/esm/packages/taco/src/primitives/Table/useTable/util/search.js +14 -1
- package/dist/esm/packages/taco/src/primitives/Table/useTable/util/search.js.map +1 -1
- package/dist/esm/packages/taco/src/primitives/Table/useTable/util/settings.js +0 -1
- package/dist/esm/packages/taco/src/primitives/Table/useTable/util/settings.js.map +1 -1
- package/dist/esm/packages/taco/src/primitives/Table/useTableDataLoader.js +127 -3
- package/dist/esm/packages/taco/src/primitives/Table/useTableDataLoader.js.map +1 -1
- package/dist/esm/packages/taco/src/utils/dom.js +12 -3
- package/dist/esm/packages/taco/src/utils/dom.js.map +1 -1
- package/dist/esm/packages/taco/src/utils/hooks/useTruncated.js +4 -4
- package/dist/esm/packages/taco/src/utils/hooks/useTruncated.js.map +1 -1
- package/dist/esm/packages/taco/src/utils/keyboard.js +2 -2
- package/dist/esm/packages/taco/src/utils/keyboard.js.map +1 -1
- package/dist/hooks/useLocalStorage.d.ts +2 -1
- package/dist/index.css +128 -121
- package/dist/index.d.ts +1 -0
- package/dist/primitives/Table/types.d.ts +12 -2
- package/dist/primitives/Table/useTable/features/useTablePrinting.d.ts +10 -3
- package/dist/primitives/Table/useTable/features/useTableSettings.d.ts +2 -2
- package/dist/primitives/Table/useTable/useTable.d.ts +2 -1
- package/dist/primitives/Table/useTable/util/settings.d.ts +0 -1
- package/dist/taco.cjs.development.js +814 -455
- 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/dist/utils/dom.d.ts +3 -1
- package/dist/utils/hooks/useTruncated.d.ts +1 -1
- package/package.json +2 -2
- package/types.json +9339 -9261
- package/dist/components/Report/components/Toolbar/components/Filters/components/Placeholder.d.ts +0 -12
- package/dist/components/Table3/components/toolbar/Filter/filters/components/Placeholder.d.ts +0 -12
- package/dist/esm/packages/taco/src/components/Report/components/Toolbar/components/Filters/components/Placeholder.js +0 -41
- package/dist/esm/packages/taco/src/components/Report/components/Toolbar/components/Filters/components/Placeholder.js.map +0 -1
- package/dist/esm/packages/taco/src/components/Table3/components/toolbar/Filter/filters/components/Placeholder.js +0 -41
- package/dist/esm/packages/taco/src/components/Table3/components/toolbar/Filter/filters/components/Placeholder.js.map +0 -1
@@ -36,7 +36,7 @@ import { useValidation } from './features/useValidation.js';
|
|
36
36
|
import { usePauseShortcuts } from './features/usePauseShortcuts.js';
|
37
37
|
|
38
38
|
function useTable(props, ref) {
|
39
|
-
var _settings$columnFreez, _props$length;
|
39
|
+
var _settings$columnFreez, _props$data, _ref, _props$length, _props$data2;
|
40
40
|
// load any persisted table settings and merge them with any defaults
|
41
41
|
const [settings, setSettings] = useSettings(props.id, props.defaultSettings, props.onChangeSettings);
|
42
42
|
// configure table3 options
|
@@ -60,6 +60,12 @@ function useTable(props, ref) {
|
|
60
60
|
// haven't migrated load all/server loading yet
|
61
61
|
const search = useSearch(options.enableSearch, settings.excludeUnmatchedRecordsInSearch);
|
62
62
|
const shortcutsState = usePauseShortcuts();
|
63
|
+
React__default.useEffect(() => {
|
64
|
+
// Needed for DataDog
|
65
|
+
if (!Array.isArray(props.data)) {
|
66
|
+
console.error('Table3 data value is not an array');
|
67
|
+
}
|
68
|
+
}, []);
|
63
69
|
// custom features - shared/migrated
|
64
70
|
const columnOrdering = useTableColumnOrdering(options.enableColumnOrdering);
|
65
71
|
const fontSize = useTableFontSize(options.enableFontSize, settings.fontSize);
|
@@ -112,7 +118,8 @@ function useTable(props, ref) {
|
|
112
118
|
};
|
113
119
|
};
|
114
120
|
const table = useReactTable({
|
115
|
-
|
121
|
+
// We need to fallback to an empty array, to avoid table crash in the client
|
122
|
+
data: (_props$data = props.data) !== null && _props$data !== void 0 ? _props$data : [],
|
116
123
|
columns,
|
117
124
|
getCoreRowModel: getCoreRowModel(),
|
118
125
|
initialState,
|
@@ -156,7 +163,7 @@ function useTable(props, ref) {
|
|
156
163
|
useTableSortingListener(table, props.onSort);
|
157
164
|
return {
|
158
165
|
table,
|
159
|
-
length: (_props$length = props.length) !== null && _props$length !== void 0 ? _props$length : props.data.length
|
166
|
+
length: (_ref = (_props$length = props.length) !== null && _props$length !== void 0 ? _props$length : (_props$data2 = props.data) === null || _props$data2 === void 0 ? void 0 : _props$data2.length) !== null && _ref !== void 0 ? _ref : 0
|
160
167
|
};
|
161
168
|
}
|
162
169
|
function configureReactTableOptions(props, options) {
|
@@ -1 +1 @@
|
|
1
|
-
{"version":3,"file":"useTable.js","sources":["../../../../../../../../src/components/Table3/hooks/useTable.tsx"],"sourcesContent":["import React from 'react';\nimport {\n getCoreRowModel,\n useReactTable,\n Row as RTRow,\n RowData,\n Column as RTColumn,\n TableOptions as RTableOptions,\n TableState,\n getSortedRowModel,\n getFilteredRowModel,\n ColumnMeta,\n} from '@tanstack/react-table';\nimport {\n Table3ColumnAlignment,\n Table3ColumnRenderer,\n Table3Props,\n Table3ColumnHeaderMenu,\n Table3ColumnControlRenderer,\n Table3ColumnDataType,\n Table3ColumnClassNameHandler,\n Table3ColumnFooterRenderer,\n TableStrategy,\n Table3FilterComparator,\n Table3Settings,\n Table3Options,\n Table3Ref,\n} from '../types';\nimport { useTableRowActive } from '../../../primitives/Table/useTable/features/useTableRowActive';\nimport { useTablePreset } from './useTablePreset';\nimport { useTableRowHeight } from '../../../primitives/Table/useTable/features/useTableRowHeight';\nimport { useTableFontSize } from '../../../primitives/Table/useTable/features/useTableFontSize';\nimport { useTableRowSelectionListener } from '../../../primitives/Table/useTable/listeners/useTableRowSelectionListener';\nimport { useRowDrag } from './features/useRowDrag';\nimport { useSettingsStateListener } from './listeners/useSettingsStateListener';\nimport { columnFilterFn, globalFilterFn } from '../util/filtering';\nimport { useTableSortingListener } from '../../../primitives/Table/useTable/listeners/useTableSortingListener';\nimport { useTableFilterListener } from '../../../primitives/Table/useTable/listeners/useTableFilterListener';\nimport { useTableDataListener } from '../../../primitives/Table/useTable/listeners/useTableDataListener';\nimport { useColumnFreezing } from './features/useColumnFreezing';\nimport { useTableRowSelection } from '../../../primitives/Table/useTable/features/useTableRowSelection';\nimport { useTableServerLoading } from '../../../primitives/Table/useTable/features/useTableServerLoading';\nimport { useTableRowClick } from '../../../primitives/Table/useTable/features/useTableRowClick';\nimport { useTableColumnOrdering } from '../../../primitives/Table/useTable/features/useTableColumnOrdering';\nimport { useRowDrop } from './features/useRowDrop';\nimport { useConvertChildrenToColumns } from './useConvertChildrenToColumns';\nimport { useEditing } from './features/useEditing';\nimport { usePrinting } from './features/usePrinting';\nimport { useTableShortcutsListener } from '../../../primitives/Table/useTable/listeners/useTableShortcutsListener';\nimport { useTableRowGoto } from '../../../primitives/Table/useTable/features/useTableRowGoto';\nimport { useTableServerLoadingListener } from '../../../primitives/Table/useTable/listeners/useTableServerLoadingListener';\nimport { useEditingStateListener } from './listeners/useEditingStateListener';\nimport { useSearch } from './features/useSearch';\nimport { useRowActions } from './features/useRowActions';\nimport { useSettings } from './features/useSettings';\nimport { getCellValueAsString } from '../util/columns';\nimport { Table3Validation, useValidation } from './features/useValidation';\nimport { usePauseShortcuts } from './features/usePauseShortcuts';\nimport { useTableFontSizeListener } from '../../../primitives/Table/useTable/listeners/useTableFontSizeListener';\nimport { ensureOrdering } from '../../../primitives/Table/useTable/util/columns';\nimport { COLUMN_ID as ACTIONS_COLUMN_ID } from '../components/columns/internal/Actions';\nimport { COLUMN_ID as EDITING_ACTIONS_COLUMN_ID } from '../components/columns/internal/EditingActions';\n\ndeclare module '@tanstack/table-core' {\n interface TableMeta<TData extends RowData> {\n // @ts-expect-error: fixing type issue while report and table3 TableMeta definitions live in parallel\n columnFreezing: ReturnType<typeof useColumnFreezing>;\n columnOrdering: ReturnType<typeof useTableColumnOrdering>;\n editing: ReturnType<typeof useEditing>;\n enableFooter: boolean;\n fontSize: ReturnType<typeof useTableFontSize>;\n getSettings: () => Table3Settings;\n isPrinting: boolean;\n isUsingServer: boolean;\n // @ts-expect-error: fixing type issue while report and table3 TableMeta definitions live in parallel\n printing: ReturnType<typeof usePrinting>;\n // @ts-expect-error: fixing type issue while report and table3 TableMeta definitions live in parallel\n rowActions: ReturnType<typeof useRowActions>;\n rowActive: ReturnType<typeof useTableRowActive>;\n rowClick: ReturnType<typeof useTableRowClick>;\n rowDrag: ReturnType<typeof useRowDrag>;\n rowDrop: ReturnType<typeof useRowDrop>;\n rowGoto: ReturnType<typeof useTableRowGoto>;\n rowHeight: ReturnType<typeof useTableRowHeight>;\n rowSelection: ReturnType<typeof useTableRowSelection>;\n // @ts-expect-error: fixing type issue while report and table3 TableMeta definitions live in parallel\n search: ReturnType<typeof useSearch>;\n server: ReturnType<typeof useTableServerLoading>;\n shortcutsState: ReturnType<typeof usePauseShortcuts>;\n tableRef: React.RefObject<Table3Ref>;\n validation: Table3Validation<TData>;\n }\n\n interface ColumnMeta<TData extends RowData, TValue> {\n align?: Table3ColumnAlignment;\n className?: Table3ColumnClassNameHandler<TData>;\n control?: Table3ColumnControlRenderer<TData>;\n dataType?: Table3ColumnDataType;\n defaultWidth?: number;\n enableOrdering?: boolean;\n enableSearch: boolean;\n enableTruncate?: boolean;\n // @ts-expect-error: fixing type issue while report and table3 TableMeta definitions live in parallel\n filters?: Table3FilterComparator[];\n footer?: Table3ColumnFooterRenderer;\n header: string;\n headerClassName?: string;\n menu?: Table3ColumnHeaderMenu;\n renderer?: Table3ColumnRenderer<TValue, TData>;\n tooltip?: string;\n }\n\n interface CellContext<TData extends RowData, TValue> {\n index: number;\n tableRef: React.RefObject<HTMLDivElement>;\n }\n\n interface HeaderContext<TData extends RowData, TValue> {\n scrollToIndex: TableStrategy['scrollToIndex'];\n }\n}\n\nexport function useTable<TType = unknown>(props: Table3Props<TType>, ref: React.RefObject<Table3Ref>) {\n // load any persisted table settings and merge them with any defaults\n const [settings, setSettings] = useSettings(props.id, props.defaultSettings, props.onChangeSettings);\n\n // configure table3 options\n const options = useTablePreset(props);\n\n // configure react-table built-in features\n const tableOptions = configureReactTableOptions(props, options);\n\n // configure custom features\n const columnFreezing = useColumnFreezing(settings.columnFreezingIndex ?? props.defaultColumnFreezingIndex, options);\n // can't change due to rename to \"active row\"\n const validation = useValidation<TType>(props.onCellValidate, props.onRowValidate);\n // not relevant to common table\n const editing = useEditing<TType>(options.enableEditing, ref, validation, props.onSave);\n // we changed how printing works, so this shouldn't be migrated\n const printing = usePrinting(options.enablePrinting, settings.showWarningWhenPrintingLargeDataset, props.id);\n // needs to be moved\n const rowActions = useRowActions<TType>(props.actionsForRow, props.actionsForRowLength);\n // not relevant to common table\n const rowDrag = useRowDrag(options.enableRowDrag);\n // not relevant to common table\n const rowDrop = useRowDrop(options.enableRowDrop, props.onRowDrop);\n // haven't migrated load all/server loading yet\n const search = useSearch(options.enableSearch, settings.excludeUnmatchedRecordsInSearch);\n const shortcutsState = usePauseShortcuts();\n\n // custom features - shared/migrated\n const columnOrdering = useTableColumnOrdering(options.enableColumnOrdering);\n const fontSize = useTableFontSize(options.enableFontSize, settings.fontSize);\n const rowActive = useTableRowActive(true, props.defaultCurrentRowIndex);\n const rowClick = useTableRowClick<TType>(true, props.onRowClick);\n const rowGoto = useTableRowGoto(options.enableRowGoto, props.onRowGoto);\n const rowHeight = useTableRowHeight(options.enableRowHeight, settings.rowHeight);\n const rowSelection = useTableRowSelection(options.enableRowSelection);\n const server = useTableServerLoading(props.loadPage, props.loadAll);\n\n // columns\n const { columns, defaultColumnSizing, defaultColumnVisibility, defaultSorting } = useConvertChildrenToColumns<TType>(\n props,\n options,\n editing\n );\n\n // built-in features\n const initialState: Partial<TableState> = React.useMemo(() => {\n const sanitizeSortedColumns = column => columns.find(definedColumn => definedColumn.id === column.id);\n\n const state: Partial<TableState> = {\n columnOrder: ensureOrdering<TType>(columns, settings.columnOrder, [ACTIONS_COLUMN_ID, EDITING_ACTIONS_COLUMN_ID]),\n columnSizing: settings.columnSizing ?? defaultColumnSizing,\n columnVisibility: settings.columnVisibility ?? defaultColumnVisibility,\n sorting: settings.sorting ? settings.sorting.filter(sanitizeSortedColumns) : defaultSorting,\n };\n\n // we don't save these outside the table, but they need to be here for print to inherit them - see PrintButton.tsx\n if ((props.defaultSettings as any)?.columnFilters) {\n state.columnFilters = (props.defaultSettings as any)?.columnFilters;\n }\n\n if ((props.defaultSettings as any)?.globalFilter) {\n state.globalFilter = (props.defaultSettings as any)?.globalFilter;\n }\n\n return state;\n }, []);\n\n const getSettings = () => {\n const state = table.getState();\n return {\n columnFreezingIndex: columnFreezing.frozenColumnIndex,\n columnOrder: columnOrdering.isEnabled ? state.columnOrder : undefined,\n columnSizing: table.options.enableColumnResizing ? state.columnSizing : undefined,\n columnVisibility: table.options.enableHiding ? state.columnVisibility : undefined,\n excludeUnmatchedRecordsInSearch: search.excludeUnmatchedResults,\n fontSize: fontSize.isEnabled ? fontSize.size : undefined,\n rowHeight: rowHeight.isEnabled ? rowHeight.height : undefined,\n showWarningWhenPrintingLargeDataset: printing.isWarningVisibleForLargeDatasets,\n sorting: state.sorting,\n };\n };\n\n const table = useReactTable<TType>({\n data: props.data,\n columns,\n getCoreRowModel: getCoreRowModel(),\n initialState,\n ...tableOptions,\n //debugAll: true,\n meta: {\n columnFreezing,\n columnOrdering,\n editing,\n enableFooter: options.enableFooter,\n fontSize,\n getSettings,\n isPrinting: props.id.endsWith('_print'),\n isUsingServer: !!props.loadPage,\n printing,\n rowActions: rowActions as any,\n rowActive,\n rowClick: rowClick as any,\n rowDrag,\n rowDrop,\n rowGoto,\n rowHeight,\n rowSelection,\n search,\n server,\n shortcutsState,\n tableRef: ref,\n validation,\n },\n });\n\n // listeners\n useEditingStateListener(table);\n useSettingsStateListener(table, setSettings);\n // listeners - shared/migrated\n useTableDataListener(table);\n useTableFilterListener(table, props.onFilter);\n useTableFontSizeListener(table);\n useTableRowSelectionListener(table, props.onRowSelect);\n useTableServerLoadingListener(table, props.loadPage);\n useTableShortcutsListener(table, props.shortcuts);\n useTableSortingListener(table, props.onSort);\n\n return { table, length: props.length ?? props.data.length };\n}\n\nfunction configureReactTableOptions<TType = unknown>(props: Table3Props<TType>, options: Table3Options) {\n const tableOptions: Partial<RTableOptions<TType>> = {\n enableColumnFilters: options.enableFiltering,\n enableColumnResizing: options.enableColumnResizing,\n enableExpanding: options.enableRowExpansion,\n enableGlobalFilter: options.enableSearch,\n enableHiding: options.enableColumnHiding,\n enableRowSelection: options.enableRowSelection,\n enableMultiRowSelection: !options.enableRowSelectionSingle,\n enableSorting: options.enableSorting,\n };\n\n // resizing\n if (tableOptions.enableColumnResizing) {\n tableOptions.columnResizeMode = 'onChange';\n }\n\n // filtering\n if (tableOptions.enableColumnFilters) {\n if (!props.onFilter) {\n tableOptions.filterFns = {\n tacoFilter: (row: RTRow<TType>, columnId: string, filter: any) => columnFilterFn(row.getValue(columnId), filter),\n };\n tableOptions.getFilteredRowModel = getFilteredRowModel();\n }\n\n // we don't tableOptions.manualFiltering = true; because it breaks global filtering, server filtering still works :shrug:\n }\n\n // search\n if (tableOptions.enableGlobalFilter) {\n // search is always client side, since we call loadAll when searching\n tableOptions.globalFilterFn = (row: RTRow<TType>, columnId: string, searchQuery: string) => {\n try {\n if (row.original) {\n const cell = row.getAllCells().find(cell => cell.column.id === columnId);\n const columnMeta = cell?.column.columnDef.meta;\n\n if (cell && cell.column.getIsVisible() && columnMeta?.enableSearch) {\n const cellValue = getCellValueAsString(row.original[columnId], columnMeta?.dataType);\n\n if (cellValue !== undefined) {\n return globalFilterFn(cellValue, searchQuery);\n }\n }\n return false;\n }\n } catch {\n //\n }\n\n return false;\n };\n tableOptions.getFilteredRowModel = getFilteredRowModel();\n tableOptions.getColumnCanGlobalFilter = (column: RTColumn<TType>) =>\n (column.columnDef.meta as ColumnMeta<TType, unknown>).enableSearch ?? true;\n }\n\n // sorting\n if (options.enableSorting) {\n if (props.onSort) {\n tableOptions.manualSorting = true;\n // onSort is called as a listener to let the consumer update their data, so we don't use onSortingChange\n } else {\n tableOptions.getSortedRowModel = getSortedRowModel();\n }\n }\n\n return tableOptions;\n}\n"],"names":["useTable","props","ref","settings","setSettings","useSettings","id","defaultSettings","onChangeSettings","options","useTablePreset","tableOptions","configureReactTableOptions","columnFreezing","useColumnFreezing","_settings$columnFreez","columnFreezingIndex","defaultColumnFreezingIndex","validation","useValidation","onCellValidate","onRowValidate","editing","useEditing","enableEditing","onSave","printing","usePrinting","enablePrinting","showWarningWhenPrintingLargeDataset","rowActions","useRowActions","actionsForRow","actionsForRowLength","rowDrag","useRowDrag","enableRowDrag","rowDrop","useRowDrop","enableRowDrop","onRowDrop","search","useSearch","enableSearch","excludeUnmatchedRecordsInSearch","shortcutsState","usePauseShortcuts","columnOrdering","useTableColumnOrdering","enableColumnOrdering","fontSize","useTableFontSize","enableFontSize","rowActive","useTableRowActive","defaultCurrentRowIndex","rowClick","useTableRowClick","onRowClick","rowGoto","useTableRowGoto","enableRowGoto","onRowGoto","rowHeight","useTableRowHeight","enableRowHeight","rowSelection","useTableRowSelection","enableRowSelection","server","useTableServerLoading","loadPage","loadAll","columns","defaultColumnSizing","defaultColumnVisibility","defaultSorting","useConvertChildrenToColumns","initialState","React","useMemo","sanitizeSortedColumns","column","find","definedColumn","state","columnOrder","ensureOrdering","ACTIONS_COLUMN_ID","EDITING_ACTIONS_COLUMN_ID","columnSizing","_settings$columnSizin","columnVisibility","_settings$columnVisib","sorting","filter","_props$defaultSetting","columnFilters","_props$defaultSetting2","_props$defaultSetting3","globalFilter","_props$defaultSetting4","getSettings","table","getState","frozenColumnIndex","isEnabled","undefined","enableColumnResizing","enableHiding","excludeUnmatchedResults","size","height","isWarningVisibleForLargeDatasets","useReactTable","data","getCoreRowModel","meta","enableFooter","isPrinting","endsWith","isUsingServer","tableRef","useEditingStateListener","useSettingsStateListener","useTableDataListener","useTableFilterListener","onFilter","useTableFontSizeListener","useTableRowSelectionListener","onRowSelect","useTableServerLoadingListener","useTableShortcutsListener","shortcuts","useTableSortingListener","onSort","length","_props$length","enableColumnFilters","enableFiltering","enableExpanding","enableRowExpansion","enableGlobalFilter","enableColumnHiding","enableMultiRowSelection","enableRowSelectionSingle","enableSorting","columnResizeMode","filterFns","tacoFilter","row","columnId","columnFilterFn","getValue","getFilteredRowModel","globalFilterFn","searchQuery","original","cell","getAllCells","columnMeta","columnDef","getIsVisible","cellValue","getCellValueAsString","dataType","getColumnCanGlobalFilter","_column$columnDef$met","manualSorting","getSortedRowModel"],"mappings":";;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;SA0HgBA,QAAQA,CAAkBC,KAAyB,EAAEC,GAA+B;;;EAEhG,MAAM,CAACC,QAAQ,EAAEC,WAAW,CAAC,GAAGC,WAAW,CAACJ,KAAK,CAACK,EAAE,EAAEL,KAAK,CAACM,eAAe,EAAEN,KAAK,CAACO,gBAAgB,CAAC;;EAGpG,MAAMC,OAAO,GAAGC,cAAc,CAACT,KAAK,CAAC;;EAGrC,MAAMU,YAAY,GAAGC,0BAA0B,CAACX,KAAK,EAAEQ,OAAO,CAAC;;EAG/D,M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AAI,aAAJA,IAAI,uBAAJA,IAAI,CAAE5E,MAAM,CAAC+E,SAAS,CAAC5C,IAAI;UAE9C,IAAIyC,IAAI,IAAIA,IAAI,CAAC5E,MAAM,CAACgF,YAAY,EAAE,IAAIF,UAAU,aAAVA,UAAU,eAAVA,UAAU,CAAErH,YAAY,EAAE;YAChE,MAAMwH,SAAS,GAAGC,oBAAoB,CAACd,GAAG,CAACO,QAAQ,CAACN,QAAQ,CAAC,EAAES,UAAU,aAAVA,UAAU,uBAAVA,UAAU,CAAEK,QAAQ,CAAC;YAEpF,IAAIF,SAAS,KAAKxD,SAAS,EAAE;cACzB,OAAOgD,cAAc,CAACQ,SAAS,EAAEP,WAAW,CAAC;;;UAGrD,OAAO,KAAK;;OAEnB,CAAC,MAAM;;;MAIR,OAAO,KAAK;KACf;IACDjJ,YAAY,CAAC+I,mBAAmB,GAAGA,mBAAmB,EAAE;IACxD/I,YAAY,CAAC2J,wBAAwB,GAAIpF,MAAuB;MAAA,IAAAqF,qBAAA;MAAA,QAAAA,qBAAA,GAC3DrF,MAAM,CAAC+E,SAAS,CAAC5C,IAAmC,CAAC1E,YAAY,cAAA4H,qBAAA,cAAAA,qBAAA,GAAI,IAAI;;;;EAIlF,IAAI9J,OAAO,CAACyI,aAAa,EAAE;IACvB,IAAIjJ,KAAK,CAACsI,MAAM,EAAE;MACd5H,YAAY,CAAC6J,aAAa,GAAG,IAAI;;KAEpC,MAAM;MACH7J,YAAY,CAAC8J,iBAAiB,GAAGA,iBAAiB,EAAE;;;EAI5D,OAAO9J,YAAY;AACvB;;;;"}
|
1
|
+
{"version":3,"file":"useTable.js","sources":["../../../../../../../../src/components/Table3/hooks/useTable.tsx"],"sourcesContent":["import React from 'react';\nimport {\n getCoreRowModel,\n useReactTable,\n Row as RTRow,\n RowData,\n Column as RTColumn,\n TableOptions as RTableOptions,\n TableState,\n getSortedRowModel,\n getFilteredRowModel,\n ColumnMeta,\n} from '@tanstack/react-table';\nimport {\n Table3ColumnAlignment,\n Table3ColumnRenderer,\n Table3Props,\n Table3ColumnHeaderMenu,\n Table3ColumnControlRenderer,\n Table3ColumnDataType,\n Table3ColumnClassNameHandler,\n Table3ColumnFooterRenderer,\n TableStrategy,\n Table3FilterComparator,\n Table3Settings,\n Table3Options,\n Table3Ref,\n} from '../types';\nimport { useTableRowActive } from '../../../primitives/Table/useTable/features/useTableRowActive';\nimport { useTablePreset } from './useTablePreset';\nimport { useTableRowHeight } from '../../../primitives/Table/useTable/features/useTableRowHeight';\nimport { useTableFontSize } from '../../../primitives/Table/useTable/features/useTableFontSize';\nimport { useTableRowSelectionListener } from '../../../primitives/Table/useTable/listeners/useTableRowSelectionListener';\nimport { useRowDrag } from './features/useRowDrag';\nimport { useSettingsStateListener } from './listeners/useSettingsStateListener';\nimport { columnFilterFn, globalFilterFn } from '../util/filtering';\nimport { useTableSortingListener } from '../../../primitives/Table/useTable/listeners/useTableSortingListener';\nimport { useTableFilterListener } from '../../../primitives/Table/useTable/listeners/useTableFilterListener';\nimport { useTableDataListener } from '../../../primitives/Table/useTable/listeners/useTableDataListener';\nimport { useColumnFreezing } from './features/useColumnFreezing';\nimport { useTableRowSelection } from '../../../primitives/Table/useTable/features/useTableRowSelection';\nimport { useTableServerLoading } from '../../../primitives/Table/useTable/features/useTableServerLoading';\nimport { useTableRowClick } from '../../../primitives/Table/useTable/features/useTableRowClick';\nimport { useTableColumnOrdering } from '../../../primitives/Table/useTable/features/useTableColumnOrdering';\nimport { useRowDrop } from './features/useRowDrop';\nimport { useConvertChildrenToColumns } from './useConvertChildrenToColumns';\nimport { useEditing } from './features/useEditing';\nimport { usePrinting } from './features/usePrinting';\nimport { useTableShortcutsListener } from '../../../primitives/Table/useTable/listeners/useTableShortcutsListener';\nimport { useTableRowGoto } from '../../../primitives/Table/useTable/features/useTableRowGoto';\nimport { useTableServerLoadingListener } from '../../../primitives/Table/useTable/listeners/useTableServerLoadingListener';\nimport { useEditingStateListener } from './listeners/useEditingStateListener';\nimport { useSearch } from './features/useSearch';\nimport { useRowActions } from './features/useRowActions';\nimport { useSettings } from './features/useSettings';\nimport { getCellValueAsString } from '../util/columns';\nimport { Table3Validation, useValidation } from './features/useValidation';\nimport { usePauseShortcuts } from './features/usePauseShortcuts';\nimport { useTableFontSizeListener } from '../../../primitives/Table/useTable/listeners/useTableFontSizeListener';\nimport { ensureOrdering } from '../../../primitives/Table/useTable/util/columns';\nimport { COLUMN_ID as ACTIONS_COLUMN_ID } from '../components/columns/internal/Actions';\nimport { COLUMN_ID as EDITING_ACTIONS_COLUMN_ID } from '../components/columns/internal/EditingActions';\n\ndeclare module '@tanstack/table-core' {\n interface TableMeta<TData extends RowData> {\n // @ts-expect-error: fixing type issue while report and table3 TableMeta definitions live in parallel\n columnFreezing: ReturnType<typeof useColumnFreezing>;\n columnOrdering: ReturnType<typeof useTableColumnOrdering>;\n editing: ReturnType<typeof useEditing>;\n enableFooter: boolean;\n fontSize: ReturnType<typeof useTableFontSize>;\n getSettings: () => Table3Settings;\n isPrinting: boolean;\n isUsingServer: boolean;\n // @ts-expect-error: fixing type issue while report and table3 TableMeta definitions live in parallel\n printing: ReturnType<typeof usePrinting>;\n // @ts-expect-error: fixing type issue while report and table3 TableMeta definitions live in parallel\n rowActions: ReturnType<typeof useRowActions>;\n rowActive: ReturnType<typeof useTableRowActive>;\n rowClick: ReturnType<typeof useTableRowClick>;\n rowDrag: ReturnType<typeof useRowDrag>;\n rowDrop: ReturnType<typeof useRowDrop>;\n rowGoto: ReturnType<typeof useTableRowGoto>;\n rowHeight: ReturnType<typeof useTableRowHeight>;\n rowSelection: ReturnType<typeof useTableRowSelection>;\n // @ts-expect-error: fixing type issue while report and table3 TableMeta definitions live in parallel\n search: ReturnType<typeof useSearch>;\n server: ReturnType<typeof useTableServerLoading>;\n shortcutsState: ReturnType<typeof usePauseShortcuts>;\n tableRef: React.RefObject<Table3Ref>;\n validation: Table3Validation<TData>;\n }\n\n interface ColumnMeta<TData extends RowData, TValue> {\n align?: Table3ColumnAlignment;\n className?: Table3ColumnClassNameHandler<TData>;\n control?: Table3ColumnControlRenderer<TData>;\n dataType?: Table3ColumnDataType;\n defaultWidth?: number;\n enableOrdering?: boolean;\n enableSearch: boolean;\n enableTruncate?: boolean;\n // @ts-expect-error: fixing type issue while report and table3 TableMeta definitions live in parallel\n filters?: Table3FilterComparator[];\n footer?: Table3ColumnFooterRenderer;\n header: string;\n headerClassName?: string;\n menu?: Table3ColumnHeaderMenu;\n renderer?: Table3ColumnRenderer<TValue, TData>;\n tooltip?: string;\n }\n\n interface CellContext<TData extends RowData, TValue> {\n index: number;\n tableRef: React.RefObject<HTMLDivElement>;\n }\n\n interface HeaderContext<TData extends RowData, TValue> {\n scrollToIndex: TableStrategy['scrollToIndex'];\n }\n}\n\nexport function useTable<TType = unknown>(props: Table3Props<TType>, ref: React.RefObject<Table3Ref>) {\n // load any persisted table settings and merge them with any defaults\n const [settings, setSettings] = useSettings(props.id, props.defaultSettings, props.onChangeSettings);\n\n // configure table3 options\n const options = useTablePreset(props);\n\n // configure react-table built-in features\n const tableOptions = configureReactTableOptions(props, options);\n\n // configure custom features\n const columnFreezing = useColumnFreezing(settings.columnFreezingIndex ?? props.defaultColumnFreezingIndex, options);\n // can't change due to rename to \"active row\"\n const validation = useValidation<TType>(props.onCellValidate, props.onRowValidate);\n // not relevant to common table\n const editing = useEditing<TType>(options.enableEditing, ref, validation, props.onSave);\n // we changed how printing works, so this shouldn't be migrated\n const printing = usePrinting(options.enablePrinting, settings.showWarningWhenPrintingLargeDataset, props.id);\n // needs to be moved\n const rowActions = useRowActions<TType>(props.actionsForRow, props.actionsForRowLength);\n // not relevant to common table\n const rowDrag = useRowDrag(options.enableRowDrag);\n // not relevant to common table\n const rowDrop = useRowDrop(options.enableRowDrop, props.onRowDrop);\n // haven't migrated load all/server loading yet\n const search = useSearch(options.enableSearch, settings.excludeUnmatchedRecordsInSearch);\n const shortcutsState = usePauseShortcuts();\n\n React.useEffect(() => {\n // Needed for DataDog\n if (!Array.isArray(props.data)) {\n console.error('Table3 data value is not an array');\n }\n }, []);\n\n // custom features - shared/migrated\n const columnOrdering = useTableColumnOrdering(options.enableColumnOrdering);\n const fontSize = useTableFontSize(options.enableFontSize, settings.fontSize);\n const rowActive = useTableRowActive(true, props.defaultCurrentRowIndex);\n const rowClick = useTableRowClick<TType>(true, props.onRowClick);\n const rowGoto = useTableRowGoto(options.enableRowGoto, props.onRowGoto);\n const rowHeight = useTableRowHeight(options.enableRowHeight, settings.rowHeight);\n const rowSelection = useTableRowSelection(options.enableRowSelection);\n const server = useTableServerLoading(props.loadPage, props.loadAll);\n\n // columns\n const { columns, defaultColumnSizing, defaultColumnVisibility, defaultSorting } = useConvertChildrenToColumns<TType>(\n props,\n options,\n editing\n );\n\n // built-in features\n const initialState: Partial<TableState> = React.useMemo(() => {\n const sanitizeSortedColumns = column => columns.find(definedColumn => definedColumn.id === column.id);\n\n const state: Partial<TableState> = {\n columnOrder: ensureOrdering<TType>(columns, settings.columnOrder, [ACTIONS_COLUMN_ID, EDITING_ACTIONS_COLUMN_ID]),\n columnSizing: settings.columnSizing ?? defaultColumnSizing,\n columnVisibility: settings.columnVisibility ?? defaultColumnVisibility,\n sorting: settings.sorting ? settings.sorting.filter(sanitizeSortedColumns) : defaultSorting,\n };\n\n // we don't save these outside the table, but they need to be here for print to inherit them - see PrintButton.tsx\n if ((props.defaultSettings as any)?.columnFilters) {\n state.columnFilters = (props.defaultSettings as any)?.columnFilters;\n }\n\n if ((props.defaultSettings as any)?.globalFilter) {\n state.globalFilter = (props.defaultSettings as any)?.globalFilter;\n }\n\n return state;\n }, []);\n\n const getSettings = () => {\n const state = table.getState();\n return {\n columnFreezingIndex: columnFreezing.frozenColumnIndex,\n columnOrder: columnOrdering.isEnabled ? state.columnOrder : undefined,\n columnSizing: table.options.enableColumnResizing ? state.columnSizing : undefined,\n columnVisibility: table.options.enableHiding ? state.columnVisibility : undefined,\n excludeUnmatchedRecordsInSearch: search.excludeUnmatchedResults,\n fontSize: fontSize.isEnabled ? fontSize.size : undefined,\n rowHeight: rowHeight.isEnabled ? rowHeight.height : undefined,\n showWarningWhenPrintingLargeDataset: printing.isWarningVisibleForLargeDatasets,\n sorting: state.sorting,\n };\n };\n\n const table = useReactTable<TType>({\n // We need to fallback to an empty array, to avoid table crash in the client\n data: props.data ?? [],\n columns,\n getCoreRowModel: getCoreRowModel(),\n initialState,\n ...tableOptions,\n //debugAll: true,\n meta: {\n columnFreezing,\n columnOrdering,\n editing,\n enableFooter: options.enableFooter,\n fontSize,\n getSettings,\n isPrinting: props.id.endsWith('_print'),\n isUsingServer: !!props.loadPage,\n printing,\n rowActions: rowActions as any,\n rowActive,\n rowClick: rowClick as any,\n rowDrag,\n rowDrop,\n rowGoto,\n rowHeight,\n rowSelection,\n search,\n server,\n shortcutsState,\n tableRef: ref,\n validation,\n },\n });\n\n // listeners\n useEditingStateListener(table);\n useSettingsStateListener(table, setSettings);\n // listeners - shared/migrated\n useTableDataListener(table);\n useTableFilterListener(table, props.onFilter);\n useTableFontSizeListener(table);\n useTableRowSelectionListener(table, props.onRowSelect);\n useTableServerLoadingListener(table, props.loadPage);\n useTableShortcutsListener(table, props.shortcuts);\n useTableSortingListener(table, props.onSort);\n\n return { table, length: props.length ?? props.data?.length ?? 0 };\n}\n\nfunction configureReactTableOptions<TType = unknown>(props: Table3Props<TType>, options: Table3Options) {\n const tableOptions: Partial<RTableOptions<TType>> = {\n enableColumnFilters: options.enableFiltering,\n enableColumnResizing: options.enableColumnResizing,\n enableExpanding: options.enableRowExpansion,\n enableGlobalFilter: options.enableSearch,\n enableHiding: options.enableColumnHiding,\n enableRowSelection: options.enableRowSelection,\n enableMultiRowSelection: !options.enableRowSelectionSingle,\n enableSorting: options.enableSorting,\n };\n\n // resizing\n if (tableOptions.enableColumnResizing) {\n tableOptions.columnResizeMode = 'onChange';\n }\n\n // filtering\n if (tableOptions.enableColumnFilters) {\n if (!props.onFilter) {\n tableOptions.filterFns = {\n tacoFilter: (row: RTRow<TType>, columnId: string, filter: any) => columnFilterFn(row.getValue(columnId), filter),\n };\n tableOptions.getFilteredRowModel = getFilteredRowModel();\n }\n\n // we don't tableOptions.manualFiltering = true; because it breaks global filtering, server filtering still works :shrug:\n }\n\n // search\n if (tableOptions.enableGlobalFilter) {\n // search is always client side, since we call loadAll when searching\n tableOptions.globalFilterFn = (row: RTRow<TType>, columnId: string, searchQuery: string) => {\n try {\n if (row.original) {\n const cell = row.getAllCells().find(cell => cell.column.id === columnId);\n const columnMeta = cell?.column.columnDef.meta;\n\n if (cell && cell.column.getIsVisible() && columnMeta?.enableSearch) {\n const cellValue = getCellValueAsString(row.original[columnId], columnMeta?.dataType);\n\n if (cellValue !== undefined) {\n return globalFilterFn(cellValue, searchQuery);\n }\n }\n return false;\n }\n } catch {\n //\n }\n\n return false;\n };\n tableOptions.getFilteredRowModel = getFilteredRowModel();\n tableOptions.getColumnCanGlobalFilter = (column: RTColumn<TType>) =>\n (column.columnDef.meta as ColumnMeta<TType, unknown>).enableSearch ?? true;\n }\n\n // sorting\n if (options.enableSorting) {\n if (props.onSort) {\n tableOptions.manualSorting = true;\n // onSort is called as a listener to let the consumer update their data, so we don't use onSortingChange\n } else {\n tableOptions.getSortedRowModel = getSortedRowModel();\n }\n }\n\n return tableOptions;\n}\n"],"names":["useTable","props","ref","settings","setSettings","useSettings","id","defaultSettings","onChangeSettings","options","useTablePreset","tableOptions","configureReactTableOptions","columnFreezing","useColumnFreezing","_settings$columnFreez","columnFreezingIndex","defaultColumnFreezingIndex","validation","useValidation","onCellValidate","onRowValidate","editing","useEditing","enableEditing","onSave","printing","usePrinting","enablePrinting","showWarningWhenPrintingLargeDataset","rowActions","useRowActions","actionsForRow","actionsForRowLength","rowDrag","useRowDrag","enableRowDrag","rowDrop","useRowDrop","enableRowDrop","onRowDrop","search","useSearch","enableSearch","excludeUnmatchedRecordsInSearch","shortcutsState","usePauseShortcuts","React","useEffect","Array","isArray","data","console","error","columnOrdering","useTableColumnOrdering","enableColumnOrdering","fontSize","useTableFontSize","enableFontSize","rowActive","useTableRowActive","defaultCurrentRowIndex","rowClick","useTableRowClick","onRowClick","rowGoto","useTableRowGoto","enableRowGoto","onRowGoto","rowHeight","useTableRowHeight","enableRowHeight","rowSelection","useTableRowSelection","enableRowSelection","server","useTableServerLoading","loadPage","loadAll","columns","defaultColumnSizing","defaultColumnVisibility","defaultSorting","useConvertChildrenToColumns","initialState","useMemo","sanitizeSortedColumns","column","find","definedColumn","state","columnOrder","ensureOrdering","ACTIONS_COLUMN_ID","EDITING_ACTIONS_COLUMN_ID","columnSizing","_settings$columnSizin","columnVisibility","_settings$columnVisib","sorting","filter","_props$defaultSetting","columnFilters","_props$defaultSetting2","_props$defaultSetting3","globalFilter","_props$defaultSetting4","getSettings","table","getState","frozenColumnIndex","isEnabled","undefined","enableColumnResizing","enableHiding","excludeUnmatchedResults","size","height","isWarningVisibleForLargeDatasets","useReactTable","_props$data","getCoreRowModel","meta","enableFooter","isPrinting","endsWith","isUsingServer","tableRef","useEditingStateListener","useSettingsStateListener","useTableDataListener","useTableFilterListener","onFilter","useTableFontSizeListener","useTableRowSelectionListener","onRowSelect","useTableServerLoadingListener","useTableShortcutsListener","shortcuts","useTableSortingListener","onSort","length","_ref","_props$length","_props$data2","enableColumnFilters","enableFiltering","enableExpanding","enableRowExpansion","enableGlobalFilter","enableColumnHiding","enableMultiRowSelection","enableRowSelectionSingle","enableSorting","columnResizeMode","filterFns","tacoFilter","row","columnId","columnFilterFn","getValue","getFilteredRowModel","globalFilterFn","searchQuery","original","cell","getAllCells","columnMeta","columnDef","getIsVisible","cellValue","getCellValueAsString","dataType","getColumnCanGlobalFilter","_column$columnDef$met","manualSorting","getSortedRowModel"],"mappings":";;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;SA0HgBA,QAAQA,CAAkBC,KAAyB,EAAEC,GAA+B;;;EAEhG,MAAM,CAACC,QAAQ,EAAEC,WAAW,CAAC,GAAGC,WAAW,CAACJ,KAAK,CAACK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AC9C,IAAmC,CAAChF,YAAY,cAAAoI,qBAAA,cAAAA,qBAAA,GAAI,IAAI;;;;EAIlF,IAAItK,OAAO,CAACiJ,aAAa,EAAE;IACvB,IAAIzJ,KAAK,CAAC4I,MAAM,EAAE;MACdlI,YAAY,CAACqK,aAAa,GAAG,IAAI;;KAEpC,MAAM;MACHrK,YAAY,CAACsK,iBAAiB,GAAGA,iBAAiB,EAAE;;;EAI5D,OAAOtK,YAAY;AACvB;;;;"}
|
@@ -1,6 +1,7 @@
|
|
1
1
|
import { useState, useCallback, useEffect, createElement, useContext, createContext } from 'react';
|
2
2
|
import { v4 } from 'uuid';
|
3
3
|
import { AnimatePresence, motion } from 'framer-motion';
|
4
|
+
import { Portal } from '@radix-ui/react-portal';
|
4
5
|
import { Toast } from './Toast.js';
|
5
6
|
|
6
7
|
const DEFAULT_AUTO_CLOSE_TIMEOUT = 7500;
|
@@ -111,9 +112,9 @@ const ToastProvider = ({
|
|
111
112
|
}, []);
|
112
113
|
return /*#__PURE__*/createElement(ToastContext.Provider, Object.assign({}, props, {
|
113
114
|
value: toaster
|
114
|
-
}), children, /*#__PURE__*/createElement("div", {
|
115
|
+
}), children, /*#__PURE__*/createElement(Portal, null, /*#__PURE__*/createElement("div", {
|
115
116
|
id: "yt-toast__container",
|
116
|
-
className: "pointer-events-all absolute bottom-0 right-0
|
117
|
+
className: "pointer-events-all absolute !left-auto bottom-0 right-0 z-[1000] mb-4 mr-4 flex max-w-md flex-col items-end justify-end",
|
117
118
|
role: "log"
|
118
119
|
}, /*#__PURE__*/createElement(AnimatePresence, {
|
119
120
|
initial: false
|
@@ -143,7 +144,7 @@ const ToastProvider = ({
|
|
143
144
|
}
|
144
145
|
}, /*#__PURE__*/createElement(Toast, Object.assign({}, toast, {
|
145
146
|
onClose: () => handleClose(toast.id)
|
146
|
-
}))))))));
|
147
|
+
})))))))));
|
147
148
|
};
|
148
149
|
const useToast = () => useContext(ToastContext);
|
149
150
|
|
@@ -1 +1 @@
|
|
1
|
-
{"version":3,"file":"Toaster.js","sources":["../../../../../../../src/components/Toast/Toaster.tsx"],"sourcesContent":["import * as React from 'react';\nimport { v4 as uuid } from 'uuid';\nimport { AnimatePresence, motion } from 'framer-motion';\nimport { ToastOptions, Toast, ToastProps, ToastContent } from './Toast';\nimport './Toast.css';\n\nconst DEFAULT_AUTO_CLOSE_TIMEOUT = 7500;\n\ntype ToastCreator<T> = (content: ToastContent | ((close: () => void) => ToastContent), options?: ToastOptions) => T;\n\nexport interface Toaster<T> extends ToastCreator<T> {\n success: ToastCreator<T>;\n error: ToastCreator<T>;\n warning: ToastCreator<T>;\n information: ToastCreator<T>;\n loading: ToastCreator<T>;\n}\n\nexport interface ToastReference {\n /** Show a success toast */\n success: ToastCreator<void>;\n /** Show an error toast */\n error: ToastCreator<void>;\n /** Show a warning toast */\n warning: ToastCreator<void>;\n /** Show an information toast */\n information: ToastCreator<void>;\n /** Show a loading toast */\n loading: ToastCreator<void>;\n /**\n * Close an existing toast.\n * The toast function returns a reference to the active toast,\n * allowing you to programmatically close it when needed\n */\n close: () => void;\n}\n\nconst ToastContext = React.createContext<Toaster<ToastReference>>({} as Toaster<ToastReference>);\n\nexport interface ToastProviderProps {\n children: React.ReactNode;\n}\n\ntype InternalToast = Omit<ToastProps, 'onClose'>;\n\nconst insertToastWithoutDuplicates = (\n currentToasts: InternalToast[],\n id: string,\n content: ToastContent,\n options: ToastOptions,\n close: () => void\n): InternalToast[] => {\n const nextToasts = [...currentToasts];\n const existingToastIndex = currentToasts.findIndex(toast => JSON.stringify(toast.content) === JSON.stringify(content));\n\n if (existingToastIndex > -1) {\n nextToasts[existingToastIndex].lastDuplicateId = id;\n nextToasts[existingToastIndex].lastUpdated = Date.now();\n } else {\n nextToasts.push({\n id,\n content: typeof content === 'function' ? content(close) : content,\n options,\n });\n }\n\n return nextToasts;\n};\n\nexport const ToastProvider = ({ children, ...props }: ToastProviderProps): JSX.Element => {\n const [toasts, setToasts] = React.useState<InternalToast[]>([]);\n\n const handleClose = (id: string): void => {\n setToasts(currentToasts => currentToasts.filter(toast => toast.id !== id));\n };\n\n // memoize (useCallback) this function,\n // it is the value of the context provider and we don't want it to trigger state tree re-renders on provider children\n const toaster = React.useCallback((content: ToastContent, options: ToastOptions): ToastReference => {\n const id = uuid();\n const close = (): void => handleClose(id);\n\n setToasts(currentToasts => insertToastWithoutDuplicates(currentToasts, id, content, options, close));\n\n const update = (content: ToastContent, options: ToastOptions): void => {\n setToasts(currentToasts => {\n const nextToasts = currentToasts.filter(toast => {\n if (toast.lastDuplicateId) {\n return toast.lastDuplicateId !== id;\n }\n\n return toast.id !== id;\n });\n return insertToastWithoutDuplicates(nextToasts, uuid(), content, options, close);\n });\n };\n\n const success = (content: ToastContent, options?: Omit<ToastOptions, 'type'>): void => {\n update(content, { autoClose: DEFAULT_AUTO_CLOSE_TIMEOUT, ...options, type: 'success' });\n };\n const error = (content: ToastContent, options?: Omit<ToastOptions, 'type'>): void => {\n update(content, { ...options, type: 'error' });\n };\n const warning = (content: ToastContent, options?: Omit<ToastOptions, 'type'>): void => {\n update(content, { ...options, type: 'warning' });\n };\n const information = (content: ToastContent, options?: Omit<ToastOptions, 'type'>): void => {\n update(content, { ...options, type: 'information' });\n };\n const loading = (content: ToastContent, options?: Omit<ToastOptions, 'type'>): void => {\n update(content, { ...options, type: 'loading' });\n };\n\n return {\n success,\n error,\n warning,\n information,\n loading,\n close,\n };\n }, []) as Toaster<ToastReference>;\n\n // no need to rebind these every render, do them once in an effect\n React.useEffect(() => {\n toaster.success = (content: ToastContent, options?: Omit<ToastOptions, 'type'>): ToastReference =>\n toaster(content, { autoClose: DEFAULT_AUTO_CLOSE_TIMEOUT, ...options, type: 'success' });\n toaster.error = (content: ToastContent, options?: Omit<ToastOptions, 'type'>): ToastReference =>\n toaster(content, { ...options, type: 'error' });\n toaster.warning = (content: ToastContent, options?: Omit<ToastOptions, 'type'>): ToastReference =>\n toaster(content, { ...options, type: 'warning' });\n toaster.information = (content: ToastContent, options?: Omit<ToastOptions, 'type'>): ToastReference =>\n toaster(content, { ...options, type: 'information' });\n toaster.loading = (content: ToastContent, options?: Omit<ToastOptions, 'type'>): ToastReference =>\n toaster(content, { ...options, type: 'loading' });\n }, []);\n\n return (\n <ToastContext.Provider {...props} value={toaster}>\n {children}\n <div\n id=\"yt-toast__container\"\n className=\"pointer-events-all absolute bottom-0 right-0 !left-auto z-[1000] mb-4 mr-4 flex max-w-md flex-col items-end justify-end\"\n role=\"log\">\n <AnimatePresence initial={false}>\n {toasts.map((toast: InternalToast) => (\n <motion.div\n key={toast.id}\n transition={{\n type: 'spring',\n damping: 20,\n stiffness: 300,\n }}\n initial={{ opacity: 0, y: 10, scale: 0.5 }}\n animate={{ opacity: 1, y: 0, scale: 1 }}\n exit={{ opacity: 0, scale: 0.5, transition: { duration: 0.2 } }}>\n <Toast {...toast} onClose={() => handleClose(toast.id)} />\n </motion.div>\n ))}\n </AnimatePresence>\n </div>\n </ToastContext.Provider>\n );\n};\n\nexport const useToast = (): Toaster<ToastReference> => React.useContext(ToastContext);\n"],"names":["DEFAULT_AUTO_CLOSE_TIMEOUT","ToastContext","React","insertToastWithoutDuplicates","currentToasts","id","content","options","close","nextToasts","existingToastIndex","findIndex","toast","JSON","stringify","lastDuplicateId","lastUpdated","Date","now","push","ToastProvider","children","props","toasts","setToasts","handleClose","filter","toaster","uuid","update","success","autoClose","type","error","warning","information","loading","Provider","value","className","role","AnimatePresence","initial","map","motion","div","key","transition","damping","stiffness","opacity","y","scale","animate","exit","duration","Toast","onClose","useToast"],"mappings":";;;;;AAMA,MAAMA,0BAA0B,GAAG,IAAI;AA+BvC,MAAMC,YAAY,gBAAGC,aAAmB,CAA0B,EAA6B,CAAC;AAQhG,MAAMC,4BAA4B,GAAGA,CACjCC,aAA8B,EAC9BC,EAAU,EACVC,OAAqB,EACrBC,OAAqB,EACrBC,KAAiB;EAEjB,MAAMC,UAAU,GAAG,CAAC,GAAGL,aAAa,CAAC;EACrC,MAAMM,kBAA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E;MAAEC,KAAK,EAAE;KAAK;IAC1CC,OAAO,EAAE;MAAEH,OAAO,EAAE,CAAC;MAAEC,CAAC,EAAE,CAAC;MAAEC,KAAK,EAAE;KAAG;IACvCE,IAAI,EAAE;MAAEJ,OAAO,EAAE,CAAC;MAAEE,KAAK,EAAE,GAAG;MAAEL,UAAU,EAAE;QAAEQ,QAAQ,EAAE;;;kBACxDrD,cAACsD,KAAK,oBAAK5C,KAAK;IAAE6C,OAAO,EAAEA,MAAMhC,WAAW,CAACb,KAAK,CAACP,EAAE;KAAK,CACjD,CAChB,CAAC,CACY,CAChB,CACc;AAEhC;MAEaqD,QAAQ,GAAGA,MAA+BxD,UAAgB,CAACD,YAAY;;;;"}
|
1
|
+
{"version":3,"file":"Toaster.js","sources":["../../../../../../../src/components/Toast/Toaster.tsx"],"sourcesContent":["import * as React from 'react';\nimport { v4 as uuid } from 'uuid';\nimport { AnimatePresence, motion } from 'framer-motion';\nimport { Portal } from '@radix-ui/react-portal';\n\nimport { ToastOptions, Toast, ToastProps, ToastContent } from './Toast';\nimport './Toast.css';\n\nconst DEFAULT_AUTO_CLOSE_TIMEOUT = 7500;\n\ntype ToastCreator<T> = (content: ToastContent | ((close: () => void) => ToastContent), options?: ToastOptions) => T;\n\nexport interface Toaster<T> extends ToastCreator<T> {\n success: ToastCreator<T>;\n error: ToastCreator<T>;\n warning: ToastCreator<T>;\n information: ToastCreator<T>;\n loading: ToastCreator<T>;\n}\n\nexport interface ToastReference {\n /** Show a success toast */\n success: ToastCreator<void>;\n /** Show an error toast */\n error: ToastCreator<void>;\n /** Show a warning toast */\n warning: ToastCreator<void>;\n /** Show an information toast */\n information: ToastCreator<void>;\n /** Show a loading toast */\n loading: ToastCreator<void>;\n /**\n * Close an existing toast.\n * The toast function returns a reference to the active toast,\n * allowing you to programmatically close it when needed\n */\n close: () => void;\n}\n\nconst ToastContext = React.createContext<Toaster<ToastReference>>({} as Toaster<ToastReference>);\n\nexport interface ToastProviderProps {\n children: React.ReactNode;\n}\n\ntype InternalToast = Omit<ToastProps, 'onClose'>;\n\nconst insertToastWithoutDuplicates = (\n currentToasts: InternalToast[],\n id: string,\n content: ToastContent,\n options: ToastOptions,\n close: () => void\n): InternalToast[] => {\n const nextToasts = [...currentToasts];\n const existingToastIndex = currentToasts.findIndex(toast => JSON.stringify(toast.content) === JSON.stringify(content));\n\n if (existingToastIndex > -1) {\n nextToasts[existingToastIndex].lastDuplicateId = id;\n nextToasts[existingToastIndex].lastUpdated = Date.now();\n } else {\n nextToasts.push({\n id,\n content: typeof content === 'function' ? content(close) : content,\n options,\n });\n }\n\n return nextToasts;\n};\n\nexport const ToastProvider = ({ children, ...props }: ToastProviderProps): JSX.Element => {\n const [toasts, setToasts] = React.useState<InternalToast[]>([]);\n\n const handleClose = (id: string): void => {\n setToasts(currentToasts => currentToasts.filter(toast => toast.id !== id));\n };\n\n // memoize (useCallback) this function,\n // it is the value of the context provider and we don't want it to trigger state tree re-renders on provider children\n const toaster = React.useCallback((content: ToastContent, options: ToastOptions): ToastReference => {\n const id = uuid();\n const close = (): void => handleClose(id);\n\n setToasts(currentToasts => insertToastWithoutDuplicates(currentToasts, id, content, options, close));\n\n const update = (content: ToastContent, options: ToastOptions): void => {\n setToasts(currentToasts => {\n const nextToasts = currentToasts.filter(toast => {\n if (toast.lastDuplicateId) {\n return toast.lastDuplicateId !== id;\n }\n\n return toast.id !== id;\n });\n return insertToastWithoutDuplicates(nextToasts, uuid(), content, options, close);\n });\n };\n\n const success = (content: ToastContent, options?: Omit<ToastOptions, 'type'>): void => {\n update(content, { autoClose: DEFAULT_AUTO_CLOSE_TIMEOUT, ...options, type: 'success' });\n };\n const error = (content: ToastContent, options?: Omit<ToastOptions, 'type'>): void => {\n update(content, { ...options, type: 'error' });\n };\n const warning = (content: ToastContent, options?: Omit<ToastOptions, 'type'>): void => {\n update(content, { ...options, type: 'warning' });\n };\n const information = (content: ToastContent, options?: Omit<ToastOptions, 'type'>): void => {\n update(content, { ...options, type: 'information' });\n };\n const loading = (content: ToastContent, options?: Omit<ToastOptions, 'type'>): void => {\n update(content, { ...options, type: 'loading' });\n };\n\n return {\n success,\n error,\n warning,\n information,\n loading,\n close,\n };\n }, []) as Toaster<ToastReference>;\n\n // no need to rebind these every render, do them once in an effect\n React.useEffect(() => {\n toaster.success = (content: ToastContent, options?: Omit<ToastOptions, 'type'>): ToastReference =>\n toaster(content, { autoClose: DEFAULT_AUTO_CLOSE_TIMEOUT, ...options, type: 'success' });\n toaster.error = (content: ToastContent, options?: Omit<ToastOptions, 'type'>): ToastReference =>\n toaster(content, { ...options, type: 'error' });\n toaster.warning = (content: ToastContent, options?: Omit<ToastOptions, 'type'>): ToastReference =>\n toaster(content, { ...options, type: 'warning' });\n toaster.information = (content: ToastContent, options?: Omit<ToastOptions, 'type'>): ToastReference =>\n toaster(content, { ...options, type: 'information' });\n toaster.loading = (content: ToastContent, options?: Omit<ToastOptions, 'type'>): ToastReference =>\n toaster(content, { ...options, type: 'loading' });\n }, []);\n\n return (\n <ToastContext.Provider {...props} value={toaster}>\n {children}\n <Portal>\n <div\n id=\"yt-toast__container\"\n className=\"pointer-events-all absolute !left-auto bottom-0 right-0 z-[1000] mb-4 mr-4 flex max-w-md flex-col items-end justify-end\"\n role=\"log\">\n <AnimatePresence initial={false}>\n {toasts.map((toast: InternalToast) => (\n <motion.div\n key={toast.id}\n transition={{\n type: 'spring',\n damping: 20,\n stiffness: 300,\n }}\n initial={{ opacity: 0, y: 10, scale: 0.5 }}\n animate={{ opacity: 1, y: 0, scale: 1 }}\n exit={{ opacity: 0, scale: 0.5, transition: { duration: 0.2 } }}>\n <Toast {...toast} onClose={() => handleClose(toast.id)} />\n </motion.div>\n ))}\n </AnimatePresence>\n </div>\n </Portal>\n </ToastContext.Provider>\n );\n};\n\nexport const useToast = (): Toaster<ToastReference> => React.useContext(ToastContext);\n"],"names":["DEFAULT_AUTO_CLOSE_TIMEOUT","ToastContext","React","insertToastWithoutDuplicates","currentToasts","id","content","options","close","nextToasts","existingToastIndex","findIndex","toast","JSON","stringify","lastDuplicateId","lastUpdated","Date","now","push","ToastProvider","children","props","toasts","setToasts","handleClose","filter","toaster","uuid","update","success","autoClose","type","error","warning","information","loading","Provider","value","Portal","className","role","AnimatePresence","initial","map","motion","div","key","transition","damping","stiffness","opacity","y","scale","animate","exit","duration","Toast","onClose","useToast"],"mappings":";;;;;;AAQA,MAAMA,0BAA0B,GAAG,IAAI;AA+BvC,MAAMC,YAAY,gBAAGC,aAAmB,CAA0B,EAA6B,CAAC;AAQhG,MAAMC,4BAA4B,GAAGA,CACjCC,aAA8B,EAC9BC,EAAU,EACVC,OAAqB,EACrBC,OAAqB,EACrBC,KAAiB;EAEjB,MAAMC,UAAU,GAAG,CAAC,GAAGL,aAAa,CAAC;EACrC,MAAMM,kBAAkB,GAAGN,aAAa,CAACO,SAAS,CAACC,KAAK,IAAIC,IAAI,CAACC,SAAS,CAACF,KAAK,CAACN,OAAO,CAAC,KAAKO,IAAI,CAACC,SAAS,CAACR,OAAO,CAAC,CAAC;EAEtH,IAAII,kBAAkB,GAAG,CAAC,CAAC,EAAE;IACzBD,UAAU,CAACC,kBAAkB,CAAC,CAACK,eAAe,GAAGV,EAAE;IACnDI,UAAU,CAACC,kBAAkB,CAAC,CAACM,WAAW,GAAGC,IAAI,CAACC,GAAG,EAAE;GAC1D,MAAM;IACHT,UAAU,CAACU,IAAI,CAAC;MACZd,EAAE;MACFC,OAAO,EAAE,OAAOA,OAAO,KAAK,UAAU,GAAGA,OAAO,CAACE,KAAK,CAAC,GAAGF,OAAO;MACjEC;KACH,CAAC;;EAGN,OAAOE,UAAU;AACrB,CAAC;MAEYW,aAAa,GAAGA,CAAC;EAAEC,QAAQ;EAAE,GAAGC;CAA2B;EACpE,MAAM,CAACC,MAAM,EAAEC,SAAS,CAAC,GAAGtB,QAAc,CAAkB,EAAE,CAAC;EAE/D,MAAMuB,WAAW,GAAIpB,EAAU;IAC3BmB,SAAS,CAACpB,aAAa,IAAIA,aA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E,CAAC;EAEN,oBACI9B,cAACD,YAAY,CAACoC,QAAQ,oBAAKf,KAAK;IAAEgB,KAAK,EAAEX;MACpCN,QAAQ,eACTnB,cAACqC,MAAM,qBACHrC;IACIG,EAAE,EAAC,qBAAqB;IACxBmC,SAAS,EAAC,yHAAyH;IACnIC,IAAI,EAAC;kBACLvC,cAACwC,eAAe;IAACC,OAAO,EAAE;KACrBpB,MAAM,CAACqB,GAAG,CAAEhC,KAAoB,mBAC7BV,cAAC2C,MAAM,CAACC,GAAG;IACPC,GAAG,EAAEnC,KAAK,CAACP,EAAE;IACb2C,UAAU,EAAE;MACRhB,IAAI,EAAE,QAAQ;MACdiB,OAAO,EAAE,EAAE;MACXC,SAAS,EAAE;KACd;IACDP,OAAO,EAAE;MAAEQ,OAAO,EAAE,CAAC;MAAEC,CAAC,EAAE,EAAE;MAAEC,KAAK,EAAE;KAAK;IAC1CC,OAAO,EAAE;MAAEH,OAAO,EAAE,CAAC;MAAEC,CAAC,EAAE,CAAC;MAAEC,KAAK,EAAE;KAAG;IACvCE,IAAI,EAAE;MAAEJ,OAAO,EAAE,CAAC;MAAEE,KAAK,EAAE,GAAG;MAAEL,UAAU,EAAE;QAAEQ,QAAQ,EAAE;;;kBACxDtD,cAACuD,KAAK,oBAAK7C,KAAK;IAAE8C,OAAO,EAAEA,MAAMjC,WAAW,CAACb,KAAK,CAACP,EAAE;KAAK,CACjD,CAChB,CAAC,CACY,CAChB,CACD,CACW;AAEhC;MAEasD,QAAQ,GAAGA,MAA+BzD,UAAgB,CAACD,YAAY;;;;"}
|
@@ -0,0 +1,34 @@
|
|
1
|
+
import React__default from 'react';
|
2
|
+
import cn from 'clsx';
|
3
|
+
import { Tooltip } from '../Tooltip/Tooltip.js';
|
4
|
+
import { useTruncated } from '../../utils/hooks/useTruncated.js';
|
5
|
+
|
6
|
+
const Truncate = ({
|
7
|
+
children,
|
8
|
+
tooltip
|
9
|
+
}) => {
|
10
|
+
const ref = React__default.useRef(null);
|
11
|
+
const [mounted, setMounted] = React__default.useState(false);
|
12
|
+
const {
|
13
|
+
isTruncated
|
14
|
+
} = useTruncated(ref.current, [mounted]);
|
15
|
+
React__default.useEffect(() => {
|
16
|
+
setMounted(true);
|
17
|
+
return () => setMounted(false);
|
18
|
+
}, []);
|
19
|
+
const clonedChildrenWithRef = /*#__PURE__*/React__default.cloneElement(React__default.Children.only(children), {
|
20
|
+
ref,
|
21
|
+
className: cn(children.props.className, 'truncate', {
|
22
|
+
'hover:cursor-pointer': isTruncated
|
23
|
+
})
|
24
|
+
});
|
25
|
+
if (isTruncated) {
|
26
|
+
return /*#__PURE__*/React__default.createElement(Tooltip, {
|
27
|
+
title: tooltip
|
28
|
+
}, clonedChildrenWithRef);
|
29
|
+
}
|
30
|
+
return clonedChildrenWithRef;
|
31
|
+
};
|
32
|
+
|
33
|
+
export { Truncate };
|
34
|
+
//# sourceMappingURL=Truncate.js.map
|
@@ -0,0 +1 @@
|
|
1
|
+
{"version":3,"file":"Truncate.js","sources":["../../../../../../../src/components/Truncate/Truncate.tsx"],"sourcesContent":["import React from 'react';\nimport cn from 'clsx';\n\nimport { useTruncated } from '../../utils/hooks/useTruncated';\nimport { Tooltip } from '../Tooltip/Tooltip';\n\nexport type TruncateProps = {\n children: React.ReactElement;\n tooltip: string;\n};\n\nexport const Truncate = ({ children, tooltip }: TruncateProps) => {\n const ref = React.useRef<HTMLElement>(null);\n const [mounted, setMounted] = React.useState(false);\n const { isTruncated } = useTruncated(ref.current, [mounted]);\n\n React.useEffect(() => {\n setMounted(true);\n\n return () => setMounted(false);\n }, []);\n\n const clonedChildrenWithRef = React.cloneElement(React.Children.only(children), {\n ref,\n className: cn(children.props.className, 'truncate', { 'hover:cursor-pointer': isTruncated }),\n });\n\n if (isTruncated) {\n return <Tooltip title={tooltip}>{clonedChildrenWithRef}</Tooltip>;\n }\n\n return clonedChildrenWithRef;\n};\n"],"names":["Truncate","children","tooltip","ref","React","useRef","mounted","setMounted","useState","isTruncated","useTruncated","current","useEffect","clonedChildrenWithRef","cloneElement","Children","only","className","cn","props","Tooltip","title"],"mappings":";;;;;MAWaA,QAAQ,GAAGA,CAAC;EAAEC,QAAQ;EAAEC;CAAwB;EACzD,MAAMC,GAAG,GAAGC,cAAK,CAACC,MAAM,CAAc,IAAI,CAAC;EAC3C,MAAM,CAACC,OAAO,EAAEC,UAAU,CAAC,GAAGH,cAAK,CAACI,QAAQ,CAAC,KAAK,CAAC;EACnD,MAAM;IAAEC;GAAa,GAAGC,YAAY,CAACP,GAAG,CAACQ,OAAO,EAAE,CAACL,OAAO,CAAC,CAAC;EAE5DF,cAAK,CAACQ,SAAS,CAAC;IACZL,UAAU,CAAC,IAAI,CAAC;IAEhB,OAAO,MAAMA,UAAU,CAAC,KAAK,CAAC;GACjC,EAAE,EAAE,CAAC;EAEN,MAAMM,qBAAqB,gBAAGT,cAAK,CAACU,YAAY,CAACV,cAAK,CAACW,QAAQ,CAACC,IAAI,CAACf,QAAQ,CAAC,EAAE;IAC5EE,GAAG;IACHc,SAAS,EAAEC,EAAE,CAACjB,QAAQ,CAACkB,KAAK,CAACF,SAAS,EAAE,UAAU,EAAE;MAAE,sBAAsB,EAAER;KAAa;GAC9F,CAAC;EAEF,IAAIA,WAAW,EAAE;IACb,oBAAOL,6BAACgB,OAAO;MAACC,KAAK,EAAEnB;OAAUW,qBAAqB,CAAW;;EAGrE,OAAOA,qBAAqB;AAChC;;;;"}
|
@@ -1 +1 @@
|
|
1
|
-
{"version":3,"file":"useLocalStorage.js","sources":["../../../../../../src/hooks/useLocalStorage.ts"],"sourcesContent":["import React from 'react';\n\nexport const useLocalStorage = <TType>(key?: string
|
1
|
+
{"version":3,"file":"useLocalStorage.js","sources":["../../../../../../src/hooks/useLocalStorage.ts"],"sourcesContent":["import React from 'react';\n\nexport const useLocalStorage = <TType>(\n key?: string,\n initialValue?: TType\n): [TType, React.Dispatch<React.SetStateAction<TType>>, () => void] => {\n const [state, setState] = React.useState<TType>(() => {\n if (!key) {\n return initialValue;\n }\n\n try {\n const localStorageValue = localStorage.getItem(key);\n\n if (typeof localStorageValue !== 'string') {\n localStorage.setItem(key, JSON.stringify(initialValue));\n return initialValue;\n } else {\n return JSON.parse(localStorageValue || 'null');\n }\n } catch {\n // If user is in private mode or has storage restriction\n // localStorage can throw. JSON.parse and JSON.stringify\n // can throw, too.\n return initialValue;\n }\n });\n\n React.useEffect(() => {\n if (!key) {\n return;\n }\n\n try {\n const serializedState = JSON.stringify(state);\n localStorage.setItem(key, serializedState);\n } catch {\n // If user is in private mode or has storage restriction\n // localStorage can throw. Also JSON.stringify can throw.\n }\n }, [key, state]);\n\n const clear = () => {\n if (key) {\n localStorage.removeItem(key);\n }\n };\n\n return [state, setState, clear];\n};\n"],"names":["useLocalStorage","key","initialValue","state","setState","React","useState","localStorageValue","localStorage","getItem","setItem","JSON","stringify","parse","useEffect","serializedState","clear","removeItem"],"mappings":";;MAEaA,eAAe,GAAGA,CAC3BC,GAAY,EACZC,YAAoB;EAEpB,MAAM,CAACC,KAAK,EAAEC,QAAQ,CAAC,GAAGC,cAAK,CAACC,QAAQ,CAAQ;IAC5C,IAAI,CAACL,GAAG,EAAE;MACN,OAAOC,YAAY;;IAGvB,IAAI;MACA,MAAMK,iBAAiB,GAAGC,YAAY,CAACC,OAAO,CAACR,GAAG,CAAC;MAEnD,IAAI,OAAOM,iBAAiB,KAAK,QAAQ,EAAE;QACvCC,YAAY,CAACE,OAAO,CAACT,GAAG,EAAEU,IAAI,CAACC,SAAS,CAACV,YAAY,CAAC,CAAC;QACvD,OAAOA,YAAY;OACtB,MAAM;QACH,OAAOS,IAAI,CAACE,KAAK,CAACN,iBAAiB,IAAI,MAAM,CAAC;;KAErD,CAAC,MAAM;;;;MAIJ,OAAOL,YAAY;;GAE1B,CAAC;EAEFG,cAAK,CAACS,SAAS,CAAC;IACZ,IAAI,CAACb,GAAG,EAAE;MACN;;IAGJ,IAAI;MACA,MAAMc,eAAe,GAAGJ,IAAI,CAACC,SAAS,CAACT,KAAK,CAAC;MAC7CK,YAAY,CAACE,OAAO,CAACT,GAAG,EAAEc,eAAe,CAAC;KAC7C,CAAC,MAAM;;;;GAIX,EAAE,CAACd,GAAG,EAAEE,KAAK,CAAC,CAAC;EAEhB,MAAMa,KAAK,GAAGA;IACV,IAAIf,GAAG,EAAE;MACLO,YAAY,CAACS,UAAU,CAAChB,GAAG,CAAC;;GAEnC;EAED,OAAO,CAACE,KAAK,EAAEC,QAAQ,EAAEY,KAAK,CAAC;AACnC;;;;"}
|
@@ -17,12 +17,12 @@ export { Banner } from './components/Banner/Banner.js';
|
|
17
17
|
export { Button } from './components/Button/Button.js';
|
18
18
|
export { Calendar } from './components/Calendar/Calendar.js';
|
19
19
|
export { Card } from './components/Card/Card.js';
|
20
|
+
export { Spinner } from './components/Spinner/Spinner.js';
|
20
21
|
export { Checkbox } from './components/Checkbox/Checkbox.js';
|
21
22
|
export { useBoundingClientRectListener } from './hooks/useBoundingClientRectListener.js';
|
22
23
|
export { Input } from './components/Input/Input.js';
|
23
24
|
export { getNextIndexFromKey, useListKeyboardNavigation } from './utils/hooks/useListKeyboardNavigation.js';
|
24
25
|
export { useListScrollTo } from './utils/hooks/useListScrollTo.js';
|
25
|
-
export { Spinner } from './components/Spinner/Spinner.js';
|
26
26
|
export { Combobox } from './components/Combobox/Combobox.js';
|
27
27
|
export { format, isWeakEqual, parseFromCustomString, parseFromISOString } from './utils/date.js';
|
28
28
|
export { Popover } from './components/Popover/Popover.js';
|
@@ -51,6 +51,7 @@ export { Progress } from './components/Progress/Progress.js';
|
|
51
51
|
export { ToastProvider, useToast } from './components/Toast/Toaster.js';
|
52
52
|
export { Provider, TacoContext } from './components/Provider/Provider.js';
|
53
53
|
export { FontSizes, fixedForwardRef } from './types.js';
|
54
|
+
export { DEFAULT_PAGE_SIZE, useTableDataLoader } from './primitives/Table/useTableDataLoader.js';
|
54
55
|
export { useLazyEffect } from './hooks/useLazyEffect.js';
|
55
56
|
export { SearchInput } from './components/SearchInput/SearchInput.js';
|
56
57
|
export { SearchInput2 } from './components/SearchInput2/SearchInput2.js';
|
@@ -1 +1 @@
|
|
1
|
-
{"version":3,"file":"index.js","sources":[],"sourcesContent":[],"names":[],"mappings":"
|
1
|
+
{"version":3,"file":"index.js","sources":[],"sourcesContent":[],"names":[],"mappings":";;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;"}
|
@@ -23,6 +23,7 @@ const Button = /*#__PURE__*/forwardRef(function Button(props, ref) {
|
|
23
23
|
});
|
24
24
|
const Tag = props.href ? 'a' : 'button';
|
25
25
|
return /*#__PURE__*/createElement(Tag, Object.assign({}, otherProps, {
|
26
|
+
href: disabled ? undefined : props.href,
|
26
27
|
"aria-disabled": disabled ? 'true' : undefined,
|
27
28
|
disabled: disabled,
|
28
29
|
target: Tag === 'a' ? target : undefined,
|
@@ -1 +1 @@
|
|
1
|
-
{"version":3,"file":"Button.js","sources":["../../../../../../src/primitives/Button.tsx"],"sourcesContent":["import * as React from 'react';\nimport { KeyDownHandlerOptions } from '../utils/keyboard';\nimport { useMergedRef } from '../hooks/useMergedRef';\nimport { useGlobalKeyDown } from '../hooks/useGlobalKeyDown';\n\ntype ButtonProps = React.ButtonHTMLAttributes<HTMLButtonElement | HTMLAnchorElement> & {\n /** Content should be a text */\n children: React.ReactNode;\n /** Provides url for buttons being used as a link */\n href?: string;\n shortcut?: string | KeyDownHandlerOptions;\n /** Provides target for buttons being used as a link */\n target?: '_self' | '_blank' | '_parent' | '_top';\n};\n\nconst Button = React.forwardRef(function Button(props: ButtonProps, ref: React.Ref<HTMLButtonElement | HTMLAnchorElement>) {\n const { disabled, shortcut, target, type = 'button', ...otherProps } = props;\n const internalRef = useMergedRef<HTMLButtonElement | HTMLAnchorElement>(ref);\n\n useGlobalKeyDown(shortcut, event => {\n event?.preventDefault();\n const dialog = document.querySelector('[role=\"dialog\"]');\n\n // Don't trigger the click on the button if it is outside of the dialog\n if (dialog && !dialog?.contains(internalRef.current)) {\n return;\n }\n\n internalRef.current?.click();\n });\n\n const Tag = props.href ? 'a' : 'button';\n\n return (\n <Tag\n {...otherProps}\n aria-disabled={disabled ? 'true' : undefined}\n disabled={disabled}\n target={Tag === 'a' ? target : undefined}\n type={Tag !== 'a' ? type : undefined}\n ref={internalRef as any}>\n {React.Children.count(props.children) > 1\n ? React.Children.map(props.children, child => (typeof child === 'string' ? <span>{child}</span> : child))\n : props.children}\n </Tag>\n );\n});\n\nexport { Button };\nexport type { ButtonProps };\n"],"names":["Button","React","props","ref","disabled","shortcut","target","type","otherProps","internalRef","useMergedRef","useGlobalKeyDown","event","preventDefault","dialog","document","querySelector","contains","current","_internalRef$current","click","Tag","href","undefined","count","children","map","child"],"mappings":";;;;MAeMA,MAAM,gBAAGC,UAAgB,CAAC,SAASD,MAAMA,CAACE,KAAkB,EAAEC,GAAqD;EACrH,MAAM;IAAEC,QAAQ;IAAEC,QAAQ;IAAEC,MAAM;IAAEC,IAAI,GAAG,QAAQ;IAAE,GAAGC;GAAY,GAAGN,KAAK;EAC5E,MAAMO,WAAW,GAAGC,YAAY,CAAwCP,GAAG,CAAC;EAE5EQ,gBAAgB,CAACN,QAAQ,EAAEO,KAAK;;IAC5BA,KAAK,aAALA,KAAK,uBAALA,KAAK,CAAEC,cAAc,EAAE;IACvB,MAAMC,MAAM,GAAGC,QAAQ,CAACC,aAAa,CAAC,iBAAiB,CAAC;;IAGxD,IAAIF,MAAM,IAAI,EAACA,MAAM,aAANA,MAAM,eAANA,MAAM,CAAEG,QAAQ,CAACR,WAAW,CAACS,OAAO,CAAC,GAAE;MAClD;;IAGJ,CAAAC,oBAAA,GAAAV,WAAW,CAACS,OAAO,cAAAC,oBAAA,uBAAnBA,oBAAA,CAAqBC,KAAK,EAAE;GAC/B,CAAC;EAEF,MAAMC,GAAG,GAAGnB,KAAK,CAACoB,IAAI,GAAG,GAAG,GAAG,QAAQ;EAEvC,oBACIrB,cAACoB,GAAG,oBACIb,UAAU;
|
1
|
+
{"version":3,"file":"Button.js","sources":["../../../../../../src/primitives/Button.tsx"],"sourcesContent":["import * as React from 'react';\nimport { KeyDownHandlerOptions } from '../utils/keyboard';\nimport { useMergedRef } from '../hooks/useMergedRef';\nimport { useGlobalKeyDown } from '../hooks/useGlobalKeyDown';\n\ntype ButtonProps = React.ButtonHTMLAttributes<HTMLButtonElement | HTMLAnchorElement> & {\n /** Content should be a text */\n children: React.ReactNode;\n /** Provides url for buttons being used as a link */\n href?: string;\n shortcut?: string | KeyDownHandlerOptions;\n /** Provides target for buttons being used as a link */\n target?: '_self' | '_blank' | '_parent' | '_top';\n};\n\nconst Button = React.forwardRef(function Button(props: ButtonProps, ref: React.Ref<HTMLButtonElement | HTMLAnchorElement>) {\n const { disabled, shortcut, target, type = 'button', ...otherProps } = props;\n const internalRef = useMergedRef<HTMLButtonElement | HTMLAnchorElement>(ref);\n\n useGlobalKeyDown(shortcut, event => {\n event?.preventDefault();\n const dialog = document.querySelector('[role=\"dialog\"]');\n\n // Don't trigger the click on the button if it is outside of the dialog\n if (dialog && !dialog?.contains(internalRef.current)) {\n return;\n }\n\n internalRef.current?.click();\n });\n\n const Tag = props.href ? 'a' : 'button';\n\n return (\n <Tag\n {...otherProps}\n href={disabled ? undefined : props.href}\n aria-disabled={disabled ? 'true' : undefined}\n disabled={disabled}\n target={Tag === 'a' ? target : undefined}\n type={Tag !== 'a' ? type : undefined}\n ref={internalRef as any}>\n {React.Children.count(props.children) > 1\n ? React.Children.map(props.children, child => (typeof child === 'string' ? <span>{child}</span> : child))\n : props.children}\n </Tag>\n );\n});\n\nexport { Button };\nexport type { ButtonProps };\n"],"names":["Button","React","props","ref","disabled","shortcut","target","type","otherProps","internalRef","useMergedRef","useGlobalKeyDown","event","preventDefault","dialog","document","querySelector","contains","current","_internalRef$current","click","Tag","href","undefined","count","children","map","child"],"mappings":";;;;MAeMA,MAAM,gBAAGC,UAAgB,CAAC,SAASD,MAAMA,CAACE,K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zB,KAAK,CAACuB,QAAQ,CAClB;AAEd,CAAC;;;;"}
|
@@ -1 +1 @@
|
|
1
|
-
{"version":3,"file":"types.js","sources":["../../../../../../../src/primitives/Table/types.ts"],"sourcesContent":["import {\n ColumnFilter as ReactTableColumnFilter,\n ColumnFiltersState as ReactTableColumnFilterState,\n ColumnOrderState as ReactTableColumnOrderState,\n ColumnPinningState as ReactTableColumnPinningState,\n ColumnSort as ReactTableColumnSort,\n ColumnSizingState as ReactTableColumnSizingState,\n GroupingState as ReactTableGroupingState,\n VisibilityState as ReactTableColumnVisibilityState,\n SortingState as ReactTableSortingState,\n BuiltInAggregationFn as ReactTableBuiltInAggregationFn,\n BuiltInSortingFn as ReactTableBuiltInSortingFn,\n HeaderContext as ReactTableHeaderContext,\n CellContext as ReactTableCellContext,\n ColumnMeta as ReactTableColumnMeta,\n} from '@tanstack/react-table';\nimport { FontSize, FontSizes, ValueOf } from '../../types';\nimport { MenuProps } from '../../components/Menu/Menu';\n\ntype TODO = any;\n\nexport type TableRef = HTMLTableElement & {\n instance: {\n resetFiltering: () => void;\n resetRowExpansion: () => void;\n resetRowSelection: () => void;\n resetSorting: () => void;\n };\n};\n\n// filtering\nexport enum TableFilterComparator {\n Contains,\n DoesNotContain,\n IsEqualTo,\n IsNotEqualTo,\n IsGreaterThan,\n IsLessThan,\n IsBetween,\n IsEmpty,\n IsNotEmpty,\n IsLessThanOrEqualTo,\n IsGreaterThanOrEqualTo,\n HasAnyOf,\n HasAllOf,\n HasNoneOf,\n}\nexport type TableFilterValue = {\n comparator: TableFilterComparator;\n value: any;\n};\nexport type TableFilter = {\n id: string;\n value: TableFilterValue;\n};\n\n// columns\nexport type TableColumnAlignment = 'left' | 'center' | 'right';\nexport type TableColumnClassNameHandler<TType = unknown> = string | ((row: TType) => string | undefined);\nexport type TableColumnDataType = 'auto' | 'number' | 'alphanumeric' | 'alphanumericCaseSensitive' | 'datetime' | 'boolean';\nexport type TableColumnFilter = ReactTableColumnFilter;\nexport type TableColumnMenu = (props: Partial<MenuProps>) => JSX.Element;\nexport type TableColumnRenderer<TType, TValue> = (value: TValue, row: TType) => JSX.Element | string | number | null;\nexport type TableColumnRendererAggregate<TType, TValue> = (value: TValue, row: TType) => JSX.Element | string | number | null;\nexport type TableColumnRendererControl<TType = unknown> =\n | ((props: TableColumnRendererControlProps, row?: TType) => JSX.Element)\n | 'datepicker'\n | 'input'\n | 'switch'\n | 'textarea';\nexport type TableColumnRendererControlProps = {\n className?: string;\n disabled?: boolean;\n fontSize?: FontSize;\n invalid?: boolean;\n onBlur?: (value: any) => void;\n onFocus?: React.FocusEventHandler;\n readOnly?: boolean;\n ref: React.RefObject<HTMLElement> | ((instance: HTMLElement | null | undefined) => void);\n setValue: (value: any) => void;\n value: any;\n};\nexport type TableColumnRendererHeader = string;\nexport type TableColumnRendererFooter<TValue> = (values: TValue[]) => JSX.Element | string | number | null;\nexport type TableColumnSort = ReactTableColumnSort;\nexport type TableColumnSortDirection = 'asc' | 'desc';\nexport type TableColumnSortFn<TType = unknown> =\n | ((rowA: TType, rowB: TType, columnId: string) => -1 | 0 | 1)\n | ReactTableBuiltInSortingFn\n | 'auto';\nexport type TableColumnWidth = number | 'grow';\n\n// rows\nexport type TableRowActionRenderer<TType = unknown> = (row: TType) => JSX.Element | null;\nexport type TableRowActionGroupRenderer<TType = unknown> = (rows: TType[]) => JSX.Element | null;\nexport type TableRowClickHandler<TType = unknown> = (row: TType) => void;\nexport type TableRowGotoHandler = (\n column: string,\n query: string,\n sorting: TableColumnSort[],\n filters: TableColumnFilter[],\n search: string | undefined\n) => Promise<number>;\nexport type TableRowHeight = 'short' | 'medium' | 'tall' | 'extra-tall';\nexport type TableRowSelectHandler<TType = unknown> = (rows: TType[]) => void;\n\n// shortcuts\nexport type TableShortcutHandlerFn<TType = unknown> = (row: TType) => void;\nexport type TableShortcutHandlerObject<TType = unknown> = {\n handler: TableShortcutHandlerFn<TType>;\n meta?: boolean;\n shift?: boolean;\n};\n\n// table\nexport type TableFilterHandler = (filters: TableColumnFilter[]) => void;\nexport type TableFontSize = keyof typeof FontSizes;\nexport type TablePreset = 'lite' | 'complex';\nexport type TableRowExpansionRenderer<TType = unknown> = (row: TType) => (() => JSX.Element) | null;\nexport type TableScrollToIndexHandler = (index: number, options?: { align: 'start' | 'center' | 'end' | 'auto' }) => void;\nexport type TableServerLoadPageHandler = (\n pageIndex: number,\n sorting: TableColumnSort[],\n filters: TableColumnFilter[],\n search: string | undefined\n) => Promise<void>;\nexport type TableServerLoadAllHandler = (\n sorting: TableColumnSort[],\n filters: TableColumnFilter[],\n search: string | undefined\n) => Promise<void>;\nexport enum TableServerLoadAllState {\n Incomplete,\n Loading,\n Completed,\n}\nexport type TableSettingsHandler = (settings: TableSettings) => void | Promise<void>;\nexport type TableShortcuts<TType = unknown> = Record<string, TableShortcutHandlerFn<TType> | TableShortcutHandlerObject<TType>>;\nexport type TableSortHandler = (sorting: TableColumnSort[]) => void;\n\n// settings\nexport type TableSettings = {\n columnFilters?: ReactTableColumnFilterState;\n columnOrder?: ReactTableColumnOrderState;\n columnPinning?: ReactTableColumnPinningState;\n columnSizing?: ReactTableColumnSizingState;\n columnVisibility?: ReactTableColumnVisibilityState;\n excludeUnmatchedRecordsInSearch?: boolean;\n fontSize?: TableFontSize;\n grouping?: ReactTableGroupingState;\n rowHeight?: TableRowHeight;\n showWarningWhenPrintingLargeDataset?: boolean;\n searchQuery?: string;\n sorting?: ReactTableSortingState;\n};\n\n// props\nexport type TableFeatureProps = {\n // react-table built-in\n enableFiltering?: boolean;\n enableSearch?: boolean;\n enableSorting?: boolean;\n enableColumnFreezing?: boolean;\n enableColumnHiding?: boolean;\n enableColumnResizing?: boolean;\n enableRowExpansion?: boolean;\n enableRowSelection?: boolean;\n enableRowSelectionSingle?: boolean;\n\n // custom -- common between all table types\n enableColumnOrdering?: boolean;\n enableFontSize?: boolean;\n enableFooter?: boolean;\n enablePrinting?: boolean;\n enableRowActions?: boolean;\n enableRowActive?: boolean;\n enableRowClick?: boolean;\n enableRowGoto?: boolean;\n enableRowHeight?: boolean;\n enableSettings?: boolean;\n /*\n\n | {\n columnOrder: boolean;\n columnPinning: boolean;\n columnSizing: boolean;\n columnVisibility: boolean;\n fontSize: boolean;\n grouping: boolean;\n rowHeight: boolean;\n sorting: boolean;\n };\n */\n};\n\nexport type useTableInternalColumn<TType = unknown> = {\n header?: (info: ReactTableHeaderContext<TType, unknown>) => JSX.Element | string | null;\n renderer: (info: ReactTableCellContext<TType, unknown>) => JSX.Element | string | null;\n meta?: ReactTableColumnMeta<TType, unknown>;\n size?: number;\n};\n\nexport type useTableInternalColumns<TType = unknown> = {\n rowActions?: useTableInternalColumn<TType>;\n rowExpansion?: useTableInternalColumn<TType>;\n rowSelection?: useTableInternalColumn<TType>;\n};\n\ntype useTableCommonProps<TType = unknown> = TableFeatureProps & {\n children: (JSX.Element | boolean | null | undefined)[];\n data: TType[];\n id: string;\n\n // misc\n defaultColumnFreezingIndex?: number;\n defaultRowActiveIndex?: number;\n defaultRowGroupColumnId?: keyof TType;\n defaultSettings?: TableSettings;\n preset?: TablePreset;\n rowActions?: TableRowActionRenderer<TType>[];\n rowActionsForGroup?: TableRowActionGroupRenderer<TType>[];\n rowActionsLength?: number;\n rowExpansionRenderer?: TableRowExpansionRenderer<TType>;\n shortcuts?: TableShortcuts<TType>;\n\n // handlers\n onRowClick?: TableRowClickHandler<TType>;\n onRowGoto?: TableRowGotoHandler;\n onRowSelect?: TableRowSelectHandler<TType>;\n\n // state change handlers\n onChangeFilter?: TableFilterHandler;\n onChangeSearch?: TODO; // not currently supported\n onChangeSettings?: TableSettingsHandler;\n onChangeSort?: TableSortHandler;\n};\n\nexport interface useTableClientProps<TType = unknown> extends useTableCommonProps<TType> {\n length?: never;\n loadAll?: never;\n loadPage?: never;\n pageSize?: never;\n}\n\nexport interface useTableServerProps<TType = unknown> extends useTableCommonProps<TType> {\n length: number | undefined;\n loadAll: TableServerLoadAllHandler;\n loadPage: TableServerLoadPageHandler;\n pageSize?: number;\n}\n\nexport type useTableProps<TType = unknown> = useTableClientProps<TType> | useTableServerProps<TType>;\n\nexport type TableColumnProps<TType = unknown> = ValueOf<{\n [Key in keyof TType]: {\n accessor?: Key;\n id: string;\n } & {\n // renderers\n renderer?: TableColumnRenderer<TType, TType[Key]>;\n /** Renderer to use if the cell is an aggregate cell and part of a grouped row */\n aggregate?: TableColumnRendererAggregate<TType, TType[Key]>;\n control?: TableColumnRendererControl<TType>;\n footer?: TableColumnRendererFooter<TType[Key]>;\n header: TableColumnRendererHeader;\n // options\n /** Aggregation function to be used when the column is part of a grouped row */\n aggregationFn?: 'auto' | ReactTableBuiltInAggregationFn;\n align?: TableColumnAlignment;\n className?: TableColumnClassNameHandler<TType>;\n dataType?: TableColumnDataType;\n defaultHidden?: boolean;\n defaultWidth?: TableColumnWidth;\n enableFiltering?: boolean;\n enableGrouping?: boolean;\n enableHiding?: boolean;\n enableOrdering?: boolean;\n enablePrinting?: boolean;\n enableResizing?: boolean;\n enableSearch?: boolean;\n enableSorting?: boolean;\n enableTruncate?: boolean;\n filters?: TableFilterComparator[];\n headerClassName?: string;\n menu?: TableColumnMenu;\n minWidth?: number;\n sort?: TableColumnSortDirection;\n sortFn?: TableColumnSortFn<TType>;\n tooltip?: string;\n };\n}>;\n\nexport type TableGroupProps = {\n children: (JSX.Element | boolean | null | undefined)[];\n header: string;\n id: string;\n};\n"],"names":["TableFilterComparator","TableServerLoadAllState"],"mappings":"AA8BA;IACYA;AAAZ,WAAYA,qBAAqB;EAC7BA,yEAAQ;EACRA,qFAAc;EACdA,2EAAS;EACTA,iFAAY;EACZA,mFAAa;EACbA,6EAAU;EACVA,2EAAS;EACTA,uEAAO;EACPA,6EAAU;EACVA,+FAAmB;EACnBA,sGAAsB;EACtBA,0EAAQ;EACRA,0EAAQ;EACRA,4EAAS;AACb,CAAC,EAfWA,qBAAqB,KAArBA,qBAAqB;IAoGrBC;AAAZ,WAAYA,uBAAuB;EAC/BA,iFAAU;EACVA,2EAAO;EACPA,+EAAS;AACb,CAAC,EAJWA,uBAAuB,KAAvBA,uBAAuB;;;;"}
|
1
|
+
{"version":3,"file":"types.js","sources":["../../../../../../../src/primitives/Table/types.ts"],"sourcesContent":["import {\n ColumnFilter as ReactTableColumnFilter,\n ColumnFiltersState as ReactTableColumnFilterState,\n ColumnOrderState as ReactTableColumnOrderState,\n ColumnPinningState as ReactTableColumnPinningState,\n ColumnSort as ReactTableColumnSort,\n ColumnSizingState as ReactTableColumnSizingState,\n GroupingState as ReactTableGroupingState,\n VisibilityState as ReactTableColumnVisibilityState,\n SortingState as ReactTableSortingState,\n BuiltInAggregationFn as ReactTableBuiltInAggregationFn,\n BuiltInSortingFn as ReactTableBuiltInSortingFn,\n HeaderContext as ReactTableHeaderContext,\n CellContext as ReactTableCellContext,\n ColumnMeta as ReactTableColumnMeta,\n} from '@tanstack/react-table';\nimport { FontSize, FontSizes, ValueOf } from '../../types';\nimport { MenuProps } from '../../components/Menu/Menu';\n\ntype TODO = any;\n\nexport type TableRef = HTMLTableElement & {\n instance: {\n resetFiltering: () => void;\n resetRowExpansion: () => void;\n resetRowSelection: () => void;\n resetSorting: () => void;\n };\n};\n\n// filtering\nexport enum TableFilterComparator {\n Contains,\n DoesNotContain,\n IsEqualTo,\n IsNotEqualTo,\n IsGreaterThan,\n IsLessThan,\n IsBetween,\n IsEmpty,\n IsNotEmpty,\n IsLessThanOrEqualTo,\n IsGreaterThanOrEqualTo,\n HasAnyOf,\n HasAllOf,\n HasNoneOf,\n}\nexport type TableFilterValue = {\n comparator: TableFilterComparator;\n value: any;\n};\nexport type TableFilter = {\n id: string;\n value: TableFilterValue;\n};\n\n// columns\nexport type TableColumnAlignment = 'left' | 'center' | 'right';\nexport type TableColumnClassNameHandler<TType = unknown> = string | ((row: TType) => string | undefined);\nexport type TableColumnDataType = 'auto' | 'number' | 'alphanumeric' | 'alphanumericCaseSensitive' | 'datetime' | 'boolean';\nexport type TableColumnFilter = ReactTableColumnFilter;\nexport type TableColumnMenu = (props: Partial<MenuProps>) => JSX.Element;\nexport type TableColumnRenderer<TType, TValue> = (value: TValue, row: TType) => JSX.Element | string | number | null;\nexport type TableColumnRendererAggregate<TType, TValue> = (value: TValue, row: TType) => JSX.Element | string | number | null;\nexport type TableColumnRendererControl<TType = unknown> =\n | ((props: TableColumnRendererControlProps, row?: TType) => JSX.Element)\n | 'datepicker'\n | 'input'\n | 'switch'\n | 'textarea';\nexport type TableColumnRendererControlProps = {\n className?: string;\n disabled?: boolean;\n fontSize?: FontSize;\n invalid?: boolean;\n onBlur?: (value: any) => void;\n onFocus?: React.FocusEventHandler;\n readOnly?: boolean;\n ref: React.RefObject<HTMLElement> | ((instance: HTMLElement | null | undefined) => void);\n setValue: (value: any) => void;\n value: any;\n};\nexport type TableColumnRendererHeader = string;\nexport type TableColumnRendererFooter<TValue> = (values: TValue[]) => JSX.Element | string | number | null;\nexport type TableColumnSort = ReactTableColumnSort;\nexport type TableColumnSortDirection = 'asc' | 'desc';\nexport type TableColumnSortFn<TType = unknown> =\n | ((rowA: TType, rowB: TType, columnId: string) => -1 | 0 | 1)\n | ReactTableBuiltInSortingFn\n | 'auto';\nexport type TableColumnWidth = number | 'grow';\n\n// rows\nexport type TableRowActionRenderer<TType = unknown> = (row: TType) => JSX.Element | null;\nexport type TableRowActionGroupRenderer<TType = unknown> = (rows: TType[]) => JSX.Element | null;\nexport type TableRowClickHandler<TType = unknown> = (row: TType) => void;\nexport type TableRowGotoHandler = (\n column: string,\n query: string,\n sorting: TableColumnSort[],\n filters: TableColumnFilter[],\n search: string | undefined\n) => Promise<number>;\nexport type TableRowHeight = 'short' | 'medium' | 'tall' | 'extra-tall';\nexport type TableRowSelectHandler<TType = unknown> = (rows: TType[]) => void;\n\n// shortcuts\nexport type TableShortcutHandlerFn<TType = unknown> = (row: TType) => void;\nexport type TableShortcutHandlerObject<TType = unknown> = {\n handler: TableShortcutHandlerFn<TType>;\n meta?: boolean;\n shift?: boolean;\n};\n\n// table\nexport type TableFilterHandler = (filters: TableColumnFilter[]) => void;\nexport type TableFontSize = keyof typeof FontSizes;\nexport type TablePreset = 'lite' | 'complex';\nexport type TableRowExpansionRenderer<TType = unknown> = (row: TType) => (() => JSX.Element) | null;\nexport type TableScrollToIndexHandler = (index: number, options?: { align: 'start' | 'center' | 'end' | 'auto' }) => void;\nexport type TableServerLoadPageHandler = (\n pageIndex: number,\n sorting: TableColumnSort[],\n filters: TableColumnFilter[],\n search: string | undefined\n) => Promise<void>;\nexport type TableServerLoadAllHandler = (\n sorting: TableColumnSort[],\n filters: TableColumnFilter[],\n search: string | undefined\n) => Promise<void>;\nexport enum TableServerLoadAllState {\n Incomplete,\n Loading,\n Completed,\n}\nexport type TableSettingsHandler = (settings: TableSettings) => void | Promise<void>;\nexport type TableShortcuts<TType = unknown> = Record<string, TableShortcutHandlerFn<TType> | TableShortcutHandlerObject<TType>>;\nexport type TableSortHandler = (sorting: TableColumnSort[]) => void;\n\n// settings\nexport type TableSettings = {\n columnFilters?: ReactTableColumnFilterState;\n columnOrder?: ReactTableColumnOrderState;\n columnPinning?: ReactTableColumnPinningState;\n columnSizing?: ReactTableColumnSizingState;\n columnVisibility?: ReactTableColumnVisibilityState;\n excludeUnmatchedRecordsInSearch?: boolean;\n fontSize?: TableFontSize;\n grouping?: ReactTableGroupingState;\n rowHeight?: TableRowHeight;\n searchQuery?: string;\n sorting?: ReactTableSortingState;\n};\nexport type EnableSettingsOptions = {\n columnOrder: boolean;\n columnPinning: boolean;\n columnSizing: boolean;\n columnVisibility: boolean;\n excludeUnmatchedRecordsInSearch: boolean;\n fontSize: boolean;\n grouping: boolean;\n rowHeight: boolean;\n sorting: boolean;\n};\n\n// props\nexport type TableFeatureProps = {\n // react-table built-in\n enableFiltering?: boolean;\n enableSearch?: boolean;\n enableSorting?: boolean;\n enableColumnFreezing?: boolean;\n enableColumnHiding?: boolean;\n enableColumnResizing?: boolean;\n enableRowExpansion?: boolean;\n enableRowSelection?: boolean;\n enableRowSelectionSingle?: boolean;\n\n // custom -- common between all table types\n enableColumnOrdering?: boolean;\n enableFontSize?: boolean;\n enableFooter?: boolean;\n enablePrinting?: boolean;\n enableRowActions?: boolean;\n enableRowActive?: boolean;\n enableRowClick?: boolean;\n enableRowGoto?: boolean;\n enableRowHeight?: boolean;\n enableSaveSettings?: boolean | Partial<EnableSettingsOptions>;\n};\n\nexport type useTableInternalColumn<TType = unknown> = {\n header?: (info: ReactTableHeaderContext<TType, unknown>) => JSX.Element | string | null;\n renderer: (info: ReactTableCellContext<TType, unknown>) => JSX.Element | string | null;\n meta?: ReactTableColumnMeta<TType, unknown>;\n size?: number;\n};\n\nexport type useTableInternalColumns<TType = unknown> = {\n rowActions?: useTableInternalColumn<TType>;\n rowExpansion?: useTableInternalColumn<TType>;\n rowSelection?: useTableInternalColumn<TType>;\n};\n\ntype useTableCommonProps<TType = unknown> = TableFeatureProps & {\n children: (JSX.Element | boolean | null | undefined)[];\n data: TType[];\n id: string;\n\n // misc\n defaultColumnFreezingIndex?: number;\n defaultRowActiveIndex?: number;\n defaultRowGroupColumnId?: keyof TType;\n defaultSettings?: TableSettings;\n preset?: TablePreset;\n rowActions?: TableRowActionRenderer<TType>[];\n rowActionsForGroup?: TableRowActionGroupRenderer<TType>[];\n rowActionsLength?: number;\n rowExpansionRenderer?: TableRowExpansionRenderer<TType>;\n shortcuts?: TableShortcuts<TType>;\n\n // handlers\n onRowClick?: TableRowClickHandler<TType>;\n onRowGoto?: TableRowGotoHandler;\n onRowSelect?: TableRowSelectHandler<TType>;\n\n // state change handlers\n onChangeFilter?: TableFilterHandler;\n onChangeSearch?: TODO; // not currently supported\n onChangeSettings?: TableSettingsHandler;\n onChangeSort?: TableSortHandler;\n};\n\nexport interface useTableClientProps<TType = unknown> extends useTableCommonProps<TType> {\n length?: never;\n loadAll?: never;\n loadPage?: never;\n pageSize?: never;\n}\n\nexport interface useTableServerProps<TType = unknown> extends useTableCommonProps<TType> {\n length: number | undefined;\n loadAll: TableServerLoadAllHandler;\n loadPage: TableServerLoadPageHandler;\n pageSize?: number;\n}\n\nexport type useTableProps<TType = unknown> = useTableClientProps<TType> | useTableServerProps<TType>;\n\nexport type TableColumnProps<TType = unknown> = ValueOf<{\n [Key in keyof TType]: {\n accessor?: Key;\n id: string;\n } & {\n // renderers\n renderer?: TableColumnRenderer<TType, TType[Key]>;\n /** Renderer to use if the cell is an aggregate cell and part of a grouped row */\n aggregate?: TableColumnRendererAggregate<TType, TType[Key]>;\n control?: TableColumnRendererControl<TType>;\n footer?: TableColumnRendererFooter<TType[Key]>;\n header: TableColumnRendererHeader;\n // options\n /** Aggregation function to be used when the column is part of a grouped row */\n aggregationFn?: 'auto' | ReactTableBuiltInAggregationFn;\n align?: TableColumnAlignment;\n className?: TableColumnClassNameHandler<TType>;\n dataType?: TableColumnDataType;\n defaultHidden?: boolean;\n defaultWidth?: TableColumnWidth;\n enableFiltering?: boolean;\n enableGrouping?: boolean;\n enableHiding?: boolean;\n enableOrdering?: boolean;\n enablePrinting?: boolean;\n enableResizing?: boolean;\n enableSearch?: boolean;\n enableSorting?: boolean;\n enableTruncate?: boolean;\n filters?: TableFilterComparator[];\n headerClassName?: string;\n menu?: TableColumnMenu;\n minWidth?: number;\n sort?: TableColumnSortDirection;\n sortFn?: TableColumnSortFn<TType>;\n tooltip?: string;\n };\n}>;\n\nexport type TableGroupProps = {\n children: (JSX.Element | boolean | null | undefined)[];\n header: string;\n id: string;\n};\n"],"names":["TableFilterComparator","TableServerLoadAllState"],"mappings":"AA8BA;IACYA;AAAZ,WAAYA,qBAAqB;EAC7BA,yEAAQ;EACRA,qFAAc;EACdA,2EAAS;EACTA,iFAAY;EACZA,mFAAa;EACbA,6EAAU;EACVA,2EAAS;EACTA,uEAAO;EACPA,6EAAU;EACVA,+FAAmB;EACnBA,sGAAsB;EACtBA,0EAAQ;EACRA,0EAAQ;EACRA,4EAAS;AACb,CAAC,EAfWA,qBAAqB,KAArBA,qBAAqB;IAoGrBC;AAAZ,WAAYA,uBAAuB;EAC/BA,iFAAU;EACVA,2EAAO;EACPA,+EAAS;AACb,CAAC,EAJWA,uBAAuB,KAAvBA,uBAAuB;;;;"}
|
@@ -1,16 +1,36 @@
|
|
1
1
|
import React__default from 'react';
|
2
|
+
import { useTacoSettings } from '../../../../hooks/useTacoSettings.js';
|
3
|
+
import { useLocalStorage } from '../../../../hooks/useLocalStorage.js';
|
2
4
|
|
3
|
-
function useTablePrinting(isEnabled = false,
|
5
|
+
function useTablePrinting(isEnabled = false, tableId) {
|
4
6
|
const [isPrinting, setIsPrinting] = React__default.useState(false);
|
5
|
-
const [
|
7
|
+
const [settings, setSetting] = useTablePrintingSettings(tableId);
|
6
8
|
return {
|
7
9
|
isEnabled,
|
8
10
|
isPrinting,
|
9
11
|
setIsPrinting,
|
10
|
-
|
11
|
-
|
12
|
+
settings,
|
13
|
+
setSetting
|
12
14
|
};
|
13
15
|
}
|
16
|
+
const DEFAULT_PRINT_SETTINGS = {
|
17
|
+
size: 'A4',
|
18
|
+
orientation: 'portrait',
|
19
|
+
allRows: true,
|
20
|
+
splitGroups: true
|
21
|
+
};
|
22
|
+
function useTablePrintingSettings(tableId) {
|
23
|
+
const tacoSettings = useTacoSettings();
|
24
|
+
const uniqueId = `taco.${tacoSettings.uniqueUserIdentifier}.table.${tableId}.print.settings`;
|
25
|
+
const [persistedSettings, setPersistedSettings] = useLocalStorage(uniqueId, DEFAULT_PRINT_SETTINGS);
|
26
|
+
function setSetting(key, value) {
|
27
|
+
setPersistedSettings(currentSettings => ({
|
28
|
+
...currentSettings,
|
29
|
+
[key]: value
|
30
|
+
}));
|
31
|
+
}
|
32
|
+
return [persistedSettings, setSetting];
|
33
|
+
}
|
14
34
|
|
15
35
|
export { useTablePrinting };
|
16
36
|
//# sourceMappingURL=useTablePrinting.js.map
|
package/dist/esm/packages/taco/src/primitives/Table/useTable/features/useTablePrinting.js.map
CHANGED
@@ -1 +1 @@
|
|
1
|
-
{"version":3,"file":"useTablePrinting.js","sources":["../../../../../../../../../src/primitives/Table/useTable/features/useTablePrinting.ts"],"sourcesContent":["import React from 'react';\n\nexport function useTablePrinting(isEnabled = false,
|
1
|
+
{"version":3,"file":"useTablePrinting.js","sources":["../../../../../../../../../src/primitives/Table/useTable/features/useTablePrinting.ts"],"sourcesContent":["import React from 'react';\nimport { useTacoSettings } from '../../../../hooks/useTacoSettings';\nimport { useLocalStorage } from '../../../../hooks/useLocalStorage';\n\ntype TablePrintSettings = {\n allRows: boolean;\n orientation: 'portrait' | 'landscape';\n size: 'A3' | 'A4' | 'A5' | 'letter' | 'legal';\n splitGroups: boolean;\n};\n\nexport function useTablePrinting(isEnabled = false, tableId: string) {\n const [isPrinting, setIsPrinting] = React.useState(false);\n const [settings, setSetting] = useTablePrintingSettings(tableId);\n\n return {\n isEnabled,\n isPrinting,\n setIsPrinting,\n settings,\n setSetting,\n };\n}\n\nconst DEFAULT_PRINT_SETTINGS: TablePrintSettings = {\n size: 'A4',\n orientation: 'portrait',\n allRows: true,\n splitGroups: true,\n};\n\nfunction useTablePrintingSettings(tableId: string): [TablePrintSettings, (key: keyof TablePrintSettings, value: any) => void] {\n const tacoSettings = useTacoSettings();\n const uniqueId = `taco.${tacoSettings.uniqueUserIdentifier}.table.${tableId}.print.settings`;\n\n const [persistedSettings, setPersistedSettings] = useLocalStorage<TablePrintSettings>(uniqueId, DEFAULT_PRINT_SETTINGS);\n\n function setSetting(key: keyof TablePrintSettings, value: any) {\n setPersistedSettings(currentSettings => ({\n ...currentSettings,\n [key]: value,\n }));\n }\n\n return [persistedSettings, setSetting];\n}\n"],"names":["useTablePrinting","isEnabled","tableId","isPrinting","setIsPrinting","React","useState","settings","setSetting","useTablePrintingSettings","DEFAULT_PRINT_SETTINGS","size","orientation","allRows","splitGroups","tacoSettings","useTacoSettings","uniqueId","uniqueUserIdentifier","persistedSettings","setPersistedSettings","useLocalStorage","key","value","currentSettings"],"mappings":";;;;SAWgBA,gBAAgBA,CAACC,SAAS,GAAG,KAAK,EAAEC,OAAe;EAC/D,MAAM,CAACC,UAAU,EAAEC,aAAa,CAAC,GAAGC,cAAK,CAACC,QAAQ,CAAC,KAAK,CAAC;EACzD,MAAM,CAACC,QAAQ,EAAEC,UAAU,CAAC,GAAGC,wBAAwB,CAACP,OAAO,CAAC;EAEhE,OAAO;IACHD,SAAS;IACTE,UAAU;IACVC,aAAa;IACbG,QAAQ;IACRC;GACH;AACL;AAEA,MAAME,sBAAsB,GAAuB;EAC/CC,IAAI,EAAE,IAAI;EACVC,WAAW,EAAE,UAAU;EACvBC,OAAO,EAAE,IAAI;EACbC,WAAW,EAAE;CAChB;AAED,SAASL,wBAAwBA,CAACP,OAAe;EAC7C,MAAMa,YAAY,GAAGC,eAAe,EAAE;EACtC,MAAMC,QAAQ,WAAWF,YAAY,CAACG,8BAA8BhB,wBAAwB;EAE5F,MAAM,CAACiB,iBAAiB,EAAEC,oBAAoB,CAAC,GAAGC,eAAe,CAAqBJ,QAAQ,EAAEP,sBAAsB,CAAC;EAEvH,SAASF,UAAUA,CAACc,GAA6B,EAAEC,KAAU;IACzDH,oBAAoB,CAACI,eAAe,KAAK;MACrC,GAAGA,eAAe;MAClB,CAACF,GAAG,GAAGC;KACV,CAAC,CAAC;;EAGP,OAAO,CAACJ,iBAAiB,EAAEX,UAAU,CAAC;AAC1C;;;;"}
|
@@ -1,28 +1,69 @@
|
|
1
1
|
import React__default from 'react';
|
2
|
-
import { useLocalStorage } from '../../../../hooks/useLocalStorage.js';
|
3
2
|
import { useTacoSettings } from '../../../../hooks/useTacoSettings.js';
|
3
|
+
import { useLocalStorage } from '../../../../hooks/useLocalStorage.js';
|
4
4
|
|
5
|
+
const DEFAULT_ENABLED_OPTIONS = {
|
6
|
+
columnOrder: true,
|
7
|
+
columnPinning: true,
|
8
|
+
columnSizing: true,
|
9
|
+
columnVisibility: true,
|
10
|
+
excludeUnmatchedRecordsInSearch: true,
|
11
|
+
fontSize: true,
|
12
|
+
grouping: true,
|
13
|
+
rowHeight: true,
|
14
|
+
sorting: true
|
15
|
+
};
|
5
16
|
function useUniqueTableId(tableId) {
|
6
17
|
const tacoSettings = useTacoSettings();
|
7
18
|
return `taco.${tacoSettings.uniqueUserIdentifier}.table.${tableId}.settings`;
|
8
19
|
}
|
20
|
+
function useEnabledSettings(isEnabled) {
|
21
|
+
return React__default.useMemo(() => {
|
22
|
+
if (isEnabled === false) {
|
23
|
+
return [Object.keys(DEFAULT_ENABLED_OPTIONS).reduce((o, key) => ({
|
24
|
+
...o,
|
25
|
+
[key]: false
|
26
|
+
}), {}), false];
|
27
|
+
} else if (isEnabled === true) {
|
28
|
+
return [DEFAULT_ENABLED_OPTIONS, true];
|
29
|
+
}
|
30
|
+
const options = {
|
31
|
+
...DEFAULT_ENABLED_OPTIONS,
|
32
|
+
...isEnabled
|
33
|
+
};
|
34
|
+
return [options, Object.values(options).some(o => o === true)];
|
35
|
+
}, [isEnabled]);
|
36
|
+
}
|
9
37
|
function useTableSettings(isEnabled = false, id, defaultSettings = {}, onChangeSettings) {
|
10
38
|
const uniqueId = useUniqueTableId(id);
|
11
|
-
const [
|
39
|
+
const [enabledSettings, hasSomeEnabledSettings] = useEnabledSettings(isEnabled);
|
40
|
+
const [persistedSettings, _setPersistedSettings] = useLocalStorage(hasSomeEnabledSettings ? uniqueId : undefined, removeDisabledSettings(defaultSettings, enabledSettings));
|
12
41
|
const setPersistedSettings = React__default.useCallback(value => {
|
13
|
-
if (!
|
42
|
+
if (!hasSomeEnabledSettings) {
|
14
43
|
return;
|
15
44
|
}
|
16
|
-
|
45
|
+
const sanitizedSettings = removeDisabledSettings(value, enabledSettings);
|
46
|
+
_setPersistedSettings(sanitizedSettings);
|
17
47
|
if (typeof onChangeSettings === 'function') {
|
18
|
-
onChangeSettings(
|
48
|
+
onChangeSettings(sanitizedSettings);
|
19
49
|
}
|
20
|
-
}, [
|
21
|
-
if (!
|
50
|
+
}, [hasSomeEnabledSettings, onChangeSettings, JSON.stringify(enabledSettings)]);
|
51
|
+
if (!hasSomeEnabledSettings) {
|
22
52
|
return [defaultSettings, () => undefined];
|
23
53
|
}
|
24
54
|
return [persistedSettings, setPersistedSettings];
|
25
55
|
}
|
56
|
+
function removeDisabledSettings(settings, enabledSettings) {
|
57
|
+
const sanitizedSettings = {
|
58
|
+
...settings
|
59
|
+
};
|
60
|
+
Object.keys(enabledSettings).forEach(setting => {
|
61
|
+
if (!enabledSettings[setting]) {
|
62
|
+
delete sanitizedSettings[setting];
|
63
|
+
}
|
64
|
+
});
|
65
|
+
return sanitizedSettings;
|
66
|
+
}
|
26
67
|
|
27
68
|
export { useTableSettings, useUniqueTableId };
|
28
69
|
//# sourceMappingURL=useTableSettings.js.map
|
package/dist/esm/packages/taco/src/primitives/Table/useTable/features/useTableSettings.js.map
CHANGED
@@ -1 +1 @@
|
|
1
|
-
{"version":3,"file":"useTableSettings.js","sources":["../../../../../../../../../src/primitives/Table/useTable/features/useTableSettings.ts"],"sourcesContent":["import React from 'react';\nimport { useLocalStorage } from '../../../../hooks/useLocalStorage';\nimport { useTacoSettings } from '../../../../hooks/useTacoSettings';\nimport { TableSettings, TableSettingsHandler } from '../../types';\n\nexport function useUniqueTableId(tableId: string) {\n const tacoSettings = useTacoSettings();\n
|
1
|
+
{"version":3,"file":"useTableSettings.js","sources":["../../../../../../../../../src/primitives/Table/useTable/features/useTableSettings.ts"],"sourcesContent":["import React from 'react';\nimport { useLocalStorage } from '../../../../hooks/useLocalStorage';\nimport { useTacoSettings } from '../../../../hooks/useTacoSettings';\nimport { EnableSettingsOptions, TableSettings, TableSettingsHandler } from '../../types';\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\nexport function useUniqueTableId(tableId: string) {\n const tacoSettings = useTacoSettings();\n return `taco.${tacoSettings.uniqueUserIdentifier}.table.${tableId}.settings`;\n}\n\nfunction useEnabledSettings(isEnabled: boolean | Partial<EnableSettingsOptions>): [EnableSettingsOptions, boolean] {\n return React.useMemo(() => {\n if (isEnabled === false) {\n return [\n Object.keys(DEFAULT_ENABLED_OPTIONS).reduce((o, key) => ({ ...o, [key]: false }), {}) as EnableSettingsOptions,\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\nexport function useTableSettings(\n isEnabled: boolean | Partial<EnableSettingsOptions> = false,\n id: string,\n defaultSettings: TableSettings | undefined = {},\n onChangeSettings: TableSettingsHandler | undefined\n): [TableSettings, TableSettingsHandler] {\n const uniqueId = useUniqueTableId(id);\n const [enabledSettings, hasSomeEnabledSettings] = useEnabledSettings(isEnabled);\n\n const [persistedSettings, _setPersistedSettings] = useLocalStorage<TableSettings>(\n hasSomeEnabledSettings ? uniqueId : undefined,\n removeDisabledSettings(defaultSettings, enabledSettings)\n );\n\n const setPersistedSettings = React.useCallback(\n (value: TableSettings) => {\n if (!hasSomeEnabledSettings) {\n return;\n }\n\n const sanitizedSettings = removeDisabledSettings(value, enabledSettings);\n _setPersistedSettings(sanitizedSettings);\n\n if (typeof onChangeSettings === 'function') {\n onChangeSettings(sanitizedSettings);\n }\n },\n [hasSomeEnabledSettings, onChangeSettings, JSON.stringify(enabledSettings)]\n );\n\n if (!hasSomeEnabledSettings) {\n return [defaultSettings, () => undefined];\n }\n\n return [persistedSettings, setPersistedSettings];\n}\n\nfunction removeDisabledSettings(settings: TableSettings, enabledSettings: EnableSettingsOptions) {\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":["DEFAULT_ENABLED_OPTIONS","columnOrder","columnPinning","columnSizing","columnVisibility","excludeUnmatchedRecordsInSearch","fontSize","grouping","rowHeight","sorting","useUniqueTableId","tableId","tacoSettings","useTacoSettings","uniqueUserIdentifier","useEnabledSettings","isEnabled","React","useMemo","Object","keys","reduce","o","key","options","values","some","useTableSettings","id","defaultSettings","onChangeSettings","uniqueId","enabledSettings","hasSomeEnabledSettings","persistedSettings","_setPersistedSettings","useLocalStorage","undefined","removeDisabledSettings","setPersistedSettings","useCallback","value","sanitizedSettings","JSON","stringify","settings","forEach","setting"],"mappings":";;;;AAKA,MAAMA,uBAAuB,GAAG;EAC5BC,WAAW,EAAE,IAAI;EACjBC,aAAa,EAAE,IAAI;EACnBC,YAAY,EAAE,IAAI;EAClBC,gBAAgB,EAAE,IAAI;EACtBC,+BAA+B,EAAE,IAAI;EACrCC,QAAQ,EAAE,IAAI;EACdC,QAAQ,EAAE,IAAI;EACdC,SAAS,EAAE,IAAI;EACfC,OAAO,EAAE;CACZ;SAEeC,gBAAgBA,CAACC,OAAe;EAC5C,MAAMC,YAAY,GAAGC,eAAe,EAAE;EACtC,eAAeD,YAAY,CAACE,8BAA8BH,kBAAkB;AAChF;AAEA,SAASI,kBAAkBA,CAACC,SAAmD;EAC3E,OAAOC,cAAK,CAACC,OAAO,CAAC;IACjB,IAAIF,SAAS,KAAK,KAAK,EAAE;MACrB,OAAO,CACHG,MAAM,CAACC,IAAI,CAACpB,uBAAuB,CAAC,CAACqB,MAAM,CAAC,CAACC,CAAC,EAAEC,GAAG,MAAM;QAAE,GAAGD,CAAC;QAAE,CAACC,GAAG,GAAG;OAAO,CAAC,EAAE,EAAE,CAA0B,EAC9G,KAAK,CACR;KACJ,MAAM,IAAIP,SAAS,KAAK,IAAI,EAAE;MAC3B,OAAO,CAAChB,uBAAuB,EAAE,IAAI,CAAC;;IAG1C,MAAMwB,OAAO,GAAG;MAAE,GAAGxB,uBAAuB;MAAE,GAAGgB;KAAW;IAC5D,OAAO,CAACQ,OAAO,EAAEL,MAAM,CAACM,MAAM,CAACD,OAAO,CAAC,CAACE,IAAI,C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