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