package.build.lib.features.Ordering.js.map Maven / Gradle / Ivy
Go to download
Show more of this group Show more artifacts with this name
Show all versions of table-core Show documentation
Show all versions of table-core Show documentation
Headless UI for building powerful tables & datagrids for TS/JS.
The newest version!
{"version":3,"file":"Ordering.js","sources":["../../../src/features/Ordering.ts"],"sourcesContent":["import { makeStateUpdater, memo } from '../utils'\n\nimport { Table, OnChangeFn, Updater, Column, RowData } from '../types'\n\nimport { orderColumns } from './Grouping'\nimport { TableFeature } from '../core/table'\n\nexport interface ColumnOrderTableState {\n columnOrder: ColumnOrderState\n}\n\nexport type ColumnOrderState = string[]\n\nexport interface ColumnOrderOptions {\n onColumnOrderChange?: OnChangeFn\n}\n\nexport interface ColumnOrderDefaultOptions {\n onColumnOrderChange: OnChangeFn\n}\n\nexport interface ColumnOrderInstance {\n setColumnOrder: (updater: Updater) => void\n resetColumnOrder: (defaultState?: boolean) => void\n _getOrderColumnsFn: () => (\n columns: Column[]\n ) => Column[]\n}\n\n//\n\nexport const Ordering: TableFeature = {\n getInitialState: (state): ColumnOrderTableState => {\n return {\n columnOrder: [],\n ...state,\n }\n },\n\n getDefaultOptions: (\n table: Table\n ): ColumnOrderDefaultOptions => {\n return {\n onColumnOrderChange: makeStateUpdater('columnOrder', table),\n }\n },\n\n createTable: (\n table: Table\n ): ColumnOrderInstance => {\n return {\n setColumnOrder: updater => table.options.onColumnOrderChange?.(updater),\n resetColumnOrder: defaultState => {\n table.setColumnOrder(\n defaultState ? [] : table.initialState.columnOrder ?? []\n )\n },\n _getOrderColumnsFn: memo(\n () => [\n table.getState().columnOrder,\n table.getState().grouping,\n table.options.groupedColumnMode,\n ],\n (columnOrder, grouping, groupedColumnMode) => columns => {\n // Sort grouped columns to the start of the column list\n // before the headers are built\n let orderedColumns: Column[] = []\n\n // If there is no order, return the normal columns\n if (!columnOrder?.length) {\n orderedColumns = columns\n } else {\n const columnOrderCopy = [...columnOrder]\n\n // If there is an order, make a copy of the columns\n const columnsCopy = [...columns]\n\n // And make a new ordered array of the columns\n\n // Loop over the columns and place them in order into the new array\n while (columnsCopy.length && columnOrderCopy.length) {\n const targetColumnId = columnOrderCopy.shift()\n const foundIndex = columnsCopy.findIndex(\n d => d.id === targetColumnId\n )\n if (foundIndex > -1) {\n orderedColumns.push(columnsCopy.splice(foundIndex, 1)[0]!)\n }\n }\n\n // If there are any columns left, add them to the end\n orderedColumns = [...orderedColumns, ...columnsCopy]\n }\n\n return orderColumns(orderedColumns, grouping, groupedColumnMode)\n },\n {\n key: process.env.NODE_ENV === 'development' && 'getOrderColumnsFn',\n // debug: () => table.options.debugAll ?? table.options.debugTable,\n }\n ),\n }\n },\n}\n"],"names":["Ordering","getInitialState","state","columnOrder","getDefaultOptions","table","onColumnOrderChange","makeStateUpdater","createTable","setColumnOrder","updater","options","resetColumnOrder","defaultState","_table$initialState$c","initialState","_getOrderColumnsFn","memo","getState","grouping","groupedColumnMode","columns","orderedColumns","length","columnOrderCopy","columnsCopy","targetColumnId","shift","foundIndex","findIndex","d","id","push","splice","orderColumns","key","process","env","NODE_ENV"],"mappings":";;;;;;;;;;;;;;;;;AA6BA;;AAEO,MAAMA,QAAsB,GAAG;EACpCC,eAAe,EAAGC,KAAK,IAA4B;IACjD,OAAO;AACLC,MAAAA,WAAW,EAAE,EAAE;MACf,GAAGD,KAAAA;KACJ,CAAA;GACF;EAEDE,iBAAiB,EACfC,KAAmB,IACW;IAC9B,OAAO;AACLC,MAAAA,mBAAmB,EAAEC,sBAAgB,CAAC,aAAa,EAAEF,KAAK,CAAA;KAC3D,CAAA;GACF;EAEDG,WAAW,EACTH,KAAmB,IACY;IAC/B,OAAO;AACLI,MAAAA,cAAc,EAAEC,OAAO,IAAIL,KAAK,CAACM,OAAO,CAACL,mBAAmB,IAAjCD,IAAAA,GAAAA,KAAAA,CAAAA,GAAAA,KAAK,CAACM,OAAO,CAACL,mBAAmB,CAAGI,OAAO,CAAC;MACvEE,gBAAgB,EAAEC,YAAY,IAAI;AAAA,QAAA,IAAAC,qBAA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