Merge remote-tracking branch 'origin/develop' into release/1.1.7-beta

This commit is contained in:
JackLian 2023-05-17 19:30:46 +08:00
commit 42795947f8
7 changed files with 54 additions and 27 deletions

View File

@ -7,6 +7,8 @@ import {
import { isNode } from '@alilc/lowcode-utils';
export interface IActiveTracker extends Omit< IPublicModelActiveTracker, 'track' | 'onChange' > {
_target: ActiveTarget | INode;
track(originalTarget: ActiveTarget | INode): void;
onChange(fn: (target: ActiveTarget) => void): () => void;
@ -17,10 +19,10 @@ export interface ActiveTarget extends Omit< IPublicTypeActiveTarget, 'node' > {
}
export class ActiveTracker implements IActiveTracker {
private emitter: IEventBus = createModuleEventBus('ActiveTracker');
@obx.ref private _target?: ActiveTarget | INode;
private emitter: IEventBus = createModuleEventBus('ActiveTracker');
track(originalTarget: ActiveTarget | INode) {
let target = originalTarget;
if (isNode(originalTarget)) {

View File

@ -90,28 +90,29 @@ export class TreeMaster {
private initEvent() {
let startTime: any;
const { event, project, canvas } = this.pluginContext;
const setExpandByActiveTracker = (target: IPublicTypeActiveTarget) => {
const { node, detail } = target;
const tree = this.currentTree;
if (!tree/* || node.document !== tree.document */) {
return;
}
const treeNode = tree.getTreeNode(node);
if (detail && isLocationChildrenDetail(detail)) {
treeNode.expand(true);
} else {
treeNode.expandParents();
}
this.boards.forEach((board) => {
board.scrollToNode(treeNode, detail);
});
};
this.disposeEvents = [
canvas.dragon?.onDragstart(() => {
startTime = Date.now() / 1000;
// needs?
this.toVision();
}),
canvas.activeTracker?.onChange((target: IPublicTypeActiveTarget) => {
const { node, detail } = target;
const tree = this.currentTree;
if (!tree/* || node.document !== tree.document */) {
return;
}
const treeNode = tree.getTreeNode(node);
if (detail && isLocationChildrenDetail(detail)) {
treeNode.expand(true);
} else {
treeNode.expandParents();
}
this.boards.forEach((board) => {
board.scrollToNode(treeNode, detail);
});
}),
canvas.activeTracker?.onChange(setExpandByActiveTracker),
canvas.dragon?.onDragend(() => {
const endTime: any = Date.now() / 1000;
const nodes = project.currentDocument?.selection?.getNodes();
@ -135,6 +136,9 @@ export class TreeMaster {
this.treeMap.delete(id);
}),
];
if (canvas.activeTracker?.target) {
setExpandByActiveTracker(canvas.activeTracker?.target);
}
}
private toVision() {

View File

@ -12,6 +12,16 @@ export class ActiveTracker implements IPublicModelActiveTracker {
this[activeTrackerSymbol] = innerTracker;
}
get target() {
const { node: innerNode, detail, instance } = this[activeTrackerSymbol]._target;
const publicNode = ShellNode.create(innerNode);
return {
node: publicNode!,
detail,
instance,
};
}
onChange(fn: (target: IPublicTypeActiveTarget) => void): () => void {
if (!fn) {
return () => {};

View File

@ -2,6 +2,12 @@ import { IPublicTypeActiveTarget } from '../type';
import { IPublicModelNode } from './node';
export interface IPublicModelActiveTracker {
/**
* @since 1.1.7
*/
target: IPublicTypeActiveTarget;
onChange(fn: (target: IPublicTypeActiveTarget) => void): () => void;
track(node: IPublicModelNode): void;

View File

@ -70,9 +70,7 @@ export class Resource implements IResource {
return this.context.innerSkeleton;
}
get children(): IResource[] {
return this.resourceData?.children?.map(d => new Resource(d, this.workspace.getResourceType(d.resourceName || this.resourceType.name), this.workspace)) || [];
}
children: IResource[];
get config() {
return this.resourceData.config;
@ -92,6 +90,7 @@ export class Resource implements IResource {
if (!resourceType) {
logger.error(`resourceType[${resourceType}] is unValid.`);
}
this.children = this.resourceData?.children?.map(d => new Resource(d, this.workspace.getResourceType(d.resourceName || this.resourceType.name), this.workspace)) || [];
}
async init() {

View File

@ -51,9 +51,6 @@ export class EditorWindow implements IEditorWindow {
this.title = config.title;
this.icon = resource.icon;
this.sleep = config.sleep;
if (!config.sleep) {
this.init();
}
}
async importSchema(schema: any) {
@ -155,6 +152,8 @@ export class EditorWindow implements IEditorWindow {
return;
}
this.editorView.setActivate(true);
if (!ignoreEmit) {
this.emitter.emit('window.change.view.type', name);
@ -162,7 +161,6 @@ export class EditorWindow implements IEditorWindow {
this.workspace.emitChangeActiveEditorView();
}
}
this.editorView.setActivate(true);
};
get project() {

View File

@ -115,7 +115,7 @@ export class Workspace implements IWorkspace {
}
}
initWindow() {
async initWindow() {
if (!this.defaultResourceType || this.enableAutoOpenFirstWindow === false) {
return;
}
@ -127,6 +127,7 @@ export class Workspace implements IWorkspace {
this.window = new EditorWindow(resource, this, {
title: resource.title,
});
await this.window.init();
this.editorWindowMap.set(this.window.id, this.window);
this.windows = [...this.windows, this.window];
this.emitChangeWindow();
@ -196,6 +197,9 @@ export class Workspace implements IWorkspace {
this.windows.splice(index, 1);
if (this.window === window) {
this.window = this.windows[index] || this.windows[index + 1] || this.windows[index - 1];
if (this.window.sleep) {
this.window.init();
}
this.emitChangeActiveWindow();
}
this.emitChangeWindow();
@ -206,10 +210,13 @@ export class Workspace implements IWorkspace {
this.remove(index);
}
openEditorWindowById(id: string) {
async openEditorWindowById(id: string) {
const window = this.editorWindowMap.get(id);
if (window) {
this.window = window;
if (window.sleep) {
await window.init();
}
this.emitChangeActiveWindow();
}
}
@ -252,6 +259,7 @@ export class Workspace implements IWorkspace {
this.editorWindowMap.set(window.id, window);
if (!sleep) {
this.window = window;
await this.window.init();
}
this.emitChangeWindow();
this.emitChangeActiveWindow();