@tanstack/table-core 9.0.0-beta.33 → 9.0.0-beta.34

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.
Files changed (32) hide show
  1. package/dist/core/rows/coreRowsFeature.cjs +4 -1
  2. package/dist/core/rows/coreRowsFeature.cjs.map +1 -1
  3. package/dist/core/rows/coreRowsFeature.js +4 -1
  4. package/dist/core/rows/coreRowsFeature.js.map +1 -1
  5. package/dist/features/row-selection/rowSelectionFeature.utils.cjs +1 -1
  6. package/dist/features/row-selection/rowSelectionFeature.utils.cjs.map +1 -1
  7. package/dist/features/row-selection/rowSelectionFeature.utils.js +2 -2
  8. package/dist/features/row-selection/rowSelectionFeature.utils.js.map +1 -1
  9. package/dist/features/row-sorting/createSortedRowModel.cjs +17 -7
  10. package/dist/features/row-sorting/createSortedRowModel.cjs.map +1 -1
  11. package/dist/features/row-sorting/createSortedRowModel.js +18 -8
  12. package/dist/features/row-sorting/createSortedRowModel.js.map +1 -1
  13. package/dist/features/row-sorting/rowSortingFeature.utils.cjs +1 -1
  14. package/dist/features/row-sorting/rowSortingFeature.utils.cjs.map +1 -1
  15. package/dist/features/row-sorting/rowSortingFeature.utils.js +1 -1
  16. package/dist/features/row-sorting/rowSortingFeature.utils.js.map +1 -1
  17. package/dist/index.cjs +1 -0
  18. package/dist/index.d.cts +2 -2
  19. package/dist/index.d.ts +2 -2
  20. package/dist/index.js +2 -2
  21. package/dist/utils.cjs +14 -0
  22. package/dist/utils.cjs.map +1 -1
  23. package/dist/utils.d.cts +6 -1
  24. package/dist/utils.d.ts +6 -1
  25. package/dist/utils.js +14 -1
  26. package/dist/utils.js.map +1 -1
  27. package/package.json +1 -1
  28. package/src/core/rows/coreRowsFeature.ts +1 -0
  29. package/src/features/row-selection/rowSelectionFeature.utils.ts +2 -1
  30. package/src/features/row-sorting/createSortedRowModel.ts +31 -10
  31. package/src/features/row-sorting/rowSortingFeature.utils.ts +2 -10
  32. package/src/utils.ts +21 -0
@@ -16,7 +16,10 @@ const coreRowsFeature = {
16
16
  fn: (row) => require_coreRowsFeature_utils.row_getAllCells(row),
17
17
  memoDeps: (row) => [row.table.getAllLeafColumns()]
18
18
  },
19
- row_getLeafRows: { fn: (row) => require_coreRowsFeature_utils.row_getLeafRows(row) },
19
+ row_getLeafRows: {
20
+ fn: (row) => require_coreRowsFeature_utils.row_getLeafRows(row),
21
+ memoDeps: (row) => [row.subRows]
22
+ },
20
23
  row_getParentRow: { fn: (row) => require_coreRowsFeature_utils.row_getParentRow(row) },
21
24
  row_getParentRows: { fn: (row) => require_coreRowsFeature_utils.row_getParentRows(row) },
22
25
  row_getUniqueValues: { fn: (row, columnId) => require_coreRowsFeature_utils.row_getUniqueValues(row, columnId) },
@@ -1 +1 @@
1
- {"version":3,"file":"coreRowsFeature.cjs","names":["row_getAllCellsByColumnId","row_getAllCells","row_getLeafRows","row_getParentRow","row_getParentRows","row_getUniqueValues","row_getValue","row_renderValue","table_getRowId","table_getRow"],"sources":["../../../src/core/rows/coreRowsFeature.ts"],"sourcesContent":["import { assignPrototypeAPIs, assignTableAPIs } from '../../utils'\nimport {\n row_getAllCells,\n row_getAllCellsByColumnId,\n row_getLeafRows,\n row_getParentRow,\n row_getParentRows,\n row_getUniqueValues,\n row_getValue,\n row_renderValue,\n table_getRow,\n table_getRowId,\n} from './coreRowsFeature.utils'\nimport type { TableFeature } from '../../types/TableFeatures'\n\n/**\n * Core feature that creates row APIs for values, cells, and tree traversal.\n */\nexport const coreRowsFeature: TableFeature = {\n assignRowPrototype: (prototype, table) => {\n assignPrototypeAPIs('coreRowsFeature', prototype, table, {\n row_getAllCellsByColumnId: {\n fn: (row) => row_getAllCellsByColumnId(row),\n memoDeps: (row) => [row.getAllCells()],\n },\n row_getAllCells: {\n fn: (row) => row_getAllCells(row),\n memoDeps: (row) => [row.table.getAllLeafColumns()],\n },\n row_getLeafRows: {\n fn: (row) => row_getLeafRows(row),\n },\n row_getParentRow: {\n fn: (row) => row_getParentRow(row),\n },\n row_getParentRows: {\n fn: (row) => row_getParentRows(row),\n },\n row_getUniqueValues: {\n fn: (row, columnId) => row_getUniqueValues(row, columnId),\n },\n row_getValue: {\n fn: (row, columnId) => row_getValue(row, columnId),\n },\n row_renderValue: {\n fn: (row, columnId) => row_renderValue(row, columnId),\n },\n })\n },\n constructTableAPIs: (table) => {\n assignTableAPIs('coreRowsFeature', table, {\n table_getRowId: {\n fn: (originalRow, index, parent) =>\n table_getRowId(originalRow, table, index, parent),\n },\n table_getRow: {\n fn: (id: string, searchAll?: boolean) =>\n table_getRow(table, id, searchAll),\n },\n })\n },\n}\n"],"mappings":";;;;;;;AAkBA,MAAa,kBAAgC;CAC3C,qBAAqB,WAAW,UAAU;EACxC,kCAAoB,mBAAmB,WAAW,OAAO;GACvD,2BAA2B;IACzB,KAAK,QAAQA,wDAA0B,GAAG;IAC1C,WAAW,QAAQ,CAAC,IAAI,YAAY,CAAC;GACvC;GACA,iBAAiB;IACf,KAAK,QAAQC,8CAAgB,GAAG;IAChC,WAAW,QAAQ,CAAC,IAAI,MAAM,kBAAkB,CAAC;GACnD;GACA,iBAAiB,EACf,KAAK,QAAQC,8CAAgB,GAAG,EAClC;GACA,kBAAkB,EAChB,KAAK,QAAQC,+CAAiB,GAAG,EACnC;GACA,mBAAmB,EACjB,KAAK,QAAQC,gDAAkB,GAAG,EACpC;GACA,qBAAqB,EACnB,KAAK,KAAK,aAAaC,kDAAoB,KAAK,QAAQ,EAC1D;GACA,cAAc,EACZ,KAAK,KAAK,aAAaC,2CAAa,KAAK,QAAQ,EACnD;GACA,iBAAiB,EACf,KAAK,KAAK,aAAaC,8CAAgB,KAAK,QAAQ,EACtD;EACF,CAAC;CACH;CACA,qBAAqB,UAAU;EAC7B,8BAAgB,mBAAmB,OAAO;GACxC,gBAAgB,EACd,KAAK,aAAa,OAAO,WACvBC,6CAAe,aAAa,OAAO,OAAO,MAAM,EACpD;GACA,cAAc,EACZ,KAAK,IAAY,cACfC,2CAAa,OAAO,IAAI,SAAS,EACrC;EACF,CAAC;CACH;AACF"}
1
+ {"version":3,"file":"coreRowsFeature.cjs","names":["row_getAllCellsByColumnId","row_getAllCells","row_getLeafRows","row_getParentRow","row_getParentRows","row_getUniqueValues","row_getValue","row_renderValue","table_getRowId","table_getRow"],"sources":["../../../src/core/rows/coreRowsFeature.ts"],"sourcesContent":["import { assignPrototypeAPIs, assignTableAPIs } from '../../utils'\nimport {\n row_getAllCells,\n row_getAllCellsByColumnId,\n row_getLeafRows,\n row_getParentRow,\n row_getParentRows,\n row_getUniqueValues,\n row_getValue,\n row_renderValue,\n table_getRow,\n table_getRowId,\n} from './coreRowsFeature.utils'\nimport type { TableFeature } from '../../types/TableFeatures'\n\n/**\n * Core feature that creates row APIs for values, cells, and tree traversal.\n */\nexport const coreRowsFeature: TableFeature = {\n assignRowPrototype: (prototype, table) => {\n assignPrototypeAPIs('coreRowsFeature', prototype, table, {\n row_getAllCellsByColumnId: {\n fn: (row) => row_getAllCellsByColumnId(row),\n memoDeps: (row) => [row.getAllCells()],\n },\n row_getAllCells: {\n fn: (row) => row_getAllCells(row),\n memoDeps: (row) => [row.table.getAllLeafColumns()],\n },\n row_getLeafRows: {\n fn: (row) => row_getLeafRows(row),\n memoDeps: (row) => [row.subRows],\n },\n row_getParentRow: {\n fn: (row) => row_getParentRow(row),\n },\n row_getParentRows: {\n fn: (row) => row_getParentRows(row),\n },\n row_getUniqueValues: {\n fn: (row, columnId) => row_getUniqueValues(row, columnId),\n },\n row_getValue: {\n fn: (row, columnId) => row_getValue(row, columnId),\n },\n row_renderValue: {\n fn: (row, columnId) => row_renderValue(row, columnId),\n },\n })\n },\n constructTableAPIs: (table) => {\n assignTableAPIs('coreRowsFeature', table, {\n table_getRowId: {\n fn: (originalRow, index, parent) =>\n table_getRowId(originalRow, table, index, parent),\n },\n table_getRow: {\n fn: (id: string, searchAll?: boolean) =>\n table_getRow(table, id, searchAll),\n },\n })\n },\n}\n"],"mappings":";;;;;;;AAkBA,MAAa,kBAAgC;CAC3C,qBAAqB,WAAW,UAAU;EACxC,kCAAoB,mBAAmB,WAAW,OAAO;GACvD,2BAA2B;IACzB,KAAK,QAAQA,wDAA0B,GAAG;IAC1C,WAAW,QAAQ,CAAC,IAAI,YAAY,CAAC;GACvC;GACA,iBAAiB;IACf,KAAK,QAAQC,8CAAgB,GAAG;IAChC,WAAW,QAAQ,CAAC,IAAI,MAAM,kBAAkB,CAAC;GACnD;GACA,iBAAiB;IACf,KAAK,QAAQC,8CAAgB,GAAG;IAChC,WAAW,QAAQ,CAAC,IAAI,OAAO;GACjC;GACA,kBAAkB,EAChB,KAAK,QAAQC,+CAAiB,GAAG,EACnC;GACA,mBAAmB,EACjB,KAAK,QAAQC,gDAAkB,GAAG,EACpC;GACA,qBAAqB,EACnB,KAAK,KAAK,aAAaC,kDAAoB,KAAK,QAAQ,EAC1D;GACA,cAAc,EACZ,KAAK,KAAK,aAAaC,2CAAa,KAAK,QAAQ,EACnD;GACA,iBAAiB,EACf,KAAK,KAAK,aAAaC,8CAAgB,KAAK,QAAQ,EACtD;EACF,CAAC;CACH;CACA,qBAAqB,UAAU;EAC7B,8BAAgB,mBAAmB,OAAO;GACxC,gBAAgB,EACd,KAAK,aAAa,OAAO,WACvBC,6CAAe,aAAa,OAAO,OAAO,MAAM,EACpD;GACA,cAAc,EACZ,KAAK,IAAY,cACfC,2CAAa,OAAO,IAAI,SAAS,EACrC;EACF,CAAC;CACH;AACF"}
@@ -16,7 +16,10 @@ const coreRowsFeature = {
16
16
  fn: (row) => row_getAllCells(row),
17
17
  memoDeps: (row) => [row.table.getAllLeafColumns()]
18
18
  },
19
- row_getLeafRows: { fn: (row) => row_getLeafRows(row) },
19
+ row_getLeafRows: {
20
+ fn: (row) => row_getLeafRows(row),
21
+ memoDeps: (row) => [row.subRows]
22
+ },
20
23
  row_getParentRow: { fn: (row) => row_getParentRow(row) },
21
24
  row_getParentRows: { fn: (row) => row_getParentRows(row) },
22
25
  row_getUniqueValues: { fn: (row, columnId) => row_getUniqueValues(row, columnId) },
@@ -1 +1 @@
1
- {"version":3,"file":"coreRowsFeature.js","names":[],"sources":["../../../src/core/rows/coreRowsFeature.ts"],"sourcesContent":["import { assignPrototypeAPIs, assignTableAPIs } from '../../utils'\nimport {\n row_getAllCells,\n row_getAllCellsByColumnId,\n row_getLeafRows,\n row_getParentRow,\n row_getParentRows,\n row_getUniqueValues,\n row_getValue,\n row_renderValue,\n table_getRow,\n table_getRowId,\n} from './coreRowsFeature.utils'\nimport type { TableFeature } from '../../types/TableFeatures'\n\n/**\n * Core feature that creates row APIs for values, cells, and tree traversal.\n */\nexport const coreRowsFeature: TableFeature = {\n assignRowPrototype: (prototype, table) => {\n assignPrototypeAPIs('coreRowsFeature', prototype, table, {\n row_getAllCellsByColumnId: {\n fn: (row) => row_getAllCellsByColumnId(row),\n memoDeps: (row) => [row.getAllCells()],\n },\n row_getAllCells: {\n fn: (row) => row_getAllCells(row),\n memoDeps: (row) => [row.table.getAllLeafColumns()],\n },\n row_getLeafRows: {\n fn: (row) => row_getLeafRows(row),\n },\n row_getParentRow: {\n fn: (row) => row_getParentRow(row),\n },\n row_getParentRows: {\n fn: (row) => row_getParentRows(row),\n },\n row_getUniqueValues: {\n fn: (row, columnId) => row_getUniqueValues(row, columnId),\n },\n row_getValue: {\n fn: (row, columnId) => row_getValue(row, columnId),\n },\n row_renderValue: {\n fn: (row, columnId) => row_renderValue(row, columnId),\n },\n })\n },\n constructTableAPIs: (table) => {\n assignTableAPIs('coreRowsFeature', table, {\n table_getRowId: {\n fn: (originalRow, index, parent) =>\n table_getRowId(originalRow, table, index, parent),\n },\n table_getRow: {\n fn: (id: string, searchAll?: boolean) =>\n table_getRow(table, id, searchAll),\n },\n })\n },\n}\n"],"mappings":";;;;;;;AAkBA,MAAa,kBAAgC;CAC3C,qBAAqB,WAAW,UAAU;EACxC,oBAAoB,mBAAmB,WAAW,OAAO;GACvD,2BAA2B;IACzB,KAAK,QAAQ,0BAA0B,GAAG;IAC1C,WAAW,QAAQ,CAAC,IAAI,YAAY,CAAC;GACvC;GACA,iBAAiB;IACf,KAAK,QAAQ,gBAAgB,GAAG;IAChC,WAAW,QAAQ,CAAC,IAAI,MAAM,kBAAkB,CAAC;GACnD;GACA,iBAAiB,EACf,KAAK,QAAQ,gBAAgB,GAAG,EAClC;GACA,kBAAkB,EAChB,KAAK,QAAQ,iBAAiB,GAAG,EACnC;GACA,mBAAmB,EACjB,KAAK,QAAQ,kBAAkB,GAAG,EACpC;GACA,qBAAqB,EACnB,KAAK,KAAK,aAAa,oBAAoB,KAAK,QAAQ,EAC1D;GACA,cAAc,EACZ,KAAK,KAAK,aAAa,aAAa,KAAK,QAAQ,EACnD;GACA,iBAAiB,EACf,KAAK,KAAK,aAAa,gBAAgB,KAAK,QAAQ,EACtD;EACF,CAAC;CACH;CACA,qBAAqB,UAAU;EAC7B,gBAAgB,mBAAmB,OAAO;GACxC,gBAAgB,EACd,KAAK,aAAa,OAAO,WACvB,eAAe,aAAa,OAAO,OAAO,MAAM,EACpD;GACA,cAAc,EACZ,KAAK,IAAY,cACf,aAAa,OAAO,IAAI,SAAS,EACrC;EACF,CAAC;CACH;AACF"}
1
+ {"version":3,"file":"coreRowsFeature.js","names":[],"sources":["../../../src/core/rows/coreRowsFeature.ts"],"sourcesContent":["import { assignPrototypeAPIs, assignTableAPIs } from '../../utils'\nimport {\n row_getAllCells,\n row_getAllCellsByColumnId,\n row_getLeafRows,\n row_getParentRow,\n row_getParentRows,\n row_getUniqueValues,\n row_getValue,\n row_renderValue,\n table_getRow,\n table_getRowId,\n} from './coreRowsFeature.utils'\nimport type { TableFeature } from '../../types/TableFeatures'\n\n/**\n * Core feature that creates row APIs for values, cells, and tree traversal.\n */\nexport const coreRowsFeature: TableFeature = {\n assignRowPrototype: (prototype, table) => {\n assignPrototypeAPIs('coreRowsFeature', prototype, table, {\n row_getAllCellsByColumnId: {\n fn: (row) => row_getAllCellsByColumnId(row),\n memoDeps: (row) => [row.getAllCells()],\n },\n row_getAllCells: {\n fn: (row) => row_getAllCells(row),\n memoDeps: (row) => [row.table.getAllLeafColumns()],\n },\n row_getLeafRows: {\n fn: (row) => row_getLeafRows(row),\n memoDeps: (row) => [row.subRows],\n },\n row_getParentRow: {\n fn: (row) => row_getParentRow(row),\n },\n row_getParentRows: {\n fn: (row) => row_getParentRows(row),\n },\n row_getUniqueValues: {\n fn: (row, columnId) => row_getUniqueValues(row, columnId),\n },\n row_getValue: {\n fn: (row, columnId) => row_getValue(row, columnId),\n },\n row_renderValue: {\n fn: (row, columnId) => row_renderValue(row, columnId),\n },\n })\n },\n constructTableAPIs: (table) => {\n assignTableAPIs('coreRowsFeature', table, {\n table_getRowId: {\n fn: (originalRow, index, parent) =>\n table_getRowId(originalRow, table, index, parent),\n },\n table_getRow: {\n fn: (id: string, searchAll?: boolean) =>\n table_getRow(table, id, searchAll),\n },\n })\n },\n}\n"],"mappings":";;;;;;;AAkBA,MAAa,kBAAgC;CAC3C,qBAAqB,WAAW,UAAU;EACxC,oBAAoB,mBAAmB,WAAW,OAAO;GACvD,2BAA2B;IACzB,KAAK,QAAQ,0BAA0B,GAAG;IAC1C,WAAW,QAAQ,CAAC,IAAI,YAAY,CAAC;GACvC;GACA,iBAAiB;IACf,KAAK,QAAQ,gBAAgB,GAAG;IAChC,WAAW,QAAQ,CAAC,IAAI,MAAM,kBAAkB,CAAC;GACnD;GACA,iBAAiB;IACf,KAAK,QAAQ,gBAAgB,GAAG;IAChC,WAAW,QAAQ,CAAC,IAAI,OAAO;GACjC;GACA,kBAAkB,EAChB,KAAK,QAAQ,iBAAiB,GAAG,EACnC;GACA,mBAAmB,EACjB,KAAK,QAAQ,kBAAkB,GAAG,EACpC;GACA,qBAAqB,EACnB,KAAK,KAAK,aAAa,oBAAoB,KAAK,QAAQ,EAC1D;GACA,cAAc,EACZ,KAAK,KAAK,aAAa,aAAa,KAAK,QAAQ,EACnD;GACA,iBAAiB,EACf,KAAK,KAAK,aAAa,gBAAgB,KAAK,QAAQ,EACtD;EACF,CAAC;CACH;CACA,qBAAqB,UAAU;EAC7B,gBAAgB,mBAAmB,OAAO;GACxC,gBAAgB,EACd,KAAK,aAAa,OAAO,WACvB,eAAe,aAAa,OAAO,OAAO,MAAM,EACpD;GACA,cAAc,EACZ,KAAK,IAAY,cACf,aAAa,OAAO,IAAI,SAAS,EACrC;EACF,CAAC;CACH;AACF"}
@@ -435,7 +435,7 @@ function selectRowsFn(rowModel, table) {
435
435
  const newSubRows = recurseRows(row.subRows, depth + 1);
436
436
  if (isSelected) {
437
437
  const cloned = Object.create(Object.getPrototypeOf(row));
438
- Object.assign(cloned, row);
438
+ require_utils.copyInstancePropertiesWithoutMemos(cloned, row);
439
439
  cloned.subRows = newSubRows;
440
440
  result.push(cloned);
441
441
  }
@@ -1 +1 @@
1
- {"version":3,"file":"rowSelectionFeature.utils.cjs","names":["makeObjectMap","cloneState","callMemoOrStaticFn","hasOwn"],"sources":["../../../src/features/row-selection/rowSelectionFeature.utils.ts"],"sourcesContent":["import {\n callMemoOrStaticFn,\n cloneState,\n hasOwn,\n makeObjectMap,\n} from '../../utils'\nimport type { RowData, Updater } from '../../types/type-utils'\nimport type { TableFeatures } from '../../types/TableFeatures'\nimport type { RowModel } from '../../core/row-models/coreRowModelsFeature.types'\nimport type { Table_Internal } from '../../types/Table'\nimport type { Row } from '../../types/Row'\nimport type { RowSelectionState } from './rowSelectionFeature.types'\n\n// State APIs\n\n/**\n * Creates the default row selection state.\n *\n * The feature default is an empty map, meaning no rows are selected. Reset APIs\n * use this value when `defaultState` is `true`.\n *\n * @example\n * ```ts\n * const selection = getDefaultRowSelectionState()\n * ```\n */\nexport function getDefaultRowSelectionState(): RowSelectionState {\n return makeObjectMap()\n}\n\n/**\n * Routes a row selection updater through the table's selection change handler.\n *\n * The updater may be a next selection map or a function of the previous map,\n * matching the instance `table.setRowSelection` behavior.\n *\n * @example\n * ```ts\n * table_setRowSelection(table, (old) => ({ ...old, [rowId]: true }))\n * ```\n */\nexport function table_setRowSelection<\n TFeatures extends TableFeatures,\n TData extends RowData,\n>(\n table: Table_Internal<TFeatures, TData>,\n updater: Updater<RowSelectionState>,\n) {\n table.options.onRowSelectionChange?.(updater)\n}\n\n/**\n * Resets `rowSelection` to the configured initial state or feature default.\n *\n * With no argument, the reset clones `table.initialState.rowSelection` when it\n * exists. Passing `true` ignores initial state and resets to `{}`.\n *\n * @example\n * ```ts\n * table_resetRowSelection(table)\n * table_resetRowSelection(table, true)\n * ```\n */\nexport function table_resetRowSelection<\n TFeatures extends TableFeatures,\n TData extends RowData,\n>(table: Table_Internal<TFeatures, TData>, defaultState?: boolean) {\n table_setRowSelection(\n table,\n defaultState\n ? makeObjectMap()\n : Object.assign(\n makeObjectMap<true>(),\n cloneState(table.initialState.rowSelection ?? {}),\n ),\n )\n}\n\n// Table APIs\n\n/**\n * Selects or deselects every selectable row before grouping.\n *\n * Omitting `value` toggles based on `table_getIsAllRowsSelected(table)`.\n * Deselecting removes matching ids from the existing selection map.\n *\n * @example\n * ```ts\n * table_toggleAllRowsSelected(table)\n * ```\n */\nexport function table_toggleAllRowsSelected<\n TFeatures extends TableFeatures,\n TData extends RowData,\n>(\n table: Table_Internal<TFeatures, TData>,\n value?: boolean,\n opts?: { deselectAll?: boolean },\n) {\n table_setRowSelection(table, (old) => {\n value =\n typeof value !== 'undefined'\n ? value\n : !callMemoOrStaticFn(\n table,\n 'getIsAllRowsSelected',\n table_getIsAllRowsSelected,\n )\n\n if (opts?.deselectAll && !value) {\n // deselectAll opt: clear the whole selection map instead of deleting ids one-by-one\n return makeObjectMap<true>()\n }\n\n const rowSelection = Object.assign(makeObjectMap<true>(), old)\n const preGroupedFlatRows = table.getPreGroupedRowModel().flatRows\n\n // We don't use `mutateRowIsSelected` here for performance reasons.\n // All of the rows are flat already, so it wouldn't be worth it\n if (value) {\n preGroupedFlatRows.forEach((row) => {\n if (row_getCanSelect(row)) {\n rowSelection[row.id] = true\n }\n })\n } else {\n preGroupedFlatRows.forEach((row) => {\n delete rowSelection[row.id]\n })\n }\n\n return rowSelection\n })\n}\n\n/**\n * Selects or deselects every selectable row on the current page.\n *\n * Omitting `value` toggles based on `table_getIsAllPageRowsSelected(table)`.\n * Child rows are included when sub-row selection allows it.\n *\n * @example\n * ```ts\n * table_toggleAllPageRowsSelected(table)\n * ```\n */\nexport function table_toggleAllPageRowsSelected<\n TFeatures extends TableFeatures,\n TData extends RowData,\n>(\n table: Table_Internal<TFeatures, TData>,\n value?: boolean,\n opts?: { deselectAll?: boolean },\n) {\n table_setRowSelection(table, (old) => {\n const resolvedValue =\n typeof value !== 'undefined'\n ? value\n : !callMemoOrStaticFn(\n table,\n 'getIsAllPageRowsSelected',\n table_getIsAllPageRowsSelected,\n )\n\n if (opts?.deselectAll && !resolvedValue) {\n // deselectAll opt: clear the whole selection map instead of deleting ids one-by-one\n return makeObjectMap<true>()\n }\n\n const rowSelection: RowSelectionState = Object.assign(\n makeObjectMap<true>(),\n old,\n )\n\n table.getRowModel().rows.forEach((row) => {\n mutateRowIsSelected(rowSelection, row.id, resolvedValue, true, table)\n })\n\n return rowSelection\n })\n}\n\n/**\n * Reads the row model before row selection is projected into selected rows.\n *\n * Selection does not alter the base row pipeline, so this returns the core row\n * model.\n *\n * @example\n * ```ts\n * const rowsBeforeSelection = table_getPreSelectedRowModel(table)\n * ```\n */\nexport function table_getPreSelectedRowModel<\n TFeatures extends TableFeatures,\n TData extends RowData,\n>(table: Table_Internal<TFeatures, TData>): RowModel<TFeatures, TData> {\n return table.getCoreRowModel()\n}\n\n/**\n * Builds a row model containing selected rows from the core row model.\n *\n * If no row ids are selected, an empty row model is returned without walking\n * the rows.\n *\n * @example\n * ```ts\n * const selectedRows = table_getSelectedRowModel(table)\n * ```\n */\nexport function table_getSelectedRowModel<\n TFeatures extends TableFeatures,\n TData extends RowData,\n>(table: Table_Internal<TFeatures, TData>) {\n const rowModel = table.getCoreRowModel()\n\n if (\n !callMemoOrStaticFn(\n table,\n 'getIsSomeRowsSelected',\n table_getIsSomeRowsSelected,\n )\n ) {\n return {\n rows: [],\n flatRows: [],\n rowsById: makeObjectMap(),\n }\n }\n\n return selectRowsFn(rowModel, table)\n}\n\n/**\n * Builds a row model containing selected rows from the filtered row model.\n *\n * If no row ids are selected, an empty row model is returned without walking\n * the rows.\n *\n * @example\n * ```ts\n * const selectedRows = table_getFilteredSelectedRowModel(table)\n * ```\n */\nexport function table_getFilteredSelectedRowModel<\n TFeatures extends TableFeatures,\n TData extends RowData,\n>(table: Table_Internal<TFeatures, TData>) {\n const rowModel = table.getFilteredRowModel()\n\n if (\n !callMemoOrStaticFn(\n table,\n 'getIsSomeRowsSelected',\n table_getIsSomeRowsSelected,\n )\n ) {\n return {\n rows: [],\n flatRows: [],\n rowsById: makeObjectMap(),\n }\n }\n\n return selectRowsFn(rowModel, table)\n}\n\n/**\n * Builds a row model containing selected rows from the grouped row model.\n *\n * If no row ids are selected, an empty row model is returned without walking\n * the rows.\n *\n * @example\n * ```ts\n * const selectedRows = table_getGroupedSelectedRowModel(table)\n * ```\n */\nexport function table_getGroupedSelectedRowModel<\n TFeatures extends TableFeatures,\n TData extends RowData,\n>(table: Table_Internal<TFeatures, TData>) {\n // The sorted model falls back grouped -> filtered -> core when those\n // features are not registered, so selected group rows are always visible.\n const rowModel = table.getSortedRowModel()\n\n if (\n !callMemoOrStaticFn(\n table,\n 'getIsSomeRowsSelected',\n table_getIsSomeRowsSelected,\n )\n ) {\n return {\n rows: [],\n flatRows: [],\n rowsById: makeObjectMap(),\n }\n }\n\n return selectRowsFn(rowModel, table)\n}\n\n/**\n * Returns the ids of all selected rows.\n *\n * @example\n * ```ts\n * const selectedRowIds = table_getSelectedRowIds(table)\n * ```\n */\nexport function table_getSelectedRowIds<\n TFeatures extends TableFeatures,\n TData extends RowData,\n>(table: Table_Internal<TFeatures, TData>): Array<string> {\n return Object.keys(table.atoms.rowSelection?.get() ?? {})\n}\n\n/**\n * Checks whether every selectable filtered row is selected.\n *\n * The result is false when there are no filtered rows or when selection state is\n * empty.\n *\n * @example\n * ```ts\n * const allSelected = table_getIsAllRowsSelected(table)\n * ```\n */\nexport function table_getIsAllRowsSelected<\n TFeatures extends TableFeatures,\n TData extends RowData,\n>(table: Table_Internal<TFeatures, TData>) {\n const preGroupedFlatRows = table.getFilteredRowModel().flatRows\n const rowSelection = table.atoms.rowSelection?.get() ?? {}\n\n let isAllRowsSelected = Boolean(\n preGroupedFlatRows.length && Object.keys(rowSelection).length,\n )\n\n if (isAllRowsSelected) {\n if (\n preGroupedFlatRows.some(\n (row) => row_getCanSelect(row) && !isRowSelected(row, rowSelection),\n )\n ) {\n isAllRowsSelected = false\n }\n }\n\n return isAllRowsSelected\n}\n\n/**\n * Checks whether every selectable row on the current page is selected.\n *\n * Non-selectable rows are ignored for this calculation.\n *\n * @example\n * ```ts\n * const allPageRowsSelected = table_getIsAllPageRowsSelected(table)\n * ```\n */\nexport function table_getIsAllPageRowsSelected<\n TFeatures extends TableFeatures,\n TData extends RowData,\n>(table: Table_Internal<TFeatures, TData>) {\n const paginationFlatRows = table\n .getPaginatedRowModel()\n .flatRows.filter((row) => row_getCanSelect(row))\n const rowSelection = table.atoms.rowSelection?.get() ?? {}\n\n let isAllPageRowsSelected = !!paginationFlatRows.length\n\n if (\n isAllPageRowsSelected &&\n paginationFlatRows.some((row) => !isRowSelected(row, rowSelection))\n ) {\n isAllPageRowsSelected = false\n }\n\n return isAllPageRowsSelected\n}\n\n/**\n * Checks whether selection is partially applied across filtered rows.\n *\n * The result is true when at least one row id is selected\n *\n * @example\n * ```ts\n * const someRowsSelected = table_getIsSomeRowsSelected(table)\n * ```\n */\nexport function table_getIsSomeRowsSelected<\n TFeatures extends TableFeatures,\n TData extends RowData,\n>(table: Table_Internal<TFeatures, TData>) {\n return (\n callMemoOrStaticFn(table, 'getSelectedRowIds', table_getSelectedRowIds)\n .length > 0\n )\n}\n\n/**\n * Checks whether the current page has a partial selection.\n *\n * @example\n * ```ts\n * const somePageRowsSelected = table_getIsSomePageRowsSelected(table)\n * ```\n */\nexport function table_getIsSomePageRowsSelected<\n TFeatures extends TableFeatures,\n TData extends RowData,\n>(table: Table_Internal<TFeatures, TData>) {\n return table\n .getPaginatedRowModel()\n .flatRows.filter((row) => row_getCanSelect(row))\n .some(\n (row) =>\n row_getIsSelected(row) ||\n callMemoOrStaticFn(row, 'getIsSomeSelected', row_getIsSomeSelected),\n )\n}\n\n/**\n * Creates a checkbox-style handler that selects or deselects all rows.\n *\n * The handler reads `event.target.checked`, so it is intended for controls whose\n * checked state means \"all rows selected\".\n *\n * @example\n * ```ts\n * const onChange = table_getToggleAllRowsSelectedHandler(table)\n * ```\n */\nexport function table_getToggleAllRowsSelectedHandler<\n TFeatures extends TableFeatures,\n TData extends RowData,\n>(table: Table_Internal<TFeatures, TData>) {\n return (e: unknown) => {\n table_toggleAllRowsSelected(\n table,\n ((e as MouseEvent).target as HTMLInputElement).checked,\n )\n }\n}\n\n/**\n * Creates a checkbox-style handler that selects or deselects current page rows.\n *\n * The handler reads `event.target.checked`, so it is intended for controls whose\n * checked state means \"all page rows selected\".\n *\n * @example\n * ```ts\n * const onChange = table_getToggleAllPageRowsSelectedHandler(table)\n * ```\n */\nexport function table_getToggleAllPageRowsSelectedHandler<\n TFeatures extends TableFeatures,\n TData extends RowData,\n>(table: Table_Internal<TFeatures, TData>) {\n return (e: unknown) => {\n table_toggleAllPageRowsSelected(\n table,\n ((e as MouseEvent).target as HTMLInputElement).checked,\n )\n }\n}\n\n// Row APIs\n\n/**\n * Selects or deselects this row.\n *\n * Omitting `value` toggles the row. Child rows are selected recursively unless\n * `opts.selectChildren` is `false` or sub-row selection is disabled.\n *\n * @example\n * ```ts\n * row_toggleSelected(row)\n * row_toggleSelected(row, true)\n * row_toggleSelected(row, false)\n * row_toggleSelected(row, true, { selectChildren: false })\n * row_toggleSelected(row, false, { selectChildren: false })\n * ```\n */\nexport function row_toggleSelected<\n TFeatures extends TableFeatures,\n TData extends RowData,\n>(\n row: Row<TFeatures, TData>,\n value?: boolean,\n opts?: {\n selectChildren?: boolean\n },\n) {\n const isSelected = row_getIsSelected(row)\n\n table_setRowSelection(row.table, (old) => {\n value = typeof value !== 'undefined' ? value : !isSelected\n\n const rowSelection = Object.assign(makeObjectMap<true>(), old)\n\n mutateRowIsSelected(\n rowSelection,\n row.id,\n value,\n opts?.selectChildren ?? true,\n row.table,\n )\n\n return rowSelection\n })\n}\n\n/**\n * Checks whether this row id is selected in `state.rowSelection`.\n *\n * Missing row ids are treated as not selected.\n *\n * @example\n * ```ts\n * const selected = row_getIsSelected(row)\n * ```\n */\nexport function row_getIsSelected<\n TFeatures extends TableFeatures,\n TData extends RowData,\n>(row: Row<TFeatures, TData>) {\n const rowSelection = row.table.atoms.rowSelection?.get() ?? {}\n return isRowSelected(row, rowSelection)\n}\n\n/**\n * Checks whether some, but not all, selectable descendants are selected.\n *\n * This supports indeterminate selection UI for parent rows.\n *\n * @example\n * ```ts\n * const partial = row_getIsSomeSelected(row)\n * ```\n */\nexport function row_getIsSomeSelected<\n TFeatures extends TableFeatures,\n TData extends RowData,\n>(row: Row<TFeatures, TData>) {\n return isSubRowSelected(row) === 'some'\n}\n\n/**\n * Checks whether all selectable descendants are selected.\n *\n * Rows without selectable descendants return false.\n *\n * @example\n * ```ts\n * const allChildrenSelected = row_getIsAllSubRowsSelected(row)\n * ```\n */\nexport function row_getIsAllSubRowsSelected<\n TFeatures extends TableFeatures,\n TData extends RowData,\n>(row: Row<TFeatures, TData>) {\n return isSubRowSelected(row) === 'all'\n}\n\n/**\n * Checks whether this row can be selected.\n *\n * `options.enableRowSelection` may be a boolean or a row predicate; it defaults\n * to `true`.\n *\n * @example\n * ```ts\n * const canSelect = row_getCanSelect(row)\n * ```\n */\nexport function row_getCanSelect<\n TFeatures extends TableFeatures,\n TData extends RowData,\n>(row: Row<TFeatures, TData>) {\n const options = row.table.options\n if (typeof options.enableRowSelection === 'function') {\n return options.enableRowSelection(row)\n }\n\n return options.enableRowSelection ?? true\n}\n\n/**\n * Checks whether selecting this row should also select its subRows.\n *\n * `options.enableSubRowSelection` may be a boolean or a row predicate; it\n * defaults to `true`.\n *\n * @example\n * ```ts\n * const canSelectChildren = row_getCanSelectSubRows(row)\n * ```\n */\nexport function row_getCanSelectSubRows<\n TFeatures extends TableFeatures,\n TData extends RowData,\n>(row: Row<TFeatures, TData>) {\n const options = row.table.options\n if (typeof options.enableSubRowSelection === 'function') {\n return options.enableSubRowSelection(row)\n }\n\n return options.enableSubRowSelection ?? true\n}\n\n/**\n * Checks whether this row can be selected alongside other rows.\n *\n * `options.enableMultiRowSelection` may be a boolean or a row predicate; it\n * defaults to `true`.\n *\n * @example\n * ```ts\n * const canMultiSelect = row_getCanMultiSelect(row)\n * ```\n */\nexport function row_getCanMultiSelect<\n TFeatures extends TableFeatures,\n TData extends RowData,\n>(row: Row<TFeatures, TData>) {\n const options = row.table.options\n if (typeof options.enableMultiRowSelection === 'function') {\n return options.enableMultiRowSelection(row)\n }\n\n return options.enableMultiRowSelection ?? true\n}\n\n/**\n * Creates a checkbox-style handler that selects or deselects this row.\n *\n * The handler is a no-op when the row cannot be selected and reads\n * `event.target.checked`.\n *\n * @example\n * ```ts\n * const onChange = row_getToggleSelectedHandler(row)\n * ```\n */\nexport function row_getToggleSelectedHandler<\n TFeatures extends TableFeatures,\n TData extends RowData,\n>(row: Row<TFeatures, TData>) {\n const canSelect = row_getCanSelect(row)\n\n return (e: unknown) => {\n if (!canSelect) return\n row_toggleSelected(\n row,\n ((e as MouseEvent).target as HTMLInputElement).checked,\n )\n }\n}\n\nconst mutateRowIsSelected = <\n TFeatures extends TableFeatures,\n TData extends RowData,\n>(\n rowSelection: RowSelectionState,\n rowId: string,\n value: boolean,\n includeChildren: boolean,\n table: Table_Internal<TFeatures, TData>,\n): void => {\n const row = table.getRow(rowId, true)\n\n if (value) {\n if (!row_getCanMultiSelect(row)) {\n Object.keys(rowSelection).forEach((key) => delete rowSelection[key])\n }\n if (row_getCanSelect(row)) {\n rowSelection[rowId] = true\n }\n } else {\n delete rowSelection[rowId]\n }\n\n if (includeChildren && row.subRows.length && row_getCanSelectSubRows(row)) {\n row.subRows.forEach((r) =>\n mutateRowIsSelected(rowSelection, r.id, value, includeChildren, table),\n )\n }\n}\n\n/**\n * Builds a row model containing rows selected by the current row selection state.\n *\n * The result is derived from the supplied row model, so selected ids absent from\n * that model are not materialized as rows.\n *\n * @example\n * ```ts\n * const selectedRows = selectRowsFn(rowModel)\n * ```\n */\nexport function selectRowsFn<\n TFeatures extends TableFeatures,\n TData extends RowData,\n>(\n rowModel: RowModel<TFeatures, TData>,\n table: Table_Internal<TFeatures, TData>,\n): RowModel<TFeatures, TData> {\n const newSelectedFlatRows: Array<Row<TFeatures, TData>> = []\n const newSelectedRowsById = makeObjectMap<Row<TFeatures, TData>>()\n const rowSelection = table.atoms.rowSelection?.get() ?? {}\n // Filters top level and nested rows.\n const recurseRows = (\n rows: Array<Row<TFeatures, TData>>,\n depth = 0,\n ): Array<Row<TFeatures, TData>> => {\n const result: Array<Row<TFeatures, TData>> = []\n for (let i = 0; i < rows.length; i++) {\n const row = rows[i]!\n const isSelected = isRowSelected(row, rowSelection)\n\n if (isSelected) {\n newSelectedFlatRows.push(row)\n newSelectedRowsById[row.id] = row\n }\n\n if (row.subRows.length) {\n // Always recurse — selected descendants of unselected parents must\n // still be collected into flatRows/rowsById.\n const newSubRows = recurseRows(row.subRows, depth + 1)\n\n if (isSelected) {\n // Preserve prototype chain so methods like getValue() remain accessible\n const cloned = Object.create(Object.getPrototypeOf(row))\n Object.assign(cloned, row)\n cloned.subRows = newSubRows\n result.push(cloned)\n }\n } else if (isSelected) {\n result.push(row)\n }\n }\n return result\n }\n\n return {\n rows: recurseRows(rowModel.rows),\n flatRows: newSelectedFlatRows,\n rowsById: newSelectedRowsById,\n }\n}\n\n/**\n * Returns whether a row id is selected in the current row selection state.\n *\n * @example\n * ```ts\n * const selected = isRowSelected(row)\n * ```\n */\nexport function isRowSelected<\n TFeatures extends TableFeatures,\n TData extends RowData,\n>(row: Row<TFeatures, TData>, rowSelection: RowSelectionState): boolean {\n return !!(hasOwn(rowSelection, row.id) && rowSelection[row.id])\n}\n\n/**\n * Returns whether all, some, or none of a row's selectable descendants are selected.\n *\n * The result is used to drive indeterminate row selection UI.\n *\n * @example\n * ```ts\n * const selectedState = isSubRowSelected(row)\n * ```\n */\nexport function isSubRowSelected<\n TFeatures extends TableFeatures,\n TData extends RowData,\n>(row: Row<TFeatures, TData>): boolean | 'some' | 'all' {\n if (!row.subRows.length) return false\n\n const rowSelection = row.table.atoms.rowSelection?.get() ?? {}\n\n let someSelected = false\n let allChildrenSelected = true\n\n for (let i = 0; i < row.subRows.length; i++) {\n const subRow = row.subRows[i]!\n\n // Bail out early if we know both of these\n if (someSelected && !allChildrenSelected) {\n break\n }\n\n if (row_getCanSelect(subRow)) {\n if (isRowSelected(subRow, rowSelection)) {\n someSelected = true\n } else {\n allChildrenSelected = false\n }\n }\n\n // Check row selection of nested subrows\n if (subRow.subRows.length) {\n const subRowChildrenSelected = isSubRowSelected(subRow)\n if (subRowChildrenSelected === 'all') {\n someSelected = true\n } else if (subRowChildrenSelected === 'some') {\n someSelected = true\n allChildrenSelected = false\n } else {\n allChildrenSelected = false\n }\n }\n }\n\n return allChildrenSelected ? 'all' : someSelected ? 'some' : false\n}\n"],"mappings":";;;;;;;;;;;;;;AA0BA,SAAgB,8BAAiD;CAC/D,OAAOA,4BAAc;AACvB;;;;;;;;;;;;AAaA,SAAgB,sBAId,OACA,SACA;CACA,MAAM,QAAQ,uBAAuB,OAAO;AAC9C;;;;;;;;;;;;;AAcA,SAAgB,wBAGd,OAAyC,cAAwB;CACjE,sBACE,OACA,eACIA,4BAAc,IACd,OAAO,OACLA,4BAAoB,GACpBC,yBAAW,MAAM,aAAa,gBAAgB,CAAC,CAAC,CAClD,CACN;AACF;;;;;;;;;;;;AAeA,SAAgB,4BAId,OACA,OACA,MACA;CACA,sBAAsB,QAAQ,QAAQ;EACpC,Q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OrStaticFn","hasOwn"],"sources":["../../../src/features/row-selection/rowSelectionFeature.utils.ts"],"sourcesContent":["import {\n callMemoOrStaticFn,\n cloneState,\n copyInstancePropertiesWithoutMemos,\n hasOwn,\n makeObjectMap,\n} from '../../utils'\nimport type { RowData, Updater } from '../../types/type-utils'\nimport type { TableFeatures } from '../../types/TableFeatures'\nimport type { RowModel } from '../../core/row-models/coreRowModelsFeature.types'\nimport type { Table_Internal } from '../../types/Table'\nimport type { Row } from '../../types/Row'\nimport type { RowSelectionState } from './rowSelectionFeature.types'\n\n// State APIs\n\n/**\n * Creates the default row selection state.\n *\n * The feature default is an empty map, meaning no rows are selected. Reset APIs\n * use this value when `defaultState` is `true`.\n *\n * @example\n * ```ts\n * const selection = getDefaultRowSelectionState()\n * ```\n */\nexport function getDefaultRowSelectionState(): RowSelectionState {\n return makeObjectMap()\n}\n\n/**\n * Routes a row selection updater through the table's selection change handler.\n *\n * The updater may be a next selection map or a function of the previous map,\n * matching the instance `table.setRowSelection` behavior.\n *\n * @example\n * ```ts\n * table_setRowSelection(table, (old) => ({ ...old, [rowId]: true }))\n * ```\n */\nexport function table_setRowSelection<\n TFeatures extends TableFeatures,\n TData extends RowData,\n>(\n table: Table_Internal<TFeatures, TData>,\n updater: Updater<RowSelectionState>,\n) {\n table.options.onRowSelectionChange?.(updater)\n}\n\n/**\n * Resets `rowSelection` to the configured initial state or feature default.\n *\n * With no argument, the reset clones `table.initialState.rowSelection` when it\n * exists. Passing `true` ignores initial state and resets to `{}`.\n *\n * @example\n * ```ts\n * table_resetRowSelection(table)\n * table_resetRowSelection(table, true)\n * ```\n */\nexport function table_resetRowSelection<\n TFeatures extends TableFeatures,\n TData extends RowData,\n>(table: Table_Internal<TFeatures, TData>, defaultState?: boolean) {\n table_setRowSelection(\n table,\n defaultState\n ? makeObjectMap()\n : Object.assign(\n makeObjectMap<true>(),\n cloneState(table.initialState.rowSelection ?? {}),\n ),\n )\n}\n\n// Table APIs\n\n/**\n * Selects or deselects every selectable row before grouping.\n *\n * Omitting `value` toggles based on `table_getIsAllRowsSelected(table)`.\n * Deselecting removes matching ids from the existing selection map.\n *\n * @example\n * ```ts\n * table_toggleAllRowsSelected(table)\n * ```\n */\nexport function table_toggleAllRowsSelected<\n TFeatures extends TableFeatures,\n TData extends RowData,\n>(\n table: Table_Internal<TFeatures, TData>,\n value?: boolean,\n opts?: { deselectAll?: boolean },\n) {\n table_setRowSelection(table, (old) => {\n value =\n typeof value !== 'undefined'\n ? value\n : !callMemoOrStaticFn(\n table,\n 'getIsAllRowsSelected',\n table_getIsAllRowsSelected,\n )\n\n if (opts?.deselectAll && !value) {\n // deselectAll opt: clear the whole selection map instead of deleting ids one-by-one\n return makeObjectMap<true>()\n }\n\n const rowSelection = Object.assign(makeObjectMap<true>(), old)\n const preGroupedFlatRows = table.getPreGroupedRowModel().flatRows\n\n // We don't use `mutateRowIsSelected` here for performance reasons.\n // All of the rows are flat already, so it wouldn't be worth it\n if (value) {\n preGroupedFlatRows.forEach((row) => {\n if (row_getCanSelect(row)) {\n rowSelection[row.id] = true\n }\n })\n } else {\n preGroupedFlatRows.forEach((row) => {\n delete rowSelection[row.id]\n })\n }\n\n return rowSelection\n })\n}\n\n/**\n * Selects or deselects every selectable row on the current page.\n *\n * Omitting `value` toggles based on `table_getIsAllPageRowsSelected(table)`.\n * Child rows are included when sub-row selection allows it.\n *\n * @example\n * ```ts\n * table_toggleAllPageRowsSelected(table)\n * ```\n */\nexport function table_toggleAllPageRowsSelected<\n TFeatures extends TableFeatures,\n TData extends RowData,\n>(\n table: Table_Internal<TFeatures, TData>,\n value?: boolean,\n opts?: { deselectAll?: boolean },\n) {\n table_setRowSelection(table, (old) => {\n const resolvedValue =\n typeof value !== 'undefined'\n ? value\n : !callMemoOrStaticFn(\n table,\n 'getIsAllPageRowsSelected',\n table_getIsAllPageRowsSelected,\n )\n\n if (opts?.deselectAll && !resolvedValue) {\n // deselectAll opt: clear the whole selection map instead of deleting ids one-by-one\n return makeObjectMap<true>()\n }\n\n const rowSelection: RowSelectionState = Object.assign(\n makeObjectMap<true>(),\n old,\n )\n\n table.getRowModel().rows.forEach((row) => {\n mutateRowIsSelected(rowSelection, row.id, resolvedValue, true, table)\n })\n\n return rowSelection\n })\n}\n\n/**\n * Reads the row model before row selection is projected into selected rows.\n *\n * Selection does not alter the base row pipeline, so this returns the core row\n * model.\n *\n * @example\n * ```ts\n * const rowsBeforeSelection = table_getPreSelectedRowModel(table)\n * ```\n */\nexport function table_getPreSelectedRowModel<\n TFeatures extends TableFeatures,\n TData extends RowData,\n>(table: Table_Internal<TFeatures, TData>): RowModel<TFeatures, TData> {\n return table.getCoreRowModel()\n}\n\n/**\n * Builds a row model containing selected rows from the core row model.\n *\n * If no row ids are selected, an empty row model is returned without walking\n * the rows.\n *\n * @example\n * ```ts\n * const selectedRows = table_getSelectedRowModel(table)\n * ```\n */\nexport function table_getSelectedRowModel<\n TFeatures extends TableFeatures,\n TData extends RowData,\n>(table: Table_Internal<TFeatures, TData>) {\n const rowModel = table.getCoreRowModel()\n\n if (\n !callMemoOrStaticFn(\n table,\n 'getIsSomeRowsSelected',\n table_getIsSomeRowsSelected,\n )\n ) {\n return {\n rows: [],\n flatRows: [],\n rowsById: makeObjectMap(),\n }\n }\n\n return selectRowsFn(rowModel, table)\n}\n\n/**\n * Builds a row model containing selected rows from the filtered row model.\n *\n * If no row ids are selected, an empty row model is returned without walking\n * the rows.\n *\n * @example\n * ```ts\n * const selectedRows = table_getFilteredSelectedRowModel(table)\n * ```\n */\nexport function table_getFilteredSelectedRowModel<\n TFeatures extends TableFeatures,\n TData extends RowData,\n>(table: Table_Internal<TFeatures, TData>) {\n const rowModel = table.getFilteredRowModel()\n\n if (\n !callMemoOrStaticFn(\n table,\n 'getIsSomeRowsSelected',\n table_getIsSomeRowsSelected,\n )\n ) {\n return {\n rows: [],\n flatRows: [],\n rowsById: makeObjectMap(),\n }\n }\n\n return selectRowsFn(rowModel, table)\n}\n\n/**\n * Builds a row model containing selected rows from the grouped row model.\n *\n * If no row ids are selected, an empty row model is returned without walking\n * the rows.\n *\n * @example\n * ```ts\n * const selectedRows = table_getGroupedSelectedRowModel(table)\n * ```\n */\nexport function table_getGroupedSelectedRowModel<\n TFeatures extends TableFeatures,\n TData extends RowData,\n>(table: Table_Internal<TFeatures, TData>) {\n // The sorted model falls back grouped -> filtered -> core when those\n // features are not registered, so selected group rows are always visible.\n const rowModel = table.getSortedRowModel()\n\n if (\n !callMemoOrStaticFn(\n table,\n 'getIsSomeRowsSelected',\n table_getIsSomeRowsSelected,\n )\n ) {\n return {\n rows: [],\n flatRows: [],\n rowsById: makeObjectMap(),\n }\n }\n\n return selectRowsFn(rowModel, table)\n}\n\n/**\n * Returns the ids of all selected rows.\n *\n * @example\n * ```ts\n * const selectedRowIds = table_getSelectedRowIds(table)\n * ```\n */\nexport function table_getSelectedRowIds<\n TFeatures extends TableFeatures,\n TData extends RowData,\n>(table: Table_Internal<TFeatures, TData>): Array<string> {\n return Object.keys(table.atoms.rowSelection?.get() ?? {})\n}\n\n/**\n * Checks whether every selectable filtered row is selected.\n *\n * The result is false when there are no filtered rows or when selection state is\n * empty.\n *\n * @example\n * ```ts\n * const allSelected = table_getIsAllRowsSelected(table)\n * ```\n */\nexport function table_getIsAllRowsSelected<\n TFeatures extends TableFeatures,\n TData extends RowData,\n>(table: Table_Internal<TFeatures, TData>) {\n const preGroupedFlatRows = table.getFilteredRowModel().flatRows\n const rowSelection = table.atoms.rowSelection?.get() ?? {}\n\n let isAllRowsSelected = Boolean(\n preGroupedFlatRows.length && Object.keys(rowSelection).length,\n )\n\n if (isAllRowsSelected) {\n if (\n preGroupedFlatRows.some(\n (row) => row_getCanSelect(row) && !isRowSelected(row, rowSelection),\n )\n ) {\n isAllRowsSelected = false\n }\n }\n\n return isAllRowsSelected\n}\n\n/**\n * Checks whether every selectable row on the current page is selected.\n *\n * Non-selectable rows are ignored for this calculation.\n *\n * @example\n * ```ts\n * const allPageRowsSelected = table_getIsAllPageRowsSelected(table)\n * ```\n */\nexport function table_getIsAllPageRowsSelected<\n TFeatures extends TableFeatures,\n TData extends RowData,\n>(table: Table_Internal<TFeatures, TData>) {\n const paginationFlatRows = table\n .getPaginatedRowModel()\n .flatRows.filter((row) => row_getCanSelect(row))\n const rowSelection = table.atoms.rowSelection?.get() ?? {}\n\n let isAllPageRowsSelected = !!paginationFlatRows.length\n\n if (\n isAllPageRowsSelected &&\n paginationFlatRows.some((row) => !isRowSelected(row, rowSelection))\n ) {\n isAllPageRowsSelected = false\n }\n\n return isAllPageRowsSelected\n}\n\n/**\n * Checks whether selection is partially applied across filtered rows.\n *\n * The result is true when at least one row id is selected\n *\n * @example\n * ```ts\n * const someRowsSelected = table_getIsSomeRowsSelected(table)\n * ```\n */\nexport function table_getIsSomeRowsSelected<\n TFeatures extends TableFeatures,\n TData extends RowData,\n>(table: Table_Internal<TFeatures, TData>) {\n return (\n callMemoOrStaticFn(table, 'getSelectedRowIds', table_getSelectedRowIds)\n .length > 0\n )\n}\n\n/**\n * Checks whether the current page has a partial selection.\n *\n * @example\n * ```ts\n * const somePageRowsSelected = table_getIsSomePageRowsSelected(table)\n * ```\n */\nexport function table_getIsSomePageRowsSelected<\n TFeatures extends TableFeatures,\n TData extends RowData,\n>(table: Table_Internal<TFeatures, TData>) {\n return table\n .getPaginatedRowModel()\n .flatRows.filter((row) => row_getCanSelect(row))\n .some(\n (row) =>\n row_getIsSelected(row) ||\n callMemoOrStaticFn(row, 'getIsSomeSelected', row_getIsSomeSelected),\n )\n}\n\n/**\n * Creates a checkbox-style handler that selects or deselects all rows.\n *\n * The handler reads `event.target.checked`, so it is intended for controls whose\n * checked state means \"all rows selected\".\n *\n * @example\n * ```ts\n * const onChange = table_getToggleAllRowsSelectedHandler(table)\n * ```\n */\nexport function table_getToggleAllRowsSelectedHandler<\n TFeatures extends TableFeatures,\n TData extends RowData,\n>(table: Table_Internal<TFeatures, TData>) {\n return (e: unknown) => {\n table_toggleAllRowsSelected(\n table,\n ((e as MouseEvent).target as HTMLInputElement).checked,\n )\n }\n}\n\n/**\n * Creates a checkbox-style handler that selects or deselects current page rows.\n *\n * The handler reads `event.target.checked`, so it is intended for controls whose\n * checked state means \"all page rows selected\".\n *\n * @example\n * ```ts\n * const onChange = table_getToggleAllPageRowsSelectedHandler(table)\n * ```\n */\nexport function table_getToggleAllPageRowsSelectedHandler<\n TFeatures extends TableFeatures,\n TData extends RowData,\n>(table: Table_Internal<TFeatures, TData>) {\n return (e: unknown) => {\n table_toggleAllPageRowsSelected(\n table,\n ((e as MouseEvent).target as HTMLInputElement).checked,\n )\n }\n}\n\n// Row APIs\n\n/**\n * Selects or deselects this row.\n *\n * Omitting `value` toggles the row. Child rows are selected recursively unless\n * `opts.selectChildren` is `false` or sub-row selection is disabled.\n *\n * @example\n * ```ts\n * row_toggleSelected(row)\n * row_toggleSelected(row, true)\n * row_toggleSelected(row, false)\n * row_toggleSelected(row, true, { selectChildren: false })\n * row_toggleSelected(row, false, { selectChildren: false })\n * ```\n */\nexport function row_toggleSelected<\n TFeatures extends TableFeatures,\n TData extends RowData,\n>(\n row: Row<TFeatures, TData>,\n value?: boolean,\n opts?: {\n selectChildren?: boolean\n },\n) {\n const isSelected = row_getIsSelected(row)\n\n table_setRowSelection(row.table, (old) => {\n value = typeof value !== 'undefined' ? value : !isSelected\n\n const rowSelection = Object.assign(makeObjectMap<true>(), old)\n\n mutateRowIsSelected(\n rowSelection,\n row.id,\n value,\n opts?.selectChildren ?? true,\n row.table,\n )\n\n return rowSelection\n })\n}\n\n/**\n * Checks whether this row id is selected in `state.rowSelection`.\n *\n * Missing row ids are treated as not selected.\n *\n * @example\n * ```ts\n * const selected = row_getIsSelected(row)\n * ```\n */\nexport function row_getIsSelected<\n TFeatures extends TableFeatures,\n TData extends RowData,\n>(row: Row<TFeatures, TData>) {\n const rowSelection = row.table.atoms.rowSelection?.get() ?? {}\n return isRowSelected(row, rowSelection)\n}\n\n/**\n * Checks whether some, but not all, selectable descendants are selected.\n *\n * This supports indeterminate selection UI for parent rows.\n *\n * @example\n * ```ts\n * const partial = row_getIsSomeSelected(row)\n * ```\n */\nexport function row_getIsSomeSelected<\n TFeatures extends TableFeatures,\n TData extends RowData,\n>(row: Row<TFeatures, TData>) {\n return isSubRowSelected(row) === 'some'\n}\n\n/**\n * Checks whether all selectable descendants are selected.\n *\n * Rows without selectable descendants return false.\n *\n * @example\n * ```ts\n * const allChildrenSelected = row_getIsAllSubRowsSelected(row)\n * ```\n */\nexport function row_getIsAllSubRowsSelected<\n TFeatures extends TableFeatures,\n TData extends RowData,\n>(row: Row<TFeatures, TData>) {\n return isSubRowSelected(row) === 'all'\n}\n\n/**\n * Checks whether this row can be selected.\n *\n * `options.enableRowSelection` may be a boolean or a row predicate; it defaults\n * to `true`.\n *\n * @example\n * ```ts\n * const canSelect = row_getCanSelect(row)\n * ```\n */\nexport function row_getCanSelect<\n TFeatures extends TableFeatures,\n TData extends RowData,\n>(row: Row<TFeatures, TData>) {\n const options = row.table.options\n if (typeof options.enableRowSelection === 'function') {\n return options.enableRowSelection(row)\n }\n\n return options.enableRowSelection ?? true\n}\n\n/**\n * Checks whether selecting this row should also select its subRows.\n *\n * `options.enableSubRowSelection` may be a boolean or a row predicate; it\n * defaults to `true`.\n *\n * @example\n * ```ts\n * const canSelectChildren = row_getCanSelectSubRows(row)\n * ```\n */\nexport function row_getCanSelectSubRows<\n TFeatures extends TableFeatures,\n TData extends RowData,\n>(row: Row<TFeatures, TData>) {\n const options = row.table.options\n if (typeof options.enableSubRowSelection === 'function') {\n return options.enableSubRowSelection(row)\n }\n\n return options.enableSubRowSelection ?? true\n}\n\n/**\n * Checks whether this row can be selected alongside other rows.\n *\n * `options.enableMultiRowSelection` may be a boolean or a row predicate; it\n * defaults to `true`.\n *\n * @example\n * ```ts\n * const canMultiSelect = row_getCanMultiSelect(row)\n * ```\n */\nexport function row_getCanMultiSelect<\n TFeatures extends TableFeatures,\n TData extends RowData,\n>(row: Row<TFeatures, TData>) {\n const options = row.table.options\n if (typeof options.enableMultiRowSelection === 'function') {\n return options.enableMultiRowSelection(row)\n }\n\n return options.enableMultiRowSelection ?? true\n}\n\n/**\n * Creates a checkbox-style handler that selects or deselects this row.\n *\n * The handler is a no-op when the row cannot be selected and reads\n * `event.target.checked`.\n *\n * @example\n * ```ts\n * const onChange = row_getToggleSelectedHandler(row)\n * ```\n */\nexport function row_getToggleSelectedHandler<\n TFeatures extends TableFeatures,\n TData extends RowData,\n>(row: Row<TFeatures, TData>) {\n const canSelect = row_getCanSelect(row)\n\n return (e: unknown) => {\n if (!canSelect) return\n row_toggleSelected(\n row,\n ((e as MouseEvent).target as HTMLInputElement).checked,\n )\n }\n}\n\nconst mutateRowIsSelected = <\n TFeatures extends TableFeatures,\n TData extends RowData,\n>(\n rowSelection: RowSelectionState,\n rowId: string,\n value: boolean,\n includeChildren: boolean,\n table: Table_Internal<TFeatures, TData>,\n): void => {\n const row = table.getRow(rowId, true)\n\n if (value) {\n if (!row_getCanMultiSelect(row)) {\n Object.keys(rowSelection).forEach((key) => delete rowSelection[key])\n }\n if (row_getCanSelect(row)) {\n rowSelection[rowId] = true\n }\n } else {\n delete rowSelection[rowId]\n }\n\n if (includeChildren && row.subRows.length && row_getCanSelectSubRows(row)) {\n row.subRows.forEach((r) =>\n mutateRowIsSelected(rowSelection, r.id, value, includeChildren, table),\n )\n }\n}\n\n/**\n * Builds a row model containing rows selected by the current row selection state.\n *\n * The result is derived from the supplied row model, so selected ids absent from\n * that model are not materialized as rows.\n *\n * @example\n * ```ts\n * const selectedRows = selectRowsFn(rowModel)\n * ```\n */\nexport function selectRowsFn<\n TFeatures extends TableFeatures,\n TData extends RowData,\n>(\n rowModel: RowModel<TFeatures, TData>,\n table: Table_Internal<TFeatures, TData>,\n): RowModel<TFeatures, TData> {\n const newSelectedFlatRows: Array<Row<TFeatures, TData>> = []\n const newSelectedRowsById = makeObjectMap<Row<TFeatures, TData>>()\n const rowSelection = table.atoms.rowSelection?.get() ?? {}\n // Filters top level and nested rows.\n const recurseRows = (\n rows: Array<Row<TFeatures, TData>>,\n depth = 0,\n ): Array<Row<TFeatures, TData>> => {\n const result: Array<Row<TFeatures, TData>> = []\n for (let i = 0; i < rows.length; i++) {\n const row = rows[i]!\n const isSelected = isRowSelected(row, rowSelection)\n\n if (isSelected) {\n newSelectedFlatRows.push(row)\n newSelectedRowsById[row.id] = row\n }\n\n if (row.subRows.length) {\n // Always recurse — selected descendants of unselected parents must\n // still be collected into flatRows/rowsById.\n const newSubRows = recurseRows(row.subRows, depth + 1)\n\n if (isSelected) {\n // Preserve prototype chain so methods like getValue() remain accessible\n const cloned = Object.create(Object.getPrototypeOf(row))\n copyInstancePropertiesWithoutMemos(cloned, row)\n cloned.subRows = newSubRows\n result.push(cloned)\n }\n } else if (isSelected) {\n result.push(row)\n }\n }\n return result\n }\n\n return {\n rows: recurseRows(rowModel.rows),\n flatRows: newSelectedFlatRows,\n rowsById: newSelectedRowsById,\n }\n}\n\n/**\n * Returns whether a row id is selected in the current row selection state.\n *\n * @example\n * ```ts\n * const selected = isRowSelected(row)\n * ```\n */\nexport function isRowSelected<\n TFeatures extends TableFeatures,\n TData extends RowData,\n>(row: Row<TFeatures, TData>, rowSelection: RowSelectionState): boolean {\n return !!(hasOwn(rowSelection, row.id) && rowSelection[row.id])\n}\n\n/**\n * Returns whether all, some, or none of a row's selectable descendants are selected.\n *\n * The result is used to drive indeterminate row selection UI.\n *\n * @example\n * ```ts\n * const selectedState = isSubRowSelected(row)\n * ```\n */\nexport function isSubRowSelected<\n TFeatures extends TableFeatures,\n TData extends RowData,\n>(row: Row<TFeatures, TData>): boolean | 'some' | 'all' {\n if (!row.subRows.length) return false\n\n const rowSelection = row.table.atoms.rowSelection?.get() ?? {}\n\n let someSelected = false\n let allChildrenSelected = true\n\n for (let i = 0; i < row.subRows.length; i++) {\n const subRow = row.subRows[i]!\n\n // Bail out early if we know both of these\n if (someSelected && !allChildrenSelected) {\n break\n }\n\n if (row_getCanSelect(subRow)) {\n if (isRowSelected(subRow, rowSelection)) {\n someSelected = true\n } else {\n allChildrenSelected = false\n }\n }\n\n // Check row selection of nested subrows\n if (subRow.subRows.length) {\n const subRowChildrenSelected = isSubRowSelected(subRow)\n if (subRowChildrenSelected === 'all') {\n someSelected = true\n } else if (subRowChildrenSelected === 'some') {\n someSelected = true\n allChildrenSelected = false\n } else {\n allChildrenSelected = false\n }\n }\n }\n\n return allChildrenSelected ? 'all' : someSelected ? 'some' : false\n}\n"],"mappings":";;;;;;;;;;;;;;AA2BA,SAAgB,8BAAiD;CAC/D,OAAOA,4BAAc;AACvB;;;;;;;;;;;;AAaA,SAAgB,sBAId,OACA,SACA;CACA,MAAM,QAAQ,uBAAuB,OAAO;AAC9C;;;;;;;;;;;;;AAcA,SAAgB,wBAGd,OAAyC,cAAwB;CACjE,sBACE,OACA,eACIA,4BAAc,IACd,OAAO,OACLA,4BAAoB,GACpBC,yBAAW,MAAM,aAAa,gBAAgB,CAAC,CAAC,CAClD,CACN;AACF;;;;;;;;;;;;AAeA,SAAgB,4BAId,OACA,OACA,MACA;CACA,sBAAsB,QAAQ,QAAQ;EACpC,QACE,OAAO,UAAU,cACb,QACA,CAACC,iCACC,OACA,wBACA,0BACF;EAEN,IAAI,MAAM,eAAe,CAAC,OAExB,OAAOF,4BAAoB;EAG7B,MAAM,eAAe,OAAO,OAAOA,4BAAoB,GAAG,GAAG;EAC7D,MAAM,qBAAqB,MAAM,sBAAsB,CAAC,CAAC;EAIzD,IAAI,OACF,mBAAmB,SAAS,QAAQ;GAClC,IAAI,iBAAiB,GAAG,GACtB,aAAa,IAAI,MAAM;EAE3B,CAAC;OAED,mBAAmB,SAAS,QAAQ;GAClC,OAAO,aAAa,IAAI;EAC1B,CAAC;EAGH,OAAO;CACT,CAAC;AACH;;;;;;;;;;;;AAaA,SAAgB,gCAId,OACA,OACA,MACA;CACA,sBAAsB,QAAQ,QAAQ;EACpC,MAAM,gBACJ,OAAO,UAAU,cACb,QACA,CAACE,iCACC,O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;;;;;;;;;;;AAYA,SAAgB,iBAGd,KAAsD;CACtD,IAAI,CAAC,IAAI,QAAQ,QAAQ,OAAO;CAEhC,MAAM,eAAe,IAAI,MAAM,MAAM,cAAc,IAAI,KAAK,CAAC;CAE7D,IAAI,eAAe;CACnB,IAAI,sBAAsB;CAE1B,KAAK,IAAI,IAAI,GAAG,IAAI,IAAI,QAAQ,QAAQ,KAAK;EAC3C,MAAM,SAAS,IAAI,QAAQ;EAG3B,IAAI,gBAAgB,CAAC,qBACnB;EAGF,IAAI,iBAAiB,MAAM,GACzB,IAAI,cAAc,QAAQ,YAAY,GACpC,eAAe;OAEf,sBAAsB;EAK1B,IAAI,OAAO,QAAQ,QAAQ;GACzB,MAAM,yBAAyB,iBAAiB,MAAM;GACtD,IAAI,2BAA2B,OAC7B,eAAe;QACV,IAAI,2BAA2B,QAAQ;IAC5C,eAAe;IACf,sBAAsB;GACxB,OACE,sBAAsB;EAE1B;CACF;CAEA,OAAO,sBAAsB,QAAQ,eAAe,SAAS;AAC/D"}
@@ -1,4 +1,4 @@
1
- import { callMemoOrStaticFn, cloneState, hasOwn, makeObjectMap } from "../../utils.js";
1
+ import { callMemoOrStaticFn, cloneState, copyInstancePropertiesWithoutMemos, hasOwn, makeObjectMap } from "../../utils.js";
2
2
 
3
3
  //#region src/features/row-selection/rowSelectionFeature.utils.ts
4
4
  /**
@@ -435,7 +435,7 @@ function selectRowsFn(rowModel, table) {
435
435
  const newSubRows = recurseRows(row.subRows, depth + 1);
436
436
  if (isSelected) {
437
437
  const cloned = Object.create(Object.getPrototypeOf(row));
438
- Object.assign(cloned, row);
438
+ copyInstancePropertiesWithoutMemos(cloned, row);
439
439
  cloned.subRows = newSubRows;
440
440
  result.push(cloned);
441
441
  }
@@ -1 +1 @@
1
- {"version":3,"file":"rowSelectionFeature.utils.js","names":[],"sources":["../../../src/features/row-selection/rowSelectionFeature.utils.ts"],"sourcesContent":["import {\n callMemoOrStaticFn,\n cloneState,\n hasOwn,\n makeObjectMap,\n} from '../../utils'\nimport type { RowData, Updater } from '../../types/type-utils'\nimport type { TableFeatures } from '../../types/TableFeatures'\nimport type { RowModel } from '../../core/row-models/coreRowModelsFeature.types'\nimport type { Table_Internal } from '../../types/Table'\nimport type { Row } from '../../types/Row'\nimport type { RowSelectionState } from './rowSelectionFeature.types'\n\n// State APIs\n\n/**\n * Creates the default row selection state.\n *\n * The feature default is an empty map, meaning no rows are selected. Reset APIs\n * use this value when `defaultState` is `true`.\n *\n * @example\n * ```ts\n * const selection = getDefaultRowSelectionState()\n * ```\n */\nexport function getDefaultRowSelectionState(): RowSelectionState {\n return makeObjectMap()\n}\n\n/**\n * Routes a row selection updater through the table's selection change handler.\n *\n * The updater may be a next selection map or a function of the previous map,\n * matching the instance `table.setRowSelection` behavior.\n *\n * @example\n * ```ts\n * table_setRowSelection(table, (old) => ({ ...old, [rowId]: true }))\n * ```\n */\nexport function table_setRowSelection<\n TFeatures extends TableFeatures,\n TData extends RowData,\n>(\n table: Table_Internal<TFeatures, TData>,\n updater: Updater<RowSelectionState>,\n) {\n table.options.onRowSelectionChange?.(updater)\n}\n\n/**\n * Resets `rowSelection` to the configured initial state or feature default.\n *\n * With no argument, the reset clones `table.initialState.rowSelection` when it\n * exists. Passing `true` ignores initial state and resets to `{}`.\n *\n * @example\n * ```ts\n * table_resetRowSelection(table)\n * table_resetRowSelection(table, true)\n * ```\n */\nexport function table_resetRowSelection<\n TFeatures extends TableFeatures,\n TData extends RowData,\n>(table: Table_Internal<TFeatures, TData>, defaultState?: boolean) {\n table_setRowSelection(\n table,\n defaultState\n ? makeObjectMap()\n : Object.assign(\n makeObjectMap<true>(),\n cloneState(table.initialState.rowSelection ?? {}),\n ),\n )\n}\n\n// Table APIs\n\n/**\n * Selects or deselects every selectable row before grouping.\n *\n * Omitting `value` toggles based on `table_getIsAllRowsSelected(table)`.\n * Deselecting removes matching ids from the existing selection map.\n *\n * @example\n * ```ts\n * table_toggleAllRowsSelected(table)\n * ```\n */\nexport function table_toggleAllRowsSelected<\n TFeatures extends TableFeatures,\n TData extends RowData,\n>(\n table: Table_Internal<TFeatures, TData>,\n value?: boolean,\n opts?: { deselectAll?: boolean },\n) {\n table_setRowSelection(table, (old) => {\n value =\n typeof value !== 'undefined'\n ? value\n : !callMemoOrStaticFn(\n table,\n 'getIsAllRowsSelected',\n table_getIsAllRowsSelected,\n )\n\n if (opts?.deselectAll && !value) {\n // deselectAll opt: clear the whole selection map instead of deleting ids one-by-one\n return makeObjectMap<true>()\n }\n\n const rowSelection = Object.assign(makeObjectMap<true>(), old)\n const preGroupedFlatRows = table.getPreGroupedRowModel().flatRows\n\n // We don't use `mutateRowIsSelected` here for performance reasons.\n // All of the rows are flat already, so it wouldn't be worth it\n if (value) {\n preGroupedFlatRows.forEach((row) => {\n if (row_getCanSelect(row)) {\n rowSelection[row.id] = true\n }\n })\n } else {\n preGroupedFlatRows.forEach((row) => {\n delete rowSelection[row.id]\n })\n }\n\n return rowSelection\n })\n}\n\n/**\n * Selects or deselects every selectable row on the current page.\n *\n * Omitting `value` toggles based on `table_getIsAllPageRowsSelected(table)`.\n * Child rows are included when sub-row selection allows it.\n *\n * @example\n * ```ts\n * table_toggleAllPageRowsSelected(table)\n * ```\n */\nexport function table_toggleAllPageRowsSelected<\n TFeatures extends TableFeatures,\n TData extends RowData,\n>(\n table: Table_Internal<TFeatures, TData>,\n value?: boolean,\n opts?: { deselectAll?: boolean },\n) {\n table_setRowSelection(table, (old) => {\n const resolvedValue =\n typeof value !== 'undefined'\n ? value\n : !callMemoOrStaticFn(\n table,\n 'getIsAllPageRowsSelected',\n table_getIsAllPageRowsSelected,\n )\n\n if (opts?.deselectAll && !resolvedValue) {\n // deselectAll opt: clear the whole selection map instead of deleting ids one-by-one\n return makeObjectMap<true>()\n }\n\n const rowSelection: RowSelectionState = Object.assign(\n makeObjectMap<true>(),\n old,\n )\n\n table.getRowModel().rows.forEach((row) => {\n mutateRowIsSelected(rowSelection, row.id, resolvedValue, true, table)\n })\n\n return rowSelection\n })\n}\n\n/**\n * Reads the row model before row selection is projected into selected rows.\n *\n * Selection does not alter the base row pipeline, so this returns the core row\n * model.\n *\n * @example\n * ```ts\n * const rowsBeforeSelection = table_getPreSelectedRowModel(table)\n * ```\n */\nexport function table_getPreSelectedRowModel<\n TFeatures extends TableFeatures,\n TData extends RowData,\n>(table: Table_Internal<TFeatures, TData>): RowModel<TFeatures, TData> {\n return table.getCoreRowModel()\n}\n\n/**\n * Builds a row model containing selected rows from the core row model.\n *\n * If no row ids are selected, an empty row model is returned without walking\n * the rows.\n *\n * @example\n * ```ts\n * const selectedRows = table_getSelectedRowModel(table)\n * ```\n */\nexport function table_getSelectedRowModel<\n TFeatures extends TableFeatures,\n TData extends RowData,\n>(table: Table_Internal<TFeatures, TData>) {\n const rowModel = table.getCoreRowModel()\n\n if (\n !callMemoOrStaticFn(\n table,\n 'getIsSomeRowsSelected',\n table_getIsSomeRowsSelected,\n )\n ) {\n return {\n rows: [],\n flatRows: [],\n rowsById: makeObjectMap(),\n }\n }\n\n return selectRowsFn(rowModel, table)\n}\n\n/**\n * Builds a row model containing selected rows from the filtered row model.\n *\n * If no row ids are selected, an empty row model is returned without walking\n * the rows.\n *\n * @example\n * ```ts\n * const selectedRows = table_getFilteredSelectedRowModel(table)\n * ```\n */\nexport function table_getFilteredSelectedRowModel<\n TFeatures extends TableFeatures,\n TData extends RowData,\n>(table: Table_Internal<TFeatures, TData>) {\n const rowModel = table.getFilteredRowModel()\n\n if (\n !callMemoOrStaticFn(\n table,\n 'getIsSomeRowsSelected',\n table_getIsSomeRowsSelected,\n )\n ) {\n return {\n rows: [],\n flatRows: [],\n rowsById: makeObjectMap(),\n }\n }\n\n return selectRowsFn(rowModel, table)\n}\n\n/**\n * Builds a row model containing selected rows from the grouped row model.\n *\n * If no row ids are selected, an empty row model is returned without walking\n * the rows.\n *\n * @example\n * ```ts\n * const selectedRows = table_getGroupedSelectedRowModel(table)\n * ```\n */\nexport function table_getGroupedSelectedRowModel<\n TFeatures extends TableFeatures,\n TData extends RowData,\n>(table: Table_Internal<TFeatures, TData>) {\n // The sorted model falls back grouped -> filtered -> core when those\n // features are not registered, so selected group rows are always visible.\n const rowModel = table.getSortedRowModel()\n\n if (\n !callMemoOrStaticFn(\n table,\n 'getIsSomeRowsSelected',\n table_getIsSomeRowsSelected,\n )\n ) {\n return {\n rows: [],\n flatRows: [],\n rowsById: makeObjectMap(),\n }\n }\n\n return selectRowsFn(rowModel, table)\n}\n\n/**\n * Returns the ids of all selected rows.\n *\n * @example\n * ```ts\n * const selectedRowIds = table_getSelectedRowIds(table)\n * ```\n */\nexport function table_getSelectedRowIds<\n TFeatures extends TableFeatures,\n TData extends RowData,\n>(table: Table_Internal<TFeatures, TData>): Array<string> {\n return Object.keys(table.atoms.rowSelection?.get() ?? {})\n}\n\n/**\n * Checks whether every selectable filtered row is selected.\n *\n * The result is false when there are no filtered rows or when selection state is\n * empty.\n *\n * @example\n * ```ts\n * const allSelected = table_getIsAllRowsSelected(table)\n * ```\n */\nexport function table_getIsAllRowsSelected<\n TFeatures extends TableFeatures,\n TData extends RowData,\n>(table: Table_Internal<TFeatures, TData>) {\n const preGroupedFlatRows = table.getFilteredRowModel().flatRows\n const rowSelection = table.atoms.rowSelection?.get() ?? {}\n\n let isAllRowsSelected = Boolean(\n preGroupedFlatRows.length && Object.keys(rowSelection).length,\n )\n\n if (isAllRowsSelected) {\n if (\n preGroupedFlatRows.some(\n (row) => row_getCanSelect(row) && !isRowSelected(row, rowSelection),\n )\n ) {\n isAllRowsSelected = false\n }\n }\n\n return isAllRowsSelected\n}\n\n/**\n * Checks whether every selectable row on the current page is selected.\n *\n * Non-selectable rows are ignored for this calculation.\n *\n * @example\n * ```ts\n * const allPageRowsSelected = table_getIsAllPageRowsSelected(table)\n * ```\n */\nexport function table_getIsAllPageRowsSelected<\n TFeatures extends TableFeatures,\n TData extends RowData,\n>(table: Table_Internal<TFeatures, TData>) {\n const paginationFlatRows = table\n .getPaginatedRowModel()\n .flatRows.filter((row) => row_getCanSelect(row))\n const rowSelection = table.atoms.rowSelection?.get() ?? {}\n\n let isAllPageRowsSelected = !!paginationFlatRows.length\n\n if (\n isAllPageRowsSelected &&\n paginationFlatRows.some((row) => !isRowSelected(row, rowSelection))\n ) {\n isAllPageRowsSelected = false\n }\n\n return isAllPageRowsSelected\n}\n\n/**\n * Checks whether selection is partially applied across filtered rows.\n *\n * The result is true when at least one row id is selected\n *\n * @example\n * ```ts\n * const someRowsSelected = table_getIsSomeRowsSelected(table)\n * ```\n */\nexport function table_getIsSomeRowsSelected<\n TFeatures extends TableFeatures,\n TData extends RowData,\n>(table: Table_Internal<TFeatures, TData>) {\n return (\n callMemoOrStaticFn(table, 'getSelectedRowIds', table_getSelectedRowIds)\n .length > 0\n )\n}\n\n/**\n * Checks whether the current page has a partial selection.\n *\n * @example\n * ```ts\n * const somePageRowsSelected = table_getIsSomePageRowsSelected(table)\n * ```\n */\nexport function table_getIsSomePageRowsSelected<\n TFeatures extends TableFeatures,\n TData extends RowData,\n>(table: Table_Internal<TFeatures, TData>) {\n return table\n .getPaginatedRowModel()\n .flatRows.filter((row) => row_getCanSelect(row))\n .some(\n (row) =>\n row_getIsSelected(row) ||\n callMemoOrStaticFn(row, 'getIsSomeSelected', row_getIsSomeSelected),\n )\n}\n\n/**\n * Creates a checkbox-style handler that selects or deselects all rows.\n *\n * The handler reads `event.target.checked`, so it is intended for controls whose\n * checked state means \"all rows selected\".\n *\n * @example\n * ```ts\n * const onChange = table_getToggleAllRowsSelectedHandler(table)\n * ```\n */\nexport function table_getToggleAllRowsSelectedHandler<\n TFeatures extends TableFeatures,\n TData extends RowData,\n>(table: Table_Internal<TFeatures, TData>) {\n return (e: unknown) => {\n table_toggleAllRowsSelected(\n table,\n ((e as MouseEvent).target as HTMLInputElement).checked,\n )\n }\n}\n\n/**\n * Creates a checkbox-style handler that selects or deselects current page rows.\n *\n * The handler reads `event.target.checked`, so it is intended for controls whose\n * checked state means \"all page rows selected\".\n *\n * @example\n * ```ts\n * const onChange = table_getToggleAllPageRowsSelectedHandler(table)\n * ```\n */\nexport function table_getToggleAllPageRowsSelectedHandler<\n TFeatures extends TableFeatures,\n TData extends RowData,\n>(table: Table_Internal<TFeatures, TData>) {\n return (e: unknown) => {\n table_toggleAllPageRowsSelected(\n table,\n ((e as MouseEvent).target as HTMLInputElement).checked,\n )\n }\n}\n\n// Row APIs\n\n/**\n * Selects or deselects this row.\n *\n * Omitting `value` toggles the row. Child rows are selected recursively unless\n * `opts.selectChildren` is `false` or sub-row selection is disabled.\n *\n * @example\n * ```ts\n * row_toggleSelected(row)\n * row_toggleSelected(row, true)\n * row_toggleSelected(row, false)\n * row_toggleSelected(row, true, { selectChildren: false })\n * row_toggleSelected(row, false, { selectChildren: false })\n * ```\n */\nexport function row_toggleSelected<\n TFeatures extends TableFeatures,\n TData extends RowData,\n>(\n row: Row<TFeatures, TData>,\n value?: boolean,\n opts?: {\n selectChildren?: boolean\n },\n) {\n const isSelected = row_getIsSelected(row)\n\n table_setRowSelection(row.table, (old) => {\n value = typeof value !== 'undefined' ? value : !isSelected\n\n const rowSelection = Object.assign(makeObjectMap<true>(), old)\n\n mutateRowIsSelected(\n rowSelection,\n row.id,\n value,\n opts?.selectChildren ?? true,\n row.table,\n )\n\n return rowSelection\n })\n}\n\n/**\n * Checks whether this row id is selected in `state.rowSelection`.\n *\n * Missing row ids are treated as not selected.\n *\n * @example\n * ```ts\n * const selected = row_getIsSelected(row)\n * ```\n */\nexport function row_getIsSelected<\n TFeatures extends TableFeatures,\n TData extends RowData,\n>(row: Row<TFeatures, TData>) {\n const rowSelection = row.table.atoms.rowSelection?.get() ?? {}\n return isRowSelected(row, rowSelection)\n}\n\n/**\n * Checks whether some, but not all, selectable descendants are selected.\n *\n * This supports indeterminate selection UI for parent rows.\n *\n * @example\n * ```ts\n * const partial = row_getIsSomeSelected(row)\n * ```\n */\nexport function row_getIsSomeSelected<\n TFeatures extends TableFeatures,\n TData extends RowData,\n>(row: Row<TFeatures, TData>) {\n return isSubRowSelected(row) === 'some'\n}\n\n/**\n * Checks whether all selectable descendants are selected.\n *\n * Rows without selectable descendants return false.\n *\n * @example\n * ```ts\n * const allChildrenSelected = row_getIsAllSubRowsSelected(row)\n * ```\n */\nexport function row_getIsAllSubRowsSelected<\n TFeatures extends TableFeatures,\n TData extends RowData,\n>(row: Row<TFeatures, TData>) {\n return isSubRowSelected(row) === 'all'\n}\n\n/**\n * Checks whether this row can be selected.\n *\n * `options.enableRowSelection` may be a boolean or a row predicate; it defaults\n * to `true`.\n *\n * @example\n * ```ts\n * const canSelect = row_getCanSelect(row)\n * ```\n */\nexport function row_getCanSelect<\n TFeatures extends TableFeatures,\n TData extends RowData,\n>(row: Row<TFeatures, TData>) {\n const options = row.table.options\n if (typeof options.enableRowSelection === 'function') {\n return options.enableRowSelection(row)\n }\n\n return options.enableRowSelection ?? true\n}\n\n/**\n * Checks whether selecting this row should also select its subRows.\n *\n * `options.enableSubRowSelection` may be a boolean or a row predicate; it\n * defaults to `true`.\n *\n * @example\n * ```ts\n * const canSelectChildren = row_getCanSelectSubRows(row)\n * ```\n */\nexport function row_getCanSelectSubRows<\n TFeatures extends TableFeatures,\n TData extends RowData,\n>(row: Row<TFeatures, TData>) {\n const options = row.table.options\n if (typeof options.enableSubRowSelection === 'function') {\n return options.enableSubRowSelection(row)\n }\n\n return options.enableSubRowSelection ?? true\n}\n\n/**\n * Checks whether this row can be selected alongside other rows.\n *\n * `options.enableMultiRowSelection` may be a boolean or a row predicate; it\n * defaults to `true`.\n *\n * @example\n * ```ts\n * const canMultiSelect = row_getCanMultiSelect(row)\n * ```\n */\nexport function row_getCanMultiSelect<\n TFeatures extends TableFeatures,\n TData extends RowData,\n>(row: Row<TFeatures, TData>) {\n const options = row.table.options\n if (typeof options.enableMultiRowSelection === 'function') {\n return options.enableMultiRowSelection(row)\n }\n\n return options.enableMultiRowSelection ?? true\n}\n\n/**\n * Creates a checkbox-style handler that selects or deselects this row.\n *\n * The handler is a no-op when the row cannot be selected and reads\n * `event.target.checked`.\n *\n * @example\n * ```ts\n * const onChange = row_getToggleSelectedHandler(row)\n * ```\n */\nexport function row_getToggleSelectedHandler<\n TFeatures extends TableFeatures,\n TData extends RowData,\n>(row: Row<TFeatures, TData>) {\n const canSelect = row_getCanSelect(row)\n\n return (e: unknown) => {\n if (!canSelect) return\n row_toggleSelected(\n row,\n ((e as MouseEvent).target as HTMLInputElement).checked,\n )\n }\n}\n\nconst mutateRowIsSelected = <\n TFeatures extends TableFeatures,\n TData extends RowData,\n>(\n rowSelection: RowSelectionState,\n rowId: string,\n value: boolean,\n includeChildren: boolean,\n table: Table_Internal<TFeatures, TData>,\n): void => {\n const row = table.getRow(rowId, true)\n\n if (value) {\n if (!row_getCanMultiSelect(row)) {\n Object.keys(rowSelection).forEach((key) => delete rowSelection[key])\n }\n if (row_getCanSelect(row)) {\n rowSelection[rowId] = true\n }\n } else {\n delete rowSelection[rowId]\n }\n\n if (includeChildren && row.subRows.length && row_getCanSelectSubRows(row)) {\n row.subRows.forEach((r) =>\n mutateRowIsSelected(rowSelection, r.id, value, includeChildren, table),\n )\n }\n}\n\n/**\n * Builds a row model containing rows selected by the current row selection state.\n *\n * The result is derived from the supplied row model, so selected ids absent from\n * that model are not materialized as rows.\n *\n * @example\n * ```ts\n * const selectedRows = selectRowsFn(rowModel)\n * ```\n */\nexport function selectRowsFn<\n TFeatures extends TableFeatures,\n TData extends RowData,\n>(\n rowModel: RowModel<TFeatures, TData>,\n table: Table_Internal<TFeatures, TData>,\n): RowModel<TFeatures, TData> {\n const newSelectedFlatRows: Array<Row<TFeatures, TData>> = []\n const newSelectedRowsById = makeObjectMap<Row<TFeatures, TData>>()\n const rowSelection = table.atoms.rowSelection?.get() ?? {}\n // Filters top level and nested rows.\n const recurseRows = (\n rows: Array<Row<TFeatures, TData>>,\n depth = 0,\n ): Array<Row<TFeatures, TData>> => {\n const result: Array<Row<TFeatures, TData>> = []\n for (let i = 0; i < rows.length; i++) {\n const row = rows[i]!\n const isSelected = isRowSelected(row, rowSelection)\n\n if (isSelected) {\n newSelectedFlatRows.push(row)\n newSelectedRowsById[row.id] = row\n }\n\n if (row.subRows.length) {\n // Always recurse — selected descendants of unselected parents must\n // still be collected into flatRows/rowsById.\n const newSubRows = recurseRows(row.subRows, depth + 1)\n\n if (isSelected) {\n // Preserve prototype chain so methods like getValue() remain accessible\n const cloned = Object.create(Object.getPrototypeOf(row))\n Object.assign(cloned, row)\n cloned.subRows = newSubRows\n result.push(cloned)\n }\n } else if (isSelected) {\n result.push(row)\n }\n }\n return result\n }\n\n return {\n rows: recurseRows(rowModel.rows),\n flatRows: newSelectedFlatRows,\n rowsById: newSelectedRowsById,\n }\n}\n\n/**\n * Returns whether a row id is selected in the current row selection state.\n *\n * @example\n * ```ts\n * const selected = isRowSelected(row)\n * ```\n */\nexport function isRowSelected<\n TFeatures extends TableFeatures,\n TData extends RowData,\n>(row: Row<TFeatures, TData>, rowSelection: RowSelectionState): boolean {\n return !!(hasOwn(rowSelection, row.id) && rowSelection[row.id])\n}\n\n/**\n * Returns whether all, some, or none of a row's selectable descendants are selected.\n *\n * The result is used to drive indeterminate row selection UI.\n *\n * @example\n * ```ts\n * const selectedState = isSubRowSelected(row)\n * ```\n */\nexport function isSubRowSelected<\n TFeatures extends TableFeatures,\n TData extends RowData,\n>(row: Row<TFeatures, TData>): boolean | 'some' | 'all' {\n if (!row.subRows.length) return false\n\n const rowSelection = row.table.atoms.rowSelection?.get() ?? {}\n\n let someSelected = false\n let allChildrenSelected = true\n\n for (let i = 0; i < row.subRows.length; i++) {\n const subRow = row.subRows[i]!\n\n // Bail out early if we know both of these\n if (someSelected && !allChildrenSelected) {\n break\n }\n\n if (row_getCanSelect(subRow)) {\n if (isRowSelected(subRow, rowSelection)) {\n someSelected = true\n } else {\n allChildrenSelected = false\n }\n }\n\n // Check row selection of nested subrows\n if (subRow.subRows.length) {\n const subRowChildrenSelected = isSubRowSelected(subRow)\n if (subRowChildrenSelected === 'all') {\n someSelected = true\n } else if (subRowChildrenSelected === 'some') {\n someSelected = true\n allChildrenSelected = false\n } else {\n allChildrenSelected = false\n }\n }\n }\n\n return allChildrenSelected ? 'all' : someSelected ? 'some' : false\n}\n"],"mappings":";;;;;;;;;;;;;;AA0BA,SAAgB,8BAAiD;CAC/D,OAAO,cAAc;AACvB;;;;;;;;;;;;AAaA,SAAgB,sBAId,OACA,SACA;CACA,MAAM,QAAQ,uBAAuB,OAAO;AAC9C;;;;;;;;;;;;;AAcA,SAAgB,wBAGd,OAAyC,cAAwB;CACjE,sBACE,OACA,eACI,cAAc,IACd,OAAO,OACL,cAAoB,GACpB,WAAW,MAAM,aAAa,gBAAgB,CAAC,CAAC,CAClD,CACN;AACF;;;;;;;;;;;;AAeA,SAAgB,4BAId,OACA,OACA,MACA;CACA,sBAAsB,QAAQ,QAAQ;EACpC,QACE,OAAO,UAAU,cACb,QACA,CAAC,mBACC,OACA,wBACA,0BACF;EAEN,IAAI,MAAM,eAAe,CAAC,OAExB,OAAO,cAAoB;EAG7B,MAAM,eAAe,OAAO,OAAO,cAAoB,GAAG,GAAG;EAC7D,MAAM,qBAAqB,MAAM,sBAAsB,CAAC,CAAC;EAIzD,IAAI,OACF,mBAAmB,SAAS,QAAQ;GAClC,IAAI,iBAAiB,GAAG,GACtB,aAAa,IAAI,MAAM;EAE3B,CAAC;OAED,mBAAmB,SAAS,QAAQ;GAClC,OAAO,aAAa,IAAI;EAC1B,CAAC;EAGH,OAAO;CACT,CAAC;AACH;;;;;;;;;;;;AAaA,SAAgB,gCAId,OACA,OACA,MACA;CACA,sBAAsB,QAAQ,QAAQ;EACpC,MAAM,gBACJ,OAAO,UAAU,cACb,QACA,CAAC,mBACC,OACA,4BACA,8BACF;EAEN,IAAI,MAAM,eAAe,CAAC,eAExB,OAAO,cAAoB;EAG7B,MAAM,eAAkC,OAAO,OAC7C,cAAoB,GACpB,GACF;EAEA,MAAM,YAAY,CAAC,CAAC,KAAK,SAAS,QAAQ;GAC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AE1B,KAAK,IAAI,IAAI,GAAG,IAAI,IAAI,QAAQ,QAAQ,KAAK;EAC3C,MAAM,SAAS,IAAI,QAAQ;EAG3B,IAAI,gBAAgB,CAAC,qBACnB;EAGF,IAAI,iBAAiB,MAAM,GACzB,IAAI,cAAc,QAAQ,YAAY,GACpC,eAAe;OAEf,sBAAsB;EAK1B,IAAI,OAAO,QAAQ,QAAQ;GACzB,MAAM,yBAAyB,iBAAiB,MAAM;GACtD,IAAI,2BAA2B,OAC7B,eAAe;QACV,IAAI,2BAA2B,QAAQ;IAC5C,eAAe;IACf,sBAAsB;GACxB,OACE,sBAAsB;EAE1B;CACF;CAEA,OAAO,sBAAsB,QAAQ,eAAe,SAAS;AAC/D"}
1
+ {"version":3,"file":"rowSelectionFeature.utils.js","names":[],"sources":["../../../src/features/row-selection/rowSelectionFeature.utils.ts"],"sourcesContent":["import {\n callMemoOrStaticFn,\n cloneState,\n copyInstancePropertiesWithoutMemos,\n hasOwn,\n makeObjectMap,\n} from '../../utils'\nimport type { RowData, Updater } from '../../types/type-utils'\nimport type { TableFeatures } from '../../types/TableFeatures'\nimport type { RowModel } from '../../core/row-models/coreRowModelsFeature.types'\nimport type { Table_Internal } from '../../types/Table'\nimport type { Row } from '../../types/Row'\nimport type { RowSelectionState } from './rowSelectionFeature.types'\n\n// State APIs\n\n/**\n * Creates the default row selection state.\n *\n * The feature default is an empty map, meaning no rows are selected. Reset APIs\n * use this value when `defaultState` is `true`.\n *\n * @example\n * ```ts\n * const selection = getDefaultRowSelectionState()\n * ```\n */\nexport function getDefaultRowSelectionState(): RowSelectionState {\n return makeObjectMap()\n}\n\n/**\n * Routes a row selection updater through the table's selection change handler.\n *\n * The updater may be a next selection map or a function of the previous map,\n * matching the instance `table.setRowSelection` behavior.\n *\n * @example\n * ```ts\n * table_setRowSelection(table, (old) => ({ ...old, [rowId]: true }))\n * ```\n */\nexport function table_setRowSelection<\n TFeatures extends TableFeatures,\n TData extends RowData,\n>(\n table: Table_Internal<TFeatures, TData>,\n updater: Updater<RowSelectionState>,\n) {\n table.options.onRowSelectionChange?.(updater)\n}\n\n/**\n * Resets `rowSelection` to the configured initial state or feature default.\n *\n * With no argument, the reset clones `table.initialState.rowSelection` when it\n * exists. Passing `true` ignores initial state and resets to `{}`.\n *\n * @example\n * ```ts\n * table_resetRowSelection(table)\n * table_resetRowSelection(table, true)\n * ```\n */\nexport function table_resetRowSelection<\n TFeatures extends TableFeatures,\n TData extends RowData,\n>(table: Table_Internal<TFeatures, TData>, defaultState?: boolean) {\n table_setRowSelection(\n table,\n defaultState\n ? makeObjectMap()\n : Object.assign(\n makeObjectMap<true>(),\n cloneState(table.initialState.rowSelection ?? {}),\n ),\n )\n}\n\n// Table APIs\n\n/**\n * Selects or deselects every selectable row before grouping.\n *\n * Omitting `value` toggles based on `table_getIsAllRowsSelected(table)`.\n * Deselecting removes matching ids from the existing selection map.\n *\n * @example\n * ```ts\n * table_toggleAllRowsSelected(table)\n * ```\n */\nexport function table_toggleAllRowsSelected<\n TFeatures extends TableFeatures,\n TData extends RowData,\n>(\n table: Table_Internal<TFeatures, TData>,\n value?: boolean,\n opts?: { deselectAll?: boolean },\n) {\n table_setRowSelection(table, (old) => {\n value =\n typeof value !== 'undefined'\n ? value\n : !callMemoOrStaticFn(\n table,\n 'getIsAllRowsSelected',\n table_getIsAllRowsSelected,\n )\n\n if (opts?.deselectAll && !value) {\n // deselectAll opt: clear the whole selection map instead of deleting ids one-by-one\n return makeObjectMap<true>()\n }\n\n const rowSelection = Object.assign(makeObjectMap<true>(), old)\n const preGroupedFlatRows = table.getPreGroupedRowModel().flatRows\n\n // We don't use `mutateRowIsSelected` here for performance reasons.\n // All of the rows are flat already, so it wouldn't be worth it\n if (value) {\n preGroupedFlatRows.forEach((row) => {\n if (row_getCanSelect(row)) {\n rowSelection[row.id] = true\n }\n })\n } else {\n preGroupedFlatRows.forEach((row) => {\n delete rowSelection[row.id]\n })\n }\n\n return rowSelection\n })\n}\n\n/**\n * Selects or deselects every selectable row on the current page.\n *\n * Omitting `value` toggles based on `table_getIsAllPageRowsSelected(table)`.\n * Child rows are included when sub-row selection allows it.\n *\n * @example\n * ```ts\n * table_toggleAllPageRowsSelected(table)\n * ```\n */\nexport function table_toggleAllPageRowsSelected<\n TFeatures extends TableFeatures,\n TData extends RowData,\n>(\n table: Table_Internal<TFeatures, TData>,\n value?: boolean,\n opts?: { deselectAll?: boolean },\n) {\n table_setRowSelection(table, (old) => {\n const resolvedValue =\n typeof value !== 'undefined'\n ? value\n : !callMemoOrStaticFn(\n table,\n 'getIsAllPageRowsSelected',\n table_getIsAllPageRowsSelected,\n )\n\n if (opts?.deselectAll && !resolvedValue) {\n // deselectAll opt: clear the whole selection map instead of deleting ids one-by-one\n return makeObjectMap<true>()\n }\n\n const rowSelection: RowSelectionState = Object.assign(\n makeObjectMap<true>(),\n old,\n )\n\n table.getRowModel().rows.forEach((row) => {\n mutateRowIsSelected(rowSelection, row.id, resolvedValue, true, table)\n })\n\n return rowSelection\n })\n}\n\n/**\n * Reads the row model before row selection is projected into selected rows.\n *\n * Selection does not alter the base row pipeline, so this returns the core row\n * model.\n *\n * @example\n * ```ts\n * const rowsBeforeSelection = table_getPreSelectedRowModel(table)\n * ```\n */\nexport function table_getPreSelectedRowModel<\n TFeatures extends TableFeatures,\n TData extends RowData,\n>(table: Table_Internal<TFeatures, TData>): RowModel<TFeatures, TData> {\n return table.getCoreRowModel()\n}\n\n/**\n * Builds a row model containing selected rows from the core row model.\n *\n * If no row ids are selected, an empty row model is returned without walking\n * the rows.\n *\n * @example\n * ```ts\n * const selectedRows = table_getSelectedRowModel(table)\n * ```\n */\nexport function table_getSelectedRowModel<\n TFeatures extends TableFeatures,\n TData extends RowData,\n>(table: Table_Internal<TFeatures, TData>) {\n const rowModel = table.getCoreRowModel()\n\n if (\n !callMemoOrStaticFn(\n table,\n 'getIsSomeRowsSelected',\n table_getIsSomeRowsSelected,\n )\n ) {\n return {\n rows: [],\n flatRows: [],\n rowsById: makeObjectMap(),\n }\n }\n\n return selectRowsFn(rowModel, table)\n}\n\n/**\n * Builds a row model containing selected rows from the filtered row model.\n *\n * If no row ids are selected, an empty row model is returned without walking\n * the rows.\n *\n * @example\n * ```ts\n * const selectedRows = table_getFilteredSelectedRowModel(table)\n * ```\n */\nexport function table_getFilteredSelectedRowModel<\n TFeatures extends TableFeatures,\n TData extends RowData,\n>(table: Table_Internal<TFeatures, TData>) {\n const rowModel = table.getFilteredRowModel()\n\n if (\n !callMemoOrStaticFn(\n table,\n 'getIsSomeRowsSelected',\n table_getIsSomeRowsSelected,\n )\n ) {\n return {\n rows: [],\n flatRows: [],\n rowsById: makeObjectMap(),\n }\n }\n\n return selectRowsFn(rowModel, table)\n}\n\n/**\n * Builds a row model containing selected rows from the grouped row model.\n *\n * If no row ids are selected, an empty row model is returned without walking\n * the rows.\n *\n * @example\n * ```ts\n * const selectedRows = table_getGroupedSelectedRowModel(table)\n * ```\n */\nexport function table_getGroupedSelectedRowModel<\n TFeatures extends TableFeatures,\n TData extends RowData,\n>(table: Table_Internal<TFeatures, TData>) {\n // The sorted model falls back grouped -> filtered -> core when those\n // features are not registered, so selected group rows are always visible.\n const rowModel = table.getSortedRowModel()\n\n if (\n !callMemoOrStaticFn(\n table,\n 'getIsSomeRowsSelected',\n table_getIsSomeRowsSelected,\n )\n ) {\n return {\n rows: [],\n flatRows: [],\n rowsById: makeObjectMap(),\n }\n }\n\n return selectRowsFn(rowModel, table)\n}\n\n/**\n * Returns the ids of all selected rows.\n *\n * @example\n * ```ts\n * const selectedRowIds = table_getSelectedRowIds(table)\n * ```\n */\nexport function table_getSelectedRowIds<\n TFeatures extends TableFeatures,\n TData extends RowData,\n>(table: Table_Internal<TFeatures, TData>): Array<string> {\n return Object.keys(table.atoms.rowSelection?.get() ?? {})\n}\n\n/**\n * Checks whether every selectable filtered row is selected.\n *\n * The result is false when there are no filtered rows or when selection state is\n * empty.\n *\n * @example\n * ```ts\n * const allSelected = table_getIsAllRowsSelected(table)\n * ```\n */\nexport function table_getIsAllRowsSelected<\n TFeatures extends TableFeatures,\n TData extends RowData,\n>(table: Table_Internal<TFeatures, TData>) {\n const preGroupedFlatRows = table.getFilteredRowModel().flatRows\n const rowSelection = table.atoms.rowSelection?.get() ?? {}\n\n let isAllRowsSelected = Boolean(\n preGroupedFlatRows.length && Object.keys(rowSelection).length,\n )\n\n if (isAllRowsSelected) {\n if (\n preGroupedFlatRows.some(\n (row) => row_getCanSelect(row) && !isRowSelected(row, rowSelection),\n )\n ) {\n isAllRowsSelected = false\n }\n }\n\n return isAllRowsSelected\n}\n\n/**\n * Checks whether every selectable row on the current page is selected.\n *\n * Non-selectable rows are ignored for this calculation.\n *\n * @example\n * ```ts\n * const allPageRowsSelected = table_getIsAllPageRowsSelected(table)\n * ```\n */\nexport function table_getIsAllPageRowsSelected<\n TFeatures extends TableFeatures,\n TData extends RowData,\n>(table: Table_Internal<TFeatures, TData>) {\n const paginationFlatRows = table\n .getPaginatedRowModel()\n .flatRows.filter((row) => row_getCanSelect(row))\n const rowSelection = table.atoms.rowSelection?.get() ?? {}\n\n let isAllPageRowsSelected = !!paginationFlatRows.length\n\n if (\n isAllPageRowsSelected &&\n paginationFlatRows.some((row) => !isRowSelected(row, rowSelection))\n ) {\n isAllPageRowsSelected = false\n }\n\n return isAllPageRowsSelected\n}\n\n/**\n * Checks whether selection is partially applied across filtered rows.\n *\n * The result is true when at least one row id is selected\n *\n * @example\n * ```ts\n * const someRowsSelected = table_getIsSomeRowsSelected(table)\n * ```\n */\nexport function table_getIsSomeRowsSelected<\n TFeatures extends TableFeatures,\n TData extends RowData,\n>(table: Table_Internal<TFeatures, TData>) {\n return (\n callMemoOrStaticFn(table, 'getSelectedRowIds', table_getSelectedRowIds)\n .length > 0\n )\n}\n\n/**\n * Checks whether the current page has a partial selection.\n *\n * @example\n * ```ts\n * const somePageRowsSelected = table_getIsSomePageRowsSelected(table)\n * ```\n */\nexport function table_getIsSomePageRowsSelected<\n TFeatures extends TableFeatures,\n TData extends RowData,\n>(table: Table_Internal<TFeatures, TData>) {\n return table\n .getPaginatedRowModel()\n .flatRows.filter((row) => row_getCanSelect(row))\n .some(\n (row) =>\n row_getIsSelected(row) ||\n callMemoOrStaticFn(row, 'getIsSomeSelected', row_getIsSomeSelected),\n )\n}\n\n/**\n * Creates a checkbox-style handler that selects or deselects all rows.\n *\n * The handler reads `event.target.checked`, so it is intended for controls whose\n * checked state means \"all rows selected\".\n *\n * @example\n * ```ts\n * const onChange = table_getToggleAllRowsSelectedHandler(table)\n * ```\n */\nexport function table_getToggleAllRowsSelectedHandler<\n TFeatures extends TableFeatures,\n TData extends RowData,\n>(table: Table_Internal<TFeatures, TData>) {\n return (e: unknown) => {\n table_toggleAllRowsSelected(\n table,\n ((e as MouseEvent).target as HTMLInputElement).checked,\n )\n }\n}\n\n/**\n * Creates a checkbox-style handler that selects or deselects current page rows.\n *\n * The handler reads `event.target.checked`, so it is intended for controls whose\n * checked state means \"all page rows selected\".\n *\n * @example\n * ```ts\n * const onChange = table_getToggleAllPageRowsSelectedHandler(table)\n * ```\n */\nexport function table_getToggleAllPageRowsSelectedHandler<\n TFeatures extends TableFeatures,\n TData extends RowData,\n>(table: Table_Internal<TFeatures, TData>) {\n return (e: unknown) => {\n table_toggleAllPageRowsSelected(\n table,\n ((e as MouseEvent).target as HTMLInputElement).checked,\n )\n }\n}\n\n// Row APIs\n\n/**\n * Selects or deselects this row.\n *\n * Omitting `value` toggles the row. Child rows are selected recursively unless\n * `opts.selectChildren` is `false` or sub-row selection is disabled.\n *\n * @example\n * ```ts\n * row_toggleSelected(row)\n * row_toggleSelected(row, true)\n * row_toggleSelected(row, false)\n * row_toggleSelected(row, true, { selectChildren: false })\n * row_toggleSelected(row, false, { selectChildren: false })\n * ```\n */\nexport function row_toggleSelected<\n TFeatures extends TableFeatures,\n TData extends RowData,\n>(\n row: Row<TFeatures, TData>,\n value?: boolean,\n opts?: {\n selectChildren?: boolean\n },\n) {\n const isSelected = row_getIsSelected(row)\n\n table_setRowSelection(row.table, (old) => {\n value = typeof value !== 'undefined' ? value : !isSelected\n\n const rowSelection = Object.assign(makeObjectMap<true>(), old)\n\n mutateRowIsSelected(\n rowSelection,\n row.id,\n value,\n opts?.selectChildren ?? true,\n row.table,\n )\n\n return rowSelection\n })\n}\n\n/**\n * Checks whether this row id is selected in `state.rowSelection`.\n *\n * Missing row ids are treated as not selected.\n *\n * @example\n * ```ts\n * const selected = row_getIsSelected(row)\n * ```\n */\nexport function row_getIsSelected<\n TFeatures extends TableFeatures,\n TData extends RowData,\n>(row: Row<TFeatures, TData>) {\n const rowSelection = row.table.atoms.rowSelection?.get() ?? {}\n return isRowSelected(row, rowSelection)\n}\n\n/**\n * Checks whether some, but not all, selectable descendants are selected.\n *\n * This supports indeterminate selection UI for parent rows.\n *\n * @example\n * ```ts\n * const partial = row_getIsSomeSelected(row)\n * ```\n */\nexport function row_getIsSomeSelected<\n TFeatures extends TableFeatures,\n TData extends RowData,\n>(row: Row<TFeatures, TData>) {\n return isSubRowSelected(row) === 'some'\n}\n\n/**\n * Checks whether all selectable descendants are selected.\n *\n * Rows without selectable descendants return false.\n *\n * @example\n * ```ts\n * const allChildrenSelected = row_getIsAllSubRowsSelected(row)\n * ```\n */\nexport function row_getIsAllSubRowsSelected<\n TFeatures extends TableFeatures,\n TData extends RowData,\n>(row: Row<TFeatures, TData>) {\n return isSubRowSelected(row) === 'all'\n}\n\n/**\n * Checks whether this row can be selected.\n *\n * `options.enableRowSelection` may be a boolean or a row predicate; it defaults\n * to `true`.\n *\n * @example\n * ```ts\n * const canSelect = row_getCanSelect(row)\n * ```\n */\nexport function row_getCanSelect<\n TFeatures extends TableFeatures,\n TData extends RowData,\n>(row: Row<TFeatures, TData>) {\n const options = row.table.options\n if (typeof options.enableRowSelection === 'function') {\n return options.enableRowSelection(row)\n }\n\n return options.enableRowSelection ?? true\n}\n\n/**\n * Checks whether selecting this row should also select its subRows.\n *\n * `options.enableSubRowSelection` may be a boolean or a row predicate; it\n * defaults to `true`.\n *\n * @example\n * ```ts\n * const canSelectChildren = row_getCanSelectSubRows(row)\n * ```\n */\nexport function row_getCanSelectSubRows<\n TFeatures extends TableFeatures,\n TData extends RowData,\n>(row: Row<TFeatures, TData>) {\n const options = row.table.options\n if (typeof options.enableSubRowSelection === 'function') {\n return options.enableSubRowSelection(row)\n }\n\n return options.enableSubRowSelection ?? true\n}\n\n/**\n * Checks whether this row can be selected alongside other rows.\n *\n * `options.enableMultiRowSelection` may be a boolean or a row predicate; it\n * defaults to `true`.\n *\n * @example\n * ```ts\n * const canMultiSelect = row_getCanMultiSelect(row)\n * ```\n */\nexport function row_getCanMultiSelect<\n TFeatures extends TableFeatures,\n TData extends RowData,\n>(row: Row<TFeatures, TData>) {\n const options = row.table.options\n if (typeof options.enableMultiRowSelection === 'function') {\n return options.enableMultiRowSelection(row)\n }\n\n return options.enableMultiRowSelection ?? true\n}\n\n/**\n * Creates a checkbox-style handler that selects or deselects this row.\n *\n * The handler is a no-op when the row cannot be selected and reads\n * `event.target.checked`.\n *\n * @example\n * ```ts\n * const onChange = row_getToggleSelectedHandler(row)\n * ```\n */\nexport function row_getToggleSelectedHandler<\n TFeatures extends TableFeatures,\n TData extends RowData,\n>(row: Row<TFeatures, TData>) {\n const canSelect = row_getCanSelect(row)\n\n return (e: unknown) => {\n if (!canSelect) return\n row_toggleSelected(\n row,\n ((e as MouseEvent).target as HTMLInputElement).checked,\n )\n }\n}\n\nconst mutateRowIsSelected = <\n TFeatures extends TableFeatures,\n TData extends RowData,\n>(\n rowSelection: RowSelectionState,\n rowId: string,\n value: boolean,\n includeChildren: boolean,\n table: Table_Internal<TFeatures, TData>,\n): void => {\n const row = table.getRow(rowId, true)\n\n if (value) {\n if (!row_getCanMultiSelect(row)) {\n Object.keys(rowSelection).forEach((key) => delete rowSelection[key])\n }\n if (row_getCanSelect(row)) {\n rowSelection[rowId] = true\n }\n } else {\n delete rowSelection[rowId]\n }\n\n if (includeChildren && row.subRows.length && row_getCanSelectSubRows(row)) {\n row.subRows.forEach((r) =>\n mutateRowIsSelected(rowSelection, r.id, value, includeChildren, table),\n )\n }\n}\n\n/**\n * Builds a row model containing rows selected by the current row selection state.\n *\n * The result is derived from the supplied row model, so selected ids absent from\n * that model are not materialized as rows.\n *\n * @example\n * ```ts\n * const selectedRows = selectRowsFn(rowModel)\n * ```\n */\nexport function selectRowsFn<\n TFeatures extends TableFeatures,\n TData extends RowData,\n>(\n rowModel: RowModel<TFeatures, TData>,\n table: Table_Internal<TFeatures, TData>,\n): RowModel<TFeatures, TData> {\n const newSelectedFlatRows: Array<Row<TFeatures, TData>> = []\n const newSelectedRowsById = makeObjectMap<Row<TFeatures, TData>>()\n const rowSelection = table.atoms.rowSelection?.get() ?? {}\n // Filters top level and nested rows.\n const recurseRows = (\n rows: Array<Row<TFeatures, TData>>,\n depth = 0,\n ): Array<Row<TFeatures, TData>> => {\n const result: Array<Row<TFeatures, TData>> = []\n for (let i = 0; i < rows.length; i++) {\n const row = rows[i]!\n const isSelected = isRowSelected(row, rowSelection)\n\n if (isSelected) {\n newSelectedFlatRows.push(row)\n newSelectedRowsById[row.id] = row\n }\n\n if (row.subRows.length) {\n // Always recurse — selected descendants of unselected parents must\n // still be collected into flatRows/rowsById.\n const newSubRows = recurseRows(row.subRows, depth + 1)\n\n if (isSelected) {\n // Preserve prototype chain so methods like getValue() remain accessible\n const cloned = Object.create(Object.getPrototypeOf(row))\n copyInstancePropertiesWithoutMemos(cloned, row)\n cloned.subRows = newSubRows\n result.push(cloned)\n }\n } else if (isSelected) {\n result.push(row)\n }\n }\n return result\n }\n\n return {\n rows: recurseRows(rowModel.rows),\n flatRows: newSelectedFlatRows,\n rowsById: newSelectedRowsById,\n }\n}\n\n/**\n * Returns whether a row id is selected in the current row selection state.\n *\n * @example\n * ```ts\n * const selected = isRowSelected(row)\n * ```\n */\nexport function isRowSelected<\n TFeatures extends TableFeatures,\n TData extends RowData,\n>(row: Row<TFeatures, TData>, rowSelection: RowSelectionState): boolean {\n return !!(hasOwn(rowSelection, row.id) && rowSelection[row.id])\n}\n\n/**\n * Returns whether all, some, or none of a row's selectable descendants are selected.\n *\n * The result is used to drive indeterminate row selection UI.\n *\n * @example\n * ```ts\n * const selectedState = isSubRowSelected(row)\n * ```\n */\nexport function isSubRowSelected<\n TFeatures extends TableFeatures,\n TData extends RowData,\n>(row: Row<TFeatures, TData>): boolean | 'some' | 'all' {\n if (!row.subRows.length) return false\n\n const rowSelection = row.table.atoms.rowSelection?.get() ?? {}\n\n let someSelected = false\n let allChildrenSelected = true\n\n for (let i = 0; i < row.subRows.length; i++) {\n const subRow = row.subRows[i]!\n\n // Bail out early if we know both of these\n if (someSelected && !allChildrenSelected) {\n break\n }\n\n if (row_getCanSelect(subRow)) {\n if (isRowSelected(subRow, rowSelection)) {\n someSelected = true\n } else {\n allChildrenSelected = false\n }\n }\n\n // Check row selection of nested subrows\n if (subRow.subRows.length) {\n const subRowChildrenSelected = isSubRowSelected(subRow)\n if (subRowChildrenSelected === 'all') {\n someSelected = true\n } else if (subRowChildrenSelected === 'some') {\n someSelected = true\n allChildrenSelected = false\n } else {\n allChildrenSelected = false\n }\n }\n }\n\n return allChildrenSelected ? 'all' : someSelected ? 'some' : false\n}\n"],"mappings":";;;;;;;;;;;;;;AA2BA,SAAgB,8BAAiD;CAC/D,OAAO,cAAc;AACvB;;;;;;;;;;;;AAaA,SAAgB,sBAId,OACA,SACA;CACA,MAAM,QAAQ,uBAAuB,OAAO;AAC9C;;;;;;;;;;;;;AAcA,SAAgB,wBAGd,OAAyC,cAAwB;CACjE,sBACE,OACA,eACI,cAAc,IACd,OAAO,OACL,cAAoB,GACpB,WAAW,MAAM,aAAa,gBAAgB,CAAC,CAAC,CAClD,CACN;AACF;;;;;;;;;;;;AAeA,SAAgB,4BAId,OACA,OACA,MACA;CACA,sBAAsB,QAAQ,QAAQ;EACpC,QACE,OAAO,UAAU,cACb,QACA,CAAC,mBACC,OACA,wBACA,0BACF;EAEN,IAAI,MA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,YAAY,IAAI,SAAS,QAAQ,CAAC;IAErD,IAAI,YAAY;KAEd,MAAM,SAAS,OAAO,OAAO,OAAO,eAAe,GAAG,CAAC;KACvD,mCAAmC,QAAQ,GAAG;KAC9C,OAAO,UAAU;KACjB,OAAO,KAAK,MAAM;IACpB;GACF,OAAO,IAAI,YACT,OAAO,KAAK,GAAG;EAEnB;EACA,OAAO;CACT;CAEA,OAAO;EACL,MAAM,YAAY,SAAS,IAAI;EAC/B,UAAU;EACV,UAAU;CACZ;AACF;;;;;;;;;AAUA,SAAgB,cAGd,KAA4B,cAA0C;CACtE,OAAO,CAAC,EAAE,OAAO,cAAc,IAAI,EAAE,KAAK,aAAa,IAAI;AAC7D;;;;;;;;;;;AAYA,SAAgB,iBAGd,KAAsD;CACtD,IAAI,CAAC,IAAI,QAAQ,QAAQ,OAAO;CAEhC,MAAM,eAAe,IAAI,MAAM,MAAM,cAAc,IAAI,KAAK,CAAC;CAE7D,IAAI,eAAe;CACnB,IAAI,sBAAsB;CAE1B,KAAK,IAAI,IAAI,GAAG,IAAI,IAAI,QAAQ,QAAQ,KAAK;EAC3C,MAAM,SAAS,IAAI,QAAQ;EAG3B,IAAI,gBAAgB,CAAC,qBACnB;EAGF,IAAI,iBAAiB,MAAM,GACzB,IAAI,cAAc,QAAQ,YAAY,GACpC,eAAe;OAEf,sBAAsB;EAK1B,IAAI,OAAO,QAAQ,QAAQ;GACzB,MAAM,yBAAyB,iBAAiB,MAAM;GACtD,IAAI,2BAA2B,OAC7B,eAAe;QACV,IAAI,2BAA2B,QAAQ;IAC5C,eAAe;IACf,sBAAsB;GACxB,OACE,sBAAsB;EAE1B;CACF;CAEA,OAAO,sBAAsB,QAAQ,eAAe,SAAS;AAC/D"}
@@ -33,6 +33,7 @@ function _createSortedRowModel(table) {
33
33
  const column = table.getColumn(sort.id);
34
34
  return column ? require_rowSortingFeature_utils.column_getCanSort(column) : false;
35
35
  });
36
+ if (!availableSorting.length) return preSortedRowModel;
36
37
  const resolvedSorting = [];
37
38
  for (let i = 0; i < availableSorting.length; i++) {
38
39
  const sortEntry = availableSorting[i];
@@ -76,20 +77,29 @@ function _createSortedRowModel(table) {
76
77
  const sortData = (rows) => {
77
78
  const sortedData = rows.slice();
78
79
  sortedData.sort(compareRows);
80
+ let changed = false;
79
81
  for (let i = 0; i < sortedData.length; i++) {
80
82
  const row = sortedData[i];
83
+ if (row !== rows[i]) changed = true;
81
84
  if (row.subRows.length) {
82
- const cloned = Object.create(Object.getPrototypeOf(row));
83
- Object.assign(cloned, row);
84
- cloned.subRows = sortData(row.subRows);
85
- sortedData[i] = cloned;
86
- sortedFlatRows.push(cloned);
85
+ const sortedSubRows = sortData(row.subRows);
86
+ if (sortedSubRows.changed) {
87
+ const cloned = Object.create(Object.getPrototypeOf(row));
88
+ require_utils.copyInstancePropertiesWithoutMemos(cloned, row);
89
+ cloned.subRows = sortedSubRows.rows;
90
+ sortedData[i] = cloned;
91
+ sortedFlatRows.push(cloned);
92
+ changed = true;
93
+ } else sortedFlatRows.push(row);
87
94
  } else sortedFlatRows.push(row);
88
95
  }
89
- return sortedData;
96
+ return {
97
+ rows: sortedData,
98
+ changed
99
+ };
90
100
  };
91
101
  return {
92
- rows: sortData(preSortedRowModel.rows),
102
+ rows: sortData(preSortedRowModel.rows).rows,
93
103
  flatRows: sortedFlatRows,
94
104
  rowsById: preSortedRowModel.rowsById
95
105
  };
@@ -1 +1 @@
1
- {"version":3,"file":"createSortedRowModel.cjs","names":["tableMemo","table_autoResetPageIndex","column_getCanSort","column_getSortFn"],"sources":["../../../src/features/row-sorting/createSortedRowModel.ts"],"sourcesContent":["import { tableMemo } from '../../utils'\nimport { table_autoResetPageIndex } from '../row-pagination/rowPaginationFeature.utils'\nimport { column_getCanSort, column_getSortFn } from './rowSortingFeature.utils'\nimport type { Column_Internal } from '../../types/Column'\nimport type { TableFeatures } from '../../types/TableFeatures'\nimport type { RowModel } from '../../core/row-models/coreRowModelsFeature.types'\nimport type { Table, Table_Internal } from '../../types/Table'\nimport type { Row } from '../../types/Row'\nimport type { SortFn } from './rowSortingFeature.types'\nimport type { RowData } from '../../types/type-utils'\n\n/**\n * Creates a memoized sorted row model factory.\n *\n * The factory reads the relevant table state atoms and options, then returns a row model function used by the table row-model pipeline.\n *\n * Register sorting functions with the `sortFns` slot on the `features` option:\n * `tableFeatures({ rowSortingFeature, sortedRowModel: createSortedRowModel(), sortFns })`.\n */\nexport function createSortedRowModel<\n TFeatures extends TableFeatures,\n TData extends RowData,\n>(): (table: Table<TFeatures, TData>) => () => RowModel<TFeatures, TData> {\n return (_table) => {\n const table = _table as unknown as Table_Internal<TFeatures, TData>\n return tableMemo({\n feature: 'rowSortingFeature',\n table,\n fnName: 'table.getSortedRowModel',\n memoDeps: () => [\n table.atoms.sorting?.get(),\n table.getPreSortedRowModel(),\n ],\n fn: () => _createSortedRowModel(table),\n onAfterUpdate: () => table_autoResetPageIndex(table),\n })\n }\n}\n\nfunction _createSortedRowModel<\n TFeatures extends TableFeatures,\n TData extends RowData = any,\n>(table: Table_Internal<TFeatures, TData>): RowModel<TFeatures, TData> {\n const preSortedRowModel = table.getPreSortedRowModel()\n const sorting = table.atoms.sorting?.get()\n\n if (!preSortedRowModel.rows.length || !sorting?.length) {\n return preSortedRowModel\n }\n\n const sortedFlatRows: Array<Row<TFeatures, TData>> = []\n\n // Filter out sortings that correspond to non existing columns\n const availableSorting = sorting.filter((sort) => {\n const column = table.getColumn(sort.id)\n return column ? column_getCanSort(column) : false\n })\n\n const resolvedSorting: Array<{\n id: string\n desc?: boolean\n sortUndefined?: false | -1 | 1 | 'first' | 'last'\n invertSorting?: boolean\n sortFn: SortFn<TFeatures, TData>\n }> = []\n\n for (let i = 0; i < availableSorting.length; i++) {\n const sortEntry = availableSorting[i]!\n const column: Column_Internal<TFeatures, TData> | undefined =\n table.getColumn(sortEntry.id)\n if (!column) {\n continue\n }\n\n resolvedSorting.push({\n id: sortEntry.id,\n desc: sortEntry.desc,\n sortUndefined: column.columnDef.sortUndefined,\n invertSorting: column.columnDef.invertSorting,\n sortFn: column_getSortFn(column),\n })\n }\n\n const compareRows = (\n rowA: Row<TFeatures, TData>,\n rowB: Row<TFeatures, TData>,\n ) => {\n for (let i = 0; i < resolvedSorting.length; i++) {\n const sortEntry = resolvedSorting[i]!\n const sortUndefined = sortEntry.sortUndefined\n const isDesc = sortEntry.desc\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 continue\n }\n\n if (aUndefined || bUndefined) {\n if (sortUndefined === 'first') return aUndefined ? -1 : 1\n if (sortUndefined === 'last') return aUndefined ? 1 : -1\n sortInt = aUndefined ? sortUndefined : -sortUndefined\n }\n }\n\n if (sortInt === 0) {\n sortInt = sortEntry.sortFn(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 (sortEntry.invertSorting) {\n sortInt *= -1\n }\n\n return sortInt\n }\n }\n\n return rowA.index - rowB.index\n }\n\n const sortData = (rows: Array<Row<TFeatures, TData>>) => {\n const sortedData = rows.slice()\n\n sortedData.sort(compareRows)\n\n // If there are sub-rows, sort them. Clone only rows that need mutation\n // (i.e. have subRows) so we don't corrupt the source row model.\n for (let i = 0; i < sortedData.length; i++) {\n const row = sortedData[i]!\n if (row.subRows.length) {\n // Preserve prototype chain so methods like getValue() remain accessible\n const cloned = Object.create(Object.getPrototypeOf(row))\n Object.assign(cloned, row)\n cloned.subRows = sortData(row.subRows)\n sortedData[i] = cloned\n sortedFlatRows.push(cloned)\n } else {\n sortedFlatRows.push(row)\n }\n }\n\n return sortedData\n }\n\n return {\n rows: sortData(preSortedRowModel.rows),\n flatRows: sortedFlatRows,\n rowsById: preSortedRowModel.rowsById,\n }\n}\n"],"mapp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AW;IAC9B,MAAM,aAAa,WAAW;IAE9B,IAAI,cAAc,YAChB;IAGF,IAAI,cAAc,YAAY;KAC5B,IAAI,kBAAkB,SAAS,OAAO,aAAa,KAAK;KACxD,IAAI,kBAAkB,QAAQ,OAAO,aAAa,IAAI;KACtD,UAAU,aAAa,gBAAgB,CAAC;IAC1C;GACF;GAEA,IAAI,YAAY,GACd,UAAU,UAAU,OAAO,MAAM,MAAM,UAAU,EAAE;GAIrD,IAAI,YAAY,GAAG;IACjB,IAAI,QACF,WAAW;IAGb,IAAI,UAAU,eACZ,WAAW;IAGb,OAAO;GACT;EACF;EAEA,OAAO,KAAK,QAAQ,KAAK;CAC3B;CAEA,MAAM,YAAY,SAAuC;EACvD,MAAM,aAAa,KAAK,MAAM;EAE9B,WAAW,KAAK,WAAW;EAI3B,KAAK,IAAI,IAAI,GAAG,IAAI,WAAW,QAAQ,KAAK;GAC1C,MAAM,MAAM,WAAW;GACvB,IAAI,IAAI,QAAQ,QAAQ;IAEtB,MAAM,SAAS,OAAO,OAAO,OAAO,eAAe,GAAG,CAAC;IACvD,OAAO,OAAO,QAAQ,GAAG;IACzB,OAAO,UAAU,SAAS,IAAI,OAAO;IACrC,WAAW,KAAK;IAChB,eAAe,KAAK,MAAM;GAC5B,OACE,eAAe,KAAK,GAAG;EAE3B;EAEA,OAAO;CACT;CAEA,OAAO;EACL,MAAM,SAAS,kBAAkB,IAAI;EACrC,UAAU;EACV,UAAU,kBAAkB;CAC9B;AACF"}
1
+ {"version":3,"file":"createSortedRowModel.cjs","names":["tableMemo","table_autoResetPageIndex","column_getCanSort","column_getSortFn"],"sources":["../../../src/features/row-sorting/createSortedRowModel.ts"],"sourcesContent":["import { copyInstancePropertiesWithoutMemos, tableMemo } from '../../utils'\nimport { table_autoResetPageIndex } from '../row-pagination/rowPaginationFeature.utils'\nimport { column_getCanSort, column_getSortFn } from './rowSortingFeature.utils'\nimport type { Column_Internal } from '../../types/Column'\nimport type { TableFeatures } from '../../types/TableFeatures'\nimport type { RowModel } from '../../core/row-models/coreRowModelsFeature.types'\nimport type { Table, Table_Internal } from '../../types/Table'\nimport type { Row } from '../../types/Row'\nimport type { SortFn } from './rowSortingFeature.types'\nimport type { RowData } from '../../types/type-utils'\n\n/**\n * Creates a memoized sorted row model factory.\n *\n * The factory reads the relevant table state atoms and options, then returns a row model function used by the table row-model pipeline.\n *\n * Register sorting functions with the `sortFns` slot on the `features` option:\n * `tableFeatures({ rowSortingFeature, sortedRowModel: createSortedRowModel(), sortFns })`.\n */\nexport function createSortedRowModel<\n TFeatures extends TableFeatures,\n TData extends RowData,\n>(): (table: Table<TFeatures, TData>) => () => RowModel<TFeatures, TData> {\n return (_table) => {\n const table = _table as unknown as Table_Internal<TFeatures, TData>\n return tableMemo({\n feature: 'rowSortingFeature',\n table,\n fnName: 'table.getSortedRowModel',\n memoDeps: () => [\n table.atoms.sorting?.get(),\n table.getPreSortedRowModel(),\n ],\n fn: () => _createSortedRowModel(table),\n onAfterUpdate: () => table_autoResetPageIndex(table),\n })\n }\n}\n\nfunction _createSortedRowModel<\n TFeatures extends TableFeatures,\n TData extends RowData = any,\n>(table: Table_Internal<TFeatures, TData>): RowModel<TFeatures, TData> {\n const preSortedRowModel = table.getPreSortedRowModel()\n const sorting = table.atoms.sorting?.get()\n\n if (!preSortedRowModel.rows.length || !sorting?.length) {\n return preSortedRowModel\n }\n\n const sortedFlatRows: Array<Row<TFeatures, TData>> = []\n\n // Filter out sortings that correspond to non existing columns\n const availableSorting = sorting.filter((sort) => {\n const column = table.getColumn(sort.id)\n return column ? column_getCanSort(column) : false\n })\n\n if (!availableSorting.length) {\n return preSortedRowModel\n }\n\n const resolvedSorting: Array<{\n id: string\n desc?: boolean\n sortUndefined?: false | -1 | 1 | 'first' | 'last'\n invertSorting?: boolean\n sortFn: SortFn<TFeatures, TData>\n }> = []\n\n for (let i = 0; i < availableSorting.length; i++) {\n const sortEntry = availableSorting[i]!\n const column: Column_Internal<TFeatures, TData> | undefined =\n table.getColumn(sortEntry.id)\n if (!column) {\n continue\n }\n\n resolvedSorting.push({\n id: sortEntry.id,\n desc: sortEntry.desc,\n sortUndefined: column.columnDef.sortUndefined,\n invertSorting: column.columnDef.invertSorting,\n sortFn: column_getSortFn(column),\n })\n }\n\n const compareRows = (\n rowA: Row<TFeatures, TData>,\n rowB: Row<TFeatures, TData>,\n ) => {\n for (let i = 0; i < resolvedSorting.length; i++) {\n const sortEntry = resolvedSorting[i]!\n const sortUndefined = sortEntry.sortUndefined\n const isDesc = sortEntry.desc\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 continue\n }\n\n if (aUndefined || bUndefined) {\n if (sortUndefined === 'first') return aUndefined ? -1 : 1\n if (sortUndefined === 'last') return aUndefined ? 1 : -1\n sortInt = aUndefined ? sortUndefined : -sortUndefined\n }\n }\n\n if (sortInt === 0) {\n sortInt = sortEntry.sortFn(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 (sortEntry.invertSorting) {\n sortInt *= -1\n }\n\n return sortInt\n }\n }\n\n return rowA.index - rowB.index\n }\n\n const sortData = (\n rows: Array<Row<TFeatures, TData>>,\n ): {\n rows: Array<Row<TFeatures, TData>>\n changed: boolean\n } => {\n const sortedData = rows.slice()\n\n sortedData.sort(compareRows)\n let changed = false\n\n // If there are sub-rows, sort them. Clone only rows that need mutation\n // (i.e. have subRows) so we don't corrupt the source row model.\n for (let i = 0; i < sortedData.length; i++) {\n const row = sortedData[i]!\n if (row !== rows[i]) {\n changed = true\n }\n\n if (row.subRows.length) {\n const sortedSubRows = sortData(row.subRows)\n\n if (sortedSubRows.changed) {\n // Preserve prototype chain so methods like getValue() remain accessible\n const cloned = Object.create(Object.getPrototypeOf(row))\n copyInstancePropertiesWithoutMemos(cloned, row)\n cloned.subRows = sortedSubRows.rows\n sortedData[i] = cloned\n sortedFlatRows.push(cloned)\n changed = true\n } else {\n sortedFlatRows.push(row)\n }\n } else {\n sortedFlatRows.push(row)\n }\n }\n\n return { rows: sortedData, changed }\n }\n\n return {\n rows: sortData(preSortedRowModel.rows).rows,\n flatRows: sortedFlatRows,\n rowsById: preSortedRowModel.rowsById,\n }\n}\n"],"mappings":";;;;;;;;;;;;;AAmBA,SAAgB,uBAG0D;CACxE,QAAQ,WAAW;EACjB,MAAM,QAAQ;EACd,OAAOA,wBAAU;GACf,SAAS;GACT;GACA,QAAQ;GACR,gBAAgB,CACd,MAAM,MAAM,SAAS,IAAI,GACzB,MAAM,qBAAqB,CAC7B;GACA,UAAU,sBAAsB,KAAK;GACrC,qBAAqBC,4DAAyB,KAAK;EACrD,CAAC;CACH;AACF;AAEA,SAAS,sBAGP,OAAqE;CACrE,MAAM,oBAAoB,MAAM,qBAAqB;CACrD,MAAM,UAAU,MAAM,MAAM,SAAS,IAAI;CAEzC,IAAI,CAAC,kBAAkB,KAAK,UAAU,CAAC,SAAS,QAC9C,OAAO;CAGT,MAAM,iBAA+C,CAAC;CAGtD,MAAM,mBAAmB,QAAQ,QAAQ,SAAS;EAChD,MAAM,SAAS,MAAM,UAAU,KAAK,EAAE;EACtC,OAAO,SAASC,kDAAkB,MAAM,IAAI;CAC9C,CAAC;CAED,IAAI,CAAC,iBAAiB,QACpB,OAAO;CAGT,MAAM,kBAMD,CAAC;CAEN,KAAK,IAAI,IAAI,GAAG,IAAI,iBAAiB,QAAQ,KAAK;EAChD,MAAM,YAAY,iBAAiB;EACnC,MAAM,SACJ,MAAM,UAAU,UAAU,EAAE;EAC9B,IAAI,CAAC,QACH;EAGF,gBAAgB,KAAK;GACnB,IAAI,UAAU;GACd,MAAM,UAAU;GAChB,eAAe,OAAO,UAAU;GAChC,eAAe,OAAO,UAAU;GAChC,QAAQC,iD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,OACE,eAAe,KAAK,GAAG;GAE3B,OACE,eAAe,KAAK,GAAG;EAE3B;EAEA,OAAO;GAAE,MAAM;GAAY;EAAQ;CACrC;CAEA,OAAO;EACL,MAAM,SAAS,kBAAkB,IAAI,CAAC,CAAC;EACvC,UAAU;EACV,UAAU,kBAAkB;CAC9B;AACF"}
@@ -1,4 +1,4 @@
1
- import { tableMemo } from "../../utils.js";
1
+ import { copyInstancePropertiesWithoutMemos, tableMemo } from "../../utils.js";
2
2
  import { table_autoResetPageIndex } from "../row-pagination/rowPaginationFeature.utils.js";
3
3
  import { column_getCanSort, column_getSortFn } from "./rowSortingFeature.utils.js";
4
4
 
@@ -33,6 +33,7 @@ function _createSortedRowModel(table) {
33
33
  const column = table.getColumn(sort.id);
34
34
  return column ? column_getCanSort(column) : false;
35
35
  });
36
+ if (!availableSorting.length) return preSortedRowModel;
36
37
  const resolvedSorting = [];
37
38
  for (let i = 0; i < availableSorting.length; i++) {
38
39
  const sortEntry = availableSorting[i];
@@ -76,20 +77,29 @@ function _createSortedRowModel(table) {
76
77
  const sortData = (rows) => {
77
78
  const sortedData = rows.slice();
78
79
  sortedData.sort(compareRows);
80
+ let changed = false;
79
81
  for (let i = 0; i < sortedData.length; i++) {
80
82
  const row = sortedData[i];
83
+ if (row !== rows[i]) changed = true;
81
84
  if (row.subRows.length) {
82
- const cloned = Object.create(Object.getPrototypeOf(row));
83
- Object.assign(cloned, row);
84
- cloned.subRows = sortData(row.subRows);
85
- sortedData[i] = cloned;
86
- sortedFlatRows.push(cloned);
85
+ const sortedSubRows = sortData(row.subRows);
86
+ if (sortedSubRows.changed) {
87
+ const cloned = Object.create(Object.getPrototypeOf(row));
88
+ copyInstancePropertiesWithoutMemos(cloned, row);
89
+ cloned.subRows = sortedSubRows.rows;
90
+ sortedData[i] = cloned;
91
+ sortedFlatRows.push(cloned);
92
+ changed = true;
93
+ } else sortedFlatRows.push(row);
87
94
  } else sortedFlatRows.push(row);
88
95
  }
89
- return sortedData;
96
+ return {
97
+ rows: sortedData,
98
+ changed
99
+ };
90
100
  };
91
101
  return {
92
- rows: sortData(preSortedRowModel.rows),
102
+ rows: sortData(preSortedRowModel.rows).rows,
93
103
  flatRows: sortedFlatRows,
94
104
  rowsById: preSortedRowModel.rowsById
95
105
  };
@@ -1 +1 @@
1
- {"version":3,"file":"createSortedRowModel.js","names":[],"sources":["../../../src/features/row-sorting/createSortedRowModel.ts"],"sourcesContent":["import { tableMemo } from '../../utils'\nimport { table_autoResetPageIndex } from '../row-pagination/rowPaginationFeature.utils'\nimport { column_getCanSort, column_getSortFn } from './rowSortingFeature.utils'\nimport type { Column_Internal } from '../../types/Column'\nimport type { TableFeatures } from '../../types/TableFeatures'\nimport type { RowModel } from '../../core/row-models/coreRowModelsFeature.types'\nimport type { Table, Table_Internal } from '../../types/Table'\nimport type { Row } from '../../types/Row'\nimport type { SortFn } from './rowSortingFeature.types'\nimport type { RowData } from '../../types/type-utils'\n\n/**\n * Creates a memoized sorted row model factory.\n *\n * The factory reads the relevant table state atoms and options, then returns a row model function used by the table row-model pipeline.\n *\n * Register sorting functions with the `sortFns` slot on the `features` option:\n * `tableFeatures({ rowSortingFeature, sortedRowModel: createSortedRowModel(), sortFns })`.\n */\nexport function createSortedRowModel<\n TFeatures extends TableFeatures,\n TData extends RowData,\n>(): (table: Table<TFeatures, TData>) => () => RowModel<TFeatures, TData> {\n return (_table) => {\n const table = _table as unknown as Table_Internal<TFeatures, TData>\n return tableMemo({\n feature: 'rowSortingFeature',\n table,\n fnName: 'table.getSortedRowModel',\n memoDeps: () => [\n table.atoms.sorting?.get(),\n table.getPreSortedRowModel(),\n ],\n fn: () => _createSortedRowModel(table),\n onAfterUpdate: () => table_autoResetPageIndex(table),\n })\n }\n}\n\nfunction _createSortedRowModel<\n TFeatures extends TableFeatures,\n TData extends RowData = any,\n>(table: Table_Internal<TFeatures, TData>): RowModel<TFeatures, TData> {\n const preSortedRowModel = table.getPreSortedRowModel()\n const sorting = table.atoms.sorting?.get()\n\n if (!preSortedRowModel.rows.length || !sorting?.length) {\n return preSortedRowModel\n }\n\n const sortedFlatRows: Array<Row<TFeatures, TData>> = []\n\n // Filter out sortings that correspond to non existing columns\n const availableSorting = sorting.filter((sort) => {\n const column = table.getColumn(sort.id)\n return column ? column_getCanSort(column) : false\n })\n\n const resolvedSorting: Array<{\n id: string\n desc?: boolean\n sortUndefined?: false | -1 | 1 | 'first' | 'last'\n invertSorting?: boolean\n sortFn: SortFn<TFeatures, TData>\n }> = []\n\n for (let i = 0; i < availableSorting.length; i++) {\n const sortEntry = availableSorting[i]!\n const column: Column_Internal<TFeatures, TData> | undefined =\n table.getColumn(sortEntry.id)\n if (!column) {\n continue\n }\n\n resolvedSorting.push({\n id: sortEntry.id,\n desc: sortEntry.desc,\n sortUndefined: column.columnDef.sortUndefined,\n invertSorting: column.columnDef.invertSorting,\n sortFn: column_getSortFn(column),\n })\n }\n\n const compareRows = (\n rowA: Row<TFeatures, TData>,\n rowB: Row<TFeatures, TData>,\n ) => {\n for (let i = 0; i < resolvedSorting.length; i++) {\n const sortEntry = resolvedSorting[i]!\n const sortUndefined = sortEntry.sortUndefined\n const isDesc = sortEntry.desc\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 continue\n }\n\n if (aUndefined || bUndefined) {\n if (sortUndefined === 'first') return aUndefined ? -1 : 1\n if (sortUndefined === 'last') return aUndefined ? 1 : -1\n sortInt = aUndefined ? sortUndefined : -sortUndefined\n }\n }\n\n if (sortInt === 0) {\n sortInt = sortEntry.sortFn(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 (sortEntry.invertSorting) {\n sortInt *= -1\n }\n\n return sortInt\n }\n }\n\n return rowA.index - rowB.index\n }\n\n const sortData = (rows: Array<Row<TFeatures, TData>>) => {\n const sortedData = rows.slice()\n\n sortedData.sort(compareRows)\n\n // If there are sub-rows, sort them. Clone only rows that need mutation\n // (i.e. have subRows) so we don't corrupt the source row model.\n for (let i = 0; i < sortedData.length; i++) {\n const row = sortedData[i]!\n if (row.subRows.length) {\n // Preserve prototype chain so methods like getValue() remain accessible\n const cloned = Object.create(Object.getPrototypeOf(row))\n Object.assign(cloned, row)\n cloned.subRows = sortData(row.subRows)\n sortedData[i] = cloned\n sortedFlatRows.push(cloned)\n } else {\n sortedFlatRows.push(row)\n }\n }\n\n return sortedData\n }\n\n return {\n rows: sortData(preSortedRowModel.rows),\n flatRows: sortedFlatRows,\n rowsById: preSortedRowModel.rowsById,\n }\n}\n"],"mappings":";;;;;;;;;;;;;AAmBA,SAAgB,uBAG0D;CACxE,QAAQ,WAAW;EACjB,MAAM,QAAQ;EACd,OAAO,UAAU;GACf,SAAS;GACT;GACA,QAAQ;GACR,gBAAgB,CACd,MAAM,MAAM,SAAS,IAAI,GACzB,MAAM,qBAAqB,CAC7B;GACA,UAAU,sBAAsB,KAAK;GACrC,qBAAqB,yBAAyB,KAAK;EACrD,CAAC;CACH;AACF;AAEA,SAAS,sBAGP,OAAqE;CACrE,MAAM,oBAAoB,MAAM,qBAAqB;CACrD,MAAM,UAAU,MAAM,MAAM,SAAS,IAAI;CAEzC,IAAI,CAAC,kBAAkB,KAAK,UAAU,CAAC,SAAS,QAC9C,OAAO;CAGT,MAAM,iBAA+C,CAAC;CAGtD,MAAM,mBAAmB,QAAQ,QAAQ,SAAS;EAChD,MAAM,SAAS,MAAM,UAAU,KAAK,EAAE;EACtC,OAAO,SAAS,kBAAkB,MAAM,IAAI;CAC9C,CAAC;CAED,MAAM,kBAMD,CAAC;CAEN,KAAK,IAAI,IAAI,GAAG,IAAI,iBAAiB,QAAQ,KAAK;EAChD,MAAM,YAAY,iBAAiB;EACnC,MAAM,SACJ,MAAM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IACrC,WAAW,KAAK;IAChB,eAAe,KAAK,MAAM;GAC5B,OACE,eAAe,KAAK,GAAG;EAE3B;EAEA,OAAO;CACT;CAEA,OAAO;EACL,MAAM,SAAS,kBAAkB,IAAI;EACrC,UAAU;EACV,UAAU,kBAAkB;CAC9B;AACF"}
1
+ {"version":3,"file":"createSortedRowModel.js","names":[],"sources":["../../../src/features/row-sorting/createSortedRowModel.ts"],"sourcesContent":["import { copyInstancePropertiesWithoutMemos, tableMemo } from '../../utils'\nimport { table_autoResetPageIndex } from '../row-pagination/rowPaginationFeature.utils'\nimport { column_getCanSort, column_getSortFn } from './rowSortingFeature.utils'\nimport type { Column_Internal } from '../../types/Column'\nimport type { TableFeatures } from '../../types/TableFeatures'\nimport type { RowModel } from '../../core/row-models/coreRowModelsFeature.types'\nimport type { Table, Table_Internal } from '../../types/Table'\nimport type { Row } from '../../types/Row'\nimport type { SortFn } from './rowSortingFeature.types'\nimport type { RowData } from '../../types/type-utils'\n\n/**\n * Creates a memoized sorted row model factory.\n *\n * The factory reads the relevant table state atoms and options, then returns a row model function used by the table row-model pipeline.\n *\n * Register sorting functions with the `sortFns` slot on the `features` option:\n * `tableFeatures({ rowSortingFeature, sortedRowModel: createSortedRowModel(), sortFns })`.\n */\nexport function createSortedRowModel<\n TFeatures extends TableFeatures,\n TData extends RowData,\n>(): (table: Table<TFeatures, TData>) => () => RowModel<TFeatures, TData> {\n return (_table) => {\n const table = _table as unknown as Table_Internal<TFeatures, TData>\n return tableMemo({\n feature: 'rowSortingFeature',\n table,\n fnName: 'table.getSortedRowModel',\n memoDeps: () => [\n table.atoms.sorting?.get(),\n table.getPreSortedRowModel(),\n ],\n fn: () => _createSortedRowModel(table),\n onAfterUpdate: () => table_autoResetPageIndex(table),\n })\n }\n}\n\nfunction _createSortedRowModel<\n TFeatures extends TableFeatures,\n TData extends RowData = any,\n>(table: Table_Internal<TFeatures, TData>): RowModel<TFeatures, TData> {\n const preSortedRowModel = table.getPreSortedRowModel()\n const sorting = table.atoms.sorting?.get()\n\n if (!preSortedRowModel.rows.length || !sorting?.length) {\n return preSortedRowModel\n }\n\n const sortedFlatRows: Array<Row<TFeatures, TData>> = []\n\n // Filter out sortings that correspond to non existing columns\n const availableSorting = sorting.filter((sort) => {\n const column = table.getColumn(sort.id)\n return column ? column_getCanSort(column) : false\n })\n\n if (!availableSorting.length) {\n return preSortedRowModel\n }\n\n const resolvedSorting: Array<{\n id: string\n desc?: boolean\n sortUndefined?: false | -1 | 1 | 'first' | 'last'\n invertSorting?: boolean\n sortFn: SortFn<TFeatures, TData>\n }> = []\n\n for (let i = 0; i < availableSorting.length; i++) {\n const sortEntry = availableSorting[i]!\n const column: Column_Internal<TFeatures, TData> | undefined =\n table.getColumn(sortEntry.id)\n if (!column) {\n continue\n }\n\n resolvedSorting.push({\n id: sortEntry.id,\n desc: sortEntry.desc,\n sortUndefined: column.columnDef.sortUndefined,\n invertSorting: column.columnDef.invertSorting,\n sortFn: column_getSortFn(column),\n })\n }\n\n const compareRows = (\n rowA: Row<TFeatures, TData>,\n rowB: Row<TFeatures, TData>,\n ) => {\n for (let i = 0; i < resolvedSorting.length; i++) {\n const sortEntry = resolvedSorting[i]!\n const sortUndefined = sortEntry.sortUndefined\n const isDesc = sortEntry.desc\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 continue\n }\n\n if (aUndefined || bUndefined) {\n if (sortUndefined === 'first') return aUndefined ? -1 : 1\n if (sortUndefined === 'last') return aUndefined ? 1 : -1\n sortInt = aUndefined ? sortUndefined : -sortUndefined\n }\n }\n\n if (sortInt === 0) {\n sortInt = sortEntry.sortFn(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 (sortEntry.invertSorting) {\n sortInt *= -1\n }\n\n return sortInt\n }\n }\n\n return rowA.index - rowB.index\n }\n\n const sortData = (\n rows: Array<Row<TFeatures, TData>>,\n ): {\n rows: Array<Row<TFeatures, TData>>\n changed: boolean\n } => {\n const sortedData = rows.slice()\n\n sortedData.sort(compareRows)\n let changed = false\n\n // If there are sub-rows, sort them. Clone only rows that need mutation\n // (i.e. have subRows) so we don't corrupt the source row model.\n for (let i = 0; i < sortedData.length; i++) {\n const row = sortedData[i]!\n if (row !== rows[i]) {\n changed = true\n }\n\n if (row.subRows.length) {\n const sortedSubRows = sortData(row.subRows)\n\n if (sortedSubRows.changed) {\n // Preserve prototype chain so methods like getValue() remain accessible\n const cloned = Object.create(Object.getPrototypeOf(row))\n copyInstancePropertiesWithoutMemos(cloned, row)\n cloned.subRows = sortedSubRows.rows\n sortedData[i] = cloned\n sortedFlatRows.push(cloned)\n changed = true\n } else {\n sortedFlatRows.push(row)\n }\n } else {\n sortedFlatRows.push(row)\n }\n }\n\n return { rows: sortedData, changed }\n }\n\n return {\n rows: sortData(preSortedRowModel.rows).rows,\n flatRows: sortedFlatRows,\n rowsById: preSortedRowModel.rowsById,\n }\n}\n"],"mappings":";;;;;;;;;;;;;AAmBA,SAAgB,uBAG0D;CACxE,QAAQ,WAAW;EACjB,MAAM,QAAQ;EACd,OAAO,UAAU;GACf,SAAS;GACT;GACA,QAAQ;GACR,gBAAgB,CACd,MAAM,MAAM,SAAS,IAAI,GACzB,MAAM,qBAAqB,CAC7B;GACA,UAAU,sBAAsB,KAAK;GACrC,qBAAqB,yBAAyB,KAAK;EACrD,CAAC;CACH;AACF;AAEA,SAAS,sBAGP,OAAqE;CACrE,MAAM,oBAAoB,MAAM,qBAAqB;CACrD,MAAM,UAAU,MAAM,MAAM,SAAS,IAAI;CAEzC,IAAI,CAAC,kBAAkB,KAAK,UAAU,CAAC,SAAS,QAC9C,OAAO;CAGT,MAAM,iBAA+C,CAAC;CAGtD,MAAM,mBAA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AAM,aAAa,KAAK,MAAM;EAE9B,WAAW,KAAK,WAAW;EAC3B,IAAI,UAAU;EAId,KAAK,IAAI,IAAI,GAAG,IAAI,WAAW,QAAQ,KAAK;GAC1C,MAAM,MAAM,WAAW;GACvB,IAAI,QAAQ,KAAK,IACf,UAAU;GAGZ,IAAI,IAAI,QAAQ,QAAQ;IACtB,MAAM,gBAAgB,SAAS,IAAI,OAAO;IAE1C,IAAI,cAAc,SAAS;KAEzB,MAAM,SAAS,OAAO,OAAO,OAAO,eAAe,GAAG,CAAC;KACvD,mCAAmC,QAAQ,GAAG;KAC9C,OAAO,UAAU,cAAc;KAC/B,WAAW,KAAK;KAChB,eAAe,KAAK,MAAM;KAC1B,UAAU;IACZ,OACE,eAAe,KAAK,GAAG;GAE3B,OACE,eAAe,KAAK,GAAG;EAE3B;EAEA,OAAO;GAAE,MAAM;GAAY;EAAQ;CACrC;CAEA,OAAO;EACL,MAAM,SAAS,kBAAkB,IAAI,CAAC,CAAC;EACvC,UAAU;EACV,UAAU,kBAAkB;CAC9B;AACF"}
@@ -124,8 +124,8 @@ function column_toggleSorting(column, desc, multi) {
124
124
  const nextSortingOrder = column_getNextSortingOrder(column);
125
125
  const hasManualValue = typeof desc !== "undefined";
126
126
  table_setSorting(column.table, (old) => {
127
- const existingSorting = old.find((d) => d.id === column.id);
128
127
  const existingIndex = old.findIndex((d) => d.id === column.id);
128
+ const existingSorting = existingIndex === -1 ? void 0 : old[existingIndex];
129
129
  let newSorting = [];
130
130
  let sortAction;
131
131
  const nextDesc = hasManualValue ? desc : nextSortingOrder === "desc";