{"id":13808429,"url":"https://github.com/reppners/ngx-drag-drop","last_synced_at":"2025-05-15T23:05:07.511Z","repository":{"id":39648801,"uuid":"94193673","full_name":"reppners/ngx-drag-drop","owner":"reppners","description":"Angular directives using the native HTML Drag And Drop API","archived":false,"fork":false,"pushed_at":"2025-01-09T10:39:26.000Z","size":8010,"stargazers_count":320,"open_issues_count":47,"forks_count":123,"subscribers_count":9,"default_branch":"master","last_synced_at":"2025-05-12T04:51:11.441Z","etag":null,"topics":[],"latest_commit_sha":null,"homepage":"https://reppners.github.io/ngx-drag-drop/","language":"TypeScript","has_issues":true,"has_wiki":null,"has_pages":null,"mirror_url":null,"source_name":null,"license":"bsd-3-clause","status":null,"scm":"git","pull_requests_enabled":true,"icon_url":"https://github.com/reppners.png","metadata":{"files":{"readme":"README.md","changelog":"CHANGELOG.md","contributing":null,"funding":null,"license":"LICENSE","code_of_conduct":null,"threat_model":null,"audit":null,"citation":null,"codeowners":null,"security":null,"support":null,"governance":null,"roadmap":null,"authors":null,"dei":null,"publiccode":null,"codemeta":null}},"created_at":"2017-06-13T09:11:40.000Z","updated_at":"2025-03-14T14:11:01.000Z","dependencies_parsed_at":"2023-11-23T22:24:17.404Z","dependency_job_id":"c7c3e26b-b192-439a-a26f-1c51713e915c","html_url":"https://github.com/reppners/ngx-drag-drop","commit_stats":{"total_commits":179,"total_committers":15,"mean_commits":"11.933333333333334","dds":"0.33519553072625696","last_synced_commit":"17868373b7ef93a2392346ca86aa82e4b84dd2c0"},"previous_names":[],"tags_count":37,"template":false,"template_full_name":null,"repository_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/reppners%2Fngx-drag-drop","tags_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/reppners%2Fngx-drag-drop/tags","releases_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/reppners%2Fngx-drag-drop/releases","manifests_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/reppners%2Fngx-drag-drop/manifests","owner_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/owners/reppners","download_url":"https://codeload.github.com/reppners/ngx-drag-drop/tar.gz/refs/heads/master","host":{"name":"GitHub","url":"https://github.com","kind":"github","repositories_count":254436944,"owners_count":22070946,"icon_url":"https://github.com/github.png","version":null,"created_at":"2022-05-30T11:31:42.601Z","updated_at":"2022-07-04T15:15:14.044Z","host_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub","repositories_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories","repository_names_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repository_names","owners_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/owners"}},"keywords":[],"created_at":"2024-08-04T01:01:42.617Z","updated_at":"2025-05-15T23:05:07.403Z","avatar_url":"https://github.com/reppners.png","language":"TypeScript","funding_links":[],"categories":["Third Party Components"],"sub_categories":["Drag and Drop"],"readme":"[![npm](https://img.shields.io/npm/v/ngx-drag-drop.svg)](https://www.npmjs.com/package/ngx-drag-drop)\n[![npm (next)](https://img.shields.io/npm/v/ngx-drag-drop/next.svg)](https://www.npmjs.com/package/ngx-drag-drop)\n[![NpmLicense](https://img.shields.io/npm/l/ngx-drag-drop.svg)](https://www.npmjs.com/package/ngx-drag-drop)\n[![GitHub issues](https://img.shields.io/github/issues/reppners/ngx-drag-drop.svg)](https://github.com/reppners/ngx-drag-drop/issues)\n[![Twitter](https://img.shields.io/twitter/url/https/github.com/reppners/ngx-drag-drop.svg?style=social)](https://twitter.com/intent/tweet?text=Angular%20drag%20and%20drop%20with%20ease:\u0026url=https://github.com/reppners/ngx-drag-drop)\n\n# NgxDragDrop\n\n[_Demo_](https://reppners.github.io/ngx-drag-drop/) / [_StackBlitz Issue Template_](https://stackblitz.com/edit/ngx-drag-drop-issue-template)\n\n```sh\nnpm install ngx-drag-drop --save\n```\n\n**Angular directives for declarative drag and drop using the HTML5 Drag-And-Drop API**\n\n- sortable lists by using placeholder element (vertical and horizontal)\n- nestable\n- dropzones optionally support external/native draggables (img, txt, file)\n- conditional drag/drop\n- typed drag/drop\n- utilize [EffectAllowed](https://developer.mozilla.org/en-US/docs/Web/API/DataTransfer/effectAllowed)\n- custom CSS classes\n- touch support by using a [polyfill](#touch-support)\n- [AOT](https://angular.io/guide/aot-compiler) compatible\n\nPort of [angular-drag-drop-lists](https://github.com/marceljuenemann/angular-drag-and-drop-lists) but without the lists :wink:\n\nThis has `dropzones` though :+1:\nThe idea is that the directive does not handle lists internally so the `dndDropzone` can be general purpose.\n\n## Usage\n\n`app.component.html`\n\n```HTML\n\u003c!--a draggable element--\u003e\n\u003cdiv [dndDraggable]=\"draggable.data\"\n     [dndEffectAllowed]=\"draggable.effectAllowed\"\n     [dndDisableIf]=\"draggable.disable\"\n     (dndStart)=\"onDragStart($event)\"\n     (dndCopied)=\"onDraggableCopied($event)\"\n     (dndLinked)=\"onDraggableLinked($event)\"\n     (dndMoved)=\"onDraggableMoved($event)\"\n     (dndCanceled)=\"onDragCanceled($event)\"\n     (dndEnd)=\"onDragEnd($event)\"\u003e\n\n    \u003c!--if [dndHandle] is used inside dndDraggable drag can only start from the handle--\u003e\n    \u003cdiv *ngIf=\"draggable.handle\"\n         dndHandle\u003eHANDLE\n    \u003c/div\u003e\n\n    draggable ({{draggable.effectAllowed}}) \u003cspan [hidden]=\"!draggable.disable\"\u003eDISABLED\u003c/span\u003e\n\n    \u003c!--optionally select a child element as drag image--\u003e\n    \u003cdiv dndDragImageRef\u003eDRAG_IMAGE\u003c/div\u003e\n\n\u003c/div\u003e\n\n\u003c!--a dropzone--\u003e\n\u003c!--to allow dropping content that is not [dndDraggable] set dndAllowExternal to true--\u003e\n\u003csection dndDropzone\n         (dndDragover)=\"onDragover($event)\"\n         (dndDrop)=\"onDrop($event)\"\u003e\n\n    dropzone\n\n    \u003c!--optional placeholder element for dropzone--\u003e\n    \u003c!--will be removed from DOM on init--\u003e\n    \u003cdiv style=\"border: 1px orangered solid; border-radius: 5px; padding: 15px;\"\n         dndPlaceholderRef\u003e\n        placeholder\n    \u003c/div\u003e\n\n\u003c/section\u003e\n```\n\n`app.component`\n\n```JS\nimport { Component } from '@angular/core';\n\nimport { DndDropEvent } from 'ngx-drag-drop';\n\n@Component()\nexport class AppComponent {\n\n  draggable = {\n    // note that data is handled with JSON.stringify/JSON.parse\n    // only set simple data or POJO's as methods will be lost\n    data: \"myDragData\",\n    effectAllowed: \"all\",\n    disable: false,\n    handle: false\n  };\n\n  onDragStart(event:DragEvent) {\n\n    console.log(\"drag started\", JSON.stringify(event, null, 2));\n  }\n\n  onDragEnd(event:DragEvent) {\n\n    console.log(\"drag ended\", JSON.stringify(event, null, 2));\n  }\n\n  onDraggableCopied(event:DragEvent) {\n\n    console.log(\"draggable copied\", JSON.stringify(event, null, 2));\n  }\n\n  onDraggableLinked(event:DragEvent) {\n\n    console.log(\"draggable linked\", JSON.stringify(event, null, 2));\n  }\n\n  onDraggableMoved(event:DragEvent) {\n\n    console.log(\"draggable moved\", JSON.stringify(event, null, 2));\n  }\n\n  onDragCanceled(event:DragEvent) {\n\n    console.log(\"drag cancelled\", JSON.stringify(event, null, 2));\n  }\n\n  onDragover(event:DragEvent) {\n\n    console.log(\"dragover\", JSON.stringify(event, null, 2));\n  }\n\n  onDrop(event:DndDropEvent) {\n\n    console.log(\"dropped\", JSON.stringify(event, null, 2));\n  }\n}\n```\n\n`app.module`\n\n```JS\nimport { BrowserModule } from '@angular/platform-browser';\nimport { NgModule } from '@angular/core';\n\nimport { DndModule } from 'ngx-drag-drop';\n\nimport { AppComponent } from './app.component';\n\n@NgModule({\n  declarations: [\n    AppComponent\n  ],\n  imports: [\n    BrowserModule,\n    DndModule\n  ],\n  providers: [],\n  bootstrap: [AppComponent]\n})\nexport class AppModule {\n}\n```\n\n## API\n\n```TS\n// https://developer.mozilla.org/en-US/docs/Web/API/DataTransfer/dropEffect\nexport type DropEffect = \"move\" | \"copy\" | \"link\" | \"none\";\n\n// https://developer.mozilla.org/en-US/docs/Web/API/DataTransfer/effectAllowed\nexport type EffectAllowed = DropEffect | \"copyMove\" | \"copyLink\" | \"linkMove\" | \"all\";\n```\n\n```TS\nexport type DndDragImageOffsetFunction = ( event:DragEvent, dragImage:Element ) =\u003e { x:number, y:number };\n\n@Directive( {\n  selector: \"[dndDraggable]\"\n} )\nexport declare class DndDraggableDirective {\n\n    // the data attached to the drag\n    dndDraggable: any;\n\n    // the allowed drop effect\n    dndEffectAllowed: EffectAllowed;\n\n    // optionally set the type of dragged data to restrict dropping on compatible dropzones\n    dndType?: string;\n\n    // conditionally disable the draggability\n    dndDisableIf: boolean;\n    dndDisableDragIf: boolean;\n\n    // set a custom class that is applied while dragging\n    dndDraggingClass: string = \"dndDragging\";\n\n    // set a custom class that is applied to only the src element while dragging\n    dndDraggingSourceClass: string = \"dndDraggingSource\";\n\n    // set the class that is applied when draggable is disabled by [dndDisableIf]\n    dndDraggableDisabledClass = \"dndDraggableDisabled\";\n\n    // enables to set a function for calculating custom dragimage offset\n    dndDragImageOffsetFunction:DndDragImageOffsetFunction = calculateDragImageOffset;\n\n    // emits on drag start\n    readonly dndStart: EventEmitter\u003cDragEvent\u003e;\n\n    // emits on drag\n    readonly dndDrag: EventEmitter\u003cDragEvent\u003e;\n\n    // emits on drag end\n    readonly dndEnd: EventEmitter\u003cDragEvent\u003e;\n\n    // emits when the dragged item has been dropped with effect \"move\"\n    readonly dndMoved: EventEmitter\u003cDragEvent\u003e;\n\n    // emits when the dragged item has been dropped with effect \"copy\"\n    readonly dndCopied: EventEmitter\u003cDragEvent\u003e;\n\n    // emits when the dragged item has been dropped with effect \"link\"\n    readonly dndLinked: EventEmitter\u003cDragEvent\u003e;\n\n    // emits when the drag is canceled\n    readonly dndCanceled: EventEmitter\u003cDragEvent\u003e;\n}\n```\n\n```TS\nexport interface DndDropEvent {\n\n    // the original drag event\n    event: DragEvent;\n\n    // the actual drop effect\n    dropEffect: DropEffect;\n\n    // true if the drag did not origin from a [dndDraggable]\n    isExternal:boolean;\n\n    // the data set on the [dndDraggable] that started the drag\n    // for external drags use the event property which contains the original drop event as this will be undefined\n    data?: any;\n\n    // the index where the draggable was dropped in a dropzone\n    // set only when using a placeholder\n    index?: number;\n\n    // if the dndType input on dndDraggable was set\n    // it will be transported here\n    type?: any;\n}\n\n@Directive( {\n  selector: \"[dndDropzone]\"\n} )\nexport declare class DndDropzoneDirective {\n\n    // optionally restrict the allowed types\n    dndDropzone?: string[];\n\n    // set the allowed drop effect\n    dndEffectAllowed: EffectAllowed;\n\n    // conditionally disable the dropzone\n    dndDisableIf: boolean;\n    dndDisableDropIf: boolean;\n\n    // if draggables that are not [dndDraggable] are allowed to be dropped\n    // set to true if dragged text, images or files should be handled\n    dndAllowExternal: boolean;\n\n    // if its a horizontal list this influences how the placeholder position\n    // is calculated\n    dndHorizontal: boolean;\n\n    // set the class applied to the dropzone\n    // when a draggable is dragged over it\n    dndDragoverClass: string = \"dndDragover\";\n\n    // set the class applied to the dropzone\n    // when the dropzone is disabled by [dndDisableIf]\n    dndDropzoneDisabledClass = \"dndDropzoneDisabled\";\n\n    // emits when a draggable is dragged over the dropzone\n    readonly dndDragover: EventEmitter\u003cDragEvent\u003e;\n\n    // emits on successful drop\n    readonly dndDrop: EventEmitter\u003cDndDropEvent\u003e;\n}\n```\n\n## Touch support\n\nInstall the `mobile-drag-drop` module available on npm.\n\nAdd the following lines to your js code\n\n```JS\nimport { polyfill } from 'mobile-drag-drop';\n// optional import of scroll behaviour\nimport { scrollBehaviourDragImageTranslateOverride } from \"mobile-drag-drop/scroll-behaviour\";\n\npolyfill( {\n  // use this to make use of the scroll behaviour\n  dragImageTranslateOverride: scrollBehaviourDragImageTranslateOverride\n} );\n\n// workaround to make scroll prevent work in iOS Safari \u003e= 10\ntry {\n  window.addEventListener( \"touchmove\", function() { }, { passive: false } );\n}\ncatch(e){}\n```\n\nFor more info on the polyfill check it out on GitHub\nhttps://github.com/timruffles/mobile-drag-drop\n\n## Known issues\n\n### Firefox\n\n- Beware that Firefox does not support dragging on `\u003cbutton\u003e` elements.\n  - `\u003cbutton [dndDraggable]\u003e` and `\u003cbutton [dndHandler]\u003e` won't work.\n  - See https://bugzilla.mozilla.org/show_bug.cgi?id=568313\n\n## Why?\n\nHTML Drag-And-Drop API implementations are not behaving the same way across browsers.\n\nThe directives contained in this module enable declarative drag and drop that \"just works\" across browsers in a consistent way.\n\nCredits go to the author and contributors of [angular-drag-drop-lists](https://github.com/marceljuenemann/angular-drag-and-drop-lists).\n\n## Maintenance\n\nThis project was generated with [Angular CLI](https://github.com/angular/angular-cli).\n\nSee https://angular.io/guide/creating-libraries\n\n#### Edit Library\n\n- run `npm run watch:lib` for hacking on library\n\n#### Release Library\n\n- assure correct version is set in `projects/dnd/package.json`\n- build library with `npm run build:lib`\n- publish library with `npm run publish:stable` (use `npm run publish:next` for pre-releases)\n\n#### Edit Docs\n\n- initially and on lib changes run `npm run build:lib` to current version of lib available to the demo\n- run `npm run start:docs`\n\n#### Release Docs\n\n- build docs site with `npm run build:docs`\n- commit and push changes in `docs` to `master`\n\n---\n\n\u003cp align=\"center\"\u003e\nMade with :heart: \u0026 \n\u003ca href=\"https://www.jetbrains.com/?from=ngx-drag-drop\"\u003e\n  \u003cimg align=\"center\" alt=\"jetbrains\" src=\"jetbrains.svg\" width=\"120px\"\u003e\n\u003c/a\u003e\n\u0026 :coffee:\n\u003c/p\u003e\n","project_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2Freppners%2Fngx-drag-drop","html_url":"https://awesome.ecosyste.ms/projects/github.com%2Freppners%2Fngx-drag-drop","lists_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2Freppners%2Fngx-drag-drop/lists"}