@firestitch/html-editor 9.5.4 → 9.5.5
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/app/components/html-editor/html-editor.component.d.ts +3 -1
- package/app/services/froala-loader.service.d.ts +2 -2
- package/bundles/firestitch-html-editor.umd.js +114 -113
- package/bundles/firestitch-html-editor.umd.js.map +1 -1
- package/bundles/firestitch-html-editor.umd.min.js +1 -1
- package/bundles/firestitch-html-editor.umd.min.js.map +1 -1
- package/esm2015/app/components/html-editor/html-editor.component.js +112 -112
- package/esm2015/app/services/froala-loader.service.js +4 -4
- package/esm5/app/components/html-editor/html-editor.component.js +114 -113
- package/esm5/app/services/froala-loader.service.js +4 -4
- package/fesm2015/firestitch-html-editor.js +113 -113
- package/fesm2015/firestitch-html-editor.js.map +1 -1
- package/fesm5/firestitch-html-editor.js +115 -114
- package/fesm5/firestitch-html-editor.js.map +1 -1
- package/firestitch-html-editor.metadata.json +1 -1
- package/package.json +1 -1
|
@@ -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
|
|
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
|
|
8
|
+
private _loaded$;
|
|
9
9
|
constructor(_defaultConfig: FsHtmlEditorConfig);
|
|
10
|
-
readonly
|
|
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.
|
|
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, "
|
|
388
|
+
Object.defineProperty(FsFroalaLoaderService.prototype, "loaded$", {
|
|
389
389
|
get: function () {
|
|
390
|
-
return this.
|
|
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, "
|
|
492
|
+
Object.defineProperty(FsHtmlEditorComponent.prototype, "froalaLoaded$", {
|
|
492
493
|
get: function () {
|
|
493
|
-
return this._fr.
|
|
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.
|
|
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.
|
|
699
|
-
|
|
700
|
-
|
|
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.
|
|
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,96 @@
|
|
|
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
|
+
this._editor.events.on('contentChanged', function () {
|
|
786
|
+
_this._contentChanged();
|
|
787
|
+
});
|
|
788
|
+
this._editor.events.on('paste.afterCleanup', function (html) {
|
|
789
|
+
var div = document.createElement('div');
|
|
790
|
+
div.innerHTML = html;
|
|
791
|
+
div.querySelectorAll('*')
|
|
792
|
+
.forEach(function (el) {
|
|
793
|
+
for (var i = 0; i < el.attributes.length; i++) {
|
|
794
|
+
var name_1 = el.attributes[0].name;
|
|
795
|
+
if (name_1 !== 'href') {
|
|
796
|
+
el.removeAttribute(name_1);
|
|
797
|
+
}
|
|
798
|
+
}
|
|
799
|
+
});
|
|
800
|
+
return div.innerHTML;
|
|
801
|
+
});
|
|
802
|
+
this._editor.events.on('keydown', function () {
|
|
803
|
+
_this.onTouched();
|
|
804
|
+
});
|
|
805
|
+
if (this.config.image && this.config.image.upload) {
|
|
806
|
+
this._editor.events.on('image.beforePasteUpload', function (image) {
|
|
807
|
+
fetch(image.getAttribute('src'))
|
|
808
|
+
.then(function (res) {
|
|
809
|
+
res.blob()
|
|
810
|
+
.then(function (blob) {
|
|
811
|
+
_this._processImageUpload(blob)
|
|
812
|
+
.pipe(operators.takeUntil(_this._destroy$))
|
|
813
|
+
.subscribe(function (url) {
|
|
814
|
+
image.setAttribute('src', url);
|
|
815
|
+
image.removeAttribute('data-fr-image-pasted');
|
|
816
|
+
_this._contentChanged();
|
|
817
|
+
});
|
|
818
|
+
});
|
|
819
|
+
});
|
|
820
|
+
return false;
|
|
821
|
+
});
|
|
822
|
+
this._editor.events.on('image.beforeUpload', function (blobs) {
|
|
823
|
+
_this._processImageUpload(blobs[0])
|
|
824
|
+
.pipe(operators.takeUntil(_this._destroy$))
|
|
825
|
+
.subscribe(function (url) {
|
|
826
|
+
_this.editor.image.insert(url, null, null, _this.editor.image.get());
|
|
827
|
+
});
|
|
828
|
+
return false;
|
|
829
|
+
});
|
|
830
|
+
}
|
|
831
|
+
if (this.el.querySelector('.fr-second-toolbar')) {
|
|
832
|
+
this.el.querySelector('.fr-second-toolbar').remove();
|
|
833
|
+
}
|
|
834
|
+
var selection = options.selection;
|
|
835
|
+
if (selection) {
|
|
836
|
+
var node = Array.from(this.el.querySelectorAll('.fr-element *')).find(function (node) {
|
|
837
|
+
return selection.node === node.textContent;
|
|
838
|
+
});
|
|
839
|
+
if (node) {
|
|
840
|
+
var range = document.createRange();
|
|
841
|
+
var sel = window.getSelection();
|
|
842
|
+
range.setStart(this._getTextNode(node), selection.offset);
|
|
843
|
+
range.collapse(true);
|
|
844
|
+
sel.removeAllRanges();
|
|
845
|
+
sel.addRange(range);
|
|
846
|
+
}
|
|
847
|
+
else if (this.config.autofocus) {
|
|
848
|
+
this.focus();
|
|
849
|
+
}
|
|
850
|
+
}
|
|
851
|
+
else if (this.config.autofocus) {
|
|
852
|
+
this.focus();
|
|
853
|
+
}
|
|
854
|
+
};
|
|
854
855
|
var FsHtmlEditorComponent_1;
|
|
855
856
|
FsHtmlEditorComponent.ctorParameters = function () { return [
|
|
856
857
|
{ type: undefined, decorators: [{ type: core.Optional }, { type: core.Inject, args: [FS_HTML_EDITOR_CONFIG,] }] },
|
|
@@ -876,7 +877,7 @@
|
|
|
876
877
|
FsHtmlEditorComponent = FsHtmlEditorComponent_1 = __decorate([
|
|
877
878
|
core.Component({
|
|
878
879
|
selector: 'fs-html-editor',
|
|
879
|
-
template: "<div class=\"fs-html-editor-default\">\n <ng-container *ngIf=\"initialized\">\n <ng-container *fsSkeleton=\"(
|
|
880
|
+
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
881
|
providers: [
|
|
881
882
|
{
|
|
882
883
|
provide: forms.NG_VALUE_ACCESSOR,
|