@basis-ng/primitives 0.0.1-alpha.74 → 0.0.1-alpha.76

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.
@@ -9,47 +9,30 @@ import * as i1 from "@angular/cdk/listbox";
9
9
  */
10
10
  export declare class SelectOptionsComponent {
11
11
  /**
12
- * Signal representing the selected values in the listbox.
13
- * This is an array of strings corresponding to the selected option values.
12
+ * Whether multiple selection is enabled.
14
13
  */
15
- readonly value: import("@angular/core").WritableSignal<string[]>;
14
+ readonly multiple: import("@angular/core").InputSignal<boolean>;
16
15
  /**
17
- * Event emitter triggered when the dropdown should close.
18
- * This is used to notify the parent component to close the dropdown.
16
+ * Signal representing the selected value(s).
17
+ * - If `multiple` is true: string[]
18
+ * - If `multiple` is false: string | null
19
19
  */
20
- closeEmitter: import("@angular/core").OutputEmitterRef<void>;
20
+ readonly value: import("@angular/core").WritableSignal<string | string[] | null>;
21
21
  /**
22
- * Reference to the host element of the component.
23
- * This provides access to the DOM element of the options list.
22
+ * Event emitter triggered when the dropdown should close.
24
23
  */
24
+ closeEmitter: import("@angular/core").OutputEmitterRef<void>;
25
25
  el: ElementRef<any>;
26
- /**
27
- * Input for setting the maximum height of the dropdown.
28
- * Defaults to '300px'. This controls the vertical size of the dropdown.
29
- */
26
+ listBox: CdkListbox<any>;
30
27
  readonly maxHeight: import("@angular/core").InputSignal<string>;
31
- /**
32
- * No options message displayed when there are no available options in the dropdown.
33
- */
34
28
  readonly noOptionsMessage: import("@angular/core").InputSignal<string>;
35
- /**
36
- * Reference to the CDK Listbox directive.
37
- * This is used to manage the options and their selection state.
38
- */
39
- listBox: CdkListbox<any>;
40
- /**
41
- * Reference to the list of options in the dropdown.
42
- * This is a collection of `OptionComponent` instances representing the available options.
43
- */
44
29
  readonly options: import("@angular/core").Signal<readonly OptionComponent[]>;
45
30
  /**
46
31
  * Handles changes to the selected value in the listbox.
47
- * This method updates the `value` signal, emits the `closeEmitter` event,
48
- * and ensures the parent component is notified of the selection change.
49
32
  *
50
- * @param value - The new array of selected values.
33
+ * @param valueArray - The new array of selected values from the CDK listbox.
51
34
  */
52
- handleValueChange(value: string[]): void;
35
+ handleValueChange(valueArray: string[]): void;
53
36
  static ɵfac: i0.ɵɵFactoryDeclaration<SelectOptionsComponent, never>;
54
- static ɵcmp: i0.ɵɵComponentDeclaration<SelectOptionsComponent, "ul[b-select-options]", never, { "maxHeight": { "alias": "maxHeight"; "required": false; "isSignal": true; }; "noOptionsMessage": { "alias": "noOptionsMessage"; "required": false; "isSignal": true; }; }, { "closeEmitter": "closeEmitter"; }, ["options"], ["*"], true, [{ directive: typeof i1.CdkListbox; inputs: { "cdkListboxValue": "cdkListboxValue"; }; outputs: { "cdkListboxValueChange": "cdkListboxValueChange"; }; }]>;
37
+ static ɵcmp: i0.ɵɵComponentDeclaration<SelectOptionsComponent, "ul[b-select-options]", never, { "multiple": { "alias": "multiple"; "required": false; "isSignal": true; }; "maxHeight": { "alias": "maxHeight"; "required": false; "isSignal": true; }; "noOptionsMessage": { "alias": "noOptionsMessage"; "required": false; "isSignal": true; }; }, { "closeEmitter": "closeEmitter"; }, ["options"], ["*"], true, [{ directive: typeof i1.CdkListbox; inputs: { "cdkListboxValue": "cdkListboxValue"; }; outputs: { "cdkListboxValueChange": "cdkListboxValueChange"; }; }]>;
55
38
  }
@@ -30,7 +30,7 @@ export declare class SelectComponent implements OnInit, ControlValueAccessor {
30
30
  * Computed signal representing the selected values from the dropdown.
31
31
  * This is linked to the value of the `OptionsListComponent`.
32
32
  */
33
- readonly value: import("@angular/core").WritableSignal<string[] | undefined>;
33
+ readonly value: import("@angular/core").WritableSignal<string | string[] | null | undefined>;
34
34
  /**
35
35
  * Linked signal for the width of the button element.
36
36
  * This is used to set the width of the dropdown overlay.
@@ -91,12 +91,12 @@ export declare class SelectComponent implements OnInit, ControlValueAccessor {
91
91
  * This method is called by Angular Forms to update the value of the select component.
92
92
  * @param value - The new value to set.
93
93
  */
94
- writeValue(value: string[]): void;
94
+ writeValue(value: string | string[] | null): void;
95
95
  /**
96
96
  * Registers a callback function to be called when the value changes.
97
97
  * @param fn - The callback function.
98
98
  */
99
- registerOnChange(fn: (value: string[]) => void): void;
99
+ registerOnChange(fn: (value: string | string[] | null) => void): void;
100
100
  /**
101
101
  * Registers a callback function to be called when the component is touched.
102
102
  * @param fn - The callback function.
@@ -317,52 +317,45 @@ i0.ɵɵngDeclareClassMetadata({ minVersion: "12.0.0", version: "19.2.10", ngImpo
317
317
  */
318
318
  class SelectOptionsComponent {
319
319
  /**
320
- * Signal representing the selected values in the listbox.
321
- * This is an array of strings corresponding to the selected option values.
320
+ * Whether multiple selection is enabled.
322
321
  */
323
- value = signal([]);
322
+ multiple = input(false);
324
323
  /**
325
- * Event emitter triggered when the dropdown should close.
326
- * This is used to notify the parent component to close the dropdown.
324
+ * Signal representing the selected value(s).
325
+ * - If `multiple` is true: string[]
326
+ * - If `multiple` is false: string | null
327
327
  */
328
- closeEmitter = output();
328
+ value = signal(null);
329
329
  /**
330
- * Reference to the host element of the component.
331
- * This provides access to the DOM element of the options list.
330
+ * Event emitter triggered when the dropdown should close.
332
331
  */
332
+ closeEmitter = output();
333
333
  el = inject(ElementRef);
334
- /**
335
- * Input for setting the maximum height of the dropdown.
336
- * Defaults to '300px'. This controls the vertical size of the dropdown.
337
- */
334
+ listBox = inject(CdkListbox);
338
335
  maxHeight = input('300px');
339
- /**
340
- * No options message displayed when there are no available options in the dropdown.
341
- */
342
336
  noOptionsMessage = input('');
343
- /**
344
- * Reference to the CDK Listbox directive.
345
- * This is used to manage the options and their selection state.
346
- */
347
- listBox = inject(CdkListbox);
348
- /**
349
- * Reference to the list of options in the dropdown.
350
- * This is a collection of `OptionComponent` instances representing the available options.
351
- */
352
337
  options = contentChildren(OptionComponent);
353
338
  /**
354
339
  * Handles changes to the selected value in the listbox.
355
- * This method updates the `value` signal, emits the `closeEmitter` event,
356
- * and ensures the parent component is notified of the selection change.
357
340
  *
358
- * @param value - The new array of selected values.
341
+ * @param valueArray - The new array of selected values from the CDK listbox.
359
342
  */
360
- handleValueChange(value) {
361
- this.value.set(value);
343
+ handleValueChange(valueArray) {
344
+ if (valueArray.length === 1 && valueArray[0] === '') {
345
+ this.value.set(this.multiple() ? [] : null);
346
+ this.closeEmitter.emit();
347
+ return;
348
+ }
349
+ if (this.multiple()) {
350
+ this.value.set(valueArray);
351
+ }
352
+ else {
353
+ this.value.set(valueArray[0] ?? null);
354
+ }
362
355
  this.closeEmitter.emit();
363
356
  }
364
357
  static ɵfac = i0.ɵɵngDeclareFactory({ minVersion: "12.0.0", version: "19.2.10", ngImport: i0, type: SelectOptionsComponent, deps: [], target: i0.ɵɵFactoryTarget.Component });
365
- static ɵcmp = i0.ɵɵngDeclareComponent({ minVersion: "17.0.0", version: "19.2.10", type: SelectOptionsComponent, isStandalone: true, selector: "ul[b-select-options]", inputs: { maxHeight: { classPropertyName: "maxHeight", publicName: "maxHeight", isSignal: true, isRequired: false, transformFunction: null }, noOptionsMessage: { classPropertyName: "noOptionsMessage", publicName: "noOptionsMessage", isSignal: true, isRequired: false, transformFunction: null } }, outputs: { closeEmitter: "closeEmitter" }, host: { listeners: { "cdkListboxValueChange": "handleValueChange($event.value)", "keydown.enter": "closeEmitter.emit()" }, properties: { "cdkListboxValue": "value()", "style.max-height": "maxHeight()" } }, queries: [{ propertyName: "options", predicate: OptionComponent, isSignal: true }], hostDirectives: [{ directive: i1.CdkListbox, inputs: ["cdkListboxValue", "cdkListboxValue"], outputs: ["cdkListboxValueChange", "cdkListboxValueChange"] }], ngImport: i0, template: `<ng-content />
358
+ static ɵcmp = i0.ɵɵngDeclareComponent({ minVersion: "17.0.0", version: "19.2.10", type: SelectOptionsComponent, isStandalone: true, selector: "ul[b-select-options]", inputs: { multiple: { classPropertyName: "multiple", publicName: "multiple", isSignal: true, isRequired: false, transformFunction: null }, maxHeight: { classPropertyName: "maxHeight", publicName: "maxHeight", isSignal: true, isRequired: false, transformFunction: null }, noOptionsMessage: { classPropertyName: "noOptionsMessage", publicName: "noOptionsMessage", isSignal: true, isRequired: false, transformFunction: null } }, outputs: { closeEmitter: "closeEmitter" }, host: { listeners: { "cdkListboxValueChange": "handleValueChange($event.value)", "keydown.enter": "closeEmitter.emit()" }, properties: { "cdkListboxValue": "value()", "style.max-height": "maxHeight()" } }, queries: [{ propertyName: "options", predicate: OptionComponent, isSignal: true }], hostDirectives: [{ directive: i1.CdkListbox, inputs: ["cdkListboxValue", "cdkListboxValue"], outputs: ["cdkListboxValueChange", "cdkListboxValueChange"] }], ngImport: i0, template: `<ng-content />
366
359
  @if (options().length === 0) {
367
360
  <div class="no-options-message">
368
361
  {{ noOptionsMessage() }}
@@ -799,11 +792,12 @@ class SelectComponent {
799
792
  */
800
793
  content = computed(() => {
801
794
  const selected = this.value();
802
- if (selected &&
803
- selected.length > 0 &&
804
- !(selected.length === 1 && selected[0] === '')) {
795
+ const selectedArray = Array.isArray(selected) ? selected : [selected];
796
+ const valid = selectedArray.length > 0 &&
797
+ !(selectedArray.length === 1 && selectedArray[0] === '');
798
+ if (valid) {
805
799
  return this.options()?.reduce((acc, option) => {
806
- if (selected.includes(option.cdkOption.value)) {
800
+ if (selectedArray.includes(option.cdkOption.value)) {
807
801
  return acc
808
802
  ? acc + ', ' + option.el.nativeElement.innerText
809
803
  : option.el.nativeElement.innerText;
@@ -834,7 +828,20 @@ class SelectComponent {
834
828
  */
835
829
  handleSelectedValueChange() {
836
830
  this.optionsList()?.closeEmitter.subscribe(() => {
837
- this.onChange(this.value());
831
+ const selected = this.value();
832
+ const isMultiple = this.optionsList()?.multiple();
833
+ let emitValue;
834
+ if (isMultiple) {
835
+ emitValue = Array.isArray(selected) ? selected : [];
836
+ }
837
+ else {
838
+ emitValue = Array.isArray(selected)
839
+ ? (selected[0] ?? null)
840
+ : typeof selected === 'string'
841
+ ? selected
842
+ : null;
843
+ }
844
+ this.onChange(emitValue);
838
845
  this.onTouched();
839
846
  this.isOpen.set(false);
840
847
  });
@@ -870,12 +877,12 @@ class SelectComponent {
870
877
  * @param value - The new value to set.
871
878
  */
872
879
  writeValue(value) {
873
- if (value) {
874
- value.forEach(value => {
875
- this.optionsList()?.listBox?.selectValue(value);
876
- });
877
- this.value.set(value);
878
- }
880
+ if (value == null)
881
+ return;
882
+ const isMultiple = this.optionsList()?.multiple();
883
+ const values = isMultiple ? value : [value];
884
+ values.forEach(v => this.optionsList()?.listBox?.selectValue(v));
885
+ this.value.set(isMultiple ? values : values[0]);
879
886
  }
880
887
  /**
881
888
  * Registers a callback function to be called when the value changes.
@@ -2587,6 +2594,13 @@ class CommandOptionsComponent {
2587
2594
  const selectValue = value
2588
2595
  ? value
2589
2596
  : (this.listKeyManager().activeItem?.value ?? []);
2597
+ // If the selectValue is an empty array or contains only an empty string, clear the selection
2598
+ if (selectValue.length === 1 && selectValue[0] === '') {
2599
+ this.value.set([]);
2600
+ this.cdkListbox.value = [];
2601
+ this.closeEmitter.emit();
2602
+ return;
2603
+ }
2590
2604
  this.value.set(selectValue);
2591
2605
  this.cdkListbox.value = this.value();
2592
2606
  this.closeEmitter.emit();