@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,304 +0,0 @@
|
|
|
1
|
-
/**
|
|
2
|
-
* AnnotateToolbar — purely presentational: its preferences are controlled props.
|
|
3
|
-
*
|
|
4
|
-
* The bar renders the given values for the given `parts` and reports choices via
|
|
5
|
-
* the on*Change callbacks. No session, no bus events, no storage — those died with
|
|
6
|
-
* the preference channels; owners (viewer instances / hosts) apply the values.
|
|
7
|
-
*/
|
|
8
|
-
import React from 'react';
|
|
9
|
-
import {
|
|
10
|
-
render,
|
|
11
|
-
screen,
|
|
12
|
-
fireEvent,
|
|
13
|
-
waitFor,
|
|
14
|
-
within,
|
|
15
|
-
} from '@testing-library/react';
|
|
16
|
-
import { vi, beforeEach, describe, it, expect } from 'vitest';
|
|
17
|
-
import '@testing-library/jest-dom';
|
|
18
|
-
import { AnnotateToolbar, type ClickAction } from '../AnnotateToolbar';
|
|
19
|
-
import type { Motivation } from '@xynolog/core';
|
|
20
|
-
import { ANNOTATORS } from '../../../lib/annotation-registry';
|
|
21
|
-
import { TranslationProvider } from '../../../contexts/TranslationContext';
|
|
22
|
-
import type { TranslationManager } from '../../../types/TranslationManager';
|
|
23
|
-
|
|
24
|
-
const messages: Record<string, Record<string, string>> = {
|
|
25
|
-
AnnotateToolbar: {
|
|
26
|
-
modeGroup: 'Mode',
|
|
27
|
-
browse: 'Browse',
|
|
28
|
-
annotate: 'Annotate',
|
|
29
|
-
clickGroup: 'Click',
|
|
30
|
-
selectionGroup: 'Motivation',
|
|
31
|
-
shapeGroup: 'Shape',
|
|
32
|
-
none: 'None',
|
|
33
|
-
linking: 'Reference',
|
|
34
|
-
highlighting: 'Highlight',
|
|
35
|
-
assessing: 'Assess',
|
|
36
|
-
commenting: 'Comment',
|
|
37
|
-
tagging: 'Tag',
|
|
38
|
-
detail: 'Detail',
|
|
39
|
-
follow: 'Follow',
|
|
40
|
-
deleting: 'Delete',
|
|
41
|
-
jsonld: 'JSON-LD',
|
|
42
|
-
rectangle: 'Rectangle',
|
|
43
|
-
circle: 'Circle',
|
|
44
|
-
polygon: 'Polygon',
|
|
45
|
-
},
|
|
46
|
-
};
|
|
47
|
-
|
|
48
|
-
const translationManager: TranslationManager = {
|
|
49
|
-
t: (namespace, key) => messages[namespace]?.[key] ?? `${namespace}.${key}`,
|
|
50
|
-
};
|
|
51
|
-
|
|
52
|
-
const renderWithIntl = (component: React.ReactElement) =>
|
|
53
|
-
render(
|
|
54
|
-
<TranslationProvider translationManager={translationManager}>
|
|
55
|
-
{component}
|
|
56
|
-
</TranslationProvider>,
|
|
57
|
-
);
|
|
58
|
-
|
|
59
|
-
/** Hover a dropdown group open and click an option in its menu. */
|
|
60
|
-
async function pick(group: string, option: string) {
|
|
61
|
-
const trigger = screen.getByLabelText(group);
|
|
62
|
-
fireEvent.mouseEnter(trigger.parentElement!);
|
|
63
|
-
await waitFor(() => {
|
|
64
|
-
const menu = screen.getByRole('menu');
|
|
65
|
-
fireEvent.click(within(menu).getByText(option));
|
|
66
|
-
});
|
|
67
|
-
}
|
|
68
|
-
|
|
69
|
-
describe('AnnotateToolbar', () => {
|
|
70
|
-
const defaultProps = {
|
|
71
|
-
selectedMotivation: null as Motivation | null,
|
|
72
|
-
selectedClick: 'detail' as ClickAction,
|
|
73
|
-
annotateMode: false,
|
|
74
|
-
annotators: ANNOTATORS,
|
|
75
|
-
};
|
|
76
|
-
|
|
77
|
-
beforeEach(() => {
|
|
78
|
-
vi.clearAllMocks();
|
|
79
|
-
});
|
|
80
|
-
|
|
81
|
-
describe('Rendering', () => {
|
|
82
|
-
it('renders the click group with the selected action', () => {
|
|
83
|
-
renderWithIntl(<AnnotateToolbar {...defaultProps} />);
|
|
84
|
-
expect(screen.getByLabelText('Click')).toBeInTheDocument();
|
|
85
|
-
expect(screen.getByText('Detail')).toBeInTheDocument();
|
|
86
|
-
});
|
|
87
|
-
|
|
88
|
-
it('shows the MODE group with the current mode', () => {
|
|
89
|
-
renderWithIntl(<AnnotateToolbar {...defaultProps} />);
|
|
90
|
-
expect(screen.getByLabelText('Mode')).toBeInTheDocument();
|
|
91
|
-
expect(screen.getByText('Browse')).toBeInTheDocument();
|
|
92
|
-
});
|
|
93
|
-
|
|
94
|
-
it('shows the selection group by default (parts default: all)', () => {
|
|
95
|
-
renderWithIntl(<AnnotateToolbar {...defaultProps} />);
|
|
96
|
-
expect(screen.getByLabelText('Motivation')).toBeInTheDocument();
|
|
97
|
-
});
|
|
98
|
-
|
|
99
|
-
it('hides the delete option when showDeleteButton is false', () => {
|
|
100
|
-
renderWithIntl(
|
|
101
|
-
<AnnotateToolbar {...defaultProps} showDeleteButton={false} />,
|
|
102
|
-
);
|
|
103
|
-
const clickGroup = screen.getByLabelText('Click');
|
|
104
|
-
fireEvent.mouseEnter(clickGroup.parentElement!);
|
|
105
|
-
expect(screen.queryByText('Delete')).not.toBeInTheDocument();
|
|
106
|
-
});
|
|
107
|
-
|
|
108
|
-
it('displays the given mode across rerenders (value comes from the owner)', () => {
|
|
109
|
-
const { rerender } = renderWithIntl(
|
|
110
|
-
<AnnotateToolbar {...defaultProps} annotateMode={false} />,
|
|
111
|
-
);
|
|
112
|
-
expect(screen.getByText('Browse')).toBeInTheDocument();
|
|
113
|
-
rerender(
|
|
114
|
-
<TranslationProvider translationManager={translationManager}>
|
|
115
|
-
<AnnotateToolbar {...defaultProps} annotateMode={true} />
|
|
116
|
-
</TranslationProvider>,
|
|
117
|
-
);
|
|
118
|
-
expect(screen.getByText('Annotate')).toBeInTheDocument();
|
|
119
|
-
});
|
|
120
|
-
});
|
|
121
|
-
|
|
122
|
-
describe('parts composition', () => {
|
|
123
|
-
it("parts={['shape']} renders exactly the shape group", () => {
|
|
124
|
-
const { container } = renderWithIntl(
|
|
125
|
-
<AnnotateToolbar
|
|
126
|
-
{...defaultProps}
|
|
127
|
-
parts={['shape']}
|
|
128
|
-
selectedShape="rectangle"
|
|
129
|
-
mediaType="image/png"
|
|
130
|
-
/>,
|
|
131
|
-
);
|
|
132
|
-
expect(screen.getByLabelText('Shape')).toBeInTheDocument();
|
|
133
|
-
expect(screen.queryByLabelText('Click')).not.toBeInTheDocument();
|
|
134
|
-
expect(screen.queryByLabelText('Mode')).not.toBeInTheDocument();
|
|
135
|
-
expect(screen.queryByLabelText('Motivation')).not.toBeInTheDocument();
|
|
136
|
-
// A lone part renders no separators
|
|
137
|
-
expect(container.querySelector('.xynolog-toolbar-separator')).toBeNull();
|
|
138
|
-
});
|
|
139
|
-
|
|
140
|
-
it("parts={['clickAction','mode']} renders those two with one separator", () => {
|
|
141
|
-
const { container } = renderWithIntl(
|
|
142
|
-
<AnnotateToolbar {...defaultProps} parts={['clickAction', 'mode']} />,
|
|
143
|
-
);
|
|
144
|
-
expect(screen.getByLabelText('Click')).toBeInTheDocument();
|
|
145
|
-
expect(screen.getByLabelText('Mode')).toBeInTheDocument();
|
|
146
|
-
expect(screen.queryByLabelText('Motivation')).not.toBeInTheDocument();
|
|
147
|
-
expect(
|
|
148
|
-
container.querySelectorAll('.xynolog-toolbar-separator'),
|
|
149
|
-
).toHaveLength(1);
|
|
150
|
-
});
|
|
151
|
-
|
|
152
|
-
it('the default renders all four groups (shape media-gated: none for PDF beyond rectangle)', () => {
|
|
153
|
-
renderWithIntl(
|
|
154
|
-
<AnnotateToolbar
|
|
155
|
-
{...defaultProps}
|
|
156
|
-
selectedShape="rectangle"
|
|
157
|
-
mediaType="image/png"
|
|
158
|
-
/>,
|
|
159
|
-
);
|
|
160
|
-
expect(screen.getByLabelText('Click')).toBeInTheDocument();
|
|
161
|
-
expect(screen.getByLabelText('Mode')).toBeInTheDocument();
|
|
162
|
-
expect(screen.getByLabelText('Motivation')).toBeInTheDocument();
|
|
163
|
-
expect(screen.getByLabelText('Shape')).toBeInTheDocument();
|
|
164
|
-
});
|
|
165
|
-
});
|
|
166
|
-
|
|
167
|
-
describe('Mode control', () => {
|
|
168
|
-
it('reports the next mode via onModeChange when switching to Annotate', async () => {
|
|
169
|
-
const onModeChange = vi.fn();
|
|
170
|
-
renderWithIntl(
|
|
171
|
-
<AnnotateToolbar
|
|
172
|
-
{...defaultProps}
|
|
173
|
-
annotateMode={false}
|
|
174
|
-
onModeChange={onModeChange}
|
|
175
|
-
/>,
|
|
176
|
-
);
|
|
177
|
-
await pick('Mode', 'Annotate');
|
|
178
|
-
expect(onModeChange).toHaveBeenCalledWith(true);
|
|
179
|
-
});
|
|
180
|
-
|
|
181
|
-
it('reports false when switching back to Browse from annotate mode', async () => {
|
|
182
|
-
const onModeChange = vi.fn();
|
|
183
|
-
renderWithIntl(
|
|
184
|
-
<AnnotateToolbar
|
|
185
|
-
{...defaultProps}
|
|
186
|
-
annotateMode={true}
|
|
187
|
-
onModeChange={onModeChange}
|
|
188
|
-
/>,
|
|
189
|
-
);
|
|
190
|
-
await pick('Mode', 'Browse');
|
|
191
|
-
expect(onModeChange).toHaveBeenCalledWith(false);
|
|
192
|
-
});
|
|
193
|
-
|
|
194
|
-
it('clicking the CURRENT mode reports nothing', async () => {
|
|
195
|
-
const onModeChange = vi.fn();
|
|
196
|
-
renderWithIntl(
|
|
197
|
-
<AnnotateToolbar
|
|
198
|
-
{...defaultProps}
|
|
199
|
-
annotateMode={false}
|
|
200
|
-
onModeChange={onModeChange}
|
|
201
|
-
/>,
|
|
202
|
-
);
|
|
203
|
-
const trigger = screen.getByLabelText('Mode');
|
|
204
|
-
fireEvent.mouseEnter(trigger.parentElement!);
|
|
205
|
-
await waitFor(() => {
|
|
206
|
-
const menu = screen.getByRole('menu');
|
|
207
|
-
fireEvent.click(within(menu).getByText('Browse')); // already in browse
|
|
208
|
-
});
|
|
209
|
-
expect(onModeChange).not.toHaveBeenCalled();
|
|
210
|
-
});
|
|
211
|
-
});
|
|
212
|
-
|
|
213
|
-
describe('Click-action control', () => {
|
|
214
|
-
it('reports the chosen action via onClickActionChange', async () => {
|
|
215
|
-
const onClickActionChange = vi.fn();
|
|
216
|
-
renderWithIntl(
|
|
217
|
-
<AnnotateToolbar
|
|
218
|
-
{...defaultProps}
|
|
219
|
-
onClickActionChange={onClickActionChange}
|
|
220
|
-
/>,
|
|
221
|
-
);
|
|
222
|
-
await pick('Click', 'Follow');
|
|
223
|
-
expect(onClickActionChange).toHaveBeenCalledWith('follow');
|
|
224
|
-
});
|
|
225
|
-
|
|
226
|
-
it('displays the selected action from props', () => {
|
|
227
|
-
renderWithIntl(
|
|
228
|
-
<AnnotateToolbar {...defaultProps} selectedClick="jsonld" />,
|
|
229
|
-
);
|
|
230
|
-
expect(screen.getByText('JSON-LD')).toBeInTheDocument();
|
|
231
|
-
});
|
|
232
|
-
});
|
|
233
|
-
|
|
234
|
-
describe('Selection control', () => {
|
|
235
|
-
it('reports the chosen motivation', async () => {
|
|
236
|
-
const onSelectionChange = vi.fn();
|
|
237
|
-
renderWithIntl(
|
|
238
|
-
<AnnotateToolbar
|
|
239
|
-
{...defaultProps}
|
|
240
|
-
onSelectionChange={onSelectionChange}
|
|
241
|
-
/>,
|
|
242
|
-
);
|
|
243
|
-
await pick('Motivation', 'Highlight');
|
|
244
|
-
expect(onSelectionChange).toHaveBeenCalledWith('highlighting');
|
|
245
|
-
});
|
|
246
|
-
|
|
247
|
-
it('re-picking the current motivation reports null (toggle off)', async () => {
|
|
248
|
-
const onSelectionChange = vi.fn();
|
|
249
|
-
renderWithIntl(
|
|
250
|
-
<AnnotateToolbar
|
|
251
|
-
{...defaultProps}
|
|
252
|
-
selectedMotivation="highlighting"
|
|
253
|
-
onSelectionChange={onSelectionChange}
|
|
254
|
-
/>,
|
|
255
|
-
);
|
|
256
|
-
await pick('Motivation', 'Highlight');
|
|
257
|
-
expect(onSelectionChange).toHaveBeenCalledWith(null);
|
|
258
|
-
});
|
|
259
|
-
|
|
260
|
-
it('picking None reports null', async () => {
|
|
261
|
-
const onSelectionChange = vi.fn();
|
|
262
|
-
renderWithIntl(
|
|
263
|
-
<AnnotateToolbar
|
|
264
|
-
{...defaultProps}
|
|
265
|
-
selectedMotivation="linking"
|
|
266
|
-
onSelectionChange={onSelectionChange}
|
|
267
|
-
/>,
|
|
268
|
-
);
|
|
269
|
-
await pick('Motivation', 'None');
|
|
270
|
-
expect(onSelectionChange).toHaveBeenCalledWith(null);
|
|
271
|
-
});
|
|
272
|
-
});
|
|
273
|
-
|
|
274
|
-
describe('Shape control', () => {
|
|
275
|
-
it('reports the chosen shape', async () => {
|
|
276
|
-
const onShapeChange = vi.fn();
|
|
277
|
-
renderWithIntl(
|
|
278
|
-
<AnnotateToolbar
|
|
279
|
-
{...defaultProps}
|
|
280
|
-
parts={['shape']}
|
|
281
|
-
selectedShape="rectangle"
|
|
282
|
-
mediaType="image/png"
|
|
283
|
-
onShapeChange={onShapeChange}
|
|
284
|
-
/>,
|
|
285
|
-
);
|
|
286
|
-
await pick('Shape', 'Circle');
|
|
287
|
-
expect(onShapeChange).toHaveBeenCalledWith('circle');
|
|
288
|
-
});
|
|
289
|
-
});
|
|
290
|
-
|
|
291
|
-
describe('Dropdown behavior', () => {
|
|
292
|
-
it('closes all dropdowns on Escape', async () => {
|
|
293
|
-
renderWithIntl(<AnnotateToolbar {...defaultProps} />);
|
|
294
|
-
const trigger = screen.getByLabelText('Mode');
|
|
295
|
-
fireEvent.click(trigger); // pin open
|
|
296
|
-
await waitFor(() => expect(screen.getByRole('menu')).toBeInTheDocument());
|
|
297
|
-
fireEvent.keyDown(document, { key: 'Escape' });
|
|
298
|
-
fireEvent.mouseLeave(trigger.parentElement!);
|
|
299
|
-
await waitFor(() =>
|
|
300
|
-
expect(screen.queryByRole('menu')).not.toBeInTheDocument(),
|
|
301
|
-
);
|
|
302
|
-
});
|
|
303
|
-
});
|
|
304
|
-
});
|
|
@@ -1,127 +0,0 @@
|
|
|
1
|
-
'use client';
|
|
2
|
-
|
|
3
|
-
import { useEffect, useRef } from 'react';
|
|
4
|
-
import { EditorView, lineNumbers } from '@codemirror/view';
|
|
5
|
-
import { EditorState } from '@codemirror/state';
|
|
6
|
-
import { json } from '@codemirror/lang-json';
|
|
7
|
-
import { syntaxHighlighting } from '@codemirror/language';
|
|
8
|
-
import { clipboard } from '../../lib/clipboard';
|
|
9
|
-
import { jsonTheme, jsonHighlightStyle } from '../../lib/codemirror-json-theme';
|
|
10
|
-
|
|
11
|
-
import type { Annotation } from '@xynolog/core';
|
|
12
|
-
|
|
13
|
-
interface JsonLdViewProps {
|
|
14
|
-
annotation: Annotation;
|
|
15
|
-
onBack: () => void;
|
|
16
|
-
/** Whether the editor numbers its lines: the viewer's own setting, handed down. */
|
|
17
|
-
showLineNumbers: boolean;
|
|
18
|
-
}
|
|
19
|
-
|
|
20
|
-
/**
|
|
21
|
-
* An annotation as W3C Web Annotation JSON-LD, read-only. It reads no
|
|
22
|
-
* provider: its line numbers come from the viewer that opens it, and its
|
|
23
|
-
* colours from the page's theme, through the CSS variables the JSON theme is
|
|
24
|
-
* written in.
|
|
25
|
-
*/
|
|
26
|
-
export function JsonLdView({
|
|
27
|
-
annotation,
|
|
28
|
-
onBack,
|
|
29
|
-
showLineNumbers,
|
|
30
|
-
}: JsonLdViewProps) {
|
|
31
|
-
const editorRef = useRef<HTMLDivElement>(null);
|
|
32
|
-
const viewRef = useRef<EditorView | null>(null);
|
|
33
|
-
|
|
34
|
-
// Store callback in ref to avoid including in dependency arrays
|
|
35
|
-
const onBackRef = useRef(onBack);
|
|
36
|
-
useEffect(() => {
|
|
37
|
-
onBackRef.current = onBack;
|
|
38
|
-
});
|
|
39
|
-
|
|
40
|
-
// Handle escape key
|
|
41
|
-
useEffect(() => {
|
|
42
|
-
const handleKeyDown = (e: KeyboardEvent) => {
|
|
43
|
-
if (e.key === 'Escape') {
|
|
44
|
-
onBackRef.current();
|
|
45
|
-
}
|
|
46
|
-
};
|
|
47
|
-
|
|
48
|
-
window.addEventListener('keydown', handleKeyDown);
|
|
49
|
-
return () => window.removeEventListener('keydown', handleKeyDown);
|
|
50
|
-
}, []);
|
|
51
|
-
|
|
52
|
-
// Initialize CodeMirror
|
|
53
|
-
useEffect(() => {
|
|
54
|
-
if (!editorRef.current) return;
|
|
55
|
-
|
|
56
|
-
const jsonContent = JSON.stringify(annotation, null, 2);
|
|
57
|
-
|
|
58
|
-
const extensions = [
|
|
59
|
-
json(),
|
|
60
|
-
EditorView.editable.of(false),
|
|
61
|
-
EditorState.readOnly.of(true),
|
|
62
|
-
];
|
|
63
|
-
|
|
64
|
-
// Add line numbers if enabled
|
|
65
|
-
if (showLineNumbers) {
|
|
66
|
-
extensions.push(lineNumbers());
|
|
67
|
-
}
|
|
68
|
-
|
|
69
|
-
// One theme for light and dark: its colours are CSS variables the page's theme sets.
|
|
70
|
-
extensions.push(jsonTheme);
|
|
71
|
-
extensions.push(syntaxHighlighting(jsonHighlightStyle));
|
|
72
|
-
|
|
73
|
-
const state = EditorState.create({
|
|
74
|
-
doc: jsonContent,
|
|
75
|
-
extensions,
|
|
76
|
-
});
|
|
77
|
-
|
|
78
|
-
const view = new EditorView({
|
|
79
|
-
state,
|
|
80
|
-
parent: editorRef.current,
|
|
81
|
-
});
|
|
82
|
-
|
|
83
|
-
viewRef.current = view;
|
|
84
|
-
|
|
85
|
-
return () => {
|
|
86
|
-
view.destroy();
|
|
87
|
-
viewRef.current = null;
|
|
88
|
-
};
|
|
89
|
-
}, [annotation, showLineNumbers]);
|
|
90
|
-
|
|
91
|
-
const copyTo = clipboard();
|
|
92
|
-
const handleCopyToClipboard = async (to: Clipboard) => {
|
|
93
|
-
try {
|
|
94
|
-
await to.writeText(JSON.stringify(annotation, null, 2));
|
|
95
|
-
} catch (err) {
|
|
96
|
-
console.error('Failed to copy JSON-LD:', err);
|
|
97
|
-
}
|
|
98
|
-
};
|
|
99
|
-
|
|
100
|
-
return (
|
|
101
|
-
<div className="xynolog-jsonld-view">
|
|
102
|
-
{/* Header with back and copy buttons */}
|
|
103
|
-
<div className="xynolog-jsonld-view__header">
|
|
104
|
-
<button
|
|
105
|
-
onClick={onBack}
|
|
106
|
-
className="xynolog-jsonld-view__back-button"
|
|
107
|
-
title="Go back (Escape)"
|
|
108
|
-
>
|
|
109
|
-
<
|
|
110
|
-
</button>
|
|
111
|
-
<h3 className="xynolog-jsonld-view__title">JSON-LD</h3>
|
|
112
|
-
{copyTo && (
|
|
113
|
-
<button
|
|
114
|
-
onClick={() => handleCopyToClipboard(copyTo)}
|
|
115
|
-
className="xynolog-jsonld-view__copy-button"
|
|
116
|
-
title="Copy to clipboard"
|
|
117
|
-
>
|
|
118
|
-
📋 Copy
|
|
119
|
-
</button>
|
|
120
|
-
)}
|
|
121
|
-
</div>
|
|
122
|
-
|
|
123
|
-
{/* JSON-LD content rendered with CodeMirror */}
|
|
124
|
-
<div ref={editorRef} className="xynolog-jsonld-view__editor" />
|
|
125
|
-
</div>
|
|
126
|
-
);
|
|
127
|
-
}
|
|
@@ -1,131 +0,0 @@
|
|
|
1
|
-
'use client';
|
|
2
|
-
|
|
3
|
-
import React from 'react';
|
|
4
|
-
import {
|
|
5
|
-
Dialog,
|
|
6
|
-
DialogPanel,
|
|
7
|
-
Transition,
|
|
8
|
-
TransitionChild,
|
|
9
|
-
} from '@headlessui/react';
|
|
10
|
-
|
|
11
|
-
interface SelectedTextDisplayProps {
|
|
12
|
-
exact: string;
|
|
13
|
-
}
|
|
14
|
-
|
|
15
|
-
export function SelectedTextDisplay({ exact }: SelectedTextDisplayProps) {
|
|
16
|
-
return (
|
|
17
|
-
<div className="xynolog-selected-text-display">
|
|
18
|
-
<p className="xynolog-selected-text-display__label">Selected text:</p>
|
|
19
|
-
<p className="xynolog-selected-text-display__content">"{exact}"</p>
|
|
20
|
-
</div>
|
|
21
|
-
);
|
|
22
|
-
}
|
|
23
|
-
|
|
24
|
-
interface EntityTypeBadgesProps {
|
|
25
|
-
entityTypes: string;
|
|
26
|
-
}
|
|
27
|
-
|
|
28
|
-
export function EntityTypeBadges({ entityTypes }: EntityTypeBadgesProps) {
|
|
29
|
-
if (!entityTypes) return null;
|
|
30
|
-
|
|
31
|
-
return (
|
|
32
|
-
<div className="xynolog-entity-type-badges">
|
|
33
|
-
{entityTypes.split(',').map((type, index) => (
|
|
34
|
-
<span key={index} className="xynolog-entity-type-badges__badge">
|
|
35
|
-
{type.trim()}
|
|
36
|
-
</span>
|
|
37
|
-
))}
|
|
38
|
-
</div>
|
|
39
|
-
);
|
|
40
|
-
}
|
|
41
|
-
|
|
42
|
-
interface PopupHeaderProps {
|
|
43
|
-
title: string;
|
|
44
|
-
selectedText?: string;
|
|
45
|
-
onClose: () => void;
|
|
46
|
-
}
|
|
47
|
-
|
|
48
|
-
export function PopupHeader({
|
|
49
|
-
title,
|
|
50
|
-
selectedText,
|
|
51
|
-
onClose,
|
|
52
|
-
}: PopupHeaderProps) {
|
|
53
|
-
return (
|
|
54
|
-
<div className="xynolog-popup-header">
|
|
55
|
-
<h3 className="xynolog-popup-header__title">
|
|
56
|
-
{title}
|
|
57
|
-
{selectedText && (
|
|
58
|
-
<span className="xynolog-popup-header__subtitle">
|
|
59
|
-
“{selectedText}”
|
|
60
|
-
</span>
|
|
61
|
-
)}
|
|
62
|
-
</h3>
|
|
63
|
-
<button onClick={onClose} className="xynolog-popup-header__close-button">
|
|
64
|
-
✕
|
|
65
|
-
</button>
|
|
66
|
-
</div>
|
|
67
|
-
);
|
|
68
|
-
}
|
|
69
|
-
|
|
70
|
-
interface PopupContainerProps {
|
|
71
|
-
children: React.ReactNode;
|
|
72
|
-
position: { x: number; y: number };
|
|
73
|
-
onClose: () => void;
|
|
74
|
-
isOpen: boolean;
|
|
75
|
-
wide?: boolean; // Optional prop to make the popup wider
|
|
76
|
-
}
|
|
77
|
-
|
|
78
|
-
export function PopupContainer({
|
|
79
|
-
children,
|
|
80
|
-
position,
|
|
81
|
-
onClose,
|
|
82
|
-
isOpen,
|
|
83
|
-
wide = false,
|
|
84
|
-
}: PopupContainerProps) {
|
|
85
|
-
const popupWidth = wide ? 800 : 400;
|
|
86
|
-
const popupHeight = wide ? 700 : 500;
|
|
87
|
-
|
|
88
|
-
const popupStyle: React.CSSProperties = {
|
|
89
|
-
position: 'fixed',
|
|
90
|
-
left: `${Math.min(position.x, typeof window !== 'undefined' ? window.innerWidth - popupWidth : position.x)}px`,
|
|
91
|
-
top: `${Math.min(position.y, typeof window !== 'undefined' ? window.innerHeight - popupHeight : position.y)}px`,
|
|
92
|
-
};
|
|
93
|
-
|
|
94
|
-
return (
|
|
95
|
-
<Transition appear show={isOpen}>
|
|
96
|
-
<Dialog as="div" className="xynolog-popup-overlay" onClose={onClose}>
|
|
97
|
-
{/* Backdrop */}
|
|
98
|
-
<TransitionChild
|
|
99
|
-
enter="ease-out duration-200"
|
|
100
|
-
enterFrom="opacity-0"
|
|
101
|
-
enterTo="opacity-100"
|
|
102
|
-
leave="ease-in duration-150"
|
|
103
|
-
leaveFrom="opacity-100"
|
|
104
|
-
leaveTo="opacity-0"
|
|
105
|
-
>
|
|
106
|
-
<div className="xynolog-popup-backdrop" />
|
|
107
|
-
</TransitionChild>
|
|
108
|
-
|
|
109
|
-
{/* Popup positioned at cursor */}
|
|
110
|
-
<div className="xynolog-popup-container">
|
|
111
|
-
<TransitionChild
|
|
112
|
-
enter="ease-out duration-200"
|
|
113
|
-
enterFrom="opacity-0 scale-95"
|
|
114
|
-
enterTo="opacity-100 scale-100"
|
|
115
|
-
leave="ease-in duration-150"
|
|
116
|
-
leaveFrom="opacity-100 scale-100"
|
|
117
|
-
leaveTo="opacity-0 scale-95"
|
|
118
|
-
>
|
|
119
|
-
<DialogPanel
|
|
120
|
-
className="xynolog-popup-panel"
|
|
121
|
-
style={popupStyle}
|
|
122
|
-
data-wide={wide ? 'true' : 'false'}
|
|
123
|
-
>
|
|
124
|
-
<>{children}</>
|
|
125
|
-
</DialogPanel>
|
|
126
|
-
</TransitionChild>
|
|
127
|
-
</div>
|
|
128
|
-
</Dialog>
|
|
129
|
-
</Transition>
|
|
130
|
-
);
|
|
131
|
-
}
|