From 3649075622602c96d2cc7263dceb2ddade69fc49 Mon Sep 17 00:00:00 2001 From: Guzman Date: Wed, 14 Feb 2024 13:49:49 -0300 Subject: [PATCH] Added ExternalSelection interface --- src/SeqViewerContainer.tsx | 19 +++---------------- src/SeqViz.tsx | 8 ++------ src/selectionContext.ts | 6 ++++++ 3 files changed, 11 insertions(+), 22 deletions(-) diff --git a/src/SeqViewerContainer.tsx b/src/SeqViewerContainer.tsx index 3c09bd12e..9ccbddaeb 100644 --- a/src/SeqViewerContainer.tsx +++ b/src/SeqViewerContainer.tsx @@ -8,7 +8,7 @@ import SelectionHandler, { InputRefFunc } from "./SelectionHandler"; import CentralIndexContext from "./centralIndexContext"; import { Annotation, CutSite, Highlight, NameRange, Primer, Range, SeqType } from "./elements"; import { isEqual } from "./isEqual"; -import SelectionContext, { Selection, defaultSelection } from "./selectionContext"; +import SelectionContext, { ExternalSelection, Selection, defaultSelection } from "./selectionContext"; /** * This is the width in pixels of a character that's 12px @@ -46,11 +46,7 @@ interface SeqViewerContainerProps { rotateOnScroll: boolean; search: NameRange[]; selectAllEvent: (event: React.KeyboardEvent) => boolean; - selection?: { - clockwise?: boolean; - end: number; - start: number; - }; + selection?: ExternalSelection; seq: string; seqType: SeqType; showComplement: boolean; @@ -142,16 +138,7 @@ class SeqViewerContainer extends React.Component { + getSelection = (state: Selection, prop?: ExternalSelection): Selection => { if (prop) { return { ...prop, clockwise: typeof prop.clockwise === "undefined" || !!prop.clockwise, type: "" }; } diff --git a/src/SeqViz.tsx b/src/SeqViz.tsx index 78e2034e1..dc4982bad 100644 --- a/src/SeqViz.tsx +++ b/src/SeqViz.tsx @@ -18,7 +18,7 @@ import { } from "./elements"; import { isEqual } from "./isEqual"; import search from "./search"; -import { Selection } from "./selectionContext"; +import { ExternalSelection, Selection } from "./selectionContext"; import { complement, directionality, guessType, randomID } from "./sequence"; /** `SeqViz` props. See the README for more details. One of `seq`, `file` or `accession` is required. */ @@ -121,11 +121,7 @@ export interface SeqVizProps { * Externally managed selection. * * If passed, SeqViz uses this prop as the selection range, rather than the internally managed selection */ - selection?: { - clockwise?: boolean; - end: number; - start: number; - }; + selection?: ExternalSelection; /** a sequence to render. Can be DNA, RNA, or an amino acid sequence. Setting accession or file overrides this */ seq?: string; diff --git a/src/selectionContext.ts b/src/selectionContext.ts index 0c7e10dd3..1f957800c 100644 --- a/src/selectionContext.ts +++ b/src/selectionContext.ts @@ -27,6 +27,12 @@ export interface Selection { viewer?: "LINEAR" | "CIRCULAR"; } +export interface ExternalSelection { + clockwise?: boolean; + end: number; + start: number; +} + /** Initial/default selection */ export const defaultSelection: Selection = { clockwise: true,