@toolbox-web/grid-angular 0.4.0 → 0.5.0

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 +1 @@
1
- {"version":3,"file":"angular-grid-adapter.d.ts","sourceRoot":"","sources":["../../../../libs/grid-angular/src/lib/angular-grid-adapter.ts"],"names":[],"mappings":"AAAA,OAAO,EACL,cAAc,EAId,mBAAmB,EAInB,gBAAgB,EACjB,MAAM,eAAe,CAAC;AACvB,OAAO,KAAK,EAEV,YAAY,EAEZ,gBAAgB,EAChB,kBAAkB,EAClB,gBAAgB,EAChB,UAAU,EACV,WAAW,EACZ,MAAM,mBAAmB,CAAC;AAC3B,OAAO,EAAoB,KAAK,mBAAmB,EAAE,KAAK,iBAAiB,EAAE,MAAM,yBAAyB,CAAC;AAkC7G;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;GA2DG;AACH,qBAAa,kBAAmB,YAAW,gBAAgB;IAMvD,OAAO,CAAC,QAAQ;IAChB,OAAO,CAAC,MAAM;IACd,OAAO,CAAC,gBAAgB;IAP1B,OAAO,CAAC,QAAQ,CAAkC;IAClD,OAAO,CAAC,aAAa,CAA+B;IACpD,OAAO,CAAC,YAAY,CAAiC;gBAG3C,QAAQ,EAAE,mBAAmB,EAC7B,MAAM,EAAE,cAAc,EACtB,gBAAgB,EAAE,gBAAgB;IAa5C;;;;;;;;;;;;;;;;;;;;;;;;;OAyBG;IACH,iBAAiB,CAAC,IAAI,GAAG,OAAO,EAAE,MAAM,EAAE,iBAAiB,CAAC,IAAI,CAAC,GAAG,UAAU,CAAC,IAAI,CAAC;IAapF;;;;;;OAMG;IACH,aAAa,CAAC,IAAI,GAAG,OAAO,EAAE,MAAM,EAAE,mBAAmB,CAAC,IAAI,CAAC,GAAG,YAAY,CAAC,IAAI,CAAC;IAgBpF;;;OAGG;IACH,SAAS,CAAC,OAAO,EAAE,WAAW,GAAG,OA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O,CAAC,kBAAkB;IAU1B;;;OAGG;IACH,OAAO,IAAI,IAAI;CAMhB"}
@@ -0,0 +1,145 @@
1
+ import { AbstractControl } from '@angular/forms';
2
+ import { ColumnConfig } from '../../../../dist/libs/grid/index.d.ts';
3
+ /**
4
+ * Base class for grid cell editors.
5
+ *
6
+ * Provides common functionality for Angular cell editors:
7
+ * - Automatic value resolution from FormControl or value input
8
+ * - Common inputs (value, row, column, control)
9
+ * - Common outputs (commit, cancel)
10
+ * - Validation state helpers
11
+ *
12
+ * ## Usage
13
+ *
14
+ * ```typescript
15
+ * import { Component } from '@angular/core';
16
+ * import { BaseGridEditor } from '@toolbox-web/grid-angular';
17
+ *
18
+ * @Component({
19
+ * selector: 'app-my-editor',
20
+ * template: \`
21
+ * <input
22
+ * [value]="currentValue()"
23
+ * [class.is-invalid]="isInvalid()"
24
+ * (input)="commitValue($event.target.value)"
25
+ * (keydown.escape)="cancelEdit()"
26
+ * />
27
+ * @if (hasErrors()) {
28
+ * <div class="error">{{ firstErrorMessage() }}</div>
29
+ * }
30
+ * \`
31
+ * })
32
+ * export class MyEditorComponent extends BaseGridEditor<MyRow, string> {
33
+ * // Override to customize error messages
34
+ * protected override getErrorMessage(errorKey: string): string {
35
+ * if (errorKey === 'required') return 'This field is required';
36
+ * if (errorKey === 'minlength') return 'Too short';
37
+ * return super.getErrorMessage(errorKey);
38
+ * }
39
+ * }
40
+ * ```
41
+ *
42
+ * ## Template Syntax
43
+ *
44
+ * When using the base class, you only need to pass the control:
45
+ *
46
+ * ```html
47
+ * <tbw-grid-column field="name">
48
+ * <app-my-editor *tbwEditor="let _; control as control" [control]="control" />
49
+ * </tbw-grid-column>
50
+ * ```
51
+ *
52
+ * Or without FormArray binding (fallback to value):
53
+ *
54
+ * ```html
55
+ * <tbw-grid-column field="name">
56
+ * <app-my-editor *tbwEditor="let value" [value]="value" />
57
+ * </tbw-grid-column>
58
+ * ```
59
+ *
60
+ * @typeParam TRow - The row data type
61
+ * @typeParam TValue - The cell value type
62
+ */
63
+ export declare abstract class BaseGridEditor<TRow = unknown, TValue = unknown> {
64
+ private readonly elementRef;
65
+ /**
66
+ * The cell value. Used when FormControl is not available.
67
+ * When a FormControl is provided, value is derived from control.value instead.
68
+ */
69
+ readonly value: import('@angular/core').InputSignal<TValue | undefined>;
70
+ /**
71
+ * The full row data object.
72
+ */
73
+ readonly row: import('@angular/core').InputSignal<TRow | undefined>;
74
+ /**
75
+ * The column configuration.
76
+ */
77
+ readonly column: import('@angular/core').InputSignal<ColumnConfig<TRow> | undefined>;
78
+ /**
79
+ * The FormControl for this cell, if the grid is bound to a FormArray.
80
+ * When provided, the editor uses control.value instead of the value input.
81
+ */
82
+ readonly control: import('@angular/core').InputSignal<AbstractControl<any, any, any> | undefined>;
83
+ /**
84
+ * Emits when the user commits a new value.
85
+ */
86
+ readonly commit: import('@angular/core').OutputEmitterRef<TValue>;
87
+ /**
88
+ * Emits when the user cancels editing.
89
+ */
90
+ readonly cancel: import('@angular/core').OutputEmitterRef<void>;
91
+ /**
92
+ * The current value, derived from FormControl if available, otherwise from value input.
93
+ * This is the recommended way to get the current value in your editor template.
94
+ */
95
+ readonly currentValue: import('@angular/core').Signal<TValue | undefined>;
96
+ /**
97
+ * Whether the control is invalid (has validation errors).
98
+ * Returns false if no FormControl is available.
99
+ */
100
+ readonly isInvalid: import('@angular/core').Signal<boolean>;
101
+ /**
102
+ * Whether the control is dirty (has been modified).
103
+ * Returns false if no FormControl is available.
104
+ */
105
+ readonly isDirty: import('@angular/core').Signal<boolean>;
106
+ /**
107
+ * Whether the control has been touched.
108
+ * Returns false if no FormControl is available.
109
+ */
110
+ readonly isTouched: import('@angular/core').Signal<boolean>;
111
+ /**
112
+ * Whether the control has any validation errors.
113
+ */
114
+ readonly hasErrors: import('@angular/core').Signal<boolean>;
115
+ /**
116
+ * The first error message from the control's validation errors.
117
+ * Returns an empty string if no errors.
118
+ */
119
+ readonly firstErrorMessage: import('@angular/core').Signal<string>;
120
+ /**
121
+ * All error messages from the control's validation errors.
122
+ */
123
+ readonly allErrorMessages: import('@angular/core').Signal<string[]>;
124
+ /**
125
+ * Commit a new value. Emits the commit output AND dispatches a DOM event.
126
+ * The DOM event enables the grid's auto-wiring to catch the commit.
127
+ * Call this when the user confirms their edit.
128
+ */
129
+ commitValue(newValue: TValue): void;
130
+ /**
131
+ * Cancel editing. Emits the cancel output AND dispatches a DOM event.
132
+ * Call this when the user cancels (e.g., presses Escape).
133
+ */
134
+ cancelEdit(): void;
135
+ /**
136
+ * Get a human-readable error message for a validation error.
137
+ * Override this method to customize error messages for your editor.
138
+ *
139
+ * @param errorKey - The validation error key (e.g., 'required', 'minlength')
140
+ * @param errorValue - The error value (e.g., { requiredLength: 5, actualLength: 3 })
141
+ * @returns A human-readable error message
142
+ */
143
+ protected getErrorMessage(errorKey: string, errorValue?: unknown): string;
144
+ }
145
+ //# sourceMappingURL=base-grid-editor.d.ts.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"base-grid-editor.d.ts","sourceRoot":"","sources":["../../../../libs/grid-angular/src/lib/base-grid-editor.ts"],"names":[],"mappings":"AACA,OAAO,KAAK,EAAE,eAAe,EAAE,MAAM,gBAAgB,CAAC;AACtD,OAAO,KAAK,EAAE,YAAY,EAAE,MAAM,mBAAmB,CAAC;AAEtD;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;GA2DG;AACH,8BACsB,cAAc,CAAC,IAAI,GAAG,OAAO,EAAE,MAAM,GAAG,OAAO;IACnE,OAAO,CAAC,QAAQ,CAAC,UAAU,CAAsB;IAMjD;;;OAGG;IACH,QAAQ,CAAC,KAAK,0DAAmB;IAEjC;;OAEG;IACH,QAAQ,CAAC,GAAG,wDAAiB;IAE7B;;OAEG;IACH,QAAQ,CAAC,MAAM,sEAA+B;IAE9C;;;OAGG;IACH,QAAQ,CAAC,OAAO,kFAA4B;IAM5C;;OAEG;IACH,QAAQ,CAAC,MAAM,mDAAoB;IAEnC;;OAEG;IACH,QAAQ,CAAC,MAAM,iDAAkB;IAMjC;;;OAGG;IACH,QAAQ,CAAC,YAAY,qDAMlB;IAEH;;;OAGG;IACH,QAAQ,CAAC,SAAS,0CAEf;IAEH;;;OAGG;IACH,QAAQ,CAAC,OAAO,0CAEb;IAEH;;;OAGG;IACH,QAAQ,CAAC,SAAS,0CAEf;IAEH;;OAEG;IACH,QAAQ,CAAC,SAAS,0CAGf;IAEH;;;OAGG;IACH,QAAQ,CAAC,iBAAiB,yCAMvB;IAEH;;OAEG;IACH,QAAQ,CAAC,gBAAgB,2CAKtB;IAMH;;;;OAIG;IACH,WAAW,CAAC,QAAQ,EAAE,MAAM,GAAG,IAAI;IASnC;;;OAGG;IACH,UAAU,IAAI,IAAI;IAQlB;;;;;;;OAOG;IACH,SAAS,CAAC,eAAe,CAAC,QAAQ,EAAE,MAAM,EAAE,UAAU,CAAC,EAAE,OAAO,GAAG,MAAM;CA4B1E"}
@@ -1,4 +1,5 @@
1
1
  import { EventEmitter, TemplateRef } from '@angular/core';
2
+ import { AbstractControl } from '@angular/forms';
2
3
  /**
3
4
  * Context object passed to the cell editor template.
4
5
  * Contains the cell value, row data, column configuration, and commit/cancel functions.
@@ -22,6 +23,22 @@ export interface GridEditorContext<TValue = unknown, TRow = unknown> {
22
23
  * Use with Angular event binding: `(cancel)="onCancel()"`
23
24
  */
24
25
  onCancel: () => void;
26
+ /**
27
+ * The FormControl for this cell, if the grid is bound to a FormArray with FormGroups.
28
+ *
29
+ * This allows custom editors to bind directly to the control for validation display:
30
+ * ```html
31
+ * <input *tbwEditor="let value; control as ctrl"
32
+ * [formControl]="ctrl"
33
+ * [class.is-invalid]="ctrl?.invalid && ctrl?.touched" />
34
+ * ```
35
+ *
36
+ * Returns `undefined` if:
37
+ * - The grid is not bound to a FormArray
38
+ * - The FormArray doesn't contain FormGroups
39
+ * - The field doesn't exist in the FormGroup
40
+ */
41
+ control?: AbstractControl;
25
42
  /**
26
43
  * @deprecated Use `onCommit` callback function instead. Will be removed in v2.0.
27
44
  * EventEmitter for commit - requires `.emit()` call.
@@ -1 +1 @@
1
- {"version":3,"file":"grid-column-editor.directive.d.ts","sourceRoot":"","sources":["../../../../../libs/grid-angular/src/lib/directives/grid-column-editor.directive.ts"],"names":[],"mappings":"AAAA,OAAO,EAA+C,YAAY,EAAU,WAAW,EAAE,MAAM,eAAe,CAAC;AAE/G;;;GAGG;AACH,MAAM,WAAW,iBAAiB,CAAC,MAAM,GAAG,OAAO,EAAE,IAAI,GAAG,OAAO;IACjE,qCAAqC;IACrC,SAAS,EAAE,MAAM,CAAC;IAClB,wCAAwC;IACxC,KAAK,EAAE,MAAM,CAAC;IACd,+BAA+B;IAC/B,GAAG,EAAE,IAAI,CAAC;IACV,+BAA+B;IAC/B,MAAM,EAAE,OAAO,CAAC;IAChB;;;OAGG;IACH,QAAQ,EAAE,CAAC,KAAK,EAAE,MAAM,KAAK,IAAI,CAAC;IAClC;;;OAGG;IACH,QAAQ,EAAE,MAAM,IAAI,CAAC;IACrB;;;OAGG;IACH,MAAM,EAAE,YAAY,CAAC,MAAM,CAAC,CAAC;IAC7B;;;OAGG;IACH,MAAM,EAAE,YAAY,CAAC,IAAI,CAAC,CAAC;CAC5B;AAKD;;;GAGG;AACH,wBAAgB,iBAAiB,CAAC,OAAO,EAAE,WAAW,GAAG,WAAW,CAAC,iBAAiB,CAAC,GAAG,SAAS,CAElG;AAED;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;GAwCG;AACH,qBACa,gBAAgB;IAC3B,OAAO,CAAC,UAAU,CAAmC;IAErD;;OAEG;IACH,QAAQ,+DAAgD;IAExD,0DAA0D;IAC1D,OAAO,CAAC,kBAAkB,CAMvB;IAEH;;;OAGG;IACH,MAAM,CAAC,sBAAsB,CAAC,GAAG,EAAE,gBAAgB,EAAE,GAAG,EAAE,OAAO,GAAG,GAAG,IAAI,iBAAiB;CAG7F"}
1
+ {"version":3,"file":"grid-column-editor.directive.d.ts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
+ import { OnDestroy, OnInit } from '@angular/core';
2
+ import { AbstractControl, FormArray, FormGroup } from '@angular/forms';
3
+ /**
4
+ * Context provided to the grid containing form-related information.
5
+ * This can be accessed by other directives to get form controls.
6
+ */
7
+ export interface FormArrayContext {
8
+ /** Get the row data at a specific index */
9
+ getRow<T = unknown>(rowIndex: number): T | null;
10
+ /** Update a field value at a specific row */
11
+ updateField(rowIndex: number, field: string, value: unknown): void;
12
+ /** Get the current form value (all rows) */
13
+ getValue<T = unknown>(): T[];
14
+ /**
15
+ * Get the FormControl for a specific cell.
16
+ * Only available when using FormArray with FormGroup rows.
17
+ *
18
+ * @param rowIndex - The row index
19
+ * @param field - The field name
20
+ * @returns The AbstractControl for the cell, or undefined if not available
21
+ */
22
+ getControl(rowIndex: number, field: string): AbstractControl | undefined;
23
+ /**
24
+ * Whether the grid is backed by a FormArray of FormGroups.
25
+ * When true, `getControl()` will return cell-level controls.
26
+ */
27
+ hasFormGroups: boolean;
28
+ /**
29
+ * Get the FormGroup for a specific row.
30
+ * Only available when using FormArray with FormGroup rows.
31
+ *
32
+ * @param rowIndex - The row index
33
+ * @returns The FormGroup for the row, or undefined if not available
34
+ */
35
+ getRowFormGroup(rowIndex: number): FormGroup | undefined;
36
+ /**
37
+ * Check if a row is valid (all controls in the FormGroup are valid).
38
+ * Returns true if not using FormArray or if the row doesn't exist.
39
+ *
40
+ * @param rowIndex - The row index
41
+ * @returns true if the row is valid, false if any control is invalid
42
+ */
43
+ isRowValid(rowIndex: number): boolean;
44
+ /**
45
+ * Check if a row has been touched (any control in the FormGroup is touched).
46
+ * Returns false if not using FormArray or if the row doesn't exist.
47
+ *
48
+ * @param rowIndex - The row index
49
+ * @returns true if any control in the row is touched
50
+ */
51
+ isRowTouched(rowIndex: number): boolean;
52
+ /**
53
+ * Check if a row is dirty (any control in the FormGroup is dirty).
54
+ * Returns false if not using FormArray or if the row doesn't exist.
55
+ *
56
+ * @param rowIndex - The row index
57
+ * @returns true if any control in the row is dirty
58
+ */
59
+ isRowDirty(rowIndex: number): boolean;
60
+ /**
61
+ * Get validation errors for a specific row.
62
+ * Aggregates errors from all controls in the FormGroup.
63
+ *
64
+ * @param rowIndex - The row index
65
+ * @returns Object with field names as keys and their errors, or null if no errors
66
+ */
67
+ getRowErrors(rowIndex: number): Record<string, unknown> | null;
68
+ }
69
+ /**
70
+ * Gets the FormArrayContext from a grid element, if present.
71
+ * @internal
72
+ */
73
+ export declare function getFormArrayContext(gridElement: HTMLElement): FormArrayContext | undefined;
74
+ /**
75
+ * Directive that binds a FormArray directly to the grid.
76
+ *
77
+ * This is the recommended way to integrate tbw-grid with Angular Reactive Forms.
78
+ * Use a FormArray of FormGroups for row-level validation and cell-level control access.
79
+ *
80
+ * ## Usage
81
+ *
82
+ * ```typescript
83
+ * import { Component, inject } from '@angular/core';
84
+ * import { FormBuilder, ReactiveFormsModule } from '@angular/forms';
85
+ * import { Grid, GridFormArray } from '@toolbox-web/grid-angular';
86
+ *
87
+ * @Component({
88
+ * imports: [Grid, GridFormArray, ReactiveFormsModule],
89
+ * template: \`
90
+ * <form [formGroup]="form">
91
+ * <tbw-grid [formArray]="form.controls.rows" [columns]="columns" />
92
+ * </form>
93
+ * \`
94
+ * })
95
+ * export class MyComponent {
96
+ * private fb = inject(FormBuilder);
97
+ *
98
+ * form = this.fb.group({
99
+ * rows: this.fb.array([
100
+ * this.fb.group({ name: 'Alice', age: 30 }),
101
+ * this.fb.group({ name: 'Bob', age: 25 }),
102
+ * ])
103
+ * });
104
+ *
105
+ * columns = [
106
+ * { field: 'name', header: 'Name', editable: true },
107
+ * { field: 'age', header: 'Age', editable: true }
108
+ * ];
109
+ * }
110
+ * ```
111
+ *
112
+ * ## How It Works
113
+ *
114
+ * - **FormArray → Grid**: The grid displays the FormArray's value as rows
115
+ * - **Grid → FormArray**: When a cell is edited, the corresponding FormControl is updated
116
+ * - FormArrayContext is available for accessing cell-level controls
117
+ *
118
+ * ## Features
119
+ *
120
+ * - Works naturally with FormArray inside a FormGroup
121
+ * - Provides cell-level FormControl access for validation
122
+ * - Supports row-level validation state aggregation
123
+ * - Automatically syncs FormArray changes to the grid
124
+ */
125
+ export declare class GridFormArray implements OnInit, OnDestroy {
126
+ #private;
127
+ private elementRef;
128
+ private cellCommitListener;
129
+ private touchListener;
130
+ /**
131
+ * The FormArray to bind to the grid.
132
+ */
133
+ readonly formArray: import('@angular/core').InputSignal<FormArray<any>>;
134
+ /**
135
+ * Effect that syncs the FormArray value to the grid rows.
136
+ */
137
+ private syncFormArrayToGrid;
138
+ ngOnInit(): void;
139
+ ngOnDestroy(): void;
140
+ }
141
+ //# sourceMappingURL=grid-form-array.directive.d.ts.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"grid-form-array.directive.d.ts","sourceRoot":"","sources":["../../../../../libs/grid-angular/src/lib/directives/grid-form-array.directive.ts"],"names":[],"mappings":"AAAA,OAAO,EAAgD,SAAS,EAAE,MAAM,EAAE,MAAM,eAAe,CAAC;AAChG,OAAO,EAAE,eAAe,EAAE,SAAS,EAAE,SAAS,EAAE,MAAM,gBAAgB,CAAC;AAGvE;;;GAGG;AACH,MAAM,WAAW,gBAAgB;IAC/B,2CAA2C;IAC3C,MAAM,CAAC,CAAC,GAAG,OAAO,EAAE,QAAQ,EAAE,MAAM,GAAG,CAAC,GAAG,IAAI,CAAC;IAChD,6CAA6C;IAC7C,WAAW,CAAC,QAAQ,EAAE,MAAM,EAAE,KAAK,EAAE,MAAM,EAAE,KAAK,EAAE,OAAO,GAAG,IAAI,CAAC;IACnE,4CAA4C;IAC5C,QAAQ,CAAC,CAAC,GAAG,OAAO,KAAK,CAAC,EAAE,CAAC;IAC7B;;;;;;;OAOG;IACH,UAAU,CAAC,QAAQ,EAAE,MAAM,EAAE,KAAK,EAAE,MAAM,GAAG,eAAe,GAAG,SAAS,CAAC;IACzE;;;OAGG;IACH,aAAa,EAAE,OAAO,CAAC;IACvB;;;;;;OAMG;IACH,eAAe,CAAC,QAAQ,EAAE,MAAM,GAAG,SAAS,GAAG,SAAS,CAAC;IACzD;;;;;;OAMG;IACH,UAAU,CAAC,QAAQ,EAAE,MAAM,GAAG,OAAO,CAAC;IACtC;;;;;;OAMG;IACH,YAAY,CAAC,QAAQ,EAAE,MAAM,GAAG,OAAO,CAAC;IACxC;;;;;;OAMG;IACH,UAAU,CAAC,QAAQ,EAAE,MAAM,GAAG,OAAO,CAAC;IACtC;;;;;;OAMG;IACH,YAAY,CAAC,QAAQ,EAAE,MAAM,GAAG,MAAM,CAAC,MAAM,EAAE,OAAO,CAAC,GAAG,IAAI,CAAC;CAChE;AAKD;;;GAGG;AACH,wBAAgB,mBAAmB,CAAC,WAAW,EAAE,WAAW,GAAG,gBAAgB,GAAG,SAAS,CAE1F;AAED;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;GAkDG;AACH,qBAGa,aAAc,YAAW,MAAM,EAAE,SAAS;;IACrD,OAAO,CAAC,UAAU,CAAmC;IACrD,OAAO,CAAC,kBAAkB,CAAqC;IAC/D,OAAO,CAAC,aAAa,CAAqC;IAE1D;;OAEG;IACH,QAAQ,CAAC,SAAS,sDAA+B;IAEjD;;OAEG;IACH,OAAO,CAAC,mBAAmB,CAOxB;IAEH,QAAQ,IAAI,IAAI;IA0BhB,WAAW,IAAI,IAAI;CAgIpB"}
@@ -1,6 +1,8 @@
1
1
  export { GridColumnEditor } from './grid-column-editor.directive';
2
2
  export { GridColumnView } from './grid-column-view.directive';
3
3
  export { GridDetailView } from './grid-detail-view.directive';
4
+ export { getFormArrayContext, GridFormArray } from './grid-form-array.directive';
5
+ export type { FormArrayContext } from './grid-form-array.directive';
4
6
  export { GridResponsiveCard } from './grid-responsive-card.directive';
5
7
  export { GridToolPanel } from './grid-tool-panel.directive';
6
8
  export { Grid } from './grid.directive';
@@ -1 +1 @@
1
- {"version":3,"file":"index.d.ts","sourceRoot":"","sources":["../../../../../libs/grid-angular/src/lib/directives/index.ts"],"names":[],"mappings":"AAAA,OAAO,EAAE,gBAAgB,EAAE,MAAM,gCAAgC,CAAC;AAClE,OAAO,EAAE,cAAc,EAAE,MAAM,8BAA8B,CAAC;AAC9D,OAAO,EAAE,cAAc,EAAE,MAAM,8BAA8B,CAAC;AAC9D,OAAO,EAAE,kBAAkB,EAAE,MAAM,kCAAkC,CAAC;AACtE,OAAO,EAAE,aAAa,EAAE,MAAM,6BAA6B,CAAC;AAC5D,OAAO,EAAE,IAAI,EAAE,MAAM,kBAAkB,CAAC"}
1
+ {"version":3,"file":"index.d.ts","sourceRoot":"","sources":["../../../../../libs/grid-angular/src/lib/directives/index.ts"],"names":[],"mappings":"AAAA,OAAO,EAAE,gBAAgB,EAAE,MAAM,gCAAgC,CAAC;AAClE,OAAO,EAAE,cAAc,EAAE,MAAM,8BAA8B,CAAC;AAC9D,OAAO,EAAE,cAAc,EAAE,MAAM,8BAA8B,CAAC;AAC9D,OAAO,EAAE,mBAAmB,EAAE,aAAa,EAAE,MAAM,6BAA6B,CAAC;AACjF,YAAY,EAAE,gBAAgB,EAAE,MAAM,6BAA6B,CAAC;AACpE,OAAO,EAAE,kBAAkB,EAAE,MAAM,kCAAkC,CAAC;AACtE,OAAO,EAAE,aAAa,EAAE,MAAM,6BAA6B,CAAC;AAC5D,OAAO,EAAE,IAAI,EAAE,MAAM,kBAAkB,CAAC"}
@@ -1,4 +1,5 @@
1
1
  import { OnDestroy, TemplateRef } from '@angular/core';
2
+ import { AbstractControl } from '@angular/forms';
2
3
  /**
3
4
  * Context type for structural directives with `any` defaults.
4
5
  * This provides better ergonomics in templates without requiring explicit type annotations.
@@ -38,6 +39,15 @@ export interface StructuralEditorContext<TValue = any, TRow = any> {
38
39
  * Callback function to cancel editing.
39
40
  */
40
41
  onCancel: () => void;
42
+ /**
43
+ * The FormControl for this cell, if the grid is bound to a FormArray with FormGroups.
44
+ *
45
+ * Returns `undefined` if:
46
+ * - The grid is not bound to a FormArray
47
+ * - The FormArray doesn't contain FormGroups
48
+ * - The field doesn't exist in the FormGroup
49
+ */
50
+ control?: AbstractControl;
41
51
  }
42
52
  /**
43
53
  * Gets the view template registered by the structural directive for a given column element.
@@ -1 +1 @@
1
- {"version":3,"file":"structural-directives.d.ts","sourceRoot":"","sources":["../../../../../libs/grid-angular/src/lib/directives/structural-directives.ts"],"names":[],"mappings":"AAAA,OAAO,EAAyC,SAAS,EAAE,WAAW,EAAE,MAAM,eAAe,CAAC;AAI9F;;;;;GAKG;AAEH,MAAM,WAAW,qBAAqB,CAAC,MAAM,GAAG,GAAG,EAAE,IAAI,GAAG,GAAG;IAC7D,qCAAqC;IACrC,SAAS,EAAE,MAAM,CAAC;IAClB,wCAAwC;IACxC,KAAK,EAAE,MAAM,CAAC;IACd,+BAA+B;IAC/B,GAAG,EAAE,IAAI,CAAC;IACV,+BAA+B;IAE/B,MAAM,EAAE,GAAG,CAAC;CACb;AAED;;;;;GAKG;AAEH,MAAM,WAAW,uBAAuB,CAAC,MAAM,GAAG,GAAG,EAAE,IAAI,GAAG,GAAG;IAC/D,qCAAqC;IACrC,SAAS,EAAE,MAAM,CAAC;IAClB,wCAAwC;IACxC,KAAK,EAAE,MAAM,CAAC;IACd,+BAA+B;IAC/B,GAAG,EAAE,IAAI,CAAC;IACV,+BAA+B;IAE/B,MAAM,EAAE,GAAG,CAAC;IACZ;;OAEG;IACH,QAAQ,EAAE,CAAC,KAAK,EAAE,MAAM,KAAK,IAAI,CAAC;IAClC;;OAEG;IACH,QAAQ,EAAE,MAAM,IAAI,CAAC;CACtB;AAMD;;;GAGG;AACH,wBAAgB,yBAAyB,CAAC,aAAa,EAAE,WAAW,GAAG,WAAW,CAAC,qBAAqB,CAAC,GAAG,SAAS,CAWpH;AAED;;;GAGG;AACH,wBAAgB,2BAA2B,CACzC,aAAa,EAAE,WAAW,GACzB,WAAW,CAAC,uBAAuB,CAAC,GAAG,SAAS,CAWlD;AAED;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;GAyCG;AACH,qBACa,WAAY,YAAW,SAAS;IAC3C,OAAO,CAAC,QAAQ,CAA8C;IAC9D,OAAO,CAAC,UAAU,CAAmC;IACrD,OAAO,CAAC,aAAa,CAA4B;;IAWjD,OAAO,CAAC,gBAAgB;IAcxB,WAAW,IAAI,IAAI;IAMnB;;;OAGG;IACH,MAAM,CAAC,sBAAsB,CAAC,GAAG,EAAE,WAAW,EAAE,GAAG,EAAE,OAAO,GAAG,GAAG,IAAI,qBAAqB;CAG5F;AAED;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;GA2CG;AACH,qBACa,SAAU,YAAW,SAAS;IACzC,OAAO,CAAC,QAAQ,CAAgD;IAChE,OAAO,CAAC,UAAU,CAAmC;IACrD,OAAO,CAAC,aAAa,CAA4B;;IAQjD,OAAO,CAAC,gBAAgB;IAaxB,WAAW,IAAI,IAAI;IAMnB;;;OAGG;IACH,MAAM,CAAC,sBAAsB,CAAC,GAAG,EAAE,SAAS,EAAE,GAAG,EAAE,OAAO,GAAG,GAAG,IAAI,uBAAuB;CAG5F"}
1
+ {"version":3,"file":"structural-directives.d.ts","sourceRoot":"","sources":["../../../../../libs/grid-angular/src/lib/directives/structural-directives.ts"],"names":[],"mappings":"AAAA,OAAO,EAAyC,SAAS,EAAE,WAAW,EAAE,MAAM,eAAe,CAAC;AAC9F,OAAO,KAAK,EAAE,eAAe,EAAE,MAAM,gBAAgB,CAAC;AAItD;;;;;GAKG;AAEH,MAAM,WAAW,qBAAqB,CAAC,MAAM,GAAG,GAAG,EAAE,IAAI,GAAG,GAAG;IAC7D,qCAAqC;IACrC,SAAS,EAAE,MAAM,CAAC;IAClB,wCAAwC;IACxC,KAAK,EAAE,MAAM,CAAC;IACd,+BAA+B;IAC/B,GAAG,EAAE,IAAI,CAAC;IACV,+BAA+B;IAE/B,MAAM,EAAE,GAAG,CAAC;CACb;AAED;;;;;GAKG;AAEH,MAAM,WAAW,uBAAuB,CAAC,MAAM,GAAG,GAAG,EAAE,IAAI,GAAG,GAAG;I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AC,GAAG,EAAE,SAAS,EAAE,GAAG,EAAE,OAAO,GAAG,GAAG,IAAI,uBAAuB;CAG5F"}
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@toolbox-web/grid-angular",
3
- "version": "0.4.0",
3
+ "version": "0.5.0",
4
4
  "description": "Angular adapter for @toolbox-web/grid data grid component",
5
5
  "type": "module",
6
6
  "main": "./index.js",
@@ -48,6 +48,6 @@
48
48
  },
49
49
  "peerDependencies": {
50
50
  "@angular/core": ">=17.0.0",
51
- "@toolbox-web/grid": ">=0.4.0"
51
+ "@toolbox-web/grid": ">=1.0.0"
52
52
  }
53
53
  }