@sd-angular/core 1.2.86 → 1.2.87

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 (33) hide show
  1. package/bundles/sd-angular-core-comment.umd.js +1 -1
  2. package/bundles/sd-angular-core-comment.umd.js.__ivy_ngcc_bak +1 -1
  3. package/bundles/sd-angular-core-comment.umd.js.map +1 -1
  4. package/bundles/sd-angular-core-comment.umd.js.map.__ivy_ngcc_bak +1 -1
  5. package/bundles/sd-angular-core-comment.umd.min.js +1 -1
  6. package/bundles/sd-angular-core-comment.umd.min.js.map +1 -1
  7. package/bundles/sd-angular-core-editor.umd.js +126 -20
  8. package/bundles/sd-angular-core-editor.umd.js.__ivy_ngcc_bak +126 -20
  9. package/bundles/sd-angular-core-editor.umd.js.map +1 -1
  10. package/bundles/sd-angular-core-editor.umd.js.map.__ivy_ngcc_bak +1 -1
  11. package/bundles/sd-angular-core-editor.umd.min.js +2 -2
  12. package/bundles/sd-angular-core-editor.umd.min.js.map +1 -1
  13. package/comment/sd-angular-core-comment.metadata.json +1 -1
  14. package/comment/src/lib/comment.model.d.ts +1 -0
  15. package/editor/sd-angular-core-editor.metadata.json +1 -1
  16. package/editor/src/lib/editor.component.d.ts +14 -4
  17. package/editor/src/lib/editor.model.d.ts +6 -0
  18. package/editor/src/public-api.d.ts +1 -0
  19. package/esm2015/comment/src/lib/comment.component.js +2 -2
  20. package/esm2015/comment/src/lib/comment.model.js +1 -1
  21. package/esm2015/editor/src/lib/editor.component.js +121 -18
  22. package/esm2015/editor/src/lib/editor.model.js +3 -0
  23. package/esm2015/editor/src/public-api.js +2 -1
  24. package/fesm2015/sd-angular-core-comment.js +1 -1
  25. package/fesm2015/sd-angular-core-comment.js.__ivy_ngcc_bak +1 -1
  26. package/fesm2015/sd-angular-core-comment.js.map +1 -1
  27. package/fesm2015/sd-angular-core-comment.js.map.__ivy_ngcc_bak +1 -1
  28. package/fesm2015/sd-angular-core-editor.js +122 -18
  29. package/fesm2015/sd-angular-core-editor.js.__ivy_ngcc_bak +122 -18
  30. package/fesm2015/sd-angular-core-editor.js.map +1 -1
  31. package/fesm2015/sd-angular-core-editor.js.map.__ivy_ngcc_bak +1 -1
  32. package/package.json +1 -1
  33. package/{sd-angular-core-1.2.86.tgz → sd-angular-core-1.2.87.tgz} +0 -0
@@ -1,4 +1,4 @@
1
- import { EventEmitter, Component, ChangeDetectionStrategy, NgZone, ChangeDetectorRef, ViewChild, Input, Output, ContentChild, NgModule } from '@angular/core';
1
+ import { InjectionToken, EventEmitter, Component, ChangeDetectionStrategy, NgZone, ChangeDetectorRef, Inject, Optional, ViewChild, Input, Output, ContentChild, NgModule } from '@angular/core';
2
2
  import { QuillModule } from 'ngx-quill';
3
3
  import { FormControl, Validators, NgForm, FormsModule, ReactiveFormsModule } from '@angular/forms';
4
4
  import { __classPrivateFieldGet, __classPrivateFieldSet } from 'tslib';
@@ -7,11 +7,14 @@ import { Subscription } from 'rxjs';
7
7
  import { SdApiService, SdApiModule } from '@sd-angular/core/api';
8
8
  import 'quill-mention';
9
9
  import { SdLabelDefDirective } from '@sd-angular/core/common';
10
+ import { SdLoadingService } from '@sd-angular/core/loading';
10
11
  import { CommonModule } from '@angular/common';
11
12
  import { SdTranslateModule } from '@sd-angular/core/translate';
12
13
  import { SdButtonModule } from '@sd-angular/core/button';
13
14
  import { SdTextareaModule } from '@sd-angular/core/textarea';
14
15
 
16
+ const EDITOR_CONFIG = new InjectionToken('editor.configuration');
17
+
15
18
  const Constants = {
16
19
  ARE_YOU_WANT_TO_DELETE: 'Are you sure you want to delete?',
17
20
  ACTIVE: 'active',
@@ -117,12 +120,14 @@ const PROMOTION_FORM = {
117
120
  }
118
121
  };
119
122
 
120
- var _name, _subscription, _model, _form, _updateValidator, _uploadImage;
123
+ var _name, _subscription, _model, _form, _updateValidator, _initUploadImage, _uploadImage, _uploadFile;
121
124
  class SdEditor {
122
- constructor(ngZone, ref, sdApiService) {
125
+ constructor(ngZone, ref, sdApiService, loadingService, configuration) {
123
126
  this.ngZone = ngZone;
124
127
  this.ref = ref;
125
128
  this.sdApiService = sdApiService;
129
+ this.loadingService = loadingService;
130
+ this.configuration = configuration;
126
131
  _name.set(this, `N${v4()}`);
127
132
  this.id = `I${v4()}`;
128
133
  _subscription.set(this, new Subscription());
@@ -199,8 +204,37 @@ class SdEditor {
199
204
  }
200
205
  }
201
206
  };
202
- this.textLength = 0;
207
+ this.customButtonFileSVG = '<svg xmlns="http://www.w3.org/2000/svg" enable-background="new 0 0 24 24" height="24px" viewBox="0 0 24 24" width="24px" fill="#000000"><g><rect fill="none" height="24" width="24"/><path d="M20.41,8.41l-4.83-4.83C15.21,3.21,14.7,3,14.17,3H5C3.9,3,3,3.9,3,5v14c0,1.1,0.9,2,2,2h14c1.1,0,2-0.9,2-2V9.83 C21,9.3,20.79,8.79,20.41,8.41z M7,7h7v2H7V7z M17,17H7v-2h10V17z M17,13H7v-2h10V13z"/></g></svg>';
203
208
  this.sdChange = new EventEmitter();
209
+ this.timerLoadQuillToolbar = null;
210
+ this.customFileHandler = (e) => {
211
+ const customButton = e.currentTarget;
212
+ const quillToolbar = customButton.closest('.ql-formats').closest('.ql-toolbar');
213
+ const quillBox = quillToolbar.closest('.ql-formats');
214
+ let fileInput = quillToolbar.querySelector('input.ql-customFile[type=file]');
215
+ if (fileInput == null) {
216
+ fileInput = document.createElement('input');
217
+ fileInput.setAttribute('type', Constants.FILE);
218
+ fileInput.setAttribute('accept', '*');
219
+ fileInput.classList.add('ql-customFile');
220
+ fileInput.addEventListener('change', () => {
221
+ const files = fileInput.files;
222
+ if (!files || !files.length) {
223
+ return;
224
+ }
225
+ const formData = new FormData();
226
+ formData.append(Constants.FILE, files[0]);
227
+ let range = localStorage.getItem('quillRange');
228
+ if (range) {
229
+ range = JSON.parse(range);
230
+ }
231
+ this.quillEvent.enable(false);
232
+ __classPrivateFieldGet(this, _uploadFile).call(this, formData, this.quillEvent, range, fileInput, quillToolbar.closest('quill-editor').id);
233
+ });
234
+ quillToolbar.appendChild(fileInput);
235
+ }
236
+ fileInput.click();
237
+ };
204
238
  _updateValidator.set(this, () => {
205
239
  this.formControl.clearValidators();
206
240
  this.formControl.clearAsyncValidators();
@@ -256,14 +290,6 @@ class SdEditor {
256
290
  const formData = new FormData();
257
291
  formData.append(Constants.FILE, files[0]);
258
292
  this.quill.enable(false);
259
- /*this.apiService.post(this.domain + this.urlUploadImage, formData).subscribe((resp: any) => {
260
- this.quill.enable(true);
261
- this.quill.editor.insertEmbed(range.index, 'image', resp.data.imageUrl || resp.data.publish_url || resp.url);
262
- const content = this.quill.getContents();
263
- this.quill.setContents(content);
264
- this.quill.setSelection(range.index + 1, 'silent');
265
- fileInput.value = '';
266
- });*/
267
293
  __classPrivateFieldGet(self, _uploadImage).call(self, formData, quill, range, fileInput);
268
294
  });
269
295
  this.container.appendChild(fileInput);
@@ -273,6 +299,33 @@ class SdEditor {
273
299
  });
274
300
  this.ref.markForCheck();
275
301
  };
302
+ _initUploadImage.set(this, (quill) => {
303
+ const self = this;
304
+ this.ngZone.runOutsideAngular(() => {
305
+ quill.getModule('toolbar').addHandler('image', function () {
306
+ let fileInput = this.container.querySelector('input.ql-image[type=file]');
307
+ if (fileInput == null) {
308
+ fileInput = document.createElement('input');
309
+ fileInput.setAttribute('type', Constants.FILE);
310
+ fileInput.setAttribute('accept', 'image/png, image/gif, image/jpeg, image/bmp, image/x-icon');
311
+ fileInput.classList.add('ql-image');
312
+ fileInput.addEventListener('change', () => {
313
+ const files = fileInput.files;
314
+ const range = this.quill.getSelection(true);
315
+ if (!files || !files.length) {
316
+ return;
317
+ }
318
+ const formData = new FormData();
319
+ formData.append(Constants.FILE, files[0]);
320
+ this.quill.enable(false);
321
+ __classPrivateFieldGet(self, _uploadImage).call(self, formData, quill, range, fileInput);
322
+ });
323
+ this.container.appendChild(fileInput);
324
+ }
325
+ fileInput.click();
326
+ });
327
+ });
328
+ });
276
329
  this.onModelChange = (val) => {
277
330
  this.formControl.setValue(val);
278
331
  this.modelHTML = val;
@@ -303,6 +356,31 @@ class SdEditor {
303
356
  });
304
357
  this.ref.markForCheck();
305
358
  });
359
+ _uploadFile.set(this, (formData, quill, range, fileInput, loadingID) => {
360
+ if (!this.urlUploadFile) {
361
+ this.urlUploadFile = '/partner/v2/merchandise/file/uploaduserfile';
362
+ }
363
+ // this.domain = 'https://api-commerce-qc.vinid.dev';
364
+ this.loadingService.start('#box-' + loadingID);
365
+ this.sdApiService.post(this.urlUploadFile, formData).then((resp) => {
366
+ this.ngZone.runOutsideAngular(() => {
367
+ var _a, _b, _c, _d;
368
+ quill.enable(true);
369
+ // quill.editor.insertEmbed(range.index, 'image', resp?.data?.imageUrl || resp?.data?.publish_url || resp?.url || '');
370
+ quill.getModule('clipboard').dangerouslyPasteHTML(range.index, '<a target="_blank" href="' + (((_a = resp === null || resp === void 0 ? void 0 : resp.data) === null || _a === void 0 ? void 0 : _a.imageUrl) || ((_b = resp === null || resp === void 0 ? void 0 : resp.data) === null || _b === void 0 ? void 0 : _b.publish_url) || (resp === null || resp === void 0 ? void 0 : resp.url) || '')
371
+ + '">' + (((_c = resp === null || resp === void 0 ? void 0 : resp.data) === null || _c === void 0 ? void 0 : _c.imageUrl) || ((_d = resp === null || resp === void 0 ? void 0 : resp.data) === null || _d === void 0 ? void 0 : _d.publish_url) || (resp === null || resp === void 0 ? void 0 : resp.url) || '') + '</a>', 'user');
372
+ // quill.insertText();
373
+ const content = quill.getContents();
374
+ quill.setContents(content);
375
+ quill.setSelection(range.index + 1, 'user');
376
+ fileInput.value = '';
377
+ });
378
+ this.loadingService.stop('#box-' + loadingID);
379
+ }).catch((er) => {
380
+ this.loadingService.stop('#box-' + loadingID);
381
+ });
382
+ this.ref.markForCheck();
383
+ });
306
384
  }
307
385
  set model(val) {
308
386
  __classPrivateFieldSet(this, _model, val);
@@ -348,7 +426,19 @@ class SdEditor {
348
426
  (_a = __classPrivateFieldGet(this, _form)) === null || _a === void 0 ? void 0 : _a.addControl(__classPrivateFieldGet(this, _name), this.formControl);
349
427
  if (this.toolbar) {
350
428
  this.quillConfig.toolbar.container = this.toolbar;
351
- console.log('toolbar', this.quillConfig);
429
+ }
430
+ if (this.quillConfig.toolbar.container.toString().includes('customFile')) {
431
+ this.timerLoadQuillToolbar = setInterval(() => {
432
+ if (document.querySelector('button.ql-customFile')) {
433
+ clearInterval(this.timerLoadQuillToolbar);
434
+ document.querySelector('button.ql-customFile').innerHTML = this.customButtonFileSVG;
435
+ const customButton = document.querySelector('button.ql-customFile');
436
+ if (customButton.getAttribute('listener') !== '1') {
437
+ customButton.setAttribute('listener', '1');
438
+ customButton.addEventListener('click', this.customFileHandler);
439
+ }
440
+ }
441
+ }, 1000);
352
442
  }
353
443
  this.ref.markForCheck();
354
444
  }
@@ -363,20 +453,32 @@ class SdEditor {
363
453
  (_a = __classPrivateFieldGet(this, _form)) === null || _a === void 0 ? void 0 : _a.removeControl(__classPrivateFieldGet(this, _name));
364
454
  __classPrivateFieldGet(this, _subscription).unsubscribe();
365
455
  }
456
+ onSelectionChanged(e) {
457
+ // localStorage.setItem('quillRange', e.range ? JSON.stringify(e.range) : (e.oldRange ? JSON.stringify(e.oldRange) : null));
458
+ localStorage.setItem('quillRange', e.editor.getSelection() ? JSON.stringify(e.editor.getSelection()) : null);
459
+ }
460
+ onContentChanged(e) {
461
+ localStorage.setItem('quillRange', JSON.stringify({
462
+ index: (e.editor.getLength() ? e.editor.getLength() - 1 : 0),
463
+ length: 0
464
+ }));
465
+ }
366
466
  }
367
- _name = new WeakMap(), _subscription = new WeakMap(), _model = new WeakMap(), _form = new WeakMap(), _updateValidator = new WeakMap(), _uploadImage = new WeakMap();
467
+ _name = new WeakMap(), _subscription = new WeakMap(), _model = new WeakMap(), _form = new WeakMap(), _updateValidator = new WeakMap(), _initUploadImage = new WeakMap(), _uploadImage = new WeakMap(), _uploadFile = new WeakMap();
368
468
  SdEditor.decorators = [
369
469
  { type: Component, args: [{
370
470
  selector: 'sd-editor',
371
- template: "<label *ngIf=\"label && !sdLabelDef?.templateRef\" class=\"d-block T14M\">{{label}} <span class=\"text-danger mb-2\" *ngIf=\"required\">*</span></label>\r\n<ng-container *ngIf=\"sdLabelDef?.templateRef\" matSuffix>\r\n <ng-container *ngTemplateOutlet=\"sdLabelDef.templateRef\">\r\n </ng-container>\r\n</ng-container>\r\n<ng-container *ngIf=\"!formControl.disabled && !showHtmlEditor\">\r\n <quill-editor #editor [styles]=\"styles\" (onEditorCreated)=\"editorInit($event)\" [ngModel]=\"formControl.value\"\r\n (ngModelChange)=\"onModelChange($event)\" [id]=\"id\" [modules]=\"quillConfig\" [placeholder]=\"placeholder\"\r\n [maxLength]=\"maxlength\" >\r\n </quill-editor>\r\n <span class=\"d-block text-danger mt-5\" *ngIf=\"formControl.errors?.required\">\r\n {{'This field is required' | sdTranslate}}\r\n </span>\r\n <span class=\"d-block text-danger mt-5\" *ngIf=\"formControl.errors?.minlength\">\r\n {{'Max length' | sdTranslate}} <strong>{{minlength}}</strong>\r\n </span>\r\n <span class=\"d-block text-danger mt-5\" *ngIf=\"formControl.errors?.maxlength\">\r\n {{'Max length' | sdTranslate}} <strong>{{maxlength}}</strong>\r\n </span>\r\n</ng-container>\r\n<ng-container *ngIf=\"formControl.disabled\">\r\n <div [innerHtml]=\"formControl.value\"></div>\r\n</ng-container>\r\n<ng-container *ngIf=\"enableHTMLButton\">\r\n <sd-textarea [(model)]=\"modelHTML\" *ngIf=\"showHtmlEditor\" rows=\"20\"\r\n (modelChange)=\"onModelChange($event)\"></sd-textarea>\r\n <sd-button\r\n title=\"{{showHtmlEditor?'\u1EA8n':'Hi\u1EC7n'}} m\u00E3 HTML\"\r\n class=\"mr-8\"\r\n fontSet=\"material-icons-outlined\"\r\n (action)=\"onClickShowHtmlEditor()\"\r\n type=\"light\"\r\n ></sd-button>\r\n</ng-container>\r\n",
471
+ template: "<div id=\"box-{{id}}\">\r\n <label *ngIf=\"label && !sdLabelDef?.templateRef\" class=\"d-block T14M\">{{label}} <span class=\"text-danger mb-2\"\r\n *ngIf=\"required\">*</span></label>\r\n <ng-container *ngIf=\"sdLabelDef?.templateRef\" matSuffix>\r\n <ng-container *ngTemplateOutlet=\"sdLabelDef.templateRef\">\r\n </ng-container>\r\n </ng-container>\r\n <ng-container *ngIf=\"!formControl.disabled && !showHtmlEditor\">\r\n <quill-editor #editor [styles]=\"styles\" (onEditorCreated)=\"editorInit($event)\" [ngModel]=\"formControl.value\"\r\n (onSelectionChanged)=\"onSelectionChanged($event)\"\r\n (onContentChanged)=\"onContentChanged($event)\"\r\n (ngModelChange)=\"onModelChange($event)\" [id]=\"id\" [modules]=\"quillConfig\" [placeholder]=\"placeholder\"\r\n [maxLength]=\"maxlength\">\r\n </quill-editor>\r\n <span class=\"d-block text-danger mt-5\" *ngIf=\"formControl.errors?.required\">\r\n {{'This field is required' | sdTranslate}}\r\n </span>\r\n <span class=\"d-block text-danger mt-5\" *ngIf=\"formControl.errors?.minlength\">\r\n {{'Max length' | sdTranslate}} <strong>{{minlength}}</strong>\r\n </span>\r\n <span class=\"d-block text-danger mt-5\" *ngIf=\"formControl.errors?.maxlength\">\r\n {{'Max length' | sdTranslate}} <strong>{{maxlength}}</strong>\r\n </span>\r\n </ng-container>\r\n <ng-container *ngIf=\"formControl.disabled\">\r\n <div [innerHtml]=\"formControl.value\"></div>\r\n </ng-container>\r\n <ng-container *ngIf=\"enableHTMLButton\">\r\n <sd-textarea [(model)]=\"modelHTML\" *ngIf=\"showHtmlEditor\" rows=\"20\"\r\n (modelChange)=\"onModelChange($event)\"></sd-textarea>\r\n <sd-button\r\n title=\"{{showHtmlEditor?'\u1EA8n':'Hi\u1EC7n'}} m\u00E3 HTML\"\r\n class=\"mr-8\"\r\n fontSet=\"material-icons-outlined\"\r\n (action)=\"onClickShowHtmlEditor()\"\r\n type=\"light\"\r\n ></sd-button>\r\n </ng-container>\r\n</div>\r\n",
372
472
  changeDetection: ChangeDetectionStrategy.OnPush,
373
- styles: ["::ng-deep img[alt=c-image-editor-quill]{max-width:80%}"]
473
+ styles: ["::ng-deep img[alt=c-image-editor-quill]{max-width:80%}::ng-deep .ql-toolbar input.ql-customFile[type=file]{display:none}"]
374
474
  },] }
375
475
  ];
376
476
  SdEditor.ctorParameters = () => [
377
477
  { type: NgZone },
378
478
  { type: ChangeDetectorRef },
379
- { type: SdApiService }
479
+ { type: SdApiService },
480
+ { type: SdLoadingService },
481
+ { type: undefined, decorators: [{ type: Inject, args: [EDITOR_CONFIG,] }, { type: Optional }] }
380
482
  ];
381
483
  SdEditor.propDecorators = {
382
484
  editor: [{ type: ViewChild, args: ['editor',] }],
@@ -389,8 +491,10 @@ SdEditor.propDecorators = {
389
491
  modelChange: [{ type: Output }],
390
492
  placeholder: [{ type: Input }],
391
493
  styles: [{ type: Input }],
494
+ args: [{ type: Input }],
392
495
  domain: [{ type: Input }],
393
496
  urlUploadImage: [{ type: Input }],
497
+ urlUploadFile: [{ type: Input }],
394
498
  form: [{ type: Input }],
395
499
  toolbar: [{ type: Input }],
396
500
  enableHTMLButton: [{ type: Input }],
@@ -428,6 +532,6 @@ SdEditorModule.decorators = [
428
532
  * Generated bundle index. Do not edit.
429
533
  */
430
534
 
431
- export { Constants, PROMOTION_FORM, PROMOTION_PERMISSIONS, SdEditor, SdEditorModule, ValidateMessageConstants };
535
+ export { Constants, EDITOR_CONFIG, PROMOTION_FORM, PROMOTION_PERMISSIONS, SdEditor, SdEditorModule, ValidateMessageConstants };
432
536
 
433
537
  //# sourceMappingURL=sd-angular-core-editor.js.map
@@ -1,4 +1,4 @@
1
- import { EventEmitter, Component, ChangeDetectionStrategy, NgZone, ChangeDetectorRef, ViewChild, Input, Output, ContentChild, NgModule } from '@angular/core';
1
+ import { InjectionToken, EventEmitter, Component, ChangeDetectionStrategy, NgZone, ChangeDetectorRef, Inject, Optional, ViewChild, Input, Output, ContentChild, NgModule } from '@angular/core';
2
2
  import { QuillModule } from 'ngx-quill';
3
3
  import { FormControl, Validators, NgForm, FormsModule, ReactiveFormsModule } from '@angular/forms';
4
4
  import { __classPrivateFieldGet, __classPrivateFieldSet } from 'tslib';
@@ -7,11 +7,14 @@ import { Subscription } from 'rxjs';
7
7
  import { SdApiService, SdApiModule } from '@sd-angular/core/api';
8
8
  import 'quill-mention';
9
9
  import { SdLabelDefDirective } from '@sd-angular/core/common';
10
+ import { SdLoadingService } from '@sd-angular/core/loading';
10
11
  import { CommonModule } from '@angular/common';
11
12
  import { SdTranslateModule } from '@sd-angular/core/translate';
12
13
  import { SdButtonModule } from '@sd-angular/core/button';
13
14
  import { SdTextareaModule } from '@sd-angular/core/textarea';
14
15
 
16
+ const EDITOR_CONFIG = new InjectionToken('editor.configuration');
17
+
15
18
  const Constants = {
16
19
  ARE_YOU_WANT_TO_DELETE: 'Are you sure you want to delete?',
17
20
  ACTIVE: 'active',
@@ -117,12 +120,14 @@ const PROMOTION_FORM = {
117
120
  }
118
121
  };
119
122
 
120
- var _name, _subscription, _model, _form, _updateValidator, _uploadImage;
123
+ var _name, _subscription, _model, _form, _updateValidator, _initUploadImage, _uploadImage, _uploadFile;
121
124
  class SdEditor {
122
- constructor(ngZone, ref, sdApiService) {
125
+ constructor(ngZone, ref, sdApiService, loadingService, configuration) {
123
126
  this.ngZone = ngZone;
124
127
  this.ref = ref;
125
128
  this.sdApiService = sdApiService;
129
+ this.loadingService = loadingService;
130
+ this.configuration = configuration;
126
131
  _name.set(this, `N${v4()}`);
127
132
  this.id = `I${v4()}`;
128
133
  _subscription.set(this, new Subscription());
@@ -199,8 +204,37 @@ class SdEditor {
199
204
  }
200
205
  }
201
206
  };
202
- this.textLength = 0;
207
+ this.customButtonFileSVG = '<svg xmlns="http://www.w3.org/2000/svg" enable-background="new 0 0 24 24" height="24px" viewBox="0 0 24 24" width="24px" fill="#000000"><g><rect fill="none" height="24" width="24"/><path d="M20.41,8.41l-4.83-4.83C15.21,3.21,14.7,3,14.17,3H5C3.9,3,3,3.9,3,5v14c0,1.1,0.9,2,2,2h14c1.1,0,2-0.9,2-2V9.83 C21,9.3,20.79,8.79,20.41,8.41z M7,7h7v2H7V7z M17,17H7v-2h10V17z M17,13H7v-2h10V13z"/></g></svg>';
203
208
  this.sdChange = new EventEmitter();
209
+ this.timerLoadQuillToolbar = null;
210
+ this.customFileHandler = (e) => {
211
+ const customButton = e.currentTarget;
212
+ const quillToolbar = customButton.closest('.ql-formats').closest('.ql-toolbar');
213
+ const quillBox = quillToolbar.closest('.ql-formats');
214
+ let fileInput = quillToolbar.querySelector('input.ql-customFile[type=file]');
215
+ if (fileInput == null) {
216
+ fileInput = document.createElement('input');
217
+ fileInput.setAttribute('type', Constants.FILE);
218
+ fileInput.setAttribute('accept', '*');
219
+ fileInput.classList.add('ql-customFile');
220
+ fileInput.addEventListener('change', () => {
221
+ const files = fileInput.files;
222
+ if (!files || !files.length) {
223
+ return;
224
+ }
225
+ const formData = new FormData();
226
+ formData.append(Constants.FILE, files[0]);
227
+ let range = localStorage.getItem('quillRange');
228
+ if (range) {
229
+ range = JSON.parse(range);
230
+ }
231
+ this.quillEvent.enable(false);
232
+ __classPrivateFieldGet(this, _uploadFile).call(this, formData, this.quillEvent, range, fileInput, quillToolbar.closest('quill-editor').id);
233
+ });
234
+ quillToolbar.appendChild(fileInput);
235
+ }
236
+ fileInput.click();
237
+ };
204
238
  _updateValidator.set(this, () => {
205
239
  this.formControl.clearValidators();
206
240
  this.formControl.clearAsyncValidators();
@@ -256,14 +290,6 @@ class SdEditor {
256
290
  const formData = new FormData();
257
291
  formData.append(Constants.FILE, files[0]);
258
292
  this.quill.enable(false);
259
- /*this.apiService.post(this.domain + this.urlUploadImage, formData).subscribe((resp: any) => {
260
- this.quill.enable(true);
261
- this.quill.editor.insertEmbed(range.index, 'image', resp.data.imageUrl || resp.data.publish_url || resp.url);
262
- const content = this.quill.getContents();
263
- this.quill.setContents(content);
264
- this.quill.setSelection(range.index + 1, 'silent');
265
- fileInput.value = '';
266
- });*/
267
293
  __classPrivateFieldGet(self, _uploadImage).call(self, formData, quill, range, fileInput);
268
294
  });
269
295
  this.container.appendChild(fileInput);
@@ -273,6 +299,33 @@ class SdEditor {
273
299
  });
274
300
  this.ref.markForCheck();
275
301
  };
302
+ _initUploadImage.set(this, (quill) => {
303
+ const self = this;
304
+ this.ngZone.runOutsideAngular(() => {
305
+ quill.getModule('toolbar').addHandler('image', function () {
306
+ let fileInput = this.container.querySelector('input.ql-image[type=file]');
307
+ if (fileInput == null) {
308
+ fileInput = document.createElement('input');
309
+ fileInput.setAttribute('type', Constants.FILE);
310
+ fileInput.setAttribute('accept', 'image/png, image/gif, image/jpeg, image/bmp, image/x-icon');
311
+ fileInput.classList.add('ql-image');
312
+ fileInput.addEventListener('change', () => {
313
+ const files = fileInput.files;
314
+ const range = this.quill.getSelection(true);
315
+ if (!files || !files.length) {
316
+ return;
317
+ }
318
+ const formData = new FormData();
319
+ formData.append(Constants.FILE, files[0]);
320
+ this.quill.enable(false);
321
+ __classPrivateFieldGet(self, _uploadImage).call(self, formData, quill, range, fileInput);
322
+ });
323
+ this.container.appendChild(fileInput);
324
+ }
325
+ fileInput.click();
326
+ });
327
+ });
328
+ });
276
329
  this.onModelChange = (val) => {
277
330
  this.formControl.setValue(val);
278
331
  this.modelHTML = val;
@@ -303,6 +356,31 @@ class SdEditor {
303
356
  });
304
357
  this.ref.markForCheck();
305
358
  });
359
+ _uploadFile.set(this, (formData, quill, range, fileInput, loadingID) => {
360
+ if (!this.urlUploadFile) {
361
+ this.urlUploadFile = '/partner/v2/merchandise/file/uploaduserfile';
362
+ }
363
+ // this.domain = 'https://api-commerce-qc.vinid.dev';
364
+ this.loadingService.start('#box-' + loadingID);
365
+ this.sdApiService.post(this.urlUploadFile, formData).then((resp) => {
366
+ this.ngZone.runOutsideAngular(() => {
367
+ var _a, _b, _c, _d;
368
+ quill.enable(true);
369
+ // quill.editor.insertEmbed(range.index, 'image', resp?.data?.imageUrl || resp?.data?.publish_url || resp?.url || '');
370
+ quill.getModule('clipboard').dangerouslyPasteHTML(range.index, '<a target="_blank" href="' + (((_a = resp === null || resp === void 0 ? void 0 : resp.data) === null || _a === void 0 ? void 0 : _a.imageUrl) || ((_b = resp === null || resp === void 0 ? void 0 : resp.data) === null || _b === void 0 ? void 0 : _b.publish_url) || (resp === null || resp === void 0 ? void 0 : resp.url) || '')
371
+ + '">' + (((_c = resp === null || resp === void 0 ? void 0 : resp.data) === null || _c === void 0 ? void 0 : _c.imageUrl) || ((_d = resp === null || resp === void 0 ? void 0 : resp.data) === null || _d === void 0 ? void 0 : _d.publish_url) || (resp === null || resp === void 0 ? void 0 : resp.url) || '') + '</a>', 'user');
372
+ // quill.insertText();
373
+ const content = quill.getContents();
374
+ quill.setContents(content);
375
+ quill.setSelection(range.index + 1, 'user');
376
+ fileInput.value = '';
377
+ });
378
+ this.loadingService.stop('#box-' + loadingID);
379
+ }).catch((er) => {
380
+ this.loadingService.stop('#box-' + loadingID);
381
+ });
382
+ this.ref.markForCheck();
383
+ });
306
384
  }
307
385
  set model(val) {
308
386
  __classPrivateFieldSet(this, _model, val);
@@ -348,7 +426,19 @@ class SdEditor {
348
426
  (_a = __classPrivateFieldGet(this, _form)) === null || _a === void 0 ? void 0 : _a.addControl(__classPrivateFieldGet(this, _name), this.formControl);
349
427
  if (this.toolbar) {
350
428
  this.quillConfig.toolbar.container = this.toolbar;
351
- console.log('toolbar', this.quillConfig);
429
+ }
430
+ if (this.quillConfig.toolbar.container.toString().includes('customFile')) {
431
+ this.timerLoadQuillToolbar = setInterval(() => {
432
+ if (document.querySelector('button.ql-customFile')) {
433
+ clearInterval(this.timerLoadQuillToolbar);
434
+ document.querySelector('button.ql-customFile').innerHTML = this.customButtonFileSVG;
435
+ const customButton = document.querySelector('button.ql-customFile');
436
+ if (customButton.getAttribute('listener') !== '1') {
437
+ customButton.setAttribute('listener', '1');
438
+ customButton.addEventListener('click', this.customFileHandler);
439
+ }
440
+ }
441
+ }, 1000);
352
442
  }
353
443
  this.ref.markForCheck();
354
444
  }
@@ -363,20 +453,32 @@ class SdEditor {
363
453
  (_a = __classPrivateFieldGet(this, _form)) === null || _a === void 0 ? void 0 : _a.removeControl(__classPrivateFieldGet(this, _name));
364
454
  __classPrivateFieldGet(this, _subscription).unsubscribe();
365
455
  }
456
+ onSelectionChanged(e) {
457
+ // localStorage.setItem('quillRange', e.range ? JSON.stringify(e.range) : (e.oldRange ? JSON.stringify(e.oldRange) : null));
458
+ localStorage.setItem('quillRange', e.editor.getSelection() ? JSON.stringify(e.editor.getSelection()) : null);
459
+ }
460
+ onContentChanged(e) {
461
+ localStorage.setItem('quillRange', JSON.stringify({
462
+ index: (e.editor.getLength() ? e.editor.getLength() - 1 : 0),
463
+ length: 0
464
+ }));
465
+ }
366
466
  }
367
- _name = new WeakMap(), _subscription = new WeakMap(), _model = new WeakMap(), _form = new WeakMap(), _updateValidator = new WeakMap(), _uploadImage = new WeakMap();
467
+ _name = new WeakMap(), _subscription = new WeakMap(), _model = new WeakMap(), _form = new WeakMap(), _updateValidator = new WeakMap(), _initUploadImage = new WeakMap(), _uploadImage = new WeakMap(), _uploadFile = new WeakMap();
368
468
  SdEditor.decorators = [
369
469
  { type: Component, args: [{
370
470
  selector: 'sd-editor',
371
- template: "<label *ngIf=\"label && !sdLabelDef?.templateRef\" class=\"d-block T14M\">{{label}} <span class=\"text-danger mb-2\" *ngIf=\"required\">*</span></label>\r\n<ng-container *ngIf=\"sdLabelDef?.templateRef\" matSuffix>\r\n <ng-container *ngTemplateOutlet=\"sdLabelDef.templateRef\">\r\n </ng-container>\r\n</ng-container>\r\n<ng-container *ngIf=\"!formControl.disabled && !showHtmlEditor\">\r\n <quill-editor #editor [styles]=\"styles\" (onEditorCreated)=\"editorInit($event)\" [ngModel]=\"formControl.value\"\r\n (ngModelChange)=\"onModelChange($event)\" [id]=\"id\" [modules]=\"quillConfig\" [placeholder]=\"placeholder\"\r\n [maxLength]=\"maxlength\" >\r\n </quill-editor>\r\n <span class=\"d-block text-danger mt-5\" *ngIf=\"formControl.errors?.required\">\r\n {{'This field is required' | sdTranslate}}\r\n </span>\r\n <span class=\"d-block text-danger mt-5\" *ngIf=\"formControl.errors?.minlength\">\r\n {{'Max length' | sdTranslate}} <strong>{{minlength}}</strong>\r\n </span>\r\n <span class=\"d-block text-danger mt-5\" *ngIf=\"formControl.errors?.maxlength\">\r\n {{'Max length' | sdTranslate}} <strong>{{maxlength}}</strong>\r\n </span>\r\n</ng-container>\r\n<ng-container *ngIf=\"formControl.disabled\">\r\n <div [innerHtml]=\"formControl.value\"></div>\r\n</ng-container>\r\n<ng-container *ngIf=\"enableHTMLButton\">\r\n <sd-textarea [(model)]=\"modelHTML\" *ngIf=\"showHtmlEditor\" rows=\"20\"\r\n (modelChange)=\"onModelChange($event)\"></sd-textarea>\r\n <sd-button\r\n title=\"{{showHtmlEditor?'\u1EA8n':'Hi\u1EC7n'}} m\u00E3 HTML\"\r\n class=\"mr-8\"\r\n fontSet=\"material-icons-outlined\"\r\n (action)=\"onClickShowHtmlEditor()\"\r\n type=\"light\"\r\n ></sd-button>\r\n</ng-container>\r\n",
471
+ template: "<div id=\"box-{{id}}\">\r\n <label *ngIf=\"label && !sdLabelDef?.templateRef\" class=\"d-block T14M\">{{label}} <span class=\"text-danger mb-2\"\r\n *ngIf=\"required\">*</span></label>\r\n <ng-container *ngIf=\"sdLabelDef?.templateRef\" matSuffix>\r\n <ng-container *ngTemplateOutlet=\"sdLabelDef.templateRef\">\r\n </ng-container>\r\n </ng-container>\r\n <ng-container *ngIf=\"!formControl.disabled && !showHtmlEditor\">\r\n <quill-editor #editor [styles]=\"styles\" (onEditorCreated)=\"editorInit($event)\" [ngModel]=\"formControl.value\"\r\n (onSelectionChanged)=\"onSelectionChanged($event)\"\r\n (onContentChanged)=\"onContentChanged($event)\"\r\n (ngModelChange)=\"onModelChange($event)\" [id]=\"id\" [modules]=\"quillConfig\" [placeholder]=\"placeholder\"\r\n [maxLength]=\"maxlength\">\r\n </quill-editor>\r\n <span class=\"d-block text-danger mt-5\" *ngIf=\"formControl.errors?.required\">\r\n {{'This field is required' | sdTranslate}}\r\n </span>\r\n <span class=\"d-block text-danger mt-5\" *ngIf=\"formControl.errors?.minlength\">\r\n {{'Max length' | sdTranslate}} <strong>{{minlength}}</strong>\r\n </span>\r\n <span class=\"d-block text-danger mt-5\" *ngIf=\"formControl.errors?.maxlength\">\r\n {{'Max length' | sdTranslate}} <strong>{{maxlength}}</strong>\r\n </span>\r\n </ng-container>\r\n <ng-container *ngIf=\"formControl.disabled\">\r\n <div [innerHtml]=\"formControl.value\"></div>\r\n </ng-container>\r\n <ng-container *ngIf=\"enableHTMLButton\">\r\n <sd-textarea [(model)]=\"modelHTML\" *ngIf=\"showHtmlEditor\" rows=\"20\"\r\n (modelChange)=\"onModelChange($event)\"></sd-textarea>\r\n <sd-button\r\n title=\"{{showHtmlEditor?'\u1EA8n':'Hi\u1EC7n'}} m\u00E3 HTML\"\r\n class=\"mr-8\"\r\n fontSet=\"material-icons-outlined\"\r\n (action)=\"onClickShowHtmlEditor()\"\r\n type=\"light\"\r\n ></sd-button>\r\n </ng-container>\r\n</div>\r\n",
372
472
  changeDetection: ChangeDetectionStrategy.OnPush,
373
- styles: ["::ng-deep img[alt=c-image-editor-quill]{max-width:80%}"]
473
+ styles: ["::ng-deep img[alt=c-image-editor-quill]{max-width:80%}::ng-deep .ql-toolbar input.ql-customFile[type=file]{display:none}"]
374
474
  },] }
375
475
  ];
376
476
  SdEditor.ctorParameters = () => [
377
477
  { type: NgZone },
378
478
  { type: ChangeDetectorRef },
379
- { type: SdApiService }
479
+ { type: SdApiService },
480
+ { type: SdLoadingService },
481
+ { type: undefined, decorators: [{ type: Inject, args: [EDITOR_CONFIG,] }, { type: Optional }] }
380
482
  ];
381
483
  SdEditor.propDecorators = {
382
484
  editor: [{ type: ViewChild, args: ['editor',] }],
@@ -389,8 +491,10 @@ SdEditor.propDecorators = {
389
491
  modelChange: [{ type: Output }],
390
492
  placeholder: [{ type: Input }],
391
493
  styles: [{ type: Input }],
494
+ args: [{ type: Input }],
392
495
  domain: [{ type: Input }],
393
496
  urlUploadImage: [{ type: Input }],
497
+ urlUploadFile: [{ type: Input }],
394
498
  form: [{ type: Input }],
395
499
  toolbar: [{ type: Input }],
396
500
  enableHTMLButton: [{ type: Input }],
@@ -428,5 +532,5 @@ SdEditorModule.decorators = [
428
532
  * Generated bundle index. Do not edit.
429
533
  */
430
534
 
431
- export { Constants, PROMOTION_FORM, PROMOTION_PERMISSIONS, SdEditor, SdEditorModule, ValidateMessageConstants };
535
+ export { Constants, EDITOR_CONFIG, PROMOTION_FORM, PROMOTION_PERMISSIONS, SdEditor, SdEditorModule, ValidateMessageConstants };
432
536
  //# sourceMappingURL=sd-angular-core-editor.js.map