Sortable.js 124 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859606162636465666768697071727374757677787980818283848586878889909192939495969798991001011021031041051061071081091101111121131141151161171181191201211221231241251261271281291301311321331341351361371381391401411421431441451461471481491501511521531541551561571581591601611621631641651661671681691701711721731741751761771781791801811821831841851861871881891901911921931941951961971981992002012022032042052062072082092102112122132142152162172182192202212222232242252262272282292302312322332342352362372382392402412422432442452462472482492502512522532542552562572582592602612622632642652662672682692702712722732742752762772782792802812822832842852862872882892902912922932942952962972982993003013023033043053063073083093103113123133143153163173183193203213223233243253263273283293303313323333343353363373383393403413423433443453463473483493503513523533543553563573583593603613623633643653663673683693703713723733743753763773783793803813823833843853863873883893903913923933943953963973983994004014024034044054064074084094104114124134144154164174184194204214224234244254264274284294304314324334344354364374384394404414424434444454464474484494504514524534544554564574584594604614624634644654664674684694704714724734744754764774784794804814824834844854864874884894904914924934944954964974984995005015025035045055065075085095105115125135145155165175185195205215225235245255265275285295305315325335345355365375385395405415425435445455465475485495505515525535545555565575585595605615625635645655665675685695705715725735745755765775785795805815825835845855865875885895905915925935945955965975985996006016026036046056066076086096106116126136146156166176186196206216226236246256266276286296306316326336346356366376386396406416426436446456466476486496506516526536546556566576586596606616626636646656666676686696706716726736746756766776786796806816826836846856866876886896906916926936946956966976986997007017027037047057067077087097107117127137147157167177187197207217227237247257267277287297307317327337347357367377387397407417427437447457467477487497507517527537547557567577587597607617627637647657667677687697707717727737747757767777787797807817827837847857867877887897907917927937947957967977987998008018028038048058068078088098108118128138148158168178188198208218228238248258268278288298308318328338348358368378388398408418428438448458468478488498508518528538548558568578588598608618628638648658668678688698708718728738748758768778788798808818828838848858868878888898908918928938948958968978988999009019029039049059069079089099109119129139149159169179189199209219229239249259269279289299309319329339349359369379389399409419429439449459469479489499509519529539549559569579589599609619629639649659669679689699709719729739749759769779789799809819829839849859869879889899909919929939949959969979989991000100110021003100410051006100710081009101010111012101310141015101610171018101910201021102210231024102510261027102810291030103110321033103410351036103710381039104010411042104310441045104610471048104910501051105210531054105510561057105810591060106110621063106410651066106710681069107010711072107310741075107610771078107910801081108210831084108510861087108810891090109110921093109410951096109710981099110011011102110311041105110611071108110911101111111211131114111511161117111811191120112111221123112411251126112711281129113011311132113311341135113611371138113911401141114211431144114511461147114811491150115111521153115411551156115711581159116011611162116311641165116611671168116911701171117211731174117511761177117811791180118111821183118411851186118711881189119011911192119311941195119611971198119912001201120212031204120512061207120812091210121112121213121412151216121712181219122012211222122312241225122612271228122912301231123212331234123512361237123812391240124112421243124412451246124712481249125012511252125312541255125612571258125912601261126212631264126512661267126812691270127112721273127412751276127712781279128012811282128312841285128612871288128912901291129212931294129512961297129812991300130113021303130413051306130713081309131013111312131313141315131613171318131913201321132213231324132513261327132813291330133113321333133413351336133713381339134013411342134313441345134613471348134913501351135213531354135513561357135813591360136113621363136413651366136713681369137013711372137313741375137613771378137913801381138213831384138513861387138813891390139113921393139413951396139713981399140014011402140314041405140614071408140914101411141214131414141514161417141814191420142114221423142414251426142714281429143014311432143314341435143614371438143914401441144214431444144514461447144814491450145114521453145414551456145714581459146014611462146314641465146614671468146914701471147214731474147514761477147814791480148114821483148414851486148714881489149014911492149314941495149614971498149915001501150215031504150515061507150815091510151115121513151415151516151715181519152015211522152315241525152615271528152915301531153215331534153515361537153815391540154115421543154415451546154715481549155015511552155315541555155615571558155915601561156215631564156515661567156815691570157115721573157415751576157715781579158015811582158315841585158615871588158915901591159215931594159515961597159815991600160116021603160416051606160716081609161016111612161316141615161616171618161916201621162216231624162516261627162816291630163116321633163416351636163716381639164016411642164316441645164616471648164916501651165216531654165516561657165816591660166116621663166416651666166716681669167016711672167316741675167616771678167916801681168216831684168516861687168816891690169116921693169416951696169716981699170017011702170317041705170617071708170917101711171217131714171517161717171817191720172117221723172417251726172717281729173017311732173317341735173617371738173917401741174217431744174517461747174817491750175117521753175417551756175717581759176017611762176317641765176617671768176917701771177217731774177517761777177817791780178117821783178417851786178717881789179017911792179317941795179617971798179918001801180218031804180518061807180818091810181118121813181418151816181718181819182018211822182318241825182618271828182918301831183218331834183518361837183818391840184118421843184418451846184718481849185018511852185318541855185618571858185918601861186218631864186518661867186818691870187118721873187418751876187718781879188018811882188318841885188618871888188918901891189218931894189518961897189818991900190119021903190419051906190719081909191019111912191319141915191619171918191919201921192219231924192519261927192819291930193119321933193419351936193719381939194019411942194319441945194619471948194919501951195219531954195519561957195819591960196119621963196419651966196719681969197019711972197319741975197619771978197919801981198219831984198519861987198819891990199119921993199419951996199719981999200020012002200320042005200620072008200920102011201220132014201520162017201820192020202120222023202420252026202720282029203020312032203320342035203620372038203920402041204220432044204520462047204820492050205120522053205420552056205720582059206020612062206320642065206620672068206920702071207220732074207520762077207820792080208120822083208420852086208720882089209020912092209320942095209620972098209921002101210221032104210521062107210821092110211121122113211421152116211721182119212021212122212321242125212621272128212921302131213221332134213521362137213821392140214121422143214421452146214721482149215021512152215321542155215621572158215921602161216221632164216521662167216821692170217121722173217421752176217721782179218021812182218321842185218621872188218921902191219221932194219521962197219821992200220122022203220422052206220722082209221022112212221322142215221622172218221922202221222222232224222522262227222822292230223122322233223422352236223722382239224022412242224322442245224622472248224922502251225222532254225522562257225822592260226122622263226422652266226722682269227022712272227322742275227622772278227922802281228222832284228522862287228822892290229122922293229422952296229722982299230023012302230323042305230623072308230923102311231223132314231523162317231823192320232123222323232423252326232723282329233023312332233323342335233623372338233923402341234223432344234523462347234823492350235123522353235423552356235723582359236023612362236323642365236623672368236923702371237223732374237523762377237823792380238123822383238423852386238723882389239023912392239323942395239623972398239924002401240224032404240524062407240824092410241124122413241424152416241724182419242024212422242324242425242624272428242924302431243224332434243524362437243824392440244124422443244424452446244724482449245024512452245324542455245624572458245924602461246224632464246524662467246824692470247124722473247424752476247724782479248024812482248324842485248624872488248924902491249224932494249524962497249824992500250125022503250425052506250725082509251025112512251325142515251625172518251925202521252225232524252525262527252825292530253125322533253425352536253725382539254025412542254325442545254625472548254925502551255225532554255525562557255825592560256125622563256425652566256725682569257025712572257325742575257625772578257925802581258225832584258525862587258825892590259125922593259425952596259725982599260026012602260326042605260626072608260926102611261226132614261526162617261826192620262126222623262426252626262726282629263026312632263326342635263626372638263926402641264226432644264526462647264826492650265126522653265426552656265726582659266026612662266326642665266626672668266926702671267226732674267526762677267826792680268126822683268426852686268726882689269026912692269326942695269626972698269927002701270227032704270527062707270827092710271127122713271427152716271727182719272027212722272327242725272627272728272927302731273227332734273527362737273827392740274127422743274427452746274727482749275027512752275327542755275627572758275927602761276227632764276527662767276827692770277127722773277427752776277727782779278027812782278327842785278627872788278927902791279227932794279527962797279827992800280128022803280428052806280728082809281028112812281328142815281628172818281928202821282228232824282528262827282828292830283128322833283428352836283728382839284028412842284328442845284628472848284928502851285228532854285528562857285828592860286128622863286428652866286728682869287028712872287328742875287628772878287928802881288228832884288528862887288828892890289128922893289428952896289728982899290029012902290329042905290629072908290929102911291229132914291529162917291829192920292129222923292429252926292729282929293029312932293329342935293629372938293929402941294229432944294529462947294829492950295129522953295429552956295729582959296029612962296329642965296629672968296929702971297229732974297529762977297829792980298129822983298429852986298729882989299029912992299329942995299629972998299930003001300230033004300530063007300830093010301130123013301430153016301730183019302030213022302330243025302630273028302930303031303230333034303530363037303830393040304130423043304430453046304730483049305030513052305330543055305630573058305930603061306230633064306530663067306830693070307130723073307430753076307730783079308030813082308330843085308630873088308930903091309230933094309530963097309830993100310131023103310431053106310731083109311031113112311331143115311631173118311931203121312231233124312531263127312831293130313131323133313431353136313731383139314031413142314331443145314631473148314931503151315231533154315531563157315831593160316131623163316431653166316731683169317031713172317331743175317631773178317931803181318231833184318531863187318831893190319131923193319431953196319731983199320032013202320332043205320632073208320932103211321232133214321532163217321832193220322132223223322432253226322732283229323032313232323332343235323632373238323932403241324232433244324532463247324832493250325132523253325432553256325732583259326032613262326332643265326632673268326932703271327232733274327532763277327832793280328132823283328432853286328732883289329032913292329332943295329632973298329933003301330233033304330533063307330833093310331133123313331433153316331733183319332033213322332333243325332633273328332933303331333233333334333533363337333833393340334133423343334433453346334733483349335033513352335333543355335633573358335933603361336233633364336533663367336833693370337133723373337433753376337733783379338033813382338333843385338633873388
  1. /**!
  2. * Sortable 1.15.6
  3. * @author RubaXa <trash@rubaxa.org>
  4. * @author owenm <owen23355@gmail.com>
  5. * @license MIT
  6. */
  7. (function (global, factory) {
  8. typeof exports === 'object' && typeof module !== 'undefined' ? module.exports = factory() :
  9. typeof define === 'function' && define.amd ? define(factory) :
  10. (global = global || self, global.Sortable = factory());
  11. }(this, (function () { 'use strict';
  12. function ownKeys(object, enumerableOnly) {
  13. var keys = Object.keys(object);
  14. if (Object.getOwnPropertySymbols) {
  15. var symbols = Object.getOwnPropertySymbols(object);
  16. if (enumerableOnly) {
  17. symbols = symbols.filter(function (sym) {
  18. return Object.getOwnPropertyDescriptor(object, sym).enumerable;
  19. });
  20. }
  21. keys.push.apply(keys, symbols);
  22. }
  23. return keys;
  24. }
  25. function _objectSpread2(target) {
  26. for (var i = 1; i < arguments.length; i++) {
  27. var source = arguments[i] != null ? arguments[i] : {};
  28. if (i % 2) {
  29. ownKeys(Object(source), true).forEach(function (key) {
  30. _defineProperty(target, key, source[key]);
  31. });
  32. } else if (Object.getOwnPropertyDescriptors) {
  33. Object.defineProperties(target, Object.getOwnPropertyDescriptors(source));
  34. } else {
  35. ownKeys(Object(source)).forEach(function (key) {
  36. Object.defineProperty(target, key, Object.getOwnPropertyDescriptor(source, key));
  37. });
  38. }
  39. }
  40. return target;
  41. }
  42. function _typeof(obj) {
  43. "@babel/helpers - typeof";
  44. if (typeof Symbol === "function" && typeof Symbol.iterator === "symbol") {
  45. _typeof = function (obj) {
  46. return typeof obj;
  47. };
  48. } else {
  49. _typeof = function (obj) {
  50. return obj && typeof Symbol === "function" && obj.constructor === Symbol && obj !== Symbol.prototype ? "symbol" : typeof obj;
  51. };
  52. }
  53. return _typeof(obj);
  54. }
  55. function _defineProperty(obj, key, value) {
  56. if (key in obj) {
  57. Object.defineProperty(obj, key, {
  58. value: value,
  59. enumerable: true,
  60. configurable: true,
  61. writable: true
  62. });
  63. } else {
  64. obj[key] = value;
  65. }
  66. return obj;
  67. }
  68. function _extends() {
  69. _extends = Object.assign || function (target) {
  70. for (var i = 1; i < arguments.length; i++) {
  71. var source = arguments[i];
  72. for (var key in source) {
  73. if (Object.prototype.hasOwnProperty.call(source, key)) {
  74. target[key] = source[key];
  75. }
  76. }
  77. }
  78. return target;
  79. };
  80. return _extends.apply(this, arguments);
  81. }
  82. function _objectWithoutPropertiesLoose(source, excluded) {
  83. if (source == null) return {};
  84. var target = {};
  85. var sourceKeys = Object.keys(source);
  86. var key, i;
  87. for (i = 0; i < sourceKeys.length; i++) {
  88. key = sourceKeys[i];
  89. if (excluded.indexOf(key) >= 0) continue;
  90. target[key] = source[key];
  91. }
  92. return target;
  93. }
  94. function _objectWithoutProperties(source, excluded) {
  95. if (source == null) return {};
  96. var target = _objectWithoutPropertiesLoose(source, excluded);
  97. var key, i;
  98. if (Object.getOwnPropertySymbols) {
  99. var sourceSymbolKeys = Object.getOwnPropertySymbols(source);
  100. for (i = 0; i < sourceSymbolKeys.length; i++) {
  101. key = sourceSymbolKeys[i];
  102. if (excluded.indexOf(key) >= 0) continue;
  103. if (!Object.prototype.propertyIsEnumerable.call(source, key)) continue;
  104. target[key] = source[key];
  105. }
  106. }
  107. return target;
  108. }
  109. function _toConsumableArray(arr) {
  110. return _arrayWithoutHoles(arr) || _iterableToArray(arr) || _unsupportedIterableToArray(arr) || _nonIterableSpread();
  111. }
  112. function _arrayWithoutHoles(arr) {
  113. if (Array.isArray(arr)) return _arrayLikeToArray(arr);
  114. }
  115. function _iterableToArray(iter) {
  116. if (typeof Symbol !== "undefined" && iter[Symbol.iterator] != null || iter["@@iterator"] != null) return Array.from(iter);
  117. }
  118. function _unsupportedIterableToArray(o, minLen) {
  119. if (!o) return;
  120. if (typeof o === "string") return _arrayLikeToArray(o, minLen);
  121. var n = Object.prototype.toString.call(o).slice(8, -1);
  122. if (n === "Object" && o.constructor) n = o.constructor.name;
  123. if (n === "Map" || n === "Set") return Array.from(o);
  124. if (n === "Arguments" || /^(?:Ui|I)nt(?:8|16|32)(?:Clamped)?Array$/.test(n)) return _arrayLikeToArray(o, minLen);
  125. }
  126. function _arrayLikeToArray(arr, len) {
  127. if (len == null || len > arr.length) len = arr.length;
  128. for (var i = 0, arr2 = new Array(len); i < len; i++) arr2[i] = arr[i];
  129. return arr2;
  130. }
  131. function _nonIterableSpread() {
  132. throw new TypeError("Invalid attempt to spread non-iterable instance.\nIn order to be iterable, non-array objects must have a [Symbol.iterator]() method.");
  133. }
  134. var version = "1.15.6";
  135. function userAgent(pattern) {
  136. if (typeof window !== 'undefined' && window.navigator) {
  137. return !! /*@__PURE__*/navigator.userAgent.match(pattern);
  138. }
  139. }
  140. var IE11OrLess = userAgent(/(?:Trident.*rv[ :]?11\.|msie|iemobile|Windows Phone)/i);
  141. var Edge = userAgent(/Edge/i);
  142. var FireFox = userAgent(/firefox/i);
  143. var Safari = userAgent(/safari/i) && !userAgent(/chrome/i) && !userAgent(/android/i);
  144. var IOS = userAgent(/iP(ad|od|hone)/i);
  145. var ChromeForAndroid = userAgent(/chrome/i) && userAgent(/android/i);
  146. var captureMode = {
  147. capture: false,
  148. passive: false
  149. };
  150. function on(el, event, fn) {
  151. el.addEventListener(event, fn, !IE11OrLess && captureMode);
  152. }
  153. function off(el, event, fn) {
  154. el.removeEventListener(event, fn, !IE11OrLess && captureMode);
  155. }
  156. function matches( /**HTMLElement*/el, /**String*/selector) {
  157. if (!selector) return;
  158. selector[0] === '>' && (selector = selector.substring(1));
  159. if (el) {
  160. try {
  161. if (el.matches) {
  162. return el.matches(selector);
  163. } else if (el.msMatchesSelector) {
  164. return el.msMatchesSelector(selector);
  165. } else if (el.webkitMatchesSelector) {
  166. return el.webkitMatchesSelector(selector);
  167. }
  168. } catch (_) {
  169. return false;
  170. }
  171. }
  172. return false;
  173. }
  174. function getParentOrHost(el) {
  175. return el.host && el !== document && el.host.nodeType ? el.host : el.parentNode;
  176. }
  177. function closest( /**HTMLElement*/el, /**String*/selector, /**HTMLElement*/ctx, includeCTX) {
  178. if (el) {
  179. ctx = ctx || document;
  180. do {
  181. if (selector != null && (selector[0] === '>' ? el.parentNode === ctx && matches(el, selector) : matches(el, selector)) || includeCTX && el === ctx) {
  182. return el;
  183. }
  184. if (el === ctx) break;
  185. /* jshint boss:true */
  186. } while (el = getParentOrHost(el));
  187. }
  188. return null;
  189. }
  190. var R_SPACE = /\s+/g;
  191. function toggleClass(el, name, state) {
  192. if (el && name) {
  193. if (el.classList) {
  194. el.classList[state ? 'add' : 'remove'](name);
  195. } else {
  196. var className = (' ' + el.className + ' ').replace(R_SPACE, ' ').replace(' ' + name + ' ', ' ');
  197. el.className = (className + (state ? ' ' + name : '')).replace(R_SPACE, ' ');
  198. }
  199. }
  200. }
  201. function css(el, prop, val) {
  202. var style = el && el.style;
  203. if (style) {
  204. if (val === void 0) {
  205. if (document.defaultView && document.defaultView.getComputedStyle) {
  206. val = document.defaultView.getComputedStyle(el, '');
  207. } else if (el.currentStyle) {
  208. val = el.currentStyle;
  209. }
  210. return prop === void 0 ? val : val[prop];
  211. } else {
  212. if (!(prop in style) && prop.indexOf('webkit') === -1) {
  213. prop = '-webkit-' + prop;
  214. }
  215. style[prop] = val + (typeof val === 'string' ? '' : 'px');
  216. }
  217. }
  218. }
  219. function matrix(el, selfOnly) {
  220. var appliedTransforms = '';
  221. if (typeof el === 'string') {
  222. appliedTransforms = el;
  223. } else {
  224. do {
  225. var transform = css(el, 'transform');
  226. if (transform && transform !== 'none') {
  227. appliedTransforms = transform + ' ' + appliedTransforms;
  228. }
  229. /* jshint boss:true */
  230. } while (!selfOnly && (el = el.parentNode));
  231. }
  232. var matrixFn = window.DOMMatrix || window.WebKitCSSMatrix || window.CSSMatrix || window.MSCSSMatrix;
  233. /*jshint -W056 */
  234. return matrixFn && new matrixFn(appliedTransforms);
  235. }
  236. function find(ctx, tagName, iterator) {
  237. if (ctx) {
  238. var list = ctx.getElementsByTagName(tagName),
  239. i = 0,
  240. n = list.length;
  241. if (iterator) {
  242. for (; i < n; i++) {
  243. iterator(list[i], i);
  244. }
  245. }
  246. return list;
  247. }
  248. return [];
  249. }
  250. function getWindowScrollingElement() {
  251. var scrollingElement = document.scrollingElement;
  252. if (scrollingElement) {
  253. return scrollingElement;
  254. } else {
  255. return document.documentElement;
  256. }
  257. }
  258. /**
  259. * Returns the "bounding client rect" of given element
  260. * @param {HTMLElement} el The element whose boundingClientRect is wanted
  261. * @param {[Boolean]} relativeToContainingBlock Whether the rect should be relative to the containing block of (including) the container
  262. * @param {[Boolean]} relativeToNonStaticParent Whether the rect should be relative to the relative parent of (including) the contaienr
  263. * @param {[Boolean]} undoScale Whether the container's scale() should be undone
  264. * @param {[HTMLElement]} container The parent the element will be placed in
  265. * @return {Object} The boundingClientRect of el, with specified adjustments
  266. */
  267. function getRect(el, relativeToContainingBlock, relativeToNonStaticParent, undoScale, container) {
  268. if (!el.getBoundingClientRect && el !== window) return;
  269. var elRect, top, left, bottom, right, height, width;
  270. if (el !== window && el.parentNode && el !== getWindowScrollingElement()) {
  271. elRect = el.getBoundingClientRect();
  272. top = elRect.top;
  273. left = elRect.left;
  274. bottom = elRect.bottom;
  275. right = elRect.right;
  276. height = elRect.height;
  277. width = elRect.width;
  278. } else {
  279. top = 0;
  280. left = 0;
  281. bottom = window.innerHeight;
  282. right = window.innerWidth;
  283. height = window.innerHeight;
  284. width = window.innerWidth;
  285. }
  286. if ((relativeToContainingBlock || relativeToNonStaticParent) && el !== window) {
  287. // Adjust for translate()
  288. container = container || el.parentNode;
  289. // solves #1123 (see: https://stackoverflow.com/a/37953806/6088312)
  290. // Not needed on <= IE11
  291. if (!IE11OrLess) {
  292. do {
  293. if (container && container.getBoundingClientRect && (css(container, 'transform') !== 'none' || relativeToNonStaticParent && css(container, 'position') !== 'static')) {
  294. var containerRect = container.getBoundingClientRect();
  295. // Set relative to edges of padding box of container
  296. top -= containerRect.top + parseInt(css(container, 'border-top-width'));
  297. left -= containerRect.left + parseInt(css(container, 'border-left-width'));
  298. bottom = top + elRect.height;
  299. right = left + elRect.width;
  300. break;
  301. }
  302. /* jshint boss:true */
  303. } while (container = container.parentNode);
  304. }
  305. }
  306. if (undoScale && el !== window) {
  307. // Adjust for scale()
  308. var elMatrix = matrix(container || el),
  309. scaleX = elMatrix && elMatrix.a,
  310. scaleY = elMatrix && elMatrix.d;
  311. if (elMatrix) {
  312. top /= scaleY;
  313. left /= scaleX;
  314. width /= scaleX;
  315. height /= scaleY;
  316. bottom = top + height;
  317. right = left + width;
  318. }
  319. }
  320. return {
  321. top: top,
  322. left: left,
  323. bottom: bottom,
  324. right: right,
  325. width: width,
  326. height: height
  327. };
  328. }
  329. /**
  330. * Checks if a side of an element is scrolled past a side of its parents
  331. * @param {HTMLElement} el The element who's side being scrolled out of view is in question
  332. * @param {String} elSide Side of the element in question ('top', 'left', 'right', 'bottom')
  333. * @param {String} parentSide Side of the parent in question ('top', 'left', 'right', 'bottom')
  334. * @return {HTMLElement} The parent scroll element that the el's side is scrolled past, or null if there is no such element
  335. */
  336. function isScrolledPast(el, elSide, parentSide) {
  337. var parent = getParentAutoScrollElement(el, true),
  338. elSideVal = getRect(el)[elSide];
  339. /* jshint boss:true */
  340. while (parent) {
  341. var parentSideVal = getRect(parent)[parentSide],
  342. visible = void 0;
  343. if (parentSide === 'top' || parentSide === 'left') {
  344. visible = elSideVal >= parentSideVal;
  345. } else {
  346. visible = elSideVal <= parentSideVal;
  347. }
  348. if (!visible) return parent;
  349. if (parent === getWindowScrollingElement()) break;
  350. parent = getParentAutoScrollElement(parent, false);
  351. }
  352. return false;
  353. }
  354. /**
  355. * Gets nth child of el, ignoring hidden children, sortable's elements (does not ignore clone if it's visible)
  356. * and non-draggable elements
  357. * @param {HTMLElement} el The parent element
  358. * @param {Number} childNum The index of the child
  359. * @param {Object} options Parent Sortable's options
  360. * @return {HTMLElement} The child at index childNum, or null if not found
  361. */
  362. function getChild(el, childNum, options, includeDragEl) {
  363. var currentChild = 0,
  364. i = 0,
  365. children = el.children;
  366. while (i < children.length) {
  367. if (children[i].style.display !== 'none' && children[i] !== Sortable.ghost && (includeDragEl || children[i] !== Sortable.dragged) && closest(children[i], options.draggable, el, false)) {
  368. if (currentChild === childNum) {
  369. return children[i];
  370. }
  371. currentChild++;
  372. }
  373. i++;
  374. }
  375. return null;
  376. }
  377. /**
  378. * Gets the last child in the el, ignoring ghostEl or invisible elements (clones)
  379. * @param {HTMLElement} el Parent element
  380. * @param {selector} selector Any other elements that should be ignored
  381. * @return {HTMLElement} The last child, ignoring ghostEl
  382. */
  383. function lastChild(el, selector) {
  384. var last = el.lastElementChild;
  385. while (last && (last === Sortable.ghost || css(last, 'display') === 'none' || selector && !matches(last, selector))) {
  386. last = last.previousElementSibling;
  387. }
  388. return last || null;
  389. }
  390. /**
  391. * Returns the index of an element within its parent for a selected set of
  392. * elements
  393. * @param {HTMLElement} el
  394. * @param {selector} selector
  395. * @return {number}
  396. */
  397. function index(el, selector) {
  398. var index = 0;
  399. if (!el || !el.parentNode) {
  400. return -1;
  401. }
  402. /* jshint boss:true */
  403. while (el = el.previousElementSibling) {
  404. if (el.nodeName.toUpperCase() !== 'TEMPLATE' && el !== Sortable.clone && (!selector || matches(el, selector))) {
  405. index++;
  406. }
  407. }
  408. return index;
  409. }
  410. /**
  411. * Returns the scroll offset of the given element, added with all the scroll offsets of parent elements.
  412. * The value is returned in real pixels.
  413. * @param {HTMLElement} el
  414. * @return {Array} Offsets in the format of [left, top]
  415. */
  416. function getRelativeScrollOffset(el) {
  417. var offsetLeft = 0,
  418. offsetTop = 0,
  419. winScroller = getWindowScrollingElement();
  420. if (el) {
  421. do {
  422. var elMatrix = matrix(el),
  423. scaleX = elMatrix.a,
  424. scaleY = elMatrix.d;
  425. offsetLeft += el.scrollLeft * scaleX;
  426. offsetTop += el.scrollTop * scaleY;
  427. } while (el !== winScroller && (el = el.parentNode));
  428. }
  429. return [offsetLeft, offsetTop];
  430. }
  431. /**
  432. * Returns the index of the object within the given array
  433. * @param {Array} arr Array that may or may not hold the object
  434. * @param {Object} obj An object that has a key-value pair unique to and identical to a key-value pair in the object you want to find
  435. * @return {Number} The index of the object in the array, or -1
  436. */
  437. function indexOfObject(arr, obj) {
  438. for (var i in arr) {
  439. if (!arr.hasOwnProperty(i)) continue;
  440. for (var key in obj) {
  441. if (obj.hasOwnProperty(key) && obj[key] === arr[i][key]) return Number(i);
  442. }
  443. }
  444. return -1;
  445. }
  446. function getParentAutoScrollElement(el, includeSelf) {
  447. // skip to window
  448. if (!el || !el.getBoundingClientRect) return getWindowScrollingElement();
  449. var elem = el;
  450. var gotSelf = false;
  451. do {
  452. // we don't need to get elem css if it isn't even overflowing in the first place (performance)
  453. if (elem.clientWidth < elem.scrollWidth || elem.clientHeight < elem.scrollHeight) {
  454. var elemCSS = css(elem);
  455. if (elem.clientWidth < elem.scrollWidth && (elemCSS.overflowX == 'auto' || elemCSS.overflowX == 'scroll') || elem.clientHeight < elem.scrollHeight && (elemCSS.overflowY == 'auto' || elemCSS.overflowY == 'scroll')) {
  456. if (!elem.getBoundingClientRect || elem === document.body) return getWindowScrollingElement();
  457. if (gotSelf || includeSelf) return elem;
  458. gotSelf = true;
  459. }
  460. }
  461. /* jshint boss:true */
  462. } while (elem = elem.parentNode);
  463. return getWindowScrollingElement();
  464. }
  465. function extend(dst, src) {
  466. if (dst && src) {
  467. for (var key in src) {
  468. if (src.hasOwnProperty(key)) {
  469. dst[key] = src[key];
  470. }
  471. }
  472. }
  473. return dst;
  474. }
  475. function isRectEqual(rect1, rect2) {
  476. return Math.round(rect1.top) === Math.round(rect2.top) && Math.round(rect1.left) === Math.round(rect2.left) && Math.round(rect1.height) === Math.round(rect2.height) && Math.round(rect1.width) === Math.round(rect2.width);
  477. }
  478. var _throttleTimeout;
  479. function throttle(callback, ms) {
  480. return function () {
  481. if (!_throttleTimeout) {
  482. var args = arguments,
  483. _this = this;
  484. if (args.length === 1) {
  485. callback.call(_this, args[0]);
  486. } else {
  487. callback.apply(_this, args);
  488. }
  489. _throttleTimeout = setTimeout(function () {
  490. _throttleTimeout = void 0;
  491. }, ms);
  492. }
  493. };
  494. }
  495. function cancelThrottle() {
  496. clearTimeout(_throttleTimeout);
  497. _throttleTimeout = void 0;
  498. }
  499. function scrollBy(el, x, y) {
  500. el.scrollLeft += x;
  501. el.scrollTop += y;
  502. }
  503. function clone(el) {
  504. var Polymer = window.Polymer;
  505. var $ = window.jQuery || window.Zepto;
  506. if (Polymer && Polymer.dom) {
  507. return Polymer.dom(el).cloneNode(true);
  508. } else if ($) {
  509. return $(el).clone(true)[0];
  510. } else {
  511. return el.cloneNode(true);
  512. }
  513. }
  514. function setRect(el, rect) {
  515. css(el, 'position', 'absolute');
  516. css(el, 'top', rect.top);
  517. css(el, 'left', rect.left);
  518. css(el, 'width', rect.width);
  519. css(el, 'height', rect.height);
  520. }
  521. function unsetRect(el) {
  522. css(el, 'position', '');
  523. css(el, 'top', '');
  524. css(el, 'left', '');
  525. css(el, 'width', '');
  526. css(el, 'height', '');
  527. }
  528. function getChildContainingRectFromElement(container, options, ghostEl) {
  529. var rect = {};
  530. Array.from(container.children).forEach(function (child) {
  531. var _rect$left, _rect$top, _rect$right, _rect$bottom;
  532. if (!closest(child, options.draggable, container, false) || child.animated || child === ghostEl) return;
  533. var childRect = getRect(child);
  534. rect.left = Math.min((_rect$left = rect.left) !== null && _rect$left !== void 0 ? _rect$left : Infinity, childRect.left);
  535. rect.top = Math.min((_rect$top = rect.top) !== null && _rect$top !== void 0 ? _rect$top : Infinity, childRect.top);
  536. rect.right = Math.max((_rect$right = rect.right) !== null && _rect$right !== void 0 ? _rect$right : -Infinity, childRect.right);
  537. rect.bottom = Math.max((_rect$bottom = rect.bottom) !== null && _rect$bottom !== void 0 ? _rect$bottom : -Infinity, childRect.bottom);
  538. });
  539. rect.width = rect.right - rect.left;
  540. rect.height = rect.bottom - rect.top;
  541. rect.x = rect.left;
  542. rect.y = rect.top;
  543. return rect;
  544. }
  545. var expando = 'Sortable' + new Date().getTime();
  546. function AnimationStateManager() {
  547. var animationStates = [],
  548. animationCallbackId;
  549. return {
  550. captureAnimationState: function captureAnimationState() {
  551. animationStates = [];
  552. if (!this.options.animation) return;
  553. var children = [].slice.call(this.el.children);
  554. children.forEach(function (child) {
  555. if (css(child, 'display') === 'none' || child === Sortable.ghost) return;
  556. animationStates.push({
  557. target: child,
  558. rect: getRect(child)
  559. });
  560. var fromRect = _objectSpread2({}, animationStates[animationStates.length - 1].rect);
  561. // If animating: compensate for current animation
  562. if (child.thisAnimationDuration) {
  563. var childMatrix = matrix(child, true);
  564. if (childMatrix) {
  565. fromRect.top -= childMatrix.f;
  566. fromRect.left -= childMatrix.e;
  567. }
  568. }
  569. child.fromRect = fromRect;
  570. });
  571. },
  572. addAnimationState: function addAnimationState(state) {
  573. animationStates.push(state);
  574. },
  575. removeAnimationState: function removeAnimationState(target) {
  576. animationStates.splice(indexOfObject(animationStates, {
  577. target: target
  578. }), 1);
  579. },
  580. animateAll: function animateAll(callback) {
  581. var _this = this;
  582. if (!this.options.animation) {
  583. clearTimeout(animationCallbackId);
  584. if (typeof callback === 'function') callback();
  585. return;
  586. }
  587. var animating = false,
  588. animationTime = 0;
  589. animationStates.forEach(function (state) {
  590. var time = 0,
  591. target = state.target,
  592. fromRect = target.fromRect,
  593. toRect = getRect(target),
  594. prevFromRect = target.prevFromRect,
  595. prevToRect = target.prevToRect,
  596. animatingRect = state.rect,
  597. targetMatrix = matrix(target, true);
  598. if (targetMatrix) {
  599. // Compensate for current animation
  600. toRect.top -= targetMatrix.f;
  601. toRect.left -= targetMatrix.e;
  602. }
  603. target.toRect = toRect;
  604. if (target.thisAnimationDuration) {
  605. // Could also check if animatingRect is between fromRect and toRect
  606. if (isRectEqual(prevFromRect, toRect) && !isRectEqual(fromRect, toRect) &&
  607. // Make sure animatingRect is on line between toRect & fromRect
  608. (animatingRect.top - toRect.top) / (animatingRect.left - toRect.left) === (fromRect.top - toRect.top) / (fromRect.left - toRect.left)) {
  609. // If returning to same place as started from animation and on same axis
  610. time = calculateRealTime(animatingRect, prevFromRect, prevToRect, _this.options);
  611. }
  612. }
  613. // if fromRect != toRect: animate
  614. if (!isRectEqual(toRect, fromRect)) {
  615. target.prevFromRect = fromRect;
  616. target.prevToRect = toRect;
  617. if (!time) {
  618. time = _this.options.animation;
  619. }
  620. _this.animate(target, animatingRect, toRect, time);
  621. }
  622. if (time) {
  623. animating = true;
  624. animationTime = Math.max(animationTime, time);
  625. clearTimeout(target.animationResetTimer);
  626. target.animationResetTimer = setTimeout(function () {
  627. target.animationTime = 0;
  628. target.prevFromRect = null;
  629. target.fromRect = null;
  630. target.prevToRect = null;
  631. target.thisAnimationDuration = null;
  632. }, time);
  633. target.thisAnimationDuration = time;
  634. }
  635. });
  636. clearTimeout(animationCallbackId);
  637. if (!animating) {
  638. if (typeof callback === 'function') callback();
  639. } else {
  640. animationCallbackId = setTimeout(function () {
  641. if (typeof callback === 'function') callback();
  642. }, animationTime);
  643. }
  644. animationStates = [];
  645. },
  646. animate: function animate(target, currentRect, toRect, duration) {
  647. if (duration) {
  648. css(target, 'transition', '');
  649. css(target, 'transform', '');
  650. var elMatrix = matrix(this.el),
  651. scaleX = elMatrix && elMatrix.a,
  652. scaleY = elMatrix && elMatrix.d,
  653. translateX = (currentRect.left - toRect.left) / (scaleX || 1),
  654. translateY = (currentRect.top - toRect.top) / (scaleY || 1);
  655. target.animatingX = !!translateX;
  656. target.animatingY = !!translateY;
  657. css(target, 'transform', 'translate3d(' + translateX + 'px,' + translateY + 'px,0)');
  658. this.forRepaintDummy = repaint(target); // repaint
  659. css(target, 'transition', 'transform ' + duration + 'ms' + (this.options.easing ? ' ' + this.options.easing : ''));
  660. css(target, 'transform', 'translate3d(0,0,0)');
  661. typeof target.animated === 'number' && clearTimeout(target.animated);
  662. target.animated = setTimeout(function () {
  663. css(target, 'transition', '');
  664. css(target, 'transform', '');
  665. target.animated = false;
  666. target.animatingX = false;
  667. target.animatingY = false;
  668. }, duration);
  669. }
  670. }
  671. };
  672. }
  673. function repaint(target) {
  674. return target.offsetWidth;
  675. }
  676. function calculateRealTime(animatingRect, fromRect, toRect, options) {
  677. return Math.sqrt(Math.pow(fromRect.top - animatingRect.top, 2) + Math.pow(fromRect.left - animatingRect.left, 2)) / Math.sqrt(Math.pow(fromRect.top - toRect.top, 2) + Math.pow(fromRect.left - toRect.left, 2)) * options.animation;
  678. }
  679. var plugins = [];
  680. var defaults = {
  681. initializeByDefault: true
  682. };
  683. var PluginManager = {
  684. mount: function mount(plugin) {
  685. // Set default static properties
  686. for (var option in defaults) {
  687. if (defaults.hasOwnProperty(option) && !(option in plugin)) {
  688. plugin[option] = defaults[option];
  689. }
  690. }
  691. plugins.forEach(function (p) {
  692. if (p.pluginName === plugin.pluginName) {
  693. throw "Sortable: Cannot mount plugin ".concat(plugin.pluginName, " more than once");
  694. }
  695. });
  696. plugins.push(plugin);
  697. },
  698. pluginEvent: function pluginEvent(eventName, sortable, evt) {
  699. var _this = this;
  700. this.eventCanceled = false;
  701. evt.cancel = function () {
  702. _this.eventCanceled = true;
  703. };
  704. var eventNameGlobal = eventName + 'Global';
  705. plugins.forEach(function (plugin) {
  706. if (!sortable[plugin.pluginName]) return;
  707. // Fire global events if it exists in this sortable
  708. if (sortable[plugin.pluginName][eventNameGlobal]) {
  709. sortable[plugin.pluginName][eventNameGlobal](_objectSpread2({
  710. sortable: sortable
  711. }, evt));
  712. }
  713. // Only fire plugin event if plugin is enabled in this sortable,
  714. // and plugin has event defined
  715. if (sortable.options[plugin.pluginName] && sortable[plugin.pluginName][eventName]) {
  716. sortable[plugin.pluginName][eventName](_objectSpread2({
  717. sortable: sortable
  718. }, evt));
  719. }
  720. });
  721. },
  722. initializePlugins: function initializePlugins(sortable, el, defaults, options) {
  723. plugins.forEach(function (plugin) {
  724. var pluginName = plugin.pluginName;
  725. if (!sortable.options[pluginName] && !plugin.initializeByDefault) return;
  726. var initialized = new plugin(sortable, el, sortable.options);
  727. initialized.sortable = sortable;
  728. initialized.options = sortable.options;
  729. sortable[pluginName] = initialized;
  730. // Add default options from plugin
  731. _extends(defaults, initialized.defaults);
  732. });
  733. for (var option in sortable.options) {
  734. if (!sortable.options.hasOwnProperty(option)) continue;
  735. var modified = this.modifyOption(sortable, option, sortable.options[option]);
  736. if (typeof modified !== 'undefined') {
  737. sortable.options[option] = modified;
  738. }
  739. }
  740. },
  741. getEventProperties: function getEventProperties(name, sortable) {
  742. var eventProperties = {};
  743. plugins.forEach(function (plugin) {
  744. if (typeof plugin.eventProperties !== 'function') return;
  745. _extends(eventProperties, plugin.eventProperties.call(sortable[plugin.pluginName], name));
  746. });
  747. return eventProperties;
  748. },
  749. modifyOption: function modifyOption(sortable, name, value) {
  750. var modifiedValue;
  751. plugins.forEach(function (plugin) {
  752. // Plugin must exist on the Sortable
  753. if (!sortable[plugin.pluginName]) return;
  754. // If static option listener exists for this option, call in the context of the Sortable's instance of this plugin
  755. if (plugin.optionListeners && typeof plugin.optionListeners[name] === 'function') {
  756. modifiedValue = plugin.optionListeners[name].call(sortable[plugin.pluginName], value);
  757. }
  758. });
  759. return modifiedValue;
  760. }
  761. };
  762. function dispatchEvent(_ref) {
  763. var sortable = _ref.sortable,
  764. rootEl = _ref.rootEl,
  765. name = _ref.name,
  766. targetEl = _ref.targetEl,
  767. cloneEl = _ref.cloneEl,
  768. toEl = _ref.toEl,
  769. fromEl = _ref.fromEl,
  770. oldIndex = _ref.oldIndex,
  771. newIndex = _ref.newIndex,
  772. oldDraggableIndex = _ref.oldDraggableIndex,
  773. newDraggableIndex = _ref.newDraggableIndex,
  774. originalEvent = _ref.originalEvent,
  775. putSortable = _ref.putSortable,
  776. extraEventProperties = _ref.extraEventProperties;
  777. sortable = sortable || rootEl && rootEl[expando];
  778. if (!sortable) return;
  779. var evt,
  780. options = sortable.options,
  781. onName = 'on' + name.charAt(0).toUpperCase() + name.substr(1);
  782. // Support for new CustomEvent feature
  783. if (window.CustomEvent && !IE11OrLess && !Edge) {
  784. evt = new CustomEvent(name, {
  785. bubbles: true,
  786. cancelable: true
  787. });
  788. } else {
  789. evt = document.createEvent('Event');
  790. evt.initEvent(name, true, true);
  791. }
  792. evt.to = toEl || rootEl;
  793. evt.from = fromEl || rootEl;
  794. evt.item = targetEl || rootEl;
  795. evt.clone = cloneEl;
  796. evt.oldIndex = oldIndex;
  797. evt.newIndex = newIndex;
  798. evt.oldDraggableIndex = oldDraggableIndex;
  799. evt.newDraggableIndex = newDraggableIndex;
  800. evt.originalEvent = originalEvent;
  801. evt.pullMode = putSortable ? putSortable.lastPutMode : undefined;
  802. var allEventProperties = _objectSpread2(_objectSpread2({}, extraEventProperties), PluginManager.getEventProperties(name, sortable));
  803. for (var option in allEventProperties) {
  804. evt[option] = allEventProperties[option];
  805. }
  806. if (rootEl) {
  807. rootEl.dispatchEvent(evt);
  808. }
  809. if (options[onName]) {
  810. options[onName].call(sortable, evt);
  811. }
  812. }
  813. var _excluded = ["evt"];
  814. var pluginEvent = function pluginEvent(eventName, sortable) {
  815. var _ref = arguments.length > 2 && arguments[2] !== undefined ? arguments[2] : {},
  816. originalEvent = _ref.evt,
  817. data = _objectWithoutProperties(_ref, _excluded);
  818. PluginManager.pluginEvent.bind(Sortable)(eventName, sortable, _objectSpread2({
  819. dragEl: dragEl,
  820. parentEl: parentEl,
  821. ghostEl: ghostEl,
  822. rootEl: rootEl,
  823. nextEl: nextEl,
  824. lastDownEl: lastDownEl,
  825. cloneEl: cloneEl,
  826. cloneHidden: cloneHidden,
  827. dragStarted: moved,
  828. putSortable: putSortable,
  829. activeSortable: Sortable.active,
  830. originalEvent: originalEvent,
  831. oldIndex: oldIndex,
  832. oldDraggableIndex: oldDraggableIndex,
  833. newIndex: newIndex,
  834. newDraggableIndex: newDraggableIndex,
  835. hideGhostForTarget: _hideGhostForTarget,
  836. unhideGhostForTarget: _unhideGhostForTarget,
  837. cloneNowHidden: function cloneNowHidden() {
  838. cloneHidden = true;
  839. },
  840. cloneNowShown: function cloneNowShown() {
  841. cloneHidden = false;
  842. },
  843. dispatchSortableEvent: function dispatchSortableEvent(name) {
  844. _dispatchEvent({
  845. sortable: sortable,
  846. name: name,
  847. originalEvent: originalEvent
  848. });
  849. }
  850. }, data));
  851. };
  852. function _dispatchEvent(info) {
  853. dispatchEvent(_objectSpread2({
  854. putSortable: putSortable,
  855. cloneEl: cloneEl,
  856. targetEl: dragEl,
  857. rootEl: rootEl,
  858. oldIndex: oldIndex,
  859. oldDraggableIndex: oldDraggableIndex,
  860. newIndex: newIndex,
  861. newDraggableIndex: newDraggableIndex
  862. }, info));
  863. }
  864. var dragEl,
  865. parentEl,
  866. ghostEl,
  867. rootEl,
  868. nextEl,
  869. lastDownEl,
  870. cloneEl,
  871. cloneHidden,
  872. oldIndex,
  873. newIndex,
  874. oldDraggableIndex,
  875. newDraggableIndex,
  876. activeGroup,
  877. putSortable,
  878. awaitingDragStarted = false,
  879. ignoreNextClick = false,
  880. sortables = [],
  881. tapEvt,
  882. touchEvt,
  883. lastDx,
  884. lastDy,
  885. tapDistanceLeft,
  886. tapDistanceTop,
  887. moved,
  888. lastTarget,
  889. lastDirection,
  890. pastFirstInvertThresh = false,
  891. isCircumstantialInvert = false,
  892. targetMoveDistance,
  893. // For positioning ghost absolutely
  894. ghostRelativeParent,
  895. ghostRelativeParentInitialScroll = [],
  896. // (left, top)
  897. _silent = false,
  898. savedInputChecked = [];
  899. /** @const */
  900. var documentExists = typeof document !== 'undefined',
  901. PositionGhostAbsolutely = IOS,
  902. CSSFloatProperty = Edge || IE11OrLess ? 'cssFloat' : 'float',
  903. // This will not pass for IE9, because IE9 DnD only works on anchors
  904. supportDraggable = documentExists && !ChromeForAndroid && !IOS && 'draggable' in document.createElement('div'),
  905. supportCssPointerEvents = function () {
  906. if (!documentExists) return;
  907. // false when <= IE11
  908. if (IE11OrLess) {
  909. return false;
  910. }
  911. var el = document.createElement('x');
  912. el.style.cssText = 'pointer-events:auto';
  913. return el.style.pointerEvents === 'auto';
  914. }(),
  915. _detectDirection = function _detectDirection(el, options) {
  916. var elCSS = css(el),
  917. elWidth = parseInt(elCSS.width) - parseInt(elCSS.paddingLeft) - parseInt(elCSS.paddingRight) - parseInt(elCSS.borderLeftWidth) - parseInt(elCSS.borderRightWidth),
  918. child1 = getChild(el, 0, options),
  919. child2 = getChild(el, 1, options),
  920. firstChildCSS = child1 && css(child1),
  921. secondChildCSS = child2 && css(child2),
  922. firstChildWidth = firstChildCSS && parseInt(firstChildCSS.marginLeft) + parseInt(firstChildCSS.marginRight) + getRect(child1).width,
  923. secondChildWidth = secondChildCSS && parseInt(secondChildCSS.marginLeft) + parseInt(secondChildCSS.marginRight) + getRect(child2).width;
  924. if (elCSS.display === 'flex') {
  925. return elCSS.flexDirection === 'column' || elCSS.flexDirection === 'column-reverse' ? 'vertical' : 'horizontal';
  926. }
  927. if (elCSS.display === 'grid') {
  928. return elCSS.gridTemplateColumns.split(' ').length <= 1 ? 'vertical' : 'horizontal';
  929. }
  930. if (child1 && firstChildCSS["float"] && firstChildCSS["float"] !== 'none') {
  931. var touchingSideChild2 = firstChildCSS["float"] === 'left' ? 'left' : 'right';
  932. return child2 && (secondChildCSS.clear === 'both' || secondChildCSS.clear === touchingSideChild2) ? 'vertical' : 'horizontal';
  933. }
  934. return child1 && (firstChildCSS.display === 'block' || firstChildCSS.display === 'flex' || firstChildCSS.display === 'table' || firstChildCSS.display === 'grid' || firstChildWidth >= elWidth && elCSS[CSSFloatProperty] === 'none' || child2 && elCSS[CSSFloatProperty] === 'none' && firstChildWidth + secondChildWidth > elWidth) ? 'vertical' : 'horizontal';
  935. },
  936. _dragElInRowColumn = function _dragElInRowColumn(dragRect, targetRect, vertical) {
  937. var dragElS1Opp = vertical ? dragRect.left : dragRect.top,
  938. dragElS2Opp = vertical ? dragRect.right : dragRect.bottom,
  939. dragElOppLength = vertical ? dragRect.width : dragRect.height,
  940. targetS1Opp = vertical ? targetRect.left : targetRect.top,
  941. targetS2Opp = vertical ? targetRect.right : targetRect.bottom,
  942. targetOppLength = vertical ? targetRect.width : targetRect.height;
  943. return dragElS1Opp === targetS1Opp || dragElS2Opp === targetS2Opp || dragElS1Opp + dragElOppLength / 2 === targetS1Opp + targetOppLength / 2;
  944. },
  945. /**
  946. * Detects first nearest empty sortable to X and Y position using emptyInsertThreshold.
  947. * @param {Number} x X position
  948. * @param {Number} y Y position
  949. * @return {HTMLElement} Element of the first found nearest Sortable
  950. */
  951. _detectNearestEmptySortable = function _detectNearestEmptySortable(x, y) {
  952. var ret;
  953. sortables.some(function (sortable) {
  954. var threshold = sortable[expando].options.emptyInsertThreshold;
  955. if (!threshold || lastChild(sortable)) return;
  956. var rect = getRect(sortable),
  957. insideHorizontally = x >= rect.left - threshold && x <= rect.right + threshold,
  958. insideVertically = y >= rect.top - threshold && y <= rect.bottom + threshold;
  959. if (insideHorizontally && insideVertically) {
  960. return ret = sortable;
  961. }
  962. });
  963. return ret;
  964. },
  965. _prepareGroup = function _prepareGroup(options) {
  966. function toFn(value, pull) {
  967. return function (to, from, dragEl, evt) {
  968. var sameGroup = to.options.group.name && from.options.group.name && to.options.group.name === from.options.group.name;
  969. if (value == null && (pull || sameGroup)) {
  970. // Default pull value
  971. // Default pull and put value if same group
  972. return true;
  973. } else if (value == null || value === false) {
  974. return false;
  975. } else if (pull && value === 'clone') {
  976. return value;
  977. } else if (typeof value === 'function') {
  978. return toFn(value(to, from, dragEl, evt), pull)(to, from, dragEl, evt);
  979. } else {
  980. var otherGroup = (pull ? to : from).options.group.name;
  981. return value === true || typeof value === 'string' && value === otherGroup || value.join && value.indexOf(otherGroup) > -1;
  982. }
  983. };
  984. }
  985. var group = {};
  986. var originalGroup = options.group;
  987. if (!originalGroup || _typeof(originalGroup) != 'object') {
  988. originalGroup = {
  989. name: originalGroup
  990. };
  991. }
  992. group.name = originalGroup.name;
  993. group.checkPull = toFn(originalGroup.pull, true);
  994. group.checkPut = toFn(originalGroup.put);
  995. group.revertClone = originalGroup.revertClone;
  996. options.group = group;
  997. },
  998. _hideGhostForTarget = function _hideGhostForTarget() {
  999. if (!supportCssPointerEvents && ghostEl) {
  1000. css(ghostEl, 'display', 'none');
  1001. }
  1002. },
  1003. _unhideGhostForTarget = function _unhideGhostForTarget() {
  1004. if (!supportCssPointerEvents && ghostEl) {
  1005. css(ghostEl, 'display', '');
  1006. }
  1007. };
  1008. // #1184 fix - Prevent click event on fallback if dragged but item not changed position
  1009. if (documentExists && !ChromeForAndroid) {
  1010. document.addEventListener('click', function (evt) {
  1011. if (ignoreNextClick) {
  1012. evt.preventDefault();
  1013. evt.stopPropagation && evt.stopPropagation();
  1014. evt.stopImmediatePropagation && evt.stopImmediatePropagation();
  1015. ignoreNextClick = false;
  1016. return false;
  1017. }
  1018. }, true);
  1019. }
  1020. var nearestEmptyInsertDetectEvent = function nearestEmptyInsertDetectEvent(evt) {
  1021. if (dragEl) {
  1022. evt = evt.touches ? evt.touches[0] : evt;
  1023. var nearest = _detectNearestEmptySortable(evt.clientX, evt.clientY);
  1024. if (nearest) {
  1025. // Create imitation event
  1026. var event = {};
  1027. for (var i in evt) {
  1028. if (evt.hasOwnProperty(i)) {
  1029. event[i] = evt[i];
  1030. }
  1031. }
  1032. event.target = event.rootEl = nearest;
  1033. event.preventDefault = void 0;
  1034. event.stopPropagation = void 0;
  1035. nearest[expando]._onDragOver(event);
  1036. }
  1037. }
  1038. };
  1039. var _checkOutsideTargetEl = function _checkOutsideTargetEl(evt) {
  1040. if (dragEl) {
  1041. dragEl.parentNode[expando]._isOutsideThisEl(evt.target);
  1042. }
  1043. };
  1044. /**
  1045. * @class Sortable
  1046. * @param {HTMLElement} el
  1047. * @param {Object} [options]
  1048. */
  1049. function Sortable(el, options) {
  1050. if (!(el && el.nodeType && el.nodeType === 1)) {
  1051. throw "Sortable: `el` must be an HTMLElement, not ".concat({}.toString.call(el));
  1052. }
  1053. this.el = el; // root element
  1054. this.options = options = _extends({}, options);
  1055. // Export instance
  1056. el[expando] = this;
  1057. var defaults = {
  1058. group: null,
  1059. sort: true,
  1060. disabled: false,
  1061. store: null,
  1062. handle: null,
  1063. draggable: /^[uo]l$/i.test(el.nodeName) ? '>li' : '>*',
  1064. swapThreshold: 1,
  1065. // percentage; 0 <= x <= 1
  1066. invertSwap: false,
  1067. // invert always
  1068. invertedSwapThreshold: null,
  1069. // will be set to same as swapThreshold if default
  1070. removeCloneOnHide: true,
  1071. direction: function direction() {
  1072. return _detectDirection(el, this.options);
  1073. },
  1074. ghostClass: 'sortable-ghost',
  1075. chosenClass: 'sortable-chosen',
  1076. dragClass: 'sortable-drag',
  1077. ignore: 'a, img',
  1078. filter: null,
  1079. preventOnFilter: true,
  1080. animation: 0,
  1081. easing: null,
  1082. setData: function setData(dataTransfer, dragEl) {
  1083. dataTransfer.setData('Text', dragEl.textContent);
  1084. },
  1085. dropBubble: false,
  1086. dragoverBubble: false,
  1087. dataIdAttr: 'data-id',
  1088. delay: 0,
  1089. delayOnTouchOnly: false,
  1090. touchStartThreshold: (Number.parseInt ? Number : window).parseInt(window.devicePixelRatio, 10) || 1,
  1091. forceFallback: false,
  1092. fallbackClass: 'sortable-fallback',
  1093. fallbackOnBody: false,
  1094. fallbackTolerance: 0,
  1095. fallbackOffset: {
  1096. x: 0,
  1097. y: 0
  1098. },
  1099. // Disabled on Safari: #1571; Enabled on Safari IOS: #2244
  1100. supportPointer: Sortable.supportPointer !== false && 'PointerEvent' in window && (!Safari || IOS),
  1101. emptyInsertThreshold: 5
  1102. };
  1103. PluginManager.initializePlugins(this, el, defaults);
  1104. // Set default options
  1105. for (var name in defaults) {
  1106. !(name in options) && (options[name] = defaults[name]);
  1107. }
  1108. _prepareGroup(options);
  1109. // Bind all private methods
  1110. for (var fn in this) {
  1111. if (fn.charAt(0) === '_' && typeof this[fn] === 'function') {
  1112. this[fn] = this[fn].bind(this);
  1113. }
  1114. }
  1115. // Setup drag mode
  1116. this.nativeDraggable = options.forceFallback ? false : supportDraggable;
  1117. if (this.nativeDraggable) {
  1118. // Touch start threshold cannot be greater than the native dragstart threshold
  1119. this.options.touchStartThreshold = 1;
  1120. }
  1121. // Bind events
  1122. if (options.supportPointer) {
  1123. on(el, 'pointerdown', this._onTapStart);
  1124. } else {
  1125. on(el, 'mousedown', this._onTapStart);
  1126. on(el, 'touchstart', this._onTapStart);
  1127. }
  1128. if (this.nativeDraggable) {
  1129. on(el, 'dragover', this);
  1130. on(el, 'dragenter', this);
  1131. }
  1132. sortables.push(this.el);
  1133. // Restore sorting
  1134. options.store && options.store.get && this.sort(options.store.get(this) || []);
  1135. // Add animation state manager
  1136. _extends(this, AnimationStateManager());
  1137. }
  1138. Sortable.prototype = /** @lends Sortable.prototype */{
  1139. constructor: Sortable,
  1140. _isOutsideThisEl: function _isOutsideThisEl(target) {
  1141. if (!this.el.contains(target) && target !== this.el) {
  1142. lastTarget = null;
  1143. }
  1144. },
  1145. _getDirection: function _getDirection(evt, target) {
  1146. return typeof this.options.direction === 'function' ? this.options.direction.call(this, evt, target, dragEl) : this.options.direction;
  1147. },
  1148. _onTapStart: function _onTapStart( /** Event|TouchEvent */evt) {
  1149. if (!evt.cancelable) return;
  1150. var _this = this,
  1151. el = this.el,
  1152. options = this.options,
  1153. preventOnFilter = options.preventOnFilter,
  1154. type = evt.type,
  1155. touch = evt.touches && evt.touches[0] || evt.pointerType && evt.pointerType === 'touch' && evt,
  1156. target = (touch || evt).target,
  1157. originalTarget = evt.target.shadowRoot && (evt.path && evt.path[0] || evt.composedPath && evt.composedPath()[0]) || target,
  1158. filter = options.filter;
  1159. _saveInputCheckedState(el);
  1160. // Don't trigger start event when an element is been dragged, otherwise the evt.oldindex always wrong when set option.group.
  1161. if (dragEl) {
  1162. return;
  1163. }
  1164. if (/mousedown|pointerdown/.test(type) && evt.button !== 0 || options.disabled) {
  1165. return; // only left button and enabled
  1166. }
  1167. // cancel dnd if original target is content editable
  1168. if (originalTarget.isContentEditable) {
  1169. return;
  1170. }
  1171. // Safari ignores further event handling after mousedown
  1172. if (!this.nativeDraggable && Safari && target && target.tagName.toUpperCase() === 'SELECT') {
  1173. return;
  1174. }
  1175. target = closest(target, options.draggable, el, false);
  1176. if (target && target.animated) {
  1177. return;
  1178. }
  1179. if (lastDownEl === target) {
  1180. // Ignoring duplicate `down`
  1181. return;
  1182. }
  1183. // Get the index of the dragged element within its parent
  1184. oldIndex = index(target);
  1185. oldDraggableIndex = index(target, options.draggable);
  1186. // Check filter
  1187. if (typeof filter === 'function') {
  1188. if (filter.call(this, evt, target, this)) {
  1189. _dispatchEvent({
  1190. sortable: _this,
  1191. rootEl: originalTarget,
  1192. name: 'filter',
  1193. targetEl: target,
  1194. toEl: el,
  1195. fromEl: el
  1196. });
  1197. pluginEvent('filter', _this, {
  1198. evt: evt
  1199. });
  1200. preventOnFilter && evt.preventDefault();
  1201. return; // cancel dnd
  1202. }
  1203. } else if (filter) {
  1204. filter = filter.split(',').some(function (criteria) {
  1205. criteria = closest(originalTarget, criteria.trim(), el, false);
  1206. if (criteria) {
  1207. _dispatchEvent({
  1208. sortable: _this,
  1209. rootEl: criteria,
  1210. name: 'filter',
  1211. targetEl: target,
  1212. fromEl: el,
  1213. toEl: el
  1214. });
  1215. pluginEvent('filter', _this, {
  1216. evt: evt
  1217. });
  1218. return true;
  1219. }
  1220. });
  1221. if (filter) {
  1222. preventOnFilter && evt.preventDefault();
  1223. return; // cancel dnd
  1224. }
  1225. }
  1226. if (options.handle && !closest(originalTarget, options.handle, el, false)) {
  1227. return;
  1228. }
  1229. // Prepare `dragstart`
  1230. this._prepareDragStart(evt, touch, target);
  1231. },
  1232. _prepareDragStart: function _prepareDragStart( /** Event */evt, /** Touch */touch, /** HTMLElement */target) {
  1233. var _this = this,
  1234. el = _this.el,
  1235. options = _this.options,
  1236. ownerDocument = el.ownerDocument,
  1237. dragStartFn;
  1238. if (target && !dragEl && target.parentNode === el) {
  1239. var dragRect = getRect(target);
  1240. rootEl = el;
  1241. dragEl = target;
  1242. parentEl = dragEl.parentNode;
  1243. nextEl = dragEl.nextSibling;
  1244. lastDownEl = target;
  1245. activeGroup = options.group;
  1246. Sortable.dragged = dragEl;
  1247. tapEvt = {
  1248. target: dragEl,
  1249. clientX: (touch || evt).clientX,
  1250. clientY: (touch || evt).clientY
  1251. };
  1252. tapDistanceLeft = tapEvt.clientX - dragRect.left;
  1253. tapDistanceTop = tapEvt.clientY - dragRect.top;
  1254. this._lastX = (touch || evt).clientX;
  1255. this._lastY = (touch || evt).clientY;
  1256. dragEl.style['will-change'] = 'all';
  1257. dragStartFn = function dragStartFn() {
  1258. pluginEvent('delayEnded', _this, {
  1259. evt: evt
  1260. });
  1261. if (Sortable.eventCanceled) {
  1262. _this._onDrop();
  1263. return;
  1264. }
  1265. // Delayed drag has been triggered
  1266. // we can re-enable the events: touchmove/mousemove
  1267. _this._disableDelayedDragEvents();
  1268. if (!FireFox && _this.nativeDraggable) {
  1269. dragEl.draggable = true;
  1270. }
  1271. // Bind the events: dragstart/dragend
  1272. _this._triggerDragStart(evt, touch);
  1273. // Drag start event
  1274. _dispatchEvent({
  1275. sortable: _this,
  1276. name: 'choose',
  1277. originalEvent: evt
  1278. });
  1279. // Chosen item
  1280. toggleClass(dragEl, options.chosenClass, true);
  1281. };
  1282. // Disable "draggable"
  1283. options.ignore.split(',').forEach(function (criteria) {
  1284. find(dragEl, criteria.trim(), _disableDraggable);
  1285. });
  1286. on(ownerDocument, 'dragover', nearestEmptyInsertDetectEvent);
  1287. on(ownerDocument, 'mousemove', nearestEmptyInsertDetectEvent);
  1288. on(ownerDocument, 'touchmove', nearestEmptyInsertDetectEvent);
  1289. if (options.supportPointer) {
  1290. on(ownerDocument, 'pointerup', _this._onDrop);
  1291. // Native D&D triggers pointercancel
  1292. !this.nativeDraggable && on(ownerDocument, 'pointercancel', _this._onDrop);
  1293. } else {
  1294. on(ownerDocument, 'mouseup', _this._onDrop);
  1295. on(ownerDocument, 'touchend', _this._onDrop);
  1296. on(ownerDocument, 'touchcancel', _this._onDrop);
  1297. }
  1298. // Make dragEl draggable (must be before delay for FireFox)
  1299. if (FireFox && this.nativeDraggable) {
  1300. this.options.touchStartThreshold = 4;
  1301. dragEl.draggable = true;
  1302. }
  1303. pluginEvent('delayStart', this, {
  1304. evt: evt
  1305. });
  1306. // Delay is impossible for native DnD in Edge or IE
  1307. if (options.delay && (!options.delayOnTouchOnly || touch) && (!this.nativeDraggable || !(Edge || IE11OrLess))) {
  1308. if (Sortable.eventCanceled) {
  1309. this._onDrop();
  1310. return;
  1311. }
  1312. // If the user moves the pointer or let go the click or touch
  1313. // before the delay has been reached:
  1314. // disable the delayed drag
  1315. if (options.supportPointer) {
  1316. on(ownerDocument, 'pointerup', _this._disableDelayedDrag);
  1317. on(ownerDocument, 'pointercancel', _this._disableDelayedDrag);
  1318. } else {
  1319. on(ownerDocument, 'mouseup', _this._disableDelayedDrag);
  1320. on(ownerDocument, 'touchend', _this._disableDelayedDrag);
  1321. on(ownerDocument, 'touchcancel', _this._disableDelayedDrag);
  1322. }
  1323. on(ownerDocument, 'mousemove', _this._delayedDragTouchMoveHandler);
  1324. on(ownerDocument, 'touchmove', _this._delayedDragTouchMoveHandler);
  1325. options.supportPointer && on(ownerDocument, 'pointermove', _this._delayedDragTouchMoveHandler);
  1326. _this._dragStartTimer = setTimeout(dragStartFn, options.delay);
  1327. } else {
  1328. dragStartFn();
  1329. }
  1330. }
  1331. },
  1332. _delayedDragTouchMoveHandler: function _delayedDragTouchMoveHandler( /** TouchEvent|PointerEvent **/e) {
  1333. var touch = e.touches ? e.touches[0] : e;
  1334. if (Math.max(Math.abs(touch.clientX - this._lastX), Math.abs(touch.clientY - this._lastY)) >= Math.floor(this.options.touchStartThreshold / (this.nativeDraggable && window.devicePixelRatio || 1))) {
  1335. this._disableDelayedDrag();
  1336. }
  1337. },
  1338. _disableDelayedDrag: function _disableDelayedDrag() {
  1339. dragEl && _disableDraggable(dragEl);
  1340. clearTimeout(this._dragStartTimer);
  1341. this._disableDelayedDragEvents();
  1342. },
  1343. _disableDelayedDragEvents: function _disableDelayedDragEvents() {
  1344. var ownerDocument = this.el.ownerDocument;
  1345. off(ownerDocument, 'mouseup', this._disableDelayedDrag);
  1346. off(ownerDocument, 'touchend', this._disableDelayedDrag);
  1347. off(ownerDocument, 'touchcancel', this._disableDelayedDrag);
  1348. off(ownerDocument, 'pointerup', this._disableDelayedDrag);
  1349. off(ownerDocument, 'pointercancel', this._disableDelayedDrag);
  1350. off(ownerDocument, 'mousemove', this._delayedDragTouchMoveHandler);
  1351. off(ownerDocument, 'touchmove', this._delayedDragTouchMoveHandler);
  1352. off(ownerDocument, 'pointermove', this._delayedDragTouchMoveHandler);
  1353. },
  1354. _triggerDragStart: function _triggerDragStart( /** Event */evt, /** Touch */touch) {
  1355. touch = touch || evt.pointerType == 'touch' && evt;
  1356. if (!this.nativeDraggable || touch) {
  1357. if (this.options.supportPointer) {
  1358. on(document, 'pointermove', this._onTouchMove);
  1359. } else if (touch) {
  1360. on(document, 'touchmove', this._onTouchMove);
  1361. } else {
  1362. on(document, 'mousemove', this._onTouchMove);
  1363. }
  1364. } else {
  1365. on(dragEl, 'dragend', this);
  1366. on(rootEl, 'dragstart', this._onDragStart);
  1367. }
  1368. try {
  1369. if (document.selection) {
  1370. _nextTick(function () {
  1371. document.selection.empty();
  1372. });
  1373. } else {
  1374. window.getSelection().removeAllRanges();
  1375. }
  1376. } catch (err) {}
  1377. },
  1378. _dragStarted: function _dragStarted(fallback, evt) {
  1379. awaitingDragStarted = false;
  1380. if (rootEl && dragEl) {
  1381. pluginEvent('dragStarted', this, {
  1382. evt: evt
  1383. });
  1384. if (this.nativeDraggable) {
  1385. on(document, 'dragover', _checkOutsideTargetEl);
  1386. }
  1387. var options = this.options;
  1388. // Apply effect
  1389. !fallback && toggleClass(dragEl, options.dragClass, false);
  1390. toggleClass(dragEl, options.ghostClass, true);
  1391. Sortable.active = this;
  1392. fallback && this._appendGhost();
  1393. // Drag start event
  1394. _dispatchEvent({
  1395. sortable: this,
  1396. name: 'start',
  1397. originalEvent: evt
  1398. });
  1399. } else {
  1400. this._nulling();
  1401. }
  1402. },
  1403. _emulateDragOver: function _emulateDragOver() {
  1404. if (touchEvt) {
  1405. this._lastX = touchEvt.clientX;
  1406. this._lastY = touchEvt.clientY;
  1407. _hideGhostForTarget();
  1408. var target = document.elementFromPoint(touchEvt.clientX, touchEvt.clientY);
  1409. var parent = target;
  1410. while (target && target.shadowRoot) {
  1411. target = target.shadowRoot.elementFromPoint(touchEvt.clientX, touchEvt.clientY);
  1412. if (target === parent) break;
  1413. parent = target;
  1414. }
  1415. dragEl.parentNode[expando]._isOutsideThisEl(target);
  1416. if (parent) {
  1417. do {
  1418. if (parent[expando]) {
  1419. var inserted = void 0;
  1420. inserted = parent[expando]._onDragOver({
  1421. clientX: touchEvt.clientX,
  1422. clientY: touchEvt.clientY,
  1423. target: target,
  1424. rootEl: parent
  1425. });
  1426. if (inserted && !this.options.dragoverBubble) {
  1427. break;
  1428. }
  1429. }
  1430. target = parent; // store last element
  1431. }
  1432. /* jshint boss:true */ while (parent = getParentOrHost(parent));
  1433. }
  1434. _unhideGhostForTarget();
  1435. }
  1436. },
  1437. _onTouchMove: function _onTouchMove( /**TouchEvent*/evt) {
  1438. if (tapEvt) {
  1439. var options = this.options,
  1440. fallbackTolerance = options.fallbackTolerance,
  1441. fallbackOffset = options.fallbackOffset,
  1442. touch = evt.touches ? evt.touches[0] : evt,
  1443. ghostMatrix = ghostEl && matrix(ghostEl, true),
  1444. scaleX = ghostEl && ghostMatrix && ghostMatrix.a,
  1445. scaleY = ghostEl && ghostMatrix && ghostMatrix.d,
  1446. relativeScrollOffset = PositionGhostAbsolutely && ghostRelativeParent && getRelativeScrollOffset(ghostRelativeParent),
  1447. dx = (touch.clientX - tapEvt.clientX + fallbackOffset.x) / (scaleX || 1) + (relativeScrollOffset ? relativeScrollOffset[0] - ghostRelativeParentInitialScroll[0] : 0) / (scaleX || 1),
  1448. dy = (touch.clientY - tapEvt.clientY + fallbackOffset.y) / (scaleY || 1) + (relativeScrollOffset ? relativeScrollOffset[1] - ghostRelativeParentInitialScroll[1] : 0) / (scaleY || 1);
  1449. // only set the status to dragging, when we are actually dragging
  1450. if (!Sortable.active && !awaitingDragStarted) {
  1451. if (fallbackTolerance && Math.max(Math.abs(touch.clientX - this._lastX), Math.abs(touch.clientY - this._lastY)) < fallbackTolerance) {
  1452. return;
  1453. }
  1454. this._onDragStart(evt, true);
  1455. }
  1456. if (ghostEl) {
  1457. if (ghostMatrix) {
  1458. ghostMatrix.e += dx - (lastDx || 0);
  1459. ghostMatrix.f += dy - (lastDy || 0);
  1460. } else {
  1461. ghostMatrix = {
  1462. a: 1,
  1463. b: 0,
  1464. c: 0,
  1465. d: 1,
  1466. e: dx,
  1467. f: dy
  1468. };
  1469. }
  1470. var cssMatrix = "matrix(".concat(ghostMatrix.a, ",").concat(ghostMatrix.b, ",").concat(ghostMatrix.c, ",").concat(ghostMatrix.d, ",").concat(ghostMatrix.e, ",").concat(ghostMatrix.f, ")");
  1471. css(ghostEl, 'webkitTransform', cssMatrix);
  1472. css(ghostEl, 'mozTransform', cssMatrix);
  1473. css(ghostEl, 'msTransform', cssMatrix);
  1474. css(ghostEl, 'transform', cssMatrix);
  1475. lastDx = dx;
  1476. lastDy = dy;
  1477. touchEvt = touch;
  1478. }
  1479. evt.cancelable && evt.preventDefault();
  1480. }
  1481. },
  1482. _appendGhost: function _appendGhost() {
  1483. // Bug if using scale(): https://stackoverflow.com/questions/2637058
  1484. // Not being adjusted for
  1485. if (!ghostEl) {
  1486. var container = this.options.fallbackOnBody ? document.body : rootEl,
  1487. rect = getRect(dragEl, true, PositionGhostAbsolutely, true, container),
  1488. options = this.options;
  1489. // Position absolutely
  1490. if (PositionGhostAbsolutely) {
  1491. // Get relatively positioned parent
  1492. ghostRelativeParent = container;
  1493. while (css(ghostRelativeParent, 'position') === 'static' && css(ghostRelativeParent, 'transform') === 'none' && ghostRelativeParent !== document) {
  1494. ghostRelativeParent = ghostRelativeParent.parentNode;
  1495. }
  1496. if (ghostRelativeParent !== document.body && ghostRelativeParent !== document.documentElement) {
  1497. if (ghostRelativeParent === document) ghostRelativeParent = getWindowScrollingElement();
  1498. rect.top += ghostRelativeParent.scrollTop;
  1499. rect.left += ghostRelativeParent.scrollLeft;
  1500. } else {
  1501. ghostRelativeParent = getWindowScrollingElement();
  1502. }
  1503. ghostRelativeParentInitialScroll = getRelativeScrollOffset(ghostRelativeParent);
  1504. }
  1505. ghostEl = dragEl.cloneNode(true);
  1506. toggleClass(ghostEl, options.ghostClass, false);
  1507. toggleClass(ghostEl, options.fallbackClass, true);
  1508. toggleClass(ghostEl, options.dragClass, true);
  1509. css(ghostEl, 'transition', '');
  1510. css(ghostEl, 'transform', '');
  1511. css(ghostEl, 'box-sizing', 'border-box');
  1512. css(ghostEl, 'margin', 0);
  1513. css(ghostEl, 'top', rect.top);
  1514. css(ghostEl, 'left', rect.left);
  1515. css(ghostEl, 'width', rect.width);
  1516. css(ghostEl, 'height', rect.height);
  1517. css(ghostEl, 'opacity', '0.8');
  1518. css(ghostEl, 'position', PositionGhostAbsolutely ? 'absolute' : 'fixed');
  1519. css(ghostEl, 'zIndex', '100000');
  1520. css(ghostEl, 'pointerEvents', 'none');
  1521. Sortable.ghost = ghostEl;
  1522. container.appendChild(ghostEl);
  1523. // Set transform-origin
  1524. css(ghostEl, 'transform-origin', tapDistanceLeft / parseInt(ghostEl.style.width) * 100 + '% ' + tapDistanceTop / parseInt(ghostEl.style.height) * 100 + '%');
  1525. }
  1526. },
  1527. _onDragStart: function _onDragStart( /**Event*/evt, /**boolean*/fallback) {
  1528. var _this = this;
  1529. var dataTransfer = evt.dataTransfer;
  1530. var options = _this.options;
  1531. pluginEvent('dragStart', this, {
  1532. evt: evt
  1533. });
  1534. if (Sortable.eventCanceled) {
  1535. this._onDrop();
  1536. return;
  1537. }
  1538. pluginEvent('setupClone', this);
  1539. if (!Sortable.eventCanceled) {
  1540. cloneEl = clone(dragEl);
  1541. cloneEl.removeAttribute("id");
  1542. cloneEl.draggable = false;
  1543. cloneEl.style['will-change'] = '';
  1544. this._hideClone();
  1545. toggleClass(cloneEl, this.options.chosenClass, false);
  1546. Sortable.clone = cloneEl;
  1547. }
  1548. // #1143: IFrame support workaround
  1549. _this.cloneId = _nextTick(function () {
  1550. pluginEvent('clone', _this);
  1551. if (Sortable.eventCanceled) return;
  1552. if (!_this.options.removeCloneOnHide) {
  1553. rootEl.insertBefore(cloneEl, dragEl);
  1554. }
  1555. _this._hideClone();
  1556. _dispatchEvent({
  1557. sortable: _this,
  1558. name: 'clone'
  1559. });
  1560. });
  1561. !fallback && toggleClass(dragEl, options.dragClass, true);
  1562. // Set proper drop events
  1563. if (fallback) {
  1564. ignoreNextClick = true;
  1565. _this._loopId = setInterval(_this._emulateDragOver, 50);
  1566. } else {
  1567. // Undo what was set in _prepareDragStart before drag started
  1568. off(document, 'mouseup', _this._onDrop);
  1569. off(document, 'touchend', _this._onDrop);
  1570. off(document, 'touchcancel', _this._onDrop);
  1571. if (dataTransfer) {
  1572. dataTransfer.effectAllowed = 'move';
  1573. options.setData && options.setData.call(_this, dataTransfer, dragEl);
  1574. }
  1575. on(document, 'drop', _this);
  1576. // #1276 fix:
  1577. css(dragEl, 'transform', 'translateZ(0)');
  1578. }
  1579. awaitingDragStarted = true;
  1580. _this._dragStartId = _nextTick(_this._dragStarted.bind(_this, fallback, evt));
  1581. on(document, 'selectstart', _this);
  1582. moved = true;
  1583. window.getSelection().removeAllRanges();
  1584. if (Safari) {
  1585. css(document.body, 'user-select', 'none');
  1586. }
  1587. },
  1588. // Returns true - if no further action is needed (either inserted or another condition)
  1589. _onDragOver: function _onDragOver( /**Event*/evt) {
  1590. var el = this.el,
  1591. target = evt.target,
  1592. dragRect,
  1593. targetRect,
  1594. revert,
  1595. options = this.options,
  1596. group = options.group,
  1597. activeSortable = Sortable.active,
  1598. isOwner = activeGroup === group,
  1599. canSort = options.sort,
  1600. fromSortable = putSortable || activeSortable,
  1601. vertical,
  1602. _this = this,
  1603. completedFired = false;
  1604. if (_silent) return;
  1605. function dragOverEvent(name, extra) {
  1606. pluginEvent(name, _this, _objectSpread2({
  1607. evt: evt,
  1608. isOwner: isOwner,
  1609. axis: vertical ? 'vertical' : 'horizontal',
  1610. revert: revert,
  1611. dragRect: dragRect,
  1612. targetRect: targetRect,
  1613. canSort: canSort,
  1614. fromSortable: fromSortable,
  1615. target: target,
  1616. completed: completed,
  1617. onMove: function onMove(target, after) {
  1618. return _onMove(rootEl, el, dragEl, dragRect, target, getRect(target), evt, after);
  1619. },
  1620. changed: changed
  1621. }, extra));
  1622. }
  1623. // Capture animation state
  1624. function capture() {
  1625. dragOverEvent('dragOverAnimationCapture');
  1626. _this.captureAnimationState();
  1627. if (_this !== fromSortable) {
  1628. fromSortable.captureAnimationState();
  1629. }
  1630. }
  1631. // Return invocation when dragEl is inserted (or completed)
  1632. function completed(insertion) {
  1633. dragOverEvent('dragOverCompleted', {
  1634. insertion: insertion
  1635. });
  1636. if (insertion) {
  1637. // Clones must be hidden before folding animation to capture dragRectAbsolute properly
  1638. if (isOwner) {
  1639. activeSortable._hideClone();
  1640. } else {
  1641. activeSortable._showClone(_this);
  1642. }
  1643. if (_this !== fromSortable) {
  1644. // Set ghost class to new sortable's ghost class
  1645. toggleClass(dragEl, putSortable ? putSortable.options.ghostClass : activeSortable.options.ghostClass, false);
  1646. toggleClass(dragEl, options.ghostClass, true);
  1647. }
  1648. if (putSortable !== _this && _this !== Sortable.active) {
  1649. putSortable = _this;
  1650. } else if (_this === Sortable.active && putSortable) {
  1651. putSortable = null;
  1652. }
  1653. // Animation
  1654. if (fromSortable === _this) {
  1655. _this._ignoreWhileAnimating = target;
  1656. }
  1657. _this.animateAll(function () {
  1658. dragOverEvent('dragOverAnimationComplete');
  1659. _this._ignoreWhileAnimating = null;
  1660. });
  1661. if (_this !== fromSortable) {
  1662. fromSortable.animateAll();
  1663. fromSortable._ignoreWhileAnimating = null;
  1664. }
  1665. }
  1666. // Null lastTarget if it is not inside a previously swapped element
  1667. if (target === dragEl && !dragEl.animated || target === el && !target.animated) {
  1668. lastTarget = null;
  1669. }
  1670. // no bubbling and not fallback
  1671. if (!options.dragoverBubble && !evt.rootEl && target !== document) {
  1672. dragEl.parentNode[expando]._isOutsideThisEl(evt.target);
  1673. // Do not detect for empty insert if already inserted
  1674. !insertion && nearestEmptyInsertDetectEvent(evt);
  1675. }
  1676. !options.dragoverBubble && evt.stopPropagation && evt.stopPropagation();
  1677. return completedFired = true;
  1678. }
  1679. // Call when dragEl has been inserted
  1680. function changed() {
  1681. newIndex = index(dragEl);
  1682. newDraggableIndex = index(dragEl, options.draggable);
  1683. _dispatchEvent({
  1684. sortable: _this,
  1685. name: 'change',
  1686. toEl: el,
  1687. newIndex: newIndex,
  1688. newDraggableIndex: newDraggableIndex,
  1689. originalEvent: evt
  1690. });
  1691. }
  1692. if (evt.preventDefault !== void 0) {
  1693. evt.cancelable && evt.preventDefault();
  1694. }
  1695. target = closest(target, options.draggable, el, true);
  1696. dragOverEvent('dragOver');
  1697. if (Sortable.eventCanceled) return completedFired;
  1698. if (dragEl.contains(evt.target) || target.animated && target.animatingX && target.animatingY || _this._ignoreWhileAnimating === target) {
  1699. return completed(false);
  1700. }
  1701. ignoreNextClick = false;
  1702. if (activeSortable && !options.disabled && (isOwner ? canSort || (revert = parentEl !== rootEl) // Reverting item into the original list
  1703. : putSortable === this || (this.lastPutMode = activeGroup.checkPull(this, activeSortable, dragEl, evt)) && group.checkPut(this, activeSortable, dragEl, evt))) {
  1704. vertical = this._getDirection(evt, target) === 'vertical';
  1705. dragRect = getRect(dragEl);
  1706. dragOverEvent('dragOverValid');
  1707. if (Sortable.eventCanceled) return completedFired;
  1708. if (revert) {
  1709. parentEl = rootEl; // actualization
  1710. capture();
  1711. this._hideClone();
  1712. dragOverEvent('revert');
  1713. if (!Sortable.eventCanceled) {
  1714. if (nextEl) {
  1715. rootEl.insertBefore(dragEl, nextEl);
  1716. } else {
  1717. rootEl.appendChild(dragEl);
  1718. }
  1719. }
  1720. return completed(true);
  1721. }
  1722. var elLastChild = lastChild(el, options.draggable);
  1723. if (!elLastChild || _ghostIsLast(evt, vertical, this) && !elLastChild.animated) {
  1724. // Insert to end of list
  1725. // If already at end of list: Do not insert
  1726. if (elLastChild === dragEl) {
  1727. return completed(false);
  1728. }
  1729. // if there is a last element, it is the target
  1730. if (elLastChild && el === evt.target) {
  1731. target = elLastChild;
  1732. }
  1733. if (target) {
  1734. targetRect = getRect(target);
  1735. }
  1736. if (_onMove(rootEl, el, dragEl, dragRect, target, targetRect, evt, !!target) !== false) {
  1737. capture();
  1738. if (elLastChild && elLastChild.nextSibling) {
  1739. // the last draggable element is not the last node
  1740. el.insertBefore(dragEl, elLastChild.nextSibling);
  1741. } else {
  1742. el.appendChild(dragEl);
  1743. }
  1744. parentEl = el; // actualization
  1745. changed();
  1746. return completed(true);
  1747. }
  1748. } else if (elLastChild && _ghostIsFirst(evt, vertical, this)) {
  1749. // Insert to start of list
  1750. var firstChild = getChild(el, 0, options, true);
  1751. if (firstChild === dragEl) {
  1752. return completed(false);
  1753. }
  1754. target = firstChild;
  1755. targetRect = getRect(target);
  1756. if (_onMove(rootEl, el, dragEl, dragRect, target, targetRect, evt, false) !== false) {
  1757. capture();
  1758. el.insertBefore(dragEl, firstChild);
  1759. parentEl = el; // actualization
  1760. changed();
  1761. return completed(true);
  1762. }
  1763. } else if (target.parentNode === el) {
  1764. targetRect = getRect(target);
  1765. var direction = 0,
  1766. targetBeforeFirstSwap,
  1767. differentLevel = dragEl.parentNode !== el,
  1768. differentRowCol = !_dragElInRowColumn(dragEl.animated && dragEl.toRect || dragRect, target.animated && target.toRect || targetRect, vertical),
  1769. side1 = vertical ? 'top' : 'left',
  1770. scrolledPastTop = isScrolledPast(target, 'top', 'top') || isScrolledPast(dragEl, 'top', 'top'),
  1771. scrollBefore = scrolledPastTop ? scrolledPastTop.scrollTop : void 0;
  1772. if (lastTarget !== target) {
  1773. targetBeforeFirstSwap = targetRect[side1];
  1774. pastFirstInvertThresh = false;
  1775. isCircumstantialInvert = !differentRowCol && options.invertSwap || differentLevel;
  1776. }
  1777. direction = _getSwapDirection(evt, target, targetRect, vertical, differentRowCol ? 1 : options.swapThreshold, options.invertedSwapThreshold == null ? options.swapThreshold : options.invertedSwapThreshold, isCircumstantialInvert, lastTarget === target);
  1778. var sibling;
  1779. if (direction !== 0) {
  1780. // Check if target is beside dragEl in respective direction (ignoring hidden elements)
  1781. var dragIndex = index(dragEl);
  1782. do {
  1783. dragIndex -= direction;
  1784. sibling = parentEl.children[dragIndex];
  1785. } while (sibling && (css(sibling, 'display') === 'none' || sibling === ghostEl));
  1786. }
  1787. // If dragEl is already beside target: Do not insert
  1788. if (direction === 0 || sibling === target) {
  1789. return completed(false);
  1790. }
  1791. lastTarget = target;
  1792. lastDirection = direction;
  1793. var nextSibling = target.nextElementSibling,
  1794. after = false;
  1795. after = direction === 1;
  1796. var moveVector = _onMove(rootEl, el, dragEl, dragRect, target, targetRect, evt, after);
  1797. if (moveVector !== false) {
  1798. if (moveVector === 1 || moveVector === -1) {
  1799. after = moveVector === 1;
  1800. }
  1801. _silent = true;
  1802. setTimeout(_unsilent, 30);
  1803. capture();
  1804. if (after && !nextSibling) {
  1805. el.appendChild(dragEl);
  1806. } else {
  1807. target.parentNode.insertBefore(dragEl, after ? nextSibling : target);
  1808. }
  1809. // Undo chrome's scroll adjustment (has no effect on other browsers)
  1810. if (scrolledPastTop) {
  1811. scrollBy(scrolledPastTop, 0, scrollBefore - scrolledPastTop.scrollTop);
  1812. }
  1813. parentEl = dragEl.parentNode; // actualization
  1814. // must be done before animation
  1815. if (targetBeforeFirstSwap !== undefined && !isCircumstantialInvert) {
  1816. targetMoveDistance = Math.abs(targetBeforeFirstSwap - getRect(target)[side1]);
  1817. }
  1818. changed();
  1819. return completed(true);
  1820. }
  1821. }
  1822. if (el.contains(dragEl)) {
  1823. return completed(false);
  1824. }
  1825. }
  1826. return false;
  1827. },
  1828. _ignoreWhileAnimating: null,
  1829. _offMoveEvents: function _offMoveEvents() {
  1830. off(document, 'mousemove', this._onTouchMove);
  1831. off(document, 'touchmove', this._onTouchMove);
  1832. off(document, 'pointermove', this._onTouchMove);
  1833. off(document, 'dragover', nearestEmptyInsertDetectEvent);
  1834. off(document, 'mousemove', nearestEmptyInsertDetectEvent);
  1835. off(document, 'touchmove', nearestEmptyInsertDetectEvent);
  1836. },
  1837. _offUpEvents: function _offUpEvents() {
  1838. var ownerDocument = this.el.ownerDocument;
  1839. off(ownerDocument, 'mouseup', this._onDrop);
  1840. off(ownerDocument, 'touchend', this._onDrop);
  1841. off(ownerDocument, 'pointerup', this._onDrop);
  1842. off(ownerDocument, 'pointercancel', this._onDrop);
  1843. off(ownerDocument, 'touchcancel', this._onDrop);
  1844. off(document, 'selectstart', this);
  1845. },
  1846. _onDrop: function _onDrop( /**Event*/evt) {
  1847. var el = this.el,
  1848. options = this.options;
  1849. // Get the index of the dragged element within its parent
  1850. newIndex = index(dragEl);
  1851. newDraggableIndex = index(dragEl, options.draggable);
  1852. pluginEvent('drop', this, {
  1853. evt: evt
  1854. });
  1855. parentEl = dragEl && dragEl.parentNode;
  1856. // Get again after plugin event
  1857. newIndex = index(dragEl);
  1858. newDraggableIndex = index(dragEl, options.draggable);
  1859. if (Sortable.eventCanceled) {
  1860. this._nulling();
  1861. return;
  1862. }
  1863. awaitingDragStarted = false;
  1864. isCircumstantialInvert = false;
  1865. pastFirstInvertThresh = false;
  1866. clearInterval(this._loopId);
  1867. clearTimeout(this._dragStartTimer);
  1868. _cancelNextTick(this.cloneId);
  1869. _cancelNextTick(this._dragStartId);
  1870. // Unbind events
  1871. if (this.nativeDraggable) {
  1872. off(document, 'drop', this);
  1873. off(el, 'dragstart', this._onDragStart);
  1874. }
  1875. this._offMoveEvents();
  1876. this._offUpEvents();
  1877. if (Safari) {
  1878. css(document.body, 'user-select', '');
  1879. }
  1880. css(dragEl, 'transform', '');
  1881. if (evt) {
  1882. if (moved) {
  1883. evt.cancelable && evt.preventDefault();
  1884. !options.dropBubble && evt.stopPropagation();
  1885. }
  1886. ghostEl && ghostEl.parentNode && ghostEl.parentNode.removeChild(ghostEl);
  1887. if (rootEl === parentEl || putSortable && putSortable.lastPutMode !== 'clone') {
  1888. // Remove clone(s)
  1889. cloneEl && cloneEl.parentNode && cloneEl.parentNode.removeChild(cloneEl);
  1890. }
  1891. if (dragEl) {
  1892. if (this.nativeDraggable) {
  1893. off(dragEl, 'dragend', this);
  1894. }
  1895. _disableDraggable(dragEl);
  1896. dragEl.style['will-change'] = '';
  1897. // Remove classes
  1898. // ghostClass is added in dragStarted
  1899. if (moved && !awaitingDragStarted) {
  1900. toggleClass(dragEl, putSortable ? putSortable.options.ghostClass : this.options.ghostClass, false);
  1901. }
  1902. toggleClass(dragEl, this.options.chosenClass, false);
  1903. // Drag stop event
  1904. _dispatchEvent({
  1905. sortable: this,
  1906. name: 'unchoose',
  1907. toEl: parentEl,
  1908. newIndex: null,
  1909. newDraggableIndex: null,
  1910. originalEvent: evt
  1911. });
  1912. if (rootEl !== parentEl) {
  1913. if (newIndex >= 0) {
  1914. // Add event
  1915. _dispatchEvent({
  1916. rootEl: parentEl,
  1917. name: 'add',
  1918. toEl: parentEl,
  1919. fromEl: rootEl,
  1920. originalEvent: evt
  1921. });
  1922. // Remove event
  1923. _dispatchEvent({
  1924. sortable: this,
  1925. name: 'remove',
  1926. toEl: parentEl,
  1927. originalEvent: evt
  1928. });
  1929. // drag from one list and drop into another
  1930. _dispatchEvent({
  1931. rootEl: parentEl,
  1932. name: 'sort',
  1933. toEl: parentEl,
  1934. fromEl: rootEl,
  1935. originalEvent: evt
  1936. });
  1937. _dispatchEvent({
  1938. sortable: this,
  1939. name: 'sort',
  1940. toEl: parentEl,
  1941. originalEvent: evt
  1942. });
  1943. }
  1944. putSortable && putSortable.save();
  1945. } else {
  1946. if (newIndex !== oldIndex) {
  1947. if (newIndex >= 0) {
  1948. // drag & drop within the same list
  1949. _dispatchEvent({
  1950. sortable: this,
  1951. name: 'update',
  1952. toEl: parentEl,
  1953. originalEvent: evt
  1954. });
  1955. _dispatchEvent({
  1956. sortable: this,
  1957. name: 'sort',
  1958. toEl: parentEl,
  1959. originalEvent: evt
  1960. });
  1961. }
  1962. }
  1963. }
  1964. if (Sortable.active) {
  1965. /* jshint eqnull:true */
  1966. if (newIndex == null || newIndex === -1) {
  1967. newIndex = oldIndex;
  1968. newDraggableIndex = oldDraggableIndex;
  1969. }
  1970. _dispatchEvent({
  1971. sortable: this,
  1972. name: 'end',
  1973. toEl: parentEl,
  1974. originalEvent: evt
  1975. });
  1976. // Save sorting
  1977. this.save();
  1978. }
  1979. }
  1980. }
  1981. this._nulling();
  1982. },
  1983. _nulling: function _nulling() {
  1984. pluginEvent('nulling', this);
  1985. rootEl = dragEl = parentEl = ghostEl = nextEl = cloneEl = lastDownEl = cloneHidden = tapEvt = touchEvt = moved = newIndex = newDraggableIndex = oldIndex = oldDraggableIndex = lastTarget = lastDirection = putSortable = activeGroup = Sortable.dragged = Sortable.ghost = Sortable.clone = Sortable.active = null;
  1986. savedInputChecked.forEach(function (el) {
  1987. el.checked = true;
  1988. });
  1989. savedInputChecked.length = lastDx = lastDy = 0;
  1990. },
  1991. handleEvent: function handleEvent( /**Event*/evt) {
  1992. switch (evt.type) {
  1993. case 'drop':
  1994. case 'dragend':
  1995. this._onDrop(evt);
  1996. break;
  1997. case 'dragenter':
  1998. case 'dragover':
  1999. if (dragEl) {
  2000. this._onDragOver(evt);
  2001. _globalDragOver(evt);
  2002. }
  2003. break;
  2004. case 'selectstart':
  2005. evt.preventDefault();
  2006. break;
  2007. }
  2008. },
  2009. /**
  2010. * Serializes the item into an array of string.
  2011. * @returns {String[]}
  2012. */
  2013. toArray: function toArray() {
  2014. var order = [],
  2015. el,
  2016. children = this.el.children,
  2017. i = 0,
  2018. n = children.length,
  2019. options = this.options;
  2020. for (; i < n; i++) {
  2021. el = children[i];
  2022. if (closest(el, options.draggable, this.el, false)) {
  2023. order.push(el.getAttribute(options.dataIdAttr) || _generateId(el));
  2024. }
  2025. }
  2026. return order;
  2027. },
  2028. /**
  2029. * Sorts the elements according to the array.
  2030. * @param {String[]} order order of the items
  2031. */
  2032. sort: function sort(order, useAnimation) {
  2033. var items = {},
  2034. rootEl = this.el;
  2035. this.toArray().forEach(function (id, i) {
  2036. var el = rootEl.children[i];
  2037. if (closest(el, this.options.draggable, rootEl, false)) {
  2038. items[id] = el;
  2039. }
  2040. }, this);
  2041. useAnimation && this.captureAnimationState();
  2042. order.forEach(function (id) {
  2043. if (items[id]) {
  2044. rootEl.removeChild(items[id]);
  2045. rootEl.appendChild(items[id]);
  2046. }
  2047. });
  2048. useAnimation && this.animateAll();
  2049. },
  2050. /**
  2051. * Save the current sorting
  2052. */
  2053. save: function save() {
  2054. var store = this.options.store;
  2055. store && store.set && store.set(this);
  2056. },
  2057. /**
  2058. * For each element in the set, get the first element that matches the selector by testing the element itself and traversing up through its ancestors in the DOM tree.
  2059. * @param {HTMLElement} el
  2060. * @param {String} [selector] default: `options.draggable`
  2061. * @returns {HTMLElement|null}
  2062. */
  2063. closest: function closest$1(el, selector) {
  2064. return closest(el, selector || this.options.draggable, this.el, false);
  2065. },
  2066. /**
  2067. * Set/get option
  2068. * @param {string} name
  2069. * @param {*} [value]
  2070. * @returns {*}
  2071. */
  2072. option: function option(name, value) {
  2073. var options = this.options;
  2074. if (value === void 0) {
  2075. return options[name];
  2076. } else {
  2077. var modifiedValue = PluginManager.modifyOption(this, name, value);
  2078. if (typeof modifiedValue !== 'undefined') {
  2079. options[name] = modifiedValue;
  2080. } else {
  2081. options[name] = value;
  2082. }
  2083. if (name === 'group') {
  2084. _prepareGroup(options);
  2085. }
  2086. }
  2087. },
  2088. /**
  2089. * Destroy
  2090. */
  2091. destroy: function destroy() {
  2092. pluginEvent('destroy', this);
  2093. var el = this.el;
  2094. el[expando] = null;
  2095. off(el, 'mousedown', this._onTapStart);
  2096. off(el, 'touchstart', this._onTapStart);
  2097. off(el, 'pointerdown', this._onTapStart);
  2098. if (this.nativeDraggable) {
  2099. off(el, 'dragover', this);
  2100. off(el, 'dragenter', this);
  2101. }
  2102. // Remove draggable attributes
  2103. Array.prototype.forEach.call(el.querySelectorAll('[draggable]'), function (el) {
  2104. el.removeAttribute('draggable');
  2105. });
  2106. this._onDrop();
  2107. this._disableDelayedDragEvents();
  2108. sortables.splice(sortables.indexOf(this.el), 1);
  2109. this.el = el = null;
  2110. },
  2111. _hideClone: function _hideClone() {
  2112. if (!cloneHidden) {
  2113. pluginEvent('hideClone', this);
  2114. if (Sortable.eventCanceled) return;
  2115. css(cloneEl, 'display', 'none');
  2116. if (this.options.removeCloneOnHide && cloneEl.parentNode) {
  2117. cloneEl.parentNode.removeChild(cloneEl);
  2118. }
  2119. cloneHidden = true;
  2120. }
  2121. },
  2122. _showClone: function _showClone(putSortable) {
  2123. if (putSortable.lastPutMode !== 'clone') {
  2124. this._hideClone();
  2125. return;
  2126. }
  2127. if (cloneHidden) {
  2128. pluginEvent('showClone', this);
  2129. if (Sortable.eventCanceled) return;
  2130. // show clone at dragEl or original position
  2131. if (dragEl.parentNode == rootEl && !this.options.group.revertClone) {
  2132. rootEl.insertBefore(cloneEl, dragEl);
  2133. } else if (nextEl) {
  2134. rootEl.insertBefore(cloneEl, nextEl);
  2135. } else {
  2136. rootEl.appendChild(cloneEl);
  2137. }
  2138. if (this.options.group.revertClone) {
  2139. this.animate(dragEl, cloneEl);
  2140. }
  2141. css(cloneEl, 'display', '');
  2142. cloneHidden = false;
  2143. }
  2144. }
  2145. };
  2146. function _globalDragOver( /**Event*/evt) {
  2147. if (evt.dataTransfer) {
  2148. evt.dataTransfer.dropEffect = 'move';
  2149. }
  2150. evt.cancelable && evt.preventDefault();
  2151. }
  2152. function _onMove(fromEl, toEl, dragEl, dragRect, targetEl, targetRect, originalEvent, willInsertAfter) {
  2153. var evt,
  2154. sortable = fromEl[expando],
  2155. onMoveFn = sortable.options.onMove,
  2156. retVal;
  2157. // Support for new CustomEvent feature
  2158. if (window.CustomEvent && !IE11OrLess && !Edge) {
  2159. evt = new CustomEvent('move', {
  2160. bubbles: true,
  2161. cancelable: true
  2162. });
  2163. } else {
  2164. evt = document.createEvent('Event');
  2165. evt.initEvent('move', true, true);
  2166. }
  2167. evt.to = toEl;
  2168. evt.from = fromEl;
  2169. evt.dragged = dragEl;
  2170. evt.draggedRect = dragRect;
  2171. evt.related = targetEl || toEl;
  2172. evt.relatedRect = targetRect || getRect(toEl);
  2173. evt.willInsertAfter = willInsertAfter;
  2174. evt.originalEvent = originalEvent;
  2175. fromEl.dispatchEvent(evt);
  2176. if (onMoveFn) {
  2177. retVal = onMoveFn.call(sortable, evt, originalEvent);
  2178. }
  2179. return retVal;
  2180. }
  2181. function _disableDraggable(el) {
  2182. el.draggable = false;
  2183. }
  2184. function _unsilent() {
  2185. _silent = false;
  2186. }
  2187. function _ghostIsFirst(evt, vertical, sortable) {
  2188. var firstElRect = getRect(getChild(sortable.el, 0, sortable.options, true));
  2189. var childContainingRect = getChildContainingRectFromElement(sortable.el, sortable.options, ghostEl);
  2190. var spacer = 10;
  2191. return vertical ? evt.clientX < childContainingRect.left - spacer || evt.clientY < firstElRect.top && evt.clientX < firstElRect.right : evt.clientY < childContainingRect.top - spacer || evt.clientY < firstElRect.bottom && evt.clientX < firstElRect.left;
  2192. }
  2193. function _ghostIsLast(evt, vertical, sortable) {
  2194. var lastElRect = getRect(lastChild(sortable.el, sortable.options.draggable));
  2195. var childContainingRect = getChildContainingRectFromElement(sortable.el, sortable.options, ghostEl);
  2196. var spacer = 10;
  2197. return vertical ? evt.clientX > childContainingRect.right + spacer || evt.clientY > lastElRect.bottom && evt.clientX > lastElRect.left : evt.clientY > childContainingRect.bottom + spacer || evt.clientX > lastElRect.right && evt.clientY > lastElRect.top;
  2198. }
  2199. function _getSwapDirection(evt, target, targetRect, vertical, swapThreshold, invertedSwapThreshold, invertSwap, isLastTarget) {
  2200. var mouseOnAxis = vertical ? evt.clientY : evt.clientX,
  2201. targetLength = vertical ? targetRect.height : targetRect.width,
  2202. targetS1 = vertical ? targetRect.top : targetRect.left,
  2203. targetS2 = vertical ? targetRect.bottom : targetRect.right,
  2204. invert = false;
  2205. if (!invertSwap) {
  2206. // Never invert or create dragEl shadow when target movemenet causes mouse to move past the end of regular swapThreshold
  2207. if (isLastTarget && targetMoveDistance < targetLength * swapThreshold) {
  2208. // multiplied only by swapThreshold because mouse will already be inside target by (1 - threshold) * targetLength / 2
  2209. // check if past first invert threshold on side opposite of lastDirection
  2210. if (!pastFirstInvertThresh && (lastDirection === 1 ? mouseOnAxis > targetS1 + targetLength * invertedSwapThreshold / 2 : mouseOnAxis < targetS2 - targetLength * invertedSwapThreshold / 2)) {
  2211. // past first invert threshold, do not restrict inverted threshold to dragEl shadow
  2212. pastFirstInvertThresh = true;
  2213. }
  2214. if (!pastFirstInvertThresh) {
  2215. // dragEl shadow (target move distance shadow)
  2216. if (lastDirection === 1 ? mouseOnAxis < targetS1 + targetMoveDistance // over dragEl shadow
  2217. : mouseOnAxis > targetS2 - targetMoveDistance) {
  2218. return -lastDirection;
  2219. }
  2220. } else {
  2221. invert = true;
  2222. }
  2223. } else {
  2224. // Regular
  2225. if (mouseOnAxis > targetS1 + targetLength * (1 - swapThreshold) / 2 && mouseOnAxis < targetS2 - targetLength * (1 - swapThreshold) / 2) {
  2226. return _getInsertDirection(target);
  2227. }
  2228. }
  2229. }
  2230. invert = invert || invertSwap;
  2231. if (invert) {
  2232. // Invert of regular
  2233. if (mouseOnAxis < targetS1 + targetLength * invertedSwapThreshold / 2 || mouseOnAxis > targetS2 - targetLength * invertedSwapThreshold / 2) {
  2234. return mouseOnAxis > targetS1 + targetLength / 2 ? 1 : -1;
  2235. }
  2236. }
  2237. return 0;
  2238. }
  2239. /**
  2240. * Gets the direction dragEl must be swapped relative to target in order to make it
  2241. * seem that dragEl has been "inserted" into that element's position
  2242. * @param {HTMLElement} target The target whose position dragEl is being inserted at
  2243. * @return {Number} Direction dragEl must be swapped
  2244. */
  2245. function _getInsertDirection(target) {
  2246. if (index(dragEl) < index(target)) {
  2247. return 1;
  2248. } else {
  2249. return -1;
  2250. }
  2251. }
  2252. /**
  2253. * Generate id
  2254. * @param {HTMLElement} el
  2255. * @returns {String}
  2256. * @private
  2257. */
  2258. function _generateId(el) {
  2259. var str = el.tagName + el.className + el.src + el.href + el.textContent,
  2260. i = str.length,
  2261. sum = 0;
  2262. while (i--) {
  2263. sum += str.charCodeAt(i);
  2264. }
  2265. return sum.toString(36);
  2266. }
  2267. function _saveInputCheckedState(root) {
  2268. savedInputChecked.length = 0;
  2269. var inputs = root.getElementsByTagName('input');
  2270. var idx = inputs.length;
  2271. while (idx--) {
  2272. var el = inputs[idx];
  2273. el.checked && savedInputChecked.push(el);
  2274. }
  2275. }
  2276. function _nextTick(fn) {
  2277. return setTimeout(fn, 0);
  2278. }
  2279. function _cancelNextTick(id) {
  2280. return clearTimeout(id);
  2281. }
  2282. // Fixed #973:
  2283. if (documentExists) {
  2284. on(document, 'touchmove', function (evt) {
  2285. if ((Sortable.active || awaitingDragStarted) && evt.cancelable) {
  2286. evt.preventDefault();
  2287. }
  2288. });
  2289. }
  2290. // Export utils
  2291. Sortable.utils = {
  2292. on: on,
  2293. off: off,
  2294. css: css,
  2295. find: find,
  2296. is: function is(el, selector) {
  2297. return !!closest(el, selector, el, false);
  2298. },
  2299. extend: extend,
  2300. throttle: throttle,
  2301. closest: closest,
  2302. toggleClass: toggleClass,
  2303. clone: clone,
  2304. index: index,
  2305. nextTick: _nextTick,
  2306. cancelNextTick: _cancelNextTick,
  2307. detectDirection: _detectDirection,
  2308. getChild: getChild,
  2309. expando: expando
  2310. };
  2311. /**
  2312. * Get the Sortable instance of an element
  2313. * @param {HTMLElement} element The element
  2314. * @return {Sortable|undefined} The instance of Sortable
  2315. */
  2316. Sortable.get = function (element) {
  2317. return element[expando];
  2318. };
  2319. /**
  2320. * Mount a plugin to Sortable
  2321. * @param {...SortablePlugin|SortablePlugin[]} plugins Plugins being mounted
  2322. */
  2323. Sortable.mount = function () {
  2324. for (var _len = arguments.length, plugins = new Array(_len), _key = 0; _key < _len; _key++) {
  2325. plugins[_key] = arguments[_key];
  2326. }
  2327. if (plugins[0].constructor === Array) plugins = plugins[0];
  2328. plugins.forEach(function (plugin) {
  2329. if (!plugin.prototype || !plugin.prototype.constructor) {
  2330. throw "Sortable: Mounted plugin must be a constructor function, not ".concat({}.toString.call(plugin));
  2331. }
  2332. if (plugin.utils) Sortable.utils = _objectSpread2(_objectSpread2({}, Sortable.utils), plugin.utils);
  2333. PluginManager.mount(plugin);
  2334. });
  2335. };
  2336. /**
  2337. * Create sortable instance
  2338. * @param {HTMLElement} el
  2339. * @param {Object} [options]
  2340. */
  2341. Sortable.create = function (el, options) {
  2342. return new Sortable(el, options);
  2343. };
  2344. // Export
  2345. Sortable.version = version;
  2346. var autoScrolls = [],
  2347. scrollEl,
  2348. scrollRootEl,
  2349. scrolling = false,
  2350. lastAutoScrollX,
  2351. lastAutoScrollY,
  2352. touchEvt$1,
  2353. pointerElemChangedInterval;
  2354. function AutoScrollPlugin() {
  2355. function AutoScroll() {
  2356. this.defaults = {
  2357. scroll: true,
  2358. forceAutoScrollFallback: false,
  2359. scrollSensitivity: 30,
  2360. scrollSpeed: 10,
  2361. bubbleScroll: true
  2362. };
  2363. // Bind all private methods
  2364. for (var fn in this) {
  2365. if (fn.charAt(0) === '_' && typeof this[fn] === 'function') {
  2366. this[fn] = this[fn].bind(this);
  2367. }
  2368. }
  2369. }
  2370. AutoScroll.prototype = {
  2371. dragStarted: function dragStarted(_ref) {
  2372. var originalEvent = _ref.originalEvent;
  2373. if (this.sortable.nativeDraggable) {
  2374. on(document, 'dragover', this._handleAutoScroll);
  2375. } else {
  2376. if (this.options.supportPointer) {
  2377. on(document, 'pointermove', this._handleFallbackAutoScroll);
  2378. } else if (originalEvent.touches) {
  2379. on(document, 'touchmove', this._handleFallbackAutoScroll);
  2380. } else {
  2381. on(document, 'mousemove', this._handleFallbackAutoScroll);
  2382. }
  2383. }
  2384. },
  2385. dragOverCompleted: function dragOverCompleted(_ref2) {
  2386. var originalEvent = _ref2.originalEvent;
  2387. // For when bubbling is canceled and using fallback (fallback 'touchmove' always reached)
  2388. if (!this.options.dragOverBubble && !originalEvent.rootEl) {
  2389. this._handleAutoScroll(originalEvent);
  2390. }
  2391. },
  2392. drop: function drop() {
  2393. if (this.sortable.nativeDraggable) {
  2394. off(document, 'dragover', this._handleAutoScroll);
  2395. } else {
  2396. off(document, 'pointermove', this._handleFallbackAutoScroll);
  2397. off(document, 'touchmove', this._handleFallbackAutoScroll);
  2398. off(document, 'mousemove', this._handleFallbackAutoScroll);
  2399. }
  2400. clearPointerElemChangedInterval();
  2401. clearAutoScrolls();
  2402. cancelThrottle();
  2403. },
  2404. nulling: function nulling() {
  2405. touchEvt$1 = scrollRootEl = scrollEl = scrolling = pointerElemChangedInterval = lastAutoScrollX = lastAutoScrollY = null;
  2406. autoScrolls.length = 0;
  2407. },
  2408. _handleFallbackAutoScroll: function _handleFallbackAutoScroll(evt) {
  2409. this._handleAutoScroll(evt, true);
  2410. },
  2411. _handleAutoScroll: function _handleAutoScroll(evt, fallback) {
  2412. var _this = this;
  2413. var x = (evt.touches ? evt.touches[0] : evt).clientX,
  2414. y = (evt.touches ? evt.touches[0] : evt).clientY,
  2415. elem = document.elementFromPoint(x, y);
  2416. touchEvt$1 = evt;
  2417. // IE does not seem to have native autoscroll,
  2418. // Edge's autoscroll seems too conditional,
  2419. // MACOS Safari does not have autoscroll,
  2420. // Firefox and Chrome are good
  2421. if (fallback || this.options.forceAutoScrollFallback || Edge || IE11OrLess || Safari) {
  2422. autoScroll(evt, this.options, elem, fallback);
  2423. // Listener for pointer element change
  2424. var ogElemScroller = getParentAutoScrollElement(elem, true);
  2425. if (scrolling && (!pointerElemChangedInterval || x !== lastAutoScrollX || y !== lastAutoScrollY)) {
  2426. pointerElemChangedInterval && clearPointerElemChangedInterval();
  2427. // Detect for pointer elem change, emulating native DnD behaviour
  2428. pointerElemChangedInterval = setInterval(function () {
  2429. var newElem = getParentAutoScrollElement(document.elementFromPoint(x, y), true);
  2430. if (newElem !== ogElemScroller) {
  2431. ogElemScroller = newElem;
  2432. clearAutoScrolls();
  2433. }
  2434. autoScroll(evt, _this.options, newElem, fallback);
  2435. }, 10);
  2436. lastAutoScrollX = x;
  2437. lastAutoScrollY = y;
  2438. }
  2439. } else {
  2440. // if DnD is enabled (and browser has good autoscrolling), first autoscroll will already scroll, so get parent autoscroll of first autoscroll
  2441. if (!this.options.bubbleScroll || getParentAutoScrollElement(elem, true) === getWindowScrollingElement()) {
  2442. clearAutoScrolls();
  2443. return;
  2444. }
  2445. autoScroll(evt, this.options, getParentAutoScrollElement(elem, false), false);
  2446. }
  2447. }
  2448. };
  2449. return _extends(AutoScroll, {
  2450. pluginName: 'scroll',
  2451. initializeByDefault: true
  2452. });
  2453. }
  2454. function clearAutoScrolls() {
  2455. autoScrolls.forEach(function (autoScroll) {
  2456. clearInterval(autoScroll.pid);
  2457. });
  2458. autoScrolls = [];
  2459. }
  2460. function clearPointerElemChangedInterval() {
  2461. clearInterval(pointerElemChangedInterval);
  2462. }
  2463. var autoScroll = throttle(function (evt, options, rootEl, isFallback) {
  2464. // Bug: https://bugzilla.mozilla.org/show_bug.cgi?id=505521
  2465. if (!options.scroll) return;
  2466. var x = (evt.touches ? evt.touches[0] : evt).clientX,
  2467. y = (evt.touches ? evt.touches[0] : evt).clientY,
  2468. sens = options.scrollSensitivity,
  2469. speed = options.scrollSpeed,
  2470. winScroller = getWindowScrollingElement();
  2471. var scrollThisInstance = false,
  2472. scrollCustomFn;
  2473. // New scroll root, set scrollEl
  2474. if (scrollRootEl !== rootEl) {
  2475. scrollRootEl = rootEl;
  2476. clearAutoScrolls();
  2477. scrollEl = options.scroll;
  2478. scrollCustomFn = options.scrollFn;
  2479. if (scrollEl === true) {
  2480. scrollEl = getParentAutoScrollElement(rootEl, true);
  2481. }
  2482. }
  2483. var layersOut = 0;
  2484. var currentParent = scrollEl;
  2485. do {
  2486. var el = currentParent,
  2487. rect = getRect(el),
  2488. top = rect.top,
  2489. bottom = rect.bottom,
  2490. left = rect.left,
  2491. right = rect.right,
  2492. width = rect.width,
  2493. height = rect.height,
  2494. canScrollX = void 0,
  2495. canScrollY = void 0,
  2496. scrollWidth = el.scrollWidth,
  2497. scrollHeight = el.scrollHeight,
  2498. elCSS = css(el),
  2499. scrollPosX = el.scrollLeft,
  2500. scrollPosY = el.scrollTop;
  2501. if (el === winScroller) {
  2502. canScrollX = width < scrollWidth && (elCSS.overflowX === 'auto' || elCSS.overflowX === 'scroll' || elCSS.overflowX === 'visible');
  2503. canScrollY = height < scrollHeight && (elCSS.overflowY === 'auto' || elCSS.overflowY === 'scroll' || elCSS.overflowY === 'visible');
  2504. } else {
  2505. canScrollX = width < scrollWidth && (elCSS.overflowX === 'auto' || elCSS.overflowX === 'scroll');
  2506. canScrollY = height < scrollHeight && (elCSS.overflowY === 'auto' || elCSS.overflowY === 'scroll');
  2507. }
  2508. var vx = canScrollX && (Math.abs(right - x) <= sens && scrollPosX + width < scrollWidth) - (Math.abs(left - x) <= sens && !!scrollPosX);
  2509. var vy = canScrollY && (Math.abs(bottom - y) <= sens && scrollPosY + height < scrollHeight) - (Math.abs(top - y) <= sens && !!scrollPosY);
  2510. if (!autoScrolls[layersOut]) {
  2511. for (var i = 0; i <= layersOut; i++) {
  2512. if (!autoScrolls[i]) {
  2513. autoScrolls[i] = {};
  2514. }
  2515. }
  2516. }
  2517. if (autoScrolls[layersOut].vx != vx || autoScrolls[layersOut].vy != vy || autoScrolls[layersOut].el !== el) {
  2518. autoScrolls[layersOut].el = el;
  2519. autoScrolls[layersOut].vx = vx;
  2520. autoScrolls[layersOut].vy = vy;
  2521. clearInterval(autoScrolls[layersOut].pid);
  2522. if (vx != 0 || vy != 0) {
  2523. scrollThisInstance = true;
  2524. /* jshint loopfunc:true */
  2525. autoScrolls[layersOut].pid = setInterval(function () {
  2526. // emulate drag over during autoscroll (fallback), emulating native DnD behaviour
  2527. if (isFallback && this.layer === 0) {
  2528. Sortable.active._onTouchMove(touchEvt$1); // To move ghost if it is positioned absolutely
  2529. }
  2530. var scrollOffsetY = autoScrolls[this.layer].vy ? autoScrolls[this.layer].vy * speed : 0;
  2531. var scrollOffsetX = autoScrolls[this.layer].vx ? autoScrolls[this.layer].vx * speed : 0;
  2532. if (typeof scrollCustomFn === 'function') {
  2533. if (scrollCustomFn.call(Sortable.dragged.parentNode[expando], scrollOffsetX, scrollOffsetY, evt, touchEvt$1, autoScrolls[this.layer].el) !== 'continue') {
  2534. return;
  2535. }
  2536. }
  2537. scrollBy(autoScrolls[this.layer].el, scrollOffsetX, scrollOffsetY);
  2538. }.bind({
  2539. layer: layersOut
  2540. }), 24);
  2541. }
  2542. }
  2543. layersOut++;
  2544. } while (options.bubbleScroll && currentParent !== winScroller && (currentParent = getParentAutoScrollElement(currentParent, false)));
  2545. scrolling = scrollThisInstance; // in case another function catches scrolling as false in between when it is not
  2546. }, 30);
  2547. var drop = function drop(_ref) {
  2548. var originalEvent = _ref.originalEvent,
  2549. putSortable = _ref.putSortable,
  2550. dragEl = _ref.dragEl,
  2551. activeSortable = _ref.activeSortable,
  2552. dispatchSortableEvent = _ref.dispatchSortableEvent,
  2553. hideGhostForTarget = _ref.hideGhostForTarget,
  2554. unhideGhostForTarget = _ref.unhideGhostForTarget;
  2555. if (!originalEvent) return;
  2556. var toSortable = putSortable || activeSortable;
  2557. hideGhostForTarget();
  2558. var touch = originalEvent.changedTouches && originalEvent.changedTouches.length ? originalEvent.changedTouches[0] : originalEvent;
  2559. var target = document.elementFromPoint(touch.clientX, touch.clientY);
  2560. unhideGhostForTarget();
  2561. if (toSortable && !toSortable.el.contains(target)) {
  2562. dispatchSortableEvent('spill');
  2563. this.onSpill({
  2564. dragEl: dragEl,
  2565. putSortable: putSortable
  2566. });
  2567. }
  2568. };
  2569. function Revert() {}
  2570. Revert.prototype = {
  2571. startIndex: null,
  2572. dragStart: function dragStart(_ref2) {
  2573. var oldDraggableIndex = _ref2.oldDraggableIndex;
  2574. this.startIndex = oldDraggableIndex;
  2575. },
  2576. onSpill: function onSpill(_ref3) {
  2577. var dragEl = _ref3.dragEl,
  2578. putSortable = _ref3.putSortable;
  2579. this.sortable.captureAnimationState();
  2580. if (putSortable) {
  2581. putSortable.captureAnimationState();
  2582. }
  2583. var nextSibling = getChild(this.sortable.el, this.startIndex, this.options);
  2584. if (nextSibling) {
  2585. this.sortable.el.insertBefore(dragEl, nextSibling);
  2586. } else {
  2587. this.sortable.el.appendChild(dragEl);
  2588. }
  2589. this.sortable.animateAll();
  2590. if (putSortable) {
  2591. putSortable.animateAll();
  2592. }
  2593. },
  2594. drop: drop
  2595. };
  2596. _extends(Revert, {
  2597. pluginName: 'revertOnSpill'
  2598. });
  2599. function Remove() {}
  2600. Remove.prototype = {
  2601. onSpill: function onSpill(_ref4) {
  2602. var dragEl = _ref4.dragEl,
  2603. putSortable = _ref4.putSortable;
  2604. var parentSortable = putSortable || this.sortable;
  2605. parentSortable.captureAnimationState();
  2606. dragEl.parentNode && dragEl.parentNode.removeChild(dragEl);
  2607. parentSortable.animateAll();
  2608. },
  2609. drop: drop
  2610. };
  2611. _extends(Remove, {
  2612. pluginName: 'removeOnSpill'
  2613. });
  2614. var lastSwapEl;
  2615. function SwapPlugin() {
  2616. function Swap() {
  2617. this.defaults = {
  2618. swapClass: 'sortable-swap-highlight'
  2619. };
  2620. }
  2621. Swap.prototype = {
  2622. dragStart: function dragStart(_ref) {
  2623. var dragEl = _ref.dragEl;
  2624. lastSwapEl = dragEl;
  2625. },
  2626. dragOverValid: function dragOverValid(_ref2) {
  2627. var completed = _ref2.completed,
  2628. target = _ref2.target,
  2629. onMove = _ref2.onMove,
  2630. activeSortable = _ref2.activeSortable,
  2631. changed = _ref2.changed,
  2632. cancel = _ref2.cancel;
  2633. if (!activeSortable.options.swap) return;
  2634. var el = this.sortable.el,
  2635. options = this.options;
  2636. if (target && target !== el) {
  2637. var prevSwapEl = lastSwapEl;
  2638. if (onMove(target) !== false) {
  2639. toggleClass(target, options.swapClass, true);
  2640. lastSwapEl = target;
  2641. } else {
  2642. lastSwapEl = null;
  2643. }
  2644. if (prevSwapEl && prevSwapEl !== lastSwapEl) {
  2645. toggleClass(prevSwapEl, options.swapClass, false);
  2646. }
  2647. }
  2648. changed();
  2649. completed(true);
  2650. cancel();
  2651. },
  2652. drop: function drop(_ref3) {
  2653. var activeSortable = _ref3.activeSortable,
  2654. putSortable = _ref3.putSortable,
  2655. dragEl = _ref3.dragEl;
  2656. var toSortable = putSortable || this.sortable;
  2657. var options = this.options;
  2658. lastSwapEl && toggleClass(lastSwapEl, options.swapClass, false);
  2659. if (lastSwapEl && (options.swap || putSortable && putSortable.options.swap)) {
  2660. if (dragEl !== lastSwapEl) {
  2661. toSortable.captureAnimationState();
  2662. if (toSortable !== activeSortable) activeSortable.captureAnimationState();
  2663. swapNodes(dragEl, lastSwapEl);
  2664. toSortable.animateAll();
  2665. if (toSortable !== activeSortable) activeSortable.animateAll();
  2666. }
  2667. }
  2668. },
  2669. nulling: function nulling() {
  2670. lastSwapEl = null;
  2671. }
  2672. };
  2673. return _extends(Swap, {
  2674. pluginName: 'swap',
  2675. eventProperties: function eventProperties() {
  2676. return {
  2677. swapItem: lastSwapEl
  2678. };
  2679. }
  2680. });
  2681. }
  2682. function swapNodes(n1, n2) {
  2683. var p1 = n1.parentNode,
  2684. p2 = n2.parentNode,
  2685. i1,
  2686. i2;
  2687. if (!p1 || !p2 || p1.isEqualNode(n2) || p2.isEqualNode(n1)) return;
  2688. i1 = index(n1);
  2689. i2 = index(n2);
  2690. if (p1.isEqualNode(p2) && i1 < i2) {
  2691. i2++;
  2692. }
  2693. p1.insertBefore(n2, p1.children[i1]);
  2694. p2.insertBefore(n1, p2.children[i2]);
  2695. }
  2696. var multiDragElements = [],
  2697. multiDragClones = [],
  2698. lastMultiDragSelect,
  2699. // for selection with modifier key down (SHIFT)
  2700. multiDragSortable,
  2701. initialFolding = false,
  2702. // Initial multi-drag fold when drag started
  2703. folding = false,
  2704. // Folding any other time
  2705. dragStarted = false,
  2706. dragEl$1,
  2707. clonesFromRect,
  2708. clonesHidden;
  2709. function MultiDragPlugin() {
  2710. function MultiDrag(sortable) {
  2711. // Bind all private methods
  2712. for (var fn in this) {
  2713. if (fn.charAt(0) === '_' && typeof this[fn] === 'function') {
  2714. this[fn] = this[fn].bind(this);
  2715. }
  2716. }
  2717. if (!sortable.options.avoidImplicitDeselect) {
  2718. if (sortable.options.supportPointer) {
  2719. on(document, 'pointerup', this._deselectMultiDrag);
  2720. } else {
  2721. on(document, 'mouseup', this._deselectMultiDrag);
  2722. on(document, 'touchend', this._deselectMultiDrag);
  2723. }
  2724. }
  2725. on(document, 'keydown', this._checkKeyDown);
  2726. on(document, 'keyup', this._checkKeyUp);
  2727. this.defaults = {
  2728. selectedClass: 'sortable-selected',
  2729. multiDragKey: null,
  2730. avoidImplicitDeselect: false,
  2731. setData: function setData(dataTransfer, dragEl) {
  2732. var data = '';
  2733. if (multiDragElements.length && multiDragSortable === sortable) {
  2734. multiDragElements.forEach(function (multiDragElement, i) {
  2735. data += (!i ? '' : ', ') + multiDragElement.textContent;
  2736. });
  2737. } else {
  2738. data = dragEl.textContent;
  2739. }
  2740. dataTransfer.setData('Text', data);
  2741. }
  2742. };
  2743. }
  2744. MultiDrag.prototype = {
  2745. multiDragKeyDown: false,
  2746. isMultiDrag: false,
  2747. delayStartGlobal: function delayStartGlobal(_ref) {
  2748. var dragged = _ref.dragEl;
  2749. dragEl$1 = dragged;
  2750. },
  2751. delayEnded: function delayEnded() {
  2752. this.isMultiDrag = ~multiDragElements.indexOf(dragEl$1);
  2753. },
  2754. setupClone: function setupClone(_ref2) {
  2755. var sortable = _ref2.sortable,
  2756. cancel = _ref2.cancel;
  2757. if (!this.isMultiDrag) return;
  2758. for (var i = 0; i < multiDragElements.length; i++) {
  2759. multiDragClones.push(clone(multiDragElements[i]));
  2760. multiDragClones[i].sortableIndex = multiDragElements[i].sortableIndex;
  2761. multiDragClones[i].draggable = false;
  2762. multiDragClones[i].style['will-change'] = '';
  2763. toggleClass(multiDragClones[i], this.options.selectedClass, false);
  2764. multiDragElements[i] === dragEl$1 && toggleClass(multiDragClones[i], this.options.chosenClass, false);
  2765. }
  2766. sortable._hideClone();
  2767. cancel();
  2768. },
  2769. clone: function clone(_ref3) {
  2770. var sortable = _ref3.sortable,
  2771. rootEl = _ref3.rootEl,
  2772. dispatchSortableEvent = _ref3.dispatchSortableEvent,
  2773. cancel = _ref3.cancel;
  2774. if (!this.isMultiDrag) return;
  2775. if (!this.options.removeCloneOnHide) {
  2776. if (multiDragElements.length && multiDragSortable === sortable) {
  2777. insertMultiDragClones(true, rootEl);
  2778. dispatchSortableEvent('clone');
  2779. cancel();
  2780. }
  2781. }
  2782. },
  2783. showClone: function showClone(_ref4) {
  2784. var cloneNowShown = _ref4.cloneNowShown,
  2785. rootEl = _ref4.rootEl,
  2786. cancel = _ref4.cancel;
  2787. if (!this.isMultiDrag) return;
  2788. insertMultiDragClones(false, rootEl);
  2789. multiDragClones.forEach(function (clone) {
  2790. css(clone, 'display', '');
  2791. });
  2792. cloneNowShown();
  2793. clonesHidden = false;
  2794. cancel();
  2795. },
  2796. hideClone: function hideClone(_ref5) {
  2797. var _this = this;
  2798. var sortable = _ref5.sortable,
  2799. cloneNowHidden = _ref5.cloneNowHidden,
  2800. cancel = _ref5.cancel;
  2801. if (!this.isMultiDrag) return;
  2802. multiDragClones.forEach(function (clone) {
  2803. css(clone, 'display', 'none');
  2804. if (_this.options.removeCloneOnHide && clone.parentNode) {
  2805. clone.parentNode.removeChild(clone);
  2806. }
  2807. });
  2808. cloneNowHidden();
  2809. clonesHidden = true;
  2810. cancel();
  2811. },
  2812. dragStartGlobal: function dragStartGlobal(_ref6) {
  2813. var sortable = _ref6.sortable;
  2814. if (!this.isMultiDrag && multiDragSortable) {
  2815. multiDragSortable.multiDrag._deselectMultiDrag();
  2816. }
  2817. multiDragElements.forEach(function (multiDragElement) {
  2818. multiDragElement.sortableIndex = index(multiDragElement);
  2819. });
  2820. // Sort multi-drag elements
  2821. multiDragElements = multiDragElements.sort(function (a, b) {
  2822. return a.sortableIndex - b.sortableIndex;
  2823. });
  2824. dragStarted = true;
  2825. },
  2826. dragStarted: function dragStarted(_ref7) {
  2827. var _this2 = this;
  2828. var sortable = _ref7.sortable;
  2829. if (!this.isMultiDrag) return;
  2830. if (this.options.sort) {
  2831. // Capture rects,
  2832. // hide multi drag elements (by positioning them absolute),
  2833. // set multi drag elements rects to dragRect,
  2834. // show multi drag elements,
  2835. // animate to rects,
  2836. // unset rects & remove from DOM
  2837. sortable.captureAnimationState();
  2838. if (this.options.animation) {
  2839. multiDragElements.forEach(function (multiDragElement) {
  2840. if (multiDragElement === dragEl$1) return;
  2841. css(multiDragElement, 'position', 'absolute');
  2842. });
  2843. var dragRect = getRect(dragEl$1, false, true, true);
  2844. multiDragElements.forEach(function (multiDragElement) {
  2845. if (multiDragElement === dragEl$1) return;
  2846. setRect(multiDragElement, dragRect);
  2847. });
  2848. folding = true;
  2849. initialFolding = true;
  2850. }
  2851. }
  2852. sortable.animateAll(function () {
  2853. folding = false;
  2854. initialFolding = false;
  2855. if (_this2.options.animation) {
  2856. multiDragElements.forEach(function (multiDragElement) {
  2857. unsetRect(multiDragElement);
  2858. });
  2859. }
  2860. // Remove all auxiliary multidrag items from el, if sorting enabled
  2861. if (_this2.options.sort) {
  2862. removeMultiDragElements();
  2863. }
  2864. });
  2865. },
  2866. dragOver: function dragOver(_ref8) {
  2867. var target = _ref8.target,
  2868. completed = _ref8.completed,
  2869. cancel = _ref8.cancel;
  2870. if (folding && ~multiDragElements.indexOf(target)) {
  2871. completed(false);
  2872. cancel();
  2873. }
  2874. },
  2875. revert: function revert(_ref9) {
  2876. var fromSortable = _ref9.fromSortable,
  2877. rootEl = _ref9.rootEl,
  2878. sortable = _ref9.sortable,
  2879. dragRect = _ref9.dragRect;
  2880. if (multiDragElements.length > 1) {
  2881. // Setup unfold animation
  2882. multiDragElements.forEach(function (multiDragElement) {
  2883. sortable.addAnimationState({
  2884. target: multiDragElement,
  2885. rect: folding ? getRect(multiDragElement) : dragRect
  2886. });
  2887. unsetRect(multiDragElement);
  2888. multiDragElement.fromRect = dragRect;
  2889. fromSortable.removeAnimationState(multiDragElement);
  2890. });
  2891. folding = false;
  2892. insertMultiDragElements(!this.options.removeCloneOnHide, rootEl);
  2893. }
  2894. },
  2895. dragOverCompleted: function dragOverCompleted(_ref10) {
  2896. var sortable = _ref10.sortable,
  2897. isOwner = _ref10.isOwner,
  2898. insertion = _ref10.insertion,
  2899. activeSortable = _ref10.activeSortable,
  2900. parentEl = _ref10.parentEl,
  2901. putSortable = _ref10.putSortable;
  2902. var options = this.options;
  2903. if (insertion) {
  2904. // Clones must be hidden before folding animation to capture dragRectAbsolute properly
  2905. if (isOwner) {
  2906. activeSortable._hideClone();
  2907. }
  2908. initialFolding = false;
  2909. // If leaving sort:false root, or already folding - Fold to new location
  2910. if (options.animation && multiDragElements.length > 1 && (folding || !isOwner && !activeSortable.options.sort && !putSortable)) {
  2911. // Fold: Set all multi drag elements's rects to dragEl's rect when multi-drag elements are invisible
  2912. var dragRectAbsolute = getRect(dragEl$1, false, true, true);
  2913. multiDragElements.forEach(function (multiDragElement) {
  2914. if (multiDragElement === dragEl$1) return;
  2915. setRect(multiDragElement, dragRectAbsolute);
  2916. // Move element(s) to end of parentEl so that it does not interfere with multi-drag clones insertion if they are inserted
  2917. // while folding, and so that we can capture them again because old sortable will no longer be fromSortable
  2918. parentEl.appendChild(multiDragElement);
  2919. });
  2920. folding = true;
  2921. }
  2922. // Clones must be shown (and check to remove multi drags) after folding when interfering multiDragElements are moved out
  2923. if (!isOwner) {
  2924. // Only remove if not folding (folding will remove them anyways)
  2925. if (!folding) {
  2926. removeMultiDragElements();
  2927. }
  2928. if (multiDragElements.length > 1) {
  2929. var clonesHiddenBefore = clonesHidden;
  2930. activeSortable._showClone(sortable);
  2931. // Unfold animation for clones if showing from hidden
  2932. if (activeSortable.options.animation && !clonesHidden && clonesHiddenBefore) {
  2933. multiDragClones.forEach(function (clone) {
  2934. activeSortable.addAnimationState({
  2935. target: clone,
  2936. rect: clonesFromRect
  2937. });
  2938. clone.fromRect = clonesFromRect;
  2939. clone.thisAnimationDuration = null;
  2940. });
  2941. }
  2942. } else {
  2943. activeSortable._showClone(sortable);
  2944. }
  2945. }
  2946. }
  2947. },
  2948. dragOverAnimationCapture: function dragOverAnimationCapture(_ref11) {
  2949. var dragRect = _ref11.dragRect,
  2950. isOwner = _ref11.isOwner,
  2951. activeSortable = _ref11.activeSortable;
  2952. multiDragElements.forEach(function (multiDragElement) {
  2953. multiDragElement.thisAnimationDuration = null;
  2954. });
  2955. if (activeSortable.options.animation && !isOwner && activeSortable.multiDrag.isMultiDrag) {
  2956. clonesFromRect = _extends({}, dragRect);
  2957. var dragMatrix = matrix(dragEl$1, true);
  2958. clonesFromRect.top -= dragMatrix.f;
  2959. clonesFromRect.left -= dragMatrix.e;
  2960. }
  2961. },
  2962. dragOverAnimationComplete: function dragOverAnimationComplete() {
  2963. if (folding) {
  2964. folding = false;
  2965. removeMultiDragElements();
  2966. }
  2967. },
  2968. drop: function drop(_ref12) {
  2969. var evt = _ref12.originalEvent,
  2970. rootEl = _ref12.rootEl,
  2971. parentEl = _ref12.parentEl,
  2972. sortable = _ref12.sortable,
  2973. dispatchSortableEvent = _ref12.dispatchSortableEvent,
  2974. oldIndex = _ref12.oldIndex,
  2975. putSortable = _ref12.putSortable;
  2976. var toSortable = putSortable || this.sortable;
  2977. if (!evt) return;
  2978. var options = this.options,
  2979. children = parentEl.children;
  2980. // Multi-drag selection
  2981. if (!dragStarted) {
  2982. if (options.multiDragKey && !this.multiDragKeyDown) {
  2983. this._deselectMultiDrag();
  2984. }
  2985. toggleClass(dragEl$1, options.selectedClass, !~multiDragElements.indexOf(dragEl$1));
  2986. if (!~multiDragElements.indexOf(dragEl$1)) {
  2987. multiDragElements.push(dragEl$1);
  2988. dispatchEvent({
  2989. sortable: sortable,
  2990. rootEl: rootEl,
  2991. name: 'select',
  2992. targetEl: dragEl$1,
  2993. originalEvent: evt
  2994. });
  2995. // Modifier activated, select from last to dragEl
  2996. if (evt.shiftKey && lastMultiDragSelect && sortable.el.contains(lastMultiDragSelect)) {
  2997. var lastIndex = index(lastMultiDragSelect),
  2998. currentIndex = index(dragEl$1);
  2999. if (~lastIndex && ~currentIndex && lastIndex !== currentIndex) {
  3000. (function () {
  3001. // Must include lastMultiDragSelect (select it), in case modified selection from no selection
  3002. // (but previous selection existed)
  3003. var n, i;
  3004. if (currentIndex > lastIndex) {
  3005. i = lastIndex;
  3006. n = currentIndex;
  3007. } else {
  3008. i = currentIndex;
  3009. n = lastIndex + 1;
  3010. }
  3011. var filter = options.filter;
  3012. for (; i < n; i++) {
  3013. if (~multiDragElements.indexOf(children[i])) continue;
  3014. // Check if element is draggable
  3015. if (!closest(children[i], options.draggable, parentEl, false)) continue;
  3016. // Check if element is filtered
  3017. var filtered = filter && (typeof filter === 'function' ? filter.call(sortable, evt, children[i], sortable) : filter.split(',').some(function (criteria) {
  3018. return closest(children[i], criteria.trim(), parentEl, false);
  3019. }));
  3020. if (filtered) continue;
  3021. toggleClass(children[i], options.selectedClass, true);
  3022. multiDragElements.push(children[i]);
  3023. dispatchEvent({
  3024. sortable: sortable,
  3025. rootEl: rootEl,
  3026. name: 'select',
  3027. targetEl: children[i],
  3028. originalEvent: evt
  3029. });
  3030. }
  3031. })();
  3032. }
  3033. } else {
  3034. lastMultiDragSelect = dragEl$1;
  3035. }
  3036. multiDragSortable = toSortable;
  3037. } else {
  3038. multiDragElements.splice(multiDragElements.indexOf(dragEl$1), 1);
  3039. lastMultiDragSelect = null;
  3040. dispatchEvent({
  3041. sortable: sortable,
  3042. rootEl: rootEl,
  3043. name: 'deselect',
  3044. targetEl: dragEl$1,
  3045. originalEvent: evt
  3046. });
  3047. }
  3048. }
  3049. // Multi-drag drop
  3050. if (dragStarted && this.isMultiDrag) {
  3051. folding = false;
  3052. // Do not "unfold" after around dragEl if reverted
  3053. if ((parentEl[expando].options.sort || parentEl !== rootEl) && multiDragElements.length > 1) {
  3054. var dragRect = getRect(dragEl$1),
  3055. multiDragIndex = index(dragEl$1, ':not(.' + this.options.selectedClass + ')');
  3056. if (!initialFolding && options.animation) dragEl$1.thisAnimationDuration = null;
  3057. toSortable.captureAnimationState();
  3058. if (!initialFolding) {
  3059. if (options.animation) {
  3060. dragEl$1.fromRect = dragRect;
  3061. multiDragElements.forEach(function (multiDragElement) {
  3062. multiDragElement.thisAnimationDuration = null;
  3063. if (multiDragElement !== dragEl$1) {
  3064. var rect = folding ? getRect(multiDragElement) : dragRect;
  3065. multiDragElement.fromRect = rect;
  3066. // Prepare unfold animation
  3067. toSortable.addAnimationState({
  3068. target: multiDragElement,
  3069. rect: rect
  3070. });
  3071. }
  3072. });
  3073. }
  3074. // Multi drag elements are not necessarily removed from the DOM on drop, so to reinsert
  3075. // properly they must all be removed
  3076. removeMultiDragElements();
  3077. multiDragElements.forEach(function (multiDragElement) {
  3078. if (children[multiDragIndex]) {
  3079. parentEl.insertBefore(multiDragElement, children[multiDragIndex]);
  3080. } else {
  3081. parentEl.appendChild(multiDragElement);
  3082. }
  3083. multiDragIndex++;
  3084. });
  3085. // If initial folding is done, the elements may have changed position because they are now
  3086. // unfolding around dragEl, even though dragEl may not have his index changed, so update event
  3087. // must be fired here as Sortable will not.
  3088. if (oldIndex === index(dragEl$1)) {
  3089. var update = false;
  3090. multiDragElements.forEach(function (multiDragElement) {
  3091. if (multiDragElement.sortableIndex !== index(multiDragElement)) {
  3092. update = true;
  3093. return;
  3094. }
  3095. });
  3096. if (update) {
  3097. dispatchSortableEvent('update');
  3098. dispatchSortableEvent('sort');
  3099. }
  3100. }
  3101. }
  3102. // Must be done after capturing individual rects (scroll bar)
  3103. multiDragElements.forEach(function (multiDragElement) {
  3104. unsetRect(multiDragElement);
  3105. });
  3106. toSortable.animateAll();
  3107. }
  3108. multiDragSortable = toSortable;
  3109. }
  3110. // Remove clones if necessary
  3111. if (rootEl === parentEl || putSortable && putSortable.lastPutMode !== 'clone') {
  3112. multiDragClones.forEach(function (clone) {
  3113. clone.parentNode && clone.parentNode.removeChild(clone);
  3114. });
  3115. }
  3116. },
  3117. nullingGlobal: function nullingGlobal() {
  3118. this.isMultiDrag = dragStarted = false;
  3119. multiDragClones.length = 0;
  3120. },
  3121. destroyGlobal: function destroyGlobal() {
  3122. this._deselectMultiDrag();
  3123. off(document, 'pointerup', this._deselectMultiDrag);
  3124. off(document, 'mouseup', this._deselectMultiDrag);
  3125. off(document, 'touchend', this._deselectMultiDrag);
  3126. off(document, 'keydown', this._checkKeyDown);
  3127. off(document, 'keyup', this._checkKeyUp);
  3128. },
  3129. _deselectMultiDrag: function _deselectMultiDrag(evt) {
  3130. if (typeof dragStarted !== "undefined" && dragStarted) return;
  3131. // Only deselect if selection is in this sortable
  3132. if (multiDragSortable !== this.sortable) return;
  3133. // Only deselect if target is not item in this sortable
  3134. if (evt && closest(evt.target, this.options.draggable, this.sortable.el, false)) return;
  3135. // Only deselect if left click
  3136. if (evt && evt.button !== 0) return;
  3137. while (multiDragElements.length) {
  3138. var el = multiDragElements[0];
  3139. toggleClass(el, this.options.selectedClass, false);
  3140. multiDragElements.shift();
  3141. dispatchEvent({
  3142. sortable: this.sortable,
  3143. rootEl: this.sortable.el,
  3144. name: 'deselect',
  3145. targetEl: el,
  3146. originalEvent: evt
  3147. });
  3148. }
  3149. },
  3150. _checkKeyDown: function _checkKeyDown(evt) {
  3151. if (evt.key === this.options.multiDragKey) {
  3152. this.multiDragKeyDown = true;
  3153. }
  3154. },
  3155. _checkKeyUp: function _checkKeyUp(evt) {
  3156. if (evt.key === this.options.multiDragKey) {
  3157. this.multiDragKeyDown = false;
  3158. }
  3159. }
  3160. };
  3161. return _extends(MultiDrag, {
  3162. // Static methods & properties
  3163. pluginName: 'multiDrag',
  3164. utils: {
  3165. /**
  3166. * Selects the provided multi-drag item
  3167. * @param {HTMLElement} el The element to be selected
  3168. */
  3169. select: function select(el) {
  3170. var sortable = el.parentNode[expando];
  3171. if (!sortable || !sortable.options.multiDrag || ~multiDragElements.indexOf(el)) return;
  3172. if (multiDragSortable && multiDragSortable !== sortable) {
  3173. multiDragSortable.multiDrag._deselectMultiDrag();
  3174. multiDragSortable = sortable;
  3175. }
  3176. toggleClass(el, sortable.options.selectedClass, true);
  3177. multiDragElements.push(el);
  3178. },
  3179. /**
  3180. * Deselects the provided multi-drag item
  3181. * @param {HTMLElement} el The element to be deselected
  3182. */
  3183. deselect: function deselect(el) {
  3184. var sortable = el.parentNode[expando],
  3185. index = multiDragElements.indexOf(el);
  3186. if (!sortable || !sortable.options.multiDrag || !~index) return;
  3187. toggleClass(el, sortable.options.selectedClass, false);
  3188. multiDragElements.splice(index, 1);
  3189. }
  3190. },
  3191. eventProperties: function eventProperties() {
  3192. var _this3 = this;
  3193. var oldIndicies = [],
  3194. newIndicies = [];
  3195. multiDragElements.forEach(function (multiDragElement) {
  3196. oldIndicies.push({
  3197. multiDragElement: multiDragElement,
  3198. index: multiDragElement.sortableIndex
  3199. });
  3200. // multiDragElements will already be sorted if folding
  3201. var newIndex;
  3202. if (folding && multiDragElement !== dragEl$1) {
  3203. newIndex = -1;
  3204. } else if (folding) {
  3205. newIndex = index(multiDragElement, ':not(.' + _this3.options.selectedClass + ')');
  3206. } else {
  3207. newIndex = index(multiDragElement);
  3208. }
  3209. newIndicies.push({
  3210. multiDragElement: multiDragElement,
  3211. index: newIndex
  3212. });
  3213. });
  3214. return {
  3215. items: _toConsumableArray(multiDragElements),
  3216. clones: [].concat(multiDragClones),
  3217. oldIndicies: oldIndicies,
  3218. newIndicies: newIndicies
  3219. };
  3220. },
  3221. optionListeners: {
  3222. multiDragKey: function multiDragKey(key) {
  3223. key = key.toLowerCase();
  3224. if (key === 'ctrl') {
  3225. key = 'Control';
  3226. } else if (key.length > 1) {
  3227. key = key.charAt(0).toUpperCase() + key.substr(1);
  3228. }
  3229. return key;
  3230. }
  3231. }
  3232. });
  3233. }
  3234. function insertMultiDragElements(clonesInserted, rootEl) {
  3235. multiDragElements.forEach(function (multiDragElement, i) {
  3236. var target = rootEl.children[multiDragElement.sortableIndex + (clonesInserted ? Number(i) : 0)];
  3237. if (target) {
  3238. rootEl.insertBefore(multiDragElement, target);
  3239. } else {
  3240. rootEl.appendChild(multiDragElement);
  3241. }
  3242. });
  3243. }
  3244. /**
  3245. * Insert multi-drag clones
  3246. * @param {[Boolean]} elementsInserted Whether the multi-drag elements are inserted
  3247. * @param {HTMLElement} rootEl
  3248. */
  3249. function insertMultiDragClones(elementsInserted, rootEl) {
  3250. multiDragClones.forEach(function (clone, i) {
  3251. var target = rootEl.children[clone.sortableIndex + (elementsInserted ? Number(i) : 0)];
  3252. if (target) {
  3253. rootEl.insertBefore(clone, target);
  3254. } else {
  3255. rootEl.appendChild(clone);
  3256. }
  3257. });
  3258. }
  3259. function removeMultiDragElements() {
  3260. multiDragElements.forEach(function (multiDragElement) {
  3261. if (multiDragElement === dragEl$1) return;
  3262. multiDragElement.parentNode && multiDragElement.parentNode.removeChild(multiDragElement);
  3263. });
  3264. }
  3265. Sortable.mount(new AutoScrollPlugin());
  3266. Sortable.mount(Remove, Revert);
  3267. Sortable.mount(new SwapPlugin());
  3268. Sortable.mount(new MultiDragPlugin());
  3269. return Sortable;
  3270. })));