| 48 | }, |
| 49 | }) |
| 50 | export class GridCellWidget { |
| 51 | /** A reference to the host element. */ |
| 52 | private readonly _elementRef = inject(ElementRef); |
| 53 | |
| 54 | /** A reference to the host element. */ |
| 55 | readonly element = this._elementRef.nativeElement as HTMLElement; |
| 56 | |
| 57 | /** Whether the widget is currently active (focused). */ |
| 58 | readonly active = computed(() => this._pattern.active()); |
| 59 | |
| 60 | /** The parent cell. */ |
| 61 | private readonly _cell = inject(GRID_CELL); |
| 62 | |
| 63 | /** A unique identifier for the widget. */ |
| 64 | readonly id = input(inject(_IdGenerator).getId('ng-grid-cell-widget-', true)); |
| 65 | |
| 66 | /** The type of widget, which determines how it is activated. */ |
| 67 | readonly widgetType = input<'simple' | 'complex' | 'editable'>('simple'); |
| 68 | |
| 69 | /** Whether the widget is disabled. */ |
| 70 | readonly disabled = input(false, {transform: booleanAttribute}); |
| 71 | |
| 72 | /** The target that will receive focus instead of the widget. */ |
| 73 | readonly focusTarget = input<ElementResolver<HTMLElement>>(); |
| 74 | |
| 75 | /** Emits when the widget is activated. */ |
| 76 | readonly activated = output<KeyboardEvent | FocusEvent | undefined>(); |
| 77 | |
| 78 | /** Emits when the widget is deactivated. */ |
| 79 | readonly deactivated = output<KeyboardEvent | FocusEvent | undefined>(); |
| 80 | |
| 81 | /** The tabindex override. */ |
| 82 | readonly tabindex = input<number | undefined>(); |
| 83 | |
| 84 | /** |
| 85 | * The tabindex value set to the element. |
| 86 | * If a focus target exists then return -1. Unless an override. |
| 87 | */ |
| 88 | protected readonly _tabIndex: Signal<number> = computed( |
| 89 | () => this.tabindex() ?? this._pattern.tabIndex(), |
| 90 | ); |
| 91 | |
| 92 | /** The UI pattern for the grid cell widget. */ |
| 93 | readonly _pattern = new GridCellWidgetPattern({ |
| 94 | ...this, |
| 95 | element: () => this.element, |
| 96 | cell: () => this._cell._pattern, |
| 97 | onActivate: e => this.activated.emit(e), |
| 98 | onDeactivate: e => this.deactivated.emit(e), |
| 99 | }); |
| 100 | |
| 101 | /** Whether the widget is activated. */ |
| 102 | get isActivated(): Signal<boolean> { |
| 103 | return computed(() => this._pattern.isActivated()); |
| 104 | } |
| 105 | |
| 106 | constructor() { |
| 107 | afterRenderEffect({ |