@bevel-software/platform-core-frontend 0.31.0 → 0.33.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 +2 -2
- package/src/core/CoreAppShell.tsx +1 -1
- package/src/modules/access/api.ts +1 -1
- package/src/modules/access/components/ManageAccessDialog.tsx +4 -5
- package/src/modules/access/hooks/useAccessRequests.ts +1 -1
- package/src/modules/access/hooks/useFileAccess.ts +1 -1
- package/src/modules/access/index.ts +11 -0
- package/src/modules/access/requests.api.ts +1 -1
- package/src/modules/admin/components/AddMemberInput.tsx +1 -1
- package/src/modules/admin/components/UserAccountsPage.tsx +3 -3
- package/src/modules/admin/index.ts +7 -0
- package/src/modules/admin/state/admin.context.tsx +1 -1
- package/src/modules/audit/components/AuditEventsPanel.tsx +1 -1
- package/src/modules/audit/components/AuditLogPage.tsx +2 -2
- package/src/modules/auth/index.ts +12 -0
- package/src/modules/change-requests/__tests__/ChangeRequestDialog.access-rules.test.tsx +0 -1
- package/src/modules/change-requests/__tests__/ChangeRequestDialog.binary.test.tsx +0 -1
- package/src/modules/change-requests/__tests__/ChangeRequestDialog.brings-itself-up-to-date.test.tsx +0 -1
- package/src/modules/change-requests/__tests__/ChangeRequestDialog.edit.test.tsx +166 -0
- package/src/modules/change-requests/__tests__/ChangeRequestDialog.fork-point.test.tsx +0 -1
- package/src/modules/change-requests/__tests__/ChangeRequestDialog.initial-file.test.tsx +0 -1
- package/src/modules/change-requests/__tests__/ChangeRequestDialog.moved.test.tsx +0 -1
- package/src/modules/change-requests/__tests__/ChangeRequestDialog.sync-banner.test.tsx +0 -1
- package/src/modules/change-requests/__tests__/ChangeRequestDialog.test.tsx +0 -2
- package/src/modules/change-requests/__tests__/ChangeRequestDialog.unreadable.test.tsx +0 -1
- package/src/modules/change-requests/__tests__/apply-outcome-for-every-viewer.test.tsx +0 -1
- package/src/modules/change-requests/components/BranchFilePreview.tsx +4 -12
- package/src/modules/change-requests/components/ChangeRequestDialog.tsx +138 -30
- package/src/modules/change-requests/components/ChangeRequestLink.tsx +2 -3
- package/src/modules/change-requests/components/CrFileTree.tsx +1 -1
- package/src/modules/change-requests/components/FileChangeBoxes.tsx +2 -3
- package/src/modules/change-requests/hooks/useApplyChangeRequest.ts +3 -5
- package/src/modules/change-requests/hooks/useCrFileDiffs.ts +1 -1
- package/src/modules/change-requests/index.ts +14 -0
- package/src/modules/change-requests/services/change-requests.api.ts +2 -2
- package/src/modules/change-requests/services/denied-file.api.ts +2 -2
- package/src/modules/change-requests/services/propose.api.ts +3 -4
- package/src/modules/change-requests/utils/diff.ts +1 -1
- package/src/modules/change-requests/utils/readFailure.ts +1 -1
- package/src/modules/embed/__tests__/EmbedView.test.tsx +19 -2
- package/src/modules/embed/components/EmbedLinkPage.tsx +1 -2
- package/src/modules/git/components/BranchSwitcher.tsx +3 -4
- package/src/modules/git/components/FileHistoryPanel.tsx +2 -2
- package/src/modules/git/components/GitSyncFailedBanner.tsx +2 -4
- package/src/modules/git/components/HistoryVersionPreview.tsx +4 -15
- package/src/modules/git/components/PullNeededBanner.tsx +1 -1
- package/src/modules/git/hooks/useAutoPullUpdates.ts +1 -1
- package/src/modules/git/index.ts +11 -0
- package/src/modules/layout/components/MobileChatLayout.tsx +1 -1
- package/src/modules/layout/index.ts +9 -0
- package/src/modules/library/__tests__/SkillPage.test.tsx +39 -0
- package/src/modules/library/__tests__/propose-change.test.ts +75 -0
- package/src/modules/library/components/AddToPluginDialog.tsx +1 -1
- package/src/modules/library/components/ChangeRequestDock.tsx +1 -1
- package/src/modules/library/components/LibraryLayout.tsx +2 -2
- package/src/modules/library/components/LibraryPage.tsx +3 -3
- package/src/modules/library/components/ManagedPluginRequests.tsx +1 -1
- package/src/modules/library/components/NewSkillPanel.tsx +2 -2
- package/src/modules/library/components/PersonalAddDialog.tsx +1 -1
- package/src/modules/library/components/PersonalPluginPage.tsx +1 -1
- package/src/modules/library/components/PluginExtras.tsx +1 -4
- package/src/modules/library/components/PluginPage.tsx +1 -1
- package/src/modules/library/components/PluginRows.tsx +1 -1
- package/src/modules/library/components/SkillsTree.tsx +1 -4
- package/src/modules/library/components/plugin-page-parts.tsx +1 -1
- package/src/modules/library/components/skill-page/SkillFilePane.tsx +19 -7
- package/src/modules/library/components/skill-page/SkillPage.tsx +19 -26
- package/src/modules/library/components/tool-page/ToolConnectionSection.tsx +2 -4
- package/src/modules/library/components/tool-page/ToolVarRow.tsx +2 -2
- package/src/modules/library/hooks/useJoinRequests.ts +1 -1
- package/src/modules/library/hooks/useLibraryData.ts +3 -3
- package/src/modules/library/hooks/useToolPage.ts +1 -1
- package/src/modules/library/hooks/useToolSource.ts +1 -1
- package/src/modules/library/index.ts +12 -0
- package/src/modules/library/routes/LibraryRoutes.tsx +1 -1
- package/src/modules/library/routes/WorkspaceItemRoute.tsx +1 -3
- package/src/modules/library/routes/library-paths.ts +1 -1
- package/src/modules/library/services/library.api.ts +10 -8
- package/src/modules/library/services/plugins.api.ts +1 -1
- package/src/modules/library/services/teams.api.ts +1 -1
- package/src/modules/library/utils/status.ts +2 -2
- package/src/modules/onboarding/components/ConnectAgentPill.tsx +1 -1
- package/src/modules/onboarding/components/CreatorWelcomePage.tsx +2 -3
- package/src/modules/onboarding/components/GetStartedColumn.tsx +6 -13
- package/src/modules/onboarding/components/InviteButton.tsx +2 -2
- package/src/modules/onboarding/components/InviteDialog.tsx +4 -6
- package/src/modules/onboarding/components/RootLanding.tsx +2 -2
- package/src/modules/onboarding/components/StarterPackCard.tsx +1 -1
- package/src/modules/onboarding/components/WelcomePage.tsx +2 -5
- package/src/modules/onboarding/index.ts +10 -0
- package/src/modules/onboarding/paths.ts +1 -1
- package/src/modules/onboarding/state/agent-connection.ts +2 -2
- package/src/modules/onboarding/state/onboarding.ts +1 -1
- package/src/modules/onboarding/state/starter-packs.ts +1 -1
- package/src/modules/pr/components/OpenChangeRequestDialog.tsx +1 -1
- package/src/modules/pr/index.ts +14 -0
- package/src/modules/pr/services/pr-approvals.api.ts +1 -1
- package/src/modules/pr/services/pr-cancel.api.ts +1 -1
- package/src/modules/pr/services/pr-detail.api.ts +2 -2
- package/src/modules/pr/services/pr-edit.api.ts +22 -0
- package/src/modules/pr/services/pr-merge.api.ts +1 -1
- package/src/modules/pr/services/pr-open.api.ts +1 -1
- package/src/modules/review/components/DiffViewer.tsx +1 -1
- package/src/modules/review/components/MarkdownDiffViewer.tsx +1 -2
- package/src/modules/review/components/ReviewPanel.tsx +2 -3
- package/src/modules/review/state/ReviewProvider.tsx +2 -2
- package/src/modules/secrets-vault/index.ts +6 -0
- package/src/modules/settings/components/DeploymentPage.tsx +2 -2
- package/src/modules/settings/components/SettingsLayout.tsx +2 -2
- package/src/modules/settings/index.ts +8 -0
- package/src/modules/setup/components/FirstRunStorage.tsx +1 -1
- package/src/modules/setup/index.ts +6 -0
- package/src/modules/toolbar/commands/actions.tsx +3 -3
- package/src/modules/toolbar/commands/useCommandActions.ts +5 -9
- package/src/modules/toolbar/components/AgentInstructionsCard.tsx +2 -2
- package/src/modules/toolbar/components/AppSwitcher.tsx +1 -2
- package/src/modules/toolbar/components/CoworkSetupSteps.tsx +1 -1
- package/src/modules/toolbar/components/ExternalAgentAccessPage.tsx +1 -1
- package/src/modules/toolbar/components/ProfileMenu.tsx +3 -3
- package/src/modules/toolbar/components/SearchPalette.tsx +4 -8
- package/src/modules/toolbar/components/Toolbar.tsx +2 -5
- package/src/modules/toolbar/index.ts +6 -0
- package/src/modules/toolbar/search/sources.ts +4 -7
- package/src/modules/toolbar/services/agent-instructions.api.ts +1 -1
- package/src/modules/tools/ToolsExplorerPage.tsx +217 -18
- package/src/modules/tools/__tests__/ToolsExplorerPage.read-only.test.tsx +220 -0
- package/src/modules/tools/tool-hints.api.ts +44 -0
- package/src/modules/workflow/index.ts +7 -0
- package/src/modules/workflow/state/ChangeRequestStaleBinder.tsx +1 -0
- package/src/modules/workflow/state/EventBusFocusBinder.tsx +1 -1
- package/src/modules/workspace/components/FileExplorer.tsx +35 -8
- package/src/modules/workspace/components/FilePaneCard.tsx +37 -12
- package/src/modules/workspace/components/FileRoute.tsx +10 -3
- package/src/modules/workspace/components/FileViewer.tsx +169 -25
- package/src/modules/workspace/components/FullScreenView.tsx +93 -0
- package/src/modules/workspace/components/KbFileRail.tsx +1 -1
- package/src/modules/workspace/components/KbPageHeader.tsx +9 -0
- package/src/modules/workspace/components/__tests__/FileExplorer.test.tsx +137 -0
- package/src/modules/workspace/components/__tests__/FileRoute.test.tsx +11 -0
- package/src/modules/workspace/components/__tests__/FileViewer.test.tsx +487 -3
- package/src/modules/workspace/components/readingCarry.ts +59 -0
- package/src/modules/workspace/components/renderers/HtmlRenderer.tsx +36 -175
- package/src/modules/workspace/components/renderers/ToolRenderer.tsx +1 -1
- package/src/modules/workspace/components/renderers/__tests__/HtmlRenderer.tools.test.tsx +168 -42
- package/src/modules/workspace/components/renderers/__tests__/bridgeHarness.ts +20 -3
- package/src/modules/workspace/components/renderers/__tests__/htmlSandbox.test.ts +63 -4
- package/src/modules/workspace/components/renderers/__tests__/htmlToolBridge.test.ts +235 -1
- package/src/modules/workspace/components/renderers/__tests__/htmlViewsGuide.test.ts +14 -3
- package/src/modules/workspace/components/renderers/__tests__/pageToolsHarness.ts +79 -0
- package/src/modules/workspace/components/renderers/__tests__/useHtmlToolBridge.test.tsx +316 -0
- package/src/modules/workspace/components/renderers/htmlSandbox.ts +75 -13
- package/src/modules/workspace/components/renderers/htmlToolBridge.ts +196 -25
- package/src/modules/workspace/components/renderers/index.ts +10 -0
- package/src/modules/workspace/components/renderers/useHtmlToolBridge.tsx +253 -0
- package/src/modules/workspace/hooks/useFullScreenView.ts +52 -0
- package/src/modules/workspace/hooks/useImageRevision.ts +1 -1
- package/src/modules/workspace/hooks/useKnowledgeWriteTarget.ts +1 -1
- package/src/modules/workspace/hooks/useLastCommit.ts +1 -1
- package/src/modules/workspace/hooks/useWorkspaceState.ts +4 -4
- package/src/modules/workspace/index.ts +30 -1
- package/src/modules/workspace/routing/kb-routes.ts +1 -1
- package/src/modules/workspace/state/__tests__/applied-request-clears-pending.test.tsx +0 -1
- package/src/modules/workspace/state/open-change-requests.tsx +1 -1
- package/src/modules/workspace/utils/frameEscape.ts +15 -0
- package/src/modules/workspace/utils/treeConfirm.ts +1 -1
- package/src/shared/theme/measure.ts +7 -0
- package/src/modules/pr/services/pr-comments.api.ts +0 -45
|
@@ -1,7 +1,7 @@
|
|
|
1
1
|
import { describe, it, expect, vi, afterEach } from 'vitest';
|
|
2
2
|
import { render, screen, waitFor, act, within } from '@testing-library/react';
|
|
3
3
|
import userEvent from '@testing-library/user-event';
|
|
4
|
-
import { MemoryRouter, Routes, Route, useLocation } from 'react-router-dom';
|
|
4
|
+
import { MemoryRouter, Routes, Route, useLocation, useNavigationType } from 'react-router-dom';
|
|
5
5
|
import { useEffect, useState } from 'react';
|
|
6
6
|
import { PAGE_HEADER_TESTID } from '../../../../shared/theme/header';
|
|
7
7
|
import type {
|
|
@@ -155,6 +155,9 @@ import { ReviewContext, type ReviewContextValue } from '../../../review/state/re
|
|
|
155
155
|
import { AuthContext, type AuthContextValue } from '../../../auth/state/auth.context';
|
|
156
156
|
import { OpenChangeRequestsContext } from '../../state/open-change-requests.context';
|
|
157
157
|
import { OPEN_COMPARISON_EVENT } from '../../../../core/events';
|
|
158
|
+
import { AppRegistryContext, makeRegistry, type FileRendererDef } from '../../../../core/registry';
|
|
159
|
+
import { Dialog } from '../../../../shared/components';
|
|
160
|
+
import type { FileRendererProps } from '../renderers';
|
|
158
161
|
|
|
159
162
|
let injectPendingFromTest: ((value?: string) => void) | null = null;
|
|
160
163
|
|
|
@@ -206,9 +209,12 @@ function makeGit(
|
|
|
206
209
|
*/
|
|
207
210
|
function LocationEcho() {
|
|
208
211
|
const location = useLocation();
|
|
212
|
+
const navigationType = useNavigationType();
|
|
209
213
|
return (
|
|
210
214
|
<>
|
|
211
215
|
<div data-testid="location">{location.pathname}</div>
|
|
216
|
+
<div data-testid="location-search">{location.search}</div>
|
|
217
|
+
<div data-testid="navigation-type">{navigationType}</div>
|
|
212
218
|
<div data-testid="location-state">{JSON.stringify(location.state ?? null)}</div>
|
|
213
219
|
</>
|
|
214
220
|
);
|
|
@@ -231,6 +237,8 @@ function ViewerHarness({
|
|
|
231
237
|
routePath,
|
|
232
238
|
workspaceBranch = 'main',
|
|
233
239
|
onSaveFile,
|
|
240
|
+
routeSearch,
|
|
241
|
+
renderers,
|
|
234
242
|
}: {
|
|
235
243
|
initialContent?: string;
|
|
236
244
|
/** What git reports about itself; the history views need `'ready'`. */
|
|
@@ -271,6 +279,10 @@ function ViewerHarness({
|
|
|
271
279
|
workspaceBranch?: string | null;
|
|
272
280
|
/** Observes every write the viewer asks the workspace to make. */
|
|
273
281
|
onSaveFile?: (relativePath: string, content: string) => void;
|
|
282
|
+
/** The query the entry opens with, e.g. `?fullscreen=1`. */
|
|
283
|
+
routeSearch?: string;
|
|
284
|
+
/** Renderers a deployment registers, as the enterprise overlay's `.html` one. */
|
|
285
|
+
renderers?: FileRendererDef[];
|
|
274
286
|
}) {
|
|
275
287
|
const [openFileContent, setOpenFileContent] = useState(initialContent);
|
|
276
288
|
const [savedContent, setSavedContent] = useState(initialContent);
|
|
@@ -413,10 +425,16 @@ function ViewerHarness({
|
|
|
413
425
|
</WorkspaceContext.Provider>
|
|
414
426
|
</AuthContext.Provider>
|
|
415
427
|
);
|
|
416
|
-
|
|
428
|
+
const routed = (
|
|
417
429
|
<MemoryRouter
|
|
418
430
|
initialEntries={[
|
|
419
|
-
|
|
431
|
+
routeSearch !== undefined
|
|
432
|
+
? {
|
|
433
|
+
pathname: `/workspace/${encodeURIComponent(urlBranch)}`,
|
|
434
|
+
search: routeSearch,
|
|
435
|
+
state: routeState ?? null,
|
|
436
|
+
}
|
|
437
|
+
: routeState !== undefined || routePath !== undefined
|
|
420
438
|
? {
|
|
421
439
|
pathname: `/workspace/${encodeURIComponent(urlBranch)}/${(routePath ?? filePath ?? '')
|
|
422
440
|
.split('/')
|
|
@@ -432,6 +450,11 @@ function ViewerHarness({
|
|
|
432
450
|
</Routes>
|
|
433
451
|
</MemoryRouter>
|
|
434
452
|
);
|
|
453
|
+
return renderers ? (
|
|
454
|
+
<AppRegistryContext.Provider value={makeRegistry({ renderers })}>{routed}</AppRegistryContext.Provider>
|
|
455
|
+
) : (
|
|
456
|
+
routed
|
|
457
|
+
);
|
|
435
458
|
}
|
|
436
459
|
|
|
437
460
|
describe('FileViewer', () => {
|
|
@@ -1980,3 +2003,464 @@ describe('FileViewer: opening straight into the editor', () => {
|
|
|
1980
2003
|
expect(acquireLockMock).not.toHaveBeenCalled();
|
|
1981
2004
|
});
|
|
1982
2005
|
});
|
|
2006
|
+
|
|
2007
|
+
// ── Full screen ───────────────────────────────────────────────────────────
|
|
2008
|
+
// The view is the host's: a renderer registered by a deployment (the
|
|
2009
|
+
// enterprise overlay's `.html` one) gets it without knowing it exists, so
|
|
2010
|
+
// every case below runs through registry stubs that know nothing about it.
|
|
2011
|
+
describe('FileViewer full screen', () => {
|
|
2012
|
+
const mounts = { count: 0 };
|
|
2013
|
+
|
|
2014
|
+
/** A renderer with its own state, that counts its mounts. */
|
|
2015
|
+
function CountingRenderer({ onSave, readOnly }: FileRendererProps) {
|
|
2016
|
+
const [scratch, setScratch] = useState('');
|
|
2017
|
+
const [dialogOpen, setDialogOpen] = useState(false);
|
|
2018
|
+
useEffect(() => {
|
|
2019
|
+
mounts.count += 1;
|
|
2020
|
+
}, []);
|
|
2021
|
+
return (
|
|
2022
|
+
<div data-testid="stub-renderer">
|
|
2023
|
+
<input aria-label="Scratch" value={scratch} onChange={(e) => setScratch(e.target.value)} />
|
|
2024
|
+
<button type="button" onClick={() => void onSave(`saved:${scratch}`)} disabled={readOnly}>
|
|
2025
|
+
Stub save
|
|
2026
|
+
</button>
|
|
2027
|
+
<button type="button" onClick={() => setDialogOpen(true)}>
|
|
2028
|
+
Open stub dialog
|
|
2029
|
+
</button>
|
|
2030
|
+
<Dialog open={dialogOpen} onClose={() => setDialogOpen(false)} title="Stub dialog">
|
|
2031
|
+
A dialog over the view
|
|
2032
|
+
</Dialog>
|
|
2033
|
+
<iframe title="Stub page" />
|
|
2034
|
+
</div>
|
|
2035
|
+
);
|
|
2036
|
+
}
|
|
2037
|
+
|
|
2038
|
+
const stubFor = (...extensions: string[]): FileRendererDef[] => [
|
|
2039
|
+
{ extensions, Component: CountingRenderer },
|
|
2040
|
+
];
|
|
2041
|
+
|
|
2042
|
+
afterEach(() => {
|
|
2043
|
+
mounts.count = 0;
|
|
2044
|
+
});
|
|
2045
|
+
|
|
2046
|
+
const readPane = () => screen.getByTestId('stub-renderer').closest('[data-read-pane]') as HTMLElement;
|
|
2047
|
+
const header = () => screen.getByTestId(PAGE_HEADER_TESTID);
|
|
2048
|
+
const paneCard = () => screen.queryByTestId('file-pane-card');
|
|
2049
|
+
|
|
2050
|
+
it.each([
|
|
2051
|
+
['Markdown', 'knowledge-base/Knowledge/Foo.md'],
|
|
2052
|
+
['text', 'knowledge-base/Knowledge/notes.txt'],
|
|
2053
|
+
])('offers Full screen in the pane bar for a prose file (%s)', async (_kind, filePath) => {
|
|
2054
|
+
render(<ViewerHarness filePath={filePath} renderers={stubFor('.md', '.txt')} />);
|
|
2055
|
+
const card = await screen.findByTestId('file-pane-card');
|
|
2056
|
+
expect(within(card).getByRole('button', { name: 'Full screen' })).toBeInTheDocument();
|
|
2057
|
+
expect(within(header()).queryByRole('button', { name: 'Full screen' })).toBeNull();
|
|
2058
|
+
});
|
|
2059
|
+
|
|
2060
|
+
it.each([
|
|
2061
|
+
['HTML', 'knowledge-base/Dashboards/Roadmap.html'],
|
|
2062
|
+
['PDF', 'knowledge-base/Docs/Guide.pdf'],
|
|
2063
|
+
['tool', 'knowledge-base/Tools/search.tool'],
|
|
2064
|
+
['spreadsheet', 'knowledge-base/Data/Sheet.xlsx'],
|
|
2065
|
+
['CSV', 'knowledge-base/Data/rows.csv'],
|
|
2066
|
+
['image', 'knowledge-base/Assets/diagram.png'],
|
|
2067
|
+
])('offers Full screen in the page header for a full-bleed file (%s)', async (_kind, filePath) => {
|
|
2068
|
+
render(
|
|
2069
|
+
<ViewerHarness
|
|
2070
|
+
filePath={filePath}
|
|
2071
|
+
renderers={stubFor('.html', '.pdf', '.tool', '.xlsx', '.csv', '.png')}
|
|
2072
|
+
/>,
|
|
2073
|
+
);
|
|
2074
|
+
await screen.findByTestId('stub-renderer');
|
|
2075
|
+
expect(within(header()).getByRole('button', { name: 'Full screen' })).toBeInTheDocument();
|
|
2076
|
+
expect(paneCard()).toBeNull();
|
|
2077
|
+
expect(screen.getAllByRole('button', { name: 'Full screen' })).toHaveLength(1);
|
|
2078
|
+
});
|
|
2079
|
+
|
|
2080
|
+
it('offers Full screen in edit mode too', async () => {
|
|
2081
|
+
const user = userEvent.setup();
|
|
2082
|
+
render(<ViewerHarness />);
|
|
2083
|
+
await user.click(await screen.findByRole('button', { name: 'Edit' }));
|
|
2084
|
+
await screen.findByRole('button', { name: 'Done' });
|
|
2085
|
+
expect(within(screen.getByTestId('file-pane-card')).getByRole('button', { name: 'Full screen' })).toBeInTheDocument();
|
|
2086
|
+
});
|
|
2087
|
+
|
|
2088
|
+
it('enters by replacing the entry with ?fullscreen=1, and leaves by taking it off again', async () => {
|
|
2089
|
+
const user = userEvent.setup();
|
|
2090
|
+
render(<ViewerHarness filePath="knowledge-base/Dashboards/Roadmap.html" renderers={stubFor('.html')} />);
|
|
2091
|
+
await screen.findByTestId('stub-renderer');
|
|
2092
|
+
expect(screen.getByTestId('location-search').textContent).toBe('');
|
|
2093
|
+
|
|
2094
|
+
await user.click(screen.getByRole('button', { name: 'Full screen' }));
|
|
2095
|
+
expect(screen.getByTestId('location-search').textContent).toBe('?fullscreen=1');
|
|
2096
|
+
expect(screen.getByTestId('navigation-type').textContent).toBe('REPLACE');
|
|
2097
|
+
expect(readPane()).toHaveAttribute('data-full-screen');
|
|
2098
|
+
expect(readPane()).toHaveClass('fixed', 'inset-0', 'z-40', 'bg-canvas');
|
|
2099
|
+
// The entry control gives way to the exit control.
|
|
2100
|
+
expect(screen.queryByRole('button', { name: 'Full screen' })).toBeNull();
|
|
2101
|
+
|
|
2102
|
+
await user.click(screen.getByRole('button', { name: 'Exit full screen' }));
|
|
2103
|
+
expect(screen.getByTestId('location-search').textContent).toBe('');
|
|
2104
|
+
expect(screen.getByTestId('navigation-type').textContent).toBe('REPLACE');
|
|
2105
|
+
expect(readPane()).not.toHaveAttribute('data-full-screen');
|
|
2106
|
+
expect(readPane()).not.toHaveClass('fixed');
|
|
2107
|
+
expect(screen.getByRole('button', { name: 'Full screen' })).toBeInTheDocument();
|
|
2108
|
+
});
|
|
2109
|
+
|
|
2110
|
+
it("gives way to an agent update that waits for the reader's answer", async () => {
|
|
2111
|
+
render(<ViewerHarness renderers={stubFor('.md')} routeSearch="?fullscreen=1" pendingValue="agent replacement" />);
|
|
2112
|
+
await screen.findByTestId('stub-renderer');
|
|
2113
|
+
expect(screen.getByRole('button', { name: 'Exit full screen' })).toBeInTheDocument();
|
|
2114
|
+
|
|
2115
|
+
await act(async () => {
|
|
2116
|
+
injectPendingFromTest?.();
|
|
2117
|
+
});
|
|
2118
|
+
|
|
2119
|
+
// Accept and Reject sit in the shell the filled view covered: the view
|
|
2120
|
+
// gives way, and the entry is taken off the URL as a manual exit would.
|
|
2121
|
+
await waitFor(() => expect(screen.queryByRole('button', { name: 'Exit full screen' })).toBeNull());
|
|
2122
|
+
expect(screen.getByTestId('location-search').textContent).toBe('');
|
|
2123
|
+
expect(await screen.findByText(/Previewing agent's changes/i)).toBeInTheDocument();
|
|
2124
|
+
});
|
|
2125
|
+
|
|
2126
|
+
it('keeps the rest of the query when it enters and leaves', async () => {
|
|
2127
|
+
const user = userEvent.setup();
|
|
2128
|
+
render(
|
|
2129
|
+
<ViewerHarness
|
|
2130
|
+
filePath="knowledge-base/Dashboards/Roadmap.html"
|
|
2131
|
+
renderers={stubFor('.html')}
|
|
2132
|
+
routeSearch="?trace=1"
|
|
2133
|
+
/>,
|
|
2134
|
+
);
|
|
2135
|
+
await screen.findByTestId('stub-renderer');
|
|
2136
|
+
await user.click(screen.getByRole('button', { name: 'Full screen' }));
|
|
2137
|
+
expect(screen.getByTestId('location-search').textContent).toBe('?trace=1&fullscreen=1');
|
|
2138
|
+
await user.click(screen.getByRole('button', { name: 'Exit full screen' }));
|
|
2139
|
+
expect(screen.getByTestId('location-search').textContent).toBe('?trace=1');
|
|
2140
|
+
});
|
|
2141
|
+
|
|
2142
|
+
it('opens filling the window when the URL carries ?fullscreen=1, from the first render', () => {
|
|
2143
|
+
render(
|
|
2144
|
+
<ViewerHarness
|
|
2145
|
+
filePath="knowledge-base/Dashboards/Roadmap.html"
|
|
2146
|
+
renderers={stubFor('.html')}
|
|
2147
|
+
routeSearch="?fullscreen=1"
|
|
2148
|
+
/>,
|
|
2149
|
+
);
|
|
2150
|
+
// No waitFor: the first commit is already the filling view, so the
|
|
2151
|
+
// app's chrome is never painted around it.
|
|
2152
|
+
expect(readPane()).toHaveAttribute('data-full-screen');
|
|
2153
|
+
expect(readPane()).toHaveClass('fixed', 'inset-0');
|
|
2154
|
+
expect(screen.getByRole('button', { name: 'Exit full screen' })).toBeInTheDocument();
|
|
2155
|
+
});
|
|
2156
|
+
|
|
2157
|
+
it('does not remount the renderer across the toggle: its state survives both ways', async () => {
|
|
2158
|
+
const user = userEvent.setup();
|
|
2159
|
+
render(<ViewerHarness renderers={stubFor('.md')} />);
|
|
2160
|
+
await screen.findByTestId('stub-renderer');
|
|
2161
|
+
await user.type(screen.getByLabelText('Scratch'), 'unsaved');
|
|
2162
|
+
expect(mounts.count).toBe(1);
|
|
2163
|
+
|
|
2164
|
+
await user.click(screen.getByRole('button', { name: 'Full screen' }));
|
|
2165
|
+
expect(readPane()).toHaveAttribute('data-full-screen');
|
|
2166
|
+
expect(screen.getByLabelText('Scratch')).toHaveValue('unsaved');
|
|
2167
|
+
|
|
2168
|
+
await user.click(screen.getByRole('button', { name: 'Exit full screen' }));
|
|
2169
|
+
expect(screen.getByLabelText('Scratch')).toHaveValue('unsaved');
|
|
2170
|
+
expect(mounts.count).toBe(1);
|
|
2171
|
+
});
|
|
2172
|
+
|
|
2173
|
+
// The pane leaving the shell's flow collapses the shell's scroll, so the
|
|
2174
|
+
// reader's place is carried by hand: into the pane's own scroller on the
|
|
2175
|
+
// way in, back into the shell's on the way out. It is measured against the
|
|
2176
|
+
// document's BODY, because the two views put a different distance above it:
|
|
2177
|
+
// on the page the body starts below the card's bar (here 144px into the
|
|
2178
|
+
// shell's content), filling the window it starts below the pane's padding
|
|
2179
|
+
// (40px). happy-dom lays nothing out, so that geometry is given.
|
|
2180
|
+
it('keeps the reader\'s place in a prose document across entry and exit, measured at the text', async () => {
|
|
2181
|
+
const user = userEvent.setup();
|
|
2182
|
+
render(<ViewerHarness renderers={stubFor('.md')} />);
|
|
2183
|
+
await screen.findByTestId('stub-renderer');
|
|
2184
|
+
const shell = screen.getByTestId('kb-document-shell');
|
|
2185
|
+
const pane = readPane();
|
|
2186
|
+
const body = pane.querySelector('[data-file-pane-body]') as HTMLElement;
|
|
2187
|
+
const BODY_ON_PAGE = 144;
|
|
2188
|
+
const BODY_FILLING = 40;
|
|
2189
|
+
const rect = (top: number) => ({ top, left: 0, right: 0, bottom: 0, width: 0, height: 0, x: 0, y: top, toJSON: () => ({}) });
|
|
2190
|
+
vi.spyOn(shell, 'getBoundingClientRect').mockImplementation(() => rect(0) as DOMRect);
|
|
2191
|
+
vi.spyOn(pane, 'getBoundingClientRect').mockImplementation(() => rect(0) as DOMRect);
|
|
2192
|
+
vi.spyOn(body, 'getBoundingClientRect').mockImplementation(
|
|
2193
|
+
() =>
|
|
2194
|
+
rect(
|
|
2195
|
+
pane.hasAttribute('data-full-screen')
|
|
2196
|
+
? BODY_FILLING - pane.scrollTop
|
|
2197
|
+
: BODY_ON_PAGE - shell.scrollTop,
|
|
2198
|
+
) as DOMRect,
|
|
2199
|
+
);
|
|
2200
|
+
|
|
2201
|
+
// 300px into the text.
|
|
2202
|
+
shell.scrollTop = BODY_ON_PAGE + 300;
|
|
2203
|
+
await user.click(screen.getByRole('button', { name: 'Full screen' }));
|
|
2204
|
+
expect(readPane()).toBe(pane);
|
|
2205
|
+
expect(pane.scrollTop).toBe(BODY_FILLING + 300);
|
|
2206
|
+
|
|
2207
|
+
// Read on to 500px into the text, then leave: the shell lands on the same line.
|
|
2208
|
+
pane.scrollTop = BODY_FILLING + 500;
|
|
2209
|
+
await user.click(screen.getByRole('button', { name: 'Exit full screen' }));
|
|
2210
|
+
expect(pane).not.toHaveAttribute('data-full-screen');
|
|
2211
|
+
expect(shell.scrollTop).toBe(BODY_ON_PAGE + 500);
|
|
2212
|
+
});
|
|
2213
|
+
|
|
2214
|
+
// A column that wraps differently puts every later line at a different
|
|
2215
|
+
// height, and no carried offset survives that (staging: Section 24 came
|
|
2216
|
+
// back as Section 30). So the text keeps the page's width to the pixel.
|
|
2217
|
+
it('lays the text out at the width it had on the page', async () => {
|
|
2218
|
+
const user = userEvent.setup();
|
|
2219
|
+
render(<ViewerHarness renderers={stubFor('.md')} />);
|
|
2220
|
+
await screen.findByTestId('stub-renderer');
|
|
2221
|
+
const card = screen.getByTestId('file-pane-card');
|
|
2222
|
+
vi.spyOn(card, 'getBoundingClientRect').mockImplementation(
|
|
2223
|
+
() => ({ top: 0, left: 0, right: 0, bottom: 0, width: 752, height: 0, x: 0, y: 0, toJSON: () => ({}) }) as DOMRect,
|
|
2224
|
+
);
|
|
2225
|
+
|
|
2226
|
+
await user.click(screen.getByRole('button', { name: 'Full screen' }));
|
|
2227
|
+
expect(card.style.maxWidth).toBe('752px');
|
|
2228
|
+
// The edges go transparent, not away: the box is as wide as it was.
|
|
2229
|
+
expect(card).toHaveClass('border-transparent');
|
|
2230
|
+
expect(card).not.toHaveClass('border-0');
|
|
2231
|
+
|
|
2232
|
+
await user.click(screen.getByRole('button', { name: 'Exit full screen' }));
|
|
2233
|
+
expect(card.style.maxWidth).toBe('');
|
|
2234
|
+
});
|
|
2235
|
+
|
|
2236
|
+
it('opened by URL, with no page to match, takes the column\'s content width', () => {
|
|
2237
|
+
render(<ViewerHarness renderers={stubFor('.md')} routeSearch="?fullscreen=1" />);
|
|
2238
|
+
const card = screen.getByTestId('file-pane-card');
|
|
2239
|
+
expect(card).toHaveClass('mx-auto', 'max-w-[800px]');
|
|
2240
|
+
expect(card.style.maxWidth).toBe('');
|
|
2241
|
+
});
|
|
2242
|
+
|
|
2243
|
+
it('keeps an edit unsaved across the toggle, and Ctrl+S saves it while filling the window', async () => {
|
|
2244
|
+
const user = userEvent.setup();
|
|
2245
|
+
const saved: string[] = [];
|
|
2246
|
+
render(
|
|
2247
|
+
<ViewerHarness
|
|
2248
|
+
initialContent="Base content"
|
|
2249
|
+
captureTyped
|
|
2250
|
+
onSaveFile={(_path, content) => saved.push(content)}
|
|
2251
|
+
/>,
|
|
2252
|
+
);
|
|
2253
|
+
await user.click(await screen.findByRole('button', { name: 'Edit' }));
|
|
2254
|
+
const textarea = await screen.findByRole('textbox');
|
|
2255
|
+
await user.type(textarea, ' and more');
|
|
2256
|
+
|
|
2257
|
+
await user.click(screen.getByRole('button', { name: 'Full screen' }));
|
|
2258
|
+
expect(screen.getByRole('textbox')).toBe(textarea);
|
|
2259
|
+
expect(textarea).toHaveValue('Base content and more');
|
|
2260
|
+
|
|
2261
|
+
textarea.focus();
|
|
2262
|
+
await user.keyboard('{Control>}s{/Control}');
|
|
2263
|
+
await waitFor(() => expect(saved).toEqual(['Base content and more']));
|
|
2264
|
+
|
|
2265
|
+
await user.click(screen.getByRole('button', { name: 'Exit full screen' }));
|
|
2266
|
+
expect(screen.getByRole('textbox')).toBe(textarea);
|
|
2267
|
+
});
|
|
2268
|
+
|
|
2269
|
+
it('draws a prose document alone: its reading column centred, no card edges, no bar', async () => {
|
|
2270
|
+
const user = userEvent.setup();
|
|
2271
|
+
render(<ViewerHarness renderers={stubFor('.md')} />);
|
|
2272
|
+
await screen.findByTestId('stub-renderer');
|
|
2273
|
+
await user.click(screen.getByRole('button', { name: 'Full screen' }));
|
|
2274
|
+
|
|
2275
|
+
const card = screen.getByTestId('file-pane-card');
|
|
2276
|
+
expect(card).toHaveClass('mx-auto', 'max-w-[800px]', 'border-transparent');
|
|
2277
|
+
expect(card).not.toHaveClass('shadow-card');
|
|
2278
|
+
// The bar (the file's name and its actions) is withdrawn.
|
|
2279
|
+
expect(within(card).queryByText('Foo.md')).toBeNull();
|
|
2280
|
+
expect(within(card).queryByRole('button', { name: 'Version history' })).toBeNull();
|
|
2281
|
+
expect(readPane()).toHaveClass('fixed', 'inset-0', 'overflow-auto');
|
|
2282
|
+
});
|
|
2283
|
+
|
|
2284
|
+
it('sizes a full-bleed renderer to the viewport', async () => {
|
|
2285
|
+
render(
|
|
2286
|
+
<ViewerHarness
|
|
2287
|
+
filePath="knowledge-base/Docs/Guide.pdf"
|
|
2288
|
+
renderers={stubFor('.pdf')}
|
|
2289
|
+
routeSearch="?fullscreen=1"
|
|
2290
|
+
/>,
|
|
2291
|
+
);
|
|
2292
|
+
expect(readPane()).toHaveClass('fixed', 'inset-0', 'flex', 'flex-col');
|
|
2293
|
+
expect(readPane()).not.toHaveClass('min-h-0');
|
|
2294
|
+
});
|
|
2295
|
+
|
|
2296
|
+
it('pins the exit control to the top right, above the renderer', () => {
|
|
2297
|
+
render(
|
|
2298
|
+
<ViewerHarness
|
|
2299
|
+
filePath="knowledge-base/Dashboards/Roadmap.html"
|
|
2300
|
+
renderers={stubFor('.html')}
|
|
2301
|
+
routeSearch="?fullscreen=1"
|
|
2302
|
+
/>,
|
|
2303
|
+
);
|
|
2304
|
+
const exit = screen.getByRole('button', { name: 'Exit full screen' });
|
|
2305
|
+
expect(exit).toHaveAttribute('aria-keyshortcuts', 'Escape');
|
|
2306
|
+
// Fixed to the viewport, so the renderer's own scroll cannot take it away,
|
|
2307
|
+
// and on a layer above the surface (z-40) the renderer sits in.
|
|
2308
|
+
expect(exit).toHaveClass('fixed', 'top-3', 'right-3', 'z-[41]');
|
|
2309
|
+
// Inside the filling surface, after the renderer: on top in paint order too.
|
|
2310
|
+
expect(readPane()).toContainElement(exit);
|
|
2311
|
+
expect(
|
|
2312
|
+
screen.getByTestId('stub-renderer').compareDocumentPosition(exit) & Node.DOCUMENT_POSITION_FOLLOWING,
|
|
2313
|
+
).toBeTruthy();
|
|
2314
|
+
});
|
|
2315
|
+
|
|
2316
|
+
// The control that was pressed is withdrawn by the switch, so focus would
|
|
2317
|
+
// otherwise fall to the body each way and the next Tab restart at the top.
|
|
2318
|
+
it.each([
|
|
2319
|
+
['prose, from the pane bar', 'knowledge-base/Knowledge/Foo.md'],
|
|
2320
|
+
['full-bleed, from the page header', 'knowledge-base/Dashboards/Roadmap.html'],
|
|
2321
|
+
])('moves focus to the exit control on entry and back to Full screen on exit (%s)', async (_kind, filePath) => {
|
|
2322
|
+
const user = userEvent.setup();
|
|
2323
|
+
render(<ViewerHarness filePath={filePath} renderers={stubFor('.md', '.html')} />);
|
|
2324
|
+
await screen.findByTestId('stub-renderer');
|
|
2325
|
+
|
|
2326
|
+
await user.click(screen.getByRole('button', { name: 'Full screen' }));
|
|
2327
|
+
expect(screen.getByRole('button', { name: 'Exit full screen' })).toHaveFocus();
|
|
2328
|
+
|
|
2329
|
+
await user.click(screen.getByRole('button', { name: 'Exit full screen' }));
|
|
2330
|
+
expect(screen.getByRole('button', { name: 'Full screen' })).toHaveFocus();
|
|
2331
|
+
});
|
|
2332
|
+
|
|
2333
|
+
it('moves focus into the view when the URL opens it, and to Full screen when it is left', async () => {
|
|
2334
|
+
const user = userEvent.setup();
|
|
2335
|
+
render(
|
|
2336
|
+
<ViewerHarness
|
|
2337
|
+
filePath="knowledge-base/Dashboards/Roadmap.html"
|
|
2338
|
+
renderers={stubFor('.html')}
|
|
2339
|
+
routeSearch="?fullscreen=1"
|
|
2340
|
+
/>,
|
|
2341
|
+
);
|
|
2342
|
+
expect(screen.getByRole('button', { name: 'Exit full screen' })).toHaveFocus();
|
|
2343
|
+
|
|
2344
|
+
await user.keyboard('{Escape}');
|
|
2345
|
+
expect(readPane()).not.toHaveAttribute('data-full-screen');
|
|
2346
|
+
expect(screen.getByRole('button', { name: 'Full screen' })).toHaveFocus();
|
|
2347
|
+
});
|
|
2348
|
+
|
|
2349
|
+
it('leaves focus in the renderer when the reader is working there', async () => {
|
|
2350
|
+
const user = userEvent.setup();
|
|
2351
|
+
render(<ViewerHarness renderers={stubFor('.md')} />);
|
|
2352
|
+
await screen.findByTestId('stub-renderer');
|
|
2353
|
+
await user.click(screen.getByRole('button', { name: 'Full screen' }));
|
|
2354
|
+
|
|
2355
|
+
await user.click(screen.getByLabelText('Scratch'));
|
|
2356
|
+
await user.keyboard('{Escape}');
|
|
2357
|
+
expect(readPane()).not.toHaveAttribute('data-full-screen');
|
|
2358
|
+
expect(screen.getByLabelText('Scratch')).toHaveFocus();
|
|
2359
|
+
});
|
|
2360
|
+
|
|
2361
|
+
it('leaves on Escape, but a dialog opened on top takes Escape first', async () => {
|
|
2362
|
+
const user = userEvent.setup();
|
|
2363
|
+
render(
|
|
2364
|
+
<ViewerHarness
|
|
2365
|
+
filePath="knowledge-base/Dashboards/Roadmap.html"
|
|
2366
|
+
renderers={stubFor('.html')}
|
|
2367
|
+
routeSearch="?fullscreen=1"
|
|
2368
|
+
/>,
|
|
2369
|
+
);
|
|
2370
|
+
await user.click(screen.getByRole('button', { name: 'Open stub dialog' }));
|
|
2371
|
+
expect(screen.getByRole('dialog', { name: 'Stub dialog' })).toBeInTheDocument();
|
|
2372
|
+
|
|
2373
|
+
await user.keyboard('{Escape}');
|
|
2374
|
+
expect(screen.queryByRole('dialog', { name: 'Stub dialog' })).toBeNull();
|
|
2375
|
+
expect(screen.getByTestId('location-search').textContent).toBe('?fullscreen=1');
|
|
2376
|
+
expect(readPane()).toHaveAttribute('data-full-screen');
|
|
2377
|
+
|
|
2378
|
+
await user.keyboard('{Escape}');
|
|
2379
|
+
expect(screen.getByTestId('location-search').textContent).toBe('');
|
|
2380
|
+
expect(readPane()).not.toHaveAttribute('data-full-screen');
|
|
2381
|
+
expect(mounts.count).toBe(1);
|
|
2382
|
+
});
|
|
2383
|
+
});
|
|
2384
|
+
|
|
2385
|
+
// An Escape pressed with focus inside a page's frame never reaches the app;
|
|
2386
|
+
// the frame posts it (`bevel.key`, see `htmlSandbox.ts`) and the view treats
|
|
2387
|
+
// it as the key it is — through the same modal layer order.
|
|
2388
|
+
describe('FileViewer full screen: Escape from inside a page', () => {
|
|
2389
|
+
function StubPage() {
|
|
2390
|
+
const [dialogOpen, setDialogOpen] = useState(false);
|
|
2391
|
+
return (
|
|
2392
|
+
<div data-testid="stub-renderer">
|
|
2393
|
+
<button type="button" onClick={() => setDialogOpen(true)}>
|
|
2394
|
+
Open stub dialog
|
|
2395
|
+
</button>
|
|
2396
|
+
<Dialog open={dialogOpen} onClose={() => setDialogOpen(false)} title="Stub dialog">
|
|
2397
|
+
A card over the page
|
|
2398
|
+
</Dialog>
|
|
2399
|
+
<iframe title="Stub page" />
|
|
2400
|
+
</div>
|
|
2401
|
+
);
|
|
2402
|
+
}
|
|
2403
|
+
|
|
2404
|
+
const renderFilling = () =>
|
|
2405
|
+
render(
|
|
2406
|
+
<ViewerHarness
|
|
2407
|
+
filePath="knowledge-base/Dashboards/Roadmap.html"
|
|
2408
|
+
renderers={[{ extensions: ['.html'], Component: StubPage }]}
|
|
2409
|
+
routeSearch="?fullscreen=1"
|
|
2410
|
+
/>,
|
|
2411
|
+
);
|
|
2412
|
+
const frameWindow = () => (screen.getByTitle('Stub page') as HTMLIFrameElement).contentWindow!;
|
|
2413
|
+
const postFrom = (source: MessageEventSource | null, data: unknown = { type: 'bevel.key', key: 'Escape' }) =>
|
|
2414
|
+
act(() => {
|
|
2415
|
+
window.dispatchEvent(new MessageEvent('message', { data, source }));
|
|
2416
|
+
});
|
|
2417
|
+
const search = () => screen.getByTestId('location-search').textContent;
|
|
2418
|
+
|
|
2419
|
+
it('leaves on an Escape the page hands up', () => {
|
|
2420
|
+
renderFilling();
|
|
2421
|
+
postFrom(frameWindow());
|
|
2422
|
+
expect(search()).toBe('');
|
|
2423
|
+
});
|
|
2424
|
+
|
|
2425
|
+
it('lets a card over the page take the handed-up Escape first, then leaves on the next', async () => {
|
|
2426
|
+
const user = userEvent.setup();
|
|
2427
|
+
renderFilling();
|
|
2428
|
+
await user.click(screen.getByRole('button', { name: 'Open stub dialog' }));
|
|
2429
|
+
|
|
2430
|
+
postFrom(frameWindow());
|
|
2431
|
+
expect(screen.queryByRole('dialog', { name: 'Stub dialog' })).toBeNull();
|
|
2432
|
+
expect(search()).toBe('?fullscreen=1');
|
|
2433
|
+
|
|
2434
|
+
postFrom(frameWindow());
|
|
2435
|
+
expect(search()).toBe('');
|
|
2436
|
+
});
|
|
2437
|
+
|
|
2438
|
+
it('ignores the message from a window that is not a frame in the view, and any other key', () => {
|
|
2439
|
+
renderFilling();
|
|
2440
|
+
const stranger = document.createElement('iframe');
|
|
2441
|
+
document.body.appendChild(stranger);
|
|
2442
|
+
try {
|
|
2443
|
+
postFrom(stranger.contentWindow);
|
|
2444
|
+
postFrom(null);
|
|
2445
|
+
postFrom(frameWindow(), { type: 'bevel.key', key: 'Enter' });
|
|
2446
|
+
postFrom(frameWindow(), { type: 'bevel.navigate', href: 'Escape' });
|
|
2447
|
+
expect(search()).toBe('?fullscreen=1');
|
|
2448
|
+
} finally {
|
|
2449
|
+
stranger.remove();
|
|
2450
|
+
}
|
|
2451
|
+
});
|
|
2452
|
+
|
|
2453
|
+
// The command menu and the single-key commands refuse to open while a modal
|
|
2454
|
+
// is up (`[aria-modal="true"]`); the filling view is one, so Ctrl+K cannot
|
|
2455
|
+
// open the menu unseen in the covered header.
|
|
2456
|
+
it('is modal while it fills the window, and only then', async () => {
|
|
2457
|
+
const user = userEvent.setup();
|
|
2458
|
+
renderFilling();
|
|
2459
|
+
const pane = screen.getByTestId('stub-renderer').closest('[data-read-pane]');
|
|
2460
|
+
expect(document.querySelector('[aria-modal="true"]')).toBe(pane);
|
|
2461
|
+
expect(screen.getByRole('dialog', { name: 'Roadmap.html, full screen' })).toBe(pane);
|
|
2462
|
+
|
|
2463
|
+
await user.click(screen.getByRole('button', { name: 'Exit full screen' }));
|
|
2464
|
+
expect(document.querySelector('[aria-modal="true"]')).toBeNull();
|
|
2465
|
+
});
|
|
2466
|
+
});
|
|
@@ -0,0 +1,59 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* Carrying a reader's place across the full-screen switch.
|
|
3
|
+
*
|
|
4
|
+
* The read pane leaving the shell's flow collapses the shell's scroll (the
|
|
5
|
+
* pane takes its scrollTop with it), so the position is carried by hand:
|
|
6
|
+
* into the pane's own scroller on the way in, back into the shell's on the
|
|
7
|
+
* way out. Measured against the document's BODY, not the pane: between the
|
|
8
|
+
* two views the pane gains padding and the card loses its bar, so the pane's
|
|
9
|
+
* top is a different distance above the text in each, and a carry against
|
|
10
|
+
* it lands the reader that many pixels off. And it only holds when the text
|
|
11
|
+
* is laid out at the SAME width in both views ({@link readingWidthOf}): a
|
|
12
|
+
* column that wraps differently puts every line below the first at a
|
|
13
|
+
* different height, and no pixel offset survives that — Section 24 came
|
|
14
|
+
* back as Section 30.
|
|
15
|
+
*
|
|
16
|
+
* Pure functions over live elements, so the real-browser suite can load them
|
|
17
|
+
* into a page as they are (`browser/full-screen-reading-width.browser.ts`):
|
|
18
|
+
* the unit suite's happy-dom lays nothing out, and this is layout.
|
|
19
|
+
*/
|
|
20
|
+
|
|
21
|
+
/**
|
|
22
|
+
* The prose document's body inside the read pane — what the switch measures
|
|
23
|
+
* the reader's place against. Null for a full-bleed file, which has no card
|
|
24
|
+
* and scrolls inside its own renderer.
|
|
25
|
+
*/
|
|
26
|
+
export function readingAnchorIn(pane: HTMLElement | null): HTMLElement | null {
|
|
27
|
+
// The body of the pane's own card (its direct child), found by the body's
|
|
28
|
+
// own marker: a test id is the tests' to rename, and a selector hung on it
|
|
29
|
+
// would stop the carry silently the day one is.
|
|
30
|
+
return pane?.querySelector<HTMLElement>(':scope > * > [data-file-pane-body]') ?? null;
|
|
31
|
+
}
|
|
32
|
+
|
|
33
|
+
/**
|
|
34
|
+
* How far into the document the reader is: the scroller's top edge below
|
|
35
|
+
* the body's top, in pixels (negative while the body's top is still below
|
|
36
|
+
* the edge).
|
|
37
|
+
*/
|
|
38
|
+
export function readingOffset(scroller: Element, anchor: Element): number {
|
|
39
|
+
return scroller.getBoundingClientRect().top - anchor.getBoundingClientRect().top;
|
|
40
|
+
}
|
|
41
|
+
|
|
42
|
+
/**
|
|
43
|
+
* Scroll `scroller` so its top edge sits `offset` px below the body's top
|
|
44
|
+
* again — a delta on whatever the scroller holds now, so it is right whether
|
|
45
|
+
* the scroller kept its place or collapsed to the top.
|
|
46
|
+
*/
|
|
47
|
+
export function carryReadingOffset(scroller: HTMLElement, anchor: Element, offset: number): void {
|
|
48
|
+
scroller.scrollTop += anchor.getBoundingClientRect().top - scroller.getBoundingClientRect().top + offset;
|
|
49
|
+
}
|
|
50
|
+
|
|
51
|
+
/**
|
|
52
|
+
* The width the page laid the document's card out at, to hold while filling
|
|
53
|
+
* the window so every line wraps where it did. Null when there is none to
|
|
54
|
+
* hold (no card, or one not laid out).
|
|
55
|
+
*/
|
|
56
|
+
export function readingWidthOf(anchor: Element): number | null {
|
|
57
|
+
const card = anchor.parentElement;
|
|
58
|
+
return card ? card.getBoundingClientRect().width || null : null;
|
|
59
|
+
}
|