fix: getSuitablePlace

This commit is contained in:
mario.gk 2020-07-29 20:38:43 +08:00
parent 21fc26045a
commit 03e7c57639
3 changed files with 33 additions and 5 deletions

View File

@ -244,7 +244,7 @@ export class NodeChildren {
return this.children.some((child, index) => fn(child, index));
}
filter(fn: (item: Node, index: number) => item is Node) {
filter(fn: (item: Node, index: number) => any) {
return this.children.filter(fn);
}

View File

@ -793,11 +793,39 @@ export class Node<Schema extends NodeSchema = NodeSchema> {
* @deprecated
*/
getSuitablePlace(node: Node, ref: any): any {
// TODO:
if (this.isRoot()) {
if (this.isRoot() && this.children) {
const dropElement = this.children.filter((c: Node) => {
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;
}
return true;
})[0];
if (dropElement) {
return { container: dropElement, ref };
}
return { container: this, ref };
}
return { container: this.parent, ref: this };
const canDropIn = this.componentMeta?.prototype?.options?.canDropIn;
if (this.isContainer()) {
if (canDropIn === undefined ||
(typeof canDropIn === 'boolean' && canDropIn) ||
(typeof canDropIn === 'function' && canDropIn(node))){
return { container: this, ref };
}
}
if (this.parent) {
return this.parent.getSuitablePlace(node, ref);
}
return null;
}
/**
* @deprecated

View File

@ -51,5 +51,5 @@
"ts-node/register"
]
},
"homepage": "https://unpkg.alibaba-inc.com/@ali/lowcode-rax-simulator-renderer@0.8.35/build/index.html"
"homepage": "https://unpkg.alibaba-inc.com/@ali/lowcode-rax-simulator-renderer@0.8.36/build/index.html"
}