This commit is contained in:
kangwei 2020-02-17 06:00:39 +08:00
parent b561024201
commit 30da8146bb
3 changed files with 78 additions and 156 deletions

View File

@ -3,7 +3,7 @@ import { obx } from '@recore/obx';
import Location from './location';
import DocumentModel from './document/document-model';
import { NodeData } from './schema';
import { SimulatorInterface } from './simulator-interface';
import { ISimulator } from './simulator';
import Node from './document/node/node';
import Designer from './designer';
@ -167,7 +167,7 @@ export default class Dragon {
};
}
getMasterSensors(): SimulatorInterface[] {
getMasterSensors(): ISimulator[] {
return this.designer.project.documents.map(doc => (doc.actived && doc.simulator) || null).filter(Boolean);
}
@ -319,7 +319,7 @@ export default class Dragon {
return evt;
};
function getSourceSensor(dragObject: DragObject): SimulatorInterface | null {
function getSourceSensor(dragObject: DragObject): ISimulator | null {
if (!isDragNodeObject(dragObject)) {
return null;
}

View File

@ -1,68 +1,65 @@
import { obx, computed } from '@recore/obx';
import { ProjectSchema } from './schema';
import { ProjectSchema, RootSchema } from './schema';
import { EventEmitter } from 'events';
import Designer from './designer';
import DocumentModel from './document/document-model';
import DocumentModel, { isDocumentModel } from './document/document-model';
export default class Project {
private emitter = new EventEmitter();
@obx.val readonly documents: DocumentModel[] = [];
private data: ProjectSchema = {};
private data: ProjectSchema;
@obx.ref canvasDisplayMode: 'exclusive' | 'overview' = 'exclusive';
// 考虑项目级别 History
// TODO: 考虑项目级别 History
constructor(readonly designer: Designer, schema?: ProjectSchema) {
this.data = {
version: '1.0.0',
componentsMap: [],
componentsTree: [],
...schema
...schema,
};
this.open(this.data.componentsTree[0] || {
componentName: 'Page',
fileName: '',
});
}
@computed get activedDocuments() {
return this.documents.filter(doc => doc.actived);
}
getDocument(fileName: string): DocumentContext {}
addDocument(data: DocumentSchema): DocumentContext {
this.documents.push(new DocumentContext(data));
}
/**
* schema
*/
get schema(): ProjectSchema {
return {
...this.data,
componentsTree: this.documents.map(doc => doc.getSchema()),
componentsTree: this.documents.map(doc => doc.schema),
};
}
/**
* schema
*/
set schema(schema: ProjectSchema) {
}
set schema(schema: ProjectSchema) {}
/**
*
*/
set(
key:
| 'version'
| 'componentsTree'
| 'componentsMap'
| 'utils'
| 'constants'
| 'i18n'
| 'css'
| 'dataSource'
| string,
| 'version'
| 'componentsTree'
| 'componentsMap'
| 'utils'
| 'constants'
| 'i18n'
| 'css'
| 'dataSource'
| string,
value: any,
): void {}
@ -71,26 +68,62 @@ export default class Project {
*/
get(
key:
| 'version'
| 'componentsTree'
| 'componentsMap'
| 'utils'
| 'constants'
| 'i18n'
| 'css'
| 'dataSource'
| string,
): any;
| 'version'
| 'componentsTree'
| 'componentsMap'
| 'utils'
| 'constants'
| 'i18n'
| 'css'
| 'dataSource'
| string,
): any {}
edit(document): void {}
open(doc: string | DocumentModel | RootSchema): void {
if (typeof doc === 'string') {
const got = this.documents.find(item => item.fileName === doc);
if (got) {
return got.open();
}
const data = this.data.componentsTree.find(data => data.fileName === doc);
if (data) {
doc = new DocumentModel(this, data);
this.documents.push(doc);
doc.open();
}
return;
}
if (isDocumentModel(doc)) {
return doc.open();
}
doc = new DocumentModel(this, doc);
this.documents.push(doc);
doc.open();
}
checkExclusive(actived: DocumentModel) {
if (this.canvasDisplayMode !== 'exclusive') {
return;
}
this.documents.forEach((doc) => {
if (doc !== actived) {
doc.suspense();
}
});
}
closeOthers(opened: DocumentModel) {
this.documents.forEach((doc) => {
if (doc !== opened) {
doc.close();
}
});
}
/**
* documents
*/
onDocumentsChange(fn: (documents: DocumentContext[]) => void): () => void {}
/**
*
*/
// 通知标记删除,需要告知服务端
// 项目角度编辑不是全量打开所有文档,是按需加载,哪个更新就通知更新谁,
// 哪个删除就

View File

@ -1,111 +0,0 @@
import { NpmInfo } from './schema';
import { ComponentClass as ReactComponentClass, Component as ReactComponent, ComponentType } from 'react';
import { LocateEvent, ISensor } from './dragon';
import { Point } from './location';
import Node from './document/node/node';
export interface SimulatorInterface<P = object> extends ISensor {
/**
*
*/
readonly bounds: object;
// dependsAsset // like react jQuery lodash
// themesAsset
// componentsAsset
// simulatorUrl //
// utils, dataSource, constants 模拟
//
// later:
// layout: ComponentName
// 获取区块代码, 通过 components 传递,可异步获取
setProps(props: P): void;
/**
*
*/
setDesignMode(mode: "live" | "design" | string): void;
/**
*
*/
setDraggingState(state: boolean): void;
/**
*
*/
isDraggingState(): boolean;
/**
*
*/
setCopyState(state: boolean): void;
/**
*
*/
isCopyState(): boolean;
/**
*
*/
clearState(): void;
/**
*
*/
locate(e: LocateEvent): any;
/**
*
*/
scrollToNode(node: Node, detail?: any): void;
/**
* event canvasX, globalX
*/
fixEvent(e: LocateEvent): LocateEvent;
/**
*
*/
toLocalPoint(point: Point): Point;
/**
*
*/
toGlobalPoint(point: Point): Point;
/**
*
*/
getComponent(componentName: string): Component | any;
/**
*
*/
getComponentInstance(node: Node): ComponentInstance[] | null;
/**
*
*/
getComponentContext(node: Node): object;
/**
*
*/
setSuspense(suspended: boolean): void;
/**
*
*/
purge(): void;
}
/**
*
*/
export type Component = ComponentType<any> | object;
/**
*
*/
export type ComponentInstance = Element | ReactComponent<any> | object;