Skip to content

Commit 89aaa5e

Browse files
disallow invalid layer drop
1 parent 8d3a8c2 commit 89aaa5e

File tree

1 file changed

+23
-7
lines changed

1 file changed

+23
-7
lines changed

frontend/src/components/panels/Layers.svelte

Lines changed: 23 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -308,16 +308,25 @@
308308
let markerHeight = 0;
309309
const layerPanel = document.querySelector("[data-layer-panel]"); // Selects the element with the data-layer-panel attribute
310310
if (layerPanel !== null && treeChildren !== undefined && treeOffset !== undefined) {
311+
const lastChild = treeChildren[treeChildren.length - 1];
312+
if (lastChild.getBoundingClientRect().bottom < clientY) {
313+
return { select, insertParentId: undefined, insertDepth: 0, insertIndex: undefined, highlightFolder: false, markerHeight: 0 };
314+
}
315+
311316
let layerPanelTop = layerPanel.getBoundingClientRect().top;
312317
Array.from(treeChildren).forEach((treeChild) => {
313-
const indexAttribute = treeChild.getAttribute("data-index");
318+
const indexAttribute = parseInt(treeChild.getAttribute("data-index") ?? "0", 10);
314319
if (!indexAttribute) return;
315-
const { folderIndex, entry: layer } = layers[parseInt(indexAttribute, 10)];
320+
const { folderIndex, entry: layer } = layers[indexAttribute];
316321
317322
const rect = treeChild.getBoundingClientRect();
318323
if (rect.top > clientY || rect.bottom < clientY) {
319324
return;
320325
}
326+
327+
const isDraggingBtnArtBoards = layers[indexAttribute]?.entry?.depth === 1 && layers[indexAttribute + 1]?.entry?.depth === 1;
328+
if (isDraggingBtnArtBoards) return;
329+
321330
const pointerPercentage = (clientY - rect.top) / rect.height;
322331
if (layer.childrenAllowed) {
323332
if (pointerPercentage < 0.25) {
@@ -353,11 +362,18 @@
353362
// Dragging to the empty space below all layers
354363
let lastLayer = treeChildren[treeChildren.length - 1];
355364
if (lastLayer.getBoundingClientRect().bottom < clientY) {
356-
const numberRootLayers = layers.filter((layer) => layer.entry.depth === 1).length;
357-
insertParentId = undefined;
358-
insertDepth = 0;
359-
insertIndex = numberRootLayers;
360-
markerHeight = lastLayer.getBoundingClientRect().bottom - layerPanelTop;
365+
const lastLayerIndexAttr = lastLayer.getAttribute("data-index");
366+
if (lastLayerIndexAttr) {
367+
const { folderIndex, entry: lastEntry } = layers[parseInt(lastLayerIndexAttr, 10)];
368+
369+
if (lastEntry.depth === 1) {
370+
insertParentId = undefined;
371+
} else {
372+
insertParentId = lastEntry.parentId;
373+
}
374+
insertIndex = folderIndex + 1;
375+
markerHeight = lastLayer.getBoundingClientRect().bottom - layerPanel.getBoundingClientRect().top;
376+
}
361377
}
362378
}
363379

0 commit comments

Comments
 (0)