dsh-better-sidebar-left 0.2.0 → 0.3.0

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/src/client.js CHANGED
@@ -62,7 +62,7 @@ window.__ModuleLoader__.load({
62
62
  dropHint: '拖到这里删除',
63
63
  dropRelease: '松手删除「{name}」',
64
64
  dropFallback: '这个对话',
65
- starAsk: '⭐ 顺手留颗 Star,作者能高兴一整天',
65
+ starAsk: '顺手留颗 Star,作者能高兴一整天',
66
66
  starCta: '行,给你一颗 Star',
67
67
  pageSyncChildrenOn: '删除对话时,把它派生的子代理会话一起删掉。',
68
68
  pageSyncChildrenOff: '不勾选时,删除前会列出子会话,由你勾选要删哪些。',
@@ -180,7 +180,7 @@ window.__ModuleLoader__.load({
180
180
  dropHint: 'Drop here to delete',
181
181
  dropRelease: 'Release to delete \'{name}\'',
182
182
  dropFallback: 'this conversation',
183
- starAsk: '⭐ A star would make the author\'s day',
183
+ starAsk: 'A star would make the author\'s day',
184
184
  starCta: 'Fine — have one',
185
185
  pageSyncChildrenOn: 'A delete also removes the subagent sessions it spawned.',
186
186
  pageSyncChildrenOff: 'When off, the dialog lists the child sessions and you tick the ones to delete.',
@@ -295,7 +295,7 @@ window.__ModuleLoader__.load({
295
295
  dropHint: 'Перетащите сюда, чтобы удалить',
296
296
  dropRelease: 'Отпустите, чтобы удалить «{name}»',
297
297
  dropFallback: 'этот диалог',
298
- starAsk: '⭐ Звёздочка на GitHub сделает автору день',
298
+ starAsk: 'Звёздочка на GitHub сделает автору день',
299
299
  starCta: 'Ладно, держи звезду',
300
300
  pageSyncChildrenOn: 'Удаление сессии удаляет и порождённые ею сессии субагентов.',
301
301
  pageSyncChildrenOff: 'Если выключено, перед удалением появится список дочерних сессий и вы отметите, какие удалить.',
@@ -1119,6 +1119,16 @@ window.__ModuleLoader__.load({
1119
1119
  '.dsdel-field:hover{background:var(--dsdel-bg-hover)}',
1120
1120
  '.dsdel-field:focus-within{outline:2px solid var(--dsdel-ring);outline-offset:1px}',
1121
1121
  '.dsdel-page-hint{margin:0;color:var(--dsdel-label-faint);font-size:12.5px;line-height:19px;letter-spacing:.01em}',
1122
+ '.dsdel-setting{display:flex;align-items:flex-start;gap:12px;padding:2px 0}',
1123
+ '.dsdel-setting-text{display:flex;flex-direction:column;gap:2px;min-width:0}',
1124
+ '.dsdel-setting-title{font-size:13px;line-height:20px;color:var(--dsdel-label)}',
1125
+ '.dsdel-setting-desc{font-size:12px;line-height:18px;color:var(--dsdel-label-faint)}',
1126
+ '.dsdel-switch{position:relative;flex:none;width:38px;height:22px;margin-left:auto;border:0;border-radius:11px;padding:0;cursor:pointer;background:rgba(127,127,127,.4);transition:background .12s ease}',
1127
+ '.dsdel-switch[aria-checked="true"]{background:#4c8dff}',
1128
+ '.dsdel-switch::after{content:"";position:absolute;top:2px;left:2px;width:18px;height:18px;border-radius:50%;background:#fff;transition:left .15s ease}',
1129
+ '.dsdel-switch[aria-checked="true"]::after{left:18px}',
1130
+ '.dsdel-switch:focus-visible{outline:2px solid var(--dsdel-ring);outline-offset:2px}',
1131
+ '@media (prefers-reduced-motion:reduce){.dsdel-switch,.dsdel-switch::after{transition:none}}',
1122
1132
  // One produced file per row: tick on the left, path in the middle, a folder
1123
1133
  // button on the right. The button sits outside the label so a click opens
1124
1134
  // the folder instead of toggling the tick.
@@ -1130,8 +1140,11 @@ window.__ModuleLoader__.load({
1130
1140
  '.dsdel-file-open:hover{background:var(--dsdel-bg);border-color:var(--dsdel-border);color:var(--dsdel-label)}',
1131
1141
  '.dsdel-file-open:focus-visible{outline:2px solid var(--dsdel-ring);outline-offset:1px}',
1132
1142
  '.dsdel-file-remove:hover{background:color-mix(in srgb,var(--dsdel-danger) 12%,transparent);border-color:color-mix(in srgb,var(--dsdel-danger) 40%,transparent);color:var(--dsdel-danger)}',
1133
- '.dsdel-star{display:flex;align-items:center;justify-content:flex-end;gap:8px;flex-wrap:wrap;font-size:12px;color:var(--dsw-alias-label-tertiary,#8b93a1);padding:2px 2px 0;}',
1134
- '.dsdel-star-link{color:var(--dsw-alias-brand-primary,#4d76e6);text-decoration:underline;}',
1143
+ '.dsdel-star{display:flex;align-items:center;gap:8px;flex-wrap:wrap;margin-top:6px;padding:8px 10px;border-radius:8px;border:1px solid rgba(0,0,0,.08);background:rgba(255,196,0,.06);color:inherit;text-decoration:none;font-size:12px;line-height:1.4}',
1144
+ '.dsdel-star:hover{background:rgba(255,196,0,.14)}',
1145
+ '.dsdel-star-icon{font-size:14px;line-height:1}',
1146
+ '.dsdel-star-cta{margin-left:auto;color:#8a6d00;font-weight:600}',
1147
+ '@media (prefers-color-scheme: dark){.dsdel-star{border-color:rgba(255,255,255,.12);background:rgba(255,196,0,.08)}.dsdel-star-cta{color:#e8c15a}}',
1135
1148
  '.dsdel-root-input{flex:1 1 220px;min-width:160px;min-height:30px;padding:0 10px;border:1px solid var(--dsw-alias-border-secondary,#d0d0d0);border-radius:6px;background:transparent;color:inherit;font:inherit;font-size:13px}',
1136
1149
  '.dsdel-picker-path{margin:0 0 8px;font-size:12px;line-height:1.6;color:var(--dsw-alias-label-secondary,#666);word-break:break-all}',
1137
1150
  // A wider confirmation dialog: the class reaches it when `Modal` forwards
@@ -2917,6 +2930,31 @@ window.__ModuleLoader__.load({
2917
2930
  // configure arrow once the bundle registers its own row.config entry (key
2918
2931
  // `<bundle package>#<row id>`). The card carries the one setting the dialog
2919
2932
  // also exposes: whether a session delete asks first.
2933
+ /**
2934
+ * One setting the way relocate's page draws it: the title and its explanation on
2935
+ * the left, the control on the right. A checkbox row reads as a form; a switch
2936
+ * with two lines of copy reads as a setting, which is what these are.
2937
+ *
2938
+ * @param options - { key, title, desc, descKey, checked, onChange }.
2939
+ */
2940
+ function settingRow(options) {
2941
+ const checked = options.checked === true
2942
+ return h('div', { key: 'row:' + options.key, className: 'dsdel-setting' },
2943
+ h('div', { key: 'text', className: 'dsdel-setting-text' },
2944
+ h('div', { key: 'title', className: 'dsdel-setting-title' }, options.title),
2945
+ h('div', { key: options.descKey === undefined ? 'desc' : options.descKey, className: 'dsdel-setting-desc' }, options.desc)),
2946
+ h('button', {
2947
+ key: options.key,
2948
+ type: 'button',
2949
+ role: 'switch',
2950
+ className: 'dsdel-switch',
2951
+ 'aria-checked': checked ? 'true' : 'false',
2952
+ 'aria-label': options.title,
2953
+ onChange: options.onChange,
2954
+ onClick: () => options.onChange(!checked),
2955
+ }))
2956
+ }
2957
+
2920
2958
  function AskBeforeDeleteOption({ view, t: injected }) {
2921
2959
  // Unlike the menu rows and the dialog, this entry is registered without a
2922
2960
  // `locale`, so the host injects no `t` here. Falling back to the
@@ -2953,66 +2991,68 @@ window.__ModuleLoader__.load({
2953
2991
  }
2954
2992
 
2955
2993
  const children = [
2956
- h(primitives.Checkbox, {
2994
+ settingRow({
2957
2995
  key: 'ask',
2996
+ title: translate('pageAsk'),
2997
+ descKey: 'askHint',
2998
+ desc:
2999
+ // Ask mode needs the dialog for its file list, so "delete straight away"
3000
+ // would be a promise this combination does not keep.
3001
+ translate(ask ? 'pageHintAsk' : (!off && !auto ? 'pageHintAutoWithArtifacts' : 'pageHintAuto')),
2958
3002
  checked: ask,
2959
- label: translate('pageAsk'),
2960
3003
  onChange: (checked) => {
2961
3004
  setAsk(checked === true)
2962
3005
  setSkipConfirm(checked !== true)
2963
3006
  },
2964
3007
  }),
2965
- h('p', { key: 'askHint', className: 'dsdel-page-hint' },
2966
- // Ask mode needs the dialog for its file list, so "delete straight away"
2967
- // would be a promise this combination does not keep.
2968
- translate(ask ? 'pageHintAsk' : (!off && !auto ? 'pageHintAutoWithArtifacts' : 'pageHintAuto'))),
2969
3008
 
2970
- h(primitives.Checkbox, {
3009
+ settingRow({
2971
3010
  key: 'recycle',
3011
+ title: translate('pageRecycle'),
3012
+ descKey: 'recycleHint',
3013
+ desc: translate(recycle ? 'pageRecycleOn' : 'pageRecycleOff'),
2972
3014
  checked: recycle,
2973
- label: translate('pageRecycle'),
2974
3015
  onChange: (checked) => {
2975
3016
  setRecycle(checked === true)
2976
3017
  setRecycleSession(checked === true)
2977
3018
  },
2978
3019
  }),
2979
- h('p', { key: 'recycleHint', className: 'dsdel-page-hint' },
2980
- translate(recycle ? 'pageRecycleOn' : 'pageRecycleOff')),
2981
3020
 
2982
- h(primitives.Checkbox, {
3021
+ settingRow({
2983
3022
  key: 'syncChildren',
3023
+ title: translate('pageSyncChildren'),
3024
+ descKey: 'syncChildrenHint',
3025
+ desc: translate(syncChildrenState ? 'pageSyncChildrenOn' : 'pageSyncChildrenOff'),
2984
3026
  checked: syncChildrenState,
2985
- label: translate('pageSyncChildren'),
2986
3027
  onChange: (checked) => {
2987
3028
  setSyncChildrenState(checked === true)
2988
3029
  setSyncChildren(checked === true)
2989
3030
  },
2990
3031
  }),
2991
- h('p', { key: 'syncChildrenHint', className: 'dsdel-page-hint' },
2992
- translate(syncChildrenState ? 'pageSyncChildrenOn' : 'pageSyncChildrenOff')),
2993
3032
 
2994
- h(primitives.Checkbox, {
3033
+ settingRow({
2995
3034
  key: 'replaceCurrent',
3035
+ title: translate('pageReplaceCurrent'),
3036
+ descKey: 'replaceCurrentHint',
3037
+ desc: translate(replaceState ? 'pageReplaceCurrentOn' : 'pageReplaceCurrentOff'),
2996
3038
  checked: replaceState,
2997
- label: translate('pageReplaceCurrent'),
2998
3039
  onChange: (checked) => {
2999
3040
  setReplaceState(checked === true)
3000
3041
  setReplaceCurrent(checked === true)
3001
3042
  },
3002
3043
  }),
3003
- h('p', { key: 'replaceCurrentHint', className: 'dsdel-page-hint' },
3004
- translate(replaceState ? 'pageReplaceCurrentOn' : 'pageReplaceCurrentOff')),
3005
3044
 
3006
- h(primitives.Checkbox, {
3045
+ settingRow({
3007
3046
  key: 'off',
3047
+ title: translate('pageArtifactsOff'),
3048
+ descKey: 'offHint',
3049
+ desc: translate(off ? 'pageHintArtifactsOff' : 'pageHintArtifactsOn'),
3008
3050
  checked: off,
3009
- label: translate('pageArtifactsOff'),
3010
3051
  onChange: (checked) => {
3011
3052
  setOff(checked === true)
3012
3053
  setArtifactsOff(checked === true)
3013
3054
  },
3014
3055
  }),
3015
- h('p', { key: 'offHint', className: 'dsdel-page-hint' }, translate(off ? 'pageHintArtifactsOff' : 'pageHintArtifactsOn')),
3016
3056
  ]
3017
3057
 
3018
3058
  // Everything below the master switch only matters while the feature is on;
@@ -3033,16 +3073,17 @@ window.__ModuleLoader__.load({
3033
3073
  borderLeft: '2px solid rgba(127,127,127,0.35)',
3034
3074
  },
3035
3075
  },
3036
- h(primitives.Checkbox, {
3076
+ settingRow({
3037
3077
  key: 'auto',
3078
+ title: translate('pageArtifactsAuto'),
3079
+ descKey: 'autoHint',
3080
+ desc: translate(auto ? 'pageHintArtifactsAuto' : 'pageHintArtifactsAsk'),
3038
3081
  checked: auto,
3039
- label: translate('pageArtifactsAuto'),
3040
3082
  onChange: (checked) => {
3041
3083
  setAuto(checked === true)
3042
3084
  setArtifactsAuto(checked === true)
3043
3085
  },
3044
3086
  }),
3045
- h('p', { key: 'autoHint', className: 'dsdel-page-hint' }, translate(auto ? 'pageHintArtifactsAuto' : 'pageHintArtifactsAsk')),
3046
3087
  h('div', {
3047
3088
  key: 'scope',
3048
3089
  style: {
@@ -3076,17 +3117,17 @@ window.__ModuleLoader__.load({
3076
3117
  }),
3077
3118
  ),
3078
3119
  h('p', { key: 'scopeHint', className: 'dsdel-page-hint' }, translate(scope === 'all' ? 'pageScopeAllHint' : 'pageScopeCreatedHint')),
3079
- h(primitives.Checkbox, {
3120
+ settingRow({
3080
3121
  key: 'skipGit',
3122
+ title: translate('pageSkipGit'),
3123
+ descKey: 'skipGitHint',
3124
+ desc: translate(skipGit ? 'pageSkipGitOn' : 'pageSkipGitOff'),
3081
3125
  checked: skipGit,
3082
- label: translate('pageSkipGit'),
3083
3126
  onChange: (checked) => {
3084
3127
  setSkipGit(checked === true)
3085
3128
  setSkipGitRepos(checked === true)
3086
3129
  },
3087
3130
  }),
3088
- h('p', { key: 'skipGitHint', className: 'dsdel-page-hint' },
3089
- translate(skipGit ? 'pageSkipGitOn' : 'pageSkipGitOff')),
3090
3131
  h('div', { key: 'root', style: { display: 'flex', flexDirection: 'column', gap: '6px', marginTop: '2px' } },
3091
3132
  h('p', { key: 'rootLabel', className: 'dsdel-page-hint' }, translate('pageRootLabel')),
3092
3133
  h('div', { key: 'rootRow', style: { display: 'flex', gap: '8px', alignItems: 'center', flexWrap: 'wrap' } },
@@ -3133,15 +3174,16 @@ window.__ModuleLoader__.load({
3133
3174
  // A quiet link to the repository, last in the card. It is a nudge, not a
3134
3175
  // setting, so it never competes with the controls above it — and it is a
3135
3176
  // plain anchor, so clicking it opens the page instead of switching tabs here.
3136
- children.push(h('div', { key: 'star', className: 'dsdel-star' },
3137
- h('span', { key: 'ask' }, translate('starAsk')),
3138
- h('a', {
3139
- key: 'cta',
3140
- className: 'dsdel-star-link',
3141
- href: 'https://github.com/DDDMUC/dsh-delete-session',
3142
- target: '_blank',
3143
- rel: 'noreferrer',
3144
- }, translate('starCta'))))
3177
+ children.push(h('a', {
3178
+ key: 'star',
3179
+ className: 'dsdel-star',
3180
+ href: 'https://github.com/DDDMUC/dsh-delete-session',
3181
+ target: '_blank',
3182
+ rel: 'noreferrer',
3183
+ },
3184
+ h('span', { key: 'icon', className: 'dsdel-star-icon', 'aria-hidden': 'true' }, '⭐'),
3185
+ h('span', { key: 'ask' }, translate('starAsk')),
3186
+ h('span', { key: 'cta', className: 'dsdel-star-cta' }, translate('starCta'))))
3145
3187
 
3146
3188
  // Each control owns the nodes that explain it. Grouping them here keeps the
3147
3189
  // markup above flat (a switch and its hint are still two pushes) while the
@@ -3327,7 +3369,7 @@ window.__ModuleLoader__.load({
3327
3369
  }
3328
3370
  }
3329
3371
 
3330
- return { apply }
3372
+ return { apply, __settings: { SettingsCard: AskBeforeDeleteOption } }
3331
3373
  }
3332
3374
 
3333
3375
  // ===== vendored dsh-session-relocate =====
@@ -7338,10 +7380,12 @@ window.__ModuleLoader__.load({
7338
7380
  const react = require('react')
7339
7381
 
7340
7382
  const NS = 'dsh-declutter'
7341
- const VERSION = '0.2.0'
7383
+ const VERSION = '0.2.4'
7342
7384
  const ROUTE_PREFIX = '/dsh-declutter'
7343
7385
  // Same cadence the sibling plugins use for transcript polling.
7344
7386
  const REFRESH_INTERVAL_MS = 3000
7387
+ const REFRESH_MAX_MS = 30000
7388
+ const STATE_TIMEOUT_MS = 15000
7345
7389
  // How often the view side is allowed to tell the host about its anchors.
7346
7390
  const REPORT_INTERVAL_MS = 2000
7347
7391
 
@@ -7368,6 +7412,7 @@ window.__ModuleLoader__.load({
7368
7412
  // manage `data-dshdc-*`, so the collapsed state survives every re-render.
7369
7413
 
7370
7414
  const CSS = [
7415
+ '[class*="_panelUnpin"]{display:none!important}',
7371
7416
  '[data-dshdc-collapsed="1"] > *:not([data-dshdc-toggle]){display:none!important}',
7372
7417
  '.dshdc-toggle{grid-column:1/-1;display:inline-flex;align-items:center;gap:6px;padding:2px 0;border:0;background:transparent;color:var(--dsw-alias-label-tertiary,#8a8f98);font:inherit;font-size:var(--dsh-content-font-size-secondary,13px);line-height:calc(20px + var(--dsh-content-font-delta-secondary,0px));cursor:pointer;text-align:left}',
7373
7418
  '.dshdc-toggle:hover{color:var(--dsw-alias-label-secondary,#61666d)}',
@@ -7629,13 +7674,30 @@ window.__ModuleLoader__.load({
7629
7674
  this.lastReportKey = ''
7630
7675
  this.observer = null
7631
7676
  this.timer = null
7677
+ this.inFlight = false
7678
+ this.nextDelay = REFRESH_INTERVAL_MS
7632
7679
  }
7633
7680
 
7634
7681
  async load() {
7635
- const response = await fetch(ROUTE_PREFIX + '/state?sessionId=' + encodeURIComponent(this.sessionId), {
7636
- credentials: 'same-origin',
7637
- headers: { accept: 'application/json' },
7638
- })
7682
+ // One rebuild at a time: a slow /state used to pile up, one request per
7683
+ // poll, which is what starved the host on a large transcript.
7684
+ if (this.inFlight === true) return
7685
+ this.inFlight = true
7686
+ const controller = typeof AbortController === 'function' ? new AbortController() : null
7687
+ const abortTimer = controller === null
7688
+ ? null
7689
+ : window.setTimeout(() => controller.abort(), STATE_TIMEOUT_MS)
7690
+ let response
7691
+ try {
7692
+ response = await fetch(ROUTE_PREFIX + '/state?sessionId=' + encodeURIComponent(this.sessionId), {
7693
+ credentials: 'same-origin',
7694
+ headers: { accept: 'application/json' },
7695
+ signal: controller === null ? undefined : controller.signal,
7696
+ })
7697
+ } finally {
7698
+ if (abortTimer !== null) window.clearTimeout(abortTimer)
7699
+ this.inFlight = false
7700
+ }
7639
7701
  // 400 means the route is mounted but this request was rejected; 404 means
7640
7702
  // the plugin is not installed at all. Both leave the view untouched.
7641
7703
  if (!response.ok) throw new Error('state ' + response.status)
@@ -7702,11 +7764,22 @@ window.__ModuleLoader__.load({
7702
7764
  })
7703
7765
  }
7704
7766
  kick()
7705
- this.timer = window.setInterval(() => {
7767
+ const tick = () => {
7768
+ if (this.detached) return
7706
7769
  // Polling an off-screen tab is pure cost; resume on the next visible tick.
7707
- if (typeof document !== 'undefined' && document.hidden === true) return
7770
+ if (typeof document !== 'undefined' && document.hidden === true) {
7771
+ this.timer = window.setTimeout(tick, REFRESH_INTERVAL_MS)
7772
+ return
7773
+ }
7774
+ const startedAt = Date.now()
7708
7775
  kick()
7709
- }, REFRESH_INTERVAL_MS)
7776
+ // Back off when a rebuild is slow, never past the ceiling, and drop back
7777
+ // to the base interval as soon as it is fast again.
7778
+ const elapsed = Date.now() - startedAt
7779
+ this.nextDelay = Math.min(Math.max(REFRESH_INTERVAL_MS, elapsed * 4), REFRESH_MAX_MS)
7780
+ this.timer = window.setTimeout(tick, this.nextDelay)
7781
+ }
7782
+ this.timer = window.setTimeout(tick, REFRESH_INTERVAL_MS)
7710
7783
 
7711
7784
  // The trajectory view is a virtual list: it discards rows and creates new
7712
7785
  // ones as the user scrolls, so a marker placed once is gone almost
@@ -7756,6 +7829,8 @@ window.__ModuleLoader__.load({
7756
7829
  // sidebar/DOM layer: stylesheet rules, panel stamping and ordering, session-
7757
7830
  // menu hiding, the settings page and its entry in the panel list. It keeps
7758
7831
  // its own storage keys so switches made before the merge survive.
7832
+ let sidebarSettingsCard = null
7833
+
7759
7834
  function mountSidebar(ctx) {
7760
7835
  const React = require('react')
7761
7836
  const h = React.createElement
@@ -7771,6 +7846,7 @@ window.__ModuleLoader__.load({
7771
7846
  const PANEL_ENTRY_LABEL = '隐藏与整理'
7772
7847
  /** Panel id: the URL segment (#/panel/<id>) and the main slot key. */
7773
7848
  const PANEL_ENTRY_ID = 'hide-rows'
7849
+ const PANEL_ENTRY_ENABLED = false
7774
7850
  /** The sidebar draws the row; this slot contributes the icon in front of it. */
7775
7851
  function PanelEntry() {
7776
7852
  return h(
@@ -9367,7 +9443,7 @@ window.__ModuleLoader__.load({
9367
9443
  // carries the icon and label, and the main slot with the same key is the
9368
9444
  // page the shell routes #/panel/<id> to. Without the second registration
9369
9445
  // the click falls back to whatever panel was open before.
9370
- if (ctx.slots && typeof ctx.slots.inject === 'function') {
9446
+ if (PANEL_ENTRY_ENABLED && ctx.slots && typeof ctx.slots.inject === 'function') {
9371
9447
  ctx.effect(() =>
9372
9448
  ctx.slots.inject('sidebar.panellist', () =>
9373
9449
  ctx.slots.register(
@@ -9415,6 +9491,7 @@ window.__ModuleLoader__.load({
9415
9491
  }
9416
9492
 
9417
9493
  sidebarApply(ctx)
9494
+ sidebarSettingsCard = SettingsCard
9418
9495
  }
9419
9496
  // ==== end sidebar half ===================================================
9420
9497
 
@@ -9463,14 +9540,902 @@ window.__ModuleLoader__.load({
9463
9540
  exports.apply = apply
9464
9541
  exports.inject = ['slots', 'locale']
9465
9542
  exports.version = VERSION
9543
+ exports.__settings = { get SettingsCard() { return sidebarSettingsCard } }
9466
9544
  // Exported for the view-side unit tests, which run this file against a
9467
9545
  // minimal DOM stub instead of a browser.
9468
9546
  exports.__test = { sweep, sweepInjectedNodes, adoptNode, readTurn, wantedTurns, surfaceMounted, DeclutterController, NS, VERSION }
9469
9547
  return module.exports
9470
9548
  }
9471
9549
 
9550
+ // ===== vendored dsh-settings-launcher =====
9551
+ const factory_dsh_settings_launcher = (require) => {
9552
+ const React = require('react')
9553
+ const h = React.createElement
9554
+
9555
+ /** Effect labels; Cordis names the fiber after these. */
9556
+ const NS = 'dsh-settings-launcher'
9557
+ /** The questionnaire the shipped account menu opens (its only feedback target). */
9558
+ const FEEDBACK_URL =
9559
+ 'https://trtgsjkv6r.feishu.cn/share/base/form/shrcnlCoGElW7MQznGy9r3YYXcg?hide_uid=1&hide_device_info=1&hide_harness_version=1'
9560
+
9561
+ /**
9562
+ * Both switches live in localStorage rather than the Loader Config: the
9563
+ * client half switches at runtime, and a Config edit restarts the row
9564
+ * instead of reaching the browser. One store, read by the switch card and
9565
+ * the installer, so a change lands everywhere at once.
9566
+ */
9567
+ const STORE_KEY = 'dsh-settings-launcher:flags'
9568
+ /**
9569
+ * Keys written under the package's previous name. Read once, then removed
9570
+ * after the first successful write, so a rename does not silently reset
9571
+ * the switches a user already chose.
9572
+ */
9573
+ const LEGACY_STORE_KEYS = ['dsh-settings-direct:flags']
9574
+ /** The single-string key written by the version before `:flags`. */
9575
+ const LEGACY_STORE_KEY = 'dsh-settings-direct:mode'
9576
+ const FLAG_HOVER = 'hover'
9577
+ const FLAG_DIRECT = 'direct'
9578
+ const DEFAULT_FLAGS = { hover: true, direct: false }
9579
+ /** Row-config key: `<bundle package>#<row id from the bundle patch>`. */
9580
+ const ROW_CONFIG_KEY = 'dsh-settings-launcher#settings-launcher'
9581
+
9582
+ /**
9583
+ * Two different attribute names on purpose. The stylesheet tag and the
9584
+ * injected card block used to share one, and the card cleanup sweeps every
9585
+ * node carrying that attribute — so reinstalling deleted the stylesheet
9586
+ * together with the cards, leaving the plugin page's form unstyled.
9587
+ */
9588
+ const STYLE_ATTR = 'data-dsd-style'
9589
+ const INJECT_ATTR = 'data-dsd-cards'
9590
+
9591
+ /**
9592
+ * The shipped account trigger is the only button in the sidebar carrying
9593
+ * `data-signed-out` (`AccountMenu` sets it from the sign-in state). Its
9594
+ * class prefix is a CSS-module hash that changes every build, and its
9595
+ * `aria-haspopup` is rewritten below when the click opens a dialog — so the
9596
+ * selector anchors on that flag alone.
9597
+ */
9598
+ const TRIGGER_SELECTOR = 'button[data-signed-out]'
9599
+ /** Any open menu list; the shipped menu is portal-rendered under the body. */
9600
+ const MENU_SELECTOR = '[role="menu"]'
9601
+ const OPEN_DELAY = 160
9602
+ const CLOSE_DELAY = 260
9603
+ /** Shipped shortcut command that opens the Settings panel. */
9604
+ const SETTINGS_COMMAND = 'settings.open'
9605
+
9606
+ const flagSubscribers = new Set()
9607
+
9608
+ /** Parse one `{hover,direct}` document; `null` when it is not one. */
9609
+ function parseFlags(raw) {
9610
+ if (raw === null) return null
9611
+ try {
9612
+ const parsed = JSON.parse(raw)
9613
+ if (parsed === null || typeof parsed !== 'object') return null
9614
+ return { hover: parsed.hover === true, direct: parsed.direct === true }
9615
+ } catch {
9616
+ return null
9617
+ }
9618
+ }
9619
+
9620
+ function readFlags() {
9621
+ try {
9622
+ const own = parseFlags(localStorage.getItem(STORE_KEY))
9623
+ if (own !== null) return own
9624
+ // Keys written under the package's previous name keep the user's
9625
+ // choice across the rename.
9626
+ for (const key of LEGACY_STORE_KEYS) {
9627
+ const previous = parseFlags(localStorage.getItem(key))
9628
+ if (previous !== null) return previous
9629
+ }
9630
+ // The single-string value from before `:flags`: 'direct' meant "click
9631
+ // opens Settings instead of the menu", 'hover' meant "menu opens on
9632
+ // hover".
9633
+ const legacy = localStorage.getItem(LEGACY_STORE_KEY)
9634
+ if (legacy === 'direct') return { hover: false, direct: true }
9635
+ if (legacy === 'hover') return { hover: true, direct: false }
9636
+ } catch {
9637
+ // Storage may be unavailable; the defaults still apply.
9638
+ }
9639
+ return { ...DEFAULT_FLAGS }
9640
+ }
9641
+
9642
+ function writeFlags(next) {
9643
+ const value = { hover: next.hover === true, direct: next.direct === true }
9644
+ try {
9645
+ localStorage.setItem(STORE_KEY, JSON.stringify(value))
9646
+ localStorage.removeItem(LEGACY_STORE_KEY)
9647
+ // Drop the previous-name copies only after the new key is written.
9648
+ for (const key of LEGACY_STORE_KEYS) localStorage.removeItem(key)
9649
+ } catch {
9650
+ // A failed write leaves the previous flags in effect; report nothing.
9651
+ }
9652
+ for (const fn of flagSubscribers) {
9653
+ try {
9654
+ fn(value)
9655
+ } catch {
9656
+ // A broken subscriber must not stop the others.
9657
+ }
9658
+ }
9659
+ }
9660
+
9661
+ function subscribeFlags(fn) {
9662
+ flagSubscribers.add(fn)
9663
+ return () => {
9664
+ flagSubscribers.delete(fn)
9665
+ }
9666
+ }
9667
+
9668
+ /** One line for the plugin row and for any log message. */
9669
+ function flagsSummary(flags) {
9670
+ if (flags.hover && flags.direct) return '当前:悬浮展开菜单 + 点击进设置'
9671
+ if (flags.hover) return '当前:悬浮展开菜单'
9672
+ if (flags.direct) return '当前:点击进设置'
9673
+ return '当前:官方原样(点一下弹菜单)'
9674
+ }
9675
+
9676
+ const CSS = [
9677
+ '.dsd-inject{display:flex;flex-direction:column;gap:12px;margin-top:12px}',
9678
+ '.dsd-card{border:1px solid var(--dsw-alias-border-secondary,rgba(128,128,128,.18));',
9679
+ 'border-radius:16px;padding:16px 20px;display:flex;flex-direction:column;gap:4px;',
9680
+ 'background:var(--dsw-alias-bg-primary,transparent);box-sizing:border-box}',
9681
+ '.dsd-title{font-size:14px;color:var(--dsw-alias-label-primary)}',
9682
+ '.dsd-sub{font-size:12px;line-height:1.5;color:var(--dsw-alias-label-tertiary)}',
9683
+ '.dsd-actions{display:flex;flex-wrap:wrap;gap:8px;margin-top:6px}',
9684
+ '.dsd-btn{font:inherit;font-size:13px;line-height:20px;padding:6px 14px;cursor:pointer;',
9685
+ 'border-radius:var(--dsw-radius-md,8px);border:1px solid var(--dsw-alias-border-secondary,rgba(128,128,128,.3));',
9686
+ 'background:transparent;color:var(--dsw-alias-label-primary)}',
9687
+ '.dsd-btn:hover{background:var(--dsw-alias-interactive-bg-hover)}',
9688
+ '.dsd-btn:disabled{opacity:.5;cursor:default}',
9689
+ '.dsd-btn[data-tone=danger]{color:var(--dsw-alias-state-error-primary,#e5484d);',
9690
+ 'border-color:var(--dsw-alias-state-error-primary,#e5484d)}',
9691
+ '.dsd-note{font-size:12px;line-height:1.5;color:var(--dsw-alias-label-tertiary)}',
9692
+ // The plugin page's form: two independent rows, each its own checkbox.
9693
+ '.dsd-form{display:flex;flex-direction:column;gap:8px}',
9694
+ '.dsd-choice{display:flex;flex-direction:column;gap:10px}',
9695
+ '.dsd-option{display:flex;align-items:flex-start;gap:10px;cursor:pointer;',
9696
+ 'border:1px solid var(--dsw-alias-border-secondary,rgba(128,128,128,.18));',
9697
+ 'border-radius:var(--dsw-radius-md,8px);padding:10px 12px;background:transparent}',
9698
+ '.dsd-option[data-selected=true]{border-color:var(--dsw-alias-state-business-primary,#4a6cf7);',
9699
+ 'background:var(--dsw-alias-interactive-bg-hover)}',
9700
+ '.dsd-option input{margin:2px 0 0;flex:none}',
9701
+ '.dsd-optionText{display:flex;flex-direction:column;gap:2px;min-width:0}',
9702
+ '.dsd-optionTitle{font-size:13px;color:var(--dsw-alias-label-primary)}',
9703
+ '.dsd-optionHint{font-size:12px;line-height:1.5;color:var(--dsw-alias-label-tertiary)}',
9704
+ ].join('')
9705
+
9706
+ function ensureStyle() {
9707
+ if (typeof document === 'undefined') return null
9708
+ const existing = document.querySelector('style[' + STYLE_ATTR + ']')
9709
+ if (existing !== null) {
9710
+ if (existing.textContent !== CSS) existing.textContent = CSS
9711
+ return existing
9712
+ }
9713
+ const tag = document.createElement('style')
9714
+ tag.setAttribute(STYLE_ATTR, '1')
9715
+ tag.textContent = CSS
9716
+ document.head.appendChild(tag)
9717
+ return tag
9718
+ }
9719
+
9720
+ /**
9721
+ * The switch on the plugin page. The host hands a keyed
9722
+ * `plugins.row.config` occupant either `view: 'summary'` (the one-liner
9723
+ * under the row) or `view: 'page'` (this form). There is no save button: a
9724
+ * checkbox change is the whole edit, so the choice lands immediately and
9725
+ * the installer below re-runs.
9726
+ */
9727
+ function SwitchCard(props) {
9728
+ const [, forceRender] = React.useReducer((count) => count + 1, 0)
9729
+ const [flags, setFlags] = React.useState(readFlags)
9730
+ React.useEffect(() => subscribeFlags((next) => { setFlags(next); forceRender() }), [])
9731
+
9732
+ if (props?.view === 'summary') {
9733
+ return h('span', { className: 'dsd-note' }, flagsSummary(flags))
9734
+ }
9735
+
9736
+ const row = (key, title, hint) =>
9737
+ h(
9738
+ 'label',
9739
+ { key, className: 'dsd-option', 'data-selected': flags[key] === true ? 'true' : undefined },
9740
+ h('input', {
9741
+ type: 'checkbox',
9742
+ checked: flags[key] === true,
9743
+ onChange: (event) => writeFlags({ ...flags, [key]: event.target.checked === true }),
9744
+ }),
9745
+ h(
9746
+ 'span',
9747
+ { className: 'dsd-optionText' },
9748
+ h('span', { className: 'dsd-optionTitle' }, title),
9749
+ h('span', { className: 'dsd-optionHint' }, hint),
9750
+ ),
9751
+ )
9752
+
9753
+ return h(
9754
+ 'div',
9755
+ { className: 'dsd-form' },
9756
+ h(
9757
+ 'fieldset',
9758
+ { className: 'dsd-choice', 'aria-label': '侧栏账号入口的交互' },
9759
+ row(
9760
+ FLAG_HOVER,
9761
+ '悬浮展开菜单',
9762
+ '指针移入即展开原版菜单(设置 / 意见反馈 / 退出登录),移出收起;点击可固定。',
9763
+ ),
9764
+ row(
9765
+ FLAG_DIRECT,
9766
+ '点击进设置',
9767
+ '点击直达设置面板;「账号与余额」页同时追加意见反馈与登录/退出登录两张卡片(与菜单内容重复,属预期)。',
9768
+ ),
9769
+ h('span', { className: 'dsd-note' }, flagsSummary(flags)),
9770
+ ),
9771
+ )
9772
+ }
9773
+
9774
+ /**
9775
+ * Resolve the account Remote surface. `remote.account` is the same service
9776
+ * path the account plugin injects; the nested form is the fallback for a
9777
+ * deployment that only publishes the namespace root.
9778
+ */
9779
+ function accountService(ctx) {
9780
+ for (const key of ['remote.account', 'remote']) {
9781
+ try {
9782
+ const service = ctx?.get(key)
9783
+ if (key === 'remote') {
9784
+ if (service?.account !== undefined) return service.account
9785
+ } else if (service !== undefined && service !== null) {
9786
+ return service
9787
+ }
9788
+ } catch {
9789
+ // A missing service is a fallback, not a failure.
9790
+ }
9791
+ }
9792
+ return null
9793
+ }
9794
+
9795
+ /** Metadata the account Remote methods carry. */
9796
+ function clientMeta(ctx) {
9797
+ const locale = (() => {
9798
+ try {
9799
+ return ctx.get('locale')?.getSnapshot()?.active ?? 'zh'
9800
+ } catch {
9801
+ return 'zh'
9802
+ }
9803
+ })()
9804
+ return {
9805
+ version: '0.3.0',
9806
+ locale,
9807
+ timezoneOffsetSeconds: -new Date().getTimezoneOffset() * 60,
9808
+ }
9809
+ }
9810
+
9811
+ /**
9812
+ * The actions the menu holds, appended to the shipped "账号与余额" page for
9813
+ * the click-only combination.
9814
+ *
9815
+ * That page is owned by ui-settings-account and declares no extension slot,
9816
+ * so the only way in is the DOM: when the settings dialog is open and the
9817
+ * account row is the active section, a card block is appended to the section
9818
+ * column and removed again on any other section. Everything here is written
9819
+ * in plain DOM — React never owns these nodes, so the observer re-adds them
9820
+ * whenever the shell re-renders the column.
9821
+ */
9822
+ /** Active-section text that means "the account page". */
9823
+ const ACCOUNT_LABELS = ['账号与余额', 'Account & balance', 'Account']
9824
+
9825
+ function buildInjectedCards(ctx) {
9826
+ const root = document.createElement('div')
9827
+ root.setAttribute(INJECT_ATTR, '1')
9828
+ root.className = 'dsd-inject'
9829
+
9830
+ const accountCard = document.createElement('section')
9831
+ accountCard.className = 'dsd-card'
9832
+ const accountTitle = document.createElement('div')
9833
+ accountTitle.className = 'dsd-title'
9834
+ accountTitle.textContent = '账号'
9835
+ const accountSub = document.createElement('div')
9836
+ accountSub.className = 'dsd-sub'
9837
+ accountSub.textContent = '正在读取账号状态…'
9838
+ const accountActions = document.createElement('div')
9839
+ accountActions.className = 'dsd-actions'
9840
+ accountCard.append(accountTitle, accountSub, accountActions)
9841
+
9842
+ const feedbackCard = document.createElement('section')
9843
+ feedbackCard.className = 'dsd-card'
9844
+ const feedbackTitle = document.createElement('div')
9845
+ feedbackTitle.className = 'dsd-title'
9846
+ feedbackTitle.textContent = '意见反馈'
9847
+ const feedbackSub = document.createElement('div')
9848
+ feedbackSub.className = 'dsd-sub'
9849
+ feedbackSub.textContent = '在浏览器中打开问卷,提交问题或建议。'
9850
+ const feedbackActions = document.createElement('div')
9851
+ feedbackActions.className = 'dsd-actions'
9852
+ const feedbackButton = document.createElement('button')
9853
+ feedbackButton.type = 'button'
9854
+ feedbackButton.className = 'dsd-btn'
9855
+ feedbackButton.textContent = '打开问卷'
9856
+ feedbackButton.addEventListener('click', () => {
9857
+ window.open(FEEDBACK_URL, '_blank', 'noopener')
9858
+ })
9859
+ feedbackActions.append(feedbackButton)
9860
+ feedbackCard.append(feedbackTitle, feedbackSub, feedbackActions)
9861
+
9862
+ root.append(accountCard, feedbackCard)
9863
+
9864
+ const service = accountService(ctx)
9865
+
9866
+ /**
9867
+ * One action button whose listeners are rebuilt whenever the account state
9868
+ * changes. Replacing the node keeps the old listeners from stacking up;
9869
+ * `actionButton` always points at the node currently in the DOM.
9870
+ */
9871
+ let actionButton = null
9872
+ let busy = false
9873
+
9874
+ const setBusy = (value, text) => {
9875
+ busy = value
9876
+ if (actionButton === null) return
9877
+ actionButton.disabled = value
9878
+ if (value) actionButton.textContent = text
9879
+ }
9880
+
9881
+ async function onSignOut() {
9882
+ if (service === null || busy || actionButton === null) return
9883
+ const node = actionButton
9884
+ if (node.dataset.confirm !== '1') {
9885
+ node.dataset.confirm = '1'
9886
+ node.textContent = '确认退出'
9887
+ accountSub.textContent = '再点一次「确认退出」完成退出。'
9888
+ setTimeout(() => {
9889
+ if (node.dataset.confirm === '1') {
9890
+ node.dataset.confirm = ''
9891
+ paint('signed-in')
9892
+ }
9893
+ }, 5000)
9894
+ return
9895
+ }
9896
+ node.dataset.confirm = ''
9897
+ setBusy(true, '正在退出…')
9898
+ try {
9899
+ const result = await service.signOut(clientMeta(ctx))
9900
+ if (!result?.ok) throw new Error('sign out failed')
9901
+ paint('signed-out')
9902
+ } catch {
9903
+ accountSub.textContent = '退出登录失败,请稍后再试。'
9904
+ paint('signed-in')
9905
+ }
9906
+ }
9907
+
9908
+ async function onSignIn() {
9909
+ if (service === null || busy || actionButton === null) return
9910
+ setBusy(true, '正在登录…')
9911
+ try {
9912
+ const result = await service.startSignIn(clientMeta(ctx))
9913
+ if (!result?.ok) throw new Error('sign in failed')
9914
+ const url = result.value?.attempt?.authorizeUrl
9915
+ if (typeof url === 'string' && url !== '') window.open(url, '_blank', 'noopener')
9916
+ accountSub.textContent = '已在浏览器中打开登录页,完成后回到这里即可。'
9917
+ paint('signed-out')
9918
+ } catch {
9919
+ accountSub.textContent = '无法开始登录,请稍后再试。'
9920
+ paint('signed-out')
9921
+ }
9922
+ }
9923
+
9924
+ /** `status` is 'signed-in', 'signed-out', 'unavailable' or 'unknown'. */
9925
+ const paint = (status) => {
9926
+ busy = false
9927
+ if (status === 'signed-in') accountSub.textContent = '退出后不影响任何本地数据,可随时重新登录。'
9928
+ else if (status === 'signed-out') accountSub.textContent = '未登录。'
9929
+ else accountSub.textContent = '当前环境无法读取账号服务。'
9930
+
9931
+ const replacement = document.createElement('button')
9932
+ replacement.type = 'button'
9933
+ replacement.className = 'dsd-btn'
9934
+ if (status === 'signed-in') {
9935
+ replacement.textContent = '退出登录'
9936
+ replacement.addEventListener('click', () => { void onSignOut() })
9937
+ } else {
9938
+ replacement.textContent = '登录'
9939
+ if (status === 'signed-out') {
9940
+ replacement.addEventListener('click', () => { void onSignIn() })
9941
+ } else {
9942
+ replacement.disabled = true
9943
+ }
9944
+ }
9945
+ if (actionButton === null) {
9946
+ actionButton = replacement
9947
+ accountActions.append(actionButton)
9948
+ return
9949
+ }
9950
+ actionButton.replaceWith(replacement)
9951
+ actionButton = replacement
9952
+ }
9953
+
9954
+ paint('unknown')
9955
+ if (service !== null) {
9956
+ Promise.resolve()
9957
+ .then(() => service.getState())
9958
+ .then((result) => {
9959
+ if (!result?.ok) return paint('unknown')
9960
+ paint(result.value?.status === 'credential-stored' ? 'signed-in' : 'signed-out')
9961
+ })
9962
+ .catch(() => paint('unknown'))
9963
+ } else {
9964
+ paint('unavailable')
9965
+ }
9966
+
9967
+ return root
9968
+ }
9969
+
9970
+ /**
9971
+ * Keep the injected block in step with the open dialog: the shell swaps the
9972
+ * section column on every navigation, so the block is re-added on the account
9973
+ * row and dropped everywhere else.
9974
+ */
9975
+ function installAccountCardInjector(ctx) {
9976
+ if (typeof document === 'undefined') return () => {}
9977
+ let dialog = null
9978
+ let dialogObserver = null
9979
+ let scheduled = false
9980
+
9981
+ const findDialog = () =>
9982
+ document.querySelector('[role="dialog"][data-shortcut-modal="settings"]')
9983
+
9984
+ /**
9985
+ * The selected row's label. The shell marks it with `aria-current` in some
9986
+ * builds and with a CSS-module `_active` class in others (the local class
9987
+ * suffix is stable across builds; the hashed prefix is not), so both are
9988
+ * accepted rather than assuming one.
9989
+ */
9990
+ const currentLabel = (node) => {
9991
+ const active =
9992
+ node.querySelector('nav button[aria-current="true"]') ??
9993
+ node.querySelector('nav button[class*="_active"]')
9994
+ return active === null ? null : (active.textContent ?? '').trim()
9995
+ }
9996
+
9997
+ const sync = () => {
9998
+ scheduled = false
9999
+ const next = findDialog()
10000
+ if (next === null) {
10001
+ if (dialogObserver !== null) {
10002
+ dialogObserver.disconnect()
10003
+ dialogObserver = null
10004
+ }
10005
+ dialog = null
10006
+ return
10007
+ }
10008
+ if (next !== dialog) {
10009
+ if (dialogObserver !== null) dialogObserver.disconnect()
10010
+ dialog = next
10011
+ dialogObserver = new MutationObserver(schedule)
10012
+ dialogObserver.observe(next, {
10013
+ childList: true,
10014
+ subtree: true,
10015
+ attributes: true,
10016
+ // The active row is marked by `aria-current` in some builds and by a
10017
+ // class swap in others, so both attribute changes must re-run `sync`.
10018
+ attributeFilter: ['aria-current', 'class'],
10019
+ })
10020
+ }
10021
+ const column = dialog.querySelector('[class*="_options"]')
10022
+ if (column === null) return
10023
+ const label = currentLabel(dialog)
10024
+ const wanted = label !== null && ACCOUNT_LABELS.some((one) => label.includes(one))
10025
+ const existing = column.querySelector('[' + INJECT_ATTR + ']')
10026
+ if (!wanted) {
10027
+ if (existing !== null) existing.remove()
10028
+ return
10029
+ }
10030
+ if (existing !== null) return
10031
+ column.append(buildInjectedCards(ctx))
10032
+ }
10033
+
10034
+ function schedule() {
10035
+ if (scheduled) return
10036
+ scheduled = true
10037
+ if (typeof requestAnimationFrame === 'function') requestAnimationFrame(sync)
10038
+ else setTimeout(sync, 16)
10039
+ }
10040
+
10041
+ const bodyObserver = new MutationObserver((records) => {
10042
+ for (const record of records) {
10043
+ if (record.addedNodes.length > 0 || record.removedNodes.length > 0) {
10044
+ schedule()
10045
+ return
10046
+ }
10047
+ }
10048
+ })
10049
+ bodyObserver.observe(document.body, { childList: true })
10050
+ schedule()
10051
+
10052
+ return () => {
10053
+ bodyObserver.disconnect()
10054
+ if (dialogObserver !== null) dialogObserver.disconnect()
10055
+ for (const node of document.querySelectorAll('[' + INJECT_ATTR + ']')) node.remove()
10056
+ }
10057
+ }
10058
+
10059
+ /**
10060
+ * Build a caller for the shipped `settings.open` command.
10061
+ *
10062
+ * Nothing in the launcher seat hands out `openSettings` to a bystander, so
10063
+ * the panel is opened through the same command its own shortcut uses. The
10064
+ * service exposes `register` / `edit` / `describeBinding` but not a runner;
10065
+ * `registry` is its own plain field and `registry.invoke(id, context)` is
10066
+ * how a menu row runs a command. That shape is checked here rather than
10067
+ * assumed, and a deployment without it leaves the shipped click alone.
10068
+ */
10069
+ function settingsInvoker(ctx) {
10070
+ let service = null
10071
+ try {
10072
+ service = ctx?.get('shortcuts') ?? null
10073
+ } catch {
10074
+ service = null
10075
+ }
10076
+ if (service === null) return null
10077
+ const registry = service.registry
10078
+ if (registry === null || typeof registry !== 'object') return null
10079
+ if (typeof registry.invoke !== 'function') return null
10080
+ return () => {
10081
+ // `settings.open` is not registered by the package itself: the settings
10082
+ // shell registers it inside `remoteAccess.whenAccess('settings/describe',
10083
+ // ...)`, which resolves asynchronously after activation. Checking
10084
+ // `commands.has()` at install time therefore reports "missing" on a
10085
+ // perfectly good build, so the check belongs here, per click.
10086
+ const commands = registry.commands
10087
+ if (typeof commands?.has === 'function' && commands.has(SETTINGS_COMMAND) === false) {
10088
+ return false
10089
+ }
10090
+ // `modal: null` means "no modal is covering the page"; the command
10091
+ // opens the panel. Passing `settings` there would close it instead.
10092
+ registry.invoke(SETTINGS_COMMAND, { region: 'page', modal: null })
10093
+ return true
10094
+ }
10095
+ }
10096
+
10097
+ /**
10098
+ * Attach the two behaviours to the shipped account trigger.
10099
+ *
10100
+ * Nothing is rendered and no slot is taken, so the menu keeps every bit of
10101
+ * its shipped appearance, keyboard behaviour, toasts, dialogs and its
10102
+ * `settings.launcher.notifications` stack.
10103
+ *
10104
+ * hover pointer enters the row -> click it once, if it is not open yet
10105
+ * pointer leaves the row -> click it again after a delay, unless
10106
+ * the pointer moved into the open menu
10107
+ * a real click -> that menu is pinned
10108
+ * direct a click lowers the menu if hover had raised it, then opens the
10109
+ * Settings panel
10110
+ */
10111
+ function installInteraction(ctx, flags) {
10112
+ if (typeof document === 'undefined') return () => {}
10113
+
10114
+ const timers = { open: null, close: null }
10115
+ let trigger = null
10116
+ let menu = null
10117
+ /** True while our own synthetic click is running, so it is not "a click". */
10118
+ let synthetic = false
10119
+ /** A menu the user opened by clicking stays open until dismissed. */
10120
+ let pinned = false
10121
+ const openSettings = flags.direct ? settingsInvoker(ctx) : null
10122
+
10123
+ if (flags.direct && openSettings === null) {
10124
+ console.warn(
10125
+ '[dsh-settings-launcher] 拿不到 shortcuts 服务的 registry.invoke,' +
10126
+ '「点击进设置」这次不生效,账号入口保持官方行为。',
10127
+ )
10128
+ }
10129
+
10130
+ const clear = (name) => {
10131
+ if (timers[name] !== null) {
10132
+ clearTimeout(timers[name])
10133
+ timers[name] = null
10134
+ }
10135
+ }
10136
+
10137
+ const isOpen = () => trigger !== null && trigger.getAttribute('aria-expanded') === 'true'
10138
+
10139
+ const openMenu = () => {
10140
+ if (trigger === null || isOpen()) return
10141
+ synthetic = true
10142
+ try {
10143
+ trigger.click()
10144
+ } finally {
10145
+ synthetic = false
10146
+ }
10147
+ }
10148
+
10149
+ const closeMenu = () => {
10150
+ if (trigger === null || !isOpen()) return
10151
+ synthetic = true
10152
+ try {
10153
+ trigger.click()
10154
+ } finally {
10155
+ synthetic = false
10156
+ }
10157
+ }
10158
+
10159
+ /** The portal the trigger raises, so hovering it counts as "inside". */
10160
+ const adoptMenu = (before) => {
10161
+ const candidates = Array.from(document.querySelectorAll(MENU_SELECTOR))
10162
+ const next = candidates.find((node) => !before.has(node)) ?? null
10163
+ if (next === menu) return
10164
+ releaseMenu()
10165
+ menu = next
10166
+ if (menu !== null) {
10167
+ menu.addEventListener('pointerenter', onMenuEnter)
10168
+ menu.addEventListener('pointerleave', onMenuLeave)
10169
+ }
10170
+ }
10171
+
10172
+ function releaseMenu() {
10173
+ if (menu === null) return
10174
+ menu.removeEventListener('pointerenter', onMenuEnter)
10175
+ menu.removeEventListener('pointerleave', onMenuLeave)
10176
+ menu = null
10177
+ }
10178
+
10179
+ const pointerInsideMenu = () => {
10180
+ if (menu === null || !menu.isConnected) return false
10181
+ return menu.matches(':hover') || menu.contains(document.activeElement)
10182
+ }
10183
+
10184
+ const scheduleOpen = () => {
10185
+ clear('close')
10186
+ if (isOpen()) return
10187
+ clear('open')
10188
+ timers.open = setTimeout(() => {
10189
+ timers.open = null
10190
+ if (pinned) return
10191
+ const before = new Set(document.querySelectorAll(MENU_SELECTOR))
10192
+ openMenu()
10193
+ // The menu mounts after the click; adopt it once React has committed.
10194
+ setTimeout(() => adoptMenu(before), 0)
10195
+ }, OPEN_DELAY)
10196
+ }
10197
+
10198
+ const scheduleClose = () => {
10199
+ clear('open')
10200
+ clear('close')
10201
+ if (pinned) return
10202
+ timers.close = setTimeout(() => {
10203
+ timers.close = null
10204
+ if (pointerInsideMenu()) return
10205
+ closeMenu()
10206
+ releaseMenu()
10207
+ }, CLOSE_DELAY)
10208
+ }
10209
+
10210
+ function onMenuEnter() {
10211
+ clear('close')
10212
+ }
10213
+
10214
+ function onMenuLeave() {
10215
+ scheduleClose()
10216
+ }
10217
+
10218
+ function onEnter() {
10219
+ scheduleOpen()
10220
+ }
10221
+
10222
+ function onLeave() {
10223
+ scheduleClose()
10224
+ }
10225
+
10226
+ /**
10227
+ * A real click is the shipped toggle. Pin only when that click *opened*
10228
+ * the menu, and read the result after React has committed the new
10229
+ * `aria-expanded` rather than guessing it here.
10230
+ */
10231
+ function onClick() {
10232
+ if (synthetic) return
10233
+ clear('open')
10234
+ clear('close')
10235
+ const before = isOpen()
10236
+ setTimeout(() => {
10237
+ if (isOpen() && !before) {
10238
+ pinned = true
10239
+ return
10240
+ }
10241
+ pinned = false
10242
+ releaseMenu()
10243
+ }, 0)
10244
+ }
10245
+
10246
+ /**
10247
+ * `direct`: run the settings command instead of React's menu toggle.
10248
+ *
10249
+ * Capturing on the trigger and stopping propagation keeps React's
10250
+ * delegated onClick (attached at the root, bubble phase) from ever seeing
10251
+ * the event. Our own bubble-phase `onClick` sits on this same node, so it
10252
+ * needs `stopImmediatePropagation` too. Because `hover` raises the menu on
10253
+ * pointer-enter, a click normally arrives with the menu already open; that
10254
+ * click lowers the menu and then opens Settings, so both switches can be
10255
+ * on at once. `pinned` therefore only applies to the hover-only mode.
10256
+ */
10257
+ function onClickCapture(event) {
10258
+ if (openSettings === null || synthetic) return
10259
+ // The command may not be registered yet; when it is not, leave the
10260
+ // event alone so the shipped toggle still runs instead of swallowing it.
10261
+ if (openSettings() === false) return
10262
+
10263
+ event.preventDefault()
10264
+ event.stopPropagation()
10265
+ // Our own bubble-phase listener sits on this same node and would still
10266
+ // run after stopPropagation, so stop it as well.
10267
+ if (typeof event.stopImmediatePropagation === 'function') event.stopImmediatePropagation()
10268
+ clear('open')
10269
+ clear('close')
10270
+ pinned = false
10271
+ // With `hover` on, the pointer entering the row already raised the menu,
10272
+ // so a click usually arrives while it is open. Lower it first, then open
10273
+ // Settings — otherwise the two switches together would only be able to
10274
+ // close the menu and Settings would stay unreachable by mouse.
10275
+ if (isOpen()) {
10276
+ closeMenu()
10277
+ releaseMenu()
10278
+ }
10279
+ }
10280
+
10281
+ /** Pin release: outside pointerdown, Escape, or the menu closing itself. */
10282
+ function onDocumentPointerDown(event) {
10283
+ if (!pinned) return
10284
+ if (trigger !== null && trigger.contains(event.target)) return
10285
+ if (menu !== null && menu.contains(event.target)) return
10286
+ pinned = false
10287
+ }
10288
+
10289
+ function onDocumentKeyDown(event) {
10290
+ if (event.key === 'Escape' && pinned) pinned = false
10291
+ }
10292
+
10293
+ /**
10294
+ * Announce the real behaviour. With `direct` alone the menu cannot be
10295
+ * opened at all, so keeping `aria-haspopup="menu"` would promise a menu
10296
+ * that never appears; with `hover` on as well the menu is still reachable
10297
+ * and the shipped value stays right.
10298
+ */
10299
+ const applyAria = (node) => {
10300
+ if (node === null) return
10301
+ if (flags.direct && !flags.hover) node.setAttribute('aria-haspopup', 'dialog')
10302
+ }
10303
+
10304
+ const restoreAria = (node) => {
10305
+ if (node === null) return
10306
+ if (flags.direct && !flags.hover) node.setAttribute('aria-haspopup', 'menu')
10307
+ }
10308
+
10309
+ const bind = () => {
10310
+ const next = document.querySelector(TRIGGER_SELECTOR)
10311
+ if (next === trigger) return
10312
+ if (trigger !== null) {
10313
+ trigger.removeEventListener('pointerenter', onEnter)
10314
+ trigger.removeEventListener('pointerleave', onLeave)
10315
+ trigger.removeEventListener('click', onClick)
10316
+ trigger.removeEventListener('click', onClickCapture, true)
10317
+ restoreAria(trigger)
10318
+ }
10319
+ trigger = next
10320
+ pinned = false
10321
+ releaseMenu()
10322
+ if (trigger === null) return
10323
+ if (flags.hover) {
10324
+ trigger.addEventListener('pointerenter', onEnter)
10325
+ trigger.addEventListener('pointerleave', onLeave)
10326
+ trigger.addEventListener('click', onClick)
10327
+ }
10328
+ if (openSettings !== null) trigger.addEventListener('click', onClickCapture, true)
10329
+ applyAria(trigger)
10330
+ }
10331
+
10332
+ const observer = new MutationObserver(() => {
10333
+ bind()
10334
+ // The menu unmounts on close; drop the reference so a reopen re-adopts.
10335
+ if (menu !== null && !isOpen()) releaseMenu()
10336
+ })
10337
+ observer.observe(document.body, { childList: true, subtree: true })
10338
+ bind()
10339
+
10340
+ document.addEventListener('pointerdown', onDocumentPointerDown, true)
10341
+ document.addEventListener('keydown', onDocumentKeyDown, true)
10342
+
10343
+ return () => {
10344
+ clear('open')
10345
+ clear('close')
10346
+ observer.disconnect()
10347
+ document.removeEventListener('pointerdown', onDocumentPointerDown, true)
10348
+ document.removeEventListener('keydown', onDocumentKeyDown, true)
10349
+ if (trigger !== null) {
10350
+ trigger.removeEventListener('pointerenter', onEnter)
10351
+ trigger.removeEventListener('pointerleave', onLeave)
10352
+ trigger.removeEventListener('click', onClick)
10353
+ trigger.removeEventListener('click', onClickCapture, true)
10354
+ restoreAria(trigger)
10355
+ }
10356
+ releaseMenu()
10357
+ }
10358
+ }
10359
+
10360
+ return {
10361
+ inject: ['slots', 'remote.account'],
10362
+ // The switches are also readable from outside this bundle: the aggregator
10363
+ // that vendors this file renders the same card (never a copy) and injects
10364
+ // the same stylesheet, so the two surfaces cannot drift.
10365
+ __settings: { SwitchCard },
10366
+ __ui: { pluginId: NS, css: () => CSS },
10367
+ apply(ctx) {
10368
+ // ctx.effect 要的是一个 cleanup 函数;ensureStyle() 返回的是 <style>
10369
+ // 元素,直接返回会让 Cordis 在激活时拿到非函数值而把 fiber 判为 failed。
10370
+ ctx.effect(() => {
10371
+ const tag = ensureStyle()
10372
+ return () => {
10373
+ if (tag !== null) tag.remove()
10374
+ }
10375
+ }, NS + ': stylesheet')
10376
+
10377
+ // Both switches are read on every install, so a checkbox change tears
10378
+ // the running behaviour down and builds the next one without a reload.
10379
+ ctx.effect(() => {
10380
+ let dispose = null
10381
+ const install = () => {
10382
+ if (dispose !== null) {
10383
+ try {
10384
+ dispose()
10385
+ } catch {
10386
+ // Rebuilding anyway; a failed teardown is not fatal.
10387
+ }
10388
+ dispose = null
10389
+ }
10390
+ const flags = readFlags()
10391
+ const releases = [installInteraction(ctx, flags)]
10392
+ // With `direct` the card is always injected, including when the
10393
+ // menu is also reachable through hover. That repeats 意见反馈 and
10394
+ // 退出登录 on the account page, which is the intended trade: the
10395
+ // page looks the same however the menu was opened.
10396
+ if (flags.direct) releases.push(installAccountCardInjector(ctx))
10397
+ dispose = () => {
10398
+ for (const release of releases) {
10399
+ try {
10400
+ release()
10401
+ } catch {
10402
+ // One failed cleanup must not skip the others.
10403
+ }
10404
+ }
10405
+ }
10406
+ }
10407
+ install()
10408
+ const off = subscribeFlags(install)
10409
+ return () => {
10410
+ off()
10411
+ if (dispose !== null) {
10412
+ try {
10413
+ dispose()
10414
+ } catch {
10415
+ // Nothing left to report on teardown failure.
10416
+ }
10417
+ dispose = null
10418
+ }
10419
+ }
10420
+ }, NS + ': behaviours')
10421
+
10422
+ // The plugin page's switches; independent of what is running.
10423
+ ctx.effect(() => {
10424
+ try {
10425
+ return ctx.slots.inject('plugins.row.config', () =>
10426
+ ctx.slots.register({ name: 'plugins.row.config', key: ROW_CONFIG_KEY }, SwitchCard),
10427
+ )
10428
+ } catch (error) {
10429
+ console.warn('[dsh-settings-launcher] 无法挂载插件页开关:', error)
10430
+ return undefined
10431
+ }
10432
+ }, NS + ': row config')
10433
+ },
10434
+ }
10435
+ }
10436
+
9472
10437
  // --- which factories this plugin mounts ---
9473
- const VENDORED_TABLE = { "dsh-delete-session": factory_dsh_delete_session, "dsh-session-relocate": factory_dsh_session_relocate, "dsh-session-rename-dblclick": factory_dsh_session_rename_dblclick, "dsh-session-counts": factory_dsh_session_counts, "dsh-declutter": factory_dsh_declutter }
10438
+ const VENDORED_TABLE = { "dsh-delete-session": factory_dsh_delete_session, "dsh-session-relocate": factory_dsh_session_relocate, "dsh-session-rename-dblclick": factory_dsh_session_rename_dblclick, "dsh-session-counts": factory_dsh_session_counts, "dsh-declutter": factory_dsh_declutter, "dsh-settings-launcher": factory_dsh_settings_launcher }
9474
10439
 
9475
10440
  // --- this plugin's own browser half ---
9476
10441
 
@@ -9485,7 +10450,7 @@ window.__ModuleLoader__.load({
9485
10450
  const NS = 'dsh-better-sidebar-left'
9486
10451
 
9487
10452
  /** Keep in sync with package.json and src/components.js. */
9488
- const PLUGIN_VERSION = '0.2.0'
10453
+ const PLUGIN_VERSION = '0.3.0'
9489
10454
 
9490
10455
  /** Presence marker the live verifier reads. */
9491
10456
  const DEBUG_KEY = '__DSH_BETTER_SIDEBAR_LEFT__'
@@ -9500,6 +10465,7 @@ window.__ModuleLoader__.load({
9500
10465
  'dsh-session-rename-dblclick',
9501
10466
  'dsh-session-counts',
9502
10467
  'dsh-declutter',
10468
+ 'dsh-settings-launcher',
9503
10469
  ]
9504
10470
 
9505
10471
  /**
@@ -9514,7 +10480,6 @@ window.__ModuleLoader__.load({
9514
10480
  * The other four keep their card only when installed standalone;
9515
10481
  * docs/INTEROP.md section 6 says what a component has to export to appear here.
9516
10482
  */
9517
- const CONFIG_CARDS = [{ id: 'dsh-session-relocate', path: ['__settings', 'ChildrenSetting'] }]
9518
10483
 
9519
10484
  /**
9520
10485
  * The cordis services this bundle's apply() needs, as the UNION of what every
@@ -9561,7 +10526,22 @@ window.__ModuleLoader__.load({
9561
10526
  settingsNone: '这个组件没有把设置卡导出给本页;单独安装时它落在自己的插件行上。',
9562
10527
  loading: '读取状态…',
9563
10528
  failed: '状态加载失败,稍后重试。',
10529
+ loading: '读取状态…',
10530
+ failed: '状态加载失败,稍后重试。',
9564
10531
  retry: '重试',
10532
+ panelEntry: '左栏管理',
10533
+ panelHeading: '左栏管理',
10534
+ panelLead: '这个包在左侧栏做的五件事,以及它们此刻是否真的在运行。',
10535
+ panelFoot: '开关在「插件 → dsh-better-sidebar-left」里;这里只看状态。',
10536
+ panelTabTidy: '收纳与整理',
10537
+ panelTabDelete: '删除会话',
10538
+ panelTabMove: '移动会话',
10539
+ panelState: '运行状态',
10540
+ panelVersion: '版本',
10541
+ panelPackage: '包名',
10542
+ panelWhat: '它做什么',
10543
+ panelNoSettings: '这个组件的设置项挂在它自己的插件行上,本包拿不到;要去改,请在「插件」页里点它自己那一行。',
10544
+ panelBack: '返回概览',
9565
10545
  }
9566
10546
 
9567
10547
  const en = {
@@ -9592,6 +10572,19 @@ window.__ModuleLoader__.load({
9592
10572
  loading: 'Reading state…',
9593
10573
  failed: 'Could not read the state. Try again in a moment.',
9594
10574
  retry: 'Retry',
10575
+ panelEntry: 'Left rail',
10576
+ panelHeading: 'Left rail',
10577
+ panelLead: 'The five things this package does in the left rail, and whether each one is really running right now.',
10578
+ panelFoot: 'Switches live under Plugins → dsh-better-sidebar-left; this page only reports state.',
10579
+ panelTabTidy: 'Tidy up',
10580
+ panelTabDelete: 'Delete a session',
10581
+ panelTabMove: 'Move a session',
10582
+ panelState: 'State',
10583
+ panelVersion: 'Version',
10584
+ panelPackage: 'Package',
10585
+ panelWhat: 'What it does',
10586
+ panelNoSettings: 'This component keeps its settings on its own plugin row, which this package cannot reach; open it from the Plugins page.',
10587
+ panelBack: 'Back to overview',
9595
10588
  }
9596
10589
 
9597
10590
  /** The component table, generated by tools/build.mjs from src/components.js. */
@@ -9675,6 +10668,22 @@ window.__ModuleLoader__.load({
9675
10668
  "zh": "两半合一:①会话内收纳 —— 失败轮、空轮、编辑产生的合成轮按规则表收起,只加 data-dshdc-* 视图属性,完全可逆,绝不改日志;②侧栏整理 —— 藏品牌行/「新会话」/「更多」/顶部空隙,面板显隐与排序。",
9676
10669
  "en": "Two halves in one: (1) in-conversation collapsing - failed, empty and synthesised turns fold away per a rule table, using data-dshdc-* view attributes only, fully reversible, never touching the log; (2) sidebar tidying - hides the brand row, the New session button, the More buttons and the top gap, plus panel visibility and order."
9677
10670
  }
10671
+ },
10672
+ {
10673
+ "id": "dsh-settings-launcher",
10674
+ "package": "dsh-settings-launcher",
10675
+ "suffix": "launcher",
10676
+ "feature": "launcher",
10677
+ "kind": "maintenance",
10678
+ "repo": "https://github.com/DDDMUC/dsh-settings-launcher",
10679
+ "title": {
10680
+ "zh": "账号入口",
10681
+ "en": "Account entry"
10682
+ },
10683
+ "pitch": {
10684
+ "zh": "侧栏账号入口的两个独立开关:悬浮自动展开原版菜单、点击直达设置;两个都关就是官方原样。",
10685
+ "en": "Two independent switches for the sidebar account entry: auto-expand the stock menu on hover, and go straight to Settings on click. Both off is the stock behaviour."
10686
+ }
9678
10687
  }
9679
10688
  ]
9680
10689
 
@@ -9800,26 +10809,48 @@ window.__ModuleLoader__.load({
9800
10809
  },
9801
10810
  {
9802
10811
  "component": "dsh-declutter",
9803
- "name": "sidebar.panellist",
9804
- "id": "hide-rows",
9805
- "order": 20
10812
+ "name": "plugins.row.config",
10813
+ "key": "dsh-declutter#dsh-declutter"
9806
10814
  },
10815
+ {
10816
+ "component": "dsh-settings-launcher",
10817
+ "name": "plugins.row.config",
10818
+ "key": "dsh-settings-launcher#settings-launcher"
10819
+ }
10820
+ ],
10821
+ "settingsCards": [
9807
10822
  {
9808
10823
  "component": "dsh-declutter",
9809
- "name": "main",
9810
- "key": "hide-rows"
10824
+ "exportPath": "__settings.SettingsCard"
9811
10825
  },
9812
10826
  {
9813
- "component": "dsh-declutter",
9814
- "name": "plugins.row.config",
9815
- "key": "dsh-declutter#dsh-declutter"
10827
+ "component": "dsh-delete-session",
10828
+ "exportPath": "__settings.SettingsCard"
10829
+ },
10830
+ {
10831
+ "component": "dsh-session-relocate",
10832
+ "exportPath": "__settings.ChildrenSetting"
10833
+ },
10834
+ {
10835
+ "component": "dsh-settings-launcher",
10836
+ "exportPath": "__settings.SwitchCard"
9816
10837
  }
9817
10838
  ]
9818
10839
  }
9819
10840
 
10841
+ const CONFIG_CARDS = INTEROP.settingsCards.map((card) => ({ id: card.component, path: card.exportPath.split('.') }))
10842
+
9820
10843
  // --- styles ----------------------------------------------------------------
9821
10844
 
9822
10845
  const STYLE = [
10846
+ '.dbsl-page{height:100%;min-height:0;overflow-y:auto;box-sizing:border-box;padding:14px 24px 24px 46px}',
10847
+ '.dbsl-h1{font-size:15px;font-weight:600;margin:0 0 6px}',
10848
+ '.dbsl-tabs{display:flex;align-items:center;gap:4px;flex-wrap:wrap;border-bottom:1px solid var(--dsw-alias-border-l2);padding-bottom:0;margin:2px 0 12px}',
10849
+ '.dbsl-tab{font:inherit;font-size:13px;color:var(--dsw-alias-label-secondary);background:transparent;border:0;border-bottom:2px solid transparent;padding:6px 10px;margin-bottom:-1px;cursor:pointer;border-radius:6px 6px 0 0}',
10850
+ '.dbsl-tab:hover{color:var(--dsw-alias-label-primary)}',
10851
+ '.dbsl-tabOn{color:var(--dsw-alias-label-primary);font-weight:600;border-bottom-color:var(--dsw-alias-brand-primary)}',
10852
+ '.dbsl-note{color:var(--dsw-alias-label-tertiary);font-size:12px;margin:0}',
10853
+ '.dbsl-panel{max-width:760px;display:flex;flex-direction:column;gap:10px}',
9823
10854
  '.dbsl-wrap{display:flex;flex-direction:column;gap:10px;font-size:13px;line-height:1.5}',
9824
10855
  '.dbsl-lead{color:var(--dsw-alias-label-secondary);margin:0}',
9825
10856
  '.dbsl-count{font-weight:600;margin:0}',
@@ -9852,12 +10883,19 @@ window.__ModuleLoader__.load({
9852
10883
  if (typeof document === 'undefined' || typeof document.querySelector !== 'function') return
9853
10884
  const style = document.querySelector('style[data-dsh-better-sidebar-left]')
9854
10885
  if (style !== null && style.parentNode !== null) style.parentNode.removeChild(style)
10886
+ const cards = typeof document.querySelectorAll === 'function'
10887
+ ? document.querySelectorAll('style[data-dsh-better-sidebar-left-css]')
10888
+ : []
10889
+ for (let index = 0; index < cards.length; index += 1) {
10890
+ if (cards[index].parentNode !== null) cards[index].parentNode.removeChild(cards[index])
10891
+ }
10892
+ injectedCss.clear()
9855
10893
  }
9856
10894
 
9857
10895
  // --- mounting the vendored halves -------------------------------------------
9858
10896
 
9859
10897
  function vendoredFactory(id) {
9860
- // tools/build.mjs declares VENDORED_TABLE with the five stitched factories;
10898
+ // tools/build.mjs declares VENDORED_TABLE with the six stitched factories;
9861
10899
  // running this file on its own (its own unit tests) has none, and mounts
9862
10900
  // nothing, which is exactly the "nothing vendored" case.
9863
10901
  if (typeof VENDORED_TABLE === 'undefined') return null
@@ -9879,6 +10917,8 @@ window.__ModuleLoader__.load({
9879
10917
  * click does nothing" failure this package exists to prevent: the page shows
9880
10918
  * the failure and the marker carries it.
9881
10919
  */
10920
+ const appliedModules = {}
10921
+
9882
10922
  function applyVendored(ctx, id) {
9883
10923
  try {
9884
10924
  const plugin = vendoredModule(id)
@@ -9886,6 +10926,7 @@ window.__ModuleLoader__.load({
9886
10926
  console.error('[' + NS + '] vendored ' + id + ' has no apply()', plugin)
9887
10927
  return { ok: false, error: 'no apply()' }
9888
10928
  }
10929
+ appliedModules[id] = plugin
9889
10930
  const result = plugin.apply(ctx)
9890
10931
  // A component whose apply() is async must not be able to fail silently.
9891
10932
  if (result !== null && typeof result === 'object' && typeof result.then === 'function') {
@@ -9917,12 +10958,57 @@ window.__ModuleLoader__.load({
9917
10958
  * returned is the component's own, so its state, storage keys and copy are the
9918
10959
  * ones its own page uses.
9919
10960
  */
10961
+ /** Component ids whose stylesheet this page has already injected. */
10962
+ const injectedCss = new Set()
10963
+
10964
+ /**
10965
+ * Inject the stylesheet a vendored component ships for its own settings card.
10966
+ *
10967
+ * A component injects its sheet from its apply(), which only runs when its row is
10968
+ * mounted. This page renders the card of a component whose row may be disabled
10969
+ * (the gate says so, and the card is still the place a reader turns the feature
10970
+ * on), so the sheet has to be asked for here - otherwise the card renders as raw
10971
+ * DOM: an invisible switch, unstyled segmented buttons, a link that runs into
10972
+ * its label. Components that export no css() supply their styling another way
10973
+ * (platform primitives) and are left alone.
10974
+ */
10975
+ function injectComponentStyles(id, plugin) {
10976
+ if (typeof document === 'undefined' || typeof document.createElement !== 'function') return
10977
+ const ui = plugin === null || plugin === undefined ? undefined : plugin.__ui
10978
+ if (ui === null || ui === undefined || typeof ui.css !== 'function') return
10979
+ const attribute = 'data-dsh-better-sidebar-left-css'
10980
+ if (injectedCss.has(id) === true) return
10981
+ let css
10982
+ try {
10983
+ css = ui.css()
10984
+ } catch (error) {
10985
+ console.error('[' + NS + '] vendored ' + id + ' stylesheet could not be read:', error)
10986
+ return
10987
+ }
10988
+ if (typeof css !== 'string' || css === '') return
10989
+ // The component injects the very same text from its own apply(); adding a
10990
+ // second copy would double every rule, including the ones with transitions.
10991
+ const existing = typeof document.querySelectorAll === 'function' ? document.querySelectorAll('style') : []
10992
+ for (let index = 0; index < existing.length; index += 1) {
10993
+ if (existing[index].textContent === css) {
10994
+ injectedCss.add(id)
10995
+ return
10996
+ }
10997
+ }
10998
+ const style = document.createElement('style')
10999
+ style.setAttribute(attribute, id)
11000
+ style.textContent = css
11001
+ document.head.appendChild(style)
11002
+ injectedCss.add(id)
11003
+ }
11004
+
9920
11005
  function vendoredConfigCard(id) {
9921
11006
  const entry = CONFIG_CARDS.filter((candidate) => candidate.id === id)[0]
9922
11007
  if (entry === undefined) return null
9923
11008
  try {
9924
- const plugin = vendoredModule(id)
11009
+ const plugin = appliedModules[id] !== undefined ? appliedModules[id] : vendoredModule(id)
9925
11010
  if (plugin === null || plugin === undefined) return null
11011
+ injectComponentStyles(id, plugin)
9926
11012
  let value = plugin
9927
11013
  for (let index = 0; index < entry.path.length; index += 1) {
9928
11014
  value = value === null || value === undefined ? undefined : value[entry.path[index]]
@@ -10043,7 +11129,7 @@ window.__ModuleLoader__.load({
10043
11129
  return typeof value === 'string' ? value : String(value)
10044
11130
  }
10045
11131
 
10046
- function renderRow(component, copy, t, locale) {
11132
+ function renderRow(component, copy, t, locale, options) {
10047
11133
  const state = stateOf(component)
10048
11134
  const badgeClass =
10049
11135
  state === 'mounted' ? 'dbsl-badge dbsl-badgeOk' : state === 'installed' ? 'dbsl-badge dbsl-badgeOff' : 'dbsl-badge dbsl-badgeNone'
@@ -10062,7 +11148,8 @@ window.__ModuleLoader__.load({
10062
11148
  if (why !== null) children.push(h('p', { className: 'dbsl-why', key: 'why' }, why))
10063
11149
  const failure = failures[component.id]
10064
11150
  if (failure !== undefined) children.push(h('p', { className: 'dsss-warn', key: 'failure' }, t('applyFailed') + ' ' + failure))
10065
- if (component.versionMatch === false) {
11151
+ const skipMismatch = options !== undefined && options !== null && options.skipMismatch === true
11152
+ if (component.versionMatch === false && !skipMismatch) {
10066
11153
  children.push(h('p', { className: 'dbsl-warn', key: 'mismatch' }, t('versionMismatch') + ' ' + String(component.installedVersion)))
10067
11154
  }
10068
11155
  return h('div', { className: 'dbsl-row', key: component.id }, children)
@@ -10082,6 +11169,84 @@ window.__ModuleLoader__.load({
10082
11169
  ])
10083
11170
  }
10084
11171
 
11172
+ // --- the left rail entry ----------------------------------------------------
11173
+
11174
+
11175
+ function LeftRailIcon(props) {
11176
+ const size = props !== null && props !== undefined && Number(props.size) > 0 ? Number(props.size) : 18
11177
+ return h(
11178
+ 'svg',
11179
+ { width: size, height: size, viewBox: '0 0 24 24', fill: 'none', 'aria-hidden': 'true' },
11180
+ h('rect', { x: 3.2, y: 4.2, width: 17.6, height: 15.6, rx: 3, stroke: 'currentColor', strokeWidth: 1.6 }),
11181
+ h('path', { d: 'M9 4.6v14.8', stroke: 'currentColor', strokeWidth: 1.6 }),
11182
+ h('path', { d: 'M12 9h5.4M12 12.4h5.4M12 15.4h3.4', stroke: 'currentColor', strokeWidth: 1.6, strokeLinecap: 'round' }),
11183
+ )
11184
+ }
11185
+
11186
+ let railTranslate = null
11187
+
11188
+ function railText(key) {
11189
+ if (railTranslate !== null) {
11190
+ const value = railTranslate(key)
11191
+ if (value !== null && value !== undefined && value !== '') return String(value)
11192
+ }
11193
+ return copyFor(zh, key) || key
11194
+ }
11195
+
11196
+ function railLabel() {
11197
+ return railText('panelEntry')
11198
+ }
11199
+
11200
+ const RAIL_TABS = [
11201
+ { id: 'dsh-declutter', labelKey: 'panelTabTidy' },
11202
+ { id: 'dsh-delete-session', labelKey: 'panelTabDelete' },
11203
+ { id: 'dsh-session-relocate', labelKey: 'panelTabMove' },
11204
+ ]
11205
+
11206
+ function availableTabs() {
11207
+ return RAIL_TABS.filter((tab) => vendoredConfigCard(tab.id) !== null)
11208
+ }
11209
+
11210
+ function railTabs(active, select) {
11211
+ const buttons = []
11212
+ const tabs = availableTabs()
11213
+ for (const tab of tabs) {
11214
+ const on = tab.id === active
11215
+ buttons.push(
11216
+ h(
11217
+ 'button',
11218
+ {
11219
+ key: tab.id,
11220
+ type: 'button',
11221
+ role: 'tab',
11222
+ 'aria-selected': on ? 'true' : 'false',
11223
+ className: on ? 'dbsl-tab dbsl-tabOn' : 'dbsl-tab',
11224
+ onClick: () => select(tab.id),
11225
+ },
11226
+ railText(tab.labelKey),
11227
+ ),
11228
+ )
11229
+ }
11230
+ return buttons.length === 0 ? null : h('div', { className: 'dbsl-tabs', role: 'tablist' }, buttons)
11231
+ }
11232
+
11233
+ function railPageOf(id) {
11234
+ const Card = vendoredConfigCard(id)
11235
+ return Card === null ? [] : [h(Card, { key: 'card-' + id, view: 'full', t: railText })]
11236
+ }
11237
+
11238
+ function LeftRailPage() {
11239
+ const tabs = availableTabs()
11240
+ const [tab, setTab] = react.useState(tabs.length === 0 ? null : tabs[0].id)
11241
+ const locale = currentLocale()
11242
+ const body = [
11243
+ h('h2', { className: 'dbsl-h1', key: 'h1' }, railText('panelHeading')),
11244
+ railTabs(tab, setTab),
11245
+ ]
11246
+ for (const node of railPageOf(tab)) body.push(node)
11247
+ return h('div', { className: 'dbsl-page' }, h('div', { className: 'dbsl-panel' }, body))
11248
+ }
11249
+
10085
11250
  /** This plugin page. Set by apply() so the panel never reaches for a global. */
10086
11251
  let ownCtx = null
10087
11252
 
@@ -10167,6 +11332,14 @@ window.__ModuleLoader__.load({
10167
11332
  ctx.slots.register({ name: 'plugins.row.config', key: NS + '#' + NS, locale: NS }, SidebarPanel),
10168
11333
  )
10169
11334
 
11335
+ railTranslate = t
11336
+ ctx.slots.inject('sidebar.panellist', () =>
11337
+ ctx.slots.register({ name: 'sidebar.panellist', id: NS, order: 40, label: railLabel }, LeftRailIcon),
11338
+ )
11339
+ ctx.slots.inject('main', () =>
11340
+ ctx.slots.register({ name: 'main', key: NS }, LeftRailPage),
11341
+ )
11342
+
10170
11343
  ctx.effect(
10171
11344
  () => () => {
10172
11345
  delete globalThis[DEBUG_KEY]
@@ -10188,6 +11361,12 @@ window.__ModuleLoader__.load({
10188
11361
  exports.NS = NS
10189
11362
  exports.STATUS_ROUTE = STATUS_ROUTE
10190
11363
  exports.SidebarPanel = SidebarPanel
11364
+ exports.LeftRailPage = LeftRailPage
11365
+ exports.LeftRailIcon = LeftRailIcon
11366
+ exports.railLabel = railLabel
11367
+ // Test-only entry: the injection runs from vendoredConfigCard, which no test
11368
+ // reaches without a rendered page.
11369
+ exports.__componentStyles = injectComponentStyles
10191
11370
  exports.stateOf = stateOf
10192
11371
  exports.shouldMount = shouldMount
10193
11372
  exports.mountableComponents = mountableComponents