From 32454245f28bbb33d22f3c35907135c58b744dbf Mon Sep 17 00:00:00 2001 From: Joel Poloney Date: Sat, 27 Feb 2021 14:24:38 -0800 Subject: [PATCH 1/3] Expose types correctly and add support for generic annotations --- package.json | 1 + src/types/index.d.ts | 56 +++++++++++++++++++++++++------------------- 2 files changed, 33 insertions(+), 24 deletions(-) diff --git a/package.json b/package.json index a5bcdef..4de2bee 100644 --- a/package.json +++ b/package.json @@ -4,6 +4,7 @@ "description": "react-image-annotation React component", "author": "Arian Allenson Valdez (http://arianv.com/)", "main": "lib/index.js", + "types": "src/types/index.d.ts", "module": "es/index.js", "files": [ "css", diff --git a/src/types/index.d.ts b/src/types/index.d.ts index 026db11..15b3890 100644 --- a/src/types/index.d.ts +++ b/src/types/index.d.ts @@ -35,7 +35,7 @@ declare module "react-image-annotation" { id?: number; }; } - interface IAnnotationProps { + interface IAnnotationProps { src: string; alt?: string; innerRef?: (e: any) => any; @@ -44,45 +44,53 @@ declare module "react-image-annotation" { onMouseMove?: (e: React.MouseEvent) => any; onClick?: (e: React.MouseEvent) => any; - annotations: IAnnotation[]; + annotations: T[]; type?: string; selectors?: ISelector[]; - value: IAnnotation | {}; + value: T | {}; onChange?: (e: any) => any; onSubmit?: (e: any) => any; - activeAnnotationComparator?: (annotation: IAnnotation) => boolean; - activeAnnotations?: IAnnotation[]; + activeAnnotationComparator?: (annotation: T) => boolean; + activeAnnotations?: T[]; disableAnnotation?: boolean; disableSelector?: boolean; - renderSelector?: ( - { annotation, active }: { annotation: IAnnotation; active: boolean } - ) => any; + renderSelector?: ({ + annotation, + active, + }: { + annotation: T; + active: boolean; + }) => any; disableEditor?: boolean; - renderEditor?: ( - { - annotation, - onChange, - onSubmit - }: { - annotation: IAnnotation; - onChange: (annotation: IAnnotation | {}) => any; - onSubmit: (e?: any) => any; - } - ) => any; + renderEditor?: ({ + annotation, + onChange, + onSubmit, + }: { + annotation: T; + onChange: (annotation: T | {}) => any; + onSubmit: (e?: any) => any; + }) => any; - renderHighlight?: ( - { annotation, active }: { annotation: IAnnotation; active: boolean } - ) => any; - renderContent?: ({ annotation }: { annotation: IAnnotation }) => any; + renderHighlight?: ({ + key, + annotation, + active, + }: { + key: string; + annotation: T; + active: boolean; + }) => any; + renderContent?: ({ annotation }: { annotation: T }) => any; disableOverlay?: boolean; renderOverlay?: () => any; allowTouch: boolean; } - class Annotation extends React.Component {} + class Annotation extends React.Component, {}> {} export default Annotation; } From 0e66a71b285aa7d6f22c2a0fff73000329e8d809 Mon Sep 17 00:00:00 2001 From: Joel Poloney Date: Tue, 2 Mar 2021 15:19:51 -0800 Subject: [PATCH 2/3] Expose types in files --- package.json | 3 ++- 1 file changed, 2 insertions(+), 1 deletion(-) diff --git a/package.json b/package.json index 4de2bee..0628d34 100644 --- a/package.json +++ b/package.json @@ -10,7 +10,8 @@ "css", "es", "lib", - "umd" + "umd", + "src/types/index.d.ts" ], "scripts": { "build": "nwb build-react-component", From 4963d68f955f16af970434e5219086c9ded7aee2 Mon Sep 17 00:00:00 2001 From: Joel Poloney Date: Tue, 2 Mar 2021 15:22:40 -0800 Subject: [PATCH 3/3] Add prepare statement for local builds --- package.json | 1 + 1 file changed, 1 insertion(+) diff --git a/package.json b/package.json index 0628d34..c262e56 100644 --- a/package.json +++ b/package.json @@ -14,6 +14,7 @@ "src/types/index.d.ts" ], "scripts": { + "prepare": "nwb build-react-component", "build": "nwb build-react-component", "deploy": "gh-pages -d demo/dist", "clean": "nwb clean-module && nwb clean-demo",