@ship-ui/core 0.14.2 → 0.14.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.
- package/fesm2022/ship-ui-core.mjs +37 -25
- package/fesm2022/ship-ui-core.mjs.map +1 -1
- package/index.d.ts +5 -1
- package/package.json +1 -1
|
@@ -1,5 +1,6 @@
|
|
|
1
1
|
import * as i0 from '@angular/core';
|
|
2
|
-
import { inject, ElementRef, Renderer2, ChangeDetectionStrategy, Component, input, computed, viewChild, effect, HostListener, NgModule,
|
|
2
|
+
import { inject, ElementRef, Renderer2, ChangeDetectionStrategy, Component, signal, DestroyRef, input, computed, viewChild, effect, HostListener, NgModule, Injectable, InjectionToken, model, output, ApplicationRef, createComponent, isSignal, OutputEmitterRef, contentChildren, afterNextRender, assertInInjectionContext, Injector, HostBinding, contentChild, TemplateRef, runInInjectionContext, Directive, ChangeDetectorRef, viewChildren, ViewContainerRef, EnvironmentInjector } from '@angular/core';
|
|
3
|
+
import { SHIP_CONFIG as SHIP_CONFIG$1 } from 'ship-ui';
|
|
3
4
|
import { DatePipe, NgTemplateOutlet } from '@angular/common';
|
|
4
5
|
import { SIGNAL } from '@angular/core/primitives/signals';
|
|
5
6
|
|
|
@@ -34,13 +35,45 @@ i0.ɵɵngDeclareClassMetadata({ minVersion: "12.0.0", version: "20.1.6", ngImpor
|
|
|
34
35
|
}]
|
|
35
36
|
}] });
|
|
36
37
|
|
|
38
|
+
function classMutationSignal() {
|
|
39
|
+
const element = inject(ElementRef).nativeElement;
|
|
40
|
+
if (!element)
|
|
41
|
+
return signal('');
|
|
42
|
+
const classListSignal = signal(element.className, ...(ngDevMode ? [{ debugName: "classListSignal" }] : []));
|
|
43
|
+
if (typeof MutationObserver === 'undefined')
|
|
44
|
+
return classListSignal.asReadonly();
|
|
45
|
+
const destroyRef = inject(DestroyRef);
|
|
46
|
+
const observer = new MutationObserver((mutations) => {
|
|
47
|
+
for (const mutation of mutations) {
|
|
48
|
+
if (mutation.type === 'attributes' && mutation.attributeName === 'class') {
|
|
49
|
+
const target = mutation.target;
|
|
50
|
+
classListSignal.set(target.className);
|
|
51
|
+
}
|
|
52
|
+
}
|
|
53
|
+
});
|
|
54
|
+
observer.observe(element, { attributes: true });
|
|
55
|
+
destroyRef.onDestroy(() => observer.disconnect());
|
|
56
|
+
return classListSignal.asReadonly();
|
|
57
|
+
}
|
|
58
|
+
|
|
59
|
+
const POSSIBLE_VARIANTS = ['simple', 'outlined', 'flat', 'raised'];
|
|
37
60
|
class ShipAlertComponent {
|
|
38
61
|
constructor() {
|
|
62
|
+
this.#shConfig = inject(SHIP_CONFIG$1, { optional: true });
|
|
63
|
+
this.variant = signal(this.#shConfig?.alertVariant ?? '', ...(ngDevMode ? [{ debugName: "variant" }] : []));
|
|
39
64
|
this._el = inject(ElementRef); // Used by alert container
|
|
40
65
|
this.alertService = input(null, ...(ngDevMode ? [{ debugName: "alertService" }] : []));
|
|
41
66
|
this.id = input(null, ...(ngDevMode ? [{ debugName: "id" }] : []));
|
|
42
|
-
this.
|
|
67
|
+
this.currentClasses = classMutationSignal();
|
|
68
|
+
this.activeClass = computed(() => {
|
|
69
|
+
const variant = this.variant();
|
|
70
|
+
if (!variant)
|
|
71
|
+
return this.currentClasses();
|
|
72
|
+
const hasVariant = POSSIBLE_VARIANTS.find((x) => this.currentClasses().includes(x));
|
|
73
|
+
return hasVariant ? this.currentClasses() : `${this.currentClasses()} ${variant}`;
|
|
74
|
+
}, ...(ngDevMode ? [{ debugName: "activeClass" }] : []));
|
|
43
75
|
}
|
|
76
|
+
#shConfig;
|
|
44
77
|
removeAlert() {
|
|
45
78
|
if (this.id() && this.alertService()) {
|
|
46
79
|
this.alertService()?.removeAlert(this.id());
|
|
@@ -55,7 +88,7 @@ class ShipAlertComponent {
|
|
|
55
88
|
</div>
|
|
56
89
|
|
|
57
90
|
<div class="icon">
|
|
58
|
-
@let _alertClasses =
|
|
91
|
+
@let _alertClasses = currentClasses();
|
|
59
92
|
|
|
60
93
|
@if (_alertClasses.includes('primary')) {
|
|
61
94
|
<sh-icon class="state-icon">info</sh-icon>
|
|
@@ -101,7 +134,7 @@ i0.ɵɵngDeclareClassMetadata({ minVersion: "12.0.0", version: "20.1.6", ngImpor
|
|
|
101
134
|
</div>
|
|
102
135
|
|
|
103
136
|
<div class="icon">
|
|
104
|
-
@let _alertClasses =
|
|
137
|
+
@let _alertClasses = currentClasses();
|
|
105
138
|
|
|
106
139
|
@if (_alertClasses.includes('primary')) {
|
|
107
140
|
<sh-icon class="state-icon">info</sh-icon>
|
|
@@ -574,27 +607,6 @@ i0.ɵɵngDeclareClassMetadata({ minVersion: "12.0.0", version: "20.1.6", ngImpor
|
|
|
574
607
|
}]
|
|
575
608
|
}] });
|
|
576
609
|
|
|
577
|
-
function classMutationSignal() {
|
|
578
|
-
const element = inject(ElementRef).nativeElement;
|
|
579
|
-
if (!element)
|
|
580
|
-
return signal('');
|
|
581
|
-
const classListSignal = signal(element.className, ...(ngDevMode ? [{ debugName: "classListSignal" }] : []));
|
|
582
|
-
if (typeof MutationObserver === 'undefined')
|
|
583
|
-
return classListSignal.asReadonly();
|
|
584
|
-
const destroyRef = inject(DestroyRef);
|
|
585
|
-
const observer = new MutationObserver((mutations) => {
|
|
586
|
-
for (const mutation of mutations) {
|
|
587
|
-
if (mutation.type === 'attributes' && mutation.attributeName === 'class') {
|
|
588
|
-
const target = mutation.target;
|
|
589
|
-
classListSignal.set(target.className);
|
|
590
|
-
}
|
|
591
|
-
}
|
|
592
|
-
});
|
|
593
|
-
observer.observe(element, { attributes: true });
|
|
594
|
-
destroyRef.onDestroy(() => observer.disconnect());
|
|
595
|
-
return classListSignal.asReadonly();
|
|
596
|
-
}
|
|
597
|
-
|
|
598
610
|
class ShipCheckboxComponent {
|
|
599
611
|
constructor() {
|
|
600
612
|
this.currentClassList = classMutationSignal();
|