agent-loft 0.2.51 → 0.2.53

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.
@@ -5,15 +5,23 @@ import { userScrolled } from "./messages.js";
5
5
  // ---------- 消息区右边的快速定位(像网页版 ChatGPT) ----------
6
6
  // 每条用户消息一道短横线,竖着排在滚动条旁边,正看到的那条高亮;平时淡淡的,滚动时清楚些。
7
7
  // 鼠标移上去展开成列表,显示每条消息的开头,点一下跳过去。用户消息少于 3 条时不显示。
8
- // 手机只在滚动和操作刻度时显示,停止后自动隐藏,点刻度直接跳转。
8
+ // 手机用短轨道定位:按住拖动预览问题,松手跳转;只在手动滚动和操作时显示。
9
9
 
10
10
  const MIN_USERS = 3;
11
+ const HIDE_DELAY = 1600;
12
+ const compact = matchMedia("(max-width: 768px), (hover: none)");
11
13
  let entries = [];
12
14
  let activeIdx = -1;
13
15
  let scheduled = false;
14
16
  let scrollRaf = 0;
15
17
  let scrollingTimer = 0;
16
18
  let builtFor = null;
19
+ let scrubbing = null;
20
+
21
+ compact.addEventListener("change", () => {
22
+ resetScrolling();
23
+ updateActive();
24
+ });
17
25
 
18
26
  export function createNav() {
19
27
  resetScrolling();
@@ -21,7 +29,17 @@ export function createNav() {
21
29
  entries = [];
22
30
  ui.navTicks = h("div", { class: "msg-nav-ticks" });
23
31
  ui.navPanel = h("div", { class: "msg-nav-panel" });
24
- ui.nav = h("nav", { class: "msg-nav", hidden: true, "aria-label": "消息快速定位", onpointerenter: revealActiveRow, onpointerdown: markScrolling }, ui.navTicks, ui.navPanel);
32
+ ui.navTrack = h("div", { class: "msg-nav-track", "aria-hidden": "true" });
33
+ ui.navRail = h("div", {
34
+ class: "msg-nav-rail", role: "slider", tabindex: "0", "aria-label": "拖动定位用户消息", "aria-orientation": "vertical", "aria-valuemin": "1",
35
+ onpointerdown: startScrubbing, onpointermove: moveScrubbing, onpointerup: finishScrubbing,
36
+ onpointercancel: cancelPointer, onlostpointercapture: cancelPointer, onkeydown: onRailKey,
37
+ onfocus: markScrolling, onblur: markScrolling,
38
+ }, ui.navTrack);
39
+ ui.navCount = h("span", { class: "msg-nav-count" });
40
+ ui.navSnippet = h("span", { class: "msg-nav-snippet" });
41
+ const preview = h("div", { class: "msg-nav-preview", "aria-hidden": "true" }, ui.navCount, ui.navSnippet);
42
+ ui.nav = h("nav", { class: "msg-nav", hidden: true, "aria-label": "消息快速定位", onpointerenter: revealActiveRow, onpointerdown: markScrolling }, ui.navTicks, ui.navPanel, ui.navRail, preview);
25
43
  ui.navTicks.addEventListener("scroll", () => {
26
44
  if (ui.nav.classList.contains("scrolling")) markScrolling();
27
45
  }, { passive: true });
@@ -50,6 +68,10 @@ function build() {
50
68
  if (!ui.nav) return;
51
69
  const users = S.view ? [] : S.items.filter((it) => it.type === "user" && it.el?.isConnected);
52
70
  if (builtFor !== S.current || users.length < MIN_USERS) resetScrolling();
71
+ else if (scrubbing) {
72
+ cancelScrubbing();
73
+ markScrolling();
74
+ }
53
75
  builtFor = S.current;
54
76
  ui.nav.hidden = users.length < MIN_USERS;
55
77
  activeIdx = -1;
@@ -57,18 +79,27 @@ function build() {
57
79
  entries = [];
58
80
  ui.navTicks.replaceChildren();
59
81
  ui.navPanel.replaceChildren();
82
+ ui.navTrack.replaceChildren();
60
83
  return;
61
84
  }
62
85
  entries = users.map((item, i) => {
63
86
  const label = snippet(item);
64
87
  return {
65
88
  item,
89
+ label,
66
90
  tick: h("button", { class: "msg-nav-tick", "aria-label": `第 ${i + 1} 条:${label}`, onclick: () => jump(item) }, h("i")),
67
91
  row: h("button", { class: "msg-nav-row", onclick: () => jump(item) }, label),
68
92
  };
69
93
  });
70
94
  ui.navTicks.replaceChildren(...entries.map((e) => e.tick));
71
95
  ui.navPanel.replaceChildren(...entries.map((e) => e.row));
96
+ const marks = Math.min(entries.length, 9);
97
+ ui.navRail.style.setProperty("--nav-rail-height", `${Math.min(156, 56 + (marks - 1) * 16)}px`);
98
+ ui.navTrack.replaceChildren(
99
+ ...Array.from({ length: marks }, (_, i) => h("i", { class: `msg-nav-mark${i % 2 === 0 ? " major" : ""}`, style: { top: `${i / (marks - 1) * 100}%` } })),
100
+ h("span", { class: "msg-nav-thumb" }),
101
+ );
102
+ ui.navRail.setAttribute("aria-valuemax", String(entries.length));
72
103
  updateActive();
73
104
  }
74
105
 
@@ -78,12 +109,13 @@ function covered() {
78
109
  }
79
110
 
80
111
  function jump(item) {
81
- if (!item.el?.isConnected) return;
112
+ if (!item?.el?.isConnected) return;
82
113
  userScrolled();
83
114
  ui.messages.scrollTo({ top: Math.max(0, item.el.offsetTop - covered() - 12), behavior: "smooth" });
84
115
  }
85
116
 
86
117
  function resetScrolling() {
118
+ cancelScrubbing();
87
119
  clearTimeout(scrollingTimer);
88
120
  cancelAnimationFrame(scrollRaf);
89
121
  scrollRaf = 0;
@@ -94,12 +126,17 @@ function markScrolling() {
94
126
  if (!entries.length) return;
95
127
  ui.nav.classList.add("scrolling");
96
128
  clearTimeout(scrollingTimer);
97
- scrollingTimer = setTimeout(() => ui.nav.classList.remove("scrolling"), 1200);
129
+ if (scrubbing) return;
130
+ scrollingTimer = setTimeout(() => {
131
+ if (compact.matches && document.activeElement === ui.navRail) return;
132
+ ui.nav.classList.remove("scrolling");
133
+ }, HIDE_DELAY);
98
134
  }
99
135
 
100
136
  function onScroll() {
101
137
  if (!entries.length) return;
102
- markScrolling();
138
+ // 自动跟随模型回复时不打扰阅读;手动滚动才唤出手机上的轨道。
139
+ if (!compact.matches || ui.follow === false) markScrolling();
103
140
  if (scrollRaf) return;
104
141
  scrollRaf = requestAnimationFrame(() => {
105
142
  scrollRaf = 0;
@@ -109,7 +146,7 @@ function onScroll() {
109
146
 
110
147
  /** 正看到的:顶部往下三分之一处以上、最后一条用户消息;已经滚到底就是最后一条 */
111
148
  function updateActive() {
112
- if (!entries.length) return;
149
+ if (!entries.length || scrubbing) return;
113
150
  const m = ui.messages;
114
151
  const line = m.scrollTop + covered() + m.clientHeight * 0.3;
115
152
  let idx = 0;
@@ -120,13 +157,80 @@ function updateActive() {
120
157
  else break;
121
158
  }
122
159
  }
160
+ selectEntry(idx);
161
+ }
162
+
163
+ function selectEntry(idx) {
164
+ const entry = entries[idx];
165
+ if (!entry) return;
166
+ ui.nav.style.setProperty("--nav-progress", String(idx / (entries.length - 1)));
167
+ ui.navRail.setAttribute("aria-valuenow", String(idx + 1));
168
+ ui.navRail.setAttribute("aria-valuetext", `第 ${idx + 1} 条,共 ${entries.length} 条:${entry.label}`);
169
+ ui.navCount.textContent = `${idx + 1} / ${entries.length}`;
170
+ ui.navSnippet.textContent = entry.label;
123
171
  if (idx === activeIdx) return;
124
172
  entries[activeIdx]?.tick.classList.remove("on");
125
173
  entries[activeIdx]?.row.classList.remove("on");
126
174
  activeIdx = idx;
127
175
  entries[idx].tick.classList.add("on");
128
176
  entries[idx].row.classList.add("on");
129
- keepVisible(ui.navTicks, entries[idx].tick);
177
+ if (!compact.matches) keepVisible(ui.navTicks, entries[idx].tick);
178
+ }
179
+
180
+ function scrubTo(clientY) {
181
+ const rect = ui.navTrack.getBoundingClientRect();
182
+ if (!rect.height) return;
183
+ const fraction = Math.max(0, Math.min(1, (clientY - rect.top) / rect.height));
184
+ scrubbing.index = Math.round(fraction * (entries.length - 1));
185
+ selectEntry(scrubbing.index);
186
+ }
187
+
188
+ function startScrubbing(e) {
189
+ if (!compact.matches || !entries.length || e.button !== 0 || scrubbing) return;
190
+ e.preventDefault();
191
+ scrubbing = { pointerId: e.pointerId, index: activeIdx, key: S.current };
192
+ ui.navRail.setPointerCapture(e.pointerId);
193
+ ui.nav.classList.add("scrubbing");
194
+ markScrolling();
195
+ scrubTo(e.clientY);
196
+ }
197
+
198
+ function moveScrubbing(e) {
199
+ if (scrubbing?.pointerId !== e.pointerId) return;
200
+ scrubTo(e.clientY);
201
+ }
202
+
203
+ function finishScrubbing(e) {
204
+ if (scrubbing?.pointerId !== e.pointerId) return;
205
+ scrubTo(e.clientY);
206
+ const target = scrubbing;
207
+ cancelScrubbing();
208
+ if (target.key === S.current) jump(entries[target.index]?.item);
209
+ markScrolling();
210
+ }
211
+
212
+ function cancelScrubbing() {
213
+ const pointerId = scrubbing?.pointerId;
214
+ scrubbing = null;
215
+ ui.nav?.classList.remove("scrubbing");
216
+ if (pointerId !== undefined && ui.navRail?.hasPointerCapture(pointerId)) ui.navRail.releasePointerCapture(pointerId);
217
+ updateActive();
218
+ }
219
+
220
+ function cancelPointer(e) {
221
+ if (scrubbing?.pointerId !== e.pointerId) return;
222
+ cancelScrubbing();
223
+ markScrolling();
224
+ }
225
+
226
+ function onRailKey(e) {
227
+ const delta = { ArrowUp: -1, ArrowLeft: -1, ArrowDown: 1, ArrowRight: 1, PageUp: -5, PageDown: 5 }[e.key];
228
+ if (!entries.length || (delta === undefined && e.key !== "Home" && e.key !== "End")) return;
229
+ e.preventDefault();
230
+ const idx = e.key === "Home" ? 0 : e.key === "End" ? entries.length - 1 : Math.max(0, Math.min(entries.length - 1, activeIdx + delta));
231
+ selectEntry(idx);
232
+ jump(entries[idx].item);
233
+ markScrolling();
130
234
  }
131
235
 
132
236
  /** 横线太多、竖条装不下时它自己能滚:让高亮的那道留在看得见的地方(不用 scrollIntoView,免得把外层也带着滚) */
@@ -138,6 +242,7 @@ function keepVisible(box, el) {
138
242
 
139
243
  /** 展开列表时:列表滚到正看到的那条 */
140
244
  function revealActiveRow() {
245
+ if (compact.matches) return;
141
246
  const row = entries[activeIdx]?.row;
142
247
  if (row) ui.navPanel.scrollTop = Math.max(0, row.offsetTop - ui.navPanel.clientHeight / 2);
143
248
  }
@@ -475,12 +475,11 @@ export function renderSidebar() {
475
475
  onclick: () => open(c.key),
476
476
  },
477
477
  orphan ? h("span", { class: "brand-icon lead fork-mark", html: ICON.fork }) : null,
478
- // 定时任务的专用对话
479
- c.taskId ? h("span", { class: "brand-icon lead task-mark", title: "定时任务的对话", html: ICON.clock }) : null,
480
478
  h("span", { class: "title" }, convTitle(c)),
481
- convExpertMark(c),
482
479
  fold ? caret(fold.folded, fold.toggle) : null,
483
480
  status(fold?.folded ? fold.keys : [c.key]),
481
+ convExpertMark(c),
482
+ c.taskId ? h("span", { class: "brand-icon task-mark", title: "定时任务的对话", html: ICON.clock }) : null,
484
483
  );
485
484
 
486
485
  const nodes = [];
@@ -502,8 +501,8 @@ export function renderSidebar() {
502
501
  },
503
502
  h("span", { class: "brand-icon lead", title: "飞书", html: ICON.feishu }),
504
503
  h("span", { class: "title" }, bot.name),
505
- convExpertMark(latest),
506
504
  status(convs.map((c) => c.key)),
505
+ convExpertMark(latest),
507
506
  ),
508
507
  });
509
508
  }