@opensumi/ide-editor 3.3.1-next-1725281510.0 → 3.3.1-next-1725350427.0

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.
@@ -1,8 +1,7 @@
1
1
  import cls from 'classnames';
2
2
  import { observer } from 'mobx-react-lite';
3
- import React from 'react';
3
+ import React, { forwardRef } from 'react';
4
4
  import ReactDOM from 'react-dom/client';
5
- import ReactIs from 'react-is';
6
5
 
7
6
  import { Scrollbars } from '@opensumi/ide-components';
8
7
  import {
@@ -282,7 +281,6 @@ export const EditorGroupView = observer(({ group }: { group: EditorGroup }) => {
282
281
 
283
282
  return (
284
283
  <div
285
- ref={groupWrapperRef as any}
286
284
  className={styles_kt_editor_group}
287
285
  tabIndex={1}
288
286
  onFocus={(e) => {
@@ -294,7 +292,7 @@ export const EditorGroupView = observer(({ group }: { group: EditorGroup }) => {
294
292
  <Tabs group={group} />
295
293
  </div>
296
294
  )}
297
- <EditorGroupBody group={group} />
295
+ <EditorGroupBody ref={groupWrapperRef as any} group={group} />
298
296
  {isEmpty && (
299
297
  <div
300
298
  className={styles.kt_editor_background}
@@ -309,190 +307,201 @@ export const EditorGroupView = observer(({ group }: { group: EditorGroup }) => {
309
307
  );
310
308
  });
311
309
 
312
- export const EditorGroupBody = observer(({ group }: { group: EditorGroup }) => {
313
- const [context, setContext] = React.useState<IEditorContext>(defaultEditorContext);
314
-
315
- const editorBodyRef = React.useRef<HTMLDivElement>(null);
316
- const editorService = useInjectable(WorkbenchEditorService) as WorkbenchEditorServiceImpl;
317
- const eventBus = useInjectable(IEventBus) as IEventBus;
318
- const styles_kt_editor_component = useDesignStyles(styles.kt_editor_component, 'kt_editor_component');
319
- const components: React.ReactNode[] = [];
320
- const codeEditorRef = React.useRef<HTMLDivElement>(null);
321
- const diffEditorRef = React.useRef<HTMLDivElement>(null);
322
- const mergeEditorRef = React.useRef<HTMLDivElement>(null);
323
- const [, updateState] = React.useState<any>();
324
- const forceUpdate = React.useCallback(() => updateState({}), []);
325
-
326
- React.useEffect(() => {
327
- const disposables = new DisposableStore();
328
-
329
- disposables.add(
330
- group.onDidEditorGroupBodyChanged(() => {
331
- forceUpdate();
332
- }),
333
- );
310
+ export const EditorGroupBody = observer(
311
+ forwardRef(({ group }: { group: EditorGroup }, ref) => {
312
+ const [context, setContext] = React.useState<IEditorContext>(defaultEditorContext);
313
+
314
+ const editorBodyRef = React.useRef<HTMLDivElement | null>(null);
315
+ const editorService = useInjectable(WorkbenchEditorService) as WorkbenchEditorServiceImpl;
316
+ const eventBus = useInjectable(IEventBus) as IEventBus;
317
+ const styles_kt_editor_component = useDesignStyles(styles.kt_editor_component, 'kt_editor_component');
318
+ const components: React.ReactNode[] = [];
319
+ const codeEditorRef = React.useRef<HTMLDivElement>(null);
320
+ const diffEditorRef = React.useRef<HTMLDivElement>(null);
321
+ const mergeEditorRef = React.useRef<HTMLDivElement>(null);
322
+ const [, updateState] = React.useState<any>();
323
+ const forceUpdate = React.useCallback(() => updateState({}), []);
324
+
325
+ React.useEffect(() => {
326
+ const disposables = new DisposableStore();
327
+
328
+ disposables.add(
329
+ group.onDidEditorGroupBodyChanged(() => {
330
+ forceUpdate();
331
+ }),
332
+ );
334
333
 
335
- if (codeEditorRef.current) {
336
- if (cachedEditor[group.name]) {
337
- cachedEditor[group.name].remove();
338
- codeEditorRef.current.appendChild(cachedEditor[group.name]);
339
- } else {
340
- const container = document.createElement('div');
341
- codeEditorRef.current.appendChild(container);
342
- cachedEditor[group.name] = container;
343
- group.createEditor(container);
344
- const minimapWith = group.codeEditor.monacoEditor.getOption(monaco.editor.EditorOption.layoutInfo).minimap
345
- .minimapWidth;
346
- setContext({ minimapWidth: minimapWith });
347
-
348
- disposables.add(
349
- group.codeEditor.monacoEditor.onDidChangeConfiguration((e) => {
350
- if (e.hasChanged(monaco.editor.EditorOption.layoutInfo)) {
351
- setContext({
352
- minimapWidth: group.codeEditor.monacoEditor.getOption(monaco.editor.EditorOption.layoutInfo).minimap
353
- .minimapWidth,
354
- });
355
- }
356
- }),
357
- );
334
+ if (codeEditorRef.current) {
335
+ if (cachedEditor[group.name]) {
336
+ cachedEditor[group.name].remove();
337
+ codeEditorRef.current.appendChild(cachedEditor[group.name]);
338
+ } else {
339
+ const container = document.createElement('div');
340
+ codeEditorRef.current.appendChild(container);
341
+ cachedEditor[group.name] = container;
342
+ group.createEditor(container);
343
+ const minimapWith = group.codeEditor.monacoEditor.getOption(monaco.editor.EditorOption.layoutInfo).minimap
344
+ .minimapWidth;
345
+ setContext({ minimapWidth: minimapWith });
346
+
347
+ disposables.add(
348
+ group.codeEditor.monacoEditor.onDidChangeConfiguration((e) => {
349
+ if (e.hasChanged(monaco.editor.EditorOption.layoutInfo)) {
350
+ setContext({
351
+ minimapWidth: group.codeEditor.monacoEditor.getOption(monaco.editor.EditorOption.layoutInfo).minimap
352
+ .minimapWidth,
353
+ });
354
+ }
355
+ }),
356
+ );
357
+ }
358
358
  }
359
- }
360
359
 
361
- if (diffEditorRef.current) {
362
- group.attachDiffEditorDom(diffEditorRef.current);
363
- }
364
- if (mergeEditorRef.current) {
365
- group.attachMergeEditorDom(mergeEditorRef.current);
366
- }
360
+ if (diffEditorRef.current) {
361
+ group.attachDiffEditorDom(diffEditorRef.current);
362
+ }
363
+ if (mergeEditorRef.current) {
364
+ group.attachMergeEditorDom(mergeEditorRef.current);
365
+ }
367
366
 
368
- return () => {
369
- disposables.dispose();
370
- };
371
- }, []);
367
+ return () => {
368
+ disposables.dispose();
369
+ };
370
+ }, []);
372
371
 
373
- group.activeComponents.forEach((resources, component) => {
374
- const initialProps = group.activateComponentsProps.get(component);
375
- components.push(
376
- <div
377
- key={component.uid}
378
- className={cls({
379
- [styles.kt_hidden]: !(group.currentOpenType && group.currentOpenType.componentId === component.uid),
380
- })}
381
- >
382
- <ComponentsWrapper
372
+ group.activeComponents.forEach((resources, component) => {
373
+ const initialProps = group.activateComponentsProps.get(component);
374
+ components.push(
375
+ <div
383
376
  key={component.uid}
384
- component={component}
385
- {...initialProps}
386
- resources={resources}
387
- current={group.currentResource}
388
- ></ComponentsWrapper>
389
- </div>,
390
- );
391
- });
377
+ className={cls({
378
+ [styles.kt_hidden]: !(group.currentOpenType && group.currentOpenType.componentId === component.uid),
379
+ })}
380
+ >
381
+ <ComponentsWrapper
382
+ key={component.uid}
383
+ component={component}
384
+ {...initialProps}
385
+ resources={resources}
386
+ current={group.currentResource}
387
+ ></ComponentsWrapper>
388
+ </div>,
389
+ );
390
+ });
392
391
 
393
- const editorHasNoTab = React.useMemo(
394
- () => group.resources.length === 0 || !group.currentResource,
395
- [group.resources.length, group.currentResource],
396
- );
392
+ const editorHasNoTab = React.useMemo(
393
+ () => group.resources.length === 0 || !group.currentResource,
394
+ [group.resources.length, group.currentResource],
395
+ );
397
396
 
398
- React.useEffect(() => {
399
- if (group.currentOpenType?.type === EditorOpenType.code) {
400
- eventBus.fire(
401
- new CodeEditorDidVisibleEvent({
402
- groupName: group.name,
403
- type: EditorOpenType.code,
404
- editorId: group.codeEditor.getId(),
405
- }),
406
- );
407
- } else if (group.currentOpenType?.type === EditorOpenType.diff) {
408
- eventBus.fire(
409
- new CodeEditorDidVisibleEvent({
410
- groupName: group.name,
411
- type: EditorOpenType.diff,
412
- editorId: group.diffEditor.modifiedEditor.getId(),
413
- }),
414
- );
415
- }
416
- });
397
+ React.useEffect(() => {
398
+ if (group.currentOpenType?.type === EditorOpenType.code) {
399
+ eventBus.fire(
400
+ new CodeEditorDidVisibleEvent({
401
+ groupName: group.name,
402
+ type: EditorOpenType.code,
403
+ editorId: group.codeEditor.getId(),
404
+ }),
405
+ );
406
+ } else if (group.currentOpenType?.type === EditorOpenType.diff) {
407
+ eventBus.fire(
408
+ new CodeEditorDidVisibleEvent({
409
+ groupName: group.name,
410
+ type: EditorOpenType.diff,
411
+ editorId: group.diffEditor.modifiedEditor.getId(),
412
+ }),
413
+ );
414
+ }
415
+ });
417
416
 
418
- return (
419
- <EditorContext.Provider value={context}>
420
- <div
421
- id={VIEW_CONTAINERS.EDITOR}
422
- ref={editorBodyRef}
423
- className={styles.kt_editor_body}
424
- onDragOver={(e) => {
425
- e.preventDefault();
426
- if (editorBodyRef.current) {
427
- const position = getDragOverPosition(e.nativeEvent, editorBodyRef.current);
428
- decorateDragOverElement(editorBodyRef.current, position);
429
- }
430
- }}
431
- onDragLeave={(e) => {
432
- if (editorBodyRef.current) {
433
- removeDecorationDragOverElement(editorBodyRef.current);
434
- }
435
- }}
436
- onDrop={(e) => {
437
- if (editorBodyRef.current) {
438
- removeDecorationDragOverElement(editorBodyRef.current);
439
- if (e.dataTransfer.getData('uri')) {
440
- const uri = new URI(e.dataTransfer.getData('uri'));
441
- let sourceGroup: EditorGroup | undefined;
442
- if (e.dataTransfer.getData('uri-source-group')) {
443
- sourceGroup = editorService.getEditorGroup(e.dataTransfer.getData('uri-source-group'));
417
+ return (
418
+ <EditorContext.Provider value={context}>
419
+ <div
420
+ id={VIEW_CONTAINERS.EDITOR}
421
+ ref={(_ref) => {
422
+ editorBodyRef.current = _ref;
423
+ if (ref) {
424
+ if (typeof ref === 'function') {
425
+ ref(_ref);
426
+ } else {
427
+ ref.current = _ref;
444
428
  }
445
- group.dropUri(uri, getDragOverPosition(e.nativeEvent, editorBodyRef.current), sourceGroup);
446
429
  }
447
- if (e.dataTransfer.files.length > 0) {
448
- eventBus.fire(
449
- new EditorGroupFileDropEvent({
450
- group,
451
- files: e.dataTransfer.files,
452
- position: getDragOverPosition(e.nativeEvent, editorBodyRef.current),
453
- }),
454
- );
430
+ }}
431
+ className={styles.kt_editor_body}
432
+ onDragOver={(e) => {
433
+ e.preventDefault();
434
+ if (editorBodyRef.current) {
435
+ const position = getDragOverPosition(e.nativeEvent, editorBodyRef.current);
436
+ decorateDragOverElement(editorBodyRef.current, position);
455
437
  }
456
- }
457
- }}
458
- >
459
- {group.currentResource && <EditorSideView side={'top'} resource={group.currentResource}></EditorSideView>}
460
- {!editorHasNoTab && <NavigationBar editorGroup={group} />}
461
- <div className={styles.kt_editor_components}>
462
- <div
463
- className={cls({
464
- [styles_kt_editor_component]: true,
465
- [styles.kt_hidden]: !group.currentOpenType || group.currentOpenType.type !== EditorOpenType.component,
466
- })}
467
- >
468
- {components}
438
+ }}
439
+ onDragLeave={(e) => {
440
+ if (editorBodyRef.current) {
441
+ removeDecorationDragOverElement(editorBodyRef.current);
442
+ }
443
+ }}
444
+ onDrop={(e) => {
445
+ if (editorBodyRef.current) {
446
+ removeDecorationDragOverElement(editorBodyRef.current);
447
+ if (e.dataTransfer.getData('uri')) {
448
+ const uri = new URI(e.dataTransfer.getData('uri'));
449
+ let sourceGroup: EditorGroup | undefined;
450
+ if (e.dataTransfer.getData('uri-source-group')) {
451
+ sourceGroup = editorService.getEditorGroup(e.dataTransfer.getData('uri-source-group'));
452
+ }
453
+ group.dropUri(uri, getDragOverPosition(e.nativeEvent, editorBodyRef.current), sourceGroup);
454
+ }
455
+ if (e.dataTransfer.files.length > 0) {
456
+ eventBus.fire(
457
+ new EditorGroupFileDropEvent({
458
+ group,
459
+ files: e.dataTransfer.files,
460
+ position: getDragOverPosition(e.nativeEvent, editorBodyRef.current),
461
+ }),
462
+ );
463
+ }
464
+ }
465
+ }}
466
+ >
467
+ {group.currentResource && <EditorSideView side='top' resource={group.currentResource}></EditorSideView>}
468
+ {!editorHasNoTab && <NavigationBar editorGroup={group} />}
469
+ <div className={styles.kt_editor_components}>
470
+ <div
471
+ className={cls({
472
+ [styles_kt_editor_component]: true,
473
+ [styles.kt_hidden]: !group.currentOpenType || group.currentOpenType.type !== EditorOpenType.component,
474
+ })}
475
+ >
476
+ {components}
477
+ </div>
478
+ <div
479
+ className={cls({
480
+ [styles.kt_editor_code_editor]: true,
481
+ [styles_kt_editor_component]: true,
482
+ [styles.kt_hidden]: !group.currentOpenType || group.currentOpenType.type !== EditorOpenType.code,
483
+ })}
484
+ ref={codeEditorRef}
485
+ />
486
+ <div
487
+ className={cls(styles.kt_editor_diff_editor, styles_kt_editor_component, {
488
+ [styles.kt_hidden]: !group.currentOpenType || group.currentOpenType.type !== EditorOpenType.diff,
489
+ })}
490
+ ref={diffEditorRef}
491
+ />
492
+ <div
493
+ className={cls(styles.kt_editor_diff_3_editor, styles_kt_editor_component, {
494
+ [styles.kt_hidden]: !group.currentOpenType || group.currentOpenType.type !== EditorOpenType.mergeEditor,
495
+ })}
496
+ ref={mergeEditorRef}
497
+ />
469
498
  </div>
470
- <div
471
- className={cls({
472
- [styles.kt_editor_code_editor]: true,
473
- [styles_kt_editor_component]: true,
474
- [styles.kt_hidden]: !group.currentOpenType || group.currentOpenType.type !== EditorOpenType.code,
475
- })}
476
- ref={codeEditorRef}
477
- />
478
- <div
479
- className={cls(styles.kt_editor_diff_editor, styles_kt_editor_component, {
480
- [styles.kt_hidden]: !group.currentOpenType || group.currentOpenType.type !== EditorOpenType.diff,
481
- })}
482
- ref={diffEditorRef}
483
- />
484
- <div
485
- className={cls(styles.kt_editor_diff_3_editor, styles_kt_editor_component, {
486
- [styles.kt_hidden]: !group.currentOpenType || group.currentOpenType.type !== EditorOpenType.mergeEditor,
487
- })}
488
- ref={mergeEditorRef}
489
- />
499
+ {group.currentResource && <EditorSideView side={'bottom'} resource={group.currentResource}></EditorSideView>}
490
500
  </div>
491
- {group.currentResource && <EditorSideView side={'bottom'} resource={group.currentResource}></EditorSideView>}
492
- </div>
493
- </EditorContext.Provider>
494
- );
495
- });
501
+ </EditorContext.Provider>
502
+ );
503
+ }),
504
+ );
496
505
 
497
506
  export const ComponentsWrapper = ({
498
507
  component,
@@ -16,6 +16,7 @@ import {
16
16
  toMarkdown,
17
17
  } from '@opensumi/ide-core-browser';
18
18
  import { ResourceContextKey } from '@opensumi/ide-core-browser/lib/contextkey/resource';
19
+ import { IDimension } from '@opensumi/ide-core-browser/lib/dom/resize-observer';
19
20
  import { IMergeEditorEditor, MergeEditorInputData } from '@opensumi/ide-core-browser/lib/monaco/merge-editor-widget';
20
21
  import {
21
22
  CUSTOM_EDITOR_SCHEME,
@@ -277,7 +278,7 @@ export class WorkbenchEditorServiceImpl extends WithEventBus implements Workbenc
277
278
  createEditorGroup(): EditorGroup {
278
279
  const editorGroup = this.injector.get(EditorGroup, [this.generateRandomEditorGroupName(), this.editorGroupIdGen++]);
279
280
  this.editorGroups.push(editorGroup);
280
- const currentWatchDisposer = new Disposable(
281
+ editorGroup.addDispose([
281
282
  editorGroup.onDidEditorGroupBodyChanged(() => {
282
283
  if (editorGroup === this.currentEditorGroup) {
283
284
  if (!editorGroup.currentOpenType && editorGroup.currentResource) {
@@ -296,25 +297,15 @@ export class WorkbenchEditorServiceImpl extends WithEventBus implements Workbenc
296
297
  }
297
298
  }
298
299
  }),
299
- );
300
- editorGroup.addDispose({
301
- dispose: () => {
302
- currentWatchDisposer.dispose();
303
- },
304
- });
305
- const groupChangeDisposer = editorGroup.onDidEditorGroupTabChanged(() => {
306
- this.saveOpenedResourceState();
307
- });
308
- editorGroup.addDispose({
309
- dispose: () => {
310
- groupChangeDisposer.dispose();
311
- },
312
- });
313
- editorGroup.onCurrentEditorCursorChange((e) => {
314
- if (this._currentEditorGroup === editorGroup) {
315
- this._onCursorChange.fire(e);
316
- }
317
- });
300
+ editorGroup.onDidEditorGroupTabChanged(() => {
301
+ this.saveOpenedResourceState();
302
+ }),
303
+ editorGroup.onCurrentEditorCursorChange((e) => {
304
+ if (this._currentEditorGroup === editorGroup) {
305
+ this._onCursorChange.fire(e);
306
+ }
307
+ }),
308
+ ]);
318
309
 
319
310
  return editorGroup;
320
311
  }
@@ -790,14 +781,14 @@ export class EditorGroup extends WithEventBus implements IGridEditorGroup {
790
781
  this.eventBus.onDirective(
791
782
  ResizeEvent.createDirective(getSlotLocation('@opensumi/ide-editor', this.config.layoutConfig)),
792
783
  () => {
793
- this.doLayoutEditors();
784
+ this.layoutEditors();
794
785
  },
795
786
  ),
796
787
  );
797
788
  this.addDispose(
798
789
  this.eventBus.on(GridResizeEvent, (e: GridResizeEvent) => {
799
790
  if (e.payload.gridId === this.grid.uid) {
800
- this.doLayoutEditors();
791
+ this.layoutEditors();
801
792
  }
802
793
  }),
803
794
  );
@@ -848,26 +839,28 @@ export class EditorGroup extends WithEventBus implements IGridEditorGroup {
848
839
  layoutEditors() {
849
840
  fastdom.measure(() => {
850
841
  if (this._domNode) {
851
- const currentWidth = this._domNode.offsetWidth;
852
- const currentHeight = this._domNode.offsetHeight;
853
- if (currentWidth !== this._prevDomWidth || currentHeight !== this._prevDomHeight) {
854
- this.doLayoutEditors();
855
- }
856
- this._prevDomWidth = currentWidth;
857
- this._prevDomHeight = currentHeight;
842
+ this._prevDomWidth = this._domNode.offsetWidth;
843
+ this._prevDomHeight = this._domNode.offsetHeight;
844
+ this.doLayoutEditors(
845
+ {
846
+ width: this._prevDomWidth,
847
+ height: this._prevDomHeight,
848
+ },
849
+ true,
850
+ );
858
851
  }
859
852
  });
860
853
  }
861
854
 
862
- private doLayoutEditors() {
855
+ private doLayoutEditors(e: IDimension, postponeRendering?: boolean) {
863
856
  if (this.codeEditor) {
864
857
  if (this.currentOpenType && this.currentOpenType.type === EditorOpenType.code) {
865
- this.codeEditor.layout();
858
+ this.codeEditor.layout(e, postponeRendering);
866
859
  }
867
860
  }
868
861
  if (this.diffEditor) {
869
862
  if (this.currentOpenType && this.currentOpenType.type === EditorOpenType.diff) {
870
- this.diffEditor.layout();
863
+ this.diffEditor.layout(e, postponeRendering);
871
864
  }
872
865
  }
873
866
  }
@@ -1817,7 +1810,7 @@ export class EditorGroup extends WithEventBus implements IGridEditorGroup {
1817
1810
  this._currentOpenType = activeOpenType;
1818
1811
  this.notifyBodyChanged();
1819
1812
 
1820
- this.doLayoutEditors();
1813
+ this.layoutEditors();
1821
1814
 
1822
1815
  this.cachedResourcesActiveOpenTypes.set(resource.uri.toString(), activeOpenType);
1823
1816
  }
@@ -310,7 +310,7 @@ export interface IDiffEditor extends IDisposable {
310
310
 
311
311
  modifiedEditor: IEditor;
312
312
 
313
- layout(): void;
313
+ layout(dimension?: IDimension, postponeRendering?: boolean): void;
314
314
 
315
315
  focus(): void;
316
316