@agorapulse/ui-components 22.5.3 → 22.5.5

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.
@@ -1,5 +1,5 @@
1
1
  import * as i0 from '@angular/core';
2
- import { inject, input, output, ViewEncapsulation, ChangeDetectionStrategy, Component, Input, ElementRef, Renderer2, ViewContainerRef, DestroyRef, effect, Directive, booleanAttribute, HostListener, ViewChild, EventEmitter, Output, signal, computed, afterNextRender, NgModule } from '@angular/core';
2
+ import { inject, input, output, ViewEncapsulation, ChangeDetectionStrategy, Component, Input, signal, computed, ElementRef, Renderer2, ViewContainerRef, DestroyRef, effect, Directive, Injector, untracked, booleanAttribute, HostListener, ViewChild, EventEmitter, Output, afterNextRender, NgModule } from '@angular/core';
3
3
  import { NgSelectComponent, NgSelectModule } from '@ng-select/ng-select';
4
4
  import { SymbolRegistry, apPlus, SymbolComponent, apCheck } from '@agorapulse/ui-symbol';
5
5
  import { BadgeComponent } from '@agorapulse/ui-components/badge';
@@ -107,6 +107,111 @@ i0.ɵɵngDeclareClassMetadata({ minVersion: "12.0.0", version: "22.0.5", ngImpor
107
107
  type: Input
108
108
  }] } });
109
109
 
110
+ /** "Select all" row added above the options by `SelectMultipleDirective` when `selectAllEnabled` is set. */
111
+ class DropdownSelectAllComponent {
112
+ select = input.required(/* @ts-ignore */
113
+ ...(ngDevMode ? [{ debugName: "select" }] : /* istanbul ignore next */ []));
114
+ text = input('Select all', /* @ts-ignore */
115
+ ...(ngDevMode ? [{ debugName: "text" }] : /* istanbul ignore next */ []));
116
+ /** Appended to `text`. `{selected}` and `{total}` are replaced by the counts of the options it acts on. */
117
+ countText = input('({selected} of {total})', /* @ts-ignore */
118
+ ...(ngDevMode ? [{ debugName: "countText" }] : /* istanbul ignore next */ []));
119
+ marked = signal(false, /* @ts-ignore */
120
+ ...(ngDevMode ? [{ debugName: "marked" }] : /* istanbul ignore next */ []));
121
+ /** Bumped by the owner on every selection or filter change, as `itemsList` is not reactive. */
122
+ version = signal(0, /* @ts-ignore */
123
+ ...(ngDevMode ? [{ debugName: "version" }] : /* istanbul ignore next */ []));
124
+ targets = computed(() => {
125
+ this.version();
126
+ return this.select().itemsList.filteredItems.filter(item => !item.children && !item.disabled);
127
+ }, /* @ts-ignore */
128
+ ...(ngDevMode ? [{ debugName: "targets" }] : /* istanbul ignore next */ []));
129
+ visible = computed(() => this.targets().length > 0, /* @ts-ignore */
130
+ ...(ngDevMode ? [{ debugName: "visible" }] : /* istanbul ignore next */ []));
131
+ checked = computed(() => this.visible() && this.targets().every(item => item.selected), /* @ts-ignore */
132
+ ...(ngDevMode ? [{ debugName: "checked" }] : /* istanbul ignore next */ []));
133
+ indeterminate = computed(() => !this.checked() && this.targets().some(item => item.selected), /* @ts-ignore */
134
+ ...(ngDevMode ? [{ debugName: "indeterminate" }] : /* istanbul ignore next */ []));
135
+ label = computed(() => {
136
+ const targets = this.targets();
137
+ const count = this.countText()
138
+ .replace('{selected}', String(targets.filter(item => item.selected).length))
139
+ .replace('{total}', String(targets.length));
140
+ return count ? `${this.text()} ${count}` : this.text();
141
+ }, /* @ts-ignore */
142
+ ...(ngDevMode ? [{ debugName: "label" }] : /* istanbul ignore next */ []));
143
+ ariaChecked = computed(() => (this.checked() ? 'true' : this.indeterminate() ? 'mixed' : 'false'), /* @ts-ignore */
144
+ ...(ngDevMode ? [{ debugName: "ariaChecked" }] : /* istanbul ignore next */ []));
145
+ get rowId() {
146
+ return `${this.select().dropdownId}-select-all`;
147
+ }
148
+ refresh() {
149
+ this.version.update(version => version + 1);
150
+ }
151
+ /** Handles a key before ng-select does, and returns whether it did. */
152
+ handleKey(event) {
153
+ const select = this.select();
154
+ if (!this.visible() || !select.isOpen()) {
155
+ this.marked.set(false);
156
+ return false;
157
+ }
158
+ if (this.marked()) {
159
+ switch (event.key) {
160
+ case 'ArrowUp':
161
+ event.preventDefault();
162
+ return true;
163
+ case 'Enter':
164
+ case ' ':
165
+ event.preventDefault();
166
+ this.toggle();
167
+ return true;
168
+ default:
169
+ this.marked.set(false);
170
+ return false;
171
+ }
172
+ }
173
+ if (event.key === 'ArrowUp' && this.isAtFirstOption()) {
174
+ event.preventDefault();
175
+ select.itemsList.unmarkItem();
176
+ this.marked.set(true);
177
+ select.detectChanges();
178
+ return true;
179
+ }
180
+ return false;
181
+ }
182
+ isAtFirstOption() {
183
+ const { markedIndex, filteredItems } = this.select().itemsList;
184
+ return markedIndex < 0 || filteredItems.slice(0, markedIndex).every(item => item.disabled);
185
+ }
186
+ toggle() {
187
+ const select = this.select();
188
+ // Snapshot first: selecting may clear the search (`clearSearchOnAdd`), which refilters the list.
189
+ const targets = this.targets();
190
+ const hasSelection = targets.some(item => item.selected);
191
+ const selectAll = select.maxSelectedItems() ? !hasSelection : !this.checked();
192
+ if (selectAll) {
193
+ for (const item of targets) {
194
+ select.select(item);
195
+ }
196
+ }
197
+ else {
198
+ for (const item of targets.filter(target => target.selected)) {
199
+ select.unselect(item);
200
+ }
201
+ }
202
+ this.refresh();
203
+ select.detectChanges();
204
+ }
205
+ static ɵfac = i0.ɵɵngDeclareFactory({ minVersion: "12.0.0", version: "22.0.5", ngImport: i0, type: DropdownSelectAllComponent, deps: [], target: i0.ɵɵFactoryTarget.Component });
206
+ static ɵcmp = i0.ɵɵngDeclareComponent({ minVersion: "17.1.0", version: "22.0.5", type: DropdownSelectAllComponent, isStandalone: true, selector: "ap-dropdown-select-all", inputs: { select: { classPropertyName: "select", publicName: "select", isSignal: true, isRequired: true, transformFunction: null }, text: { classPropertyName: "text", publicName: "text", isSignal: true, isRequired: false, transformFunction: null }, countText: { classPropertyName: "countText", publicName: "countText", isSignal: true, isRequired: false, transformFunction: null } }, host: { properties: { "attr.hidden": "visible() ? null : \"\"" } }, ngImport: i0, template: "<button\n type=\"button\"\n role=\"checkbox\"\n class=\"select-all-row\"\n tabindex=\"-1\"\n [id]=\"rowId\"\n [class.marked]=\"marked()\"\n [attr.aria-checked]=\"ariaChecked()\"\n (click)=\"toggle()\">\n <ap-checkbox\n class=\"centered\"\n fullyControlled\n presentational\n [name]=\"'option-select-all-' + select().dropdownId\"\n [checked]=\"checked()\"\n [indeterminate]=\"indeterminate()\">\n <span class=\"select-all-text\">\n {{ label() }}\n </span>\n </ap-checkbox>\n</button>\n", styles: ["ap-dropdown-select-all{display:block;padding:0 var(--comp-select-search-bar-padding-horizontal);margin-bottom:var(--ref-spacing-xxs);border-bottom:1px solid var(--comp-select-search-bar-border-bottom-color)}ap-dropdown-select-all[hidden]{display:none}.ng-dropdown-header ap-dropdown-select-all{padding:0;margin:0;border:none}ap-dropdown-select-all .select-all-row{display:flex;align-items:center;width:100%;height:var(--comp-select-one-line-height);box-sizing:border-box;margin:0;padding:0 var(--comp-select-search-bar-padding-horizontal);border:none;background-color:var(--comp-select-one-line-background-color);cursor:pointer;text-align:left}ap-dropdown-select-all .select-all-row.marked{background-color:var(--ref-color-electric-blue-10)}ap-dropdown-select-all .select-all-row ap-checkbox{width:100%;pointer-events:none}ap-dropdown-select-all .select-all-row ap-checkbox .checkbox{width:100%}ap-dropdown-select-all .select-all-text{overflow:hidden;white-space:nowrap;text-overflow:ellipsis;font-family:var(--comp-select-one-line-selected-text-font-family);font-size:var(--comp-select-one-line-selected-text-size);font-weight:var(--comp-select-one-line-selected-text-font-weight);line-height:var(--comp-select-one-line-selected-text-line-height);color:var(--comp-select-one-line-text-color)}.ng-dropdown-panel.ap-select .ng-dropdown-header:has(>ap-dropdown-select-all:not([hidden])){padding-bottom:0}\n"], dependencies: [{ kind: "component", type: CheckboxComponent, selector: "ap-checkbox", inputs: ["aria-label", "aria-labelledby", "aria-describedby", "disabled", "indeterminate", "checked", "fullyControlled", "presentational", "required", "name"], outputs: ["change"] }], changeDetection: i0.ChangeDetectionStrategy.OnPush, encapsulation: i0.ViewEncapsulation.None });
207
+ }
208
+ i0.ɵɵngDeclareClassMetadata({ minVersion: "12.0.0", version: "22.0.5", ngImport: i0, type: DropdownSelectAllComponent, decorators: [{
209
+ type: Component,
210
+ args: [{ selector: 'ap-dropdown-select-all', encapsulation: ViewEncapsulation.None, changeDetection: ChangeDetectionStrategy.OnPush, imports: [CheckboxComponent], host: {
211
+ '[attr.hidden]': 'visible() ? null : ""',
212
+ }, template: "<button\n type=\"button\"\n role=\"checkbox\"\n class=\"select-all-row\"\n tabindex=\"-1\"\n [id]=\"rowId\"\n [class.marked]=\"marked()\"\n [attr.aria-checked]=\"ariaChecked()\"\n (click)=\"toggle()\">\n <ap-checkbox\n class=\"centered\"\n fullyControlled\n presentational\n [name]=\"'option-select-all-' + select().dropdownId\"\n [checked]=\"checked()\"\n [indeterminate]=\"indeterminate()\">\n <span class=\"select-all-text\">\n {{ label() }}\n </span>\n </ap-checkbox>\n</button>\n", styles: ["ap-dropdown-select-all{display:block;padding:0 var(--comp-select-search-bar-padding-horizontal);margin-bottom:var(--ref-spacing-xxs);border-bottom:1px solid var(--comp-select-search-bar-border-bottom-color)}ap-dropdown-select-all[hidden]{display:none}.ng-dropdown-header ap-dropdown-select-all{padding:0;margin:0;border:none}ap-dropdown-select-all .select-all-row{display:flex;align-items:center;width:100%;height:var(--comp-select-one-line-height);box-sizing:border-box;margin:0;padding:0 var(--comp-select-search-bar-padding-horizontal);border:none;background-color:var(--comp-select-one-line-background-color);cursor:pointer;text-align:left}ap-dropdown-select-all .select-all-row.marked{background-color:var(--ref-color-electric-blue-10)}ap-dropdown-select-all .select-all-row ap-checkbox{width:100%;pointer-events:none}ap-dropdown-select-all .select-all-row ap-checkbox .checkbox{width:100%}ap-dropdown-select-all .select-all-text{overflow:hidden;white-space:nowrap;text-overflow:ellipsis;font-family:var(--comp-select-one-line-selected-text-font-family);font-size:var(--comp-select-one-line-selected-text-size);font-weight:var(--comp-select-one-line-selected-text-font-weight);line-height:var(--comp-select-one-line-selected-text-line-height);color:var(--comp-select-one-line-text-color)}.ng-dropdown-panel.ap-select .ng-dropdown-header:has(>ap-dropdown-select-all:not([hidden])){padding-bottom:0}\n"] }]
213
+ }], propDecorators: { select: [{ type: i0.Input, args: [{ isSignal: true, alias: "select", required: true }] }], text: [{ type: i0.Input, args: [{ isSignal: true, alias: "text", required: false }] }], countText: [{ type: i0.Input, args: [{ isSignal: true, alias: "countText", required: false }] }] } });
214
+
110
215
  class SelectBaseDirective {
111
216
  inlineLabel = input(/* @ts-ignore */
112
217
  ...(ngDevMode ? [undefined, { debugName: "inlineLabel" }] : /* istanbul ignore next */ []));
@@ -268,14 +373,25 @@ i0.ɵɵngDeclareClassMetadata({ minVersion: "12.0.0", version: "22.0.5", ngImpor
268
373
  class SelectMultipleDirective {
269
374
  selectComponent = inject(NgSelectComponent);
270
375
  elementRef = inject(ElementRef);
376
+ injector = inject(Injector);
271
377
  originalDisabledState = new WeakMap();
272
378
  maxItemsTooltip = input(/* @ts-ignore */
273
379
  ...(ngDevMode ? [undefined, { debugName: "maxItemsTooltip" }] : /* istanbul ignore next */ []));
274
380
  /** Pins items selected at open time to the top of the dropdown. Ignored when `groupBy` is set. */
275
381
  pinnedItemsEnabled = input(false, /* @ts-ignore */
276
382
  ...(ngDevMode ? [{ debugName: "pinnedItemsEnabled" }] : /* istanbul ignore next */ []));
383
+ /** Adds a "Select all" row above the options, acting on every visible option across groups. */
384
+ selectAllEnabled = input(false, /* @ts-ignore */
385
+ ...(ngDevMode ? [{ debugName: "selectAllEnabled" }] : /* istanbul ignore next */ []));
386
+ /** Label of the "Select all" row. */
387
+ selectAllText = input('Select all', /* @ts-ignore */
388
+ ...(ngDevMode ? [{ debugName: "selectAllText" }] : /* istanbul ignore next */ []));
389
+ /** Count after the "Select all" label. `{selected}` and `{total}` are replaced; empty hides it. */
390
+ selectAllCountText = input('({selected} of {total})', /* @ts-ignore */
391
+ ...(ngDevMode ? [{ debugName: "selectAllCountText" }] : /* istanbul ignore next */ []));
277
392
  valueContainer = null;
278
393
  subs = new Subscription();
394
+ selectAllRow = null;
279
395
  constructor() {
280
396
  this.selectComponent.multiple.set(true);
281
397
  this.selectComponent.closeOnSelect.set(false);
@@ -286,7 +402,9 @@ class SelectMultipleDirective {
286
402
  this.subs.add(this.selectComponent.openEvent.subscribe(() => {
287
403
  this.pinSelectedAtTop();
288
404
  this.openAtTop();
405
+ this.mountSelectAll();
289
406
  }));
407
+ this.subs.add(this.selectComponent.closeEvent.subscribe(() => this.unmountSelectAll()));
290
408
  }
291
409
  ngAfterViewInit() {
292
410
  if (!this.selectComponent.multiLabelTemplate()) {
@@ -303,6 +421,7 @@ class SelectMultipleDirective {
303
421
  if (this.valueContainer) {
304
422
  this.valueContainer.removeEventListener('mousedown', this.onMousedown, true);
305
423
  }
424
+ this.unmountSelectAll();
306
425
  this.subs.unsubscribe();
307
426
  }
308
427
  onMousedown = (event) => {
@@ -343,6 +462,72 @@ class SelectMultipleDirective {
343
462
  }
344
463
  });
345
464
  }
465
+ // `openEvent` fires before ng-select renders the panel, hence the microtask (cf. `pinSelectedAtTop`).
466
+ mountSelectAll() {
467
+ if (!this.selectAllEnabled())
468
+ return;
469
+ queueMicrotask(() => {
470
+ const panel = document.getElementById(this.selectComponent.dropdownId);
471
+ const items = panel?.querySelector('.ng-dropdown-panel-items');
472
+ if (!panel || !items || !this.selectComponent.isOpen())
473
+ return;
474
+ this.unmountSelectAll();
475
+ const ref = this.injector.get(ViewContainerRef).createComponent(DropdownSelectAllComponent);
476
+ ref.setInput('select', this.selectComponent);
477
+ ref.setInput('text', this.selectAllText());
478
+ ref.setInput('countText', this.selectAllCountText());
479
+ const host = ref.location.nativeElement;
480
+ // ng-select closes or blurs on a press it receives; the row handles its own clicks.
481
+ host.addEventListener('mousedown', event => event.preventDefault());
482
+ const header = panel.querySelector('.ng-dropdown-header');
483
+ if (header) {
484
+ header.append(host);
485
+ }
486
+ else {
487
+ items.before(host);
488
+ }
489
+ // Also reached by the keys the header search field forwards.
490
+ const originalHandleKeyCodeInput = this.selectComponent.handleKeyCodeInput.bind(this.selectComponent);
491
+ this.selectComponent.handleKeyCodeInput = (event) => {
492
+ const handled = ref.instance.handleKey(event);
493
+ if (!handled) {
494
+ originalHandleKeyCodeInput(event);
495
+ }
496
+ this.syncActiveDescendant(ref.instance);
497
+ };
498
+ const unmarkOnHover = () => ref.instance.marked.set(false);
499
+ items.addEventListener('mouseover', unmarkOnHover);
500
+ const refresh = () => ref.instance.refresh();
501
+ const subs = new Subscription(() => {
502
+ this.selectComponent.handleKeyCodeInput = originalHandleKeyCodeInput;
503
+ items.removeEventListener('mouseover', unmarkOnHover);
504
+ });
505
+ subs.add(this.selectComponent.addEvent.subscribe(refresh));
506
+ subs.add(this.selectComponent.removeEvent.subscribe(refresh));
507
+ subs.add(this.selectComponent.clearEvent.subscribe(refresh));
508
+ subs.add(this.selectComponent.searchEvent.subscribe(refresh));
509
+ // ng-select rebuilds its list after this effect runs.
510
+ const itemsEffect = effect(() => {
511
+ this.selectComponent.items();
512
+ untracked(() => queueMicrotask(refresh));
513
+ }, { ...(ngDevMode ? { debugName: "itemsEffect" } : /* istanbul ignore next */ {}), injector: this.injector });
514
+ this.selectAllRow = { ref, subs, itemsEffect };
515
+ ref.changeDetectorRef.detectChanges();
516
+ });
517
+ }
518
+ syncActiveDescendant(selectAll) {
519
+ if (!selectAll.marked())
520
+ return;
521
+ this.elementRef.nativeElement.querySelector('input[role="combobox"]')?.setAttribute('aria-activedescendant', selectAll.rowId);
522
+ }
523
+ unmountSelectAll() {
524
+ if (!this.selectAllRow)
525
+ return;
526
+ this.selectAllRow.subs.unsubscribe();
527
+ this.selectAllRow.itemsEffect.destroy();
528
+ this.selectAllRow.ref.destroy();
529
+ this.selectAllRow = null;
530
+ }
346
531
  // On open, ng-select natively marks the last selected option, which ends up scrolling the panel to it.
347
532
  // This method removes the mark so that the panel stays scrolled to the top.
348
533
  openAtTop() {
@@ -371,7 +556,7 @@ class SelectMultipleDirective {
371
556
  }
372
557
  }
373
558
  static ɵfac = i0.ɵɵngDeclareFactory({ minVersion: "12.0.0", version: "22.0.5", ngImport: i0, type: SelectMultipleDirective, deps: [], target: i0.ɵɵFactoryTarget.Directive });
374
- static ɵdir = i0.ɵɵngDeclareDirective({ minVersion: "17.1.0", version: "22.0.5", type: SelectMultipleDirective, isStandalone: true, selector: "ng-select[apSelectMultiple]", inputs: { maxItemsTooltip: { classPropertyName: "maxItemsTooltip", publicName: "maxItemsTooltip", isSignal: true, isRequired: false, transformFunction: null }, pinnedItemsEnabled: { classPropertyName: "pinnedItemsEnabled", publicName: "pinnedItemsEnabled", isSignal: true, isRequired: false, transformFunction: null } }, hostDirectives: [{ directive: SelectBaseDirective, inputs: ["inlineLabel", "inlineLabel", "symbolId", "symbolId", "clearable", "clearable"] }], ngImport: i0 });
559
+ static ɵdir = i0.ɵɵngDeclareDirective({ minVersion: "17.1.0", version: "22.0.5", type: SelectMultipleDirective, isStandalone: true, selector: "ng-select[apSelectMultiple]", inputs: { maxItemsTooltip: { classPropertyName: "maxItemsTooltip", publicName: "maxItemsTooltip", isSignal: true, isRequired: false, transformFunction: null }, pinnedItemsEnabled: { classPropertyName: "pinnedItemsEnabled", publicName: "pinnedItemsEnabled", isSignal: true, isRequired: false, transformFunction: null }, selectAllEnabled: { classPropertyName: "selectAllEnabled", publicName: "selectAllEnabled", isSignal: true, isRequired: false, transformFunction: null }, selectAllText: { classPropertyName: "selectAllText", publicName: "selectAllText", isSignal: true, isRequired: false, transformFunction: null }, selectAllCountText: { classPropertyName: "selectAllCountText", publicName: "selectAllCountText", isSignal: true, isRequired: false, transformFunction: null } }, hostDirectives: [{ directive: SelectBaseDirective, inputs: ["inlineLabel", "inlineLabel", "symbolId", "symbolId", "clearable", "clearable"] }], ngImport: i0 });
375
560
  }
376
561
  i0.ɵɵngDeclareClassMetadata({ minVersion: "12.0.0", version: "22.0.5", ngImport: i0, type: SelectMultipleDirective, decorators: [{
377
562
  type: Directive,
@@ -385,7 +570,7 @@ i0.ɵɵngDeclareClassMetadata({ minVersion: "12.0.0", version: "22.0.5", ngImpor
385
570
  },
386
571
  ],
387
572
  }]
388
- }], ctorParameters: () => [], propDecorators: { maxItemsTooltip: [{ type: i0.Input, args: [{ isSignal: true, alias: "maxItemsTooltip", required: false }] }], pinnedItemsEnabled: [{ type: i0.Input, args: [{ isSignal: true, alias: "pinnedItemsEnabled", required: false }] }] } });
573
+ }], ctorParameters: () => [], propDecorators: { maxItemsTooltip: [{ type: i0.Input, args: [{ isSignal: true, alias: "maxItemsTooltip", required: false }] }], pinnedItemsEnabled: [{ type: i0.Input, args: [{ isSignal: true, alias: "pinnedItemsEnabled", required: false }] }], selectAllEnabled: [{ type: i0.Input, args: [{ isSignal: true, alias: "selectAllEnabled", required: false }] }], selectAllText: [{ type: i0.Input, args: [{ isSignal: true, alias: "selectAllText", required: false }] }], selectAllCountText: [{ type: i0.Input, args: [{ isSignal: true, alias: "selectAllCountText", required: false }] }] } });
389
574
 
390
575
  class DropdownItemMultipleOneLineComponent {
391
576
  symbolRegistry = inject(SymbolRegistry);
@@ -934,5 +1119,5 @@ i0.ɵɵngDeclareClassMetadata({ minVersion: "12.0.0", version: "22.0.5", ngImpor
934
1119
  * Generated bundle index. Do not edit.
935
1120
  */
936
1121
 
937
- export { ApSelectModule, DropdownCreateNewComponent, DropdownGroupItemComponent, DropdownItemMultipleOneLineComponent, DropdownItemMultipleTwoLinesComponent, DropdownItemSingleOneLineComponent, DropdownItemSingleTwoLinesComponent, DropdownSearchFormComponent, SelectBaseDirective, SelectLabelMultipleComponent, SelectLabelSingleComponent, SelectMultipleDirective, SelectSingleDirective };
1122
+ export { ApSelectModule, DropdownCreateNewComponent, DropdownGroupItemComponent, DropdownItemMultipleOneLineComponent, DropdownItemMultipleTwoLinesComponent, DropdownItemSingleOneLineComponent, DropdownItemSingleTwoLinesComponent, DropdownSearchFormComponent, DropdownSelectAllComponent, SelectBaseDirective, SelectLabelMultipleComponent, SelectLabelSingleComponent, SelectMultipleDirective, SelectSingleDirective };
938
1123
  //# sourceMappingURL=agorapulse-ui-components-select.mjs.map