@opensumi/ide-overlay 2.21.8-rc-1670567192.0 → 2.21.8

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
package/package.json CHANGED
@@ -1,9 +1,8 @@
1
1
  {
2
2
  "name": "@opensumi/ide-overlay",
3
- "version": "2.21.8-rc-1670567192.0",
3
+ "version": "2.21.8",
4
4
  "files": [
5
- "lib",
6
- "src"
5
+ "lib"
7
6
  ],
8
7
  "license": "MIT",
9
8
  "main": "lib/index.js",
@@ -17,12 +16,12 @@
17
16
  "url": "git@github.com:opensumi/core.git"
18
17
  },
19
18
  "dependencies": {
20
- "@opensumi/ide-core-common": "2.21.8-rc-1670567192.0"
19
+ "@opensumi/ide-core-common": "2.21.8"
21
20
  },
22
21
  "devDependencies": {
23
- "@opensumi/ide-components": "2.21.8-rc-1670567192.0",
24
- "@opensumi/ide-core-browser": "2.21.8-rc-1670567192.0",
22
+ "@opensumi/ide-components": "2.21.8",
23
+ "@opensumi/ide-core-browser": "2.21.8",
25
24
  "@opensumi/ide-dev-tool": "^1.3.1"
26
25
  },
27
- "gitHead": "acb182cbff72a453386044944b33a9f71eca426d"
26
+ "gitHead": "603eaa81756ee0e8a58871fb67cfb01c8499593a"
28
27
  }
@@ -1,53 +0,0 @@
1
- import { observable, action } from 'mobx';
2
-
3
- import { Injectable } from '@opensumi/di';
4
- import { MenuNode } from '@opensumi/ide-core-browser/lib/menu/next/base';
5
- import { CtxMenuRenderParams } from '@opensumi/ide-core-browser/lib/menu/next/renderer/ctxmenu/base';
6
- import { IBrowserCtxMenu } from '@opensumi/ide-core-browser/lib/menu/next/renderer/ctxmenu/browser';
7
-
8
- @Injectable()
9
- export class BrowserCtxMenuService implements IBrowserCtxMenu {
10
- @observable
11
- visible = false;
12
-
13
- @observable
14
- onHide: ((canceled: boolean) => void) | undefined = undefined;
15
-
16
- @observable
17
- point: { pageX: number; pageY: number } | undefined = undefined;
18
-
19
- @observable
20
- context: any = undefined;
21
-
22
- @observable
23
- menuNodes: MenuNode[] = observable.array([]);
24
-
25
- @action
26
- public show(payload: CtxMenuRenderParams): void {
27
- const { anchor, onHide, args: context, menuNodes } = payload;
28
- // 上层调用前已经将 MenuNodes 处理为数组了
29
- if (!Array.isArray(menuNodes) || !menuNodes.length) {
30
- return;
31
- }
32
-
33
- this.context = context;
34
- this.menuNodes.splice(0, this.menuNodes.length, ...menuNodes);
35
- const { x, y } = anchor instanceof window.MouseEvent ? { x: anchor.clientX, y: anchor.clientY } : anchor;
36
- this.onHide = onHide;
37
- this.point = { pageX: x, pageY: y };
38
- this.visible = true;
39
- }
40
-
41
- @action.bound
42
- public hide(canceled: boolean) {
43
- if (typeof this.onHide === 'function') {
44
- this.onHide(canceled);
45
- }
46
- this.reset();
47
- }
48
-
49
- @action.bound
50
- private reset() {
51
- this.visible = false;
52
- }
53
- }
@@ -1,53 +0,0 @@
1
- import { observer } from 'mobx-react-lite';
2
- import React from 'react';
3
- import CtxMenuTrigger from 'react-ctxmenu-trigger';
4
-
5
- import { ClickOutside } from '@opensumi/ide-components';
6
- import { useInjectable } from '@opensumi/ide-core-browser';
7
- import { MenuActionList } from '@opensumi/ide-core-browser/lib/components/actions';
8
- import placements from '@opensumi/ide-core-browser/lib/components/actions/placements';
9
- import { IBrowserCtxMenu } from '@opensumi/ide-core-browser/lib/menu/next/renderer/ctxmenu/browser';
10
-
11
- import 'react-ctxmenu-trigger/assets/index.css';
12
-
13
- export const CtxMenu = observer(() => {
14
- const ctxMenuService = useInjectable<IBrowserCtxMenu>(IBrowserCtxMenu);
15
-
16
- const handleClick = React.useCallback(() => {
17
- ctxMenuService.hide(false);
18
- }, []);
19
-
20
- const onClickOutSide = React.useCallback(() => {
21
- if (ctxMenuService.visible) {
22
- ctxMenuService.hide(true);
23
- }
24
- }, [ctxMenuService.visible]);
25
-
26
- // todo: 缓存上一次点击 visible 完成 toggle 效果
27
- return (
28
- <CtxMenuTrigger
29
- // popupTransitionName='slide-up'
30
- popupPlacement='bottomLeft'
31
- popupVisible={ctxMenuService.visible}
32
- action={['contextMenu']}
33
- popupAlign={{
34
- overflow: {
35
- adjustX: 1,
36
- adjustY: 1,
37
- },
38
- offset: [window.scrollX, window.scrollY],
39
- }}
40
- point={ctxMenuService.point || {}}
41
- popupClassName='point-popup'
42
- builtinPlacements={placements}
43
- popup={
44
- <ClickOutside mouseEvents={['click', 'contextmenu']} onOutsideClick={onClickOutSide}>
45
- <MenuActionList data={ctxMenuService.menuNodes} afterClick={handleClick} context={ctxMenuService.context} />
46
- </ClickOutside>
47
- }
48
- alignPoint
49
- />
50
- );
51
- });
52
-
53
- CtxMenu.displayName = 'CtxMenu';
@@ -1,18 +0,0 @@
1
- import { Injectable, Autowired } from '@opensumi/di';
2
- import { IContextKeyService, IContextKey } from '@opensumi/ide-core-browser';
3
- import { DialogViewVisibleContext } from '@opensumi/ide-core-browser/lib/contextkey/dialog';
4
-
5
- @Injectable()
6
- export class DialogContextKey {
7
- @Autowired(IContextKeyService)
8
- private readonly globalContextKeyService: IContextKeyService;
9
-
10
- public readonly dialogViewVisibleContext: IContextKey<boolean>;
11
-
12
- private readonly _contextKeyService: IContextKeyService;
13
-
14
- constructor() {
15
- this._contextKeyService = this.globalContextKeyService;
16
- this.dialogViewVisibleContext = DialogViewVisibleContext.bind(this._contextKeyService);
17
- }
18
- }
@@ -1,43 +0,0 @@
1
- import { Autowired } from '@opensumi/di';
2
- import {
3
- DIALOG_COMMANDS,
4
- Domain,
5
- localize,
6
- CommandContribution,
7
- CommandRegistry,
8
- KeybindingContribution,
9
- KeybindingRegistry,
10
- } from '@opensumi/ide-core-browser';
11
- import { DialogViewVisibleContext } from '@opensumi/ide-core-browser/lib/contextkey/dialog';
12
-
13
- import { IDialogService } from '../common';
14
-
15
- @Domain(CommandContribution, KeybindingContribution)
16
- export class DialogContribution implements CommandContribution, KeybindingContribution {
17
- @Autowired(IDialogService)
18
- private dialogService: IDialogService;
19
-
20
- registerCommands(registry: CommandRegistry) {
21
- registry.registerCommand(
22
- {
23
- id: DIALOG_COMMANDS.ENSURE.id,
24
- label: localize('dialog.ensure'),
25
- },
26
- {
27
- execute: () => {
28
- const buttons = this.dialogService.getButtons();
29
- // 默认使用最后一个选项作为返回值
30
- this.dialogService.hide(buttons[buttons.length - 1]);
31
- },
32
- },
33
- );
34
- }
35
-
36
- registerKeybindings(bindings: KeybindingRegistry) {
37
- bindings.registerKeybinding({
38
- command: DIALOG_COMMANDS.ENSURE.id,
39
- keybinding: 'enter',
40
- when: `${DialogViewVisibleContext.raw}`,
41
- });
42
- }
43
- }
@@ -1,110 +0,0 @@
1
- import { observable, action } from 'mobx';
2
-
3
- import { Injectable, Autowired } from '@opensumi/di';
4
- import { Deferred, MessageType } from '@opensumi/ide-core-common';
5
-
6
- import { IDialogService, AbstractMessageService, Icon } from '../common';
7
-
8
- import { DialogContextKey } from './dialog.contextkey';
9
-
10
- @Injectable()
11
- export class DialogService extends AbstractMessageService implements IDialogService {
12
- protected type: MessageType | undefined;
13
-
14
- protected deferred: Deferred<any>;
15
-
16
- @Autowired(DialogContextKey)
17
- private readonly contextkeyService: DialogContextKey;
18
-
19
- @observable
20
- protected visible = false;
21
-
22
- protected message: string | React.ReactNode = '';
23
-
24
- protected title = '';
25
-
26
- public closable = true;
27
-
28
- protected buttons: string[] = [];
29
-
30
- protected props: Record<string, any> = {};
31
-
32
- @action
33
- open<T = string>(
34
- message: string | React.ReactNode,
35
- type: MessageType,
36
- buttons?: any[],
37
- closable = true,
38
- _?: string,
39
- props?: Record<string, any>,
40
- ): Promise<T | undefined> {
41
- this.deferred = new Deferred<string>();
42
- this.type = type;
43
- this.message = message;
44
- this.visible = true;
45
- this.contextkeyService.dialogViewVisibleContext.set(true);
46
- this.closable = closable;
47
- this.props = props ?? {};
48
- if (buttons) {
49
- this.buttons = buttons;
50
- }
51
- return this.deferred.promise;
52
- }
53
-
54
- @action
55
- hide<T = string>(value?: T): void {
56
- this.visible = false;
57
- this.contextkeyService.dialogViewVisibleContext.set(false);
58
- this.deferred.resolve(value);
59
- }
60
-
61
- @action
62
- reset(): void {
63
- this.type = undefined;
64
- this.message = '';
65
- this.buttons = [];
66
- this.props = {};
67
- }
68
-
69
- isVisible(): boolean {
70
- return this.visible;
71
- }
72
-
73
- getMessage(): string | React.ReactNode {
74
- return this.message;
75
- }
76
-
77
- getType(): MessageType | undefined {
78
- return this.type;
79
- }
80
-
81
- getIcon(): Icon | undefined {
82
- switch (this.type) {
83
- case MessageType.Error:
84
- return {
85
- color: 'var(--notificationsErrorIcon-foreground)',
86
- className: 'close-circle',
87
- };
88
- case MessageType.Info:
89
- return {
90
- color: 'var(--notificationsInfoIcon-foreground)',
91
- className: 'info-circle',
92
- };
93
- case MessageType.Warning:
94
- return {
95
- color: 'var(--notificationsWarningIcon-foreground)',
96
- className: 'question-circle',
97
- };
98
- default:
99
- break;
100
- }
101
- }
102
-
103
- getButtons(): string[] {
104
- return this.buttons;
105
- }
106
-
107
- getProps(): Record<string, any> {
108
- return this.props;
109
- }
110
- }
@@ -1,65 +0,0 @@
1
- import { observer } from 'mobx-react-lite';
2
- import React from 'react';
3
-
4
- import { Button, Dialog as DialogView } from '@opensumi/ide-components';
5
- import { useInjectable, localize } from '@opensumi/ide-core-browser';
6
- import { strings } from '@opensumi/ide-core-browser';
7
-
8
- import { IDialogService } from '../common';
9
-
10
- export const Dialog = observer(() => {
11
- const dialogService = useInjectable<IDialogService>(IDialogService);
12
- const icon = dialogService.getIcon();
13
- const message = dialogService.getMessage();
14
- const buttons = dialogService.getButtons();
15
- const type = dialogService.getType();
16
- // props will transfer to Overlay component
17
- const customProps = dialogService.getProps();
18
-
19
- function afterClose() {
20
- dialogService.reset();
21
- }
22
-
23
- function handleClose() {
24
- dialogService.hide();
25
- }
26
-
27
- function handlerClickButton(value: string) {
28
- return () => {
29
- dialogService.hide(value);
30
- };
31
- }
32
-
33
- return (
34
- <DialogView
35
- visible={dialogService.isVisible()}
36
- onClose={handleClose}
37
- closable={dialogService.closable}
38
- afterClose={afterClose}
39
- message={message}
40
- type='confirm'
41
- messageType={type}
42
- icon={icon}
43
- keyboard={true}
44
- buttons={
45
- buttons.length ? (
46
- buttons.map((button, index) => (
47
- <Button
48
- size='large'
49
- onClick={handlerClickButton(button)}
50
- key={button}
51
- type={index === buttons.length - 1 ? 'primary' : 'secondary'}
52
- >
53
- {strings.mnemonicButtonLabel(button, true)}
54
- </Button>
55
- ))
56
- ) : (
57
- <Button size='large' onClick={handleClose} type='primary'>
58
- {localize('dialog.confirm')}
59
- </Button>
60
- )
61
- }
62
- {...customProps}
63
- />
64
- );
65
- });
@@ -1,38 +0,0 @@
1
- import { Provider, Injectable } from '@opensumi/di';
2
- import { BrowserModule } from '@opensumi/ide-core-browser';
3
- import { IBrowserCtxMenu } from '@opensumi/ide-core-browser/lib/menu/next/renderer/ctxmenu/browser';
4
-
5
- import { IDialogService, IMessageService } from '../common';
6
-
7
- import { BrowserCtxMenuService } from './ctx-menu/ctx-menu.service';
8
- import { DialogContextKey } from './dialog.contextkey';
9
- import { DialogContribution } from './dialog.contribution';
10
- import { DialogService } from './dialog.service';
11
- import { Overlay } from './index.view';
12
- import { MessageService } from './message.service';
13
-
14
- @Injectable()
15
- export class OverlayModule extends BrowserModule {
16
- providers: Provider[] = [
17
- {
18
- token: DialogContextKey,
19
- useClass: DialogContextKey,
20
- },
21
- {
22
- token: IDialogService,
23
- useClass: DialogService,
24
- },
25
- {
26
- token: IMessageService,
27
- useClass: MessageService,
28
- },
29
- {
30
- token: IBrowserCtxMenu,
31
- useClass: BrowserCtxMenuService,
32
- },
33
- DialogContribution,
34
- ];
35
-
36
- isOverlay = true;
37
- component = Overlay;
38
- }
@@ -1,49 +0,0 @@
1
- import { observer } from 'mobx-react-lite';
2
- import React from 'react';
3
-
4
- import {
5
- ComponentRenderer,
6
- ComponentRegistry,
7
- SlotLocation,
8
- useInjectable,
9
- AppConfig,
10
- IClientApp,
11
- } from '@opensumi/ide-core-browser';
12
-
13
- import { CtxMenu } from './ctx-menu/ctx-menu.view';
14
- import { Dialog } from './dialog.view';
15
- import './styles.module.less';
16
-
17
- export const Overlay = observer(() => {
18
- const componentRegistry: ComponentRegistry = useInjectable(ComponentRegistry);
19
- const clientApp = useInjectable(IClientApp);
20
- const [extraComponents, setExtra] = React.useState<React.ComponentType[]>([]);
21
- const appConfig: AppConfig = useInjectable(AppConfig);
22
- React.useEffect(() => {
23
- // 对于嵌套在模块视图的SlotRenderer,渲染时应用已启动
24
- clientApp.appInitialized.promise.then(() => {
25
- if (appConfig.layoutConfig[SlotLocation.extra]?.modules) {
26
- const components: React.ComponentType[] = [];
27
- appConfig.layoutConfig[SlotLocation.extra].modules.forEach((name) => {
28
- const info = componentRegistry.getComponentRegistryInfo(name);
29
- if (info) {
30
- (info.views || []).forEach((v) => {
31
- if (v.component) {
32
- components.push(v.component!);
33
- }
34
- });
35
- }
36
- });
37
- setExtra(components);
38
- }
39
- });
40
- }, []);
41
-
42
- return (
43
- <div id='ide-overlay' className='ide-overlay'>
44
- <Dialog />
45
- <CtxMenu />
46
- <ComponentRenderer Component={extraComponents} />
47
- </div>
48
- );
49
- });
File without changes
@@ -1,81 +0,0 @@
1
- import React from 'react';
2
-
3
- import { Autowired, Injectable } from '@opensumi/di';
4
- import { notification, open } from '@opensumi/ide-components';
5
- import { IOpenerService, toMarkdown } from '@opensumi/ide-core-browser';
6
- import { MessageType, uuid, localize } from '@opensumi/ide-core-common';
7
-
8
- import { IMessageService, AbstractMessageService, MAX_MESSAGE_LENGTH } from '../common';
9
-
10
- @Injectable()
11
- export class MessageService extends AbstractMessageService implements IMessageService {
12
- @Autowired(IOpenerService)
13
- private readonly openerService: IOpenerService;
14
-
15
- // 上一个展示的文案
16
- private preMessage: string | React.ReactNode;
17
-
18
- // 当前组件展示的时间
19
- private showTime = 0;
20
-
21
- // 相同文案返回的间隔时间
22
- // https://github.com/react-component/notification#notificationnoticeprops
23
- protected static SAME_MESSAGE_DURATION = 30;
24
-
25
- // 参考 vscode message 组件消失的时间
26
- protected static DURATION: { [type: number]: number } = {
27
- [MessageType.Info]: 15,
28
- [MessageType.Warning]: 18,
29
- [MessageType.Error]: 20,
30
- };
31
-
32
- /**
33
- *
34
- * @param rawMessage message
35
- * @param type MessageType
36
- * @param buttons buttons
37
- * @param closable true | false
38
- * @param from from extension
39
- */
40
- open<T = string>(
41
- rawMessage: string | React.ReactNode,
42
- type: MessageType,
43
- buttons?: string[],
44
- closable = true,
45
- from?: string,
46
- ): Promise<T | undefined> {
47
- if (!rawMessage) {
48
- return Promise.resolve(undefined);
49
- }
50
- let message = rawMessage;
51
- // 如果两秒内提示信息相同,则直接返回上一个提示
52
- if (
53
- Date.now() - this.showTime < MessageService.SAME_MESSAGE_DURATION &&
54
- typeof message === 'string' &&
55
- this.preMessage === message
56
- ) {
57
- return Promise.resolve(undefined);
58
- }
59
- this.preMessage = typeof message === 'string' && message;
60
- this.showTime = Date.now();
61
- if (typeof rawMessage === 'string' && rawMessage.length > MAX_MESSAGE_LENGTH) {
62
- message = `${rawMessage.substr(0, MAX_MESSAGE_LENGTH)}...`;
63
- }
64
- const description = from && typeof from === 'string' ? `${localize('component.message.origin')}: ${from}` : '';
65
- const key = uuid();
66
- const promise = open<T>(
67
- toMarkdown(message, this.openerService),
68
- type,
69
- closable,
70
- key,
71
- buttons,
72
- description,
73
- MessageService.DURATION[type],
74
- );
75
- return promise || Promise.resolve(undefined);
76
- }
77
-
78
- hide(): void {
79
- notification.destroy();
80
- }
81
- }
@@ -1,8 +0,0 @@
1
- :global {
2
- .ide-overlay {
3
- position: relative;
4
- z-index: 999;
5
- overflow: auto;
6
- outline: 0;
7
- }
8
- }
@@ -1,134 +0,0 @@
1
- import React from 'react';
2
-
3
- import { MessageType, URI } from '@opensumi/ide-core-common';
4
-
5
- export const IMessageService = Symbol('IMessageService');
6
-
7
- export interface IMessageService {
8
- info(
9
- message: string | React.ReactNode,
10
- buttons?: string[],
11
- closable?: boolean,
12
- props?: Record<string, any>,
13
- ): Promise<string | undefined>;
14
- warning(
15
- message: string | React.ReactNode,
16
- buttons?: string[],
17
- closable?: boolean,
18
- props?: Record<string, any>,
19
- ): Promise<string | undefined>;
20
- error(
21
- message: string | React.ReactNode,
22
- buttons?: string[],
23
- closable?: boolean,
24
- props?: Record<string, any>,
25
- ): Promise<string | undefined>;
26
- open<T = string>(
27
- message: string | React.ReactNode,
28
- type: MessageType,
29
- buttons?: string[],
30
- closable?: boolean,
31
- from?: string,
32
- props?: Record<string, any>,
33
- ): Promise<T | undefined>;
34
- hide<T = string>(value?: T): void;
35
- }
36
-
37
- export interface Icon {
38
- color: string;
39
- className: string;
40
- }
41
-
42
- export const MAX_MESSAGE_LENGTH = 1000;
43
-
44
- export const IDialogService = Symbol('IDialogService');
45
- export interface IDialogService extends IMessageService {
46
- closable?: boolean;
47
- isVisible(): boolean;
48
- getMessage(): string | React.ReactNode;
49
- getIcon(): Icon | undefined;
50
- getButtons(): string[];
51
- getType(): MessageType | undefined;
52
- getProps(): Record<string, any>;
53
- reset(): void;
54
- }
55
-
56
- export abstract class AbstractMessageService implements IMessageService {
57
- info(
58
- message: string | React.ReactNode,
59
- buttons?: string[],
60
- closable?: boolean,
61
- props?: Record<string, any>,
62
- ): Promise<string | undefined> {
63
- return this.open(message, MessageType.Info, buttons, closable, undefined, props);
64
- }
65
-
66
- warning(
67
- message: string | React.ReactNode,
68
- buttons?: string[],
69
- closable?: boolean,
70
- props?: Record<string, any>,
71
- ): Promise<string | undefined> {
72
- return this.open(message, MessageType.Warning, buttons, closable, undefined, props);
73
- }
74
-
75
- error(
76
- message: string | React.ReactNode,
77
- buttons?: string[],
78
- closable?: boolean,
79
- props?: Record<string, any>,
80
- ): Promise<string | undefined> {
81
- return this.open(message, MessageType.Error, buttons, closable, undefined, props);
82
- }
83
- abstract open<T = string>(
84
- message: string | React.ReactNode,
85
- type: MessageType,
86
- buttons?: any[],
87
- closable?: boolean,
88
- from?: string,
89
- props?: Record<string, any>,
90
- ): Promise<T | undefined>;
91
- abstract hide<T = string>(value?: T): void;
92
- }
93
-
94
- export interface IWindowDialogService {
95
- showOpenDialog(options?: IOpenDialogOptions): Promise<URI[] | undefined>;
96
- showSaveDialog(options?: ISaveDialogOptions): Promise<URI | undefined>;
97
- }
98
-
99
- export const IWindowDialogService = Symbol('IWindowDialogService');
100
-
101
- export interface IDialogOptions {
102
- title?: string;
103
- defaultUri?: URI;
104
- filters?: {
105
- [name: string]: string;
106
- };
107
- }
108
-
109
- export interface ISaveDialogOptions extends IDialogOptions {
110
- saveLabel?: string;
111
- showNameInput?: boolean;
112
- defaultFileName?: string;
113
- }
114
-
115
- export interface IOpenDialogOptions extends IDialogOptions {
116
- canSelectFiles?: boolean;
117
- canSelectFolders?: boolean;
118
- canSelectMany?: boolean;
119
- openLabel?: string;
120
- }
121
-
122
- export namespace ISaveDialogOptions {
123
- export function is(option) {
124
- return 'saveLabel' in option || 'showNameInput' in option || 'defaultFileName' in option;
125
- }
126
- }
127
-
128
- export namespace IOpenDialogOptions {
129
- export function is(option) {
130
- return (
131
- 'canSelectFiles' in option || 'canSelectFolders' in option || 'canSelectMany' in option || 'openLabel' in option
132
- );
133
- }
134
- }
package/src/index.ts DELETED
@@ -1 +0,0 @@
1
- export * from './common';