Skip to content

Commit

Permalink
feat(workspace): add config for resource shell model
Browse files Browse the repository at this point in the history
  • Loading branch information
liujuping authored and JackLian committed Apr 26, 2023
1 parent 5b14230 commit c3d75b2
Show file tree
Hide file tree
Showing 8 changed files with 26 additions and 3 deletions.
4 changes: 4 additions & 0 deletions packages/designer/src/plugin/plugin-context.ts
Original file line number Diff line number Diff line change
Expand Up @@ -17,6 +17,8 @@ import {
IPublicTypePluginDeclaration,
IPublicApiCanvas,
IPublicApiWorkspace,
IPublicEnumPluginRegisterLevel,
IPublicModelWindow,
} from '@alilc/lowcode-types';
import {
IPluginContextOptions,
Expand All @@ -41,6 +43,8 @@ export default class PluginContext implements
pluginEvent: IPublicApiEvent;
canvas: IPublicApiCanvas;
workspace: IPublicApiWorkspace;
registerLevel: IPublicEnumPluginRegisterLevel;
editorWindow: IPublicModelWindow;

constructor(
options: IPluginContextOptions,
Expand Down
4 changes: 4 additions & 0 deletions packages/shell/src/model/resource.ts
Original file line number Diff line number Diff line change
Expand Up @@ -25,6 +25,10 @@ export class Resource implements IPublicModelResource {
return this[resourceSymbol].resourceType.name;
}

get config() {
return this[resourceSymbol].config;
}

get type() {
return this[resourceSymbol].resourceType.type;
}
Expand Down
5 changes: 4 additions & 1 deletion packages/shell/src/model/window.ts
Original file line number Diff line number Diff line change
Expand Up @@ -44,7 +44,10 @@ export class Window implements IPublicModelWindow {
}

get currentEditorView() {
return new EditorView(this[windowSymbol].editorView).toProxy() as any;
if (this[windowSymbol].editorView) {
return new EditorView(this[windowSymbol].editorView).toProxy() as any;
}
return null;
}

get editorViews() {
Expand Down
4 changes: 4 additions & 0 deletions packages/types/src/shell/model/resource.ts
Original file line number Diff line number Diff line change
Expand Up @@ -18,6 +18,10 @@ export interface IBaseModelResource<
get children(): Resource[];

get viewName(): string | undefined;

get config(): {
disableBehaviors?: ('copy' | 'remove')[];
} | undefined;
}

export type IPublicModelResource = IBaseModelResource<IPublicModelResource>;
2 changes: 1 addition & 1 deletion packages/types/src/shell/model/window.ts
Original file line number Diff line number Diff line change
Expand Up @@ -23,7 +23,7 @@ export interface IPublicModelWindow<
* 窗口当前视图
* @since v1.1.7
*/
currentEditorView: IPublicModelEditorView;
currentEditorView: IPublicModelEditorView | null;

/**
* 窗口全部视图实例
Expand Down
4 changes: 4 additions & 0 deletions packages/types/src/shell/type/resource-list.ts
Original file line number Diff line number Diff line change
Expand Up @@ -24,6 +24,10 @@ export interface IPublicResourceData {

/** 资源子元素 */
children?: IPublicResourceData[];

config?: {
disableBehaviors?: ('copy' | 'remove')[];
};
}

export type IPublicResourceList = IPublicResourceData[];
2 changes: 1 addition & 1 deletion packages/workspace/src/context/base-context.ts
Original file line number Diff line number Diff line change
Expand Up @@ -101,7 +101,7 @@ export class BasicContext implements IBasicContext {
preference: IPluginPreferenceMananger;
workspace: IWorkspace;

constructor(innerWorkspace: IWorkspace, viewName: string, registerLevel: IPublicEnumPluginRegisterLevel, public editorWindow?: IEditorWindow) {
constructor(innerWorkspace: IWorkspace, viewName: string, readonly registerLevel: IPublicEnumPluginRegisterLevel, public editorWindow?: IEditorWindow) {
const editor = new Editor(viewName, true);

const innerSkeleton = new InnerSkeleton(editor, viewName);
Expand Down
4 changes: 4 additions & 0 deletions packages/workspace/src/resource.ts
Original file line number Diff line number Diff line change
Expand Up @@ -74,6 +74,10 @@ export class Resource implements IResource {
return this.resourceData?.children?.map(d => new Resource(d, this.workspace.getResourceType(d.resourceName || this.resourceType.name), this.workspace)) || [];
}

get config() {
return this.resourceData.config;
}

constructor(readonly resourceData: IPublicResourceData, readonly resourceType: IResourceType, readonly workspace: IWorkspace) {
this.context = new BasicContext(workspace, `resource-${resourceData.resourceName || resourceType.name}`, IPublicEnumPluginRegisterLevel.Resource);
this.resourceTypeInstance = resourceType.resourceTypeModel(this.context.innerPlugins._getLowCodePluginContext({
Expand Down

0 comments on commit c3d75b2

Please sign in to comment.