MCPcopy Create free account
hub / github.com/Easy-Editor/EasyEditor / getDropContainer

Method getDropContainer

packages/core/src/simulator/simulator.ts:739–814  ·  view source on GitHub ↗

* find the suitable drop container

(e: LocateEvent)

Source from the content-addressed store, hash-verified

737 * find the suitable drop container
738 */
739 getDropContainer(e: LocateEvent): DropContainer | null {
740 const { target, dragObject } = e
741 const isAny = isDragAnyObject(dragObject)
742 const document = this.project.currentDocument!
743 const { rootNode } = document
744 let container: Node | null
745 let nodeInstance: NodeInstance<ComponentInstance, Node> | undefined
746
747 if (target) {
748 const ref = this.getNodeInstanceFromElement(target)
749 if (ref?.node) {
750 nodeInstance = ref
751 container = ref.node
752 } else if (isAny) {
753 return null
754 } else {
755 container = rootNode
756 }
757 } else if (isAny) {
758 return null
759 } else {
760 container = rootNode
761 }
762
763 if (!container?.isParental) {
764 container = container?.parent || rootNode
765 }
766
767 // TODO: use spec container to accept specialData
768 if (isAny) {
769 // will return locationData
770 return null
771 }
772
773 let instance: ComponentInstance | null | undefined = null
774 if (nodeInstance) {
775 if (nodeInstance.node === container) {
776 instance = nodeInstance.instance
777 } else {
778 instance = this.getClosestNodeInstance(nodeInstance.instance, container?.id)?.instance
779 }
780 } else {
781 instance = container && this.getComponentInstances(container!)[0]
782 }
783
784 let dropContainer: DropContainer = {
785 container: container!,
786 instance: instance!,
787 }
788
789 let res: any
790 let upward: DropContainer | null = null
791 while (container) {
792 res = this.handleAccept(dropContainer, e)
793 if (res === true) {
794 return dropContainer
795 }
796 if (!res) {

Callers 1

locateMethod · 0.95

Calls 5

getComponentInstancesMethod · 0.95
handleAcceptMethod · 0.95
isDragAnyObjectFunction · 0.90

Tested by

no test coverage detected