@chatcode/cco-better-sidebar 0.18.0-alpha.4 → 0.18.0-rc.12
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/README.md +30 -9
- package/README_EN.md +30 -9
- package/cordis.patch.yml +6 -5
- package/lib/client-editor.js +10954 -395
- package/lib/client-mermaid.js +10835 -300
- package/lib/client-registry.js +4035 -2215
- package/lib/client-terminal.js +435 -292
- package/lib/client.js +4035 -2215
- package/lib/index.js +282 -47
- package/lib/types/client/LogoutConfirmDialog.d.ts +5 -0
- package/lib/types/client/PluginMarketSettingsSection.d.ts +7 -0
- package/lib/types/client/PluginMarketView.d.ts +7 -0
- package/lib/types/client/PluginProjectPicker.d.ts +13 -0
- package/lib/types/client/api.d.ts +21 -0
- package/lib/types/client/builtins/tabs.d.ts +13 -1
- package/lib/types/client/icons.d.ts +26 -8
- package/lib/types/client/locales-ja.d.ts +25 -0
- package/lib/types/client/locales.d.ts +39 -0
- package/lib/types/client/plugin-market-catalog.d.ts +25 -0
- package/lib/types/client/service.d.ts +1 -1
- package/lib/types/client/ui-tweaks/archive.d.ts +9 -28
- package/lib/types/client/ui-tweaks/branding.d.ts +1 -1
- package/lib/types/client/ui-tweaks/dom-text.d.ts +2 -0
- package/lib/types/client/ui-tweaks/index.d.ts +9 -1
- package/lib/types/client/ui-tweaks/sidebar-header.d.ts +6 -0
- package/lib/types/client/ui-tweaks/typography.d.ts +9 -0
- package/lib/types/config.d.ts +4 -3
- package/lib/types/context-types.d.ts +12 -14
- package/lib/types/login-page-script.d.ts +2 -0
- package/lib/types/login-route.d.ts +2 -0
- package/lib/types/plugin-market-api.d.ts +5 -0
- package/lib/types/plugin-market-shared.d.ts +59 -0
- package/lib/types/prefs-shared.d.ts +1 -1
- package/lib/types/pty-deps.d.ts +1 -1
- package/lib/types/ui-tweaks/config.d.ts +6 -7
- package/lib/types/ui-tweaks/index.d.ts +2 -3
- package/package.json +2 -2
- package/src/client/AccountMenu.tsx +12 -2
- package/src/client/BrowserView.tsx +1 -1
- package/src/client/DiffTab.tsx +1 -1
- package/src/client/EditorHost.tsx +1 -1
- package/src/client/FileTree.tsx +10 -5
- package/src/client/FreeWindow.tsx +2 -1
- package/src/client/GitView.tsx +7 -3
- package/src/client/LogoutConfirmDialog.tsx +39 -0
- package/src/client/PluginMarketSettingsSection.tsx +55 -0
- package/src/client/PluginMarketView.module.css +50 -0
- package/src/client/PluginMarketView.tsx +243 -0
- package/src/client/PluginProjectPicker.tsx +73 -0
- package/src/client/SideCardSection.tsx +2 -23
- package/src/client/Sidebar.tsx +2 -2
- package/src/client/TabBar.tsx +2 -4
- package/src/client/TextEditor.tsx +2 -1
- package/src/client/TreePanel.tsx +1 -2
- package/src/client/UsageHeatmapSection.tsx +1 -1
- package/src/client/api.ts +12 -0
- package/src/client/builtins/tabs.tsx +25 -5
- package/src/client/builtins/viewers.tsx +2 -1
- package/src/client/icons.tsx +57 -4
- package/src/client/index.tsx +10 -1
- package/src/client/intercept.tsx +1 -1
- package/src/client/locales-ja.ts +65 -0
- package/src/client/locales.ts +118 -1
- package/src/client/md-toc.tsx +1 -1
- package/src/client/mermaid.tsx +2 -1
- package/src/client/open-with-settings.tsx +1 -1
- package/src/client/plugin-market-catalog.ts +90 -0
- package/src/client/service.ts +1 -1
- package/src/client/sidebar.module.css +81 -19
- package/src/client/ui-tweaks/archive.tsx +118 -140
- package/src/client/ui-tweaks/branding.tsx +117 -49
- package/src/client/ui-tweaks/cachehit.tsx +24 -14
- package/src/client/ui-tweaks/dom-text.ts +12 -0
- package/src/client/ui-tweaks/index.tsx +75 -103
- package/src/client/ui-tweaks/sidebar-header.ts +73 -0
- package/src/client/ui-tweaks/typography.ts +38 -0
- package/src/config.ts +22 -2
- package/src/context-types.ts +5 -15
- package/src/index.ts +28 -21
- package/src/login-page-script.ts +107 -0
- package/src/login-route.ts +7 -4
- package/src/plugin-market-api.ts +88 -0
- package/src/plugin-market-shared.ts +30 -0
- package/src/prefs-shared.ts +1 -1
- package/src/pty-deps.ts +2 -2
- package/src/ui-tweaks/config.ts +12 -12
- package/src/ui-tweaks/index.ts +7 -13
|
@@ -8,6 +8,9 @@
|
|
|
8
8
|
*/
|
|
9
9
|
|
|
10
10
|
import type { ReactNode } from 'react'
|
|
11
|
+
import { api } from '../api.ts'
|
|
12
|
+
import { updateTextContent } from './dom-text.ts'
|
|
13
|
+
import { clearSidebarHeader, SIDEBAR_HEADER_CSS, syncSidebarHeader } from './sidebar-header.ts'
|
|
11
14
|
|
|
12
15
|
declare module '@deepseek-ai/dsh-client-ui-slots' {
|
|
13
16
|
interface SlotMap {
|
|
@@ -29,12 +32,19 @@ export const PROJECT_LOGO_URL = '/_dsh/ui-tweaks/assets/logo.svg'
|
|
|
29
32
|
const PROJECT_NAME = 'ChatCode CLI'
|
|
30
33
|
const HERO_TITLE = '与世界,深一度对话'
|
|
31
34
|
const LEGACY_HOST_BRAND_TEXT = /DSH\s*(?:Local\s*Build|本地构建)|DeepSeek\s*Harness|ChatCode\s*CLI/giu
|
|
32
|
-
const
|
|
35
|
+
const LEGACY_HOST_BRAND_LABEL_TEXT = /^(?:DSH\s*(?:Local\s*Build|本地构建)|ChatCode\s*CLI)$/iu
|
|
36
|
+
const BRAND_SURFACE = '[class*="brandIdentity"],[class*="brandName"],[class*="headline"],.dut-sidebar-brand-name'
|
|
37
|
+
const USER_CONTENT = 'input,textarea,[contenteditable],[role="textbox"],pre,code,script,style'
|
|
33
38
|
const HOST_BUILD_VERSION_TEXT = /^v?\d+\.\d+\.\d+(?:[-+][0-9a-z.-]+)*$/iu
|
|
34
39
|
const HERO_HEADLINE = /探索未至之境/u
|
|
35
40
|
const HERO_PREVIEW_TEXT = /^(?:预览版|Preview)$/iu
|
|
36
41
|
const FAVICON_MARKER = 'data-dut-project-favicon'
|
|
42
|
+
const SIDEBAR_VERSION_MARKER = 'data-dut-sidebar-version'
|
|
37
43
|
const VERSION_NOTICE_MARKER = 'data-dut-version-notice'
|
|
44
|
+
/** The General Settings "current version" row the plugin moves to the sidebar. */
|
|
45
|
+
const VERSION_ROW_TEXT = /^(?:当前版本|Current version)\s*[::]\s*v?\d/iu
|
|
46
|
+
/** The globally installed CLI version, fetched once from the sidebar host. */
|
|
47
|
+
let sidebarVersion: string | null = null
|
|
38
48
|
const VERSION_NOTICE = {
|
|
39
49
|
en: {
|
|
40
50
|
legacyTitle: 'Internal Testing Notice',
|
|
@@ -77,24 +87,31 @@ export function SidebarProjectName(): ReactNode {
|
|
|
77
87
|
}
|
|
78
88
|
|
|
79
89
|
export const BRANDING_CSS = `
|
|
80
|
-
/*
|
|
81
|
-
other
|
|
82
|
-
menus, the composer, text and shadows) remains owned by the host theme. */
|
|
90
|
+
/* Solid branding is limited to primary actions. Question choices only get a
|
|
91
|
+
faint token-derived tint; other surfaces remain owned by the host theme. */
|
|
83
92
|
body:not([data-ds-dark-theme]) .dut-unicom-primary-action{background:linear-gradient(135deg,#9B0B09,#b71916) !important;border-color:#9B0B09 !important;color:#fff !important;box-shadow:0 7px 18px rgba(155,11,9,.24) !important}
|
|
84
93
|
body:not([data-ds-dark-theme]) .dut-unicom-primary-action:hover{background:linear-gradient(135deg,#b71916,#cf302c) !important;border-color:#b71916 !important;color:#fff !important;box-shadow:0 10px 24px rgba(155,11,9,.30) !important}
|
|
85
94
|
body:not([data-ds-dark-theme]) .dut-unicom-primary-action:active{transform:translateY(1px);box-shadow:0 4px 11px rgba(155,11,9,.22) !important}
|
|
86
95
|
/* In dark mode, alter only the resting background of primary buttons. Once
|
|
87
96
|
hovered, the host owns the complete interaction treatment again. */
|
|
88
97
|
body[data-ds-dark-theme] .dut-unicom-primary-action:not(:hover){background:#9B0B09 !important}
|
|
98
|
+
/* Only the host's question composer, never global radio/checkbox controls.
|
|
99
|
+
Keep normal text, focus rings and disabled behavior; no gradient or shadow. */
|
|
100
|
+
[data-question-key] button:is([role="radio"],[role="checkbox"]):hover:not(:disabled){background:color-mix(in srgb,var(--dsw-alias-state-error-primary) 5%,transparent)}
|
|
101
|
+
[data-question-key] button:is([role="radio"],[role="checkbox"])[aria-checked="true"]{background:color-mix(in srgb,var(--dsw-alias-state-error-primary) 8%,transparent);border-color:color-mix(in srgb,var(--dsw-alias-state-error-primary) 18%,transparent)}
|
|
102
|
+
[data-question-key] button:is([role="radio"],[role="checkbox"])[aria-checked="true"]:hover:not(:disabled){background:color-mix(in srgb,var(--dsw-alias-state-error-primary) 10%,transparent)}
|
|
89
103
|
.dut-project-logo{display:block;object-fit:contain}
|
|
90
|
-
.dut-left-logo{width:
|
|
91
|
-
|
|
92
|
-
.dut-
|
|
93
|
-
|
|
94
|
-
|
|
95
|
-
|
|
96
|
-
|
|
97
|
-
|
|
104
|
+
.dut-left-logo{width:24px !important;height:24px !important}
|
|
105
|
+
/* Legacy host marks remain in React's tree; only their painted appearance changes. */
|
|
106
|
+
svg.dut-project-logo{background:url("${PROJECT_LOGO_URL}") center/contain no-repeat}
|
|
107
|
+
svg.dut-project-logo>*{visibility:hidden}
|
|
108
|
+
.dut-brand-title{font:var(--dsw-font-s-strong-14) !important}
|
|
109
|
+
.dut-sidebar-logo{width:24px !important;height:24px !important}
|
|
110
|
+
.dut-sidebar-brand-name{font:var(--dsw-font-s-strong-14) !important;letter-spacing:-.01em !important;white-space:nowrap}
|
|
111
|
+
/* The version the plugin injects beside the sidebar wordmark. */
|
|
112
|
+
.dut-sidebar-version{margin-left:8px;font-size:12px !important;font-weight:500 !important;line-height:22px !important;color:var(--dsw-alias-label-secondary) !important;letter-spacing:0 !important;white-space:nowrap}
|
|
113
|
+
.dut-version-row-hidden{display:none !important}
|
|
114
|
+
${SIDEBAR_HEADER_CSS}
|
|
98
115
|
.dut-brand-version{display:none !important}
|
|
99
116
|
.dut-hero-preview{display:none !important}
|
|
100
117
|
.dut-hero-logo{width:60px !important;height:60px !important}
|
|
@@ -104,23 +121,26 @@ body[data-ds-dark-theme] .dut-unicom-primary-action:not(:hover){background:#9B0B
|
|
|
104
121
|
`
|
|
105
122
|
|
|
106
123
|
function hasPrimaryLabel(button: HTMLButtonElement): boolean {
|
|
107
|
-
|
|
108
|
-
|
|
124
|
+
// Plugin cards own their appearance. Inventory disclosure buttons include
|
|
125
|
+
// descriptions, where words like "install" do not identify a primary action.
|
|
126
|
+
if (button.closest('[data-chatcode-plugin-market], [data-plugin-module]')) return false
|
|
127
|
+
// User/model text can itself be "Send" or contain "发送". These are choices
|
|
128
|
+
// and transcript disclosures, not submit/install actions, regardless of copy.
|
|
129
|
+
if (button.closest('[data-question-key], [data-tool], [data-variant="think"], [data-disclosure-row]')) return false
|
|
130
|
+
const role = button.getAttribute('role')
|
|
131
|
+
if ((role !== null && role !== 'button') || button.hasAttribute('aria-expanded')) return false
|
|
132
|
+
if (button.classList.contains('dut-sidebar-brand') || button.classList.contains('dut-sidebar-new-session')) return false
|
|
133
|
+
// Prefer the accessible action name. Never match words inside descriptions,
|
|
134
|
+
// nor concatenate title/text/aria-label into an unbounded substring search.
|
|
135
|
+
const label = (button.getAttribute('aria-label')?.trim() || button.title.trim() || button.textContent || '')
|
|
136
|
+
.replace(/\s+/gu, ' ').trim().toLowerCase()
|
|
137
|
+
return /^(?:发送(?:消息)?|排队发送|插话发送|send(?: message)?|queue message|steer (?:queued )?message|安装|install)$/u.test(label)
|
|
109
138
|
}
|
|
110
139
|
|
|
111
|
-
/**
|
|
112
|
-
function
|
|
140
|
+
/** Restyle a legacy host SVG without replacing the DOM node held by React. */
|
|
141
|
+
function styleHostLogo(svg: SVGElement): void {
|
|
113
142
|
if (svg.classList.contains('dut-project-logo')) return
|
|
114
|
-
|
|
115
|
-
image.className = `${svg.getAttribute('class') ?? ''} dut-project-logo dut-left-logo`.trim()
|
|
116
|
-
image.src = PROJECT_LOGO_URL
|
|
117
|
-
image.alt = ''
|
|
118
|
-
image.setAttribute('aria-hidden', 'true')
|
|
119
|
-
const width = svg.getAttribute('width')
|
|
120
|
-
const height = svg.getAttribute('height')
|
|
121
|
-
if (width !== null) image.setAttribute('width', width)
|
|
122
|
-
if (height !== null) image.setAttribute('height', height)
|
|
123
|
-
svg.replaceWith(image)
|
|
143
|
+
svg.classList.add('dut-project-logo', 'dut-left-logo')
|
|
124
144
|
}
|
|
125
145
|
|
|
126
146
|
/** Locate the mark adjacent to an otherwise unstructured sidebar brand label. */
|
|
@@ -131,12 +151,12 @@ function replaceLogoBesideBrandLabel(label: HTMLElement): void {
|
|
|
131
151
|
]
|
|
132
152
|
for (const candidate of nearby) {
|
|
133
153
|
if (candidate instanceof SVGElement) {
|
|
134
|
-
|
|
154
|
+
styleHostLogo(candidate)
|
|
135
155
|
return
|
|
136
156
|
}
|
|
137
157
|
const svg = candidate?.querySelector('svg')
|
|
138
158
|
if (svg instanceof SVGElement) {
|
|
139
|
-
|
|
159
|
+
styleHostLogo(svg)
|
|
140
160
|
return
|
|
141
161
|
}
|
|
142
162
|
}
|
|
@@ -148,12 +168,40 @@ function hideVersionBesideBrandLabel(label: HTMLElement): void {
|
|
|
148
168
|
if (container === null) return
|
|
149
169
|
for (const sibling of container.children) {
|
|
150
170
|
if (sibling === label || !(sibling instanceof HTMLElement)) continue
|
|
171
|
+
if (sibling.hasAttribute(SIDEBAR_VERSION_MARKER)) continue
|
|
151
172
|
if (!HOST_BUILD_VERSION_TEXT.test(sibling.textContent?.trim() ?? '')) continue
|
|
152
173
|
sibling.classList.add('dut-brand-version')
|
|
153
174
|
sibling.setAttribute('aria-hidden', 'true')
|
|
154
175
|
}
|
|
155
176
|
}
|
|
156
177
|
|
|
178
|
+
/** Insert or update the version span immediately after the sidebar wordmark. */
|
|
179
|
+
function injectSidebarVersion(name: HTMLElement, version: string): void {
|
|
180
|
+
const container = name.parentElement
|
|
181
|
+
if (container === null) return
|
|
182
|
+
for (const sibling of container.children) {
|
|
183
|
+
if (sibling === name || !(sibling instanceof HTMLElement)) continue
|
|
184
|
+
if (!sibling.hasAttribute(SIDEBAR_VERSION_MARKER)) continue
|
|
185
|
+
if (sibling.textContent !== version) sibling.textContent = version
|
|
186
|
+
return
|
|
187
|
+
}
|
|
188
|
+
const span = document.createElement('span')
|
|
189
|
+
span.className = 'dut-sidebar-version'
|
|
190
|
+
span.setAttribute(SIDEBAR_VERSION_MARKER, '')
|
|
191
|
+
span.textContent = version
|
|
192
|
+
name.after(span)
|
|
193
|
+
}
|
|
194
|
+
|
|
195
|
+
/** Hide the General Settings "当前版本" row, now that the sidebar owns it. */
|
|
196
|
+
function hideSettingsVersionRow(): void {
|
|
197
|
+
document.querySelectorAll<HTMLElement>('body *').forEach((row) => {
|
|
198
|
+
if (row.childElementCount !== 0) return
|
|
199
|
+
if (!VERSION_ROW_TEXT.test(row.textContent?.trim() ?? '')) return
|
|
200
|
+
row.classList.add('dut-version-row-hidden')
|
|
201
|
+
row.setAttribute('aria-hidden', 'true')
|
|
202
|
+
})
|
|
203
|
+
}
|
|
204
|
+
|
|
157
205
|
/** Replace the registry build's older upstream notice with ChatCode product copy. */
|
|
158
206
|
function syncVersionNotice(): void {
|
|
159
207
|
document.querySelectorAll<HTMLElement>(
|
|
@@ -169,17 +217,18 @@ function syncVersionNotice(): void {
|
|
|
169
217
|
dialog.setAttribute('aria-label', notice.title)
|
|
170
218
|
dialog.setAttribute(VERSION_NOTICE_MARKER, '')
|
|
171
219
|
dialog.dataset.dutVersionNoticeLanguage = language
|
|
172
|
-
if (heading !== null) heading
|
|
220
|
+
if (heading !== null) updateTextContent(heading, notice.title)
|
|
173
221
|
const paragraphs = dialog.querySelectorAll<HTMLParagraphElement>('p')
|
|
174
222
|
notice.paragraphs.forEach((text, index) => {
|
|
175
223
|
const paragraph = paragraphs.item(index)
|
|
176
|
-
if (paragraph !== null) paragraph
|
|
224
|
+
if (paragraph !== null) updateTextContent(paragraph, text)
|
|
177
225
|
})
|
|
178
226
|
})
|
|
179
227
|
}
|
|
180
228
|
|
|
181
229
|
function syncBranding(): void {
|
|
182
|
-
|
|
230
|
+
const title = document.title.replace(LEGACY_HOST_BRAND_TEXT, PROJECT_NAME)
|
|
231
|
+
if (title !== document.title) document.title = title
|
|
183
232
|
|
|
184
233
|
// The host deliberately renders the blank-session preview badge as a
|
|
185
234
|
// third headline column. ChatCode is the production identity here, so
|
|
@@ -193,25 +242,30 @@ function syncBranding(): void {
|
|
|
193
242
|
|
|
194
243
|
// The sidebar label identifies the precise icon to its left. Process it
|
|
195
244
|
// before the generic text pass so the sibling relationship is still intact.
|
|
196
|
-
document.querySelectorAll<HTMLElement>(
|
|
197
|
-
|
|
198
|
-
|
|
199
|
-
|
|
200
|
-
|
|
201
|
-
|
|
245
|
+
document.querySelectorAll<HTMLElement>(BRAND_SURFACE).forEach((surface) => {
|
|
246
|
+
surface.querySelectorAll<HTMLElement>('*').forEach((element) => {
|
|
247
|
+
if (element.closest(USER_CONTENT) !== null) return
|
|
248
|
+
if (element.childElementCount !== 0 || !LEGACY_HOST_BRAND_LABEL_TEXT.test(element.textContent?.trim() ?? '')) return
|
|
249
|
+
updateTextContent(element, PROJECT_NAME)
|
|
250
|
+
element.classList.add('dut-brand-title')
|
|
251
|
+
replaceLogoBesideBrandLabel(element)
|
|
252
|
+
hideVersionBesideBrandLabel(element)
|
|
253
|
+
// The sidebar wordmark carries its dedicated slot class; inject the version
|
|
254
|
+
// only there, never onto the hero headline that shares the label text.
|
|
255
|
+
if (element.classList.contains('dut-sidebar-brand-name') && sidebarVersion !== null) {
|
|
256
|
+
injectSidebarVersion(element, sidebarVersion)
|
|
257
|
+
}
|
|
258
|
+
})
|
|
202
259
|
})
|
|
203
260
|
|
|
204
|
-
const
|
|
205
|
-
|
|
206
|
-
|
|
207
|
-
|
|
208
|
-
|
|
209
|
-
|
|
210
|
-
|
|
211
|
-
node.data = node.data.replace(LEGACY_HOST_BRAND_TEXT, PROJECT_NAME)
|
|
212
|
-
LEGACY_HOST_BRAND_TEXT.lastIndex = 0
|
|
261
|
+
for (const surface of document.querySelectorAll(BRAND_SURFACE)) {
|
|
262
|
+
const walker = document.createTreeWalker(surface, NodeFilter.SHOW_TEXT)
|
|
263
|
+
let node: Text | null
|
|
264
|
+
while ((node = walker.nextNode() as Text | null) !== null) {
|
|
265
|
+
if (node.parentElement?.closest(USER_CONTENT) !== null) continue
|
|
266
|
+
const next = node.data.replace(LEGACY_HOST_BRAND_TEXT, PROJECT_NAME).replace(HERO_HEADLINE, PROJECT_NAME)
|
|
267
|
+
if (next !== node.data) node.data = next
|
|
213
268
|
}
|
|
214
|
-
if (HERO_HEADLINE.test(node.data)) node.data = node.data.replace(HERO_HEADLINE, PROJECT_NAME)
|
|
215
269
|
}
|
|
216
270
|
|
|
217
271
|
// Keep the product name in the sidebar, but use a more expressive headline
|
|
@@ -221,18 +275,22 @@ function syncBranding(): void {
|
|
|
221
275
|
const title = Array.from(headline?.querySelectorAll<HTMLElement>('*') ?? [])
|
|
222
276
|
.find(element => element.childElementCount === 0 && element.textContent?.trim() === PROJECT_NAME)
|
|
223
277
|
if (title === undefined) return
|
|
224
|
-
title
|
|
278
|
+
updateTextContent(title, HERO_TITLE)
|
|
225
279
|
title.classList.add('dut-hero-title')
|
|
226
280
|
})
|
|
227
281
|
|
|
228
282
|
syncVersionNotice()
|
|
229
283
|
|
|
284
|
+
// The General Settings version row moved to the sidebar; keep it hidden.
|
|
285
|
+
hideSettingsVersionRow()
|
|
286
|
+
|
|
230
287
|
// Older host builds expose a brand-mark wrapper but no text-bearing sibling.
|
|
231
288
|
document.querySelectorAll<HTMLElement>('[class*="brandMark"]').forEach((host) => {
|
|
232
289
|
const svg = host.matches('svg') ? host : host.querySelector('svg')
|
|
233
|
-
if (svg instanceof SVGElement)
|
|
290
|
+
if (svg instanceof SVGElement) styleHostLogo(svg)
|
|
234
291
|
})
|
|
235
292
|
|
|
293
|
+
syncSidebarHeader()
|
|
236
294
|
document.querySelectorAll<HTMLButtonElement>('button').forEach((button) => {
|
|
237
295
|
button.classList.toggle('dut-unicom-primary-action', hasPrimaryLabel(button))
|
|
238
296
|
})
|
|
@@ -272,11 +330,21 @@ export function installBranding(): () => void {
|
|
|
272
330
|
})
|
|
273
331
|
}
|
|
274
332
|
syncBranding()
|
|
333
|
+
// Fetch the installed version asynchronously; once it lands, re-run the
|
|
334
|
+
// pass so the sidebar wordmark gets its version span.
|
|
335
|
+
void api.chatcodeInstalledVersion()
|
|
336
|
+
.then(({ version }) => {
|
|
337
|
+
if (version === null || version === '') return
|
|
338
|
+
sidebarVersion = version
|
|
339
|
+
schedule()
|
|
340
|
+
})
|
|
341
|
+
.catch(() => {})
|
|
275
342
|
const observer = new MutationObserver(schedule)
|
|
276
343
|
observer.observe(document.body, { childList: true, characterData: true, subtree: true })
|
|
277
344
|
return () => {
|
|
278
345
|
observer.disconnect()
|
|
279
346
|
if (frame !== undefined) window.cancelAnimationFrame(frame)
|
|
347
|
+
clearSidebarHeader()
|
|
280
348
|
favicon.remove()
|
|
281
349
|
style.remove()
|
|
282
350
|
}
|
|
@@ -65,8 +65,14 @@ export function PreciseCacheHitEntry({ useProjection }: PreciseCacheHitEntryProp
|
|
|
65
65
|
const bands = document.querySelectorAll<HTMLElement>('[data-slot="conversation.composer.dock"]')
|
|
66
66
|
if (bands.length === 0) return
|
|
67
67
|
|
|
68
|
-
/**
|
|
69
|
-
const patched = new Map<
|
|
68
|
+
/** Preserve host-owned nodes, including icons and React's text-node references. */
|
|
69
|
+
const patched = new Map<Text, { original: string; rewritten: string }>()
|
|
70
|
+
const restore = (node: Text): void => {
|
|
71
|
+
const previous = patched.get(node)
|
|
72
|
+
// React may already have supplied newer copy; cleanup must not undo it.
|
|
73
|
+
if (previous !== undefined && node.data === previous.rewritten) node.data = previous.original
|
|
74
|
+
patched.delete(node)
|
|
75
|
+
}
|
|
70
76
|
|
|
71
77
|
/**
|
|
72
78
|
* Two-decimal share over the raw buckets; null while there is nothing
|
|
@@ -89,21 +95,28 @@ export function PreciseCacheHitEntry({ useProjection }: PreciseCacheHitEntryProp
|
|
|
89
95
|
if (precise === null) {
|
|
90
96
|
// Projection gone (session switch race): undo any rewrite so the
|
|
91
97
|
// stock integer shows again instead of a stale figure.
|
|
92
|
-
const
|
|
93
|
-
|
|
94
|
-
|
|
98
|
+
for (const node of patched.keys()) {
|
|
99
|
+
if (el.contains(node)) restore(node)
|
|
100
|
+
}
|
|
95
101
|
continue
|
|
96
102
|
}
|
|
97
|
-
|
|
98
|
-
|
|
99
|
-
|
|
103
|
+
const walker = document.createTreeWalker(el, NodeFilter.SHOW_TEXT)
|
|
104
|
+
let node: Text | null
|
|
105
|
+
while ((node = walker.nextNode() as Text | null) !== null) {
|
|
106
|
+
if (!PERCENT_IN_SPAN_PATTERN.test(node.data)) continue
|
|
107
|
+
const previous = patched.get(node)
|
|
108
|
+
const original = previous !== undefined && node.data === previous.rewritten ? previous.original : node.data
|
|
109
|
+
const rewritten = node.data.replace(PERCENT_IN_SPAN_PATTERN, `${precise}%`)
|
|
110
|
+
patched.set(node, { original, rewritten })
|
|
111
|
+
if (rewritten !== node.data) node.data = rewritten
|
|
112
|
+
}
|
|
100
113
|
}
|
|
101
114
|
}
|
|
102
115
|
}
|
|
103
116
|
|
|
104
117
|
apply()
|
|
105
|
-
//
|
|
106
|
-
//
|
|
118
|
+
// Mutate Text.data only: textContent would remove the host's icon and text
|
|
119
|
+
// children, making a later React commit fail with NotFoundError.
|
|
107
120
|
const observer = new MutationObserver(apply)
|
|
108
121
|
for (const band of bands) {
|
|
109
122
|
observer.observe(band, { childList: true, characterData: true, subtree: true })
|
|
@@ -111,10 +124,7 @@ export function PreciseCacheHitEntry({ useProjection }: PreciseCacheHitEntryProp
|
|
|
111
124
|
return () => {
|
|
112
125
|
observer.disconnect()
|
|
113
126
|
// Toggle-off/unmount must not leave a stale precise figure behind.
|
|
114
|
-
for (const
|
|
115
|
-
if ((el.textContent ?? '') !== original) el.textContent = original
|
|
116
|
-
}
|
|
117
|
-
patched.clear()
|
|
127
|
+
for (const node of patched.keys()) restore(node)
|
|
118
128
|
}
|
|
119
129
|
}, [usage])
|
|
120
130
|
|
|
@@ -0,0 +1,12 @@
|
|
|
1
|
+
/** Update copy without detaching the text/element nodes owned by the host's React tree. */
|
|
2
|
+
export function updateTextContent(element: Element, value: string): void {
|
|
3
|
+
if (element.textContent === value) return
|
|
4
|
+
const walker = document.createTreeWalker(element, NodeFilter.SHOW_TEXT)
|
|
5
|
+
let node = walker.nextNode()
|
|
6
|
+
let remaining = value
|
|
7
|
+
while (node !== null) {
|
|
8
|
+
if (node.nodeValue !== remaining) node.nodeValue = remaining
|
|
9
|
+
remaining = ''
|
|
10
|
+
node = walker.nextNode()
|
|
11
|
+
}
|
|
12
|
+
}
|