@@ -13,6 +13,7 @@ import type {
13
13
ColumnOptionsFor ,
14
14
OptionsFor ,
15
15
Plugin ,
16
+ PluginClass ,
16
17
RowMetaFor ,
17
18
TableMetaFor ,
18
19
} from '#interfaces' ;
@@ -121,7 +122,7 @@ export abstract class BasePlugin<Signature = unknown> implements Plugin<Signatur
121
122
row ?: Constructor < RowMetaFor < Signature > > ;
122
123
} ;
123
124
124
- abstract name : string ;
125
+ static pluginName : string ;
125
126
static features ?: string [ ] ;
126
127
static requires ?: string [ ] ;
127
128
}
@@ -151,17 +152,17 @@ export const preferences = {
151
152
* (though, if other plugins can guess how the underlying plugin access
152
153
* works, they can access this data, too. No security guaranteed)
153
154
*/
154
- forColumn < P extends BasePlugin < any > , Data = unknown > ( column : Column < Data > , klass : Class < P > ) {
155
+ forColumn < Data = unknown > ( column : Column < Data > , klass : PluginClass < any > ) {
155
156
return {
156
157
/**
157
158
* delete an entry on the underlying `Map` used for this column-plugin pair
158
159
*/
159
160
delete ( key : string ) {
160
161
let prefs = column . table . preferences ;
161
- let existing = prefs . storage . forPlugin ( klass . name ) ;
162
- let columnPrefs = existing . forColumn ( column . key ) ;
162
+ let existing = klass . pluginName ? prefs . storage . forPlugin ( klass . pluginName ) : null ;
163
+ let columnPrefs = existing ? .forColumn ( column . key ) ;
163
164
164
- columnPrefs . delete ( key ) ;
165
+ columnPrefs ? .delete ( key ) ;
165
166
166
167
return prefs . persist ( ) ;
167
168
} ,
@@ -170,20 +171,20 @@ export const preferences = {
170
171
*/
171
172
get ( key : string ) {
172
173
let prefs = column . table . preferences ;
173
- let existing = prefs . storage . forPlugin ( klass . name ) ;
174
- let columnPrefs = existing . forColumn ( column . key ) ;
174
+ let existing = klass . pluginName ? prefs . storage . forPlugin ( klass . pluginName ) : null ;
175
+ let columnPrefs = existing ? .forColumn ( column . key ) ;
175
176
176
- return columnPrefs . get ( key ) ;
177
+ return columnPrefs ? .get ( key ) ;
177
178
} ,
178
179
/**
179
180
* set an entry on the underlying `Map` used for this column-plugin pair
180
181
*/
181
182
set ( key : string , value : unknown ) {
182
183
let prefs = column . table . preferences ;
183
- let existing = prefs . storage . forPlugin ( klass . name ) ;
184
- let columnPrefs = existing . forColumn ( column . key ) ;
184
+ let existing = klass . pluginName ? prefs . storage . forPlugin ( klass . pluginName ) : null ;
185
+ let columnPrefs = existing ? .forColumn ( column . key ) ;
185
186
186
- columnPrefs . set ( key , value ) ;
187
+ columnPrefs ? .set ( key , value ) ;
187
188
188
189
prefs . persist ( ) ;
189
190
} ,
@@ -196,7 +197,7 @@ export const preferences = {
196
197
* returns an object for bulk updating preferences data
197
198
* for all columns (scoped to key and table)
198
199
*/
199
- forAllColumns < P extends BasePlugin < any > , Data = unknown > ( table : Table < Data > , klass : Class < P > ) {
200
+ forAllColumns < Data = unknown > ( table : Table < Data > , klass : PluginClass < any > ) {
200
201
return {
201
202
/**
202
203
* delete an entry on every column in the underlying column `Map` for this table-plugin pair
@@ -206,10 +207,10 @@ export const preferences = {
206
207
207
208
for ( let column of table . columns ) {
208
209
let prefs = column . table . preferences ;
209
- let existing = prefs . storage . forPlugin ( klass . name ) ;
210
- let columnPrefs = existing . forColumn ( column . key ) ;
210
+ let existing = klass . pluginName ? prefs . storage . forPlugin ( klass . pluginName ) : null ;
211
+ let columnPrefs = existing ? .forColumn ( column . key ) ;
211
212
212
- columnPrefs . delete ( key ) ;
213
+ columnPrefs ? .delete ( key ) ;
213
214
}
214
215
215
216
return tablePrefs . persist ( ) ;
@@ -227,16 +228,16 @@ export const preferences = {
227
228
* (though, if other plugins can guess how the underlying plugin access
228
229
* works, they can access this data, too. No security guaranteed)
229
230
*/
230
- forTable < P extends BasePlugin < any > , Data = unknown > ( table : Table < Data > , klass : Class < P > ) {
231
+ forTable < Data = unknown > ( table : Table < Data > , klass : PluginClass < any > ) {
231
232
return {
232
233
/**
233
234
* delete an entry on the underlying `Map` used for this table-plugin pair
234
235
*/
235
236
delete ( key : string ) {
236
237
let prefs = table . preferences ;
237
- let existing = prefs . storage . forPlugin ( klass . name ) ;
238
+ let existing = klass . pluginName ? prefs . storage . forPlugin ( klass . pluginName ) : null ;
238
239
239
- existing . table . delete ( key ) ;
240
+ existing ? .table . delete ( key ) ;
240
241
241
242
return prefs . persist ( ) ;
242
243
} ,
@@ -245,18 +246,18 @@ export const preferences = {
245
246
*/
246
247
get ( key : string ) {
247
248
let prefs = table . preferences ;
248
- let existing = prefs . storage . forPlugin ( klass . name ) ;
249
+ let existing = klass . pluginName ? prefs . storage . forPlugin ( klass . pluginName ) : null ;
249
250
250
- return existing . table . get ( key ) ;
251
+ return existing ? .table . get ( key ) ;
251
252
} ,
252
253
/**
253
254
* set an entry on the underlying `Map` used for this table-plugin pair
254
255
*/
255
256
set ( key : string , value : unknown ) {
256
257
let prefs = table . preferences ;
257
- let existing = prefs . storage . forPlugin ( klass . name ) ;
258
+ let existing = klass . pluginName ? prefs . storage . forPlugin ( klass . pluginName ) : null ;
258
259
259
- existing . table . set ( key , value ) ;
260
+ existing ? .table . set ( key , value ) ;
260
261
261
262
return prefs . persist ( ) ;
262
263
} ,
@@ -297,7 +298,7 @@ function columnsFor<DataType = any>(
297
298
298
299
if ( requester ) {
299
300
assert (
300
- `[${ requester . name } ] requested columns from the table, but the plugin, ${ requester . name } , ` +
301
+ `[${ requester . pluginName } ] requested columns from the table, but the plugin, ${ requester . pluginName } , ` +
301
302
`is not used in this table` ,
302
303
table . plugins . some ( ( plugin ) => plugin instanceof ( requester as Class < Plugin > ) )
303
304
) ;
@@ -313,7 +314,7 @@ function columnsFor<DataType = any>(
313
314
if ( reordering && reordering . constructor === requester ) {
314
315
if ( visibility ) {
315
316
assert (
316
- `<#${ visibility . name } > defined a 'columns' property, but did not return valid data.` ,
317
+ `<#${ visibility . pluginName } > defined a 'columns' property, but did not return valid data.` ,
317
318
visibility . columns && Array . isArray ( visibility . columns )
318
319
) ;
319
320
@@ -325,7 +326,7 @@ function columnsFor<DataType = any>(
325
326
326
327
if ( reordering ) {
327
328
assert (
328
- `<#${ reordering . name } > defined a 'columns' property, but did not return valid data.` ,
329
+ `<#${ reordering . pluginName } > defined a 'columns' property, but did not return valid data.` ,
329
330
reordering . columns && Array . isArray ( reordering . columns )
330
331
) ;
331
332
@@ -334,7 +335,7 @@ function columnsFor<DataType = any>(
334
335
335
336
if ( visibility ) {
336
337
assert (
337
- `<#${ visibility . name } > defined a 'columns' property, but did not return valid data.` ,
338
+ `<#${ visibility . pluginName } > defined a 'columns' property, but did not return valid data.` ,
338
339
visibility . columns && Array . isArray ( visibility . columns )
339
340
) ;
340
341
@@ -343,7 +344,7 @@ function columnsFor<DataType = any>(
343
344
344
345
if ( sizing ) {
345
346
assert (
346
- `<#${ sizing . name } > defined a 'columns' property, but did not return valid data.` ,
347
+ `<#${ sizing . pluginName } > defined a 'columns' property, but did not return valid data.` ,
347
348
sizing . columns && Array . isArray ( sizing . columns )
348
349
) ;
349
350
@@ -359,7 +360,7 @@ function columnsFor<DataType = any>(
359
360
360
361
if ( reordering ) {
361
362
assert (
362
- `<#${ reordering . name } > defined a 'columns' property, but did not return valid data.` ,
363
+ `<#${ reordering . pluginName } > defined a 'columns' property, but did not return valid data.` ,
363
364
reordering . columns && Array . isArray ( reordering . columns )
364
365
) ;
365
366
@@ -368,7 +369,7 @@ function columnsFor<DataType = any>(
368
369
369
370
if ( visibility ) {
370
371
assert (
371
- `<#${ visibility . name } > defined a 'columns' property, but did not return valid data.` ,
372
+ `<#${ visibility . pluginName } > defined a 'columns' property, but did not return valid data.` ,
372
373
visibility . columns && Array . isArray ( visibility . columns )
373
374
) ;
374
375
@@ -377,7 +378,7 @@ function columnsFor<DataType = any>(
377
378
378
379
if ( sizing ) {
379
380
assert (
380
- `<#${ sizing . name } > defined a 'columns' property, but did not return valid data.` ,
381
+ `<#${ sizing . pluginName } > defined a 'columns' property, but did not return valid data.` ,
381
382
sizing . columns && Array . isArray ( sizing . columns )
382
383
) ;
383
384
@@ -489,16 +490,19 @@ export const meta = {
489
490
*/
490
491
forColumn < P extends BasePlugin < any > , Data = unknown > (
491
492
column : Column < Data > ,
492
- klass : Class < P >
493
+ klass : PluginClass < any >
493
494
) : ColumnMetaFor < SignatureFrom < P > > {
494
495
let columnMeta = column . table [ COLUMN_META_KEY ] ;
495
496
496
497
return getPluginInstance ( columnMeta , column , klass , ( ) => {
497
498
let plugin = column . table . pluginOf ( klass ) ;
498
499
499
- assert ( `[${ klass . name } ] cannot get plugin instance of unregistered plugin class` , plugin ) ;
500
- assert ( `<#${ plugin . name } > plugin does not have meta specified` , plugin . meta ) ;
501
- assert ( `<#${ plugin . name } > plugin does not specify column meta` , plugin . meta . column ) ;
500
+ assert (
501
+ `[${ klass . pluginName } ] cannot get plugin instance of unregistered plugin class` ,
502
+ plugin
503
+ ) ;
504
+ assert ( `<#${ klass . pluginName } > plugin does not have meta specified` , plugin . meta ) ;
505
+ assert ( `<#${ klass . pluginName } > plugin does not specify column meta` , plugin . meta . column ) ;
502
506
503
507
return new plugin . meta . column ( column ) ;
504
508
} ) ;
@@ -514,16 +518,21 @@ export const meta = {
514
518
*/
515
519
forRow < P extends BasePlugin < any > , Data = unknown > (
516
520
row : Row < Data > ,
517
- klass : Class < P >
521
+ klass : PluginClass < any >
518
522
) : RowMetaFor < SignatureFrom < P > > {
519
523
let rowMeta = row . table [ ROW_META_KEY ] ;
520
524
521
525
return getPluginInstance ( rowMeta , row , klass , ( ) => {
522
526
let plugin = row . table . pluginOf ( klass ) ;
523
527
524
- assert ( `[${ klass . name } ] cannot get plugin instance of unregistered plugin class` , plugin ) ;
525
- assert ( `<#${ plugin . name } > plugin does not have meta specified` , plugin . meta ) ;
526
- assert ( `<#${ plugin . name } > plugin does not specify row meta` , plugin . meta . row ) ;
528
+ assert (
529
+ `[${ klass . pluginName } ] cannot get plugin instance of unregistered plugin class` ,
530
+ plugin
531
+ ) ;
532
+
533
+ assert ( `<#${ klass . pluginName } > plugin does not have meta specified` , plugin . meta ) ;
534
+
535
+ assert ( `<#${ klass . pluginName } > plugin does not specify row meta` , plugin . meta . row ) ;
527
536
528
537
return new plugin . meta . row ( row ) ;
529
538
} ) ;
@@ -537,23 +546,27 @@ export const meta = {
537
546
*/
538
547
forTable < P extends BasePlugin < any > , Data = unknown > (
539
548
table : Table < Data > ,
540
- klass : Class < P >
549
+ klass : PluginClass < any >
541
550
) : TableMetaFor < SignatureFrom < P > > {
542
551
let tableMeta = table [ TABLE_META_KEY ] ;
543
552
544
553
return getPluginInstance ( tableMeta , klass , ( ) => {
545
554
let plugin = table . pluginOf ( klass ) ;
546
555
547
- assert ( `[${ klass . name } ] cannot get plugin instance of unregistered plugin class` , plugin ) ;
548
- assert ( `<#${ plugin . name } > plugin does not have meta specified` , plugin . meta ) ;
549
- assert ( `<#${ plugin . name } > plugin does not specify table meta` , plugin . meta . table ) ;
550
556
assert (
551
- `<#${ plugin . name } > plugin already exists for the table. ` +
557
+ `[${ klass . pluginName } ] cannot get plugin instance of unregistered plugin class` ,
558
+ plugin
559
+ ) ;
560
+ assert ( `<#${ klass . pluginName } > plugin does not have meta specified` , plugin . meta ) ;
561
+ assert ( `<#${ klass . pluginName } > plugin does not specify table meta` , plugin . meta . table ) ;
562
+ assert (
563
+ `<#${ klass . pluginName } > plugin already exists for the table. ` +
552
564
`A plugin may only be instantiated once per table.` ,
565
+
553
566
! [ ...tableMeta . keys ( ) ] . includes ( klass )
554
567
) ;
555
568
556
- return new plugin . meta . table ( table ) ;
569
+ return plugin ?. meta ?. table && new plugin . meta . table ( table ) ;
557
570
} ) ;
558
571
} ,
559
572
@@ -662,7 +675,7 @@ export const options = {
662
675
*/
663
676
forTable < P extends BasePlugin < any > , Data = unknown > (
664
677
table : Table < Data > ,
665
- klass : Class < P >
678
+ klass : PluginClass < any >
666
679
) : Partial < OptionsFor < SignatureFrom < P > > > {
667
680
let normalized = normalizePluginsConfig ( table ?. config ?. plugins ) ;
668
681
let tuple = normalized ?. find ( ( option ) => option [ 0 ] === klass ) ;
@@ -678,7 +691,7 @@ export const options = {
678
691
679
692
forColumn < P extends BasePlugin < any > , Data = unknown > (
680
693
column : Column < Data > ,
681
- klass : Class < P >
694
+ klass : PluginClass < any >
682
695
) : Partial < ColumnOptionsFor < SignatureFrom < P > > > {
683
696
let tuple = column . config . pluginOptions ?. find ( ( option ) => option [ 0 ] === klass ) ;
684
697
let t = tuple as [ unknown , ( ) => ColumnOptionsFor < SignatureFrom < P > > ] ;
0 commit comments