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

[FHL] Part 2 - Image Selection - Image Selection Plugin #1286

Merged
merged 8 commits into from
Sep 23, 2022

Conversation

juliaroldi
Copy link
Contributor

@juliaroldi juliaroldi commented Sep 21, 2022

Add Image Selection Plugin, this plugin is responsible for detect if a click was made above an image. If an image is selected, the selecImage core api will be triggered and will add border to the selected image.

selectImagePlugin

@juliaroldi juliaroldi changed the title [FHL] Part 2 - Image Selection - Image Selection [FHL] Part 2 - Image Selection - Image Selection Plugin Sep 21, 2022
@juliaroldi juliaroldi marked this pull request as ready for review September 21, 2022 23:24
*/
export default class ImageSelection implements EditorPlugin {
private editor: IEditor | null = null;
private image: HTMLImageElement | null = null;
Copy link
Collaborator

Choose a reason for hiding this comment

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

do we need to cache the image here? Can we get it (its id) using getSelectionRangeEx()?

Copy link
Contributor Author

Choose a reason for hiding this comment

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

Instead of saving the image, I'm saving only the id.

@@ -21,3 +30,38 @@ export const selectImage: SelectImage = (image: HTMLImageElement | null) => {

return null;
};

const select = (core: EditorCore, image: HTMLImageElement) => {
Copy link
Collaborator

Choose a reason for hiding this comment

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

Is there any duplicated code with table selection? we can move them out into dom package under style folder

Copy link
Contributor Author

Choose a reason for hiding this comment

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

I added this duplicated code as function under utils folder of the core, it add styles, but only for selection and it uses editor core object.


el.id = idPrefix + cont;
} else {
const elements = doc.querySelectorAll(`#${el.id}`);
Copy link
Collaborator

Choose a reason for hiding this comment

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

I know this is moved from table selection, but let's refine it. It may not be a good idea to call the function recursively. So we can do:

if (has id) {
  if (id is not unique) {
     remove id;
  }
}
if (not have id) {
   apply an id
}

Copy link
Contributor Author

Choose a reason for hiding this comment

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

I fixed and changed the name to addUniqueId, since the function is responsible to add the id and not only ensure that is unique.

@juliaroldi juliaroldi merged commit efef982 into master Sep 23, 2022
@JiuqingSong JiuqingSong deleted the fhl/juliaroldi/imageSelection-plugin branch October 31, 2022 19:20
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.

3 participants