@guiexpert/svelte-table 4.1.79 → 4.1.80

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 (2) hide show
  1. package/index.js +1013 -41
  2. package/package.json +5 -3
package/index.js CHANGED
@@ -732,28 +732,128 @@ class Xe {
732
732
  }
733
733
  }
734
734
  class F extends je {
735
+ /**
736
+ * Creates an instance of AreaModelObjectArray.
737
+ *
738
+ * @param {AreaIdent} areaIdent - Identifies which area of the table this model represents ('header', 'body', or 'footer')
739
+ * @param {T[]} rows - The array of objects that represent the rows in this area
740
+ * @param {number} defaultRowHeight - The default height for rows in this area (in pixels)
741
+ * @param {ColumnDefIf[]} [columnDefs=[]] - Definitions for the columns in this area
742
+ * @param {string} [selectedRowClass='ge-selected-row'] - CSS class to apply to selected rows
743
+ * @param {string} [focusedRowClass='ge-focused-row'] - CSS class to apply to the focused row
744
+ *
745
+ * @example
746
+ * const rows = [
747
+ * { id: 1, name: 'John', age: 30 },
748
+ * { id: 2, name: 'Jane', age: 25 }
749
+ * ];
750
+ *
751
+ * const columnDefs = [
752
+ * { property: 'id', headerLabel: 'ID', width: 50 },
753
+ * { property: 'name', headerLabel: 'Name', width: 150 },
754
+ * { property: 'age', headerLabel: 'Age', width: 100 }
755
+ * ];
756
+ *
757
+ * const bodyAreaModel = new AreaModelObjectArray(
758
+ * 'body',
759
+ * rows,
760
+ * 30,
761
+ * columnDefs
762
+ * );
763
+ */
735
764
  constructor(e, t, s, o = [], i = "ge-selected-row", r = "ge-focused-row") {
736
765
  super(e, o, s), this.areaIdent = e, this.rows = t, this.defaultRowHeight = s, this.columnDefs = o, this.selectedRowClass = i, this.focusedRowClass = r, this.sorterService = new Xe(), this._focusedRowIndex = 0, this.filteredRows = [...t], this.properties = o.map((a) => a.property);
737
766
  }
767
+ /**
768
+ * Gets the index of the currently focused row.
769
+ *
770
+ * @returns {number} The index of the focused row
771
+ *
772
+ * @example
773
+ * const focusedRowIndex = bodyAreaModel.getFocusedRowIndex();
774
+ * console.log(`The focused row is at index ${focusedRowIndex}`);
775
+ */
738
776
  getFocusedRowIndex() {
739
777
  return this._focusedRowIndex;
740
778
  }
779
+ /**
780
+ * Sets the index of the focused row.
781
+ * This will apply the focused row styling to the specified row.
782
+ *
783
+ * @param {number} value - The index of the row to focus
784
+ *
785
+ * @example
786
+ * // Focus the second row (index 1)
787
+ * bodyAreaModel.setFocusedRowIndex(1);
788
+ */
741
789
  setFocusedRowIndex(e) {
742
790
  this._focusedRowIndex = e;
743
791
  }
792
+ /**
793
+ * Replaces the current rows array with a new one.
794
+ * This also resets the filtered rows to match the new rows array.
795
+ *
796
+ * @param {T[]} rows - The new array of row objects
797
+ *
798
+ * @example
799
+ * // Replace the current rows with new data
800
+ * const newRows = [
801
+ * { id: 4, name: 'Alice', age: 35 },
802
+ * { id: 5, name: 'Charlie', age: 45 }
803
+ * ];
804
+ * bodyAreaModel.setRows(newRows);
805
+ */
744
806
  setRows(e) {
745
807
  this.rows = e, this.filteredRows = [...e];
746
808
  }
809
+ /**
810
+ * Filters both the original rows and filtered rows arrays using the provided predicate function.
811
+ * Unlike `externalFilterChanged`, this method permanently modifies the original rows array.
812
+ *
813
+ * @param {(row: T) => boolean} predict - A function that returns true for rows to keep and false for rows to filter out
814
+ *
815
+ * @example
816
+ * // Remove all rows where age is less than 30
817
+ * bodyAreaModel.filterRowsByPredict(row => row.age >= 30);
818
+ */
747
819
  filterRowsByPredict(e) {
748
820
  this.rows = this.rows.filter(e), this.filteredRows = this.filteredRows.filter(e);
749
821
  }
750
822
  /**
751
- * return row count of filtered rows
823
+ * Returns the number of rows in the filtered rows array.
824
+ * This is used to determine how many rows should be rendered in the table.
825
+ *
826
+ * @returns {number} The number of rows in the filtered rows array
827
+ *
828
+ * @example
829
+ * const rowCount = bodyAreaModel.getRowCount();
830
+ * console.log(`The table has ${rowCount} rows`);
752
831
  */
753
832
  getRowCount() {
754
833
  var e;
755
834
  return ((e = this.filteredRows) == null ? void 0 : e.length) ?? 0;
756
835
  }
836
+ /**
837
+ * Gets the value at the specified row and column indices.
838
+ * This method handles tree rows and nested properties.
839
+ *
840
+ * @param {number} rowIndex - The index of the row
841
+ * @param {number} columnIndex - The index of the column
842
+ * @returns {any} The value at the specified cell, or an empty string if not found
843
+ *
844
+ * @example
845
+ * // Get the value in the first row, second column
846
+ * const value = bodyAreaModel.getValueAt(0, 1);
847
+ * console.log(`The value is: ${value}`);
848
+ *
849
+ * @example
850
+ * // Iterate through all cells in a row
851
+ * const rowIndex = 0;
852
+ * for (let colIndex = 0; colIndex < columnDefs.length; colIndex++) {
853
+ * const value = bodyAreaModel.getValueAt(rowIndex, colIndex);
854
+ * console.log(`Cell (${rowIndex}, ${colIndex}): ${value}`);
855
+ * }
856
+ */
757
857
  getValueAt(e, t) {
758
858
  const s = this.properties[t];
759
859
  let o = this.filteredRows[e];
@@ -762,46 +862,176 @@ class F extends je {
762
862
  /**
763
863
  * Retrieves the filtered and sorted rows from the dataset.
764
864
  * These rows are used for rendering the table.
865
+ * Unlike `getAllRows()`, this method returns only the rows that match any applied filters.
765
866
  *
766
- * @return {T[]} An array containing the filtered (and sorted) rows.
867
+ * @returns {T[]} An array containing the filtered (and sorted) rows
868
+ *
869
+ * @example
870
+ * // Get all filtered rows
871
+ * const filteredRows = bodyAreaModel.getFilteredRows();
872
+ *
873
+ * // Count rows that match a certain condition
874
+ * const adultsCount = filteredRows.filter(row => row.age >= 18).length;
767
875
  */
768
876
  getFilteredRows() {
769
877
  return this.filteredRows;
770
878
  }
879
+ /**
880
+ * Returns the original, unfiltered array of rows.
881
+ * This can be useful when you need to access all data regardless of any applied filters.
882
+ *
883
+ * @returns {T[]} The original array of row objects
884
+ *
885
+ * @example
886
+ * // Get all rows, including those filtered out
887
+ * const allRows = bodyAreaModel.getAllRows();
888
+ *
889
+ * // Calculate average age across all rows
890
+ * const totalAge = allRows.reduce((sum, row) => sum + row.age, 0);
891
+ * const averageAge = totalAge / allRows.length;
892
+ */
771
893
  getAllRows() {
772
894
  return this.rows;
773
895
  }
774
896
  /**
775
897
  * Returns the first row from the filtered rows that matches the given criteria based on the provided predicate function.
898
+ * This method only searches within the filtered rows, not the original rows array.
776
899
  *
777
900
  * @param {Partial<T>} criteria - A partial object containing the search criteria
778
901
  * @param {(criteria: Partial<T>, row: T) => boolean} predicate - A function that takes the search criteria and a row,
779
902
  * and returns true if the row matches the criteria
780
903
  * @returns {T | undefined} The first matching row, or undefined if no match is found
904
+ *
905
+ * @example
906
+ * // Find a user by name in the filtered rows
907
+ * const criteria = { name: 'John' };
908
+ * const user = bodyAreaModel.findRowFromFilteredRowsByAllCriteria(
909
+ * criteria,
910
+ * (criteria, row) => row.name === criteria.name
911
+ * );
912
+ *
913
+ * @example
914
+ * // Find a user by age range in the filtered rows
915
+ * const criteria = { minAge: 25, maxAge: 35 };
916
+ * const user = bodyAreaModel.findRowFromFilteredRowsByAllCriteria(
917
+ * criteria,
918
+ * (criteria, row) => row.age >= criteria.minAge && row.age <= criteria.maxAge
919
+ * );
781
920
  */
782
921
  findRowFromFilteredRowsByAllCriteria(e, t) {
783
922
  return this.getFilteredRows().find((s) => t(e, s));
784
923
  }
785
924
  /**
786
925
  * Searches through all rows to find a row that matches the given criteria based on the predicate function.
926
+ * This method searches within the original rows array, including rows that may have been filtered out.
787
927
  *
788
928
  * @param {Partial<T>} criteria - A partial object containing the search criteria
789
929
  * @param {(criteria: Partial<T>, row: T) => boolean} predicate - A function that takes the search criteria and a row,
790
930
  * and returns true if the row matches the criteria
791
931
  * @returns {T | undefined} The first matching row from all rows, or undefined if no match is found
932
+ *
933
+ * @example
934
+ * // Find a user by ID in all rows
935
+ * const criteria = { id: 42 };
936
+ * const user = bodyAreaModel.findRowFromAllRowsByAllCriteria(
937
+ * criteria,
938
+ * (criteria, row) => row.id === criteria.id
939
+ * );
940
+ *
941
+ * @example
942
+ * // Find a user with a specific property value in all rows
943
+ * const criteria = { department: 'Engineering', role: 'Manager' };
944
+ * const user = bodyAreaModel.findRowFromAllRowsByAllCriteria(
945
+ * criteria,
946
+ * (criteria, row) => row.department === criteria.department && row.role === criteria.role
947
+ * );
792
948
  */
793
949
  findRowFromAllRowsByAllCriteria(e, t) {
794
950
  return this.getAllRows().find((s) => t(e, s));
795
951
  }
952
+ /**
953
+ * Returns the height of the row at the specified index.
954
+ * This implementation always returns the default row height.
955
+ * Override this method in subclasses to support variable row heights.
956
+ *
957
+ * @param {number} _rowIndex - The index of the row (unused in this implementation)
958
+ * @returns {number} The height of the row in pixels
959
+ *
960
+ * @example
961
+ * const rowHeight = bodyAreaModel.getRowHeight(0);
962
+ * console.log(`The first row has a height of ${rowHeight}px`);
963
+ */
796
964
  getRowHeight(e) {
797
965
  return this.defaultRowHeight;
798
966
  }
967
+ /**
968
+ * Returns the row object at the specified index from the filtered rows array.
969
+ * This method overrides the parent class implementation.
970
+ *
971
+ * @param {number} rowIndex - The index of the row to retrieve
972
+ * @returns {any} The row object at the specified index, or undefined if the index is out of bounds
973
+ *
974
+ * @example
975
+ * // Get the first row object
976
+ * const row = bodyAreaModel.getRowByIndex(0);
977
+ * console.log('First row:', row);
978
+ *
979
+ * @example
980
+ * // Iterate through all rows
981
+ * for (let i = 0; i < bodyAreaModel.getRowCount(); i++) {
982
+ * const row = bodyAreaModel.getRowByIndex(i);
983
+ * console.log(`Row ${i}:`, row);
984
+ * }
985
+ */
799
986
  getRowByIndex(e) {
800
987
  return this.filteredRows[e];
801
988
  }
989
+ /**
990
+ * Applies an external filter function to the rows array.
991
+ * This method updates the filtered rows array without modifying the original rows array.
992
+ *
993
+ * @param {FilterFunction<any>} predictFn - A function that returns true for rows to keep and false for rows to filter out
994
+ *
995
+ * @example
996
+ * // Filter rows where age is greater than 30
997
+ * bodyAreaModel.externalFilterChanged(row => row.age > 30);
998
+ *
999
+ * @example
1000
+ * // Filter rows based on a search term
1001
+ * const searchTerm = 'john';
1002
+ * bodyAreaModel.externalFilterChanged(row =>
1003
+ * row.name.toLowerCase().includes(searchTerm.toLowerCase())
1004
+ * );
1005
+ *
1006
+ * @example
1007
+ * // Clear all filters
1008
+ * bodyAreaModel.externalFilterChanged(() => true);
1009
+ */
802
1010
  externalFilterChanged(e) {
803
1011
  this.filteredRows = this.rows ? this.rows.filter(e) : [];
804
1012
  }
1013
+ /**
1014
+ * Sorts the filtered rows based on the provided sort items.
1015
+ * This method supports sorting by multiple columns with different sort directions.
1016
+ *
1017
+ * @param {SortItem[]} sortItems - An array of sort items, each containing a column index and sort state
1018
+ * @returns {boolean} Always returns true to indicate sorting was performed
1019
+ *
1020
+ * @example
1021
+ * // Sort by age in ascending order
1022
+ * bodyAreaModel.doSort([{ columnIndex: 2, sortState: 'asc' }]);
1023
+ *
1024
+ * @example
1025
+ * // Sort by name in descending order, then by age in ascending order
1026
+ * bodyAreaModel.doSort([
1027
+ * { columnIndex: 1, sortState: 'desc' },
1028
+ * { columnIndex: 2, sortState: 'asc' }
1029
+ * ]);
1030
+ *
1031
+ * @example
1032
+ * // Clear sorting
1033
+ * bodyAreaModel.doSort([{ columnIndex: 0, sortState: 'none' }]);
1034
+ */
805
1035
  doSort(e) {
806
1036
  for (const t of e) {
807
1037
  const { columnIndex: s, sortState: o } = t, i = o === "asc" ? 1 : o === "desc" ? -1 : 0, r = this.properties[s];
@@ -809,20 +1039,110 @@ class F extends je {
809
1039
  }
810
1040
  return !0;
811
1041
  }
1042
+ /**
1043
+ * Sorts the filtered rows using a custom comparator function.
1044
+ * This method provides more flexibility than `doSort()` for complex sorting logic.
1045
+ *
1046
+ * @param {(a: T, b: T) => number} compareFn - A function that compares two rows and returns a number:
1047
+ * - Negative if a should come before b
1048
+ * - Positive if a should come after b
1049
+ * - Zero if they are equivalent for sorting purposes
1050
+ *
1051
+ * @example
1052
+ * // Sort by name length
1053
+ * bodyAreaModel.sort((a, b) => a.name.length - b.name.length);
1054
+ *
1055
+ * @example
1056
+ * // Sort by a computed value
1057
+ * bodyAreaModel.sort((a, b) => {
1058
+ * const scoreA = a.wins * 3 + a.draws;
1059
+ * const scoreB = b.wins * 3 + b.draws;
1060
+ * return scoreB - scoreA; // Descending order
1061
+ * });
1062
+ */
812
1063
  sort(e) {
813
1064
  this.filteredRows = this.filteredRows.sort(e);
814
1065
  }
1066
+ /**
1067
+ * Gets a value from an object using a property path.
1068
+ * This method supports accessing nested properties using dot notation (e.g., 'person.name').
1069
+ *
1070
+ * @param {T} t - The object to get the value from
1071
+ * @param {string} property - The property path to access (e.g., 'name' or 'person.contact.email')
1072
+ * @returns {any} The value at the specified property path, or undefined if not found
1073
+ *
1074
+ * @example
1075
+ * const user = { id: 1, name: 'John', contact: { email: 'john@example.com' } };
1076
+ *
1077
+ * // Access simple property
1078
+ * const name = bodyAreaModel.getValueByT(user, 'name');
1079
+ * console.log(name); // 'John'
1080
+ *
1081
+ * // Access nested property
1082
+ * const email = bodyAreaModel.getValueByT(user, 'contact.email');
1083
+ * console.log(email); // 'john@example.com'
1084
+ */
815
1085
  getValueByT(e, t) {
816
1086
  if (e && t)
817
1087
  return t.includes(".") ? this.getPropertyValue(e, t.split(".")) : e[t];
818
1088
  }
1089
+ /**
1090
+ * Changes the order of columns by moving a column from one position to another.
1091
+ * This method updates both the properties array and calls the parent class implementation.
1092
+ *
1093
+ * @param {number} sourceColumnIndex - The index of the column to move
1094
+ * @param {number} targetColumnIndex - The index where the column should be moved to
1095
+ *
1096
+ * @example
1097
+ * // Move the second column (index 1) to the fourth position (index 3)
1098
+ * bodyAreaModel.changeColumnOrder(1, 3);
1099
+ *
1100
+ * @example
1101
+ * // Move the last column to the first position
1102
+ * const lastIndex = bodyAreaModel.columnDefs.length - 1;
1103
+ * bodyAreaModel.changeColumnOrder(lastIndex, 0);
1104
+ */
819
1105
  changeColumnOrder(e, t) {
820
1106
  this.arrayMove(this.properties, e, t), super.changeColumnOrder(e, t);
821
1107
  }
1108
+ /**
1109
+ * Gets the custom CSS classes that should be applied to a cell.
1110
+ * This method extends the parent class implementation to add selection and focus classes.
1111
+ *
1112
+ * @param {number} rowIndex - The index of the row
1113
+ * @param {number} _columnIndex - The index of the column (unused in this implementation)
1114
+ * @returns {string[]} An array of CSS class names to apply to the cell
1115
+ *
1116
+ * @example
1117
+ * // Get the CSS classes for a cell
1118
+ * const classes = bodyAreaModel.getCustomClassesAt(1, 2);
1119
+ * console.log('CSS classes:', classes);
1120
+ *
1121
+ * @example
1122
+ * // Apply the classes to a cell element
1123
+ * const cellElement = document.createElement('div');
1124
+ * const classes = bodyAreaModel.getCustomClassesAt(rowIndex, columnIndex);
1125
+ * cellElement.classList.add(...classes);
1126
+ */
822
1127
  getCustomClassesAt(e, t) {
823
1128
  const s = super.getCustomClassesAt(e, t);
824
1129
  return this.getRowByIndex(e).selected && s.push(this.selectedRowClass), this._focusedRowIndex === e && s.push(this.focusedRowClass), s;
825
1130
  }
1131
+ /**
1132
+ * Creates a comparator function for sorting rows based on a property and sort direction.
1133
+ * This method supports custom sort comparators defined in column definitions.
1134
+ *
1135
+ * @param {string} property - The property to sort by
1136
+ * @param {number} f - The sort direction factor: 1 for ascending, -1 for descending, 0 for no sorting
1137
+ * @returns {(a: T, b: T) => number} A comparator function that compares two rows
1138
+ *
1139
+ * @example
1140
+ * // Create a comparator for sorting by name in ascending order
1141
+ * const comparator = bodyAreaModel.genericFlatTableSortComparator('name', 1);
1142
+ *
1143
+ * // Sort the rows using the comparator
1144
+ * const sortedRows = [...bodyAreaModel.getFilteredRows()].sort(comparator);
1145
+ */
826
1146
  genericFlatTableSortComparator(e, t) {
827
1147
  const s = this.columnDefs.find((o) => o.property === e);
828
1148
  return (o, i) => {
@@ -830,6 +1150,16 @@ class F extends je {
830
1150
  return s != null && s.sortComparator ? t * s.sortComparator(r, a, o, i, t) : this.sorterService.genericSortComparator(r, a, t);
831
1151
  };
832
1152
  }
1153
+ /**
1154
+ * Recursively gets a value from an object using an array of property names.
1155
+ * This is a helper method used by `getValueByT` to access nested properties.
1156
+ *
1157
+ * @param {any} o - The object to get the value from
1158
+ * @param {string[]} props - An array of property names representing the path to the value
1159
+ * @returns {any} The value at the specified property path, or undefined if not found
1160
+ *
1161
+ * @private
1162
+ */
833
1163
  getPropertyValue(e, t) {
834
1164
  const s = t.shift(), o = e[s];
835
1165
  return o && t.length ? this.getPropertyValue(o, t) : o;
@@ -840,41 +1170,302 @@ class Ke {
840
1170
  this.tableScope = e;
841
1171
  }
842
1172
  /**
843
- * Updates the cells in the table based on the provided events.
1173
+ * Updates the cells in the table with the provided cell update events.
844
1174
  *
845
- * @param {TableCellUpdateEventIf[]} events - The array of events representing the updates to perform on the cells.
846
- * @param {boolean} [repaintAll=false] - Optional parameter indicating whether to repaint all cells or not. Default value is false. If true, the full table will be rendered. If false, the table cell will be rendered immediately.
1175
+ * This method allows you to update specific cells in the table without requiring a full table repaint,
1176
+ * which can significantly improve performance when updating large tables frequently.
847
1177
  *
848
- * @return {void} - This method doesn't return anything.
1178
+ * @param {TableCellUpdateEventIf[]} events - An array of cell update events, each defining a single cell update operation.
1179
+ * Each event must specify:
1180
+ * - area: The table area to update ('header', 'body', or 'footer')
1181
+ * - rowIndex: The row index of the cell to update
1182
+ * - columnIndex: The column index of the cell to update
1183
+ * - value: The new value to set for the cell
1184
+ * - cssClasses: Optional object mapping CSS class names to boolean values
1185
+ * (true to add the class, false to remove it)
1186
+ *
1187
+ * @param {boolean} [repaintAll=false] - Whether to repaint the entire table after updating cells.
1188
+ * - If true: All cells will be repainted after updating (slower but ensures visual consistency)
1189
+ * - If false: Only the modified cells will be repainted (faster, recommended for frequent updates)
1190
+ *
1191
+ * @returns {void}
1192
+ *
1193
+ * @example
1194
+ * // Update a single cell with a new value and CSS classes
1195
+ * tableApi.updateCells([{
1196
+ * area: 'body',
1197
+ * rowIndex: 3,
1198
+ * columnIndex: 2,
1199
+ * value: 42,
1200
+ * cssClasses: {
1201
+ * 'highlight': true, // Add 'highlight' class
1202
+ * 'error': false // Remove 'error' class if present
1203
+ * }
1204
+ * }]);
1205
+ *
1206
+ * @example
1207
+ * // Update multiple cells at once
1208
+ * tableApi.updateCells([
1209
+ * {
1210
+ * area: 'body',
1211
+ * rowIndex: 1,
1212
+ * columnIndex: 1,
1213
+ * value: 'New Value 1',
1214
+ * cssClasses: { 'updated': true }
1215
+ * },
1216
+ * {
1217
+ * area: 'body',
1218
+ * rowIndex: 2,
1219
+ * columnIndex: 3,
1220
+ * value: 'New Value 2',
1221
+ * cssClasses: { 'updated': true }
1222
+ * }
1223
+ * ]);
1224
+ *
1225
+ * @example
1226
+ * // Update cells and repaint the entire table
1227
+ * tableApi.updateCells([
1228
+ * { area: 'body', rowIndex: 0, columnIndex: 0, value: 'Hello', cssClasses: { 'bg-green-0': true } },
1229
+ * { area: 'body', rowIndex: 1, columnIndex: 1, value: 'World', cssClasses: { 'bg-red-0': true } }
1230
+ * ], true);
1231
+ *
1232
+ * @example
1233
+ * // High-performance animation example (update without full repaint)
1234
+ * function animateCell() {
1235
+ * const value = Math.sin(Date.now() / 1000) * 50;
1236
+ * const cssClasses = {
1237
+ * 'positive': value > 0,
1238
+ * 'negative': value < 0
1239
+ * };
1240
+ *
1241
+ * tableApi.updateCells([{
1242
+ * area: 'body',
1243
+ * rowIndex: 0,
1244
+ * columnIndex: 0,
1245
+ * value: Math.round(value),
1246
+ * cssClasses
1247
+ * }]);
1248
+ *
1249
+ * requestAnimationFrame(animateCell);
1250
+ * }
1251
+ * animateCell();
849
1252
  */
850
1253
  updateCells(e, t = !1) {
851
1254
  this.tableScope.updateCells(e, t);
852
1255
  }
853
1256
  /**
854
- * Notifies that the external filter has changed.
1257
+ * Notifies the table that an external filter has been changed and needs to be applied.
855
1258
  *
856
- * @return {void}
1259
+ * This method is used when an external filter condition (defined by `tableOptions.externalFilterFunction`)
1260
+ * has changed and the table needs to refresh its display to reflect the new filtering criteria.
1261
+ *
1262
+ * When called, this method:
1263
+ * 1. Applies the external filter function to all rows
1264
+ * 2. Clears the current selection (by default)
1265
+ * 3. Scrolls to the top of the table
1266
+ * 4. Recalculates table dimensions
1267
+ * 5. Repaints the table to display only the filtered rows
1268
+ *
1269
+ * @example
1270
+ * ```typescript
1271
+ * // Define an external filter function in your table options
1272
+ * const tableOptions = {
1273
+ * externalFilterFunction: (row: MyRowType) => {
1274
+ * // Return true to include the row, false to filter it out
1275
+ * return row.status === 'active';
1276
+ * }
1277
+ * };
1278
+ *
1279
+ * // Initialize your table with these options
1280
+ * const tableApi = new TableApi(tableScope);
1281
+ *
1282
+ * // Later, when filter criteria change (e.g., in a search input handler)
1283
+ * function onFilterTextChanged() {
1284
+ * // Update the filter function if needed
1285
+ * tableOptions.externalFilterFunction = (row: MyRowType) => {
1286
+ * return row.name.includes(searchText);
1287
+ * };
1288
+ *
1289
+ * // Apply the updated filter
1290
+ * tableApi.externalFilterChanged();
1291
+ * }
1292
+ * ```
1293
+ *
1294
+ * @returns {void}
1295
+ * @see TableScope.externalFilterChanged
857
1296
  */
858
1297
  externalFilterChanged() {
859
1298
  this.tableScope.externalFilterChanged();
860
1299
  }
861
1300
  /**
862
- * Scrolls the table body to the specified pixel coordinates.
1301
+ * Scrolls the table content to the specified pixel coordinates.
863
1302
  *
864
- * @param {number} px - The horizontal pixel coordinate to scroll to. Defaults to 0.
865
- * @param {number} py - The vertical pixel coordinate to scroll to. Defaults to 0.
866
- * @return {void}
1303
+ * This method allows programmatic scrolling of the table viewport to exact pixel positions.
1304
+ * It delegates the scrolling operation to the underlying TableScope instance.
1305
+ *
1306
+ * @param {number} px - The horizontal pixel coordinate to scroll to. Defaults to 0 (leftmost position).
1307
+ * @param {number} py - The vertical pixel coordinate to scroll to. Defaults to 0 (topmost position).
1308
+ * @returns {void}
1309
+ *
1310
+ * @example
1311
+ * // Scroll to the top-left corner of the table
1312
+ * tableApi.scrollToPixel(0, 0);
1313
+ *
1314
+ * @example
1315
+ * // Scroll 200 pixels horizontally and 150 pixels vertically
1316
+ * tableApi.scrollToPixel(200, 150);
1317
+ *
1318
+ * @example
1319
+ * // Scroll only vertically, keeping the current horizontal position
1320
+ * tableApi.scrollToPixel(undefined, 300);
1321
+ *
1322
+ * @example
1323
+ * // Example in a component that needs precise scrolling control
1324
+ * class TableScroller {
1325
+ * private tableApi: TableApi;
1326
+ *
1327
+ * constructor(tableApi: TableApi) {
1328
+ * this.tableApi = tableApi;
1329
+ * }
1330
+ *
1331
+ * scrollToPosition(x: number, y: number) {
1332
+ * // Scroll to exact pixel coordinates
1333
+ * this.tableApi.scrollToPixel(x, y);
1334
+ * }
1335
+ *
1336
+ * scrollHalfway() {
1337
+ * const tableModel = this.tableApi.getTableModel();
1338
+ * const totalWidth = tableModel.getContentWidthInPixel();
1339
+ * const totalHeight = tableModel.getContentHeightInPixel();
1340
+ *
1341
+ * // Scroll to the middle of the table content
1342
+ * this.tableApi.scrollToPixel(totalWidth / 2, totalHeight / 2);
1343
+ * }
1344
+ * }
1345
+ *
1346
+ * @example
1347
+ * // Advanced usage with animated scrolling
1348
+ * class SmoothScroller {
1349
+ * private tableApi: TableApi;
1350
+ * private animationFrameId: number | null = null;
1351
+ *
1352
+ * constructor(tableApi: TableApi) {
1353
+ * this.tableApi = tableApi;
1354
+ * }
1355
+ *
1356
+ * smoothScrollTo(targetX: number, targetY: number, duration: number = 500) {
1357
+ * // Cancel any ongoing animation
1358
+ * if (this.animationFrameId !== null) {
1359
+ * cancelAnimationFrame(this.animationFrameId);
1360
+ * }
1361
+ *
1362
+ * const startTime = performance.now();
1363
+ * const startX = this.tableApi.getTableScope().getScrollLeft();
1364
+ * const startY = this.tableApi.getTableScope().getScrollTop();
1365
+ * const distanceX = targetX - startX;
1366
+ * const distanceY = targetY - startY;
1367
+ *
1368
+ * const step = (currentTime: number) => {
1369
+ * const elapsed = currentTime - startTime;
1370
+ * const progress = Math.min(elapsed / duration, 1);
1371
+ *
1372
+ * // Use easing function for smooth animation
1373
+ * const easeProgress = 1 - Math.pow(1 - progress, 3); // Cubic ease-out
1374
+ *
1375
+ * const currentX = startX + distanceX * easeProgress;
1376
+ * const currentY = startY + distanceY * easeProgress;
1377
+ *
1378
+ * this.tableApi.scrollToPixel(currentX, currentY);
1379
+ *
1380
+ * if (progress < 1) {
1381
+ * this.animationFrameId = requestAnimationFrame(step);
1382
+ * } else {
1383
+ * this.animationFrameId = null;
1384
+ * }
1385
+ * };
1386
+ *
1387
+ * this.animationFrameId = requestAnimationFrame(step);
1388
+ * }
1389
+ *
1390
+ * cancelAnimation() {
1391
+ * if (this.animationFrameId !== null) {
1392
+ * cancelAnimationFrame(this.animationFrameId);
1393
+ * this.animationFrameId = null;
1394
+ * }
1395
+ * }
1396
+ * }
1397
+ *
1398
+ * @see {@link scrollToIndex} - For scrolling based on row and column indices
1399
+ * @see {@link ensureRowIsVisible} - For scrolling to make a specific row visible
867
1400
  */
868
1401
  scrollToPixel(e = 0, t = 0) {
869
1402
  this.tableScope.scrollToPixel(e, t);
870
1403
  }
871
1404
  /**
872
- * Scrolls to the specified index in both horizontal and vertical directions.
1405
+ * Scrolls the table to display the specified row and column indices at the top-left corner of the viewport.
873
1406
  *
874
- * @param {number} indexX - The index of the column to scroll to in the horizontal direction. Default is 0.
875
- * @param {number} indexY - The index of the row to scroll to in the vertical direction. Default is 0.
1407
+ * This method allows programmatic scrolling to a specific position in the table grid based on row and column indices.
1408
+ * It uses the underlying TableScope's scrolling mechanism to navigate to the target location.
876
1409
  *
877
- * @return undefined
1410
+ * @param {number} indexX - The horizontal index (column) to scroll to. Defaults to 0 (leftmost column).
1411
+ * @param {number} indexY - The vertical index (row) to scroll to. Defaults to 0 (topmost row).
1412
+ * @returns {void}
1413
+ *
1414
+ * @example
1415
+ * // Scroll to the 5th row, keeping the current horizontal scroll position
1416
+ * tableApi.scrollToIndex(0, 5);
1417
+ *
1418
+ * @example
1419
+ * // Scroll to column 3, row 10
1420
+ * tableApi.scrollToIndex(3, 10);
1421
+ *
1422
+ * @example
1423
+ * // Example in a component that needs to navigate to specific content
1424
+ * class TableNavigator {
1425
+ * private tableApi: TableApi;
1426
+ *
1427
+ * constructor(tableApi: TableApi) {
1428
+ * this.tableApi = tableApi;
1429
+ * }
1430
+ *
1431
+ * goToCell(columnIndex: number, rowIndex: number) {
1432
+ * // Navigate directly to the specified cell position
1433
+ * this.tableApi.scrollToIndex(columnIndex, rowIndex);
1434
+ *
1435
+ * // Optional: Select the cell after navigating to it
1436
+ * const selectionModel = this.tableApi.getSelectionModel();
1437
+ * if (selectionModel) {
1438
+ * selectionModel.selectCell(rowIndex, columnIndex);
1439
+ * }
1440
+ * }
1441
+ * }
1442
+ *
1443
+ * @example
1444
+ * // Advanced usage with search functionality
1445
+ * class TableSearcher {
1446
+ * findAndScrollToMatch(searchTerm: string) {
1447
+ * const tableModel = this.tableApi.getTableModel();
1448
+ * const bodyModel = tableModel.getAreaModel('body');
1449
+ *
1450
+ * // Search for the term in the table data
1451
+ * for (let row = 0; row < bodyModel.getRowCount(); row++) {
1452
+ * for (let col = 0; col < tableModel.getColumnCount(); col++) {
1453
+ * const cellContent = bodyModel.getValueAt(row, col)?.toString() || '';
1454
+ *
1455
+ * if (cellContent.includes(searchTerm)) {
1456
+ * // Found a match, scroll to it
1457
+ * this.tableApi.scrollToIndex(col, row);
1458
+ * return true;
1459
+ * }
1460
+ * }
1461
+ * }
1462
+ *
1463
+ * return false; // No match found
1464
+ * }
1465
+ * }
1466
+ *
1467
+ * @see {@link scrollToPixel} - For scrolling to specific pixel coordinates
1468
+ * @see {@link ensureRowIsVisible} - For scrolling to make a specific row visible
878
1469
  */
879
1470
  scrollToIndex(e = 0, t = 0) {
880
1471
  this.tableScope.scrollToIndex(e, t);
@@ -935,19 +1526,71 @@ class Ke {
935
1526
  /**
936
1527
  * Repaints the table.
937
1528
  *
938
- * This method calls the repaint method of the tableScope object
939
- * to update and redraw the table based on the latest data.
1529
+ * This method refreshes the visual representation of the table by delegating to the
1530
+ * tableScope's repaint functionality. Use this method whenever the table's visual state
1531
+ * needs to be updated after data changes, selection changes, or any modifications that
1532
+ * affect the rendered output.
1533
+ *
1534
+ * Repainting the table ensures that all visible cells, rows, and styling reflect the
1535
+ * current state of the underlying data model and configuration settings.
1536
+ *
1537
+ * @example
1538
+ * // Update data and repaint the table
1539
+ * const tableApi = new TableApi(tableScope);
1540
+ * tableApi.setRows(newData);
1541
+ * tableApi.repaint();
1542
+ *
1543
+ * @example
1544
+ * // Update selection and repaint to show the visual change
1545
+ * tableApi.getSelectionModel().selectCell(2, 3);
1546
+ * tableApi.repaint();
1547
+ *
1548
+ * @example
1549
+ * // After changing column visibility, repaint to reflect changes
1550
+ * tableApi.setColumnVisible(0, false);
1551
+ * tableApi.repaint();
1552
+ *
1553
+ * @returns {void}
940
1554
  */
941
1555
  repaint() {
942
1556
  this.tableScope.repaint();
943
1557
  }
944
1558
  /**
945
- * Repaints the table scope with hard repaint.
946
- * Repaints the UI by resetting the size of the wrapper div,
947
- * adjusting the containers and rows, and performing additional adjustments
948
- * after scrolling.
1559
+ * Performs a complete repaint of the table by triggering a hard repaint on the underlying table scope.
949
1560
  *
950
- * @return {void}
1561
+ * A hard repaint is more thorough than a regular repaint and performs the following operations:
1562
+ * - Recalculates the height and padding of the table model
1563
+ * - Resets the size of the wrapper div elements
1564
+ * - Adjusts containers and rows positioning
1565
+ * - Makes additional adjustments after scrolling
1566
+ *
1567
+ * Use this method when regular repaint isn't sufficient, such as when:
1568
+ * - Table dimensions have significantly changed
1569
+ * - The structure of data has been modified (rows/columns added or removed)
1570
+ * - The table layout needs complete recalculation
1571
+ * - After major DOM changes affecting the table's container
1572
+ *
1573
+ * @example
1574
+ * // Example 1: Basic usage
1575
+ * tableApi.repaintHard();
1576
+ *
1577
+ * @example
1578
+ * // Example 2: Using after major data changes
1579
+ * tableApi.setRows(newDataSet);
1580
+ * tableApi.repaintHard();
1581
+ *
1582
+ * @example
1583
+ * // Example 3: Using after resizing a container
1584
+ * window.addEventListener('resize', () => {
1585
+ * tableApi.repaintHard();
1586
+ * });
1587
+ *
1588
+ * @example
1589
+ * // Example 4: Using after changing column visibility
1590
+ * tableApi.setColumnVisible(2, false);
1591
+ * tableApi.repaintHard();
1592
+ *
1593
+ * @returns {void} This method doesn't return a value
951
1594
  */
952
1595
  repaintHard() {
953
1596
  this.tableScope.repaintHard();
@@ -963,8 +1606,30 @@ class Ke {
963
1606
  this.tableScope.recalcColumnWidths(e);
964
1607
  }
965
1608
  /**
966
- * Clears the current selection of the table.
967
- * The table will be rendered automatically.
1609
+ * Clears the current selection in the table.
1610
+ *
1611
+ * This method removes any selected cells, rows, or columns in the table.
1612
+ * It provides a convenient way to programmatically clear all selections in the table
1613
+ * without having to access the underlying selection model directly.
1614
+ *
1615
+ * When called, this method delegates to the table scope's clearSelection method with
1616
+ * a parameter value of true, which ensures the table is automatically repainted after
1617
+ * the selection is cleared.
1618
+ *
1619
+ * @example
1620
+ * // Clear all selections in the table
1621
+ * tableApi.clearSelection();
1622
+ *
1623
+ * // Example usage in a component
1624
+ * class MyComponent {
1625
+ * @ViewChild('tableComponent') tableComponent: TableComponent;
1626
+ *
1627
+ * resetTableSelection(): void {
1628
+ * if (this.tableComponent?.api) {
1629
+ * this.tableComponent.api.clearSelection();
1630
+ * }
1631
+ * }
1632
+ * }
968
1633
  *
969
1634
  * @returns {void}
970
1635
  */
@@ -972,12 +1637,31 @@ class Ke {
972
1637
  this.tableScope.clearSelection(!0);
973
1638
  }
974
1639
  /**
975
- * Sets the selection model for the table scope.
1640
+ * Sets the selection model for the table.
976
1641
  *
977
- * @param {SelectionModel} sm - The selection model to be set.
978
- * @param {boolean} [repaint=true] - Indicates whether the table should be repainted after setting the selection model. Default value is true.
1642
+ * This method allows you to replace the current selection model with a new one,
1643
+ * which controls how cells, rows, or columns can be selected in the table.
979
1644
  *
980
- * @return {void}
1645
+ * @param {SelectionModel} sm - The new selection model to be set. This model defines
1646
+ * the selection behavior including selection type (none, cell, row, column),
1647
+ * selection mode (single, multi), and manages the selected ranges.
1648
+ * @param {boolean} [repaint=true] - Whether to repaint the table after changing the selection model.
1649
+ * Default is true, which immediately reflects the change visually.
1650
+ * Set to false if you want to avoid immediate repainting.
1651
+ *
1652
+ * @example
1653
+ * // Create a new selection model with row selection and multi-select mode
1654
+ * const selectionModel = new SelectionModel("row", "multi");
1655
+ *
1656
+ * // Set the new selection model and repaint the table
1657
+ * tableApi.setSelectionModel(selectionModel);
1658
+ *
1659
+ * // Set a selection model without repainting (if you plan to make more changes)
1660
+ * tableApi.setSelectionModel(selectionModel, false);
1661
+ * // ... make other changes ...
1662
+ * tableApi.repaint(); // Now repaint once
1663
+ *
1664
+ * @returns {void}
981
1665
  */
982
1666
  setSelectionModel(e, t = !0) {
983
1667
  this.tableScope.setSelectionModel(e, t);
@@ -993,9 +1677,36 @@ class Ke {
993
1677
  this.tableScope.onActionTriggered(e);
994
1678
  }
995
1679
  /**
996
- * Retrieves the mapping of shortcuts to corresponding action in the current table scope.
1680
+ * Retrieves the shortcut action mapping from the table's shortcut service.
1681
+ *
1682
+ * This method provides access to the keyboard shortcut configuration that defines
1683
+ * which keys trigger specific actions in the table. The mapping contains key-value
1684
+ * pairs where:
1685
+ * - Keys are string representations of keyboard shortcuts (e.g., "ctrl+c", "shift+arrow_down")
1686
+ * - Values are ActionId values representing the corresponding table actions
1687
+ *
1688
+ * This mapping can be useful for:
1689
+ * - Displaying available shortcuts to users
1690
+ * - Creating custom shortcut documentation
1691
+ * - Dynamically checking which actions are available via keyboard
1692
+ * - Extending or integrating with the table's shortcut system
1693
+ *
1694
+ * @returns {ShortcutActionIdMapping} An object mapping shortcut key combinations to their corresponding action IDs.
1695
+ * For example: { "ctrl+c": "COPY_2_CLIPBOARD", "arrow_down": "NAVIGATE_DOWN" }
1696
+ *
1697
+ * @example
1698
+ * // Get all available shortcuts in the table
1699
+ * const shortcuts = tableApi.getShortcutActionMapping();
1700
+ *
1701
+ * // Check if a specific shortcut exists
1702
+ * if (shortcuts["ctrl+c"]) {
1703
+ * console.log("Copy shortcut is available with action:", shortcuts["ctrl+c"]);
1704
+ * }
997
1705
  *
998
- * @return {ShortcutActionIdMapping} The mapping of shortcuts to corresponding action.
1706
+ * // Display available shortcuts in the UI
1707
+ * Object.entries(shortcuts).forEach(([key, actionId]) => {
1708
+ * console.log(`${key}: ${actionId}`);
1709
+ * });
999
1710
  */
1000
1711
  getShortcutActionMapping() {
1001
1712
  return this.tableScope.shortcutService.getShortcutActionMapping();
@@ -1003,7 +1714,35 @@ class Ke {
1003
1714
  /**
1004
1715
  * Copies the selected data from the table to the clipboard.
1005
1716
  *
1006
- * @return {Promise<string>} - A promise that resolves with the copied data as a string.
1717
+ * This method leverages the copyService to extract and copy the currently selected data
1718
+ * from the table. It works with the current selection state and focus position to determine
1719
+ * what content should be copied.
1720
+ *
1721
+ * The copied data is formatted as tab-separated text that can be pasted into spreadsheet
1722
+ * applications like Excel or text editors while maintaining the tabular structure.
1723
+ *
1724
+ * @example
1725
+ * // Copy the currently selected data to clipboard
1726
+ * tableApi.copyToClipboard().then(content => {
1727
+ * console.log('Copied to clipboard:', content);
1728
+ * });
1729
+ *
1730
+ * // Using with a button click handler
1731
+ * function onCopyButtonClick() {
1732
+ * if (tableApi) {
1733
+ * tableApi.copyToClipboard()
1734
+ * .then(content => {
1735
+ * console.log('Successfully copied data to clipboard');
1736
+ * // Optionally do something with the copied content
1737
+ * })
1738
+ * .catch(error => {
1739
+ * console.error('Failed to copy to clipboard:', error);
1740
+ * });
1741
+ * }
1742
+ * }
1743
+ *
1744
+ * @returns {Promise<string>} A promise that resolves with the copied data as a string.
1745
+ * The string contains the tab-separated representation of the selected table data.
1007
1746
  */
1008
1747
  copyToClipboard() {
1009
1748
  return this.tableScope.copyService.copyToClipboard(
@@ -1013,11 +1752,33 @@ class Ke {
1013
1752
  );
1014
1753
  }
1015
1754
  /**
1016
- * Generates and downloads an Excel file based on the table data.
1755
+ * Downloads the current table data as an Excel file.
1756
+ *
1757
+ * This method extracts all visible data from the table (including header, body, and footer areas),
1758
+ * converts it into a matrix format, and triggers a download of an Excel file containing this data.
1759
+ *
1760
+ * The method works by:
1761
+ * 1. Creating an empty matrix to hold all table data
1762
+ * 2. Iterating through each area of the table (header, body, footer)
1763
+ * 3. For each area, iterating through all rows and columns to extract cell values
1764
+ * 4. Passing the complete data matrix to the Excel service for file generation and download
1765
+ *
1766
+ * @param {string} fileName - The name of the Excel file to be downloaded (default: 'table.xlsx')
1767
+ * @param {string} author - Optional metadata for the Excel file to specify the author (default: '')
1017
1768
  *
1018
- * @param {string} fileName - The name of the Excel file to be downloaded. Defaults to 'table.xlsx'.
1019
- * @param {string} author - The author of the Excel file. If not provided, it will remain empty.
1020
- * @return {void} No return value. Initiates a file download of the Excel document.
1769
+ * @returns {void} The result of the excelService.downloadExcel method call
1770
+ *
1771
+ * @example
1772
+ * // Download table data with default filename
1773
+ * tableApi.downloadExcel();
1774
+ *
1775
+ * @example
1776
+ * // Download table data with custom filename and author
1777
+ * tableApi.downloadExcel('sales-report.xlsx', 'John Doe');
1778
+ *
1779
+ * @example
1780
+ * // Download table data with custom filename only
1781
+ * tableApi.downloadExcel('quarterly-data.xlsx');
1021
1782
  */
1022
1783
  downloadExcel(e = "table.xlsx", t = "") {
1023
1784
  const s = [], o = this.tableScope.tableModel.getColumnCount(), i = ["header", "body", "footer"];
@@ -1033,18 +1794,66 @@ class Ke {
1033
1794
  return this.tableScope.excelService.downloadExcel(s, e, t);
1034
1795
  }
1035
1796
  /**
1036
- * Retrieves the current scope of the table.
1797
+ * Returns the TableScope instance associated with this TableApi.
1798
+ *
1799
+ * The TableScope provides access to the core functionality and internal state of the table component,
1800
+ * including rendering, event handling, selection, and other low-level operations.
1801
+ *
1802
+ * This method is useful for advanced customization scenarios where you need direct access
1803
+ * to the table's internal structure and behaviors.
1804
+ *
1805
+ * @returns {TableScope} The TableScope instance that controls this table component
1806
+ *
1807
+ * @example
1808
+ * // Access the TableScope to perform a custom operation
1809
+ * const tableApi = new TableApi(myTableScope);
1810
+ * const tableScope = tableApi.getTableScope();
1037
1811
  *
1038
- * @returns {TableScope} The current scope of the table.
1812
+ * // Example: Manually trigger a context menu at a specific location
1813
+ * const mouseEvent = new MouseEvent('contextmenu');
1814
+ * const geMouseEvent = tableScope.createGeMouseEvent(mouseEvent);
1815
+ * tableScope.contextmenu(geMouseEvent);
1039
1816
  */
1040
1817
  getTableScope() {
1041
1818
  return this.tableScope;
1042
1819
  }
1043
1820
  /**
1044
- * Retrieves the selection model of the table.
1821
+ * Returns the current selection model for the table.
1045
1822
  *
1046
- * @return {SelectionModelIf | undefined} The selection model of the table,
1047
- * or undefined if no selection model is available.
1823
+ * The selection model manages cell selection state, including single cells, ranges, rows, and columns.
1824
+ * This method provides access to the selection model instance, allowing operations like:
1825
+ * - Checking if cells are selected
1826
+ * - Getting selection ranges
1827
+ * - Modifying selections
1828
+ * - Adding/removing selection event listeners
1829
+ *
1830
+ * @returns {SelectionModelIf | undefined} The current selection model if available, otherwise undefined.
1831
+ *
1832
+ * @example
1833
+ * // Get the selection model
1834
+ * const selectionModel = tableApi.getSelectionModel();
1835
+ *
1836
+ * // Check if a specific cell is selected
1837
+ * if (selectionModel?.isSelected(3, 2)) {
1838
+ * console.log('Cell at row 3, column 2 is selected');
1839
+ * }
1840
+ *
1841
+ * // Get all selected ranges
1842
+ * const ranges = selectionModel?.getRanges();
1843
+ * console.log('Selected ranges:', ranges);
1844
+ *
1845
+ * // Clear all selections
1846
+ * selectionModel?.clear();
1847
+ *
1848
+ * // Toggle selection of a cell
1849
+ * selectionModel?.togglePoint(5, 1);
1850
+ *
1851
+ * // Add a selection change listener
1852
+ * selectionModel?.addEventSelectionChangedListener({
1853
+ * selectionChanged: () => {
1854
+ * console.log('Selection has changed');
1855
+ * }
1856
+ * });
1048
1857
  */
1049
1858
  getSelectionModel() {
1050
1859
  return this.tableScope.selectionModel();
@@ -1525,18 +2334,181 @@ class Ke {
1525
2334
  getFirstVisibleRowIndex() {
1526
2335
  return this.tableScope.getFirstVisibleRowIndex();
1527
2336
  }
2337
+ /**
2338
+ * Retrieves the index of the first fully visible row in the table's viewport.
2339
+ *
2340
+ * A row is considered "fully visible" when it's completely within the visible area of the table.
2341
+ * This differs from the regular "visible" row, which might be partially visible at the edges of the viewport.
2342
+ *
2343
+ * This method is useful for:
2344
+ * - Determining which rows are completely in view for operations that require full visibility
2345
+ * - Implementing pagination or virtualization logic that needs to know complete row visibility
2346
+ * - Supporting keyboard navigation that should skip partially visible rows
2347
+ *
2348
+ * @returns {number} The index of the first fully visible row, or -1 if no rows are fully visible
2349
+ *
2350
+ * @example
2351
+ * // Get the first fully visible row index
2352
+ * const firstFullVisibleRow = tableApi.getFirstFullVisibleRowIndex();
2353
+ *
2354
+ * // Check if a specific row is fully visible
2355
+ * const isRowFullyVisible = (rowIndex) => {
2356
+ * const firstFullVisible = tableApi.getFirstFullVisibleRowIndex();
2357
+ * const lastFullVisible = tableApi.getLastFullVisibleRowIndex();
2358
+ * return rowIndex >= firstFullVisible && rowIndex <= lastFullVisible;
2359
+ * };
2360
+ */
1528
2361
  getFirstFullVisibleRowIndex() {
1529
2362
  return this.tableScope.getFirstFullVisibleRowIndex();
1530
2363
  }
2364
+ /**
2365
+ * Returns the index of the last row that is visible in the table's viewport.
2366
+ *
2367
+ * This method retrieves the last visible row index from the table scope, which keeps
2368
+ * track of which rows are currently visible as the user scrolls through the table.
2369
+ *
2370
+ * This can be useful for:
2371
+ * - Implementing virtualized scrolling optimizations
2372
+ * - Determining if specific rows are currently in view
2373
+ * - Implementing features that need to know the visible range of rows
2374
+ *
2375
+ * @returns {number} The index of the last visible row in the table viewport
2376
+ *
2377
+ * @example
2378
+ * // Check if a specific row is currently visible in the viewport
2379
+ * const lastVisibleIndex = tableApi.getLastVisibleRowIndex();
2380
+ * const firstVisibleIndex = tableApi.getFirstVisibleRowIndex();
2381
+ * const isRowVisible = rowIndex >= firstVisibleIndex && rowIndex <= lastVisibleIndex;
2382
+ *
2383
+ * @example
2384
+ * // Get the range of visible rows
2385
+ * const visibleRowsRange = {
2386
+ * first: tableApi.getFirstVisibleRowIndex(),
2387
+ * last: tableApi.getLastVisibleRowIndex()
2388
+ * };
2389
+ * console.log(`Visible rows: ${visibleRowsRange.first} to ${visibleRowsRange.last}`);
2390
+ */
1531
2391
  getLastVisibleRowIndex() {
1532
2392
  return this.tableScope.getLastVisibleRowIndex();
1533
2393
  }
2394
+ /**
2395
+ * Returns the index of the last fully visible row in the table's viewport.
2396
+ *
2397
+ * This method retrieves the last row that is completely visible within the current
2398
+ * viewport of the table. A row is considered "fully visible" when its entire height
2399
+ * is visible without any portion being cut off by the viewport boundaries.
2400
+ *
2401
+ * The distinction between "visible" and "fully visible" is important when scrolling:
2402
+ * - A row can be partially visible (some portion is in view)
2403
+ * - A row can be fully visible (the entire row is in view)
2404
+ *
2405
+ * @returns {number} The index of the last fully visible row in the table.
2406
+ * If no row is fully visible or the table is empty, the method might return -1.
2407
+ *
2408
+ * @example
2409
+ * ```typescript
2410
+ * // Get the index of the last fully visible row
2411
+ * const lastVisibleRowIndex = tableApi.getLastFullVisibleRowIndex();
2412
+ *
2413
+ * // Use this information to determine if a specific row is fully visible
2414
+ * const isRowFullyVisible = rowIndex <= lastVisibleRowIndex && rowIndex >= tableApi.getFirstFullVisibleRowIndex();
2415
+ *
2416
+ * // Can be used with scrolling operations to ensure certain rows are visible
2417
+ * if (rowIndex > lastVisibleRowIndex) {
2418
+ * tableApi.ensureRowIsVisible(rowIndex);
2419
+ * }
2420
+ * ```
2421
+ */
1534
2422
  getLastFullVisibleRowIndex() {
1535
2423
  return this.tableScope.getLastFullVisibleRowIndex();
1536
2424
  }
2425
+ /**
2426
+ * Checks whether logging is currently active for the table component.
2427
+ *
2428
+ * This method returns the current state of logging for the table. When logging is active,
2429
+ * the table outputs detailed information about its operations to the console, including:
2430
+ *
2431
+ * - Rendering processes and lifecycle events
2432
+ * - Data modifications and updates
2433
+ * - Event handling and user interactions
2434
+ * - Performance metrics and state changes
2435
+ *
2436
+ * Logging can be toggled using the `setLoggingActive(boolean)` method.
2437
+ *
2438
+ * @returns {boolean} True if logging is currently enabled, false otherwise.
2439
+ *
2440
+ * @example
2441
+ * // Check if logging is enabled
2442
+ * if (tableApi.isLoggingActive()) {
2443
+ * console.log("Table logging is currently active");
2444
+ * }
2445
+ *
2446
+ * // Conditionally enable logging only if it's not already active
2447
+ * if (!tableApi.isLoggingActive()) {
2448
+ * tableApi.setLoggingActive(true);
2449
+ *
2450
+ * // Perform operations that need debugging
2451
+ * tableApi.updateCells([
2452
+ * {
2453
+ * area: "body",
2454
+ * rowIndex: 2,
2455
+ * columnIndex: 3,
2456
+ * value: "New Value",
2457
+ * cssClasses: { "highlight": true }
2458
+ * }
2459
+ * ]);
2460
+ *
2461
+ * // Run some additional operations...
2462
+ *
2463
+ * // Disable logging when finished
2464
+ * tableApi.setLoggingActive(false);
2465
+ * }
2466
+ */
1537
2467
  setLoggingActive(e) {
1538
2468
  this.tableScope.loggingActive = e;
1539
2469
  }
2470
+ /**
2471
+ * Checks whether logging is currently active for the table component.
2472
+ *
2473
+ * This method returns the current state of logging for the table. When logging is active,
2474
+ * the table outputs detailed information about its operations to the console, including:
2475
+ *
2476
+ * - Rendering processes and lifecycle events
2477
+ * - Data modifications and updates
2478
+ * - Event handling and user interactions
2479
+ * - Performance metrics and state changes
2480
+ *
2481
+ * Logging can be toggled using the `setLoggingActive(boolean)` method.
2482
+ *
2483
+ * @returns {boolean} True if logging is currently enabled, false otherwise.
2484
+ *
2485
+ * @example
2486
+ * // Check if logging is enabled
2487
+ * if (tableApi.isLoggingActive()) {
2488
+ * console.log("Table logging is currently active");
2489
+ * }
2490
+ *
2491
+ * // Conditionally enable logging only if it's not already active
2492
+ * if (!tableApi.isLoggingActive()) {
2493
+ * tableApi.setLoggingActive(true);
2494
+ *
2495
+ * // Perform operations that need debugging
2496
+ * tableApi.updateCells([
2497
+ * {
2498
+ * area: "body",
2499
+ * rowIndex: 2,
2500
+ * columnIndex: 3,
2501
+ * value: "New Value",
2502
+ * cssClasses: { "highlight": true }
2503
+ * }
2504
+ * ]);
2505
+ *
2506
+ * // Run some additional operations...
2507
+ *
2508
+ * // Disable logging when finished
2509
+ * tableApi.setLoggingActive(false);
2510
+ * }
2511
+ */
1540
2512
  isLoggingActive() {
1541
2513
  return this.tableScope.loggingActive;
1542
2514
  }
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@guiexpert/svelte-table",
3
- "version": "4.1.79",
3
+ "version": "4.1.80",
4
4
  "type": "module",
5
5
  "main": "./index.js",
6
6
  "types": "./index.d.ts",
@@ -8,7 +8,9 @@
8
8
  "entryFile": "src/index.ts"
9
9
  },
10
10
  "publishConfig": {
11
- "directory": "dist"
11
+ "directory": "dist",
12
+ "registry": "https://registry.npmjs.org/",
13
+ "access": "public"
12
14
  },
13
15
  "exports": {
14
16
  ".": {
@@ -19,7 +21,7 @@
19
21
  "dependencies": {
20
22
  "tslib": "^2.3.0",
21
23
  "preact": "^10.19.4",
22
- "@guiexpert/table": "^1.1.79"
24
+ "@guiexpert/table": "^1.1.80"
23
25
  },
24
26
  "devDependencies": {
25
27
  "svelte": "4.2.19",