@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.
Files changed (235) hide show
  1. package/README.md +26 -46
  2. package/package.json +12 -9
  3. package/src/components/Button/Button.tsx +0 -188
  4. package/src/components/Button/__tests__/Button.test.tsx +0 -449
  5. package/src/components/CodeMirrorRenderer.tsx +0 -536
  6. package/src/components/DelegateProgress.tsx +0 -308
  7. package/src/components/ErrorBoundary.tsx +0 -174
  8. package/src/components/ItemFoundLog.tsx +0 -42
  9. package/src/components/LiveRegion.tsx +0 -261
  10. package/src/components/ProtectedErrorBoundary.tsx +0 -114
  11. package/src/components/ResizeHandle.tsx +0 -167
  12. package/src/components/ResourceTagsInline.tsx +0 -120
  13. package/src/components/SessionExpiryBanner.tsx +0 -74
  14. package/src/components/SessionTimer.tsx +0 -17
  15. package/src/components/StatusDisplay.tsx +0 -131
  16. package/src/components/Toast.tsx +0 -217
  17. package/src/components/Toolbar.tsx +0 -194
  18. package/src/components/UserMenuSkeleton.tsx +0 -13
  19. package/src/components/__tests__/DelegateProgress.denominator.test.tsx +0 -102
  20. package/src/components/__tests__/DelegateProgress.test.tsx +0 -649
  21. package/src/components/__tests__/ErrorBoundary.test.tsx +0 -565
  22. package/src/components/__tests__/LiveRegion.a11y.test.tsx +0 -258
  23. package/src/components/__tests__/LiveRegion.hooks.test.tsx +0 -140
  24. package/src/components/__tests__/ProtectedErrorBoundary.test.tsx +0 -225
  25. package/src/components/__tests__/ResizeHandle.test.tsx +0 -159
  26. package/src/components/__tests__/ResourceTagsInline.test.tsx +0 -325
  27. package/src/components/__tests__/SessionExpiryBanner.test.tsx +0 -124
  28. package/src/components/__tests__/SessionTimer.test.tsx +0 -199
  29. package/src/components/__tests__/StatusDisplay.test.tsx +0 -179
  30. package/src/components/__tests__/Toast.test.tsx +0 -96
  31. package/src/components/__tests__/Toolbar.test.tsx +0 -111
  32. package/src/components/__tests__/UserMenuSkeleton.test.tsx +0 -182
  33. package/src/components/annotation/AnchoredTextNotice.tsx +0 -36
  34. package/src/components/annotation/AnnotateToolbar.tsx +0 -531
  35. package/src/components/annotation/__tests__/AnnotateToolbar.display.test.tsx +0 -127
  36. package/src/components/annotation/__tests__/AnnotateToolbar.test.tsx +0 -304
  37. package/src/components/annotation-popups/JsonLdView.tsx +0 -127
  38. package/src/components/annotation-popups/SharedPopupElements.tsx +0 -131
  39. package/src/components/annotation-popups/__tests__/JsonLdView.test.tsx +0 -432
  40. package/src/components/annotation-popups/__tests__/SharedPopupElements.test.tsx +0 -297
  41. package/src/components/branding/XynologBranding.tsx +0 -41
  42. package/src/components/branding/__tests__/XynologBranding.test.tsx +0 -383
  43. package/src/components/error-states/ResourceErrorState.tsx +0 -30
  44. package/src/components/error-states/__tests__/ResourceErrorState.test.tsx +0 -102
  45. package/src/components/image-annotation/AnnotationOverlay.tsx +0 -307
  46. package/src/components/image-annotation/SvgDrawingCanvas.tsx +0 -514
  47. package/src/components/image-annotation/__tests__/AnnotationOverlay.click.test.tsx +0 -169
  48. package/src/components/image-annotation/__tests__/AnnotationOverlay.hover.test.tsx +0 -83
  49. package/src/components/image-annotation/__tests__/SvgDrawingCanvas.annotate-gate.test.tsx +0 -228
  50. package/src/components/image-annotation/__tests__/SvgDrawingCanvas.click.test.tsx +0 -204
  51. package/src/components/layout/LeftSidebar.tsx +0 -150
  52. package/src/components/layout/PageLayout.tsx +0 -49
  53. package/src/components/layout/SkipLinks.tsx +0 -36
  54. package/src/components/layout/UnifiedHeader.tsx +0 -151
  55. package/src/components/layout/__tests__/LeftSidebar.test.tsx +0 -426
  56. package/src/components/layout/__tests__/PageLayout.test.tsx +0 -311
  57. package/src/components/layout/__tests__/SkipLinks.a11y.test.tsx +0 -218
  58. package/src/components/layout/__tests__/UnifiedHeader.test.tsx +0 -555
  59. package/src/components/loading-states/ComposeLoadingState.tsx +0 -19
  60. package/src/components/loading-states/ResourceLoadingState.tsx +0 -13
  61. package/src/components/loading-states/__tests__/ComposeLoadingState.test.tsx +0 -37
  62. package/src/components/loading-states/__tests__/ResourceLoadingState.test.tsx +0 -31
  63. package/src/components/modals/ComposeStep.tsx +0 -245
  64. package/src/components/modals/ConfigureGatherStep.tsx +0 -110
  65. package/src/components/modals/ConfigureGenerationStep.tsx +0 -458
  66. package/src/components/modals/ConfigureSearchStep.tsx +0 -124
  67. package/src/components/modals/ContextSummary.tsx +0 -317
  68. package/src/components/modals/CorpusPane.tsx +0 -96
  69. package/src/components/modals/DiscardPrompt.tsx +0 -44
  70. package/src/components/modals/GatherContextStep.tsx +0 -480
  71. package/src/components/modals/KbIdentityConflictModal.tsx +0 -122
  72. package/src/components/modals/KeyboardShortcutsHelpModal.tsx +0 -238
  73. package/src/components/modals/PermissionDeniedModal.tsx +0 -207
  74. package/src/components/modals/ReferenceWizardModal.tsx +0 -656
  75. package/src/components/modals/ResourceGenerateModal.tsx +0 -457
  76. package/src/components/modals/SearchModal.tsx +0 -334
  77. package/src/components/modals/SearchResultsStep.tsx +0 -117
  78. package/src/components/modals/SessionEndedModal.tsx +0 -148
  79. package/src/components/modals/WizardFooter.tsx +0 -72
  80. package/src/components/modals/__tests__/ComposeStep.test.tsx +0 -187
  81. package/src/components/modals/__tests__/ConfigureGatherStep.test.tsx +0 -92
  82. package/src/components/modals/__tests__/ConfigureGenerationStep.test.tsx +0 -574
  83. package/src/components/modals/__tests__/ConfigureSearchStep.test.tsx +0 -124
  84. package/src/components/modals/__tests__/GatherContextStep.resource.test.tsx +0 -702
  85. package/src/components/modals/__tests__/KbIdentityConflictModal.test.tsx +0 -102
  86. package/src/components/modals/__tests__/KeyboardShortcutsHelpModal.test.tsx +0 -115
  87. package/src/components/modals/__tests__/PermissionDeniedModal.test.tsx +0 -218
  88. package/src/components/modals/__tests__/ReferenceWizardModal.test.tsx +0 -936
  89. package/src/components/modals/__tests__/ResourceGenerateModal.test.tsx +0 -532
  90. package/src/components/modals/__tests__/SearchModal.accessibility.test.tsx +0 -95
  91. package/src/components/modals/__tests__/SearchModal.basic.test.tsx +0 -84
  92. package/src/components/modals/__tests__/SearchModal.keyboard.test.tsx +0 -162
  93. package/src/components/modals/__tests__/SearchModal.search-wiring.test.tsx +0 -237
  94. package/src/components/modals/__tests__/SearchModal.translations.test.tsx +0 -91
  95. package/src/components/modals/__tests__/SearchResultsStep.test.tsx +0 -95
  96. package/src/components/modals/__tests__/SessionEndedModal.test.tsx +0 -171
  97. package/src/components/modals/__tests__/WizardFooter.test.tsx +0 -446
  98. package/src/components/modals/__tests__/search-modal-harness.ts +0 -82
  99. package/src/components/navigation/CollapsibleResourceNavigation.tsx +0 -364
  100. package/src/components/navigation/NavigationMenu.tsx +0 -66
  101. package/src/components/navigation/ObservableLink.tsx +0 -90
  102. package/src/components/navigation/SimpleNavigation.tsx +0 -169
  103. package/src/components/navigation/SortableResourceTab.tsx +0 -122
  104. package/src/components/navigation/__tests__/NavigationMenu.a11y.test.tsx +0 -302
  105. package/src/components/navigation/__tests__/NavigationMenu.test.tsx +0 -399
  106. package/src/components/navigation/__tests__/ObservableLink.test.tsx +0 -85
  107. package/src/components/navigation/__tests__/SimpleNavigation.test.tsx +0 -193
  108. package/src/components/navigation/__tests__/SortableResourceTab.test.tsx +0 -421
  109. package/src/components/pdf-annotation/PdfAnnotationCanvas.client.tsx +0 -10
  110. package/src/components/pdf-annotation/PdfAnnotationCanvas.tsx +0 -632
  111. package/src/components/pdf-annotation/PdfPageView.tsx +0 -527
  112. package/src/components/pdf-annotation/__tests__/PdfAnnotationCanvas.annotate-gate.test.tsx +0 -295
  113. package/src/components/pdf-annotation/__tests__/PdfAnnotationCanvas.pixels-before-anchoring.test.tsx +0 -166
  114. package/src/components/pdf-annotation/__tests__/PdfAnnotationCanvas.test.tsx +0 -1719
  115. package/src/components/pdf-annotation/__tests__/estimate-slot-height.test.ts +0 -61
  116. package/src/components/pdf-annotation/__tests__/rects-for-page.test.ts +0 -110
  117. package/src/components/pdf-annotation/estimate-slot-height.ts +0 -31
  118. package/src/components/pdf-annotation/rects-for-page.ts +0 -50
  119. package/src/components/resource/AnnotateView.tsx +0 -373
  120. package/src/components/resource/AnnotationHistory.tsx +0 -169
  121. package/src/components/resource/BrowseView.tsx +0 -440
  122. package/src/components/resource/DownloadFileLink.tsx +0 -53
  123. package/src/components/resource/HistoryEvent.tsx +0 -186
  124. package/src/components/resource/ResourceViewer.tsx +0 -617
  125. package/src/components/resource/__tests__/AnnotateView.code-point-offsets.test.tsx +0 -482
  126. package/src/components/resource/__tests__/AnnotateView.embeddable.test.tsx +0 -78
  127. package/src/components/resource/__tests__/AnnotateView.focus.test.tsx +0 -147
  128. package/src/components/resource/__tests__/AnnotateView.registry.test.tsx +0 -143
  129. package/src/components/resource/__tests__/AnnotationHistory.test.tsx +0 -257
  130. package/src/components/resource/__tests__/BrowseView.code-point-offsets.test.tsx +0 -123
  131. package/src/components/resource/__tests__/BrowseView.embeddable.test.tsx +0 -76
  132. package/src/components/resource/__tests__/BrowseView.links.test.tsx +0 -84
  133. package/src/components/resource/__tests__/BrowseView.overlay-async.test.tsx +0 -165
  134. package/src/components/resource/__tests__/BrowseView.reference-hover.test.tsx +0 -200
  135. package/src/components/resource/__tests__/BrowseView.registry.test.tsx +0 -57
  136. package/src/components/resource/__tests__/BrowseView.test.tsx +0 -915
  137. package/src/components/resource/__tests__/HistoryEvent.test.tsx +0 -571
  138. package/src/components/resource/__tests__/ResourceViewer.delete-failure.test.tsx +0 -103
  139. package/src/components/resource/__tests__/ResourceViewer.embeddable.test.tsx +0 -250
  140. package/src/components/resource/__tests__/ResourceViewer.mode-switch.test.tsx +0 -262
  141. package/src/components/resource/__tests__/ResourceViewer.multi-mount-invalidation.test.tsx +0 -166
  142. package/src/components/resource/__tests__/ResourceViewer.registry.test.tsx +0 -112
  143. package/src/components/resource/__tests__/ResourceViewer.toolbar-opt-out.test.tsx +0 -207
  144. package/src/components/resource/__tests__/ResourceViewer.toolbar-prefs.test.tsx +0 -274
  145. package/src/components/resource/__tests__/annotation-interactions.test.tsx +0 -116
  146. package/src/components/resource/__tests__/browse-renderers.dispatch.test.tsx +0 -183
  147. package/src/components/resource/__tests__/browse-renderers.test.tsx +0 -47
  148. package/src/components/resource/__tests__/download-link.test.tsx +0 -171
  149. package/src/components/resource/__tests__/event-formatting.test.ts +0 -379
  150. package/src/components/resource/__tests__/inline-embedding.test.tsx +0 -133
  151. package/src/components/resource/__tests__/media-completeness.test.tsx +0 -144
  152. package/src/components/resource/annotate-renderers.tsx +0 -186
  153. package/src/components/resource/browse-renderers.tsx +0 -133
  154. package/src/components/resource/event-formatting.ts +0 -393
  155. package/src/components/resource/panels/AssessmentEntry.tsx +0 -127
  156. package/src/components/resource/panels/AssessmentPanel.tsx +0 -309
  157. package/src/components/resource/panels/CollaborationPanel.tsx +0 -228
  158. package/src/components/resource/panels/CommentEntry.tsx +0 -242
  159. package/src/components/resource/panels/CommentsPanel.tsx +0 -320
  160. package/src/components/resource/panels/DelegateSection.tsx +0 -282
  161. package/src/components/resource/panels/DelegateShell.tsx +0 -134
  162. package/src/components/resource/panels/HighlightEntry.tsx +0 -83
  163. package/src/components/resource/panels/HighlightPanel.tsx +0 -212
  164. package/src/components/resource/panels/JsonLdPanel.tsx +0 -119
  165. package/src/components/resource/panels/PanelHeader.tsx +0 -22
  166. package/src/components/resource/panels/ReferenceEntry.tsx +0 -232
  167. package/src/components/resource/panels/ReferencesPanel.tsx +0 -626
  168. package/src/components/resource/panels/ResourceInfoPanel.tsx +0 -433
  169. package/src/components/resource/panels/StatisticsPanel.tsx +0 -145
  170. package/src/components/resource/panels/TagEntry.tsx +0 -87
  171. package/src/components/resource/panels/TaggingPanel.tsx +0 -554
  172. package/src/components/resource/panels/UnifiedAnnotationsPanel.tsx +0 -384
  173. package/src/components/resource/panels/__tests__/AssessmentEntry.test.tsx +0 -292
  174. package/src/components/resource/panels/__tests__/AssessmentPanel.test.tsx +0 -685
  175. package/src/components/resource/panels/__tests__/CollaborationPanel.test.tsx +0 -685
  176. package/src/components/resource/panels/__tests__/CommentEntry.test.tsx +0 -750
  177. package/src/components/resource/panels/__tests__/CommentsPanel.test.tsx +0 -877
  178. package/src/components/resource/panels/__tests__/DelegateSection.test.tsx +0 -623
  179. package/src/components/resource/panels/__tests__/DelegateShell.test.tsx +0 -212
  180. package/src/components/resource/panels/__tests__/HighlightEntry.test.tsx +0 -236
  181. package/src/components/resource/panels/__tests__/HighlightPanel.annotationProgress.test.tsx +0 -506
  182. package/src/components/resource/panels/__tests__/HighlightPanel.out-of-order.test.tsx +0 -132
  183. package/src/components/resource/panels/__tests__/JsonLdPanel.test.tsx +0 -230
  184. package/src/components/resource/panels/__tests__/PanelHeader.test.tsx +0 -54
  185. package/src/components/resource/panels/__tests__/ReferenceEntry.test.tsx +0 -578
  186. package/src/components/resource/panels/__tests__/ReferencesPanel.headless.test.tsx +0 -193
  187. package/src/components/resource/panels/__tests__/ReferencesPanel.observable-flow.test.tsx +0 -193
  188. package/src/components/resource/panels/__tests__/ReferencesPanel.test.tsx +0 -1080
  189. package/src/components/resource/panels/__tests__/ResourceInfoPanel.test.tsx +0 -812
  190. package/src/components/resource/panels/__tests__/ResourceInfoPanel.text-layer.test.tsx +0 -106
  191. package/src/components/resource/panels/__tests__/StatisticsPanel.test.tsx +0 -329
  192. package/src/components/resource/panels/__tests__/TagEntry.test.tsx +0 -250
  193. package/src/components/resource/panels/__tests__/TaggingPanel.test.tsx +0 -772
  194. package/src/components/resource/panels/__tests__/UnifiedAnnotationsPanel.delegated-job.test.tsx +0 -207
  195. package/src/components/resource/panels/__tests__/UnifiedAnnotationsPanel.failure.test.tsx +0 -89
  196. package/src/components/resource/panels/__tests__/agent-label.test.ts +0 -136
  197. package/src/components/resource/panels/agent-label.ts +0 -35
  198. package/src/components/settings/SettingsPanel.tsx +0 -251
  199. package/src/components/settings/__tests__/SettingsPanel.test.tsx +0 -260
  200. package/src/components/viewers/ImageViewer.tsx +0 -18
  201. package/src/components/viewers/__tests__/ImageViewer.test.tsx +0 -57
  202. package/src/components/viewers/index.ts +0 -1
  203. package/src/features/auth/__tests__/AuthErrorDisplay.test.tsx +0 -181
  204. package/src/features/auth/components/AuthErrorDisplay.tsx +0 -89
  205. package/src/features/moderate-entity-tags/__tests__/EntityTagsPage.test.tsx +0 -387
  206. package/src/features/moderate-entity-tags/components/EntityTagsPage.tsx +0 -161
  207. package/src/features/moderate-entity-tags/state/__tests__/entity-tags-state-unit.test.ts +0 -183
  208. package/src/features/moderate-entity-tags/state/entity-tags-state-unit.ts +0 -73
  209. package/src/features/moderate-recent/__tests__/RecentDocumentsPage.test.tsx +0 -422
  210. package/src/features/moderate-recent/components/RecentDocumentsPage.tsx +0 -117
  211. package/src/features/moderate-tag-schemas/__tests__/TagSchemasPage.test.tsx +0 -481
  212. package/src/features/moderate-tag-schemas/components/TagSchemasPage.tsx +0 -161
  213. package/src/features/resource-compose/__tests__/ResourceComposePage.test.tsx +0 -600
  214. package/src/features/resource-compose/__tests__/UploadProgressBar.test.tsx +0 -256
  215. package/src/features/resource-compose/components/ResourceComposePage.tsx +0 -809
  216. package/src/features/resource-compose/components/UploadProgressBar.tsx +0 -125
  217. package/src/features/resource-compose/state/__tests__/compose-page-state-unit.test.ts +0 -195
  218. package/src/features/resource-compose/state/compose-page-state-unit.ts +0 -187
  219. package/src/features/resource-discovery/__tests__/ResourceCard.test.tsx +0 -338
  220. package/src/features/resource-discovery/__tests__/ResourceDiscoveryPage.test.tsx +0 -449
  221. package/src/features/resource-discovery/components/ResourceCard.tsx +0 -80
  222. package/src/features/resource-discovery/components/ResourceDiscoveryPage.tsx +0 -330
  223. package/src/features/resource-discovery/state/__tests__/discover-state-unit.test.ts +0 -477
  224. package/src/features/resource-discovery/state/discover-state-unit.ts +0 -162
  225. package/src/features/resource-viewer/__tests__/ResourceViewerPage.content-loading.test.tsx +0 -260
  226. package/src/features/resource-viewer/__tests__/ResourceViewerPage.test.tsx +0 -570
  227. package/src/features/resource-viewer/__tests__/generation-params.test.ts +0 -49
  228. package/src/features/resource-viewer/components/ResourceViewerPage.tsx +0 -1058
  229. package/src/features/resource-viewer/generation-params.ts +0 -23
  230. package/src/features/resource-viewer/hooks/__tests__/useResourceViewedReport.test.tsx +0 -77
  231. package/src/features/resource-viewer/hooks/useResourceViewedReport.ts +0 -38
  232. package/src/features/resource-viewer/state/__tests__/resource-loader-state-unit.test.ts +0 -178
  233. package/src/features/resource-viewer/state/__tests__/resource-viewer-page-state-unit.test.ts +0 -505
  234. package/src/features/resource-viewer/state/resource-loader-state-unit.ts +0 -93
  235. package/src/features/resource-viewer/state/resource-viewer-page-state-unit.ts +0 -156
@@ -1,125 +0,0 @@
1
- 'use client';
2
-
3
- /**
4
- * Inline upload-progress affordance for the compose page.
5
- *
6
- * Subscribes (via prop) to a `UploadProgress | null` value derived from
7
- * `composeVM.uploadProgress$`. Renders nothing when null; renders an
8
- * indeterminate state on `started`; renders a labeled bar with byte
9
- * counts on `progress`; renders a brief "Uploaded" success state on
10
- * `finished` (cleared by the state unit's `null` push on complete).
11
- *
12
- * Designed to live below the Save button in the compose form so the
13
- * visual association with the action that triggered the upload is
14
- * direct. Uses the existing `.xynolog-progress` styles in
15
- * `typescript/react-ui/src/styles/core/progress.css`.
16
- */
17
-
18
- import React from 'react';
19
- import type { UploadProgress } from '@xynolog/sdk';
20
-
21
- export interface UploadProgressBarProps {
22
- progress: UploadProgress | null;
23
- /** What is being uploaded, named at the head of each line. */
24
- label: string;
25
- }
26
-
27
- function formatBytes(bytes: number): string {
28
- if (bytes < 1024) return `${bytes} B`;
29
- if (bytes < 1024 * 1024) return `${(bytes / 1024).toFixed(1)} KB`;
30
- if (bytes < 1024 * 1024 * 1024)
31
- return `${(bytes / (1024 * 1024)).toFixed(1)} MB`;
32
- return `${(bytes / (1024 * 1024 * 1024)).toFixed(2)} GB`;
33
- }
34
-
35
- export function UploadProgressBar({
36
- progress,
37
- label,
38
- }: UploadProgressBarProps): React.ReactElement | null {
39
- if (!progress) return null;
40
-
41
- if (progress.phase === 'started') {
42
- return (
43
- <div
44
- className="xynolog-progress-wrapper"
45
- role="status"
46
- aria-live="polite"
47
- >
48
- <div className="xynolog-progress__label">
49
- <span>{label}: starting…</span>
50
- </div>
51
- <div className="xynolog-progress xynolog-progress--indeterminate">
52
- <div className="xynolog-progress__fill" />
53
- </div>
54
- </div>
55
- );
56
- }
57
-
58
- if (progress.phase === 'progress') {
59
- const indeterminate = progress.totalBytes <= 0;
60
- const percentage = indeterminate
61
- ? 0
62
- : Math.min(
63
- 100,
64
- Math.round((progress.bytesUploaded / progress.totalBytes) * 100),
65
- );
66
- return (
67
- <div
68
- className="xynolog-progress-wrapper"
69
- role="status"
70
- aria-live="polite"
71
- >
72
- <div className="xynolog-progress__label">
73
- {indeterminate ? (
74
- <span>
75
- {label}: {formatBytes(progress.bytesUploaded)}…
76
- </span>
77
- ) : (
78
- <>
79
- <span>
80
- {label}: {percentage}%
81
- </span>
82
- <span>
83
- {formatBytes(progress.bytesUploaded)} /{' '}
84
- {formatBytes(progress.totalBytes)}
85
- </span>
86
- </>
87
- )}
88
- </div>
89
- <div
90
- className={`xynolog-progress${indeterminate ? ' xynolog-progress--indeterminate' : ''}`}
91
- role="progressbar"
92
- aria-valuemin={0}
93
- aria-valuemax={indeterminate ? undefined : 100}
94
- aria-valuenow={indeterminate ? undefined : percentage}
95
- >
96
- <div
97
- className="xynolog-progress__fill"
98
- style={indeterminate ? undefined : { width: `${percentage}%` }}
99
- />
100
- </div>
101
- </div>
102
- );
103
- }
104
-
105
- // phase === 'finished'
106
- return (
107
- <div className="xynolog-progress-wrapper" role="status" aria-live="polite">
108
- <div className="xynolog-progress__label">
109
- <span>{label}: uploaded</span>
110
- </div>
111
- <div
112
- className="xynolog-progress"
113
- role="progressbar"
114
- aria-valuemin={0}
115
- aria-valuemax={100}
116
- aria-valuenow={100}
117
- >
118
- <div
119
- className="xynolog-progress__fill xynolog-progress__fill--success"
120
- style={{ width: '100%' }}
121
- />
122
- </div>
123
- </div>
124
- );
125
- }
@@ -1,195 +0,0 @@
1
- import { describe, it, expect, vi } from 'vitest';
2
- import { asStates } from '../../../../__tests__/test-client';
3
- import { sessionOf } from '../../../../__tests__/test-client';
4
- import { BehaviorSubject, Observable, firstValueFrom } from 'rxjs';
5
- import { filter } from 'rxjs/operators';
6
- import type { XynologClient } from '@xynolog/sdk';
7
- import type { ShellStateUnit } from '../../../../state/shell-state-unit';
8
- import {
9
- createComposePageStateUnit,
10
- type ComposePageStateUnit,
11
- } from '../compose-page-state-unit';
12
- import {
13
- assertStateUnitAxioms,
14
- disposeProbe,
15
- } from '@xynolog/core/testing/axioms';
16
-
17
- /** Build an `UploadObservable`-shaped mock that emits started → finished. */
18
- function mockUpload(resourceId: string) {
19
- return vi.fn().mockReturnValue(
20
- new Observable((subscriber) => {
21
- subscriber.next({ phase: 'started', totalBytes: 100 });
22
- subscriber.next({ phase: 'finished', resourceId });
23
- subscriber.complete();
24
- }),
25
- );
26
- }
27
-
28
- function mockBrowse(): ShellStateUnit {
29
- return { dispose: vi.fn() } as unknown as ShellStateUnit;
30
- }
31
-
32
- function mockClient(
33
- overrides: {
34
- entityTypes$?: BehaviorSubject<string[] | undefined>;
35
- fromToken?: ReturnType<typeof vi.fn>;
36
- getResourceRepresentation?: ReturnType<typeof vi.fn>;
37
- createFromToken?: ReturnType<typeof vi.fn>;
38
- resource?: ReturnType<typeof vi.fn>;
39
- body?: ReturnType<typeof vi.fn>;
40
- } = {},
41
- ): XynologClient {
42
- const entityTypes$ =
43
- overrides.entityTypes$ ??
44
- new BehaviorSubject<string[] | undefined>(['Person']);
45
- return {
46
- browse: {
47
- entityTypes: () => asStates(entityTypes$.asObservable()),
48
- },
49
- yield: {
50
- fromToken:
51
- overrides.fromToken ??
52
- vi.fn().mockResolvedValue({
53
- '@id': 'src-1',
54
- representations: [{ mediaType: 'text/plain' }],
55
- }),
56
- createFromToken:
57
- overrides.createFromToken ??
58
- vi.fn().mockResolvedValue({ resourceId: 'new-1' }),
59
- resource: overrides.resource ?? mockUpload('new-2'),
60
- },
61
- bind: {
62
- body: overrides.body ?? vi.fn().mockResolvedValue(undefined),
63
- },
64
- getResourceRepresentation:
65
- overrides.getResourceRepresentation ??
66
- vi.fn().mockResolvedValue({
67
- data: new TextEncoder().encode('source content').buffer,
68
- contentType: 'text/plain',
69
- }),
70
- } as unknown as XynologClient;
71
- }
72
-
73
- describe('createComposePageStateUnit', () => {
74
- it('defaults to "new" mode', async () => {
75
- const stateUnit = createComposePageStateUnit(
76
- sessionOf(mockClient()),
77
- mockBrowse(),
78
- {},
79
- );
80
-
81
- const mode = await firstValueFrom(stateUnit.mode$);
82
- expect(mode).toBe('new');
83
-
84
- const loading = await firstValueFrom(
85
- stateUnit.loading$.pipe(filter((l) => !l)),
86
- );
87
- expect(loading).toBe(false);
88
-
89
- stateUnit.dispose();
90
- });
91
-
92
- it('exposes entity types', async () => {
93
- const stateUnit = createComposePageStateUnit(
94
- sessionOf(mockClient()),
95
- mockBrowse(),
96
- {},
97
- );
98
-
99
- const types = await firstValueFrom(stateUnit.entityTypes.value$);
100
- expect(types).toEqual(['Person']);
101
-
102
- stateUnit.dispose();
103
- });
104
-
105
- it('save in new mode calls yield.resource', async () => {
106
- const resource = mockUpload('new-3');
107
- const stateUnit = createComposePageStateUnit(
108
- sessionOf(mockClient({ resource })),
109
- mockBrowse(),
110
- {},
111
- );
112
-
113
- const id = await stateUnit.save({
114
- mode: 'new',
115
- name: 'Test',
116
- storageUri: '/docs/test.md',
117
- content: '# Hello',
118
- format: 'text/markdown',
119
- language: 'en',
120
- });
121
-
122
- expect(id).toBe('new-3');
123
- expect(resource).toHaveBeenCalledOnce();
124
-
125
- stateUnit.dispose();
126
- });
127
-
128
- it('save in clone mode calls yield.createFromToken', async () => {
129
- const createFromToken = vi
130
- .fn()
131
- .mockResolvedValue({ resourceId: 'cloned-1' });
132
- const stateUnit = createComposePageStateUnit(
133
- sessionOf(mockClient({ createFromToken })),
134
- mockBrowse(),
135
- {
136
- mode: 'clone',
137
- token: 'tok-abc',
138
- },
139
- );
140
-
141
- const id = await stateUnit.save({
142
- mode: 'clone',
143
- name: 'Cloned',
144
- storageUri: '/docs/cloned.md',
145
- content: 'cloned content',
146
- language: 'en',
147
- });
148
-
149
- expect(id).toBe('cloned-1');
150
- expect(createFromToken).toHaveBeenCalledOnce();
151
-
152
- stateUnit.dispose();
153
- });
154
- });
155
-
156
- describe('ComposePageStateUnit — StateUnit axioms', () => {
157
- it('satisfies the StateUnit axioms (incl. A7-passed: never disposes the injected browse)', () => {
158
- assertStateUnitAxioms<ComposePageStateUnit>({
159
- setup: () => {
160
- const browse = disposeProbe();
161
- return {
162
- unit: createComposePageStateUnit(
163
- sessionOf(mockClient()),
164
- browse as unknown as ShellStateUnit,
165
- {},
166
- ),
167
- passedIn: [browse],
168
- };
169
- },
170
- surfaces: (u) => [u.mode$, u.loading$, u.cloneData$, u.uploadProgress$],
171
- });
172
- });
173
- });
174
-
175
- describe('createComposePageStateUnit — entity types load failure', () => {
176
- // Lower severity than the two hangs: compose defaults to an empty picker,
177
- // which misrepresents a failed load as "this KB has no entity types".
178
-
179
- it('surfaces the failure rather than presenting an empty picker as fact', async () => {
180
- const entityTypes$ = new BehaviorSubject<string[] | undefined>(undefined);
181
- const stateUnit = createComposePageStateUnit(
182
- sessionOf(mockClient({ entityTypes$ })),
183
- mockBrowse(),
184
- {},
185
- );
186
-
187
- entityTypes$.next({ status: 'failed', error: new Error('boom') } as never);
188
-
189
- expect(await firstValueFrom(stateUnit.entityTypes.loading$)).toBe(false);
190
- expect(await firstValueFrom(stateUnit.entityTypes.error$)).not.toBeNull();
191
- expect(await firstValueFrom(stateUnit.entityTypes.value$)).toEqual([]);
192
-
193
- stateUnit.dispose();
194
- });
195
- });
@@ -1,187 +0,0 @@
1
- import { BehaviorSubject, type Observable } from 'rxjs';
2
- import type {
3
- AccessToken,
4
- ResourceDescriptor,
5
- ResourceId,
6
- } from '@xynolog/core';
7
- import { createDisposer } from '@xynolog/sdk';
8
- import type { StateUnit } from '@xynolog/core';
9
- import type { ShellStateUnit } from '../../../state/shell-state-unit';
10
- import { trackList, type ListState } from '../../../state/list-state';
11
- import type { XynologSession } from '@xynolog/sdk';
12
- import { decodeWithCharset, extensionForMediaType } from '@xynolog/core';
13
- import type { UploadProgress } from '@xynolog/sdk';
14
-
15
- export type ComposeMode = 'new' | 'clone';
16
-
17
- export interface ComposeParams {
18
- mode?: string | undefined;
19
- token?: string | undefined;
20
- }
21
-
22
- export interface CloneData {
23
- sourceResource: ResourceDescriptor;
24
- sourceContent: string;
25
- }
26
-
27
- export interface SaveResourceParams {
28
- mode: ComposeMode;
29
- name: string;
30
- storageUri: string;
31
- content?: string;
32
- file?: File;
33
- format?: string;
34
- charset?: string;
35
- entityTypes?: string[];
36
- language: string;
37
- archiveOriginal?: boolean;
38
- }
39
-
40
- export interface ComposePageStateUnit extends StateUnit {
41
- browse: ShellStateUnit;
42
- mode$: Observable<ComposeMode>;
43
- loading$: Observable<boolean>;
44
- cloneData$: Observable<CloneData | null>;
45
- entityTypes: ListState<string[]>;
46
- /**
47
- * Live upload-progress for the in-flight `save(...)` call. Emits the
48
- * full `UploadProgress` lifecycle (started → finished) while a save is
49
- * underway; resets to `null` between saves and after completion. UI
50
- * components can subscribe to render an upload-in-progress indicator.
51
- */
52
- uploadProgress$: Observable<UploadProgress | null>;
53
- save(params: SaveResourceParams): Promise<string>;
54
- }
55
-
56
- export function createComposePageStateUnit(
57
- session: XynologSession,
58
- browse: ShellStateUnit,
59
- params: ComposeParams,
60
- auth?: AccessToken,
61
- ): ComposePageStateUnit {
62
- const { client } = session;
63
- const disposer = createDisposer();
64
- // `browse` (ShellStateUnit) is a *passed-in* dependency owned by the caller
65
- // (`useShellStateUnit`), not this unit — do NOT add it to the disposer (it's the
66
- // shared, app-scoped shell). See https://github.com/xynolog/docs/blob/main/builder/STATE-UNITS.md (composition rule).
67
-
68
- const isCloneMode = params.mode === 'clone' && Boolean(params.token);
69
- const pageMode: ComposeMode = isCloneMode ? 'clone' : 'new';
70
-
71
- const mode$ = new BehaviorSubject<ComposeMode>(pageMode);
72
- const loading$ = new BehaviorSubject<boolean>(true);
73
- const cloneData$ = new BehaviorSubject<CloneData | null>(null);
74
- const uploadProgress$ = new BehaviorSubject<UploadProgress | null>(null);
75
-
76
- const entityTypes = trackList<string[]>(
77
- () => client.browse.entityTypes(),
78
- [],
79
- );
80
- disposer.add(entityTypes.dispose);
81
-
82
- // Initialize based on mode
83
- if (isCloneMode) {
84
- void (async () => {
85
- try {
86
- const tokenResult = await client.yield.fromToken(params.token!);
87
- if (tokenResult && auth) {
88
- const rId = tokenResult['@id'];
89
- const { data, contentType } =
90
- await client.browse.resourceRepresentation(rId);
91
- const content = decodeWithCharset(data, contentType);
92
- cloneData$.next({
93
- sourceResource: tokenResult,
94
- sourceContent: content,
95
- });
96
- }
97
- } catch {
98
- // Error handling is the consumer's responsibility (toast)
99
- }
100
- loading$.next(false);
101
- })();
102
- } else {
103
- loading$.next(false);
104
- }
105
-
106
- const save = async (saveParams: SaveResourceParams): Promise<string> => {
107
- if (saveParams.mode === 'clone') {
108
- const response = await client.yield.createFromToken({
109
- token: params.token!,
110
- name: saveParams.name,
111
- content: saveParams.content!,
112
- archiveOriginal: saveParams.archiveOriginal ?? true,
113
- });
114
- return response.resourceId;
115
- }
116
-
117
- let fileToUpload: File;
118
- let mimeType: string;
119
-
120
- if (saveParams.file) {
121
- fileToUpload = saveParams.file;
122
- mimeType = saveParams.format ?? 'application/octet-stream';
123
- } else {
124
- const blob = new Blob([saveParams.content || ''], {
125
- type: saveParams.format ?? 'application/octet-stream',
126
- });
127
- const extension = extensionForMediaType(
128
- saveParams.format ?? 'application/octet-stream',
129
- );
130
- fileToUpload = new File([blob], saveParams.name + extension, {
131
- type: saveParams.format ?? 'application/octet-stream',
132
- });
133
- mimeType = saveParams.format ?? 'application/octet-stream';
134
- }
135
-
136
- const format =
137
- saveParams.charset && !saveParams.file
138
- ? `${mimeType}; charset=${saveParams.charset}`
139
- : mimeType;
140
-
141
- // Subscribe to the upload's full progress lifecycle so the UI can
142
- // render an upload-in-progress indicator. Resolve the save() promise
143
- // on the `finished` event and clear the progress signal on completion
144
- // (success or error).
145
- const newResourceId = await new Promise<ResourceId>((resolve, reject) => {
146
- client.yield
147
- .resource({
148
- name: saveParams.name,
149
- file: fileToUpload,
150
- format,
151
- entityTypes: saveParams.entityTypes || [],
152
- language: saveParams.language,
153
- storageUri: saveParams.storageUri,
154
- })
155
- .subscribe({
156
- next: (event) => {
157
- uploadProgress$.next(event);
158
- if (event.phase === 'finished') resolve(event.resourceId);
159
- },
160
- error: (err) => {
161
- uploadProgress$.next(null);
162
- reject(err);
163
- },
164
- complete: () => uploadProgress$.next(null),
165
- });
166
- });
167
-
168
- return newResourceId;
169
- };
170
-
171
- return {
172
- browse,
173
- mode$: mode$.asObservable(),
174
- loading$: loading$.asObservable(),
175
- cloneData$: cloneData$.asObservable(),
176
- entityTypes: entityTypes.state,
177
- uploadProgress$: uploadProgress$.asObservable(),
178
- save,
179
- dispose: () => {
180
- mode$.complete();
181
- loading$.complete();
182
- cloneData$.complete();
183
- uploadProgress$.complete();
184
- disposer.dispose();
185
- },
186
- };
187
- }