fix: fix the problem of using canvas.dragon api in workspace mode

This commit is contained in:
liujuping 2023-01-05 11:13:20 +08:00 committed by 林熠
parent 02b4a5eaa9
commit b07d33e99a
7 changed files with 31 additions and 10 deletions

View File

@ -59,7 +59,7 @@ export interface DesignerProps {
export class Designer implements IDesigner { export class Designer implements IDesigner {
readonly dragon = new Dragon(this); dragon: Dragon;
readonly componentActions = new ComponentActions(); readonly componentActions = new ComponentActions();
@ -99,6 +99,7 @@ export class Designer implements IDesigner {
this.project = new Project(this, props.defaultSchema, viewName); this.project = new Project(this, props.defaultSchema, viewName);
this.dragon = new Dragon(this);
this.dragon.onDragstart((e) => { this.dragon.onDragstart((e) => {
this.detecting.enable = false; this.detecting.enable = false;
const { dragObject } = e; const { dragObject } = e;
@ -564,6 +565,10 @@ export class Designer implements IDesigner {
} }
addPropsReducer(reducer: IPublicTypePropsTransducer, stage: IPublicEnumTransformStage) { addPropsReducer(reducer: IPublicTypePropsTransducer, stage: IPublicEnumTransformStage) {
if (!reducer) {
logger.error('reducer is not available');
return;
}
const reducers = this.propsReducers.get(stage); const reducers = this.propsReducers.get(stage);
if (reducers) { if (reducers) {
reducers.push(reducer); reducers.push(reducer);

View File

@ -26,7 +26,7 @@ export class Canvas implements IPublicApiCanvas {
return this[editorSymbol].get('designer') as IDesigner; return this[editorSymbol].get('designer') as IDesigner;
} }
constructor(editor: IPublicModelEditor) { constructor(editor: IPublicModelEditor, readonly workspaceMode: boolean = false) {
this[editorSymbol] = editor; this[editorSymbol] = editor;
} }
@ -49,7 +49,7 @@ export class Canvas implements IPublicApiCanvas {
} }
get dragon(): IPublicModelDragon | null { get dragon(): IPublicModelDragon | null {
return Dragon.create(this[designerSymbol].dragon); return Dragon.create(this[designerSymbol].dragon, this.workspaceMode);
} }
get activeTracker(): IPublicModelActiveTracker | null { get activeTracker(): IPublicModelActiveTracker | null {

View File

@ -19,11 +19,14 @@ export const innerDragonSymbol = Symbol('innerDragonSymbol');
export class Dragon implements IPublicModelDragon { export class Dragon implements IPublicModelDragon {
private readonly [innerDragonSymbol]: IPublicModelDragon; private readonly [innerDragonSymbol]: IPublicModelDragon;
constructor(innerDragon: IPublicModelDragon) { constructor(innerDragon: IPublicModelDragon, readonly workspaceMode: boolean) {
this[innerDragonSymbol] = innerDragon; this[innerDragonSymbol] = innerDragon;
} }
get [dragonSymbol](): any { get [dragonSymbol](): any {
if (this.workspaceMode) {
return this[innerDragonSymbol];
}
const workspace = globalContext.get('workspace'); const workspace = globalContext.get('workspace');
let editor = globalContext.get('editor'); let editor = globalContext.get('editor');
@ -35,11 +38,11 @@ export class Dragon implements IPublicModelDragon {
return designer.dragon; return designer.dragon;
} }
static create(dragon: IPublicModelDragon | null): IPublicModelDragon | null { static create(dragon: IPublicModelDragon | null, workspaceMode: boolean): IPublicModelDragon | null {
if (!dragon) { if (!dragon) {
return null; return null;
} }
return new Dragon(dragon); return new Dragon(dragon, workspaceMode);
} }
/** /**

View File

@ -81,7 +81,7 @@ export class BasicContext {
const event = new Event(commonEvent, { prefix: 'common' }); const event = new Event(commonEvent, { prefix: 'common' });
const logger = getLogger({ level: 'warn', bizName: 'common' }); const logger = getLogger({ level: 'warn', bizName: 'common' });
const skeleton = new Skeleton(innerSkeleton, 'any', true); const skeleton = new Skeleton(innerSkeleton, 'any', true);
const canvas = new Canvas(editor); const canvas = new Canvas(editor, 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);

View File

@ -153,6 +153,7 @@ body {
.lc-top-area-left, .lc-sub-top-area-left { .lc-top-area-left, .lc-sub-top-area-left {
display: flex; display: flex;
align-items: center; align-items: center;
max-width: 100%;
} }
.lc-top-area-center, .lc-sub-top-area-center { .lc-top-area-center, .lc-sub-top-area-center {
@ -361,6 +362,18 @@ body {
} }
} }
.lc-workspace-workbench-center-content {
position: absolute;
top: 0;
right: 0;
bottom: 0;
left: 0;
}
.engine-actionitem {
max-width: 100%;
}
.lc-workspace-workbench-window { .lc-workspace-workbench-window {
position: relative; position: relative;
height: 100%; height: 100%;

View File

@ -41,7 +41,7 @@ export class Workbench extends Component<{
<LeftFloatPane area={skeleton.leftFloatArea} /> <LeftFloatPane area={skeleton.leftFloatArea} />
<LeftFixedPane area={skeleton.leftFixedArea} /> <LeftFixedPane area={skeleton.leftFixedArea} />
<div className="lc-workspace-workbench-center"> <div className="lc-workspace-workbench-center">
<> <div className="lc-workspace-workbench-center-content">
<SubTopArea area={skeleton.subTopArea} itemClassName={topAreaItemClassName} /> <SubTopArea area={skeleton.subTopArea} itemClassName={topAreaItemClassName} />
<div className="lc-workspace-workbench-window"> <div className="lc-workspace-workbench-window">
{ {
@ -54,7 +54,7 @@ export class Workbench extends Component<{
)) ))
} }
</div> </div>
</> </div>
<MainArea area={skeleton.mainArea} /> <MainArea area={skeleton.mainArea} />
<BottomArea area={skeleton.bottomArea} /> <BottomArea area={skeleton.bottomArea} />
</div> </div>

View File

@ -101,7 +101,7 @@ export class Workspace implements IPublicApiWorkspace {
private remove(index: number) { private remove(index: number) {
const window = this.windows[index]; const window = this.windows[index];
this.windows = this.windows.splice(index - 1, 1); this.windows.splice(index, 1);
if (this.window === window) { if (this.window === window) {
this.window = this.windows[index] || this.windows[index + 1] || this.windows[index - 1]; this.window = this.windows[index] || this.windows[index + 1] || this.windows[index - 1];
this.emitChangeActiveWindow(); this.emitChangeActiveWindow();