Ability to check if an element was edited #4215
-
Hello artf and all contributors I have a task that we call "Nice to have" :P For example: I thought about editing all the element blocks to receive an attribute, eg data-has-edited and checking that attribute programmatically, but it seemed soooo laborious. Is there a "Grapesjs way" to achieve it? |
Beta Was this translation helpful? Give feedback.
Replies: 1 comment 1 reply
-
CodeHey! I was working on the same thing and solved it by updating the
ExplanationI considered making a new component type but realized it would be messy. A I also thought about making some sort of trait to handle this, so that way I could add it to component I wanted and easily remove it (example in docs). However I don't believe there is a way to add a trait in a component definition, which means the traits would have to be added at runtime (after the block is dropped onto the canvas). To ensure compatibility with existing blocks and data, nothing is set as a placeholder by default, and all that needs to be done for text to return to its default behavior is to set the The method
There is still the issue of events not bubbling, meaning we don't know when we should be checking if the component was edited. We could do it on any change detected through the global event however I am unsure of the potential performance impact as every text component on the page would be checking to see if it was edited, every time the user changes their selection. Also the To work around that potential issue a global event listener is only created for text which is a placeholder, and before the edit check actually takes place, it ensures that the change actually happened to the placeholder or inside the placeholder. After it is detected that the component is no longer a placeholder, the event listener is removed to prevent unnecessary processing. UsageI was unsure of when the user should be warned that they haven't changed placeholder text. I will probably do when the user attempts to save (as I am not using auto saving for remote storage). Some the reason I used the approach of storing the To check every component we can do:
|
Beta Was this translation helpful? Give feedback.
Code
Hey! I was working on the same thing and solved it by updating the
Text
component type. (as mentioned in docs)