1
0

Delete article

Deleted articles cannot be recovered.

Draft of this article would be also deleted.

Are you sure you want to delete this article?

HTML5 ドラッグ & ドロップ + イミュータブル状態でローカル Kanban を作った

1
Posted at

作ったもの

Kanban Localhttps://sen.ltd/portfolio/kanban-local/

スクリーンショット

  • 複数ボードに複数カラム、カード
  • HTML5 ドラッグ & ドロップ(カラム間移動、カラム内並び替え、カラム並び替え)
  • localStorage 永続化
  • JSON インポート / エクスポート
  • カード検索
  • カラーラベル

vanilla JS、ゼロ依存、ビルド不要node --test で 46 ケース。

イミュータブルなボード状態

12 個の変更関数すべてが新しいオブジェクトを返すboard → columns → cards のツリー全体を純関数的に再構築。

同一カラム内移動のオフバイワン

カードを削除してから挿入する場合、移動元より後ろに移動するときは toIndex -= 1 が必要:

if (fromColId === toColId && toIndex > fromIndex) toIndex -= 1;

これを忘れると「0 → 2」のつもりが「0 → 1」になる。

HTML5 ドラッグイベントの罠

  • dragover では preventDefault() 必須。これを忘れると drop が発火しない
  • dragleave はカラムの子要素を跨ぐたびに発火する。ドロップ対象のハイライト制御には e.relatedTarget や enter/leave カウンタが必要
  • dragend はキャンセル時も発火するのでクリーンアップはここで

シリーズ

100+ 公開ポートフォリオ シリーズの #57 です。

1
0
0

Register as a new user and use Qiita more conveniently

  1. You get articles that match your needs
  2. You can efficiently read back useful information
  3. You can use dark theme
What you can do with signing up
1
0

Delete article

Deleted articles cannot be recovered.

Draft of this article would be also deleted.

Are you sure you want to delete this article?