@harvard-lts/mirador-citation-plugin 0.0.2 → 0.0.3
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.
- package/dist/es/index.js +685 -85
- package/package.json +1 -1
package/dist/es/index.js
CHANGED
|
@@ -8,16 +8,31 @@ import SanitizedHtml from 'mirador/dist/es/src/containers/SanitizedHtml';
|
|
|
8
8
|
import { PluginHook } from 'mirador/dist/es/src/components/PluginHook';
|
|
9
9
|
import ns from 'mirador/dist/es/src/config/css-ns';
|
|
10
10
|
import List from '@material-ui/core/List';
|
|
11
|
+
import Typography from '@material-ui/core/Typography';
|
|
12
|
+
import Link from '@material-ui/core/Link';
|
|
11
13
|
import ListItem from '@material-ui/core/ListItem';
|
|
12
14
|
import ListItemText from '@material-ui/core/ListItemText';
|
|
13
|
-
import
|
|
14
|
-
import { jsxs, jsx } from 'react/jsx-runtime';
|
|
15
|
+
import { jsx, jsxs } from 'react/jsx-runtime';
|
|
15
16
|
import { withStyles } from '@material-ui/core/styles';
|
|
16
17
|
import { withTranslation } from 'react-i18next';
|
|
17
|
-
import { getManifestTitle } from 'mirador/dist/es/src/state/selectors';
|
|
18
|
+
import { getManifestUrl, getManifestTitle, getAnnotationResourcesByMotivation, getCanvases, getVisibleCanvases, getWindow, getSearchQuery, getCompanionWindowsForPosition, getManifestSearchService, getWindowConfig } from 'mirador/dist/es/src/state/selectors';
|
|
18
19
|
import CitationIcon from '@material-ui/icons/FormatQuote';
|
|
19
|
-
import
|
|
20
|
+
import Icon from '@material-ui/core/Icon';
|
|
20
21
|
import RelatedLinksIcon from '@material-ui/icons/Link';
|
|
22
|
+
import { withStyles as withStyles$1 } from '@material-ui/core';
|
|
23
|
+
import 'mirador/dist/es/src/extend/withPlugins';
|
|
24
|
+
import * as actions from 'mirador/dist/es/src/state/actions';
|
|
25
|
+
import MiradorCanvas from 'mirador/dist/es/src/lib/MiradorCanvas';
|
|
26
|
+
import Badge from '@material-ui/core/Badge';
|
|
27
|
+
import Tabs from '@material-ui/core/Tabs';
|
|
28
|
+
import Tab from '@material-ui/core/Tab';
|
|
29
|
+
import Tooltip from '@material-ui/core/Tooltip';
|
|
30
|
+
import InfoIcon from '@material-ui/icons/InfoSharp';
|
|
31
|
+
import AnnotationIcon from '@material-ui/icons/CommentSharp';
|
|
32
|
+
import AttributionIcon from '@material-ui/icons/CopyrightSharp';
|
|
33
|
+
import LayersIcon from '@material-ui/icons/LayersSharp';
|
|
34
|
+
import SearchIcon from '@material-ui/icons/SearchSharp';
|
|
35
|
+
import CanvasIndexIcon from 'mirador/dist/es/src/components/icons/CanvasIndexIcon';
|
|
21
36
|
|
|
22
37
|
function _assertThisInitialized(e) {
|
|
23
38
|
if (void 0 === e) throw new ReferenceError("this hasn't been initialised - super() hasn't been called");
|
|
@@ -445,6 +460,52 @@ function _toPropertyKey(t) {
|
|
|
445
460
|
return "symbol" == typeof i ? i : i + "";
|
|
446
461
|
}
|
|
447
462
|
|
|
463
|
+
/**
|
|
464
|
+
*/
|
|
465
|
+
function isValidUrl(url) {
|
|
466
|
+
try {
|
|
467
|
+
new URL(url);
|
|
468
|
+
return true;
|
|
469
|
+
} catch (e) {
|
|
470
|
+
return false;
|
|
471
|
+
}
|
|
472
|
+
}
|
|
473
|
+
|
|
474
|
+
function CitationListItem(_ref) {
|
|
475
|
+
var primary = _ref.primary,
|
|
476
|
+
secondary = _ref.secondary,
|
|
477
|
+
i = _ref.i;
|
|
478
|
+
if (primary !== undefined && secondary !== undefined) {
|
|
479
|
+
if (isValidUrl(secondary)) {
|
|
480
|
+
return /*#__PURE__*/jsx(ListItem, {
|
|
481
|
+
button: true,
|
|
482
|
+
component: Link,
|
|
483
|
+
href: secondary,
|
|
484
|
+
target: "_blank",
|
|
485
|
+
rel: "noopener",
|
|
486
|
+
children: /*#__PURE__*/jsx(ListItemText, {
|
|
487
|
+
primary: primary,
|
|
488
|
+
secondary: secondary
|
|
489
|
+
})
|
|
490
|
+
}, i);
|
|
491
|
+
} else {
|
|
492
|
+
return /*#__PURE__*/jsx(ListItem, {
|
|
493
|
+
children: /*#__PURE__*/jsx(ListItemText, {
|
|
494
|
+
primary: primary,
|
|
495
|
+
secondary: secondary
|
|
496
|
+
}, i)
|
|
497
|
+
});
|
|
498
|
+
}
|
|
499
|
+
} else {
|
|
500
|
+
return null;
|
|
501
|
+
}
|
|
502
|
+
}
|
|
503
|
+
CitationListItem.propTypes = {
|
|
504
|
+
primary: PropTypes.string,
|
|
505
|
+
secondary: PropTypes.string,
|
|
506
|
+
i: PropTypes.number
|
|
507
|
+
};
|
|
508
|
+
|
|
448
509
|
var CitationSidePanel = /*#__PURE__*/function (_Component) {
|
|
449
510
|
function CitationSidePanel(props) {
|
|
450
511
|
var _this;
|
|
@@ -554,31 +615,21 @@ var CitationSidePanel = /*#__PURE__*/function (_Component) {
|
|
|
554
615
|
id: "".concat(id, "-resource"),
|
|
555
616
|
label: 'resource',
|
|
556
617
|
children: /*#__PURE__*/jsxs(List, {
|
|
557
|
-
children: [/*#__PURE__*/jsx(
|
|
558
|
-
|
|
559
|
-
|
|
560
|
-
|
|
561
|
-
|
|
562
|
-
|
|
563
|
-
|
|
564
|
-
|
|
565
|
-
|
|
566
|
-
|
|
567
|
-
|
|
568
|
-
|
|
569
|
-
|
|
570
|
-
|
|
571
|
-
|
|
572
|
-
}), /*#__PURE__*/jsx(ListItem, {
|
|
573
|
-
children: /*#__PURE__*/jsx(ListItemText, {
|
|
574
|
-
primary: "Institution:",
|
|
575
|
-
secondary: citationData.institution
|
|
576
|
-
})
|
|
577
|
-
}), /*#__PURE__*/jsx(ListItem, {
|
|
578
|
-
children: /*#__PURE__*/jsx(ListItemText, {
|
|
579
|
-
primary: "Accessed:",
|
|
580
|
-
secondary: citationData.access_date
|
|
581
|
-
})
|
|
618
|
+
children: [/*#__PURE__*/jsx(CitationListItem, {
|
|
619
|
+
primary: "Persistent Link:",
|
|
620
|
+
secondary: citationData.resource_persistent_link
|
|
621
|
+
}), /*#__PURE__*/jsx(CitationListItem, {
|
|
622
|
+
primary: "Description:",
|
|
623
|
+
secondary: manifestTitle
|
|
624
|
+
}), /*#__PURE__*/jsx(CitationListItem, {
|
|
625
|
+
primary: "Repository:",
|
|
626
|
+
secondary: citationData.repository
|
|
627
|
+
}), /*#__PURE__*/jsx(CitationListItem, {
|
|
628
|
+
primary: "Institution:",
|
|
629
|
+
secondary: citationData.institution
|
|
630
|
+
}), /*#__PURE__*/jsx(CitationListItem, {
|
|
631
|
+
primary: "Accessed:",
|
|
632
|
+
secondary: citationData.access_date
|
|
582
633
|
})]
|
|
583
634
|
})
|
|
584
635
|
})
|
|
@@ -603,7 +654,7 @@ CitationSidePanel.defaultProps = {
|
|
|
603
654
|
index: 1
|
|
604
655
|
};
|
|
605
656
|
|
|
606
|
-
var styles$
|
|
657
|
+
var styles$3 = function styles(theme) {
|
|
607
658
|
return {
|
|
608
659
|
section: {
|
|
609
660
|
borderBottom: ".5px solid ".concat(theme.palette.section_divider),
|
|
@@ -620,32 +671,195 @@ var styles$1 = function styles(theme) {
|
|
|
620
671
|
}
|
|
621
672
|
};
|
|
622
673
|
};
|
|
623
|
-
var mapStateToProps$
|
|
624
|
-
var _state$config$
|
|
674
|
+
var mapStateToProps$4 = function mapStateToProps(state, _ref) {
|
|
675
|
+
var _state$config$mirador;
|
|
625
676
|
_ref.id;
|
|
626
677
|
var windowId = _ref.windowId;
|
|
627
678
|
return {
|
|
628
|
-
manifestId: (
|
|
679
|
+
manifestId: getManifestUrl(state, {
|
|
680
|
+
windowId: windowId
|
|
681
|
+
}),
|
|
629
682
|
citationAPI: (_state$config$mirador = state.config.miradorCitationPlugin) === null || _state$config$mirador === void 0 ? void 0 : _state$config$mirador.citationAPI,
|
|
630
683
|
manifestTitle: getManifestTitle(state, {
|
|
631
684
|
windowId: windowId
|
|
632
685
|
})
|
|
633
686
|
};
|
|
634
687
|
};
|
|
635
|
-
var enhance$
|
|
688
|
+
var enhance$4 = compose(withTranslation(), withStyles(styles$3), connect(mapStateToProps$4));
|
|
636
689
|
var CitationPanel = {
|
|
637
|
-
component: enhance$
|
|
690
|
+
component: enhance$4(CitationSidePanel),
|
|
638
691
|
companionWindowKey: 'CitationKey'
|
|
639
692
|
};
|
|
640
693
|
|
|
641
|
-
var
|
|
642
|
-
return
|
|
694
|
+
var styles$2 = function styles(theme) {
|
|
695
|
+
return {
|
|
696
|
+
hideCitationButton: {
|
|
697
|
+
display: 'none'
|
|
698
|
+
}
|
|
699
|
+
};
|
|
643
700
|
};
|
|
701
|
+
var CitationButton = /*#__PURE__*/function (_Component) {
|
|
702
|
+
function CitationButton(props) {
|
|
703
|
+
var _this;
|
|
704
|
+
_classCallCheck(this, CitationButton);
|
|
705
|
+
_this = _callSuper(this, CitationButton, [props]);
|
|
706
|
+
var _this$props = _this.props,
|
|
707
|
+
manifestId = _this$props.manifestId,
|
|
708
|
+
citationAPI = _this$props.citationAPI,
|
|
709
|
+
manifestTitle = _this$props.manifestTitle;
|
|
710
|
+
_this.state = {
|
|
711
|
+
manifestId: manifestId,
|
|
712
|
+
citationAPI: citationAPI,
|
|
713
|
+
manifestTitle: manifestTitle
|
|
714
|
+
};
|
|
715
|
+
return _this;
|
|
716
|
+
}
|
|
717
|
+
_inherits(CitationButton, _Component);
|
|
718
|
+
return _createClass(CitationButton, [{
|
|
719
|
+
key: "componentDidMount",
|
|
720
|
+
value: function () {
|
|
721
|
+
var _componentDidMount = _asyncToGenerator(/*#__PURE__*/_regeneratorRuntime().mark(function _callee() {
|
|
722
|
+
var _this2 = this;
|
|
723
|
+
var _this$state, manifestId, citationAPI, body;
|
|
724
|
+
return _regeneratorRuntime().wrap(function _callee$(_context) {
|
|
725
|
+
while (1) switch (_context.prev = _context.next) {
|
|
726
|
+
case 0:
|
|
727
|
+
_this$state = this.state, manifestId = _this$state.manifestId, citationAPI = _this$state.citationAPI, _this$state.manifestTitle;
|
|
728
|
+
body = {
|
|
729
|
+
"manifest_id": manifestId
|
|
730
|
+
};
|
|
731
|
+
fetch(citationAPI, {
|
|
732
|
+
method: 'post',
|
|
733
|
+
body: JSON.stringify(body),
|
|
734
|
+
headers: {
|
|
735
|
+
'Content-Type': 'application/json'
|
|
736
|
+
}
|
|
737
|
+
}).then(function (response) {
|
|
738
|
+
if (!response.ok) {
|
|
739
|
+
throw new Error('Network response was not ok');
|
|
740
|
+
}
|
|
741
|
+
return response.json();
|
|
742
|
+
}).then(function (citationData) {
|
|
743
|
+
_this2.setState({
|
|
744
|
+
citationData: citationData,
|
|
745
|
+
loading: false
|
|
746
|
+
});
|
|
747
|
+
})["catch"](function (error) {
|
|
748
|
+
console.error('There was a problem receiving the citation:', error);
|
|
749
|
+
_this2.setState({
|
|
750
|
+
loading: false,
|
|
751
|
+
error: error.message
|
|
752
|
+
});
|
|
753
|
+
});
|
|
754
|
+
case 3:
|
|
755
|
+
case "end":
|
|
756
|
+
return _context.stop();
|
|
757
|
+
}
|
|
758
|
+
}, _callee, this);
|
|
759
|
+
}));
|
|
760
|
+
function componentDidMount() {
|
|
761
|
+
return _componentDidMount.apply(this, arguments);
|
|
762
|
+
}
|
|
763
|
+
return componentDidMount;
|
|
764
|
+
}()
|
|
765
|
+
}, {
|
|
766
|
+
key: "render",
|
|
767
|
+
value: function render() {
|
|
768
|
+
var _this$props2 = this.props,
|
|
769
|
+
classes = _this$props2.classes,
|
|
770
|
+
windowId = _this$props2.windowId;
|
|
771
|
+
var _this$state2 = this.state,
|
|
772
|
+
citationData = _this$state2.citationData;
|
|
773
|
+
_this$state2.loading;
|
|
774
|
+
_this$state2.error;
|
|
775
|
+
if (citationData) {
|
|
776
|
+
if (!citationData.error) {
|
|
777
|
+
return /*#__PURE__*/jsx("div", {
|
|
778
|
+
children: /*#__PURE__*/jsx(CitationIcon, {})
|
|
779
|
+
});
|
|
780
|
+
} else {
|
|
781
|
+
return /*#__PURE__*/jsxs("div", {
|
|
782
|
+
className: classes.hideCitationButton,
|
|
783
|
+
children: [/*#__PURE__*/jsx("style", {
|
|
784
|
+
children: "\n section[id=\"" + windowId + "\"] button[title=\"Cite\"] { display: none }\n "
|
|
785
|
+
}), /*#__PURE__*/jsx(Icon, {})]
|
|
786
|
+
});
|
|
787
|
+
}
|
|
788
|
+
} else {
|
|
789
|
+
return /*#__PURE__*/jsxs("div", {
|
|
790
|
+
className: classes.hideCitationButton,
|
|
791
|
+
children: [/*#__PURE__*/jsx("style", {
|
|
792
|
+
children: "\n section[id=\"" + windowId + "\"] button[title=\"Cite\"] { display: none }\n "
|
|
793
|
+
}), /*#__PURE__*/jsx(Icon, {})]
|
|
794
|
+
});
|
|
795
|
+
}
|
|
796
|
+
}
|
|
797
|
+
}]);
|
|
798
|
+
}(Component);
|
|
644
799
|
CitationButton.value = 'CitationKey';
|
|
800
|
+
var mapStateToProps$3 = function mapStateToProps(state, _ref) {
|
|
801
|
+
var _state$config$mirador;
|
|
802
|
+
var windowId = _ref.windowId;
|
|
803
|
+
var manifestId = getManifestUrl(state, {
|
|
804
|
+
windowId: windowId
|
|
805
|
+
});
|
|
806
|
+
var citationAPI = (_state$config$mirador = state.config.miradorCitationPlugin) === null || _state$config$mirador === void 0 ? void 0 : _state$config$mirador.citationAPI;
|
|
807
|
+
var manifestTitle = getManifestTitle(state, {
|
|
808
|
+
windowId: windowId
|
|
809
|
+
});
|
|
810
|
+
return {
|
|
811
|
+
manifestId: manifestId,
|
|
812
|
+
citationAPI: citationAPI,
|
|
813
|
+
manifestTitle: manifestTitle
|
|
814
|
+
};
|
|
815
|
+
};
|
|
816
|
+
var enhance$3 = compose(withStyles(styles$2), connect(mapStateToProps$3));
|
|
817
|
+
CitationButton.propTypes = {
|
|
818
|
+
classes: PropTypes.objectOf(PropTypes.string),
|
|
819
|
+
manifestId: PropTypes.string,
|
|
820
|
+
citationAPI: PropTypes.string,
|
|
821
|
+
manifestTitle: PropTypes.string
|
|
822
|
+
};
|
|
823
|
+
CitationButton.defaultProps = {
|
|
824
|
+
classes: {},
|
|
825
|
+
manifestId: null,
|
|
826
|
+
citationAPI: null,
|
|
827
|
+
manifestTitle: null
|
|
828
|
+
};
|
|
645
829
|
var CitationButton$1 = {
|
|
646
830
|
target: 'WindowSideBarButtons',
|
|
831
|
+
name: 'WindowSideBarCitationButton',
|
|
647
832
|
mode: 'add',
|
|
648
|
-
component: CitationButton
|
|
833
|
+
component: enhance$3(CitationButton)
|
|
834
|
+
};
|
|
835
|
+
|
|
836
|
+
function CitationSection(_ref) {
|
|
837
|
+
var id = _ref.id,
|
|
838
|
+
label = _ref.label,
|
|
839
|
+
links = _ref.links;
|
|
840
|
+
if (!links) {
|
|
841
|
+
return null;
|
|
842
|
+
} else if (links.length === 0) {
|
|
843
|
+
return null;
|
|
844
|
+
} else {
|
|
845
|
+
return /*#__PURE__*/jsx(CollapsibleSection, {
|
|
846
|
+
id: "".concat(id, "-").concat(id),
|
|
847
|
+
label: "".concat(label),
|
|
848
|
+
children: /*#__PURE__*/jsx(List, {
|
|
849
|
+
children: links.map(function (link, i) {
|
|
850
|
+
return /*#__PURE__*/jsx(CitationListItem, {
|
|
851
|
+
primary: link.label,
|
|
852
|
+
secondary: link.link
|
|
853
|
+
}, i);
|
|
854
|
+
})
|
|
855
|
+
})
|
|
856
|
+
});
|
|
857
|
+
}
|
|
858
|
+
}
|
|
859
|
+
CitationSection.propTypes = {
|
|
860
|
+
id: PropTypes.string.isRequired,
|
|
861
|
+
label: PropTypes.string.isRequired,
|
|
862
|
+
links: PropTypes.arrayOf(PropTypes.object)
|
|
649
863
|
};
|
|
650
864
|
|
|
651
865
|
var RelatedLinksSidePanel = /*#__PURE__*/function (_Component) {
|
|
@@ -764,42 +978,14 @@ var RelatedLinksSidePanel = /*#__PURE__*/function (_Component) {
|
|
|
764
978
|
})]
|
|
765
979
|
}), citationData && /*#__PURE__*/jsxs("div", {
|
|
766
980
|
className: classes.section,
|
|
767
|
-
children: [/*#__PURE__*/jsx(
|
|
768
|
-
id: "
|
|
769
|
-
label:
|
|
770
|
-
|
|
771
|
-
|
|
772
|
-
|
|
773
|
-
|
|
774
|
-
|
|
775
|
-
href: metadataLink.link,
|
|
776
|
-
target: "_blank",
|
|
777
|
-
rel: "noopener",
|
|
778
|
-
children: /*#__PURE__*/jsx(ListItemText, {
|
|
779
|
-
primary: metadataLink.label,
|
|
780
|
-
secondary: metadataLink.link
|
|
781
|
-
})
|
|
782
|
-
}, i);
|
|
783
|
-
})
|
|
784
|
-
})
|
|
785
|
-
}), /*#__PURE__*/jsx(CollapsibleSection, {
|
|
786
|
-
id: "".concat(id, "-related-links"),
|
|
787
|
-
label: 'related links',
|
|
788
|
-
children: /*#__PURE__*/jsx(List, {
|
|
789
|
-
children: citationData.related_links.map(function (relatedLink, i) {
|
|
790
|
-
return /*#__PURE__*/jsx(ListItem, {
|
|
791
|
-
button: true,
|
|
792
|
-
component: Link,
|
|
793
|
-
href: relatedLink.link,
|
|
794
|
-
target: "_blank",
|
|
795
|
-
rel: "noopener",
|
|
796
|
-
children: /*#__PURE__*/jsx(ListItemText, {
|
|
797
|
-
primary: relatedLink.label,
|
|
798
|
-
secondary: relatedLink.link
|
|
799
|
-
})
|
|
800
|
-
}, i);
|
|
801
|
-
})
|
|
802
|
-
})
|
|
981
|
+
children: [/*#__PURE__*/jsx(CitationSection, {
|
|
982
|
+
id: "harvard-metadata",
|
|
983
|
+
label: "harvard metadata",
|
|
984
|
+
links: citationData.harvard_metadata_links
|
|
985
|
+
}), /*#__PURE__*/jsx(CitationSection, {
|
|
986
|
+
id: "related-links",
|
|
987
|
+
label: "related links",
|
|
988
|
+
links: citationData.related_links
|
|
803
989
|
})]
|
|
804
990
|
}), /*#__PURE__*/jsx(PluginHook, _objectSpread2({}, this.props))]
|
|
805
991
|
});
|
|
@@ -820,7 +1006,7 @@ RelatedLinksSidePanel.defaultProps = {
|
|
|
820
1006
|
index: 1
|
|
821
1007
|
};
|
|
822
1008
|
|
|
823
|
-
var styles = function styles(theme) {
|
|
1009
|
+
var styles$1 = function styles(theme) {
|
|
824
1010
|
return {
|
|
825
1011
|
section: {
|
|
826
1012
|
borderBottom: ".5px solid ".concat(theme.palette.section_divider),
|
|
@@ -837,34 +1023,448 @@ var styles = function styles(theme) {
|
|
|
837
1023
|
}
|
|
838
1024
|
};
|
|
839
1025
|
};
|
|
840
|
-
var mapStateToProps = function mapStateToProps(state, _ref) {
|
|
841
|
-
var _state$config$
|
|
1026
|
+
var mapStateToProps$2 = function mapStateToProps(state, _ref) {
|
|
1027
|
+
var _state$config$mirador;
|
|
842
1028
|
_ref.id;
|
|
843
1029
|
var windowId = _ref.windowId;
|
|
844
1030
|
return {
|
|
845
|
-
manifestId: (
|
|
1031
|
+
manifestId: getManifestUrl(state, {
|
|
1032
|
+
windowId: windowId
|
|
1033
|
+
}),
|
|
846
1034
|
citationAPI: (_state$config$mirador = state.config.miradorCitationPlugin) === null || _state$config$mirador === void 0 ? void 0 : _state$config$mirador.citationAPI,
|
|
847
1035
|
manifestTitle: getManifestTitle(state, {
|
|
848
1036
|
windowId: windowId
|
|
849
1037
|
})
|
|
850
1038
|
};
|
|
851
1039
|
};
|
|
852
|
-
var enhance = compose(withTranslation(), withStyles(styles), connect(mapStateToProps));
|
|
1040
|
+
var enhance$2 = compose(withTranslation(), withStyles(styles$1), connect(mapStateToProps$2));
|
|
853
1041
|
var RelatedLinksPanel = {
|
|
854
|
-
component: enhance(RelatedLinksSidePanel),
|
|
1042
|
+
component: enhance$2(RelatedLinksSidePanel),
|
|
855
1043
|
companionWindowKey: 'RelatedLinksKey'
|
|
856
1044
|
};
|
|
857
1045
|
|
|
858
|
-
var
|
|
859
|
-
return
|
|
1046
|
+
var styles = function styles(theme) {
|
|
1047
|
+
return {
|
|
1048
|
+
hideRelatedLinksButton: {
|
|
1049
|
+
display: 'none'
|
|
1050
|
+
}
|
|
1051
|
+
};
|
|
860
1052
|
};
|
|
1053
|
+
var RelatedLinksButton = /*#__PURE__*/function (_Component) {
|
|
1054
|
+
function RelatedLinksButton(props) {
|
|
1055
|
+
var _this;
|
|
1056
|
+
_classCallCheck(this, RelatedLinksButton);
|
|
1057
|
+
_this = _callSuper(this, RelatedLinksButton, [props]);
|
|
1058
|
+
var _this$props = _this.props,
|
|
1059
|
+
manifestId = _this$props.manifestId,
|
|
1060
|
+
citationAPI = _this$props.citationAPI,
|
|
1061
|
+
manifestTitle = _this$props.manifestTitle;
|
|
1062
|
+
_this.state = {
|
|
1063
|
+
manifestId: manifestId,
|
|
1064
|
+
citationAPI: citationAPI,
|
|
1065
|
+
manifestTitle: manifestTitle
|
|
1066
|
+
};
|
|
1067
|
+
return _this;
|
|
1068
|
+
}
|
|
1069
|
+
_inherits(RelatedLinksButton, _Component);
|
|
1070
|
+
return _createClass(RelatedLinksButton, [{
|
|
1071
|
+
key: "componentDidMount",
|
|
1072
|
+
value: function () {
|
|
1073
|
+
var _componentDidMount = _asyncToGenerator(/*#__PURE__*/_regeneratorRuntime().mark(function _callee() {
|
|
1074
|
+
var _this2 = this;
|
|
1075
|
+
var _this$state, manifestId, citationAPI, body;
|
|
1076
|
+
return _regeneratorRuntime().wrap(function _callee$(_context) {
|
|
1077
|
+
while (1) switch (_context.prev = _context.next) {
|
|
1078
|
+
case 0:
|
|
1079
|
+
_this$state = this.state, manifestId = _this$state.manifestId, citationAPI = _this$state.citationAPI, _this$state.manifestTitle;
|
|
1080
|
+
body = {
|
|
1081
|
+
"manifest_id": manifestId
|
|
1082
|
+
};
|
|
1083
|
+
fetch(citationAPI, {
|
|
1084
|
+
method: 'post',
|
|
1085
|
+
body: JSON.stringify(body),
|
|
1086
|
+
headers: {
|
|
1087
|
+
'Content-Type': 'application/json'
|
|
1088
|
+
}
|
|
1089
|
+
}).then(function (response) {
|
|
1090
|
+
if (!response.ok) {
|
|
1091
|
+
throw new Error('Network response was not ok');
|
|
1092
|
+
}
|
|
1093
|
+
return response.json();
|
|
1094
|
+
}).then(function (citationData) {
|
|
1095
|
+
_this2.setState({
|
|
1096
|
+
citationData: citationData,
|
|
1097
|
+
loading: false
|
|
1098
|
+
});
|
|
1099
|
+
})["catch"](function (error) {
|
|
1100
|
+
console.error('There was a problem receiving the citation:', error);
|
|
1101
|
+
_this2.setState({
|
|
1102
|
+
loading: false,
|
|
1103
|
+
error: error.message
|
|
1104
|
+
});
|
|
1105
|
+
});
|
|
1106
|
+
case 3:
|
|
1107
|
+
case "end":
|
|
1108
|
+
return _context.stop();
|
|
1109
|
+
}
|
|
1110
|
+
}, _callee, this);
|
|
1111
|
+
}));
|
|
1112
|
+
function componentDidMount() {
|
|
1113
|
+
return _componentDidMount.apply(this, arguments);
|
|
1114
|
+
}
|
|
1115
|
+
return componentDidMount;
|
|
1116
|
+
}()
|
|
1117
|
+
}, {
|
|
1118
|
+
key: "render",
|
|
1119
|
+
value: function render() {
|
|
1120
|
+
var _this$props2 = this.props,
|
|
1121
|
+
classes = _this$props2.classes,
|
|
1122
|
+
windowId = _this$props2.windowId;
|
|
1123
|
+
var _this$state2 = this.state,
|
|
1124
|
+
citationData = _this$state2.citationData;
|
|
1125
|
+
_this$state2.loading;
|
|
1126
|
+
_this$state2.error;
|
|
1127
|
+
if (citationData) {
|
|
1128
|
+
if (!citationData.error) {
|
|
1129
|
+
return /*#__PURE__*/jsx("div", {
|
|
1130
|
+
children: /*#__PURE__*/jsx(RelatedLinksIcon, {})
|
|
1131
|
+
});
|
|
1132
|
+
} else {
|
|
1133
|
+
return /*#__PURE__*/jsxs("div", {
|
|
1134
|
+
className: classes.hideRelatedLinksButton,
|
|
1135
|
+
children: [/*#__PURE__*/jsx("style", {
|
|
1136
|
+
children: "\n section[id=\"" + windowId + "\"] button[title=\"Related Links\"] { display: none }\n "
|
|
1137
|
+
}), /*#__PURE__*/jsx(Icon, {})]
|
|
1138
|
+
});
|
|
1139
|
+
}
|
|
1140
|
+
} else {
|
|
1141
|
+
return /*#__PURE__*/jsxs("div", {
|
|
1142
|
+
className: classes.hideRelatedLinksButton,
|
|
1143
|
+
children: [/*#__PURE__*/jsx("style", {
|
|
1144
|
+
children: "\n section[id=\"" + windowId + "\"] button[title=\"Related Links\"] { display: none }\n "
|
|
1145
|
+
}), /*#__PURE__*/jsx(Icon, {})]
|
|
1146
|
+
});
|
|
1147
|
+
}
|
|
1148
|
+
}
|
|
1149
|
+
}]);
|
|
1150
|
+
}(Component);
|
|
861
1151
|
RelatedLinksButton.value = 'RelatedLinksKey';
|
|
1152
|
+
var mapStateToProps$1 = function mapStateToProps(state, _ref) {
|
|
1153
|
+
var _state$config$mirador;
|
|
1154
|
+
var windowId = _ref.windowId;
|
|
1155
|
+
var manifestId = getManifestUrl(state, {
|
|
1156
|
+
windowId: windowId
|
|
1157
|
+
});
|
|
1158
|
+
var citationAPI = (_state$config$mirador = state.config.miradorCitationPlugin) === null || _state$config$mirador === void 0 ? void 0 : _state$config$mirador.citationAPI;
|
|
1159
|
+
var manifestTitle = getManifestTitle(state, {
|
|
1160
|
+
windowId: windowId
|
|
1161
|
+
});
|
|
1162
|
+
return {
|
|
1163
|
+
manifestId: manifestId,
|
|
1164
|
+
citationAPI: citationAPI,
|
|
1165
|
+
manifestTitle: manifestTitle
|
|
1166
|
+
};
|
|
1167
|
+
};
|
|
1168
|
+
var enhance$1 = compose(withStyles(styles), connect(mapStateToProps$1));
|
|
1169
|
+
RelatedLinksButton.propTypes = {
|
|
1170
|
+
classes: PropTypes.objectOf(PropTypes.string),
|
|
1171
|
+
manifestId: PropTypes.string,
|
|
1172
|
+
citationAPI: PropTypes.string,
|
|
1173
|
+
manifestTitle: PropTypes.string
|
|
1174
|
+
};
|
|
1175
|
+
RelatedLinksButton.defaultProps = {
|
|
1176
|
+
classes: {},
|
|
1177
|
+
manifestId: null,
|
|
1178
|
+
citationAPI: null,
|
|
1179
|
+
manifestTitle: null
|
|
1180
|
+
};
|
|
862
1181
|
var RelatedLinksButton$1 = {
|
|
863
1182
|
target: 'WindowSideBarButtons',
|
|
1183
|
+
name: 'WindowSideBarRelatedLinksButton',
|
|
864
1184
|
mode: 'add',
|
|
865
|
-
component: RelatedLinksButton
|
|
1185
|
+
component: enhance$1(RelatedLinksButton)
|
|
1186
|
+
};
|
|
1187
|
+
|
|
1188
|
+
var WindowSideBarButtons = /*#__PURE__*/function (_Component) {
|
|
1189
|
+
/** */
|
|
1190
|
+
function WindowSideBarButtons(props) {
|
|
1191
|
+
var _this;
|
|
1192
|
+
_classCallCheck(this, WindowSideBarButtons);
|
|
1193
|
+
_this = _callSuper(this, WindowSideBarButtons, [props]);
|
|
1194
|
+
_this.handleChange = _this.handleChange.bind(_this);
|
|
1195
|
+
return _this;
|
|
1196
|
+
}
|
|
1197
|
+
|
|
1198
|
+
/**
|
|
1199
|
+
* @param {object} event the change event
|
|
1200
|
+
* @param {string} value the tab's value
|
|
1201
|
+
*/
|
|
1202
|
+
_inherits(WindowSideBarButtons, _Component);
|
|
1203
|
+
return _createClass(WindowSideBarButtons, [{
|
|
1204
|
+
key: "handleChange",
|
|
1205
|
+
value: function handleChange(event, value) {
|
|
1206
|
+
var addCompanionWindow = this.props.addCompanionWindow;
|
|
1207
|
+
addCompanionWindow(value);
|
|
1208
|
+
}
|
|
1209
|
+
|
|
1210
|
+
/**
|
|
1211
|
+
* render
|
|
1212
|
+
*
|
|
1213
|
+
* @return {type} description
|
|
1214
|
+
*/
|
|
1215
|
+
}, {
|
|
1216
|
+
key: "render",
|
|
1217
|
+
value: function render() {
|
|
1218
|
+
var _this2 = this;
|
|
1219
|
+
var _this$props = this.props,
|
|
1220
|
+
classes = _this$props.classes,
|
|
1221
|
+
hasAnnotations = _this$props.hasAnnotations,
|
|
1222
|
+
hasAnyAnnotations = _this$props.hasAnyAnnotations,
|
|
1223
|
+
hasAnyLayers = _this$props.hasAnyLayers,
|
|
1224
|
+
hasCurrentLayers = _this$props.hasCurrentLayers,
|
|
1225
|
+
hasSearchResults = _this$props.hasSearchResults,
|
|
1226
|
+
hasSearchService = _this$props.hasSearchService,
|
|
1227
|
+
panels = _this$props.panels,
|
|
1228
|
+
PluginComponents = _this$props.PluginComponents,
|
|
1229
|
+
sideBarPanel = _this$props.sideBarPanel,
|
|
1230
|
+
t = _this$props.t,
|
|
1231
|
+
windowId = _this$props.windowId;
|
|
1232
|
+
|
|
1233
|
+
/** */
|
|
1234
|
+
var TabButton = function TabButton(props) {
|
|
1235
|
+
return /*#__PURE__*/jsx(Tooltip, {
|
|
1236
|
+
title: t('openCompanionWindow', {
|
|
1237
|
+
context: props.value
|
|
1238
|
+
}),
|
|
1239
|
+
children: /*#__PURE__*/jsx(Tab, _objectSpread2(_objectSpread2({}, props), {}, {
|
|
1240
|
+
classes: {
|
|
1241
|
+
root: classes.tab,
|
|
1242
|
+
selected: classes.tabSelected
|
|
1243
|
+
},
|
|
1244
|
+
"aria-label": t('openCompanionWindow', {
|
|
1245
|
+
context: props.value
|
|
1246
|
+
}),
|
|
1247
|
+
disableRipple: true,
|
|
1248
|
+
onKeyUp: _this2.handleKeyUp
|
|
1249
|
+
}))
|
|
1250
|
+
});
|
|
1251
|
+
};
|
|
1252
|
+
return /*#__PURE__*/jsxs(Tabs, {
|
|
1253
|
+
classes: {
|
|
1254
|
+
flexContainer: classes.tabsFlexContainer,
|
|
1255
|
+
indicator: classes.tabsIndicator
|
|
1256
|
+
},
|
|
1257
|
+
value: sideBarPanel === 'closed' ? false : sideBarPanel,
|
|
1258
|
+
onChange: this.handleChange,
|
|
1259
|
+
variant: "fullWidth",
|
|
1260
|
+
indicatorColor: "primary",
|
|
1261
|
+
textColor: "primary",
|
|
1262
|
+
orientation: "vertical",
|
|
1263
|
+
"aria-orientation": "vertical",
|
|
1264
|
+
"aria-label": t('sidebarPanelsNavigation'),
|
|
1265
|
+
children: [panels.info && /*#__PURE__*/jsx(TabButton, {
|
|
1266
|
+
value: "info",
|
|
1267
|
+
icon: /*#__PURE__*/jsx(InfoIcon, {})
|
|
1268
|
+
}), panels.attribution && /*#__PURE__*/jsx(TabButton, {
|
|
1269
|
+
value: "attribution",
|
|
1270
|
+
icon: /*#__PURE__*/jsx(AttributionIcon, {})
|
|
1271
|
+
}), panels.canvas && /*#__PURE__*/jsx(TabButton, {
|
|
1272
|
+
value: "canvas",
|
|
1273
|
+
icon: /*#__PURE__*/jsx(CanvasIndexIcon, {})
|
|
1274
|
+
}), panels.annotations && (hasAnnotations || hasAnyAnnotations) && /*#__PURE__*/jsx(TabButton, {
|
|
1275
|
+
value: "annotations",
|
|
1276
|
+
icon: /*#__PURE__*/jsx(Badge, {
|
|
1277
|
+
classes: {
|
|
1278
|
+
badge: classes.badge
|
|
1279
|
+
},
|
|
1280
|
+
invisible: !hasAnnotations,
|
|
1281
|
+
variant: "dot",
|
|
1282
|
+
children: /*#__PURE__*/jsx(AnnotationIcon, {})
|
|
1283
|
+
})
|
|
1284
|
+
}), panels.search && hasSearchService && /*#__PURE__*/jsx(TabButton, {
|
|
1285
|
+
value: "search",
|
|
1286
|
+
icon: /*#__PURE__*/jsx(Badge, {
|
|
1287
|
+
classes: {
|
|
1288
|
+
badge: classes.badge
|
|
1289
|
+
},
|
|
1290
|
+
invisible: !hasSearchResults,
|
|
1291
|
+
variant: "dot",
|
|
1292
|
+
children: /*#__PURE__*/jsx(SearchIcon, {})
|
|
1293
|
+
})
|
|
1294
|
+
}), panels.layers && hasAnyLayers && /*#__PURE__*/jsx(TabButton, {
|
|
1295
|
+
value: "layers",
|
|
1296
|
+
icon: /*#__PURE__*/jsx(Badge, {
|
|
1297
|
+
classes: {
|
|
1298
|
+
badge: classes.badge
|
|
1299
|
+
},
|
|
1300
|
+
invisible: !hasCurrentLayers,
|
|
1301
|
+
variant: "dot",
|
|
1302
|
+
children: /*#__PURE__*/jsx(LayersIcon, {})
|
|
1303
|
+
})
|
|
1304
|
+
}), PluginComponents && PluginComponents.map(function (PluginComponent) {
|
|
1305
|
+
return /*#__PURE__*/jsx(TabButton, {
|
|
1306
|
+
value: PluginComponent.value,
|
|
1307
|
+
icon: /*#__PURE__*/jsx(PluginComponent, {
|
|
1308
|
+
windowId: windowId
|
|
1309
|
+
})
|
|
1310
|
+
}, PluginComponent.value);
|
|
1311
|
+
})]
|
|
1312
|
+
});
|
|
1313
|
+
}
|
|
1314
|
+
}]);
|
|
1315
|
+
}(Component);
|
|
1316
|
+
WindowSideBarButtons.propTypes = {
|
|
1317
|
+
addCompanionWindow: PropTypes.func.isRequired,
|
|
1318
|
+
classes: PropTypes.objectOf(PropTypes.string),
|
|
1319
|
+
hasAnnotations: PropTypes.bool,
|
|
1320
|
+
hasAnyAnnotations: PropTypes.bool,
|
|
1321
|
+
hasAnyLayers: PropTypes.bool,
|
|
1322
|
+
hasCurrentLayers: PropTypes.bool,
|
|
1323
|
+
hasSearchResults: PropTypes.bool,
|
|
1324
|
+
hasSearchService: PropTypes.bool,
|
|
1325
|
+
panels: PropTypes.arrayOf(PropTypes.bool),
|
|
1326
|
+
PluginComponents: PropTypes.array,
|
|
1327
|
+
// eslint-disable-line react/forbid-prop-types
|
|
1328
|
+
sideBarPanel: PropTypes.string,
|
|
1329
|
+
t: PropTypes.func
|
|
1330
|
+
};
|
|
1331
|
+
WindowSideBarButtons.defaultProps = {
|
|
1332
|
+
classes: {},
|
|
1333
|
+
hasAnnotations: false,
|
|
1334
|
+
hasAnyAnnotations: false,
|
|
1335
|
+
hasAnyLayers: false,
|
|
1336
|
+
hasCurrentLayers: false,
|
|
1337
|
+
hasSearchResults: false,
|
|
1338
|
+
hasSearchService: false,
|
|
1339
|
+
panels: [],
|
|
1340
|
+
PluginComponents: null,
|
|
1341
|
+
sideBarPanel: 'closed',
|
|
1342
|
+
t: function t(key) {
|
|
1343
|
+
return key;
|
|
1344
|
+
}
|
|
1345
|
+
};
|
|
1346
|
+
|
|
1347
|
+
/**
|
|
1348
|
+
* mapDispatchToProps - used to hook up connect to action creators
|
|
1349
|
+
* @memberof WindowSideButtons
|
|
1350
|
+
* @private
|
|
1351
|
+
*/
|
|
1352
|
+
var mapDispatchToProps = function mapDispatchToProps(dispatch, _ref) {
|
|
1353
|
+
var windowId = _ref.windowId;
|
|
1354
|
+
return {
|
|
1355
|
+
addCompanionWindow: function addCompanionWindow(content) {
|
|
1356
|
+
return dispatch(actions.addOrUpdateCompanionWindow(windowId, {
|
|
1357
|
+
content: content,
|
|
1358
|
+
position: 'left'
|
|
1359
|
+
}));
|
|
1360
|
+
}
|
|
1361
|
+
};
|
|
1362
|
+
};
|
|
1363
|
+
|
|
1364
|
+
/** */
|
|
1365
|
+
function hasLayers(canvases) {
|
|
1366
|
+
return canvases && canvases.some(function (c) {
|
|
1367
|
+
return new MiradorCanvas(c).imageResources.length > 1;
|
|
1368
|
+
});
|
|
1369
|
+
}
|
|
1370
|
+
|
|
1371
|
+
/** */
|
|
1372
|
+
function hasAnnotations(canvases) {
|
|
1373
|
+
return canvases && canvases.some(function (c) {
|
|
1374
|
+
var canvas = new MiradorCanvas(c);
|
|
1375
|
+
return canvas.annotationListUris.length > 0 || canvas.canvasAnnotationPages.length > 0;
|
|
1376
|
+
});
|
|
1377
|
+
}
|
|
1378
|
+
|
|
1379
|
+
/**
|
|
1380
|
+
* mapStateToProps - used to hook up connect to state
|
|
1381
|
+
* @memberof WindowSideButtons
|
|
1382
|
+
* @private
|
|
1383
|
+
*/
|
|
1384
|
+
var mapStateToProps = function mapStateToProps(state, _ref2) {
|
|
1385
|
+
var windowId = _ref2.windowId;
|
|
1386
|
+
return {
|
|
1387
|
+
hasAnnotations: getAnnotationResourcesByMotivation(state, {
|
|
1388
|
+
windowId: windowId
|
|
1389
|
+
}).length > 0,
|
|
1390
|
+
hasAnyAnnotations: hasAnnotations(getCanvases(state, {
|
|
1391
|
+
windowId: windowId
|
|
1392
|
+
})),
|
|
1393
|
+
hasAnyLayers: hasLayers(getCanvases(state, {
|
|
1394
|
+
windowId: windowId
|
|
1395
|
+
})),
|
|
1396
|
+
hasCurrentLayers: hasLayers(getVisibleCanvases(state, {
|
|
1397
|
+
windowId: windowId
|
|
1398
|
+
})),
|
|
1399
|
+
hasSearchResults: getWindow(state, {
|
|
1400
|
+
windowId: windowId
|
|
1401
|
+
}).suggestedSearches || getSearchQuery(state, {
|
|
1402
|
+
companionWindowId: (getCompanionWindowsForPosition(state, {
|
|
1403
|
+
position: 'left',
|
|
1404
|
+
windowId: windowId
|
|
1405
|
+
})[0] || {}).id,
|
|
1406
|
+
windowId: windowId
|
|
1407
|
+
}),
|
|
1408
|
+
hasSearchService: getManifestSearchService(state, {
|
|
1409
|
+
windowId: windowId
|
|
1410
|
+
}) !== null,
|
|
1411
|
+
panels: getWindowConfig(state, {
|
|
1412
|
+
windowId: windowId
|
|
1413
|
+
}).panels,
|
|
1414
|
+
sideBarPanel: (getCompanionWindowsForPosition(state, {
|
|
1415
|
+
position: 'left',
|
|
1416
|
+
windowId: windowId
|
|
1417
|
+
})[0] || {}).content
|
|
1418
|
+
};
|
|
1419
|
+
};
|
|
1420
|
+
|
|
1421
|
+
/** */
|
|
1422
|
+
var style = function style(theme) {
|
|
1423
|
+
return {
|
|
1424
|
+
badge: {
|
|
1425
|
+
backgroundColor: theme.palette.notification.main
|
|
1426
|
+
},
|
|
1427
|
+
tab: {
|
|
1428
|
+
'&:active': {
|
|
1429
|
+
backgroundColor: theme.palette.action.active
|
|
1430
|
+
},
|
|
1431
|
+
'&:focus': {
|
|
1432
|
+
'@media (hover: none)': {
|
|
1433
|
+
backgroundColor: 'transparent'
|
|
1434
|
+
},
|
|
1435
|
+
backgroundColor: theme.palette.action.hover,
|
|
1436
|
+
textDecoration: 'none'
|
|
1437
|
+
// Reset on touch devices, it doesn't add specificity
|
|
1438
|
+
},
|
|
1439
|
+
'&:hover': {
|
|
1440
|
+
'@media (hover: none)': {
|
|
1441
|
+
backgroundColor: 'transparent'
|
|
1442
|
+
},
|
|
1443
|
+
backgroundColor: theme.palette.action.hover,
|
|
1444
|
+
textDecoration: 'none'
|
|
1445
|
+
// Reset on touch devices, it doesn't add specificity
|
|
1446
|
+
},
|
|
1447
|
+
borderRight: '2px solid transparent',
|
|
1448
|
+
minWidth: 'auto'
|
|
1449
|
+
},
|
|
1450
|
+
tabSelected: {
|
|
1451
|
+
borderRight: "2px solid ".concat(theme.palette.primary.main)
|
|
1452
|
+
},
|
|
1453
|
+
tabsFlexContainer: {
|
|
1454
|
+
flexDirection: 'column'
|
|
1455
|
+
},
|
|
1456
|
+
tabsIndicator: {
|
|
1457
|
+
display: 'none'
|
|
1458
|
+
}
|
|
1459
|
+
};
|
|
1460
|
+
};
|
|
1461
|
+
var enhance = compose(withTranslation(), withStyles$1(style), connect(mapStateToProps, mapDispatchToProps));
|
|
1462
|
+
var WindowSidebarButtons = {
|
|
1463
|
+
target: 'WindowSideBarButtons',
|
|
1464
|
+
mode: 'wrap',
|
|
1465
|
+
component: enhance(WindowSideBarButtons)
|
|
866
1466
|
};
|
|
867
1467
|
|
|
868
|
-
var index = [CitationPanel, CitationButton$1, RelatedLinksPanel, RelatedLinksButton$1];
|
|
1468
|
+
var index = [CitationPanel, CitationButton$1, RelatedLinksPanel, RelatedLinksButton$1, WindowSidebarButtons];
|
|
869
1469
|
|
|
870
|
-
export { CitationButton$1 as CitationButton, CitationPanel, RelatedLinksButton$1 as RelatedLinksButton, RelatedLinksPanel, index as default };
|
|
1470
|
+
export { CitationButton$1 as CitationButton, CitationPanel, RelatedLinksButton$1 as RelatedLinksButton, RelatedLinksPanel, WindowSidebarButtons, index as default };
|