@bevel-software/platform-core-frontend 0.25.2 → 0.27.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 +87 -25
- package/src/core/ProductName.tsx +49 -0
- package/src/core/__tests__/ShellRoutes.test.tsx +22 -0
- package/src/core/__tests__/core-contributions.test.ts +16 -0
- package/src/core/core-contributions.ts +17 -0
- package/src/core/registry.ts +51 -1
- package/src/index.css +23 -5
- package/src/index.ts +5 -0
- package/src/modules/access/__tests__/ManageAccessDialog.proposal.test.tsx +1 -1
- package/src/modules/access/components/ManageAccessDialog.tsx +1 -1
- package/src/modules/admin/__tests__/RolesCorruptedBanner.test.tsx +70 -0
- package/src/modules/admin/components/RolesCorruptedBanner.tsx +9 -4
- package/src/modules/auth/components/LoginScreen.tsx +4 -1
- package/src/modules/auth/services/account.api.ts +28 -1
- package/src/modules/auth/services/sso.ts +1 -2
- package/src/modules/change-requests/__tests__/ChangeRequestDialog.sync-banner.test.tsx +176 -0
- package/src/modules/change-requests/__tests__/ChangeRequestDialog.unreadable.test.tsx +68 -0
- package/src/modules/change-requests/__tests__/ChangeRequestLink.test.tsx +182 -0
- package/src/modules/change-requests/__tests__/FileChangeBoxes.test.tsx +1 -1
- package/src/modules/change-requests/__tests__/readFileOnBranch.test.ts +79 -0
- package/src/modules/change-requests/components/ChangeBox.tsx +6 -1
- package/src/modules/change-requests/components/ChangeRequestDialog.tsx +45 -15
- package/src/modules/change-requests/components/ChangeRequestLink.tsx +151 -0
- package/src/modules/change-requests/components/CrFileTree.tsx +2 -1
- package/src/modules/change-requests/components/FileChangeBoxes.tsx +4 -2
- package/src/modules/change-requests/hooks/useApplyChangeRequest.ts +6 -3
- package/src/modules/change-requests/services/change-requests.api.ts +15 -2
- package/src/modules/change-requests/utils/readFailure.ts +22 -0
- package/src/modules/embed/__tests__/EmbedLinkPage.test.tsx +74 -0
- package/src/modules/embed/__tests__/EmbedView.test.tsx +473 -0
- package/src/modules/embed/__tests__/embed-config.test.ts +128 -0
- package/src/modules/embed/__tests__/embed-host.test.ts +111 -0
- package/src/modules/embed/__tests__/mcp-app-view.test.ts +295 -0
- package/src/modules/embed/__tests__/mount.test.tsx +157 -0
- package/src/modules/embed/components/EmbedLinkPage.tsx +109 -0
- package/src/modules/embed/components/EmbedView.tsx +545 -0
- package/src/modules/embed/embed-config.ts +132 -0
- package/src/modules/embed/embed-host.ts +120 -0
- package/src/modules/embed/mount.tsx +80 -0
- package/src/modules/embed/services/embed-token.ts +22 -0
- package/src/modules/embed/services/embed.api.ts +158 -0
- package/src/modules/git/__tests__/BranchSwitcher.test.tsx +202 -4
- package/src/modules/git/__tests__/GitSyncFailedBanner.test.tsx +59 -1
- package/src/modules/git/__tests__/PullNeededBanner.test.tsx +39 -22
- package/src/modules/git/__tests__/useAutoPullUpdates.test.tsx +7 -2
- package/src/modules/git/branch-delete-menu-item.tsx +24 -0
- package/src/modules/git/components/BranchSwitcher.tsx +29 -5
- package/src/modules/git/components/GitSyncFailedBanner.tsx +53 -15
- package/src/modules/git/components/HistoryVersionPreview.tsx +5 -3
- package/src/modules/git/components/PullNeededBanner.tsx +15 -49
- package/src/modules/git/hooks/useAutoPullUpdates.ts +9 -5
- package/src/modules/git/index.ts +15 -0
- package/src/modules/git/services/__tests__/error-messages.test.ts +67 -0
- package/src/modules/git/services/__tests__/pull-failure.test.ts +36 -0
- package/src/modules/git/services/error-messages.ts +58 -1
- package/src/modules/git/services/pull-failure.ts +68 -0
- package/src/modules/git/state/branch-delete-confirm.ts +46 -0
- package/src/modules/layout/__tests__/HeaderAlignment.test.tsx +1 -0
- package/src/modules/layout/__tests__/breakpoints.test.ts +7 -1
- package/src/modules/layout/breakpoints.ts +8 -0
- package/src/modules/library/__tests__/PluginExtras.test.tsx +9 -9
- package/src/modules/library/__tests__/PluginPage.test.tsx +8 -1
- package/src/modules/library/__tests__/SkillsTree.test.tsx +13 -4
- package/src/modules/library/__tests__/ToolPage.test.tsx +53 -0
- package/src/modules/library/components/LibraryPage.tsx +22 -0
- package/src/modules/library/components/PluginExtras.tsx +23 -6
- package/src/modules/library/components/PluginPage.tsx +6 -1
- package/src/modules/library/components/tool-page/ToolPage.tsx +45 -1
- package/src/modules/library/routes/LibraryRoutes.tsx +8 -7
- package/src/modules/library/services/plugins.api.ts +4 -1
- package/src/modules/library/services/tools.api.ts +27 -0
- package/src/modules/library/state/plugins-revision.ts +28 -0
- package/src/modules/onboarding/__tests__/agent-connection-api.test.ts +55 -0
- package/src/modules/onboarding/__tests__/creator-welcome.test.tsx +87 -82
- package/src/modules/onboarding/__tests__/first-page-prompt.test.ts +109 -0
- package/src/modules/onboarding/__tests__/get-started-column.test.tsx +1001 -0
- package/src/modules/onboarding/__tests__/invite-dialog.test.tsx +392 -0
- package/src/modules/onboarding/__tests__/onboarding.test.tsx +226 -193
- package/src/modules/onboarding/__tests__/starter-pack-card.test.tsx +136 -0
- package/src/modules/onboarding/components/CreatorWelcomePage.tsx +7 -11
- package/src/modules/onboarding/components/EmailChipsInput.tsx +138 -0
- package/src/modules/onboarding/components/GetStartedColumn.tsx +651 -0
- package/src/modules/onboarding/components/InviteButton.tsx +35 -0
- package/src/modules/onboarding/components/InviteDialog.tsx +424 -0
- package/src/modules/onboarding/components/RootLanding.tsx +8 -24
- package/src/modules/onboarding/components/StarterPackCard.tsx +98 -0
- package/src/modules/onboarding/components/WelcomePage.tsx +65 -154
- package/src/modules/onboarding/first-page-prompt.ts +89 -0
- package/src/modules/onboarding/invite-emails.ts +175 -0
- package/src/modules/onboarding/services/agent-connection.api.ts +53 -0
- package/src/modules/onboarding/services/starter-packs.api.ts +83 -0
- package/src/modules/onboarding/state/agent-connection.ts +167 -0
- package/src/modules/onboarding/state/invite-dialog.context.ts +32 -0
- package/src/modules/onboarding/state/invite-dialog.tsx +31 -0
- package/src/modules/onboarding/state/onboarding.ts +133 -59
- package/src/modules/onboarding/state/starter-packs.ts +169 -0
- package/src/modules/settings/settings-nav-items.tsx +8 -3
- package/src/modules/setup/__tests__/setup.first-run-storage.test.tsx +389 -0
- package/src/modules/setup/__tests__/setup.github.test.tsx +5 -5
- package/src/modules/setup/__tests__/setup.kept-draft.test.tsx +1 -1
- package/src/modules/setup/__tests__/setup.repository-change.test.tsx +1 -1
- package/src/modules/setup/__tests__/setup.repository.test.tsx +21 -21
- package/src/modules/setup/__tests__/setup.test.tsx +65 -81
- package/src/modules/setup/__tests__/useConnectionProbe.test.tsx +123 -0
- package/src/modules/setup/components/FirstRunStorage.tsx +560 -0
- package/src/modules/setup/components/SetupGate.tsx +46 -1
- package/src/modules/setup/components/SetupScreen.tsx +92 -152
- package/src/modules/setup/hooks/useConnectionProbe.ts +93 -0
- package/src/modules/setup/services/setup.api.ts +3 -3
- package/src/modules/setup/utils/suggested-branch.ts +27 -0
- package/src/modules/toolbar/commands/__tests__/actions.test.tsx +210 -0
- package/src/modules/toolbar/commands/actions.tsx +324 -0
- package/src/modules/toolbar/commands/command-menu.ts +44 -0
- package/src/modules/toolbar/commands/useCommandActions.ts +69 -0
- package/src/modules/toolbar/commands/useCommandShortcuts.ts +121 -0
- package/src/modules/toolbar/components/AppSwitcher.tsx +106 -22
- package/src/modules/toolbar/components/ExternalAgentAccessPage.tsx +1 -1
- package/src/modules/toolbar/components/ProfileMenu.tsx +9 -4
- package/src/modules/toolbar/components/SearchPalette.tsx +540 -0
- package/src/modules/toolbar/components/Toolbar.tsx +10 -0
- package/src/modules/toolbar/components/__tests__/AppSwitcher.test.tsx +187 -54
- package/src/modules/toolbar/components/__tests__/ExternalAgentAccessPage.test.tsx +4 -4
- package/src/modules/toolbar/components/__tests__/ProfileMenu.test.tsx +64 -0
- package/src/modules/toolbar/components/__tests__/SearchPalette.test.tsx +832 -0
- package/src/modules/toolbar/components/__tests__/Toolbar.test.tsx +57 -2
- package/src/modules/toolbar/search/__tests__/rank.test.ts +93 -0
- package/src/modules/toolbar/search/__tests__/sources.test.ts +131 -0
- package/src/modules/toolbar/search/rank.ts +111 -0
- package/src/modules/toolbar/search/sources.ts +169 -0
- package/src/modules/workflow/hooks/useFileLock.ts +10 -7
- package/src/modules/workflow/services/__tests__/lock.api.test.ts +41 -0
- package/src/modules/workflow/services/lock.api.ts +17 -2
- package/src/modules/workspace/__tests__/useWorkspaceState.test.ts +49 -1
- package/src/modules/workspace/components/EditorTabs.tsx +39 -15
- package/src/modules/workspace/components/FileExplorer.tsx +39 -6
- package/src/modules/workspace/components/FilePaneCard.tsx +6 -2
- package/src/modules/workspace/components/FileRoute.tsx +12 -7
- package/src/modules/workspace/components/FileViewer.tsx +271 -74
- package/src/modules/workspace/components/KbPageHeader.tsx +13 -6
- package/src/modules/workspace/components/__tests__/EditorTabs.test.tsx +88 -21
- package/src/modules/workspace/components/__tests__/FileExplorer.test.tsx +101 -11
- package/src/modules/workspace/components/__tests__/FileRoute.test.tsx +23 -3
- package/src/modules/workspace/components/__tests__/FileViewer.test.tsx +330 -6
- package/src/modules/workspace/components/__tests__/KbPageHeader.test.tsx +17 -2
- package/src/modules/workspace/components/renderers/DocxRenderer.tsx +11 -16
- package/src/modules/workspace/components/renderers/DownloadFileButton.tsx +6 -0
- package/src/modules/workspace/components/renderers/EmailRenderer.tsx +23 -21
- package/src/modules/workspace/components/renderers/ImageRenderer.tsx +13 -29
- package/src/modules/workspace/components/renderers/KbMarkdownView.tsx +9 -2
- package/src/modules/workspace/components/renderers/MarkdownRenderer.tsx +8 -0
- package/src/modules/workspace/components/renderers/PdfRenderer.tsx +14 -19
- package/src/modules/workspace/components/renderers/PptxRenderer.tsx +11 -17
- package/src/modules/workspace/components/renderers/ToolRenderer.tsx +35 -7
- package/src/modules/workspace/components/renderers/XlsxRenderer.tsx +11 -17
- package/src/modules/workspace/components/renderers/__tests__/EmailRenderer.links.test.tsx +73 -0
- package/src/modules/workspace/components/renderers/__tests__/ToolRenderer.scaffold.test.tsx +64 -0
- package/src/modules/workspace/components/renderers/__tests__/ToolRenderer.surface.test.tsx +82 -0
- package/src/modules/workspace/components/renderers/__tests__/bridgeHarness.ts +99 -0
- package/src/modules/workspace/components/renderers/__tests__/htmlSandbox.test.ts +129 -35
- package/src/modules/workspace/components/renderers/__tests__/htmlViewsGuide.test.ts +149 -0
- package/src/modules/workspace/components/renderers/__tests__/kbMarkdownLinkPolicy.test.tsx +100 -0
- package/src/modules/workspace/components/renderers/htmlSandbox.ts +76 -20
- package/src/modules/workspace/components/renderers/index.ts +26 -0
- package/src/modules/workspace/components/renderers/kbMarkdownPipeline.tsx +51 -1
- package/src/modules/workspace/components/renderers/rendererRawRead.ts +53 -0
- package/src/modules/workspace/components/renderers/rendererSurface.ts +109 -0
- package/src/modules/workspace/components/renderers/rendererWorkspace.ts +8 -2
- package/src/modules/workspace/hooks/__tests__/useWorkspaceState.test.tsx +126 -21
- package/src/modules/workspace/hooks/useCreatePage.ts +116 -0
- package/src/modules/workspace/hooks/useWorkspaceImageResolver.ts +24 -7
- package/src/modules/workspace/hooks/useWorkspaceState.ts +42 -8
- package/src/modules/workspace/routing/__tests__/kb-routes.test.tsx +10 -0
- package/src/modules/workspace/routing/__tests__/md-links-parity.test.tsx +113 -0
- package/src/modules/workspace/routing/kb-routes.ts +66 -12
- package/src/modules/workspace/state/editable-page.ts +42 -0
- package/src/modules/workspace/state/workspace.context.ts +13 -4
- package/src/modules/workspace/utils/__tests__/display-file-name.test.ts +60 -0
- package/src/modules/workspace/utils/__tests__/fileTree.test.ts +75 -0
- package/src/modules/workspace/utils/__tests__/treeConfirm.test.ts +26 -14
- package/src/modules/workspace/utils/display-file-name.ts +102 -0
- package/src/modules/workspace/utils/fileTree.ts +49 -14
- package/src/modules/workspace/utils/treeConfirm.ts +22 -5
- package/src/shared/__tests__/no-builtin-confirm.test.ts +102 -0
- package/src/shared/components/ConfirmProvider.tsx +156 -0
- package/src/shared/components/Dialog.tsx +7 -0
- package/src/shared/components/__tests__/ConfirmProvider.test.tsx +198 -0
- package/src/shared/components/confirm-context.ts +94 -0
- package/src/shared/components/index.ts +3 -0
- package/src/shared/mcp/__tests__/connect-snippets.test.ts +2 -2
- package/src/shared/mcp/connect-snippets.ts +8 -5
- package/src/modules/onboarding/components/WelcomeRoute.tsx +0 -57
- package/src/modules/onboarding/welcome-state.ts +0 -36
|
@@ -296,40 +296,96 @@ function escapeForScriptBody(source: string): string {
|
|
|
296
296
|
* (`HtmlRenderer` / the embed) decides whether and how to navigate.
|
|
297
297
|
*
|
|
298
298
|
* Two entry points:
|
|
299
|
-
* - `window.bevel.openNode(href)`
|
|
300
|
-
* whose node `click` handler
|
|
301
|
-
*
|
|
302
|
-
*
|
|
299
|
+
* - `window.bevel.openNode(href)` (and its alias `window.bevel.navigate`) —
|
|
300
|
+
* for programmatic viewers (e.g. a d3 graph whose node `click` handler
|
|
301
|
+
* wants to open the underlying node).
|
|
302
|
+
* - A delegated click listener on `<a href>` — for plain HTML links.
|
|
303
|
+
*
|
|
304
|
+
* A bare fragment (`#totals`) is the one address the bridge keeps to itself,
|
|
305
|
+
* by either route: it scrolls the element with that id into view inside the
|
|
306
|
+
* frame and posts nothing. The browser cannot be left to do it — a `srcdoc`
|
|
307
|
+
* frame resolves `#totals` against the APP's URL, so the default action
|
|
308
|
+
* navigates the frame away and unloads the page. A fragment naming no element
|
|
309
|
+
* does nothing, except `#` and `#top`, which scroll to the top as a browser
|
|
310
|
+
* would. A click whose default a handler of the page already cancelled is
|
|
311
|
+
* left to that handler. The `html-views` section of the agent guide states this rule, and
|
|
312
|
+
* `htmlViewsGuide.test.ts` holds the two together.
|
|
303
313
|
*/
|
|
304
314
|
const NAV_BRIDGE = `
|
|
305
315
|
;(function () {
|
|
316
|
+
// A written href is read the way a browser reads it before the bridge
|
|
317
|
+
// decides anything — the same rule as \`normalizeHref\` in the parent, kept
|
|
318
|
+
// here in ES5 because this source is a string injected into the iframe and
|
|
319
|
+
// cannot import. Without it a padded ' #goal ' would be posted to the
|
|
320
|
+
// parent instead of scrolled to here.
|
|
321
|
+
function normalize(url) {
|
|
322
|
+
var s = url.replace(/[\\t\\n\\r]/g, '');
|
|
323
|
+
var start = 0;
|
|
324
|
+
var end = s.length;
|
|
325
|
+
while (start < end && s.charCodeAt(start) <= 0x20) start++;
|
|
326
|
+
while (end > start && s.charCodeAt(end - 1) <= 0x20) end--;
|
|
327
|
+
return s.slice(start, end);
|
|
328
|
+
}
|
|
329
|
+
function findTarget(id) {
|
|
330
|
+
if (id === '') return null;
|
|
331
|
+
var el = document.getElementById(id);
|
|
332
|
+
if (el) return el;
|
|
333
|
+
// The standard's fallback is the first <a name="…"> — an anchor, and only
|
|
334
|
+
// an anchor. A form control's name is not a fragment target: a browser
|
|
335
|
+
// leaves '#query' alone when only <input name="query"> carries it.
|
|
336
|
+
var named = document.getElementsByName ? document.getElementsByName(id) : null;
|
|
337
|
+
for (var i = 0; named && i < named.length; i++) {
|
|
338
|
+
if (named[i].tagName && named[i].tagName.toUpperCase() === 'A') return named[i];
|
|
339
|
+
}
|
|
340
|
+
return null;
|
|
341
|
+
}
|
|
342
|
+
// A bare fragment is an in-page jump, scrolled here inside the frame. The
|
|
343
|
+
// target is found as the HTML standard finds it: the fragment as written
|
|
344
|
+
// first, its percent-decoding only when that names nothing.
|
|
345
|
+
function jumpTo(fragment) {
|
|
346
|
+
if (typeof document === 'undefined') return;
|
|
347
|
+
var id = fragment.slice(1);
|
|
348
|
+
var el = findTarget(id);
|
|
349
|
+
if (!el) {
|
|
350
|
+
var decoded = id;
|
|
351
|
+
try {
|
|
352
|
+
decoded = decodeURIComponent(id);
|
|
353
|
+
} catch (err) {
|
|
354
|
+
decoded = id;
|
|
355
|
+
}
|
|
356
|
+
if (decoded !== id) el = findTarget(decoded);
|
|
357
|
+
}
|
|
358
|
+
if (el) {
|
|
359
|
+
el.scrollIntoView();
|
|
360
|
+
return;
|
|
361
|
+
}
|
|
362
|
+
if (id === '' || id.toLowerCase() === 'top') globalThis.scrollTo(0, 0);
|
|
363
|
+
}
|
|
306
364
|
function navigate(target) {
|
|
307
|
-
if (typeof target !== 'string'
|
|
365
|
+
if (typeof target !== 'string') return;
|
|
366
|
+
var href = normalize(target);
|
|
367
|
+
if (href === '') return;
|
|
368
|
+
if (href.charAt(0) === '#') {
|
|
369
|
+
jumpTo(href);
|
|
370
|
+
return;
|
|
371
|
+
}
|
|
308
372
|
parent.postMessage({ type: 'bevel.navigate', href: target }, '*');
|
|
309
373
|
}
|
|
310
374
|
globalThis.bevel.openNode = navigate;
|
|
311
375
|
globalThis.bevel.navigate = navigate;
|
|
312
376
|
if (typeof document !== 'undefined') {
|
|
313
|
-
// A written href is read the way a browser reads it before the bridge
|
|
314
|
-
// decides anything — the same rule as \`normalizeHref\` in the parent, kept
|
|
315
|
-
// here in ES5 because this source is a string injected into the iframe and
|
|
316
|
-
// cannot import. Without it a padded ' #goal ' would be posted to the
|
|
317
|
-
// parent instead of left to the browser to scroll.
|
|
318
|
-
function normalize(url) {
|
|
319
|
-
var s = url.replace(/[\\t\\n\\r]/g, '');
|
|
320
|
-
var start = 0;
|
|
321
|
-
var end = s.length;
|
|
322
|
-
while (start < end && s.charCodeAt(start) <= 0x20) start++;
|
|
323
|
-
while (end > start && s.charCodeAt(end - 1) <= 0x20) end--;
|
|
324
|
-
return s.slice(start, end);
|
|
325
|
-
}
|
|
326
377
|
document.addEventListener('click', function (e) {
|
|
327
378
|
var el = e.target;
|
|
328
379
|
var a = el && el.closest ? el.closest('a[href]') : null;
|
|
329
380
|
if (!a) return;
|
|
330
|
-
|
|
331
|
-
|
|
381
|
+
// A handler of the page's own that already cancelled this click owns
|
|
382
|
+
// it (a toggle, a hash router); the bridge stays out of its way.
|
|
383
|
+
if (e.defaultPrevented) return;
|
|
384
|
+
// Cancelled even when there is nowhere to go: left to the browser, an
|
|
385
|
+
// empty href reloads the frame against the app's URL, as '#…' would.
|
|
332
386
|
e.preventDefault();
|
|
387
|
+
var href = normalize(a.getAttribute('href') || '');
|
|
388
|
+
if (!href) return;
|
|
333
389
|
navigate(href);
|
|
334
390
|
});
|
|
335
391
|
}
|
|
@@ -245,3 +245,29 @@ const VIEW_ONLY_EXTENSIONS = new Set([
|
|
|
245
245
|
export function isViewOnlyFile(filePath: string): boolean {
|
|
246
246
|
return VIEW_ONLY_EXTENSIONS.has(filePath.slice(filePath.lastIndexOf('.')).toLowerCase());
|
|
247
247
|
}
|
|
248
|
+
|
|
249
|
+
/**
|
|
250
|
+
* The renderer a surface should mount for `filePath`: a deployment's own
|
|
251
|
+
* override for that extension when it registered one, else the built-in map
|
|
252
|
+
* above.
|
|
253
|
+
*
|
|
254
|
+
* ONE lookup, because "which renderer draws this file" has to have one
|
|
255
|
+
* answer. The file page, Version history and the embed each used to spell the
|
|
256
|
+
* precedence out — and the embed is the reason it matters: the whole promise
|
|
257
|
+
* of the page-in-chat is that it renders with the app's renderer for the
|
|
258
|
+
* type, a registered one included, so a second spelling here would be a
|
|
259
|
+
* second answer and the embed would be the one that lagged.
|
|
260
|
+
*/
|
|
261
|
+
export function pickFileRenderer(
|
|
262
|
+
filePath: string,
|
|
263
|
+
overrides: readonly { extensions: string[]; Component: ComponentType<FileRendererProps> }[] = [],
|
|
264
|
+
): ComponentType<FileRendererProps> {
|
|
265
|
+
// The access rules file is plain text on every surface, whatever a
|
|
266
|
+
// deployment registered for `.md`: rules rendered as a page could hide or
|
|
267
|
+
// misstate what they grant.
|
|
268
|
+
const name = filePath.slice(filePath.lastIndexOf('/') + 1).toLowerCase();
|
|
269
|
+
if (name === ACCESS_RULES_FILE) return TextRenderer;
|
|
270
|
+
const ext = filePath.slice(filePath.lastIndexOf('.')).toLowerCase();
|
|
271
|
+
const override = overrides.find((r) => r.extensions.includes(ext));
|
|
272
|
+
return override?.Component ?? getFileRenderer(filePath);
|
|
273
|
+
}
|
|
@@ -44,6 +44,7 @@ import rehypeSanitize from 'rehype-sanitize';
|
|
|
44
44
|
import rehypeSlug from 'rehype-slug';
|
|
45
45
|
import { CopyAnchorButton } from './CopyAnchorButton';
|
|
46
46
|
import { KbImage, type KbImageResolver } from './KbImage';
|
|
47
|
+
import { normalizeHref } from '../../../../shared/markdown/hrefs';
|
|
47
48
|
|
|
48
49
|
export type { KbImageResolver, KbImageSource } from './KbImage';
|
|
49
50
|
|
|
@@ -132,6 +133,29 @@ export interface KbMarkdownComponentOptions {
|
|
|
132
133
|
* never reach it. See {@link KbImage} for every state.
|
|
133
134
|
*/
|
|
134
135
|
resolveImage?: KbImageResolver;
|
|
136
|
+
/**
|
|
137
|
+
* WHICH links this surface wants handed to `onOpenFile`, rather than left
|
|
138
|
+
* to the browser.
|
|
139
|
+
*
|
|
140
|
+
* - `'browser'` (default, the app): the internal `.md` path links only.
|
|
141
|
+
* An `http(s)` destination becomes a plain `target="_blank"` anchor,
|
|
142
|
+
* because in a tab that is exactly right — the browser opens a new tab
|
|
143
|
+
* and nothing needs intercepting.
|
|
144
|
+
* - `'surface'` (the embed): EVERY destination that leaves this page. In a
|
|
145
|
+
* host's sandbox there is no `allow-popups`, so `target="_blank"` does
|
|
146
|
+
* nothing and the plain anchor NAVIGATES THE FRAME instead — the reader
|
|
147
|
+
* loses the page and has no way back. Every such link has to be relayed
|
|
148
|
+
* to the host, which is what `onOpenFile` does there.
|
|
149
|
+
*
|
|
150
|
+
* It also settles the narrower bug: the `.md` rule meant a knowledge-base
|
|
151
|
+
* link to an image, a PDF or a document was left to the browser as a
|
|
152
|
+
* relative URL. In the app that is a stale no-op; in a frame it is another
|
|
153
|
+
* way to navigate away.
|
|
154
|
+
*
|
|
155
|
+
* A same-page `#anchor` is the browser's under BOTH policies: it scrolls
|
|
156
|
+
* within the view and leaves nothing.
|
|
157
|
+
*/
|
|
158
|
+
linkPolicy?: 'browser' | 'surface';
|
|
135
159
|
}
|
|
136
160
|
|
|
137
161
|
/**
|
|
@@ -144,6 +168,7 @@ export function useKbMarkdownComponents({
|
|
|
144
168
|
headingLink,
|
|
145
169
|
onMermaidError = 'error',
|
|
146
170
|
resolveImage,
|
|
171
|
+
linkPolicy = 'browser',
|
|
147
172
|
}: KbMarkdownComponentOptions) {
|
|
148
173
|
return useMemo(() => {
|
|
149
174
|
// One renderer for h1–h6: reads its level from the hast node's tagName,
|
|
@@ -222,6 +247,31 @@ export function useKbMarkdownComponents({
|
|
|
222
247
|
</a>
|
|
223
248
|
);
|
|
224
249
|
}
|
|
250
|
+
// A surface that owns every outgoing link takes the rest: an
|
|
251
|
+
// `http(s)` address, and a workspace path the `.md` rule above did
|
|
252
|
+
// not match (an image, a PDF, a document). Same-page `#anchor` links
|
|
253
|
+
// are excluded — they scroll inside this view and leave nothing —
|
|
254
|
+
// judged on the NORMALISED spelling, as a browser judges it, so a
|
|
255
|
+
// whitespace-padded ` #goal` still scrolls rather than leaving.
|
|
256
|
+
if (onOpenFile && linkPolicy === 'surface' && href !== undefined && !normalizeHref(href).startsWith('#')) {
|
|
257
|
+
// A destination that normalises to nothing (`href=""`, whitespace)
|
|
258
|
+
// is nowhere to go: inert, and its default — which would navigate
|
|
259
|
+
// the frame to itself — cancelled, like a same-page anchor's.
|
|
260
|
+
const inert = normalizeHref(href) === '';
|
|
261
|
+
return (
|
|
262
|
+
<a
|
|
263
|
+
{...props}
|
|
264
|
+
href={href}
|
|
265
|
+
onClick={(e) => {
|
|
266
|
+
e.preventDefault();
|
|
267
|
+
if (!inert) onOpenFile(href);
|
|
268
|
+
}}
|
|
269
|
+
className={inert ? undefined : 'cursor-pointer'}
|
|
270
|
+
>
|
|
271
|
+
{children}
|
|
272
|
+
</a>
|
|
273
|
+
);
|
|
274
|
+
}
|
|
225
275
|
if (href && /^https?:\/\//i.test(href)) {
|
|
226
276
|
return <a href={href} {...props} target="_blank" rel="noopener noreferrer">{children}</a>;
|
|
227
277
|
}
|
|
@@ -258,5 +308,5 @@ export function useKbMarkdownComponents({
|
|
|
258
308
|
return <pre {...props}>{children}</pre>;
|
|
259
309
|
},
|
|
260
310
|
};
|
|
261
|
-
}, [onOpenFile, onOpenNodeId, headingLink, onMermaidError, resolveImage]);
|
|
311
|
+
}, [onOpenFile, onOpenNodeId, headingLink, onMermaidError, resolveImage, linkPolicy]);
|
|
262
312
|
}
|
|
@@ -0,0 +1,53 @@
|
|
|
1
|
+
import { useMemo } from 'react';
|
|
2
|
+
import { authFetch } from '../../../../lib/api';
|
|
3
|
+
import { rawFileUrl } from '../../services/workspace.api';
|
|
4
|
+
import { useRendererFileRef, useRendererWorkspaceId } from './rendererWorkspace';
|
|
5
|
+
import { useRendererSurface, type RendererRawRead } from './rendererSurface';
|
|
6
|
+
|
|
7
|
+
/**
|
|
8
|
+
* Where THIS renderer reads a file's bytes from.
|
|
9
|
+
*
|
|
10
|
+
* In the app: the workspace raw file route under the session, for the
|
|
11
|
+
* workspace the renderer is pointed at and the save it is bound to — which
|
|
12
|
+
* every byte-reading viewer here used to spell out for itself, five times
|
|
13
|
+
* over, each one re-deriving the version-ref rules. On a
|
|
14
|
+
* {@link RendererSurface} (the embed): that surface's own route, with its own
|
|
15
|
+
* credential, because there is no session to send.
|
|
16
|
+
*
|
|
17
|
+
* Null while there is no workspace to read from, which is the same "nothing
|
|
18
|
+
* to read yet" every caller already handled.
|
|
19
|
+
*/
|
|
20
|
+
export function useRendererRawRead(): RendererRawRead | null {
|
|
21
|
+
const surface = useRendererSurface();
|
|
22
|
+
const workspaceId = useRendererWorkspaceId();
|
|
23
|
+
const fileRef = useRendererFileRef();
|
|
24
|
+
// The save as PRIMITIVES, so the memo depends on exactly what it reads
|
|
25
|
+
// rather than on a context object a provider may rebuild per render.
|
|
26
|
+
const versionRef = fileRef?.ref ?? null;
|
|
27
|
+
const versionSide = fileRef?.side;
|
|
28
|
+
return useMemo<RendererRawRead | null>(() => {
|
|
29
|
+
if (surface) {
|
|
30
|
+
// A surface shows one page's working tree and has no history to point
|
|
31
|
+
// at, so it is never pinned to a save.
|
|
32
|
+
return {
|
|
33
|
+
url: (path, options) => surface.rawUrl(path, options),
|
|
34
|
+
fetch: (path, options) => surface.rawFetch(path, options),
|
|
35
|
+
pinnedToVersion: false,
|
|
36
|
+
};
|
|
37
|
+
}
|
|
38
|
+
if (!workspaceId) return null;
|
|
39
|
+
const url = (path: string, options?: { version?: number }) =>
|
|
40
|
+
rawFileUrl(
|
|
41
|
+
workspaceId,
|
|
42
|
+
path,
|
|
43
|
+
versionRef === null
|
|
44
|
+
? { version: options?.version }
|
|
45
|
+
: { ref: versionRef, side: versionSide },
|
|
46
|
+
);
|
|
47
|
+
return {
|
|
48
|
+
url,
|
|
49
|
+
fetch: (path, options) => authFetch(url(path, options), { signal: options?.signal }),
|
|
50
|
+
pinnedToVersion: versionRef !== null,
|
|
51
|
+
};
|
|
52
|
+
}, [surface, workspaceId, versionRef, versionSide]);
|
|
53
|
+
}
|
|
@@ -0,0 +1,109 @@
|
|
|
1
|
+
import { createContext, useContext } from 'react';
|
|
2
|
+
|
|
3
|
+
/**
|
|
4
|
+
* A surface that mounts the app's file renderers OUTSIDE the app.
|
|
5
|
+
*
|
|
6
|
+
* Every renderer in this folder asks its surroundings for exactly two things
|
|
7
|
+
* beyond its props: where a file's BYTES come from, and what happens when
|
|
8
|
+
* somebody CLICKS A LINK. Inside the app both answers come from the
|
|
9
|
+
* providers — the raw file route under the session cookie, and react-router
|
|
10
|
+
* navigation — and nothing needs this context.
|
|
11
|
+
*
|
|
12
|
+
* The embed is the surface where both answers are different, and neither is a
|
|
13
|
+
* variation of the app's:
|
|
14
|
+
*
|
|
15
|
+
* - Bytes come from `/api/embed/raw`, authenticated by the embed token and
|
|
16
|
+
* nothing else. There is no session: the page is framed by a host, and a
|
|
17
|
+
* cookie that travelled into that frame is exactly what the token-only
|
|
18
|
+
* rule exists to prevent.
|
|
19
|
+
* - A link must open the APP IN A NEW TAB, through the host, and must never
|
|
20
|
+
* navigate the embed. The embed is one page deep by decision; navigating
|
|
21
|
+
* it would show a page no token was minted for, inside a frame whose
|
|
22
|
+
* reader has no way back.
|
|
23
|
+
*
|
|
24
|
+
* So this is an INDIRECTION, not a feature flag: with no surface the hooks
|
|
25
|
+
* below behave exactly as they always have, and the renderers are unchanged.
|
|
26
|
+
* It is deliberately the narrowest thing that works — four verbs and a URL
|
|
27
|
+
* builder — rather than a stand-in `WorkspaceContextValue`, which would be
|
|
28
|
+
* forty methods that mutate a working tree the embed must never touch, and a
|
|
29
|
+
* lie about what the page can do.
|
|
30
|
+
*/
|
|
31
|
+
export interface RendererSurface {
|
|
32
|
+
/**
|
|
33
|
+
* The knowledge-base directory name, for the link and image grammar
|
|
34
|
+
* (`resolveKbHref`). The app reads it from the workspace; the embed is told
|
|
35
|
+
* it by the load.
|
|
36
|
+
*/
|
|
37
|
+
kbDirName: string;
|
|
38
|
+
/**
|
|
39
|
+
* Follow a link destination written inside `basePath`: a knowledge-base
|
|
40
|
+
* page, or an external address. The embed opens both in a new tab through
|
|
41
|
+
* its host.
|
|
42
|
+
*/
|
|
43
|
+
openLink(href: string, basePath: string): void;
|
|
44
|
+
/**
|
|
45
|
+
* Open a workspace PATH — one that came from a file tree, not a link — taken
|
|
46
|
+
* verbatim: no anchor split, no repair, `#` is part of the name.
|
|
47
|
+
*/
|
|
48
|
+
openWorkspacePath(workspacePath: string): void;
|
|
49
|
+
/** Follow a node-id link (`<id>` or `<id#heading>`), the copy-link form. */
|
|
50
|
+
openNodeId(idOrLink: string): void;
|
|
51
|
+
/** The absolute, shareable address of `workspacePath` — what a copy-link yields. */
|
|
52
|
+
canonicalUrlFor(workspacePath: string): string | null;
|
|
53
|
+
/** The URL that serves `workspacePath`'s bytes on this surface. */
|
|
54
|
+
rawUrl(workspacePath: string, options?: { version?: number }): string;
|
|
55
|
+
/** Fetch those bytes with whatever credential this surface carries. */
|
|
56
|
+
rawFetch(
|
|
57
|
+
workspacePath: string,
|
|
58
|
+
options?: { version?: number; signal?: AbortSignal },
|
|
59
|
+
): Promise<Response>;
|
|
60
|
+
/**
|
|
61
|
+
* Whether this surface offers the original bytes as a DOWNLOAD.
|
|
62
|
+
*
|
|
63
|
+
* `download:` is a verb of its own in the app, resolved per path, and the
|
|
64
|
+
* embed has no route that resolves it — so the embed says NO and the button
|
|
65
|
+
* is not drawn at all. Not drawn, rather than drawn and disabled: a
|
|
66
|
+
* disabled control reads as "you may not", and the reader may well read the
|
|
67
|
+
* page perfectly fine. There is simply no download here.
|
|
68
|
+
*/
|
|
69
|
+
offersDownload: boolean;
|
|
70
|
+
}
|
|
71
|
+
|
|
72
|
+
export const RendererSurfaceContext = createContext<RendererSurface | null>(null);
|
|
73
|
+
|
|
74
|
+
/**
|
|
75
|
+
* The surface a renderer is mounted on, or null inside the app.
|
|
76
|
+
*
|
|
77
|
+
* Never throws and needs no provider: "I am in the app" is the answer for
|
|
78
|
+
* every surface but one, and a hook that threw here would make the context
|
|
79
|
+
* mandatory for the whole renderer folder.
|
|
80
|
+
*/
|
|
81
|
+
export function useRendererSurface(): RendererSurface | null {
|
|
82
|
+
return useContext(RendererSurfaceContext);
|
|
83
|
+
}
|
|
84
|
+
|
|
85
|
+
/**
|
|
86
|
+
* How a renderer reads a file's bytes on the surface it is mounted on.
|
|
87
|
+
*
|
|
88
|
+
* `url` for the places a URL is the whole interface — an `<img src>`, an
|
|
89
|
+
* `<object>`, a markdown picture — and `fetch` for the viewers that read the
|
|
90
|
+
* bytes themselves (a PDF, a workbook, a deck, a message).
|
|
91
|
+
*/
|
|
92
|
+
export interface RendererRawRead {
|
|
93
|
+
url(workspacePath: string, options?: { version?: number }): string;
|
|
94
|
+
fetch(
|
|
95
|
+
workspacePath: string,
|
|
96
|
+
options?: { version?: number; signal?: AbortSignal },
|
|
97
|
+
): Promise<Response>;
|
|
98
|
+
/**
|
|
99
|
+
* Whether this read is pinned to a PAST SAVE rather than the working tree.
|
|
100
|
+
*
|
|
101
|
+
* The image viewers fold the workspace image revision into the URL so a
|
|
102
|
+
* replaced picture reaches an open tab. On a past save that is worse than
|
|
103
|
+
* useless: the bytes at a commit cannot change, so the revision would only
|
|
104
|
+
* defeat the browser cache — and it bumps on every save of the file, which
|
|
105
|
+
* for a version pane means re-reading a version that is not what changed.
|
|
106
|
+
* So a pinned read says so, and the revision is dropped.
|
|
107
|
+
*/
|
|
108
|
+
pinnedToVersion: boolean;
|
|
109
|
+
}
|
|
@@ -1,5 +1,6 @@
|
|
|
1
1
|
import { createContext, useContext } from 'react';
|
|
2
2
|
import { WorkspaceContext } from '../../state/workspace.context';
|
|
3
|
+
import { RendererSurfaceContext } from './rendererSurface';
|
|
3
4
|
|
|
4
5
|
/**
|
|
5
6
|
* A PAST SAVE the renderers should read instead of the working tree.
|
|
@@ -50,13 +51,18 @@ export const RendererWorkspaceContext = createContext<{
|
|
|
50
51
|
* The workspace id the renderer should read from: the override when one is
|
|
51
52
|
* provided, otherwise the checked-out workspace.
|
|
52
53
|
*
|
|
53
|
-
* Throws when neither is present
|
|
54
|
-
* with no workspace at all would
|
|
54
|
+
* Throws when neither is present and no renderer surface is either, exactly
|
|
55
|
+
* as `useWorkspace()` did — a renderer with no workspace at all would
|
|
56
|
+
* otherwise sit on "Loading…" forever. Under a surface it answers null.
|
|
55
57
|
*/
|
|
56
58
|
export function useRendererWorkspaceId(): string | null {
|
|
57
59
|
const override = useContext(RendererWorkspaceContext);
|
|
58
60
|
const workspace = useContext(WorkspaceContext);
|
|
61
|
+
const surface = useContext(RendererSurfaceContext);
|
|
59
62
|
if (override !== null) return override.workspaceId;
|
|
63
|
+
// A surface (the embed) stands alone: its bytes come through the surface,
|
|
64
|
+
// so "no workspace" is an answer there, not a mounting mistake.
|
|
65
|
+
if (workspace === null && surface !== null) return null;
|
|
60
66
|
if (workspace === null) {
|
|
61
67
|
throw new Error(
|
|
62
68
|
'useRendererWorkspaceId must be used within WorkspaceContext.Provider or RendererWorkspaceContext.Provider',
|
|
@@ -1,5 +1,6 @@
|
|
|
1
1
|
import { describe, it, expect, vi, beforeEach, afterEach } from 'vitest';
|
|
2
|
-
import { renderHook, act, waitFor } from '@testing-library/react';
|
|
2
|
+
import { renderHook, act, waitFor, screen, within, fireEvent } from '@testing-library/react';
|
|
3
|
+
import { ConfirmProvider } from '../../../../shared/components';
|
|
3
4
|
|
|
4
5
|
// Build a single error class shared between the mock module and the tests.
|
|
5
6
|
// Hoisted so vi.mock can reach it during module initialization, before the
|
|
@@ -102,7 +103,10 @@ describe('useWorkspaceState multi-tab', () => {
|
|
|
102
103
|
});
|
|
103
104
|
|
|
104
105
|
async function mountReady() {
|
|
105
|
-
|
|
106
|
+
// The unsaved-work questions are the app's own dialog, hosted here.
|
|
107
|
+
const { result } = renderHook(() => useWorkspaceState(), {
|
|
108
|
+
wrapper: ({ children }: { children: ReactNode }) => <ConfirmProvider>{children}</ConfirmProvider>,
|
|
109
|
+
});
|
|
106
110
|
await waitFor(() => expect(result.current.workspaceId).toBe('ws-1'));
|
|
107
111
|
return result;
|
|
108
112
|
}
|
|
@@ -143,29 +147,112 @@ describe('useWorkspaceState multi-tab', () => {
|
|
|
143
147
|
expect(tabA?.isDirty).toBe(true);
|
|
144
148
|
});
|
|
145
149
|
|
|
146
|
-
|
|
150
|
+
/** Answer the app's open dialog by pressing one of its buttons. */
|
|
151
|
+
async function answer(button: string, text?: RegExp) {
|
|
152
|
+
const dialog = await screen.findByRole('dialog');
|
|
153
|
+
if (text) expect(dialog.textContent).toMatch(text);
|
|
154
|
+
// A per-tab question is never one you can switch off.
|
|
155
|
+
expect(within(dialog).queryByText("Don't ask again")).toBeNull();
|
|
156
|
+
fireEvent.click(within(dialog).getByRole('button', { name: button }));
|
|
157
|
+
}
|
|
158
|
+
|
|
159
|
+
it("closeTab asks in the app's dialog when the tab is dirty; Cancel keeps it, Close closes it", async () => {
|
|
160
|
+
// The browser's dialogs suppressed: a stubbed confirm that always says no
|
|
161
|
+
// must never be what answers.
|
|
147
162
|
const confirmSpy = vi.spyOn(window, 'confirm').mockReturnValue(false);
|
|
148
163
|
const result = await mountReady();
|
|
149
164
|
await act(async () => { await result.current.addTab('Knowledge/A.md'); });
|
|
150
165
|
await act(async () => { result.current.setHasUnsavedFileChanges?.(true); });
|
|
151
166
|
|
|
152
167
|
const tabA = result.current.openTabs[0];
|
|
153
|
-
|
|
154
|
-
|
|
155
|
-
|
|
156
|
-
});
|
|
157
|
-
expect(
|
|
158
|
-
'You have unsaved changes in A.md. Close anyway?',
|
|
159
|
-
);
|
|
168
|
+
let closing!: Promise<{ closed: boolean }>;
|
|
169
|
+
act(() => { closing = result.current.closeTab(tabA); });
|
|
170
|
+
await answer('Cancel', /You have unsaved changes in A\.md\. Close anyway\?/);
|
|
171
|
+
await act(async () => { expect((await closing).closed).toBe(false); });
|
|
172
|
+
expect(screen.queryByRole('dialog')).toBeNull();
|
|
160
173
|
expect(result.current.openTabs).toHaveLength(1);
|
|
161
174
|
|
|
162
|
-
|
|
163
|
-
await
|
|
164
|
-
|
|
165
|
-
expect(result2.closed).toBe(true);
|
|
166
|
-
});
|
|
175
|
+
act(() => { closing = result.current.closeTab(tabA); });
|
|
176
|
+
await answer('Close anyway');
|
|
177
|
+
await act(async () => { expect((await closing).closed).toBe(true); });
|
|
167
178
|
expect(result.current.openTabs).toHaveLength(0);
|
|
168
179
|
expect(result.current.activeTab).toBeNull();
|
|
180
|
+
expect(confirmSpy).not.toHaveBeenCalled();
|
|
181
|
+
});
|
|
182
|
+
|
|
183
|
+
it('closeTab counts Escape as Cancel', async () => {
|
|
184
|
+
const result = await mountReady();
|
|
185
|
+
await act(async () => { await result.current.addTab('Knowledge/A.md'); });
|
|
186
|
+
await act(async () => { result.current.setHasUnsavedFileChanges?.(true); });
|
|
187
|
+
let closing!: Promise<{ closed: boolean }>;
|
|
188
|
+
act(() => { closing = result.current.closeTab(result.current.openTabs[0]); });
|
|
189
|
+
await screen.findByRole('dialog');
|
|
190
|
+
fireEvent.keyDown(document, { key: 'Escape' });
|
|
191
|
+
await act(async () => { expect((await closing).closed).toBe(false); });
|
|
192
|
+
expect(result.current.openTabs).toHaveLength(1);
|
|
193
|
+
});
|
|
194
|
+
|
|
195
|
+
it('closeTab asks once when the same dirty tab is closed twice while asking', async () => {
|
|
196
|
+
const result = await mountReady();
|
|
197
|
+
await act(async () => { await result.current.addTab('Knowledge/A.md'); });
|
|
198
|
+
await act(async () => { result.current.setHasUnsavedFileChanges?.(true); });
|
|
199
|
+
const tabA = result.current.openTabs[0];
|
|
200
|
+
let first!: Promise<{ closed: boolean }>;
|
|
201
|
+
let second!: Promise<{ closed: boolean }>;
|
|
202
|
+
act(() => {
|
|
203
|
+
first = result.current.closeTab(tabA);
|
|
204
|
+
second = result.current.closeTab(tabA);
|
|
205
|
+
});
|
|
206
|
+
await act(async () => { expect((await second).closed).toBe(false); });
|
|
207
|
+
await answer('Close anyway');
|
|
208
|
+
await act(async () => { expect((await first).closed).toBe(true); });
|
|
209
|
+
expect(screen.queryByRole('dialog')).toBeNull();
|
|
210
|
+
expect(result.current.openTabs).toHaveLength(0);
|
|
211
|
+
});
|
|
212
|
+
|
|
213
|
+
it('closeTab closes nothing when the workspace moved to another branch while it asked', async () => {
|
|
214
|
+
apiMocks.getOrCreateWorkspace.mockResolvedValue({
|
|
215
|
+
...WORKSPACE_FIXTURE,
|
|
216
|
+
workspace: { ...WORKSPACE_FIXTURE.workspace, id: 'main' },
|
|
217
|
+
});
|
|
218
|
+
const { result } = renderHook(() => useWorkspaceState(), {
|
|
219
|
+
wrapper: ({ children }: { children: ReactNode }) => <ConfirmProvider>{children}</ConfirmProvider>,
|
|
220
|
+
});
|
|
221
|
+
await waitFor(() => expect(result.current.workspaceId).toBe('main'));
|
|
222
|
+
act(() => { result.current.setPersistenceBranch('main'); });
|
|
223
|
+
await act(async () => { await result.current.addTab('Knowledge/A.md'); });
|
|
224
|
+
await act(async () => { result.current.setHasUnsavedFileChanges?.(true); });
|
|
225
|
+
let closing!: Promise<{ closed: boolean }>;
|
|
226
|
+
act(() => { closing = result.current.closeTab(result.current.openTabs[0]); });
|
|
227
|
+
await screen.findByRole('dialog');
|
|
228
|
+
|
|
229
|
+
// The person switches branch with the question still up, and the same
|
|
230
|
+
// path is open there.
|
|
231
|
+
apiMocks.getOrCreateWorkspace.mockResolvedValue({
|
|
232
|
+
...WORKSPACE_FIXTURE,
|
|
233
|
+
workspace: { ...WORKSPACE_FIXTURE.workspace, id: 'alice%2Fdraft' },
|
|
234
|
+
});
|
|
235
|
+
act(() => { result.current.setPersistenceBranch('alice/draft'); });
|
|
236
|
+
await waitFor(() => expect(result.current.workspaceId).toBe('alice%2Fdraft'));
|
|
237
|
+
await act(async () => { await result.current.addTab('Knowledge/A.md'); });
|
|
238
|
+
|
|
239
|
+
await answer('Close anyway');
|
|
240
|
+
await act(async () => { expect((await closing).closed).toBe(false); });
|
|
241
|
+
expect(result.current.openTabs.map((t) => t.path)).toEqual(['Knowledge/A.md']);
|
|
242
|
+
});
|
|
243
|
+
|
|
244
|
+
it('a bulk close pinned to a workspace that moved on closes nothing', async () => {
|
|
245
|
+
const result = await mountReady();
|
|
246
|
+
await act(async () => { await result.current.addTab('Knowledge/A.md'); });
|
|
247
|
+
let outcome!: { closed: boolean };
|
|
248
|
+
await act(async () => {
|
|
249
|
+
outcome = await result.current.closeTab(result.current.openTabs[0], {
|
|
250
|
+
skipConfirm: true,
|
|
251
|
+
workspaceId: 'some-other-branch',
|
|
252
|
+
});
|
|
253
|
+
});
|
|
254
|
+
expect(outcome.closed).toBe(false);
|
|
255
|
+
expect(result.current.openTabs).toHaveLength(1);
|
|
169
256
|
});
|
|
170
257
|
|
|
171
258
|
it('closeTab activates the left neighbor when closing the active tab', async () => {
|
|
@@ -202,20 +289,38 @@ describe('useWorkspaceState multi-tab', () => {
|
|
|
202
289
|
expect(result.current.openTabs.map((t) => t.path)).toEqual(['keep.md']);
|
|
203
290
|
});
|
|
204
291
|
|
|
205
|
-
it('deleteEntry sweeps tabs under a deleted directory and
|
|
206
|
-
const confirmSpy = vi.spyOn(window, 'confirm').mockReturnValue(
|
|
292
|
+
it('deleteEntry sweeps tabs under a deleted directory and asks once for dirty', async () => {
|
|
293
|
+
const confirmSpy = vi.spyOn(window, 'confirm').mockReturnValue(false);
|
|
207
294
|
const result = await mountReady();
|
|
208
295
|
await act(async () => { await result.current.addTab('Knowledge/keep.md'); });
|
|
209
296
|
await act(async () => { await result.current.addTab('OldDir/a.md'); });
|
|
210
297
|
await act(async () => { result.current.setHasUnsavedFileChanges?.(true); });
|
|
211
298
|
await act(async () => { await result.current.addTab('OldDir/b.md'); });
|
|
212
299
|
|
|
213
|
-
|
|
300
|
+
let deleting!: Promise<unknown>;
|
|
301
|
+
act(() => { deleting = result.current.deleteEntry('OldDir'); });
|
|
302
|
+
// Today's bulk question, by basename, not full path.
|
|
303
|
+
await answer('Close anyway', /You have unsaved changes in:\n {2}- a\.md\nClose anyway\?/);
|
|
304
|
+
await act(async () => { await deleting; });
|
|
214
305
|
|
|
215
|
-
expect(
|
|
216
|
-
|
|
217
|
-
expect(confirmSpy.mock.calls[0][0]).toMatch(/a\.md/);
|
|
306
|
+
expect(screen.queryAllByRole('dialog')).toHaveLength(0);
|
|
307
|
+
expect(apiMocks.deleteFile).toHaveBeenCalledWith('ws-1', 'OldDir');
|
|
218
308
|
expect(result.current.openTabs.map((t) => t.path)).toEqual(['Knowledge/keep.md']);
|
|
309
|
+
expect(confirmSpy).not.toHaveBeenCalled();
|
|
310
|
+
});
|
|
311
|
+
|
|
312
|
+
it('deleteEntry keeps everything when the unsaved-tabs question is cancelled', async () => {
|
|
313
|
+
const result = await mountReady();
|
|
314
|
+
await act(async () => { await result.current.addTab('OldDir/a.md'); });
|
|
315
|
+
await act(async () => { result.current.setHasUnsavedFileChanges?.(true); });
|
|
316
|
+
|
|
317
|
+
let deleting!: Promise<unknown>;
|
|
318
|
+
act(() => { deleting = result.current.deleteEntry('OldDir'); });
|
|
319
|
+
await answer('Cancel');
|
|
320
|
+
await act(async () => { expect(await deleting).toBe(false); });
|
|
321
|
+
|
|
322
|
+
expect(apiMocks.deleteFile).not.toHaveBeenCalled();
|
|
323
|
+
expect(result.current.openTabs.map((t) => t.path)).toEqual(['OldDir/a.md']);
|
|
219
324
|
});
|
|
220
325
|
|
|
221
326
|
it('moveEntry rewrites tab paths in place', async () => {
|