@bevel-software/platform-core-frontend 0.32.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/core/CoreAppShell.tsx +1 -1
- 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 +4 -5
- package/src/modules/access/components/ManageAccessDialog.tsx +11 -12
- 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/__tests__/DirectoryGroupsPage.test.tsx +51 -0
- package/src/modules/admin/components/AddMemberInput.tsx +1 -1
- package/src/modules/admin/components/DirectoryGroupsPage.tsx +42 -5
- package/src/modules/admin/components/UserAccountsPage.tsx +3 -3
- package/src/modules/admin/index.ts +7 -0
- package/src/modules/admin/services/groups.api.ts +11 -1
- package/src/modules/admin/state/admin.context.tsx +1 -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/AuditEventsPanel.tsx +1 -1
- package/src/modules/audit/components/AuditLogPage.tsx +11 -2
- 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/index.ts +12 -0
- package/src/modules/auth/services/account.api.ts +18 -2
- 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/__tests__/BranchSwitcher.test.tsx +0 -14
- package/src/modules/git/__tests__/git.api.test.ts +2 -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/__tests__/useGitState.deleteBranch.test.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 +268 -24
- 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 +74 -14
- package/src/modules/library/components/skill-page/SkillPage.tsx +80 -47
- 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 +24 -3
- package/src/modules/review/components/ReviewPanel.tsx +10 -5
- package/src/modules/review/components/__tests__/MarkdownDiffViewer.test.tsx +31 -0
- package/src/modules/review/state/ReviewProvider.tsx +2 -2
- 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/index.ts +6 -0
- package/src/modules/secrets-vault/services/connect.api.ts +20 -5
- 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 +39 -5
- 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/components/__tests__/ExternalAgentAccessPage.test.tsx +91 -2
- 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/toolbar/services/external-api-keys.api.ts +5 -2
- 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 +163 -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 +74 -180
- 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/ToolRenderer.tsx +1 -1
- package/src/modules/workspace/components/renderers/__tests__/HtmlRenderer.links.test.tsx +185 -0
- package/src/modules/workspace/components/renderers/__tests__/HtmlRenderer.tools.test.tsx +168 -42
- 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 +57 -7
- package/src/modules/workspace/components/renderers/__tests__/htmlSandbox.test.ts +122 -4
- package/src/modules/workspace/components/renderers/__tests__/htmlToolBridge.test.ts +235 -1
- package/src/modules/workspace/components/renderers/__tests__/htmlViewsGuide.test.ts +29 -4
- package/src/modules/workspace/components/renderers/__tests__/liveDataReferencePage.test.ts +397 -0
- 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 +123 -28
- package/src/modules/workspace/components/renderers/htmlToolBridge.ts +215 -25
- package/src/modules/workspace/components/renderers/index.ts +10 -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/components/renderers/useHtmlToolBridge.tsx +253 -0
- package/src/modules/workspace/hooks/__tests__/useLinksOut.test.ts +6 -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/useLinksOut.ts +12 -6
- package/src/modules/workspace/hooks/useWorkspaceState.ts +4 -4
- package/src/modules/workspace/index.ts +50 -2
- package/src/modules/workspace/routing/__tests__/kb-routes.test.tsx +262 -25
- package/src/modules/workspace/routing/kb-routes.ts +222 -54
- 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/fileTree.ts +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,19 +1,12 @@
|
|
|
1
1
|
import { useState, useCallback, useEffect, useMemo, useRef } from 'react';
|
|
2
2
|
import { Pencil, Eye, RotateCw } from 'lucide-react';
|
|
3
|
+
import { useLocation } from 'react-router-dom';
|
|
3
4
|
import { useFileNav } from '../../routing/kb-routes';
|
|
4
5
|
import type { FileRendererProps, RendererSaveState } from './types';
|
|
5
6
|
import { buildSandboxedHtml, sanitizeAgentHtml } from './htmlSandbox';
|
|
6
7
|
import { useRendererSurface } from './rendererSurface';
|
|
7
|
-
import {
|
|
8
|
-
import {
|
|
9
|
-
PageConsent,
|
|
10
|
-
PageToolsClient,
|
|
11
|
-
answerToolCall,
|
|
12
|
-
asToolCall,
|
|
13
|
-
pageName,
|
|
14
|
-
useOpenPageInPlatform,
|
|
15
|
-
usePageTools,
|
|
16
|
-
} from './htmlToolBridge';
|
|
8
|
+
import { usePageLinkHome } from './htmlToolBridge';
|
|
9
|
+
import { useHtmlToolBridge } from './useHtmlToolBridge';
|
|
17
10
|
import {
|
|
18
11
|
HTML_FRAME_KEY_STEP,
|
|
19
12
|
HTML_FRAME_MAX_HEIGHT,
|
|
@@ -22,13 +15,6 @@ import {
|
|
|
22
15
|
attachFrameResizeHandle,
|
|
23
16
|
} from './frameResizeHandle';
|
|
24
17
|
|
|
25
|
-
/**
|
|
26
|
-
* The card the app shows over a page, outside its frame: the page cannot draw,
|
|
27
|
-
* see or answer it. `write`: the page's first writing call asks the viewer.
|
|
28
|
-
* `platform`: a page that needs tools asked for them where there are none.
|
|
29
|
-
*/
|
|
30
|
-
type PageCard = { kind: 'write' | 'platform'; answer: (ok: boolean | null) => void };
|
|
31
|
-
|
|
32
18
|
/**
|
|
33
19
|
* Where the reader's chosen frame height is kept, per browser: a
|
|
34
20
|
* convenience, like a remembered tab. A browser that cannot store it is
|
|
@@ -65,16 +51,20 @@ export function HtmlRenderer({
|
|
|
65
51
|
onSaveStateChange,
|
|
66
52
|
readOnly = false,
|
|
67
53
|
}: FileRendererProps) {
|
|
68
|
-
const { openLink,
|
|
54
|
+
const { openLink, branch: tabBranch } = useFileNav();
|
|
55
|
+
// The fragment this tab's address arrived with (`Board.html#totals`, from a
|
|
56
|
+
// section link opened in a new tab or a shared address). It names a place
|
|
57
|
+
// in the PAGE, which lives in the frame, where the app's address never
|
|
58
|
+
// reaches: the frame is handed it as `bevel.jump` once it has loaded, the
|
|
59
|
+
// same message a click on a section link inside the page is answered with.
|
|
60
|
+
const { hash: arrivalHash } = useLocation();
|
|
69
61
|
const surface = useRendererSurface();
|
|
70
62
|
// Whether the surface's host grows with the page (an issue panel) rather
|
|
71
63
|
// than giving it a pane to scroll in (the app, the MCP App's pane).
|
|
72
64
|
const sizesToContent = surface?.sizesToContent === true;
|
|
73
|
-
// The
|
|
74
|
-
//
|
|
75
|
-
const
|
|
76
|
-
const openPageInPlatform = useOpenPageInPlatform();
|
|
77
|
-
const toolPagePath = surface === null && pageTools ? pageTools.pagePath : null;
|
|
65
|
+
// The file this page's links resolve against, where the host's `filePath`
|
|
66
|
+
// is not a workspace path on this tab's branch (a skill page).
|
|
67
|
+
const linkHome = usePageLinkHome();
|
|
78
68
|
const [mode, setMode] = useState<'preview' | 'edit'>('preview');
|
|
79
69
|
/**
|
|
80
70
|
* The frame's height where the host grows with the page: the standard
|
|
@@ -91,17 +81,20 @@ export function HtmlRenderer({
|
|
|
91
81
|
const [savedValue, setSavedValue] = useState(savedContent ?? content);
|
|
92
82
|
const [saveState, setSaveState] = useState<RendererSaveState>('idle');
|
|
93
83
|
const [saveError, setSaveError] = useState<string | null>(null);
|
|
94
|
-
const [bundledSrcdoc, setBundledSrcdoc] = useState<string | null>(null);
|
|
95
|
-
const [previewError, setPreviewError] = useState<string | null>(null);
|
|
96
84
|
const [reloadKey, setReloadKey] = useState(0);
|
|
97
85
|
const iframeRef = useRef<HTMLIFrameElement | null>(null);
|
|
98
86
|
const prevFilePathRef = useRef(filePath);
|
|
99
|
-
|
|
100
|
-
|
|
101
|
-
|
|
102
|
-
//
|
|
103
|
-
//
|
|
104
|
-
|
|
87
|
+
|
|
88
|
+
// The page tool bridge: a page's `window.bevel.tools` and `requireTools()`,
|
|
89
|
+
// answered for one view of the page — a new frame document (a reload, a
|
|
90
|
+
// saved edit, another file) or the frame gone (Edit) is a new view. The
|
|
91
|
+
// view's key is a fresh identity whenever one of the INPUTS of the
|
|
92
|
+
// document changes, never the built document itself: the bridge's
|
|
93
|
+
// `toolBridge` goes into the build, so a key read off the build would
|
|
94
|
+
// chase it; and a distribution's document carries its inlined libraries,
|
|
95
|
+
// which a key built from it would compare on every render.
|
|
96
|
+
const viewKey = useMemo(() => ({ reloadKey, mode, savedValue, filePath }), [reloadKey, mode, savedValue, filePath]);
|
|
97
|
+
const { toolBridge, cards } = useHtmlToolBridge({ iframeRef, filePath, viewKey });
|
|
105
98
|
|
|
106
99
|
const dirty = !readOnly && value !== savedValue;
|
|
107
100
|
|
|
@@ -126,17 +119,23 @@ export function HtmlRenderer({
|
|
|
126
119
|
onSaveStateChange?.(saveState);
|
|
127
120
|
}, [saveState, onSaveStateChange]);
|
|
128
121
|
|
|
129
|
-
// Build the iframe document
|
|
130
|
-
// content
|
|
131
|
-
// (defense in depth — CSP also
|
|
132
|
-
// the KB's JS library inlined as
|
|
133
|
-
//
|
|
134
|
-
|
|
135
|
-
|
|
136
|
-
|
|
137
|
-
|
|
122
|
+
// Build the iframe document for the view on screen: in preview, from the
|
|
123
|
+
// saved content and the bridge's identity for this view. The agent's HTML
|
|
124
|
+
// is sanitized to strip any external URLs (defense in depth — CSP also
|
|
125
|
+
// blocks them at runtime), then bundled with the KB's JS library inlined as
|
|
126
|
+
// a `<script type="module">`. The result is a fully self-contained srcdoc —
|
|
127
|
+
// the iframe makes no network calls of any kind.
|
|
128
|
+
//
|
|
129
|
+
// Built DURING render, never in an effect after it: a new view (Refresh
|
|
130
|
+
// remounts the frame) must mount its frame with its own document. Built
|
|
131
|
+
// after the commit, the new frame first loaded the previous view's document
|
|
132
|
+
// and had the new one swapped in mid-load, and Chromium leaves a sandboxed
|
|
133
|
+
// frame whose srcdoc is replaced that early unpainted — blank on every
|
|
134
|
+
// Refresh.
|
|
135
|
+
const preview = useMemo((): { srcdoc: string; error: null } | { srcdoc: null; error: string } | null => {
|
|
136
|
+
if (mode !== 'preview') return null;
|
|
138
137
|
try {
|
|
139
|
-
const
|
|
138
|
+
const srcdoc = buildSandboxedHtml({
|
|
140
139
|
title: filePath,
|
|
141
140
|
// Core ships no inlined vendor libraries. (The enterprise build inlines
|
|
142
141
|
// d3 + mermaid and the KB graph client here — the knowledge system,
|
|
@@ -144,13 +143,19 @@ export function HtmlRenderer({
|
|
|
144
143
|
// extension.)
|
|
145
144
|
libModuleSources: [],
|
|
146
145
|
bodyHtml: sanitizeAgentHtml(savedValue),
|
|
147
|
-
toolBridge
|
|
146
|
+
toolBridge,
|
|
147
|
+
// The branch the page is viewed on — the real home of a page whose
|
|
148
|
+
// host is not a workspace path (a skill page), else the file page's
|
|
149
|
+
// tab: the same branch its links resolve on. Absent on a surface.
|
|
150
|
+
branch: linkHome?.branch ?? tabBranch ?? undefined,
|
|
148
151
|
});
|
|
149
|
-
|
|
152
|
+
return { srcdoc, error: null };
|
|
150
153
|
} catch (err) {
|
|
151
|
-
|
|
154
|
+
return { srcdoc: null, error: err instanceof Error ? err.message : 'Failed to build preview' };
|
|
152
155
|
}
|
|
153
|
-
}, [mode, savedValue, filePath,
|
|
156
|
+
}, [mode, savedValue, filePath, toolBridge, linkHome, tabBranch]);
|
|
157
|
+
const bundledSrcdoc = preview?.srcdoc ?? null;
|
|
158
|
+
const previewError = preview?.error ?? null;
|
|
154
159
|
|
|
155
160
|
// (The enterprise build additionally installs a postMessage bridge here that
|
|
156
161
|
// serves the iframe's KB-graph client from `/api/workspace/:id/graph` — the
|
|
@@ -162,115 +167,36 @@ export function HtmlRenderer({
|
|
|
162
167
|
// node — both post a `bevel.navigate` message (the iframe sandbox can't
|
|
163
168
|
// navigate the host window itself). `openLink` resolves the href the same
|
|
164
169
|
// way the markdown renderer does (absolute `/workspace/…` URLs keep their
|
|
165
|
-
// branch; relative paths resolve against this file) and
|
|
166
|
-
//
|
|
170
|
+
// branch; relative paths resolve against this file) and follows it by the
|
|
171
|
+
// rule for links inside a file: another file opens in a new tab, and this
|
|
172
|
+
// page — its state, its scroll, its full-screen view — stays as it was.
|
|
173
|
+
// A link to a section of this same page (`Roadmap.html#q3` from inside
|
|
174
|
+
// Roadmap.html) is handed back to the frame as `bevel.jump`, which scrolls
|
|
175
|
+
// it the way the bridge scrolls a bare `#q3`: a fragment on the app's own
|
|
176
|
+
// address would never reach the frame. A host whose `filePath` is not a
|
|
177
|
+
// workspace path on this tab's branch (a skill page) names the page's real
|
|
178
|
+
// home through `PageLinkHomeContext`.
|
|
167
179
|
useEffect(() => {
|
|
168
180
|
function onNavMessage(event: MessageEvent) {
|
|
169
181
|
const iframeWin = iframeRef.current?.contentWindow;
|
|
170
182
|
if (!iframeWin || event.source !== iframeWin) return;
|
|
171
|
-
const msg = event.data as { type?: unknown; href?: unknown } | null;
|
|
183
|
+
const msg = event.data as { type?: unknown; href?: unknown; newTab?: unknown } | null;
|
|
172
184
|
if (!msg || typeof msg !== 'object' || msg.type !== 'bevel.navigate') return;
|
|
173
185
|
const href = typeof msg.href === 'string' ? msg.href : null;
|
|
174
186
|
if (!href) return;
|
|
175
|
-
openLink(href, filePath
|
|
187
|
+
openLink(href, linkHome?.path ?? filePath, {
|
|
188
|
+
homeBranch: linkHome?.branch,
|
|
189
|
+
// A modified or middle click in the page, which the frame cannot
|
|
190
|
+
// open a tab for itself (see the nav bridge in `htmlSandbox.ts`).
|
|
191
|
+
newTab: msg.newTab === true,
|
|
192
|
+
onSection: (hash) => {
|
|
193
|
+
if (hash) iframeWin.postMessage({ type: 'bevel.jump', hash }, '*');
|
|
194
|
+
},
|
|
195
|
+
});
|
|
176
196
|
}
|
|
177
197
|
window.addEventListener('message', onNavMessage);
|
|
178
198
|
return () => window.removeEventListener('message', onNavMessage);
|
|
179
|
-
}, [openLink, filePath]);
|
|
180
|
-
|
|
181
|
-
/** Show one of the app's cards over the page and resolve with the viewer's answer. A card already up answers this ask too. */
|
|
182
|
-
function showCard(kind: PageCard['kind']): Promise<boolean | null> {
|
|
183
|
-
const open = cardRef.current;
|
|
184
|
-
if (open && open.kind === kind) {
|
|
185
|
-
return new Promise((resolve) => {
|
|
186
|
-
const first = open.answer;
|
|
187
|
-
open.answer = (ok) => {
|
|
188
|
-
first(ok);
|
|
189
|
-
resolve(ok);
|
|
190
|
-
};
|
|
191
|
-
});
|
|
192
|
-
}
|
|
193
|
-
return new Promise((resolve) => {
|
|
194
|
-
const next: PageCard = { kind, answer: resolve };
|
|
195
|
-
cardRef.current = next;
|
|
196
|
-
setCard(next);
|
|
197
|
-
});
|
|
198
|
-
}
|
|
199
|
-
|
|
200
|
-
/** Close the card with the viewer's answer, or null when the view went before they gave one. */
|
|
201
|
-
const closeCard = useCallback((ok: boolean | null) => {
|
|
202
|
-
const open = cardRef.current;
|
|
203
|
-
cardRef.current = null;
|
|
204
|
-
setCard(null);
|
|
205
|
-
open?.answer(ok);
|
|
206
|
-
}, []);
|
|
207
|
-
|
|
208
|
-
// When the page's document goes (a reload, a saved edit, another file, or
|
|
209
|
-
// Edit, which unmounts the frame even when the document comes back the same)
|
|
210
|
-
// its consent goes with it, and a card left open answers no: nothing the old
|
|
211
|
-
// view asked for runs in the new one.
|
|
212
|
-
useEffect(
|
|
213
|
-
() => () => {
|
|
214
|
-
consentRef.current = null;
|
|
215
|
-
closeCard(null);
|
|
216
|
-
},
|
|
217
|
-
[bundledSrcdoc, reloadKey, mode, closeCard],
|
|
218
|
-
);
|
|
219
|
-
|
|
220
|
-
// Tool bridge: a page's `window.bevel.tools` calls and its
|
|
221
|
-
// `requireTools()`, posted by the runtime in the frame (see
|
|
222
|
-
// `htmlSandbox.ts`), answered here with the viewer's session.
|
|
223
|
-
useEffect(() => {
|
|
224
|
-
function onToolMessage(event: MessageEvent) {
|
|
225
|
-
const iframeWin = iframeRef.current?.contentWindow;
|
|
226
|
-
if (!iframeWin || event.source !== iframeWin) return;
|
|
227
|
-
const reply = (message: unknown) => {
|
|
228
|
-
// Only to the document that asked: a reloaded frame is a new window.
|
|
229
|
-
if (iframeRef.current?.contentWindow === iframeWin) iframeWin.postMessage(message, '*');
|
|
230
|
-
};
|
|
231
|
-
const data = event.data as { type?: unknown; requestId?: unknown } | null;
|
|
232
|
-
if (data && data.type === 'bevel.tools.require' && typeof data.requestId === 'string') {
|
|
233
|
-
const requestId = data.requestId;
|
|
234
|
-
if (toolsClient) {
|
|
235
|
-
reply({ type: 'bevel.tools.require.response', requestId, ok: true, result: true });
|
|
236
|
-
return;
|
|
237
|
-
}
|
|
238
|
-
void showCard('platform').then(() =>
|
|
239
|
-
// Either way the page that asked carries on without tools: Open in
|
|
240
|
-
// the platform opened it elsewhere, it did not give it tools here.
|
|
241
|
-
reply({ type: 'bevel.tools.require.response', requestId, ok: true, result: false }),
|
|
242
|
-
);
|
|
243
|
-
return;
|
|
244
|
-
}
|
|
245
|
-
const call = asToolCall(data);
|
|
246
|
-
if (!call) return;
|
|
247
|
-
if (!toolsClient) {
|
|
248
|
-
reply({
|
|
249
|
-
type: 'bevel.tool.response',
|
|
250
|
-
requestId: call.requestId,
|
|
251
|
-
ok: false,
|
|
252
|
-
error: 'Tools are only available on the page in the platform.',
|
|
253
|
-
code: 'unavailable',
|
|
254
|
-
});
|
|
255
|
-
return;
|
|
256
|
-
}
|
|
257
|
-
consentRef.current ??= new PageConsent(() => showCard('write'));
|
|
258
|
-
void answerToolCall(call, toolsClient, consentRef.current).then(reply);
|
|
259
|
-
}
|
|
260
|
-
window.addEventListener('message', onToolMessage);
|
|
261
|
-
return () => window.removeEventListener('message', onToolMessage);
|
|
262
|
-
}, [toolsClient]);
|
|
263
|
-
|
|
264
|
-
const openInPlatform = useCallback(() => {
|
|
265
|
-
closeCard(false);
|
|
266
|
-
// The host's own way when it has one (a skill page, whose filePath is
|
|
267
|
-
// relative to the skill); otherwise the file page, by an address that
|
|
268
|
-
// asks for it outright: on the embed the surface opens it through the
|
|
269
|
-
// host in a new tab, which carries no router state, and a page inside a
|
|
270
|
-
// skill's folder would otherwise open as that skill's page again.
|
|
271
|
-
if (openPageInPlatform) openPageInPlatform();
|
|
272
|
-
else openFilePage(filePath);
|
|
273
|
-
}, [closeCard, openPageInPlatform, openFilePage, filePath]);
|
|
199
|
+
}, [openLink, filePath, linkHome]);
|
|
274
200
|
|
|
275
201
|
useEffect(() => {
|
|
276
202
|
frameHeightRef.current = frameHeight;
|
|
@@ -414,6 +340,9 @@ export function HtmlRenderer({
|
|
|
414
340
|
// iframe cannot exfiltrate, navigate, popup, or fetch.
|
|
415
341
|
sandbox="allow-scripts"
|
|
416
342
|
referrerPolicy="no-referrer"
|
|
343
|
+
onLoad={(e) => {
|
|
344
|
+
if (arrivalHash) e.currentTarget.contentWindow?.postMessage({ type: 'bevel.jump', hash: arrivalHash }, '*');
|
|
345
|
+
}}
|
|
417
346
|
// In a pane the frame fills it and scrolls inside; where the host
|
|
418
347
|
// grows with the page, the frame has the reader's height (a
|
|
419
348
|
// flex-grown frame in an auto-height column would collapse to the
|
|
@@ -449,42 +378,7 @@ export function HtmlRenderer({
|
|
|
449
378
|
Loading preview…
|
|
450
379
|
</div>
|
|
451
380
|
)}
|
|
452
|
-
|
|
453
|
-
open={card?.kind === 'write'}
|
|
454
|
-
onClose={() => closeCard(false)}
|
|
455
|
-
title={`${pageName(filePath)} wants to write to the knowledge base`}
|
|
456
|
-
size="md"
|
|
457
|
-
footer={
|
|
458
|
-
<>
|
|
459
|
-
<Button variant="outline" onClick={() => closeCard(false)}>
|
|
460
|
-
Deny
|
|
461
|
-
</Button>
|
|
462
|
-
<Button variant="primary" onClick={() => closeCard(true)}>
|
|
463
|
-
Allow while open
|
|
464
|
-
</Button>
|
|
465
|
-
</>
|
|
466
|
-
}
|
|
467
|
-
>
|
|
468
|
-
<p className="font-mono text-detail text-ink-muted break-all">{toolPagePath ?? filePath}</p>
|
|
469
|
-
</Dialog>
|
|
470
|
-
<Dialog
|
|
471
|
-
open={card?.kind === 'platform'}
|
|
472
|
-
onClose={() => closeCard(false)}
|
|
473
|
-
title={`${pageName(filePath)} uses tools that are only available in the platform`}
|
|
474
|
-
size="md"
|
|
475
|
-
footer={
|
|
476
|
-
<>
|
|
477
|
-
<Button variant="outline" onClick={() => closeCard(false)}>
|
|
478
|
-
Continue without tools
|
|
479
|
-
</Button>
|
|
480
|
-
<Button variant="primary" onClick={openInPlatform}>
|
|
481
|
-
Open in the platform
|
|
482
|
-
</Button>
|
|
483
|
-
</>
|
|
484
|
-
}
|
|
485
|
-
>
|
|
486
|
-
<p className="font-mono text-detail text-ink-muted break-all">{filePath}</p>
|
|
487
|
-
</Dialog>
|
|
381
|
+
{cards}
|
|
488
382
|
</div>
|
|
489
383
|
);
|
|
490
384
|
}
|
|
@@ -0,0 +1,56 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* Where an in-app link inside rendered content leads, as the app's file-nav
|
|
3
|
+
* hook answers it (`useFileNav().linkTarget`, `useNodeIdNav().nodeIdTarget`):
|
|
4
|
+
* `href` is the address the click opens, `newTab` whether it opens there in a
|
|
5
|
+
* new tab (another file) or in this one (a section of the file on screen).
|
|
6
|
+
*/
|
|
7
|
+
export interface KbLinkTarget {
|
|
8
|
+
href: string;
|
|
9
|
+
newTab: boolean;
|
|
10
|
+
}
|
|
11
|
+
|
|
12
|
+
/**
|
|
13
|
+
* An in-app link the caller follows on click (`onOpen`, with the destination
|
|
14
|
+
* as written). With a `target` the anchor carries the address the click goes
|
|
15
|
+
* to, and — when that is a new tab — `target="_blank"` and `rel="noopener"`,
|
|
16
|
+
* so a middle-click, the context menu and a screen reader all agree with the
|
|
17
|
+
* click. A click the reader modified (Ctrl, ⌘, Shift, Alt) or made with
|
|
18
|
+
* another button is left to the browser, on a new-tab link and a section link
|
|
19
|
+
* alike: the anchor's `href` is already the address the click would open, so
|
|
20
|
+
* the browser does with it what it does with any link — a Ctrl-click on a
|
|
21
|
+
* section link opens that section in a new tab rather than moving this one.
|
|
22
|
+
* Without a `target` (no resolver) the anchor is what it always was, every
|
|
23
|
+
* click taken by `onOpen`: its `href` is the destination as written, not an
|
|
24
|
+
* address the browser could follow.
|
|
25
|
+
*/
|
|
26
|
+
export function KbAppLink({
|
|
27
|
+
href,
|
|
28
|
+
target,
|
|
29
|
+
onOpen,
|
|
30
|
+
className = 'cursor-pointer',
|
|
31
|
+
children,
|
|
32
|
+
...props
|
|
33
|
+
}: {
|
|
34
|
+
href: string;
|
|
35
|
+
target: KbLinkTarget | null;
|
|
36
|
+
onOpen: () => void;
|
|
37
|
+
className?: string;
|
|
38
|
+
children?: React.ReactNode;
|
|
39
|
+
}) {
|
|
40
|
+
const newTab = target?.newTab === true;
|
|
41
|
+
return (
|
|
42
|
+
<a
|
|
43
|
+
{...props}
|
|
44
|
+
href={target?.href ?? href}
|
|
45
|
+
{...(newTab ? { target: '_blank', rel: 'noopener' } : {})}
|
|
46
|
+
onClick={(e) => {
|
|
47
|
+
if (target && (e.button !== 0 || e.metaKey || e.ctrlKey || e.shiftKey || e.altKey)) return;
|
|
48
|
+
e.preventDefault();
|
|
49
|
+
onOpen();
|
|
50
|
+
}}
|
|
51
|
+
className={className}
|
|
52
|
+
>
|
|
53
|
+
{children}
|
|
54
|
+
</a>
|
|
55
|
+
);
|
|
56
|
+
}
|
|
@@ -8,6 +8,7 @@ import {
|
|
|
8
8
|
useKbMarkdownComponents,
|
|
9
9
|
type KbImageResolver,
|
|
10
10
|
} from './kbMarkdownPipeline';
|
|
11
|
+
import { KbAppLink, type KbLinkTarget } from './KbAppLink';
|
|
11
12
|
|
|
12
13
|
// A frontmatter value that is a single markdown link, e.g.
|
|
13
14
|
// `nodeType: [Process](../../NodeTypes/Process.md)` (parseFrontmatter strips
|
|
@@ -31,25 +32,25 @@ const FRONTMATTER_LINK_RE = /^\[([^\]]+)\]\(<?([^)>]+)>?\)$/;
|
|
|
31
32
|
function FrontmatterValue({
|
|
32
33
|
value,
|
|
33
34
|
onOpenFile,
|
|
35
|
+
fileLinkTarget,
|
|
34
36
|
}: {
|
|
35
37
|
value: string;
|
|
36
38
|
onOpenFile: (href: string) => void;
|
|
39
|
+
fileLinkTarget?: (href: string) => KbLinkTarget | null;
|
|
37
40
|
}) {
|
|
38
41
|
const match = value.match(FRONTMATTER_LINK_RE);
|
|
39
42
|
const href = match ? defaultUrlTransform(match[2]) : '';
|
|
40
43
|
if (match && href) {
|
|
41
44
|
const label = match[1];
|
|
42
45
|
return (
|
|
43
|
-
<
|
|
46
|
+
<KbAppLink
|
|
44
47
|
href={href}
|
|
45
|
-
|
|
46
|
-
|
|
47
|
-
onOpenFile(href);
|
|
48
|
-
}}
|
|
48
|
+
target={fileLinkTarget?.(href) ?? null}
|
|
49
|
+
onOpen={() => onOpenFile(href)}
|
|
49
50
|
className="text-accent hover:text-accent-hover hover:underline cursor-pointer"
|
|
50
51
|
>
|
|
51
52
|
{label}
|
|
52
|
-
</
|
|
53
|
+
</KbAppLink>
|
|
53
54
|
);
|
|
54
55
|
}
|
|
55
56
|
return <>{value}</>;
|
|
@@ -58,9 +59,11 @@ function FrontmatterValue({
|
|
|
58
59
|
function FrontmatterPanel({
|
|
59
60
|
data,
|
|
60
61
|
onOpenFile,
|
|
62
|
+
fileLinkTarget,
|
|
61
63
|
}: {
|
|
62
64
|
data: Record<string, string | string[]>;
|
|
63
65
|
onOpenFile: (href: string) => void;
|
|
66
|
+
fileLinkTarget?: (href: string) => KbLinkTarget | null;
|
|
64
67
|
}) {
|
|
65
68
|
const entries = Object.entries(data).filter(([, v]) => {
|
|
66
69
|
if (Array.isArray(v)) return v.length > 0;
|
|
@@ -77,7 +80,7 @@ function FrontmatterPanel({
|
|
|
77
80
|
{Array.isArray(value) ? (
|
|
78
81
|
value.join(', ')
|
|
79
82
|
) : (
|
|
80
|
-
<FrontmatterValue value={value} onOpenFile={onOpenFile} />
|
|
83
|
+
<FrontmatterValue value={value} onOpenFile={onOpenFile} fileLinkTarget={fileLinkTarget} />
|
|
81
84
|
)}
|
|
82
85
|
</span>
|
|
83
86
|
</div>
|
|
@@ -102,6 +105,15 @@ interface KbMarkdownViewProps {
|
|
|
102
105
|
* which has no in-app navigation).
|
|
103
106
|
*/
|
|
104
107
|
onOpenNodeId?: (id: string) => void;
|
|
108
|
+
/**
|
|
109
|
+
* Where an in-app link leads (body or link-valued frontmatter), so its
|
|
110
|
+
* anchor names the address the click opens and says when that is a new tab
|
|
111
|
+
* — see `KbAppLink` in the pipeline. The file page passes the file-nav
|
|
112
|
+
* hook's answer; omitted, an anchor carries the href as written.
|
|
113
|
+
*/
|
|
114
|
+
fileLinkTarget?: (href: string) => KbLinkTarget | null;
|
|
115
|
+
/** The same for an id-link. */
|
|
116
|
+
nodeIdLinkTarget?: (id: string) => KbLinkTarget | null;
|
|
105
117
|
/**
|
|
106
118
|
* When provided, each heading gets a hover-revealed copy button that copies
|
|
107
119
|
* `headingLink(slug)` — the heading's citation deep-link. `slug` is the
|
|
@@ -146,7 +158,7 @@ interface KbMarkdownViewProps {
|
|
|
146
158
|
* frontmatter panel, with navigation injected via `onOpenFile` so it carries no
|
|
147
159
|
* dependency on workspace routing or context.
|
|
148
160
|
*/
|
|
149
|
-
export function KbMarkdownView({ source, onOpenFile, onOpenNodeId, headingLink, resolveImage, linkPolicy, containerRef, scroll = true, className }: KbMarkdownViewProps) {
|
|
161
|
+
export function KbMarkdownView({ source, onOpenFile, onOpenNodeId, fileLinkTarget, nodeIdLinkTarget, headingLink, resolveImage, linkPolicy, containerRef, scroll = true, className }: KbMarkdownViewProps) {
|
|
150
162
|
const { data: frontmatter, body } = useMemo(() => parseFrontmatter(source), [source]);
|
|
151
163
|
// CommonMark rejects unescaped spaces in link destinations, so a KB link like
|
|
152
164
|
// `[Foo](Some File.md)` would render as plain text. Wrap space-bearing
|
|
@@ -154,14 +166,22 @@ export function KbMarkdownView({ source, onOpenFile, onOpenNodeId, headingLink,
|
|
|
154
166
|
// rule covers an image's `` tail.
|
|
155
167
|
const normalizedBody = useMemo(() => escapeSpacesInLinkDestinations(body), [body]);
|
|
156
168
|
|
|
157
|
-
const components = useKbMarkdownComponents({
|
|
169
|
+
const components = useKbMarkdownComponents({
|
|
170
|
+
onOpenFile,
|
|
171
|
+
onOpenNodeId,
|
|
172
|
+
fileLinkTarget,
|
|
173
|
+
nodeIdLinkTarget,
|
|
174
|
+
headingLink,
|
|
175
|
+
resolveImage,
|
|
176
|
+
linkPolicy,
|
|
177
|
+
});
|
|
158
178
|
|
|
159
179
|
return (
|
|
160
180
|
<div
|
|
161
181
|
className={`${scroll ? 'flex-1 overflow-auto' : 'min-w-0'} ${className ?? ''}`}
|
|
162
182
|
ref={containerRef}
|
|
163
183
|
>
|
|
164
|
-
<FrontmatterPanel data={frontmatter} onOpenFile={onOpenFile} />
|
|
184
|
+
<FrontmatterPanel data={frontmatter} onOpenFile={onOpenFile} fileLinkTarget={fileLinkTarget} />
|
|
165
185
|
<div className="prose prose-sm max-w-none">
|
|
166
186
|
<Markdown
|
|
167
187
|
remarkPlugins={KB_REMARK_PLUGINS}
|
|
@@ -6,6 +6,7 @@ import {
|
|
|
6
6
|
useFileNav,
|
|
7
7
|
useNodeIdNav,
|
|
8
8
|
useCanonicalFileUrl,
|
|
9
|
+
useFileNodeId,
|
|
9
10
|
} from '../../routing/kb-routes';
|
|
10
11
|
import { useRendererWorkspaceId } from './rendererWorkspace';
|
|
11
12
|
import { useRendererSurface } from './rendererSurface';
|
|
@@ -13,29 +14,7 @@ import { WorkspaceContext } from '../../state/workspace.context';
|
|
|
13
14
|
import { markdownLinkForPaste } from '../../utils/pasteLink';
|
|
14
15
|
import { useWorkspaceImageResolver } from '../../hooks/useWorkspaceImageResolver';
|
|
15
16
|
import type { FileRendererProps, RendererSaveState } from './types';
|
|
16
|
-
|
|
17
|
-
/** Decode a URL hash (`#some%20slug`) to its bare slug, tolerating bad escapes. */
|
|
18
|
-
function safeDecodeHash(hash: string): string {
|
|
19
|
-
const raw = hash.replace(/^#/, '');
|
|
20
|
-
try {
|
|
21
|
-
return decodeURIComponent(raw);
|
|
22
|
-
} catch {
|
|
23
|
-
return raw;
|
|
24
|
-
}
|
|
25
|
-
}
|
|
26
|
-
|
|
27
|
-
/** Escape a slug for safe interpolation into an attribute-selector string. */
|
|
28
|
-
function escapeForSelector(value: string): string {
|
|
29
|
-
return (
|
|
30
|
-
value
|
|
31
|
-
.replace(/["\\]/g, '\\$&')
|
|
32
|
-
// CSS-hex-escape control characters (newline, CR, …): a raw control char in
|
|
33
|
-
// a CSS string is a syntax error that would make querySelector throw. The
|
|
34
|
-
// trailing space terminates the hex escape.
|
|
35
|
-
// eslint-disable-next-line no-control-regex
|
|
36
|
-
.replace(/[\x00-\x1f\x7f]/g, (c) => `\\${c.charCodeAt(0).toString(16)} `)
|
|
37
|
-
);
|
|
38
|
-
}
|
|
17
|
+
import { scrollToHeading } from './scrollToHeading';
|
|
39
18
|
|
|
40
19
|
/**
|
|
41
20
|
* Markdown view/edit renderer driven entirely by the parent's `readOnly`
|
|
@@ -63,12 +42,13 @@ export function MarkdownRenderer({
|
|
|
63
42
|
onSaveStateChange,
|
|
64
43
|
readOnly = false,
|
|
65
44
|
}: FileRendererProps) {
|
|
66
|
-
//
|
|
67
|
-
//
|
|
68
|
-
|
|
69
|
-
|
|
45
|
+
// A link out of the page opens its file in a new tab and leaves this one
|
|
46
|
+
// where it is; a section link scrolls here. The hook decides which, and
|
|
47
|
+
// `linkTarget` is the same answer for the anchor to carry.
|
|
48
|
+
const { openLink, linkTarget } = useFileNav();
|
|
49
|
+
// Shared id-link follower (the node's id URL, heading preserved) — same
|
|
70
50
|
// implementation the chat citation renderer uses.
|
|
71
|
-
const { openNodeId } = useNodeIdNav();
|
|
51
|
+
const { openNodeId, nodeIdTarget } = useNodeIdNav();
|
|
72
52
|
// The URL hash carries a heading slug for citation deep-links
|
|
73
53
|
// (`…/Node.md#goal`); we scroll the matching heading into view once the
|
|
74
54
|
// rendered content is in the DOM.
|
|
@@ -126,19 +106,17 @@ export function MarkdownRenderer({
|
|
|
126
106
|
// Deep-link scroll: when the URL has a `#heading-slug` fragment, scroll the
|
|
127
107
|
// heading with that id (added by rehype-slug) into view. Re-runs when the
|
|
128
108
|
// hash, the file, or the rendered value changes — the latter because the
|
|
129
|
-
// content may still be loading when the route first resolves.
|
|
109
|
+
// content may still be loading when the route first resolves. Also on
|
|
110
|
+
// `location.key`: a section link to this file navigates to this tab's own
|
|
111
|
+
// address plus the fragment, and when the tab is already there the hash
|
|
112
|
+
// string does not change — only the key, which `navigate` renews on every
|
|
113
|
+
// call — so a second click on the same link, after the reader scrolled
|
|
114
|
+
// away, scrolls again instead of doing nothing.
|
|
130
115
|
useEffect(() => {
|
|
131
|
-
if (!readOnly) return;
|
|
132
|
-
const
|
|
133
|
-
if (!slug) return;
|
|
134
|
-
const raf = requestAnimationFrame(() => {
|
|
135
|
-
const container = scrollContainerRef.current;
|
|
136
|
-
if (!container) return;
|
|
137
|
-
const target = container.querySelector(`[id="${escapeForSelector(slug)}"]`);
|
|
138
|
-
target?.scrollIntoView({ block: 'start' });
|
|
139
|
-
});
|
|
116
|
+
if (!readOnly || !location.hash) return;
|
|
117
|
+
const raf = requestAnimationFrame(() => scrollToHeading(scrollContainerRef.current, location.hash));
|
|
140
118
|
return () => cancelAnimationFrame(raf);
|
|
141
|
-
}, [location.hash, filePath, value, readOnly]);
|
|
119
|
+
}, [location.hash, location.key, filePath, value, readOnly]);
|
|
142
120
|
|
|
143
121
|
// Citation deep-link for a heading: the node's canonical URL (its id URL when
|
|
144
122
|
// it's a node, else the path URL) plus the heading's `#slug`. Matches the "copy
|
|
@@ -159,6 +137,23 @@ export function MarkdownRenderer({
|
|
|
159
137
|
(href: string) => openLink(href, filePath),
|
|
160
138
|
[openLink, filePath],
|
|
161
139
|
);
|
|
140
|
+
const fileLinkTarget = useCallback(
|
|
141
|
+
(href: string) => linkTarget(href, filePath),
|
|
142
|
+
[linkTarget, filePath],
|
|
143
|
+
);
|
|
144
|
+
// An id-link to THIS node is a section link whatever the address bar says:
|
|
145
|
+
// the tab may still be on the path URL (the id not canonicalized yet, or a
|
|
146
|
+
// library frame that never canonicalizes), so the hook is told which node
|
|
147
|
+
// is on screen rather than reading it off the URL.
|
|
148
|
+
const ownNodeId = useFileNodeId(filePath);
|
|
149
|
+
const handleNodeIdLink = useCallback(
|
|
150
|
+
(idOrLink: string) => openNodeId(idOrLink, ownNodeId),
|
|
151
|
+
[openNodeId, ownNodeId],
|
|
152
|
+
);
|
|
153
|
+
const nodeIdLinkTarget = useCallback(
|
|
154
|
+
(idOrLink: string) => nodeIdTarget(idOrLink, ownNodeId),
|
|
155
|
+
[nodeIdTarget, ownNodeId],
|
|
156
|
+
);
|
|
162
157
|
|
|
163
158
|
// An image in the page: the same grammar, but the bytes come from this
|
|
164
159
|
// workspace's raw file route (a plain `<img>` authenticates through the
|
|
@@ -266,7 +261,9 @@ export function MarkdownRenderer({
|
|
|
266
261
|
<KbMarkdownView
|
|
267
262
|
source={value}
|
|
268
263
|
onOpenFile={handleFileLink}
|
|
269
|
-
onOpenNodeId={
|
|
264
|
+
onOpenNodeId={handleNodeIdLink}
|
|
265
|
+
fileLinkTarget={fileLinkTarget}
|
|
266
|
+
nodeIdLinkTarget={nodeIdLinkTarget}
|
|
270
267
|
headingLink={headingLink}
|
|
271
268
|
resolveImage={resolveImage}
|
|
272
269
|
// On a renderer surface (the embed) EVERY outgoing link is the
|
|
@@ -7,7 +7,7 @@ import { Surface, useConfirm } from '../../../../shared/components';
|
|
|
7
7
|
import { Markdown } from '../../../../shared/markdown/Markdown';
|
|
8
8
|
import { ToolForm } from './ToolForm';
|
|
9
9
|
import { ToolSecretsPanel } from '../../../secrets-vault/components/ToolSecretsPanel';
|
|
10
|
-
import { listToolSecrets, type ToolSecrets } from '../../../secrets-vault
|
|
10
|
+
import { listToolSecrets, type ToolSecrets } from '../../../secrets-vault';
|
|
11
11
|
import { useRendererSurface } from './rendererSurface';
|
|
12
12
|
|
|
13
13
|
/**
|