Skip to content
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

Open
wants to merge 6 commits into
base: main
Choose a base branch
from
Open

Conversation

96LawDawg
Copy link
Collaborator

@96LawDawg 96LawDawg commented Jan 22, 2025

Fixes #2454.

I've attached an image to show how this looks. Pretty cool.

Screenshot 2025-01-21 225458

To do:

  • When clicking on another widget (or no widget), close the svg color list
  • Add support for VTT icons (currentColor)

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)

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.
@96LawDawg 96LawDawg added enhancement New feature or request editor labels Jan 22, 2025
@96LawDawg 96LawDawg marked this pull request as draft January 22, 2025 05:16
@96LawDawg 96LawDawg added the help needed The author of this PR needs help implementing one of its features label Jan 22, 2025
@96LawDawg 96LawDawg changed the title Editor Help with SVG Colors Editor Displays SVG Colors Jan 22, 2025
@96LawDawg
Copy link
Collaborator Author

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.

@96LawDawg
Copy link
Collaborator Author

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.

@96LawDawg 96LawDawg marked this pull request as ready for review January 23, 2025 04:25
@RaphaelAlvez
Copy link
Collaborator

this looks super cool

I wonder if fot the new UI we should reuse is wqith just the addition of a color picker to the right so we have the original and the new color:

image

@96LawDawg
Copy link
Collaborator Author

I wonder if fot the new UI we should reuse is wqith just the addition of a color picker to the right so we have the original and the new color:

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.

@96LawDawg 96LawDawg removed the help needed The author of this PR needs help implementing one of its features label Jan 27, 2025
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
editor enhancement New feature or request
Projects
None yet
Development

Successfully merging this pull request may close these issues.

Automatic svgReplaces color detection
2 participants