@tanstack/table-core 9.0.0-alpha.4 → 9.0.0-alpha.6
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/dist/cjs/aggregationFns.cjs +4 -8
- package/dist/cjs/aggregationFns.cjs.map +1 -1
- package/dist/cjs/core/cell.cjs +3 -3
- package/dist/cjs/core/cell.cjs.map +1 -1
- package/dist/cjs/core/cell.d.cts +1 -1
- package/dist/cjs/core/column.cjs +3 -3
- package/dist/cjs/core/column.cjs.map +1 -1
- package/dist/cjs/core/column.d.cts +1 -1
- package/dist/cjs/core/headers.cjs +5 -5
- package/dist/cjs/core/headers.cjs.map +1 -1
- package/dist/cjs/core/row.cjs +5 -6
- package/dist/cjs/core/row.cjs.map +1 -1
- package/dist/cjs/core/row.d.cts +1 -1
- package/dist/cjs/core/table.cjs +11 -7
- package/dist/cjs/core/table.cjs.map +1 -1
- package/dist/cjs/core/table.d.cts +9 -1
- package/dist/cjs/features/ColumnFaceting.cjs +1 -1
- package/dist/cjs/features/ColumnFaceting.cjs.map +1 -1
- package/dist/cjs/features/ColumnFiltering.cjs +6 -6
- package/dist/cjs/features/ColumnFiltering.cjs.map +1 -1
- package/dist/cjs/features/ColumnGrouping.cjs +8 -9
- package/dist/cjs/features/ColumnGrouping.cjs.map +1 -1
- package/dist/cjs/features/ColumnOrdering.cjs +4 -4
- package/dist/cjs/features/ColumnOrdering.cjs.map +1 -1
- package/dist/cjs/features/ColumnPinning.cjs +5 -5
- package/dist/cjs/features/ColumnPinning.cjs.map +1 -1
- package/dist/cjs/features/ColumnSizing.cjs +7 -8
- package/dist/cjs/features/ColumnSizing.cjs.map +1 -1
- package/dist/cjs/features/ColumnVisibility.cjs +5 -5
- package/dist/cjs/features/ColumnVisibility.cjs.map +1 -1
- package/dist/cjs/features/GlobalFaceting.cjs +1 -1
- package/dist/cjs/features/GlobalFaceting.cjs.map +1 -1
- package/dist/cjs/features/GlobalFiltering.cjs +4 -4
- package/dist/cjs/features/GlobalFiltering.cjs.map +1 -1
- package/dist/cjs/features/RowExpanding.cjs +6 -8
- package/dist/cjs/features/RowExpanding.cjs.map +1 -1
- package/dist/cjs/features/RowPagination.cjs +4 -5
- package/dist/cjs/features/RowPagination.cjs.map +1 -1
- package/dist/cjs/features/RowPinning.cjs +5 -6
- package/dist/cjs/features/RowPinning.cjs.map +1 -1
- package/dist/cjs/features/RowSelection.cjs +6 -8
- package/dist/cjs/features/RowSelection.cjs.map +1 -1
- package/dist/cjs/features/RowSorting.cjs +6 -7
- package/dist/cjs/features/RowSorting.cjs.map +1 -1
- package/dist/cjs/index.cjs +5 -4
- package/dist/cjs/index.cjs.map +1 -1
- package/dist/cjs/types.d.cts +8 -8
- package/dist/cjs/utils/filterRowsUtils.cjs +2 -2
- package/dist/cjs/utils/filterRowsUtils.cjs.map +1 -1
- package/dist/cjs/utils/getCoreRowModel.cjs +1 -1
- package/dist/cjs/utils/getCoreRowModel.cjs.map +1 -1
- package/dist/cjs/utils/getFacetedMinMaxValues.cjs +1 -2
- package/dist/cjs/utils/getFacetedMinMaxValues.cjs.map +1 -1
- package/dist/cjs/utils/getFacetedUniqueValues.cjs +1 -2
- package/dist/cjs/utils/getFacetedUniqueValues.cjs.map +1 -1
- package/dist/cjs/utils/getGroupedRowModel.cjs +1 -1
- package/dist/cjs/utils/getGroupedRowModel.cjs.map +1 -1
- package/dist/cjs/utils/getSortedRowModel.cjs +3 -6
- package/dist/cjs/utils/getSortedRowModel.cjs.map +1 -1
- package/dist/cjs/utils.cjs +2 -4
- package/dist/cjs/utils.cjs.map +1 -1
- package/dist/esm/aggregationFns.js +4 -8
- package/dist/esm/aggregationFns.js.map +1 -1
- package/dist/esm/core/cell.d.ts +1 -1
- package/dist/esm/core/cell.js +3 -3
- package/dist/esm/core/cell.js.map +1 -1
- package/dist/esm/core/column.d.ts +1 -1
- package/dist/esm/core/column.js +3 -3
- package/dist/esm/core/column.js.map +1 -1
- package/dist/esm/core/headers.js +5 -5
- package/dist/esm/core/headers.js.map +1 -1
- package/dist/esm/core/row.d.ts +1 -1
- package/dist/esm/core/row.js +6 -7
- package/dist/esm/core/row.js.map +1 -1
- package/dist/esm/core/table.d.ts +9 -1
- package/dist/esm/core/table.js +12 -8
- package/dist/esm/core/table.js.map +1 -1
- package/dist/esm/features/ColumnFaceting.js +1 -1
- package/dist/esm/features/ColumnFaceting.js.map +1 -1
- package/dist/esm/features/ColumnFiltering.js +6 -6
- package/dist/esm/features/ColumnFiltering.js.map +1 -1
- package/dist/esm/features/ColumnGrouping.js +8 -9
- package/dist/esm/features/ColumnGrouping.js.map +1 -1
- package/dist/esm/features/ColumnOrdering.js +4 -4
- package/dist/esm/features/ColumnOrdering.js.map +1 -1
- package/dist/esm/features/ColumnPinning.js +5 -5
- package/dist/esm/features/ColumnPinning.js.map +1 -1
- package/dist/esm/features/ColumnSizing.js +7 -8
- package/dist/esm/features/ColumnSizing.js.map +1 -1
- package/dist/esm/features/ColumnVisibility.js +5 -5
- package/dist/esm/features/ColumnVisibility.js.map +1 -1
- package/dist/esm/features/GlobalFaceting.js +1 -1
- package/dist/esm/features/GlobalFaceting.js.map +1 -1
- package/dist/esm/features/GlobalFiltering.js +4 -4
- package/dist/esm/features/GlobalFiltering.js.map +1 -1
- package/dist/esm/features/RowExpanding.js +6 -8
- package/dist/esm/features/RowExpanding.js.map +1 -1
- package/dist/esm/features/RowPagination.js +4 -5
- package/dist/esm/features/RowPagination.js.map +1 -1
- package/dist/esm/features/RowPinning.js +5 -6
- package/dist/esm/features/RowPinning.js.map +1 -1
- package/dist/esm/features/RowSelection.js +6 -8
- package/dist/esm/features/RowSelection.js.map +1 -1
- package/dist/esm/features/RowSorting.js +6 -7
- package/dist/esm/features/RowSorting.js.map +1 -1
- package/dist/esm/index.js +10 -9
- package/dist/esm/types.d.ts +8 -8
- package/dist/esm/utils/filterRowsUtils.js +3 -3
- package/dist/esm/utils/filterRowsUtils.js.map +1 -1
- package/dist/esm/utils/getCoreRowModel.js +2 -2
- package/dist/esm/utils/getCoreRowModel.js.map +1 -1
- package/dist/esm/utils/getFacetedMinMaxValues.js +1 -2
- package/dist/esm/utils/getFacetedMinMaxValues.js.map +1 -1
- package/dist/esm/utils/getFacetedUniqueValues.js +1 -2
- package/dist/esm/utils/getFacetedUniqueValues.js.map +1 -1
- package/dist/esm/utils/getGroupedRowModel.js +2 -2
- package/dist/esm/utils/getGroupedRowModel.js.map +1 -1
- package/dist/esm/utils/getSortedRowModel.js +3 -6
- package/dist/esm/utils/getSortedRowModel.js.map +1 -1
- package/dist/esm/utils.js +2 -4
- package/dist/esm/utils.js.map +1 -1
- package/package.json +1 -1
- package/src/core/cell.ts +2 -2
- package/src/core/column.ts +2 -2
- package/src/core/headers.ts +5 -5
- package/src/core/row.ts +4 -4
- package/src/core/table.ts +43 -7
- package/src/features/ColumnFaceting.ts +1 -1
- package/src/features/ColumnFiltering.ts +6 -6
- package/src/features/ColumnGrouping.ts +7 -7
- package/src/features/ColumnOrdering.ts +4 -4
- package/src/features/ColumnPinning.ts +5 -5
- package/src/features/ColumnSizing.ts +6 -6
- package/src/features/ColumnVisibility.ts +5 -5
- package/src/features/GlobalFaceting.ts +1 -1
- package/src/features/GlobalFiltering.ts +4 -4
- package/src/features/RowExpanding.ts +4 -4
- package/src/features/RowPagination.ts +3 -3
- package/src/features/RowPinning.ts +4 -4
- package/src/features/RowSelection.ts +4 -4
- package/src/features/RowSorting.ts +5 -5
- package/src/types.ts +8 -8
- package/src/utils/filterRowsUtils.ts +3 -3
- package/src/utils/getCoreRowModel.ts +2 -2
- package/src/utils/getGroupedRowModel.ts +2 -2
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"RowSorting.cjs","sources":["../../../src/features/RowSorting.ts"],"sourcesContent":["import { RowModel } from '..'\nimport {\n BuiltInSortingFn,\n reSplitAlphaNumeric,\n sortingFns,\n} from '../sortingFns'\n\nimport {\n Column,\n OnChangeFn,\n Table,\n Row,\n Updater,\n RowData,\n SortingFns,\n TableFeature,\n} from '../types'\n\nimport { isFunction, makeStateUpdater } from '../utils'\n\nexport type SortDirection = 'asc' | 'desc'\n\nexport interface ColumnSort {\n desc: boolean\n id: string\n}\n\nexport type SortingState = ColumnSort[]\n\nexport interface SortingTableState {\n sorting: SortingState\n}\n\nexport interface SortingFn<TData extends RowData> {\n (rowA: Row<TData>, rowB: Row<TData>, columnId: string): number\n}\n\nexport type CustomSortingFns<TData extends RowData> = Record<\n string,\n SortingFn<TData>\n>\n\nexport type SortingFnOption<TData extends RowData> =\n | 'auto'\n | keyof SortingFns\n | BuiltInSortingFn\n | SortingFn<TData>\n\nexport interface SortingColumnDef<TData extends RowData> {\n /**\n * Enables/Disables multi-sorting for this column.\n * @link [API Docs](https://tanstack.com/table/v8/docs/api/features/sorting#enablemultisort)\n * @link [Guide](https://tanstack.com/table/v8/docs/guide/sorting)\n */\n enableMultiSort?: boolean\n /**\n * Enables/Disables sorting for this column.\n * @link [API Docs](https://tanstack.com/table/v8/docs/api/features/sorting#enablesorting)\n * @link [Guide](https://tanstack.com/table/v8/docs/guide/sorting)\n */\n enableSorting?: boolean\n /**\n * Inverts the order of the sorting for this column. This is useful for values that have an inverted best/worst scale where lower numbers are better, eg. a ranking (1st, 2nd, 3rd) or golf-like scoring\n * @link [API Docs](https://tanstack.com/table/v8/docs/api/features/sorting#invertsorting)\n * @link [Guide](https://tanstack.com/table/v8/docs/guide/sorting)\n */\n invertSorting?: boolean\n /**\n * Set to `true` for sorting toggles on this column to start in the descending direction.\n * @link [API Docs](https://tanstack.com/table/v8/docs/api/features/sorting#sortdescfirst)\n * @link [Guide](https://tanstack.com/table/v8/docs/guide/sorting)\n */\n sortDescFirst?: boolean\n /**\n * The sorting function to use with this column.\n * - A `string` referencing a built-in sorting function\n * - A custom sorting function\n * @link [API Docs](https://tanstack.com/table/v8/docs/api/features/sorting#sortingfn)\n * @link [Guide](https://tanstack.com/table/v8/docs/guide/sorting)\n */\n sortingFn?: SortingFnOption<TData>\n /**\n * The priority of undefined values when sorting this column.\n * - `false`\n * - Undefined values will be considered tied and need to be sorted by the next column filter or original index (whichever applies)\n * - `-1`\n * - Undefined values will be sorted with higher priority (ascending) (if ascending, undefined will appear on the beginning of the list)\n * - `1`\n * - Undefined values will be sorted with lower priority (descending) (if ascending, undefined will appear on the end of the list)\n * @link [API Docs](https://tanstack.com/table/v8/docs/api/features/sorting#sortundefined)\n * @link [Guide](https://tanstack.com/table/v8/docs/guide/sorting)\n */\n sortUndefined?: false | -1 | 1 | 'first' | 'last'\n}\n\nexport interface SortingColumn<TData extends RowData> {\n /**\n * Removes this column from the table's sorting state\n * @link [API Docs](https://tanstack.com/table/v8/docs/api/features/sorting#clearsorting)\n * @link [Guide](https://tanstack.com/table/v8/docs/guide/sorting)\n */\n clearSorting: () => void\n /**\n * Returns a sort direction automatically inferred based on the columns values.\n * @link [API Docs](https://tanstack.com/table/v8/docs/api/features/sorting#getautosortdir)\n * @link [Guide](https://tanstack.com/table/v8/docs/guide/sorting)\n */\n getAutoSortDir: () => SortDirection\n /**\n * Returns a sorting function automatically inferred based on the columns values.\n * @link [API Docs](https://tanstack.com/table/v8/docs/api/features/sorting#getautosortingfn)\n * @link [Guide](https://tanstack.com/table/v8/docs/guide/sorting)\n */\n getAutoSortingFn: () => SortingFn<TData>\n /**\n * Returns whether this column can be multi-sorted.\n * @link [API Docs](https://tanstack.com/table/v8/docs/api/features/sorting#getcanmultisort)\n * @link [Guide](https://tanstack.com/table/v8/docs/guide/sorting)\n */\n getCanMultiSort: () => boolean\n /**\n * Returns whether this column can be sorted.\n * @link [API Docs](https://tanstack.com/table/v8/docs/api/features/sorting#getcansort)\n * @link [Guide](https://tanstack.com/table/v8/docs/guide/sorting)\n */\n getCanSort: () => boolean\n /**\n * Returns the first direction that should be used when sorting this column.\n * @link [API Docs](https://tanstack.com/table/v8/docs/api/features/sorting#getfirstsortdir)\n * @link [Guide](https://tanstack.com/table/v8/docs/guide/sorting)\n */\n getFirstSortDir: () => SortDirection\n /**\n * Returns the current sort direction of this column.\n * @link [API Docs](https://tanstack.com/table/v8/docs/api/features/sorting#getissorted)\n * @link [Guide](https://tanstack.com/table/v8/docs/guide/sorting)\n */\n getIsSorted: () => false | SortDirection\n /**\n * Returns the next sorting order.\n * @link [API Docs](https://tanstack.com/table/v8/docs/api/features/sorting#getnextsortingorder)\n * @link [Guide](https://tanstack.com/table/v8/docs/guide/sorting)\n */\n getNextSortingOrder: () => SortDirection | false\n /**\n * Returns the index position of this column's sorting within the sorting state\n * @link [API Docs](https://tanstack.com/table/v8/docs/api/features/sorting#getsortindex)\n * @link [Guide](https://tanstack.com/table/v8/docs/guide/sorting)\n */\n getSortIndex: () => number\n /**\n * Returns the resolved sorting function to be used for this column\n * @link [API Docs](https://tanstack.com/table/v8/docs/api/features/sorting#getsortingfn)\n * @link [Guide](https://tanstack.com/table/v8/docs/guide/sorting)\n */\n getSortingFn: () => SortingFn<TData>\n /**\n * Returns a function that can be used to toggle this column's sorting state. This is useful for attaching a click handler to the column header.\n * @link [API Docs](https://tanstack.com/table/v8/docs/api/features/sorting#gettogglesortinghandler)\n * @link [Guide](https://tanstack.com/table/v8/docs/guide/sorting)\n */\n getToggleSortingHandler: () => undefined | ((event: unknown) => void)\n /**\n * Toggles this columns sorting state. If `desc` is provided, it will force the sort direction to that value. If `isMulti` is provided, it will additivity multi-sort the column (or toggle it if it is already sorted).\n * @link [API Docs](https://tanstack.com/table/v8/docs/api/features/sorting#togglesorting)\n * @link [Guide](https://tanstack.com/table/v8/docs/guide/sorting)\n */\n toggleSorting: (desc?: boolean, isMulti?: boolean) => void\n}\n\ninterface SortingOptionsBase {\n /**\n * Enables/disables the ability to remove multi-sorts\n * @link [API Docs](https://tanstack.com/table/v8/docs/api/features/sorting#enablemultiremove)\n * @link [Guide](https://tanstack.com/table/v8/docs/guide/sorting)\n */\n enableMultiRemove?: boolean\n /**\n * Enables/Disables multi-sorting for the table.\n * @link [API Docs](https://tanstack.com/table/v8/docs/api/features/sorting#enablemultisort)\n * @link [Guide](https://tanstack.com/table/v8/docs/guide/sorting)\n */\n enableMultiSort?: boolean\n /**\n * Enables/Disables sorting for the table.\n * @link [API Docs](https://tanstack.com/table/v8/docs/api/features/sorting#enablesorting)\n * @link [Guide](https://tanstack.com/table/v8/docs/guide/sorting)\n */\n enableSorting?: boolean\n /**\n * Enables/Disables the ability to remove sorting for the table.\n * - If `true` then changing sort order will circle like: 'none' -> 'desc' -> 'asc' -> 'none' -> ...\n * - If `false` then changing sort order will circle like: 'none' -> 'desc' -> 'asc' -> 'desc' -> 'asc' -> ...\n * @link [API Docs](https://tanstack.com/table/v8/docs/api/features/sorting#enablesortingremoval)\n * @link [Guide](https://tanstack.com/table/v8/docs/guide/sorting)\n */\n enableSortingRemoval?: boolean\n /**\n * This function is used to retrieve the sorted row model. If using server-side sorting, this function is not required. To use client-side sorting, pass the exported `getSortedRowModel()` from your adapter to your table or implement your own.\n * @link [API Docs](https://tanstack.com/table/v8/docs/api/features/sorting#getsortedrowmodel)\n * @link [Guide](https://tanstack.com/table/v8/docs/guide/sorting)\n */\n getSortedRowModel?: (table: Table<any>) => () => RowModel<any>\n /**\n * Pass a custom function that will be used to determine if a multi-sort event should be triggered. It is passed the event from the sort toggle handler and should return `true` if the event should trigger a multi-sort.\n * @link [API Docs](https://tanstack.com/table/v8/docs/api/features/sorting#ismultisortevent)\n * @link [Guide](https://tanstack.com/table/v8/docs/guide/sorting)\n */\n isMultiSortEvent?: (e: unknown) => boolean\n /**\n * Enables manual sorting for the table. If this is `true`, you will be expected to sort your data before it is passed to the table. This is useful if you are doing server-side sorting.\n * @link [API Docs](https://tanstack.com/table/v8/docs/api/features/sorting#manualsorting)\n * @link [Guide](https://tanstack.com/table/v8/docs/guide/sorting)\n */\n manualSorting?: boolean\n /**\n * Set a maximum number of columns that can be multi-sorted.\n * @link [API Docs](https://tanstack.com/table/v8/docs/api/features/sorting#maxmultisortcolcount)\n * @link [Guide](https://tanstack.com/table/v8/docs/guide/sorting)\n */\n maxMultiSortColCount?: number\n /**\n * If provided, this function will be called with an `updaterFn` when `state.sorting` changes. This overrides the default internal state management, so you will need to persist the state change either fully or partially outside of the table.\n * @link [API Docs](https://tanstack.com/table/v8/docs/api/features/sorting#onsortingchange)\n * @link [Guide](https://tanstack.com/table/v8/docs/guide/sorting)\n */\n onSortingChange?: OnChangeFn<SortingState>\n /**\n * If `true`, all sorts will default to descending as their first toggle state.\n * @link [API Docs](https://tanstack.com/table/v8/docs/api/features/sorting#sortdescfirst)\n * @link [Guide](https://tanstack.com/table/v8/docs/guide/sorting)\n */\n sortDescFirst?: boolean\n}\n\ntype ResolvedSortingFns = keyof SortingFns extends never\n ? {\n sortingFns?: Record<string, SortingFn<any>>\n }\n : {\n sortingFns: Record<keyof SortingFns, SortingFn<any>>\n }\n\nexport interface SortingOptions<TData extends RowData>\n extends SortingOptionsBase,\n ResolvedSortingFns {}\n\nexport interface SortingInstance<TData extends RowData> {\n _getSortedRowModel?: () => RowModel<TData>\n /**\n * Returns the row model for the table before any sorting has been applied.\n * @link [API Docs](https://tanstack.com/table/v8/docs/api/features/sorting#getpresortedrowmodel)\n * @link [Guide](https://tanstack.com/table/v8/docs/guide/sorting)\n */\n getPreSortedRowModel: () => RowModel<TData>\n /**\n * Returns the row model for the table after sorting has been applied.\n * @link [API Docs](https://tanstack.com/table/v8/docs/api/features/sorting#getsortedrowmodel)\n * @link [Guide](https://tanstack.com/table/v8/docs/guide/sorting)\n */\n getSortedRowModel: () => RowModel<TData>\n /**\n * Resets the **sorting** state to `initialState.sorting`, or `true` can be passed to force a default blank state reset to `[]`.\n * @link [API Docs](https://tanstack.com/table/v8/docs/api/features/sorting#resetsorting)\n * @link [Guide](https://tanstack.com/table/v8/docs/guide/sorting)\n */\n resetSorting: (defaultState?: boolean) => void\n /**\n * Sets or updates the `state.sorting` state.\n * @link [API Docs](https://tanstack.com/table/v8/docs/api/features/sorting#setsorting)\n * @link [Guide](https://tanstack.com/table/v8/docs/guide/sorting)\n */\n setSorting: (updater: Updater<SortingState>) => void\n}\n\n//\n\nexport const RowSorting: TableFeature = {\n getInitialState: (state): SortingTableState => {\n return {\n sorting: [],\n ...state,\n }\n },\n\n getDefaultColumnDef: <TData extends RowData>(): SortingColumnDef<TData> => {\n return {\n sortingFn: 'auto',\n sortUndefined: 1,\n }\n },\n\n getDefaultOptions: <TData extends RowData>(\n table: Table<TData>\n ): SortingOptions<TData> => {\n return {\n onSortingChange: makeStateUpdater('sorting', table),\n isMultiSortEvent: (e: unknown) => {\n return (e as MouseEvent).shiftKey\n },\n }\n },\n\n createColumn: <TData extends RowData, TValue>(\n column: Column<TData, TValue>,\n table: Table<TData>\n ): void => {\n column.getAutoSortingFn = () => {\n const firstRows = table.getFilteredRowModel().flatRows.slice(10)\n\n let isString = false\n\n for (const row of firstRows) {\n const value = row?.getValue(column.id)\n\n if (Object.prototype.toString.call(value) === '[object Date]') {\n return sortingFns.datetime\n }\n\n if (typeof value === 'string') {\n isString = true\n\n if (value.split(reSplitAlphaNumeric).length > 1) {\n return sortingFns.alphanumeric\n }\n }\n }\n\n if (isString) {\n return sortingFns.text\n }\n\n return sortingFns.basic\n }\n column.getAutoSortDir = () => {\n const firstRow = table.getFilteredRowModel().flatRows[0]\n\n const value = firstRow?.getValue(column.id)\n\n if (typeof value === 'string') {\n return 'asc'\n }\n\n return 'desc'\n }\n column.getSortingFn = () => {\n if (!column) {\n throw new Error()\n }\n\n return isFunction(column.columnDef.sortingFn)\n ? column.columnDef.sortingFn\n : column.columnDef.sortingFn === 'auto'\n ? column.getAutoSortingFn()\n : table.options.sortingFns?.[column.columnDef.sortingFn as string] ??\n sortingFns[column.columnDef.sortingFn as BuiltInSortingFn]\n }\n column.toggleSorting = (desc, multi) => {\n // if (column.columns.length) {\n // column.columns.forEach((c, i) => {\n // if (c.id) {\n // table.toggleColumnSorting(c.id, undefined, multi || !!i)\n // }\n // })\n // return\n // }\n\n // this needs to be outside of table.setSorting to be in sync with rerender\n const nextSortingOrder = column.getNextSortingOrder()\n const hasManualValue = typeof desc !== 'undefined' && desc !== null\n\n table.setSorting(old => {\n // Find any existing sorting for this column\n const existingSorting = old?.find(d => d.id === column.id)\n const existingIndex = old?.findIndex(d => d.id === column.id)\n\n let newSorting: SortingState = []\n\n // What should we do with this sort action?\n let sortAction: 'add' | 'remove' | 'toggle' | 'replace'\n let nextDesc = hasManualValue ? desc : nextSortingOrder === 'desc'\n\n // Multi-mode\n if (old?.length && column.getCanMultiSort() && multi) {\n if (existingSorting) {\n sortAction = 'toggle'\n } else {\n sortAction = 'add'\n }\n } else {\n // Normal mode\n if (old?.length && existingIndex !== old.length - 1) {\n sortAction = 'replace'\n } else if (existingSorting) {\n sortAction = 'toggle'\n } else {\n sortAction = 'replace'\n }\n }\n\n // Handle toggle states that will remove the sorting\n if (sortAction === 'toggle') {\n // If we are \"actually\" toggling (not a manual set value), should we remove the sorting?\n if (!hasManualValue) {\n // Is our intention to remove?\n if (!nextSortingOrder) {\n sortAction = 'remove'\n }\n }\n }\n\n if (sortAction === 'add') {\n newSorting = [\n ...old,\n {\n id: column.id,\n desc: nextDesc,\n },\n ]\n // Take latest n columns\n newSorting.splice(\n 0,\n newSorting.length -\n (table.options.maxMultiSortColCount ?? Number.MAX_SAFE_INTEGER)\n )\n } else if (sortAction === 'toggle') {\n // This flips (or sets) the\n newSorting = old.map(d => {\n if (d.id === column.id) {\n return {\n ...d,\n desc: nextDesc,\n }\n }\n return d\n })\n } else if (sortAction === 'remove') {\n newSorting = old.filter(d => d.id !== column.id)\n } else {\n newSorting = [\n {\n id: column.id,\n desc: nextDesc,\n },\n ]\n }\n\n return newSorting\n })\n }\n\n column.getFirstSortDir = () => {\n const sortDescFirst =\n column.columnDef.sortDescFirst ??\n table.options.sortDescFirst ??\n column.getAutoSortDir() === 'desc'\n return sortDescFirst ? 'desc' : 'asc'\n }\n\n column.getNextSortingOrder = (multi?: boolean) => {\n const firstSortDirection = column.getFirstSortDir()\n const isSorted = column.getIsSorted()\n\n if (!isSorted) {\n return firstSortDirection\n }\n\n if (\n isSorted !== firstSortDirection &&\n (table.options.enableSortingRemoval ?? true) && // If enableSortRemove, enable in general\n (multi ? table.options.enableMultiRemove ?? true : true) // If multi, don't allow if enableMultiRemove))\n ) {\n return false\n }\n return isSorted === 'desc' ? 'asc' : 'desc'\n }\n\n column.getCanSort = () => {\n return (\n (column.columnDef.enableSorting ?? true) &&\n (table.options.enableSorting ?? true) &&\n !!column.accessorFn\n )\n }\n\n column.getCanMultiSort = () => {\n return (\n column.columnDef.enableMultiSort ??\n table.options.enableMultiSort ??\n !!column.accessorFn\n )\n }\n\n column.getIsSorted = () => {\n const columnSort = table.getState().sorting?.find(d => d.id === column.id)\n\n return !columnSort ? false : columnSort.desc ? 'desc' : 'asc'\n }\n\n column.getSortIndex = () =>\n table.getState().sorting?.findIndex(d => d.id === column.id) ?? -1\n\n column.clearSorting = () => {\n //clear sorting for just 1 column\n table.setSorting(old =>\n old?.length ? old.filter(d => d.id !== column.id) : []\n )\n }\n\n column.getToggleSortingHandler = () => {\n const canSort = column.getCanSort()\n\n return (e: unknown) => {\n if (!canSort) return\n ;(e as any).persist?.()\n column.toggleSorting?.(\n undefined,\n column.getCanMultiSort() ? table.options.isMultiSortEvent?.(e) : false\n )\n }\n }\n },\n\n createTable: <TData extends RowData>(table: Table<TData>): void => {\n table.setSorting = updater => table.options.onSortingChange?.(updater)\n table.resetSorting = defaultState => {\n table.setSorting(defaultState ? [] : table.initialState?.sorting ?? [])\n }\n table.getPreSortedRowModel = () => table.getGroupedRowModel()\n table.getSortedRowModel = () => {\n if (!table._getSortedRowModel && table.options.getSortedRowModel) {\n table._getSortedRowModel = table.options.getSortedRowModel(table)\n }\n\n if (table.options.manualSorting || !table._getSortedRowModel) {\n return table.getPreSortedRowModel()\n }\n\n return table._getSortedRowModel()\n }\n },\n}\n"],"names":["makeStateUpdater","sortingFns","reSplitAlphaNumeric","isFunction"],"mappings":";;;;AAqRO,MAAM,aAA2B;AAAA,EACtC,iB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D,WAAO,eAAe,MACpB;;AAAA,0BAAM,SAAW,EAAA,YAAjB,mBAA0B,UAAU,CAAA,MAAK,EAAE,OAAO,OAAO,QAAO;AAAA;AAElE,WAAO,eAAe,MAAM;AAEpB,YAAA;AAAA,QAAW,CAAA,SACf,2BAAK,UAAS,IAAI,OAAO,CAAK,MAAA,EAAE,OAAO,OAAO,EAAE,IAAI,CAAC;AAAA,MAAA;AAAA,IACvD;AAGF,WAAO,0BAA0B,MAAM;AAC/B,YAAA,UAAU,OAAO;AAEvB,aAAO,CAAC,MAAe;;AACrB,YAAI,CAAC;AAAS;AACZ,gBAAU,YAAV;AACK,qBAAA,kBAAA;AAAA;AAAA,UACL;AAAA,UACA,OAAO,gBAAgB,KAAI,iBAAM,SAAQ,qBAAd,4BAAiC,KAAK;AAAA;AAAA,MACnE;AAAA,IACF;AAAA,EAEJ;AAAA,EAEA,aAAa,CAAwB,UAA8B;AACjE,UAAM,aAAa,CAAA,YAAA;;AAAW,+BAAM,SAAQ,oBAAd,4BAAgC;AAAA;AAC9D,UAAM,eAAe,CAAgB,iBAAA;;AAC7B,YAAA,WAAW,eAAe,CAAC,MAAI,WAAM,iBAAN,mBAAoB,YAAW,CAAA,CAAE;AAAA,IAAA;AAElE,UAAA,uBAAuB,MAAM,MAAM,mBAAmB;AAC5D,UAAM,oBAAoB,MAAM;AAC9B,UAAI,CAAC,MAAM,sBAAsB,MAAM,QAAQ,mBAAmB;AAChE,cAAM,qBAAqB,MAAM,QAAQ,kBAAkB,KAAK;AAAA,MAClE;AAEA,UAAI,MAAM,QAAQ,iBAAiB,CAAC,MAAM,oBAAoB;AAC5D,eAAO,MAAM;MACf;AAEA,aAAO,MAAM;IAAmB;AAAA,EAEpC;AACF;;"}
|
|
1
|
+
{"version":3,"file":"RowSorting.cjs","sources":["../../../src/features/RowSorting.ts"],"sourcesContent":["import { RowModel } from '..'\nimport {\n BuiltInSortingFn,\n reSplitAlphaNumeric,\n sortingFns,\n} from '../sortingFns'\n\nimport {\n Column,\n OnChangeFn,\n Table,\n Row,\n Updater,\n RowData,\n SortingFns,\n TableFeature,\n} from '../types'\n\nimport { isFunction, makeStateUpdater } from '../utils'\n\nexport type SortDirection = 'asc' | 'desc'\n\nexport interface ColumnSort {\n desc: boolean\n id: string\n}\n\nexport type SortingState = ColumnSort[]\n\nexport interface SortingTableState {\n sorting: SortingState\n}\n\nexport interface SortingFn<TData extends RowData> {\n (rowA: Row<TData>, rowB: Row<TData>, columnId: string): number\n}\n\nexport type CustomSortingFns<TData extends RowData> = Record<\n string,\n SortingFn<TData>\n>\n\nexport type SortingFnOption<TData extends RowData> =\n | 'auto'\n | keyof SortingFns\n | BuiltInSortingFn\n | SortingFn<TData>\n\nexport interface SortingColumnDef<TData extends RowData> {\n /**\n * Enables/Disables multi-sorting for this column.\n * @link [API Docs](https://tanstack.com/table/v8/docs/api/features/sorting#enablemultisort)\n * @link [Guide](https://tanstack.com/table/v8/docs/guide/sorting)\n */\n enableMultiSort?: boolean\n /**\n * Enables/Disables sorting for this column.\n * @link [API Docs](https://tanstack.com/table/v8/docs/api/features/sorting#enablesorting)\n * @link [Guide](https://tanstack.com/table/v8/docs/guide/sorting)\n */\n enableSorting?: boolean\n /**\n * Inverts the order of the sorting for this column. This is useful for values that have an inverted best/worst scale where lower numbers are better, eg. a ranking (1st, 2nd, 3rd) or golf-like scoring\n * @link [API Docs](https://tanstack.com/table/v8/docs/api/features/sorting#invertsorting)\n * @link [Guide](https://tanstack.com/table/v8/docs/guide/sorting)\n */\n invertSorting?: boolean\n /**\n * Set to `true` for sorting toggles on this column to start in the descending direction.\n * @link [API Docs](https://tanstack.com/table/v8/docs/api/features/sorting#sortdescfirst)\n * @link [Guide](https://tanstack.com/table/v8/docs/guide/sorting)\n */\n sortDescFirst?: boolean\n /**\n * The sorting function to use with this column.\n * - A `string` referencing a built-in sorting function\n * - A custom sorting function\n * @link [API Docs](https://tanstack.com/table/v8/docs/api/features/sorting#sortingfn)\n * @link [Guide](https://tanstack.com/table/v8/docs/guide/sorting)\n */\n sortingFn?: SortingFnOption<TData>\n /**\n * The priority of undefined values when sorting this column.\n * - `false`\n * - Undefined values will be considered tied and need to be sorted by the next column filter or original index (whichever applies)\n * - `-1`\n * - Undefined values will be sorted with higher priority (ascending) (if ascending, undefined will appear on the beginning of the list)\n * - `1`\n * - Undefined values will be sorted with lower priority (descending) (if ascending, undefined will appear on the end of the list)\n * @link [API Docs](https://tanstack.com/table/v8/docs/api/features/sorting#sortundefined)\n * @link [Guide](https://tanstack.com/table/v8/docs/guide/sorting)\n */\n sortUndefined?: false | -1 | 1 | 'first' | 'last'\n}\n\nexport interface SortingColumn<TData extends RowData> {\n /**\n * Removes this column from the table's sorting state\n * @link [API Docs](https://tanstack.com/table/v8/docs/api/features/sorting#clearsorting)\n * @link [Guide](https://tanstack.com/table/v8/docs/guide/sorting)\n */\n clearSorting: () => void\n /**\n * Returns a sort direction automatically inferred based on the columns values.\n * @link [API Docs](https://tanstack.com/table/v8/docs/api/features/sorting#getautosortdir)\n * @link [Guide](https://tanstack.com/table/v8/docs/guide/sorting)\n */\n getAutoSortDir: () => SortDirection\n /**\n * Returns a sorting function automatically inferred based on the columns values.\n * @link [API Docs](https://tanstack.com/table/v8/docs/api/features/sorting#getautosortingfn)\n * @link [Guide](https://tanstack.com/table/v8/docs/guide/sorting)\n */\n getAutoSortingFn: () => SortingFn<TData>\n /**\n * Returns whether this column can be multi-sorted.\n * @link [API Docs](https://tanstack.com/table/v8/docs/api/features/sorting#getcanmultisort)\n * @link [Guide](https://tanstack.com/table/v8/docs/guide/sorting)\n */\n getCanMultiSort: () => boolean\n /**\n * Returns whether this column can be sorted.\n * @link [API Docs](https://tanstack.com/table/v8/docs/api/features/sorting#getcansort)\n * @link [Guide](https://tanstack.com/table/v8/docs/guide/sorting)\n */\n getCanSort: () => boolean\n /**\n * Returns the first direction that should be used when sorting this column.\n * @link [API Docs](https://tanstack.com/table/v8/docs/api/features/sorting#getfirstsortdir)\n * @link [Guide](https://tanstack.com/table/v8/docs/guide/sorting)\n */\n getFirstSortDir: () => SortDirection\n /**\n * Returns the current sort direction of this column.\n * @link [API Docs](https://tanstack.com/table/v8/docs/api/features/sorting#getissorted)\n * @link [Guide](https://tanstack.com/table/v8/docs/guide/sorting)\n */\n getIsSorted: () => false | SortDirection\n /**\n * Returns the next sorting order.\n * @link [API Docs](https://tanstack.com/table/v8/docs/api/features/sorting#getnextsortingorder)\n * @link [Guide](https://tanstack.com/table/v8/docs/guide/sorting)\n */\n getNextSortingOrder: () => SortDirection | false\n /**\n * Returns the index position of this column's sorting within the sorting state\n * @link [API Docs](https://tanstack.com/table/v8/docs/api/features/sorting#getsortindex)\n * @link [Guide](https://tanstack.com/table/v8/docs/guide/sorting)\n */\n getSortIndex: () => number\n /**\n * Returns the resolved sorting function to be used for this column\n * @link [API Docs](https://tanstack.com/table/v8/docs/api/features/sorting#getsortingfn)\n * @link [Guide](https://tanstack.com/table/v8/docs/guide/sorting)\n */\n getSortingFn: () => SortingFn<TData>\n /**\n * Returns a function that can be used to toggle this column's sorting state. This is useful for attaching a click handler to the column header.\n * @link [API Docs](https://tanstack.com/table/v8/docs/api/features/sorting#gettogglesortinghandler)\n * @link [Guide](https://tanstack.com/table/v8/docs/guide/sorting)\n */\n getToggleSortingHandler: () => undefined | ((event: unknown) => void)\n /**\n * Toggles this columns sorting state. If `desc` is provided, it will force the sort direction to that value. If `isMulti` is provided, it will additivity multi-sort the column (or toggle it if it is already sorted).\n * @link [API Docs](https://tanstack.com/table/v8/docs/api/features/sorting#togglesorting)\n * @link [Guide](https://tanstack.com/table/v8/docs/guide/sorting)\n */\n toggleSorting: (desc?: boolean, isMulti?: boolean) => void\n}\n\ninterface SortingOptionsBase {\n /**\n * Enables/disables the ability to remove multi-sorts\n * @link [API Docs](https://tanstack.com/table/v8/docs/api/features/sorting#enablemultiremove)\n * @link [Guide](https://tanstack.com/table/v8/docs/guide/sorting)\n */\n enableMultiRemove?: boolean\n /**\n * Enables/Disables multi-sorting for the table.\n * @link [API Docs](https://tanstack.com/table/v8/docs/api/features/sorting#enablemultisort)\n * @link [Guide](https://tanstack.com/table/v8/docs/guide/sorting)\n */\n enableMultiSort?: boolean\n /**\n * Enables/Disables sorting for the table.\n * @link [API Docs](https://tanstack.com/table/v8/docs/api/features/sorting#enablesorting)\n * @link [Guide](https://tanstack.com/table/v8/docs/guide/sorting)\n */\n enableSorting?: boolean\n /**\n * Enables/Disables the ability to remove sorting for the table.\n * - If `true` then changing sort order will circle like: 'none' -> 'desc' -> 'asc' -> 'none' -> ...\n * - If `false` then changing sort order will circle like: 'none' -> 'desc' -> 'asc' -> 'desc' -> 'asc' -> ...\n * @link [API Docs](https://tanstack.com/table/v8/docs/api/features/sorting#enablesortingremoval)\n * @link [Guide](https://tanstack.com/table/v8/docs/guide/sorting)\n */\n enableSortingRemoval?: boolean\n /**\n * This function is used to retrieve the sorted row model. If using server-side sorting, this function is not required. To use client-side sorting, pass the exported `getSortedRowModel()` from your adapter to your table or implement your own.\n * @link [API Docs](https://tanstack.com/table/v8/docs/api/features/sorting#getsortedrowmodel)\n * @link [Guide](https://tanstack.com/table/v8/docs/guide/sorting)\n */\n getSortedRowModel?: (table: Table<any>) => () => RowModel<any>\n /**\n * Pass a custom function that will be used to determine if a multi-sort event should be triggered. It is passed the event from the sort toggle handler and should return `true` if the event should trigger a multi-sort.\n * @link [API Docs](https://tanstack.com/table/v8/docs/api/features/sorting#ismultisortevent)\n * @link [Guide](https://tanstack.com/table/v8/docs/guide/sorting)\n */\n isMultiSortEvent?: (e: unknown) => boolean\n /**\n * Enables manual sorting for the table. If this is `true`, you will be expected to sort your data before it is passed to the table. This is useful if you are doing server-side sorting.\n * @link [API Docs](https://tanstack.com/table/v8/docs/api/features/sorting#manualsorting)\n * @link [Guide](https://tanstack.com/table/v8/docs/guide/sorting)\n */\n manualSorting?: boolean\n /**\n * Set a maximum number of columns that can be multi-sorted.\n * @link [API Docs](https://tanstack.com/table/v8/docs/api/features/sorting#maxmultisortcolcount)\n * @link [Guide](https://tanstack.com/table/v8/docs/guide/sorting)\n */\n maxMultiSortColCount?: number\n /**\n * If provided, this function will be called with an `updaterFn` when `state.sorting` changes. This overrides the default internal state management, so you will need to persist the state change either fully or partially outside of the table.\n * @link [API Docs](https://tanstack.com/table/v8/docs/api/features/sorting#onsortingchange)\n * @link [Guide](https://tanstack.com/table/v8/docs/guide/sorting)\n */\n onSortingChange?: OnChangeFn<SortingState>\n /**\n * If `true`, all sorts will default to descending as their first toggle state.\n * @link [API Docs](https://tanstack.com/table/v8/docs/api/features/sorting#sortdescfirst)\n * @link [Guide](https://tanstack.com/table/v8/docs/guide/sorting)\n */\n sortDescFirst?: boolean\n}\n\ntype ResolvedSortingFns = keyof SortingFns extends never\n ? {\n sortingFns?: Record<string, SortingFn<any>>\n }\n : {\n sortingFns: Record<keyof SortingFns, SortingFn<any>>\n }\n\nexport interface SortingOptions<TData extends RowData>\n extends SortingOptionsBase,\n ResolvedSortingFns {}\n\nexport interface SortingInstance<TData extends RowData> {\n _getSortedRowModel?: () => RowModel<TData>\n /**\n * Returns the row model for the table before any sorting has been applied.\n * @link [API Docs](https://tanstack.com/table/v8/docs/api/features/sorting#getpresortedrowmodel)\n * @link [Guide](https://tanstack.com/table/v8/docs/guide/sorting)\n */\n getPreSortedRowModel: () => RowModel<TData>\n /**\n * Returns the row model for the table after sorting has been applied.\n * @link [API Docs](https://tanstack.com/table/v8/docs/api/features/sorting#getsortedrowmodel)\n * @link [Guide](https://tanstack.com/table/v8/docs/guide/sorting)\n */\n getSortedRowModel: () => RowModel<TData>\n /**\n * Resets the **sorting** state to `initialState.sorting`, or `true` can be passed to force a default blank state reset to `[]`.\n * @link [API Docs](https://tanstack.com/table/v8/docs/api/features/sorting#resetsorting)\n * @link [Guide](https://tanstack.com/table/v8/docs/guide/sorting)\n */\n resetSorting: (defaultState?: boolean) => void\n /**\n * Sets or updates the `state.sorting` state.\n * @link [API Docs](https://tanstack.com/table/v8/docs/api/features/sorting#setsorting)\n * @link [Guide](https://tanstack.com/table/v8/docs/guide/sorting)\n */\n setSorting: (updater: Updater<SortingState>) => void\n}\n\n//\n\nexport const RowSorting: TableFeature = {\n _getInitialState: (state): SortingTableState => {\n return {\n sorting: [],\n ...state,\n }\n },\n\n _getDefaultColumnDef: <TData extends RowData>(): SortingColumnDef<TData> => {\n return {\n sortingFn: 'auto',\n sortUndefined: 1,\n }\n },\n\n _getDefaultOptions: <TData extends RowData>(\n table: Table<TData>\n ): SortingOptions<TData> => {\n return {\n onSortingChange: makeStateUpdater('sorting', table),\n isMultiSortEvent: (e: unknown) => {\n return (e as MouseEvent).shiftKey\n },\n }\n },\n\n _createColumn: <TData extends RowData, TValue>(\n column: Column<TData, TValue>,\n table: Table<TData>\n ): void => {\n column.getAutoSortingFn = () => {\n const firstRows = table.getFilteredRowModel().flatRows.slice(10)\n\n let isString = false\n\n for (const row of firstRows) {\n const value = row?.getValue(column.id)\n\n if (Object.prototype.toString.call(value) === '[object Date]') {\n return sortingFns.datetime\n }\n\n if (typeof value === 'string') {\n isString = true\n\n if (value.split(reSplitAlphaNumeric).length > 1) {\n return sortingFns.alphanumeric\n }\n }\n }\n\n if (isString) {\n return sortingFns.text\n }\n\n return sortingFns.basic\n }\n column.getAutoSortDir = () => {\n const firstRow = table.getFilteredRowModel().flatRows[0]\n\n const value = firstRow?.getValue(column.id)\n\n if (typeof value === 'string') {\n return 'asc'\n }\n\n return 'desc'\n }\n column.getSortingFn = () => {\n if (!column) {\n throw new Error()\n }\n\n return isFunction(column.columnDef.sortingFn)\n ? column.columnDef.sortingFn\n : column.columnDef.sortingFn === 'auto'\n ? column.getAutoSortingFn()\n : table.options.sortingFns?.[column.columnDef.sortingFn as string] ??\n sortingFns[column.columnDef.sortingFn as BuiltInSortingFn]\n }\n column.toggleSorting = (desc, multi) => {\n // if (column.columns.length) {\n // column.columns.forEach((c, i) => {\n // if (c.id) {\n // table.toggleColumnSorting(c.id, undefined, multi || !!i)\n // }\n // })\n // return\n // }\n\n // this needs to be outside of table.setSorting to be in sync with rerender\n const nextSortingOrder = column.getNextSortingOrder()\n const hasManualValue = typeof desc !== 'undefined' && desc !== null\n\n table.setSorting(old => {\n // Find any existing sorting for this column\n const existingSorting = old?.find(d => d.id === column.id)\n const existingIndex = old?.findIndex(d => d.id === column.id)\n\n let newSorting: SortingState = []\n\n // What should we do with this sort action?\n let sortAction: 'add' | 'remove' | 'toggle' | 'replace'\n let nextDesc = hasManualValue ? desc : nextSortingOrder === 'desc'\n\n // Multi-mode\n if (old?.length && column.getCanMultiSort() && multi) {\n if (existingSorting) {\n sortAction = 'toggle'\n } else {\n sortAction = 'add'\n }\n } else {\n // Normal mode\n if (old?.length && existingIndex !== old.length - 1) {\n sortAction = 'replace'\n } else if (existingSorting) {\n sortAction = 'toggle'\n } else {\n sortAction = 'replace'\n }\n }\n\n // Handle toggle states that will remove the sorting\n if (sortAction === 'toggle') {\n // If we are \"actually\" toggling (not a manual set value), should we remove the sorting?\n if (!hasManualValue) {\n // Is our intention to remove?\n if (!nextSortingOrder) {\n sortAction = 'remove'\n }\n }\n }\n\n if (sortAction === 'add') {\n newSorting = [\n ...old,\n {\n id: column.id,\n desc: nextDesc,\n },\n ]\n // Take latest n columns\n newSorting.splice(\n 0,\n newSorting.length -\n (table.options.maxMultiSortColCount ?? Number.MAX_SAFE_INTEGER)\n )\n } else if (sortAction === 'toggle') {\n // This flips (or sets) the\n newSorting = old.map(d => {\n if (d.id === column.id) {\n return {\n ...d,\n desc: nextDesc,\n }\n }\n return d\n })\n } else if (sortAction === 'remove') {\n newSorting = old.filter(d => d.id !== column.id)\n } else {\n newSorting = [\n {\n id: column.id,\n desc: nextDesc,\n },\n ]\n }\n\n return newSorting\n })\n }\n\n column.getFirstSortDir = () => {\n const sortDescFirst =\n column.columnDef.sortDescFirst ??\n table.options.sortDescFirst ??\n column.getAutoSortDir() === 'desc'\n return sortDescFirst ? 'desc' : 'asc'\n }\n\n column.getNextSortingOrder = (multi?: boolean) => {\n const firstSortDirection = column.getFirstSortDir()\n const isSorted = column.getIsSorted()\n\n if (!isSorted) {\n return firstSortDirection\n }\n\n if (\n isSorted !== firstSortDirection &&\n (table.options.enableSortingRemoval ?? true) && // If enableSortRemove, enable in general\n (multi ? table.options.enableMultiRemove ?? true : true) // If multi, don't allow if enableMultiRemove))\n ) {\n return false\n }\n return isSorted === 'desc' ? 'asc' : 'desc'\n }\n\n column.getCanSort = () => {\n return (\n (column.columnDef.enableSorting ?? true) &&\n (table.options.enableSorting ?? true) &&\n !!column.accessorFn\n )\n }\n\n column.getCanMultiSort = () => {\n return (\n column.columnDef.enableMultiSort ??\n table.options.enableMultiSort ??\n !!column.accessorFn\n )\n }\n\n column.getIsSorted = () => {\n const columnSort = table.getState().sorting?.find(d => d.id === column.id)\n\n return !columnSort ? false : columnSort.desc ? 'desc' : 'asc'\n }\n\n column.getSortIndex = () =>\n table.getState().sorting?.findIndex(d => d.id === column.id) ?? -1\n\n column.clearSorting = () => {\n //clear sorting for just 1 column\n table.setSorting(old =>\n old?.length ? old.filter(d => d.id !== column.id) : []\n )\n }\n\n column.getToggleSortingHandler = () => {\n const canSort = column.getCanSort()\n\n return (e: unknown) => {\n if (!canSort) return\n ;(e as any).persist?.()\n column.toggleSorting?.(\n undefined,\n column.getCanMultiSort() ? table.options.isMultiSortEvent?.(e) : false\n )\n }\n }\n },\n\n _createTable: <TData extends RowData>(table: Table<TData>): void => {\n table.setSorting = updater => table.options.onSortingChange?.(updater)\n table.resetSorting = defaultState => {\n table.setSorting(defaultState ? [] : table.initialState?.sorting ?? [])\n }\n table.getPreSortedRowModel = () => table.getGroupedRowModel()\n table.getSortedRowModel = () => {\n if (!table._getSortedRowModel && table.options.getSortedRowModel) {\n table._getSortedRowModel = table.options.getSortedRowModel(table)\n }\n\n if (table.options.manualSorting || !table._getSortedRowModel) {\n return table.getPreSortedRowModel()\n }\n\n return table._getSortedRowModel()\n }\n },\n}\n"],"names":["makeStateUpdater","sortingFns","reSplitAlphaNum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./filterFns.cjs");
|
|
35
35
|
const sortingFns = require("./sortingFns.cjs");
|
|
36
36
|
exports.createColumnHelper = columnHelper.createColumnHelper;
|
|
37
|
-
exports.
|
|
38
|
-
exports.
|
|
37
|
+
exports._createCell = cell._createCell;
|
|
38
|
+
exports._createColumn = column._createColumn;
|
|
39
39
|
exports.Headers = headers.Headers;
|
|
40
40
|
exports.buildHeaderGroups = headers.buildHeaderGroups;
|
|
41
|
-
exports.
|
|
42
|
-
exports.
|
|
41
|
+
exports._createRow = row._createRow;
|
|
42
|
+
exports._createTable = table._createTable;
|
|
43
|
+
exports.tableOptions = table.tableOptions;
|
|
43
44
|
exports.ColumnFaceting = ColumnFaceting.ColumnFaceting;
|
|
44
45
|
exports.ColumnFiltering = ColumnFiltering.ColumnFiltering;
|
|
45
46
|
exports.shouldAutoRemoveFilter = ColumnFiltering.shouldAutoRemoveFilter;
|
package/dist/cjs/index.cjs.map
CHANGED
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"index.cjs","sources":[],"sourcesContent":[],"names":[],"mappings":"
|
|
1
|
+
{"version":3,"file":"index.cjs","sources":[],"sourcesContent":[],"names":[],"mappings":";;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;"}
|
package/dist/cjs/types.d.cts
CHANGED
|
@@ -20,14 +20,14 @@ import { CellContext, CoreCell } from './core/cell.cjs';
|
|
|
20
20
|
import { CoreColumn } from './core/column.cjs';
|
|
21
21
|
|
|
22
22
|
export interface TableFeature<TData extends RowData = any> {
|
|
23
|
-
|
|
24
|
-
|
|
25
|
-
|
|
26
|
-
|
|
27
|
-
|
|
28
|
-
|
|
29
|
-
|
|
30
|
-
|
|
23
|
+
_createCell?: (cell: Cell<TData, unknown>, column: Column<TData>, row: Row<TData>, table: Table<TData>) => void;
|
|
24
|
+
_createColumn?: (column: Column<TData, unknown>, table: Table<TData>) => void;
|
|
25
|
+
_createHeader?: (header: Header<TData, unknown>, table: Table<TData>) => void;
|
|
26
|
+
_createRow?: (row: Row<TData>, table: Table<TData>) => void;
|
|
27
|
+
_createTable?: (table: Table<TData>) => void;
|
|
28
|
+
_getDefaultColumnDef?: () => Partial<ColumnDef<TData, unknown>>;
|
|
29
|
+
_getDefaultOptions?: (table: Table<TData>) => Partial<TableOptionsResolved<TData>>;
|
|
30
|
+
_getInitialState?: (initialState?: InitialTableState) => Partial<TableState>;
|
|
31
31
|
}
|
|
32
32
|
export interface TableMeta<TData extends RowData> {
|
|
33
33
|
}
|
|
@@ -16,7 +16,7 @@ function filterRowModelFromLeafs(rowsToFilter, filterRow, table) {
|
|
|
16
16
|
const rows = [];
|
|
17
17
|
for (let i = 0; i < rowsToFilter2.length; i++) {
|
|
18
18
|
let row$1 = rowsToFilter2[i];
|
|
19
|
-
const newRow = row.
|
|
19
|
+
const newRow = row._createRow(
|
|
20
20
|
table,
|
|
21
21
|
row$1.id,
|
|
22
22
|
row$1.original,
|
|
@@ -70,7 +70,7 @@ function filterRowModelFromRoot(rowsToFilter, filterRow, table) {
|
|
|
70
70
|
const pass = filterRow(row$1);
|
|
71
71
|
if (pass) {
|
|
72
72
|
if (((_a = row$1.subRows) == null ? void 0 : _a.length) && depth < maxDepth) {
|
|
73
|
-
const newRow = row.
|
|
73
|
+
const newRow = row._createRow(
|
|
74
74
|
table,
|
|
75
75
|
row$1.id,
|
|
76
76
|
row$1.original,
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"filterRowsUtils.cjs","sources":["../../../src/utils/filterRowsUtils.ts"],"sourcesContent":["import {
|
|
1
|
+
{"version":3,"file":"filterRowsUtils.cjs","sources":["../../../src/utils/filterRowsUtils.ts"],"sourcesContent":["import { _createRow } from '../core/row'\nimport { Row, RowModel, Table, RowData } from '../types'\n\nexport function filterRows<TData extends RowData>(\n rows: Row<TData>[],\n filterRowImpl: (row: Row<TData>) => any,\n table: Table<TData>\n) {\n if (table.options.filterFromLeafRows) {\n return filterRowModelFromLeafs(rows, filterRowImpl, table)\n }\n\n return filterRowModelFromRoot(rows, filterRowImpl, table)\n}\n\nfunction filterRowModelFromLeafs<TData extends RowData>(\n rowsToFilter: Row<TData>[],\n filterRow: (row: Row<TData>) => Row<TData>[],\n table: Table<TData>\n): RowModel<TData> {\n const newFilteredFlatRows: Row<TData>[] = []\n const newFilteredRowsById: Record<string, Row<TData>> = {}\n const maxDepth = table.options.maxLeafRowFilterDepth ?? 100\n\n const recurseFilterRows = (rowsToFilter: Row<TData>[], depth = 0) => {\n const rows: Row<TData>[] = []\n\n // Filter from children up first\n for (let i = 0; i < rowsToFilter.length; i++) {\n let row = rowsToFilter[i]!\n\n const newRow = _createRow(\n table,\n row.id,\n row.original,\n row.index,\n row.depth,\n undefined,\n row.parentId\n )\n newRow.columnFilters = row.columnFilters\n\n if (row.subRows?.length && depth < maxDepth) {\n newRow.subRows = recurseFilterRows(row.subRows, depth + 1)\n row = newRow\n\n if (filterRow(row) && !newRow.subRows.length) {\n rows.push(row)\n newFilteredRowsById[row.id] = row\n newFilteredFlatRows.push(row)\n continue\n }\n\n if (filterRow(row) || newRow.subRows.length) {\n rows.push(row)\n newFilteredRowsById[row.id] = row\n newFilteredFlatRows.push(row)\n continue\n }\n } else {\n row = newRow\n if (filterRow(row)) {\n rows.push(row)\n newFilteredRowsById[row.id] = row\n newFilteredFlatRows.push(row)\n }\n }\n }\n\n return rows\n }\n\n return {\n rows: recurseFilterRows(rowsToFilter),\n flatRows: newFilteredFlatRows,\n rowsById: newFilteredRowsById,\n }\n}\n\nfunction filterRowModelFromRoot<TData extends RowData>(\n rowsToFilter: Row<TData>[],\n filterRow: (row: Row<TData>) => any,\n table: Table<TData>\n): RowModel<TData> {\n const newFilteredFlatRows: Row<TData>[] = []\n const newFilteredRowsById: Record<string, Row<TData>> = {}\n const maxDepth = table.options.maxLeafRowFilterDepth ?? 100\n\n // Filters top level and nested rows\n const recurseFilterRows = (rowsToFilter: Row<TData>[], depth = 0) => {\n // Filter from parents downward first\n\n const rows: Row<TData>[] = []\n\n // Apply the filter to any subRows\n for (let i = 0; i < rowsToFilter.length; i++) {\n let row = rowsToFilter[i]!\n\n const pass = filterRow(row)\n\n if (pass) {\n if (row.subRows?.length && depth < maxDepth) {\n const newRow = _createRow(\n table,\n row.id,\n row.original,\n row.index,\n row.depth,\n undefined,\n row.parentId\n )\n newRow.subRows = recurseFilterRows(row.subRows, depth + 1)\n row = newRow\n }\n\n rows.push(row)\n newFilteredFlatRows.push(row)\n newFilteredRowsById[row.id] = row\n }\n }\n\n return rows\n }\n\n return {\n rows: recurseFilterRows(rowsToFilter),\n flatRows: newFilteredFlatRows,\n rowsById: newFilteredRowsById,\n }\n}\n"],"names":["rowsToFilter","row","_createRow"],"mappings":";;;AAGgB,SAAA,WACd,MACA,eACA,OACA;AACI,MAAA,MAAM,QAAQ,oBAAoB;AAC7B,WAAA,wBAAwB,MAAM,eAAe,KAAK;AAAA,EAC3D;AAEO,SAAA,uBAAuB,MAAM,eAAe,KAAK;AAC1D;AAEA,SAAS,wBACP,cACA,WACA,OACiB;AACjB,QAAM,sBAAoC,CAAA;AAC1C,QAAM,sBAAkD,CAAA;AAClD,QAAA,WAAW,MAAM,QAAQ,yBAAyB;AAExD,QAAM,oBAAoB,CAACA,eAA4B,QAAQ,MAAM;;AACnE,UAAM,OAAqB,CAAA;AAG3B,aAAS,IAAI,GAAG,IAAIA,cAAa,QAAQ,KAAK;AACxC,UAAAC,QAAMD,cAAa,CAAC;AAExB,YAAM,SAASE,IAAA;AAAA,QACb;AAAA,QACAD,MAAI;AAAA,QACJA,MAAI;AAAA,QACJA,MAAI;AAAA,QACJA,MAAI;AAAA,QACJ;AAAA,QACAA,MAAI;AAAA,MAAA;AAEN,aAAO,gBAAgBA,MAAI;AAE3B,YAAIA,WAAI,YAAJA,mBAAa,WAAU,QAAQ,UAAU;AAC3C,eAAO,UAAU,kBAAkBA,MAAI,SAAS,QAAQ,CAAC;AACnD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DA,kBAAA;AAAA,QACR;AAEA,aAAK,KAAKA,KAAG;AACb,4BAAoB,KAAKA,KAAG;AACR,4BAAAA,MAAI,EAAE,IAAIA;AAAAA,MAChC;AAAA,IACF;AAEO,WAAA;AAAA,EAAA;AAGF,SAAA;AAAA,IACL,MAAM,kBAAkB,YAAY;AAAA,IACpC,UAAU;AAAA,IACV,UAAU;AAAA,EAAA;AAEd;;"}
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"getCoreRowModel.cjs","sources":["../../../src/utils/getCoreRowModel.ts"],"sourcesContent":["import {
|
|
1
|
+
{"version":3,"file":"getCoreRowModel.cjs","sources":["../../../src/utils/getCoreRowModel.ts"],"sourcesContent":["import { _createRow } from '../core/row'\nimport { Table, Row, RowModel, RowData } from '../types'\nimport { getMemoOptions, memo } from '../utils'\n\nexport function getCoreRowModel<TData extends RowData>(): (\n table: Table<TData>\n) => () => RowModel<TData> {\n return table =>\n memo(\n () => [table.options.data],\n (\n data\n ): {\n rows: Row<TData>[]\n flatRows: Row<TData>[]\n rowsById: Record<string, Row<TData>>\n } => {\n const rowModel: RowModel<TData> = {\n rows: [],\n flatRows: [],\n rowsById: {},\n }\n\n const accessRows = (\n originalRows: TData[],\n depth = 0,\n parentRow?: Row<TData>\n ): Row<TData>[] => {\n const rows = [] as Row<TData>[]\n\n for (let i = 0; i < originalRows.length; i++) {\n // This could be an expensive check at scale, so we should move it somewhere else, but where?\n // if (!id) {\n // if (process.env.NODE_ENV !== 'production') {\n // throw new Error(`getRowId expected an ID, but got ${id}`)\n // }\n // }\n\n // Make the row\n const row = _createRow(\n table,\n table._getRowId(originalRows[i]!, i, parentRow),\n originalRows[i]!,\n i,\n depth,\n undefined,\n parentRow?.id\n )\n\n // Keep track of every row in a flat array\n rowModel.flatRows.push(row)\n // Also keep track of every row by its ID\n rowModel.rowsById[row.id] = row\n // Push table row into parent\n rows.push(row)\n\n // Get the original subrows\n if (table.options.getSubRows) {\n row.originalSubRows = table.options.getSubRows(\n originalRows[i]!,\n i\n )\n\n // Then recursively access them\n if (row.originalSubRows?.length) {\n row.subRows = accessRows(row.originalSubRows, depth + 1, row)\n }\n }\n }\n\n return rows\n }\n\n rowModel.rows = accessRows(data)\n\n return rowModel\n },\n getMemoOptions(table.options, 'debugTable', 'getRowModel', () =>\n table._autoResetPageIndex()\n )\n )\n}\n"],"names":["memo","row","_createRow","getMemoOptions"],"mappings":";;;;AAIO,SAAS,kBAEW;AACzB,SAAO,CACL,UAAAA,MAAA;AAAA,IACE,MAAM,CAAC,MAAM,QAAQ,IAAI;AAAA,IACzB,CACE,SAKG;AACH,YAAM,WAA4B;AAAA,QAChC,MAAM,CAAC;AAAA,QACP,UAAU,CAAC;AAAA,QACX,UAAU,CAAC;AAAA,MAAA;AAGb,YAAM,aAAa,CACjB,cACA,QAAQ,GACR,cACiB;;AACjB,cAAM,OAAO,CAAA;AAEb,iBAAS,IAAI,GAAG,IAAI,aAAa,QAAQ,KAAK;AAS5C,gBAAMC,QAAMC,IAAA;AAAA,YACV;AAAA,YACA,MAAM,UAAU,aAAa,CAAC,GAAI,GAAG,SAAS;AAAA,YAC9C,aAAa,CAAC;AAAA,YACd;AAAA,YACA;AAAA,YACA;AAAA,YACA,uCAAW;AAAA,UAAA;AAIJ,mBAAA,SAAS,KAAKD,KAAG;AAEjB,mBAAA,SAASA,MAAI,EAAE,IAAIA;AAE5B,eAAK,KAAKA,KAAG;AAGT,cAAA,MAAM,QAAQ,YAAY;AACxBA,kBAAA,kBAAkB,MAAM,QAAQ;AAAA,cAClC,aAAa,CAAC;AAAA,cACd;AAAA,YAAA;AAIE,iBAAAA,WAAI,oBAAJA,mBAAqB,QAAQ;AAC/BA,oBAAI,UAAU,WAAWA,MAAI,iBAAiB,QAAQ,GAAGA,KAAG;AAAA,YAC9D;AAAA,UACF;AAAA,QACF;AAEO,eAAA;AAAA,MAAA;AAGA,eAAA,OAAO,WAAW,IAAI;AAExB,aAAA;AAAA,IACT;AAAA,IACAE,MAAA;AAAA,MAAe,MAAM;AAAA,MAAS;AAAA,MAAc;AAAA,MAAe,MACzD,MAAM,oBAAoB;AAAA,IAC5B;AAAA,EAAA;AAEN;;"}
|
|
@@ -9,8 +9,7 @@ function getFacetedMinMaxValues() {
|
|
|
9
9
|
},
|
|
10
10
|
(facetedRowModel) => {
|
|
11
11
|
var _a;
|
|
12
|
-
if (!facetedRowModel)
|
|
13
|
-
return void 0;
|
|
12
|
+
if (!facetedRowModel) return void 0;
|
|
14
13
|
const firstValue = (_a = facetedRowModel.flatRows[0]) == null ? void 0 : _a.getUniqueValues(columnId);
|
|
15
14
|
if (typeof firstValue === "undefined") {
|
|
16
15
|
return void 0;
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"getFacetedMinMaxValues.cjs","sources":["../../../src/utils/getFacetedMinMaxValues.ts"],"sourcesContent":["import { Table, RowData } from '../types'\nimport { getMemoOptions, memo } from '../utils'\n\nexport function getFacetedMinMaxValues<TData extends RowData>(): (\n table: Table<TData>,\n columnId: string\n) => () => undefined | [number, number] {\n return (table, columnId) =>\n memo(\n () => [table.getColumn(columnId)?.getFacetedRowModel()],\n facetedRowModel => {\n if (!facetedRowModel) return undefined\n\n const firstValue =\n facetedRowModel.flatRows[0]?.getUniqueValues(columnId)\n\n if (typeof firstValue === 'undefined') {\n return undefined\n }\n\n let facetedMinMaxValues: [any, any] = [firstValue, firstValue]\n\n for (let i = 0; i < facetedRowModel.flatRows.length; i++) {\n const values =\n facetedRowModel.flatRows[i]!.getUniqueValues<number>(columnId)\n\n for (let j = 0; j < values.length; j++) {\n const value = values[j]!\n\n if (value < facetedMinMaxValues[0]) {\n facetedMinMaxValues[0] = value\n } else if (value > facetedMinMaxValues[1]) {\n facetedMinMaxValues[1] = value\n }\n }\n }\n\n return facetedMinMaxValues\n },\n getMemoOptions(table.options, 'debugTable', 'getFacetedMinMaxValues')\n )\n}\n"],"names":["memo","getMemoOptions"],"mappings":";;;AAGO,SAAS,yBAGwB;AAC/B,SAAA,CAAC,OAAO,aACbA,MAAA;AAAA,IACE,MAAA;;AAAM,eAAC,WAAM,UAAU,QAAQ,MAAxB,mBAA2B,oBAAoB;AAAA;AAAA,IACtD,CAAmB,oBAAA;;
|
|
1
|
+
{"version":3,"file":"getFacetedMinMaxValues.cjs","sources":["../../../src/utils/getFacetedMinMaxValues.ts"],"sourcesContent":["import { Table, RowData } from '../types'\nimport { getMemoOptions, memo } from '../utils'\n\nexport function getFacetedMinMaxValues<TData extends RowData>(): (\n table: Table<TData>,\n columnId: string\n) => () => undefined | [number, number] {\n return (table, columnId) =>\n memo(\n () => [table.getColumn(columnId)?.getFacetedRowModel()],\n facetedRowModel => {\n if (!facetedRowModel) return undefined\n\n const firstValue =\n facetedRowModel.flatRows[0]?.getUniqueValues(columnId)\n\n if (typeof firstValue === 'undefined') {\n return undefined\n }\n\n let facetedMinMaxValues: [any, any] = [firstValue, firstValue]\n\n for (let i = 0; i < facetedRowModel.flatRows.length; i++) {\n const values =\n facetedRowModel.flatRows[i]!.getUniqueValues<number>(columnId)\n\n for (let j = 0; j < values.length; j++) {\n const value = values[j]!\n\n if (value < facetedMinMaxValues[0]) {\n facetedMinMaxValues[0] = value\n } else if (value > facetedMinMaxValues[1]) {\n facetedMinMaxValues[1] = value\n }\n }\n }\n\n return facetedMinMaxValues\n },\n getMemoOptions(table.options, 'debugTable', 'getFacetedMinMaxValues')\n )\n}\n"],"names":["memo","getMemoOptions"],"mappings":";;;AAGO,SAAS,yBAGwB;AAC/B,SAAA,CAAC,OAAO,aACbA,MAAA;AAAA,IACE,MAAA;;AAAM,eAAC,WAAM,UAAU,QAAQ,MAAxB,mBAA2B,oBAAoB;AAAA;AAAA,IACtD,CAAmB,oBAAA;;AACb,UAAA,CAAC,gBAAwB,QAAA;AAE7B,YAAM,cACJ,qBAAgB,SAAS,CAAC,MAA1B,mBAA6B,gBAAgB;AAE3C,UAAA,OAAO,eAAe,aAAa;AAC9B,eAAA;AAAA,MACT;AAEI,UAAA,sBAAkC,CAAC,YAAY,UAAU;AAE7D,eAAS,IAAI,GAAG,IAAI,gBAAgB,SAAS,QAAQ,KAAK;AACxD,cAAM,SACJ,gBAAgB,SAAS,CAAC,EAAG,gBAAwB,QAAQ;AAE/D,iBAAS,IAAI,GAAG,IAAI,OAAO,QAAQ,KAAK;AAChC,gBAAA,QAAQ,OAAO,CAAC;AAElB,cAAA,QAAQ,oBAAoB,CAAC,GAAG;AAClC,gCAAoB,CAAC,IAAI;AAAA,UAChB,WAAA,QAAQ,oBAAoB,CAAC,GAAG;AACzC,gCAAoB,CAAC,IAAI;AAAA,UAC3B;AAAA,QACF;AAAA,MACF;AAEO,aAAA;AAAA,IACT;AAAA,IACAC,MAAAA,eAAe,MAAM,SAAS,cAAc,wBAAwB;AAAA,EAAA;AAE1E;;"}
|
|
@@ -8,8 +8,7 @@ function getFacetedUniqueValues() {
|
|
|
8
8
|
return [(_a = table.getColumn(columnId)) == null ? void 0 : _a.getFacetedRowModel()];
|
|
9
9
|
},
|
|
10
10
|
(facetedRowModel) => {
|
|
11
|
-
if (!facetedRowModel)
|
|
12
|
-
return /* @__PURE__ */ new Map();
|
|
11
|
+
if (!facetedRowModel) return /* @__PURE__ */ new Map();
|
|
13
12
|
let facetedUniqueValues = /* @__PURE__ */ new Map();
|
|
14
13
|
for (let i = 0; i < facetedRowModel.flatRows.length; i++) {
|
|
15
14
|
const values = facetedRowModel.flatRows[i].getUniqueValues(columnId);
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"getFacetedUniqueValues.cjs","sources":["../../../src/utils/getFacetedUniqueValues.ts"],"sourcesContent":["import { Table, RowData } from '../types'\nimport { getMemoOptions, memo } from '../utils'\n\nexport function getFacetedUniqueValues<TData extends RowData>(): (\n table: Table<TData>,\n columnId: string\n) => () => Map<any, number> {\n return (table, columnId) =>\n memo(\n () => [table.getColumn(columnId)?.getFacetedRowModel()],\n facetedRowModel => {\n if (!facetedRowModel) return new Map()\n\n let facetedUniqueValues = new Map<any, number>()\n\n for (let i = 0; i < facetedRowModel.flatRows.length; i++) {\n const values =\n facetedRowModel.flatRows[i]!.getUniqueValues<number>(columnId)\n\n for (let j = 0; j < values.length; j++) {\n const value = values[j]!\n\n if (facetedUniqueValues.has(value)) {\n facetedUniqueValues.set(\n value,\n (facetedUniqueValues.get(value) ?? 0) + 1\n )\n } else {\n facetedUniqueValues.set(value, 1)\n }\n }\n }\n\n return facetedUniqueValues\n },\n getMemoOptions(\n table.options,\n 'debugTable',\n `getFacetedUniqueValues_${columnId}`\n )\n )\n}\n"],"names":["memo","getMemoOptions"],"mappings":";;;AAGO,SAAS,yBAGY;AACnB,SAAA,CAAC,OAAO,aACbA,MAAA;AAAA,IACE,MAAA;;AAAM,eAAC,WAAM,UAAU,QAAQ,MAAxB,mBAA2B,oBAAoB;AAAA;AAAA,IACtD,CAAmB,oBAAA;AACjB,UAAI,CAAC
|
|
1
|
+
{"version":3,"file":"getFacetedUniqueValues.cjs","sources":["../../../src/utils/getFacetedUniqueValues.ts"],"sourcesContent":["import { Table, RowData } from '../types'\nimport { getMemoOptions, memo } from '../utils'\n\nexport function getFacetedUniqueValues<TData extends RowData>(): (\n table: Table<TData>,\n columnId: string\n) => () => Map<any, number> {\n return (table, columnId) =>\n memo(\n () => [table.getColumn(columnId)?.getFacetedRowModel()],\n facetedRowModel => {\n if (!facetedRowModel) return new Map()\n\n let facetedUniqueValues = new Map<any, number>()\n\n for (let i = 0; i < facetedRowModel.flatRows.length; i++) {\n const values =\n facetedRowModel.flatRows[i]!.getUniqueValues<number>(columnId)\n\n for (let j = 0; j < values.length; j++) {\n const value = values[j]!\n\n if (facetedUniqueValues.has(value)) {\n facetedUniqueValues.set(\n value,\n (facetedUniqueValues.get(value) ?? 0) + 1\n )\n } else {\n facetedUniqueValues.set(value, 1)\n }\n }\n }\n\n return facetedUniqueValues\n },\n getMemoOptions(\n table.options,\n 'debugTable',\n `getFacetedUniqueValues_${columnId}`\n )\n )\n}\n"],"names":["memo","getMemoOptions"],"mappings":";;;AAGO,SAAS,yBAGY;AACnB,SAAA,CAAC,OAAO,aACbA,MAAA;AAAA,IACE,MAAA;;AAAM,eAAC,WAAM,UAAU,QAAQ,MAAxB,mBAA2B,oBAAoB;AAAA;AAAA,IACtD,CAAmB,oBAAA;AACjB,UAAI,CAAC,gBAAwB,QAAA,oBAAI;AAE7B,UAAA,0CAA0B;AAE9B,eAAS,IAAI,GAAG,IAAI,gBAAgB,SAAS,QAAQ,KAAK;AACxD,cAAM,SACJ,gBAAgB,SAAS,CAAC,EAAG,gBAAwB,QAAQ;AAE/D,iBAAS,IAAI,GAAG,IAAI,OAAO,QAAQ,KAAK;AAChC,gBAAA,QAAQ,OAAO,CAAC;AAElB,cAAA,oBAAoB,IAAI,KAAK,GAAG;AACd,gCAAA;AAAA,cAClB;AAAA,eACC,oBAAoB,IAAI,KAAK,KAAK,KAAK;AAAA,YAAA;AAAA,UAC1C,OACK;AACe,gCAAA,IAAI,OAAO,CAAC;AAAA,UAClC;AAAA,QACF;AAAA,MACF;AAEO,aAAA;AAAA,IACT;AAAA,IACAC,MAAA;AAAA,MACE,MAAM;AAAA,MACN;AAAA,MACA,0BAA0B,QAAQ;AAAA,IACpC;AAAA,EAAA;AAEN;;"}
|
|
@@ -34,7 +34,7 @@ function getGroupedRowModel() {
|
|
|
34
34
|
id = parentId ? `${parentId}>${id}` : id;
|
|
35
35
|
const subRows = groupUpRecursively(groupedRows2, depth + 1, id);
|
|
36
36
|
const leafRows = depth ? utils.flattenBy(groupedRows2, (row2) => row2.subRows) : groupedRows2;
|
|
37
|
-
const row$1 = row.
|
|
37
|
+
const row$1 = row._createRow(
|
|
38
38
|
table,
|
|
39
39
|
id,
|
|
40
40
|
leafRows[0].original,
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"getGroupedRowModel.cjs","sources":["../../../src/utils/getGroupedRowModel.ts"],"sourcesContent":["import {
|
|
1
|
+
{"version":3,"file":"getGroupedRowModel.cjs","sources":["../../../src/utils/getGroupedRowModel.ts"],"sourcesContent":["import { _createRow } from '../core/row'\nimport { Table, Row, RowModel, RowData } from '../types'\nimport { flattenBy, getMemoOptions, memo } from '../utils'\n\nexport function getGroupedRowModel<TData extends RowData>(): (\n table: Table<TData>\n) => () => RowModel<TData> {\n return table =>\n memo(\n () => [table.getState().grouping, table.getPreGroupedRowModel()],\n (grouping, rowModel) => {\n if (!rowModel.rows.length || !grouping.length) {\n return rowModel\n }\n\n // Filter the grouping list down to columns that exist\n const existingGrouping = grouping.filter(columnId =>\n table.getColumn(columnId)\n )\n\n const groupedFlatRows: Row<TData>[] = []\n const groupedRowsById: Record<string, Row<TData>> = {}\n // const onlyGroupedFlatRows: Row[] = [];\n // const onlyGroupedRowsById: Record<RowId, Row> = {};\n // const nonGroupedFlatRows: Row[] = [];\n // const nonGroupedRowsById: Record<RowId, Row> = {};\n\n // Recursively group the data\n const groupUpRecursively = (\n rows: Row<TData>[],\n depth = 0,\n parentId?: string\n ) => {\n // Grouping depth has been been met\n // Stop grouping and simply rewrite thd depth and row relationships\n if (depth >= existingGrouping.length) {\n return rows.map(row => {\n row.depth = depth\n\n groupedFlatRows.push(row)\n groupedRowsById[row.id] = row\n\n if (row.subRows) {\n row.subRows = groupUpRecursively(row.subRows, depth + 1, row.id)\n }\n\n return row\n })\n }\n\n const columnId: string = existingGrouping[depth]!\n\n // Group the rows together for this level\n const rowGroupsMap = groupBy(rows, columnId)\n\n // Peform aggregations for each group\n const aggregatedGroupedRows = Array.from(rowGroupsMap.entries()).map(\n ([groupingValue, groupedRows], index) => {\n let id = `${columnId}:${groupingValue}`\n id = parentId ? `${parentId}>${id}` : id\n\n // First, Recurse to group sub rows before aggregation\n const subRows = groupUpRecursively(groupedRows, depth + 1, id)\n\n // Flatten the leaf rows of the rows in this group\n const leafRows = depth\n ? flattenBy(groupedRows, row => row.subRows)\n : groupedRows\n\n const row = _createRow(\n table,\n id,\n leafRows[0]!.original,\n index,\n depth,\n undefined,\n parentId\n )\n\n Object.assign(row, {\n groupingColumnId: columnId,\n groupingValue,\n subRows,\n leafRows,\n getValue: (columnId: string) => {\n // Don't aggregate columns that are in the grouping\n if (existingGrouping.includes(columnId)) {\n if (row._valuesCache.hasOwnProperty(columnId)) {\n return row._valuesCache[columnId]\n }\n\n if (groupedRows[0]) {\n row._valuesCache[columnId] =\n groupedRows[0].getValue(columnId) ?? undefined\n }\n\n return row._valuesCache[columnId]\n }\n\n if (row._groupingValuesCache.hasOwnProperty(columnId)) {\n return row._groupingValuesCache[columnId]\n }\n\n // Aggregate the values\n const column = table.getColumn(columnId)\n const aggregateFn = column?.getAggregationFn()\n\n if (aggregateFn) {\n row._groupingValuesCache[columnId] = aggregateFn(\n columnId,\n leafRows,\n groupedRows\n )\n\n return row._groupingValuesCache[columnId]\n }\n },\n })\n\n subRows.forEach(subRow => {\n groupedFlatRows.push(subRow)\n groupedRowsById[subRow.id] = subRow\n // if (subRow.getIsGrouped?.()) {\n // onlyGroupedFlatRows.push(subRow);\n // onlyGroupedRowsById[subRow.id] = subRow;\n // } else {\n // nonGroupedFlatRows.push(subRow);\n // nonGroupedRowsById[subRow.id] = subRow;\n // }\n })\n\n return row\n }\n )\n\n return aggregatedGroupedRows\n }\n\n const groupedRows = groupUpRecursively(rowModel.rows, 0)\n\n groupedRows.forEach(subRow => {\n groupedFlatRows.push(subRow)\n groupedRowsById[subRow.id] = subRow\n // if (subRow.getIsGrouped?.()) {\n // onlyGroupedFlatRows.push(subRow);\n // onlyGroupedRowsById[subRow.id] = subRow;\n // } else {\n // nonGroupedFlatRows.push(subRow);\n // nonGroupedRowsById[subRow.id] = subRow;\n // }\n })\n\n return {\n rows: groupedRows,\n flatRows: groupedFlatRows,\n rowsById: groupedRowsById,\n }\n },\n getMemoOptions(table.options, 'debugTable', 'getGroupedRowModel', () => {\n table._queue(() => {\n table._autoResetExpanded()\n table._autoResetPageIndex()\n })\n })\n )\n}\n\nfunction groupBy<TData extends RowData>(rows: Row<TData>[], columnId: string) {\n const groupMap = new Map<any, Row<TData>[]>()\n\n return rows.reduce((map, row) => {\n const resKey = `${row.getGroupingValue(columnId)}`\n const previous = map.get(resKey)\n if (!previous) {\n map.set(resKey, [row])\n } else {\n previous.push(row)\n }\n return map\n }, groupMap)\n}\n"],"names":["memo","row","groupedRows","flattenBy","_createRow","columnId","getMemoOptions"],"mappings":";;;;AAIO,SAAS,qBAEW;AACzB,SAAO,CACL,UAAAA,MAAA;AAAA,IACE,MAAM,CAAC,MAAM,SAAA,EAAW,UAAU,MAAM,uBAAuB;AAAA,IAC/D,CAAC,UAAU,aAAa;AACtB,UAAI,CAAC,SAAS,KAAK,UAAU,CAAC,SAAS,QAAQ;AACtC,eAAA;AAAA,MACT;AAGA,YAAM,mBAAmB,SAAS;AAAA,QAAO,CAAA,aACvC,MAAM,UAAU,QAAQ;AAAA,MAAA;AAG1B,YAAM,kBAAgC,CAAA;AACtC,YAAM,kBAA8C,CAAA;AAOpD,YAAM,qBAAqB,CACzB,MACA,QAAQ,GACR,aACG;AAGC,YAAA,SAAS,iBAAiB,QAAQ;AAC7B,iBAAA,KAAK,IAAI,CAAOC,SAAA;AACrB,YAAAA,KAAI,QAAQ;AAEZ,4BAAgB,KAAKA,IAAG;AACR,4BAAAA,KAAI,EAAE,IAAIA;AAE1B,gBAAIA,KAAI,SAAS;AACf,cAAAA,KAAI,UAAU,mBAAmBA,KAAI,SAAS,QAAQ,GAAGA,KAAI,EAAE;AAAA,YACjE;AAEO,mBAAAA;AAAA,UAAA,CACR;AAAA,QACH;AAEM,cAAA,WAAmB,iBAAiB,KAAK;AAGzC,cAAA,eAAe,QAAQ,MAAM,QAAQ;AAG3C,cAAM,wBAAwB,MAAM,KAAK,aAAa,QAAS,CAAA,EAAE;AAAA,UAC/D,CAAC,CAAC,eAAeC,YAAW,GAAG,UAAU;AACvC,gBAAI,KAAK,GAAG,QAAQ,IAAI,aAAa;AACrC,iBAAK,WAAW,GAAG,QAAQ,IAAI,EAAE,KAAK;AAGtC,k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AAc,mBAAmB,SAAS,MAAM,CAAC;AAEvD,kBAAY,QAAQ,CAAU,WAAA;AAC5B,wBAAgB,KAAK,MAAM;AACX,wBAAA,OAAO,EAAE,IAAI;AAAA,MAAA,CAQ9B;AAEM,aAAA;AAAA,QACL,MAAM;AAAA,QACN,UAAU;AAAA,QACV,UAAU;AAAA,MAAA;AAAA,IAEd;AAAA,IACAK,MAAAA,eAAe,MAAM,SAAS,cAAc,sBAAsB,MAAM;AACtE,YAAM,OAAO,MAAM;AACjB,cAAM,mBAAmB;AACzB,cAAM,oBAAoB;AAAA,MAAA,CAC3B;AAAA,IAAA,CACF;AAAA,EAAA;AAEP;AAEA,SAAS,QAA+B,MAAoB,UAAkB;AACtE,QAAA,+BAAe;AAErB,SAAO,KAAK,OAAO,CAAC,KAAKL,SAAQ;AAC/B,UAAM,SAAS,GAAGA,KAAI,iBAAiB,QAAQ,CAAC;AAC1C,UAAA,WAAW,IAAI,IAAI,MAAM;AAC/B,QAAI,CAAC,UAAU;AACb,UAAI,IAAI,QAAQ,CAACA,IAAG,CAAC;AAAA,IAAA,OAChB;AACL,eAAS,KAAKA,IAAG;AAAA,IACnB;AACO,WAAA;AAAA,KACN,QAAQ;AACb;;"}
|
|
@@ -19,8 +19,7 @@ function getSortedRowModel() {
|
|
|
19
19
|
const columnInfoById = {};
|
|
20
20
|
availableSorting.forEach((sortEntry) => {
|
|
21
21
|
const column = table.getColumn(sortEntry.id);
|
|
22
|
-
if (!column)
|
|
23
|
-
return;
|
|
22
|
+
if (!column) return;
|
|
24
23
|
columnInfoById[sortEntry.id] = {
|
|
25
24
|
sortUndefined: column.columnDef.sortUndefined,
|
|
26
25
|
invertSorting: column.columnDef.invertSorting,
|
|
@@ -42,10 +41,8 @@ function getSortedRowModel() {
|
|
|
42
41
|
const aUndefined = aValue === void 0;
|
|
43
42
|
const bUndefined = bValue === void 0;
|
|
44
43
|
if (aUndefined || bUndefined) {
|
|
45
|
-
if (sortUndefined === "first")
|
|
46
|
-
|
|
47
|
-
if (sortUndefined === "last")
|
|
48
|
-
return aUndefined ? 1 : -1;
|
|
44
|
+
if (sortUndefined === "first") return aUndefined ? -1 : 1;
|
|
45
|
+
if (sortUndefined === "last") return aUndefined ? 1 : -1;
|
|
49
46
|
sortInt = aUndefined && bUndefined ? 0 : aUndefined ? sortUndefined : -sortUndefined;
|
|
50
47
|
}
|
|
51
48
|
}
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"getSortedRowModel.cjs","sources":["../../../src/utils/getSortedRowModel.ts"],"sourcesContent":["import { Table, Row, RowModel, RowData } from '../types'\nimport { SortingFn } from '../features/RowSorting'\nimport { getMemoOptions, memo } from '../utils'\n\nexport function getSortedRowModel<TData extends RowData>(): (\n table: Table<TData>\n) => () => RowModel<TData> {\n return table =>\n memo(\n () => [table.getState().sorting, table.getPreSortedRowModel()],\n (sorting, rowModel) => {\n if (!rowModel.rows.length || !sorting?.length) {\n return rowModel\n }\n\n const sortingState = table.getState().sorting\n\n const sortedFlatRows: Row<TData>[] = []\n\n // Filter out sortings that correspond to non existing columns\n const availableSorting = sortingState.filter(\n sort => table.getColumn(sort.id)?.getCanSort()\n )\n\n const columnInfoById: Record<\n string,\n {\n sortUndefined?: false | -1 | 1 | 'first' | 'last'\n invertSorting?: boolean\n sortingFn: SortingFn<TData>\n }\n > = {}\n\n availableSorting.forEach(sortEntry => {\n const column = table.getColumn(sortEntry.id)\n if (!column) return\n\n columnInfoById[sortEntry.id] = {\n sortUndefined: column.columnDef.sortUndefined,\n invertSorting: column.columnDef.invertSorting,\n sortingFn: column.getSortingFn(),\n }\n })\n\n const sortData = (rows: Row<TData>[]) => {\n // This will also perform a stable sorting using the row index\n // if needed.\n const sortedData = rows.map(row => ({ ...row }))\n\n sortedData.sort((rowA, rowB) => {\n for (let i = 0; i < availableSorting.length; i += 1) {\n const sortEntry = availableSorting[i]!\n const columnInfo = columnInfoById[sortEntry.id]!\n const sortUndefined = columnInfo.sortUndefined\n const isDesc = sortEntry?.desc ?? false\n\n let sortInt = 0\n\n // All sorting ints should always return in ascending order\n if (sortUndefined) {\n const aValue = rowA.getValue(sortEntry.id)\n const bValue = rowB.getValue(sortEntry.id)\n\n const aUndefined = aValue === undefined\n const bUndefined = bValue === undefined\n\n if (aUndefined || bUndefined) {\n if (sortUndefined === 'first') return aUndefined ? -1 : 1\n if (sortUndefined === 'last') return aUndefined ? 1 : -1\n sortInt =\n aUndefined && bUndefined\n ? 0\n : aUndefined\n ? sortUndefined\n : -sortUndefined\n }\n }\n\n if (sortInt === 0) {\n sortInt = columnInfo.sortingFn(rowA, rowB, sortEntry.id)\n }\n\n // If sorting is non-zero, take care of desc and inversion\n if (sortInt !== 0) {\n if (isDesc) {\n sortInt *= -1\n }\n\n if (columnInfo.invertSorting) {\n sortInt *= -1\n }\n\n return sortInt\n }\n }\n\n return rowA.index - rowB.index\n })\n\n // If there are sub-rows, sort them\n sortedData.forEach(row => {\n sortedFlatRows.push(row)\n if (row.subRows?.length) {\n row.subRows = sortData(row.subRows)\n }\n })\n\n return sortedData\n }\n\n return {\n rows: sortData(rowModel.rows),\n flatRows: sortedFlatRows,\n rowsById: rowModel.rowsById,\n }\n },\n getMemoOptions(table.options, 'debugTable', 'getSortedRowModel', () =>\n table._autoResetPageIndex()\n )\n )\n}\n"],"names":["memo","getMemoOptions"],"mappings":";;;AAIO,SAAS,oBAEW;AACzB,SAAO,CACL,UAAAA,MAAA;AAAA,IACE,MAAM,CAAC,MAAM,SAAA,EAAW,SAAS,MAAM,sBAAsB;AAAA,IAC7D,CAAC,SAAS,aAAa;AACrB,UAAI,CAAC,SAAS,KAAK,UAAU,EAAC,mCAAS,SAAQ;AACtC,eAAA;AAAA,MACT;AAEM,YAAA,eAAe,MAAM,SAAA,EAAW;AAEtC,YAAM,iBAA+B,CAAA;AAGrC,YAAM,mBAAmB,aAAa;AAAA,QACpC,UAAQ;;AAAA,6BAAM,UAAU,KAAK,EAAE,MAAvB,mBAA0B;AAAA;AAAA,MAAW;AAG/C,YAAM,iBAOF,CAAA;AAEJ,uBAAiB,QAAQ,CAAa,cAAA;AACpC,cAAM,SAAS,MAAM,UAAU,UAAU,EAAE;AAC3C,YAAI,CAAC;
|
|
1
|
+
{"version":3,"file":"getSortedRowModel.cjs","sources":["../../../src/utils/getSortedRowModel.ts"],"sourcesContent":["import { Table, Row, RowModel, RowData } from '../types'\nimport { SortingFn } from '../features/RowSorting'\nimport { getMemoOptions, memo } from '../utils'\n\nexport function getSortedRowModel<TData extends RowData>(): (\n table: Table<TData>\n) => () => RowModel<TData> {\n return table =>\n memo(\n () => [table.getState().sorting, table.getPreSortedRowModel()],\n (sorting, rowModel) => {\n if (!rowModel.rows.length || !sorting?.length) {\n return rowModel\n }\n\n const sortingState = table.getState().sorting\n\n const sortedFlatRows: Row<TData>[] = []\n\n // Filter out sortings that correspond to non existing columns\n const availableSorting = sortingState.filter(\n sort => table.getColumn(sort.id)?.getCanSort()\n )\n\n const columnInfoById: Record<\n string,\n {\n sortUndefined?: false | -1 | 1 | 'first' | 'last'\n invertSorting?: boolean\n sortingFn: SortingFn<TData>\n }\n > = {}\n\n availableSorting.forEach(sortEntry => {\n const column = table.getColumn(sortEntry.id)\n if (!column) return\n\n columnInfoById[sortEntry.id] = {\n sortUndefined: column.columnDef.sortUndefined,\n invertSorting: column.columnDef.invertSorting,\n sortingFn: column.getSortingFn(),\n }\n })\n\n const sortData = (rows: Row<TData>[]) => {\n // This will also perform a stable sorting using the row index\n // if needed.\n const sortedData = rows.map(row => ({ ...row }))\n\n sortedData.sort((rowA, rowB) => {\n for (let i = 0; i < availableSorting.length; i += 1) {\n const sortEntry = availableSorting[i]!\n const columnInfo = columnInfoById[sortEntry.id]!\n const sortUndefined = columnInfo.sortUndefined\n const isDesc = sortEntry?.desc ?? false\n\n let sortInt = 0\n\n // All sorting ints should always return in ascending order\n if (sortUndefined) {\n const aValue = rowA.getValue(sortEntry.id)\n const bValue = rowB.getValue(sortEntry.id)\n\n const aUndefined = aValue === undefined\n const bUndefined = bValue === undefined\n\n if (aUndefined || bUndefined) {\n if (sortUndefined === 'first') return aUndefined ? -1 : 1\n if (sortUndefined === 'last') return aUndefined ? 1 : -1\n sortInt =\n aUndefined && bUndefined\n ? 0\n : aUndefined\n ? sortUndefined\n : -sortUndefined\n }\n }\n\n if (sortInt === 0) {\n sortInt = columnInfo.sortingFn(rowA, rowB, sortEntry.id)\n }\n\n // If sorting is non-zero, take care of desc and inversion\n if (sortInt !== 0) {\n if (isDesc) {\n sortInt *= -1\n }\n\n if (columnInfo.invertSorting) {\n sortInt *= -1\n }\n\n return sortInt\n }\n }\n\n return rowA.index - rowB.index\n })\n\n // If there are sub-rows, sort them\n sortedData.forEach(row => {\n sortedFlatRows.push(row)\n if (row.subRows?.length) {\n row.subRows = sortData(row.subRows)\n }\n })\n\n return sortedData\n }\n\n return {\n rows: sortData(rowModel.rows),\n flatRows: sortedFlatRows,\n rowsById: rowModel.rowsById,\n }\n },\n getMemoOptions(table.options, 'debugTable', 'getSortedRowModel', () =>\n table._autoResetPageIndex()\n )\n )\n}\n"],"names":["memo","getMemoOptions"],"mappings":";;;AAIO,SAAS,oBAEW;AACzB,SAAO,CACL,UAAAA,MAAA;AAAA,IACE,MAAM,CAAC,MAAM,SAAA,EAAW,SAAS,MAAM,sBAAsB;AAAA,IAC7D,CAAC,SAAS,aAAa;AACrB,UAAI,CAAC,SAAS,KAAK,UAAU,EAAC,mCAAS,SAAQ;AACtC,eAAA;AAAA,MACT;AAEM,YAAA,eAAe,MAAM,SAAA,EAAW;AAEtC,YAAM,iBAA+B,CAAA;AAGrC,YAAM,mBAAmB,aAAa;AAAA,QACpC,UAAQ;;AAAA,6BAAM,UAAU,KAAK,EAAE,MAAvB,mBAA0B;AAAA;AAAA,MAAW;AAG/C,YAAM,iBAOF,CAAA;AAEJ,uBAAiB,QAAQ,CAAa,cAAA;AACpC,cAAM,SAAS,MAAM,UAAU,UAAU,EAAE;AAC3C,YAAI,CAAC,OAAQ;AAEE,u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B,gBAAA,UAAU,SAAS,IAAI,OAAO;AAAA,UACpC;AAAA,QAAA,CACD;AAEM,eAAA;AAAA,MAAA;AAGF,aAAA;AAAA,QACL,MAAM,SAAS,SAAS,IAAI;AAAA,QAC5B,UAAU;AAAA,QACV,UAAU,SAAS;AAAA,MAAA;AAAA,IAEvB;AAAA,IACAC,MAAA;AAAA,MAAe,MAAM;AAAA,MAAS;AAAA,MAAc;AAAA,MAAqB,MAC/D,MAAM,oBAAoB;AAAA,IAC5B;AAAA,EAAA;AAEN;;"}
|
package/dist/cjs/utils.cjs
CHANGED
|
@@ -41,8 +41,7 @@ function memo(getDeps, fn, opts) {
|
|
|
41
41
|
return (depArgs) => {
|
|
42
42
|
var _a;
|
|
43
43
|
let depTime;
|
|
44
|
-
if (opts.key && opts.debug)
|
|
45
|
-
depTime = Date.now();
|
|
44
|
+
if (opts.key && opts.debug) depTime = Date.now();
|
|
46
45
|
const newDeps = getDeps(depArgs);
|
|
47
46
|
const depsChanged = newDeps.length !== deps.length || newDeps.some((dep, index) => deps[index] !== dep);
|
|
48
47
|
if (!depsChanged) {
|
|
@@ -50,8 +49,7 @@ function memo(getDeps, fn, opts) {
|
|
|
50
49
|
}
|
|
51
50
|
deps = newDeps;
|
|
52
51
|
let resultTime;
|
|
53
|
-
if (opts.key && opts.debug)
|
|
54
|
-
resultTime = Date.now();
|
|
52
|
+
if (opts.key && opts.debug) resultTime = Date.now();
|
|
55
53
|
result = fn(...newDeps);
|
|
56
54
|
(_a = opts == null ? void 0 : opts.onChange) == null ? void 0 : _a.call(opts, result);
|
|
57
55
|
if (opts.key && opts.debug) {
|
package/dist/cjs/utils.cjs.map
CHANGED
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"utils.cjs","sources":["../../src/utils.ts"],"sourcesContent":["import { TableOptionsResolved, TableState, Updater } from './types'\n\nexport type PartialKeys<T, K extends keyof T> = Omit<T, K> & Partial<Pick<T, K>>\nexport type RequiredKeys<T, K extends keyof T> = Omit<T, K> &\n Required<Pick<T, K>>\nexport type Overwrite<T, U extends { [TKey in keyof T]?: any }> = Omit<\n T,\n keyof U\n> &\n U\n\nexport type UnionToIntersection<T> = (\n T extends any ? (x: T) => any : never\n) extends (x: infer R) => any\n ? R\n : never\n\nexport type IsAny<T, Y, N> = 1 extends 0 & T ? Y : N\nexport type IsKnown<T, Y, N> = unknown extends T ? N : Y\n\ntype ComputeRange<\n N extends number,\n Result extends Array<unknown> = [],\n> = Result['length'] extends N\n ? Result\n : ComputeRange<N, [...Result, Result['length']]>\ntype Index40 = ComputeRange<40>[number]\n\n// Is this type a tuple?\ntype IsTuple<T> = T extends readonly any[] & { length: infer Length }\n ? Length extends Index40\n ? T\n : never\n : never\n\n// If this type is a tuple, what indices are allowed?\ntype AllowedIndexes<\n Tuple extends ReadonlyArray<any>,\n Keys extends number = never,\n> = Tuple extends readonly []\n ? Keys\n : Tuple extends readonly [infer _, ...infer Tail]\n ? AllowedIndexes<Tail, Keys | Tail['length']>\n : Keys\n\nexport type DeepKeys<T, TDepth extends any[] = []> = TDepth['length'] extends 5\n ? never\n : unknown extends T\n ? string\n : T extends readonly any[] & IsTuple<T>\n ? AllowedIndexes<T> | DeepKeysPrefix<T, AllowedIndexes<T>, TDepth>\n : T extends any[]\n ? DeepKeys<T[number], [...TDepth, any]>\n : T extends Date\n ? never\n : T extends object\n ? (keyof T & string) | DeepKeysPrefix<T, keyof T, TDepth>\n : never\n\ntype DeepKeysPrefix<\n T,\n TPrefix,\n TDepth extends any[],\n> = TPrefix extends keyof T & (number | string)\n ? `${TPrefix}.${DeepKeys<T[TPrefix], [...TDepth, any]> & string}`\n : never\n\nexport type DeepValue<T, TProp> = T extends Record<string | number, any>\n ? TProp extends `${infer TBranch}.${infer TDeepProp}`\n ? DeepValue<T[TBranch], TDeepProp>\n : T[TProp & string]\n : never\n\nexport type NoInfer<T> = [T][T extends any ? 0 : never]\n\nexport type Getter<TValue> = <TTValue = TValue>() => NoInfer<TTValue>\n\n///\n\nexport function functionalUpdate<T>(updater: Updater<T>, input: T): T {\n return typeof updater === 'function'\n ? (updater as (input: T) => T)(input)\n : updater\n}\n\nexport function noop() {\n //\n}\n\nexport function makeStateUpdater<K extends keyof TableState>(\n key: K,\n instance: unknown\n) {\n return (updater: Updater<TableState[K]>) => {\n ;(instance as any).setState(<TTableState>(old: TTableState) => {\n return {\n ...old,\n [key]: functionalUpdate(updater, (old as any)[key]),\n }\n })\n }\n}\n\ntype AnyFunction = (...args: any) => any\n\nexport function isFunction<T extends AnyFunction>(d: any): d is T {\n return d instanceof Function\n}\n\nexport function isNumberArray(d: any): d is number[] {\n return Array.isArray(d) && d.every(val => typeof val === 'number')\n}\n\nexport function flattenBy<TNode>(\n arr: TNode[],\n getChildren: (item: TNode) => TNode[]\n) {\n const flat: TNode[] = []\n\n const recurse = (subArr: TNode[]) => {\n subArr.forEach(item => {\n flat.push(item)\n const children = getChildren(item)\n if (children?.length) {\n recurse(children)\n }\n })\n }\n\n recurse(arr)\n\n return flat\n}\n\nexport function memo<TDeps extends readonly any[], TDepArgs, TResult>(\n getDeps: (depArgs?: TDepArgs) => [...TDeps],\n fn: (...args: NoInfer<[...TDeps]>) => TResult,\n opts: {\n key: any\n debug?: () => any\n onChange?: (result: TResult) => void\n }\n): (depArgs?: TDepArgs) => TResult {\n let deps: any[] = []\n let result: TResult | undefined\n\n return depArgs => {\n let depTime: number\n if (opts.key && opts.debug) depTime = Date.now()\n\n const newDeps = getDeps(depArgs)\n\n const depsChanged =\n newDeps.length !== deps.length ||\n newDeps.some((dep: any, index: number) => deps[index] !== dep)\n\n if (!depsChanged) {\n return result!\n }\n\n deps = newDeps\n\n let resultTime: number\n if (opts.key && opts.debug) resultTime = Date.now()\n\n result = fn(...newDeps)\n opts?.onChange?.(result)\n\n if (opts.key && opts.debug) {\n if (opts?.debug()) {\n const depEndTime = Math.round((Date.now() - depTime!) * 100) / 100\n const resultEndTime = Math.round((Date.now() - resultTime!) * 100) / 100\n const resultFpsPercentage = resultEndTime / 16\n\n const pad = (str: number | string, num: number) => {\n str = String(str)\n while (str.length < num) {\n str = ' ' + str\n }\n return str\n }\n\n console.info(\n `%c⏱ ${pad(resultEndTime, 5)} /${pad(depEndTime, 5)} ms`,\n `\n font-size: .6rem;\n font-weight: bold;\n color: hsl(${Math.max(\n 0,\n Math.min(120 - 120 * resultFpsPercentage, 120)\n )}deg 100% 31%);`,\n opts?.key\n )\n }\n }\n\n return result!\n }\n}\n\nexport function getMemoOptions(\n tableOptions: Partial<TableOptionsResolved<any>>,\n debugLevel:\n | 'debugAll'\n | 'debugCells'\n | 'debugTable'\n | 'debugColumns'\n | 'debugRows'\n | 'debugHeaders',\n key: string,\n onChange?: (result: any) => void\n) {\n return {\n debug: () => tableOptions?.debugAll ?? tableOptions[debugLevel],\n key: process.env.NODE_ENV === 'development' && key,\n onChange,\n }\n}\n"],"names":[],"mappings":";;AA+EgB,SAAA,iBAAoB,SAAqB,OAAa;AACpE,SAAO,OAAO,YAAY,aACrB,QAA4B,KAAK,IAClC;AACN;AAEO,SAAS,OAAO;AAEvB;AAEgB,SAAA,iBACd,KACA,UACA;AACA,SAAO,CAAC,YAAoC;AACxC,aAAiB,SAAS,CAAc,QAAqB;AACtD,aAAA;AAAA,QACL,GAAG;AAAA,QACH,CAAC,GAAG,GAAG,iBAAiB,SAAU,IAAY,GAAG,CAAC;AAAA,MAAA;AAAA,IACpD,CACD;AAAA,EAAA;AAEL;AAIO,SAAS,WAAkC,GAAgB;AAChE,SAAO,aAAa;AACtB;AAEO,SAAS,cAAc,GAAuB;AAC5C,SAAA,MAAM,QAAQ,CAAC,KAAK,EAAE,MAAM,CAAA,QAAO,OAAO,QAAQ,QAAQ;AACnE;AAEgB,SAAA,UACd,KACA,aACA;AACA,QAAM,OAAgB,CAAA;AAEhB,QAAA,UAAU,CAAC,WAAoB;AACnC,WAAO,QAAQ,CAAQ,SAAA;AACrB,WAAK,KAAK,IAAI;AACR,YAAA,WAAW,YAAY,IAAI;AACjC,UAAI,qCAAU,QAAQ;AACpB,gBAAQ,QAAQ;AAAA,MAClB;AAAA,IAAA,CACD;AAAA,EAAA;AAGH,UAAQ,GAAG;AAEJ,SAAA;AACT;AAEgB,SAAA,KACd,SACA,IACA,MAKiC;AACjC,MAAI,OAAc,CAAA;AACd,MAAA;AAEJ,SAAO,CAAW,YAAA;;AACZ,QAAA;
|
|
1
|
+
{"version":3,"file":"utils.cjs","sources":["../../src/utils.ts"],"sourcesContent":["import { TableOptionsResolved, TableState, Updater } from './types'\n\nexport type PartialKeys<T, K extends keyof T> = Omit<T, K> & Partial<Pick<T, K>>\nexport type RequiredKeys<T, K extends keyof T> = Omit<T, K> &\n Required<Pick<T, K>>\nexport type Overwrite<T, U extends { [TKey in keyof T]?: any }> = Omit<\n T,\n keyof U\n> &\n U\n\nexport type UnionToIntersection<T> = (\n T extends any ? (x: T) => any : never\n) extends (x: infer R) => any\n ? R\n : never\n\nexport type IsAny<T, Y, N> = 1 extends 0 & T ? Y : N\nexport type IsKnown<T, Y, N> = unknown extends T ? N : Y\n\ntype ComputeRange<\n N extends number,\n Result extends Array<unknown> = [],\n> = Result['length'] extends N\n ? Result\n : ComputeRange<N, [...Result, Result['length']]>\ntype Index40 = ComputeRange<40>[number]\n\n// Is this type a tuple?\ntype IsTuple<T> = T extends readonly any[] & { length: infer Length }\n ? Length extends Index40\n ? T\n : never\n : never\n\n// If this type is a tuple, what indices are allowed?\ntype AllowedIndexes<\n Tuple extends ReadonlyArray<any>,\n Keys extends number = never,\n> = Tuple extends readonly []\n ? Keys\n : Tuple extends readonly [infer _, ...infer Tail]\n ? AllowedIndexes<Tail, Keys | Tail['length']>\n : Keys\n\nexport type DeepKeys<T, TDepth extends any[] = []> = TDepth['length'] extends 5\n ? never\n : unknown extends T\n ? string\n : T extends readonly any[] & IsTuple<T>\n ? AllowedIndexes<T> | DeepKeysPrefix<T, AllowedIndexes<T>, TDepth>\n : T extends any[]\n ? DeepKeys<T[number], [...TDepth, any]>\n : T extends Date\n ? never\n : T extends object\n ? (keyof T & string) | DeepKeysPrefix<T, keyof T, TDepth>\n : never\n\ntype DeepKeysPrefix<\n T,\n TPrefix,\n TDepth extends any[],\n> = TPrefix extends keyof T & (number | string)\n ? `${TPrefix}.${DeepKeys<T[TPrefix], [...TDepth, any]> & string}`\n : never\n\nexport type DeepValue<T, TProp> = T extends Record<string | number, any>\n ? TProp extends `${infer TBranch}.${infer TDeepProp}`\n ? DeepValue<T[TBranch], TDeepProp>\n : T[TProp & string]\n : never\n\nexport type NoInfer<T> = [T][T extends any ? 0 : never]\n\nexport type Getter<TValue> = <TTValue = TValue>() => NoInfer<TTValue>\n\n///\n\nexport function functionalUpdate<T>(updater: Updater<T>, input: T): T {\n return typeof updater === 'function'\n ? (updater as (input: T) => T)(input)\n : updater\n}\n\nexport function noop() {\n //\n}\n\nexport function makeStateUpdater<K extends keyof TableState>(\n key: K,\n instance: unknown\n) {\n return (updater: Updater<TableState[K]>) => {\n ;(instance as any).setState(<TTableState>(old: TTableState) => {\n return {\n ...old,\n [key]: functionalUpdate(updater, (old as any)[key]),\n }\n })\n }\n}\n\ntype AnyFunction = (...args: any) => any\n\nexport function isFunction<T extends AnyFunction>(d: any): d is T {\n return d instanceof Function\n}\n\nexport function isNumberArray(d: any): d is number[] {\n return Array.isArray(d) && d.every(val => typeof val === 'number')\n}\n\nexport function flattenBy<TNode>(\n arr: TNode[],\n getChildren: (item: TNode) => TNode[]\n) {\n const flat: TNode[] = []\n\n const recurse = (subArr: TNode[]) => {\n subArr.forEach(item => {\n flat.push(item)\n const children = getChildren(item)\n if (children?.length) {\n recurse(children)\n }\n })\n }\n\n recurse(arr)\n\n return flat\n}\n\nexport function memo<TDeps extends readonly any[], TDepArgs, TResult>(\n getDeps: (depArgs?: TDepArgs) => [...TDeps],\n fn: (...args: NoInfer<[...TDeps]>) => TResult,\n opts: {\n key: any\n debug?: () => any\n onChange?: (result: TResult) => void\n }\n): (depArgs?: TDepArgs) => TResult {\n let deps: any[] = []\n let result: TResult | undefined\n\n return depArgs => {\n let depTime: number\n if (opts.key && opts.debug) depTime = Date.now()\n\n const newDeps = getDeps(depArgs)\n\n const depsChanged =\n newDeps.length !== deps.length ||\n newDeps.some((dep: any, index: number) => deps[index] !== dep)\n\n if (!depsChanged) {\n return result!\n }\n\n deps = newDeps\n\n let resultTime: number\n if (opts.key && opts.debug) resultTime = Date.now()\n\n result = fn(...newDeps)\n opts?.onChange?.(result)\n\n if (opts.key && opts.debug) {\n if (opts?.debug()) {\n const depEndTime = Math.round((Date.now() - depTime!) * 100) / 100\n const resultEndTime = Math.round((Date.now() - resultTime!) * 100) / 100\n const resultFpsPercentage = resultEndTime / 16\n\n const pad = (str: number | string, num: number) => {\n str = String(str)\n while (str.length < num) {\n str = ' ' + str\n }\n return str\n }\n\n console.info(\n `%c⏱ ${pad(resultEndTime, 5)} /${pad(depEndTime, 5)} ms`,\n `\n font-size: .6rem;\n font-weight: bold;\n color: hsl(${Math.max(\n 0,\n Math.min(120 - 120 * resultFpsPercentage, 120)\n )}deg 100% 31%);`,\n opts?.key\n )\n }\n }\n\n return result!\n }\n}\n\nexport function getMemoOptions(\n tableOptions: Partial<TableOptionsResolved<any>>,\n debugLevel:\n | 'debugAll'\n | 'debugCells'\n | 'debugTable'\n | 'debugColumns'\n | 'debugRows'\n | 'debugHeaders',\n key: string,\n onChange?: (result: any) => void\n) {\n return {\n debug: () => tableOptions?.debugAll ?? tableOptions[debugLevel],\n key: process.env.NODE_ENV === 'development' && key,\n onChange,\n }\n}\n"],"names":[],"mappings":";;AA+EgB,SAAA,iBAAoB,SAAqB,OAAa;AACpE,SAAO,OAAO,YAAY,aACrB,QAA4B,KAAK,IAClC;AACN;AAEO,SAAS,OAAO;AAEvB;AAEgB,SAAA,iBACd,KACA,UACA;AACA,SAAO,CAAC,YAAoC;AACxC,aAAiB,SAAS,CAAc,QAAqB;AACtD,aAAA;AAAA,QACL,GAAG;AAAA,QACH,CAAC,GAAG,GAAG,iBAAiB,SAAU,IA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sB,QAAgB;AACjD,gBAAM,OAAO,GAAG;AACT,iBAAA,IAAI,SAAS,KAAK;AACvB,kBAAM,MAAM;AAAA,UACd;AACO,iBAAA;AAAA,QAAA;AAGD,gBAAA;AAAA,UACN,OAAO,IAAI,eAAe,CAAC,CAAC,KAAK,IAAI,YAAY,CAAC,CAAC;AAAA,UACnD;AAAA;AAAA;AAAA,yBAGe,KAAK;AAAA,YAChB;AAAA,YACA,KAAK,IAAI,MAAM,MAAM,qBAAqB,GAAG;AAAA,UAC9C,CAAA;AAAA,UACH,6BAAM;AAAA,QAAA;AAAA,MAEV;AAAA,IACF;AAEO,WAAA;AAAA,EAAA;AAEX;AAEO,SAAS,eACd,cACA,YAOA,KACA,UACA;AACO,SAAA;AAAA,IACL,OAAO,OAAM,6CAAc,aAAY,aAAa,UAAU;AAAA,IAC9D,KAAK,QAAQ,IAAI,aAAa,iBAAiB;AAAA,IAC/C;AAAA,EAAA;AAEJ;;;;;;;;;"}
|
|
@@ -32,13 +32,10 @@ const extent = (columnId, _leafRows, childRows) => {
|
|
|
32
32
|
const value = row.getValue(columnId);
|
|
33
33
|
if (value != null) {
|
|
34
34
|
if (min2 === void 0) {
|
|
35
|
-
if (value >= value)
|
|
36
|
-
min2 = max2 = value;
|
|
35
|
+
if (value >= value) min2 = max2 = value;
|
|
37
36
|
} else {
|
|
38
|
-
if (min2 > value)
|
|
39
|
-
|
|
40
|
-
if (max2 < value)
|
|
41
|
-
max2 = value;
|
|
37
|
+
if (min2 > value) min2 = value;
|
|
38
|
+
if (max2 < value) max2 = value;
|
|
42
39
|
}
|
|
43
40
|
}
|
|
44
41
|
});
|
|
@@ -53,8 +50,7 @@ const mean = (columnId, leafRows) => {
|
|
|
53
50
|
++count2, sum2 += value;
|
|
54
51
|
}
|
|
55
52
|
});
|
|
56
|
-
if (count2)
|
|
57
|
-
return sum2 / count2;
|
|
53
|
+
if (count2) return sum2 / count2;
|
|
58
54
|
return;
|
|
59
55
|
};
|
|
60
56
|
const median = (columnId, leafRows) => {
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"aggregationFns.js","sources":["../../src/aggregationFns.ts"],"sourcesContent":["import { AggregationFn } from './features/ColumnGrouping'\nimport { isNumberArray } from './utils'\n\nconst sum: AggregationFn<any> = (columnId, _leafRows, childRows) => {\n // It's faster to just add the aggregations together instead of\n // process leaf nodes individually\n return childRows.reduce((sum, next) => {\n const nextValue = next.getValue(columnId)\n return sum + (typeof nextValue === 'number' ? nextValue : 0)\n }, 0)\n}\n\nconst min: AggregationFn<any> = (columnId, _leafRows, childRows) => {\n let min: number | undefined\n\n childRows.forEach(row => {\n const value = row.getValue<number>(columnId)\n\n if (\n value != null &&\n (min! > value || (min === undefined && value >= value))\n ) {\n min = value\n }\n })\n\n return min\n}\n\nconst max: AggregationFn<any> = (columnId, _leafRows, childRows) => {\n let max: number | undefined\n\n childRows.forEach(row => {\n const value = row.getValue<number>(columnId)\n if (\n value != null &&\n (max! < value || (max === undefined && value >= value))\n ) {\n max = value\n }\n })\n\n return max\n}\n\nconst extent: AggregationFn<any> = (columnId, _leafRows, childRows) => {\n let min: number | undefined\n let max: number | undefined\n\n childRows.forEach(row => {\n const value = row.getValue<number>(columnId)\n if (value != null) {\n if (min === undefined) {\n if (value >= value) min = max = value\n } else {\n if (min > value) min = value\n if (max! < value) max = value\n }\n }\n })\n\n return [min, max]\n}\n\nconst mean: AggregationFn<any> = (columnId, leafRows) => {\n let count = 0\n let sum = 0\n\n leafRows.forEach(row => {\n let value = row.getValue<number>(columnId)\n if (value != null && (value = +value) >= value) {\n ++count, (sum += value)\n }\n })\n\n if (count) return sum / count\n\n return\n}\n\nconst median: AggregationFn<any> = (columnId, leafRows) => {\n if (!leafRows.length) {\n return\n }\n\n const values = leafRows.map(row => row.getValue(columnId))\n if (!isNumberArray(values)) {\n return\n }\n if (values.length === 1) {\n return values[0]\n }\n\n const mid = Math.floor(values.length / 2)\n const nums = values.sort((a, b) => a - b)\n return values.length % 2 !== 0 ? nums[mid] : (nums[mid - 1]! + nums[mid]!) / 2\n}\n\nconst unique: AggregationFn<any> = (columnId, leafRows) => {\n return Array.from(new Set(leafRows.map(d => d.getValue(columnId))).values())\n}\n\nconst uniqueCount: AggregationFn<any> = (columnId, leafRows) => {\n return new Set(leafRows.map(d => d.getValue(columnId))).size\n}\n\nconst count: AggregationFn<any> = (_columnId, leafRows) => {\n return leafRows.length\n}\n\nexport const aggregationFns = {\n sum,\n min,\n max,\n extent,\n mean,\n median,\n unique,\n uniqueCount,\n count,\n}\n\nexport type BuiltInAggregationFn = keyof typeof aggregationFns\n"],"names":["sum","min","max","count"],"mappings":";AAGA,MAAM,MAA0B,CAAC,UAAU,WAAW,cAAc;AAGlE,SAAO,UAAU,OAAO,CAACA,MAAK,SAAS;AAC/B,UAAA,YAAY,KAAK,SAAS,QAAQ;AACxC,WAAOA,QAAO,OAAO,cAAc,WAAW,YAAY;AAAA,KACzD,CAAC;AACN;AAEA,MAAM,MAA0B,CAAC,UAAU,WAAW,cAAc;AAC9DC,MAAAA;AAEJ,YAAU,QAAQ,CAAO,QAAA;AACjB,UAAA,QAAQ,IAAI,SAAiB,QAAQ;AAE3C,QACE,SAAS,SACRA,OAAO,SAAUA,SAAQ,UAAa,SAAS,QAChD;AACAA,aAAM;AAAA,IACR;AAAA,EAAA,CACD;AAEMA,SAAAA;AACT;AAEA,MAAM,MAA0B,CAAC,UAAU,WAAW,cAAc;AAC9DC,MAAAA;AAEJ,YAAU,QAAQ,CAAO,QAAA;AACjB,UAAA,QAAQ,IAAI,SAAiB,QAAQ;AAC3C,QACE,SAAS,SACRA,OAAO,SAAUA,SAAQ,UAAa,SAAS,QAChD;AACAA,aAAM;AAAA,IACR;AAAA,EAAA,CACD;AAEMA,SAAAA;AACT;AAEA,MAAM,SAA6B,CAAC,UAAU,WAAW,cAAc;AACjED,MAAAA;AACAC,MAAAA;AAEJ,YAAU,QAAQ,CAAO,QAAA;AACjB,UAAA,QAAQ,IAAI,SAAiB,QAAQ;AAC3C,QAAI,SAAS,MAAM;AACjB,UAAID,SAAQ,QAAW;AACrB,YAAI,SAAS
|
|
1
|
+
{"version":3,"file":"aggregationFns.js","sources":["../../src/aggregationFns.ts"],"sourcesContent":["import { AggregationFn } from './features/ColumnGrouping'\nimport { isNumberArray } from './utils'\n\nconst sum: AggregationFn<any> = (columnId, _leafRows, childRows) => {\n // It's faster to just add the aggregations together instead of\n // process leaf nodes individually\n return childRows.reduce((sum, next) => {\n const nextValue = next.getValue(columnId)\n return sum + (typeof nextValue === 'number' ? nextValue : 0)\n }, 0)\n}\n\nconst min: AggregationFn<any> = (columnId, _leafRows, childRows) => {\n let min: number | undefined\n\n childRows.forEach(row => {\n const value = row.getValue<number>(columnId)\n\n if (\n value != null &&\n (min! > value || (min === undefined && value >= value))\n ) {\n min = value\n }\n })\n\n return min\n}\n\nconst max: AggregationFn<any> = (columnId, _leafRows, childRows) => {\n let max: number | undefined\n\n childRows.forEach(row => {\n const value = row.getValue<number>(columnId)\n if (\n value != null &&\n (max! < value || (max === undefined && value >= value))\n ) {\n max = value\n }\n })\n\n return max\n}\n\nconst extent: AggregationFn<any> = (columnId, _leafRows, childRows) => {\n let min: number | undefined\n let max: number | undefined\n\n childRows.forEach(row => {\n const value = row.getValue<number>(columnId)\n if (value != null) {\n if (min === undefined) {\n if (value >= value) min = max = value\n } else {\n if (min > value) min = value\n if (max! < value) max = value\n }\n }\n })\n\n return [min, max]\n}\n\nconst mean: AggregationFn<any> = (columnId, leafRows) => {\n let count = 0\n let sum = 0\n\n leafRows.forEach(row => {\n let value = row.getValue<number>(columnId)\n if (value != null && (value = +value) >= value) {\n ++count, (sum += value)\n }\n })\n\n if (count) return sum / count\n\n return\n}\n\nconst median: AggregationFn<any> = (columnId, leafRows) => {\n if (!leafRows.length) {\n return\n }\n\n const values = leafRows.map(row => row.getValue(columnId))\n if (!isNumberArray(values)) {\n return\n }\n if (values.length === 1) {\n return values[0]\n }\n\n const mid = Math.floor(values.length / 2)\n const nums = values.sort((a, b) => a - b)\n return values.length % 2 !== 0 ? nums[mid] : (nums[mid - 1]! + nums[mid]!) / 2\n}\n\nconst unique: AggregationFn<any> = (columnId, leafRows) => {\n return Array.from(new Set(leafRows.map(d => d.getValue(columnId))).values())\n}\n\nconst uniqueCount: AggregationFn<any> = (columnId, leafRows) => {\n return new Set(leafRows.map(d => d.getValue(columnId))).size\n}\n\nconst count: AggregationFn<any> = (_columnId, leafRows) => {\n return leafRows.length\n}\n\nexport const aggregationFns = {\n sum,\n min,\n max,\n extent,\n mean,\n median,\n unique,\n uniqueCount,\n count,\n}\n\nexport type BuiltInAggregationFn = keyof typeof aggregationFns\n"],"names":["sum","min","max","count"],"mappings":";AAGA,MAAM,MAA0B,CAAC,UAAU,WAAW,cAAc;AAGlE,SAAO,UAAU,OAAO,CAACA,MAAK,SAAS;AAC/B,UAAA,YAAY,KAAK,SAAS,QAAQ;AACxC,WAAOA,QAAO,OAAO,cAAc,WAAW,YAAY;AAAA,KACzD,CAAC;AACN;AAEA,MAAM,MAA0B,CAAC,UAAU,WAAW,cAAc;AAC9DC,MAAAA;AAEJ,YAAU,QAAQ,CAAO,QAAA;AACjB,UAAA,QAAQ,IAAI,SAAiB,QAAQ;AAE3C,QACE,SAAS,SACRA,OAAO,SAAUA,SAAQ,UAAa,SAAS,QAChD;AACAA,aAAM;AAAA,IACR;AAAA,EAAA,CACD;AAEMA,SAAAA;AACT;AAEA,MAAM,MAA0B,CAAC,UAAU,WAAW,cAAc;AAC9DC,MAAAA;AAEJ,YAAU,QAAQ,CAAO,QAAA;AACjB,UAAA,QAAQ,IAAI,SAAiB,QAAQ;AAC3C,QACE,SAAS,SACRA,OAAO,SAAUA,SAAQ,UAAa,SAAS,QAChD;AACAA,aAAM;AAAA,IACR;AAAA,EAAA,CACD;AAEMA,SAAAA;AACT;AAEA,MAAM,SAA6B,CAAC,UAAU,WAAW,cAAc;AACjED,MAAAA;AACAC,MAAAA;AAEJ,YAAU,QAAQ,CAAO,QAAA;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AAkC,CAAC,UAAU,aAAa;AACvD,SAAA,IAAI,IAAI,SAAS,IAAI,CAAA,MAAK,EAAE,SAAS,QAAQ,CAAC,CAAC,EAAE;AAC1D;AAEA,MAAM,QAA4B,CAAC,WAAW,aAAa;AACzD,SAAO,SAAS;AAClB;AAEO,MAAM,iBAAiB;AAAA,EAC5B;AAAA,EACA;AAAA,EACA;AAAA,EACA;AAAA,EACA;AAAA,EACA;AAAA,EACA;AAAA,EACA;AAAA,EACA;AACF;"}
|
package/dist/esm/core/cell.d.ts
CHANGED
|
@@ -47,4 +47,4 @@ export interface CoreCell<TData extends RowData, TValue> {
|
|
|
47
47
|
*/
|
|
48
48
|
row: Row<TData>;
|
|
49
49
|
}
|
|
50
|
-
export declare function
|
|
50
|
+
export declare function _createCell<TData extends RowData, TValue>(table: Table<TData>, row: Row<TData>, column: Column<TData, TValue>, columnId: string): Cell<TData, TValue>;
|
package/dist/esm/core/cell.js
CHANGED
|
@@ -1,5 +1,5 @@
|
|
|
1
1
|
import { memo, getMemoOptions } from "../utils.js";
|
|
2
|
-
function
|
|
2
|
+
function _createCell(table, row, column, columnId) {
|
|
3
3
|
const getRenderValue = () => cell.getValue() ?? table.options.renderFallbackValue;
|
|
4
4
|
const cell = {
|
|
5
5
|
id: `${row.id}_${column.id}`,
|
|
@@ -22,7 +22,7 @@ function createCell(table, row, column, columnId) {
|
|
|
22
22
|
};
|
|
23
23
|
table._features.forEach((feature) => {
|
|
24
24
|
var _a;
|
|
25
|
-
(_a = feature.
|
|
25
|
+
(_a = feature._createCell) == null ? void 0 : _a.call(
|
|
26
26
|
feature,
|
|
27
27
|
cell,
|
|
28
28
|
column,
|
|
@@ -33,6 +33,6 @@ function createCell(table, row, column, columnId) {
|
|
|
33
33
|
return cell;
|
|
34
34
|
}
|
|
35
35
|
export {
|
|
36
|
-
|
|
36
|
+
_createCell
|
|
37
37
|
};
|
|
38
38
|
//# sourceMappingURL=cell.js.map
|