Skip to content
Snippets Groups Projects
Select Git revision
  • 21e53d9f36e6eac3bcdeaccaa12068dae4f8dab0
  • mui5-annotation-on-video-stable default
  • get_setter_canvasSizeInformations
  • fix-error-div-into-p
  • annotation-on-video-v2
  • detached
  • annotation-on-video-r17
  • mui5
  • mui5-react-18
  • jacob-test
  • annotation-on-video protected
  • master
  • test-antoinev1
  • 20-fetch-thumbnail-on-annotation
  • add-research-field
  • Save
  • add-plugin
  • 14-wip-no-seek-to
  • 14-bug-on-video-time-control
  • 9_wip_videotests
  • _upgrade_material_ui
  • latest-tetras-16
  • v3.3.0
  • v3.2.0
  • v3.1.1
  • v3.1.0
  • v3.0.0
  • v3.0.0-rc.7
  • v3.0.0-rc.6
  • v3.0.0-rc.5
  • v3.0.0-rc.4
  • v3.0.0-rc.3
  • v3.0.0-rc.2
  • v3.0.0-rc.1
  • v3.0.0-beta.10
  • v3.0.0-beta.9
  • v3.0.0-beta.8
  • v3.0.0-beta.7
  • v3.0.0-beta.6
  • v3.0.0-beta.5
  • v3.0.0-beta.3
41 results

windows.js

Blame
  • windows.js 2.81 KiB
    import { createSelector } from 'reselect';
    import {
      getManifestTitle,
      getManifestBehaviors,
      getManifestViewingHint,
      getManifestoInstance,
    } from './manifests';
    import { getDefaultView } from './config';
    import { getWorkspaceType } from './workspace';
    
    /**
     * Return the manifest titles for all open windows
     * @param {object} state
     * @return {object}
     */
    export function getWindowTitles(state) {
      const result = {};
    
      Object.keys(getWindows(state)).forEach((windowId) => {
        result[windowId] = getManifestTitle(state, { windowId });
      });
    
      return result;
    }
    
    /**
     * Return the manifest titles for all open windows
     * @param {object} state
     * @return {object}
     */
    export function getWindowManifests(state) {
      return Object.values(state.windows).map(window => window.manifestId);
    }
    
    /** */
    export function getWindows(state) {
      return state.windows || {};
    }
    
    /** */
    export const getWindowIds = createSelector(
      [getWindows],
      windows => Object.keys(windows),
    );
    
    /** */
    export const getMaximizedWindowsIds = createSelector(
      [getWindows],
      windows => Object.values(windows)
        .filter(window => window.maximized === true)
        .map(window => window.id),
    );
    
    /** */
    export function getWindow(state, { windowId }) {
      return getWindows(state)[windowId];
    }
    
    /** Return the canvas index for a certain window.
    * @param {object} state
    * @param {String} windowId
    * @param {Number}
    */
    export const getCanvasIndex = createSelector(
      [
        getWindow,
        getManifestoInstance,
      ],
      (window, manifest) => (
        (manifest && window && window.canvasId
          && manifest.getSequences()[0].getCanvasById(window.canvasId))
        || {}).index || 0,
    );
    
    /** Return type of view in a certain window.
    * @param {object} state
    * @param {object} props
    * @param {string} props.manifestId
    * @param {string} props.windowId
    * @param {String}
    */
    export const getWindowViewType = createSelector(
      [
        getWindow,
        getManifestViewingHint,
        getManifestBehaviors,
        getDefaultView,
      ],
      (window, manifestViewingHint, manifestBehaviors, defaultView) => {
        const lookup = {
          individuals: 'single',
          paged: 'book',
        };
        return (window && window.view)
          || lookup[manifestBehaviors.find(b => lookup[b]) || manifestViewingHint]
          || defaultView;
      },
    );
    
    export const getViewer = createSelector(
      [
        state => state.viewers,
        (state, { windowId }) => windowId,
      ],
      (viewers, windowId) => viewers[windowId],
    );
    
    /**
     * Returns the draggability of a window
     * @param {object} state
     * @param {object} props
     * @return {Boolean}
     */
    export const getWindowDraggability = createSelector(
      [
        getWorkspaceType,
        getWindow,
        state => Object.keys(state.windows).length > 1,
      ],
      (workspaceType, window, manyWindows) => {
        if (workspaceType === 'elastic') return true;
        return manyWindows && window && window.maximized === false;
      },
    );