@harvard-lts/mirador-citation-plugin 0.0.4 → 0.0.5
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 +240 -94
- package/package.json +1 -1
package/dist/es/index.js
CHANGED
|
@@ -646,75 +646,148 @@ var CitationButton = /*#__PURE__*/function (_Component) {
|
|
|
646
646
|
var _this;
|
|
647
647
|
_classCallCheck(this, CitationButton);
|
|
648
648
|
_this = _callSuper(this, CitationButton, [props]);
|
|
649
|
-
|
|
650
|
-
|
|
651
|
-
|
|
652
|
-
manifestTitle = _this$props.manifestTitle;
|
|
653
|
-
_this.state = {
|
|
654
|
-
manifestId: manifestId,
|
|
655
|
-
citationAPI: citationAPI,
|
|
656
|
-
manifestTitle: manifestTitle
|
|
657
|
-
};
|
|
658
|
-
return _this;
|
|
659
|
-
}
|
|
660
|
-
_inherits(CitationButton, _Component);
|
|
661
|
-
return _createClass(CitationButton, [{
|
|
662
|
-
key: "componentDidMount",
|
|
663
|
-
value: function () {
|
|
664
|
-
var _componentDidMount = _asyncToGenerator(/*#__PURE__*/_regeneratorRuntime().mark(function _callee() {
|
|
665
|
-
var _this2 = this;
|
|
666
|
-
var _this$state, manifestId, citationAPI, body;
|
|
649
|
+
_defineProperty(_this, "fetchCitationData", /*#__PURE__*/function () {
|
|
650
|
+
var _ref = _asyncToGenerator(/*#__PURE__*/_regeneratorRuntime().mark(function _callee(manifestId, citationAPI) {
|
|
651
|
+
var body, response, citationData;
|
|
667
652
|
return _regeneratorRuntime().wrap(function _callee$(_context) {
|
|
668
653
|
while (1) switch (_context.prev = _context.next) {
|
|
669
654
|
case 0:
|
|
670
|
-
_this$state = this.state, manifestId = _this$state.manifestId, citationAPI = _this$state.citationAPI, _this$state.manifestTitle;
|
|
671
655
|
body = {
|
|
672
656
|
"manifest_id": manifestId
|
|
673
657
|
};
|
|
674
|
-
|
|
658
|
+
_context.prev = 1;
|
|
659
|
+
_context.next = 4;
|
|
660
|
+
return fetch(citationAPI, {
|
|
675
661
|
method: 'post',
|
|
676
662
|
body: JSON.stringify(body),
|
|
677
663
|
headers: {
|
|
678
664
|
'Content-Type': 'application/json'
|
|
679
665
|
}
|
|
680
|
-
}).then(function (response) {
|
|
681
|
-
if (!response.ok) {
|
|
682
|
-
throw new Error('Network response was not ok');
|
|
683
|
-
}
|
|
684
|
-
return response.json();
|
|
685
|
-
}).then(function (citationData) {
|
|
686
|
-
_this2.setState({
|
|
687
|
-
citationData: citationData,
|
|
688
|
-
loading: false
|
|
689
|
-
});
|
|
690
|
-
})["catch"](function (error) {
|
|
691
|
-
console.error('There was a problem receiving the citation:', error);
|
|
692
|
-
_this2.setState({
|
|
693
|
-
loading: false,
|
|
694
|
-
error: error.message
|
|
695
|
-
});
|
|
696
666
|
});
|
|
697
|
-
case
|
|
667
|
+
case 4:
|
|
668
|
+
response = _context.sent;
|
|
669
|
+
if (response.ok) {
|
|
670
|
+
_context.next = 7;
|
|
671
|
+
break;
|
|
672
|
+
}
|
|
673
|
+
throw new Error('Network response was not ok');
|
|
674
|
+
case 7:
|
|
675
|
+
_context.next = 9;
|
|
676
|
+
return response.json();
|
|
677
|
+
case 9:
|
|
678
|
+
citationData = _context.sent;
|
|
679
|
+
_this.setState({
|
|
680
|
+
citationData: citationData,
|
|
681
|
+
loading: false
|
|
682
|
+
});
|
|
683
|
+
_context.next = 17;
|
|
684
|
+
break;
|
|
685
|
+
case 13:
|
|
686
|
+
_context.prev = 13;
|
|
687
|
+
_context.t0 = _context["catch"](1);
|
|
688
|
+
console.error('There was a problem receiving the citation:', _context.t0);
|
|
689
|
+
_this.setState({
|
|
690
|
+
loading: false,
|
|
691
|
+
error: _context.t0.message
|
|
692
|
+
});
|
|
693
|
+
case 17:
|
|
698
694
|
case "end":
|
|
699
695
|
return _context.stop();
|
|
700
696
|
}
|
|
701
|
-
}, _callee,
|
|
697
|
+
}, _callee, null, [[1, 13]]);
|
|
698
|
+
}));
|
|
699
|
+
return function (_x, _x2) {
|
|
700
|
+
return _ref.apply(this, arguments);
|
|
701
|
+
};
|
|
702
|
+
}());
|
|
703
|
+
var _this$props = _this.props,
|
|
704
|
+
_manifestId = _this$props.manifestId,
|
|
705
|
+
_citationAPI = _this$props.citationAPI,
|
|
706
|
+
manifestTitle = _this$props.manifestTitle;
|
|
707
|
+
_this.state = {
|
|
708
|
+
manifestId: _manifestId,
|
|
709
|
+
citationAPI: _citationAPI,
|
|
710
|
+
manifestTitle: manifestTitle,
|
|
711
|
+
citationData: null,
|
|
712
|
+
loading: true,
|
|
713
|
+
error: null
|
|
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 _callee2() {
|
|
722
|
+
var _this$state, manifestId, citationAPI;
|
|
723
|
+
return _regeneratorRuntime().wrap(function _callee2$(_context2) {
|
|
724
|
+
while (1) switch (_context2.prev = _context2.next) {
|
|
725
|
+
case 0:
|
|
726
|
+
_this$state = this.state, manifestId = _this$state.manifestId, citationAPI = _this$state.citationAPI, _this$state.manifestTitle; // Only fetch if we have the required data
|
|
727
|
+
if (manifestId && citationAPI) {
|
|
728
|
+
this.fetchCitationData(manifestId, citationAPI);
|
|
729
|
+
} else {
|
|
730
|
+
console.log('CitationButton: manifestId or citationAPI not available yet', {
|
|
731
|
+
manifestId: manifestId,
|
|
732
|
+
citationAPI: citationAPI
|
|
733
|
+
});
|
|
734
|
+
}
|
|
735
|
+
case 2:
|
|
736
|
+
case "end":
|
|
737
|
+
return _context2.stop();
|
|
738
|
+
}
|
|
739
|
+
}, _callee2, this);
|
|
702
740
|
}));
|
|
703
741
|
function componentDidMount() {
|
|
704
742
|
return _componentDidMount.apply(this, arguments);
|
|
705
743
|
}
|
|
706
744
|
return componentDidMount;
|
|
707
745
|
}()
|
|
746
|
+
}, {
|
|
747
|
+
key: "componentDidUpdate",
|
|
748
|
+
value: function () {
|
|
749
|
+
var _componentDidUpdate = _asyncToGenerator(/*#__PURE__*/_regeneratorRuntime().mark(function _callee3(prevProps, prevState) {
|
|
750
|
+
var _this$props2, newManifestId, newCitationAPI, newManifestTitle, prevManifestId, prevCitationAPI, _this$state2, manifestId, citationAPI;
|
|
751
|
+
return _regeneratorRuntime().wrap(function _callee3$(_context3) {
|
|
752
|
+
while (1) switch (_context3.prev = _context3.next) {
|
|
753
|
+
case 0:
|
|
754
|
+
// Check if props changed and update state accordingly
|
|
755
|
+
_this$props2 = this.props, newManifestId = _this$props2.manifestId, newCitationAPI = _this$props2.citationAPI, newManifestTitle = _this$props2.manifestTitle;
|
|
756
|
+
prevManifestId = prevState.manifestId, prevCitationAPI = prevState.citationAPI; // Update state if props changed
|
|
757
|
+
if (newManifestId !== prevManifestId || newCitationAPI !== prevCitationAPI || newManifestTitle !== prevState.manifestTitle) {
|
|
758
|
+
this.setState({
|
|
759
|
+
manifestId: newManifestId,
|
|
760
|
+
citationAPI: newCitationAPI,
|
|
761
|
+
manifestTitle: newManifestTitle
|
|
762
|
+
});
|
|
763
|
+
}
|
|
764
|
+
|
|
765
|
+
// Check if manifestId or citationAPI became available and fetch data
|
|
766
|
+
_this$state2 = this.state, manifestId = _this$state2.manifestId, citationAPI = _this$state2.citationAPI;
|
|
767
|
+
if ((manifestId !== prevManifestId || citationAPI !== prevCitationAPI) && manifestId && citationAPI) {
|
|
768
|
+
this.fetchCitationData(manifestId, citationAPI);
|
|
769
|
+
}
|
|
770
|
+
case 5:
|
|
771
|
+
case "end":
|
|
772
|
+
return _context3.stop();
|
|
773
|
+
}
|
|
774
|
+
}, _callee3, this);
|
|
775
|
+
}));
|
|
776
|
+
function componentDidUpdate(_x3, _x4) {
|
|
777
|
+
return _componentDidUpdate.apply(this, arguments);
|
|
778
|
+
}
|
|
779
|
+
return componentDidUpdate;
|
|
780
|
+
}()
|
|
708
781
|
}, {
|
|
709
782
|
key: "render",
|
|
710
783
|
value: function render() {
|
|
711
|
-
var _this$
|
|
712
|
-
classes = _this$
|
|
713
|
-
windowId = _this$
|
|
714
|
-
var _this$
|
|
715
|
-
citationData = _this$
|
|
716
|
-
_this$
|
|
717
|
-
_this$
|
|
784
|
+
var _this$props3 = this.props,
|
|
785
|
+
classes = _this$props3.classes,
|
|
786
|
+
windowId = _this$props3.windowId;
|
|
787
|
+
var _this$state3 = this.state,
|
|
788
|
+
citationData = _this$state3.citationData;
|
|
789
|
+
_this$state3.loading;
|
|
790
|
+
_this$state3.error;
|
|
718
791
|
if (citationData) {
|
|
719
792
|
if (!citationData.error) {
|
|
720
793
|
return /*#__PURE__*/jsx("div", {
|
|
@@ -740,9 +813,9 @@ var CitationButton = /*#__PURE__*/function (_Component) {
|
|
|
740
813
|
}]);
|
|
741
814
|
}(Component);
|
|
742
815
|
CitationButton.value = 'CitationKey';
|
|
743
|
-
var mapStateToProps$3 = function mapStateToProps(state,
|
|
816
|
+
var mapStateToProps$3 = function mapStateToProps(state, _ref2) {
|
|
744
817
|
var _state$config$mirador;
|
|
745
|
-
var windowId =
|
|
818
|
+
var windowId = _ref2.windowId;
|
|
746
819
|
var manifestId = getManifestUrl(state, {
|
|
747
820
|
windowId: windowId
|
|
748
821
|
});
|
|
@@ -998,75 +1071,148 @@ var RelatedLinksButton = /*#__PURE__*/function (_Component) {
|
|
|
998
1071
|
var _this;
|
|
999
1072
|
_classCallCheck(this, RelatedLinksButton);
|
|
1000
1073
|
_this = _callSuper(this, RelatedLinksButton, [props]);
|
|
1001
|
-
|
|
1002
|
-
|
|
1003
|
-
|
|
1004
|
-
manifestTitle = _this$props.manifestTitle;
|
|
1005
|
-
_this.state = {
|
|
1006
|
-
manifestId: manifestId,
|
|
1007
|
-
citationAPI: citationAPI,
|
|
1008
|
-
manifestTitle: manifestTitle
|
|
1009
|
-
};
|
|
1010
|
-
return _this;
|
|
1011
|
-
}
|
|
1012
|
-
_inherits(RelatedLinksButton, _Component);
|
|
1013
|
-
return _createClass(RelatedLinksButton, [{
|
|
1014
|
-
key: "componentDidMount",
|
|
1015
|
-
value: function () {
|
|
1016
|
-
var _componentDidMount = _asyncToGenerator(/*#__PURE__*/_regeneratorRuntime().mark(function _callee() {
|
|
1017
|
-
var _this2 = this;
|
|
1018
|
-
var _this$state, manifestId, citationAPI, body;
|
|
1074
|
+
_defineProperty(_this, "fetchRelatedLinksData", /*#__PURE__*/function () {
|
|
1075
|
+
var _ref = _asyncToGenerator(/*#__PURE__*/_regeneratorRuntime().mark(function _callee(manifestId, citationAPI) {
|
|
1076
|
+
var body, response, citationData;
|
|
1019
1077
|
return _regeneratorRuntime().wrap(function _callee$(_context) {
|
|
1020
1078
|
while (1) switch (_context.prev = _context.next) {
|
|
1021
1079
|
case 0:
|
|
1022
|
-
_this$state = this.state, manifestId = _this$state.manifestId, citationAPI = _this$state.citationAPI, _this$state.manifestTitle;
|
|
1023
1080
|
body = {
|
|
1024
1081
|
"manifest_id": manifestId
|
|
1025
1082
|
};
|
|
1026
|
-
|
|
1083
|
+
_context.prev = 1;
|
|
1084
|
+
_context.next = 4;
|
|
1085
|
+
return fetch(citationAPI, {
|
|
1027
1086
|
method: 'post',
|
|
1028
1087
|
body: JSON.stringify(body),
|
|
1029
1088
|
headers: {
|
|
1030
1089
|
'Content-Type': 'application/json'
|
|
1031
1090
|
}
|
|
1032
|
-
}).then(function (response) {
|
|
1033
|
-
if (!response.ok) {
|
|
1034
|
-
throw new Error('Network response was not ok');
|
|
1035
|
-
}
|
|
1036
|
-
return response.json();
|
|
1037
|
-
}).then(function (citationData) {
|
|
1038
|
-
_this2.setState({
|
|
1039
|
-
citationData: citationData,
|
|
1040
|
-
loading: false
|
|
1041
|
-
});
|
|
1042
|
-
})["catch"](function (error) {
|
|
1043
|
-
console.error('There was a problem receiving the citation:', error);
|
|
1044
|
-
_this2.setState({
|
|
1045
|
-
loading: false,
|
|
1046
|
-
error: error.message
|
|
1047
|
-
});
|
|
1048
1091
|
});
|
|
1049
|
-
case
|
|
1092
|
+
case 4:
|
|
1093
|
+
response = _context.sent;
|
|
1094
|
+
if (response.ok) {
|
|
1095
|
+
_context.next = 7;
|
|
1096
|
+
break;
|
|
1097
|
+
}
|
|
1098
|
+
throw new Error('Network response was not ok');
|
|
1099
|
+
case 7:
|
|
1100
|
+
_context.next = 9;
|
|
1101
|
+
return response.json();
|
|
1102
|
+
case 9:
|
|
1103
|
+
citationData = _context.sent;
|
|
1104
|
+
_this.setState({
|
|
1105
|
+
citationData: citationData,
|
|
1106
|
+
loading: false
|
|
1107
|
+
});
|
|
1108
|
+
_context.next = 17;
|
|
1109
|
+
break;
|
|
1110
|
+
case 13:
|
|
1111
|
+
_context.prev = 13;
|
|
1112
|
+
_context.t0 = _context["catch"](1);
|
|
1113
|
+
console.error('There was a problem receiving the related links:', _context.t0);
|
|
1114
|
+
_this.setState({
|
|
1115
|
+
loading: false,
|
|
1116
|
+
error: _context.t0.message
|
|
1117
|
+
});
|
|
1118
|
+
case 17:
|
|
1050
1119
|
case "end":
|
|
1051
1120
|
return _context.stop();
|
|
1052
1121
|
}
|
|
1053
|
-
}, _callee,
|
|
1122
|
+
}, _callee, null, [[1, 13]]);
|
|
1123
|
+
}));
|
|
1124
|
+
return function (_x, _x2) {
|
|
1125
|
+
return _ref.apply(this, arguments);
|
|
1126
|
+
};
|
|
1127
|
+
}());
|
|
1128
|
+
var _this$props = _this.props,
|
|
1129
|
+
_manifestId = _this$props.manifestId,
|
|
1130
|
+
_citationAPI = _this$props.citationAPI,
|
|
1131
|
+
manifestTitle = _this$props.manifestTitle;
|
|
1132
|
+
_this.state = {
|
|
1133
|
+
manifestId: _manifestId,
|
|
1134
|
+
citationAPI: _citationAPI,
|
|
1135
|
+
manifestTitle: manifestTitle,
|
|
1136
|
+
citationData: null,
|
|
1137
|
+
loading: true,
|
|
1138
|
+
error: null
|
|
1139
|
+
};
|
|
1140
|
+
return _this;
|
|
1141
|
+
}
|
|
1142
|
+
_inherits(RelatedLinksButton, _Component);
|
|
1143
|
+
return _createClass(RelatedLinksButton, [{
|
|
1144
|
+
key: "componentDidMount",
|
|
1145
|
+
value: function () {
|
|
1146
|
+
var _componentDidMount = _asyncToGenerator(/*#__PURE__*/_regeneratorRuntime().mark(function _callee2() {
|
|
1147
|
+
var _this$state, manifestId, citationAPI;
|
|
1148
|
+
return _regeneratorRuntime().wrap(function _callee2$(_context2) {
|
|
1149
|
+
while (1) switch (_context2.prev = _context2.next) {
|
|
1150
|
+
case 0:
|
|
1151
|
+
_this$state = this.state, manifestId = _this$state.manifestId, citationAPI = _this$state.citationAPI, _this$state.manifestTitle; // Only fetch if we have the required data
|
|
1152
|
+
if (manifestId && citationAPI) {
|
|
1153
|
+
this.fetchRelatedLinksData(manifestId, citationAPI);
|
|
1154
|
+
} else {
|
|
1155
|
+
console.log('RelatedLinksButton: manifestId or citationAPI not available yet', {
|
|
1156
|
+
manifestId: manifestId,
|
|
1157
|
+
citationAPI: citationAPI
|
|
1158
|
+
});
|
|
1159
|
+
}
|
|
1160
|
+
case 2:
|
|
1161
|
+
case "end":
|
|
1162
|
+
return _context2.stop();
|
|
1163
|
+
}
|
|
1164
|
+
}, _callee2, this);
|
|
1054
1165
|
}));
|
|
1055
1166
|
function componentDidMount() {
|
|
1056
1167
|
return _componentDidMount.apply(this, arguments);
|
|
1057
1168
|
}
|
|
1058
1169
|
return componentDidMount;
|
|
1059
1170
|
}()
|
|
1171
|
+
}, {
|
|
1172
|
+
key: "componentDidUpdate",
|
|
1173
|
+
value: function () {
|
|
1174
|
+
var _componentDidUpdate = _asyncToGenerator(/*#__PURE__*/_regeneratorRuntime().mark(function _callee3(prevProps, prevState) {
|
|
1175
|
+
var _this$props2, newManifestId, newCitationAPI, newManifestTitle, prevManifestId, prevCitationAPI, _this$state2, manifestId, citationAPI;
|
|
1176
|
+
return _regeneratorRuntime().wrap(function _callee3$(_context3) {
|
|
1177
|
+
while (1) switch (_context3.prev = _context3.next) {
|
|
1178
|
+
case 0:
|
|
1179
|
+
// Check if props changed and update state accordingly
|
|
1180
|
+
_this$props2 = this.props, newManifestId = _this$props2.manifestId, newCitationAPI = _this$props2.citationAPI, newManifestTitle = _this$props2.manifestTitle;
|
|
1181
|
+
prevManifestId = prevState.manifestId, prevCitationAPI = prevState.citationAPI; // Update state if props changed
|
|
1182
|
+
if (newManifestId !== prevManifestId || newCitationAPI !== prevCitationAPI || newManifestTitle !== prevState.manifestTitle) {
|
|
1183
|
+
this.setState({
|
|
1184
|
+
manifestId: newManifestId,
|
|
1185
|
+
citationAPI: newCitationAPI,
|
|
1186
|
+
manifestTitle: newManifestTitle
|
|
1187
|
+
});
|
|
1188
|
+
}
|
|
1189
|
+
|
|
1190
|
+
// Check if manifestId or citationAPI became available and fetch data
|
|
1191
|
+
_this$state2 = this.state, manifestId = _this$state2.manifestId, citationAPI = _this$state2.citationAPI;
|
|
1192
|
+
if ((manifestId !== prevManifestId || citationAPI !== prevCitationAPI) && manifestId && citationAPI) {
|
|
1193
|
+
this.fetchRelatedLinksData(manifestId, citationAPI);
|
|
1194
|
+
}
|
|
1195
|
+
case 5:
|
|
1196
|
+
case "end":
|
|
1197
|
+
return _context3.stop();
|
|
1198
|
+
}
|
|
1199
|
+
}, _callee3, this);
|
|
1200
|
+
}));
|
|
1201
|
+
function componentDidUpdate(_x3, _x4) {
|
|
1202
|
+
return _componentDidUpdate.apply(this, arguments);
|
|
1203
|
+
}
|
|
1204
|
+
return componentDidUpdate;
|
|
1205
|
+
}()
|
|
1060
1206
|
}, {
|
|
1061
1207
|
key: "render",
|
|
1062
1208
|
value: function render() {
|
|
1063
|
-
var _this$
|
|
1064
|
-
classes = _this$
|
|
1065
|
-
windowId = _this$
|
|
1066
|
-
var _this$
|
|
1067
|
-
citationData = _this$
|
|
1068
|
-
_this$
|
|
1069
|
-
_this$
|
|
1209
|
+
var _this$props3 = this.props,
|
|
1210
|
+
classes = _this$props3.classes,
|
|
1211
|
+
windowId = _this$props3.windowId;
|
|
1212
|
+
var _this$state3 = this.state,
|
|
1213
|
+
citationData = _this$state3.citationData;
|
|
1214
|
+
_this$state3.loading;
|
|
1215
|
+
_this$state3.error;
|
|
1070
1216
|
if (citationData) {
|
|
1071
1217
|
if (!citationData.error) {
|
|
1072
1218
|
return /*#__PURE__*/jsx("div", {
|
|
@@ -1092,9 +1238,9 @@ var RelatedLinksButton = /*#__PURE__*/function (_Component) {
|
|
|
1092
1238
|
}]);
|
|
1093
1239
|
}(Component);
|
|
1094
1240
|
RelatedLinksButton.value = 'RelatedLinksKey';
|
|
1095
|
-
var mapStateToProps$1 = function mapStateToProps(state,
|
|
1241
|
+
var mapStateToProps$1 = function mapStateToProps(state, _ref2) {
|
|
1096
1242
|
var _state$config$mirador;
|
|
1097
|
-
var windowId =
|
|
1243
|
+
var windowId = _ref2.windowId;
|
|
1098
1244
|
var manifestId = getManifestUrl(state, {
|
|
1099
1245
|
windowId: windowId
|
|
1100
1246
|
});
|