dsh-asuta-model-group-label 0.1.12 → 0.1.13
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 +6 -2
- package/client.js +171 -35
- package/package.json +1 -1
package/README.md
CHANGED
|
@@ -2,8 +2,12 @@
|
|
|
2
2
|
|
|
3
3
|
在 DSH 输入栏的模型按钮显示“分组名称/模型名称”,并保留原有徽标及推理强度。点击模型右侧的星标即可收藏;收藏项会出现在菜单顶部,原分组中的条目仍保留。收藏记录保存在当前客户端。
|
|
4
4
|
|
|
5
|
-
|
|
5
|
+
星标旁的小色块可以为模型设置背景色或恢复无色。颜色保存在当前客户端,同时显示在收藏区和原分组中。
|
|
6
|
+
|
|
7
|
+
在模型菜单中,用 ↑ / ↓ 浏览,按 Enter 选择模型,按 F2 切换收藏,按 F3 打开当前高亮模型的色板。
|
|
6
8
|
|
|
7
9
|
Show the selected model as “group name/model name” in the DSH composer, with its original badge and reasoning effort. Star a model to add it to the top of the menu while keeping its original entry. Favorites are saved in the current client.
|
|
8
10
|
|
|
9
|
-
Use
|
|
11
|
+
Use the swatch next to the star to set or clear the model's background color. The color is saved in the current client and shown in both lists.
|
|
12
|
+
|
|
13
|
+
Use Up / Down to browse, Enter to select a model, F2 to toggle favorites, and F3 to open the highlighted model's color palette.
|
package/client.js
CHANGED
|
@@ -6,37 +6,63 @@ window.__ModuleLoader__.load({
|
|
|
6
6
|
const slot = 'conversation.input.model.label'
|
|
7
7
|
const badgeLayout = { display: 'inline-flex', verticalAlign: 'baseline', alignItems: 'center', maxWidth: '100%', gap: 4, whiteSpace: 'nowrap' }
|
|
8
8
|
const storageKey = 'dsh-model-group-label:favorites:v1'
|
|
9
|
+
const colorStorageKey = 'dsh-model-group-label:colors:v1'
|
|
10
|
+
const palette = {
|
|
11
|
+
rose: ['#e66885', '玫红', 'Rose'], amber: ['#d4942f', '琥珀', 'Amber'],
|
|
12
|
+
green: ['#43ab77', '绿色', 'Green'], teal: ['#2aa4a6', '青色', 'Teal'],
|
|
13
|
+
blue: ['#629af0', '蓝色', 'Blue'], violet: ['#ab80ed', '紫色', 'Violet'],
|
|
14
|
+
}
|
|
9
15
|
const rowSelector = 'button[role="menuitemradio"]:has([data-cdx-model-key])'
|
|
10
16
|
const modelPane = '[role="group"][style*="--dsh-model-anchor:"]'
|
|
11
17
|
const listSelector = '[role="menu"].scrollable'
|
|
12
18
|
const modelList = modelPane + ' > ' + listSelector
|
|
13
19
|
const changedNodeSelector = rowSelector + ', [data-cdx-model-key], ' + listSelector
|
|
14
20
|
function installFavorites(ctx) {
|
|
15
|
-
let favorites = readFavorites(), scheduled = false, stopped = false
|
|
16
|
-
const
|
|
21
|
+
let favorites = readFavorites(), colors = readColors(), scheduled = false, stopped = false, picker
|
|
22
|
+
const controls = new Map(), menus = new Map(), openingLists = new Map()
|
|
17
23
|
function readFavorites() {
|
|
18
24
|
try { return new Set(JSON.parse(localStorage.getItem(storageKey) || '[]').filter(key => typeof key === 'string')) }
|
|
19
25
|
catch { return new Set() }
|
|
20
26
|
}
|
|
27
|
+
function readColors() {
|
|
28
|
+
try {
|
|
29
|
+
return new Map(Object.entries(JSON.parse(localStorage.getItem(colorStorageKey) || '{}'))
|
|
30
|
+
.filter(([, color]) => Object.hasOwn(palette, color)))
|
|
31
|
+
} catch { return new Map() }
|
|
32
|
+
}
|
|
33
|
+
function isChinese() {
|
|
34
|
+
return (ctx.locale.getSnapshot?.().active || navigator.language).toLowerCase().startsWith('zh')
|
|
35
|
+
}
|
|
21
36
|
function copy(key) {
|
|
22
|
-
|
|
23
|
-
|
|
37
|
+
return (isChinese()
|
|
38
|
+
? { folder: '收藏模型', add: '收藏', remove: '取消收藏', color: '模型背景色', clear: '无颜色' }
|
|
39
|
+
: { folder: 'Favorite models', add: 'Favorite', remove: 'Remove favorite', color: 'Model background color', clear: 'No color' })[key]
|
|
24
40
|
}
|
|
25
41
|
const css = document.createElement('style')
|
|
26
42
|
css.dataset.plugin = 'dsh-asuta-model-group-label'
|
|
27
43
|
// Keep the native anchor and viewport insets; don't resize to each result set.
|
|
28
44
|
css.textContent = modelPane + '{width:min(280px,calc(100vw - 24px));height:stretch}' +
|
|
29
45
|
'[data-menu-group]:has(>[data-cdx-model-row]){position:relative}' +
|
|
30
|
-
'[data-menu-group]>[data-cdx-model-row]{padding-inline-end:
|
|
31
|
-
'.cdx-model-star{box-sizing:border-box;width:28px;height:28px;border:0;background:transparent;color:var(--dsw-alias-label-secondary);border-radius:6px;cursor:pointer;font:inherit;font-size:17px}' +
|
|
32
|
-
'[data-menu-group]>.cdx-model-star{position:absolute;inset-inline-end:3px;transform:translateY(calc(-100% - 3px))}' +
|
|
46
|
+
'[data-menu-group]>[data-cdx-model-row]{padding-inline-end:59px}' +
|
|
47
|
+
'.cdx-model-star,.cdx-model-color{box-sizing:border-box;width:28px;height:28px;border:0;background:transparent;color:var(--dsw-alias-label-secondary);border-radius:6px;cursor:pointer;font:inherit;font-size:17px}' +
|
|
48
|
+
'[data-menu-group]>.cdx-model-star,[data-menu-group]>.cdx-model-color{position:absolute;inset-inline-end:3px;transform:translateY(calc(-100% - 3px))}' +
|
|
49
|
+
'[data-menu-group]>.cdx-model-color{inset-inline-end:32px}' +
|
|
50
|
+
'.cdx-model-color{width:25px;display:grid;place-items:center;order:1;opacity:.55}' +
|
|
51
|
+
'.cdx-model-color:hover,.cdx-model-color:focus-visible,.cdx-model-color[aria-expanded="true"],.cdx-model-color[data-colored]{opacity:1}' +
|
|
52
|
+
'.cdx-model-color::before{content:"";width:12px;height:12px;box-sizing:border-box;border:1px solid currentColor;border-radius:4px;background:var(--cdx-model-tint,transparent)}' +
|
|
53
|
+
'.cdx-model-favorite-row>.cdx-model-star{order:2}' +
|
|
33
54
|
'.cdx-model-star[aria-pressed="true"]{color:var(--dsw-alias-brand-primary,#eab54d)}' +
|
|
34
|
-
'.cdx-model-star:hover,.cdx-model-favorite-choice:hover{background:var(--dsw-alias-interactive-bg-hover)}' +
|
|
55
|
+
'.cdx-model-star:hover,.cdx-model-color:hover,.cdx-model-favorite-choice:hover{background:var(--dsw-alias-interactive-bg-hover)}' +
|
|
35
56
|
'.cdx-model-favorites{margin-bottom:4px;border-bottom:1px solid var(--dsw-alias-border-l2);padding-bottom:4px}' +
|
|
36
57
|
'.cdx-model-favorites-label{padding:4px 7px 2px;color:var(--dsw-alias-label-tertiary);font-size:11px;line-height:16px;font-weight:500}' +
|
|
37
|
-
'.cdx-model-favorite-row{display:flex;align-items:center;padding-inline-end:3px;gap:3px}' +
|
|
58
|
+
'.cdx-model-favorite-row{display:flex;align-items:center;padding-inline-end:3px;gap:3px;border-radius:var(--dsw-radius-md)}' +
|
|
38
59
|
'.cdx-model-favorite-choice{flex:1;min-width:0;text-align:start;min-height:34px;padding:5px 7px;border:0;border-radius:var(--dsw-radius-md);background:transparent;color:inherit;font-family:inherit;font-size:13px;line-height:18px;font-weight:400;cursor:pointer;white-space:nowrap;overflow:hidden;text-overflow:ellipsis}' +
|
|
39
|
-
'
|
|
60
|
+
'[data-cdx-model-color]{background-image:linear-gradient(color-mix(in srgb,var(--cdx-model-tint) 22%,transparent),color-mix(in srgb,var(--cdx-model-tint) 22%,transparent))!important}' +
|
|
61
|
+
'.cdx-model-palette{position:fixed;inset:auto;margin:0;box-sizing:border-box;max-width:calc(100vw - 16px);width:max-content;padding:8px;border:1px solid var(--dsw-alias-border-l2);border-radius:10px;background:var(--dsw-alias-bg-l2,Canvas);color:var(--dsw-alias-label-primary,CanvasText);box-shadow:0 8px 24px #0004;z-index:1000;-webkit-app-region:no-drag}' +
|
|
62
|
+
'.cdx-model-swatches{display:flex;flex-wrap:wrap;gap:4px}' +
|
|
63
|
+
'.cdx-model-swatch{height:26px;min-width:26px;padding:0 5px;border:1px solid var(--dsw-alias-border-l2);border-radius:6px;background:var(--cdx-model-tint,transparent);color:inherit;cursor:pointer;font:inherit;font-size:11px}' +
|
|
64
|
+
'.cdx-model-swatch[aria-pressed="true"]{box-shadow:inset 0 0 0 2px var(--dsw-alias-label-primary,CanvasText)}' +
|
|
65
|
+
'.cdx-model-star:focus-visible,.cdx-model-color:focus-visible,.cdx-model-swatch:focus-visible,.cdx-model-favorite-choice:focus-visible{outline:2px solid var(--dsw-alias-brand-primary);outline-offset:-2px}'
|
|
40
66
|
document.head.append(css)
|
|
41
67
|
function toggle(key) {
|
|
42
68
|
favorites.has(key) ? favorites.delete(key) : favorites.add(key)
|
|
@@ -58,6 +84,87 @@ window.__ModuleLoader__.load({
|
|
|
58
84
|
star.addEventListener('click', action)
|
|
59
85
|
return star
|
|
60
86
|
}
|
|
87
|
+
function colorButton(getKey) {
|
|
88
|
+
const button = document.createElement('button')
|
|
89
|
+
button.type = 'button'; button.className = 'cdx-model-color'
|
|
90
|
+
button.setAttribute('aria-keyshortcuts', 'F3')
|
|
91
|
+
button.setAttribute('aria-expanded', 'false')
|
|
92
|
+
button.addEventListener('click', event => openPalette(button, getKey, event.detail === 0 ? document.activeElement : button))
|
|
93
|
+
return button
|
|
94
|
+
}
|
|
95
|
+
function paintColor(row, button, key, name) {
|
|
96
|
+
const color = colors.get(key)
|
|
97
|
+
if (color) {
|
|
98
|
+
row.dataset.cdxModelColor = color
|
|
99
|
+
row.style.setProperty('--cdx-model-tint', palette[color][0])
|
|
100
|
+
button.style.setProperty('--cdx-model-tint', palette[color][0])
|
|
101
|
+
} else {
|
|
102
|
+
delete row.dataset.cdxModelColor
|
|
103
|
+
row.style.removeProperty('--cdx-model-tint')
|
|
104
|
+
button.style.removeProperty('--cdx-model-tint')
|
|
105
|
+
}
|
|
106
|
+
button.toggleAttribute('data-colored', !!color)
|
|
107
|
+
const title = copy('color') + ' · ' + name
|
|
108
|
+
button.title = title + ' (F3)'
|
|
109
|
+
button.setAttribute('aria-label', title)
|
|
110
|
+
}
|
|
111
|
+
function closePalette(restoreFocus = false) {
|
|
112
|
+
if (!picker) return
|
|
113
|
+
const { button, popup, listeners, previousFocus } = picker
|
|
114
|
+
picker = undefined
|
|
115
|
+
listeners.abort()
|
|
116
|
+
button.setAttribute('aria-expanded', 'false')
|
|
117
|
+
const focus = previousFocus?.isConnected ? previousFocus : button
|
|
118
|
+
if (restoreFocus && focus.isConnected) focus.focus({ preventScroll: true })
|
|
119
|
+
popup.remove()
|
|
120
|
+
}
|
|
121
|
+
function openPalette(button, getKey, previousFocus) {
|
|
122
|
+
if (picker?.button === button) { closePalette(true); return }
|
|
123
|
+
closePalette()
|
|
124
|
+
const key = getKey(), menu = button.closest(modelList)
|
|
125
|
+
if (!key || !menu) return
|
|
126
|
+
const popup = document.createElement('div'), swatches = document.createElement('div')
|
|
127
|
+
popup.className = 'cdx-model-palette'
|
|
128
|
+
popup.setAttribute('role', 'group')
|
|
129
|
+
popup.setAttribute('aria-label', copy('color'))
|
|
130
|
+
swatches.className = 'cdx-model-swatches'
|
|
131
|
+
popup.append(swatches)
|
|
132
|
+
const current = colors.get(key)
|
|
133
|
+
for (const color of [...Object.keys(palette), undefined]) {
|
|
134
|
+
const choice = document.createElement('button')
|
|
135
|
+
const name = color ? palette[color][isChinese() ? 1 : 2] : copy('clear')
|
|
136
|
+
choice.type = 'button'; choice.className = 'cdx-model-swatch'
|
|
137
|
+
choice.title = name; choice.setAttribute('aria-label', name)
|
|
138
|
+
choice.setAttribute('aria-pressed', String(color === current))
|
|
139
|
+
if (color) choice.style.setProperty('--cdx-model-tint', palette[color][0])
|
|
140
|
+
else choice.textContent = name
|
|
141
|
+
choice.addEventListener('click', () => {
|
|
142
|
+
if (color) colors.set(key, color)
|
|
143
|
+
else colors.delete(key)
|
|
144
|
+
try { localStorage.setItem(colorStorageKey, JSON.stringify(Object.fromEntries(colors))) } catch {}
|
|
145
|
+
closePalette(true)
|
|
146
|
+
reconcile()
|
|
147
|
+
})
|
|
148
|
+
swatches.append(choice)
|
|
149
|
+
}
|
|
150
|
+
// Keep the popup inside the native menu for its focus and outside-click checks.
|
|
151
|
+
if (typeof popup.showPopover === 'function') popup.setAttribute('popover', 'manual')
|
|
152
|
+
menu.append(popup)
|
|
153
|
+
popup.showPopover?.()
|
|
154
|
+
const anchor = button.getBoundingClientRect(), { width, height } = popup.getBoundingClientRect()
|
|
155
|
+
popup.style.left = Math.max(8, Math.min(anchor.right - width, innerWidth - width - 8)) + 'px'
|
|
156
|
+
popup.style.top = (anchor.bottom + height + 4 <= innerHeight - 8 ? anchor.bottom + 4 : Math.max(8, anchor.top - height - 4)) + 'px'
|
|
157
|
+
const listeners = new AbortController()
|
|
158
|
+
const options = { capture: true, signal: listeners.signal }
|
|
159
|
+
picker = { key, button, getKey, popup, listeners, previousFocus }
|
|
160
|
+
button.setAttribute('aria-expanded', 'true')
|
|
161
|
+
document.addEventListener('pointerdown', event => {
|
|
162
|
+
if (!popup.contains(event.target) && !button.contains(event.target)) closePalette()
|
|
163
|
+
}, options)
|
|
164
|
+
menu.addEventListener('scroll', () => closePalette(), options)
|
|
165
|
+
window.addEventListener('resize', () => closePalette(), options)
|
|
166
|
+
swatches.querySelector('[aria-pressed="true"]').focus({ preventScroll: true })
|
|
167
|
+
}
|
|
61
168
|
function reconcileOpeningLists() {
|
|
62
169
|
for (const [list, opening] of openingLists) if (!list.isConnected) {
|
|
63
170
|
opening?.finish()
|
|
@@ -92,23 +199,24 @@ window.__ModuleLoader__.load({
|
|
|
92
199
|
const menu = row.closest('[role="menu"]')
|
|
93
200
|
if (!menu || !row.parentElement?.matches('[data-menu-group]')) continue
|
|
94
201
|
seen.add(row)
|
|
95
|
-
let
|
|
96
|
-
if (!
|
|
97
|
-
|
|
98
|
-
|
|
99
|
-
|
|
100
|
-
})
|
|
202
|
+
let actions = controls.get(row)
|
|
203
|
+
if (!actions) {
|
|
204
|
+
const getKey = () => row.querySelector('[data-cdx-model-key]')?.dataset.cdxModelKey
|
|
205
|
+
const star = starButton(() => { const key = getKey(); if (key) toggle(key) })
|
|
206
|
+
actions = { star, color: colorButton(getKey) }
|
|
101
207
|
row.setAttribute('data-cdx-model-row', '')
|
|
102
|
-
|
|
208
|
+
controls.set(row, actions)
|
|
103
209
|
}
|
|
104
|
-
|
|
210
|
+
const { star, color } = actions
|
|
211
|
+
if (row.nextElementSibling !== star || star.nextElementSibling !== color) row.after(star, color)
|
|
105
212
|
const key = label.dataset.cdxModelKey, name = label.dataset.cdxModelName
|
|
106
213
|
paint(star, key, name)
|
|
214
|
+
paintColor(row, color, key, name)
|
|
107
215
|
const list = byMenu.get(menu) || []
|
|
108
216
|
if (favorites.has(key)) list.push({ key, name, group: label.dataset.cdxModelGroup, row, star })
|
|
109
217
|
byMenu.set(menu, list)
|
|
110
218
|
}
|
|
111
|
-
for (const [row,
|
|
219
|
+
for (const [row, actions] of controls) if (!seen.has(row)) removeControls(row, actions)
|
|
112
220
|
for (const [menu, entry] of menus) if (!byMenu.get(menu)?.length) { entry.section.remove(); menus.delete(menu) }
|
|
113
221
|
for (const [menu, rows] of byMenu) {
|
|
114
222
|
if (!rows.length) continue
|
|
@@ -133,8 +241,9 @@ window.__ModuleLoader__.load({
|
|
|
133
241
|
choice.setAttribute('role', 'menuitem')
|
|
134
242
|
choice.addEventListener('click', () => item.data.row.click())
|
|
135
243
|
const star = starButton(() => { item.data.star.focus(); toggle(item.data.key) })
|
|
136
|
-
|
|
137
|
-
|
|
244
|
+
const color = colorButton(() => item.data.key)
|
|
245
|
+
line.append(choice, star, color)
|
|
246
|
+
item = { line, choice, star, color }; entry.rows.set(data.key, item)
|
|
138
247
|
}
|
|
139
248
|
item.data = data
|
|
140
249
|
if (previous.nextElementSibling !== item.line) previous.after(item.line)
|
|
@@ -144,52 +253,75 @@ window.__ModuleLoader__.load({
|
|
|
144
253
|
item.choice.title = name; item.choice.disabled = data.row.disabled
|
|
145
254
|
item.choice.setAttribute('aria-current', data.row.getAttribute('aria-checked') === 'true' ? 'true' : 'false')
|
|
146
255
|
paint(item.star, data.key, data.name)
|
|
256
|
+
paintColor(item.line, item.color, data.key, data.name)
|
|
147
257
|
}
|
|
148
258
|
}
|
|
259
|
+
if (picker && (!picker.button.isConnected || !picker.popup.isConnected || picker.key !== picker.getKey())) closePalette()
|
|
149
260
|
reconcileOpeningLists()
|
|
150
261
|
}
|
|
262
|
+
function removeControls(row, { star, color }) {
|
|
263
|
+
row.removeAttribute('data-cdx-model-row')
|
|
264
|
+
delete row.dataset.cdxModelColor
|
|
265
|
+
row.style.removeProperty('--cdx-model-tint')
|
|
266
|
+
star.remove(); color.remove(); controls.delete(row)
|
|
267
|
+
}
|
|
151
268
|
function onKeyDown(event) {
|
|
152
269
|
// Focus can remain on the trigger when a picker opens without search.
|
|
153
270
|
const controlled = event.target.matches?.('button[aria-expanded="true"][aria-controls]')
|
|
154
271
|
&& document.getElementById(event.target.getAttribute('aria-controls'))
|
|
155
272
|
const list = controlled && controlled.matches(modelPane) && controlled.querySelector(modelList)
|
|
156
273
|
if (list) openingLists.get(list)?.finish()
|
|
157
|
-
if (event.isComposing || event.keyCode === 229 || event.altKey || event.ctrlKey || event.metaKey
|
|
274
|
+
if (event.isComposing || event.keyCode === 229 || event.altKey || event.ctrlKey || event.metaKey) return
|
|
158
275
|
const target = event.target
|
|
276
|
+
if (picker?.popup.contains(target)) {
|
|
277
|
+
const step = event.key === 'ArrowLeft' || event.key === 'ArrowUp' ? -1
|
|
278
|
+
: event.key === 'ArrowRight' || event.key === 'ArrowDown' ? 1
|
|
279
|
+
: event.key === 'Tab' ? (event.shiftKey ? -1 : 1) : 0
|
|
280
|
+
if (event.key === 'Escape' || step) {
|
|
281
|
+
event.preventDefault(); event.stopPropagation()
|
|
282
|
+
if (event.key === 'Escape') closePalette(true)
|
|
283
|
+
else {
|
|
284
|
+
const choices = [...picker.popup.querySelectorAll('button')]
|
|
285
|
+
choices[(choices.indexOf(target) + step + choices.length) % choices.length].focus()
|
|
286
|
+
}
|
|
287
|
+
}
|
|
288
|
+
return
|
|
289
|
+
}
|
|
290
|
+
if (event.shiftKey) return
|
|
159
291
|
if (event.key === 'Enter' && target.matches?.('.cdx-model-favorite-choice:not(:disabled)')) {
|
|
160
292
|
event.preventDefault(); event.stopPropagation()
|
|
161
293
|
if (!event.repeat) target.click()
|
|
162
294
|
return
|
|
163
295
|
}
|
|
164
296
|
const direction = event.key === 'ArrowDown' ? 1 : event.key === 'ArrowUp' ? -1 : 0
|
|
165
|
-
if (!direction && event.key !== 'F2') return
|
|
166
|
-
const
|
|
167
|
-
const menu =
|
|
297
|
+
if (!direction && event.key !== 'F2' && event.key !== 'F3') return
|
|
298
|
+
const controlledId = target.matches?.('[role="searchbox"][aria-controls]') ? target.getAttribute('aria-controls') : null
|
|
299
|
+
const menu = controlledId ? document.getElementById(controlledId) : target.closest?.('[role="menu"]')
|
|
168
300
|
if (!menu || menu.hidden) return
|
|
169
|
-
const nativeRows = [...menu.querySelectorAll(rowSelector)].filter(row =>
|
|
301
|
+
const nativeRows = [...menu.querySelectorAll(rowSelector)].filter(row => controls.has(row) && !row.disabled)
|
|
170
302
|
if (!nativeRows.length) return
|
|
171
303
|
const search = [...menu.parentElement.querySelectorAll('[role="searchbox"][aria-controls]')]
|
|
172
304
|
.find(input => input.getAttribute('aria-controls') === menu.id)
|
|
173
305
|
const favorites = [...menu.querySelectorAll('.cdx-model-favorite-choice:not(:disabled)')]
|
|
174
|
-
const
|
|
306
|
+
const fromControl = target.matches('.cdx-model-star,.cdx-model-color')
|
|
307
|
+
const choice = fromControl ? (target.matches('.cdx-model-color') ? target.previousElementSibling?.previousElementSibling : target.previousElementSibling)
|
|
175
308
|
: target === search ? document.getElementById(search.getAttribute('aria-activedescendant')) : target
|
|
176
309
|
const rows = [...favorites, ...nativeRows]
|
|
177
310
|
const index = rows.indexOf(choice)
|
|
178
|
-
if (event.key === 'F2') {
|
|
311
|
+
if (event.key === 'F2' || event.key === 'F3') {
|
|
179
312
|
if (index < 0) return
|
|
180
|
-
const
|
|
181
|
-
if (!
|
|
313
|
+
const control = event.key === 'F2' ? choice.nextElementSibling : choice.nextElementSibling?.nextElementSibling
|
|
314
|
+
if (!control?.matches('.cdx-model-star,.cdx-model-color')) return
|
|
182
315
|
event.preventDefault(); event.stopPropagation()
|
|
183
|
-
if (!event.repeat)
|
|
316
|
+
if (!event.repeat) control.click()
|
|
184
317
|
return
|
|
185
318
|
}
|
|
186
319
|
// In search mode the host tracks only its own rows. Intercept steps
|
|
187
320
|
// into/out of favorites and let the host handle ordinary search steps.
|
|
188
321
|
// Without search the host already navigates role=menuitem buttons.
|
|
189
322
|
const next = rows[index < 0 ? (direction > 0 ? 0 : rows.length - 1) : (index + direction + rows.length) % rows.length]
|
|
190
|
-
const fromStar = target.matches('.cdx-model-star')
|
|
191
323
|
const toFavorite = favorites.includes(next)
|
|
192
|
-
if (!
|
|
324
|
+
if (!fromControl && (!search || (!toFavorite && !favorites.includes(choice)) || (target !== search && index < 0))) return
|
|
193
325
|
event.preventDefault(); event.stopPropagation()
|
|
194
326
|
next.focus()
|
|
195
327
|
if (search && !toFavorite) search.focus()
|
|
@@ -200,16 +332,20 @@ window.__ModuleLoader__.load({
|
|
|
200
332
|
: [...record.addedNodes, ...record.removedNodes].some(node => node.nodeType === 1 && (node.matches?.(changedNodeSelector) || node.querySelector?.(changedNodeSelector))))) schedule()
|
|
201
333
|
})
|
|
202
334
|
observer.observe(document.body, { subtree: true, childList: true, attributes: true, attributeFilter: ['aria-checked', 'disabled', 'data-cdx-model-key'] })
|
|
203
|
-
const onStorage = event => {
|
|
335
|
+
const onStorage = event => {
|
|
336
|
+
if (event.key === storageKey || event.key === null) { favorites = readFavorites(); schedule() }
|
|
337
|
+
if (event.key === colorStorageKey || event.key === null) { colors = readColors(); closePalette(true); schedule() }
|
|
338
|
+
}
|
|
204
339
|
window.addEventListener('storage', onStorage)
|
|
205
340
|
document.addEventListener('keydown', onKeyDown, true)
|
|
206
341
|
reconcile()
|
|
207
342
|
return () => {
|
|
208
343
|
stopped = true; observer.disconnect(); window.removeEventListener('storage', onStorage); css.remove()
|
|
209
344
|
document.removeEventListener('keydown', onKeyDown, true)
|
|
345
|
+
closePalette()
|
|
210
346
|
for (const opening of openingLists.values()) opening?.finish()
|
|
211
347
|
openingLists.clear()
|
|
212
|
-
for (const [row,
|
|
348
|
+
for (const [row, actions] of controls) removeControls(row, actions)
|
|
213
349
|
for (const { section } of menus.values()) section.remove()
|
|
214
350
|
}
|
|
215
351
|
}
|