mirror of
https://github.com/alibaba/lowcode-engine.git
synced 2026-01-19 22:58:15 +00:00
Merge branch 'code-83' into release/0.9.0
This commit is contained in:
commit
462e0956cf
@ -40,6 +40,7 @@ export interface BuiltinSimulatorProps {
|
|||||||
device?: 'mobile' | 'iphone' | string;
|
device?: 'mobile' | 'iphone' | string;
|
||||||
deviceClassName?: string;
|
deviceClassName?: string;
|
||||||
environment?: Asset;
|
environment?: Asset;
|
||||||
|
extraEnvironment?: Asset;
|
||||||
library?: LibraryItem[];
|
library?: LibraryItem[];
|
||||||
simulatorUrl?: Asset;
|
simulatorUrl?: Asset;
|
||||||
theme?: Asset;
|
theme?: Asset;
|
||||||
@ -187,6 +188,8 @@ export class BuiltinSimulatorHost implements ISimulatorHost<BuiltinSimulatorProp
|
|||||||
// required & use once
|
// required & use once
|
||||||
assetBundle(this.get('environment') || defaultEnvironment, AssetLevel.Environment),
|
assetBundle(this.get('environment') || defaultEnvironment, AssetLevel.Environment),
|
||||||
// required & use once
|
// required & use once
|
||||||
|
assetBundle(this.get('extraEnvironment'), AssetLevel.Environment),
|
||||||
|
// required & use once
|
||||||
assetBundle(libraryAsset, AssetLevel.Library),
|
assetBundle(libraryAsset, AssetLevel.Library),
|
||||||
// required & TODO: think of update
|
// required & TODO: think of update
|
||||||
assetBundle(this.theme, AssetLevel.Theme),
|
assetBundle(this.theme, AssetLevel.Theme),
|
||||||
|
|||||||
@ -152,6 +152,9 @@ function getSourceSensor(dragObject: DragObject): ISimulatorHost | null {
|
|||||||
return dragObject.nodes[0]?.document.simulator || null;
|
return dragObject.nodes[0]?.document.simulator || null;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* make a handler that listen all sensors:document, avoid frame lost
|
||||||
|
*/
|
||||||
function makeEventsHandler(
|
function makeEventsHandler(
|
||||||
boostEvent: MouseEvent | DragEvent,
|
boostEvent: MouseEvent | DragEvent,
|
||||||
sensors: ISimulatorHost[],
|
sensors: ISimulatorHost[],
|
||||||
@ -178,6 +181,9 @@ function isDragEvent(e: any): e is DragEvent {
|
|||||||
return e?.type?.substr(0, 4) === 'drag';
|
return e?.type?.substr(0, 4) === 'drag';
|
||||||
}
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Drag-on 拖拽引擎
|
||||||
|
*/
|
||||||
export class Dragon {
|
export class Dragon {
|
||||||
private sensors: ISensor[] = [];
|
private sensors: ISensor[] = [];
|
||||||
|
|
||||||
@ -195,12 +201,15 @@ export class Dragon {
|
|||||||
}
|
}
|
||||||
|
|
||||||
private emitter = new EventEmitter();
|
private emitter = new EventEmitter();
|
||||||
// private emptyImage: HTMLImageElement = new Image();
|
|
||||||
|
|
||||||
constructor(readonly designer: Designer) {
|
constructor(readonly designer: Designer) {
|
||||||
// this.emptyImage.src = 'data:image/gif;base64,R0lGODlhAQABAAAAACH5BAEKAAEALAAAAAABAAEAAAICTAEAOw==';
|
|
||||||
}
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Quick listen a shell(container element) drag behavior
|
||||||
|
* @param shell container element
|
||||||
|
* @param boost boost got a drag object
|
||||||
|
*/
|
||||||
from(shell: Element, boost: (e: MouseEvent) => DragObject | null) {
|
from(shell: Element, boost: (e: MouseEvent) => DragObject | null) {
|
||||||
const mousedown = (e: MouseEvent) => {
|
const mousedown = (e: MouseEvent) => {
|
||||||
// ESC or RightClick
|
// ESC or RightClick
|
||||||
@ -222,6 +231,12 @@ export class Dragon {
|
|||||||
};
|
};
|
||||||
}
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* boost your dragObject for dragging(flying) 发射拖拽对象
|
||||||
|
*
|
||||||
|
* @param dragObject 拖拽对象
|
||||||
|
* @param boostEvent 拖拽初始时事件
|
||||||
|
*/
|
||||||
boost(dragObject: DragObject, boostEvent: MouseEvent | DragEvent) {
|
boost(dragObject: DragObject, boostEvent: MouseEvent | DragEvent) {
|
||||||
const designer = this.designer;
|
const designer = this.designer;
|
||||||
const masterSensors = this.getMasterSensors();
|
const masterSensors = this.getMasterSensors();
|
||||||
@ -313,16 +328,20 @@ export class Dragon {
|
|||||||
this.emitter.emit('dragstart', locateEvent);
|
this.emitter.emit('dragstart', locateEvent);
|
||||||
};
|
};
|
||||||
|
|
||||||
|
// route: drag-move
|
||||||
const move = (e: MouseEvent | DragEvent) => {
|
const move = (e: MouseEvent | DragEvent) => {
|
||||||
if (isBoostFromDragAPI) {
|
if (isBoostFromDragAPI) {
|
||||||
e.preventDefault();
|
e.preventDefault();
|
||||||
}
|
}
|
||||||
if (this._dragging) {
|
if (this._dragging) {
|
||||||
|
// process dragging
|
||||||
drag(e);
|
drag(e);
|
||||||
return;
|
return;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
// first move check is shaken
|
||||||
if (isShaken(boostEvent, e)) {
|
if (isShaken(boostEvent, e)) {
|
||||||
|
// is shaken dragstart
|
||||||
dragstart();
|
dragstart();
|
||||||
drag(e);
|
drag(e);
|
||||||
}
|
}
|
||||||
@ -335,6 +354,7 @@ export class Dragon {
|
|||||||
didDrop = true;
|
didDrop = true;
|
||||||
};
|
};
|
||||||
|
|
||||||
|
// end-tail drag process
|
||||||
const over = (e?: any) => {
|
const over = (e?: any) => {
|
||||||
if (e && isDragEvent(e)) {
|
if (e && isDragEvent(e)) {
|
||||||
e.preventDefault();
|
e.preventDefault();
|
||||||
@ -381,6 +401,7 @@ export class Dragon {
|
|||||||
}
|
}
|
||||||
};
|
};
|
||||||
|
|
||||||
|
// create drag locate event
|
||||||
const createLocateEvent = (e: MouseEvent | DragEvent): LocateEvent => {
|
const createLocateEvent = (e: MouseEvent | DragEvent): LocateEvent => {
|
||||||
const evt: any = {
|
const evt: any = {
|
||||||
type: 'LocateEvent',
|
type: 'LocateEvent',
|
||||||
@ -391,12 +412,14 @@ export class Dragon {
|
|||||||
|
|
||||||
const sourceDocument = e.view?.document;
|
const sourceDocument = e.view?.document;
|
||||||
|
|
||||||
|
// event from current document
|
||||||
if (!sourceDocument || sourceDocument === document) {
|
if (!sourceDocument || sourceDocument === document) {
|
||||||
evt.globalX = e.clientX;
|
evt.globalX = e.clientX;
|
||||||
evt.globalY = e.clientY;
|
evt.globalY = e.clientY;
|
||||||
} else {
|
} else { // event from simulator sandbox
|
||||||
let srcSim: ISimulatorHost | undefined;
|
let srcSim: ISimulatorHost | undefined;
|
||||||
const lastSim = lastSensor && isSimulatorHost(lastSensor) ? lastSensor : null;
|
const lastSim = lastSensor && isSimulatorHost(lastSensor) ? lastSensor : null;
|
||||||
|
// check source simulator
|
||||||
if (lastSim && lastSim.contentDocument === sourceDocument) {
|
if (lastSim && lastSim.contentDocument === sourceDocument) {
|
||||||
srcSim = lastSim;
|
srcSim = lastSim;
|
||||||
} else {
|
} else {
|
||||||
@ -406,6 +429,7 @@ export class Dragon {
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
if (srcSim) {
|
if (srcSim) {
|
||||||
|
// transform point by simulator
|
||||||
const g = srcSim.viewport.toGlobalPoint(e);
|
const g = srcSim.viewport.toGlobalPoint(e);
|
||||||
evt.globalX = g.clientX;
|
evt.globalX = g.clientX;
|
||||||
evt.globalY = g.clientY;
|
evt.globalY = g.clientY;
|
||||||
@ -454,9 +478,7 @@ export class Dragon {
|
|||||||
const { dataTransfer } = boostEvent;
|
const { dataTransfer } = boostEvent;
|
||||||
|
|
||||||
if (dataTransfer) {
|
if (dataTransfer) {
|
||||||
// dataTransfer.setDragImage(this.emptyImage, 0, 0);
|
|
||||||
dataTransfer.effectAllowed = 'all';
|
dataTransfer.effectAllowed = 'all';
|
||||||
// dataTransfer.dropEffect = newBie || forceCopyState ? 'copy' : 'move';
|
|
||||||
|
|
||||||
try {
|
try {
|
||||||
dataTransfer.setData('application/json', '{}');
|
dataTransfer.setData('application/json', '{}');
|
||||||
|
|||||||
@ -1,6 +1,6 @@
|
|||||||
import lg from '@ali/vu-logger';
|
import lg from '@ali/vu-logger';
|
||||||
import { ComponentClass, ComponentType } from 'react';
|
import { ComponentClass, ComponentType } from 'react';
|
||||||
import Prototype from './prototype';
|
import Prototype, { isPrototype } from './prototype';
|
||||||
import { designer } from '../editor';
|
import { designer } from '../editor';
|
||||||
|
|
||||||
function basename(name: string) {
|
function basename(name: string) {
|
||||||
@ -141,12 +141,12 @@ export default class Bundle {
|
|||||||
|
|
||||||
private recursivelyRegisterPrototypes(list: any[], cp: ComponentProtoBundle) {
|
private recursivelyRegisterPrototypes(list: any[], cp: ComponentProtoBundle) {
|
||||||
const propList: ComponentProtoBundle[] = list;
|
const propList: ComponentProtoBundle[] = list;
|
||||||
propList.forEach((proto: ComponentProtoBundle, index: number) => {
|
propList.forEach((proto: any, index: number) => {
|
||||||
if (Array.isArray(proto)) {
|
if (Array.isArray(proto)) {
|
||||||
this.recursivelyRegisterPrototypes(proto, cp);
|
this.recursivelyRegisterPrototypes(proto, cp);
|
||||||
return;
|
return;
|
||||||
}
|
}
|
||||||
if (proto instanceof Prototype) {
|
if (isPrototype(proto)) {
|
||||||
const componentName = proto.getComponentName()!;
|
const componentName = proto.getComponentName()!;
|
||||||
if (!proto.getView() && this.viewsMap[componentName]) {
|
if (!proto.getView() && this.viewsMap[componentName]) {
|
||||||
proto.setView(this.viewsMap[componentName]);
|
proto.setView(this.viewsMap[componentName]);
|
||||||
|
|||||||
@ -217,7 +217,7 @@ class Prototype {
|
|||||||
}
|
}
|
||||||
|
|
||||||
readonly isPrototype = true;
|
readonly isPrototype = true;
|
||||||
private meta: ComponentMeta;
|
readonly meta: ComponentMeta;
|
||||||
readonly options: OldPrototypeConfig | ComponentMetadata;
|
readonly options: OldPrototypeConfig | ComponentMetadata;
|
||||||
|
|
||||||
constructor(input: OldPrototypeConfig | ComponentMetadata | ComponentMeta) {
|
constructor(input: OldPrototypeConfig | ComponentMetadata | ComponentMeta) {
|
||||||
|
|||||||
@ -35,7 +35,7 @@ export class Trunk {
|
|||||||
bundle = this.trunk[i];
|
bundle = this.trunk[i];
|
||||||
prototype = bundle.get(name);
|
prototype = bundle.get(name);
|
||||||
if (prototype) {
|
if (prototype) {
|
||||||
return prototype;
|
return (prototype.meta as any).prototype;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
return this.metaBundle.getFromMeta(name);
|
return this.metaBundle.getFromMeta(name);
|
||||||
|
|||||||
@ -125,7 +125,7 @@ function compatiableReducer(props: any) {
|
|||||||
});
|
});
|
||||||
return newProps;
|
return newProps;
|
||||||
}
|
}
|
||||||
// Dirty fix: will remove this reducer
|
// FIXME: Dirty fix, will remove this reducer
|
||||||
designer.addPropsReducer(compatiableReducer, TransformStage.Save);
|
designer.addPropsReducer(compatiableReducer, TransformStage.Save);
|
||||||
|
|
||||||
// 设计器组件样式处理
|
// 设计器组件样式处理
|
||||||
|
|||||||
@ -10,6 +10,7 @@ export interface PluginProps {
|
|||||||
interface DesignerPluginState {
|
interface DesignerPluginState {
|
||||||
componentMetadatas?: any[] | null;
|
componentMetadatas?: any[] | null;
|
||||||
library?: any[] | null;
|
library?: any[] | null;
|
||||||
|
extraEnvironment?: any[] | null;
|
||||||
}
|
}
|
||||||
|
|
||||||
export default class DesignerPlugin extends PureComponent<PluginProps, DesignerPluginState> {
|
export default class DesignerPlugin extends PureComponent<PluginProps, DesignerPluginState> {
|
||||||
@ -18,6 +19,7 @@ export default class DesignerPlugin extends PureComponent<PluginProps, DesignerP
|
|||||||
state: DesignerPluginState = {
|
state: DesignerPluginState = {
|
||||||
componentMetadatas: null,
|
componentMetadatas: null,
|
||||||
library: null,
|
library: null,
|
||||||
|
extraEnvironment: null,
|
||||||
};
|
};
|
||||||
|
|
||||||
private _mounted = true;
|
private _mounted = true;
|
||||||
@ -33,10 +35,11 @@ export default class DesignerPlugin extends PureComponent<PluginProps, DesignerP
|
|||||||
if (!this._mounted) {
|
if (!this._mounted) {
|
||||||
return;
|
return;
|
||||||
}
|
}
|
||||||
const { components, packages } = assets;
|
const { components, packages, extraEnvironment } = assets;
|
||||||
const state = {
|
const state = {
|
||||||
componentMetadatas: components || [],
|
componentMetadatas: components || [],
|
||||||
library: packages || [],
|
library: packages || [],
|
||||||
|
extraEnvironment,
|
||||||
};
|
};
|
||||||
this.setState(state);
|
this.setState(state);
|
||||||
};
|
};
|
||||||
@ -56,7 +59,7 @@ export default class DesignerPlugin extends PureComponent<PluginProps, DesignerP
|
|||||||
|
|
||||||
render(): React.ReactNode {
|
render(): React.ReactNode {
|
||||||
const { editor } = this.props;
|
const { editor } = this.props;
|
||||||
const { componentMetadatas, library } = this.state;
|
const { componentMetadatas, library, extraEnvironment } = this.state;
|
||||||
|
|
||||||
if (!library || !componentMetadatas) {
|
if (!library || !componentMetadatas) {
|
||||||
// TODO: use a Loading
|
// TODO: use a Loading
|
||||||
@ -72,6 +75,7 @@ export default class DesignerPlugin extends PureComponent<PluginProps, DesignerP
|
|||||||
componentMetadatas={componentMetadatas}
|
componentMetadatas={componentMetadatas}
|
||||||
simulatorProps={{
|
simulatorProps={{
|
||||||
library,
|
library,
|
||||||
|
extraEnvironment,
|
||||||
}}
|
}}
|
||||||
/>
|
/>
|
||||||
);
|
);
|
||||||
|
|||||||
Loading…
x
Reference in New Issue
Block a user