sortable.complete.esm.js 111 KB

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