Skip to content
Snippets Groups Projects
Select Git revision
  • 3890b8d6fd33fd251fcfadc2db682acda205972b
  • main default
  • 35-cgu
  • 34-peertube-support
  • 27-add-autoplay-to-iframe
  • 33-bug-on-youtube-embed-urls
  • RC-Rekall-v1.1-fix_lpo
  • tuleap-140-go-back-to-my-capsules-page-when-i-m-on-capsule-preview-page
  • RC-Rekall-v1.2-fix10
  • RC-Rekall-v1.2-fix9
  • RC-Rekall-v1.2-fix8
  • RC-Rekall-v1.2-fix7
  • RC-Rekall-v1.2-fix6
  • RC-Rekall-v1.2-fix5
  • RC-Rekall-v1.2-fix4
  • RC-Rekall-v1.2-fix3
  • RC-Rekall-v1.2-fix2
  • RC-Rekall-v1.2-fix1
  • RC-Rekall-v1.1-fix-3
  • RC-Rekall-v1.1-fix-2
  • RC-Rekall-v1.1-fix-1
  • RC-Rekall-v1.1-delivered
  • preprod20220209-1535
23 results

UnitTester.php

Blame
  • MiradorViewer.js 2.64 KiB
    import React from 'react';
    import ReactDOM from 'react-dom';
    import { Provider } from 'react-redux';
    import deepmerge from 'deepmerge';
    import App from '../containers/App';
    import createRootReducer from '../state/reducers/index';
    import createStore from '../state/createStore';
    import * as actions from '../state/actions';
    import settings from '../config/settings';
    
    /**
     * Default Mirador instantiation
     */
    class MiradorViewer {
      /**
       */
      constructor(config) {
        this.store = createStore();
        this.config = config;
        this.processPlugins();
        this.processConfig();
        const viewer = {
          actions,
          store: this.store,
        };
    
        ReactDOM.render(
          <Provider store={this.store}>
            <App config={config} />
          </Provider>,
          document.getElementById(config.id),
        );
    
        return viewer;
      }
    
      /**
       * Process config into actions
       */
      processConfig() {
        const mergedConfig = deepmerge(settings, this.config);
        const action = actions.setConfig(mergedConfig);
        this.store.dispatch(action);
    
        mergedConfig.windows.forEach((miradorWindow) => {
          let thumbnailNavigationPosition;
          if (miradorWindow.thumbnailNavigationPosition !== undefined) {
            ({ thumbnailNavigationPosition } = miradorWindow);
          } else {
            thumbnailNavigationPosition = mergedConfig.thumbnailNavigation.defaultPosition;
          }
          this.store.dispatch(actions.fetchManifest(miradorWindow.loadedManifest));
          this.store.dispatch(actions.addWindow({
            canvasIndex: (miradorWindow.canvasIndex || 0),
            manifestId: miradorWindow.loadedManifest,
            thumbnailNavigationPosition,
          }));
        });
      }
    
      /**
       * Process Plugins
       */
      processPlugins() {
        const plugins = this.config.plugins || [];
        const actionCreators = [];
        const reducers = [];
    
        plugins.forEach((pluginName) => {
          const plugin = window.Mirador.plugins[pluginName];
    
          // Add Actions
          if (plugin.actions) {
            Object.keys(plugin.actions)
              .forEach(actionName => actionCreators.push({
                name: actionName,
                action: plugin.actions[actionName],
              }));
          }
          // Add Reducers
          if (plugin.reducers) {
            Object.keys(plugin.reducers)
              .forEach(reducerName => reducers.push({
                name: reducerName,
                reducer: plugin.reducers[reducerName],
              }));
          }
        });
    
        actionCreators.forEach((action) => { actions[action.name] = action.action; });
        reducers.forEach((reducer) => { this.store.pluginReducers[reducer.name] = reducer.reducer; });
        this.store.replaceReducer(createRootReducer(this.store.pluginReducers));
      }
    }
    
    export default MiradorViewer;