@guiexpert/table 1.1.29 → 1.1.31

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.
@@ -1,6 +1,50 @@
1
1
  import { FocusType } from "./focus.type";
2
2
  import { FocusModelIf } from "./focus-model.if";
3
3
  import { EventFocusChangedListenerIf } from './event-focus-changed-listener.if';
4
+ /**
5
+ * The `FocusModel` class is an implementation of the `FocusModelIf` interface.
6
+ * It provides core functionality to manage focus inside a data grid or spreadsheet-like structure.
7
+ * The focus can be set to a specific cell or to the whole row.
8
+ * This class also maintains a list of `EventFocusChangedListenerIf` instances and notifies them
9
+ * whenever there is a change in focus.
10
+ *
11
+ * ## Instance Properties:
12
+ * - `selectionType: FocusType` — Specifies the type of selection that is currently in focus. It could be either a specific cell or the whole row. Defaults to "none".
13
+ * - `rowIndex: number` — Specifies the row index of the cell that is currently in focus.
14
+ * - `columnIndex: number` — Specifies the column index of the cell that is currently in focus.
15
+ * - `listenerArr: EventFocusChangedListenerIf[]` — An array of `EventFocusChangedListenerIf` instances. These instances will be triggered when the focus changes.
16
+ * - `changed` — A boolean flag to check if the focus has changed since the last trigger.
17
+ *
18
+ * ## Instance Methods:
19
+ * - `getEventFocusChangedListeners` — Returns an array of `EventFocusChangedListenerIf` instances.
20
+ * - `addEventFocusChangedListener(listener: EventFocusChangedListenerIf): void` — Adds a listener to the listeners array, if it's not already present.
21
+ * - `removeEventFocusChangedListener(listener: EventFocusChangedListenerIf): void` — Removes a listener from the listeners array.
22
+ * - `clear`: void — Clears the current focus.
23
+ * - `setFocus(rowIndex: number, columnIndex: number): void` — Sets focus on a given cell.
24
+ * - `hasChanged(): boolean` — Checks if the focus has changed.
25
+ * - `clearChanged`: void — Clears the `changed` flag.
26
+ * - `hasFocus(rowIndex: number, columnIndex: number): boolean` — Checks if a given cell is in focus.
27
+ * - `getFocus(): [number, number]` — Returns the row and column indexes of the cell that's currently in focus.
28
+ *
29
+ * ## Usage Example
30
+ * ```typescript
31
+ *
32
+ * class MyFocusChangeListener implements EventFocusChangedListenerIf {
33
+ * onFocusChanged(model: FocusModelIf): void {
34
+ * console.log('Focus changed: ', model.getFocus());
35
+ * }
36
+ * }
37
+ * let focusModel = new FocusModel("cell");
38
+ * focusModel.addEventFocusChangedListener(new MyFocusChangeListener());
39
+ * focusModel.setFocus(2, 3);
40
+ * ```
41
+ *
42
+ * @see [FocusType](./FocusType.md)
43
+ * @see [EventFocusChangedListenerIf](./EventFocusChangedListenerIf.md)
44
+ *
45
+ * @class
46
+ * @implements {FocusModelIf}
47
+ */
4
48
  export declare class FocusModel implements FocusModelIf {
5
49
  selectionType: FocusType;
6
50
  protected rowIndex: number;
@@ -1 +1,29 @@
1
+ /**
2
+ * The `FocusType` type alias provides an enumerated set of string literal values
3
+ * which can be used to indicate the type of focus within the grid.
4
+ *
5
+ * The values are:
6
+ * - "none" : Indicating that cells and rows cannot have a focus.
7
+ * - "cell" : Indicating that cells can have a focus.
8
+ * - "row" : Indicating that entire rows can have a focus.
9
+ *
10
+ * Typically, this type is used within the `FocusModel` class,
11
+ * specifically in the `constructor` and in the `setFocus` method,
12
+ * to set `selectionType` property and determine where the focus is set respectively.
13
+ *
14
+ * Here is a usage example with the `FocusModel` class:
15
+ *
16
+ * ```typescript
17
+ * let focusModel = new FocusModel("cell");
18
+ * focusModel.setFocus(2, 3);
19
+ * ```
20
+ *
21
+ * In the above example, a `FocusModel` instance is created with a `FocusType` of "cell".
22
+ * Then the focus is set to the cell at row index 2 and column index 3.
23
+ *
24
+ * @see FocusModel
25
+ * @see FocusModel#setFocus
26
+ * @see FocusModelIf
27
+ * @type
28
+ */
1
29
  export type FocusType = "none" | "cell" | "row";
@@ -1,6 +1,12 @@
1
1
  import { TableScope } from "./table-scope";
2
+ /**
3
+ * Class representing a ResizeHandler.
4
+ * @class
5
+ * @classdesc Handles resizing of elements and calls a callback function on resize. These calls will be debounced with 500 ms.
6
+ */
2
7
  export declare class ResizeHandler {
3
8
  protected tableScope: TableScope;
4
- constructor(tableScope: TableScope);
9
+ protected debounceDelay: number;
10
+ constructor(tableScope: TableScope, debounceDelay?: number);
5
11
  private handleResize;
6
12
  }
@@ -2,6 +2,42 @@ import { CellRange } from "../data/common/cell-range";
2
2
  import { ExtendedSelectionType, SelectionMode } from './selection.type';
3
3
  import { SelectionModelIf } from "./selection-model.if";
4
4
  import { EventSelectionChangedListenerIf } from './event-selection-changed-listener.if';
5
+ /**
6
+ * `SelectionModel` is a class that manages the various modes and types of selections within a grid.
7
+ * It supports basic modes like single cell, row, column, and range selections, as well as advanced mode like negative ranges.
8
+ * Events related to selections, such as changes to a selection, are propagated to listeners through the EventSelectionChangedListener interface.
9
+ *
10
+ * The class extends `SelectionModelIf` interface and defines additional methods and fields specific to its functionality.
11
+ *
12
+ * @property {ExtendedSelectionType} selectionType - The type of selection being used. It's of type ExtendedSelectionType. Default: "none"
13
+ * @property {SelectionMode} selectionMode - The mode of selection being used. It's of type SelectionMode. Default: "single"
14
+ * @property {Array} ranges - This contains all the current selected cell ranges in the grid.
15
+ * @property {Array} negativeRanges - This contains all the current negative cell ranges in the grid.
16
+ * @property {boolean} allSelected - This is a flag to indicate whether all cells in the grid are selected or not.
17
+ * @property {boolean} silent - This is a flag to suppress the firing of selection change events.
18
+ * @property {Array} listenerArr - This contains all the listeners for selection change events.
19
+ *
20
+ * @method constructor(selectionType?: ExtendedSelectionType, selectionMode?: SelectionMode) - Constructs a new instance of the SelectionModel class.
21
+ * @method getEventSelectionChangedListeners(): EventSelectionChangedListenerIf[] - Returns the array of registered event selection changed listeners.
22
+ * @method addEventSelectionChangedListener(listener: EventSelectionChangedListenerIf): void - Adds an event selection changed listener to the array.
23
+ * @method removeEventSelectionChangedListener(listener: EventSelectionChangedListenerIf): void - Removes a specific event selection changed listener if it exists.
24
+ * @method fireChangeEvent(): void - Fires a change event on each registered listener when a selection change occurs. Does nothing if the silent property is true.
25
+ * @method firstClick(rowIndex: number, columnIndex: number): void - Initiates a selection operation at the specified coordinates. The nature of the operation is determined by the current selection type and mode.
26
+ * @method getSelectionCount(rowIndex: number, columnIndex: number): number - Returns the selection count of current ranges
27
+ * @method isInNegativeRange(rowIndex: number, columnIndex: number): boolean - Verifies if any point (cell) is in negative range or not.
28
+ * @method getRanges() - Returns the selection ranges
29
+ * @method clear(): void - Clears all selections in all ranges and resets allSelected and negativeRanges arrays.
30
+ * @method hasSelection(): boolean - Checks whether there is any selection. Returns true if yes, false if no.
31
+ * @method hasNoSelection(): boolean - Checks whether there is no selection. Returns true if yes, false if no.
32
+ * @method getMergedRowIndices(): number[] - Gets the array of merged row indices.
33
+ * @method selectAll(): void - Selects all selectable entities.
34
+ * @method isAllSelected() - Checks if all selectable entities are selected.
35
+ * @method addSelection(range: CellRange): void - Adds a certain range to the selection.
36
+ * @method removeSelection(range: CellRange): void - Removes a certain range from the selection.
37
+ * @method togglePoint(row: number, col: number): void - Toggles the selection state of a point at the specified row and column in a grid.
38
+ * @method isSelected(row: number, col: number): boolean - Checks if a specific cell in a grid is selected.
39
+ * @method addRange(range: CellRange): void - Adds a range of cells to the selection.
40
+ */
5
41
  export declare class SelectionModel implements SelectionModelIf {
6
42
  selectionType: ExtendedSelectionType;
7
43
  selectionMode: SelectionMode;
@@ -0,0 +1,19 @@
1
+ import { ExcelServiceIf } from './excel-service.if';
2
+ export declare class ExcelService implements ExcelServiceIf {
3
+ /**
4
+ * Downloads a matrix data as an Excel file.
5
+ *
6
+ * @param {Array<Array<any>>} matrix - A 2D array representing the data to be included in the Excel file. Each inner array corresponds to a row in the sheet.
7
+ * @param {string} [filename='file.xlsx'] - The name of the Excel file to be downloaded. Defaults to 'file.xlsx'.
8
+ * @param {string} [author=''] - The author's name to include as metadata in the Excel file. Optional parameter.
9
+ * @return {void} Does not return a value.
10
+ * @throws {Error} Throws an error if the input matrix is not a valid 2D array or if the filename is an empty string.
11
+ */
12
+ downloadExcel(matrix: Array<Array<any>>, filename?: string, author?: string): void;
13
+ private generateMap;
14
+ private getX1WorksheetsSheet1Xml;
15
+ private escapeXml;
16
+ private getCellAddress;
17
+ createZip(files: Map<string, string>): Uint8Array;
18
+ private generateBuffer;
19
+ }
@@ -0,0 +1,3 @@
1
+ export interface ExcelServiceIf {
2
+ downloadExcel(matrix: Array<Array<any>>, filename: string, author?: string): void;
3
+ }
@@ -5,6 +5,15 @@ import { SelectionModel } from './selection/selection-model';
5
5
  import { ActionId } from './action/action-id.type';
6
6
  import { ShortcutActionIdMapping } from './action/shortcut-actionid-mapping.type';
7
7
  import { SelectionModelIf } from './selection/selection-model.if';
8
+ /**
9
+ * TableApi Class
10
+ *
11
+ * A class for interfacing with a table within the application.
12
+ * It includes features for scrolling, updating cells, handling visibility of elements like header and footer,
13
+ * and dealing with selections within the table.
14
+ *
15
+ * An instance of this class is automatically created for each table component.
16
+ */
8
17
  export declare class TableApi {
9
18
  readonly tableScope: TableScope;
10
19
  constructor(tableScope: TableScope);
@@ -100,6 +109,13 @@ export declare class TableApi {
100
109
  * @return {void}
101
110
  */
102
111
  repaintHard(): void;
112
+ /**
113
+ * Recalculates the column widths of the table.
114
+ *
115
+ * @param {number} clientWidth - The width of the client area.
116
+ *
117
+ * @return {void}
118
+ */
103
119
  recalcColumnWidths(clientWidth?: number): void;
104
120
  /**
105
121
  * Clears the current selection of the table.
@@ -137,6 +153,13 @@ export declare class TableApi {
137
153
  * @return {Promise<string>} - A promise that resolves with the copied data as a string.
138
154
  */
139
155
  copyToClipboard(): Promise<string>;
156
+ /**
157
+ * Downloads an Excel file containing data from the table's header, body, and footer areas.
158
+ * Extracts the table data into a 2D matrix and uses the Excel service to generate and download the file.
159
+ *
160
+ * @return {void} No return value, downloads the Excel file directly.
161
+ */
162
+ downloadExcel(): void;
140
163
  /**
141
164
  * Retrieves the current scope of the table.
142
165
  *
@@ -24,6 +24,7 @@ import { FocusModelIf } from './focus/focus-model.if';
24
24
  import { EventFocusChangedListenerIf } from './focus/event-focus-changed-listener.if';
25
25
  import { EventSelectionChangedListenerIf } from './selection/event-selection-changed-listener.if';
26
26
  import { ResizeHandler } from './resize-handler';
27
+ import { ExcelServiceIf } from './service/excel-service.if';
27
28
  /**
28
29
  * The TableScope class extends the RenderScope class and provides functionality for rendering and interacting with a table.
29
30
  *
@@ -53,6 +54,7 @@ import { ResizeHandler } from './resize-handler';
53
54
  export declare class TableScope extends RenderScope implements OnActionTriggeredIf, EventFocusChangedListenerIf, EventSelectionChangedListenerIf {
54
55
  protected readonly eventListener: EventListenerIf;
55
56
  readonly copyService: CopyServiceIf;
57
+ readonly excelService: ExcelServiceIf;
56
58
  licenseManager: LicenseManager;
57
59
  mouseHandler: MouseHandler;
58
60
  inputHandler: InputHandler;
@@ -71,7 +73,7 @@ export declare class TableScope extends RenderScope implements OnActionTriggered
71
73
  private lastDragFrom;
72
74
  private lastDragTo;
73
75
  private firstDraggingRendering;
74
- constructor(hostElement: HTMLDivElement, tableModel: TableModelIf, domService: DomServiceIf, tableOptions: TableOptionsIf, eventListener: EventListenerIf, copyService?: CopyServiceIf);
76
+ constructor(hostElement: HTMLDivElement, tableModel: TableModelIf, domService: DomServiceIf, tableOptions: TableOptionsIf, eventListener: EventListenerIf, copyService?: CopyServiceIf, excelService?: ExcelServiceIf);
75
77
  /**
76
78
  * Creates a TableScope instance.
77
79
  *
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@guiexpert/table",
3
- "version": "1.1.29",
3
+ "version": "1.1.31",
4
4
  "private": false,
5
5
  "type": "module",
6
6
  "main": "./index.js",