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.
- package/LICENSE +201 -0
- package/README.en.md +149 -0
- package/README.md +149 -0
- package/cordis.patch.yml +4 -0
- package/lib/client/NavOverlay.js +35 -0
- package/lib/client/NavRail.js +12 -0
- package/lib/client/QuestionNavSettingsTab.js +26 -0
- package/lib/client/QuestionNavStrip.js +555 -0
- package/lib/client/components/ConfigPanel.js +14 -0
- package/lib/client/components/DotRail.js +62 -0
- package/lib/client/components/NavOverlay.js +121 -0
- package/lib/client/components/NavRail.js +97 -0
- package/lib/client/components/RailDispatch.js +22 -0
- package/lib/client/components/RailHost.js +79 -0
- package/lib/client/components/SearchBox.js +66 -0
- package/lib/client/components/SettingsPage.js +46 -0
- package/lib/client/components/StandaloneSettings.js +16 -0
- package/lib/client/components/codex/CodexRail.js +139 -0
- package/lib/client/components/deepseek/DeepseekRail.js +264 -0
- package/lib/client/components/minimal/MinimalRail.js +135 -0
- package/lib/client/components/minimal/cards.js +32 -0
- package/lib/client/components/minimal/dot.js +11 -0
- package/lib/client/components/minimal/hint.js +30 -0
- package/lib/client/components/minimal/paging.js +5 -0
- package/lib/client/components/minimal/quick-settings.js +28 -0
- package/lib/client/components/minimal/search.js +67 -0
- package/lib/client/components/minimal/useRail.js +716 -0
- package/lib/client/components/rail/cards.js +32 -0
- package/lib/client/components/rail/hint.js +30 -0
- package/lib/client/components/rail/paging.js +5 -0
- package/lib/client/components/rail/quick-settings.js +28 -0
- package/lib/client/components/rail/search.js +76 -0
- package/lib/client/components/rail/useRail.js +845 -0
- package/lib/client/components/settings/SettingsPage.js +46 -0
- package/lib/client/components/settings/SettingsTab.js +17 -0
- package/lib/client/components/settings/StandaloneSettings.js +16 -0
- package/lib/client/components/shared/Cascade.js +26 -0
- package/lib/client/components/shared/ConfigPanel.js +27 -0
- package/lib/client/components/shared/Dot.js +8 -0
- package/lib/client/components/shared/Hint.js +5 -0
- package/lib/client/components/shared/PagingButton.js +5 -0
- package/lib/client/components/shared/RailShell.js +78 -0
- package/lib/client/components/shared/SearchBox.js +63 -0
- package/lib/client/components/shared/hooks.js +427 -0
- package/lib/client/components/shared/types.js +1 -0
- package/lib/client/config.js +1 -0
- package/lib/client/engines/jump.js +34 -0
- package/lib/client/engines/useAtBottom.js +25 -0
- package/lib/client/engines/useJump.js +40 -0
- package/lib/client/engines/useScrollSpy.js +88 -0
- package/lib/client/hooks.js +11 -0
- package/lib/client/index.js +312 -0
- package/lib/client/jump.js +255 -0
- package/lib/client/locales.js +142 -0
- package/lib/client/pure.js +61 -0
- package/lib/client/settings.js +369 -0
- package/lib/client/virtual/VirtualList.js +21 -0
- package/lib/client.js +3213 -0
- package/lib/compat.js +145 -0
- package/lib/config.js +37 -0
- package/lib/core/active-dot.js +17 -0
- package/lib/core/align.js +9 -0
- package/lib/core/config.js +37 -0
- package/lib/core/focus.js +38 -0
- package/lib/core/jump.js +98 -0
- package/lib/core/logic/active-dot.js +16 -0
- package/lib/core/logic/focus.js +34 -0
- package/lib/core/logic/jump.js +188 -0
- package/lib/core/logic/nodes.js +59 -0
- package/lib/core/model/nav-item.js +1 -0
- package/lib/core/model/turns.js +73 -0
- package/lib/core/nav-item.js +1 -0
- package/lib/core/nodes.js +57 -0
- package/lib/core/page-size.js +7 -0
- package/lib/core/question-entry.js +1 -0
- package/lib/core/time.js +23 -0
- package/lib/core/turn-dots.js +85 -0
- package/lib/core/utils/measure.js +24 -0
- package/lib/core/utils/time.js +26 -0
- package/lib/index.js +64 -0
- package/lib/nav-item.js +1 -0
- package/lib/nodes.js +59 -0
- package/lib/projection.js +126 -0
- package/lib/schema.js +26 -0
- package/lib/search.js +285 -0
- package/lib/settings.js +89 -0
- package/lib/types/client/NavOverlay.d.ts +18 -0
- package/lib/types/client/NavRail.d.ts +7 -0
- package/lib/types/client/QuestionNavSettingsTab.d.ts +16 -0
- package/lib/types/client/QuestionNavStrip.d.ts +48 -0
- package/lib/types/client/components/ConfigPanel.d.ts +14 -0
- package/lib/types/client/components/DotRail.d.ts +15 -0
- package/lib/types/client/components/NavOverlay.d.ts +30 -0
- package/lib/types/client/components/NavRail.d.ts +16 -0
- package/lib/types/client/components/RailDispatch.d.ts +8 -0
- package/lib/types/client/components/RailHost.d.ts +27 -0
- package/lib/types/client/components/SearchBox.d.ts +9 -0
- package/lib/types/client/components/SettingsPage.d.ts +9 -0
- package/lib/types/client/components/StandaloneSettings.d.ts +13 -0
- package/lib/types/client/components/codex/CodexRail.d.ts +3 -0
- package/lib/types/client/components/deepseek/DeepseekRail.d.ts +3 -0
- package/lib/types/client/components/minimal/MinimalRail.d.ts +8 -0
- package/lib/types/client/components/minimal/cards.d.ts +19 -0
- package/lib/types/client/components/minimal/dot.d.ts +14 -0
- package/lib/types/client/components/minimal/hint.d.ts +11 -0
- package/lib/types/client/components/minimal/paging.d.ts +10 -0
- package/lib/types/client/components/minimal/quick-settings.d.ts +8 -0
- package/lib/types/client/components/minimal/search.d.ts +27 -0
- package/lib/types/client/components/minimal/useRail.d.ts +90 -0
- package/lib/types/client/components/rail/cards.d.ts +19 -0
- package/lib/types/client/components/rail/hint.d.ts +11 -0
- package/lib/types/client/components/rail/paging.d.ts +10 -0
- package/lib/types/client/components/rail/quick-settings.d.ts +8 -0
- package/lib/types/client/components/rail/search.d.ts +34 -0
- package/lib/types/client/components/rail/useRail.d.ts +132 -0
- package/lib/types/client/components/settings/SettingsPage.d.ts +9 -0
- package/lib/types/client/components/settings/SettingsTab.d.ts +6 -0
- package/lib/types/client/components/settings/StandaloneSettings.d.ts +13 -0
- package/lib/types/client/components/shared/Cascade.d.ts +14 -0
- package/lib/types/client/components/shared/ConfigPanel.d.ts +8 -0
- package/lib/types/client/components/shared/Dot.d.ts +17 -0
- package/lib/types/client/components/shared/Hint.d.ts +6 -0
- package/lib/types/client/components/shared/PagingButton.d.ts +10 -0
- package/lib/types/client/components/shared/RailShell.d.ts +43 -0
- package/lib/types/client/components/shared/SearchBox.d.ts +18 -0
- package/lib/types/client/components/shared/hooks.d.ts +64 -0
- package/lib/types/client/components/shared/types.d.ts +101 -0
- package/lib/types/client/config.d.ts +9 -0
- package/lib/types/client/engines/jump.d.ts +17 -0
- package/lib/types/client/engines/useAtBottom.d.ts +1 -0
- package/lib/types/client/engines/useJump.d.ts +16 -0
- package/lib/types/client/engines/useScrollSpy.d.ts +12 -0
- package/lib/types/client/hooks.d.ts +7 -0
- package/lib/types/client/index.d.ts +31 -0
- package/lib/types/client/jump.d.ts +47 -0
- package/lib/types/client/locales.d.ts +142 -0
- package/lib/types/client/pure.d.ts +21 -0
- package/lib/types/client/settings.d.ts +173 -0
- package/lib/types/client/virtual/VirtualList.d.ts +15 -0
- package/lib/types/compat.d.ts +44 -0
- package/lib/types/config.d.ts +44 -0
- package/lib/types/core/active-dot.d.ts +15 -0
- package/lib/types/core/align.d.ts +10 -0
- package/lib/types/core/config.d.ts +44 -0
- package/lib/types/core/focus.d.ts +24 -0
- package/lib/types/core/jump.d.ts +39 -0
- package/lib/types/core/logic/active-dot.d.ts +15 -0
- package/lib/types/core/logic/focus.d.ts +22 -0
- package/lib/types/core/logic/jump.d.ts +39 -0
- package/lib/types/core/logic/nodes.d.ts +48 -0
- package/lib/types/core/model/nav-item.d.ts +12 -0
- package/lib/types/core/model/turns.d.ts +30 -0
- package/lib/types/core/nav-item.d.ts +12 -0
- package/lib/types/core/nodes.d.ts +43 -0
- package/lib/types/core/page-size.d.ts +8 -0
- package/lib/types/core/question-entry.d.ts +12 -0
- package/lib/types/core/time.d.ts +4 -0
- package/lib/types/core/turn-dots.d.ts +29 -0
- package/lib/types/core/utils/measure.d.ts +12 -0
- package/lib/types/core/utils/time.d.ts +4 -0
- package/lib/types/index.d.ts +4 -0
- package/lib/types/nav-item.d.ts +12 -0
- package/lib/types/nodes.d.ts +48 -0
- package/lib/types/projection.d.ts +71 -0
- package/lib/types/schema.d.ts +37 -0
- package/lib/types/search.d.ts +42 -0
- package/lib/types/settings.d.ts +99 -0
- package/package.json +71 -0
- package/src/client/components/RailDispatch.tsx +27 -0
- package/src/client/components/codex/CodexRail.tsx +348 -0
- package/src/client/components/deepseek/DeepseekRail.tsx +522 -0
- package/src/client/components/minimal/MinimalRail.tsx +324 -0
- package/src/client/components/minimal/dot.tsx +32 -0
- package/src/client/components/rail/cards.tsx +102 -0
- package/src/client/components/rail/hint.tsx +50 -0
- package/src/client/components/rail/paging.tsx +26 -0
- package/src/client/components/rail/quick-settings.tsx +130 -0
- package/src/client/components/rail/search.tsx +147 -0
- package/src/client/components/rail/useRail.ts +906 -0
- package/src/client/components/settings/SettingsPage.tsx +198 -0
- package/src/client/components/settings/StandaloneSettings.tsx +28 -0
- package/src/client/components/shared/types.ts +99 -0
- package/src/client/index.ts +388 -0
- package/src/client/jump.ts +293 -0
- package/src/client/locales.ts +143 -0
- package/src/client/settings.ts +482 -0
- package/src/client/styles.css +1580 -0
- package/src/compat.ts +161 -0
- package/src/index.ts +66 -0
- package/src/projection.ts +174 -0
- package/src/search.ts +291 -0
- package/src/settings.ts +169 -0
|
@@ -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 ? 'mgcn-cardFav mgcn-cardFavOn' : 'mgcn-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' ? 'mgcn-cascade mgcn-cascadeRight' : 'mgcn-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
|
+
? 'mgcn-card mgcn-cardSelected' + (align === 'right' ? ' mgcn-cardSelectedRight' : '')
|
|
26
|
+
: 'mgcn-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: "mgcn-cardHead", children: [showFavorite ? favoriteButton(favorited, () => onToggleFavorite(dot.key)) : null, showTurn && isSelected && dot.turn !== null ? (_jsxs("div", { className: "mgcn-cardTitle", children: ["Turn ", dot.turn] })) : null, _jsx("div", { className: "mgcn-cardTime", children: clockText(dot.time, Date.now()) })] }), showDuration && dot.metrics !== undefined && isSelected ? (_jsx("div", { className: "mgcn-cardMetrics", children: metricsLine(dot.metrics) })) : null, _jsx("div", { className: isSelected ? 'mgcn-cardBody' : 'mgcn-cardClamp', style: isSelected
|
|
29
|
+
? undefined
|
|
30
|
+
: { WebkitLineClamp: metrics.maxLines, fontSize: metrics.fontSize }, children: text })] }, dot.key));
|
|
31
|
+
}) }), document.body);
|
|
32
|
+
}
|
|
@@ -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' ? 'mgcn-hint mgcn-hint--bottom' : 'mgcn-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: "mgcn-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 ? 'mgcn-navBtn mgcn-navUp' : 'mgcn-navBtn mgcn-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, MARK_TONE_OPTIONS, SHOW_OPTIONS, STYLE_CAPABILITIES } from "../../settings.js";
|
|
5
|
+
function Seg(props) {
|
|
6
|
+
return (_jsx("div", { className: "mgcn-segmented", role: "radiogroup", children: props.options.map((o) => (_jsx("button", { type: "button", role: "radio", "aria-checked": props.value === o, className: props.value === o ? 'mgcn-segment mgcn-segmentActive' : 'mgcn-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: "mgcn-config-panel", role: "dialog", "aria-label": t('config.title'), children: [_jsxs("div", { className: "mgcn-config-head", children: [_jsxs("span", { className: "mgcn-config-title", children: [t('config.style.' + injected.style()), " \u00B7 ", t('config.settings')] }), _jsx("button", { type: "button", className: "mgcn-config-close", "aria-label": t('config.close'), onClick: onClose, children: "\u2715" })] }), _jsxs("div", { className: "mgcn-config-row", children: [_jsx("span", { className: "mgcn-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: "mgcn-config-row", children: [_jsx("span", { className: "mgcn-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: "mgcn-config-row", children: [_jsx("span", { className: "mgcn-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, injected.style() === 'codex' ? (_jsxs("div", { className: "mgcn-config-row", children: [_jsx("span", { className: "mgcn-config-label", children: t('config.markTone') }), _jsx(Seg, { options: MARK_TONE_OPTIONS, value: injected.markTone(), labels: { soft: t('config.markTone.soft'), deep: t('config.markTone.deep') }, onPick: (v) => injected.setMarkTone(v) })] })) : null, _jsx("div", { className: "mgcn-config-sep" }), _jsxs("div", { className: "mgcn-config-row", children: [_jsx("span", { className: "mgcn-config-label", children: t('config.showQuickSettings') }), _jsx(ModeSeg, { value: injected.showQuickSettings(), onChange: (v) => injected.setShowQuickSettings(v), t: t })] }), _jsxs("div", { className: "mgcn-config-row", children: [_jsx("span", { className: "mgcn-config-label", children: t('config.showSearch') }), _jsx(ModeSeg, { value: injected.showSearch(), onChange: (v) => injected.setShowSearch(v), t: t })] }), _jsxs("div", { className: "mgcn-config-row", children: [_jsx("span", { className: "mgcn-config-label", children: t('config.showFavorites') }), _jsx(ModeSeg, { value: injected.showFavorites(), onChange: (v) => injected.setShowFavorites(v), t: t })] }), _jsxs("div", { className: "mgcn-config-row", children: [_jsx("span", { className: "mgcn-config-label", children: t('config.showCount') }), _jsx(ModeSeg, { value: injected.showCount(), onChange: (v) => injected.setShowCount(v), t: t })] }), STYLE_CAPABILITIES[injected.style()].paging ? (_jsxs("div", { className: "mgcn-config-row", children: [_jsx("span", { className: "mgcn-config-label", children: t('config.showPaging') }), _jsx(ModeSeg, { value: injected.showPaging(), onChange: (v) => injected.setShowPaging(v), t: t })] })) : null] }));
|
|
28
|
+
}
|
|
@@ -0,0 +1,76 @@
|
|
|
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
|
+
/**
|
|
7
|
+
* 检索 + 统一排序:host 按日志顺序返回,此处统一按轮次倒序(最新轮在上;
|
|
8
|
+
* 同轮按 seq 倒序——最新消息在前)。minimal/codex 浮层、deepseek 面板与移动抽屉共用,
|
|
9
|
+
* 保证三种风格与搜索抽屉的命中顺序一致。
|
|
10
|
+
*/
|
|
11
|
+
export function fetchHits(sessionId, query, scopes, signal) {
|
|
12
|
+
const url = '/mega-chat-nav/search?session=' + encodeURIComponent(sessionId ?? '')
|
|
13
|
+
+ '&q=' + encodeURIComponent(query)
|
|
14
|
+
+ '&scopes=' + encodeURIComponent(scopes.join(',')); // 不传 limit → host 返回全部命中
|
|
15
|
+
return fetch(url, { signal })
|
|
16
|
+
.then((resp) => resp.json())
|
|
17
|
+
.then((data) => {
|
|
18
|
+
const hits = data.ok === true ? (data.hits ?? []) : [];
|
|
19
|
+
return hits.sort((x, y) => (y.turn - x.turn) || (y.seq - x.seq));
|
|
20
|
+
});
|
|
21
|
+
}
|
|
22
|
+
/** 角色 → 标签文本(用户/助手/工具;steering 归用户侧) */
|
|
23
|
+
function roleTag(role, t) {
|
|
24
|
+
if (role === 'assistant')
|
|
25
|
+
return t('search.tag.assistant');
|
|
26
|
+
if (role === 'tool')
|
|
27
|
+
return t('search.tag.tool');
|
|
28
|
+
return t('search.tag.user');
|
|
29
|
+
}
|
|
30
|
+
export function SearchBox(props) {
|
|
31
|
+
const [query, setQuery] = useState('');
|
|
32
|
+
const [results, setResults] = useState([]);
|
|
33
|
+
const [busy, setBusy] = useState(false);
|
|
34
|
+
const abortRef = useRef(null);
|
|
35
|
+
const debounceRef = useRef(null);
|
|
36
|
+
const inputRef = useRef(null);
|
|
37
|
+
const run = useCallback((raw) => {
|
|
38
|
+
abortRef.current?.abort();
|
|
39
|
+
const ac = new AbortController();
|
|
40
|
+
abortRef.current = ac;
|
|
41
|
+
const q = raw.trim();
|
|
42
|
+
if (q.length < 1) {
|
|
43
|
+
setResults([]);
|
|
44
|
+
setBusy(false);
|
|
45
|
+
return;
|
|
46
|
+
}
|
|
47
|
+
setBusy(true);
|
|
48
|
+
fetchHits(props.sessionId, q, props.scopes, ac.signal)
|
|
49
|
+
.then((hits) => {
|
|
50
|
+
setResults(hits); // fetchHits 已按轮次倒序返回
|
|
51
|
+
})
|
|
52
|
+
.catch((e) => {
|
|
53
|
+
if (e.name !== 'AbortError')
|
|
54
|
+
setResults([]);
|
|
55
|
+
})
|
|
56
|
+
.finally(() => setBusy(false));
|
|
57
|
+
}, [props.sessionId, props.scopes]);
|
|
58
|
+
const onType = (value) => {
|
|
59
|
+
setQuery(value);
|
|
60
|
+
if (debounceRef.current !== null)
|
|
61
|
+
window.clearTimeout(debounceRef.current);
|
|
62
|
+
// 250ms 防抖:连续输入只触发一次检索
|
|
63
|
+
debounceRef.current = window.setTimeout(() => run(value), 250);
|
|
64
|
+
};
|
|
65
|
+
useEffect(() => {
|
|
66
|
+
inputRef.current?.focus();
|
|
67
|
+
return () => {
|
|
68
|
+
if (debounceRef.current !== null)
|
|
69
|
+
window.clearTimeout(debounceRef.current);
|
|
70
|
+
abortRef.current?.abort();
|
|
71
|
+
};
|
|
72
|
+
}, []);
|
|
73
|
+
const historicCount = results.filter((hit) => hit.historic).length;
|
|
74
|
+
return (_jsxs("div", { className: "mgcn-search", role: "dialog", "aria-label": props.t('search.placeholder'), children: [_jsx("input", { ref: inputRef, className: "mgcn-search-input", value: query, placeholder: props.t('search.placeholder'), onChange: (e) => onType(e.target.value), onKeyDown: (e) => { if (e.key === 'Escape')
|
|
75
|
+
props.onClose(); } }), busy ? _jsx("div", { className: "mgcn-search-busy", children: "\u2026" }) : null, !busy && query.trim() === '' && props.emptyContent !== undefined ? props.emptyContent : null, !busy && results.length > 0 && historicCount > 0 ? (_jsx("div", { className: "mgcn-search-historic", children: props.t('search.historic', { n: historicCount }) })) : null, results.length > 0 ? (_jsx("div", { className: "mgcn-search-results", children: results.map((hit) => (_jsxs("button", { type: "button", className: "mgcn-search-hit", onClick: () => props.onJump(hit.key, hit.seq), children: [_jsxs("span", { className: "mgcn-search-title", children: [_jsxs("span", { className: "mgcn-search-titleLeft", children: [hit.turn > 0 ? _jsx("span", { className: "mgcn-search-turn", children: props.t('search.turnTitle', { turn: hit.turn }) }) : null, _jsx("span", { className: 'mgcn-search-tag mgcn-search-tag--' + hit.role, children: roleTag(hit.role, props.t) })] }), _jsx("span", { className: "mgcn-search-titleTime", children: clockText(hit.time, Date.now()) })] }), _jsx("span", { className: "mgcn-search-body", children: _jsx("span", { className: "mgcn-search-text", 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 }) })] }, hit.key + ':' + hit.seq))) })) : null] }));
|
|
76
|
+
}
|