@weng-lab/genomebrowser-ui 0.1.7 → 0.1.9

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
package/dist/lib.d.ts CHANGED
@@ -1,4 +1,8 @@
1
1
  import { default as TrackSelect, TrackSelectProps } from './TrackSelect/TrackSelect';
2
2
  import { createSelectionStore, SelectionStoreInstance } from './TrackSelect/store.ts';
3
+ import { rowById } from './TrackSelect/consts.ts';
4
+ import { RowInfo } from './TrackSelect/types.ts';
3
5
  export { TrackSelect, TrackSelectProps };
4
6
  export { createSelectionStore, SelectionStoreInstance };
7
+ export { rowById };
8
+ export { RowInfo };
package/package.json CHANGED
@@ -1,7 +1,7 @@
1
1
  {
2
2
  "name": "@weng-lab/genomebrowser-ui",
3
3
  "private": false,
4
- "version": "0.1.7",
4
+ "version": "0.1.9",
5
5
  "license": "MIT",
6
6
  "type": "module",
7
7
  "publishConfig": {
@@ -1,5 +1,6 @@
1
1
  import { create, StoreApi, UseBoundStore } from "zustand";
2
- import { SelectionAction, SelectionState } from "./types";
2
+ import { rowById } from "./consts";
3
+ import { RowInfo, SelectionAction, SelectionState } from "./types";
3
4
 
4
5
  export type SelectionStoreInstance = UseBoundStore<
5
6
  StoreApi<SelectionState & SelectionAction>
@@ -18,6 +19,20 @@ export function createSelectionStore(initialIds?: Set<string>) {
18
19
  const all = get().selectedIds;
19
20
  return new Set([...all].filter((id) => !isAutoGeneratedId(id)));
20
21
  },
22
+ // Returns a Map of track IDs to RowInfo (no auto-generated IDs)
23
+ getTrackMap: () => {
24
+ const all = get().selectedIds;
25
+ const map = new Map<string, RowInfo>();
26
+ all.forEach((id) => {
27
+ if (!isAutoGeneratedId(id)) {
28
+ const row = rowById.get(id);
29
+ if (row) {
30
+ map.set(id, row);
31
+ }
32
+ }
33
+ });
34
+ return map;
35
+ },
21
36
  setSelected: (ids: Set<string>) =>
22
37
  set(() => ({
23
38
  selectedIds: new Set(ids),
@@ -105,6 +105,8 @@ export type SelectionState = {
105
105
  export type SelectionAction = {
106
106
  // Returns only real track IDs (filters out auto-generated group IDs)
107
107
  getTrackIds: () => Set<string>;
108
+ // Returns a Map of track IDs to RowInfo (no auto-generated IDs)
109
+ getTrackMap: () => Map<string, RowInfo>;
108
110
  setSelected: (ids: Set<string>) => void;
109
111
  removeIds: (removedIds: Set<string>) => void;
110
112
  clear: () => void;
package/src/lib.ts CHANGED
@@ -6,3 +6,9 @@ import {
6
6
  type SelectionStoreInstance,
7
7
  } from "./TrackSelect/store.ts";
8
8
  export { createSelectionStore, SelectionStoreInstance };
9
+
10
+ import { rowById } from "./TrackSelect/consts.ts";
11
+ export { rowById };
12
+
13
+ import type { RowInfo } from "./TrackSelect/types.ts";
14
+ export { RowInfo };
package/test/main.tsx CHANGED
@@ -1,10 +1,43 @@
1
+ import { useEffect, useMemo } from "react";
1
2
  import { createSelectionStore } from "../src/TrackSelect/store";
2
3
  import TrackSelect from "../src/TrackSelect/TrackSelect";
3
4
  import { createRoot } from "react-dom/client";
4
5
 
6
+ function getLocalStorage(assembly: string): Set<string> | null {
7
+ if (typeof window === "undefined" || !window.sessionStorage) return null;
8
+
9
+ const selectedIds = sessionStorage.getItem(assembly + "-selected-tracks");
10
+ if (!selectedIds) return null;
11
+ const idsArray = JSON.parse(selectedIds) as string[];
12
+ return new Set(idsArray);
13
+ }
14
+
15
+ function setLocalStorage(trackIds: Set<string>, assembly: string) {
16
+ sessionStorage.setItem(
17
+ assembly + "-selected-tracks",
18
+ JSON.stringify([...trackIds]),
19
+ );
20
+ }
21
+
22
+ const assembly = "grch38";
5
23
  function Main() {
6
- const store = createSelectionStore();
7
- return <TrackSelect store={store} />;
24
+ const selectionStore = useMemo(() => {
25
+ const localIds = getLocalStorage(assembly);
26
+ const ids = localIds != null ? localIds : new Set<string>();
27
+ return createSelectionStore(ids);
28
+ }, [assembly]);
29
+
30
+ const selectedIds = selectionStore((s) => s.selectedIds);
31
+ const getTrackIds = selectionStore((s) => s.getTrackIds);
32
+
33
+ // Get only real track IDs (no auto-generated group IDs)
34
+ const trackIds = useMemo(() => getTrackIds(), [selectedIds, getTrackIds]);
35
+
36
+ useEffect(() => {
37
+ setLocalStorage(trackIds, assembly);
38
+ }, [assembly, trackIds]);
39
+
40
+ return <TrackSelect store={selectionStore} />;
8
41
  }
9
42
 
10
43
  createRoot(document.getElementById("root")!).render(<Main />);