@asymmetric-effort/specifyjs 0.2.158 → 0.2.160

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
@@ -17593,15 +17593,29 @@ function findContainerAtPoint(collection, x, y, excludeId) {
17593
17593
  const descendants = collectDescendantContainerIds(collection, excludeId);
17594
17594
  for (const id of descendants) excluded.add(id);
17595
17595
  }
17596
- for (let i = 0; i < collection.length; i++) {
17597
- const item = collection[i];
17598
- if (!isContainer(item)) continue;
17599
- if (excluded.has(item.container_id)) continue;
17600
- if (x >= item.position.x && x <= item.position.x + item.size.width && y >= item.position.y && y <= item.position.y + item.size.height) {
17601
- return item.container_id;
17596
+ let bestMatch = null;
17597
+ let bestDepth = -1;
17598
+ const stack = [[collection, 0, 0, 0]];
17599
+ while (stack.length > 0) {
17600
+ const [items, offsetX, offsetY, depth] = stack.pop();
17601
+ for (let i = 0; i < items.length; i++) {
17602
+ const item = items[i];
17603
+ if (!isContainer(item)) continue;
17604
+ if (excluded.has(item.container_id)) continue;
17605
+ const absX = item.position.x + offsetX;
17606
+ const absY = item.position.y + offsetY;
17607
+ if (x >= absX && x <= absX + item.size.width && y >= absY && y <= absY + item.size.height) {
17608
+ if (depth > bestDepth) {
17609
+ bestMatch = item.container_id;
17610
+ bestDepth = depth;
17611
+ }
17612
+ if (item.contents.length > 0) {
17613
+ stack.push([item.contents, absX, absY + 30, depth + 1]);
17614
+ }
17615
+ }
17602
17616
  }
17603
17617
  }
17604
- return null;
17618
+ return bestMatch;
17605
17619
  }
17606
17620
  function snapToGrid(pos, gridSize) {
17607
17621
  return {