@tanstack/table-core 9.0.0-beta.42 → 9.0.0-beta.44

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
Files changed (81) hide show
  1. package/dist/core/rows/constructRow.cjs +1 -0
  2. package/dist/core/rows/constructRow.cjs.map +1 -1
  3. package/dist/core/rows/constructRow.js +1 -0
  4. package/dist/core/rows/constructRow.js.map +1 -1
  5. package/dist/core/rows/coreRowsFeature.cjs +9 -0
  6. package/dist/core/rows/coreRowsFeature.cjs.map +1 -1
  7. package/dist/core/rows/coreRowsFeature.js +10 -1
  8. package/dist/core/rows/coreRowsFeature.js.map +1 -1
  9. package/dist/core/rows/coreRowsFeature.types.d.cts +24 -0
  10. package/dist/core/rows/coreRowsFeature.types.d.ts +24 -0
  11. package/dist/core/rows/coreRowsFeature.utils.cjs +34 -0
  12. package/dist/core/rows/coreRowsFeature.utils.cjs.map +1 -1
  13. package/dist/core/rows/coreRowsFeature.utils.d.cts +15 -1
  14. package/dist/core/rows/coreRowsFeature.utils.d.ts +15 -1
  15. package/dist/core/rows/coreRowsFeature.utils.js +33 -1
  16. package/dist/core/rows/coreRowsFeature.utils.js.map +1 -1
  17. package/dist/core/table/constructTable.cjs +1 -0
  18. package/dist/core/table/constructTable.cjs.map +1 -1
  19. package/dist/core/table/constructTable.js +1 -0
  20. package/dist/core/table/constructTable.js.map +1 -1
  21. package/dist/core/table/coreTablesFeature.types.d.cts +2 -1
  22. package/dist/core/table/coreTablesFeature.types.d.ts +2 -1
  23. package/dist/core/table/coreTablesFeature.utils.cjs +4 -1
  24. package/dist/core/table/coreTablesFeature.utils.cjs.map +1 -1
  25. package/dist/core/table/coreTablesFeature.utils.d.cts +2 -1
  26. package/dist/core/table/coreTablesFeature.utils.d.ts +2 -1
  27. package/dist/core/table/coreTablesFeature.utils.js +4 -1
  28. package/dist/core/table/coreTablesFeature.utils.js.map +1 -1
  29. package/dist/features/row-selection/rowSelectionFeature.cjs +13 -2
  30. package/dist/features/row-selection/rowSelectionFeature.cjs.map +1 -1
  31. package/dist/features/row-selection/rowSelectionFeature.js +13 -2
  32. package/dist/features/row-selection/rowSelectionFeature.js.map +1 -1
  33. package/dist/features/row-selection/rowSelectionFeature.types.d.cts +35 -5
  34. package/dist/features/row-selection/rowSelectionFeature.types.d.ts +35 -5
  35. package/dist/features/row-selection/rowSelectionFeature.utils.cjs +50 -3
  36. package/dist/features/row-selection/rowSelectionFeature.utils.cjs.map +1 -1
  37. package/dist/features/row-selection/rowSelectionFeature.utils.d.cts +8 -6
  38. package/dist/features/row-selection/rowSelectionFeature.utils.d.ts +8 -6
  39. package/dist/features/row-selection/rowSelectionFeature.utils.js +50 -3
  40. package/dist/features/row-selection/rowSelectionFeature.utils.js.map +1 -1
  41. package/dist/index.d.cts +2 -2
  42. package/dist/index.d.ts +2 -2
  43. package/dist/static-functions.cjs +2 -0
  44. package/dist/static-functions.d.cts +2 -2
  45. package/dist/static-functions.d.ts +2 -2
  46. package/dist/static-functions.js +2 -2
  47. package/dist/types/TableFeatures.d.cts +22 -2
  48. package/dist/types/TableFeatures.d.ts +22 -2
  49. package/package.json +1 -1
  50. package/skills/api-not-found/SKILL.md +1 -1
  51. package/skills/client-vs-server/SKILL.md +1 -1
  52. package/skills/column-faceting/SKILL.md +1 -1
  53. package/skills/column-filtering/SKILL.md +1 -1
  54. package/skills/column-ordering/SKILL.md +1 -1
  55. package/skills/column-pinning/SKILL.md +1 -1
  56. package/skills/column-resizing/SKILL.md +1 -1
  57. package/skills/column-sizing/SKILL.md +1 -1
  58. package/skills/column-visibility/SKILL.md +1 -1
  59. package/skills/core/SKILL.md +37 -2
  60. package/skills/custom-features/SKILL.md +30 -2
  61. package/skills/expanding/SKILL.md +1 -1
  62. package/skills/global-filtering/SKILL.md +1 -1
  63. package/skills/grouping/SKILL.md +1 -1
  64. package/skills/migrate-v8-to-v9/SKILL.md +1 -1
  65. package/skills/pagination/SKILL.md +1 -1
  66. package/skills/row-pinning/SKILL.md +1 -1
  67. package/skills/row-selection/SKILL.md +91 -3
  68. package/skills/sorting/SKILL.md +1 -1
  69. package/skills/table-features/SKILL.md +1 -1
  70. package/skills/typescript/SKILL.md +1 -1
  71. package/src/core/rows/constructRow.ts +1 -0
  72. package/src/core/rows/coreRowsFeature.ts +15 -0
  73. package/src/core/rows/coreRowsFeature.types.ts +24 -0
  74. package/src/core/rows/coreRowsFeature.utils.ts +58 -0
  75. package/src/core/table/constructTable.ts +4 -0
  76. package/src/core/table/coreTablesFeature.types.ts +2 -1
  77. package/src/core/table/coreTablesFeature.utils.ts +7 -1
  78. package/src/features/row-selection/rowSelectionFeature.ts +19 -1
  79. package/src/features/row-selection/rowSelectionFeature.types.ts +37 -3
  80. package/src/features/row-selection/rowSelectionFeature.utils.ts +114 -14
  81. package/src/types/TableFeatures.ts +32 -2
@@ -21,6 +21,7 @@ function getRowPrototype(table) {
21
21
  const constructRow = (table, id, original, rowIndex, depth, subRows, parentId) => {
22
22
  const rowPrototype = getRowPrototype(table);
23
23
  const row = Object.create(rowPrototype);
24
+ row._displayIndexCache = -1;
24
25
  row._uniqueValuesCache = require_utils.makeObjectMap();
25
26
  row._valuesCache = require_utils.makeObjectMap();
26
27
  row.depth = depth;
@@ -1 +1 @@
1
- {"version":3,"file":"constructRow.cjs","names":["makeObjectMap"],"sources":["../../../src/core/rows/constructRow.ts"],"sourcesContent":["import { makeObjectMap } from '../../utils'\nimport type { Table_Internal } from '../../types/Table'\nimport type { RowData } from '../../types/type-utils'\nimport type { TableFeatures } from '../../types/TableFeatures'\nimport type { Row } from '../../types/Row'\nimport type { Row_CoreProperties } from './coreRowsFeature.types'\n\n/**\n * Creates or retrieves the row prototype for a table.\n * The prototype is cached on the table and shared by all row instances.\n */\nfunction getRowPrototype<\n TFeatures extends TableFeatures,\n TData extends RowData,\n>(table: Table_Internal<TFeatures, TData>): object {\n if (!table._rowPrototype) {\n table._rowPrototype = { table }\n const features = Object.values(table._features)\n for (let i = 0; i < features.length; i++) {\n features[i]!.assignRowPrototype?.(table._rowPrototype, table)\n }\n }\n return table._rowPrototype\n}\n\n/**\n * Constructs a row instance from normalized table internals.\n *\n * This wires core properties, feature prototype APIs, and instance data used by table rendering and row-model operations.\n */\nexport const constructRow = <\n TFeatures extends TableFeatures,\n TData extends RowData,\n>(\n table: Table_Internal<TFeatures, TData>,\n id: string,\n original: TData,\n rowIndex: number,\n depth: number,\n subRows?: Array<Row<TFeatures, TData>>,\n parentId?: string,\n): Row<TFeatures, TData> => {\n // Create row with shared prototype for memory efficiency\n const rowPrototype = getRowPrototype(table)\n const row = Object.create(rowPrototype) as Row_CoreProperties<\n TFeatures,\n TData\n >\n\n // Only assign instance-specific properties\n row._uniqueValuesCache = makeObjectMap()\n row._valuesCache = makeObjectMap()\n row.depth = depth\n row.id = id\n row.index = rowIndex\n row.original = original\n row.parentId = parentId\n row.subRows = subRows ?? []\n\n // Initialize instance-specific data (e.g., caches) for features that need it\n const features = Object.values(table._features)\n for (let i = 0; i < features.length; i++) {\n features[i]!.initRowInstanceData?.(row)\n }\n\n return row as Row<TFeatures, TData>\n}\n"],"mappings":";;;;;;;AAWA,SAAS,gBAGP,OAAiD;CACjD,IAAI,CAAC,MAAM,eAAe;EACxB,MAAM,gBAAgB,EAAE,MAAM;EAC9B,MAAM,WAAW,OAAO,OAAO,MAAM,SAAS;EAC9C,KAAK,IAAI,IAAI,GAAG,IAAI,SAAS,QAAQ,KACnC,SAAS,EAAE,CAAE,qBAAqB,MAAM,eAAe,KAAK;CAEhE;CACA,OAAO,MAAM;AACf;;;;;;AAOA,MAAa,gBAIX,OACA,IACA,UACA,UACA,OACA,SACA,aAC0B;CAE1B,MAAM,eAAe,gBAAgB,KAAK;CAC1C,MAAM,MAAM,OAAO,OAAO,YAAY;CAMtC,IAAI,qBAAqBA,4BAAc;CACvC,IAAI,eAAeA,4BAAc;CACjC,IAAI,QAAQ;CACZ,IAAI,KAAK;CACT,IAAI,QAAQ;CACZ,IAAI,WAAW;CACf,IAAI,WAAW;CACf,IAAI,UAAU,WAAW,CAAC;CAG1B,MAAM,WAAW,OAAO,OAAO,MAAM,SAAS;CAC9C,KAAK,IAAI,IAAI,GAAG,IAAI,SAAS,QAAQ,KACnC,SAAS,EAAE,CAAE,sBAAsB,GAAG;CAGxC,OAAO;AACT"}
1
+ {"version":3,"file":"constructRow.cjs","names":["makeObjectMap"],"sources":["../../../src/core/rows/constructRow.ts"],"sourcesContent":["import { makeObjectMap } from '../../utils'\nimport type { Table_Internal } from '../../types/Table'\nimport type { RowData } from '../../types/type-utils'\nimport type { TableFeatures } from '../../types/TableFeatures'\nimport type { Row } from '../../types/Row'\nimport type { Row_CoreProperties } from './coreRowsFeature.types'\n\n/**\n * Creates or retrieves the row prototype for a table.\n * The prototype is cached on the table and shared by all row instances.\n */\nfunction getRowPrototype<\n TFeatures extends TableFeatures,\n TData extends RowData,\n>(table: Table_Internal<TFeatures, TData>): object {\n if (!table._rowPrototype) {\n table._rowPrototype = { table }\n const features = Object.values(table._features)\n for (let i = 0; i < features.length; i++) {\n features[i]!.assignRowPrototype?.(table._rowPrototype, table)\n }\n }\n return table._rowPrototype\n}\n\n/**\n * Constructs a row instance from normalized table internals.\n *\n * This wires core properties, feature prototype APIs, and instance data used by table rendering and row-model operations.\n */\nexport const constructRow = <\n TFeatures extends TableFeatures,\n TData extends RowData,\n>(\n table: Table_Internal<TFeatures, TData>,\n id: string,\n original: TData,\n rowIndex: number,\n depth: number,\n subRows?: Array<Row<TFeatures, TData>>,\n parentId?: string,\n): Row<TFeatures, TData> => {\n // Create row with shared prototype for memory efficiency\n const rowPrototype = getRowPrototype(table)\n const row = Object.create(rowPrototype) as Row_CoreProperties<\n TFeatures,\n TData\n >\n\n // Only assign instance-specific properties\n row._displayIndexCache = -1\n row._uniqueValuesCache = makeObjectMap()\n row._valuesCache = makeObjectMap()\n row.depth = depth\n row.id = id\n row.index = rowIndex\n row.original = original\n row.parentId = parentId\n row.subRows = subRows ?? []\n\n // Initialize instance-specific data (e.g., caches) for features that need it\n const features = Object.values(table._features)\n for (let i = 0; i < features.length; i++) {\n features[i]!.initRowInstanceData?.(row)\n }\n\n return row as Row<TFeatures, TData>\n}\n"],"mappings":";;;;;;;AAWA,SAAS,gBAGP,OAAiD;CACjD,IAAI,CAAC,MAAM,eAAe;EACxB,MAAM,gBAAgB,EAAE,MAAM;EAC9B,MAAM,WAAW,OAAO,OAAO,MAAM,SAAS;EAC9C,KAAK,IAAI,IAAI,GAAG,IAAI,SAAS,QAAQ,KACnC,SAAS,EAAE,CAAE,qBAAqB,MAAM,eAAe,KAAK;CAEhE;CACA,OAAO,MAAM;AACf;;;;;;AAOA,MAAa,gBAIX,OACA,IACA,UACA,UACA,OACA,SACA,aAC0B;CAE1B,MAAM,eAAe,gBAAgB,KAAK;CAC1C,MAAM,MAAM,OAAO,OAAO,YAAY;CAMtC,IAAI,qBAAqB;CACzB,IAAI,qBAAqBA,4BAAc;CACvC,IAAI,eAAeA,4BAAc;CACjC,IAAI,QAAQ;CACZ,IAAI,KAAK;CACT,IAAI,QAAQ;CACZ,IAAI,WAAW;CACf,IAAI,WAAW;CACf,IAAI,UAAU,WAAW,CAAC;CAG1B,MAAM,WAAW,OAAO,OAAO,MAAM,SAAS;CAC9C,KAAK,IAAI,IAAI,GAAG,IAAI,SAAS,QAAQ,KACnC,SAAS,EAAE,CAAE,sBAAsB,GAAG;CAGxC,OAAO;AACT"}
@@ -21,6 +21,7 @@ function getRowPrototype(table) {
21
21
  const constructRow = (table, id, original, rowIndex, depth, subRows, parentId) => {
22
22
  const rowPrototype = getRowPrototype(table);
23
23
  const row = Object.create(rowPrototype);
24
+ row._displayIndexCache = -1;
24
25
  row._uniqueValuesCache = makeObjectMap();
25
26
  row._valuesCache = makeObjectMap();
26
27
  row.depth = depth;
@@ -1 +1 @@
1
- {"version":3,"file":"constructRow.js","names":[],"sources":["../../../src/core/rows/constructRow.ts"],"sourcesContent":["import { makeObjectMap } from '../../utils'\nimport type { Table_Internal } from '../../types/Table'\nimport type { RowData } from '../../types/type-utils'\nimport type { TableFeatures } from '../../types/TableFeatures'\nimport type { Row } from '../../types/Row'\nimport type { Row_CoreProperties } from './coreRowsFeature.types'\n\n/**\n * Creates or retrieves the row prototype for a table.\n * The prototype is cached on the table and shared by all row instances.\n */\nfunction getRowPrototype<\n TFeatures extends TableFeatures,\n TData extends RowData,\n>(table: Table_Internal<TFeatures, TData>): object {\n if (!table._rowPrototype) {\n table._rowPrototype = { table }\n const features = Object.values(table._features)\n for (let i = 0; i < features.length; i++) {\n features[i]!.assignRowPrototype?.(table._rowPrototype, table)\n }\n }\n return table._rowPrototype\n}\n\n/**\n * Constructs a row instance from normalized table internals.\n *\n * This wires core properties, feature prototype APIs, and instance data used by table rendering and row-model operations.\n */\nexport const constructRow = <\n TFeatures extends TableFeatures,\n TData extends RowData,\n>(\n table: Table_Internal<TFeatures, TData>,\n id: string,\n original: TData,\n rowIndex: number,\n depth: number,\n subRows?: Array<Row<TFeatures, TData>>,\n parentId?: string,\n): Row<TFeatures, TData> => {\n // Create row with shared prototype for memory efficiency\n const rowPrototype = getRowPrototype(table)\n const row = Object.create(rowPrototype) as Row_CoreProperties<\n TFeatures,\n TData\n >\n\n // Only assign instance-specific properties\n row._uniqueValuesCache = makeObjectMap()\n row._valuesCache = makeObjectMap()\n row.depth = depth\n row.id = id\n row.index = rowIndex\n row.original = original\n row.parentId = parentId\n row.subRows = subRows ?? []\n\n // Initialize instance-specific data (e.g., caches) for features that need it\n const features = Object.values(table._features)\n for (let i = 0; i < features.length; i++) {\n features[i]!.initRowInstanceData?.(row)\n }\n\n return row as Row<TFeatures, TData>\n}\n"],"mappings":";;;;;;;AAWA,SAAS,gBAGP,OAAiD;CACjD,IAAI,CAAC,MAAM,eAAe;EACxB,MAAM,gBAAgB,EAAE,MAAM;EAC9B,MAAM,WAAW,OAAO,OAAO,MAAM,SAAS;EAC9C,KAAK,IAAI,IAAI,GAAG,IAAI,SAAS,QAAQ,KACnC,SAAS,EAAE,CAAE,qBAAqB,MAAM,eAAe,KAAK;CAEhE;CACA,OAAO,MAAM;AACf;;;;;;AAOA,MAAa,gBAIX,OACA,IACA,UACA,UACA,OACA,SACA,aAC0B;CAE1B,MAAM,eAAe,gBAAgB,KAAK;CAC1C,MAAM,MAAM,OAAO,OAAO,YAAY;CAMtC,IAAI,qBAAqB,cAAc;CACvC,IAAI,eAAe,cAAc;CACjC,IAAI,QAAQ;CACZ,IAAI,KAAK;CACT,IAAI,QAAQ;CACZ,IAAI,WAAW;CACf,IAAI,WAAW;CACf,IAAI,UAAU,WAAW,CAAC;CAG1B,MAAM,WAAW,OAAO,OAAO,MAAM,SAAS;CAC9C,KAAK,IAAI,IAAI,GAAG,IAAI,SAAS,QAAQ,KACnC,SAAS,EAAE,CAAE,sBAAsB,GAAG;CAGxC,OAAO;AACT"}
1
+ {"version":3,"file":"constructRow.js","names":[],"sources":["../../../src/core/rows/constructRow.ts"],"sourcesContent":["import { makeObjectMap } from '../../utils'\nimport type { Table_Internal } from '../../types/Table'\nimport type { RowData } from '../../types/type-utils'\nimport type { TableFeatures } from '../../types/TableFeatures'\nimport type { Row } from '../../types/Row'\nimport type { Row_CoreProperties } from './coreRowsFeature.types'\n\n/**\n * Creates or retrieves the row prototype for a table.\n * The prototype is cached on the table and shared by all row instances.\n */\nfunction getRowPrototype<\n TFeatures extends TableFeatures,\n TData extends RowData,\n>(table: Table_Internal<TFeatures, TData>): object {\n if (!table._rowPrototype) {\n table._rowPrototype = { table }\n const features = Object.values(table._features)\n for (let i = 0; i < features.length; i++) {\n features[i]!.assignRowPrototype?.(table._rowPrototype, table)\n }\n }\n return table._rowPrototype\n}\n\n/**\n * Constructs a row instance from normalized table internals.\n *\n * This wires core properties, feature prototype APIs, and instance data used by table rendering and row-model operations.\n */\nexport const constructRow = <\n TFeatures extends TableFeatures,\n TData extends RowData,\n>(\n table: Table_Internal<TFeatures, TData>,\n id: string,\n original: TData,\n rowIndex: number,\n depth: number,\n subRows?: Array<Row<TFeatures, TData>>,\n parentId?: string,\n): Row<TFeatures, TData> => {\n // Create row with shared prototype for memory efficiency\n const rowPrototype = getRowPrototype(table)\n const row = Object.create(rowPrototype) as Row_CoreProperties<\n TFeatures,\n TData\n >\n\n // Only assign instance-specific properties\n row._displayIndexCache = -1\n row._uniqueValuesCache = makeObjectMap()\n row._valuesCache = makeObjectMap()\n row.depth = depth\n row.id = id\n row.index = rowIndex\n row.original = original\n row.parentId = parentId\n row.subRows = subRows ?? []\n\n // Initialize instance-specific data (e.g., caches) for features that need it\n const features = Object.values(table._features)\n for (let i = 0; i < features.length; i++) {\n features[i]!.initRowInstanceData?.(row)\n }\n\n return row as Row<TFeatures, TData>\n}\n"],"mappings":";;;;;;;AAWA,SAAS,gBAGP,OAAiD;CACjD,IAAI,CAAC,MAAM,eAAe;EACxB,MAAM,gBAAgB,EAAE,MAAM;EAC9B,MAAM,WAAW,OAAO,OAAO,MAAM,SAAS;EAC9C,KAAK,IAAI,IAAI,GAAG,IAAI,SAAS,QAAQ,KACnC,SAAS,EAAE,CAAE,qBAAqB,MAAM,eAAe,KAAK;CAEhE;CACA,OAAO,MAAM;AACf;;;;;;AAOA,MAAa,gBAIX,OACA,IACA,UACA,UACA,OACA,SACA,aAC0B;CAE1B,MAAM,eAAe,gBAAgB,KAAK;CAC1C,MAAM,MAAM,OAAO,OAAO,YAAY;CAMtC,IAAI,qBAAqB;CACzB,IAAI,qBAAqB,cAAc;CACvC,IAAI,eAAe,cAAc;CACjC,IAAI,QAAQ;CACZ,IAAI,KAAK;CACT,IAAI,QAAQ;CACZ,IAAI,WAAW;CACf,IAAI,WAAW;CACf,IAAI,UAAU,WAAW,CAAC;CAG1B,MAAM,WAAW,OAAO,OAAO,MAAM,SAAS;CAC9C,KAAK,IAAI,IAAI,GAAG,IAAI,SAAS,QAAQ,KACnC,SAAS,EAAE,CAAE,sBAAsB,GAAG;CAGxC,OAAO;AACT"}
@@ -8,6 +8,7 @@ const require_coreRowsFeature_utils = require('./coreRowsFeature.utils.cjs');
8
8
  const coreRowsFeature = {
9
9
  assignRowPrototype: (prototype, table) => {
10
10
  require_utils.assignPrototypeAPIs("coreRowsFeature", prototype, table, {
11
+ row_getDisplayIndex: { fn: (row) => require_coreRowsFeature_utils.row_getDisplayIndex(row) },
11
12
  row_getAllCellsByColumnId: {
12
13
  fn: (row) => require_coreRowsFeature_utils.row_getAllCellsByColumnId(row),
13
14
  memoDeps: (row) => [row.getAllCells()]
@@ -29,6 +30,14 @@ const coreRowsFeature = {
29
30
  },
30
31
  constructTableAPIs: (table) => {
31
32
  require_utils.assignTableAPIs("coreRowsFeature", table, {
33
+ table_getRowsInDisplayOrder: {
34
+ fn: () => require_coreRowsFeature_utils.table_getRowsInDisplayOrder(table),
35
+ memoDeps: () => [
36
+ table.getPrePaginatedRowModel().rows,
37
+ table.options.paginateExpandedRows,
38
+ table.options.paginateExpandedRows === false ? table.atoms.expanded?.get() : void 0
39
+ ]
40
+ },
32
41
  table_getRowId: { fn: (originalRow, index, parent) => require_coreRowsFeature_utils.table_getRowId(originalRow, table, index, parent) },
33
42
  table_getRow: { fn: (id, searchAll) => require_coreRowsFeature_utils.table_getRow(table, id, searchAll) }
34
43
  });
@@ -1 +1 @@
1
- {"version":3,"file":"coreRowsFeature.cjs","names":["row_getAllCellsByColumnId","row_getAllCells","row_getLeafRows","row_getParentRow","row_getParentRows","row_getUniqueValues","row_getValue","row_renderValue","table_getRowId","table_getRow"],"sources":["../../../src/core/rows/coreRowsFeature.ts"],"sourcesContent":["import { assignPrototypeAPIs, assignTableAPIs } from '../../utils'\nimport {\n row_getAllCells,\n row_getAllCellsByColumnId,\n row_getLeafRows,\n row_getParentRow,\n row_getParentRows,\n row_getUniqueValues,\n row_getValue,\n row_renderValue,\n table_getRow,\n table_getRowId,\n} from './coreRowsFeature.utils'\nimport type { TableFeature } from '../../types/TableFeatures'\n\n/**\n * Core feature that creates row APIs for values, cells, and tree traversal.\n */\nexport const coreRowsFeature: TableFeature = {\n assignRowPrototype: (prototype, table) => {\n assignPrototypeAPIs('coreRowsFeature', prototype, table, {\n row_getAllCellsByColumnId: {\n fn: (row) => row_getAllCellsByColumnId(row),\n memoDeps: (row) => [row.getAllCells()],\n },\n row_getAllCells: {\n fn: (row) => row_getAllCells(row),\n memoDeps: (row) => [row.table.getAllLeafColumns()],\n },\n row_getLeafRows: {\n fn: (row) => row_getLeafRows(row),\n memoDeps: (row) => [row.subRows],\n },\n row_getParentRow: {\n fn: (row) => row_getParentRow(row),\n },\n row_getParentRows: {\n fn: (row) => row_getParentRows(row),\n },\n row_getUniqueValues: {\n fn: (row, columnId) => row_getUniqueValues(row, columnId),\n },\n row_getValue: {\n fn: (row, columnId) => row_getValue(row, columnId),\n },\n row_renderValue: {\n fn: (row, columnId) => row_renderValue(row, columnId),\n },\n })\n },\n constructTableAPIs: (table) => {\n assignTableAPIs('coreRowsFeature', table, {\n table_getRowId: {\n fn: (originalRow, index, parent) =>\n table_getRowId(originalRow, table, index, parent),\n },\n table_getRow: {\n fn: (id: string, searchAll?: boolean) =>\n table_getRow(table, id, searchAll),\n },\n })\n },\n}\n"],"mappings":";;;;;;;AAkBA,MAAa,kBAAgC;CAC3C,qBAAqB,WAAW,UAAU;EACxC,kCAAoB,mBAAmB,WAAW,OAAO;GACvD,2BAA2B;IACzB,KAAK,QAAQA,wDAA0B,GAAG;IAC1C,WAAW,QAAQ,CAAC,IAAI,YAAY,CAAC;GACvC;GACA,iBAAiB;IACf,KAAK,QAAQC,8CAAgB,GAAG;IAChC,WAAW,QAAQ,CAAC,IAAI,MAAM,kBAAkB,CAAC;GACnD;GACA,iBAAiB;IACf,KAAK,QAAQC,8CAAgB,GAAG;IAChC,WAAW,QAAQ,CAAC,IAAI,OAAO;GACjC;GACA,kBAAkB,EAChB,KAAK,QAAQC,+CAAiB,GAAG,EACnC;GACA,mBAAmB,EACjB,KAAK,QAAQC,gDAAkB,GAAG,EACpC;GACA,qBAAqB,EACnB,KAAK,KAAK,aAAaC,kDAAoB,KAAK,QAAQ,EAC1D;GACA,cAAc,EACZ,KAAK,KAAK,aAAaC,2CAAa,KAAK,QAAQ,EACnD;GACA,iBAAiB,EACf,KAAK,KAAK,aAAaC,8CAAgB,KAAK,QAAQ,EACtD;EACF,CAAC;CACH;CACA,qBAAqB,UAAU;EAC7B,8BAAgB,mBAAmB,OAAO;GACxC,gBAAgB,EACd,KAAK,aAAa,OAAO,WACvBC,6CAAe,aAAa,OAAO,OAAO,MAAM,EACpD;GACA,cAAc,EACZ,KAAK,IAAY,cACfC,2CAAa,OAAO,IAAI,SAAS,EACrC;EACF,CAAC;CACH;AACF"}
1
+ {"version":3,"file":"coreRowsFeature.cjs","names":["row_getDisplayIndex","row_getAllCellsByColumnId","row_getAllCells","row_getLeafRows","row_getParentRow","row_getParentRows","row_getUniqueValues","row_getValue","row_renderValue","table_getRowsInDisplayOrder","table_getRowId","table_getRow"],"sources":["../../../src/core/rows/coreRowsFeature.ts"],"sourcesContent":["import { assignPrototypeAPIs, assignTableAPIs } from '../../utils'\nimport {\n row_getAllCells,\n row_getAllCellsByColumnId,\n row_getDisplayIndex,\n row_getLeafRows,\n row_getParentRow,\n row_getParentRows,\n row_getUniqueValues,\n row_getValue,\n row_renderValue,\n table_getRow,\n table_getRowId,\n table_getRowsInDisplayOrder,\n} from './coreRowsFeature.utils'\nimport type { TableFeature } from '../../types/TableFeatures'\n\n/**\n * Core feature that creates row APIs for values, cells, and tree traversal.\n */\nexport const coreRowsFeature: TableFeature = {\n assignRowPrototype: (prototype, table) => {\n assignPrototypeAPIs('coreRowsFeature', prototype, table, {\n row_getDisplayIndex: {\n fn: (row) => row_getDisplayIndex(row),\n },\n row_getAllCellsByColumnId: {\n fn: (row) => row_getAllCellsByColumnId(row),\n memoDeps: (row) => [row.getAllCells()],\n },\n row_getAllCells: {\n fn: (row) => row_getAllCells(row),\n memoDeps: (row) => [row.table.getAllLeafColumns()],\n },\n row_getLeafRows: {\n fn: (row) => row_getLeafRows(row),\n memoDeps: (row) => [row.subRows],\n },\n row_getParentRow: {\n fn: (row) => row_getParentRow(row),\n },\n row_getParentRows: {\n fn: (row) => row_getParentRows(row),\n },\n row_getUniqueValues: {\n fn: (row, columnId) => row_getUniqueValues(row, columnId),\n },\n row_getValue: {\n fn: (row, columnId) => row_getValue(row, columnId),\n },\n row_renderValue: {\n fn: (row, columnId) => row_renderValue(row, columnId),\n },\n })\n },\n constructTableAPIs: (table) => {\n assignTableAPIs('coreRowsFeature', table, {\n table_getRowsInDisplayOrder: {\n fn: () => table_getRowsInDisplayOrder(table),\n memoDeps: () => [\n table.getPrePaginatedRowModel().rows,\n table.options.paginateExpandedRows,\n table.options.paginateExpandedRows === false\n ? table.atoms.expanded?.get()\n : undefined,\n ],\n },\n table_getRowId: {\n fn: (originalRow, index, parent) =>\n table_getRowId(originalRow, table, index, parent),\n },\n table_getRow: {\n fn: (id: string, searchAll?: boolean) =>\n table_getRow(table, id, searchAll),\n },\n })\n },\n}\n"],"mappings":";;;;;;;AAoBA,MAAa,kBAAgC;CAC3C,qBAAqB,WAAW,UAAU;EACxC,kCAAoB,mBAAmB,WAAW,OAAO;GACvD,qBAAqB,EACnB,KAAK,QAAQA,kDAAoB,GAAG,EACtC;GACA,2BAA2B;IACzB,KAAK,QAAQC,wDAA0B,GAAG;IAC1C,WAAW,QAAQ,CAAC,IAAI,YAAY,CAAC;GACvC;GACA,iBAAiB;IACf,KAAK,QAAQC,8CAAgB,GAAG;IAChC,WAAW,QAAQ,CAAC,IAAI,MAAM,kBAAkB,CAAC;GACnD;GACA,iBAAiB;IACf,KAAK,QAAQC,8CAAgB,GAAG;IAChC,WAAW,QAAQ,CAAC,IAAI,OAAO;GACjC;GACA,kBAAkB,EAChB,KAAK,QAAQC,+CAAiB,GAAG,EACnC;GACA,mBAAmB,EACjB,KAAK,QAAQC,gDAAkB,GAAG,EACpC;GACA,qBAAqB,EACnB,KAAK,KAAK,aAAaC,kDAAoB,KAAK,QAAQ,EAC1D;GACA,cAAc,EACZ,KAAK,KAAK,aAAaC,2CAAa,KAAK,QAAQ,EACnD;GACA,iBAAiB,EACf,KAAK,KAAK,aAAaC,8CAAgB,KAAK,QAAQ,EACtD;EACF,CAAC;CACH;CACA,qBAAqB,UAAU;EAC7B,8BAAgB,mBAAmB,OAAO;GACxC,6BAA6B;IAC3B,UAAUC,0DAA4B,KAAK;IAC3C,gBAAgB;KACd,MAAM,wBAAwB,CAAC,CAAC;KAChC,MAAM,QAAQ;KACd,MAAM,QAAQ,yBAAyB,QACnC,MAAM,MAAM,UAAU,IAAI,IAC1B;IACN;GACF;GACA,gBAAgB,EACd,KAAK,aAAa,OAAO,WACvBC,6CAAe,aAAa,OAAO,OAAO,MAAM,EACpD;GACA,cAAc,EACZ,KAAK,IAAY,cACfC,2CAAa,OAAO,IAAI,SAAS,EACrC;EACF,CAAC;CACH;AACF"}
@@ -1,5 +1,5 @@
1
1
  import { assignPrototypeAPIs, assignTableAPIs } from "../../utils.js";
2
- import { row_getAllCells, row_getAllCellsByColumnId, row_getLeafRows, row_getParentRow, row_getParentRows, row_getUniqueValues, row_getValue, row_renderValue, table_getRow, table_getRowId } from "./coreRowsFeature.utils.js";
2
+ import { row_getAllCells, row_getAllCellsByColumnId, row_getDisplayIndex, row_getLeafRows, row_getParentRow, row_getParentRows, row_getUniqueValues, row_getValue, row_renderValue, table_getRow, table_getRowId, table_getRowsInDisplayOrder } from "./coreRowsFeature.utils.js";
3
3
 
4
4
  //#region src/core/rows/coreRowsFeature.ts
5
5
  /**
@@ -8,6 +8,7 @@ import { row_getAllCells, row_getAllCellsByColumnId, row_getLeafRows, row_getPar
8
8
  const coreRowsFeature = {
9
9
  assignRowPrototype: (prototype, table) => {
10
10
  assignPrototypeAPIs("coreRowsFeature", prototype, table, {
11
+ row_getDisplayIndex: { fn: (row) => row_getDisplayIndex(row) },
11
12
  row_getAllCellsByColumnId: {
12
13
  fn: (row) => row_getAllCellsByColumnId(row),
13
14
  memoDeps: (row) => [row.getAllCells()]
@@ -29,6 +30,14 @@ const coreRowsFeature = {
29
30
  },
30
31
  constructTableAPIs: (table) => {
31
32
  assignTableAPIs("coreRowsFeature", table, {
33
+ table_getRowsInDisplayOrder: {
34
+ fn: () => table_getRowsInDisplayOrder(table),
35
+ memoDeps: () => [
36
+ table.getPrePaginatedRowModel().rows,
37
+ table.options.paginateExpandedRows,
38
+ table.options.paginateExpandedRows === false ? table.atoms.expanded?.get() : void 0
39
+ ]
40
+ },
32
41
  table_getRowId: { fn: (originalRow, index, parent) => table_getRowId(originalRow, table, index, parent) },
33
42
  table_getRow: { fn: (id, searchAll) => table_getRow(table, id, searchAll) }
34
43
  });
@@ -1 +1 @@
1
- {"version":3,"file":"coreRowsFeature.js","names":[],"sources":["../../../src/core/rows/coreRowsFeature.ts"],"sourcesContent":["import { assignPrototypeAPIs, assignTableAPIs } from '../../utils'\nimport {\n row_getAllCells,\n row_getAllCellsByColumnId,\n row_getLeafRows,\n row_getParentRow,\n row_getParentRows,\n row_getUniqueValues,\n row_getValue,\n row_renderValue,\n table_getRow,\n table_getRowId,\n} from './coreRowsFeature.utils'\nimport type { TableFeature } from '../../types/TableFeatures'\n\n/**\n * Core feature that creates row APIs for values, cells, and tree traversal.\n */\nexport const coreRowsFeature: TableFeature = {\n assignRowPrototype: (prototype, table) => {\n assignPrototypeAPIs('coreRowsFeature', prototype, table, {\n row_getAllCellsByColumnId: {\n fn: (row) => row_getAllCellsByColumnId(row),\n memoDeps: (row) => [row.getAllCells()],\n },\n row_getAllCells: {\n fn: (row) => row_getAllCells(row),\n memoDeps: (row) => [row.table.getAllLeafColumns()],\n },\n row_getLeafRows: {\n fn: (row) => row_getLeafRows(row),\n memoDeps: (row) => [row.subRows],\n },\n row_getParentRow: {\n fn: (row) => row_getParentRow(row),\n },\n row_getParentRows: {\n fn: (row) => row_getParentRows(row),\n },\n row_getUniqueValues: {\n fn: (row, columnId) => row_getUniqueValues(row, columnId),\n },\n row_getValue: {\n fn: (row, columnId) => row_getValue(row, columnId),\n },\n row_renderValue: {\n fn: (row, columnId) => row_renderValue(row, columnId),\n },\n })\n },\n constructTableAPIs: (table) => {\n assignTableAPIs('coreRowsFeature', table, {\n table_getRowId: {\n fn: (originalRow, index, parent) =>\n table_getRowId(originalRow, table, index, parent),\n },\n table_getRow: {\n fn: (id: string, searchAll?: boolean) =>\n table_getRow(table, id, searchAll),\n },\n })\n },\n}\n"],"mappings":";;;;;;;AAkBA,MAAa,kBAAgC;CAC3C,qBAAqB,WAAW,UAAU;EACxC,oBAAoB,mBAAmB,WAAW,OAAO;GACvD,2BAA2B;IACzB,KAAK,QAAQ,0BAA0B,GAAG;IAC1C,WAAW,QAAQ,CAAC,IAAI,YAAY,CAAC;GACvC;GACA,iBAAiB;IACf,KAAK,QAAQ,gBAAgB,GAAG;IAChC,WAAW,QAAQ,CAAC,IAAI,MAAM,kBAAkB,CAAC;GACnD;GACA,iBAAiB;IACf,KAAK,QAAQ,gBAAgB,GAAG;IAChC,WAAW,QAAQ,CAAC,IAAI,OAAO;GACjC;GACA,kBAAkB,EAChB,KAAK,QAAQ,iBAAiB,GAAG,EACnC;GACA,mBAAmB,EACjB,KAAK,QAAQ,kBAAkB,GAAG,EACpC;GACA,qBAAqB,EACnB,KAAK,KAAK,aAAa,oBAAoB,KAAK,QAAQ,EAC1D;GACA,cAAc,EACZ,KAAK,KAAK,aAAa,aAAa,KAAK,QAAQ,EACnD;GACA,iBAAiB,EACf,KAAK,KAAK,aAAa,gBAAgB,KAAK,QAAQ,EACtD;EACF,CAAC;CACH;CACA,qBAAqB,UAAU;EAC7B,gBAAgB,mBAAmB,OAAO;GACxC,gBAAgB,EACd,KAAK,aAAa,OAAO,WACvB,eAAe,aAAa,OAAO,OAAO,MAAM,EACpD;GACA,cAAc,EACZ,KAAK,IAAY,cACf,aAAa,OAAO,IAAI,SAAS,EACrC;EACF,CAAC;CACH;AACF"}
1
+ {"version":3,"file":"coreRowsFeature.js","names":[],"sources":["../../../src/core/rows/coreRowsFeature.ts"],"sourcesContent":["import { assignPrototypeAPIs, assignTableAPIs } from '../../utils'\nimport {\n row_getAllCells,\n row_getAllCellsByColumnId,\n row_getDisplayIndex,\n row_getLeafRows,\n row_getParentRow,\n row_getParentRows,\n row_getUniqueValues,\n row_getValue,\n row_renderValue,\n table_getRow,\n table_getRowId,\n table_getRowsInDisplayOrder,\n} from './coreRowsFeature.utils'\nimport type { TableFeature } from '../../types/TableFeatures'\n\n/**\n * Core feature that creates row APIs for values, cells, and tree traversal.\n */\nexport const coreRowsFeature: TableFeature = {\n assignRowPrototype: (prototype, table) => {\n assignPrototypeAPIs('coreRowsFeature', prototype, table, {\n row_getDisplayIndex: {\n fn: (row) => row_getDisplayIndex(row),\n },\n row_getAllCellsByColumnId: {\n fn: (row) => row_getAllCellsByColumnId(row),\n memoDeps: (row) => [row.getAllCells()],\n },\n row_getAllCells: {\n fn: (row) => row_getAllCells(row),\n memoDeps: (row) => [row.table.getAllLeafColumns()],\n },\n row_getLeafRows: {\n fn: (row) => row_getLeafRows(row),\n memoDeps: (row) => [row.subRows],\n },\n row_getParentRow: {\n fn: (row) => row_getParentRow(row),\n },\n row_getParentRows: {\n fn: (row) => row_getParentRows(row),\n },\n row_getUniqueValues: {\n fn: (row, columnId) => row_getUniqueValues(row, columnId),\n },\n row_getValue: {\n fn: (row, columnId) => row_getValue(row, columnId),\n },\n row_renderValue: {\n fn: (row, columnId) => row_renderValue(row, columnId),\n },\n })\n },\n constructTableAPIs: (table) => {\n assignTableAPIs('coreRowsFeature', table, {\n table_getRowsInDisplayOrder: {\n fn: () => table_getRowsInDisplayOrder(table),\n memoDeps: () => [\n table.getPrePaginatedRowModel().rows,\n table.options.paginateExpandedRows,\n table.options.paginateExpandedRows === false\n ? table.atoms.expanded?.get()\n : undefined,\n ],\n },\n table_getRowId: {\n fn: (originalRow, index, parent) =>\n table_getRowId(originalRow, table, index, parent),\n },\n table_getRow: {\n fn: (id: string, searchAll?: boolean) =>\n table_getRow(table, id, searchAll),\n },\n })\n },\n}\n"],"mappings":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
9
9
  interface Row_CoreProperties<in out TFeatures extends TableFeatures, in out TData extends RowData> {
10
10
  _cellsCache?: WeakMap<Column<TFeatures, TData, unknown>, Cell<TFeatures, TData, unknown>>;
11
+ /**
12
+ * Internal cache used while resolving the current display order.
13
+ *
14
+ * This value may be stale until display order is recomputed. Use
15
+ * `row.getDisplayIndex()` instead; it refreshes and validates the cached
16
+ * position before returning it.
17
+ *
18
+ * @internal
19
+ */
20
+ _displayIndexCache: number;
11
21
  _uniqueValuesCache: Record<string, unknown>;
12
22
  _valuesCache: Record<string, unknown>;
13
23
  /**
@@ -44,6 +54,13 @@ interface Row_CoreProperties<in out TFeatures extends TableFeatures, in out TDat
44
54
  table: Table<TFeatures, TData>;
45
55
  }
46
56
  interface Row_Row<in out TFeatures extends TableFeatures, in out TData extends RowData> extends Row_CoreProperties<TFeatures, TData> {
57
+ /**
58
+ * Returns the zero-based index of the row in the current display order
59
+ * before pagination, or `-1` if the row is not in that model. Use this for
60
+ * display row-number columns instead of `row.index` or the internal
61
+ * `_displayIndexCache` field.
62
+ */
63
+ getDisplayIndex: () => number;
47
64
  /**
48
65
  * Builds a lookup of this row's cells keyed by leaf column id.
49
66
  */
@@ -90,6 +107,13 @@ interface TableOptions_Rows<in out TFeatures extends TableFeatures, in out TData
90
107
  getSubRows?: (originalRow: TData, index: number) => undefined | ReadonlyArray<TData>;
91
108
  }
92
109
  interface Table_Rows<in out TFeatures extends TableFeatures, in out TData extends RowData> {
110
+ /**
111
+ * Returns the rows in the current display order and assigns their display
112
+ * indexes. When expanded rows bypass pagination, expanded descendants are
113
+ * included in this order. This is the memoized source for
114
+ * `row.getDisplayIndex()`.
115
+ */
116
+ getRowsInDisplayOrder: () => Array<Row<TFeatures, TData>>;
93
117
  getRowId: (_: TData, index: number, parent?: Row<TFeatures, TData>) => string;
94
118
  /**
95
119
  * Returns the row with the given ID.
@@ -8,6 +8,16 @@ import { TableFeatures } from "../../types/TableFeatures.js";
8
8
  //#region src/core/rows/coreRowsFeature.types.d.ts
9
9
  interface Row_CoreProperties<in out TFeatures extends TableFeatures, in out TData extends RowData> {
10
10
  _cellsCache?: WeakMap<Column<TFeatures, TData, unknown>, Cell<TFeatures, TData, unknown>>;
11
+ /**
12
+ * Internal cache used while resolving the current display order.
13
+ *
14
+ * This value may be stale until display order is recomputed. Use
15
+ * `row.getDisplayIndex()` instead; it refreshes and validates the cached
16
+ * position before returning it.
17
+ *
18
+ * @internal
19
+ */
20
+ _displayIndexCache: number;
11
21
  _uniqueValuesCache: Record<string, unknown>;
12
22
  _valuesCache: Record<string, unknown>;
13
23
  /**
@@ -44,6 +54,13 @@ interface Row_CoreProperties<in out TFeatures extends TableFeatures, in out TDat
44
54
  table: Table<TFeatures, TData>;
45
55
  }
46
56
  interface Row_Row<in out TFeatures extends TableFeatures, in out TData extends RowData> extends Row_CoreProperties<TFeatures, TData> {
57
+ /**
58
+ * Returns the zero-based index of the row in the current display order
59
+ * before pagination, or `-1` if the row is not in that model. Use this for
60
+ * display row-number columns instead of `row.index` or the internal
61
+ * `_displayIndexCache` field.
62
+ */
63
+ getDisplayIndex: () => number;
47
64
  /**
48
65
  * Builds a lookup of this row's cells keyed by leaf column id.
49
66
  */
@@ -90,6 +107,13 @@ interface TableOptions_Rows<in out TFeatures extends TableFeatures, in out TData
90
107
  getSubRows?: (originalRow: TData, index: number) => undefined | ReadonlyArray<TData>;
91
108
  }
92
109
  interface Table_Rows<in out TFeatures extends TableFeatures, in out TData extends RowData> {
110
+ /**
111
+ * Returns the rows in the current display order and assigns their display
112
+ * indexes. When expanded rows bypass pagination, expanded descendants are
113
+ * included in this order. This is the memoized source for
114
+ * `row.getDisplayIndex()`.
115
+ */
116
+ getRowsInDisplayOrder: () => Array<Row<TFeatures, TData>>;
93
117
  getRowId: (_: TData, index: number, parent?: Row<TFeatures, TData>) => string;
94
118
  /**
95
119
  * Returns the row with the given ID.
@@ -3,6 +3,38 @@ const require_constructCell = require('../cells/constructCell.cjs');
3
3
 
4
4
  //#region src/core/rows/coreRowsFeature.utils.ts
5
5
  /**
6
+ * Returns this row's zero-based position in the current pre-pagination row
7
+ * model. Rows outside that model return `-1`.
8
+ */
9
+ function row_getDisplayIndex(row) {
10
+ const rows = row.table.getRowsInDisplayOrder();
11
+ const displayIndex = row._displayIndexCache;
12
+ return rows[displayIndex] === row ? displayIndex : -1;
13
+ }
14
+ /**
15
+ * Returns the rows in the current display order after assigning their
16
+ * zero-based display indexes.
17
+ *
18
+ * When expanded rows bypass pagination, expanded descendants are inserted into
19
+ * the returned order even though they are absent from the pre-pagination row
20
+ * model.
21
+ */
22
+ function table_getRowsInDisplayOrder(table) {
23
+ const rows = table.getPrePaginatedRowModel().rows;
24
+ if (table.options.paginateExpandedRows === false) {
25
+ const displayRows = [];
26
+ const handleRow = (row) => {
27
+ row._displayIndexCache = displayRows.length;
28
+ displayRows.push(row);
29
+ if (row.subRows.length && row.getIsExpanded?.()) row.subRows.forEach(handleRow);
30
+ };
31
+ rows.forEach(handleRow);
32
+ return displayRows;
33
+ }
34
+ for (let i = 0; i < rows.length; i++) rows[i]._displayIndexCache = i;
35
+ return rows;
36
+ }
37
+ /**
6
38
  * Reads and caches this row's value for a column.
7
39
  *
8
40
  * The value is produced by the column accessor. Missing columns or display
@@ -190,6 +222,7 @@ function table_getRow(table, rowId, searchAll) {
190
222
  //#endregion
191
223
  exports.row_getAllCells = row_getAllCells;
192
224
  exports.row_getAllCellsByColumnId = row_getAllCellsByColumnId;
225
+ exports.row_getDisplayIndex = row_getDisplayIndex;
193
226
  exports.row_getLeafRows = row_getLeafRows;
194
227
  exports.row_getParentRow = row_getParentRow;
195
228
  exports.row_getParentRows = row_getParentRows;
@@ -198,4 +231,5 @@ exports.row_getValue = row_getValue;
198
231
  exports.row_renderValue = row_renderValue;
199
232
  exports.table_getRow = table_getRow;
200
233
  exports.table_getRowId = table_getRowId;
234
+ exports.table_getRowsInDisplayOrder = table_getRowsInDisplayOrder;
201
235
  //# sourceMappingURL=coreRowsFeature.utils.cjs.map
@@ -1 +1 @@
1
- {"version":3,"file":"coreRowsFeature.utils.cjs","names":["hasOwn","flattenBy","constructCell","makeObjectMap"],"sources":["../../../src/core/rows/coreRowsFeature.utils.ts"],"sourcesContent":["import { flattenBy, hasOwn, makeObjectMap } from '../../utils'\nimport { constructCell } from '../cells/constructCell'\nimport type { Table_Internal } from '../../types/Table'\nimport type { RowData } from '../../types/type-utils'\nimport type { TableFeatures } from '../../types/TableFeatures'\nimport type { Row } from '../../types/Row'\nimport type { Cell } from '../../types/Cell'\n\n/**\n * Reads and caches this row's value for a column.\n *\n * The value is produced by the column accessor. Missing columns or display\n * columns without an accessor return `undefined`.\n *\n * @example\n * ```ts\n * const firstName = row_getValue(row, 'firstName')\n * ```\n */\nexport function row_getValue<\n TFeatures extends TableFeatures,\n TData extends RowData,\n>(row: Row<TFeatures, TData>, columnId: string) {\n if (hasOwn(row._valuesCache, columnId)) {\n return row._valuesCache[columnId]\n }\n\n const column = row.table.getColumn(columnId)\n\n if (!column?.accessorFn) {\n return undefined\n }\n\n row._valuesCache[columnId] = column.accessorFn(row.original, row.index)\n\n return row._valuesCache[columnId]\n}\n\n/**\n * Reads and caches the values used by faceting/grouping for a column.\n *\n * If the column defines `getUniqueValues`, that result is used. Otherwise the\n * row's accessor value is wrapped in a single-item array.\n *\n * @example\n * ```ts\n * const values = row_getUniqueValues(row, 'tags')\n * ```\n */\nexport function row_getUniqueValues<\n TFeatures extends TableFeatures,\n TData extends RowData,\n>(row: Row<TFeatures, TData>, columnId: string) {\n if (hasOwn(row._uniqueValuesCache, columnId)) {\n return row._uniqueValuesCache[columnId]\n }\n\n const column = row.table.getColumn(columnId)\n\n if (!column?.accessorFn) {\n return undefined\n }\n\n if (!column.columnDef.getUniqueValues) {\n row._uniqueValuesCache[columnId] = [row.getValue(columnId)]\n return row._uniqueValuesCache[columnId]\n }\n\n row._uniqueValuesCache[columnId] = column.columnDef.getUniqueValues(\n row.original,\n row.index,\n )\n\n return row._uniqueValuesCache[columnId]\n}\n\n/**\n * Returns a renderable row value for a column.\n *\n * If the accessor value is nullish, the table's `renderFallbackValue` is used\n * instead.\n *\n * @example\n * ```ts\n * const value = row_renderValue(row, 'firstName')\n * ```\n */\nexport function row_renderValue<\n TFeatures extends TableFeatures,\n TData extends RowData,\n>(row: Row<TFeatures, TData>, columnId: string) {\n return row.getValue(columnId) ?? row.table.options.renderFallbackValue\n}\n\n/**\n * Flattens this row's descendant tree into leaf rows.\n *\n * The row itself is not included; only nested `subRows` are walked.\n *\n * @example\n * ```ts\n * const descendants = row_getLeafRows(row)\n * ```\n */\nexport function row_getLeafRows<\n TFeatures extends TableFeatures,\n TData extends RowData,\n>(row: Row<TFeatures, TData>): Array<Row<TFeatures, TData>> {\n return flattenBy(row.subRows, (d) => d.subRows)\n}\n\n/**\n * Looks up this row's direct parent, if it has one.\n *\n * Parent lookup searches the pre-pagination row model so parent relationships\n * are available even when the parent is not on the current page.\n *\n * @example\n * ```ts\n * const parent = row_getParentRow(row)\n * ```\n */\nexport function row_getParentRow<\n TFeatures extends TableFeatures,\n TData extends RowData,\n>(row: Row<TFeatures, TData>) {\n return row.parentId ? row.table.getRow(row.parentId, true) : undefined\n}\n\n/**\n * Collects this row's ancestor chain from root to direct parent.\n *\n * The current row is not included. Rows without a parent return an empty array.\n *\n * @example\n * ```ts\n * const ancestors = row_getParentRows(row)\n * ```\n */\nexport function row_getParentRows<\n TFeatures extends TableFeatures,\n TData extends RowData,\n>(row: Row<TFeatures, TData>) {\n const parentRows: Array<Row<TFeatures, TData>> = []\n let currentRow = row\n // eslint-disable-next-line @typescript-eslint/no-unnecessary-condition\n while (true) {\n const parentRow = currentRow.getParentRow()\n if (!parentRow) break\n parentRows.push(parentRow)\n currentRow = parentRow\n }\n return parentRows.reverse()\n}\n\n/**\n * Constructs one cell for each leaf column in this row.\n *\n * The result follows `table.getAllLeafColumns()` order and includes hidden\n * columns; visibility-specific APIs filter this list later.\n *\n * @example\n * ```ts\n * const cells = row_getAllCells(row)\n * ```\n */\nexport function row_getAllCells<\n TFeatures extends TableFeatures,\n TData extends RowData,\n>(row: Row<TFeatures, TData>): Array<Cell<TFeatures, TData, unknown>> {\n const columns = row.table.getAllLeafColumns()\n // WeakMap so cells keyed by replaced column instances can be collected;\n // rows are memoized on data only and outlive column generations\n let cache = row._cellsCache\n if (!cache) {\n cache = row._cellsCache = new WeakMap()\n }\n const cells: Array<Cell<TFeatures, TData, unknown>> = new Array(\n columns.length,\n )\n for (let i = 0; i < columns.length; i++) {\n const column = columns[i]!\n let cell = cache.get(column)\n if (!cell) {\n cell = constructCell(column, row, row.table)\n cache.set(column, cell)\n }\n cells[i] = cell\n }\n return cells\n}\n\n/**\n * Builds a lookup map of this row's cells keyed by column id.\n *\n * This is the static implementation behind `row.getAllCellsByColumnId()`.\n *\n * @example\n * ```ts\n * const cellsById = row_getAllCellsByColumnId(row)\n * ```\n */\nexport function row_getAllCellsByColumnId<\n TFeatures extends TableFeatures,\n TData extends RowData,\n>(row: Row<TFeatures, TData>) {\n const result = makeObjectMap<Cell<TFeatures, TData, unknown>>()\n const cells = row.getAllCells()\n for (let i = 0; i < cells.length; i++) {\n const cell = cells[i]!\n result[cell.column.id] = cell\n }\n return result\n}\n\n/**\n * Resolves the stable id for a row.\n *\n * `options.getRowId` wins when provided. Otherwise root rows use their index\n * and child rows append their index to the parent id, such as `0.2`.\n *\n * @example\n * ```ts\n * const id = table_getRowId(originalRow, table, index, parentRow)\n * ```\n */\nexport function table_getRowId<\n TFeatures extends TableFeatures,\n TData extends RowData,\n>(\n originalRow: TData,\n table: Table_Internal<TFeatures, TData>,\n index: number,\n parent?: Row<TFeatures, TData>,\n) {\n return (\n table.options.getRowId?.(originalRow, index, parent) ??\n `${parent ? [parent.id, index].join('.') : index}`\n )\n}\n\n/**\n * Looks up a row by id from the current or full row model.\n *\n * By default this searches `table.getRowModel()`. Passing `searchAll` searches\n * the pre-pagination model first, then falls back to the core model.\n *\n * @example\n * ```ts\n * const row = table_getRow(table, rowId, true)\n * ```\n */\nexport function table_getRow<\n TFeatures extends TableFeatures,\n TData extends RowData,\n>(\n table: Table_Internal<TFeatures, TData>,\n rowId: string,\n searchAll?: boolean,\n): Row<TFeatures, TData> {\n // TODO - simplify this across different row models\n let row = (searchAll ? table.getPrePaginatedRowModel() : table.getRowModel())\n .rowsById[rowId]\n\n if (!row) {\n row = table.getCoreRowModel().rowsById[rowId]\n if (!row) {\n if (process.env.NODE_ENV === 'development') {\n throw new Error(`getRow could not find row with ID: ${rowId}`)\n }\n throw new Error()\n }\n }\n\n return row\n}\n"],"mappings":";;;;;;;;;;;;;;;AAmBA,SAAgB,aAGd,KAA4B,UAAkB;CAC9C,IAAIA,qBAAO,IAAI,cAAc,QAAQ,GACnC,OAAO,IAAI,aAAa;CAG1B,MAAM,SAAS,IAAI,MAAM,UAAU,QAAQ;CAE3C,IAAI,CAAC,QAAQ,YACX;CAGF,IAAI,aAAa,YAAY,OAAO,WAAW,IAAI,UAAU,IAAI,KAAK;CAEtE,OAAO,IAAI,aAAa;AAC1B;;;;;;;;;;;;AAaA,SAAgB,oBAGd,KAA4B,UAAkB;CAC9C,IAAIA,qBAAO,IAAI,oBAAoB,QAAQ,GACzC,OAAO,IAAI,mBAAmB;CAGhC,MAAM,SAAS,IAAI,MAAM,UAAU,QAAQ;CAE3C,IAAI,CAAC,QAAQ,YACX;CAGF,IAAI,CAAC,OAAO,UAAU,iBAAiB;EACrC,IAAI,mBAAmB,YAAY,CAAC,IAAI,SAAS,QAAQ,CAAC;EAC1D,OAAO,IAAI,mBAAmB;CAChC;CAEA,IAAI,mBAAmB,YAAY,OAAO,UAAU,gBAClD,IAAI,UACJ,IAAI,KACN;CAEA,OAAO,IAAI,mBAAmB;AAChC;;;;;;;;;;;;AAaA,SAAgB,gBAGd,KAA4B,UAAkB;CAC9C,OAAO,IAAI,SAAS,QAAQ,KAAK,IAAI,MAAM,QAAQ;AACrD;;;;;;;;;;;AAYA,SAAgB,gBAGd,KAA0D;CAC1D,OAAOC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AAC,CAAC,KAAK,GAAG,IAAI;AAE/C;;;;;;;;;;;;AAaA,SAAgB,aAId,OACA,OACA,WACuB;CAEvB,IAAI,OAAO,YAAY,MAAM,wBAAwB,IAAI,MAAM,YAAY,EAAC,CACzE,SAAS;CAEZ,IAAI,CAAC,KAAK;EACR,MAAM,MAAM,gBAAgB,CAAC,CAAC,SAAS;EACvC,IAAI,CAAC,KAAK;GACR,IAAI,QAAQ,IAAI,aAAa,eAC3B,MAAM,IAAI,MAAM,sCAAsC,OAAO;GAE/D,MAAM,IAAI,MAAM;EAClB;CACF;CAEA,OAAO;AACT"}
1
+ {"version":3,"file":"coreRowsFeature.utils.cjs","names":["hasOwn","flattenBy","constructCell","makeObjectMap"],"sources":["../../../src/core/rows/coreRowsFeature.utils.ts"],"sourcesContent":["import { flattenBy, hasOwn, makeObjectMap } from '../../utils'\nimport { constructCell } from '../cells/constructCell'\nimport type { Table_Internal } from '../../types/Table'\nimport type { RowData } from '../../types/type-utils'\nimport type { TableFeatures } from '../../types/TableFeatures'\nimport type { Row } from '../../types/Row'\nimport type { Cell } from '../../types/Cell'\nimport type { Row_RowExpanding } from '../../features/row-expanding/rowExpandingFeature.types'\n\n/**\n * Returns this row's zero-based position in the current pre-pagination row\n * model. Rows outside that model return `-1`.\n */\nexport function row_getDisplayIndex<\n TFeatures extends TableFeatures,\n TData extends RowData,\n>(row: Row<TFeatures, TData>) {\n const rows = row.table.getRowsInDisplayOrder()\n const displayIndex = row._displayIndexCache\n\n return rows[displayIndex] === row ? displayIndex : -1\n}\n\n/**\n * Returns the rows in the current display order after assigning their\n * zero-based display indexes.\n *\n * When expanded rows bypass pagination, expanded descendants are inserted into\n * the returned order even though they are absent from the pre-pagination row\n * model.\n */\nexport function table_getRowsInDisplayOrder<\n TFeatures extends TableFeatures,\n TData extends RowData,\n>(table: Table_Internal<TFeatures, TData>) {\n const rows = table.getPrePaginatedRowModel().rows\n\n if (table.options.paginateExpandedRows === false) {\n const displayRows: Array<Row<TFeatures, TData>> = []\n\n const handleRow = (row: Row<TFeatures, TData>) => {\n row._displayIndexCache = displayRows.length\n displayRows.push(row)\n\n if (\n row.subRows.length &&\n (\n row as Row<TFeatures, TData> & Partial<Row_RowExpanding>\n ).getIsExpanded?.()\n ) {\n row.subRows.forEach(handleRow)\n }\n }\n\n rows.forEach(handleRow)\n\n return displayRows\n }\n\n for (let i = 0; i < rows.length; i++) {\n rows[i]!._displayIndexCache = i\n }\n\n return rows\n}\n\n/**\n * Reads and caches this row's value for a column.\n *\n * The value is produced by the column accessor. Missing columns or display\n * columns without an accessor return `undefined`.\n *\n * @example\n * ```ts\n * const firstName = row_getValue(row, 'firstName')\n * ```\n */\nexport function row_getValue<\n TFeatures extends TableFeatures,\n TData extends RowData,\n>(row: Row<TFeatures, TData>, columnId: string) {\n if (hasOwn(row._valuesCache, columnId)) {\n return row._valuesCache[columnId]\n }\n\n const column = row.table.getColumn(columnId)\n\n if (!column?.accessorFn) {\n return undefined\n }\n\n row._valuesCache[columnId] = column.accessorFn(row.original, row.index)\n\n return row._valuesCache[columnId]\n}\n\n/**\n * Reads and caches the values used by faceting/grouping for a column.\n *\n * If the column defines `getUniqueValues`, that result is used. Otherwise the\n * row's accessor value is wrapped in a single-item array.\n *\n * @example\n * ```ts\n * const values = row_getUniqueValues(row, 'tags')\n * ```\n */\nexport function row_getUniqueValues<\n TFeatures extends TableFeatures,\n TData extends RowData,\n>(row: Row<TFeatures, TData>, columnId: string) {\n if (hasOwn(row._uniqueValuesCache, columnId)) {\n return row._uniqueValuesCache[columnId]\n }\n\n const column = row.table.getColumn(columnId)\n\n if (!column?.accessorFn) {\n return undefined\n }\n\n if (!column.columnDef.getUniqueValues) {\n row._uniqueValuesCache[columnId] = [row.getValue(columnId)]\n return row._uniqueValuesCache[columnId]\n }\n\n row._uniqueValuesCache[columnId] = column.columnDef.getUniqueValues(\n row.original,\n row.index,\n )\n\n return row._uniqueValuesCache[columnId]\n}\n\n/**\n * Returns a renderable row value for a column.\n *\n * If the accessor value is nullish, the table's `renderFallbackValue` is used\n * instead.\n *\n * @example\n * ```ts\n * const value = row_renderValue(row, 'firstName')\n * ```\n */\nexport function row_renderValue<\n TFeatures extends TableFeatures,\n TData extends RowData,\n>(row: Row<TFeatures, TData>, columnId: string) {\n return row.getValue(columnId) ?? row.table.options.renderFallbackValue\n}\n\n/**\n * Flattens this row's descendant tree into leaf rows.\n *\n * The row itself is not included; only nested `subRows` are walked.\n *\n * @example\n * ```ts\n * const descendants = row_getLeafRows(row)\n * ```\n */\nexport function row_getLeafRows<\n TFeatures extends TableFeatures,\n TData extends RowData,\n>(row: Row<TFeatures, TData>): Array<Row<TFeatures, TData>> {\n return flattenBy(row.subRows, (d) => d.subRows)\n}\n\n/**\n * Looks up this row's direct parent, if it has one.\n *\n * Parent lookup searches the pre-pagination row model so parent relationships\n * are available even when the parent is not on the current page.\n *\n * @example\n * ```ts\n * const parent = row_getParentRow(row)\n * ```\n */\nexport function row_getParentRow<\n TFeatures extends TableFeatures,\n TData extends RowData,\n>(row: Row<TFeatures, TData>) {\n return row.parentId ? row.table.getRow(row.parentId, true) : undefined\n}\n\n/**\n * Collects this row's ancestor chain from root to direct parent.\n *\n * The current row is not included. Rows without a parent return an empty array.\n *\n * @example\n * ```ts\n * const ancestors = row_getParentRows(row)\n * ```\n */\nexport function row_getParentRows<\n TFeatures extends TableFeatures,\n TData extends RowData,\n>(row: Row<TFeatures, TData>) {\n const parentRows: Array<Row<TFeatures, TData>> = []\n let currentRow = row\n // eslint-disable-next-line @typescript-eslint/no-unnecessary-condition\n while (true) {\n const parentRow = currentRow.getParentRow()\n if (!parentRow) break\n parentRows.push(parentRow)\n currentRow = parentRow\n }\n return parentRows.reverse()\n}\n\n/**\n * Constructs one cell for each leaf column in this row.\n *\n * The result follows `table.getAllLeafColumns()` order and includes hidden\n * columns; visibility-specific APIs filter this list later.\n *\n * @example\n * ```ts\n * const cells = row_getAllCells(row)\n * ```\n */\nexport function row_getAllCells<\n TFeatures extends TableFeatures,\n TData extends RowData,\n>(row: Row<TFeatures, TData>): Array<Cell<TFeatures, TData, unknown>> {\n const columns = row.table.getAllLeafColumns()\n // WeakMap so cells keyed by replaced column instances can be collected;\n // rows are memoized on data only and outlive column generations\n let cache = row._cellsCache\n if (!cache) {\n cache = row._cellsCache = new WeakMap()\n }\n const cells: Array<Cell<TFeatures, TData, unknown>> = new Array(\n columns.length,\n )\n for (let i = 0; i < columns.length; i++) {\n const column = columns[i]!\n let cell = cache.get(column)\n if (!cell) {\n cell = constructCell(column, row, row.table)\n cache.set(column, cell)\n }\n cells[i] = cell\n }\n return cells\n}\n\n/**\n * Builds a lookup map of this row's cells keyed by column id.\n *\n * This is the static implementation behind `row.getAllCellsByColumnId()`.\n *\n * @example\n * ```ts\n * const cellsById = row_getAllCellsByColumnId(row)\n * ```\n */\nexport function row_getAllCellsByColumnId<\n TFeatures extends TableFeatures,\n TData extends RowData,\n>(row: Row<TFeatures, TData>) {\n const result = makeObjectMap<Cell<TFeatures, TData, unknown>>()\n const cells = row.getAllCells()\n for (let i = 0; i < cells.length; i++) {\n const cell = cells[i]!\n result[cell.column.id] = cell\n }\n return result\n}\n\n/**\n * Resolves the stable id for a row.\n *\n * `options.getRowId` wins when provided. Otherwise root rows use their index\n * and child rows append their index to the parent id, such as `0.2`.\n *\n * @example\n * ```ts\n * const id = table_getRowId(originalRow, table, index, parentRow)\n * ```\n */\nexport function table_getRowId<\n TFeatures extends TableFeatures,\n TData extends RowData,\n>(\n originalRow: TData,\n table: Table_Internal<TFeatures, TData>,\n index: number,\n parent?: Row<TFeatures, TData>,\n) {\n return (\n table.options.getRowId?.(originalRow, index, parent) ??\n `${parent ? [parent.id, index].join('.') : index}`\n )\n}\n\n/**\n * Looks up a row by id from the current or full row model.\n *\n * By default this searches `table.getRowModel()`. Passing `searchAll` searches\n * the pre-pagination model first, then falls back to the core model.\n *\n * @example\n * ```ts\n * const row = table_getRow(table, rowId, true)\n * ```\n */\nexport function table_getRow<\n TFeatures extends TableFeatures,\n TData extends RowData,\n>(\n table: Table_Internal<TFeatures, TData>,\n rowId: string,\n searchAll?: boolean,\n): Row<TFeatures, TData> {\n // TODO - simplify this across different row models\n let row = (searchAll ? table.getPrePaginatedRowModel() : table.getRowModel())\n .rowsById[rowId]\n\n if (!row) {\n row = table.getCoreRowModel().rowsById[rowId]\n if (!row) {\n if (process.env.NODE_ENV === 'development') {\n throw new Error(`getRow could not find row with ID: ${rowId}`)\n }\n throw new Error()\n }\n }\n\n return row\n}\n"],"mappings":";;;;;;;;AAaA,SAAgB,oBAGd,KAA4B;CAC5B,MAAM,OAAO,IAAI,MAAM,sBAAsB;CAC7C,MAAM,eAAe,IAAI;CAEzB,OAAO,KAAK,kBAAkB,MAAM,eAAe;AACrD;;;;;;;;;AAUA,SAAgB,4BAGd,OAAyC;CACzC,MAAM,OAAO,MAAM,wBAAwB,CAAC,CAAC;CAE7C,IAAI,MAAM,QAAQ,yBAAyB,OAAO;EAChD,MAAM,cAA4C,CAAC;EAEnD,MAAM,aAAa,QAA+B;GAChD,IAAI,qBAAqB,YAAY;GACrC,YAAY,KAAK,GAAG;GAEpB,IACE,IAAI,QAAQ,UAEV,IACA,gBAAgB,GAElB,IAAI,QAAQ,QAAQ,SAAS;EAEjC;EAEA,KAAK,QAAQ,SAAS;EAEtB,OAAO;CACT;CAEA,KAAK,IAAI,IAAI,GAAG,IAAI,KAAK,QAAQ,KAC/B,KAAK,EAAE,CAAE,qBAAqB;CAGhC,OAAO;AACT;;;;;;;;;;;;AAaA,SAAgB,aAGd,KAA4B,UAAkB;CAC9C,IAAIA,qBAAO,IAAI,cAAc,QAAQ,GACnC,OAAO,IAAI,aAAa;CAG1B,MAAM,SAAS,IAAI,MAAM,UAAU,QAAQ;CAE3C,IAAI,CAAC,QAAQ,YACX;CAGF,IAAI,aAAa,YAAY,OAAO,WAAW,IAAI,UAAU,IAAI,KAAK;CAEtE,OAAO,IAAI,aAAa;AAC1B;;;;;;;;;;;;AAaA,SAAgB,oBAG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;EACvB,IAAI,OAAO,MAAM,IAAI,MAAM;EAC3B,IAAI,CAAC,MAAM;GACT,OAAOC,oCAAc,QAAQ,KAAK,IAAI,KAAK;GAC3C,MAAM,IAAI,QAAQ,IAAI;EACxB;EACA,MAAM,KAAK;CACb;CACA,OAAO;AACT;;;;;;;;;;;AAYA,SAAgB,0BAGd,KAA4B;CAC5B,MAAM,SAASC,4BAA+C;CAC9D,MAAM,QAAQ,IAAI,YAAY;CAC9B,KAAK,IAAI,IAAI,GAAG,IAAI,MAAM,QAAQ,KAAK;EACrC,MAAM,OAAO,MAAM;EACnB,OAAO,KAAK,OAAO,MAAM;CAC3B;CACA,OAAO;AACT;;;;;;;;;;;;AAaA,SAAgB,eAId,aACA,OACA,OACA,QACA;CACA,OACE,MAAM,QAAQ,WAAW,aAAa,OAAO,MAAM,KACnD,GAAG,SAAS,CAAC,OAAO,IAAI,KAAK,CAAC,CAAC,KAAK,GAAG,IAAI;AAE/C;;;;;;;;;;;;AAaA,SAAgB,aAId,OACA,OACA,WACuB;CAEvB,IAAI,OAAO,YAAY,MAAM,wBAAwB,IAAI,MAAM,YAAY,EAAC,CACzE,SAAS;CAEZ,IAAI,CAAC,KAAK;EACR,MAAM,MAAM,gBAAgB,CAAC,CAAC,SAAS;EACvC,IAAI,CAAC,KAAK;GACR,IAAI,QAAQ,IAAI,aAAa,eAC3B,MAAM,IAAI,MAAM,sCAAsC,OAAO;GAE/D,MAAM,IAAI,MAAM;EAClB;CACF;CAEA,OAAO;AACT"}
@@ -5,6 +5,20 @@ import { Table } from "../../types/Table.cjs";
5
5
  import { TableFeatures } from "../../types/TableFeatures.cjs";
6
6
 
7
7
  //#region src/core/rows/coreRowsFeature.utils.d.ts
8
+ /**
9
+ * Returns this row's zero-based position in the current pre-pagination row
10
+ * model. Rows outside that model return `-1`.
11
+ */
12
+ declare function row_getDisplayIndex<TFeatures extends TableFeatures, TData extends RowData>(row: Row<TFeatures, TData>): number;
13
+ /**
14
+ * Returns the rows in the current display order after assigning their
15
+ * zero-based display indexes.
16
+ *
17
+ * When expanded rows bypass pagination, expanded descendants are inserted into
18
+ * the returned order even though they are absent from the pre-pagination row
19
+ * model.
20
+ */
21
+ declare function table_getRowsInDisplayOrder<TFeatures extends TableFeatures, TData extends RowData>(table: Table<TFeatures, TData>): Row<TFeatures, TData>[];
8
22
  /**
9
23
  * Reads and caches this row's value for a column.
10
24
  *
@@ -123,5 +137,5 @@ declare function table_getRowId<TFeatures extends TableFeatures, TData extends R
123
137
  */
124
138
  declare function table_getRow<TFeatures extends TableFeatures, TData extends RowData>(table: Table<TFeatures, TData>, rowId: string, searchAll?: boolean): Row<TFeatures, TData>;
125
139
  //#endregion
126
- export { row_getAllCells, row_getAllCellsByColumnId, row_getLeafRows, row_getParentRow, row_getParentRows, row_getUniqueValues, row_getValue, row_renderValue, table_getRow, table_getRowId };
140
+ export { row_getAllCells, row_getAllCellsByColumnId, row_getDisplayIndex, row_getLeafRows, row_getParentRow, row_getParentRows, row_getUniqueValues, row_getValue, row_renderValue, table_getRow, table_getRowId, table_getRowsInDisplayOrder };
127
141
  //# sourceMappingURL=coreRowsFeature.utils.d.cts.map
@@ -5,6 +5,20 @@ import { Table } from "../../types/Table.js";
5
5
  import { TableFeatures } from "../../types/TableFeatures.js";
6
6
 
7
7
  //#region src/core/rows/coreRowsFeature.utils.d.ts
8
+ /**
9
+ * Returns this row's zero-based position in the current pre-pagination row
10
+ * model. Rows outside that model return `-1`.
11
+ */
12
+ declare function row_getDisplayIndex<TFeatures extends TableFeatures, TData extends RowData>(row: Row<TFeatures, TData>): number;
13
+ /**
14
+ * Returns the rows in the current display order after assigning their
15
+ * zero-based display indexes.
16
+ *
17
+ * When expanded rows bypass pagination, expanded descendants are inserted into
18
+ * the returned order even though they are absent from the pre-pagination row
19
+ * model.
20
+ */
21
+ declare function table_getRowsInDisplayOrder<TFeatures extends TableFeatures, TData extends RowData>(table: Table<TFeatures, TData>): Row<TFeatures, TData>[];
8
22
  /**
9
23
  * Reads and caches this row's value for a column.
10
24
  *
@@ -123,5 +137,5 @@ declare function table_getRowId<TFeatures extends TableFeatures, TData extends R
123
137
  */
124
138
  declare function table_getRow<TFeatures extends TableFeatures, TData extends RowData>(table: Table<TFeatures, TData>, rowId: string, searchAll?: boolean): Row<TFeatures, TData>;
125
139
  //#endregion
126
- export { row_getAllCells, row_getAllCellsByColumnId, row_getLeafRows, row_getParentRow, row_getParentRows, row_getUniqueValues, row_getValue, row_renderValue, table_getRow, table_getRowId };
140
+ export { row_getAllCells, row_getAllCellsByColumnId, row_getDisplayIndex, row_getLeafRows, row_getParentRow, row_getParentRows, row_getUniqueValues, row_getValue, row_renderValue, table_getRow, table_getRowId, table_getRowsInDisplayOrder };
127
141
  //# sourceMappingURL=coreRowsFeature.utils.d.ts.map
@@ -3,6 +3,38 @@ import { constructCell } from "../cells/constructCell.js";
3
3
 
4
4
  //#region src/core/rows/coreRowsFeature.utils.ts
5
5
  /**
6
+ * Returns this row's zero-based position in the current pre-pagination row
7
+ * model. Rows outside that model return `-1`.
8
+ */
9
+ function row_getDisplayIndex(row) {
10
+ const rows = row.table.getRowsInDisplayOrder();
11
+ const displayIndex = row._displayIndexCache;
12
+ return rows[displayIndex] === row ? displayIndex : -1;
13
+ }
14
+ /**
15
+ * Returns the rows in the current display order after assigning their
16
+ * zero-based display indexes.
17
+ *
18
+ * When expanded rows bypass pagination, expanded descendants are inserted into
19
+ * the returned order even though they are absent from the pre-pagination row
20
+ * model.
21
+ */
22
+ function table_getRowsInDisplayOrder(table) {
23
+ const rows = table.getPrePaginatedRowModel().rows;
24
+ if (table.options.paginateExpandedRows === false) {
25
+ const displayRows = [];
26
+ const handleRow = (row) => {
27
+ row._displayIndexCache = displayRows.length;
28
+ displayRows.push(row);
29
+ if (row.subRows.length && row.getIsExpanded?.()) row.subRows.forEach(handleRow);
30
+ };
31
+ rows.forEach(handleRow);
32
+ return displayRows;
33
+ }
34
+ for (let i = 0; i < rows.length; i++) rows[i]._displayIndexCache = i;
35
+ return rows;
36
+ }
37
+ /**
6
38
  * Reads and caches this row's value for a column.
7
39
  *
8
40
  * The value is produced by the column accessor. Missing columns or display
@@ -188,5 +220,5 @@ function table_getRow(table, rowId, searchAll) {
188
220
  }
189
221
 
190
222
  //#endregion
191
- export { row_getAllCells, row_getAllCellsByColumnId, row_getLeafRows, row_getParentRow, row_getParentRows, row_getUniqueValues, row_getValue, row_renderValue, table_getRow, table_getRowId };
223
+ export { row_getAllCells, row_getAllCellsByColumnId, row_getDisplayIndex, row_getLeafRows, row_getParentRow, row_getParentRows, row_getUniqueValues, row_getValue, row_renderValue, table_getRow, table_getRowId, table_getRowsInDisplayOrder };
192
224
  //# sourceMappingURL=coreRowsFeature.utils.js.map
@@ -1 +1 @@
1
- {"version":3,"file":"coreRowsFeature.utils.js","names":[],"sources":["../../../src/core/rows/coreRowsFeature.utils.ts"],"sourcesContent":["import { flattenBy, hasOwn, makeObjectMap } from '../../utils'\nimport { constructCell } from '../cells/constructCell'\nimport type { Table_Internal } from '../../types/Table'\nimport type { RowData } from '../../types/type-utils'\nimport type { TableFeatures } from '../../types/TableFeatures'\nimport type { Row } from '../../types/Row'\nimport type { Cell } from '../../types/Cell'\n\n/**\n * Reads and caches this row's value for a column.\n *\n * The value is produced by the column accessor. Missing columns or display\n * columns without an accessor return `undefined`.\n *\n * @example\n * ```ts\n * const firstName = row_getValue(row, 'firstName')\n * ```\n */\nexport function row_getValue<\n TFeatures extends TableFeatures,\n TData extends RowData,\n>(row: Row<TFeatures, TData>, columnId: string) {\n if (hasOwn(row._valuesCache, columnId)) {\n return row._valuesCache[columnId]\n }\n\n const column = row.table.getColumn(columnId)\n\n if (!column?.accessorFn) {\n return undefined\n }\n\n row._valuesCache[columnId] = column.accessorFn(row.original, row.index)\n\n return row._valuesCache[columnId]\n}\n\n/**\n * Reads and caches the values used by faceting/grouping for a column.\n *\n * If the column defines `getUniqueValues`, that result is used. Otherwise the\n * row's accessor value is wrapped in a single-item array.\n *\n * @example\n * ```ts\n * const values = row_getUniqueValues(row, 'tags')\n * ```\n */\nexport function row_getUniqueValues<\n TFeatures extends TableFeatures,\n TData extends RowData,\n>(row: Row<TFeatures, TData>, columnId: string) {\n if (hasOwn(row._uniqueValuesCache, columnId)) {\n return row._uniqueValuesCache[columnId]\n }\n\n const column = row.table.getColumn(columnId)\n\n if (!column?.accessorFn) {\n return undefined\n }\n\n if (!column.columnDef.getUniqueValues) {\n row._uniqueValuesCache[columnId] = [row.getValue(columnId)]\n return row._uniqueValuesCache[columnId]\n }\n\n row._uniqueValuesCache[columnId] = column.columnDef.getUniqueValues(\n row.original,\n row.index,\n )\n\n return row._uniqueValuesCache[columnId]\n}\n\n/**\n * Returns a renderable row value for a column.\n *\n * If the accessor value is nullish, the table's `renderFallbackValue` is used\n * instead.\n *\n * @example\n * ```ts\n * const value = row_renderValue(row, 'firstName')\n * ```\n */\nexport function row_renderValue<\n TFeatures extends TableFeatures,\n TData extends RowData,\n>(row: Row<TFeatures, TData>, columnId: string) {\n return row.getValue(columnId) ?? row.table.options.renderFallbackValue\n}\n\n/**\n * Flattens this row's descendant tree into leaf rows.\n *\n * The row itself is not included; only nested `subRows` are walked.\n *\n * @example\n * ```ts\n * const descendants = row_getLeafRows(row)\n * ```\n */\nexport function row_getLeafRows<\n TFeatures extends TableFeatures,\n TData extends RowData,\n>(row: Row<TFeatures, TData>): Array<Row<TFeatures, TData>> {\n return flattenBy(row.subRows, (d) => d.subRows)\n}\n\n/**\n * Looks up this row's direct parent, if it has one.\n *\n * Parent lookup searches the pre-pagination row model so parent relationships\n * are available even when the parent is not on the current page.\n *\n * @example\n * ```ts\n * const parent = row_getParentRow(row)\n * ```\n */\nexport function row_getParentRow<\n TFeatures extends TableFeatures,\n TData extends RowData,\n>(row: Row<TFeatures, TData>) {\n return row.parentId ? row.table.getRow(row.parentId, true) : undefined\n}\n\n/**\n * Collects this row's ancestor chain from root to direct parent.\n *\n * The current row is not included. Rows without a parent return an empty array.\n *\n * @example\n * ```ts\n * const ancestors = row_getParentRows(row)\n * ```\n */\nexport function row_getParentRows<\n TFeatures extends TableFeatures,\n TData extends RowData,\n>(row: Row<TFeatures, TData>) {\n const parentRows: Array<Row<TFeatures, TData>> = []\n let currentRow = row\n // eslint-disable-next-line @typescript-eslint/no-unnecessary-condition\n while (true) {\n const parentRow = currentRow.getParentRow()\n if (!parentRow) break\n parentRows.push(parentRow)\n currentRow = parentRow\n }\n return parentRows.reverse()\n}\n\n/**\n * Constructs one cell for each leaf column in this row.\n *\n * The result follows `table.getAllLeafColumns()` order and includes hidden\n * columns; visibility-specific APIs filter this list later.\n *\n * @example\n * ```ts\n * const cells = row_getAllCells(row)\n * ```\n */\nexport function row_getAllCells<\n TFeatures extends TableFeatures,\n TData extends RowData,\n>(row: Row<TFeatures, TData>): Array<Cell<TFeatures, TData, unknown>> {\n const columns = row.table.getAllLeafColumns()\n // WeakMap so cells keyed by replaced column instances can be collected;\n // rows are memoized on data only and outlive column generations\n let cache = row._cellsCache\n if (!cache) {\n cache = row._cellsCache = new WeakMap()\n }\n const cells: Array<Cell<TFeatures, TData, unknown>> = new Array(\n columns.length,\n )\n for (let i = 0; i < columns.length; i++) {\n const column = columns[i]!\n let cell = cache.get(column)\n if (!cell) {\n cell = constructCell(column, row, row.table)\n cache.set(column, cell)\n }\n cells[i] = cell\n }\n return cells\n}\n\n/**\n * Builds a lookup map of this row's cells keyed by column id.\n *\n * This is the static implementation behind `row.getAllCellsByColumnId()`.\n *\n * @example\n * ```ts\n * const cellsById = row_getAllCellsByColumnId(row)\n * ```\n */\nexport function row_getAllCellsByColumnId<\n TFeatures extends TableFeatures,\n TData extends RowData,\n>(row: Row<TFeatures, TData>) {\n const result = makeObjectMap<Cell<TFeatures, TData, unknown>>()\n const cells = row.getAllCells()\n for (let i = 0; i < cells.length; i++) {\n const cell = cells[i]!\n result[cell.column.id] = cell\n }\n return result\n}\n\n/**\n * Resolves the stable id for a row.\n *\n * `options.getRowId` wins when provided. Otherwise root rows use their index\n * and child rows append their index to the parent id, such as `0.2`.\n *\n * @example\n * ```ts\n * const id = table_getRowId(originalRow, table, index, parentRow)\n * ```\n */\nexport function table_getRowId<\n TFeatures extends TableFeatures,\n TData extends RowData,\n>(\n originalRow: TData,\n table: Table_Internal<TFeatures, TData>,\n index: number,\n parent?: Row<TFeatures, TData>,\n) {\n return (\n table.options.getRowId?.(originalRow, index, parent) ??\n `${parent ? [parent.id, index].join('.') : index}`\n )\n}\n\n/**\n * Looks up a row by id from the current or full row model.\n *\n * By default this searches `table.getRowModel()`. Passing `searchAll` searches\n * the pre-pagination model first, then falls back to the core model.\n *\n * @example\n * ```ts\n * const row = table_getRow(table, rowId, true)\n * ```\n */\nexport function table_getRow<\n TFeatures extends TableFeatures,\n TData extends RowData,\n>(\n table: Table_Internal<TFeatures, TData>,\n rowId: string,\n searchAll?: boolean,\n): Row<TFeatures, TData> {\n // TODO - simplify this across different row models\n let row = (searchAll ? table.getPrePaginatedRowModel() : table.getRowModel())\n .rowsById[rowId]\n\n if (!row) {\n row = table.getCoreRowModel().rowsById[rowId]\n if (!row) {\n if (process.env.NODE_ENV === 'development') {\n throw new Error(`getRow could not find row with ID: ${rowId}`)\n }\n throw new Error()\n }\n }\n\n return row\n}\n"],"mappings":";;;;;;;;;;;;;;;AAmBA,SAAgB,aAGd,KAA4B,UAAkB;CAC9C,IAAI,OAAO,IAAI,cAAc,QAAQ,GACnC,OAAO,IAAI,aAAa;CAG1B,MAAM,SAAS,IAAI,MAAM,UAAU,QAAQ;CAE3C,IAAI,CAAC,QAAQ,YACX;CAGF,IAAI,aAAa,YAAY,OAAO,WAAW,IAAI,UAAU,IAAI,KAAK;CAEtE,OAAO,IAAI,aAAa;AAC1B;;;;;;;;;;;;AAaA,SAAgB,oBAGd,KAA4B,UAAkB;CAC9C,IAAI,OAAO,IAAI,oBAAoB,QAAQ,GACzC,OAAO,IAAI,mBAAmB;CAGhC,MAAM,SAAS,IAAI,MAAM,UAAU,QAAQ;CAE3C,IAAI,CAAC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AM,KAAK;CACb;CACA,OAAO;AACT;;;;;;;;;;;AAYA,SAAgB,0BAGd,KAA4B;CAC5B,MAAM,SAAS,cAA+C;CAC9D,MAAM,QAAQ,IAAI,YAAY;CAC9B,KAAK,IAAI,IAAI,GAAG,IAAI,MAAM,QAAQ,KAAK;EACrC,MAAM,OAAO,MAAM;EACnB,OAAO,KAAK,OAAO,MAAM;CAC3B;CACA,OAAO;AACT;;;;;;;;;;;;AAaA,SAAgB,eAId,aACA,OACA,OACA,QACA;CACA,OACE,MAAM,QAAQ,WAAW,aAAa,OAAO,MAAM,KACnD,GAAG,SAAS,CAAC,OAAO,IAAI,KAAK,CAAC,CAAC,KAAK,GAAG,IAAI;AAE/C;;;;;;;;;;;;AAaA,SAAgB,aAId,OACA,OACA,WACuB;CAEvB,IAAI,OAAO,YAAY,MAAM,wBAAwB,IAAI,MAAM,YAAY,EAAC,CACzE,SAAS;CAEZ,IAAI,CAAC,KAAK;EACR,MAAM,MAAM,gBAAgB,CAAC,CAAC,SAAS;EACvC,IAAI,CAAC,KAAK;GACR,IAAI,QAAQ,IAAI,aAAa,eAC3B,MAAM,IAAI,MAAM,sCAAsC,OAAO;GAE/D,MAAM,IAAI,MAAM;EAClB;CACF;CAEA,OAAO;AACT"}
1
+ {"version":3,"file":"coreRowsFeature.utils.js","names":[],"sources":["../../../src/core/rows/coreRowsFeature.utils.ts"],"sourcesContent":["import { flattenBy, hasOwn, makeObjectMap } from '../../utils'\nimport { constructCell } from '../cells/constructCell'\nimport type { Table_Internal } from '../../types/Table'\nimport type { RowData } from '../../types/type-utils'\nimport type { TableFeatures } from '../../types/TableFeatures'\nimport type { Row } from '../../types/Row'\nimport type { Cell } from '../../types/Cell'\nimport type { Row_RowExpanding } from '../../features/row-expanding/rowExpandingFeature.types'\n\n/**\n * Returns this row's zero-based position in the current pre-pagination row\n * model. Rows outside that model return `-1`.\n */\nexport function row_getDisplayIndex<\n TFeatures extends TableFeatures,\n TData extends RowData,\n>(row: Row<TFeatures, TData>) {\n const rows = row.table.getRowsInDisplayOrder()\n const displayIndex = row._displayIndexCache\n\n return rows[displayIndex] === row ? displayIndex : -1\n}\n\n/**\n * Returns the rows in the current display order after assigning their\n * zero-based display indexes.\n *\n * When expanded rows bypass pagination, expanded descendants are inserted into\n * the returned order even though they are absent from the pre-pagination row\n * model.\n */\nexport function table_getRowsInDisplayOrder<\n TFeatures extends TableFeatures,\n TData extends RowData,\n>(table: Table_Internal<TFeatures, TData>) {\n const rows = table.getPrePaginatedRowModel().rows\n\n if (table.options.paginateExpandedRows === false) {\n const displayRows: Array<Row<TFeatures, TData>> = []\n\n const handleRow = (row: Row<TFeatures, TData>) => {\n row._displayIndexCache = displayRows.length\n displayRows.push(row)\n\n if (\n row.subRows.length &&\n (\n row as Row<TFeatures, TData> & Partial<Row_RowExpanding>\n ).getIsExpanded?.()\n ) {\n row.subRows.forEach(handleRow)\n }\n }\n\n rows.forEach(handleRow)\n\n return displayRows\n }\n\n for (let i = 0; i < rows.length; i++) {\n rows[i]!._displayIndexCache = i\n }\n\n return rows\n}\n\n/**\n * Reads and caches this row's value for a column.\n *\n * The value is produced by the column accessor. Missing columns or display\n * columns without an accessor return `undefined`.\n *\n * @example\n * ```ts\n * const firstName = row_getValue(row, 'firstName')\n * ```\n */\nexport function row_getValue<\n TFeatures extends TableFeatures,\n TData extends RowData,\n>(row: Row<TFeatures, TData>, columnId: string) {\n if (hasOwn(row._valuesCache, columnId)) {\n return row._valuesCache[columnId]\n }\n\n const column = row.table.getColumn(columnId)\n\n if (!column?.accessorFn) {\n return undefined\n }\n\n row._valuesCache[columnId] = column.accessorFn(row.original, row.index)\n\n return row._valuesCache[columnId]\n}\n\n/**\n * Reads and caches the values used by faceting/grouping for a column.\n *\n * If the column defines `getUniqueValues`, that result is used. Otherwise the\n * row's accessor value is wrapped in a single-item array.\n *\n * @example\n * ```ts\n * const values = row_getUniqueValues(row, 'tags')\n * ```\n */\nexport function row_getUniqueValues<\n TFeatures extends TableFeatures,\n TData extends RowData,\n>(row: Row<TFeatures, TData>, columnId: string) {\n if (hasOwn(row._uniqueValuesCache, columnId)) {\n return row._uniqueValuesCache[columnId]\n }\n\n const column = row.table.getColumn(columnId)\n\n if (!column?.accessorFn) {\n return undefined\n }\n\n if (!column.columnDef.getUniqueValues) {\n row._uniqueValuesCache[columnId] = [row.getValue(columnId)]\n return row._uniqueValuesCache[columnId]\n }\n\n row._uniqueValuesCache[columnId] = column.columnDef.getUniqueValues(\n row.original,\n row.index,\n )\n\n return row._uniqueValuesCache[columnId]\n}\n\n/**\n * Returns a renderable row value for a column.\n *\n * If the accessor value is nullish, the table's `renderFallbackValue` is used\n * instead.\n *\n * @example\n * ```ts\n * const value = row_renderValue(row, 'firstName')\n * ```\n */\nexport function row_renderValue<\n TFeatures extends TableFeatures,\n TData extends RowData,\n>(row: Row<TFeatures, TData>, columnId: string) {\n return row.getValue(columnId) ?? row.table.options.renderFallbackValue\n}\n\n/**\n * Flattens this row's descendant tree into leaf rows.\n *\n * The row itself is not included; only nested `subRows` are walked.\n *\n * @example\n * ```ts\n * const descendants = row_getLeafRows(row)\n * ```\n */\nexport function row_getLeafRows<\n TFeatures extends TableFeatures,\n TData extends RowData,\n>(row: Row<TFeatures, TData>): Array<Row<TFeatures, TData>> {\n return flattenBy(row.subRows, (d) => d.subRows)\n}\n\n/**\n * Looks up this row's direct parent, if it has one.\n *\n * Parent lookup searches the pre-pagination row model so parent relationships\n * are available even when the parent is not on the current page.\n *\n * @example\n * ```ts\n * const parent = row_getParentRow(row)\n * ```\n */\nexport function row_getParentRow<\n TFeatures extends TableFeatures,\n TData extends RowData,\n>(row: Row<TFeatures, TData>) {\n return row.parentId ? row.table.getRow(row.parentId, true) : undefined\n}\n\n/**\n * Collects this row's ancestor chain from root to direct parent.\n *\n * The current row is not included. Rows without a parent return an empty array.\n *\n * @example\n * ```ts\n * const ancestors = row_getParentRows(row)\n * ```\n */\nexport function row_getParentRows<\n TFeatures extends TableFeatures,\n TData extends RowData,\n>(row: Row<TFeatures, TData>) {\n const parentRows: Array<Row<TFeatures, TData>> = []\n let currentRow = row\n // eslint-disable-next-line @typescript-eslint/no-unnecessary-condition\n while (true) {\n const parentRow = currentRow.getParentRow()\n if (!parentRow) break\n parentRows.push(parentRow)\n currentRow = parentRow\n }\n return parentRows.reverse()\n}\n\n/**\n * Constructs one cell for each leaf column in this row.\n *\n * The result follows `table.getAllLeafColumns()` order and includes hidden\n * columns; visibility-specific APIs filter this list later.\n *\n * @example\n * ```ts\n * const cells = row_getAllCells(row)\n * ```\n */\nexport function row_getAllCells<\n TFeatures extends TableFeatures,\n TData extends RowData,\n>(row: Row<TFeatures, TData>): Array<Cell<TFeatures, TData, unknown>> {\n const columns = row.table.getAllLeafColumns()\n // WeakMap so cells keyed by replaced column instances can be collected;\n // rows are memoized on data only and outlive column generations\n let cache = row._cellsCache\n if (!cache) {\n cache = row._cellsCache = new WeakMap()\n }\n const cells: Array<Cell<TFeatures, TData, unknown>> = new Array(\n columns.length,\n )\n for (let i = 0; i < columns.length; i++) {\n const column = columns[i]!\n let cell = cache.get(column)\n if (!cell) {\n cell = constructCell(column, row, row.table)\n cache.set(column, cell)\n }\n cells[i] = cell\n }\n return cells\n}\n\n/**\n * Builds a lookup map of this row's cells keyed by column id.\n *\n * This is the static implementation behind `row.getAllCellsByColumnId()`.\n *\n * @example\n * ```ts\n * const cellsById = row_getAllCellsByColumnId(row)\n * ```\n */\nexport function row_getAllCellsByColumnId<\n TFeatures extends TableFeatures,\n TData extends RowData,\n>(row: Row<TFeatures, TData>) {\n const result = makeObjectMap<Cell<TFeatures, TData, unknown>>()\n const cells = row.getAllCells()\n for (let i = 0; i < cells.length; i++) {\n const cell = cells[i]!\n result[cell.column.id] = cell\n }\n return result\n}\n\n/**\n * Resolves the stable id for a row.\n *\n * `options.getRowId` wins when provided. Otherwise root rows use their index\n * and child rows append their index to the parent id, such as `0.2`.\n *\n * @example\n * ```ts\n * const id = table_getRowId(originalRow, table, index, parentRow)\n * ```\n */\nexport function table_getRowId<\n TFeatures extends TableFeatures,\n TData extends RowData,\n>(\n originalRow: TData,\n table: Table_Internal<TFeatures, TData>,\n index: number,\n parent?: Row<TFeatures, TData>,\n) {\n return (\n table.options.getRowId?.(originalRow, index, parent) ??\n `${parent ? [parent.id, index].join('.') : index}`\n )\n}\n\n/**\n * Looks up a row by id from the current or full row model.\n *\n * By default this searches `table.getRowModel()`. Passing `searchAll` searches\n * the pre-pagination model first, then falls back to the core model.\n *\n * @example\n * ```ts\n * const row = table_getRow(table, rowId, true)\n * ```\n */\nexport function table_getRow<\n TFeatures extends TableFeatures,\n TData extends RowData,\n>(\n table: Table_Internal<TFeatures, TData>,\n rowId: string,\n searchAll?: boolean,\n): Row<TFeatures, TData> {\n // TODO - simplify this across different row models\n let row = (searchAll ? table.getPrePaginatedRowModel() : table.getRowModel())\n .rowsById[rowId]\n\n if (!row) {\n row = table.getCoreRowModel().rowsById[rowId]\n if (!row) {\n if (process.env.NODE_ENV === 'development') {\n throw new Error(`getRow could not find row with ID: ${rowId}`)\n }\n throw new Error()\n }\n }\n\n return row\n}\n"],"mappings":";;;;;;;;AAaA,SAAgB,oBAGd,KAA4B;CAC5B,MAAM,OAAO,IAAI,MAAM,sBAAsB;CAC7C,MAAM,eAAe,IAAI;CAEzB,OAAO,KAAK,kBAAkB,MAAM,eAAe;AACrD;;;;;;;;;AAUA,SAAgB,4BAGd,OAAyC;CACzC,MAAM,OAAO,MAAM,wBAAwB,CAAC,CAAC;CAE7C,IAAI,MAAM,QAAQ,yBAAyB,OAAO;EAChD,MAAM,cAA4C,CAAC;EAEnD,MAAM,aAAa,QAA+B;GAChD,IAAI,qBAAqB,YAAY;GACrC,YAAY,KAAK,GAAG;GAEpB,IACE,IAAI,QAAQ,UAEV,IACA,gBAAgB,GAElB,IAAI,QAAQ,QAAQ,SAAS;EAEjC;EAEA,KAAK,QAAQ,SAAS;EAEtB,OAAO;CACT;CAEA,KAAK,IAAI,IAAI,GAAG,IAAI,KAAK,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,OAAO;GAE/D,MAAM,IAAI,MAAM;EAClB;CACF;CAEA,OAAO;AACT"}
@@ -95,6 +95,7 @@ function constructTable(tableOptions) {
95
95
  }
96
96
  return snapshot;
97
97
  }, { debugName: "table/store" }));
98
+ for (let i = 0; i < featuresList.length; i++) featuresList[i].initTableInstanceData?.(table);
98
99
  if (process.env.NODE_ENV === "development" && (tableOptions.debugAll || tableOptions.debugTable)) {
99
100
  const features = Object.keys(table._features);
100
101
  const rowModels = Object.entries({
@@ -1 +1 @@
1
- {"version":3,"file":"constructTable.cjs","names":["cloneState","coreFeatures","atomToStore"],"sources":["../../../src/core/table/constructTable.ts"],"sourcesContent":["import { coreFeatures } from '../coreFeatures'\nimport { cloneState } from '../../utils'\nimport { atomToStore } from '../reactivity/coreReactivityFeature.utils'\nimport { table_syncExternalStateToBaseAtoms } from './coreTablesFeature.utils'\nimport type { Atom } from '@tanstack/store'\nimport type { RowData } from '../../types/type-utils'\nimport type { TableFeature, TableFeatures } from '../../types/TableFeatures'\nimport type { Table, Table_Internal } from '../../types/Table'\nimport type { TableOptions } from '../../types/TableOptions'\nimport type { TableState, TableState_All } from '../../types/TableState'\n\n/**\n * Builds the initial table state from registered features and user initial state.\n *\n * Each feature contributes its default state before user-provided `initialState` values are merged in.\n */\nexport function getInitialTableState<TFeatures extends TableFeatures>(\n features: TFeatures,\n initialState: Partial<TableState<TFeatures>> | undefined = {},\n): TableState<TFeatures> {\n Object.values(features).forEach((feature) => {\n initialState = feature.getInitialState?.(initialState) ?? initialState\n })\n return cloneState(initialState) as TableState<TFeatures>\n}\n\n/**\n * Constructs a table instance from normalized table internals.\n *\n * This wires core properties, feature prototype APIs, and instance data used by table rendering and row-model operations.\n */\nexport function constructTable<\n TFeatures extends TableFeatures,\n TData extends RowData,\n>(tableOptions: TableOptions<TFeatures, TData>): Table<TFeatures, TData> {\n const _reactivity = tableOptions.features.coreReactivityFeature!\n\n // Strip the non-feature slots: type-only meta slots, row model factories,\n // and row model fn registries all live on the `features` option but are not\n // table features themselves.\n const {\n aggregationFns,\n columnMeta: _columnMeta,\n coreRowModel,\n expandedRowModel,\n facetedMinMaxValues,\n facetedRowModel,\n facetedUniqueValues,\n filterFns,\n filterMeta: _filterMeta,\n filteredRowModel,\n groupedRowModel,\n paginatedRowModel,\n sortFns,\n sortedRowModel,\n tableMeta: _tableMeta,\n ...features\n } = tableOptions.features\n\n const table = {\n _reactivity,\n _features: { ...coreFeatures, ...features },\n _rowModels: {},\n _rowModelFns: { aggregationFns, filterFns, sortFns },\n baseAtoms: {},\n atoms: {},\n } as unknown as Table_Internal<TFeatures, TData>\n\n const featuresList: Array<TableFeature> = Object.values(table._features)\n\n const defaultOptions = featuresList.reduce((obj, feature) => {\n return Object.assign(obj, feature.getDefaultTableOptions?.(table))\n }, {}) as TableOptions<TFeatures, TData>\n\n const mergedOptions = { ...defaultOptions, ...tableOptions }\n\n if (_reactivity.wrapExternalAtoms && mergedOptions.atoms) {\n for (const [atomKey, _atom] of Object.entries(mergedOptions.atoms)) {\n const atom = _atom as Atom<any>\n const wrappedAtom = _reactivity.createWritableAtom(atom.get(), {\n debugName: `externalAtom/${atomKey}`,\n })\n ;(mergedOptions.atoms as any)[atomKey] = wrappedAtom\n // Two-way syncing between the original atom and the wrapped one.\n let syncExternal = false\n const syncAtomToWrappedSub = atom.subscribe((value) => {\n if (syncExternal) return\n wrappedAtom.set(value)\n })\n const syncWrappedToAtomSub = wrappedAtom.subscribe((value) => {\n syncExternal = true\n atom.set(value)\n syncExternal = false\n })\n _reactivity.addSubscription(syncAtomToWrappedSub)\n _reactivity.addSubscription(syncWrappedToAtomSub)\n }\n }\n\n if (_reactivity.createOptionsStore) {\n // @ts-ignore - direct set\n table.optionsStore = _reactivity.createWritableAtom<\n TableOptions<TFeatures, TData>\n >(mergedOptions, { debugName: 'table/optionsStore' })\n Object.defineProperty(table, 'options', {\n configurable: true,\n enumerable: true,\n get() {\n return table.optionsStore!.get()\n },\n set(value) {\n table.optionsStore!.set(() => value) // or your real update shape\n },\n })\n } else {\n table.options = mergedOptions\n }\n\n table.initialState = getInitialTableState(\n table._features,\n table.options.initialState,\n )\n\n const stateKeys = Object.keys(table.initialState) as Array<\n string & keyof TableState_All\n >\n\n for (let i = 0; i < stateKeys.length; i++) {\n const key = stateKeys[i]!\n table.baseAtoms[key] = _reactivity.createWritableAtom(\n table.initialState[key],\n {\n debugName: `table/baseAtoms/${key}`,\n },\n ) as any\n\n // create readonly derived atom: on each get(), read either external atom or base atom\n ;(table.atoms as any)[key] = _reactivity.createReadonlyAtom(\n () => {\n const externalAtoms = table.options.atoms as\n | Partial<Record<keyof TableState_All, Atom<unknown>>>\n | undefined\n const externalAtom = externalAtoms?.[key]\n if (externalAtom) {\n return externalAtom.get()\n }\n return table.baseAtoms[key]!.get()\n },\n { debugName: `table/atoms/${key}` },\n )\n }\n\n table_syncExternalStateToBaseAtoms(table)\n\n table.store = atomToStore(\n _reactivity.createReadonlyAtom(\n () => {\n const snapshot = {} as TableState<TFeatures> & TableState_All\n for (let i = 0; i < stateKeys.length; i++) {\n const key = stateKeys[i]!\n ;(snapshot as Record<string, unknown>)[key] = table.atoms[key]!.get()\n }\n return snapshot\n },\n { debugName: 'table/store' },\n ),\n )\n\n if (\n process.env.NODE_ENV === 'development' &&\n (tableOptions.debugAll || tableOptions.debugTable)\n ) {\n const features = Object.keys(table._features)\n const rowModels = Object.entries({\n coreRowModel,\n filteredRowModel,\n groupedRowModel,\n sortedRowModel,\n expandedRowModel,\n paginatedRowModel,\n facetedRowModel,\n facetedMinMaxValues,\n facetedUniqueValues,\n })\n .filter(([, factory]) => factory)\n .map(([key]) => key)\n const states = Object.keys(table.initialState)\n\n console.log(\n `Constructing Table Instance\n\n Features: ${features.join('\\n ')}\n\n Row Models: ${rowModels.length ? rowModels.join('\\n ') : '(none)'}\n\n States: ${states.join('\\n ')}\\n`,\n { table },\n )\n }\n\n for (let i = 0; i < featuresList.length; i++) {\n featuresList[i]!.constructTableAPIs?.(table)\n }\n\n return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AC/B;GACA;GACA;GACA;GACA;GACA;GACA;GACA;GACA;EACF,CAAC,CAAC,CACC,QAAQ,GAAG,aAAa,OAAO,CAAC,CAChC,KAAK,CAAC,SAAS,GAAG;EACrB,MAAM,SAAS,OAAO,KAAK,MAAM,YAAY;EAE7C,QAAQ,IACN;;gBAEU,SAAS,KAAK,kBAAkB,EAAE;;gBAElC,UAAU,SAAS,UAAU,KAAK,kBAAkB,IAAI,SAAS;;gBAEjE,OAAO,KAAK,kBAAkB,EAAE,KAC1C,EAAE,MAAM,CACV;CACF;CAEA,KAAK,IAAI,IAAI,GAAG,IAAI,aAAa,QAAQ,KACvC,aAAa,EAAE,CAAE,qBAAqB,KAAK;CAG7C,OAAO;AACT"}
1
+ {"version":3,"file":"constructTable.cjs","names":["cloneState","coreFeatures","atomToStore"],"sources":["../../../src/core/table/constructTable.ts"],"sourcesContent":["import { coreFeatures } from '../coreFeatures'\nimport { cloneState } from '../../utils'\nimport { atomToStore } from '../reactivity/coreReactivityFeature.utils'\nimport { table_syncExternalStateToBaseAtoms } from './coreTablesFeature.utils'\nimport type { Atom } from '@tanstack/store'\nimport type { RowData } from '../../types/type-utils'\nimport type { TableFeature, TableFeatures } from '../../types/TableFeatures'\nimport type { Table, Table_Internal } from '../../types/Table'\nimport type { TableOptions } from '../../types/TableOptions'\nimport type { TableState, TableState_All } from '../../types/TableState'\n\n/**\n * Builds the initial table state from registered features and user initial state.\n *\n * Each feature contributes its default state before user-provided `initialState` values are merged in.\n */\nexport function getInitialTableState<TFeatures extends TableFeatures>(\n features: TFeatures,\n initialState: Partial<TableState<TFeatures>> | undefined = {},\n): TableState<TFeatures> {\n Object.values(features).forEach((feature) => {\n initialState = feature.getInitialState?.(initialState) ?? initialState\n })\n return cloneState(initialState) as TableState<TFeatures>\n}\n\n/**\n * Constructs a table instance from normalized table internals.\n *\n * This wires core properties, feature prototype APIs, and instance data used by table rendering and row-model operations.\n */\nexport function constructTable<\n TFeatures extends TableFeatures,\n TData extends RowData,\n>(tableOptions: TableOptions<TFeatures, TData>): Table<TFeatures, TData> {\n const _reactivity = tableOptions.features.coreReactivityFeature!\n\n // Strip the non-feature slots: type-only meta slots, row model factories,\n // and row model fn registries all live on the `features` option but are not\n // table features themselves.\n const {\n aggregationFns,\n columnMeta: _columnMeta,\n coreRowModel,\n expandedRowModel,\n facetedMinMaxValues,\n facetedRowModel,\n facetedUniqueValues,\n filterFns,\n filterMeta: _filterMeta,\n filteredRowModel,\n groupedRowModel,\n paginatedRowModel,\n sortFns,\n sortedRowModel,\n tableMeta: _tableMeta,\n ...features\n } = tableOptions.features\n\n const table = {\n _reactivity,\n _features: { ...coreFeatures, ...features },\n _rowModels: {},\n _rowModelFns: { aggregationFns, filterFns, sortFns },\n baseAtoms: {},\n atoms: {},\n } as unknown as Table_Internal<TFeatures, TData>\n\n const featuresList: Array<TableFeature> = Object.values(table._features)\n\n const defaultOptions = featuresList.reduce((obj, feature) => {\n return Object.assign(obj, feature.getDefaultTableOptions?.(table))\n }, {}) as TableOptions<TFeatures, TData>\n\n const mergedOptions = { ...defaultOptions, ...tableOptions }\n\n if (_reactivity.wrapExternalAtoms && mergedOptions.atoms) {\n for (const [atomKey, _atom] of Object.entries(mergedOptions.atoms)) {\n const atom = _atom as Atom<any>\n const wrappedAtom = _reactivity.createWritableAtom(atom.get(), {\n debugName: `externalAtom/${atomKey}`,\n })\n ;(mergedOptions.atoms as any)[atomKey] = wrappedAtom\n // Two-way syncing between the original atom and the wrapped one.\n let syncExternal = false\n const syncAtomToWrappedSub = atom.subscribe((value) => {\n if (syncExternal) return\n wrappedAtom.set(value)\n })\n const syncWrappedToAtomSub = wrappedAtom.subscribe((value) => {\n syncExternal = true\n atom.set(value)\n syncExternal = false\n })\n _reactivity.addSubscription(syncAtomToWrappedSub)\n _reactivity.addSubscription(syncWrappedToAtomSub)\n }\n }\n\n if (_reactivity.createOptionsStore) {\n // @ts-ignore - direct set\n table.optionsStore = _reactivity.createWritableAtom<\n TableOptions<TFeatures, TData>\n >(mergedOptions, { debugName: 'table/optionsStore' })\n Object.defineProperty(table, 'options', {\n configurable: true,\n enumerable: true,\n get() {\n return table.optionsStore!.get()\n },\n set(value) {\n table.optionsStore!.set(() => value) // or your real update shape\n },\n })\n } else {\n table.options = mergedOptions\n }\n\n table.initialState = getInitialTableState(\n table._features,\n table.options.initialState,\n )\n\n const stateKeys = Object.keys(table.initialState) as Array<\n string & keyof TableState_All\n >\n\n for (let i = 0; i < stateKeys.length; i++) {\n const key = stateKeys[i]!\n table.baseAtoms[key] = _reactivity.createWritableAtom(\n table.initialState[key],\n {\n debugName: `table/baseAtoms/${key}`,\n },\n ) as any\n\n // create readonly derived atom: on each get(), read either external atom or base atom\n ;(table.atoms as any)[key] = _reactivity.createReadonlyAtom(\n () => {\n const externalAtoms = table.options.atoms as\n | Partial<Record<keyof TableState_All, Atom<unknown>>>\n | undefined\n const externalAtom = externalAtoms?.[key]\n if (externalAtom) {\n return externalAtom.get()\n }\n return table.baseAtoms[key]!.get()\n },\n { debugName: `table/atoms/${key}` },\n )\n }\n\n table_syncExternalStateToBaseAtoms(table)\n\n table.store = atomToStore(\n _reactivity.createReadonlyAtom(\n () => {\n const snapshot = {} as TableState<TFeatures> & TableState_All\n for (let i = 0; i < stateKeys.length; i++) {\n const key = stateKeys[i]!\n ;(snapshot as Record<string, unknown>)[key] = table.atoms[key]!.get()\n }\n return snapshot\n },\n { debugName: 'table/store' },\n ),\n )\n\n for (let i = 0; i < featuresList.length; i++) {\n featuresList[i]!.initTableInstanceData?.(table)\n }\n\n if (\n process.env.NODE_ENV === 'development' &&\n (tableOptions.debugAll || tableOptions.debugTable)\n ) {\n const features = Object.keys(table._features)\n const rowModels = Object.entries({\n coreRowModel,\n filteredRowModel,\n groupedRowModel,\n sortedRowModel,\n expandedRowModel,\n paginatedRowModel,\n facetedRowModel,\n facetedMinMaxValues,\n facetedUniqueValues,\n })\n .filter(([, factory]) => factory)\n .map(([key]) => key)\n const states = Object.keys(table.initialState)\n\n console.log(\n `Constructing Table Instance\n\n Features: ${features.join('\\n ')}\n\n Row Models: ${rowModels.length ? rowModels.join('\\n ') : '(none)'}\n\n States: ${states.join('\\n ')}\\n`,\n { table },\n )\n }\n\n for (let i = 0; i < featuresList.length; i++) {\n featuresList[i]!.constructTableAPIs?.(table)\n }\n\n return table as unknown as Table<TFeatures, TData>\n}\n"],"mappings":";;;;;;;;;;;AAgBA,SAAgB,qBACd,UACA,eAA2D,CAAC,GACrC;CACvB,OAAO,OAAO,QAAQ,CAAC,CAAC,SAAS,YAAY;EAC3C,eAAe,QAAQ,kBAAkB,YAAY,KAAK;CAC5D,CAAC;CACD,OAAOA,yBAAW,YAAY;AAChC;;;;;;AAOA,SAAgB,eAGd,cAAuE;CACvE,MAAM,cAAc,aAAa,SAAS;CAK1C,MAAM,EACJ,gBACA,YAAY,aACZ,cACA,kBACA,qBACA,iBACA,qBACA,WACA,YAAY,aACZ,kBACA,iBACA,mBACA,SACA,gBACA,WAAW,YACX,GAAG,aACD,aAAa;CAEjB,MAAM,QAAQ;EACZ;EACA,WAAW;GAAE,GAAGC;GAAc,GAAG;EAAS;EAC1C,YAAY,CAAC;EACb,cAAc;GAAE;GAAgB;GAAW;EAAQ;EACnD,WAAW,CAAC;EACZ,OAAO,CAAC;CACV;CAEA,MAAM,eAAoC,OAAO,OAAO,MAAM,SAAS;CAMvE,MAAM,gBAAgB;EAAE,GAJD,aAAa,QAAQ,KAAK,YAAY;GAC3D,OAAO,OAAO,OAAO,KAAK,QAAQ,yBAAyB,KAAK,CAAC;EACnE,GAAG,CAAC,CAEoC;EAAG,GAAG;CAAa;CAE3D,IAAI,YAAY,qBAAqB,cAAc,OACjD,KAAK,MAAM,CAAC,SAAS,UAAU,OAAO,QAAQ,cAAc,KAAK,GAAG;EAClE,MAAM,OAAO;EACb,MAAM,cAAc,YAAY,mBAAmB,KAAK,IAAI,GAAG,EAC7D,WAAW,gBAAgB,UAC7B,CAAC;EACA,AAAC,cAAc,MAAc,WAAW;EA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AI;EACtE;EACA,OAAO;CACT,GACA,EAAE,WAAW,cAAc,CAC7B,CACF;CAEA,KAAK,IAAI,IAAI,GAAG,IAAI,aAAa,QAAQ,KACvC,aAAa,EAAE,CAAE,wBAAwB,KAAK;CAGhD,IACE,QAAQ,IAAI,aAAa,kBACxB,aAAa,YAAY,aAAa,aACvC;EACA,MAAM,WAAW,OAAO,KAAK,MAAM,SAAS;EAC5C,MAAM,YAAY,OAAO,QAAQ;GAC/B;GACA;GACA;GACA;GACA;GACA;GACA;GACA;GACA;EACF,CAAC,CAAC,CACC,QAAQ,GAAG,aAAa,OAAO,CAAC,CAChC,KAAK,CAAC,SAAS,GAAG;EACrB,MAAM,SAAS,OAAO,KAAK,MAAM,YAAY;EAE7C,QAAQ,IACN;;gBAEU,SAAS,KAAK,kBAAkB,EAAE;;gBAElC,UAAU,SAAS,UAAU,KAAK,kBAAkB,IAAI,SAAS;;gBAEjE,OAAO,KAAK,kBAAkB,EAAE,KAC1C,EAAE,MAAM,CACV;CACF;CAEA,KAAK,IAAI,IAAI,GAAG,IAAI,aAAa,QAAQ,KACvC,aAAa,EAAE,CAAE,qBAAqB,KAAK;CAG7C,OAAO;AACT"}
@@ -95,6 +95,7 @@ function constructTable(tableOptions) {
95
95
  }
96
96
  return snapshot;
97
97
  }, { debugName: "table/store" }));
98
+ for (let i = 0; i < featuresList.length; i++) featuresList[i].initTableInstanceData?.(table);
98
99
  if (process.env.NODE_ENV === "development" && (tableOptions.debugAll || tableOptions.debugTable)) {
99
100
  const features = Object.keys(table._features);
100
101
  const rowModels = Object.entries({