joint legao

This commit is contained in:
kangwei 2020-05-05 15:37:49 +08:00
parent 83d8ae4b81
commit 8119c4c1bc
7 changed files with 40 additions and 46 deletions

View File

@ -39,27 +39,25 @@ export class BorderHoveringInstance extends PureComponent<{
}
@observer
export class BorderHovering extends Component {
static contextType = SimulatorContext;
export class BorderHovering extends Component<{ host: BuiltinSimulatorHost }> {
shouldComponentUpdate() {
return false;
}
@computed get scale() {
return (this.context as BuiltinSimulatorHost).viewport.scale;
return this.props.host.viewport.scale;
}
@computed get scrollX() {
return (this.context as BuiltinSimulatorHost).viewport.scrollX;
return this.props.host.viewport.scrollX;
}
@computed get scrollY() {
return (this.context as BuiltinSimulatorHost).viewport.scrollY;
return this.props.host.viewport.scrollY;
}
@computed get current() {
const host = this.context as BuiltinSimulatorHost;
const host = this.props.host;
const doc = host.document;
const selection = doc.selection;
const current = host.designer.hovering.current;
@ -70,7 +68,7 @@ export class BorderHovering extends Component {
}
render() {
const host = this.context as BuiltinSimulatorHost;
const host = this.props.host;
const current = this.current;
if (!current || host.viewport.scrolling) {
return <Fragment />;

View File

@ -132,11 +132,9 @@ function createAction(content: ReactNode | ComponentType<any> | ActionContentObj
}
@observer
export class BorderSelectingForNode extends Component<{ node: Node }> {
static contextType = SimulatorContext;
export class BorderSelectingForNode extends Component<{ host: BuiltinSimulatorHost; node: Node }> {
get host(): BuiltinSimulatorHost {
return this.context;
return this.props.host;
}
get dragging(): boolean {
@ -177,11 +175,9 @@ export class BorderSelectingForNode extends Component<{ node: Node }> {
}
@observer
export class BorderSelecting extends Component {
static contextType = SimulatorContext;
export class BorderSelecting extends Component<{ host: BuiltinSimulatorHost }> {
get host(): BuiltinSimulatorHost {
return this.context;
return this.props.host;
}
get dragging(): boolean {
@ -211,7 +207,7 @@ export class BorderSelecting extends Component {
return (
<Fragment>
{selecting.map((node) => (
<BorderSelectingForNode key={node.id} node={node} />
<BorderSelectingForNode key={node.id} host={this.props.host} node={node} />
))}
</Fragment>
);

View File

@ -1,7 +1,6 @@
import { Component } from 'react';
import { observer } from '@ali/lowcode-editor-core';
import { BorderHovering } from './border-hovering';
import { SimulatorContext } from '../context';
import { BuiltinSimulatorHost } from '../host';
import { BorderSelecting } from './border-selecting';
import { InsertionView } from './insertion';
@ -9,21 +8,19 @@ import './bem-tools.less';
import './borders.less';
@observer
export class BemTools extends Component {
static contextType = SimulatorContext;
export class BemTools extends Component<{ host: BuiltinSimulatorHost }> {
shouldComponentUpdate() {
return false;
}
render() {
const host = this.context as BuiltinSimulatorHost;
const host = this.props.host;
const { scrollX, scrollY, scale } = host.viewport;
return (
<div className="lc-bem-tools" style={{ transform: `translate(${-scrollX * scale}px,${-scrollY * scale}px)` }}>
<BorderHovering key="hovering" />
<BorderSelecting key="selecting" />
<InsertionView key="insertion" />
<BorderHovering key="hovering" host={host} />
<BorderSelecting key="selecting" host={host} />
<InsertionView key="insertion" host={host} />
</div>
);
}

View File

@ -112,24 +112,19 @@ function processDetail({ target, detail, document }: DropLocation): InsertionDat
}
@observer
export class InsertionView extends Component {
static contextType = SimulatorContext;
@computed get host(): BuiltinSimulatorHost {
return this.context;
}
export class InsertionView extends Component<{ host: BuiltinSimulatorHost }> {
shouldComponentUpdate() {
return false;
}
render() {
const loc = this.host.document.dropLocation;
const { host } = this.props;
const loc = host.document.dropLocation;
if (!loc) {
return null;
}
const { scale, scrollX, scrollY } = this.host.viewport;
const { scale, scrollX, scrollY } = host.viewport;
const { edge, insertType, coverRect, nearRect, vertical } = processDetail(loc);
if (!edge) {

View File

@ -41,20 +41,17 @@ export class BuiltinSimulatorHostView extends Component<SimulatorHostProps> {
const { Provider } = SimulatorContext;
return (
<div className="lc-simulator">
<Provider value={this.host}>
{/*progressing.visible ? <PreLoaderView /> : null*/}
<Canvas />
</Provider>
{/*progressing.visible ? <PreLoaderView /> : null*/}
<Canvas host={this.host} />
</div>
);
}
}
@observer
class Canvas extends Component {
static contextType = SimulatorContext;
class Canvas extends Component<{ host: BuiltinSimulatorHost }> {
render() {
const sim = this.context as BuiltinSimulatorHost;
const sim = this.props.host;
let className = 'lc-simulator-canvas';
if (sim.deviceClassName) {
className += ` ${sim.deviceClassName}`;
@ -65,8 +62,8 @@ class Canvas extends Component {
return (
<div className={className}>
<div ref={elmt => sim.mountViewport(elmt)} className="lc-simulator-canvas-viewport">
<BemTools />
<Content />
<BemTools host={sim} />
<Content host={sim} />
</div>
</div>
);
@ -74,10 +71,9 @@ class Canvas extends Component {
}
@observer
class Content extends Component {
static contextType = SimulatorContext;
class Content extends Component<{ host: BuiltinSimulatorHost }> {
render() {
const sim = this.context as BuiltinSimulatorHost;
const sim = this.props.host;
const viewport = sim.viewport;
let frameStyle = {};
if (viewport.scale < 1) {

View File

@ -309,4 +309,11 @@ export class Props implements IPropParent {
getPropValue(path: string): any {
return this.getProp(path, false)?.value;
}
/**
*
*/
setPropValue(path: string, value: any) {
this.getProp(path, true)!.setValue(value);
}
}

View File

@ -12,6 +12,11 @@ export interface OldPageData {
const pages = Object.assign(project, {
setPages(pages: OldPageData[]) {
// FIXME: upgrade schema
pages[0].componentsTree.forEach((item: any) => {
item.lifeCycles = {};
item.methods = {};
});
project.load({
version: '1.0.0',
componentsMap: [],