From 2de71320cb830dcb2be99b346a050cc8582ea724 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Lo=C3=AFs=20Poujade?= <lois.poujade@tetras-libre.fr> Date: Mon, 7 Nov 2022 17:59:51 +0100 Subject: [PATCH] Expose VideoViewerReferences like OSDReferences OSDReferences is a list of ref to OpenSeadragon instances, used in Mirador as an image viewer. This commit exposes a VideoViewerReferences, to allows the annotations plugins to get video canvas dimensions and DOM element + removed build warning + disable "prepare" script to speed up build --- babel.config.js | 48 +++++++-------------------- package.json | 1 - src/components/VideoViewer.js | 5 ++- src/lib/AnnotationItem.js | 1 + src/plugins/VideoViewersReferences.js | 11 ++++++ 5 files changed, 28 insertions(+), 38 deletions(-) create mode 100644 src/plugins/VideoViewersReferences.js diff --git a/babel.config.js b/babel.config.js index 71e3e16ee..982d91dfd 100644 --- a/babel.config.js +++ b/babel.config.js @@ -47,44 +47,20 @@ module.exports = function (api) { const plugins = [ 'babel-plugin-macros', '@babel/plugin-transform-destructuring', - [ - '@babel/plugin-proposal-class-properties', - { - loose: true, - }, - ], - [ - '@babel/plugin-proposal-object-rest-spread', - { - useBuiltIns: true, - }, - ], - [ - '@babel/plugin-transform-runtime', - { - corejs: false, - helpers: false, // Needed to support IE/Edge - regenerator: true, - }, - ], - [ - '@babel/plugin-transform-regenerator', - { - async: false, - }, - ], - ['transform-react-remove-prop-types', - { - ignoreFilenames: ['node_modules'], - removeImport: true, - }, - ], - ['lodash', { - id: [ - 'lodash', - ], + // TODO loose: which options is ignored in depencies ? + ['@babel/plugin-proposal-private-methods', { loose: true }], + ['@babel/plugin-proposal-private-property-in-object', { loose: true }], + ['@babel/plugin-proposal-class-properties', { loose: true }], + ['@babel/plugin-proposal-object-rest-spread', { useBuiltIns: true }], + ['@babel/plugin-transform-runtime', { + corejs: false, + helpers: false, // Needed to support IE/Edge + regenerator: true, }, ], + ['@babel/plugin-transform-regenerator', { async: false }], + ['transform-react-remove-prop-types', { ignoreFilenames: ['node_modules'], removeImport: true }], + ['lodash', { id: ['lodash'] }], ].filter(Boolean); return { diff --git a/package.json b/package.json index b3c552136..c7c58347a 100644 --- a/package.json +++ b/package.json @@ -9,7 +9,6 @@ ], "sideEffects": false, "scripts": { - "prepare": "npm run clean && npm run build:es && npm run build:cjs", "clean": "rm -rf ./dist", "lint": "node_modules/.bin/eslint ./ && npm run lint:translations && npm run lint:containers", "lint:containers": "node ./scripts/container-lint.js", diff --git a/src/components/VideoViewer.js b/src/components/VideoViewer.js index d13ebbdaf..6dd39e8be 100644 --- a/src/components/VideoViewer.js +++ b/src/components/VideoViewer.js @@ -5,6 +5,7 @@ import PropTypes from 'prop-types'; import AnnotationItem from '../lib/AnnotationItem'; import AnnotationsOverlayVideo from '../containers/AnnotationsOverlayVideo'; import WindowCanvasNavigationControlsVideo from '../containers/WindowCanvasNavigationControlsVideo'; +import { VideoViewersReferences } from '../plugins/VideoViewersReferences'; /** */ export class VideoViewer extends Component { @@ -12,6 +13,8 @@ export class VideoViewer extends Component { constructor(props) { super(props); this.videoRef = React.createRef(); + this.apiRef = React.createRef(); + VideoViewersReferences.set(props.windowId, this); this.state = { start: 0, @@ -156,7 +159,7 @@ export class VideoViewer extends Component { }; } return ( - <div className={classes.flexContainer}> + <div className={classes.flexContainer} ref={this.apiRef}> <div className={classes.flexFill}> { video && ( <> diff --git a/src/lib/AnnotationItem.js b/src/lib/AnnotationItem.js index d927ec071..0d5fcae8d 100644 --- a/src/lib/AnnotationItem.js +++ b/src/lib/AnnotationItem.js @@ -138,6 +138,7 @@ export default class AnnotationItem { break; case 'object': temporalfragmentSelector = selector.find(s => s.type && s.type === 'FragmentSelector'); + // TODO regex for t=5,10 t=,10 t=5 ? cf w3c media fragments match = temporalfragmentSelector && temporalfragmentSelector.value.match(/t=(.*?)(&|$)/); break; default: diff --git a/src/plugins/VideoViewersReferences.js b/src/plugins/VideoViewersReferences.js new file mode 100644 index 000000000..1d6c0cf3a --- /dev/null +++ b/src/plugins/VideoViewersReferences.js @@ -0,0 +1,11 @@ +export const VideoViewersReferences = { + /** */ + get(windowId) { + return this.refs[windowId]; + }, + refs: {}, + /** */ + set(windowId, ref) { + this.refs[windowId] = ref; + }, +}; -- GitLab