Closed oleksandr-danylchenko closed 1 month ago
I also tried following the RecogitoTEIAnnotator
example:
https://github.com/recogito/text-annotator-js/blob/3a70b9ef5cafec4b54ed629e934e5875d6f06262/packages/extension-tei/src/TEIPlugin.ts#L34-L36
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 🤷🏻♂️
Current State
Currently, the
TextAnnotator
allows to provide a generic only for the external type: https://github.com/recogito/text-annotator-js/blob/3f587dd752084f3f6c291dec0577e01afb2d1e4d/packages/text-annotator/src/TextAnnotator.ts#L13 And everywhere in the following code, only theTextAnnotation
is hard-bindedIssue
When a user (me 😅) wants to extend the
TextAnnotator
with some plugin that might mutate theTextAnnotation
with additional properties - I'm pretty much out of luck... Because theTextAnnotator
,TextAnnotatorState
, are strictly bound to the R6OTextAnnotation
type.The one option is to define the
.d.ts
file and override theTextAnnotation
there. But it creates inconvenient indirectness and maintainers will have questions...However, another better alternative is to make the
TextAnnotator
look something like this:In that way - lib consumers can safely describe the extended internal types. And then simply use the typed
useAnnotator
anduseAnnotatorStore
hooks