@basis-ng/primitives 0.0.1-alpha.28 → 0.0.1-alpha.29

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.
@@ -0,0 +1,11 @@
1
+ import { CdkOption } from '@angular/cdk/listbox';
2
+ import * as i0 from "@angular/core";
3
+ import * as i1 from "@angular/cdk/listbox";
4
+ export declare class TabComponent {
5
+ /**
6
+ * Reference to the injected CDK Option instance.
7
+ */
8
+ cdkOption: CdkOption<any>;
9
+ static ɵfac: i0.ɵɵFactoryDeclaration<TabComponent, never>;
10
+ static ɵcmp: i0.ɵɵComponentDeclaration<TabComponent, "b-tab", never, {}, {}, never, ["*"], true, [{ directive: typeof i1.CdkOption; inputs: { "cdkOption": "value"; }; outputs: {}; }]>;
11
+ }
@@ -1,60 +1,29 @@
1
- import { Tab } from './components/tab/tab.component';
1
+ import { ActiveDescendantKeyManager } from '@angular/cdk/a11y';
2
+ import { CdkListbox } from '@angular/cdk/listbox';
3
+ import { OnInit } from '@angular/core';
4
+ import { TabComponent } from './tab.component';
2
5
  import * as i0 from "@angular/core";
3
- export declare class Tabs {
4
- readonly tabs: import("@angular/core").Signal<readonly Tab[]>;
5
- readonly selectedIndex: import("@angular/core").WritableSignal<number>;
6
- readonly selectedValue: import("@angular/core").ModelSignal<string | null>;
7
- readonly highlightedIndex: import("@angular/core").WritableSignal<number>;
8
- changesEmitter: import("@angular/core").OutputEmitterRef<string>;
9
- lastSelectedValue: string | null;
10
- constructor();
6
+ import * as i1 from "@angular/cdk/listbox";
7
+ export declare class TabsComponent implements OnInit {
11
8
  /**
12
- * Handle the selection of a tab.
9
+ * Reference to the injected CDK Listbox instance.
13
10
  */
14
- handleTabSelection(): void;
11
+ cdkListbox: CdkListbox<any>;
15
12
  /**
16
- * Select a tab.
17
- * @param {Tab} tab - The tab to select.
18
- * @param {number} index - The index of the tab.
13
+ * Collection of child options within the listbox.
19
14
  */
20
- selectTab(tab: Tab, index: number): void;
15
+ readonly tabs: import("@angular/core").Signal<readonly TabComponent[]>;
21
16
  /**
22
- * Highlight a tab.
23
- * @param {number} index - The index of the tab to highlight.
17
+ * Collection of cdk options within the listbox.
24
18
  */
25
- highlightTab(index: number): void;
19
+ readonly cdkOptions: import("@angular/core").Signal<import("@angular/cdk/listbox").CdkOption<any>[]>;
26
20
  /**
27
- * Handle the states of the tabs.
21
+ * Key manager for handling keyboard navigation and active descendant management.
28
22
  */
29
- handleTabStates(): void;
30
- /**
31
- * Handle the external selected value.
32
- */
33
- handleExternalSelectedValue(): void;
34
- /**
35
- * Scroll to the selected tab.
36
- */
37
- handleScrollToSelectedTab(): void;
38
- /**
39
- * Handle keyboard events for navigation and selection.
40
- * @param {KeyboardEvent} event - The keyboard event.
41
- */
42
- handleKeyboard(event: KeyboardEvent): void;
43
- /**
44
- * Focus on the next or previous tab.
45
- * @param {'next' | 'previous'} direction - The direction to move the focus.
46
- */
47
- focusOption(direction: 'next' | 'previous'): void;
48
- /**
49
- * Select the currently focused tab.
50
- */
51
- selectFocusedTab(): void;
52
- /**
53
- * Scroll to a specific tab.
54
- * @param {number} index - The index of the tab to scroll to.
55
- * @param {string} behavior - The scroll behavior ('instant' or 'smooth').
56
- */
57
- scrollToTab(index: number, behavior: string): void;
58
- static ɵfac: i0.ɵɵFactoryDeclaration<Tabs, never>;
59
- static ɵcmp: i0.ɵɵComponentDeclaration<Tabs, "b-tabs", never, { "selectedValue": { "alias": "selectedValue"; "required": false; "isSignal": true; }; }, { "selectedValue": "selectedValueChange"; "changesEmitter": "changesEmitter"; }, ["tabs"], ["*"], true, never>;
23
+ readonly listKeyManager: import("@angular/core").Signal<ActiveDescendantKeyManager<import("@angular/cdk/listbox").CdkOption<any>>>;
24
+ previousTab(): void;
25
+ nextTab(): void;
26
+ ngOnInit(): void;
27
+ static ɵfac: i0.ɵɵFactoryDeclaration<TabsComponent, never>;
28
+ static ɵcmp: i0.ɵɵComponentDeclaration<TabsComponent, "b-tabs", never, {}, {}, ["tabs"], ["*"], true, [{ directive: typeof i1.CdkListbox; inputs: { "cdkListboxValue": "value"; }; outputs: { "cdkListboxValueChange": "cdkListboxValueChange"; }; }]>;
60
29
  }
@@ -8,11 +8,11 @@ import { icons, createElement } from 'lucide';
8
8
  import * as i1$1 from '@angular/cdk/overlay';
9
9
  import { CdkOverlayOrigin, CdkConnectedOverlay } from '@angular/cdk/overlay';
10
10
  import { NgStyle, NgClass, CommonModule } from '@angular/common';
11
+ import { ActiveDescendantKeyManager, CdkTrapFocus } from '@angular/cdk/a11y';
11
12
  import * as i1$2 from '@angular/cdk/drag-drop';
12
13
  import { CdkDrag, CdkDragHandle, CdkDropList, CdkDropListGroup } from '@angular/cdk/drag-drop';
13
14
  import * as i1$3 from '@angular/cdk/menu';
14
15
  import { CdkMenu, CdkMenuItem, CdkMenuGroup, CdkMenuItemCheckbox, CdkMenuItemRadio, CdkMenuTrigger } from '@angular/cdk/menu';
15
- import { ActiveDescendantKeyManager, CdkTrapFocus } from '@angular/cdk/a11y';
16
16
  import { BreakpointObserver, Breakpoints } from '@angular/cdk/layout';
17
17
 
18
18
  class ThemeService {
@@ -1011,192 +1011,83 @@ i0.ɵɵngDeclareClassMetadata({ minVersion: "12.0.0", version: "19.2.7", ngImpor
1011
1011
  args: [{ selector: 'b-row-item', imports: [NgStyle], template: "<div [ngStyle]=\"style()\" class=\"row-item-container\">\r\n <ng-content />\r\n</div>\r\n" }]
1012
1012
  }] });
1013
1013
 
1014
- class Tab {
1015
- el;
1016
- value = input.required();
1017
- disabled = input(false);
1018
- selected = signal(false);
1019
- highlighted = signal(false);
1020
- selectEmitter = output();
1021
- constructor(el) {
1022
- this.el = el;
1023
- }
1024
- /**
1025
- * Emit the select event when the tab is selected.
1026
- */
1027
- onSelect() {
1028
- this.selectEmitter.emit(this);
1029
- }
1014
+ class TabComponent {
1030
1015
  /**
1031
- * Highlight the tab on mouse enter if it is not disabled and not in keyboard-active mode.
1016
+ * Reference to the injected CDK Option instance.
1032
1017
  */
1033
- onMouseEnter() {
1034
- if (!this.disabled() &&
1035
- !this.el.nativeElement.parentElement.parentElement.classList.contains('keyboard-active')) {
1036
- this.highlighted.set(true);
1037
- }
1038
- }
1039
- /**
1040
- * Remove the highlight from the tab on mouse leave if it is not disabled and not in keyboard-active mode.
1041
- */
1042
- onMouseLeave() {
1043
- if (!this.disabled() &&
1044
- !this.el.nativeElement.parentElement.parentElement.classList.contains('keyboard-active')) {
1045
- this.highlighted.set(false);
1046
- }
1047
- }
1048
- static ɵfac = i0.ɵɵngDeclareFactory({ minVersion: "12.0.0", version: "19.2.7", ngImport: i0, type: Tab, deps: [{ token: i0.ElementRef }], target: i0.ɵɵFactoryTarget.Component });
1049
- static ɵcmp = i0.ɵɵngDeclareComponent({ minVersion: "17.1.0", version: "19.2.7", type: Tab, isStandalone: true, selector: "b-tab", inputs: { value: { classPropertyName: "value", publicName: "value", isSignal: true, isRequired: true, transformFunction: null }, disabled: { classPropertyName: "disabled", publicName: "disabled", isSignal: true, isRequired: false, transformFunction: null } }, outputs: { selectEmitter: "selectEmitter" }, ngImport: i0, template: "<span\r\n tabindex=\"0\"\r\n (click)=\"onSelect()\"\r\n (keydown.enter)=\"onSelect()\"\r\n (mouseenter)=\"onMouseEnter()\"\r\n (mouseleave)=\"onMouseLeave()\"\r\n [ngClass]=\"{ selected: selected(), highlighted: highlighted() }\">\r\n <ng-content\r\n/></span>\r\n", dependencies: [{ kind: "directive", type: NgClass, selector: "[ngClass]", inputs: ["class", "ngClass"] }] });
1018
+ cdkOption = inject(CdkOption);
1019
+ static ɵfac = i0.ɵɵngDeclareFactory({ minVersion: "12.0.0", version: "19.2.7", ngImport: i0, type: TabComponent, deps: [], target: i0.ɵɵFactoryTarget.Component });
1020
+ static ɵcmp = i0.ɵɵngDeclareComponent({ minVersion: "14.0.0", version: "19.2.7", type: TabComponent, isStandalone: true, selector: "b-tab", hostDirectives: [{ directive: i1.CdkOption, inputs: ["cdkOption", "value"] }], ngImport: i0, template: `<ng-content />`, isInline: true });
1050
1021
  }
1051
- i0.ɵɵngDeclareClassMetadata({ minVersion: "12.0.0", version: "19.2.7", ngImport: i0, type: Tab, decorators: [{
1022
+ i0.ɵɵngDeclareClassMetadata({ minVersion: "12.0.0", version: "19.2.7", ngImport: i0, type: TabComponent, decorators: [{
1052
1023
  type: Component,
1053
- args: [{ selector: 'b-tab', imports: [NgClass], template: "<span\r\n tabindex=\"0\"\r\n (click)=\"onSelect()\"\r\n (keydown.enter)=\"onSelect()\"\r\n (mouseenter)=\"onMouseEnter()\"\r\n (mouseleave)=\"onMouseLeave()\"\r\n [ngClass]=\"{ selected: selected(), highlighted: highlighted() }\">\r\n <ng-content\r\n/></span>\r\n" }]
1054
- }], ctorParameters: () => [{ type: i0.ElementRef }] });
1024
+ args: [{
1025
+ selector: 'b-tab',
1026
+ imports: [],
1027
+ template: `<ng-content />`,
1028
+ hostDirectives: [
1029
+ {
1030
+ directive: CdkOption,
1031
+ inputs: ['cdkOption: value'],
1032
+ },
1033
+ ],
1034
+ }]
1035
+ }] });
1055
1036
 
1056
- class Tabs {
1057
- tabs = contentChildren(Tab);
1058
- selectedIndex = signal(-1);
1059
- selectedValue = model(null);
1060
- highlightedIndex = signal(-1);
1061
- changesEmitter = output();
1062
- lastSelectedValue = null;
1063
- constructor() {
1064
- effect(() => {
1065
- this.handleTabSelection();
1066
- this.handleExternalSelectedValue();
1067
- this.handleScrollToSelectedTab();
1068
- });
1069
- }
1070
- /**
1071
- * Handle the selection of a tab.
1072
- */
1073
- handleTabSelection() {
1074
- this.tabs().forEach((tab, index) => {
1075
- tab.selectEmitter.subscribe(tabEmitted => {
1076
- this.selectTab(tabEmitted, index);
1077
- this.highlightTab(index);
1078
- this.handleTabStates();
1079
- this.changesEmitter.emit(tab.value());
1080
- });
1081
- });
1082
- }
1083
- /**
1084
- * Select a tab.
1085
- * @param {Tab} tab - The tab to select.
1086
- * @param {number} index - The index of the tab.
1087
- */
1088
- selectTab(tab, index) {
1089
- this.selectedValue.set(tab.value());
1090
- this.lastSelectedValue = tab.value();
1091
- this.selectedIndex.set(index);
1092
- }
1037
+ class TabsComponent {
1093
1038
  /**
1094
- * Highlight a tab.
1095
- * @param {number} index - The index of the tab to highlight.
1096
- */
1097
- highlightTab(index) {
1098
- this.highlightedIndex.set(index);
1099
- }
1100
- /**
1101
- * Handle the states of the tabs.
1039
+ * Reference to the injected CDK Listbox instance.
1102
1040
  */
1103
- handleTabStates() {
1104
- this.tabs().forEach((tab, index) => {
1105
- tab.selected.set(index === this.selectedIndex());
1106
- tab.highlighted.set(index === this.highlightedIndex());
1107
- });
1108
- }
1041
+ cdkListbox = inject(CdkListbox);
1109
1042
  /**
1110
- * Handle the external selected value.
1043
+ * Collection of child options within the listbox.
1111
1044
  */
1112
- handleExternalSelectedValue() {
1113
- if (this.lastSelectedValue !== this.selectedValue()) {
1114
- const selectedOptionIndex = this.tabs().findIndex(tab => tab.value() === this.selectedValue());
1115
- if (selectedOptionIndex !== -1) {
1116
- this.selectTab(this.tabs()[selectedOptionIndex], selectedOptionIndex);
1117
- this.highlightTab(selectedOptionIndex);
1118
- this.handleTabStates();
1119
- }
1120
- }
1121
- }
1045
+ tabs = contentChildren(TabComponent);
1122
1046
  /**
1123
- * Scroll to the selected tab.
1047
+ * Collection of cdk options within the listbox.
1124
1048
  */
1125
- handleScrollToSelectedTab() {
1126
- if (this.selectedIndex() !== -1) {
1127
- this.scrollToTab(this.selectedIndex(), 'smooth');
1128
- }
1129
- }
1130
- /**
1131
- * Handle keyboard events for navigation and selection.
1132
- * @param {KeyboardEvent} event - The keyboard event.
1133
- */
1134
- handleKeyboard(event) {
1135
- switch (event.key) {
1136
- case 'ArrowRight':
1137
- event.preventDefault();
1138
- this.focusOption('next');
1139
- break;
1140
- case 'ArrowLeft':
1141
- event.preventDefault();
1142
- this.focusOption('previous');
1143
- break;
1144
- case 'Enter':
1145
- event.preventDefault();
1146
- this.selectFocusedTab();
1147
- break;
1148
- }
1149
- }
1049
+ cdkOptions = computed(() => this.tabs().map(tab => tab.cdkOption));
1150
1050
  /**
1151
- * Focus on the next or previous tab.
1152
- * @param {'next' | 'previous'} direction - The direction to move the focus.
1051
+ * Key manager for handling keyboard navigation and active descendant management.
1153
1052
  */
1154
- focusOption(direction) {
1155
- let index = this.highlightedIndex();
1156
- const increment = direction === 'next' ? 1 : -1;
1157
- index += increment;
1158
- while (index >= 0 &&
1159
- index < this.tabs().length &&
1160
- this.tabs()[index].disabled()) {
1161
- index += increment;
1162
- }
1163
- if (index >= 0 && index < this.tabs().length) {
1164
- this.highlightTab(index);
1165
- this.handleTabStates();
1166
- this.scrollToTab(this.highlightedIndex(), 'smooth');
1167
- }
1053
+ listKeyManager = computed(() => new ActiveDescendantKeyManager(this.cdkOptions())
1054
+ .withWrap()
1055
+ .withHorizontalOrientation('ltr'));
1056
+ previousTab() {
1057
+ this.listKeyManager().setPreviousItemActive();
1058
+ this.cdkListbox.value = this.listKeyManager().activeItem?.value;
1168
1059
  }
1169
- /**
1170
- * Select the currently focused tab.
1171
- */
1172
- selectFocusedTab() {
1173
- this.selectTab(this.tabs()[this.highlightedIndex()], this.highlightedIndex());
1174
- this.handleTabStates();
1060
+ nextTab() {
1061
+ this.listKeyManager().setNextItemActive();
1062
+ this.cdkListbox.value = this.listKeyManager().activeItem?.value;
1175
1063
  }
1176
- /**
1177
- * Scroll to a specific tab.
1178
- * @param {number} index - The index of the tab to scroll to.
1179
- * @param {string} behavior - The scroll behavior ('instant' or 'smooth').
1180
- */
1181
- scrollToTab(index, behavior) {
1182
- const tabsElements = this.tabs();
1183
- if (tabsElements[index].el.nativeElement) {
1184
- tabsElements[index].el.nativeElement.scrollIntoView({
1185
- block: 'nearest',
1186
- behavior: behavior,
1187
- });
1188
- }
1064
+ ngOnInit() {
1065
+ this.cdkListbox.useActiveDescendant = true;
1066
+ this.cdkListbox.orientation = 'horizontal';
1189
1067
  }
1190
- static ɵfac = i0.ɵɵngDeclareFactory({ minVersion: "12.0.0", version: "19.2.7", ngImport: i0, type: Tabs, deps: [], target: i0.ɵɵFactoryTarget.Component });
1191
- static ɵcmp = i0.ɵɵngDeclareComponent({ minVersion: "17.2.0", version: "19.2.7", type: Tabs, isStandalone: true, selector: "b-tabs", inputs: { selectedValue: { classPropertyName: "selectedValue", publicName: "selectedValue", isSignal: true, isRequired: false, transformFunction: null } }, outputs: { selectedValue: "selectedValueChange", changesEmitter: "changesEmitter" }, host: { listeners: { "keydown": "handleKeyboard($event)" } }, queries: [{ propertyName: "tabs", predicate: Tab, isSignal: true }], ngImport: i0, template: "<div class=\"tabs\" [tabIndex]=\"0\">\r\n <ng-content />\r\n</div>\r\n" });
1068
+ static ɵfac = i0.ɵɵngDeclareFactory({ minVersion: "12.0.0", version: "19.2.7", ngImport: i0, type: TabsComponent, deps: [], target: i0.ɵɵFactoryTarget.Component });
1069
+ static ɵcmp = i0.ɵɵngDeclareComponent({ minVersion: "17.2.0", version: "19.2.7", type: TabsComponent, isStandalone: true, selector: "b-tabs", host: { listeners: { "cdkListboxValueChange": "selectOption($event.value)", "keydown.arrowLeft": "previousTab()", "keydown.arrowRight": "nextTab()" } }, queries: [{ propertyName: "tabs", predicate: TabComponent, isSignal: true }], hostDirectives: [{ directive: i1.CdkListbox, inputs: ["cdkListboxValue", "value"], outputs: ["cdkListboxValueChange", "cdkListboxValueChange"] }], ngImport: i0, template: `<ng-content />`, isInline: true });
1192
1070
  }
1193
- i0.ɵɵngDeclareClassMetadata({ minVersion: "12.0.0", version: "19.2.7", ngImport: i0, type: Tabs, decorators: [{
1071
+ i0.ɵɵngDeclareClassMetadata({ minVersion: "12.0.0", version: "19.2.7", ngImport: i0, type: TabsComponent, decorators: [{
1194
1072
  type: Component,
1195
- args: [{ selector: 'b-tabs', template: "<div class=\"tabs\" [tabIndex]=\"0\">\r\n <ng-content />\r\n</div>\r\n" }]
1196
- }], ctorParameters: () => [], propDecorators: { handleKeyboard: [{
1197
- type: HostListener,
1198
- args: ['keydown', ['$event']]
1199
- }] } });
1073
+ args: [{
1074
+ selector: 'b-tabs',
1075
+ imports: [],
1076
+ template: `<ng-content />`,
1077
+ hostDirectives: [
1078
+ {
1079
+ directive: CdkListbox,
1080
+ inputs: ['cdkListboxValue: value'],
1081
+ outputs: ['cdkListboxValueChange'],
1082
+ },
1083
+ ],
1084
+ host: {
1085
+ '(cdkListboxValueChange)': 'selectOption($event.value)',
1086
+ '(keydown.arrowLeft)': 'previousTab()',
1087
+ '(keydown.arrowRight)': 'nextTab()',
1088
+ },
1089
+ }]
1090
+ }] });
1200
1091
 
1201
1092
  class InViewportService {
1202
1093
  elements = signal({});
@@ -3056,5 +2947,5 @@ i0.ɵɵngDeclareClassMetadata({ minVersion: "12.0.0", version: "19.2.7", ngImpor
3056
2947
  * Generated bundle index. Do not edit.
3057
2948
  */
3058
2949
 
3059
- export { Alert, AttachedBox, Badge, BottomSheet, Button, ButtonGroup, Checkbox, ColorPicker, ComboboxComponent, CommandComponent, CommandOptionsComponent, Icon, InViewportDirective, InViewportService, Input, InputGroup, LazyContentDirective, Menu, MenuGroupComponent, MenuItemCheckboxComponent, MenuItemComponent, MenuItemRadioComponent, MenuLabel, MenuTrigger, OptionComponent, OverlayDirective, OverlayTriggerDirective, Range, ResponsiveService, Row, RowItem, SelectComponent, SelectOptionsComponent, SideSheet, Spinner, Switch, Tab, Table, Tabs, Textarea, ThemeService, TooltipComponent, Tree, TreeNode };
2950
+ export { Alert, AttachedBox, Badge, BottomSheet, Button, ButtonGroup, Checkbox, ColorPicker, ComboboxComponent, CommandComponent, CommandOptionsComponent, Icon, InViewportDirective, InViewportService, Input, InputGroup, LazyContentDirective, Menu, MenuGroupComponent, MenuItemCheckboxComponent, MenuItemComponent, MenuItemRadioComponent, MenuLabel, MenuTrigger, OptionComponent, OverlayDirective, OverlayTriggerDirective, Range, ResponsiveService, Row, RowItem, SelectComponent, SelectOptionsComponent, SideSheet, Spinner, Switch, TabComponent, Table, TabsComponent, Textarea, ThemeService, TooltipComponent, Tree, TreeNode };
3060
2951
  //# sourceMappingURL=basis-ng-primitives.mjs.map