@bevel-software/platform-core-frontend 0.33.0 → 0.34.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/lib/__tests__/api.test.ts +28 -1
- package/src/lib/api.ts +4 -2
- package/src/modules/access/__tests__/ManageAccessDialog.add-row-picking.test.tsx +53 -1
- package/src/modules/access/api.ts +3 -4
- package/src/modules/access/components/ManageAccessDialog.tsx +7 -7
- package/src/modules/admin/__tests__/DirectoryGroupsPage.test.tsx +51 -0
- package/src/modules/admin/components/DirectoryGroupsPage.tsx +42 -5
- package/src/modules/admin/services/groups.api.ts +11 -1
- package/src/modules/agents/__tests__/useConnectAsChoice.test.ts +56 -0
- package/src/modules/agents/components/ConnectAsChoice.tsx +81 -0
- package/src/modules/agents/connect-as.ts +15 -0
- package/src/modules/agents/index.ts +5 -0
- package/src/modules/agents/services/agent-choices.api.ts +39 -0
- package/src/modules/agents/useConnectAsChoice.ts +66 -0
- package/src/modules/audit/__tests__/AuditLogPage.test.tsx +13 -0
- package/src/modules/audit/components/AuditLogPage.tsx +9 -0
- package/src/modules/audit/services/audit.api.ts +5 -0
- package/src/modules/auth/__tests__/AccountPage.test.tsx +21 -0
- package/src/modules/auth/__tests__/account.api.test.ts +69 -0
- package/src/modules/auth/components/AccountPage.tsx +8 -2
- package/src/modules/auth/services/account.api.ts +18 -2
- package/src/modules/git/__tests__/BranchSwitcher.test.tsx +0 -14
- package/src/modules/git/__tests__/git.api.test.ts +2 -2
- package/src/modules/git/hooks/__tests__/useGitState.deleteBranch.test.tsx +1 -1
- package/src/modules/library/__tests__/SkillPage.test.tsx +229 -24
- package/src/modules/library/components/skill-page/SkillFilePane.tsx +57 -9
- package/src/modules/library/components/skill-page/SkillPage.tsx +65 -25
- package/src/modules/review/components/MarkdownDiffViewer.tsx +23 -1
- package/src/modules/review/components/ReviewPanel.tsx +8 -2
- package/src/modules/review/components/__tests__/MarkdownDiffViewer.test.tsx +31 -0
- package/src/modules/secrets-vault/components/ConnectToolsPage.tsx +79 -16
- package/src/modules/secrets-vault/components/__tests__/ConnectToolsPage.test.tsx +112 -2
- package/src/modules/secrets-vault/services/connect.api.ts +20 -5
- package/src/modules/toolbar/components/ExternalAgentAccessPage.tsx +38 -4
- package/src/modules/toolbar/components/__tests__/ExternalAgentAccessPage.test.tsx +91 -2
- package/src/modules/toolbar/services/external-api-keys.api.ts +5 -2
- package/src/modules/workspace/components/__tests__/FileExplorer.test.tsx +26 -0
- package/src/modules/workspace/components/renderers/HtmlRenderer.tsx +40 -7
- package/src/modules/workspace/components/renderers/KbAppLink.tsx +56 -0
- package/src/modules/workspace/components/renderers/KbMarkdownView.tsx +30 -10
- package/src/modules/workspace/components/renderers/MarkdownRenderer.tsx +37 -40
- package/src/modules/workspace/components/renderers/__tests__/HtmlRenderer.links.test.tsx +185 -0
- package/src/modules/workspace/components/renderers/__tests__/MarkdownRenderer.sectionReclick.test.tsx +88 -0
- package/src/modules/workspace/components/renderers/__tests__/MarkdownRenderer.test.tsx +199 -29
- package/src/modules/workspace/components/renderers/__tests__/bridgeHarness.ts +37 -4
- package/src/modules/workspace/components/renderers/__tests__/htmlSandbox.test.ts +59 -0
- package/src/modules/workspace/components/renderers/__tests__/htmlViewsGuide.test.ts +15 -1
- package/src/modules/workspace/components/renderers/__tests__/liveDataReferencePage.test.ts +397 -0
- package/src/modules/workspace/components/renderers/htmlSandbox.ts +48 -15
- package/src/modules/workspace/components/renderers/htmlToolBridge.ts +19 -0
- package/src/modules/workspace/components/renderers/kbMarkdownPipeline.tsx +35 -28
- package/src/modules/workspace/components/renderers/scrollToHeading.ts +35 -0
- package/src/modules/workspace/hooks/__tests__/useLinksOut.test.ts +6 -0
- package/src/modules/workspace/hooks/useLinksOut.ts +12 -6
- package/src/modules/workspace/index.ts +21 -2
- package/src/modules/workspace/routing/__tests__/kb-routes.test.tsx +262 -25
- package/src/modules/workspace/routing/kb-routes.ts +221 -53
- package/src/modules/workspace/utils/fileTree.ts +1 -1
|
@@ -3,6 +3,7 @@ import { useLocation, useNavigate } from 'react-router-dom';
|
|
|
3
3
|
import { GitContext } from '../../git';
|
|
4
4
|
import { WorkspaceContext } from '../state/workspace.context';
|
|
5
5
|
import { useRendererSurface } from '../components/renderers/rendererSurface';
|
|
6
|
+
import type { KbLinkTarget } from '../components/renderers/KbAppLink';
|
|
6
7
|
import { authFetch } from '../../../lib/api';
|
|
7
8
|
import {
|
|
8
9
|
isExternalHref,
|
|
@@ -149,23 +150,22 @@ export function fetchNodeId(branch: string, workspacePath: string): Promise<stri
|
|
|
149
150
|
}
|
|
150
151
|
|
|
151
152
|
/**
|
|
152
|
-
* The
|
|
153
|
-
*
|
|
154
|
-
*
|
|
155
|
-
*
|
|
156
|
-
*
|
|
157
|
-
*
|
|
153
|
+
* The frontmatter id of the file at `workspacePath` on the checked-out branch,
|
|
154
|
+
* as the backend answers it ({@link fetchNodeId}), or null — not a node, not
|
|
155
|
+
* resolved yet, or a renderer surface, which has no git status to ask with.
|
|
156
|
+
* `onBranch` names another branch the file was read from: the skill page
|
|
157
|
+
* renders its files from the default branch whatever is checked out.
|
|
158
|
+
* The one answer to "which node is this file", shared by the copy-link URL
|
|
159
|
+
* below and the id-link rule in {@link useNodeIdNav}, so neither re-reads the
|
|
160
|
+
* frontmatter its own way.
|
|
158
161
|
*/
|
|
159
|
-
export function
|
|
160
|
-
// A surface outside the app knows the address of the file it is showing —
|
|
161
|
-
// it was told it by whatever opened it — and has no git status to resolve
|
|
162
|
-
// one from. Asked FIRST, and before `useGit`, which has no provider there.
|
|
162
|
+
export function useFileNodeId(workspacePath: string | null, onBranch?: string): string | null {
|
|
163
163
|
const surface = useRendererSurface();
|
|
164
164
|
const git = useContext(GitContext);
|
|
165
|
-
const branch = surface ? null : (git?.status?.branch ?? null);
|
|
165
|
+
const branch = surface ? null : (onBranch ?? git?.status?.branch ?? null);
|
|
166
166
|
// Tie the resolved id to the exact (branch, path) it was fetched for. Inputs
|
|
167
|
-
// change a render before the effect re-resolves, so without this key the
|
|
168
|
-
// would briefly pair the new path with the *previous* node's id.
|
|
167
|
+
// change a render before the effect re-resolves, so without this key the
|
|
168
|
+
// answer would briefly pair the new path with the *previous* node's id.
|
|
169
169
|
const key = branch && workspacePath ? `${branch}\n${workspacePath}` : null;
|
|
170
170
|
const [resolved, setResolved] = useState<{ key: string; id: string | null } | null>(null);
|
|
171
171
|
|
|
@@ -181,9 +181,28 @@ export function useCanonicalFileUrl(workspacePath: string | null): string | null
|
|
|
181
181
|
};
|
|
182
182
|
}, [key, branch, workspacePath]);
|
|
183
183
|
|
|
184
|
+
return resolved && resolved.key === key ? resolved.id : null;
|
|
185
|
+
}
|
|
186
|
+
|
|
187
|
+
/**
|
|
188
|
+
* The canonical absolute URL for a file, for the "copy link" affordances: a node's
|
|
189
|
+
* id URL (`<origin>/workspace/<branch>/<id>`) when the file is an id-bearing node,
|
|
190
|
+
* else its path URL. Resolves the id in the background and falls back to the path
|
|
191
|
+
* URL until it resolves (and permanently for non-node files). Null when there's no
|
|
192
|
+
* branch or path yet. Callers append any `#heading` themselves. This makes copied
|
|
193
|
+
* links id-based on their own, independent of the `FileRoute` path→id redirect.
|
|
194
|
+
*/
|
|
195
|
+
export function useCanonicalFileUrl(workspacePath: string | null): string | null {
|
|
196
|
+
// A surface outside the app knows the address of the file it is showing —
|
|
197
|
+
// it was told it by whatever opened it — and has no git status to resolve
|
|
198
|
+
// one from. Asked FIRST, and before `useGit`, which has no provider there.
|
|
199
|
+
const surface = useRendererSurface();
|
|
200
|
+
const git = useContext(GitContext);
|
|
201
|
+
const branch = surface ? null : (git?.status?.branch ?? null);
|
|
202
|
+
const nodeId = useFileNodeId(workspacePath);
|
|
203
|
+
|
|
184
204
|
if (surface) return workspacePath ? surface.canonicalUrlFor(workspacePath) : null;
|
|
185
205
|
if (!branch || !workspacePath) return null;
|
|
186
|
-
const nodeId = resolved && resolved.key === key ? resolved.id : null;
|
|
187
206
|
const relative = nodeId ? kbNodeUrl(branch, nodeId) : kbFileUrl(branch, workspacePath);
|
|
188
207
|
return `${window.location.origin}${relative}`;
|
|
189
208
|
}
|
|
@@ -329,6 +348,60 @@ export function openExternalHref(href: string): boolean {
|
|
|
329
348
|
return true;
|
|
330
349
|
}
|
|
331
350
|
|
|
351
|
+
/**
|
|
352
|
+
* Open an in-app address in a new tab: the one way a link inside rendered
|
|
353
|
+
* file content leaves the file it sits in. The tab gets the plain address;
|
|
354
|
+
* whatever view this tab is in (full screen, a query of its own) stays here.
|
|
355
|
+
*
|
|
356
|
+
* `window.open(url, '_blank', 'noopener')` answers `null` whether or not the
|
|
357
|
+
* tab opened, so a tab the browser refused (no user gesture left, a popup
|
|
358
|
+
* blocker) would be a click swallowed without a word. The tab is opened
|
|
359
|
+
* without the feature instead and its `opener` severed at once: the address
|
|
360
|
+
* is this app's own, and a tab just opened has run nothing before this line.
|
|
361
|
+
*/
|
|
362
|
+
function openInNewTab(url: string): void {
|
|
363
|
+
const opened = window.open(url, '_blank');
|
|
364
|
+
if (!opened) {
|
|
365
|
+
console.warn(`[useFileNav] the browser did not open a new tab for ${url}`);
|
|
366
|
+
return;
|
|
367
|
+
}
|
|
368
|
+
opened.opener = null;
|
|
369
|
+
}
|
|
370
|
+
|
|
371
|
+
/** Follow a content link where its target says: a new tab, or this tab by its fragment. */
|
|
372
|
+
function followLinkTarget(target: KbLinkTarget | null, navigate: (to: string) => void): void {
|
|
373
|
+
if (!target) return;
|
|
374
|
+
if (target.newTab) openInNewTab(target.href);
|
|
375
|
+
else navigate(target.href);
|
|
376
|
+
}
|
|
377
|
+
|
|
378
|
+
/**
|
|
379
|
+
* A link to the file on screen: this tab's OWN address with the link's
|
|
380
|
+
* fragment — an id URL stays an id URL, and the query (`?fullscreen=1`)
|
|
381
|
+
* stays — so following it scrolls and changes nothing else.
|
|
382
|
+
*/
|
|
383
|
+
function sectionOfThisTab(location: { pathname: string; search: string }, hash: string): KbLinkTarget {
|
|
384
|
+
return { href: location.pathname + location.search + hash, newTab: false };
|
|
385
|
+
}
|
|
386
|
+
|
|
387
|
+
const noLinkTarget = (): KbLinkTarget | null => null;
|
|
388
|
+
|
|
389
|
+
/** How `useFileNav().openLink` follows one link, beyond the rule itself. */
|
|
390
|
+
export interface OpenLinkOptions {
|
|
391
|
+
/** The branch the link's file was read from, when not this tab's (see `linkTarget`). */
|
|
392
|
+
homeBranch?: string;
|
|
393
|
+
/** Follow a link to a section of the same file here, given its fragment, instead of moving this tab. */
|
|
394
|
+
onSection?(hash: string): void;
|
|
395
|
+
/**
|
|
396
|
+
* The reader asked for a new tab — a modified or middle click a host had
|
|
397
|
+
* to relay, because it could not leave the click to the browser (the HTML
|
|
398
|
+
* page's sandboxed frame). Every in-app destination then opens in a new
|
|
399
|
+
* tab at its plain address, a section of this file included, as the
|
|
400
|
+
* browser opens a new-tab link: this tab stays as it is.
|
|
401
|
+
*/
|
|
402
|
+
newTab?: boolean;
|
|
403
|
+
}
|
|
404
|
+
|
|
332
405
|
/**
|
|
333
406
|
* The branch segment of a `/workspace/<branch>/…` pathname, decoded, or null
|
|
334
407
|
* when this location is not a workspace URL. The pathname from the router is
|
|
@@ -395,6 +468,34 @@ export function useFileNav() {
|
|
|
395
468
|
[branch, kbDirName, navigate],
|
|
396
469
|
);
|
|
397
470
|
|
|
471
|
+
/**
|
|
472
|
+
* Where an in-app link destination written inside `basePath` leads, as
|
|
473
|
+
* {@link openLink} follows it: the file it sits in keeps THIS tab's own
|
|
474
|
+
* address with the link's fragment (an id URL stays an id URL, and the
|
|
475
|
+
* query — `?fullscreen=1` — stays), any other file opens in a new tab at
|
|
476
|
+
* its plain `kbFileUrl`. Null for an external or unresolvable destination,
|
|
477
|
+
* which is not this rule's.
|
|
478
|
+
*
|
|
479
|
+
* `homeBranch` is the branch the file the link sits in was read from, when
|
|
480
|
+
* that is not the branch this tab stands on: the skill page renders its
|
|
481
|
+
* files from the default branch whatever is checked out, so a relative link
|
|
482
|
+
* there resolves on the default branch. Omitted, it is this tab's branch.
|
|
483
|
+
*/
|
|
484
|
+
const linkTarget = useCallback(
|
|
485
|
+
(href: string, basePath: string, homeBranch?: string): KbLinkTarget | null => {
|
|
486
|
+
const target = resolveKbHref(href, { basePath, kbDirName });
|
|
487
|
+
if (target?.kind !== 'workspace') return null;
|
|
488
|
+
const home = homeBranch ?? branch;
|
|
489
|
+
const onBranch = target.branch ?? home;
|
|
490
|
+
if (!onBranch) return null;
|
|
491
|
+
if (onBranch === home && target.path === basePath) {
|
|
492
|
+
return sectionOfThisTab(location, target.hash);
|
|
493
|
+
}
|
|
494
|
+
return { href: kbFileUrl(onBranch, target.path) + target.hash, newTab: true };
|
|
495
|
+
},
|
|
496
|
+
[branch, kbDirName, location],
|
|
497
|
+
);
|
|
498
|
+
|
|
398
499
|
/**
|
|
399
500
|
* Follow a link DESTINATION out of a rendered document: the href as the
|
|
400
501
|
* author wrote it (or as react-markdown encoded it), resolved against
|
|
@@ -404,6 +505,16 @@ export function useFileNav() {
|
|
|
404
505
|
* branch; a relative one opens on the branch you are standing on. See
|
|
405
506
|
* {@link resolveKbHref}.
|
|
406
507
|
*
|
|
508
|
+
* A LINK INSIDE A FILE NEVER NAVIGATES AWAY FROM IT. Another file opens in
|
|
509
|
+
* a new tab at its plain address, and this tab — its location, its scroll,
|
|
510
|
+
* its full-screen view — stays as it was; only a link to the file it sits
|
|
511
|
+
* in (a section link) moves this tab, by its fragment. {@link linkTarget}
|
|
512
|
+
* decides which, and the markdown pipeline renders its anchors from the
|
|
513
|
+
* same answer, so a click and a middle-click go to one place. This is the
|
|
514
|
+
* rule for content, not for the app's own navigation: the tree, the tabs,
|
|
515
|
+
* search and the library reach `openFile` and `openWorkspacePath`, which
|
|
516
|
+
* navigate in place.
|
|
517
|
+
*
|
|
407
518
|
* AN EXTERNAL LINK IS OPENED HERE TOO, in a new tab. It used to be dropped
|
|
408
519
|
* on the floor — "not ours to open" — which is true of a link the browser
|
|
409
520
|
* still owns, and false of every link that reaches this function. Callers
|
|
@@ -429,20 +540,35 @@ export function useFileNav() {
|
|
|
429
540
|
* URL as a `Referer`, and the scheme allowlist is what keeps the sandbox
|
|
430
541
|
* sealed — see {@link isOpenableExternalHref}. A destination that is
|
|
431
542
|
* external but not openable stays a no-op, as it was.
|
|
543
|
+
*
|
|
544
|
+
* `onSection` is how a host whose file does not scroll to this tab's
|
|
545
|
+
* fragment follows a section link instead: the HTML page's frame (a
|
|
546
|
+
* fragment on the app's address never reaches it) and the skill page (its
|
|
547
|
+
* address has no heading scroll). It is handed the link's fragment —
|
|
548
|
+
* `#steps`, or `''` for the file itself — and this tab's address stays as
|
|
549
|
+
* it is. Without it the tab moves to its own address plus the fragment,
|
|
550
|
+
* which the markdown file page scrolls to.
|
|
432
551
|
*/
|
|
433
552
|
const openLink = useCallback(
|
|
434
|
-
(href: string, basePath: string) => {
|
|
435
|
-
const
|
|
436
|
-
if (
|
|
553
|
+
(href: string, basePath: string, options: OpenLinkOptions = {}) => {
|
|
554
|
+
const resolved = resolveKbHref(href, { basePath, kbDirName });
|
|
555
|
+
if (resolved?.kind === 'external') {
|
|
437
556
|
openExternalHref(href);
|
|
438
557
|
return;
|
|
439
558
|
}
|
|
440
|
-
if (
|
|
441
|
-
|
|
442
|
-
|
|
443
|
-
|
|
559
|
+
if (options.newTab && resolved) {
|
|
560
|
+
const onBranch = resolved.branch ?? options.homeBranch ?? branch;
|
|
561
|
+
if (onBranch) openInNewTab(kbFileUrl(onBranch, resolved.path) + resolved.hash);
|
|
562
|
+
return;
|
|
563
|
+
}
|
|
564
|
+
const target = linkTarget(href, basePath, options.homeBranch);
|
|
565
|
+
if (target && !target.newTab && resolved && options.onSection) {
|
|
566
|
+
options.onSection(resolved.hash);
|
|
567
|
+
return;
|
|
568
|
+
}
|
|
569
|
+
followLinkTarget(target, navigate);
|
|
444
570
|
},
|
|
445
|
-
[branch, kbDirName, navigate],
|
|
571
|
+
[branch, kbDirName, linkTarget, navigate],
|
|
446
572
|
);
|
|
447
573
|
|
|
448
574
|
/**
|
|
@@ -486,13 +612,17 @@ export function useFileNav() {
|
|
|
486
612
|
|
|
487
613
|
// The file page for a path a skill's page would otherwise claim (see
|
|
488
614
|
// `FILE_PAGE_PARAM`): an HTML page's "Open in the platform", whose tools
|
|
489
|
-
// are answered there and nowhere else.
|
|
615
|
+
// are answered there and nowhere else. The page asked for it from inside
|
|
616
|
+
// itself, so it opens in a new tab like any other way out of a page.
|
|
617
|
+
// `homeBranch` as in `linkTarget`: the skill page's files are read from the
|
|
618
|
+
// default branch, whatever this tab stands on.
|
|
490
619
|
const openFilePage = useCallback(
|
|
491
|
-
(path: string) => {
|
|
492
|
-
|
|
493
|
-
|
|
620
|
+
(path: string, homeBranch?: string) => {
|
|
621
|
+
const onBranch = homeBranch ?? branch;
|
|
622
|
+
if (!onBranch) return;
|
|
623
|
+
openInNewTab(kbFilePageUrl(onBranch, path));
|
|
494
624
|
},
|
|
495
|
-
[branch
|
|
625
|
+
[branch],
|
|
496
626
|
);
|
|
497
627
|
|
|
498
628
|
const closeFile = useCallback(() => {
|
|
@@ -509,25 +639,57 @@ export function useFileNav() {
|
|
|
509
639
|
return {
|
|
510
640
|
openFile: (pathOrUrl: string) => surface.openLink(pathOrUrl, ''),
|
|
511
641
|
openLink: surface.openLink,
|
|
642
|
+
// A surface takes every click itself (`linkPolicy: 'surface'`), so its
|
|
643
|
+
// anchors carry no app address of their own.
|
|
644
|
+
linkTarget: noLinkTarget,
|
|
512
645
|
openWorkspacePath: surface.openWorkspacePath,
|
|
513
646
|
openFilePage: surface.openFilePage,
|
|
514
647
|
closeFile: () => undefined,
|
|
648
|
+
// A surface stands on no branch of its own (an embed shows one page).
|
|
649
|
+
branch: null,
|
|
515
650
|
};
|
|
516
651
|
}
|
|
517
|
-
|
|
652
|
+
// `branch`: the one this tab stands on, as the URL says it — what a page
|
|
653
|
+
// shown on it is told as `window.bevel.branch`.
|
|
654
|
+
return { openFile, openLink, linkTarget, openWorkspacePath, openFilePage, closeFile, branch };
|
|
518
655
|
}
|
|
519
656
|
|
|
520
657
|
/**
|
|
521
|
-
*
|
|
522
|
-
*
|
|
523
|
-
*
|
|
524
|
-
*
|
|
525
|
-
*
|
|
526
|
-
*
|
|
658
|
+
* Follow a node referenced by its frontmatter id (`<id>` or `<id#heading>`), a
|
|
659
|
+
* link inside rendered content — so it follows {@link useFileNav}'s rule for
|
|
660
|
+
* those: a node other than the one on screen opens in a NEW TAB at its
|
|
661
|
+
* canonical id URL (`kbNodeUrl`, plus any heading as a real fragment so the
|
|
662
|
+
* deep-link scroll fires there), and this tab stays as it was. The id is
|
|
663
|
+
* resolved by that tab's `FileRoute`, through the same `resolve-id` route this
|
|
664
|
+
* hook used to call first (it 404s fail-closed for ids the reader may not
|
|
665
|
+
* read, and the tab shows not-found). Resolving here first would put a round
|
|
666
|
+
* trip between the click and `window.open`, and a browser lets a click open a
|
|
667
|
+
* tab only for so long — and the address would be one a middle-click on the
|
|
668
|
+
* same anchor never reaches.
|
|
669
|
+
*
|
|
670
|
+
* A link to the node on screen is a section link and moves this tab by its
|
|
671
|
+
* fragment only. Which node is on screen is decided by its ID, not by this
|
|
672
|
+
* tab's address: `ownId` is the id of the file the link sits in, as the
|
|
673
|
+
* renderer read it from that file, so a tab still on the file's PATH URL —
|
|
674
|
+
* the id not canonicalized yet, or a `FileRoute` that never canonicalizes
|
|
675
|
+
* (the library's) — knows the node too. Without one, the node whose id URL
|
|
676
|
+
* this tab is at (where `FileRoute` puts a node) is the one on screen.
|
|
677
|
+
* Shared by the file renderer and the chat citation renderer so both follow
|
|
678
|
+
* id-links identically.
|
|
679
|
+
*
|
|
680
|
+
* `onSection` is `OpenLinkOptions.onSection` for an id-link: a host whose
|
|
681
|
+
* address has no heading scroll (the skill page) scrolls to the fragment of a
|
|
682
|
+
* link to its own node itself, and this tab's address stays as it is.
|
|
683
|
+
*
|
|
684
|
+
* `homeBranch` is `linkTarget`'s, for an id-link: the branch the file the
|
|
685
|
+
* link sits in was read from, when not this tab's. The skill page renders
|
|
686
|
+
* its files from the default branch whatever is checked out, so an id there
|
|
687
|
+
* names a node on the default branch, not on somebody's draft. Omitted, it
|
|
688
|
+
* is this tab's branch.
|
|
527
689
|
*/
|
|
528
690
|
export function useNodeIdNav() {
|
|
529
691
|
const surface = useRendererSurface();
|
|
530
|
-
const
|
|
692
|
+
const navigate = useNavigate();
|
|
531
693
|
const git = useContext(GitContext);
|
|
532
694
|
const location = useLocation();
|
|
533
695
|
// The URL's branch first, the git status second — the same order as
|
|
@@ -535,32 +697,38 @@ export function useNodeIdNav() {
|
|
|
535
697
|
// being left, and an id resolved against it would open the wrong tree.
|
|
536
698
|
const branch = branchFromPathname(location.pathname) ?? git?.status?.branch ?? null;
|
|
537
699
|
|
|
538
|
-
const
|
|
539
|
-
|
|
540
|
-
|
|
700
|
+
const nodeIdTarget = useCallback(
|
|
701
|
+
(idOrLink: string, ownId?: string | null, homeBranch?: string): KbLinkTarget | null => {
|
|
702
|
+
const onBranch = homeBranch ?? branch;
|
|
703
|
+
if (!onBranch) return null;
|
|
541
704
|
const hashIdx = idOrLink.indexOf('#');
|
|
542
705
|
const id = hashIdx >= 0 ? idOrLink.slice(0, hashIdx) : idOrLink;
|
|
543
706
|
const hash = hashIdx >= 0 ? idOrLink.slice(hashIdx) : '';
|
|
544
|
-
|
|
545
|
-
|
|
546
|
-
|
|
547
|
-
|
|
548
|
-
|
|
549
|
-
|
|
550
|
-
|
|
551
|
-
|
|
552
|
-
|
|
553
|
-
|
|
554
|
-
|
|
555
|
-
|
|
707
|
+
const url = kbNodeUrl(onBranch, id);
|
|
708
|
+
if (id === ownId || url === location.pathname) {
|
|
709
|
+
return sectionOfThisTab(location, hash);
|
|
710
|
+
}
|
|
711
|
+
return { href: url + hash, newTab: true };
|
|
712
|
+
},
|
|
713
|
+
[branch, location],
|
|
714
|
+
);
|
|
715
|
+
|
|
716
|
+
const openNodeId = useCallback(
|
|
717
|
+
(idOrLink: string, ownId?: string | null, options: OpenLinkOptions = {}) => {
|
|
718
|
+
const target = nodeIdTarget(idOrLink, ownId, options.homeBranch);
|
|
719
|
+
if (target && !target.newTab && options.onSection) {
|
|
720
|
+
const hashIdx = idOrLink.indexOf('#');
|
|
721
|
+
options.onSection(hashIdx >= 0 ? idOrLink.slice(hashIdx) : '');
|
|
722
|
+
return;
|
|
556
723
|
}
|
|
724
|
+
followLinkTarget(target, navigate);
|
|
557
725
|
},
|
|
558
|
-
[
|
|
726
|
+
[nodeIdTarget, navigate],
|
|
559
727
|
);
|
|
560
728
|
|
|
561
729
|
// The surface resolves an id its own way — the embed hands it to its host
|
|
562
730
|
// as an app address, which the app then resolves with the reader's own
|
|
563
731
|
// session. Resolving it HERE would need a session the embed does not have.
|
|
564
|
-
if (surface) return { openNodeId: surface.openNodeId };
|
|
565
|
-
return { openNodeId };
|
|
732
|
+
if (surface) return { openNodeId: surface.openNodeId, nodeIdTarget: noLinkTarget };
|
|
733
|
+
return { openNodeId, nodeIdTarget };
|
|
566
734
|
}
|
|
@@ -48,7 +48,7 @@ export function checkoutRoot(
|
|
|
48
48
|
* Whether the tree shows the caller anything of the knowledge base at all.
|
|
49
49
|
* What does not count: the reserved root folders themselves (every knowledge
|
|
50
50
|
* base has them, and the server keeps them visible even to a reader who may
|
|
51
|
-
* open nothing inside), and the root `.bevelignore`
|
|
51
|
+
* open nothing inside), and the root `.bevelignore` every reader sees in a
|
|
52
52
|
* knowledge base nobody has written to yet. Anything else — a file, or a
|
|
53
53
|
* folder, at any depth — is an entry on screen.
|
|
54
54
|
*
|