@ngflux/ngflux 3.2.3 → 3.2.4

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,9 +1,9 @@
1
1
  import * as i0 from '@angular/core';
2
- import { InjectionToken, input, Component, inject, ElementRef, computed, HostBinding, Injector, viewChild, ViewContainerRef, ApplicationRef, signal, createComponent, effect, Injectable, linkedSignal, output, model, ChangeDetectionStrategy, untracked, booleanAttribute, Directive, viewChildren, TemplateRef, debounced, makeEnvironmentProviders, provideAppInitializer, runInInjectionContext } from '@angular/core';
2
+ import { InjectionToken, input, Component, inject, ElementRef, computed, HostBinding, Injector, viewChild, ViewContainerRef, ApplicationRef, signal, createComponent, effect, Injectable, linkedSignal, model, Directive, output, ChangeDetectionStrategy, untracked, booleanAttribute, viewChildren, TemplateRef, debounced, makeEnvironmentProviders, provideAppInitializer, runInInjectionContext } from '@angular/core';
3
3
  import * as i1$1 from '@angular/router';
4
4
  import { TitleStrategy, Router, ActivationEnd, RouterLink, RouterLinkActive, isActive, NavigationStart, NavigationEnd, NavigationCancel, NavigationError } from '@angular/router';
5
5
  import { filter, map, AsyncSubject, of, switchMap, Observable, from } from 'rxjs';
6
- import { NgClass, NgTemplateOutlet } from '@angular/common';
6
+ import { NgClass, KeyValuePipe, NgTemplateOutlet } from '@angular/common';
7
7
  import { Title, Meta } from '@angular/platform-browser';
8
8
  import * as i1 from '@angular/forms';
9
9
  import { FormsModule } from '@angular/forms';
@@ -360,6 +360,144 @@ i0.ɵɵngDeclareClassMetadata({ minVersion: "12.0.0", version: "22.1.2", ngImpor
360
360
  type: Injectable
361
361
  }] });
362
362
 
363
+ class NgFluxToastController {
364
+ config = inject(NGF_CONFIG);
365
+ data = signal(new Map(), /* @ts-ignore */
366
+ ...(ngDevMode ? [{ debugName: "data" }] : /* istanbul ignore next */ []));
367
+ map = computed(() => {
368
+ const data = this.data();
369
+ const map = new Map();
370
+ for (const [item] of data.entries()) {
371
+ const key = item.placement;
372
+ const entries = map.get(key) ?? [];
373
+ entries.push(item);
374
+ map.set(key, entries);
375
+ }
376
+ return map;
377
+ }, /* @ts-ignore */
378
+ ...(ngDevMode ? [{ debugName: "map" }] : /* istanbul ignore next */ []));
379
+ add = (options) => this.data.update(v => {
380
+ const data = new Map(v);
381
+ data.set(options, true);
382
+ return data;
383
+ });
384
+ remove = (options) => this.data.update(v => {
385
+ const data = new Map(v);
386
+ data.delete(options);
387
+ return data;
388
+ });
389
+ static ɵfac = i0.ɵɵngDeclareFactory({ minVersion: "12.0.0", version: "22.1.2", ngImport: i0, type: NgFluxToastController, deps: [], target: i0.ɵɵFactoryTarget.Injectable });
390
+ static ɵprov = i0.ɵɵngDeclareInjectable({ minVersion: "12.0.0", version: "22.1.2", ngImport: i0, type: NgFluxToastController, providedIn: 'root' });
391
+ }
392
+ i0.ɵɵngDeclareClassMetadata({ minVersion: "12.0.0", version: "22.1.2", ngImport: i0, type: NgFluxToastController, decorators: [{
393
+ type: Injectable,
394
+ args: [{ providedIn: 'root' }]
395
+ }] });
396
+
397
+ class NgFluxThemeDirective {
398
+ ngfTheme = model('default', /* @ts-ignore */
399
+ ...(ngDevMode ? [{ debugName: "ngfTheme" }] : /* istanbul ignore next */ []));
400
+ className = computed(() => `ngf-theme-${this.ngfTheme()}`, /* @ts-ignore */
401
+ ...(ngDevMode ? [{ debugName: "className" }] : /* istanbul ignore next */ []));
402
+ static ɵfac = i0.ɵɵngDeclareFactory({ minVersion: "12.0.0", version: "22.1.2", ngImport: i0, type: NgFluxThemeDirective, deps: [], target: i0.ɵɵFactoryTarget.Directive });
403
+ static ɵdir = i0.ɵɵngDeclareDirective({ minVersion: "17.1.0", version: "22.1.2", type: NgFluxThemeDirective, isStandalone: true, selector: "[ngfTheme]", inputs: { ngfTheme: { classPropertyName: "ngfTheme", publicName: "ngfTheme", isSignal: true, isRequired: false, transformFunction: null } }, outputs: { ngfTheme: "ngfThemeChange" }, host: { properties: { "class": "className()" } }, ngImport: i0 });
404
+ }
405
+ i0.ɵɵngDeclareClassMetadata({ minVersion: "12.0.0", version: "22.1.2", ngImport: i0, type: NgFluxThemeDirective, decorators: [{
406
+ type: Directive,
407
+ args: [{
408
+ selector: '[ngfTheme]',
409
+ host: {
410
+ '[class]': 'className()',
411
+ },
412
+ }]
413
+ }], propDecorators: { ngfTheme: [{ type: i0.Input, args: [{ isSignal: true, alias: "ngfTheme", required: false }] }, { type: i0.Output, args: ["ngfThemeChange"] }] } });
414
+
415
+ class NgFluxToastComponent {
416
+ ctrl = inject(NgFluxToastController);
417
+ theme = inject(NgFluxThemeDirective);
418
+ options = input.required(/* @ts-ignore */
419
+ ...(ngDevMode ? [{ debugName: "options" }] : /* istanbul ignore next */ []));
420
+ constructor() {
421
+ const { ctrl } = this;
422
+ effect(() => {
423
+ const options = this.options();
424
+ this.theme.ngfTheme.set(options.theme);
425
+ });
426
+ effect(onCleanup => {
427
+ const options = this.options();
428
+ if (!options.timeout)
429
+ return;
430
+ const timeout = setTimeout(() => ctrl.remove(options), options.timeout);
431
+ onCleanup(() => clearTimeout(timeout));
432
+ });
433
+ }
434
+ close() {
435
+ const options = this.options();
436
+ this.ctrl.remove(options);
437
+ }
438
+ static ɵfac = i0.ɵɵngDeclareFactory({ minVersion: "12.0.0", version: "22.1.2", ngImport: i0, type: NgFluxToastComponent, deps: [], target: i0.ɵɵFactoryTarget.Component });
439
+ static ɵcmp = i0.ɵɵngDeclareComponent({ minVersion: "17.1.0", version: "22.1.2", type: NgFluxToastComponent, isStandalone: true, selector: "ngf-toast", inputs: { options: { classPropertyName: "options", publicName: "options", isSignal: true, isRequired: true, transformFunction: null } }, hostDirectives: [{ directive: NgFluxThemeDirective }], ngImport: i0, template: "<div class=\"wrapper\">\n <div class=\"content\" [innerHTML]=\"options().content\"></div>\n\n <div class=\"close-btn\" (click)=\"close()\">\n <i class=\"ngf-icon close\"></i>\n </div>\n</div>\n", styles: [":host{display:block;box-shadow:0 0 3px #000000b3;visibility:visible!important;padding:5px 10px;font-size:.8rem;transition:opacity .5s ease-in-out;opacity:0}:host .wrapper{display:flex;flex-direction:row;align-items:center;gap:10px}:host .wrapper>.content{display:block;flex:1 0 0;font-weight:500}:host .wrapper>.close-btn{display:block;cursor:pointer;padding:5px}\n"] });
440
+ }
441
+ i0.ɵɵngDeclareClassMetadata({ minVersion: "12.0.0", version: "22.1.2", ngImport: i0, type: NgFluxToastComponent, decorators: [{
442
+ type: Component,
443
+ args: [{ selector: 'ngf-toast', imports: [], hostDirectives: [
444
+ NgFluxThemeDirective,
445
+ ], template: "<div class=\"wrapper\">\n <div class=\"content\" [innerHTML]=\"options().content\"></div>\n\n <div class=\"close-btn\" (click)=\"close()\">\n <i class=\"ngf-icon close\"></i>\n </div>\n</div>\n", styles: [":host{display:block;box-shadow:0 0 3px #000000b3;visibility:visible!important;padding:5px 10px;font-size:.8rem;transition:opacity .5s ease-in-out;opacity:0}:host .wrapper{display:flex;flex-direction:row;align-items:center;gap:10px}:host .wrapper>.content{display:block;flex:1 0 0;font-weight:500}:host .wrapper>.close-btn{display:block;cursor:pointer;padding:5px}\n"] }]
446
+ }], ctorParameters: () => [], propDecorators: { options: [{ type: i0.Input, args: [{ isSignal: true, alias: "options", required: true }] }] } });
447
+
448
+ class NgFluxToastGroupComponent {
449
+ placement = input.required(/* @ts-ignore */
450
+ ...(ngDevMode ? [{ debugName: "placement" }] : /* istanbul ignore next */ []));
451
+ items = input.required(/* @ts-ignore */
452
+ ...(ngDevMode ? [{ debugName: "items" }] : /* istanbul ignore next */ []));
453
+ static ɵfac = i0.ɵɵngDeclareFactory({ minVersion: "12.0.0", version: "22.1.2", ngImport: i0, type: NgFluxToastGroupComponent, deps: [], target: i0.ɵɵFactoryTarget.Component });
454
+ static ɵcmp = i0.ɵɵngDeclareComponent({ minVersion: "17.0.0", version: "22.1.2", type: NgFluxToastGroupComponent, isStandalone: true, selector: "ngf-toast-group", inputs: { placement: { classPropertyName: "placement", publicName: "placement", isSignal: true, isRequired: true, transformFunction: null }, items: { classPropertyName: "items", publicName: "items", isSignal: true, isRequired: true, transformFunction: null } }, host: { properties: { "class": "placement()" } }, ngImport: i0, template: "<div class=\"wrapper\">\n @for (item of items(); track item) {\n <ngf-toast [options]=\"item\" animate.enter=\"fade-in\" animate.leave=\"fade-out\" />\n }\n</div>\n", styles: [":host{display:block;position:absolute;width:calc(100% - 2 * var(--ngf-toast-x));transition:opacity .5s ease-in-out;max-width:300px;--flex-direction: column}:host.topLeft{inset:var(--ngf-toast-y) auto auto var(--ngf-toast-x)}:host.topCenter{inset:var(--ngf-toast-y) auto auto 50%;transform:translate(-50%)}:host.topRight{inset:var(--ngf-toast-y) var(--ngf-toast-x) auto auto}:host.bottomLeft{inset:auto auto var(--ngf-toast-y) var(--ngf-toast-x);--flex-direction: column-reverse}:host.bottomCenter{inset:auto auto var(--ngf-toast-y) 50%;transform:translate(-50%);--flex-direction: column-reverse}:host.bottomRight{inset:auto var(--ngf-toast-x) var(--ngf-toast-y) auto;--flex-direction: column-reverse}:host .wrapper{display:flex;flex-direction:var(--flex-direction)!important;gap:10px}:host .wrapper .fade-in{opacity:1}:host .wrapper .fade-out{opacity:0}\n"], dependencies: [{ kind: "component", type: NgFluxToastComponent, selector: "ngf-toast", inputs: ["options"] }] });
455
+ }
456
+ i0.ɵɵngDeclareClassMetadata({ minVersion: "12.0.0", version: "22.1.2", ngImport: i0, type: NgFluxToastGroupComponent, decorators: [{
457
+ type: Component,
458
+ args: [{ selector: 'ngf-toast-group', imports: [
459
+ NgFluxToastComponent,
460
+ ], host: {
461
+ '[class]': 'placement()',
462
+ }, template: "<div class=\"wrapper\">\n @for (item of items(); track item) {\n <ngf-toast [options]=\"item\" animate.enter=\"fade-in\" animate.leave=\"fade-out\" />\n }\n</div>\n", styles: [":host{display:block;position:absolute;width:calc(100% - 2 * var(--ngf-toast-x));transition:opacity .5s ease-in-out;max-width:300px;--flex-direction: column}:host.topLeft{inset:var(--ngf-toast-y) auto auto var(--ngf-toast-x)}:host.topCenter{inset:var(--ngf-toast-y) auto auto 50%;transform:translate(-50%)}:host.topRight{inset:var(--ngf-toast-y) var(--ngf-toast-x) auto auto}:host.bottomLeft{inset:auto auto var(--ngf-toast-y) var(--ngf-toast-x);--flex-direction: column-reverse}:host.bottomCenter{inset:auto auto var(--ngf-toast-y) 50%;transform:translate(-50%);--flex-direction: column-reverse}:host.bottomRight{inset:auto var(--ngf-toast-x) var(--ngf-toast-y) auto;--flex-direction: column-reverse}:host .wrapper{display:flex;flex-direction:var(--flex-direction)!important;gap:10px}:host .wrapper .fade-in{opacity:1}:host .wrapper .fade-out{opacity:0}\n"] }]
463
+ }], propDecorators: { placement: [{ type: i0.Input, args: [{ isSignal: true, alias: "placement", required: true }] }], items: [{ type: i0.Input, args: [{ isSignal: true, alias: "items", required: true }] }] } });
464
+
465
+ class NgFluxToastRootComponent {
466
+ ctrl = inject(NgFluxToastController);
467
+ static ɵfac = i0.ɵɵngDeclareFactory({ minVersion: "12.0.0", version: "22.1.2", ngImport: i0, type: NgFluxToastRootComponent, deps: [], target: i0.ɵɵFactoryTarget.Component });
468
+ static ɵcmp = i0.ɵɵngDeclareComponent({ minVersion: "17.0.0", version: "22.1.2", type: NgFluxToastRootComponent, isStandalone: true, selector: "ngf-toast-root", ngImport: i0, template: "<div class=\"wrapper\">\n @for (item of ctrl.map() | keyvalue; track item.key) {\n <ngf-toast-group [placement]=\"item.key\" [items]=\"item.value\" animate.leave=\"fade-out\" />\n }\n</div>\n", styles: [":host{display:block;visibility:hidden;height:0px!important}:host .wrapper{display:block;position:fixed;visibility:hidden;z-index:var(--ngf-toast-z-index)!important;inset:0}:host .wrapper .fade-out{opacity:0}\n"], dependencies: [{ kind: "component", type: NgFluxToastGroupComponent, selector: "ngf-toast-group", inputs: ["placement", "items"] }, { kind: "pipe", type: KeyValuePipe, name: "keyvalue" }] });
469
+ }
470
+ i0.ɵɵngDeclareClassMetadata({ minVersion: "12.0.0", version: "22.1.2", ngImport: i0, type: NgFluxToastRootComponent, decorators: [{
471
+ type: Component,
472
+ args: [{ selector: 'ngf-toast-root', imports: [
473
+ KeyValuePipe,
474
+ NgFluxToastGroupComponent,
475
+ ], template: "<div class=\"wrapper\">\n @for (item of ctrl.map() | keyvalue; track item.key) {\n <ngf-toast-group [placement]=\"item.key\" [items]=\"item.value\" animate.leave=\"fade-out\" />\n }\n</div>\n", styles: [":host{display:block;visibility:hidden;height:0px!important}:host .wrapper{display:block;position:fixed;visibility:hidden;z-index:var(--ngf-toast-z-index)!important;inset:0}:host .wrapper .fade-out{opacity:0}\n"] }]
476
+ }] });
477
+
478
+ class NgFluxToastInitializer {
479
+ appRef = inject(ApplicationRef);
480
+ rootRef;
481
+ constructor() {
482
+ const { appRef } = this;
483
+ this.rootRef = createComponent(NgFluxToastRootComponent, {
484
+ environmentInjector: appRef.injector,
485
+ });
486
+ }
487
+ initialize() {
488
+ const { appRef, rootRef } = this;
489
+ appRef.attachView(rootRef.hostView);
490
+ const elem = rootRef.location.nativeElement;
491
+ document.body.appendChild(elem);
492
+ }
493
+ static ɵfac = i0.ɵɵngDeclareFactory({ minVersion: "12.0.0", version: "22.1.2", ngImport: i0, type: NgFluxToastInitializer, deps: [], target: i0.ɵɵFactoryTarget.Injectable });
494
+ static ɵprov = i0.ɵɵngDeclareInjectable({ minVersion: "12.0.0", version: "22.1.2", ngImport: i0, type: NgFluxToastInitializer, providedIn: 'root' });
495
+ }
496
+ i0.ɵɵngDeclareClassMetadata({ minVersion: "12.0.0", version: "22.1.2", ngImport: i0, type: NgFluxToastInitializer, decorators: [{
497
+ type: Injectable,
498
+ args: [{ providedIn: 'root' }]
499
+ }], ctorParameters: () => [] });
500
+
363
501
  class NgFluxDialogHeader {
364
502
  config = inject(NGF_DIALOG_CONFIG);
365
503
  dialogRef = inject(NgFluxDialogRef);
@@ -1609,7 +1747,7 @@ class NgFluxDialog {
1609
1747
  closeOnEsc: false,
1610
1748
  data
1611
1749
  });
1612
- return dialog.closed;
1750
+ return dialog.closed.pipe(map(resp => resp ?? false));
1613
1751
  }
1614
1752
  prompt(data) {
1615
1753
  const dialog = this.open(NgFluxPromptDialog, {
@@ -1628,6 +1766,68 @@ i0.ɵɵngDeclareClassMetadata({ minVersion: "12.0.0", version: "22.1.2", ngImpor
1628
1766
  args: [{ providedIn: 'root' }]
1629
1767
  }] });
1630
1768
 
1769
+ class NgFluxToast {
1770
+ config = inject(NGF_CONFIG);
1771
+ ctrl = inject(NgFluxToastController);
1772
+ show(options) {
1773
+ const config = this.config.toast;
1774
+ options.placement ??= config?.placement ?? 'topRight';
1775
+ options.showCloseButton ??= config?.showCloseButton ?? true;
1776
+ options.timeout ??= Math.max(config?.timeout ?? 5000, 0);
1777
+ options.theme ??= config?.theme ?? 'info';
1778
+ this.ctrl.add(options);
1779
+ }
1780
+ showDefault(options) {
1781
+ const opts = { ...options, theme: 'default' };
1782
+ return this.show(opts);
1783
+ }
1784
+ showPrimary(options) {
1785
+ const opts = { ...options, theme: 'primary' };
1786
+ return this.show(opts);
1787
+ }
1788
+ showSecondary(options) {
1789
+ const opts = { ...options, theme: 'secondary' };
1790
+ return this.show(opts);
1791
+ }
1792
+ showError(options) {
1793
+ const opts = { ...options, theme: 'error' };
1794
+ return this.show(opts);
1795
+ }
1796
+ showDanger(options) {
1797
+ const opts = { ...options, theme: 'danger' };
1798
+ return this.show(opts);
1799
+ }
1800
+ showSuccess(options) {
1801
+ const opts = { ...options, theme: 'success' };
1802
+ return this.show(opts);
1803
+ }
1804
+ showWarning(options) {
1805
+ const opts = { ...options, theme: 'warning' };
1806
+ return this.show(opts);
1807
+ }
1808
+ showInfo(options) {
1809
+ const opts = { ...options, theme: 'info' };
1810
+ return this.show(opts);
1811
+ }
1812
+ showLight(options) {
1813
+ const opts = { ...options, theme: 'light' };
1814
+ return this.show(opts);
1815
+ }
1816
+ showDark(options) {
1817
+ const opts = { ...options, theme: 'dark' };
1818
+ return this.show(opts);
1819
+ }
1820
+ static ɵfac = i0.ɵɵngDeclareFactory({ minVersion: "12.0.0", version: "22.1.2", ngImport: i0, type: NgFluxToast, deps: [], target: i0.ɵɵFactoryTarget.Injectable });
1821
+ static ɵprov = i0.ɵɵngDeclareInjectable({ minVersion: "12.0.0", version: "22.1.2", ngImport: i0, type: NgFluxToast, providedIn: 'root' });
1822
+ }
1823
+ i0.ɵɵngDeclareClassMetadata({ minVersion: "12.0.0", version: "22.1.2", ngImport: i0, type: NgFluxToast, decorators: [{
1824
+ type: Injectable,
1825
+ args: [{ providedIn: 'root' }]
1826
+ }] });
1827
+
1828
+ class ToastInstance {
1829
+ }
1830
+
1631
1831
  const provideNgFlux = (config) => {
1632
1832
  config ??= {};
1633
1833
  return makeEnvironmentProviders([
@@ -1638,6 +1838,9 @@ const provideNgFlux = (config) => {
1638
1838
  NgFluxLoading,
1639
1839
  NgFluxLoadingInternal,
1640
1840
  MetaInternal,
1841
+ NgFluxToast,
1842
+ NgFluxToastController,
1843
+ NgFluxToastInitializer,
1641
1844
  provideAppInitializer(() => {
1642
1845
  const meta = inject(MetaInternal);
1643
1846
  meta.initialize();
@@ -1651,6 +1854,10 @@ const provideNgFlux = (config) => {
1651
1854
  loading.initialize();
1652
1855
  loading.showOnRouteNavigation();
1653
1856
  }),
1857
+ provideAppInitializer(() => {
1858
+ const toast = inject(NgFluxToastInitializer);
1859
+ toast.initialize();
1860
+ }),
1654
1861
  ]);
1655
1862
  };
1656
1863
 
@@ -1710,5 +1917,5 @@ var NgFlux;
1710
1917
  * Generated bundle index. Do not edit.
1711
1918
  */
1712
1919
 
1713
- export { NGF_CONFIG, NGF_DIALOG_DATA, NgFlux, NgFluxActions, NgFluxButton, NgFluxDialog, NgFluxDialogBody, NgFluxDialogFooter, NgFluxDialogHeader, NgFluxDialogInstance, NgFluxDialogRef, NgFluxDialogRootComponent, NgFluxForm, NgFluxFormMessage, NgFluxFrame, NgFluxLoading, NgFluxLoadingRootComponent, NgFluxPagination, NgFluxPinInput, NgFluxSelect, NgFluxTab, NgFluxTabContentDirective, NgFluxTabGroup, NgFluxTabNavDirective, NgFluxTabNavbar, NgFluxTabPanel, provideNgFlux };
1920
+ export { NGF_CONFIG, NGF_DIALOG_DATA, NgFlux, NgFluxActions, NgFluxButton, NgFluxDialog, NgFluxDialogBody, NgFluxDialogFooter, NgFluxDialogHeader, NgFluxDialogInstance, NgFluxDialogRef, NgFluxForm, NgFluxFormMessage, NgFluxFrame, NgFluxLoading, NgFluxLoadingRootComponent, NgFluxPagination, NgFluxPinInput, NgFluxSelect, NgFluxTab, NgFluxTabContentDirective, NgFluxTabGroup, NgFluxTabNavDirective, NgFluxTabNavbar, NgFluxTabPanel, NgFluxThemeDirective, NgFluxToast, ToastInstance, provideNgFlux };
1714
1921
  //# sourceMappingURL=ngflux-ngflux.mjs.map