@firestitch/html-editor 12.0.0 → 12.0.1

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 (49) hide show
  1. package/app/classes/plugin.d.ts +7 -7
  2. package/app/components/html-editor/html-editor.component.d.ts +57 -57
  3. package/app/components/html-renderer/html-renderer.component.d.ts +12 -12
  4. package/app/consts/paragraph-buttons.const.d.ts +1 -1
  5. package/app/consts/rich-buttons.const.d.ts +1 -1
  6. package/app/consts/text-buttons.const.d.ts +1 -1
  7. package/app/enums/default-plugin.enum.d.ts +14 -14
  8. package/app/fs-html-editor.module.d.ts +33 -33
  9. package/app/injects/config.inject.d.ts +3 -3
  10. package/app/interfaces/html-editor-config.d.ts +31 -31
  11. package/app/interfaces/plugin-button.d.ts +12 -12
  12. package/app/interfaces/plugin-config.d.ts +5 -5
  13. package/app/plugins/checklist.plugin.d.ts +7 -7
  14. package/app/plugins/code.plugin.d.ts +9 -9
  15. package/app/plugins/configs/mention-plugin.config.d.ts +13 -13
  16. package/app/plugins/configs/screen-record-plugin.config.d.ts +7 -7
  17. package/app/plugins/mention.plugin.d.ts +15 -15
  18. package/app/plugins/screen-record.plugin.d.ts +11 -11
  19. package/app/services/froala-loader.service.d.ts +20 -20
  20. package/app/utils/loader.d.ts +7 -7
  21. package/bundles/firestitch-html-editor.umd.js +1359 -1358
  22. package/bundles/firestitch-html-editor.umd.js.map +1 -1
  23. package/esm2015/app/classes/plugin.js +4 -4
  24. package/esm2015/app/components/html-editor/html-editor.component.js +454 -453
  25. package/esm2015/app/components/html-renderer/html-renderer.component.js +28 -28
  26. package/esm2015/app/consts/paragraph-buttons.const.js +8 -8
  27. package/esm2015/app/consts/rich-buttons.const.js +6 -6
  28. package/esm2015/app/consts/text-buttons.const.js +18 -18
  29. package/esm2015/app/enums/default-plugin.enum.js +1 -1
  30. package/esm2015/app/fs-html-editor.module.js +64 -64
  31. package/esm2015/app/injects/config.inject.js +3 -3
  32. package/esm2015/app/interfaces/html-editor-config.js +1 -1
  33. package/esm2015/app/interfaces/plugin-button.js +1 -1
  34. package/esm2015/app/interfaces/plugin-config.js +1 -1
  35. package/esm2015/app/plugins/checklist.plugin.js +34 -34
  36. package/esm2015/app/plugins/code.plugin.js +62 -62
  37. package/esm2015/app/plugins/configs/mention-plugin.config.js +1 -1
  38. package/esm2015/app/plugins/configs/screen-record-plugin.config.js +1 -1
  39. package/esm2015/app/plugins/mention.plugin.js +86 -86
  40. package/esm2015/app/plugins/screen-record.plugin.js +91 -91
  41. package/esm2015/app/services/froala-loader.service.js +80 -80
  42. package/esm2015/app/utils/loader.js +82 -82
  43. package/esm2015/firestitch-html-editor.js +4 -4
  44. package/esm2015/public_api.js +11 -11
  45. package/fesm2015/firestitch-html-editor.js +961 -960
  46. package/fesm2015/firestitch-html-editor.js.map +1 -1
  47. package/firestitch-html-editor.d.ts +5 -5
  48. package/package.json +1 -1
  49. package/public_api.d.ts +16 -16
@@ -14,996 +14,997 @@ import Tribute from 'tributejs';
14
14
  import { guid } from '@firestitch/common';
15
15
  import { __awaiter } from 'tslib';
16
16
 
17
- const RichButtons = [
18
- 'insertTable',
19
- 'insertImage',
20
- 'insertLink',
21
- 'insertVideo',
17
+ const RichButtons = [
18
+ 'insertTable',
19
+ 'insertImage',
20
+ 'insertLink',
21
+ 'insertVideo',
22
22
  ];
23
23
 
24
- const TextButtons = [
25
- 'paragraphFormat',
26
- 'code',
27
- 'bold',
28
- 'italic',
29
- 'underline',
30
- 'strikeThrough',
31
- 'subscript',
32
- 'superscript',
33
- 'fontFamily',
34
- 'fontSize',
35
- 'textColor',
36
- 'backgroundColor',
37
- 'inlineClass',
38
- 'inlineStyle',
39
- 'clearFormatting',
40
- 'quote',
24
+ const TextButtons = [
25
+ 'paragraphFormat',
26
+ 'code',
27
+ 'bold',
28
+ 'italic',
29
+ 'underline',
30
+ 'strikeThrough',
31
+ 'subscript',
32
+ 'superscript',
33
+ 'fontFamily',
34
+ 'fontSize',
35
+ 'textColor',
36
+ 'backgroundColor',
37
+ 'inlineClass',
38
+ 'inlineStyle',
39
+ 'clearFormatting',
40
+ 'quote',
41
41
  ];
42
42
 
43
- const ParagraphButtons = [
44
- 'align',
45
- 'formatOL',
46
- 'formatUL',
47
- 'checklist',
48
- 'indent',
49
- 'outdent',
43
+ const ParagraphButtons = [
44
+ 'align',
45
+ 'formatOL',
46
+ 'formatUL',
47
+ 'checklist',
48
+ 'indent',
49
+ 'outdent',
50
50
  ];
51
51
 
52
- const FS_HTML_EDITOR_DEFAULT_CONFIG = new InjectionToken('fs-html-editor.default-config');
52
+ const FS_HTML_EDITOR_DEFAULT_CONFIG = new InjectionToken('fs-html-editor.default-config');
53
53
  const FS_HTML_EDITOR_CONFIG = new InjectionToken('fs-html-editor.config');
54
54
 
55
- function resourceLoaderFactory() {
56
- let resourceBase = '/assets/js/froala/';
57
- let stylesBase = '/assets/css/';
58
- const head = document.getElementsByTagName('head')[0];
59
- const files = new Map();
60
- const resourcePaths = {
61
- froala: 'froala_editor.min.js',
62
- align: 'plugins/align.min.js',
63
- colors: 'plugins/colors.min.js',
64
- image: 'plugins/image.min.js',
65
- link: 'plugins/link.min.js',
66
- lists: 'plugins/lists.min.js',
67
- paragraph_format: 'plugins/paragraph_format.min.js',
68
- table: 'plugins/table.min.js',
69
- url: 'plugins/url.min.js',
70
- video: 'plugins/video.min.js',
71
- quote: 'plugins/quote.min.js',
72
- draggable: 'plugins/draggable.min.js',
73
- font_size: 'plugins/font_size.min.js',
74
- };
75
- const stylesPaths = {
76
- froala: 'froala_editor.pkgd.min.css',
77
- };
78
- const loadResource = function (scriptPath) {
79
- if (!files.has(scriptPath)) {
80
- const obs$ = new Observable((obs) => {
81
- const script = document.createElement('script');
82
- script.src = scriptPath;
83
- head.appendChild(script);
84
- script.onload = () => {
85
- obs.next();
86
- obs.complete();
87
- };
88
- script.onerror = (err) => {
89
- obs.error(err);
90
- };
91
- })
92
- .pipe(shareReplay(1));
93
- files.set(scriptPath, obs$);
94
- }
95
- return files.get(scriptPath);
96
- };
97
- const loadStyles = function (stylePath) {
98
- if (!files.has(stylePath)) {
99
- const obs$ = new Observable((obs) => {
100
- const style = document.createElement('link');
101
- style.id = stylePath;
102
- style.rel = 'stylesheet';
103
- style.href = `${stylePath}`;
104
- head.appendChild(style);
105
- style.onload = () => {
106
- obs.next();
107
- obs.complete();
108
- };
109
- style.onerror = (err) => {
110
- obs.error(err);
111
- };
112
- });
113
- files.set(stylePath, obs$);
114
- }
115
- return files.get(stylePath);
116
- };
117
- return {
118
- setResourceBase: (path) => {
119
- resourceBase = path;
120
- },
121
- setStylesBase: (path) => {
122
- stylesBase = path;
123
- },
124
- loadResource: (resourceName) => {
125
- const path = resourcePaths[resourceName] || resourceName;
126
- return loadResource(resourceBase + path);
127
- },
128
- loadStyles: (resourceName) => {
129
- const path = stylesPaths[resourceName] || resourceName;
130
- return loadStyles(stylesBase + path);
131
- }
132
- };
133
- }
55
+ function resourceLoaderFactory() {
56
+ let resourceBase = '/assets/js/froala/';
57
+ let stylesBase = '/assets/css/';
58
+ const head = document.getElementsByTagName('head')[0];
59
+ const files = new Map();
60
+ const resourcePaths = {
61
+ froala: 'froala_editor.min.js',
62
+ align: 'plugins/align.min.js',
63
+ colors: 'plugins/colors.min.js',
64
+ image: 'plugins/image.min.js',
65
+ link: 'plugins/link.min.js',
66
+ lists: 'plugins/lists.min.js',
67
+ paragraph_format: 'plugins/paragraph_format.min.js',
68
+ table: 'plugins/table.min.js',
69
+ url: 'plugins/url.min.js',
70
+ video: 'plugins/video.min.js',
71
+ quote: 'plugins/quote.min.js',
72
+ draggable: 'plugins/draggable.min.js',
73
+ font_size: 'plugins/font_size.min.js',
74
+ };
75
+ const stylesPaths = {
76
+ froala: 'froala_editor.pkgd.min.css',
77
+ };
78
+ const loadResource = function (scriptPath) {
79
+ if (!files.has(scriptPath)) {
80
+ const obs$ = new Observable((obs) => {
81
+ const script = document.createElement('script');
82
+ script.src = scriptPath;
83
+ head.appendChild(script);
84
+ script.onload = () => {
85
+ obs.next();
86
+ obs.complete();
87
+ };
88
+ script.onerror = (err) => {
89
+ obs.error(err);
90
+ };
91
+ })
92
+ .pipe(shareReplay(1));
93
+ files.set(scriptPath, obs$);
94
+ }
95
+ return files.get(scriptPath);
96
+ };
97
+ const loadStyles = function (stylePath) {
98
+ if (!files.has(stylePath)) {
99
+ const obs$ = new Observable((obs) => {
100
+ const style = document.createElement('link');
101
+ style.id = stylePath;
102
+ style.rel = 'stylesheet';
103
+ style.href = `${stylePath}`;
104
+ head.appendChild(style);
105
+ style.onload = () => {
106
+ obs.next();
107
+ obs.complete();
108
+ };
109
+ style.onerror = (err) => {
110
+ obs.error(err);
111
+ };
112
+ });
113
+ files.set(stylePath, obs$);
114
+ }
115
+ return files.get(stylePath);
116
+ };
117
+ return {
118
+ setResourceBase: (path) => {
119
+ resourceBase = path;
120
+ },
121
+ setStylesBase: (path) => {
122
+ stylesBase = path;
123
+ },
124
+ loadResource: (resourceName) => {
125
+ const path = resourcePaths[resourceName] || resourceName;
126
+ return loadResource(resourceBase + path);
127
+ },
128
+ loadStyles: (resourceName) => {
129
+ const path = stylesPaths[resourceName] || resourceName;
130
+ return loadStyles(stylesBase + path);
131
+ }
132
+ };
133
+ }
134
134
  const ResourceLoader = resourceLoaderFactory();
135
135
 
136
- class FsFroalaLoaderService {
137
- constructor(_defaultConfig) {
138
- this._defaultConfig = _defaultConfig;
139
- this._froalaLoaded = new BehaviorSubject(false);
140
- this._defaultPluginsLoaded = new BehaviorSubject(false);
141
- this._loaded$ = combineLatest([this._froalaLoaded, this._defaultPluginsLoaded])
142
- .pipe(map(([FroalaReady, pluginsRead]) => {
143
- return pluginsRead && FroalaReady;
144
- }), shareReplay(1));
145
- if (this._defaultConfig) {
146
- if (this._defaultConfig.assetsJSPath) {
147
- ResourceLoader.setResourceBase(this._defaultConfig.assetsJSPath);
148
- }
149
- if (this._defaultConfig.assetsCSSPath) {
150
- ResourceLoader.setStylesBase(this._defaultConfig.assetsCSSPath);
151
- }
152
- }
153
- this._load();
154
- }
155
- get loaded$() {
156
- return this._loaded$;
157
- }
158
- get ready() {
159
- return this._froalaLoaded.getValue() && this._defaultPluginsLoaded.getValue();
160
- }
161
- get FroalaEditor() {
162
- return this._FroalaEditor;
163
- }
164
- _load() {
165
- combineLatest([
166
- ResourceLoader.loadResource('froala'),
167
- ResourceLoader.loadStyles('froala')
168
- ])
169
- .pipe(tap(() => {
170
- this._FroalaEditor = window.FroalaEditor;
171
- this._froalaDone();
172
- }), concatMap(() => {
173
- return this._loadPlugins();
174
- }), tap(() => {
175
- this._defaultPluginsDone();
176
- }))
177
- .subscribe();
178
- }
179
- _loadPlugins() {
180
- const imports = this._defaultConfig
181
- .defaultPlugins
182
- .reduce((acc, pluginName) => {
183
- const import$ = ResourceLoader.loadResource(pluginName);
184
- acc.push(import$);
185
- return acc;
186
- }, []);
187
- return combineLatest(imports);
188
- }
189
- _froalaDone() {
190
- this._froalaLoaded.next(true);
191
- }
192
- _defaultPluginsDone() {
193
- this._defaultPluginsLoaded.next(true);
194
- }
195
- }
196
- FsFroalaLoaderService.ɵfac = i0.ɵɵngDeclareFactory({ minVersion: "12.0.0", version: "12.2.16", ngImport: i0, type: FsFroalaLoaderService, deps: [{ token: FS_HTML_EDITOR_CONFIG, optional: true }], target: i0.ɵɵFactoryTarget.Injectable });
197
- FsFroalaLoaderService.ɵprov = i0.ɵɵngDeclareInjectable({ minVersion: "12.0.0", version: "12.2.16", ngImport: i0, type: FsFroalaLoaderService, providedIn: 'root' });
198
- i0.ɵɵngDeclareClassMetadata({ minVersion: "12.0.0", version: "12.2.16", ngImport: i0, type: FsFroalaLoaderService, decorators: [{
199
- type: Injectable,
200
- args: [{
201
- providedIn: 'root',
202
- }]
203
- }], ctorParameters: function () { return [{ type: undefined, decorators: [{
204
- type: Optional
205
- }, {
206
- type: Inject,
207
- args: [FS_HTML_EDITOR_CONFIG]
136
+ class FsFroalaLoaderService {
137
+ constructor(_defaultConfig) {
138
+ this._defaultConfig = _defaultConfig;
139
+ this._froalaLoaded = new BehaviorSubject(false);
140
+ this._defaultPluginsLoaded = new BehaviorSubject(false);
141
+ this._loaded$ = combineLatest([this._froalaLoaded, this._defaultPluginsLoaded])
142
+ .pipe(map(([FroalaReady, pluginsRead]) => {
143
+ return pluginsRead && FroalaReady;
144
+ }), shareReplay(1));
145
+ if (this._defaultConfig) {
146
+ if (this._defaultConfig.assetsJSPath) {
147
+ ResourceLoader.setResourceBase(this._defaultConfig.assetsJSPath);
148
+ }
149
+ if (this._defaultConfig.assetsCSSPath) {
150
+ ResourceLoader.setStylesBase(this._defaultConfig.assetsCSSPath);
151
+ }
152
+ }
153
+ this._load();
154
+ }
155
+ get loaded$() {
156
+ return this._loaded$;
157
+ }
158
+ get ready() {
159
+ return this._froalaLoaded.getValue() && this._defaultPluginsLoaded.getValue();
160
+ }
161
+ get FroalaEditor() {
162
+ return this._FroalaEditor;
163
+ }
164
+ _load() {
165
+ combineLatest([
166
+ ResourceLoader.loadResource('froala'),
167
+ ResourceLoader.loadStyles('froala')
168
+ ])
169
+ .pipe(tap(() => {
170
+ this._FroalaEditor = window.FroalaEditor;
171
+ this._froalaDone();
172
+ }), concatMap(() => {
173
+ return this._loadPlugins();
174
+ }), tap(() => {
175
+ this._defaultPluginsDone();
176
+ }))
177
+ .subscribe();
178
+ }
179
+ _loadPlugins() {
180
+ const imports = this._defaultConfig
181
+ .defaultPlugins
182
+ .reduce((acc, pluginName) => {
183
+ const import$ = ResourceLoader.loadResource(pluginName);
184
+ acc.push(import$);
185
+ return acc;
186
+ }, []);
187
+ return combineLatest(imports);
188
+ }
189
+ _froalaDone() {
190
+ this._froalaLoaded.next(true);
191
+ }
192
+ _defaultPluginsDone() {
193
+ this._defaultPluginsLoaded.next(true);
194
+ }
195
+ }
196
+ FsFroalaLoaderService.ɵfac = i0.ɵɵngDeclareFactory({ minVersion: "12.0.0", version: "12.2.16", ngImport: i0, type: FsFroalaLoaderService, deps: [{ token: FS_HTML_EDITOR_CONFIG, optional: true }], target: i0.ɵɵFactoryTarget.Injectable });
197
+ FsFroalaLoaderService.ɵprov = i0.ɵɵngDeclareInjectable({ minVersion: "12.0.0", version: "12.2.16", ngImport: i0, type: FsFroalaLoaderService, providedIn: 'root' });
198
+ i0.ɵɵngDeclareClassMetadata({ minVersion: "12.0.0", version: "12.2.16", ngImport: i0, type: FsFroalaLoaderService, decorators: [{
199
+ type: Injectable,
200
+ args: [{
201
+ providedIn: 'root',
202
+ }]
203
+ }], ctorParameters: function () { return [{ type: undefined, decorators: [{
204
+ type: Optional
205
+ }, {
206
+ type: Inject,
207
+ args: [FS_HTML_EDITOR_CONFIG]
208
208
  }] }]; } });
209
209
 
210
- class FsHtmlRendererComponent {
211
- constructor(sanitized, _cdRef) {
212
- this.sanitized = sanitized;
213
- this._cdRef = _cdRef;
214
- }
215
- set setHtml(html) {
216
- this.trustedHtml = this.sanitized.bypassSecurityTrustHtml(html || '');
217
- this._cdRef.markForCheck();
218
- }
219
- }
220
- FsHtmlRendererComponent.ɵfac = i0.ɵɵngDeclareFactory({ minVersion: "12.0.0", version: "12.2.16", ngImport: i0, type: FsHtmlRendererComponent, deps: [{ token: i1.DomSanitizer }, { token: i0.ChangeDetectorRef }], target: i0.ɵɵFactoryTarget.Component });
221
- FsHtmlRendererComponent.ɵcmp = i0.ɵɵngDeclareComponent({ minVersion: "12.0.0", version: "12.2.16", type: FsHtmlRendererComponent, selector: "fs-html-renderer", inputs: { setHtml: ["html", "setHtml"] }, ngImport: i0, template: "<div class=\"fr-view fs-html-editor-default\" [innerHtml]=\"trustedHtml\"></div>\n", styles: [""], changeDetection: i0.ChangeDetectionStrategy.OnPush });
222
- i0.ɵɵngDeclareClassMetadata({ minVersion: "12.0.0", version: "12.2.16", ngImport: i0, type: FsHtmlRendererComponent, decorators: [{
223
- type: Component,
224
- args: [{
225
- selector: 'fs-html-renderer',
226
- templateUrl: 'html-renderer.component.html',
227
- styleUrls: ['html-renderer.component.scss'],
228
- changeDetection: ChangeDetectionStrategy.OnPush,
229
- }]
230
- }], ctorParameters: function () { return [{ type: i1.DomSanitizer }, { type: i0.ChangeDetectorRef }]; }, propDecorators: { setHtml: [{
231
- type: Input,
232
- args: ['html']
210
+ class FsHtmlRendererComponent {
211
+ constructor(sanitized, _cdRef) {
212
+ this.sanitized = sanitized;
213
+ this._cdRef = _cdRef;
214
+ }
215
+ set setHtml(html) {
216
+ this.trustedHtml = this.sanitized.bypassSecurityTrustHtml(html || '');
217
+ this._cdRef.markForCheck();
218
+ }
219
+ }
220
+ FsHtmlRendererComponent.ɵfac = i0.ɵɵngDeclareFactory({ minVersion: "12.0.0", version: "12.2.16", ngImport: i0, type: FsHtmlRendererComponent, deps: [{ token: i1.DomSanitizer }, { token: i0.ChangeDetectorRef }], target: i0.ɵɵFactoryTarget.Component });
221
+ FsHtmlRendererComponent.ɵcmp = i0.ɵɵngDeclareComponent({ minVersion: "12.0.0", version: "12.2.16", type: FsHtmlRendererComponent, selector: "fs-html-renderer", inputs: { setHtml: ["html", "setHtml"] }, ngImport: i0, template: "<div class=\"fr-view fs-html-editor-default\" [innerHtml]=\"trustedHtml\"></div>\n", styles: [""], changeDetection: i0.ChangeDetectionStrategy.OnPush });
222
+ i0.ɵɵngDeclareClassMetadata({ minVersion: "12.0.0", version: "12.2.16", ngImport: i0, type: FsHtmlRendererComponent, decorators: [{
223
+ type: Component,
224
+ args: [{
225
+ selector: 'fs-html-renderer',
226
+ templateUrl: 'html-renderer.component.html',
227
+ styleUrls: ['html-renderer.component.scss'],
228
+ changeDetection: ChangeDetectionStrategy.OnPush,
229
+ }]
230
+ }], ctorParameters: function () { return [{ type: i1.DomSanitizer }, { type: i0.ChangeDetectorRef }]; }, propDecorators: { setHtml: [{
231
+ type: Input,
232
+ args: ['html']
233
233
  }] } });
234
234
 
235
- class FsHtmlEditorComponent {
236
- constructor(_defaultConfig, _cdRef, _fr) {
237
- this._defaultConfig = _defaultConfig;
238
- this._cdRef = _cdRef;
239
- this._fr = _fr;
240
- this.classFocused = false;
241
- this.classDisabled = false;
242
- this.config = {};
243
- this.initialized = false;
244
- this._initialize$ = new ReplaySubject();
245
- this._froalaReady$ = new BehaviorSubject(null);
246
- this._destroy$ = new Subject();
247
- this.onChange = (data) => { };
248
- this.onTouched = () => { };
249
- }
250
- get el() {
251
- return this.elRef.nativeElement;
252
- }
253
- get html() {
254
- return this._html;
255
- }
256
- get editor() {
257
- return this._editor;
258
- }
259
- get froalaLoaded$() {
260
- return this._fr.loaded$;
261
- }
262
- ngOnInit() {
263
- this.config = this.config || {};
264
- this.config.autofocus = this.config.autofocus !== false && !this.config.disabled;
265
- this.initialized = !this.config.initOnClick;
266
- this._listenLazyInit();
267
- }
268
- ngAfterViewInit() {
269
- if (!this.config.initOnClick || !this.hasContent()) {
270
- this.initialized = true;
271
- this._initialize$.next();
272
- }
273
- }
274
- hasContent() {
275
- const el = document.createElement('div');
276
- if (el.querySelector('img')) {
277
- return true;
278
- }
279
- el.innerHTML = this._html;
280
- return !!el.innerText.length;
281
- }
282
- initialize(options = {}) {
283
- const config = this._createConfig();
284
- this._initPlugins(config);
285
- // this.el.innerHTML = this._html || '';
286
- this._editor = new this._fr.FroalaEditor(this.el, this._createOptions(), () => {
287
- this._froalaReady$.next({ config, options });
288
- });
289
- }
290
- _processImageUpload(blob) {
291
- const processor = new FileProcessor();
292
- const file = new FsFile(blob);
293
- return processor.process([file], this.config.image)
294
- .pipe(switchMap(([f]) => {
295
- return this.config.image.upload(f.file);
296
- }));
297
- }
298
- _getTextNode(node) {
299
- if (node) {
300
- if (node.nodeType === Node.TEXT_NODE) {
301
- return node;
302
- }
303
- if (node.childNodes) {
304
- return this._getTextNode(node.childNodes[0]);
305
- }
306
- }
307
- }
308
- uninitializedClick(event) {
309
- if (!event.defaultPrevented) {
310
- const target = event.target;
311
- if (target && target.nodeName === 'A' && target.getAttribute('href')) {
312
- const targetTarget = target.getAttribute('target');
313
- target.setAttribute('target', '_blank');
314
- setTimeout(() => {
315
- if (targetTarget) {
316
- target.setAttribute('target', targetTarget);
317
- }
318
- else {
319
- target.removeAttribute('target');
320
- }
321
- });
322
- }
323
- else {
324
- if (this.config.initClick) {
325
- this.config.initClick(event);
326
- }
327
- this._initialize$.next();
328
- this.initialized = true;
329
- }
330
- }
331
- }
332
- updateSize() {
333
- // Hack: To trigger the toolbar button size modes
334
- window.dispatchEvent(new Event('resize'));
335
- }
336
- validate(control) {
337
- const err = {};
338
- if (this.config.maxLength && this._html) {
339
- const maxLength = this.config.maxLength;
340
- const length = this._html.length;
341
- if (length > maxLength) {
342
- err.maxLengthError = `Must be ${maxLength} characters or fewer. You entered ${length} characters.`;
343
- }
344
- }
345
- return Object.keys(err).length ? err : null;
346
- }
347
- focus(options) {
348
- options = options ? options : {};
349
- if (options.cursorPosition === 'end') {
350
- this.editor.selection.setAtEnd(this.editor.$el.get(0));
351
- }
352
- else {
353
- this.editor.selection.setAtStart(this.editor.$el.get(0));
354
- }
355
- this.editor.selection.restore();
356
- const elSelection = this.editor.selection.element();
357
- if (elSelection) {
358
- elSelection.scrollIntoView({ block: 'center' });
359
- }
360
- }
361
- clear() {
362
- this.writeValue('');
363
- }
364
- disable() {
365
- this.classDisabled = true;
366
- }
367
- setHtml(html) {
368
- this.writeValue(html);
369
- }
370
- writeValue(html) {
371
- this._html = html || '';
372
- if (this.editor && this.editor.html) {
373
- try {
374
- this.editor.html.set(this._html);
375
- }
376
- catch (e) {
377
- }
378
- }
379
- this._cdRef.markForCheck();
380
- }
381
- registerOnChange(fn) {
382
- this.onChange = fn;
383
- }
384
- registerOnTouched(fn) {
385
- this.onTouched = fn;
386
- }
387
- ngOnDestroy() {
388
- this._initialize$.complete();
389
- this._destroy$.next();
390
- this._destroy$.complete();
391
- this.destroy();
392
- }
393
- destroy() {
394
- if (this.editor) {
395
- this.editor.destroy();
396
- }
397
- this.initialized = false;
398
- this._cdRef.markForCheck();
399
- this.el.innerHTML = '';
400
- }
401
- _createConfig() {
402
- return merge({ froalaConfig: {} }, this._defaultConfig, this.config);
403
- }
404
- _change(html) {
405
- // this._html = html;
406
- this.onChange(html);
407
- }
408
- _initPlugins(config) {
409
- (config.plugins || []).forEach((plugin) => {
410
- this._fr.FroalaEditor.PLUGINS[plugin.config.name] = function (editor) {
411
- plugin.editor = editor;
412
- plugin.initialize();
413
- return plugin;
414
- };
415
- (plugin.config.buttons || []).forEach((button) => {
416
- this._fr.FroalaEditor.DefineIcon(button.name, {
417
- NAME: button.name,
418
- PATH: button.svgPath,
419
- });
420
- this._fr.FroalaEditor.RegisterCommand(button.name, {
421
- icon: button.name,
422
- title: button.tooltip,
423
- undo: button.undo,
424
- focus: button.focus,
425
- showOnMobile: button.showOnMobile,
426
- refreshAfterCallback: button.refreshAfterCallback,
427
- callback: function () {
428
- if (button.click) {
429
- button.click(this);
430
- }
431
- },
432
- refresh: function (button) {
433
- if (button.refresh) {
434
- button.refresh(this, button);
435
- }
436
- }
437
- });
438
- });
439
- });
440
- }
441
- _createOptions() {
442
- const config = this._createConfig();
443
- return merge(
444
- // For some reason editor store somewhere pointer on default config object and dublicate options each time on init
445
- // Extra merge level fixed this problem and allow to init config properly without legacy data
446
- {}, {
447
- key: config.activationKey,
448
- placeholderText: config.placeholder,
449
- linkAlwaysBlank: true,
450
- tabSpaces: 2,
451
- typingTimer: 250,
452
- tooltips: false,
453
- wordPasteModal: false,
454
- imageDefaultWidth: 0,
455
- imageDefaultAlign: 'left',
456
- quickInsertEnabled: false,
457
- paragraphDefaultSelection: 'Format',
458
- videoUpload: false,
459
- paragraphFormat: {
460
- N: 'Normal',
461
- H1: 'Heading 1',
462
- H2: 'Heading 2',
463
- H3: 'Heading 3',
464
- H4: 'Heading 4',
465
- BLOCKQUOTE: 'Quote',
466
- },
467
- paragraphFormatSelection: true,
468
- toolbarButtonsXS: {
469
- moreText: {
470
- buttons: TextButtons,
471
- buttonsVisible: 1,
472
- },
473
- moreParagraph: {
474
- buttons: ParagraphButtons,
475
- buttonsVisible: 2,
476
- },
477
- moreRich: {
478
- buttons: RichButtons,
479
- buttonsVisible: 0,
480
- },
481
- },
482
- toolbarButtons: {
483
- moreText: {
484
- buttons: TextButtons,
485
- buttonsVisible: 3,
486
- },
487
- moreParagraph: {
488
- buttons: ParagraphButtons,
489
- buttonsVisible: 5,
490
- },
491
- moreRich: {
492
- buttons: RichButtons,
493
- buttonsVisible: 3,
494
- },
495
- },
496
- }, config.froalaConfig);
497
- }
498
- _listenLazyInit() {
499
- this.froalaLoaded$
500
- .pipe(filter((ready) => ready), switchMap(() => this._initialize$), tap(() => {
501
- const selection = window.getSelection();
502
- const options = {};
503
- if (selection.baseNode) {
504
- options.selection = {
505
- node: selection.baseNode.nodeValue,
506
- offset: selection.baseOffset,
507
- };
508
- }
509
- this.initialize(options);
510
- }), switchMap(() => this._froalaReady$), filter((data) => !!data), tap(({ config, options }) => {
511
- this._setupFroala(config, options);
512
- }))
513
- .subscribe();
514
- }
515
- _contentChanged() {
516
- const editorHTML = this._editor.html.get();
517
- if (this.html !== editorHTML) {
518
- this._change(editorHTML);
519
- }
520
- }
521
- _setupFroala(config, options) {
522
- this._cdRef.markForCheck();
523
- this.setHtml(this._html);
524
- if (config.disabled) {
525
- this.disable();
526
- }
527
- if (config.froalaConfig.events) {
528
- if (config.froalaConfig.events.initialized) {
529
- config.froalaConfig.events.initialized();
530
- }
531
- }
532
- this._editor.events.on('focus', () => {
533
- this.classFocused = true;
534
- this._cdRef.markForCheck();
535
- });
536
- this._editor.events.on('blur', () => {
537
- this.classFocused = false;
538
- this._cdRef.markForCheck();
539
- });
540
- fromEventPattern((handler) => {
541
- this._editor.events.on('contentChanged', handler);
542
- }, () => { })
543
- .pipe(startWith(this._html), map(() => this.editor.html.get()), distinctUntilChanged(), skip(1))
544
- .subscribe(() => {
545
- this._contentChanged();
546
- });
547
- // this._editor.events.on('contentChanged', () => {
548
- // console.log('test');
549
- // if (!this._firstChange) {
550
- // this._contentChanged();
551
- // }
552
- // });
553
- this._editor.events.on('paste.afterCleanup', (html) => {
554
- var div = document.createElement('div');
555
- div.innerHTML = html;
556
- div.querySelectorAll('*')
557
- .forEach((el) => {
558
- for (var i = 0; i < el.attributes.length; i++) {
559
- const name = el.attributes[0].name;
560
- if (name !== 'href') {
561
- el.removeAttribute(name);
562
- }
563
- }
564
- });
565
- return div.innerHTML;
566
- });
567
- this._editor.events.on('keydown', () => {
568
- this.onTouched();
569
- });
570
- if (this.config.image && this.config.image.upload) {
571
- this._editor.events.on('image.beforePasteUpload', (image) => {
572
- fetch(image.getAttribute('src'))
573
- .then((res) => {
574
- res.blob()
575
- .then((blob) => {
576
- this._processImageUpload(blob)
577
- .pipe(takeUntil(this._destroy$))
578
- .subscribe((url) => {
579
- image.setAttribute('src', url);
580
- image.removeAttribute('data-fr-image-pasted');
581
- this._contentChanged();
582
- });
583
- });
584
- });
585
- return false;
586
- });
587
- this._editor.events.on('image.beforeUpload', (blobs) => {
588
- this._processImageUpload(blobs[0])
589
- .pipe(takeUntil(this._destroy$))
590
- .subscribe((url) => {
591
- this.editor.image.insert(url, null, null, this.editor.image.get());
592
- });
593
- return false;
594
- });
595
- }
596
- if (this.el.querySelector('.fr-second-toolbar')) {
597
- this.el.querySelector('.fr-second-toolbar').remove();
598
- }
599
- const selection = options.selection;
600
- if (selection) {
601
- const node = Array.from(this.el.querySelectorAll('.fr-element *')).find((node) => {
602
- return selection.node === node.textContent;
603
- });
604
- if (node) {
605
- const range = document.createRange();
606
- const sel = window.getSelection();
607
- range.setStart(this._getTextNode(node), selection.offset);
608
- range.collapse(true);
609
- sel.removeAllRanges();
610
- sel.addRange(range);
611
- }
612
- else if (this.config.autofocus) {
613
- this.focus();
614
- }
615
- }
616
- else if (this.config.autofocus) {
617
- this.focus();
618
- }
619
- }
620
- }
621
- FsHtmlEditorComponent.ɵfac = i0.ɵɵngDeclareFactory({ minVersion: "12.0.0", version: "12.2.16", ngImport: i0, type: FsHtmlEditorComponent, deps: [{ token: FS_HTML_EDITOR_CONFIG, optional: true }, { token: i0.ChangeDetectorRef }, { token: FsFroalaLoaderService }], target: i0.ɵɵFactoryTarget.Component });
622
- FsHtmlEditorComponent.ɵcmp = i0.ɵɵngDeclareComponent({ minVersion: "12.0.0", version: "12.2.16", type: FsHtmlEditorComponent, selector: "fs-html-editor", inputs: { config: "config" }, host: { properties: { "class.focused": "this.classFocused", "class.disabled": "this.classDisabled" } }, providers: [
623
- {
624
- provide: NG_VALUE_ACCESSOR,
625
- useExisting: forwardRef(() => FsHtmlEditorComponent),
626
- multi: true
627
- },
628
- {
629
- provide: NG_VALIDATORS,
630
- useExisting: forwardRef(() => FsHtmlEditorComponent),
631
- multi: true
632
- },
633
- ], viewQueries: [{ propertyName: "elRef", first: true, predicate: ["elRef"], descendants: true }], ngImport: i0, 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", 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-more-toolbar,:host ::ng-deep .fr-toolbar,:host ::ng-deep .fr-dropdown:after,:host ::ng-deep .fr-dropdown-menu .fr-dropdown-wrapper{transition:none!important}:host ::ng-deep .fr-toolbar.fr-top{position:sticky;z-index:2;border-radius:0;background-color:#fff}:host ::ng-deep .fr-toolbar.fr-top .fr-btn-grp{margin:0 20px 0 0}:host ::ng-deep .fr-toolbar.fr-top .fr-btn-grp:nth-child(1):after,:host ::ng-deep .fr-toolbar.fr-top .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.fr-top div:first-of-type:before{border:none}:host ::ng-deep .fr-toolbar.fr-top.fr-toolbar-open .fr-newline{height:auto}:host ::ng-deep .fr-toolbar.fr-top .fr-btn-grp:first-child{margin-left:0}:host ::ng-deep .fr-toolbar.fr-top.fr-top{border:0}:host ::ng-deep .fr-toolbar.fr-top .fr-newline{margin:0}:host ::ng-deep .fr-toolbar.fr-top .fr-more-toolbar{z-index:auto}:host ::ng-deep .fr-toolbar.fr-top .fr-command.fr-btn{z-index:auto}:host ::ng-deep .fr-toolbar.fr-top .fr-command.fr-btn.fr-dropdown:after{right:3px}:host ::ng-deep .fr-toolbar.fr-top .fr-command.fr-btn.fr-dropdown.fr-selection span{margin-right:24px}:host ::ng-deep .fr-toolbar.fr-top .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 #0003,0 4px 5px #00000024,0 1px 10px #0000001f;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}\n"], components: [{ type: FsHtmlRendererComponent, selector: "fs-html-renderer", inputs: ["html"] }], directives: [{ type: i3.NgIf, selector: "[ngIf]", inputs: ["ngIf", "ngIfThen", "ngIfElse"] }, { type: i4.FsSkeletonContentDirective, selector: "[fsSkeleton]", inputs: ["fsSkeleton", "fsSkeletonPattern"] }], pipes: { "async": i3.AsyncPipe }, changeDetection: i0.ChangeDetectionStrategy.OnPush });
634
- i0.ɵɵngDeclareClassMetadata({ minVersion: "12.0.0", version: "12.2.16", ngImport: i0, type: FsHtmlEditorComponent, decorators: [{
635
- type: Component,
636
- args: [{
637
- selector: 'fs-html-editor',
638
- templateUrl: 'html-editor.component.html',
639
- styleUrls: ['html-editor.component.scss'],
640
- providers: [
641
- {
642
- provide: NG_VALUE_ACCESSOR,
643
- useExisting: forwardRef(() => FsHtmlEditorComponent),
644
- multi: true
645
- },
646
- {
647
- provide: NG_VALIDATORS,
648
- useExisting: forwardRef(() => FsHtmlEditorComponent),
649
- multi: true
650
- },
651
- ],
652
- changeDetection: ChangeDetectionStrategy.OnPush,
653
- }]
654
- }], ctorParameters: function () { return [{ type: undefined, decorators: [{
655
- type: Optional
656
- }, {
657
- type: Inject,
658
- args: [FS_HTML_EDITOR_CONFIG]
659
- }] }, { type: i0.ChangeDetectorRef }, { type: FsFroalaLoaderService }]; }, propDecorators: { classFocused: [{
660
- type: HostBinding,
661
- args: ['class.focused']
662
- }], classDisabled: [{
663
- type: HostBinding,
664
- args: ['class.disabled']
665
- }], elRef: [{
666
- type: ViewChild,
667
- args: ['elRef']
668
- }], config: [{
669
- type: Input
235
+ class FsHtmlEditorComponent {
236
+ constructor(_defaultConfig, _cdRef, _fr) {
237
+ this._defaultConfig = _defaultConfig;
238
+ this._cdRef = _cdRef;
239
+ this._fr = _fr;
240
+ this.classFocused = false;
241
+ this.classDisabled = false;
242
+ this.config = {};
243
+ this.initialized = false;
244
+ this._initialize$ = new ReplaySubject();
245
+ this._froalaReady$ = new BehaviorSubject(null);
246
+ this._destroy$ = new Subject();
247
+ this.onChange = (data) => { };
248
+ this.onTouched = () => { };
249
+ }
250
+ get el() {
251
+ return this.elRef.nativeElement;
252
+ }
253
+ get html() {
254
+ return this._html;
255
+ }
256
+ get editor() {
257
+ return this._editor;
258
+ }
259
+ get froalaLoaded$() {
260
+ return this._fr.loaded$;
261
+ }
262
+ ngOnInit() {
263
+ this.config = this.config || {};
264
+ this.config.autofocus = this.config.autofocus !== false && !this.config.disabled;
265
+ this.initialized = !this.config.initOnClick;
266
+ this._listenLazyInit();
267
+ }
268
+ ngAfterViewInit() {
269
+ if (!this.config.initOnClick || !this.hasContent()) {
270
+ this.initialized = true;
271
+ this._initialize$.next();
272
+ }
273
+ }
274
+ hasContent() {
275
+ const el = document.createElement('div');
276
+ if (el.querySelector('img')) {
277
+ return true;
278
+ }
279
+ el.innerHTML = this._html;
280
+ return !!el.innerText.length;
281
+ }
282
+ initialize(options = {}) {
283
+ const config = this._createConfig();
284
+ this._initPlugins(config);
285
+ // this.el.innerHTML = this._html || '';
286
+ this._editor = new this._fr.FroalaEditor(this.el, this._createOptions(), () => {
287
+ this._froalaReady$.next({ config, options });
288
+ });
289
+ }
290
+ _processImageUpload(blob) {
291
+ const processor = new FileProcessor();
292
+ const file = new FsFile(blob);
293
+ return processor.process([file], this.config.image)
294
+ .pipe(switchMap(([f]) => {
295
+ return this.config.image.upload(f.file);
296
+ }));
297
+ }
298
+ _getTextNode(node) {
299
+ if (node) {
300
+ if (node.nodeType === Node.TEXT_NODE) {
301
+ return node;
302
+ }
303
+ if (node.childNodes) {
304
+ return this._getTextNode(node.childNodes[0]);
305
+ }
306
+ }
307
+ }
308
+ uninitializedClick(event) {
309
+ if (!event.defaultPrevented) {
310
+ const target = event.target;
311
+ if (target && target.nodeName === 'A' && target.getAttribute('href')) {
312
+ const targetTarget = target.getAttribute('target');
313
+ target.setAttribute('target', '_blank');
314
+ setTimeout(() => {
315
+ if (targetTarget) {
316
+ target.setAttribute('target', targetTarget);
317
+ }
318
+ else {
319
+ target.removeAttribute('target');
320
+ }
321
+ });
322
+ }
323
+ else {
324
+ if (this.config.initClick) {
325
+ this.config.initClick(event);
326
+ }
327
+ this._initialize$.next();
328
+ this.initialized = true;
329
+ }
330
+ }
331
+ }
332
+ updateSize() {
333
+ // Hack: To trigger the toolbar button size modes
334
+ window.dispatchEvent(new Event('resize'));
335
+ }
336
+ validate(control) {
337
+ const err = {};
338
+ if (this.config.maxLength && this._html) {
339
+ const maxLength = this.config.maxLength;
340
+ const length = this._html.length;
341
+ if (length > maxLength) {
342
+ err.maxLengthError = `Must be ${maxLength} characters or fewer. You entered ${length} characters.`;
343
+ }
344
+ }
345
+ return Object.keys(err).length ? err : null;
346
+ }
347
+ focus(options) {
348
+ options = options ? options : {};
349
+ if (options.cursorPosition === 'end') {
350
+ this.editor.selection.setAtEnd(this.editor.$el.get(0));
351
+ }
352
+ else {
353
+ this.editor.selection.setAtStart(this.editor.$el.get(0));
354
+ }
355
+ this.editor.selection.restore();
356
+ const elSelection = this.editor.selection.element();
357
+ if (elSelection) {
358
+ elSelection.scrollIntoView({ block: 'center' });
359
+ }
360
+ }
361
+ clear() {
362
+ this.writeValue('');
363
+ }
364
+ disable() {
365
+ this.classDisabled = true;
366
+ }
367
+ setHtml(html) {
368
+ this.writeValue(html);
369
+ }
370
+ writeValue(html) {
371
+ this._html = html || '';
372
+ if (this.editor && this.editor.html) {
373
+ try {
374
+ this.editor.html.set(this._html);
375
+ }
376
+ catch (e) {
377
+ }
378
+ }
379
+ this._cdRef.markForCheck();
380
+ }
381
+ registerOnChange(fn) {
382
+ this.onChange = fn;
383
+ }
384
+ registerOnTouched(fn) {
385
+ this.onTouched = fn;
386
+ }
387
+ ngOnDestroy() {
388
+ this._initialize$.complete();
389
+ this._destroy$.next();
390
+ this._destroy$.complete();
391
+ this.destroy();
392
+ }
393
+ destroy() {
394
+ if (this.editor) {
395
+ this.editor.destroy();
396
+ }
397
+ this.initialized = false;
398
+ this._cdRef.markForCheck();
399
+ this.el.innerHTML = '';
400
+ }
401
+ _createConfig() {
402
+ return merge({ froalaConfig: {} }, this._defaultConfig, this.config);
403
+ }
404
+ _change(html) {
405
+ // this._html = html;
406
+ this.onChange(html);
407
+ }
408
+ _initPlugins(config) {
409
+ (config.plugins || []).forEach((plugin) => {
410
+ this._fr.FroalaEditor.PLUGINS[plugin.config.name] = function (editor) {
411
+ plugin.editor = editor;
412
+ plugin.initialize();
413
+ return plugin;
414
+ };
415
+ (plugin.config.buttons || []).forEach((button) => {
416
+ this._fr.FroalaEditor.DefineIcon(button.name, {
417
+ NAME: button.name,
418
+ PATH: button.svgPath,
419
+ });
420
+ this._fr.FroalaEditor.RegisterCommand(button.name, {
421
+ icon: button.name,
422
+ title: button.tooltip,
423
+ undo: button.undo,
424
+ focus: button.focus,
425
+ showOnMobile: button.showOnMobile,
426
+ refreshAfterCallback: button.refreshAfterCallback,
427
+ callback: function () {
428
+ if (button.click) {
429
+ button.click(this);
430
+ }
431
+ },
432
+ refresh: function (button) {
433
+ if (button.refresh) {
434
+ button.refresh(this, button);
435
+ }
436
+ }
437
+ });
438
+ });
439
+ });
440
+ }
441
+ _createOptions() {
442
+ const config = this._createConfig();
443
+ return merge(
444
+ // For some reason editor store somewhere pointer on default config object and dublicate options each time on init
445
+ // Extra merge level fixed this problem and allow to init config properly without legacy data
446
+ {}, {
447
+ shortcutsEnabled: ['show', 'bold', 'italic', 'underline', 'indent', 'outdent', 'undo', 'redo', 'insertImage', 'createLink'],
448
+ key: config.activationKey,
449
+ placeholderText: config.placeholder,
450
+ linkAlwaysBlank: true,
451
+ tabSpaces: 2,
452
+ typingTimer: 250,
453
+ tooltips: false,
454
+ wordPasteModal: false,
455
+ imageDefaultWidth: 0,
456
+ imageDefaultAlign: 'left',
457
+ quickInsertEnabled: false,
458
+ paragraphDefaultSelection: 'Format',
459
+ videoUpload: false,
460
+ paragraphFormat: {
461
+ N: 'Normal',
462
+ H1: 'Heading 1',
463
+ H2: 'Heading 2',
464
+ H3: 'Heading 3',
465
+ H4: 'Heading 4',
466
+ BLOCKQUOTE: 'Quote',
467
+ },
468
+ paragraphFormatSelection: true,
469
+ toolbarButtonsXS: {
470
+ moreText: {
471
+ buttons: TextButtons,
472
+ buttonsVisible: 1,
473
+ },
474
+ moreParagraph: {
475
+ buttons: ParagraphButtons,
476
+ buttonsVisible: 2,
477
+ },
478
+ moreRich: {
479
+ buttons: RichButtons,
480
+ buttonsVisible: 0,
481
+ },
482
+ },
483
+ toolbarButtons: {
484
+ moreText: {
485
+ buttons: TextButtons,
486
+ buttonsVisible: 3,
487
+ },
488
+ moreParagraph: {
489
+ buttons: ParagraphButtons,
490
+ buttonsVisible: 5,
491
+ },
492
+ moreRich: {
493
+ buttons: RichButtons,
494
+ buttonsVisible: 3,
495
+ },
496
+ },
497
+ }, config.froalaConfig);
498
+ }
499
+ _listenLazyInit() {
500
+ this.froalaLoaded$
501
+ .pipe(filter((ready) => ready), switchMap(() => this._initialize$), tap(() => {
502
+ const selection = window.getSelection();
503
+ const options = {};
504
+ if (selection.baseNode) {
505
+ options.selection = {
506
+ node: selection.baseNode.nodeValue,
507
+ offset: selection.baseOffset,
508
+ };
509
+ }
510
+ this.initialize(options);
511
+ }), switchMap(() => this._froalaReady$), filter((data) => !!data), tap(({ config, options }) => {
512
+ this._setupFroala(config, options);
513
+ }))
514
+ .subscribe();
515
+ }
516
+ _contentChanged() {
517
+ const editorHTML = this._editor.html.get();
518
+ if (this.html !== editorHTML) {
519
+ this._change(editorHTML);
520
+ }
521
+ }
522
+ _setupFroala(config, options) {
523
+ this._cdRef.markForCheck();
524
+ this.setHtml(this._html);
525
+ if (config.disabled) {
526
+ this.disable();
527
+ }
528
+ if (config.froalaConfig.events) {
529
+ if (config.froalaConfig.events.initialized) {
530
+ config.froalaConfig.events.initialized();
531
+ }
532
+ }
533
+ this._editor.events.on('focus', () => {
534
+ this.classFocused = true;
535
+ this._cdRef.markForCheck();
536
+ });
537
+ this._editor.events.on('blur', () => {
538
+ this.classFocused = false;
539
+ this._cdRef.markForCheck();
540
+ });
541
+ fromEventPattern((handler) => {
542
+ this._editor.events.on('contentChanged', handler);
543
+ }, () => { })
544
+ .pipe(startWith(this._html), map(() => this.editor.html.get()), distinctUntilChanged(), skip(1))
545
+ .subscribe(() => {
546
+ this._contentChanged();
547
+ });
548
+ // this._editor.events.on('contentChanged', () => {
549
+ // console.log('test');
550
+ // if (!this._firstChange) {
551
+ // this._contentChanged();
552
+ // }
553
+ // });
554
+ this._editor.events.on('paste.afterCleanup', (html) => {
555
+ var div = document.createElement('div');
556
+ div.innerHTML = html;
557
+ div.querySelectorAll('*')
558
+ .forEach((el) => {
559
+ for (var i = 0; i < el.attributes.length; i++) {
560
+ const name = el.attributes[0].name;
561
+ if (name !== 'href') {
562
+ el.removeAttribute(name);
563
+ }
564
+ }
565
+ });
566
+ return div.innerHTML;
567
+ });
568
+ this._editor.events.on('keydown', () => {
569
+ this.onTouched();
570
+ });
571
+ if (this.config.image && this.config.image.upload) {
572
+ this._editor.events.on('image.beforePasteUpload', (image) => {
573
+ fetch(image.getAttribute('src'))
574
+ .then((res) => {
575
+ res.blob()
576
+ .then((blob) => {
577
+ this._processImageUpload(blob)
578
+ .pipe(takeUntil(this._destroy$))
579
+ .subscribe((url) => {
580
+ image.setAttribute('src', url);
581
+ image.removeAttribute('data-fr-image-pasted');
582
+ this._contentChanged();
583
+ });
584
+ });
585
+ });
586
+ return false;
587
+ });
588
+ this._editor.events.on('image.beforeUpload', (blobs) => {
589
+ this._processImageUpload(blobs[0])
590
+ .pipe(takeUntil(this._destroy$))
591
+ .subscribe((url) => {
592
+ this.editor.image.insert(url, null, null, this.editor.image.get());
593
+ });
594
+ return false;
595
+ });
596
+ }
597
+ if (this.el.querySelector('.fr-second-toolbar')) {
598
+ this.el.querySelector('.fr-second-toolbar').remove();
599
+ }
600
+ const selection = options.selection;
601
+ if (selection) {
602
+ const node = Array.from(this.el.querySelectorAll('.fr-element *')).find((node) => {
603
+ return selection.node === node.textContent;
604
+ });
605
+ if (node) {
606
+ const range = document.createRange();
607
+ const sel = window.getSelection();
608
+ range.setStart(this._getTextNode(node), selection.offset);
609
+ range.collapse(true);
610
+ sel.removeAllRanges();
611
+ sel.addRange(range);
612
+ }
613
+ else if (this.config.autofocus) {
614
+ this.focus();
615
+ }
616
+ }
617
+ else if (this.config.autofocus) {
618
+ this.focus();
619
+ }
620
+ }
621
+ }
622
+ FsHtmlEditorComponent.ɵfac = i0.ɵɵngDeclareFactory({ minVersion: "12.0.0", version: "12.2.16", ngImport: i0, type: FsHtmlEditorComponent, deps: [{ token: FS_HTML_EDITOR_CONFIG, optional: true }, { token: i0.ChangeDetectorRef }, { token: FsFroalaLoaderService }], target: i0.ɵɵFactoryTarget.Component });
623
+ FsHtmlEditorComponent.ɵcmp = i0.ɵɵngDeclareComponent({ minVersion: "12.0.0", version: "12.2.16", type: FsHtmlEditorComponent, selector: "fs-html-editor", inputs: { config: "config" }, host: { properties: { "class.focused": "this.classFocused", "class.disabled": "this.classDisabled" } }, providers: [
624
+ {
625
+ provide: NG_VALUE_ACCESSOR,
626
+ useExisting: forwardRef(() => FsHtmlEditorComponent),
627
+ multi: true
628
+ },
629
+ {
630
+ provide: NG_VALIDATORS,
631
+ useExisting: forwardRef(() => FsHtmlEditorComponent),
632
+ multi: true
633
+ },
634
+ ], viewQueries: [{ propertyName: "elRef", first: true, predicate: ["elRef"], descendants: true }], ngImport: i0, 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", 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-more-toolbar,:host ::ng-deep .fr-toolbar,:host ::ng-deep .fr-dropdown:after,:host ::ng-deep .fr-dropdown-menu .fr-dropdown-wrapper{transition:none!important}:host ::ng-deep .fr-toolbar.fr-top{position:sticky;z-index:2;border-radius:0;background-color:#fff}:host ::ng-deep .fr-toolbar.fr-top .fr-btn-grp{margin:0 20px 0 0}:host ::ng-deep .fr-toolbar.fr-top .fr-btn-grp:nth-child(1):after,:host ::ng-deep .fr-toolbar.fr-top .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.fr-top div:first-of-type:before{border:none}:host ::ng-deep .fr-toolbar.fr-top.fr-toolbar-open .fr-newline{height:auto}:host ::ng-deep .fr-toolbar.fr-top .fr-btn-grp:first-child{margin-left:0}:host ::ng-deep .fr-toolbar.fr-top.fr-top{border:0}:host ::ng-deep .fr-toolbar.fr-top .fr-newline{margin:0}:host ::ng-deep .fr-toolbar.fr-top .fr-more-toolbar{z-index:auto}:host ::ng-deep .fr-toolbar.fr-top .fr-command.fr-btn{z-index:auto}:host ::ng-deep .fr-toolbar.fr-top .fr-command.fr-btn.fr-dropdown:after{right:3px}:host ::ng-deep .fr-toolbar.fr-top .fr-command.fr-btn.fr-dropdown.fr-selection span{margin-right:24px}:host ::ng-deep .fr-toolbar.fr-top .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 #0003,0 4px 5px #00000024,0 1px 10px #0000001f;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}\n"], components: [{ type: FsHtmlRendererComponent, selector: "fs-html-renderer", inputs: ["html"] }], directives: [{ type: i3.NgIf, selector: "[ngIf]", inputs: ["ngIf", "ngIfThen", "ngIfElse"] }, { type: i4.FsSkeletonContentDirective, selector: "[fsSkeleton]", inputs: ["fsSkeleton", "fsSkeletonPattern"] }], pipes: { "async": i3.AsyncPipe }, changeDetection: i0.ChangeDetectionStrategy.OnPush });
635
+ i0.ɵɵngDeclareClassMetadata({ minVersion: "12.0.0", version: "12.2.16", ngImport: i0, type: FsHtmlEditorComponent, decorators: [{
636
+ type: Component,
637
+ args: [{
638
+ selector: 'fs-html-editor',
639
+ templateUrl: 'html-editor.component.html',
640
+ styleUrls: ['html-editor.component.scss'],
641
+ providers: [
642
+ {
643
+ provide: NG_VALUE_ACCESSOR,
644
+ useExisting: forwardRef(() => FsHtmlEditorComponent),
645
+ multi: true
646
+ },
647
+ {
648
+ provide: NG_VALIDATORS,
649
+ useExisting: forwardRef(() => FsHtmlEditorComponent),
650
+ multi: true
651
+ },
652
+ ],
653
+ changeDetection: ChangeDetectionStrategy.OnPush,
654
+ }]
655
+ }], ctorParameters: function () { return [{ type: undefined, decorators: [{
656
+ type: Optional
657
+ }, {
658
+ type: Inject,
659
+ args: [FS_HTML_EDITOR_CONFIG]
660
+ }] }, { type: i0.ChangeDetectorRef }, { type: FsFroalaLoaderService }]; }, propDecorators: { classFocused: [{
661
+ type: HostBinding,
662
+ args: ['class.focused']
663
+ }], classDisabled: [{
664
+ type: HostBinding,
665
+ args: ['class.disabled']
666
+ }], elRef: [{
667
+ type: ViewChild,
668
+ args: ['elRef']
669
+ }], config: [{
670
+ type: Input
670
671
  }] } });
671
672
 
672
- class FsHtmlEditorModule {
673
- static forRoot(config = {}) {
674
- return {
675
- ngModule: FsHtmlEditorModule,
676
- providers: [
677
- { provide: FS_HTML_EDITOR_DEFAULT_CONFIG, useValue: config },
678
- {
679
- provide: FS_HTML_EDITOR_CONFIG,
680
- useFactory: FsHtmlEditorConfigFactory,
681
- deps: [FS_HTML_EDITOR_DEFAULT_CONFIG]
682
- }
683
- ]
684
- };
685
- }
686
- }
687
- FsHtmlEditorModule.ɵfac = i0.ɵɵngDeclareFactory({ minVersion: "12.0.0", version: "12.2.16", ngImport: i0, type: FsHtmlEditorModule, deps: [], target: i0.ɵɵFactoryTarget.NgModule });
688
- FsHtmlEditorModule.ɵmod = i0.ɵɵngDeclareNgModule({ minVersion: "12.0.0", version: "12.2.16", ngImport: i0, type: FsHtmlEditorModule, declarations: [FsHtmlEditorComponent,
689
- FsHtmlRendererComponent], imports: [CommonModule,
690
- FsSkeletonModule], exports: [FsHtmlEditorComponent,
691
- FsHtmlRendererComponent] });
692
- FsHtmlEditorModule.ɵinj = i0.ɵɵngDeclareInjector({ minVersion: "12.0.0", version: "12.2.16", ngImport: i0, type: FsHtmlEditorModule, imports: [[
693
- CommonModule,
694
- FsSkeletonModule,
695
- ]] });
696
- i0.ɵɵngDeclareClassMetadata({ minVersion: "12.0.0", version: "12.2.16", ngImport: i0, type: FsHtmlEditorModule, decorators: [{
697
- type: NgModule,
698
- args: [{
699
- imports: [
700
- CommonModule,
701
- FsSkeletonModule,
702
- ],
703
- exports: [
704
- FsHtmlEditorComponent,
705
- FsHtmlRendererComponent,
706
- ],
707
- declarations: [
708
- FsHtmlEditorComponent,
709
- FsHtmlRendererComponent,
710
- ],
711
- }]
712
- }] });
713
- function FsHtmlEditorConfigFactory(config) {
714
- return Object.assign({ defaultPlugins: [
715
- "align" /* Align */,
716
- "colors" /* Colors */,
717
- "image" /* Image */,
718
- "link" /* Link */,
719
- "lists" /* Lists */,
720
- "paragraph_format" /* ParagraphFormat */,
721
- "quote" /* Quote */,
722
- "table" /* Table */,
723
- "url" /* Url */,
724
- "video" /* Video */,
725
- "draggable" /* Draggable */,
726
- "font_size" /* FontSize */,
727
- ] }, config);
673
+ class FsHtmlEditorModule {
674
+ static forRoot(config = {}) {
675
+ return {
676
+ ngModule: FsHtmlEditorModule,
677
+ providers: [
678
+ { provide: FS_HTML_EDITOR_DEFAULT_CONFIG, useValue: config },
679
+ {
680
+ provide: FS_HTML_EDITOR_CONFIG,
681
+ useFactory: FsHtmlEditorConfigFactory,
682
+ deps: [FS_HTML_EDITOR_DEFAULT_CONFIG]
683
+ }
684
+ ]
685
+ };
686
+ }
687
+ }
688
+ FsHtmlEditorModule.ɵfac = i0.ɵɵngDeclareFactory({ minVersion: "12.0.0", version: "12.2.16", ngImport: i0, type: FsHtmlEditorModule, deps: [], target: i0.ɵɵFactoryTarget.NgModule });
689
+ FsHtmlEditorModule.ɵmod = i0.ɵɵngDeclareNgModule({ minVersion: "12.0.0", version: "12.2.16", ngImport: i0, type: FsHtmlEditorModule, declarations: [FsHtmlEditorComponent,
690
+ FsHtmlRendererComponent], imports: [CommonModule,
691
+ FsSkeletonModule], exports: [FsHtmlEditorComponent,
692
+ FsHtmlRendererComponent] });
693
+ FsHtmlEditorModule.ɵinj = i0.ɵɵngDeclareInjector({ minVersion: "12.0.0", version: "12.2.16", ngImport: i0, type: FsHtmlEditorModule, imports: [[
694
+ CommonModule,
695
+ FsSkeletonModule,
696
+ ]] });
697
+ i0.ɵɵngDeclareClassMetadata({ minVersion: "12.0.0", version: "12.2.16", ngImport: i0, type: FsHtmlEditorModule, decorators: [{
698
+ type: NgModule,
699
+ args: [{
700
+ imports: [
701
+ CommonModule,
702
+ FsSkeletonModule,
703
+ ],
704
+ exports: [
705
+ FsHtmlEditorComponent,
706
+ FsHtmlRendererComponent,
707
+ ],
708
+ declarations: [
709
+ FsHtmlEditorComponent,
710
+ FsHtmlRendererComponent,
711
+ ],
712
+ }]
713
+ }] });
714
+ function FsHtmlEditorConfigFactory(config) {
715
+ return Object.assign({ defaultPlugins: [
716
+ "align" /* Align */,
717
+ "colors" /* Colors */,
718
+ "image" /* Image */,
719
+ "link" /* Link */,
720
+ "lists" /* Lists */,
721
+ "paragraph_format" /* ParagraphFormat */,
722
+ "quote" /* Quote */,
723
+ "table" /* Table */,
724
+ "url" /* Url */,
725
+ "video" /* Video */,
726
+ "draggable" /* Draggable */,
727
+ "font_size" /* FontSize */,
728
+ ] }, config);
728
729
  }
729
730
 
730
- class Plugin {
731
- initialize() { }
732
- destroy() { }
731
+ class Plugin {
732
+ initialize() { }
733
+ destroy() { }
733
734
  }
734
735
 
735
- class MentionPlugin extends Plugin {
736
- constructor(config) {
737
- super();
738
- this.config = config;
739
- this._guid = guid();
740
- this.selected = (event) => {
741
- if (this.config.selected) {
742
- if (MentionPlugin._currentGuid === this._guid) {
743
- this.config.selected(event.detail.item.original);
744
- }
745
- }
746
- };
747
- this.config = Object.assign(Object.assign({}, config), { buttons: [
748
- {
749
- name: config.name,
750
- tooltip: config.tooltip,
751
- svgPath: config.iconPath,
752
- click: (editor) => {
753
- this._closeAll();
754
- this._tribute.showMenuForCollection(editor.el);
755
- }
756
- }
757
- ] });
758
- this._tribute = new Tribute({
759
- values: debounce(this._loadValues.bind(this), 200),
760
- searchOpts: {
761
- pre: '',
762
- post: '',
763
- skip: true
764
- },
765
- containerClass: `fs-html-editor-mention-container ${this.config.containerClass || ''}`,
766
- itemClass: `fs-html-editor-mention-menu-item ${this.config.menuItemClass || ''}`,
767
- trigger: this.config.trigger,
768
- allowSpaces: true,
769
- menuItemTemplate: (item) => {
770
- return this.config.menuItemTemplate(item.original);
771
- },
772
- selectTemplate: (item) => {
773
- const template = this.config.selectedTemplate(item.original);
774
- let p = document.createElement('p');
775
- p.innerHTML = template;
776
- let node = p.firstElementChild;
777
- if (!node) {
778
- node = document.createElement('span');
779
- node.innerHTML = template;
780
- }
781
- node.setAttribute('contenteditable', 'false');
782
- node.classList.add('fr-deletable');
783
- return node.outerHTML;
784
- },
785
- });
786
- MentionPlugin._tributes.push(this._tribute);
787
- }
788
- initialize() {
789
- this._tribute.attach(this.editor.el);
790
- this.editor.events.on('keydown', (e) => {
791
- if (e.key === 'Enter' && this._tribute.isActive) {
792
- return false;
793
- }
794
- }, true);
795
- this.editor.el.addEventListener("tribute-replaced", this.selected);
796
- }
797
- destroy() {
798
- this.editor.el.removeEventListener("tribute-replaced", this.selected);
799
- }
800
- _closeAll() {
801
- MentionPlugin._tributes.forEach((tribute) => {
802
- if (tribute.menu) {
803
- tribute.hideMenu();
804
- }
805
- });
806
- }
807
- _loadValues(keyword, cb) {
808
- MentionPlugin._currentGuid = this._guid;
809
- return this.config.fetch(keyword)
810
- .subscribe((data) => {
811
- cb(data);
812
- });
813
- }
814
- }
815
- MentionPlugin._currentGuid = null;
736
+ class MentionPlugin extends Plugin {
737
+ constructor(config) {
738
+ super();
739
+ this.config = config;
740
+ this._guid = guid();
741
+ this.selected = (event) => {
742
+ if (this.config.selected) {
743
+ if (MentionPlugin._currentGuid === this._guid) {
744
+ this.config.selected(event.detail.item.original);
745
+ }
746
+ }
747
+ };
748
+ this.config = Object.assign(Object.assign({}, config), { buttons: [
749
+ {
750
+ name: config.name,
751
+ tooltip: config.tooltip,
752
+ svgPath: config.iconPath,
753
+ click: (editor) => {
754
+ this._closeAll();
755
+ this._tribute.showMenuForCollection(editor.el);
756
+ }
757
+ }
758
+ ] });
759
+ this._tribute = new Tribute({
760
+ values: debounce(this._loadValues.bind(this), 200),
761
+ searchOpts: {
762
+ pre: '',
763
+ post: '',
764
+ skip: true
765
+ },
766
+ containerClass: `fs-html-editor-mention-container ${this.config.containerClass || ''}`,
767
+ itemClass: `fs-html-editor-mention-menu-item ${this.config.menuItemClass || ''}`,
768
+ trigger: this.config.trigger,
769
+ allowSpaces: true,
770
+ menuItemTemplate: (item) => {
771
+ return this.config.menuItemTemplate(item.original);
772
+ },
773
+ selectTemplate: (item) => {
774
+ const template = this.config.selectedTemplate(item.original);
775
+ let p = document.createElement('p');
776
+ p.innerHTML = template;
777
+ let node = p.firstElementChild;
778
+ if (!node) {
779
+ node = document.createElement('span');
780
+ node.innerHTML = template;
781
+ }
782
+ node.setAttribute('contenteditable', 'false');
783
+ node.classList.add('fr-deletable');
784
+ return node.outerHTML;
785
+ },
786
+ });
787
+ MentionPlugin._tributes.push(this._tribute);
788
+ }
789
+ initialize() {
790
+ this._tribute.attach(this.editor.el);
791
+ this.editor.events.on('keydown', (e) => {
792
+ if (e.key === 'Enter' && this._tribute.isActive) {
793
+ return false;
794
+ }
795
+ }, true);
796
+ this.editor.el.addEventListener("tribute-replaced", this.selected);
797
+ }
798
+ destroy() {
799
+ this.editor.el.removeEventListener("tribute-replaced", this.selected);
800
+ }
801
+ _closeAll() {
802
+ MentionPlugin._tributes.forEach((tribute) => {
803
+ if (tribute.menu) {
804
+ tribute.hideMenu();
805
+ }
806
+ });
807
+ }
808
+ _loadValues(keyword, cb) {
809
+ MentionPlugin._currentGuid = this._guid;
810
+ return this.config.fetch(keyword)
811
+ .subscribe((data) => {
812
+ cb(data);
813
+ });
814
+ }
815
+ }
816
+ MentionPlugin._currentGuid = null;
816
817
  MentionPlugin._tributes = [];
817
818
 
818
- class ChecklistPlugin extends Plugin {
819
- constructor(config = { name: 'checklist' }) {
820
- super();
821
- this.config = config;
822
- this.config = Object.assign(Object.assign({}, config), { name: 'checklist', buttons: [
823
- {
824
- name: 'checklist',
825
- svgPath: 'M8.4,10.3l-1.2,1.2l4,4L20,6.7l-1.2-1.2l-7.6,7.6L8.4,10.3z M18.2,18.2H5.8V5.8h8.9V4H5.8C4.8,4,4,4.8,4,5.8v12.4c0,1,0.8,1.8,1.8,1.8h12.4c1,0,1.8-0.8,1.8-1.8v-7.1h-1.8V18.2z',
826
- click: (editor) => {
827
- editor.html.insert('<ul class="checklist"><li></li></ul>');
828
- }
829
- }
830
- ] });
831
- }
832
- initialize() {
833
- this.editor.events.on('click', (e) => {
834
- const li = e.target;
835
- if (li.nodeName === 'LI' && e.offsetX < 0) {
836
- const items = [li, ...li.querySelectorAll('li')];
837
- if (li.classList.contains('checked')) {
838
- items.forEach((item) => {
839
- item.classList.remove('checked');
840
- });
841
- }
842
- else {
843
- items.forEach((item) => {
844
- item.classList.add('checked');
845
- });
846
- }
847
- }
848
- }, false);
849
- }
819
+ class ChecklistPlugin extends Plugin {
820
+ constructor(config = { name: 'checklist' }) {
821
+ super();
822
+ this.config = config;
823
+ this.config = Object.assign(Object.assign({}, config), { name: 'checklist', buttons: [
824
+ {
825
+ name: 'checklist',
826
+ svgPath: 'M8.4,10.3l-1.2,1.2l4,4L20,6.7l-1.2-1.2l-7.6,7.6L8.4,10.3z M18.2,18.2H5.8V5.8h8.9V4H5.8C4.8,4,4,4.8,4,5.8v12.4c0,1,0.8,1.8,1.8,1.8h12.4c1,0,1.8-0.8,1.8-1.8v-7.1h-1.8V18.2z',
827
+ click: (editor) => {
828
+ editor.html.insert('<ul class="checklist"><li></li></ul>');
829
+ }
830
+ }
831
+ ] });
832
+ }
833
+ initialize() {
834
+ this.editor.events.on('click', (e) => {
835
+ const li = e.target;
836
+ if (li.nodeName === 'LI' && e.offsetX < 0) {
837
+ const items = [li, ...li.querySelectorAll('li')];
838
+ if (li.classList.contains('checked')) {
839
+ items.forEach((item) => {
840
+ item.classList.remove('checked');
841
+ });
842
+ }
843
+ else {
844
+ items.forEach((item) => {
845
+ item.classList.add('checked');
846
+ });
847
+ }
848
+ }
849
+ }, false);
850
+ }
850
851
  }
851
852
 
852
- class CodePlugin extends Plugin {
853
- constructor(config = { name: 'code' }) {
854
- super();
855
- this.config = config;
856
- this.config = Object.assign(Object.assign({}, config), { name: 'code', buttons: [
857
- {
858
- name: 'code',
859
- svgPath: 'M8.9,7.3L4.2,12l4.7,4.7l1.1-1.1L6.4,12L10,8.4L8.9,7.3z M15.1,7.3L14,8.4l3.6,3.6L14,15.6l1.1,1.1l4.7-4.7L15.1,7.3z',
860
- click: (editor) => {
861
- const node = editor.selection.get();
862
- const codeEl = this._getCodeEl(node.baseNode);
863
- if (codeEl) {
864
- codeEl.classList.remove('code');
865
- }
866
- else {
867
- editor.html.insert('<p class="code">' + editor.selection.get().toString().replace(/\n{1,}/g, '<br>') + '</p>');
868
- }
869
- }
870
- }
871
- ] });
872
- }
873
- initialize() {
874
- this.editor.events.on('keydown', (e) => {
875
- if (e.keyCode === 13) {
876
- const selection = this.editor.selection.get();
877
- if (selection && this._getCodeEl(selection.baseNode)) {
878
- e.preventDefault();
879
- e.stopPropagation();
880
- e.stopImmediatePropagation();
881
- let br = '<br>';
882
- const base = selection.baseNode;
883
- if (base.nodeName === '#text' && selection.baseOffset === base.length) {
884
- if (!(base.nextSibling && base.nextSibling.nodeName === 'BR')) {
885
- br += '<br>';
886
- }
887
- }
888
- else {
889
- const el = Array.from(base.childNodes).splice(selection.baseOffset - 1, 1).pop();
890
- if (el && el.nodeName !== 'BR') {
891
- br += '<br>';
892
- }
893
- }
894
- this.editor.html.insert(br);
895
- return false;
896
- }
897
- }
898
- }, true);
899
- }
900
- destroy() { }
901
- _getCodeEl(el) {
902
- if (el) {
903
- if (el.classList && el.classList.contains('code')) {
904
- return el;
905
- }
906
- if (el.parentElement) {
907
- return this._getCodeEl(el.parentElement);
908
- }
909
- }
910
- return null;
911
- }
853
+ class CodePlugin extends Plugin {
854
+ constructor(config = { name: 'code' }) {
855
+ super();
856
+ this.config = config;
857
+ this.config = Object.assign(Object.assign({}, config), { name: 'code', buttons: [
858
+ {
859
+ name: 'code',
860
+ svgPath: 'M8.9,7.3L4.2,12l4.7,4.7l1.1-1.1L6.4,12L10,8.4L8.9,7.3z M15.1,7.3L14,8.4l3.6,3.6L14,15.6l1.1,1.1l4.7-4.7L15.1,7.3z',
861
+ click: (editor) => {
862
+ const node = editor.selection.get();
863
+ const codeEl = this._getCodeEl(node.baseNode);
864
+ if (codeEl) {
865
+ codeEl.classList.remove('code');
866
+ }
867
+ else {
868
+ editor.html.insert('<p class="code">' + editor.selection.get().toString().replace(/\n{1,}/g, '<br>') + '</p>');
869
+ }
870
+ }
871
+ }
872
+ ] });
873
+ }
874
+ initialize() {
875
+ this.editor.events.on('keydown', (e) => {
876
+ if (e.keyCode === 13) {
877
+ const selection = this.editor.selection.get();
878
+ if (selection && this._getCodeEl(selection.baseNode)) {
879
+ e.preventDefault();
880
+ e.stopPropagation();
881
+ e.stopImmediatePropagation();
882
+ let br = '<br>';
883
+ const base = selection.baseNode;
884
+ if (base.nodeName === '#text' && selection.baseOffset === base.length) {
885
+ if (!(base.nextSibling && base.nextSibling.nodeName === 'BR')) {
886
+ br += '<br>';
887
+ }
888
+ }
889
+ else {
890
+ const el = Array.from(base.childNodes).splice(selection.baseOffset - 1, 1).pop();
891
+ if (el && el.nodeName !== 'BR') {
892
+ br += '<br>';
893
+ }
894
+ }
895
+ this.editor.html.insert(br);
896
+ return false;
897
+ }
898
+ }
899
+ }, true);
900
+ }
901
+ destroy() { }
902
+ _getCodeEl(el) {
903
+ if (el) {
904
+ if (el.classList && el.classList.contains('code')) {
905
+ return el;
906
+ }
907
+ if (el.parentElement) {
908
+ return this._getCodeEl(el.parentElement);
909
+ }
910
+ }
911
+ return null;
912
+ }
912
913
  }
913
914
 
914
- class ScreenRecordPlugin extends Plugin {
915
- constructor(config = {}) {
916
- super();
917
- this.config = config;
918
- this.config = Object.assign(Object.assign({}, config), { name: config.name || 'screenRecord', buttons: [
919
- {
920
- name: 'screenRecord',
915
+ class ScreenRecordPlugin extends Plugin {
916
+ constructor(config = {}) {
917
+ super();
918
+ this.config = config;
919
+ this.config = Object.assign(Object.assign({}, config), { name: config.name || 'screenRecord', buttons: [
920
+ {
921
+ name: 'screenRecord',
921
922
  svgPath: `M14.7,7.7v6.1H7.1V7.7H14.7 M16.3,9.6V6.9c0-0.4-0.3-0.8-0.8-0.8H6.4c-0.4,0-0.8,0.3-0.8,0.8v7.6c0,0.4,0.3,0.8,0.8,0.8h9.1c0.4,0,0.8-0.3,0.8-0.8v-2.7l1.7,1.7c0.3,0.3,0.8,0.3,1.1,0c0.1-0.1,0.2-0.3,0.2-0.5V8.4c0-0.4-0.3-0.8-0.8-0.8
922
923
  c-0.2,0-0.4,0.1-0.5,0.2L16.3,9.6z M21.5,1.6H2.9c-0.7,0-1.3,0.7-1.3,1.6v14.6c0,0.9,0.6,1.6,1.3,1.6h7.6v1.1l-5,1c-0.2,0-0.4,0.3-0.4,0.6c0,0.3,0.2,0.4,0.4,0.4c0,0,0,0,0.1,0l5.3-1h2.6l5.3,1c0,0,0,0,0.1,0c0.2,0,0.4-0.2,0.4-0.4
923
- c0-0.3-0.1-0.6-0.4-0.6l-5-1v-1.1h7.6c0.7,0,1.3-0.7,1.3-1.6V3.2C22.9,2.3,22.3,1.6,21.5,1.6z M21.1,17.3H3.3V3.7h17.8L21.1,17.3L21.1,17.3z`,
924
- tooltip: 'Screen Record',
925
- click: (editor) => {
926
- navigator.mediaDevices.getDisplayMedia({ video: true })
927
- .then((stream) => {
928
- const chunks = [];
929
- const options = { mimeType: 'video/webm; codecs=vp9' };
930
- let mediaRecorder = new MediaRecorder(stream, options);
931
- stream.addEventListener('inactive', (e) => {
932
- mediaRecorder.stop();
933
- mediaRecorder = null;
934
- stream.getTracks().forEach((track) => track.stop());
935
- stream = null;
936
- const blob = new Blob(chunks, { type: 'video/webm' });
937
- config.upload(blob)
938
- .subscribe((url) => {
939
- editor.html.insert(`<span class="fr-screen-record fr-deletable fr-draggable"><video controls style="max-width:${config.maxWidth}"><source src="${url}" type="video/webm"></video></span>`);
940
- });
941
- });
942
- mediaRecorder.addEventListener('dataavailable', (event) => {
943
- if (event.data && event.data.size > 0) {
944
- chunks.push(event.data);
945
- }
946
- });
947
- mediaRecorder.start(10);
948
- })
949
- .catch((e) => { });
950
- }
951
- }
952
- ] });
953
- }
954
- initialize() {
955
- return __awaiter(this, void 0, void 0, function* () {
956
- yield ResourceLoader.loadStyles('froala')
957
- .toPromise();
958
- const FroalaEditor = window.FroalaEditor;
959
- this.editor.events.on('mouseup', (e) => {
960
- const el = this._getEl(e.target);
961
- if (el) {
962
- this.editor.popups.hideAll();
963
- this._activeEl = el;
964
- this._showPopup(el);
965
- }
966
- });
967
- FroalaEditor.POPUP_TEMPLATES["screenRecordPlugin.popup"] = '[_BUTTONS_]';
968
- FroalaEditor.DefineIcon('popupClose', { NAME: 'trash', SVG_KEY: 'remove' });
969
- FroalaEditor.RegisterCommand('popupClose', {
970
- title: 'Remove',
971
- undo: false,
972
- focus: false,
973
- callback: () => {
974
- if (this._activeEl) {
975
- this._activeEl.remove();
976
- }
977
- }
978
- });
979
- });
980
- }
981
- _createPopup() {
982
- const template = {
983
- buttons: `<div class="fr-buttons">${this.editor.button.buildList(['popupClose'])}</div>`,
984
- };
985
- return this.editor.popups.create('screenRecordPlugin.popup', template);
986
- }
987
- _showPopup(el) {
988
- var $popup = this.editor.popups.get('screenRecordPlugin.popup');
989
- if (!$popup) {
990
- $popup = this._createPopup();
991
- }
992
- this.editor.popups.setContainer('screenRecordPlugin.popup', this.editor.$(el));
993
- const left = el.offsetLeft + el.offsetWidth / 2;
994
- this.editor.popups.show('screenRecordPlugin.popup', left, null);
995
- }
996
- _getEl(el) {
997
- if (el && el.classList) {
998
- if (el.classList.contains('fr-screen-record'))
999
- return el;
1000
- return this._getEl(el.parentNode);
1001
- }
1002
- }
924
+ c0-0.3-0.1-0.6-0.4-0.6l-5-1v-1.1h7.6c0.7,0,1.3-0.7,1.3-1.6V3.2C22.9,2.3,22.3,1.6,21.5,1.6z M21.1,17.3H3.3V3.7h17.8L21.1,17.3L21.1,17.3z`,
925
+ tooltip: 'Screen Record',
926
+ click: (editor) => {
927
+ navigator.mediaDevices.getDisplayMedia({ video: true })
928
+ .then((stream) => {
929
+ const chunks = [];
930
+ const options = { mimeType: 'video/webm; codecs=vp9' };
931
+ let mediaRecorder = new MediaRecorder(stream, options);
932
+ stream.addEventListener('inactive', (e) => {
933
+ mediaRecorder.stop();
934
+ mediaRecorder = null;
935
+ stream.getTracks().forEach((track) => track.stop());
936
+ stream = null;
937
+ const blob = new Blob(chunks, { type: 'video/webm' });
938
+ config.upload(blob)
939
+ .subscribe((url) => {
940
+ editor.html.insert(`<span class="fr-screen-record fr-deletable fr-draggable"><video controls style="max-width:${config.maxWidth}"><source src="${url}" type="video/webm"></video></span>`);
941
+ });
942
+ });
943
+ mediaRecorder.addEventListener('dataavailable', (event) => {
944
+ if (event.data && event.data.size > 0) {
945
+ chunks.push(event.data);
946
+ }
947
+ });
948
+ mediaRecorder.start(10);
949
+ })
950
+ .catch((e) => { });
951
+ }
952
+ }
953
+ ] });
954
+ }
955
+ initialize() {
956
+ return __awaiter(this, void 0, void 0, function* () {
957
+ yield ResourceLoader.loadStyles('froala')
958
+ .toPromise();
959
+ const FroalaEditor = window.FroalaEditor;
960
+ this.editor.events.on('mouseup', (e) => {
961
+ const el = this._getEl(e.target);
962
+ if (el) {
963
+ this.editor.popups.hideAll();
964
+ this._activeEl = el;
965
+ this._showPopup(el);
966
+ }
967
+ });
968
+ FroalaEditor.POPUP_TEMPLATES["screenRecordPlugin.popup"] = '[_BUTTONS_]';
969
+ FroalaEditor.DefineIcon('popupClose', { NAME: 'trash', SVG_KEY: 'remove' });
970
+ FroalaEditor.RegisterCommand('popupClose', {
971
+ title: 'Remove',
972
+ undo: false,
973
+ focus: false,
974
+ callback: () => {
975
+ if (this._activeEl) {
976
+ this._activeEl.remove();
977
+ }
978
+ }
979
+ });
980
+ });
981
+ }
982
+ _createPopup() {
983
+ const template = {
984
+ buttons: `<div class="fr-buttons">${this.editor.button.buildList(['popupClose'])}</div>`,
985
+ };
986
+ return this.editor.popups.create('screenRecordPlugin.popup', template);
987
+ }
988
+ _showPopup(el) {
989
+ var $popup = this.editor.popups.get('screenRecordPlugin.popup');
990
+ if (!$popup) {
991
+ $popup = this._createPopup();
992
+ }
993
+ this.editor.popups.setContainer('screenRecordPlugin.popup', this.editor.$(el));
994
+ const left = el.offsetLeft + el.offsetWidth / 2;
995
+ this.editor.popups.show('screenRecordPlugin.popup', left, null);
996
+ }
997
+ _getEl(el) {
998
+ if (el && el.classList) {
999
+ if (el.classList.contains('fr-screen-record'))
1000
+ return el;
1001
+ return this._getEl(el.parentNode);
1002
+ }
1003
+ }
1003
1004
  }
1004
1005
 
1005
- /**
1006
- * Generated bundle index. Do not edit.
1006
+ /**
1007
+ * Generated bundle index. Do not edit.
1007
1008
  */
1008
1009
 
1009
1010
  export { ChecklistPlugin, CodePlugin, FS_HTML_EDITOR_CONFIG, FsHtmlEditorComponent, FsHtmlEditorModule, FsHtmlRendererComponent, MentionPlugin, ParagraphButtons, RichButtons, ScreenRecordPlugin, TextButtons };