Browse Source

Add `trait:category:update` event

pull/5907/head
Artur Arseniev 2 years ago
parent
commit
a18743b094
  1. 9
      src/trait_manager/model/Traits.ts
  2. 7
      src/trait_manager/types.ts

9
src/trait_manager/model/Traits.ts

@ -5,7 +5,7 @@ import Categories from '../../abstract/ModuleCategories';
import { AddOptions } from '../../common'; import { AddOptions } from '../../common';
import Component from '../../dom_components/model/Component'; import Component from '../../dom_components/model/Component';
import EditorModel from '../../editor/model/Editor'; import EditorModel from '../../editor/model/Editor';
import { TraitProperties } from '../types'; import TraitsEvents, { TraitProperties } from '../types';
import Trait from './Trait'; import Trait from './Trait';
import TraitFactory from './TraitFactory'; import TraitFactory from './TraitFactory';
@ -17,7 +17,12 @@ export default class Traits extends CollectionWithCategories<Trait> {
constructor(coll: TraitProperties[], options: { em: EditorModel }) { constructor(coll: TraitProperties[], options: { em: EditorModel }) {
super(coll); super(coll);
this.em = options.em; const { em } = options;
this.em = em;
this.categories = new Categories([], {
em,
events: { update: TraitsEvents.categoryUpdate },
});
this.on('add', this.handleAdd); this.on('add', this.handleAdd);
this.on('reset', this.handleReset); this.on('reset', this.handleReset);
const tm = this.module; const tm = this.module;

7
src/trait_manager/types.ts

@ -188,6 +188,13 @@ export enum TraitsEvents {
*/ */
value = 'trait:value', value = 'trait:value',
/**
* @event `trait:category:update` Trait category updated.
* @example
* editor.on('trait:category:update', ({ category, changes }) => { ... });
*/
categoryUpdate = 'trait:category:update',
/** /**
* @event `trait:custom` Event to use in case of [custom Trait Manager UI](https://grapesjs.com/docs/modules/Traits.html#custom-trait-manager). * @event `trait:custom` Event to use in case of [custom Trait Manager UI](https://grapesjs.com/docs/modules/Traits.html#custom-trait-manager).
* @example * @example

Loading…
Cancel
Save