Custom storage : autoload not triggered
The autoload option actually works while adding the custom storage as a plugin.custom storage plugin : Editor :
Read full answer below ↓Question
version : grapes.min.js 0.15.10
Hi, I'm using a custom storage to load & store json data from/to a textarea. Using a custom storage seems to not support the autoload option. Instead, I have to manually trigger editor.load(), but it seems to update the editor so it messes with the noticeOnUnload option (which get triggered before any changes made by the user).
Here is the storageManager configuration :
storageManager
const editor = grapesjs.init({
...
storageManager: {
type: 'customStorage',
autosave: false,
autoload: true
},
...
});
Here is the the custom storage :
custom storage
editor.StorageManager.add('customStorage', {
load: function(keys, clb, clbErr) {
var res = {}, data = storageEl.text(); // get textarea json content
// custom logic
if( "" !== data ) {
try {
data = JSON.parse(data);
for (var i = 0; i < keys.length; i++) {
var v = data[keys[i]];
if(v) res[keys[i]] = v;
}
} catch(e) { clbErr( "Error while parsing JSON : " + e.message ); }
}
clb( res );
},
store(data, clb) {
var dataString = JSON.stringify( data );
storageEl.text( dataString ); // updating textarea json content
clb();
}
});
Is there any way to autoload a custom storage ? Thank you !
Answers (3)
The autoload option actually works while adding the custom storage as a plugin.
custom storage plugin :
grapesjs.plugins.add('customStorage', editor => {
...
sm.add('customStorage', {
// custom storage logic
});
...
});
Editor :
const editor = grapesjs.init({
...
plugins: ['customStorage'],
storageManager: {
type: 'customStorage',
autoload: true
},
...
});
@treztreiz did you ever figure out how to do it without registering it as a plugin? I'm also running into this issue.
@collindutter It seems that you must make a plugin. I suppose that the autoload option is used while grapes is instantiated, and unfortunately the function editor.StorageManager.add actually needs that instance... This does not happen with plugins as they are injected in the configuration during the instantiation :) Not sure about what I'm saying tho
Related Questions and Answers
Continue research with similar issue discussions.
Issue #597
storageManager: Loading from remote storage
Hi, I'm trying to read the HTML and CSS from my database. When I try to load it into the editor, nothing displays. I can store the data jus...
Issue #911
Could some one please help me with Custom Load.
What I can use instead of followings- editor.setHtml( arrdata['html'] ), editor.setCss( arrdata['css'] ), In below code.
Issue #1429
Empty content when load from remote storage if components array is not empty
I have problem loading stored remote content into the editor when the JSON contains non empty gjs-components My JSON data looks like this w...
Issue #2106
Traits not appear in edit mode when i update grapes version
Hi artf, i make traits for specific component ,when i saved this component as a json and load again in editor the traits were load correctl...
Paid Plugins That Match This Issue
Curated by issue keywords and label relevance to help you ship faster.
Loading paid plugin recommendations...
Check the open-source GrapesJS plugins on GitHub or run a quick search in our free catalog.
Browse free plugins →Premium plugins ship with support, regular updates, and production-ready features — save days of integration work.
Browse premium plugins →Related tutorials
In-depth guides on the same topic.
Tutorial
How to Build a Production GrapesJS Editor: The Complete Walkthrough of Brief, Preset, Plugins, and Services
A complete walkthrough of building a production GrapesJS editor: how to choose a preset, pick plugins, and scope setup services without burning a sprint.
Tutorial
GrapesJS Inline RTE Plugins Update: CKEditor 5 v0.1.4 and Froala Inline Text Editor
CKEditor 5 Inline for GrapesJS v0.1.4 fixes Studio SDK toolbar clipping, iframe injection and link balloon bugs. Compare with Froala Inline — both $69.
Tutorial
Embed GrapesJS in Your SaaS: A Weekend Guide
Embed GrapesJS in your SaaS and ship a white-label page builder over a weekend. Honest tradeoffs, real code, and the plugins that close the UX gap.
Browse Plugin Categories
Jump directly to plugin category pages on the marketplace.