ZDDC/classifier/js/dnd.js
ZDDC 47cf58b0e9 feat(classifier): drag-and-drop assignment (phase 3)
In Classify & Copy mode the left tree now lists each folder's files as
draggable rows (with a classification state dot), and folder rows are
draggable for a group-drag of the whole subtree. Target-tree nodes are drop
zones: a tracking folder (any node) or a transmittal bin; dropping assigns the
dragged source key(s) along that axis via classify.place().

- dnd.js: drag-payload bus (keys held in a module var since dataTransfer can't
  be read during dragover; carries a marker for the copy cursor).
- tree.js: createFileElement + group-drag dragstart; classify-mode file rows.
- target-tree.js: setupDropZone with dragover highlight + drop assignment
  (tracking = any node, transmittal = bins only).
- app.js: source tree re-renders on classify state change.
- 2 DnD drop-handler tests (14 total green).

Co-Authored-By: Claude Opus 4.8 (1M context) <noreply@anthropic.com>
2026-06-09 12:23:38 -05:00

28 lines
985 B
JavaScript

/**
* ZDDC Classifier — drag payload bus for Classify & Copy.
*
* HTML5 dataTransfer can't be read during `dragover` (only on `drop`), and we
* need the dragged set to drive drop-target highlighting. So the source keys
* live in a module variable for the lifetime of a drag; dataTransfer carries a
* marker so the browser shows a copy cursor and external drops are ignored.
*/
(function () {
'use strict';
var keys = [];
function setDrag(srcKeys, e) {
keys = (srcKeys || []).slice();
if (e && e.dataTransfer) {
e.dataTransfer.effectAllowed = 'copy';
try { e.dataTransfer.setData('application/x-zddc-keys', keys.join('\n')); } catch (_) { /* ok */ }
}
}
function getDrag() { return keys; }
function active() { return keys.length > 0; }
function clearDrag() { keys = []; }
window.app.modules.dnd = {
setDrag: setDrag, getDrag: getDrag, active: active, clearDrag: clearDrag,
};
})();