sortable.complete.esm.js 117 KB

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