A RetroSearch Logo

Home - News ( United States | United Kingdom | Italy | Germany ) - Football scores

Search Query:

Showing content from https://github.com/marcojakob/dart-dnd below:

marcojakob/dart-dnd: Drag and Drop for Dart web apps with mouse and touch support.

Drag and Drop for Dart web apps with mouse and touch support.

GitHub | Pub | Demos and Examples

Before you read the instructions below, you should take a look at the examples.

Create a Draggable and give it some HTML elements; this will make them draggable. You can either pass a single Element to the constructor or an ElementList that is returned by querySelectorAll.

If you also want to drop somewhere, you'll need a Dropzone.

// Install draggable (no avatar).
Draggable draggable = Draggable(querySelectorAll('.draggable'));

// Install dropzone.
Dropzone dropzone = Dropzone(querySelector('.dropzone'));

You'll most likely want some drag avatar to show the user that a drag is going on. There are two predefined AvatarHandlers that you can use as follows. But you could also provide your own implementation of AvatarHandler.

// Draggable with clone as avatar.
Draggable draggable = Draggable(querySelectorAll('.draggable'),
    avatarHandler: AvatarHandler.clone());


// Draggable with original element as avatar.
Draggable draggable = Draggable(querySelectorAll('.draggable'),
    avatarHandler: AvatarHandler.original());

The following options can be passed as named parameters to the constructor of Draggable:

Available event Streams on Draggable:

The following options can be passed as named parameters to the constructor of Dropzone:

Available event Streams on Dropzone:

Note: Dropzone events are only fired when the Draggable is accepted by the Acceptor.

Web Components create a nice ecapsulation through Shadow DOM. But this creates a problem with dropzones inside the Shadow DOM as they never receive events because all events are captured by the host element. To make this work we need to retarget events to the Shadow DOM children through recursive elementFromPoint() calls.

For performance reasons it wouldn't make sense to retarget all drag and drop events. If you wish to retarget events to the Shadow DOM children, you must add a dnd-retarget attribute to the host:

// Retarget drag and drop events to Shadow DOM children.
<my-element dnd-retarget></my-element>

The Dart Drag and Drop library is inspired by

Thank you for your work!

Running / Building / Testing

The MIT License (MIT)


RetroSearch is an open source project built by @garambo | Open a GitHub Issue

Search and Browse the WWW like it's 1997 | Search results from DuckDuckGo

HTML: 3.2 | Encoding: UTF-8 | Version: 0.7.4