Skip to content

Commit 6482609

Browse files
liujupingJackLian
authored andcommitted
feat: add resource layer layout in workspace mode
1 parent 67a5e72 commit 6482609

12 files changed

Lines changed: 127 additions & 79 deletions

File tree

packages/types/src/shell/type/resource-list.ts

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,7 @@
11
export interface IPublicResourceData {
22
resourceName: string;
33
title: string;
4-
category: string;
4+
category?: string;
55
options: {
66
[key: string]: any;
77
};

packages/workspace/src/base-context.ts renamed to packages/workspace/src/context/base-context.ts

Lines changed: 2 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,3 @@
1-
/* eslint-disable no-param-reassign */
2-
/* eslint-disable max-len */
31
import {
42
Editor,
53
engineConfig, Setters as InnerSetters,
@@ -33,8 +31,8 @@ import {
3331
IPublicTypePluginMeta,
3432
} from '@alilc/lowcode-types';
3533
import { getLogger } from '@alilc/lowcode-utils';
36-
import { Workspace as InnerWorkspace } from './workspace';
37-
import { EditorWindow } from './editor-window/context';
34+
import { Workspace as InnerWorkspace } from '../workspace';
35+
import { EditorWindow } from '../window';
3836

3937
export class BasicContext {
4038
skeleton: Skeleton;

packages/workspace/src/editor-view/context.ts renamed to packages/workspace/src/context/view-context.ts

Lines changed: 6 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -2,8 +2,8 @@ import { makeObservable, obx } from '@alilc/lowcode-editor-core';
22
import { IPublicEditorViewConfig, IPublicTypeEditorView } from '@alilc/lowcode-types';
33
import { flow } from 'mobx';
44
import { Workspace as InnerWorkspace } from '../workspace';
5-
import { BasicContext } from '../base-context';
6-
import { EditorWindow } from '../editor-window/context';
5+
import { BasicContext } from './base-context';
6+
import { EditorWindow } from '../window';
77
import { getWebviewPlugin } from '../inner-plugins/webview';
88

99
export class Context extends BasicContext {
@@ -17,6 +17,10 @@ export class Context extends BasicContext {
1717

1818
@obx isInit: boolean = false;
1919

20+
get active() {
21+
return this._activate;
22+
}
23+
2024
init = flow(function* (this: any) {
2125
if (this.viewType === 'webview') {
2226
const url = yield this.instance?.url?.();
@@ -44,10 +48,6 @@ export class Context extends BasicContext {
4448
this.innerHotkey.activate(this._activate);
4549
};
4650

47-
get active() {
48-
return this._activate;
49-
}
50-
5151
async save() {
5252
return await this.instance?.save?.();
5353
}

packages/workspace/src/index.ts

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,4 @@
11
export { Workspace } from './workspace';
2-
export * from './editor-window/context';
2+
export * from './window';
33
export * from './layouts/workbench';
44
export { Resource } from './resource';

packages/workspace/src/layouts/workbench.tsx

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,6 @@
11
import { Component } from 'react';
22
import { TipContainer, observer } from '@alilc/lowcode-editor-core';
3-
import { EditorWindowView } from '../editor-window/view';
3+
import { WindowView } from '../view/window-view';
44
import classNames from 'classnames';
55
import TopArea from './top-area';
66
import LeftArea from './left-area';
@@ -46,9 +46,9 @@ export class Workbench extends Component<{
4646
<div className="lc-workspace-workbench-window">
4747
{
4848
workspace.windows.map(d => (
49-
<EditorWindowView
49+
<WindowView
5050
active={d.id === workspace.window.id}
51-
editorWindow={d}
51+
window={d}
5252
key={d.id}
5353
/>
5454
))

packages/workspace/src/resource.ts

Lines changed: 20 additions & 15 deletions
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,6 @@
11
import { IPublicTypeEditorView, IPublicModelResource, IPublicResourceData, IPublicResourceTypeConfig } from '@alilc/lowcode-types';
22
import { Logger } from '@alilc/lowcode-utils';
3-
import { BasicContext } from './base-context';
3+
import { BasicContext } from './context/base-context';
44
import { ResourceType } from './resource-type';
55
import { Workspace as InnerWorkSpace } from './workspace';
66

@@ -13,20 +13,6 @@ export class Resource implements IPublicModelResource {
1313

1414
editorViewMap: Map<string, IPublicTypeEditorView> = new Map<string, IPublicTypeEditorView>();
1515

16-
constructor(readonly resourceData: IPublicResourceData, readonly resourceType: ResourceType, workspace: InnerWorkSpace) {
17-
this.context = new BasicContext(workspace, '');
18-
this.resourceTypeInstance = resourceType.resourceTypeModel(this.context, {});
19-
this.init();
20-
if (this.resourceTypeInstance.editorViews) {
21-
this.resourceTypeInstance.editorViews.forEach((d: any) => {
22-
this.editorViewMap.set(d.viewName, d);
23-
});
24-
}
25-
if (!resourceType) {
26-
logger.error(`resourceType[${resourceType}] is unValid.`);
27-
}
28-
}
29-
3016
get name() {
3117
return this.resourceType.name;
3218
}
@@ -55,6 +41,24 @@ export class Resource implements IPublicModelResource {
5541
return this.resourceData?.category;
5642
}
5743

44+
get skeleton() {
45+
return this.context.innerSkeleton;
46+
}
47+
48+
constructor(readonly resourceData: IPublicResourceData, readonly resourceType: ResourceType, workspace: InnerWorkSpace) {
49+
this.context = new BasicContext(workspace, `resource-${resourceData.resourceName || resourceType.name}`);
50+
this.resourceTypeInstance = resourceType.resourceTypeModel(this.context, {});
51+
this.init();
52+
if (this.resourceTypeInstance.editorViews) {
53+
this.resourceTypeInstance.editorViews.forEach((d: any) => {
54+
this.editorViewMap.set(d.viewName, d);
55+
});
56+
}
57+
if (!resourceType) {
58+
logger.error(`resourceType[${resourceType}] is unValid.`);
59+
}
60+
}
61+
5862
async init() {
5963
await this.resourceTypeInstance.init?.();
6064
await this.context.innerPlugins.init();
@@ -63,6 +67,7 @@ export class Resource implements IPublicModelResource {
6367
async import(schema: any) {
6468
return await this.resourceTypeInstance.import?.(schema);
6569
}
70+
6671
async save(value: any) {
6772
return await this.resourceTypeInstance.save?.(value);
6873
}

packages/workspace/src/editor-view/view.tsx renamed to packages/workspace/src/view/editor-view.tsx

Lines changed: 7 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -4,9 +4,9 @@ import {
44
Workbench,
55
} from '@alilc/lowcode-editor-skeleton';
66
import { PureComponent } from 'react';
7-
import { Context } from './context';
7+
import { Context } from '../context/view-context';
88

9-
export * from '../base-context';
9+
export * from '../context/base-context';
1010

1111
@observer
1212
export class EditorView extends PureComponent<{
@@ -23,13 +23,11 @@ export class EditorView extends PureComponent<{
2323
}
2424

2525
return (
26-
<>
27-
<Workbench
28-
skeleton={skeleton}
29-
className={active ? 'active engine-editor-view' : 'engine-editor-view'}
30-
topAreaItemClassName="engine-actionitem"
31-
/>
32-
</>
26+
<Workbench
27+
skeleton={skeleton}
28+
className={active ? 'active engine-editor-view' : 'engine-editor-view'}
29+
topAreaItemClassName="engine-actionitem"
30+
/>
3331
);
3432
}
3533
}
Lines changed: 14 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,14 @@
1+
.workspace-resource-view {
2+
display: flex;
3+
position: absolute;
4+
flex-direction: column;
5+
top: 0;
6+
bottom: 0;
7+
left: 0;
8+
right: 0;
9+
}
10+
11+
.workspace-editor-body {
12+
position: relative;
13+
height: 100%;
14+
}
Lines changed: 36 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,36 @@
1+
import { PureComponent } from 'react';
2+
import { EditorView } from './editor-view';
3+
import { observer } from '@alilc/lowcode-editor-core';
4+
import TopArea from '../layouts/top-area';
5+
import { Resource } from '../resource';
6+
import { EditorWindow } from '../window';
7+
import './resource-view.less';
8+
9+
@observer
10+
export class ResourceView extends PureComponent<{
11+
window: EditorWindow;
12+
resource: Resource;
13+
}, any> {
14+
render() {
15+
const { skeleton } = this.props.resource;
16+
const { editorViews } = this.props.window;
17+
return (
18+
<div className="workspace-resource-view">
19+
<TopArea area={skeleton.topArea} itemClassName="engine-actionitem" />
20+
<div className="workspace-editor-body">
21+
{
22+
Array.from(editorViews.values()).map((editorView: any) => {
23+
return (
24+
<EditorView
25+
key={editorView.name}
26+
active={editorView.active}
27+
editorView={editorView}
28+
/>
29+
);
30+
})
31+
}
32+
</div>
33+
</div>
34+
);
35+
}
36+
}

packages/workspace/src/editor-window/view.tsx renamed to packages/workspace/src/view/window-view.tsx

Lines changed: 9 additions & 16 deletions
Original file line numberDiff line numberDiff line change
@@ -1,17 +1,17 @@
11
import { PureComponent } from 'react';
2-
import { EditorView } from '../editor-view/view';
2+
import { ResourceView } from './resource-view';
33
import { engineConfig, observer } from '@alilc/lowcode-editor-core';
4-
import { EditorWindow } from './context';
4+
import { EditorWindow } from '../window';
55
import { BuiltinLoading } from '@alilc/lowcode-designer';
66

77
@observer
8-
export class EditorWindowView extends PureComponent<{
9-
editorWindow: EditorWindow;
8+
export class WindowView extends PureComponent<{
9+
window: EditorWindow;
1010
active: boolean;
1111
}, any> {
1212
render() {
1313
const { active } = this.props;
14-
const { editorView, editorViews } = this.props.editorWindow;
14+
const { editorView, resource } = this.props.window;
1515
if (!editorView) {
1616
const Loading = engineConfig.get('loadingComponent', BuiltinLoading);
1717
return (
@@ -23,17 +23,10 @@ export class EditorWindowView extends PureComponent<{
2323

2424
return (
2525
<div className={`workspace-engine-main ${active ? 'active' : ''}`}>
26-
{
27-
Array.from(editorViews.values()).map((editorView: any) => {
28-
return (
29-
<EditorView
30-
key={editorView.name}
31-
active={editorView.active}
32-
editorView={editorView}
33-
/>
34-
);
35-
})
36-
}
26+
<ResourceView
27+
resource={resource}
28+
window={this.props.window}
29+
/>
3730
</div>
3831
);
3932
}

0 commit comments

Comments
 (0)