|  | 
| 308 | 308 | 		let markerHeight = 0; | 
| 309 | 309 | 		const layerPanel = document.querySelector("[data-layer-panel]"); // Selects the element with the data-layer-panel attribute | 
| 310 | 310 | 		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 | +
 | 
| 311 | 316 | 			let layerPanelTop = layerPanel.getBoundingClientRect().top; | 
| 312 | 317 | 			Array.from(treeChildren).forEach((treeChild) => { | 
| 313 |  | -				const indexAttribute = treeChild.getAttribute("data-index"); | 
|  | 318 | +				const indexAttribute = parseInt(treeChild.getAttribute("data-index") ?? "0", 10); | 
| 314 | 319 | 				if (!indexAttribute) return; | 
| 315 |  | -				const { folderIndex, entry: layer } = layers[parseInt(indexAttribute, 10)]; | 
|  | 320 | +				const { folderIndex, entry: layer } = layers[indexAttribute]; | 
| 316 | 321 | 
 | 
| 317 | 322 | 				const rect = treeChild.getBoundingClientRect(); | 
| 318 | 323 | 				if (rect.top > clientY || rect.bottom < clientY) { | 
| 319 | 324 | 					return; | 
| 320 | 325 | 				} | 
|  | 326 | +
 | 
|  | 327 | +				const isDraggingBtnArtBoards = layers[indexAttribute]?.entry?.depth === 1 && layers[indexAttribute + 1]?.entry?.depth === 1; | 
|  | 328 | +				if (isDraggingBtnArtBoards) return; | 
|  | 329 | +
 | 
| 321 | 330 | 				const pointerPercentage = (clientY - rect.top) / rect.height; | 
| 322 | 331 | 				if (layer.childrenAllowed) { | 
| 323 | 332 | 					if (pointerPercentage < 0.25) { | 
|  | 
| 353 | 362 | 			// Dragging to the empty space below all layers | 
| 354 | 363 | 			let lastLayer = treeChildren[treeChildren.length - 1]; | 
| 355 | 364 | 			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 | +				} | 
| 361 | 377 | 			} | 
| 362 | 378 | 		} | 
| 363 | 379 | 
 | 
|  | 
0 commit comments