@sdcorejs/angular 20.3.0 → 20.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.
- package/README.md +2 -2
- package/assets/STYLE-GUIDE.md +25 -5
- package/assets/THEME.md +237 -5
- package/assets/licenses/tiptap-oss-NOTICES.txt +332 -0
- package/assets/scss/ckeditor5.scss +2 -88
- package/assets/scss/core/_control.scss +39 -0
- package/assets/scss/core/form.scss +156 -45
- package/assets/scss/core/view.scss +24 -0
- package/assets/scss/editor-content.scss +173 -0
- package/assets/scss/sd-core.scss +1 -0
- package/assets/scss/themes/_component-tokens.scss +93 -31
- package/assets/scss/themes/_material-tokens.scss +112 -0
- package/assets/scss/themes/_presets.scss +25 -0
- package/assets/scss/themes/_scales.scss +10 -0
- package/assets/scss/themes/_semantic.scss +13 -0
- package/assets/scss/themes/default.scss +8 -2
- package/components/avatar/index.d.ts +67 -2
- package/components/badge/index.d.ts +188 -6
- package/components/button/index.d.ts +20 -1
- package/components/ckeditor-styles/index.d.ts +3 -18
- package/components/editor/index.d.ts +20 -17
- package/components/editor-engine/index.d.ts +246 -0
- package/components/file-explorer/index.d.ts +449 -57
- package/components/form-generic/index.d.ts +301 -37
- package/components/index.d.ts +2 -0
- package/components/kanban/index.d.ts +179 -0
- package/components/mini-editor/index.d.ts +33 -70
- package/components/modal-resizable/index.d.ts +1 -124
- package/components/operator/index.d.ts +137 -8
- package/components/section/index.d.ts +2 -1
- package/components/tab/index.d.ts +3 -1
- package/components/tab-router/index.d.ts +31 -18
- package/components/table/index.d.ts +84 -6
- package/components/window/index.d.ts +81 -0
- package/configurations/index.d.ts +8 -1
- package/fesm2022/sdcorejs-angular-components-api-contract-builder.mjs +5 -5
- package/fesm2022/sdcorejs-angular-components-api-contract-builder.mjs.map +1 -1
- package/fesm2022/sdcorejs-angular-components-avatar.mjs +142 -11
- package/fesm2022/sdcorejs-angular-components-avatar.mjs.map +1 -1
- package/fesm2022/sdcorejs-angular-components-badge.mjs +548 -24
- package/fesm2022/sdcorejs-angular-components-badge.mjs.map +1 -1
- package/fesm2022/sdcorejs-angular-components-button.mjs +33 -3
- package/fesm2022/sdcorejs-angular-components-button.mjs.map +1 -1
- package/fesm2022/sdcorejs-angular-components-ckeditor-styles.mjs +5 -20
- package/fesm2022/sdcorejs-angular-components-ckeditor-styles.mjs.map +1 -1
- package/fesm2022/sdcorejs-angular-components-data-state.mjs +1 -1
- package/fesm2022/sdcorejs-angular-components-data-state.mjs.map +1 -1
- package/fesm2022/sdcorejs-angular-components-editor-engine.mjs +1872 -0
- package/fesm2022/sdcorejs-angular-components-editor-engine.mjs.map +1 -0
- package/fesm2022/sdcorejs-angular-components-editor.mjs +457 -756
- package/fesm2022/sdcorejs-angular-components-editor.mjs.map +1 -1
- package/fesm2022/sdcorejs-angular-components-file-explorer.mjs +2209 -106
- package/fesm2022/sdcorejs-angular-components-file-explorer.mjs.map +1 -1
- package/fesm2022/sdcorejs-angular-components-form-generic.mjs +2616 -1054
- package/fesm2022/sdcorejs-angular-components-form-generic.mjs.map +1 -1
- package/fesm2022/sdcorejs-angular-components-history.mjs +5 -2
- package/fesm2022/sdcorejs-angular-components-history.mjs.map +1 -1
- package/fesm2022/sdcorejs-angular-components-image-editor.mjs +1 -1
- package/fesm2022/sdcorejs-angular-components-image-editor.mjs.map +1 -1
- package/fesm2022/sdcorejs-angular-components-import-excel.mjs +21 -6
- package/fesm2022/sdcorejs-angular-components-import-excel.mjs.map +1 -1
- package/fesm2022/sdcorejs-angular-components-inform.mjs +1 -1
- package/fesm2022/sdcorejs-angular-components-inform.mjs.map +1 -1
- package/fesm2022/sdcorejs-angular-components-kanban.mjs +451 -0
- package/fesm2022/sdcorejs-angular-components-kanban.mjs.map +1 -0
- package/fesm2022/sdcorejs-angular-components-mini-editor.mjs +177 -283
- package/fesm2022/sdcorejs-angular-components-mini-editor.mjs.map +1 -1
- package/fesm2022/sdcorejs-angular-components-modal-resizable.mjs +1 -308
- package/fesm2022/sdcorejs-angular-components-modal-resizable.mjs.map +1 -1
- package/fesm2022/sdcorejs-angular-components-modal.mjs +2 -2
- package/fesm2022/sdcorejs-angular-components-modal.mjs.map +1 -1
- package/fesm2022/sdcorejs-angular-components-operator.mjs +262 -43
- package/fesm2022/sdcorejs-angular-components-operator.mjs.map +1 -1
- package/fesm2022/sdcorejs-angular-components-query-bar.mjs +12 -12
- package/fesm2022/sdcorejs-angular-components-query-bar.mjs.map +1 -1
- package/fesm2022/sdcorejs-angular-components-query-builder.mjs +1 -1
- package/fesm2022/sdcorejs-angular-components-query-builder.mjs.map +1 -1
- package/fesm2022/sdcorejs-angular-components-section.mjs +5 -4
- package/fesm2022/sdcorejs-angular-components-section.mjs.map +1 -1
- package/fesm2022/sdcorejs-angular-components-side-drawer.mjs +2 -2
- package/fesm2022/sdcorejs-angular-components-side-drawer.mjs.map +1 -1
- package/fesm2022/sdcorejs-angular-components-stepper.mjs +5 -1
- package/fesm2022/sdcorejs-angular-components-stepper.mjs.map +1 -1
- package/fesm2022/sdcorejs-angular-components-tab-router.mjs +192 -42
- package/fesm2022/sdcorejs-angular-components-tab-router.mjs.map +1 -1
- package/fesm2022/sdcorejs-angular-components-tab.mjs +12 -4
- package/fesm2022/sdcorejs-angular-components-tab.mjs.map +1 -1
- package/fesm2022/sdcorejs-angular-components-table.mjs +564 -110
- package/fesm2022/sdcorejs-angular-components-table.mjs.map +1 -1
- package/fesm2022/sdcorejs-angular-components-tree.mjs +1 -1
- package/fesm2022/sdcorejs-angular-components-tree.mjs.map +1 -1
- package/fesm2022/sdcorejs-angular-components-upload-file.mjs +1 -1
- package/fesm2022/sdcorejs-angular-components-upload-file.mjs.map +1 -1
- package/fesm2022/sdcorejs-angular-components-view.mjs +2 -2
- package/fesm2022/sdcorejs-angular-components-view.mjs.map +1 -1
- package/fesm2022/sdcorejs-angular-components-window.mjs +486 -0
- package/fesm2022/sdcorejs-angular-components-window.mjs.map +1 -0
- package/fesm2022/sdcorejs-angular-components.mjs +2 -0
- package/fesm2022/sdcorejs-angular-components.mjs.map +1 -1
- package/fesm2022/sdcorejs-angular-configurations.mjs.map +1 -1
- package/fesm2022/sdcorejs-angular-directives.mjs +18 -1
- package/fesm2022/sdcorejs-angular-directives.mjs.map +1 -1
- package/fesm2022/sdcorejs-angular-forms-autocomplete.mjs +15 -2
- package/fesm2022/sdcorejs-angular-forms-autocomplete.mjs.map +1 -1
- package/fesm2022/sdcorejs-angular-forms-checkbox.mjs +2 -2
- package/fesm2022/sdcorejs-angular-forms-checkbox.mjs.map +1 -1
- package/fesm2022/sdcorejs-angular-forms-chip-calendar.mjs +460 -125
- package/fesm2022/sdcorejs-angular-forms-chip-calendar.mjs.map +1 -1
- package/fesm2022/sdcorejs-angular-forms-date-range.mjs +75 -13
- package/fesm2022/sdcorejs-angular-forms-date-range.mjs.map +1 -1
- package/fesm2022/sdcorejs-angular-forms-date.mjs +71 -18
- package/fesm2022/sdcorejs-angular-forms-date.mjs.map +1 -1
- package/fesm2022/sdcorejs-angular-forms-datetime.mjs +75 -16
- package/fesm2022/sdcorejs-angular-forms-datetime.mjs.map +1 -1
- package/fesm2022/sdcorejs-angular-forms-directives.mjs +82 -2
- package/fesm2022/sdcorejs-angular-forms-directives.mjs.map +1 -1
- package/fesm2022/sdcorejs-angular-forms-entity-picker.mjs +2 -2
- package/fesm2022/sdcorejs-angular-forms-entity-picker.mjs.map +1 -1
- package/fesm2022/sdcorejs-angular-forms-input-color.mjs +1 -1
- package/fesm2022/sdcorejs-angular-forms-input-color.mjs.map +1 -1
- package/fesm2022/sdcorejs-angular-forms-input-number.mjs +40 -5
- package/fesm2022/sdcorejs-angular-forms-input-number.mjs.map +1 -1
- package/fesm2022/sdcorejs-angular-forms-input.mjs +50 -7
- package/fesm2022/sdcorejs-angular-forms-input.mjs.map +1 -1
- package/fesm2022/sdcorejs-angular-forms-models.mjs +88 -5
- package/fesm2022/sdcorejs-angular-forms-models.mjs.map +1 -1
- package/fesm2022/sdcorejs-angular-forms-radio.mjs +2 -2
- package/fesm2022/sdcorejs-angular-forms-radio.mjs.map +1 -1
- package/fesm2022/sdcorejs-angular-forms-segmented.mjs +245 -0
- package/fesm2022/sdcorejs-angular-forms-segmented.mjs.map +1 -0
- package/fesm2022/sdcorejs-angular-forms-select.mjs +63 -15
- package/fesm2022/sdcorejs-angular-forms-select.mjs.map +1 -1
- package/fesm2022/sdcorejs-angular-forms-switch.mjs +2 -2
- package/fesm2022/sdcorejs-angular-forms-switch.mjs.map +1 -1
- package/fesm2022/sdcorejs-angular-forms-textarea.mjs +2 -2
- package/fesm2022/sdcorejs-angular-forms-textarea.mjs.map +1 -1
- package/fesm2022/sdcorejs-angular-forms-time.mjs +2 -2
- package/fesm2022/sdcorejs-angular-forms-time.mjs.map +1 -1
- package/fesm2022/sdcorejs-angular-forms-tree-select.mjs +1 -1
- package/fesm2022/sdcorejs-angular-forms-tree-select.mjs.map +1 -1
- package/fesm2022/sdcorejs-angular-forms.mjs +8 -0
- package/fesm2022/sdcorejs-angular-forms.mjs.map +1 -1
- package/fesm2022/sdcorejs-angular-i18n.mjs +1830 -17
- package/fesm2022/sdcorejs-angular-i18n.mjs.map +1 -1
- package/fesm2022/sdcorejs-angular-interceptors.mjs +1 -1
- package/fesm2022/sdcorejs-angular-interceptors.mjs.map +1 -1
- package/fesm2022/sdcorejs-angular-modules-generic-generic-configuration.page-DnbDCdcz.mjs +478 -0
- package/fesm2022/sdcorejs-angular-modules-generic-generic-configuration.page-DnbDCdcz.mjs.map +1 -0
- package/fesm2022/sdcorejs-angular-modules-generic-generic-form-host.page-EBHM4kx2.mjs +214 -0
- package/fesm2022/sdcorejs-angular-modules-generic-generic-form-host.page-EBHM4kx2.mjs.map +1 -0
- package/fesm2022/sdcorejs-angular-modules-generic-generic-list.page-BtHe8YIW.mjs +277 -0
- package/fesm2022/sdcorejs-angular-modules-generic-generic-list.page-BtHe8YIW.mjs.map +1 -0
- package/fesm2022/sdcorejs-angular-modules-generic-sdcorejs-angular-modules-generic-eFshU7ew.mjs +1556 -0
- package/fesm2022/sdcorejs-angular-modules-generic-sdcorejs-angular-modules-generic-eFshU7ew.mjs.map +1 -0
- package/fesm2022/sdcorejs-angular-modules-generic.mjs +2 -0
- package/fesm2022/sdcorejs-angular-modules-generic.mjs.map +1 -0
- package/fesm2022/sdcorejs-angular-modules-icon.mjs +96 -3
- package/fesm2022/sdcorejs-angular-modules-icon.mjs.map +1 -1
- package/fesm2022/sdcorejs-angular-modules-layout.mjs +1825 -62
- package/fesm2022/sdcorejs-angular-modules-layout.mjs.map +1 -1
- package/fesm2022/sdcorejs-angular-modules.mjs +1 -0
- package/fesm2022/sdcorejs-angular-modules.mjs.map +1 -1
- package/fesm2022/sdcorejs-angular-pipes.mjs +27 -7
- package/fesm2022/sdcorejs-angular-pipes.mjs.map +1 -1
- package/fesm2022/sdcorejs-angular-services-confirm.mjs +2 -2
- package/fesm2022/sdcorejs-angular-services-confirm.mjs.map +1 -1
- package/fesm2022/sdcorejs-angular-services-date-time.mjs +143 -0
- package/fesm2022/sdcorejs-angular-services-date-time.mjs.map +1 -0
- package/fesm2022/sdcorejs-angular-services-storage.mjs +44 -8
- package/fesm2022/sdcorejs-angular-services-storage.mjs.map +1 -1
- package/fesm2022/sdcorejs-angular-services.mjs +1 -0
- package/fesm2022/sdcorejs-angular-services.mjs.map +1 -1
- package/fesm2022/sdcorejs-angular-utilities-read-state.mjs +4 -0
- package/fesm2022/sdcorejs-angular-utilities-read-state.mjs.map +1 -1
- package/fesm2022/sdcorejs-angular-utilities-theme.mjs +10 -0
- package/fesm2022/sdcorejs-angular-utilities-theme.mjs.map +1 -1
- package/forms/autocomplete/index.d.ts +5 -0
- package/forms/chip-calendar/index.d.ts +163 -18
- package/forms/date/index.d.ts +23 -2
- package/forms/date-range/index.d.ts +24 -2
- package/forms/directives/index.d.ts +47 -2
- package/forms/index.d.ts +8 -6
- package/forms/input/index.d.ts +23 -2
- package/forms/input-number/index.d.ts +23 -2
- package/forms/models/index.d.ts +38 -3
- package/forms/segmented/index.d.ts +90 -0
- package/forms/select/index.d.ts +32 -2
- package/i18n/index.d.ts +360 -1
- package/modules/generic/index.d.ts +316 -0
- package/modules/icon/index.d.ts +37 -6
- package/modules/index.d.ts +1 -0
- package/modules/layout/index.d.ts +536 -86
- package/package.json +49 -8
- package/pipes/index.d.ts +2 -0
- package/services/date-time/index.d.ts +57 -0
- package/services/index.d.ts +1 -0
- package/services/storage/index.d.ts +8 -1
- package/utilities/read-state/index.d.ts +2 -0
- package/utilities/theme/index.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
|
|
6
|
+
import * as i1 from '@angular/material/form-field';
|
|
7
7
|
import { MatFormFieldModule } from '@angular/material/form-field';
|
|
8
|
-
import * as
|
|
8
|
+
import * as i2 from '@angular/material/tooltip';
|
|
9
9
|
import { MatTooltipModule } from '@angular/material/tooltip';
|
|
10
|
-
import
|
|
11
|
-
|
|
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
|
-
|
|
324
|
-
|
|
325
|
-
|
|
326
|
-
|
|
327
|
-
|
|
328
|
-
|
|
329
|
-
|
|
330
|
-
|
|
331
|
-
|
|
332
|
-
|
|
333
|
-
|
|
334
|
-
|
|
335
|
-
|
|
336
|
-
|
|
337
|
-
|
|
338
|
-
return
|
|
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
|
-
|
|
347
|
-
|
|
348
|
-
|
|
349
|
-
|
|
350
|
-
|
|
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
|
-
|
|
358
|
-
|
|
359
|
-
|
|
360
|
-
|
|
361
|
-
|
|
362
|
-
|
|
363
|
-
|
|
364
|
-
|
|
365
|
-
|
|
366
|
-
|
|
367
|
-
|
|
368
|
-
|
|
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
|
-
|
|
373
|
-
|
|
374
|
-
|
|
375
|
-
|
|
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
|
-
|
|
380
|
-
|
|
381
|
-
|
|
382
|
-
|
|
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 (
|
|
386
|
-
|
|
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
|
|
498
|
-
|
|
499
|
-
|
|
500
|
-
|
|
501
|
-
|
|
502
|
-
|
|
503
|
-
|
|
504
|
-
|
|
505
|
-
|
|
506
|
-
|
|
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
|
-
|
|
519
|
-
|
|
520
|
-
|
|
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
|
-
|
|
545
|
-
|
|
297
|
+
catch {
|
|
298
|
+
// Validation already reports a localized warning. An invalidated local decode is silent.
|
|
546
299
|
}
|
|
547
|
-
|
|
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
|
-
|
|
568
|
-
|
|
569
|
-
|
|
570
|
-
|
|
571
|
-
|
|
572
|
-
|
|
573
|
-
|
|
574
|
-
|
|
575
|
-
|
|
576
|
-
|
|
577
|
-
|
|
578
|
-
|
|
579
|
-
|
|
580
|
-
|
|
581
|
-
|
|
582
|
-
|
|
583
|
-
|
|
584
|
-
|
|
585
|
-
|
|
586
|
-
|
|
587
|
-
|
|
588
|
-
|
|
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
|
-
|
|
592
|
-
|
|
593
|
-
|
|
594
|
-
|
|
595
|
-
|
|
596
|
-
|
|
597
|
-
|
|
598
|
-
|
|
599
|
-
|
|
600
|
-
|
|
601
|
-
|
|
602
|
-
|
|
603
|
-
|
|
604
|
-
|
|
605
|
-
|
|
606
|
-
|
|
607
|
-
|
|
608
|
-
|
|
609
|
-
|
|
610
|
-
|
|
611
|
-
|
|
612
|
-
|
|
613
|
-
|
|
614
|
-
|
|
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
|
-
|
|
625
|
-
|
|
626
|
-
|
|
627
|
-
|
|
628
|
-
|
|
629
|
-
|
|
630
|
-
|
|
631
|
-
|
|
632
|
-
|
|
633
|
-
|
|
634
|
-
|
|
635
|
-
|
|
636
|
-
|
|
637
|
-
|
|
638
|
-
|
|
639
|
-
|
|
640
|
-
|
|
641
|
-
|
|
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
|
-
|
|
648
|
-
if (
|
|
649
|
-
return
|
|
650
|
-
|
|
651
|
-
|
|
652
|
-
|
|
653
|
-
|
|
654
|
-
|
|
655
|
-
|
|
656
|
-
|
|
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
|
-
|
|
659
|
-
|
|
660
|
-
|
|
661
|
-
|
|
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
|
-
#
|
|
668
|
-
if (
|
|
669
|
-
|
|
670
|
-
|
|
671
|
-
|
|
672
|
-
|
|
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 });
|
|
@@ -757,180 +544,182 @@ class SdEditor {
|
|
|
757
544
|
return this.inlineError();
|
|
758
545
|
return undefined;
|
|
759
546
|
}
|
|
760
|
-
|
|
761
|
-
#
|
|
762
|
-
|
|
763
|
-
|
|
764
|
-
|
|
765
|
-
|
|
766
|
-
|
|
767
|
-
|
|
768
|
-
|
|
769
|
-
|
|
770
|
-
|
|
771
|
-
|
|
772
|
-
|
|
773
|
-
'underline',
|
|
774
|
-
'|',
|
|
775
|
-
'fontSize',
|
|
776
|
-
'fontColor',
|
|
777
|
-
'|',
|
|
778
|
-
'alignment:left',
|
|
779
|
-
'alignment:center',
|
|
780
|
-
'alignment:right',
|
|
781
|
-
'alignment:justify',
|
|
782
|
-
'|',
|
|
783
|
-
'bulletedList',
|
|
784
|
-
'numberedList',
|
|
785
|
-
];
|
|
786
|
-
if (enableImageUpload)
|
|
787
|
-
toolbarItems.push('|', 'uploadImage');
|
|
788
|
-
const config = {
|
|
789
|
-
licenseKey: 'GPL',
|
|
790
|
-
getOption: () => ({
|
|
791
|
-
...opt,
|
|
792
|
-
uploadFn,
|
|
793
|
-
onWarning: (msg) => this.#notifyService.warning(msg),
|
|
794
|
-
// Truyền i18n service xuống CKEditor plugin (ngoài DI tree) để dịch warning messages
|
|
795
|
-
_i18n: this.#i18n,
|
|
796
|
-
}),
|
|
797
|
-
plugins,
|
|
798
|
-
toolbar: { items: toolbarItems, shouldNotGroupWhenFull: true },
|
|
799
|
-
placeholder: this.placeholder(),
|
|
800
|
-
fontColor: { columns: 5, documentColors: 10, colorPicker: { format: 'hex' } },
|
|
801
|
-
fontSize: { options: [10, 11, 12, 14, 16, 18, 20], supportAllValues: true },
|
|
802
|
-
};
|
|
803
|
-
if (enableImageUpload) {
|
|
804
|
-
config.image = {
|
|
805
|
-
resizeUnit: '%',
|
|
806
|
-
resizeOptions: [
|
|
807
|
-
{ name: 'resizeImage:100', value: '100', label: '100%' },
|
|
808
|
-
{ name: 'resizeImage:75', value: '75', label: '75%' },
|
|
809
|
-
{ name: 'resizeImage:50', value: '50', label: '50%' },
|
|
810
|
-
{ name: 'resizeImage:25', value: '25', label: '25%' },
|
|
811
|
-
{ name: 'resizeImage:original', value: null, label: 'Original' },
|
|
812
|
-
],
|
|
813
|
-
toolbar: ['resizeImage', '|', 'imageStyle:alignBlockLeft', 'imageStyle:alignCenter', 'imageStyle:alignBlockRight'],
|
|
814
|
-
};
|
|
815
|
-
}
|
|
816
|
-
return config;
|
|
817
|
-
}, ...(ngDevMode ? [{ debugName: "editorConfig" }] : []));
|
|
547
|
+
sdImportWarning = output();
|
|
548
|
+
#diagnostics = signal([], ...(ngDevMode ? [{ debugName: "#diagnostics" }] : []));
|
|
549
|
+
importDiagnostics = this.#diagnostics.asReadonly();
|
|
550
|
+
surfaceContent = signal('', ...(ngDevMode ? [{ debugName: "surfaceContent" }] : []));
|
|
551
|
+
uploadEnabled = computed(() => !!this.#buildUploadFn(), ...(ngDevMode ? [{ debugName: "uploadEnabled" }] : []));
|
|
552
|
+
descriptionId = computed(() => `sd-editor-description-${Utilities.generateUuid()}`, ...(ngDevMode ? [{ debugName: "descriptionId" }] : []));
|
|
553
|
+
#engine;
|
|
554
|
+
#uploads;
|
|
555
|
+
#timer;
|
|
556
|
+
#pending;
|
|
557
|
+
#deadline;
|
|
558
|
+
#composing = false;
|
|
559
|
+
#destroyed = false;
|
|
818
560
|
constructor() {
|
|
819
561
|
this.#validateDuplicateConfigKeys();
|
|
820
|
-
|
|
821
|
-
|
|
822
|
-
|
|
823
|
-
|
|
824
|
-
|
|
825
|
-
|
|
826
|
-
|
|
827
|
-
|
|
828
|
-
|
|
829
|
-
|
|
830
|
-
|
|
831
|
-
|
|
832
|
-
}
|
|
833
|
-
|
|
834
|
-
|
|
835
|
-
|
|
836
|
-
|
|
837
|
-
|
|
838
|
-
|
|
839
|
-
|
|
840
|
-
|
|
841
|
-
|
|
842
|
-
|
|
843
|
-
|
|
844
|
-
|
|
845
|
-
}
|
|
846
|
-
}
|
|
847
|
-
return changed;
|
|
562
|
+
effect(() => {
|
|
563
|
+
const disabled = this.disabled();
|
|
564
|
+
if (disabled)
|
|
565
|
+
this.formControl.disable({ emitEvent: false });
|
|
566
|
+
else
|
|
567
|
+
this.formControl.enable({ emitEvent: false });
|
|
568
|
+
if (disabled)
|
|
569
|
+
this.#cancelWork();
|
|
570
|
+
});
|
|
571
|
+
effect(() => {
|
|
572
|
+
if (this.readonly())
|
|
573
|
+
this.#cancelWork();
|
|
574
|
+
});
|
|
575
|
+
effect(() => this.#setExternalContent(this.valueModel() ?? ''));
|
|
576
|
+
effect(() => {
|
|
577
|
+
this.required();
|
|
578
|
+
this.maxlength();
|
|
579
|
+
this.inlineError();
|
|
580
|
+
this.validator();
|
|
581
|
+
this.#updateValidators();
|
|
582
|
+
});
|
|
583
|
+
this.formControl.valueChanges.pipe(takeUntilDestroyed(this.#destroyRef)).subscribe((value) => {
|
|
584
|
+
const normalized = value ?? '';
|
|
585
|
+
this.#setExternalContent(normalized);
|
|
586
|
+
this.valueModel.set(normalized);
|
|
848
587
|
});
|
|
849
|
-
|
|
850
|
-
|
|
851
|
-
|
|
852
|
-
this.sdBlur.emit(evt.domEvent);
|
|
853
|
-
this.formControl.markAsTouched();
|
|
588
|
+
this.formControl.statusChanges.pipe(takeUntilDestroyed(this.#destroyRef)).subscribe(() => {
|
|
589
|
+
if (this.formControl.disabled)
|
|
590
|
+
this.#cancelWork();
|
|
854
591
|
this.#cdRef.markForCheck();
|
|
855
592
|
});
|
|
856
|
-
|
|
857
|
-
|
|
858
|
-
|
|
859
|
-
|
|
860
|
-
|
|
861
|
-
|
|
862
|
-
|
|
863
|
-
* - Hàm hỗ trợ trả ra data cuối cùng.
|
|
864
|
-
* * @returns {Promise<string>} Nội dung cuối cùng được trích xuất từ sd-editor.
|
|
865
|
-
*/
|
|
866
|
-
upload = async () => {
|
|
867
|
-
await this.#uploadImages();
|
|
868
|
-
return this.#getFromEditor();
|
|
869
|
-
};
|
|
870
|
-
// Editor Content
|
|
871
|
-
#setToEditor(html) {
|
|
872
|
-
this.#editor?.setData?.(this.#normalizeHtmlForEditor(html));
|
|
593
|
+
this.formControl.sdChanges.pipe(takeUntilDestroyed(this.#destroyRef)).subscribe(() => this.#cdRef.markForCheck());
|
|
594
|
+
this.#destroyRef.onDestroy(() => {
|
|
595
|
+
this.#destroyed = true;
|
|
596
|
+
this.#cancelCadence();
|
|
597
|
+
this.#uploads?.destroy();
|
|
598
|
+
this.#engine = undefined; // Surface owns engine destruction exactly once.
|
|
599
|
+
});
|
|
873
600
|
}
|
|
874
|
-
|
|
875
|
-
|
|
876
|
-
|
|
601
|
+
onEngineReady(engine) {
|
|
602
|
+
this.#cancelCadence();
|
|
603
|
+
this.#composing = false;
|
|
604
|
+
this.#uploads?.destroy();
|
|
605
|
+
this.#engine = engine;
|
|
606
|
+
this.#uploads = new SdEditorUploadManager(engine, () => ({ ...this.option().imageConfig, uploadFn: this.#buildUploadFn() }), message => this.#notifyService.warning(message), this.#i18n);
|
|
607
|
+
}
|
|
608
|
+
onSourceChange() {
|
|
609
|
+
this.#cancelCadence();
|
|
610
|
+
if (this.formControl.disabled || this.readonly())
|
|
611
|
+
this.#uploads?.invalidateWork();
|
|
612
|
+
else
|
|
613
|
+
this.#uploads?.invalidateSource();
|
|
614
|
+
}
|
|
615
|
+
onSurfaceChange(value) {
|
|
616
|
+
if (this.#destroyed || this.formControl.disabled || this.readonly())
|
|
617
|
+
return;
|
|
618
|
+
this.#uploads?.pruneRemoved();
|
|
619
|
+
this.#clearTimer();
|
|
620
|
+
this.#pending = value;
|
|
621
|
+
// Composition pauses an existing deadline; its final document replaces only
|
|
622
|
+
// the pending value. An ordinary edit starts a new 100ms debounce deadline.
|
|
623
|
+
if (!this.#composing || this.#deadline === undefined)
|
|
624
|
+
this.#deadline = Date.now() + 100;
|
|
625
|
+
if (!this.#composing)
|
|
626
|
+
this.#schedulePending();
|
|
627
|
+
}
|
|
628
|
+
onCompositionChange(composing) {
|
|
629
|
+
this.#composing = composing;
|
|
630
|
+
this.#clearTimer();
|
|
631
|
+
if (!composing)
|
|
632
|
+
this.#schedulePending();
|
|
633
|
+
}
|
|
634
|
+
#schedulePending() {
|
|
635
|
+
if (this.#pending === undefined || this.#deadline === undefined || this.#composing || this.#destroyed)
|
|
636
|
+
return;
|
|
637
|
+
this.#timer = setTimeout(() => {
|
|
638
|
+
this.#timer = undefined;
|
|
639
|
+
const value = this.#pending;
|
|
640
|
+
this.#pending = undefined;
|
|
641
|
+
this.#deadline = undefined;
|
|
642
|
+
if (value !== undefined && !this.#destroyed && !this.#composing && !this.formControl.disabled && !this.readonly())
|
|
643
|
+
this.#onEditorUserInput(value);
|
|
644
|
+
}, Math.max(0, this.#deadline - Date.now()));
|
|
645
|
+
}
|
|
646
|
+
onSurfaceFocus(event) {
|
|
647
|
+
this.sdFocus.emit(event);
|
|
648
|
+
}
|
|
649
|
+
onSurfaceBlur(event) {
|
|
650
|
+
this.sdBlur.emit(event);
|
|
651
|
+
this.formControl.markAsTouched();
|
|
652
|
+
this.#cdRef.markForCheck();
|
|
653
|
+
}
|
|
654
|
+
onDiagnostics(diagnostics) {
|
|
655
|
+
this.#diagnostics.set(diagnostics);
|
|
656
|
+
this.sdImportWarning.emit(diagnostics);
|
|
657
|
+
}
|
|
658
|
+
async onFilesSelected(files) {
|
|
659
|
+
if (this.formControl.disabled || this.readonly())
|
|
660
|
+
return;
|
|
661
|
+
await this.#uploads?.selectFiles(files);
|
|
877
662
|
}
|
|
878
|
-
|
|
879
|
-
|
|
880
|
-
|
|
881
|
-
return '';
|
|
882
|
-
}
|
|
883
|
-
let result = html;
|
|
884
|
-
result = imageInlineStylesToClasses(result);
|
|
885
|
-
return result;
|
|
663
|
+
focusEditor = () => {
|
|
664
|
+
if (!this.formControl.disabled)
|
|
665
|
+
this.#engine?.focus();
|
|
886
666
|
};
|
|
887
|
-
|
|
888
|
-
|
|
889
|
-
|
|
890
|
-
|
|
667
|
+
upload = async () => {
|
|
668
|
+
if ((this.option().imageConfig?.uploadMode ?? 'deferred') === 'deferred') {
|
|
669
|
+
if (!this.#buildUploadFn())
|
|
670
|
+
throw new Error('No upload function configured for image upload');
|
|
671
|
+
await this.#uploads?.upload();
|
|
891
672
|
}
|
|
892
|
-
|
|
893
|
-
result = imageClassesToInlineStyles(result);
|
|
894
|
-
return result;
|
|
673
|
+
return this.#engine?.getHtml() ?? '';
|
|
895
674
|
};
|
|
896
|
-
|
|
897
|
-
|
|
898
|
-
|
|
899
|
-
|
|
675
|
+
#clearTimer() {
|
|
676
|
+
if (this.#timer !== undefined)
|
|
677
|
+
clearTimeout(this.#timer);
|
|
678
|
+
this.#timer = undefined;
|
|
679
|
+
}
|
|
680
|
+
#cancelCadence() {
|
|
681
|
+
this.#clearTimer();
|
|
682
|
+
this.#pending = undefined;
|
|
683
|
+
this.#deadline = undefined;
|
|
684
|
+
}
|
|
685
|
+
#cancelWork() {
|
|
686
|
+
this.#cancelCadence();
|
|
687
|
+
this.#uploads?.invalidateWork();
|
|
688
|
+
}
|
|
689
|
+
#setExternalContent(value) {
|
|
690
|
+
if (this.formControl.value !== value)
|
|
691
|
+
this.formControl.setValue(value, { emitEvent: false });
|
|
692
|
+
this._textLength.set(countTextLength(value));
|
|
693
|
+
this.formControl.updateValueAndValidity({ emitEvent: false });
|
|
694
|
+
if (this.#isCurrentContent(value))
|
|
900
695
|
return;
|
|
696
|
+
this.#cancelCadence();
|
|
697
|
+
this.#uploads?.invalidateSource();
|
|
698
|
+
this.surfaceContent.set(value);
|
|
699
|
+
this.#engine?.setContent(value);
|
|
700
|
+
}
|
|
701
|
+
#isCurrentContent(value) {
|
|
702
|
+
if (!this.#engine)
|
|
703
|
+
return value === this.surfaceContent();
|
|
704
|
+
try {
|
|
705
|
+
return value === this.#engine.getContent();
|
|
901
706
|
}
|
|
902
|
-
|
|
903
|
-
|
|
904
|
-
if (this.#editor) {
|
|
905
|
-
this.#setToEditor(v);
|
|
707
|
+
catch {
|
|
708
|
+
return false;
|
|
906
709
|
}
|
|
907
710
|
}
|
|
908
|
-
// Xử lý khi user soạn thảo
|
|
909
711
|
#onEditorUserInput(rawHtml) {
|
|
910
|
-
const
|
|
911
|
-
|
|
912
|
-
|
|
913
|
-
|
|
914
|
-
|
|
915
|
-
if (this.formControl.value !== out) {
|
|
916
|
-
this.formControl.setValue(out, { emitEvent: false });
|
|
917
|
-
// 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.
|
|
918
|
-
if (out !== normalized)
|
|
712
|
+
const value = sdSanitizeEditorHtml(rawHtml);
|
|
713
|
+
this._textLength.set(countTextLength(value));
|
|
714
|
+
if (this.formControl.value !== value) {
|
|
715
|
+
this.formControl.setValue(value, { emitEvent: false });
|
|
716
|
+
if (value !== rawHtml)
|
|
919
717
|
this.formControl.markAsDirty();
|
|
920
718
|
}
|
|
921
719
|
this.formControl.updateValueAndValidity({ emitEvent: false });
|
|
922
720
|
this.formControl.sdChanges.next(true);
|
|
923
|
-
this.valueModel.set(
|
|
924
|
-
this.sdChange.emit(
|
|
925
|
-
}
|
|
926
|
-
// Xử lý nếu dev sử dụng form và set trực tiếp data
|
|
927
|
-
#onFormGroupExternalChange(html) {
|
|
928
|
-
const v = html ?? '';
|
|
929
|
-
this.valueModel.set(v);
|
|
930
|
-
this._textLength.set(countTextLength(v));
|
|
931
|
-
if (this.#editor) {
|
|
932
|
-
this.#setToEditor(v);
|
|
933
|
-
}
|
|
721
|
+
this.valueModel.set(value);
|
|
722
|
+
this.sdChange.emit(value);
|
|
934
723
|
}
|
|
935
724
|
// Validators
|
|
936
725
|
#requiredValidator() {
|
|
@@ -966,94 +755,6 @@ class SdEditor {
|
|
|
966
755
|
this.formControl.setAsyncValidators(asyncValidators.length ? asyncValidators : null);
|
|
967
756
|
this.formControl.updateValueAndValidity({ emitEvent: false });
|
|
968
757
|
}
|
|
969
|
-
// Setup
|
|
970
|
-
#setupEffects() {
|
|
971
|
-
// Lắng nghe disabled
|
|
972
|
-
effect(() => {
|
|
973
|
-
if (this.disabled()) {
|
|
974
|
-
this.formControl.disable({ emitEvent: false });
|
|
975
|
-
}
|
|
976
|
-
else {
|
|
977
|
-
this.formControl.enable({ emitEvent: false });
|
|
978
|
-
}
|
|
979
|
-
});
|
|
980
|
-
// Lắng nghe readonly
|
|
981
|
-
effect(() => {
|
|
982
|
-
if (!this.#editor) {
|
|
983
|
-
return;
|
|
984
|
-
}
|
|
985
|
-
if (this.readonly()) {
|
|
986
|
-
this.#editor.enableReadOnlyMode('sd-editor-readonly');
|
|
987
|
-
}
|
|
988
|
-
else {
|
|
989
|
-
this.#editor.disableReadOnlyMode('sd-editor-readonly');
|
|
990
|
-
}
|
|
991
|
-
});
|
|
992
|
-
// Lắng nghe binđing 2 chiều model
|
|
993
|
-
effect(() => this.#onModelSignalChange(this.valueModel()));
|
|
994
|
-
// Lắng nghe validators
|
|
995
|
-
effect(() => {
|
|
996
|
-
this.required();
|
|
997
|
-
this.maxlength();
|
|
998
|
-
this.inlineError();
|
|
999
|
-
this.validator();
|
|
1000
|
-
this.#updateValidators();
|
|
1001
|
-
});
|
|
1002
|
-
}
|
|
1003
|
-
#setupSubscriptions() {
|
|
1004
|
-
// Đăng ký nếu dev sử dụng form để set data trực tiếp từ bên ngoài vào
|
|
1005
|
-
this.formControl.valueChanges
|
|
1006
|
-
.pipe(takeUntilDestroyed(this.#destroyRef))
|
|
1007
|
-
.subscribe((val) => this.#onFormGroupExternalChange(val));
|
|
1008
|
-
this.formControl.sdChanges.pipe(takeUntilDestroyed(this.#destroyRef)).subscribe(() => this.#cdRef.markForCheck());
|
|
1009
|
-
// Đăng ký user gõ trong editor
|
|
1010
|
-
this.#contentChangeSubject
|
|
1011
|
-
.pipe(debounceTime(100), takeUntilDestroyed(this.#destroyRef))
|
|
1012
|
-
.subscribe(rawHtml => this.#onEditorUserInput(rawHtml));
|
|
1013
|
-
}
|
|
1014
|
-
#setupDestroy() {
|
|
1015
|
-
this.#destroyRef.onDestroy(() => {
|
|
1016
|
-
this.#editor?.destroy?.();
|
|
1017
|
-
});
|
|
1018
|
-
}
|
|
1019
|
-
// Helpers
|
|
1020
|
-
#uploadImages = async () => {
|
|
1021
|
-
const uploadMode = this.option()?.imageConfig?.uploadMode ?? 'deferred';
|
|
1022
|
-
// Early return nếu không phải 'deferred' mode.
|
|
1023
|
-
// 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.
|
|
1024
|
-
if (uploadMode !== 'deferred')
|
|
1025
|
-
return;
|
|
1026
|
-
const uploadFn = this.#buildUploadFn();
|
|
1027
|
-
if (!uploadFn) {
|
|
1028
|
-
throw new Error('No upload function configured for image upload');
|
|
1029
|
-
}
|
|
1030
|
-
const plugin = this.#editor?.plugins?.get(EditorImageUploadPlugin);
|
|
1031
|
-
if (!plugin || plugin.pendingFiles.size === 0)
|
|
1032
|
-
return;
|
|
1033
|
-
const { batchSize, maxConcurrent } = getBatchConfig(this.option());
|
|
1034
|
-
const activeBlobUrls = this.#editor ? getActiveBlobUrls(this.#editor) : new Set();
|
|
1035
|
-
const toUpload = filterActivePendingFiles(plugin.pendingFiles, activeBlobUrls);
|
|
1036
|
-
// Capture trước await để tránh race condition: ảnh được chèn trong lúc chờ API
|
|
1037
|
-
const processedBlobUrls = new Set(toUpload.map(([blobUrl]) => blobUrl));
|
|
1038
|
-
const { replacements, failedBatches } = await runBatchUploads(toUpload, uploadFn, batchSize, maxConcurrent);
|
|
1039
|
-
if (this.#editor) {
|
|
1040
|
-
const lazyLoad = this.option()?.imageConfig?.lazyLoad ?? true;
|
|
1041
|
-
for (const detail of replacements.values()) {
|
|
1042
|
-
plugin.setMeta(detail.cdn, { name: detail.name, idOrKey: detail.idOrKey, lazyLoad });
|
|
1043
|
-
}
|
|
1044
|
-
applyReplacementsToEditor(this.#editor, replacements);
|
|
1045
|
-
}
|
|
1046
|
-
// Chỉ xóa đúng các entries đã được xử lý
|
|
1047
|
-
for (const blobUrl of processedBlobUrls) {
|
|
1048
|
-
plugin.pendingFiles.delete(blobUrl);
|
|
1049
|
-
}
|
|
1050
|
-
for (const [blobUrl, file] of failedBatches.flat()) {
|
|
1051
|
-
plugin.pendingFiles.set(blobUrl, file);
|
|
1052
|
-
}
|
|
1053
|
-
if (failedBatches.length > 0) {
|
|
1054
|
-
throw new Error(`Upload failed for ${failedBatches.flat().length} image(s)`);
|
|
1055
|
-
}
|
|
1056
|
-
};
|
|
1057
758
|
#getConfigurations = () => {
|
|
1058
759
|
const config = this.#uploadConfig;
|
|
1059
760
|
if (!config) {
|
|
@@ -1088,12 +789,12 @@ class SdEditor {
|
|
|
1088
789
|
return this.option()?.imageConfig?.uploadFn ?? this.#getSelectedConfig()?.upload;
|
|
1089
790
|
};
|
|
1090
791
|
static ɵfac = i0.ɵɵngDeclareFactory({ minVersion: "12.0.0", version: "20.3.25", ngImport: i0, type: SdEditor, deps: [], target: i0.ɵɵFactoryTarget.Component });
|
|
1091
|
-
static ɵcmp = i0.ɵɵngDeclareComponent({ minVersion: "17.0.0", version: "20.3.25", 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: "
|
|
792
|
+
static ɵcmp = i0.ɵɵngDeclareComponent({ minVersion: "17.0.0", version: "20.3.25", 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 });
|
|
1092
793
|
}
|
|
1093
794
|
i0.ɵɵngDeclareClassMetadata({ minVersion: "12.0.0", version: "20.3.25", ngImport: i0, type: SdEditor, decorators: [{
|
|
1094
795
|
type: Component,
|
|
1095
|
-
args: [{ selector: 'sd-editor', standalone: true, changeDetection: ChangeDetectionStrategy.OnPush, imports: [SdIcon,
|
|
1096
|
-
}], 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"] }] } });
|
|
796
|
+
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"] }]
|
|
797
|
+
}], 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"] }] } });
|
|
1097
798
|
|
|
1098
799
|
/**
|
|
1099
800
|
* Generated bundle index. Do not edit.
|