@@ -7,7 +7,7 @@ import type { Table } from '../../-private/table';
7
7
import type { ColumnReordering } from '../column-reordering' ;
8
8
import type { ColumnVisibility } from '../column-visibility' ;
9
9
import type { Class , Constructor } from '[private-types]' ;
10
- import type { Column } from '[public-types]' ;
10
+ import type { Column , Row } from '[public-types]' ;
11
11
import type {
12
12
ColumnMetaFor ,
13
13
ColumnOptionsFor ,
@@ -19,6 +19,7 @@ import type {
19
19
20
20
const TABLE_META = new Map < string , Map < Class < unknown > , any > > ( ) ;
21
21
const COLUMN_META = new WeakMap < Column , Map < Class < unknown > , any > > ( ) ;
22
+ const ROW_META = new WeakMap < Row , Map < Class < unknown > , any > > ( ) ;
22
23
23
24
type InstanceOf < T > = T extends Class < infer Instance > ? Instance : T ;
24
25
@@ -250,6 +251,29 @@ export const meta = {
250
251
} ) ;
251
252
} ,
252
253
254
+ /**
255
+ * @public
256
+ *
257
+ * For a given row and plugin, return the meta / state bucket for the
258
+ * plugin<->row instance pair.
259
+ *
260
+ * Note that this requires the row instance to exist on the table.
261
+ */
262
+ forRow < P extends BasePlugin < any > , Data = unknown > (
263
+ row : Row < Data > ,
264
+ klass : Class < P > ,
265
+ ) : RowMetaFor < SignatureFrom < P > > {
266
+ return getPluginInstance ( ROW_META , row , klass , ( ) => {
267
+ let plugin = row . table . pluginOf ( klass ) ;
268
+
269
+ assert ( `[${ klass . name } ] cannot get plugin instance of unregistered plugin class` , plugin ) ;
270
+ assert ( `<#${ plugin . name } > plugin does not have meta specified` , plugin . meta ) ;
271
+ assert ( `<#${ plugin . name } > plugin does not specify row meta` , plugin . meta . row ) ;
272
+
273
+ return new plugin . meta . row ( row ) ;
274
+ } ) ;
275
+ } ,
276
+
253
277
/**
254
278
* @public
255
279
*
@@ -413,10 +437,10 @@ export const options = {
413
437
/**
414
438
* @private
415
439
*/
416
- function getPluginInstance < RootKey extends string | Column < any > , Instance > (
440
+ function getPluginInstance < RootKey extends string | Column < any > | Row < any > , Instance > (
417
441
map : RootKey extends string
418
442
? Map < string , Map < Class < Instance > , Instance > >
419
- : WeakMap < Column , Map < Class < Instance > , Instance > > ,
443
+ : WeakMap < Column | Row , Map < Class < Instance > , Instance > > ,
420
444
rootKey : RootKey ,
421
445
mapKey : Class < Instance > ,
422
446
factory : ( ) => Instance
0 commit comments