@gridstorm/angular 0.1.2
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/README.md +203 -0
- package/dist/index.cjs +294 -0
- package/dist/index.cjs.map +1 -0
- package/dist/index.d.cts +237 -0
- package/dist/index.d.ts +237 -0
- package/dist/index.js +294 -0
- package/dist/index.js.map +1 -0
- package/package.json +80 -0
- package/src/gridstorm.component.ts +252 -0
- package/src/gridstorm.service.ts +101 -0
- package/src/index.ts +23 -0
- package/src/types.ts +94 -0
|
@@ -0,0 +1,101 @@
|
|
|
1
|
+
// ─── GridStorm Service ───
|
|
2
|
+
// Injectable service for managing multiple GridStorm instances.
|
|
3
|
+
// Allows Angular components to access grid APIs by a unique identifier,
|
|
4
|
+
// useful in applications with multiple grids or cross-component communication.
|
|
5
|
+
|
|
6
|
+
import { Injectable } from '@angular/core';
|
|
7
|
+
import type { GridApi } from '@gridstorm/core';
|
|
8
|
+
|
|
9
|
+
/**
|
|
10
|
+
* Service for registering and retrieving GridStorm API instances.
|
|
11
|
+
*
|
|
12
|
+
* Use this service when you have multiple grids in your application
|
|
13
|
+
* and need to access their APIs from different components or services.
|
|
14
|
+
*
|
|
15
|
+
* @example
|
|
16
|
+
* ```typescript
|
|
17
|
+
* // In a component that hosts the grid:
|
|
18
|
+
* constructor(private gridService: GridStormService) {}
|
|
19
|
+
*
|
|
20
|
+
* onGridReady(api: GridApi) {
|
|
21
|
+
* this.gridService.registerApi('employees', api);
|
|
22
|
+
* }
|
|
23
|
+
*
|
|
24
|
+
* // In another component that needs to interact with the grid:
|
|
25
|
+
* constructor(private gridService: GridStormService) {}
|
|
26
|
+
*
|
|
27
|
+
* exportData() {
|
|
28
|
+
* const api = this.gridService.getApi('employees');
|
|
29
|
+
* if (api) {
|
|
30
|
+
* const rows = api.getSelectedRows();
|
|
31
|
+
* // ... do something with rows
|
|
32
|
+
* }
|
|
33
|
+
* }
|
|
34
|
+
* ```
|
|
35
|
+
*/
|
|
36
|
+
@Injectable({ providedIn: 'root' })
|
|
37
|
+
export class GridStormService {
|
|
38
|
+
private apiMap = new Map<string, GridApi>();
|
|
39
|
+
|
|
40
|
+
/**
|
|
41
|
+
* Registers a GridApi instance under a unique identifier.
|
|
42
|
+
*
|
|
43
|
+
* Call this from the `(gridReady)` output handler of the `<gridstorm>` component.
|
|
44
|
+
* If an API with the same ID already exists, it will be replaced.
|
|
45
|
+
*
|
|
46
|
+
* @param id - A unique string identifier for this grid instance.
|
|
47
|
+
* @param api - The GridApi instance to register.
|
|
48
|
+
*/
|
|
49
|
+
registerApi(id: string, api: GridApi): void {
|
|
50
|
+
this.apiMap.set(id, api);
|
|
51
|
+
}
|
|
52
|
+
|
|
53
|
+
/**
|
|
54
|
+
* Retrieves a previously registered GridApi by its identifier.
|
|
55
|
+
*
|
|
56
|
+
* @param id - The unique identifier used during registration.
|
|
57
|
+
* @returns The GridApi instance, or `undefined` if not found.
|
|
58
|
+
*/
|
|
59
|
+
getApi(id: string): GridApi | undefined {
|
|
60
|
+
return this.apiMap.get(id);
|
|
61
|
+
}
|
|
62
|
+
|
|
63
|
+
/**
|
|
64
|
+
* Removes a registered GridApi by its identifier.
|
|
65
|
+
*
|
|
66
|
+
* Call this when a grid component is destroyed to prevent memory leaks.
|
|
67
|
+
*
|
|
68
|
+
* @param id - The unique identifier of the API to remove.
|
|
69
|
+
*/
|
|
70
|
+
removeApi(id: string): void {
|
|
71
|
+
this.apiMap.delete(id);
|
|
72
|
+
}
|
|
73
|
+
|
|
74
|
+
/**
|
|
75
|
+
* Returns all registered grid API identifiers.
|
|
76
|
+
*
|
|
77
|
+
* @returns An array of registered grid IDs.
|
|
78
|
+
*/
|
|
79
|
+
getRegisteredIds(): string[] {
|
|
80
|
+
return Array.from(this.apiMap.keys());
|
|
81
|
+
}
|
|
82
|
+
|
|
83
|
+
/**
|
|
84
|
+
* Checks whether a grid API is registered under the given identifier.
|
|
85
|
+
*
|
|
86
|
+
* @param id - The unique identifier to check.
|
|
87
|
+
* @returns `true` if an API is registered with that ID.
|
|
88
|
+
*/
|
|
89
|
+
hasApi(id: string): boolean {
|
|
90
|
+
return this.apiMap.has(id);
|
|
91
|
+
}
|
|
92
|
+
|
|
93
|
+
/**
|
|
94
|
+
* Removes all registered grid APIs.
|
|
95
|
+
*
|
|
96
|
+
* Useful during application teardown or testing.
|
|
97
|
+
*/
|
|
98
|
+
clear(): void {
|
|
99
|
+
this.apiMap.clear();
|
|
100
|
+
}
|
|
101
|
+
}
|
package/src/index.ts
ADDED
|
@@ -0,0 +1,23 @@
|
|
|
1
|
+
// ─── @gridstorm/angular — Public API ───
|
|
2
|
+
|
|
3
|
+
// Component
|
|
4
|
+
export { GridStormComponent } from './gridstorm.component';
|
|
5
|
+
|
|
6
|
+
// Service
|
|
7
|
+
export { GridStormService } from './gridstorm.service';
|
|
8
|
+
|
|
9
|
+
// Types
|
|
10
|
+
export type {
|
|
11
|
+
GridStormInputs,
|
|
12
|
+
GridStormOutputs,
|
|
13
|
+
GridRegistration,
|
|
14
|
+
} from './types';
|
|
15
|
+
|
|
16
|
+
// Re-export commonly needed core types for convenience
|
|
17
|
+
export type {
|
|
18
|
+
GridApi,
|
|
19
|
+
GridConfig,
|
|
20
|
+
GridEngine,
|
|
21
|
+
ColumnDef,
|
|
22
|
+
GridPlugin,
|
|
23
|
+
} from '@gridstorm/core';
|
package/src/types.ts
ADDED
|
@@ -0,0 +1,94 @@
|
|
|
1
|
+
// ─── Angular-Specific Types for GridStorm ───
|
|
2
|
+
|
|
3
|
+
import type { GridApi, GridConfig, ColumnDef, GridPlugin } from '@gridstorm/core';
|
|
4
|
+
|
|
5
|
+
/**
|
|
6
|
+
* Input configuration for the GridStorm Angular component.
|
|
7
|
+
*
|
|
8
|
+
* Maps GridConfig properties to Angular `@Input()` bindings.
|
|
9
|
+
* All properties are optional and match the core GridConfig interface.
|
|
10
|
+
*
|
|
11
|
+
* @typeParam TData - The type of each row data object.
|
|
12
|
+
*/
|
|
13
|
+
export interface GridStormInputs<TData = any> {
|
|
14
|
+
/** Column definitions describing each column's structure and behavior. */
|
|
15
|
+
columns: ColumnDef<TData>[];
|
|
16
|
+
|
|
17
|
+
/** Client-side row data array. */
|
|
18
|
+
rowData: TData[];
|
|
19
|
+
|
|
20
|
+
/** Array of plugins to install during grid initialization. */
|
|
21
|
+
plugins: GridPlugin<TData>[];
|
|
22
|
+
|
|
23
|
+
/** Callback to generate a unique string ID for each row. */
|
|
24
|
+
getRowId?: GridConfig<TData>['getRowId'];
|
|
25
|
+
|
|
26
|
+
/** Height of each data row in pixels. */
|
|
27
|
+
rowHeight: number;
|
|
28
|
+
|
|
29
|
+
/** Theme identifier: 'light', 'dark', or custom theme name. */
|
|
30
|
+
theme: string;
|
|
31
|
+
|
|
32
|
+
/** Density mode: 'compact', 'normal', or 'comfortable'. */
|
|
33
|
+
density: string;
|
|
34
|
+
|
|
35
|
+
/** Default column definition applied to all columns as fallback. */
|
|
36
|
+
defaultColDef?: Partial<ColumnDef<TData>>;
|
|
37
|
+
|
|
38
|
+
/** Number of rows per page when pagination is enabled. */
|
|
39
|
+
paginationPageSize?: number;
|
|
40
|
+
|
|
41
|
+
/** Height of the header row in pixels. */
|
|
42
|
+
headerHeight?: number;
|
|
43
|
+
|
|
44
|
+
/** Controls how the grid's DOM height is determined. */
|
|
45
|
+
domLayout?: GridConfig<TData>['domLayout'];
|
|
46
|
+
|
|
47
|
+
/** Row selection mode: 'single', 'multiple', or false. */
|
|
48
|
+
rowSelection?: GridConfig<TData>['rowSelection'];
|
|
49
|
+
|
|
50
|
+
/** When true, enables client-side pagination. */
|
|
51
|
+
pagination?: boolean;
|
|
52
|
+
|
|
53
|
+
/** ARIA label for the grid root element. */
|
|
54
|
+
ariaLabel?: string;
|
|
55
|
+
}
|
|
56
|
+
|
|
57
|
+
/**
|
|
58
|
+
* Event payloads emitted by the GridStorm Angular component.
|
|
59
|
+
*
|
|
60
|
+
* These are emitted through Angular `@Output()` EventEmitter bindings,
|
|
61
|
+
* bridging core engine events to Angular's event system.
|
|
62
|
+
*
|
|
63
|
+
* @typeParam TData - The type of each row data object.
|
|
64
|
+
*/
|
|
65
|
+
export interface GridStormOutputs<TData = any> {
|
|
66
|
+
/** Emitted when the grid engine is fully initialized and the API is ready. */
|
|
67
|
+
gridReady: GridApi<TData>;
|
|
68
|
+
|
|
69
|
+
/** Emitted when row data changes. */
|
|
70
|
+
rowDataChanged: { rowData: TData[] };
|
|
71
|
+
|
|
72
|
+
/** Emitted when the selection state changes. */
|
|
73
|
+
selectionChanged: { selectedNodes: any[]; source: string };
|
|
74
|
+
|
|
75
|
+
/** Emitted when the sort model changes. */
|
|
76
|
+
sortChanged: { sortModel: any[] };
|
|
77
|
+
|
|
78
|
+
/** Emitted when the filter model changes. */
|
|
79
|
+
filterChanged: { filterModel: Record<string, any> };
|
|
80
|
+
|
|
81
|
+
/** Emitted when a cell value is changed through editing. */
|
|
82
|
+
cellValueChanged: { node: any; colId: string; oldValue: any; newValue: any };
|
|
83
|
+
}
|
|
84
|
+
|
|
85
|
+
/**
|
|
86
|
+
* Options for the GridStormService `registerApi` call.
|
|
87
|
+
*/
|
|
88
|
+
export interface GridRegistration {
|
|
89
|
+
/** Unique identifier for this grid instance. */
|
|
90
|
+
id: string;
|
|
91
|
+
|
|
92
|
+
/** The grid API instance. */
|
|
93
|
+
api: GridApi;
|
|
94
|
+
}
|