@firestitch/html-editor 9.5.4 → 9.5.7

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.
@@ -15,6 +15,7 @@ export declare class FsHtmlEditorComponent implements OnInit, AfterViewInit, Con
15
15
  private _editor;
16
16
  private _html;
17
17
  private _initialize$;
18
+ private _froalaReady$;
18
19
  private _destroy$;
19
20
  constructor(_defaultConfig: any, _cdRef: ChangeDetectorRef, _fr: FsFroalaLoaderService);
20
21
  onChange: (data: any) => void;
@@ -22,7 +23,7 @@ export declare class FsHtmlEditorComponent implements OnInit, AfterViewInit, Con
22
23
  readonly el: any;
23
24
  readonly html: string;
24
25
  readonly editor: any;
25
- readonly froalaReady$: Observable<boolean>;
26
+ readonly froalaLoaded$: Observable<boolean>;
26
27
  ngOnInit(): void;
27
28
  ngAfterViewInit(): void;
28
29
  hasContent(): boolean;
@@ -49,4 +50,5 @@ export declare class FsHtmlEditorComponent implements OnInit, AfterViewInit, Con
49
50
  private _createOptions;
50
51
  private _listenLazyInit;
51
52
  private _contentChanged;
53
+ private _setupFroala;
52
54
  }
@@ -5,9 +5,9 @@ export declare class FsFroalaLoaderService {
5
5
  private _FroalaEditor;
6
6
  private _froalaLoaded;
7
7
  private _defaultPluginsLoaded;
8
- private _ready$;
8
+ private _loaded$;
9
9
  constructor(_defaultConfig: FsHtmlEditorConfig);
10
- readonly ready$: Observable<boolean>;
10
+ readonly loaded$: Observable<boolean>;
11
11
  readonly ready: boolean;
12
12
  readonly FroalaEditor: any;
13
13
  private _load;
@@ -370,7 +370,7 @@
370
370
  this._defaultConfig = _defaultConfig;
371
371
  this._froalaLoaded = new rxjs.BehaviorSubject(false);
372
372
  this._defaultPluginsLoaded = new rxjs.BehaviorSubject(false);
373
- this._ready$ = rxjs.combineLatest([this._froalaLoaded, this._defaultPluginsLoaded])
373
+ this._loaded$ = rxjs.combineLatest([this._froalaLoaded, this._defaultPluginsLoaded])
374
374
  .pipe(operators.map(function (_a) {
375
375
  var _b = __read(_a, 2), FroalaReady = _b[0], pluginsRead = _b[1];
376
376
  return pluginsRead && FroalaReady;
@@ -385,9 +385,9 @@
385
385
  }
386
386
  this._load();
387
387
  }
388
- Object.defineProperty(FsFroalaLoaderService.prototype, "ready$", {
388
+ Object.defineProperty(FsFroalaLoaderService.prototype, "loaded$", {
389
389
  get: function () {
390
- return this._ready$;
390
+ return this._loaded$;
391
391
  },
392
392
  enumerable: true,
393
393
  configurable: true
@@ -462,6 +462,7 @@
462
462
  this.config = {};
463
463
  this.initialized = false;
464
464
  this._initialize$ = new rxjs.ReplaySubject();
465
+ this._froalaReady$ = new rxjs.BehaviorSubject(null);
465
466
  this._destroy$ = new rxjs.Subject();
466
467
  this.onChange = function (data) { };
467
468
  this.onTouched = function () { };
@@ -488,9 +489,9 @@
488
489
  enumerable: true,
489
490
  configurable: true
490
491
  });
491
- Object.defineProperty(FsHtmlEditorComponent.prototype, "froalaReady$", {
492
+ Object.defineProperty(FsHtmlEditorComponent.prototype, "froalaLoaded$", {
492
493
  get: function () {
493
- return this._fr.ready$;
494
+ return this._fr.loaded$;
494
495
  },
495
496
  enumerable: true,
496
497
  configurable: true
@@ -520,94 +521,9 @@
520
521
  if (options === void 0) { options = {}; }
521
522
  var config = this._createConfig();
522
523
  this._initPlugins(config);
523
- this.el.innerHTML = this._html;
524
+ // this.el.innerHTML = this._html || '';
524
525
  this._editor = new this._fr.FroalaEditor(this.el, this._createOptions(), function () {
525
- _this._cdRef.markForCheck();
526
- if (config.disabled) {
527
- _this.disable();
528
- }
529
- if (config.froalaConfig.events) {
530
- if (config.froalaConfig.events.initialized) {
531
- config.froalaConfig.events.initialized();
532
- }
533
- }
534
- _this._editor.events.on('focus', function () {
535
- _this.classFocused = true;
536
- _this._cdRef.markForCheck();
537
- });
538
- _this._editor.events.on('blur', function () {
539
- _this.classFocused = false;
540
- _this._cdRef.markForCheck();
541
- });
542
- _this._editor.events.on('contentChanged', function () {
543
- _this._contentChanged();
544
- });
545
- _this._editor.events.on('paste.afterCleanup', function (html) {
546
- var div = document.createElement('div');
547
- div.innerHTML = html;
548
- div.querySelectorAll('*')
549
- .forEach(function (el) {
550
- for (var i = 0; i < el.attributes.length; i++) {
551
- var name_1 = el.attributes[0].name;
552
- if (name_1 !== 'href') {
553
- el.removeAttribute(name_1);
554
- }
555
- }
556
- });
557
- return div.innerHTML;
558
- });
559
- _this._editor.events.on('keydown', function () {
560
- _this.onTouched();
561
- });
562
- if (_this.config.image && _this.config.image.upload) {
563
- _this._editor.events.on('image.beforePasteUpload', function (image) {
564
- fetch(image.getAttribute('src'))
565
- .then(function (res) {
566
- res.blob()
567
- .then(function (blob) {
568
- _this._processImageUpload(blob)
569
- .pipe(operators.takeUntil(_this._destroy$))
570
- .subscribe(function (url) {
571
- image.setAttribute('src', url);
572
- image.removeAttribute('data-fr-image-pasted');
573
- _this._contentChanged();
574
- });
575
- });
576
- });
577
- return false;
578
- });
579
- _this._editor.events.on('image.beforeUpload', function (blobs) {
580
- _this._processImageUpload(blobs[0])
581
- .pipe(operators.takeUntil(_this._destroy$))
582
- .subscribe(function (url) {
583
- _this.editor.image.insert(url, null, null, _this.editor.image.get());
584
- });
585
- return false;
586
- });
587
- }
588
- if (_this.el.querySelector('.fr-second-toolbar')) {
589
- _this.el.querySelector('.fr-second-toolbar').remove();
590
- }
591
- var selection = options.selection;
592
- if (selection) {
593
- var node = Array.from(_this.el.querySelectorAll('.fr-element *')).find(function (node) {
594
- return selection.node === node.textContent;
595
- });
596
- if (node) {
597
- var range = document.createRange();
598
- var sel = window.getSelection();
599
- range.setStart(_this._getTextNode(node), selection.offset);
600
- range.collapse(true);
601
- sel.removeAllRanges();
602
- sel.addRange(range);
603
- }
604
- else if (_this.config.autofocus) {
605
- _this.focus();
606
- }
607
- }
608
- else if (_this.config.autofocus) {
609
- _this.focus();
610
- }
526
+ _this._froalaReady$.next({ config: config, options: options });
611
527
  });
612
528
  };
613
529
  FsHtmlEditorComponent.prototype._processImageUpload = function (blob) {
@@ -693,23 +609,15 @@
693
609
  this.writeValue(html);
694
610
  };
695
611
  FsHtmlEditorComponent.prototype.writeValue = function (html) {
696
- var _this = this;
697
612
  this._html = html || '';
698
- this._cdRef.markForCheck();
699
- // SP-T2298 timeout needed for the case, when froala was already initated and
700
- // second instance opened in dialog/drawer. In this case init step pass much faster, writeValue trigger
701
- // after init and froala ignore new html. At the same time froala was initied but editor not yet, and next
702
- // code doesn't work without timeout. We've got time range when too late for initiate value, and to early
703
- // for change event.
704
- setTimeout(function () {
705
- if (_this.editor && _this.editor.html) {
706
- try {
707
- _this.editor.html.set(_this._html);
708
- }
709
- catch (e) {
710
- }
613
+ if (this.editor && this.editor.html) {
614
+ try {
615
+ this.editor.html.set(this._html);
711
616
  }
712
- });
617
+ catch (e) {
618
+ }
619
+ }
620
+ this._cdRef.markForCheck();
713
621
  };
714
622
  FsHtmlEditorComponent.prototype.registerOnChange = function (fn) {
715
623
  this.onChange = fn;
@@ -735,7 +643,7 @@
735
643
  return lodashEs.merge({ froalaConfig: {} }, this._defaultConfig, this.config);
736
644
  };
737
645
  FsHtmlEditorComponent.prototype._change = function (html) {
738
- this._html = html;
646
+ // this._html = html;
739
647
  this.onChange(html);
740
648
  };
741
649
  FsHtmlEditorComponent.prototype._initPlugins = function (config) {
@@ -831,9 +739,8 @@
831
739
  };
832
740
  FsHtmlEditorComponent.prototype._listenLazyInit = function () {
833
741
  var _this = this;
834
- this.froalaReady$
835
- .pipe(operators.filter(function (ready) { return ready; }), operators.switchMap(function () { return _this._initialize$; }))
836
- .subscribe(function () {
742
+ this.froalaLoaded$
743
+ .pipe(operators.filter(function (ready) { return ready; }), operators.switchMap(function () { return _this._initialize$; }), operators.tap(function () {
837
744
  var selection = window.getSelection();
838
745
  var options = {};
839
746
  if (selection.baseNode) {
@@ -843,7 +750,11 @@
843
750
  };
844
751
  }
845
752
  _this.initialize(options);
846
- });
753
+ }), operators.switchMap(function () { return _this._froalaReady$; }), operators.filter(function (data) { return !!data; }), operators.tap(function (_a) {
754
+ var config = _a.config, options = _a.options;
755
+ _this._setupFroala(config, options);
756
+ }))
757
+ .subscribe();
847
758
  };
848
759
  FsHtmlEditorComponent.prototype._contentChanged = function () {
849
760
  var editorHTML = this._editor.html.get();
@@ -851,6 +762,106 @@
851
762
  this._change(editorHTML);
852
763
  }
853
764
  };
765
+ FsHtmlEditorComponent.prototype._setupFroala = function (config, options) {
766
+ var _this = this;
767
+ this._cdRef.markForCheck();
768
+ this.setHtml(this._html);
769
+ if (config.disabled) {
770
+ this.disable();
771
+ }
772
+ if (config.froalaConfig.events) {
773
+ if (config.froalaConfig.events.initialized) {
774
+ config.froalaConfig.events.initialized();
775
+ }
776
+ }
777
+ this._editor.events.on('focus', function () {
778
+ _this.classFocused = true;
779
+ _this._cdRef.markForCheck();
780
+ });
781
+ this._editor.events.on('blur', function () {
782
+ _this.classFocused = false;
783
+ _this._cdRef.markForCheck();
784
+ });
785
+ rxjs.fromEventPattern(function (handler) {
786
+ _this._editor.events.on('contentChanged', handler);
787
+ }, function () { })
788
+ .pipe(operators.startWith(this._html), operators.map(function () { return _this.editor.html.get(); }), operators.distinctUntilChanged(), operators.skip(1))
789
+ .subscribe(function () {
790
+ _this._contentChanged();
791
+ });
792
+ // this._editor.events.on('contentChanged', () => {
793
+ // console.log('test');
794
+ // if (!this._firstChange) {
795
+ // this._contentChanged();
796
+ // }
797
+ // });
798
+ this._editor.events.on('paste.afterCleanup', function (html) {
799
+ var div = document.createElement('div');
800
+ div.innerHTML = html;
801
+ div.querySelectorAll('*')
802
+ .forEach(function (el) {
803
+ for (var i = 0; i < el.attributes.length; i++) {
804
+ var name_1 = el.attributes[0].name;
805
+ if (name_1 !== 'href') {
806
+ el.removeAttribute(name_1);
807
+ }
808
+ }
809
+ });
810
+ return div.innerHTML;
811
+ });
812
+ this._editor.events.on('keydown', function () {
813
+ _this.onTouched();
814
+ });
815
+ if (this.config.image && this.config.image.upload) {
816
+ this._editor.events.on('image.beforePasteUpload', function (image) {
817
+ fetch(image.getAttribute('src'))
818
+ .then(function (res) {
819
+ res.blob()
820
+ .then(function (blob) {
821
+ _this._processImageUpload(blob)
822
+ .pipe(operators.takeUntil(_this._destroy$))
823
+ .subscribe(function (url) {
824
+ image.setAttribute('src', url);
825
+ image.removeAttribute('data-fr-image-pasted');
826
+ _this._contentChanged();
827
+ });
828
+ });
829
+ });
830
+ return false;
831
+ });
832
+ this._editor.events.on('image.beforeUpload', function (blobs) {
833
+ _this._processImageUpload(blobs[0])
834
+ .pipe(operators.takeUntil(_this._destroy$))
835
+ .subscribe(function (url) {
836
+ _this.editor.image.insert(url, null, null, _this.editor.image.get());
837
+ });
838
+ return false;
839
+ });
840
+ }
841
+ if (this.el.querySelector('.fr-second-toolbar')) {
842
+ this.el.querySelector('.fr-second-toolbar').remove();
843
+ }
844
+ var selection = options.selection;
845
+ if (selection) {
846
+ var node = Array.from(this.el.querySelectorAll('.fr-element *')).find(function (node) {
847
+ return selection.node === node.textContent;
848
+ });
849
+ if (node) {
850
+ var range = document.createRange();
851
+ var sel = window.getSelection();
852
+ range.setStart(this._getTextNode(node), selection.offset);
853
+ range.collapse(true);
854
+ sel.removeAllRanges();
855
+ sel.addRange(range);
856
+ }
857
+ else if (this.config.autofocus) {
858
+ this.focus();
859
+ }
860
+ }
861
+ else if (this.config.autofocus) {
862
+ this.focus();
863
+ }
864
+ };
854
865
  var FsHtmlEditorComponent_1;
855
866
  FsHtmlEditorComponent.ctorParameters = function () { return [
856
867
  { type: undefined, decorators: [{ type: core.Optional }, { type: core.Inject, args: [FS_HTML_EDITOR_CONFIG,] }] },
@@ -876,7 +887,7 @@
876
887
  FsHtmlEditorComponent = FsHtmlEditorComponent_1 = __decorate([
877
888
  core.Component({
878
889
  selector: 'fs-html-editor',
879
- template: "<div class=\"fs-html-editor-default\">\n <ng-container *ngIf=\"initialized\">\n <ng-container *fsSkeleton=\"(froalaReady$ | async) !== false\">\n </ng-container>\n </ng-container>\n\n <div #elRef></div>\n\n <div class=\"bottom-line\"></div>\n <div class=\"disabled-line\"></div>\n <fs-html-renderer\n *ngIf=\"!initialized\"\n [html]=\"html\"\n (click)=\"uninitializedClick($event)\">\n </fs-html-renderer>\n</div>\n",
890
+ template: "<div class=\"fs-html-editor-default\">\n <ng-container *ngIf=\"initialized\">\n <ng-container *fsSkeleton=\"(froalaLoaded$ | async) !== false\">\n </ng-container>\n </ng-container>\n\n <div #elRef></div>\n\n <div class=\"bottom-line\"></div>\n <div class=\"disabled-line\"></div>\n <fs-html-renderer\n *ngIf=\"!initialized\"\n [html]=\"html\"\n (click)=\"uninitializedClick($event)\">\n </fs-html-renderer>\n</div>\n",
880
891
  providers: [
881
892
  {
882
893
  provide: forms.NG_VALUE_ACCESSOR,
@@ -890,7 +901,7 @@
890
901
  },
891
902
  ],
892
903
  changeDetection: core.ChangeDetectionStrategy.OnPush,
893
- styles: [":host ::ng-deep .fr-box.fr-basic .fr-wrapper{border:0;border-bottom:1px solid #949494;margin-bottom:1px;background-color:transparent}:host ::ng-deep .fr-box.fr-basic .fr-element{padding:0;font-family:inherit;color:inherit;font-size:inherit;line-height:inherit;min-height:auto}:host ::ng-deep .fr-dropdown-menu .fr-dropdown-wrapper,:host ::ng-deep .fr-dropdown:after,:host ::ng-deep .fr-more-toolbar,:host ::ng-deep .fr-toolbar{transition:none!important}:host ::ng-deep .fr-toolbar{position:-webkit-sticky;position:sticky;z-index:2;border-radius:0;background-color:transparent}:host ::ng-deep .fr-toolbar .fr-btn-grp{margin:0 20px 0 0}:host ::ng-deep .fr-toolbar .fr-btn-grp:nth-child(1):after,:host ::ng-deep .fr-toolbar .fr-btn-grp:nth-child(2):after{content:\"\";position:absolute;top:9px;height:30px;border-left:1px solid #e5e5e5;margin-left:10px}:host ::ng-deep .fr-toolbar div:first-of-type:before{border:none}:host ::ng-deep .fr-toolbar.fr-toolbar-open .fr-newline{height:auto}:host ::ng-deep .fr-toolbar .fr-btn-grp:first-child{margin-left:0}:host ::ng-deep .fr-toolbar.fr-top{border:0}:host ::ng-deep .fr-toolbar .fr-newline{margin:0}:host ::ng-deep .fr-toolbar .fr-more-toolbar{z-index:auto}:host ::ng-deep .fr-toolbar .fr-command.fr-btn{z-index:auto}:host ::ng-deep .fr-toolbar .fr-command.fr-btn.fr-dropdown:after{right:3px}:host ::ng-deep .fr-toolbar .fr-command.fr-btn.fr-dropdown.fr-selection span{margin-right:24px}:host ::ng-deep .fr-toolbar .fr-command.fr-btn.fr-open{border-radius:4px;margin:4px 2px}:host ::ng-deep .fr-view ol,:host ::ng-deep .fr-view ul{list-style-position:unset}:host.disabled ::ng-deep .fr-box.fr-basic{opacity:.5;pointer-events:none}:host.disabled ::ng-deep .fr-box.fr-basic .fr-wrapper{border:none}:host.disabled ::ng-deep .disabled-line{display:block}::ng-deep .fr-popup{z-index:1001!important}::ng-deep .fr-video-by-url-layer .fr-checkbox-line{display:none}.disabled-line{display:none;position:absolute;bottom:-1px;z-index:1;background-image:linear-gradient(90deg,rgba(0,0,0,.42) 0,rgba(0,0,0,.42) 33%,transparent 0);background-size:4px 100%;background-repeat:repeat-x;height:1px;width:100%}.bottom-line{opacity:0;transform-origin:50%;transform:scaleX(.5);transition:background-color .3s cubic-bezier(.55,0,.55,.2);width:100%;border-bottom:2px solid #949494;position:absolute;bottom:-1px;z-index:1}:host{position:relative;display:block}:host.focused .bottom-line{opacity:1;display:block;transform:scaleX(1);transition:transform .3s cubic-bezier(.25,.8,.25,1),opacity .1s cubic-bezier(.25,.8,.25,1),background-color .3s cubic-bezier(.25,.8,.25,1)}::ng-deep .fs-html-editor-mention-container{position:absolute;top:0;left:0;height:auto;max-height:300px;max-width:500px;overflow:auto;display:block;z-index:999999;box-shadow:0 2px 4px -1px rgba(0,0,0,.2),0 4px 5px 0 rgba(0,0,0,.14),0 1px 10px 0 rgba(0,0,0,.12);border-bottom-left-radius:4px;border-bottom-right-radius:4px;background:#fff}::ng-deep .fs-html-editor-mention-container ul{margin:0;padding:0;list-style:none}::ng-deep .fs-html-editor-mention-container li{padding:0 16px;cursor:pointer;line-height:48px}::ng-deep .fs-html-editor-mention-container li.highlight,::ng-deep .fs-html-editor-mention-container li:hover{background:#f5f5f5}::ng-deep .fs-html-editor-mention-container li.no-match{cursor:default}"]
904
+ styles: [":host ::ng-deep .fr-box.fr-basic .fr-wrapper{border:0;border-bottom:1px solid #949494;margin-bottom:1px;background-color:transparent}:host ::ng-deep .fr-box.fr-basic .fr-element{padding:0;font-family:inherit;color:inherit;font-size:inherit;line-height:inherit;min-height:auto}:host ::ng-deep .fr-dropdown-menu .fr-dropdown-wrapper,:host ::ng-deep .fr-dropdown:after,:host ::ng-deep .fr-more-toolbar,:host ::ng-deep .fr-toolbar{transition:none!important}:host ::ng-deep .fr-toolbar{position:-webkit-sticky;position:sticky;z-index:2;border-radius:0;background-color:#fff}:host ::ng-deep .fr-toolbar .fr-btn-grp{margin:0 20px 0 0}:host ::ng-deep .fr-toolbar .fr-btn-grp:nth-child(1):after,:host ::ng-deep .fr-toolbar .fr-btn-grp:nth-child(2):after{content:\"\";position:absolute;top:9px;height:30px;border-left:1px solid #e5e5e5;margin-left:10px}:host ::ng-deep .fr-toolbar div:first-of-type:before{border:none}:host ::ng-deep .fr-toolbar.fr-toolbar-open .fr-newline{height:auto}:host ::ng-deep .fr-toolbar .fr-btn-grp:first-child{margin-left:0}:host ::ng-deep .fr-toolbar.fr-top{border:0}:host ::ng-deep .fr-toolbar .fr-newline{margin:0}:host ::ng-deep .fr-toolbar .fr-more-toolbar{z-index:auto}:host ::ng-deep .fr-toolbar .fr-command.fr-btn{z-index:auto}:host ::ng-deep .fr-toolbar .fr-command.fr-btn.fr-dropdown:after{right:3px}:host ::ng-deep .fr-toolbar .fr-command.fr-btn.fr-dropdown.fr-selection span{margin-right:24px}:host ::ng-deep .fr-toolbar .fr-command.fr-btn.fr-open{border-radius:4px;margin:4px 2px}:host ::ng-deep .fr-view ol,:host ::ng-deep .fr-view ul{list-style-position:unset}:host.disabled ::ng-deep .fr-box.fr-basic{opacity:.5;pointer-events:none}:host.disabled ::ng-deep .fr-box.fr-basic .fr-wrapper{border:none}:host.disabled ::ng-deep .disabled-line{display:block}::ng-deep .fr-popup{z-index:1001!important}::ng-deep .fr-video-by-url-layer .fr-checkbox-line{display:none}.disabled-line{display:none;position:absolute;bottom:-1px;z-index:1;background-image:linear-gradient(90deg,rgba(0,0,0,.42) 0,rgba(0,0,0,.42) 33%,transparent 0);background-size:4px 100%;background-repeat:repeat-x;height:1px;width:100%}.bottom-line{opacity:0;transform-origin:50%;transform:scaleX(.5);transition:background-color .3s cubic-bezier(.55,0,.55,.2);width:100%;border-bottom:2px solid #949494;position:absolute;bottom:-1px;z-index:1}:host{position:relative;display:block}:host.focused .bottom-line{opacity:1;display:block;transform:scaleX(1);transition:transform .3s cubic-bezier(.25,.8,.25,1),opacity .1s cubic-bezier(.25,.8,.25,1),background-color .3s cubic-bezier(.25,.8,.25,1)}::ng-deep .fs-html-editor-mention-container{position:absolute;top:0;left:0;height:auto;max-height:300px;max-width:500px;overflow:auto;display:block;z-index:999999;box-shadow:0 2px 4px -1px rgba(0,0,0,.2),0 4px 5px 0 rgba(0,0,0,.14),0 1px 10px 0 rgba(0,0,0,.12);border-bottom-left-radius:4px;border-bottom-right-radius:4px;background:#fff}::ng-deep .fs-html-editor-mention-container ul{margin:0;padding:0;list-style:none}::ng-deep .fs-html-editor-mention-container li{padding:0 16px;cursor:pointer;line-height:48px}::ng-deep .fs-html-editor-mention-container li.highlight,::ng-deep .fs-html-editor-mention-container li:hover{background:#f5f5f5}::ng-deep .fs-html-editor-mention-container li.no-match{cursor:default}"]
894
905
  }),
895
906
  __param(0, core.Optional()), __param(0, core.Inject(FS_HTML_EDITOR_CONFIG)),
896
907
  __metadata("design:paramtypes", [Object, core.ChangeDetectorRef,