Skip to content

Commit

Permalink
Fix when item is missing
Browse files Browse the repository at this point in the history
  • Loading branch information
jrmi committed Mar 9, 2024
1 parent 8b4cf07 commit 27aa15e
Show file tree
Hide file tree
Showing 2 changed files with 26 additions and 17 deletions.
24 changes: 13 additions & 11 deletions src/lib/board/useDim.js
Original file line number Diff line number Diff line change
Expand Up @@ -329,17 +329,19 @@ const useDim = () => {
(boundingBox, item) => {
const elem = getItemElem(boardWrapper, item.id);

boundingBox.left = Math.min(item.x, boundingBox.left);
boundingBox.top = Math.min(item.y, boundingBox.top);

boundingBox.right = Math.max(
item.x + elem.offsetWidth,
boundingBox.right
);
boundingBox.bottom = Math.max(
item.y + elem.offsetHeight,
boundingBox.bottom
);
if (elem) {
boundingBox.left = Math.min(item.x, boundingBox.left);
boundingBox.top = Math.min(item.y, boundingBox.top);

boundingBox.right = Math.max(
item.x + elem.offsetWidth,
boundingBox.right
);
boundingBox.bottom = Math.max(
item.y + elem.offsetHeight,
boundingBox.bottom
);
}

return boundingBox;
},
Expand Down
19 changes: 13 additions & 6 deletions src/lib/utils.js
Original file line number Diff line number Diff line change
Expand Up @@ -123,13 +123,20 @@ export const isItemInsideElement = (itemElement, otherElem) => {
};

export const getItemElem = (wrapper, itemId) => {
const elems = wrapper.getElementsByClassName(`item ${itemId}`);
const elem = elems[0];
if (!elem) {
// eslint-disable-next-line no-console
console.error(`Missing item ${itemId}`);
try {
const elems = wrapper.getElementsByClassName(`item ${itemId}`);
const elem = elems[0];
if (!elem) {
console.error(`Missing item ${itemId}`);
}
return elem;
} catch (e) {
console.error(
`Error while getting item with id ${itemId} with wrapper`,
wrapper
);
return undefined;
}
return elem;
};

export const getIdFromElem = (elem) => {
Expand Down

0 comments on commit 27aa15e

Please sign in to comment.