Skip to content

Commit

Permalink
Small updates + README
Browse files Browse the repository at this point in the history
  • Loading branch information
stephenwf committed Feb 14, 2024
1 parent 7e3f002 commit 800f523
Show file tree
Hide file tree
Showing 9 changed files with 528 additions and 213 deletions.
672 changes: 495 additions & 177 deletions README.md

Large diffs are not rendered by default.

Binary file added images/canvas-panel.jpg
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Binary file added images/metadata.jpg
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Binary file added images/sequence.jpg
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
44 changes: 15 additions & 29 deletions src/canvas-panel/index.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -10,8 +10,6 @@ import { VaultProvider } from '../context/VaultContext';
import { useManifest } from '../hooks/useManifest';
import { useVisibleCanvases } from '../context/VisibleCanvasContext';
import { CanvasContext } from '../context/CanvasContext';
import { ViewerControls } from '../demo/viewer-controls';
import { MediaControls } from '../demo/media-controls';
import { useExistingVault } from '../hooks/useExistingVault';
import { SimpleViewerContext } from '../viewers/SimpleViewerContext.types';
import { Audio, AudioHTML } from './render/Audio';
Expand Down Expand Up @@ -42,20 +40,19 @@ interface CanvasPanelProps {
annotations?: ReactNode;
}

const Inner = forwardRef(function Inner(
props: {
height?: number;
canvasProps?: CanvasPanelProps['canvasProps'];
spacing?: number;
components?: CanvasPanelProps['components'];
children?: ReactNode;
annotations?: ReactNode;
header?: ReactNode;
reuseAtlas?: boolean;
mode?: ViewerMode;
},
ref
) {
interface InnerProps {
height?: number;
canvasProps?: CanvasPanelProps['canvasProps'];
spacing?: number;
components?: CanvasPanelProps['components'];
children?: ReactNode;
annotations?: ReactNode;
header?: ReactNode;
reuseAtlas?: boolean;
mode?: ViewerMode;
}

const Inner = forwardRef<SimpleViewerContext, InnerProps>(function Inner(props, ref) {
const manifest = useManifest();
const canvases = useVisibleCanvases();
const viewer = useSimpleViewer();
Expand Down Expand Up @@ -116,19 +113,8 @@ type CanvasPanelType = ForwardRefExoticComponent<CanvasPanelProps & RefAttribute
ModelHTML: typeof ModelHTML;
};

export const CanvasPanel = forwardRef(function CanvasPanel(
{
children,
height,
annotations,
canvasProps,
spacing,
header,
components,
mode,
reuseAtlas,
...props
}: CanvasPanelProps,
export const CanvasPanel = forwardRef<SimpleViewerContext, CanvasPanelProps>(function CanvasPanel(
{ children, height, annotations, canvasProps, spacing, header, components, mode, reuseAtlas, ...props },
ref
) {
const vault = useExistingVault();
Expand Down
8 changes: 6 additions & 2 deletions src/hooks/useExistingVault.ts
Original file line number Diff line number Diff line change
@@ -1,9 +1,13 @@
import { globalVault } from '@iiif/helpers/vault';
import { globalVault, Vault } from '@iiif/helpers/vault';
import { useContext } from 'react';
import { ReactVaultContext } from '../context/VaultContext';

export function useExistingVault() {
export function useExistingVault(vault?: Vault): Vault {
const oldContext: any = useContext(ReactVaultContext);

if (vault) {
return vault;
}

return oldContext && oldContext.vault ? (oldContext.vault as any) : globalVault();
}
4 changes: 2 additions & 2 deletions src/hooks/useExternalResource.ts
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
import { useVault } from './useVault';
import { useExistingVault } from './useExistingVault';
import { useEffect, useMemo, useState } from 'react';

export type ResourceRequestOptions = {
Expand All @@ -17,7 +17,7 @@ export function useExternalResource<T extends { id: string }>(
resource?: T;
} {
const id = typeof idOrRef === 'string' ? idOrRef : idOrRef.id;
const vault = useVault();
const vault = useExistingVault();
const [realId, setRealId] = useState(id);
const [error, setError] = useState<Error | undefined>(undefined);
const initialData = useMemo(() => {
Expand Down
11 changes: 8 additions & 3 deletions src/viewers/SimpleViewerContext.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -71,6 +71,8 @@ import { useManifest } from '../hooks/useManifest';
import { SimpleViewerContext, SimpleViewerProps } from './SimpleViewerContext.types';
import { RangeContext } from '../context/RangeContext';
import { useCanvasSequence } from './SimpleViewerContext.hooks';
import { VaultProvider } from '../context/VaultContext';
import { useExistingVault } from '../hooks/useExistingVault';

const noop = () => {
//
Expand Down Expand Up @@ -146,6 +148,7 @@ export function InnerViewerProvider(props: SimpleViewerProps) {
}

export function SimpleViewerProvider(props: SimpleViewerProps) {
const vault = useExistingVault(props.vault);
const manifest = useExternalManifest(props.manifest);

if (!manifest) {
Expand All @@ -164,9 +167,11 @@ export function SimpleViewerProvider(props: SimpleViewerProps) {
const inner = <InnerViewerProvider {...props}>{props.children}</InnerViewerProvider>;

return (
<ManifestContext manifest={manifest.id}>
{props.rangeId ? <RangeContext range={props.rangeId}>{inner}</RangeContext> : inner}
</ManifestContext>
<VaultProvider vault={vault}>
<ManifestContext manifest={manifest.id}>
{props.rangeId ? <RangeContext range={props.rangeId}>{inner}</RangeContext> : inner}
</ManifestContext>
</VaultProvider>
);
}

Expand Down
2 changes: 2 additions & 0 deletions src/viewers/SimpleViewerContext.types.ts
Original file line number Diff line number Diff line change
@@ -1,3 +1,4 @@
import { Vault } from '@iiif/helpers/vault';
import { Reference } from '@iiif/presentation-3';
import { ReactNode } from 'react';

Expand All @@ -15,6 +16,7 @@ export type SimpleViewerContext = {
};

export type SimpleViewerProps = {
vault?: Vault;
manifest: string;
pagingEnabled?: boolean;
children: ReactNode;
Expand Down

0 comments on commit 800f523

Please sign in to comment.