-
Notifications
You must be signed in to change notification settings - Fork 256
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Core mirador behaviors to provide a plugin target for text resources
- refactor type-based filters into a module - MiradorCanvas.imagesResources does not assume any service is an image service - stub TextViewer shows empty div, source elements for text resources, and canvas navigation - fixes #4085
- Loading branch information
Showing
14 changed files
with
364 additions
and
19 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,35 @@ | ||
{ | ||
"@context": "http://iiif.io/api/presentation/3/context.json", | ||
"id": "https://iiif.io/api/cookbook/recipe/0001-text-pdf/manifest.json", | ||
"type": "Manifest", | ||
"label": { | ||
"en": [ | ||
"Simplest Text Example 1" | ||
] | ||
}, | ||
"items": [ | ||
{ | ||
"id": "https://iiif.io/api/cookbook/recipe/0001-text-pdf/canvas", | ||
"type": "Canvas", | ||
"items": [ | ||
{ | ||
"id": "https://iiif.io/api/cookbook/recipe/0001-text-pdf/canvas/page", | ||
"type": "AnnotationPage", | ||
"items": [ | ||
{ | ||
"id": "https://iiif.io/api/cookbook/recipe/0001-text-pdf/canvas/page/annotation", | ||
"type": "Annotation", | ||
"motivation": "painting", | ||
"body": { | ||
"id": "https://fixtures.iiif.io/other/UCLA/kabuki_ezukushi_rtl.pdf", | ||
"type": "Text", | ||
"format": "application/pdf" | ||
}, | ||
"target": "https://iiif.io/api/cookbook/recipe/0001-text-pdf/canvas/page" | ||
} | ||
] | ||
} | ||
] | ||
} | ||
] | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,47 @@ | ||
import { render, screen } from '@tests/utils/test-utils'; | ||
import { TextViewer } from '../../../src/components/TextViewer'; | ||
|
||
/** create wrapper */ | ||
function createWrapper(props, suspenseFallback) { | ||
return render( | ||
<TextViewer | ||
classes={{}} | ||
textOptions={{ crossOrigin: 'anonymous', 'data-testid': 'text' }} | ||
{...props} | ||
/>, | ||
); | ||
} | ||
|
||
describe('TextViewer', () => { | ||
describe('render', () => { | ||
it('textResources as source elements', () => { | ||
createWrapper({ | ||
textResources: [ | ||
{ getFormat: () => 'application/pdf', getType: () => 'Text', id: 1 }, | ||
], | ||
windowId: 'a', | ||
}, true); | ||
const text = screen.getByTestId('text'); | ||
expect(text.querySelector('source:nth-of-type(1)')).toHaveAttribute('type', 'application/pdf'); // eslint-disable-line testing-library/no-node-access | ||
}); | ||
it('passes through configurable options', () => { | ||
createWrapper({ | ||
textResources: [ | ||
{ getFormat: () => 'application/pdf', getType: () => 'Text', id: 1 }, | ||
], | ||
windowId: 'a', | ||
}, true); | ||
expect(screen.getByTestId('text')).toHaveAttribute('crossOrigin', 'anonymous'); | ||
}); | ||
it('canvas navigation', () => { | ||
createWrapper({ | ||
textResources: [ | ||
{ getFormat: () => 'application/pdf', getType: () => 'Text', id: 1 }, | ||
], | ||
windowId: 'a', | ||
}, true); | ||
const text = screen.getByTestId('text'); | ||
expect(text.querySelector('.mirador-canvas-nav')).toBeDefined(); // eslint-disable-line testing-library/no-node-access | ||
}); | ||
}); | ||
}); |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,31 @@ | ||
import { Utils } from 'manifesto.js'; | ||
import flattenDeep from 'lodash/flattenDeep'; | ||
import manifestFixture019 from '../../fixtures/version-2/019.json'; | ||
import { | ||
filterByProfiles, filterByTypes, | ||
} from '../../../src/lib/resourceFilters'; | ||
|
||
describe('resourceFilters', () => { | ||
let canvas; | ||
beforeEach(() => { | ||
[canvas] = Utils.parseManifest(manifestFixture019).getSequences()[0].getCanvases(); | ||
}); | ||
describe('filterByProfiles', () => { | ||
it('filters resources', () => { | ||
const services = flattenDeep(canvas.resourceAnnotations.map((a) => a.getResource().getServices())); | ||
expect(filterByProfiles(services, 'http://iiif.io/api/image/2/level2.json').map((s) => s.id)).toEqual([ | ||
'https://stacks.stanford.edu/image/iiif/hg676jb4964%2F0380_796-44', | ||
]); | ||
expect(filterByProfiles(services, 'http://nonexistent.io/api/service.json').map((s) => s.id)).toEqual([]); | ||
}); | ||
}); | ||
describe('filterByTypes', () => { | ||
it('filters resources', () => { | ||
const resources = flattenDeep(canvas.resourceAnnotations.map((a) => a.getResource())); | ||
expect(filterByTypes(resources, 'dctypes:Image').map((r) => r.id)).toEqual([ | ||
'https://stacks.stanford.edu/image/iiif/hg676jb4964%2F0380_796-44/full/full/0/default.jpg', | ||
]); | ||
expect(filterByTypes(resources, 'Nonexistent').map((r) => r.id)).toEqual([]); | ||
}); | ||
}); | ||
}); |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,37 @@ | ||
import { styled } from '@mui/material/styles'; | ||
import PropTypes from 'prop-types'; | ||
import WindowCanvasNavigationControls from '../containers/WindowCanvasNavigationControls'; | ||
|
||
const StyledContainer = styled('div')(() => ({ | ||
alignItems: 'center', | ||
display: 'flex', | ||
width: '100%', | ||
})); | ||
|
||
const StyledText = styled('div')(() => ({ | ||
maxHeight: '100%', | ||
width: '100%', | ||
})); | ||
|
||
/** | ||
* Simple divs with canvas navigation, which should mimic v3 fallthrough to WindowViewer | ||
* with non-image resources and provide a target for plugin overrides with minimal disruption. | ||
*/ | ||
export function TextViewer({ textOptions = {}, textResources = [], windowId }) { | ||
return ( | ||
<StyledContainer> | ||
<StyledText {...textOptions}> | ||
{textResources.map(text => ( | ||
<source key={text.id} src={text.id} type={text.getFormat()} /> | ||
))} | ||
<WindowCanvasNavigationControls windowId={windowId} /> | ||
</StyledText> | ||
</StyledContainer> | ||
); | ||
} | ||
|
||
TextViewer.propTypes = { | ||
textOptions: PropTypes.object, // eslint-disable-line react/forbid-prop-types | ||
textResources: PropTypes.arrayOf(PropTypes.object), // eslint-disable-line react/forbid-prop-types | ||
windowId: PropTypes.string.isRequired, | ||
}; |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,19 @@ | ||
import { compose } from 'redux'; | ||
import { withPlugins } from '../extend/withPlugins'; | ||
import { TextViewer } from '../components/TextViewer'; | ||
|
||
/** */ | ||
const mapStateToProps = (state, { windowId }) => ( | ||
{ | ||
textOptions: getConfig(state).textOptions, | ||
textResources: getVisibleCanvasTextResources(state, { windowId }) || [], | ||
} | ||
); | ||
|
||
const enhance = compose( | ||
connect(mapStateToProps, null), | ||
withPlugins('TextViewer'), | ||
// further HOC go here | ||
); | ||
|
||
export default enhance(TextViewer); | ||
Oops, something went wrong.