A Svelte example that enables D'n'D API to work with Touch Event
Please see demos in the follwing table.
Touchable | Demo | Source |
---|---|---|
no | demo | App.svelte |
yes | demo | TouchableApp.svelte |
import Draggable from './Draggable.svelte';
let drag;
let drop_nodes = [];
dragstart
and drop
functions to be writable- function dragstart(e, target, i) {
+ let dragstart = function(e, target, i) {
- function drop(e, target) {
+ let drop = function(e, target) {
<Draggable bind:this={drag} bind:drop_nodes bind:dragstart bind:drop />
on:touchstart={e => drag.touchstart(e, e.target, card_i)}
on:touchmove={e => drag.touchmove(e, e.target, card_i)}
on:touchend={e => drag.touchend(e, e.target, card_i)}
Change arguments in your case
drop_nodes
bind:this={drop_nodes[0]}
bind:this={drop_nodes[1]}
$ diff src/App.svelte src/TouchableApp.svelte
6a7,8
> import Draggable from './Draggable.svelte';
>
11a14,17
> // Touchable
> let drag;
> let drop_nodes = [];
>
16c22
< function dragstart(e, target, i) {
---
> let dragstart = function(e, target, i) {
27c33
< function drop(e, target) {
---
> let drop = function(e, target) {
109a116,118
> on:touchstart={e => drag.touchstart(e, e.target, card_i)}
> on:touchmove={e => drag.touchmove(e, e.target, card_i)}
> on:touchend={e => drag.touchend(e, e.target, card_i)}
116a126
> bind:this={drop_nodes[0]}
123a134
> bind:this={drop_nodes[1]}
131a143,144
>
> <Draggable bind:this={drag} bind:drop_nodes bind:dragstart bind:drop />
Copyright 2020 Sosuke Kato
Licensed under the Apache License, Version 2.0 (the "License"); you may not use this file except in compliance with the License. You may obtain a copy of the License at
http://www.apache.org/licenses/LICENSE-2.0
Unless required by applicable law or agreed to in writing, software distributed under the License is distributed on an "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. See the License for the specific language governing permissions and limitations under the License.