GrapesJS / grapesjs

Free and Open source Web Builder Framework. Next generation tool for building templates without coding
https://grapesjs.com
BSD 3-Clause "New" or "Revised" License
22.36k stars 4.05k forks source link

Default Component Properties #1374

Closed emilsedgh closed 6 years ago

emilsedgh commented 6 years ago

Is there any way I can change the default properties of components?

I want almost everything to be copyable: false, resizable: false, draggable: false unless the loaded component specifically provides a data-resizable=true.

So basically I want to whitelist some components to enable these instead of blacklisting.

Is it doable?

artf commented 6 years ago

You can update the default component https://grapesjs.com/docs/modules/Components.html#update-component-type

jereddanielson commented 6 years ago

@artf FYI that doesn't exactly work as needed. Updating the default component's default properties does not take effect for already-defined components (such as built in table, textnode, et. al.) because they have already extended the default model. Updating the default component would only change the default behavior for any new models that further extend the new default model definition.

In order to update all components, including existing and built ins, to have the desired default properties, I had to iterate over them all and update them one by one. This resulted in the desired (for me) behavior of establishing across-the-board default properties.

// Update all component model default properties
const allComps = editor.DomComponents.componentTypes.slice();
for (let i = 0; i < allComps.length; i++) {
    editor.DomComponents.addType(allComps[i].id, {
        model: {
            defaults: {
                copyable: false,
                resizable: false,
                draggable: false,
            }
        },
    });
}
artf commented 6 years ago

@jereddanielson correct, this is how you should do to update also already defined component types. Thanks for pointing this out

lock[bot] commented 5 years ago

This thread has been automatically locked since there has not been any recent activity after it was closed. Please open a new issue for related bugs.