@in-the-loop-labs/pair-review 4.1.1 → 5.0.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/README.md +81 -13
- package/package.json +6 -2
- package/plugin/.claude-plugin/plugin.json +1 -1
- package/plugin-code-critic/.claude-plugin/plugin.json +1 -1
- package/plugin-pair-loop/.claude-plugin/plugin.json +1 -1
- package/plugin-pair-loop/skills/loop/SKILL.md +17 -8
- package/public/css/ai-summary-modal.css +1 -1
- package/public/css/analysis-config.css +33 -49
- package/public/css/council-card.css +118 -0
- package/public/css/council-dropdown.css +164 -0
- package/public/css/pr.css +666 -394
- package/public/css/repo-settings.css +15 -305
- package/public/css/settings.css +1141 -0
- package/public/css/snippet-manager.css +233 -0
- package/public/index.html +40 -59
- package/public/js/components/AIPanel.js +82 -16
- package/public/js/components/ChatPanel.js +401 -5
- package/public/js/components/CouncilCard.js +202 -0
- package/public/js/components/CouncilDropdown.js +292 -0
- package/public/js/components/DiffOptionsDropdown.js +177 -4
- package/public/js/components/SnippetManager.js +463 -0
- package/public/js/index.js +7 -30
- package/public/js/local.js +20 -2
- package/public/js/modules/comment-manager.js +8 -1
- package/public/js/modules/comment-minimizer.js +249 -190
- package/public/js/modules/external-comment-manager.js +414 -48
- package/public/js/modules/file-comment-manager.js +28 -21
- package/public/js/modules/hunk-summary-renderer.js +155 -29
- package/public/js/modules/pierre-bridge.js +2513 -0
- package/public/js/modules/pierre-context.js +345 -0
- package/public/js/modules/suggestion-manager.js +176 -20
- package/public/js/modules/tour-renderer.js +400 -184
- package/public/js/pr.js +1434 -150
- package/public/js/repo-settings.js +60 -284
- package/public/js/settings.js +1086 -0
- package/public/js/theme-bootstrap.js +40 -0
- package/public/js/theme.js +247 -0
- package/public/js/utils/provider-model.js +3 -3
- package/public/js/utils/suggestion-ui.js +157 -8
- package/public/local.html +20 -31
- package/public/pr.html +14 -23
- package/public/repo-settings.html +24 -14
- package/public/settings.html +138 -0
- package/public/setup.html +8 -13
- package/src/chat/api-reference.js +9 -5
- package/src/chat/prompt-builder.js +8 -1
- package/src/config.js +15 -6
- package/src/database.js +307 -14
- package/src/external/github-adapter.js +39 -5
- package/src/headless/delegate.js +682 -0
- package/src/local-review.js +10 -10
- package/src/local-scope.js +9 -0
- package/src/main.js +276 -157
- package/src/mcp-stdio.js +24 -1
- package/src/review-config.js +93 -25
- package/src/routes/chat.js +2 -2
- package/src/routes/config.js +12 -10
- package/src/routes/external-comments.js +5 -1
- package/src/routes/local.js +2 -4
- package/src/routes/mcp.js +18 -13
- package/src/routes/reviews.js +223 -4
- package/src/routes/settings.js +252 -0
- package/src/routes/setup.js +80 -1
- package/src/routes/shared.js +31 -29
- package/src/routes/snippets.js +154 -0
- package/src/routes/stack-analysis.js +17 -14
- package/src/server.js +86 -18
- package/src/settings/global-settings-service.js +472 -0
- package/src/settings/registry.js +624 -0
- package/src/utils/db-identity.js +44 -0
|
@@ -0,0 +1,202 @@
|
|
|
1
|
+
// Copyright 2026 Tim Perkins (tjwp) | SPDX-License-Identifier: Apache-2.0
|
|
2
|
+
/**
|
|
3
|
+
* CouncilCard — a shared council composition preview.
|
|
4
|
+
*
|
|
5
|
+
* Extracted from the repo-settings page so the global settings page can show the
|
|
6
|
+
* same "what does this council run" preview (reviewers/models, levels, and
|
|
7
|
+
* consolidation) when a council is chosen as the Default for Analysis. It renders
|
|
8
|
+
* into a caller-supplied container and dispatches on council type
|
|
9
|
+
* (voice/standard vs. advanced), exactly like the original.
|
|
10
|
+
*
|
|
11
|
+
* Provider/model id → display-name resolution differs per page (repo settings
|
|
12
|
+
* keys providers by id; the global settings page holds an array from
|
|
13
|
+
* /api/providers), so the consumer injects a `resolveModelDisplay(providerId,
|
|
14
|
+
* modelId) => { providerName, modelName }` callback rather than the component
|
|
15
|
+
* reaching for page-specific data.
|
|
16
|
+
*
|
|
17
|
+
* Consumers:
|
|
18
|
+
* - public/js/repo-settings.js — renderVoiceCouncilCard / renderAdvancedCouncilCard
|
|
19
|
+
* delegate here; resolveModelDisplay uses its own alias-aware lookup.
|
|
20
|
+
* - public/js/settings.js — renders the preview beneath the "Default for
|
|
21
|
+
* Analysis" dropdown when a council is selected.
|
|
22
|
+
*
|
|
23
|
+
* CSS classes (.council-card*) live in public/css/council-card.css (loaded by
|
|
24
|
+
* both pages). The component only sets innerHTML + calls the injected resolver,
|
|
25
|
+
* so it also runs under the repo-settings mock-DOM unit tests.
|
|
26
|
+
*/
|
|
27
|
+
|
|
28
|
+
class CouncilCard {
|
|
29
|
+
/**
|
|
30
|
+
* @param {Object} opts
|
|
31
|
+
* @param {HTMLElement} opts.container - Element to render the card into.
|
|
32
|
+
* @param {Function} [opts.resolveModelDisplay] - (providerId, modelId) =>
|
|
33
|
+
* { providerName, modelName }. Defaults to echoing the raw ids.
|
|
34
|
+
*/
|
|
35
|
+
constructor(opts = {}) {
|
|
36
|
+
this.container = opts.container;
|
|
37
|
+
this.resolveModelDisplay = typeof opts.resolveModelDisplay === 'function'
|
|
38
|
+
? opts.resolveModelDisplay
|
|
39
|
+
: (providerId, modelId) => ({
|
|
40
|
+
providerName: providerId || 'Unknown',
|
|
41
|
+
modelName: modelId || 'Unknown'
|
|
42
|
+
});
|
|
43
|
+
}
|
|
44
|
+
|
|
45
|
+
escapeHtml(str) {
|
|
46
|
+
if (str === null || str === undefined) return '';
|
|
47
|
+
return String(str).replace(/[&<>"']/g, (c) => ({
|
|
48
|
+
'&': '&', '<': '<', '>': '>', '"': '"', "'": '''
|
|
49
|
+
}[c]));
|
|
50
|
+
}
|
|
51
|
+
|
|
52
|
+
/** Empty the container. */
|
|
53
|
+
clear() {
|
|
54
|
+
if (this.container) this.container.innerHTML = '';
|
|
55
|
+
}
|
|
56
|
+
|
|
57
|
+
/**
|
|
58
|
+
* Render the preview for `council`, dispatching by type. A falsy council
|
|
59
|
+
* clears the container.
|
|
60
|
+
* @param {Object|null} council - { id, name, type, config }
|
|
61
|
+
*/
|
|
62
|
+
render(council) {
|
|
63
|
+
if (!this.container) return;
|
|
64
|
+
if (!council) {
|
|
65
|
+
this.clear();
|
|
66
|
+
return;
|
|
67
|
+
}
|
|
68
|
+
if (council.type === 'advanced') {
|
|
69
|
+
this.renderAdvanced(council);
|
|
70
|
+
} else {
|
|
71
|
+
this.renderVoice(council);
|
|
72
|
+
}
|
|
73
|
+
}
|
|
74
|
+
|
|
75
|
+
/**
|
|
76
|
+
* Render a standard (voice-centric) council card.
|
|
77
|
+
* @param {Object} council
|
|
78
|
+
*/
|
|
79
|
+
renderVoice(council) {
|
|
80
|
+
if (!this.container) return;
|
|
81
|
+
|
|
82
|
+
const config = council.config || {};
|
|
83
|
+
const voices = config.voices || [];
|
|
84
|
+
const levels = config.levels || {};
|
|
85
|
+
|
|
86
|
+
// Build summary: "Levels 1, 2" for enabled levels.
|
|
87
|
+
const enabledLevels = Object.entries(levels)
|
|
88
|
+
.filter(([, enabled]) => enabled)
|
|
89
|
+
.map(([level]) => level);
|
|
90
|
+
const summaryText = enabledLevels.length > 0
|
|
91
|
+
? `Levels ${enabledLevels.join(', ')}`
|
|
92
|
+
: 'No levels configured';
|
|
93
|
+
|
|
94
|
+
const reviewerLines = voices.map((voice) => {
|
|
95
|
+
const display = this.resolveModelDisplay(voice.provider, voice.model);
|
|
96
|
+
const tierLabel = voice.tier ? `<span class="council-card-tier">${this.escapeHtml(voice.tier)}</span>` : '';
|
|
97
|
+
return `<div class="council-card-reviewer">
|
|
98
|
+
<span class="council-card-reviewer-name">${this.escapeHtml(display.providerName)} / ${this.escapeHtml(display.modelName)}</span>
|
|
99
|
+
${tierLabel}
|
|
100
|
+
</div>`;
|
|
101
|
+
}).join('');
|
|
102
|
+
|
|
103
|
+
let consolidationHTML = '';
|
|
104
|
+
if (config.consolidation && config.consolidation.provider) {
|
|
105
|
+
const consolDisplay = this.resolveModelDisplay(config.consolidation.provider, config.consolidation.model);
|
|
106
|
+
const consolTier = config.consolidation.tier ? `<span class="council-card-tier">${this.escapeHtml(config.consolidation.tier)}</span>` : '';
|
|
107
|
+
consolidationHTML = `
|
|
108
|
+
<div class="council-card-divider"></div>
|
|
109
|
+
<div class="council-card-consolidation">
|
|
110
|
+
<div class="council-card-consolidation-label">Consolidation</div>
|
|
111
|
+
<div class="council-card-reviewer">
|
|
112
|
+
<span class="council-card-reviewer-name">${this.escapeHtml(consolDisplay.providerName)} / ${this.escapeHtml(consolDisplay.modelName)}</span>
|
|
113
|
+
${consolTier}
|
|
114
|
+
</div>
|
|
115
|
+
</div>`;
|
|
116
|
+
}
|
|
117
|
+
|
|
118
|
+
this.container.innerHTML = `
|
|
119
|
+
<div class="council-card">
|
|
120
|
+
<div class="council-card-name">${this.escapeHtml(council.name)}</div>
|
|
121
|
+
<div class="council-card-summary">${summaryText}</div>
|
|
122
|
+
<div class="council-card-reviewers">
|
|
123
|
+
${reviewerLines}
|
|
124
|
+
</div>
|
|
125
|
+
${consolidationHTML}
|
|
126
|
+
</div>
|
|
127
|
+
`;
|
|
128
|
+
}
|
|
129
|
+
|
|
130
|
+
/**
|
|
131
|
+
* Render an advanced council card with level-grouped reviewers.
|
|
132
|
+
* @param {Object} council
|
|
133
|
+
*/
|
|
134
|
+
renderAdvanced(council) {
|
|
135
|
+
if (!this.container) return;
|
|
136
|
+
|
|
137
|
+
const config = council.config || {};
|
|
138
|
+
const levels = config.levels || {};
|
|
139
|
+
|
|
140
|
+
const levelLabels = {
|
|
141
|
+
'1': 'Level 1 — Isolation',
|
|
142
|
+
'2': 'Level 2 — File Context',
|
|
143
|
+
'3': 'Level 3 — Codebase'
|
|
144
|
+
};
|
|
145
|
+
|
|
146
|
+
let levelGroupsHTML = '';
|
|
147
|
+
for (const [levelNum, levelConfig] of Object.entries(levels)) {
|
|
148
|
+
if (!levelConfig || !levelConfig.enabled) continue;
|
|
149
|
+
const voices = levelConfig.voices || [];
|
|
150
|
+
const header = levelLabels[levelNum] || `Level ${levelNum}`;
|
|
151
|
+
const voiceLines = voices.map((voice) => {
|
|
152
|
+
const display = this.resolveModelDisplay(voice.provider, voice.model);
|
|
153
|
+
const tierLabel = voice.tier ? `<span class="council-card-tier">${this.escapeHtml(voice.tier)}</span>` : '';
|
|
154
|
+
return `<div class="council-card-reviewer">
|
|
155
|
+
<span class="council-card-reviewer-name">${this.escapeHtml(display.providerName)} / ${this.escapeHtml(display.modelName)}</span>
|
|
156
|
+
${tierLabel}
|
|
157
|
+
</div>`;
|
|
158
|
+
}).join('');
|
|
159
|
+
levelGroupsHTML += `
|
|
160
|
+
<div class="council-card-level-header">${this.escapeHtml(header)}</div>
|
|
161
|
+
${voiceLines}`;
|
|
162
|
+
}
|
|
163
|
+
|
|
164
|
+
let consolidationHTML = '';
|
|
165
|
+
if (config.consolidation && config.consolidation.provider) {
|
|
166
|
+
const consolDisplay = this.resolveModelDisplay(config.consolidation.provider, config.consolidation.model);
|
|
167
|
+
const consolTier = config.consolidation.tier ? `<span class="council-card-tier">${this.escapeHtml(config.consolidation.tier)}</span>` : '';
|
|
168
|
+
consolidationHTML = `
|
|
169
|
+
<div class="council-card-divider"></div>
|
|
170
|
+
<div class="council-card-consolidation">
|
|
171
|
+
<div class="council-card-consolidation-label">Orchestration</div>
|
|
172
|
+
<div class="council-card-reviewer">
|
|
173
|
+
<span class="council-card-reviewer-name">${this.escapeHtml(consolDisplay.providerName)} / ${this.escapeHtml(consolDisplay.modelName)}</span>
|
|
174
|
+
${consolTier}
|
|
175
|
+
</div>
|
|
176
|
+
</div>`;
|
|
177
|
+
}
|
|
178
|
+
|
|
179
|
+
this.container.innerHTML = `
|
|
180
|
+
<div class="council-card">
|
|
181
|
+
<div class="council-card-name">
|
|
182
|
+
${this.escapeHtml(council.name)}
|
|
183
|
+
<span class="council-card-badge-advanced">Advanced</span>
|
|
184
|
+
</div>
|
|
185
|
+
<div class="council-card-reviewers">
|
|
186
|
+
${levelGroupsHTML}
|
|
187
|
+
</div>
|
|
188
|
+
${consolidationHTML}
|
|
189
|
+
</div>
|
|
190
|
+
`;
|
|
191
|
+
}
|
|
192
|
+
}
|
|
193
|
+
|
|
194
|
+
// Browser global for the pages that load this before their page script.
|
|
195
|
+
if (typeof window !== 'undefined') {
|
|
196
|
+
window.CouncilCard = CouncilCard;
|
|
197
|
+
}
|
|
198
|
+
|
|
199
|
+
// Export for unit tests, following the repo's component export pattern.
|
|
200
|
+
if (typeof module !== 'undefined' && module.exports) {
|
|
201
|
+
module.exports = { CouncilCard };
|
|
202
|
+
}
|
|
@@ -0,0 +1,292 @@
|
|
|
1
|
+
// Copyright 2026 Tim Perkins (tjwp) | SPDX-License-Identifier: Apache-2.0
|
|
2
|
+
/**
|
|
3
|
+
* CouncilDropdown — a shared rich council picker.
|
|
4
|
+
*
|
|
5
|
+
* Extracted from the repo-settings page so the global settings page can reuse
|
|
6
|
+
* the SAME control instead of a bare native <select>. It renders a styled
|
|
7
|
+
* trigger + option list that surfaces each council's name and type badge
|
|
8
|
+
* (Standard / Advanced), with full keyboard navigation and outside-click close.
|
|
9
|
+
*
|
|
10
|
+
* The component owns rendering + interaction only; it does NOT decide what a
|
|
11
|
+
* selection means. On selection it calls `onSelect(value)` (value is the council
|
|
12
|
+
* id, or '' for the optional "none" base option) and lets the consumer update
|
|
13
|
+
* its own model / previews / persistence, then reflect the new selection back
|
|
14
|
+
* via `setSelected()`.
|
|
15
|
+
*
|
|
16
|
+
* Consumers:
|
|
17
|
+
* - public/js/repo-settings.js — no base option; the single/council mode is a
|
|
18
|
+
* separate segmented control, so the dropdown only lists councils.
|
|
19
|
+
* - public/js/settings.js — includeNone:true renders a "Default Provider /
|
|
20
|
+
* Model" base option as the first row, so the one control expresses the
|
|
21
|
+
* "either the provider/model default OR a council" choice.
|
|
22
|
+
*
|
|
23
|
+
* Markup + CSS classes match the original repo-settings dropdown
|
|
24
|
+
* (.custom-dropdown*, .council-type-badge*), now in public/css/council-dropdown.css
|
|
25
|
+
* (loaded by both pages).
|
|
26
|
+
*/
|
|
27
|
+
|
|
28
|
+
class CouncilDropdown {
|
|
29
|
+
/**
|
|
30
|
+
* @param {Object} opts
|
|
31
|
+
* @param {HTMLElement} opts.container - Mount element (given `.custom-dropdown`).
|
|
32
|
+
* @param {Array<{id:string,name:string,type:string}>} [opts.councils] - Council list.
|
|
33
|
+
* @param {string} [opts.selectedId] - Currently selected council id ('' = none).
|
|
34
|
+
* @param {Function} [opts.onSelect] - Called with the chosen value (id or '').
|
|
35
|
+
* @param {boolean} [opts.includeNone] - Render a base/none option at the top.
|
|
36
|
+
* @param {string} [opts.noneLabel] - Label for the none option + its trigger text.
|
|
37
|
+
* @param {string} [opts.placeholder] - Trigger text when nothing is selected and
|
|
38
|
+
* there is no none option (repo-settings behavior).
|
|
39
|
+
* @param {string} [opts.emptyText] - Trigger text when there are no councils and
|
|
40
|
+
* no none option.
|
|
41
|
+
* @param {boolean} [opts.disabled] - Render non-interactive (e.g. a config
|
|
42
|
+
* `final` lock): the trigger is disabled and no listeners are wired.
|
|
43
|
+
*/
|
|
44
|
+
constructor(opts = {}) {
|
|
45
|
+
this.container = opts.container;
|
|
46
|
+
this.councils = Array.isArray(opts.councils) ? opts.councils : [];
|
|
47
|
+
this.selectedId = opts.selectedId || '';
|
|
48
|
+
this.onSelect = typeof opts.onSelect === 'function' ? opts.onSelect : () => {};
|
|
49
|
+
this.includeNone = opts.includeNone === true;
|
|
50
|
+
this.noneLabel = opts.noneLabel || 'None';
|
|
51
|
+
this.placeholder = opts.placeholder || 'Select a council...';
|
|
52
|
+
this.emptyText = opts.emptyText || 'No councils available';
|
|
53
|
+
this.disabled = opts.disabled === true;
|
|
54
|
+
|
|
55
|
+
// Bound document handler so we can add/remove the exact same reference.
|
|
56
|
+
this._outsideClickHandler = null;
|
|
57
|
+
this._focusedIndex = -1;
|
|
58
|
+
|
|
59
|
+
if (this.container) this.render();
|
|
60
|
+
}
|
|
61
|
+
|
|
62
|
+
/**
|
|
63
|
+
* Map a council type to its display badge. Shared so the dropdown and any
|
|
64
|
+
* consumer (e.g. a card preview) label types identically.
|
|
65
|
+
* @param {string} type
|
|
66
|
+
* @returns {{ label: string, cssClass: string }}
|
|
67
|
+
*/
|
|
68
|
+
static typeBadge(type) {
|
|
69
|
+
if (type === 'advanced') return { label: 'Advanced', cssClass: 'badge-advanced' };
|
|
70
|
+
return { label: 'Standard', cssClass: 'badge-standard' };
|
|
71
|
+
}
|
|
72
|
+
|
|
73
|
+
/** Replace the council list and re-render (preserving the current selection). */
|
|
74
|
+
setCouncils(councils) {
|
|
75
|
+
this.councils = Array.isArray(councils) ? councils : [];
|
|
76
|
+
this.render();
|
|
77
|
+
}
|
|
78
|
+
|
|
79
|
+
/** Update the selected id and re-render the trigger/option states. */
|
|
80
|
+
setSelected(id) {
|
|
81
|
+
this.selectedId = id || '';
|
|
82
|
+
this.render();
|
|
83
|
+
}
|
|
84
|
+
|
|
85
|
+
/** Escape text for safe interpolation into the option/trigger HTML. */
|
|
86
|
+
escapeHtml(str) {
|
|
87
|
+
if (str === null || str === undefined) return '';
|
|
88
|
+
return String(str).replace(/[&<>"']/g, (c) => ({
|
|
89
|
+
'&': '&', '<': '<', '>': '>', '"': '"', "'": '''
|
|
90
|
+
}[c]));
|
|
91
|
+
}
|
|
92
|
+
|
|
93
|
+
/**
|
|
94
|
+
* Build the trigger inner HTML for the current selection.
|
|
95
|
+
* @private
|
|
96
|
+
*/
|
|
97
|
+
_triggerHtml() {
|
|
98
|
+
if (this.selectedId === '' && this.includeNone) {
|
|
99
|
+
return `<span class="trigger-text">${this.escapeHtml(this.noneLabel)}</span>`;
|
|
100
|
+
}
|
|
101
|
+
const selected = this.councils.find((c) => c.id === this.selectedId);
|
|
102
|
+
if (selected) {
|
|
103
|
+
const badge = CouncilDropdown.typeBadge(selected.type);
|
|
104
|
+
return `<span class="trigger-text">${this.escapeHtml(selected.name)}</span>` +
|
|
105
|
+
`<span class="council-type-badge ${badge.cssClass}">${badge.label}</span>`;
|
|
106
|
+
}
|
|
107
|
+
// Nothing selected and no (or unmatched) none option.
|
|
108
|
+
const placeholder = this.councils.length > 0 ? this.placeholder : this.emptyText;
|
|
109
|
+
return `<span class="trigger-text placeholder">${this.escapeHtml(placeholder)}</span>`;
|
|
110
|
+
}
|
|
111
|
+
|
|
112
|
+
/**
|
|
113
|
+
* Build the option list HTML (optional none row first, then councils sorted
|
|
114
|
+
* alphabetically by name).
|
|
115
|
+
* @private
|
|
116
|
+
*/
|
|
117
|
+
_optionsHtml() {
|
|
118
|
+
let html = '';
|
|
119
|
+
if (this.includeNone) {
|
|
120
|
+
const selected = this.selectedId === '';
|
|
121
|
+
html += `<div class="custom-dropdown-option${selected ? ' selected' : ''}" data-value="" role="option" aria-selected="${selected}">` +
|
|
122
|
+
`<span class="option-name">${this.escapeHtml(this.noneLabel)}</span>` +
|
|
123
|
+
`</div>`;
|
|
124
|
+
}
|
|
125
|
+
const sorted = [...this.councils].sort((a, b) =>
|
|
126
|
+
(a.name || '').localeCompare(b.name || '', undefined, { sensitivity: 'base' })
|
|
127
|
+
);
|
|
128
|
+
for (const council of sorted) {
|
|
129
|
+
const badge = CouncilDropdown.typeBadge(council.type);
|
|
130
|
+
const selected = council.id === this.selectedId;
|
|
131
|
+
html += `<div class="custom-dropdown-option${selected ? ' selected' : ''}" data-value="${this.escapeHtml(council.id)}" role="option" aria-selected="${selected}">` +
|
|
132
|
+
`<span class="option-name">${this.escapeHtml(council.name)}</span>` +
|
|
133
|
+
`<span class="council-type-badge ${badge.cssClass}">${badge.label}</span>` +
|
|
134
|
+
`</div>`;
|
|
135
|
+
}
|
|
136
|
+
return html;
|
|
137
|
+
}
|
|
138
|
+
|
|
139
|
+
/** Render (or re-render) the trigger + list and (re)wire listeners. */
|
|
140
|
+
render() {
|
|
141
|
+
if (!this.container) return;
|
|
142
|
+
this.container.innerHTML = `
|
|
143
|
+
<button type="button" class="custom-dropdown-trigger" aria-haspopup="listbox" aria-expanded="false"${this.disabled ? ' disabled' : ''}>
|
|
144
|
+
${this._triggerHtml()}
|
|
145
|
+
</button>
|
|
146
|
+
<div class="custom-dropdown-list" role="listbox">
|
|
147
|
+
${this._optionsHtml()}
|
|
148
|
+
</div>
|
|
149
|
+
`;
|
|
150
|
+
// A disabled control shows its value but wires no interaction.
|
|
151
|
+
if (!this.disabled) this._attachListeners();
|
|
152
|
+
}
|
|
153
|
+
|
|
154
|
+
/**
|
|
155
|
+
* Wire trigger click, option click, keyboard navigation, and outside-click
|
|
156
|
+
* close. Re-attached on every render; the document handler is de-duplicated by
|
|
157
|
+
* removing the previous reference first (a render replaces the DOM but the
|
|
158
|
+
* document listener would otherwise accumulate).
|
|
159
|
+
* @private
|
|
160
|
+
*/
|
|
161
|
+
_attachListeners() {
|
|
162
|
+
const container = this.container;
|
|
163
|
+
const trigger = container.querySelector('.custom-dropdown-trigger');
|
|
164
|
+
const list = container.querySelector('.custom-dropdown-list');
|
|
165
|
+
if (!trigger || !list) return;
|
|
166
|
+
|
|
167
|
+
const getOptions = () => Array.from(list.querySelectorAll('.custom-dropdown-option'));
|
|
168
|
+
const updateFocus = (options, index) => {
|
|
169
|
+
options.forEach((opt) => opt.classList.remove('focused'));
|
|
170
|
+
if (index >= 0 && index < options.length) {
|
|
171
|
+
options[index].classList.add('focused');
|
|
172
|
+
options[index].scrollIntoView({ block: 'nearest' });
|
|
173
|
+
}
|
|
174
|
+
};
|
|
175
|
+
|
|
176
|
+
trigger.addEventListener('click', () => {
|
|
177
|
+
if (container.classList.contains('open')) {
|
|
178
|
+
this.close();
|
|
179
|
+
} else {
|
|
180
|
+
this.open();
|
|
181
|
+
this._focusedIndex = -1;
|
|
182
|
+
}
|
|
183
|
+
});
|
|
184
|
+
|
|
185
|
+
list.addEventListener('click', (e) => {
|
|
186
|
+
const option = e.target.closest('.custom-dropdown-option');
|
|
187
|
+
if (!option) return;
|
|
188
|
+
this._choose(option.dataset.value);
|
|
189
|
+
});
|
|
190
|
+
|
|
191
|
+
trigger.addEventListener('keydown', (e) => {
|
|
192
|
+
const isOpen = container.classList.contains('open');
|
|
193
|
+
|
|
194
|
+
if (e.key === 'Escape' && isOpen) {
|
|
195
|
+
e.preventDefault();
|
|
196
|
+
this.close();
|
|
197
|
+
trigger.focus();
|
|
198
|
+
return;
|
|
199
|
+
}
|
|
200
|
+
if (e.key === 'Enter' || e.key === ' ') {
|
|
201
|
+
e.preventDefault();
|
|
202
|
+
if (!isOpen) {
|
|
203
|
+
this.open();
|
|
204
|
+
this._focusedIndex = -1;
|
|
205
|
+
} else {
|
|
206
|
+
const options = getOptions();
|
|
207
|
+
if (this._focusedIndex >= 0 && this._focusedIndex < options.length) {
|
|
208
|
+
this._choose(options[this._focusedIndex].dataset.value);
|
|
209
|
+
}
|
|
210
|
+
}
|
|
211
|
+
return;
|
|
212
|
+
}
|
|
213
|
+
if ((e.key === 'ArrowDown' || e.key === 'ArrowUp') && isOpen) {
|
|
214
|
+
e.preventDefault();
|
|
215
|
+
const options = getOptions();
|
|
216
|
+
if (e.key === 'ArrowDown') {
|
|
217
|
+
this._focusedIndex = Math.min(this._focusedIndex + 1, options.length - 1);
|
|
218
|
+
} else {
|
|
219
|
+
this._focusedIndex = Math.max(this._focusedIndex - 1, 0);
|
|
220
|
+
}
|
|
221
|
+
updateFocus(options, this._focusedIndex);
|
|
222
|
+
return;
|
|
223
|
+
}
|
|
224
|
+
if (e.key === 'ArrowDown' && !isOpen) {
|
|
225
|
+
e.preventDefault();
|
|
226
|
+
this.open();
|
|
227
|
+
this._focusedIndex = 0;
|
|
228
|
+
updateFocus(getOptions(), this._focusedIndex);
|
|
229
|
+
}
|
|
230
|
+
});
|
|
231
|
+
|
|
232
|
+
// Outside-click close — remove the previous reference before adding so
|
|
233
|
+
// repeated renders don't stack listeners.
|
|
234
|
+
if (this._outsideClickHandler && typeof document !== 'undefined') {
|
|
235
|
+
document.removeEventListener('click', this._outsideClickHandler);
|
|
236
|
+
}
|
|
237
|
+
this._outsideClickHandler = (e) => {
|
|
238
|
+
if (!container.contains(e.target) && container.classList.contains('open')) {
|
|
239
|
+
this.close();
|
|
240
|
+
}
|
|
241
|
+
};
|
|
242
|
+
if (typeof document !== 'undefined') {
|
|
243
|
+
document.addEventListener('click', this._outsideClickHandler);
|
|
244
|
+
}
|
|
245
|
+
}
|
|
246
|
+
|
|
247
|
+
/**
|
|
248
|
+
* Handle a chosen value: notify the consumer. The consumer updates its model
|
|
249
|
+
* and calls setSelected() to reflect the new state, so we do not mutate
|
|
250
|
+
* selectedId here (mirrors the original repo-settings flow).
|
|
251
|
+
* @private
|
|
252
|
+
*/
|
|
253
|
+
_choose(value) {
|
|
254
|
+
this.close();
|
|
255
|
+
this.onSelect(value || '');
|
|
256
|
+
}
|
|
257
|
+
|
|
258
|
+
open() {
|
|
259
|
+
if (!this.container) return;
|
|
260
|
+
this.container.classList.add('open');
|
|
261
|
+
const trigger = this.container.querySelector('.custom-dropdown-trigger');
|
|
262
|
+
if (trigger) trigger.setAttribute('aria-expanded', 'true');
|
|
263
|
+
}
|
|
264
|
+
|
|
265
|
+
close() {
|
|
266
|
+
if (!this.container) return;
|
|
267
|
+
this.container.classList.remove('open');
|
|
268
|
+
const trigger = this.container.querySelector('.custom-dropdown-trigger');
|
|
269
|
+
if (trigger) trigger.setAttribute('aria-expanded', 'false');
|
|
270
|
+
this.container.querySelectorAll('.custom-dropdown-option.focused').forEach(
|
|
271
|
+
(opt) => opt.classList.remove('focused')
|
|
272
|
+
);
|
|
273
|
+
}
|
|
274
|
+
|
|
275
|
+
/** Remove the document-level outside-click listener (call on teardown). */
|
|
276
|
+
destroy() {
|
|
277
|
+
if (this._outsideClickHandler && typeof document !== 'undefined') {
|
|
278
|
+
document.removeEventListener('click', this._outsideClickHandler);
|
|
279
|
+
this._outsideClickHandler = null;
|
|
280
|
+
}
|
|
281
|
+
}
|
|
282
|
+
}
|
|
283
|
+
|
|
284
|
+
// Browser global for the two pages that load this before their page script.
|
|
285
|
+
if (typeof window !== 'undefined') {
|
|
286
|
+
window.CouncilDropdown = CouncilDropdown;
|
|
287
|
+
}
|
|
288
|
+
|
|
289
|
+
// Export for unit tests (jsdom), following the repo's component export pattern.
|
|
290
|
+
if (typeof module !== 'undefined' && module.exports) {
|
|
291
|
+
module.exports = { CouncilDropdown };
|
|
292
|
+
}
|