feat(dragula): update to version 3.7 (#42106)

- version 2 created
- version 3 update with refined constructor, listeners and missing
properties and methods
- tests amended
- configuration as per DT defaults

Thanks!
This commit is contained in:
Piotr Błażejewicz (Peter Blazejewicz) 2020-02-05 18:31:59 +01:00 committed by GitHub
parent 776ca50f8d
commit a8b10755f8
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23
8 changed files with 258 additions and 116 deletions

View File

@ -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')!);

View File

@ -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 <https://github.com/pwelter34>
// Yang He <https://github.com/abruzzihraig>
// Piotr Błażejewicz <https://github.com/peterblazejewicz>
// 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;
}
}

View File

@ -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"
]
}
}

View File

@ -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" }

View File

@ -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', '');
});

47
types/dragula/v2/index.d.ts vendored Normal file
View File

@ -0,0 +1,47 @@
// Type definitions for dragula v2.1.2
// Project: http://bevacqua.github.io/dragula/
// Definitions by: Paul Welter <https://github.com/pwelter34>
// Yang He <https://github.com/abruzzihraig>
// 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;
}
}

View File

@ -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"
]
}

View File

@ -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
}
}