whisper.cat/weboasis/todo/scripts/TodoList.min.js
2023-10-05 23:28:32 +11:00

1 line
885 B
JavaScript

window.VT=window.VT||{},VT.TodoList=function(a){var b={items:[]};a.innerHTML="<div class=\"items\"></div>\n<div class=\"todo-item-input\"></div>",VT.AppSortable(a.querySelector(".items"),{}),VT.TodoItemInput(a.querySelector(".todo-item-input")),a.addEventListener("sortableDrop",function(b){a.dispatchEvent(new CustomEvent("moveItem",{detail:{item:b.detail.data.item,index:b.detail.index},bubbles:!0}))}),a.todoList={update:function(c){Object.assign(b,c);var d=a.querySelector(".items"),e=new Set(d.children),f=new Map;e.forEach(function(a){f.set(a.dataset.key,a)});var g=b.items.map(function(a){var b=f.get(a.id);return b?e.delete(b):(b=document.createElement("div"),b.classList.add("todo-item"),b.dataset.key=a.id,VT.TodoItem(b)),b.todoItem.update({item:a}),b});e.forEach(function(a){d.removeChild(a)}),g.forEach(function(a,b){a!==d.children[b]&&d.insertBefore(a,d.children[b])})}}};