@harvard-lts/mirador-eda-plugin 0.1.1

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 (40) hide show
  1. package/.github/pull_request_template.md +31 -0
  2. package/.github/workflows/publish-package.yml +34 -0
  3. package/.nvmrc +1 -0
  4. package/.parcelrc +9 -0
  5. package/.travis.yml +16 -0
  6. package/CONTRIBUTING.md +20 -0
  7. package/LICENSE +201 -0
  8. package/README.md +175 -0
  9. package/__mocks__/fileMock.js +1 -0
  10. package/babel.config.json +11 -0
  11. package/demo/data/manifest-3037.json +524 -0
  12. package/demo/data/manifest-5f3b.json +315 -0
  13. package/demo/data/manifest-609.json +500 -0
  14. package/demo/data/ms_am_1118_3_142_0001.jpg +0 -0
  15. package/demo/data/ms_am_1118_3_142_0002.jpg +0 -0
  16. package/demo/data/ms_am_1118_3_142_0003.jpg +0 -0
  17. package/demo/demoEntry.js +21 -0
  18. package/demo/index.html +23 -0
  19. package/dist/es/index.js +535 -0
  20. package/jest.config.js +23 -0
  21. package/nwb.config.js +20 -0
  22. package/package.json +73 -0
  23. package/rollup.config.mjs +12 -0
  24. package/setupTests.js +1 -0
  25. package/src/index.js +10 -0
  26. package/src/plugins/EdaSideBarButtonsWrapper.js +51 -0
  27. package/src/plugins/EdaTranscriptionButton.js +19 -0
  28. package/src/plugins/EdaTranscriptionPanel.js +245 -0
  29. package/src/plugins/__tests__/EdaSideBarButtonsWrapper.spec.js +183 -0
  30. package/src/plugins/__tests__/EdaTranscriptionButton.spec.js +17 -0
  31. package/src/plugins/__tests__/EdaTranscriptionPanel.spec.js +188 -0
  32. package/src/plugins/__tests__/edaManifest.spec.js +110 -0
  33. package/src/plugins/__tests__/nonEdaManifest.spec.js +64 -0
  34. package/src/plugins/__tests__/transcriptionUtils.spec.js +430 -0
  35. package/src/plugins/testFixtures/combinedEditionsTranscriptions.js +62 -0
  36. package/src/plugins/testFixtures/franklinVariorum1998Transcription.js +85 -0
  37. package/src/plugins/testFixtures/johnsonPoems1955Transcription.js +88 -0
  38. package/src/plugins/transcriptionUtils.js +114 -0
  39. package/src/plugins/utils/suppressWarnings.js +41 -0
  40. package/webpack.config.cjs +56 -0
@@ -0,0 +1,535 @@
1
+ import { useState, createRef } from 'react';
2
+ import CompanionWindow from 'mirador/dist/es/src/containers/CompanionWindow';
3
+ import { compose } from 'redux';
4
+ import { connect, useSelector, shallowEqual } from 'react-redux';
5
+ import { withStyles } from '@material-ui/core/styles';
6
+ import { Typography, FormControl, Select, MenuItem, FormControlLabel, Checkbox } from '@material-ui/core';
7
+ import { jsxs, jsx } from 'react/jsx-runtime';
8
+ import TitleIcon from '@material-ui/icons/Title';
9
+ import { version } from 'mirador/package.json';
10
+
11
+ function _arrayLikeToArray(r, a) {
12
+ (null == a || a > r.length) && (a = r.length);
13
+ for (var e = 0, n = Array(a); e < a; e++) n[e] = r[e];
14
+ return n;
15
+ }
16
+ function _arrayWithHoles(r) {
17
+ if (Array.isArray(r)) return r;
18
+ }
19
+ function _arrayWithoutHoles(r) {
20
+ if (Array.isArray(r)) return _arrayLikeToArray(r);
21
+ }
22
+ function _defineProperty(e, r, t) {
23
+ return (r = _toPropertyKey(r)) in e ? Object.defineProperty(e, r, {
24
+ value: t,
25
+ enumerable: !0,
26
+ configurable: !0,
27
+ writable: !0
28
+ }) : e[r] = t, e;
29
+ }
30
+ function _iterableToArray(r) {
31
+ if ("undefined" != typeof Symbol && null != r[Symbol.iterator] || null != r["@@iterator"]) return Array.from(r);
32
+ }
33
+ function _iterableToArrayLimit(r, l) {
34
+ var t = null == r ? null : "undefined" != typeof Symbol && r[Symbol.iterator] || r["@@iterator"];
35
+ if (null != t) {
36
+ var e,
37
+ n,
38
+ i,
39
+ u,
40
+ a = [],
41
+ f = !0,
42
+ o = !1;
43
+ try {
44
+ if (i = (t = t.call(r)).next, 0 === l) {
45
+ if (Object(t) !== t) return;
46
+ f = !1;
47
+ } else for (; !(f = (e = i.call(t)).done) && (a.push(e.value), a.length !== l); f = !0);
48
+ } catch (r) {
49
+ o = !0, n = r;
50
+ } finally {
51
+ try {
52
+ if (!f && null != t.return && (u = t.return(), Object(u) !== u)) return;
53
+ } finally {
54
+ if (o) throw n;
55
+ }
56
+ }
57
+ return a;
58
+ }
59
+ }
60
+ function _nonIterableRest() {
61
+ throw new TypeError("Invalid attempt to destructure non-iterable instance.\nIn order to be iterable, non-array objects must have a [Symbol.iterator]() method.");
62
+ }
63
+ function _nonIterableSpread() {
64
+ throw new TypeError("Invalid attempt to spread non-iterable instance.\nIn order to be iterable, non-array objects must have a [Symbol.iterator]() method.");
65
+ }
66
+ function ownKeys(e, r) {
67
+ var t = Object.keys(e);
68
+ if (Object.getOwnPropertySymbols) {
69
+ var o = Object.getOwnPropertySymbols(e);
70
+ r && (o = o.filter(function (r) {
71
+ return Object.getOwnPropertyDescriptor(e, r).enumerable;
72
+ })), t.push.apply(t, o);
73
+ }
74
+ return t;
75
+ }
76
+ function _objectSpread2(e) {
77
+ for (var r = 1; r < arguments.length; r++) {
78
+ var t = null != arguments[r] ? arguments[r] : {};
79
+ r % 2 ? ownKeys(Object(t), !0).forEach(function (r) {
80
+ _defineProperty(e, r, t[r]);
81
+ }) : Object.getOwnPropertyDescriptors ? Object.defineProperties(e, Object.getOwnPropertyDescriptors(t)) : ownKeys(Object(t)).forEach(function (r) {
82
+ Object.defineProperty(e, r, Object.getOwnPropertyDescriptor(t, r));
83
+ });
84
+ }
85
+ return e;
86
+ }
87
+ function _objectWithoutProperties(e, t) {
88
+ if (null == e) return {};
89
+ var o,
90
+ r,
91
+ i = _objectWithoutPropertiesLoose(e, t);
92
+ if (Object.getOwnPropertySymbols) {
93
+ var n = Object.getOwnPropertySymbols(e);
94
+ for (r = 0; r < n.length; r++) o = n[r], -1 === t.indexOf(o) && {}.propertyIsEnumerable.call(e, o) && (i[o] = e[o]);
95
+ }
96
+ return i;
97
+ }
98
+ function _objectWithoutPropertiesLoose(r, e) {
99
+ if (null == r) return {};
100
+ var t = {};
101
+ for (var n in r) if ({}.hasOwnProperty.call(r, n)) {
102
+ if (-1 !== e.indexOf(n)) continue;
103
+ t[n] = r[n];
104
+ }
105
+ return t;
106
+ }
107
+ function _slicedToArray(r, e) {
108
+ return _arrayWithHoles(r) || _iterableToArrayLimit(r, e) || _unsupportedIterableToArray(r, e) || _nonIterableRest();
109
+ }
110
+ function _toConsumableArray(r) {
111
+ return _arrayWithoutHoles(r) || _iterableToArray(r) || _unsupportedIterableToArray(r) || _nonIterableSpread();
112
+ }
113
+ function _toPrimitive(t, r) {
114
+ if ("object" != typeof t || !t) return t;
115
+ var e = t[Symbol.toPrimitive];
116
+ if (void 0 !== e) {
117
+ var i = e.call(t, r || "default");
118
+ if ("object" != typeof i) return i;
119
+ throw new TypeError("@@toPrimitive must return a primitive value.");
120
+ }
121
+ return ("string" === r ? String : Number)(t);
122
+ }
123
+ function _toPropertyKey(t) {
124
+ var i = _toPrimitive(t, "string");
125
+ return "symbol" == typeof i ? i : i + "";
126
+ }
127
+ function _unsupportedIterableToArray(r, a) {
128
+ if (r) {
129
+ if ("string" == typeof r) return _arrayLikeToArray(r, a);
130
+ var t = {}.toString.call(r).slice(8, -1);
131
+ return "Object" === t && r.constructor && (t = r.constructor.name), "Map" === t || "Set" === t ? Array.from(r) : "Arguments" === t || /^(?:Ui|I)nt(?:8|16|32)(?:Clamped)?Array$/.test(t) ? _arrayLikeToArray(r, a) : void 0;
132
+ }
133
+ }
134
+
135
+ /**
136
+ * Extract the edition name from a transcription HTML string
137
+ * @param {string} html
138
+ * @returns {string} "Unknown Edition" if no name is found
139
+ */
140
+
141
+ var getEditionName = function getEditionName(html) {
142
+ var _workBody$dataset;
143
+ var parser = new DOMParser();
144
+ var doc = parser.parseFromString(html, "text/html");
145
+ var workBody = doc.querySelector(".work-body");
146
+ return (workBody === null || workBody === void 0 || (_workBody$dataset = workBody.dataset) === null || _workBody$dataset === void 0 ? void 0 : _workBody$dataset.edition) || "Unknown Edition";
147
+ };
148
+
149
+ /**
150
+ * Returns an array of EDA transcriptions from the manifest
151
+ * Transcriptions with the same edition name will be combined into a single transcription
152
+ * @param {Object} state
153
+ * @param {string} windowId
154
+ * @returns {array} - empty if EDA no transcriptions exist
155
+ */
156
+
157
+ var getEdaTranscription = function getEdaTranscription(state, windowId) {
158
+ var _targetWindow, _targetWindow2, _manifest$json$items;
159
+ var windows = (state === null || state === void 0 ? void 0 : state.windows) || {};
160
+ var targetWindow;
161
+ if (windowId && windows[windowId]) {
162
+ targetWindow = windows[windowId];
163
+ } else {
164
+ var windowIds = Object.keys(windows);
165
+ targetWindow = windowIds.length > 0 ? windows[windowIds[0]] : null;
166
+ }
167
+ var canvasId = (_targetWindow = targetWindow) === null || _targetWindow === void 0 ? void 0 : _targetWindow.canvasId;
168
+ var manifestId = (_targetWindow2 = targetWindow) === null || _targetWindow2 === void 0 ? void 0 : _targetWindow2.manifestId;
169
+ var manifest = manifestId ? state.manifests[manifestId] : null;
170
+ if (!(manifest !== null && manifest !== void 0 && manifest.json) || !canvasId) {
171
+ return [];
172
+ }
173
+ var canvas = (_manifest$json$items = manifest.json.items) === null || _manifest$json$items === void 0 ? void 0 : _manifest$json$items.find(function (item) {
174
+ return item.id === canvasId;
175
+ });
176
+ if (!(canvas !== null && canvas !== void 0 && canvas.annotations)) {
177
+ return [];
178
+ }
179
+ var allTranscriptions = canvas.annotations.flatMap(function (page) {
180
+ return page.items || [];
181
+ }).filter(function (annotation) {
182
+ var _annotation$body, _annotation$body2;
183
+ if ((annotation === null || annotation === void 0 || (_annotation$body = annotation.body) === null || _annotation$body === void 0 ? void 0 : _annotation$body.format) !== "text/html") return false;
184
+ var value = annotation === null || annotation === void 0 || (_annotation$body2 = annotation.body) === null || _annotation$body2 === void 0 ? void 0 : _annotation$body2.value;
185
+ if (!value) return false;
186
+ return value.includes('data-exhibit="emily-dickinson-archive"');
187
+ }).map(function (annotation) {
188
+ return annotation.body.value;
189
+ });
190
+
191
+ // Group transcriptions by edition name
192
+ var transcriptionsByEdition = allTranscriptions.reduce(function (acc, html) {
193
+ var editionName = getEditionName(html);
194
+ if (!acc[editionName]) {
195
+ acc[editionName] = [];
196
+ }
197
+ acc[editionName].push(html);
198
+ return acc;
199
+ }, {});
200
+
201
+ // Combine HTML for editions with multiple transcriptions
202
+ var combinedTranscriptions = Object.entries(transcriptionsByEdition).map(function (_ref) {
203
+ var _ref2 = _slicedToArray(_ref, 2);
204
+ _ref2[0];
205
+ var htmlArray = _ref2[1];
206
+ if (htmlArray.length === 1) {
207
+ return htmlArray[0];
208
+ }
209
+ var parser = new DOMParser();
210
+ var firstDoc = parser.parseFromString(htmlArray[0], "text/html");
211
+ var firstWorkBody = firstDoc.querySelector(".work-body");
212
+ var combinedDoc = parser.parseFromString('<div class="work-body"></div>', "text/html");
213
+ var combinedWorkBody = combinedDoc.querySelector(".work-body");
214
+ if (firstWorkBody.dataset.edition) {
215
+ combinedWorkBody.dataset.edition = firstWorkBody.dataset.edition;
216
+ }
217
+ if (firstWorkBody.dataset.exhibit) {
218
+ combinedWorkBody.dataset.exhibit = firstWorkBody.dataset.exhibit;
219
+ }
220
+ htmlArray.forEach(function (html) {
221
+ var doc = parser.parseFromString(html, "text/html");
222
+ var workBody = doc.querySelector(".work-body");
223
+ var title = workBody.querySelector("h3");
224
+ var stanzas = workBody.querySelectorAll(".stanza");
225
+ if (title) {
226
+ var titleClone = title.cloneNode(true);
227
+ combinedWorkBody.appendChild(titleClone);
228
+ }
229
+ stanzas.forEach(function (stanza) {
230
+ var clone = stanza.cloneNode(true);
231
+ combinedWorkBody.appendChild(clone);
232
+ });
233
+ if (html !== htmlArray[htmlArray.length - 1]) {
234
+ var spacer = combinedDoc.createElement("div");
235
+ spacer.style.height = "2em";
236
+ combinedWorkBody.appendChild(spacer);
237
+ }
238
+ });
239
+ return combinedWorkBody.outerHTML;
240
+ });
241
+ return combinedTranscriptions;
242
+ };
243
+
244
+ var EdaTranscriptionPanel = function EdaTranscriptionPanel(_ref) {
245
+ var classes = _ref.classes,
246
+ transcriptions = _ref.transcriptions,
247
+ windowId = _ref.windowId,
248
+ id = _ref.id;
249
+ var _useState = useState(0),
250
+ _useState2 = _slicedToArray(_useState, 2),
251
+ selectedEdition = _useState2[0],
252
+ setSelectedEdition = _useState2[1];
253
+ var _useState3 = useState(true),
254
+ _useState4 = _slicedToArray(_useState3, 2),
255
+ showPhysicalLinebreaks = _useState4[0],
256
+ setShowPhysicalLinebreaks = _useState4[1];
257
+ var _useState5 = useState(false),
258
+ _useState6 = _slicedToArray(_useState5, 2),
259
+ hideEdits = _useState6[0],
260
+ setHideEdits = _useState6[1];
261
+ var currentTranscription = transcriptions[selectedEdition] || "";
262
+ var contentRef = /*#__PURE__*/createRef();
263
+ var getEditionLabel = function getEditionLabel(html) {
264
+ var _workBody$dataset;
265
+ var parser = new DOMParser();
266
+ var doc = parser.parseFromString(html, "text/html");
267
+ var workBody = doc.querySelector(".work-body");
268
+ return (workBody === null || workBody === void 0 || (_workBody$dataset = workBody.dataset) === null || _workBody$dataset === void 0 ? void 0 : _workBody$dataset.edition) || "Unknown Edition";
269
+ };
270
+ var handleEditionChange = function handleEditionChange(event) {
271
+ setSelectedEdition(event.target.value);
272
+ };
273
+ var handleLinebreaksChange = function handleLinebreaksChange(event) {
274
+ setShowPhysicalLinebreaks(event.target.checked);
275
+ };
276
+ var handleEditsChange = function handleEditsChange(event) {
277
+ setHideEdits(event.target.checked);
278
+ };
279
+ var sectionClasses = [classes.section, showPhysicalLinebreaks ? "show-linebreaks" : "", hideEdits ? "hide-edits" : ""].filter(Boolean).join(" ");
280
+
281
+ // CompanionWindow pulls the resizing functionality from Mirador
282
+ // the paperClassName prop allows styles to the underlying container
283
+ return /*#__PURE__*/jsxs(CompanionWindow, {
284
+ title: "EDA Transcription",
285
+ windowId: windowId,
286
+ id: id,
287
+ paperClassName: classes.paper,
288
+ children: [(!transcriptions || transcriptions.length === 0) && /*#__PURE__*/jsx("div", {
289
+ className: classes.root,
290
+ children: /*#__PURE__*/jsxs("div", {
291
+ className: classes.section,
292
+ children: [/*#__PURE__*/jsx(Typography, {
293
+ variant: "body1",
294
+ className: classes.noTranscriptionsMessage1,
295
+ children: "No Emily Dickinson Archive transcriptions are available for this manifest."
296
+ }), /*#__PURE__*/jsx(Typography, {
297
+ variant: "body2",
298
+ className: classes.noTranscriptionsMessage2,
299
+ children: "This feature is only available for items from the Emily Dickinson Archive."
300
+ })]
301
+ })
302
+ }), /*#__PURE__*/jsxs("div", {
303
+ className: classes.root,
304
+ children: [/*#__PURE__*/jsxs("div", {
305
+ className: classes.controls,
306
+ children: [transcriptions.length > 0 && /*#__PURE__*/jsxs(FormControl, {
307
+ className: classes.formControl,
308
+ children: [/*#__PURE__*/jsx(Typography, {
309
+ variant: "body2",
310
+ className: classes.editionLabel,
311
+ children: "Edition"
312
+ }), /*#__PURE__*/jsx(Select, {
313
+ value: selectedEdition,
314
+ onChange: handleEditionChange,
315
+ variant: "outlined",
316
+ margin: "dense",
317
+ className: classes.selectInput,
318
+ disabled: transcriptions.length === 1,
319
+ children: transcriptions.map(function (transcription, index) {
320
+ return /*#__PURE__*/jsx(MenuItem, {
321
+ value: index,
322
+ children: getEditionLabel(transcription)
323
+ }, index);
324
+ })
325
+ })]
326
+ }), /*#__PURE__*/jsx(FormControlLabel, {
327
+ control: /*#__PURE__*/jsx(Checkbox, {
328
+ checked: hideEdits,
329
+ onChange: handleEditsChange,
330
+ name: "edits",
331
+ color: "primary"
332
+ }),
333
+ label: "Hide Edits"
334
+ }), /*#__PURE__*/jsx(FormControlLabel, {
335
+ control: /*#__PURE__*/jsx(Checkbox, {
336
+ checked: showPhysicalLinebreaks,
337
+ onChange: handleLinebreaksChange,
338
+ name: "linebreaks",
339
+ color: "primary"
340
+ }),
341
+ label: "Physical Line Breaks"
342
+ })]
343
+ }), /*#__PURE__*/jsx("div", {
344
+ ref: contentRef,
345
+ className: sectionClasses,
346
+ dangerouslySetInnerHTML: {
347
+ __html: currentTranscription
348
+ }
349
+ })]
350
+ })]
351
+ });
352
+ };
353
+ var styles = function styles(theme) {
354
+ return {
355
+ "@global": {
356
+ ".react-draggable": {
357
+ minWidth: "350px !important" // this must match the paper minWidth
358
+ }
359
+ },
360
+ root: {
361
+ height: "100%",
362
+ overflow: "auto",
363
+ display: "flex",
364
+ flexDirection: "column"
365
+ },
366
+ paper: {
367
+ minWidth: "350px" // this must match the companion window minWidth
368
+ },
369
+ controls: {
370
+ padding: theme.spacing(2),
371
+ borderBottom: "1px solid ".concat(theme.palette.divider),
372
+ backgroundColor: theme.palette.background.paper
373
+ },
374
+ formControl: {
375
+ marginBottom: theme.spacing(1),
376
+ width: "100%"
377
+ },
378
+ editionLabel: {
379
+ fontWeight: "bold",
380
+ marginBottom: theme.spacing(0.5),
381
+ fontSize: "0.875rem"
382
+ },
383
+ selectInput: {
384
+ width: 300
385
+ },
386
+ section: {
387
+ flex: 1,
388
+ fontSize: ".875em",
389
+ lineHeight: theme.typography.body2.lineHeight,
390
+ fontFamily: theme.typography.fontFamily,
391
+ backgroundColor: theme.palette.background.paper,
392
+ borderRight: "0.5px solid ".concat(theme.palette.divider),
393
+ overflow: "auto",
394
+ color: theme.palette.text.primary,
395
+ padding: theme.spacing(2),
396
+ "& .line": {
397
+ display: "block"
398
+ },
399
+ "& ins:before": {
400
+ content: '"["',
401
+ fontWeight: theme.typography.fontWeightBold
402
+ },
403
+ "& ins:after": {
404
+ content: '"]"',
405
+ fontWeight: theme.typography.fontWeightBold
406
+ },
407
+ "& rt": {
408
+ fontSize: "0.833em"
409
+ },
410
+ "& .work-body": {
411
+ whiteSpace: "nowrap",
412
+ "& h3, & h4": {
413
+ fontWeight: theme.typography.fontWeightBold,
414
+ whiteSpace: "normal"
415
+ },
416
+ "& br": {
417
+ display: "none"
418
+ }
419
+ },
420
+ "&.show-linebreaks .work-body br": {
421
+ display: "block"
422
+ },
423
+ "&.hide-edits ins": {
424
+ display: "none"
425
+ },
426
+ "&.hide-edits rt": {
427
+ display: "none"
428
+ },
429
+ "& .stanza": {
430
+ marginBottom: theme.spacing(1.875)
431
+ },
432
+ "& .page-break": {
433
+ borderWidth: "1px 0 0 0",
434
+ borderStyle: "dotted",
435
+ display: "block !important"
436
+ }
437
+ },
438
+ noTranscriptionsMessage1: {
439
+ padding: "16px"
440
+ },
441
+ noTranscriptionsMessage2: {
442
+ padding: "0 16px 16px"
443
+ }
444
+ };
445
+ };
446
+ var mapStateToProps = function mapStateToProps(state, _ref2) {
447
+ var windowId = _ref2.windowId;
448
+ return {
449
+ transcriptions: getEdaTranscription(state, windowId)
450
+ };
451
+ };
452
+ var enhance = compose(withStyles(styles), connect(mapStateToProps));
453
+ var EdaTranscriptionPanel$1 = {
454
+ component: enhance(EdaTranscriptionPanel),
455
+ companionWindowKey: "edaTranscription"
456
+ };
457
+
458
+ var EdaTranscriptionButton = function EdaTranscriptionButton() {
459
+ return /*#__PURE__*/jsx(TitleIcon, {
460
+ "data-testid": "eda-transcription-icon"
461
+ });
462
+ };
463
+
464
+ // this needs to match the companionWindowKey in EdaTranscriptionPanel.js
465
+ EdaTranscriptionButton.value = "edaTranscription";
466
+
467
+ var _excluded = ["TargetComponent"];
468
+ var EdaSideBarButtonsWrapper = function EdaSideBarButtonsWrapper(_ref) {
469
+ var TargetComponent = _ref.TargetComponent,
470
+ targetProps = _objectWithoutProperties(_ref, _excluded);
471
+ // shallowEqual prevents re-renders unless transcriptions actually change
472
+ var transcriptions = useSelector(getEdaTranscription, shallowEqual);
473
+ var hasTranscriptions = Boolean(transcriptions && transcriptions.length > 0);
474
+
475
+ // sets the translation for the EDA Transcriptions button tooltip
476
+ var customTranslation = function customTranslation(key, opts) {
477
+ if (key === "openCompanionWindow" && opts && opts.context === "edaTranscription") {
478
+ return "EDA Transcriptions";
479
+ }
480
+ var originalTranslation = targetProps.t || function (key) {
481
+ return key;
482
+ };
483
+ return originalTranslation(key, opts);
484
+ };
485
+
486
+ // if transcriptions exist, add EDA Transcriptions button and hide Annotations button
487
+ var plugin = hasTranscriptions ? [].concat(_toConsumableArray(targetProps.PluginComponents || []), [EdaTranscriptionButton]) : targetProps.PluginComponents;
488
+ return /*#__PURE__*/jsx(TargetComponent, _objectSpread2(_objectSpread2({}, targetProps), {}, {
489
+ t: customTranslation,
490
+ panels: _objectSpread2(_objectSpread2({}, targetProps.panels), {}, {
491
+ annotations: !hasTranscriptions
492
+ }),
493
+ PluginComponents: plugin
494
+ }));
495
+ };
496
+ var EdaSideBarButtonsWrapper$1 = {
497
+ target: "WindowSideBarButtons",
498
+ mode: "wrap",
499
+ component: EdaSideBarButtonsWrapper
500
+ };
501
+
502
+ // In Mirador version 3x there is a deprecation console warning:
503
+ // Warning: Failed prop type: Material-UI: `overlap="rectangle"` was deprecated. Use `overlap="rectangular"` instead.
504
+ // This was fixed in Mirador version 4.0.0
505
+ // https://github.com/ProjectMirador/mirador/commit/90e695e0df5df44174a023cfae367a76e5697760
506
+
507
+ // Suppressing this error to improve developer experience
508
+
509
+ var FIXED_VERSION = "4.0.0";
510
+ var parsedCurrentVersion = parseInt(version.replace(/\./g, ""));
511
+ var parsedFixedVersion = parseInt(FIXED_VERSION.replace(/\./g, ""));
512
+
513
+ // Once the version is greater than or equal to the fixed version, we can remove this suppression
514
+ if (parsedCurrentVersion >= parsedFixedVersion) {
515
+ console.log("⚠️ Warning suppression for Material-UI Badge overlap prop may no longer be needed.\n" + " Current Mirador version: " + version + "\n" + " Fixed in version: " + FIXED_VERSION + "\n" + " Consider removing src/plugins/utils/suppressWarnings.js");
516
+ } else {
517
+ var originalConsoleError = console.error;
518
+ console.error = function () {
519
+ for (var _len = arguments.length, args = new Array(_len), _key = 0; _key < _len; _key++) {
520
+ args[_key] = arguments[_key];
521
+ }
522
+ var suppressedWarnings = ["Material-UI: `overlap=\"rectangle\"` was deprecated. Use `overlap=\"rectangular\"` instead."];
523
+ var shouldSuppress = suppressedWarnings.some(function (warning) {
524
+ var _args$;
525
+ return ((_args$ = args[0]) === null || _args$ === void 0 ? void 0 : _args$.includes) && args[0].includes(warning);
526
+ });
527
+ if (!shouldSuppress) {
528
+ originalConsoleError.apply(console, args);
529
+ }
530
+ };
531
+ }
532
+
533
+ var index = [EdaSideBarButtonsWrapper$1, EdaTranscriptionPanel$1];
534
+
535
+ export { index as default };
package/jest.config.js ADDED
@@ -0,0 +1,23 @@
1
+ /** @type {import('jest').Config} */
2
+ module.exports = {
3
+ testEnvironment: "jsdom",
4
+ transformIgnorePatterns: ["node_modules/(?!mirador)/", "node_modules/pdiiif"],
5
+ setupFilesAfterEnv: ["@testing-library/jest-dom", "./setupTests"],
6
+ moduleNameMapper: {
7
+ "\\.(jpg|jpeg|png|gif|svg)$": "<rootDir>/__mocks__/fileMock.js"
8
+ },
9
+ // collectCoverage: true,
10
+ // coverageDirectory: "coverage",
11
+ // verbose: true,
12
+ // testRegex: "(/tests/.*|\\.(test|spec))\\.jsx?$",
13
+ // moduleFileExtensions: ["js", "json", "jsx", "node"],
14
+ // coverageThreshold: {
15
+ // global: {
16
+ // branches: 30,
17
+ // functions: 90,
18
+ // lines: 90,
19
+ // statements: 90,
20
+ // },
21
+ // },
22
+ // // setupFiles: ["./setupTests"],
23
+ };
package/nwb.config.js ADDED
@@ -0,0 +1,20 @@
1
+ const path = require('path');
2
+
3
+ module.exports = {
4
+ type: 'react-component',
5
+ npm: {
6
+ esModules: true,
7
+ umd: {
8
+ global: 'miradorTemplate',
9
+ externals: {
10
+ react: 'React'
11
+ }
12
+ }
13
+ },
14
+ webpack: {
15
+ aliases: {
16
+ react: path.resolve('./', 'node_modules', 'react'),
17
+ 'react-dom': path.resolve('./', 'node_modules', 'react-dom'),
18
+ },
19
+ },
20
+ }
package/package.json ADDED
@@ -0,0 +1,73 @@
1
+ {
2
+ "name": "@harvard-lts/mirador-eda-plugin",
3
+ "version": "0.1.1",
4
+ "description": "A Mirador plugin for displaying Emily Dickinson Archive transcriptions with toggleable line breaks and editorial marks",
5
+ "main": "dist/index.js",
6
+ "source": "src/index.js",
7
+ "module": "es/index.js",
8
+ "scripts": {
9
+ "start": "npm run serve",
10
+ "clean": "rm -rf ./dist && rm -rf ./demo/dist",
11
+ "prebuild": "npm run clean",
12
+ "prepublishOnly": "npm run build",
13
+ "build": "run-p build:es",
14
+ "build:es": "rollup -c",
15
+ "serve": "webpack serve --mode development --open",
16
+ "test": "jest",
17
+ "test:coverage": "jest --coverage",
18
+ "test:watch": "jest --watch"
19
+ },
20
+ "repository": {
21
+ "type": "git",
22
+ "url": "git+https://github.com/harvard-lts/mirador-eda-plugin.git"
23
+ },
24
+ "keywords": [
25
+ "mirador",
26
+ "iiif",
27
+ "plugin",
28
+ "emily-dickinson",
29
+ "manuscript",
30
+ "transcription",
31
+ "scholarly-edition"
32
+ ],
33
+ "author": "Notch8",
34
+ "license": "Apache-2.0",
35
+ "homepage": "https://github.com/harvard-lts/mirador-eda-plugin#readme",
36
+ "dependencies": {
37
+ "jquery": "^3.7.0",
38
+ "prop-types": "^15.8.1",
39
+ "react": "^16.14.0",
40
+ "react-dom": "^16.14.0",
41
+ "redux": "^4.2.1",
42
+ "redux-saga": "^1.2.3"
43
+ },
44
+ "peerDependencies": {
45
+ "@material-ui/core": "^4.0.0",
46
+ "@material-ui/icons": "^4.0.0",
47
+ "mirador": "^3.0.0",
48
+ "react-redux": "^5.0.0 || ^6.0.0 || ^7.0.0"
49
+ },
50
+ "devDependencies": {
51
+ "@babel/cli": "^7.26.4",
52
+ "@babel/core": "^7.26.0",
53
+ "@babel/preset-env": "^7.21.4",
54
+ "@babel/preset-react": "^7.18.6",
55
+ "@reduxjs/toolkit": "^2.9.1",
56
+ "@rollup/plugin-babel": "^6.0.3",
57
+ "@testing-library/jest-dom": "^5.16.5",
58
+ "@testing-library/react": "^12.0.0",
59
+ "babel-jest": "^29.7.0",
60
+ "babel-loader": "^9.1.2",
61
+ "jest": "^30.0.2",
62
+ "jest-environment-jsdom": "^30.0.2",
63
+ "mirador": "^3.4.3",
64
+ "npm-run-all": "^4.1.5",
65
+ "parcel": "^2.8.3",
66
+ "rollup": "^3.29.5",
67
+ "url": "^0.11.0",
68
+ "webpack": "^5.94.0",
69
+ "webpack-cli": "^5.1.4",
70
+ "webpack-dev-server": "^5.2.0",
71
+ "webpack-node-externals": "^3.0.0"
72
+ }
73
+ }
@@ -0,0 +1,12 @@
1
+ import { babel } from "@rollup/plugin-babel";
2
+
3
+ const config = {
4
+ input: "src/index.js",
5
+ output: {
6
+ dir: "dist/es",
7
+ format: "es",
8
+ },
9
+ plugins: [babel({ babelHelpers: "bundled" })],
10
+ };
11
+
12
+ export default config;
package/setupTests.js ADDED
@@ -0,0 +1 @@
1
+ // import "whatwg-fetch"
package/src/index.js ADDED
@@ -0,0 +1,10 @@
1
+ import EdaTranscriptionPanel from "./plugins/EdaTranscriptionPanel"
2
+ import EdaSideBarButtonsWrapper from "./plugins/EdaSideBarButtonsWrapper"
3
+
4
+ // suppressing a console warning message that has been fixed in Mirador v4
5
+ import "./plugins/utils/suppressWarnings"
6
+
7
+ export default [
8
+ EdaSideBarButtonsWrapper,
9
+ EdaTranscriptionPanel
10
+ ]