@knaw-huc/osd-iiif-viewer 0.1.11 → 0.2.0
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/Viewer.d.ts +3 -2
- package/dist/index.js +24 -9
- package/dist/useStableProp.d.ts +1 -0
- package/package.json +1 -1
package/dist/Viewer.d.ts
CHANGED
|
@@ -1,5 +1,6 @@
|
|
|
1
|
+
import { Options as OsdOptions } from 'openseadragon';
|
|
1
2
|
type ViewerProps = {
|
|
2
|
-
|
|
3
|
+
options?: Partial<OsdOptions>;
|
|
3
4
|
};
|
|
4
|
-
export declare function Viewer(
|
|
5
|
+
export declare function Viewer(props: ViewerProps): import("react/jsx-runtime").JSX.Element;
|
|
5
6
|
export {};
|
package/dist/index.js
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
import { jsx } from "react/jsx-runtime";
|
|
2
2
|
import { Viewer as Viewer$1 } from "openseadragon";
|
|
3
|
-
import { createContext, useContext, useMemo, useRef, useEffect,
|
|
3
|
+
import { createContext, useContext, useMemo, useState, useRef, useEffect, useCallback } from "react";
|
|
4
4
|
import { createStore } from "zustand/vanilla";
|
|
5
5
|
import { useStore } from "zustand/index";
|
|
6
6
|
import { createPortal } from "react-dom";
|
|
@@ -1955,17 +1955,25 @@ function useManifest() {
|
|
|
1955
1955
|
function useLoadManifest() {
|
|
1956
1956
|
return useViewerStoreSelector((s2) => s2.loadManifest);
|
|
1957
1957
|
}
|
|
1958
|
-
function
|
|
1959
|
-
const
|
|
1960
|
-
|
|
1958
|
+
function useStableProp(options) {
|
|
1959
|
+
const [stable, setStable] = useState(options), [key, setKey] = useState(() => JSON.stringify(options)), json = JSON.stringify(options);
|
|
1960
|
+
return json !== key && (setKey(json), setStable(options)), stable;
|
|
1961
|
+
}
|
|
1962
|
+
const defaultOptions = {
|
|
1963
|
+
prefixUrl: "https://openseadragon.github.io/openseadragon/images/",
|
|
1964
|
+
crossOriginPolicy: "Anonymous",
|
|
1965
|
+
showNavigationControl: !0
|
|
1966
|
+
};
|
|
1967
|
+
function Viewer(props) {
|
|
1968
|
+
const containerRef = useRef(null), store = useViewerStore(), { vault } = useManifest(), { current } = useCanvas(), tileSource = current ? findTileSource(vault, current) : null, size = useContainerSize(containerRef), isContainerReady = size.width > 0 && size.height > 0, options = useStableProp(props.options);
|
|
1969
|
+
useEffect(createOsdViewer, [isContainerReady, store, options]);
|
|
1961
1970
|
function createOsdViewer() {
|
|
1962
1971
|
if (!containerRef.current || !isContainerReady)
|
|
1963
1972
|
return;
|
|
1964
1973
|
const viewer = new Viewer$1({
|
|
1965
|
-
|
|
1966
|
-
|
|
1967
|
-
|
|
1968
|
-
showNavigationControl: showControls
|
|
1974
|
+
...defaultOptions,
|
|
1975
|
+
...options,
|
|
1976
|
+
element: containerRef.current
|
|
1969
1977
|
});
|
|
1970
1978
|
store.getState().setViewer(viewer), viewer.addHandler("open", () => {
|
|
1971
1979
|
const state2 = store.getState();
|
|
@@ -2045,9 +2053,16 @@ function Overlay({ location, children }) {
|
|
|
2045
2053
|
return el.style.position = "absolute", el.style.pointerEvents = "none", el;
|
|
2046
2054
|
});
|
|
2047
2055
|
return useEffect(() => {
|
|
2056
|
+
function stopPropagation(e2) {
|
|
2057
|
+
e2.target !== container && e2.stopPropagation();
|
|
2058
|
+
}
|
|
2059
|
+
return container.addEventListener("pointerdown", stopPropagation), () => {
|
|
2060
|
+
container.removeEventListener("pointerdown", stopPropagation);
|
|
2061
|
+
};
|
|
2062
|
+
}, [container]), useEffect(() => {
|
|
2048
2063
|
if (viewer)
|
|
2049
2064
|
return viewer.addOverlay({ element: container, location }), () => {
|
|
2050
|
-
viewer.removeOverlay(container);
|
|
2065
|
+
viewer.isOpen() && viewer.removeOverlay(container);
|
|
2051
2066
|
};
|
|
2052
2067
|
}, [viewer, location, container]), viewer ? createPortal(children, container) : null;
|
|
2053
2068
|
}
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
export declare function useStableProp<T>(options: T): T;
|