Svelte makes Drag And Drop API easy!

  Рет қаралды 19,140

Antonio Sarcevic

Antonio Sarcevic

Күн бұрын

This video shows how to create a minimal draggable and dropzone Svelte Action using the browser native Drag and Drop API. It only takes about 80 lines of code for the Svelte Actions.
Svelte Actions are functions that make a node and hook into their lifecycle, making it easy to compose DOM work in components.
Boilerplate Kanban Board without Drag and Drop for coding along: www.sveltelab.dev/rl7w8rx3eyd...
Finished Board with Drag and Drop: www.sveltelab.dev/xzz3zkyjzwe...
00:00 Intro
00:34 Data, HTML and CSS
01:33 Svelte Actions
01:53 use:draggable Action
05:20 use:dropzone Action
12:18 Recap
13:32 Example Use Cases
14:12 Note on Accessibility
14:35 No Library Needed
15:03 Outro

Пікірлер: 31
@JoyofCodeDev
@JoyofCodeDev Жыл бұрын
🔥
@RDR-jn1sn
@RDR-jn1sn 9 ай бұрын
Finally a tutorial that doesn't use svelte-dnd-action... thanks a lot!!!
@Huntabyte
@Huntabyte Жыл бұрын
What VSCode theme are you using? Joking aside, great video!
@codygriffith1693
@codygriffith1693 Жыл бұрын
Hype
@Huntabyte
@Huntabyte Жыл бұрын
@@codygriffith1693 🥳
@techn1cs
@techn1cs Жыл бұрын
😁 💾
@SvelteSociety
@SvelteSociety Жыл бұрын
Nice!
@nickstaresinic9933
@nickstaresinic9933 Жыл бұрын
Very impressive, Antonio -- well organized and presented, and it expands my understanding of how/when to use actions. Thanks.
@FabianVilersBe
@FabianVilersBe 8 ай бұрын
Nice tutorial, thank you. May I add that I'd rather use the API function "dispatchEvent" on the node object to emit a "drop" custom event with the required data. node.dispatchEvent(new CustomEvent('custom_drop', { detail: data })); Then, the usage would be more idiomatic by writing (...) My two cents ;-)
@daleyc.3008
@daleyc.3008 3 ай бұрын
I tried this on Svelte 5 with runes, smooth like butter. Nice video!
@blokche_dev
@blokche_dev Жыл бұрын
svelte actions are so powerful. Thanks for sharing.
@Martin-kt8sz
@Martin-kt8sz Жыл бұрын
Excellent video, great work !
@ScriptRaccoon
@ScriptRaccoon Жыл бұрын
Very well explained!
@justingolden87
@justingolden87 Жыл бұрын
Very informative! I thought of something else for DND, not "drag and drop" lol
@roblesrt
@roblesrt Жыл бұрын
Amazing! Thanks for sharing!
@hallowatcher
@hallowatcher Жыл бұрын
Cool, thanks!
@Hurby24
@Hurby24 Жыл бұрын
great video
@FrostFlag
@FrostFlag 4 ай бұрын
lifesaver, this is so useful!
@Kikibeh
@Kikibeh Жыл бұрын
Great video, very helpful! How would you handle the drag and drop on touch devices e.g. smartphones or tablets? May you do a video of that as well?
@naranyala_dev
@naranyala_dev Жыл бұрын
more about svelte 😍
@SarcevicAntonio
@SarcevicAntonio Жыл бұрын
On it 😁👍
@zipcod7726
@zipcod7726 Жыл бұрын
Cool! I subscribe
@cv3787
@cv3787 8 ай бұрын
Does this work with re-ordering between the items in the same column?
@IStMl
@IStMl Жыл бұрын
Wow
@NabekenProG87
@NabekenProG87 3 күн бұрын
Very cool, unfortunaltely the DnD API does not work on mobile :c. I don't want to use another library, I just want to be happy
@alpaslaneldemir6904
@alpaslaneldemir6904 10 ай бұрын
Just incase someone implementing this on Tauri + Svelte set the "fileDropEnabled":false .
@GrzegorzPalian
@GrzegorzPalian 4 ай бұрын
Does your "update" function actually work? Unless there is some svelte magic going on, the functions created with the initial value of `state` (like handle_dragstart) would create a closure and never get the updated value when you reassign the variable like this. Am I missing something here?
@sledgex9
@sledgex9 Жыл бұрын
Can someone explain to me 5:10? I am coming from C++ and I am a JS noob. It seems to me that changing the "state" variable after the draggable() function has returned (via update()) it will also affect the data seen inside handle_dragstart() after it is called as an event listener at a later time. Is that correct? So the "state" variable not only outlives the draggable() function but it also has effects on the nested functions? Does this behavior/pattern have a name in JS so I can read up on it?
@trzcin5724
@trzcin5724 Жыл бұрын
I think this is called a closure.
@sledgex9
@sledgex9 Жыл бұрын
@@trzcin5724 Thank you. I had just read up on Closures on MDN. I'll give a more detailed comment below this one.
@sledgex9
@sledgex9 Жыл бұрын
For any other noob wondering: You must read on what "closures" are in Javascript and how they behave in that context. MDN has a very good article on them. In short and very simple words(mostly in C++ speak): Closures( lambdas in C++) capture the variables in their surroundings by reference AND extend their lifetime. Hence, a variable captured in one closure can be updated in another closure that has captured the same variable even if that variable was local to the surrounding scope.
Crafting Magical Spells Using Svelte's Powerful Reactivity
13:53
Joy of Code
Рет қаралды 11 М.
How To Build Sortable Drag & Drop With Vanilla Javascript
22:22
Web Dev Simplified
Рет қаралды 325 М.
Super gymnastics 😍🫣
00:15
Lexa_Merin
Рет қаралды 108 МЛН
⬅️🤔➡️
00:31
Celine Dept
Рет қаралды 50 МЛН
She ruined my dominos! 😭 Cool train tool helps me #gadget
00:40
Go Gizmo!
Рет қаралды 60 МЛН
I built a $5 chat app with Pocketbase & Svelte. Will it scale?
13:34
Svelte 5 is a beast, but is it worth switching?
37:55
Syntax
Рет қаралды 20 М.
How to POST & SAVE Files using SvelteKit in 5 minutes
5:26
Daniel Gorra
Рет қаралды 1 М.
Svelte 5 Surprised Me
6:06
Theo - t3․gg
Рет қаралды 64 М.
This React Drag and Drop Component Is Magic
9:56
developedbyed
Рет қаралды 78 М.
Drag & Drop with Javascript in 4 minutes
3:58
Appwrite
Рет қаралды 20 М.
SvelteKit is my mistress
4:19
Fireship
Рет қаралды 413 М.
Pagination with SvelteKit
9:33
Huntabyte
Рет қаралды 18 М.
React Drag and Drop List Sort Tutorial
9:54
Darwin Tech
Рет қаралды 15 М.
Svelte Actions Make Svelte The Best JavaScript Framework
46:33
Joy of Code
Рет қаралды 29 М.
#miniphone
0:16
Miniphone
Рет қаралды 3,6 МЛН
Samsung S24 Ultra professional shooting kit #shorts
0:12
Photographer Army
Рет қаралды 33 МЛН
Телефон в воде 🤯
0:28
FATA MORGANA
Рет қаралды 1,2 МЛН
cute mini iphone
0:34
승비니 Seungbini
Рет қаралды 5 МЛН
Что не так с LG? #lg
0:54
Не шарю!
Рет қаралды 65 М.