From c635092f032d1f879a3aff2c3ff51d2ab1aa014d Mon Sep 17 00:00:00 2001 From: Maarten Staa Date: Thu, 20 Sep 2018 15:06:59 +0200 Subject: [PATCH] Sortablejs: Types for group option. --- types/sortablejs/index.d.ts | 9 +++- types/sortablejs/sortablejs-tests.ts | 61 +++++++++++++++++++++++++++- 2 files changed, 68 insertions(+), 2 deletions(-) diff --git a/types/sortablejs/index.d.ts b/types/sortablejs/index.d.ts index 4c521feaa7..0801996ce5 100644 --- a/types/sortablejs/index.d.ts +++ b/types/sortablejs/index.d.ts @@ -88,8 +88,15 @@ declare namespace Sortable { willInsertAfter?: boolean; } + export interface GroupOptions { + name: string; + pull?: boolean | 'clone' | ((to: Sortable, from: Sortable) => boolean | string); + put?: boolean | string | string[] | ((to: Sortable) => boolean); + revertClone?: boolean; + } + export interface Options { - group?: any; + group?: string | GroupOptions; sort?: boolean; delay?: number; disabled?: boolean; diff --git a/types/sortablejs/sortablejs-tests.ts b/types/sortablejs/sortablejs-tests.ts index 73c32ea862..cf3e248167 100644 --- a/types/sortablejs/sortablejs-tests.ts +++ b/types/sortablejs/sortablejs-tests.ts @@ -197,7 +197,7 @@ simpleList.innerHTML = Array.apply(null, new Array(100)).map(function(value: any }, { name: 'advanced', - pull: 'clone', + pull: 'clone' as 'clone', put: false }, { name: 'advanced', @@ -297,3 +297,62 @@ document.addEventListener("DOMContentLoaded", function() { setNoiseBackground(document.getElementsByTagName('body')[0], 50, 50, 0.02); }, false); + +Sortable.create(simpleList, { + group: 'foo', + animation: 100 +}); + +Sortable.create(simpleList, { + group: 'bar', + animation: 100 +}); + +Sortable.create(simpleList, { + group: { + name: 'qux', + put: ['foo', 'bar'] + }, + animation: 100 +}); + +Sortable.create(simpleList, { + group: 'foo', + animation: 100 +}); + +Sortable.create(simpleList, { + group: { + name: 'bar', + put: 'qux', + pull: function (to, from) { + return from.el.children.length > 2 || 'clone'; + } + }, + animation: 100 +}); + +Sortable.create(simpleList, { + group: { + name: 'qux', + put: function (to) { + return to.el.children.length < 4; + } + }, + animation: 100 +}); + +Sortable.create(simpleList, { + animation: 200, + group: { + name: "shared", + pull: "clone", + revertClone: true, + }, + sort: true +}); + +Sortable.create(simpleList, { + group: "shared", + sort: false +});