off
# Development
**Draggable is no longer maintained by its original authors.** Maintenance of this repo has been passed on to new collaborators and is no longer worked on by anyone at Shopify.
**We are still looking for more maintainers!** If anyone is interested in answering / triaging issues, reviewing / rejecting / approving PRs, and authoring code for bug fixes / new features — please send an email to `max.hoffmann (at) shopify (dot) com`. You may be asked a few questions before obtaining collaboration permission, but if everything checks out, we will happily add you as a collaborator.
---
Get complete control over drag and drop behaviour with Draggable! Draggable abstracts
native browser events into a comprehensive API to create a custom drag and drop experience.
`Draggable` comes with additional modules: `Sortable`, `Droppable`, `Swappable`. Draggable
itself does not perform any sorting behaviour while dragging, but does the heavy lifting, e.g.
creates mirror, emits events, manages sensor events, makes elements draggable.
The additional modules are built on top of `Draggable` and therefore provide a similar API
interface, for more information read the documentation below.
**Features**
- Works with native drag, mouse, touch and force touch events
- Can extend dragging behaviour by hooking into draggables event life cycle
- Can extend drag detection by adding sensors to draggable
- The library is targeted ES6 first
## Table of Contents
- [Install](#install)
- [Documentation](#documentation)
- [Contributing](#contributing)
- [Roadmap](#roadmap)
- [Copyright](#copyright)
## Install
You can install the library via npm.
```bash
npm install @shopify/draggable --save
```
or via yarn:
```bash
yarn add @shopify/draggable
```
or via CDN
```html
```
## Browser Compatibility
Check the "browserlist" property in [package.json](https://github.com/Shopify/draggable/blob/main/package.json#L88) for more info
|  |  |  |  |  |
| ---------------------------------------------------------------------------------------- | ------------------------------------------------------------------------------------------- | ------------------------------------------------------------------------------------- | ---------------------------------------------------------------------------------------- | ---------------------------------------------------------------------------------- |
| Last 3 versions ✔ | Last 3 versions ✔ | Last 3 versions ✔ | Last 3 versions ✔ | Last 3 versions ✔ |
## Documentation
You can find the documentation for each module within their respective directories.
- [Draggable](src/Draggable)
- [DragEvent](src/Draggable/DragEvent)
- [DraggableEvent](src/Draggable/DraggableEvent)
- [Plugins](src/Draggable/Plugins)
- [Announcement](src/Draggable/Plugins/Announcement)
- [Focusable](src/Draggable/Plugins/Focusable)
- [Mirror](src/Draggable/Plugins/Mirror)
- [MirrorEvent](src/Draggable/Plugins/Mirror/MirrorEvent)
- [Scrollable](src/Draggable/Plugins/Scrollable)
- [Sensors](src/Draggable/Sensors)
- [DragSensor](src/Draggable/Sensors/DragSensor)
- [ForceTouchSensor](src/Draggable/Sensors/ForceTouchSensor)
- [MouseSensor](src/Draggable/Sensors/MouseSensor)
- [Sensor](src/Draggable/Sensors/Sensor)
- [SensorEvent](src/Draggable/Sensors/SensorEvent)
- [TouchSensor](src/Draggable/Sensors/TouchSensor)
- [Droppable](src/Droppable)
- [DroppableEvent](src/Droppable/DroppableEvent)
- [Plugins](src/Plugins)
- [Collidable](src/Plugins/Collidable)
- [ResizeMirror](src/Plugins/ResizeMirror)
- [Snappable](src/Plugins/Snappable)
- [SwapAnimation](src/Plugins/SwapAnimation)
- [SortAnimation](src/Plugins/SortAnimation)
- [Sortable](src/Sortable)
- [SortableEvent](src/Sortable/SortableEvent)
- [Swappable](src/Swappable)
- [SwappableEvent](src/Swappable/SwappableEvent)
### TypeScript
Draggable includes [TypeScript](http://typescriptlang.org) definitions.
[Documentation](doc/typescript.md)
## Running examples
To run the `examples` project locally, simply run the following from the `draggable` root:
```bash
yarn && yarn start
```
This will start a server that hosts the contents of `examples/`. It also watches for file
changes from both `src/` and `examples/src` and reloads the browser.
## Contributing
Contributions are more than welcome, the code base is still new and needs more love.
For more information, please checkout the [contributing document](https://github.com/Shopify/draggable/blob/main/CONTRIBUTING.md).
## Related resources
- [Ember CLI Shim](https://github.com/timrourke/ember-cli-shopify-draggable-shim) on Github by [@timrourke](https://github.com/timrourke)
- [Ember CLI Shim](https://www.npmjs.com/package/ember-cli-shopify-draggable-shim) on NPM by [@timrourke](https://github.com/timrourke)
## Copyright
Copyright (c) 2018-present Shopify. See LICENSE.md for further details.
================================================
FILE: babel.config.js
================================================
module.exports = function (api) {
api.cache(true);
return {
presets: [
[
'@babel/preset-env',
{useBuiltIns: 'entry', corejs: '3.0', bugfixes: true},
],
['@babel/preset-typescript'],
],
plugins: [['@babel/plugin-proposal-decorators', {version: '2023-05'}]],
assumptions: {
setPublicClassFields: true,
privateFieldsAsProperties: true,
// nothing accesses `document.all`:
noDocumentAll: true,
// nothing relies on class constructors invoked without `new` throwing:
noClassCalls: true,
// nothing should be relying on tagged template strings being frozen:
mutableTemplateObject: true,
// nothing is relying on Function.prototype.length:
ignoreFunctionLength: true,
// nothing is relying on mutable re-exported bindings:
constantReexports: true,
// don't bother marking Module records non-enumerable:
enumerableModuleMeta: true,
// nothing uses [[Symbol.toPrimitive]]:
// (see https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Global_Objects/Symbol/toPrimitive)
ignoreToPrimitiveHint: true,
// nothing relies on spread copying Symbol keys: ({...{ [Symbol()]: 1 }})
objectRestNoSymbols: true,
// nothing relies on `new (() => {})` throwing:
noNewArrows: true,
// transpile object spread to assignment instead of defineProperty():
setSpreadProperties: true,
// nothing should be using custom iterator protocol:
skipForOfIteratorClosing: true,
// nothing inherits from a constructor function with explicit return value:
superIsCallableConstructor: true,
// nothing relies on CJS-transpiled namespace imports having all properties prior to module execution completing:
noIncompleteNsImportDetection: true,
},
};
};
================================================
FILE: config/typescript/rollup-plugin-includepaths.d.ts
================================================
declare module 'rollup-plugin-includepaths' {
interface Options {
include: {[key: string]: string};
paths: string[];
extensions: string[];
}
export = includePaths;
function includePaths(object: Options);
}
================================================
FILE: doc/typescript.md
================================================
# Default usage
```typescript
import {Sortable} from '@shopify/draggable';
const sortable = new Sortable(document.querySelectorAll('ul'), {
draggable: 'li',
});
// The type of the first argument is SortableEventNames
sortable.on('sortable:sort', (evt) => {
// The type of evt is SortableSortEvent
});
// The type of the first argument is SortableEventNames
sortable.on('drag:out:container', (evt) => {
// The type of evt is DragOutContainerEvent
});
```
# Using plugins
When creating an instance with plugins with events, you need to manually specify the event names.
```typescript
import {Droppable, Plugins} from '@shopify/draggable';
// 1. import the event names you need
import type {
DroppableEventNames,
CollidableEventNames,
} from "@shopify/draggable";
// 2. Specify the event names when create the instance
const droppable = new Droppableoff
3 item capacity