@economic/taco 2.46.9 → 2.47.0-server-2
Sign up to get free protection for your applications and to get access to all the features.
- package/dist/components/Report/Report.d.ts +1 -1
- package/dist/components/SearchInput2/SearchInput2.d.ts +2 -0
- package/dist/components/Table3/components/Row/Editing/CreateNewRow.d.ts +1 -2
- package/dist/components/Table3/components/Row/Editing/TemporaryRow.d.ts +1 -0
- package/dist/components/Table3/features/useEditingState.d.ts +11 -11
- package/dist/components/Table3/features/useTableEditing.d.ts +13 -13
- package/dist/components/Table3/util/editing.d.ts +3 -0
- package/dist/esm/index.css +2 -2
- package/dist/esm/node_modules/babel-plugin-transform-async-to-promises/helpers.mjs.js +17 -17
- package/dist/esm/node_modules/babel-plugin-transform-async-to-promises/helpers.mjs.js.map +1 -1
- package/dist/esm/packages/taco/src/charts/components/Donut/Legend.js +1 -0
- package/dist/esm/packages/taco/src/charts/components/Donut/Legend.js.map +1 -1
- package/dist/esm/packages/taco/src/charts/components/Legend.js +1 -0
- package/dist/esm/packages/taco/src/charts/components/Legend.js.map +1 -1
- package/dist/esm/packages/taco/src/components/SearchInput2/SearchInput2.js +6 -3
- package/dist/esm/packages/taco/src/components/SearchInput2/SearchInput2.js.map +1 -1
- package/dist/esm/packages/taco/src/components/Table/hooks/plugins/useRowActions.js +1 -1
- package/dist/esm/packages/taco/src/components/Table3/Table3.js +14 -4
- package/dist/esm/packages/taco/src/components/Table3/Table3.js.map +1 -1
- package/dist/esm/packages/taco/src/components/Table3/components/Columns/Cell/EditingControlCell.js +1 -1
- package/dist/esm/packages/taco/src/components/Table3/components/Columns/Cell/EditingControlCell.js.map +1 -1
- package/dist/esm/packages/taco/src/components/Table3/components/Editing/Alert.js +14 -9
- package/dist/esm/packages/taco/src/components/Table3/components/Editing/Alert.js.map +1 -1
- package/dist/esm/packages/taco/src/components/Table3/components/Row/Editing/CreateNewRow.js +2 -4
- package/dist/esm/packages/taco/src/components/Table3/components/Row/Editing/CreateNewRow.js.map +1 -1
- package/dist/esm/packages/taco/src/components/Table3/components/Row/Editing/TemporaryRow.js +5 -4
- package/dist/esm/packages/taco/src/components/Table3/components/Row/Editing/TemporaryRow.js.map +1 -1
- package/dist/esm/packages/taco/src/components/Table3/features/useEditingState.js +32 -51
- package/dist/esm/packages/taco/src/components/Table3/features/useEditingState.js.map +1 -1
- package/dist/esm/packages/taco/src/components/Table3/features/useTableEditing.js +5 -3
- package/dist/esm/packages/taco/src/components/Table3/features/useTableEditing.js.map +1 -1
- package/dist/esm/packages/taco/src/components/Table3/listeners/useTableEditingListener.js +15 -12
- package/dist/esm/packages/taco/src/components/Table3/listeners/useTableEditingListener.js.map +1 -1
- package/dist/esm/packages/taco/src/components/Table3/util/editing.js +9 -1
- package/dist/esm/packages/taco/src/components/Table3/util/editing.js.map +1 -1
- package/dist/esm/packages/taco/src/index.js +1 -0
- package/dist/esm/packages/taco/src/index.js.map +1 -1
- package/dist/esm/packages/taco/src/primitives/Table/Core/Table.js +2 -1
- package/dist/esm/packages/taco/src/primitives/Table/Core/Table.js.map +1 -1
- package/dist/esm/packages/taco/src/primitives/Table/Core/components/Columns/Internal/Expansion.js +4 -0
- package/dist/esm/packages/taco/src/primitives/Table/Core/components/Columns/Internal/Expansion.js.map +1 -1
- package/dist/esm/packages/taco/src/primitives/Table/Core/components/Columns/Internal/Selection.js +7 -4
- package/dist/esm/packages/taco/src/primitives/Table/Core/components/Columns/Internal/Selection.js.map +1 -1
- package/dist/esm/packages/taco/src/primitives/Table/Core/components/Footer/Footer.js +7 -2
- package/dist/esm/packages/taco/src/primitives/Table/Core/components/Footer/Footer.js.map +1 -1
- package/dist/esm/packages/taco/src/primitives/Table/Core/components/Footer/Summary.js +7 -5
- package/dist/esm/packages/taco/src/primitives/Table/Core/components/Footer/Summary.js.map +1 -1
- package/dist/esm/packages/taco/src/primitives/Table/Core/components/Row/BuiltIns/SkeletonRow.js +24 -22
- package/dist/esm/packages/taco/src/primitives/Table/Core/components/Row/BuiltIns/SkeletonRow.js.map +1 -1
- package/dist/esm/packages/taco/src/primitives/Table/Core/components/Row/Row.js +41 -4
- package/dist/esm/packages/taco/src/primitives/Table/Core/components/Row/Row.js.map +1 -1
- package/dist/esm/packages/taco/src/primitives/Table/Core/components/Toolbar/components/Print/Print.js +3 -1
- package/dist/esm/packages/taco/src/primitives/Table/Core/components/Toolbar/components/Print/Print.js.map +1 -1
- package/dist/esm/packages/taco/src/primitives/Table/Core/components/Toolbar/components/Search/Search.js +26 -3
- package/dist/esm/packages/taco/src/primitives/Table/Core/components/Toolbar/components/Search/Search.js.map +1 -1
- package/dist/esm/packages/taco/src/primitives/Table/Core/features/useTableGlobalShortcuts.js +1 -1
- package/dist/esm/packages/taco/src/primitives/Table/Core/features/useTableGlobalShortcuts.js.map +1 -1
- package/dist/esm/packages/taco/src/primitives/Table/Core/features/useTableRenderer.js +36 -9
- package/dist/esm/packages/taco/src/primitives/Table/Core/features/useTableRenderer.js.map +1 -1
- package/dist/esm/packages/taco/src/primitives/Table/Core/useTable.js +1 -1
- package/dist/esm/packages/taco/src/primitives/Table/Core/useTable.js.map +1 -1
- package/dist/esm/packages/taco/src/primitives/Table/types.js.map +1 -1
- package/dist/esm/packages/taco/src/primitives/Table/useTableDataLoader.js +5 -7
- package/dist/esm/packages/taco/src/primitives/Table/useTableDataLoader.js.map +1 -1
- package/dist/esm/packages/taco/src/primitives/Table/useTableDataLoader2.js +249 -0
- package/dist/esm/packages/taco/src/primitives/Table/useTableDataLoader2.js.map +1 -0
- package/dist/esm/packages/taco/src/primitives/Table/useTableManager/features/useTableRowActive.js +1 -1
- package/dist/esm/packages/taco/src/primitives/Table/useTableManager/features/useTableRowActive.js.map +1 -1
- package/dist/esm/packages/taco/src/primitives/Table/useTableManager/features/useTableRowExpansion.js +2 -1
- package/dist/esm/packages/taco/src/primitives/Table/useTableManager/features/useTableRowExpansion.js.map +1 -1
- package/dist/esm/packages/taco/src/primitives/Table/useTableManager/features/useTableSearch.js +3 -2
- package/dist/esm/packages/taco/src/primitives/Table/useTableManager/features/useTableSearch.js.map +1 -1
- package/dist/esm/packages/taco/src/primitives/Table/useTableManager/features/useTableServerLoading.js +4 -2
- package/dist/esm/packages/taco/src/primitives/Table/useTableManager/features/useTableServerLoading.js.map +1 -1
- package/dist/esm/packages/taco/src/primitives/Table/useTableManager/listeners/useTableFilterListener.js +3 -1
- package/dist/esm/packages/taco/src/primitives/Table/useTableManager/listeners/useTableFilterListener.js.map +1 -1
- package/dist/esm/packages/taco/src/primitives/Table/useTableManager/listeners/useTableRowSelectionListener.js +4 -4
- package/dist/esm/packages/taco/src/primitives/Table/useTableManager/listeners/useTableRowSelectionListener.js.map +1 -1
- package/dist/esm/packages/taco/src/primitives/Table/useTableManager/listeners/useTableSearchListener.js +14 -13
- package/dist/esm/packages/taco/src/primitives/Table/useTableManager/listeners/useTableSearchListener.js.map +1 -1
- package/dist/esm/packages/taco/src/primitives/Table/useTableManager/listeners/useTableServerLoadingListener.js +7 -3
- package/dist/esm/packages/taco/src/primitives/Table/useTableManager/listeners/useTableServerLoadingListener.js.map +1 -1
- package/dist/esm/packages/taco/src/primitives/Table/useTableManager/useTableManager.js +4 -4
- package/dist/esm/packages/taco/src/primitives/Table/useTableManager/useTableManager.js.map +1 -1
- package/dist/esm/packages/taco/src/primitives/Table/useTableManager/util/columns.js +4 -1
- package/dist/esm/packages/taco/src/primitives/Table/useTableManager/util/columns.js.map +1 -1
- package/dist/esm/packages/taco/src/primitives/Table/useTableManager/util/presets.js +7 -1
- package/dist/esm/packages/taco/src/primitives/Table/useTableManager/util/presets.js.map +1 -1
- package/dist/esm/packages/taco/src/primitives/Table/useTableManager/util/setup.js +6 -0
- package/dist/esm/packages/taco/src/primitives/Table/useTableManager/util/setup.js.map +1 -1
- package/dist/hooks/useLazyDebouncedEffect.d.ts +2 -0
- package/dist/index.css +2 -2
- package/dist/index.d.ts +1 -0
- package/dist/primitives/Table/Core/Table.d.ts +1 -0
- package/dist/primitives/Table/Core/components/Row/BuiltIns/SkeletonRow.d.ts +2 -2
- package/dist/primitives/Table/Core/components/Row/Row.d.ts +2 -0
- package/dist/primitives/Table/Core/features/useTableRenderer.d.ts +1 -1
- package/dist/primitives/Table/types.d.ts +11 -6
- package/dist/primitives/Table/useTableDataLoader2.d.ts +23 -0
- package/dist/primitives/Table/useTableManager/features/useTableRowExpansion.d.ts +2 -1
- package/dist/primitives/Table/useTableManager/features/useTableSearch.d.ts +4 -2
- package/dist/primitives/Table/useTableManager/features/useTableServerLoading.d.ts +3 -1
- package/dist/primitives/Table/useTableManager/listeners/useTableSearchListener.d.ts +1 -2
- package/dist/primitives/Table/useTableManager/util/columns.d.ts +2 -1
- package/dist/taco.cjs.development.js +607 -229
- package/dist/taco.cjs.development.js.map +1 -1
- package/dist/taco.cjs.production.min.js +1 -1
- package/dist/taco.cjs.production.min.js.map +1 -1
- package/package.json +2 -3
@@ -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 VisibilityState as ReactTableColumnVisibilityState,\n SortingState as ReactTableSortingState,\n BuiltInAggregationFn as ReactTableBuiltInAggregationFn,\n BuiltInSortingFn as ReactTableBuiltInSortingFn,\n} from '@tanstack/react-table';\nimport { FontSize, FontSizes, StringWithAutocompleteOptions, ValueOf } from '../../types';\nimport { MenuItemProps } from '../../components/Menu/components/Item';\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 =\n // base\n | 'text'\n | 'number'\n | 'datetime'\n | 'boolean'\n // advanced\n | 'amount';\nexport type TableColumnFilter = ReactTableColumnFilter;\nexport type TableColumnMenu = ((columnId: string) => React.ReactNode | null)[];\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 | 'checkbox'\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<TType> = (rows: TType[]) => 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, internalRowId: string) => JSX.Element | null;\nexport type TableRowActionGroupRenderer<TType = unknown> = (rows: TType[]) => JSX.Element | null;\nexport type TableRowClickHandler<TType = unknown> = (row: TType) => void;\nexport type TableRowDragHandler<TType = unknown> = (\n rows: TType[],\n showPlaceholder: (string) => void,\n setDataTransfer: (data: string) => void\n) => void;\nexport type TableRowDropHandler<TType = unknown> = (event: React.DragEvent, 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;\nexport type TableRowWithMetaData<TType = unknown> = TType & {\n _meta?: {\n layout?: 'heading' | 'summary' | 'item';\n };\n};\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 | Promise<void>;\nexport type TableFontSize = keyof typeof FontSizes;\nexport type TablePreset = 'complex' | 'list' | 'simple';\nexport type TableRowExpansionRenderer<TType = unknown> = (row: TType) => (() => JSX.Element) | null;\nexport type TableScrollToIndexHandler = (index: number, options?: { align: 'start' | 'center' | 'end' | 'auto' }) => void;\nexport type TableSearchHandler = (search: string | undefined) => void | Promise<void>;\nexport type TableServerLoadPageHandler = (\n pageIndex: number,\n sorting: TableColumnSort[],\n filters: TableColumnFilter[]\n) => Promise<void>;\nexport type TableServerLoadAllHandler = (sorting: TableColumnSort[], filters: TableColumnFilter[]) => 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 | Promise<void>;\nexport type TableCustomSettingsRenderer = (props: TableSettings) => React.ReactElement<MenuItemProps>[];\nexport type TableEmptyStateReason = 'empty' | 'filtering' | 'searching';\nexport type TableEmptyStateRenderer = (props: { reason: TableEmptyStateReason }) => JSX.Element | null;\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 rowHeight?: TableRowHeight;\n searchQuery?: string;\n sorting?: ReactTableSortingState;\n};\nexport type TableEnableSettingsOptions = {\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 TableConditionalRowProp<TType = unknown> = boolean | ((row: TType) => boolean);\nexport type TableFeatureProps<TType = unknown> = {\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?: TableConditionalRowProp<TType>;\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?: TableConditionalRowProp<TType>;\n enableRowDrag?: boolean;\n enableRowDrop?: boolean;\n enableRowGoto?: boolean;\n enableRowHeight?: boolean;\n enableSaveSettings?: boolean | Partial<TableEnableSettingsOptions>;\n};\n\nexport type TableChild = JSX.Element | boolean | null | undefined;\n\nexport type TableCommonProps<TType = unknown> = TableFeatureProps<TType> & {\n children: TableChild | TableChild[];\n data: TType[];\n id: string;\n\n // misc\n customSettings?: TableCustomSettingsRenderer;\n defaultColumnFreezingIndex?: number;\n defaultRowActiveIndex?: number;\n defaultRowGroupColumnId?: keyof TType;\n defaultSettings?: TableSettings;\n emptyState?: TableEmptyStateRenderer;\n preset?: TablePreset;\n rowActions?: TableRowActionRenderer<TType>[];\n rowActionsForGroup?: TableRowActionGroupRenderer<TType>[];\n rowActionsLength?: number;\n rowExpansionRenderer?: TableRowExpansionRenderer<TType>;\n rowIdentityAccessor?: keyof TType;\n shortcuts?: TableShortcuts<TType>;\n toolbarLeft?: JSX.Element;\n toolbarRight?: JSX.Element;\n toolbarPanel?: JSX.Element;\n\n // handlers\n onRowClick?: TableRowClickHandler<TType>;\n onRowDrag?: TableRowDragHandler<TType>;\n onRowDrop?: TableRowDropHandler<TType>;\n onRowGoto?: TableRowGotoHandler;\n onRowSelect?: TableRowSelectHandler<TType>;\n\n // state change handlers\n onChangeFilter?: TableFilterHandler;\n onChangeSearch?: TableSearchHandler;\n onChangeSettings?: TableSettingsHandler;\n onChangeSort?: TableSortHandler;\n};\n\nexport interface TableClientProps<TType = unknown> extends TableCommonProps<TType> {\n length?: never;\n loadAll?: never;\n loadPage?: never;\n pageSize?: never;\n}\n\nexport interface TableServerProps<TType = unknown> extends TableCommonProps<TType> {\n length: number | undefined;\n loadAll: TableServerLoadAllHandler;\n loadPage: TableServerLoadPageHandler;\n pageSize?: number;\n}\n\nexport type TableProps<TType = unknown> = TableClientProps<TType> | TableServerProps<TType>;\n\nexport type TableColumnProps<TType = unknown> = ValueOf<{\n [Key in keyof TType]: {\n accessor?: Key;\n id: StringWithAutocompleteOptions<Key>;\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>;\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 enableEditing?: boolean;\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\nexport type TableTexts = {\n columns: {\n actions: {\n tooltip: string;\n };\n drag: {\n tooltip: string;\n };\n expansion: {\n collapse: string;\n collapseAll: string;\n expand: string;\n expandAll: string;\n };\n menu: {\n editFilter: string;\n filter: string;\n freezeFirstColumn: string;\n freezeUptoColumn: string;\n gotoRow: string;\n hideColumn: string;\n unfreezeColumns: string;\n sorting: string;\n sortingOrder: {\n ascending: string;\n descending: string;\n unsorted: string;\n };\n };\n resize: {\n tooltip: string;\n };\n select: {\n deselect: string;\n deselectAll: string;\n select: string;\n selectAll: string;\n };\n };\n columnSettings: {\n button: string;\n noResults: string;\n search: string;\n tooltip: string;\n };\n filters: {\n button: string;\n buttons: {\n addFilter: string;\n clearFilters: string;\n cancel: string;\n clear: string;\n apply: string;\n };\n comparators: {\n contains: string;\n doesNotContain: string;\n isEqualTo: string;\n isNotEqualTo: string;\n isGreaterThan: string;\n isLessThan: string;\n isBetween: string;\n isEmpty: string;\n isNotEmpty: string;\n isBefore: string;\n isAfter: string;\n isLessThanOrEqualTo: string;\n isGreaterThanOrEqualTo: string;\n isOnOrBefore: string;\n isOnOrAfter: string;\n hasAnyOf: string;\n hasAllOf: string;\n hasNoneOf: string;\n };\n conditions: {\n and: string;\n where: string;\n };\n emptyFilter: {\n condition: string;\n value: string;\n };\n hiddenColumn: string;\n hiddenGroupedColumn: string;\n tooltip: string;\n total: string;\n };\n fontSize: {\n tooltip: string;\n sizes: {\n small: string;\n medium: string;\n large: string;\n };\n };\n footer: {\n summary: {\n count: string;\n records: string;\n selected: string;\n };\n };\n print: {\n error: string;\n loading: string;\n tooltip: string;\n warningDialog: {\n title: string;\n description: string;\n checkboxVisibilityLabel: string;\n cancelButtonText: string;\n printButtonText: string;\n };\n settingsDialog: {\n title: string;\n size: string;\n sizeA5: string;\n sizeA4: string;\n sizeA3: string;\n sizeLetter: string;\n sizeLegal: string;\n orientation: string;\n orientationLandscape: string;\n orientationPortrait: string;\n rows: string;\n rowsAll: string;\n rowsSelected: string;\n layout: string;\n layoutSplitGroups: string;\n };\n };\n rowHeight: {\n tooltip: string;\n sizes: {\n short: string;\n medium: string;\n tall: string;\n extraTall: string;\n };\n };\n search: {\n excludeUnmatchedResults: string;\n placeholder: string;\n };\n otherOptions: {\n tooltip: string;\n };\n};\n"],"names":["TableFilterComparator","TableServerLoadAllState"],"mappings":"AAwBA;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;IAmHrBC;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 VisibilityState as ReactTableColumnVisibilityState,\n SortingState as ReactTableSortingState,\n BuiltInAggregationFn as ReactTableBuiltInAggregationFn,\n BuiltInSortingFn as ReactTableBuiltInSortingFn,\n} from '@tanstack/react-table';\nimport { FontSize, FontSizes, StringWithAutocompleteOptions, ValueOf } from '../../types';\nimport { MenuItemProps } from '../../components/Menu/components/Item';\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 =\n // base\n | 'text'\n | 'number'\n | 'datetime'\n | 'boolean'\n // advanced\n | 'amount';\nexport type TableColumnFilter = ReactTableColumnFilter;\nexport type TableColumnMenu = ((columnId: string) => React.ReactNode | null)[];\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 | 'checkbox'\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<TType> = (rows: TType[]) => 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, internalRowId: string) => JSX.Element | null;\nexport type TableRowActionGroupRenderer<TType = unknown> = (rows: TType[]) => JSX.Element | null;\nexport type TableRowClickHandler<TType = unknown> = (row: TType) => void;\nexport type TableRowDragHandler<TType = unknown> = (\n rows: TType[],\n showPlaceholder: (string) => void,\n setDataTransfer: (data: string) => void\n) => void;\nexport type TableRowDropHandler<TType = unknown> = (event: React.DragEvent, 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[], ids: (keyof TType)[]) => void;\nexport type TableRowWithMetaData<TType = unknown> = TType & {\n _meta?: {\n layout?: 'heading' | 'summary' | 'item';\n };\n};\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 TableSortHandler = (sorting: TableColumnSort[]) => Promise<void>;\nexport type TableFilterHandler = (filters: TableColumnFilter[], hiddenColumns: string[]) => Promise<void>;\nexport type TableSearchHandler = (search: string | undefined, hiddenColumns: string[]) => Promise<void>;\nexport type TableFontSize = keyof typeof FontSizes;\nexport type TablePreset = 'complex' | 'list' | 'simple';\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 hiddenColumns: string[]\n) => Promise<void>;\nexport type TableServerLoadAllHandler = (\n sorting: TableColumnSort[],\n filters: TableColumnFilter[],\n search: string | undefined,\n hiddenColumns: string[]\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 TableCustomSettingsRenderer = (props: TableSettings) => React.ReactElement<MenuItemProps>[];\nexport type TableEmptyStateReason = 'empty' | 'filtering' | 'searching';\nexport type TableEmptyStateRenderer = (props: { reason: TableEmptyStateReason }) => JSX.Element | null;\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 rowHeight?: TableRowHeight;\n searchQuery?: string;\n sorting?: ReactTableSortingState;\n};\nexport type TableEnableSettingsOptions = {\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 TableConditionalRowProp<TType = unknown> = boolean | ((row: TType) => boolean);\nexport type TableFeatureProps<TType = unknown> = {\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 enableRowExpansionAll?: boolean;\n enableRowSelection?: TableConditionalRowProp<TType>;\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?: TableConditionalRowProp<TType>;\n enableRowDrag?: boolean;\n enableRowDrop?: boolean;\n enableRowGoto?: boolean;\n enableRowHeight?: boolean;\n enableSaveSettings?: boolean | Partial<TableEnableSettingsOptions>;\n};\n\nexport type TableChild = JSX.Element | boolean | null | undefined;\n\nexport type TableCommonProps<TType = unknown> = TableFeatureProps<TType> & {\n children: TableChild | TableChild[];\n data: TType[];\n id: string;\n\n // misc\n customSettings?: TableCustomSettingsRenderer;\n defaultColumnFreezingIndex?: number;\n defaultRowActiveIndex?: number;\n defaultRowGroupColumnId?: keyof TType;\n defaultSettings?: TableSettings;\n emptyState?: TableEmptyStateRenderer;\n preset?: TablePreset;\n rowActions?: TableRowActionRenderer<TType>[];\n rowActionsForGroup?: TableRowActionGroupRenderer<TType>[];\n rowActionsLength?: number;\n rowExpansionRenderer?: TableRowExpansionRenderer<TType>;\n rowIdentityAccessor?: keyof TType;\n shortcuts?: TableShortcuts<TType>;\n toolbarLeft?: JSX.Element;\n toolbarRight?: JSX.Element;\n toolbarPanel?: JSX.Element;\n\n // handlers\n onRowClick?: TableRowClickHandler<TType>;\n onRowDrag?: TableRowDragHandler<TType>;\n onRowDrop?: TableRowDropHandler<TType>;\n onRowGoto?: TableRowGotoHandler;\n onRowSelect?: TableRowSelectHandler<TType>;\n\n // state change handlers\n onChangeFilter?: TableFilterHandler;\n onChangeSearch?: TableSearchHandler;\n onChangeSettings?: TableSettingsHandler;\n onChangeSort?: TableSortHandler;\n};\n\nexport interface TableClientProps<TType = unknown> extends TableCommonProps<TType> {\n length?: never;\n loadAll?: never;\n loadPage?: never;\n pageSize?: never;\n pages?: never;\n\n // experimental\n _experimentalDataLoader2?: never;\n}\n\nexport interface TableServerProps<TType = unknown> extends TableCommonProps<TType> {\n length: number | undefined;\n loadAll: TableServerLoadAllHandler;\n loadPage: TableServerLoadPageHandler;\n pageSize?: number;\n pages?: number[];\n\n // experimental\n _experimentalDataLoader2?: boolean;\n}\n\nexport type TableProps<TType = unknown> = TableClientProps<TType> | TableServerProps<TType>;\n\nexport type TableColumnProps<TType = unknown> = ValueOf<{\n [Key in keyof TType]: {\n accessor?: Key;\n id: StringWithAutocompleteOptions<Key>;\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>;\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 enableEditing?: boolean;\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\nexport type TableTexts = {\n columns: {\n actions: {\n tooltip: string;\n };\n drag: {\n tooltip: string;\n };\n expansion: {\n collapse: string;\n collapseAll: string;\n expand: string;\n expandAll: string;\n };\n menu: {\n editFilter: string;\n filter: string;\n freezeFirstColumn: string;\n freezeUptoColumn: string;\n gotoRow: string;\n hideColumn: string;\n unfreezeColumns: string;\n sorting: string;\n sortingOrder: {\n ascending: string;\n descending: string;\n unsorted: string;\n };\n };\n resize: {\n tooltip: string;\n };\n select: {\n deselect: string;\n deselectAll: string;\n select: string;\n selectAll: string;\n };\n };\n columnSettings: {\n button: string;\n noResults: string;\n search: string;\n tooltip: string;\n };\n filters: {\n button: string;\n buttons: {\n addFilter: string;\n clearFilters: string;\n cancel: string;\n clear: string;\n apply: string;\n };\n comparators: {\n contains: string;\n doesNotContain: string;\n isEqualTo: string;\n isNotEqualTo: string;\n isGreaterThan: string;\n isLessThan: string;\n isBetween: string;\n isEmpty: string;\n isNotEmpty: string;\n isBefore: string;\n isAfter: string;\n isLessThanOrEqualTo: string;\n isGreaterThanOrEqualTo: string;\n isOnOrBefore: string;\n isOnOrAfter: string;\n hasAnyOf: string;\n hasAllOf: string;\n hasNoneOf: string;\n };\n conditions: {\n and: string;\n where: string;\n };\n emptyFilter: {\n condition: string;\n value: string;\n };\n hiddenColumn: string;\n hiddenGroupedColumn: string;\n tooltip: string;\n total: string;\n };\n fontSize: {\n tooltip: string;\n sizes: {\n small: string;\n medium: string;\n large: string;\n };\n };\n footer: {\n summary: {\n count: string;\n records: string;\n selected: string;\n };\n };\n print: {\n error: string;\n loading: string;\n tooltip: string;\n warningDialog: {\n title: string;\n description: string;\n checkboxVisibilityLabel: string;\n cancelButtonText: string;\n printButtonText: string;\n };\n settingsDialog: {\n title: string;\n size: string;\n sizeA5: string;\n sizeA4: string;\n sizeA3: string;\n sizeLetter: string;\n sizeLegal: string;\n orientation: string;\n orientationLandscape: string;\n orientationPortrait: string;\n rows: string;\n rowsAll: string;\n rowsSelected: string;\n layout: string;\n layoutSplitGroups: string;\n };\n };\n rowHeight: {\n tooltip: string;\n sizes: {\n short: string;\n medium: string;\n tall: string;\n extraTall: string;\n };\n };\n search: {\n excludeUnmatchedResults: string;\n placeholder: string;\n };\n otherOptions: {\n tooltip: string;\n };\n};\n"],"names":["TableFilterComparator","TableServerLoadAllState"],"mappings":"AAwBA;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;IA2HrBC;AAAZ,WAAYA,uBAAuB;EAC/BA,iFAAU;EACVA,2EAAO;EACPA,+EAAS;AACb,CAAC,EAJWA,uBAAuB,KAAvBA,uBAAuB;;;;"}
|
@@ -54,7 +54,7 @@ function useTableDataLoader(fetchPage, fetchAll, options = {
|
|
54
54
|
length.current = response.length;
|
55
55
|
nextData = Array(length.current).fill(undefined);
|
56
56
|
} else {
|
57
|
-
nextData = [
|
57
|
+
nextData = [].concat(currentData);
|
58
58
|
}
|
59
59
|
const startIndex = pageIndex * pageSize;
|
60
60
|
nextData.splice(startIndex, pageSize, ...response.data);
|
@@ -120,13 +120,12 @@ function useTableDataLoader(fetchPage, fetchAll, options = {
|
|
120
120
|
try {
|
121
121
|
if (_lastUsedSearch.current) {
|
122
122
|
// we're searching, which means we need to refetch all with the correct sorting applied
|
123
|
-
loadAll(sorting, _lastUsedFilters.current);
|
123
|
+
return loadAll(sorting, _lastUsedFilters.current);
|
124
124
|
} else {
|
125
125
|
var _lastUsedPageIndex$cu2;
|
126
126
|
// load the last page that we scrolled to
|
127
|
-
loadPage((_lastUsedPageIndex$cu2 = _lastUsedPageIndex.current) !== null && _lastUsedPageIndex$cu2 !== void 0 ? _lastUsedPageIndex$cu2 : 0, sorting, _lastUsedFilters.current);
|
127
|
+
return loadPage((_lastUsedPageIndex$cu2 = _lastUsedPageIndex.current) !== null && _lastUsedPageIndex$cu2 !== void 0 ? _lastUsedPageIndex$cu2 : 0, sorting, _lastUsedFilters.current);
|
128
128
|
}
|
129
|
-
return Promise.resolve();
|
130
129
|
} catch (e) {
|
131
130
|
return Promise.reject(e);
|
132
131
|
}
|
@@ -135,13 +134,12 @@ function useTableDataLoader(fetchPage, fetchAll, options = {
|
|
135
134
|
try {
|
136
135
|
if (_lastUsedSearch.current) {
|
137
136
|
// we're searching, which means we need to refetch all with the correct sorting applied
|
138
|
-
loadAll(_lastUsedSorting.current, filters);
|
137
|
+
return loadAll(_lastUsedSorting.current, filters);
|
139
138
|
} else {
|
140
139
|
var _lastUsedPageIndex$cu3;
|
141
140
|
// load the last page that we scrolled to
|
142
|
-
loadPage((_lastUsedPageIndex$cu3 = _lastUsedPageIndex.current) !== null && _lastUsedPageIndex$cu3 !== void 0 ? _lastUsedPageIndex$cu3 : 0, _lastUsedSorting.current, filters);
|
141
|
+
return loadPage((_lastUsedPageIndex$cu3 = _lastUsedPageIndex.current) !== null && _lastUsedPageIndex$cu3 !== void 0 ? _lastUsedPageIndex$cu3 : 0, _lastUsedSorting.current, filters);
|
143
142
|
}
|
144
|
-
return Promise.resolve();
|
145
143
|
} catch (e) {
|
146
144
|
return Promise.reject(e);
|
147
145
|
}
|
@@ -1 +1 @@
|
|
1
|
-
{"version":3,"file":"useTableDataLoader.js","sources":["../../../../../../../src/primitives/Table/useTableDataLoader.ts"],"sourcesContent":["import React from 'react';\nimport {\n TableColumnFilter,\n TableColumnSort,\n TableFilterHandler,\n TableServerLoadPageHandler,\n TableServerLoadAllHandler,\n TableSortHandler,\n TableSearchHandler,\n} from './types';\n\nexport const DEFAULT_PAGE_SIZE = 100;\n\nexport type useTableDataPageFetcher<TType = unknown> = (\n pageIndex: number,\n pageSize: number,\n sorting: TableColumnSort[],\n filters: TableColumnFilter[]\n) => Promise<{ data: TType[]; length: number }>;\n\nexport type useTableDataAllFetcher<TType = unknown> = (\n sorting: TableColumnSort[],\n filters: TableColumnFilter[]\n) => Promise<{ data: TType[]; length: number }>;\n\nexport type useTableDataLoaderOptions = { pageSize: number };\n\nexport type useTableDataLoaderValues<TType = unknown> = {\n data: TType[];\n length: number | undefined;\n loadAll: TableServerLoadAllHandler;\n loadPage: TableServerLoadPageHandler;\n onChangeFilter: TableFilterHandler;\n onChangeSearch: TableSearchHandler;\n onChangeSort: TableSortHandler;\n pageSize: number;\n};\n\nexport function useTableDataLoader<TType = unknown>(\n fetchPage: useTableDataPageFetcher<TType>,\n fetchAll: useTableDataAllFetcher<TType>,\n options: useTableDataLoaderOptions = { pageSize: DEFAULT_PAGE_SIZE }\n): [useTableDataLoaderValues<TType>, () => void] {\n const { pageSize } = options;\n\n // track the data length, we don't know it until the first request\n const length = React.useRef<number | undefined>(undefined);\n // data will be filled after the first request, then we'll update values in place\n const [data, setData] = React.useState<any[]>([]);\n // track which pages have been loaded to dedupe requests\n const _pendingPageRequests = React.useRef({});\n const _lastUsedSorting = React.useRef<TableColumnSort[]>([]);\n const _lastUsedFilters = React.useRef<TableColumnFilter[]>([]);\n const _lastUsedSearch = React.useRef<string>();\n const _lastUsedPageIndex = React.useRef<number>();\n const _forceReset = React.useRef(false);\n\n const loadPage = async (pageIndex: number, sorting: TableColumnSort[], filters: TableColumnFilter[]) => {\n let reset = false;\n\n // sorting or filters changed, reset everything\n if (\n _forceReset.current ||\n JSON.stringify(sorting) !== JSON.stringify(_lastUsedSorting.current) ||\n JSON.stringify(filters) !== JSON.stringify(_lastUsedFilters.current)\n ) {\n _pendingPageRequests.current = {};\n // nuke the dataset so that we \"start again\" after sorting\n reset = true;\n }\n\n if (_pendingPageRequests.current[pageIndex]) {\n // if page is already loaded/loading, abort, otherwise mark it as loading\n return;\n } else {\n _pendingPageRequests.current[pageIndex] = true;\n }\n\n _forceReset.current = false;\n // set the last page loaded (or tried to load), so that we can load it back again after resets\n _lastUsedPageIndex.current = pageIndex;\n // set the sorting so we can track if it changed between loads\n _lastUsedSorting.current = sorting;\n // set the filters so we can track if it changed between loads\n _lastUsedFilters.current = filters;\n\n try {\n const response = await fetchPage(pageIndex, pageSize, sorting, filters);\n\n // update state, here we do some \"magic\" to support \"load in place\"\n setData(currentData => {\n let nextData;\n\n // reset table state if:\n // - the length isn't set at all (first load)\n // - the client length and server length are different (the data changed)\n if (reset || length.current !== response.length) {\n length.current = response.length;\n nextData = Array(length.current).fill(undefined);\n } else {\n nextData = [...currentData];\n }\n\n const startIndex = pageIndex * pageSize;\n nextData.splice(startIndex, pageSize, ...response.data);\n return nextData;\n });\n } catch {\n //\n } finally {\n _pendingPageRequests.current[pageIndex] = false;\n }\n };\n\n const loadAll = async (sorting: TableColumnSort[], filters: TableColumnFilter[]) => {\n // set the sorting so we can track if it changed between loads\n _lastUsedSorting.current = sorting;\n // set the filters so we can track if it changed between loads\n _lastUsedFilters.current = filters;\n\n try {\n const response = await fetchAll(sorting, filters);\n length.current = response.length;\n\n setData(() => {\n let nextData;\n\n if (response.data.length !== response.length) {\n nextData = Array(response.length).fill(undefined);\n nextData.splice(0, response.data.length, ...response.data);\n } else {\n nextData = [...response.data];\n }\n\n return nextData;\n });\n } catch {\n //\n }\n };\n\n const invalidate = async () => {\n // empties the entire data array\n _forceReset.current = true;\n\n if (_lastUsedSearch.current) {\n // we're searching, which means we need to refetch all with the correct sorting applied\n return loadAll(_lastUsedSorting.current, _lastUsedFilters.current);\n } else {\n // load the last page that we scrolled to\n return loadPage(_lastUsedPageIndex.current ?? 0, _lastUsedSorting.current, _lastUsedFilters.current);\n }\n };\n\n // search works client side - it fetches all then works client side - so these handlers are a little \"weird\"\n // if a search is currently \"active\", we need to re load all because\n const handleSort = async (sorting: TableColumnSort[]) => {\n if (_lastUsedSearch.current) {\n // we're searching, which means we need to refetch all with the correct sorting applied\n loadAll(sorting, _lastUsedFilters.current);\n } else {\n // load the last page that we scrolled to\n loadPage(_lastUsedPageIndex.current ?? 0, sorting, _lastUsedFilters.current);\n }\n };\n const handleFilter = async (filters: TableColumnFilter[]) => {\n if (_lastUsedSearch.current) {\n // we're searching, which means we need to refetch all with the correct sorting applied\n loadAll(_lastUsedSorting.current, filters);\n } else {\n // load the last page that we scrolled to\n loadPage(_lastUsedPageIndex.current ?? 0, _lastUsedSorting.current, filters);\n }\n };\n const handleSearch = async (search: string | undefined) => {\n // set the search so we can track if it changed between loads\n _lastUsedSearch.current = search || undefined;\n // search works client side, and focusing the search field triggers a load of all so we don't actually\n // want to load anything when search gets changed, we just store the value for other handlers\n };\n\n return [\n {\n data,\n length: length.current,\n loadAll,\n loadPage,\n onChangeFilter: handleFilter,\n onChangeSearch: handleSearch,\n onChangeSort: handleSort,\n pageSize,\n },\n invalidate,\n ];\n}\n"],"names":["DEFAULT_PAGE_SIZE","useTableDataLoader","fetchPage","fetchAll","options","pageSize","length","React","useRef","undefined","data","setData","useState","_pendingPageRequests","_lastUsedSorting","_lastUsedFilters","_lastUsedSearch","_lastUsedPageIndex","_forceReset","loadPage","pageIndex","sorting","filters","reset","current","JSON","stringify","Promise","resolve","_temp","_finallyRethrows","_catch","then","response","currentData","nextData","Array","fill","startIndex","splice","_wasThrown","_result","e","reject","loadAll","_temp2","invalidate","_lastUsedPageIndex$cu","handleSort","_lastUsedPageIndex$cu2","handleFilter","_lastUsedPageIndex$cu3","handleSearch","search","onChangeFilter","onChangeSearch","onChangeSort"],"mappings":";;;MAWaA,iBAAiB,GAAG;SA2BjBC,kBAAkBA,CAC9BC,SAAyC,EACzCC,QAAuC,EACvCC,UAAqC;EAAEC,QAAQ,EAAEL;CAAmB;EAEpE,MAAM;IAAEK;GAAU,GAAGD,OAAO;;EAG5B,MAAME,MAAM,GAAGC,cAAK,CAACC,MAAM,CAAqBC,SAAS,CAAC;;EAE1D,MAAM,CAACC,IAAI,EAAEC,OAAO,CAAC,GAAGJ,cAAK,CAACK,QAAQ,CAAQ,E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TableDataLoader.js","sources":["../../../../../../../src/primitives/Table/useTableDataLoader.ts"],"sourcesContent":["import React from 'react';\nimport {\n TableColumnFilter,\n TableColumnSort,\n TableFilterHandler,\n TableServerLoadPageHandler,\n TableServerLoadAllHandler,\n TableSortHandler,\n TableSearchHandler,\n} from './types';\n\nexport const DEFAULT_PAGE_SIZE = 100;\n\nexport type useTableDataPageFetcher<TType = unknown> = (\n pageIndex: number,\n pageSize: number,\n sorting: TableColumnSort[],\n filters: TableColumnFilter[]\n) => Promise<{ data: TType[]; length: number }>;\n\nexport type useTableDataAllFetcher<TType = unknown> = (\n sorting: TableColumnSort[],\n filters: TableColumnFilter[]\n) => Promise<{ data: TType[]; length: number }>;\n\nexport type useTableDataLoaderOptions = { pageSize: number };\n\nexport type useTableDataLoaderValues<TType = unknown> = {\n data: TType[];\n length: number | undefined;\n loadAll: TableServerLoadAllHandler;\n loadPage: TableServerLoadPageHandler;\n onChangeFilter: TableFilterHandler;\n onChangeSearch: TableSearchHandler;\n onChangeSort: TableSortHandler;\n pageSize: number;\n};\n\nexport function useTableDataLoader<TType = unknown>(\n fetchPage: useTableDataPageFetcher<TType>,\n fetchAll: useTableDataAllFetcher<TType>,\n options: useTableDataLoaderOptions = { pageSize: DEFAULT_PAGE_SIZE }\n): [useTableDataLoaderValues<TType>, () => void] {\n const { pageSize } = options;\n\n // track the data length, we don't know it until the first request\n const length = React.useRef<number | undefined>(undefined);\n // data will be filled after the first request, then we'll update values in place\n const [data, setData] = React.useState<TType[]>([]);\n // track which pages have been loaded to dedupe requests\n const _pendingPageRequests = React.useRef({});\n const _lastUsedSorting = React.useRef<TableColumnSort[]>([]);\n const _lastUsedFilters = React.useRef<TableColumnFilter[]>([]);\n const _lastUsedSearch = React.useRef<string>();\n const _lastUsedPageIndex = React.useRef<number>();\n const _forceReset = React.useRef(false);\n\n const loadPage = async (pageIndex: number, sorting: TableColumnSort[], filters: TableColumnFilter[]) => {\n let reset = false;\n\n // sorting or filters changed, reset everything\n if (\n _forceReset.current ||\n JSON.stringify(sorting) !== JSON.stringify(_lastUsedSorting.current) ||\n JSON.stringify(filters) !== JSON.stringify(_lastUsedFilters.current)\n ) {\n _pendingPageRequests.current = {};\n // nuke the dataset so that we \"start again\" after sorting\n reset = true;\n }\n\n if (_pendingPageRequests.current[pageIndex]) {\n // if page is already loaded/loading, abort, otherwise mark it as loading\n return;\n } else {\n _pendingPageRequests.current[pageIndex] = true;\n }\n\n _forceReset.current = false;\n // set the last page loaded (or tried to load), so that we can load it back again after resets\n _lastUsedPageIndex.current = pageIndex;\n // set the sorting so we can track if it changed between loads\n _lastUsedSorting.current = sorting;\n // set the filters so we can track if it changed between loads\n _lastUsedFilters.current = filters;\n\n try {\n const response = await fetchPage(pageIndex, pageSize, sorting, filters);\n\n // update state, here we do some \"magic\" to support \"load in place\"\n setData(currentData => {\n let nextData;\n\n // reset table state if:\n // - the length isn't set at all (first load)\n // - the client length and server length are different (the data changed)\n if (reset || length.current !== response.length) {\n length.current = response.length;\n nextData = Array(length.current).fill(undefined);\n } else {\n nextData = ([] as TType[]).concat(currentData);\n }\n\n const startIndex = pageIndex * pageSize;\n nextData.splice(startIndex, pageSize, ...response.data);\n return nextData;\n });\n } catch {\n //\n } finally {\n _pendingPageRequests.current[pageIndex] = false;\n }\n };\n\n const loadAll = async (sorting: TableColumnSort[], filters: TableColumnFilter[]) => {\n // set the sorting so we can track if it changed between loads\n _lastUsedSorting.current = sorting;\n // set the filters so we can track if it changed between loads\n _lastUsedFilters.current = filters;\n\n try {\n const response = await fetchAll(sorting, filters);\n length.current = response.length;\n\n setData(() => {\n let nextData;\n\n if (response.data.length !== response.length) {\n nextData = Array(response.length).fill(undefined);\n nextData.splice(0, response.data.length, ...response.data);\n } else {\n nextData = [...response.data];\n }\n\n return nextData;\n });\n } catch {\n //\n }\n };\n\n const invalidate = async () => {\n // empties the entire data array\n _forceReset.current = true;\n\n if (_lastUsedSearch.current) {\n // we're searching, which means we need to refetch all with the correct sorting applied\n return loadAll(_lastUsedSorting.current, _lastUsedFilters.current);\n } else {\n // load the last page that we scrolled to\n return loadPage(_lastUsedPageIndex.current ?? 0, _lastUsedSorting.current, _lastUsedFilters.current);\n }\n };\n\n // search works client side - it fetches all then works client side - so these handlers are a little \"weird\"\n // if a search is currently \"active\", we need to re load all because\n const handleSort = async (sorting: TableColumnSort[]) => {\n if (_lastUsedSearch.current) {\n // we're searching, which means we need to refetch all with the correct sorting applied\n return loadAll(sorting, _lastUsedFilters.current);\n } else {\n // load the last page that we scrolled to\n return loadPage(_lastUsedPageIndex.current ?? 0, sorting, _lastUsedFilters.current);\n }\n };\n const handleFilter = async (filters: TableColumnFilter[]) => {\n if (_lastUsedSearch.current) {\n // we're searching, which means we need to refetch all with the correct sorting applied\n return loadAll(_lastUsedSorting.current, filters);\n } else {\n // load the last page that we scrolled to\n return loadPage(_lastUsedPageIndex.current ?? 0, _lastUsedSorting.current, filters);\n }\n };\n const handleSearch = async (search: string | undefined) => {\n // set the search so we can track if it changed between loads\n _lastUsedSearch.current = search || undefined;\n // search works client side, and focusing the search field triggers a load of all so we don't actually\n // want to load anything when search gets changed, we just store the value for other handlers\n };\n\n return [\n {\n data,\n length: length.current,\n loadAll,\n loadPage,\n onChangeFilter: handleFilter,\n onChangeSearch: handleSearch,\n onChangeSort: handleSort,\n pageSize,\n },\n invalidate,\n ];\n}\n"],"names":["DEFAULT_PAGE_SIZE","useTableDataLoader","fetchPage","fetchAll","options","pageSize","length","React","useRef","undefined","data","setData","useState","_pendingPageRequests","_lastUsedSorting","_lastUsedFilters","_lastUsedSearch","_lastUsedPageIndex","_forceReset","loadPage","pageIndex","sorting","filters","reset","current","JSON","stringify","Promise","resolve","_temp","_finallyRethrows","_catch","then","response","currentData","nextData","Array","fill","concat","startIndex","splice","_wasThrown","_result","e","reject","loadAll","_temp2","invalidate","_lastUsedPageIndex$cu","handleSort","_lastUsedPageIndex$cu2","handleFilter","_lastUsedPageIndex$cu3","handleSearch","search","onChangeFilter","onChangeSearch","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;MAAA,OAAAhB,OAAA,CAAAiB,MAAA,CAAAD,CAAA;;;EAED,OAAO,CACH;IACIjC,IAAI;IACJJ,MAAM,EAAEA,MAAM,CAACkB,OAAO;IACtBqB,OAAO;IACP1B,QAAQ;IACRoC,cAAc,EAAEJ,YAAY;IAC5BK,cAAc,EAAEH,YAAY;IAC5BI,YAAY,EAAER,UAAU;IACxB5C;GACH,EACD0C,UAAU,CACb;AACL;;;;"}
|
@@ -0,0 +1,249 @@
|
|
1
|
+
import React__default from 'react';
|
2
|
+
import { _finallyRethrows, _catch } from '../../../../../node_modules/babel-plugin-transform-async-to-promises/helpers.mjs.js';
|
3
|
+
import { DEFAULT_PAGE_SIZE } from './useTableDataLoader.js';
|
4
|
+
|
5
|
+
const DATASET_SIZE_MULTIPLIER = 15;
|
6
|
+
function useTableDataLoader2(fetchPage, fetchAll, options = {
|
7
|
+
pageSize: DEFAULT_PAGE_SIZE
|
8
|
+
}) {
|
9
|
+
const loadPage = function (pageIndex, sorting, filters, search, hiddenColumns, reset = false) {
|
10
|
+
try {
|
11
|
+
if (_hasFetchedAll.current) {
|
12
|
+
return Promise.resolve();
|
13
|
+
}
|
14
|
+
// if page is already loading, abort, otherwise mark it as loading
|
15
|
+
if (_pendingPageRequests.current[pageIndex]) {
|
16
|
+
return Promise.resolve();
|
17
|
+
} else {
|
18
|
+
_pendingPageRequests.current[pageIndex] = true;
|
19
|
+
}
|
20
|
+
// if the page is already loaded and has actual rows, abort
|
21
|
+
if (data.pages.includes(pageIndex)) {
|
22
|
+
const position = data.pages.indexOf(pageIndex);
|
23
|
+
if (data.rows[position * pageSize] !== undefined) {
|
24
|
+
return Promise.resolve();
|
25
|
+
}
|
26
|
+
}
|
27
|
+
// set the sorting so we can track if it changed between loads
|
28
|
+
_lastUsedSorting.current = sorting;
|
29
|
+
// set the filters so we can track if it changed between loads
|
30
|
+
_lastUsedFilters.current = filters;
|
31
|
+
const direction = getDirection2(pageIndex, _lastFetchedPage.current);
|
32
|
+
const _temp2 = _finallyRethrows(function () {
|
33
|
+
return _catch(function () {
|
34
|
+
return Promise.resolve(fetchPage(pageIndex, pageSize, sorting, filters, search, hiddenColumns)).then(function (response) {
|
35
|
+
length.current = response.length;
|
36
|
+
// update state, here we do some "magic" to support "load in place"
|
37
|
+
setData(currentData => {
|
38
|
+
const nextPages = getPages(pageIndex, _lastFetchedPage.current, reset ? [] : currentData.pages, direction);
|
39
|
+
let nextRows = currentData.rows;
|
40
|
+
if (reset || !direction) {
|
41
|
+
const index = nextPages.indexOf(pageIndex);
|
42
|
+
const startIndex = (index > -1 ? index : 0) * pageSize;
|
43
|
+
if (reset) {
|
44
|
+
nextRows = [].concat(response.data);
|
45
|
+
} else if (startIndex > 0 || pageIndex === 0) {
|
46
|
+
nextRows = Array(startIndex).fill(undefined).concat(response.data);
|
47
|
+
} else if (startIndex === 0) {
|
48
|
+
nextRows = response.data.concat(currentData.rows.slice(pageSize));
|
49
|
+
}
|
50
|
+
} else if (direction === 'forward') {
|
51
|
+
// if the new data will exceed the dataset size, then chop off the start or end
|
52
|
+
// this keeps the stored dataset to our preferred size
|
53
|
+
if (currentData.rows.length >= DATASET_SIZE) {
|
54
|
+
nextRows = currentData.rows.slice(DEFAULT_PAGE_SIZE).concat(response.data);
|
55
|
+
} else {
|
56
|
+
nextRows = currentData.rows.concat(response.data);
|
57
|
+
}
|
58
|
+
} else if (direction === 'backward') {
|
59
|
+
if (currentData.rows.length >= DATASET_SIZE) {
|
60
|
+
nextRows = response.data.concat(currentData.rows.slice(0, -1 * pageSize));
|
61
|
+
} else {
|
62
|
+
nextRows = currentData.rows.concat(response.data);
|
63
|
+
}
|
64
|
+
}
|
65
|
+
return {
|
66
|
+
rows: nextRows,
|
67
|
+
pages: nextPages
|
68
|
+
};
|
69
|
+
});
|
70
|
+
});
|
71
|
+
}, function () {});
|
72
|
+
}, function (_wasThrown2, _result2) {
|
73
|
+
_hasFetchedAll.current = false;
|
74
|
+
// reset pending requests
|
75
|
+
delete _pendingPageRequests.current[pageIndex];
|
76
|
+
// update the last loaded page
|
77
|
+
_lastFetchedPage.current = {
|
78
|
+
index: pageIndex,
|
79
|
+
direction
|
80
|
+
};
|
81
|
+
if (_wasThrown2) throw _result2;
|
82
|
+
return _result2;
|
83
|
+
});
|
84
|
+
return Promise.resolve(_temp2 && _temp2.then ? _temp2.then(function () {}) : void 0);
|
85
|
+
} catch (e) {
|
86
|
+
return Promise.reject(e);
|
87
|
+
}
|
88
|
+
};
|
89
|
+
const {
|
90
|
+
pageSize
|
91
|
+
} = options;
|
92
|
+
const DATASET_SIZE = DATASET_SIZE_MULTIPLIER * pageSize;
|
93
|
+
// track the data length, we don't know it until the first request
|
94
|
+
const length = React__default.useRef(0);
|
95
|
+
// data will be filled after the first request
|
96
|
+
const [data, setData] = React__default.useState({
|
97
|
+
rows: [],
|
98
|
+
pages: []
|
99
|
+
});
|
100
|
+
// track which pages have been loaded to dedupe requests
|
101
|
+
const _pendingPageRequests = React__default.useRef({});
|
102
|
+
const _lastUsedSorting = React__default.useRef([]);
|
103
|
+
const _lastUsedFilters = React__default.useRef([]);
|
104
|
+
const _lastUsedSearch = React__default.useRef();
|
105
|
+
const _lastUsedHiddenColumns = React__default.useRef([]);
|
106
|
+
const _lastFetchedPage = React__default.useRef({
|
107
|
+
index: undefined,
|
108
|
+
direction: undefined
|
109
|
+
});
|
110
|
+
const _hasFetchedAll = React__default.useRef(false);
|
111
|
+
const loadAll = function (sorting, filters, search, hiddenColumns) {
|
112
|
+
try {
|
113
|
+
_hasFetchedAll.current = true;
|
114
|
+
// set the sorting so we can track if it changed between loads
|
115
|
+
_lastUsedSorting.current = sorting;
|
116
|
+
// set the filters so we can track if it changed between loads
|
117
|
+
_lastUsedFilters.current = filters;
|
118
|
+
const _temp = _finallyRethrows(function () {
|
119
|
+
return _catch(function () {
|
120
|
+
return Promise.resolve(fetchAll(sorting, filters, search, hiddenColumns)).then(function (response) {
|
121
|
+
length.current = response.length;
|
122
|
+
setData({
|
123
|
+
rows: response.data,
|
124
|
+
pages: Array.from(Array(response.length / pageSize).keys())
|
125
|
+
});
|
126
|
+
});
|
127
|
+
}, function () {});
|
128
|
+
}, function (_wasThrown, _result) {
|
129
|
+
// reset pending requests
|
130
|
+
_pendingPageRequests.current = {};
|
131
|
+
if (_wasThrown) throw _result;
|
132
|
+
return _result;
|
133
|
+
});
|
134
|
+
return Promise.resolve(_temp && _temp.then ? _temp.then(function () {}) : void 0);
|
135
|
+
} catch (e) {
|
136
|
+
return Promise.reject(e);
|
137
|
+
}
|
138
|
+
};
|
139
|
+
const invalidate = function () {
|
140
|
+
try {
|
141
|
+
// reset stuff
|
142
|
+
_pendingPageRequests.current = {};
|
143
|
+
_hasFetchedAll.current = false;
|
144
|
+
// load the last page that we scrolled to
|
145
|
+
return loadPage(getCurrentPage(data.pages, _lastFetchedPage.current), _lastUsedSorting.current, _lastUsedFilters.current, _lastUsedSearch.current, _lastUsedHiddenColumns.current, true);
|
146
|
+
} catch (e) {
|
147
|
+
return Promise.reject(e);
|
148
|
+
}
|
149
|
+
};
|
150
|
+
// search works client side - it fetches all then works client side - so these handlers are a little "weird"
|
151
|
+
// if a search is currently "active", we need to re load all because
|
152
|
+
const handleSort = function (sorting) {
|
153
|
+
try {
|
154
|
+
_lastUsedSorting.current = sorting;
|
155
|
+
// reset stuff
|
156
|
+
_pendingPageRequests.current = {};
|
157
|
+
_hasFetchedAll.current = false;
|
158
|
+
return loadPage(getCurrentPage(data.pages, _lastFetchedPage.current), sorting, _lastUsedFilters.current, _lastUsedSearch.current, _lastUsedHiddenColumns.current, true);
|
159
|
+
} catch (e) {
|
160
|
+
return Promise.reject(e);
|
161
|
+
}
|
162
|
+
};
|
163
|
+
const handleFilter = function (filters, hiddenColumns) {
|
164
|
+
try {
|
165
|
+
_lastUsedFilters.current = filters;
|
166
|
+
_lastUsedHiddenColumns.current = hiddenColumns;
|
167
|
+
// reset stuff
|
168
|
+
_pendingPageRequests.current = {};
|
169
|
+
_hasFetchedAll.current = false;
|
170
|
+
return loadPage(getCurrentPage(data.pages, _lastFetchedPage.current), _lastUsedSorting.current, filters, _lastUsedSearch.current, hiddenColumns, true);
|
171
|
+
} catch (e) {
|
172
|
+
return Promise.reject(e);
|
173
|
+
}
|
174
|
+
};
|
175
|
+
const handleSearch = function (search, hiddenColumns) {
|
176
|
+
try {
|
177
|
+
_lastUsedSearch.current = search;
|
178
|
+
_lastUsedHiddenColumns.current = hiddenColumns;
|
179
|
+
// reset stuff
|
180
|
+
_pendingPageRequests.current = {};
|
181
|
+
_hasFetchedAll.current = false;
|
182
|
+
return loadPage(getCurrentPage(data.pages, _lastFetchedPage.current), _lastUsedSorting.current, _lastUsedFilters.current, search, hiddenColumns, true);
|
183
|
+
} catch (e) {
|
184
|
+
return Promise.reject(e);
|
185
|
+
}
|
186
|
+
};
|
187
|
+
return [{
|
188
|
+
data: data.rows,
|
189
|
+
pages: data.pages,
|
190
|
+
length: length.current,
|
191
|
+
loadAll,
|
192
|
+
loadPage,
|
193
|
+
onChangeFilter: handleFilter,
|
194
|
+
onChangeSearch: handleSearch,
|
195
|
+
onChangeSort: handleSort,
|
196
|
+
pageSize,
|
197
|
+
_experimentalDataLoader2: true
|
198
|
+
}, invalidate];
|
199
|
+
}
|
200
|
+
function getCurrentPage(currentPages, lastFetchedPage) {
|
201
|
+
if (currentPages.length <= 2) {
|
202
|
+
var _currentPages$;
|
203
|
+
return (_currentPages$ = currentPages[0]) !== null && _currentPages$ !== void 0 ? _currentPages$ : 0;
|
204
|
+
}
|
205
|
+
const middle = Math.floor(DATASET_SIZE_MULTIPLIER / 2);
|
206
|
+
if (lastFetchedPage.index) {
|
207
|
+
if (!lastFetchedPage.direction) {
|
208
|
+
return lastFetchedPage.index;
|
209
|
+
}
|
210
|
+
return lastFetchedPage.direction === 'forward' ? lastFetchedPage.index + middle : lastFetchedPage.index - middle;
|
211
|
+
}
|
212
|
+
return 0;
|
213
|
+
}
|
214
|
+
function getDirection2(pageIndex, lastUsedPage) {
|
215
|
+
if (lastUsedPage.index === undefined) {
|
216
|
+
return undefined;
|
217
|
+
}
|
218
|
+
if (pageIndex > lastUsedPage.index) {
|
219
|
+
if (lastUsedPage.index + 1 === pageIndex || lastUsedPage.index + DATASET_SIZE_MULTIPLIER === pageIndex) {
|
220
|
+
return 'forward';
|
221
|
+
}
|
222
|
+
} else if (pageIndex < lastUsedPage.index) {
|
223
|
+
if (lastUsedPage.index - 1 === pageIndex || lastUsedPage.index - DATASET_SIZE_MULTIPLIER === pageIndex) {
|
224
|
+
return 'backward';
|
225
|
+
}
|
226
|
+
}
|
227
|
+
return undefined;
|
228
|
+
}
|
229
|
+
function getPages(pageIndex, lastUsedPage, currentPages, direction) {
|
230
|
+
if (currentPages.length && (pageIndex === lastUsedPage.index || currentPages.includes(pageIndex))) {
|
231
|
+
return currentPages;
|
232
|
+
}
|
233
|
+
if (direction === 'forward') {
|
234
|
+
const nextPages = currentPages.length === DATASET_SIZE_MULTIPLIER ? currentPages.slice(1) : currentPages;
|
235
|
+
return nextPages.concat(pageIndex);
|
236
|
+
}
|
237
|
+
if (direction === 'backward') {
|
238
|
+
const nextPages = currentPages.length === DATASET_SIZE_MULTIPLIER ? currentPages.slice(0, -1) : currentPages;
|
239
|
+
return [pageIndex].concat(nextPages);
|
240
|
+
}
|
241
|
+
if (pageIndex === 0) {
|
242
|
+
return [0];
|
243
|
+
}
|
244
|
+
// don't go forward, the current page will trigger load of the next page
|
245
|
+
return [pageIndex - 1, pageIndex];
|
246
|
+
}
|
247
|
+
|
248
|
+
export { useTableDataLoader2 };
|
249
|
+
//# sourceMappingURL=useTableDataLoader2.js.map
|
@@ -0,0 +1 @@
|
|
1
|
+
{"version":3,"file":"useTableDataLoader2.js","sources":["../../../../../../../src/primitives/Table/useTableDataLoader2.ts"],"sourcesContent":["import React from 'react';\nimport {\n TableColumnFilter,\n TableColumnSort,\n TableFilterHandler,\n TableServerLoadPageHandler,\n TableServerLoadAllHandler,\n TableSortHandler,\n TableSearchHandler,\n} from './types';\nimport { DEFAULT_PAGE_SIZE, useTableDataLoaderOptions } from './useTableDataLoader';\n\nconst DATASET_SIZE_MULTIPLIER = 15;\n\nexport type useTableDataPageFetcher2<TType = unknown> = (\n pageIndex: number,\n pageSize: number,\n sorting: TableColumnSort[],\n filters: TableColumnFilter[],\n search: string | undefined,\n hiddenColumns: string[]\n) => Promise<{ data: TType[]; length: number }>;\n\nexport type useTableDataAllFetcher2<TType = unknown> = (\n sorting: TableColumnSort[],\n filters: TableColumnFilter[],\n search: string | undefined,\n hiddenColumns: string[]\n) => Promise<{ data: TType[]; length: number }>;\n\nexport type useTableDataLoaderValues2<TType = unknown> = {\n data: TType[];\n length: number | undefined;\n loadAll: TableServerLoadAllHandler;\n loadPage: TableServerLoadPageHandler;\n onChangeFilter: TableFilterHandler;\n onChangeSearch: TableSearchHandler;\n onChangeSort: TableSortHandler;\n pageSize: number;\n pages: number[];\n _experimentalDataLoader2: boolean;\n};\n\ntype Data<TType = unknown> = {\n rows: TType[];\n pages: number[];\n};\ntype Direction = 'forward' | 'backward' | undefined;\ntype LastFetchedPage = {\n index: number | undefined;\n direction: Direction;\n};\n\nexport function useTableDataLoader2<TType = unknown>(\n fetchPage: useTableDataPageFetcher2<TType>,\n fetchAll: useTableDataAllFetcher2<TType>,\n options: useTableDataLoaderOptions = { pageSize: DEFAULT_PAGE_SIZE }\n): [useTableDataLoaderValues2<TType>, () => void] {\n const { pageSize } = options;\n const DATASET_SIZE = DATASET_SIZE_MULTIPLIER * pageSize;\n\n // track the data length, we don't know it until the first request\n const length = React.useRef<number>(0);\n // data will be filled after the first request\n const [data, setData] = React.useState<Data<TType>>({ rows: [], pages: [] });\n // track which pages have been loaded to dedupe requests\n const _pendingPageRequests = React.useRef({});\n const _lastUsedSorting = React.useRef<TableColumnSort[]>([]);\n const _lastUsedFilters = React.useRef<TableColumnFilter[]>([]);\n const _lastUsedSearch = React.useRef<string | undefined>();\n const _lastUsedHiddenColumns = React.useRef<string[]>([]);\n const _lastFetchedPage = React.useRef<LastFetchedPage>({\n index: undefined,\n direction: undefined,\n });\n const _hasFetchedAll = React.useRef<boolean>(false);\n\n async function loadPage(\n pageIndex: number,\n sorting: TableColumnSort[],\n filters: TableColumnFilter[],\n search: string | undefined,\n hiddenColumns: string[],\n reset = false\n ) {\n if (_hasFetchedAll.current) {\n return;\n }\n\n // if page is already loading, abort, otherwise mark it as loading\n if (_pendingPageRequests.current[pageIndex]) {\n return;\n } else {\n _pendingPageRequests.current[pageIndex] = true;\n }\n\n // if the page is already loaded and has actual rows, abort\n if (data.pages.includes(pageIndex)) {\n const position = data.pages.indexOf(pageIndex);\n\n if (data.rows[position * pageSize] !== undefined) {\n return;\n }\n }\n\n // set the sorting so we can track if it changed between loads\n _lastUsedSorting.current = sorting;\n // set the filters so we can track if it changed between loads\n _lastUsedFilters.current = filters;\n\n const direction = getDirection2(pageIndex, _lastFetchedPage.current);\n\n try {\n const response = await fetchPage(pageIndex, pageSize, sorting, filters, search, hiddenColumns);\n length.current = response.length;\n\n // update state, here we do some \"magic\" to support \"load in place\"\n setData(currentData => {\n const nextPages = getPages(pageIndex, _lastFetchedPage.current, reset ? [] : currentData.pages, direction);\n let nextRows = currentData.rows;\n\n if (reset || !direction) {\n const index = nextPages.indexOf(pageIndex);\n const startIndex = (index > -1 ? index : 0) * pageSize;\n\n if (reset) {\n nextRows = ([] as TType[]).concat(response.data);\n } else if (startIndex > 0 || pageIndex === 0) {\n nextRows = Array(startIndex).fill(undefined).concat(response.data);\n } else if (startIndex === 0) {\n nextRows = response.data.concat(currentData.rows.slice(pageSize));\n }\n } else if (direction === 'forward') {\n // if the new data will exceed the dataset size, then chop off the start or end\n // this keeps the stored dataset to our preferred size\n if (currentData.rows.length >= DATASET_SIZE) {\n nextRows = currentData.rows.slice(DEFAULT_PAGE_SIZE).concat(response.data);\n } else {\n nextRows = currentData.rows.concat(response.data);\n }\n } else if (direction === 'backward') {\n if (currentData.rows.length >= DATASET_SIZE) {\n nextRows = response.data.concat(currentData.rows.slice(0, -1 * pageSize));\n } else {\n nextRows = currentData.rows.concat(response.data);\n }\n }\n\n return {\n rows: nextRows,\n pages: nextPages,\n };\n });\n } catch {\n //\n } finally {\n _hasFetchedAll.current = false;\n // reset pending requests\n delete _pendingPageRequests.current[pageIndex];\n // update the last loaded page\n _lastFetchedPage.current = {\n index: pageIndex,\n direction,\n };\n }\n }\n\n const loadAll = async (\n sorting: TableColumnSort[],\n filters: TableColumnFilter[],\n search: string | undefined,\n hiddenColumns: string[]\n ) => {\n _hasFetchedAll.current = true;\n // set the sorting so we can track if it changed between loads\n _lastUsedSorting.current = sorting;\n // set the filters so we can track if it changed between loads\n _lastUsedFilters.current = filters;\n\n try {\n const response = await fetchAll(sorting, filters, search, hiddenColumns);\n length.current = response.length;\n\n setData({\n rows: response.data,\n pages: Array.from(Array(response.length / pageSize).keys()),\n });\n } catch {\n //\n } finally {\n // reset pending requests\n _pendingPageRequests.current = {};\n }\n };\n\n const invalidate = async () => {\n // reset stuff\n _pendingPageRequests.current = {};\n _hasFetchedAll.current = false;\n\n // load the last page that we scrolled to\n return loadPage(\n getCurrentPage(data.pages, _lastFetchedPage.current),\n _lastUsedSorting.current,\n _lastUsedFilters.current,\n _lastUsedSearch.current,\n _lastUsedHiddenColumns.current,\n true\n );\n };\n\n // search works client side - it fetches all then works client side - so these handlers are a little \"weird\"\n // if a search is currently \"active\", we need to re load all because\n const handleSort = async (sorting: TableColumnSort[]) => {\n _lastUsedSorting.current = sorting;\n // reset stuff\n _pendingPageRequests.current = {};\n _hasFetchedAll.current = false;\n\n return loadPage(\n getCurrentPage(data.pages, _lastFetchedPage.current),\n sorting,\n _lastUsedFilters.current,\n _lastUsedSearch.current,\n _lastUsedHiddenColumns.current,\n true\n );\n };\n const handleFilter = async (filters: TableColumnFilter[], hiddenColumns: string[]) => {\n _lastUsedFilters.current = filters;\n _lastUsedHiddenColumns.current = hiddenColumns;\n\n // reset stuff\n _pendingPageRequests.current = {};\n _hasFetchedAll.current = false;\n\n return loadPage(\n getCurrentPage(data.pages, _lastFetchedPage.current),\n _lastUsedSorting.current,\n filters,\n _lastUsedSearch.current,\n hiddenColumns,\n true\n );\n };\n const handleSearch = async (search: string | undefined, hiddenColumns: string[]) => {\n _lastUsedSearch.current = search;\n _lastUsedHiddenColumns.current = hiddenColumns;\n\n // reset stuff\n _pendingPageRequests.current = {};\n _hasFetchedAll.current = false;\n\n return loadPage(\n getCurrentPage(data.pages, _lastFetchedPage.current),\n _lastUsedSorting.current,\n _lastUsedFilters.current,\n search,\n hiddenColumns,\n true\n );\n };\n\n return [\n {\n data: data.rows,\n pages: data.pages,\n length: length.current,\n loadAll,\n loadPage,\n onChangeFilter: handleFilter,\n onChangeSearch: handleSearch,\n onChangeSort: handleSort,\n pageSize,\n _experimentalDataLoader2: true,\n },\n invalidate,\n ];\n}\n\nfunction getCurrentPage(currentPages: number[], lastFetchedPage: LastFetchedPage): number {\n if (currentPages.length <= 2) {\n return currentPages[0] ?? 0;\n }\n\n const middle = Math.floor(DATASET_SIZE_MULTIPLIER / 2);\n\n if (lastFetchedPage.index) {\n if (!lastFetchedPage.direction) {\n return lastFetchedPage.index;\n }\n\n return lastFetchedPage.direction === 'forward' ? lastFetchedPage.index + middle : lastFetchedPage.index - middle;\n }\n\n return 0;\n}\n\nfunction getDirection2(pageIndex: number, lastUsedPage: LastFetchedPage): Direction {\n if (lastUsedPage.index === undefined) {\n return undefined;\n }\n\n if (pageIndex > lastUsedPage.index) {\n if (lastUsedPage.index + 1 === pageIndex || lastUsedPage.index + DATASET_SIZE_MULTIPLIER === pageIndex) {\n return 'forward';\n }\n } else if (pageIndex < lastUsedPage.index) {\n if (lastUsedPage.index - 1 === pageIndex || lastUsedPage.index - DATASET_SIZE_MULTIPLIER === pageIndex) {\n return 'backward';\n }\n }\n\n return undefined;\n}\n\nfunction getPages(pageIndex: number, lastUsedPage: LastFetchedPage, currentPages: number[], direction: Direction) {\n if (currentPages.length && (pageIndex === lastUsedPage.index || currentPages.includes(pageIndex))) {\n return currentPages;\n }\n\n if (direction === 'forward') {\n const nextPages = currentPages.length === DATASET_SIZE_MULTIPLIER ? currentPages.slice(1) : currentPages;\n return nextPages.concat(pageIndex);\n }\n\n if (direction === 'backward') {\n const nextPages = currentPages.length === DATASET_SIZE_MULTIPLIER ? currentPages.slice(0, -1) : currentPages;\n return [pageIndex].concat(nextPages);\n }\n\n if (pageIndex === 0) {\n return [0];\n }\n\n // don't go forward, the current page will trigger load of the next page\n return [pageIndex - 1, pageIndex];\n}\n"],"names":["DATASET_SIZE_MULTIPLIER","useTableDataLoader2","fetchPage","fetchAll","options","pageSize","DEFAULT_PAGE_SIZE","loadPage","pageIndex","sorting","filters","search","hiddenColumns","reset","_hasFetchedAll","current","Promise","resolve","_pendingPageRequests","data","pages","includes","position","indexOf","rows","undefined","_lastUsedSorting","_lastUsedFilters","direction","getDirection2","_lastFetchedPage","_temp2","_finallyRethrows","_catch","then","response","length","setData","currentData","nextPages","getPages","nextRows","index","startIndex","concat","Array","fill","slice","DATASET_SIZE","_wasThrown2","_result2","e","reject","React","useRef","useState","_lastUsedSearch","_lastUsedHiddenColumns","loadAll","_temp","from","keys","_wasThrown","_result","invalidate","getCurrentPage","handleSort","handleFilter","handleSearch","onChangeFilter","onChangeSearch","onChangeSort","_experimentalDataLoader2","currentPages","lastFetchedPage","_currentPages$","middle","Math","floor","lastUsedPage"],"mappings":";;;;AAYA,MAAMA,uBAAuB,GAAG,EAAE;SAyClBC,mBAAmBA,CAC/BC,SAA0C,EAC1CC,QAAwC,EACxCC,UAAqC;EAAEC,QAAQ,EAAEC;CAAmB;QAqBrDC,QAAQ,aACnBC,SAAiB,EACjBC,OAA0B,EAC1BC,OAA4B,EAC5BC,MAA0B,EAC1BC,aAAuB,EACvBC,KAAK,GAAG,KAAK;IAAA;MAEb,IAAIC,cAAc,CAACC,OAAO,EAAE;QACxB,OAAAC,OAAA,CAAAC,OAAA;;;MAIJ,IAAIC,oBAAoB,CAACH,OAAO,CAACP,S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,OAAO,CAACjE,SAAS,CAAC,CAACoC,MAAM,CAACL,SAAS,CAAC;;EAGxC,IAAI/B,SAAS,KAAK,CAAC,EAAE;IACjB,OAAO,CAAC,CAAC,CAAC;;;EAId,OAAO,CAACA,SAAS,GAAG,CAAC,EAAEA,SAAS,CAAC;AACrC;;;;"}
|
@@ -1 +1 @@
|
|
1
|
-
{"version":3,"file":"useTableRowActive.js","sources":["../../../../../../../../../src/primitives/Table/useTableManager/features/useTableRowActive.ts"],"sourcesContent":["import React from 'react';\nimport { TableScrollToIndexHandler } from '../../types';\nimport { useIsHoverStatePaused } from '../../../../hooks/useIsHoverStatePaused';\nimport { isElementInsideOrTriggeredFromContainer } from '../../../../utils/dom';\n\nexport function useTableRowActive(isEnabled = false, initialRowActiveIndex?: number) {\n const [rowActiveIndex, setRowActiveIndex] = React.useState<number | undefined>(initialRowActiveIndex);\n const [rowHoverIndex, setRowHoverIndex] = React.useState<number | undefined>(undefined);\n const [isHoverStatePaused, setHoverStatePaused] = useIsHoverStatePaused();\n\n const move = (direction: -1 | 1, length: number, scrollToIndex: TableScrollToIndexHandler) => {\n const nextIndex = rowActiveIndex !== undefined ? getNextIndex(direction, rowActiveIndex, length) : 0;\n scrollToIndex(nextIndex);\n setTimeout(() => setRowActiveIndex(nextIndex), 50);\n };\n\n const onKeyDown = React.useCallback(\n (event: KeyboardEvent, length: number, scrollToIndex: TableScrollToIndexHandler) => {\n if (!isEnabled || event.defaultPrevented) {\n return;\n }\n\n if (event.key === 'ArrowUp' || event.key === 'ArrowDown') {\n setHoverStatePaused(true);\n }\n\n if (event.key === 'ArrowUp') {\n event.preventDefault();\n\n if (event.ctrlKey || event.metaKey) {\n const newIndex = 0;\n scrollToIndex(newIndex);\n setRowActiveIndex(newIndex);\n } else {\n move(-1, length, scrollToIndex);\n }\n\n return;\n } else if (event.key === 'ArrowDown') {\n event.preventDefault();\n\n if (event.ctrlKey || event.metaKey) {\n const newIndex = length - 1;\n scrollToIndex(newIndex);\n setRowActiveIndex(newIndex);\n } else {\n move(+1, length, scrollToIndex);\n }\n return;\n }\n },\n [isEnabled, rowActiveIndex]\n );\n\n const onFocus = React.useCallback(\n (event: React.FocusEvent, length: number, scrollToIndex: TableScrollToIndexHandler) => {\n if (!isEnabled || event.isDefaultPrevented()) {\n return;\n }\n\n if (event.target.closest('tbody') || isElementInsideOrTriggeredFromContainer(event.target, event.currentTarget)) {\n return;\n }\n\n if (rowActiveIndex === undefined && length > 0) {\n setRowActiveIndex(index => {\n if (index === undefined) {\n scrollToIndex(0);\n return 0;\n }\n return index;\n });\n }\n },\n [rowActiveIndex,
|
1
|
+
{"version":3,"file":"useTableRowActive.js","sources":["../../../../../../../../../src/primitives/Table/useTableManager/features/useTableRowActive.ts"],"sourcesContent":["import React from 'react';\nimport { TableScrollToIndexHandler } from '../../types';\nimport { useIsHoverStatePaused } from '../../../../hooks/useIsHoverStatePaused';\nimport { isElementInsideOrTriggeredFromContainer } from '../../../../utils/dom';\n\nexport function useTableRowActive(isEnabled = false, initialRowActiveIndex?: number) {\n const [rowActiveIndex, setRowActiveIndex] = React.useState<number | undefined>(initialRowActiveIndex);\n const [rowHoverIndex, setRowHoverIndex] = React.useState<number | undefined>(undefined);\n const [isHoverStatePaused, setHoverStatePaused] = useIsHoverStatePaused();\n\n const move = (direction: -1 | 1, length: number, scrollToIndex: TableScrollToIndexHandler) => {\n const nextIndex = rowActiveIndex !== undefined ? getNextIndex(direction, rowActiveIndex, length) : 0;\n scrollToIndex(nextIndex);\n setTimeout(() => setRowActiveIndex(nextIndex), 50);\n };\n\n const onKeyDown = React.useCallback(\n (event: KeyboardEvent, length: number, scrollToIndex: TableScrollToIndexHandler) => {\n if (!isEnabled || event.defaultPrevented) {\n return;\n }\n\n if (event.key === 'ArrowUp' || event.key === 'ArrowDown') {\n setHoverStatePaused(true);\n }\n\n if (event.key === 'ArrowUp') {\n event.preventDefault();\n\n if (event.ctrlKey || event.metaKey) {\n const newIndex = 0;\n scrollToIndex(newIndex);\n setRowActiveIndex(newIndex);\n } else {\n move(-1, length, scrollToIndex);\n }\n\n return;\n } else if (event.key === 'ArrowDown') {\n event.preventDefault();\n\n if (event.ctrlKey || event.metaKey) {\n const newIndex = length - 1;\n scrollToIndex(newIndex);\n setRowActiveIndex(newIndex);\n } else {\n move(+1, length, scrollToIndex);\n }\n return;\n }\n },\n [isEnabled, rowActiveIndex]\n );\n\n const onFocus = React.useCallback(\n (event: React.FocusEvent, length: number, scrollToIndex: TableScrollToIndexHandler) => {\n if (!isEnabled || event.isDefaultPrevented()) {\n return;\n }\n\n if (event.target.closest('tbody') || isElementInsideOrTriggeredFromContainer(event.target, event.currentTarget)) {\n return;\n }\n\n if (rowActiveIndex === undefined && length > 0) {\n setRowActiveIndex(index => {\n if (index === undefined) {\n scrollToIndex(0);\n return 0;\n }\n return index;\n });\n }\n },\n [rowActiveIndex, isEnabled]\n );\n\n return {\n isEnabled,\n rowActiveIndex,\n setRowActiveIndex: isEnabled ? setRowActiveIndex : () => undefined,\n rowHoverIndex,\n setRowHoverIndex,\n isHoverStatePaused,\n setHoverStatePaused: isEnabled ? setHoverStatePaused : () => undefined,\n handleFocus: isEnabled ? onFocus : () => undefined,\n handleKeyDown: isEnabled ? onKeyDown : () => undefined,\n };\n}\n\nfunction getNextIndex(direction: -1 | 1, currentIndex: number, length: number) {\n if (direction === -1) {\n return currentIndex - 1 > 0 ? currentIndex - 1 : 0;\n }\n\n return currentIndex + 1 < length ? currentIndex + 1 : currentIndex;\n}\n"],"names":["useTableRowActive","isEnabled","initialRowActiveIndex","rowActiveIndex","setRowActiveIndex","React","useState","rowHoverIndex","setRowHoverIndex","undefined","isHoverStatePaused","setHoverStatePaused","useIsHoverStatePaused","move","direction","length","scrollToIndex","nextIndex","getNextIndex","setTimeout","onKeyDown","useCallback","event","defaultPrevented","key","preventDefault","ctrlKey","metaKey","newIndex","onFocus","isDefaultPrevented","target","closest","isElementInsideOrTriggeredFromContainer","currentTarget","index","handleFocus","handleKeyDown","currentInd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,GAAG4B,OAAO,GAAG,MAAMpB,SAAS;IAClD4B,aAAa,EAAEpC,SAAS,GAAGmB,SAAS,GAAG,MAAMX;GAChD;AACL;AAEA,SAASS,YAAYA,CAACJ,SAAiB,EAAEwB,YAAoB,EAAEvB,MAAc;EACzE,IAAID,SAAS,KAAK,CAAC,CAAC,EAAE;IAClB,OAAOwB,YAAY,GAAG,CAAC,GAAG,CAAC,GAAGA,YAAY,GAAG,CAAC,GAAG,CAAC;;EAGtD,OAAOA,YAAY,GAAG,CAAC,GAAGvB,MAAM,GAAGuB,YAAY,GAAG,CAAC,GAAGA,YAAY;AACtE;;;;"}
|
package/dist/esm/packages/taco/src/primitives/Table/useTableManager/features/useTableRowExpansion.js
CHANGED
@@ -1,6 +1,7 @@
|
|
1
|
-
function useTableRowExpansion(isEnabled = false, rowExpansionRenderer) {
|
1
|
+
function useTableRowExpansion(isEnabled = false, canExpandAll = true, rowExpansionRenderer) {
|
2
2
|
return {
|
3
3
|
isEnabled,
|
4
|
+
canExpandAll,
|
4
5
|
rowExpansionRenderer: isEnabled ? rowExpansionRenderer : undefined
|
5
6
|
};
|
6
7
|
}
|
@@ -1 +1 @@
|
|
1
|
-
{"version":3,"file":"useTableRowExpansion.js","sources":["../../../../../../../../../src/primitives/Table/useTableManager/features/useTableRowExpansion.ts"],"sourcesContent":["import { TableRowExpansionRenderer } from '../../types';\n\nexport function useTableRowExpansion<TType = unknown>(\n isEnabled = false,\n rowExpansionRenderer?: TableRowExpansionRenderer<TType>\n) {\n return {\n isEnabled,\n rowExpansionRenderer: isEnabled ? rowExpansionRenderer : undefined,\n };\n}\n"],"names":["useTableRowExpansion","isEnabled","rowExpansionRenderer","undefined"],"mappings":"SAEgBA,oBAAoBA,CAChCC,SAAS,GAAG,KAAK,EACjBC,oBAAuD;EAEvD,OAAO;
|
1
|
+
{"version":3,"file":"useTableRowExpansion.js","sources":["../../../../../../../../../src/primitives/Table/useTableManager/features/useTableRowExpansion.ts"],"sourcesContent":["import { TableRowExpansionRenderer } from '../../types';\n\nexport function useTableRowExpansion<TType = unknown>(\n isEnabled = false,\n canExpandAll = true,\n rowExpansionRenderer?: TableRowExpansionRenderer<TType>\n) {\n return {\n isEnabled,\n canExpandAll,\n rowExpansionRenderer: isEnabled ? rowExpansionRenderer : undefined,\n };\n}\n"],"names":["useTableRowExpansion","isEnabled","canExpandAll","rowExpansionRenderer","undefined"],"mappings":"SAEgBA,oBAAoBA,CAChCC,SAAS,GAAG,KAAK,EACjBC,YAAY,GAAG,IAAI,EACnBC,oBAAuD;EAEvD,OAAO;IACHF,SAAS;IACTC,YAAY;IACZC,oBAAoB,EAAEF,SAAS,GAAGE,oBAAoB,GAAGC;GAC5D;AACL;;;;"}
|
package/dist/esm/packages/taco/src/primitives/Table/useTableManager/features/useTableSearch.js
CHANGED
@@ -5,7 +5,7 @@ import React__default from 'react';
|
|
5
5
|
- Highlighting search results, this is custom and only uses the state part of globalFilter (to store the search query)
|
6
6
|
- Filtering of results, this is essentially the built in filtering, and relies on enableGlobalFilter being on or off
|
7
7
|
*/
|
8
|
-
function useTableSearch(isEnabled = false, defaultEnableGlobalFilter = false) {
|
8
|
+
function useTableSearch(isEnabled = false, onChangeSearch, defaultEnableGlobalFilter = false) {
|
9
9
|
const [enableGlobalFilter, _setEnableGlobalFilter] = React__default.useState(defaultEnableGlobalFilter);
|
10
10
|
function setEnableGlobalFilter(enabled, instance) {
|
11
11
|
_setEnableGlobalFilter(enabled);
|
@@ -30,7 +30,8 @@ function useTableSearch(isEnabled = false, defaultEnableGlobalFilter = false) {
|
|
30
30
|
highlightedColumnIndexes,
|
31
31
|
setHighlightedColumnIndexes,
|
32
32
|
currentHighlightColumnIndex,
|
33
|
-
setCurrentHighlightColumnIndex
|
33
|
+
setCurrentHighlightColumnIndex,
|
34
|
+
handleSearch: isEnabled && typeof onChangeSearch === 'function' ? onChangeSearch : undefined
|
34
35
|
};
|
35
36
|
}
|
36
37
|
|
package/dist/esm/packages/taco/src/primitives/Table/useTableManager/features/useTableSearch.js.map
CHANGED
@@ -1 +1 @@
|
|
1
|
-
{"version":3,"file":"useTableSearch.js","sources":["../../../../../../../../../src/primitives/Table/useTableManager/features/useTableSearch.ts"],"sourcesContent":["import React from 'react';\nimport { Table as ReactTable } from '@tanstack/react-table';\n\n/*\n Search has two behaviours:\n - Highlighting search results, this is custom and only uses the state part of globalFilter (to store the search query)\n - Filtering of results, this is essentially the built in filtering, and relies on enableGlobalFilter being on or off\n*/\nexport function useTableSearch(isEnabled = false
|
1
|
+
{"version":3,"file":"useTableSearch.js","sources":["../../../../../../../../../src/primitives/Table/useTableManager/features/useTableSearch.ts"],"sourcesContent":["import React from 'react';\nimport { Table as ReactTable } from '@tanstack/react-table';\nimport { TableSearchHandler } from '../../types';\n\n/*\n Search has two behaviours:\n - Highlighting search results, this is custom and only uses the state part of globalFilter (to store the search query)\n - Filtering of results, this is essentially the built in filtering, and relies on enableGlobalFilter being on or off\n*/\nexport function useTableSearch<TType = unknown>(\n isEnabled = false,\n onChangeSearch: TableSearchHandler | undefined,\n defaultEnableGlobalFilter = false\n) {\n const [enableGlobalFilter, _setEnableGlobalFilter] = React.useState<boolean>(defaultEnableGlobalFilter);\n\n function setEnableGlobalFilter<T extends TType>(enabled: boolean, instance: ReactTable<T>) {\n _setEnableGlobalFilter(enabled);\n\n // react-table doesn't re-render when options.enableGlobalFilter changes, so for now we force it\n const currentFilter = instance.getState().globalFilter;\n\n if (currentFilter) {\n setTimeout(() => {\n instance.setGlobalFilter('');\n instance.setGlobalFilter(currentFilter);\n }, 1);\n }\n }\n\n // highlighting\n const [highlightedColumnIndexes, setHighlightedColumnIndexes] = React.useState<number[][]>([]);\n const [currentHighlightColumnIndex, setCurrentHighlightColumnIndex] = React.useState<number | undefined>(undefined);\n\n return {\n isEnabled,\n // filtering - built-in\n enableGlobalFilter,\n setEnableGlobalFilter,\n // highlighting - custom\n highlightedColumnIndexes,\n setHighlightedColumnIndexes,\n currentHighlightColumnIndex,\n setCurrentHighlightColumnIndex,\n handleSearch: isEnabled && typeof onChangeSearch === 'function' ? onChangeSearch : undefined,\n };\n}\n"],"names":["useTableSearch","isEnabled","onChangeSearch","defaultEnableGlobalFilter","enableGlobalFilter","_setEnableGlobalFilter","React","useState","setEnableGlobalFilter","enabled","instance","currentFilter","getState","globalFilter","setTimeout","setGlobalFilter","highlightedColumnIndexes","setHighlightedColumnIndexes","currentHighlightColumnIndex","setCurrentHighlightColumnIndex","undefined","handleSearch"],"mappings":";;AAIA;;;;;SAKgBA,cAAcA,CAC1BC,SAAS,GAAG,KAAK,EACjBC,cAA8C,EAC9CC,yBAAyB,GAAG,KAAK;EAEjC,MAAM,CAACC,kBAAkB,EAAEC,sBAAsB,CAAC,GAAGC,cAAK,CAACC,QAAQ,CAAUJ,yBAAyB,CAAC;EAEvG,SAASK,qBAAqBA,CAAkBC,OAAgB,EAAEC,QAAuB;IACrFL,sBAAsB,CAACI,OAAO,CAAC;;IAG/B,MAAME,aAAa,GAAGD,QAAQ,CAACE,QAAQ,EAAE,CAACC,YAAY;IAEtD,IAAIF,aAAa,EAAE;MACfG,UAAU,CAAC;QACPJ,QAAQ,CAACK,eAAe,CAAC,EAAE,CAAC;QAC5BL,QAAQ,CAACK,eAAe,CAACJ,aAAa,CAAC;OAC1C,EAAE,CAAC,CAAC;;;;EAKb,MAAM,CAACK,wBAAwB,EAAEC,2BAA2B,CAAC,GAAGX,cAAK,CAACC,QAAQ,CAAa,EAAE,CAAC;EAC9F,MAAM,CAACW,2BAA2B,EAAEC,8BAA8B,CAAC,GAAGb,cAAK,CAACC,QAAQ,CAAqBa,SAAS,CAAC;EAEnH,OAAO;IACHnB,SAAS;;IAETG,kBAAkB;IAClBI,qBAAqB;;IAErBQ,wBAAwB;IACxBC,2BAA2B;IAC3BC,2BAA2B;IAC3BC,8BAA8B;IAC9BE,YAAY,EAAEpB,SAAS,IAAI,OAAOC,cAAc,KAAK,UAAU,GAAGA,cAAc,GAAGkB;GACtF;AACL;;;;"}
|
@@ -2,7 +2,7 @@ import React__default from 'react';
|
|
2
2
|
import { TableServerLoadAllState } from '../../types.js';
|
3
3
|
import { DEFAULT_PAGE_SIZE } from '../../useTableDataLoader.js';
|
4
4
|
|
5
|
-
function useTableServerLoading(loadPage, loadAll, pageSize = DEFAULT_PAGE_SIZE) {
|
5
|
+
function useTableServerLoading(loadPage, loadAll, pages, pageSize = DEFAULT_PAGE_SIZE, _experimentalDataLoader2 = false) {
|
6
6
|
const isEnabled = !!loadPage && !!loadAll;
|
7
7
|
const [isReady, setReady] = React__default.useState(false);
|
8
8
|
const [loadAllStatus, setLoadedStatus] = React__default.useState(TableServerLoadAllState.Incomplete);
|
@@ -57,13 +57,15 @@ function useTableServerLoading(loadPage, loadAll, pageSize = DEFAULT_PAGE_SIZE)
|
|
57
57
|
};
|
58
58
|
}
|
59
59
|
return {
|
60
|
+
pages,
|
60
61
|
isEnabled,
|
61
62
|
isReady,
|
62
63
|
loadPage: _loadPage,
|
63
64
|
loadAll: _loadAll,
|
64
65
|
loadAllIfNeeded: _loadAllIfNeeded,
|
65
66
|
loadAllStatus,
|
66
|
-
pageSize
|
67
|
+
pageSize,
|
68
|
+
_experimentalDataLoader2
|
67
69
|
};
|
68
70
|
}
|
69
71
|
|