diff --git a/docs/modules/Style-manager.md b/docs/modules/Style-manager.md index 9cc5bb70c..59753c87d 100644 --- a/docs/modules/Style-manager.md +++ b/docs/modules/Style-manager.md @@ -536,6 +536,311 @@ grapesjs.init({ ### Custom Style Manager +In case you need a completely custom Style Manager UI (eg. you have to use your UI components), you can create it from scratch by relying on the same sector/propriety architecture or even interfacing directly with selected targets. + +All you have to do is to indicate the editor your intent to use a custom UI and then subscribe to the `style:custom` event that will let you know when is the right moment to create/update your UI. + +```js +const editor = grapesjs.init({ + // ... + styleManager: { + custom: true, + // ... + }, +}); + +editor.on('style:custom', props => { + // props.container (HTMLElement) + // The default element where you can append your + // custom UI in order to render it in the default position. + + // Here you would put the logic to render/update your UI by relying on Style Manager API +}); +``` + +Here an example below of a custom Style Manager UI rendered by using Vuetify (Vue Material components) and relying on the default sector/propriety state architecture via API. + + + + + + ## Events diff --git a/src/commands/view/OpenStyleManager.js b/src/commands/view/OpenStyleManager.js index 65ba2b0af..679df818c 100644 --- a/src/commands/view/OpenStyleManager.js +++ b/src/commands/view/OpenStyleManager.js @@ -35,13 +35,14 @@ export default { const sm = editor.StyleManager; this.sm = sm; const smConfig = sm.getConfig(); + const pfx = smConfig.stylePrefix; + this.$header = $(`
${editor.t('styleManager.empty')}
`); + this.$cn.append(this.$header); + if (smConfig.custom) { sm.__trgCustom({ container: this.$cn2.get(0) }); } else if (!smConfig.appendTo) { this.$cn2.append(sm.render()); - const pfx = smConfig.stylePrefix; - this.$header = $(`
${editor.t('styleManager.empty')}
`); - this.$cn.append(this.$header); } // Create panel if not exists diff --git a/src/style_manager/index.js b/src/style_manager/index.js index 07483aecc..08ff5ddeb 100644 --- a/src/style_manager/index.js +++ b/src/style_manager/index.js @@ -183,13 +183,7 @@ export default () => { }, postRender() { - const elTo = this.getConfig().appendTo; - - if (elTo) { - const el = isElement(elTo) ? elTo : document.querySelector(elTo); - if (!el) return this.__logWarn('"appendTo" element not found'); - el.appendChild(this.render()); - } + this.__appendTo(); }, /**