mirror of
https://github.com/alibaba/lowcode-engine.git
synced 2025-12-12 19:52:51 +00:00
fix: fix the problem that the childWhitelist is invalid when dragged to the root container (#1168)
This commit is contained in:
parent
fab83b4ab1
commit
413d17b84b
@ -1473,7 +1473,7 @@ export class BuiltinSimulatorHost implements ISimulatorHost<BuiltinSimulatorProp
|
||||
const document = this.currentDocument!;
|
||||
const focusNode = document.focusNode;
|
||||
if (isRootNode(container) || container.contains(focusNode)) {
|
||||
return document.checkDropTarget(focusNode, dragObject as any);
|
||||
return document.checkNesting(focusNode, dragObject as any);
|
||||
}
|
||||
|
||||
const meta = (container as Node).componentMeta;
|
||||
|
||||
@ -4,7 +4,7 @@ import { EventEmitter } from 'events';
|
||||
import { Project } from '../project';
|
||||
import { ISimulatorHost } from '../simulator';
|
||||
import { ComponentMeta } from '../component-meta';
|
||||
import { isDragNodeDataObject, DragNodeObject, DragNodeDataObject, DropLocation, Designer } from '../designer';
|
||||
import { isDragNodeDataObject, DragNodeObject, DragNodeDataObject, DropLocation, Designer, isDragNodeObject } from '../designer';
|
||||
import { Node, insertChildren, insertChild, isNode, RootNode, ParentalNode } from './node/node';
|
||||
import { Selection } from './selection';
|
||||
import { History } from './history';
|
||||
@ -505,16 +505,26 @@ export class DocumentModel {
|
||||
this.rootNode = null;
|
||||
}
|
||||
|
||||
checkNesting(dropTarget: ParentalNode, dragObject: DragNodeObject | DragNodeDataObject): boolean {
|
||||
checkNesting(dropTarget: ParentalNode, dragObject: DragNodeObject | NodeSchema | Node | DragNodeDataObject): boolean {
|
||||
let items: Array<Node | NodeSchema>;
|
||||
if (isDragNodeDataObject(dragObject)) {
|
||||
items = Array.isArray(dragObject.data) ? dragObject.data : [dragObject.data];
|
||||
} else {
|
||||
} else if (isDragNodeObject(dragObject)) {
|
||||
items = dragObject.nodes;
|
||||
} else if (isNode(dragObject) || isNodeSchema(dragObject)) {
|
||||
items = [dragObject];
|
||||
} else {
|
||||
console.warn('the dragObject is not in the correct type, dragObject:', dragObject);
|
||||
return true;
|
||||
}
|
||||
return items.every((item) => this.checkNestingDown(dropTarget, item));
|
||||
return items.every((item) => this.checkNestingDown(dropTarget, item) && this.checkNestingUp(dropTarget, item));
|
||||
}
|
||||
|
||||
/**
|
||||
* @deprecated since version 1.0.16.
|
||||
* Will be deleted in version 2.0.0.
|
||||
* Use checkNesting method instead.
|
||||
*/
|
||||
checkDropTarget(dropTarget: ParentalNode, dragObject: DragNodeObject | DragNodeDataObject): boolean {
|
||||
let items: Array<Node | NodeSchema>;
|
||||
if (isDragNodeDataObject(dragObject)) {
|
||||
@ -544,7 +554,7 @@ export class DocumentModel {
|
||||
*/
|
||||
checkNestingDown(parent: ParentalNode, obj: NodeSchema | Node): boolean {
|
||||
const config = parent.componentMeta;
|
||||
return config.checkNestingDown(parent, obj) && this.checkNestingUp(parent, obj);
|
||||
return config.checkNestingDown(parent, obj);
|
||||
}
|
||||
|
||||
// ======= compatibles for vision
|
||||
|
||||
@ -219,6 +219,7 @@ describe('document-model 测试', () => {
|
||||
it('checkNesting / checkDropTarget / checkNestingUp / checkNestingDown', () => {
|
||||
designer.createComponentMeta(pageMeta);
|
||||
designer.createComponentMeta(formMeta);
|
||||
designer.createComponentMeta(otherMeta);
|
||||
const doc = new DocumentModel(project, formSchema);
|
||||
|
||||
expect(
|
||||
@ -240,6 +241,26 @@ describe('document-model 测试', () => {
|
||||
data: { componentName: 'Form' },
|
||||
}),
|
||||
).toBeTruthy();
|
||||
expect(
|
||||
doc.checkNesting(doc.getNode('page'), doc.getNode('form'))
|
||||
).toBeTruthy();
|
||||
expect(
|
||||
doc.checkNesting(doc.getNode('page'), null)
|
||||
).toBeTruthy();
|
||||
expect(
|
||||
doc.checkNesting(doc.getNode('page'), {
|
||||
type: 'nodedata',
|
||||
data: { componentName: 'Other' },
|
||||
})
|
||||
).toBeFalsy();
|
||||
|
||||
expect(
|
||||
doc.checkNestingUp(doc.getNode('page'), { componentName: 'Other' })
|
||||
).toBeFalsy();
|
||||
|
||||
expect(
|
||||
doc.checkNestingDown(doc.getNode('page'), { componentName: 'Other' })
|
||||
).toBeTruthy();
|
||||
|
||||
expect(doc.checkNestingUp(doc.getNode('page'), null)).toBeTruthy();
|
||||
});
|
||||
|
||||
Loading…
x
Reference in New Issue
Block a user