@agorapulse/ui-components 22.5.5 → 22.5.7-beta.1

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, signal, computed, ElementRef, Renderer2, ViewContainerRef, DestroyRef, effect, Directive, Injector, untracked, booleanAttribute, HostListener, ViewChild, EventEmitter, Output, afterNextRender, NgModule } 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';
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,111 +107,6 @@ 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
-
215
110
  class SelectBaseDirective {
216
111
  inlineLabel = input(/* @ts-ignore */
217
112
  ...(ngDevMode ? [undefined, { debugName: "inlineLabel" }] : /* istanbul ignore next */ []));
@@ -373,25 +268,14 @@ i0.ɵɵngDeclareClassMetadata({ minVersion: "12.0.0", version: "22.0.5", ngImpor
373
268
  class SelectMultipleDirective {
374
269
  selectComponent = inject(NgSelectComponent);
375
270
  elementRef = inject(ElementRef);
376
- injector = inject(Injector);
377
271
  originalDisabledState = new WeakMap();
378
272
  maxItemsTooltip = input(/* @ts-ignore */
379
273
  ...(ngDevMode ? [undefined, { debugName: "maxItemsTooltip" }] : /* istanbul ignore next */ []));
380
274
  /** Pins items selected at open time to the top of the dropdown. Ignored when `groupBy` is set. */
381
275
  pinnedItemsEnabled = input(false, /* @ts-ignore */
382
276
  ...(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 */ []));
392
277
  valueContainer = null;
393
278
  subs = new Subscription();
394
- selectAllRow = null;
395
279
  constructor() {
396
280
  this.selectComponent.multiple.set(true);
397
281
  this.selectComponent.closeOnSelect.set(false);
@@ -402,9 +286,7 @@ class SelectMultipleDirective {
402
286
  this.subs.add(this.selectComponent.openEvent.subscribe(() => {
403
287
  this.pinSelectedAtTop();
404
288
  this.openAtTop();
405
- this.mountSelectAll();
406
289
  }));
407
- this.subs.add(this.selectComponent.closeEvent.subscribe(() => this.unmountSelectAll()));
408
290
  }
409
291
  ngAfterViewInit() {
410
292
  if (!this.selectComponent.multiLabelTemplate()) {
@@ -421,7 +303,6 @@ class SelectMultipleDirective {
421
303
  if (this.valueContainer) {
422
304
  this.valueContainer.removeEventListener('mousedown', this.onMousedown, true);
423
305
  }
424
- this.unmountSelectAll();
425
306
  this.subs.unsubscribe();
426
307
  }
427
308
  onMousedown = (event) => {
@@ -462,72 +343,6 @@ class SelectMultipleDirective {
462
343
  }
463
344
  });
464
345
  }
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
- }
531
346
  // On open, ng-select natively marks the last selected option, which ends up scrolling the panel to it.
532
347
  // This method removes the mark so that the panel stays scrolled to the top.
533
348
  openAtTop() {
@@ -556,7 +371,7 @@ class SelectMultipleDirective {
556
371
  }
557
372
  }
558
373
  static ɵfac = i0.ɵɵngDeclareFactory({ minVersion: "12.0.0", version: "22.0.5", ngImport: i0, type: SelectMultipleDirective, deps: [], target: i0.ɵɵFactoryTarget.Directive });
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 });
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 });
560
375
  }
561
376
  i0.ɵɵngDeclareClassMetadata({ minVersion: "12.0.0", version: "22.0.5", ngImport: i0, type: SelectMultipleDirective, decorators: [{
562
377
  type: Directive,
@@ -570,7 +385,7 @@ i0.ɵɵngDeclareClassMetadata({ minVersion: "12.0.0", version: "22.0.5", ngImpor
570
385
  },
571
386
  ],
572
387
  }]
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 }] }] } });
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 }] }] } });
574
389
 
575
390
  class DropdownItemMultipleOneLineComponent {
576
391
  symbolRegistry = inject(SymbolRegistry);
@@ -1119,5 +934,5 @@ i0.ɵɵngDeclareClassMetadata({ minVersion: "12.0.0", version: "22.0.5", ngImpor
1119
934
  * Generated bundle index. Do not edit.
1120
935
  */
1121
936
 
1122
- export { ApSelectModule, DropdownCreateNewComponent, DropdownGroupItemComponent, DropdownItemMultipleOneLineComponent, DropdownItemMultipleTwoLinesComponent, DropdownItemSingleOneLineComponent, DropdownItemSingleTwoLinesComponent, DropdownSearchFormComponent, DropdownSelectAllComponent, SelectBaseDirective, SelectLabelMultipleComponent, SelectLabelSingleComponent, SelectMultipleDirective, SelectSingleDirective };
937
+ export { ApSelectModule, DropdownCreateNewComponent, DropdownGroupItemComponent, DropdownItemMultipleOneLineComponent, DropdownItemMultipleTwoLinesComponent, DropdownItemSingleOneLineComponent, DropdownItemSingleTwoLinesComponent, DropdownSearchFormComponent, SelectBaseDirective, SelectLabelMultipleComponent, SelectLabelSingleComponent, SelectMultipleDirective, SelectSingleDirective };
1123
938
  //# sourceMappingURL=agorapulse-ui-components-select.mjs.map