mirror of https://github.com/artf/grapesjs.git
nocodeframeworkdrag-and-dropsite-buildersite-generatortemplate-builderui-builderweb-builderweb-builder-frameworkwebsite-builderno-codepage-builder
You can not select more than 25 topics
Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.
3.4 KiB
3.4 KiB
Traits
You can customize the initial state of the module from the editor initialization, by passing the following Configuration Object
const editor = grapesjs.init({
traitManager: {
// options
}
})
Once the editor is instantiated you can use the API below and listen to the events. Before using these methods, you should get the module from the instance.
// Listen to events
editor.on('trait:value', () => { ... });
// Use the Trait Manager API
const tm = editor.Traits;
tm.select(...)
Available Events
trait:selectNew traits selected (eg. by changing a component).
editor.on('trait:select', ({ traits, component }) => { ... });
trait:valueTrait value updated.
editor.on('trait:value', ({ trait, component, value }) => { ... });
trait:category:updateTrait category updated.
editor.on('trait:category:update', ({ category, changes }) => { ... });
trait:customEvent to use in case of custom Trait Manager UI.
editor.on('trait:custom', ({ container }) => { ... });
traitCatch-all event for all the events mentioned above. An object containing all the available data about the triggered event is passed as an argument to the callback.
editor.on('trait', ({ event, model, ... }) => { ... });
getConfig
Get configuration object
Returns Object
select
Select traits from a component.
Parameters
componentComponent
Examples
tm.select(someComponent);
getCategories
Get trait categories from the currently selected component.
Examples
const traitCategories: Category[] = tm.getCategories();
Returns Array<Category>
getTraits
Get traits from the currently selected component.
Examples
const currentTraits: Trait[] = tm.getTraits();
getTraitsByCategory
Get traits by category from the currently selected component.
Parameters
traitsArray<Trait>?
Examples
tm.getTraitsByCategory();
// Returns an array of items of this type
// > { category?: Category; items: Trait[] }
// NOTE: The item without category is the one containing traits without category.
// You can also get the same output format by passing your own array of Traits
const myFilteredTraits: Trait[] = [...];
tm.getTraitsByCategory(myFilteredTraits);
Returns Array<TraitsByCategory>
getComponent
Get component from the currently selected traits.
Examples
tm.getComponent();
// Component {}
addType
Add new trait type. More about it here: Define new Trait type.