nomcopter / react-mosaic

A React tiling window manager

Home Page:https://nomcopter.github.io/react-mosaic/

Geek Repo:Geek Repo

Github PK Tool:Github PK Tool

Support overriding the mosaic ID to allow for external drag-and-drop

chrisdalke opened this issue · comments

Hello, thanks for your great work on the library :)

For my use case, I'd like to drag-and-drop into the mosaic layout from external drag sources (You've previously commented on this in #128 and #122).

In order to drag externally and have the nice-looking drag previews render correctly, you must pass a mosaicId into the drag item. Obtaining this ID from outside the mosaic context is clumsy. Could we support overriding this ID to make external drag-and-drop simpler?

Some more details:

After reading the previous tickets on external dragging, I was able to get an external drag source working, by passing an object of the form:

{
    type: MosaicDragType.WINDOW,
    mosaicId: <the mosaic ID from the context>
}

However, in order to get this mosaic ID from a component outside of the Mosaic context, I had to do something very "hacky" from inside a window component to get the generated UUID for the Mosaic, along these lines:

const mosaicContext = useContext(MosaicContext);
useEffect(() => {
    globalMosaicId = mosaicContext.mosaicId;
    // ... On mount, save the mosaic ID somewhere for use in drag sources
}, []);

Do you have any thoughts on a more elegant way to get the generated mosaic ID from outside the Mosaic context, since this is a requirement to be able to drag content externally into the mosaic and have the drag preview display properly?

My initial suggestion would be to allow a fixed mosaic ID to be set via a property on the Mosaic object, but I'm not sure if there would be unforeseen consequences of that ID being constant.

Good call - thanks for the detailed report