UNPKG

mirador

Version:

An open-source, web-based 'multi-up' viewer that supports zoom-pan-rotate functionality, ability to display/compare simple images, and images with annotations.

136 lines (106 loc) 5.58 kB
"use strict"; var _regeneratorRuntime2 = require("@babel/runtime/regenerator"); Object.defineProperty(exports, "__esModule", { value: true }); exports["default"] = appSaga; exports.fetchAnnotations = fetchAnnotations; exports.fetchCanvasAnnotations = fetchCanvasAnnotations; var _regenerator = _interopRequireDefault(require("@babel/runtime/regenerator")); var _effects = require("redux-saga/effects"); var _actions = require("../actions"); var _selectors = require("../selectors"); var _actionTypes = _interopRequireDefault(require("../actions/action-types")); var _MiradorCanvas = _interopRequireDefault(require("../../lib/MiradorCanvas")); function _interopRequireDefault(obj) { return obj && obj.__esModule ? obj : { "default": obj }; } var _marked = /*#__PURE__*/_regeneratorRuntime2.mark(fetchCanvasAnnotations), _marked2 = /*#__PURE__*/_regeneratorRuntime2.mark(fetchAnnotations), _marked3 = /*#__PURE__*/_regeneratorRuntime2.mark(appSaga); function _toConsumableArray(arr) { return _arrayWithoutHoles(arr) || _iterableToArray(arr) || _unsupportedIterableToArray(arr) || _nonIterableSpread(); } function _nonIterableSpread() { throw new TypeError("Invalid attempt to spread non-iterable instance.\nIn order to be iterable, non-array objects must have a [Symbol.iterator]() method."); } function _unsupportedIterableToArray(o, minLen) { if (!o) return; if (typeof o === "string") return _arrayLikeToArray(o, minLen); var n = Object.prototype.toString.call(o).slice(8, -1); if (n === "Object" && o.constructor) n = o.constructor.name; if (n === "Map" || n === "Set") return Array.from(o); if (n === "Arguments" || /^(?:Ui|I)nt(?:8|16|32)(?:Clamped)?Array$/.test(n)) return _arrayLikeToArray(o, minLen); } function _iterableToArray(iter) { if (typeof Symbol !== "undefined" && iter[Symbol.iterator] != null || iter["@@iterator"] != null) return Array.from(iter); } function _arrayWithoutHoles(arr) { if (Array.isArray(arr)) return _arrayLikeToArray(arr); } function _arrayLikeToArray(arr, len) { if (len == null || len > arr.length) len = arr.length; for (var i = 0, arr2 = new Array(len); i < len; i++) { arr2[i] = arr[i]; } return arr2; } /** Fetch annotations for a given canvas */ function fetchCanvasAnnotations(_ref) { var canvasId, windowId, canvas, annotations, miradorCanvas; return _regenerator["default"].wrap(function fetchCanvasAnnotations$(_context) { while (1) { switch (_context.prev = _context.next) { case 0: canvasId = _ref.canvasId, windowId = _ref.windowId; _context.next = 3; return (0, _effects.select)(_selectors.getCanvas, { canvasId: canvasId, windowId: windowId }); case 3: canvas = _context.sent; _context.next = 6; return (0, _effects.select)(_selectors.getAnnotations); case 6: annotations = _context.sent; miradorCanvas = new _MiradorCanvas["default"](canvas); _context.next = 10; return (0, _effects.all)([].concat(_toConsumableArray(miradorCanvas.annotationListUris.filter(function (uri) { return !(annotations[canvas.id] && annotations[canvas.id][uri]); }).map(function (uri) { return (0, _effects.put)((0, _actions.requestAnnotation)(canvas.id, uri)); })), _toConsumableArray(miradorCanvas.canvasAnnotationPages.filter(function (annotation) { return !(annotations[canvas.id] && annotations[canvas.id][annotation.id]); }).map(function (annotation) { // If there are no items, try to retrieve the referenced resource. // otherwise the resource should be embedded and just add to the store. if (!annotation.items) { return (0, _effects.put)((0, _actions.requestAnnotation)(canvas.id, annotation.id)); } return (0, _effects.put)((0, _actions.receiveAnnotation)(canvas.id, annotation.id, annotation)); })))); case 10: return _context.abrupt("return", _context.sent); case 11: case "end": return _context.stop(); } } }, _marked); } /** * Fetch annotations for the visible canvases. */ function fetchAnnotations(_ref2) { var _ref2$visibleCanvases, visibleCanvases, windowId; return _regenerator["default"].wrap(function fetchAnnotations$(_context2) { while (1) { switch (_context2.prev = _context2.next) { case 0: _ref2$visibleCanvases = _ref2.visibleCanvases, visibleCanvases = _ref2$visibleCanvases === void 0 ? [] : _ref2$visibleCanvases, windowId = _ref2.windowId; _context2.next = 3; return (0, _effects.all)(visibleCanvases.map(function (canvasId) { return (0, _effects.put)((0, _actions.requestCanvasAnnotations)(windowId, canvasId)); })); case 3: return _context2.abrupt("return", _context2.sent); case 4: case "end": return _context2.stop(); } } }, _marked2); } /** */ function appSaga() { return _regenerator["default"].wrap(function appSaga$(_context3) { while (1) { switch (_context3.prev = _context3.next) { case 0: _context3.next = 2; return (0, _effects.all)([(0, _effects.takeEvery)(_actionTypes["default"].REQUEST_CANVAS_ANNOTATIONS, fetchCanvasAnnotations), (0, _effects.takeEvery)(_actionTypes["default"].SET_CANVAS, fetchAnnotations)]); case 2: case "end": return _context3.stop(); } } }, _marked3); }