@opensumi/ide-editor 3.3.1-next-1725521092.0 → 3.3.1-next-1725534862.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,6 +1,6 @@
1
1
  import cls from 'classnames';
2
2
  import { observer } from 'mobx-react-lite';
3
- import React, { forwardRef } from 'react';
3
+ import React from 'react';
4
4
  import ReactDOM from 'react-dom/client';
5
5
 
6
6
  import { Scrollbars } from '@opensumi/ide-components';
@@ -13,7 +13,6 @@ import {
13
13
  ErrorBoundary,
14
14
  IEventBus,
15
15
  MaybeNull,
16
- PreferenceService,
17
16
  URI,
18
17
  View,
19
18
  renderView,
@@ -93,12 +92,12 @@ export const EditorView = () => {
93
92
  }}
94
93
  >
95
94
  <div className={styles.kt_editor_main_wrapper}>
96
- <EditorGridView grid={workbenchEditorService.topGrid}></EditorGridView>
95
+ <EditorGridView grid={workbenchEditorService.topGrid} />
97
96
  </div>
98
97
  {RightWidget ? (
99
98
  <div className={styles.kt_editor_right_widget}>
100
99
  <ErrorBoundary>
101
- <RightWidget></RightWidget>
100
+ <RightWidget />
102
101
  </ErrorBoundary>
103
102
  </div>
104
103
  ) : null}
@@ -281,6 +280,7 @@ export const EditorGroupView = observer(({ group }: { group: EditorGroup }) => {
281
280
 
282
281
  return (
283
282
  <div
283
+ ref={groupWrapperRef as any}
284
284
  className={styles_kt_editor_group}
285
285
  tabIndex={1}
286
286
  onFocus={(e) => {
@@ -292,7 +292,7 @@ export const EditorGroupView = observer(({ group }: { group: EditorGroup }) => {
292
292
  <Tabs group={group} />
293
293
  </div>
294
294
  )}
295
- <EditorGroupBody ref={groupWrapperRef as any} group={group} />
295
+ <EditorGroupBody group={group} />
296
296
  {isEmpty && (
297
297
  <div
298
298
  className={styles.kt_editor_background}
@@ -307,201 +307,190 @@ export const EditorGroupView = observer(({ group }: { group: EditorGroup }) => {
307
307
  );
308
308
  });
309
309
 
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
- );
333
-
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
- }
310
+ export const EditorGroupBody = observer(({ group }: { group: EditorGroup }) => {
311
+ const [context, setContext] = React.useState<IEditorContext>(defaultEditorContext);
359
312
 
360
- if (diffEditorRef.current) {
361
- group.attachDiffEditorDom(diffEditorRef.current);
362
- }
363
- if (mergeEditorRef.current) {
364
- group.attachMergeEditorDom(mergeEditorRef.current);
365
- }
366
-
367
- return () => {
368
- disposables.dispose();
369
- };
370
- }, []);
313
+ const editorBodyRef = React.useRef<HTMLDivElement>(null);
314
+ const editorService = useInjectable(WorkbenchEditorService) as WorkbenchEditorServiceImpl;
315
+ const eventBus = useInjectable(IEventBus) as IEventBus;
316
+ const styles_kt_editor_component = useDesignStyles(styles.kt_editor_component, 'kt_editor_component');
317
+ const components: React.ReactNode[] = [];
318
+ const codeEditorRef = React.useRef<HTMLDivElement>(null);
319
+ const diffEditorRef = React.useRef<HTMLDivElement>(null);
320
+ const mergeEditorRef = React.useRef<HTMLDivElement>(null);
321
+ const [, updateState] = React.useState<any>();
322
+ const forceUpdate = React.useCallback(() => updateState({}), []);
371
323
 
372
- group.activeComponents.forEach((resources, component) => {
373
- const initialProps = group.activateComponentsProps.get(component);
374
- components.push(
375
- <div
376
- key={component.uid}
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
- });
324
+ React.useEffect(() => {
325
+ const disposables = new DisposableStore();
391
326
 
392
- const editorHasNoTab = React.useMemo(
393
- () => group.resources.length === 0 || !group.currentResource,
394
- [group.resources.length, group.currentResource],
327
+ disposables.add(
328
+ group.onDidEditorGroupBodyChanged(() => {
329
+ forceUpdate();
330
+ }),
395
331
  );
396
332
 
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(),
333
+ if (codeEditorRef.current) {
334
+ if (cachedEditor[group.name]) {
335
+ cachedEditor[group.name].remove();
336
+ codeEditorRef.current.appendChild(cachedEditor[group.name]);
337
+ } else {
338
+ const container = document.createElement('div');
339
+ codeEditorRef.current.appendChild(container);
340
+ cachedEditor[group.name] = container;
341
+ group.createEditor(container);
342
+ const minimapWith = group.codeEditor.monacoEditor.getOption(monaco.editor.EditorOption.layoutInfo).minimap
343
+ .minimapWidth;
344
+ setContext({ minimapWidth: minimapWith });
345
+
346
+ disposables.add(
347
+ group.codeEditor.monacoEditor.onDidChangeConfiguration((e) => {
348
+ if (e.hasChanged(monaco.editor.EditorOption.layoutInfo)) {
349
+ setContext({
350
+ minimapWidth: group.codeEditor.monacoEditor.getOption(monaco.editor.EditorOption.layoutInfo).minimap
351
+ .minimapWidth,
352
+ });
353
+ }
412
354
  }),
413
355
  );
414
356
  }
415
- });
357
+ }
416
358
 
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;
359
+ if (diffEditorRef.current) {
360
+ group.attachDiffEditorDom(diffEditorRef.current);
361
+ }
362
+ if (mergeEditorRef.current) {
363
+ group.attachMergeEditorDom(mergeEditorRef.current);
364
+ }
365
+
366
+ return () => {
367
+ disposables.dispose();
368
+ };
369
+ }, []);
370
+
371
+ group.activeComponents.forEach((resources, component) => {
372
+ const initialProps = group.activateComponentsProps.get(component);
373
+ components.push(
374
+ <div
375
+ key={component.uid}
376
+ className={cls({
377
+ [styles.kt_hidden]: !(group.currentOpenType && group.currentOpenType.componentId === component.uid),
378
+ })}
379
+ >
380
+ <ComponentsWrapper
381
+ key={component.uid}
382
+ component={component}
383
+ {...initialProps}
384
+ resources={resources}
385
+ current={group.currentResource}
386
+ ></ComponentsWrapper>
387
+ </div>,
388
+ );
389
+ });
390
+
391
+ const editorHasNoTab = React.useMemo(
392
+ () => group.resources.length === 0 || !group.currentResource,
393
+ [group.resources.length, group.currentResource],
394
+ );
395
+
396
+ React.useEffect(() => {
397
+ if (group.currentOpenType?.type === EditorOpenType.code) {
398
+ eventBus.fire(
399
+ new CodeEditorDidVisibleEvent({
400
+ groupName: group.name,
401
+ type: EditorOpenType.code,
402
+ editorId: group.codeEditor.getId(),
403
+ }),
404
+ );
405
+ } else if (group.currentOpenType?.type === EditorOpenType.diff) {
406
+ eventBus.fire(
407
+ new CodeEditorDidVisibleEvent({
408
+ groupName: group.name,
409
+ type: EditorOpenType.diff,
410
+ editorId: group.diffEditor.modifiedEditor.getId(),
411
+ }),
412
+ );
413
+ }
414
+ });
415
+
416
+ return (
417
+ <EditorContext.Provider value={context}>
418
+ <div
419
+ id={VIEW_CONTAINERS.EDITOR}
420
+ ref={editorBodyRef}
421
+ className={styles.kt_editor_body}
422
+ onDragOver={(e) => {
423
+ e.preventDefault();
424
+ if (editorBodyRef.current) {
425
+ const position = getDragOverPosition(e.nativeEvent, editorBodyRef.current);
426
+ decorateDragOverElement(editorBodyRef.current, position);
427
+ }
428
+ }}
429
+ onDragLeave={(e) => {
430
+ if (editorBodyRef.current) {
431
+ removeDecorationDragOverElement(editorBodyRef.current);
432
+ }
433
+ }}
434
+ onDrop={(e) => {
435
+ if (editorBodyRef.current) {
436
+ removeDecorationDragOverElement(editorBodyRef.current);
437
+ if (e.dataTransfer.getData('uri')) {
438
+ const uri = new URI(e.dataTransfer.getData('uri'));
439
+ let sourceGroup: EditorGroup | undefined;
440
+ if (e.dataTransfer.getData('uri-source-group')) {
441
+ sourceGroup = editorService.getEditorGroup(e.dataTransfer.getData('uri-source-group'));
428
442
  }
443
+ group.dropUri(uri, getDragOverPosition(e.nativeEvent, editorBodyRef.current), sourceGroup);
429
444
  }
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);
437
- }
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
- }
445
+ if (e.dataTransfer.files.length > 0) {
446
+ eventBus.fire(
447
+ new EditorGroupFileDropEvent({
448
+ group,
449
+ files: e.dataTransfer.files,
450
+ position: getDragOverPosition(e.nativeEvent, editorBodyRef.current),
451
+ }),
452
+ );
464
453
  }
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
- />
454
+ }
455
+ }}
456
+ >
457
+ {group.currentResource && <EditorSideView side={'top'} resource={group.currentResource}></EditorSideView>}
458
+ {!editorHasNoTab && <NavigationBar editorGroup={group} />}
459
+ <div className={styles.kt_editor_components}>
460
+ <div
461
+ className={cls({
462
+ [styles_kt_editor_component]: true,
463
+ [styles.kt_hidden]: !group.currentOpenType || group.currentOpenType.type !== EditorOpenType.component,
464
+ })}
465
+ >
466
+ {components}
498
467
  </div>
499
- {group.currentResource && <EditorSideView side={'bottom'} resource={group.currentResource}></EditorSideView>}
468
+ <div
469
+ className={cls({
470
+ [styles.kt_editor_code_editor]: true,
471
+ [styles_kt_editor_component]: true,
472
+ [styles.kt_hidden]: !group.currentOpenType || group.currentOpenType.type !== EditorOpenType.code,
473
+ })}
474
+ ref={codeEditorRef}
475
+ />
476
+ <div
477
+ className={cls(styles.kt_editor_diff_editor, styles_kt_editor_component, {
478
+ [styles.kt_hidden]: !group.currentOpenType || group.currentOpenType.type !== EditorOpenType.diff,
479
+ })}
480
+ ref={diffEditorRef}
481
+ />
482
+ <div
483
+ className={cls(styles.kt_editor_diff_3_editor, styles_kt_editor_component, {
484
+ [styles.kt_hidden]: !group.currentOpenType || group.currentOpenType.type !== EditorOpenType.mergeEditor,
485
+ })}
486
+ ref={mergeEditorRef}
487
+ />
500
488
  </div>
501
- </EditorContext.Provider>
502
- );
503
- }),
504
- );
489
+ {group.currentResource && <EditorSideView side={'bottom'} resource={group.currentResource}></EditorSideView>}
490
+ </div>
491
+ </EditorContext.Provider>
492
+ );
493
+ });
505
494
 
506
495
  export const ComponentsWrapper = ({
507
496
  component,
@@ -415,12 +415,14 @@ export const Tabs = ({ group }: ITabsProps) => {
415
415
  );
416
416
 
417
417
  const renderTabContent = () => {
418
+ const noTab = group.resources.length === 0;
418
419
  const curTabIndex = group.resources.findIndex((resource) => group.currentResource === resource);
419
420
  return (
420
421
  <div
421
422
  draggable={false}
422
423
  className={cls({
423
424
  [styles_kt_editor_tabs_content]: true,
425
+ [styles.kt_editor_tabs_content_empty]: noTab,
424
426
  [styles_kt_editor_tabs_current_last]: curTabIndex === group.resources.length - 1,
425
427
  })}
426
428
  ref={contentRef as any}