@datagrok/sequence-translator 1.10.8 → 1.10.10
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/CLAUDE.md +452 -0
- package/dist/package-test.js +1 -1
- package/dist/package-test.js.map +1 -1
- package/dist/package.js +1 -1
- package/dist/package.js.map +1 -1
- package/package.json +2 -2
- package/src/demo/demo-st-ui.ts +1 -2
- package/src/polytool/const.ts +0 -1
- package/src/polytool/pt-enumerate-seq-dialog.ts +9 -96
- package/src/polytool/types.ts +0 -1
- package/test-console-output-1.log +82 -82
- package/test-record-1.mp4 +0 -0
- package/src/polytool/pt-monomer-selection-dialog.ts +0 -237
package/test-record-1.mp4
CHANGED
|
Binary file
|
|
@@ -1,237 +0,0 @@
|
|
|
1
|
-
/* eslint-disable max-len */
|
|
2
|
-
import * as ui from 'datagrok-api/ui';
|
|
3
|
-
import * as DG from 'datagrok-api/dg';
|
|
4
|
-
|
|
5
|
-
import {HelmType, PolymerType} from '@datagrok-libraries/bio/src/helm/types';
|
|
6
|
-
import {IMonomerLib, Monomer} from '@datagrok-libraries/bio/src/types/monomer-library';
|
|
7
|
-
import {polymerTypeToHelmType} from '@datagrok-libraries/bio/src/utils/macromolecule/utils';
|
|
8
|
-
|
|
9
|
-
import {parseMonomerSymbolList} from './pt-placeholders-input';
|
|
10
|
-
|
|
11
|
-
const MAX_SUGGESTIONS = 20;
|
|
12
|
-
|
|
13
|
-
/** Shows a dialog for selecting monomers with autocomplete and tag-based display.
|
|
14
|
-
* @returns comma-separated monomer symbols, or null if cancelled */
|
|
15
|
-
export async function showMonomerSelectionDialog(
|
|
16
|
-
monomerLib: IMonomerLib, polymerType: PolymerType, presetMonomers?: string[],
|
|
17
|
-
): Promise<string[] | null> {
|
|
18
|
-
return new Promise<string[] | null>((resolve) => {
|
|
19
|
-
const helmType: HelmType = polymerTypeToHelmType(polymerType);
|
|
20
|
-
const allSymbols = monomerLib.getMonomerSymbolsByType(polymerType);
|
|
21
|
-
|
|
22
|
-
const selectedMonomers: string[] = presetMonomers ? [...presetMonomers] : [];
|
|
23
|
-
|
|
24
|
-
const tagsHost = ui.div([], {style: {display: 'flex', flexWrap: 'wrap', gap: '4px', marginTop: '8px', maxWidth: '400px'}});
|
|
25
|
-
const input = ui.input.string('Monomers', {value: ''});
|
|
26
|
-
const inputEl = input.input as HTMLInputElement;
|
|
27
|
-
inputEl.setAttribute('autocomplete', 'off');
|
|
28
|
-
inputEl.placeholder = 'Type to search...';
|
|
29
|
-
|
|
30
|
-
let currentMenu: DG.Menu | null = null;
|
|
31
|
-
let menuItems: HTMLElement[] = [];
|
|
32
|
-
let highlightedIndex = -1;
|
|
33
|
-
|
|
34
|
-
function renderTags(): void {
|
|
35
|
-
tagsHost.innerHTML = '';
|
|
36
|
-
for (const symbol of selectedMonomers) {
|
|
37
|
-
const removeBtn = ui.iconFA('times', () => {
|
|
38
|
-
const idx = selectedMonomers.indexOf(symbol);
|
|
39
|
-
if (idx >= 0) {
|
|
40
|
-
selectedMonomers.splice(idx, 1);
|
|
41
|
-
renderTags();
|
|
42
|
-
}
|
|
43
|
-
});
|
|
44
|
-
removeBtn.style.marginLeft = '4px';
|
|
45
|
-
removeBtn.style.cursor = 'pointer';
|
|
46
|
-
|
|
47
|
-
const tag = ui.div([ui.span([symbol]), removeBtn], {
|
|
48
|
-
style: {
|
|
49
|
-
display: 'inline-flex', alignItems: 'center',
|
|
50
|
-
padding: '2px 6px', borderRadius: '4px',
|
|
51
|
-
backgroundColor: 'var(--grey-2)', border: '1px solid var(--grey-3)',
|
|
52
|
-
fontSize: '12px', cursor: 'default',
|
|
53
|
-
},
|
|
54
|
-
});
|
|
55
|
-
// Tooltip on hover
|
|
56
|
-
tag.addEventListener('mouseenter', (e) => {
|
|
57
|
-
const tooltip = monomerLib.getTooltip(helmType, symbol);
|
|
58
|
-
ui.tooltip.show(tooltip, tag.getBoundingClientRect().left, tag.getBoundingClientRect().bottom + 16);
|
|
59
|
-
});
|
|
60
|
-
tag.addEventListener('mouseleave', () => { ui.tooltip.hide(); });
|
|
61
|
-
|
|
62
|
-
tagsHost.appendChild(tag);
|
|
63
|
-
}
|
|
64
|
-
}
|
|
65
|
-
|
|
66
|
-
function addMonomer(symbol: string): void {
|
|
67
|
-
if (!selectedMonomers.includes(symbol)) {
|
|
68
|
-
selectedMonomers.push(symbol);
|
|
69
|
-
renderTags();
|
|
70
|
-
}
|
|
71
|
-
inputEl.value = '';
|
|
72
|
-
hideMenu();
|
|
73
|
-
inputEl.focus();
|
|
74
|
-
}
|
|
75
|
-
|
|
76
|
-
function hideMenu(): void {
|
|
77
|
-
if (currentMenu) {
|
|
78
|
-
currentMenu.hide();
|
|
79
|
-
currentMenu = null;
|
|
80
|
-
}
|
|
81
|
-
menuItems = [];
|
|
82
|
-
highlightedIndex = -1;
|
|
83
|
-
}
|
|
84
|
-
|
|
85
|
-
function getSuggestions(query: string): {symbol: string, monomer: Monomer | null}[] {
|
|
86
|
-
const q = query.toLowerCase();
|
|
87
|
-
const results: {symbol: string, monomer: Monomer | null, rank: number}[] = [];
|
|
88
|
-
|
|
89
|
-
for (const symbol of allSymbols) {
|
|
90
|
-
if (selectedMonomers.includes(symbol))
|
|
91
|
-
continue;
|
|
92
|
-
const monomer = monomerLib.getMonomer(polymerType, symbol);
|
|
93
|
-
const symLower = symbol.toLowerCase();
|
|
94
|
-
const nameLower = monomer?.name?.toLowerCase() ?? '';
|
|
95
|
-
|
|
96
|
-
if (symLower.startsWith(q))
|
|
97
|
-
results.push({symbol, monomer, rank: 0});
|
|
98
|
-
else if (symLower.includes(q))
|
|
99
|
-
results.push({symbol, monomer, rank: 1});
|
|
100
|
-
else if (nameLower.includes(q))
|
|
101
|
-
results.push({symbol, monomer, rank: 2});
|
|
102
|
-
}
|
|
103
|
-
|
|
104
|
-
results.sort((a, b) => a.rank - b.rank || a.symbol.localeCompare(b.symbol));
|
|
105
|
-
return results.slice(0, MAX_SUGGESTIONS);
|
|
106
|
-
}
|
|
107
|
-
|
|
108
|
-
function showSuggestions(): void {
|
|
109
|
-
hideMenu();
|
|
110
|
-
const query = inputEl.value.trim();
|
|
111
|
-
if (!query)
|
|
112
|
-
return;
|
|
113
|
-
|
|
114
|
-
const suggestions = getSuggestions(query);
|
|
115
|
-
if (suggestions.length === 0)
|
|
116
|
-
return;
|
|
117
|
-
|
|
118
|
-
currentMenu = DG.Menu.popup();
|
|
119
|
-
const maxElement = suggestions.reduce((max, s) => {
|
|
120
|
-
const label = s.monomer?.name ? `${s.symbol} - ${s.monomer.name}` : s.symbol;
|
|
121
|
-
if (max.length < label.length)
|
|
122
|
-
return label;
|
|
123
|
-
return max;
|
|
124
|
-
}, '');
|
|
125
|
-
currentMenu.item(maxElement, () => {}); // Dummy item to set menu width
|
|
126
|
-
|
|
127
|
-
const causedBy = new MouseEvent('mousemove', {clientX: inputEl.getBoundingClientRect().left, clientY: inputEl.getBoundingClientRect().bottom});
|
|
128
|
-
currentMenu.show({causedBy: causedBy,
|
|
129
|
-
y: inputEl.offsetHeight + inputEl.offsetTop, x: inputEl.offsetLeft});
|
|
130
|
-
|
|
131
|
-
// collect menu items for keyboard navigation
|
|
132
|
-
setTimeout(() => {
|
|
133
|
-
currentMenu?.clear();
|
|
134
|
-
for (const s of suggestions) {
|
|
135
|
-
const label = s.monomer?.name ? `${s.symbol} - ${s.monomer.name}` : s.symbol;
|
|
136
|
-
currentMenu?.item(label, () => { addMonomer(s.symbol); });
|
|
137
|
-
}
|
|
138
|
-
|
|
139
|
-
const menuRoot = document.querySelector('.d4-menu-popup:last-of-type');
|
|
140
|
-
if (menuRoot)
|
|
141
|
-
menuItems = Array.from(menuRoot.querySelectorAll('.d4-menu-item')) as HTMLElement[];
|
|
142
|
-
|
|
143
|
-
highlightedIndex = -1;
|
|
144
|
-
}, 0);
|
|
145
|
-
}
|
|
146
|
-
|
|
147
|
-
function updateHighlight(newIndex: number): void {
|
|
148
|
-
if (menuItems.length === 0)
|
|
149
|
-
return;
|
|
150
|
-
if (highlightedIndex >= 0 && highlightedIndex < menuItems.length)
|
|
151
|
-
menuItems[highlightedIndex].classList.remove('d4-menu-item-hover');
|
|
152
|
-
highlightedIndex = newIndex;
|
|
153
|
-
if (highlightedIndex >= 0 && highlightedIndex < menuItems.length) {
|
|
154
|
-
menuItems[highlightedIndex].classList.add('d4-menu-item-hover');
|
|
155
|
-
menuItems[highlightedIndex].scrollIntoView({block: 'nearest'});
|
|
156
|
-
}
|
|
157
|
-
}
|
|
158
|
-
|
|
159
|
-
inputEl.addEventListener('input', () => { showSuggestions(); });
|
|
160
|
-
|
|
161
|
-
// Handle pasting multiple monomers (space / comma / newline separated)
|
|
162
|
-
inputEl.addEventListener('paste', (e: ClipboardEvent) => {
|
|
163
|
-
const pastedText = e.clipboardData?.getData('text');
|
|
164
|
-
if (!pastedText)
|
|
165
|
-
return;
|
|
166
|
-
|
|
167
|
-
// Split on newlines first, then parse each line (handles parenthesized symbols like hArg(Et,Et))
|
|
168
|
-
const lines = pastedText.split(/[\n\r]+/).map((l) => l.trim()).filter((l) => l.length > 0);
|
|
169
|
-
const candidates: string[] = [];
|
|
170
|
-
for (const line of lines) {
|
|
171
|
-
const parsed = parseMonomerSymbolList(line);
|
|
172
|
-
// If parseMonomerSymbolList returned a single token but the line has spaces and no commas,
|
|
173
|
-
// split on spaces as well (e.g. "K P F" -> ["K", "P", "F"])
|
|
174
|
-
if (parsed.length === 1 && line.includes(' ') && !line.includes(','))
|
|
175
|
-
candidates.push(...line.split(/\s+/).map((s) => s.trim()).filter((s) => s.length > 0));
|
|
176
|
-
else
|
|
177
|
-
candidates.push(...parsed);
|
|
178
|
-
}
|
|
179
|
-
|
|
180
|
-
if (candidates.length <= 1)
|
|
181
|
-
return; // Single symbol: let default paste + autocomplete handle it
|
|
182
|
-
|
|
183
|
-
e.preventDefault();
|
|
184
|
-
|
|
185
|
-
for (const candidate of candidates) {
|
|
186
|
-
if (allSymbols.includes(candidate) && !selectedMonomers.includes(candidate))
|
|
187
|
-
selectedMonomers.push(candidate);
|
|
188
|
-
}
|
|
189
|
-
|
|
190
|
-
renderTags();
|
|
191
|
-
inputEl.value = '';
|
|
192
|
-
hideMenu();
|
|
193
|
-
inputEl.focus();
|
|
194
|
-
});
|
|
195
|
-
|
|
196
|
-
inputEl.addEventListener('keydown', (e: KeyboardEvent) => {
|
|
197
|
-
if (e.key === 'ArrowDown') {
|
|
198
|
-
e.preventDefault();
|
|
199
|
-
if (menuItems.length > 0) {
|
|
200
|
-
const next = (highlightedIndex + 1) % menuItems.length;
|
|
201
|
-
updateHighlight(next);
|
|
202
|
-
}
|
|
203
|
-
} else if (e.key === 'ArrowUp') {
|
|
204
|
-
e.preventDefault();
|
|
205
|
-
if (menuItems.length > 0) {
|
|
206
|
-
const prev = (highlightedIndex - 1 + menuItems.length) % menuItems.length;
|
|
207
|
-
updateHighlight(prev);
|
|
208
|
-
}
|
|
209
|
-
} else if (e.key === 'Enter') {
|
|
210
|
-
e.preventDefault();
|
|
211
|
-
e.stopPropagation();
|
|
212
|
-
if (highlightedIndex >= 0 && highlightedIndex < menuItems.length) {
|
|
213
|
-
menuItems[highlightedIndex].click();
|
|
214
|
-
} else {
|
|
215
|
-
// If input exactly matches a symbol, add it directly
|
|
216
|
-
const val = inputEl.value.trim();
|
|
217
|
-
if (val && allSymbols.includes(val))
|
|
218
|
-
addMonomer(val);
|
|
219
|
-
}
|
|
220
|
-
} else if (e.key === 'Escape') {
|
|
221
|
-
hideMenu();
|
|
222
|
-
}
|
|
223
|
-
});
|
|
224
|
-
|
|
225
|
-
renderTags();
|
|
226
|
-
|
|
227
|
-
const dlg = ui.dialog({title: 'Select Monomers', showFooter: true})
|
|
228
|
-
.add(ui.div([input.root, tagsHost], {style: {minWidth: '350px', minHeight: '200px'}}))
|
|
229
|
-
.onOK(() => { resolve(selectedMonomers); })
|
|
230
|
-
.onCancel(() => { resolve(null); })
|
|
231
|
-
.show({resizable: true});
|
|
232
|
-
// dlg.root.addEventListener('close', () => { hideMenu(); });
|
|
233
|
-
|
|
234
|
-
inputEl.focus();
|
|
235
|
-
setTimeout(() => { showSuggestions(); }, 0);
|
|
236
|
-
});
|
|
237
|
-
}
|