| 17 | import { toModelDropTarget } from "./toModelDropTarget"; |
| 18 | |
| 19 | export function getDropTarget({ |
| 20 | clientX, |
| 21 | clientY, |
| 22 | isExternal = false, |
| 23 | model, |
| 24 | rootElement, |
| 25 | source, |
| 26 | tabsetElements |
| 27 | }: { |
| 28 | clientX: number; |
| 29 | clientY: number; |
| 30 | /** Set if the source is in another workspace, so its ids don't refer to nodes of this one's model (and the nodes' own tabsets don't apply) */ |
| 31 | isExternal?: boolean; |
| 32 | model: WorkspaceModel; |
| 33 | rootElement: HTMLElement; |
| 34 | source: DragSource; |
| 35 | /** The workspace's tabset elements; tabsets that aren't registered are searched for their elements instead */ |
| 36 | tabsetElements?: TabsetElementRegistry | undefined; |
| 37 | }): TabDropTarget | undefined { |
| 38 | // Hit test within the workspace's own root, since for a workspace in a shadow root the document only reports the shadow host |
| 39 | const root = rootElement.getRootNode(); |
| 40 | const element = ( |
| 41 | isShadowRoot(root) ? root : rootElement.ownerDocument |
| 42 | ).elementFromPoint(clientX, clientY); |
| 43 | if (!element || !rootElement.contains(element)) { |
| 44 | return undefined; |
| 45 | } |
| 46 | |
| 47 | const modelIndex = getModelIndex(model); |
| 48 | |
| 49 | // Edges of the workspace take precedence over the tabsets beneath them (which still accept drops further in) |
| 50 | const edge = getEdgeDropTarget({ |
| 51 | clientX, |
| 52 | clientY, |
| 53 | element, |
| 54 | isExternal, |
| 55 | model, |
| 56 | rootElement, |
| 57 | source |
| 58 | }); |
| 59 | if (edge) { |
| 60 | const collapsedTarget = getCollapsedEdgeTabsetTarget({ |
| 61 | clientX, |
| 62 | clientY, |
| 63 | edge, |
| 64 | isExternal, |
| 65 | model, |
| 66 | rootElement, |
| 67 | source |
| 68 | }); |
| 69 | if (collapsedTarget === undefined) { |
| 70 | return { edge }; |
| 71 | } |
| 72 | |
| 73 | return collapsedTarget ?? undefined; |
| 74 | } |
| 75 | |
| 76 | // Skip tabsets of other workspaces (e.g. one rendered within a tab) |