@vibe-forge/client 0.11.2 → 1.0.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/cli.cjs +6 -11
- package/dist/assets/{arc-De_WjPJ3.js → arc-CbOXL0l9.js} +1 -1
- package/dist/assets/{blockDiagram-c4efeb88-C4aR2zTE.js → blockDiagram-c4efeb88-CqxINvsS.js} +1 -1
- package/dist/assets/{c4Diagram-c83219d4-BZH3rq_m.js → c4Diagram-c83219d4-BKazU0hb.js} +1 -1
- package/dist/assets/channel-Dnopc5A6.js +1 -0
- package/dist/assets/{classDiagram-beda092f-BzJgBrIK.js → classDiagram-beda092f-fAFX5BpB.js} +1 -1
- package/dist/assets/{classDiagram-v2-2358418a-5ZtXcnT3.js → classDiagram-v2-2358418a-w1VkNGJj.js} +1 -1
- package/dist/assets/clone-sQthahUA.js +1 -0
- package/dist/assets/{createText-1719965b-DUVvEtmR.js → createText-1719965b-CEinakVP.js} +1 -1
- package/dist/assets/{cssMode-GoTNjuXX.js → cssMode-DPqRki4y.js} +1 -1
- package/dist/assets/{edges-96097737-Dd7m4Cvs.js → edges-96097737-Cb0F1_3K.js} +1 -1
- package/dist/assets/{erDiagram-0228fc6a-DxqFlG_f.js → erDiagram-0228fc6a-C-N2fx-J.js} +1 -1
- package/dist/assets/{flowDb-c6c81e3f-DU0C5kCI.js → flowDb-c6c81e3f-D1Xz_8Gf.js} +1 -1
- package/dist/assets/{flowDiagram-50d868cf-Di1uDa_X.js → flowDiagram-50d868cf-DyPSZyAj.js} +1 -1
- package/dist/assets/flowDiagram-v2-4f6560a1-OazrdWQO.js +1 -0
- package/dist/assets/{flowchart-elk-definition-6af322e1-CwG8aty5.js → flowchart-elk-definition-6af322e1-Dr1DDXwE.js} +1 -1
- package/dist/assets/{freemarker2-j39cqTlI.js → freemarker2-C3DvPFaK.js} +1 -1
- package/dist/assets/{ganttDiagram-a2739b55-baO_lzL-.js → ganttDiagram-a2739b55-DmvY1GRj.js} +1 -1
- package/dist/assets/{gitGraphDiagram-82fe8481-COoHjYMf.js → gitGraphDiagram-82fe8481-CoXfPYYi.js} +1 -1
- package/dist/assets/{graph-KxESr4M5.js → graph-BkDQy7Qt.js} +1 -1
- package/dist/assets/{handlebars-BgjdZO8G.js → handlebars-BcTFdqjl.js} +1 -1
- package/dist/assets/{html-Ba7tYObe.js → html-Dg-O6XFr.js} +1 -1
- package/dist/assets/{htmlMode-Bztvbig1.js → htmlMode-B_wqYWvn.js} +1 -1
- package/dist/assets/{index-5325376f-BMTAx2mL.js → index-5325376f-kxPTR3_e.js} +1 -1
- package/dist/assets/index-o93dlo92.css +32 -0
- package/dist/assets/{index-Pm_kLJvG.js → index-wkhI4dr6.js} +350 -329
- package/dist/assets/{infoDiagram-8eee0895-CC74qbHY.js → infoDiagram-8eee0895-BEvqkwPI.js} +1 -1
- package/dist/assets/{javascript-C1e1cllX.js → javascript-DhlOH8_z.js} +1 -1
- package/dist/assets/{journeyDiagram-c64418c1-C4MyOdE6.js → journeyDiagram-c64418c1-gKtLYmmp.js} +1 -1
- package/dist/assets/{jsonMode-BC98AlvF.js → jsonMode-DxTbF9OD.js} +1 -1
- package/dist/assets/{layout-CxAyTlr7.js → layout-CDaZEk6E.js} +1 -1
- package/dist/assets/{line-DhaUfI71.js → line-DNRQu8iq.js} +1 -1
- package/dist/assets/{linear-MYukzldK.js → linear-Cph9Z6_j.js} +1 -1
- package/dist/assets/{liquid-DahfJEYl.js → liquid-ByZ6JgRG.js} +1 -1
- package/dist/assets/{lspLanguageFeatures-BWDJcswW.js → lspLanguageFeatures-DzvhkgnM.js} +1 -1
- package/dist/assets/{mdx-BELlF_FD.js → mdx-D8RGHTl6.js} +1 -1
- package/dist/assets/{mermaid.core-BrQnSGSY.js → mermaid.core-BgcryF__.js} +4 -4
- package/dist/assets/{mindmap-definition-8da855dc-B0FoxTiy.js → mindmap-definition-8da855dc-WrxK0FcB.js} +1 -1
- package/dist/assets/{pieDiagram-a8764435-Ddr2cjSL.js → pieDiagram-a8764435-VsZBsiQy.js} +1 -1
- package/dist/assets/{python--C9if_AD.js → python-CXVtk_cg.js} +1 -1
- package/dist/assets/{quadrantDiagram-1e28029f-BlEs7Mrl.js → quadrantDiagram-1e28029f-BVlgwOvU.js} +1 -1
- package/dist/assets/{razor-B9U9JxKn.js → razor-0tind7h2.js} +1 -1
- package/dist/assets/{requirementDiagram-08caed73-kEFOAu2v.js → requirementDiagram-08caed73-CpPMPoYp.js} +1 -1
- package/dist/assets/{sankeyDiagram-a04cb91d-BBghez8I.js → sankeyDiagram-a04cb91d-Cm5nnRmc.js} +1 -1
- package/dist/assets/{sequenceDiagram-c5b8d532-CJqgzdUE.js → sequenceDiagram-c5b8d532-DpMlJvJB.js} +1 -1
- package/dist/assets/{stateDiagram-1ecb1508-BER4XEI6.js → stateDiagram-1ecb1508-DU1zc7vq.js} +1 -1
- package/dist/assets/{stateDiagram-v2-c2b004d7-EBV2vSks.js → stateDiagram-v2-c2b004d7-D-0RgmAp.js} +1 -1
- package/dist/assets/{styles-b4e223ce-k0eswZsE.js → styles-b4e223ce-BSO-yNWV.js} +1 -1
- package/dist/assets/{styles-ca3715f6-Ckr7GA-0.js → styles-ca3715f6-CHnsn2Ro.js} +1 -1
- package/dist/assets/{styles-d45a18b0-C1bpSwV3.js → styles-d45a18b0-B-rVGjEq.js} +1 -1
- package/dist/assets/{svgDrawCommon-b86b1483-CDtKpGvy.js → svgDrawCommon-b86b1483-CA3Pl89f.js} +1 -1
- package/dist/assets/{timeline-definition-faaaa080-BeGR-vua.js → timeline-definition-faaaa080-BcihLR6s.js} +1 -1
- package/dist/assets/{tsMode-D_gJXIy3.js → tsMode-D9GGa5Ur.js} +1 -1
- package/dist/assets/{typescript-BoKcNXkN.js → typescript-BT9CK_EL.js} +1 -1
- package/dist/assets/{xml-DZvURlJ-.js → xml-DNO75J-T.js} +1 -1
- package/dist/assets/{xychartDiagram-f5964ef8-DxfeLuYV.js → xychartDiagram-f5964ef8-DJTwe32X.js} +1 -1
- package/dist/assets/{yaml-CTC8PAGY.js → yaml-7CVzhiP2.js} +1 -1
- package/dist/index.html +2 -2
- package/package.json +13 -10
- package/src/api/git.ts +12 -0
- package/src/api/sessions.ts +131 -4
- package/src/api/types.ts +2 -1
- package/src/api.ts +13 -0
- package/src/components/ArchiveView.scss +143 -54
- package/src/components/ArchiveView.tsx +181 -167
- package/src/components/CodeBlock.scss +5 -0
- package/src/components/ConfigView.scss +142 -31
- package/src/components/ConfigView.tsx +161 -86
- package/src/components/MarkdownContent.tsx +7 -0
- package/src/components/NavRail.scss +248 -0
- package/src/components/NavRail.tsx +80 -107
- package/src/components/NavRailCompact.tsx +107 -0
- package/src/components/NavRailCompactMoreSheet.tsx +141 -0
- package/src/components/ShortcutTooltip.tsx +4 -2
- package/src/components/Sidebar.scss +51 -0
- package/src/components/Sidebar.tsx +43 -16
- package/src/components/automation-view/RuleFormPanel.scss +40 -13
- package/src/components/automation-view/RuleSidebar.scss +73 -47
- package/src/components/automation-view/RuleSidebar.tsx +9 -13
- package/src/components/automation-view/RunHistoryPanel.scss +141 -13
- package/src/components/automation-view/RunHistoryPanel.tsx +203 -161
- package/src/components/automation-view/TaskList.scss +44 -13
- package/src/components/automation-view/TriggerList.scss +46 -14
- package/src/components/automation-view/index.scss +82 -10
- package/src/components/automation-view/index.tsx +108 -55
- package/src/components/benchmark-view/BenchmarkCasePanel.scss +36 -16
- package/src/components/benchmark-view/BenchmarkSidebar.scss +44 -22
- package/src/components/benchmark-view/BenchmarkSidebar.tsx +0 -6
- package/src/components/benchmark-view/BenchmarkView.scss +63 -20
- package/src/components/benchmark-view/index.tsx +71 -34
- package/src/components/chat/AGENTS.md +14 -2
- package/src/components/chat/ChatComposerCard.scss +77 -0
- package/src/components/chat/ChatComposerCard.tsx +59 -0
- package/src/components/chat/ChatHeader.scss +187 -0
- package/src/components/chat/ChatHeader.tsx +209 -57
- package/src/components/chat/ChatHistoryView.tsx +279 -52
- package/src/components/chat/ChatTimelineView.scss +94 -1
- package/src/components/chat/ChatTimelineView.tsx +42 -0
- package/src/components/chat/CurrentTodoList.scss +210 -200
- package/src/components/chat/CurrentTodoList.tsx +116 -48
- package/src/components/chat/NewSessionGuide.scss +139 -1
- package/src/components/chat/NewSessionGuide.tsx +57 -100
- package/src/components/chat/NewSessionGuideCompactPanel.tsx +130 -0
- package/src/components/chat/NewSessionGuideGrid.tsx +141 -0
- package/src/components/chat/QueuedMessagesCard.scss +195 -0
- package/src/components/chat/QueuedMessagesCard.tsx +170 -0
- package/src/components/chat/git-controls/BranchSwitcherDropdown.tsx +61 -56
- package/src/components/chat/git-controls/BranchSwitcherResults.tsx +167 -0
- package/src/components/chat/git-controls/BranchTreeEntries.tsx +99 -0
- package/src/components/chat/git-controls/ChatGitControls.scss +437 -5
- package/src/components/chat/git-controls/ChatGitControls.tsx +136 -109
- package/src/components/chat/git-controls/DraftGitControls.tsx +91 -0
- package/src/components/chat/git-controls/GitOperationsDropdown.tsx +10 -2
- package/src/components/chat/git-controls/GitWorktreeDropdown.tsx +301 -28
- package/src/components/chat/git-controls/git-branch-tree.ts +148 -0
- package/src/components/chat/git-controls/use-chat-draft-git-controls.ts +168 -0
- package/src/components/chat/git-controls/use-chat-git-controls.ts +76 -3
- package/src/components/chat/messages/MessageContextMenu.tsx +3 -1
- package/src/components/chat/messages/MessageItem.scss +78 -4
- package/src/components/chat/messages/MessageItem.tsx +47 -3
- package/src/components/chat/sender/@components/adapter-select/AdapterSelectControl.scss +23 -0
- package/src/components/chat/sender/@components/reference-actions/ReferenceActionsControl.scss +17 -0
- package/src/components/chat/sender/@components/reference-actions/ReferencePermissionActionsPopover.tsx +4 -1
- package/src/components/chat/sender/@components/sender-attachments/SenderAttachments.scss +167 -30
- package/src/components/chat/sender/@components/sender-attachments/SenderAttachments.tsx +95 -23
- package/src/components/chat/sender/@components/sender-body/SenderBody.tsx +10 -0
- package/src/components/chat/sender/@components/sender-interaction-panel/SenderInteractionPanel.scss +161 -45
- package/src/components/chat/sender/@components/sender-interaction-panel/SenderInteractionPanel.tsx +310 -71
- package/src/components/chat/sender/@components/sender-monaco-editor/SenderMonacoEditor.tsx +18 -0
- package/src/components/chat/sender/@components/sender-monaco-editor/use-sender-monaco-editor.ts +86 -9
- package/src/components/chat/sender/@components/sender-monaco-editor/use-sender-monaco-theme.ts +52 -3
- package/src/components/chat/sender/@components/sender-submit-action/SenderSubmitAction.scss +110 -1
- package/src/components/chat/sender/@components/sender-submit-action/SenderSubmitAction.tsx +137 -17
- package/src/components/chat/sender/@components/sender-toolbar/SenderSelectBase.scss +21 -0
- package/src/components/chat/sender/@components/sender-toolbar/SenderSelectShared.scss +21 -0
- package/src/components/chat/sender/@components/sender-toolbar/SenderToolbar.scss +63 -0
- package/src/components/chat/sender/@components/sender-toolbar/SenderToolbar.tsx +12 -6
- package/src/components/chat/sender/@core/build-sender-controller-result.ts +6 -0
- package/src/components/chat/sender/@core/build-sender-toolbar.ts +25 -2
- package/src/components/chat/sender/@core/create-sender-toolbar-handlers.ts +9 -2
- package/src/components/chat/sender/@core/get-sender-runtime-state.ts +1 -1
- package/src/components/chat/sender/@core/interaction-request.ts +2 -2
- package/src/components/chat/sender/@core/sender-toolbar-bindings.ts +28 -4
- package/src/components/chat/sender/@hooks/use-model-select-browser.tsx +4 -2
- package/src/components/chat/sender/@hooks/use-sender-controller.ts +56 -11
- package/src/components/chat/sender/@hooks/use-sender-keydown.ts +64 -0
- package/src/components/chat/sender/@hooks/use-sender-shortcuts.ts +16 -1
- package/src/components/chat/sender/@hooks/use-sender-submit.ts +16 -8
- package/src/components/chat/sender/@types/sender-props.ts +20 -3
- package/src/components/chat/sender/@types/sender-toolbar-types.ts +12 -1
- package/src/components/chat/sender/Sender.scss +4 -1
- package/src/components/chat/sender/Sender.tsx +3 -12
- package/src/components/chat/session-timeline-panel/EventList.scss +88 -0
- package/src/components/chat/session-timeline-panel/EventList.tsx +99 -47
- package/src/components/chat/session-timeline-panel/gantt.ts +23 -7
- package/src/components/chat/session-timeline-panel/git-graph.ts +6 -1
- package/src/components/chat/session-timeline-panel/index.scss +14 -1
- package/src/components/chat/session-timeline-panel/index.tsx +86 -10
- package/src/components/chat/session-timeline-panel/types.ts +4 -0
- package/src/components/chat/status-bar/ChatStatusBar.scss +27 -0
- package/src/components/chat/status-bar/ChatStatusBar.tsx +39 -0
- package/src/components/chat/terminal/ChatTerminalView.tsx +6 -0
- package/src/components/chat/tools/core/ToolCallBox.scss +19 -0
- package/src/components/chat/tools/core/ToolGroup.scss +32 -0
- package/src/components/chat/tools/task/components/TaskToolCard.scss +59 -1
- package/src/components/config/ConfigEditors.scss +20 -6
- package/src/components/config/ConfigFieldRow.scss +57 -17
- package/src/components/config/ConfigSectionForm.scss +10 -4
- package/src/components/config/ConfigSectionPanel.tsx +18 -11
- package/src/components/config/configSchema.ts +1 -0
- package/src/components/config/record-editors/RecordEditors.scss +42 -9
- package/src/components/dock-panel/DockPanel.scss +6 -2
- package/src/components/dock-panel/DockPanel.tsx +12 -16
- package/src/components/knowledge-base/KnowledgeBaseView.scss +180 -6
- package/src/components/knowledge-base/KnowledgeBaseView.tsx +98 -26
- package/src/components/knowledge-base/components/ActionButton.scss +4 -0
- package/src/components/knowledge-base/components/EmptyState.scss +5 -8
- package/src/components/knowledge-base/components/EntitiesTab.tsx +8 -2
- package/src/components/knowledge-base/components/EntityItem.scss +10 -3
- package/src/components/knowledge-base/components/FilterBar.scss +13 -2
- package/src/components/knowledge-base/components/FlowsTab.tsx +8 -2
- package/src/components/knowledge-base/components/KnowledgeBaseHeader.scss +2 -23
- package/src/components/knowledge-base/components/KnowledgeBaseHeader.tsx +0 -5
- package/src/components/knowledge-base/components/KnowledgeList.scss +15 -6
- package/src/components/knowledge-base/components/LoadingState.scss +4 -0
- package/src/components/knowledge-base/components/RuleItem.scss +86 -0
- package/src/components/knowledge-base/components/RuleItem.tsx +2 -0
- package/src/components/knowledge-base/components/RulesTab.tsx +8 -2
- package/src/components/knowledge-base/components/SectionHeader.scss +3 -18
- package/src/components/knowledge-base/components/SectionHeader.tsx +3 -7
- package/src/components/knowledge-base/components/SkillsTab.tsx +8 -3
- package/src/components/knowledge-base/components/SpecItem.scss +16 -7
- package/src/components/layout/@hooks/use-mobile-sidebar-modal.ts +190 -0
- package/src/components/layout/AppShell.scss +106 -6
- package/src/components/layout/AppShell.tsx +118 -10
- package/src/components/layout/PageShell.scss +41 -0
- package/src/components/layout/PageShell.tsx +32 -0
- package/src/components/layout/mobile-sidebar-constants.ts +1 -0
- package/src/components/nav-rail-compact-config.ts +114 -0
- package/src/components/nav-rail-items.tsx +181 -0
- package/src/components/sidebar/SessionContextMenu.tsx +3 -1
- package/src/components/sidebar/SessionItem.scss +62 -0
- package/src/components/sidebar/SessionItem.tsx +97 -52
- package/src/components/sidebar/SessionList.tsx +6 -0
- package/src/components/sidebar/SidebarHeader.scss +49 -0
- package/src/components/sidebar/SidebarHeader.tsx +27 -5
- package/src/components/sidebar/SidebarHeaderBatchActions.tsx +8 -4
- package/src/components/sidebar/SidebarHeaderSearchActions.tsx +6 -3
- package/src/components/sidebar/SidebarUtilityFooter.tsx +69 -0
- package/src/components/workspace/ContextFilePicker.tsx +12 -4
- package/src/hooks/chat/chat-session-workspace-draft.ts +25 -0
- package/src/hooks/chat/session-view-cache.ts +4 -1
- package/src/hooks/chat/use-chat-adapter.ts +5 -1
- package/src/hooks/chat/use-chat-model-adapter-selection.tsx +5 -1
- package/src/hooks/chat/use-chat-scroll.ts +24 -7
- package/src/hooks/chat/use-chat-session-actions.ts +118 -6
- package/src/hooks/chat/use-chat-session-messages.ts +20 -1
- package/src/hooks/chat/use-chat-session.ts +2 -0
- package/src/hooks/use-responsive-layout.ts +115 -0
- package/src/main.tsx +8 -0
- package/src/resources/adapters.ts +15 -0
- package/src/resources/locales/en.json +84 -1
- package/src/resources/locales/zh.json +84 -1
- package/src/routes/ChatRoute.scss +152 -9
- package/src/routes/ChatRoute.tsx +31 -34
- package/src/store/index.ts +2 -0
- package/dist/assets/channel-BvERb8WU.js +0 -1
- package/dist/assets/clone-B9_0v-6Y.js +0 -1
- package/dist/assets/flowDiagram-v2-4f6560a1-LpS8Kb00.js +0 -1
- package/dist/assets/index-C1oh0w9H.css +0 -32
- package/src/components/chat/ThinkingStatus.scss +0 -70
- package/src/components/chat/ThinkingStatus.tsx +0 -13
package/src/components/chat/sender/@components/sender-interaction-panel/SenderInteractionPanel.tsx
CHANGED
|
@@ -1,12 +1,18 @@
|
|
|
1
|
+
/* eslint-disable max-lines */
|
|
1
2
|
import './SenderInteractionPanel.scss'
|
|
2
3
|
|
|
3
|
-
import {
|
|
4
|
-
import {
|
|
4
|
+
import { useEffect, useMemo, useRef, useState } from 'react'
|
|
5
|
+
import type { KeyboardEvent as ReactKeyboardEvent } from 'react'
|
|
6
|
+
|
|
7
|
+
import { Button, Tooltip } from 'antd'
|
|
5
8
|
import { useTranslation } from 'react-i18next'
|
|
6
9
|
|
|
7
10
|
import type { AskUserQuestionParams } from '@vibe-forge/core'
|
|
8
11
|
import type { PermissionInteractionContext } from '@vibe-forge/types'
|
|
9
12
|
|
|
13
|
+
import { ChatComposerCard } from '#~/components/chat/ChatComposerCard'
|
|
14
|
+
import { getLoopedIndex } from '#~/hooks/use-roving-focus-list'
|
|
15
|
+
|
|
10
16
|
const primaryOptionValues = new Set(['allow_once', 'allow_session', 'deny_once'])
|
|
11
17
|
|
|
12
18
|
const getOptionMeta = (value?: string) => {
|
|
@@ -28,118 +34,351 @@ const getOptionMeta = (value?: string) => {
|
|
|
28
34
|
}
|
|
29
35
|
}
|
|
30
36
|
|
|
37
|
+
const renderInfoButton = (title: string) => (
|
|
38
|
+
<Tooltip title={title} placement='top' destroyOnHidden>
|
|
39
|
+
<span
|
|
40
|
+
className='material-symbols-rounded interaction-panel__info-trigger'
|
|
41
|
+
aria-label={title}
|
|
42
|
+
role='img'
|
|
43
|
+
onMouseDown={(event) => {
|
|
44
|
+
event.preventDefault()
|
|
45
|
+
event.stopPropagation()
|
|
46
|
+
}}
|
|
47
|
+
onClick={(event) => {
|
|
48
|
+
event.preventDefault()
|
|
49
|
+
event.stopPropagation()
|
|
50
|
+
}}
|
|
51
|
+
>
|
|
52
|
+
info
|
|
53
|
+
</span>
|
|
54
|
+
</Tooltip>
|
|
55
|
+
)
|
|
56
|
+
|
|
57
|
+
const getInteractionOptionKey = (
|
|
58
|
+
option: { label: string; value?: string },
|
|
59
|
+
idx: number
|
|
60
|
+
) => option.value ?? `${idx}:${option.label}`
|
|
61
|
+
|
|
31
62
|
export function SenderInteractionPanel({
|
|
32
63
|
interactionRequest,
|
|
64
|
+
activeOptionIndex,
|
|
33
65
|
permissionContext,
|
|
34
66
|
deniedTools,
|
|
35
67
|
reasons: _reasons,
|
|
68
|
+
onActiveOptionIndexChange,
|
|
69
|
+
onMoveActiveOption,
|
|
36
70
|
onInteractionResponse
|
|
37
71
|
}: {
|
|
38
72
|
interactionRequest: { id: string; payload: AskUserQuestionParams }
|
|
73
|
+
activeOptionIndex: number
|
|
39
74
|
permissionContext?: PermissionInteractionContext
|
|
40
75
|
deniedTools: string[]
|
|
41
76
|
reasons: string[]
|
|
77
|
+
onActiveOptionIndexChange: (index: number) => void
|
|
78
|
+
onMoveActiveOption: (delta: number) => void
|
|
42
79
|
onInteractionResponse?: (id: string, data: string | string[]) => void
|
|
43
80
|
}) {
|
|
44
81
|
const { t } = useTranslation()
|
|
45
|
-
const [
|
|
82
|
+
const [showAllPermissionOptions, setShowAllPermissionOptions] = useState(false)
|
|
83
|
+
const isPermissionInteraction = permissionContext != null
|
|
84
|
+
const options = interactionRequest.payload.options ?? []
|
|
85
|
+
const optionsContainerRef = useRef<HTMLDivElement | null>(null)
|
|
86
|
+
const normalizedActiveOptionIndex = options.length === 0
|
|
87
|
+
? -1
|
|
88
|
+
: Math.min(Math.max(activeOptionIndex, 0), options.length - 1)
|
|
89
|
+
|
|
90
|
+
const optionItems = useMemo(() =>
|
|
91
|
+
options.map((option, index) => ({
|
|
92
|
+
option,
|
|
93
|
+
index,
|
|
94
|
+
meta: getOptionMeta(option.value)
|
|
95
|
+
})), [options])
|
|
96
|
+
const primaryPermissionOptionItems = useMemo(
|
|
97
|
+
() => optionItems.filter(({ option }) => primaryOptionValues.has(option.value ?? '')),
|
|
98
|
+
[optionItems]
|
|
99
|
+
)
|
|
100
|
+
const secondaryPermissionOptionItems = useMemo(
|
|
101
|
+
() => optionItems.filter(({ option }) => !primaryOptionValues.has(option.value ?? '')),
|
|
102
|
+
[optionItems]
|
|
103
|
+
)
|
|
104
|
+
const activePermissionOptionIsSecondary = isPermissionInteraction &&
|
|
105
|
+
secondaryPermissionOptionItems.some(({ index }) => index === normalizedActiveOptionIndex)
|
|
106
|
+
const visibleOptionItems = isPermissionInteraction
|
|
107
|
+
? ((showAllPermissionOptions || activePermissionOptionIsSecondary) ? optionItems : primaryPermissionOptionItems)
|
|
108
|
+
: optionItems
|
|
46
109
|
|
|
47
110
|
const toolNames = [
|
|
48
111
|
permissionContext?.subjectLabel?.trim() ?? '',
|
|
49
112
|
...deniedTools.map(tool => tool.trim())
|
|
50
113
|
].filter((value, index, values) => value !== '' && values.indexOf(value) === index)
|
|
51
114
|
const toolSummary = toolNames.join('、')
|
|
52
|
-
const title = toolSummary
|
|
53
|
-
?
|
|
54
|
-
:
|
|
55
|
-
|
|
56
|
-
|
|
57
|
-
|
|
58
|
-
|
|
115
|
+
const title = isPermissionInteraction && toolSummary !== ''
|
|
116
|
+
? t('chat.permissionRequestTitleWithTool', { tool: toolSummary })
|
|
117
|
+
: interactionRequest.payload.question
|
|
118
|
+
|
|
119
|
+
const focusOptionAtIndex = (index: number, attempt = 0) => {
|
|
120
|
+
const option = optionsContainerRef.current?.querySelector<HTMLButtonElement>(
|
|
121
|
+
`.interaction-panel__option[data-option-index="${index}"]`
|
|
122
|
+
)
|
|
123
|
+
|
|
124
|
+
if (option != null) {
|
|
125
|
+
option.focus()
|
|
126
|
+
return
|
|
127
|
+
}
|
|
128
|
+
|
|
129
|
+
if (attempt >= 5) {
|
|
130
|
+
return
|
|
131
|
+
}
|
|
132
|
+
|
|
133
|
+
window.setTimeout(() => {
|
|
134
|
+
focusOptionAtIndex(index, attempt + 1)
|
|
135
|
+
}, 40)
|
|
136
|
+
}
|
|
59
137
|
|
|
60
138
|
useEffect(() => {
|
|
61
|
-
|
|
139
|
+
setShowAllPermissionOptions(false)
|
|
62
140
|
}, [interactionRequest.id])
|
|
63
141
|
|
|
142
|
+
useEffect(() => {
|
|
143
|
+
if (activePermissionOptionIsSecondary) {
|
|
144
|
+
setShowAllPermissionOptions(true)
|
|
145
|
+
}
|
|
146
|
+
}, [activePermissionOptionIsSecondary])
|
|
147
|
+
|
|
148
|
+
useEffect(() => {
|
|
149
|
+
if (!isPermissionInteraction || options.length === 0) {
|
|
150
|
+
return
|
|
151
|
+
}
|
|
152
|
+
let cancelled = false
|
|
153
|
+
const targetIndex = normalizedActiveOptionIndex >= 0 ? normalizedActiveOptionIndex : 0
|
|
154
|
+
|
|
155
|
+
const focusWhenReady = (attempt = 0) => {
|
|
156
|
+
if (cancelled) {
|
|
157
|
+
return
|
|
158
|
+
}
|
|
159
|
+
|
|
160
|
+
const option = optionsContainerRef.current?.querySelector<HTMLButtonElement>(
|
|
161
|
+
`.interaction-panel__option[data-option-index="${targetIndex}"]`
|
|
162
|
+
)
|
|
163
|
+
|
|
164
|
+
if (option != null) {
|
|
165
|
+
option.focus()
|
|
166
|
+
return
|
|
167
|
+
}
|
|
168
|
+
|
|
169
|
+
if (attempt >= 5) {
|
|
170
|
+
return
|
|
171
|
+
}
|
|
172
|
+
|
|
173
|
+
window.setTimeout(() => {
|
|
174
|
+
focusWhenReady(attempt + 1)
|
|
175
|
+
}, 40)
|
|
176
|
+
}
|
|
177
|
+
|
|
178
|
+
focusWhenReady()
|
|
179
|
+
|
|
180
|
+
return () => {
|
|
181
|
+
cancelled = true
|
|
182
|
+
}
|
|
183
|
+
}, [
|
|
184
|
+
interactionRequest.id,
|
|
185
|
+
isPermissionInteraction,
|
|
186
|
+
normalizedActiveOptionIndex,
|
|
187
|
+
options.length,
|
|
188
|
+
showAllPermissionOptions
|
|
189
|
+
])
|
|
190
|
+
|
|
191
|
+
const handleSubmitOption = (option: { label: string; value?: string }) => {
|
|
192
|
+
onInteractionResponse?.(interactionRequest.id, option.value ?? option.label)
|
|
193
|
+
}
|
|
194
|
+
|
|
195
|
+
const moveOptionFocus = (delta: number, focus = isPermissionInteraction) => {
|
|
196
|
+
if (options.length === 0) {
|
|
197
|
+
return
|
|
198
|
+
}
|
|
199
|
+
|
|
200
|
+
const sourceIndex = normalizedActiveOptionIndex >= 0 ? normalizedActiveOptionIndex : 0
|
|
201
|
+
const nextIndex = getLoopedIndex(sourceIndex, delta, options.length)
|
|
202
|
+
onMoveActiveOption(delta)
|
|
203
|
+
if (focus) {
|
|
204
|
+
focusOptionAtIndex(nextIndex)
|
|
205
|
+
}
|
|
206
|
+
}
|
|
207
|
+
|
|
208
|
+
const handleNavButtonKeyDown = (
|
|
209
|
+
event: ReactKeyboardEvent<HTMLElement>,
|
|
210
|
+
delta: number
|
|
211
|
+
) => {
|
|
212
|
+
if ((event.key === 'ArrowUp' && delta < 0) || (event.key === 'ArrowDown' && delta > 0)) {
|
|
213
|
+
event.preventDefault()
|
|
214
|
+
moveOptionFocus(delta)
|
|
215
|
+
}
|
|
216
|
+
}
|
|
217
|
+
|
|
218
|
+
const handleOptionKeyDown = (
|
|
219
|
+
event: ReactKeyboardEvent<HTMLElement>,
|
|
220
|
+
optionIndex: number
|
|
221
|
+
) => {
|
|
222
|
+
if (event.key === 'ArrowDown') {
|
|
223
|
+
event.preventDefault()
|
|
224
|
+
onActiveOptionIndexChange(getLoopedIndex(optionIndex, 1, options.length))
|
|
225
|
+
focusOptionAtIndex(getLoopedIndex(optionIndex, 1, options.length))
|
|
226
|
+
return
|
|
227
|
+
}
|
|
228
|
+
|
|
229
|
+
if (event.key === 'ArrowUp') {
|
|
230
|
+
event.preventDefault()
|
|
231
|
+
onActiveOptionIndexChange(getLoopedIndex(optionIndex, -1, options.length))
|
|
232
|
+
focusOptionAtIndex(getLoopedIndex(optionIndex, -1, options.length))
|
|
233
|
+
}
|
|
234
|
+
}
|
|
235
|
+
|
|
236
|
+
const handleTogglePermissionOptions = () => {
|
|
237
|
+
setShowAllPermissionOptions((current) => {
|
|
238
|
+
const next = !current
|
|
239
|
+
|
|
240
|
+
if (!next && activePermissionOptionIsSecondary) {
|
|
241
|
+
const fallbackIndex = primaryPermissionOptionItems.at(-1)?.index ?? 0
|
|
242
|
+
onActiveOptionIndexChange(fallbackIndex)
|
|
243
|
+
}
|
|
244
|
+
|
|
245
|
+
return next
|
|
246
|
+
})
|
|
247
|
+
}
|
|
248
|
+
|
|
249
|
+
const showOptionControls = options.length > 1
|
|
250
|
+
|
|
64
251
|
return (
|
|
65
|
-
<
|
|
66
|
-
|
|
67
|
-
|
|
68
|
-
|
|
252
|
+
<ChatComposerCard
|
|
253
|
+
className={[
|
|
254
|
+
'interaction-panel',
|
|
255
|
+
isPermissionInteraction ? 'interaction-panel--permission' : 'interaction-panel--question'
|
|
256
|
+
].filter(Boolean).join(' ')}
|
|
257
|
+
summaryClassName='interaction-panel__summary'
|
|
258
|
+
bodyClassName='interaction-panel__body'
|
|
259
|
+
narrow
|
|
260
|
+
summary={
|
|
261
|
+
<div className='interaction-panel__header'>
|
|
262
|
+
<div className='interaction-panel__title-wrap'>
|
|
263
|
+
{!isPermissionInteraction && (
|
|
264
|
+
<span className='material-symbols-rounded interaction-panel__title-icon'>
|
|
265
|
+
help
|
|
266
|
+
</span>
|
|
267
|
+
)}
|
|
268
|
+
<div className='interaction-question'>{title}</div>
|
|
269
|
+
</div>
|
|
270
|
+
{showOptionControls && (
|
|
271
|
+
<div className='interaction-panel__nav' aria-label={t('chat.interactionOptionNavigation')}>
|
|
272
|
+
<Tooltip title={t('chat.interactionOptionPrevious')} placement='top' destroyOnHidden>
|
|
273
|
+
<button
|
|
274
|
+
type='button'
|
|
275
|
+
className='interaction-panel__nav-button'
|
|
276
|
+
aria-label={t('chat.interactionOptionPrevious')}
|
|
277
|
+
onMouseDown={(event) => {
|
|
278
|
+
event.preventDefault()
|
|
279
|
+
}}
|
|
280
|
+
onKeyDown={(event) => handleNavButtonKeyDown(event, -1)}
|
|
281
|
+
onClick={() => moveOptionFocus(-1)}
|
|
282
|
+
>
|
|
283
|
+
<span className='material-symbols-rounded'>keyboard_arrow_up</span>
|
|
284
|
+
</button>
|
|
285
|
+
</Tooltip>
|
|
286
|
+
<Tooltip title={t('chat.interactionOptionNext')} placement='top' destroyOnHidden>
|
|
287
|
+
<button
|
|
288
|
+
type='button'
|
|
289
|
+
className='interaction-panel__nav-button'
|
|
290
|
+
aria-label={t('chat.interactionOptionNext')}
|
|
291
|
+
onMouseDown={(event) => {
|
|
292
|
+
event.preventDefault()
|
|
293
|
+
}}
|
|
294
|
+
onKeyDown={(event) => handleNavButtonKeyDown(event, 1)}
|
|
295
|
+
onClick={() => moveOptionFocus(1)}
|
|
296
|
+
>
|
|
297
|
+
<span className='material-symbols-rounded'>keyboard_arrow_down</span>
|
|
298
|
+
</button>
|
|
299
|
+
</Tooltip>
|
|
300
|
+
</div>
|
|
301
|
+
)}
|
|
69
302
|
</div>
|
|
70
|
-
|
|
71
|
-
|
|
72
|
-
|
|
73
|
-
|
|
303
|
+
}
|
|
304
|
+
>
|
|
305
|
+
<div ref={optionsContainerRef} className='interaction-panel__options'>
|
|
306
|
+
{visibleOptionItems.map(({ option, index, meta }) => {
|
|
307
|
+
const optionKey = getInteractionOptionKey(option, index)
|
|
308
|
+
const isActive = index === normalizedActiveOptionIndex
|
|
309
|
+
|
|
310
|
+
if (isPermissionInteraction) {
|
|
311
|
+
return (
|
|
312
|
+
<Button
|
|
313
|
+
key={optionKey}
|
|
314
|
+
block
|
|
315
|
+
data-option-index={index}
|
|
316
|
+
tabIndex={isActive ? 0 : -1}
|
|
317
|
+
className={[
|
|
318
|
+
'interaction-panel__option',
|
|
319
|
+
`interaction-panel__option--${meta.tone}`,
|
|
320
|
+
isActive ? 'is-active' : ''
|
|
321
|
+
].filter(Boolean).join(' ')}
|
|
322
|
+
onFocus={() => onActiveOptionIndexChange(index)}
|
|
323
|
+
onKeyDown={(event) => handleOptionKeyDown(event, index)}
|
|
324
|
+
onClick={() => handleSubmitOption(option)}
|
|
325
|
+
>
|
|
326
|
+
<span className='interaction-panel__option-icon material-symbols-rounded'>{meta.icon}</span>
|
|
327
|
+
<span className='interaction-panel__option-copy'>
|
|
328
|
+
<span className='interaction-panel__option-text'>
|
|
329
|
+
<span className='interaction-panel__option-label'>{option.label}</span>
|
|
330
|
+
{option.description && (
|
|
331
|
+
<span className='interaction-panel__option-description'>
|
|
332
|
+
{option.description}
|
|
333
|
+
</span>
|
|
334
|
+
)}
|
|
335
|
+
</span>
|
|
336
|
+
</span>
|
|
337
|
+
</Button>
|
|
338
|
+
)
|
|
339
|
+
}
|
|
74
340
|
|
|
75
341
|
return (
|
|
76
342
|
<Button
|
|
77
|
-
key={
|
|
78
|
-
|
|
79
|
-
|
|
80
|
-
|
|
81
|
-
|
|
82
|
-
|
|
343
|
+
key={optionKey}
|
|
344
|
+
block
|
|
345
|
+
data-option-index={index}
|
|
346
|
+
tabIndex={isActive ? 0 : -1}
|
|
347
|
+
className={`interaction-panel__option interaction-panel__option--question ${isActive ? 'is-active' : ''}`
|
|
348
|
+
.trim()}
|
|
349
|
+
onFocus={() => onActiveOptionIndexChange(index)}
|
|
350
|
+
onKeyDown={(event) => handleOptionKeyDown(event, index)}
|
|
351
|
+
onClick={() => handleSubmitOption(option)}
|
|
83
352
|
>
|
|
84
|
-
<span className='interaction-panel__option-
|
|
85
|
-
|
|
86
|
-
|
|
87
|
-
|
|
88
|
-
|
|
89
|
-
|
|
90
|
-
|
|
91
|
-
|
|
92
|
-
|
|
93
|
-
|
|
94
|
-
</
|
|
353
|
+
<span className='interaction-panel__option-main'>
|
|
354
|
+
<span className='interaction-panel__option-index' aria-hidden='true'>
|
|
355
|
+
{index + 1}.
|
|
356
|
+
</span>
|
|
357
|
+
<span className='interaction-panel__option-label'>{option.label}</span>
|
|
358
|
+
{option.description && (
|
|
359
|
+
<span className='interaction-panel__option-side'>
|
|
360
|
+
{renderInfoButton(option.description)}
|
|
361
|
+
</span>
|
|
362
|
+
)}
|
|
363
|
+
</span>
|
|
95
364
|
</Button>
|
|
96
365
|
)
|
|
97
366
|
})}
|
|
98
|
-
{
|
|
99
|
-
<div className='interaction-panel__secondary'>
|
|
100
|
-
{secondaryOptions.map((option: { label: string; value?: string; description?: string }) => {
|
|
101
|
-
const meta = getOptionMeta(option.value)
|
|
102
|
-
|
|
103
|
-
return (
|
|
104
|
-
<Button
|
|
105
|
-
key={option.value ?? option.label}
|
|
106
|
-
className={[
|
|
107
|
-
'interaction-panel__option',
|
|
108
|
-
`interaction-panel__option--${meta.tone}`
|
|
109
|
-
].join(' ')}
|
|
110
|
-
onClick={() => onInteractionResponse?.(interactionRequest.id, option.value ?? option.label)}
|
|
111
|
-
>
|
|
112
|
-
<span className='interaction-panel__option-icon material-symbols-rounded'>{meta.icon}</span>
|
|
113
|
-
<div className='interaction-panel__option-copy'>
|
|
114
|
-
<div className='interaction-panel__option-text'>
|
|
115
|
-
<div className='interaction-panel__option-label'>{option.label}</div>
|
|
116
|
-
{option.description && (
|
|
117
|
-
<div className='interaction-panel__option-description'>
|
|
118
|
-
{option.description}
|
|
119
|
-
</div>
|
|
120
|
-
)}
|
|
121
|
-
</div>
|
|
122
|
-
</div>
|
|
123
|
-
</Button>
|
|
124
|
-
)
|
|
125
|
-
})}
|
|
126
|
-
</div>
|
|
127
|
-
)}
|
|
128
|
-
{secondaryOptions.length > 0 && (
|
|
367
|
+
{isPermissionInteraction && secondaryPermissionOptionItems.length > 0 && (
|
|
129
368
|
<Button
|
|
130
369
|
type='text'
|
|
131
370
|
className='interaction-panel__toggle'
|
|
132
|
-
onClick={
|
|
371
|
+
onClick={handleTogglePermissionOptions}
|
|
133
372
|
>
|
|
134
373
|
<span className='interaction-panel__toggle-label'>
|
|
135
|
-
{
|
|
374
|
+
{showAllPermissionOptions ? t('chat.permissionCollapseOptions') : t('chat.permissionExpandOptions')}
|
|
136
375
|
</span>
|
|
137
376
|
<span className='interaction-panel__toggle-icon material-symbols-rounded'>
|
|
138
|
-
{
|
|
377
|
+
{showAllPermissionOptions ? 'expand_less' : 'expand_more'}
|
|
139
378
|
</span>
|
|
140
379
|
</Button>
|
|
141
380
|
)}
|
|
142
381
|
</div>
|
|
143
|
-
</
|
|
382
|
+
</ChatComposerCard>
|
|
144
383
|
)
|
|
145
384
|
}
|
|
@@ -18,7 +18,10 @@ export function SenderMonacoEditor({
|
|
|
18
18
|
placeholder,
|
|
19
19
|
disabled,
|
|
20
20
|
sendShortcut,
|
|
21
|
+
sendShortcutDisabled,
|
|
21
22
|
onSendShortcut,
|
|
23
|
+
secondarySendShortcut,
|
|
24
|
+
onSecondarySendShortcut,
|
|
22
25
|
onInputChange,
|
|
23
26
|
onCursorChange,
|
|
24
27
|
onKeyDown,
|
|
@@ -32,7 +35,10 @@ export function SenderMonacoEditor({
|
|
|
32
35
|
placeholder: string
|
|
33
36
|
disabled: boolean
|
|
34
37
|
sendShortcut: string
|
|
38
|
+
sendShortcutDisabled?: boolean
|
|
35
39
|
onSendShortcut: () => void
|
|
40
|
+
secondarySendShortcut?: string
|
|
41
|
+
onSecondarySendShortcut?: () => void
|
|
36
42
|
onInputChange: (value: string, cursorOffset: number | null) => void
|
|
37
43
|
onCursorChange: (cursorOffset: number | null) => void
|
|
38
44
|
onKeyDown: (event: KeyboardEvent) => void
|
|
@@ -56,7 +62,10 @@ export function SenderMonacoEditor({
|
|
|
56
62
|
value,
|
|
57
63
|
disabled,
|
|
58
64
|
sendShortcut,
|
|
65
|
+
sendShortcutDisabled,
|
|
59
66
|
onSendShortcut,
|
|
67
|
+
secondarySendShortcut,
|
|
68
|
+
onSecondarySendShortcut,
|
|
60
69
|
onInputChange,
|
|
61
70
|
onCursorChange,
|
|
62
71
|
onKeyDown,
|
|
@@ -79,17 +88,25 @@ export function SenderMonacoEditor({
|
|
|
79
88
|
options={{
|
|
80
89
|
ariaLabel: placeholder,
|
|
81
90
|
automaticLayout: true,
|
|
91
|
+
bracketPairColorization: { enabled: false },
|
|
82
92
|
domReadOnly: disabled,
|
|
83
93
|
folding: false,
|
|
84
94
|
fontFamily: 'ui-monospace, SFMono-Regular, Menlo, Monaco, Consolas, monospace',
|
|
85
95
|
fontSize: FONT_SIZE,
|
|
86
96
|
glyphMargin: false,
|
|
97
|
+
guides: {
|
|
98
|
+
bracketPairs: false,
|
|
99
|
+
highlightActiveBracketPair: false,
|
|
100
|
+
indentation: false
|
|
101
|
+
},
|
|
87
102
|
hideCursorInOverviewRuler: true,
|
|
88
103
|
lineDecorationsWidth: 0,
|
|
89
104
|
lineHeight: LINE_HEIGHT,
|
|
90
105
|
lineNumbers: 'off',
|
|
91
106
|
lineNumbersMinChars: 0,
|
|
107
|
+
matchBrackets: 'never',
|
|
92
108
|
minimap: { enabled: false },
|
|
109
|
+
occurrencesHighlight: 'off',
|
|
93
110
|
overviewRulerBorder: false,
|
|
94
111
|
overviewRulerLanes: 0,
|
|
95
112
|
padding: { top: 0, bottom: 0 },
|
|
@@ -99,6 +116,7 @@ export function SenderMonacoEditor({
|
|
|
99
116
|
renderLineHighlight: 'none',
|
|
100
117
|
roundedSelection: true,
|
|
101
118
|
scrollBeyondLastLine: false,
|
|
119
|
+
selectionHighlight: false,
|
|
102
120
|
scrollbar: {
|
|
103
121
|
alwaysConsumeMouseWheel: false,
|
|
104
122
|
horizontal: 'hidden',
|
package/src/components/chat/sender/@components/sender-monaco-editor/use-sender-monaco-editor.ts
CHANGED
|
@@ -1,5 +1,4 @@
|
|
|
1
1
|
/* eslint-disable max-lines */
|
|
2
|
-
|
|
3
2
|
import type { SenderEditorHandle } from '#~/components/chat/sender/@types/sender-editor'
|
|
4
3
|
import type { SenderCompletionMatch, SenderTokenDecoration } from '#~/components/chat/sender/@utils/sender-completion'
|
|
5
4
|
import { isShortcutMatch } from '#~/utils/shortcutUtils'
|
|
@@ -17,13 +16,21 @@ import {
|
|
|
17
16
|
import { useSenderEditorHandle } from './use-sender-editor-handle'
|
|
18
17
|
import { useSenderMonacoTheme } from './use-sender-monaco-theme'
|
|
19
18
|
|
|
19
|
+
const hasPastedImageFile = (clipboardData?: DataTransfer | null) => {
|
|
20
|
+
return Array.from(clipboardData?.items ?? [])
|
|
21
|
+
.some(item => item.kind === 'file' && item.type.startsWith('image/'))
|
|
22
|
+
}
|
|
23
|
+
|
|
20
24
|
export const useSenderMonacoEditor = ({
|
|
21
25
|
editorRef,
|
|
22
26
|
modelPath,
|
|
23
27
|
value,
|
|
24
28
|
disabled,
|
|
25
29
|
sendShortcut,
|
|
30
|
+
sendShortcutDisabled,
|
|
26
31
|
onSendShortcut,
|
|
32
|
+
secondarySendShortcut,
|
|
33
|
+
onSecondarySendShortcut,
|
|
27
34
|
onInputChange,
|
|
28
35
|
onCursorChange,
|
|
29
36
|
onKeyDown,
|
|
@@ -37,7 +44,10 @@ export const useSenderMonacoEditor = ({
|
|
|
37
44
|
value: string
|
|
38
45
|
disabled: boolean
|
|
39
46
|
sendShortcut: string
|
|
47
|
+
sendShortcutDisabled?: boolean
|
|
40
48
|
onSendShortcut: () => void
|
|
49
|
+
secondarySendShortcut?: string
|
|
50
|
+
onSecondarySendShortcut?: () => void
|
|
41
51
|
onInputChange: (value: string, cursorOffset: number | null) => void
|
|
42
52
|
onCursorChange: (cursorOffset: number | null) => void
|
|
43
53
|
onKeyDown: (event: KeyboardEvent) => void
|
|
@@ -56,7 +66,10 @@ export const useSenderMonacoEditor = ({
|
|
|
56
66
|
const decorationsRef = useRef<MonacoEditorNamespace.IEditorDecorationsCollection | null>(null)
|
|
57
67
|
const disabledRef = useRef(disabled)
|
|
58
68
|
const sendShortcutRef = useRef(sendShortcut)
|
|
69
|
+
const sendShortcutDisabledRef = useRef(Boolean(sendShortcutDisabled))
|
|
59
70
|
const onSendShortcutRef = useRef(onSendShortcut)
|
|
71
|
+
const secondarySendShortcutRef = useRef(secondarySendShortcut)
|
|
72
|
+
const onSecondarySendShortcutRef = useRef(onSecondarySendShortcut)
|
|
60
73
|
const onInputChangeRef = useRef(onInputChange)
|
|
61
74
|
const onCursorChangeRef = useRef(onCursorChange)
|
|
62
75
|
const onKeyDownRef = useRef(onKeyDown)
|
|
@@ -67,7 +80,10 @@ export const useSenderMonacoEditor = ({
|
|
|
67
80
|
|
|
68
81
|
disabledRef.current = disabled
|
|
69
82
|
sendShortcutRef.current = sendShortcut
|
|
83
|
+
sendShortcutDisabledRef.current = Boolean(sendShortcutDisabled)
|
|
70
84
|
onSendShortcutRef.current = onSendShortcut
|
|
85
|
+
secondarySendShortcutRef.current = secondarySendShortcut
|
|
86
|
+
onSecondarySendShortcutRef.current = onSecondarySendShortcut
|
|
71
87
|
onInputChangeRef.current = onInputChange
|
|
72
88
|
onCursorChangeRef.current = onCursorChange
|
|
73
89
|
onKeyDownRef.current = onKeyDown
|
|
@@ -141,30 +157,91 @@ export const useSenderMonacoEditor = ({
|
|
|
141
157
|
const domNode = editor.getDomNode()
|
|
142
158
|
|
|
143
159
|
if (domNode != null) {
|
|
144
|
-
const
|
|
145
|
-
|
|
160
|
+
const inputTargets = Array.from(
|
|
161
|
+
domNode.querySelectorAll<HTMLElement>('.native-edit-context, textarea.inputarea')
|
|
162
|
+
)
|
|
163
|
+
const shouldHandleImagePaste = (event: ClipboardEvent, requireFocus: boolean) => {
|
|
164
|
+
if (!hasPastedImageFile(event.clipboardData)) {
|
|
165
|
+
return false
|
|
166
|
+
}
|
|
167
|
+
|
|
168
|
+
if (!requireFocus) {
|
|
169
|
+
return true
|
|
170
|
+
}
|
|
171
|
+
|
|
172
|
+
const activeElement = document.activeElement
|
|
173
|
+
|
|
174
|
+
return editor.hasTextFocus() ||
|
|
175
|
+
(activeElement != null && domNode.contains(activeElement)) ||
|
|
176
|
+
(event.target instanceof Node && domNode.contains(event.target))
|
|
177
|
+
}
|
|
178
|
+
const handleImagePaste = (
|
|
179
|
+
event: ClipboardEvent,
|
|
180
|
+
{ requireFocus, stopImmediately }: { requireFocus: boolean; stopImmediately: boolean }
|
|
181
|
+
) => {
|
|
182
|
+
if (!shouldHandleImagePaste(event, requireFocus)) {
|
|
146
183
|
return
|
|
147
184
|
}
|
|
185
|
+
|
|
186
|
+
event.preventDefault()
|
|
187
|
+
event.stopPropagation()
|
|
188
|
+
|
|
189
|
+
if (stopImmediately) {
|
|
190
|
+
event.stopImmediatePropagation()
|
|
191
|
+
}
|
|
192
|
+
|
|
148
193
|
void onPasteRef.current(event)
|
|
149
194
|
}
|
|
150
|
-
const
|
|
195
|
+
const handleDocumentPaste = (event: ClipboardEvent) => {
|
|
196
|
+
if (!shouldHandleImagePaste(event, true)) {
|
|
197
|
+
return
|
|
198
|
+
}
|
|
199
|
+
|
|
200
|
+
handleImagePaste(event, { requireFocus: true, stopImmediately: true })
|
|
201
|
+
}
|
|
202
|
+
const handleNativePaste: EventListener = (event) => {
|
|
203
|
+
if (!(event instanceof ClipboardEvent)) {
|
|
204
|
+
return
|
|
205
|
+
}
|
|
206
|
+
|
|
207
|
+
handleImagePaste(event, { requireFocus: false, stopImmediately: true })
|
|
208
|
+
}
|
|
151
209
|
const handleNativeKeyDown: EventListener = (event) => {
|
|
152
210
|
if (!(event instanceof KeyboardEvent)) {
|
|
153
211
|
return
|
|
154
212
|
}
|
|
155
|
-
if (
|
|
213
|
+
if (
|
|
214
|
+
secondarySendShortcutRef.current != null &&
|
|
215
|
+
onSecondarySendShortcutRef.current != null &&
|
|
216
|
+
isShortcutMatch(event, secondarySendShortcutRef.current, navigator.platform.includes('Mac'))
|
|
217
|
+
) {
|
|
218
|
+
event.preventDefault()
|
|
219
|
+
event.stopPropagation()
|
|
220
|
+
onSecondarySendShortcutRef.current()
|
|
221
|
+
return
|
|
222
|
+
}
|
|
223
|
+
if (
|
|
224
|
+
!sendShortcutDisabledRef.current &&
|
|
225
|
+
isShortcutMatch(event, sendShortcutRef.current, navigator.platform.includes('Mac'))
|
|
226
|
+
) {
|
|
156
227
|
event.preventDefault()
|
|
157
228
|
event.stopPropagation()
|
|
158
229
|
onSendShortcutRef.current()
|
|
159
230
|
}
|
|
160
231
|
}
|
|
161
232
|
|
|
162
|
-
|
|
163
|
-
|
|
233
|
+
document.addEventListener('paste', handleDocumentPaste, true)
|
|
234
|
+
for (const inputTarget of inputTargets) {
|
|
235
|
+
inputTarget.addEventListener('paste', handleNativePaste, true)
|
|
236
|
+
inputTarget.addEventListener('keydown', handleNativeKeyDown, true)
|
|
237
|
+
}
|
|
164
238
|
disposables.push({
|
|
165
239
|
dispose: () => {
|
|
166
|
-
|
|
167
|
-
|
|
240
|
+
document.removeEventListener('paste', handleDocumentPaste, true)
|
|
241
|
+
for (const inputTarget of inputTargets) {
|
|
242
|
+
inputTarget.removeEventListener('paste', handleNativePaste, true)
|
|
243
|
+
inputTarget.removeEventListener('keydown', handleNativeKeyDown, true)
|
|
244
|
+
}
|
|
168
245
|
}
|
|
169
246
|
})
|
|
170
247
|
}
|