Files
odysseus/static/js/features/notes/ui/cardChecklist.js
T
Alexandre TeixeiraandLéo f1a47f3812 refactor(notes): decompose Notes into feature-owned modules (#6713)
* refactor(notes): decompose Notes into feature-owned modules

* fix(notes): avoid HTML interpolation in reminder picker

* docs(notes): drop checkpoint archives, session logs and publication drafts

The N0-N6 tarballs and raw pytest/node logs are not read by any script or
test, and the logs carry absolute home-directory paths. Once squashed into
dev they would stay in history for good. notes-pr.md and notes-issue.md
were the drafts used to open #6712 and #6713, not documentation.

notes-validation.md keeps the counts, the checkpoint hashes and
implementation.sha256 as the record; local interpreter paths and the local
Docker image name are replaced with portable placeholders.

* fix(notes): keep the state store raw and stop masonry re-observing after close

- state: writes built from views (filter, spread, splice) stored nested
  read-only views in the store, so structuredClone on a stored note threw
  DataCloneError. Store writes now unwrap nested views.
- layout: a save that resolves after closePanel re-renders the leaving pane
  and re-created the masonry ResizeObserver that teardown had disposed.
  Skip creating it once Notes is closed.
- index.js: drop 30 imported or declared names that were never used and
  group the imports at the top. Import order is unchanged.
- Revert unrelated punctuation edits in .gitattributes and keep the header
  comment and docstring first in compare/vote.js and
  test_notes_dom_xss_helpers.py.

Both fixes have a node test that fails on the previous head.

* test(notes): make script rejection assertion case-insensitive

Address CodeQL js/bad-tag-filter alert #1150 in test-only assertion and refresh Notes evidence manifest checksum.

---------

Co-authored-by: Léo <leograndcontact@gmail.com>
2026-10-15 09:29:41 +01:00

149 lines
5.1 KiB
JavaScript

/** Card checklist editing and Today-step interactions. */
export function createCardChecklist({
checklistOperations,
_editNote,
_renderNotes,
app,
spawnConfetti,
state
}) {
function _wireCardChecklist(body) {
// Remove a single checklist item (hover X)
body.querySelectorAll('.note-checkbox-rm').forEach(btn => {
btn.addEventListener('click', (e) => {
e.stopPropagation();
if (state.selectMode) return;
const noteId = btn.dataset.noteId;
const idx = parseInt(btn.dataset.idx);
checklistOperations.removeItem(noteId, idx);
});
});
function _startChecklistItemEdit(noteId, idx, span) {
if (span.isContentEditable) return;
const note = state.notes.find(n => n.id === noteId);
if (!note || !Array.isArray(note.items) || !note.items[idx]) return;
span.textContent = note.items[idx].text || '';
span.contentEditable = "true";
span.spellcheck = false;
span.focus();
const selection = window.getSelection();
const range = document.createRange();
range.selectNodeContents(span);
selection.removeAllRanges();
selection.addRange(range);
const save = () => {
if (!span.isContentEditable) return;
span.contentEditable = "false";
const newText = span.textContent.trim();
checklistOperations.editItem(note, idx, newText);
};
const onKeydown = (e) => {
if (e.key === 'Enter') {
e.preventDefault();
save();
} else if (e.key === 'Escape') {
e.preventDefault();
span.contentEditable = "false";
_renderNotes();
}
};
span.addEventListener('blur', save, { once: true });
span.addEventListener('keydown', onKeydown);
}
// Edit a single checklist item (hover Edit button)
body.querySelectorAll('.note-checkbox-edit').forEach(btn => {
btn.addEventListener('click', (e) => {
e.stopPropagation();
if (state.selectMode) return;
const noteId = btn.dataset.noteId;
const idx = parseInt(btn.dataset.idx);
const span = btn.parentElement.querySelector('.note-check-text');
if (span) _startChecklistItemEdit(noteId, idx, span);
});
});
// Prevent clicks from toggling the row while actively editing inline
body.querySelectorAll('.note-check-text').forEach(span => {
span.addEventListener('click', (e) => {
if (span.isContentEditable) {
e.stopPropagation();
}
});
});
// Quick-add new checklist item (hover input at bottom of todo cards)
body.querySelectorAll('.note-cl-quickadd-input').forEach(input => {
input.addEventListener('click', (e) => e.stopPropagation());
input.addEventListener('keydown', async (e) => {
e.stopPropagation();
if (e.key !== 'Enter') return;
e.preventDefault();
const text = input.value.trim();
if (!text) return;
const noteId = input.dataset.noteId;
const persist = checklistOperations.addItem(noteId, text, () => { input.value = ''; });
if (!persist) return;
// Refocus the input on the same card
setTimeout(() => {
const next = document.querySelector(`.note-cl-quickadd-input[data-note-id="${noteId}"]`);
if (next) next.focus();
}, 0);
persist();
});
});
// Checkboxes (dot toggle, optimistic) : disabled in select mode
body.querySelectorAll('.note-checkbox').forEach(el => {
el.addEventListener('click', (e) => {
if (state.selectMode) return; // let card-level handler take over
e.preventDefault();
e.stopPropagation();
const noteId = el.dataset.noteId;
const idx = parseInt(el.dataset.idx);
checklistOperations.toggleItem(noteId, idx, done => el.classList.toggle('done', done), () => {
const card = el.closest('.note-card');
if (card) { const r = card.getBoundingClientRect(); spawnConfetti(r.left + r.width / 2, r.top + r.height / 2, 60); }
});
});
});
}
function _wireTodayView(body) {
body.querySelectorAll('.notes-today-row .note-check-dot').forEach(dot => {
dot.addEventListener('click', async (e) => {
e.stopPropagation();
const id = dot.dataset.noteId;
const idx = parseInt(dot.dataset.idx);
const row = dot.closest('.notes-today-row');
await checklistOperations.toggleTodayStep(id, idx, () => row?.classList.add('done'), () => {
const r = (row || dot).getBoundingClientRect();
spawnConfetti(r.left + r.width / 2, r.top + r.height / 2, 60);
});
});
});
body.querySelectorAll('.notes-today-title').forEach(el => {
el.addEventListener('click', () => {
const id = el.dataset.noteId;
if (!id) return;
// Drop the Today filter first so the regular card list is rendered;
// _editNote needs to find a .note-card in the DOM to replace with
// the editor form.
app.setActiveFilter(null);
_renderNotes();
_editNote(id);
});
});
}
return { _wireCardChecklist, _wireTodayView };
}