@toolbox-web/grid-angular 0.0.1 → 0.1.1

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 ADDED
@@ -0,0 +1,394 @@
1
+ # @toolbox-web/grid-angular
2
+
3
+ [![npm version](https://img.shields.io/npm/v/@toolbox-web/grid-angular.svg)](https://www.npmjs.com/package/@toolbox-web/grid-angular)
4
+ [![License: MIT](https://img.shields.io/badge/License-MIT-blue.svg)](../../LICENSE)
5
+
6
+ Angular adapter for `@toolbox-web/grid` data grid component. Provides directives for declarative template-driven cell renderers and editors.
7
+
8
+ ## Features
9
+
10
+ - ✅ **Auto-adapter registration** - Just import `Grid` directive
11
+ - ✅ **Structural directives** - Clean `*tbwRenderer` and `*tbwEditor` syntax
12
+ - ✅ **Template-driven renderers** - Use `<ng-template>` for custom cell views
13
+ - ✅ **Template-driven editors** - Use `<ng-template>` for custom cell editors
14
+ - ✅ **Auto-wiring** - Editor components just emit events, no manual binding needed
15
+ - ✅ **Full type safety** - Typed template contexts (`GridCellContext`, `GridEditorContext`)
16
+ - ✅ **Angular 17+** - Standalone components, signals support
17
+ - ✅ **AOT compatible** - Works with Angular's ahead-of-time compilation
18
+
19
+ ## Installation
20
+
21
+ ```bash
22
+ # npm
23
+ npm install @toolbox-web/grid @toolbox-web/grid-angular
24
+
25
+ # yarn
26
+ yarn add @toolbox-web/grid @toolbox-web/grid-angular
27
+
28
+ # pnpm
29
+ pnpm add @toolbox-web/grid @toolbox-web/grid-angular
30
+
31
+ # bun
32
+ bun add @toolbox-web/grid @toolbox-web/grid-angular
33
+ ```
34
+
35
+ ## Quick Start
36
+
37
+ ### 1. Register the Grid Component
38
+
39
+ In your Angular application, import the grid registration:
40
+
41
+ ```typescript
42
+ // main.ts or app.config.ts
43
+ import '@toolbox-web/grid';
44
+ ```
45
+
46
+ ### 2. Use in Components
47
+
48
+ ```typescript
49
+ import { Component, CUSTOM_ELEMENTS_SCHEMA } from '@angular/core';
50
+ import { Grid } from '@toolbox-web/grid-angular';
51
+
52
+ @Component({
53
+ selector: 'app-my-grid',
54
+ imports: [Grid],
55
+ schemas: [CUSTOM_ELEMENTS_SCHEMA],
56
+ template: ` <tbw-grid [rows]="rows" [gridConfig]="config" style="height: 400px; display: block;"> </tbw-grid> `,
57
+ })
58
+ export class MyGridComponent {
59
+ rows = [
60
+ { id: 1, name: 'Alice', status: 'active' },
61
+ { id: 2, name: 'Bob', status: 'inactive' },
62
+ ];
63
+
64
+ config = {
65
+ columns: [
66
+ { field: 'id', header: 'ID', type: 'number' },
67
+ { field: 'name', header: 'Name' },
68
+ { field: 'status', header: 'Status' },
69
+ ],
70
+ };
71
+ }
72
+ ```
73
+
74
+ ## Structural Directives (Recommended)
75
+
76
+ The cleanest way to define custom renderers and editors is with structural directives. These provide a concise syntax without the boilerplate of nested `<ng-template>` elements.
77
+
78
+ ### TbwRenderer
79
+
80
+ Use `*tbwRenderer` to customize how cell values are displayed:
81
+
82
+ ```typescript
83
+ import { Component, CUSTOM_ELEMENTS_SCHEMA } from '@angular/core';
84
+ import { Grid, TbwRenderer } from '@toolbox-web/grid-angular';
85
+
86
+ @Component({
87
+ imports: [Grid, TbwRenderer, StatusBadgeComponent],
88
+ schemas: [CUSTOM_ELEMENTS_SCHEMA],
89
+ template: `
90
+ <tbw-grid [rows]="rows" [gridConfig]="config">
91
+ <tbw-grid-column field="status">
92
+ <app-status-badge *tbwRenderer="let value" [value]="value" />
93
+ </tbw-grid-column>
94
+ </tbw-grid>
95
+ `,
96
+ })
97
+ export class MyGridComponent {}
98
+ ```
99
+
100
+ **Template Context:**
101
+
102
+ | Variable | Type | Description |
103
+ | ----------- | --------- | ------------------------------------- |
104
+ | `$implicit` | `TValue` | The cell value (use with `let-value`) |
105
+ | `row` | `TRow` | The full row data object |
106
+ | `column` | `unknown` | The column configuration |
107
+
108
+ ### TbwEditor
109
+
110
+ Use `*tbwEditor` for custom cell editors. The adapter automatically listens for `commit` and `cancel` events from your component, so you don't need to manually wire up callbacks:
111
+
112
+ ```typescript
113
+ import { Component, CUSTOM_ELEMENTS_SCHEMA, output } from '@angular/core';
114
+ import { Grid, TbwRenderer, TbwEditor } from '@toolbox-web/grid-angular';
115
+
116
+ // Your editor component just needs to emit 'commit' and 'cancel' events
117
+ @Component({
118
+ selector: 'app-status-editor',
119
+ template: `
120
+ <select [value]="value()" (change)="commit.emit($any($event.target).value)">
121
+ <option value="active">Active</option>
122
+ <option value="inactive">Inactive</option>
123
+ </select>
124
+ `,
125
+ })
126
+ export class StatusEditorComponent {
127
+ value = input<string>();
128
+ commit = output<string>();
129
+ cancel = output<void>();
130
+ }
131
+
132
+ @Component({
133
+ imports: [Grid, TbwRenderer, TbwEditor, StatusBadgeComponent, StatusEditorComponent],
134
+ schemas: [CUSTOM_ELEMENTS_SCHEMA],
135
+ template: `
136
+ <tbw-grid [rows]="rows" [gridConfig]="config">
137
+ <tbw-grid-column field="status" editable>
138
+ <app-status-badge *tbwRenderer="let value" [value]="value" />
139
+ <app-status-editor *tbwEditor="let value" [value]="value" />
140
+ </tbw-grid-column>
141
+ </tbw-grid>
142
+ `,
143
+ })
144
+ export class MyGridComponent {}
145
+ ```
146
+
147
+ **Template Context:**
148
+
149
+ | Variable | Type | Description |
150
+ | ----------- | ---------- | -------------------------------------------- |
151
+ | `$implicit` | `TValue` | The cell value (use with `let-value`) |
152
+ | `row` | `TRow` | The full row data object |
153
+ | `column` | `unknown` | The column configuration |
154
+ | `onCommit` | `Function` | Callback to commit (optional with auto-wire) |
155
+ | `onCancel` | `Function` | Callback to cancel (optional with auto-wire) |
156
+
157
+ > **Auto-wiring:** If your editor component emits a `commit` event with the new value, the adapter automatically calls the grid's commit function. Similarly for `cancel`. This means you can skip the explicit `onCommit`/`onCancel` bindings!
158
+
159
+ ## Nested Directive Syntax (Alternative)
160
+
161
+ For more explicit control, you can use the nested directive syntax with `<ng-template>`:
162
+
163
+ ### GridColumnView
164
+
165
+ ```typescript
166
+ import { Grid, GridColumnView } from '@toolbox-web/grid-angular';
167
+
168
+ @Component({
169
+ imports: [Grid, GridColumnView],
170
+ schemas: [CUSTOM_ELEMENTS_SCHEMA],
171
+ template: `
172
+ <tbw-grid [rows]="rows" [gridConfig]="config">
173
+ <tbw-grid-column field="status">
174
+ <tbw-grid-column-view>
175
+ <ng-template let-value let-row="row">
176
+ <span [class]="'badge badge--' + value">{{ value }}</span>
177
+ </ng-template>
178
+ </tbw-grid-column-view>
179
+ </tbw-grid-column>
180
+ </tbw-grid>
181
+ `
182
+ })
183
+ ```
184
+
185
+ ### GridColumnEditor
186
+
187
+ ```typescript
188
+ import { Grid, GridColumnView, GridColumnEditor } from '@toolbox-web/grid-angular';
189
+
190
+ @Component({
191
+ imports: [Grid, GridColumnView, GridColumnEditor],
192
+ schemas: [CUSTOM_ELEMENTS_SCHEMA],
193
+ template: `
194
+ <tbw-grid [rows]="rows" [gridConfig]="config">
195
+ <tbw-grid-column field="status" editable>
196
+ <tbw-grid-column-view>
197
+ <ng-template let-value>
198
+ <span [class]="'badge badge--' + value">{{ value }}</span>
199
+ </ng-template>
200
+ </tbw-grid-column-view>
201
+ <tbw-grid-column-editor>
202
+ <ng-template let-value let-commit="commit" let-cancel="cancel">
203
+ <select [value]="value" (change)="commit.emit($any($event.target).value)">
204
+ <option value="active">Active</option>
205
+ <option value="inactive">Inactive</option>
206
+ </select>
207
+ </ng-template>
208
+ </tbw-grid-column-editor>
209
+ </tbw-grid-column>
210
+ </tbw-grid>
211
+ `
212
+ })
213
+ ```
214
+
215
+ ## Grid-Level Events
216
+
217
+ The `Grid` directive provides convenient outputs for common grid events:
218
+
219
+ ```typescript
220
+ import { Grid, CellCommitEvent, RowCommitEvent } from '@toolbox-web/grid-angular';
221
+
222
+ @Component({
223
+ imports: [Grid],
224
+ template: `
225
+ <tbw-grid
226
+ [rows]="rows"
227
+ [gridConfig]="config"
228
+ (cellCommit)="onCellCommit($event)"
229
+ (rowCommit)="onRowCommit($event)"
230
+ />
231
+ `,
232
+ })
233
+ export class MyGridComponent {
234
+ onCellCommit(event: CellCommitEvent<Employee>) {
235
+ console.log('Cell edited:', event.field, event.oldValue, '→', event.newValue);
236
+ }
237
+
238
+ onRowCommit(event: RowCommitEvent<Employee>) {
239
+ console.log('Row saved:', event.rowIndex, event.row);
240
+ }
241
+ }
242
+ ```
243
+
244
+ ## Master-Detail Panels
245
+
246
+ Use `GridDetailView` for expandable row details:
247
+
248
+ ```typescript
249
+ import { Grid, GridDetailView } from '@toolbox-web/grid-angular';
250
+ import { MasterDetailPlugin } from '@toolbox-web/grid/all';
251
+
252
+ @Component({
253
+ imports: [Grid, GridDetailView, DetailPanelComponent],
254
+ template: `
255
+ <tbw-grid [rows]="rows" [gridConfig]="config">
256
+ <tbw-grid-detail showExpandColumn animation="slide">
257
+ <ng-template let-row>
258
+ <app-detail-panel [employee]="row" />
259
+ </ng-template>
260
+ </tbw-grid-detail>
261
+ </tbw-grid>
262
+ `,
263
+ })
264
+ export class MyGridComponent {
265
+ config = {
266
+ plugins: [new MasterDetailPlugin()],
267
+ // ... columns
268
+ };
269
+ }
270
+ ```
271
+
272
+ ## Custom Tool Panels
273
+
274
+ Add custom sidebar panels with `GridToolPanel`:
275
+
276
+ ```typescript
277
+ import { Grid, GridToolPanel } from '@toolbox-web/grid-angular';
278
+
279
+ @Component({
280
+ imports: [Grid, GridToolPanel, QuickFiltersPanelComponent],
281
+ template: `
282
+ <tbw-grid [rows]="rows" [gridConfig]="config">
283
+ <tbw-grid-tool-panel
284
+ id="filters"
285
+ title="Quick Filters"
286
+ icon="🔍"
287
+ tooltip="Filter the data"
288
+ [order]="10"
289
+ >
290
+ <ng-template let-grid>
291
+ <app-quick-filters [grid]="grid" />
292
+ </ng-template>
293
+ </tbw-grid-tool-panel>
294
+ </tbw-grid>
295
+ `,
296
+ })
297
+ ```
298
+
299
+ ## API Reference
300
+
301
+ ### Exported Directives
302
+
303
+ | Directive | Selector | Description |
304
+ | ------------------ | ------------------------ | -------------------------------------- |
305
+ | `Grid` | `tbw-grid` | Main directive, auto-registers adapter |
306
+ | `TbwRenderer` | `*tbwRenderer` | Structural directive for cell views |
307
+ | `TbwEditor` | `*tbwEditor` | Structural directive for cell editors |
308
+ | `GridColumnView` | `tbw-grid-column-view` | Nested directive for cell views |
309
+ | `GridColumnEditor` | `tbw-grid-column-editor` | Nested directive for cell editors |
310
+ | `GridDetailView` | `tbw-grid-detail` | Master-detail panel template |
311
+ | `GridToolPanel` | `tbw-grid-tool-panel` | Custom sidebar panel |
312
+
313
+ ### Exported Types
314
+
315
+ ```typescript
316
+ import type {
317
+ GridCellContext,
318
+ GridEditorContext,
319
+ GridDetailContext,
320
+ GridToolPanelContext,
321
+ CellCommitEvent,
322
+ RowCommitEvent,
323
+ StructuralCellContext,
324
+ StructuralEditorContext,
325
+ } from '@toolbox-web/grid-angular';
326
+ ```
327
+
328
+ ### AngularGridAdapter
329
+
330
+ The adapter class is exported for advanced use cases:
331
+
332
+ ```typescript
333
+ import { AngularGridAdapter } from '@toolbox-web/grid-angular';
334
+ ```
335
+
336
+ In most cases, the `Grid` directive handles adapter registration automatically.
337
+
338
+ ## Migration from TbwCellView/TbwCellEditor
339
+
340
+ If you were using the previous directive names, update your imports and templates:
341
+
342
+ ```typescript
343
+ // Before
344
+ import { TbwCellView, TbwCellEditor } from '@toolbox-web/grid-angular';
345
+
346
+ // After
347
+ import { TbwRenderer, TbwEditor } from '@toolbox-web/grid-angular';
348
+ ```
349
+
350
+ ```html
351
+ <!-- Before -->
352
+ <app-badge *tbwCellView="let value" [value]="value" />
353
+ <app-editor *tbwCellEditor="let value" [value]="value" />
354
+
355
+ <!-- After -->
356
+ <app-badge *tbwRenderer="let value" [value]="value" />
357
+ <app-editor *tbwEditor="let value" [value]="value" />
358
+ ```
359
+
360
+ > **Backwards Compatibility:** The old names (`TbwCellView`, `TbwCellEditor`) are still exported as aliases but are deprecated. They will be removed in a future major version.
361
+
362
+ ## Requirements
363
+
364
+ - Angular 17+ (standalone components)
365
+ - `@toolbox-web/grid` >= 0.2.0
366
+
367
+ ## Demo
368
+
369
+ See the full Angular demo at [`demos/employee-management/angular/`](../../demos/employee-management/angular/) which demonstrates:
370
+
371
+ - 15+ plugins with full configuration
372
+ - Custom editors (star rating, date picker, status select, bonus slider)
373
+ - Custom renderers (status badges, rating colors, top performer stars)
374
+ - Structural directives with auto-wiring
375
+ - Signal-based reactivity
376
+ - Shell integration (header, tool panels)
377
+ - Master-detail expandable rows
378
+
379
+ ## Development
380
+
381
+ ```bash
382
+ # Build the library
383
+ bun nx build grid-angular
384
+
385
+ # Run tests
386
+ bun nx test grid-angular
387
+
388
+ # Lint
389
+ bun nx lint grid-angular
390
+ ```
391
+
392
+ ## License
393
+
394
+ MIT
package/index.d.ts CHANGED
@@ -1,3 +1,9 @@
1
+ /**
2
+ * @packageDocumentation
3
+ * @toolbox-web/grid-angular - Angular adapter for @toolbox-web/grid.
4
+ *
5
+ * Provides directives for seamless Angular integration with the grid component.
6
+ */
1
7
  export { AngularGridAdapter } from './lib/angular-grid-adapter';
2
8
  export { GridColumnEditor } from './lib/directives/grid-column-editor.directive';
3
9
  export type { GridEditorContext } from './lib/directives/grid-column-editor.directive';
@@ -8,4 +14,8 @@ export type { GridDetailContext } from './lib/directives/grid-detail-view.direct
8
14
  export { GridToolPanel } from './lib/directives/grid-tool-panel.directive';
9
15
  export type { GridToolPanelContext } from './lib/directives/grid-tool-panel.directive';
10
16
  export { Grid } from './lib/directives/grid.directive';
17
+ export type { CellCommitEvent, RowCommitEvent } from './lib/directives/grid.directive';
18
+ export { TbwEditor, TbwRenderer } from './lib/directives/structural-directives';
19
+ export type { StructuralCellContext, StructuralEditorContext } from './lib/directives/structural-directives';
20
+ export { TbwEditor as TbwCellEditor, TbwRenderer as TbwCellView } from './lib/directives/structural-directives';
11
21
  //# sourceMappingURL=index.d.ts.map
package/index.d.ts.map CHANGED
@@ -1 +1 @@
1
- {"version":3,"file":"index.d.ts","sourceRoot":"","sources":["../../../libs/grid-ang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