dbf-mirador 4.3.0-testing3 → 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/{OpenSeadragonViewer-B_KV5sbU.js → OpenSeadragonViewer-4nw8qaVM.js} +342 -329
- package/dist/OpenSeadragonViewer-4nw8qaVM.js.map +1 -0
- package/dist/{WindowViewer-DMNeTH1_.js → WindowViewer-uHVYcMsX.js} +2 -2
- package/dist/{WindowViewer-DMNeTH1_.js.map → WindowViewer-uHVYcMsX.js.map} +1 -1
- package/dist/{WorkspaceArea-CzKnpSim.js → WorkspaceArea-CAti6dTA.js} +2 -2
- package/dist/{WorkspaceArea-CzKnpSim.js.map → WorkspaceArea-CAti6dTA.js.map} +1 -1
- package/dist/mirador.es.js +4 -4
- package/dist/mirador.min.js +33 -33
- package/dist/mirador.min.js.map +1 -1
- package/package.json +1 -1
- package/src/components/AnnotationsOverlay.jsx +34 -27
- package/src/lib/CanvasAnnotationDisplay.js +32 -4
- package/src/plugins/poiPreviewPlugin.tsx +340 -0
- package/dist/OpenSeadragonViewer-B_KV5sbU.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,11 +2,12 @@ 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, {
|
|
10
|
+
import CanvasAnnotationDisplay, { poiHitTarget } from '../lib/CanvasAnnotationDisplay';
|
|
10
11
|
import { buildPath2D } from '../lib/svgShapesToPath';
|
|
11
12
|
|
|
12
13
|
/** @private */
|
|
@@ -30,10 +31,10 @@ function isAnnotationAtPoint({ canvasWorld, osdCanvasOverlay, viewer }, resource
|
|
|
30
31
|
// CanvasAnnotationDisplay#pointContext), so its clickable footprint must counter-scale the
|
|
31
32
|
// same way, or the hit region would shrink/grow with the image instead of the icon.
|
|
32
33
|
const zoomRatio = viewportCanvas.viewportToImageZoom(viewer.viewport.getZoom(true));
|
|
33
|
-
const
|
|
34
|
-
const dx = relativeX - x;
|
|
35
|
-
const dy = relativeY - y;
|
|
36
|
-
return dx * dx + dy * dy <=
|
|
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;
|
|
37
38
|
}
|
|
38
39
|
|
|
39
40
|
if (resource.fragmentSelector) {
|
|
@@ -97,30 +98,36 @@ export function AnnotationsOverlay({
|
|
|
97
98
|
const annotationsToContext = useCallback(
|
|
98
99
|
(renderedAnnotations, currentPalette) => {
|
|
99
100
|
const context = osdCanvasOverlay.context2d;
|
|
100
|
-
renderedAnnotations.
|
|
101
|
-
|
|
102
|
-
|
|
103
|
-
|
|
104
|
-
|
|
105
|
-
|
|
106
|
-
|
|
107
|
-
|
|
108
|
-
|
|
109
|
-
|
|
110
|
-
|
|
111
|
-
|
|
112
|
-
|
|
113
|
-
|
|
114
|
-
|
|
115
|
-
|
|
116
|
-
|
|
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),
|
|
117
124
|
},
|
|
118
|
-
|
|
119
|
-
|
|
120
|
-
|
|
121
|
-
|
|
122
|
-
canvasAnnotationDisplay.toContext(context);
|
|
125
|
+
},
|
|
126
|
+
resource,
|
|
127
|
+
selected: selectedAnnotationId === resource.id,
|
|
128
|
+
zoomRatio,
|
|
123
129
|
});
|
|
130
|
+
canvasAnnotationDisplay.toContext(context);
|
|
124
131
|
});
|
|
125
132
|
},
|
|
126
133
|
[osdCanvasOverlay, viewer, canvasWorld, highlightAllAnnotations, hoveredAnnotationIds, selectedAnnotationId],
|
|
@@ -13,13 +13,41 @@ import { buildPath2D } from '../lib/svgShapesToPath';
|
|
|
13
13
|
const POI_ICON_PATH_D =
|
|
14
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
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. */
|
|
17
|
-
const POI_ICON_TIP = { x: 50, y:
|
|
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
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
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;
|
|
20
22
|
const POI_ICON_DEFAULT_FILL = '#1e88e5';
|
|
21
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). */
|
|
22
|
-
export const POI_ICON_HEIGHT_PX =
|
|
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
|
+
}
|
|
23
51
|
|
|
24
52
|
export default class CanvasAnnotationDisplay {
|
|
25
53
|
/** */
|
|
@@ -95,7 +123,7 @@ export default class CanvasAnnotationDisplay {
|
|
|
95
123
|
this.context.fill();
|
|
96
124
|
|
|
97
125
|
this.context.fillStyle = this.currentPalette().fillStyle || POI_ICON_DEFAULT_FILL;
|
|
98
|
-
this.context.font = `bold ${POI_ICON_HEAD.radius}px sans-serif`;
|
|
126
|
+
this.context.font = `bold ${POI_ICON_HEAD.radius * POI_ICON_HEAD_FONT_SCALE}px sans-serif`;
|
|
99
127
|
this.context.textAlign = 'center';
|
|
100
128
|
this.context.textBaseline = 'middle';
|
|
101
129
|
this.context.fillText(String(order), POI_ICON_HEAD.x, POI_ICON_HEAD.y);
|
|
@@ -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];
|