mirror of
https://github.com/alibaba/lowcode-engine.git
synced 2026-03-07 02:47:12 +00:00
fix: getSuitablePlace
This commit is contained in:
parent
f9d4ff61af
commit
db2b6d5218
@ -1,9 +1,7 @@
|
||||
{
|
||||
"entry": {
|
||||
"index": "src/index",
|
||||
"editor-preset-vision": "../editor-preset-vision/src/index.ts",
|
||||
"react-simulator-renderer": "../react-simulator-renderer/src/index.ts",
|
||||
"rax-simulator-renderer": "../rax-simulator-renderer/src/index.ts"
|
||||
"react-simulator-renderer": "../react-simulator-renderer/src/index.ts"
|
||||
},
|
||||
"vendor": false,
|
||||
"devServer": {
|
||||
|
||||
@ -108,7 +108,7 @@ export class Node<Schema extends NodeSchema = NodeSchema> {
|
||||
/**
|
||||
* @deprecated
|
||||
*/
|
||||
private _addons: { [key: string]: { exportData: () => any; isProp: boolean; } } = {};
|
||||
private _addons: { [key: string]: { exportData: () => any; isProp: boolean } } = {};
|
||||
|
||||
@obx.ref private _parent: ParentalNode | null = null;
|
||||
|
||||
@ -173,7 +173,10 @@ export class Node<Schema extends NodeSchema = NodeSchema> {
|
||||
this.settingEntry = this.document.designer.createSettingEntry([this]);
|
||||
this._children = new NodeChildren(this as ParentalNode, this.initialChildren(children));
|
||||
this._children.internalInitParent();
|
||||
this.props.import(this.upgradeProps(this.initProps(props || {})), this.upgradeProps(extras || {}));
|
||||
this.props.import(
|
||||
this.upgradeProps(this.initProps(props || {})),
|
||||
this.upgradeProps(extras || {}),
|
||||
);
|
||||
this.setupAutoruns();
|
||||
}
|
||||
|
||||
@ -596,15 +599,21 @@ export class Node<Schema extends NodeSchema = NodeSchema> {
|
||||
import(data: Schema, checkId = false) {
|
||||
const { componentName, id, children, props, ...extras } = data;
|
||||
if (this.isSlot()) {
|
||||
foreachReverse(this.children, (subNode: Node) => {
|
||||
subNode.remove(true, true);
|
||||
}, (iterable, idx) => (iterable as NodeChildren).get(idx));
|
||||
foreachReverse(
|
||||
this.children,
|
||||
(subNode: Node) => {
|
||||
subNode.remove(true, true);
|
||||
},
|
||||
(iterable, idx) => (iterable as NodeChildren).get(idx),
|
||||
);
|
||||
}
|
||||
if (this.isParental()) {
|
||||
this.props.import(props, extras);
|
||||
(this._children as NodeChildren).import(children, checkId);
|
||||
} else {
|
||||
this.props.get('children', true)!.setValue(isDOMText(children) || isJSExpression(children) ? children : '');
|
||||
this.props
|
||||
.get('children', true)!
|
||||
.setValue(isDOMText(children) || isJSExpression(children) ? children : '');
|
||||
}
|
||||
}
|
||||
|
||||
@ -768,7 +777,8 @@ export class Node<Schema extends NodeSchema = NodeSchema> {
|
||||
* 是否可执行某action
|
||||
*/
|
||||
canPerformAction(action: string): boolean {
|
||||
const availableActions = this.componentMeta?.availableActions?.map((action) => action.name) || [];
|
||||
const availableActions =
|
||||
this.componentMeta?.availableActions?.map((action) => action.name) || [];
|
||||
return availableActions.indexOf(action) >= 0;
|
||||
}
|
||||
|
||||
@ -837,7 +847,11 @@ export class Node<Schema extends NodeSchema = NodeSchema> {
|
||||
return this.children?.onChange(fn);
|
||||
}
|
||||
|
||||
mergeChildren(remover: () => any, adder: (children: Node[]) => NodeData[] | null, sorter: () => any) {
|
||||
mergeChildren(
|
||||
remover: () => any,
|
||||
adder: (children: Node[]) => NodeData[] | null,
|
||||
sorter: () => any,
|
||||
) {
|
||||
this.children?.mergeChildren(remover, adder, sorter);
|
||||
}
|
||||
|
||||
@ -894,37 +908,60 @@ export class Node<Schema extends NodeSchema = NodeSchema> {
|
||||
* @deprecated
|
||||
*/
|
||||
getSuitablePlace(node: Node, ref: any): any {
|
||||
const focusNode = this.document.focusNode;
|
||||
if (!ref && this.contains(focusNode)) {
|
||||
const rootCanDropIn = focusNode.componentMeta?.prototype?.options?.canDropIn;
|
||||
if (
|
||||
rootCanDropIn === undefined ||
|
||||
rootCanDropIn === true ||
|
||||
(typeof rootCanDropIn === 'function' && rootCanDropIn(node))
|
||||
) {
|
||||
return { container: focusNode };
|
||||
}
|
||||
|
||||
return null;
|
||||
}
|
||||
|
||||
// todo: remove these dirty code (for legao tranditional scene)
|
||||
if (this.isRoot() && this.children) {
|
||||
const dropElement = this.children.filter((c: Node) => {
|
||||
const rootCanDropIn = this.componentMeta?.prototype?.options?.canDropIn;
|
||||
if (
|
||||
rootCanDropIn === undefined ||
|
||||
rootCanDropIn === true ||
|
||||
(typeof rootCanDropIn === 'function' && rootCanDropIn(node))
|
||||
) {
|
||||
return { container: this, ref };
|
||||
}
|
||||
|
||||
const dropElement = this.children.filter((c) => {
|
||||
if (!c.isContainer()) {
|
||||
return false;
|
||||
}
|
||||
const canDropIn = c.componentMeta?.prototype?.options?.canDropIn;
|
||||
if (typeof canDropIn === 'function') {
|
||||
return canDropIn(node);
|
||||
} else if (typeof canDropIn === 'boolean') {
|
||||
return canDropIn;
|
||||
if (
|
||||
canDropIn === undefined ||
|
||||
canDropIn === true ||
|
||||
(typeof canDropIn === 'function' && canDropIn(node))
|
||||
) {
|
||||
return true;
|
||||
}
|
||||
return true;
|
||||
return false;
|
||||
})[0];
|
||||
|
||||
if (dropElement) {
|
||||
return { container: dropElement, ref };
|
||||
return { container: dropElement };
|
||||
}
|
||||
const rootCanDropIn = this.componentMeta?.prototype?.options?.canDropIn;
|
||||
if (rootCanDropIn === undefined
|
||||
|| rootCanDropIn === true
|
||||
|| (typeof rootCanDropIn === 'function' && rootCanDropIn(node))) {
|
||||
return { container: this, ref };
|
||||
}
|
||||
// 假如最后找不到合适位置,返回 undefined 阻止继续插入节点
|
||||
return undefined;
|
||||
|
||||
return null;
|
||||
}
|
||||
|
||||
const canDropIn = this.componentMeta?.prototype?.options?.canDropIn;
|
||||
if (this.isContainer()) {
|
||||
if (canDropIn === undefined ||
|
||||
(typeof canDropIn === 'boolean' && canDropIn) ||
|
||||
(typeof canDropIn === 'function' && canDropIn(node))) {
|
||||
if (
|
||||
canDropIn === undefined ||
|
||||
canDropIn === true ||
|
||||
(typeof canDropIn === 'function' && canDropIn(node))
|
||||
) {
|
||||
return { container: this, ref };
|
||||
}
|
||||
}
|
||||
@ -1077,7 +1114,12 @@ export function comparePosition(node1: Node, node2: Node): PositionNO {
|
||||
return PositionNO.BeforeOrAfter;
|
||||
}
|
||||
|
||||
export function insertChild(container: ParentalNode, thing: Node | NodeData, at?: number | null, copy?: boolean): Node {
|
||||
export function insertChild(
|
||||
container: ParentalNode,
|
||||
thing: Node | NodeData,
|
||||
at?: number | null,
|
||||
copy?: boolean,
|
||||
): Node {
|
||||
let node: Node;
|
||||
if (isNode(thing) && (copy || thing.isSlot())) {
|
||||
thing = thing.export(TransformStage.Clone);
|
||||
|
||||
@ -1,6 +1,5 @@
|
||||
#!/usr/bin/env bash
|
||||
|
||||
# FIXME! do not run build
|
||||
lerna exec --scope @ali/lowcode-rax-renderer -- npm run build
|
||||
lerna exec --scope @ali/lowcode-react-renderer -- npm run build
|
||||
lerna exec --scope @ali/lowcode-demo -- npm start
|
||||
|
||||
Loading…
x
Reference in New Issue
Block a user