47bf8699f6041c02f75e14ac74f7d9d384ae2a4faad9b8941fa1a46549d8caed1696bfaa5fdab1ef7e11afc517a3fc9772e9a16efbe3c53df369292dd8e35c 114 KB

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