Spaces:
Sleeping
Plasmid Editor: Benchling-style inline sequence editing
Browse filesReplace the indirect From/To + Delete/Insert flow with direct, click-and-type
editing on the sequence canvas:
- click to place a blinking caret between bases; drag to select a region
- type A/C/G/T/N to insert at the caret (or replace the selection)
- Backspace / Delete; arrow keys to move; Shift+arrows to extend selection;
Home/End; Cmd/Ctrl+A select-all; Cmd/Ctrl+C copy; paste sanitised to ACGTN
- live position + length; features + map remap and restriction sites rescan
(debounced while typing so we don't hit the backend on every keystroke)
Per-base interactive render below EDIT_CAP (20 kb); larger sequences keep the
read-only run view. Also fixes a latent bug where applyEdit refreshed the small
meta line but not the Length/GC chips or the methods box — now both update on
every edit (affected the old Delete/Insert buttons too).
Co-Authored-By: Claude Opus 4.8 <noreply@anthropic.com>
- dee/static/app.css +16 -0
- dee/static/app.js +177 -9
- dee/static/index.html +2 -2
|
@@ -5563,6 +5563,22 @@ h3, h4 {
|
|
| 5563 |
.seqed-sel { outline: 1.5px solid var(--brand); background: color-mix(in srgb, var(--brand) 30%, transparent) !important; border-radius: 2px; }
|
| 5564 |
.seqed-toobig { font-size: 13px; color: var(--ink-soft); padding: 18px; font-style: italic; }
|
| 5565 |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 5566 |
@media (max-width: 640px) {
|
| 5567 |
.seqtool-input { width: 100%; }
|
| 5568 |
.seqtool-find { width: 100%; }
|
|
|
|
| 5563 |
.seqed-sel { outline: 1.5px solid var(--brand); background: color-mix(in srgb, var(--brand) 30%, transparent) !important; border-radius: 2px; }
|
| 5564 |
.seqed-toobig { font-size: 13px; color: var(--ink-soft); padding: 18px; font-style: italic; }
|
| 5565 |
|
| 5566 |
+
/* ── Inline (per-base) sequence editor ── */
|
| 5567 |
+
.seqed-edit { outline: none; cursor: text; }
|
| 5568 |
+
.seqed-edit .seqed-bases { letter-spacing: 0; } /* flush bases → contiguous selection + tight caret */
|
| 5569 |
+
.seqb { display: inline-block; }
|
| 5570 |
+
.seqb-feat { background: color-mix(in srgb, var(--featc) 26%, transparent); }
|
| 5571 |
+
.seqb-sel { background: color-mix(in srgb, var(--brand) 32%, transparent) !important; border-radius: 1px; }
|
| 5572 |
+
.seqb-find { background: var(--warning) !important; color: #1a1205; }
|
| 5573 |
+
.seqed-caret {
|
| 5574 |
+
display: inline-block; width: 0; margin: 0 -0.5px;
|
| 5575 |
+
border-left: 1.5px solid var(--brand);
|
| 5576 |
+
height: 1.15em; vertical-align: -0.18em;
|
| 5577 |
+
animation: seqcaret 1.05s steps(1) infinite;
|
| 5578 |
+
}
|
| 5579 |
+
@keyframes seqcaret { 0%, 49.9% { opacity: 1; } 50%, 100% { opacity: 0; } }
|
| 5580 |
+
.seqed-ro-note { font-size: 11.5px; color: var(--ink-faint); font-style: italic; margin: 2px 0 10px; }
|
| 5581 |
+
|
| 5582 |
@media (max-width: 640px) {
|
| 5583 |
.seqtool-input { width: 100%; }
|
| 5584 |
.seqtool-find { width: 100%; }
|
|
@@ -6914,8 +6914,16 @@ function runOracle(opts){
|
|
| 6914 |
})();
|
| 6915 |
const SEQ_RENDER_CAP = 60000; // bp — bigger than this, show a notice not a wall
|
| 6916 |
const SEQ_LINE = 60;
|
|
|
|
| 6917 |
let sel = null; // {from, to} 1-based inclusive
|
| 6918 |
let findHits = [], findIdx = -1, findLen = 0;
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 6919 |
|
| 6920 |
const rcStr = (s) => s.toUpperCase().replace(/[^ACGTN]/g, '')
|
| 6921 |
.split('').reverse().map((c) => ({ A: 'T', T: 'A', G: 'C', C: 'G', N: 'N' }[c] || 'N')).join('');
|
|
@@ -6939,14 +6947,60 @@ function runOracle(opts){
|
|
| 6939 |
function renderSequence() {
|
| 6940 |
const seq = plasmid.sequence, len = seq.length, feats = plasmid.features || [];
|
| 6941 |
syncSelInputs();
|
|
|
|
| 6942 |
if (len > SEQ_RENDER_CAP) {
|
| 6943 |
-
mapWrap.innerHTML = `<div class="seqed-toobig">This sequence is ${len.toLocaleString()} bp — too long to render
|
| 6944 |
+ `Use Find or the From/To fields to work on a region; export to view the full sequence.</div>`;
|
| 6945 |
return;
|
| 6946 |
}
|
| 6947 |
-
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 6948 |
const styleKey = (i) => `${_featColorAt(i, feats)}|${(i >= sF && i < sT) ? 'S' : ''}${_inFind(i) ? 'F' : ''}`;
|
| 6949 |
-
let html =
|
| 6950 |
for (let ls = 0; ls < len; ls += SEQ_LINE) {
|
| 6951 |
const le = Math.min(ls + SEQ_LINE, len);
|
| 6952 |
html += `<div class="seqed-line"><span class="seqed-pos">${(ls + 1).toLocaleString()}</span><span class="seqed-bases">`;
|
|
@@ -6956,8 +7010,6 @@ function runOracle(opts){
|
|
| 6956 |
while (j < le && styleKey(j) === key) j++;
|
| 6957 |
const [color, flags] = key.split('|');
|
| 6958 |
const cls = 'seqed-run' + (flags.includes('S') ? ' seqed-sel' : '') + (flags.includes('F') ? ' seqed-find' : '');
|
| 6959 |
-
// Only emit a known-safe hex colour into the inline style (defends
|
| 6960 |
-
// against an injection-laden feature colour from a saved plasmid).
|
| 6961 |
const safe = /^#[0-9A-Fa-f]{3,8}$/.test(color) ? color : '';
|
| 6962 |
const st = safe ? ` style="--featc:${safe}"` : '';
|
| 6963 |
html += `<span class="${cls}"${color ? ' data-feat="1"' : ''}${st}>${seq.slice(i, j)}</span>`;
|
|
@@ -6971,6 +7023,35 @@ function runOracle(opts){
|
|
| 6971 |
if (selRun && sel) selRun.scrollIntoView({ block: 'nearest' });
|
| 6972 |
}
|
| 6973 |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 6974 |
function syncSelInputs() {
|
| 6975 |
const f = $('plasmidSelFrom'), t = $('plasmidSelTo'), l = $('plasmidSelLen');
|
| 6976 |
if (sel) { if (f) f.value = sel.from; if (t) t.value = sel.to; if (l) l.textContent = `${(sel.to - sel.from + 1).toLocaleString()} bp selected`; }
|
|
@@ -7008,16 +7089,31 @@ function runOracle(opts){
|
|
| 7008 |
}
|
| 7009 |
|
| 7010 |
// edits: rewrite the sequence + remap features + rescan restriction.
|
| 7011 |
-
function applyEdit(newSeq, remap) {
|
| 7012 |
plasmid.sequence = newSeq.toUpperCase(); plasmid.length = newSeq.length;
|
| 7013 |
plasmid.features = (plasmid.features || []).map(remap).filter((f) => f && f.end > f.start);
|
| 7014 |
plasmid.gc = gcOf(newSeq); plasmid.source = plasmid.source || 'raw';
|
| 7015 |
sel = null; findHits = []; restriction = null; selected.clear();
|
| 7016 |
-
setMeta(); nameEl.value = plasmid.name || nameEl.value;
|
| 7017 |
renderMap(); renderFeatures();
|
| 7018 |
gelEl.hidden = true; gelEl.innerHTML = '';
|
| 7019 |
-
|
| 7020 |
-
loadRestriction();
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 7021 |
}
|
| 7022 |
function deleteRange(a, b) { // 0-based [a, b)
|
| 7023 |
const seq = plasmid.sequence; const cut = b - a;
|
|
@@ -7047,6 +7143,78 @@ function runOracle(opts){
|
|
| 7047 |
if (f && t) setSel(f, t); };
|
| 7048 |
if ($('plasmidSelFrom')) $('plasmidSelFrom').addEventListener('change', onSelInput);
|
| 7049 |
if ($('plasmidSelTo')) $('plasmidSelTo').addEventListener('change', onSelInput);
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 7050 |
// click a feature → select it (and jump to sequence)
|
| 7051 |
featuresEl.addEventListener('click', (e) => {
|
| 7052 |
const item = e.target.closest('.plasmid-feat-item'); if (!item) return;
|
|
|
|
| 6914 |
})();
|
| 6915 |
const SEQ_RENDER_CAP = 60000; // bp — bigger than this, show a notice not a wall
|
| 6916 |
const SEQ_LINE = 60;
|
| 6917 |
+
const EDIT_CAP = 20000; // bp — full inline per-base editing below this
|
| 6918 |
let sel = null; // {from, to} 1-based inclusive
|
| 6919 |
let findHits = [], findIdx = -1, findLen = 0;
|
| 6920 |
+
// Inline-editor state (Benchling-style click-and-type).
|
| 6921 |
+
let caret = null; // cursor index 0..len (before base `caret`), or null
|
| 6922 |
+
let selAnchor = null; // anchor for keyboard/drag selection extension
|
| 6923 |
+
let dragging = false, dragAnchor = 0;
|
| 6924 |
+
let seqSpans = null; // editable render: NodeList of per-base <span>, indexed by position
|
| 6925 |
+
let curSel = null; // [a,b) 0-based currently painted on spans
|
| 6926 |
+
let _rescanT = null; // debounce timer for restriction rescan during typing
|
| 6927 |
|
| 6928 |
const rcStr = (s) => s.toUpperCase().replace(/[^ACGTN]/g, '')
|
| 6929 |
.split('').reverse().map((c) => ({ A: 'T', T: 'A', G: 'C', C: 'G', N: 'N' }[c] || 'N')).join('');
|
|
|
|
| 6947 |
function renderSequence() {
|
| 6948 |
const seq = plasmid.sequence, len = seq.length, feats = plasmid.features || [];
|
| 6949 |
syncSelInputs();
|
| 6950 |
+
seqSpans = null;
|
| 6951 |
if (len > SEQ_RENDER_CAP) {
|
| 6952 |
+
mapWrap.innerHTML = `<div class="seqed-toobig">This sequence is ${len.toLocaleString()} bp — too long to render in the browser. `
|
| 6953 |
+ `Use Find or the From/To fields to work on a region; export to view the full sequence.</div>`;
|
| 6954 |
return;
|
| 6955 |
}
|
| 6956 |
+
if (len > EDIT_CAP) { renderSeqReadonly(seq, len, feats); return; }
|
| 6957 |
+
renderSeqEditable(seq, len, feats);
|
| 6958 |
+
}
|
| 6959 |
+
|
| 6960 |
+
// First feature covering each base wins; one pass for the whole sequence.
|
| 6961 |
+
function _colorArray(len, feats) {
|
| 6962 |
+
const arr = new Array(len).fill('');
|
| 6963 |
+
for (const f of feats) {
|
| 6964 |
+
const c = /^#[0-9A-Fa-f]{3,8}$/.test(f.color || '') ? f.color : '#9AA0AA';
|
| 6965 |
+
const a = Math.max(0, f.start | 0), b = Math.min(len, f.end | 0);
|
| 6966 |
+
for (let i = a; i < b; i++) if (!arr[i]) arr[i] = c;
|
| 6967 |
+
}
|
| 6968 |
+
return arr;
|
| 6969 |
+
}
|
| 6970 |
+
|
| 6971 |
+
// Editable, per-base render — click to place the caret, drag to select, type to edit.
|
| 6972 |
+
function renderSeqEditable(seq, len, feats) {
|
| 6973 |
+
const colors = _colorArray(len, feats);
|
| 6974 |
+
const sF = sel ? sel.from - 1 : -1, sT = sel ? sel.to : -1;
|
| 6975 |
+
const parts = ['<div class="seqed seqed-edit" tabindex="0" role="textbox" aria-multiline="true" '
|
| 6976 |
+
+ 'aria-label="DNA sequence — click to place the cursor, type A/C/G/T to edit, drag to select" spellcheck="false">'];
|
| 6977 |
+
for (let ls = 0; ls < len; ls += SEQ_LINE) {
|
| 6978 |
+
const le = Math.min(ls + SEQ_LINE, len);
|
| 6979 |
+
parts.push(`<div class="seqed-line"><span class="seqed-pos">${(ls + 1).toLocaleString()}</span><span class="seqed-bases">`);
|
| 6980 |
+
for (let i = ls; i < le; i++) {
|
| 6981 |
+
const c = colors[i];
|
| 6982 |
+
const cls = 'seqb' + (c ? ' seqb-feat' : '') + ((i >= sF && i < sT) ? ' seqb-sel' : '') + (_inFind(i) ? ' seqb-find' : '');
|
| 6983 |
+
const st = c ? ` style="--featc:${c}"` : '';
|
| 6984 |
+
parts.push(`<span class="${cls}" data-i="${i}"${st}>${seq[i]}</span>`);
|
| 6985 |
+
}
|
| 6986 |
+
parts.push('</span></div>');
|
| 6987 |
+
}
|
| 6988 |
+
if (len === 0) parts.push('<div class="seqed-line"><span class="seqed-pos">1</span><span class="seqed-bases"></span></div>');
|
| 6989 |
+
parts.push('</div>');
|
| 6990 |
+
mapWrap.innerHTML = parts.join('');
|
| 6991 |
+
const container = mapWrap.querySelector('.seqed-edit');
|
| 6992 |
+
seqSpans = container ? container.querySelectorAll('.seqb') : null;
|
| 6993 |
+
curSel = sel ? [sel.from - 1, sel.to] : null;
|
| 6994 |
+
placeCaretEl();
|
| 6995 |
+
const anchorEl = mapWrap.querySelector('.seqed-caret') || mapWrap.querySelector('.seqb-sel');
|
| 6996 |
+
if (anchorEl) anchorEl.scrollIntoView({ block: 'nearest' });
|
| 6997 |
+
}
|
| 6998 |
+
|
| 6999 |
+
// Legacy run-based read-only render — kept for sequences above EDIT_CAP.
|
| 7000 |
+
function renderSeqReadonly(seq, len, feats) {
|
| 7001 |
+
const sF = sel ? sel.from - 1 : -1, sT = sel ? sel.to : -1;
|
| 7002 |
const styleKey = (i) => `${_featColorAt(i, feats)}|${(i >= sF && i < sT) ? 'S' : ''}${_inFind(i) ? 'F' : ''}`;
|
| 7003 |
+
let html = `<div class="seqed seqed-readonly"><div class="seqed-ro-note">Read-only view (over ${EDIT_CAP.toLocaleString()} bp) — use Find or the From/To fields to edit a region.</div>`;
|
| 7004 |
for (let ls = 0; ls < len; ls += SEQ_LINE) {
|
| 7005 |
const le = Math.min(ls + SEQ_LINE, len);
|
| 7006 |
html += `<div class="seqed-line"><span class="seqed-pos">${(ls + 1).toLocaleString()}</span><span class="seqed-bases">`;
|
|
|
|
| 7010 |
while (j < le && styleKey(j) === key) j++;
|
| 7011 |
const [color, flags] = key.split('|');
|
| 7012 |
const cls = 'seqed-run' + (flags.includes('S') ? ' seqed-sel' : '') + (flags.includes('F') ? ' seqed-find' : '');
|
|
|
|
|
|
|
| 7013 |
const safe = /^#[0-9A-Fa-f]{3,8}$/.test(color) ? color : '';
|
| 7014 |
const st = safe ? ` style="--featc:${safe}"` : '';
|
| 7015 |
html += `<span class="${cls}"${color ? ' data-feat="1"' : ''}${st}>${seq.slice(i, j)}</span>`;
|
|
|
|
| 7023 |
if (selRun && sel) selRun.scrollIntoView({ block: 'nearest' });
|
| 7024 |
}
|
| 7025 |
|
| 7026 |
+
// ── caret + selection painting (editable mode, no full re-render) ──
|
| 7027 |
+
function placeCaretEl() {
|
| 7028 |
+
const old = mapWrap.querySelector('.seqed-caret'); if (old) old.remove();
|
| 7029 |
+
if (caret == null || !seqSpans) return;
|
| 7030 |
+
const car = document.createElement('i'); car.className = 'seqed-caret'; car.setAttribute('aria-hidden', 'true');
|
| 7031 |
+
if (caret >= seqSpans.length) {
|
| 7032 |
+
const lines = mapWrap.querySelectorAll('.seqed-bases');
|
| 7033 |
+
const last = lines[lines.length - 1]; if (last) last.appendChild(car);
|
| 7034 |
+
} else {
|
| 7035 |
+
const sp = seqSpans[caret]; sp.parentNode.insertBefore(car, sp);
|
| 7036 |
+
}
|
| 7037 |
+
}
|
| 7038 |
+
function paintSel(a, b) {
|
| 7039 |
+
if (!seqSpans) return;
|
| 7040 |
+
if (curSel) for (let i = curSel[0]; i < curSel[1] && i < seqSpans.length; i++) { if (seqSpans[i]) seqSpans[i].classList.remove('seqb-sel'); }
|
| 7041 |
+
if (a != null && b > a) { for (let i = a; i < b && i < seqSpans.length; i++) { if (seqSpans[i]) seqSpans[i].classList.add('seqb-sel'); } curSel = [a, b]; }
|
| 7042 |
+
else curSel = null;
|
| 7043 |
+
}
|
| 7044 |
+
function idxFromEvent(e) {
|
| 7045 |
+
const sp = e.target.closest && e.target.closest('.seqb');
|
| 7046 |
+
if (sp) { let i = +sp.getAttribute('data-i'); const r = sp.getBoundingClientRect(); if (e.clientX > r.left + r.width / 2) i += 1; return i; }
|
| 7047 |
+
const bl = e.target.closest && e.target.closest('.seqed-bases');
|
| 7048 |
+
if (bl) { const ss = bl.querySelectorAll('.seqb'); if (ss.length) return (+ss[ss.length - 1].getAttribute('data-i')) + 1; }
|
| 7049 |
+
return null;
|
| 7050 |
+
}
|
| 7051 |
+
function focusEditor() { const c = mapWrap.querySelector('.seqed-edit'); if (c) c.focus({ preventScroll: true }); }
|
| 7052 |
+
function caretVisible() { const cr = mapWrap.querySelector('.seqed-caret'); if (cr) cr.scrollIntoView({ block: 'nearest' }); }
|
| 7053 |
+
function isEditable() { return viewMode === 'sequence' && plasmid && plasmid.length <= EDIT_CAP; }
|
| 7054 |
+
|
| 7055 |
function syncSelInputs() {
|
| 7056 |
const f = $('plasmidSelFrom'), t = $('plasmidSelTo'), l = $('plasmidSelLen');
|
| 7057 |
if (sel) { if (f) f.value = sel.from; if (t) t.value = sel.to; if (l) l.textContent = `${(sel.to - sel.from + 1).toLocaleString()} bp selected`; }
|
|
|
|
| 7089 |
}
|
| 7090 |
|
| 7091 |
// edits: rewrite the sequence + remap features + rescan restriction.
|
| 7092 |
+
function applyEdit(newSeq, remap, defer) {
|
| 7093 |
plasmid.sequence = newSeq.toUpperCase(); plasmid.length = newSeq.length;
|
| 7094 |
plasmid.features = (plasmid.features || []).map(remap).filter((f) => f && f.end > f.start);
|
| 7095 |
plasmid.gc = gcOf(newSeq); plasmid.source = plasmid.source || 'raw';
|
| 7096 |
sel = null; findHits = []; restriction = null; selected.clear();
|
| 7097 |
+
setMeta(); _renderPlasmidMeta(); nameEl.value = plasmid.name || nameEl.value;
|
| 7098 |
renderMap(); renderFeatures();
|
| 7099 |
gelEl.hidden = true; gelEl.innerHTML = '';
|
| 7100 |
+
if (defer) { scheduleRescan(); }
|
| 7101 |
+
else { enzGrid.innerHTML = '<span class="field-hint">Re-scanning restriction sites…</span>'; loadRestriction(); }
|
| 7102 |
+
}
|
| 7103 |
+
// During active typing we don't want a network restriction rescan on every
|
| 7104 |
+
// keystroke — debounce it until the user pauses.
|
| 7105 |
+
function scheduleRescan() {
|
| 7106 |
+
enzGrid.innerHTML = '<span class="field-hint">Editing… restriction sites update when you pause.</span>';
|
| 7107 |
+
clearTimeout(_rescanT);
|
| 7108 |
+
_rescanT = setTimeout(() => {
|
| 7109 |
+
enzGrid.innerHTML = '<span class="field-hint">Re-scanning restriction sites…</span>'; loadRestriction();
|
| 7110 |
+
}, 500);
|
| 7111 |
+
}
|
| 7112 |
+
// Single-applyEdit splice (inline editor): remove [a,b), insert `ins`, remap features.
|
| 7113 |
+
function replaceRange(a, b, ins, defer) {
|
| 7114 |
+
const seq = plasmid.sequence, shift = ins.length - (b - a);
|
| 7115 |
+
const map = (x) => (x <= a ? x : (x >= b ? x + shift : a + Math.min(Math.max(0, x - a), ins.length)));
|
| 7116 |
+
applyEdit(seq.slice(0, a) + ins + seq.slice(b), (f) => ({ ...f, start: map(f.start), end: map(f.end) }), defer);
|
| 7117 |
}
|
| 7118 |
function deleteRange(a, b) { // 0-based [a, b)
|
| 7119 |
const seq = plasmid.sequence; const cut = b - a;
|
|
|
|
| 7143 |
if (f && t) setSel(f, t); };
|
| 7144 |
if ($('plasmidSelFrom')) $('plasmidSelFrom').addEventListener('change', onSelInput);
|
| 7145 |
if ($('plasmidSelTo')) $('plasmidSelTo').addEventListener('change', onSelInput);
|
| 7146 |
+
|
| 7147 |
+
// ── Inline editing: mouse caret/selection + keyboard typing (Benchling-style) ──
|
| 7148 |
+
function _editInsert(ins) {
|
| 7149 |
+
const len = plasmid.length;
|
| 7150 |
+
if (sel) { const a = sel.from - 1, b = sel.to; caret = a + ins.length; replaceRange(a, b, ins, true); }
|
| 7151 |
+
else { const p = caret == null ? len : caret; caret = p + ins.length; replaceRange(p, p, ins, true); }
|
| 7152 |
+
sel = null; selAnchor = null; caretVisible(); focusEditor();
|
| 7153 |
+
}
|
| 7154 |
+
mapWrap.addEventListener('mousedown', (e) => {
|
| 7155 |
+
if (!isEditable()) return;
|
| 7156 |
+
const i = idxFromEvent(e); if (i == null) return;
|
| 7157 |
+
e.preventDefault();
|
| 7158 |
+
dragging = true; dragAnchor = i; selAnchor = i;
|
| 7159 |
+
paintSel(null); sel = null; syncSelInputs();
|
| 7160 |
+
caret = i; placeCaretEl(); focusEditor();
|
| 7161 |
+
});
|
| 7162 |
+
mapWrap.addEventListener('mousemove', (e) => {
|
| 7163 |
+
if (!dragging || !isEditable()) return;
|
| 7164 |
+
const i = idxFromEvent(e); if (i == null) return;
|
| 7165 |
+
const a = Math.min(dragAnchor, i), b = Math.max(dragAnchor, i);
|
| 7166 |
+
if (b > a) { caret = null; const c = mapWrap.querySelector('.seqed-caret'); if (c) c.remove(); paintSel(a, b); }
|
| 7167 |
+
else { paintSel(null); caret = i; placeCaretEl(); }
|
| 7168 |
+
});
|
| 7169 |
+
window.addEventListener('mouseup', () => {
|
| 7170 |
+
if (!dragging) return; dragging = false;
|
| 7171 |
+
sel = curSel ? { from: curSel[0] + 1, to: curSel[1] } : null;
|
| 7172 |
+
syncSelInputs();
|
| 7173 |
+
});
|
| 7174 |
+
mapWrap.addEventListener('paste', (e) => {
|
| 7175 |
+
if (!isEditable() || !(e.target.closest && e.target.closest('.seqed-edit'))) return;
|
| 7176 |
+
e.preventDefault();
|
| 7177 |
+
const txt = ((e.clipboardData || window.clipboardData).getData('text') || '').toUpperCase().replace(/[^ACGTN]/g, '');
|
| 7178 |
+
if (txt) _editInsert(txt);
|
| 7179 |
+
});
|
| 7180 |
+
mapWrap.addEventListener('keydown', (e) => {
|
| 7181 |
+
if (!isEditable() || !(e.target.closest && e.target.closest('.seqed-edit'))) return;
|
| 7182 |
+
const len = plasmid.length, k = e.key;
|
| 7183 |
+
if (/^[acgtnACGTN]$/.test(k) && !e.metaKey && !e.ctrlKey) { e.preventDefault(); _editInsert(k.toUpperCase()); return; }
|
| 7184 |
+
if (k === 'Backspace') {
|
| 7185 |
+
e.preventDefault();
|
| 7186 |
+
if (sel) { const a = sel.from - 1, b = sel.to; caret = a; replaceRange(a, b, '', true); }
|
| 7187 |
+
else if (caret > 0) { const c0 = caret; caret = c0 - 1; replaceRange(c0 - 1, c0, '', true); }
|
| 7188 |
+
sel = null; selAnchor = null; caretVisible(); focusEditor(); return;
|
| 7189 |
+
}
|
| 7190 |
+
if (k === 'Delete') {
|
| 7191 |
+
e.preventDefault();
|
| 7192 |
+
if (sel) { const a = sel.from - 1, b = sel.to; caret = a; replaceRange(a, b, '', true); }
|
| 7193 |
+
else if (caret != null && caret < len) { replaceRange(caret, caret + 1, '', true); }
|
| 7194 |
+
sel = null; selAnchor = null; caretVisible(); focusEditor(); return;
|
| 7195 |
+
}
|
| 7196 |
+
if (k === 'ArrowLeft' || k === 'ArrowRight' || k === 'ArrowUp' || k === 'ArrowDown' || k === 'Home' || k === 'End') {
|
| 7197 |
+
e.preventDefault();
|
| 7198 |
+
let c = caret == null ? (sel ? sel.from - 1 : 0) : caret;
|
| 7199 |
+
if (k === 'ArrowLeft') c = Math.max(0, c - 1);
|
| 7200 |
+
else if (k === 'ArrowRight') c = Math.min(len, c + 1);
|
| 7201 |
+
else if (k === 'ArrowUp') c = Math.max(0, c - SEQ_LINE);
|
| 7202 |
+
else if (k === 'ArrowDown') c = Math.min(len, c + SEQ_LINE);
|
| 7203 |
+
else if (k === 'Home') c = c - (c % SEQ_LINE);
|
| 7204 |
+
else if (k === 'End') c = Math.min(len, c - (c % SEQ_LINE) + SEQ_LINE);
|
| 7205 |
+
if (e.shiftKey) {
|
| 7206 |
+
if (selAnchor == null) selAnchor = caret == null ? c : caret;
|
| 7207 |
+
const a = Math.min(selAnchor, c), b = Math.max(selAnchor, c);
|
| 7208 |
+
caret = c; paintSel(a, b); placeCaretEl();
|
| 7209 |
+
sel = (b > a) ? { from: a + 1, to: b } : null; syncSelInputs();
|
| 7210 |
+
} else { selAnchor = null; paintSel(null); sel = null; syncSelInputs(); caret = c; placeCaretEl(); }
|
| 7211 |
+
caretVisible(); return;
|
| 7212 |
+
}
|
| 7213 |
+
if ((e.metaKey || e.ctrlKey) && k.toLowerCase() === 'a') { e.preventDefault(); if (len) { sel = { from: 1, to: len }; caret = len; selAnchor = 0; renderSequence(); } return; }
|
| 7214 |
+
if ((e.metaKey || e.ctrlKey) && k.toLowerCase() === 'c') { if (sel) { e.preventDefault(); copyText(selSeq(), 'selection'); } return; }
|
| 7215 |
+
// swallow other single printable keys so they don't scroll / leak into the page
|
| 7216 |
+
if (k.length === 1 && !e.metaKey && !e.ctrlKey) e.preventDefault();
|
| 7217 |
+
});
|
| 7218 |
// click a feature → select it (and jump to sequence)
|
| 7219 |
featuresEl.addEventListener('click', (e) => {
|
| 7220 |
const item = e.target.closest('.plasmid-feat-item'); if (!item) return;
|
|
@@ -28,7 +28,7 @@
|
|
| 28 |
<!-- ?v= query bumps invalidate browser + iframe asset caches when app.css /
|
| 29 |
app.js change. Bump these numbers whenever you ship a frontend update —
|
| 30 |
without them, users keep getting the stale file for up to a week. -->
|
| 31 |
-
<link rel="stylesheet" href="/static/app.css?v=20260609-
|
| 32 |
<link rel="icon" type="image/svg+xml" href="/static/favicon.svg?v=2" />
|
| 33 |
<link rel="apple-touch-icon" href="/static/favicon.svg?v=2" />
|
| 34 |
<!-- Mol* (PDBe) viewer for AlphaFold structure embed. Loaded async; the
|
|
@@ -1817,6 +1817,6 @@
|
|
| 1817 |
<!-- Cloning reference data must load before app.js so the Designer
|
| 1818 |
can read VECTORS / ENZYMES / CLONING_METHODS / TAGS / LINKERS. -->
|
| 1819 |
<script src="/static/cloning_db.js?v=20260530-ui-polish" defer></script>
|
| 1820 |
-
<script src="/static/app.js?v=20260609-
|
| 1821 |
</body>
|
| 1822 |
</html>
|
|
|
|
| 28 |
<!-- ?v= query bumps invalidate browser + iframe asset caches when app.css /
|
| 29 |
app.js change. Bump these numbers whenever you ship a frontend update —
|
| 30 |
without them, users keep getting the stale file for up to a week. -->
|
| 31 |
+
<link rel="stylesheet" href="/static/app.css?v=20260609-editor" />
|
| 32 |
<link rel="icon" type="image/svg+xml" href="/static/favicon.svg?v=2" />
|
| 33 |
<link rel="apple-touch-icon" href="/static/favicon.svg?v=2" />
|
| 34 |
<!-- Mol* (PDBe) viewer for AlphaFold structure embed. Loaded async; the
|
|
|
|
| 1817 |
<!-- Cloning reference data must load before app.js so the Designer
|
| 1818 |
can read VECTORS / ENZYMES / CLONING_METHODS / TAGS / LINKERS. -->
|
| 1819 |
<script src="/static/cloning_db.js?v=20260530-ui-polish" defer></script>
|
| 1820 |
+
<script src="/static/app.js?v=20260609-editor" defer></script>
|
| 1821 |
</body>
|
| 1822 |
</html>
|