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

Trait extends #1999

Closed acamenhas closed 5 years ago

acamenhas commented 5 years ago

Hi,

I need to extends the video type, just to add a new trait/property: muted There is any documentation that can tell me how can i extend an existing type?

Thanks

artf commented 5 years ago

To learn more about how to extend components start from here: https://grapesjs.com/docs/modules/Components.html

The problem with the Video Component that its traits are handled a bit differently so in this case, I'd suggest looking at its source to get a better idea of how they work, but I think at the end this will work for you:

const dc = editor.DomComponents;
dc.addType('video', {
    extendFn: ['updateTraits'],
    model: {
        init() {
            this.addMutedTrait();
        },

        updateTraits() {
            this.addMutedTrait();
        },

        addMutedTrait() {
            if (!this.getTrait('muted')) {
                this.addTrait({
                    type: 'checkbox',
                    name: 'muted',
                })
            }
        },
    },
})
lock[bot] commented 4 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.

lock[bot] commented 4 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.