@weng-lab/genomebrowser-ui 0.1.8 → 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/genomebrowser-ui.es.js +2 -1
- package/dist/lib.d.ts +4 -0
- package/package.json +1 -1
- package/src/lib.ts +6 -0
- package/test/main.tsx +35 -2
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
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
|
|
7
|
-
|
|
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 />);
|