chore: merge from develop

This commit is contained in:
JackLian 2022-12-22 12:44:04 +08:00
parent 46789ac581
commit 0f38cc8e3d
8 changed files with 30 additions and 18 deletions

View File

@ -26,7 +26,6 @@
}, },
"devDependencies": { "devDependencies": {
"@alib/build-scripts": "^0.1.29", "@alib/build-scripts": "^0.1.29",
"@alilc/lowcode-shell": "1.1.0-beta.7",
"@testing-library/react": "^11.2.2", "@testing-library/react": "^11.2.2",
"@types/classnames": "^2.2.7", "@types/classnames": "^2.2.7",
"@types/enzyme": "^3.10.12", "@types/enzyme": "^3.10.12",

View File

@ -29,6 +29,7 @@ export class LowCodePluginManager implements ILowCodePluginManager {
private plugins: ILowCodePluginRuntime[] = []; private plugins: ILowCodePluginRuntime[] = [];
pluginsMap: Map<string, ILowCodePluginRuntime> = new Map(); pluginsMap: Map<string, ILowCodePluginRuntime> = new Map();
pluginContextMap: Map<string, LowCodePluginContext> = new Map();
private pluginPreference?: PluginPreference = new Map(); private pluginPreference?: PluginPreference = new Map();
@ -39,7 +40,13 @@ export class LowCodePluginManager implements ILowCodePluginManager {
} }
_getLowCodePluginContext = (options: IPluginContextOptions) => { _getLowCodePluginContext = (options: IPluginContextOptions) => {
return new LowCodePluginContext(options, this.contextApiAssembler); const { pluginName } = options;
let context = this.pluginContextMap.get(pluginName);
if (!context) {
context = new LowCodePluginContext(options, this.contextApiAssembler);
this.pluginContextMap.set(pluginName, context);
}
return context;
}; };
isEngineVersionMatched(versionExp: string): boolean { isEngineVersionMatched(versionExp: string): boolean {

View File

@ -13,7 +13,7 @@ export class SettingsMain {
private _sessionId = ''; private _sessionId = '';
@obx.ref private _settings?: SettingTopEntry; @obx.ref private _settings?: SettingTopEntry | null = null;
@computed get length(): number | undefined { @computed get length(): number | undefined {
return this._settings?.nodes.length; return this._settings?.nodes.length;
@ -23,7 +23,7 @@ export class SettingsMain {
return this._settings?.componentMeta; return this._settings?.componentMeta;
} }
get settings() { @computed get settings() {
return this._settings; return this._settings;
} }
@ -48,7 +48,7 @@ export class SettingsMain {
this.disposeListener = () => { this.disposeListener = () => {
this.editor.removeListener('designer.selection.change', setupSelection); this.editor.removeListener('designer.selection.change', setupSelection);
}; };
const designer = await this.editor.onceGot(Designer); const designer = await this.editor.onceGot('designer');
this.designer = designer; this.designer = designer;
setupSelection(designer.currentSelection); setupSelection(designer.currentSelection);
} }

View File

@ -10,11 +10,11 @@ import { SkeletonContext } from '../../context';
import { createIcon, isSettingField } from '@alilc/lowcode-utils'; import { createIcon, isSettingField } from '@alilc/lowcode-utils';
@observer @observer
export class SettingsPrimaryPane extends Component<{ editor: Editor; config: any }, { shouldIgnoreRoot: boolean }> { export class SettingsPrimaryPane extends Component<{ engineEditor: Editor; config: any }, { shouldIgnoreRoot: boolean }> {
state = { state = {
shouldIgnoreRoot: false, shouldIgnoreRoot: false,
}; };
private main; private main = new SettingsMain(this.props.engineEditor);
@obx.ref private _activeKey?: any; @obx.ref private _activeKey?: any;
@ -29,8 +29,7 @@ export class SettingsPrimaryPane extends Component<{ editor: Editor; config: any
componentDidMount() { componentDidMount() {
this.setShouldIgnoreRoot(); this.setShouldIgnoreRoot();
const workspace = globalContext.get('workspace'); const editor = this.props.engineEditor;
const editor = workspace.isActive ? workspace.window.editor : globalContext.get('editor');
editor.eventBus.on('designer.selection.change', () => { editor.eventBus.on('designer.selection.change', () => {
if (!engineConfig.get('stayOnTheSameSettingTab', false)) { if (!engineConfig.get('stayOnTheSameSettingTab', false)) {
@ -135,8 +134,7 @@ export class SettingsPrimaryPane extends Component<{ editor: Editor; config: any
render() { render() {
const { settings } = this.main; const { settings } = this.main;
const workspace = globalContext.get('workspace'); const editor = this.props.engineEditor;
const editor = workspace.isActive ? workspace.window.editor : globalContext.get('editor');
if (!settings) { if (!settings) {
// 未选中节点,提示选中 或者 显示根节点设置 // 未选中节点,提示选中 或者 显示根节点设置
return ( return (

View File

@ -77,7 +77,7 @@ const { project: innerProject } = designer;
const innerHotkey = new InnerHotkey(); const innerHotkey = new InnerHotkey();
const hotkey = new Hotkey(innerHotkey); const hotkey = new Hotkey(innerHotkey);
const project = new Project(innerProject); const project = new Project(innerProject);
const skeleton = new Skeleton(innerSkeleton); const skeleton = new Skeleton(innerSkeleton, 'any', false);
const innerSetters = new InnerSetters(); const innerSetters = new InnerSetters();
const setters = new Setters(innerSetters); const setters = new Setters(innerSetters);
@ -98,7 +98,7 @@ const pluginContextApiAssembler: ILowCodePluginContextApiAssembler = {
assembleApis: (context: ILowCodePluginContextPrivate, pluginName: string, meta: IPublicTypePluginMeta) => { assembleApis: (context: ILowCodePluginContextPrivate, pluginName: string, meta: IPublicTypePluginMeta) => {
context.hotkey = hotkey; context.hotkey = hotkey;
context.project = project; context.project = project;
context.skeleton = skeleton; context.skeleton = new Skeleton(innerSkeleton, pluginName, false);
context.setters = setters; context.setters = setters;
context.material = material; context.material = material;
const eventPrefix = meta?.eventPrefix || 'common'; const eventPrefix = meta?.eventPrefix || 'common';

View File

@ -22,7 +22,9 @@ export const defaultPanelRegistry = (editor: any, designer: any) => {
area: 'rightArea', area: 'rightArea',
name: 'settingsPane', name: 'settingsPane',
type: 'Panel', type: 'Panel',
content: SettingsPrimaryPane, content: <SettingsPrimaryPane
engineEditor={editor}
/>,
props: { props: {
ignoreRoot: true, ignoreRoot: true,
}, },

View File

@ -9,6 +9,7 @@ import { IPublicApiSkeleton, IPublicTypeWidgetBaseConfig, IPublicTypeWidgetConfi
const innerSkeletonSymbol = Symbol('skeleton'); const innerSkeletonSymbol = Symbol('skeleton');
export class Skeleton implements IPublicApiSkeleton { export class Skeleton implements IPublicApiSkeleton {
private readonly [innerSkeletonSymbol]: InnerSkeleton; private readonly [innerSkeletonSymbol]: InnerSkeleton;
private readonly pluginName: string;
get [skeletonSymbol]() { get [skeletonSymbol]() {
if (this.workspaceMode) { if (this.workspaceMode) {
@ -22,8 +23,9 @@ export class Skeleton implements IPublicApiSkeleton {
return this[innerSkeletonSymbol]; return this[innerSkeletonSymbol];
} }
constructor(skeleton: InnerSkeleton, readonly workspaceMode: boolean = false) { constructor(skeleton: InnerSkeleton, pluginName: string, readonly workspaceMode: boolean = false) {
this[innerSkeletonSymbol] = skeleton; this[innerSkeletonSymbol] = skeleton;
this.pluginName = pluginName;
} }
/** /**
@ -33,7 +35,11 @@ export class Skeleton implements IPublicApiSkeleton {
* @returns * @returns
*/ */
add(config: IPublicTypeWidgetBaseConfig, extraConfig?: Record<string, any>) { add(config: IPublicTypeWidgetBaseConfig, extraConfig?: Record<string, any>) {
return this[skeletonSymbol].add(config, extraConfig); const configWithName = {
...config,
pluginName: this.pluginName,
};
return this[skeletonSymbol].add(configWithName, extraConfig);
} }
/** /**

View File

@ -82,7 +82,7 @@ export class BasicContext {
const config = engineConfig; const config = engineConfig;
const event = new Event(editor, { prefix: 'common' }); const event = new Event(editor, { prefix: 'common' });
const logger = getLogger({ level: 'warn', bizName: 'common' }); const logger = getLogger({ level: 'warn', bizName: 'common' });
const skeleton = new Skeleton(innerSkeleton, true); const skeleton = new Skeleton(innerSkeleton, 'any', true);
editor.set('setters', setters); editor.set('setters', setters);
editor.set('project', project); editor.set('project', project);
editor.set('material', material); editor.set('material', material);
@ -110,7 +110,7 @@ export class BasicContext {
context.workspace = workspace; context.workspace = workspace;
context.hotkey = hotkey; context.hotkey = hotkey;
context.project = project; context.project = project;
context.skeleton = skeleton; context.skeleton = new Skeleton(innerSkeleton, pluginName, true);
context.setters = setters; context.setters = setters;
context.material = material; context.material = material;
const eventPrefix = meta?.eventPrefix || 'common'; const eventPrefix = meta?.eventPrefix || 'common';