@semiont/react-ui 0.5.9 → 0.5.11

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 (209) hide show
  1. package/README.md +1 -1
  2. package/dist/{PdfAnnotationCanvas.client-U4EVBZEV.js → PdfAnnotationCanvas.client-KWQ7XDWT.js} +5 -2
  3. package/dist/PdfAnnotationCanvas.client-KWQ7XDWT.js.map +1 -0
  4. package/dist/{ar-WA47UUWA.js → ar-ZHKO4XDR.js} +45 -4
  5. package/dist/ar-ZHKO4XDR.js.map +1 -0
  6. package/dist/{bn-5ANDRIU6.js → bn-3BUDKAK5.js} +45 -4
  7. package/dist/bn-3BUDKAK5.js.map +1 -0
  8. package/dist/{chunk-YBGN4ACY.js → chunk-O23TLLXW.js} +1 -6
  9. package/dist/{chunk-WHUGODTB.js → chunk-PFUXQPWJ.js} +127 -127
  10. package/dist/{chunk-WHUGODTB.js.map → chunk-PFUXQPWJ.js.map} +1 -1
  11. package/dist/{chunk-GERSK2DY.js → chunk-R52YAGHK.js} +42 -1
  12. package/dist/chunk-R52YAGHK.js.map +1 -0
  13. package/dist/{cs-3RU7F4JX.js → cs-2EFEUKTW.js} +45 -4
  14. package/dist/cs-2EFEUKTW.js.map +1 -0
  15. package/dist/{da-GSW5P5HG.js → da-SUD3Q44Q.js} +45 -4
  16. package/dist/da-SUD3Q44Q.js.map +1 -0
  17. package/dist/{de-JUAUYF4Z.js → de-6IC5QRX7.js} +45 -4
  18. package/dist/de-6IC5QRX7.js.map +1 -0
  19. package/dist/{el-JNLWCKEC.js → el-Q4NAXFRC.js} +45 -4
  20. package/dist/el-Q4NAXFRC.js.map +1 -0
  21. package/dist/{en-RBN2GUHF.js → en-P2L4X27N.js} +5 -3
  22. package/dist/{es-WPOX225H.js → es-YUKZBD4W.js} +45 -4
  23. package/dist/es-YUKZBD4W.js.map +1 -0
  24. package/dist/{fa-TAEP6N77.js → fa-OJ47LILE.js} +45 -4
  25. package/dist/fa-OJ47LILE.js.map +1 -0
  26. package/dist/{fi-ZVZHANSP.js → fi-QFFL5CUB.js} +45 -4
  27. package/dist/fi-QFFL5CUB.js.map +1 -0
  28. package/dist/{fr-VLZW7M4N.js → fr-BOQZZWP4.js} +45 -4
  29. package/dist/fr-BOQZZWP4.js.map +1 -0
  30. package/dist/{he-QFAFYA77.js → he-LXDY3TFA.js} +45 -4
  31. package/dist/he-LXDY3TFA.js.map +1 -0
  32. package/dist/{hi-AO3DQPCV.js → hi-HOJER77V.js} +45 -4
  33. package/dist/hi-HOJER77V.js.map +1 -0
  34. package/dist/{id-GTXF42WM.js → id-I5WQ6EWD.js} +45 -4
  35. package/dist/id-I5WQ6EWD.js.map +1 -0
  36. package/dist/index.css +150 -112
  37. package/dist/index.css.map +1 -1
  38. package/dist/index.d.ts +403 -45
  39. package/dist/index.js +4660 -18860
  40. package/dist/index.js.map +1 -1
  41. package/dist/integrations/css-modules-helper.js +1 -1
  42. package/dist/integrations/styled-components-theme.js +1 -1
  43. package/dist/{it-AS5GM232.js → it-UYH642IJ.js} +45 -4
  44. package/dist/it-UYH642IJ.js.map +1 -0
  45. package/dist/{ja-GZ4HLUOF.js → ja-JTVWAC4L.js} +45 -4
  46. package/dist/ja-JTVWAC4L.js.map +1 -0
  47. package/dist/{ko-A4XUXFGJ.js → ko-IHXFMOIZ.js} +45 -4
  48. package/dist/ko-IHXFMOIZ.js.map +1 -0
  49. package/dist/{ms-YBAO3S6K.js → ms-JH25VFLO.js} +45 -4
  50. package/dist/ms-JH25VFLO.js.map +1 -0
  51. package/dist/{nl-3TJGIIIU.js → nl-SURXW7IQ.js} +45 -4
  52. package/dist/nl-SURXW7IQ.js.map +1 -0
  53. package/dist/{no-4AXIQPRQ.js → no-HXIKQFDZ.js} +45 -4
  54. package/dist/no-HXIKQFDZ.js.map +1 -0
  55. package/dist/{pl-5GP6GKXO.js → pl-7A4KU6XK.js} +45 -4
  56. package/dist/pl-7A4KU6XK.js.map +1 -0
  57. package/dist/{pt-26Y6JFG5.js → pt-6MGYP7Q5.js} +45 -4
  58. package/dist/pt-6MGYP7Q5.js.map +1 -0
  59. package/dist/{ro-C7UXFRWJ.js → ro-IROCHNIA.js} +45 -4
  60. package/dist/ro-IROCHNIA.js.map +1 -0
  61. package/dist/{sv-44DVD76T.js → sv-WDJD75CV.js} +45 -4
  62. package/dist/sv-WDJD75CV.js.map +1 -0
  63. package/dist/test-utils.js +9 -4
  64. package/dist/test-utils.js.map +1 -1
  65. package/dist/{th-GIQRTBOY.js → th-RIO2E6B3.js} +45 -4
  66. package/dist/th-RIO2E6B3.js.map +1 -0
  67. package/dist/{tr-WMQWO4D6.js → tr-TZ7ERCIN.js} +45 -4
  68. package/dist/tr-TZ7ERCIN.js.map +1 -0
  69. package/dist/{uk-I7ML6RGG.js → uk-ZFWDKLUE.js} +45 -4
  70. package/dist/uk-ZFWDKLUE.js.map +1 -0
  71. package/dist/{vi-FGWECASQ.js → vi-UIOSP2JG.js} +45 -4
  72. package/dist/vi-UIOSP2JG.js.map +1 -0
  73. package/dist/{zh-L5FN73XC.js → zh-6R6YUY46.js} +45 -4
  74. package/dist/zh-6R6YUY46.js.map +1 -0
  75. package/package.json +18 -9
  76. package/src/components/AnnotateReferencesProgressWidget.tsx +35 -16
  77. package/src/components/ResourceTagsInline.tsx +94 -11
  78. package/src/components/StatusDisplay.css +36 -0
  79. package/src/components/__tests__/AnnotateReferencesProgressWidget.test.tsx +41 -91
  80. package/src/components/__tests__/ResourceTagsInline.test.tsx +101 -3
  81. package/src/components/annotation/AnnotateToolbar.tsx +53 -28
  82. package/src/components/annotation/__tests__/AnnotateToolbar.display.test.tsx +76 -0
  83. package/src/components/annotation/__tests__/AnnotateToolbar.test.tsx +124 -360
  84. package/src/components/image-annotation/SvgDrawingCanvas.tsx +5 -1
  85. package/src/components/modals/ConfigureGatherStep.tsx +102 -0
  86. package/src/components/modals/ContextSummary.tsx +15 -6
  87. package/src/components/modals/GatherContextStep.tsx +104 -59
  88. package/src/components/modals/ResourceGenerateModal.tsx +258 -0
  89. package/src/components/modals/__tests__/ConfigureGatherStep.test.tsx +82 -0
  90. package/src/components/modals/__tests__/GatherContextStep.resource.test.tsx +107 -0
  91. package/src/components/modals/__tests__/ResourceGenerateModal.test.tsx +197 -0
  92. package/src/components/pdf-annotation/PdfAnnotationCanvas.tsx +5 -0
  93. package/src/components/pdf-annotation/__tests__/PdfAnnotationCanvas.test.tsx +6 -6
  94. package/src/components/resource/AnnotateView.tsx +59 -38
  95. package/src/components/resource/BrowseView.tsx +159 -133
  96. package/src/components/resource/ResourceViewer.tsx +119 -128
  97. package/src/components/resource/__tests__/AnnotateView.embeddable.test.tsx +55 -0
  98. package/src/components/resource/__tests__/BrowseView.embeddable.test.tsx +49 -0
  99. package/src/components/resource/__tests__/BrowseView.links.test.tsx +60 -0
  100. package/src/components/resource/__tests__/BrowseView.overlay-async.test.tsx +113 -0
  101. package/src/components/resource/__tests__/BrowseView.reference-hover.test.tsx +161 -0
  102. package/src/components/resource/__tests__/BrowseView.registry.test.tsx +43 -0
  103. package/src/components/resource/__tests__/BrowseView.test.tsx +35 -22
  104. package/src/components/resource/__tests__/ResourceViewer.embeddable.test.tsx +63 -0
  105. package/src/components/resource/__tests__/ResourceViewer.mode-switch.test.tsx +12 -7
  106. package/src/components/resource/__tests__/ResourceViewer.toolbar-opt-out.test.tsx +135 -0
  107. package/src/components/resource/__tests__/ResourceViewer.toolbar-prefs.test.tsx +200 -0
  108. package/src/components/resource/__tests__/browse-renderers.test.tsx +34 -0
  109. package/src/components/resource/__tests__/inline-embedding.test.tsx +81 -0
  110. package/src/components/resource/__tests__/media-completeness.test.tsx +88 -0
  111. package/src/components/resource/browse-renderers.tsx +63 -0
  112. package/src/components/resource/panels/AssessmentPanel.tsx +4 -0
  113. package/src/components/resource/panels/CommentsPanel.tsx +4 -0
  114. package/src/components/resource/panels/HighlightPanel.tsx +4 -0
  115. package/src/components/resource/panels/ReferencesPanel.tsx +14 -0
  116. package/src/components/resource/panels/ResourceInfoPanel.tsx +22 -0
  117. package/src/components/resource/panels/TaggingPanel.tsx +4 -0
  118. package/src/components/resource/panels/UnifiedAnnotationsPanel.tsx +5 -2
  119. package/src/components/resource/panels/__tests__/AssessmentPanel.test.tsx +1 -0
  120. package/src/components/resource/panels/__tests__/CommentsPanel.test.tsx +1 -0
  121. package/src/components/resource/panels/__tests__/HighlightPanel.annotationProgress.test.tsx +16 -16
  122. package/src/components/resource/panels/__tests__/ReferencesPanel.observable-flow.test.tsx +1 -1
  123. package/src/components/resource/panels/__tests__/ReferencesPanel.test.tsx +1 -0
  124. package/src/components/resource/panels/__tests__/ResourceInfoPanel.test.tsx +26 -0
  125. package/src/components/resource/panels/__tests__/TaggingPanel.test.tsx +1 -0
  126. package/src/components/toolbar/Toolbar.css +14 -0
  127. package/src/features/admin-exchange/state/__tests__/exchange-state-unit.test.ts +14 -0
  128. package/src/features/admin-exchange/state/exchange-state-unit.ts +4 -2
  129. package/src/features/admin-security/state/__tests__/admin-security-state-unit.test.ts +14 -0
  130. package/src/features/admin-security/state/admin-security-state-unit.ts +4 -2
  131. package/src/features/admin-users/state/__tests__/admin-users-state-unit.test.ts +12 -5
  132. package/src/features/admin-users/state/admin-users-state-unit.ts +4 -2
  133. package/src/features/auth-welcome/state/__tests__/welcome-state-unit.test.ts +11 -0
  134. package/src/features/auth-welcome/state/welcome-state-unit.ts +1 -1
  135. package/src/features/moderate-entity-tags/state/__tests__/entity-tags-state-unit.test.ts +14 -0
  136. package/src/features/moderate-entity-tags/state/entity-tags-state-unit.ts +4 -2
  137. package/src/features/resource-compose/components/ResourceComposePage.tsx +13 -7
  138. package/src/features/resource-compose/state/__tests__/compose-page-state-unit.test.ts +13 -0
  139. package/src/features/resource-compose/state/compose-page-state-unit.ts +5 -2
  140. package/src/features/resource-discovery/state/__tests__/discover-state-unit.test.ts +15 -9
  141. package/src/features/resource-discovery/state/discover-state-unit.ts +5 -2
  142. package/src/features/resource-viewer/__tests__/ResourceViewerPage.test.tsx +7 -17
  143. package/src/features/resource-viewer/components/ResourceViewerPage.tsx +119 -17
  144. package/src/features/resource-viewer/state/__tests__/resource-loader-state-unit.test.ts +11 -0
  145. package/src/features/resource-viewer/state/__tests__/resource-viewer-page-state-unit.test.ts +30 -0
  146. package/src/features/resource-viewer/state/resource-loader-state-unit.ts +1 -1
  147. package/src/features/resource-viewer/state/resource-viewer-page-state-unit.ts +7 -16
  148. package/src/styles/features/resource-viewer.css +19 -0
  149. package/translations/ar.json +41 -2
  150. package/translations/bn.json +41 -2
  151. package/translations/cs.json +41 -2
  152. package/translations/da.json +41 -2
  153. package/translations/de.json +41 -2
  154. package/translations/el.json +41 -2
  155. package/translations/en.json +39 -0
  156. package/translations/es.json +41 -2
  157. package/translations/fa.json +41 -2
  158. package/translations/fi.json +41 -2
  159. package/translations/fr.json +41 -2
  160. package/translations/he.json +41 -2
  161. package/translations/hi.json +41 -2
  162. package/translations/id.json +41 -2
  163. package/translations/it.json +41 -2
  164. package/translations/ja.json +41 -2
  165. package/translations/ko.json +41 -2
  166. package/translations/ms.json +41 -2
  167. package/translations/nl.json +41 -2
  168. package/translations/no.json +41 -2
  169. package/translations/pl.json +41 -2
  170. package/translations/pt.json +41 -2
  171. package/translations/ro.json +41 -2
  172. package/translations/sv.json +41 -2
  173. package/translations/th.json +41 -2
  174. package/translations/tr.json +41 -2
  175. package/translations/uk.json +41 -2
  176. package/translations/vi.json +41 -2
  177. package/translations/zh.json +41 -2
  178. package/dist/PdfAnnotationCanvas.client-U4EVBZEV.js.map +0 -1
  179. package/dist/ar-WA47UUWA.js.map +0 -1
  180. package/dist/bn-5ANDRIU6.js.map +0 -1
  181. package/dist/chunk-GERSK2DY.js.map +0 -1
  182. package/dist/cs-3RU7F4JX.js.map +0 -1
  183. package/dist/da-GSW5P5HG.js.map +0 -1
  184. package/dist/de-JUAUYF4Z.js.map +0 -1
  185. package/dist/el-JNLWCKEC.js.map +0 -1
  186. package/dist/es-WPOX225H.js.map +0 -1
  187. package/dist/fa-TAEP6N77.js.map +0 -1
  188. package/dist/fi-ZVZHANSP.js.map +0 -1
  189. package/dist/fr-VLZW7M4N.js.map +0 -1
  190. package/dist/he-QFAFYA77.js.map +0 -1
  191. package/dist/hi-AO3DQPCV.js.map +0 -1
  192. package/dist/id-GTXF42WM.js.map +0 -1
  193. package/dist/it-AS5GM232.js.map +0 -1
  194. package/dist/ja-GZ4HLUOF.js.map +0 -1
  195. package/dist/ko-A4XUXFGJ.js.map +0 -1
  196. package/dist/ms-YBAO3S6K.js.map +0 -1
  197. package/dist/nl-3TJGIIIU.js.map +0 -1
  198. package/dist/no-4AXIQPRQ.js.map +0 -1
  199. package/dist/pl-5GP6GKXO.js.map +0 -1
  200. package/dist/pt-26Y6JFG5.js.map +0 -1
  201. package/dist/ro-C7UXFRWJ.js.map +0 -1
  202. package/dist/sv-44DVD76T.js.map +0 -1
  203. package/dist/th-GIQRTBOY.js.map +0 -1
  204. package/dist/tr-WMQWO4D6.js.map +0 -1
  205. package/dist/uk-I7ML6RGG.js.map +0 -1
  206. package/dist/vi-FGWECASQ.js.map +0 -1
  207. package/dist/zh-L5FN73XC.js.map +0 -1
  208. /package/dist/{chunk-YBGN4ACY.js.map → chunk-O23TLLXW.js.map} +0 -0
  209. /package/dist/{en-RBN2GUHF.js.map → en-P2L4X27N.js.map} +0 -0
@@ -0,0 +1,82 @@
1
+ /**
2
+ * GENERATE-FROM-BUTTON P2/P4 — the gather-options form.
3
+ *
4
+ * Pure presentational form (no providers): it owns the gather config in local
5
+ * state and emits a `ResourceGatherConfig` on submit. The `children` slot hosts
6
+ * the Phase-4 exclusion multi-select.
7
+ */
8
+ import { describe, it, expect, vi } from 'vitest';
9
+ import { render, screen, fireEvent } from '@testing-library/react';
10
+ import '@testing-library/jest-dom';
11
+ import { ConfigureGatherStep } from '../ConfigureGatherStep';
12
+
13
+ const t = {
14
+ intro: 'Choose what to include.',
15
+ includeContent: 'Include content',
16
+ includeSummary: 'Include summary',
17
+ depth: 'Depth',
18
+ maxResources: 'Max resources',
19
+ cancel: 'Cancel',
20
+ gather: 'Gather',
21
+ };
22
+
23
+ describe('ConfigureGatherStep', () => {
24
+ it('renders the intro and the default option values', () => {
25
+ render(<ConfigureGatherStep onGather={vi.fn()} onCancel={vi.fn()} translations={t} />);
26
+ expect(screen.getByText('Choose what to include.')).toBeInTheDocument();
27
+ expect(screen.getByLabelText('Include content')).toBeChecked();
28
+ expect(screen.getByLabelText('Include summary')).toBeChecked();
29
+ expect(screen.getByLabelText('Depth')).toHaveValue(2);
30
+ expect(screen.getByLabelText('Max resources')).toHaveValue(10);
31
+ });
32
+
33
+ it('emits the default config on submit', () => {
34
+ const onGather = vi.fn();
35
+ render(<ConfigureGatherStep onGather={onGather} onCancel={vi.fn()} translations={t} />);
36
+ fireEvent.click(screen.getByRole('button', { name: /Gather/ }));
37
+ expect(onGather).toHaveBeenCalledWith({ includeContent: true, includeSummary: true, depth: 2, maxResources: 10 });
38
+ });
39
+
40
+ it('reflects edits in the emitted config', () => {
41
+ const onGather = vi.fn();
42
+ render(<ConfigureGatherStep onGather={onGather} onCancel={vi.fn()} translations={t} />);
43
+ fireEvent.click(screen.getByLabelText('Include content')); // uncheck
44
+ fireEvent.click(screen.getByLabelText('Include summary')); // uncheck
45
+ fireEvent.change(screen.getByLabelText('Depth'), { target: { value: '4' } });
46
+ fireEvent.change(screen.getByLabelText('Max resources'), { target: { value: '25' } });
47
+ fireEvent.click(screen.getByRole('button', { name: /Gather/ }));
48
+ expect(onGather).toHaveBeenCalledWith({ includeContent: false, includeSummary: false, depth: 4, maxResources: 25 });
49
+ });
50
+
51
+ it('honors the defaults prop', () => {
52
+ const onGather = vi.fn();
53
+ render(
54
+ <ConfigureGatherStep
55
+ defaults={{ includeSummary: false, depth: 1, maxResources: 5 }}
56
+ onGather={onGather}
57
+ onCancel={vi.fn()}
58
+ translations={t}
59
+ />,
60
+ );
61
+ expect(screen.getByLabelText('Include summary')).not.toBeChecked();
62
+ expect(screen.getByLabelText('Depth')).toHaveValue(1);
63
+ fireEvent.click(screen.getByRole('button', { name: /Gather/ }));
64
+ expect(onGather).toHaveBeenCalledWith({ includeContent: true, includeSummary: false, depth: 1, maxResources: 5 });
65
+ });
66
+
67
+ it('calls onCancel from the cancel button', () => {
68
+ const onCancel = vi.fn();
69
+ render(<ConfigureGatherStep onGather={vi.fn()} onCancel={onCancel} translations={t} />);
70
+ fireEvent.click(screen.getByRole('button', { name: /Cancel/ }));
71
+ expect(onCancel).toHaveBeenCalledTimes(1);
72
+ });
73
+
74
+ it('renders the children slot (exclusion picker)', () => {
75
+ render(
76
+ <ConfigureGatherStep onGather={vi.fn()} onCancel={vi.fn()} translations={t}>
77
+ <div>EXCLUDE-SLOT</div>
78
+ </ConfigureGatherStep>,
79
+ );
80
+ expect(screen.getByText('EXCLUDE-SLOT')).toBeInTheDocument();
81
+ });
82
+ });
@@ -0,0 +1,107 @@
1
+ /**
2
+ * GENERATE-FROM-BUTTON P1 — the GatheredContext display renders a resource focus.
3
+ *
4
+ * ContextSummary's graph views are focus-agnostic; GatherContextStep gains a
5
+ * resource-focus strip and hides the annotation-only controls (hint + the
6
+ * Bind/Generate/Compose footer) for a resource focus.
7
+ */
8
+ import { describe, it, expect, beforeEach, vi } from 'vitest';
9
+ import { render } from '@testing-library/react';
10
+ import type { GatheredContext } from '@semiont/core';
11
+ import { GatherContextStep } from '../GatherContextStep';
12
+ import { ContextSummary } from '../ContextSummary';
13
+
14
+ const t = {
15
+ title: 'Gather',
16
+ loadingContext: 'Loading…',
17
+ failedContext: 'Failed',
18
+ search: 'Search',
19
+ generate: 'Generate',
20
+ compose: 'Compose',
21
+ resolutionStrategyLabel: 'Strategy',
22
+ sourceContextLabel: 'Source',
23
+ connectionsLabel: 'Connections',
24
+ citedByLabel: 'Cited by',
25
+ userHintLabel: 'Hint',
26
+ userHintPlaceholder: 'hint…',
27
+ };
28
+
29
+ function resourceContext(): GatheredContext {
30
+ return {
31
+ focus: {
32
+ kind: 'resource',
33
+ resource: { id: 'res-1', name: 'My Resource' },
34
+ summary: 'A short summary',
35
+ suggestedReferences: ['Suggested Topic'],
36
+ content: { main: 'main content' },
37
+ },
38
+ graph: {
39
+ nodes: [
40
+ { id: 'res-1', type: 'resource', label: 'My Resource' },
41
+ { id: 'res-2', type: 'resource', label: 'Related Resource', entityTypes: ['Topic'] },
42
+ ],
43
+ edges: [{ source: 'res-1', target: 'res-2', type: 'peer' }],
44
+ },
45
+ metadata: { entityTypes: ['Topic'] },
46
+ } as unknown as GatheredContext;
47
+ }
48
+
49
+ describe('GatheredContext display — resource focus', () => {
50
+ beforeEach(() => {
51
+ // jsdom doesn't implement scrollIntoView — GatherContextStep's annotation
52
+ // strip calls it on mount. (Same stub the panel tests use.)
53
+ Element.prototype.scrollIntoView = vi.fn();
54
+ });
55
+
56
+ it('ContextSummary renders graph views (connections) for a resource focus', () => {
57
+ const { container } = render(<ContextSummary context={resourceContext()} translations={t} />);
58
+ expect(container.textContent).toContain('Related Resource'); // peer connection from deriveViews
59
+ });
60
+
61
+ it('GatherContextStep shows the resource strip and hides the annotation-only footer', () => {
62
+ const { container } = render(
63
+ <GatherContextStep
64
+ context={resourceContext()}
65
+ contextLoading={false}
66
+ contextError={null}
67
+ translations={t}
68
+ />,
69
+ );
70
+ expect(container.textContent).toContain('My Resource'); // focal resource name
71
+ expect(container.textContent).toContain('A short summary'); // resource summary
72
+ expect(container.textContent).toContain('Suggested Topic'); // suggestedReferences chip
73
+ expect(container.textContent).toContain('Related Resource'); // graph view via ContextSummary
74
+ // annotation-only controls are gated out for a resource focus
75
+ expect(container.textContent).not.toContain('Strategy');
76
+ expect(container.querySelector('.semiont-gather__footer')).toBeNull();
77
+ expect(container.querySelector('.semiont-gather__hint-textarea')).toBeNull();
78
+ });
79
+
80
+ it('GatherContextStep still shows the footer for an annotation focus', () => {
81
+ const annotationContext = {
82
+ focus: {
83
+ kind: 'annotation',
84
+ annotation: { id: 'anno-1', motivation: 'linking' },
85
+ sourceResource: { id: 'res-1', name: 'Host' },
86
+ selected: { before: 'a ', text: 'term', after: ' b' },
87
+ },
88
+ graph: { nodes: [], edges: [] },
89
+ metadata: {},
90
+ } as unknown as GatheredContext;
91
+ const { container } = render(
92
+ <GatherContextStep
93
+ context={annotationContext}
94
+ contextLoading={false}
95
+ contextError={null}
96
+ userHint=""
97
+ onUserHintChange={() => {}}
98
+ onBind={() => {}}
99
+ onGenerate={() => {}}
100
+ onCompose={() => {}}
101
+ translations={t}
102
+ />,
103
+ );
104
+ expect(container.querySelector('.semiont-gather__footer')).not.toBeNull();
105
+ expect(container.textContent).toContain('Strategy');
106
+ });
107
+ });
@@ -0,0 +1,197 @@
1
+ /**
2
+ * GENERATE-FROM-BUTTON P2/P4 — the resource-generate flow modal.
3
+ *
4
+ * Drives the step machine: configure-gather → review → configure-generation.
5
+ * `useResourceGather` is mocked so we control the gathered context and assert
6
+ * how the step wires `gather()` (incl. the Phase-4 exclusion threading) and
7
+ * `onGenerateSubmit`. `useSemiont` is mocked to feed the entity-type options.
8
+ */
9
+ import { describe, it, expect, vi, beforeEach, type Mock } from 'vitest';
10
+ import { render, screen, fireEvent } from '@testing-library/react';
11
+ import '@testing-library/jest-dom';
12
+ import { BehaviorSubject, of } from 'rxjs';
13
+ import type { GatheredContext } from '@semiont/core';
14
+ import type { GenerationConfig } from '../ConfigureGenerationStep';
15
+
16
+ const RESOURCE_CONTEXT = {
17
+ focus: { kind: 'resource', resource: { id: 'res-1', name: 'My Resource' }, summary: 'A short summary' },
18
+ graph: { nodes: [{ id: 'res-1', type: 'resource', label: 'My Resource' }], edges: [] },
19
+ metadata: {},
20
+ } as unknown as GatheredContext;
21
+
22
+ // Mutable hook state + spies, shared with the hoisted vi.mock factory.
23
+ const h = vi.hoisted(() => ({
24
+ gather: vi.fn(),
25
+ reset: vi.fn(),
26
+ state: { context: null as unknown, loading: false, error: null as Error | null },
27
+ }));
28
+
29
+ vi.mock('../../../hooks/useResourceGather', () => ({
30
+ useResourceGather: () => ({
31
+ context: h.state.context,
32
+ loading: h.state.loading,
33
+ error: h.state.error,
34
+ gather: h.gather,
35
+ reset: h.reset,
36
+ }),
37
+ }));
38
+
39
+ // Stable observable instance — the modal calls `entityTypes()` inline in
40
+ // render, so a fresh observable each call would re-subscribe every render and
41
+ // loop. The real SDK returns a cached observable; mirror that here.
42
+ const entityTypes$ = of<string[]>(['Person', 'Topic']);
43
+ const mockClient = { browse: { entityTypes: () => entityTypes$ } };
44
+ const activeSession$ = new BehaviorSubject<unknown>({ client: mockClient });
45
+ vi.mock('../../../session/SemiontProvider', async () => {
46
+ const actual = await vi.importActual<typeof import('../../../session/SemiontProvider')>('../../../session/SemiontProvider');
47
+ return { ...actual, useSemiont: () => ({ activeSession$ }) };
48
+ });
49
+
50
+ import { ResourceGenerateModal } from '../ResourceGenerateModal';
51
+
52
+ const T = {
53
+ gatherTitle: 'Configure Gather',
54
+ reviewTitle: 'Review Context',
55
+ configureTitle: 'Configure Generation',
56
+ next: 'Next',
57
+ back: 'Back',
58
+ cancel: 'Cancel',
59
+ gatherIntro: 'Choose what to include.',
60
+ includeContent: 'Include content',
61
+ includeSummary: 'Include summary',
62
+ gatherDepth: 'Depth',
63
+ gatherMaxResources: 'Max resources',
64
+ gatherButton: 'Gather',
65
+ excludeLabel: 'Exclude from recall',
66
+ loadingContext: 'Gathering…',
67
+ failedContext: 'Failed',
68
+ sourceContextLabel: 'Resource',
69
+ connectionsLabel: 'Connections',
70
+ citedByLabel: 'Cited by',
71
+ resourceTitle: 'New resource title',
72
+ resourceTitlePlaceholder: 'Title…',
73
+ additionalInstructions: 'Additional Instructions',
74
+ additionalInstructionsPlaceholder: 'Optional…',
75
+ language: 'Language',
76
+ languageHelp: 'Language help',
77
+ creativity: 'Creativity',
78
+ creativityFocused: 'Focused',
79
+ creativityCreative: 'Creative',
80
+ maxLength: 'Max Length',
81
+ maxLengthHelp: 'Max help',
82
+ generate: 'Generate',
83
+ };
84
+
85
+ let onClose: Mock<() => void>;
86
+ let onGenerateSubmit: Mock<(resourceId: string, config: GenerationConfig) => void>;
87
+
88
+ function renderModal(props: Partial<React.ComponentProps<typeof ResourceGenerateModal>> = {}) {
89
+ return render(
90
+ <ResourceGenerateModal
91
+ isOpen
92
+ onClose={onClose}
93
+ resourceId="res-1"
94
+ defaultTitle="Default Title"
95
+ locale="en"
96
+ onGenerateSubmit={onGenerateSubmit}
97
+ translations={T}
98
+ {...props}
99
+ />,
100
+ );
101
+ }
102
+
103
+ describe('ResourceGenerateModal', () => {
104
+ beforeEach(() => {
105
+ vi.clearAllMocks();
106
+ onClose = vi.fn<() => void>();
107
+ onGenerateSubmit = vi.fn<(resourceId: string, config: GenerationConfig) => void>();
108
+ h.state = { context: null, loading: false, error: null };
109
+ activeSession$.next({ client: mockClient });
110
+ // jsdom doesn't implement scrollIntoView; GatherContextStep may call it.
111
+ Element.prototype.scrollIntoView = vi.fn();
112
+ });
113
+
114
+ it('renders nothing when closed', () => {
115
+ renderModal({ isOpen: false });
116
+ expect(screen.queryByText('Configure Gather')).not.toBeInTheDocument();
117
+ });
118
+
119
+ it('opens on the configure-gather step with the exclusion options', () => {
120
+ renderModal();
121
+ expect(screen.getByText('Configure Gather')).toBeInTheDocument(); // step title
122
+ expect(screen.getByText('Choose what to include.')).toBeInTheDocument();
123
+ expect(screen.getByLabelText('Include content')).toBeInTheDocument();
124
+ expect(screen.getByRole('button', { name: 'Person' })).toBeInTheDocument();
125
+ expect(screen.getByRole('button', { name: 'Topic' })).toBeInTheDocument();
126
+ });
127
+
128
+ it('submitting the gather step calls gather() and advances to review (exclusion omitted when none picked)', () => {
129
+ renderModal();
130
+ fireEvent.click(screen.getByRole('button', { name: /Gather/ }));
131
+ expect(h.gather).toHaveBeenCalledWith('res-1', { includeContent: true, includeSummary: true, depth: 2, maxResources: 10 });
132
+ expect(screen.getByText('Review Context')).toBeInTheDocument(); // step title flipped
133
+ expect(screen.getByRole('button', { name: /Next/ })).toBeDisabled(); // no context yet
134
+ });
135
+
136
+ it('threads picked entity types into the gather call', () => {
137
+ renderModal();
138
+ fireEvent.click(screen.getByRole('button', { name: 'Person' })); // select to exclude
139
+ fireEvent.click(screen.getByRole('button', { name: /Gather/ }));
140
+ expect(h.gather).toHaveBeenCalledWith('res-1', {
141
+ includeContent: true,
142
+ includeSummary: true,
143
+ depth: 2,
144
+ maxResources: 10,
145
+ excludeEntityTypes: ['Person'],
146
+ });
147
+ });
148
+
149
+ it('walks gather → review → configure-generation → emits onGenerateSubmit then closes', () => {
150
+ h.state.context = RESOURCE_CONTEXT; // gather already resolved
151
+ renderModal();
152
+
153
+ fireEvent.click(screen.getByRole('button', { name: /Gather/ })); // → review
154
+ const next = screen.getByRole('button', { name: /Next/ });
155
+ expect(next).toBeEnabled();
156
+ fireEvent.click(next); // → configure-generation
157
+
158
+ fireEvent.change(screen.getByLabelText('New resource title'), { target: { value: 'Generated Doc' } });
159
+ fireEvent.change(screen.getByLabelText('Save location'), { target: { value: 'generated/out.md' } });
160
+ fireEvent.click(screen.getByRole('button', { name: /Generate/ }));
161
+
162
+ expect(onGenerateSubmit).toHaveBeenCalledTimes(1);
163
+ expect(onGenerateSubmit).toHaveBeenCalledWith(
164
+ 'res-1',
165
+ expect.objectContaining({
166
+ title: 'Generated Doc',
167
+ storagePath: 'file://generated/out.md',
168
+ context: RESOURCE_CONTEXT,
169
+ }),
170
+ );
171
+ expect(onClose).toHaveBeenCalled();
172
+ });
173
+
174
+ it('Back from configure-generation returns to review', () => {
175
+ h.state.context = RESOURCE_CONTEXT;
176
+ renderModal();
177
+ fireEvent.click(screen.getByRole('button', { name: /Gather/ })); // → review
178
+ fireEvent.click(screen.getByRole('button', { name: /Next/ })); // → configure-generation
179
+ expect(screen.getByText('Configure Generation')).toBeInTheDocument();
180
+ fireEvent.click(screen.getByRole('button', { name: /Back/ })); // → review
181
+ expect(screen.getByText('Review Context')).toBeInTheDocument();
182
+ });
183
+
184
+ it('Back from review returns to the configure-gather step', () => {
185
+ renderModal();
186
+ fireEvent.click(screen.getByRole('button', { name: /Gather/ })); // → review
187
+ expect(screen.getByText('Review Context')).toBeInTheDocument();
188
+ fireEvent.click(screen.getByRole('button', { name: /Back/ })); // → configure-gather
189
+ expect(screen.getByText('Configure Gather')).toBeInTheDocument();
190
+ });
191
+
192
+ it('the header close button calls onClose', () => {
193
+ renderModal();
194
+ fireEvent.click(screen.getByLabelText('Close'));
195
+ expect(onClose).toHaveBeenCalledTimes(1);
196
+ });
197
+ });
@@ -2,6 +2,7 @@
2
2
 
3
3
  import React, { useRef, useState, useCallback, useEffect, useMemo } from 'react';
4
4
  import type { Annotation } from '@semiont/core';
5
+ import { resourceId as toResourceId } from '@semiont/core';
5
6
  import {
6
7
  getTargetSelector,
7
8
  createFragmentSelector,
@@ -48,6 +49,8 @@ function getMotivationColor(motivation: SelectionMotivation | null): { stroke: s
48
49
 
49
50
  interface PdfAnnotationCanvasProps {
50
51
  pdfUrl: string;
52
+ /** The '@id' of the annotated resource — stamped as `source` on mark:requested (multi-viewer routing). */
53
+ resourceUri: string;
51
54
  existingAnnotations?: Annotation[];
52
55
  drawingMode: DrawingMode;
53
56
  selectedMotivation?: SelectionMotivation | null;
@@ -66,6 +69,7 @@ interface PdfAnnotationCanvasProps {
66
69
  */
67
70
  export function PdfAnnotationCanvas({
68
71
  pdfUrl,
72
+ resourceUri,
69
73
  existingAnnotations = [],
70
74
  drawingMode,
71
75
  selectedMotivation,
@@ -319,6 +323,7 @@ export function PdfAnnotationCanvas({
319
323
  // Emit annotation:requested event with FragmentSelector
320
324
  if (selectedMotivation) {
321
325
  session.client.mark.request(
326
+ toResourceId(resourceUri),
322
327
  {
323
328
  type: 'FragmentSelector',
324
329
  conformsTo: 'http://tools.ietf.org/rfc/rfc3778',
@@ -56,7 +56,7 @@ describe('PdfAnnotationCanvas', () => {
56
56
 
57
57
  test('renders loading state initially', () => {
58
58
  render(
59
- <PdfAnnotationCanvas
59
+ <PdfAnnotationCanvas resourceUri="res-1"
60
60
  pdfUrl={mockPdfUrl}
61
61
  drawingMode={null}
62
62
  />
@@ -67,7 +67,7 @@ describe('PdfAnnotationCanvas', () => {
67
67
 
68
68
  test('renders page navigation controls after loading', async () => {
69
69
  render(
70
- <PdfAnnotationCanvas
70
+ <PdfAnnotationCanvas resourceUri="res-1"
71
71
  pdfUrl={mockPdfUrl}
72
72
  drawingMode={null}
73
73
  />
@@ -83,7 +83,7 @@ describe('PdfAnnotationCanvas', () => {
83
83
 
84
84
  test('previous button is disabled on first page', async () => {
85
85
  render(
86
- <PdfAnnotationCanvas
86
+ <PdfAnnotationCanvas resourceUri="res-1"
87
87
  pdfUrl={mockPdfUrl}
88
88
  drawingMode={null}
89
89
  />
@@ -99,7 +99,7 @@ describe('PdfAnnotationCanvas', () => {
99
99
 
100
100
  test('next button is disabled on last page', async () => {
101
101
  render(
102
- <PdfAnnotationCanvas
102
+ <PdfAnnotationCanvas resourceUri="res-1"
103
103
  pdfUrl={mockPdfUrl}
104
104
  drawingMode={null}
105
105
  />
@@ -144,7 +144,7 @@ describe('PdfAnnotationCanvas', () => {
144
144
  ];
145
145
 
146
146
  render(
147
- <PdfAnnotationCanvas
147
+ <PdfAnnotationCanvas resourceUri="res-1"
148
148
  pdfUrl={mockPdfUrl}
149
149
  existingAnnotations={mockAnnotations}
150
150
  drawingMode={null}
@@ -179,7 +179,7 @@ describe('PdfAnnotationCanvas', () => {
179
179
 
180
180
  test('accepts a drawing gesture without throwing when drawing mode is active', async () => {
181
181
  render(
182
- <PdfAnnotationCanvas
182
+ <PdfAnnotationCanvas resourceUri="res-1"
183
183
  pdfUrl={mockPdfUrl}
184
184
  drawingMode="rectangle"
185
185
  selectedMotivation="highlighting"