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
Sponsored
·
SiteGround - Reliable hosting with speed, security, and support you can count on.
→
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
90
未知のプログラミング言語にChatGPTと共に挑む
yudppp
0
530
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.7k
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
音楽のための関数型プログラミング言語mimiumにおける多段階計算の活用
tomoyanonymous
1
330
The Past, Present, and Future of Enterprise Java
ivargrimstad
0
230
技術記事、 専門家としてのプログラマ、 言語化
mizchi
14
7.5k
5分で問診!Composer セキュリティ健康診断
codmoninc
0
250
Performance Engineering for Everyone
elenatanasoiu
0
270
AI 輔助遺留系統現代化的經驗分享
jame2408
1
1.2k
The Bowling Game- From Imperative to Functional Programming - Part 1
philipschwarz
PRO
0
330
Laravelで学ぶ Webアプリケーションチューニング入門/web_application_tuning_101
hanhan1978
4
540
【やさしく解説 設計編・中級 #1】一つの車に、運転手は一人 ~ある倉庫システムの事例から~
panda728
PRO
0
180
Claude Opus 4.6以後の受託開発エンジニアの変化(Claude Code開発ノウハウ大公開スペシャルbyクラスメソッド)
iidatakuma
1
760
【やさしく解説 設計編 #0】DDDのコード、読めるのに分からない人へ
panda728
PRO
2
270
ソフトウェア設計に溶けるインフラ ― AWS CDK のインフラ認識論
konokenj
2
500
Featured
See All Featured
A brief & incomplete history of UX Design for the World Wide Web: 1989–2019
jct
2
420
Design of three-dimensional binary manipulators for pick-and-place task avoiding obstacles (IECON2024)
konakalab
0
490
The MySQL Ecosystem @ GitHub 2015
samlambert
251
13k
Writing Fast Ruby
sferik
630
63k
How to Grow Your eCommerce with AI & Automation
katarinadahlin
PRO
1
230
How to optimise 3,500 product descriptions for ecommerce in one day using ChatGPT
katarinadahlin
PRO
1
3.7k
Visual Storytelling: How to be a Superhuman Communicator
reverentgeek
2
590
Leadership Guide Workshop - DevTernity 2021
reverentgeek
1
320
Leading Effective Engineering Teams in the AI Era
addyosmani
9
2.1k
Why Your Marketing Sucks and What You Can Do About It - Sophie Logan
marketingsoph
0
270
Leveraging Curiosity to Care for An Aging Population
cassininazir
1
390
Designing Powerful Visuals for Engaging Learning
tmiket
1
450
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側では当たり判定の範囲を綿密に計画する