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

Add ability to provide generic for the internal type of the TextAnnotator #64

Open
oleksandr-danylchenko opened this issue Feb 26, 2024 · 1 comment

Comments

@oleksandr-danylchenko
Copy link
Contributor

Current State

Currently, the TextAnnotator allows to provide a generic only for the external type:

export interface TextAnnotator<T extends unknown = TextAnnotation> extends Annotator<TextAnnotation, T> {

And everywhere in the following code, only the TextAnnotation is hard-binded

Issue

When a user (me 😅) wants to extend the TextAnnotator with some plugin that might mutate the TextAnnotation with additional properties - I'm pretty much out of luck... Because the TextAnnotator, TextAnnotatorState, are strictly bound to the R6O TextAnnotation type.

The one option is to define the .d.ts file and override the TextAnnotation there. But it creates inconvenient indirectness and maintainers will have questions...

However, another better alternative is to make the TextAnnotator look something like this:

export interface TextAnnotator<I extends TextAnnotation = TextAnnotation, E extends unknown = TextAnnotation> extends Annotator<I, E> {

  element: HTMLElement;

  // Returns true if successful (or false if the annotation is not currently rendered)
  scrollIntoView(annotation: I): boolean;

  state: TextAnnotatorState<I>;

}

In that way - lib consumers can safely describe the extended internal types. And then simply use the typed useAnnotator and useAnnotatorStore hooks

@oleksandr-danylchenko
Copy link
Contributor Author

oleksandr-danylchenko commented Feb 26, 2024

I also tried following the RecogitoTEIAnnotator example:

export interface RecogitoTEIAnnotator<T extends unknown = TEIAnnotation> extends Annotator<TEIAnnotation, T> { }
export const TEIPlugin = (anno: TextAnnotator): RecogitoTEIAnnotator => {

But I think that using the extends Annotator for the plugin that works with the TextAnnotator won't be a precise type depiction. Because the latter adds new props (element, scrollIntoView, etc.) and overrides some of the lifecycle methods of the store (addAnnotation, getAnnotationBounds, etc.). Unfortunately, the extended Annotator won't have any of those...
Instead, I would like to be able to use the TextAnnotator type directly with a slightly updated internal model. Which cannot be done at the moment 🤷🏻‍♂️

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

No branches or pull requests

1 participant