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

fix: resolve caption state handling and CSS issues #278

Open
wants to merge 2 commits into
base: master
Choose a base branch
from

Conversation

idebenone
Copy link
Member

Problem

  • The caption feature in the Image Tool wasn't properly reflecting the correct state when preloaded data contained a caption.
    pre-load data caption state
  • The tune state for the caption wasn't consistent.
    tune-state-inconsistency
  • CSS styling for visually showing/hiding caption field was altering the inline-toolbar position.
    inline-toolbar-css
  • select an image button was hidden in uploading state causing a bad UX if user doesn't select any file.
    upload-image

Solution

  • Corrected the logic to properly handle the caption state when loading pre-existing data.
    if (data.caption) {
      this.setTune('caption', true);
    }
  • Introduced an utility function which determines the tune state directly reading the CSS rather than depending on this._data values.
  • Instead of depending on display property, relying on visibility fixed the problem.
  • Removed button's styling display: none during uploading state.

@idebenone idebenone requested a review from neSpecc November 30, 2024 06:54
src/index.ts Outdated

// reset caption on toggle
if (tuneName === 'caption' && !this._data[tuneName]) {
if (tuneName === 'caption' && !this.ui.isTuneActive(tuneName)) {
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

why we depend on style instead of actual data state?

Copy link
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

The reason why I considered style because the way caption in features needs to be interpreted as boolean while its a string, leading to the inconsistency in maintaining the tune state (On successive enable/disable while resetting the caption). This doesn't feel like a a permanent fix.

So I took a step back and thought of introducing a withCaption field which is of type boolean like other tune values which are very consistent with tune state.

I also tried to turn the field caption into an object:

{
    state: boolean,
    value: string,
}

But introducing a complex structure compared to a straight forward boolean seems unnecessary.

@@ -135,6 +135,7 @@ This Tool returns `data` with following format
| -------------- | --------- | ------------------------------- |
| file | `object` | Uploaded file data. Any data got from backend uploader. Always contain the `url` property |
| caption | `string` | image's caption |
| withCaption | `boolean` | add caption to image |
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I think it's redundant property since we already have "caption" field that can be empty.

Developer can disable caption for all image blocks using tool config. It should not affect output data

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

2 participants