@kabmo-labs/kabmo 0.17.0 → 0.18.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/dist/client/index.html +1 -1
- package/dist/client/index.js +538 -457
- package/dist/client/static/js/index-hp75vsv9.css +1 -0
- package/dist/client/static/js/{index-rerjq5th.js → index-tc09dtca.js} +823 -814
- package/package.json +1 -1
- package/src/client/components/common/MarkdownRenderer.tsx +136 -89
- package/src/client/components/common/anchored-menu/index.test.tsx +141 -0
- package/src/client/components/common/anchored-menu/index.tsx +143 -0
- package/src/client/components/common/markdown-review/ReviewPopover.tsx +144 -0
- package/src/client/components/common/markdown-review/ReviewSummary.tsx +108 -0
- package/src/client/components/common/markdown-review/index.tsx +129 -0
- package/src/client/components/common/server-control/Panel.tsx +33 -23
- package/src/client/components/common/server-control/index.test.tsx +11 -5
- package/src/client/components/common/server-control/index.tsx +10 -8
- package/src/client/components/layout/session-sidebar/CategoryHeader.tsx +42 -21
- package/src/client/components/layout/session-sidebar/CategoryHeader.worktree.test.tsx +36 -17
- package/src/client/components/layout/session-sidebar/CategoryItem.tsx +8 -7
- package/src/client/components/layout/session-sidebar/about-modal/NotesDialog.tsx +94 -0
- package/src/client/components/layout/session-sidebar/about-modal/VersionLine.test.tsx +68 -0
- package/src/client/components/layout/session-sidebar/about-modal/VersionLine.tsx +36 -0
- package/src/client/components/layout/session-sidebar/about-modal/index.tsx +57 -34
- package/src/client/components/layout/session-sidebar/modern/WorkspaceHeader.tsx +28 -10
- package/src/client/components/layout/session-sidebar/modern/WorkspaceSection.tsx +7 -6
- package/src/client/components/layout/session-sidebar/modern/workspace-header.test.tsx +1 -1
- package/src/client/components/layout/update-popup/ReleaseNotes.tsx +8 -3
- package/src/client/components/layout/update-popup/index.tsx +5 -1
- package/src/client/components/mobile/mobile-right-sidebar/FullEditor.tsx +13 -15
- package/src/client/components/mobile/mobile-right-sidebar/Header.tsx +23 -1
- package/src/client/components/mobile/mobile-right-sidebar/MissingFileBanner.tsx +30 -0
- package/src/client/components/mobile/mobile-right-sidebar/PreviewScroller.tsx +18 -2
- package/src/client/components/mobile/mobile-session-sidebar/Item.tsx +22 -67
- package/src/client/components/mobile/mobile-session-sidebar/ItemMenu.tsx +110 -0
- package/src/client/components/settings/SettingsSidebarList.tsx +20 -0
- package/src/client/components/settings/categories/AgentSettings.tsx +23 -50
- package/src/client/components/settings/categories/CommandSettings.tsx +2 -2
- package/src/client/components/settings/categories/McpSettings.tsx +4 -21
- package/src/client/components/settings/categories/OmpSettings.tsx +147 -194
- package/src/client/components/settings/categories/SkillSettings.tsx +2 -2
- package/src/client/components/settings/categories/TokenUsageSettings.tsx +211 -229
- package/src/client/components/settings/categories/agent-settings/DetailPane.tsx +229 -237
- package/src/client/components/settings/categories/agent-settings/ModelPicker.tsx +71 -0
- package/src/client/components/settings/categories/agent-settings/SidebarList.tsx +9 -2
- package/src/client/components/settings/categories/agent-settings/levels.ts +38 -0
- package/src/client/components/settings/categories/behavior-settings/Editor.tsx +27 -7
- package/src/client/components/settings/categories/chat-settings/ToolRenderSection.tsx +23 -5
- package/src/client/components/settings/categories/command-settings/DetailPane.tsx +75 -33
- package/src/client/components/settings/categories/command-settings/SidebarList.tsx +7 -0
- package/src/client/components/settings/categories/mcp-settings/DetailPane.tsx +91 -76
- package/src/client/components/settings/categories/mcp-settings/EnvVarsSection.tsx +83 -0
- package/src/client/components/settings/categories/mcp-settings/ImportModal.tsx +26 -13
- package/src/client/components/settings/categories/mcp-settings/SidebarList.tsx +20 -0
- package/src/client/components/settings/categories/omp-settings/ConfigTabs.tsx +97 -36
- package/src/client/components/settings/categories/omp-settings/EngineHeader.tsx +151 -0
- package/src/client/components/settings/categories/omp-settings/ExtensionsPanel.tsx +68 -32
- package/src/client/components/settings/categories/omp-settings/OrderedChips.tsx +119 -0
- package/src/client/components/settings/categories/omp-settings/PresetBar.tsx +14 -7
- package/src/client/components/settings/categories/omp-settings/RoleEditor.tsx +15 -6
- package/src/client/components/settings/categories/omp-settings/RowEditor.tsx +165 -226
- package/src/client/components/settings/categories/omp-settings/types.ts +28 -0
- package/src/client/components/settings/categories/skill-settings/DetailHeader.tsx +35 -7
- package/src/client/components/settings/categories/skill-settings/DetailPane.tsx +34 -14
- package/src/client/components/settings/categories/skill-settings/SidebarList.tsx +21 -0
- package/src/client/components/settings/categories/skill-settings/pane.test.tsx +15 -6
- package/src/client/components/settings/categories/token-usage-settings/Breakdown.tsx +242 -102
- package/src/client/components/settings/categories/token-usage-settings/Chart.tsx +130 -56
- package/src/client/components/settings/categories/token-usage-settings/Controls.tsx +135 -0
- package/src/client/components/settings/categories/token-usage-settings/MetricsGrid.tsx +55 -33
- package/src/client/components/settings/categories/token-usage-settings/Provenance.tsx +59 -0
- package/src/client/components/settings/categories/token-usage-settings/panel.test.tsx +239 -0
- package/src/client/components/workspace/browser-panel/Screencast.test.ts +1 -0
- package/src/client/components/workspace/browser-panel/Screencast.tsx +17 -22
- package/src/client/components/workspace/browser-panel/TabStrip.test.tsx +158 -0
- package/src/client/components/workspace/browser-panel/TabStrip.tsx +90 -0
- package/src/client/components/workspace/browser-panel/index.tsx +50 -4
- package/src/client/components/workspace/browser-toolbar/index.tsx +41 -1
- package/src/client/components/workspace/chat-timeline/ThinkingSection.tsx +3 -1
- package/src/client/components/workspace/chat-timeline/ToolCallingSection.tsx +2 -0
- package/src/client/components/workspace/chat-timeline/block-chrome.test.tsx +13 -2
- package/src/client/components/workspace/chat-timeline/tool-renderers/panels/Bash.test.ts +88 -0
- package/src/client/components/workspace/chat-timeline/tool-renderers/panels/Bash.tsx +24 -1
- package/src/client/components/workspace/chat-timeline/tool-renderers/panels/Read.test.ts +34 -0
- package/src/client/components/workspace/chat-timeline/tool-renderers/panels/Read.tsx +5 -1
- package/src/client/components/workspace/chat-timeline/tool-renderers/shared/ArtifactChip.tsx +7 -6
- package/src/client/components/workspace/chat-timeline/tool-renderers/styles/Tui.test.tsx +237 -0
- package/src/client/components/workspace/chat-timeline/tool-renderers/styles/Tui.tsx +191 -0
- package/src/client/components/workspace/chat-timeline/tool-renderers/styles/styles.test.tsx +1 -1
- package/src/client/components/workspace/diff-panel/MergeDiffView.tsx +21 -7
- package/src/client/components/workspace/diff-panel/changes.test.ts +51 -0
- package/src/client/components/workspace/diff-panel/changes.ts +28 -12
- package/src/client/components/workspace/diff-panel/merge.test.ts +28 -0
- package/src/client/components/workspace/diff-panel/merge.ts +21 -1
- package/src/client/components/workspace/editor/Body.tsx +7 -0
- package/src/client/components/workspace/editor/FileDocument.tsx +15 -21
- package/src/client/components/workspace/editor/FilePane.tsx +12 -0
- package/src/client/components/workspace/editor/PreviewPane.tsx +70 -0
- package/src/client/components/workspace/editor/Toolbar.tsx +17 -1
- package/src/client/components/workspace/editor/index.tsx +25 -22
- package/src/client/components/workspace/editor/toolbar-clusters.test.ts +14 -0
- package/src/client/components/workspace/editor/toolbar-clusters.tsx +12 -86
- package/src/client/components/workspace/editor/toolbar-toggle.tsx +53 -0
- package/src/client/components/workspace/editor/toolbar-write-clusters.tsx +112 -0
- package/src/client/components/workspace/git-panel/commit-modal.test.ts +5 -3
- package/src/client/components/workspace/user-browser-panel/AddressBar.tsx +5 -0
- package/src/client/components/workspace/user-browser-panel/AnnotateBar.test.tsx +201 -0
- package/src/client/components/workspace/user-browser-panel/AnnotateBar.tsx +112 -0
- package/src/client/components/workspace/user-browser-panel/AnnotateLayer.test.tsx +225 -0
- package/src/client/components/workspace/user-browser-panel/AnnotateLayer.tsx +217 -0
- package/src/client/components/workspace/user-browser-panel/AnnotateTarget.tsx +99 -0
- package/src/client/components/workspace/user-browser-panel/Frame.tsx +30 -1
- package/src/client/components/workspace/user-browser-panel/index.tsx +81 -2
- package/src/client/data/agent-data/builtin.ts +0 -10
- package/src/client/data/agent-data/orchestrator.ts +0 -45
- package/src/client/data/agent-data/specialist.ts +0 -100
- package/src/client/data/mock/token-usage.ts +170 -120
- package/src/client/data/settings/omp-schema.json +33 -1
- package/src/client/hooks/browser/use-annotate.test.ts +143 -0
- package/src/client/hooks/browser/use-annotate.ts +98 -0
- package/src/client/hooks/browser/use-close-tab.test.ts +148 -0
- package/src/client/hooks/browser/use-close-tab.ts +67 -0
- package/src/client/hooks/browser/use-screencast.ts +13 -1
- package/src/client/hooks/chat/composer/browser-context.test.ts +117 -0
- package/src/client/hooks/chat/composer/browser-context.ts +40 -16
- package/src/client/hooks/chat/composer/items.test.ts +1 -1
- package/src/client/hooks/chat/composer/review-context.ts +38 -0
- package/src/client/hooks/chat/composer/use-draft.test.ts +132 -0
- package/src/client/hooks/chat/composer/use-draft.ts +31 -2
- package/src/client/hooks/chat/timeline/row-window.test.ts +15 -2
- package/src/client/hooks/editor/use-document-annotations.ts +124 -0
- package/src/client/hooks/editor/use-editor-panel-ui.ts +52 -0
- package/src/client/hooks/editor/use-file-review-mode.ts +35 -0
- package/src/client/hooks/editor/use-preview-review.ts +148 -0
- package/src/client/hooks/settings/agents.ts +149 -0
- package/src/client/hooks/settings/crud-list.test.ts +28 -6
- package/src/client/hooks/settings/crud-list.ts +96 -57
- package/src/client/hooks/settings/omp-config.ts +164 -0
- package/src/client/hooks/settings/useTokenUsage.ts +125 -0
- package/src/client/hooks/settings/write-feedback.test.ts +104 -0
- package/src/client/hooks/settings/write-feedback.ts +63 -0
- package/src/client/hooks/ui/markdown-hydration.ts +125 -0
- package/src/client/hooks/ui/updates/index.test.ts +100 -1
- package/src/client/hooks/ui/updates/index.ts +50 -0
- package/src/client/hooks/ui/updates/notes.test.ts +138 -0
- package/src/client/hooks/ui/updates/notes.ts +57 -0
- package/src/client/lib/browser/element-at.test.ts +229 -0
- package/src/client/lib/browser/element-at.ts +139 -0
- package/src/client/lib/review/client.ts +73 -0
- package/src/client/lib/router/search-params.ts +42 -20
- package/src/client/tailwind.css +65 -0
- package/src/server/lib/btw/lifecycle.server.ts +2 -2
- package/src/server/lib/db/schema.ts +7 -0
- package/src/server/lib/db/seed-terminal.test.ts +4 -0
- package/src/server/lib/omp/config/agent-definitions.test.ts +273 -0
- package/src/server/lib/omp/config/agents.ts +231 -61
- package/src/server/lib/omp/config/definitions.test.ts +9 -105
- package/src/server/lib/omp/config/extensions.ts +16 -7
- package/src/server/lib/omp/config/omp-config-files.test.ts +27 -0
- package/src/server/lib/omp/rpc/constants.test.ts +11 -0
- package/src/server/lib/omp/rpc/constants.ts +15 -0
- package/src/server/lib/omp/rpc/process.ts +11 -14
- package/src/server/lib/omp/rpc/session-commands.ts +6 -3
- package/src/server/lib/omp/rpc/utility-agent-dir.test.ts +134 -0
- package/src/server/lib/omp/rpc/utility-agent-dir.ts +138 -0
- package/src/server/lib/omp/rpc/utility.ts +12 -0
- package/src/server/lib/review/schema.server.ts +45 -0
- package/src/server/lib/review/store.server.ts +138 -0
- package/src/server/lib/terminal/attach-replay.test.ts +132 -0
- package/src/server/lib/terminal/output.test.ts +166 -0
- package/src/server/lib/terminal/output.ts +104 -0
- package/src/server/lib/terminal/runtime.server.ts +5 -0
- package/src/server/lib/terminal/send-result.test.ts +33 -0
- package/src/server/lib/terminal/send-result.ts +32 -0
- package/src/server/lib/terminal/session.server.ts +45 -11
- package/src/server/lib/terminal/store-liveness.test.ts +4 -0
- package/src/server/lib/updates/active-notes.test.ts +149 -0
- package/src/server/lib/updates/active-notes.ts +75 -0
- package/src/server/lib/updates/changelog-file.ts +42 -11
- package/src/server/lib/updates/changelog.test.ts +15 -1
- package/src/server/lib/updates/omp.ts +42 -15
- package/src/server/lib/updates/release-url.ts +27 -1
- package/src/server/lib/usage/index-parse.test.ts +200 -0
- package/src/server/lib/usage/index-parse.ts +178 -0
- package/src/server/lib/usage/index-query.server.ts +248 -0
- package/src/server/lib/usage/index-scan.server.ts +343 -0
- package/src/server/lib/usage/index-schema.server.ts +82 -0
- package/src/server/lib/usage/index.test.ts +234 -0
- package/src/server/lib/usage/providers.server.ts +4 -53
- package/src/server/routes/browser/index.ts +3 -0
- package/src/server/routes/browser/stream.ts +31 -2
- package/src/server/routes/browser/tabs.test.ts +94 -0
- package/src/server/routes/browser/tabs.ts +85 -0
- package/src/server/routes/index.ts +2 -0
- package/src/server/routes/review/bindings.ts +11 -0
- package/src/server/routes/review/index.ts +127 -0
- package/src/server/routes/review/routes.test.ts +191 -0
- package/src/server/routes/settings/agents.test.ts +180 -0
- package/src/server/routes/settings/agents.ts +95 -102
- package/src/server/routes/settings/mcp.test.ts +135 -0
- package/src/server/routes/settings/mcp.ts +14 -6
- package/src/server/routes/settings/settings-store-routes.test.ts +6 -113
- package/src/server/routes/telemetry/tokens.test.ts +145 -0
- package/src/server/routes/telemetry/tokens.ts +70 -149
- package/src/server/routes/terminal/ws.ts +6 -5
- package/src/server/routes/updates/index.ts +2 -0
- package/src/server/routes/updates/notes.ts +34 -0
- package/src/server/routes/updates/routes.test.ts +49 -0
- package/src/shared/lib/browser/annotate.test.ts +283 -0
- package/src/shared/lib/browser/annotate.ts +231 -0
- package/src/shared/lib/browser/browser-viewer.test.ts +26 -4
- package/src/shared/lib/browser/frame-gate.test.ts +91 -0
- package/src/shared/lib/browser/frame-gate.ts +69 -0
- package/src/shared/lib/browser/frame-params.test.ts +43 -0
- package/src/shared/lib/browser/frame-params.ts +60 -0
- package/src/shared/lib/browser/frame-pipeline.test.ts +132 -0
- package/src/shared/lib/browser/frame-pipeline.ts +80 -0
- package/src/shared/lib/browser/page-context.ts +60 -4
- package/src/shared/lib/browser/snapshot.test.ts +115 -0
- package/src/shared/lib/browser/snapshot.ts +112 -0
- package/src/shared/lib/browser/tab-close.test.ts +74 -0
- package/src/shared/lib/browser/tab-close.ts +77 -0
- package/src/shared/lib/browser/viewer.ts +45 -26
- package/src/shared/lib/chat/timeline/block-chrome.ts +19 -0
- package/src/shared/lib/chat/timeline/tool-render-mode.ts +17 -4
- package/src/shared/lib/chat/tool/artifact.ts +55 -20
- package/src/shared/lib/chat/tool/bash-facts.ts +96 -0
- package/src/shared/lib/chat/tool/minimized.test.ts +98 -0
- package/src/shared/lib/chat/tool/minimized.ts +64 -0
- package/src/shared/lib/chat/tool/summary.test.ts +28 -8
- package/src/shared/lib/chat/tool/summary.ts +3 -32
- package/src/shared/lib/markdown/blocks/anchor.ts +63 -0
- package/src/shared/lib/markdown/blocks/blocks.test.ts +141 -0
- package/src/shared/lib/markdown/blocks/renderer.ts +120 -0
- package/src/shared/lib/markdown/blocks/scan.ts +100 -0
- package/src/shared/lib/markdown/blocks/types.ts +62 -0
- package/src/shared/lib/markdown/marked.ts +58 -147
- package/src/shared/lib/markdown/math-extensions.ts +168 -0
- package/src/shared/lib/markdown/review/prompt.ts +77 -0
- package/src/shared/lib/markdown/review/reconcile.ts +55 -0
- package/src/shared/lib/markdown/review/review.test.ts +96 -0
- package/src/shared/lib/markdown/xml-sections.test.ts +140 -0
- package/src/shared/lib/markdown/xml-sections.ts +139 -0
- package/src/shared/lib/models/provider/label.ts +57 -0
- package/src/shared/lib/omp/config/agent-file.test.ts +54 -0
- package/src/shared/lib/omp/config/agent-file.ts +43 -0
- package/src/shared/lib/omp/config/row-value.test.ts +95 -0
- package/src/shared/lib/omp/config/row-value.ts +97 -0
- package/src/shared/lib/omp/config/schema.test.ts +31 -0
- package/src/shared/lib/omp/config/schema.ts +6 -0
- package/src/shared/lib/omp/rpc/frame.test.ts +48 -47
- package/src/shared/lib/omp/rpc/frame.ts +49 -40
- package/src/shared/lib/ui/menu-anchor.test.ts +69 -0
- package/src/shared/lib/ui/menu-anchor.ts +89 -0
- package/src/shared/lib/usage/breakdown.test.ts +197 -0
- package/src/shared/lib/usage/breakdown.ts +241 -0
- package/src/shared/lib/usage/range.test.ts +204 -0
- package/src/shared/lib/usage/range.ts +240 -0
- package/src/shared/lib/usage/view.test.ts +85 -0
- package/src/shared/lib/usage/view.ts +74 -0
- package/src/shared/types/browser.ts +78 -0
- package/src/shared/types/index.ts +1 -0
- package/src/shared/types/settings/agent.ts +28 -6
- package/src/shared/types/settings/state.ts +4 -3
- package/src/shared/types/settings/write.ts +6 -0
- package/src/shared/types/tokenUsage.ts +128 -21
- package/src/shared/types/updates.ts +20 -0
- package/dist/client/static/js/index-3ve31rzx.css +0 -1
- package/src/server/lib/omp/session/usage/aggregate-shaping.test.ts +0 -149
- package/src/server/lib/omp/session/usage/aggregate.test.ts +0 -243
- package/src/server/lib/omp/session/usage/aggregate.ts +0 -330
- package/src/server/lib/omp/session/usage/shaping.ts +0 -130
|
@@ -4,35 +4,59 @@
|
|
|
4
4
|
*/
|
|
5
5
|
|
|
6
6
|
/**
|
|
7
|
-
* Sibling-panel bridge: listens for
|
|
8
|
-
*
|
|
9
|
-
*
|
|
7
|
+
* Sibling-panel bridge: listens for a browser panel's "include page" event and
|
|
8
|
+
* appends its block to the chat draft. Lives beside the timeline hooks because
|
|
9
|
+
* they own the persisted draft (`chat.draft`).
|
|
10
|
+
*
|
|
11
|
+
* The TEXT is built by `shared/lib/browser/page-context`, not here: the same
|
|
12
|
+
* block is produced by the formatter's own tests, so a second spelling in the
|
|
13
|
+
* listener would let the annotated page and the plain page drift apart.
|
|
14
|
+
*
|
|
15
|
+
* An annotated page sends no attachment. The user panel's page is a
|
|
16
|
+
* cross-origin iframe, so there are no bytes to attach — what it sends is the
|
|
17
|
+
* region and the note, which the agent resolves by opening the URL itself.
|
|
10
18
|
*/
|
|
11
19
|
|
|
12
20
|
import { useEffect, useRef } from 'preact/hooks';
|
|
13
|
-
import { BROWSER_INCLUDE_PAGE_EVENT } from '@/shared/lib/browser/page-context';
|
|
14
|
-
import {
|
|
21
|
+
import { BROWSER_INCLUDE_PAGE_EVENT, appendPageContext } from '@/shared/lib/browser/page-context';
|
|
22
|
+
import { readAnnotatePanel, readAnnotationShapes } from '@/shared/lib/browser/annotate';
|
|
15
23
|
import { isRecord } from '@/shared/lib/util/guards';
|
|
24
|
+
import { readString } from '@/shared/lib/browser/util';
|
|
25
|
+
import type { BrowserPageContext } from '@/shared/types';
|
|
16
26
|
|
|
17
27
|
type DraftSetter = (value: string | ((prev: string) => string)) => void;
|
|
18
28
|
|
|
19
|
-
/**
|
|
29
|
+
/** The parts of a dispatched detail this bridge trusts, from a DOM event. */
|
|
30
|
+
export function readPageContextDetail(raw: unknown): BrowserPageContext | null {
|
|
31
|
+
if (!isRecord(raw)) return null;
|
|
32
|
+
const url = readString(raw, 'url');
|
|
33
|
+
if (!url) return null;
|
|
34
|
+
const title = readString(raw, 'title');
|
|
35
|
+
const detail: BrowserPageContext = { url };
|
|
36
|
+
if (title) detail.title = title;
|
|
37
|
+
// The marks are echoed back only when BOTH halves survive validation: a shape
|
|
38
|
+
// list without its panel box cannot be turned into percentages of anything,
|
|
39
|
+
// and a malformed batch degrades to the plain page context rather than to a
|
|
40
|
+
// prompt carrying a broken annotation section.
|
|
41
|
+
const annotations = readAnnotationShapes(raw.annotations);
|
|
42
|
+
const panel = readAnnotatePanel(raw.panel);
|
|
43
|
+
if (annotations && panel) {
|
|
44
|
+
detail.annotations = annotations;
|
|
45
|
+
detail.panel = panel;
|
|
46
|
+
}
|
|
47
|
+
return detail;
|
|
48
|
+
}
|
|
49
|
+
|
|
50
|
+
/** Append a page-context block to the composer draft on the panel event. */
|
|
20
51
|
export function useBrowserPageContextInsert(setInputValue: DraftSetter): void {
|
|
21
52
|
const setterRef = useRef(setInputValue);
|
|
22
53
|
setterRef.current = setInputValue;
|
|
23
54
|
|
|
24
55
|
useEffect(() => {
|
|
25
56
|
const handler = (event: Event): void => {
|
|
26
|
-
const detail = event instanceof CustomEvent ? event.detail : null;
|
|
27
|
-
if (!
|
|
28
|
-
|
|
29
|
-
if (!url) return;
|
|
30
|
-
const title = readString(detail, 'title');
|
|
31
|
-
setterRef.current((prev) => {
|
|
32
|
-
const separator = prev && !prev.endsWith('\n') ? '\n\n' : prev ? '\n' : '';
|
|
33
|
-
const titleLine = title ? `\nJudul: ${title}` : '';
|
|
34
|
-
return `${prev}${separator}[Konteks halaman browser]\nURL: ${url}${titleLine}\n(Lanjutkan dari halaman ini.)`;
|
|
35
|
-
});
|
|
57
|
+
const detail = event instanceof CustomEvent ? readPageContextDetail(event.detail) : null;
|
|
58
|
+
if (!detail) return;
|
|
59
|
+
setterRef.current((prev) => appendPageContext(prev, detail));
|
|
36
60
|
};
|
|
37
61
|
window.addEventListener(BROWSER_INCLUDE_PAGE_EVENT, handler);
|
|
38
62
|
return () => window.removeEventListener(BROWSER_INCLUDE_PAGE_EVENT, handler);
|
|
@@ -255,7 +255,7 @@ describe('plugin commands in the popup', () => {
|
|
|
255
255
|
describe('pick item mapping', () => {
|
|
256
256
|
test('an agent becomes a bare @name token', () => {
|
|
257
257
|
const [item] = toAgentPickItems([
|
|
258
|
-
{ id: 'a1', name: 'sonic', description: 'fast', scope: 'user',
|
|
258
|
+
{ id: 'a1', name: 'sonic', description: 'fast', scope: 'user', systemPrompt: '' },
|
|
259
259
|
]);
|
|
260
260
|
expect(item).toMatchObject({ id: 'agent-sonic', name: 'sonic', kind: 'agent', source: 'agent', token: '@sonic' });
|
|
261
261
|
});
|
|
@@ -0,0 +1,38 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* @license
|
|
3
|
+
* SPDX-License-Identifier: MIT
|
|
4
|
+
*/
|
|
5
|
+
|
|
6
|
+
/**
|
|
7
|
+
* Sibling-surface bridge: the editor's document review appended to the chat
|
|
8
|
+
* draft.
|
|
9
|
+
*
|
|
10
|
+
* A DOM event rather than shared state, for the same reason the browser panel's
|
|
11
|
+
* page context is one: the editor column and the chat timeline are separate
|
|
12
|
+
* trees, and the draft belongs to the timeline's own persisted hook
|
|
13
|
+
* (`chat.draft`). `formatReviewBlock` in `shared/lib/markdown/review/prompt.ts`
|
|
14
|
+
* owns the TEXT — two spellings of it is how the annotated document and the
|
|
15
|
+
* plain one start saying different things.
|
|
16
|
+
*/
|
|
17
|
+
|
|
18
|
+
import { useEffect, useRef } from 'preact/hooks';
|
|
19
|
+
|
|
20
|
+
import { REVIEW_INCLUDE_EVENT, appendReviewBlock } from '@/shared/lib/markdown/review/prompt';
|
|
21
|
+
|
|
22
|
+
type DraftSetter = (value: string | ((prev: string) => string)) => void;
|
|
23
|
+
|
|
24
|
+
/** Append a review block to the composer draft on the editor's event. */
|
|
25
|
+
export function useReviewIncludeInsert(setInputValue: DraftSetter): void {
|
|
26
|
+
const setterRef = useRef(setInputValue);
|
|
27
|
+
setterRef.current = setInputValue;
|
|
28
|
+
|
|
29
|
+
useEffect(() => {
|
|
30
|
+
const handler = (event: Event): void => {
|
|
31
|
+
const block = event instanceof CustomEvent && typeof event.detail === 'string' ? event.detail : '';
|
|
32
|
+
if (!block) return;
|
|
33
|
+
setterRef.current((previous) => appendReviewBlock(previous, block));
|
|
34
|
+
};
|
|
35
|
+
window.addEventListener(REVIEW_INCLUDE_EVENT, handler);
|
|
36
|
+
return () => window.removeEventListener(REVIEW_INCLUDE_EVENT, handler);
|
|
37
|
+
}, []);
|
|
38
|
+
}
|
|
@@ -0,0 +1,132 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* @license
|
|
3
|
+
* SPDX-License-Identifier: MIT
|
|
4
|
+
*/
|
|
5
|
+
|
|
6
|
+
/**
|
|
7
|
+
* The composer draft's SCOPE: a chat named in the URL, or the landing.
|
|
8
|
+
*
|
|
9
|
+
* The reported bug this pins: text appended while no session was open (an
|
|
10
|
+
* annotation sent from the browser panel) was stored on the provider's fallback
|
|
11
|
+
* id — the landing's own bucket — which is not a chat and never gets cleared,
|
|
12
|
+
* because the landing composer is disabled and nothing can send or clear it.
|
|
13
|
+
* Every later launch then opened with that text already in the box, reading as
|
|
14
|
+
* something the new chat had inherited.
|
|
15
|
+
*
|
|
16
|
+
* A landing draft is therefore memory-only. The cases below mount the real
|
|
17
|
+
* provider id the way `App` derives it (`?sessionId=` else `'1'`), so the
|
|
18
|
+
* fallback bucket is still the landing's store — it is just not WRITTEN.
|
|
19
|
+
*
|
|
20
|
+
* The hook is imported DYNAMICALLY, after the DOM exists: `useSearchParams`
|
|
21
|
+
* caches the search string and subscribes to `popstate` when its module loads,
|
|
22
|
+
* so a static import (evaluated before any `beforeAll` runs) would leave the
|
|
23
|
+
* router unable to see the URL these cases set. The module-load boundary is the
|
|
24
|
+
* subject here, which is the documented exception to static imports.
|
|
25
|
+
*/
|
|
26
|
+
|
|
27
|
+
import { afterAll, afterEach, beforeAll, beforeEach, describe, expect, test } from 'bun:test';
|
|
28
|
+
import { Window } from 'happy-dom';
|
|
29
|
+
import { h, render } from 'preact';
|
|
30
|
+
import { act } from 'preact/test-utils';
|
|
31
|
+
|
|
32
|
+
import { forgetSession, getSessionValue, setSessionKey } from '@/shared/lib/workspace/session-state/store';
|
|
33
|
+
import { emitBrowserPageContext } from '@/shared/lib/browser/page-context';
|
|
34
|
+
import { installDomGlobals, restoreDomGlobals } from '@/test-support/pristine-globals';
|
|
35
|
+
import { CHAT_DRAFT_KEY } from '@/shared/lib/chat/composer/draft';
|
|
36
|
+
import type { Context } from 'preact';
|
|
37
|
+
import type { ComposerDraftState } from '@/client/hooks/chat/composer/use-draft';
|
|
38
|
+
import type { SessionStateContextValue } from '@/client/hooks/workspace/session-state/context';
|
|
39
|
+
|
|
40
|
+
const LANDING_ID = '1';
|
|
41
|
+
const SEEDED = '[Konteks halaman browser]\nURL: http://localhost:7801/\n(Lanjutkan dari halaman ini.)';
|
|
42
|
+
|
|
43
|
+
let container: HTMLElement | undefined;
|
|
44
|
+
let holder: { api: ComposerDraftState | null };
|
|
45
|
+
let useComposerDraft: () => ComposerDraftState;
|
|
46
|
+
let SessionStateContext: Context<SessionStateContextValue | null>;
|
|
47
|
+
const nativeFetch = globalThis.fetch;
|
|
48
|
+
|
|
49
|
+
beforeAll(async () => {
|
|
50
|
+
installDomGlobals(new Window({ url: 'http://127.0.0.1/' }));
|
|
51
|
+
({ useComposerDraft } = await import('@/client/hooks/chat/composer/use-draft'));
|
|
52
|
+
({ SessionStateContext } = await import('@/client/hooks/workspace/session-state/context'));
|
|
53
|
+
});
|
|
54
|
+
|
|
55
|
+
beforeEach(() => {
|
|
56
|
+
// Writes are debounced-persisted; a stray POST is not what these cases read.
|
|
57
|
+
globalThis.fetch = (async () => new Response('{"state":{}}')) as unknown as typeof fetch;
|
|
58
|
+
forgetSession(LANDING_ID);
|
|
59
|
+
holder = { api: null };
|
|
60
|
+
pointAt('');
|
|
61
|
+
});
|
|
62
|
+
|
|
63
|
+
afterEach(() => {
|
|
64
|
+
if (container) render(null, container);
|
|
65
|
+
container?.remove();
|
|
66
|
+
container = undefined;
|
|
67
|
+
forgetSession(LANDING_ID);
|
|
68
|
+
});
|
|
69
|
+
|
|
70
|
+
afterAll(() => {
|
|
71
|
+
// The router caches `location.search` in a module and subscribes to
|
|
72
|
+
// `popstate` on the window that existed when IT loaded — this suite's. Put
|
|
73
|
+
// that cache back to the bare path before the window goes away, or every
|
|
74
|
+
// later suite in the same `bun test` process reads `?sessionId=1` off a
|
|
75
|
+
// window nobody can reach any more (measured: the sidebar controller drew a
|
|
76
|
+
// stray `1` row).
|
|
77
|
+
pointAt('');
|
|
78
|
+
globalThis.fetch = nativeFetch;
|
|
79
|
+
restoreDomGlobals();
|
|
80
|
+
});
|
|
81
|
+
|
|
82
|
+
function pointAt(search: string): void {
|
|
83
|
+
window.history.replaceState(null, '', `/${search}`);
|
|
84
|
+
window.dispatchEvent(new Event('popstate'));
|
|
85
|
+
}
|
|
86
|
+
|
|
87
|
+
/** Mount the draft hook for one URL, with the provider id `App` derives. */
|
|
88
|
+
function mount(search: string): void {
|
|
89
|
+
pointAt(search);
|
|
90
|
+
const sessionId = new URLSearchParams(search).get('sessionId') || LANDING_ID;
|
|
91
|
+
function Probe() {
|
|
92
|
+
holder.api = useComposerDraft();
|
|
93
|
+
return null;
|
|
94
|
+
}
|
|
95
|
+
container = document.body.appendChild(document.createElement('div'));
|
|
96
|
+
act(() => {
|
|
97
|
+
render(
|
|
98
|
+
h(SessionStateContext.Provider, { value: { sessionId, ready: true }, children: h(Probe, null) }),
|
|
99
|
+
container!,
|
|
100
|
+
);
|
|
101
|
+
});
|
|
102
|
+
}
|
|
103
|
+
|
|
104
|
+
describe('useComposerDraft', () => {
|
|
105
|
+
test('the landing does not restore the fallback bucket\'s draft', () => {
|
|
106
|
+
setSessionKey(LANDING_ID, CHAT_DRAFT_KEY, SEEDED);
|
|
107
|
+
mount('');
|
|
108
|
+
expect(holder.api!.inputValue).toBe('');
|
|
109
|
+
});
|
|
110
|
+
|
|
111
|
+
test('a landing draft is kept in memory and never written to a session slot', () => {
|
|
112
|
+
mount('');
|
|
113
|
+
act(() => holder.api!.setInputValue('typed at the landing'));
|
|
114
|
+
expect(holder.api!.inputValue).toBe('typed at the landing');
|
|
115
|
+
expect(getSessionValue(LANDING_ID, CHAT_DRAFT_KEY)).toBeUndefined();
|
|
116
|
+
});
|
|
117
|
+
|
|
118
|
+
test('an annotation sent at the landing stays out of the persisted draft', () => {
|
|
119
|
+
mount('');
|
|
120
|
+
act(() => emitBrowserPageContext({ url: 'https://a.test/x' }));
|
|
121
|
+
expect(holder.api!.inputValue).toContain('[Konteks halaman browser]');
|
|
122
|
+
expect(getSessionValue(LANDING_ID, CHAT_DRAFT_KEY)).toBeUndefined();
|
|
123
|
+
});
|
|
124
|
+
|
|
125
|
+
test('a session named in the URL still restores and persists its own draft', () => {
|
|
126
|
+
setSessionKey(LANDING_ID, CHAT_DRAFT_KEY, SEEDED);
|
|
127
|
+
mount(`?sessionId=${LANDING_ID}`);
|
|
128
|
+
expect(holder.api!.inputValue).toBe(SEEDED);
|
|
129
|
+
act(() => holder.api!.setInputValue('follow-up'));
|
|
130
|
+
expect(getSessionValue(LANDING_ID, CHAT_DRAFT_KEY)).toBe('follow-up');
|
|
131
|
+
});
|
|
132
|
+
});
|
|
@@ -11,10 +11,23 @@
|
|
|
11
11
|
* and the browser-panel insert appends to the text beside the attachments that
|
|
12
12
|
* arrived with it. Extracted from the timeline hook, which is at the repo's
|
|
13
13
|
* per-file ceiling.
|
|
14
|
+
*
|
|
15
|
+
* A LANDING draft (no `?sessionId=` in the URL) is memory-only.
|
|
16
|
+
*
|
|
17
|
+
* The landing mounts `SessionStateProvider` on its fallback id (`'1'`), which
|
|
18
|
+
* is not a chat: the composer there is disabled until a workspace is picked, so
|
|
19
|
+
* nothing the user does can send or clear it. Persisting under that id made the
|
|
20
|
+
* slot permanent — measured: a browser-panel annotation appended once at the
|
|
21
|
+
* landing was still sitting in the composer on every later launch, looking like
|
|
22
|
+
* text a new chat had inherited. A draft belongs to the chat named in the URL;
|
|
23
|
+
* with no chat named, it is kept for this page session only.
|
|
14
24
|
*/
|
|
15
25
|
|
|
26
|
+
import { useState } from 'preact/hooks';
|
|
27
|
+
import { useSearchParams } from '@/client/lib/router/search-params';
|
|
16
28
|
import { useSessionState } from '@/client/hooks/workspace/session-state';
|
|
17
29
|
import { useBrowserPageContextInsert } from '@/client/hooks/chat/composer/browser-context';
|
|
30
|
+
import { useReviewIncludeInsert } from '@/client/hooks/chat/composer/review-context';
|
|
18
31
|
import { CHAT_DRAFT_ATTACHMENTS_KEY, CHAT_DRAFT_KEY } from '@/shared/lib/chat/composer/draft';
|
|
19
32
|
import type { Attachment } from '@/shared/types';
|
|
20
33
|
|
|
@@ -26,8 +39,24 @@ export interface ComposerDraftState {
|
|
|
26
39
|
}
|
|
27
40
|
|
|
28
41
|
export function useComposerDraft(): ComposerDraftState {
|
|
29
|
-
const [
|
|
42
|
+
const [searchParams] = useSearchParams();
|
|
43
|
+
const scoped = Boolean(searchParams.get('sessionId'));
|
|
44
|
+
|
|
45
|
+
// Both branches are mounted unconditionally (hook order) and the scope only
|
|
46
|
+
// picks which one this render OBSERVES: the session copy keeps following the
|
|
47
|
+
// store, and the landing copy keeps whatever was typed at the landing, so
|
|
48
|
+
// stepping into a chat and back does not destroy either.
|
|
49
|
+
const [storedText, setStoredText] = useSessionState<string>(CHAT_DRAFT_KEY, '');
|
|
50
|
+
const [storedAttachments, setStoredAttachments] = useSessionState<Attachment[]>(CHAT_DRAFT_ATTACHMENTS_KEY, []);
|
|
51
|
+
const [landingText, setLandingText] = useState('');
|
|
52
|
+
const [landingAttachments, setLandingAttachments] = useState<Attachment[]>([]);
|
|
53
|
+
|
|
54
|
+
const inputValue = scoped ? storedText : landingText;
|
|
55
|
+
const setInputValue = scoped ? setStoredText : setLandingText;
|
|
30
56
|
useBrowserPageContextInsert(setInputValue);
|
|
31
|
-
|
|
57
|
+
useReviewIncludeInsert(setInputValue);
|
|
58
|
+
|
|
59
|
+
const inputAttachments = scoped ? storedAttachments : landingAttachments;
|
|
60
|
+
const setInputAttachments = scoped ? setStoredAttachments : setLandingAttachments;
|
|
32
61
|
return { inputValue, setInputValue, inputAttachments, setInputAttachments };
|
|
33
62
|
}
|
|
@@ -50,6 +50,9 @@ const scrollWrites: Array<{ top: number; behavior?: ScrollBehavior }> = [];
|
|
|
50
50
|
/** Frames are queued, never run by the platform, so a test drives them. */
|
|
51
51
|
let frames: Array<() => void> = [];
|
|
52
52
|
|
|
53
|
+
/** The runner's own globals, captured before this suite overwrites them. */
|
|
54
|
+
const saved: Record<string, unknown> = {};
|
|
55
|
+
|
|
53
56
|
function drainFrames(rounds = 6): void {
|
|
54
57
|
for (let i = 0; i < rounds && frames.length > 0; i += 1) {
|
|
55
58
|
const pending = frames;
|
|
@@ -119,6 +122,8 @@ beforeAll(async () => {
|
|
|
119
122
|
cancelAnimationFrame: () => {},
|
|
120
123
|
};
|
|
121
124
|
for (const [key, value] of Object.entries(globals)) {
|
|
125
|
+
// Captured BEFORE the overwrite, so the runner's own values come back.
|
|
126
|
+
saved[key] = (globalThis as Record<string, unknown>)[key];
|
|
122
127
|
(globalThis as Record<string, unknown>)[key] = value;
|
|
123
128
|
}
|
|
124
129
|
// Preact binds its environment at module evaluation, so the modules below
|
|
@@ -129,8 +134,16 @@ beforeAll(async () => {
|
|
|
129
134
|
});
|
|
130
135
|
|
|
131
136
|
afterAll(() => {
|
|
132
|
-
|
|
133
|
-
|
|
137
|
+
// RESTORED, never deleted: `requestAnimationFrame`/`cancelAnimationFrame` are
|
|
138
|
+
// in `installDomGlobals`'s list (`pristine-globals.ts`), so a later suite that
|
|
139
|
+
// installs a window keeps whatever this file left behind. Deleting them made
|
|
140
|
+
// every following Preact suite that schedules a frame die with
|
|
141
|
+
// `ReferenceError: cancelAnimationFrame is not defined` (measured:
|
|
142
|
+
// `session-pagination.test.ts`'s rail jump, and the unhandled errors that
|
|
143
|
+
// followed it through `session-switch` and `scroll-reading-back`).
|
|
144
|
+
for (const [key, value] of Object.entries(saved)) {
|
|
145
|
+
if (value === undefined) delete (globalThis as Record<string, unknown>)[key];
|
|
146
|
+
else (globalThis as Record<string, unknown>)[key] = value;
|
|
134
147
|
}
|
|
135
148
|
});
|
|
136
149
|
|
|
@@ -0,0 +1,124 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* @license
|
|
3
|
+
* SPDX-License-Identifier: MIT
|
|
4
|
+
*/
|
|
5
|
+
|
|
6
|
+
/**
|
|
7
|
+
* One document's annotations, loaded and written.
|
|
8
|
+
*
|
|
9
|
+
* The hook owns the three states the review surface must distinguish, because
|
|
10
|
+
* collapsing them is how a failed read looks like "no annotations yet":
|
|
11
|
+
*
|
|
12
|
+
* - `loading` — a read is in flight;
|
|
13
|
+
* - `error` — the read failed, and the message is shown as-is;
|
|
14
|
+
* - an empty list — the read SUCCEEDED and there is nothing stored.
|
|
15
|
+
*
|
|
16
|
+
* A write optimistically replaces the row for its block and rolls back to the
|
|
17
|
+
* previous list when the server refuses, so the mark on screen never disagrees
|
|
18
|
+
* with what is stored. The tradeoff is deliberate: an optimistic write is what
|
|
19
|
+
* makes a click feel instant, and the rollback is the half that keeps it honest.
|
|
20
|
+
*/
|
|
21
|
+
|
|
22
|
+
import { useCallback, useEffect, useRef, useState } from 'preact/hooks';
|
|
23
|
+
|
|
24
|
+
import { fetchAnnotations, removeAnnotation, saveAnnotation } from '@/client/lib/review/client';
|
|
25
|
+
import type { BlockVerdict, DocumentAnnotation, ReviewTarget } from '@/shared/lib/markdown/blocks/types';
|
|
26
|
+
|
|
27
|
+
export interface UseDocumentAnnotationsResult {
|
|
28
|
+
annotations: DocumentAnnotation[];
|
|
29
|
+
loading: boolean;
|
|
30
|
+
/** The read's or a write's failure, shown verbatim. */
|
|
31
|
+
error: string | null;
|
|
32
|
+
/** Store a judgement for one block. Resolves whether or not the write landed. */
|
|
33
|
+
save: (input: { blockKey: string; lineStart: number; lineEnd: number; verdict: BlockVerdict; note: string; quote: string }) => Promise<void>;
|
|
34
|
+
/** Remove one judgement by its stored id. */
|
|
35
|
+
remove: (id: string) => Promise<void>;
|
|
36
|
+
/** Re-read after a failure. */
|
|
37
|
+
reload: () => void;
|
|
38
|
+
}
|
|
39
|
+
|
|
40
|
+
export function useDocumentAnnotations(target: ReviewTarget | null, enabled: boolean): UseDocumentAnnotationsResult {
|
|
41
|
+
const [annotations, setAnnotations] = useState<DocumentAnnotation[]>([]);
|
|
42
|
+
const [loading, setLoading] = useState(false);
|
|
43
|
+
const [error, setError] = useState<string | null>(null);
|
|
44
|
+
const [revision, setRevision] = useState(0);
|
|
45
|
+
|
|
46
|
+
const path = target?.path ?? null;
|
|
47
|
+
const root = target?.root ?? null;
|
|
48
|
+
const repo = target?.repo ?? null;
|
|
49
|
+
|
|
50
|
+
useEffect(() => {
|
|
51
|
+
if (!enabled || !path) {
|
|
52
|
+
setAnnotations([]);
|
|
53
|
+
setError(null);
|
|
54
|
+
setLoading(false);
|
|
55
|
+
return;
|
|
56
|
+
}
|
|
57
|
+
const controller = new AbortController();
|
|
58
|
+
setLoading(true);
|
|
59
|
+
setError(null);
|
|
60
|
+
fetchAnnotations({ path, root, repo }, controller.signal)
|
|
61
|
+
.then((rows) => {
|
|
62
|
+
if (controller.signal.aborted) return;
|
|
63
|
+
setAnnotations(rows);
|
|
64
|
+
})
|
|
65
|
+
.catch((cause: unknown) => {
|
|
66
|
+
if (controller.signal.aborted) return;
|
|
67
|
+
setError(cause instanceof Error ? cause.message : 'Could not read annotations');
|
|
68
|
+
})
|
|
69
|
+
.finally(() => {
|
|
70
|
+
if (!controller.signal.aborted) setLoading(false);
|
|
71
|
+
});
|
|
72
|
+
return () => controller.abort();
|
|
73
|
+
// The primitives, never the object: a caller builds `target` inline.
|
|
74
|
+
}, [enabled, path, root, repo, revision]);
|
|
75
|
+
|
|
76
|
+
// The latest list, so a rollback restores what was there — not what the
|
|
77
|
+
// render that created this closure saw.
|
|
78
|
+
const latest = useRef(annotations);
|
|
79
|
+
latest.current = annotations;
|
|
80
|
+
|
|
81
|
+
const save = useCallback<UseDocumentAnnotationsResult['save']>(
|
|
82
|
+
async (input) => {
|
|
83
|
+
if (!path) return;
|
|
84
|
+
const previous = latest.current;
|
|
85
|
+
const optimistic: DocumentAnnotation = {
|
|
86
|
+
id: `pending:${input.blockKey}`,
|
|
87
|
+
scope: '',
|
|
88
|
+
path,
|
|
89
|
+
blockKey: input.blockKey,
|
|
90
|
+
lineStart: input.lineStart,
|
|
91
|
+
lineEnd: input.lineEnd,
|
|
92
|
+
verdict: input.verdict,
|
|
93
|
+
note: input.note,
|
|
94
|
+
quote: input.quote,
|
|
95
|
+
createdAt: Date.now(),
|
|
96
|
+
updatedAt: Date.now(),
|
|
97
|
+
};
|
|
98
|
+
setAnnotations([...previous.filter((row) => row.blockKey !== input.blockKey), optimistic]);
|
|
99
|
+
setError(null);
|
|
100
|
+
try {
|
|
101
|
+
const stored = await saveAnnotation({ path, root, repo }, input);
|
|
102
|
+
setAnnotations((current) => current.map((row) => (row.blockKey === input.blockKey ? stored : row)));
|
|
103
|
+
} catch (cause) {
|
|
104
|
+
setAnnotations(previous);
|
|
105
|
+
setError(cause instanceof Error ? cause.message : 'Could not save the annotation');
|
|
106
|
+
}
|
|
107
|
+
},
|
|
108
|
+
[path, root, repo],
|
|
109
|
+
);
|
|
110
|
+
|
|
111
|
+
const remove = useCallback<UseDocumentAnnotationsResult['remove']>(async (id) => {
|
|
112
|
+
const previous = latest.current;
|
|
113
|
+
setAnnotations(previous.filter((row) => row.id !== id));
|
|
114
|
+
setError(null);
|
|
115
|
+
try {
|
|
116
|
+
await removeAnnotation(id);
|
|
117
|
+
} catch (cause) {
|
|
118
|
+
setAnnotations(previous);
|
|
119
|
+
setError(cause instanceof Error ? cause.message : 'Could not remove the annotation');
|
|
120
|
+
}
|
|
121
|
+
}, []);
|
|
122
|
+
|
|
123
|
+
return { annotations, loading, error, save, remove, reload: () => setRevision((value) => value + 1) };
|
|
124
|
+
}
|
|
@@ -0,0 +1,52 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* @license
|
|
3
|
+
* SPDX-License-Identifier: MIT
|
|
4
|
+
*/
|
|
5
|
+
|
|
6
|
+
/**
|
|
7
|
+
* The editor panel's transient UI: the command palette, the go-to-line dialog,
|
|
8
|
+
* quick open and Save As.
|
|
9
|
+
*
|
|
10
|
+
* One hook because these four are one decision — each is a thing the user is
|
|
11
|
+
* doing RIGHT NOW, so none of them is persisted — and because the panel that
|
|
12
|
+
* owns them also owns the chords that open them. Extracting them keeps
|
|
13
|
+
* `index.tsx` under the per-file ceiling as the panel gained a review mode, and
|
|
14
|
+
* it is the same split `use-editor-panel-keys` already makes for the keyboard.
|
|
15
|
+
*
|
|
16
|
+
* `goToLineRequest` is a COUNTER rather than a boolean: the dialog lives in the
|
|
17
|
+
* document (where the caret and the handle are), so a boolean would need a
|
|
18
|
+
* matching "closed" write from that side to be re-openable.
|
|
19
|
+
*/
|
|
20
|
+
|
|
21
|
+
import { useCallback, useState } from 'preact/hooks';
|
|
22
|
+
|
|
23
|
+
export interface EditorPanelUi {
|
|
24
|
+
paletteOpen: boolean;
|
|
25
|
+
setPaletteOpen: (open: boolean) => void;
|
|
26
|
+
/** Bumped once per request; the document opens the dialog when it moves. */
|
|
27
|
+
goToLineRequest: number;
|
|
28
|
+
openGoToLine: () => void;
|
|
29
|
+
quickOpen: boolean;
|
|
30
|
+
setQuickOpen: (open: boolean) => void;
|
|
31
|
+
saveAsOpen: boolean;
|
|
32
|
+
setSaveAsOpen: (open: boolean) => void;
|
|
33
|
+
}
|
|
34
|
+
|
|
35
|
+
export function useEditorPanelUi(): EditorPanelUi {
|
|
36
|
+
const [paletteOpen, setPaletteOpen] = useState(false);
|
|
37
|
+
const [goToLineRequest, setGoToLineRequest] = useState(0);
|
|
38
|
+
const [quickOpen, setQuickOpen] = useState(false);
|
|
39
|
+
const [saveAsOpen, setSaveAsOpen] = useState(false);
|
|
40
|
+
const openGoToLine = useCallback(() => setGoToLineRequest((previous) => previous + 1), []);
|
|
41
|
+
|
|
42
|
+
return {
|
|
43
|
+
paletteOpen,
|
|
44
|
+
setPaletteOpen,
|
|
45
|
+
goToLineRequest,
|
|
46
|
+
openGoToLine,
|
|
47
|
+
quickOpen,
|
|
48
|
+
setQuickOpen,
|
|
49
|
+
saveAsOpen,
|
|
50
|
+
setSaveAsOpen,
|
|
51
|
+
};
|
|
52
|
+
}
|
|
@@ -0,0 +1,35 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* @license
|
|
3
|
+
* SPDX-License-Identifier: MIT
|
|
4
|
+
*/
|
|
5
|
+
|
|
6
|
+
/**
|
|
7
|
+
* Review mode for one open document, as a per-tab persisted toggle.
|
|
8
|
+
*
|
|
9
|
+
* ONE key (`editor.reviewMode`) and one owner, shared by the desktop pane and the
|
|
10
|
+
* phone's full-screen editor: both draw the same surface, both remember the
|
|
11
|
+
* choice per tab, and a second copy of this rule is how the two layouts end up
|
|
12
|
+
* disagreeing about whether a document is being reviewed.
|
|
13
|
+
*
|
|
14
|
+
* Off by default, and that default is the feature: review mode swallows clicks
|
|
15
|
+
* inside the document — links, copy buttons, the diagram viewer all become block
|
|
16
|
+
* selections. A reader who never asked to review anything keeps every one of
|
|
17
|
+
* them, which is why the mode is entered from a toolbar button and nowhere else.
|
|
18
|
+
*/
|
|
19
|
+
|
|
20
|
+
import { useSessionState } from '@/client/hooks/workspace/session-state';
|
|
21
|
+
|
|
22
|
+
export interface FileReviewMode {
|
|
23
|
+
/** This tab is being reviewed. */
|
|
24
|
+
active: boolean;
|
|
25
|
+
/** Turn it on or off. */
|
|
26
|
+
toggle: () => void;
|
|
27
|
+
}
|
|
28
|
+
|
|
29
|
+
export function useFileReviewMode(tabKey: string): FileReviewMode {
|
|
30
|
+
const [mode, setMode] = useSessionState<Record<string, boolean>>('editor.reviewMode', {});
|
|
31
|
+
return {
|
|
32
|
+
active: mode[tabKey] === true,
|
|
33
|
+
toggle: () => setMode((previous) => ({ ...previous, [tabKey]: previous[tabKey] !== true })),
|
|
34
|
+
};
|
|
35
|
+
}
|