Issue #1640Opened December 8, 2018by northkode0 reactions

[Q] Loading a new module into the editor

Question

I have built a fully working page management system into the editor but I wasn't quite sure the proper way to inject the panel into the editor without doing the below code so i'm looking for some advice if this is not correct.

I have a Page Plugin that I load in:


var editor = grapesjs.init( {
    height: '100%',
    showOffsets: 1,
    noticeOnUnload: 0,
    storageManager: {
        id: 'sa-', // Prefix identifier that will be used on parameters
        type: 'local', // Type of the storage
        autosave: false, // Store data automatically
        autoload: true, // Autoload stored data on init
    },
    container: '#gjs',
    fromElement: true,
    plugins: [ 'page-editor' ],
    pluginsOpts: {
        'page-editor': {}
    }
} );

The page-editor plugin basically loads in a custom panels plugin i have import panels from './panels'; which then in the Plugin Constructor does

    panels( editor, config );

This is where things to me feel weird. I load in my PageManager class import PageManager from "./pagemanager";

And then in the init function of the Panels Controller Class, after I have set all the custom panels for devices, buttons etc, I load in the Page Manager like:

// ADDING IN NEW PAGE MANAGER COMPONENT
        editor.getModel().loadModule( PageManager );
        editor.PageManager = editor.getModel().get( 'PageManager' );

I found the loadModule function from the source code and wasnt sure if there was a different way to inject this into the core as I also wanted to create a custom command that toggles the PageManager on and off which I do by binding a new command to the system and I toggle the PageManager display to block just like the LayerManager.

Please let me know if that is not the best way of loading the PageManager in as id like to folllow the proper system flow.

Answers (2)

artfDecember 12, 20180 reactions

Hi @northkode modules are only used internally by GrapesJS, it's not something you have to deal in your plugin, just init all your stuff inside your plugin function

lock[bot]December 12, 20190 reactions

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.

Related Questions and Answers

Continue research with similar issue discussions.

Paid Plugins That Match This Issue

Curated by issue keywords and label relevance to help you ship faster.

View all plugins

Loading paid plugin recommendations...

Browse Plugin Categories

Jump directly to plugin category pages on the marketplace.