MCPcopy Create free account
hub / github.com/bvaughn/react-resizable-panels / getDropTarget

Function getDropTarget

lib/workspace/utils/getDropTarget.ts:19–167  ·  view source on GitHub ↗
({
  clientX,
  clientY,
  isExternal = false,
  model,
  rootElement,
  source,
  tabsetElements
}: {
  clientX: number;
  clientY: number;
  /** 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) */
  isExternal?: boolean;
  model: WorkspaceModel;
  rootElement: HTMLElement;
  source: DragSource;
  /** The workspace's tabset elements; tabsets that aren't registered are searched for their elements instead */
  tabsetElements?: TabsetElementRegistry | undefined;
})

Source from the content-addressed store, hash-verified

17import { toModelDropTarget } from "./toModelDropTarget";
18
19export 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)

Callers 5

getTargetFunction · 0.90
getTargetFunction · 0.90
updateTargetFunction · 0.90
getTargetFunction · 0.90

Calls 8

isShadowRootFunction · 0.90
getModelIndexFunction · 0.90
getOwnElementFunction · 0.90
getTabListIndexFunction · 0.90
getDropRegionFunction · 0.90
getEdgeDropTargetFunction · 0.85
getTabsetDropTargetFunction · 0.85

Tested by 1

getTargetFunction · 0.72