-
Notifications
You must be signed in to change notification settings - Fork 257
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Improve Documentation Based on User Feedback #3932
Comments
Draft for 'Enhance plugin usage documentation.' Here's a step-by-step guide to creating and using plugins in Mirador 4, written in Markdown for easy documentation. Mirador 4 Plugin Creation and Usage GuideThis guide provides an overview of how to create, configure, and use plugins in Mirador 4 to customize and extend its functionality. Mirador 4 supports plugins to add new components, modify existing ones, and interact with its Redux-based state.
Introduction to Mirador PluginsMirador 4’s plugin system allows developers to extend and modify the viewer’s functionality by adding or wrapping existing components, managing the application state, and triggering custom behaviors. The plugins are structured as JavaScript objects that include specific properties to define what and how they interact with the Mirador environment. Setting Up Your Development EnvironmentTo start developing a plugin, ensure you have the following tools installed:
# Clone Mirador repository
git clone https://github.com/ProjectMirador/mirador.git
cd mirador
npm install
npm start Creating a Basic PluginA Mirador plugin requires several essential properties to interact with the viewer. Here’s a breakdown of each step in creating a basic plugin. 1. Define the Plugin StructureA plugin is a JavaScript object with properties like const MyFirstPlugin = {
target: 'WindowTopBarPluginArea',
mode: 'add',
component: MyPluginComponent,
};
2. Create the React ComponentYour plugin can include any custom React component. For example: import React from 'react';
const MyPluginComponent = () => (
<div>
<p>This is my first plugin component!</p>
</div>
); 3. Export the PluginOnce your plugin object and component are ready, export the plugin so it can be imported into Mirador’s main configuration. export default MyFirstPlugin; Configuring the Plugin in MiradorTo use the plugin, add it to Mirador's configuration when initializing the viewer. Here’s how to include the plugin during setup: import Mirador from 'mirador';
import MyFirstPlugin from './path/to/MyFirstPlugin';
const miradorConfig = {
id: 'mirador',
windows: [{
manifestId: 'https://iiif.harvardartmuseums.org/manifests/object/299843',
}],
plugins: [
MyFirstPlugin,
],
};
Mirador.viewer(miradorConfig); Here:
Advanced Plugin CapabilitiesMirador plugins support interaction with Redux for state management, enabling you to connect to the viewer's data or dispatch actions. 1. Mapping State and Dispatch to PropsUse const MyFirstPlugin = {
target: 'WindowTopBarPluginArea',
mode: 'add',
component: connect(mapStateToProps, mapDispatchToProps)(MyPluginComponent),
};
2. Example: Toggling a Plugin ComponentSuppose we want our plugin to toggle based on a Redux state change: const mapStateToProps = (state) => ({
isVisible: state.myPluginState.isVisible,
});
const mapDispatchToProps = (dispatch) => ({
toggleVisibility: () => dispatch({ type: 'TOGGLE_VISIBILITY' }),
});
const MyPluginComponent = ({ isVisible, toggleVisibility }) => (
<div>
{isVisible && <p>Plugin is visible!</p>}
<button onClick={toggleVisibility}>Toggle Visibility</button>
</div>
); Debugging and TestingWhile developing plugins, use the following tools and techniques for debugging:
Best Practices and Tips
ConclusionMirador plugins are powerful tools for customizing the viewer experience. By following these steps, you can create plugins that seamlessly integrate with the Mirador environment, offering flexibility and control over its functionality. This guide covers the basics of creating and configuring plugins in Mirador 4. For further details and advanced customization, refer to the official Mirador Plugin Documentation. |
Maybe something like this could be added to this section. 3 Reducer PluginThe plugin system allows for optional adding of actions and reducers. // define a plugin state
const myPluginDefaultState: {
id: 'default',
count: 0
}
// define some actions
const myPluginCountIncrement = createAction('myPluginCounter/increment')
const myPluginCountDecrement = createAction('myPluginCounter/decrement')
// create some plugin reducer
const myPluginReducer = createReducer(myPluginDefaultState) => {
(builder => {
builder.addCase(myPluginCountIncrement, (state, action) => {
state.count = state.count + 1
}
...
}
}
// Add the reducer to the Mirador Plugin. Later, the 'myCount' value will be accessible
// as a prop in the MyPlugin component, allowing you to access the current count state.
const myPlugin = {
component: MyPlugin,
target: 'Workspace',
mode: 'add',
reducers: {
myPluginState: myPluginReducer
},
mapStateToProps: (state) => ({
myCount: state.myPluginState.count
})
} |
Based on feedback gathered from our recent user survey, several areas of the Mirador documentation have been identified as needing improvement to enhance the user experience. The following key areas require updates:
1. Improve Documentation for Standalone Setup
2. Improve Documentation for Framework Integration
3. Enhance Plugin Usage Documentation
Additional Notes:
Tasks:
The text was updated successfully, but these errors were encountered: