sagittarius-admin-template 0.2.0 → 0.2.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.
Files changed (25) hide show
  1. package/ng-package.json +11 -0
  2. package/package.json +3 -12
  3. package/src/lib/sagittarius-admin/drawer-component/drawer-component.html +1 -0
  4. package/src/lib/sagittarius-admin/drawer-component/drawer-component.scss +0 -0
  5. package/src/lib/sagittarius-admin/drawer-component/drawer-component.spec.ts +54 -0
  6. package/src/lib/sagittarius-admin/drawer-component/drawer-component.ts +123 -0
  7. package/src/lib/sagittarius-admin/drawer-component/drawer-content/drawer-content.html +23 -0
  8. package/src/lib/sagittarius-admin/drawer-component/drawer-content/drawer-content.scss +103 -0
  9. package/src/lib/sagittarius-admin/drawer-component/drawer-content/drawer-content.spec.ts +63 -0
  10. package/src/lib/sagittarius-admin/drawer-component/drawer-content/drawer-content.ts +67 -0
  11. package/src/lib/sagittarius-admin/drawer-ref.ts +26 -0
  12. package/src/lib/sagittarius-admin/drawer-service.ts +58 -0
  13. package/src/lib/sagittarius-admin/sagittarius-admin.html +150 -0
  14. package/src/lib/sagittarius-admin/sagittarius-admin.labels.ts +63 -0
  15. package/src/lib/sagittarius-admin/sagittarius-admin.models.ts +60 -0
  16. package/src/lib/sagittarius-admin/sagittarius-admin.scss +592 -0
  17. package/src/lib/sagittarius-admin/sagittarius-admin.spec.ts +45 -0
  18. package/src/lib/sagittarius-admin/sagittarius-admin.ts +159 -0
  19. package/src/public-api.ts +9 -0
  20. package/tsconfig.lib.json +18 -0
  21. package/tsconfig.lib.prod.json +11 -0
  22. package/tsconfig.spec.json +14 -0
  23. package/fesm2022/sagittarius-admin-template.mjs +0 -399
  24. package/fesm2022/sagittarius-admin-template.mjs.map +0 -1
  25. package/index.d.ts +0 -203
@@ -0,0 +1,159 @@
1
+ import { AfterViewInit, Component, HostListener, OnInit, ViewChild, computed, inject, input, output, signal } from '@angular/core';
2
+ import { MatButtonModule } from '@angular/material/button';
3
+ import { MatIconModule } from '@angular/material/icon';
4
+ import { MatMenuModule } from '@angular/material/menu';
5
+ import { RouterModule } from '@angular/router';
6
+ import { DrawerComponent } from './drawer-component/drawer-component';
7
+ import { DrawerService } from './drawer-service';
8
+ import { SG_ADMIN_LABELS } from './sagittarius-admin.labels';
9
+ import { SgMenuItem, SgUser, SgUserMenuItem } from './sagittarius-admin.models';
10
+
11
+ const MOBILE_BREAKPOINT = 800;
12
+ const COLLAPSED_STORAGE_KEY = 'sg-admin-sidebar-collapsed';
13
+
14
+ @Component({
15
+ selector: 'lib-sagittarius-admin',
16
+ imports: [
17
+ RouterModule,
18
+ MatIconModule,
19
+ MatButtonModule,
20
+ MatMenuModule,
21
+ DrawerComponent,
22
+ ],
23
+ templateUrl: './sagittarius-admin.html',
24
+ styleUrl: './sagittarius-admin.scss'
25
+ })
26
+ export class SagittariusAdmin implements OnInit, AfterViewInit {
27
+ /** Názov aplikácie v hlavičke sidebaru. */
28
+ readonly appTitle = input('Sagittarius');
29
+ /** Skratka zobrazená v zbalenom sidebare (default: iniciály z `appTitle`). */
30
+ readonly appShortTitle = input<string>();
31
+ /** URL loga; bez neho sa zobrazí farebný štvorec so skratkou. */
32
+ readonly logoUrl = input<string>();
33
+ /** Routa, kam vedie klik na logo. */
34
+ readonly homeRoute = input<string | any[]>('/');
35
+ readonly menuItems = input<SgMenuItem[]>([]);
36
+ readonly user = input<SgUser | null>(null);
37
+ readonly userMenuItems = input<SgUserMenuItem[]>([]);
38
+ /** Pamätať si zbalenie sidebaru v localStorage. */
39
+ readonly persistSidebarState = input(true);
40
+
41
+ /** Emituje sa pri kliknutí na položku user menu (popri jej `action`). */
42
+ readonly userMenuItemClick = output<SgUserMenuItem>();
43
+
44
+ /** Texty layoutu (`provideSgAdminLabels`). */
45
+ protected readonly labels = inject(SG_ADMIN_LABELS);
46
+
47
+ readonly isHandset = signal(false);
48
+ readonly sidebarOpen = signal(false);
49
+ readonly sidebarCollapsed = signal(false);
50
+ readonly hovered = signal(false);
51
+ readonly drawerOpen = signal(false);
52
+ private noHover = false;
53
+
54
+ /** Zbalenie platí len na desktope, na mobile je sidebar vždy v plnej šírke. */
55
+ readonly collapsed = computed(() => this.sidebarCollapsed() && !this.isHandset());
56
+
57
+ readonly shortTitle = computed(() => this.appShortTitle() ?? initials(this.appTitle()));
58
+ readonly userInitials = computed(() => {
59
+ const user = this.user();
60
+ return user ? user.initials ?? initials(user.name) : '';
61
+ });
62
+
63
+ @ViewChild(DrawerComponent) drawerComponent!: DrawerComponent;
64
+
65
+ constructor(private drawerService: DrawerService) { }
66
+
67
+ ngOnInit(): void {
68
+ if (this.persistSidebarState()) {
69
+ this.sidebarCollapsed.set(readStorage(COLLAPSED_STORAGE_KEY) === 'true');
70
+ }
71
+ this.calculateWidth();
72
+ }
73
+
74
+ ngAfterViewInit(): void {
75
+ this.drawerService.setHost(this.drawerComponent, this);
76
+ }
77
+
78
+ @HostListener('window:resize')
79
+ onResize() {
80
+ this.calculateWidth();
81
+ }
82
+
83
+ openSidebar() {
84
+ this.sidebarOpen.set(true);
85
+ }
86
+
87
+ closeSidebar() {
88
+ this.sidebarOpen.set(false);
89
+ }
90
+
91
+ toggleSidebar() {
92
+ this.sidebarCollapsed.update(v => !v);
93
+ if (this.persistSidebarState()) {
94
+ writeStorage(COLLAPSED_STORAGE_KEY, String(this.sidebarCollapsed()));
95
+ }
96
+ // Po prepnutí krátko ignorujeme hover, aby sa sidebar hneď znova nerozbalil
97
+ this.noHover = true;
98
+ this.hovered.set(false);
99
+ setTimeout(() => this.noHover = false, 300);
100
+ }
101
+
102
+ setHovered(value: boolean) {
103
+ if (!this.noHover) {
104
+ this.hovered.set(value);
105
+ }
106
+ }
107
+
108
+ onNavigate() {
109
+ if (this.isHandset()) {
110
+ this.closeSidebar();
111
+ }
112
+ }
113
+
114
+ onUserMenuItem(item: SgUserMenuItem) {
115
+ item.action?.();
116
+ this.userMenuItemClick.emit(item);
117
+ }
118
+
119
+ openDrawer() {
120
+ this.drawerOpen.set(true);
121
+ }
122
+
123
+ closeDrawer() {
124
+ this.drawerOpen.set(false);
125
+ }
126
+
127
+ private calculateWidth() {
128
+ const handset = window.innerWidth <= MOBILE_BREAKPOINT;
129
+ this.isHandset.set(handset);
130
+ if (!handset) {
131
+ this.sidebarOpen.set(false);
132
+ }
133
+ }
134
+ }
135
+
136
+ function initials(text: string): string {
137
+ return text
138
+ .split(/\s+/)
139
+ .filter(Boolean)
140
+ .slice(0, 2)
141
+ .map(w => w[0]!.toUpperCase())
142
+ .join('');
143
+ }
144
+
145
+ function readStorage(key: string): string | null {
146
+ try {
147
+ return localStorage.getItem(key);
148
+ } catch {
149
+ return null;
150
+ }
151
+ }
152
+
153
+ function writeStorage(key: string, value: string) {
154
+ try {
155
+ localStorage.setItem(key, value);
156
+ } catch {
157
+ // localStorage nemusí byť dostupný (privátny režim, SSR)
158
+ }
159
+ }
@@ -0,0 +1,9 @@
1
+ /*
2
+ * Public API Surface of sagittarius-admin-template
3
+ */
4
+
5
+ export * from './lib/sagittarius-admin/sagittarius-admin';
6
+ export * from './lib/sagittarius-admin/sagittarius-admin.models';
7
+ export * from './lib/sagittarius-admin/sagittarius-admin.labels';
8
+ export * from './lib/sagittarius-admin/drawer-service';
9
+ export * from './lib/sagittarius-admin/drawer-ref';
@@ -0,0 +1,18 @@
1
+ /* To learn more about Typescript configuration file: https://www.typescriptlang.org/docs/handbook/tsconfig-json.html. */
2
+ /* To learn more about Angular compiler options: https://angular.dev/reference/configs/angular-compiler-options. */
3
+ {
4
+ "extends": "../../tsconfig.json",
5
+ "compilerOptions": {
6
+ "outDir": "../../out-tsc/lib",
7
+ "declaration": true,
8
+ "declarationMap": true,
9
+ "inlineSources": true,
10
+ "types": []
11
+ },
12
+ "include": [
13
+ "src/**/*.ts"
14
+ ],
15
+ "exclude": [
16
+ "**/*.spec.ts"
17
+ ]
18
+ }
@@ -0,0 +1,11 @@
1
+ /* To learn more about Typescript configuration file: https://www.typescriptlang.org/docs/handbook/tsconfig-json.html. */
2
+ /* To learn more about Angular compiler options: https://angular.dev/reference/configs/angular-compiler-options. */
3
+ {
4
+ "extends": "./tsconfig.lib.json",
5
+ "compilerOptions": {
6
+ "declarationMap": false
7
+ },
8
+ "angularCompilerOptions": {
9
+ "compilationMode": "partial"
10
+ }
11
+ }
@@ -0,0 +1,14 @@
1
+ /* To learn more about Typescript configuration file: https://www.typescriptlang.org/docs/handbook/tsconfig-json.html. */
2
+ /* To learn more about Angular compiler options: https://angular.dev/reference/configs/angular-compiler-options. */
3
+ {
4
+ "extends": "../../tsconfig.json",
5
+ "compilerOptions": {
6
+ "outDir": "../../out-tsc/spec",
7
+ "types": [
8
+ "jasmine"
9
+ ]
10
+ },
11
+ "include": [
12
+ "src/**/*.ts"
13
+ ]
14
+ }