sortable.esm.js 111 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474475476477478479480481482483484485486487488489490491492493494495496497498499500501502503504505506507508509510511512513514515516517518519520521522523524525526527528529530531532533534535536537538539540541542543544545546547548549550551552553554555556557558559560561562563564565566567568569570571572573574575576577578579580581582583584585586587588589590591592593594595596597598599600601602603604605606607608609610611612613614615616617618619620621622623624625626627628629630631632633634635636637638639640641642643644645646647648649650651652653654655656657658659660661662663664665666667668669670671672673674675676677678679680681682683684685686687688689690691692693694695696697698699700701702703704705706707708709710711712713714715716717718719720721722723724725726727728729730731732733734735736737738739740741742743744745746747748749750751752753754755756757758759760761762763764765766767768769770771772773774775776777778779780781782783784785786787788789790791792793794795796797798799800801802803804805806807808809810811812813814815816817818819820821822823824825826827828829830831832833834835836837838839840841842843844845846847848849850851852853854855856857858859860861862863864865866867868869870871872873874875876877878879880881882883884885886887888889890891892893894895896897898899900901902903904905906907908909910911912913914915916917918919920921922923924925926927928929930931932933934935936937938939940941942943944945946947948949950951952953954955956957958959960961962963964965966967968969970971972973974975976977978979980981982983984985986987988989990991992993994995996997998999100010011002100310041005100610071008100910101011101210131014101510161017101810191020102110221023102410251026102710281029103010311032103310341035103610371038103910401041104210431044104510461047104810491050105110521053105410551056105710581059106010611062106310641065106610671068106910701071107210731074107510761077107810791080108110821083108410851086108710881089109010911092109310941095109610971098109911001101110211031104110511061107110811091110111111121113111411151116111711181119112011211122112311241125112611271128112911301131113211331134113511361137113811391140114111421143114411451146114711481149115011511152115311541155115611571158115911601161116211631164116511661167116811691170117111721173117411751176117711781179118011811182118311841185118611871188118911901191119211931194119511961197119811991200120112021203120412051206120712081209121012111212121312141215121612171218121912201221122212231224122512261227122812291230123112321233123412351236123712381239124012411242124312441245124612471248124912501251125212531254125512561257125812591260126112621263126412651266126712681269127012711272127312741275127612771278127912801281128212831284128512861287128812891290129112921293129412951296129712981299130013011302130313041305130613071308130913101311131213131314131513161317131813191320132113221323132413251326132713281329133013311332133313341335133613371338133913401341134213431344134513461347134813491350135113521353135413551356135713581359136013611362136313641365136613671368136913701371137213731374137513761377137813791380138113821383138413851386138713881389139013911392139313941395139613971398139914001401140214031404140514061407140814091410141114121413141414151416141714181419142014211422142314241425142614271428142914301431143214331434143514361437143814391440144114421443144414451446144714481449145014511452145314541455145614571458145914601461146214631464146514661467146814691470147114721473147414751476147714781479148014811482148314841485148614871488148914901491149214931494149514961497149814991500150115021503150415051506150715081509151015111512151315141515151615171518151915201521152215231524152515261527152815291530153115321533153415351536153715381539154015411542154315441545154615471548154915501551155215531554155515561557155815591560156115621563156415651566156715681569157015711572157315741575157615771578157915801581158215831584158515861587158815891590159115921593159415951596159715981599160016011602160316041605160616071608160916101611161216131614161516161617161816191620162116221623162416251626162716281629163016311632163316341635163616371638163916401641164216431644164516461647164816491650165116521653165416551656165716581659166016611662166316641665166616671668166916701671167216731674167516761677167816791680168116821683168416851686168716881689169016911692169316941695169616971698169917001701170217031704170517061707170817091710171117121713171417151716171717181719172017211722172317241725172617271728172917301731173217331734173517361737173817391740174117421743174417451746174717481749175017511752175317541755175617571758175917601761176217631764176517661767176817691770177117721773177417751776177717781779178017811782178317841785178617871788178917901791179217931794179517961797179817991800180118021803180418051806180718081809181018111812181318141815181618171818181918201821182218231824182518261827182818291830183118321833183418351836183718381839184018411842184318441845184618471848184918501851185218531854185518561857185818591860186118621863186418651866186718681869187018711872187318741875187618771878187918801881188218831884188518861887188818891890189118921893189418951896189718981899190019011902190319041905190619071908190919101911191219131914191519161917191819191920192119221923192419251926192719281929193019311932193319341935193619371938193919401941194219431944194519461947194819491950195119521953195419551956195719581959196019611962196319641965196619671968196919701971197219731974197519761977197819791980198119821983198419851986198719881989199019911992199319941995199619971998199920002001200220032004200520062007200820092010201120122013201420152016201720182019202020212022202320242025202620272028202920302031203220332034203520362037203820392040204120422043204420452046204720482049205020512052205320542055205620572058205920602061206220632064206520662067206820692070207120722073207420752076207720782079208020812082208320842085208620872088208920902091209220932094209520962097209820992100210121022103210421052106210721082109211021112112211321142115211621172118211921202121212221232124212521262127212821292130213121322133213421352136213721382139214021412142214321442145214621472148214921502151215221532154215521562157215821592160216121622163216421652166216721682169217021712172217321742175217621772178217921802181218221832184218521862187218821892190219121922193219421952196219721982199220022012202220322042205220622072208220922102211221222132214221522162217221822192220222122222223222422252226222722282229223022312232223322342235223622372238223922402241224222432244224522462247224822492250225122522253225422552256225722582259226022612262226322642265226622672268226922702271227222732274227522762277227822792280228122822283228422852286228722882289229022912292229322942295229622972298229923002301230223032304230523062307230823092310231123122313231423152316231723182319232023212322232323242325232623272328232923302331233223332334233523362337233823392340234123422343234423452346234723482349235023512352235323542355235623572358235923602361236223632364236523662367236823692370237123722373237423752376237723782379238023812382238323842385238623872388238923902391239223932394239523962397239823992400240124022403240424052406240724082409241024112412241324142415241624172418241924202421242224232424242524262427242824292430243124322433243424352436243724382439244024412442244324442445244624472448244924502451245224532454245524562457245824592460246124622463246424652466246724682469247024712472247324742475247624772478247924802481248224832484248524862487248824892490249124922493249424952496249724982499250025012502250325042505250625072508250925102511251225132514251525162517251825192520252125222523252425252526252725282529253025312532253325342535253625372538253925402541254225432544254525462547254825492550255125522553255425552556255725582559256025612562256325642565256625672568256925702571257225732574257525762577257825792580258125822583258425852586258725882589259025912592259325942595259625972598259926002601260226032604260526062607260826092610261126122613261426152616261726182619262026212622262326242625262626272628262926302631263226332634263526362637263826392640264126422643264426452646264726482649265026512652265326542655265626572658265926602661266226632664266526662667266826692670267126722673267426752676267726782679268026812682268326842685268626872688268926902691269226932694269526962697269826992700270127022703270427052706270727082709271027112712271327142715271627172718271927202721272227232724272527262727272827292730273127322733273427352736273727382739274027412742274327442745274627472748274927502751275227532754275527562757275827592760276127622763276427652766276727682769277027712772277327742775277627772778277927802781278227832784278527862787278827892790279127922793279427952796279727982799280028012802280328042805280628072808280928102811281228132814281528162817281828192820282128222823282428252826282728282829283028312832283328342835283628372838283928402841284228432844284528462847284828492850285128522853285428552856285728582859286028612862286328642865286628672868286928702871287228732874287528762877287828792880288128822883288428852886288728882889289028912892289328942895289628972898289929002901290229032904290529062907290829092910291129122913291429152916291729182919292029212922292329242925292629272928292929302931293229332934293529362937293829392940294129422943294429452946294729482949295029512952295329542955295629572958295929602961296229632964296529662967296829692970297129722973297429752976297729782979298029812982298329842985298629872988298929902991299229932994299529962997299829993000300130023003300430053006300730083009301030113012301330143015301630173018301930203021302230233024302530263027302830293030303130323033303430353036303730383039304030413042304330443045304630473048304930503051305230533054305530563057305830593060306130623063306430653066306730683069307030713072307330743075307630773078307930803081308230833084308530863087308830893090309130923093309430953096309730983099310031013102310331043105310631073108310931103111311231133114311531163117311831193120312131223123312431253126312731283129313031313132313331343135313631373138313931403141314231433144314531463147314831493150315131523153315431553156315731583159316031613162316331643165316631673168316931703171317231733174317531763177317831793180318131823183318431853186318731883189319031913192319331943195319631973198319932003201320232033204320532063207320832093210321132123213321432153216321732183219322032213222322332243225322632273228322932303231323232333234323532363237323832393240324132423243324432453246324732483249325032513252325332543255325632573258325932603261326232633264326532663267326832693270327132723273327432753276327732783279328032813282328332843285328632873288328932903291329232933294329532963297329832993300330133023303330433053306330733083309331033113312331333143315331633173318331933203321332233233324332533263327332833293330333133323333333433353336333733383339334033413342334333443345334633473348334933503351335233533354335533563357335833593360336133623363336433653366336733683369337033713372337333743375337633773378337933803381338233833384338533863387338833893390339133923393339433953396339733983399340034013402340334043405340634073408340934103411341234133414341534163417341834193420342134223423342434253426342734283429343034313432343334343435343634373438343934403441344234433444344534463447344834493450345134523453345434553456345734583459346034613462346334643465346634673468346934703471347234733474347534763477347834793480348134823483348434853486348734883489349034913492349334943495349634973498349935003501350235033504350535063507350835093510351135123513351435153516351735183519352035213522352335243525352635273528352935303531353235333534353535363537353835393540354135423543354435453546354735483549355035513552355335543555355635573558355935603561356235633564356535663567356835693570357135723573357435753576357735783579358035813582358335843585358635873588358935903591359235933594359535963597359835993600360136023603360436053606360736083609361036113612361336143615361636173618361936203621362236233624362536263627362836293630363136323633363436353636363736383639364036413642364336443645364636473648364936503651365236533654365536563657365836593660366136623663366436653666366736683669367036713672367336743675367636773678367936803681368236833684368536863687368836893690369136923693369436953696369736983699
  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. export default Sortable;
  3103. export { MultiDragPlugin as MultiDrag, Sortable, SwapPlugin as Swap };