chore: 兼容 editor, 实际提供的是 event 对象

This commit is contained in:
lihao.ylh 2021-12-31 11:04:06 +08:00
parent e75cdc99a7
commit 7b8e1d862d
10 changed files with 27 additions and 15 deletions

View File

@ -13,7 +13,7 @@ export class SettingsPrimaryPane extends Component<{ editor: Editor; config: any
state = {
shouldIgnoreRoot: false,
};
private main = new SettingsMain(this.props.editor);
private main = new SettingsMain(globalContext.get('editor'));
@obx.ref private _activeKey?: any;
@ -25,7 +25,7 @@ export class SettingsPrimaryPane extends Component<{ editor: Editor; config: any
componentDidMount() {
this.setShouldIgnoreRoot();
this.props.editor.on('designer.selection.change', () => {
globalContext.get('editor').on('designer.selection.change', () => {
if (!engineConfig.get('stayOnTheSameSettingTab', false)) {
this._activeKey = null;
}
@ -33,7 +33,7 @@ export class SettingsPrimaryPane extends Component<{ editor: Editor; config: any
}
async setShouldIgnoreRoot() {
const designMode = await this.props.editor.get('designMode');
const designMode = await globalContext.get('editor').get('designMode');
this.setState({
shouldIgnoreRoot: designMode === 'live',
});

View File

@ -1,6 +1,7 @@
import { ReactNode, createElement } from 'react';
import { makeObservable, obx } from '@ali/lowcode-editor-core';
import { uniqueId, createContent } from '@ali/lowcode-utils';
import { getEvent } from '@ali/lowcode-shell';
import { DockConfig } from '../types';
import { Skeleton } from '../skeleton';
import { DockView, WidgetView } from '../components/widget-views';
@ -48,7 +49,7 @@ export default class Dock implements IWidget {
this._body = createContent(content, {
...contentProps,
config: this.config,
editor: this.skeleton.editor,
editor: getEvent(this.skeleton.editor),
});
} else {
this._body = createElement(DockView, props);

View File

@ -4,6 +4,7 @@ import { obx, computed, makeObservable } from '@ali/lowcode-editor-core';
import { uniqueId, createContent } from '@ali/lowcode-utils';
import { TitleContent } from '@ali/lowcode-types';
import WidgetContainer from './widget-container';
import { getEvent } from '@ali/lowcode-shell';
import { PanelConfig, HelpTipConfig } from '../types';
import { TitledPanelView, TabsPanelView, PanelView } from '../components/widget-views';
import { Skeleton } from '../skeleton';
@ -51,7 +52,7 @@ export default class Panel implements IWidget {
const { content, contentProps } = this.config;
return createContent(content, {
...contentProps,
editor: this.skeleton.editor,
editor: getEvent(this.skeleton.editor),
config: this.config,
panel: this,
pane: this,

View File

@ -1,6 +1,7 @@
import { ReactNode, createElement } from 'react';
import { makeObservable, obx } from '@ali/lowcode-editor-core';
import { createContent, uniqueId } from '@ali/lowcode-utils';
import { getEvent } from '@ali/lowcode-shell';
import { WidgetConfig, IWidgetBaseConfig } from '../types';
import { Skeleton } from '../skeleton';
import { WidgetView } from '../components/widget-views';
@ -56,7 +57,7 @@ export default class Widget implements IWidget {
this._body = createContent(content, {
...contentProps,
config: this.config,
editor: this.skeleton.editor,
editor: getEvent(this.skeleton.editor),
});
return this._body;
}

View File

@ -40,10 +40,12 @@ globalContext.register(editor, 'editor');
const innerSkeleton = new InnerSkeleton(editor);
editor.set(Skeleton, innerSkeleton);
editor.set('skeleton' as any, innerSkeleton);
engineConfig.set('skeleton' as any, innerSkeleton);
const designer = new Designer({ editor });
editor.set(Designer, designer);
editor.set('designer' as any, designer);
engineConfig.set('designer' as any, designer);
const plugins = new LowCodePluginManager(editor).toProxy();
editor.set('plugins' as any, plugins);

View File

@ -1,5 +1,5 @@
import React, { PureComponent } from 'react';
import { Editor, engineConfig } from '@ali/lowcode-editor-core';
import { Editor, engineConfig, globalContext } from '@ali/lowcode-editor-core';
import { DesignerView, Designer } from '@ali/lowcode-designer';
import { Asset } from '@ali/lowcode-utils';
import './index.scss';
@ -46,7 +46,7 @@ export default class DesignerPlugin extends PureComponent<PluginProps, DesignerP
}
private async setupAssets() {
const { editor } = this.props;
const editor = globalContext.get('editor');
try {
const assets = await editor.onceGot('assets');
const renderEnv = engineConfig.get('renderEnv') || editor.get('renderEnv');
@ -85,7 +85,7 @@ export default class DesignerPlugin extends PureComponent<PluginProps, DesignerP
}
private handleDesignerMount = (designer: Designer): void => {
const { editor } = this.props;
const editor = globalContext.get('editor');
editor.set('designer', designer);
editor.emit('designer.ready', designer);
editor.onGot('schema', (schema) => {
@ -94,7 +94,7 @@ export default class DesignerPlugin extends PureComponent<PluginProps, DesignerP
};
render(): React.ReactNode {
const { editor } = this.props;
const editor = globalContext.get('editor');
const {
componentMetadatas,
utilsMetadata,

View File

@ -1,4 +1,5 @@
import { PureComponent } from 'react';
import { globalContext } from '@ali/lowcode-editor-core';
import { PluginProps } from '@ali/lowcode-types';
import { OutlinePane } from './pane';
@ -8,7 +9,7 @@ export class OutlineBackupPane extends PureComponent<PluginProps> {
render() {
return (
<OutlinePane
editor={this.props.editor}
editor={globalContext.get('editor')}
config={{
name: Backup,
}}

View File

@ -1,5 +1,5 @@
import React, { Component } from 'react';
import { observer } from '@ali/lowcode-editor-core';
import { observer, globalContext } from '@ali/lowcode-editor-core';
import { intl } from '../locale';
import { OutlineMain } from '../main';
import TreeView from './tree';
@ -8,7 +8,7 @@ import { IEditor } from '@ali/lowcode-types';
@observer
export class OutlinePane extends Component<{ config: any; editor: IEditor }> {
private main = new OutlineMain(this.props.editor, this.props.config.name || this.props.config.pluginKey);
private main = new OutlineMain(globalContext.get('editor'), this.props.config.name || this.props.config.pluginKey);
componentWillUnmount() {
this.main.purge();

View File

@ -1,4 +1,4 @@
import { Editor as InnerEditor } from '@ali/lowcode-editor-core';
import { Editor as InnerEditor, globalContext } from '@ali/lowcode-editor-core';
import { getLogger } from '@ali/lowcode-utils';
import { editorSymbol } from './symbols';
@ -12,6 +12,7 @@ export default class Event {
private readonly [editorSymbol]: InnerEditor;
private readonly options: EventOptions;
// TODO:
/**
*
*/
@ -41,3 +42,7 @@ export default class Event {
this[editorSymbol].emit(`${this.options.prefix}:${event}`, ...args);
}
}
export function getEvent(editor: InnerEditor, options: any = { prefix: 'common' }) {
return new Event(editor, options);
}

View File

@ -1,7 +1,7 @@
import Detecting from './detecting';
// import Dragon from './dragon';
import DocumentModel from './document-model';
import Event from './event';
import Event, { getEvent } from './event';
import History from './history';
import Material from './material';
import Node from './node';
@ -35,4 +35,5 @@ export {
Hotkey,
Skeleton,
SettingPropEntry,
getEvent,
};