@sdcorejs/angular 22.3.0 → 22.3.2

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 (199) hide show
  1. package/README.md +2 -2
  2. package/assets/STYLE-GUIDE.md +25 -5
  3. package/assets/THEME.md +237 -5
  4. package/assets/licenses/tiptap-oss-NOTICES.txt +332 -0
  5. package/assets/scss/ckeditor5.scss +2 -88
  6. package/assets/scss/core/_control.scss +39 -0
  7. package/assets/scss/core/form.scss +156 -45
  8. package/assets/scss/core/view.scss +24 -0
  9. package/assets/scss/editor-content.scss +173 -0
  10. package/assets/scss/sd-core.scss +1 -0
  11. package/assets/scss/themes/_component-tokens.scss +93 -31
  12. package/assets/scss/themes/_material-tokens.scss +112 -0
  13. package/assets/scss/themes/_presets.scss +25 -0
  14. package/assets/scss/themes/_scales.scss +10 -0
  15. package/assets/scss/themes/_semantic.scss +13 -0
  16. package/assets/scss/themes/default.scss +8 -2
  17. package/fesm2022/sdcorejs-angular-components-api-contract-builder.mjs +5 -5
  18. package/fesm2022/sdcorejs-angular-components-api-contract-builder.mjs.map +1 -1
  19. package/fesm2022/sdcorejs-angular-components-avatar.mjs +166 -11
  20. package/fesm2022/sdcorejs-angular-components-avatar.mjs.map +1 -1
  21. package/fesm2022/sdcorejs-angular-components-badge.mjs +590 -24
  22. package/fesm2022/sdcorejs-angular-components-badge.mjs.map +1 -1
  23. package/fesm2022/sdcorejs-angular-components-button.mjs +35 -3
  24. package/fesm2022/sdcorejs-angular-components-button.mjs.map +1 -1
  25. package/fesm2022/sdcorejs-angular-components-ckeditor-styles.mjs +5 -20
  26. package/fesm2022/sdcorejs-angular-components-ckeditor-styles.mjs.map +1 -1
  27. package/fesm2022/sdcorejs-angular-components-data-state.mjs +1 -1
  28. package/fesm2022/sdcorejs-angular-components-data-state.mjs.map +1 -1
  29. package/fesm2022/sdcorejs-angular-components-editor-engine.mjs +1906 -0
  30. package/fesm2022/sdcorejs-angular-components-editor-engine.mjs.map +1 -0
  31. package/fesm2022/sdcorejs-angular-components-editor.mjs +461 -757
  32. package/fesm2022/sdcorejs-angular-components-editor.mjs.map +1 -1
  33. package/fesm2022/sdcorejs-angular-components-file-explorer.mjs +2295 -106
  34. package/fesm2022/sdcorejs-angular-components-file-explorer.mjs.map +1 -1
  35. package/fesm2022/sdcorejs-angular-components-form-generic.mjs +2686 -1050
  36. package/fesm2022/sdcorejs-angular-components-form-generic.mjs.map +1 -1
  37. package/fesm2022/sdcorejs-angular-components-history.mjs +5 -2
  38. package/fesm2022/sdcorejs-angular-components-history.mjs.map +1 -1
  39. package/fesm2022/sdcorejs-angular-components-image-editor.mjs +1 -1
  40. package/fesm2022/sdcorejs-angular-components-image-editor.mjs.map +1 -1
  41. package/fesm2022/sdcorejs-angular-components-import-excel.mjs +21 -6
  42. package/fesm2022/sdcorejs-angular-components-import-excel.mjs.map +1 -1
  43. package/fesm2022/sdcorejs-angular-components-inform.mjs +1 -1
  44. package/fesm2022/sdcorejs-angular-components-inform.mjs.map +1 -1
  45. package/fesm2022/sdcorejs-angular-components-kanban.mjs +474 -0
  46. package/fesm2022/sdcorejs-angular-components-kanban.mjs.map +1 -0
  47. package/fesm2022/sdcorejs-angular-components-mini-editor.mjs +182 -284
  48. package/fesm2022/sdcorejs-angular-components-mini-editor.mjs.map +1 -1
  49. package/fesm2022/sdcorejs-angular-components-modal-resizable.mjs +1 -316
  50. package/fesm2022/sdcorejs-angular-components-modal-resizable.mjs.map +1 -1
  51. package/fesm2022/sdcorejs-angular-components-modal.mjs +2 -2
  52. package/fesm2022/sdcorejs-angular-components-modal.mjs.map +1 -1
  53. package/fesm2022/sdcorejs-angular-components-operator.mjs +274 -44
  54. package/fesm2022/sdcorejs-angular-components-operator.mjs.map +1 -1
  55. package/fesm2022/sdcorejs-angular-components-query-bar.mjs +12 -12
  56. package/fesm2022/sdcorejs-angular-components-query-bar.mjs.map +1 -1
  57. package/fesm2022/sdcorejs-angular-components-query-builder.mjs +1 -1
  58. package/fesm2022/sdcorejs-angular-components-query-builder.mjs.map +1 -1
  59. package/fesm2022/sdcorejs-angular-components-section.mjs +5 -4
  60. package/fesm2022/sdcorejs-angular-components-section.mjs.map +1 -1
  61. package/fesm2022/sdcorejs-angular-components-side-drawer.mjs +2 -2
  62. package/fesm2022/sdcorejs-angular-components-side-drawer.mjs.map +1 -1
  63. package/fesm2022/sdcorejs-angular-components-stepper.mjs +5 -1
  64. package/fesm2022/sdcorejs-angular-components-stepper.mjs.map +1 -1
  65. package/fesm2022/sdcorejs-angular-components-tab-router.mjs +202 -43
  66. package/fesm2022/sdcorejs-angular-components-tab-router.mjs.map +1 -1
  67. package/fesm2022/sdcorejs-angular-components-tab.mjs +12 -4
  68. package/fesm2022/sdcorejs-angular-components-tab.mjs.map +1 -1
  69. package/fesm2022/sdcorejs-angular-components-table.mjs +581 -110
  70. package/fesm2022/sdcorejs-angular-components-table.mjs.map +1 -1
  71. package/fesm2022/sdcorejs-angular-components-tree.mjs +1 -1
  72. package/fesm2022/sdcorejs-angular-components-tree.mjs.map +1 -1
  73. package/fesm2022/sdcorejs-angular-components-upload-file.mjs +1 -1
  74. package/fesm2022/sdcorejs-angular-components-upload-file.mjs.map +1 -1
  75. package/fesm2022/sdcorejs-angular-components-view.mjs +2 -2
  76. package/fesm2022/sdcorejs-angular-components-view.mjs.map +1 -1
  77. package/fesm2022/sdcorejs-angular-components-window.mjs +498 -0
  78. package/fesm2022/sdcorejs-angular-components-window.mjs.map +1 -0
  79. package/fesm2022/sdcorejs-angular-components.mjs +2 -0
  80. package/fesm2022/sdcorejs-angular-components.mjs.map +1 -1
  81. package/fesm2022/sdcorejs-angular-configurations.mjs.map +1 -1
  82. package/fesm2022/sdcorejs-angular-directives.mjs +18 -1
  83. package/fesm2022/sdcorejs-angular-directives.mjs.map +1 -1
  84. package/fesm2022/sdcorejs-angular-forms-autocomplete.mjs +15 -2
  85. package/fesm2022/sdcorejs-angular-forms-autocomplete.mjs.map +1 -1
  86. package/fesm2022/sdcorejs-angular-forms-checkbox.mjs +2 -2
  87. package/fesm2022/sdcorejs-angular-forms-checkbox.mjs.map +1 -1
  88. package/fesm2022/sdcorejs-angular-forms-chip-calendar.mjs +480 -126
  89. package/fesm2022/sdcorejs-angular-forms-chip-calendar.mjs.map +1 -1
  90. package/fesm2022/sdcorejs-angular-forms-date-range.mjs +82 -13
  91. package/fesm2022/sdcorejs-angular-forms-date-range.mjs.map +1 -1
  92. package/fesm2022/sdcorejs-angular-forms-date.mjs +77 -18
  93. package/fesm2022/sdcorejs-angular-forms-date.mjs.map +1 -1
  94. package/fesm2022/sdcorejs-angular-forms-datetime.mjs +75 -16
  95. package/fesm2022/sdcorejs-angular-forms-datetime.mjs.map +1 -1
  96. package/fesm2022/sdcorejs-angular-forms-directives.mjs +90 -2
  97. package/fesm2022/sdcorejs-angular-forms-directives.mjs.map +1 -1
  98. package/fesm2022/sdcorejs-angular-forms-entity-picker.mjs +2 -2
  99. package/fesm2022/sdcorejs-angular-forms-entity-picker.mjs.map +1 -1
  100. package/fesm2022/sdcorejs-angular-forms-input-color.mjs +1 -1
  101. package/fesm2022/sdcorejs-angular-forms-input-color.mjs.map +1 -1
  102. package/fesm2022/sdcorejs-angular-forms-input-number.mjs +46 -5
  103. package/fesm2022/sdcorejs-angular-forms-input-number.mjs.map +1 -1
  104. package/fesm2022/sdcorejs-angular-forms-input.mjs +56 -7
  105. package/fesm2022/sdcorejs-angular-forms-input.mjs.map +1 -1
  106. package/fesm2022/sdcorejs-angular-forms-models.mjs +88 -5
  107. package/fesm2022/sdcorejs-angular-forms-models.mjs.map +1 -1
  108. package/fesm2022/sdcorejs-angular-forms-radio.mjs +2 -2
  109. package/fesm2022/sdcorejs-angular-forms-radio.mjs.map +1 -1
  110. package/fesm2022/sdcorejs-angular-forms-segmented.mjs +263 -0
  111. package/fesm2022/sdcorejs-angular-forms-segmented.mjs.map +1 -0
  112. package/fesm2022/sdcorejs-angular-forms-select.mjs +71 -15
  113. package/fesm2022/sdcorejs-angular-forms-select.mjs.map +1 -1
  114. package/fesm2022/sdcorejs-angular-forms-switch.mjs +2 -2
  115. package/fesm2022/sdcorejs-angular-forms-switch.mjs.map +1 -1
  116. package/fesm2022/sdcorejs-angular-forms-textarea.mjs +2 -2
  117. package/fesm2022/sdcorejs-angular-forms-textarea.mjs.map +1 -1
  118. package/fesm2022/sdcorejs-angular-forms-time.mjs +2 -2
  119. package/fesm2022/sdcorejs-angular-forms-time.mjs.map +1 -1
  120. package/fesm2022/sdcorejs-angular-forms-tree-select.mjs +1 -1
  121. package/fesm2022/sdcorejs-angular-forms-tree-select.mjs.map +1 -1
  122. package/fesm2022/sdcorejs-angular-forms.mjs +8 -0
  123. package/fesm2022/sdcorejs-angular-forms.mjs.map +1 -1
  124. package/fesm2022/sdcorejs-angular-i18n.mjs +1830 -17
  125. package/fesm2022/sdcorejs-angular-i18n.mjs.map +1 -1
  126. package/fesm2022/sdcorejs-angular-interceptors.mjs +1 -1
  127. package/fesm2022/sdcorejs-angular-interceptors.mjs.map +1 -1
  128. package/fesm2022/sdcorejs-angular-modules-generic-generic-configuration.page-BrJfOTWy.mjs +509 -0
  129. package/fesm2022/sdcorejs-angular-modules-generic-generic-configuration.page-BrJfOTWy.mjs.map +1 -0
  130. package/fesm2022/sdcorejs-angular-modules-generic-generic-form-host.page-DQYXx2nr.mjs +232 -0
  131. package/fesm2022/sdcorejs-angular-modules-generic-generic-form-host.page-DQYXx2nr.mjs.map +1 -0
  132. package/fesm2022/sdcorejs-angular-modules-generic-generic-list.page-Cjg3Dfq1.mjs +294 -0
  133. package/fesm2022/sdcorejs-angular-modules-generic-generic-list.page-Cjg3Dfq1.mjs.map +1 -0
  134. package/fesm2022/sdcorejs-angular-modules-generic-sdcorejs-angular-modules-generic-DpXg2yI7.mjs +1556 -0
  135. package/fesm2022/sdcorejs-angular-modules-generic-sdcorejs-angular-modules-generic-DpXg2yI7.mjs.map +1 -0
  136. package/fesm2022/sdcorejs-angular-modules-generic.mjs +2 -0
  137. package/fesm2022/sdcorejs-angular-modules-generic.mjs.map +1 -0
  138. package/fesm2022/sdcorejs-angular-modules-icon.mjs +96 -3
  139. package/fesm2022/sdcorejs-angular-modules-icon.mjs.map +1 -1
  140. package/fesm2022/sdcorejs-angular-modules-layout.mjs +1908 -46
  141. package/fesm2022/sdcorejs-angular-modules-layout.mjs.map +1 -1
  142. package/fesm2022/sdcorejs-angular-modules.mjs +1 -0
  143. package/fesm2022/sdcorejs-angular-modules.mjs.map +1 -1
  144. package/fesm2022/sdcorejs-angular-pipes.mjs +27 -7
  145. package/fesm2022/sdcorejs-angular-pipes.mjs.map +1 -1
  146. package/fesm2022/sdcorejs-angular-services-confirm.mjs +2 -2
  147. package/fesm2022/sdcorejs-angular-services-confirm.mjs.map +1 -1
  148. package/fesm2022/sdcorejs-angular-services-date-time.mjs +143 -0
  149. package/fesm2022/sdcorejs-angular-services-date-time.mjs.map +1 -0
  150. package/fesm2022/sdcorejs-angular-services-storage.mjs +44 -8
  151. package/fesm2022/sdcorejs-angular-services-storage.mjs.map +1 -1
  152. package/fesm2022/sdcorejs-angular-services.mjs +1 -0
  153. package/fesm2022/sdcorejs-angular-services.mjs.map +1 -1
  154. package/fesm2022/sdcorejs-angular-utilities-read-state.mjs +4 -0
  155. package/fesm2022/sdcorejs-angular-utilities-read-state.mjs.map +1 -1
  156. package/fesm2022/sdcorejs-angular-utilities-theme.mjs +10 -0
  157. package/fesm2022/sdcorejs-angular-utilities-theme.mjs.map +1 -1
  158. package/package.json +48 -7
  159. package/types/sdcorejs-angular-components-avatar.d.ts +67 -2
  160. package/types/sdcorejs-angular-components-badge.d.ts +188 -6
  161. package/types/sdcorejs-angular-components-button.d.ts +20 -1
  162. package/types/sdcorejs-angular-components-ckeditor-styles.d.ts +3 -18
  163. package/types/sdcorejs-angular-components-editor-engine.d.ts +246 -0
  164. package/types/sdcorejs-angular-components-editor.d.ts +20 -17
  165. package/types/sdcorejs-angular-components-file-explorer.d.ts +449 -57
  166. package/types/sdcorejs-angular-components-form-generic.d.ts +301 -37
  167. package/types/sdcorejs-angular-components-kanban.d.ts +179 -0
  168. package/types/sdcorejs-angular-components-mini-editor.d.ts +33 -70
  169. package/types/sdcorejs-angular-components-modal-resizable.d.ts +1 -124
  170. package/types/sdcorejs-angular-components-operator.d.ts +137 -8
  171. package/types/sdcorejs-angular-components-section.d.ts +2 -1
  172. package/types/sdcorejs-angular-components-tab-router.d.ts +31 -18
  173. package/types/sdcorejs-angular-components-tab.d.ts +3 -1
  174. package/types/sdcorejs-angular-components-table.d.ts +84 -6
  175. package/types/sdcorejs-angular-components-window.d.ts +81 -0
  176. package/types/sdcorejs-angular-components.d.ts +2 -0
  177. package/types/sdcorejs-angular-configurations.d.ts +8 -1
  178. package/types/sdcorejs-angular-forms-autocomplete.d.ts +5 -0
  179. package/types/sdcorejs-angular-forms-chip-calendar.d.ts +163 -18
  180. package/types/sdcorejs-angular-forms-date-range.d.ts +24 -2
  181. package/types/sdcorejs-angular-forms-date.d.ts +23 -2
  182. package/types/sdcorejs-angular-forms-directives.d.ts +47 -2
  183. package/types/sdcorejs-angular-forms-input-number.d.ts +23 -2
  184. package/types/sdcorejs-angular-forms-input.d.ts +23 -2
  185. package/types/sdcorejs-angular-forms-models.d.ts +38 -3
  186. package/types/sdcorejs-angular-forms-segmented.d.ts +90 -0
  187. package/types/sdcorejs-angular-forms-select.d.ts +32 -2
  188. package/types/sdcorejs-angular-forms.d.ts +8 -6
  189. package/types/sdcorejs-angular-i18n.d.ts +360 -1
  190. package/types/sdcorejs-angular-modules-generic.d.ts +316 -0
  191. package/types/sdcorejs-angular-modules-icon.d.ts +37 -6
  192. package/types/sdcorejs-angular-modules-layout.d.ts +536 -86
  193. package/types/sdcorejs-angular-modules.d.ts +1 -0
  194. package/types/sdcorejs-angular-pipes.d.ts +2 -0
  195. package/types/sdcorejs-angular-services-date-time.d.ts +57 -0
  196. package/types/sdcorejs-angular-services-storage.d.ts +8 -1
  197. package/types/sdcorejs-angular-services.d.ts +1 -0
  198. package/types/sdcorejs-angular-utilities-read-state.d.ts +2 -0
  199. package/types/sdcorejs-angular-utilities-theme.d.ts +1 -1
@@ -3,196 +3,23 @@ import { InjectionToken, inject, DestroyRef, ChangeDetectorRef, input, booleanAt
3
3
  import { Utilities } from '@sdcorejs/utils/fns';
4
4
  import { takeUntilDestroyed } from '@angular/core/rxjs-interop';
5
5
  import { NgForm, FormGroup } from '@angular/forms';
6
- import * as i2 from '@angular/material/form-field';
6
+ import * as i1 from '@angular/material/form-field';
7
7
  import { MatFormFieldModule } from '@angular/material/form-field';
8
- import * as i3 from '@angular/material/tooltip';
8
+ import * as i2 from '@angular/material/tooltip';
9
9
  import { MatTooltipModule } from '@angular/material/tooltip';
10
- import * as i1 from '@ckeditor/ckeditor5-angular';
11
- import { CKEditorModule } from '@ckeditor/ckeditor5-angular';
12
- import { Plugin, FileRepository, Image, ImageResize, ImageUpload, ImageStyle, ImageToolbar, ClassicEditor, Essentials, FontColor, FontSize, Paragraph, Bold, Italic, Underline, List, Undo, Widget, Alignment } from 'ckeditor5';
13
- import { Subject } from 'rxjs';
14
- import { debounceTime } from 'rxjs/operators';
10
+ import { SdEditorSurface } from '@sdcorejs/angular/components/editor-engine';
11
+ export { SdEditorImportError } from '@sdcorejs/angular/components/editor-engine';
15
12
  import { SdNotifyService } from '@sdcorejs/angular/services';
16
13
  import { I18nService } from '@sdcorejs/angular/i18n';
17
14
  import { sdIsEmpty } from '@sdcorejs/angular/utilities/data-state';
18
15
  import { sdSanitizeEditorHtml } from '@sdcorejs/angular/utilities/extensions';
19
- import { SdFormControl, ɵsdFormControlConnector as _sdFormControlConnector, HandleSdCustomValidator } from '@sdcorejs/angular/forms/models';
20
- import { SdCKEditorStyles } from '@sdcorejs/angular/components/ckeditor-styles';
21
16
  import { SdLabel } from '@sdcorejs/angular/forms/label';
22
17
  import { SdIcon } from '@sdcorejs/angular/modules/icon';
18
+ import { parse } from 'parse5';
19
+ import { SdFormControl, ɵsdFormControlConnector as _sdFormControlConnector, HandleSdCustomValidator } from '@sdcorejs/angular/forms/models';
23
20
 
24
21
  const SD_EDITOR_CONFIGURATION = new InjectionToken('sd.editor.configuration');
25
22
 
26
- // Dựa vào file để detect định dạng thay vì chỉ check tên
27
- // Tránh user gửi file không đúng, ví dụ file docx nhưng đổi tên thành ảnh docx.jpg
28
- const detectFormatFromBytes = async (file) => {
29
- const buffer = await file.slice(0, 12).arrayBuffer();
30
- const b = new Uint8Array(buffer);
31
- if (b[0] === 0xff && b[1] === 0xd8 && b[2] === 0xff)
32
- return 'jpg';
33
- if (b[0] === 0x89 && b[1] === 0x50 && b[2] === 0x4e && b[3] === 0x47)
34
- return 'png';
35
- if (b[0] === 0x52 && b[1] === 0x49 && b[2] === 0x46 && b[3] === 0x46 && b[8] === 0x57)
36
- return 'webp';
37
- if (b[0] === 0x47 && b[1] === 0x49 && b[2] === 0x46 && b[3] === 0x38)
38
- return 'gif';
39
- if (b[4] === 0x66 && b[5] === 0x74 && b[6] === 0x79 && b[7] === 0x70) {
40
- const brand = String.fromCharCode(b[8], b[9], b[10], b[11]);
41
- if (brand === 'avif')
42
- return 'avif';
43
- if (brand.startsWith('hei'))
44
- return 'heic';
45
- }
46
- return '';
47
- };
48
- const getImageInfo = async (file) => {
49
- const sizeMB = file.size / (1024 * 1024);
50
- const loadDimensions = new Promise(resolve => {
51
- const url = URL.createObjectURL(file);
52
- const img = new window.Image();
53
- img.onload = () => {
54
- URL.revokeObjectURL(url);
55
- resolve({ width: img.naturalWidth, height: img.naturalHeight });
56
- };
57
- img.onerror = () => {
58
- URL.revokeObjectURL(url);
59
- resolve({ width: 0, height: 0 });
60
- };
61
- img.src = url;
62
- });
63
- const [format, { width, height }] = await Promise.all([detectFormatFromBytes(file), loadDimensions]);
64
- return { width, height, sizeMB, format };
65
- };
66
- // Helper: gọi i18n.t khi có service; nếu thiếu thì trả empty (Angular wrapper luôn truyền i18n)
67
- const tr = (i18n, key, params) => i18n?.t(key, params) ?? '';
68
- const validateImageFile = async (file, validation, onWarning, i18n) => {
69
- const { width, height, sizeMB, format } = await getImageInfo(file);
70
- if (validation.allowedFormats !== undefined) {
71
- const normalizedFormats = validation.allowedFormats.map((f) => {
72
- const fmt = f.replace(/^\./, '').toLowerCase();
73
- return fmt === 'jpeg' ? 'jpg' : fmt;
74
- });
75
- if (!normalizedFormats.includes(format)) {
76
- const allowed = normalizedFormats.join(', ');
77
- onWarning?.(tr(i18n, 'core.component.editor.image.invalid-format', { format, allowed }));
78
- return false;
79
- }
80
- }
81
- if (validation.maxSizeMB !== undefined && sizeMB > validation.maxSizeMB) {
82
- const sizeMBFixed = sizeMB.toFixed(2);
83
- onWarning?.(tr(i18n, 'core.component.editor.image.size-exceeded', { sizeMB: sizeMBFixed, maxSizeMB: validation.maxSizeMB }));
84
- return false;
85
- }
86
- if (validation.minWidth !== undefined && width < validation.minWidth) {
87
- onWarning?.(tr(i18n, 'core.component.editor.image.min-width', { width, min: validation.minWidth }));
88
- return false;
89
- }
90
- if (validation.minHeight !== undefined && height < validation.minHeight) {
91
- onWarning?.(tr(i18n, 'core.component.editor.image.min-height', { height, min: validation.minHeight }));
92
- return false;
93
- }
94
- if (validation.maxWidth !== undefined && width > validation.maxWidth) {
95
- onWarning?.(tr(i18n, 'core.component.editor.image.max-width', { width, max: validation.maxWidth }));
96
- return false;
97
- }
98
- if (validation.maxHeight !== undefined && height > validation.maxHeight) {
99
- onWarning?.(tr(i18n, 'core.component.editor.image.max-height', { height, max: validation.maxHeight }));
100
- return false;
101
- }
102
- return true;
103
- };
104
- const validateAndGetFile = async (loader, validation, onWarning, i18n) => {
105
- const file = (await loader.file);
106
- if (!file) {
107
- throw new Error('No file found');
108
- }
109
- if (validation) {
110
- const valid = await validateImageFile(file, validation, onWarning, i18n);
111
- if (!valid) {
112
- throw new Error('Image validation failed');
113
- }
114
- }
115
- return file;
116
- };
117
-
118
- const getBatchConfig = (option) => {
119
- const imageConfig = option?.imageConfig;
120
- return {
121
- batchSize: Math.max(1, imageConfig?.batchSize ?? 2),
122
- maxConcurrent: Math.max(1, imageConfig?.maxConcurrentUploads ?? 2),
123
- };
124
- };
125
- const getActiveBlobUrls = (editor) => {
126
- const urls = new Set();
127
- const root = editor.model.document.getRoot();
128
- if (!root)
129
- return urls;
130
- for (const item of editor.model.createRangeIn(root).getItems()) {
131
- if (item.is('element', 'imageBlock') || item.is('element', 'imageInline')) {
132
- const src = item.getAttribute('src');
133
- if (src?.startsWith('blob:'))
134
- urls.add(src);
135
- }
136
- }
137
- return urls;
138
- };
139
- const filterActivePendingFiles = (pendingFiles, activeBlobUrls) => {
140
- const toUpload = [];
141
- for (const [blobUrl, file] of pendingFiles) {
142
- if (activeBlobUrls.has(blobUrl)) {
143
- toUpload.push([blobUrl, file]);
144
- }
145
- else {
146
- URL.revokeObjectURL(blobUrl);
147
- pendingFiles.delete(blobUrl);
148
- }
149
- }
150
- return toUpload;
151
- };
152
- const runBatchUploads = async (toUpload, uploadFn, batchSize, maxConcurrent) => {
153
- const batches = [];
154
- for (let i = 0; i < toUpload.length; i += batchSize) {
155
- batches.push(toUpload.slice(i, i + batchSize));
156
- }
157
- const replacements = new Map();
158
- const failedBatches = [];
159
- let head = 0;
160
- const runWorker = async () => {
161
- while (head < batches.length) {
162
- const batch = batches[head++];
163
- try {
164
- const details = await uploadFn(batch.map(([, file]) => file));
165
- if (details.length !== batch.length) {
166
- throw new Error(`API returned ${details.length} results for ${batch.length} files`);
167
- }
168
- batch.forEach(([blobUrl], idx) => {
169
- replacements.set(blobUrl, details[idx]);
170
- URL.revokeObjectURL(blobUrl);
171
- });
172
- }
173
- catch {
174
- failedBatches.push(batch);
175
- }
176
- }
177
- };
178
- await Promise.all(Array.from({ length: Math.min(maxConcurrent, batches.length) }, runWorker));
179
- return { replacements, failedBatches };
180
- };
181
- const applyReplacementsToEditor = (editor, replacements) => {
182
- if (replacements.size === 0)
183
- return;
184
- editor.model.change(writer => {
185
- const root = editor.model.document.getRoot();
186
- for (const item of editor.model.createRangeIn(root).getItems()) {
187
- if (!item.is('element', 'imageBlock') && !item.is('element', 'imageInline'))
188
- continue;
189
- const detail = replacements.get(item.getAttribute('src'));
190
- if (detail)
191
- writer.setAttribute('src', detail.cdn, item);
192
- }
193
- });
194
- };
195
-
196
23
  const parseStyle = (style) => {
197
24
  const map = new Map();
198
25
  for (const decl of style.split(';')) {
@@ -210,6 +37,20 @@ const serializeStyle = (map) => [...map.entries()].map(([k, v]) => `${k}:${v}`).
210
37
  const countTextLength = (content) => {
211
38
  if (!content)
212
39
  return 0;
40
+ // The same standards-based HTML tree and UTF-16 text counting on the server.
41
+ if (typeof DOMParser === 'undefined') {
42
+ const document = parse(content, { scriptingEnabled: false });
43
+ const html = document.childNodes.find(node => node.nodeName === 'html');
44
+ const body = html && 'childNodes' in html ? html.childNodes.find(node => node.nodeName === 'body') : undefined;
45
+ const count = (node) => {
46
+ if ('tagName' in node && (node.tagName === 'img' || node.tagName === 'figure'))
47
+ return 0;
48
+ if (node.nodeName === '#text' && 'value' in node)
49
+ return node.value.length;
50
+ return 'childNodes' in node ? node.childNodes.reduce((length, child) => length + count(child), 0) : 0;
51
+ };
52
+ return body ? count(body) : 0;
53
+ }
213
54
  const doc = new DOMParser().parseFromString(content, 'text/html');
214
55
  doc.querySelectorAll('img, figure').forEach(el => el.remove());
215
56
  return doc.body.textContent?.length ?? 0;
@@ -320,364 +161,310 @@ const imageClassesToInlineStyles = (html) => {
320
161
  return doc.body.innerHTML;
321
162
  };
322
163
 
323
- class UploadQueue {
324
- #queue = [];
325
- #running = 0;
326
- maxConcurrent;
327
- constructor(maxConcurrent) {
328
- this.maxConcurrent = maxConcurrent;
329
- }
330
- async run(task) {
331
- if (this.#running >= this.maxConcurrent) {
332
- await new Promise(resolve => {
333
- this.#queue.push(resolve);
334
- });
335
- }
336
- this.#running++;
337
- try {
338
- return await task();
339
- }
340
- finally {
341
- this.#running--;
342
- this.#queue.shift()?.();
343
- }
164
+ const detectFormatFromBytes = async (file) => {
165
+ const b = new Uint8Array(await file.slice(0, 12).arrayBuffer());
166
+ if (b[0] === 0xff && b[1] === 0xd8 && b[2] === 0xff)
167
+ return 'jpg';
168
+ if ([0x89, 0x50, 0x4e, 0x47, 0x0d, 0x0a, 0x1a, 0x0a].every((v, i) => b[i] === v))
169
+ return 'png';
170
+ if (String.fromCharCode(...b.slice(0, 4)) === 'RIFF' && String.fromCharCode(...b.slice(8, 12)) === 'WEBP')
171
+ return 'webp';
172
+ if (['GIF87a', 'GIF89a'].includes(String.fromCharCode(...b.slice(0, 6))))
173
+ return 'gif';
174
+ if (String.fromCharCode(...b.slice(4, 8)) === 'ftyp') {
175
+ const brand = String.fromCharCode(...b.slice(8, 12));
176
+ if (['avif', 'avis'].includes(brand))
177
+ return 'avif';
178
+ if (['heic', 'heix', 'hevc', 'hevx'].includes(brand))
179
+ return 'heic';
344
180
  }
345
- }
346
- class BatchUploadScheduler {
347
- #pending = [];
348
- #timer = null;
349
- #batchSize;
350
- #uploadFn;
351
- #queue;
352
- constructor(batchSize, uploadFn, queue) {
353
- this.#batchSize = batchSize;
354
- this.#uploadFn = uploadFn;
355
- this.#queue = queue;
181
+ return '';
182
+ };
183
+ const loadDimensions = (file, signal) => new Promise((resolve, reject) => {
184
+ if (signal?.aborted) {
185
+ reject(new Error('Image validation cancelled'));
186
+ return;
356
187
  }
357
- enqueue(file) {
358
- return new Promise((resolve, reject) => {
359
- this.#pending.push({ file, resolve, reject });
360
- if (this.#timer) {
361
- clearTimeout(this.#timer);
362
- }
363
- if (this.#pending.length >= this.#batchSize) {
364
- this.#timer = null;
365
- this.#flush();
366
- }
367
- else {
368
- this.#timer = setTimeout(() => this.#flush(), 50);
369
- }
370
- });
188
+ const url = URL.createObjectURL(file);
189
+ const img = new Image();
190
+ const finish = (dimensions) => {
191
+ clearTimeout(timer);
192
+ signal?.removeEventListener('abort', abort);
193
+ img.onload = img.onerror = null;
194
+ img.src = '';
195
+ URL.revokeObjectURL(url);
196
+ if (dimensions)
197
+ resolve(dimensions);
198
+ else
199
+ reject(new Error('Image validation cancelled'));
200
+ };
201
+ const abort = () => finish();
202
+ const timer = setTimeout(() => finish({ width: 0, height: 0 }), 15000);
203
+ signal?.addEventListener('abort', abort, { once: true });
204
+ img.onload = () => finish({ width: img.naturalWidth, height: img.naturalHeight });
205
+ img.onerror = () => finish({ width: 0, height: 0 });
206
+ img.src = url;
207
+ });
208
+ const validateAndGetFile = async (loader, validation = {}, onWarning, i18n, signal) => {
209
+ const file = await loader.file;
210
+ if (!file)
211
+ throw new Error('No file found');
212
+ const warn = (key, params) => onWarning?.(i18n?.t(key, params) ?? '');
213
+ const format = await detectFormatFromBytes(file);
214
+ const allowed = validation.allowedFormats?.map(value => {
215
+ const normalized = value.replace(/^\./, '').toLowerCase();
216
+ return normalized === 'jpeg' ? 'jpg' : normalized;
217
+ });
218
+ if (!format || (allowed && !allowed.includes(format))) {
219
+ warn('core.component.editor.image.invalid-format', { format, allowed: allowed?.join(', ') ?? 'jpg, png, webp, gif, avif, heic' });
220
+ throw new Error('Image validation failed');
371
221
  }
372
- destroy() {
373
- if (this.#timer !== null) {
374
- clearTimeout(this.#timer);
375
- this.#timer = null;
222
+ const sizeMB = file.size / (1024 * 1024);
223
+ if (validation.maxSizeMB !== undefined && sizeMB > validation.maxSizeMB) {
224
+ warn('core.component.editor.image.size-exceeded', { sizeMB: sizeMB.toFixed(2), maxSizeMB: validation.maxSizeMB });
225
+ throw new Error('Image validation failed');
226
+ }
227
+ const { width, height } = await loadDimensions(file, signal);
228
+ if (!width || !height) {
229
+ warn('core.component.editor.image.invalid-format', { format, allowed: allowed?.join(', ') ?? format });
230
+ throw new Error('Image validation failed');
231
+ }
232
+ const checks = [
233
+ [validation.minWidth, width, true, 'min-width', 'min'],
234
+ [validation.minHeight, height, true, 'min-height', 'min'],
235
+ [validation.maxWidth, width, false, 'max-width', 'max'],
236
+ [validation.maxHeight, height, false, 'max-height', 'max'],
237
+ ];
238
+ for (const [limit, actual, minimum, key, param] of checks) {
239
+ if (limit !== undefined && (minimum ? actual < limit : actual > limit)) {
240
+ warn(`core.component.editor.image.${key}`, { width, height, [param]: limit });
241
+ throw new Error('Image validation failed');
376
242
  }
377
- this.#pending.splice(0).forEach(p => p.reject(new Error('Upload cancelled')));
378
243
  }
379
- #flush() {
380
- this.#timer = null;
381
- const all = this.#pending.splice(0);
382
- if (all.length === 0) {
244
+ return file;
245
+ };
246
+
247
+ const positiveInteger = (value, fallback) => Number.isFinite(value) ? Math.max(1, Math.floor(value)) : fallback;
248
+ /** Per-component file queue. Invalidating work ignores callbacks; it cannot cancel an app's API request. */
249
+ class SdEditorUploadManager {
250
+ engine;
251
+ configuration;
252
+ warning;
253
+ i18n;
254
+ #pending = new Map();
255
+ #validations = new Set();
256
+ #generation = 0;
257
+ #destroyed = false;
258
+ #running;
259
+ #runningGeneration = -1;
260
+ #immediateTimer;
261
+ #nextImmediate = false;
262
+ constructor(engine, configuration, warning = () => { }, i18n) {
263
+ this.engine = engine;
264
+ this.configuration = configuration;
265
+ this.warning = warning;
266
+ this.i18n = i18n;
267
+ }
268
+ async selectFiles(files) {
269
+ if (this.#destroyed || !this.configuration().uploadFn)
270
+ return;
271
+ const config = this.configuration();
272
+ const generation = this.#generation;
273
+ const maximum = config.maxImagesPerSelection;
274
+ if (maximum !== undefined && files.length > Math.max(0, Math.floor(maximum))) {
275
+ this.warning(this.i18n?.t('core.component.editor.image.max-per-selection', { max: maximum }) ?? '');
383
276
  return;
384
277
  }
385
- for (let i = 0; i < all.length; i += this.#batchSize) {
386
- const batch = all.slice(i, i + this.#batchSize);
387
- this.#queue
388
- .run(() => this.#uploadFn(batch.map(p => p.file)))
389
- .then(details => {
390
- batch.forEach((p, idx) => {
391
- if (details && details[idx]) {
392
- p.resolve(details[idx]);
393
- }
394
- else {
395
- p.reject(new Error('Upload failed: Missing details from server'));
396
- }
397
- });
398
- })
399
- .catch(err => {
400
- batch.forEach(p => p.reject(err));
401
- });
402
- }
403
- }
404
- }
405
- class DeferredImageUploadAdapter {
406
- #loader;
407
- #pendingFiles;
408
- #imageMetaMap;
409
- #validation;
410
- #onWarning;
411
- #i18n;
412
- #lazyLoad;
413
- #currentBlobUrl = null;
414
- constructor(loader, pendingFiles, imageMetaMap, options) {
415
- this.#loader = loader;
416
- this.#pendingFiles = pendingFiles;
417
- this.#imageMetaMap = imageMetaMap;
418
- this.#validation = options.validation;
419
- this.#onWarning = options.onWarning;
420
- this.#i18n = options.i18n;
421
- this.#lazyLoad = options.lazyLoad;
422
- }
423
- upload = async () => {
424
- const file = await validateAndGetFile(this.#loader, this.#validation, this.#onWarning, this.#i18n);
425
- if (!file)
426
- throw new Error('Image validation failed');
427
- this.#currentBlobUrl = URL.createObjectURL(file);
428
- this.#pendingFiles.set(this.#currentBlobUrl, file);
429
- this.#imageMetaMap.set(this.#currentBlobUrl, { fileName: file.name, lazyLoad: this.#lazyLoad });
430
- return { default: this.#currentBlobUrl };
431
- };
432
- abort() {
433
- if (this.#currentBlobUrl) {
434
- URL.revokeObjectURL(this.#currentBlobUrl);
435
- this.#pendingFiles.delete(this.#currentBlobUrl);
436
- this.#imageMetaMap.delete(this.#currentBlobUrl);
437
- }
438
- }
439
- }
440
- class ImmediateImageUploadAdapter {
441
- #loader;
442
- #validation;
443
- #onWarning;
444
- #i18n;
445
- #scheduler;
446
- #imageMetaMap;
447
- #lazyLoad;
448
- constructor(loader, scheduler, imageMetaMap, options) {
449
- this.#loader = loader;
450
- this.#scheduler = scheduler;
451
- this.#imageMetaMap = imageMetaMap;
452
- this.#validation = options.validation;
453
- this.#onWarning = options.onWarning;
454
- this.#i18n = options.i18n;
455
- this.#lazyLoad = options.lazyLoad;
456
- }
457
- upload = async () => {
458
- const file = await validateAndGetFile(this.#loader, this.#validation, this.#onWarning, this.#i18n);
459
- if (!file)
460
- throw new Error('Image validation failed');
461
- const detail = await this.#scheduler.enqueue(file);
462
- this.#imageMetaMap.set(detail.cdn, {
463
- name: detail.name,
464
- fileName: file.name,
465
- idOrKey: detail.idOrKey,
466
- lazyLoad: this.#lazyLoad,
467
- });
468
- return { default: detail.cdn };
469
- };
470
- abort() { }
471
- }
472
- class EditorImageUploadPlugin extends Plugin {
473
- pendingFiles = new Map();
474
- uploadQueue;
475
- #batchScheduler;
476
- #imageMetaMap = new Map();
477
- setMeta(cdnUrl, meta) {
478
- this.#imageMetaMap.set(cdnUrl, { name: meta.name, idOrKey: meta.idOrKey, lazyLoad: meta.lazyLoad });
479
- }
480
- static get pluginName() {
481
- return 'EditorImageUploadPlugin';
482
- }
483
- static get requires() {
484
- return [FileRepository, Image, ImageResize, ImageUpload, ImageStyle, ImageToolbar];
485
- }
486
- init() {
487
- const editor = this.editor;
488
- const getOption = editor.config.get('getOption');
489
- const maxConcurrent = getOption?.()?.imageConfig?.maxConcurrentUploads ?? 2;
490
- this.uploadQueue = new UploadQueue(maxConcurrent);
491
- this.#registerSchemaAndConverters();
492
- this.#listenForSrcChanges();
493
- editor.editing.view.document.on('clipboardInput', (evt, data) => {
494
- const dataTransfer = data.dataTransfer;
495
- if (!dataTransfer)
278
+ for (const file of files) {
279
+ if (!this.#isCurrent(generation))
496
280
  return;
497
- const hasImageFiles = Array.from(dataTransfer.files ?? []).some(f => f.type.startsWith('image/'));
498
- const hasImageInHtml = /<img[\s>]/i.test(dataTransfer.getData('text/html') ?? '');
499
- if (hasImageFiles || hasImageInHtml) {
500
- evt.stop();
501
- }
502
- }, { priority: 'highest' });
503
- const uploadImageCommand = editor.commands.get('uploadImage');
504
- if (uploadImageCommand) {
505
- uploadImageCommand.on('execute', (evt, args) => {
506
- const options = args[0] || {};
507
- const option = getOption?.();
508
- const maxPerSelection = option?.imageConfig?.maxImagesPerSelection;
509
- if (maxPerSelection !== undefined) {
510
- const files = Array.isArray(options?.file) ? options.file : options?.file ? [options.file] : [];
511
- if (files.length > maxPerSelection) {
512
- // Angular wrapper luôn truyền _i18n; nếu thiếu thì warning sẽ là chuỗi rỗng (i18n service tự log missing key)
513
- const msg = option?._i18n?.t('core.component.editor.image.max-per-selection', { max: maxPerSelection }) ?? '';
514
- option?.onWarning?.(msg);
515
- evt.stop();
516
- }
281
+ const validation = new AbortController();
282
+ this.#validations.add(validation);
283
+ try {
284
+ await validateAndGetFile({ file }, config.validation, this.warning, this.i18n, validation.signal);
285
+ if (!this.#isCurrent(generation))
286
+ return;
287
+ const src = URL.createObjectURL(file);
288
+ this.#pending.set(src, file);
289
+ try {
290
+ this.engine.insertImage({ src, alt: file.name, loading: config.lazyLoad === false ? 'eager' : 'lazy' });
517
291
  }
518
- }, { priority: 'high' });
519
- }
520
- editor.once('ready', () => {
521
- const notification = editor.plugins.get('Notification');
522
- notification?.on('show:warning', (evt) => {
523
- evt.stop();
524
- }, { priority: 'highest' });
525
- });
526
- editor.plugins.get('FileRepository').createUploadAdapter = (loader) => {
527
- const option = getOption?.();
528
- const imageConfig = option?.imageConfig;
529
- const uploadMode = imageConfig?.uploadMode ?? 'deferred';
530
- const validation = imageConfig?.validation;
531
- const onWarning = option?.onWarning;
532
- const i18n = option?._i18n;
533
- const lazyLoad = imageConfig?.lazyLoad ?? true;
534
- if (uploadMode === 'deferred') {
535
- return new DeferredImageUploadAdapter(loader, this.pendingFiles, this.#imageMetaMap, { validation, onWarning, i18n, lazyLoad });
536
- }
537
- if (!this.#batchScheduler) {
538
- const uploadFn = option?.uploadFn;
539
- if (uploadFn) {
540
- const batchSize = imageConfig?.batchSize ?? 2;
541
- this.#batchScheduler = new BatchUploadScheduler(batchSize, uploadFn, this.uploadQueue);
292
+ catch (error) {
293
+ this.#release(src);
294
+ throw error;
542
295
  }
543
296
  }
544
- if (!this.#batchScheduler) {
545
- throw new Error('No upload function configured');
297
+ catch {
298
+ // Validation already reports a localized warning. An invalidated local decode is silent.
546
299
  }
547
- return new ImmediateImageUploadAdapter(loader, this.#batchScheduler, this.#imageMetaMap, { validation, onWarning, i18n, lazyLoad });
548
- };
549
- }
550
- destroy() {
551
- super.destroy();
552
- this.#batchScheduler?.destroy();
553
- for (const blobUrl of this.pendingFiles.keys()) {
554
- URL.revokeObjectURL(blobUrl);
555
- }
556
- this.pendingFiles.clear();
557
- this.#imageMetaMap.clear();
558
- }
559
- #registerSchemaAndConverters() {
560
- const editor = this.editor;
561
- const schema = editor.model.schema;
562
- for (const type of ['imageBlock', 'imageInline']) {
563
- if (schema.isRegistered(type)) {
564
- schema.extend(type, { allowAttributes: ['loading', 'imageId'] });
300
+ finally {
301
+ this.#validations.delete(validation);
565
302
  }
566
303
  }
567
- // Downcast: model → HTML view
568
- editor.conversion.for('downcast').add((dispatcher) => {
569
- for (const [modelAttr, htmlAttr] of [
570
- ['loading', 'loading'],
571
- ['imageId', 'id'],
572
- ]) {
573
- const handleAttribute = (isBlock) => (evt, data, conversionApi) => {
574
- if (!conversionApi.consumable.consume(data.item, evt.name))
575
- return;
576
- const viewElement = conversionApi.mapper.toViewElement(data.item);
577
- const viewImg = isBlock ? this.#findImg(viewElement) : viewElement;
578
- if (!viewImg)
579
- return;
580
- if (data.attributeNewValue != null) {
581
- conversionApi.writer.setAttribute(htmlAttr, String(data.attributeNewValue), viewImg);
582
- }
583
- else {
584
- conversionApi.writer.removeAttribute(htmlAttr, viewImg);
585
- }
586
- };
587
- dispatcher.on(`attribute:${modelAttr}:imageBlock`, handleAttribute(true));
588
- dispatcher.on(`attribute:${modelAttr}:imageInline`, handleAttribute(false));
304
+ if (this.#isCurrent(generation) && config.uploadMode === 'immediate')
305
+ this.#scheduleImmediate();
306
+ }
307
+ /** Snapshot only files still present; later insertions remain pending for a later deferred call. */
308
+ upload() {
309
+ if (this.#running) {
310
+ if (this.#runningGeneration === this.#generation)
311
+ return this.#running;
312
+ // An app callback remains in flight after invalidation. Await it to keep the
313
+ // concurrency bound, then submit the new generation's own snapshot.
314
+ return this.#running.catch(() => { }).then(() => this.upload());
315
+ }
316
+ const running = this.#uploadSnapshot();
317
+ this.#running = running;
318
+ this.#runningGeneration = this.#generation;
319
+ void running
320
+ .finally(() => {
321
+ if (this.#running !== running)
322
+ return;
323
+ this.#running = undefined;
324
+ if (this.#nextImmediate && !this.#destroyed) {
325
+ this.#nextImmediate = false;
326
+ this.#scheduleImmediate();
589
327
  }
590
- });
591
- // Upcast: HTML → model
592
- editor.conversion.for('upcast').add((dispatcher) => {
593
- dispatcher.on('element:figure', (_evt, data, conversionApi) => {
594
- if (!data.viewItem.hasClass('image'))
595
- return;
596
- const modelElement = data.modelRange?.start?.nodeAfter;
597
- if (!modelElement)
598
- return;
599
- const viewImg = this.#findImg(data.viewItem);
600
- if (!viewImg)
601
- return;
602
- this.#transferHtmlAttrsToModel(viewImg, modelElement, conversionApi);
603
- }, { priority: 'low' });
604
- dispatcher.on('element:img', (_evt, data, conversionApi) => {
605
- const modelElement = data.modelRange?.start?.nodeAfter;
606
- if (!modelElement)
607
- return;
608
- this.#transferHtmlAttrsToModel(data.viewItem, modelElement, conversionApi);
609
- }, { priority: 'low' });
610
- });
611
- }
612
- #listenForSrcChanges() {
613
- const editor = this.editor;
614
- editor.model.document.on('change', () => {
615
- const changes = editor.model.document.differ.getChanges();
616
- const updates = [];
617
- for (const change of changes) {
618
- if (change.type !== 'attribute' || change.attributeKey !== 'src')
619
- continue;
620
- const newSrc = change.attributeNewValue;
621
- const meta = this.#imageMetaMap.get(newSrc);
622
- if (!meta)
328
+ })
329
+ .catch(() => { });
330
+ return running;
331
+ }
332
+ async #uploadSnapshot() {
333
+ const config = this.configuration();
334
+ const uploadFn = config.uploadFn;
335
+ if (!uploadFn)
336
+ throw new Error('No upload function configured for image upload');
337
+ if (this.#destroyed)
338
+ return;
339
+ this.pruneRemoved();
340
+ const generation = this.#generation;
341
+ const entries = [...this.#pending.entries()];
342
+ const batchSize = positiveInteger(config.batchSize, 2);
343
+ const concurrency = positiveInteger(config.maxConcurrentUploads, 2);
344
+ const batches = [];
345
+ for (let i = 0; i < entries.length; i += batchSize)
346
+ batches.push(entries.slice(i, i + batchSize));
347
+ let head = 0;
348
+ let failures = 0;
349
+ const worker = async () => {
350
+ while (head < batches.length && this.#isCurrent(generation)) {
351
+ const batch = batches[head++].filter(([src, file]) => this.#pending.get(src) === file && this.engine.activeImageSources().has(src));
352
+ if (!batch.length)
623
353
  continue;
624
- const node = change.range?.start?.nodeAfter;
625
- if (node?.is('element')) {
626
- updates.push({ element: node, meta });
627
- this.#imageMetaMap.delete(newSrc);
628
- }
629
- }
630
- if (updates.length === 0)
631
- return;
632
- editor.model.enqueueChange('transparent', (writer) => {
633
- for (const { element, meta } of updates) {
634
- if (meta.name || meta.fileName) {
635
- writer.setAttribute('alt', meta.name || this.#generateAlt(meta.fileName), element);
636
- }
637
- if (meta.lazyLoad) {
638
- writer.setAttribute('loading', 'lazy', element);
639
- }
640
- if (meta.idOrKey) {
641
- writer.setAttribute('imageId', meta.idOrKey, element);
354
+ try {
355
+ const results = await uploadFn(batch.map(([, file]) => file));
356
+ if (!this.#isCurrent(generation))
357
+ return;
358
+ if (!Array.isArray(results) || results.length !== batch.length)
359
+ throw new Error('Image upload result cardinality does not match the submitted files');
360
+ // Validate the whole batch before applying any result; failed batches remain retryable.
361
+ const attributes = results.map((detail, i) => this.#resultAttributes(detail, batch[i][1], config));
362
+ for (const [index, [src, file]] of batch.entries()) {
363
+ if (!this.#isCurrent(generation))
364
+ return;
365
+ if (this.#pending.get(src) !== file)
366
+ continue;
367
+ if (!this.engine.activeImageSources().has(src)) {
368
+ this.#release(src);
369
+ continue;
370
+ }
371
+ let replaced = false;
372
+ try {
373
+ replaced = this.engine.replaceImage(src, attributes[index]);
374
+ }
375
+ catch {
376
+ /* Keep the active file retryable. */
377
+ }
378
+ if (replaced || !this.engine.activeImageSources().has(src))
379
+ this.#release(src);
380
+ else
381
+ failures++;
642
382
  }
643
383
  }
384
+ catch {
385
+ if (this.#isCurrent(generation))
386
+ failures += batch.filter(([src, file]) => this.#pending.get(src) === file && this.engine.activeImageSources().has(src)).length;
387
+ }
388
+ }
389
+ };
390
+ await Promise.all(Array.from({ length: Math.min(concurrency, batches.length) }, worker));
391
+ if (this.#isCurrent(generation)) {
392
+ this.pruneRemoved();
393
+ if (failures)
394
+ throw new Error(`Upload failed for ${failures} image(s)`);
395
+ }
396
+ }
397
+ #resultAttributes(detail, file, config) {
398
+ if (!detail ||
399
+ typeof detail.cdn !== 'string' ||
400
+ !detail.cdn.trim() ||
401
+ /^blob:/i.test(detail.cdn.trim()) ||
402
+ typeof detail.idOrKey !== 'string' ||
403
+ (detail.name !== undefined && typeof detail.name !== 'string'))
404
+ throw new Error('Invalid image upload metadata');
405
+ const image = document.implementation.createHTMLDocument().createElement('img');
406
+ image.setAttribute('src', detail.cdn);
407
+ if (sdSanitizeEditorHtml(image.outerHTML) !== image.outerHTML)
408
+ throw new Error('Unsafe image upload URL');
409
+ return { src: detail.cdn, id: detail.idOrKey, alt: detail.name ?? file.name, loading: config.lazyLoad === false ? 'eager' : 'lazy' };
410
+ }
411
+ #scheduleImmediate() {
412
+ if (this.#destroyed)
413
+ return;
414
+ if (this.#running) {
415
+ this.#nextImmediate = true;
416
+ return;
417
+ }
418
+ if (this.#immediateTimer !== undefined)
419
+ clearTimeout(this.#immediateTimer);
420
+ const ready = this.#pending.size >= positiveInteger(this.configuration().batchSize, 2);
421
+ this.#immediateTimer = setTimeout(() => {
422
+ this.#immediateTimer = undefined;
423
+ void this.upload().catch(() => {
424
+ if (!this.#destroyed)
425
+ this.warning(this.i18n?.t('core.component.editor.image.upload-failed') ?? '');
644
426
  });
645
- });
427
+ }, ready ? 0 : 50);
646
428
  }
647
- #findImg(viewElement) {
648
- if (!viewElement)
649
- return null;
650
- if (viewElement.is?.('element', 'img'))
651
- return viewElement;
652
- for (const child of viewElement.getChildren?.() ?? []) {
653
- if (child.is?.('element', 'img'))
654
- return child;
655
- }
656
- return null;
429
+ pruneRemoved() {
430
+ if (this.#destroyed)
431
+ return;
432
+ const active = this.engine.activeImageSources();
433
+ for (const src of this.#pending.keys())
434
+ if (!active.has(src))
435
+ this.#release(src);
436
+ }
437
+ invalidateWork() {
438
+ this.#generation++;
439
+ for (const validation of this.#validations)
440
+ validation.abort();
441
+ this.#validations.clear();
442
+ if (this.#immediateTimer !== undefined)
443
+ clearTimeout(this.#immediateTimer);
444
+ this.#immediateTimer = undefined;
445
+ this.#nextImmediate = false;
446
+ }
447
+ invalidateSource() {
448
+ this.invalidateWork();
449
+ for (const src of this.#pending.keys())
450
+ this.#release(src);
657
451
  }
658
- #transferHtmlAttrsToModel(viewImg, modelElement, conversionApi) {
659
- const schema = this.editor.model.schema;
660
- if (viewImg.hasAttribute('loading') && schema.checkAttribute(modelElement, 'loading')) {
661
- conversionApi.writer.setAttribute('loading', viewImg.getAttribute('loading'), modelElement);
662
- }
663
- if (viewImg.hasAttribute('id') && schema.checkAttribute(modelElement, 'imageId')) {
664
- conversionApi.writer.setAttribute('imageId', viewImg.getAttribute('id'), modelElement);
452
+ destroy() {
453
+ if (!this.#destroyed) {
454
+ this.invalidateSource();
455
+ this.#destroyed = true;
665
456
  }
666
457
  }
667
- #generateAlt(fileName) {
668
- if (!fileName)
669
- return 'Image';
670
- const nameWithoutExt = fileName.replace(/\.[^.]+$/, '');
671
- const result = nameWithoutExt
672
- .replace(/[-_.]+/g, ' ')
673
- .replace(/\s+/g, ' ')
674
- .trim();
675
- return result || 'Image';
458
+ #release(src) {
459
+ if (this.#pending.delete(src))
460
+ URL.revokeObjectURL(src);
461
+ }
462
+ #isCurrent(generation) {
463
+ return !this.#destroyed && generation === this.#generation;
676
464
  }
677
465
  }
678
466
 
679
467
  class SdEditor {
680
- // Injected
681
468
  #destroyRef = inject(DestroyRef);
682
469
  #cdRef = inject(ChangeDetectorRef);
683
470
  #uploadConfig = inject(SD_EDITOR_CONFIGURATION, { optional: true });
@@ -761,181 +548,186 @@ class SdEditor {
761
548
  return this.inlineError();
762
549
  return undefined;
763
550
  }
764
- Editor = ClassicEditor;
765
- #editor;
766
- #contentChangeSubject = new Subject();
767
- editorConfig = computed(() => {
768
- const opt = this.option();
769
- const uploadFn = this.#buildUploadFn();
770
- const enableImageUpload = !!uploadFn;
771
- const plugins = [Essentials, FontColor, FontSize, Paragraph, Bold, Italic, Underline, List, Undo, Widget, Alignment];
772
- if (enableImageUpload)
773
- plugins.push(EditorImageUploadPlugin);
774
- const toolbarItems = [
775
- 'bold',
776
- 'italic',
777
- 'underline',
778
- '|',
779
- 'fontSize',
780
- 'fontColor',
781
- '|',
782
- 'alignment:left',
783
- 'alignment:center',
784
- 'alignment:right',
785
- 'alignment:justify',
786
- '|',
787
- 'bulletedList',
788
- 'numberedList',
789
- ];
790
- if (enableImageUpload)
791
- toolbarItems.push('|', 'uploadImage');
792
- const config = {
793
- licenseKey: 'GPL',
794
- getOption: () => ({
795
- ...opt,
796
- uploadFn,
797
- onWarning: (msg) => this.#notifyService.warning(msg),
798
- // Truyền i18n service xuống CKEditor plugin (ngoài DI tree) để dịch warning messages
799
- _i18n: this.#i18n,
800
- }),
801
- plugins,
802
- toolbar: { items: toolbarItems, shouldNotGroupWhenFull: true },
803
- placeholder: this.placeholder(),
804
- fontColor: { columns: 5, documentColors: 10, colorPicker: { format: 'hex' } },
805
- fontSize: { options: [10, 11, 12, 14, 16, 18, 20], supportAllValues: true },
806
- };
807
- if (enableImageUpload) {
808
- config.image = {
809
- resizeUnit: '%',
810
- resizeOptions: [
811
- { name: 'resizeImage:100', value: '100', label: '100%' },
812
- { name: 'resizeImage:75', value: '75', label: '75%' },
813
- { name: 'resizeImage:50', value: '50', label: '50%' },
814
- { name: 'resizeImage:25', value: '25', label: '25%' },
815
- { name: 'resizeImage:original', value: null, label: 'Original' },
816
- ],
817
- toolbar: ['resizeImage', '|', 'imageStyle:alignBlockLeft', 'imageStyle:alignCenter', 'imageStyle:alignBlockRight'],
818
- };
819
- }
820
- return config;
821
- }, /* @ts-ignore */
822
- ...(ngDevMode ? [{ debugName: "editorConfig" }] : /* istanbul ignore next */ []));
551
+ sdImportWarning = output();
552
+ #diagnostics = signal([], /* @ts-ignore */
553
+ ...(ngDevMode ? [{ debugName: "#diagnostics" }] : /* istanbul ignore next */ []));
554
+ importDiagnostics = this.#diagnostics.asReadonly();
555
+ surfaceContent = signal('', /* @ts-ignore */
556
+ ...(ngDevMode ? [{ debugName: "surfaceContent" }] : /* istanbul ignore next */ []));
557
+ uploadEnabled = computed(() => !!this.#buildUploadFn(), /* @ts-ignore */
558
+ ...(ngDevMode ? [{ debugName: "uploadEnabled" }] : /* istanbul ignore next */ []));
559
+ descriptionId = computed(() => `sd-editor-description-${Utilities.generateUuid()}`, /* @ts-ignore */
560
+ ...(ngDevMode ? [{ debugName: "descriptionId" }] : /* istanbul ignore next */ []));
561
+ #engine;
562
+ #uploads;
563
+ #timer;
564
+ #pending;
565
+ #deadline;
566
+ #composing = false;
567
+ #destroyed = false;
823
568
  constructor() {
824
569
  this.#validateDuplicateConfigKeys();
825
- this.#setupEffects();
826
- this.#setupSubscriptions();
827
- this.#setupDestroy();
828
- }
829
- onReady = (editor) => {
830
- this.#editor = editor;
831
- const currentValue = this.valueModel();
832
- if (currentValue) {
833
- this.#setToEditor(currentValue);
834
- }
835
- if (this.formControl.disabled) {
836
- editor.enableReadOnlyMode('sd-editor');
837
- }
838
- if (this.readonly()) {
839
- editor.enableReadOnlyMode('sd-editor-readonly');
840
- }
841
- editor.model.document.registerPostFixer(writer => {
842
- let changed = false;
843
- for (const change of editor.model.document.differ.getChanges()) {
844
- if (change.type === 'insert' && (change.name === 'imageBlock' || change.name === 'imageInline')) {
845
- const element = change.position.nodeAfter;
846
- if (element && !element.hasAttribute('resizedWidth')) {
847
- writer.setAttribute('resizedWidth', '100%', element);
848
- changed = true;
849
- }
850
- }
851
- }
852
- return changed;
570
+ effect(() => {
571
+ const disabled = this.disabled();
572
+ if (disabled)
573
+ this.formControl.disable({ emitEvent: false });
574
+ else
575
+ this.formControl.enable({ emitEvent: false });
576
+ if (disabled)
577
+ this.#cancelWork();
578
+ });
579
+ effect(() => {
580
+ if (this.readonly())
581
+ this.#cancelWork();
853
582
  });
854
- editor.model.document.on('change:data', () => this.#contentChangeSubject.next(editor.getData()));
855
- editor.editing.view.document.on('focus', evt => this.sdFocus.emit(evt.domEvent));
856
- editor.editing.view.document.on('blur', evt => {
857
- this.sdBlur.emit(evt.domEvent);
858
- this.formControl.markAsTouched();
583
+ effect(() => this.#setExternalContent(this.valueModel() ?? ''));
584
+ effect(() => {
585
+ this.required();
586
+ this.maxlength();
587
+ this.inlineError();
588
+ this.validator();
589
+ this.#updateValidators();
590
+ });
591
+ this.formControl.valueChanges.pipe(takeUntilDestroyed(this.#destroyRef)).subscribe((value) => {
592
+ const normalized = value ?? '';
593
+ this.#setExternalContent(normalized);
594
+ this.valueModel.set(normalized);
595
+ });
596
+ this.formControl.statusChanges.pipe(takeUntilDestroyed(this.#destroyRef)).subscribe(() => {
597
+ if (this.formControl.disabled)
598
+ this.#cancelWork();
859
599
  this.#cdRef.markForCheck();
860
600
  });
861
- };
862
- focusEditor = () => this.#editor?.editing?.view?.focus?.();
863
- /**
864
- * Xử lý tải lên các file và trả về nội dung dữ liệu cuối cùng.
865
- * * @description
866
- * - Đối với các file upload chế độ 'deferred' (chỉ xử lý khi submit), cần @ViewChild component và gọi hàm upload() này.
867
- * - Hỗ trợ two-way binding.
868
- * - Hàm hỗ trợ trả ra data cuối cùng.
869
- * * @returns {Promise<string>} Nội dung cuối cùng được trích xuất từ sd-editor.
870
- */
871
- upload = async () => {
872
- await this.#uploadImages();
873
- return this.#getFromEditor();
874
- };
875
- // Editor Content
876
- #setToEditor(html) {
877
- this.#editor?.setData?.(this.#normalizeHtmlForEditor(html));
601
+ this.formControl.sdChanges.pipe(takeUntilDestroyed(this.#destroyRef)).subscribe(() => this.#cdRef.markForCheck());
602
+ this.#destroyRef.onDestroy(() => {
603
+ this.#destroyed = true;
604
+ this.#cancelCadence();
605
+ this.#uploads?.destroy();
606
+ this.#engine = undefined; // Surface owns engine destruction exactly once.
607
+ });
878
608
  }
879
- #getFromEditor() {
880
- // why: `upload()` trả HTML cuối cùng cho consumer lưu — cùng bộ lọc với luồng soạn thảo (D-032).
881
- return this.#editor ? sdSanitizeEditorHtml(this.#normalizeEditorToHtml(this.#editor.getData())) : '';
609
+ onEngineReady(engine) {
610
+ this.#cancelCadence();
611
+ this.#composing = false;
612
+ this.#uploads?.destroy();
613
+ this.#engine = engine;
614
+ this.#uploads = new SdEditorUploadManager(engine, () => ({ ...this.option().imageConfig, uploadFn: this.#buildUploadFn() }), message => this.#notifyService.warning(message), this.#i18n);
615
+ }
616
+ onSourceChange() {
617
+ this.#cancelCadence();
618
+ if (this.formControl.disabled || this.readonly())
619
+ this.#uploads?.invalidateWork();
620
+ else
621
+ this.#uploads?.invalidateSource();
622
+ }
623
+ onSurfaceChange(value) {
624
+ if (this.#destroyed || this.formControl.disabled || this.readonly())
625
+ return;
626
+ this.#uploads?.pruneRemoved();
627
+ this.#clearTimer();
628
+ this.#pending = value;
629
+ // Composition pauses an existing deadline; its final document replaces only
630
+ // the pending value. An ordinary edit starts a new 100ms debounce deadline.
631
+ if (!this.#composing || this.#deadline === undefined)
632
+ this.#deadline = Date.now() + 100;
633
+ if (!this.#composing)
634
+ this.#schedulePending();
635
+ }
636
+ onCompositionChange(composing) {
637
+ this.#composing = composing;
638
+ this.#clearTimer();
639
+ if (!composing)
640
+ this.#schedulePending();
641
+ }
642
+ #schedulePending() {
643
+ if (this.#pending === undefined || this.#deadline === undefined || this.#composing || this.#destroyed)
644
+ return;
645
+ this.#timer = setTimeout(() => {
646
+ this.#timer = undefined;
647
+ const value = this.#pending;
648
+ this.#pending = undefined;
649
+ this.#deadline = undefined;
650
+ if (value !== undefined && !this.#destroyed && !this.#composing && !this.formControl.disabled && !this.readonly())
651
+ this.#onEditorUserInput(value);
652
+ }, Math.max(0, this.#deadline - Date.now()));
653
+ }
654
+ onSurfaceFocus(event) {
655
+ this.sdFocus.emit(event);
656
+ }
657
+ onSurfaceBlur(event) {
658
+ this.sdBlur.emit(event);
659
+ this.formControl.markAsTouched();
660
+ this.#cdRef.markForCheck();
661
+ }
662
+ onDiagnostics(diagnostics) {
663
+ this.#diagnostics.set(diagnostics);
664
+ this.sdImportWarning.emit(diagnostics);
665
+ }
666
+ async onFilesSelected(files) {
667
+ if (this.formControl.disabled || this.readonly())
668
+ return;
669
+ await this.#uploads?.selectFiles(files);
882
670
  }
883
- // Normalize HTML từ bên ngoài -> format CKEditor.
884
- #normalizeHtmlForEditor = (html) => {
885
- if (!html) {
886
- return '';
887
- }
888
- let result = html;
889
- result = imageInlineStylesToClasses(result);
890
- return result;
671
+ focusEditor = () => {
672
+ if (!this.formControl.disabled)
673
+ this.#engine?.focus();
891
674
  };
892
- // Normalize HTML từ CKEditor → format HTML.
893
- #normalizeEditorToHtml = (html) => {
894
- if (!html) {
895
- return '';
675
+ upload = async () => {
676
+ if ((this.option().imageConfig?.uploadMode ?? 'deferred') === 'deferred') {
677
+ if (!this.#buildUploadFn())
678
+ throw new Error('No upload function configured for image upload');
679
+ await this.#uploads?.upload();
896
680
  }
897
- let result = html;
898
- result = imageClassesToInlineStyles(result);
899
- return result;
681
+ return this.#engine?.getHtml() ?? '';
900
682
  };
901
- // Xử lý binding 2 chiều
902
- #onModelSignalChange(html) {
903
- const v = html ?? '';
904
- if (this.formControl.value === v) {
683
+ #clearTimer() {
684
+ if (this.#timer !== undefined)
685
+ clearTimeout(this.#timer);
686
+ this.#timer = undefined;
687
+ }
688
+ #cancelCadence() {
689
+ this.#clearTimer();
690
+ this.#pending = undefined;
691
+ this.#deadline = undefined;
692
+ }
693
+ #cancelWork() {
694
+ this.#cancelCadence();
695
+ this.#uploads?.invalidateWork();
696
+ }
697
+ #setExternalContent(value) {
698
+ if (this.formControl.value !== value)
699
+ this.formControl.setValue(value, { emitEvent: false });
700
+ this._textLength.set(countTextLength(value));
701
+ this.formControl.updateValueAndValidity({ emitEvent: false });
702
+ if (this.#isCurrentContent(value))
905
703
  return;
704
+ this.#cancelCadence();
705
+ this.#uploads?.invalidateSource();
706
+ this.surfaceContent.set(value);
707
+ this.#engine?.setContent(value);
708
+ }
709
+ #isCurrentContent(value) {
710
+ if (!this.#engine)
711
+ return value === this.surfaceContent();
712
+ try {
713
+ return value === this.#engine.getContent();
906
714
  }
907
- this.formControl.setValue(v, { emitEvent: false });
908
- this._textLength.set(countTextLength(v));
909
- if (this.#editor) {
910
- this.#setToEditor(v);
715
+ catch {
716
+ return false;
911
717
  }
912
718
  }
913
- // Xử lý khi user soạn thảo
914
719
  #onEditorUserInput(rawHtml) {
915
- const normalized = imageClassesToInlineStyles(rawHtml);
916
- // why: HTML này đi thẳng vào form value, model và `sdChange`. Nội dung nạp từ ngoài (hoặc dán vào) có
917
- // thể mang `javascript:`, `on*`, `data:text/html` — lọc theo allowlist (D-032) trước khi phát ra.
918
- const out = sdSanitizeEditorHtml(normalized);
919
- this._textLength.set(countTextLength(out));
920
- if (this.formControl.value !== out) {
921
- this.formControl.setValue(out, { emitEvent: false });
922
- // why: bộ lọc đã sửa nội dung so với dữ liệu nạp vào — đánh dấu dirty để consumer biết cần lưu lại.
923
- if (out !== normalized)
720
+ const value = sdSanitizeEditorHtml(rawHtml);
721
+ this._textLength.set(countTextLength(value));
722
+ if (this.formControl.value !== value) {
723
+ this.formControl.setValue(value, { emitEvent: false });
724
+ if (value !== rawHtml)
924
725
  this.formControl.markAsDirty();
925
726
  }
926
727
  this.formControl.updateValueAndValidity({ emitEvent: false });
927
728
  this.formControl.sdChanges.next(true);
928
- this.valueModel.set(out);
929
- this.sdChange.emit(out);
930
- }
931
- // Xử lý nếu dev sử dụng form và set trực tiếp data
932
- #onFormGroupExternalChange(html) {
933
- const v = html ?? '';
934
- this.valueModel.set(v);
935
- this._textLength.set(countTextLength(v));
936
- if (this.#editor) {
937
- this.#setToEditor(v);
938
- }
729
+ this.valueModel.set(value);
730
+ this.sdChange.emit(value);
939
731
  }
940
732
  // Validators
941
733
  #requiredValidator() {
@@ -971,94 +763,6 @@ class SdEditor {
971
763
  this.formControl.setAsyncValidators(asyncValidators.length ? asyncValidators : null);
972
764
  this.formControl.updateValueAndValidity({ emitEvent: false });
973
765
  }
974
- // Setup
975
- #setupEffects() {
976
- // Lắng nghe disabled
977
- effect(() => {
978
- if (this.disabled()) {
979
- this.formControl.disable({ emitEvent: false });
980
- }
981
- else {
982
- this.formControl.enable({ emitEvent: false });
983
- }
984
- });
985
- // Lắng nghe readonly
986
- effect(() => {
987
- if (!this.#editor) {
988
- return;
989
- }
990
- if (this.readonly()) {
991
- this.#editor.enableReadOnlyMode('sd-editor-readonly');
992
- }
993
- else {
994
- this.#editor.disableReadOnlyMode('sd-editor-readonly');
995
- }
996
- });
997
- // Lắng nghe binđing 2 chiều model
998
- effect(() => this.#onModelSignalChange(this.valueModel()));
999
- // Lắng nghe validators
1000
- effect(() => {
1001
- this.required();
1002
- this.maxlength();
1003
- this.inlineError();
1004
- this.validator();
1005
- this.#updateValidators();
1006
- });
1007
- }
1008
- #setupSubscriptions() {
1009
- // Đăng ký nếu dev sử dụng form để set data trực tiếp từ bên ngoài vào
1010
- this.formControl.valueChanges
1011
- .pipe(takeUntilDestroyed(this.#destroyRef))
1012
- .subscribe((val) => this.#onFormGroupExternalChange(val));
1013
- this.formControl.sdChanges.pipe(takeUntilDestroyed(this.#destroyRef)).subscribe(() => this.#cdRef.markForCheck());
1014
- // Đăng ký user gõ trong editor
1015
- this.#contentChangeSubject
1016
- .pipe(debounceTime(100), takeUntilDestroyed(this.#destroyRef))
1017
- .subscribe(rawHtml => this.#onEditorUserInput(rawHtml));
1018
- }
1019
- #setupDestroy() {
1020
- this.#destroyRef.onDestroy(() => {
1021
- this.#editor?.destroy?.();
1022
- });
1023
- }
1024
- // Helpers
1025
- #uploadImages = async () => {
1026
- const uploadMode = this.option()?.imageConfig?.uploadMode ?? 'deferred';
1027
- // Early return nếu không phải 'deferred' mode.
1028
- // Nếu trước đó là mode "deferred" mà mong muốn chuyển sang mode "immediate", dev chưa cần refactor code phía caller mà không ảnh hưởng đến logic.
1029
- if (uploadMode !== 'deferred')
1030
- return;
1031
- const uploadFn = this.#buildUploadFn();
1032
- if (!uploadFn) {
1033
- throw new Error('No upload function configured for image upload');
1034
- }
1035
- const plugin = this.#editor?.plugins?.get(EditorImageUploadPlugin);
1036
- if (!plugin || plugin.pendingFiles.size === 0)
1037
- return;
1038
- const { batchSize, maxConcurrent } = getBatchConfig(this.option());
1039
- const activeBlobUrls = this.#editor ? getActiveBlobUrls(this.#editor) : new Set();
1040
- const toUpload = filterActivePendingFiles(plugin.pendingFiles, activeBlobUrls);
1041
- // Capture trước await để tránh race condition: ảnh được chèn trong lúc chờ API
1042
- const processedBlobUrls = new Set(toUpload.map(([blobUrl]) => blobUrl));
1043
- const { replacements, failedBatches } = await runBatchUploads(toUpload, uploadFn, batchSize, maxConcurrent);
1044
- if (this.#editor) {
1045
- const lazyLoad = this.option()?.imageConfig?.lazyLoad ?? true;
1046
- for (const detail of replacements.values()) {
1047
- plugin.setMeta(detail.cdn, { name: detail.name, idOrKey: detail.idOrKey, lazyLoad });
1048
- }
1049
- applyReplacementsToEditor(this.#editor, replacements);
1050
- }
1051
- // Chỉ xóa đúng các entries đã được xử lý
1052
- for (const blobUrl of processedBlobUrls) {
1053
- plugin.pendingFiles.delete(blobUrl);
1054
- }
1055
- for (const [blobUrl, file] of failedBatches.flat()) {
1056
- plugin.pendingFiles.set(blobUrl, file);
1057
- }
1058
- if (failedBatches.length > 0) {
1059
- throw new Error(`Upload failed for ${failedBatches.flat().length} image(s)`);
1060
- }
1061
- };
1062
766
  #getConfigurations = () => {
1063
767
  const config = this.#uploadConfig;
1064
768
  if (!config) {
@@ -1093,12 +797,12 @@ class SdEditor {
1093
797
  return this.option()?.imageConfig?.uploadFn ?? this.#getSelectedConfig()?.upload;
1094
798
  };
1095
799
  static ɵfac = i0.ɵɵngDeclareFactory({ minVersion: "12.0.0", version: "22.1.5", ngImport: i0, type: SdEditor, deps: [], target: i0.ɵɵFactoryTarget.Component });
1096
- static ɵcmp = i0.ɵɵngDeclareComponent({ minVersion: "17.0.0", version: "22.1.5", type: SdEditor, isStandalone: true, selector: "sd-editor", inputs: { option: { classPropertyName: "option", publicName: "option", isSignal: true, isRequired: false, transformFunction: null }, height: { classPropertyName: "height", publicName: "height", isSignal: true, isRequired: false, transformFunction: null }, maxHeight: { classPropertyName: "maxHeight", publicName: "maxHeight", isSignal: true, isRequired: false, transformFunction: null }, maxlength: { classPropertyName: "maxlength", publicName: "maxlength", isSignal: true, isRequired: false, transformFunction: null }, label: { classPropertyName: "label", publicName: "label", isSignal: true, isRequired: false, transformFunction: null }, helperText: { classPropertyName: "helperText", publicName: "helperText", isSignal: true, isRequired: false, transformFunction: null }, required: { classPropertyName: "required", publicName: "required", isSignal: true, isRequired: false, transformFunction: null }, disabled: { classPropertyName: "disabled", publicName: "disabled", isSignal: true, isRequired: false, transformFunction: null }, readonly: { classPropertyName: "readonly", publicName: "readonly", isSignal: true, isRequired: false, transformFunction: null }, hideInlineError: { classPropertyName: "hideInlineError", publicName: "hideInlineError", isSignal: true, isRequired: false, transformFunction: null }, inlineError: { classPropertyName: "inlineError", publicName: "inlineError", isSignal: true, isRequired: false, transformFunction: null }, placeholder: { classPropertyName: "placeholder", publicName: "placeholder", isSignal: true, isRequired: false, transformFunction: null }, validator: { classPropertyName: "validator", publicName: "validator", isSignal: true, isRequired: false, transformFunction: null }, form: { classPropertyName: "form", publicName: "form", isSignal: true, isRequired: false, transformFunction: null }, key: { classPropertyName: "key", publicName: "key", isSignal: true, isRequired: false, transformFunction: null }, autoIdInput: { classPropertyName: "autoIdInput", publicName: "autoId", isSignal: true, isRequired: false, transformFunction: null }, name: { classPropertyName: "name", publicName: "name", isSignal: true, isRequired: false, transformFunction: null }, valueModel: { classPropertyName: "valueModel", publicName: "model", isSignal: true, isRequired: false, transformFunction: null } }, outputs: { valueModel: "modelChange", sdChange: "sdChange", sdBlur: "sdBlur", sdFocus: "sdFocus" }, ngImport: i0, template: "<sd-ckeditor-styles />\n@let _label = label();\n@let _helperText = helperText();\n@let _hideInlineError = hideInlineError();\n@let _errorMessage = errorMessage;\n@let _required = required();\n@let _maxLength = maxlength();\n@let _showCounter = !!_maxLength && !formControl.disabled && !_hideInlineError;\n\n@if (_label) {\n <sd-label [label]=\"_label\" [required]=\"_required\" [helperText]=\"_helperText\"></sd-label>\n}\n\n<div\n class=\"sd-editor\"\n [class.sd-editor--readonly]=\"readonly()\"\n [class.sd-editor--error]=\"formControl.invalid && formControl.touched\"\n [class.has-counter]=\"_showCounter\"\n [style.--sd-editor-content-min-height]=\"height()\"\n [style.--sd-editor-content-max-height]=\"maxHeight()\"\n [attr.data-autoId]=\"autoId()\"\n [attr.data-disabled]=\"dataDisabled()\"\n [attr.data-empty]=\"dataEmpty()\">\n <ckeditor [editor]=\"Editor\" [config]=\"editorConfig()\" [disabled]=\"formControl.disabled\" (ready)=\"onReady($event)\"></ckeditor>\n\n @if (_showCounter) {\n <div class=\"sd-editor-counter-row\">\n <span class=\"sd-editor-counter\" [class.sd-editor-counter--over]=\"isOverLimit()\"> {{ _textLength() }}/{{ _maxLength }} </span>\n </div>\n }\n\n @if (_hideInlineError && _errorMessage && formControl.touched) {\n <sd-icon class=\"sd-error-icon\" [matTooltip]=\"_errorMessage\" matTooltipPosition=\"above\" name=\"error\"></sd-icon>\n }\n @if (_hideInlineError && _errorMessage && formControl.touched) {\n <span class=\"sd-visually-hidden\">{{ _errorMessage }}</span>\n\n }\n</div>\n\n<div class=\"sd-editor-footer\">\n @if (!_hideInlineError && _errorMessage && formControl.touched) {\n <mat-error>{{ _errorMessage }}</mat-error>\n }\n</div>\n", styles: [".sd-editor{display:flex;flex-direction:column;width:100%;position:relative}.sd-editor-counter-row{display:flex;justify-content:flex-end;align-items:center;padding:4px 12px;border:1px solid var(--ck-color-base-border);border-top:none}.sd-editor-footer{min-height:20px;margin-top:4px}.sd-editor-footer mat-error{font-size:var(--sd-font-size-12, 12px);color:var(--mdc-theme-error, #f44336)}.sd-error-icon{position:absolute;right:8px;bottom:8px;z-index:2;color:var(--mdc-theme-error, #f44336);height:20px;width:20px;font-size:var(--sd-font-size-20, 20px);cursor:default}.sd-editor--readonly :host ::ng-deep .ck-editor__editable{background:#0000000a;cursor:default}.sd-editor-counter{font-size:var(--sd-font-size-12, 12px);color:#0009}.sd-editor-counter--over{color:var(--mdc-theme-error, #f44336)}::ng-deep .ck-powered-by,::ng-deep .ck-powered-by-balloon{display:none!important}:host ::ng-deep ckeditor,:host ::ng-deep .ck-editor{display:flex;flex-direction:column}:host ::ng-deep .ck-editor{--ck-content-font-size: 14px;--ck-content-line-height: 1.5}:host ::ng-deep .ck-editor__main{overflow:visible}:host ::ng-deep .ck-editor__editable{min-height:var(--sd-editor-content-min-height, 200px)!important;max-height:var(--sd-editor-content-max-height, none)!important;padding:24px!important;overflow-y:auto!important;border:1px solid var(--ck-color-base-border)!important}:host ::ng-deep .ck-editor__editable.ck-focused{box-shadow:none!important}:host ::ng-deep .sd-editor.has-counter .ck-editor__editable{border-bottom:none!important}:host ::ng-deep .sd-editor--error .ck-editor__editable,:host ::ng-deep .sd-editor--error .ck-toolbar{border-color:var(--mdc-theme-error, #f44336)!important}:host ::ng-deep .sd-editor--error.has-counter .sd-editor-counter-row{border-color:var(--mdc-theme-error, #f44336)}:host ::ng-deep .ck-content p{margin-bottom:var(--ck-spacing-large);text-indent:0}:host ::ng-deep .ck-content ul,:host ::ng-deep .ck-content ol{margin-left:0!important;padding-left:20px!important}\n", ":host ::ng-deep .ck-content img{max-width:100%!important;height:auto!important;object-fit:contain}:host ::ng-deep .ck-content figure.image{position:relative;display:block;width:fit-content;max-width:100%;margin:0 auto;overflow:visible}:host ::ng-deep .ck-content figure.image:hover{z-index:99999!important}:host ::ng-deep .ck-content figure.image.image-style-align-left{float:left;margin:0 1em 0 0}:host ::ng-deep .ck-content figure.image.image-style-align-left[style*=\"width:100\"]{float:none;margin:0 auto 0 0}:host ::ng-deep .ck-content figure.image.image-style-align-right{float:right;margin:0 0 0 1em}:host ::ng-deep .ck-content figure.image.image-style-align-right[style*=\"width:100\"]{float:none;margin:0 0 0 auto}:host ::ng-deep .ck-content figure.image.image-style-block-align-left{margin:0 auto 0 0}:host ::ng-deep .ck-content figure.image.image-style-block-align-right{margin:0 0 0 auto}:host ::ng-deep .ck-content figure.image .ck-progress-bar{position:absolute;bottom:0;left:0;width:30%!important;height:3px;background:var(--sd-primary, #005cbb);border-radius:var(--sd-radius-2, 2px);z-index:10;pointer-events:none;animation:sd-progress-indeterminate 1.4s ease-in-out infinite}:host ::ng-deep .ck-content figure.image:has(.ck-progress-bar){overflow:hidden}:host ::ng-deep .ck-content figure.image:has(.ck-progress-bar) img{filter:blur(1px) brightness(.85);transition:filter var(--sd-duration-slow, .3s) ease}:host ::ng-deep .ck-content figure.image:has(.ck-progress-bar):after{content:\"\";position:absolute;inset:0;display:flex;align-items:center;justify-content:center;z-index:9;background:#ffffff40;border-radius:inherit}:host ::ng-deep .ck-content figure.image:has(.ck-progress-bar):before{content:\"\";position:absolute;top:50%;left:50%;width:28px;height:28px;margin:-14px 0 0 -14px;border:3px solid rgba(255,255,255,.5);border-top-color:var(--sd-primary, #005cbb);border-radius:50%;animation:sd-spinner .75s linear infinite;z-index:11;pointer-events:none}@keyframes sd-spinner{to{transform:rotate(360deg)}}@keyframes sd-progress-indeterminate{0%{left:-30%}to{left:100%}}\n"], dependencies: [{ kind: "component", type: SdIcon, selector: "sd-icon", inputs: ["name", "fontIcon", "color", "set", "fontSet", "size", "strokeWidth", "absoluteStrokeWidth", "ariaLabel"] }, { kind: "ngmodule", type: CKEditorModule }, { kind: "component", type: i1.CKEditorComponent, selector: "ckeditor", inputs: ["editor", "config", "data", "tagName", "watchdog", "editorWatchdogConfig", "disableWatchdog", "disableTwoWayDataBinding", "disabled"], outputs: ["ready", "change", "blur", "focus", "error"] }, { kind: "component", type: SdLabel, selector: "sd-label", inputs: ["label", "description", "required", "helperText", "for", "labelId"] }, { kind: "component", type: SdCKEditorStyles, selector: "sd-ckeditor-styles" }, { kind: "ngmodule", type: MatFormFieldModule }, { kind: "directive", type: i2.MatError, selector: "mat-error, [matError]", inputs: ["id"] }, { kind: "ngmodule", type: MatTooltipModule }, { kind: "directive", type: i3.MatTooltip, selector: "[matTooltip]", inputs: ["matTooltipPosition", "matTooltipPositionAtOrigin", "matTooltipDisabled", "matTooltipShowDelay", "matTooltipHideDelay", "matTooltipTouchGestures", "matTooltip", "matTooltipClass"], exportAs: ["matTooltip"] }], changeDetection: i0.ChangeDetectionStrategy.OnPush });
800
+ static ɵcmp = i0.ɵɵngDeclareComponent({ minVersion: "17.0.0", version: "22.1.5", type: SdEditor, isStandalone: true, selector: "sd-editor", inputs: { option: { classPropertyName: "option", publicName: "option", isSignal: true, isRequired: false, transformFunction: null }, height: { classPropertyName: "height", publicName: "height", isSignal: true, isRequired: false, transformFunction: null }, maxHeight: { classPropertyName: "maxHeight", publicName: "maxHeight", isSignal: true, isRequired: false, transformFunction: null }, maxlength: { classPropertyName: "maxlength", publicName: "maxlength", isSignal: true, isRequired: false, transformFunction: null }, label: { classPropertyName: "label", publicName: "label", isSignal: true, isRequired: false, transformFunction: null }, helperText: { classPropertyName: "helperText", publicName: "helperText", isSignal: true, isRequired: false, transformFunction: null }, required: { classPropertyName: "required", publicName: "required", isSignal: true, isRequired: false, transformFunction: null }, disabled: { classPropertyName: "disabled", publicName: "disabled", isSignal: true, isRequired: false, transformFunction: null }, readonly: { classPropertyName: "readonly", publicName: "readonly", isSignal: true, isRequired: false, transformFunction: null }, hideInlineError: { classPropertyName: "hideInlineError", publicName: "hideInlineError", isSignal: true, isRequired: false, transformFunction: null }, inlineError: { classPropertyName: "inlineError", publicName: "inlineError", isSignal: true, isRequired: false, transformFunction: null }, placeholder: { classPropertyName: "placeholder", publicName: "placeholder", isSignal: true, isRequired: false, transformFunction: null }, validator: { classPropertyName: "validator", publicName: "validator", isSignal: true, isRequired: false, transformFunction: null }, form: { classPropertyName: "form", publicName: "form", isSignal: true, isRequired: false, transformFunction: null }, key: { classPropertyName: "key", publicName: "key", isSignal: true, isRequired: false, transformFunction: null }, autoIdInput: { classPropertyName: "autoIdInput", publicName: "autoId", isSignal: true, isRequired: false, transformFunction: null }, name: { classPropertyName: "name", publicName: "name", isSignal: true, isRequired: false, transformFunction: null }, valueModel: { classPropertyName: "valueModel", publicName: "model", isSignal: true, isRequired: false, transformFunction: null } }, outputs: { valueModel: "modelChange", sdChange: "sdChange", sdBlur: "sdBlur", sdFocus: "sdFocus", sdImportWarning: "sdImportWarning" }, ngImport: i0, template: "@let _label = label();\n@let _helperText = helperText();\n@let _hideInlineError = hideInlineError();\n@let _errorMessage = errorMessage;\n@let _required = required();\n@let _maxLength = maxlength();\n@let _showCounter = !!_maxLength && !formControl.disabled && !_hideInlineError;\n\n@if (_label) {\n <sd-label [label]=\"_label\" [required]=\"_required\" [helperText]=\"_helperText\"></sd-label>\n}\n\n<div\n class=\"sd-editor\"\n [class.sd-editor--readonly]=\"readonly()\"\n [class.sd-editor--error]=\"formControl.invalid && formControl.touched\"\n [class.has-counter]=\"_showCounter\"\n [style.--sd-editor-content-min-height]=\"height()\"\n [style.--sd-editor-content-max-height]=\"maxHeight()\"\n [attr.data-autoId]=\"autoId()\"\n [attr.data-disabled]=\"dataDisabled()\"\n [attr.data-empty]=\"dataEmpty()\">\n <sd-editor-surface\n variant=\"full\"\n [content]=\"surfaceContent()\"\n [editable]=\"!formControl.disabled && !readonly()\"\n [disabled]=\"formControl.disabled\"\n [readonly]=\"readonly()\"\n [placeholder]=\"placeholder()\"\n [height]=\"height()\"\n [maxHeight]=\"maxHeight()\"\n [uploadEnabled]=\"uploadEnabled()\"\n [label]=\"label()\"\n [describedBy]=\"helperText() || (_errorMessage && formControl.touched) ? descriptionId() : undefined\"\n [invalid]=\"formControl.invalid && formControl.touched\"\n (engineReady)=\"onEngineReady($event)\"\n (sourceChange)=\"onSourceChange()\"\n (change)=\"onSurfaceChange($event)\"\n (compositionChange)=\"onCompositionChange($event)\"\n (focus)=\"onSurfaceFocus($event)\"\n (blur)=\"onSurfaceBlur($event)\"\n (diagnostics)=\"onDiagnostics($event)\"\n (filesSelected)=\"onFilesSelected($event)\" />\n\n @if (_showCounter) {\n <div class=\"sd-editor-counter-row\">\n <span class=\"sd-editor-counter\" [class.sd-editor-counter--over]=\"isOverLimit()\"> {{ _textLength() }}/{{ _maxLength }} </span>\n </div>\n }\n\n @if (_hideInlineError && _errorMessage && formControl.touched) {\n <sd-icon class=\"sd-error-icon\" [matTooltip]=\"_errorMessage\" matTooltipPosition=\"above\" name=\"error\"></sd-icon>\n }\n @if (_hideInlineError && _errorMessage && formControl.touched) {\n <span class=\"sd-visually-hidden\">{{ _errorMessage }}</span>\n }\n</div>\n\n<div class=\"sd-editor-footer\">\n @if (!_hideInlineError && _errorMessage && formControl.touched) {\n <mat-error>{{ _errorMessage }}</mat-error>\n }\n</div>\n\n@if (_helperText || (_errorMessage && formControl.touched)) {\n <span class=\"sd-visually-hidden\" [id]=\"descriptionId()\">{{ _helperText }} {{ formControl.touched ? _errorMessage : '' }}</span>\n}\n", styles: [".sd-editor{display:flex;flex-direction:column;width:100%;position:relative}.sd-editor-counter-row{display:flex;justify-content:flex-end;padding:4px 12px;border:1px solid var(--sd-border-color, #d1d5db);border-top:none}.sd-editor-counter{font-size:var(--sd-font-size-12, 12px);color:var(--sd-text-muted, #666)}.sd-editor-counter--over{color:var(--mdc-theme-error, #f44336)}.sd-editor-footer{min-height:20px;margin-top:4px}.sd-editor-footer mat-error{font-size:var(--sd-font-size-12, 12px);color:var(--mdc-theme-error, #f44336)}.sd-error-icon{position:absolute;right:8px;bottom:8px;z-index:2;color:var(--mdc-theme-error, #f44336);height:20px;width:20px;font-size:var(--sd-font-size-20, 20px)}.sd-visually-hidden{position:absolute;width:1px;height:1px;overflow:hidden;clip-path:inset(50%);white-space:nowrap}\n"], dependencies: [{ kind: "component", type: SdIcon, selector: "sd-icon", inputs: ["name", "fontIcon", "color", "set", "fontSet", "size", "strokeWidth", "absoluteStrokeWidth", "ariaLabel"] }, { kind: "component", type: SdEditorSurface, selector: "sd-editor-surface", inputs: ["content", "format", "variant", "editable", "disabled", "readonly", "placeholder", "mentionFeeds", "uploadEnabled", "height", "maxHeight", "label", "describedBy", "invalid", "id"], outputs: ["engineReady", "change", "focus", "blur", "diagnostics", "sourceChange", "formatChange", "compositionChange", "mentionSelected", "filesSelected"] }, { kind: "component", type: SdLabel, selector: "sd-label", inputs: ["label", "description", "required", "helperText", "for", "labelId"] }, { kind: "ngmodule", type: MatFormFieldModule }, { kind: "directive", type: i1.MatError, selector: "mat-error, [matError]", inputs: ["id"] }, { kind: "ngmodule", type: MatTooltipModule }, { kind: "directive", type: i2.MatTooltip, selector: "[matTooltip]", inputs: ["matTooltipPosition", "matTooltipPositionAtOrigin", "matTooltipDisabled", "matTooltipShowDelay", "matTooltipHideDelay", "matTooltipTouchGestures", "matTooltip", "matTooltipClass"], exportAs: ["matTooltip"] }], changeDetection: i0.ChangeDetectionStrategy.OnPush });
1097
801
  }
1098
802
  i0.ɵɵngDeclareClassMetadata({ minVersion: "12.0.0", version: "22.1.5", ngImport: i0, type: SdEditor, decorators: [{
1099
803
  type: Component,
1100
- args: [{ selector: 'sd-editor', standalone: true, changeDetection: ChangeDetectionStrategy.OnPush, imports: [SdIcon, CKEditorModule, SdLabel, SdCKEditorStyles, MatFormFieldModule, MatTooltipModule], template: "<sd-ckeditor-styles />\n@let _label = label();\n@let _helperText = helperText();\n@let _hideInlineError = hideInlineError();\n@let _errorMessage = errorMessage;\n@let _required = required();\n@let _maxLength = maxlength();\n@let _showCounter = !!_maxLength && !formControl.disabled && !_hideInlineError;\n\n@if (_label) {\n <sd-label [label]=\"_label\" [required]=\"_required\" [helperText]=\"_helperText\"></sd-label>\n}\n\n<div\n class=\"sd-editor\"\n [class.sd-editor--readonly]=\"readonly()\"\n [class.sd-editor--error]=\"formControl.invalid && formControl.touched\"\n [class.has-counter]=\"_showCounter\"\n [style.--sd-editor-content-min-height]=\"height()\"\n [style.--sd-editor-content-max-height]=\"maxHeight()\"\n [attr.data-autoId]=\"autoId()\"\n [attr.data-disabled]=\"dataDisabled()\"\n [attr.data-empty]=\"dataEmpty()\">\n <ckeditor [editor]=\"Editor\" [config]=\"editorConfig()\" [disabled]=\"formControl.disabled\" (ready)=\"onReady($event)\"></ckeditor>\n\n @if (_showCounter) {\n <div class=\"sd-editor-counter-row\">\n <span class=\"sd-editor-counter\" [class.sd-editor-counter--over]=\"isOverLimit()\"> {{ _textLength() }}/{{ _maxLength }} </span>\n </div>\n }\n\n @if (_hideInlineError && _errorMessage && formControl.touched) {\n <sd-icon class=\"sd-error-icon\" [matTooltip]=\"_errorMessage\" matTooltipPosition=\"above\" name=\"error\"></sd-icon>\n }\n @if (_hideInlineError && _errorMessage && formControl.touched) {\n <span class=\"sd-visually-hidden\">{{ _errorMessage }}</span>\n\n }\n</div>\n\n<div class=\"sd-editor-footer\">\n @if (!_hideInlineError && _errorMessage && formControl.touched) {\n <mat-error>{{ _errorMessage }}</mat-error>\n }\n</div>\n", styles: [".sd-editor{display:flex;flex-direction:column;width:100%;position:relative}.sd-editor-counter-row{display:flex;justify-content:flex-end;align-items:center;padding:4px 12px;border:1px solid var(--ck-color-base-border);border-top:none}.sd-editor-footer{min-height:20px;margin-top:4px}.sd-editor-footer mat-error{font-size:var(--sd-font-size-12, 12px);color:var(--mdc-theme-error, #f44336)}.sd-error-icon{position:absolute;right:8px;bottom:8px;z-index:2;color:var(--mdc-theme-error, #f44336);height:20px;width:20px;font-size:var(--sd-font-size-20, 20px);cursor:default}.sd-editor--readonly :host ::ng-deep .ck-editor__editable{background:#0000000a;cursor:default}.sd-editor-counter{font-size:var(--sd-font-size-12, 12px);color:#0009}.sd-editor-counter--over{color:var(--mdc-theme-error, #f44336)}::ng-deep .ck-powered-by,::ng-deep .ck-powered-by-balloon{display:none!important}:host ::ng-deep ckeditor,:host ::ng-deep .ck-editor{display:flex;flex-direction:column}:host ::ng-deep .ck-editor{--ck-content-font-size: 14px;--ck-content-line-height: 1.5}:host ::ng-deep .ck-editor__main{overflow:visible}:host ::ng-deep .ck-editor__editable{min-height:var(--sd-editor-content-min-height, 200px)!important;max-height:var(--sd-editor-content-max-height, none)!important;padding:24px!important;overflow-y:auto!important;border:1px solid var(--ck-color-base-border)!important}:host ::ng-deep .ck-editor__editable.ck-focused{box-shadow:none!important}:host ::ng-deep .sd-editor.has-counter .ck-editor__editable{border-bottom:none!important}:host ::ng-deep .sd-editor--error .ck-editor__editable,:host ::ng-deep .sd-editor--error .ck-toolbar{border-color:var(--mdc-theme-error, #f44336)!important}:host ::ng-deep .sd-editor--error.has-counter .sd-editor-counter-row{border-color:var(--mdc-theme-error, #f44336)}:host ::ng-deep .ck-content p{margin-bottom:var(--ck-spacing-large);text-indent:0}:host ::ng-deep .ck-content ul,:host ::ng-deep .ck-content ol{margin-left:0!important;padding-left:20px!important}\n", ":host ::ng-deep .ck-content img{max-width:100%!important;height:auto!important;object-fit:contain}:host ::ng-deep .ck-content figure.image{position:relative;display:block;width:fit-content;max-width:100%;margin:0 auto;overflow:visible}:host ::ng-deep .ck-content figure.image:hover{z-index:99999!important}:host ::ng-deep .ck-content figure.image.image-style-align-left{float:left;margin:0 1em 0 0}:host ::ng-deep .ck-content figure.image.image-style-align-left[style*=\"width:100\"]{float:none;margin:0 auto 0 0}:host ::ng-deep .ck-content figure.image.image-style-align-right{float:right;margin:0 0 0 1em}:host ::ng-deep .ck-content figure.image.image-style-align-right[style*=\"width:100\"]{float:none;margin:0 0 0 auto}:host ::ng-deep .ck-content figure.image.image-style-block-align-left{margin:0 auto 0 0}:host ::ng-deep .ck-content figure.image.image-style-block-align-right{margin:0 0 0 auto}:host ::ng-deep .ck-content figure.image .ck-progress-bar{position:absolute;bottom:0;left:0;width:30%!important;height:3px;background:var(--sd-primary, #005cbb);border-radius:var(--sd-radius-2, 2px);z-index:10;pointer-events:none;animation:sd-progress-indeterminate 1.4s ease-in-out infinite}:host ::ng-deep .ck-content figure.image:has(.ck-progress-bar){overflow:hidden}:host ::ng-deep .ck-content figure.image:has(.ck-progress-bar) img{filter:blur(1px) brightness(.85);transition:filter var(--sd-duration-slow, .3s) ease}:host ::ng-deep .ck-content figure.image:has(.ck-progress-bar):after{content:\"\";position:absolute;inset:0;display:flex;align-items:center;justify-content:center;z-index:9;background:#ffffff40;border-radius:inherit}:host ::ng-deep .ck-content figure.image:has(.ck-progress-bar):before{content:\"\";position:absolute;top:50%;left:50%;width:28px;height:28px;margin:-14px 0 0 -14px;border:3px solid rgba(255,255,255,.5);border-top-color:var(--sd-primary, #005cbb);border-radius:50%;animation:sd-spinner .75s linear infinite;z-index:11;pointer-events:none}@keyframes sd-spinner{to{transform:rotate(360deg)}}@keyframes sd-progress-indeterminate{0%{left:-30%}to{left:100%}}\n"] }]
1101
- }], ctorParameters: () => [], propDecorators: { option: [{ type: i0.Input, args: [{ isSignal: true, alias: "option", required: false }] }], height: [{ type: i0.Input, args: [{ isSignal: true, alias: "height", required: false }] }], maxHeight: [{ type: i0.Input, args: [{ isSignal: true, alias: "maxHeight", required: false }] }], maxlength: [{ type: i0.Input, args: [{ isSignal: true, alias: "maxlength", required: false }] }], label: [{ type: i0.Input, args: [{ isSignal: true, alias: "label", required: false }] }], helperText: [{ type: i0.Input, args: [{ isSignal: true, alias: "helperText", required: false }] }], required: [{ type: i0.Input, args: [{ isSignal: true, alias: "required", required: false }] }], disabled: [{ type: i0.Input, args: [{ isSignal: true, alias: "disabled", required: false }] }], readonly: [{ type: i0.Input, args: [{ isSignal: true, alias: "readonly", required: false }] }], hideInlineError: [{ type: i0.Input, args: [{ isSignal: true, alias: "hideInlineError", required: false }] }], inlineError: [{ type: i0.Input, args: [{ isSignal: true, alias: "inlineError", required: false }] }], placeholder: [{ type: i0.Input, args: [{ isSignal: true, alias: "placeholder", required: false }] }], validator: [{ type: i0.Input, args: [{ isSignal: true, alias: "validator", required: false }] }], form: [{ type: i0.Input, args: [{ isSignal: true, alias: "form", required: false }] }], key: [{ type: i0.Input, args: [{ isSignal: true, alias: "key", required: false }] }], autoIdInput: [{ type: i0.Input, args: [{ isSignal: true, alias: "autoId", required: false }] }], name: [{ type: i0.Input, args: [{ isSignal: true, alias: "name", required: false }] }], valueModel: [{ type: i0.Input, args: [{ isSignal: true, alias: "model", required: false }] }, { type: i0.Output, args: ["modelChange"] }], sdChange: [{ type: i0.Output, args: ["sdChange"] }], sdBlur: [{ type: i0.Output, args: ["sdBlur"] }], sdFocus: [{ type: i0.Output, args: ["sdFocus"] }] } });
804
+ args: [{ selector: 'sd-editor', standalone: true, changeDetection: ChangeDetectionStrategy.OnPush, imports: [SdIcon, SdEditorSurface, SdLabel, MatFormFieldModule, MatTooltipModule], template: "@let _label = label();\n@let _helperText = helperText();\n@let _hideInlineError = hideInlineError();\n@let _errorMessage = errorMessage;\n@let _required = required();\n@let _maxLength = maxlength();\n@let _showCounter = !!_maxLength && !formControl.disabled && !_hideInlineError;\n\n@if (_label) {\n <sd-label [label]=\"_label\" [required]=\"_required\" [helperText]=\"_helperText\"></sd-label>\n}\n\n<div\n class=\"sd-editor\"\n [class.sd-editor--readonly]=\"readonly()\"\n [class.sd-editor--error]=\"formControl.invalid && formControl.touched\"\n [class.has-counter]=\"_showCounter\"\n [style.--sd-editor-content-min-height]=\"height()\"\n [style.--sd-editor-content-max-height]=\"maxHeight()\"\n [attr.data-autoId]=\"autoId()\"\n [attr.data-disabled]=\"dataDisabled()\"\n [attr.data-empty]=\"dataEmpty()\">\n <sd-editor-surface\n variant=\"full\"\n [content]=\"surfaceContent()\"\n [editable]=\"!formControl.disabled && !readonly()\"\n [disabled]=\"formControl.disabled\"\n [readonly]=\"readonly()\"\n [placeholder]=\"placeholder()\"\n [height]=\"height()\"\n [maxHeight]=\"maxHeight()\"\n [uploadEnabled]=\"uploadEnabled()\"\n [label]=\"label()\"\n [describedBy]=\"helperText() || (_errorMessage && formControl.touched) ? descriptionId() : undefined\"\n [invalid]=\"formControl.invalid && formControl.touched\"\n (engineReady)=\"onEngineReady($event)\"\n (sourceChange)=\"onSourceChange()\"\n (change)=\"onSurfaceChange($event)\"\n (compositionChange)=\"onCompositionChange($event)\"\n (focus)=\"onSurfaceFocus($event)\"\n (blur)=\"onSurfaceBlur($event)\"\n (diagnostics)=\"onDiagnostics($event)\"\n (filesSelected)=\"onFilesSelected($event)\" />\n\n @if (_showCounter) {\n <div class=\"sd-editor-counter-row\">\n <span class=\"sd-editor-counter\" [class.sd-editor-counter--over]=\"isOverLimit()\"> {{ _textLength() }}/{{ _maxLength }} </span>\n </div>\n }\n\n @if (_hideInlineError && _errorMessage && formControl.touched) {\n <sd-icon class=\"sd-error-icon\" [matTooltip]=\"_errorMessage\" matTooltipPosition=\"above\" name=\"error\"></sd-icon>\n }\n @if (_hideInlineError && _errorMessage && formControl.touched) {\n <span class=\"sd-visually-hidden\">{{ _errorMessage }}</span>\n }\n</div>\n\n<div class=\"sd-editor-footer\">\n @if (!_hideInlineError && _errorMessage && formControl.touched) {\n <mat-error>{{ _errorMessage }}</mat-error>\n }\n</div>\n\n@if (_helperText || (_errorMessage && formControl.touched)) {\n <span class=\"sd-visually-hidden\" [id]=\"descriptionId()\">{{ _helperText }} {{ formControl.touched ? _errorMessage : '' }}</span>\n}\n", styles: [".sd-editor{display:flex;flex-direction:column;width:100%;position:relative}.sd-editor-counter-row{display:flex;justify-content:flex-end;padding:4px 12px;border:1px solid var(--sd-border-color, #d1d5db);border-top:none}.sd-editor-counter{font-size:var(--sd-font-size-12, 12px);color:var(--sd-text-muted, #666)}.sd-editor-counter--over{color:var(--mdc-theme-error, #f44336)}.sd-editor-footer{min-height:20px;margin-top:4px}.sd-editor-footer mat-error{font-size:var(--sd-font-size-12, 12px);color:var(--mdc-theme-error, #f44336)}.sd-error-icon{position:absolute;right:8px;bottom:8px;z-index:2;color:var(--mdc-theme-error, #f44336);height:20px;width:20px;font-size:var(--sd-font-size-20, 20px)}.sd-visually-hidden{position:absolute;width:1px;height:1px;overflow:hidden;clip-path:inset(50%);white-space:nowrap}\n"] }]
805
+ }], ctorParameters: () => [], propDecorators: { option: [{ type: i0.Input, args: [{ isSignal: true, alias: "option", required: false }] }], height: [{ type: i0.Input, args: [{ isSignal: true, alias: "height", required: false }] }], maxHeight: [{ type: i0.Input, args: [{ isSignal: true, alias: "maxHeight", required: false }] }], maxlength: [{ type: i0.Input, args: [{ isSignal: true, alias: "maxlength", required: false }] }], label: [{ type: i0.Input, args: [{ isSignal: true, alias: "label", required: false }] }], helperText: [{ type: i0.Input, args: [{ isSignal: true, alias: "helperText", required: false }] }], required: [{ type: i0.Input, args: [{ isSignal: true, alias: "required", required: false }] }], disabled: [{ type: i0.Input, args: [{ isSignal: true, alias: "disabled", required: false }] }], readonly: [{ type: i0.Input, args: [{ isSignal: true, alias: "readonly", required: false }] }], hideInlineError: [{ type: i0.Input, args: [{ isSignal: true, alias: "hideInlineError", required: false }] }], inlineError: [{ type: i0.Input, args: [{ isSignal: true, alias: "inlineError", required: false }] }], placeholder: [{ type: i0.Input, args: [{ isSignal: true, alias: "placeholder", required: false }] }], validator: [{ type: i0.Input, args: [{ isSignal: true, alias: "validator", required: false }] }], form: [{ type: i0.Input, args: [{ isSignal: true, alias: "form", required: false }] }], key: [{ type: i0.Input, args: [{ isSignal: true, alias: "key", required: false }] }], autoIdInput: [{ type: i0.Input, args: [{ isSignal: true, alias: "autoId", required: false }] }], name: [{ type: i0.Input, args: [{ isSignal: true, alias: "name", required: false }] }], valueModel: [{ type: i0.Input, args: [{ isSignal: true, alias: "model", required: false }] }, { type: i0.Output, args: ["modelChange"] }], sdChange: [{ type: i0.Output, args: ["sdChange"] }], sdBlur: [{ type: i0.Output, args: ["sdBlur"] }], sdFocus: [{ type: i0.Output, args: ["sdFocus"] }], sdImportWarning: [{ type: i0.Output, args: ["sdImportWarning"] }] } });
1102
806
 
1103
807
  /**
1104
808
  * Generated bundle index. Do not edit.