@ququ-jiaxk/dsh-groupchat 0.1.4 → 0.1.5

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 (2) hide show
  1. package/client.js +118 -3
  2. package/package.json +1 -1
package/client.js CHANGED
@@ -350,6 +350,26 @@ window.__ModuleLoader__.load({
350
350
  }
351
351
  })()
352
352
 
353
+ // ---- 群聊面板是否处于激活态 ----
354
+ // DSH 的 main 插槽只挂载当前面板:切到别的面板/会话时 GroupchatPanel 会卸载。
355
+ // 所以用「面板挂载 = 激活」来驱动侧栏入口的高亮,不依赖内部 layout store。
356
+ const panelActiveStore = (() => {
357
+ let value = false
358
+ const listeners = new Set()
359
+ return {
360
+ get: () => value,
361
+ set: (next) => {
362
+ if (next === value) return
363
+ value = next
364
+ for (const l of listeners) l()
365
+ },
366
+ subscribe: (listener) => {
367
+ listeners.add(listener)
368
+ return () => listeners.delete(listener)
369
+ },
370
+ }
371
+ })()
372
+
353
373
  // ---- 面板记忆(跨卸载保留 UI 状态) ----
354
374
  // 用户切到别的界面/会话时 GroupchatPanel 会卸载,React state 全部丢失,
355
375
  // 再回来就"重新加载"(回到列表、草稿没了、滚动回顶部)。
@@ -1054,7 +1074,13 @@ window.__ModuleLoader__.load({
1054
1074
 
1055
1075
  // ---- 主面板 ----
1056
1076
  function GroupchatPanel() {
1057
- // 数据来自全局 stateStore(由 globalPoll 驱动),面板不再自己轮询
1077
+ // 挂载 = 群聊面板被选中(DSH 的 main 插槽只挂载当前面板),用于侧栏入口高亮
1078
+ useEffect(() => {
1079
+ panelActiveStore.set(true)
1080
+ return () => panelActiveStore.set(false)
1081
+ }, [])
1082
+
1083
+ // 数据来自全局 stateStore(由全局轮询驱动),面板不再自己轮询
1058
1084
  const [state, setState] = useState(() => stateStore.get())
1059
1085
  // 视图从模块级记忆恢复:切走再切回仍停留在原来的群/标签页
1060
1086
  const [view, setViewRaw] = useState(() => panelMemo.view || 'list') // 'list' | 'create' | 'roster' | 'createProfile' | groupId
@@ -3312,6 +3338,93 @@ window.__ModuleLoader__.load({
3312
3338
  }
3313
3339
 
3314
3340
  // ---- 侧栏图标(带未读角标) ----
3341
+ /**
3342
+ * 侧栏「群聊」入口按钮:与「新会话」并排(`sidebar.session.action` 槽位)。
3343
+ *
3344
+ * 两个约束(都踩过):
3345
+ * 1. 该槽位会把默认的「新会话」按钮作为 children 传进来,必须原样渲染,否则新会话消失。
3346
+ * 2. 那一行是横向 flex,新会话靠 flex:1 占位;我们的按钮**不能设 width:100%**,
3347
+ * 否则会把新会话挤成 0 宽。用自适应宽度 + flexShrink:0,新会话会自然收窄,两者并排。
3348
+ */
3349
+ function GroupchatEntryButton(props) {
3350
+ const wide = !!(props && props.wide)
3351
+ const children = props ? props.children : null
3352
+ const [unread, setUnread] = useState(0)
3353
+ const [active, setActive] = useState(() => panelActiveStore.get())
3354
+ useEffect(() => {
3355
+ const unsubscribe = unreadStore.subscribe(() => setUnread(unreadStore.get()))
3356
+ setUnread(unreadStore.get())
3357
+ return unsubscribe
3358
+ }, [])
3359
+ useEffect(() => {
3360
+ const unsubscribe = panelActiveStore.subscribe(() => setActive(panelActiveStore.get()))
3361
+ setActive(panelActiveStore.get())
3362
+ return unsubscribe
3363
+ }, [])
3364
+ const open = () => {
3365
+ const layout = layoutRef.current
3366
+ if (layout && typeof layout.selectPanel === 'function') layout.selectPanel(PANEL_ID)
3367
+ }
3368
+ // 选中态:主色底 + 主色文字(和其他面板选中时一致的感觉)
3369
+ // 默认态:和「新会话」完全一致(同一套变量、同圆角、同高度、同字号)
3370
+ const idleBg = 'var(--dsw-alias-fill-secondary, rgba(16,41,66,0.05))'
3371
+ const idleColor = 'var(--dsw-alias-label-primary, #102942)'
3372
+ // 激活态:主色实底 + 白字,一眼能看出当前就在群聊
3373
+ const activeBg = 'var(--dsw-alias-accent, #2E6BE6)'
3374
+ const activeColor = '#fff'
3375
+ return h(React.Fragment, null,
3376
+ children,
3377
+ h('button', {
3378
+ type: 'button',
3379
+ 'aria-label': '群聊',
3380
+ 'aria-current': active ? 'page' : undefined,
3381
+ title: '群聊',
3382
+ onClick: open,
3383
+ style: {
3384
+ display: 'flex', alignItems: 'center', justifyContent: 'center',
3385
+ gap: wide ? 6 : 0,
3386
+ height: 34, boxSizing: 'border-box',
3387
+ padding: wide ? '0 6px' : 0,
3388
+ // 高度/圆角/配色与新会话一致;宽度按内容,避免把新会话压成两行
3389
+ flex: '0 0 auto', minWidth: 0, whiteSpace: 'nowrap',
3390
+ border: 'none', cursor: 'pointer',
3391
+ borderRadius: 'var(--dsw-radius-md, 10px)',
3392
+ background: active ? activeBg : idleBg,
3393
+ color: active ? activeColor : idleColor,
3394
+ fontSize: 13, fontWeight: active ? 600 : 500, fontFamily: 'inherit',
3395
+ transition: 'background .15s ease, color .15s ease',
3396
+ },
3397
+ onMouseEnter: (e) => { if (!active) e.currentTarget.style.background = 'var(--dsw-alias-fill-tertiary, rgba(16,41,66,0.09))' },
3398
+ onMouseLeave: (e) => { e.currentTarget.style.background = active ? activeBg : idleBg },
3399
+ onMouseDown: (e) => { if (active) e.currentTarget.style.filter = 'brightness(0.94)' },
3400
+ onMouseUp: (e) => { e.currentTarget.style.filter = 'none' },
3401
+ },
3402
+ h('span', { style: { position: 'relative', display: 'flex', flexShrink: 0 } },
3403
+ h('svg', { width: 16, height: 16, viewBox: '0 0 18 18', fill: 'none', stroke: 'currentColor', strokeWidth: 1.7, strokeLinecap: 'round', strokeLinejoin: 'round' },
3404
+ h('circle', { cx: 6, cy: 7.5, r: 2.2 }),
3405
+ h('circle', { cx: 12, cy: 7.5, r: 2.2 }),
3406
+ h('path', { d: 'M2.5 14.5c0-1.9 1.3-3.2 3.3-3.2h1.4M15.5 14.5c0-1.9-1.3-3.2-3.3-3.2h-1.4' }),
3407
+ ),
3408
+ unread > 0 && !wide ? h('span', {
3409
+ style: {
3410
+ position: 'absolute', top: -3, right: -5, minWidth: 13, height: 13, borderRadius: 999,
3411
+ background: '#C0392B', color: '#fff', fontSize: 8, fontWeight: 700,
3412
+ display: 'flex', alignItems: 'center', justifyContent: 'center', padding: '0 3px',
3413
+ },
3414
+ }, unread > 99 ? '99+' : String(unread)) : null,
3415
+ ),
3416
+ wide ? h('span', { style: { whiteSpace: 'nowrap', overflow: 'hidden', textOverflow: 'ellipsis' } }, '群聊') : null,
3417
+ unread > 0 && wide ? h('span', {
3418
+ style: {
3419
+ minWidth: 16, height: 16, borderRadius: 999, background: '#C0392B', color: '#fff',
3420
+ fontSize: 9, fontWeight: 700, display: 'flex', alignItems: 'center',
3421
+ justifyContent: 'center', padding: '0 4px', flexShrink: 0,
3422
+ },
3423
+ }, unread > 99 ? '99+' : String(unread)) : null,
3424
+ ),
3425
+ )
3426
+ }
3427
+
3315
3428
  function GroupchatIcon() {
3316
3429
  const [unread, setUnread] = useState(0)
3317
3430
  useEffect(() => {
@@ -3419,8 +3532,10 @@ window.__ModuleLoader__.load({
3419
3532
  return () => { clearInterval(globalPollTimer); globalPollTimer = null }
3420
3533
  }, 'groupchat: global poll')
3421
3534
 
3422
- ctx.slots.inject('sidebar.panellist', () =>
3423
- ctx.slots.register({ name: 'sidebar.panellist', id: PANEL_ID, order: 30, label: () => '群聊', locale: NS }, GroupchatIcon),
3535
+ // 侧栏入口:与「新会话」并排(sidebar.session.action 槽位)。
3536
+ // 该槽位是横向 flex 行,我们注册一个自适应宽度的按钮,新会话会随之收窄,两者并排。
3537
+ ctx.slots.inject('sidebar.session.action', () =>
3538
+ ctx.slots.register({ name: 'sidebar.session.action', id: PANEL_ID, locale: NS }, GroupchatEntryButton),
3424
3539
  )
3425
3540
  ctx.slots.inject('main', function* () {
3426
3541
  yield ctx.slots.register({ name: 'main', key: PANEL_ID }, GroupchatPanel)
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@ququ-jiaxk/dsh-groupchat",
3
- "version": "0.1.4",
3
+ "version": "0.1.5",
4
4
  "type": "module",
5
5
  "description": "DSH 群聊插件:把已有会话作为固定角色的智能体拉进项目群,由项目经理 agent(sAgent)聚合、推进、排人、汇报。",
6
6
  "exports": {