Commit b459d75fb6c0f9d12af8a634c602f67f06159bd8

Authored by Vladyslav
Committed by GitHub
1 parent c654f1ad

Improvement resize (#2654)

@@ -65,7 +65,7 @@ export class CustomActionPrettyResourcesTabsComponent extends PageComponent impl @@ -65,7 +65,7 @@ export class CustomActionPrettyResourcesTabsComponent extends PageComponent impl
65 65
66 aceEditors: ace.Ace.Editor[] = []; 66 aceEditors: ace.Ace.Editor[] = [];
67 editorsResizeCafs: {[editorId: string]: CancelAnimationFrame} = {}; 67 editorsResizeCafs: {[editorId: string]: CancelAnimationFrame} = {};
68 - aceResizeObservers: ResizeObserver[] = []; 68 + aceResize$: ResizeObserver;
69 htmlEditor: ace.Ace.Editor; 69 htmlEditor: ace.Ace.Editor;
70 cssEditor: ace.Ace.Editor; 70 cssEditor: ace.Ace.Editor;
71 setValuesPending = false; 71 setValuesPending = false;
@@ -85,9 +85,7 @@ export class CustomActionPrettyResourcesTabsComponent extends PageComponent impl @@ -85,9 +85,7 @@ export class CustomActionPrettyResourcesTabsComponent extends PageComponent impl
85 } 85 }
86 86
87 ngOnDestroy(): void { 87 ngOnDestroy(): void {
88 - this.aceResizeObservers.forEach((resize$) => {  
89 - resize$.disconnect();  
90 - }); 88 + this.aceResize$.disconnect();
91 } 89 }
92 90
93 ngOnChanges(changes: SimpleChanges): void { 91 ngOnChanges(changes: SimpleChanges): void {
@@ -153,6 +151,12 @@ export class CustomActionPrettyResourcesTabsComponent extends PageComponent impl @@ -153,6 +151,12 @@ export class CustomActionPrettyResourcesTabsComponent extends PageComponent impl
153 } 151 }
154 152
155 private initAceEditors() { 153 private initAceEditors() {
  154 + this.aceResize$ = new ResizeObserver((enteris) => {
  155 + enteris.forEach((entry) => {
  156 + const editor = this.aceEditors.find(aceEditor => aceEditor.container === entry.target);
  157 + this.onAceEditorResize(editor);
  158 + })
  159 + });
156 this.htmlEditor = this.createAceEditor(this.htmlInputElmRef, 'html'); 160 this.htmlEditor = this.createAceEditor(this.htmlInputElmRef, 'html');
157 this.htmlEditor.on('input', () => { 161 this.htmlEditor.on('input', () => {
158 const editorValue = this.htmlEditor.getValue(); 162 const editorValue = this.htmlEditor.getValue();
@@ -187,12 +191,7 @@ export class CustomActionPrettyResourcesTabsComponent extends PageComponent impl @@ -187,12 +191,7 @@ export class CustomActionPrettyResourcesTabsComponent extends PageComponent impl
187 const aceEditor = ace.edit(editorElement, editorOptions); 191 const aceEditor = ace.edit(editorElement, editorOptions);
188 aceEditor.session.setUseWrapMode(true); 192 aceEditor.session.setUseWrapMode(true);
189 this.aceEditors.push(aceEditor); 193 this.aceEditors.push(aceEditor);
190 -  
191 - const resize$ = new ResizeObserver(() => {  
192 - this.onAceEditorResize(aceEditor);  
193 - });  
194 - resize$.observe(editorElement);  
195 - this.aceResizeObservers.push(resize$); 194 + this.aceResize$.observe(editorElement);
196 return aceEditor; 195 return aceEditor;
197 } 196 }
198 197
@@ -125,7 +125,7 @@ export class WidgetEditorComponent extends PageComponent implements OnInit, OnDe @@ -125,7 +125,7 @@ export class WidgetEditorComponent extends PageComponent implements OnInit, OnDe
125 jsonSettingsEditor: ace.Ace.Editor; 125 jsonSettingsEditor: ace.Ace.Editor;
126 dataKeyJsonSettingsEditor: ace.Ace.Editor; 126 dataKeyJsonSettingsEditor: ace.Ace.Editor;
127 jsEditor: ace.Ace.Editor; 127 jsEditor: ace.Ace.Editor;
128 - aceResizeObservers: ResizeObserver[] = []; 128 + aceResize$: ResizeObserver;
129 129
130 onWindowMessageListener = this.onWindowMessage.bind(this); 130 onWindowMessageListener = this.onWindowMessage.bind(this);
131 131
@@ -194,9 +194,7 @@ export class WidgetEditorComponent extends PageComponent implements OnInit, OnDe @@ -194,9 +194,7 @@ export class WidgetEditorComponent extends PageComponent implements OnInit, OnDe
194 194
195 ngOnDestroy(): void { 195 ngOnDestroy(): void {
196 this.window.removeEventListener('message', this.onWindowMessageListener); 196 this.window.removeEventListener('message', this.onWindowMessageListener);
197 - this.aceResizeObservers.forEach((resize$) => {  
198 - resize$.disconnect();  
199 - }); 197 + this.aceResize$.disconnect();
200 this.rxSubscriptions.forEach((subscription) => { 198 this.rxSubscriptions.forEach((subscription) => {
201 subscription.unsubscribe(); 199 subscription.unsubscribe();
202 }); 200 });
@@ -272,6 +270,12 @@ export class WidgetEditorComponent extends PageComponent implements OnInit, OnDe @@ -272,6 +270,12 @@ export class WidgetEditorComponent extends PageComponent implements OnInit, OnDe
272 } 270 }
273 271
274 private initAceEditors() { 272 private initAceEditors() {
  273 + this.aceResize$ = new ResizeObserver((enteris) => {
  274 + enteris.forEach((entry) => {
  275 + const editor = this.aceEditors.find(aceEditor => aceEditor.container === entry.target);
  276 + this.onAceEditorResize(editor);
  277 + })
  278 + });
275 this.htmlEditor = this.createAceEditor(this.htmlInputElmRef, 'html'); 279 this.htmlEditor = this.createAceEditor(this.htmlInputElmRef, 'html');
276 this.htmlEditor.on('input', () => { 280 this.htmlEditor.on('input', () => {
277 const editorValue = this.htmlEditor.getValue(); 281 const editorValue = this.htmlEditor.getValue();
@@ -342,12 +346,7 @@ export class WidgetEditorComponent extends PageComponent implements OnInit, OnDe @@ -342,12 +346,7 @@ export class WidgetEditorComponent extends PageComponent implements OnInit, OnDe
342 const aceEditor = ace.edit(editorElement, editorOptions); 346 const aceEditor = ace.edit(editorElement, editorOptions);
343 aceEditor.session.setUseWrapMode(true); 347 aceEditor.session.setUseWrapMode(true);
344 this.aceEditors.push(aceEditor); 348 this.aceEditors.push(aceEditor);
345 -  
346 - const resize$ = new ResizeObserver(() => {  
347 - this.onAceEditorResize(aceEditor);  
348 - });  
349 - resize$.observe(editorElement);  
350 - this.aceResizeObservers.push(resize$); 349 + this.aceResize$.observe(editorElement);
351 return aceEditor; 350 return aceEditor;
352 } 351 }
353 352