@harvard-lts/mirador-annotations-auth-plugin 0.0.1 → 0.0.2

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
Files changed (2) hide show
  1. package/dist/es/index.js +143 -94
  2. package/package.json +1 -1
package/dist/es/index.js CHANGED
@@ -430,10 +430,10 @@ var AnnotationsAuthSidePanel = /*#__PURE__*/function (_Component) {
430
430
  _this.handleAnnotationBlur = _this.handleAnnotationBlur.bind(_this);
431
431
  var _this$props = _this.props,
432
432
  windowId = _this$props.windowId,
433
- canvasAnnotationPage = _this$props.canvasAnnotationPage;
433
+ canvasAnnotationPages = _this$props.canvasAnnotationPages;
434
434
  _this.state = {
435
435
  windowId: windowId,
436
- canvasAnnotationPage: canvasAnnotationPage
436
+ canvasAnnotationPages: canvasAnnotationPages
437
437
  };
438
438
  return _this;
439
439
  }
@@ -479,38 +479,71 @@ var AnnotationsAuthSidePanel = /*#__PURE__*/function (_Component) {
479
479
  }, {
480
480
  key: "componentDidMount",
481
481
  value: function () {
482
- var _componentDidMount = _asyncToGenerator(/*#__PURE__*/_regeneratorRuntime().mark(function _callee() {
483
- var _this2 = this;
484
- var canvasAnnotationPage;
485
- return _regeneratorRuntime().wrap(function _callee$(_context) {
486
- while (1) switch (_context.prev = _context.next) {
482
+ var _componentDidMount = _asyncToGenerator(/*#__PURE__*/_regeneratorRuntime().mark(function _callee2() {
483
+ var canvasAnnotationPages, promises, results;
484
+ return _regeneratorRuntime().wrap(function _callee2$(_context2) {
485
+ while (1) switch (_context2.prev = _context2.next) {
487
486
  case 0:
488
- canvasAnnotationPage = this.state.canvasAnnotationPage;
489
- fetch(canvasAnnotationPage, {
490
- method: 'get',
491
- credentials: 'include'
492
- }).then(function (response) {
493
- if (!response.ok) {
494
- throw new Error('Network response was not ok');
495
- }
496
- return response.json();
497
- }).then(function (annotationData) {
498
- _this2.setState({
499
- annotationData: annotationData,
500
- loading: false
501
- });
502
- })["catch"](function (error) {
503
- console.error('There was a problem receiving the annotation:', error);
504
- _this2.setState({
505
- loading: false,
506
- error: error.message
507
- });
487
+ canvasAnnotationPages = this.state.canvasAnnotationPages;
488
+ promises = [];
489
+ canvasAnnotationPages.forEach(function (annotationPage, index) {
490
+ var promise = new Promise(/*#__PURE__*/function () {
491
+ var _ref = _asyncToGenerator(/*#__PURE__*/_regeneratorRuntime().mark(function _callee(resolve, reject) {
492
+ var result;
493
+ return _regeneratorRuntime().wrap(function _callee$(_context) {
494
+ while (1) switch (_context.prev = _context.next) {
495
+ case 0:
496
+ _context.prev = 0;
497
+ _context.next = 3;
498
+ return fetch(annotationPage, {
499
+ method: 'get',
500
+ credentials: 'include'
501
+ });
502
+ case 3:
503
+ result = _context.sent;
504
+ resolve(result.json());
505
+ _context.next = 10;
506
+ break;
507
+ case 7:
508
+ _context.prev = 7;
509
+ _context.t0 = _context["catch"](0);
510
+ reject('Network response was not ok');
511
+ case 10:
512
+ case "end":
513
+ return _context.stop();
514
+ }
515
+ }, _callee, null, [[0, 7]]);
516
+ }));
517
+ return function (_x, _x2) {
518
+ return _ref.apply(this, arguments);
519
+ };
520
+ }());
521
+ promises.push(promise);
508
522
  });
509
- case 2:
523
+ _context2.prev = 3;
524
+ _context2.next = 6;
525
+ return Promise.all(promises);
526
+ case 6:
527
+ results = _context2.sent;
528
+ this.setState({
529
+ annotationData: results,
530
+ loading: false
531
+ });
532
+ _context2.next = 14;
533
+ break;
534
+ case 10:
535
+ _context2.prev = 10;
536
+ _context2.t0 = _context2["catch"](3);
537
+ console.error('There was a problem receiving the annotation:', _context2.t0);
538
+ this.setState({
539
+ loading: false,
540
+ error: _context2.t0.message
541
+ });
542
+ case 14:
510
543
  case "end":
511
- return _context.stop();
544
+ return _context2.stop();
512
545
  }
513
- }, _callee, this);
546
+ }, _callee2, this, [[3, 10]]);
514
547
  }));
515
548
  function componentDidMount() {
516
549
  return _componentDidMount.apply(this, arguments);
@@ -520,7 +553,7 @@ var AnnotationsAuthSidePanel = /*#__PURE__*/function (_Component) {
520
553
  }, {
521
554
  key: "render",
522
555
  value: function render() {
523
- var _this3 = this;
556
+ var _this2 = this;
524
557
  var _this$props5 = this.props,
525
558
  classes = _this$props5.classes,
526
559
  containerRef = _this$props5.containerRef,
@@ -545,67 +578,71 @@ var AnnotationsAuthSidePanel = /*#__PURE__*/function (_Component) {
545
578
  }), error && /*#__PURE__*/jsxs("p", {
546
579
  children: ["Error: ", error]
547
580
  })]
548
- }), /*#__PURE__*/jsx(MenuList, {
549
- autoFocusItem: true,
550
- variant: "selectedMenu",
551
- children: /*#__PURE__*/jsx(ScrollTo, {
552
- containerRef: containerRef,
553
- offsetTop: 96 // offset for the height of the form above
554
- ,
555
- scrollTo: selectedAnnotationId === {
556
- annotationData: annotationData
557
- }.id,
558
- children: /*#__PURE__*/jsx(MenuItem, {
559
- button: true,
560
- component: listContainerComponent,
561
- className: clsx(classes.annotationListItem, _defineProperty({}, classes.hovered, hoveredAnnotationIds.includes({
562
- annotationData: annotationData
563
- }.id))),
564
- annotationid: {
565
- annotationData: annotationData
566
- }.id,
567
- selected: selectedAnnotationId === {
568
- annotationData: annotationData
569
- }.id,
570
- onClick: function onClick(e) {
571
- return _this3.handleClick(e, {
572
- annotationData: annotationData
573
- });
574
- },
575
- onFocus: function onFocus() {
576
- return _this3.handleAnnotationHover({
577
- annotationData: annotationData
578
- });
579
- },
580
- onBlur: this.handleAnnotationBlur,
581
- onMouseEnter: function onMouseEnter() {
582
- return _this3.handleAnnotationHover({
583
- annotationData: annotationData
584
- });
585
- },
586
- onMouseLeave: this.handleAnnotationBlur,
587
- children: /*#__PURE__*/jsx(ListItemText, {
588
- primaryTypographyProps: {
589
- variant: 'body2'
590
- },
591
- children: annotationData && /*#__PURE__*/jsx(SanitizedHtml, {
592
- ruleSet: htmlSanitizationRuleSet,
593
- htmlString: annotationData.resources[0].resource.chars
594
- })
595
- })
596
- }, {
597
- annotationData: annotationData
598
- }.id)
599
- }, "".concat({
600
- annotationData: annotationData
601
- }.id, "-scroll"))
581
+ }), annotationData && /*#__PURE__*/jsx(Fragment, {
582
+ children: annotationData.map(function (annotation, i) {
583
+ return /*#__PURE__*/jsx(MenuList, {
584
+ autoFocusItem: true,
585
+ variant: "selectedMenu",
586
+ children: /*#__PURE__*/jsx(ScrollTo, {
587
+ containerRef: containerRef,
588
+ offsetTop: 96 // offset for the height of the form above
589
+ ,
590
+ scrollTo: selectedAnnotationId === {
591
+ annotation: annotation
592
+ }.id,
593
+ children: /*#__PURE__*/jsx(MenuItem, {
594
+ button: true,
595
+ component: listContainerComponent,
596
+ className: clsx(classes.annotationListItem, _defineProperty({}, classes.hovered, hoveredAnnotationIds.includes({
597
+ annotation: annotation
598
+ }.id))),
599
+ annotationid: {
600
+ annotation: annotation
601
+ }.id,
602
+ selected: selectedAnnotationId === {
603
+ annotation: annotation
604
+ }.id,
605
+ onClick: function onClick(e) {
606
+ return _this2.handleClick(e, {
607
+ annotation: annotation
608
+ });
609
+ },
610
+ onFocus: function onFocus() {
611
+ return _this2.handleAnnotationHover({
612
+ annotation: annotation
613
+ });
614
+ },
615
+ onBlur: _this2.handleAnnotationBlur,
616
+ onMouseEnter: function onMouseEnter() {
617
+ return _this2.handleAnnotationHover({
618
+ annotation: annotation
619
+ });
620
+ },
621
+ onMouseLeave: _this2.handleAnnotationBlur,
622
+ children: /*#__PURE__*/jsx(ListItemText, {
623
+ primaryTypographyProps: {
624
+ variant: 'body2'
625
+ },
626
+ children: /*#__PURE__*/jsx(SanitizedHtml, {
627
+ ruleSet: htmlSanitizationRuleSet,
628
+ htmlString: annotation.resources[0].resource.chars
629
+ })
630
+ })
631
+ }, {
632
+ annotation: annotation
633
+ }.id)
634
+ }, "".concat({
635
+ annotation: annotation
636
+ }.id, "-scroll"))
637
+ });
638
+ })
602
639
  })]
603
640
  });
604
641
  }
605
642
  }]);
606
643
  }(Component);
607
644
  AnnotationsAuthSidePanel.propTypes = {
608
- canvasAnnotationPage: PropTypes.string,
645
+ canvasAnnotationPages: PropTypes.arrayOf(PropTypes.string),
609
646
  canvasLabel: PropTypes.string,
610
647
  classes: PropTypes.objectOf(PropTypes.string),
611
648
  htmlSanitizationRuleSet: PropTypes.string,
@@ -617,7 +654,7 @@ AnnotationsAuthSidePanel.propTypes = {
617
654
  windowId: PropTypes.string.isRequired
618
655
  };
619
656
  AnnotationsAuthSidePanel.defaultProps = {
620
- canvasAnnotationPage: null,
657
+ canvasAnnotationPages: [],
621
658
  canvasLabel: null,
622
659
  classes: {},
623
660
  htmlSanitizationRuleSet: 'iiif',
@@ -648,29 +685,41 @@ var styles = function styles(theme) {
648
685
  };
649
686
 
650
687
  /** */
651
- function getAnnotationPage(canvases, canvasIds) {
652
- var annotationPage = null;
688
+ function getAnnotationPages(canvases, canvasIds) {
689
+ var annotationPagesArray = [];
690
+ var annotationPages = [];
653
691
  for (var i = 0; i < canvases.length; i++) {
654
692
  if (canvases[i].id === canvasIds[0]) {
655
693
  if (canvases[i].__jsonld.otherContent !== undefined) {
656
694
  // Version 2 Annotation Page
657
- annotationPage = canvases[i].__jsonld.otherContent[0]["@id"];
695
+ canvases[i].__jsonld.otherContent[0]["@id"];
696
+ annotationPagesArray = canvases[i].__jsonld.otherContent;
697
+ for (var j = 0; j < annotationPagesArray.length; j++) {
698
+ if (annotationPagesArray[j]["@type"] === "sc:AnnotationList") {
699
+ annotationPages[j] = annotationPagesArray[j]["@id"];
700
+ }
701
+ }
658
702
  }
659
703
  if (canvases[i].__jsonld.annotations !== undefined) {
660
704
  // Version 3 Annotation Page
661
- annotationPage = canvases[i].__jsonld.annotations[0].id;
705
+ canvases[i].__jsonld.annotations[0].id;
706
+ annotationPagesArray = canvases[i].__jsonld.annotations;
707
+ for (var _j = 0; _j < annotationPagesArray.length; _j++) {
708
+ if (annotationPagesArray[_j].type === "AnnotationPage") {
709
+ annotationPages[_j] = annotationPagesArray[_j].id;
710
+ }
711
+ }
662
712
  }
663
713
  break;
664
714
  }
665
715
  }
666
- console.log('annotationPage', annotationPage);
667
- return annotationPage;
716
+ return annotationPages;
668
717
  }
669
718
  var mapStateToProps = function mapStateToProps(state, _ref) {
670
719
  var canvasId = _ref.canvasId,
671
720
  windowId = _ref.windowId;
672
721
  return {
673
- canvasAnnotationPage: getAnnotationPage(getCanvases(state, {
722
+ canvasAnnotationPages: getAnnotationPages(getCanvases(state, {
674
723
  windowId: windowId
675
724
  }), getVisibleCanvasIds(state, {
676
725
  windowId: windowId
package/package.json CHANGED
@@ -5,7 +5,7 @@
5
5
  "keywords": [
6
6
  "react-component"
7
7
  ],
8
- "version": "0.0.1",
8
+ "version": "0.0.2",
9
9
  "description": "A Mirador 3 plugin for including authentication cookies for annotations.",
10
10
  "module": "dist/es/index.js",
11
11
  "files": [