[QUESTION] How to prevent unique ids generation?
Question
Hi! Thanks for your work @artf.
This is a simplified code of how I use grapesjs, I want to save the styles and then want to apply them again. The problem is that ids already changed in DOM after first call of container.components() so styles will not be applied.
How to prevent this behavior? What should I clear/reset?
wrapper = [...]
style = [...]
components = [{mainBody: [...]}]
this.editor.setComponents(
Array.isArray(wrapper) ? this.pruneWrapper(wrapper) : wrapper,
);
const grapesWrapper = this.editor.getWrapper();
const [container] = grapesWrapper.find(
'[data-main-container]',
);
if (container) {
container.components(components.mainBody);
}
if (style) {
this.editor.setStyle(style);
const grapesJsWrapper = this.editor.getWrapper();
grapesJsWrapper.rerender();
}
Answers (3)
Hi @nikita-balakirev see if #2706 comment can help you. Cheers!
I fixed it now using editor.DomComponents.componentsById = {};
but I think it can lead to collisions between blocks at some point
what do you think?
Sorry @nikita-balakirev can't help you here without a complete reproducible example. When you export components as JSON all IDs are preserved and reused if load correctly, so for sure you're doing something wrong with storing/loading data. Obviously you shouldn't prevent unique ids generation (or doing what you did) as it'll break a lot of stuff
Related Questions and Answers
Continue research with similar issue discussions.
Issue #1341
[Question] How to work with Custom Components
Hello, I have some questions and issues about and with the grapes editorProblem 1 In a component, which class is there extended? Is it real...
Issue #913
[Question] Using Style tag instead of css
Hi, I've been taking a look inside of the dom_components, but cant seem to figure out how to manually override the styling aspect. I need a...
Issue #3213
QUESTION: How to save the dynamically added traits
Hi, @artf, I have a custom component that has a button trait. When the button is pressed, I am adding a custom trait dynamically using comp...
Issue #2076
[QUESTION] How make a new component to allow laravel blade directives?
Hi, thanks for the nice work. I'll like to know if there is a way to use blade directives inside the code. I already add a new functionalit...
Paid Plugins That Match This Issue
Curated by issue keywords and label relevance to help you ship faster.
Loading paid plugin recommendations...
Browse Plugin Categories
Jump directly to plugin category pages on the marketplace.