@xynolog/react-ui 0.8.0 → 0.8.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/README.md +26 -46
- package/package.json +12 -9
- package/src/components/Button/Button.tsx +0 -188
- package/src/components/Button/__tests__/Button.test.tsx +0 -449
- package/src/components/CodeMirrorRenderer.tsx +0 -536
- package/src/components/DelegateProgress.tsx +0 -308
- package/src/components/ErrorBoundary.tsx +0 -174
- package/src/components/ItemFoundLog.tsx +0 -42
- package/src/components/LiveRegion.tsx +0 -261
- package/src/components/ProtectedErrorBoundary.tsx +0 -114
- package/src/components/ResizeHandle.tsx +0 -167
- package/src/components/ResourceTagsInline.tsx +0 -120
- package/src/components/SessionExpiryBanner.tsx +0 -74
- package/src/components/SessionTimer.tsx +0 -17
- package/src/components/StatusDisplay.tsx +0 -131
- package/src/components/Toast.tsx +0 -217
- package/src/components/Toolbar.tsx +0 -194
- package/src/components/UserMenuSkeleton.tsx +0 -13
- package/src/components/__tests__/DelegateProgress.denominator.test.tsx +0 -102
- package/src/components/__tests__/DelegateProgress.test.tsx +0 -649
- package/src/components/__tests__/ErrorBoundary.test.tsx +0 -565
- package/src/components/__tests__/LiveRegion.a11y.test.tsx +0 -258
- package/src/components/__tests__/LiveRegion.hooks.test.tsx +0 -140
- package/src/components/__tests__/ProtectedErrorBoundary.test.tsx +0 -225
- package/src/components/__tests__/ResizeHandle.test.tsx +0 -159
- package/src/components/__tests__/ResourceTagsInline.test.tsx +0 -325
- package/src/components/__tests__/SessionExpiryBanner.test.tsx +0 -124
- package/src/components/__tests__/SessionTimer.test.tsx +0 -199
- package/src/components/__tests__/StatusDisplay.test.tsx +0 -179
- package/src/components/__tests__/Toast.test.tsx +0 -96
- package/src/components/__tests__/Toolbar.test.tsx +0 -111
- package/src/components/__tests__/UserMenuSkeleton.test.tsx +0 -182
- package/src/components/annotation/AnchoredTextNotice.tsx +0 -36
- package/src/components/annotation/AnnotateToolbar.tsx +0 -531
- package/src/components/annotation/__tests__/AnnotateToolbar.display.test.tsx +0 -127
- package/src/components/annotation/__tests__/AnnotateToolbar.test.tsx +0 -304
- package/src/components/annotation-popups/JsonLdView.tsx +0 -127
- package/src/components/annotation-popups/SharedPopupElements.tsx +0 -131
- package/src/components/annotation-popups/__tests__/JsonLdView.test.tsx +0 -432
- package/src/components/annotation-popups/__tests__/SharedPopupElements.test.tsx +0 -297
- package/src/components/branding/XynologBranding.tsx +0 -41
- package/src/components/branding/__tests__/XynologBranding.test.tsx +0 -383
- package/src/components/error-states/ResourceErrorState.tsx +0 -30
- package/src/components/error-states/__tests__/ResourceErrorState.test.tsx +0 -102
- package/src/components/image-annotation/AnnotationOverlay.tsx +0 -307
- package/src/components/image-annotation/SvgDrawingCanvas.tsx +0 -514
- package/src/components/image-annotation/__tests__/AnnotationOverlay.click.test.tsx +0 -169
- package/src/components/image-annotation/__tests__/AnnotationOverlay.hover.test.tsx +0 -83
- package/src/components/image-annotation/__tests__/SvgDrawingCanvas.annotate-gate.test.tsx +0 -228
- package/src/components/image-annotation/__tests__/SvgDrawingCanvas.click.test.tsx +0 -204
- package/src/components/layout/LeftSidebar.tsx +0 -150
- package/src/components/layout/PageLayout.tsx +0 -49
- package/src/components/layout/SkipLinks.tsx +0 -36
- package/src/components/layout/UnifiedHeader.tsx +0 -151
- package/src/components/layout/__tests__/LeftSidebar.test.tsx +0 -426
- package/src/components/layout/__tests__/PageLayout.test.tsx +0 -311
- package/src/components/layout/__tests__/SkipLinks.a11y.test.tsx +0 -218
- package/src/components/layout/__tests__/UnifiedHeader.test.tsx +0 -555
- package/src/components/loading-states/ComposeLoadingState.tsx +0 -19
- package/src/components/loading-states/ResourceLoadingState.tsx +0 -13
- package/src/components/loading-states/__tests__/ComposeLoadingState.test.tsx +0 -37
- package/src/components/loading-states/__tests__/ResourceLoadingState.test.tsx +0 -31
- package/src/components/modals/ComposeStep.tsx +0 -245
- package/src/components/modals/ConfigureGatherStep.tsx +0 -110
- package/src/components/modals/ConfigureGenerationStep.tsx +0 -458
- package/src/components/modals/ConfigureSearchStep.tsx +0 -124
- package/src/components/modals/ContextSummary.tsx +0 -317
- package/src/components/modals/CorpusPane.tsx +0 -96
- package/src/components/modals/DiscardPrompt.tsx +0 -44
- package/src/components/modals/GatherContextStep.tsx +0 -480
- package/src/components/modals/KbIdentityConflictModal.tsx +0 -122
- package/src/components/modals/KeyboardShortcutsHelpModal.tsx +0 -238
- package/src/components/modals/PermissionDeniedModal.tsx +0 -207
- package/src/components/modals/ReferenceWizardModal.tsx +0 -656
- package/src/components/modals/ResourceGenerateModal.tsx +0 -457
- package/src/components/modals/SearchModal.tsx +0 -334
- package/src/components/modals/SearchResultsStep.tsx +0 -117
- package/src/components/modals/SessionEndedModal.tsx +0 -148
- package/src/components/modals/WizardFooter.tsx +0 -72
- package/src/components/modals/__tests__/ComposeStep.test.tsx +0 -187
- package/src/components/modals/__tests__/ConfigureGatherStep.test.tsx +0 -92
- package/src/components/modals/__tests__/ConfigureGenerationStep.test.tsx +0 -574
- package/src/components/modals/__tests__/ConfigureSearchStep.test.tsx +0 -124
- package/src/components/modals/__tests__/GatherContextStep.resource.test.tsx +0 -702
- package/src/components/modals/__tests__/KbIdentityConflictModal.test.tsx +0 -102
- package/src/components/modals/__tests__/KeyboardShortcutsHelpModal.test.tsx +0 -115
- package/src/components/modals/__tests__/PermissionDeniedModal.test.tsx +0 -218
- package/src/components/modals/__tests__/ReferenceWizardModal.test.tsx +0 -936
- package/src/components/modals/__tests__/ResourceGenerateModal.test.tsx +0 -532
- package/src/components/modals/__tests__/SearchModal.accessibility.test.tsx +0 -95
- package/src/components/modals/__tests__/SearchModal.basic.test.tsx +0 -84
- package/src/components/modals/__tests__/SearchModal.keyboard.test.tsx +0 -162
- package/src/components/modals/__tests__/SearchModal.search-wiring.test.tsx +0 -237
- package/src/components/modals/__tests__/SearchModal.translations.test.tsx +0 -91
- package/src/components/modals/__tests__/SearchResultsStep.test.tsx +0 -95
- package/src/components/modals/__tests__/SessionEndedModal.test.tsx +0 -171
- package/src/components/modals/__tests__/WizardFooter.test.tsx +0 -446
- package/src/components/modals/__tests__/search-modal-harness.ts +0 -82
- package/src/components/navigation/CollapsibleResourceNavigation.tsx +0 -364
- package/src/components/navigation/NavigationMenu.tsx +0 -66
- package/src/components/navigation/ObservableLink.tsx +0 -90
- package/src/components/navigation/SimpleNavigation.tsx +0 -169
- package/src/components/navigation/SortableResourceTab.tsx +0 -122
- package/src/components/navigation/__tests__/NavigationMenu.a11y.test.tsx +0 -302
- package/src/components/navigation/__tests__/NavigationMenu.test.tsx +0 -399
- package/src/components/navigation/__tests__/ObservableLink.test.tsx +0 -85
- package/src/components/navigation/__tests__/SimpleNavigation.test.tsx +0 -193
- package/src/components/navigation/__tests__/SortableResourceTab.test.tsx +0 -421
- package/src/components/pdf-annotation/PdfAnnotationCanvas.client.tsx +0 -10
- package/src/components/pdf-annotation/PdfAnnotationCanvas.tsx +0 -632
- package/src/components/pdf-annotation/PdfPageView.tsx +0 -527
- package/src/components/pdf-annotation/__tests__/PdfAnnotationCanvas.annotate-gate.test.tsx +0 -295
- package/src/components/pdf-annotation/__tests__/PdfAnnotationCanvas.pixels-before-anchoring.test.tsx +0 -166
- package/src/components/pdf-annotation/__tests__/PdfAnnotationCanvas.test.tsx +0 -1719
- package/src/components/pdf-annotation/__tests__/estimate-slot-height.test.ts +0 -61
- package/src/components/pdf-annotation/__tests__/rects-for-page.test.ts +0 -110
- package/src/components/pdf-annotation/estimate-slot-height.ts +0 -31
- package/src/components/pdf-annotation/rects-for-page.ts +0 -50
- package/src/components/resource/AnnotateView.tsx +0 -373
- package/src/components/resource/AnnotationHistory.tsx +0 -169
- package/src/components/resource/BrowseView.tsx +0 -440
- package/src/components/resource/DownloadFileLink.tsx +0 -53
- package/src/components/resource/HistoryEvent.tsx +0 -186
- package/src/components/resource/ResourceViewer.tsx +0 -617
- package/src/components/resource/__tests__/AnnotateView.code-point-offsets.test.tsx +0 -482
- package/src/components/resource/__tests__/AnnotateView.embeddable.test.tsx +0 -78
- package/src/components/resource/__tests__/AnnotateView.focus.test.tsx +0 -147
- package/src/components/resource/__tests__/AnnotateView.registry.test.tsx +0 -143
- package/src/components/resource/__tests__/AnnotationHistory.test.tsx +0 -257
- package/src/components/resource/__tests__/BrowseView.code-point-offsets.test.tsx +0 -123
- package/src/components/resource/__tests__/BrowseView.embeddable.test.tsx +0 -76
- package/src/components/resource/__tests__/BrowseView.links.test.tsx +0 -84
- package/src/components/resource/__tests__/BrowseView.overlay-async.test.tsx +0 -165
- package/src/components/resource/__tests__/BrowseView.reference-hover.test.tsx +0 -200
- package/src/components/resource/__tests__/BrowseView.registry.test.tsx +0 -57
- package/src/components/resource/__tests__/BrowseView.test.tsx +0 -915
- package/src/components/resource/__tests__/HistoryEvent.test.tsx +0 -571
- package/src/components/resource/__tests__/ResourceViewer.delete-failure.test.tsx +0 -103
- package/src/components/resource/__tests__/ResourceViewer.embeddable.test.tsx +0 -250
- package/src/components/resource/__tests__/ResourceViewer.mode-switch.test.tsx +0 -262
- package/src/components/resource/__tests__/ResourceViewer.multi-mount-invalidation.test.tsx +0 -166
- package/src/components/resource/__tests__/ResourceViewer.registry.test.tsx +0 -112
- package/src/components/resource/__tests__/ResourceViewer.toolbar-opt-out.test.tsx +0 -207
- package/src/components/resource/__tests__/ResourceViewer.toolbar-prefs.test.tsx +0 -274
- package/src/components/resource/__tests__/annotation-interactions.test.tsx +0 -116
- package/src/components/resource/__tests__/browse-renderers.dispatch.test.tsx +0 -183
- package/src/components/resource/__tests__/browse-renderers.test.tsx +0 -47
- package/src/components/resource/__tests__/download-link.test.tsx +0 -171
- package/src/components/resource/__tests__/event-formatting.test.ts +0 -379
- package/src/components/resource/__tests__/inline-embedding.test.tsx +0 -133
- package/src/components/resource/__tests__/media-completeness.test.tsx +0 -144
- package/src/components/resource/annotate-renderers.tsx +0 -186
- package/src/components/resource/browse-renderers.tsx +0 -133
- package/src/components/resource/event-formatting.ts +0 -393
- package/src/components/resource/panels/AssessmentEntry.tsx +0 -127
- package/src/components/resource/panels/AssessmentPanel.tsx +0 -309
- package/src/components/resource/panels/CollaborationPanel.tsx +0 -228
- package/src/components/resource/panels/CommentEntry.tsx +0 -242
- package/src/components/resource/panels/CommentsPanel.tsx +0 -320
- package/src/components/resource/panels/DelegateSection.tsx +0 -282
- package/src/components/resource/panels/DelegateShell.tsx +0 -134
- package/src/components/resource/panels/HighlightEntry.tsx +0 -83
- package/src/components/resource/panels/HighlightPanel.tsx +0 -212
- package/src/components/resource/panels/JsonLdPanel.tsx +0 -119
- package/src/components/resource/panels/PanelHeader.tsx +0 -22
- package/src/components/resource/panels/ReferenceEntry.tsx +0 -232
- package/src/components/resource/panels/ReferencesPanel.tsx +0 -626
- package/src/components/resource/panels/ResourceInfoPanel.tsx +0 -433
- package/src/components/resource/panels/StatisticsPanel.tsx +0 -145
- package/src/components/resource/panels/TagEntry.tsx +0 -87
- package/src/components/resource/panels/TaggingPanel.tsx +0 -554
- package/src/components/resource/panels/UnifiedAnnotationsPanel.tsx +0 -384
- package/src/components/resource/panels/__tests__/AssessmentEntry.test.tsx +0 -292
- package/src/components/resource/panels/__tests__/AssessmentPanel.test.tsx +0 -685
- package/src/components/resource/panels/__tests__/CollaborationPanel.test.tsx +0 -685
- package/src/components/resource/panels/__tests__/CommentEntry.test.tsx +0 -750
- package/src/components/resource/panels/__tests__/CommentsPanel.test.tsx +0 -877
- package/src/components/resource/panels/__tests__/DelegateSection.test.tsx +0 -623
- package/src/components/resource/panels/__tests__/DelegateShell.test.tsx +0 -212
- package/src/components/resource/panels/__tests__/HighlightEntry.test.tsx +0 -236
- package/src/components/resource/panels/__tests__/HighlightPanel.annotationProgress.test.tsx +0 -506
- package/src/components/resource/panels/__tests__/HighlightPanel.out-of-order.test.tsx +0 -132
- package/src/components/resource/panels/__tests__/JsonLdPanel.test.tsx +0 -230
- package/src/components/resource/panels/__tests__/PanelHeader.test.tsx +0 -54
- package/src/components/resource/panels/__tests__/ReferenceEntry.test.tsx +0 -578
- package/src/components/resource/panels/__tests__/ReferencesPanel.headless.test.tsx +0 -193
- package/src/components/resource/panels/__tests__/ReferencesPanel.observable-flow.test.tsx +0 -193
- package/src/components/resource/panels/__tests__/ReferencesPanel.test.tsx +0 -1080
- package/src/components/resource/panels/__tests__/ResourceInfoPanel.test.tsx +0 -812
- package/src/components/resource/panels/__tests__/ResourceInfoPanel.text-layer.test.tsx +0 -106
- package/src/components/resource/panels/__tests__/StatisticsPanel.test.tsx +0 -329
- package/src/components/resource/panels/__tests__/TagEntry.test.tsx +0 -250
- package/src/components/resource/panels/__tests__/TaggingPanel.test.tsx +0 -772
- package/src/components/resource/panels/__tests__/UnifiedAnnotationsPanel.delegated-job.test.tsx +0 -207
- package/src/components/resource/panels/__tests__/UnifiedAnnotationsPanel.failure.test.tsx +0 -89
- package/src/components/resource/panels/__tests__/agent-label.test.ts +0 -136
- package/src/components/resource/panels/agent-label.ts +0 -35
- package/src/components/settings/SettingsPanel.tsx +0 -251
- package/src/components/settings/__tests__/SettingsPanel.test.tsx +0 -260
- package/src/components/viewers/ImageViewer.tsx +0 -18
- package/src/components/viewers/__tests__/ImageViewer.test.tsx +0 -57
- package/src/components/viewers/index.ts +0 -1
- package/src/features/auth/__tests__/AuthErrorDisplay.test.tsx +0 -181
- package/src/features/auth/components/AuthErrorDisplay.tsx +0 -89
- package/src/features/moderate-entity-tags/__tests__/EntityTagsPage.test.tsx +0 -387
- package/src/features/moderate-entity-tags/components/EntityTagsPage.tsx +0 -161
- package/src/features/moderate-entity-tags/state/__tests__/entity-tags-state-unit.test.ts +0 -183
- package/src/features/moderate-entity-tags/state/entity-tags-state-unit.ts +0 -73
- package/src/features/moderate-recent/__tests__/RecentDocumentsPage.test.tsx +0 -422
- package/src/features/moderate-recent/components/RecentDocumentsPage.tsx +0 -117
- package/src/features/moderate-tag-schemas/__tests__/TagSchemasPage.test.tsx +0 -481
- package/src/features/moderate-tag-schemas/components/TagSchemasPage.tsx +0 -161
- package/src/features/resource-compose/__tests__/ResourceComposePage.test.tsx +0 -600
- package/src/features/resource-compose/__tests__/UploadProgressBar.test.tsx +0 -256
- package/src/features/resource-compose/components/ResourceComposePage.tsx +0 -809
- package/src/features/resource-compose/components/UploadProgressBar.tsx +0 -125
- package/src/features/resource-compose/state/__tests__/compose-page-state-unit.test.ts +0 -195
- package/src/features/resource-compose/state/compose-page-state-unit.ts +0 -187
- package/src/features/resource-discovery/__tests__/ResourceCard.test.tsx +0 -338
- package/src/features/resource-discovery/__tests__/ResourceDiscoveryPage.test.tsx +0 -449
- package/src/features/resource-discovery/components/ResourceCard.tsx +0 -80
- package/src/features/resource-discovery/components/ResourceDiscoveryPage.tsx +0 -330
- package/src/features/resource-discovery/state/__tests__/discover-state-unit.test.ts +0 -477
- package/src/features/resource-discovery/state/discover-state-unit.ts +0 -162
- package/src/features/resource-viewer/__tests__/ResourceViewerPage.content-loading.test.tsx +0 -260
- package/src/features/resource-viewer/__tests__/ResourceViewerPage.test.tsx +0 -570
- package/src/features/resource-viewer/__tests__/generation-params.test.ts +0 -49
- package/src/features/resource-viewer/components/ResourceViewerPage.tsx +0 -1058
- package/src/features/resource-viewer/generation-params.ts +0 -23
- package/src/features/resource-viewer/hooks/__tests__/useResourceViewedReport.test.tsx +0 -77
- package/src/features/resource-viewer/hooks/useResourceViewedReport.ts +0 -38
- package/src/features/resource-viewer/state/__tests__/resource-loader-state-unit.test.ts +0 -178
- package/src/features/resource-viewer/state/__tests__/resource-viewer-page-state-unit.test.ts +0 -505
- package/src/features/resource-viewer/state/resource-loader-state-unit.ts +0 -93
- package/src/features/resource-viewer/state/resource-viewer-page-state-unit.ts +0 -156
|
@@ -1,242 +0,0 @@
|
|
|
1
|
-
'use client';
|
|
2
|
-
|
|
3
|
-
import {
|
|
4
|
-
useState,
|
|
5
|
-
useEffect,
|
|
6
|
-
useRef,
|
|
7
|
-
useImperativeHandle,
|
|
8
|
-
type Ref,
|
|
9
|
-
} from 'react';
|
|
10
|
-
import { useTranslations } from '../../../contexts/TranslationContext';
|
|
11
|
-
import type { Annotation, components } from '@xynolog/core';
|
|
12
|
-
import {
|
|
13
|
-
getAnnotationExactText,
|
|
14
|
-
getCommentText,
|
|
15
|
-
getTargetSource,
|
|
16
|
-
} from '@xynolog/core';
|
|
17
|
-
import type { XynologSession } from '@xynolog/sdk';
|
|
18
|
-
import { useHoverEmitter } from '../../../hooks/useHoverEmitter';
|
|
19
|
-
import { creatorName, renderAgentLabels } from './agent-label';
|
|
20
|
-
|
|
21
|
-
type TextualBody = components['schemas']['TextualBody'];
|
|
22
|
-
|
|
23
|
-
/** An edit in progress: the session it is saved through, and its text. */
|
|
24
|
-
interface Edit {
|
|
25
|
-
session: XynologSession;
|
|
26
|
-
text: string;
|
|
27
|
-
}
|
|
28
|
-
|
|
29
|
-
interface CommentEntryProps {
|
|
30
|
-
/** Session for interaction routing (browse.click etc.); the panel threads it. */
|
|
31
|
-
session: XynologSession | null;
|
|
32
|
-
comment: Annotation;
|
|
33
|
-
isFocused: boolean;
|
|
34
|
-
isHovered?: boolean;
|
|
35
|
-
annotateMode?: boolean;
|
|
36
|
-
ref?: Ref<HTMLDivElement>;
|
|
37
|
-
}
|
|
38
|
-
|
|
39
|
-
function formatRelativeTime(isoString: string): string {
|
|
40
|
-
const date = new Date(isoString);
|
|
41
|
-
const now = new Date();
|
|
42
|
-
const diffMs = now.getTime() - date.getTime();
|
|
43
|
-
const diffSecs = Math.floor(diffMs / 1000);
|
|
44
|
-
const diffMins = Math.floor(diffSecs / 60);
|
|
45
|
-
const diffHours = Math.floor(diffMins / 60);
|
|
46
|
-
const diffDays = Math.floor(diffHours / 24);
|
|
47
|
-
|
|
48
|
-
if (diffSecs < 60) return 'just now';
|
|
49
|
-
if (diffMins < 60) return `${diffMins} minute${diffMins > 1 ? 's' : ''} ago`;
|
|
50
|
-
if (diffHours < 24) return `${diffHours} hour${diffHours > 1 ? 's' : ''} ago`;
|
|
51
|
-
if (diffDays < 7) return `${diffDays} day${diffDays > 1 ? 's' : ''} ago`;
|
|
52
|
-
|
|
53
|
-
return date.toLocaleDateString();
|
|
54
|
-
}
|
|
55
|
-
|
|
56
|
-
/**
|
|
57
|
-
* @emits browse:click - This entry clicked. Payload: { annotationId: string }
|
|
58
|
-
* @emits bind:update-body - Save an edit: replace the comment body item with one holding the edited text. Payload: BindUpdateBodyCommand
|
|
59
|
-
*/
|
|
60
|
-
export function CommentEntry({
|
|
61
|
-
session,
|
|
62
|
-
comment,
|
|
63
|
-
isFocused,
|
|
64
|
-
isHovered = false,
|
|
65
|
-
annotateMode = true,
|
|
66
|
-
ref,
|
|
67
|
-
}: CommentEntryProps) {
|
|
68
|
-
const t = useTranslations('CommentsPanel');
|
|
69
|
-
const hoverProps = useHoverEmitter(session, comment.id);
|
|
70
|
-
const [edit, setEdit] = useState<Edit | null>(null);
|
|
71
|
-
const [saving, setSaving] = useState(false);
|
|
72
|
-
const [saveError, setSaveError] = useState<string | null>(null);
|
|
73
|
-
const internalRef = useRef<HTMLDivElement>(null);
|
|
74
|
-
|
|
75
|
-
// Combine external ref with internal ref
|
|
76
|
-
useImperativeHandle(ref, () => internalRef.current!);
|
|
77
|
-
|
|
78
|
-
const commentText = getCommentText(comment) || '';
|
|
79
|
-
const selectedText = getAnnotationExactText(comment);
|
|
80
|
-
// The body item that holds the words shown, exactly as the annotation holds
|
|
81
|
-
// it: an edit replaces this item, and a replace whose old item differs from
|
|
82
|
-
// the held one in any member changes nothing.
|
|
83
|
-
const bodyItems =
|
|
84
|
-
comment.body === undefined
|
|
85
|
-
? []
|
|
86
|
-
: Array.isArray(comment.body)
|
|
87
|
-
? comment.body
|
|
88
|
-
: [comment.body];
|
|
89
|
-
const commentBody = bodyItems.find(
|
|
90
|
-
(item): item is TextualBody =>
|
|
91
|
-
item.type === 'TextualBody' && item.value === commentText,
|
|
92
|
-
);
|
|
93
|
-
|
|
94
|
-
// Scroll into view when focused
|
|
95
|
-
useEffect(() => {
|
|
96
|
-
if (isFocused && internalRef.current) {
|
|
97
|
-
internalRef.current.scrollIntoView({
|
|
98
|
-
behavior: 'smooth',
|
|
99
|
-
block: 'center',
|
|
100
|
-
});
|
|
101
|
-
}
|
|
102
|
-
}, [isFocused]);
|
|
103
|
-
|
|
104
|
-
const handleEditClick = (editSession: XynologSession) => {
|
|
105
|
-
setSaveError(null);
|
|
106
|
-
setEdit({ session: editSession, text: commentText });
|
|
107
|
-
};
|
|
108
|
-
|
|
109
|
-
const handleSave = (saved: Edit, heldBody: TextualBody) => {
|
|
110
|
-
if (saved.text === heldBody.value) {
|
|
111
|
-
setEdit(null);
|
|
112
|
-
return;
|
|
113
|
-
}
|
|
114
|
-
setSaving(true);
|
|
115
|
-
setSaveError(null);
|
|
116
|
-
saved.session.client.bind
|
|
117
|
-
.body(getTargetSource(comment.target), comment.id, [
|
|
118
|
-
{
|
|
119
|
-
op: 'replace',
|
|
120
|
-
oldItem: heldBody,
|
|
121
|
-
newItem: { ...heldBody, value: saved.text },
|
|
122
|
-
},
|
|
123
|
-
])
|
|
124
|
-
.then(
|
|
125
|
-
() => {
|
|
126
|
-
setSaving(false);
|
|
127
|
-
setEdit(null);
|
|
128
|
-
},
|
|
129
|
-
(error: unknown) => {
|
|
130
|
-
// The editor stays open with the edit, and says why it was not saved.
|
|
131
|
-
setSaving(false);
|
|
132
|
-
setSaveError(
|
|
133
|
-
t('saveFailed', {
|
|
134
|
-
detail: error instanceof Error ? error.message : String(error),
|
|
135
|
-
}),
|
|
136
|
-
);
|
|
137
|
-
},
|
|
138
|
-
);
|
|
139
|
-
};
|
|
140
|
-
|
|
141
|
-
const handleCancel = () => {
|
|
142
|
-
setEdit(null);
|
|
143
|
-
setSaveError(null);
|
|
144
|
-
};
|
|
145
|
-
|
|
146
|
-
return (
|
|
147
|
-
<div
|
|
148
|
-
ref={internalRef}
|
|
149
|
-
className={`xynolog-annotation-entry${isHovered ? ' xynolog-annotation-pulse' : ''}`}
|
|
150
|
-
data-type="comment"
|
|
151
|
-
data-focused={isFocused ? 'true' : 'false'}
|
|
152
|
-
onClick={() => {
|
|
153
|
-
session?.client.browse.click(comment.id);
|
|
154
|
-
}}
|
|
155
|
-
{...hoverProps}
|
|
156
|
-
>
|
|
157
|
-
{/* Selected text quote - only for text annotations */}
|
|
158
|
-
{selectedText && (
|
|
159
|
-
<div className="xynolog-annotation-entry__quote" data-type="comment">
|
|
160
|
-
"{selectedText.substring(0, 100)}
|
|
161
|
-
{selectedText.length > 100 ? '...' : ''}"
|
|
162
|
-
</div>
|
|
163
|
-
)}
|
|
164
|
-
|
|
165
|
-
{/* Comment body */}
|
|
166
|
-
{edit && commentBody ? (
|
|
167
|
-
<div
|
|
168
|
-
className="xynolog-annotation-entry__edit"
|
|
169
|
-
onClick={(e) => e.stopPropagation()}
|
|
170
|
-
>
|
|
171
|
-
<textarea
|
|
172
|
-
value={edit.text}
|
|
173
|
-
onChange={(e) => setEdit({ ...edit, text: e.target.value })}
|
|
174
|
-
className="xynolog-textarea"
|
|
175
|
-
rows={3}
|
|
176
|
-
autoFocus
|
|
177
|
-
maxLength={2000}
|
|
178
|
-
/>
|
|
179
|
-
{saveError && (
|
|
180
|
-
<p className="xynolog-error-message" role="alert">
|
|
181
|
-
{saveError}
|
|
182
|
-
</p>
|
|
183
|
-
)}
|
|
184
|
-
<div className="xynolog-annotation-entry__edit-footer">
|
|
185
|
-
<span className="xynolog-annotation-entry__char-count">
|
|
186
|
-
{edit.text.length}/2000
|
|
187
|
-
</span>
|
|
188
|
-
<div className="xynolog-annotation-entry__button-group">
|
|
189
|
-
<button
|
|
190
|
-
onClick={() => handleSave(edit, commentBody)}
|
|
191
|
-
disabled={saving}
|
|
192
|
-
className="xynolog-button xynolog-button--primary"
|
|
193
|
-
data-type="comment"
|
|
194
|
-
>
|
|
195
|
-
{t('save')}
|
|
196
|
-
</button>
|
|
197
|
-
<button
|
|
198
|
-
onClick={handleCancel}
|
|
199
|
-
className="xynolog-button xynolog-button--secondary"
|
|
200
|
-
>
|
|
201
|
-
{t('cancel')}
|
|
202
|
-
</button>
|
|
203
|
-
</div>
|
|
204
|
-
</div>
|
|
205
|
-
</div>
|
|
206
|
-
) : (
|
|
207
|
-
<div className="xynolog-annotation-entry__body">{commentText}</div>
|
|
208
|
-
)}
|
|
209
|
-
|
|
210
|
-
{/* Metadata and actions */}
|
|
211
|
-
{!(edit && commentBody) && (
|
|
212
|
-
<div className="xynolog-annotation-entry__footer">
|
|
213
|
-
<div className="xynolog-annotation-entry__metadata">
|
|
214
|
-
{creatorName(comment.creator) && (
|
|
215
|
-
<>By {creatorName(comment.creator)} • </>
|
|
216
|
-
)}
|
|
217
|
-
{formatRelativeTime(comment.created || new Date().toISOString())}
|
|
218
|
-
</div>
|
|
219
|
-
{comment.generator && renderAgentLabels(comment.generator) && (
|
|
220
|
-
<div className="xynolog-annotation-entry__metadata">
|
|
221
|
-
Via {renderAgentLabels(comment.generator)}
|
|
222
|
-
</div>
|
|
223
|
-
)}
|
|
224
|
-
{annotateMode && session && commentBody && (
|
|
225
|
-
<div
|
|
226
|
-
className="xynolog-annotation-entry__actions"
|
|
227
|
-
onClick={(e) => e.stopPropagation()}
|
|
228
|
-
>
|
|
229
|
-
<button
|
|
230
|
-
onClick={() => handleEditClick(session)}
|
|
231
|
-
className="xynolog-text-button"
|
|
232
|
-
data-variant="comment"
|
|
233
|
-
>
|
|
234
|
-
{t('edit')}
|
|
235
|
-
</button>
|
|
236
|
-
</div>
|
|
237
|
-
)}
|
|
238
|
-
</div>
|
|
239
|
-
)}
|
|
240
|
-
</div>
|
|
241
|
-
);
|
|
242
|
-
}
|
|
@@ -1,320 +0,0 @@
|
|
|
1
|
-
'use client';
|
|
2
|
-
|
|
3
|
-
import { useState, useEffect, useRef, useCallback, useMemo } from 'react';
|
|
4
|
-
import { useTranslations } from '../../../contexts/TranslationContext';
|
|
5
|
-
import type {
|
|
6
|
-
MarkStateUnit,
|
|
7
|
-
PendingAnnotation,
|
|
8
|
-
XynologSession,
|
|
9
|
-
} from '@xynolog/sdk';
|
|
10
|
-
import { useSessionEventSubscriptions } from '../../../hooks/useSessionEventSubscriptions';
|
|
11
|
-
import type { components, JobId, ResourceId, Selector } from '@xynolog/core';
|
|
12
|
-
import { getTextPositionSelector, getTargetSelector } from '@xynolog/core';
|
|
13
|
-
import { CommentEntry } from './CommentEntry';
|
|
14
|
-
import { DelegateSection } from './DelegateSection';
|
|
15
|
-
import { PanelHeader } from './PanelHeader';
|
|
16
|
-
|
|
17
|
-
import type { Annotation } from '@xynolog/core';
|
|
18
|
-
type JobProgress = components['schemas']['JobProgress'];
|
|
19
|
-
|
|
20
|
-
// Unified pending annotation type
|
|
21
|
-
// Helper to extract display text from selector
|
|
22
|
-
function getSelectorDisplayText(
|
|
23
|
-
selector: Selector | Selector[],
|
|
24
|
-
): string | null {
|
|
25
|
-
if (Array.isArray(selector)) {
|
|
26
|
-
// Text selectors: array of [TextPositionSelector, TextQuoteSelector]
|
|
27
|
-
const quoteSelector = selector.find((s) => s.type === 'TextQuoteSelector');
|
|
28
|
-
if (quoteSelector && 'exact' in quoteSelector) {
|
|
29
|
-
return quoteSelector.exact;
|
|
30
|
-
}
|
|
31
|
-
} else {
|
|
32
|
-
// Single selector
|
|
33
|
-
if (selector.type === 'TextQuoteSelector' && 'exact' in selector) {
|
|
34
|
-
return selector.exact;
|
|
35
|
-
}
|
|
36
|
-
}
|
|
37
|
-
return null;
|
|
38
|
-
}
|
|
39
|
-
|
|
40
|
-
interface CommentsPanelProps {
|
|
41
|
-
/** Session carrying the client and event bus; null renders inert. */
|
|
42
|
-
session: XynologSession | null;
|
|
43
|
-
/** The resource's mark unit, which delegations, cancels and dismissals are asked of; undefined renders inert. */
|
|
44
|
-
mark: MarkStateUnit | undefined;
|
|
45
|
-
/** The '@id' of the panel's resource — stamped as `source` on mark:submit (multi-viewer routing). */
|
|
46
|
-
resourceId: ResourceId;
|
|
47
|
-
annotations: Annotation[];
|
|
48
|
-
pendingAnnotation: PendingAnnotation | null;
|
|
49
|
-
annotateMode?: boolean;
|
|
50
|
-
isDelegating?: boolean;
|
|
51
|
-
progress?: JobProgress | null;
|
|
52
|
-
/**
|
|
53
|
-
* The id of the delegated job (`mark.jobId$`): what the cancel control
|
|
54
|
-
* names. Null until the queue has answered the job's creation and once the
|
|
55
|
-
* job is over, and then there is no control.
|
|
56
|
-
*/
|
|
57
|
-
jobId: JobId | null;
|
|
58
|
-
/**
|
|
59
|
-
* The delegated job ended cancelled (`mark.failure$` holds a
|
|
60
|
-
* `JobCancelledError`): its display stays, in its cancelled form.
|
|
61
|
-
*/
|
|
62
|
-
cancelled: boolean;
|
|
63
|
-
locale?: string;
|
|
64
|
-
/** BCP-47 tag of the resource being analyzed — forwarded to the delegated job. */
|
|
65
|
-
sourceLanguage?: string;
|
|
66
|
-
scrollToAnnotationId?: string | null;
|
|
67
|
-
onScrollCompleted?: () => void;
|
|
68
|
-
hoveredAnnotationId?: string | null;
|
|
69
|
-
}
|
|
70
|
-
|
|
71
|
-
/**
|
|
72
|
-
* Panel for managing comment annotations with text input
|
|
73
|
-
*
|
|
74
|
-
* @emits mark:submit - Create new comment annotation. Payload: MarkSubmitEvent with motivation 'commenting' and the comment as a TextualBody
|
|
75
|
-
* @subscribes browse:click - Annotation clicked. Payload: { annotationId: string }
|
|
76
|
-
*/
|
|
77
|
-
export function CommentsPanel({
|
|
78
|
-
session,
|
|
79
|
-
mark,
|
|
80
|
-
resourceId,
|
|
81
|
-
annotations,
|
|
82
|
-
pendingAnnotation,
|
|
83
|
-
annotateMode = true,
|
|
84
|
-
isDelegating = false,
|
|
85
|
-
progress,
|
|
86
|
-
jobId,
|
|
87
|
-
cancelled,
|
|
88
|
-
locale,
|
|
89
|
-
sourceLanguage,
|
|
90
|
-
scrollToAnnotationId,
|
|
91
|
-
onScrollCompleted,
|
|
92
|
-
hoveredAnnotationId,
|
|
93
|
-
}: CommentsPanelProps) {
|
|
94
|
-
const t = useTranslations('CommentsPanel');
|
|
95
|
-
const [newCommentText, setNewCommentText] = useState('');
|
|
96
|
-
const [focusedAnnotationId, setFocusedAnnotationId] = useState<string | null>(
|
|
97
|
-
null,
|
|
98
|
-
);
|
|
99
|
-
const containerRef = useRef<HTMLDivElement>(null);
|
|
100
|
-
|
|
101
|
-
// Direct ref management
|
|
102
|
-
const entryRefs = useRef<Map<string, HTMLDivElement>>(new Map());
|
|
103
|
-
|
|
104
|
-
// Sort annotations by their position in the resource
|
|
105
|
-
const sortedAnnotations = useMemo(() => {
|
|
106
|
-
return [...annotations].sort((a, b) => {
|
|
107
|
-
const aSelector = getTextPositionSelector(getTargetSelector(a.target));
|
|
108
|
-
const bSelector = getTextPositionSelector(getTargetSelector(b.target));
|
|
109
|
-
if (!aSelector || !bSelector) return 0;
|
|
110
|
-
return aSelector.start - bSelector.start;
|
|
111
|
-
});
|
|
112
|
-
}, [annotations]);
|
|
113
|
-
|
|
114
|
-
// Ref callback for entry components
|
|
115
|
-
const setEntryRef = useCallback(
|
|
116
|
-
(id: string, element: HTMLDivElement | null) => {
|
|
117
|
-
if (element) {
|
|
118
|
-
entryRefs.current.set(id, element);
|
|
119
|
-
} else {
|
|
120
|
-
entryRefs.current.delete(id);
|
|
121
|
-
}
|
|
122
|
-
},
|
|
123
|
-
[],
|
|
124
|
-
);
|
|
125
|
-
|
|
126
|
-
// Handle scrollToAnnotationId (click scroll)
|
|
127
|
-
useEffect(() => {
|
|
128
|
-
if (!scrollToAnnotationId) return;
|
|
129
|
-
|
|
130
|
-
const element = entryRefs.current.get(scrollToAnnotationId);
|
|
131
|
-
|
|
132
|
-
if (element && containerRef.current) {
|
|
133
|
-
// Calculate scroll position to center element in container
|
|
134
|
-
const elementTop = element.offsetTop;
|
|
135
|
-
const containerHeight = containerRef.current.clientHeight;
|
|
136
|
-
const elementHeight = element.offsetHeight;
|
|
137
|
-
const scrollTo = elementTop - containerHeight / 2 + elementHeight / 2;
|
|
138
|
-
|
|
139
|
-
// Scroll to center
|
|
140
|
-
containerRef.current.scrollTo({ top: scrollTo, behavior: 'smooth' });
|
|
141
|
-
|
|
142
|
-
// Add pulse effect
|
|
143
|
-
element.classList.remove('xynolog-annotation-pulse');
|
|
144
|
-
void element.offsetWidth; // Force reflow
|
|
145
|
-
element.classList.add('xynolog-annotation-pulse');
|
|
146
|
-
|
|
147
|
-
// Notify completion
|
|
148
|
-
if (onScrollCompleted) {
|
|
149
|
-
onScrollCompleted();
|
|
150
|
-
}
|
|
151
|
-
}
|
|
152
|
-
}, [scrollToAnnotationId]);
|
|
153
|
-
|
|
154
|
-
// Handle hoveredAnnotationId (hover scroll only - pulse is handled by isHovered prop)
|
|
155
|
-
useEffect(() => {
|
|
156
|
-
if (!hoveredAnnotationId) return;
|
|
157
|
-
|
|
158
|
-
const element = entryRefs.current.get(hoveredAnnotationId);
|
|
159
|
-
|
|
160
|
-
if (!element || !containerRef.current) return;
|
|
161
|
-
|
|
162
|
-
const container = containerRef.current;
|
|
163
|
-
const elementRect = element.getBoundingClientRect();
|
|
164
|
-
const containerRect = container.getBoundingClientRect();
|
|
165
|
-
|
|
166
|
-
// Only scroll if element is not fully visible
|
|
167
|
-
const isVisible =
|
|
168
|
-
elementRect.top >= containerRect.top &&
|
|
169
|
-
elementRect.bottom <= containerRect.bottom;
|
|
170
|
-
|
|
171
|
-
if (!isVisible) {
|
|
172
|
-
const elementTop = element.offsetTop;
|
|
173
|
-
const containerHeight = container.clientHeight;
|
|
174
|
-
const elementHeight = element.offsetHeight;
|
|
175
|
-
const scrollTo = elementTop - containerHeight / 2 + elementHeight / 2;
|
|
176
|
-
|
|
177
|
-
container.scrollTo({ top: scrollTo, behavior: 'smooth' });
|
|
178
|
-
}
|
|
179
|
-
|
|
180
|
-
// Pulse effect is handled by isHovered prop on CommentEntry
|
|
181
|
-
}, [hoveredAnnotationId]);
|
|
182
|
-
|
|
183
|
-
// Subscribe to click events - update focused state
|
|
184
|
-
// Event handler for annotation clicks (a named callback rather than an inline arrow function)
|
|
185
|
-
const handleAnnotationClick = useCallback(
|
|
186
|
-
({ annotationId }: { annotationId: string }) => {
|
|
187
|
-
setFocusedAnnotationId(annotationId);
|
|
188
|
-
setTimeout(() => setFocusedAnnotationId(null), 3000);
|
|
189
|
-
},
|
|
190
|
-
[],
|
|
191
|
-
);
|
|
192
|
-
|
|
193
|
-
useSessionEventSubscriptions(session, {
|
|
194
|
-
'browse:click': handleAnnotationClick,
|
|
195
|
-
});
|
|
196
|
-
|
|
197
|
-
const handleSaveNewComment = () => {
|
|
198
|
-
if (newCommentText.trim() && pendingAnnotation) {
|
|
199
|
-
session?.client.mark.submit({
|
|
200
|
-
source: resourceId,
|
|
201
|
-
motivation: 'commenting',
|
|
202
|
-
selector: pendingAnnotation.selector,
|
|
203
|
-
body: [
|
|
204
|
-
{ type: 'TextualBody', value: newCommentText, purpose: 'commenting' },
|
|
205
|
-
],
|
|
206
|
-
});
|
|
207
|
-
setNewCommentText('');
|
|
208
|
-
}
|
|
209
|
-
};
|
|
210
|
-
|
|
211
|
-
// Escape key handler for cancelling pending annotation
|
|
212
|
-
useEffect(() => {
|
|
213
|
-
if (!pendingAnnotation) return;
|
|
214
|
-
|
|
215
|
-
const handleEscape = (e: KeyboardEvent) => {
|
|
216
|
-
if (e.key === 'Escape') {
|
|
217
|
-
mark?.cancelPending();
|
|
218
|
-
setNewCommentText('');
|
|
219
|
-
}
|
|
220
|
-
};
|
|
221
|
-
|
|
222
|
-
document.addEventListener('keydown', handleEscape);
|
|
223
|
-
return () => document.removeEventListener('keydown', handleEscape);
|
|
224
|
-
}, [pendingAnnotation, mark]);
|
|
225
|
-
|
|
226
|
-
return (
|
|
227
|
-
<div className="xynolog-panel">
|
|
228
|
-
<PanelHeader count={annotations.length} title={t('title')} />
|
|
229
|
-
|
|
230
|
-
{/* New comment input - shown when there's a pending annotation with commenting motivation */}
|
|
231
|
-
{pendingAnnotation && pendingAnnotation.motivation === 'commenting' && (
|
|
232
|
-
<div className="xynolog-annotation-prompt" data-type="comment">
|
|
233
|
-
<div className="xynolog-annotation-prompt__quote">
|
|
234
|
-
{(() => {
|
|
235
|
-
const displayText = getSelectorDisplayText(
|
|
236
|
-
pendingAnnotation.selector,
|
|
237
|
-
);
|
|
238
|
-
if (displayText) {
|
|
239
|
-
return `"${displayText.substring(0, 100)}${displayText.length > 100 ? '...' : ''}"`;
|
|
240
|
-
}
|
|
241
|
-
// Generic labels for PDF/image annotations without text
|
|
242
|
-
return t('fragmentSelected');
|
|
243
|
-
})()}
|
|
244
|
-
</div>
|
|
245
|
-
<textarea
|
|
246
|
-
value={newCommentText}
|
|
247
|
-
onChange={(e) => setNewCommentText(e.target.value)}
|
|
248
|
-
className="xynolog-textarea"
|
|
249
|
-
rows={3}
|
|
250
|
-
placeholder={t('commentPlaceholder')}
|
|
251
|
-
autoFocus
|
|
252
|
-
maxLength={2000}
|
|
253
|
-
/>
|
|
254
|
-
<div className="xynolog-annotation-prompt__footer">
|
|
255
|
-
<span className="xynolog-annotation-prompt__char-count">
|
|
256
|
-
{newCommentText.length}/2000
|
|
257
|
-
</span>
|
|
258
|
-
<div className="xynolog-annotation-prompt__actions">
|
|
259
|
-
<button
|
|
260
|
-
onClick={() => {
|
|
261
|
-
mark?.cancelPending();
|
|
262
|
-
setNewCommentText('');
|
|
263
|
-
}}
|
|
264
|
-
className="xynolog-button xynolog-button--secondary"
|
|
265
|
-
data-type="comment"
|
|
266
|
-
>
|
|
267
|
-
{t('cancel')}
|
|
268
|
-
</button>
|
|
269
|
-
<button
|
|
270
|
-
onClick={handleSaveNewComment}
|
|
271
|
-
disabled={!newCommentText.trim()}
|
|
272
|
-
className="xynolog-button xynolog-button--primary"
|
|
273
|
-
data-type="comment"
|
|
274
|
-
>
|
|
275
|
-
{t('save')}
|
|
276
|
-
</button>
|
|
277
|
-
</div>
|
|
278
|
-
</div>
|
|
279
|
-
</div>
|
|
280
|
-
)}
|
|
281
|
-
|
|
282
|
-
{/* Scrollable content area */}
|
|
283
|
-
<div ref={containerRef} className="xynolog-panel__content">
|
|
284
|
-
{/* Delegate section - only in Annotate mode; shown for any media type (AI detection is media-agnostic — text is resolved via the media-type registry, incl. PDF text layers) */}
|
|
285
|
-
{annotateMode && (
|
|
286
|
-
<DelegateSection
|
|
287
|
-
session={session}
|
|
288
|
-
mark={mark}
|
|
289
|
-
annotationType="comment"
|
|
290
|
-
isDelegating={isDelegating}
|
|
291
|
-
locale={locale}
|
|
292
|
-
sourceLanguage={sourceLanguage}
|
|
293
|
-
progress={progress}
|
|
294
|
-
jobId={jobId}
|
|
295
|
-
cancelled={cancelled}
|
|
296
|
-
/>
|
|
297
|
-
)}
|
|
298
|
-
|
|
299
|
-
{/* Comments list */}
|
|
300
|
-
<div className="xynolog-panel__list">
|
|
301
|
-
{sortedAnnotations.length === 0 ? (
|
|
302
|
-
<p className="xynolog-panel__empty">{t('noComments')}</p>
|
|
303
|
-
) : (
|
|
304
|
-
sortedAnnotations.map((comment) => (
|
|
305
|
-
<CommentEntry
|
|
306
|
-
session={session}
|
|
307
|
-
key={comment.id}
|
|
308
|
-
comment={comment}
|
|
309
|
-
isFocused={comment.id === focusedAnnotationId}
|
|
310
|
-
isHovered={comment.id === hoveredAnnotationId}
|
|
311
|
-
annotateMode={annotateMode}
|
|
312
|
-
ref={(el) => setEntryRef(comment.id, el)}
|
|
313
|
-
/>
|
|
314
|
-
))
|
|
315
|
-
)}
|
|
316
|
-
</div>
|
|
317
|
-
</div>
|
|
318
|
-
</div>
|
|
319
|
-
);
|
|
320
|
-
}
|