dsh-mega-chat-nav 0.1.1

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.
Files changed (192) hide show
  1. package/LICENSE +201 -0
  2. package/README.en.md +149 -0
  3. package/README.md +149 -0
  4. package/cordis.patch.yml +4 -0
  5. package/lib/client/NavOverlay.js +35 -0
  6. package/lib/client/NavRail.js +12 -0
  7. package/lib/client/QuestionNavSettingsTab.js +26 -0
  8. package/lib/client/QuestionNavStrip.js +555 -0
  9. package/lib/client/components/ConfigPanel.js +14 -0
  10. package/lib/client/components/DotRail.js +62 -0
  11. package/lib/client/components/NavOverlay.js +121 -0
  12. package/lib/client/components/NavRail.js +97 -0
  13. package/lib/client/components/RailDispatch.js +22 -0
  14. package/lib/client/components/RailHost.js +79 -0
  15. package/lib/client/components/SearchBox.js +66 -0
  16. package/lib/client/components/SettingsPage.js +46 -0
  17. package/lib/client/components/StandaloneSettings.js +16 -0
  18. package/lib/client/components/codex/CodexRail.js +139 -0
  19. package/lib/client/components/deepseek/DeepseekRail.js +264 -0
  20. package/lib/client/components/minimal/MinimalRail.js +135 -0
  21. package/lib/client/components/minimal/cards.js +32 -0
  22. package/lib/client/components/minimal/dot.js +11 -0
  23. package/lib/client/components/minimal/hint.js +30 -0
  24. package/lib/client/components/minimal/paging.js +5 -0
  25. package/lib/client/components/minimal/quick-settings.js +28 -0
  26. package/lib/client/components/minimal/search.js +67 -0
  27. package/lib/client/components/minimal/useRail.js +716 -0
  28. package/lib/client/components/rail/cards.js +32 -0
  29. package/lib/client/components/rail/hint.js +30 -0
  30. package/lib/client/components/rail/paging.js +5 -0
  31. package/lib/client/components/rail/quick-settings.js +28 -0
  32. package/lib/client/components/rail/search.js +76 -0
  33. package/lib/client/components/rail/useRail.js +845 -0
  34. package/lib/client/components/settings/SettingsPage.js +46 -0
  35. package/lib/client/components/settings/SettingsTab.js +17 -0
  36. package/lib/client/components/settings/StandaloneSettings.js +16 -0
  37. package/lib/client/components/shared/Cascade.js +26 -0
  38. package/lib/client/components/shared/ConfigPanel.js +27 -0
  39. package/lib/client/components/shared/Dot.js +8 -0
  40. package/lib/client/components/shared/Hint.js +5 -0
  41. package/lib/client/components/shared/PagingButton.js +5 -0
  42. package/lib/client/components/shared/RailShell.js +78 -0
  43. package/lib/client/components/shared/SearchBox.js +63 -0
  44. package/lib/client/components/shared/hooks.js +427 -0
  45. package/lib/client/components/shared/types.js +1 -0
  46. package/lib/client/config.js +1 -0
  47. package/lib/client/engines/jump.js +34 -0
  48. package/lib/client/engines/useAtBottom.js +25 -0
  49. package/lib/client/engines/useJump.js +40 -0
  50. package/lib/client/engines/useScrollSpy.js +88 -0
  51. package/lib/client/hooks.js +11 -0
  52. package/lib/client/index.js +312 -0
  53. package/lib/client/jump.js +255 -0
  54. package/lib/client/locales.js +142 -0
  55. package/lib/client/pure.js +61 -0
  56. package/lib/client/settings.js +369 -0
  57. package/lib/client/virtual/VirtualList.js +21 -0
  58. package/lib/client.js +3213 -0
  59. package/lib/compat.js +145 -0
  60. package/lib/config.js +37 -0
  61. package/lib/core/active-dot.js +17 -0
  62. package/lib/core/align.js +9 -0
  63. package/lib/core/config.js +37 -0
  64. package/lib/core/focus.js +38 -0
  65. package/lib/core/jump.js +98 -0
  66. package/lib/core/logic/active-dot.js +16 -0
  67. package/lib/core/logic/focus.js +34 -0
  68. package/lib/core/logic/jump.js +188 -0
  69. package/lib/core/logic/nodes.js +59 -0
  70. package/lib/core/model/nav-item.js +1 -0
  71. package/lib/core/model/turns.js +73 -0
  72. package/lib/core/nav-item.js +1 -0
  73. package/lib/core/nodes.js +57 -0
  74. package/lib/core/page-size.js +7 -0
  75. package/lib/core/question-entry.js +1 -0
  76. package/lib/core/time.js +23 -0
  77. package/lib/core/turn-dots.js +85 -0
  78. package/lib/core/utils/measure.js +24 -0
  79. package/lib/core/utils/time.js +26 -0
  80. package/lib/index.js +64 -0
  81. package/lib/nav-item.js +1 -0
  82. package/lib/nodes.js +59 -0
  83. package/lib/projection.js +126 -0
  84. package/lib/schema.js +26 -0
  85. package/lib/search.js +285 -0
  86. package/lib/settings.js +89 -0
  87. package/lib/types/client/NavOverlay.d.ts +18 -0
  88. package/lib/types/client/NavRail.d.ts +7 -0
  89. package/lib/types/client/QuestionNavSettingsTab.d.ts +16 -0
  90. package/lib/types/client/QuestionNavStrip.d.ts +48 -0
  91. package/lib/types/client/components/ConfigPanel.d.ts +14 -0
  92. package/lib/types/client/components/DotRail.d.ts +15 -0
  93. package/lib/types/client/components/NavOverlay.d.ts +30 -0
  94. package/lib/types/client/components/NavRail.d.ts +16 -0
  95. package/lib/types/client/components/RailDispatch.d.ts +8 -0
  96. package/lib/types/client/components/RailHost.d.ts +27 -0
  97. package/lib/types/client/components/SearchBox.d.ts +9 -0
  98. package/lib/types/client/components/SettingsPage.d.ts +9 -0
  99. package/lib/types/client/components/StandaloneSettings.d.ts +13 -0
  100. package/lib/types/client/components/codex/CodexRail.d.ts +3 -0
  101. package/lib/types/client/components/deepseek/DeepseekRail.d.ts +3 -0
  102. package/lib/types/client/components/minimal/MinimalRail.d.ts +8 -0
  103. package/lib/types/client/components/minimal/cards.d.ts +19 -0
  104. package/lib/types/client/components/minimal/dot.d.ts +14 -0
  105. package/lib/types/client/components/minimal/hint.d.ts +11 -0
  106. package/lib/types/client/components/minimal/paging.d.ts +10 -0
  107. package/lib/types/client/components/minimal/quick-settings.d.ts +8 -0
  108. package/lib/types/client/components/minimal/search.d.ts +27 -0
  109. package/lib/types/client/components/minimal/useRail.d.ts +90 -0
  110. package/lib/types/client/components/rail/cards.d.ts +19 -0
  111. package/lib/types/client/components/rail/hint.d.ts +11 -0
  112. package/lib/types/client/components/rail/paging.d.ts +10 -0
  113. package/lib/types/client/components/rail/quick-settings.d.ts +8 -0
  114. package/lib/types/client/components/rail/search.d.ts +34 -0
  115. package/lib/types/client/components/rail/useRail.d.ts +132 -0
  116. package/lib/types/client/components/settings/SettingsPage.d.ts +9 -0
  117. package/lib/types/client/components/settings/SettingsTab.d.ts +6 -0
  118. package/lib/types/client/components/settings/StandaloneSettings.d.ts +13 -0
  119. package/lib/types/client/components/shared/Cascade.d.ts +14 -0
  120. package/lib/types/client/components/shared/ConfigPanel.d.ts +8 -0
  121. package/lib/types/client/components/shared/Dot.d.ts +17 -0
  122. package/lib/types/client/components/shared/Hint.d.ts +6 -0
  123. package/lib/types/client/components/shared/PagingButton.d.ts +10 -0
  124. package/lib/types/client/components/shared/RailShell.d.ts +43 -0
  125. package/lib/types/client/components/shared/SearchBox.d.ts +18 -0
  126. package/lib/types/client/components/shared/hooks.d.ts +64 -0
  127. package/lib/types/client/components/shared/types.d.ts +101 -0
  128. package/lib/types/client/config.d.ts +9 -0
  129. package/lib/types/client/engines/jump.d.ts +17 -0
  130. package/lib/types/client/engines/useAtBottom.d.ts +1 -0
  131. package/lib/types/client/engines/useJump.d.ts +16 -0
  132. package/lib/types/client/engines/useScrollSpy.d.ts +12 -0
  133. package/lib/types/client/hooks.d.ts +7 -0
  134. package/lib/types/client/index.d.ts +31 -0
  135. package/lib/types/client/jump.d.ts +47 -0
  136. package/lib/types/client/locales.d.ts +142 -0
  137. package/lib/types/client/pure.d.ts +21 -0
  138. package/lib/types/client/settings.d.ts +173 -0
  139. package/lib/types/client/virtual/VirtualList.d.ts +15 -0
  140. package/lib/types/compat.d.ts +44 -0
  141. package/lib/types/config.d.ts +44 -0
  142. package/lib/types/core/active-dot.d.ts +15 -0
  143. package/lib/types/core/align.d.ts +10 -0
  144. package/lib/types/core/config.d.ts +44 -0
  145. package/lib/types/core/focus.d.ts +24 -0
  146. package/lib/types/core/jump.d.ts +39 -0
  147. package/lib/types/core/logic/active-dot.d.ts +15 -0
  148. package/lib/types/core/logic/focus.d.ts +22 -0
  149. package/lib/types/core/logic/jump.d.ts +39 -0
  150. package/lib/types/core/logic/nodes.d.ts +48 -0
  151. package/lib/types/core/model/nav-item.d.ts +12 -0
  152. package/lib/types/core/model/turns.d.ts +30 -0
  153. package/lib/types/core/nav-item.d.ts +12 -0
  154. package/lib/types/core/nodes.d.ts +43 -0
  155. package/lib/types/core/page-size.d.ts +8 -0
  156. package/lib/types/core/question-entry.d.ts +12 -0
  157. package/lib/types/core/time.d.ts +4 -0
  158. package/lib/types/core/turn-dots.d.ts +29 -0
  159. package/lib/types/core/utils/measure.d.ts +12 -0
  160. package/lib/types/core/utils/time.d.ts +4 -0
  161. package/lib/types/index.d.ts +4 -0
  162. package/lib/types/nav-item.d.ts +12 -0
  163. package/lib/types/nodes.d.ts +48 -0
  164. package/lib/types/projection.d.ts +71 -0
  165. package/lib/types/schema.d.ts +37 -0
  166. package/lib/types/search.d.ts +42 -0
  167. package/lib/types/settings.d.ts +99 -0
  168. package/package.json +71 -0
  169. package/src/client/components/RailDispatch.tsx +27 -0
  170. package/src/client/components/codex/CodexRail.tsx +348 -0
  171. package/src/client/components/deepseek/DeepseekRail.tsx +522 -0
  172. package/src/client/components/minimal/MinimalRail.tsx +324 -0
  173. package/src/client/components/minimal/dot.tsx +32 -0
  174. package/src/client/components/rail/cards.tsx +102 -0
  175. package/src/client/components/rail/hint.tsx +50 -0
  176. package/src/client/components/rail/paging.tsx +26 -0
  177. package/src/client/components/rail/quick-settings.tsx +130 -0
  178. package/src/client/components/rail/search.tsx +147 -0
  179. package/src/client/components/rail/useRail.ts +906 -0
  180. package/src/client/components/settings/SettingsPage.tsx +198 -0
  181. package/src/client/components/settings/StandaloneSettings.tsx +28 -0
  182. package/src/client/components/shared/types.ts +99 -0
  183. package/src/client/index.ts +388 -0
  184. package/src/client/jump.ts +293 -0
  185. package/src/client/locales.ts +143 -0
  186. package/src/client/settings.ts +482 -0
  187. package/src/client/styles.css +1580 -0
  188. package/src/compat.ts +161 -0
  189. package/src/index.ts +66 -0
  190. package/src/projection.ts +174 -0
  191. package/src/search.ts +291 -0
  192. package/src/settings.ts +169 -0
@@ -0,0 +1,264 @@
1
+ import { jsx as _jsx, jsxs as _jsxs, Fragment as _Fragment } from "react/jsx-runtime";
2
+ import { memo, useEffect, useRef, useState } from 'react';
3
+ import { useMarkerData, usePinning, useReadingSpy, useFailureNotice, useLoadingNotice, useFavorites, useMobileMode, useMobileSearchButton, useNavSettings, clockText } from "../rail/useRail.js";
4
+ import { Hint } from "../rail/hint.js";
5
+ import { fetchHits } from "../rail/search.js";
6
+ import { QuickSettings } from "../rail/quick-settings.js";
7
+ import { BAND_HEIGHT_PX } from "../../settings.js";
8
+ /** deepseek 消息行高(px):行高 30px = 行距几何(文字 14px) */
9
+ const DS_ROW_HEIGHT = 30;
10
+ /** 消息行:行首横线(hover 变收藏按钮)+ 用户消息单行预览 */
11
+ const DsRow = memo(function DsRow(props) {
12
+ const { marker, current, jumping, hovered, favorited, label, onHover, onLeave, onToggleFavorite, onJump } = props;
13
+ const cls = ['mgcn-dsRow'];
14
+ if (current)
15
+ cls.push('mgcn-dsCurrent');
16
+ if (jumping)
17
+ cls.push('mgcn-dsJump');
18
+ if (hovered)
19
+ cls.push('mgcn-dsRowHover');
20
+ return (_jsxs("div", { className: cls.join(' '), "data-mega-chat-nav-key": marker.key, onMouseEnter: onHover, onMouseLeave: onLeave, children: [hovered ? (_jsx("button", { type: "button", className: favorited ? 'mgcn-dsFav mgcn-dsFavOn' : 'mgcn-dsFav', "aria-label": favorited ? 'unfavorite' : 'favorite', onClick: (e) => { e.stopPropagation(); onToggleFavorite(); }, children: _jsx("svg", { viewBox: "0 0 16 16", width: "11", height: "11", "aria-hidden": "true", children: _jsx("path", { d: "M8 2.2l1.76 3.56 3.93.57-2.84 2.77.67 3.91L8 11.4l-3.52 1.85.67-3.91-2.84-2.77 3.93-.57z", fill: favorited ? 'currentColor' : 'none', stroke: "currentColor", strokeWidth: "1.4", strokeLinejoin: "round" }) }) })) : (_jsx("i", { className: "mgcn-dsMark", "aria-hidden": "true" })), _jsx("button", { type: "button", className: "mgcn-dsText", "aria-label": label, onClick: onJump, children: _jsx("span", { className: "mgcn-dsTextInner", children: marker.texts[0] ?? '' }) })] }));
21
+ });
22
+ /** 就地搜索结果行(点击跳转) */
23
+ function SearchHitRow(props) {
24
+ const { hit, onJump } = props;
25
+ const roleTag = hit.role === 'assistant' ? '助手' : hit.role === 'tool' ? '工具' : '用户';
26
+ return (_jsxs("button", { type: "button", className: "mgcn-dsHit", onClick: onJump, children: [_jsx("i", { className: "mgcn-dsMark", "aria-hidden": "true" }), _jsxs("span", { className: "mgcn-dsHitBody", children: [_jsxs("span", { className: "mgcn-dsHitMeta", children: [hit.turn > 0 ? _jsxs("span", { children: ["\u7B2C ", hit.turn, " \u8F6E"] }) : null, _jsx("span", { className: 'mgcn-dsHitTag mgcn-dsHitTag--' + hit.role, children: roleTag })] }), _jsx("span", { className: "mgcn-dsHitText", children: hit.hitStart >= 0 && hit.hitLen > 0 ? (_jsxs(_Fragment, { children: [hit.snippet.slice(0, hit.hitStart), _jsx("mark", { className: "mgcn-search-mark", children: hit.snippet.slice(hit.hitStart, hit.hitStart + hit.hitLen) }), hit.snippet.slice(hit.hitStart + hit.hitLen)] })) : hit.snippet })] })] }));
27
+ }
28
+ /** 阅读位置跟随:正文滚动时面板内当前行平滑居中。
29
+ * resetKey:外部事件计数(退出搜索 searchOpen / 鼠标离开 rail followTick),
30
+ * 变化时强制重新居中到当前行——即使 currentKey/markers 未变也执行一次跟随。 */
31
+ function useFollowCurrent(listRef, currentKey, markers, resetKey) {
32
+ useEffect(() => {
33
+ const list = listRef.current;
34
+ if (list === null || currentKey === null)
35
+ return;
36
+ const index = markers.findIndex((d) => d.key === currentKey);
37
+ if (index < 0)
38
+ return;
39
+ const slotTop = index * DS_ROW_HEIGHT;
40
+ const contentHeight = markers.length * DS_ROW_HEIGHT + 12;
41
+ const maxScroll = Math.max(0, contentHeight - list.clientHeight);
42
+ const target = Math.max(0, Math.min(slotTop - list.clientHeight / 2 + DS_ROW_HEIGHT / 2, maxScroll));
43
+ if (Math.abs(target - list.scrollTop) < 2)
44
+ return;
45
+ list.scrollTo({ top: target, behavior: 'smooth' });
46
+ }, [currentKey, markers, resetKey]);
47
+ }
48
+ export function DeepseekRail(props) {
49
+ const { injected, useSessions, t } = props;
50
+ const panelRef = useRef(null);
51
+ const listRef = useRef(null);
52
+ const searchInputRef = useRef(null);
53
+ const [open, setOpen] = useState(false); // JS hover 展开态(不用 CSS :hover)
54
+ const [jumpingKey, setJumpingKey] = useState(null);
55
+ const [searchOpen, setSearchOpen] = useState(false);
56
+ const [configOpen, setConfigOpen] = useState(false);
57
+ const [favFilter, setFavFilter] = useState(false);
58
+ const [hoverKey, setHoverKey] = useState(null);
59
+ const [drawerOpen, setDrawerOpen] = useState(false);
60
+ const closeTimer = useRef(null);
61
+ const [query, setQuery] = useState('');
62
+ const [results, setResults] = useState([]);
63
+ const [searching, setSearching] = useState(false); // 检索进行中(列表 loading 态)
64
+ // 鼠标离开导航区域触发一次跟随:并入 resetKey 使跟随 effect 重跑(几何复用,无新增计算)
65
+ const [followTick, setFollowTick] = useState(0);
66
+ const abortRef = useRef(null);
67
+ const debounceRef = useRef(null);
68
+ const mobile = useMobileMode();
69
+ const { sessionId, visible, markers } = useMarkerData(injected, useSessions);
70
+ const { favorites, toggle: toggleFavorite } = useFavorites(sessionId);
71
+ const settings = useNavSettings(injected);
72
+ const { align, bandHeight } = settings;
73
+ useMobileSearchButton(() => setDrawerOpen(true), mobile && markers.length > 0, align, t('search.placeholder'));
74
+ const effectiveFilter = favFilter && favorites.size > 0;
75
+ const displayMarkers = effectiveFilter
76
+ ? markers.filter((m) => m.members.some((k) => favorites.has(k)))
77
+ : markers;
78
+ usePinning(panelRef, visible, align, settings.railOffset, sessionId);
79
+ const [currentKey, forceKey] = useReadingSpy(visible, displayMarkers);
80
+ const hint = useFailureNotice(t);
81
+ const loading = useLoadingNotice(t);
82
+ useFollowCurrent(listRef, currentKey, displayMarkers, String(searchOpen) + ':' + followTick);
83
+ // 一键复位:收起面板并关闭全部就地模式(搜索/设置/收藏筛选),列表还原
84
+ const collapseToIdle = () => {
85
+ cancelClose();
86
+ setOpen(false);
87
+ setHoverKey(null);
88
+ setSearchOpen(false);
89
+ setQuery('');
90
+ setResults([]);
91
+ setSearching(false);
92
+ if (debounceRef.current !== null) {
93
+ window.clearTimeout(debounceRef.current);
94
+ debounceRef.current = null;
95
+ }
96
+ abortRef.current?.abort();
97
+ setConfigOpen(false);
98
+ setFavFilter(false);
99
+ };
100
+ // 展开/收起 JS 状态:进入即开,离开延迟 260ms 收。
101
+ // 就地模式(搜索/设置)开启时移出**不收起**——只有点击外部才关闭。
102
+ const cancelClose = () => {
103
+ if (closeTimer.current !== null) {
104
+ window.clearTimeout(closeTimer.current);
105
+ closeTimer.current = null;
106
+ }
107
+ };
108
+ const scheduleClose = () => {
109
+ cancelClose();
110
+ if (searchOpen || configOpen || effectiveFilter)
111
+ return;
112
+ closeTimer.current = window.setTimeout(() => {
113
+ closeTimer.current = null;
114
+ collapseToIdle();
115
+ }, 260);
116
+ };
117
+ // 复位函数经 ref 提供给稳定的全局监听(点击外部)
118
+ const collapseToIdleRef = useRef(collapseToIdle);
119
+ collapseToIdleRef.current = collapseToIdle;
120
+ // 点击外部(rail 及就地浮层之外):收起面板并复位全部就地状态
121
+ useEffect(() => {
122
+ const onDocPointerDown = (e) => {
123
+ const panel = panelRef.current;
124
+ if (panel === null)
125
+ return;
126
+ const t = e.target;
127
+ if (t instanceof Node && panel.contains(t))
128
+ return;
129
+ collapseToIdleRef.current?.();
130
+ };
131
+ document.addEventListener('pointerdown', onDocPointerDown, true);
132
+ return () => document.removeEventListener('pointerdown', onDocPointerDown, true);
133
+ }, []);
134
+ // 卸载清理
135
+ useEffect(() => () => {
136
+ if (closeTimer.current !== null)
137
+ window.clearTimeout(closeTimer.current);
138
+ if (debounceRef.current !== null)
139
+ window.clearTimeout(debounceRef.current);
140
+ abortRef.current?.abort();
141
+ }, []);
142
+ // 搜索:就地输入防抖 → host 检索(进行中列表进入 loading 态)
143
+ const runSearch = (raw) => {
144
+ abortRef.current?.abort();
145
+ const ac = new AbortController();
146
+ abortRef.current = ac;
147
+ const q = raw.trim();
148
+ if (q.length < 1) {
149
+ setResults([]);
150
+ setSearching(false);
151
+ return;
152
+ }
153
+ setSearching(true);
154
+ fetchHits(sessionId, q, settings.searchScopes, ac.signal)
155
+ .then((hits) => {
156
+ if (abortRef.current !== ac)
157
+ return;
158
+ setResults(hits);
159
+ setSearching(false);
160
+ })
161
+ .catch(() => { if (abortRef.current === ac)
162
+ setSearching(false); });
163
+ };
164
+ const onSearchInput = (value) => {
165
+ setQuery(value);
166
+ if (debounceRef.current !== null)
167
+ window.clearTimeout(debounceRef.current);
168
+ if (value.trim() === '') {
169
+ // 清空:取消在途检索并还原列表(不再等防抖)
170
+ debounceRef.current = null;
171
+ abortRef.current?.abort();
172
+ setResults([]);
173
+ setSearching(false);
174
+ return;
175
+ }
176
+ setSearching(true); // 输入即 loading(含防抖窗口),结果到达后熄灭
177
+ // 250ms 防抖:连续输入只触发一次检索
178
+ debounceRef.current = window.setTimeout(() => {
179
+ debounceRef.current = null;
180
+ runSearch(value);
181
+ }, 250);
182
+ };
183
+ const openSearch = () => {
184
+ cancelClose();
185
+ setConfigOpen(false);
186
+ setFavFilter(false); // 搜索替代收藏筛选:全量历史检索
187
+ setSearchOpen(true);
188
+ setOpen(true); // 搜索就地态要求面板保持展开(移出不收)
189
+ window.setTimeout(() => searchInputRef.current?.focus(), 30);
190
+ };
191
+ // 收藏行切换:筛选态下取消「最后一个收藏」→ 自动退出收藏模式
192
+ // (再点行收藏只 +1 收藏,不再自动进入筛选;需点操作栏 ⭐ 才重新进入)
193
+ const onToggleRowFavorite = (key) => {
194
+ const removingLast = effectiveFilter && favorites.size === 1 && favorites.has(key);
195
+ toggleFavorite(key);
196
+ if (removingLast)
197
+ setFavFilter(false);
198
+ };
199
+ const closeSearch = () => {
200
+ cancelClose();
201
+ setSearchOpen(false);
202
+ setQuery('');
203
+ setResults([]);
204
+ setSearching(false);
205
+ if (debounceRef.current !== null) {
206
+ window.clearTimeout(debounceRef.current);
207
+ debounceRef.current = null;
208
+ }
209
+ abortRef.current?.abort();
210
+ // 还原时指针已不在 rail 上 → 一并收起;仍在 rail 上则保持展开
211
+ if (panelRef.current !== null && !panelRef.current.matches(':hover')) {
212
+ setOpen(false);
213
+ setHoverKey(null);
214
+ }
215
+ };
216
+ // ⚙:消息面板收起(还原未 hover 的窄轨)+ 弹出通用设置浮层(rail 对话侧)
217
+ const toggleConfig = () => {
218
+ cancelClose();
219
+ if (configOpen) {
220
+ setConfigOpen(false);
221
+ setHoverKey(null);
222
+ // 点击浮层 ✕/外部后若指针已离开 rail 区域则整体收起
223
+ if (panelRef.current !== null && !panelRef.current.matches(':hover')) {
224
+ setOpen(false);
225
+ }
226
+ return;
227
+ }
228
+ closeSearch();
229
+ setOpen(false);
230
+ setHoverKey(null);
231
+ setConfigOpen(true);
232
+ };
233
+ if (!visible || injected === undefined || markers.length === 0)
234
+ return null;
235
+ const onJump = (row) => {
236
+ if (sessionId === undefined)
237
+ return;
238
+ setJumpingKey(row.key);
239
+ forceKey(row.key);
240
+ const currentMarker = currentKey === null ? undefined : displayMarkers.find((m) => m.key === currentKey);
241
+ injected.jump(sessionId, row.key, row.seq, currentMarker?.seq);
242
+ window.setTimeout(() => setJumpingKey((k) => (k === row.key ? null : k)), 600);
243
+ };
244
+ const onJumpHit = (hit) => {
245
+ if (sessionId === undefined)
246
+ return;
247
+ setJumpingKey(hit.key);
248
+ forceKey(hit.key);
249
+ injected.jump(sessionId, hit.key, hit.seq);
250
+ window.setTimeout(() => setJumpingKey((k) => (k === hit.key ? null : k)), 600);
251
+ };
252
+ if (mobile) {
253
+ return (_jsx(_Fragment, { children: drawerOpen ? (_jsxs(_Fragment, { children: [_jsx("div", { className: "mgcn-drawerMask", onClick: () => setDrawerOpen(false) }), _jsxs("div", { className: "mgcn-searchDrawer", role: "dialog", "aria-label": t('search.placeholder'), children: [_jsx("div", { className: "mgcn-drawerInput", children: _jsx("input", { className: "mgcn-search-input", value: query, placeholder: t('search.placeholder'), autoFocus: true, onChange: (e) => onSearchInput(e.target.value), onKeyDown: (e) => { if (e.key === 'Escape')
254
+ setDrawerOpen(false); } }) }), query.trim() === '' ? (_jsx("div", { className: "mgcn-drawerList", children: [...markers].reverse().slice(0, 20).map((m) => (_jsxs("button", { type: "button", className: "mgcn-drawerItem", onClick: () => { setDrawerOpen(false); onJump(m); }, children: [_jsxs("span", { className: "mgcn-drawerItemTitle", children: [_jsx("span", { className: "mgcn-drawerItemTurn", children: m.turn !== null ? 'Turn ' + m.turn : '' }), _jsx("span", { className: "mgcn-drawerItemTime", children: clockText(m.time, Date.now()) })] }), _jsx("span", { className: "mgcn-drawerItemText", children: m.texts[0] ?? '' })] }, m.key))) })) : searching ? (_jsx("div", { className: "mgcn-drawerList", children: _jsxs("div", { className: "mgcn-dsLoadingRow", role: "status", children: [_jsxs("span", { className: "mgcn-dsLoadingDots", "aria-hidden": "true", children: [_jsx("i", {}), _jsx("i", {}), _jsx("i", {})] }), _jsx("span", { children: t('search.loading') })] }) })) : (_jsxs("div", { className: "mgcn-drawerList", children: [results.map((hit) => (_jsx(SearchHitRow, { hit: hit, onJump: () => { setDrawerOpen(false); onJumpHit(hit); } }, hit.key + ':' + hit.seq))), results.length === 0 ? _jsx("div", { className: "mgcn-dsNoHit", children: t('search.empty') }) : null] }))] })] })) : null }));
255
+ }
256
+ const messagesBody = (scrollable) => (_jsx("div", { ref: scrollable ? listRef : undefined, className: "mgcn-dsList", children: displayMarkers.map((row) => (_jsx(DsRow, { marker: row, current: currentKey === row.key, jumping: jumpingKey === row.key, hovered: hoverKey === row.key, favorited: favorites.has(row.key), label: row.texts[0] ?? '', onHover: () => setHoverKey(row.key), onLeave: () => setHoverKey((k) => (k === row.key ? null : k)), onToggleFavorite: () => onToggleRowFavorite(row.key), onJump: () => onJump(row) }, row.key))) }));
257
+ return (_jsxs("div", { ref: panelRef, className: (align === 'right' ? 'mgcn-rail mgcn-dsRail mgcn-railRight' : 'mgcn-rail mgcn-dsRail')
258
+ + (open ? ' mgcn-dsOpen' : '')
259
+ + (configOpen ? ' mgcn-dsSnap' : '') // 设置浮层开启:rail 收起窄轨(无过渡、层级抬升)
260
+ , "data-mega-chat-nav": "rail", onMouseEnter: () => { cancelClose(); if (!configOpen)
261
+ setOpen(true); }, onMouseLeave: () => { setFollowTick((n) => n + 1); scheduleClose(); }, children: [_jsx("div", { className: "mgcn-queue", children: displayMarkers.length === 0 ? (_jsx("div", { className: "mgcn-empty", children: t('strip.empty') })) : (_jsxs("div", { className: "mgcn-list", style: { '--mgcn-band-height': BAND_HEIGHT_PX.deepseek[bandHeight] + 'px' }, children: [_jsxs("div", { role: "menu", className: "mgcn-dsPanel", children: [_jsxs("div", { className: "mgcn-dsHead", children: [settings.showSearch !== 'hide' ? (searchOpen ? (_jsxs(_Fragment, { children: [_jsx("button", { type: "button", className: "mgcn-config-gear mgcn-dsModeOn", "aria-label": t('search.placeholder'), onClick: closeSearch, children: _jsxs("svg", { className: "mgcn-btn-icon", viewBox: "0 0 16 16", width: "13", height: "13", "aria-hidden": "true", children: [_jsx("circle", { cx: "7", cy: "7", r: "4.5", fill: "none", stroke: "currentColor", strokeWidth: "1.6" }), _jsx("line", { x1: "10.4", y1: "10.4", x2: "14", y2: "14", stroke: "currentColor", strokeWidth: "1.6", strokeLinecap: "round" })] }) }), _jsx("input", { ref: searchInputRef, className: "mgcn-dsSearchInput", value: query, placeholder: t('search.placeholder'), onChange: (e) => onSearchInput(e.target.value), onKeyDown: (e) => { if (e.key === 'Escape')
262
+ closeSearch(); } })] })) : (_jsx("button", { type: "button", className: "mgcn-config-gear", "aria-label": t('search.placeholder'), onClick: openSearch, children: _jsxs("svg", { className: "mgcn-btn-icon", viewBox: "0 0 16 16", width: "13", height: "13", "aria-hidden": "true", children: [_jsx("circle", { cx: "7", cy: "7", r: "4.5", fill: "none", stroke: "currentColor", strokeWidth: "1.6" }), _jsx("line", { x1: "10.4", y1: "10.4", x2: "14", y2: "14", stroke: "currentColor", strokeWidth: "1.6", strokeLinecap: "round" })] }) }))) : null, !searchOpen && settings.showQuickSettings !== 'hide' ? (_jsx("button", { type: "button", className: configOpen ? 'mgcn-config-gear mgcn-dsModeOn' : 'mgcn-config-gear', "aria-label": t('config.title'), onClick: toggleConfig, children: _jsxs("svg", { className: "mgcn-btn-icon", viewBox: "0 0 24 24", width: "13", height: "13", "aria-hidden": "true", children: [_jsx("circle", { cx: "12", cy: "12", r: "3", fill: "none", stroke: "currentColor", strokeWidth: "1.7" }), _jsx("path", { d: "M19.4 15a1.65 1.65 0 0 0 .33 1.82l.06.06a2 2 0 0 1 0 2.83 2 2 0 0 1-2.83 0l-.06-.06a1.65 1.65 0 0 0-1.82-.33 1.65 1.65 0 0 0-1 1.51V21a2 2 0 0 1-2 2 2 2 0 0 1-2-2v-.09A1.65 1.65 0 0 0 9 19.4a1.65 1.65 0 0 0-1.82.33l-.06.06a2 2 0 0 1-2.83 0 2 2 0 0 1 0-2.83l.06-.06a1.65 1.65 0 0 0 .33-1.82 1.65 1.65 0 0 0-1.51-1H3a2 2 0 0 1-2-2 2 2 0 0 1 2-2h.09A1.65 1.65 0 0 0 4.6 9a1.65 1.65 0 0 0-.33-1.82l-.06-.06a2 2 0 0 1 0-2.83 2 2 0 0 1 2.83 0l.06.06a1.65 1.65 0 0 0 1.82.33H9a1.65 1.65 0 0 0 1-1.51V3a2 2 0 0 1 2-2 2 2 0 0 1 2 2v.09a1.65 1.65 0 0 0 1 1.51 1.65 1.65 0 0 0 1.82-.33l.06-.06a2 2 0 0 1 2.83 0 2 2 0 0 1 0 2.83l-.06.06a1.65 1.65 0 0 0-.33 1.82V9a1.65 1.65 0 0 0 1.51 1H21a2 2 0 0 1 2 2 2 2 0 0 1-2 2h-.09a1.65 1.65 0 0 0-1.51 1z", fill: "none", stroke: "currentColor", strokeWidth: "1.5", strokeLinejoin: "round" })] }) })) : null, !searchOpen && settings.showFavorites !== 'hide' ? (_jsx("button", { type: "button", className: effectiveFilter ? 'mgcn-config-gear mgcn-favFilterOn' : 'mgcn-config-gear', "aria-label": t('fav.filter'), onClick: () => { if (favorites.size > 0)
263
+ setFavFilter((v) => !v); }, children: _jsx("svg", { className: "mgcn-btn-icon", viewBox: "0 0 16 16", width: "13", height: "13", "aria-hidden": "true", children: _jsx("path", { d: "M8 2.2l1.76 3.56 3.93.57-2.84 2.77.67 3.91L8 11.4l-3.52 1.85.67-3.91-2.84-2.77 3.93-.57z", fill: favFilter ? 'currentColor' : 'none', stroke: "currentColor", strokeWidth: "1.3", strokeLinejoin: "round" }) }) })) : null, !searchOpen && settings.showCount !== 'hide' ? (_jsx("span", { className: "mgcn-count", children: displayMarkers.length })) : null] }), searchOpen ? (_jsx("div", { className: "mgcn-dsMode", children: query.trim() === '' ? (messagesBody(false)) : searching ? (_jsxs("div", { className: "mgcn-dsLoadingRow", role: "status", children: [_jsxs("span", { className: "mgcn-dsLoadingDots", "aria-hidden": "true", children: [_jsx("i", {}), _jsx("i", {}), _jsx("i", {})] }), _jsx("span", { children: t('search.loading') })] })) : (_jsxs("div", { className: "mgcn-dsList", children: [results.map((hit) => (_jsx(SearchHitRow, { hit: hit, onJump: () => onJumpHit(hit) }, hit.key + ':' + hit.seq))), results.length === 0 ? _jsx("div", { className: "mgcn-dsNoHit", children: t('search.empty') }) : null] })) })) : (messagesBody(true))] }), configOpen ? (_jsx("span", { className: 'mgcn-gear-wrap mgcn-gear-wrap--' + align + ' mgcn-dsFloat', children: _jsx(QuickSettings, { injected: injected, t: t, onClose: () => { cancelClose(); setConfigOpen(false); setHoverKey(null); } }) })) : null] })) }), loading !== null ? _jsx(Hint, { text: loading, align: align, position: "bottom", loading: true }) : hint !== null ? _jsx(Hint, { text: hint, align: align }) : null] }));
264
+ }
@@ -0,0 +1,135 @@
1
+ import { jsx as _jsx, jsxs as _jsxs, Fragment as _Fragment } from "react/jsx-runtime";
2
+ import { useEffect, useRef, useState } from 'react';
3
+ import { useMarkerData, usePinning, useReadingSpy, useBandPaging, useCardPreview, useFailureNotice, useLoadingNotice, useFavorites, useMobileMode, useMobileSearchButton, useNavSettings, clockText, markerScale, markerTier, ROW_HEIGHT, usePeekState, useClosePopoversOnOutside } from "../rail/useRail.js";
4
+ import { Dot } from "./dot.js";
5
+ import { Cards } from "../rail/cards.js";
6
+ import { PagingButton } from "../rail/paging.js";
7
+ import { Hint } from "../rail/hint.js";
8
+ import { SearchBox } from "../rail/search.js";
9
+ import { QuickSettings } from "../rail/quick-settings.js";
10
+ import { STYLE_CAPABILITIES, BAND_HEIGHT_PX } from "../../settings.js";
11
+ export function MinimalRail(props) {
12
+ const { injected, useSessions, t } = props;
13
+ const panelRef = useRef(null);
14
+ const listRef = useRef(null);
15
+ const [jumpingKey, setJumpingKey] = useState(null);
16
+ const [configOpen, setConfigOpen] = useState(false);
17
+ const [searchOpen, setSearchOpen] = useState(false);
18
+ const [favFilter, setFavFilter] = useState(false);
19
+ const [drawerOpen, setDrawerOpen] = useState(false);
20
+ // 鼠标离开导航区域触发一次跟随:仅作 effect 重跑计数(跟随几何复用下方 effect)
21
+ const [followTick, setFollowTick] = useState(0);
22
+ const { showPeek, hidePeek, peekCls } = usePeekState();
23
+ // 上次 hover 命中的圆点 key(同一圆点内 mouseover 高频触发不重复开卡)
24
+ const lastHoverKey = useRef(null);
25
+ // 手机模式(<1024px):仅搜索图标 + 底部半宽搜索抽屉
26
+ const mobile = useMobileMode();
27
+ // 数据与设置
28
+ const { sessionId, visible, markers } = useMarkerData(injected, useSessions);
29
+ const { favorites, toggle: toggleFavorite } = useFavorites(sessionId);
30
+ const settings = useNavSettings(injected);
31
+ const { style, align, bandHeight, cardCount, cardItems, showPaging } = settings;
32
+ useMobileSearchButton(() => setDrawerOpen(true), mobile && markers.length > 0, align, t('search.placeholder'));
33
+ // 收藏过滤:派生状态——无收藏数据时自动视为未过滤
34
+ // (取消最后一个收藏立即恢复全部列表,不会困在空过滤态)
35
+ const effectiveFilter = favFilter && favorites.size > 0;
36
+ const displayMarkers = effectiveFilter
37
+ ? markers.filter((m) => m.members.some((k) => favorites.has(k)))
38
+ : markers;
39
+ // 布局钉位(含导航栏偏移;sessionId 变化 → 校准循环重启,覆盖会话/工作区切换重建)
40
+ usePinning(panelRef, visible, align, settings.railOffset, sessionId);
41
+ const [currentKey, forceKey] = useReadingSpy(visible, displayMarkers);
42
+ const { scrollable, revealed, syncScroll, pageBy, canPageUp, canPageDown } = useBandPaging(listRef, displayMarkers);
43
+ // 悬浮卡片(风格能力)
44
+ const caps = STYLE_CAPABILITIES[style];
45
+ const focusRadius = Math.floor((cardCount - 1) / 2);
46
+ const { focus, openCards, cancelClear, scheduleClear } = useCardPreview(displayMarkers, align, focusRadius, caps.hoverCards);
47
+ // 跳转失败提示 / 加载较早记录提示
48
+ const hint = useFailureNotice(t);
49
+ const loading = useLoadingNotice(t);
50
+ useClosePopoversOnOutside(configOpen, searchOpen, () => {
51
+ setConfigOpen(false);
52
+ setSearchOpen(false);
53
+ });
54
+ // 激活节点跟随:正文滚动时导航列表平滑居中(点击跳转后不冻结)
55
+ useEffect(() => {
56
+ const list = listRef.current;
57
+ if (list === null || currentKey === null)
58
+ return;
59
+ const index = displayMarkers.findIndex((d) => d.key === currentKey);
60
+ if (index < 0)
61
+ return;
62
+ const step = ROW_HEIGHT; // 行距 14px(8px 节点 + 6px 间距,与 rail 层几何一致)
63
+ const dotTop = 8 + index * step; // 列表上内边距 8px + 节点位置
64
+ const contentHeight = 16 + displayMarkers.length * step - 6;
65
+ const maxScroll = Math.max(0, contentHeight - list.clientHeight);
66
+ const target = Math.max(0, Math.min(dotTop - list.clientHeight / 2 + step / 2, maxScroll));
67
+ if (Math.abs(target - list.scrollTop) < 2)
68
+ return;
69
+ list.scrollTo({ top: target, behavior: 'smooth' });
70
+ }, [currentKey, markers, followTick]); // followTick:鼠标离开 rail 时重跑一次跟随
71
+ if (!visible || injected === undefined || markers.length === 0)
72
+ return null;
73
+ const onJump = (dot) => {
74
+ if (sessionId === undefined)
75
+ return;
76
+ setJumpingKey(dot.key);
77
+ forceKey(dot.key); // 点击瞬间强制激活目标(正文滚动稳定后由采样判据接管)
78
+ const currentMarker = currentKey === null ? undefined : displayMarkers.find((m) => m.key === currentKey);
79
+ injected.jump(sessionId, dot.key, dot.seq, currentMarker?.seq);
80
+ window.setTimeout(() => setJumpingKey((k) => (k === dot.key ? null : k)), 600);
81
+ };
82
+ // 事件委托(圆点是 memo 纯展示):hover 开悬浮卡 / 点击跳转。
83
+ // 用 onMouseOver(真实冒泡,圆点间移动每次触发)而非 onMouseEnter
84
+ // (容器级 mouseenter 只在从外部进入时触发一次——圆点间移动不会换卡)。
85
+ const onDotsOver = (e) => {
86
+ const el = e.target;
87
+ const hit = el.closest('[data-mega-chat-nav-key]');
88
+ if (hit === null)
89
+ return;
90
+ const key = hit.dataset.megaChatNavKey;
91
+ if (key === undefined || key === lastHoverKey.current)
92
+ return;
93
+ const dot = displayMarkers.find((d) => d.key === key);
94
+ if (dot === undefined)
95
+ return;
96
+ lastHoverKey.current = key;
97
+ cancelClear();
98
+ openCards(dot, hit);
99
+ };
100
+ const onDotsClick = (e) => {
101
+ const el = e.target;
102
+ const hit = el.closest('[data-mega-chat-nav-key]');
103
+ if (hit === null)
104
+ return;
105
+ const key = hit.dataset.megaChatNavKey;
106
+ const dot = displayMarkers.find((d) => d.key === key);
107
+ if (dot !== undefined)
108
+ onJump(dot);
109
+ };
110
+ if (mobile) {
111
+ return (_jsx(_Fragment, { children: drawerOpen ? (_jsxs(_Fragment, { children: [_jsx("div", { className: "mgcn-drawerMask", onClick: () => setDrawerOpen(false) }), _jsx("div", { className: "mgcn-searchDrawer", role: "dialog", "aria-label": t('search.placeholder'), children: _jsx(SearchBox, { sessionId: sessionId, scopes: settings.searchScopes, t: t, onJump: (key, seq) => {
112
+ setDrawerOpen(false);
113
+ onJump({ key, seq: seq ?? 0, turn: null, time: Date.now(), texts: [], members: [key] });
114
+ }, onClose: () => setDrawerOpen(false), emptyContent: _jsx("div", { className: "mgcn-drawerList", children: [...markers].reverse().slice(0, 20).map((m) => (_jsxs("button", { type: "button", className: "mgcn-drawerItem", onClick: () => { setDrawerOpen(false); onJump(m); }, children: [_jsxs("span", { className: "mgcn-drawerItemTitle", children: [_jsx("span", { className: "mgcn-drawerItemTurn", children: m.turn !== null ? 'Turn ' + m.turn : '' }), _jsx("span", { className: "mgcn-drawerItemTime", children: clockText(m.time, Date.now()) })] }), _jsx("span", { className: "mgcn-drawerItemText", children: m.texts[0] ?? '' })] }, m.key))) }) }) })] })) : null }));
115
+ }
116
+ const selectedIndex = focus === null ? -1 : displayMarkers.findIndex((d) => d.key === focus?.key);
117
+ return (_jsxs("div", { ref: panelRef, className: align === 'right' ? 'mgcn-rail mgcn-railRight' : 'mgcn-rail', "data-mega-chat-nav": "rail", onMouseEnter: showPeek, onMouseLeave: () => { hidePeek(); setFollowTick((n) => n + 1); }, children: [_jsx("div", { className: "mgcn-queue", children: displayMarkers.length === 0 ? (_jsx("div", { className: "mgcn-empty", children: t('strip.empty') })) : (_jsxs("div", { className: "mgcn-list", style: { '--mgcn-band-height': BAND_HEIGHT_PX.minimal[bandHeight] + 'px' }, children: [_jsxs("div", { className: "mgcn-actions", children: [settings.showQuickSettings !== 'hide' ? (_jsxs("span", { className: 'mgcn-gear-wrap mgcn-gear-wrap--' + align + peekCls(settings.showQuickSettings, configOpen), children: [_jsx("button", { type: "button", className: "mgcn-config-gear", "aria-label": t('config.title'), onClick: () => { setConfigOpen((v) => !v); setSearchOpen(false); }, children: _jsxs("svg", { className: "mgcn-btn-icon", viewBox: "0 0 24 24", width: "12", height: "12", "aria-hidden": "true", children: [_jsx("circle", { cx: "12", cy: "12", r: "3", fill: "none", stroke: "currentColor", strokeWidth: "1.7" }), _jsx("path", { d: "M19.4 15a1.65 1.65 0 0 0 .33 1.82l.06.06a2 2 0 0 1 0 2.83 2 2 0 0 1-2.83 0l-.06-.06a1.65 1.65 0 0 0-1.82-.33 1.65 1.65 0 0 0-1 1.51V21a2 2 0 0 1-2 2 2 2 0 0 1-2-2v-.09A1.65 1.65 0 0 0 9 19.4a1.65 1.65 0 0 0-1.82.33l-.06.06a2 2 0 0 1-2.83 0 2 2 0 0 1 0-2.83l.06-.06a1.65 1.65 0 0 0 .33-1.82 1.65 1.65 0 0 0-1.51-1H3a2 2 0 0 1-2-2 2 2 0 0 1 2-2h.09A1.65 1.65 0 0 0 4.6 9a1.65 1.65 0 0 0-.33-1.82l-.06-.06a2 2 0 0 1 0-2.83 2 2 0 0 1 2.83 0l.06.06a1.65 1.65 0 0 0 1.82.33H9a1.65 1.65 0 0 0 1-1.51V3a2 2 0 0 1 2-2 2 2 0 0 1 2 2v.09a1.65 1.65 0 0 0 1 1.51 1.65 1.65 0 0 0 1.82-.33l.06-.06a2 2 0 0 1 2.83 0 2 2 0 0 1 0 2.83l-.06.06a1.65 1.65 0 0 0-.33 1.82V9a1.65 1.65 0 0 0 1.51 1H21a2 2 0 0 1 2 2 2 2 0 0 1-2 2h-.09a1.65 1.65 0 0 0-1.51 1z", fill: "none", stroke: "currentColor", strokeWidth: "1.5", strokeLinejoin: "round" })] }) }), configOpen ? (_jsx(QuickSettings, { injected: injected, t: t, onClose: () => setConfigOpen(false) })) : null] })) : null, settings.showFavorites !== 'hide' ? (_jsx("span", { className: 'mgcn-gear-wrap mgcn-gear-wrap--' + align + peekCls(settings.showFavorites, false), children: _jsx("button", { type: "button", className: effectiveFilter ? 'mgcn-config-gear mgcn-favFilterOn' : 'mgcn-config-gear', "aria-label": t('fav.filter'), onClick: () => { if (favorites.size > 0)
118
+ setFavFilter((v) => !v); }, children: _jsx("svg", { className: "mgcn-btn-icon", viewBox: "0 0 16 16", width: "12", height: "12", "aria-hidden": "true", children: _jsx("path", { d: "M8 2.2l1.76 3.56 3.93.57-2.84 2.77.67 3.91L8 11.4l-3.52 1.85.67-3.91-2.84-2.77 3.93-.57z", fill: favFilter ? 'currentColor' : 'none', stroke: "currentColor", strokeWidth: "1.3", strokeLinejoin: "round" }) }) }) })) : null, settings.showSearch !== 'hide' ? (_jsxs("span", { className: 'mgcn-gear-wrap mgcn-gear-wrap--' + align + peekCls(settings.showSearch, searchOpen), children: [_jsx("button", { type: "button", className: "mgcn-config-gear", "aria-label": t('search.placeholder'), onClick: () => { setSearchOpen((v) => !v); setConfigOpen(false); }, children: _jsxs("svg", { className: "mgcn-btn-icon", viewBox: "0 0 16 16", width: "12", height: "12", "aria-hidden": "true", children: [_jsx("circle", { cx: "7", cy: "7", r: "4.5", fill: "none", stroke: "currentColor", strokeWidth: "1.6" }), _jsx("line", { x1: "10.4", y1: "10.4", x2: "14", y2: "14", stroke: "currentColor", strokeWidth: "1.6", strokeLinecap: "round" })] }) }), searchOpen ? (_jsx(SearchBox, { sessionId: sessionId, scopes: settings.searchScopes, t: t, onJump: (key, seq) => onJump({ key, seq: seq ?? 0, turn: null, time: Date.now(), texts: [], members: [key] }), onClose: () => setSearchOpen(false) })) : null] })) : null, settings.showCount !== 'hide' ? (_jsx("span", { className: 'mgcn-count' + peekCls(settings.showCount, false), children: displayMarkers.length })) : null] }), scrollable && showPaging !== 'hide' ? (_jsx("div", { className: 'mgcn-pageUp' + peekCls(showPaging, false), children: _jsx(PagingButton, { dir: -1, visible: canPageUp, label: t('strip.up'), onEnter: cancelClear, onLeave: scheduleClear, onClick: () => pageBy(-1) }) })) : null, _jsx("div", { ref: listRef, className: "mgcn-dots", onScroll: syncScroll, onMouseLeave: () => { lastHoverKey.current = null; scheduleClear(); }, onMouseOver: onDotsOver, onClick: onDotsClick, children: displayMarkers.map((dot, index) => {
119
+ const isFocused = focus !== null && focus.key === dot.key;
120
+ const tier = selectedIndex < 0 ? null : markerTier(index - selectedIndex);
121
+ const scale = jumpingKey === dot.key ? 1.6 : tier !== null ? markerScale(tier) : 1;
122
+ const reveal = revealed?.get(dot.key);
123
+ const cls = ['mgcn-dot'];
124
+ if (isFocused)
125
+ cls.push('mgcn-focused');
126
+ if (jumpingKey === dot.key)
127
+ cls.push('mgcn-active');
128
+ if (currentKey === dot.key)
129
+ cls.push('mgcn-current');
130
+ if (reveal !== undefined) {
131
+ cls.push(reveal.dir === 1 ? 'mgcn-dotEnterFromBottom' : 'mgcn-dotEnterFromTop');
132
+ }
133
+ return (_jsx(Dot, { keyName: dot.key, index: index, className: cls.join(' '), scale: scale, label: dot.texts[0] ?? '', focused: isFocused, revealed: reveal }, dot.key));
134
+ }) }), scrollable && showPaging !== 'hide' ? (_jsx("div", { className: 'mgcn-pageDown' + peekCls(showPaging, false), children: _jsx(PagingButton, { dir: 1, visible: canPageDown, label: t('strip.down'), onEnter: cancelClear, onLeave: scheduleClear, onClick: () => pageBy(1) }) })) : null] })) }), loading !== null ? _jsx(Hint, { text: loading, align: align, position: "bottom", loading: true }) : hint !== null ? _jsx(Hint, { text: hint, align: align }) : null, focus !== null ? (_jsx(Cards, { focus: focus, align: align, cardItems: cardItems, favorites: favorites, onToggleFavorite: toggleFavorite, onJump: onJump, onEnter: cancelClear, onLeave: scheduleClear })) : null] }));
135
+ }
@@ -0,0 +1,32 @@
1
+ import { jsx as _jsx, jsxs as _jsxs } from "react/jsx-runtime";
2
+ import { createPortal } from 'react-dom';
3
+ import { cardMetrics, metricsLine, clockText } from "./useRail.js";
4
+ function favoriteButton(favorited, onClick) {
5
+ return (_jsx("button", { type: "button", className: favorited ? 'mgs-cardFav mgs-cardFavOn' : 'mgs-cardFav', "aria-label": favorited ? 'unfavorite' : 'favorite', onClick: (e) => { e.stopPropagation(); onClick(); }, children: _jsx("svg", { viewBox: "0 0 16 16", width: "11", height: "11", "aria-hidden": "true", children: _jsx("path", { d: "M8 2.2l1.76 3.56 3.93.57-2.84 2.77.67 3.91L8 11.4l-3.52 1.85.67-3.91-2.84-2.77 3.93-.57z", fill: favorited ? 'currentColor' : 'none', stroke: "currentColor", strokeWidth: "1.3", strokeLinejoin: "round" }) }) }));
6
+ }
7
+ export function Cards(props) {
8
+ const { focus, align, cardItems, favorites, onToggleFavorite, onJump, onEnter, onLeave } = props;
9
+ const showTurn = cardItems.includes('turn');
10
+ const showDuration = cardItems.includes('duration');
11
+ const showFavorite = cardItems.includes('favorite');
12
+ return createPortal(_jsx("div", { className: align === 'right' ? 'mgs-cascade mgs-cascadeRight' : 'mgs-cascade', style: {
13
+ ...(focus.left !== undefined ? { left: focus.left } : {}),
14
+ ...(focus.right !== undefined ? { right: focus.right } : {}),
15
+ top: focus.centerY,
16
+ transform: 'translateY(-50%)',
17
+ }, onMouseEnter: onEnter, onMouseLeave: onLeave, children: focus.items.map((item) => {
18
+ const metrics = cardMetrics(item.distance);
19
+ if (metrics === null)
20
+ return null;
21
+ const isSelected = item.distance === 0;
22
+ const dot = item.dot;
23
+ const text = dot.texts.join(' · ');
24
+ const cls = isSelected
25
+ ? 'mgs-card mgs-cardSelected' + (align === 'right' ? ' mgs-cardSelectedRight' : '')
26
+ : 'mgs-card';
27
+ const favorited = favorites.has(dot.key);
28
+ return (_jsxs("div", { className: cls, role: "button", tabIndex: -1, style: { width: metrics.widthPx }, onClick: () => onJump(dot), children: [_jsxs("div", { className: "mgs-cardHead", children: [showFavorite ? favoriteButton(favorited, () => onToggleFavorite(dot.key)) : null, showTurn && isSelected && dot.turn !== null ? (_jsxs("div", { className: "mgs-cardTitle", children: ["Turn ", dot.turn] })) : null, _jsx("div", { className: "mgs-cardTime", children: clockText(dot.time, Date.now()) })] }), showDuration && dot.metrics !== undefined && isSelected ? (_jsx("div", { className: "mgs-cardMetrics", children: metricsLine(dot.metrics) })) : null, _jsx("div", { className: isSelected ? 'mgs-cardBody' : 'mgs-cardClamp', style: isSelected
29
+ ? undefined
30
+ : { WebkitLineClamp: metrics.maxLines, fontSize: metrics.fontSize }, children: text })] }, dot.key));
31
+ }) }), document.body);
32
+ }
@@ -0,0 +1,11 @@
1
+ import { jsx as _jsx } from "react/jsx-runtime";
2
+ // 圆点按钮:纯展示(缩放/跳转/翻页弹出状态由父级 memo 前算好)——
3
+ // memo 化后长会话 hover 不再整列重渲;事件由列表容器委托
4
+ import { memo } from 'react';
5
+ export const Dot = memo(function Dot(props) {
6
+ const { scale, className, label, index, keyName, focused, revealed } = props;
7
+ return (_jsx("button", { type: "button", className: className, style: {
8
+ transform: 'scale(' + scale + ')',
9
+ ...(revealed !== undefined ? { animationDelay: revealed.order * 35 + 'ms' } : {}),
10
+ }, "data-mega-chat-nav-focused": focused ? 'true' : undefined, "data-mega-chat-nav-index": index, "data-mega-chat-nav-key": keyName, "aria-label": label }));
11
+ });
@@ -0,0 +1,30 @@
1
+ import { jsx as _jsx, jsxs as _jsxs } from "react/jsx-runtime";
2
+ // 跳转失败 / 加载提示(portal 到 body):
3
+ // - 失败提示:贴 rail 侧顶部(rail 左右对齐)
4
+ // - 加载提示:对话输入框上方细条,水平对齐相对**对话区域**左右边缘(跟随 rail 侧)
5
+ import { useEffect, useState } from 'react';
6
+ import { createPortal } from 'react-dom';
7
+ /** 对话区域左/右边缘到视口的距离(fixed 定位用) */
8
+ function conversationEdge(align) {
9
+ const root = document.querySelector('[data-slot="conversation"] > div[data-phase]');
10
+ if (root === null)
11
+ return null;
12
+ const r = root.getBoundingClientRect();
13
+ return align === 'right' ? window.innerWidth - r.right : r.left;
14
+ }
15
+ export function Hint({ text, align, position = 'rail', loading = false }) {
16
+ const [edge, setEdge] = useState(() => conversationEdge(align));
17
+ useEffect(() => {
18
+ const measure = () => setEdge(conversationEdge(align));
19
+ measure();
20
+ window.addEventListener('resize', measure);
21
+ return () => window.removeEventListener('resize', measure);
22
+ }, [align]);
23
+ const cls = position === 'bottom' ? 'mgs-hint mgs-hint--bottom' : 'mgs-hint';
24
+ const style = position === 'bottom'
25
+ ? align === 'right'
26
+ ? { right: (edge ?? 0) + 20, bottom: 150 }
27
+ : { left: (edge ?? 0) + 20, bottom: 150 }
28
+ : align === 'right' ? { right: 52, top: 12 } : { left: 52, top: 12 };
29
+ return createPortal(_jsxs("div", { className: cls, style: style, children: [loading ? (_jsxs("span", { className: "mgs-hint-dots", "aria-hidden": "true", children: [_jsx("i", {}), _jsx("i", {}), _jsx("i", {})] })) : null, _jsx("span", { children: text })] }), document.body);
30
+ }
@@ -0,0 +1,5 @@
1
+ import { jsx as _jsx } from "react/jsx-runtime";
2
+ export function PagingButton(props) {
3
+ const cls = props.dir === -1 ? 'mgs-navBtn mgs-navUp' : 'mgs-navBtn mgs-navDown';
4
+ return (_jsx("button", { type: "button", className: cls, "aria-label": props.label, style: { visibility: props.visible ? 'visible' : 'hidden' }, onMouseEnter: props.onEnter, onMouseLeave: props.onLeave, onClick: props.onClick }));
5
+ }
@@ -0,0 +1,28 @@
1
+ import { jsx as _jsx, jsxs as _jsxs } from "react/jsx-runtime";
2
+ // 快捷设置面板:对齐/条带高度/卡片数(能力感知)+ 显示模式
3
+ import { useEffect, useState } from 'react';
4
+ import { ALIGN_OPTIONS, BAND_OPTIONS, CARD_OPTIONS, SHOW_OPTIONS, STYLE_CAPABILITIES } from "../../settings.js";
5
+ function Seg(props) {
6
+ return (_jsx("div", { className: "mgs-segmented", role: "radiogroup", children: props.options.map((o) => (_jsx("button", { type: "button", role: "radio", "aria-checked": props.value === o, className: props.value === o ? 'mgs-segment mgs-segmentActive' : 'mgs-segment', onClick: () => props.onPick(o), children: props.labels[String(o)] ?? String(o) }, o))) }));
7
+ }
8
+ function ModeSeg({ value, onChange, t }) {
9
+ return (_jsx(Seg, { options: SHOW_OPTIONS, value: value, labels: {
10
+ show: t('config.showMode.show'),
11
+ peek: t('config.showMode.peek'),
12
+ hide: t('config.showMode.hide'),
13
+ }, onPick: (v) => onChange(v) }));
14
+ }
15
+ function useSettingsTick(subscribe) {
16
+ const [, bump] = useState(0);
17
+ useEffect(() => subscribe(() => bump((n) => n + 1)), [subscribe]);
18
+ }
19
+ export function QuickSettings(props) {
20
+ const { injected, t, onClose } = props;
21
+ useSettingsTick(injected.subscribeSettings);
22
+ const caps = STYLE_CAPABILITIES[injected.style()];
23
+ return (_jsxs("div", { className: "mgs-config-panel", role: "dialog", "aria-label": t('config.title'), children: [_jsxs("div", { className: "mgs-config-head", children: [_jsxs("span", { className: "mgs-config-title", children: [t('config.style.' + injected.style()), " \u00B7 ", t('config.settings')] }), _jsx("button", { type: "button", className: "mgs-config-close", "aria-label": t('config.close'), onClick: onClose, children: "\u2715" })] }), _jsxs("div", { className: "mgs-config-row", children: [_jsx("span", { className: "mgs-config-label", children: t('config.align') }), _jsx(Seg, { options: ALIGN_OPTIONS, value: injected.align(), labels: { left: t('settings.align.left'), right: t('settings.align.right') }, onPick: (v) => injected.setAlign(v) })] }), _jsxs("div", { className: "mgs-config-row", children: [_jsx("span", { className: "mgs-config-label", children: t('config.bandHeight') }), _jsx(Seg, { options: BAND_OPTIONS, value: injected.bandHeight(), labels: {
24
+ compact: t('config.bandHeight.compact'),
25
+ standard: t('config.bandHeight.standard'),
26
+ tall: t('config.bandHeight.tall'),
27
+ }, onPick: (v) => injected.setBandHeight(v) })] }), caps.hoverCards ? (_jsxs("div", { className: "mgs-config-row", children: [_jsx("span", { className: "mgs-config-label", children: t('config.cardCount') }), _jsx(Seg, { options: CARD_OPTIONS, value: injected.cardCount(), labels: { 1: '1', 3: '3', 5: '5' }, onPick: (v) => injected.setCardCount(v) })] })) : null, _jsx("div", { className: "mgs-config-sep" }), _jsxs("div", { className: "mgs-config-row", children: [_jsx("span", { className: "mgs-config-label", children: t('config.showQuickSettings') }), _jsx(ModeSeg, { value: injected.showQuickSettings(), onChange: (v) => injected.setShowQuickSettings(v), t: t })] }), _jsxs("div", { className: "mgs-config-row", children: [_jsx("span", { className: "mgs-config-label", children: t('config.showSearch') }), _jsx(ModeSeg, { value: injected.showSearch(), onChange: (v) => injected.setShowSearch(v), t: t })] }), _jsxs("div", { className: "mgs-config-row", children: [_jsx("span", { className: "mgs-config-label", children: t('config.showFavorites') }), _jsx(ModeSeg, { value: injected.showFavorites(), onChange: (v) => injected.setShowFavorites(v), t: t })] }), _jsxs("div", { className: "mgs-config-row", children: [_jsx("span", { className: "mgs-config-label", children: t('config.showCount') }), _jsx(ModeSeg, { value: injected.showCount(), onChange: (v) => injected.setShowCount(v), t: t })] })] }));
28
+ }
@@ -0,0 +1,67 @@
1
+ import { jsx as _jsx, jsxs as _jsxs, Fragment as _Fragment } from "react/jsx-runtime";
2
+ // 搜索浮层:输入防抖 → host 检索 → 结果(tag 用户/AI + 轮次标题 + 两行预览 + 历史提示)
3
+ import { useCallback, useEffect, useRef, useState } from 'react';
4
+ import { clockText } from "./useRail.js";
5
+ /** 检索:携带 AbortController 的 host 请求(scopes 过滤由 host 执行) */
6
+ function fetchHits(sessionId, query, scopes, signal) {
7
+ const url = '/mega-chat-nav/search?session=' + encodeURIComponent(sessionId ?? '')
8
+ + '&q=' + encodeURIComponent(query) + '&limit=20'
9
+ + '&scopes=' + encodeURIComponent(scopes.join(','));
10
+ return fetch(url, { signal })
11
+ .then((resp) => resp.json())
12
+ .then((data) => (data.ok === true ? (data.hits ?? []) : []));
13
+ }
14
+ /** 角色 → 标签文本(用户/助手/工具;steering 归用户侧) */
15
+ function roleTag(role, t) {
16
+ if (role === 'assistant')
17
+ return t('search.tag.assistant');
18
+ if (role === 'tool')
19
+ return t('search.tag.tool');
20
+ return t('search.tag.user');
21
+ }
22
+ export function SearchBox(props) {
23
+ const [query, setQuery] = useState('');
24
+ const [results, setResults] = useState([]);
25
+ const [busy, setBusy] = useState(false);
26
+ const abortRef = useRef(null);
27
+ const debounceRef = useRef(null);
28
+ const inputRef = useRef(null);
29
+ const run = useCallback((raw) => {
30
+ abortRef.current?.abort();
31
+ const ac = new AbortController();
32
+ abortRef.current = ac;
33
+ const q = raw.trim();
34
+ if (q.length < 1) {
35
+ setResults([]);
36
+ setBusy(false);
37
+ return;
38
+ }
39
+ setBusy(true);
40
+ fetchHits(props.sessionId, q, props.scopes, ac.signal)
41
+ .then((hits) => {
42
+ setResults(hits);
43
+ })
44
+ .catch((e) => {
45
+ if (e.name !== 'AbortError')
46
+ setResults([]);
47
+ })
48
+ .finally(() => setBusy(false));
49
+ }, [props.sessionId, props.scopes]);
50
+ const onType = (value) => {
51
+ setQuery(value);
52
+ if (debounceRef.current !== null)
53
+ window.clearTimeout(debounceRef.current);
54
+ debounceRef.current = window.setTimeout(() => run(value), 200);
55
+ };
56
+ useEffect(() => {
57
+ inputRef.current?.focus();
58
+ return () => {
59
+ if (debounceRef.current !== null)
60
+ window.clearTimeout(debounceRef.current);
61
+ abortRef.current?.abort();
62
+ };
63
+ }, []);
64
+ const historicCount = results.filter((hit) => hit.historic).length;
65
+ return (_jsxs("div", { className: "mgs-search", role: "dialog", "aria-label": props.t('search.placeholder'), children: [_jsx("input", { ref: inputRef, className: "mgs-search-input", value: query, placeholder: props.t('search.placeholder'), onChange: (e) => onType(e.target.value), onKeyDown: (e) => { if (e.key === 'Escape')
66
+ props.onClose(); } }), busy ? _jsx("div", { className: "mgs-search-busy", children: "\u2026" }) : null, !busy && query.trim() === '' && props.emptyContent !== undefined ? props.emptyContent : null, !busy && results.length > 0 && historicCount > 0 ? (_jsx("div", { className: "mgs-search-historic", children: props.t('search.historic', { n: historicCount }) })) : null, results.length > 0 ? (_jsx("div", { className: "mgs-search-results", children: results.map((hit) => (_jsxs("button", { type: "button", className: "mgs-search-hit", onClick: () => props.onJump(hit.key, hit.seq), children: [_jsxs("span", { className: "mgs-search-title", children: [_jsxs("span", { className: "mgs-search-titleLeft", children: [hit.turn > 0 ? _jsx("span", { className: "mgs-search-turn", children: props.t('search.turnTitle', { turn: hit.turn }) }) : null, _jsx("span", { className: 'mgs-search-tag mgs-search-tag--' + hit.role, children: roleTag(hit.role, props.t) })] }), _jsx("span", { className: "mgs-search-titleTime", children: clockText(hit.time, Date.now()) })] }), _jsx("span", { className: "mgs-search-body", children: _jsx("span", { className: "mgs-search-text", children: hit.hitStart >= 0 && hit.hitLen > 0 ? (_jsxs(_Fragment, { children: [hit.snippet.slice(0, hit.hitStart), _jsx("mark", { className: "mgs-search-mark", children: hit.snippet.slice(hit.hitStart, hit.hitStart + hit.hitLen) }), hit.snippet.slice(hit.hitStart + hit.hitLen)] })) : hit.snippet }) })] }, hit.key + ':' + hit.seq))) })) : null] }));
67
+ }