dbf-mirador 4.3.0-testing2 → 4.3.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.
- package/dist/{CommentSharp-DaW0oBJy.js → CommentSharp-BJ6oQAe3.js} +2 -2
- package/dist/{CommentSharp-DaW0oBJy.js.map → CommentSharp-BJ6oQAe3.js.map} +1 -1
- package/dist/{FailedImageContext-DYZ9cZx9.js → FailedImageContext-BhA0TpVp.js} +22 -1
- package/dist/FailedImageContext-BhA0TpVp.js.map +1 -0
- package/dist/{GalleryView-DyLH1kk0.js → GalleryView-rCx0Q4f3.js} +3 -3
- package/dist/{GalleryView-DyLH1kk0.js.map → GalleryView-rCx0Q4f3.js.map} +1 -1
- package/dist/{OpenSeadragonViewer-CBmX5sYE.js → OpenSeadragonViewer-4nw8qaVM.js} +377 -327
- package/dist/OpenSeadragonViewer-4nw8qaVM.js.map +1 -0
- package/dist/{WindowViewer-BW0_w7wv.js → WindowViewer-uHVYcMsX.js} +2 -2
- package/dist/{WindowViewer-BW0_w7wv.js.map → WindowViewer-uHVYcMsX.js.map} +1 -1
- package/dist/{WorkspaceArea-C0RjqnIL.js → WorkspaceArea-CAti6dTA.js} +4 -4
- package/dist/{WorkspaceArea-C0RjqnIL.js.map → WorkspaceArea-CAti6dTA.js.map} +1 -1
- package/dist/mirador.es.js +7 -7
- package/dist/mirador.min.js +72 -72
- package/dist/mirador.min.js.map +1 -1
- package/package.json +1 -1
- package/src/components/AnnotationsOverlay.jsx +50 -28
- package/src/lib/AnnotationItem.js +18 -0
- package/src/lib/AnnotationResource.js +14 -0
- package/src/lib/CanvasAnnotationDisplay.js +104 -0
- package/src/plugins/poiPreviewPlugin.tsx +340 -0
- package/dist/FailedImageContext-DYZ9cZx9.js.map +0 -1
- package/dist/OpenSeadragonViewer-CBmX5sYE.js.map +0 -1
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "dbf-mirador",
|
|
3
|
-
"version": "4.3.
|
|
3
|
+
"version": "4.3.1",
|
|
4
4
|
"description": "An open-source, web-based 'multi-up' viewer that supports zoom-pan-rotate functionality, ability to display/compare simple images, and images with annotations.",
|
|
5
5
|
"type": "module",
|
|
6
6
|
"main": "./dist/mirador.min.js",
|
|
@@ -2,15 +2,16 @@ import { useRef, useEffect, useCallback, useMemo } from 'react';
|
|
|
2
2
|
import ReactDOM from 'react-dom';
|
|
3
3
|
import PropTypes from 'prop-types';
|
|
4
4
|
import { useDebouncedCallback } from 'use-debounce';
|
|
5
|
+
import partition from 'lodash/partition';
|
|
5
6
|
import sortBy from 'lodash/sortBy';
|
|
6
7
|
import xor from 'lodash/xor';
|
|
7
8
|
import OpenSeadragonCanvasOverlay from '../lib/OpenSeadragonCanvasOverlay';
|
|
8
9
|
import CanvasWorld from '../lib/CanvasWorld';
|
|
9
|
-
import CanvasAnnotationDisplay from '../lib/CanvasAnnotationDisplay';
|
|
10
|
+
import CanvasAnnotationDisplay, { poiHitTarget } from '../lib/CanvasAnnotationDisplay';
|
|
10
11
|
import { buildPath2D } from '../lib/svgShapesToPath';
|
|
11
12
|
|
|
12
13
|
/** @private */
|
|
13
|
-
function isAnnotationAtPoint(canvasWorld, osdCanvasOverlay, resource, canvas, point) {
|
|
14
|
+
function isAnnotationAtPoint({ canvasWorld, osdCanvasOverlay, viewer }, resource, canvas, point) {
|
|
14
15
|
const [canvasX, canvasY] = canvasWorld.canvasToWorldCoordinates(canvas.id);
|
|
15
16
|
const relativeX = point.x - canvasX;
|
|
16
17
|
const relativeY = point.y - canvasY;
|
|
@@ -21,6 +22,21 @@ function isAnnotationAtPoint(canvasWorld, osdCanvasOverlay, resource, canvas, po
|
|
|
21
22
|
return [...svgPaths].some((path) => context.isPointInPath(buildPath2D(path), relativeX, relativeY));
|
|
22
23
|
}
|
|
23
24
|
|
|
25
|
+
if (resource.pointSelector) {
|
|
26
|
+
const { x, y } = resource.pointSelector;
|
|
27
|
+
const osdCanvasIndex = canvasWorld.canvases.findIndex((c) => c.id === canvas.id);
|
|
28
|
+
const viewportCanvas = viewer.world.getItemAt(osdCanvasIndex);
|
|
29
|
+
if (!viewportCanvas) return false;
|
|
30
|
+
// The icon renders at a constant on-screen size regardless of zoom (see
|
|
31
|
+
// CanvasAnnotationDisplay#pointContext), so its clickable footprint must counter-scale the
|
|
32
|
+
// same way, or the hit region would shrink/grow with the image instead of the icon.
|
|
33
|
+
const zoomRatio = viewportCanvas.viewportToImageZoom(viewer.viewport.getZoom(true));
|
|
34
|
+
const hitTarget = poiHitTarget(x, y, zoomRatio);
|
|
35
|
+
const dx = relativeX - hitTarget.x;
|
|
36
|
+
const dy = relativeY - hitTarget.y;
|
|
37
|
+
return dx * dx + dy * dy <= hitTarget.radius * hitTarget.radius;
|
|
38
|
+
}
|
|
39
|
+
|
|
24
40
|
if (resource.fragmentSelector) {
|
|
25
41
|
const [x, y, w, h] = resource.fragmentSelector;
|
|
26
42
|
return x <= relativeX && relativeX <= x + w && y <= relativeY && relativeY <= y + h;
|
|
@@ -82,30 +98,36 @@ export function AnnotationsOverlay({
|
|
|
82
98
|
const annotationsToContext = useCallback(
|
|
83
99
|
(renderedAnnotations, currentPalette) => {
|
|
84
100
|
const context = osdCanvasOverlay.context2d;
|
|
85
|
-
renderedAnnotations.
|
|
86
|
-
|
|
87
|
-
|
|
88
|
-
|
|
89
|
-
|
|
90
|
-
|
|
91
|
-
|
|
92
|
-
|
|
93
|
-
|
|
94
|
-
|
|
95
|
-
|
|
96
|
-
|
|
97
|
-
|
|
98
|
-
|
|
99
|
-
|
|
100
|
-
|
|
101
|
-
|
|
101
|
+
const resources = renderedAnnotations.flatMap((annotation) => annotation.resources);
|
|
102
|
+
|
|
103
|
+
// POI pins always draw last, on top of every other annotation shape on the same canvas -
|
|
104
|
+
// notably including a Journey's own annotation target (an svg/fragment selector, not a
|
|
105
|
+
// pointSelector), which would otherwise draw in plain store order and can end up covering
|
|
106
|
+
// - and stealing clicks from - a POI pin it happens to overlap on screen.
|
|
107
|
+
const [otherResources, poiResources] = partition(resources, (resource) => !resource.pointSelector);
|
|
108
|
+
|
|
109
|
+
[...otherResources, ...poiResources].forEach((resource) => {
|
|
110
|
+
const osdCanvasIndex = canvasWorld.canvases.findIndex((canvas) => canvas.id === resource.targetId);
|
|
111
|
+
if (osdCanvasIndex === -1) return;
|
|
112
|
+
const viewportCanvas = viewer.world.getItemAt(osdCanvasIndex);
|
|
113
|
+
if (!viewportCanvas) return;
|
|
114
|
+
const offset = canvasWorld.offsetByCanvas(resource.targetId);
|
|
115
|
+
const zoomRatio = viewportCanvas.viewportToImageZoom(viewer.viewport.getZoom(true));
|
|
116
|
+
const canvasAnnotationDisplay = new CanvasAnnotationDisplay({
|
|
117
|
+
hovered: hoveredAnnotationIds.includes(resource.id),
|
|
118
|
+
offset,
|
|
119
|
+
palette: {
|
|
120
|
+
...currentPalette,
|
|
121
|
+
default: {
|
|
122
|
+
...currentPalette.default,
|
|
123
|
+
...(!highlightAllAnnotations && currentPalette.hidden),
|
|
102
124
|
},
|
|
103
|
-
|
|
104
|
-
|
|
105
|
-
|
|
106
|
-
|
|
107
|
-
canvasAnnotationDisplay.toContext(context);
|
|
125
|
+
},
|
|
126
|
+
resource,
|
|
127
|
+
selected: selectedAnnotationId === resource.id,
|
|
128
|
+
zoomRatio,
|
|
108
129
|
});
|
|
130
|
+
canvasAnnotationDisplay.toContext(context);
|
|
109
131
|
});
|
|
110
132
|
},
|
|
111
133
|
[osdCanvasOverlay, viewer, canvasWorld, highlightAllAnnotations, hoveredAnnotationIds, selectedAnnotationId],
|
|
@@ -137,12 +159,12 @@ export function AnnotationsOverlay({
|
|
|
137
159
|
.filter((resource) => {
|
|
138
160
|
if (canvas.id !== resource.targetId) return false;
|
|
139
161
|
|
|
140
|
-
return isAnnotationAtPoint(canvasWorld, osdCanvasOverlay, resource, canvas, point);
|
|
162
|
+
return isAnnotationAtPoint({ canvasWorld, osdCanvasOverlay, viewer }, resource, canvas, point);
|
|
141
163
|
});
|
|
142
164
|
|
|
143
165
|
return annos;
|
|
144
166
|
},
|
|
145
|
-
[annotations, canvasWorld, osdCanvasOverlay, searchAnnotations],
|
|
167
|
+
[annotations, canvasWorld, osdCanvasOverlay, searchAnnotations, viewer],
|
|
146
168
|
);
|
|
147
169
|
|
|
148
170
|
const onCanvasClick = useCallback(
|
|
@@ -188,7 +210,7 @@ export function AnnotationsOverlay({
|
|
|
188
210
|
const x = Math.cos(degrees * degreesToRadians) * radius + point.x;
|
|
189
211
|
const y = Math.sin(degrees * degreesToRadians) * radius + point.y;
|
|
190
212
|
|
|
191
|
-
if (isAnnotationAtPoint(canvasWorld, osdCanvasOverlay, anno, canvas, { x, y })) score += 1;
|
|
213
|
+
if (isAnnotationAtPoint({ canvasWorld, osdCanvasOverlay, viewer }, anno, canvas, { x, y })) score += 1;
|
|
192
214
|
}
|
|
193
215
|
|
|
194
216
|
return { anno, score };
|
|
@@ -206,7 +228,7 @@ export function AnnotationsOverlay({
|
|
|
206
228
|
toggleAnnotation(annosWithScore[0].anno.id);
|
|
207
229
|
}
|
|
208
230
|
},
|
|
209
|
-
[annotationsAtPoint, canvasWorld, osdCanvasOverlay, toggleAnnotation],
|
|
231
|
+
[annotationsAtPoint, canvasWorld, osdCanvasOverlay, toggleAnnotation, viewer],
|
|
210
232
|
);
|
|
211
233
|
|
|
212
234
|
const onCanvasMouseMove = useDebouncedCallback(
|
|
@@ -120,4 +120,22 @@ export default class AnnotationItem {
|
|
|
120
120
|
|
|
121
121
|
return match && match[1].split(',').map((str) => parseInt(str, 10));
|
|
122
122
|
}
|
|
123
|
+
|
|
124
|
+
/** */
|
|
125
|
+
get pointSelector() {
|
|
126
|
+
const { selector } = this;
|
|
127
|
+
switch (typeof selector) {
|
|
128
|
+
case 'string':
|
|
129
|
+
return null;
|
|
130
|
+
case 'object':
|
|
131
|
+
return selector.find((s) => s.type && s.type === 'PointSelector');
|
|
132
|
+
default:
|
|
133
|
+
return null;
|
|
134
|
+
}
|
|
135
|
+
}
|
|
136
|
+
|
|
137
|
+
/** the POI's position within its journey (see mirador-annotation-editor's `dbf:journey`), or null when the POI is not part of a journey */
|
|
138
|
+
get journeyOrder() {
|
|
139
|
+
return this.resource['dbf:journey']?.order ?? null;
|
|
140
|
+
}
|
|
123
141
|
}
|
|
@@ -119,4 +119,18 @@ export default class AnnotationResource {
|
|
|
119
119
|
|
|
120
120
|
return match && match[1].split(',').map((str) => parseInt(str, 10));
|
|
121
121
|
}
|
|
122
|
+
|
|
123
|
+
/** */
|
|
124
|
+
get pointSelector() {
|
|
125
|
+
const { selector } = this;
|
|
126
|
+
if (selector && typeof selector === 'object' && selector['@type'] === 'oa:PointSelector') {
|
|
127
|
+
return { x: selector.x, y: selector.y };
|
|
128
|
+
}
|
|
129
|
+
return null;
|
|
130
|
+
}
|
|
131
|
+
|
|
132
|
+
/** the POI's position within its journey (see mirador-annotation-editor's `dbf:journey`), or null when the POI is not part of a journey */
|
|
133
|
+
get journeyOrder() {
|
|
134
|
+
return this.resource['dbf:journey']?.order ?? null;
|
|
135
|
+
}
|
|
122
136
|
}
|
|
@@ -4,6 +4,51 @@
|
|
|
4
4
|
*/
|
|
5
5
|
import { buildPath2D } from '../lib/svgShapesToPath';
|
|
6
6
|
|
|
7
|
+
/**
|
|
8
|
+
* The POI marker icon's path data and viewBox, copied from src/assets/icons/poi-marker.svg -
|
|
9
|
+
* inlined as a Path2D (rather than loaded as an image via drawImage) so it renders as a crisp
|
|
10
|
+
* vector at any zoom with no async image-load step to coordinate with the render loop. Update
|
|
11
|
+
* this constant (and the asset file, for reference) together if the icon changes.
|
|
12
|
+
*/
|
|
13
|
+
const POI_ICON_PATH_D =
|
|
14
|
+
'M50.002 0C30.763 0 15 15.718 15 34.902c0 7.432 2.374 14.34 6.392 20.019L45.73 96.994c3.409 4.453 5.675 3.607 8.51-.235l26.843-45.683c.542-.981.967-2.026 1.338-3.092A34.446 34.446 0 0 0 85 34.902C85 15.718 69.24 0 50.002 0zm0 16.354c10.359 0 18.597 8.218 18.597 18.548c0 10.33-8.238 18.544-18.597 18.544c-10.36 0-18.601-8.215-18.601-18.544c0-10.33 8.241-18.548 18.6-18.548z';
|
|
15
|
+
const POI_ICON_VIEWBOX_SIZE = 100;
|
|
16
|
+
/** The icon's own point (its pin tip), in viewBox units - this is what gets placed exactly on the annotated coordinate, not the icon's bounding-box center. Derived from the path's actual lowest point (~50, 100), not just its nearby `L` command endpoint. */
|
|
17
|
+
const POI_ICON_TIP = { x: 50, y: 100 };
|
|
18
|
+
/** Center/radius of the icon's circular head, in viewBox units - where a journey-order badge is drawn, overlapping the icon like a numbered pin. */
|
|
19
|
+
const POI_ICON_HEAD = { x: 50, y: 34.9, radius: 18.6 };
|
|
20
|
+
/** Font size of the journey-order number, relative to POI_ICON_HEAD.radius, so it's bigger than the badge circle would otherwise imply while the circle itself stays the same size. */
|
|
21
|
+
const POI_ICON_HEAD_FONT_SCALE = 1.6;
|
|
22
|
+
const POI_ICON_DEFAULT_FILL = '#1e88e5';
|
|
23
|
+
/** Constant on-screen height (CSS px) for the POI icon, regardless of zoom - counter-scaled the same way this class already counter-scales stroke width (see `lineWidth /= zoomRatio` in svgContext). */
|
|
24
|
+
export const POI_ICON_HEIGHT_PX = 44;
|
|
25
|
+
/**
|
|
26
|
+
* On-screen radius (CSS px, before counter-scaling by zoomRatio) of a POI marker's
|
|
27
|
+
* clickable/tappable hit target - deliberately independent of, and larger than, the icon's
|
|
28
|
+
* visual size (POI_ICON_HEIGHT_PX). The icon tapers to a fine point at its anchor, which is
|
|
29
|
+
* hard to hit precisely with a mouse and well under the ~44-48px minimum touch target size
|
|
30
|
+
* recommended for mobile (Apple HIG / Material Design), so the tappable area is deliberately
|
|
31
|
+
* generous rather than matching the icon's own footprint.
|
|
32
|
+
*/
|
|
33
|
+
export const POI_ICON_HIT_RADIUS_PX = 32;
|
|
34
|
+
|
|
35
|
+
/**
|
|
36
|
+
* The on-screen hit-test circle (already counter-scaled by zoomRatio, in the same coordinate
|
|
37
|
+
* space as a resource's `pointSelector`) for a POI marker anchored at (x, y). Centered on the
|
|
38
|
+
* icon's round head rather than its pin tip: the tip is the anchor point used for rendering
|
|
39
|
+
* (see pointContext/POI_ICON_TIP), but it's the least visually prominent, hardest-to-aim-for
|
|
40
|
+
* part of the icon, so hit-testing there instead of at the head would make the marker harder,
|
|
41
|
+
* not easier, to hit.
|
|
42
|
+
*/
|
|
43
|
+
export function poiHitTarget(x, y, zoomRatio) {
|
|
44
|
+
const iconScale = POI_ICON_HEIGHT_PX / zoomRatio / POI_ICON_VIEWBOX_SIZE;
|
|
45
|
+
return {
|
|
46
|
+
radius: POI_ICON_HIT_RADIUS_PX / zoomRatio,
|
|
47
|
+
x: x + (POI_ICON_HEAD.x - POI_ICON_TIP.x) * iconScale,
|
|
48
|
+
y: y + (POI_ICON_HEAD.y - POI_ICON_TIP.y) * iconScale,
|
|
49
|
+
};
|
|
50
|
+
}
|
|
51
|
+
|
|
7
52
|
export default class CanvasAnnotationDisplay {
|
|
8
53
|
/** */
|
|
9
54
|
constructor({ resource, palette, zoomRatio, offset, selected, hovered }) {
|
|
@@ -20,11 +65,70 @@ export default class CanvasAnnotationDisplay {
|
|
|
20
65
|
this.context = context;
|
|
21
66
|
if (this.resource.svgSelector) {
|
|
22
67
|
this.svgContext();
|
|
68
|
+
} else if (this.resource.pointSelector) {
|
|
69
|
+
this.pointContext();
|
|
23
70
|
} else if (this.resource.fragmentSelector) {
|
|
24
71
|
this.fragmentContext();
|
|
25
72
|
}
|
|
26
73
|
}
|
|
27
74
|
|
|
75
|
+
/** */
|
|
76
|
+
currentPalette() {
|
|
77
|
+
if (this.hovered) return this.palette.hovered;
|
|
78
|
+
if (this.selected) return this.palette.selected;
|
|
79
|
+
return this.palette.default;
|
|
80
|
+
}
|
|
81
|
+
|
|
82
|
+
/**
|
|
83
|
+
* Draws a POI marker (IIIF PointSelector) as the SVG pin icon, at a constant on-screen size,
|
|
84
|
+
* with the icon's own tip placed exactly on the annotated point. When the annotation carries
|
|
85
|
+
* journey-order metadata (`dbf:journey.order`), also draws a numbered badge over the icon's
|
|
86
|
+
* head, so a POI's position within its journey is visible directly on the map.
|
|
87
|
+
*/
|
|
88
|
+
pointContext() {
|
|
89
|
+
const { x, y } = this.resource.pointSelector;
|
|
90
|
+
const currentPalette = this.currentPalette();
|
|
91
|
+
if (currentPalette.globalAlpha === 0) return;
|
|
92
|
+
|
|
93
|
+
const iconHeight = POI_ICON_HEIGHT_PX / this.zoomRatio;
|
|
94
|
+
const iconScale = iconHeight / POI_ICON_VIEWBOX_SIZE;
|
|
95
|
+
|
|
96
|
+
this.context.save();
|
|
97
|
+
this.context.translate(this.offset.x + x, this.offset.y + y);
|
|
98
|
+
this.context.scale(iconScale, iconScale);
|
|
99
|
+
this.context.translate(-POI_ICON_TIP.x, -POI_ICON_TIP.y);
|
|
100
|
+
|
|
101
|
+
this.context.globalAlpha = currentPalette.globalAlpha ?? 1;
|
|
102
|
+
this.context.fillStyle = currentPalette.fillStyle || POI_ICON_DEFAULT_FILL;
|
|
103
|
+
this.context.fill(new Path2D(POI_ICON_PATH_D));
|
|
104
|
+
|
|
105
|
+
const { journeyOrder } = this.resource;
|
|
106
|
+
if (journeyOrder != null) {
|
|
107
|
+
this.journeyOrderBadgeContext(journeyOrder);
|
|
108
|
+
}
|
|
109
|
+
|
|
110
|
+
this.context.restore();
|
|
111
|
+
}
|
|
112
|
+
|
|
113
|
+
/**
|
|
114
|
+
* Draws a small numbered circle over the POI icon's head, in the icon's own (viewBox-unit,
|
|
115
|
+
* already-scaled/translated) coordinate space - called from within pointContext's transform,
|
|
116
|
+
* before it restores the context.
|
|
117
|
+
* @param {number} order
|
|
118
|
+
*/
|
|
119
|
+
journeyOrderBadgeContext(order) {
|
|
120
|
+
this.context.beginPath();
|
|
121
|
+
this.context.arc(POI_ICON_HEAD.x, POI_ICON_HEAD.y, POI_ICON_HEAD.radius, 0, Math.PI * 2);
|
|
122
|
+
this.context.fillStyle = '#ffffff';
|
|
123
|
+
this.context.fill();
|
|
124
|
+
|
|
125
|
+
this.context.fillStyle = this.currentPalette().fillStyle || POI_ICON_DEFAULT_FILL;
|
|
126
|
+
this.context.font = `bold ${POI_ICON_HEAD.radius * POI_ICON_HEAD_FONT_SCALE}px sans-serif`;
|
|
127
|
+
this.context.textAlign = 'center';
|
|
128
|
+
this.context.textBaseline = 'middle';
|
|
129
|
+
this.context.fillText(String(order), POI_ICON_HEAD.x, POI_ICON_HEAD.y);
|
|
130
|
+
}
|
|
131
|
+
|
|
28
132
|
/** */
|
|
29
133
|
get svgString() {
|
|
30
134
|
return this.resource.svgSelector.value;
|
|
@@ -0,0 +1,340 @@
|
|
|
1
|
+
import { useState, type ComponentType } from 'react';
|
|
2
|
+
import {
|
|
3
|
+
ConnectedCompanionWindow as CompanionWindow,
|
|
4
|
+
addCompanionWindow,
|
|
5
|
+
getAnnotations,
|
|
6
|
+
getCompanionWindow,
|
|
7
|
+
getCompanionWindows,
|
|
8
|
+
getVisibleCanvases,
|
|
9
|
+
updateCompanionWindow,
|
|
10
|
+
} from 'dbf-mirador';
|
|
11
|
+
|
|
12
|
+
// A "dumb" way to preview a POI/journey (issue #375): a Mirador companion window plugin,
|
|
13
|
+
// registered alongside dbf-mirador-annotation-editor's own (see MiradorMaeViewer.tsx) via
|
|
14
|
+
// Mirador's `companionWindowKey` mechanism - no core patch needed, just adding this plugin
|
|
15
|
+
// to the same `plugins` array. The actual "Preview" button lives per-row in
|
|
16
|
+
// dbf-mirador-annotation-editor's own CanvasListItem.jsx, right next to Edit/Delete
|
|
17
|
+
// (see that package's own PR for issue #375) - it opens this companion window passing the
|
|
18
|
+
// specific row's id as `annotationid`, the same convention MAE's own 'annotationCreation'
|
|
19
|
+
// companion window already uses for its own Edit button.
|
|
20
|
+
//
|
|
21
|
+
// Journeys (issue #378) get a richer path here: instead of the "dumb" dual-locale dump
|
|
22
|
+
// below, a Journey renders its ordered stops as numbered cards with a single active
|
|
23
|
+
// locale (toggle EN/AR), closer to how the public site will eventually present it. Two
|
|
24
|
+
// pieces of the Figma design are intentionally NOT built here, per the issue author's own
|
|
25
|
+
// follow-up comment saying they "wait more precision": numbered pins drawn on the map
|
|
26
|
+
// canvas itself, and an SVG line joining those pins in journey order.
|
|
27
|
+
|
|
28
|
+
const POI_PREVIEW_CONTENT_ID = 'mapsPoiPreview';
|
|
29
|
+
|
|
30
|
+
type TextualAnnotationBody = {
|
|
31
|
+
purpose: 'identifying' | 'describing';
|
|
32
|
+
type: 'TextualBody';
|
|
33
|
+
language: string;
|
|
34
|
+
value: string;
|
|
35
|
+
};
|
|
36
|
+
|
|
37
|
+
// Mirrors the maps plugin's `Annotation['dbf:mediaEn']`/`Annotation['dbf:mediaAr']`
|
|
38
|
+
// (issue #377) - one media selection per language, unlike the single, language-agnostic
|
|
39
|
+
// `dbf:media` extension issue #391 briefly introduced.
|
|
40
|
+
type DbfMedia = {
|
|
41
|
+
source: 'upload' | 'iiif-image' | 'media-item';
|
|
42
|
+
id: string;
|
|
43
|
+
title: string | null;
|
|
44
|
+
mediaType?: string | null;
|
|
45
|
+
thumbnailUrl: string | null;
|
|
46
|
+
};
|
|
47
|
+
|
|
48
|
+
type RawAnnotation = {
|
|
49
|
+
id: string;
|
|
50
|
+
'dbf:kind'?: 'POI' | 'Journey';
|
|
51
|
+
'dbf:mediaEn'?: DbfMedia | null;
|
|
52
|
+
'dbf:mediaAr'?: DbfMedia | null;
|
|
53
|
+
// A POI's membership in a journey and its position within it - a Journey never lists
|
|
54
|
+
// its own POIs, membership is always POI -> Journey (see mirador-annotation-editor's
|
|
55
|
+
// annotationListGrouping.js, which this plugin can't import directly since grouping
|
|
56
|
+
// isn't part of that package's public API - so the same filter+sort is redone below).
|
|
57
|
+
'dbf:journey'?: { id: string; order: number } | null;
|
|
58
|
+
body?: TextualAnnotationBody[];
|
|
59
|
+
};
|
|
60
|
+
|
|
61
|
+
// Both locales, side by side - see the module comment above: the point of a "dumb" preview
|
|
62
|
+
// is to see everything a poi/journey holds, not to render it the way the public site
|
|
63
|
+
// eventually will for one active language.
|
|
64
|
+
const LOCALES = ['en', 'ar'] as const;
|
|
65
|
+
|
|
66
|
+
const textBody = (
|
|
67
|
+
annotation: RawAnnotation,
|
|
68
|
+
language: string,
|
|
69
|
+
purpose: 'identifying' | 'describing'
|
|
70
|
+
): string =>
|
|
71
|
+
annotation.body?.find(
|
|
72
|
+
(item): item is TextualAnnotationBody =>
|
|
73
|
+
item.type === 'TextualBody' && item.purpose === purpose && item.language === language
|
|
74
|
+
)?.value ?? '';
|
|
75
|
+
|
|
76
|
+
const mediaForLocale = (annotation: RawAnnotation, locale: (typeof LOCALES)[number]): DbfMedia | null | undefined =>
|
|
77
|
+
locale === 'en' ? annotation['dbf:mediaEn'] : annotation['dbf:mediaAr'];
|
|
78
|
+
|
|
79
|
+
// A journey's ordered stops, derived the same way the rest of the codebase does: every
|
|
80
|
+
// POI whose `dbf:journey.id` points at this journey, sorted by `dbf:journey.order`.
|
|
81
|
+
export const getOrderedJourneyPois = (items: RawAnnotation[], journeyId: string): RawAnnotation[] =>
|
|
82
|
+
items
|
|
83
|
+
.filter(
|
|
84
|
+
(item): item is RawAnnotation & { 'dbf:journey': { id: string; order: number } } =>
|
|
85
|
+
item['dbf:kind'] === 'POI' && item['dbf:journey']?.id === journeyId
|
|
86
|
+
)
|
|
87
|
+
.sort((a, b) => a['dbf:journey'].order - b['dbf:journey'].order);
|
|
88
|
+
|
|
89
|
+
const JOURNEY_PREVIEW_LOCALES = ['en', 'ar'] as const;
|
|
90
|
+
type JourneyPreviewLocale = (typeof JOURNEY_PREVIEW_LOCALES)[number];
|
|
91
|
+
|
|
92
|
+
// Arabic is the only RTL locale this project handles today (mirrors the same check in
|
|
93
|
+
// mirador-annotation-editor's POITemplate.jsx/JourneyTemplate.jsx).
|
|
94
|
+
const isRtlLocale = (locale: string) => locale.toLowerCase().startsWith('ar');
|
|
95
|
+
|
|
96
|
+
interface JourneyPreviewContentProps {
|
|
97
|
+
id: string;
|
|
98
|
+
journey: RawAnnotation;
|
|
99
|
+
pois: RawAnnotation[];
|
|
100
|
+
windowId: string;
|
|
101
|
+
}
|
|
102
|
+
|
|
103
|
+
const JourneyPreviewContent = ({ id, journey, pois, windowId }: JourneyPreviewContentProps) => {
|
|
104
|
+
const [locale, setLocale] = useState<JourneyPreviewLocale>('en');
|
|
105
|
+
const journeyTitle = textBody(journey, locale, 'identifying');
|
|
106
|
+
|
|
107
|
+
return (
|
|
108
|
+
<CompanionWindow id={id} title={journeyTitle || 'Journey'} windowId={windowId}>
|
|
109
|
+
<div dir={isRtlLocale(locale) ? 'rtl' : 'ltr'} style={{ padding: 16 }}>
|
|
110
|
+
<div style={{ display: 'flex', justifyContent: 'flex-end', gap: 4, marginBottom: 16 }}>
|
|
111
|
+
{JOURNEY_PREVIEW_LOCALES.map((code) => (
|
|
112
|
+
<button
|
|
113
|
+
aria-pressed={locale === code}
|
|
114
|
+
key={code}
|
|
115
|
+
onClick={() => setLocale(code)}
|
|
116
|
+
style={{
|
|
117
|
+
background: locale === code ? '#333' : 'transparent',
|
|
118
|
+
border: '1px solid #333',
|
|
119
|
+
borderRadius: 4,
|
|
120
|
+
color: locale === code ? '#fff' : '#333',
|
|
121
|
+
cursor: 'pointer',
|
|
122
|
+
padding: '4px 12px',
|
|
123
|
+
}}
|
|
124
|
+
type="button"
|
|
125
|
+
>
|
|
126
|
+
{code.toUpperCase()}
|
|
127
|
+
</button>
|
|
128
|
+
))}
|
|
129
|
+
</div>
|
|
130
|
+
{pois.length === 0 && <p>This journey has no stops yet.</p>}
|
|
131
|
+
{pois.map((poi, index) => {
|
|
132
|
+
const poiTitle = textBody(poi, locale, 'identifying');
|
|
133
|
+
const description = textBody(poi, locale, 'describing');
|
|
134
|
+
const media = mediaForLocale(poi, locale);
|
|
135
|
+
const isLast = index === pois.length - 1;
|
|
136
|
+
return (
|
|
137
|
+
<div key={poi.id} style={{ display: 'flex' }}>
|
|
138
|
+
<div
|
|
139
|
+
style={{
|
|
140
|
+
alignItems: 'center',
|
|
141
|
+
display: 'flex',
|
|
142
|
+
flexDirection: 'column',
|
|
143
|
+
marginInlineEnd: 16,
|
|
144
|
+
}}
|
|
145
|
+
>
|
|
146
|
+
<span
|
|
147
|
+
style={{
|
|
148
|
+
alignItems: 'center',
|
|
149
|
+
background: '#000',
|
|
150
|
+
borderRadius: '50%',
|
|
151
|
+
color: '#fff',
|
|
152
|
+
display: 'flex',
|
|
153
|
+
flexShrink: 0,
|
|
154
|
+
fontWeight: 'bold',
|
|
155
|
+
height: 28,
|
|
156
|
+
justifyContent: 'center',
|
|
157
|
+
width: 28,
|
|
158
|
+
}}
|
|
159
|
+
>
|
|
160
|
+
{index + 1}
|
|
161
|
+
</span>
|
|
162
|
+
{/* A plain vertical stepper line standing in for the map's own dashed
|
|
163
|
+
connector line, which is out of scope here - see the module comment. */}
|
|
164
|
+
{!isLast && <div style={{ background: '#ccc', flex: 1, margin: '4px 0', width: 2 }} />}
|
|
165
|
+
</div>
|
|
166
|
+
<div style={{ flex: 1, paddingBottom: isLast ? 0 : 24 }}>
|
|
167
|
+
<h3 style={{ margin: '0 0 8px' }}>{poiTitle || '—'}</h3>
|
|
168
|
+
{media?.thumbnailUrl && (
|
|
169
|
+
<img
|
|
170
|
+
alt={media.title ?? ''}
|
|
171
|
+
src={media.thumbnailUrl}
|
|
172
|
+
style={{ borderRadius: 8, marginBottom: 8, maxWidth: '100%' }}
|
|
173
|
+
/>
|
|
174
|
+
)}
|
|
175
|
+
{description && (
|
|
176
|
+
// eslint-disable-next-line react/no-danger -- description is CKEditor HTML, the same content the public site will eventually render
|
|
177
|
+
<div dangerouslySetInnerHTML={{ __html: description }} />
|
|
178
|
+
)}
|
|
179
|
+
</div>
|
|
180
|
+
</div>
|
|
181
|
+
);
|
|
182
|
+
})}
|
|
183
|
+
</div>
|
|
184
|
+
</CompanionWindow>
|
|
185
|
+
);
|
|
186
|
+
};
|
|
187
|
+
|
|
188
|
+
interface PoiPreviewContentProps {
|
|
189
|
+
annotation: RawAnnotation | null;
|
|
190
|
+
id: string;
|
|
191
|
+
windowId: string;
|
|
192
|
+
}
|
|
193
|
+
|
|
194
|
+
const PoiPreviewContent = ({ annotation, id, windowId }: PoiPreviewContentProps) => (
|
|
195
|
+
<CompanionWindow id={id} title={annotation?.['dbf:kind'] ?? 'Preview'} windowId={windowId}>
|
|
196
|
+
<div style={{ padding: 16 }}>
|
|
197
|
+
{!annotation && <p>This annotation could not be found - it may have been deleted.</p>}
|
|
198
|
+
{annotation &&
|
|
199
|
+
LOCALES.map((locale) => {
|
|
200
|
+
const title = textBody(annotation, locale, 'identifying');
|
|
201
|
+
const description = textBody(annotation, locale, 'describing');
|
|
202
|
+
const media = mediaForLocale(annotation, locale);
|
|
203
|
+
return (
|
|
204
|
+
<section key={locale} style={{ marginBottom: 24 }}>
|
|
205
|
+
<h3 style={{ textTransform: 'uppercase' }}>{locale}</h3>
|
|
206
|
+
<p>
|
|
207
|
+
<strong>{title || '—'}</strong>
|
|
208
|
+
</p>
|
|
209
|
+
{description && (
|
|
210
|
+
// eslint-disable-next-line react/no-danger -- descriptionEn/Ar is CKEditor HTML, the same content the public site will eventually render
|
|
211
|
+
<div dangerouslySetInnerHTML={{ __html: description }} />
|
|
212
|
+
)}
|
|
213
|
+
{media &&
|
|
214
|
+
(media.thumbnailUrl ? (
|
|
215
|
+
<img alt={media.title ?? ''} src={media.thumbnailUrl} style={{ maxWidth: '100%' }} />
|
|
216
|
+
) : (
|
|
217
|
+
<p>
|
|
218
|
+
{media.title}
|
|
219
|
+
{media.mediaType ? ` (${media.mediaType})` : ''}
|
|
220
|
+
</p>
|
|
221
|
+
))}
|
|
222
|
+
</section>
|
|
223
|
+
);
|
|
224
|
+
})}
|
|
225
|
+
</div>
|
|
226
|
+
</CompanionWindow>
|
|
227
|
+
);
|
|
228
|
+
|
|
229
|
+
interface PreviewContentProps {
|
|
230
|
+
annotation: RawAnnotation | null;
|
|
231
|
+
id: string;
|
|
232
|
+
journeyPois: RawAnnotation[];
|
|
233
|
+
windowId: string;
|
|
234
|
+
}
|
|
235
|
+
|
|
236
|
+
const PreviewContent = ({ annotation, id, journeyPois, windowId }: PreviewContentProps) => {
|
|
237
|
+
if (annotation && annotation['dbf:kind'] === 'Journey') {
|
|
238
|
+
return <JourneyPreviewContent id={id} journey={annotation} pois={journeyPois} windowId={windowId} />;
|
|
239
|
+
}
|
|
240
|
+
return <PoiPreviewContent annotation={annotation} id={id} windowId={windowId} />;
|
|
241
|
+
};
|
|
242
|
+
|
|
243
|
+
const poiPreviewCompanionWindowPlugin = {
|
|
244
|
+
component: PreviewContent,
|
|
245
|
+
companionWindowKey: POI_PREVIEW_CONTENT_ID,
|
|
246
|
+
mapStateToProps: (state: unknown, { id, windowId }: { id: string; windowId: string }) => {
|
|
247
|
+
const annotationId = getCompanionWindow(state, { companionWindowId: id })?.annotationid as
|
|
248
|
+
| string
|
|
249
|
+
| undefined;
|
|
250
|
+
const canvasId = getVisibleCanvases(state, { windowId })[0]?.id;
|
|
251
|
+
const pages: Record<string, { json?: { items?: unknown[] } }> | undefined = canvasId
|
|
252
|
+
? getAnnotations(state)[canvasId]
|
|
253
|
+
: undefined;
|
|
254
|
+
const items = (pages ? Object.values(pages) : []).flatMap(
|
|
255
|
+
(page) => (page.json?.items ?? []) as RawAnnotation[]
|
|
256
|
+
);
|
|
257
|
+
const annotation = items.find((item) => item.id === annotationId) ?? null;
|
|
258
|
+
return {
|
|
259
|
+
annotation,
|
|
260
|
+
journeyPois:
|
|
261
|
+
annotation && annotation['dbf:kind'] === 'Journey' ? getOrderedJourneyPois(items, annotation.id) : [],
|
|
262
|
+
};
|
|
263
|
+
},
|
|
264
|
+
};
|
|
265
|
+
|
|
266
|
+
// A canvas annotation resource, as AnnotationsOverlay's own `annotations`/`searchAnnotations`
|
|
267
|
+
// props carry it (see AnnotationItem#pointSelector) - a POI marker is any resource with a
|
|
268
|
+
// pointSelector, exactly the condition CanvasAnnotationDisplay#pointContext draws on.
|
|
269
|
+
type AnnotationResourceLike = { id: string; pointSelector?: unknown };
|
|
270
|
+
type AnnotationListItem = { resources?: AnnotationResourceLike[] };
|
|
271
|
+
|
|
272
|
+
interface AnnotationsOverlayTargetProps {
|
|
273
|
+
annotations?: AnnotationListItem[];
|
|
274
|
+
searchAnnotations?: AnnotationListItem[];
|
|
275
|
+
selectAnnotation?: (windowId: string, annotationId: string) => void;
|
|
276
|
+
windowId: string;
|
|
277
|
+
[key: string]: unknown;
|
|
278
|
+
}
|
|
279
|
+
|
|
280
|
+
interface AnnotationsOverlayPoiClickWrapperProps {
|
|
281
|
+
TargetComponent: ComponentType<Record<string, unknown>>;
|
|
282
|
+
targetProps: AnnotationsOverlayTargetProps;
|
|
283
|
+
addCompanionWindow: typeof addCompanionWindow;
|
|
284
|
+
updateCompanionWindow: typeof updateCompanionWindow;
|
|
285
|
+
existingPreviewCompanionWindowId?: string;
|
|
286
|
+
}
|
|
287
|
+
|
|
288
|
+
// Wraps AnnotationsOverlay (the component that owns the OSD canvas-click handler and the
|
|
289
|
+
// select/deselect-annotation dispatch, see AnnotationsOverlay#toggleAnnotation) so that
|
|
290
|
+
// clicking a POI marker on the canvas - not just a row in a list somewhere - opens this same
|
|
291
|
+
// preview companion window a "Preview" button would (issue #375's own follow-up: pins on the
|
|
292
|
+
// map itself). Re-uses an already-open preview window instead of stacking a new one per click.
|
|
293
|
+
const AnnotationsOverlayPoiClickWrapper = ({
|
|
294
|
+
TargetComponent,
|
|
295
|
+
targetProps,
|
|
296
|
+
addCompanionWindow: dispatchAddCompanionWindow,
|
|
297
|
+
updateCompanionWindow: dispatchUpdateCompanionWindow,
|
|
298
|
+
existingPreviewCompanionWindowId,
|
|
299
|
+
}: AnnotationsOverlayPoiClickWrapperProps) => {
|
|
300
|
+
const { annotations = [], searchAnnotations = [], selectAnnotation } = targetProps;
|
|
301
|
+
|
|
302
|
+
const selectAnnotationAndMaybePreview = (clickedWindowId: string, annotationId: string) => {
|
|
303
|
+
selectAnnotation?.(clickedWindowId, annotationId);
|
|
304
|
+
|
|
305
|
+
const resource = [...annotations, ...searchAnnotations]
|
|
306
|
+
.flatMap((item) => item.resources ?? [])
|
|
307
|
+
.find((item) => item.id === annotationId);
|
|
308
|
+
|
|
309
|
+
if (!resource?.pointSelector) return;
|
|
310
|
+
|
|
311
|
+
if (existingPreviewCompanionWindowId) {
|
|
312
|
+
dispatchUpdateCompanionWindow(clickedWindowId, existingPreviewCompanionWindowId, {
|
|
313
|
+
annotationid: annotationId,
|
|
314
|
+
});
|
|
315
|
+
} else {
|
|
316
|
+
dispatchAddCompanionWindow(clickedWindowId, {
|
|
317
|
+
annotationid: annotationId,
|
|
318
|
+
content: POI_PREVIEW_CONTENT_ID,
|
|
319
|
+
position: 'right',
|
|
320
|
+
});
|
|
321
|
+
}
|
|
322
|
+
};
|
|
323
|
+
|
|
324
|
+
return <TargetComponent {...targetProps} selectAnnotation={selectAnnotationAndMaybePreview} />;
|
|
325
|
+
};
|
|
326
|
+
|
|
327
|
+
const poiPreviewClickPlugin = {
|
|
328
|
+
target: 'AnnotationsOverlay',
|
|
329
|
+
mode: 'wrap',
|
|
330
|
+
component: AnnotationsOverlayPoiClickWrapper,
|
|
331
|
+
mapStateToProps: (state: unknown, { windowId }: { windowId: string }) => {
|
|
332
|
+
const existing = Object.values(getCompanionWindows(state) as Record<string, { id: string; windowId: string; content: string | null }>).find(
|
|
333
|
+
(cw) => cw.windowId === windowId && cw.content === POI_PREVIEW_CONTENT_ID,
|
|
334
|
+
);
|
|
335
|
+
return { existingPreviewCompanionWindowId: existing?.id };
|
|
336
|
+
},
|
|
337
|
+
mapDispatchToProps: { addCompanionWindow, updateCompanionWindow },
|
|
338
|
+
};
|
|
339
|
+
|
|
340
|
+
export const poiPreviewPlugins = [poiPreviewCompanionWindowPlugin, poiPreviewClickPlugin];
|