MCPcopy
hub / github.com/GrapesJS/grapesjs / StyleManager

Class StyleManager

packages/core/src/style_manager/index.ts:75–840  ·  view source on GitHub ↗

Source from the content-addressed store, hash-verified

73const propDef = (value: any) => value || value === 0;
74
75export default class StyleManager extends ItemManagerModule<
76 StyleManagerConfig,
77 /** @ts-ignore */
78 Sectors
79> {
80 builtIn: PropertyFactory;
81 upAll: Debounced;
82 properties: typeof Properties;
83 events = StyleManagerEvents;
84 sectors: Sectors;
85 SectView!: SectorsView;
86 Sector = Sector;
87 storageKey = '';
88 __ctn?: HTMLElement;
89
90 /**
91 * Get configuration object
92 * @name getConfig
93 * @function
94 * @return {Object}
95 */
96
97 /**
98 * Initialize module. Automatically called with a new instance of the editor
99 * @param {Object} config Configurations
100 * @private
101 */
102 constructor(em: EditorModel) {
103 super(em, 'StyleManager', new Sectors([], { em }), StyleManagerEvents, defConfig());
104 bindAll(this, '__clearStateTarget');
105 const { events } = this;
106 const c = this.config;
107 const ppfx = c.pStylePrefix;
108 if (ppfx) c.stylePrefix = ppfx + c.stylePrefix;
109 this.builtIn = new PropertyFactory();
110 this.properties = new Properties([], { em, module: this });
111 this.sectors = this.all; // TODO check if (module: this) is required
112 const model = new Model({ targets: [] });
113 this.model = model;
114
115 // Triggers for the selection refresh and properties
116 const eventCmpUpdate = ComponentsEvents.update;
117 const ev = `${ComponentsEvents.toggled} ${eventCmpUpdate}:classes change:state change:device frame:resized selector:type`;
118 this.upAll = debounce(() => this.__upSel(), 0);
119 model.listenTo(em, ev, this.upAll as any);
120 // Clear state target on any component selection change, without debounce (#4208)
121 model.listenTo(em, ComponentsEvents.toggled, this.__clearStateTarget);
122
123 // Triggers only for properties (avoid selection refresh)
124 const upProps = debounce(() => {
125 this.__upProps();
126 this.__trgCustom();
127 }, 0);
128 model.listenTo(em, 'styleable:change undo redo', upProps);
129
130 // Triggers only custom event
131 const trgCustom = debounce(() => this.__trgCustom(), 0);
132 model.listenTo(em, `${events.layerSelect} ${events.target}`, trgCustom);

Callers

nothing calls this directly

Calls

no outgoing calls

Tested by

no test coverage detected