diff --git a/types/dragula/dragula-tests.ts b/types/dragula/dragula-tests.ts index 0e6280ae61..3534865443 100644 --- a/types/dragula/dragula-tests.ts +++ b/types/dragula/dragula-tests.ts @@ -1,43 +1,58 @@ -import dragula = require("dragula"); +const d1 = dragula([document.querySelector('#left')!, document.querySelector('#right')!]); -var d1 = dragula([document.querySelector('#left'), document.querySelector('#right')]); - -var d2 = dragula({ - isContainer: function (el) { +const d2 = dragula({ + isContainer(el) { return false; }, - moves: function (el, container, handle) { + moves(el, container, handle) { return true; }, - accepts: function (el, target, source, sibling) { + accepts(el, target, source, sibling) { return true; }, - invalid: function (el, target) { - return el.tagName === 'A' || el.tagName === 'BUTTON'; + invalid(el, target) { + if (el) { + return el.tagName === 'A' || el.tagName === 'BUTTON'; + } + return false; }, direction: 'vertical', copy: false, + copySortSource: true, revertOnSpill: false, removeOnSpill: false, delay: false, mirrorContainer: document.body, - ignoreInputTextSelection: true + ignoreInputTextSelection: true, }); -var d3 = dragula(); +const d3 = dragula(); -var drake = dragula({ - copy: true +const drake = dragula({ + copy: true, }); -drake.containers.push(document.querySelector('#container')); -dragula([document.getElementById('left'), document.getElementById('right')]) - .on('drag', function (el: Element) { - el.className = el.className.replace('ex-moved', ''); - }).on('drop', function (el: Element) { - el.className += ' ex-moved'; - }).on('over', function (el: Element, container: Element) { - container.className += ' ex-over'; - }).on('out', function (el: Element, container: Element) { - container.className = container.className.replace('ex-over', ''); - }); +drake.containers.push(document.querySelector('#container')!); + +dragula([document.getElementById('left')!, document.getElementById('right')!]) + .on('cancel', () => {}) + .on('cloned', () => {}) + .on('drag', () => {}) + .on('dragend', () => {}) + .on('drop', () => {}) + .on('drop', () => {}) + .on('out', () => {}) + .on('over', () => {}) + .on('remove', () => {}) + .on('shadow', () => {}) + .on('cancel', (el, container) => {}) + .on('cloned', (clone, original, type) => {}) + .on('drag', (el, source) => {}) + .on('dragend', el => {}) + .on('drop', (el, target, source, sibling) => {}) + .on('out', (el, containers, source) => {}) + .on('over', (el, container, source) => {}) + .on('remove', (el, container, source) => {}) + .on('shadow', (el, container, source) => {}); + +drake.containers.push(document.querySelector('#container')!); diff --git a/types/dragula/index.d.ts b/types/dragula/index.d.ts index 925a586971..ef10602172 100644 --- a/types/dragula/index.d.ts +++ b/types/dragula/index.d.ts @@ -1,10 +1,11 @@ -// Type definitions for dragula v2.1.2 +// Type definitions for dragula 3.7 // Project: http://bevacqua.github.io/dragula/ // Definitions by: Paul Welter // Yang He +// Piotr Błażejewicz // Definitions: https://github.com/DefinitelyTyped/DefinitelyTyped -declare var dragula: dragula.Dragula; +declare const dragula: dragula.Dragula; export = dragula; export as namespace dragula; @@ -18,6 +19,7 @@ declare namespace dragula { invalid?: (el?: Element, target?: Element) => boolean; direction?: string; copy?: ((el: Element, source: Element) => boolean) | boolean; + copySortSource?: boolean; revertOnSpill?: boolean; removeOnSpill?: boolean; delay?: boolean | number; @@ -28,20 +30,25 @@ declare namespace dragula { interface Drake { containers: Element[]; dragging: boolean; - start(item:Element): void; + start(item: Element): void; end(): void; - cancel(revert:boolean): void; - cancel(): void; + cancel(revert?: boolean): void; + canMove(item: Element): boolean; remove(): void; - on(events: string, callback: Function): Drake; + on(event: 'drag', listener: (el: Element, source: Element) => void): Drake; + on(event: 'dragend', listener: (el: Element) => void): Drake; + on(event: 'drop', listener: (el: Element, target: Element, source: Element, sibling: Element) => void): Drake; + on( + event: 'cancel' | 'remove' | 'shadow' | 'over' | 'out', + listener: (el: Element, container: Element, source: Element) => void, + ): Drake; + on(event: 'cloned', listener: (clone: Element, original: Element, type: 'mirror' | 'copy') => void): Drake; destroy(): void; } interface Dragula { - (containers: Element[], options: DragulaOptions): Drake; (containers: Element, options: DragulaOptions): Drake; - (containers: Element[]): Drake; - (options: DragulaOptions): Drake; - (): Drake; + (containers: Element[], options?: DragulaOptions): Drake; + (options?: DragulaOptions): Drake; } } diff --git a/types/dragula/tsconfig.json b/types/dragula/tsconfig.json index 8179057247..7ab87cdfc9 100644 --- a/types/dragula/tsconfig.json +++ b/types/dragula/tsconfig.json @@ -7,7 +7,7 @@ ], "noImplicitAny": true, "noImplicitThis": true, - "strictNullChecks": false, + "strictNullChecks": true, "strictFunctionTypes": true, "baseUrl": "../", "typeRoots": [ @@ -21,4 +21,4 @@ "index.d.ts", "dragula-tests.ts" ] -} \ No newline at end of file +} diff --git a/types/dragula/tslint.json b/types/dragula/tslint.json index 3d59f55fda..3db14f85ea 100644 --- a/types/dragula/tslint.json +++ b/types/dragula/tslint.json @@ -1,80 +1 @@ -{ - "extends": "dtslint/dt.json", - "rules": { - "adjacent-overload-signatures": false, - "array-type": false, - "arrow-return-shorthand": false, - "ban-types": false, - "callable-types": false, - "comment-format": false, - "dt-header": false, - "npm-naming": false, - "eofline": false, - "export-just-namespace": false, - "import-spacing": false, - "interface-name": false, - "interface-over-type-literal": false, - "jsdoc-format": false, - "max-line-length": false, - "member-access": false, - "new-parens": false, - "no-any-union": false, - "no-boolean-literal-compare": false, - "no-conditional-assignment": false, - "no-consecutive-blank-lines": false, - "no-construct": false, - "no-declare-current-package": false, - "no-duplicate-imports": false, - "no-duplicate-variable": false, - "no-empty-interface": false, - "no-for-in-array": false, - "no-inferrable-types": false, - "no-internal-module": false, - "no-irregular-whitespace": false, - "no-mergeable-namespace": false, - "no-misused-new": false, - "no-namespace": false, - "no-object-literal-type-assertion": false, - "no-padding": false, - "no-redundant-jsdoc": false, - "no-redundant-jsdoc-2": false, - "no-redundant-undefined": false, - "no-reference-import": false, - "no-relative-import-in-test": false, - "no-self-import": false, - "no-single-declare-module": false, - "no-string-throw": false, - "no-unnecessary-callback-wrapper": false, - "no-unnecessary-class": false, - "no-unnecessary-generics": false, - "no-unnecessary-qualifier": false, - "no-unnecessary-type-assertion": false, - "no-useless-files": false, - "no-var-keyword": false, - "no-var-requires": false, - "no-void-expression": false, - "no-trailing-whitespace": false, - "object-literal-key-quotes": false, - "object-literal-shorthand": false, - "one-line": false, - "one-variable-per-declaration": false, - "only-arrow-functions": false, - "prefer-conditional-expression": false, - "prefer-const": false, - "prefer-declare-function": false, - "prefer-for-of": false, - "prefer-method-signature": false, - "prefer-template": false, - "radix": false, - "semicolon": false, - "space-before-function-paren": false, - "space-within-parens": false, - "strict-export-declare-modifiers": false, - "trim-file": false, - "triple-equals": false, - "typedef-whitespace": false, - "unified-signatures": false, - "void-return": false, - "whitespace": false - } -} +{ "extends": "dtslint/dt.json" } diff --git a/types/dragula/v2/dragula-tests.ts b/types/dragula/v2/dragula-tests.ts new file mode 100644 index 0000000000..0e6280ae61 --- /dev/null +++ b/types/dragula/v2/dragula-tests.ts @@ -0,0 +1,43 @@ +import dragula = require("dragula"); + +var d1 = dragula([document.querySelector('#left'), document.querySelector('#right')]); + +var d2 = dragula({ + isContainer: function (el) { + return false; + }, + moves: function (el, container, handle) { + return true; + }, + accepts: function (el, target, source, sibling) { + return true; + }, + invalid: function (el, target) { + return el.tagName === 'A' || el.tagName === 'BUTTON'; + }, + direction: 'vertical', + copy: false, + revertOnSpill: false, + removeOnSpill: false, + delay: false, + mirrorContainer: document.body, + ignoreInputTextSelection: true +}); + +var d3 = dragula(); + +var drake = dragula({ + copy: true +}); +drake.containers.push(document.querySelector('#container')); + +dragula([document.getElementById('left'), document.getElementById('right')]) + .on('drag', function (el: Element) { + el.className = el.className.replace('ex-moved', ''); + }).on('drop', function (el: Element) { + el.className += ' ex-moved'; + }).on('over', function (el: Element, container: Element) { + container.className += ' ex-over'; + }).on('out', function (el: Element, container: Element) { + container.className = container.className.replace('ex-over', ''); + }); diff --git a/types/dragula/v2/index.d.ts b/types/dragula/v2/index.d.ts new file mode 100644 index 0000000000..925a586971 --- /dev/null +++ b/types/dragula/v2/index.d.ts @@ -0,0 +1,47 @@ +// Type definitions for dragula v2.1.2 +// Project: http://bevacqua.github.io/dragula/ +// Definitions by: Paul Welter +// Yang He +// Definitions: https://github.com/DefinitelyTyped/DefinitelyTyped + +declare var dragula: dragula.Dragula; + +export = dragula; +export as namespace dragula; + +declare namespace dragula { + interface DragulaOptions { + containers?: Element[]; + isContainer?: (el?: Element) => boolean; + moves?: (el?: Element, container?: Element, handle?: Element, sibling?: Element) => boolean; + accepts?: (el?: Element, target?: Element, source?: Element, sibling?: Element) => boolean; + invalid?: (el?: Element, target?: Element) => boolean; + direction?: string; + copy?: ((el: Element, source: Element) => boolean) | boolean; + revertOnSpill?: boolean; + removeOnSpill?: boolean; + delay?: boolean | number; + mirrorContainer?: Element; + ignoreInputTextSelection?: boolean; + } + + interface Drake { + containers: Element[]; + dragging: boolean; + start(item:Element): void; + end(): void; + cancel(revert:boolean): void; + cancel(): void; + remove(): void; + on(events: string, callback: Function): Drake; + destroy(): void; + } + + interface Dragula { + (containers: Element[], options: DragulaOptions): Drake; + (containers: Element, options: DragulaOptions): Drake; + (containers: Element[]): Drake; + (options: DragulaOptions): Drake; + (): Drake; + } +} diff --git a/types/dragula/v2/tsconfig.json b/types/dragula/v2/tsconfig.json new file mode 100644 index 0000000000..e9a751be06 --- /dev/null +++ b/types/dragula/v2/tsconfig.json @@ -0,0 +1,29 @@ +{ + "compilerOptions": { + "module": "commonjs", + "lib": [ + "es6", + "dom" + ], + "noImplicitAny": true, + "noImplicitThis": true, + "strictNullChecks": false, + "strictFunctionTypes": true, + "baseUrl": "../../", + "typeRoots": [ + "../../" + ], + "paths": { + "dragula": [ + "dragula/v2" + ] + }, + "types": [], + "noEmit": true, + "forceConsistentCasingInFileNames": true + }, + "files": [ + "index.d.ts", + "dragula-tests.ts" + ] +} diff --git a/types/dragula/v2/tslint.json b/types/dragula/v2/tslint.json new file mode 100644 index 0000000000..3d59f55fda --- /dev/null +++ b/types/dragula/v2/tslint.json @@ -0,0 +1,80 @@ +{ + "extends": "dtslint/dt.json", + "rules": { + "adjacent-overload-signatures": false, + "array-type": false, + "arrow-return-shorthand": false, + "ban-types": false, + "callable-types": false, + "comment-format": false, + "dt-header": false, + "npm-naming": false, + "eofline": false, + "export-just-namespace": false, + "import-spacing": false, + "interface-name": false, + "interface-over-type-literal": false, + "jsdoc-format": false, + "max-line-length": false, + "member-access": false, + "new-parens": false, + "no-any-union": false, + "no-boolean-literal-compare": false, + "no-conditional-assignment": false, + "no-consecutive-blank-lines": false, + "no-construct": false, + "no-declare-current-package": false, + "no-duplicate-imports": false, + "no-duplicate-variable": false, + "no-empty-interface": false, + "no-for-in-array": false, + "no-inferrable-types": false, + "no-internal-module": false, + "no-irregular-whitespace": false, + "no-mergeable-namespace": false, + "no-misused-new": false, + "no-namespace": false, + "no-object-literal-type-assertion": false, + "no-padding": false, + "no-redundant-jsdoc": false, + "no-redundant-jsdoc-2": false, + "no-redundant-undefined": false, + "no-reference-import": false, + "no-relative-import-in-test": false, + "no-self-import": false, + "no-single-declare-module": false, + "no-string-throw": false, + "no-unnecessary-callback-wrapper": false, + "no-unnecessary-class": false, + "no-unnecessary-generics": false, + "no-unnecessary-qualifier": false, + "no-unnecessary-type-assertion": false, + "no-useless-files": false, + "no-var-keyword": false, + "no-var-requires": false, + "no-void-expression": false, + "no-trailing-whitespace": false, + "object-literal-key-quotes": false, + "object-literal-shorthand": false, + "one-line": false, + "one-variable-per-declaration": false, + "only-arrow-functions": false, + "prefer-conditional-expression": false, + "prefer-const": false, + "prefer-declare-function": false, + "prefer-for-of": false, + "prefer-method-signature": false, + "prefer-template": false, + "radix": false, + "semicolon": false, + "space-before-function-paren": false, + "space-within-parens": false, + "strict-export-declare-modifiers": false, + "trim-file": false, + "triple-equals": false, + "typedef-whitespace": false, + "unified-signatures": false, + "void-return": false, + "whitespace": false + } +}