@sd-angular/core 19.0.9 → 19.0.11

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 (150) hide show
  1. package/README.md +21 -21
  2. package/assets/STYLE-GUIDE.md +19 -19
  3. package/assets/fonts/fonts.scss +115 -115
  4. package/assets/scss/core/scrollbar.scss +30 -30
  5. package/assets/scss/core/utilities/_grid.scss +25 -19
  6. package/components/form-generic/src/components/form-builder/components/attribute-table/attribute-table.component.d.ts +2 -4
  7. package/components/form-generic/src/components/form-builder/components/attribute-template/attribute-template.component.d.ts +2 -4
  8. package/components/form-generic/src/components/form-builder/components/configure-validation/configure-validation.component.d.ts +5 -6
  9. package/components/form-generic/src/components/form-builder/components/expression-builder/expression-builder.component.d.ts +1 -1
  10. package/components/form-generic/src/components/form-builder/components/table/control/table-control.component.d.ts +1 -1
  11. package/components/form-generic/src/components/form-render/form-render.component.d.ts +4 -6
  12. package/components/form-generic/src/components/sd-feel-expression/sd-feel-expression.component.d.ts +1 -1
  13. package/components/form-generic/src/services/form-generic.service.d.ts +1 -3
  14. package/components/modal/src/modal.component.d.ts +1 -1
  15. package/components/tab-router/src/models/tab-router.model.d.ts +2 -1
  16. package/components/tab-router/src/services/tab-router.service.d.ts +0 -1
  17. package/components/table/src/components/command/desktop-command.component.d.ts +7 -7
  18. package/components/table/src/components/command/pipes/command.pipe.d.ts +1 -12
  19. package/components/table/src/components/command/pipes/filter.pipe.d.ts +1 -8
  20. package/components/table/src/components/filter/column-filter/column-filter.component.d.ts +2 -1
  21. package/components/table/src/models/table-column.model.d.ts +3 -2
  22. package/components/table/src/pipes/selection-disabled.pipe.d.ts +1 -1
  23. package/components/table/src/services/config.service.d.ts +4 -5
  24. package/fesm2022/sd-angular-core-components-anchor.mjs +14 -14
  25. package/fesm2022/sd-angular-core-components-anchor.mjs.map +1 -1
  26. package/fesm2022/sd-angular-core-components-autoid-inspector.mjs.map +1 -1
  27. package/fesm2022/sd-angular-core-components-avatar.mjs +2 -2
  28. package/fesm2022/sd-angular-core-components-avatar.mjs.map +1 -1
  29. package/fesm2022/sd-angular-core-components-badge.mjs.map +1 -1
  30. package/fesm2022/sd-angular-core-components-button.mjs.map +1 -1
  31. package/fesm2022/sd-angular-core-components-chart.mjs +40 -40
  32. package/fesm2022/sd-angular-core-components-chart.mjs.map +1 -1
  33. package/fesm2022/sd-angular-core-components-ckeditor-styles.mjs.map +1 -1
  34. package/fesm2022/sd-angular-core-components-code-editor.mjs.map +1 -1
  35. package/fesm2022/sd-angular-core-components-document-builder.mjs +0 -1
  36. package/fesm2022/sd-angular-core-components-document-builder.mjs.map +1 -1
  37. package/fesm2022/sd-angular-core-components-editor.mjs +2 -2
  38. package/fesm2022/sd-angular-core-components-editor.mjs.map +1 -1
  39. package/fesm2022/sd-angular-core-components-form-generic.mjs +39 -68
  40. package/fesm2022/sd-angular-core-components-form-generic.mjs.map +1 -1
  41. package/fesm2022/sd-angular-core-components-import-excel.mjs.map +1 -1
  42. package/fesm2022/sd-angular-core-components-inform.mjs +2 -2
  43. package/fesm2022/sd-angular-core-components-inform.mjs.map +1 -1
  44. package/fesm2022/sd-angular-core-components-mini-editor.mjs.map +1 -1
  45. package/fesm2022/sd-angular-core-components-modal-resizable.mjs.map +1 -1
  46. package/fesm2022/sd-angular-core-components-modal.mjs +2 -2
  47. package/fesm2022/sd-angular-core-components-modal.mjs.map +1 -1
  48. package/fesm2022/sd-angular-core-components-operator.mjs.map +1 -1
  49. package/fesm2022/sd-angular-core-components-org-chart.mjs +2 -2
  50. package/fesm2022/sd-angular-core-components-org-chart.mjs.map +1 -1
  51. package/fesm2022/sd-angular-core-components-preview.mjs +4 -4
  52. package/fesm2022/sd-angular-core-components-preview.mjs.map +1 -1
  53. package/fesm2022/sd-angular-core-components-query-bar.mjs +10 -10
  54. package/fesm2022/sd-angular-core-components-query-bar.mjs.map +1 -1
  55. package/fesm2022/sd-angular-core-components-query-builder.mjs +2 -2
  56. package/fesm2022/sd-angular-core-components-query-builder.mjs.map +1 -1
  57. package/fesm2022/sd-angular-core-components-quick-action.mjs +2 -2
  58. package/fesm2022/sd-angular-core-components-quick-action.mjs.map +1 -1
  59. package/fesm2022/sd-angular-core-components-section.mjs +2 -2
  60. package/fesm2022/sd-angular-core-components-section.mjs.map +1 -1
  61. package/fesm2022/sd-angular-core-components-side-drawer.mjs +2 -2
  62. package/fesm2022/sd-angular-core-components-side-drawer.mjs.map +1 -1
  63. package/fesm2022/sd-angular-core-components-splitter.mjs +6 -6
  64. package/fesm2022/sd-angular-core-components-splitter.mjs.map +1 -1
  65. package/fesm2022/sd-angular-core-components-stepper.mjs +2 -2
  66. package/fesm2022/sd-angular-core-components-stepper.mjs.map +1 -1
  67. package/fesm2022/sd-angular-core-components-tab-router.mjs +31 -26
  68. package/fesm2022/sd-angular-core-components-tab-router.mjs.map +1 -1
  69. package/fesm2022/sd-angular-core-components-tab.mjs +2 -2
  70. package/fesm2022/sd-angular-core-components-tab.mjs.map +1 -1
  71. package/fesm2022/sd-angular-core-components-table.mjs +53 -64
  72. package/fesm2022/sd-angular-core-components-table.mjs.map +1 -1
  73. package/fesm2022/sd-angular-core-components-tree.mjs +2 -2
  74. package/fesm2022/sd-angular-core-components-tree.mjs.map +1 -1
  75. package/fesm2022/sd-angular-core-components-upload-file.mjs.map +1 -1
  76. package/fesm2022/sd-angular-core-components-view.mjs.map +1 -1
  77. package/fesm2022/sd-angular-core-directives.mjs +0 -1
  78. package/fesm2022/sd-angular-core-directives.mjs.map +1 -1
  79. package/fesm2022/sd-angular-core-forms-autocomplete.mjs.map +1 -1
  80. package/fesm2022/sd-angular-core-forms-chip-calendar.mjs.map +1 -1
  81. package/fesm2022/sd-angular-core-forms-chip.mjs.map +1 -1
  82. package/fesm2022/sd-angular-core-forms-date-range.mjs +2 -2
  83. package/fesm2022/sd-angular-core-forms-date-range.mjs.map +1 -1
  84. package/fesm2022/sd-angular-core-forms-date.mjs.map +1 -1
  85. package/fesm2022/sd-angular-core-forms-datetime.mjs +4 -4
  86. package/fesm2022/sd-angular-core-forms-datetime.mjs.map +1 -1
  87. package/fesm2022/sd-angular-core-forms-inline-text.mjs.map +1 -1
  88. package/fesm2022/sd-angular-core-forms-input-color.mjs.map +1 -1
  89. package/fesm2022/sd-angular-core-forms-input-number.mjs +2 -2
  90. package/fesm2022/sd-angular-core-forms-input-number.mjs.map +1 -1
  91. package/fesm2022/sd-angular-core-forms-input.mjs.map +1 -1
  92. package/fesm2022/sd-angular-core-forms-label.mjs +2 -2
  93. package/fesm2022/sd-angular-core-forms-label.mjs.map +1 -1
  94. package/fesm2022/sd-angular-core-forms-models.mjs.map +1 -1
  95. package/fesm2022/sd-angular-core-forms-radio.mjs.map +1 -1
  96. package/fesm2022/sd-angular-core-forms-select.mjs +47 -14
  97. package/fesm2022/sd-angular-core-forms-select.mjs.map +1 -1
  98. package/fesm2022/sd-angular-core-forms-textarea.mjs.map +1 -1
  99. package/fesm2022/sd-angular-core-i18n.mjs.map +1 -1
  100. package/fesm2022/sd-angular-core-interceptors.mjs +0 -2
  101. package/fesm2022/sd-angular-core-interceptors.mjs.map +1 -1
  102. package/fesm2022/sd-angular-core-modules-auth.mjs +14 -38
  103. package/fesm2022/sd-angular-core-modules-auth.mjs.map +1 -1
  104. package/fesm2022/sd-angular-core-modules-authom.mjs.map +1 -1
  105. package/fesm2022/sd-angular-core-modules-keycloak.mjs.map +1 -1
  106. package/fesm2022/sd-angular-core-modules-layout.mjs +7 -14
  107. package/fesm2022/sd-angular-core-modules-layout.mjs.map +1 -1
  108. package/fesm2022/sd-angular-core-modules-permission.mjs +5 -12
  109. package/fesm2022/sd-angular-core-modules-permission.mjs.map +1 -1
  110. package/fesm2022/sd-angular-core-pipes.mjs +4 -12
  111. package/fesm2022/sd-angular-core-pipes.mjs.map +1 -1
  112. package/fesm2022/sd-angular-core-services-api.mjs.map +1 -1
  113. package/fesm2022/sd-angular-core-services-confirm.mjs +16 -21
  114. package/fesm2022/sd-angular-core-services-confirm.mjs.map +1 -1
  115. package/fesm2022/sd-angular-core-services-docx.mjs +1 -8
  116. package/fesm2022/sd-angular-core-services-docx.mjs.map +1 -1
  117. package/fesm2022/sd-angular-core-services-excel.mjs +26 -19
  118. package/fesm2022/sd-angular-core-services-excel.mjs.map +1 -1
  119. package/fesm2022/sd-angular-core-services-license.mjs +5 -12
  120. package/fesm2022/sd-angular-core-services-license.mjs.map +1 -1
  121. package/fesm2022/sd-angular-core-services-notify.mjs +70 -87
  122. package/fesm2022/sd-angular-core-services-notify.mjs.map +1 -1
  123. package/fesm2022/sd-angular-core-services-storage.mjs +4 -12
  124. package/fesm2022/sd-angular-core-services-storage.mjs.map +1 -1
  125. package/fesm2022/sd-angular-core-utilities-extensions.mjs +43 -1
  126. package/fesm2022/sd-angular-core-utilities-extensions.mjs.map +1 -1
  127. package/fesm2022/sd-angular-core-utilities-models.mjs.map +1 -1
  128. package/fesm2022/sd-angular-core.mjs.map +1 -1
  129. package/forms/select/src/select-footer-action.directive.d.ts +5 -1
  130. package/forms/select/src/select.component.d.ts +4 -0
  131. package/modules/auth/guards/auth.guard.d.ts +2 -4
  132. package/modules/auth/guards/portal.guard.d.ts +2 -4
  133. package/modules/auth/services/auth.service.d.ts +3 -4
  134. package/modules/keycloak/htmls/auth-keycloak-error.html +54 -54
  135. package/modules/keycloak/htmls/silent-renew.html +7 -7
  136. package/modules/layout/modules/home/guards/home-redirect.guard.d.ts +3 -5
  137. package/modules/permission/src/guards/permission.guard.d.ts +2 -5
  138. package/package.json +80 -80
  139. package/pipes/src/format-number.pipe.d.ts +1 -3
  140. package/sd-angular-core-19.0.11.tgz +0 -0
  141. package/services/confirm/src/lib/components/dialog-confirm/dialog-confirm.component.d.ts +3 -3
  142. package/services/excel/src/lib/excel.service.d.ts +0 -1
  143. package/services/excel/src/lib/spreadsheet-formula-injection.util.d.ts +5 -0
  144. package/services/license/src/license.service.d.ts +2 -3
  145. package/services/notify/src/components/toast/toast.component.d.ts +9 -13
  146. package/services/notify/src/notify.service.d.ts +4 -5
  147. package/services/storage/src/storage.service.d.ts +3 -4
  148. package/utilities/extensions/index.d.ts +1 -0
  149. package/utilities/extensions/src/object.extension.d.ts +8 -0
  150. package/sd-angular-core-19.0.9.tgz +0 -0
@@ -1,69 +1,62 @@
1
1
  import { CommonModule, DOCUMENT } from '@angular/common';
2
2
  import * as i0 from '@angular/core';
3
- import { signal, SecurityContext, HostListener, Input, Component, createComponent, Inject, Injectable } from '@angular/core';
3
+ import { signal, computed, SecurityContext, HostListener, Input, ChangeDetectionStrategy, Component, inject, ApplicationRef, EnvironmentInjector, createComponent, Injectable } from '@angular/core';
4
4
  import { Utilities } from '@sdcorejs/utils/fns';
5
- import { trigger, transition, style, animate } from '@angular/animations';
6
- import { TranslatePipe } from '@sd-angular/core/i18n';
5
+ import { TranslatePipe, I18nService } from '@sd-angular/core/i18n';
7
6
  import * as i2 from '@angular/platform-browser';
8
7
 
8
+ const TOAST_EXIT_ANIMATION_MS = 200;
9
9
  class ToastComponent {
10
10
  notifyService;
11
11
  sanitizer;
12
12
  data;
13
13
  isExpanded = signal(false);
14
+ isClosing = signal(false);
15
+ hostClasses = computed(() => (this.isClosing() ? 'bg-white sd-toast sd-toast--closing' : 'bg-white sd-toast'));
14
16
  MAX_SHOW = 2;
15
- // --- Logic Timer ---
16
- timer;
17
- start;
18
- remaining;
17
+ timer = null;
18
+ closeTimer = null;
19
+ start = 0;
20
+ remaining = 0;
19
21
  constructor(notifyService, sanitizer) {
20
22
  this.notifyService = notifyService;
21
23
  this.sanitizer = sanitizer;
22
24
  }
23
- /**
24
- * Sanitize HTML tường minh trước khi render qua `[innerHTML]` — strip
25
- * `<script>`, event handler (`on*`), `javascript:` URL. Chỉ chạy ở nhánh
26
- * `data.html === true`; nhánh mặc định render text (auto-escape) nên không
27
- * có sink này. // why: phơi rõ việc sanitize cho review/scanner bảo mật.
28
- */
29
- sanitizeHtml(value) {
30
- return this.sanitizer.sanitize(SecurityContext.HTML, value) ?? '';
31
- }
32
- /** Message ở dạng chuỗi đơn (chỉ dùng khi !isMultiMessage). */
33
- get singleMessage() {
34
- return this.data.message;
35
- }
36
25
  ngOnInit() {
37
- // Khởi tạo thời gian còn lại bằng duration ban đầu
38
26
  this.remaining = this.data.duration;
39
- // Bắt đầu đếm ngược ngay khi hiện ra
40
27
  this.resumeTimer();
41
28
  }
42
29
  ngOnDestroy() {
43
- clearTimeout(this.timer);
30
+ this.clearAutoDismissTimer();
31
+ this.clearCloseTimer();
44
32
  }
45
- // --- Logic Pause/Resume ---
46
33
  pauseTimer() {
47
- if (this.timer) {
48
- // Xóa timer hiện tại
49
- clearTimeout(this.timer);
50
- this.timer = null;
51
- // Tính toán thời gian đã trôi qua để trừ đi
52
- this.remaining -= Date.now() - this.start;
34
+ if (!this.timer || this.isClosing()) {
35
+ return;
53
36
  }
37
+ clearTimeout(this.timer);
38
+ this.timer = null;
39
+ this.remaining = Math.max(this.remaining - (Date.now() - this.start), 0);
54
40
  }
55
41
  resumeTimer() {
56
- // Chỉ chạy tiếp nếu còn thời gian và timer chưa chạy
57
- if (this.remaining > 0 && !this.timer) {
58
- this.start = Date.now();
59
- this.timer = setTimeout(() => {
60
- this.close();
61
- }, this.remaining);
42
+ if (this.remaining <= 0 || this.timer || this.isClosing()) {
43
+ return;
62
44
  }
45
+ this.start = Date.now();
46
+ this.timer = setTimeout(() => {
47
+ this.close();
48
+ }, this.remaining);
63
49
  }
64
- // --- Logic cũ ---
65
50
  close() {
66
- this.notifyService.remove(this.data.id);
51
+ if (this.isClosing()) {
52
+ return;
53
+ }
54
+ this.clearAutoDismissTimer();
55
+ this.isClosing.set(true);
56
+ this.closeTimer = setTimeout(() => {
57
+ this.closeTimer = null;
58
+ this.notifyService.remove(this.data.id);
59
+ }, TOAST_EXIT_ANIMATION_MS);
67
60
  }
68
61
  onActionClick() {
69
62
  this.data.onAction?.();
@@ -71,6 +64,12 @@ class ToastComponent {
71
64
  toggleExpand() {
72
65
  this.isExpanded.update(v => !v);
73
66
  }
67
+ sanitizeHtml(value) {
68
+ return this.sanitizer.sanitize(SecurityContext.HTML, value) ?? '';
69
+ }
70
+ get singleMessage() {
71
+ return this.data.message;
72
+ }
74
73
  get isMultiMessage() {
75
74
  return Array.isArray(this.data.message);
76
75
  }
@@ -89,48 +88,38 @@ class ToastComponent {
89
88
  get hasMore() {
90
89
  return this.isMultiMessage && this.messages.length > this.MAX_SHOW;
91
90
  }
92
- /** autoid theo loại toast để E2E chọn trực tiếp, vd `services-notify-toast-success`. */
93
91
  get autoId() {
94
92
  return `services-notify-toast-${this.data.type}`;
95
93
  }
96
- /** Gộp message (mảng nối ' | ') để phơi ra data-message cho E2E. */
97
94
  get dataMessage() {
98
95
  return Array.isArray(this.data.message) ? this.data.message.join(' | ') : this.data.message;
99
96
  }
97
+ clearAutoDismissTimer() {
98
+ if (!this.timer) {
99
+ return;
100
+ }
101
+ clearTimeout(this.timer);
102
+ this.timer = null;
103
+ }
104
+ clearCloseTimer() {
105
+ if (!this.closeTimer) {
106
+ return;
107
+ }
108
+ clearTimeout(this.closeTimer);
109
+ this.closeTimer = null;
110
+ }
100
111
  static ɵfac = i0.ɵɵngDeclareFactory({ minVersion: "12.0.0", version: "19.2.21", ngImport: i0, type: ToastComponent, deps: [{ token: SdNotifyService }, { token: i2.DomSanitizer }], target: i0.ɵɵFactoryTarget.Component });
101
- static ɵcmp = i0.ɵɵngDeclareComponent({ minVersion: "17.0.0", version: "19.2.21", type: ToastComponent, isStandalone: true, selector: "toast", inputs: { data: "data" }, host: { listeners: { "mouseenter": "pauseTimer()", "mouseleave": "resumeTimer()" }, properties: { "@toastAnimation": "true", "class": "\"bg-white sd-toast\"", "attr.data-autoid": "autoId", "attr.data-type": "data.type", "attr.data-title": "data.title ?? null", "attr.data-message": "dataMessage" } }, ngImport: i0, template: "<div class=\"sd-toast__bar\" [class]=\"'bg-' + data.type\"></div>\r\n\r\n<div class=\"sd-toast__icon\" [class]=\"'text-' + data.type\">\r\n @switch (data.type) {\r\n @case ('success') {\r\n <svg viewBox=\"0 0 24 24\" fill=\"currentColor\"><path d=\"M12 2C6.48 2 2 6.48 2 12s4.48 10 10 10 10-4.48 10-10S17.52 2 12 2zm-2 15l-5-5 1.41-1.41L10 14.17l7.59-7.59L19 8l-9 9z\"/></svg>\r\n }\r\n @case ('info') {\r\n <svg viewBox=\"0 0 24 24\" fill=\"currentColor\"><path d=\"M12 2C6.48 2 2 6.48 2 12s4.48 10 10 10 10-4.48 10-10S17.52 2 12 2zm1 15h-2v-6h2v6zm0-8h-2V7h2v2z\"/></svg>\r\n }\r\n @case ('warning') {\r\n <svg viewBox=\"0 0 24 24\" fill=\"currentColor\"><path d=\"M1 21h22L12 2 1 21zm12-3h-2v-2h2v2zm0-4h-2v-4h2v4z\"/></svg>\r\n }\r\n @case ('error') {\r\n <svg viewBox=\"0 0 24 24\" fill=\"currentColor\"><path d=\"M12 2C6.48 2 2 6.48 2 12s4.48 10 10 10 10-4.48 10-10S17.52 2 12 2zm1 15h-2v-2h2v2zm0-4h-2V7h2v6z\"/></svg>\r\n }\r\n }\r\n</div>\r\n\r\n<div class=\"sd-toast__content\">\r\n <div class=\"sd-toast__header\">\r\n <strong class=\"sd-toast__title\">{{ data.title || ('core.notify.type.' + data.type | translate) }}</strong>\r\n <button class=\"sd-toast__close\" (click)=\"close()\">\u2715</button>\r\n </div>\r\n\r\n <div class=\"sd-toast__body\">\r\n @if (!isMultiMessage) {\r\n <!-- why: m\u1EB7c \u0111\u1ECBnh render TEXT (auto-escape) \u2014 an to\u00E0n. Ch\u1EC9 render HTML\r\n (\u0111\u00E3 sanitize) khi data.html=true. -->\r\n @if (data.html) {\r\n <div [innerHTML]=\"sanitizeHtml(singleMessage)\"></div>\r\n } @else {\r\n <div>{{ singleMessage }}</div>\r\n }\r\n }\r\n @else {\r\n <ul class=\"msg-list\">\r\n @for (msg of displayMessages; track msg) {\r\n @if (data.html) {\r\n <li [innerHTML]=\"sanitizeHtml('- ' + msg)\"></li>\r\n } @else {\r\n <li>{{ '- ' + msg }}</li>\r\n }\r\n }\r\n </ul>\r\n\r\n @if (hasMore) {\r\n <button type=\"button\" \r\n class=\"toggle-more btn-link\" \r\n [class]=\"'text-' + data.type\" \r\n (click)=\"toggleExpand()\">\r\n {{ isExpanded() ? ('core.notify.show-less' | translate) : ('core.notify.show-more' | translate: { count: restCount }) }}\r\n </button>\r\n }\r\n }\r\n </div>\r\n\r\n @if (data.actionLabel) {\r\n <div class=\"sd-toast__actions\">\r\n <button class=\"btn-action\" \r\n [class]=\"'bg-' + data.type + '-light text-' + data.type\"\r\n (click)=\"onActionClick()\">\r\n {{ data.actionLabel }}\r\n </button>\r\n </div>\r\n }\r\n</div>", styles: ["@charset \"UTF-8\";:host{display:flex;width:350px;border-radius:8px;box-shadow:0 4px 12px #00000026;margin-bottom:12px;overflow:hidden;position:relative;font-family:Roboto,sans-serif;pointer-events:auto}.sd-toast__bar{width:6px;flex-shrink:0}.sd-toast__icon{padding:12px 0 0 12px;flex-shrink:0}.sd-toast__icon svg{width:24px;height:24px}.sd-toast__content{flex-grow:1;padding:12px;display:flex;flex-direction:column}.sd-toast__header{display:flex;justify-content:space-between;align-items:flex-start;margin-bottom:4px}.sd-toast__title{font-size:16px;font-weight:600}.sd-toast__close{background:none;border:none;font-size:16px;cursor:pointer;line-height:1;padding:0;opacity:.5;transition:opacity .2s}.sd-toast__close:hover{opacity:1}.sd-toast__body{font-size:14px;line-height:1.4;word-break:break-word}.sd-toast__actions{display:flex;justify-content:flex-end;margin-top:8px}.msg-list{padding-left:0;list-style:none;margin:0}.toggle-more{background:none;border:none;padding:0;font:inherit;cursor:pointer;font-size:13px;margin-top:4px;font-weight:500;text-align:left}.toggle-more:hover{text-decoration:underline}.toggle-more:focus-visible{outline:2px solid currentColor;outline-offset:2px}.btn-action{border:none;padding:6px 12px;border-radius:4px;font-weight:600;cursor:pointer;font-size:13px;transition:filter .2s}.btn-action:hover{filter:brightness(.95)}\n"], dependencies: [{ kind: "ngmodule", type: CommonModule }, { kind: "pipe", type: TranslatePipe, name: "translate" }], animations: [
102
- trigger('toastAnimation', [
103
- transition(':enter', [
104
- style({ transform: 'translateX(100%)', opacity: 0 }),
105
- animate('300ms ease-out', style({ transform: 'translateX(0)', opacity: 1 }))
106
- ]),
107
- transition(':leave', [
108
- animate('200ms ease-in', style({ transform: 'translateX(100%)', opacity: 0 }))
109
- ])
110
- ])
111
- ] });
112
+ static ɵcmp = i0.ɵɵngDeclareComponent({ minVersion: "17.0.0", version: "19.2.21", type: ToastComponent, isStandalone: true, selector: "toast", inputs: { data: "data" }, host: { listeners: { "mouseenter": "pauseTimer()", "mouseleave": "resumeTimer()" }, properties: { "class": "hostClasses()", "attr.data-autoid": "autoId", "attr.data-type": "data.type", "attr.data-title": "data.title ?? null", "attr.data-message": "dataMessage" } }, ngImport: i0, template: "<div class=\"sd-toast__bar\" [class]=\"'bg-' + data.type\"></div>\r\n\r\n<div class=\"sd-toast__icon\" [class]=\"'text-' + data.type\">\r\n @switch (data.type) {\r\n @case ('success') {\r\n <svg viewBox=\"0 0 24 24\" fill=\"currentColor\"><path d=\"M12 2C6.48 2 2 6.48 2 12s4.48 10 10 10 10-4.48 10-10S17.52 2 12 2zm-2 15l-5-5 1.41-1.41L10 14.17l7.59-7.59L19 8l-9 9z\"/></svg>\r\n }\r\n @case ('info') {\r\n <svg viewBox=\"0 0 24 24\" fill=\"currentColor\"><path d=\"M12 2C6.48 2 2 6.48 2 12s4.48 10 10 10 10-4.48 10-10S17.52 2 12 2zm1 15h-2v-6h2v6zm0-8h-2V7h2v2z\"/></svg>\r\n }\r\n @case ('warning') {\r\n <svg viewBox=\"0 0 24 24\" fill=\"currentColor\"><path d=\"M1 21h22L12 2 1 21zm12-3h-2v-2h2v2zm0-4h-2v-4h2v4z\"/></svg>\r\n }\r\n @case ('error') {\r\n <svg viewBox=\"0 0 24 24\" fill=\"currentColor\"><path d=\"M12 2C6.48 2 2 6.48 2 12s4.48 10 10 10 10-4.48 10-10S17.52 2 12 2zm1 15h-2v-2h2v2zm0-4h-2V7h2v6z\"/></svg>\r\n }\r\n }\r\n</div>\r\n\r\n<div class=\"sd-toast__content\">\r\n <div class=\"sd-toast__header\">\r\n <strong class=\"sd-toast__title\">{{ data.title || ('core.notify.type.' + data.type | translate) }}</strong>\r\n <button class=\"sd-toast__close\" (click)=\"close()\">&times;</button>\r\n </div>\r\n\r\n <div class=\"sd-toast__body\">\r\n @if (!isMultiMessage) {\r\n <!-- Text rendering is the default safe path; HTML is opt-in and sanitized. -->\r\n @if (data.html) {\r\n <div [innerHTML]=\"sanitizeHtml(singleMessage)\"></div>\r\n } @else {\r\n <div>{{ singleMessage }}</div>\r\n }\r\n } @else {\r\n <ul class=\"msg-list\">\r\n @for (msg of displayMessages; track msg) {\r\n @if (data.html) {\r\n <li [innerHTML]=\"sanitizeHtml('- ' + msg)\"></li>\r\n } @else {\r\n <li>{{ '- ' + msg }}</li>\r\n }\r\n }\r\n </ul>\r\n\r\n @if (hasMore) {\r\n <button\r\n type=\"button\"\r\n class=\"toggle-more btn-link\"\r\n [class]=\"'text-' + data.type\"\r\n (click)=\"toggleExpand()\">\r\n {{ isExpanded() ? ('core.notify.show-less' | translate) : ('core.notify.show-more' | translate: { count: restCount }) }}\r\n </button>\r\n }\r\n }\r\n </div>\r\n\r\n @if (data.actionLabel) {\r\n <div class=\"sd-toast__actions\">\r\n <button\r\n class=\"btn-action\"\r\n [class]=\"'bg-' + data.type + '-light text-' + data.type\"\r\n (click)=\"onActionClick()\">\r\n {{ data.actionLabel }}\r\n </button>\r\n </div>\r\n }\r\n</div>\r\n", styles: [":host{display:flex;width:350px;border-radius:8px;box-shadow:0 4px 12px #00000026;margin-bottom:12px;overflow:hidden;position:relative;font-family:Roboto,sans-serif;pointer-events:auto;animation:sd-toast-enter .3s ease-out}:host(.sd-toast--closing){pointer-events:none;animation:sd-toast-leave .2s ease-in forwards}@keyframes sd-toast-enter{0%{transform:translate(100%);opacity:0}to{transform:translate(0);opacity:1}}@keyframes sd-toast-leave{0%{transform:translate(0);opacity:1}to{transform:translate(100%);opacity:0}}@media(prefers-reduced-motion:reduce){:host,:host(.sd-toast--closing){animation:none}}.sd-toast__bar{width:6px;flex-shrink:0}.sd-toast__icon{padding:12px 0 0 12px;flex-shrink:0}.sd-toast__icon svg{width:24px;height:24px}.sd-toast__content{flex-grow:1;padding:12px;display:flex;flex-direction:column}.sd-toast__header{display:flex;justify-content:space-between;align-items:flex-start;margin-bottom:4px}.sd-toast__title{font-size:16px;font-weight:600}.sd-toast__close{background:none;border:none;font-size:16px;cursor:pointer;line-height:1;padding:0;opacity:.5;transition:opacity .2s}.sd-toast__close:hover{opacity:1}.sd-toast__body{font-size:14px;line-height:1.4;word-break:break-word}.sd-toast__actions{display:flex;justify-content:flex-end;margin-top:8px}.msg-list{padding-left:0;list-style:none;margin:0}.toggle-more{background:none;border:none;padding:0;font:inherit;cursor:pointer;font-size:13px;margin-top:4px;font-weight:500;text-align:left}.toggle-more:hover{text-decoration:underline}.toggle-more:focus-visible{outline:2px solid currentColor;outline-offset:2px}.btn-action{border:none;padding:6px 12px;border-radius:4px;font-weight:600;cursor:pointer;font-size:13px;transition:filter .2s}.btn-action:hover{filter:brightness(.95)}\n"], dependencies: [{ kind: "ngmodule", type: CommonModule }, { kind: "pipe", type: TranslatePipe, name: "translate" }], changeDetection: i0.ChangeDetectionStrategy.OnPush });
112
113
  }
113
114
  i0.ɵɵngDeclareClassMetadata({ minVersion: "12.0.0", version: "19.2.21", ngImport: i0, type: ToastComponent, decorators: [{
114
115
  type: Component,
115
- args: [{ selector: 'toast', standalone: true, imports: [CommonModule, TranslatePipe], animations: [
116
- trigger('toastAnimation', [
117
- transition(':enter', [
118
- style({ transform: 'translateX(100%)', opacity: 0 }),
119
- animate('300ms ease-out', style({ transform: 'translateX(0)', opacity: 1 }))
120
- ]),
121
- transition(':leave', [
122
- animate('200ms ease-in', style({ transform: 'translateX(100%)', opacity: 0 }))
123
- ])
124
- ])
125
- ], host: {
126
- '[@toastAnimation]': 'true',
127
- '[class]': '"bg-white sd-toast"',
128
- // E2E hooks đọc bởi sd-autoid-inspector: autoid theo loại + state type/title/message.
116
+ args: [{ selector: 'toast', standalone: true, imports: [CommonModule, TranslatePipe], changeDetection: ChangeDetectionStrategy.OnPush, host: {
117
+ '[class]': 'hostClasses()',
129
118
  '[attr.data-autoid]': 'autoId',
130
119
  '[attr.data-type]': 'data.type',
131
120
  '[attr.data-title]': 'data.title ?? null',
132
- '[attr.data-message]': 'dataMessage'
133
- }, template: "<div class=\"sd-toast__bar\" [class]=\"'bg-' + data.type\"></div>\r\n\r\n<div class=\"sd-toast__icon\" [class]=\"'text-' + data.type\">\r\n @switch (data.type) {\r\n @case ('success') {\r\n <svg viewBox=\"0 0 24 24\" fill=\"currentColor\"><path d=\"M12 2C6.48 2 2 6.48 2 12s4.48 10 10 10 10-4.48 10-10S17.52 2 12 2zm-2 15l-5-5 1.41-1.41L10 14.17l7.59-7.59L19 8l-9 9z\"/></svg>\r\n }\r\n @case ('info') {\r\n <svg viewBox=\"0 0 24 24\" fill=\"currentColor\"><path d=\"M12 2C6.48 2 2 6.48 2 12s4.48 10 10 10 10-4.48 10-10S17.52 2 12 2zm1 15h-2v-6h2v6zm0-8h-2V7h2v2z\"/></svg>\r\n }\r\n @case ('warning') {\r\n <svg viewBox=\"0 0 24 24\" fill=\"currentColor\"><path d=\"M1 21h22L12 2 1 21zm12-3h-2v-2h2v2zm0-4h-2v-4h2v4z\"/></svg>\r\n }\r\n @case ('error') {\r\n <svg viewBox=\"0 0 24 24\" fill=\"currentColor\"><path d=\"M12 2C6.48 2 2 6.48 2 12s4.48 10 10 10 10-4.48 10-10S17.52 2 12 2zm1 15h-2v-2h2v2zm0-4h-2V7h2v6z\"/></svg>\r\n }\r\n }\r\n</div>\r\n\r\n<div class=\"sd-toast__content\">\r\n <div class=\"sd-toast__header\">\r\n <strong class=\"sd-toast__title\">{{ data.title || ('core.notify.type.' + data.type | translate) }}</strong>\r\n <button class=\"sd-toast__close\" (click)=\"close()\">\u2715</button>\r\n </div>\r\n\r\n <div class=\"sd-toast__body\">\r\n @if (!isMultiMessage) {\r\n <!-- why: m\u1EB7c \u0111\u1ECBnh render TEXT (auto-escape) \u2014 an to\u00E0n. Ch\u1EC9 render HTML\r\n (\u0111\u00E3 sanitize) khi data.html=true. -->\r\n @if (data.html) {\r\n <div [innerHTML]=\"sanitizeHtml(singleMessage)\"></div>\r\n } @else {\r\n <div>{{ singleMessage }}</div>\r\n }\r\n }\r\n @else {\r\n <ul class=\"msg-list\">\r\n @for (msg of displayMessages; track msg) {\r\n @if (data.html) {\r\n <li [innerHTML]=\"sanitizeHtml('- ' + msg)\"></li>\r\n } @else {\r\n <li>{{ '- ' + msg }}</li>\r\n }\r\n }\r\n </ul>\r\n\r\n @if (hasMore) {\r\n <button type=\"button\" \r\n class=\"toggle-more btn-link\" \r\n [class]=\"'text-' + data.type\" \r\n (click)=\"toggleExpand()\">\r\n {{ isExpanded() ? ('core.notify.show-less' | translate) : ('core.notify.show-more' | translate: { count: restCount }) }}\r\n </button>\r\n }\r\n }\r\n </div>\r\n\r\n @if (data.actionLabel) {\r\n <div class=\"sd-toast__actions\">\r\n <button class=\"btn-action\" \r\n [class]=\"'bg-' + data.type + '-light text-' + data.type\"\r\n (click)=\"onActionClick()\">\r\n {{ data.actionLabel }}\r\n </button>\r\n </div>\r\n }\r\n</div>", styles: ["@charset \"UTF-8\";:host{display:flex;width:350px;border-radius:8px;box-shadow:0 4px 12px #00000026;margin-bottom:12px;overflow:hidden;position:relative;font-family:Roboto,sans-serif;pointer-events:auto}.sd-toast__bar{width:6px;flex-shrink:0}.sd-toast__icon{padding:12px 0 0 12px;flex-shrink:0}.sd-toast__icon svg{width:24px;height:24px}.sd-toast__content{flex-grow:1;padding:12px;display:flex;flex-direction:column}.sd-toast__header{display:flex;justify-content:space-between;align-items:flex-start;margin-bottom:4px}.sd-toast__title{font-size:16px;font-weight:600}.sd-toast__close{background:none;border:none;font-size:16px;cursor:pointer;line-height:1;padding:0;opacity:.5;transition:opacity .2s}.sd-toast__close:hover{opacity:1}.sd-toast__body{font-size:14px;line-height:1.4;word-break:break-word}.sd-toast__actions{display:flex;justify-content:flex-end;margin-top:8px}.msg-list{padding-left:0;list-style:none;margin:0}.toggle-more{background:none;border:none;padding:0;font:inherit;cursor:pointer;font-size:13px;margin-top:4px;font-weight:500;text-align:left}.toggle-more:hover{text-decoration:underline}.toggle-more:focus-visible{outline:2px solid currentColor;outline-offset:2px}.btn-action{border:none;padding:6px 12px;border-radius:4px;font-weight:600;cursor:pointer;font-size:13px;transition:filter .2s}.btn-action:hover{filter:brightness(.95)}\n"] }]
121
+ '[attr.data-message]': 'dataMessage',
122
+ }, template: "<div class=\"sd-toast__bar\" [class]=\"'bg-' + data.type\"></div>\r\n\r\n<div class=\"sd-toast__icon\" [class]=\"'text-' + data.type\">\r\n @switch (data.type) {\r\n @case ('success') {\r\n <svg viewBox=\"0 0 24 24\" fill=\"currentColor\"><path d=\"M12 2C6.48 2 2 6.48 2 12s4.48 10 10 10 10-4.48 10-10S17.52 2 12 2zm-2 15l-5-5 1.41-1.41L10 14.17l7.59-7.59L19 8l-9 9z\"/></svg>\r\n }\r\n @case ('info') {\r\n <svg viewBox=\"0 0 24 24\" fill=\"currentColor\"><path d=\"M12 2C6.48 2 2 6.48 2 12s4.48 10 10 10 10-4.48 10-10S17.52 2 12 2zm1 15h-2v-6h2v6zm0-8h-2V7h2v2z\"/></svg>\r\n }\r\n @case ('warning') {\r\n <svg viewBox=\"0 0 24 24\" fill=\"currentColor\"><path d=\"M1 21h22L12 2 1 21zm12-3h-2v-2h2v2zm0-4h-2v-4h2v4z\"/></svg>\r\n }\r\n @case ('error') {\r\n <svg viewBox=\"0 0 24 24\" fill=\"currentColor\"><path d=\"M12 2C6.48 2 2 6.48 2 12s4.48 10 10 10 10-4.48 10-10S17.52 2 12 2zm1 15h-2v-2h2v2zm0-4h-2V7h2v6z\"/></svg>\r\n }\r\n }\r\n</div>\r\n\r\n<div class=\"sd-toast__content\">\r\n <div class=\"sd-toast__header\">\r\n <strong class=\"sd-toast__title\">{{ data.title || ('core.notify.type.' + data.type | translate) }}</strong>\r\n <button class=\"sd-toast__close\" (click)=\"close()\">&times;</button>\r\n </div>\r\n\r\n <div class=\"sd-toast__body\">\r\n @if (!isMultiMessage) {\r\n <!-- Text rendering is the default safe path; HTML is opt-in and sanitized. -->\r\n @if (data.html) {\r\n <div [innerHTML]=\"sanitizeHtml(singleMessage)\"></div>\r\n } @else {\r\n <div>{{ singleMessage }}</div>\r\n }\r\n } @else {\r\n <ul class=\"msg-list\">\r\n @for (msg of displayMessages; track msg) {\r\n @if (data.html) {\r\n <li [innerHTML]=\"sanitizeHtml('- ' + msg)\"></li>\r\n } @else {\r\n <li>{{ '- ' + msg }}</li>\r\n }\r\n }\r\n </ul>\r\n\r\n @if (hasMore) {\r\n <button\r\n type=\"button\"\r\n class=\"toggle-more btn-link\"\r\n [class]=\"'text-' + data.type\"\r\n (click)=\"toggleExpand()\">\r\n {{ isExpanded() ? ('core.notify.show-less' | translate) : ('core.notify.show-more' | translate: { count: restCount }) }}\r\n </button>\r\n }\r\n }\r\n </div>\r\n\r\n @if (data.actionLabel) {\r\n <div class=\"sd-toast__actions\">\r\n <button\r\n class=\"btn-action\"\r\n [class]=\"'bg-' + data.type + '-light text-' + data.type\"\r\n (click)=\"onActionClick()\">\r\n {{ data.actionLabel }}\r\n </button>\r\n </div>\r\n }\r\n</div>\r\n", styles: [":host{display:flex;width:350px;border-radius:8px;box-shadow:0 4px 12px #00000026;margin-bottom:12px;overflow:hidden;position:relative;font-family:Roboto,sans-serif;pointer-events:auto;animation:sd-toast-enter .3s ease-out}:host(.sd-toast--closing){pointer-events:none;animation:sd-toast-leave .2s ease-in forwards}@keyframes sd-toast-enter{0%{transform:translate(100%);opacity:0}to{transform:translate(0);opacity:1}}@keyframes sd-toast-leave{0%{transform:translate(0);opacity:1}to{transform:translate(100%);opacity:0}}@media(prefers-reduced-motion:reduce){:host,:host(.sd-toast--closing){animation:none}}.sd-toast__bar{width:6px;flex-shrink:0}.sd-toast__icon{padding:12px 0 0 12px;flex-shrink:0}.sd-toast__icon svg{width:24px;height:24px}.sd-toast__content{flex-grow:1;padding:12px;display:flex;flex-direction:column}.sd-toast__header{display:flex;justify-content:space-between;align-items:flex-start;margin-bottom:4px}.sd-toast__title{font-size:16px;font-weight:600}.sd-toast__close{background:none;border:none;font-size:16px;cursor:pointer;line-height:1;padding:0;opacity:.5;transition:opacity .2s}.sd-toast__close:hover{opacity:1}.sd-toast__body{font-size:14px;line-height:1.4;word-break:break-word}.sd-toast__actions{display:flex;justify-content:flex-end;margin-top:8px}.msg-list{padding-left:0;list-style:none;margin:0}.toggle-more{background:none;border:none;padding:0;font:inherit;cursor:pointer;font-size:13px;margin-top:4px;font-weight:500;text-align:left}.toggle-more:hover{text-decoration:underline}.toggle-more:focus-visible{outline:2px solid currentColor;outline-offset:2px}.btn-action{border:none;padding:6px 12px;border-radius:4px;font-weight:600;cursor:pointer;font-size:13px;transition:filter .2s}.btn-action:hover{filter:brightness(.95)}\n"] }]
134
123
  }], ctorParameters: () => [{ type: SdNotifyService }, { type: i2.DomSanitizer }], propDecorators: { data: [{
135
124
  type: Input,
136
125
  args: [{ required: true }]
@@ -165,9 +154,6 @@ i0.ɵɵngDeclareClassMetadata({ minVersion: "12.0.0", version: "19.2.21", ngImpo
165
154
  }] });
166
155
 
167
156
  class SdNotifyService {
168
- appRef;
169
- injector;
170
- document;
171
157
  toasts = signal([]);
172
158
  // Constants
173
159
  #DEBOUNCE_TIME = 500;
@@ -177,10 +163,11 @@ class SdNotifyService {
177
163
  // State
178
164
  #buffer = {};
179
165
  #timers = {};
180
- constructor(appRef, injector, document) {
181
- this.appRef = appRef;
182
- this.injector = injector;
183
- this.document = document;
166
+ appRef = inject(ApplicationRef);
167
+ injector = inject(EnvironmentInjector);
168
+ document = inject(DOCUMENT);
169
+ #i18n = inject(I18nService);
170
+ constructor() {
184
171
  this.#initContainer();
185
172
  }
186
173
  #initContainer() {
@@ -206,14 +193,14 @@ class SdNotifyService {
206
193
  this.#addToBuffer('error', message, option);
207
194
  }
208
195
  remove(id) {
209
- this.toasts.update((current) => current.filter((t) => t.id !== id));
196
+ this.toasts.update(current => current.filter(t => t.id !== id));
210
197
  }
211
198
  clearAll() {
212
199
  this.toasts.set([]);
213
200
  this.#clearAllTimers();
214
201
  }
215
202
  clearByType(type) {
216
- this.toasts.update((current) => current.filter((t) => t.type !== type));
203
+ this.toasts.update(current => current.filter(t => t.type !== type));
217
204
  }
218
205
  // Private helpers
219
206
  #addImmediate(type, message, option) {
@@ -225,9 +212,9 @@ class SdNotifyService {
225
212
  duration: option?.duration ?? this.#DEFAULT_SUCCESS_DURATION,
226
213
  actionLabel: option?.actionLabel,
227
214
  onAction: option?.onAction,
228
- html: option?.html
215
+ html: option?.html,
229
216
  };
230
- this.toasts.update((current) => {
217
+ this.toasts.update(current => {
231
218
  const updated = [newToast, ...current];
232
219
  return updated.slice(0, this.#MAX_TOASTS);
233
220
  });
@@ -253,8 +240,7 @@ class SdNotifyService {
253
240
  this.#timers[type] = null;
254
241
  if (messages.length === 0)
255
242
  return;
256
- const typeLabel = type === 'error' ? 'Error' : 'Warning';
257
- const title = option?.title ?? typeLabel;
243
+ const title = option?.title ?? this.#i18n.t(`core.notify.type.${type}`);
258
244
  const finalTitle = messages.length > 1 ? `${title} (${messages.length})` : title;
259
245
  const newToast = {
260
246
  id: Utilities.generateUuid(),
@@ -264,9 +250,9 @@ class SdNotifyService {
264
250
  duration: option?.duration ?? this.#DEFAULT_BUFFERED_DURATION,
265
251
  actionLabel: option?.actionLabel,
266
252
  onAction: option?.onAction,
267
- html: option?.html
253
+ html: option?.html,
268
254
  };
269
- this.toasts.update((current) => {
255
+ this.toasts.update(current => {
270
256
  const updated = [newToast, ...current];
271
257
  return updated.slice(0, this.#MAX_TOASTS);
272
258
  });
@@ -278,7 +264,7 @@ class SdNotifyService {
278
264
  });
279
265
  this.#timers = {};
280
266
  }
281
- static ɵfac = i0.ɵɵngDeclareFactory({ minVersion: "12.0.0", version: "19.2.21", ngImport: i0, type: SdNotifyService, deps: [{ token: i0.ApplicationRef }, { token: i0.EnvironmentInjector }, { token: DOCUMENT }], target: i0.ɵɵFactoryTarget.Injectable });
267
+ static ɵfac = i0.ɵɵngDeclareFactory({ minVersion: "12.0.0", version: "19.2.21", ngImport: i0, type: SdNotifyService, deps: [], target: i0.ɵɵFactoryTarget.Injectable });
282
268
  static ɵprov = i0.ɵɵngDeclareInjectable({ minVersion: "12.0.0", version: "19.2.21", ngImport: i0, type: SdNotifyService, providedIn: 'root' });
283
269
  }
284
270
  i0.ɵɵngDeclareClassMetadata({ minVersion: "12.0.0", version: "19.2.21", ngImport: i0, type: SdNotifyService, decorators: [{
@@ -286,10 +272,7 @@ i0.ɵɵngDeclareClassMetadata({ minVersion: "12.0.0", version: "19.2.21", ngImpo
286
272
  args: [{
287
273
  providedIn: 'root',
288
274
  }]
289
- }], ctorParameters: () => [{ type: i0.ApplicationRef }, { type: i0.EnvironmentInjector }, { type: Document, decorators: [{
290
- type: Inject,
291
- args: [DOCUMENT]
292
- }] }] });
275
+ }], ctorParameters: () => [] });
293
276
 
294
277
  /**
295
278
  * Generated bundle index. Do not edit.
@@ -1 +1 @@
1
- {"version":3,"file":"sd-angular-core-services-notify.mjs","sources":["../../../projects/sd-angular/services/notify/src/components/toast/toast.component.ts","../../../projects/sd-angular/services/notify/src/components/toast/toast.component.html","../../../projects/sd-angular/services/notify/src/components/toast-container.component.ts","../../../projects/sd-angular/services/notify/src/notify.service.ts","../../../projects/sd-angular/services/notify/sd-angular-core-services-notify.ts"],"sourcesContent":["import { Component, Input, signal, HostListener, OnInit, OnDestroy, SecurityContext } from '@angular/core';\r\nimport { CommonModule } from '@angular/common';\r\nimport { DomSanitizer } from '@angular/platform-browser';\r\nimport { animate, style, transition, trigger } from '@angular/animations';\r\nimport { TranslatePipe } from '@sd-angular/core/i18n';\r\nimport { ToastData } from '../../notify.model';\r\nimport { SdNotifyService } from '../../notify.service';\r\n\r\n@Component({\r\n selector: 'toast',\r\n standalone: true,\r\n imports: [CommonModule, TranslatePipe],\r\n templateUrl: './toast.component.html',\r\n styleUrls: ['./toast.component.scss'],\r\n animations: [\r\n trigger('toastAnimation', [\r\n transition(':enter', [\r\n style({ transform: 'translateX(100%)', opacity: 0 }),\r\n animate('300ms ease-out', style({ transform: 'translateX(0)', opacity: 1 }))\r\n ]),\r\n transition(':leave', [\r\n animate('200ms ease-in', style({ transform: 'translateX(100%)', opacity: 0 }))\r\n ])\r\n ])\r\n ],\r\n host: {\r\n '[@toastAnimation]': 'true',\r\n '[class]': '\"bg-white sd-toast\"',\r\n // E2E hooks đọc bởi sd-autoid-inspector: autoid theo loại + state type/title/message.\r\n '[attr.data-autoid]': 'autoId',\r\n '[attr.data-type]': 'data.type',\r\n '[attr.data-title]': 'data.title ?? null',\r\n '[attr.data-message]': 'dataMessage'\r\n }\r\n})\r\nexport class ToastComponent implements OnInit, OnDestroy {\r\n @Input({ required: true }) data!: ToastData;\r\n \r\n isExpanded = signal(false);\r\n readonly MAX_SHOW = 2;\r\n\r\n // --- Logic Timer ---\r\n private timer: any;\r\n private start!: number;\r\n private remaining!: number;\r\n\r\n constructor(\r\n private notifyService: SdNotifyService,\r\n private sanitizer: DomSanitizer\r\n ) {}\r\n\r\n /**\r\n * Sanitize HTML tường minh trước khi render qua `[innerHTML]` — strip\r\n * `<script>`, event handler (`on*`), `javascript:` URL. Chỉ chạy ở nhánh\r\n * `data.html === true`; nhánh mặc định render text (auto-escape) nên không\r\n * có sink này. // why: phơi rõ việc sanitize cho review/scanner bảo mật.\r\n */\r\n sanitizeHtml(value: string): string {\r\n return this.sanitizer.sanitize(SecurityContext.HTML, value) ?? '';\r\n }\r\n\r\n /** Message ở dạng chuỗi đơn (chỉ dùng khi !isMultiMessage). */\r\n get singleMessage(): string {\r\n return this.data.message as string;\r\n }\r\n\r\n ngOnInit() {\r\n // Khởi tạo thời gian còn lại bằng duration ban đầu\r\n this.remaining = this.data.duration;\r\n // Bắt đầu đếm ngược ngay khi hiện ra\r\n this.resumeTimer();\r\n }\r\n\r\n ngOnDestroy() {\r\n clearTimeout(this.timer);\r\n }\r\n\r\n // --- Logic Pause/Resume ---\r\n\r\n @HostListener('mouseenter')\r\n pauseTimer() {\r\n if (this.timer) {\r\n // Xóa timer hiện tại\r\n clearTimeout(this.timer);\r\n this.timer = null;\r\n // Tính toán thời gian đã trôi qua để trừ đi\r\n this.remaining -= Date.now() - this.start;\r\n }\r\n }\r\n\r\n @HostListener('mouseleave')\r\n resumeTimer() {\r\n // Chỉ chạy tiếp nếu còn thời gian và timer chưa chạy\r\n if (this.remaining > 0 && !this.timer) {\r\n this.start = Date.now();\r\n this.timer = setTimeout(() => {\r\n this.close();\r\n }, this.remaining);\r\n }\r\n }\r\n\r\n // --- Logic cũ ---\r\n\r\n close() {\r\n this.notifyService.remove(this.data.id);\r\n }\r\n\r\n onActionClick() {\r\n this.data.onAction?.();\r\n }\r\n\r\n toggleExpand() {\r\n this.isExpanded.update(v => !v);\r\n }\r\n\r\n get isMultiMessage(): boolean {\r\n return Array.isArray(this.data.message);\r\n }\r\n\r\n get messages(): string[] {\r\n return this.data.message as string[];\r\n }\r\n\r\n get displayMessages(): string[] {\r\n const msgs = this.messages;\r\n if (this.isExpanded()) return msgs;\r\n return msgs.slice(0, this.MAX_SHOW);\r\n }\r\n\r\n get restCount(): number {\r\n return this.messages.length - this.MAX_SHOW;\r\n }\r\n\r\n get hasMore(): boolean {\r\n return this.isMultiMessage && this.messages.length > this.MAX_SHOW;\r\n }\r\n\r\n /** autoid theo loại toast để E2E chọn trực tiếp, vd `services-notify-toast-success`. */\r\n get autoId(): string {\r\n return `services-notify-toast-${this.data.type}`;\r\n }\r\n\r\n /** Gộp message (mảng nối ' | ') để phơi ra data-message cho E2E. */\r\n get dataMessage(): string {\r\n return Array.isArray(this.data.message) ? this.data.message.join(' | ') : this.data.message;\r\n }\r\n}","<div class=\"sd-toast__bar\" [class]=\"'bg-' + data.type\"></div>\r\n\r\n<div class=\"sd-toast__icon\" [class]=\"'text-' + data.type\">\r\n @switch (data.type) {\r\n @case ('success') {\r\n <svg viewBox=\"0 0 24 24\" fill=\"currentColor\"><path d=\"M12 2C6.48 2 2 6.48 2 12s4.48 10 10 10 10-4.48 10-10S17.52 2 12 2zm-2 15l-5-5 1.41-1.41L10 14.17l7.59-7.59L19 8l-9 9z\"/></svg>\r\n }\r\n @case ('info') {\r\n <svg viewBox=\"0 0 24 24\" fill=\"currentColor\"><path d=\"M12 2C6.48 2 2 6.48 2 12s4.48 10 10 10 10-4.48 10-10S17.52 2 12 2zm1 15h-2v-6h2v6zm0-8h-2V7h2v2z\"/></svg>\r\n }\r\n @case ('warning') {\r\n <svg viewBox=\"0 0 24 24\" fill=\"currentColor\"><path d=\"M1 21h22L12 2 1 21zm12-3h-2v-2h2v2zm0-4h-2v-4h2v4z\"/></svg>\r\n }\r\n @case ('error') {\r\n <svg viewBox=\"0 0 24 24\" fill=\"currentColor\"><path d=\"M12 2C6.48 2 2 6.48 2 12s4.48 10 10 10 10-4.48 10-10S17.52 2 12 2zm1 15h-2v-2h2v2zm0-4h-2V7h2v6z\"/></svg>\r\n }\r\n }\r\n</div>\r\n\r\n<div class=\"sd-toast__content\">\r\n <div class=\"sd-toast__header\">\r\n <strong class=\"sd-toast__title\">{{ data.title || ('core.notify.type.' + data.type | translate) }}</strong>\r\n <button class=\"sd-toast__close\" (click)=\"close()\">✕</button>\r\n </div>\r\n\r\n <div class=\"sd-toast__body\">\r\n @if (!isMultiMessage) {\r\n <!-- why: mặc định render TEXT (auto-escape) — an toàn. Chỉ render HTML\r\n (đã sanitize) khi data.html=true. -->\r\n @if (data.html) {\r\n <div [innerHTML]=\"sanitizeHtml(singleMessage)\"></div>\r\n } @else {\r\n <div>{{ singleMessage }}</div>\r\n }\r\n }\r\n @else {\r\n <ul class=\"msg-list\">\r\n @for (msg of displayMessages; track msg) {\r\n @if (data.html) {\r\n <li [innerHTML]=\"sanitizeHtml('- ' + msg)\"></li>\r\n } @else {\r\n <li>{{ '- ' + msg }}</li>\r\n }\r\n }\r\n </ul>\r\n\r\n @if (hasMore) {\r\n <button type=\"button\" \r\n class=\"toggle-more btn-link\" \r\n [class]=\"'text-' + data.type\" \r\n (click)=\"toggleExpand()\">\r\n {{ isExpanded() ? ('core.notify.show-less' | translate) : ('core.notify.show-more' | translate: { count: restCount }) }}\r\n </button>\r\n }\r\n }\r\n </div>\r\n\r\n @if (data.actionLabel) {\r\n <div class=\"sd-toast__actions\">\r\n <button class=\"btn-action\" \r\n [class]=\"'bg-' + data.type + '-light text-' + data.type\"\r\n (click)=\"onActionClick()\">\r\n {{ data.actionLabel }}\r\n </button>\r\n </div>\r\n }\r\n</div>","import { Component, signal, WritableSignal } from '@angular/core';\r\nimport { ToastData } from '../notify.model';\r\nimport { ToastComponent } from './toast/toast.component';\r\n\r\n@Component({\r\n selector: 'toast-container',\r\n standalone: true,\r\n imports: [ToastComponent],\r\n template: `\r\n <div class=\"toast-container\">\r\n @for (toast of toasts(); track toast.id) {\r\n <toast [data]=\"toast\"> </toast>\r\n }\r\n </div>\r\n `,\r\n styles: [\r\n `\r\n .toast-container {\r\n position: fixed;\r\n top: 20px;\r\n right: 20px;\r\n z-index: 9999;\r\n display: flex;\r\n flex-direction: column;\r\n pointer-events: none; /* Cho phép click xuyên qua vùng trống */\r\n }\r\n sd-toast {\r\n pointer-events: auto; /* Bật lại click cho toast */\r\n }\r\n `,\r\n ],\r\n})\r\nexport class ToastContainerComponent {\r\n toasts: WritableSignal<ToastData[]> = signal([]);\r\n}\r\n","import { DOCUMENT } from '@angular/common';\r\nimport {\r\n ApplicationRef,\r\n createComponent,\r\n EnvironmentInjector,\r\n Inject,\r\n Injectable,\r\n signal\r\n} from '@angular/core';\r\nimport { Utilities } from '@sdcorejs/utils/fns';\r\nimport { ToastContainerComponent } from './components/toast-container.component';\r\nimport { NotifyOption, ToastData, ToastType } from './notify.model';\r\n\r\n@Injectable({\r\n providedIn: 'root',\r\n})\r\nexport class SdNotifyService {\r\n readonly toasts = signal<ToastData[]>([]);\r\n\r\n // Constants\r\n readonly #DEBOUNCE_TIME = 500;\r\n readonly #DEFAULT_SUCCESS_DURATION = 3000;\r\n readonly #DEFAULT_BUFFERED_DURATION = 5000;\r\n readonly #MAX_TOASTS = 5;\r\n\r\n // State\r\n #buffer: Record<string, string[]> = {};\r\n #timers: Record<string, ReturnType<typeof setTimeout> | null> = {};\r\n\r\n constructor(\r\n private appRef: ApplicationRef,\r\n private injector: EnvironmentInjector,\r\n @Inject(DOCUMENT) private document: Document\r\n ) {\r\n this.#initContainer();\r\n }\r\n\r\n #initContainer() {\r\n const componentRef = createComponent(ToastContainerComponent, {\r\n environmentInjector: this.injector,\r\n });\r\n componentRef.instance.toasts = this.toasts;\r\n this.appRef.attachView(componentRef.hostView);\r\n const domElem = (componentRef.hostView as any).rootNodes[0] as HTMLElement;\r\n this.document.body.appendChild(domElem);\r\n }\r\n\r\n // Public API\r\n success(message: string, option?: NotifyOption) {\r\n this.#addImmediate('success', message, option);\r\n }\r\n\r\n info(message: string, option?: NotifyOption) {\r\n this.#addImmediate('info', message, option);\r\n }\r\n\r\n warning(message: string | string[], option?: NotifyOption) {\r\n this.#addToBuffer('warning', message, option);\r\n }\r\n\r\n error(message: string | string[], option?: NotifyOption) {\r\n this.#addToBuffer('error', message, option);\r\n }\r\n\r\n remove(id: string) {\r\n this.toasts.update((current) => current.filter((t) => t.id !== id));\r\n }\r\n\r\n clearAll() {\r\n this.toasts.set([]);\r\n this.#clearAllTimers();\r\n }\r\n\r\n clearByType(type: ToastType) {\r\n this.toasts.update((current) => current.filter((t) => t.type !== type));\r\n }\r\n\r\n // Private helpers\r\n #addImmediate(type: ToastType, message: string, option?: NotifyOption) {\r\n const newToast: ToastData = {\r\n id: Utilities.generateUuid(),\r\n type,\r\n message,\r\n title: option?.title,\r\n duration: option?.duration ?? this.#DEFAULT_SUCCESS_DURATION,\r\n actionLabel: option?.actionLabel,\r\n onAction: option?.onAction,\r\n html: option?.html\r\n };\r\n\r\n this.toasts.update((current) => {\r\n const updated = [newToast, ...current];\r\n return updated.slice(0, this.#MAX_TOASTS);\r\n });\r\n }\r\n\r\n #addToBuffer(type: ToastType, message: string | string[], option?: NotifyOption) {\r\n if (!this.#buffer[type]) {\r\n this.#buffer[type] = [];\r\n }\r\n \r\n const msgs = Array.isArray(message) ? message : [message];\r\n this.#buffer[type].push(...msgs);\r\n\r\n // Clear existing timer and set new one\r\n if (this.#timers[type]) {\r\n clearTimeout(this.#timers[type]!);\r\n }\r\n\r\n this.#timers[type] = setTimeout(() => {\r\n this.#flushBuffer(type, option);\r\n }, this.#DEBOUNCE_TIME);\r\n }\r\n\r\n #flushBuffer(type: ToastType, option?: NotifyOption) {\r\n const messages = [...new Set(this.#buffer[type])];\r\n \r\n // Cleanup\r\n this.#buffer[type] = [];\r\n this.#timers[type] = null;\r\n\r\n if (messages.length === 0) return;\r\n\r\n const typeLabel = type === 'error' ? 'Error' : 'Warning';\r\n const title = option?.title ?? typeLabel;\r\n const finalTitle = messages.length > 1 ? `${title} (${messages.length})` : title;\r\n\r\n const newToast: ToastData = {\r\n id: Utilities.generateUuid(),\r\n type,\r\n message: messages.length === 1 ? messages[0] : messages, \r\n title: finalTitle,\r\n duration: option?.duration ?? this.#DEFAULT_BUFFERED_DURATION,\r\n actionLabel: option?.actionLabel,\r\n onAction: option?.onAction,\r\n html: option?.html\r\n };\r\n\r\n this.toasts.update((current) => {\r\n const updated = [newToast, ...current];\r\n return updated.slice(0, this.#MAX_TOASTS);\r\n });\r\n }\r\n\r\n #clearAllTimers() {\r\n Object.values(this.#timers).forEach(timer => {\r\n if (timer) clearTimeout(timer);\r\n });\r\n this.#timers = {};\r\n }\r\n}","/**\n * Generated bundle index. Do not edit.\n */\n\nexport * from './index';\n"],"names":["i1.SdNotifyService"],"mappings":";;;;;;;;MA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AAI,CAAC,WAAW,CAAC;AAC3C,QAAA,CAAC,CAAC;IACJ;IAEA,eAAe,GAAA;AACb,QAAA,MAAM,CAAC,MAAM,CAAC,IAAI,CAAC,OAAO,CAAC,CAAC,OAAO,CAAC,KAAK,IAAG;AAC1C,YAAA,IAAI,KAAK;gBAAE,YAAY,CAAC,KAAK,CAAC;AAChC,QAAA,CAAC,CAAC;AACF,QAAA,IAAI,CAAC,OAAO,GAAG,EAAE;IACnB;AArIW,IAAA,OAAA,IAAA,GAAA,EAAA,CAAA,kBAAA,CAAA,EAAA,UAAA,EAAA,QAAA,EAAA,OAAA,EAAA,SAAA,EAAA,QAAA,EAAA,EAAA,EAAA,IAAA,EAAA,eAAe,mFAgBhB,QAAQ,EAAA,CAAA,EAAA,MAAA,EAAA,EAAA,CAAA,eAAA,CAAA,UAAA,EAAA,CAAA;AAhBP,IAAA,OAAA,KAAA,GAAA,EAAA,CAAA,qBAAA,CAAA,EAAA,UAAA,EAAA,QAAA,EAAA,OAAA,EAAA,SAAA,EAAA,QAAA,EAAA,EAAA,EAAA,IAAA,EAAA,eAAe,cAFd,MAAM,EAAA,CAAA;;4FAEP,eAAe,EAAA,UAAA,EAAA,CAAA;kBAH3B,UAAU;AAAC,YAAA,IAAA,EAAA,CAAA;AACV,oBAAA,UAAU,EAAE,MAAM;AACnB,iBAAA;;0BAiBI,MAAM;2BAAC,QAAQ;;;AChCpB;;AAEG;;;;"}
1
+ {"version":3,"file":"sd-angular-core-services-notify.mjs","sources":["../../../projects/sd-angular/services/notify/src/components/toast/toast.component.ts","../../../projects/sd-angular/services/notify/src/components/toast/toast.component.html","../../../projects/sd-angular/services/notify/src/components/toast-container.component.ts","../../../projects/sd-angular/services/notify/src/notify.service.ts","../../../projects/sd-angular/services/notify/sd-angular-core-services-notify.ts"],"sourcesContent":["import { CommonModule } from '@angular/common';\r\nimport {\r\n ChangeDetectionStrategy,\r\n Component,\r\n HostListener,\r\n Input,\r\n OnDestroy,\r\n OnInit,\r\n SecurityContext,\r\n computed,\r\n signal,\r\n} from '@angular/core';\r\nimport { DomSanitizer } from '@angular/platform-browser';\r\nimport { TranslatePipe } from '@sd-angular/core/i18n';\r\n\r\nimport { ToastData } from '../../notify.model';\r\nimport { SdNotifyService } from '../../notify.service';\r\n\r\nconst TOAST_EXIT_ANIMATION_MS = 200;\r\n\r\n@Component({\r\n selector: 'toast',\r\n standalone: true,\r\n imports: [CommonModule, TranslatePipe],\r\n templateUrl: './toast.component.html',\r\n styleUrl: './toast.component.scss',\r\n changeDetection: ChangeDetectionStrategy.OnPush,\r\n host: {\r\n '[class]': 'hostClasses()',\r\n '[attr.data-autoid]': 'autoId',\r\n '[attr.data-type]': 'data.type',\r\n '[attr.data-title]': 'data.title ?? null',\r\n '[attr.data-message]': 'dataMessage',\r\n },\r\n})\r\nexport class ToastComponent implements OnInit, OnDestroy {\r\n @Input({ required: true }) data!: ToastData;\r\n\r\n readonly isExpanded = signal(false);\r\n readonly isClosing = signal(false);\r\n readonly hostClasses = computed(() => (this.isClosing() ? 'bg-white sd-toast sd-toast--closing' : 'bg-white sd-toast'));\r\n readonly MAX_SHOW = 2;\r\n\r\n private timer: ReturnType<typeof setTimeout> | null = null;\r\n private closeTimer: ReturnType<typeof setTimeout> | null = null;\r\n private start = 0;\r\n private remaining = 0;\r\n\r\n constructor(\r\n private notifyService: SdNotifyService,\r\n private sanitizer: DomSanitizer\r\n ) {}\r\n\r\n ngOnInit(): void {\r\n this.remaining = this.data.duration;\r\n this.resumeTimer();\r\n }\r\n\r\n ngOnDestroy(): void {\r\n this.clearAutoDismissTimer();\r\n this.clearCloseTimer();\r\n }\r\n\r\n @HostListener('mouseenter')\r\n pauseTimer(): void {\r\n if (!this.timer || this.isClosing()) {\r\n return;\r\n }\r\n\r\n clearTimeout(this.timer);\r\n this.timer = null;\r\n this.remaining = Math.max(this.remaining - (Date.now() - this.start), 0);\r\n }\r\n\r\n @HostListener('mouseleave')\r\n resumeTimer(): void {\r\n if (this.remaining <= 0 || this.timer || this.isClosing()) {\r\n return;\r\n }\r\n\r\n this.start = Date.now();\r\n this.timer = setTimeout(() => {\r\n this.close();\r\n }, this.remaining);\r\n }\r\n\r\n close(): void {\r\n if (this.isClosing()) {\r\n return;\r\n }\r\n\r\n this.clearAutoDismissTimer();\r\n this.isClosing.set(true);\r\n this.closeTimer = setTimeout(() => {\r\n this.closeTimer = null;\r\n this.notifyService.remove(this.data.id);\r\n }, TOAST_EXIT_ANIMATION_MS);\r\n }\r\n\r\n onActionClick(): void {\r\n this.data.onAction?.();\r\n }\r\n\r\n toggleExpand(): void {\r\n this.isExpanded.update(v => !v);\r\n }\r\n\r\n sanitizeHtml(value: string): string {\r\n return this.sanitizer.sanitize(SecurityContext.HTML, value) ?? '';\r\n }\r\n\r\n get singleMessage(): string {\r\n return this.data.message as string;\r\n }\r\n\r\n get isMultiMessage(): boolean {\r\n return Array.isArray(this.data.message);\r\n }\r\n\r\n get messages(): string[] {\r\n return this.data.message as string[];\r\n }\r\n\r\n get displayMessages(): string[] {\r\n const msgs = this.messages;\r\n if (this.isExpanded()) return msgs;\r\n return msgs.slice(0, this.MAX_SHOW);\r\n }\r\n\r\n get restCount(): number {\r\n return this.messages.length - this.MAX_SHOW;\r\n }\r\n\r\n get hasMore(): boolean {\r\n return this.isMultiMessage && this.messages.length > this.MAX_SHOW;\r\n }\r\n\r\n get autoId(): string {\r\n return `services-notify-toast-${this.data.type}`;\r\n }\r\n\r\n get dataMessage(): string {\r\n return Array.isArray(this.data.message) ? this.data.message.join(' | ') : this.data.message;\r\n }\r\n\r\n private clearAutoDismissTimer(): void {\r\n if (!this.timer) {\r\n return;\r\n }\r\n\r\n clearTimeout(this.timer);\r\n this.timer = null;\r\n }\r\n\r\n private clearCloseTimer(): void {\r\n if (!this.closeTimer) {\r\n return;\r\n }\r\n\r\n clearTimeout(this.closeTimer);\r\n this.closeTimer = null;\r\n }\r\n}\r\n","<div class=\"sd-toast__bar\" [class]=\"'bg-' + data.type\"></div>\r\n\r\n<div class=\"sd-toast__icon\" [class]=\"'text-' + data.type\">\r\n @switch (data.type) {\r\n @case ('success') {\r\n <svg viewBox=\"0 0 24 24\" fill=\"currentColor\"><path d=\"M12 2C6.48 2 2 6.48 2 12s4.48 10 10 10 10-4.48 10-10S17.52 2 12 2zm-2 15l-5-5 1.41-1.41L10 14.17l7.59-7.59L19 8l-9 9z\"/></svg>\r\n }\r\n @case ('info') {\r\n <svg viewBox=\"0 0 24 24\" fill=\"currentColor\"><path d=\"M12 2C6.48 2 2 6.48 2 12s4.48 10 10 10 10-4.48 10-10S17.52 2 12 2zm1 15h-2v-6h2v6zm0-8h-2V7h2v2z\"/></svg>\r\n }\r\n @case ('warning') {\r\n <svg viewBox=\"0 0 24 24\" fill=\"currentColor\"><path d=\"M1 21h22L12 2 1 21zm12-3h-2v-2h2v2zm0-4h-2v-4h2v4z\"/></svg>\r\n }\r\n @case ('error') {\r\n <svg viewBox=\"0 0 24 24\" fill=\"currentColor\"><path d=\"M12 2C6.48 2 2 6.48 2 12s4.48 10 10 10 10-4.48 10-10S17.52 2 12 2zm1 15h-2v-2h2v2zm0-4h-2V7h2v6z\"/></svg>\r\n }\r\n }\r\n</div>\r\n\r\n<div class=\"sd-toast__content\">\r\n <div class=\"sd-toast__header\">\r\n <strong class=\"sd-toast__title\">{{ data.title || ('core.notify.type.' + data.type | translate) }}</strong>\r\n <button class=\"sd-toast__close\" (click)=\"close()\">&times;</button>\r\n </div>\r\n\r\n <div class=\"sd-toast__body\">\r\n @if (!isMultiMessage) {\r\n <!-- Text rendering is the default safe path; HTML is opt-in and sanitized. -->\r\n @if (data.html) {\r\n <div [innerHTML]=\"sanitizeHtml(singleMessage)\"></div>\r\n } @else {\r\n <div>{{ singleMessage }}</div>\r\n }\r\n } @else {\r\n <ul class=\"msg-list\">\r\n @for (msg of displayMessages; track msg) {\r\n @if (data.html) {\r\n <li [innerHTML]=\"sanitizeHtml('- ' + msg)\"></li>\r\n } @else {\r\n <li>{{ '- ' + msg }}</li>\r\n }\r\n }\r\n </ul>\r\n\r\n @if (hasMore) {\r\n <button\r\n type=\"button\"\r\n class=\"toggle-more btn-link\"\r\n [class]=\"'text-' + data.type\"\r\n (click)=\"toggleExpand()\">\r\n {{ isExpanded() ? ('core.notify.show-less' | translate) : ('core.notify.show-more' | translate: { count: restCount }) }}\r\n </button>\r\n }\r\n }\r\n </div>\r\n\r\n @if (data.actionLabel) {\r\n <div class=\"sd-toast__actions\">\r\n <button\r\n class=\"btn-action\"\r\n [class]=\"'bg-' + data.type + '-light text-' + data.type\"\r\n (click)=\"onActionClick()\">\r\n {{ data.actionLabel }}\r\n </button>\r\n </div>\r\n }\r\n</div>\r\n","import { Component, signal, WritableSignal } from '@angular/core';\r\nimport { ToastData } from '../notify.model';\r\nimport { ToastComponent } from './toast/toast.component';\r\n\r\n@Component({\r\n selector: 'toast-container',\r\n standalone: true,\r\n imports: [ToastComponent],\r\n template: `\r\n <div class=\"toast-container\">\r\n @for (toast of toasts(); track toast.id) {\r\n <toast [data]=\"toast\"> </toast>\r\n }\r\n </div>\r\n `,\r\n styles: [\r\n `\r\n .toast-container {\r\n position: fixed;\r\n top: 20px;\r\n right: 20px;\r\n z-index: 9999;\r\n display: flex;\r\n flex-direction: column;\r\n pointer-events: none; /* Cho phép click xuyên qua vùng trống */\r\n }\r\n sd-toast {\r\n pointer-events: auto; /* Bật lại click cho toast */\r\n }\r\n `,\r\n ],\r\n})\r\nexport class ToastContainerComponent {\r\n toasts: WritableSignal<ToastData[]> = signal([]);\r\n}\r\n","import { DOCUMENT } from '@angular/common';\r\nimport { ApplicationRef, createComponent, EnvironmentInjector, inject, Injectable, signal } from '@angular/core';\r\nimport { Utilities } from '@sdcorejs/utils/fns';\r\n\r\nimport { I18nService } from '@sd-angular/core/i18n';\r\n\r\nimport { ToastContainerComponent } from './components/toast-container.component';\r\nimport { NotifyOption, ToastData, ToastType } from './notify.model';\r\n\r\n@Injectable({\r\n providedIn: 'root',\r\n})\r\nexport class SdNotifyService {\r\n readonly toasts = signal<ToastData[]>([]);\r\n\r\n // Constants\r\n readonly #DEBOUNCE_TIME = 500;\r\n readonly #DEFAULT_SUCCESS_DURATION = 3000;\r\n readonly #DEFAULT_BUFFERED_DURATION = 5000;\r\n readonly #MAX_TOASTS = 5;\r\n\r\n // State\r\n #buffer: Record<string, string[]> = {};\r\n #timers: Record<string, ReturnType<typeof setTimeout> | null> = {};\r\n private readonly appRef = inject(ApplicationRef);\r\n private readonly injector = inject(EnvironmentInjector);\r\n private readonly document = inject(DOCUMENT);\r\n readonly #i18n = inject(I18nService);\r\n\r\n constructor() {\r\n this.#initContainer();\r\n }\r\n\r\n #initContainer() {\r\n const componentRef = createComponent(ToastContainerComponent, {\r\n environmentInjector: this.injector,\r\n });\r\n componentRef.instance.toasts = this.toasts;\r\n this.appRef.attachView(componentRef.hostView);\r\n const domElem = (componentRef.hostView as any).rootNodes[0] as HTMLElement;\r\n this.document.body.appendChild(domElem);\r\n }\r\n\r\n // Public API\r\n success(message: string, option?: NotifyOption) {\r\n this.#addImmediate('success', message, option);\r\n }\r\n\r\n info(message: string, option?: NotifyOption) {\r\n this.#addImmediate('info', message, option);\r\n }\r\n\r\n warning(message: string | string[], option?: NotifyOption) {\r\n this.#addToBuffer('warning', message, option);\r\n }\r\n\r\n error(message: string | string[], option?: NotifyOption) {\r\n this.#addToBuffer('error', message, option);\r\n }\r\n\r\n remove(id: string) {\r\n this.toasts.update(current => current.filter(t => t.id !== id));\r\n }\r\n\r\n clearAll() {\r\n this.toasts.set([]);\r\n this.#clearAllTimers();\r\n }\r\n\r\n clearByType(type: ToastType) {\r\n this.toasts.update(current => current.filter(t => t.type !== type));\r\n }\r\n\r\n // Private helpers\r\n #addImmediate(type: ToastType, message: string, option?: NotifyOption) {\r\n const newToast: ToastData = {\r\n id: Utilities.generateUuid(),\r\n type,\r\n message,\r\n title: option?.title,\r\n duration: option?.duration ?? this.#DEFAULT_SUCCESS_DURATION,\r\n actionLabel: option?.actionLabel,\r\n onAction: option?.onAction,\r\n html: option?.html,\r\n };\r\n\r\n this.toasts.update(current => {\r\n const updated = [newToast, ...current];\r\n return updated.slice(0, this.#MAX_TOASTS);\r\n });\r\n }\r\n\r\n #addToBuffer(type: ToastType, message: string | string[], option?: NotifyOption) {\r\n if (!this.#buffer[type]) {\r\n this.#buffer[type] = [];\r\n }\r\n\r\n const msgs = Array.isArray(message) ? message : [message];\r\n this.#buffer[type].push(...msgs);\r\n\r\n // Clear existing timer and set new one\r\n if (this.#timers[type]) {\r\n clearTimeout(this.#timers[type]!);\r\n }\r\n\r\n this.#timers[type] = setTimeout(() => {\r\n this.#flushBuffer(type, option);\r\n }, this.#DEBOUNCE_TIME);\r\n }\r\n\r\n #flushBuffer(type: ToastType, option?: NotifyOption) {\r\n const messages = [...new Set(this.#buffer[type])];\r\n\r\n // Cleanup\r\n this.#buffer[type] = [];\r\n this.#timers[type] = null;\r\n\r\n if (messages.length === 0) return;\r\n\r\n const title = option?.title ?? this.#i18n.t(`core.notify.type.${type}`);\r\n const finalTitle = messages.length > 1 ? `${title} (${messages.length})` : title;\r\n\r\n const newToast: ToastData = {\r\n id: Utilities.generateUuid(),\r\n type,\r\n message: messages.length === 1 ? messages[0] : messages,\r\n title: finalTitle,\r\n duration: option?.duration ?? this.#DEFAULT_BUFFERED_DURATION,\r\n actionLabel: option?.actionLabel,\r\n onAction: option?.onAction,\r\n html: option?.html,\r\n };\r\n\r\n this.toasts.update(current => {\r\n const updated = [newToast, ...current];\r\n return updated.slice(0, this.#MAX_TOASTS);\r\n });\r\n }\r\n\r\n #clearAllTimers() {\r\n Object.values(this.#timers).forEach(timer => {\r\n if (timer) clearTimeout(timer);\r\n });\r\n this.#timers = {};\r\n }\r\n}\r\n","/**\n * Generated bundle index. Do not edit.\n */\n\nexport * from './index';\n"],"names":["i1.SdNotifyService"],"mappings":";;;;;;;AAkBA,MAAM,uBAAuB,GAAG,GAAG;MAiBtB,cAAc,CAAA;AAcf,IAAA,aAAA;AACA,IAAA,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Injectable } from '@angular/core';
3
3
  import { Utilities } from '@sdcorejs/utils/fns';
4
4
  import { BehaviorSubject } from 'rxjs';
5
5
  import { map } from 'rxjs/operators';
@@ -8,13 +8,10 @@ const SD_STORAGE_CONFIG = new InjectionToken('storage.configuration');
8
8
 
9
9
  /* eslint-disable @typescript-eslint/no-explicit-any */
10
10
  class SdStorageService {
11
- configuration;
12
11
  // Dùng Map để quản lý bộ nhớ tốt hơn Record
13
12
  #memoryCache = new Map();
14
13
  #subjects = new Map();
15
- constructor(configuration) {
16
- this.configuration = configuration;
17
- }
14
+ configuration = inject(SD_STORAGE_CONFIG, { optional: true });
18
15
  create(key, option) {
19
16
  if (!key)
20
17
  throw new Error('Key is required');
@@ -151,7 +148,7 @@ class SdStorageService {
151
148
  return val;
152
149
  return JSON.parse(JSON.stringify(val));
153
150
  }
154
- static ɵfac = i0.ɵɵngDeclareFactory({ minVersion: "12.0.0", version: "19.2.21", ngImport: i0, type: SdStorageService, deps: [{ token: SD_STORAGE_CONFIG, optional: true }], target: i0.ɵɵFactoryTarget.Injectable });
151
+ static ɵfac = i0.ɵɵngDeclareFactory({ minVersion: "12.0.0", version: "19.2.21", ngImport: i0, type: SdStorageService, deps: [], target: i0.ɵɵFactoryTarget.Injectable });
155
152
  static ɵprov = i0.ɵɵngDeclareInjectable({ minVersion: "12.0.0", version: "19.2.21", ngImport: i0, type: SdStorageService, providedIn: 'root' });
156
153
  }
157
154
  i0.ɵɵngDeclareClassMetadata({ minVersion: "12.0.0", version: "19.2.21", ngImport: i0, type: SdStorageService, decorators: [{
@@ -159,12 +156,7 @@ i0.ɵɵngDeclareClassMetadata({ minVersion: "12.0.0", version: "19.2.21", ngImpo
159
156
  args: [{
160
157
  providedIn: 'root',
161
158
  }]
162
- }], ctorParameters: () => [{ type: undefined, decorators: [{
163
- type: Inject,
164
- args: [SD_STORAGE_CONFIG]
165
- }, {
166
- type: Optional
167
- }] }] });
159
+ }] });
168
160
 
169
161
  /**
170
162
  * Generated bundle index. Do not edit.
@@ -1 +1 @@
1
- {"version":3,"file":"sd-angular-core-services-storage.mjs","sources":["../../../projects/sd-angular/services/storage/src/storage.model.ts","../../../projects/sd-angular/services/storage/src/storage.service.ts","../../../projects/sd-angular/services/storage/sd-angular-core-services-storage.ts"],"sourcesContent":["import { InjectionToken } from '@angular/core';\r\nimport { BehaviorSubject, Observable } from 'rxjs';\r\n\r\nexport interface SdStorageOption<T = any> {\r\n type?: 'session';\r\n default?: T;\r\n args?: Record<string, any>;\r\n}\r\n\r\nexport interface SdStorage<T = any> {\r\n get: () => T;\r\n set: (data: T) => void;\r\n // Ghi vào storage nhưng KHÔNG emit subject. Dùng cho thay đổi UI-only\r\n // (vd: column width) để tránh re-trigger các subscriber gây reload data.\r\n setSilent: (data: T) => void;\r\n has: () => boolean;\r\n remove: () => void;\r\n subject: BehaviorSubject<T>;\r\n observer: Observable<T>;\r\n}\r\n\r\nexport interface ISdStorageConfiguration {\r\n key?: (key: string) => string;\r\n}\r\n\r\nexport const SD_STORAGE_CONFIG = new InjectionToken<ISdStorageConfiguration>('storage.configuration');\r\n","/* eslint-disable @typescript-eslint/no-explicit-any */\r\nimport { Inject, Injectable, Optional } from '@angular/core';\r\nimport { Utilities } from '@sdcorejs/utils/fns';\r\nimport { BehaviorSubject } from 'rxjs';\r\nimport { map } from 'rxjs/operators';\r\nimport { ISdStorageConfiguration, SD_STORAGE_CONFIG, SdStorage, SdStorageOption } from './storage.model';\r\n\r\ninterface StorageCacheEntry<T> {\r\n data: T;\r\n createdOn: Date;\r\n}\r\n\r\n@Injectable({\r\n providedIn: 'root',\r\n})\r\nexport class SdStorageService {\r\n // Dùng Map để quản lý bộ nhớ tốt hơn Record\r\n #memoryCache = new Map<string, StorageCacheEntry<any>>();\r\n #subjects = new Map<string, BehaviorSubject<any>>();\r\n\r\n constructor(\r\n @Inject(SD_STORAGE_CONFIG)\r\n @Optional()\r\n private configuration: ISdStorageConfiguration\r\n ) {}\r\n\r\n create<T = any>(key: string | object, option?: SdStorageOption<T>): SdStorage<T> {\r\n if (!key) throw new Error('Key is required');\r\n\r\n // 1. Xử lý Key\r\n let hashKey: string;\r\n if (typeof key === 'string') {\r\n hashKey = key;\r\n } else if (typeof key === 'object') {\r\n hashKey = Utilities.hash(key);\r\n } else {\r\n throw new Error('Invalid key type');\r\n }\r\n\r\n if (this.configuration?.key) {\r\n hashKey = this.configuration.key(hashKey);\r\n }\r\n\r\n // 2. Init Subject: Đọc dữ liệu từ Storage ngay lập tức để Subject có giá trị đúng\r\n if (!this.#subjects.has(hashKey)) {\r\n const existingData = this.#internalGet<T>(hashKey, option);\r\n // Fix Type: as T | undefined\r\n this.#subjects.set(hashKey, new BehaviorSubject<T | undefined>(existingData ?? option?.default));\r\n }\r\n\r\n const subject = this.#subjects.get(hashKey)!;\r\n\r\n // 3. Define Helpers\r\n const get = () => {\r\n const val = this.#internalGet<T>(hashKey, option);\r\n return (val ?? option?.default) as T;\r\n };\r\n\r\n const set = (data: T) => {\r\n this.#internalSet(hashKey, data, option);\r\n subject.next(data);\r\n };\r\n\r\n const setSilent = (data: T) => {\r\n this.#internalSet(hashKey, data, option);\r\n // Cố tình KHÔNG gọi subject.next — consumer dùng kênh riêng để thông báo\r\n };\r\n\r\n const has = () => {\r\n return this.#internalGet<T>(hashKey, option) !== undefined;\r\n };\r\n\r\n const remove = () => {\r\n this.#internalRemove(hashKey, option);\r\n subject.next(undefined);\r\n };\r\n\r\n // Hàm dọn dẹp bộ nhớ (quan trọng)\r\n const destroy = () => {\r\n subject.complete();\r\n this.#subjects.delete(hashKey);\r\n this.#memoryCache.delete(hashKey);\r\n };\r\n\r\n return {\r\n get,\r\n set,\r\n setSilent,\r\n has,\r\n remove,\r\n // @ts-ignore: Bổ sung vào interface nếu cần\r\n destroy,\r\n subject: subject,\r\n observer: subject.asObservable().pipe(map(() => get())),\r\n };\r\n }\r\n\r\n // --- PRIVATE CORE LOGIC ---\r\n\r\n /**\r\n * Helper xác định loại Storage đang dùng\r\n */\r\n #getStorage(option?: SdStorageOption<any>): Storage {\r\n return option?.type === 'session' ? sessionStorage : localStorage;\r\n }\r\n\r\n /**\r\n * Đọc dữ liệu: Memory -> Storage -> Parse\r\n */\r\n #internalGet<T>(key: string, option?: SdStorageOption<T>): T | undefined {\r\n // 1. Check Memory (Nhanh nhất)\r\n let entry = this.#memoryCache.get(key);\r\n\r\n // 2. Check Storage (Nếu memory chưa có hoặc mới F5)\r\n if (!entry) {\r\n const storage = this.#getStorage(option);\r\n const raw = storage.getItem(key);\r\n if (raw) {\r\n try {\r\n const parsed = JSON.parse(raw);\r\n // Convert string date back to Date object nếu cần\r\n entry = {\r\n data: parsed.data,\r\n createdOn: new Date(parsed.createdOn)\r\n };\r\n // Sync ngược vào RAM\r\n this.#memoryCache.set(key, entry);\r\n } catch (e) {\r\n console.warn('Storage parse error', e);\r\n this.#internalRemove(key, option); // Dữ liệu lỗi -> Xóa\r\n }\r\n }\r\n }\r\n\r\n if (!entry) return undefined;\r\n\r\n return this.#deepClone(entry.data);\r\n }\r\n\r\n /**\r\n * Ghi dữ liệu: Memory -> Storage\r\n */\r\n #internalSet<T>(key: string, data: T, option?: SdStorageOption<T>): void {\r\n const clonedData = this.#deepClone(data);\r\n\r\n const entry: StorageCacheEntry<T> = {\r\n data: clonedData,\r\n createdOn: new Date(),\r\n };\r\n\r\n // 1. Lưu Memory\r\n this.#memoryCache.set(key, entry);\r\n\r\n // 2. Lưu Storage\r\n const storage = this.#getStorage(option);\r\n try {\r\n storage.setItem(key, JSON.stringify(entry));\r\n } catch (e) {\r\n console.error('Storage quota exceeded', e);\r\n }\r\n }\r\n\r\n /**\r\n * Xóa dữ liệu\r\n */\r\n #internalRemove(key: string, option?: SdStorageOption<any>): void {\r\n this.#memoryCache.delete(key);\r\n const storage = this.#getStorage(option);\r\n storage.removeItem(key);\r\n }\r\n\r\n /**\r\n * Deep Clone an toàn\r\n */\r\n #deepClone<T>(val: T): T {\r\n if (val === undefined || val === null) return val;\r\n return JSON.parse(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EAAA,UAAA,EAAA,CAAA;kBAH5B,UAAU;AAAC,YAAA,IAAA,EAAA,CAAA;AACV,oBAAA,UAAU,EAAE,MAAM;AACnB,iBAAA;;0BAOI,MAAM;2BAAC,iBAAiB;;0BACxB;;;ACtBL;;AAEG;;;;"}
1
+ {"version":3,"file":"sd-angular-core-services-storage.mjs","sources":["../../../projects/sd-angular/services/storage/src/storage.model.ts","../../../projects/sd-angular/services/storage/src/storage.service.ts","../../../projects/sd-angular/services/storage/sd-angular-core-services-storage.ts"],"sourcesContent":["import { InjectionToken } from '@angular/core';\r\nimport { BehaviorSubject, Observable } from 'rxjs';\r\n\r\nexport interface SdStorageOption<T = any> {\r\n type?: 'session';\r\n default?: T;\r\n args?: Record<string, any>;\r\n}\r\n\r\nexport interface SdStorage<T = any> {\r\n get: () => T;\r\n set: (data: T) => void;\r\n // Ghi vào storage nhưng KHÔNG emit subject. Dùng cho thay đổi UI-only\r\n // (vd: column width) để tránh re-trigger các subscriber gây reload data.\r\n setSilent: (data: T) => void;\r\n has: () => boolean;\r\n remove: () => void;\r\n subject: BehaviorSubject<T>;\r\n observer: Observable<T>;\r\n}\r\n\r\nexport interface ISdStorageConfiguration {\r\n key?: (key: string) => string;\r\n}\r\n\r\nexport const SD_STORAGE_CONFIG = new InjectionToken<ISdStorageConfiguration>('storage.configuration');\r\n","/* eslint-disable @typescript-eslint/no-explicit-any */\r\nimport { inject, Injectable } from '@angular/core';\r\nimport { Utilities } from '@sdcorejs/utils/fns';\r\nimport { BehaviorSubject } from 'rxjs';\r\nimport { map } from 'rxjs/operators';\r\nimport { ISdStorageConfiguration, SD_STORAGE_CONFIG, SdStorage, SdStorageOption } from './storage.model';\r\n\r\ninterface StorageCacheEntry<T> {\r\n data: T;\r\n createdOn: Date;\r\n}\r\n\r\n@Injectable({\r\n providedIn: 'root',\r\n})\r\nexport class SdStorageService {\r\n // Dùng Map để quản lý bộ nhớ tốt hơn Record\r\n #memoryCache = new Map<string, StorageCacheEntry<any>>();\r\n #subjects = new Map<string, BehaviorSubject<any>>();\r\n private readonly configuration: ISdStorageConfiguration | null = inject(SD_STORAGE_CONFIG, { optional: true });\r\n\r\n create<T = any>(key: string | object, option?: SdStorageOption<T>): SdStorage<T> {\r\n if (!key) throw new Error('Key is required');\r\n\r\n // 1. Xử lý Key\r\n let hashKey: string;\r\n if (typeof key === 'string') {\r\n hashKey = key;\r\n } else if (typeof key === 'object') {\r\n hashKey = Utilities.hash(key);\r\n } else {\r\n throw new Error('Invalid key type');\r\n }\r\n\r\n if (this.configuration?.key) {\r\n hashKey = this.configuration.key(hashKey);\r\n }\r\n\r\n // 2. Init Subject: Đọc dữ liệu từ Storage ngay lập tức để Subject có giá trị đúng\r\n if (!this.#subjects.has(hashKey)) {\r\n const existingData = this.#internalGet<T>(hashKey, option);\r\n // Fix Type: as T | undefined\r\n this.#subjects.set(hashKey, new BehaviorSubject<T | undefined>(existingData ?? option?.default));\r\n }\r\n\r\n const subject = this.#subjects.get(hashKey)!;\r\n\r\n // 3. Define Helpers\r\n const get = () => {\r\n const val = this.#internalGet<T>(hashKey, option);\r\n return (val ?? option?.default) as T;\r\n };\r\n\r\n const set = (data: T) => {\r\n this.#internalSet(hashKey, data, option);\r\n subject.next(data);\r\n };\r\n\r\n const setSilent = (data: T) => {\r\n this.#internalSet(hashKey, data, option);\r\n // Cố tình KHÔNG gọi subject.next — consumer dùng kênh riêng để thông báo\r\n };\r\n\r\n const has = () => {\r\n return this.#internalGet<T>(hashKey, option) !== undefined;\r\n };\r\n\r\n const remove = () => {\r\n this.#internalRemove(hashKey, option);\r\n subject.next(undefined);\r\n };\r\n\r\n // Hàm dọn dẹp bộ nhớ (quan trọng)\r\n const destroy = () => {\r\n subject.complete();\r\n this.#subjects.delete(hashKey);\r\n this.#memoryCache.delete(hashKey);\r\n };\r\n\r\n return {\r\n get,\r\n set,\r\n setSilent,\r\n has,\r\n remove,\r\n // @ts-ignore: Bổ sung vào interface nếu cần\r\n destroy,\r\n subject: subject,\r\n observer: subject.asObservable().pipe(map(() => get())),\r\n };\r\n }\r\n\r\n // --- PRIVATE CORE LOGIC ---\r\n\r\n /**\r\n * Helper xác định loại Storage đang dùng\r\n */\r\n #getStorage(option?: SdStorageOption<any>): Storage {\r\n return option?.type === 'session' ? sessionStorage : localStorage;\r\n }\r\n\r\n /**\r\n * Đọc dữ liệu: Memory -> Storage -> Parse\r\n */\r\n #internalGet<T>(key: string, option?: SdStorageOption<T>): T | undefined {\r\n // 1. Check Memory (Nhanh nhất)\r\n let entry = this.#memoryCache.get(key);\r\n\r\n // 2. Check Storage (Nếu memory chưa có hoặc mới F5)\r\n if (!entry) {\r\n const storage = this.#getStorage(option);\r\n const raw = storage.getItem(key);\r\n if (raw) {\r\n try {\r\n const parsed = JSON.parse(raw);\r\n // Convert string date back to Date object nếu cần\r\n entry = {\r\n data: parsed.data,\r\n createdOn: new Date(parsed.createdOn)\r\n };\r\n // Sync ngược vào RAM\r\n this.#memoryCache.set(key, entry);\r\n } catch (e) {\r\n console.warn('Storage parse error', e);\r\n this.#internalRemove(key, option); // Dữ liệu lỗi -> Xóa\r\n }\r\n }\r\n }\r\n\r\n if (!entry) return undefined;\r\n\r\n return this.#deepClone(entry.data);\r\n }\r\n\r\n /**\r\n * Ghi dữ liệu: Memory -> Storage\r\n */\r\n #internalSet<T>(key: string, data: T, option?: SdStorageOption<T>): void {\r\n const clonedData = this.#deepClone(data);\r\n\r\n const entry: StorageCacheEntry<T> = {\r\n data: clonedData,\r\n createdOn: new Date(),\r\n };\r\n\r\n // 1. Lưu Memory\r\n this.#memoryCache.set(key, entry);\r\n\r\n // 2. Lưu Storage\r\n const storage = this.#getStorage(option);\r\n try {\r\n storage.setItem(key, JSON.stringify(entry));\r\n } catch (e) {\r\n console.error('Storage quota exceeded', e);\r\n }\r\n }\r\n\r\n /**\r\n * Xóa dữ liệu\r\n */\r\n #internalRemove(key: string, option?: SdStorageOption<any>): void {\r\n this.#memoryCache.delete(key);\r\n const storage = this.#getStorage(option);\r\n storage.removeItem(key);\r\n }\r\n\r\n /**\r\n * Deep Clone an toàn\r\n */\r\n #deepClone<T>(val: T): T {\r\n if (val === undefined || val === null) return val;\r\n return JSON.parse(JSON.stringify(val));\r\n }\r\n}","/**\n * Generated bundle index. Do not edit.\n */\n\nexport * from './index';\n"],"names":[],"mappings":";;;;;;MAyBa,iBAAiB,GAAG,IAAI,cAAc,CAA0B,uBAAuB;;ACzBpG;MAea,gBAAgB,CAAA;;AAE3B,IAAA,YAAY,GAAG,IAAI,GAAG,EAAkC;AACxD,IAAA,SAAS,GAAG,IAAI,GAAG,EAAgC;IAClC,aAAa,GAAmC,MAAM,CAAC,iBAAiB,EAAE,EAAE,QAAQ,EAAE,IAAI,EAAE,CAAC;IAE9G,MAAM,CAAU,GAAoB,EAAE,MAA2B,EAAA;AAC/D,QAAA,IAAI,CAAC,GAAG;AAAE,YAAA,MAAM,IAAI,KAAK,CAAC,iBAAiB,CAAC;;AAG5C,QAAA,IAAI,OAAe;AACnB,QAAA,IAAI,OAAO,GAAG,KAAK,QAAQ,EAAE;YAC3B,OAAO,GAAG,GAAG;QACf;AAAO,aAAA,IAAI,OAAO,GAAG,KAAK,QAAQ,EAAE;AAClC,YAAA,OAAO,GAAG,SAAS,CAAC,IAAI,CAAC,GAAG,CAAC;QAC/B;aAAO;AACL,YAAA,MAAM,IAAI,KAAK,CAAC,kBAAkB,CAAC;QACrC;AAEA,QAAA,IAAI,IAAI,CAAC,aAAa,EAAE,GAAG,EAAE;YAC3B,OAAO,GAAG,IAAI,CAAC,aAAa,CAAC,GAAG,CAAC,OAAO,CAAC;QAC3C;;QAGA,IAAI,CAAC,IAAI,CAAC,SAAS,CAAC,GAAG,CAAC,OAAO,CAAC,EAAE;YAChC,MAAM,YAAY,GAAG,IAAI,CAAC,YAAY,CAAI,OAAO,EAAE,MAAM,CAAC;;AAE1D,YAAA,IAAI,CAAC,SAAS,CAAC,GAAG,CAAC,OAAO,EAAE,IAAI,eAAe,CAAgB,YAAY,I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CAAA;AACV,oBAAA,UAAU,EAAE,MAAM;AACnB,iBAAA;;;ACdD;;AAEG;;;;"}
@@ -383,9 +383,51 @@ const hslToHex = ColorUtilities.hslToHex;
383
383
  /** @deprecated Use {@link ColorUtilities.rgbToHex} from `@sdcorejs/utils/fns` instead */
384
384
  const rgbToHex = ColorUtilities.rgbToHex;
385
385
 
386
+ const isPlainObject = (value) => {
387
+ if (value === null || typeof value !== 'object')
388
+ return false;
389
+ const prototype = Object.getPrototypeOf(value);
390
+ return prototype === Object.prototype || prototype === null;
391
+ };
392
+ const clone = (value) => {
393
+ if (Array.isArray(value)) {
394
+ return value.map(item => clone(item));
395
+ }
396
+ if (isPlainObject(value)) {
397
+ return Object.keys(value).reduce((result, key) => {
398
+ result[key] = clone(value[key]);
399
+ return result;
400
+ }, {});
401
+ }
402
+ return value;
403
+ };
404
+ const merge = (target, source) => {
405
+ const result = clone(target);
406
+ Object.keys(source).forEach(key => {
407
+ const sourceValue = source[key];
408
+ if (sourceValue === undefined)
409
+ return;
410
+ const targetValue = result[key];
411
+ if (isPlainObject(targetValue) && isPlainObject(sourceValue)) {
412
+ result[key] = merge(targetValue, sourceValue);
413
+ }
414
+ else {
415
+ result[key] = clone(sourceValue);
416
+ }
417
+ });
418
+ return result;
419
+ };
420
+ const deepMerge = (...sources) => sources.reduce((result, source) => merge(result, source), {});
421
+ const ObjectUtilities = {
422
+ isPlainObject,
423
+ clone,
424
+ merge,
425
+ deepMerge,
426
+ };
427
+
386
428
  /**
387
429
  * Generated bundle index. Do not edit.
388
430
  */
389
431
 
390
- export { SdUtilities, StringUtilities, hslToHex, rgbToHex };
432
+ export { ObjectUtilities, SdUtilities, StringUtilities, hslToHex, rgbToHex };
391
433
  //# sourceMappingURL=sd-angular-core-utilities-extensions.mjs.map