@bevel-software/platform-core-frontend 0.28.0 → 0.29.0

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 (59) hide show
  1. package/package.json +11 -4
  2. package/src/core/CoreAppShell.tsx +29 -11
  3. package/src/core/__tests__/ShellRoutes.test.tsx +43 -1
  4. package/src/core/events.ts +4 -2
  5. package/src/core/registry.ts +25 -3
  6. package/src/modules/embed/__tests__/EmbedView.test.tsx +560 -17
  7. package/src/modules/embed/__tests__/embed-config.test.ts +77 -1
  8. package/src/modules/embed/__tests__/mcp-app-view.test.ts +203 -1
  9. package/src/modules/embed/components/EmbedView.tsx +233 -47
  10. package/src/modules/embed/embed-config.ts +126 -2
  11. package/src/modules/embed/embed-host.ts +11 -2
  12. package/src/modules/embed/mount.tsx +1 -0
  13. package/src/modules/library/__tests__/LibraryRoutes.test.tsx +213 -4
  14. package/src/modules/library/__tests__/PluginPage.test.tsx +1 -1
  15. package/src/modules/library/__tests__/SkillPage.test.tsx +10 -0
  16. package/src/modules/library/components/LibraryLayout.tsx +2 -2
  17. package/src/modules/library/components/PluginPage.tsx +2 -1
  18. package/src/modules/library/components/skill-page/SkillPage.tsx +2 -2
  19. package/src/modules/library/components/tool-page/ToolPage.tsx +1 -1
  20. package/src/modules/library/index.ts +18 -0
  21. package/src/modules/library/routes/LibraryRoutes.tsx +17 -1
  22. package/src/modules/library/routes/library-paths.ts +16 -2
  23. package/src/modules/onboarding/__tests__/get-started-column.test.tsx +3 -3
  24. package/src/modules/secrets-vault/components/ConnectToolsPage.tsx +39 -32
  25. package/src/modules/secrets-vault/components/SecretsPage.tsx +9 -24
  26. package/src/modules/secrets-vault/components/__tests__/ConnectToolsPage.test.tsx +111 -8
  27. package/src/modules/secrets-vault/components/__tests__/connect-lists-what-the-banner-counted.test.tsx +1 -1
  28. package/src/modules/secrets-vault/index.ts +7 -0
  29. package/src/modules/settings/settings-nav-items.tsx +3 -3
  30. package/src/modules/toolbar/commands/__tests__/actions.test.tsx +20 -37
  31. package/src/modules/toolbar/commands/actions.tsx +62 -50
  32. package/src/modules/toolbar/commands/command-menu.ts +37 -3
  33. package/src/modules/toolbar/commands/useCommandShortcuts.ts +29 -76
  34. package/src/modules/toolbar/components/ExternalAgentAccessPage.tsx +4 -2
  35. package/src/modules/toolbar/components/SearchPalette.tsx +20 -21
  36. package/src/modules/toolbar/components/__tests__/ExternalAgentAccessPage.test.tsx +5 -2
  37. package/src/modules/toolbar/components/__tests__/SearchPalette.test.tsx +242 -103
  38. package/src/modules/toolbar/components/__tests__/Toolbar.test.tsx +51 -1
  39. package/src/modules/toolbar/search/__tests__/rank.test.ts +7 -3
  40. package/src/modules/workflow/hooks/__tests__/useFileLock.test.tsx +475 -0
  41. package/src/modules/workflow/hooks/__tests__/useFileLock.wire.test.tsx +115 -0
  42. package/src/modules/workflow/hooks/useFileLock.ts +321 -57
  43. package/src/modules/workflow/index.ts +8 -0
  44. package/src/modules/workflow/services/__tests__/lock.api.test.ts +4 -0
  45. package/src/modules/workflow/services/lock.api.ts +28 -9
  46. package/src/modules/workspace/components/FileViewer.tsx +30 -16
  47. package/src/modules/workspace/components/KbPageHeader.tsx +8 -1
  48. package/src/modules/workspace/components/__tests__/FileViewer.test.tsx +107 -4
  49. package/src/modules/workspace/components/__tests__/KbPageHeader.test.tsx +12 -0
  50. package/src/modules/workspace/components/renderers/HtmlRenderer.tsx +118 -13
  51. package/src/modules/workspace/components/renderers/__tests__/HtmlRenderer.test.tsx +189 -0
  52. package/src/modules/workspace/components/renderers/__tests__/htmlSandbox.test.ts +9 -0
  53. package/src/modules/workspace/components/renderers/__tests__/kbGraphLoader.test.tsx +60 -0
  54. package/src/modules/workspace/components/renderers/frameResizeHandle.ts +116 -0
  55. package/src/modules/workspace/components/renderers/index.ts +6 -0
  56. package/src/modules/workspace/components/renderers/kbGraphLoader.ts +27 -0
  57. package/src/modules/workspace/components/renderers/lazyRenderer.tsx +1 -1
  58. package/src/modules/workspace/components/renderers/rendererSurface.ts +19 -0
  59. package/src/modules/workspace/index.ts +33 -0
@@ -0,0 +1,189 @@
1
+ import { afterEach, describe, expect, it } from 'vitest';
2
+ import { cleanup, fireEvent, render, screen, waitFor } from '@testing-library/react';
3
+ import { MemoryRouter } from 'react-router-dom';
4
+ import { RendererSurfaceContext, getFileRenderer, type RendererSurface } from '..';
5
+
6
+ /** The renderer the module hands out for an `.html` page — the way the app and the embed get it. */
7
+ const HtmlRenderer = getFileRenderer('Pages/Board.html');
8
+
9
+ /** A surface outside the app, with only what the HTML view reads of it. */
10
+ function surface(extra: Partial<RendererSurface>): RendererSurface {
11
+ return {
12
+ kbDirName: 'knowledge-base',
13
+ openLink: () => undefined,
14
+ openWorkspacePath: () => undefined,
15
+ openNodeId: () => undefined,
16
+ canonicalUrlFor: () => null,
17
+ rawUrl: (path) => `/raw/${path}`,
18
+ rawFetch: async () => new Response(''),
19
+ offersDownload: false,
20
+ ...extra,
21
+ };
22
+ }
23
+
24
+ function page(s: RendererSurface, content: string) {
25
+ return (
26
+ <MemoryRouter>
27
+ <RendererSurfaceContext.Provider value={s}>
28
+ <HtmlRenderer content={content} filePath="Pages/Board.html" onSave={async () => undefined} readOnly />
29
+ </RendererSurfaceContext.Provider>
30
+ </MemoryRouter>
31
+ );
32
+ }
33
+
34
+ function mount(s: RendererSurface, content = '<h1>Board</h1>') {
35
+ return render(page(s, content));
36
+ }
37
+
38
+ /** The frame once the preview is built. */
39
+ async function frameOf(container: HTMLElement): Promise<HTMLIFrameElement> {
40
+ return waitFor(() => {
41
+ const el = container.querySelector('iframe');
42
+ if (!el) throw new Error('no frame yet');
43
+ return el;
44
+ });
45
+ }
46
+
47
+ const STORED = 'bevel.htmlFrame.height';
48
+
49
+ /** The handle under the frame. */
50
+ const handle = () => screen.getByRole('separator', { name: 'Resize the page' });
51
+
52
+ /** A drag of the handle by `dy`, as the pointer reports it. */
53
+ function drag(dy: number) {
54
+ const el = handle();
55
+ fireEvent.pointerDown(el, { button: 0, clientY: 100, pointerId: 1 });
56
+ fireEvent.pointerMove(el, { clientY: 100 + dy, pointerId: 1 });
57
+ fireEvent.pointerUp(el, { clientY: 100 + dy, pointerId: 1 });
58
+ }
59
+
60
+ describe('HtmlRenderer on a surface', () => {
61
+ afterEach(() => {
62
+ cleanup();
63
+ window.localStorage.removeItem(STORED);
64
+ });
65
+
66
+ it('gives its frame the standard height, as a content box, with a handle to resize it, where the host grows with the content', async () => {
67
+ const { container } = mount(surface({ sizesToContent: true }));
68
+ const iframe = await frameOf(container);
69
+ expect(iframe.className).toContain('shrink-0');
70
+ expect(iframe.className).not.toContain('flex-1');
71
+ // The content box, so the page's viewport is exactly the height and the
72
+ // border is not taken out of it.
73
+ expect(iframe.style.height).toBe('480px');
74
+ expect(iframe.style.boxSizing).toBe('content-box');
75
+ expect(handle().getAttribute('aria-valuenow')).toBe('480');
76
+ expect(handle().getAttribute('aria-valuemin')).toBe('160');
77
+ expect(handle().getAttribute('aria-valuemax')).toBe('2400');
78
+ // A finger on the handle is a resize, never a scroll of the page.
79
+ expect(handle().style.touchAction).toBe('none');
80
+ });
81
+
82
+ it('the reader drags the handle to make the frame taller or shorter, and the choice is kept in this browser', async () => {
83
+ const { container, unmount } = mount(surface({ sizesToContent: true }));
84
+ const iframe = await frameOf(container);
85
+ const el = handle();
86
+ fireEvent.pointerDown(el, { button: 0, clientY: 100, pointerId: 1 });
87
+ // While the drag lasts the frame takes no pointer, so the drag can cross it.
88
+ fireEvent.pointerMove(el, { clientY: 160, pointerId: 1 });
89
+ await waitFor(() => expect(iframe.style.height).toBe('540px'));
90
+ expect(el.getAttribute('data-dragging')).toBe('true');
91
+ expect(iframe.style.pointerEvents).toBe('none');
92
+ fireEvent.pointerMove(el, { clientY: 220, pointerId: 1 });
93
+ fireEvent.pointerUp(el, { clientY: 220, pointerId: 1 });
94
+ await waitFor(() => expect(iframe.style.height).toBe('600px'));
95
+ expect(el.hasAttribute('data-dragging')).toBe(false);
96
+ expect(iframe.style.pointerEvents).toBe('');
97
+ expect(window.localStorage.getItem(STORED)).toBe('600');
98
+
99
+ // Shorter, and never below the least: a page is still a page at 160.
100
+ drag(-1000);
101
+ await waitFor(() => expect(iframe.style.height).toBe('160px'));
102
+ expect(window.localStorage.getItem(STORED)).toBe('160');
103
+ // Taller, and never past the most: the range the handle announces.
104
+ drag(10_000);
105
+ await waitFor(() => expect(iframe.style.height).toBe('2400px'));
106
+ expect(handle().getAttribute('aria-valuenow')).toBe('2400');
107
+ drag(-1000);
108
+ await waitFor(() => expect(iframe.style.height).toBe('1400px'));
109
+
110
+ // The next frame in this browser starts where this one was left.
111
+ unmount();
112
+ const again = mount(surface({ sizesToContent: true }));
113
+ expect((await frameOf(again.container)).style.height).toBe('1400px');
114
+
115
+ // A stored height outside the range is not believed.
116
+ again.unmount();
117
+ window.localStorage.setItem(STORED, '99999');
118
+ const standard = mount(surface({ sizesToContent: true }));
119
+ expect((await frameOf(standard.container)).style.height).toBe('480px');
120
+ });
121
+
122
+ it('a preview rebuilt mid-drag ends the drag where it is: nothing left dragging, the height kept', async () => {
123
+ const s = surface({ sizesToContent: true });
124
+ const { container, rerender } = mount(s, '<h1>Board</h1>');
125
+ const iframe = await frameOf(container);
126
+ const el = handle();
127
+ fireEvent.pointerDown(el, { button: 0, clientY: 100, pointerId: 1 });
128
+ fireEvent.pointerMove(el, { clientY: 200, pointerId: 1 });
129
+ await waitFor(() => expect(iframe.style.height).toBe('580px'));
130
+ expect(el.getAttribute('data-dragging')).toBe('true');
131
+
132
+ // The page changes under the reader's finger: the handle is re-attached
133
+ // for the new preview, and the drag it was in the middle of is settled.
134
+ rerender(page(s, '<h1>Board</h1><p>rebuilt</p>'));
135
+ await waitFor(() => expect(handle().hasAttribute('data-dragging')).toBe(false));
136
+ const frame = container.querySelector('iframe')!;
137
+ await waitFor(() => expect(frame.style.pointerEvents).toBe(''));
138
+ expect(frame.style.height).toBe('580px');
139
+ expect(handle().getAttribute('aria-valuenow')).toBe('580');
140
+ expect(window.localStorage.getItem(STORED)).toBe('580');
141
+ });
142
+
143
+ it('a second pointer mid-drag does not take the drag over', async () => {
144
+ const { container } = mount(surface({ sizesToContent: true }));
145
+ const iframe = await frameOf(container);
146
+ const el = handle();
147
+ fireEvent.pointerDown(el, { button: 0, clientY: 100, pointerId: 1 });
148
+ fireEvent.pointerMove(el, { clientY: 150, pointerId: 1 });
149
+ await waitFor(() => expect(iframe.style.height).toBe('530px'));
150
+ // A second finger lands: ignored, so the first keeps moving the frame
151
+ // and is the one that ends the drag.
152
+ fireEvent.pointerDown(el, { button: 0, clientY: 400, pointerId: 2 });
153
+ fireEvent.pointerMove(el, { clientY: 900, pointerId: 2 });
154
+ fireEvent.pointerMove(el, { clientY: 200, pointerId: 1 });
155
+ await waitFor(() => expect(iframe.style.height).toBe('580px'));
156
+ fireEvent.pointerUp(el, { clientY: 900, pointerId: 2 });
157
+ expect(el.getAttribute('data-dragging')).toBe('true');
158
+ fireEvent.pointerUp(el, { clientY: 200, pointerId: 1 });
159
+ await waitFor(() => expect(el.hasAttribute('data-dragging')).toBe(false));
160
+ expect(window.localStorage.getItem(STORED)).toBe('580');
161
+ });
162
+
163
+ it('the arrow keys nudge the frame by a step, and a drag that is not the main button is ignored', async () => {
164
+ const { container } = mount(surface({ sizesToContent: true }));
165
+ const iframe = await frameOf(container);
166
+ fireEvent.keyDown(handle(), { key: 'ArrowDown' });
167
+ await waitFor(() => expect(iframe.style.height).toBe('504px'));
168
+ fireEvent.keyDown(handle(), { key: 'ArrowUp' });
169
+ fireEvent.keyDown(handle(), { key: 'ArrowUp' });
170
+ await waitFor(() => expect(iframe.style.height).toBe('456px'));
171
+ fireEvent.keyDown(handle(), { key: 'Enter' });
172
+ expect(iframe.style.height).toBe('456px');
173
+
174
+ const el = handle();
175
+ fireEvent.pointerDown(el, { button: 2, clientY: 100, pointerId: 2 });
176
+ fireEvent.pointerMove(el, { clientY: 300, pointerId: 2 });
177
+ fireEvent.pointerUp(el, { clientY: 300, pointerId: 2 });
178
+ await new Promise((resolve) => setTimeout(resolve, 0));
179
+ expect(iframe.style.height).toBe('456px');
180
+ });
181
+
182
+ it('keeps filling its pane, with no handle, where the host gives it one', async () => {
183
+ const { container } = mount(surface({}));
184
+ const iframe = await frameOf(container);
185
+ expect(iframe.className).toContain('flex-1');
186
+ expect(iframe.style.height).toBe('');
187
+ expect(screen.queryByRole('separator')).toBeNull();
188
+ });
189
+ });
@@ -424,6 +424,15 @@ describe('buildSandboxedHtml', () => {
424
424
  expect(out).toContain('jumpTo(href)');
425
425
  });
426
426
 
427
+ it('injects no height reporter: the frame tells its parent where a link goes, never how tall it is', () => {
428
+ // The frame's height is the reader's (`frameResizeHandle.ts`), never
429
+ // read off the page: a page laid out in the frame and measured there
430
+ // feeds the frame's height back into itself.
431
+ const out = buildSandboxedHtml({ title: 't', libModuleSources: [], bodyHtml: '' });
432
+ expect(out).not.toContain('bevel.height');
433
+ expect(out).not.toContain('ResizeObserver');
434
+ });
435
+
427
436
  // The bridge half of the one-rule promise. The sanitizer keeps a padded
428
437
  // href by reading past the padding; the bridge has to hand the parent the
429
438
  // same reading, or the resolver builds a path out of the spaces. A padded
@@ -0,0 +1,60 @@
1
+ import { describe, expect, it, vi } from 'vitest';
2
+ import { renderHook } from '@testing-library/react';
3
+ import type { ReactNode } from 'react';
4
+ import { AppRegistryContext, EMPTY_REGISTRY, type AppRegistry } from '../../../../../core/registry';
5
+ import { RendererSurfaceContext, useKbGraphLoader, type RendererSurface } from '..';
6
+
7
+ const SURFACE: RendererSurface = {
8
+ kbDirName: 'knowledge-base',
9
+ openLink: () => undefined,
10
+ openWorkspacePath: () => undefined,
11
+ openNodeId: () => undefined,
12
+ canonicalUrlFor: () => null,
13
+ rawUrl: () => '',
14
+ rawFetch: async () => new Response(),
15
+ offersDownload: false,
16
+ };
17
+
18
+ function wrap(registry: AppRegistry, surface: RendererSurface | null) {
19
+ return ({ children }: { children: ReactNode }) => (
20
+ <AppRegistryContext.Provider value={registry}>
21
+ <RendererSurfaceContext.Provider value={surface}>{children}</RendererSurfaceContext.Provider>
22
+ </AppRegistryContext.Provider>
23
+ );
24
+ }
25
+
26
+ /**
27
+ * The one place a graph-drawing renderer gets its loader: the surface's own
28
+ * on a surface, the registry's `inApp` in the app, nothing when the
29
+ * distribution registered no source.
30
+ */
31
+ describe('useKbGraphLoader', () => {
32
+ it('reads the registry source with the session in the app, where there is no surface', async () => {
33
+ const inApp = vi.fn(async (id: string) => ({ for: id }));
34
+ const inEmbed = vi.fn(async () => ({}));
35
+ const registry = { ...EMPTY_REGISTRY, kbGraphSource: { inApp, inEmbed } };
36
+ const { result } = renderHook(() => useKbGraphLoader('ws-main'), { wrapper: wrap(registry, null) });
37
+ expect(await result.current!()).toEqual({ for: 'ws-main' });
38
+ expect(inApp).toHaveBeenCalledWith('ws-main');
39
+ expect(inEmbed).not.toHaveBeenCalled();
40
+ });
41
+
42
+ it("uses the surface's loader on a surface that offers one, and nothing on one that does not", async () => {
43
+ const inApp = vi.fn(async () => ({}));
44
+ const registry = { ...EMPTY_REGISTRY, kbGraphSource: { inApp, inEmbed: async () => ({}) } };
45
+ const loadKbGraph = vi.fn(async () => ({ from: 'surface' }));
46
+ const offering = renderHook(() => useKbGraphLoader('ws-main'), { wrapper: wrap(registry, { ...SURFACE, loadKbGraph }) });
47
+ expect(await offering.result.current!()).toEqual({ from: 'surface' });
48
+ expect(inApp).not.toHaveBeenCalled();
49
+ const bare = renderHook(() => useKbGraphLoader('ws-main'), { wrapper: wrap(registry, SURFACE) });
50
+ expect(bare.result.current).toBeNull();
51
+ });
52
+
53
+ it('answers nothing when no source is registered, or no workspace is known', () => {
54
+ const none = renderHook(() => useKbGraphLoader('ws-main'), { wrapper: wrap(EMPTY_REGISTRY, null) });
55
+ expect(none.result.current).toBeNull();
56
+ const registry = { ...EMPTY_REGISTRY, kbGraphSource: { inApp: async () => ({}), inEmbed: async () => ({}) } };
57
+ const unknown = renderHook(() => useKbGraphLoader(null), { wrapper: wrap(registry, null) });
58
+ expect(unknown.result.current).toBeNull();
59
+ });
60
+ });
@@ -0,0 +1,116 @@
1
+ /**
2
+ * The handle under an HTML page's frame where the host grows with the
3
+ * content: the reader drags it to make the frame taller or shorter, or
4
+ * nudges it from the keyboard.
5
+ *
6
+ * Plain DOM, no React and no module scope: the browser suite loads this
7
+ * function's own source into a page and drives it with a real pointer, over
8
+ * a real sandboxed frame — the one thing a stand-in document cannot answer
9
+ * is whether a drag that crosses the frame keeps reaching the handle, which
10
+ * is what pointer capture is for. Anything this closes over that is not an
11
+ * argument would not travel with it.
12
+ */
13
+
14
+ /** The standard height of the frame where the host grows with the content. */
15
+ export const HTML_FRAME_STANDARD_HEIGHT = 480;
16
+ /** The least a reader can make it: enough to see that there is a page. */
17
+ export const HTML_FRAME_MIN_HEIGHT = 160;
18
+ /** The most: a tall dashboard's worth; past it the page scrolls inside. */
19
+ export const HTML_FRAME_MAX_HEIGHT = 2400;
20
+ /** One keyboard nudge, in CSS pixels. */
21
+ export const HTML_FRAME_KEY_STEP = 24;
22
+
23
+ export interface FrameResizeHandleOptions {
24
+ /** The frame's current height, read when a drag or a nudge starts. */
25
+ current: () => number;
26
+ /** Apply a height while it changes; called on every move. */
27
+ apply: (height: number) => void;
28
+ /** A height the reader settled on: the drag ended, or a key was pressed. */
29
+ settle: (height: number) => void;
30
+ /** The least height to apply. */
31
+ min: number;
32
+ /** The most. */
33
+ max: number;
34
+ /** One keyboard nudge. */
35
+ step: number;
36
+ }
37
+
38
+ /**
39
+ * Attach the drag and the keys to `handle`; returns what detaches them.
40
+ * `data-dragging` on the handle says a drag is under way, for the frame to
41
+ * stop taking the pointer meanwhile. The handle is also told to take no
42
+ * touch gesture of the browser's (`touch-action: none`) while attached: a
43
+ * finger dragging it would otherwise read as scrolling the page, and the
44
+ * browser would cancel the pointer before the resize was done.
45
+ */
46
+ export function attachFrameResizeHandle(handle: HTMLElement, options: FrameResizeHandleOptions): () => void {
47
+ let start: { y: number; height: number; pointerId: number } | null = null;
48
+
49
+ const clamp = (height: number) => Math.min(options.max, Math.max(options.min, Math.round(height)));
50
+ const ownTouchAction = handle.style.touchAction;
51
+ handle.style.touchAction = 'none';
52
+
53
+ const onPointerDown = (event: PointerEvent) => {
54
+ // One drag at a time, by the main button: a second finger or a second
55
+ // button mid-drag must not take the drag over, or the first pointer's
56
+ // moves would be ignored and the wrong one would end it.
57
+ if (start || event.button !== 0) return;
58
+ start = { y: event.clientY, height: options.current(), pointerId: event.pointerId };
59
+ handle.setAttribute('data-dragging', 'true');
60
+ // Capture: the pointer will cross the frame below, which would otherwise
61
+ // take every event from then on — a frame is its own document.
62
+ if (typeof handle.setPointerCapture === 'function') handle.setPointerCapture(event.pointerId);
63
+ event.preventDefault();
64
+ };
65
+ const onPointerMove = (event: PointerEvent) => {
66
+ if (!start || event.pointerId !== start.pointerId) return;
67
+ options.apply(clamp(start.height + (event.clientY - start.y)));
68
+ };
69
+ /** Let the pointer go and clear the drag's marks; the drag's height is the caller's to settle. */
70
+ const letGo = (pointerId: number) => {
71
+ start = null;
72
+ handle.removeAttribute('data-dragging');
73
+ if (typeof handle.releasePointerCapture === 'function') {
74
+ try {
75
+ handle.releasePointerCapture(pointerId);
76
+ } catch {
77
+ // Already released with the pointer; nothing to let go of.
78
+ }
79
+ }
80
+ };
81
+ const end = (event: PointerEvent) => {
82
+ if (!start || event.pointerId !== start.pointerId) return;
83
+ const height = clamp(start.height + (event.clientY - start.y));
84
+ letGo(event.pointerId);
85
+ options.settle(height);
86
+ };
87
+ const onKeyDown = (event: KeyboardEvent) => {
88
+ const direction = event.key === 'ArrowDown' ? 1 : event.key === 'ArrowUp' ? -1 : 0;
89
+ if (direction === 0) return;
90
+ event.preventDefault();
91
+ options.settle(clamp(options.current() + direction * options.step));
92
+ };
93
+
94
+ handle.addEventListener('pointerdown', onPointerDown);
95
+ handle.addEventListener('pointermove', onPointerMove);
96
+ handle.addEventListener('pointerup', end);
97
+ handle.addEventListener('pointercancel', end);
98
+ handle.addEventListener('keydown', onKeyDown);
99
+ return () => {
100
+ // Detached mid-drag (the preview was rebuilt under the reader's finger):
101
+ // the drag ends where it is, settled at the height it had reached, so
102
+ // the caller's dragging state and the frame's pointer-events are not
103
+ // left as they were in the middle of it.
104
+ if (start) {
105
+ const height = clamp(options.current());
106
+ letGo(start.pointerId);
107
+ options.settle(height);
108
+ }
109
+ handle.style.touchAction = ownTouchAction;
110
+ handle.removeEventListener('pointerdown', onPointerDown);
111
+ handle.removeEventListener('pointermove', onPointerMove);
112
+ handle.removeEventListener('pointerup', end);
113
+ handle.removeEventListener('pointercancel', end);
114
+ handle.removeEventListener('keydown', onKeyDown);
115
+ };
116
+ }
@@ -16,6 +16,12 @@ export {
16
16
  useRendererFileRef,
17
17
  type RendererFileRef,
18
18
  } from './rendererWorkspace';
19
+ // A surface that mounts these renderers outside the app (the embed) and
20
+ // what a renderer asks of it: the one door for both, so a surface is built
21
+ // and a renderer is tested through this module's entry, never its files.
22
+ export { RendererSurfaceContext, useRendererSurface, type RendererRawRead, type RendererSurface } from './rendererSurface';
23
+ export { CanDownloadContext } from './DownloadFileButton';
24
+ export { useKbGraphLoader } from './kbGraphLoader';
19
25
 
20
26
  /**
21
27
  * The document viewers are code-split: their parsers (xlsx ~141 KB gzip,
@@ -0,0 +1,27 @@
1
+ import { useMemo } from 'react';
2
+ import { useAppRegistry } from '../../../../core/registry';
3
+ import { useRendererSurface } from './rendererSurface';
4
+
5
+ /**
6
+ * How a renderer that draws the knowledge graph (a dashboard's HTML) loads
7
+ * it on the surface it is mounted on — the ONE place both answers live:
8
+ *
9
+ * - On a surface that offers the graph (the embed, which reads it with its
10
+ * token), the surface's own loader.
11
+ * - In the app, where there is no surface by design, the registry's source
12
+ * read with the reader's session for `workspaceId`.
13
+ *
14
+ * Null when the distribution registered no graph source at all; the renderer
15
+ * then draws its "open this in the app" fallback. The renderer never picks
16
+ * an address itself, so the same one draws inside an issue panel or a chat
17
+ * as it draws in the app. See `AppRegistry.kbGraphSource`.
18
+ */
19
+ export function useKbGraphLoader(workspaceId: string | null): (() => Promise<unknown>) | null {
20
+ const surface = useRendererSurface();
21
+ const source = useAppRegistry().kbGraphSource;
22
+ return useMemo(() => {
23
+ if (surface) return surface.loadKbGraph ?? null;
24
+ if (!source || !workspaceId) return null;
25
+ return () => source.inApp(workspaceId);
26
+ }, [surface, source, workspaceId]);
27
+ }
@@ -7,7 +7,7 @@ import type { FileRendererProps } from './types';
7
7
  * bundle. Measured from a production build: xlsx (141 KB gzip), mammoth
8
8
  * (119 KB) and mermaid's eager core (151 KB) are 411 KB gzip — 43% of a
9
9
  * 964 KB payload — for file types most sessions never open. Every route paid
10
- * that, including `/connect` and `/secrets`, which are the pages users land
10
+ * that, including Connect your tools and `/secrets`, which are the pages users land
11
11
  * on returning from an external OAuth sign-in.
12
12
  *
13
13
  * The lazy component is self-contained: it carries its own Suspense fallback
@@ -67,6 +67,25 @@ export interface RendererSurface {
67
67
  * page perfectly fine. There is simply no download here.
68
68
  */
69
69
  offersDownload: boolean;
70
+ /**
71
+ * The knowledge graph as this surface's viewer may see it, for a renderer
72
+ * that draws it (a dashboard's HTML). Absent when the distribution
73
+ * registers no graph source (`AppRegistry.kbGraphSource`), and the
74
+ * renderer then draws its "open this in the app" fallback. The app reads
75
+ * it with the session, the embed with its token; the renderer never
76
+ * chooses an address itself — it asks `useKbGraphLoader`, which answers
77
+ * from here on a surface and from the registry's source in the app.
78
+ */
79
+ loadKbGraph?: () => Promise<unknown>;
80
+ /**
81
+ * Whether this surface's host grows with the content rather than giving
82
+ * the page a fixed pane to scroll in. A renderer that draws inside its own
83
+ * frame (the sandboxed HTML view) has no pane to fill there, so where this
84
+ * is true it gives its frame a standard height the reader can drag taller
85
+ * or shorter, and the host follows the frame; where it is false or absent,
86
+ * the frame fills its pane and scrolls inside it as it does in the app.
87
+ */
88
+ sizesToContent?: boolean;
70
89
  }
71
90
 
72
91
  export const RendererSurfaceContext = createContext<RendererSurface | null>(null);
@@ -0,0 +1,33 @@
1
+ /**
2
+ * Workspace's public surface for other modules: what it takes to mount the
3
+ * app's own renderer for a file somewhere other than the file page. The
4
+ * embed (a page shown inside a chat) does exactly that, and imports these
5
+ * from here rather than reaching into workspace's components.
6
+ *
7
+ * - `pickFileRenderer` and `isViewOnlyFile`: the same lookup the file page
8
+ * runs, registered renderers included, and whether the file has an
9
+ * editing surface behind it at all.
10
+ * - `RendererSurfaceContext` and `RendererSurface`: where a renderer reads
11
+ * bytes from and how its links leave, when there is no workspace around
12
+ * it (see `rendererSurface.ts` for why it is this narrow).
13
+ * - `RendererWorkspaceContext`: the workspace a renderer believes it reads
14
+ * from, where there is none to dial.
15
+ * - `CanDownloadContext`: whether a renderer may offer Download.
16
+ * - `useRendererSurface` and `useKbGraphLoader`: what a renderer mounted
17
+ * there reads its surroundings with, for a renderer a distribution
18
+ * registers (and for a stand-in one in a test).
19
+ * - `kbFileUrl` and `resolveKbHref`: the app's address for a file on a
20
+ * branch, and what a link in a page resolves to there, which a link out
21
+ * of such a mount has to name.
22
+ */
23
+ export {
24
+ CanDownloadContext,
25
+ isViewOnlyFile,
26
+ pickFileRenderer,
27
+ RendererSurfaceContext,
28
+ useKbGraphLoader,
29
+ useRendererSurface,
30
+ type RendererSurface,
31
+ } from './components/renderers';
32
+ export { RendererWorkspaceContext } from './components/renderers/rendererWorkspace';
33
+ export { kbFileUrl, resolveKbHref } from './routing/kb-routes';