| 640 | } |
| 641 | |
| 642 | drop(item?: DroppableItem): void { |
| 643 | if (!this.currentDropTarget) { |
| 644 | this.cancel(); |
| 645 | return; |
| 646 | } |
| 647 | |
| 648 | if (typeof item?.getDropOperation === 'function') { |
| 649 | let types = getTypes(this.dragTarget.items); |
| 650 | this.dropOperation = item.getDropOperation(types, this.dragTarget.allowedDropOperations); |
| 651 | } else if (typeof this.currentDropTarget.getDropOperation === 'function') { |
| 652 | let types = getTypes(this.dragTarget.items); |
| 653 | this.dropOperation = this.currentDropTarget.getDropOperation( |
| 654 | types, |
| 655 | this.dragTarget.allowedDropOperations |
| 656 | ); |
| 657 | } else { |
| 658 | // TODO: show menu ?? |
| 659 | this.dropOperation = this.dragTarget.allowedDropOperations[0]; |
| 660 | } |
| 661 | |
| 662 | if (typeof this.currentDropTarget.onDrop === 'function') { |
| 663 | let items: DropItem[] = this.dragTarget.items.map(item => ({ |
| 664 | kind: 'text', |
| 665 | types: new Set(Object.keys(item)), |
| 666 | getText: (type: string) => Promise.resolve(item[type]) |
| 667 | })); |
| 668 | |
| 669 | let rect = this.currentDropTarget.element.getBoundingClientRect(); |
| 670 | this.currentDropTarget.onDrop( |
| 671 | { |
| 672 | type: 'drop', |
| 673 | x: rect.left + rect.width / 2, |
| 674 | y: rect.top + rect.height / 2, |
| 675 | items, |
| 676 | dropOperation: this.dropOperation |
| 677 | }, |
| 678 | item?.target ?? null |
| 679 | ); |
| 680 | } |
| 681 | |
| 682 | this.end(); |
| 683 | announce(this.stringFormatter.format('dropComplete')); |
| 684 | } |
| 685 | |
| 686 | activate(dropTarget: DropTarget | null, dropItem: DroppableItem | null | undefined): void { |
| 687 | if (dropTarget && typeof dropTarget.onDropActivate === 'function') { |