codefoxcore 0.0.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 (40) hide show
  1. package/README.md +24 -0
  2. package/esm2022/codefoxcore.mjs +5 -0
  3. package/esm2022/lib/classes/dialog.config.class.mjs +22 -0
  4. package/esm2022/lib/classes/dialog.injector.class.mjs +14 -0
  5. package/esm2022/lib/classes/dialog.ref.class.mjs +72 -0
  6. package/esm2022/lib/classes/index.mjs +4 -0
  7. package/esm2022/lib/interfaces.mjs +28 -0
  8. package/esm2022/lib/services/api.service.mjs +84 -0
  9. package/esm2022/lib/services/dialog.service.mjs +324 -0
  10. package/esm2022/lib/services/index.mjs +5 -0
  11. package/esm2022/lib/services/logger.service.mjs +62 -0
  12. package/esm2022/lib/services/message.service.mjs +174 -0
  13. package/esm2022/lib/tokens/alert.token.mjs +20 -0
  14. package/esm2022/lib/tokens/confirm.token.mjs +7 -0
  15. package/esm2022/lib/tokens/dialog.token.mjs +7 -0
  16. package/esm2022/lib/tokens/index.mjs +6 -0
  17. package/esm2022/lib/tokens/loglevel.token.mjs +8 -0
  18. package/esm2022/lib/tokens/message.token.mjs +14 -0
  19. package/esm2022/public-api.mjs +5 -0
  20. package/fesm2022/codefoxcore.mjs +820 -0
  21. package/fesm2022/codefoxcore.mjs.map +1 -0
  22. package/index.d.ts +5 -0
  23. package/lib/classes/dialog.config.class.d.ts +22 -0
  24. package/lib/classes/dialog.injector.class.d.ts +8 -0
  25. package/lib/classes/dialog.ref.class.d.ts +24 -0
  26. package/lib/classes/index.d.ts +3 -0
  27. package/lib/interfaces.d.ts +121 -0
  28. package/lib/services/api.service.d.ts +24 -0
  29. package/lib/services/dialog.service.d.ts +34 -0
  30. package/lib/services/index.d.ts +4 -0
  31. package/lib/services/logger.service.d.ts +17 -0
  32. package/lib/services/message.service.d.ts +76 -0
  33. package/lib/tokens/alert.token.d.ts +6 -0
  34. package/lib/tokens/confirm.token.d.ts +5 -0
  35. package/lib/tokens/dialog.token.d.ts +3 -0
  36. package/lib/tokens/index.d.ts +5 -0
  37. package/lib/tokens/loglevel.token.d.ts +3 -0
  38. package/lib/tokens/message.token.d.ts +3 -0
  39. package/package.json +25 -0
  40. package/public-api.d.ts +4 -0
@@ -0,0 +1,820 @@
1
+ import { Subject, filter, Observable, takeUntil, timer } from 'rxjs';
2
+ import { isPlatformBrowser } from '@angular/common';
3
+ import * as i0 from '@angular/core';
4
+ import { InjectionToken, inject, Injector, PLATFORM_ID, ApplicationRef, createComponent, Injectable } from '@angular/core';
5
+ import { Title } from '@angular/platform-browser';
6
+ import { HttpClient } from '@angular/common/http';
7
+
8
+ class DialogRef {
9
+ constructor() {
10
+ this.messageService = null;
11
+ this.dialogConfig = null;
12
+ this._onClose = new Subject();
13
+ this.onClose = this._onClose.asObservable();
14
+ this.onCloseValue = this._onClose.pipe(filter(result => result !== undefined && result !== null));
15
+ this.onCloseOnValue = (value) => this._onClose.pipe(filter(result => result === value));
16
+ this._onMessage = new Subject();
17
+ this.onMessage = this._onMessage.asObservable();
18
+ this._onDestroy = new Subject();
19
+ this.onDestroy = this._onDestroy.asObservable();
20
+ this.savedTitle = '';
21
+ this.title = null;
22
+ this.opened = new Date();
23
+ }
24
+ doClose(result, params = {}) {
25
+ if (params.message !== undefined && this.messageService !== null) {
26
+ this.messageService.show(params.message.title, params.message.message, params.message);
27
+ }
28
+ this._onClose.next(result);
29
+ }
30
+ close(result, params = {}) {
31
+ if (this.dialogConfig === null || this.dialogConfig.beforeClose === null) {
32
+ this.doClose(result, params);
33
+ return;
34
+ }
35
+ if (this.dialogConfig.beforeClose instanceof Promise) {
36
+ this.dialogConfig.beforeClose.then((value) => {
37
+ if (value) {
38
+ this.doClose(result, params);
39
+ }
40
+ }).catch(() => { });
41
+ return;
42
+ }
43
+ if (this.dialogConfig.beforeClose instanceof Observable) {
44
+ this.dialogConfig.beforeClose.pipe(takeUntil(this._onClose)).subscribe((value) => {
45
+ if (value) {
46
+ this.doClose(result, params);
47
+ }
48
+ });
49
+ return;
50
+ }
51
+ const beforeCloseResult = this.dialogConfig.beforeClose();
52
+ if (beforeCloseResult instanceof Promise) {
53
+ beforeCloseResult.then((value) => {
54
+ if (value) {
55
+ this.doClose(result, params);
56
+ }
57
+ }).catch(() => { });
58
+ return;
59
+ }
60
+ if (beforeCloseResult instanceof Observable) {
61
+ beforeCloseResult.pipe(takeUntil(this._onClose)).subscribe((value) => {
62
+ if (value) {
63
+ this.doClose(result, params);
64
+ }
65
+ });
66
+ return;
67
+ }
68
+ if (beforeCloseResult) {
69
+ this.doClose(result, params);
70
+ }
71
+ }
72
+ forceClose(result) {
73
+ this.doClose(result);
74
+ }
75
+ message(message) { this._onMessage.next(message); }
76
+ destroy() { this._onDestroy.next(undefined); }
77
+ }
78
+
79
+ class DialogConfig {
80
+ constructor() {
81
+ this.showCloseIcon = true;
82
+ this.beforeClose = null;
83
+ this.ignoreKeyUp = false;
84
+ this.data = {};
85
+ this.noPadding = false;
86
+ this.keepActiveElement = false;
87
+ this.containerClasses = [];
88
+ this.dialogClasses = [];
89
+ this.resolve = {};
90
+ this.title = null;
91
+ this.contentElement = null;
92
+ this.single = false;
93
+ this.width = null;
94
+ this.height = null;
95
+ }
96
+ getData(key, defaultOnUndefined = null) {
97
+ return this.data[key] !== undefined ? this.data[key] : defaultOnUndefined;
98
+ }
99
+ }
100
+
101
+ class DialogInjector {
102
+ constructor(_parentInjector, _additionalTokens) {
103
+ this._parentInjector = _parentInjector;
104
+ this._additionalTokens = _additionalTokens;
105
+ }
106
+ get(token, notFoundValue, _) {
107
+ const value = this._additionalTokens.get(token);
108
+ if (value) {
109
+ return value;
110
+ }
111
+ return this._parentInjector.get(token, notFoundValue);
112
+ }
113
+ }
114
+
115
+ const ALERT_DEFAULT_BUTTON_CONFIGURATION = new InjectionToken('Alert default button', {
116
+ factory: () => {
117
+ return {
118
+ label: 'alert.ok',
119
+ severity: 'success',
120
+ callback: ({ dialogRef }) => {
121
+ dialogRef.close();
122
+ },
123
+ focus: true,
124
+ translateLabel: true
125
+ };
126
+ }
127
+ });
128
+ const ALERT_CONFIGURATIONS = new InjectionToken('Alert configurations predefined', {
129
+ factory: () => {
130
+ return {};
131
+ }
132
+ });
133
+
134
+ const CF_PREDEFINED_DIALOGS = new InjectionToken('Predefined dialogs', {
135
+ factory: () => {
136
+ return {};
137
+ }
138
+ });
139
+
140
+ const CONFIRM_CONFIGURATIONS = new InjectionToken('Confirm configurations predefined', {
141
+ factory: () => {
142
+ return {};
143
+ }
144
+ });
145
+
146
+ var AcceptValidationMode;
147
+ (function (AcceptValidationMode) {
148
+ AcceptValidationMode["PATTERN"] = "PATTERN";
149
+ AcceptValidationMode["TEXT"] = "TEXT";
150
+ })(AcceptValidationMode || (AcceptValidationMode = {}));
151
+ var MessagePosition;
152
+ (function (MessagePosition) {
153
+ MessagePosition["TOP"] = "top";
154
+ MessagePosition["BOTTOM"] = "bottom";
155
+ })(MessagePosition || (MessagePosition = {}));
156
+ var MessageSeverity;
157
+ (function (MessageSeverity) {
158
+ MessageSeverity["SUCCESS"] = "success";
159
+ MessageSeverity["WARNING"] = "warning";
160
+ MessageSeverity["DANGER"] = "danger";
161
+ MessageSeverity["INFO"] = "info";
162
+ })(MessageSeverity || (MessageSeverity = {}));
163
+ var LogLevel;
164
+ (function (LogLevel) {
165
+ LogLevel[LogLevel["All"] = 0] = "All";
166
+ LogLevel[LogLevel["Debug"] = 1] = "Debug";
167
+ LogLevel[LogLevel["Info"] = 2] = "Info";
168
+ LogLevel[LogLevel["Warn"] = 3] = "Warn";
169
+ LogLevel[LogLevel["Error"] = 4] = "Error";
170
+ LogLevel[LogLevel["Fatal"] = 5] = "Fatal";
171
+ LogLevel[LogLevel["Off"] = 6] = "Off";
172
+ })(LogLevel || (LogLevel = {}));
173
+
174
+ const MESSAGE_DEFAULT_CONFIGURATION = new InjectionToken('Message default configuration', {
175
+ factory: () => {
176
+ return {
177
+ closeable: true,
178
+ lifetime: 3000,
179
+ position: MessagePosition.TOP,
180
+ severity: MessageSeverity.SUCCESS,
181
+ keepOnHover: false
182
+ };
183
+ }
184
+ });
185
+
186
+ const LOG_LEVEL = new InjectionToken('Log level', {
187
+ factory: () => {
188
+ return LogLevel.All;
189
+ }
190
+ });
191
+
192
+ class DialogService {
193
+ constructor() {
194
+ this.injector = inject(Injector);
195
+ this.predefinedConfirmConfigurations = inject(CONFIRM_CONFIGURATIONS);
196
+ this.predefinedAlertConfigurations = inject(ALERT_CONFIGURATIONS);
197
+ this.predefinedDialogs = inject(CF_PREDEFINED_DIALOGS);
198
+ this.title = inject(Title);
199
+ this.messageService = inject(MessageService);
200
+ this.dialogs = new Map();
201
+ this.openIndex = 1;
202
+ this.platformId = inject(PLATFORM_ID);
203
+ if (isPlatformBrowser(this.platformId)) {
204
+ document.addEventListener("keyup", (keyboardEvent) => {
205
+ if (keyboardEvent.key.toLowerCase() === 'escape') {
206
+ let lastOpenIndex = 0;
207
+ let lastOpenedDialogRef = null;
208
+ for (const [dialogRef, cfDialogComponentRefContainer] of this.dialogs.entries()) {
209
+ if (cfDialogComponentRefContainer.openIndex > lastOpenIndex) {
210
+ lastOpenIndex = cfDialogComponentRefContainer.openIndex;
211
+ lastOpenedDialogRef = dialogRef;
212
+ }
213
+ }
214
+ if (lastOpenedDialogRef !== null && lastOpenedDialogRef.dialogConfig !== null) {
215
+ if (lastOpenedDialogRef.dialogConfig.ignoreKeyUp || document.activeElement instanceof HTMLInputElement || document.activeElement instanceof HTMLTextAreaElement) {
216
+ return;
217
+ }
218
+ lastOpenedDialogRef.close();
219
+ }
220
+ }
221
+ });
222
+ }
223
+ }
224
+ async openPredefined(name, dialogConfiguration = {}) {
225
+ if (this.predefinedDialogs[name] === undefined) {
226
+ throw Error('Dialog with name "' + name + '" not found!');
227
+ }
228
+ const predefinedDialog = this.predefinedDialogs[name];
229
+ if (typeof predefinedDialog === 'function') {
230
+ return this.openImport(predefinedDialog, dialogConfiguration);
231
+ }
232
+ return this.openImport(predefinedDialog.component, { ...predefinedDialog.configuration, ...dialogConfiguration });
233
+ }
234
+ async openImport(component, dialogConfiguration = {}) {
235
+ return new Promise(async (resolve) => {
236
+ resolve(this.open(await component(), dialogConfiguration));
237
+ });
238
+ }
239
+ open(component, dialogConfiguration = {}) {
240
+ for (let dialog of this.dialogs.entries()) {
241
+ if ((dialogConfiguration.single && dialog[1].componentRef.componentType.name === component.name) ||
242
+ (dialog[0].dialogConfig !== null && dialog[0].dialogConfig.single && dialog[1].componentRef.componentType.name === component.name)) {
243
+ return dialog[0];
244
+ }
245
+ }
246
+ const dialogConfig = this.createDialogConfig(dialogConfiguration);
247
+ if (!dialogConfig.keepActiveElement) {
248
+ if (document.activeElement instanceof HTMLElement) {
249
+ document.activeElement.blur();
250
+ }
251
+ }
252
+ const dialogRef = this.appendToBody(component, dialogConfig);
253
+ dialogRef.messageService = this.messageService;
254
+ dialogRef.dialogConfig = dialogConfig;
255
+ this.changeAndStoreTitle(dialogRef);
256
+ return dialogRef;
257
+ }
258
+ changeAndStoreTitle(dialogRef) {
259
+ dialogRef.savedTitle = this.title.getTitle();
260
+ if (dialogRef.dialogConfig !== null && dialogRef.dialogConfig.title !== null) {
261
+ this.title.setTitle(dialogRef.dialogConfig.title);
262
+ }
263
+ }
264
+ createDialogConfig(dialogConfiguration) {
265
+ const dialogConfig = new DialogConfig();
266
+ if (dialogConfiguration.showCloseIcon !== undefined) {
267
+ dialogConfig.showCloseIcon = dialogConfiguration.showCloseIcon;
268
+ }
269
+ if (dialogConfiguration.beforeClose !== undefined) {
270
+ dialogConfig.beforeClose = dialogConfiguration.beforeClose;
271
+ }
272
+ if (dialogConfiguration.ignoreKeyUp !== undefined) {
273
+ dialogConfig.ignoreKeyUp = dialogConfiguration.ignoreKeyUp;
274
+ }
275
+ if (dialogConfiguration.data !== undefined) {
276
+ dialogConfig.data = dialogConfiguration.data;
277
+ }
278
+ if (dialogConfiguration.noPadding !== undefined) {
279
+ dialogConfig.noPadding = dialogConfiguration.noPadding;
280
+ }
281
+ if (dialogConfiguration.keepActiveElement !== undefined) {
282
+ dialogConfig.keepActiveElement = dialogConfiguration.keepActiveElement;
283
+ }
284
+ if (dialogConfiguration.containerClasses !== undefined) {
285
+ dialogConfig.containerClasses = dialogConfiguration.containerClasses;
286
+ }
287
+ if (dialogConfiguration.dialogClasses !== undefined) {
288
+ dialogConfig.dialogClasses = dialogConfiguration.dialogClasses;
289
+ }
290
+ if (dialogConfiguration.title !== undefined) {
291
+ dialogConfig.title = dialogConfiguration.title;
292
+ }
293
+ if (dialogConfiguration.contentElement !== undefined) {
294
+ dialogConfig.contentElement = dialogConfiguration.contentElement;
295
+ }
296
+ if (dialogConfiguration.single !== undefined) {
297
+ dialogConfig.single = dialogConfiguration.single;
298
+ }
299
+ if (dialogConfiguration.width !== undefined) {
300
+ dialogConfig.width = dialogConfiguration.width;
301
+ }
302
+ if (dialogConfiguration.height !== undefined) {
303
+ dialogConfig.height = dialogConfiguration.height;
304
+ }
305
+ return dialogConfig;
306
+ }
307
+ appendToBody(component, dialogConfig) {
308
+ const appRef = this.injector.get(ApplicationRef);
309
+ // CREATE INJECTION TOKENS
310
+ const tokens = new WeakMap();
311
+ // CREATE DIALOG CONFIGURATION CLASS
312
+ tokens.set(DialogConfig, dialogConfig);
313
+ // CREATE DIALOG REFERENCE CLASS
314
+ const dialogRef = new DialogRef();
315
+ tokens.set(DialogRef, dialogRef);
316
+ // LISTEN ON DIALOG CLOSE
317
+ const closeSub = dialogRef.onClose.subscribe(() => {
318
+ this.removeFromBody(dialogRef);
319
+ closeSub.unsubscribe();
320
+ });
321
+ // CREATE COMPONENT REF
322
+ const componentRef = createComponent(component, {
323
+ environmentInjector: appRef.injector,
324
+ elementInjector: new DialogInjector(this.injector, tokens)
325
+ });
326
+ // ATTACH VIEW TO ANGULAR
327
+ appRef.attachView(componentRef.hostView);
328
+ // CREATE DIALOG CONTAINER ELEMENT
329
+ const dialogContainer = document.createElement('div');
330
+ dialogContainer.classList.add('cf-dialog-container');
331
+ if (dialogConfig.containerClasses.length > 0) {
332
+ dialogContainer.classList.add(...dialogConfig.containerClasses);
333
+ }
334
+ // APPEND DOM ELEMENT TO DIALOG
335
+ const childDomElem = componentRef.hostView.rootNodes[0];
336
+ childDomElem.classList.add('cf-dialog');
337
+ if (dialogConfig.width !== null) {
338
+ childDomElem.style.width = dialogConfig.width;
339
+ }
340
+ if (dialogConfig.height !== null) {
341
+ childDomElem.style.height = dialogConfig.height;
342
+ }
343
+ if (dialogConfig.noPadding) {
344
+ childDomElem.classList.add('no-padding');
345
+ }
346
+ if (dialogConfig.dialogClasses.length > 0) {
347
+ childDomElem.classList.add(...dialogConfig.dialogClasses);
348
+ }
349
+ if (dialogConfig.contentElement !== null) {
350
+ childDomElem.appendChild(dialogConfig.contentElement);
351
+ }
352
+ dialogContainer.appendChild(childDomElem);
353
+ // CLOSEABLE? APPEND BUTTON
354
+ if (dialogConfig.showCloseIcon) {
355
+ const closeElement = document.createElement('div');
356
+ closeElement.classList.add(...['cf-dialog-close', 'remixicon', 'close-line']);
357
+ closeElement.onclick = () => {
358
+ dialogRef.close();
359
+ };
360
+ childDomElem.appendChild(closeElement);
361
+ }
362
+ // APPEND DIALOG CONTAINER TO BODY
363
+ document.body.appendChild(dialogContainer);
364
+ this.dialogs.set(dialogRef, {
365
+ componentRef,
366
+ container: dialogContainer,
367
+ openIndex: this.openIndex
368
+ });
369
+ this.openIndex++;
370
+ return dialogRef;
371
+ }
372
+ removeFromBody(dialogRef) {
373
+ const appRef = this.injector.get(ApplicationRef);
374
+ if (!dialogRef || !this.dialogs.has(dialogRef)) {
375
+ return;
376
+ }
377
+ const dialogComponentRefContainer = this.dialogs.get(dialogRef);
378
+ if (dialogComponentRefContainer == undefined) {
379
+ return;
380
+ }
381
+ appRef.detachView(dialogComponentRefContainer.componentRef.hostView);
382
+ if (dialogComponentRefContainer.container !== null) {
383
+ dialogComponentRefContainer.container.remove();
384
+ }
385
+ dialogComponentRefContainer.componentRef.destroy();
386
+ this.dialogs.delete(dialogRef);
387
+ if (this.dialogs.size === 0) {
388
+ this.openIndex = 1;
389
+ }
390
+ // Restore title
391
+ if (this.dialogs.size === 0) {
392
+ this.title.setTitle(dialogRef.savedTitle);
393
+ }
394
+ else {
395
+ let latestOpenedDialogRef = null;
396
+ this.dialogs.forEach((_, dialogRef) => {
397
+ if (latestOpenedDialogRef === null) {
398
+ latestOpenedDialogRef = dialogRef;
399
+ }
400
+ else {
401
+ if (latestOpenedDialogRef.opened < dialogRef.opened) {
402
+ latestOpenedDialogRef = dialogRef;
403
+ }
404
+ }
405
+ });
406
+ if (latestOpenedDialogRef !== null) {
407
+ //this.title.setTitle(latestOpenedDialogRef.savedTitle);
408
+ }
409
+ else {
410
+ this.title.setTitle(dialogRef.savedTitle);
411
+ }
412
+ }
413
+ }
414
+ confirm(configuration, dialogConfiguration = {}, component) {
415
+ if (typeof configuration === 'string') {
416
+ const predefinedConfirmConfiguration = this.predefinedConfirmConfigurations[configuration];
417
+ if (predefinedConfirmConfiguration === undefined) {
418
+ throw new Error('Predefined confirm configuration not found for: ' + configuration);
419
+ }
420
+ configuration = predefinedConfirmConfiguration;
421
+ }
422
+ return new Promise((resolve, reject) => {
423
+ this.open(component, {
424
+ ...dialogConfiguration,
425
+ data: {
426
+ configuration
427
+ },
428
+ ignoreKeyUp: true,
429
+ showCloseIcon: false
430
+ }).onClose.pipe(filter(value => value !== undefined)).subscribe((accepted) => {
431
+ if (accepted) {
432
+ resolve(true);
433
+ }
434
+ else {
435
+ reject(true);
436
+ }
437
+ });
438
+ });
439
+ }
440
+ async confirmAsync(configuration, dialogConfiguration = {}, component) {
441
+ return await new Promise((resolve) => {
442
+ this.confirm(configuration, dialogConfiguration, component).then(() => {
443
+ resolve(true);
444
+ }).catch(() => {
445
+ resolve(false);
446
+ });
447
+ });
448
+ }
449
+ confirmAccept(configuration, dialogConfiguration = {}, component) {
450
+ return new Promise((resolve) => {
451
+ this.confirm(configuration, dialogConfiguration, component).then(() => resolve(true)).catch(() => { });
452
+ });
453
+ }
454
+ confirmDecline(configuration, dialogConfiguration = {}, component) {
455
+ return new Promise((resolve) => {
456
+ this.confirm(configuration, dialogConfiguration, component).then(() => { }).catch(() => resolve(true));
457
+ });
458
+ }
459
+ showLoading(configuration, dialogConfiguration = {}, component) {
460
+ return this.open(component, {
461
+ ...dialogConfiguration,
462
+ showCloseIcon: false,
463
+ ignoreKeyUp: true,
464
+ data: {
465
+ configuration
466
+ }
467
+ });
468
+ }
469
+ showAlert(configuration, dialogConfiguration = {}, component) {
470
+ if (typeof configuration === 'string') {
471
+ const predefinedAlertConfiguration = this.predefinedAlertConfigurations[configuration];
472
+ if (predefinedAlertConfiguration === undefined) {
473
+ throw new Error('Predefined alert configuration not found for: ' + configuration);
474
+ }
475
+ configuration = predefinedAlertConfiguration;
476
+ }
477
+ return new Promise((resolve) => {
478
+ return this.open(component, {
479
+ ...dialogConfiguration,
480
+ data: {
481
+ configuration
482
+ },
483
+ ignoreKeyUp: true,
484
+ showCloseIcon: false
485
+ }).onClose.subscribe(() => {
486
+ resolve();
487
+ });
488
+ });
489
+ }
490
+ showModalWithButtons(configuration, dialogConfiguration = {}, component) {
491
+ return this.open(component, {
492
+ ...dialogConfiguration,
493
+ data: {
494
+ configuration
495
+ }
496
+ });
497
+ }
498
+ static { this.ɵfac = i0.ɵɵngDeclareFactory({ minVersion: "12.0.0", version: "16.2.12", ngImport: i0, type: DialogService, deps: [], target: i0.ɵɵFactoryTarget.Injectable }); }
499
+ static { this.ɵprov = i0.ɵɵngDeclareInjectable({ minVersion: "12.0.0", version: "16.2.12", ngImport: i0, type: DialogService, providedIn: 'root' }); }
500
+ }
501
+ i0.ɵɵngDeclareClassMetadata({ minVersion: "12.0.0", version: "16.2.12", ngImport: i0, type: DialogService, decorators: [{
502
+ type: Injectable,
503
+ args: [{
504
+ providedIn: 'root'
505
+ }]
506
+ }], ctorParameters: function () { return []; } });
507
+
508
+ class MessageService {
509
+ /**
510
+ * Show
511
+ *
512
+ * Displays message with the given configuration
513
+ *
514
+ * @param messageConfiguration `Partial<MessageConfiguration>`
515
+ */
516
+ show(title, message, configuration) {
517
+ this.messageSubject.next({
518
+ ...this.defaultConfiguration,
519
+ ...configuration,
520
+ title,
521
+ message
522
+ });
523
+ }
524
+ /**
525
+ * Show success message
526
+ *
527
+ * Display a message with default success severity
528
+ *
529
+ * @param title `string`, required
530
+ * @param message `string`, required
531
+ * @param lifetime `number`, optional, default is `this.defaultLifetime`
532
+ * @param position `MessagePosition`, optional, default is `this.defaultPosition`
533
+ * @param closeable `boolean`, optional, default is `this.defaultClosable`
534
+ */
535
+ showSuccessMessage(title, message, configuration) {
536
+ this.show(title, message, {
537
+ ...configuration,
538
+ severity: MessageSeverity.SUCCESS
539
+ });
540
+ }
541
+ /**
542
+ * Show danger message
543
+ *
544
+ * Display a message with default danger severity
545
+ *
546
+ * @param title `string`, required
547
+ * @param message `string`, required
548
+ * @param lifetime `number`, optional, default is `this.defaultLifetime`
549
+ * @param position `MessagePosition`, optional, default is `this.defaultPosition`
550
+ * @param closeable `boolean`, optional, default is `this.defaultClosable`
551
+ */
552
+ showDangerMessage(title, message, configuration) {
553
+ this.show(title, message, {
554
+ ...configuration,
555
+ severity: MessageSeverity.DANGER,
556
+ keepOnHover: true
557
+ });
558
+ }
559
+ /**
560
+ * Show warning message
561
+ *
562
+ * Display a message with default warning severity
563
+ *
564
+ * @param title `string`, required
565
+ * @param message `string`, required
566
+ * @param lifetime `number`, optional, default is `this.defaultLifetime`
567
+ * @param position `MessagePosition`, optional, default is `this.defaultPosition`
568
+ * @param closeable `boolean`, optional, default is `this.defaultClosable`
569
+ */
570
+ showWarningMessage(title, message, configuration) {
571
+ this.show(title, message, {
572
+ ...configuration,
573
+ severity: MessageSeverity.WARNING
574
+ });
575
+ }
576
+ /**
577
+ * Show info message
578
+ *
579
+ * Display a message with default info severity
580
+ *
581
+ * @param title `string`, required
582
+ * @param message `string`, required
583
+ * @param lifetime `number`, optional, default is `this.defaultLifetime`
584
+ * @param position `MessagePosition`, optional, default is `this.defaultPosition`
585
+ * @param closeable `boolean`, optional, default is `this.defaultClosable`
586
+ */
587
+ showInfoMessage(title, message, configuration) {
588
+ this.show(title, message, {
589
+ ...configuration,
590
+ severity: MessageSeverity.INFO
591
+ });
592
+ }
593
+ showMessage(message) {
594
+ let container = document.getElementById('cf-toasts-' + message.position + '-container');
595
+ if (container === null) {
596
+ container = document.createElement('div');
597
+ container.id = 'cf-toasts-' + message.position + '-container';
598
+ document.body.appendChild(container);
599
+ }
600
+ const div = this.createMessageHtmlElement(message);
601
+ container.appendChild(div);
602
+ if (message.lifetime !== null) {
603
+ let disposeTimerSubscription = timer(message.lifetime + 500).subscribe(() => {
604
+ this.hideMessage(div);
605
+ });
606
+ if (message.keepOnHover) {
607
+ div.addEventListener('mouseenter', () => {
608
+ if (disposeTimerSubscription !== null) {
609
+ disposeTimerSubscription.unsubscribe();
610
+ disposeTimerSubscription = null;
611
+ }
612
+ });
613
+ }
614
+ }
615
+ }
616
+ createMessageHtmlElement(message) {
617
+ const div = document.createElement('div');
618
+ div.classList.add('cf-toast', 'cf-' + message.severity + '-toast');
619
+ const titleDiv = document.createElement('div');
620
+ titleDiv.classList.add('cf-toast-title');
621
+ titleDiv.innerText = message.title;
622
+ const messageDiv = document.createElement('div');
623
+ messageDiv.classList.add('cf-toast-message');
624
+ messageDiv.innerText = message.message;
625
+ div.appendChild(titleDiv);
626
+ div.appendChild(messageDiv);
627
+ if (message.closeable) {
628
+ const closeIcon = document.createElement('i');
629
+ closeIcon.classList.add('close-icon', 'remixicon', 'close-line');
630
+ closeIcon.onclick = () => {
631
+ this.hideMessage(div, true);
632
+ };
633
+ div.appendChild(closeIcon);
634
+ }
635
+ return div;
636
+ }
637
+ hideMessage(messageElement, forceClose = false) {
638
+ messageElement.classList.add('hidden-toast');
639
+ let remainOpen = false;
640
+ messageElement.addEventListener('mouseenter', (() => {
641
+ remainOpen = true;
642
+ }));
643
+ timer(500).subscribe(() => {
644
+ if (remainOpen && !forceClose) {
645
+ messageElement.classList.remove('hidden-toast');
646
+ return;
647
+ }
648
+ messageElement.removeEventListener('mouseenter', (() => { }));
649
+ messageElement.remove();
650
+ });
651
+ }
652
+ constructor() {
653
+ /**
654
+ * Default configuration
655
+ *
656
+ * Can be changed if you overwrite it or use the `MESSAGE_DEFAULT_CONFIGURATION` InjectionToken
657
+ */
658
+ this.defaultConfiguration = inject(MESSAGE_DEFAULT_CONFIGURATION);
659
+ /**
660
+ * Message subject
661
+ */
662
+ this.messageSubject = new Subject();
663
+ this.messageSubject.subscribe((message) => {
664
+ this.showMessage(message);
665
+ });
666
+ }
667
+ static { this.ɵfac = i0.ɵɵngDeclareFactory({ minVersion: "12.0.0", version: "16.2.12", ngImport: i0, type: MessageService, deps: [], target: i0.ɵɵFactoryTarget.Injectable }); }
668
+ static { this.ɵprov = i0.ɵɵngDeclareInjectable({ minVersion: "12.0.0", version: "16.2.12", ngImport: i0, type: MessageService, providedIn: 'root' }); }
669
+ }
670
+ i0.ɵɵngDeclareClassMetadata({ minVersion: "12.0.0", version: "16.2.12", ngImport: i0, type: MessageService, decorators: [{
671
+ type: Injectable,
672
+ args: [{
673
+ providedIn: 'root'
674
+ }]
675
+ }], ctorParameters: function () { return []; } });
676
+
677
+ class LoggerService {
678
+ constructor() {
679
+ this._logLevel = inject(LOG_LEVEL);
680
+ this.logLevelColors = [
681
+ '',
682
+ 'background-color: #D2BDF3; padding: 5px 10px;',
683
+ 'background-color: #A2DDFF; padding: 5px 10px;',
684
+ 'background-color: #FFD5C5; padding: 5px 10px;',
685
+ 'background-color: #EA4331; color: #FFFFFF; padding: 5px 10px;',
686
+ 'background-color: #F71900; color: #FFFFFF; padding: 5px 10px;',
687
+ ''
688
+ ];
689
+ }
690
+ debug(log, group = false) {
691
+ this.log({ log, logLevel: LogLevel.Debug, group });
692
+ }
693
+ info(log, group = false) {
694
+ this.log({ log, logLevel: LogLevel.Info, group });
695
+ }
696
+ warn(log, group = false) {
697
+ this.log({ log, logLevel: LogLevel.Warn, group });
698
+ }
699
+ error(log, group = false) {
700
+ this.log({ log, logLevel: LogLevel.Error, group });
701
+ }
702
+ fatal(log, group = false) {
703
+ this.log({ log, logLevel: LogLevel.Fatal, group });
704
+ }
705
+ groupEnd() {
706
+ console.groupEnd();
707
+ }
708
+ log(configuration) {
709
+ if (this._logLevel === null || this._logLevel === LogLevel.Off || this._logLevel > configuration.logLevel) {
710
+ return;
711
+ }
712
+ if (configuration.group) {
713
+ console.group(configuration.log);
714
+ }
715
+ else {
716
+ console.log('%c' + configuration.log, this.logLevelColors[configuration.logLevel]);
717
+ }
718
+ }
719
+ set logLevel(logLevel) {
720
+ this._logLevel = logLevel;
721
+ }
722
+ get logLevel() {
723
+ return this._logLevel;
724
+ }
725
+ static { this.ɵfac = i0.ɵɵngDeclareFactory({ minVersion: "12.0.0", version: "16.2.12", ngImport: i0, type: LoggerService, deps: [], target: i0.ɵɵFactoryTarget.Injectable }); }
726
+ static { this.ɵprov = i0.ɵɵngDeclareInjectable({ minVersion: "12.0.0", version: "16.2.12", ngImport: i0, type: LoggerService, providedIn: 'root' }); }
727
+ }
728
+ i0.ɵɵngDeclareClassMetadata({ minVersion: "12.0.0", version: "16.2.12", ngImport: i0, type: LoggerService, decorators: [{
729
+ type: Injectable,
730
+ args: [{
731
+ providedIn: 'root'
732
+ }]
733
+ }] });
734
+
735
+ class ApiService {
736
+ constructor() {
737
+ this.httpClient = inject(HttpClient);
738
+ this.loggerService = inject(LoggerService);
739
+ this._apiBaseUrl = null;
740
+ }
741
+ post(endPoint, body) {
742
+ return this.httpClient.post(this.generateUrl(endPoint), body);
743
+ }
744
+ get(endPoint) {
745
+ return this.httpClient.get(this.generateUrl(endPoint));
746
+ }
747
+ getFileArrayBuffer(endPoint) {
748
+ return this.httpClient.get(this.generateUrl(endPoint), {
749
+ responseType: 'arraybuffer'
750
+ });
751
+ }
752
+ getFileText(endPoint) {
753
+ return this.httpClient.get(this.generateUrl(endPoint), {
754
+ responseType: 'text'
755
+ });
756
+ }
757
+ getWithHttpParams(endPoint, params = null) {
758
+ if (params === null) {
759
+ return this.get(endPoint);
760
+ }
761
+ else {
762
+ return this.httpClient.get(this.generateUrl(endPoint), {
763
+ params
764
+ });
765
+ }
766
+ }
767
+ delete(endPoint) {
768
+ return this.httpClient.delete(this.generateUrl(endPoint));
769
+ }
770
+ patch(endPoint, body) {
771
+ return this.httpClient.patch(this.generateUrl(endPoint), body);
772
+ }
773
+ head(endPoint) {
774
+ return this.httpClient.head(this.generateUrl(endPoint));
775
+ }
776
+ options(endPoint) {
777
+ return this.httpClient.options(this.generateUrl(endPoint));
778
+ }
779
+ put(endPoint, body) {
780
+ return this.httpClient.put(this.generateUrl(endPoint), body);
781
+ }
782
+ generateUrl(endPoint) {
783
+ if (this._apiBaseUrl === null) {
784
+ throw new Error('No API base url set in generateUrl call!');
785
+ }
786
+ if (endPoint.length === 0) {
787
+ return this._apiBaseUrl;
788
+ }
789
+ if (typeof endPoint[0] === 'string' && endPoint[0].startsWith('#')) {
790
+ endPoint[0] = endPoint[0].slice(1);
791
+ return endPoint.map((v, i) => i === 0 ? v : encodeURIComponent(v)).join('/');
792
+ }
793
+ return [this._apiBaseUrl, ...endPoint.map((v) => encodeURIComponent(v))].join('/');
794
+ }
795
+ set apiBaseUrl(apiBaseUrl) {
796
+ this.loggerService.info('Api Service base url set to: ' + apiBaseUrl);
797
+ if (apiBaseUrl[apiBaseUrl.length - 1] === '/') {
798
+ apiBaseUrl = apiBaseUrl.slice(0, apiBaseUrl.length - 1);
799
+ }
800
+ this._apiBaseUrl = apiBaseUrl;
801
+ }
802
+ get apiBaseUrl() {
803
+ return this._apiBaseUrl;
804
+ }
805
+ static { this.ɵfac = i0.ɵɵngDeclareFactory({ minVersion: "12.0.0", version: "16.2.12", ngImport: i0, type: ApiService, deps: [], target: i0.ɵɵFactoryTarget.Injectable }); }
806
+ static { this.ɵprov = i0.ɵɵngDeclareInjectable({ minVersion: "12.0.0", version: "16.2.12", ngImport: i0, type: ApiService, providedIn: 'root' }); }
807
+ }
808
+ i0.ɵɵngDeclareClassMetadata({ minVersion: "12.0.0", version: "16.2.12", ngImport: i0, type: ApiService, decorators: [{
809
+ type: Injectable,
810
+ args: [{
811
+ providedIn: 'root'
812
+ }]
813
+ }] });
814
+
815
+ /**
816
+ * Generated bundle index. Do not edit.
817
+ */
818
+
819
+ export { ALERT_CONFIGURATIONS, ALERT_DEFAULT_BUTTON_CONFIGURATION, AcceptValidationMode, ApiService, CF_PREDEFINED_DIALOGS, CONFIRM_CONFIGURATIONS, DialogConfig, DialogInjector, DialogRef, DialogService, LOG_LEVEL, LogLevel, LoggerService, MESSAGE_DEFAULT_CONFIGURATION, MessagePosition, MessageService, MessageSeverity };
820
+ //# sourceMappingURL=codefoxcore.mjs.map