vaheqelyan / svelte-grid

A responsive, draggable and resizable grid layout, for Svelte. [NOT MAINTAINED]
https://svelte-grid.now.sh/
MIT License
970 stars 58 forks source link

Freeze and unfreeze grid #142

Open MikeSpock opened 1 year ago

MikeSpock commented 1 year ago

I don't see a way to freeze and unfreeze the grid, meaning that all items should become fixed, not draggable or scalable.

I wrote a rather dirty workaround:

const toggleFreeze = (shouldFreeze) => {
        for(let item of items){
            for(let key in item){
                if(typeof(item[key].fixed) === 'boolean' ){
                    item[key].fixed = !!shouldFreeze;
                    item[key].resizable = !!shouldFreeze;
                    item[key].draggable = !!shouldFreeze;
                }
            }
        }
    }

but it has one caveat. After toggling the grid needs to update in order to change to fixed elements, which I don't know how to trigger within the code. So it waits until some user action to take effect.

Is there any other way to freeze the grid and unfreeze it if necessary?

vaheqelyan commented 1 year ago

check this https://svelte.dev/repl/a908ae0c59ad421cb9d9bc37503f07ef?version=3.53.1

i think the way you update your items does not trigger reactivity