@knaw-huc/osd-iiif-viewer 0.2.1 → 0.2.2
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/index.js
CHANGED
|
@@ -1797,10 +1797,14 @@ const defaultState$1 = {
|
|
|
1797
1797
|
setRotation: (rotation) => set({ rotation }),
|
|
1798
1798
|
reset: () => set(defaultState)
|
|
1799
1799
|
});
|
|
1800
|
-
function findCanvasIndex(vault,
|
|
1801
|
-
return vault.get({ id:
|
|
1800
|
+
function findCanvasIndex(vault, manifestId, canvasId) {
|
|
1801
|
+
return vault.get({ id: manifestId, type: "Manifest" }).items.findIndex((item) => vault.get(item).id === canvasId);
|
|
1802
|
+
}
|
|
1803
|
+
function orThrow(msg) {
|
|
1804
|
+
throw new Error(msg);
|
|
1802
1805
|
}
|
|
1803
1806
|
const defaultManifest = {
|
|
1807
|
+
id: null,
|
|
1804
1808
|
url: null,
|
|
1805
1809
|
isLoading: !1,
|
|
1806
1810
|
isReady: !1,
|
|
@@ -1811,10 +1815,14 @@ const defaultManifest = {
|
|
|
1811
1815
|
loadManifest: async (url, initialCanvasId) => {
|
|
1812
1816
|
set({ url, isLoading: !0, error: null });
|
|
1813
1817
|
try {
|
|
1814
|
-
await vault.loadManifest(url)
|
|
1815
|
-
|
|
1818
|
+
const id = (await vault.loadManifest(url))?.id || orThrow("No manifest"), updates = {
|
|
1819
|
+
id,
|
|
1820
|
+
url,
|
|
1821
|
+
isLoading: !1,
|
|
1822
|
+
error: null
|
|
1823
|
+
};
|
|
1816
1824
|
if (initialCanvasId) {
|
|
1817
|
-
const index = findCanvasIndex(vault,
|
|
1825
|
+
const index = findCanvasIndex(vault, id, initialCanvasId);
|
|
1818
1826
|
index !== -1 && (updates.currentIndex = index);
|
|
1819
1827
|
}
|
|
1820
1828
|
set(updates);
|
|
@@ -1829,17 +1837,17 @@ const defaultManifest = {
|
|
|
1829
1837
|
}, createCanvasSlice = (set, get) => ({
|
|
1830
1838
|
...defaultCanvas,
|
|
1831
1839
|
goToCanvas: (index) => {
|
|
1832
|
-
const { vault,
|
|
1833
|
-
if (!
|
|
1840
|
+
const { vault, id: manifestId } = get();
|
|
1841
|
+
if (!manifestId)
|
|
1834
1842
|
return;
|
|
1835
|
-
const manifest = vault.get({ id:
|
|
1843
|
+
const manifest = vault.get({ id: manifestId, type: "Manifest" }), clamped = Math.max(0, Math.min(index, manifest.items.length - 1));
|
|
1836
1844
|
set({ currentIndex: clamped });
|
|
1837
1845
|
},
|
|
1838
1846
|
goToCanvasById: (id) => {
|
|
1839
|
-
const { vault,
|
|
1840
|
-
if (!
|
|
1847
|
+
const { vault, id: manifestId, goToCanvas } = get();
|
|
1848
|
+
if (!manifestId)
|
|
1841
1849
|
return;
|
|
1842
|
-
const index = findCanvasIndex(vault,
|
|
1850
|
+
const index = findCanvasIndex(vault, manifestId, id);
|
|
1843
1851
|
if (index === -1) {
|
|
1844
1852
|
console.warn(`Canvas not found: ${id}`);
|
|
1845
1853
|
return;
|
|
@@ -1871,9 +1879,6 @@ const defaultManifest = {
|
|
|
1871
1879
|
};
|
|
1872
1880
|
});
|
|
1873
1881
|
}, ViewerContext = createContext(null);
|
|
1874
|
-
function orThrow(msg) {
|
|
1875
|
-
throw new Error(msg);
|
|
1876
|
-
}
|
|
1877
1882
|
function useViewerStore() {
|
|
1878
1883
|
return useContext(ViewerContext) ?? orThrow("viewer hook must be used within viewer provider");
|
|
1879
1884
|
}
|
|
@@ -1968,12 +1973,12 @@ function useViewerStoreSelector(selector) {
|
|
|
1968
1973
|
return useStore(store, selector);
|
|
1969
1974
|
}
|
|
1970
1975
|
function useCanvas() {
|
|
1971
|
-
const vault = useViewerStoreSelector((s2) => s2.vault),
|
|
1972
|
-
if (!
|
|
1976
|
+
const vault = useViewerStoreSelector((s2) => s2.vault), id = useViewerStoreSelector((s2) => s2.id), isLoading = useViewerStoreSelector((s2) => s2.isLoading), currentIndex = useViewerStoreSelector((s2) => s2.currentIndex), goTo = useViewerStoreSelector((s2) => s2.goToCanvas), goToById = useViewerStoreSelector((s2) => s2.goToCanvasById), next = useViewerStoreSelector((s2) => s2.nextCanvas), prev = useViewerStoreSelector((s2) => s2.prevCanvas), { current, total } = useMemo(() => {
|
|
1977
|
+
if (!id || isLoading)
|
|
1973
1978
|
return { current: null, total: 0 };
|
|
1974
|
-
const manifest = vault.get({ id
|
|
1979
|
+
const manifest = vault.get({ id, type: "Manifest" }), canvasRef = manifest.items[currentIndex] ?? orThrow("No canvas ref for " + currentIndex), current2 = vault.get(canvasRef), total2 = manifest.items.length;
|
|
1975
1980
|
return { current: current2, total: total2 };
|
|
1976
|
-
}, [vault,
|
|
1981
|
+
}, [vault, id, isLoading, currentIndex]), currentCanvasId = current?.id ?? null;
|
|
1977
1982
|
return {
|
|
1978
1983
|
currentIndex,
|
|
1979
1984
|
currentCanvasId,
|
|
@@ -1986,8 +1991,8 @@ function useCanvas() {
|
|
|
1986
1991
|
};
|
|
1987
1992
|
}
|
|
1988
1993
|
function useManifest() {
|
|
1989
|
-
const vault = useViewerStoreSelector((s2) => s2.vault), url = useViewerStoreSelector((s2) => s2.url), isLoading = useViewerStoreSelector((s2) => s2.isLoading), error = useViewerStoreSelector((s2) => s2.error), loadManifest = useViewerStoreSelector((s2) => s2.loadManifest);
|
|
1990
|
-
return { vault, url, isLoading, error, isReady: !!url && !isLoading && !error, loadManifest };
|
|
1994
|
+
const vault = useViewerStoreSelector((s2) => s2.vault), id = useViewerStoreSelector((s2) => s2.id), url = useViewerStoreSelector((s2) => s2.url), isLoading = useViewerStoreSelector((s2) => s2.isLoading), error = useViewerStoreSelector((s2) => s2.error), loadManifest = useViewerStoreSelector((s2) => s2.loadManifest);
|
|
1995
|
+
return { vault, id, url, isLoading, error, isReady: !!url && !isLoading && !error, loadManifest };
|
|
1991
1996
|
}
|
|
1992
1997
|
function useLoadManifest() {
|
|
1993
1998
|
return useViewerStoreSelector((s2) => s2.loadManifest);
|
|
@@ -2085,23 +2090,23 @@ function useImageInfo() {
|
|
|
2085
2090
|
}, [viewer, ready]);
|
|
2086
2091
|
}
|
|
2087
2092
|
function Overlay({ location, children }) {
|
|
2088
|
-
const viewer = useViewer(), [
|
|
2089
|
-
const
|
|
2090
|
-
return
|
|
2093
|
+
const viewer = useViewer(), [overlay] = useState(() => {
|
|
2094
|
+
const div = document.createElement("div");
|
|
2095
|
+
return div.style.position = "absolute", div.style.pointerEvents = "none", div;
|
|
2091
2096
|
});
|
|
2092
2097
|
return useEffect(() => {
|
|
2093
|
-
function stopPropagation(
|
|
2094
|
-
|
|
2098
|
+
function stopPropagation(event) {
|
|
2099
|
+
event.target !== overlay && event.stopPropagation();
|
|
2095
2100
|
}
|
|
2096
|
-
return
|
|
2097
|
-
|
|
2101
|
+
return overlay.addEventListener("pointerdown", stopPropagation), () => {
|
|
2102
|
+
overlay.removeEventListener("pointerdown", stopPropagation);
|
|
2098
2103
|
};
|
|
2099
|
-
}, [
|
|
2104
|
+
}, [overlay]), useEffect(() => {
|
|
2100
2105
|
if (viewer)
|
|
2101
|
-
return viewer.addOverlay({ element:
|
|
2102
|
-
viewer.isOpen() && viewer.removeOverlay(
|
|
2106
|
+
return viewer.addOverlay({ element: overlay, location }), () => {
|
|
2107
|
+
viewer.isOpen() && viewer.removeOverlay(overlay);
|
|
2103
2108
|
};
|
|
2104
|
-
}, [viewer, location,
|
|
2109
|
+
}, [viewer, location, overlay]), viewer ? createPortal(children, overlay) : null;
|
|
2105
2110
|
}
|
|
2106
2111
|
function ViewerProvider({ children }) {
|
|
2107
2112
|
const [store] = useState(() => createViewerStore());
|
|
@@ -1,2 +1,2 @@
|
|
|
1
1
|
import { Vault } from '@iiif/helpers/vault';
|
|
2
|
-
export declare function findCanvasIndex(vault: Vault,
|
|
2
|
+
export declare function findCanvasIndex(vault: Vault, manifestId: string, canvasId: string): number;
|