forked from ProjectMirador/mirador
-
Notifications
You must be signed in to change notification settings - Fork 0
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Merge pull request ProjectMirador#4086 from cul/4085-text-viewer
Core mirador behaviors to provide a plugin target for text resources
- Loading branch information
Showing
11 changed files
with
243 additions
and
5 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
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
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,21 @@ | ||
import { compose } from 'redux'; | ||
import { connect } from 'react-redux'; | ||
import { withPlugins } from '../extend/withPlugins'; | ||
import { getConfig, getVisibleCanvasTextResources } from '../state/selectors'; | ||
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); |
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