Skip to content

Commit b07d33e

Browse files
liujupingJackLian
authored andcommitted
fix: fix the problem of using canvas.dragon api in workspace mode
1 parent 02b4a5e commit b07d33e

File tree

7 files changed

+31
-10
lines changed

7 files changed

+31
-10
lines changed

packages/designer/src/designer/designer.ts

Lines changed: 6 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -59,7 +59,7 @@ export interface DesignerProps {
5959

6060

6161
export class Designer implements IDesigner {
62-
readonly dragon = new Dragon(this);
62+
dragon: Dragon;
6363

6464
readonly componentActions = new ComponentActions();
6565

@@ -99,6 +99,7 @@ export class Designer implements IDesigner {
9999

100100
this.project = new Project(this, props.defaultSchema, viewName);
101101

102+
this.dragon = new Dragon(this);
102103
this.dragon.onDragstart((e) => {
103104
this.detecting.enable = false;
104105
const { dragObject } = e;
@@ -564,6 +565,10 @@ export class Designer implements IDesigner {
564565
}
565566

566567
addPropsReducer(reducer: IPublicTypePropsTransducer, stage: IPublicEnumTransformStage) {
568+
if (!reducer) {
569+
logger.error('reducer is not available');
570+
return;
571+
}
567572
const reducers = this.propsReducers.get(stage);
568573
if (reducers) {
569574
reducers.push(reducer);

packages/shell/src/api/canvas.ts

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -26,7 +26,7 @@ export class Canvas implements IPublicApiCanvas {
2626
return this[editorSymbol].get('designer') as IDesigner;
2727
}
2828

29-
constructor(editor: IPublicModelEditor) {
29+
constructor(editor: IPublicModelEditor, readonly workspaceMode: boolean = false) {
3030
this[editorSymbol] = editor;
3131
}
3232

@@ -49,7 +49,7 @@ export class Canvas implements IPublicApiCanvas {
4949
}
5050

5151
get dragon(): IPublicModelDragon | null {
52-
return Dragon.create(this[designerSymbol].dragon);
52+
return Dragon.create(this[designerSymbol].dragon, this.workspaceMode);
5353
}
5454

5555
get activeTracker(): IPublicModelActiveTracker | null {

packages/shell/src/model/dragon.ts

Lines changed: 6 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -19,11 +19,14 @@ export const innerDragonSymbol = Symbol('innerDragonSymbol');
1919
export class Dragon implements IPublicModelDragon {
2020
private readonly [innerDragonSymbol]: IPublicModelDragon;
2121

22-
constructor(innerDragon: IPublicModelDragon) {
22+
constructor(innerDragon: IPublicModelDragon, readonly workspaceMode: boolean) {
2323
this[innerDragonSymbol] = innerDragon;
2424
}
2525

2626
get [dragonSymbol](): any {
27+
if (this.workspaceMode) {
28+
return this[innerDragonSymbol];
29+
}
2730
const workspace = globalContext.get('workspace');
2831
let editor = globalContext.get('editor');
2932

@@ -35,11 +38,11 @@ export class Dragon implements IPublicModelDragon {
3538
return designer.dragon;
3639
}
3740

38-
static create(dragon: IPublicModelDragon | null): IPublicModelDragon | null {
41+
static create(dragon: IPublicModelDragon | null, workspaceMode: boolean): IPublicModelDragon | null {
3942
if (!dragon) {
4043
return null;
4144
}
42-
return new Dragon(dragon);
45+
return new Dragon(dragon, workspaceMode);
4346
}
4447

4548
/**

packages/workspace/src/base-context.ts

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -81,7 +81,7 @@ export class BasicContext {
8181
const event = new Event(commonEvent, { prefix: 'common' });
8282
const logger = getLogger({ level: 'warn', bizName: 'common' });
8383
const skeleton = new Skeleton(innerSkeleton, 'any', true);
84-
const canvas = new Canvas(editor);
84+
const canvas = new Canvas(editor, true);
8585
editor.set('setters', setters);
8686
editor.set('project', project);
8787
editor.set('material', material);

packages/workspace/src/layouts/workbench.less

Lines changed: 13 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -153,6 +153,7 @@ body {
153153
.lc-top-area-left, .lc-sub-top-area-left {
154154
display: flex;
155155
align-items: center;
156+
max-width: 100%;
156157
}
157158

158159
.lc-top-area-center, .lc-sub-top-area-center {
@@ -361,6 +362,18 @@ body {
361362
}
362363
}
363364

365+
.lc-workspace-workbench-center-content {
366+
position: absolute;
367+
top: 0;
368+
right: 0;
369+
bottom: 0;
370+
left: 0;
371+
}
372+
373+
.engine-actionitem {
374+
max-width: 100%;
375+
}
376+
364377
.lc-workspace-workbench-window {
365378
position: relative;
366379
height: 100%;

packages/workspace/src/layouts/workbench.tsx

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -41,7 +41,7 @@ export class Workbench extends Component<{
4141
<LeftFloatPane area={skeleton.leftFloatArea} />
4242
<LeftFixedPane area={skeleton.leftFixedArea} />
4343
<div className="lc-workspace-workbench-center">
44-
<>
44+
<div className="lc-workspace-workbench-center-content">
4545
<SubTopArea area={skeleton.subTopArea} itemClassName={topAreaItemClassName} />
4646
<div className="lc-workspace-workbench-window">
4747
{
@@ -54,7 +54,7 @@ export class Workbench extends Component<{
5454
))
5555
}
5656
</div>
57-
</>
57+
</div>
5858
<MainArea area={skeleton.mainArea} />
5959
<BottomArea area={skeleton.bottomArea} />
6060
</div>

packages/workspace/src/workspace.ts

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -101,7 +101,7 @@ export class Workspace implements IPublicApiWorkspace {
101101

102102
private remove(index: number) {
103103
const window = this.windows[index];
104-
this.windows = this.windows.splice(index - 1, 1);
104+
this.windows.splice(index, 1);
105105
if (this.window === window) {
106106
this.window = this.windows[index] || this.windows[index + 1] || this.windows[index - 1];
107107
this.emitChangeActiveWindow();

0 commit comments

Comments
 (0)