@tanstack/table-core 9.0.0-beta.23 → 9.0.0-beta.26
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/README.md +1 -0
- package/dist/features/row-selection/rowSelectionFeature.cjs +22 -2
- package/dist/features/row-selection/rowSelectionFeature.cjs.map +1 -1
- package/dist/features/row-selection/rowSelectionFeature.js +22 -2
- package/dist/features/row-selection/rowSelectionFeature.js.map +1 -1
- package/dist/features/row-selection/rowSelectionFeature.utils.cjs +5 -5
- package/dist/features/row-selection/rowSelectionFeature.utils.cjs.map +1 -1
- package/dist/features/row-selection/rowSelectionFeature.utils.js +5 -5
- package/dist/features/row-selection/rowSelectionFeature.utils.js.map +1 -1
- package/package.json +1 -1
- package/src/features/row-selection/rowSelectionFeature.ts +10 -0
- package/src/features/row-selection/rowSelectionFeature.utils.ts +6 -9
package/README.md
CHANGED
|
@@ -39,6 +39,7 @@
|
|
|
39
39
|
> - [Solid Table](https://tanstack.com/table/alpha/docs/framework/solid/solid-table)
|
|
40
40
|
> - [Svelte Table](https://tanstack.com/table/alpha/docs/framework/svelte/svelte-table)
|
|
41
41
|
> - [Vue Table](https://tanstack.com/table/alpha/docs/framework/vue/vue-table)
|
|
42
|
+
> - [Alpine Table](https://tanstack.com/table/alpha/docs/framework/alpine/alpine-table)
|
|
42
43
|
|
|
43
44
|
A headless table library for building powerful datagrids with full control over markup, styles, and behavior.
|
|
44
45
|
|
|
@@ -24,8 +24,28 @@ const rowSelectionFeature = {
|
|
|
24
24
|
require_utils.assignPrototypeAPIs("rowSelectionFeature", prototype, table, {
|
|
25
25
|
row_toggleSelected: { fn: (row, value, opts) => require_rowSelectionFeature_utils.row_toggleSelected(row, value, opts) },
|
|
26
26
|
row_getIsSelected: { fn: (row) => require_rowSelectionFeature_utils.row_getIsSelected(row) },
|
|
27
|
-
row_getIsSomeSelected: {
|
|
28
|
-
|
|
27
|
+
row_getIsSomeSelected: {
|
|
28
|
+
fn: (row) => require_rowSelectionFeature_utils.row_getIsSomeSelected(row),
|
|
29
|
+
memoDeps: (row) => {
|
|
30
|
+
var _row$table$atoms$rowS;
|
|
31
|
+
return [
|
|
32
|
+
row.subRows,
|
|
33
|
+
(_row$table$atoms$rowS = row.table.atoms.rowSelection) === null || _row$table$atoms$rowS === void 0 ? void 0 : _row$table$atoms$rowS.get(),
|
|
34
|
+
row.table.options.enableRowSelection
|
|
35
|
+
];
|
|
36
|
+
}
|
|
37
|
+
},
|
|
38
|
+
row_getIsAllSubRowsSelected: {
|
|
39
|
+
fn: (row) => require_rowSelectionFeature_utils.row_getIsAllSubRowsSelected(row),
|
|
40
|
+
memoDeps: (row) => {
|
|
41
|
+
var _row$table$atoms$rowS2;
|
|
42
|
+
return [
|
|
43
|
+
row.subRows,
|
|
44
|
+
(_row$table$atoms$rowS2 = row.table.atoms.rowSelection) === null || _row$table$atoms$rowS2 === void 0 ? void 0 : _row$table$atoms$rowS2.get(),
|
|
45
|
+
row.table.options.enableRowSelection
|
|
46
|
+
];
|
|
47
|
+
}
|
|
48
|
+
},
|
|
29
49
|
row_getCanSelect: { fn: (row) => require_rowSelectionFeature_utils.row_getCanSelect(row) },
|
|
30
50
|
row_getCanSelectSubRows: { fn: (row) => require_rowSelectionFeature_utils.row_getCanSelectSubRows(row) },
|
|
31
51
|
row_getCanMultiSelect: { fn: (row) => require_rowSelectionFeature_utils.row_getCanMultiSelect(row) },
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"rowSelectionFeature.cjs","names":["getDefaultRowSelectionState","makeStateUpdater","row_toggleSelected","row_getIsSelected","row_getIsSomeSelected","row_getIsAllSubRowsSelected","row_getCanSelect","row_getCanSelectSubRows","row_getCanMultiSelect","row_getToggleSelectedHandler","table_setRowSelection","table_resetRowSelection","table_toggleAllRowsSelected","table_toggleAllPageRowsSelected","table_getPreSelectedRowModel","table_getSelectedRowModel","table_getFilteredSelectedRowModel","table_getGroupedSelectedRowModel","table_getSelectedRowIds","table_getIsAllRowsSelected","table_getIsAllPageRowsSelected","table_getIsSomeRowsSelected","table_getIsSomePageRowsSelected","table_getToggleAllRowsSelectedHandler","table_getToggleAllPageRowsSelectedHandler"],"sources":["../../../src/features/row-selection/rowSelectionFeature.ts"],"sourcesContent":["import {\n assignPrototypeAPIs,\n assignTableAPIs,\n makeStateUpdater,\n} from '../../utils'\nimport {\n getDefaultRowSelectionState,\n row_getCanMultiSelect,\n row_getCanSelect,\n row_getCanSelectSubRows,\n row_getIsAllSubRowsSelected,\n row_getIsSelected,\n row_getIsSomeSelected,\n row_getToggleSelectedHandler,\n row_toggleSelected,\n table_getFilteredSelectedRowModel,\n table_getGroupedSelectedRowModel,\n table_getIsAllPageRowsSelected,\n table_getIsAllRowsSelected,\n table_getIsSomePageRowsSelected,\n table_getIsSomeRowsSelected,\n table_getPreSelectedRowModel,\n table_getSelectedRowIds,\n table_getSelectedRowModel,\n table_getToggleAllPageRowsSelectedHandler,\n table_getToggleAllRowsSelectedHandler,\n table_resetRowSelection,\n table_setRowSelection,\n table_toggleAllPageRowsSelected,\n table_toggleAllRowsSelected,\n} from './rowSelectionFeature.utils'\nimport type { TableFeature } from '../../types/TableFeatures'\n\n/**\n * Feature that adds row selection state and APIs for row and page selection.\n */\nexport const rowSelectionFeature: TableFeature = {\n getInitialState: (initialState) => {\n return {\n rowSelection: getDefaultRowSelectionState(),\n ...initialState,\n }\n },\n\n getDefaultTableOptions: (table) => {\n return {\n onRowSelectionChange: makeStateUpdater('rowSelection', table),\n enableRowSelection: true,\n enableMultiRowSelection: true,\n enableSubRowSelection: true,\n }\n },\n\n assignRowPrototype: (prototype, table) => {\n assignPrototypeAPIs('rowSelectionFeature', prototype, table, {\n row_toggleSelected: {\n fn: (row, value, opts) => row_toggleSelected(row, value, opts),\n },\n row_getIsSelected: {\n fn: (row) => row_getIsSelected(row),\n },\n row_getIsSomeSelected: {\n fn: (row) => row_getIsSomeSelected(row),\n },\n row_getIsAllSubRowsSelected: {\n fn: (row) => row_getIsAllSubRowsSelected(row),\n },\n row_getCanSelect: {\n fn: (row) => row_getCanSelect(row),\n },\n row_getCanSelectSubRows: {\n fn: (row) => row_getCanSelectSubRows(row),\n },\n row_getCanMultiSelect: {\n fn: (row) => row_getCanMultiSelect(row),\n },\n row_getToggleSelectedHandler: {\n fn: (row) => row_getToggleSelectedHandler(row),\n },\n })\n },\n\n constructTableAPIs: (table) => {\n assignTableAPIs('rowSelectionFeature', table, {\n table_setRowSelection: {\n fn: (updater) => table_setRowSelection(table, updater),\n },\n table_resetRowSelection: {\n fn: (defaultState) => table_resetRowSelection(table, defaultState),\n },\n table_toggleAllRowsSelected: {\n fn: (value, opts) => table_toggleAllRowsSelected(table, value, opts),\n },\n table_toggleAllPageRowsSelected: {\n fn: (value, opts) =>\n table_toggleAllPageRowsSelected(table, value, opts),\n },\n table_getPreSelectedRowModel: {\n fn: () => table_getPreSelectedRowModel(table),\n },\n table_getSelectedRowModel: {\n fn: () => table_getSelectedRowModel(table),\n memoDeps: () => [\n table.atoms.rowSelection?.get(),\n table.getCoreRowModel(),\n ],\n },\n table_getFilteredSelectedRowModel: {\n fn: () => table_getFilteredSelectedRowModel(table),\n memoDeps: () => [\n table.atoms.rowSelection?.get(),\n table.getFilteredRowModel(),\n ],\n },\n table_getGroupedSelectedRowModel: {\n fn: () => table_getGroupedSelectedRowModel(table),\n memoDeps: () => [\n table.atoms.rowSelection?.get(),\n table.getSortedRowModel(),\n ],\n },\n table_getSelectedRowIds: {\n fn: () => table_getSelectedRowIds(table),\n memoDeps: () => [table.atoms.rowSelection?.get()],\n },\n table_getIsAllRowsSelected: {\n fn: () => table_getIsAllRowsSelected(table),\n memoDeps: () => [\n table.atoms.rowSelection?.get(),\n table.getFilteredRowModel(),\n table.options.enableRowSelection,\n ],\n },\n table_getIsAllPageRowsSelected: {\n fn: () => table_getIsAllPageRowsSelected(table),\n memoDeps: () => [\n table.atoms.rowSelection?.get(),\n table.getPaginatedRowModel(),\n table.options.enableRowSelection,\n ],\n },\n table_getIsSomeRowsSelected: {\n fn: () => table_getIsSomeRowsSelected(table),\n memoDeps: () => [table.atoms.rowSelection?.get()],\n },\n table_getIsSomePageRowsSelected: {\n fn: () => table_getIsSomePageRowsSelected(table),\n memoDeps: () => [\n table.atoms.rowSelection?.get(),\n table.getPaginatedRowModel(),\n table.options.enableRowSelection,\n ],\n },\n table_getToggleAllRowsSelectedHandler: {\n fn: () => table_getToggleAllRowsSelectedHandler(table),\n },\n table_getToggleAllPageRowsSelectedHandler: {\n fn: () => table_getToggleAllPageRowsSelectedHandler(table),\n },\n })\n },\n}\n"],"mappings":";;;;;;;AAoCA,MAAa,sBAAoC;CAC/C,kBAAkB,iBAAiB;EACjC,OAAO;GACL,cAAcA,8DAA4B;GAC1C,GAAG;EACL;CACF;CAEA,yBAAyB,UAAU;EACjC,OAAO;GACL,sBAAsBC,+BAAiB,gBAAgB,KAAK;GAC5D,oBAAoB;GACpB,yBAAyB;GACzB,uBAAuB;EACzB;CACF;CAEA,qBAAqB,WAAW,UAAU;EACxC,kCAAoB,uBAAuB,WAAW,OAAO;GAC3D,oBAAoB,EAClB,KAAK,KAAK,OAAO,SAASC,qDAAmB,KAAK,OAAO,IAAI,EAC/D;GACA,mBAAmB,EACjB,KAAK,QAAQC,oDAAkB,GAAG,EACpC;GACA,uBAAuB,
|
|
1
|
+
{"version":3,"file":"rowSelectionFeature.cjs","names":["getDefaultRowSelectionState","makeStateUpdater","row_toggleSelected","row_getIsSelected","row_getIsSomeSelected","row_getIsAllSubRowsSelected","row_getCanSelect","row_getCanSelectSubRows","row_getCanMultiSelect","row_getToggleSelectedHandler","table_setRowSelection","table_resetRowSelection","table_toggleAllRowsSelected","table_toggleAllPageRowsSelected","table_getPreSelectedRowModel","table_getSelectedRowModel","table_getFilteredSelectedRowModel","table_getGroupedSelectedRowModel","table_getSelectedRowIds","table_getIsAllRowsSelected","table_getIsAllPageRowsSelected","table_getIsSomeRowsSelected","table_getIsSomePageRowsSelected","table_getToggleAllRowsSelectedHandler","table_getToggleAllPageRowsSelectedHandler"],"sources":["../../../src/features/row-selection/rowSelectionFeature.ts"],"sourcesContent":["import {\n assignPrototypeAPIs,\n assignTableAPIs,\n makeStateUpdater,\n} from '../../utils'\nimport {\n getDefaultRowSelectionState,\n row_getCanMultiSelect,\n row_getCanSelect,\n row_getCanSelectSubRows,\n row_getIsAllSubRowsSelected,\n row_getIsSelected,\n row_getIsSomeSelected,\n row_getToggleSelectedHandler,\n row_toggleSelected,\n table_getFilteredSelectedRowModel,\n table_getGroupedSelectedRowModel,\n table_getIsAllPageRowsSelected,\n table_getIsAllRowsSelected,\n table_getIsSomePageRowsSelected,\n table_getIsSomeRowsSelected,\n table_getPreSelectedRowModel,\n table_getSelectedRowIds,\n table_getSelectedRowModel,\n table_getToggleAllPageRowsSelectedHandler,\n table_getToggleAllRowsSelectedHandler,\n table_resetRowSelection,\n table_setRowSelection,\n table_toggleAllPageRowsSelected,\n table_toggleAllRowsSelected,\n} from './rowSelectionFeature.utils'\nimport type { TableFeature } from '../../types/TableFeatures'\n\n/**\n * Feature that adds row selection state and APIs for row and page selection.\n */\nexport const rowSelectionFeature: TableFeature = {\n getInitialState: (initialState) => {\n return {\n rowSelection: getDefaultRowSelectionState(),\n ...initialState,\n }\n },\n\n getDefaultTableOptions: (table) => {\n return {\n onRowSelectionChange: makeStateUpdater('rowSelection', table),\n enableRowSelection: true,\n enableMultiRowSelection: true,\n enableSubRowSelection: true,\n }\n },\n\n assignRowPrototype: (prototype, table) => {\n assignPrototypeAPIs('rowSelectionFeature', prototype, table, {\n row_toggleSelected: {\n fn: (row, value, opts) => row_toggleSelected(row, value, opts),\n },\n row_getIsSelected: {\n fn: (row) => row_getIsSelected(row),\n },\n row_getIsSomeSelected: {\n fn: (row) => row_getIsSomeSelected(row),\n memoDeps: (row) => [\n row.subRows,\n row.table.atoms.rowSelection?.get(),\n row.table.options.enableRowSelection,\n ],\n },\n row_getIsAllSubRowsSelected: {\n fn: (row) => row_getIsAllSubRowsSelected(row),\n memoDeps: (row) => [\n row.subRows,\n row.table.atoms.rowSelection?.get(),\n row.table.options.enableRowSelection,\n ],\n },\n row_getCanSelect: {\n fn: (row) => row_getCanSelect(row),\n },\n row_getCanSelectSubRows: {\n fn: (row) => row_getCanSelectSubRows(row),\n },\n row_getCanMultiSelect: {\n fn: (row) => row_getCanMultiSelect(row),\n },\n row_getToggleSelectedHandler: {\n fn: (row) => row_getToggleSelectedHandler(row),\n },\n })\n },\n\n constructTableAPIs: (table) => {\n assignTableAPIs('rowSelectionFeature', table, {\n table_setRowSelection: {\n fn: (updater) => table_setRowSelection(table, updater),\n },\n table_resetRowSelection: {\n fn: (defaultState) => table_resetRowSelection(table, defaultState),\n },\n table_toggleAllRowsSelected: {\n fn: (value, opts) => table_toggleAllRowsSelected(table, value, opts),\n },\n table_toggleAllPageRowsSelected: {\n fn: (value, opts) =>\n table_toggleAllPageRowsSelected(table, value, opts),\n },\n table_getPreSelectedRowModel: {\n fn: () => table_getPreSelectedRowModel(table),\n },\n table_getSelectedRowModel: {\n fn: () => table_getSelectedRowModel(table),\n memoDeps: () => [\n table.atoms.rowSelection?.get(),\n table.getCoreRowModel(),\n ],\n },\n table_getFilteredSelectedRowModel: {\n fn: () => table_getFilteredSelectedRowModel(table),\n memoDeps: () => [\n table.atoms.rowSelection?.get(),\n table.getFilteredRowModel(),\n ],\n },\n table_getGroupedSelectedRowModel: {\n fn: () => table_getGroupedSelectedRowModel(table),\n memoDeps: () => [\n table.atoms.rowSelection?.get(),\n table.getSortedRowModel(),\n ],\n },\n table_getSelectedRowIds: {\n fn: () => table_getSelectedRowIds(table),\n memoDeps: () => [table.atoms.rowSelection?.get()],\n },\n table_getIsAllRowsSelected: {\n fn: () => table_getIsAllRowsSelected(table),\n memoDeps: () => [\n table.atoms.rowSelection?.get(),\n table.getFilteredRowModel(),\n table.options.enableRowSelection,\n ],\n },\n table_getIsAllPageRowsSelected: {\n fn: () => table_getIsAllPageRowsSelected(table),\n memoDeps: () => [\n table.atoms.rowSelection?.get(),\n table.getPaginatedRowModel(),\n table.options.enableRowSelection,\n ],\n },\n table_getIsSomeRowsSelected: {\n fn: () => table_getIsSomeRowsSelected(table),\n memoDeps: () => [table.atoms.rowSelection?.get()],\n },\n table_getIsSomePageRowsSelected: {\n fn: () => table_getIsSomePageRowsSelected(table),\n memoDeps: () => [\n table.atoms.rowSelection?.get(),\n table.getPaginatedRowModel(),\n table.options.enableRowSelection,\n ],\n },\n table_getToggleAllRowsSelectedHandler: {\n fn: () => table_getToggleAllRowsSelectedHandler(table),\n },\n table_getToggleAllPageRowsSelectedHandler: {\n fn: () => table_getToggleAllPageRowsSelectedHandler(table),\n },\n })\n },\n}\n"],"mappings":";;;;;;;AAoCA,MAAa,sBAAoC;CAC/C,kBAAkB,iBAAiB;EACjC,OAAO;GACL,cAAcA,8DAA4B;GAC1C,GAAG;EACL;CACF;CAEA,yBAAyB,UAAU;EACjC,OAAO;GACL,sBAAsBC,+BAAiB,gBAAgB,KAAK;GAC5D,oBAAoB;GACpB,yBAAyB;GACzB,uBAAuB;EACzB;CACF;CAEA,qBAAqB,WAAW,UAAU;EACxC,kCAAoB,uBAAuB,WAAW,OAAO;GAC3D,oBAAoB,EAClB,KAAK,KAAK,OAAO,SAASC,qDAAmB,KAAK,OAAO,IAAI,EAC/D;GACA,mBAAmB,EACjB,KAAK,QAAQC,oDAAkB,GAAG,EACpC;GACA,uBAAuB;IACrB,KAAK,QAAQC,wDAAsB,GAAG;IACtC,WAAW,QAAQ;;;MACjB,IAAI;+BACJ,IAAI,MAAM,MAAM,4FAAc,IAAI;MAClC,IAAI,MAAM,QAAQ;KACpB;;GACF;GACA,6BAA6B;IAC3B,KAAK,QAAQC,8DAA4B,GAAG;IAC5C,WAAW,QAAQ;;;MACjB,IAAI;gCACJ,IAAI,MAAM,MAAM,8FAAc,IAAI;MAClC,IAAI,MAAM,QAAQ;KACpB;;GACF;GACA,kBAAkB,EAChB,KAAK,QAAQC,mDAAiB,G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d,MAAM,MAAM,8FAAc,IAAI;MAC9B,MAAM,qBAAqB;MAC3B,MAAM,QAAQ;KAChB;;GACF;GACA,6BAA6B;IAC3B,UAAUC,8DAA4B,KAAK;IAC3C,gBAAgB;;uCAAC,MAAM,MAAM,8FAAc,IAAI,CAAC;;GAClD;GACA,iCAAiC;IAC/B,UAAUC,kEAAgC,KAAK;IAC/C,gBAAgB;;;gCACd,MAAM,MAAM,8FAAc,IAAI;MAC9B,MAAM,qBAAqB;MAC3B,MAAM,QAAQ;KAChB;;GACF;GACA,uCAAuC,EACrC,UAAUC,wEAAsC,KAAK,EACvD;GACA,2CAA2C,EACzC,UAAUC,4EAA0C,KAAK,EAC3D;EACF,CAAC;CACH;AACF"}
|
|
@@ -24,8 +24,28 @@ const rowSelectionFeature = {
|
|
|
24
24
|
assignPrototypeAPIs("rowSelectionFeature", prototype, table, {
|
|
25
25
|
row_toggleSelected: { fn: (row, value, opts) => row_toggleSelected(row, value, opts) },
|
|
26
26
|
row_getIsSelected: { fn: (row) => row_getIsSelected(row) },
|
|
27
|
-
row_getIsSomeSelected: {
|
|
28
|
-
|
|
27
|
+
row_getIsSomeSelected: {
|
|
28
|
+
fn: (row) => row_getIsSomeSelected(row),
|
|
29
|
+
memoDeps: (row) => {
|
|
30
|
+
var _row$table$atoms$rowS;
|
|
31
|
+
return [
|
|
32
|
+
row.subRows,
|
|
33
|
+
(_row$table$atoms$rowS = row.table.atoms.rowSelection) === null || _row$table$atoms$rowS === void 0 ? void 0 : _row$table$atoms$rowS.get(),
|
|
34
|
+
row.table.options.enableRowSelection
|
|
35
|
+
];
|
|
36
|
+
}
|
|
37
|
+
},
|
|
38
|
+
row_getIsAllSubRowsSelected: {
|
|
39
|
+
fn: (row) => row_getIsAllSubRowsSelected(row),
|
|
40
|
+
memoDeps: (row) => {
|
|
41
|
+
var _row$table$atoms$rowS2;
|
|
42
|
+
return [
|
|
43
|
+
row.subRows,
|
|
44
|
+
(_row$table$atoms$rowS2 = row.table.atoms.rowSelection) === null || _row$table$atoms$rowS2 === void 0 ? void 0 : _row$table$atoms$rowS2.get(),
|
|
45
|
+
row.table.options.enableRowSelection
|
|
46
|
+
];
|
|
47
|
+
}
|
|
48
|
+
},
|
|
29
49
|
row_getCanSelect: { fn: (row) => row_getCanSelect(row) },
|
|
30
50
|
row_getCanSelectSubRows: { fn: (row) => row_getCanSelectSubRows(row) },
|
|
31
51
|
row_getCanMultiSelect: { fn: (row) => row_getCanMultiSelect(row) },
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"rowSelectionFeature.js","names":[],"sources":["../../../src/features/row-selection/rowSelectionFeature.ts"],"sourcesContent":["import {\n assignPrototypeAPIs,\n assignTableAPIs,\n makeStateUpdater,\n} from '../../utils'\nimport {\n getDefaultRowSelectionState,\n row_getCanMultiSelect,\n row_getCanSelect,\n row_getCanSelectSubRows,\n row_getIsAllSubRowsSelected,\n row_getIsSelected,\n row_getIsSomeSelected,\n row_getToggleSelectedHandler,\n row_toggleSelected,\n table_getFilteredSelectedRowModel,\n table_getGroupedSelectedRowModel,\n table_getIsAllPageRowsSelected,\n table_getIsAllRowsSelected,\n table_getIsSomePageRowsSelected,\n table_getIsSomeRowsSelected,\n table_getPreSelectedRowModel,\n table_getSelectedRowIds,\n table_getSelectedRowModel,\n table_getToggleAllPageRowsSelectedHandler,\n table_getToggleAllRowsSelectedHandler,\n table_resetRowSelection,\n table_setRowSelection,\n table_toggleAllPageRowsSelected,\n table_toggleAllRowsSelected,\n} from './rowSelectionFeature.utils'\nimport type { TableFeature } from '../../types/TableFeatures'\n\n/**\n * Feature that adds row selection state and APIs for row and page selection.\n */\nexport const rowSelectionFeature: TableFeature = {\n getInitialState: (initialState) => {\n return {\n rowSelection: getDefaultRowSelectionState(),\n ...initialState,\n }\n },\n\n getDefaultTableOptions: (table) => {\n return {\n onRowSelectionChange: makeStateUpdater('rowSelection', table),\n enableRowSelection: true,\n enableMultiRowSelection: true,\n enableSubRowSelection: true,\n }\n },\n\n assignRowPrototype: (prototype, table) => {\n assignPrototypeAPIs('rowSelectionFeature', prototype, table, {\n row_toggleSelected: {\n fn: (row, value, opts) => row_toggleSelected(row, value, opts),\n },\n row_getIsSelected: {\n fn: (row) => row_getIsSelected(row),\n },\n row_getIsSomeSelected: {\n fn: (row) => row_getIsSomeSelected(row),\n },\n row_getIsAllSubRowsSelected: {\n fn: (row) => row_getIsAllSubRowsSelected(row),\n },\n row_getCanSelect: {\n fn: (row) => row_getCanSelect(row),\n },\n row_getCanSelectSubRows: {\n fn: (row) => row_getCanSelectSubRows(row),\n },\n row_getCanMultiSelect: {\n fn: (row) => row_getCanMultiSelect(row),\n },\n row_getToggleSelectedHandler: {\n fn: (row) => row_getToggleSelectedHandler(row),\n },\n })\n },\n\n constructTableAPIs: (table) => {\n assignTableAPIs('rowSelectionFeature', table, {\n table_setRowSelection: {\n fn: (updater) => table_setRowSelection(table, updater),\n },\n table_resetRowSelection: {\n fn: (defaultState) => table_resetRowSelection(table, defaultState),\n },\n table_toggleAllRowsSelected: {\n fn: (value, opts) => table_toggleAllRowsSelected(table, value, opts),\n },\n table_toggleAllPageRowsSelected: {\n fn: (value, opts) =>\n table_toggleAllPageRowsSelected(table, value, opts),\n },\n table_getPreSelectedRowModel: {\n fn: () => table_getPreSelectedRowModel(table),\n },\n table_getSelectedRowModel: {\n fn: () => table_getSelectedRowModel(table),\n memoDeps: () => [\n table.atoms.rowSelection?.get(),\n table.getCoreRowModel(),\n ],\n },\n table_getFilteredSelectedRowModel: {\n fn: () => table_getFilteredSelectedRowModel(table),\n memoDeps: () => [\n table.atoms.rowSelection?.get(),\n table.getFilteredRowModel(),\n ],\n },\n table_getGroupedSelectedRowModel: {\n fn: () => table_getGroupedSelectedRowModel(table),\n memoDeps: () => [\n table.atoms.rowSelection?.get(),\n table.getSortedRowModel(),\n ],\n },\n table_getSelectedRowIds: {\n fn: () => table_getSelectedRowIds(table),\n memoDeps: () => [table.atoms.rowSelection?.get()],\n },\n table_getIsAllRowsSelected: {\n fn: () => table_getIsAllRowsSelected(table),\n memoDeps: () => [\n table.atoms.rowSelection?.get(),\n table.getFilteredRowModel(),\n table.options.enableRowSelection,\n ],\n },\n table_getIsAllPageRowsSelected: {\n fn: () => table_getIsAllPageRowsSelected(table),\n memoDeps: () => [\n table.atoms.rowSelection?.get(),\n table.getPaginatedRowModel(),\n table.options.enableRowSelection,\n ],\n },\n table_getIsSomeRowsSelected: {\n fn: () => table_getIsSomeRowsSelected(table),\n memoDeps: () => [table.atoms.rowSelection?.get()],\n },\n table_getIsSomePageRowsSelected: {\n fn: () => table_getIsSomePageRowsSelected(table),\n memoDeps: () => [\n table.atoms.rowSelection?.get(),\n table.getPaginatedRowModel(),\n table.options.enableRowSelection,\n ],\n },\n table_getToggleAllRowsSelectedHandler: {\n fn: () => table_getToggleAllRowsSelectedHandler(table),\n },\n table_getToggleAllPageRowsSelectedHandler: {\n fn: () => table_getToggleAllPageRowsSelectedHandler(table),\n },\n })\n },\n}\n"],"mappings":";;;;;;;AAoCA,MAAa,sBAAoC;CAC/C,kBAAkB,iBAAiB;EACjC,OAAO;GACL,cAAc,4BAA4B;GAC1C,GAAG;EACL;CACF;CAEA,yBAAyB,UAAU;EACjC,OAAO;GACL,sBAAsB,iBAAiB,gBAAgB,KAAK;GAC5D,oBAAoB;GACpB,yBAAyB;GACzB,uBAAuB;EACzB;CACF;CAEA,qBAAqB,WAAW,UAAU;EACxC,oBAAoB,uBAAuB,WAAW,OAAO;GAC3D,oBAAoB,EAClB,KAAK,KAAK,OAAO,SAAS,mBAAmB,KAAK,OAAO,IAAI,EAC/D;GACA,mBAAmB,EACjB,KAAK,QAAQ,kBAAkB,GAAG,EACpC;GACA,uBAAuB,
|
|
1
|
+
{"version":3,"file":"rowSelectionFeature.js","names":[],"sources":["../../../src/features/row-selection/rowSelectionFeature.ts"],"sourcesContent":["import {\n assignPrototypeAPIs,\n assignTableAPIs,\n makeStateUpdater,\n} from '../../utils'\nimport {\n getDefaultRowSelectionState,\n row_getCanMultiSelect,\n row_getCanSelect,\n row_getCanSelectSubRows,\n row_getIsAllSubRowsSelected,\n row_getIsSelected,\n row_getIsSomeSelected,\n row_getToggleSelectedHandler,\n row_toggleSelected,\n table_getFilteredSelectedRowModel,\n table_getGroupedSelectedRowModel,\n table_getIsAllPageRowsSelected,\n table_getIsAllRowsSelected,\n table_getIsSomePageRowsSelected,\n table_getIsSomeRowsSelected,\n table_getPreSelectedRowModel,\n table_getSelectedRowIds,\n table_getSelectedRowModel,\n table_getToggleAllPageRowsSelectedHandler,\n table_getToggleAllRowsSelectedHandler,\n table_resetRowSelection,\n table_setRowSelection,\n table_toggleAllPageRowsSelected,\n table_toggleAllRowsSelected,\n} from './rowSelectionFeature.utils'\nimport type { TableFeature } from '../../types/TableFeatures'\n\n/**\n * Feature that adds row selection state and APIs for row and page selection.\n */\nexport const rowSelectionFeature: TableFeature = {\n getInitialState: (initialState) => {\n return {\n rowSelection: getDefaultRowSelectionState(),\n ...initialState,\n }\n },\n\n getDefaultTableOptions: (table) => {\n return {\n onRowSelectionChange: makeStateUpdater('rowSelection', table),\n enableRowSelection: true,\n enableMultiRowSelection: true,\n enableSubRowSelection: true,\n }\n },\n\n assignRowPrototype: (prototype, table) => {\n assignPrototypeAPIs('rowSelectionFeature', prototype, table, {\n row_toggleSelected: {\n fn: (row, value, opts) => row_toggleSelected(row, value, opts),\n },\n row_getIsSelected: {\n fn: (row) => row_getIsSelected(row),\n },\n row_getIsSomeSelected: {\n fn: (row) => row_getIsSomeSelected(row),\n memoDeps: (row) => [\n row.subRows,\n row.table.atoms.rowSelection?.get(),\n row.table.options.enableRowSelection,\n ],\n },\n row_getIsAllSubRowsSelected: {\n fn: (row) => row_getIsAllSubRowsSelected(row),\n memoDeps: (row) => [\n row.subRows,\n row.table.atoms.rowSelection?.get(),\n row.table.options.enableRowSelection,\n ],\n },\n row_getCanSelect: {\n fn: (row) => row_getCanSelect(row),\n },\n row_getCanSelectSubRows: {\n fn: (row) => row_getCanSelectSubRows(row),\n },\n row_getCanMultiSelect: {\n fn: (row) => row_getCanMultiSelect(row),\n },\n row_getToggleSelectedHandler: {\n fn: (row) => row_getToggleSelectedHandler(row),\n },\n })\n },\n\n constructTableAPIs: (table) => {\n assignTableAPIs('rowSelectionFeature', table, {\n table_setRowSelection: {\n fn: (updater) => table_setRowSelection(table, updater),\n },\n table_resetRowSelection: {\n fn: (defaultState) => table_resetRowSelection(table, defaultState),\n },\n table_toggleAllRowsSelected: {\n fn: (value, opts) => table_toggleAllRowsSelected(table, value, opts),\n },\n table_toggleAllPageRowsSelected: {\n fn: (value, opts) =>\n table_toggleAllPageRowsSelected(table, value, opts),\n },\n table_getPreSelectedRowModel: {\n fn: () => table_getPreSelectedRowModel(table),\n },\n table_getSelectedRowModel: {\n fn: () => table_getSelectedRowModel(table),\n memoDeps: () => [\n table.atoms.rowSelection?.get(),\n table.getCoreRowModel(),\n ],\n },\n table_getFilteredSelectedRowModel: {\n fn: () => table_getFilteredSelectedRowModel(table),\n memoDeps: () => [\n table.atoms.rowSelection?.get(),\n table.getFilteredRowModel(),\n ],\n },\n table_getGroupedSelectedRowModel: {\n fn: () => table_getGroupedSelectedRowModel(table),\n memoDeps: () => [\n table.atoms.rowSelection?.get(),\n table.getSortedRowModel(),\n ],\n },\n table_getSelectedRowIds: {\n fn: () => table_getSelectedRowIds(table),\n memoDeps: () => [table.atoms.rowSelection?.get()],\n },\n table_getIsAllRowsSelected: {\n fn: () => table_getIsAllRowsSelected(table),\n memoDeps: () => [\n table.atoms.rowSelection?.get(),\n table.getFilteredRowModel(),\n table.options.enableRowSelection,\n ],\n },\n table_getIsAllPageRowsSelected: {\n fn: () => table_getIsAllPageRowsSelected(table),\n memoDeps: () => [\n table.atoms.rowSelection?.get(),\n table.getPaginatedRowModel(),\n table.options.enableRowSelection,\n ],\n },\n table_getIsSomeRowsSelected: {\n fn: () => table_getIsSomeRowsSelected(table),\n memoDeps: () => [table.atoms.rowSelection?.get()],\n },\n table_getIsSomePageRowsSelected: {\n fn: () => table_getIsSomePageRowsSelected(table),\n memoDeps: () => [\n table.atoms.rowSelection?.get(),\n table.getPaginatedRowModel(),\n table.options.enableRowSelection,\n ],\n },\n table_getToggleAllRowsSelectedHandler: {\n fn: () => table_getToggleAllRowsSelectedHandler(table),\n },\n table_getToggleAllPageRowsSelectedHandler: {\n fn: () => table_getToggleAllPageRowsSelectedHandler(table),\n },\n })\n },\n}\n"],"mappings":";;;;;;;AAoCA,MAAa,sBAAoC;CAC/C,kBAAkB,iBAAiB;EACjC,OAAO;GACL,cAAc,4BAA4B;GAC1C,GAAG;EACL;CACF;CAEA,yBAAyB,UAAU;EACjC,OAAO;GACL,sBAAsB,iBAAiB,gBAAgB,KAAK;GAC5D,oBAAoB;GACpB,yBAAyB;GACzB,uBAAuB;EACzB;CACF;CAEA,qBAAqB,WAAW,UAAU;EACxC,oBAAoB,uBAAuB,WAAW,OAAO;GAC3D,oBAAoB,EAClB,KAAK,KAAK,OAAO,SAAS,mBAAmB,KAAK,OAAO,IAAI,EAC/D;GACA,mBAAmB,EACjB,KAAK,QAAQ,kBAAkB,GAAG,EACpC;GACA,uBAAuB;IACrB,KAAK,QAAQ,sBAAsB,GAAG;IACtC,WAAW,QAAQ;;;MACjB,IAAI;+BACJ,IAAI,MAAM,MAAM,4FAAc,IAAI;MAClC,IAAI,MAAM,QAAQ;KACpB;;GACF;GACA,6BAA6B;IAC3B,KAAK,QAAQ,4BAA4B,GAAG;IAC5C,WAAW,QAAQ;;;MACjB,IAAI;gCACJ,IAAI,MAAM,MAAM,8FAAc,IAAI;MAClC,IAAI,MAAM,QAAQ;KACpB;;GACF;GACA,kBAAkB,EAChB,KAAK,QAAQ,iBAAiB,GAAG,EACnC;GACA,yBAAyB,EACvB,KAAK,QAAQ,wBAAwB,GAAG,EAC1C;GACA,uBAAuB,EACrB,KAAK,QAAQ,sBAAsB,GAAG,EACxC;GACA,8BAA8B,EAC5B,KAAK,QAAQ,6BAA6B,GAAG,EAC/C;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GACA,iCAAiC;IAC/B,UAAU,gCAAgC,KAAK;IAC/C,gBAAgB;;;gCACd,MAAM,MAAM,8FAAc,IAAI;MAC9B,MAAM,qBAAqB;MAC3B,MAAM,QAAQ;KAChB;;GACF;GACA,uCAAuC,EACrC,UAAU,sCAAsC,KAAK,EACvD;GACA,2CAA2C,EACzC,UAAU,0CAA0C,KAAK,EAC3D;EACF,CAAC;CACH;AACF"}
|
|
@@ -293,7 +293,6 @@ function row_toggleSelected(row, value, opts) {
|
|
|
293
293
|
const isSelected = row_getIsSelected(row);
|
|
294
294
|
table_setRowSelection(row.table, (old) => {
|
|
295
295
|
value = typeof value !== "undefined" ? value : !isSelected;
|
|
296
|
-
if (row_getCanSelect(row) && isSelected === value) return old;
|
|
297
296
|
const rowSelection = Object.assign(require_utils.makeObjectMap(), old);
|
|
298
297
|
mutateRowIsSelected(rowSelection, row.id, value, (opts === null || opts === void 0 ? void 0 : opts.selectChildren) ?? true, row.table);
|
|
299
298
|
return rowSelection;
|
|
@@ -481,10 +480,11 @@ function isSubRowSelected(row) {
|
|
|
481
480
|
var _row$table$atoms$rowS2;
|
|
482
481
|
if (!row.subRows.length) return false;
|
|
483
482
|
const rowSelection = ((_row$table$atoms$rowS2 = row.table.atoms.rowSelection) === null || _row$table$atoms$rowS2 === void 0 ? void 0 : _row$table$atoms$rowS2.get()) ?? {};
|
|
484
|
-
let allChildrenSelected = true;
|
|
485
483
|
let someSelected = false;
|
|
486
|
-
|
|
487
|
-
|
|
484
|
+
let allChildrenSelected = true;
|
|
485
|
+
for (let i = 0; i < row.subRows.length; i++) {
|
|
486
|
+
const subRow = row.subRows[i];
|
|
487
|
+
if (someSelected && !allChildrenSelected) break;
|
|
488
488
|
if (row_getCanSelect(subRow)) if (isRowSelected(subRow, rowSelection)) someSelected = true;
|
|
489
489
|
else allChildrenSelected = false;
|
|
490
490
|
if (subRow.subRows.length) {
|
|
@@ -495,7 +495,7 @@ function isSubRowSelected(row) {
|
|
|
495
495
|
allChildrenSelected = false;
|
|
496
496
|
} else allChildrenSelected = false;
|
|
497
497
|
}
|
|
498
|
-
}
|
|
498
|
+
}
|
|
499
499
|
return allChildrenSelected ? "all" : someSelected ? "some" : false;
|
|
500
500
|
}
|
|
501
501
|
|
|
@@ -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.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 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 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 * 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((row) => row_getIsSelected(row) || row_getIsSomeSelected(row))\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 if (row_getCanSelect(row) && isSelected === value) {\n return old\n }\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 allChildrenSelected = true\n let someSelected = false\n\n row.subRows.forEach((subRow) => {\n // Bail out early if we know both of these\n if (someSelected && !allChildrenSelected) {\n return\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 // eslint-disable-next-line @typescript-eslint/no-unnecessary-condition\n return allChildrenSelected ? 'all' : someSelected ? 'some' : false\n}\n"],"mappings":";;;;;;;;;;;;;;AA0BA,SAAgB,8BAAiD;CAC/D,OAAOA,4BAAc;AACvB;;;;;;;;;;;;AAaA,SAAgB,sBAId,OACA,SACA;;CACA,iDAAM,SAAQ,iHAAuB,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,iDAAI,KAAM,gBAAe,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,C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AAG;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,EAAEG,qBAAO,cAAc,IAAI,EAAE,KAAK,aAAa,IAAI;AAC7D;;;;;;;;;;;AAYA,SAAgB,iBAGd,KAAsD;;CACtD,IAAI,CAAC,IAAI,QAAQ,QAAQ,OAAO;CAEhC,MAAM,0CAAe,IAAI,MAAM,MAAM,8FAAc,IAAI,MAAK,CAAC;CAE7D,IAAI,sBAAsB;CAC1B,IAAI,eAAe;CAEnB,IAAI,QAAQ,SAAS,WAAW;EAE9B,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,CAAC;CAGD,OAAO,sBAAsB,QAAQ,eAAe,SAAS;AAC/D"}
|
|
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.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 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 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 * 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((row) => row_getIsSelected(row) || row_getIsSomeSelected(row))\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,iDAAM,SAAQ,iHAAuB,OAAO;AAC9C;;;;;;;;;;;;;AAcA,SAAgB,wBAGd,OAA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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"}
|
|
@@ -293,7 +293,6 @@ function row_toggleSelected(row, value, opts) {
|
|
|
293
293
|
const isSelected = row_getIsSelected(row);
|
|
294
294
|
table_setRowSelection(row.table, (old) => {
|
|
295
295
|
value = typeof value !== "undefined" ? value : !isSelected;
|
|
296
|
-
if (row_getCanSelect(row) && isSelected === value) return old;
|
|
297
296
|
const rowSelection = Object.assign(makeObjectMap(), old);
|
|
298
297
|
mutateRowIsSelected(rowSelection, row.id, value, (opts === null || opts === void 0 ? void 0 : opts.selectChildren) ?? true, row.table);
|
|
299
298
|
return rowSelection;
|
|
@@ -481,10 +480,11 @@ function isSubRowSelected(row) {
|
|
|
481
480
|
var _row$table$atoms$rowS2;
|
|
482
481
|
if (!row.subRows.length) return false;
|
|
483
482
|
const rowSelection = ((_row$table$atoms$rowS2 = row.table.atoms.rowSelection) === null || _row$table$atoms$rowS2 === void 0 ? void 0 : _row$table$atoms$rowS2.get()) ?? {};
|
|
484
|
-
let allChildrenSelected = true;
|
|
485
483
|
let someSelected = false;
|
|
486
|
-
|
|
487
|
-
|
|
484
|
+
let allChildrenSelected = true;
|
|
485
|
+
for (let i = 0; i < row.subRows.length; i++) {
|
|
486
|
+
const subRow = row.subRows[i];
|
|
487
|
+
if (someSelected && !allChildrenSelected) break;
|
|
488
488
|
if (row_getCanSelect(subRow)) if (isRowSelected(subRow, rowSelection)) someSelected = true;
|
|
489
489
|
else allChildrenSelected = false;
|
|
490
490
|
if (subRow.subRows.length) {
|
|
@@ -495,7 +495,7 @@ function isSubRowSelected(row) {
|
|
|
495
495
|
allChildrenSelected = false;
|
|
496
496
|
} else allChildrenSelected = false;
|
|
497
497
|
}
|
|
498
|
-
}
|
|
498
|
+
}
|
|
499
499
|
return allChildrenSelected ? "all" : someSelected ? "some" : false;
|
|
500
500
|
}
|
|
501
501
|
|
|
@@ -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.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 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 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 * 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((row) => row_getIsSelected(row) || row_getIsSomeSelected(row))\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 if (row_getCanSelect(row) && isSelected === value) {\n return old\n }\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 allChildrenSelected = true\n let someSelected = false\n\n row.subRows.forEach((subRow) => {\n // Bail out early if we know both of these\n if (someSelected && !allChildrenSelected) {\n return\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 // eslint-disable-next-line @typescript-eslint/no-unnecessary-condition\n return allChildrenSelected ? 'all' : someSelected ? 'some' : false\n}\n"],"mappings":";;;;;;;;;;;;;;AA0BA,SAAgB,8BAAiD;CAC/D,OAAO,cAAc;AACvB;;;;;;;;;;;;AAaA,SAAgB,sBAId,OACA,SACA;;CACA,iDAAM,SAAQ,iHAAuB,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,iDAAI,KAAM,gBAAe,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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cAAc,IAAI,EAAE,KAAK,aAAa,IAAI;AAC7D;;;;;;;;;;;AAYA,SAAgB,iBAGd,KAAsD;;CACtD,IAAI,CAAC,IAAI,QAAQ,QAAQ,OAAO;CAEhC,MAAM,0CAAe,IAAI,MAAM,MAAM,8FAAc,IAAI,MAAK,CAAC;CAE7D,IAAI,sBAAsB;CAC1B,IAAI,eAAe;CAEnB,IAAI,QAAQ,SAAS,WAAW;EAE9B,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,CAAC;CAGD,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 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.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 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 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 * 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((row) => row_getIsSelected(row) || row_getIsSomeSelected(row))\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,iDAAM,SAAQ,iHAAuB,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,cAC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_getIsSomeSelected: {
|
|
63
63
|
fn: (row) => row_getIsSomeSelected(row),
|
|
64
|
+
memoDeps: (row) => [
|
|
65
|
+
row.subRows,
|
|
66
|
+
row.table.atoms.rowSelection?.get(),
|
|
67
|
+
row.table.options.enableRowSelection,
|
|
68
|
+
],
|
|
64
69
|
},
|
|
65
70
|
row_getIsAllSubRowsSelected: {
|
|
66
71
|
fn: (row) => row_getIsAllSubRowsSelected(row),
|
|
72
|
+
memoDeps: (row) => [
|
|
73
|
+
row.subRows,
|
|
74
|
+
row.table.atoms.rowSelection?.get(),
|
|
75
|
+
row.table.options.enableRowSelection,
|
|
76
|
+
],
|
|
67
77
|
},
|
|
68
78
|
row_getCanSelect: {
|
|
69
79
|
fn: (row) => row_getCanSelect(row),
|
|
@@ -497,10 +497,6 @@ export function row_toggleSelected<
|
|
|
497
497
|
table_setRowSelection(row.table, (old) => {
|
|
498
498
|
value = typeof value !== 'undefined' ? value : !isSelected
|
|
499
499
|
|
|
500
|
-
if (row_getCanSelect(row) && isSelected === value) {
|
|
501
|
-
return old
|
|
502
|
-
}
|
|
503
|
-
|
|
504
500
|
const rowSelection = Object.assign(makeObjectMap<true>(), old)
|
|
505
501
|
|
|
506
502
|
mutateRowIsSelected(
|
|
@@ -787,13 +783,15 @@ export function isSubRowSelected<
|
|
|
787
783
|
|
|
788
784
|
const rowSelection = row.table.atoms.rowSelection?.get() ?? {}
|
|
789
785
|
|
|
790
|
-
let allChildrenSelected = true
|
|
791
786
|
let someSelected = false
|
|
787
|
+
let allChildrenSelected = true
|
|
788
|
+
|
|
789
|
+
for (let i = 0; i < row.subRows.length; i++) {
|
|
790
|
+
const subRow = row.subRows[i]!
|
|
792
791
|
|
|
793
|
-
row.subRows.forEach((subRow) => {
|
|
794
792
|
// Bail out early if we know both of these
|
|
795
793
|
if (someSelected && !allChildrenSelected) {
|
|
796
|
-
|
|
794
|
+
break
|
|
797
795
|
}
|
|
798
796
|
|
|
799
797
|
if (row_getCanSelect(subRow)) {
|
|
@@ -816,8 +814,7 @@ export function isSubRowSelected<
|
|
|
816
814
|
allChildrenSelected = false
|
|
817
815
|
}
|
|
818
816
|
}
|
|
819
|
-
}
|
|
817
|
+
}
|
|
820
818
|
|
|
821
|
-
// eslint-disable-next-line @typescript-eslint/no-unnecessary-condition
|
|
822
819
|
return allChildrenSelected ? 'all' : someSelected ? 'some' : false
|
|
823
820
|
}
|