@timlassiter11/yatl 1.0.13 → 1.0.15

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
package/dist/index.d.mts CHANGED
@@ -13,6 +13,15 @@ type UnspecifiedRecord = Record<string, any>;
13
13
  * Record that maps a column's field to arbitrary data.
14
14
  */
15
15
  type ColumnPropertyRecord<TData, TProp> = Partial<Record<NestedKeyOf<TData>, TProp>>;
16
+ type RowId = string | number;
17
+ type RowIdCallback<T> = (row: T, index: number) => RowId;
18
+ /**
19
+ * The method used for selecting rows.
20
+ * * single - Only a single row can be selected at a time
21
+ * * multi - Multiple rows can be selected at a time
22
+ * * null - Disable row selection
23
+ */
24
+ type RowSelectionMethod = 'single' | 'multi' | null;
16
25
  /**
17
26
  * Defines the possible sorting orders for columns.
18
27
  */
@@ -278,12 +287,13 @@ declare class YatlEvent<T = unknown> extends CustomEvent<T> {
278
287
  }
279
288
  declare class YatlRowClickEvent<T> extends YatlEvent<{
280
289
  row: T;
290
+ id: RowId;
281
291
  index: number;
282
292
  field: NestedKeyOf<T>;
283
293
  originalEvent: MouseEvent;
284
294
  }> {
285
295
  static readonly EVENT_NAME = "yatl-row-click";
286
- constructor(row: T, index: number, field: NestedKeyOf<T>, originalEvent: MouseEvent);
296
+ constructor(row: T, id: RowId, index: number, field: NestedKeyOf<T>, originalEvent: MouseEvent);
287
297
  }
288
298
  declare class YatlChangeEvent<T> extends YatlEvent<{
289
299
  data: T[];
@@ -326,6 +336,13 @@ declare class YatlSearchEvent extends YatlEvent<{
326
336
  static readonly EVENT_NAME = "yatl-search";
327
337
  constructor(query: string);
328
338
  }
339
+ declare class YatlRowSelectEvent<T> extends YatlEvent<{
340
+ row: T;
341
+ selectedIds: RowId[];
342
+ }> {
343
+ static readonly EVENT_NAME = "yatl-row-select";
344
+ constructor(row: T, selectedIds: RowId[]);
345
+ }
329
346
  declare class YatlStateChangeEvent<T> extends YatlEvent<{
330
347
  state: TableState<T>;
331
348
  triggers: string[];
@@ -355,14 +372,16 @@ declare class YatlTable<T extends object = UnspecifiedRecord> extends LitElement
355
372
  private tableElement;
356
373
  private virtualizer?;
357
374
  private headerElement;
358
- private scrollerElement;
359
375
  private _enableSearchTokenization;
360
376
  private _enableSearchScoring;
361
377
  private _columns;
362
378
  private _columnDefinitionMap;
363
379
  private _columnStateMap;
364
380
  private _columnOrder;
381
+ private _rowSelectionMethod;
382
+ private _selectedRowIds;
365
383
  private _storageOptions;
384
+ private _rowIdCallback;
366
385
  private _data;
367
386
  private _searchQuery;
368
387
  private _searchTokenizer;
@@ -374,6 +393,7 @@ declare class YatlTable<T extends object = UnspecifiedRecord> extends LitElement
374
393
  private sortDirty;
375
394
  private dataLastUpdate;
376
395
  private rowMetadata;
396
+ private idToRowMap;
377
397
  private queryTokens;
378
398
  private resizeState;
379
399
  private dragColumn;
@@ -427,6 +447,10 @@ declare class YatlTable<T extends object = UnspecifiedRecord> extends LitElement
427
447
  * @default true
428
448
  */
429
449
  enableColumnReorder: boolean;
450
+ /**
451
+ * Shows a column to the left of each row with its row number.
452
+ */
453
+ enableRowNumberColumn: boolean;
430
454
  /**
431
455
  * Shows the built-in footer row which displays the current record count.
432
456
  * The footer content can be customized using the `slot="footer"` element.
@@ -518,12 +542,29 @@ declare class YatlTable<T extends object = UnspecifiedRecord> extends LitElement
518
542
  * A callback function to conditionally apply CSS parts to table rows.
519
543
  */
520
544
  rowParts: RowPartsCallback<T> | null;
545
+ /**
546
+ * The row selection method to use.
547
+ * * single - Only a single row can be selected at a time
548
+ * * multi - Multiple rows can be selected at a time
549
+ * * null - Disable row selection
550
+ */
551
+ get rowSelectionMethod(): RowSelectionMethod;
552
+ set rowSelectionMethod(selection: RowSelectionMethod);
553
+ /**
554
+ * List of currently selected row indexes.
555
+ * * **NOTE**: These indexes are based off the of
556
+ * the original data array index, *not* the filtered data.
557
+ */
558
+ get selectedRowIds(): RowId[];
559
+ set selectedRowIds(rows: RowId[]);
521
560
  /**
522
561
  * Configuration options for automatically saving and restoring table state
523
562
  * (column width, order, visibility, etc.) to browser storage.
524
563
  */
525
564
  get storageOptions(): StorageOptions | null;
526
565
  set storageOptions(options: StorageOptions | null);
566
+ get rowIdCallback(): RowIdCallback<T>;
567
+ set rowIdCallback(callback: RowIdCallback<T>);
527
568
  /**
528
569
  * The array of data objects to be displayed.
529
570
  * Objects must satisfy the `WeakKey` constraint (objects only, no primitives).
@@ -586,11 +627,17 @@ declare class YatlTable<T extends object = UnspecifiedRecord> extends LitElement
586
627
  scrollToFilteredIndex(index: number): Promise<void>;
587
628
  scrollToPx(px: number): Promise<void>;
588
629
  /**
589
- * Finds the first row
590
- * @param field
591
- * @param value
630
+ * Gets the row associated with the provided ID.
631
+ * @param id - The ID of the row to get
592
632
  * @returns
593
633
  */
634
+ getRow(id: RowId): T | undefined;
635
+ /**
636
+ * Finds the first row where {@link field} matches {@link value}
637
+ * @param field - The field name within the row data to search.
638
+ * @param value - The value to match against the field's content.
639
+ * @returns The found row, or undefined if no match is found.
640
+ */
594
641
  findRow(field: NestedKeyOf<T>, value: unknown): T | undefined;
595
642
  /**
596
643
  * Finds the original index of the first row where the specified field matches the given value.
@@ -607,6 +654,7 @@ declare class YatlTable<T extends object = UnspecifiedRecord> extends LitElement
607
654
  * ```
608
655
  */
609
656
  findRowIndex(field: NestedKeyOf<T>, value: unknown): number;
657
+ updateRow(rowId: RowId, data: Partial<T>): void;
610
658
  /**
611
659
  * Updates the data of a row at a specific original index.
612
660
  * @param index - The original index of the row to update.
@@ -620,19 +668,28 @@ declare class YatlTable<T extends object = UnspecifiedRecord> extends LitElement
620
668
  * }
621
669
  * ```
622
670
  */
623
- updateRow(index: number, data: Partial<T>): void;
671
+ updateRowAtIndex(index: number, data: Partial<T>): void;
672
+ /**
673
+ * Deletes the row with the matching ID.
674
+ * @param id - The ID of the row to delete
675
+ */
676
+ deleteRow(rowId: RowId): void;
624
677
  /**
625
678
  * Deletes a row at a specific original index from the table.
626
679
  * @param index - The original index of the row to delete.
627
680
  */
628
- deleteRow(index: number): void;
681
+ deleteRowAtIndex(index: number): void;
629
682
  protected renderColumnSortIcon(column: DisplayColumnOptions<T>, state: ColumnState<T>): TemplateResult<1> | typeof nothing;
630
683
  protected renderColumnResizer(column: DisplayColumnOptions<T>, _state: ColumnState<T>): TemplateResult<1> | typeof nothing;
631
684
  protected renderHeaderCell(field: NestedKeyOf<T>): TemplateResult<1> | typeof nothing;
685
+ protected renderColumnIndexHeader(): TemplateResult<1>;
686
+ protected renderSelectionHeader(): TemplateResult<1>;
632
687
  protected renderHeader(): TemplateResult<1>;
633
688
  protected renderCellContents(value: unknown, column: DisplayColumnOptions<T>, row: T): unknown;
634
689
  protected renderCell(field: NestedKeyOf<T>, row: T): TemplateResult<1> | typeof nothing | undefined;
635
- protected renderRow(row: T, index: number): TemplateResult<1>;
690
+ protected renderRowSelectorCell(row: T, selected: boolean): TemplateResult<1>;
691
+ protected renderRowNumberCell(rowNumber: number): TemplateResult<1>;
692
+ protected renderRow(row: T, renderIndex: number): TemplateResult<1>;
636
693
  protected renderBodyContents(): TemplateResult<1>;
637
694
  protected renderFooter(): TemplateResult<1> | typeof nothing;
638
695
  protected render(): TemplateResult<1>;
@@ -687,6 +744,7 @@ declare class YatlTable<T extends object = UnspecifiedRecord> extends LitElement
687
744
  private handleDragColumnOver;
688
745
  private handleDragColumnDrop;
689
746
  private handleDragColumnEnd;
747
+ private handleRowSelectionClicked;
690
748
  addEventListener<K extends keyof EventMap<T>>(type: K, listener: (this: EventMap<T>, ev: EventMap<T>[K]) => void, options?: boolean | AddEventListenerOptions): void;
691
749
  addEventListener(type: string, listener: EventListenerOrEventListenerObject, options?: boolean | AddEventListenerOptions): void;
692
750
  removeEventListener<K extends keyof EventMap<T>>(type: K, listener: EventListenerOrEventListenerObject, options?: boolean | EventListenerOptions): void;
@@ -703,6 +761,7 @@ interface EventMap<T> {
703
761
  'yatl-column-resize': YatlColumnResizeEvent<T>;
704
762
  'yatl-column-reorder': YatlColumnReorderEvent<T>;
705
763
  'yatl-search': YatlSearchEvent;
764
+ 'yatl-row-select': YatlRowSelectEvent<T>;
706
765
  'yatl-state-change': YatlStateChangeEvent<T>;
707
766
  }
708
767
  declare global {
@@ -711,4 +770,4 @@ declare global {
711
770
  }
712
771
  }
713
772
 
714
- export { type BaseColumnOptions, type CellPartsCallback, type CellRenderCallback, type ColumnFilterCallback, type ColumnInitOptions, type ColumnOptions, type ColumnPropertyRecord, type ColumnRole, type ColumnState, type ComparatorCallback, type Compareable, type DisplayColumnOptions, type FilterCallback, type Filters, type InternalColumnOptions, type NestedKeyOf, type QueryToken, type RestorableColumnState, type RestorableTableState, type RowPartsCallback, type SortOrder, type SortState, type SortValueCallback, type StorageOptions, type TableState, type TokenizerCallback, type UnspecifiedRecord, type ValueFormatterCallback, YatlChangeEvent, YatlColumnReorderEvent, YatlColumnResizeEvent, YatlColumnToggleEvent, YatlEvent, YatlRowClickEvent, YatlSearchEvent, YatlSortEvent, YatlStateChangeEvent, YatlTable, createRegexTokenizer, isDisplayColumn, isInternalColumn, whitespaceTokenizer };
773
+ export { type BaseColumnOptions, type CellPartsCallback, type CellRenderCallback, type ColumnFilterCallback, type ColumnInitOptions, type ColumnOptions, type ColumnPropertyRecord, type ColumnRole, type ColumnState, type ComparatorCallback, type Compareable, type DisplayColumnOptions, type FilterCallback, type Filters, type InternalColumnOptions, type NestedKeyOf, type QueryToken, type RestorableColumnState, type RestorableTableState, type RowId, type RowIdCallback, type RowPartsCallback, type RowSelectionMethod, type SortOrder, type SortState, type SortValueCallback, type StorageOptions, type TableState, type TokenizerCallback, type UnspecifiedRecord, type ValueFormatterCallback, YatlChangeEvent, YatlColumnReorderEvent, YatlColumnResizeEvent, YatlColumnToggleEvent, YatlEvent, YatlRowClickEvent, YatlRowSelectEvent, YatlSearchEvent, YatlSortEvent, YatlStateChangeEvent, YatlTable, createRegexTokenizer, isDisplayColumn, isInternalColumn, whitespaceTokenizer };
package/dist/index.d.ts CHANGED
@@ -13,6 +13,15 @@ type UnspecifiedRecord = Record<string, any>;
13
13
  * Record that maps a column's field to arbitrary data.
14
14
  */
15
15
  type ColumnPropertyRecord<TData, TProp> = Partial<Record<NestedKeyOf<TData>, TProp>>;
16
+ type RowId = string | number;
17
+ type RowIdCallback<T> = (row: T, index: number) => RowId;
18
+ /**
19
+ * The method used for selecting rows.
20
+ * * single - Only a single row can be selected at a time
21
+ * * multi - Multiple rows can be selected at a time
22
+ * * null - Disable row selection
23
+ */
24
+ type RowSelectionMethod = 'single' | 'multi' | null;
16
25
  /**
17
26
  * Defines the possible sorting orders for columns.
18
27
  */
@@ -278,12 +287,13 @@ declare class YatlEvent<T = unknown> extends CustomEvent<T> {
278
287
  }
279
288
  declare class YatlRowClickEvent<T> extends YatlEvent<{
280
289
  row: T;
290
+ id: RowId;
281
291
  index: number;
282
292
  field: NestedKeyOf<T>;
283
293
  originalEvent: MouseEvent;
284
294
  }> {
285
295
  static readonly EVENT_NAME = "yatl-row-click";
286
- constructor(row: T, index: number, field: NestedKeyOf<T>, originalEvent: MouseEvent);
296
+ constructor(row: T, id: RowId, index: number, field: NestedKeyOf<T>, originalEvent: MouseEvent);
287
297
  }
288
298
  declare class YatlChangeEvent<T> extends YatlEvent<{
289
299
  data: T[];
@@ -326,6 +336,13 @@ declare class YatlSearchEvent extends YatlEvent<{
326
336
  static readonly EVENT_NAME = "yatl-search";
327
337
  constructor(query: string);
328
338
  }
339
+ declare class YatlRowSelectEvent<T> extends YatlEvent<{
340
+ row: T;
341
+ selectedIds: RowId[];
342
+ }> {
343
+ static readonly EVENT_NAME = "yatl-row-select";
344
+ constructor(row: T, selectedIds: RowId[]);
345
+ }
329
346
  declare class YatlStateChangeEvent<T> extends YatlEvent<{
330
347
  state: TableState<T>;
331
348
  triggers: string[];
@@ -355,14 +372,16 @@ declare class YatlTable<T extends object = UnspecifiedRecord> extends LitElement
355
372
  private tableElement;
356
373
  private virtualizer?;
357
374
  private headerElement;
358
- private scrollerElement;
359
375
  private _enableSearchTokenization;
360
376
  private _enableSearchScoring;
361
377
  private _columns;
362
378
  private _columnDefinitionMap;
363
379
  private _columnStateMap;
364
380
  private _columnOrder;
381
+ private _rowSelectionMethod;
382
+ private _selectedRowIds;
365
383
  private _storageOptions;
384
+ private _rowIdCallback;
366
385
  private _data;
367
386
  private _searchQuery;
368
387
  private _searchTokenizer;
@@ -374,6 +393,7 @@ declare class YatlTable<T extends object = UnspecifiedRecord> extends LitElement
374
393
  private sortDirty;
375
394
  private dataLastUpdate;
376
395
  private rowMetadata;
396
+ private idToRowMap;
377
397
  private queryTokens;
378
398
  private resizeState;
379
399
  private dragColumn;
@@ -427,6 +447,10 @@ declare class YatlTable<T extends object = UnspecifiedRecord> extends LitElement
427
447
  * @default true
428
448
  */
429
449
  enableColumnReorder: boolean;
450
+ /**
451
+ * Shows a column to the left of each row with its row number.
452
+ */
453
+ enableRowNumberColumn: boolean;
430
454
  /**
431
455
  * Shows the built-in footer row which displays the current record count.
432
456
  * The footer content can be customized using the `slot="footer"` element.
@@ -518,12 +542,29 @@ declare class YatlTable<T extends object = UnspecifiedRecord> extends LitElement
518
542
  * A callback function to conditionally apply CSS parts to table rows.
519
543
  */
520
544
  rowParts: RowPartsCallback<T> | null;
545
+ /**
546
+ * The row selection method to use.
547
+ * * single - Only a single row can be selected at a time
548
+ * * multi - Multiple rows can be selected at a time
549
+ * * null - Disable row selection
550
+ */
551
+ get rowSelectionMethod(): RowSelectionMethod;
552
+ set rowSelectionMethod(selection: RowSelectionMethod);
553
+ /**
554
+ * List of currently selected row indexes.
555
+ * * **NOTE**: These indexes are based off the of
556
+ * the original data array index, *not* the filtered data.
557
+ */
558
+ get selectedRowIds(): RowId[];
559
+ set selectedRowIds(rows: RowId[]);
521
560
  /**
522
561
  * Configuration options for automatically saving and restoring table state
523
562
  * (column width, order, visibility, etc.) to browser storage.
524
563
  */
525
564
  get storageOptions(): StorageOptions | null;
526
565
  set storageOptions(options: StorageOptions | null);
566
+ get rowIdCallback(): RowIdCallback<T>;
567
+ set rowIdCallback(callback: RowIdCallback<T>);
527
568
  /**
528
569
  * The array of data objects to be displayed.
529
570
  * Objects must satisfy the `WeakKey` constraint (objects only, no primitives).
@@ -586,11 +627,17 @@ declare class YatlTable<T extends object = UnspecifiedRecord> extends LitElement
586
627
  scrollToFilteredIndex(index: number): Promise<void>;
587
628
  scrollToPx(px: number): Promise<void>;
588
629
  /**
589
- * Finds the first row
590
- * @param field
591
- * @param value
630
+ * Gets the row associated with the provided ID.
631
+ * @param id - The ID of the row to get
592
632
  * @returns
593
633
  */
634
+ getRow(id: RowId): T | undefined;
635
+ /**
636
+ * Finds the first row where {@link field} matches {@link value}
637
+ * @param field - The field name within the row data to search.
638
+ * @param value - The value to match against the field's content.
639
+ * @returns The found row, or undefined if no match is found.
640
+ */
594
641
  findRow(field: NestedKeyOf<T>, value: unknown): T | undefined;
595
642
  /**
596
643
  * Finds the original index of the first row where the specified field matches the given value.
@@ -607,6 +654,7 @@ declare class YatlTable<T extends object = UnspecifiedRecord> extends LitElement
607
654
  * ```
608
655
  */
609
656
  findRowIndex(field: NestedKeyOf<T>, value: unknown): number;
657
+ updateRow(rowId: RowId, data: Partial<T>): void;
610
658
  /**
611
659
  * Updates the data of a row at a specific original index.
612
660
  * @param index - The original index of the row to update.
@@ -620,19 +668,28 @@ declare class YatlTable<T extends object = UnspecifiedRecord> extends LitElement
620
668
  * }
621
669
  * ```
622
670
  */
623
- updateRow(index: number, data: Partial<T>): void;
671
+ updateRowAtIndex(index: number, data: Partial<T>): void;
672
+ /**
673
+ * Deletes the row with the matching ID.
674
+ * @param id - The ID of the row to delete
675
+ */
676
+ deleteRow(rowId: RowId): void;
624
677
  /**
625
678
  * Deletes a row at a specific original index from the table.
626
679
  * @param index - The original index of the row to delete.
627
680
  */
628
- deleteRow(index: number): void;
681
+ deleteRowAtIndex(index: number): void;
629
682
  protected renderColumnSortIcon(column: DisplayColumnOptions<T>, state: ColumnState<T>): TemplateResult<1> | typeof nothing;
630
683
  protected renderColumnResizer(column: DisplayColumnOptions<T>, _state: ColumnState<T>): TemplateResult<1> | typeof nothing;
631
684
  protected renderHeaderCell(field: NestedKeyOf<T>): TemplateResult<1> | typeof nothing;
685
+ protected renderColumnIndexHeader(): TemplateResult<1>;
686
+ protected renderSelectionHeader(): TemplateResult<1>;
632
687
  protected renderHeader(): TemplateResult<1>;
633
688
  protected renderCellContents(value: unknown, column: DisplayColumnOptions<T>, row: T): unknown;
634
689
  protected renderCell(field: NestedKeyOf<T>, row: T): TemplateResult<1> | typeof nothing | undefined;
635
- protected renderRow(row: T, index: number): TemplateResult<1>;
690
+ protected renderRowSelectorCell(row: T, selected: boolean): TemplateResult<1>;
691
+ protected renderRowNumberCell(rowNumber: number): TemplateResult<1>;
692
+ protected renderRow(row: T, renderIndex: number): TemplateResult<1>;
636
693
  protected renderBodyContents(): TemplateResult<1>;
637
694
  protected renderFooter(): TemplateResult<1> | typeof nothing;
638
695
  protected render(): TemplateResult<1>;
@@ -687,6 +744,7 @@ declare class YatlTable<T extends object = UnspecifiedRecord> extends LitElement
687
744
  private handleDragColumnOver;
688
745
  private handleDragColumnDrop;
689
746
  private handleDragColumnEnd;
747
+ private handleRowSelectionClicked;
690
748
  addEventListener<K extends keyof EventMap<T>>(type: K, listener: (this: EventMap<T>, ev: EventMap<T>[K]) => void, options?: boolean | AddEventListenerOptions): void;
691
749
  addEventListener(type: string, listener: EventListenerOrEventListenerObject, options?: boolean | AddEventListenerOptions): void;
692
750
  removeEventListener<K extends keyof EventMap<T>>(type: K, listener: EventListenerOrEventListenerObject, options?: boolean | EventListenerOptions): void;
@@ -703,6 +761,7 @@ interface EventMap<T> {
703
761
  'yatl-column-resize': YatlColumnResizeEvent<T>;
704
762
  'yatl-column-reorder': YatlColumnReorderEvent<T>;
705
763
  'yatl-search': YatlSearchEvent;
764
+ 'yatl-row-select': YatlRowSelectEvent<T>;
706
765
  'yatl-state-change': YatlStateChangeEvent<T>;
707
766
  }
708
767
  declare global {
@@ -711,4 +770,4 @@ declare global {
711
770
  }
712
771
  }
713
772
 
714
- export { type BaseColumnOptions, type CellPartsCallback, type CellRenderCallback, type ColumnFilterCallback, type ColumnInitOptions, type ColumnOptions, type ColumnPropertyRecord, type ColumnRole, type ColumnState, type ComparatorCallback, type Compareable, type DisplayColumnOptions, type FilterCallback, type Filters, type InternalColumnOptions, type NestedKeyOf, type QueryToken, type RestorableColumnState, type RestorableTableState, type RowPartsCallback, type SortOrder, type SortState, type SortValueCallback, type StorageOptions, type TableState, type TokenizerCallback, type UnspecifiedRecord, type ValueFormatterCallback, YatlChangeEvent, YatlColumnReorderEvent, YatlColumnResizeEvent, YatlColumnToggleEvent, YatlEvent, YatlRowClickEvent, YatlSearchEvent, YatlSortEvent, YatlStateChangeEvent, YatlTable, createRegexTokenizer, isDisplayColumn, isInternalColumn, whitespaceTokenizer };
773
+ export { type BaseColumnOptions, type CellPartsCallback, type CellRenderCallback, type ColumnFilterCallback, type ColumnInitOptions, type ColumnOptions, type ColumnPropertyRecord, type ColumnRole, type ColumnState, type ComparatorCallback, type Compareable, type DisplayColumnOptions, type FilterCallback, type Filters, type InternalColumnOptions, type NestedKeyOf, type QueryToken, type RestorableColumnState, type RestorableTableState, type RowId, type RowIdCallback, type RowPartsCallback, type RowSelectionMethod, type SortOrder, type SortState, type SortValueCallback, type StorageOptions, type TableState, type TokenizerCallback, type UnspecifiedRecord, type ValueFormatterCallback, YatlChangeEvent, YatlColumnReorderEvent, YatlColumnResizeEvent, YatlColumnToggleEvent, YatlEvent, YatlRowClickEvent, YatlRowSelectEvent, YatlSearchEvent, YatlSortEvent, YatlStateChangeEvent, YatlTable, createRegexTokenizer, isDisplayColumn, isInternalColumn, whitespaceTokenizer };