From 2a362d2a2099980b25f4ee0c8771ca9b445ed00f Mon Sep 17 00:00:00 2001 From: Mat Jordan Date: Fri, 15 Nov 2024 09:36:06 -0500 Subject: [PATCH] Try moduleResolutio of `bundler`; update typescript defs. --- src/components/Image/Controls/Controls.tsx | 15 ++--- src/components/Scroll/Items/Item.tsx | 2 +- .../Viewer/InformationPanel/About/About.tsx | 57 ++++++++++++------- .../InformationPanel/Annotation/Item.tsx | 4 +- .../InformationPanel/ContentSearch/Item.tsx | 4 +- .../InformationPanel/InformationPanel.tsx | 4 +- src/components/Viewer/Viewer/Viewer.tsx | 20 +++---- src/components/Viewer/index.tsx | 2 +- src/context/scroll-context.tsx | 5 +- tsconfig.json | 2 +- 10 files changed, 66 insertions(+), 49 deletions(-) diff --git a/src/components/Image/Controls/Controls.tsx b/src/components/Image/Controls/Controls.tsx index 171c711f..5007066a 100644 --- a/src/components/Image/Controls/Controls.tsx +++ b/src/components/Image/Controls/Controls.tsx @@ -1,13 +1,14 @@ -import Button from "src/components/Image/Controls/Button"; -import { Options } from "openseadragon"; -import React from "react"; -import { Wrapper } from "src/components/Image/Controls/Controls.styled"; import { ViewerContextStore, - useViewerState, useViewerDispatch, + useViewerState, } from "src/context/viewer-context"; + +import Button from "src/components/Image/Controls/Button"; import { CanvasNormalized } from "@iiif/presentation-3"; +import { Options } from "openseadragon"; +import React from "react"; +import { Wrapper } from "src/components/Image/Controls/Controls.styled"; const ZoomIn = () => { return ( @@ -75,10 +76,10 @@ const Controls = ({ const viewerState: ViewerContextStore = useViewerState(); const { activeCanvas, plugins, vault } = viewerState; - const canvas: CanvasNormalized = vault.get({ + const canvas = vault.get({ id: activeCanvas, type: "Canvas", - }); + }) as CanvasNormalized; function renderPlugins() { return plugins diff --git a/src/components/Scroll/Items/Item.tsx b/src/components/Scroll/Items/Item.tsx index 99657c4d..b1957c78 100644 --- a/src/components/Scroll/Items/Item.tsx +++ b/src/components/Scroll/Items/Item.tsx @@ -36,7 +36,7 @@ const ScrollItem: React.FC = ({ const { state } = React.useContext(ScrollContext); const { annotations, vault } = state; - const canvas: CanvasNormalized | undefined = vault?.get(item); + const canvas = vault?.get(item) as CanvasNormalized; const annotationBody = annotations ?.filter((annotation) => annotation.target === item.id) diff --git a/src/components/Viewer/InformationPanel/About/About.tsx b/src/components/Viewer/InformationPanel/About/About.tsx index 0e96a969..68ff9fe8 100644 --- a/src/components/Viewer/InformationPanel/About/About.tsx +++ b/src/components/Viewer/InformationPanel/About/About.tsx @@ -2,6 +2,11 @@ import { AboutContent, AboutStyled, } from "src/components/Viewer/InformationPanel/About/About.styled"; +import { + ContentResource, + IIIFExternalWebResource, + ManifestNormalized, +} from "@iiif/presentation-3"; import { Homepage, Id, @@ -13,10 +18,6 @@ import { Summary, Thumbnail, } from "src/components/Viewer/Properties"; -import { - IIIFExternalWebResource, - ManifestNormalized, -} from "@iiif/presentation-3"; import React, { useEffect, useState } from "react"; import { ViewerContextStore, useViewerState } from "src/context/viewer-context"; @@ -28,19 +29,41 @@ const About: React.FC = () => { const [manifest, setManifest] = useState(); - const [homepage, setHomepage] = useState([]); - const [seeAlso, setSeeAlso] = useState([]); - const [rendering, setRendering] = useState([]); + const [homepage, setHomepage] = useState([]); + const [seeAlso, setSeeAlso] = useState([]); + const [rendering, setRendering] = useState( + [], + ); const [thumbnail, setThumbnail] = useState([]); useEffect(() => { const data: ManifestNormalized = vault.get(activeManifest); setManifest(data); - if (data.homepage?.length > 0) setHomepage(vault.get(data.homepage)); - if (data.seeAlso?.length > 0) setSeeAlso(vault.get(data.seeAlso)); - if (data.rendering?.length > 0) setRendering(vault.get(data.rendering)); - if (data.thumbnail?.length > 0) setThumbnail(vault.get(data.thumbnail)); + if (data.homepage?.length > 0) + setHomepage( + vault.get( + data.homepage, + ) as ContentResource[] as PrimitivesExternalWebResource[], + ); + if (data.seeAlso?.length > 0) + setSeeAlso( + vault.get( + data.seeAlso, + ) as ContentResource[] as PrimitivesExternalWebResource[], + ); + if (data.rendering?.length > 0) + setRendering( + vault.get( + data.rendering, + ) as ContentResource[] as PrimitivesExternalWebResource[], + ); + if (data.thumbnail?.length > 0) + setThumbnail( + vault.get( + data.thumbnail, + ) as ContentResource[] as IIIFExternalWebResource[], + ); }, [activeManifest, vault]); if (!manifest) return <>; @@ -53,15 +76,9 @@ const About: React.FC = () => { - - - + + + diff --git a/src/components/Viewer/InformationPanel/Annotation/Item.tsx b/src/components/Viewer/InformationPanel/Annotation/Item.tsx index 1a660dc2..9c69350e 100644 --- a/src/components/Viewer/InformationPanel/Annotation/Item.tsx +++ b/src/components/Viewer/InformationPanel/Annotation/Item.tsx @@ -36,10 +36,10 @@ export const AnnotationItem: React.FC = ({ annotation }) => { const annotationBodyValue = annotationBody.find((body) => body.value)?.value || ""; - const canvas: CanvasNormalized = vault.get({ + const canvas = vault.get({ id: activeCanvas, type: "Canvas", - }); + }) as CanvasNormalized; function handleClick() { if (!target) return; diff --git a/src/components/Viewer/InformationPanel/ContentSearch/Item.tsx b/src/components/Viewer/InformationPanel/ContentSearch/Item.tsx index a6b43732..7e467f48 100644 --- a/src/components/Viewer/InformationPanel/ContentSearch/Item.tsx +++ b/src/components/Viewer/InformationPanel/ContentSearch/Item.tsx @@ -40,10 +40,10 @@ export const ContentSearchItem: React.FC = ({ OSDImageLoaded, } = viewerState; - const canvas: CanvasNormalized = vault.get({ + const canvas = vault.get({ id: activeCanvas, type: "Canvas", - }); + }) as CanvasNormalized; const annotationBody: Array< EmbeddedResource & { diff --git a/src/components/Viewer/InformationPanel/InformationPanel.tsx b/src/components/Viewer/InformationPanel/InformationPanel.tsx index 4332aa92..cd4ee70e 100644 --- a/src/components/Viewer/InformationPanel/InformationPanel.tsx +++ b/src/components/Viewer/InformationPanel/InformationPanel.tsx @@ -59,10 +59,10 @@ export const InformationPanel: React.FC = ({ const renderAbout = informationPanel?.renderAbout; const renderAnnotation = informationPanel?.renderAnnotation; - const canvas: CanvasNormalized = vault.get({ + const canvas = vault.get({ id: activeCanvas, type: "Canvas", - }); + }) as CanvasNormalized; const renderContentSearch = informationPanel?.renderContentSearch; diff --git a/src/components/Viewer/Viewer/Viewer.tsx b/src/components/Viewer/Viewer/Viewer.tsx index f26dd667..e07f1b55 100644 --- a/src/components/Viewer/Viewer/Viewer.tsx +++ b/src/components/Viewer/Viewer/Viewer.tsx @@ -1,10 +1,11 @@ import * as Collapsible from "@radix-ui/react-collapsible"; +import { AnnotationResource, AnnotationResources } from "src/types/annotations"; import { + CanvasNormalized, ExternalResourceTypes, InternationalString, ManifestNormalized, - CanvasNormalized, } from "@iiif/presentation-3"; import React, { useCallback, useEffect, useState } from "react"; import { @@ -12,17 +13,17 @@ import { useViewerDispatch, useViewerState, } from "src/context/viewer-context"; -import { - getAnnotationResources, - getPaintingResource, - getContentSearchResources, -} from "src/hooks/use-iiif"; import { addContentSearchOverlays, removeOverlaysFromViewer, } from "src/lib/openseadragon-helpers"; +import { + getAnnotationResources, + getContentSearchResources, + getPaintingResource, +} from "src/hooks/use-iiif"; -import { AnnotationResources, AnnotationResource } from "src/types/annotations"; +import { ContentSearchQuery } from "src/types/annotations"; import { ErrorBoundary } from "react-error-boundary"; import ErrorFallback from "src/components/UI/ErrorFallback/ErrorFallback"; import { IIIFExternalWebResource } from "@iiif/presentation-3"; @@ -32,7 +33,6 @@ import { Wrapper } from "src/components/Viewer/Viewer/Viewer.styled"; import { media } from "src/styles/stitches.config"; import { useBodyLocked } from "src/hooks/useBodyLocked"; import { useMediaQuery } from "src/hooks/useMediaQuery"; -import { ContentSearchQuery } from "src/types/annotations"; interface ViewerProps { manifest: ManifestNormalized; @@ -168,10 +168,10 @@ const Viewer: React.FC = ({ if (!openSeadragonViewer) return; if (!contentSearchResource) return; - const canvas: CanvasNormalized = vault.get({ + const canvas = vault.get({ id: activeCanvas, type: "Canvas", - }); + }) as CanvasNormalized; removeOverlaysFromViewer(openSeadragonViewer, "content-search-overlay"); addContentSearchOverlays( diff --git a/src/components/Viewer/index.tsx b/src/components/Viewer/index.tsx index 29e16a28..175aec43 100644 --- a/src/components/Viewer/index.tsx +++ b/src/components/Viewer/index.tsx @@ -125,7 +125,7 @@ const RenderViewer: React.FC = ({ useEffect(() => { if (activeManifest) vault - .loadManifest(activeManifest) + .load(activeManifest) .then((data: ManifestNormalized) => { setManifest(data); dispatch({ diff --git a/src/context/scroll-context.tsx b/src/context/scroll-context.tsx index f6fbe421..d4e12bdd 100644 --- a/src/context/scroll-context.tsx +++ b/src/context/scroll-context.tsx @@ -2,7 +2,6 @@ import { AnnotationNormalized, ManifestNormalized } from "@iiif/presentation-3"; import React, { Dispatch, createContext, useReducer } from "react"; import { Vault } from "@iiif/helpers/vault"; -import { Vault as VaultShape } from "@iiif/helpers/dist/index"; interface StateType { annotations?: AnnotationNormalized[]; @@ -11,7 +10,7 @@ interface StateType { options: { offset: number; }; - vault?: VaultShape; + vault?: Vault; } interface ActionType { @@ -61,7 +60,7 @@ interface ScrollProviderProps { options?: { offset?: number; }; - vault?: VaultShape; + vault?: Vault; } export const ScrollProvider: React.FC = (props) => { diff --git a/tsconfig.json b/tsconfig.json index 97c0a997..ed5da470 100644 --- a/tsconfig.json +++ b/tsconfig.json @@ -12,7 +12,7 @@ "jsx": "preserve", "lib": ["dom", "dom.iterable", "esnext"], "module": "ESNext", - "moduleResolution": "Node", + "moduleResolution": "bundler", "noEmit": false, "noEmitHelpers": true, "outDir": "dist",