From a2f21d0bde0e18d5faaa6416bcdbc2addc1ec2e6 Mon Sep 17 00:00:00 2001 From: Fabian Stoehr Date: Wed, 27 Sep 2023 14:42:35 +0200 Subject: [PATCH] added jsdocs for selectors --- src/state/selectors/annotations.js | 45 +++-- src/state/selectors/auth.js | 23 ++- src/state/selectors/canvases.js | 159 ++++++++++----- src/state/selectors/companionWindows.js | 100 ++++++---- src/state/selectors/config.js | 38 +++- src/state/selectors/getters.js | 58 +++++- src/state/selectors/layers.js | 25 ++- src/state/selectors/manifests.js | 251 ++++++++++++++---------- src/state/selectors/ranges.js | 41 +++- src/state/selectors/searches.js | 45 ++++- src/state/selectors/sequences.js | 42 ++-- src/state/selectors/utils.js | 2 +- src/state/selectors/viewer.js | 7 +- src/state/selectors/windows.js | 33 ++-- src/state/selectors/workspace.js | 25 ++- 15 files changed, 614 insertions(+), 280 deletions(-) diff --git a/src/state/selectors/annotations.js b/src/state/selectors/annotations.js index e48c1db489..c2554f0fb4 100644 --- a/src/state/selectors/annotations.js +++ b/src/state/selectors/annotations.js @@ -7,7 +7,11 @@ import { getCanvas, getVisibleCanvasIds } from './canvases'; import { getConfig } from './config'; import { getWindow } from './getters'; -/** */ +/** + * Returns the annotation object from the mirador slice. + * @param {object} state redux state + * @returns {object} Annotations from the state + */ export const getAnnotations = state => miradorSlice(state).annotations; const getMotivation = createSelector( @@ -60,6 +64,12 @@ const getAnnotationsOnSelectedCanvases = createSelector( }, ); +/** + * Returns an array of present annotations given a canvasId. + * @param {object} state redux state + * @param {string} canvasId canvasId + * @returns {Array} An array of present annotations + */ export const getPresentAnnotationsOnSelectedCanvases = createSelector( [ getAnnotationsOnSelectedCanvases, @@ -72,11 +82,11 @@ export const getPresentAnnotationsOnSelectedCanvases = createSelector( ); /** -* Return an array of annotation resources filtered by the given motivation for a particular canvas -* @param {Array} annotations -* @param {Array} motivations -* @return {Array} -*/ + * Returns an array of annotation resources filtered by the given motivation for a particular canvas. + * @param {Array} annotations + * @param {Array} motivations + * @returns {Array} + */ export const getAnnotationResourcesByMotivationForCanvas = createSelector( [ getPresentAnnotationsCanvas, @@ -91,11 +101,11 @@ export const getAnnotationResourcesByMotivationForCanvas = createSelector( ); /** -* Return an array of annotation resources filtered by the given motivation -* @param {Array} annotations -* @param {Array} motivations -* @return {Array} -*/ + * Returns an array of annotation resources filtered by the given motivation. + * @param {Array} annotations + * @param {Array} motivations + * @returns {Array} + */ export const getAnnotationResourcesByMotivation = createSelector( [ getPresentAnnotationsOnSelectedCanvases, @@ -110,11 +120,11 @@ export const getAnnotationResourcesByMotivation = createSelector( ); /** - * Return the selected annotations IDs of a given CanvasId - * @param {Object} state - * @param {String} windowId + * Returns the selected annotations IDs. + * @param {object} state + * @param {string} windowId * @param {Array} targetIds - * @return {Array} + * @returns {Array} */ export const getSelectedAnnotationId = createSelector( [ @@ -123,6 +133,11 @@ export const getSelectedAnnotationId = createSelector( ({ selectedAnnotationId }) => selectedAnnotationId, ); +/** + * Returns annotations on selected canvases. + * @param {object} state + * @returns {Array} + */ export const getSelectedAnnotationsOnCanvases = createSelector( [ getPresentAnnotationsOnSelectedCanvases, diff --git a/src/state/selectors/auth.js b/src/state/selectors/auth.js index 7c290bfca4..bd93f718bf 100644 --- a/src/state/selectors/auth.js +++ b/src/state/selectors/auth.js @@ -6,6 +6,11 @@ import { miradorSlice } from './utils'; import { getConfig } from './config'; import { getVisibleCanvases, selectInfoResponses } from './canvases'; +/** + * Returns the authentification profile from the configuration + * @param {object} state + * @returns {Array} + */ export const getAuthProfiles = createSelector( [ getConfig, @@ -13,12 +18,26 @@ export const getAuthProfiles = createSelector( ({ auth: { serviceProfiles = [] } = {} }) => serviceProfiles, ); -/** */ +/** + * Returns access tokens from the state + * @param {object} state + * @returns {object} + */ export const getAccessTokens = state => miradorSlice(state).accessTokens || {}; -/** */ +/** + * Return the authentification data from the state + * @param {object} state + * @returns {object} + */ export const getAuth = state => miradorSlice(state).auth || {}; +/** + * Returns current authentification services based on state and windowId + * @param {object} state + * @param {string} windowId + * @returns {Array} + */ export const selectCurrentAuthServices = createSelector( [ getVisibleCanvases, diff --git a/src/state/selectors/canvases.js b/src/state/selectors/canvases.js index 7cfa0c044c..f93daa8411 100644 --- a/src/state/selectors/canvases.js +++ b/src/state/selectors/canvases.js @@ -7,7 +7,11 @@ import { getWindow } from './getters'; import { getSequence } from './sequences'; import { getWindowViewType } from './windows'; -/** */ +/** + * Returns the info response. + * @param {object} state + * @returns {object} + */ export const selectInfoResponses = state => miradorSlice(state).infoResponses; export const getCanvases = createSelector( @@ -16,13 +20,12 @@ export const getCanvases = createSelector( ); /** -* Return the canvas selected by an id -* @param {object} state -* @param {object} props -* @param {string} props.manifestId -* @param {string} props.windowId -* @return {Object} -*/ + * Return the canvas selected by an id + * @param {object} state + * @param {object} props + * @param {string} props.canvasId + * @returns {object} + */ export const getCanvas = createSelector( [ getSequence, @@ -35,6 +38,13 @@ export const getCanvas = createSelector( }, ); +/** + * Returns the current canvas. + * @param {object} state + * @param {object} props + * @param {string} props.windowId + * @returns {object|undefined} + */ export const getCurrentCanvas = createSelector( [ getSequence, @@ -49,27 +59,39 @@ export const getCurrentCanvas = createSelector( }, ); -/** */ +/** + * Returns the visible canvas ids. + * @param {object} state + * @param {object} props + * @param {string} props.windowId + * @returns {Array} + */ export const getVisibleCanvasIds = createSelector( [getWindow], window => (window && (window.visibleCanvases || (window.canvasId && [window.canvasId]))) || [], ); -/** */ +/** + * Returns the visible canvses. + * @param {object} state + * @param {object} props + * @param {string} props.windowId + * @returns {Array} + */ export const getVisibleCanvases = createSelector( [getVisibleCanvasIds, getCanvases], (canvasIds, canvases) => (canvases || []).filter(c => canvasIds.includes(c.id)), ); /** -* Return the current canvases grouped by how they'll appear in the viewer -* For book view returns groups of 2, for single returns 1 -* @param {object} state -* @param {object} props -* @param {string} props.manifestId -* @param {string} props.windowId -* @return {Array} -*/ + * Return the current canvases grouped by how they'll appear in the viewer. + * For book view returns groups of 2, for single returns 1. + * @param {object} state + * @param {object} props + * @param {string} props.manifestId + * @param {string} props.windowId + * @returns {Array} + */ export const getCanvasGroupings = createSelector( [ getCanvases, @@ -83,14 +105,15 @@ export const getCanvasGroupings = createSelector( ); /** -* Return the current canvases selected in a window -* For book view returns 2, for single returns 1 -* @param {object} state -* @param {object} props -* @param {string} props.manifestId -* @param {string} props.windowId -* @return {Array} -*/ + * Return the current canvases selected in a window. + * For book view returns 2, for single returns 1. + * @param {object} state + * @param {object} props + * @param {string} props.manifestId + * @param {string} props.windowId + * @param {string} props.canvasId + * @returns {Array} + */ export const getCanvasGrouping = createSelector( [ getCanvasGroupings, @@ -101,14 +124,14 @@ export const getCanvasGrouping = createSelector( ); /** -* Return the next canvas(es) for a window -* For book view returns 2, for single returns 1 -* @param {object} state -* @param {object} props -* @param {string} props.manifestId -* @param {string} props.windowId -* @return {Array} -*/ + * Return the next canvas(es) for a window. + * For book view returns 2, for single returns 1. + * @param {object} state + * @param {object} props + * @param {string} props.manifestId + * @param {string} props.windowId + * @returns {Array} + */ export const getNextCanvasGrouping = createSelector( [ getCanvasGroupings, @@ -126,14 +149,14 @@ export const getNextCanvasGrouping = createSelector( ); /** -* Return the previous canvas(es) for a window -* For book view returns 2, for single returns 1 -* @param {object} state -* @param {object} props -* @param {string} props.manifestId -* @param {string} props.windowId -* @return {Array} -*/ + * Return the previous canvas(es) for a window. + * For book view returns 2, for single returns 1. + * @param {object} state + * @param {object} props + * @param {string} props.manifestId + * @param {string} props.windowId + * @returns {Array} + */ export const getPreviousCanvasGrouping = createSelector( [ getCanvasGroupings, @@ -152,10 +175,13 @@ export const getPreviousCanvasGrouping = createSelector( ); /** -* Return canvas label, or alternatively return the given index + 1 to be displayed -* @param {object} canvas -* @return {String|Integer} -*/ + * Return canvas label, or alternatively return the given index + 1 to be displayed. + * @param {object} state + * @param {object} props + * @param {string} props.canvasId + * @param {string} props.manifestId + * @returns {string|number} + */ export const getCanvasLabel = createSelector( [getCanvas], canvas => (canvas && ( @@ -166,15 +192,21 @@ export const getCanvasLabel = createSelector( ); /** -* Return canvas description -* @param {object} canvas -* @param {String} -*/ + * Return canvas description. + * @param {object} canvas + * @param {string} companionWindowId + */ export const getCanvasDescription = createSelector( [getCanvas], canvas => canvas && canvas.getProperty('description'), ); +/** + * Return visible non tiled canvas resources. + * @param {object} + * @param {string} windowId + * @returns {Array} + */ export const getVisibleCanvasNonTiledResources = createSelector( [ getVisibleCanvases, @@ -184,6 +216,12 @@ export const getVisibleCanvasNonTiledResources = createSelector( .filter(resource => resource.getServices().length < 1), ); +/** + * Returns visible canvas video resources. + * @param {object} state + * @param {string} windowId + * @return {Array} + */ export const getVisibleCanvasVideoResources = createSelector( [ getVisibleCanvases, @@ -192,6 +230,12 @@ export const getVisibleCanvasVideoResources = createSelector( .map(canvas => new MiradorCanvas(canvas).videoResources)), ); +/** + * Returns visible canvas captions. + * @param {object} state + * @param {string} windowId + * @return {Array} + */ export const getVisibleCanvasCaptions = createSelector( [ getVisibleCanvases, @@ -204,6 +248,12 @@ export const getVisibleCanvasCaptions = createSelector( })), ); +/** + * Returns visible canvas audio resources. + * @param {object} state + * @param {string} windowId + * @return {Array} + */ export const getVisibleCanvasAudioResources = createSelector( [ getVisibleCanvases, @@ -212,6 +262,15 @@ export const getVisibleCanvasAudioResources = createSelector( .map(canvas => new MiradorCanvas(canvas).audioResources)), ); +/** + * Returns info response. + * @param {object} state + * @param {object} props + * @param {string} props.windowId + * @param {string} props.canvasId + * @param {string} props.infoId + * @returns {object|undefined} + */ export const selectInfoResponse = createSelector( [ (state, { infoId }) => infoId, diff --git a/src/state/selectors/companionWindows.js b/src/state/selectors/companionWindows.js index 914c73a2f0..7d9e2a9c97 100644 --- a/src/state/selectors/companionWindows.js +++ b/src/state/selectors/companionWindows.js @@ -3,11 +3,22 @@ import groupBy from 'lodash/groupBy'; import { miradorSlice } from './utils'; import { getWindow, getWindows } from './getters'; -/** */ +/** + * Returns companion windows. + * @param {object} state + * @returns {object} + */ export function getCompanionWindows(state) { return miradorSlice(state).companionWindows || {}; } +/** + * Returns the companion window. + * @param {object} state + * @param {object} props + * @param {string} props.companionWindowId + * @returns {object|undefined} + */ export const getCompanionWindow = createSelector( [ getCompanionWindows, @@ -16,11 +27,13 @@ export const getCompanionWindow = createSelector( (companionWindows, companionWindowId) => companionWindowId && companionWindows[companionWindowId], ); -/** Return position of thumbnail navigation in a certain window. -* @param {object} state -* @param {String} windowId -* @param {String} -*/ +/** + * Return position of thumbnail navigation in a certain window. + * @param {object} state + * @param {object} props + * @param {string} props.windowId + * @returns {string|undefined} + */ export const getThumbnailNavigationPosition = createSelector( [ getWindow, @@ -32,10 +45,10 @@ export const getThumbnailNavigationPosition = createSelector( ); /** -* Return compantion window ids from a window -* @param {String} windowId -* @return {Array} -*/ + * Return companion window ids from a window. + * @param {string} windowId + * @returns {Array} + */ const getCompanionWindowIndexByWindowAndPosition = createSelector( [getWindows, getCompanionWindows], (windows, companionWindows) => ( @@ -51,10 +64,10 @@ const getCompanionWindowIndexByWindowAndPosition = createSelector( ); /** -* Return compantion window ids from a window -* @param {String} windowId -* @return {Array} -*/ + * Return companion window ids from a window. + * @param {string} windowId + * @returns {Array} + */ const getCompanionWindowsByWindowAndPosition = createSelector( [getWindows, getCompanionWindows], (windows, companionWindows) => ( @@ -69,9 +82,10 @@ const getCompanionWindowsByWindowAndPosition = createSelector( ); /** - * Return companion windows of a window - * @param {String} windowId - * @return {Array} + * Return companion windows of a window. + * @param {object} state + * @param {string} windowId + * @returns {Array} */ const getCompanionWindowsOfWindow = createSelector( [(state, { windowId }) => windowId, getCompanionWindowsByWindowAndPosition], @@ -79,9 +93,10 @@ const getCompanionWindowsOfWindow = createSelector( ); /** - * Return companion windows of a window - * @param {String} windowId - * @return {Array} + * Return companion windows ids of a window. + * @param {object} state + * @param {string} windowId + * @returns {Array} */ const getCompanionWindowIdsOfWindow = createSelector( [(state, { windowId }) => windowId, getCompanionWindowIndexByWindowAndPosition], @@ -89,12 +104,12 @@ const getCompanionWindowIdsOfWindow = createSelector( ); /** -* Return the companion window string from state in a given windowId and position -* @param {object} state -* @param {String} windowId -* @param {String} position -* @return {String} -*/ + * Return the companion window string from state in a given windowId and position. + * @param {object} state + * @param {string} windowId + * @param {string} position + * @returns {string} + */ export const getCompanionWindowsForPosition = createSelector( [ getCompanionWindowsOfWindow, @@ -104,12 +119,12 @@ export const getCompanionWindowsForPosition = createSelector( ); /** -* Return the companion window string from state in a given windowId and content type -* @param {object} state -* @param {String} windowId -* @param {String} position -* @return {String} -*/ + * Return the companion window string from state in a given windowId and content type. + * @param {object} state + * @param {string} windowId + * @param {string} position + * @returns {string} + */ export const getCompanionWindowsForContent = createSelector( [ getCompanionWindowsOfWindow, @@ -122,7 +137,14 @@ export const getCompanionWindowsForContent = createSelector( const EMPTY_ARRAY = []; -/** */ +/** + * Returns companion window ids for position. + * @param {object} state + * @param {object} props + * @param {string} props.windowId + * @param {string} props.position + * @returns {Array} + */ export const getCompanionWindowIdsForPosition = createSelector( [ getCompanionWindowIdsOfWindow, @@ -132,10 +154,10 @@ export const getCompanionWindowIdsForPosition = createSelector( ); /** - * Returns the visibility of the companion area + * Returns the visibility of the companion area. * @param {object} state - * @param {object} props - * @return {Boolean} + * @param {string} position + * @returns {boolean} */ export const getCompanionAreaVisibility = createSelector( [ @@ -150,6 +172,12 @@ export const getCompanionAreaVisibility = createSelector( }, ); +/** + * Returns the dimensions. + * @param {object} state + * @param {string} companionWindowId + * @returns {object} containing height and width + */ export const selectCompanionWindowDimensions = createSelector( [getCompanionWindowsOfWindow], (companionWindows) => { diff --git a/src/state/selectors/config.js b/src/state/selectors/config.js index d5b99995d2..7a025b3474 100644 --- a/src/state/selectors/config.js +++ b/src/state/selectors/config.js @@ -3,7 +3,11 @@ import deepmerge from 'deepmerge'; import { miradorSlice } from './utils'; import { getWorkspace } from './getters'; -/** */ +/** + * Returns the config from the redux state. + * @param {object} state + * @returns {object} containing config + */ export function getConfig(state) { const slice = miradorSlice(state || {}); return slice.config || {}; @@ -11,6 +15,8 @@ export function getConfig(state) { /** * Extract an exportable version of state using the configuration from the config. + * @param {object} state + * @returns {object} containing exportable state */ export function getExportableState(state) { const exportConfig = getConfig(state).export; @@ -37,9 +43,9 @@ export function getExportableState(state) { } /** -* Return languages from config (in state) and indicate which is currently set +* Return languages from config (in state) and indicate which is currently set. * @param {object} state -* @return {Array} [ {locale: 'de', label: 'Deutsch', current: true}, ... ] +* @returns {Array} [ {locale: 'de', label: 'Deutsch', current: true}, ... ] */ export const getLanguagesFromConfigWithCurrent = createSelector( [getConfig], @@ -50,6 +56,11 @@ export const getLanguagesFromConfigWithCurrent = createSelector( })), ); +/** + * Returns if showZoomControls is set in the config. + * @param {object} state + * @returns {boolean} + */ export const getShowZoomControlsConfig = createSelector( [ getWorkspace, @@ -62,11 +73,21 @@ export const getShowZoomControlsConfig = createSelector( ), ); +/** + * Returns the theme from the config. + * @param {object} state + * @returns {object} {palette: {...}, typography: {...}, overrides: {...}, ...} + */ export const getTheme = createSelector( [getConfig], ({ theme, themes, selectedTheme }) => deepmerge(theme, themes[selectedTheme] || {}), ); +/** + * Returns the theme ids from the config. + * @param {object} state + * @returns {Array} ['dark', 'light'] + */ export const getThemeIds = createSelector( [getConfig], ({ themes }) => Object.keys(themes), @@ -78,11 +99,20 @@ export const getContainerId = createSelector( ({ id }) => id, ); +/** + * Returns the theme direction from the config. + * @param {object} state + * @returns {string} + */ export const getThemeDirection = createSelector( [getConfig], ({ theme }) => theme.direction || 'ltr', ); - +/** + * Returns the theme direction from the config. + * @param {object} state + * @returns {object} {preprocessor: [...], postprocessor: [...]} + */ export const getRequestsConfig = createSelector( [getConfig], ({ requests }) => requests || {}, diff --git a/src/state/selectors/getters.js b/src/state/selectors/getters.js index 066dce47da..7475545778 100644 --- a/src/state/selectors/getters.js +++ b/src/state/selectors/getters.js @@ -2,24 +2,41 @@ import { createSelector } from 'reselect'; import { miradorSlice } from './utils'; /** - * Return the manifest titles for all open windows + * Returns the manifest titles for all open windows. * @param {object} state - * @return {object} + * @returns {Array} containing manifests ids. */ export function getWindowManifests(state) { return Object.values(miradorSlice(state).windows).map(window => window.manifestId); } -/** */ +/** + * Returns the opened windows. + * @param {object} state + * @returns {object} {id: {canvasId: {...}, ...}, ...} + */ export function getWindows(state) { return miradorSlice(state).windows || {}; } -/** */ +/** + * Returns a window based on a given windowId. + * @param {object} state + * @param {object} props + * @param {string} props.windowId + * @returns {object|undefined} + */ export function getWindow(state, { windowId }) { return getWindows(state)[windowId]; } +/** + * Returns the viewer for a given window. + * @param {object} state + * @param {object} props + * @param {string} props.windowId + * @returns {object|undefined} {flip: false, rotation: 0, x: 1, y: 2, zoom: 0.5} + */ export const getViewer = createSelector( [ state => miradorSlice(state).viewers, @@ -28,23 +45,42 @@ export const getViewer = createSelector( (viewers, windowId) => viewers[windowId], ); -/** */ +/** + * Returns the workspace. + * @param {object} state + * @returns {object} + */ export function getWorkspace(state) { return miradorSlice(state).workspace; } -/** */ +/** + * Returns the windowIds. + * @param {object} state + * @returns {Array} + */ export const getWindowIds = createSelector( [getWorkspace], ({ windowIds }) => windowIds || [], ); -/** */ +/** + * Returns all manifests including manifest information. + * @param {object} state + * @returns {object} + */ export function getManifests(state) { return miradorSlice(state).manifests || {}; } -/** Get the relevant manifest information */ +/** + * Get the relevant manifest information for a given manifest. + * @param {object} state + * @param {object} props + * @param {string} props.manifestId + * @param {string} props.windowId + * @returns {object} + */ export function getManifest(state, { manifestId, windowId }) { const manifests = getManifests(state); return manifests && manifests[ @@ -53,7 +89,11 @@ export function getManifest(state, { manifestId, windowId }) { ]; } -/** */ +/** + * Get the opened catalog. + * @param {object} state + * @returns {object} containing manifestIds for the manifests in the catalog + */ export function getCatalog(state) { return miradorSlice(state).catalog || {}; } diff --git a/src/state/selectors/layers.js b/src/state/selectors/layers.js index e75c165b7e..6a1ebd4897 100644 --- a/src/state/selectors/layers.js +++ b/src/state/selectors/layers.js @@ -4,7 +4,13 @@ import { getCanvas, getVisibleCanvasIds } from './canvases'; import { miradorSlice } from './utils'; /** - * Get the image layers from a canvas + * Get the image layers from a canvas. + * @param {object} state + * @param {object} props + * @param {string} props.canvasId + * @param {string} props.windowId + * @param {string} props.companionWindowId + * @returns {Array} */ export const getCanvasLayers = createSelector( [ @@ -18,7 +24,10 @@ export const getCanvasLayers = createSelector( ); /** - * Get the layer state for a particular canvas + * Get the layer state for a particular canvas. + * @param {object} state + * @param {string} windowId + * @returns {object} */ export const getLayers = createSelector( [ @@ -30,7 +39,11 @@ export const getLayers = createSelector( ); /** - * Returns a list of canvas layers, sorted by the layer state configuration + * Returns a list of canvas layers, sorted by the layer state configuration. + * @param {object} state + * @param {object} props + * @param {string} props.companionWindowId + * @returns {Array} */ export const getSortedLayers = createSelector( [ @@ -58,7 +71,11 @@ export const getSortedLayers = createSelector( ); /** - * Get all the layer configuration for visible canvases + * Get all the layer configuration for visible canvases. + * @param {object} state + * @param {object} props + * @param {string} props.windowId + * @returns {object} */ export const getLayersForVisibleCanvases = createSelector( [ diff --git a/src/state/selectors/manifests.js b/src/state/selectors/manifests.js index 496d845621..807e575dd9 100644 --- a/src/state/selectors/manifests.js +++ b/src/state/selectors/manifests.js @@ -29,13 +29,25 @@ const getLocale = createSelector( ), ); -/** Convenience selector to get a manifest (or placeholder) */ +/** + * Convenience selector to get a manifest (or placeholder). + * @param {object} state + * @param {object} props + * @param {string} props.windowId + * @returns {object} {error: null: id: string, isFetching: boolean, json: {...}} + */ export const getManifestStatus = createSelector( [getManifest], manifest => manifest || { missing: true }, ); -/** Convenience selector to get a manifest loading error */ +/** + * Convenience selector to get a manifest loading error + * @param {object} state + * @param {object} props + * @param {string} props.manifestId + * @returns {string|null} + */ export const getManifestError = createSelector( [getManifest], manifest => manifest && manifest.error, @@ -55,7 +67,13 @@ const getContextualManifestoInstance = createCachedSelector( ].join(' - '), // Cache key consisting of manifestId, windowId, and locale ); -/** Instantiate a manifesto instance */ +/** + * Instantiate a manifesto instance + * @param {object} state + * @param {object} props + * @param {string} props.manifestId + * @returns {object} + */ export const getManifestoInstance = createSelector( getContextualManifestoInstance, (state, { json }) => json, @@ -78,7 +96,13 @@ function getProperty(property) { ); } -/** */ +/** + * Returns the manifest provider. + * @param {object} state + * @param {object} props + * @param {string} props.companionWindowId + * @returns {string} + */ export const getManifestProvider = createSelector( [ getProperty('provider'), @@ -87,13 +111,13 @@ export const getManifestProvider = createSelector( ); /** -* Return the IIIF v3 provider of a manifest or null -* @param {object} state -* @param {object} props -* @param {string} props.manifestId -* @param {string} props.windowId -* @return {String|null} -*/ + * Return the IIIF v3 provider of a manifest or null. + * @param {object} state + * @param {object} props + * @param {string} props.manifestId + * @param {string} props.windowId + * @returns {string|null} + */ export const getManifestProviderName = createSelector( [ getProperty('provider'), @@ -105,10 +129,10 @@ export const getManifestProviderName = createSelector( ); /** - * Return the IIIF v3 provider logo + * Return the IIIF v3 provider logo. * @param {object} state * @param {object} props - * @return {String|null} + * @returns {string|null} */ export const getProviderLogo = createSelector( [getManifestProvider], @@ -120,10 +144,10 @@ export const getProviderLogo = createSelector( ); /** - * Get the logo for a manifest + * Get the logo for a manifest. * @param {object} state * @param {object} props - * @return {String|null} + * @returns {string|null} */ export const getManifestLogo = createSelector( [getManifestoInstance, getProviderLogo], @@ -131,13 +155,13 @@ export const getManifestLogo = createSelector( ); /** -* Return the IIIF v3 homepage of a manifest or null -* @param {object} state -* @param {object} props -* @param {string} props.manifestId -* @param {string} props.windowId -* @return {String|null} -*/ + * Return the IIIF v3 homepage of a manifest or null. + * @param {object} state + * @param {object} props + * @param {string} props.manifestId + * @param {string} props.windowId + * @returns {string|null} + */ export const getManifestHomepage = createSelector( [ getProperty('homepage'), @@ -154,13 +178,13 @@ export const getManifestHomepage = createSelector( ); /** -* Return the IIIF v3 renderings of a manifest or null -* @param {object} state -* @param {object} props -* @param {string} props.manifestId -* @param {string} props.windowId -* @return {String|null} -*/ + * Return the IIIF v3 renderings of a manifest or null. + * @param {object} state + * @param {object} props + * @param {string} props.manifestId + * @param {string} props.windowId + * @returns {string|null} + */ export const getManifestRenderings = createSelector( [getManifestoInstance], manifest => manifest @@ -173,14 +197,13 @@ export const getManifestRenderings = createSelector( ); /** -* Return the IIIF v2/v3 seeAlso data from a manifest or null -* -* @param {object} state -* @param {object} props -* @param {string} props.manifestId -* @param {string} props.windowId -* @return {String|null} -*/ + * Return the IIIF v2/v3 seeAlso data from a manifest or null. + * @param {object} state + * @param {object} props + * @param {string} props.manifestId + * @param {string} props.windowId + * @returns {string|null} + */ export const getManifestSeeAlso = createSelector( [ getProperty('seeAlso'), @@ -198,27 +221,26 @@ export const getManifestSeeAlso = createSelector( ); /** -* Return the IIIF v2/v3 seeAlso data from a manifest or null -* -* @param {object} state -* @param {object} props -* @param {string} props.manifestId -* @param {string} props.windowId -* @return {String|null} -* @deprecated This does not actually return the content of "related" and -* might be removed in a future version. -* @see getManifestSeeAlso -*/ + * Return the IIIF v2/v3 seeAlso data from a manifest or null. + * @param {object} state + * @param {object} props + * @param {string} props.manifestId + * @param {string} props.windowId + * @returns {string|null} + * @deprecated This does not actually return the content of "related" and + * might be removed in a future version. + * @see getManifestSeeAlso + */ export const getManifestRelatedContent = getManifestSeeAlso; /** -* Return the IIIF v2 realated links manifest or null -* @param {object} state -* @param {object} props -* @param {string} props.manifestId -* @param {string} props.windowId -* @return {String|null} -*/ + * Return the IIIF v2 realated links manifest or null + * @param {object} state + * @param {object} props + * @param {string} props.manifestId + * @param {string} props.windowId + * @returns {string|null} + */ export const getManifestRelated = createSelector( [ getProperty('related'), @@ -240,13 +262,13 @@ export const getManifestRelated = createSelector( ); /** -* Return the IIIF requiredStatement (v3) or attribution (v2) data from a manifest or null -* @param {object} state -* @param {object} props -* @param {string} props.manifestId -* @param {string} props.windowId -* @return {String|null} -*/ + * Return the IIIF requiredStatement (v3) or attribution (v2) data from a manifest or null + * @param {object} state + * @param {object} props + * @param {string} props.manifestId + * @param {string} props.windowId + * @returns {string|null} + */ export const getRequiredStatement = createSelector( [getManifestoInstance], manifest => manifest @@ -259,12 +281,12 @@ export const getRequiredStatement = createSelector( ); /** -* Return the IIIF v2 rights (v3) or license (v2) data from a manifest or null -* @param {object} state -* @param {object} props -* @param {string} props.manifestId -* @param {string} props.windowId -* @return {String|null} + * Return the IIIF v2 rights (v3) or license (v2) data from a manifest or null + * @param {object} state + * @param {object} props + * @param {string} props.manifestId + * @param {string} props.windowId + * @returns {string|null} */ export const getRights = createSelector( [ @@ -279,13 +301,13 @@ export const getRights = createSelector( ); /** -* Return the supplied thumbnail for a manifest or null -* @param {object} state -* @param {object} props -* @param {string} props.manifestId -* @param {string} props.windowId -* @return {String|null} -*/ + * Return the supplied thumbnail for a manifest or null. + * @param {object} state + * @param {object} props + * @param {string} props.manifestId + * @param {string} props.windowId + * @returns {string|null} + */ export function getManifestThumbnail(state, props) { const manifest = getManifestoInstance(state, props); const { thumbnails = {} } = getConfig(state); @@ -300,13 +322,13 @@ export function getManifestThumbnail(state, props) { } /** -* Return manifest title -* @param {object} state -* @param {object} props -* @param {string} props.manifestId -* @param {string} props.windowId -* @return {String} -*/ + * Return manifest title. + * @param {object} state + * @param {object} props + * @param {string} props.manifestId + * @param {string} props.windowId + * @returns {string} + */ export const getManifestTitle = createSelector( [getManifestoInstance], manifest => manifest @@ -314,13 +336,13 @@ export const getManifestTitle = createSelector( ); /** -* Return manifest description (IIIF v2) -- distinct from any description field nested under metadata -* @param {object} state -* @param {object} props -* @param {string} props.manifestId -* @param {string} props.windowId -* @return {String|null} -*/ + * Return manifest description (IIIF v2) -- distinct from any description field nested under metadata. + * @param {object} state + * @param {object} props + * @param {string} props.manifestId + * @param {string} props.windowId + * @returns {string|null} + */ export const getManifestDescription = createSelector( [getManifestoInstance], manifest => manifest @@ -328,12 +350,12 @@ export const getManifestDescription = createSelector( ); /** -* Return manifest summary (IIIF v3) +* Return manifest summary (IIIF v3). * @param {object} state * @param {object} props * @param {string} props.manifestId * @param {string} props.windowId -* @return {String|null} +* @return {string|null} */ export const getManifestSummary = createSelector( [ @@ -345,26 +367,27 @@ export const getManifestSummary = createSelector( ); /** -* Return manifest title -* @param {object} state -* @param {object} props -* @param {string} props.manifestId -* @param {string} props.windowId -* @return {String} -*/ + * Return manifest title. + * @param {object} state + * @param {object} props + * @param {string} props.manifestId + * @param {string} props.windowId + * @returns {string} + */ export const getManifestUrl = createSelector( [getManifestoInstance], manifest => manifest && manifest.id, ); /** -* Return metadata in a label / value structure -* This is a potential seam for pulling the i18n locale from -* state and plucking out the appropriate language. -* For now we're just getting the first. -* @param {object} Manifesto IIIF Resource (e.g. canvas, manifest) -* @return {Array[Object]} -*/ + * Return metadata in a label / value structure + * This is a potential seam for pulling the i18n locale from + * state and plucking out the appropriate language. + * For now we're just getting the first. + * @param {object} Manifesto IIIF Resource (e.g. canvas, manifest) + * @param iiifResource + * @returns {Array[Object]} + */ export function getDestructuredMetadata(iiifResource) { return (iiifResource && iiifResource.getMetadata().map(labelValuePair => ({ @@ -380,7 +403,7 @@ export function getDestructuredMetadata(iiifResource) { * @param {object} props * @param {string} props.manifestId * @param {string} props.windowId - * @return {Array[Object]} + * @returns {Array[Object]} */ export const getManifestMetadata = createSelector( [getManifestoInstance], @@ -419,7 +442,13 @@ export const getMetadataLocales = createSelector( manifest => getLocales(manifest), ); -/** */ +/** + * Returns manifest search service. + * @param {object} state + * @param {object} props + * @param {string} props.manifestId + * @returns {string|null} + */ export const getManifestSearchService = createSelector( [getManifestoInstance], (manifest) => { @@ -431,7 +460,13 @@ export const getManifestSearchService = createSelector( }, ); -/** */ +/** + * Returns manifest autocomplete service. + * @param {object} state + * @param {object} props + * @param {string} props.manifestId + * @returns {string|null} + */ export const getManifestAutocompleteService = createSelector( [getManifestSearchService], (searchService) => { diff --git a/src/state/selectors/ranges.js b/src/state/selectors/ranges.js index a2e3129558..c025b5a3a6 100644 --- a/src/state/selectors/ranges.js +++ b/src/state/selectors/ranges.js @@ -66,7 +66,13 @@ const getVisibleLeafAndBranchNodeIds = createSelector( }, ); -/** */ +/** + * Returns visible node ids. + * @param {object} state + * @param {object} props + * @param {string} props.windowId + * @returns {Array} + */ export const getVisibleNodeIds = createSelector( [ getVisibleLeafAndBranchNodeIds, @@ -94,7 +100,14 @@ const getCanvasContainingNodeIds = createSelector( ), ); -/** */ +/** + * Returns ids of manually exanded nodes. + * @param {object} state + * @param {object} props + * @param {string} props.companionWindowId + * @param expanded + * @returns {Array} + */ export function getManuallyExpandedNodeIds(state, { companionWindowId }, expanded) { const companionWindow = getCompanionWindow(state, { companionWindowId }); return companionWindow.tocNodes ? Object.keys(companionWindow.tocNodes).reduce( @@ -105,7 +118,14 @@ export function getManuallyExpandedNodeIds(state, { companionWindowId }, expande ) : []; } -/** */ +/** + * Returns ids of exanded nodes. + * @param {object} state + * @param {object} props + * @param {string} props.companionWindowId + * @param {string} props.windowId + * @returns {Array} + */ export function getExpandedNodeIds(state, { companionWindowId, windowId }) { const visibleBranchNodeIds = getVisibleBranchNodeIds(state, { companionWindowId, windowId }); const manuallyExpandedNodeIds = getManuallyExpandedNodeIds(state, { companionWindowId }, true); @@ -113,7 +133,15 @@ export function getExpandedNodeIds(state, { companionWindowId, windowId }) { return without(union(manuallyExpandedNodeIds, visibleBranchNodeIds), ...manuallyClosedNodeIds); } -/** */ +/** + * Returns id of node to scroll to. + * @param {object} state + * @param {object} props + * @param {string} props.companionWindowId + * @param {string} props.windowId + * @param {string} props.manifestid + * @returns {string} + */ export function getNodeIdToScrollTo(state, { ...args }) { const canvasContainingNodeIds = getCanvasContainingNodeIds(state, { ...args }); const collapsedNodeIds = getManuallyExpandedNodeIds(state, args, false); @@ -129,7 +157,10 @@ export function getNodeIdToScrollTo(state, { ...args }) { } /** - * Returns the default sidebar variant depending on whether or not ranges exist + * Returns the default sidebar variant depending on whether or not ranges exist. + * @param {object} state + * @param {string} + * @returns {string} */ export const getDefaultSidebarVariant = createSelector( [ diff --git a/src/state/selectors/searches.js b/src/state/selectors/searches.js index 7a1dab899c..ef773cb083 100644 --- a/src/state/selectors/searches.js +++ b/src/state/selectors/searches.js @@ -7,7 +7,9 @@ import { getWindow } from './getters'; import { getManifestLocale } from './manifests'; import { miradorSlice } from './utils'; -/** Get searches from state */ +/** + * Get searches from state. + */ const getSearches = (state) => miradorSlice(state).searches; /** @@ -195,7 +197,10 @@ export const getSearchAnnotationsForCompanionWindow = createSelector( results => results && searchResultsToAnnotation(results), ); -/** */ +/** + * Sorts search annotations based on canvas order. + * @returns {Array} + */ export function sortSearchAnnotationsByCanvasOrder(searchAnnotations, canvases) { if (!searchAnnotations || !searchAnnotations.resources @@ -208,6 +213,12 @@ export function sortSearchAnnotationsByCanvasOrder(searchAnnotations, canvases) ); } +/** + * Returns sorted search annotations for companion window. + * @param {object} state + * @param {string} companionWindowId + * @returns {Array} + */ export const getSortedSearchAnnotationsForCompanionWindow = createSelector( [ getSearchAnnotationsForCompanionWindow, @@ -216,6 +227,12 @@ export const getSortedSearchAnnotationsForCompanionWindow = createSelector( (searchAnnotations, canvases) => sortSearchAnnotationsByCanvasOrder(searchAnnotations, canvases), ); +/** + * Returns sorted search annotations for window. + * @param {object} state + * @param {string} windowId + * @returns {Array} + */ export const getSearchAnnotationsForWindow = createSelector( [ getSearchForWindow, @@ -228,6 +245,12 @@ export const getSearchAnnotationsForWindow = createSelector( }, ); +/** + * Returns ids of selected content search annotations. + * @param {object} state + * @param {string} windowId + * @returns {Array} + */ export const getSelectedContentSearchAnnotationIds = createSelector( [ getWindow, @@ -237,6 +260,12 @@ export const getSelectedContentSearchAnnotationIds = createSelector( || [], ); +/** + * Returns resource annotations for search hit. + * @param {object} state + * @param {string} windowId + * @returns {Array} + */ export const getResourceAnnotationForSearchHit = createSelector( [ getSearchAnnotationsForCompanionWindow, @@ -247,6 +276,12 @@ export const getResourceAnnotationForSearchHit = createSelector( ), ); +/** + * Returns annotation label. + * @param {object} state + * @param {string} windowId + * @returns {Array} + */ export const getResourceAnnotationLabel = createSelector( [ getResourceAnnotationForSearchHit, @@ -272,6 +307,12 @@ const getAnnotationById = createSelector( }, ); +/** + * Returns annotation label. + * @param {object} state + * @param {string} windowId + * @returns {Array} + */ export const getCanvasForAnnotation = createSelector( [ getAnnotationById, diff --git a/src/state/selectors/sequences.js b/src/state/selectors/sequences.js index 8e9834f4d1..097d341d5e 100644 --- a/src/state/selectors/sequences.js +++ b/src/state/selectors/sequences.js @@ -6,7 +6,11 @@ import { import { getWindow } from './getters'; /** - * @param {string} companionWindowId + * Returns the sequences for a given windowId + * @param {object} state + * @param {object} props + * @param {string} props.windowId + * @returns {Array} */ export const getSequences = createSelector( [getManifestoInstance], @@ -33,7 +37,11 @@ export const getSequences = createSelector( ); /** - * @param {string} companionWindowId + * Returns the sequence for a given windowId + * @param {object} state + * @param {object} props + * @param {string} props.windowId + * @returns {Array} */ export const getSequence = createSelector( [ @@ -54,11 +62,12 @@ export const getSequence = createSelector( }, ); -/** Return the canvas index for a certain window. -* @param {object} state -* @param {String} windowId -* @param {Number} -*/ +/** + * Return the canvas index for a certain window. + * @param {Object} state + * @param {string} windowId + * @returns {number} + */ export const getCanvasIndex = createSelector( [ getWindow, @@ -71,12 +80,12 @@ export const getCanvasIndex = createSelector( ); /** - * Returns the viewing hint for the first sequence in the manifest or the manifest + * Returns the viewing hint for the first sequence in the manifest or the manifest. * @param {object} state * @param {object} props * @param {string} props.manifestId * @param {string} props.windowId - * @return {Number} + * @returns {number} */ export const getSequenceViewingHint = createSelector( [getSequence, getManifestoInstance], @@ -92,6 +101,7 @@ export const getSequenceViewingHint = createSelector( /** * @param {object} state * @param {string} windowId + * @return {string|null} */ export const getSequenceViewingDirection = createSelector( [getWindow, getSequence, getManifestoInstance], @@ -106,11 +116,11 @@ export const getSequenceViewingDirection = createSelector( /** * Returns the behaviors viewing hint for the manifest - * @param {object} state - * @param {object} props + * @param {Object} state + * @param {Object} props * @param {string} props.manifestId * @param {string} props.windowId - * @return {Number} + * @return {number} */ export const getSequenceBehaviors = createSelector( [getSequence, getManifestoInstance], @@ -132,10 +142,12 @@ export const getSequenceBehaviors = createSelector( ); /** + * Retruns a sequence tree structure. * @param {object} state - * @param {string} companionWindowId - * -*/ + * @param {object} props + * @param {string} props.windowId + * @returns {object} + */ export const getSequenceTreeStructure = createSelector( [getSequence, getManifestoInstance], (sequence, manifest) => { diff --git a/src/state/selectors/utils.js b/src/state/selectors/utils.js index 4dcec1de07..8f494c03aa 100644 --- a/src/state/selectors/utils.js +++ b/src/state/selectors/utils.js @@ -2,7 +2,7 @@ import settings from '../../config/settings'; /** * Returns a slice of the mirador redux state based on settings. - * Otherwise the entire Redux state is returned + * Otherwise the entire Redux state is returned. * @param {object} state * @returns {object} */ diff --git a/src/state/selectors/viewer.js b/src/state/selectors/viewer.js index b2012ff135..860da3a28a 100644 --- a/src/state/selectors/viewer.js +++ b/src/state/selectors/viewer.js @@ -5,11 +5,12 @@ import { getVisibleCanvases } from './canvases'; import { getLayersForVisibleCanvases } from './layers'; import { getSequenceViewingDirection } from './sequences'; -/** Instantiate a manifesto instance +/** + * Instantiate a manifesto instance. * @param {object} state * @param {string} windowId - * @returns {object} -*/ + * @return {object} + */ export const getCurrentCanvasWorld = createSelector( getVisibleCanvases, getLayersForVisibleCanvases, diff --git a/src/state/selectors/windows.js b/src/state/selectors/windows.js index 896e708e6c..3e3ade3fba 100644 --- a/src/state/selectors/windows.js +++ b/src/state/selectors/windows.js @@ -8,7 +8,7 @@ import { getWorkspaceType } from './workspace'; import { getSequenceViewingHint, getSequenceBehaviors } from './sequences'; /** - * Returns the window configuration + * Returns the window configuration based. * @param {object} state * @param {string} windowId * @returns {object} @@ -19,9 +19,9 @@ export const getWindowConfig = createSelector( ); /** - * Return the manifest titles for all open windows + * Returns the manifest titles for all open windows. * @param {object} state - * @return {object} + * @returns {object} */ export function getWindowTitles(state) { const result = {}; @@ -34,10 +34,10 @@ export function getWindowTitles(state) { } /** - * Returns an array containing the maximized windowIds + * Returns an array containing the maximized windowIds. * @param {object} state - * @returns {Array} -*/ + * @return {Array} + */ export const getMaximizedWindowsIds = createSelector( [getWindows], windows => Object.values(windows) @@ -45,13 +45,14 @@ export const getMaximizedWindowsIds = createSelector( .map(window => window.id), ); -/** Return type of view in a certain window. -* @param {object} state -* @param {object} props -* @param {string} props.manifestId -* @param {string} props.windowId -* @param {String} -*/ +/** + * Returns 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, @@ -72,7 +73,7 @@ export const getWindowViewType = createSelector( ); /** - * Returns the window view type for a given window + * Returns the window view type for a given window. * @param {object} state * @param {string} windowId * @returns {string} 'single' | 'book' | 'scroll' | 'gallery' @@ -97,10 +98,10 @@ export const getAllowedWindowViewTypes = createSelector( ); /** - * Returns the draggability of a window + * Return the draggability of a window. * @param {object} state * @param {object} props - * @return {Boolean} + * @returns {boolean} */ export const getWindowDraggability = createSelector( [ diff --git a/src/state/selectors/workspace.js b/src/state/selectors/workspace.js index 6c973c9f2c..6ac19e2154 100644 --- a/src/state/selectors/workspace.js +++ b/src/state/selectors/workspace.js @@ -2,15 +2,17 @@ import { createSelector } from 'reselect'; import { getWorkspace } from './getters'; import { miradorSlice } from './utils'; -/** Returns the elastic layout from the state +/** + * Returns the elastic layout from the state. * @param {object} state - * @returns {object} -*/ + * @returns {Object} + */ export function getElasticLayout(state) { return miradorSlice(state).elasticLayout; } -/** Returns if fullscreen is enabled +/** + * Returns if fullscreen is enabled. * @param {object} state * @returns {boolean} */ @@ -19,8 +21,10 @@ export const getFullScreenEnabled = createSelector( workspace => workspace.isFullscreenEnabled, ); -/** Returns the latest error from the state +/** + * Returns the latest error from the state. * @param {object} state + * @returns {object|undefined} */ export function getLatestError(state) { const [errorId] = miradorSlice(state).errors.items; @@ -29,8 +33,8 @@ export function getLatestError(state) { } /** - * Selector that returns the type of the workspace - * @param {object} state + * Returns the type of the workspace. + * @param {Object} state * @returns {string} 'mosaic' | 'elastic' */ export const getWorkspaceType = createSelector( @@ -39,7 +43,7 @@ export const getWorkspaceType = createSelector( ); /** - * Selector that returns the ID of the focused window. + * Returns the ID of the focused window. * @param {object} state * @returns {string|undefined} */ @@ -48,11 +52,12 @@ export const getFocusedWindowId = createSelector( ({ focusedWindowId }) => focusedWindowId, ); -/** Check if the current window is focused +/** + * Returns if a given window is focused. * @param {object} state * @param {string} windowId * @returns {boolean} -*/ + */ export const isFocused = (state, { windowId }) => ( getFocusedWindowId(state) === windowId );