-
-
Notifications
You must be signed in to change notification settings - Fork 32
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Editor Displays SVG Colors #2459
base: main
Are you sure you want to change the base?
Conversation
Fixes #2454. This is only a proof of concept. I would like to have been able to get this to work with actual editor buttons, but that seemed impossible, so I settled on showing it in the JSON Editor like the duplicate widget button. I used that area as an example, but I could never get the div to display properly. It does work in place of the duplicate widget button now as a demo. I could use some help getting the new div right. The button is there, it just doesn't work as it should. I've attached an image to show how this looks. Pretty cool.
So I tried debugging this some more. ChatGPT had me set up a mutation observer. What is happening (for the new svg button) is that the div is being appended properly, but right after that, the whole div gets re-written and the new div is gone. That does not happen for the commandoptions div. I just don't understand why. |
This works now! Hooray. I'm sure there is a more professional way to code this, but it does work. But it looks awesome because you can see the colors and hex codes AND you can click on the button and get automatic svgReplaces insertion for that color. A few observations: It filters out and will not show the options unless the widget has an svg image. The div is still doing something strange and keeps getting removed, so I added a mutation observer to reinsert it. Kind of a hack, but I spent more time on that than anything. The only thing not working the way I would like is that the colors do not close or reload if you select a different widget. So it is possible to select one widget, get the color choices, select a different widget (even one without an svg) and have the buttons insert the svgReplaces code. |
For what it's worth, I tried to implement this in the existing editor. Not too hard to set everything up. The problem was keeping everything in sync. The browser color picker, the right-side button color, the color of the image in the room, and the JSON text. Any of those could change and syncing was a real pain. So I abandoned that. I believe this is done and ready for review. |
Fixes #2454.
I've attached an image to show how this looks. Pretty cool.
To do:
Maybe: Fix so that div does not have to be reinserted by a mutation observer. Not needed to make it work but might make the code cleaner.
PR-SERVER-BOT: You can play around with it here: https://test.virtualtabletop.io/PR-2459/pr-test (or any other room on that server)