Custom Store/Load using a Json object, without using the "Storage" API
I think I got it using: Then: let export = editor.store(); And: importFrom(export); That said, it doesn't feel totaly "right" to me. I would like a version of the functions where you can specify the exported Json object directly!
Read full answer below ↓Question
I'm using the latest version, 0.15.9, and I'm new to this fantastic project! I'm currently learning a lot, starting from scratch. Please let me know if you prefere such questions on Stack Overflow or elsewhere.
I'm trying to export/import the content by myself, without using the "Storage" API. I see the store() function returns the exported content as a JSON object, and this is perfect for my needs! But how can I then programmatically import this JSON back? I think the load() function doesn't take such exported JSON object as a parameter, it forces you to use the "Storage" API, is that correct?
In other words, is there a way to programatically reset the state of a GrapeJs instance using the exported content, as a JSON object?
Answers (2)
I think I got it using:
let exportToLoad;
let editor = grapesjs.init({
// ...
storageManager: {
type: 'simpleStorage'
}
});
editor.StorageManager.add('simpleStorage', {
load(keys, clb, clbErr) {
if(exportToLoad) {
clb(exportToLoad);
}
},
store(data, clb, clbErr) {
return data;
}
});
function importFrom(exportContent) {
exportToLoad = exportContent;
editor.load(() => {});
},
Then:
let export = editor.store();
And:
importFrom(export);
That said, it doesn't feel totaly "right" to me. I would like a version of the functions where you can specify the exported Json object directly!
Using custom storage is actually the best way
I would like a version of the functions where you can specify the exported Json object directly!
Well, no one limits you to update your exportToLoad
Related Questions and Answers
Continue research with similar issue discussions.
Issue #759
Problems trying to load and save
Could someone please let me know the required format of the response from the storage save action? I originally posted an issue under the m...
Issue #3136
Create one more key in JSON
{ "type": "text", "status": "hovered", "content": "Insert your text here", "attributes": { "id": "ixx2" }, "activeOnRender": 0, "open": fal...
Issue #1088
add new custom default class for map
can you please let me know how to add custom class in parent div of map iframe. when I try to add custom class in move function of 'grapesj...
Issue #2526
Custom storage : autoload not triggered
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 t...
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.