@ni/nimble-angular 17.4.0 → 17.4.2

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.
@@ -1239,7 +1239,8 @@ class NimbleComboboxControlValueAccessorDirective {
1239
1239
  constructor(_renderer, _elementRef) {
1240
1240
  this._renderer = _renderer;
1241
1241
  this._elementRef = _elementRef;
1242
- this._optionMap = new Map();
1242
+ this._displayTextToOptionsMap = new Map();
1243
+ this._optionToModelValueMap = new Map();
1243
1244
  this._optionUpdateQueue = [];
1244
1245
  this._compareWith = Object.is;
1245
1246
  }
@@ -1256,7 +1257,7 @@ class NimbleComboboxControlValueAccessorDirective {
1256
1257
  }
1257
1258
  ngAfterViewChecked() {
1258
1259
  for (const updateValue of this._optionUpdateQueue) {
1259
- this.addOption(updateValue.listOption.text, updateValue.modelValue);
1260
+ this.addOption(updateValue.modelValue, updateValue.listOption);
1260
1261
  }
1261
1262
  this._optionUpdateQueue = [];
1262
1263
  }
@@ -1274,9 +1275,11 @@ class NimbleComboboxControlValueAccessorDirective {
1274
1275
  */
1275
1276
  registerOnChange(fn) {
1276
1277
  this.onChange = (valueString) => {
1277
- const modelValue = this._optionMap.has(valueString) ? this._optionMap.get(valueString) : OPTION_NOT_FOUND;
1278
- this._modelValue = modelValue;
1279
- fn(modelValue);
1278
+ const options = this._displayTextToOptionsMap.get(valueString);
1279
+ this._modelValue = options
1280
+ ? this._optionToModelValueMap.get(options[0])
1281
+ : OPTION_NOT_FOUND;
1282
+ fn(this._modelValue);
1280
1283
  };
1281
1284
  }
1282
1285
  /**
@@ -1299,18 +1302,43 @@ class NimbleComboboxControlValueAccessorDirective {
1299
1302
  /**
1300
1303
  * @internal
1301
1304
  */
1302
- addOption(displayValue, modelValue) {
1303
- this._optionMap.set(displayValue, modelValue);
1305
+ addOption(modelValue, option) {
1306
+ this._optionToModelValueMap.set(option, modelValue);
1307
+ const options = this._displayTextToOptionsMap.get(option.text);
1308
+ if (options) {
1309
+ const optionIndex = options.indexOf(option);
1310
+ if (optionIndex < 0) {
1311
+ options.push(option);
1312
+ }
1313
+ }
1314
+ else {
1315
+ this._displayTextToOptionsMap.set(option.text, [option]);
1316
+ }
1304
1317
  this.updateDisplayValue();
1305
1318
  }
1306
1319
  /**
1307
1320
  * @internal
1308
1321
  */
1309
- removeOption(displayValue) {
1310
- this._optionMap.delete(displayValue);
1322
+ removeOption(option) {
1323
+ const options = this._displayTextToOptionsMap.get(option.text);
1324
+ if (options) {
1325
+ if (options.length > 1) {
1326
+ const removeIndex = options.indexOf(option);
1327
+ if (removeIndex >= 0) {
1328
+ options.splice(removeIndex, 1);
1329
+ }
1330
+ }
1331
+ else {
1332
+ this._displayTextToOptionsMap.delete(option.text);
1333
+ }
1334
+ }
1335
+ this._optionToModelValueMap.delete(option);
1311
1336
  }
1312
- queueOptionUpdate(listOption, modelValue) {
1313
- this.removeOption(listOption.text);
1337
+ /**
1338
+ * @internal
1339
+ */
1340
+ queueOptionUpdate(modelValue, listOption) {
1341
+ this.removeOption(listOption);
1314
1342
  this._optionUpdateQueue.push({ listOption, modelValue });
1315
1343
  }
1316
1344
  updateDisplayValue() {
@@ -1318,9 +1346,13 @@ class NimbleComboboxControlValueAccessorDirective {
1318
1346
  this.setProperty('value', valueAsString ?? '');
1319
1347
  }
1320
1348
  getValueStringFromValue(value) {
1321
- for (const [optionKey, optionValue] of this._optionMap.entries()) {
1322
- if (this._compareWith(optionValue, value)) {
1323
- return optionKey;
1349
+ for (const [option, modelValue] of this._optionToModelValueMap.entries()) {
1350
+ if (this._compareWith(modelValue, value)) {
1351
+ for (const [displayText, options] of this._displayTextToOptionsMap.entries()) {
1352
+ if (options.includes(option)) {
1353
+ return displayText;
1354
+ }
1355
+ }
1324
1356
  }
1325
1357
  }
1326
1358
  return undefined;
@@ -6534,17 +6566,16 @@ class NimbleComboboxListOptionDirective {
6534
6566
  }
6535
6567
  ngAfterViewInit() {
6536
6568
  if (this.combobox) {
6537
- this._currentTextContent = this.elementRef.nativeElement.text;
6538
- this.combobox.addOption(this._currentTextContent, this._modelValue);
6569
+ this.combobox.addOption(this._modelValue, this.elementRef.nativeElement);
6539
6570
  }
6540
6571
  }
6541
6572
  ngOnDestroy() {
6542
6573
  if (this.combobox) {
6543
- this.combobox.removeOption(this._currentTextContent);
6574
+ this.combobox.removeOption(this.elementRef.nativeElement);
6544
6575
  }
6545
6576
  }
6546
6577
  updateComboboxValue(value) {
6547
- this.combobox.queueOptionUpdate(this.elementRef.nativeElement, value);
6578
+ this.combobox.queueOptionUpdate(value, this.elementRef.nativeElement);
6548
6579
  }
6549
6580
  }
6550
6581
  NimbleComboboxListOptionDirective.ɵfac = i0.ɵɵngDeclareFactory({ minVersion: "12.0.0", version: "14.3.0", ngImport: i0, type: NimbleComboboxListOptionDirective, deps: [{ token: i0.ElementRef }, { token: i0.Renderer2 }, { token: NimbleComboboxControlValueAccessorDirective, host: true, optional: true }], target: i0.ɵɵFactoryTarget.Directive });