Skip to content

Commit

Permalink
fix(context-menu): fix context menu component instance changed
Browse files Browse the repository at this point in the history
  • Loading branch information
liujuping committed Jan 17, 2024
1 parent a8b9b2b commit 8f8908c
Showing 1 changed file with 20 additions and 15 deletions.
35 changes: 20 additions & 15 deletions packages/shell/src/api/commonUI.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -8,6 +8,7 @@ import {
import { Balloon, Breadcrumb, Button, Card, Checkbox, DatePicker, Dialog, Dropdown, Form, Icon, Input, Loading, Message, Overlay, Pagination, Radio, Search, Select, SplitButton, Step, Switch, Tab, Table, Tree, TreeSelect, Upload, Divider } from '@alifd/next';
import { ContextMenu } from '../components/context-menu';
import { editorSymbol } from '../symbols';
import { ReactElement } from 'react';

export class CommonUI implements IPublicApiCommonUI {
[editorSymbol]: IEditor;
Expand Down Expand Up @@ -40,8 +41,27 @@ export class CommonUI implements IPublicApiCommonUI {
Upload = Upload;
Divider = Divider;

ContextMenu: ((props: {
menus: IPublicTypeContextMenuAction[];
children: React.ReactElement[] | React.ReactElement;
}) => ReactElement) & {
create(menus: IPublicTypeContextMenuAction[], event: MouseEvent | React.MouseEvent): void;
};

constructor(editor: IEditor) {
this[editorSymbol] = editor;

const innerContextMenu = (props: any) => {
const pluginContext: IPublicModelPluginContext = editor.get('pluginContext') as IPublicModelPluginContext;
return <ContextMenu {...props} pluginContext={pluginContext} />;
};

innerContextMenu.create = (menus: IPublicTypeContextMenuAction[], event: MouseEvent) => {
const pluginContext: IPublicModelPluginContext = editor.get('pluginContext') as IPublicModelPluginContext;
return ContextMenu.create(pluginContext, menus, event);
};

this.ContextMenu = innerContextMenu;
}

get Tip() {
Expand All @@ -55,19 +75,4 @@ export class CommonUI implements IPublicApiCommonUI {
get Title() {
return InnerTitle;
}

get ContextMenu() {
const editor = this[editorSymbol];
const innerContextMenu = (props: any) => {
const pluginContext: IPublicModelPluginContext = editor.get('pluginContext') as IPublicModelPluginContext;
return <ContextMenu {...props} pluginContext={pluginContext} />;
};

innerContextMenu.create = (menus: IPublicTypeContextMenuAction[], event: MouseEvent) => {
const pluginContext: IPublicModelPluginContext = editor.get('pluginContext') as IPublicModelPluginContext;
return ContextMenu.create(pluginContext, menus, event);
};

return innerContextMenu;
}
}

0 comments on commit 8f8908c

Please sign in to comment.