@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.
- package/package.json +11 -4
- package/src/core/CoreAppShell.tsx +29 -11
- package/src/core/__tests__/ShellRoutes.test.tsx +43 -1
- package/src/core/events.ts +4 -2
- package/src/core/registry.ts +25 -3
- package/src/modules/embed/__tests__/EmbedView.test.tsx +560 -17
- package/src/modules/embed/__tests__/embed-config.test.ts +77 -1
- package/src/modules/embed/__tests__/mcp-app-view.test.ts +203 -1
- package/src/modules/embed/components/EmbedView.tsx +233 -47
- package/src/modules/embed/embed-config.ts +126 -2
- package/src/modules/embed/embed-host.ts +11 -2
- package/src/modules/embed/mount.tsx +1 -0
- package/src/modules/library/__tests__/LibraryRoutes.test.tsx +213 -4
- package/src/modules/library/__tests__/PluginPage.test.tsx +1 -1
- package/src/modules/library/__tests__/SkillPage.test.tsx +10 -0
- package/src/modules/library/components/LibraryLayout.tsx +2 -2
- package/src/modules/library/components/PluginPage.tsx +2 -1
- package/src/modules/library/components/skill-page/SkillPage.tsx +2 -2
- package/src/modules/library/components/tool-page/ToolPage.tsx +1 -1
- package/src/modules/library/index.ts +18 -0
- package/src/modules/library/routes/LibraryRoutes.tsx +17 -1
- package/src/modules/library/routes/library-paths.ts +16 -2
- package/src/modules/onboarding/__tests__/get-started-column.test.tsx +3 -3
- package/src/modules/secrets-vault/components/ConnectToolsPage.tsx +39 -32
- package/src/modules/secrets-vault/components/SecretsPage.tsx +9 -24
- package/src/modules/secrets-vault/components/__tests__/ConnectToolsPage.test.tsx +111 -8
- package/src/modules/secrets-vault/components/__tests__/connect-lists-what-the-banner-counted.test.tsx +1 -1
- package/src/modules/secrets-vault/index.ts +7 -0
- package/src/modules/settings/settings-nav-items.tsx +3 -3
- package/src/modules/toolbar/commands/__tests__/actions.test.tsx +20 -37
- package/src/modules/toolbar/commands/actions.tsx +62 -50
- package/src/modules/toolbar/commands/command-menu.ts +37 -3
- package/src/modules/toolbar/commands/useCommandShortcuts.ts +29 -76
- package/src/modules/toolbar/components/ExternalAgentAccessPage.tsx +4 -2
- package/src/modules/toolbar/components/SearchPalette.tsx +20 -21
- package/src/modules/toolbar/components/__tests__/ExternalAgentAccessPage.test.tsx +5 -2
- package/src/modules/toolbar/components/__tests__/SearchPalette.test.tsx +242 -103
- package/src/modules/toolbar/components/__tests__/Toolbar.test.tsx +51 -1
- package/src/modules/toolbar/search/__tests__/rank.test.ts +7 -3
- package/src/modules/workflow/hooks/__tests__/useFileLock.test.tsx +475 -0
- package/src/modules/workflow/hooks/__tests__/useFileLock.wire.test.tsx +115 -0
- package/src/modules/workflow/hooks/useFileLock.ts +321 -57
- package/src/modules/workflow/index.ts +8 -0
- package/src/modules/workflow/services/__tests__/lock.api.test.ts +4 -0
- package/src/modules/workflow/services/lock.api.ts +28 -9
- package/src/modules/workspace/components/FileViewer.tsx +30 -16
- package/src/modules/workspace/components/KbPageHeader.tsx +8 -1
- package/src/modules/workspace/components/__tests__/FileViewer.test.tsx +107 -4
- package/src/modules/workspace/components/__tests__/KbPageHeader.test.tsx +12 -0
- package/src/modules/workspace/components/renderers/HtmlRenderer.tsx +118 -13
- package/src/modules/workspace/components/renderers/__tests__/HtmlRenderer.test.tsx +189 -0
- package/src/modules/workspace/components/renderers/__tests__/htmlSandbox.test.ts +9 -0
- package/src/modules/workspace/components/renderers/__tests__/kbGraphLoader.test.tsx +60 -0
- package/src/modules/workspace/components/renderers/frameResizeHandle.ts +116 -0
- package/src/modules/workspace/components/renderers/index.ts +6 -0
- package/src/modules/workspace/components/renderers/kbGraphLoader.ts +27 -0
- package/src/modules/workspace/components/renderers/lazyRenderer.tsx +1 -1
- package/src/modules/workspace/components/renderers/rendererSurface.ts +19 -0
- package/src/modules/workspace/index.ts +33 -0
|
@@ -28,8 +28,7 @@ import {
|
|
|
28
28
|
type OpenComparisonDetail,
|
|
29
29
|
} from '../../../core/events';
|
|
30
30
|
import { useAppRegistry } from '../../../core/registry';
|
|
31
|
-
import { useFileLock } from '../../workflow
|
|
32
|
-
import { LockApiError } from '../../workflow/services/lock.api';
|
|
31
|
+
import { LockApiError, SELF_HOLD_MESSAGE, useFileLock } from '../../workflow';
|
|
33
32
|
import { useAuth } from '../../auth/state/auth.context';
|
|
34
33
|
import {
|
|
35
34
|
knowledgeSuggestionBranchFor,
|
|
@@ -448,10 +447,11 @@ export function FileViewer() {
|
|
|
448
447
|
// already been re-set to true by the Edit click — and the naive
|
|
449
448
|
// mirror would revert editMode back to false. To avoid that, Done
|
|
450
449
|
// stamps `lastDoneAtRef`; the mirror ignores transitions that fall
|
|
451
|
-
// within a short window after Done (longer than a typical
|
|
452
|
-
//
|
|
453
|
-
// running >`DONE_RELEASE_WINDOW_MS` would be
|
|
454
|
-
// worst-case outcome is one extra Edit click to
|
|
450
|
+
// within a short window after Done (longer than a typical save-and-
|
|
451
|
+
// release round-trip on a normal network; the server queues the commit
|
|
452
|
+
// itself — Done's release running >`DONE_RELEASE_WINDOW_MS` would be
|
|
453
|
+
// exceptional, and the worst-case outcome is one extra Edit click to
|
|
454
|
+
// recover).
|
|
455
455
|
const wasHoldingLockRef = useRef(false);
|
|
456
456
|
const lastDoneAtRef = useRef(0);
|
|
457
457
|
const DONE_RELEASE_WINDOW_MS = 5_000;
|
|
@@ -665,8 +665,9 @@ export function FileViewer() {
|
|
|
665
665
|
|
|
666
666
|
const handleExitEditMode = useCallback(() => {
|
|
667
667
|
if (!editMode) return;
|
|
668
|
-
// Flip to View mode SYNCHRONOUSLY. The
|
|
669
|
-
// `saveAndRelease` runs
|
|
668
|
+
// Flip to View mode SYNCHRONOUSLY. The save and release that
|
|
669
|
+
// `saveAndRelease` runs are two network round-trips (the server then
|
|
670
|
+
// queues the commit of what is on disk; nothing waits on git here),
|
|
670
671
|
// and we don't want the user staring at a frozen "Done" button
|
|
671
672
|
// waiting for the network — they explicitly asked to leave edit
|
|
672
673
|
// mode, the UI should respect that immediately.
|
|
@@ -857,8 +858,9 @@ export function FileViewer() {
|
|
|
857
858
|
// - Lock is already held because we're in edit mode (handleEnterEditMode
|
|
858
859
|
// guarantees it). Save = checkpoint commit, lock stays held so
|
|
859
860
|
// subsequent keystrokes don't have to re-acquire.
|
|
860
|
-
// -
|
|
861
|
-
// or `IDLE_RELEASE_MS` of inactivity (the hook's idle
|
|
861
|
+
// - The final write + release happens on exit-edit, unmount, file
|
|
862
|
+
// switch, or `IDLE_RELEASE_MS` of inactivity (the hook's idle
|
|
863
|
+
// timer); the server queues the commit of what is on disk.
|
|
862
864
|
const handleSave = useCallback(async (content: string) => {
|
|
863
865
|
if (!openFilePath) return;
|
|
864
866
|
openFileContentRef.current = content;
|
|
@@ -866,12 +868,12 @@ export function FileViewer() {
|
|
|
866
868
|
// Defensive: this path runs when a save fires without us being in
|
|
867
869
|
// edit mode (rare — renderer is readOnly when !editMode, so
|
|
868
870
|
// normally only the explicit Edit-button + saveCheckpoint flow
|
|
869
|
-
// reaches here). Acquire the lock,
|
|
871
|
+
// reaches here). Acquire the lock, save-and-release as a
|
|
870
872
|
// one-shot, and stay in View mode. We deliberately do NOT call
|
|
871
873
|
// `setEditMode(true)` — the user didn't ask to enter Edit mode,
|
|
872
874
|
// they just hit save, so the UI shouldn't silently promote them.
|
|
873
|
-
// `saveAndRelease`
|
|
874
|
-
//
|
|
875
|
+
// `saveAndRelease` writes the buffer and releases the hold in one
|
|
876
|
+
// call; the server queues the commit of what is on disk.
|
|
875
877
|
const { acquired, error } = await fileLock.acquire();
|
|
876
878
|
if (!acquired) {
|
|
877
879
|
// Read the message off the resolved outcome, not `fileLock.lockError`
|
|
@@ -1255,6 +1257,9 @@ export function FileViewer() {
|
|
|
1255
1257
|
// rule). While a mode is OPEN it shows the way out instead. The header's
|
|
1256
1258
|
// own cluster is suppressed for prose files (`writeActionInPane`).
|
|
1257
1259
|
const lockedBy = fileLock.externalLock?.holderName ?? null;
|
|
1260
|
+
// The hold is the viewer's own (another tab, a closed browser whose hold
|
|
1261
|
+
// has not expired, their agent): say so, never name them as someone else.
|
|
1262
|
+
const lockedByYou = fileLock.externalLockIsMine;
|
|
1258
1263
|
const writeAction = isReviewingPending || viewOnly ? null : proposeMode ? (
|
|
1259
1264
|
<>
|
|
1260
1265
|
<Button variant="quiet" size="tiny" onClick={handleDiscardProposal} disabled={proposalBusy}>
|
|
@@ -1301,7 +1306,7 @@ export function FileViewer() {
|
|
|
1301
1306
|
onClick={handleEnterEditMode}
|
|
1302
1307
|
title={
|
|
1303
1308
|
lockedBy
|
|
1304
|
-
? `${lockedBy} is editing this page`
|
|
1309
|
+
? lockedByYou ? SELF_HOLD_MESSAGE : `${lockedBy} is editing this page`
|
|
1305
1310
|
: isEnteringEdit
|
|
1306
1311
|
? 'Getting the latest version…'
|
|
1307
1312
|
: 'Click to edit this file'
|
|
@@ -1388,6 +1393,7 @@ export function FileViewer() {
|
|
|
1388
1393
|
historyButtonRef={headerClockRef}
|
|
1389
1394
|
titleRef={titleRef}
|
|
1390
1395
|
lockedBy={fileLock.externalLock?.holderName ?? null}
|
|
1396
|
+
lockedByYou={fileLock.externalLockIsMine}
|
|
1391
1397
|
historyAvailable={historyAvailable}
|
|
1392
1398
|
isDirty={isManualDirty}
|
|
1393
1399
|
waitingOnAgentUpdate={waitingOnAgentUpdate}
|
|
@@ -1559,7 +1565,9 @@ export function FileViewer() {
|
|
|
1559
1565
|
</Banner>
|
|
1560
1566
|
)}
|
|
1561
1567
|
|
|
1562
|
-
{/*
|
|
1568
|
+
{/* Held-page banner — read-only state until the holder releases or
|
|
1569
|
+
the hold expires (the hook clears it either way). A hold under
|
|
1570
|
+
the viewer's own id says so instead of naming them. */}
|
|
1563
1571
|
{fileLock.externalLock && !fileLock.holdingLock && !isReviewingPending && !onProtectedBranch && (
|
|
1564
1572
|
<Banner
|
|
1565
1573
|
role="status"
|
|
@@ -1569,7 +1577,13 @@ export function FileViewer() {
|
|
|
1569
1577
|
aria-atomic="true"
|
|
1570
1578
|
className="mb-4 flex-none"
|
|
1571
1579
|
>
|
|
1572
|
-
|
|
1580
|
+
{fileLock.externalLockIsMine ? (
|
|
1581
|
+
SELF_HOLD_MESSAGE
|
|
1582
|
+
) : (
|
|
1583
|
+
<>
|
|
1584
|
+
<span className="font-medium">{fileLock.externalLock.holderName}</span> is editing this page. You can edit it when they finish.
|
|
1585
|
+
</>
|
|
1586
|
+
)}
|
|
1573
1587
|
</Banner>
|
|
1574
1588
|
)}
|
|
1575
1589
|
|
|
@@ -17,6 +17,7 @@ import { useDismissableMenu } from '../../../shared/components';
|
|
|
17
17
|
import { HEADER_BAND, PAGE_HEADER_TESTID } from '../../../shared/theme/header';
|
|
18
18
|
import { rootAnchoredPath } from '../utils/pasteLink';
|
|
19
19
|
import { displayFileName, fileNameTooltip } from '../utils/display-file-name';
|
|
20
|
+
import { SELF_HOLD_MESSAGE } from '../../workflow';
|
|
20
21
|
|
|
21
22
|
/**
|
|
22
23
|
* The document's title, and the page's actions beside it.
|
|
@@ -102,6 +103,11 @@ export interface KbPageHeaderProps {
|
|
|
102
103
|
titleRef?: Ref<HTMLHeadingElement>;
|
|
103
104
|
/** Disables Edit and explains why via `title`. */
|
|
104
105
|
lockedBy: string | null;
|
|
106
|
+
/**
|
|
107
|
+
* The hold behind `lockedBy` is the viewer's own (another tab, their
|
|
108
|
+
* agent): the title says so instead of naming them as someone else.
|
|
109
|
+
*/
|
|
110
|
+
lockedByYou?: boolean;
|
|
105
111
|
historyAvailable: boolean;
|
|
106
112
|
/** → "Unsaved" badge. */
|
|
107
113
|
isDirty: boolean;
|
|
@@ -164,6 +170,7 @@ export function KbPageHeader({
|
|
|
164
170
|
historyButtonRef,
|
|
165
171
|
titleRef,
|
|
166
172
|
lockedBy,
|
|
173
|
+
lockedByYou = false,
|
|
167
174
|
historyAvailable,
|
|
168
175
|
isDirty,
|
|
169
176
|
waitingOnAgentUpdate,
|
|
@@ -427,7 +434,7 @@ export function KbPageHeader({
|
|
|
427
434
|
disabled={!!lockedBy || entering}
|
|
428
435
|
title={
|
|
429
436
|
lockedBy
|
|
430
|
-
? `${lockedBy} is editing this page`
|
|
437
|
+
? lockedByYou ? SELF_HOLD_MESSAGE : `${lockedBy} is editing this page`
|
|
431
438
|
: entering
|
|
432
439
|
? 'Getting the latest version…'
|
|
433
440
|
: 'Click to edit this file'
|
|
@@ -38,7 +38,9 @@ vi.mock('../../../access/api', () => ({
|
|
|
38
38
|
// real endpoints. In these tests we just need the acquire to succeed so the
|
|
39
39
|
// save flow can finish; lock contention paths are exercised in lock-specific
|
|
40
40
|
// tests, not here.
|
|
41
|
-
vi.mock('../../../workflow/services/lock.api', () => ({
|
|
41
|
+
vi.mock('../../../workflow/services/lock.api', async (importOriginal) => ({
|
|
42
|
+
// The sentences (SELF_HOLD_MESSAGE, EDITING_ENDED_MESSAGE) stay real.
|
|
43
|
+
...(await importOriginal<typeof import('../../../workflow/services/lock.api')>()),
|
|
42
44
|
acquireLock: vi.fn(async () => ({
|
|
43
45
|
acquired: true,
|
|
44
46
|
lock: {
|
|
@@ -53,7 +55,7 @@ vi.mock('../../../workflow/services/lock.api', () => ({
|
|
|
53
55
|
})),
|
|
54
56
|
heartbeatLock: vi.fn(async () => ({})),
|
|
55
57
|
checkpointLockedFile: vi.fn(async () => null),
|
|
56
|
-
releaseLock: vi.fn(async () =>
|
|
58
|
+
releaseLock: vi.fn(async (): Promise<void> => {}),
|
|
57
59
|
getLock: vi.fn(async () => null),
|
|
58
60
|
LockApiError: class LockApiError extends Error {
|
|
59
61
|
readonly status: number;
|
|
@@ -140,7 +142,13 @@ vi.mock('../../../onboarding/services/starter-packs.api', async (importOriginal)
|
|
|
140
142
|
import { FileViewer } from '../FileViewer';
|
|
141
143
|
// The lock API is mocked above; import the mocked fns so individual tests can
|
|
142
144
|
// override the acquire outcome (e.g. a 403 on enter-edit).
|
|
143
|
-
import {
|
|
145
|
+
import {
|
|
146
|
+
acquireLock as acquireLockMock,
|
|
147
|
+
getLock as getLockMock,
|
|
148
|
+
releaseLock as releaseLockMock,
|
|
149
|
+
LockApiError,
|
|
150
|
+
SELF_HOLD_MESSAGE,
|
|
151
|
+
} from '../../../workflow/services/lock.api';
|
|
144
152
|
import { WorkspaceContext, type WorkspaceContextValue } from '../../state/workspace.context';
|
|
145
153
|
import { GitContext, type GitContextValue } from '../../../git/state/git.context';
|
|
146
154
|
import { ReviewContext, type ReviewContextValue } from '../../../review/state/review.context';
|
|
@@ -222,6 +230,7 @@ function ViewerHarness({
|
|
|
222
230
|
routeState,
|
|
223
231
|
routePath,
|
|
224
232
|
workspaceBranch = 'main',
|
|
233
|
+
onSaveFile,
|
|
225
234
|
}: {
|
|
226
235
|
initialContent?: string;
|
|
227
236
|
/** What git reports about itself; the history views need `'ready'`. */
|
|
@@ -260,6 +269,8 @@ function ViewerHarness({
|
|
|
260
269
|
routePath?: string;
|
|
261
270
|
/** The branch the workspace is on, as the workspace state reports it. */
|
|
262
271
|
workspaceBranch?: string | null;
|
|
272
|
+
/** Observes every write the viewer asks the workspace to make. */
|
|
273
|
+
onSaveFile?: (relativePath: string, content: string) => void;
|
|
263
274
|
}) {
|
|
264
275
|
const [openFileContent, setOpenFileContent] = useState(initialContent);
|
|
265
276
|
const [savedContent, setSavedContent] = useState(initialContent);
|
|
@@ -324,7 +335,8 @@ function ViewerHarness({
|
|
|
324
335
|
clearUploadError: () => {},
|
|
325
336
|
deleteEntry: async () => {},
|
|
326
337
|
moveEntry: async () => {},
|
|
327
|
-
saveFile: async (
|
|
338
|
+
saveFile: async (relativePath: string, content: string) => {
|
|
339
|
+
onSaveFile?.(relativePath, content);
|
|
328
340
|
setOpenFileContent(content);
|
|
329
341
|
setSavedContent(content);
|
|
330
342
|
},
|
|
@@ -749,6 +761,97 @@ describe('FileViewer', () => {
|
|
|
749
761
|
expect(screen.getByRole('button', { name: 'Edit' })).toHaveAttribute('title', 'Dana Lee is editing this page');
|
|
750
762
|
});
|
|
751
763
|
|
|
764
|
+
// The hold is the viewer's own — another tab, a closed browser whose hold
|
|
765
|
+
// has not expired yet, their agent saving. Clicking Edit says so, never
|
|
766
|
+
// "<their own name> is editing this page", and once the hold is gone the
|
|
767
|
+
// notice leaves by itself and Edit works without a reload.
|
|
768
|
+
it('says a page held by the viewer is theirs, and gives Edit back when the hold ends', async () => {
|
|
769
|
+
vi.useFakeTimers({ shouldAdvanceTime: true });
|
|
770
|
+
try {
|
|
771
|
+
vi.mocked(acquireLockMock).mockResolvedValueOnce({
|
|
772
|
+
acquired: false,
|
|
773
|
+
lock: {
|
|
774
|
+
branch: 'alice/draft',
|
|
775
|
+
path: 'knowledge-base/Knowledge/Foo.md',
|
|
776
|
+
holderUserId: 'u-juan',
|
|
777
|
+
holderName: 'Juan V.',
|
|
778
|
+
acquiredAt: new Date().toISOString(),
|
|
779
|
+
lastHeartbeatAt: new Date().toISOString(),
|
|
780
|
+
expiresAt: new Date(Date.now() + 10_000).toISOString(),
|
|
781
|
+
},
|
|
782
|
+
});
|
|
783
|
+
const user = userEvent.setup({ advanceTimers: vi.advanceTimersByTime });
|
|
784
|
+
render(
|
|
785
|
+
<ViewerHarness
|
|
786
|
+
initialContent="Base content"
|
|
787
|
+
authUser={{ id: 'u-juan', email: 'juan@example.com', name: 'Juan V.' }}
|
|
788
|
+
/>,
|
|
789
|
+
);
|
|
790
|
+
|
|
791
|
+
await user.click(await screen.findByRole('button', { name: 'Edit' }));
|
|
792
|
+
|
|
793
|
+
const banner = await screen.findByText(SELF_HOLD_MESSAGE);
|
|
794
|
+
expect(banner).toHaveTextContent(
|
|
795
|
+
'You have this page open for editing somewhere else, in another tab or through your agent. You can edit it here in a moment.',
|
|
796
|
+
);
|
|
797
|
+
expect(screen.queryByText(/Juan V\./)).not.toBeInTheDocument();
|
|
798
|
+
expect(screen.queryByText(/is editing this page/)).not.toBeInTheDocument();
|
|
799
|
+
const edit = screen.getByRole('button', { name: 'Edit' });
|
|
800
|
+
expect(edit).toBeDisabled();
|
|
801
|
+
expect(edit).toHaveAttribute('title', SELF_HOLD_MESSAGE);
|
|
802
|
+
|
|
803
|
+
// The hold expires; the re-check finds the page free.
|
|
804
|
+
vi.mocked(getLockMock).mockResolvedValue(null);
|
|
805
|
+
await act(async () => { await vi.advanceTimersByTimeAsync(11_500); });
|
|
806
|
+
|
|
807
|
+
await waitFor(() => expect(screen.queryByText(SELF_HOLD_MESSAGE)).not.toBeInTheDocument());
|
|
808
|
+
expect(screen.getByRole('button', { name: 'Edit' })).toBeEnabled();
|
|
809
|
+
} finally {
|
|
810
|
+
vi.useRealTimers();
|
|
811
|
+
}
|
|
812
|
+
});
|
|
813
|
+
|
|
814
|
+
// Closing a tab mid-edit: the browser still warns while there is unsaved
|
|
815
|
+
// text (the page's `beforeunload` guard), and a clean editor does not
|
|
816
|
+
// warn. Once the person accepts and the page goes (`pagehide`), the hold
|
|
817
|
+
// is released at once with a keep-alive request, and the unsaved text is
|
|
818
|
+
// not written on the way out.
|
|
819
|
+
it('warns before closing a tab with unsaved text, then gives the page back without saving it', async () => {
|
|
820
|
+
const user = userEvent.setup();
|
|
821
|
+
const saved: string[] = [];
|
|
822
|
+
render(
|
|
823
|
+
<ViewerHarness
|
|
824
|
+
initialContent="Base content"
|
|
825
|
+
captureTyped
|
|
826
|
+
onSaveFile={(_path, content) => saved.push(content)}
|
|
827
|
+
/>,
|
|
828
|
+
);
|
|
829
|
+
await user.click(await screen.findByRole('button', { name: 'Edit' }));
|
|
830
|
+
const textarea = await screen.findByRole('textbox');
|
|
831
|
+
|
|
832
|
+
const tryToClose = () => {
|
|
833
|
+
const event = new Event('beforeunload', { cancelable: true });
|
|
834
|
+
window.dispatchEvent(event);
|
|
835
|
+
return event.defaultPrevented;
|
|
836
|
+
};
|
|
837
|
+
// Nothing typed yet: the tab closes without a warning.
|
|
838
|
+
expect(tryToClose()).toBe(false);
|
|
839
|
+
|
|
840
|
+
await user.type(textarea, ' and a new line');
|
|
841
|
+
// Unsaved text: the browser asks first, as today.
|
|
842
|
+
await waitFor(() => expect(tryToClose()).toBe(true));
|
|
843
|
+
|
|
844
|
+
vi.mocked(releaseLockMock).mockClear();
|
|
845
|
+
await act(async () => { window.dispatchEvent(new Event('pagehide')); });
|
|
846
|
+
|
|
847
|
+
expect(releaseLockMock).toHaveBeenCalledTimes(1);
|
|
848
|
+
expect(releaseLockMock).toHaveBeenCalledWith(
|
|
849
|
+
'ws-1', 'alice/draft', 'knowledge-base/Knowledge/Foo.md', undefined, { keepalive: true },
|
|
850
|
+
);
|
|
851
|
+
// No write of the unsaved text happened on the way out.
|
|
852
|
+
expect(saved).toEqual([]);
|
|
853
|
+
});
|
|
854
|
+
|
|
752
855
|
// WP1 regression. The document column moved: the viewer pane used to be
|
|
753
856
|
// `overflow-hidden` with a per-renderer scroller, and `editorContainerRef`
|
|
754
857
|
// sat on that pane. It now sits on `KbDocumentShell`, which is what actually
|
|
@@ -117,6 +117,18 @@ describe('KbPageHeader', () => {
|
|
|
117
117
|
expect(edit).toHaveAttribute('title', 'Ali Raza is editing this page');
|
|
118
118
|
});
|
|
119
119
|
|
|
120
|
+
// A hold under the viewer's own id (another tab, their agent) is not
|
|
121
|
+
// "someone else": the title says it is theirs and never names them.
|
|
122
|
+
it('disables Edit for the viewer\'s own hold without naming them', () => {
|
|
123
|
+
renderHeader({ lockedBy: 'Juan V.', lockedByYou: true });
|
|
124
|
+
const edit = screen.getByRole('button', { name: 'Edit' });
|
|
125
|
+
expect(edit).toBeDisabled();
|
|
126
|
+
expect(edit).toHaveAttribute(
|
|
127
|
+
'title',
|
|
128
|
+
'You have this page open for editing somewhere else, in another tab or through your agent. You can edit it here in a moment.',
|
|
129
|
+
);
|
|
130
|
+
});
|
|
131
|
+
|
|
120
132
|
it('swaps Edit for Done in edit mode', () => {
|
|
121
133
|
renderHeader({ editMode: true });
|
|
122
134
|
expect(screen.queryByRole('button', { name: 'Edit' })).not.toBeInTheDocument();
|
|
@@ -3,6 +3,40 @@ import { Pencil, Eye, RotateCw } from 'lucide-react';
|
|
|
3
3
|
import { useFileNav } from '../../routing/kb-routes';
|
|
4
4
|
import type { FileRendererProps, RendererSaveState } from './types';
|
|
5
5
|
import { buildSandboxedHtml, sanitizeAgentHtml } from './htmlSandbox';
|
|
6
|
+
import { useRendererSurface } from './rendererSurface';
|
|
7
|
+
import {
|
|
8
|
+
HTML_FRAME_KEY_STEP,
|
|
9
|
+
HTML_FRAME_MAX_HEIGHT,
|
|
10
|
+
HTML_FRAME_MIN_HEIGHT,
|
|
11
|
+
HTML_FRAME_STANDARD_HEIGHT,
|
|
12
|
+
attachFrameResizeHandle,
|
|
13
|
+
} from './frameResizeHandle';
|
|
14
|
+
|
|
15
|
+
/**
|
|
16
|
+
* Where the reader's chosen frame height is kept, per browser: a
|
|
17
|
+
* convenience, like a remembered tab. A browser that cannot store it is
|
|
18
|
+
* asked nothing and shows the standard height each time.
|
|
19
|
+
*/
|
|
20
|
+
const FRAME_HEIGHT_KEY = 'bevel.htmlFrame.height';
|
|
21
|
+
|
|
22
|
+
function rememberedFrameHeight(): number {
|
|
23
|
+
try {
|
|
24
|
+
const stored = Number(window.localStorage.getItem(FRAME_HEIGHT_KEY));
|
|
25
|
+
return Number.isFinite(stored) && stored >= HTML_FRAME_MIN_HEIGHT && stored <= HTML_FRAME_MAX_HEIGHT
|
|
26
|
+
? Math.round(stored)
|
|
27
|
+
: HTML_FRAME_STANDARD_HEIGHT;
|
|
28
|
+
} catch {
|
|
29
|
+
return HTML_FRAME_STANDARD_HEIGHT;
|
|
30
|
+
}
|
|
31
|
+
}
|
|
32
|
+
|
|
33
|
+
function rememberFrameHeight(height: number): void {
|
|
34
|
+
try {
|
|
35
|
+
window.localStorage.setItem(FRAME_HEIGHT_KEY, String(height));
|
|
36
|
+
} catch {
|
|
37
|
+
// Not stored: the standard height next time, which is no worse than today.
|
|
38
|
+
}
|
|
39
|
+
}
|
|
6
40
|
|
|
7
41
|
export function HtmlRenderer({
|
|
8
42
|
content,
|
|
@@ -15,7 +49,21 @@ export function HtmlRenderer({
|
|
|
15
49
|
readOnly = false,
|
|
16
50
|
}: FileRendererProps) {
|
|
17
51
|
const { openLink } = useFileNav();
|
|
52
|
+
// Whether the surface's host grows with the page (an issue panel) rather
|
|
53
|
+
// than giving it a pane to scroll in (the app, the MCP App's pane).
|
|
54
|
+
const sizesToContent = useRendererSurface()?.sizesToContent === true;
|
|
18
55
|
const [mode, setMode] = useState<'preview' | 'edit'>('preview');
|
|
56
|
+
/**
|
|
57
|
+
* The frame's height where the host grows with the page: the standard
|
|
58
|
+
* height, or the one this reader last chose in this browser; the reader
|
|
59
|
+
* drags the handle under the frame to change it. Never derived from the
|
|
60
|
+
* page — a frame is its own document, and a height read off a page that
|
|
61
|
+
* is itself laid out in the frame feeds back into itself.
|
|
62
|
+
*/
|
|
63
|
+
const [frameHeight, setFrameHeight] = useState(() => (sizesToContent ? rememberedFrameHeight() : HTML_FRAME_STANDARD_HEIGHT));
|
|
64
|
+
const frameHeightRef = useRef(frameHeight);
|
|
65
|
+
const [dragging, setDragging] = useState(false);
|
|
66
|
+
const handleRef = useRef<HTMLDivElement | null>(null);
|
|
19
67
|
const [value, setValue] = useState(content);
|
|
20
68
|
const [savedValue, setSavedValue] = useState(savedContent ?? content);
|
|
21
69
|
const [saveState, setSaveState] = useState<RendererSaveState>('idle');
|
|
@@ -100,6 +148,34 @@ export function HtmlRenderer({
|
|
|
100
148
|
return () => window.removeEventListener('message', onNavMessage);
|
|
101
149
|
}, [openLink, filePath]);
|
|
102
150
|
|
|
151
|
+
useEffect(() => {
|
|
152
|
+
frameHeightRef.current = frameHeight;
|
|
153
|
+
}, [frameHeight]);
|
|
154
|
+
|
|
155
|
+
// The handle under the frame, where the host grows with the page: a drag
|
|
156
|
+
// or the arrow keys set the frame's height, and a height the reader
|
|
157
|
+
// settled on is remembered in this browser. Attached whenever the handle
|
|
158
|
+
// is on screen — it comes and goes with the preview.
|
|
159
|
+
useEffect(() => {
|
|
160
|
+
const handle = handleRef.current;
|
|
161
|
+
if (!sizesToContent || !handle) return;
|
|
162
|
+
return attachFrameResizeHandle(handle, {
|
|
163
|
+
current: () => frameHeightRef.current,
|
|
164
|
+
apply: (height) => {
|
|
165
|
+
setDragging(true);
|
|
166
|
+
setFrameHeight(height);
|
|
167
|
+
},
|
|
168
|
+
settle: (height) => {
|
|
169
|
+
setDragging(false);
|
|
170
|
+
setFrameHeight(height);
|
|
171
|
+
rememberFrameHeight(height);
|
|
172
|
+
},
|
|
173
|
+
min: HTML_FRAME_MIN_HEIGHT,
|
|
174
|
+
max: HTML_FRAME_MAX_HEIGHT,
|
|
175
|
+
step: HTML_FRAME_KEY_STEP,
|
|
176
|
+
});
|
|
177
|
+
}, [sizesToContent, mode, previewError, bundledSrcdoc]);
|
|
178
|
+
|
|
103
179
|
const save = useCallback(async (): Promise<boolean> => {
|
|
104
180
|
if (readOnly || value === savedValue) return true;
|
|
105
181
|
setSaveState('saving');
|
|
@@ -202,19 +278,48 @@ export function HtmlRenderer({
|
|
|
202
278
|
{previewError}
|
|
203
279
|
</div>
|
|
204
280
|
) : bundledSrcdoc ? (
|
|
205
|
-
|
|
206
|
-
|
|
207
|
-
|
|
208
|
-
|
|
209
|
-
|
|
210
|
-
|
|
211
|
-
|
|
212
|
-
|
|
213
|
-
|
|
214
|
-
|
|
215
|
-
|
|
216
|
-
|
|
217
|
-
|
|
281
|
+
<>
|
|
282
|
+
<iframe
|
|
283
|
+
key={reloadKey}
|
|
284
|
+
ref={iframeRef}
|
|
285
|
+
srcDoc={bundledSrcdoc}
|
|
286
|
+
title={filePath}
|
|
287
|
+
// `allow-scripts` only — without `allow-same-origin` the iframe's
|
|
288
|
+
// origin is opaque/null. Combined with the document's CSP
|
|
289
|
+
// (`connect-src 'none'`) and the postMessage-only data channel, the
|
|
290
|
+
// iframe cannot exfiltrate, navigate, popup, or fetch.
|
|
291
|
+
sandbox="allow-scripts"
|
|
292
|
+
referrerPolicy="no-referrer"
|
|
293
|
+
// In a pane the frame fills it and scrolls inside; where the host
|
|
294
|
+
// grows with the page, the frame has the reader's height (a
|
|
295
|
+
// flex-grown frame in an auto-height column would collapse to the
|
|
296
|
+
// browser's default 150px instead), as its CONTENT box, so the
|
|
297
|
+
// page's viewport is exactly that height and the border is not
|
|
298
|
+
// taken out of it. While the handle is dragged the frame takes no
|
|
299
|
+
// pointer — a frame is its own document, and would keep the
|
|
300
|
+
// pointer the moment it crossed in.
|
|
301
|
+
className={`w-full bg-white rounded-xs border border-line ${sizesToContent ? 'shrink-0' : 'flex-1'}`}
|
|
302
|
+
style={
|
|
303
|
+
sizesToContent
|
|
304
|
+
? { height: frameHeight, boxSizing: 'content-box', pointerEvents: dragging ? 'none' : undefined }
|
|
305
|
+
: undefined
|
|
306
|
+
}
|
|
307
|
+
/>
|
|
308
|
+
{sizesToContent && (
|
|
309
|
+
<div
|
|
310
|
+
ref={handleRef}
|
|
311
|
+
role="separator"
|
|
312
|
+
aria-orientation="horizontal"
|
|
313
|
+
aria-label="Resize the page"
|
|
314
|
+
aria-valuenow={frameHeight}
|
|
315
|
+
aria-valuemin={HTML_FRAME_MIN_HEIGHT}
|
|
316
|
+
aria-valuemax={HTML_FRAME_MAX_HEIGHT}
|
|
317
|
+
tabIndex={0}
|
|
318
|
+
title="Drag to make the page taller or shorter"
|
|
319
|
+
className="shrink-0 h-2 mt-1 rounded-xs cursor-row-resize outline-none hover:bg-hover focus-visible:bg-accent-hover/60 data-[dragging=true]:bg-accent-hover/60 transition-colors"
|
|
320
|
+
/>
|
|
321
|
+
)}
|
|
322
|
+
</>
|
|
218
323
|
) : (
|
|
219
324
|
<div className="flex items-center justify-center h-full text-ink-muted text-sm">
|
|
220
325
|
Loading preview…
|