Upgrade to Pro
— share decks privately, control downloads, hide ads and more …
Speaker Deck
Features
Speaker Deck
PRO
Sign in
Sign up for free
Search
Search
型安全なDrag and Dropの設計を考える
Search
yudppp
May 23, 2025
Programming
1k
5
Share
Embed
Copy iframe code
Copy JS code
Copy link
Start on current slide
型安全なDrag and Dropの設計を考える
TSKaigi 2025のLT資料
yudppp
May 23, 2025
More Decks by yudppp
See All by yudppp
開発者にもコーディングエージェントにも働きやすい環境を整える
yudppp
0
72
未知のプログラミング言語にChatGPTと共に挑む
yudppp
0
520
SaaSフロントエンド開発の現場で求められる技術 / Technologies for SaaS Frontend Development in the Field
yudppp
2
280
2019年 HRBrainの技術的挑戦 / hrbain technology challenge 2019
yudppp
3
1.5k
Web開発を支えるマイグレーションツールについて / sqldef introduction for psql users
yudppp
2
3.6k
ISUCON向けのツールを作った話 / isutools
yudppp
1
340
Row Level Securityはマルチテナントの銀の弾丸になりうるのか / Row Level Security is silver bullet for multitenancy?
yudppp
23
34k
Webサービス開発に必要な統計学入門 / study of statistics for web developers
yudppp
1
360
メジャーな Live Reloaderの違いをちゃんと調べて見た / Compare major live reloader of Go
yudppp
1
2k
Other Decks in Programming
See All in Programming
ローカルLLMを使ってB2Bサービスを作っていての学び
yaotti
0
220
Inside Stream API
skrb
1
820
Strategic Design in the Frontend: Moduliths & Micro Frontends @DDDEurope
manfredsteyer
PRO
0
140
Performance Engineering for Everyone
elenatanasoiu
0
240
代数的データ型って何が嬉しいの? #frontend_phpcon_do
kajitack
8
3.8k
キャリア迷子上等 ─ "ない道"は自分で作ればいい
16bitidol
3
2.6k
作って学ぶ、 JSX (TSX) ランタイムの基本
syumai
7
1.7k
エージェンティックRAGにAWSで入門しよう!
har1101
9
1.8k
jQueryをバージョンアップする前に使いたいjQuery Migrate
matsuo_atsushi
0
620
過去最大のMCPアップデート! 2026-07-28 RC版の謎に迫る
licux
6
430
スマートグラスで並列バイブコーディング
hyshu
0
270
The ROI of Quarkus for Spring Boot Applications
hollycummins
0
150
Featured
See All Featured
Responsive Adventures: Dirty Tricks From The Dark Corners of Front-End
smashingmag
254
22k
The Pragmatic Product Professional
lauravandoore
37
7.3k
Between Models and Reality
mayunak
4
360
Exploring anti-patterns in Rails
aemeredith
3
430
The Organizational Zoo: Understanding Human Behavior Agility Through Metaphoric Constructive Conversations (based on the works of Arthur Shelley, Ph.D)
kimpetersen
PRO
0
380
Making the Leap to Tech Lead
cromwellryan
135
9.9k
How To Stay Up To Date on Web Technology
chriscoyier
790
250k
Taking LLMs out of the black box: A practical guide to human-in-the-loop distillation
inesmontani
PRO
3
2.3k
Scaling GitHub
holman
464
140k
Discover your Explorer Soul
emna__ayadi
2
1.2k
Accessibility Awareness
sabderemane
1
150
Practical Tips for Bootstrapping Information Extraction Pipelines
honnibal
25
2k
Transcript
型安全なDrag and Dropの設計を考える TSKaigi 2025
株式会社HRBrain 執行役員CTO 2018年に HRBrain に 10人目の社員、3人目のエンジニアとして 入社。TypeScriptも2018年からはじめました。 今もバックエンドとフロントエンドのプロダクションのコードを 本当にたくさん書いてます。 yudppp
について HRBrain は「タレントマネジメント」「人事評価」「組織診断サーベイ」「労務管理」など 8種類のプロダクトを提供し ており、人事の様々な業務を効率化し、蓄積されたデータを活用して効果的な人事戦略を実現するためのタレントマネジ メントシステムです。 SaaSは一つのアプリケーションを、複数の会社、複数の運用を担う必要があるため、カスタマイズ性が求められます。カ スタマイズを直感的に扱えるようにするため、Drag and
Dropを利用しています。
利用例 例えば、管理する従業員の情報を設定 する画面で利用しています。 項目とグループといったドラックでき るオブジェクトがあり、どこにおける かはドラックしているオブジェクトの 情報とドラッグされる場所の情報、状 態によって変わっていきます。 このようなシンプルなリストの並び替 え以外のことをすることが多いです。
Drag and Dropの失敗例 V ドラッグした要素の消S V ドラッグした瞬間にページが真っ白にな$ V インプット付きのアイテムの場合に、中のテキストが元の場所に居残る
Drag and Dropの失敗例 t ドラッグした要素の消s t ドラッグした瞬間にページが真っ白になC t インプット付きのアイテムの場合に、中のテキストが元の場所に居残る ↓↓e
t ドラッグしている要素と、置く要素の関係の定義が漏れていることが多い
ドラッグできるオブジェクト 項目 グループ
ドラッグできるオブジェクト 項目 グループ
ドロップできる場所 項目 グループ
ドロップできる場所 項目 グループ
これを型に落とし込んでいく
型の定義 ① // ドラッグする型の定義 // ドロップする場所の定義 // 全体のレイアウト export interface
extends = : : export interface extends = : : export interface < , > { ; ; } < , > { ; ; } {} DraggableItem T P T P DropAreaItem T P T P LayoutData string unknown string unknown type payload type payload
型の定義 ② // ItemとTargetの組み合わせで置けるのか、置いたときどうなるのか // 「移動元→移動先」という文字列にする // 「移動元→移動先」のすべての組み合わせごとに必ずルールを定義するようにする export interface
extends extends : : : : => : : : : => | type extends extends = export type extends extends = in : extends infer extends infer extends ? : < < , >, < , >, > { ( , , ) ; ( , , ) ; } { : ; } < < , >, < , >, > ; < < , >, < , >, > { [ < , >] < < , < , >>, < , < , >>, > ; }; Rule Item DraggableItem Target DropAreaItem LayoutData canDrop Item Target LayoutData onDrop Item Target LayoutData LayoutData canDrop RuleKey Item DraggableItem Target DropAreaItem Item Target RuleSet Item DraggableItem Target DropAreaItem LayoutData K RuleKey Item Target K IT Item TT Target Rule Extract Item DraggableItem IT Extract Target DropAreaItem TT LayoutData any any any any boolean false any any any any any any any any any any never item target layoutData item target layoutData `${ ["type"]}→${ ["type"]}` `${ ["type"]}->${ ["type"]}`
型の定義 ③ export class extends extends : : : :
=> : : : => constructor : : = = : : => const = return as as = : : => if ! return const = as as < < , >, < , >, > { ; ( , ) ; ( , ) ; ( , < , , >) { .data initialData; . ( , ) { ruleSet[ (item, target)]; rule. (item , target , .data); }; . ( , ) { ( . (item, target)) .data ruleSet[ (item, target)]; this.data = rule. (item , target , .data); }; } } Layout Item DraggableItem Target DropAreaItem LayoutData LayoutData canDrop Item Target onDrop Item Target LayoutData RuleSet Item Target LayoutData canDrop Item Target getRuleKey canDrop onDrop Item Target canDrop getRuleKey onDrop any any any any boolean void this this rule any any this this this this rule any any this data item target item target initialData ruleSet item target item target ※発表用に簡略化しています(本当はcanDrop === falseの対応とか必要)
使い方 ① // 全体のデータをどう持つか { [] } // ドラッグできるものの定義 <
, >; < , >; ; < , >; // 行と行の隙間で新しい行作るときのやつ < , { groupId: string, index: number }>; ; type = : type = type = type = | type = type = type = | LayoutData Group DraggableFieldItem DraggableItem Field DraggableGroupItem DraggableItem Group AnyDraggableItem DraggableFieldItem DraggableGroupItem RowDropArea DropAreaItem Row InsertRowDropArea DropAreaItem AnyDropAreaItem RowDropArea InsertRowDropArea groups "field" "group" "row" "insertRow" // ドロップできる場所の定義
使い方 ② // 何がどこに置けて、置けたらどうなるのか < , , > { :
{ : ( , , ) target.fields. , : ( , , ) xxxx, }, : { : ( , , ) , : ( , , ) xxxx, }, : { : }, : { : ( , , ) , : ( , , ) xxxx, }, }; const : = => < => => => => => layoutRules length 6 true false true RuleSet AnyDraggableItem AnyDropAreaItem LayoutData canDrop onDrop canDrop onDrop canDrop canDrop onDrop 'field->row' 'field→insertRow 'group->row' 'group->insertRow' item target layout item target layout item target layout item target layout item target layout item target layout // 対象行の項目数が6未満だったら追加可能 // 頑張りどころでitemがtargetに移動したときにどうlayoutが変更されるか // 常に追加可能 // 常に不可 // 常に追加可能
使い方 ③ export class extends constructor : --- const =
new --- --- < , , > { ( ) { (data, layoutRules); } } (data) layout. (item, area) layout. (item, area) Layout LayoutState AnyDraggableItem AnyDropAreaItem LayoutData LayoutData Layout canDrop onDrop data super layout
結局我々がやるべきこと ドラッグ可能なアイテムの種類とドロップエリアの種類と、持つべきデータを定R 置けるのか置けないのか、置いたあとにどう変化するかを表すRuleを本気で実装すG 新しいアイテムが追加されたときに、実装漏れがないような作りにするこt Viewの作り込みと分離することで、集中する領域を切り離すこt
今回は話せていないが、あとはView側では当たり判定の範囲を綿密に計画する