feat: add absorb command — merge source entity into target
DB: Absorb() merges body (newline-separated), unions tags, demotes
crystallized sources, soft-deletes source. Rejects crystallized targets.
API: POST /api/entities/:id/absorb { source_id }
CLI: nib absorb <target> <source> with prefix ID resolution
Web: absorb button on fluid entities, 'a' keyboard shortcut,
source picker modal
This commit is contained in:
+60
-6
@@ -85,6 +85,14 @@
|
||||
});
|
||||
return resp.json();
|
||||
},
|
||||
async absorbEntity(targetId, sourceId) {
|
||||
const resp = await fetch('/api/entities/' + targetId + '/absorb', {
|
||||
method: 'POST',
|
||||
headers: { 'Content-Type': 'application/json' },
|
||||
body: JSON.stringify({ source_id: sourceId }),
|
||||
});
|
||||
return resp.json();
|
||||
},
|
||||
async listTags() {
|
||||
const resp = await fetch('/api/tags');
|
||||
return resp.json();
|
||||
@@ -269,6 +277,7 @@
|
||||
actions += `<button class="action-btn" onclick="nibApp.demoteEntity('${e.id}')">demote</button>`;
|
||||
} else {
|
||||
actions += `<button class="action-btn primary" onclick="nibApp.showPromote('${e.id}')">promote</button>`;
|
||||
actions += `<button class="action-btn" onclick="nibApp.showAbsorb('${e.id}')">absorb</button>`;
|
||||
}
|
||||
actions += `<button class="action-btn danger" onclick="nibApp.deleteEntity('${e.id}')">delete</button>`;
|
||||
|
||||
@@ -469,6 +478,44 @@
|
||||
}
|
||||
},
|
||||
|
||||
showAbsorb(targetId) {
|
||||
const target = state.entities.find(x => x.id === targetId);
|
||||
if (!target) return;
|
||||
if (target.card_type) return;
|
||||
|
||||
const modal = $('#absorb-modal');
|
||||
modal.dataset.targetId = targetId;
|
||||
const list = $('#absorb-source-list');
|
||||
|
||||
const sources = state.entities.filter(x => x.id !== targetId);
|
||||
if (!sources.length) { list.innerHTML = '<div class="detail-empty">no other entities</div>'; }
|
||||
else {
|
||||
list.innerHTML = sources.map(e => {
|
||||
const g = displayGlyph(e);
|
||||
const gc = glyphClass(e);
|
||||
return `<div class="absorb-source-item" data-id="${e.id}">
|
||||
<span class="entity-glyph ${gc}">${g}</span>
|
||||
<span class="entity-body">${escHtml(e.body)}</span>
|
||||
</div>`;
|
||||
}).join('');
|
||||
}
|
||||
|
||||
list.querySelectorAll('.absorb-source-item').forEach(el => {
|
||||
el.addEventListener('click', async () => {
|
||||
modal.classList.add('hidden');
|
||||
modal.classList.remove('visible');
|
||||
await api.absorbEntity(targetId, el.dataset.id);
|
||||
await loadEntities();
|
||||
await loadTags();
|
||||
const idx = state.entities.findIndex(x => x.id === targetId);
|
||||
if (idx >= 0) selectEntity(idx);
|
||||
});
|
||||
});
|
||||
|
||||
modal.classList.remove('hidden');
|
||||
modal.classList.add('visible');
|
||||
},
|
||||
|
||||
async toggleStep(id, stepIdx) {
|
||||
const e = state.entities.find(x => x.id === id);
|
||||
if (!e || !e.card_data) return;
|
||||
@@ -520,13 +567,14 @@
|
||||
});
|
||||
});
|
||||
|
||||
$('.modal-backdrop').addEventListener('click', closeModal);
|
||||
$('.modal-close').addEventListener('click', closeModal);
|
||||
$$('.modal-backdrop').forEach(el => el.addEventListener('click', closeModal));
|
||||
$$('.modal-close').forEach(el => el.addEventListener('click', closeModal));
|
||||
|
||||
function closeModal() {
|
||||
const modal = $('#promote-modal');
|
||||
modal.classList.add('hidden');
|
||||
modal.classList.remove('visible');
|
||||
$$('.modal.visible').forEach(m => {
|
||||
m.classList.add('hidden');
|
||||
m.classList.remove('visible');
|
||||
});
|
||||
}
|
||||
|
||||
// ========== Keyboard shortcuts ==========
|
||||
@@ -541,7 +589,8 @@
|
||||
return;
|
||||
}
|
||||
|
||||
if ($('#promote-modal').classList.contains('visible')) {
|
||||
if ($('#promote-modal').classList.contains('visible') ||
|
||||
$('#absorb-modal').classList.contains('visible')) {
|
||||
if (ev.key === 'Escape') closeModal();
|
||||
return;
|
||||
}
|
||||
@@ -586,6 +635,11 @@
|
||||
startEditBody();
|
||||
break;
|
||||
}
|
||||
case 'a': {
|
||||
const e = state.entities[state.selectedIndex];
|
||||
if (e && !e.card_type) nibApp.showAbsorb(e.id);
|
||||
break;
|
||||
}
|
||||
case '1': switchView('stream'); break;
|
||||
case '2': switchView('cards'); break;
|
||||
}
|
||||
|
||||
@@ -59,6 +59,15 @@
|
||||
</div>
|
||||
</div>
|
||||
|
||||
<div id="absorb-modal" class="modal hidden">
|
||||
<div class="modal-backdrop"></div>
|
||||
<div class="modal-content">
|
||||
<h3>absorb source into target</h3>
|
||||
<div id="absorb-source-list" class="absorb-list"></div>
|
||||
<button class="modal-close">esc to cancel</button>
|
||||
</div>
|
||||
</div>
|
||||
|
||||
<script src="/app.js"></script>
|
||||
</body>
|
||||
</html>
|
||||
|
||||
@@ -483,6 +483,33 @@ main {
|
||||
font-family: var(--font-mono);
|
||||
}
|
||||
|
||||
/* Absorb modal */
|
||||
.absorb-list {
|
||||
max-height: 300px;
|
||||
overflow-y: auto;
|
||||
}
|
||||
|
||||
.absorb-source-item {
|
||||
display: flex;
|
||||
align-items: center;
|
||||
gap: 10px;
|
||||
padding: 8px 12px;
|
||||
cursor: pointer;
|
||||
border-radius: var(--radius);
|
||||
transition: background 0.1s;
|
||||
}
|
||||
|
||||
.absorb-source-item:hover {
|
||||
background: var(--bg-hover);
|
||||
}
|
||||
|
||||
.absorb-source-item .entity-body {
|
||||
font-size: 13px;
|
||||
white-space: nowrap;
|
||||
overflow: hidden;
|
||||
text-overflow: ellipsis;
|
||||
}
|
||||
|
||||
/* Responsive */
|
||||
@media (max-width: 900px) {
|
||||
main { grid-template-columns: 1fr; }
|
||||
|
||||
Reference in New Issue
Block a user