1- import { memo , lazy , Suspense , useMemo , useState } from "react" ;
1+ import { memo , lazy , Suspense , useMemo , useState , useEffect , useRef } from "react" ;
22import { message , Tooltip , Popover } from "antd" ;
33import classNames from "classnames" ;
44import IconFont from "../../iconfonts" ;
@@ -7,8 +7,6 @@ import { useFlowStore } from "../../../stores/flow";
77import { useConfigStore } from "../../../stores/configStore" ;
88import { useClipboardStore } from "../../../stores/clipboardStore" ;
99import { useDebugSessionStore } from "../../../stores/debugSessionStore" ;
10- import { useWikiStore } from "../../../stores/wikiStore" ;
11- import { isWikiModuleVisible } from "../../../wiki/visibility" ;
1210import PathSelector from "./PathSelector" ;
1311import style from "../../../styles/panels/ToolPanel.module.less" ;
1412
@@ -25,7 +23,59 @@ type GlobalToolType = {
2523 onDisabledClick ?: ( ) => void ;
2624} ;
2725
26+ const DOCS_URL = "https://mpe.codax.site/docs" ;
27+ const HOLD_DURATION_MS = 600 ;
28+
29+ function isEditableTarget ( target : EventTarget | null ) {
30+ if ( ! ( target instanceof HTMLElement ) ) return false ;
31+ const tagName = target . tagName . toLowerCase ( ) ;
32+ if ( tagName === "input" || tagName === "textarea" || tagName === "select" ) return true ;
33+ if ( target . isContentEditable ) return true ;
34+ if ( target . closest ( '[contenteditable="true"]' ) ) return true ;
35+ return Boolean ( target . closest ( ".monaco-editor" ) ) ;
36+ }
37+
38+ function useDocsHoldHotkey ( ) {
39+ const timerRef = useRef < number | undefined > ( undefined ) ;
40+ const holdingRef = useRef ( false ) ;
41+
42+ useEffect ( ( ) => {
43+ const handleKeyDown = ( event : KeyboardEvent ) => {
44+ if ( event . key . toLowerCase ( ) !== "w" ) return ;
45+ if ( event . repeat || holdingRef . current ) return ;
46+ if ( event . ctrlKey || event . altKey || event . metaKey ) return ;
47+ if ( event . isComposing || isEditableTarget ( event . target ) ) return ;
48+
49+ holdingRef . current = true ;
50+ timerRef . current = window . setTimeout ( ( ) => {
51+ holdingRef . current = false ;
52+ window . open ( DOCS_URL , "_blank" ) ;
53+ } , HOLD_DURATION_MS ) ;
54+ } ;
55+
56+ const handleKeyUp = ( event : KeyboardEvent ) => {
57+ if ( event . key . toLowerCase ( ) === "w" ) {
58+ if ( timerRef . current !== undefined ) {
59+ window . clearTimeout ( timerRef . current ) ;
60+ timerRef . current = undefined ;
61+ }
62+ holdingRef . current = false ;
63+ }
64+ } ;
65+
66+ document . addEventListener ( "keydown" , handleKeyDown ) ;
67+ document . addEventListener ( "keyup" , handleKeyUp ) ;
68+ return ( ) => {
69+ document . removeEventListener ( "keydown" , handleKeyDown ) ;
70+ document . removeEventListener ( "keyup" , handleKeyUp ) ;
71+ if ( timerRef . current !== undefined ) window . clearTimeout ( timerRef . current ) ;
72+ } ;
73+ } , [ ] ) ;
74+ }
75+
2876function GlobalPanel ( ) {
77+ useDocsHoldHotkey ( ) ;
78+
2979 // store
3080 const clipboardNodes = useClipboardStore ( ( state ) => state . clipboardNodes ) ;
3181 const debouncedSelectedNodes = useFlowStore (
@@ -42,7 +92,6 @@ function GlobalPanel() {
4292 const getHistoryState = useFlowStore ( ( state ) => state . getHistoryState ) ;
4393 const pathMode = useFlowStore ( ( state ) => state . pathMode ) ;
4494 const openDebugModal = useDebugSessionStore ( ( state ) => state . openModal ) ;
45- const openWiki = useWikiStore ( ( state ) => state . openWiki ) ;
4695
4796 // 历史状态
4897 const [ , forceUpdate ] = useState ( { } ) ;
@@ -267,23 +316,21 @@ function GlobalPanel() {
267316 </ Tooltip >
268317 </ li >
269318 </ div >
270- { isWikiModuleVisible && (
271- < div className = { style . group } >
319+ < div className = { style . group } >
272320 < div className = { style . devider } >
273321 < div > </ div >
274322 </ div >
275323 < li className = { style . item } >
276- < Tooltip placement = "bottom" title = "MPE Wiki / 俺寻思 " >
324+ < Tooltip placement = "bottom" title = "文档站 " >
277325 < IconFont
278326 className = { style . icon }
279327 name = "icon-icon_wendangziliaopeizhi"
280328 size = { 24 }
281- onClick = { ( ) => openWiki ( ) }
329+ onClick = { ( ) => window . open ( "https://mpe.codax.site/docs" , "_blank" ) }
282330 />
283331 </ Tooltip >
284332 </ li >
285333 </ div >
286- ) }
287334 </ ul >
288335 < ul className = { editPanelClass } > { renderTools ( editingTools ) } </ ul >
289336 </ >
0 commit comments