cdk-drag-drop.umd.js 192 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474475476477478479480481482483484485486487488489490491492493494495496497498499500501502503504505506507508509510511512513514515516517518519520521522523524525526527528529530531532533534535536537538539540541542543544545546547548549550551552553554555556557558559560561562563564565566567568569570571572573574575576577578579580581582583584585586587588589590591592593594595596597598599600601602603604605606607608609610611612613614615616617618619620621622623624625626627628629630631632633634635636637638639640641642643644645646647648649650651652653654655656657658659660661662663664665666667668669670671672673674675676677678679680681682683684685686687688689690691692693694695696697698699700701702703704705706707708709710711712713714715716717718719720721722723724725726727728729730731732733734735736737738739740741742743744745746747748749750751752753754755756757758759760761762763764765766767768769770771772773774775776777778779780781782783784785786787788789790791792793794795796797798799800801802803804805806807808809810811812813814815816817818819820821822823824825826827828829830831832833834835836837838839840841842843844845846847848849850851852853854855856857858859860861862863864865866867868869870871872873874875876877878879880881882883884885886887888889890891892893894895896897898899900901902903904905906907908909910911912913914915916917918919920921922923924925926927928929930931932933934935936937938939940941942943944945946947948949950951952953954955956957958959960961962963964965966967968969970971972973974975976977978979980981982983984985986987988989990991992993994995996997998999100010011002100310041005100610071008100910101011101210131014101510161017101810191020102110221023102410251026102710281029103010311032103310341035103610371038103910401041104210431044104510461047104810491050105110521053105410551056105710581059106010611062106310641065106610671068106910701071107210731074107510761077107810791080108110821083108410851086108710881089109010911092109310941095109610971098109911001101110211031104110511061107110811091110111111121113111411151116111711181119112011211122112311241125112611271128112911301131113211331134113511361137113811391140114111421143114411451146114711481149115011511152115311541155115611571158115911601161116211631164116511661167116811691170117111721173117411751176117711781179118011811182118311841185118611871188118911901191119211931194119511961197119811991200120112021203120412051206120712081209121012111212121312141215121612171218121912201221122212231224122512261227122812291230123112321233123412351236123712381239124012411242124312441245124612471248124912501251125212531254125512561257125812591260126112621263126412651266126712681269127012711272127312741275127612771278127912801281128212831284128512861287128812891290129112921293129412951296129712981299130013011302130313041305130613071308130913101311131213131314131513161317131813191320132113221323132413251326132713281329133013311332133313341335133613371338133913401341134213431344134513461347134813491350135113521353135413551356135713581359136013611362136313641365136613671368136913701371137213731374137513761377137813791380138113821383138413851386138713881389139013911392139313941395139613971398139914001401140214031404140514061407140814091410141114121413141414151416141714181419142014211422142314241425142614271428142914301431143214331434143514361437143814391440144114421443144414451446144714481449145014511452145314541455145614571458145914601461146214631464146514661467146814691470147114721473147414751476147714781479148014811482148314841485148614871488148914901491149214931494149514961497149814991500150115021503150415051506150715081509151015111512151315141515151615171518151915201521152215231524152515261527152815291530153115321533153415351536153715381539154015411542154315441545154615471548154915501551155215531554155515561557155815591560156115621563156415651566156715681569157015711572157315741575157615771578157915801581158215831584158515861587158815891590159115921593159415951596159715981599160016011602160316041605160616071608160916101611161216131614161516161617161816191620162116221623162416251626162716281629163016311632163316341635163616371638163916401641164216431644164516461647164816491650165116521653165416551656165716581659166016611662166316641665166616671668166916701671167216731674167516761677167816791680168116821683168416851686168716881689169016911692169316941695169616971698169917001701170217031704170517061707170817091710171117121713171417151716171717181719172017211722172317241725172617271728172917301731173217331734173517361737173817391740174117421743174417451746174717481749175017511752175317541755175617571758175917601761176217631764176517661767176817691770177117721773177417751776177717781779178017811782178317841785178617871788178917901791179217931794179517961797179817991800180118021803180418051806180718081809181018111812181318141815181618171818181918201821182218231824182518261827182818291830183118321833183418351836183718381839184018411842184318441845184618471848184918501851185218531854185518561857185818591860186118621863186418651866186718681869187018711872187318741875187618771878187918801881188218831884188518861887188818891890189118921893189418951896189718981899190019011902190319041905190619071908190919101911191219131914191519161917191819191920192119221923192419251926192719281929193019311932193319341935193619371938193919401941194219431944194519461947194819491950195119521953195419551956195719581959196019611962196319641965196619671968196919701971197219731974197519761977197819791980198119821983198419851986198719881989199019911992199319941995199619971998199920002001200220032004200520062007200820092010201120122013201420152016201720182019202020212022202320242025202620272028202920302031203220332034203520362037203820392040204120422043204420452046204720482049205020512052205320542055205620572058205920602061206220632064206520662067206820692070207120722073207420752076207720782079208020812082208320842085208620872088208920902091209220932094209520962097209820992100210121022103210421052106210721082109211021112112211321142115211621172118211921202121212221232124212521262127212821292130213121322133213421352136213721382139214021412142214321442145214621472148214921502151215221532154215521562157215821592160216121622163216421652166216721682169217021712172217321742175217621772178217921802181218221832184218521862187218821892190219121922193219421952196219721982199220022012202220322042205220622072208220922102211221222132214221522162217221822192220222122222223222422252226222722282229223022312232223322342235223622372238223922402241224222432244224522462247224822492250225122522253225422552256225722582259226022612262226322642265226622672268226922702271227222732274227522762277227822792280228122822283228422852286228722882289229022912292229322942295229622972298229923002301230223032304230523062307230823092310231123122313231423152316231723182319232023212322232323242325232623272328232923302331233223332334233523362337233823392340234123422343234423452346234723482349235023512352235323542355235623572358235923602361236223632364236523662367236823692370237123722373237423752376237723782379238023812382238323842385238623872388238923902391239223932394239523962397239823992400240124022403240424052406240724082409241024112412241324142415241624172418241924202421242224232424242524262427242824292430243124322433243424352436243724382439244024412442244324442445244624472448244924502451245224532454245524562457245824592460246124622463246424652466246724682469247024712472247324742475247624772478247924802481248224832484248524862487248824892490249124922493249424952496249724982499250025012502250325042505250625072508250925102511251225132514251525162517251825192520252125222523252425252526252725282529253025312532253325342535253625372538253925402541254225432544254525462547254825492550255125522553255425552556255725582559256025612562256325642565256625672568256925702571257225732574257525762577257825792580258125822583258425852586258725882589259025912592259325942595259625972598259926002601260226032604260526062607260826092610261126122613261426152616261726182619262026212622262326242625262626272628262926302631263226332634263526362637263826392640264126422643264426452646264726482649265026512652265326542655265626572658265926602661266226632664266526662667266826692670267126722673267426752676267726782679268026812682268326842685268626872688268926902691269226932694269526962697269826992700270127022703270427052706270727082709271027112712271327142715271627172718271927202721272227232724272527262727272827292730273127322733273427352736273727382739274027412742274327442745274627472748274927502751275227532754275527562757275827592760276127622763276427652766276727682769277027712772277327742775277627772778277927802781278227832784278527862787278827892790279127922793279427952796279727982799280028012802280328042805280628072808280928102811281228132814281528162817281828192820282128222823282428252826282728282829283028312832283328342835283628372838283928402841284228432844284528462847284828492850285128522853285428552856285728582859286028612862286328642865286628672868286928702871287228732874287528762877287828792880288128822883288428852886288728882889289028912892289328942895289628972898289929002901290229032904290529062907290829092910291129122913291429152916291729182919292029212922292329242925292629272928292929302931293229332934293529362937293829392940294129422943294429452946294729482949295029512952295329542955295629572958295929602961296229632964296529662967296829692970297129722973297429752976297729782979298029812982298329842985298629872988298929902991299229932994299529962997299829993000300130023003300430053006300730083009301030113012301330143015301630173018301930203021302230233024302530263027302830293030303130323033303430353036303730383039304030413042304330443045304630473048304930503051305230533054305530563057305830593060306130623063306430653066306730683069307030713072307330743075307630773078307930803081308230833084308530863087308830893090309130923093309430953096309730983099310031013102310331043105310631073108310931103111311231133114311531163117311831193120312131223123312431253126312731283129313031313132313331343135313631373138313931403141314231433144314531463147314831493150315131523153315431553156315731583159316031613162316331643165316631673168316931703171317231733174317531763177317831793180318131823183318431853186318731883189319031913192319331943195319631973198319932003201320232033204320532063207320832093210321132123213321432153216321732183219322032213222322332243225322632273228322932303231323232333234323532363237323832393240324132423243324432453246324732483249325032513252325332543255325632573258325932603261326232633264326532663267326832693270327132723273327432753276327732783279328032813282328332843285328632873288328932903291329232933294329532963297329832993300330133023303330433053306330733083309331033113312331333143315331633173318331933203321332233233324332533263327332833293330333133323333333433353336333733383339334033413342334333443345334633473348334933503351335233533354335533563357335833593360336133623363336433653366336733683369337033713372337333743375337633773378337933803381338233833384338533863387338833893390339133923393339433953396339733983399340034013402340334043405340634073408340934103411341234133414341534163417341834193420342134223423342434253426342734283429343034313432343334343435343634373438343934403441344234433444344534463447344834493450345134523453345434553456345734583459346034613462346334643465346634673468346934703471347234733474347534763477347834793480348134823483348434853486348734883489349034913492349334943495349634973498349935003501350235033504350535063507350835093510351135123513351435153516351735183519352035213522352335243525352635273528352935303531353235333534353535363537353835393540354135423543354435453546354735483549355035513552355335543555355635573558355935603561356235633564356535663567356835693570357135723573357435753576357735783579358035813582358335843585358635873588358935903591359235933594359535963597359835993600360136023603360436053606360736083609361036113612361336143615361636173618361936203621362236233624362536263627362836293630363136323633363436353636363736383639364036413642364336443645364636473648364936503651365236533654365536563657365836593660366136623663366436653666366736683669367036713672367336743675367636773678367936803681368236833684368536863687368836893690369136923693369436953696369736983699370037013702370337043705370637073708370937103711371237133714371537163717371837193720372137223723372437253726372737283729373037313732373337343735373637373738373937403741374237433744374537463747374837493750375137523753375437553756375737583759376037613762376337643765376637673768376937703771377237733774377537763777377837793780378137823783378437853786378737883789379037913792379337943795379637973798379938003801380238033804380538063807380838093810381138123813381438153816381738183819382038213822382338243825382638273828382938303831383238333834383538363837383838393840384138423843384438453846384738483849385038513852385338543855385638573858385938603861386238633864386538663867386838693870387138723873387438753876387738783879388038813882388338843885388638873888388938903891389238933894389538963897389838993900390139023903390439053906390739083909391039113912391339143915391639173918391939203921392239233924392539263927392839293930393139323933393439353936393739383939394039413942394339443945394639473948394939503951395239533954395539563957395839593960396139623963396439653966396739683969397039713972397339743975397639773978397939803981398239833984398539863987398839893990399139923993399439953996399739983999400040014002400340044005400640074008400940104011401240134014401540164017401840194020402140224023402440254026402740284029403040314032403340344035403640374038403940404041404240434044404540464047404840494050405140524053405440554056405740584059406040614062406340644065406640674068406940704071407240734074407540764077407840794080408140824083408440854086408740884089409040914092409340944095409640974098409941004101410241034104410541064107410841094110411141124113411441154116411741184119412041214122412341244125412641274128412941304131413241334134413541364137413841394140414141424143414441454146414741484149415041514152415341544155415641574158415941604161416241634164416541664167416841694170417141724173417441754176417741784179418041814182418341844185418641874188418941904191419241934194419541964197419841994200420142024203420442054206420742084209421042114212421342144215421642174218421942204221422242234224422542264227422842294230423142324233423442354236423742384239424042414242424342444245424642474248424942504251425242534254425542564257425842594260426142624263426442654266426742684269427042714272427342744275427642774278427942804281428242834284428542864287428842894290429142924293429442954296429742984299430043014302430343044305430643074308430943104311431243134314431543164317431843194320432143224323432443254326432743284329433043314332433343344335433643374338433943404341434243434344434543464347434843494350435143524353435443554356435743584359436043614362436343644365436643674368436943704371437243734374437543764377437843794380438143824383438443854386438743884389439043914392439343944395439643974398439944004401440244034404440544064407440844094410441144124413441444154416441744184419442044214422442344244425442644274428442944304431443244334434443544364437443844394440444144424443444444454446444744484449445044514452445344544455445644574458445944604461446244634464446544664467446844694470447144724473447444754476447744784479448044814482448344844485448644874488448944904491449244934494449544964497449844994500450145024503450445054506450745084509451045114512451345144515451645174518451945204521452245234524452545264527452845294530453145324533453445354536453745384539454045414542454345444545454645474548454945504551455245534554455545564557455845594560456145624563456445654566456745684569457045714572457345744575457645774578457945804581458245834584458545864587458845894590459145924593459445954596459745984599460046014602460346044605460646074608460946104611461246134614461546164617461846194620462146224623462446254626462746284629463046314632463346344635463646374638463946404641464246434644464546464647464846494650465146524653465446554656465746584659466046614662466346644665466646674668466946704671467246734674467546764677467846794680468146824683468446854686468746884689469046914692469346944695469646974698469947004701470247034704470547064707470847094710471147124713471447154716471747184719472047214722472347244725472647274728472947304731473247334734473547364737473847394740474147424743474447454746474747484749475047514752475347544755475647574758475947604761476247634764476547664767476847694770477147724773477447754776477747784779478047814782478347844785478647874788478947904791479247934794479547964797479847994800480148024803480448054806480748084809481048114812481348144815481648174818481948204821482248234824482548264827482848294830483148324833483448354836483748384839484048414842484348444845484648474848484948504851485248534854485548564857485848594860486148624863486448654866486748684869487048714872487348744875487648774878487948804881488248834884488548864887488848894890489148924893489448954896489748984899490049014902490349044905490649074908490949104911491249134914491549164917491849194920492149224923492449254926492749284929493049314932493349344935493649374938493949404941494249434944494549464947494849494950495149524953495449554956495749584959496049614962496349644965496649674968496949704971497249734974497549764977497849794980498149824983498449854986498749884989499049914992499349944995
  1. /**
  2. * @license
  3. * Copyright Google LLC All Rights Reserved.
  4. *
  5. * Use of this source code is governed by an MIT-style license that can be
  6. * found in the LICENSE file at https://angular.io/license
  7. */
  8. (function (global, factory) {
  9. typeof exports === 'object' && typeof module !== 'undefined' ? factory(exports, require('@angular/cdk/platform'), require('@angular/cdk/coercion'), require('rxjs'), require('rxjs/operators'), require('@angular/core'), require('@angular/common'), require('@angular/cdk/scrolling'), require('@angular/cdk/bidi')) :
  10. typeof define === 'function' && define.amd ? define('@angular/cdk/drag-drop', ['exports', '@angular/cdk/platform', '@angular/cdk/coercion', 'rxjs', 'rxjs/operators', '@angular/core', '@angular/common', '@angular/cdk/scrolling', '@angular/cdk/bidi'], factory) :
  11. (factory((global.ng = global.ng || {}, global.ng.cdk = global.ng.cdk || {}, global.ng.cdk.dragDrop = {}),global.ng.cdk.platform,global.ng.cdk.coercion,global.rxjs,global.rxjs.operators,global.ng.core,global.ng.common,global.ng.cdk.scrolling,global.ng.cdk.bidi));
  12. }(this, (function (exports,platform,coercion,rxjs,operators,core,common,scrolling,bidi) { 'use strict';
  13. /**
  14. * @fileoverview added by tsickle
  15. * @suppress {checkTypes,extraRequire,missingOverride,missingReturn,unusedPrivateMembers,uselessCode} checked by tsc
  16. */
  17. /**
  18. * Shallow-extends a stylesheet object with another stylesheet object.
  19. * \@docs-private
  20. * @param {?} dest
  21. * @param {?} source
  22. * @return {?}
  23. */
  24. function extendStyles(dest, source) {
  25. for (var key in source) {
  26. if (source.hasOwnProperty(key)) {
  27. dest[key] = (/** @type {?} */ (source[key]));
  28. }
  29. }
  30. return dest;
  31. }
  32. /**
  33. * Toggles whether the native drag interactions should be enabled for an element.
  34. * \@docs-private
  35. * @param {?} element Element on which to toggle the drag interactions.
  36. * @param {?} enable Whether the drag interactions should be enabled.
  37. * @return {?}
  38. */
  39. function toggleNativeDragInteractions(element, enable) {
  40. /** @type {?} */
  41. var userSelect = enable ? '' : 'none';
  42. extendStyles(element.style, {
  43. touchAction: enable ? '' : 'none',
  44. webkitUserDrag: enable ? '' : 'none',
  45. webkitTapHighlightColor: enable ? '' : 'transparent',
  46. userSelect: userSelect,
  47. msUserSelect: userSelect,
  48. webkitUserSelect: userSelect,
  49. MozUserSelect: userSelect
  50. });
  51. }
  52. /**
  53. * @fileoverview added by tsickle
  54. * @suppress {checkTypes,extraRequire,missingOverride,missingReturn,unusedPrivateMembers,uselessCode} checked by tsc
  55. */
  56. /**
  57. * Parses a CSS time value to milliseconds.
  58. * @param {?} value
  59. * @return {?}
  60. */
  61. function parseCssTimeUnitsToMs(value) {
  62. // Some browsers will return it in seconds, whereas others will return milliseconds.
  63. /** @type {?} */
  64. var multiplier = value.toLowerCase().indexOf('ms') > -1 ? 1 : 1000;
  65. return parseFloat(value) * multiplier;
  66. }
  67. /**
  68. * Gets the transform transition duration, including the delay, of an element in milliseconds.
  69. * @param {?} element
  70. * @return {?}
  71. */
  72. function getTransformTransitionDurationInMs(element) {
  73. /** @type {?} */
  74. var computedStyle = getComputedStyle(element);
  75. /** @type {?} */
  76. var transitionedProperties = parseCssPropertyValue(computedStyle, 'transition-property');
  77. /** @type {?} */
  78. var property = transitionedProperties.find((/**
  79. * @param {?} prop
  80. * @return {?}
  81. */
  82. function (prop) { return prop === 'transform' || prop === 'all'; }));
  83. // If there's no transition for `all` or `transform`, we shouldn't do anything.
  84. if (!property) {
  85. return 0;
  86. }
  87. // Get the index of the property that we're interested in and match
  88. // it up to the same index in `transition-delay` and `transition-duration`.
  89. /** @type {?} */
  90. var propertyIndex = transitionedProperties.indexOf(property);
  91. /** @type {?} */
  92. var rawDurations = parseCssPropertyValue(computedStyle, 'transition-duration');
  93. /** @type {?} */
  94. var rawDelays = parseCssPropertyValue(computedStyle, 'transition-delay');
  95. return parseCssTimeUnitsToMs(rawDurations[propertyIndex]) +
  96. parseCssTimeUnitsToMs(rawDelays[propertyIndex]);
  97. }
  98. /**
  99. * Parses out multiple values from a computed style into an array.
  100. * @param {?} computedStyle
  101. * @param {?} name
  102. * @return {?}
  103. */
  104. function parseCssPropertyValue(computedStyle, name) {
  105. /** @type {?} */
  106. var value = computedStyle.getPropertyValue(name);
  107. return value.split(',').map((/**
  108. * @param {?} part
  109. * @return {?}
  110. */
  111. function (part) { return part.trim(); }));
  112. }
  113. /**
  114. * @fileoverview added by tsickle
  115. * @suppress {checkTypes,extraRequire,missingOverride,missingReturn,unusedPrivateMembers,uselessCode} checked by tsc
  116. */
  117. /**
  118. * Options that can be used to bind a passive event listener.
  119. * @type {?}
  120. */
  121. var passiveEventListenerOptions = platform.normalizePassiveListenerOptions({ passive: true });
  122. /**
  123. * Options that can be used to bind an active event listener.
  124. * @type {?}
  125. */
  126. var activeEventListenerOptions = platform.normalizePassiveListenerOptions({ passive: false });
  127. /**
  128. * Time in milliseconds for which to ignore mouse events, after
  129. * receiving a touch event. Used to avoid doing double work for
  130. * touch devices where the browser fires fake mouse events, in
  131. * addition to touch events.
  132. * @type {?}
  133. */
  134. var MOUSE_EVENT_IGNORE_TIME = 800;
  135. /**
  136. * Reference to a draggable item. Used to manipulate or dispose of the item.
  137. * \@docs-private
  138. * @template T
  139. */
  140. var /**
  141. * Reference to a draggable item. Used to manipulate or dispose of the item.
  142. * \@docs-private
  143. * @template T
  144. */
  145. DragRef = /** @class */ (function () {
  146. function DragRef(element, _config, _document, _ngZone, _viewportRuler, _dragDropRegistry) {
  147. var _this = this;
  148. this._config = _config;
  149. this._document = _document;
  150. this._ngZone = _ngZone;
  151. this._viewportRuler = _viewportRuler;
  152. this._dragDropRegistry = _dragDropRegistry;
  153. /**
  154. * CSS `transform` applied to the element when it isn't being dragged. We need a
  155. * passive transform in order for the dragged element to retain its new position
  156. * after the user has stopped dragging and because we need to know the relative
  157. * position in case they start dragging again. This corresponds to `element.style.transform`.
  158. */
  159. this._passiveTransform = { x: 0, y: 0 };
  160. /**
  161. * CSS `transform` that is applied to the element while it's being dragged.
  162. */
  163. this._activeTransform = { x: 0, y: 0 };
  164. /**
  165. * Emits when the item is being moved.
  166. */
  167. this._moveEvents = new rxjs.Subject();
  168. /**
  169. * Subscription to pointer movement events.
  170. */
  171. this._pointerMoveSubscription = rxjs.Subscription.EMPTY;
  172. /**
  173. * Subscription to the event that is dispatched when the user lifts their pointer.
  174. */
  175. this._pointerUpSubscription = rxjs.Subscription.EMPTY;
  176. /**
  177. * Subscription to the viewport being scrolled.
  178. */
  179. this._scrollSubscription = rxjs.Subscription.EMPTY;
  180. /**
  181. * Subscription to the viewport being resized.
  182. */
  183. this._resizeSubscription = rxjs.Subscription.EMPTY;
  184. /**
  185. * Cached reference to the boundary element.
  186. */
  187. this._boundaryElement = null;
  188. /**
  189. * Whether the native dragging interactions have been enabled on the root element.
  190. */
  191. this._nativeInteractionsEnabled = true;
  192. /**
  193. * Elements that can be used to drag the draggable item.
  194. */
  195. this._handles = [];
  196. /**
  197. * Registered handles that are currently disabled.
  198. */
  199. this._disabledHandles = new Set();
  200. /**
  201. * Layout direction of the item.
  202. */
  203. this._direction = 'ltr';
  204. /**
  205. * Amount of milliseconds to wait after the user has put their
  206. * pointer down before starting to drag the element.
  207. */
  208. this.dragStartDelay = 0;
  209. this._disabled = false;
  210. /**
  211. * Emits as the drag sequence is being prepared.
  212. */
  213. this.beforeStarted = new rxjs.Subject();
  214. /**
  215. * Emits when the user starts dragging the item.
  216. */
  217. this.started = new rxjs.Subject();
  218. /**
  219. * Emits when the user has released a drag item, before any animations have started.
  220. */
  221. this.released = new rxjs.Subject();
  222. /**
  223. * Emits when the user stops dragging an item in the container.
  224. */
  225. this.ended = new rxjs.Subject();
  226. /**
  227. * Emits when the user has moved the item into a new container.
  228. */
  229. this.entered = new rxjs.Subject();
  230. /**
  231. * Emits when the user removes the item its container by dragging it into another container.
  232. */
  233. this.exited = new rxjs.Subject();
  234. /**
  235. * Emits when the user drops the item inside a container.
  236. */
  237. this.dropped = new rxjs.Subject();
  238. /**
  239. * Emits as the user is dragging the item. Use with caution,
  240. * because this event will fire for every pixel that the user has dragged.
  241. */
  242. this.moved = this._moveEvents.asObservable();
  243. /**
  244. * Handler for the `mousedown`/`touchstart` events.
  245. */
  246. this._pointerDown = (/**
  247. * @param {?} event
  248. * @return {?}
  249. */
  250. function (event) {
  251. _this.beforeStarted.next();
  252. // Delegate the event based on whether it started from a handle or the element itself.
  253. if (_this._handles.length) {
  254. /** @type {?} */
  255. var targetHandle = _this._handles.find((/**
  256. * @param {?} handle
  257. * @return {?}
  258. */
  259. function (handle) {
  260. /** @type {?} */
  261. var target = event.target;
  262. return !!target && (target === handle || handle.contains((/** @type {?} */ (target))));
  263. }));
  264. if (targetHandle && !_this._disabledHandles.has(targetHandle) && !_this.disabled) {
  265. _this._initializeDragSequence(targetHandle, event);
  266. }
  267. }
  268. else if (!_this.disabled) {
  269. _this._initializeDragSequence(_this._rootElement, event);
  270. }
  271. });
  272. /**
  273. * Handler that is invoked when the user moves their pointer after they've initiated a drag.
  274. */
  275. this._pointerMove = (/**
  276. * @param {?} event
  277. * @return {?}
  278. */
  279. function (event) {
  280. if (!_this._hasStartedDragging) {
  281. /** @type {?} */
  282. var pointerPosition = _this._getPointerPositionOnPage(event);
  283. /** @type {?} */
  284. var distanceX = Math.abs(pointerPosition.x - _this._pickupPositionOnPage.x);
  285. /** @type {?} */
  286. var distanceY = Math.abs(pointerPosition.y - _this._pickupPositionOnPage.y);
  287. /** @type {?} */
  288. var isOverThreshold = distanceX + distanceY >= _this._config.dragStartThreshold;
  289. // Only start dragging after the user has moved more than the minimum distance in either
  290. // direction. Note that this is preferrable over doing something like `skip(minimumDistance)`
  291. // in the `pointerMove` subscription, because we're not guaranteed to have one move event
  292. // per pixel of movement (e.g. if the user moves their pointer quickly).
  293. if (isOverThreshold) {
  294. /** @type {?} */
  295. var isDelayElapsed = Date.now() >= _this._dragStartTime + (_this.dragStartDelay || 0);
  296. if (!isDelayElapsed) {
  297. _this._endDragSequence(event);
  298. return;
  299. }
  300. // Prevent other drag sequences from starting while something in the container is still
  301. // being dragged. This can happen while we're waiting for the drop animation to finish
  302. // and can cause errors, because some elements might still be moving around.
  303. if (!_this._dropContainer || !_this._dropContainer.isDragging()) {
  304. _this._hasStartedDragging = true;
  305. _this._ngZone.run((/**
  306. * @return {?}
  307. */
  308. function () { return _this._startDragSequence(event); }));
  309. }
  310. }
  311. return;
  312. }
  313. // We only need the preview dimensions if we have a boundary element.
  314. if (_this._boundaryElement) {
  315. // Cache the preview element rect if we haven't cached it already or if
  316. // we cached it too early before the element dimensions were computed.
  317. if (!_this._previewRect || (!_this._previewRect.width && !_this._previewRect.height)) {
  318. _this._previewRect = (_this._preview || _this._rootElement).getBoundingClientRect();
  319. }
  320. }
  321. /** @type {?} */
  322. var constrainedPointerPosition = _this._getConstrainedPointerPosition(event);
  323. _this._hasMoved = true;
  324. event.preventDefault();
  325. _this._updatePointerDirectionDelta(constrainedPointerPosition);
  326. if (_this._dropContainer) {
  327. _this._updateActiveDropContainer(constrainedPointerPosition);
  328. }
  329. else {
  330. /** @type {?} */
  331. var activeTransform = _this._activeTransform;
  332. activeTransform.x =
  333. constrainedPointerPosition.x - _this._pickupPositionOnPage.x + _this._passiveTransform.x;
  334. activeTransform.y =
  335. constrainedPointerPosition.y - _this._pickupPositionOnPage.y + _this._passiveTransform.y;
  336. _this._applyRootElementTransform(activeTransform.x, activeTransform.y);
  337. // Apply transform as attribute if dragging and svg element to work for IE
  338. if (typeof SVGElement !== 'undefined' && _this._rootElement instanceof SVGElement) {
  339. /** @type {?} */
  340. var appliedTransform = "translate(" + activeTransform.x + " " + activeTransform.y + ")";
  341. _this._rootElement.setAttribute('transform', appliedTransform);
  342. }
  343. }
  344. // Since this event gets fired for every pixel while dragging, we only
  345. // want to fire it if the consumer opted into it. Also we have to
  346. // re-enter the zone because we run all of the events on the outside.
  347. if (_this._moveEvents.observers.length) {
  348. _this._ngZone.run((/**
  349. * @return {?}
  350. */
  351. function () {
  352. _this._moveEvents.next({
  353. source: _this,
  354. pointerPosition: constrainedPointerPosition,
  355. event: event,
  356. distance: _this._getDragDistance(constrainedPointerPosition),
  357. delta: _this._pointerDirectionDelta
  358. });
  359. }));
  360. }
  361. });
  362. /**
  363. * Handler that is invoked when the user lifts their pointer up, after initiating a drag.
  364. */
  365. this._pointerUp = (/**
  366. * @param {?} event
  367. * @return {?}
  368. */
  369. function (event) {
  370. _this._endDragSequence(event);
  371. });
  372. this.withRootElement(element);
  373. _dragDropRegistry.registerDragItem(this);
  374. }
  375. Object.defineProperty(DragRef.prototype, "disabled", {
  376. /** Whether starting to drag this element is disabled. */
  377. get: /**
  378. * Whether starting to drag this element is disabled.
  379. * @return {?}
  380. */
  381. function () {
  382. return this._disabled || !!(this._dropContainer && this._dropContainer.disabled);
  383. },
  384. set: /**
  385. * @param {?} value
  386. * @return {?}
  387. */
  388. function (value) {
  389. /** @type {?} */
  390. var newValue = coercion.coerceBooleanProperty(value);
  391. if (newValue !== this._disabled) {
  392. this._disabled = newValue;
  393. this._toggleNativeDragInteractions();
  394. }
  395. },
  396. enumerable: true,
  397. configurable: true
  398. });
  399. /**
  400. * Returns the element that is being used as a placeholder
  401. * while the current element is being dragged.
  402. */
  403. /**
  404. * Returns the element that is being used as a placeholder
  405. * while the current element is being dragged.
  406. * @return {?}
  407. */
  408. DragRef.prototype.getPlaceholderElement = /**
  409. * Returns the element that is being used as a placeholder
  410. * while the current element is being dragged.
  411. * @return {?}
  412. */
  413. function () {
  414. return this._placeholder;
  415. };
  416. /** Returns the root draggable element. */
  417. /**
  418. * Returns the root draggable element.
  419. * @return {?}
  420. */
  421. DragRef.prototype.getRootElement = /**
  422. * Returns the root draggable element.
  423. * @return {?}
  424. */
  425. function () {
  426. return this._rootElement;
  427. };
  428. /** Registers the handles that can be used to drag the element. */
  429. /**
  430. * Registers the handles that can be used to drag the element.
  431. * @template THIS
  432. * @this {THIS}
  433. * @param {?} handles
  434. * @return {THIS}
  435. */
  436. DragRef.prototype.withHandles = /**
  437. * Registers the handles that can be used to drag the element.
  438. * @template THIS
  439. * @this {THIS}
  440. * @param {?} handles
  441. * @return {THIS}
  442. */
  443. function (handles) {
  444. (/** @type {?} */ (this))._handles = handles.map((/**
  445. * @param {?} handle
  446. * @return {?}
  447. */
  448. function (handle) { return coercion.coerceElement(handle); }));
  449. (/** @type {?} */ (this))._handles.forEach((/**
  450. * @param {?} handle
  451. * @return {?}
  452. */
  453. function (handle) { return toggleNativeDragInteractions(handle, false); }));
  454. (/** @type {?} */ (this))._toggleNativeDragInteractions();
  455. return (/** @type {?} */ (this));
  456. };
  457. /**
  458. * Registers the template that should be used for the drag preview.
  459. * @param template Template that from which to stamp out the preview.
  460. */
  461. /**
  462. * Registers the template that should be used for the drag preview.
  463. * @template THIS
  464. * @this {THIS}
  465. * @param {?} template Template that from which to stamp out the preview.
  466. * @return {THIS}
  467. */
  468. DragRef.prototype.withPreviewTemplate = /**
  469. * Registers the template that should be used for the drag preview.
  470. * @template THIS
  471. * @this {THIS}
  472. * @param {?} template Template that from which to stamp out the preview.
  473. * @return {THIS}
  474. */
  475. function (template) {
  476. (/** @type {?} */ (this))._previewTemplate = template;
  477. return (/** @type {?} */ (this));
  478. };
  479. /**
  480. * Registers the template that should be used for the drag placeholder.
  481. * @param template Template that from which to stamp out the placeholder.
  482. */
  483. /**
  484. * Registers the template that should be used for the drag placeholder.
  485. * @template THIS
  486. * @this {THIS}
  487. * @param {?} template Template that from which to stamp out the placeholder.
  488. * @return {THIS}
  489. */
  490. DragRef.prototype.withPlaceholderTemplate = /**
  491. * Registers the template that should be used for the drag placeholder.
  492. * @template THIS
  493. * @this {THIS}
  494. * @param {?} template Template that from which to stamp out the placeholder.
  495. * @return {THIS}
  496. */
  497. function (template) {
  498. (/** @type {?} */ (this))._placeholderTemplate = template;
  499. return (/** @type {?} */ (this));
  500. };
  501. /**
  502. * Sets an alternate drag root element. The root element is the element that will be moved as
  503. * the user is dragging. Passing an alternate root element is useful when trying to enable
  504. * dragging on an element that you might not have access to.
  505. */
  506. /**
  507. * Sets an alternate drag root element. The root element is the element that will be moved as
  508. * the user is dragging. Passing an alternate root element is useful when trying to enable
  509. * dragging on an element that you might not have access to.
  510. * @template THIS
  511. * @this {THIS}
  512. * @param {?} rootElement
  513. * @return {THIS}
  514. */
  515. DragRef.prototype.withRootElement = /**
  516. * Sets an alternate drag root element. The root element is the element that will be moved as
  517. * the user is dragging. Passing an alternate root element is useful when trying to enable
  518. * dragging on an element that you might not have access to.
  519. * @template THIS
  520. * @this {THIS}
  521. * @param {?} rootElement
  522. * @return {THIS}
  523. */
  524. function (rootElement) {
  525. /** @type {?} */
  526. var element = coercion.coerceElement(rootElement);
  527. if (element !== (/** @type {?} */ (this))._rootElement) {
  528. if ((/** @type {?} */ (this))._rootElement) {
  529. (/** @type {?} */ (this))._removeRootElementListeners((/** @type {?} */ (this))._rootElement);
  530. }
  531. element.addEventListener('mousedown', (/** @type {?} */ (this))._pointerDown, activeEventListenerOptions);
  532. element.addEventListener('touchstart', (/** @type {?} */ (this))._pointerDown, passiveEventListenerOptions);
  533. (/** @type {?} */ (this))._initialTransform = undefined;
  534. (/** @type {?} */ (this))._rootElement = element;
  535. }
  536. return (/** @type {?} */ (this));
  537. };
  538. /**
  539. * Element to which the draggable's position will be constrained.
  540. */
  541. /**
  542. * Element to which the draggable's position will be constrained.
  543. * @template THIS
  544. * @this {THIS}
  545. * @param {?} boundaryElement
  546. * @return {THIS}
  547. */
  548. DragRef.prototype.withBoundaryElement = /**
  549. * Element to which the draggable's position will be constrained.
  550. * @template THIS
  551. * @this {THIS}
  552. * @param {?} boundaryElement
  553. * @return {THIS}
  554. */
  555. function (boundaryElement) {
  556. var _this = this;
  557. (/** @type {?} */ (this))._boundaryElement = boundaryElement ? coercion.coerceElement(boundaryElement) : null;
  558. (/** @type {?} */ (this))._resizeSubscription.unsubscribe();
  559. if (boundaryElement) {
  560. (/** @type {?} */ (this))._resizeSubscription = (/** @type {?} */ (this))._viewportRuler
  561. .change(10)
  562. .subscribe((/**
  563. * @return {?}
  564. */
  565. function () { return (/** @type {?} */ (_this))._containInsideBoundaryOnResize(); }));
  566. }
  567. return (/** @type {?} */ (this));
  568. };
  569. /** Removes the dragging functionality from the DOM element. */
  570. /**
  571. * Removes the dragging functionality from the DOM element.
  572. * @return {?}
  573. */
  574. DragRef.prototype.dispose = /**
  575. * Removes the dragging functionality from the DOM element.
  576. * @return {?}
  577. */
  578. function () {
  579. this._removeRootElementListeners(this._rootElement);
  580. // Do this check before removing from the registry since it'll
  581. // stop being considered as dragged once it is removed.
  582. if (this.isDragging()) {
  583. // Since we move out the element to the end of the body while it's being
  584. // dragged, we have to make sure that it's removed if it gets destroyed.
  585. removeElement(this._rootElement);
  586. }
  587. this._destroyPreview();
  588. this._destroyPlaceholder();
  589. this._dragDropRegistry.removeDragItem(this);
  590. this._removeSubscriptions();
  591. this.beforeStarted.complete();
  592. this.started.complete();
  593. this.released.complete();
  594. this.ended.complete();
  595. this.entered.complete();
  596. this.exited.complete();
  597. this.dropped.complete();
  598. this._moveEvents.complete();
  599. this._handles = [];
  600. this._disabledHandles.clear();
  601. this._dropContainer = undefined;
  602. this._boundaryElement = this._rootElement = this._placeholderTemplate =
  603. this._previewTemplate = this._nextSibling = (/** @type {?} */ (null));
  604. };
  605. /** Checks whether the element is currently being dragged. */
  606. /**
  607. * Checks whether the element is currently being dragged.
  608. * @return {?}
  609. */
  610. DragRef.prototype.isDragging = /**
  611. * Checks whether the element is currently being dragged.
  612. * @return {?}
  613. */
  614. function () {
  615. return this._hasStartedDragging && this._dragDropRegistry.isDragging(this);
  616. };
  617. /** Resets a standalone drag item to its initial position. */
  618. /**
  619. * Resets a standalone drag item to its initial position.
  620. * @return {?}
  621. */
  622. DragRef.prototype.reset = /**
  623. * Resets a standalone drag item to its initial position.
  624. * @return {?}
  625. */
  626. function () {
  627. this._rootElement.style.transform = this._initialTransform || '';
  628. this._activeTransform = { x: 0, y: 0 };
  629. this._passiveTransform = { x: 0, y: 0 };
  630. };
  631. /**
  632. * Sets a handle as disabled. While a handle is disabled, it'll capture and interrupt dragging.
  633. * @param handle Handle element that should be disabled.
  634. */
  635. /**
  636. * Sets a handle as disabled. While a handle is disabled, it'll capture and interrupt dragging.
  637. * @param {?} handle Handle element that should be disabled.
  638. * @return {?}
  639. */
  640. DragRef.prototype.disableHandle = /**
  641. * Sets a handle as disabled. While a handle is disabled, it'll capture and interrupt dragging.
  642. * @param {?} handle Handle element that should be disabled.
  643. * @return {?}
  644. */
  645. function (handle) {
  646. if (this._handles.indexOf(handle) > -1) {
  647. this._disabledHandles.add(handle);
  648. }
  649. };
  650. /**
  651. * Enables a handle, if it has been disabled.
  652. * @param handle Handle element to be enabled.
  653. */
  654. /**
  655. * Enables a handle, if it has been disabled.
  656. * @param {?} handle Handle element to be enabled.
  657. * @return {?}
  658. */
  659. DragRef.prototype.enableHandle = /**
  660. * Enables a handle, if it has been disabled.
  661. * @param {?} handle Handle element to be enabled.
  662. * @return {?}
  663. */
  664. function (handle) {
  665. this._disabledHandles.delete(handle);
  666. };
  667. /** Sets the layout direction of the draggable item. */
  668. /**
  669. * Sets the layout direction of the draggable item.
  670. * @template THIS
  671. * @this {THIS}
  672. * @param {?} direction
  673. * @return {THIS}
  674. */
  675. DragRef.prototype.withDirection = /**
  676. * Sets the layout direction of the draggable item.
  677. * @template THIS
  678. * @this {THIS}
  679. * @param {?} direction
  680. * @return {THIS}
  681. */
  682. function (direction) {
  683. (/** @type {?} */ (this))._direction = direction;
  684. return (/** @type {?} */ (this));
  685. };
  686. /** Sets the container that the item is part of. */
  687. /**
  688. * Sets the container that the item is part of.
  689. * @param {?} container
  690. * @return {?}
  691. */
  692. DragRef.prototype._withDropContainer = /**
  693. * Sets the container that the item is part of.
  694. * @param {?} container
  695. * @return {?}
  696. */
  697. function (container) {
  698. this._dropContainer = container;
  699. };
  700. /**
  701. * Gets the current position in pixels the draggable outside of a drop container.
  702. */
  703. /**
  704. * Gets the current position in pixels the draggable outside of a drop container.
  705. * @return {?}
  706. */
  707. DragRef.prototype.getFreeDragPosition = /**
  708. * Gets the current position in pixels the draggable outside of a drop container.
  709. * @return {?}
  710. */
  711. function () {
  712. /** @type {?} */
  713. var position = this.isDragging() ? this._activeTransform : this._passiveTransform;
  714. return { x: position.x, y: position.y };
  715. };
  716. /**
  717. * Sets the current position in pixels the draggable outside of a drop container.
  718. * @param value New position to be set.
  719. */
  720. /**
  721. * Sets the current position in pixels the draggable outside of a drop container.
  722. * @template THIS
  723. * @this {THIS}
  724. * @param {?} value New position to be set.
  725. * @return {THIS}
  726. */
  727. DragRef.prototype.setFreeDragPosition = /**
  728. * Sets the current position in pixels the draggable outside of a drop container.
  729. * @template THIS
  730. * @this {THIS}
  731. * @param {?} value New position to be set.
  732. * @return {THIS}
  733. */
  734. function (value) {
  735. (/** @type {?} */ (this))._activeTransform = { x: 0, y: 0 };
  736. (/** @type {?} */ (this))._passiveTransform.x = value.x;
  737. (/** @type {?} */ (this))._passiveTransform.y = value.y;
  738. if (!(/** @type {?} */ (this))._dropContainer) {
  739. (/** @type {?} */ (this))._applyRootElementTransform(value.x, value.y);
  740. }
  741. return (/** @type {?} */ (this));
  742. };
  743. /** Updates the item's sort order based on the last-known pointer position. */
  744. /**
  745. * Updates the item's sort order based on the last-known pointer position.
  746. * @return {?}
  747. */
  748. DragRef.prototype._sortFromLastPointerPosition = /**
  749. * Updates the item's sort order based on the last-known pointer position.
  750. * @return {?}
  751. */
  752. function () {
  753. /** @type {?} */
  754. var position = this._pointerPositionAtLastDirectionChange;
  755. if (position && this._dropContainer) {
  756. this._updateActiveDropContainer(position);
  757. }
  758. };
  759. /** Unsubscribes from the global subscriptions. */
  760. /**
  761. * Unsubscribes from the global subscriptions.
  762. * @private
  763. * @return {?}
  764. */
  765. DragRef.prototype._removeSubscriptions = /**
  766. * Unsubscribes from the global subscriptions.
  767. * @private
  768. * @return {?}
  769. */
  770. function () {
  771. this._pointerMoveSubscription.unsubscribe();
  772. this._pointerUpSubscription.unsubscribe();
  773. this._scrollSubscription.unsubscribe();
  774. };
  775. /** Destroys the preview element and its ViewRef. */
  776. /**
  777. * Destroys the preview element and its ViewRef.
  778. * @private
  779. * @return {?}
  780. */
  781. DragRef.prototype._destroyPreview = /**
  782. * Destroys the preview element and its ViewRef.
  783. * @private
  784. * @return {?}
  785. */
  786. function () {
  787. if (this._preview) {
  788. removeElement(this._preview);
  789. }
  790. if (this._previewRef) {
  791. this._previewRef.destroy();
  792. }
  793. this._preview = this._previewRef = (/** @type {?} */ (null));
  794. };
  795. /** Destroys the placeholder element and its ViewRef. */
  796. /**
  797. * Destroys the placeholder element and its ViewRef.
  798. * @private
  799. * @return {?}
  800. */
  801. DragRef.prototype._destroyPlaceholder = /**
  802. * Destroys the placeholder element and its ViewRef.
  803. * @private
  804. * @return {?}
  805. */
  806. function () {
  807. if (this._placeholder) {
  808. removeElement(this._placeholder);
  809. }
  810. if (this._placeholderRef) {
  811. this._placeholderRef.destroy();
  812. }
  813. this._placeholder = this._placeholderRef = (/** @type {?} */ (null));
  814. };
  815. /**
  816. * Clears subscriptions and stops the dragging sequence.
  817. * @param event Browser event object that ended the sequence.
  818. */
  819. /**
  820. * Clears subscriptions and stops the dragging sequence.
  821. * @private
  822. * @param {?} event Browser event object that ended the sequence.
  823. * @return {?}
  824. */
  825. DragRef.prototype._endDragSequence = /**
  826. * Clears subscriptions and stops the dragging sequence.
  827. * @private
  828. * @param {?} event Browser event object that ended the sequence.
  829. * @return {?}
  830. */
  831. function (event) {
  832. var _this = this;
  833. // Note that here we use `isDragging` from the service, rather than from `this`.
  834. // The difference is that the one from the service reflects whether a dragging sequence
  835. // has been initiated, whereas the one on `this` includes whether the user has passed
  836. // the minimum dragging threshold.
  837. if (!this._dragDropRegistry.isDragging(this)) {
  838. return;
  839. }
  840. this._removeSubscriptions();
  841. this._dragDropRegistry.stopDragging(this);
  842. this._toggleNativeDragInteractions();
  843. if (this._handles) {
  844. this._rootElement.style.webkitTapHighlightColor = this._rootElementTapHighlight;
  845. }
  846. if (!this._hasStartedDragging) {
  847. return;
  848. }
  849. this.released.next({ source: this });
  850. if (this._dropContainer) {
  851. // Stop scrolling immediately, instead of waiting for the animation to finish.
  852. this._dropContainer._stopScrolling();
  853. this._animatePreviewToPlaceholder().then((/**
  854. * @return {?}
  855. */
  856. function () {
  857. _this._cleanupDragArtifacts(event);
  858. _this._cleanupCachedDimensions();
  859. _this._dragDropRegistry.stopDragging(_this);
  860. }));
  861. }
  862. else {
  863. // Convert the active transform into a passive one. This means that next time
  864. // the user starts dragging the item, its position will be calculated relatively
  865. // to the new passive transform.
  866. this._passiveTransform.x = this._activeTransform.x;
  867. this._passiveTransform.y = this._activeTransform.y;
  868. this._ngZone.run((/**
  869. * @return {?}
  870. */
  871. function () {
  872. _this.ended.next({
  873. source: _this,
  874. distance: _this._getDragDistance(_this._getPointerPositionOnPage(event))
  875. });
  876. }));
  877. this._cleanupCachedDimensions();
  878. this._dragDropRegistry.stopDragging(this);
  879. }
  880. };
  881. /** Starts the dragging sequence. */
  882. /**
  883. * Starts the dragging sequence.
  884. * @private
  885. * @param {?} event
  886. * @return {?}
  887. */
  888. DragRef.prototype._startDragSequence = /**
  889. * Starts the dragging sequence.
  890. * @private
  891. * @param {?} event
  892. * @return {?}
  893. */
  894. function (event) {
  895. // Emit the event on the item before the one on the container.
  896. this.started.next({ source: this });
  897. if (isTouchEvent(event)) {
  898. this._lastTouchEventTime = Date.now();
  899. }
  900. this._toggleNativeDragInteractions();
  901. if (this._dropContainer) {
  902. /** @type {?} */
  903. var element = this._rootElement;
  904. // Grab the `nextSibling` before the preview and placeholder
  905. // have been created so we don't get the preview by accident.
  906. this._nextSibling = element.nextSibling;
  907. /** @type {?} */
  908. var preview = this._preview = this._createPreviewElement();
  909. /** @type {?} */
  910. var placeholder = this._placeholder = this._createPlaceholderElement();
  911. // We move the element out at the end of the body and we make it hidden, because keeping it in
  912. // place will throw off the consumer's `:last-child` selectors. We can't remove the element
  913. // from the DOM completely, because iOS will stop firing all subsequent events in the chain.
  914. element.style.display = 'none';
  915. this._document.body.appendChild((/** @type {?} */ (element.parentNode)).replaceChild(placeholder, element));
  916. getPreviewInsertionPoint(this._document).appendChild(preview);
  917. this._dropContainer.start();
  918. }
  919. };
  920. /**
  921. * Sets up the different variables and subscriptions
  922. * that will be necessary for the dragging sequence.
  923. * @param referenceElement Element that started the drag sequence.
  924. * @param event Browser event object that started the sequence.
  925. */
  926. /**
  927. * Sets up the different variables and subscriptions
  928. * that will be necessary for the dragging sequence.
  929. * @private
  930. * @param {?} referenceElement Element that started the drag sequence.
  931. * @param {?} event Browser event object that started the sequence.
  932. * @return {?}
  933. */
  934. DragRef.prototype._initializeDragSequence = /**
  935. * Sets up the different variables and subscriptions
  936. * that will be necessary for the dragging sequence.
  937. * @private
  938. * @param {?} referenceElement Element that started the drag sequence.
  939. * @param {?} event Browser event object that started the sequence.
  940. * @return {?}
  941. */
  942. function (referenceElement, event) {
  943. var _this = this;
  944. // Always stop propagation for the event that initializes
  945. // the dragging sequence, in order to prevent it from potentially
  946. // starting another sequence for a draggable parent somewhere up the DOM tree.
  947. event.stopPropagation();
  948. /** @type {?} */
  949. var isDragging = this.isDragging();
  950. /** @type {?} */
  951. var isTouchSequence = isTouchEvent(event);
  952. /** @type {?} */
  953. var isAuxiliaryMouseButton = !isTouchSequence && ((/** @type {?} */ (event))).button !== 0;
  954. /** @type {?} */
  955. var rootElement = this._rootElement;
  956. /** @type {?} */
  957. var isSyntheticEvent = !isTouchSequence && this._lastTouchEventTime &&
  958. this._lastTouchEventTime + MOUSE_EVENT_IGNORE_TIME > Date.now();
  959. // If the event started from an element with the native HTML drag&drop, it'll interfere
  960. // with our own dragging (e.g. `img` tags do it by default). Prevent the default action
  961. // to stop it from happening. Note that preventing on `dragstart` also seems to work, but
  962. // it's flaky and it fails if the user drags it away quickly. Also note that we only want
  963. // to do this for `mousedown` since doing the same for `touchstart` will stop any `click`
  964. // events from firing on touch devices.
  965. if (event.target && ((/** @type {?} */ (event.target))).draggable && event.type === 'mousedown') {
  966. event.preventDefault();
  967. }
  968. // Abort if the user is already dragging or is using a mouse button other than the primary one.
  969. if (isDragging || isAuxiliaryMouseButton || isSyntheticEvent) {
  970. return;
  971. }
  972. // If we've got handles, we need to disable the tap highlight on the entire root element,
  973. // otherwise iOS will still add it, even though all the drag interactions on the handle
  974. // are disabled.
  975. if (this._handles.length) {
  976. this._rootElementTapHighlight = rootElement.style.webkitTapHighlightColor;
  977. rootElement.style.webkitTapHighlightColor = 'transparent';
  978. }
  979. this._hasStartedDragging = this._hasMoved = false;
  980. this._initialContainer = (/** @type {?} */ (this._dropContainer));
  981. // Avoid multiple subscriptions and memory leaks when multi touch
  982. // (isDragging check above isn't enough because of possible temporal and/or dimensional delays)
  983. this._removeSubscriptions();
  984. this._pointerMoveSubscription = this._dragDropRegistry.pointerMove.subscribe(this._pointerMove);
  985. this._pointerUpSubscription = this._dragDropRegistry.pointerUp.subscribe(this._pointerUp);
  986. this._scrollSubscription = this._dragDropRegistry.scroll.pipe(operators.startWith(null)).subscribe((/**
  987. * @return {?}
  988. */
  989. function () {
  990. _this._scrollPosition = _this._viewportRuler.getViewportScrollPosition();
  991. }));
  992. if (this._boundaryElement) {
  993. this._boundaryRect = this._boundaryElement.getBoundingClientRect();
  994. }
  995. // If we have a custom preview template, the element won't be visible anyway so we avoid the
  996. // extra `getBoundingClientRect` calls and just move the preview next to the cursor.
  997. this._pickupPositionInElement = this._previewTemplate && this._previewTemplate.template ?
  998. { x: 0, y: 0 } :
  999. this._getPointerPositionInElement(referenceElement, event);
  1000. /** @type {?} */
  1001. var pointerPosition = this._pickupPositionOnPage = this._getPointerPositionOnPage(event);
  1002. this._pointerDirectionDelta = { x: 0, y: 0 };
  1003. this._pointerPositionAtLastDirectionChange = { x: pointerPosition.x, y: pointerPosition.y };
  1004. this._dragStartTime = Date.now();
  1005. this._dragDropRegistry.startDragging(this, event);
  1006. };
  1007. /** Cleans up the DOM artifacts that were added to facilitate the element being dragged. */
  1008. /**
  1009. * Cleans up the DOM artifacts that were added to facilitate the element being dragged.
  1010. * @private
  1011. * @param {?} event
  1012. * @return {?}
  1013. */
  1014. DragRef.prototype._cleanupDragArtifacts = /**
  1015. * Cleans up the DOM artifacts that were added to facilitate the element being dragged.
  1016. * @private
  1017. * @param {?} event
  1018. * @return {?}
  1019. */
  1020. function (event) {
  1021. var _this = this;
  1022. // Restore the element's visibility and insert it at its old position in the DOM.
  1023. // It's important that we maintain the position, because moving the element around in the DOM
  1024. // can throw off `NgFor` which does smart diffing and re-creates elements only when necessary,
  1025. // while moving the existing elements in all other cases.
  1026. this._rootElement.style.display = '';
  1027. if (this._nextSibling) {
  1028. (/** @type {?} */ (this._nextSibling.parentNode)).insertBefore(this._rootElement, this._nextSibling);
  1029. }
  1030. else {
  1031. coercion.coerceElement(this._initialContainer.element).appendChild(this._rootElement);
  1032. }
  1033. this._destroyPreview();
  1034. this._destroyPlaceholder();
  1035. this._boundaryRect = this._previewRect = undefined;
  1036. // Re-enter the NgZone since we bound `document` events on the outside.
  1037. this._ngZone.run((/**
  1038. * @return {?}
  1039. */
  1040. function () {
  1041. /** @type {?} */
  1042. var container = (/** @type {?} */ (_this._dropContainer));
  1043. /** @type {?} */
  1044. var currentIndex = container.getItemIndex(_this);
  1045. /** @type {?} */
  1046. var pointerPosition = _this._getPointerPositionOnPage(event);
  1047. /** @type {?} */
  1048. var distance = _this._getDragDistance(_this._getPointerPositionOnPage(event));
  1049. /** @type {?} */
  1050. var isPointerOverContainer = container._isOverContainer(pointerPosition.x, pointerPosition.y);
  1051. _this.ended.next({ source: _this, distance: distance });
  1052. _this.dropped.next({
  1053. item: _this,
  1054. currentIndex: currentIndex,
  1055. previousIndex: _this._initialContainer.getItemIndex(_this),
  1056. container: container,
  1057. previousContainer: _this._initialContainer,
  1058. isPointerOverContainer: isPointerOverContainer,
  1059. distance: distance
  1060. });
  1061. container.drop(_this, currentIndex, _this._initialContainer, isPointerOverContainer, distance);
  1062. _this._dropContainer = _this._initialContainer;
  1063. }));
  1064. };
  1065. /**
  1066. * Updates the item's position in its drop container, or moves it
  1067. * into a new one, depending on its current drag position.
  1068. */
  1069. /**
  1070. * Updates the item's position in its drop container, or moves it
  1071. * into a new one, depending on its current drag position.
  1072. * @private
  1073. * @param {?} __0
  1074. * @return {?}
  1075. */
  1076. DragRef.prototype._updateActiveDropContainer = /**
  1077. * Updates the item's position in its drop container, or moves it
  1078. * into a new one, depending on its current drag position.
  1079. * @private
  1080. * @param {?} __0
  1081. * @return {?}
  1082. */
  1083. function (_a) {
  1084. var _this = this;
  1085. var x = _a.x, y = _a.y;
  1086. // Drop container that draggable has been moved into.
  1087. /** @type {?} */
  1088. var newContainer = this._initialContainer._getSiblingContainerFromPosition(this, x, y);
  1089. // If we couldn't find a new container to move the item into, and the item has left its
  1090. // initial container, check whether the it's over the initial container. This handles the
  1091. // case where two containers are connected one way and the user tries to undo dragging an
  1092. // item into a new container.
  1093. if (!newContainer && this._dropContainer !== this._initialContainer &&
  1094. this._initialContainer._isOverContainer(x, y)) {
  1095. newContainer = this._initialContainer;
  1096. }
  1097. if (newContainer && newContainer !== this._dropContainer) {
  1098. this._ngZone.run((/**
  1099. * @return {?}
  1100. */
  1101. function () {
  1102. // Notify the old container that the item has left.
  1103. _this.exited.next({ item: _this, container: (/** @type {?} */ (_this._dropContainer)) });
  1104. (/** @type {?} */ (_this._dropContainer)).exit(_this);
  1105. // Notify the new container that the item has entered.
  1106. _this._dropContainer = (/** @type {?} */ (newContainer));
  1107. _this._dropContainer.enter(_this, x, y);
  1108. _this.entered.next({
  1109. item: _this,
  1110. container: (/** @type {?} */ (newContainer)),
  1111. currentIndex: (/** @type {?} */ (newContainer)).getItemIndex(_this)
  1112. });
  1113. }));
  1114. }
  1115. (/** @type {?} */ (this._dropContainer))._startScrollingIfNecessary(x, y);
  1116. (/** @type {?} */ (this._dropContainer))._sortItem(this, x, y, this._pointerDirectionDelta);
  1117. this._preview.style.transform =
  1118. getTransform(x - this._pickupPositionInElement.x, y - this._pickupPositionInElement.y);
  1119. };
  1120. /**
  1121. * Creates the element that will be rendered next to the user's pointer
  1122. * and will be used as a preview of the element that is being dragged.
  1123. */
  1124. /**
  1125. * Creates the element that will be rendered next to the user's pointer
  1126. * and will be used as a preview of the element that is being dragged.
  1127. * @private
  1128. * @return {?}
  1129. */
  1130. DragRef.prototype._createPreviewElement = /**
  1131. * Creates the element that will be rendered next to the user's pointer
  1132. * and will be used as a preview of the element that is being dragged.
  1133. * @private
  1134. * @return {?}
  1135. */
  1136. function () {
  1137. /** @type {?} */
  1138. var previewConfig = this._previewTemplate;
  1139. /** @type {?} */
  1140. var previewTemplate = previewConfig ? previewConfig.template : null;
  1141. /** @type {?} */
  1142. var preview;
  1143. if (previewTemplate) {
  1144. /** @type {?} */
  1145. var viewRef = (/** @type {?} */ (previewConfig)).viewContainer.createEmbeddedView(previewTemplate, (/** @type {?} */ (previewConfig)).context);
  1146. preview = getRootNode(viewRef, this._document);
  1147. this._previewRef = viewRef;
  1148. preview.style.transform =
  1149. getTransform(this._pickupPositionOnPage.x, this._pickupPositionOnPage.y);
  1150. }
  1151. else {
  1152. /** @type {?} */
  1153. var element = this._rootElement;
  1154. /** @type {?} */
  1155. var elementRect = element.getBoundingClientRect();
  1156. preview = deepCloneNode(element);
  1157. preview.style.width = elementRect.width + "px";
  1158. preview.style.height = elementRect.height + "px";
  1159. preview.style.transform = getTransform(elementRect.left, elementRect.top);
  1160. }
  1161. extendStyles(preview.style, {
  1162. // It's important that we disable the pointer events on the preview, because
  1163. // it can throw off the `document.elementFromPoint` calls in the `CdkDropList`.
  1164. pointerEvents: 'none',
  1165. // We have to reset the margin, because can throw off positioning relative to the viewport.
  1166. margin: '0',
  1167. position: 'fixed',
  1168. top: '0',
  1169. left: '0',
  1170. zIndex: '1000'
  1171. });
  1172. toggleNativeDragInteractions(preview, false);
  1173. preview.classList.add('cdk-drag-preview');
  1174. preview.setAttribute('dir', this._direction);
  1175. return preview;
  1176. };
  1177. /**
  1178. * Animates the preview element from its current position to the location of the drop placeholder.
  1179. * @returns Promise that resolves when the animation completes.
  1180. */
  1181. /**
  1182. * Animates the preview element from its current position to the location of the drop placeholder.
  1183. * @private
  1184. * @return {?} Promise that resolves when the animation completes.
  1185. */
  1186. DragRef.prototype._animatePreviewToPlaceholder = /**
  1187. * Animates the preview element from its current position to the location of the drop placeholder.
  1188. * @private
  1189. * @return {?} Promise that resolves when the animation completes.
  1190. */
  1191. function () {
  1192. var _this = this;
  1193. // If the user hasn't moved yet, the transitionend event won't fire.
  1194. if (!this._hasMoved) {
  1195. return Promise.resolve();
  1196. }
  1197. /** @type {?} */
  1198. var placeholderRect = this._placeholder.getBoundingClientRect();
  1199. // Apply the class that adds a transition to the preview.
  1200. this._preview.classList.add('cdk-drag-animating');
  1201. // Move the preview to the placeholder position.
  1202. this._preview.style.transform = getTransform(placeholderRect.left, placeholderRect.top);
  1203. // If the element doesn't have a `transition`, the `transitionend` event won't fire. Since
  1204. // we need to trigger a style recalculation in order for the `cdk-drag-animating` class to
  1205. // apply its style, we take advantage of the available info to figure out whether we need to
  1206. // bind the event in the first place.
  1207. /** @type {?} */
  1208. var duration = getTransformTransitionDurationInMs(this._preview);
  1209. if (duration === 0) {
  1210. return Promise.resolve();
  1211. }
  1212. return this._ngZone.runOutsideAngular((/**
  1213. * @return {?}
  1214. */
  1215. function () {
  1216. return new Promise((/**
  1217. * @param {?} resolve
  1218. * @return {?}
  1219. */
  1220. function (resolve) {
  1221. /** @type {?} */
  1222. var handler = (/** @type {?} */ (((/**
  1223. * @param {?} event
  1224. * @return {?}
  1225. */
  1226. function (event) {
  1227. if (!event || (event.target === _this._preview && event.propertyName === 'transform')) {
  1228. _this._preview.removeEventListener('transitionend', handler);
  1229. resolve();
  1230. clearTimeout(timeout);
  1231. }
  1232. }))));
  1233. // If a transition is short enough, the browser might not fire the `transitionend` event.
  1234. // Since we know how long it's supposed to take, add a timeout with a 50% buffer that'll
  1235. // fire if the transition hasn't completed when it was supposed to.
  1236. /** @type {?} */
  1237. var timeout = setTimeout((/** @type {?} */ (handler)), duration * 1.5);
  1238. _this._preview.addEventListener('transitionend', handler);
  1239. }));
  1240. }));
  1241. };
  1242. /** Creates an element that will be shown instead of the current element while dragging. */
  1243. /**
  1244. * Creates an element that will be shown instead of the current element while dragging.
  1245. * @private
  1246. * @return {?}
  1247. */
  1248. DragRef.prototype._createPlaceholderElement = /**
  1249. * Creates an element that will be shown instead of the current element while dragging.
  1250. * @private
  1251. * @return {?}
  1252. */
  1253. function () {
  1254. /** @type {?} */
  1255. var placeholderConfig = this._placeholderTemplate;
  1256. /** @type {?} */
  1257. var placeholderTemplate = placeholderConfig ? placeholderConfig.template : null;
  1258. /** @type {?} */
  1259. var placeholder;
  1260. if (placeholderTemplate) {
  1261. this._placeholderRef = (/** @type {?} */ (placeholderConfig)).viewContainer.createEmbeddedView(placeholderTemplate, (/** @type {?} */ (placeholderConfig)).context);
  1262. placeholder = getRootNode(this._placeholderRef, this._document);
  1263. }
  1264. else {
  1265. placeholder = deepCloneNode(this._rootElement);
  1266. }
  1267. placeholder.classList.add('cdk-drag-placeholder');
  1268. return placeholder;
  1269. };
  1270. /**
  1271. * Figures out the coordinates at which an element was picked up.
  1272. * @param referenceElement Element that initiated the dragging.
  1273. * @param event Event that initiated the dragging.
  1274. */
  1275. /**
  1276. * Figures out the coordinates at which an element was picked up.
  1277. * @private
  1278. * @param {?} referenceElement Element that initiated the dragging.
  1279. * @param {?} event Event that initiated the dragging.
  1280. * @return {?}
  1281. */
  1282. DragRef.prototype._getPointerPositionInElement = /**
  1283. * Figures out the coordinates at which an element was picked up.
  1284. * @private
  1285. * @param {?} referenceElement Element that initiated the dragging.
  1286. * @param {?} event Event that initiated the dragging.
  1287. * @return {?}
  1288. */
  1289. function (referenceElement, event) {
  1290. /** @type {?} */
  1291. var elementRect = this._rootElement.getBoundingClientRect();
  1292. /** @type {?} */
  1293. var handleElement = referenceElement === this._rootElement ? null : referenceElement;
  1294. /** @type {?} */
  1295. var referenceRect = handleElement ? handleElement.getBoundingClientRect() : elementRect;
  1296. /** @type {?} */
  1297. var point = isTouchEvent(event) ? event.targetTouches[0] : event;
  1298. /** @type {?} */
  1299. var x = point.pageX - referenceRect.left - this._scrollPosition.left;
  1300. /** @type {?} */
  1301. var y = point.pageY - referenceRect.top - this._scrollPosition.top;
  1302. return {
  1303. x: referenceRect.left - elementRect.left + x,
  1304. y: referenceRect.top - elementRect.top + y
  1305. };
  1306. };
  1307. /** Determines the point of the page that was touched by the user. */
  1308. /**
  1309. * Determines the point of the page that was touched by the user.
  1310. * @private
  1311. * @param {?} event
  1312. * @return {?}
  1313. */
  1314. DragRef.prototype._getPointerPositionOnPage = /**
  1315. * Determines the point of the page that was touched by the user.
  1316. * @private
  1317. * @param {?} event
  1318. * @return {?}
  1319. */
  1320. function (event) {
  1321. // `touches` will be empty for start/end events so we have to fall back to `changedTouches`.
  1322. /** @type {?} */
  1323. var point = isTouchEvent(event) ? (event.touches[0] || event.changedTouches[0]) : event;
  1324. return {
  1325. x: point.pageX - this._scrollPosition.left,
  1326. y: point.pageY - this._scrollPosition.top
  1327. };
  1328. };
  1329. /** Gets the pointer position on the page, accounting for any position constraints. */
  1330. /**
  1331. * Gets the pointer position on the page, accounting for any position constraints.
  1332. * @private
  1333. * @param {?} event
  1334. * @return {?}
  1335. */
  1336. DragRef.prototype._getConstrainedPointerPosition = /**
  1337. * Gets the pointer position on the page, accounting for any position constraints.
  1338. * @private
  1339. * @param {?} event
  1340. * @return {?}
  1341. */
  1342. function (event) {
  1343. /** @type {?} */
  1344. var point = this._getPointerPositionOnPage(event);
  1345. /** @type {?} */
  1346. var constrainedPoint = this.constrainPosition ? this.constrainPosition(point, this) : point;
  1347. /** @type {?} */
  1348. var dropContainerLock = this._dropContainer ? this._dropContainer.lockAxis : null;
  1349. if (this.lockAxis === 'x' || dropContainerLock === 'x') {
  1350. constrainedPoint.y = this._pickupPositionOnPage.y;
  1351. }
  1352. else if (this.lockAxis === 'y' || dropContainerLock === 'y') {
  1353. constrainedPoint.x = this._pickupPositionOnPage.x;
  1354. }
  1355. if (this._boundaryRect) {
  1356. var _a = this._pickupPositionInElement, pickupX = _a.x, pickupY = _a.y;
  1357. /** @type {?} */
  1358. var boundaryRect = this._boundaryRect;
  1359. /** @type {?} */
  1360. var previewRect = (/** @type {?} */ (this._previewRect));
  1361. /** @type {?} */
  1362. var minY = boundaryRect.top + pickupY;
  1363. /** @type {?} */
  1364. var maxY = boundaryRect.bottom - (previewRect.height - pickupY);
  1365. /** @type {?} */
  1366. var minX = boundaryRect.left + pickupX;
  1367. /** @type {?} */
  1368. var maxX = boundaryRect.right - (previewRect.width - pickupX);
  1369. constrainedPoint.x = clamp(constrainedPoint.x, minX, maxX);
  1370. constrainedPoint.y = clamp(constrainedPoint.y, minY, maxY);
  1371. }
  1372. return constrainedPoint;
  1373. };
  1374. /** Updates the current drag delta, based on the user's current pointer position on the page. */
  1375. /**
  1376. * Updates the current drag delta, based on the user's current pointer position on the page.
  1377. * @private
  1378. * @param {?} pointerPositionOnPage
  1379. * @return {?}
  1380. */
  1381. DragRef.prototype._updatePointerDirectionDelta = /**
  1382. * Updates the current drag delta, based on the user's current pointer position on the page.
  1383. * @private
  1384. * @param {?} pointerPositionOnPage
  1385. * @return {?}
  1386. */
  1387. function (pointerPositionOnPage) {
  1388. var x = pointerPositionOnPage.x, y = pointerPositionOnPage.y;
  1389. /** @type {?} */
  1390. var delta = this._pointerDirectionDelta;
  1391. /** @type {?} */
  1392. var positionSinceLastChange = this._pointerPositionAtLastDirectionChange;
  1393. // Amount of pixels the user has dragged since the last time the direction changed.
  1394. /** @type {?} */
  1395. var changeX = Math.abs(x - positionSinceLastChange.x);
  1396. /** @type {?} */
  1397. var changeY = Math.abs(y - positionSinceLastChange.y);
  1398. // Because we handle pointer events on a per-pixel basis, we don't want the delta
  1399. // to change for every pixel, otherwise anything that depends on it can look erratic.
  1400. // To make the delta more consistent, we track how much the user has moved since the last
  1401. // delta change and we only update it after it has reached a certain threshold.
  1402. if (changeX > this._config.pointerDirectionChangeThreshold) {
  1403. delta.x = x > positionSinceLastChange.x ? 1 : -1;
  1404. positionSinceLastChange.x = x;
  1405. }
  1406. if (changeY > this._config.pointerDirectionChangeThreshold) {
  1407. delta.y = y > positionSinceLastChange.y ? 1 : -1;
  1408. positionSinceLastChange.y = y;
  1409. }
  1410. return delta;
  1411. };
  1412. /** Toggles the native drag interactions, based on how many handles are registered. */
  1413. /**
  1414. * Toggles the native drag interactions, based on how many handles are registered.
  1415. * @private
  1416. * @return {?}
  1417. */
  1418. DragRef.prototype._toggleNativeDragInteractions = /**
  1419. * Toggles the native drag interactions, based on how many handles are registered.
  1420. * @private
  1421. * @return {?}
  1422. */
  1423. function () {
  1424. if (!this._rootElement || !this._handles) {
  1425. return;
  1426. }
  1427. /** @type {?} */
  1428. var shouldEnable = this._handles.length > 0 || !this.isDragging();
  1429. if (shouldEnable !== this._nativeInteractionsEnabled) {
  1430. this._nativeInteractionsEnabled = shouldEnable;
  1431. toggleNativeDragInteractions(this._rootElement, shouldEnable);
  1432. }
  1433. };
  1434. /** Removes the manually-added event listeners from the root element. */
  1435. /**
  1436. * Removes the manually-added event listeners from the root element.
  1437. * @private
  1438. * @param {?} element
  1439. * @return {?}
  1440. */
  1441. DragRef.prototype._removeRootElementListeners = /**
  1442. * Removes the manually-added event listeners from the root element.
  1443. * @private
  1444. * @param {?} element
  1445. * @return {?}
  1446. */
  1447. function (element) {
  1448. element.removeEventListener('mousedown', this._pointerDown, activeEventListenerOptions);
  1449. element.removeEventListener('touchstart', this._pointerDown, passiveEventListenerOptions);
  1450. };
  1451. /**
  1452. * Applies a `transform` to the root element, taking into account any existing transforms on it.
  1453. * @param x New transform value along the X axis.
  1454. * @param y New transform value along the Y axis.
  1455. */
  1456. /**
  1457. * Applies a `transform` to the root element, taking into account any existing transforms on it.
  1458. * @private
  1459. * @param {?} x New transform value along the X axis.
  1460. * @param {?} y New transform value along the Y axis.
  1461. * @return {?}
  1462. */
  1463. DragRef.prototype._applyRootElementTransform = /**
  1464. * Applies a `transform` to the root element, taking into account any existing transforms on it.
  1465. * @private
  1466. * @param {?} x New transform value along the X axis.
  1467. * @param {?} y New transform value along the Y axis.
  1468. * @return {?}
  1469. */
  1470. function (x, y) {
  1471. /** @type {?} */
  1472. var transform = getTransform(x, y);
  1473. // Cache the previous transform amount only after the first drag sequence, because
  1474. // we don't want our own transforms to stack on top of each other.
  1475. if (this._initialTransform == null) {
  1476. this._initialTransform = this._rootElement.style.transform || '';
  1477. }
  1478. // Preserve the previous `transform` value, if there was one. Note that we apply our own
  1479. // transform before the user's, because things like rotation can affect which direction
  1480. // the element will be translated towards.
  1481. this._rootElement.style.transform = this._initialTransform ?
  1482. transform + ' ' + this._initialTransform : transform;
  1483. };
  1484. /**
  1485. * Gets the distance that the user has dragged during the current drag sequence.
  1486. * @param currentPosition Current position of the user's pointer.
  1487. */
  1488. /**
  1489. * Gets the distance that the user has dragged during the current drag sequence.
  1490. * @private
  1491. * @param {?} currentPosition Current position of the user's pointer.
  1492. * @return {?}
  1493. */
  1494. DragRef.prototype._getDragDistance = /**
  1495. * Gets the distance that the user has dragged during the current drag sequence.
  1496. * @private
  1497. * @param {?} currentPosition Current position of the user's pointer.
  1498. * @return {?}
  1499. */
  1500. function (currentPosition) {
  1501. /** @type {?} */
  1502. var pickupPosition = this._pickupPositionOnPage;
  1503. if (pickupPosition) {
  1504. return { x: currentPosition.x - pickupPosition.x, y: currentPosition.y - pickupPosition.y };
  1505. }
  1506. return { x: 0, y: 0 };
  1507. };
  1508. /** Cleans up any cached element dimensions that we don't need after dragging has stopped. */
  1509. /**
  1510. * Cleans up any cached element dimensions that we don't need after dragging has stopped.
  1511. * @private
  1512. * @return {?}
  1513. */
  1514. DragRef.prototype._cleanupCachedDimensions = /**
  1515. * Cleans up any cached element dimensions that we don't need after dragging has stopped.
  1516. * @private
  1517. * @return {?}
  1518. */
  1519. function () {
  1520. this._boundaryRect = this._previewRect = undefined;
  1521. };
  1522. /**
  1523. * Checks whether the element is still inside its boundary after the viewport has been resized.
  1524. * If not, the position is adjusted so that the element fits again.
  1525. */
  1526. /**
  1527. * Checks whether the element is still inside its boundary after the viewport has been resized.
  1528. * If not, the position is adjusted so that the element fits again.
  1529. * @private
  1530. * @return {?}
  1531. */
  1532. DragRef.prototype._containInsideBoundaryOnResize = /**
  1533. * Checks whether the element is still inside its boundary after the viewport has been resized.
  1534. * If not, the position is adjusted so that the element fits again.
  1535. * @private
  1536. * @return {?}
  1537. */
  1538. function () {
  1539. var _a = this._passiveTransform, x = _a.x, y = _a.y;
  1540. if ((x === 0 && y === 0) || this.isDragging() || !this._boundaryElement) {
  1541. return;
  1542. }
  1543. /** @type {?} */
  1544. var boundaryRect = this._boundaryElement.getBoundingClientRect();
  1545. /** @type {?} */
  1546. var elementRect = this._rootElement.getBoundingClientRect();
  1547. /** @type {?} */
  1548. var leftOverflow = boundaryRect.left - elementRect.left;
  1549. /** @type {?} */
  1550. var rightOverflow = elementRect.right - boundaryRect.right;
  1551. /** @type {?} */
  1552. var topOverflow = boundaryRect.top - elementRect.top;
  1553. /** @type {?} */
  1554. var bottomOverflow = elementRect.bottom - boundaryRect.bottom;
  1555. // If the element has become wider than the boundary, we can't
  1556. // do much to make it fit so we just anchor it to the left.
  1557. if (boundaryRect.width > elementRect.width) {
  1558. if (leftOverflow > 0) {
  1559. x += leftOverflow;
  1560. }
  1561. if (rightOverflow > 0) {
  1562. x -= rightOverflow;
  1563. }
  1564. }
  1565. else {
  1566. x = 0;
  1567. }
  1568. // If the element has become taller than the boundary, we can't
  1569. // do much to make it fit so we just anchor it to the top.
  1570. if (boundaryRect.height > elementRect.height) {
  1571. if (topOverflow > 0) {
  1572. y += topOverflow;
  1573. }
  1574. if (bottomOverflow > 0) {
  1575. y -= bottomOverflow;
  1576. }
  1577. }
  1578. else {
  1579. y = 0;
  1580. }
  1581. if (x !== this._passiveTransform.x || y !== this._passiveTransform.y) {
  1582. this.setFreeDragPosition({ y: y, x: x });
  1583. }
  1584. };
  1585. return DragRef;
  1586. }());
  1587. /**
  1588. * Gets a 3d `transform` that can be applied to an element.
  1589. * @param {?} x Desired position of the element along the X axis.
  1590. * @param {?} y Desired position of the element along the Y axis.
  1591. * @return {?}
  1592. */
  1593. function getTransform(x, y) {
  1594. // Round the transforms since some browsers will
  1595. // blur the elements for sub-pixel transforms.
  1596. return "translate3d(" + Math.round(x) + "px, " + Math.round(y) + "px, 0)";
  1597. }
  1598. /**
  1599. * Creates a deep clone of an element.
  1600. * @param {?} node
  1601. * @return {?}
  1602. */
  1603. function deepCloneNode(node) {
  1604. /** @type {?} */
  1605. var clone = (/** @type {?} */ (node.cloneNode(true)));
  1606. /** @type {?} */
  1607. var descendantsWithId = clone.querySelectorAll('[id]');
  1608. /** @type {?} */
  1609. var descendantCanvases = node.querySelectorAll('canvas');
  1610. // Remove the `id` to avoid having multiple elements with the same id on the page.
  1611. clone.removeAttribute('id');
  1612. for (var i = 0; i < descendantsWithId.length; i++) {
  1613. descendantsWithId[i].removeAttribute('id');
  1614. }
  1615. // `cloneNode` won't transfer the content of `canvas` elements so we have to do it ourselves.
  1616. // We match up the cloned canvas to their sources using their index in the DOM.
  1617. if (descendantCanvases.length) {
  1618. /** @type {?} */
  1619. var cloneCanvases = clone.querySelectorAll('canvas');
  1620. for (var i = 0; i < descendantCanvases.length; i++) {
  1621. /** @type {?} */
  1622. var correspondingCloneContext = cloneCanvases[i].getContext('2d');
  1623. if (correspondingCloneContext) {
  1624. correspondingCloneContext.drawImage(descendantCanvases[i], 0, 0);
  1625. }
  1626. }
  1627. }
  1628. return clone;
  1629. }
  1630. /**
  1631. * Clamps a value between a minimum and a maximum.
  1632. * @param {?} value
  1633. * @param {?} min
  1634. * @param {?} max
  1635. * @return {?}
  1636. */
  1637. function clamp(value, min, max) {
  1638. return Math.max(min, Math.min(max, value));
  1639. }
  1640. /**
  1641. * Helper to remove an element from the DOM and to do all the necessary null checks.
  1642. * @param {?} element Element to be removed.
  1643. * @return {?}
  1644. */
  1645. function removeElement(element) {
  1646. if (element && element.parentNode) {
  1647. element.parentNode.removeChild(element);
  1648. }
  1649. }
  1650. /**
  1651. * Determines whether an event is a touch event.
  1652. * @param {?} event
  1653. * @return {?}
  1654. */
  1655. function isTouchEvent(event) {
  1656. // This function is called for every pixel that the user has dragged so we need it to be
  1657. // as fast as possible. Since we only bind mouse events and touch events, we can assume
  1658. // that if the event's name starts with `t`, it's a touch event.
  1659. return event.type[0] === 't';
  1660. }
  1661. /**
  1662. * Gets the element into which the drag preview should be inserted.
  1663. * @param {?} documentRef
  1664. * @return {?}
  1665. */
  1666. function getPreviewInsertionPoint(documentRef) {
  1667. // We can't use the body if the user is in fullscreen mode,
  1668. // because the preview will render under the fullscreen element.
  1669. // TODO(crisbeto): dedupe this with the `FullscreenOverlayContainer` eventually.
  1670. return documentRef.fullscreenElement ||
  1671. documentRef.webkitFullscreenElement ||
  1672. documentRef.mozFullScreenElement ||
  1673. documentRef.msFullscreenElement ||
  1674. documentRef.body;
  1675. }
  1676. /**
  1677. * Gets the root HTML element of an embedded view.
  1678. * If the root is not an HTML element it gets wrapped in one.
  1679. * @param {?} viewRef
  1680. * @param {?} _document
  1681. * @return {?}
  1682. */
  1683. function getRootNode(viewRef, _document) {
  1684. /** @type {?} */
  1685. var rootNode = viewRef.rootNodes[0];
  1686. if (rootNode.nodeType !== _document.ELEMENT_NODE) {
  1687. /** @type {?} */
  1688. var wrapper = _document.createElement('div');
  1689. wrapper.appendChild(rootNode);
  1690. return wrapper;
  1691. }
  1692. return (/** @type {?} */ (rootNode));
  1693. }
  1694. /**
  1695. * @fileoverview added by tsickle
  1696. * @suppress {checkTypes,extraRequire,missingOverride,missingReturn,unusedPrivateMembers,uselessCode} checked by tsc
  1697. */
  1698. /**
  1699. * Moves an item one index in an array to another.
  1700. * @template T
  1701. * @param {?} array Array in which to move the item.
  1702. * @param {?} fromIndex Starting index of the item.
  1703. * @param {?} toIndex Index to which the item should be moved.
  1704. * @return {?}
  1705. */
  1706. function moveItemInArray(array, fromIndex, toIndex) {
  1707. /** @type {?} */
  1708. var from = clamp$1(fromIndex, array.length - 1);
  1709. /** @type {?} */
  1710. var to = clamp$1(toIndex, array.length - 1);
  1711. if (from === to) {
  1712. return;
  1713. }
  1714. /** @type {?} */
  1715. var target = array[from];
  1716. /** @type {?} */
  1717. var delta = to < from ? -1 : 1;
  1718. for (var i = from; i !== to; i += delta) {
  1719. array[i] = array[i + delta];
  1720. }
  1721. array[to] = target;
  1722. }
  1723. /**
  1724. * Moves an item from one array to another.
  1725. * @template T
  1726. * @param {?} currentArray Array from which to transfer the item.
  1727. * @param {?} targetArray Array into which to put the item.
  1728. * @param {?} currentIndex Index of the item in its current array.
  1729. * @param {?} targetIndex Index at which to insert the item.
  1730. * @return {?}
  1731. */
  1732. function transferArrayItem(currentArray, targetArray, currentIndex, targetIndex) {
  1733. /** @type {?} */
  1734. var from = clamp$1(currentIndex, currentArray.length - 1);
  1735. /** @type {?} */
  1736. var to = clamp$1(targetIndex, targetArray.length);
  1737. if (currentArray.length) {
  1738. targetArray.splice(to, 0, currentArray.splice(from, 1)[0]);
  1739. }
  1740. }
  1741. /**
  1742. * Copies an item from one array to another, leaving it in its
  1743. * original position in current array.
  1744. * @template T
  1745. * @param {?} currentArray Array from which to copy the item.
  1746. * @param {?} targetArray Array into which is copy the item.
  1747. * @param {?} currentIndex Index of the item in its current array.
  1748. * @param {?} targetIndex Index at which to insert the item.
  1749. *
  1750. * @return {?}
  1751. */
  1752. function copyArrayItem(currentArray, targetArray, currentIndex, targetIndex) {
  1753. /** @type {?} */
  1754. var to = clamp$1(targetIndex, targetArray.length);
  1755. if (currentArray.length) {
  1756. targetArray.splice(to, 0, currentArray[currentIndex]);
  1757. }
  1758. }
  1759. /**
  1760. * Clamps a number between zero and a maximum.
  1761. * @param {?} value
  1762. * @param {?} max
  1763. * @return {?}
  1764. */
  1765. function clamp$1(value, max) {
  1766. return Math.max(0, Math.min(max, value));
  1767. }
  1768. /**
  1769. * @fileoverview added by tsickle
  1770. * @suppress {checkTypes,extraRequire,missingOverride,missingReturn,unusedPrivateMembers,uselessCode} checked by tsc
  1771. */
  1772. /**
  1773. * Counter used to generate unique ids for drop refs.
  1774. * @type {?}
  1775. */
  1776. var _uniqueIdCounter = 0;
  1777. /**
  1778. * Proximity, as a ratio to width/height, at which a
  1779. * dragged item will affect the drop container.
  1780. * @type {?}
  1781. */
  1782. var DROP_PROXIMITY_THRESHOLD = 0.05;
  1783. /**
  1784. * Proximity, as a ratio to width/height at which to start auto-scrolling the drop list or the
  1785. * viewport. The value comes from trying it out manually until it feels right.
  1786. * @type {?}
  1787. */
  1788. var SCROLL_PROXIMITY_THRESHOLD = 0.05;
  1789. /**
  1790. * Number of pixels to scroll for each frame when auto-scrolling an element.
  1791. * The value comes from trying it out manually until it feels right.
  1792. * @type {?}
  1793. */
  1794. var AUTO_SCROLL_STEP = 2;
  1795. /**
  1796. * Reference to a drop list. Used to manipulate or dispose of the container.
  1797. * \@docs-private
  1798. * @template T
  1799. */
  1800. var /**
  1801. * Reference to a drop list. Used to manipulate or dispose of the container.
  1802. * \@docs-private
  1803. * @template T
  1804. */
  1805. DropListRef = /** @class */ (function () {
  1806. function DropListRef(element, _dragDropRegistry, _document, _ngZone, _viewportRuler) {
  1807. var _this = this;
  1808. this._dragDropRegistry = _dragDropRegistry;
  1809. this._ngZone = _ngZone;
  1810. this._viewportRuler = _viewportRuler;
  1811. /**
  1812. * Unique ID for the drop list.
  1813. * @deprecated No longer being used. To be removed.
  1814. * \@breaking-change 8.0.0
  1815. */
  1816. this.id = "cdk-drop-list-ref-" + _uniqueIdCounter++;
  1817. /**
  1818. * Whether starting a dragging sequence from this container is disabled.
  1819. */
  1820. this.disabled = false;
  1821. /**
  1822. * Whether sorting items within the list is disabled.
  1823. */
  1824. this.sortingDisabled = false;
  1825. /**
  1826. * Whether auto-scrolling the view when the user
  1827. * moves their pointer close to the edges is disabled.
  1828. */
  1829. this.autoScrollDisabled = false;
  1830. /**
  1831. * Function that is used to determine whether an item
  1832. * is allowed to be moved into a drop container.
  1833. */
  1834. this.enterPredicate = (/**
  1835. * @return {?}
  1836. */
  1837. function () { return true; });
  1838. /**
  1839. * Emits right before dragging has started.
  1840. */
  1841. this.beforeStarted = new rxjs.Subject();
  1842. /**
  1843. * Emits when the user has moved a new drag item into this container.
  1844. */
  1845. this.entered = new rxjs.Subject();
  1846. /**
  1847. * Emits when the user removes an item from the container
  1848. * by dragging it into another container.
  1849. */
  1850. this.exited = new rxjs.Subject();
  1851. /**
  1852. * Emits when the user drops an item inside the container.
  1853. */
  1854. this.dropped = new rxjs.Subject();
  1855. /**
  1856. * Emits as the user is swapping items while actively dragging.
  1857. */
  1858. this.sorted = new rxjs.Subject();
  1859. /**
  1860. * Whether an item in the list is being dragged.
  1861. */
  1862. this._isDragging = false;
  1863. /**
  1864. * Cache of the dimensions of all the items inside the container.
  1865. */
  1866. this._itemPositions = [];
  1867. /**
  1868. * Keeps track of the container's scroll position.
  1869. */
  1870. this._scrollPosition = { top: 0, left: 0 };
  1871. /**
  1872. * Keeps track of the scroll position of the viewport.
  1873. */
  1874. this._viewportScrollPosition = { top: 0, left: 0 };
  1875. /**
  1876. * Keeps track of the item that was last swapped with the dragged item, as
  1877. * well as what direction the pointer was moving in when the swap occured.
  1878. */
  1879. this._previousSwap = { drag: (/** @type {?} */ (null)), delta: 0 };
  1880. /**
  1881. * Drop lists that are connected to the current one.
  1882. */
  1883. this._siblings = [];
  1884. /**
  1885. * Direction in which the list is oriented.
  1886. */
  1887. this._orientation = 'vertical';
  1888. /**
  1889. * Connected siblings that currently have a dragged item.
  1890. */
  1891. this._activeSiblings = new Set();
  1892. /**
  1893. * Layout direction of the drop list.
  1894. */
  1895. this._direction = 'ltr';
  1896. /**
  1897. * Subscription to the window being scrolled.
  1898. */
  1899. this._viewportScrollSubscription = rxjs.Subscription.EMPTY;
  1900. /**
  1901. * Vertical direction in which the list is currently scrolling.
  1902. */
  1903. this._verticalScrollDirection = 0 /* NONE */;
  1904. /**
  1905. * Horizontal direction in which the list is currently scrolling.
  1906. */
  1907. this._horizontalScrollDirection = 0 /* NONE */;
  1908. /**
  1909. * Used to signal to the current auto-scroll sequence when to stop.
  1910. */
  1911. this._stopScrollTimers = new rxjs.Subject();
  1912. /**
  1913. * Handles the container being scrolled. Has to be an arrow function to preserve the context.
  1914. */
  1915. this._handleScroll = (/**
  1916. * @return {?}
  1917. */
  1918. function () {
  1919. if (!_this.isDragging()) {
  1920. return;
  1921. }
  1922. /** @type {?} */
  1923. var element = coercion.coerceElement(_this.element);
  1924. _this._updateAfterScroll(_this._scrollPosition, element.scrollTop, element.scrollLeft);
  1925. });
  1926. /**
  1927. * Starts the interval that'll auto-scroll the element.
  1928. */
  1929. this._startScrollInterval = (/**
  1930. * @return {?}
  1931. */
  1932. function () {
  1933. _this._stopScrolling();
  1934. rxjs.interval(0, rxjs.animationFrameScheduler)
  1935. .pipe(operators.takeUntil(_this._stopScrollTimers))
  1936. .subscribe((/**
  1937. * @return {?}
  1938. */
  1939. function () {
  1940. /** @type {?} */
  1941. var node = _this._scrollNode;
  1942. if (_this._verticalScrollDirection === 1 /* UP */) {
  1943. incrementVerticalScroll(node, -AUTO_SCROLL_STEP);
  1944. }
  1945. else if (_this._verticalScrollDirection === 2 /* DOWN */) {
  1946. incrementVerticalScroll(node, AUTO_SCROLL_STEP);
  1947. }
  1948. if (_this._horizontalScrollDirection === 1 /* LEFT */) {
  1949. incrementHorizontalScroll(node, -AUTO_SCROLL_STEP);
  1950. }
  1951. else if (_this._horizontalScrollDirection === 2 /* RIGHT */) {
  1952. incrementHorizontalScroll(node, AUTO_SCROLL_STEP);
  1953. }
  1954. }));
  1955. });
  1956. /** @type {?} */
  1957. var nativeNode = this.element = coercion.coerceElement(element);
  1958. this._shadowRoot = getShadowRoot(nativeNode) || _document;
  1959. _dragDropRegistry.registerDropContainer(this);
  1960. }
  1961. /** Removes the drop list functionality from the DOM element. */
  1962. /**
  1963. * Removes the drop list functionality from the DOM element.
  1964. * @return {?}
  1965. */
  1966. DropListRef.prototype.dispose = /**
  1967. * Removes the drop list functionality from the DOM element.
  1968. * @return {?}
  1969. */
  1970. function () {
  1971. this._stopScrolling();
  1972. this._stopScrollTimers.complete();
  1973. this._removeListeners();
  1974. this.beforeStarted.complete();
  1975. this.entered.complete();
  1976. this.exited.complete();
  1977. this.dropped.complete();
  1978. this.sorted.complete();
  1979. this._activeSiblings.clear();
  1980. this._scrollNode = (/** @type {?} */ (null));
  1981. this._dragDropRegistry.removeDropContainer(this);
  1982. };
  1983. /** Whether an item from this list is currently being dragged. */
  1984. /**
  1985. * Whether an item from this list is currently being dragged.
  1986. * @return {?}
  1987. */
  1988. DropListRef.prototype.isDragging = /**
  1989. * Whether an item from this list is currently being dragged.
  1990. * @return {?}
  1991. */
  1992. function () {
  1993. return this._isDragging;
  1994. };
  1995. /** Starts dragging an item. */
  1996. /**
  1997. * Starts dragging an item.
  1998. * @return {?}
  1999. */
  2000. DropListRef.prototype.start = /**
  2001. * Starts dragging an item.
  2002. * @return {?}
  2003. */
  2004. function () {
  2005. var _this = this;
  2006. /** @type {?} */
  2007. var element = coercion.coerceElement(this.element);
  2008. this.beforeStarted.next();
  2009. this._isDragging = true;
  2010. this._cacheItems();
  2011. this._siblings.forEach((/**
  2012. * @param {?} sibling
  2013. * @return {?}
  2014. */
  2015. function (sibling) { return sibling._startReceiving(_this); }));
  2016. this._removeListeners();
  2017. // @breaking-change 9.0.0 Remove check for _ngZone once it's marked as a required param.
  2018. if (this._ngZone) {
  2019. this._ngZone.runOutsideAngular((/**
  2020. * @return {?}
  2021. */
  2022. function () { return element.addEventListener('scroll', _this._handleScroll); }));
  2023. }
  2024. else {
  2025. element.addEventListener('scroll', this._handleScroll);
  2026. }
  2027. // @breaking-change 9.0.0 Remove check for _viewportRuler once it's marked as a required param.
  2028. if (this._viewportRuler) {
  2029. this._listenToScrollEvents();
  2030. }
  2031. };
  2032. /**
  2033. * Emits an event to indicate that the user moved an item into the container.
  2034. * @param item Item that was moved into the container.
  2035. * @param pointerX Position of the item along the X axis.
  2036. * @param pointerY Position of the item along the Y axis.
  2037. */
  2038. /**
  2039. * Emits an event to indicate that the user moved an item into the container.
  2040. * @param {?} item Item that was moved into the container.
  2041. * @param {?} pointerX Position of the item along the X axis.
  2042. * @param {?} pointerY Position of the item along the Y axis.
  2043. * @return {?}
  2044. */
  2045. DropListRef.prototype.enter = /**
  2046. * Emits an event to indicate that the user moved an item into the container.
  2047. * @param {?} item Item that was moved into the container.
  2048. * @param {?} pointerX Position of the item along the X axis.
  2049. * @param {?} pointerY Position of the item along the Y axis.
  2050. * @return {?}
  2051. */
  2052. function (item, pointerX, pointerY) {
  2053. this.start();
  2054. // If sorting is disabled, we want the item to return to its starting
  2055. // position if the user is returning it to its initial container.
  2056. /** @type {?} */
  2057. var newIndex = this.sortingDisabled ? this._draggables.indexOf(item) : -1;
  2058. if (newIndex === -1) {
  2059. // We use the coordinates of where the item entered the drop
  2060. // zone to figure out at which index it should be inserted.
  2061. newIndex = this._getItemIndexFromPointerPosition(item, pointerX, pointerY);
  2062. }
  2063. /** @type {?} */
  2064. var activeDraggables = this._activeDraggables;
  2065. /** @type {?} */
  2066. var currentIndex = activeDraggables.indexOf(item);
  2067. /** @type {?} */
  2068. var placeholder = item.getPlaceholderElement();
  2069. /** @type {?} */
  2070. var newPositionReference = activeDraggables[newIndex];
  2071. // If the item at the new position is the same as the item that is being dragged,
  2072. // it means that we're trying to restore the item to its initial position. In this
  2073. // case we should use the next item from the list as the reference.
  2074. if (newPositionReference === item) {
  2075. newPositionReference = activeDraggables[newIndex + 1];
  2076. }
  2077. // Since the item may be in the `activeDraggables` already (e.g. if the user dragged it
  2078. // into another container and back again), we have to ensure that it isn't duplicated.
  2079. if (currentIndex > -1) {
  2080. activeDraggables.splice(currentIndex, 1);
  2081. }
  2082. // Don't use items that are being dragged as a reference, because
  2083. // their element has been moved down to the bottom of the body.
  2084. if (newPositionReference && !this._dragDropRegistry.isDragging(newPositionReference)) {
  2085. /** @type {?} */
  2086. var element = newPositionReference.getRootElement();
  2087. (/** @type {?} */ (element.parentElement)).insertBefore(placeholder, element);
  2088. activeDraggables.splice(newIndex, 0, item);
  2089. }
  2090. else {
  2091. coercion.coerceElement(this.element).appendChild(placeholder);
  2092. activeDraggables.push(item);
  2093. }
  2094. // The transform needs to be cleared so it doesn't throw off the measurements.
  2095. placeholder.style.transform = '';
  2096. // Note that the positions were already cached when we called `start` above,
  2097. // but we need to refresh them since the amount of items has changed.
  2098. this._cacheItemPositions();
  2099. this.entered.next({ item: item, container: this, currentIndex: this.getItemIndex(item) });
  2100. };
  2101. /**
  2102. * Removes an item from the container after it was dragged into another container by the user.
  2103. * @param item Item that was dragged out.
  2104. */
  2105. /**
  2106. * Removes an item from the container after it was dragged into another container by the user.
  2107. * @param {?} item Item that was dragged out.
  2108. * @return {?}
  2109. */
  2110. DropListRef.prototype.exit = /**
  2111. * Removes an item from the container after it was dragged into another container by the user.
  2112. * @param {?} item Item that was dragged out.
  2113. * @return {?}
  2114. */
  2115. function (item) {
  2116. this._reset();
  2117. this.exited.next({ item: item, container: this });
  2118. };
  2119. /**
  2120. * Drops an item into this container.
  2121. * @param item Item being dropped into the container.
  2122. * @param currentIndex Index at which the item should be inserted.
  2123. * @param previousContainer Container from which the item got dragged in.
  2124. * @param isPointerOverContainer Whether the user's pointer was over the
  2125. * container when the item was dropped.
  2126. * @param distance Distance the user has dragged since the start of the dragging sequence.
  2127. * @breaking-change 9.0.0 `distance` parameter to become required.
  2128. */
  2129. /**
  2130. * Drops an item into this container.
  2131. * \@breaking-change 9.0.0 `distance` parameter to become required.
  2132. * @param {?} item Item being dropped into the container.
  2133. * @param {?} currentIndex Index at which the item should be inserted.
  2134. * @param {?} previousContainer Container from which the item got dragged in.
  2135. * @param {?} isPointerOverContainer Whether the user's pointer was over the
  2136. * container when the item was dropped.
  2137. * @param {?=} distance Distance the user has dragged since the start of the dragging sequence.
  2138. * @return {?}
  2139. */
  2140. DropListRef.prototype.drop = /**
  2141. * Drops an item into this container.
  2142. * \@breaking-change 9.0.0 `distance` parameter to become required.
  2143. * @param {?} item Item being dropped into the container.
  2144. * @param {?} currentIndex Index at which the item should be inserted.
  2145. * @param {?} previousContainer Container from which the item got dragged in.
  2146. * @param {?} isPointerOverContainer Whether the user's pointer was over the
  2147. * container when the item was dropped.
  2148. * @param {?=} distance Distance the user has dragged since the start of the dragging sequence.
  2149. * @return {?}
  2150. */
  2151. function (item, currentIndex, previousContainer, isPointerOverContainer, distance) {
  2152. if (distance === void 0) { distance = { x: 0, y: 0 }; }
  2153. this._reset();
  2154. this.dropped.next({
  2155. item: item,
  2156. currentIndex: currentIndex,
  2157. previousIndex: previousContainer.getItemIndex(item),
  2158. container: this,
  2159. previousContainer: previousContainer,
  2160. isPointerOverContainer: isPointerOverContainer,
  2161. distance: distance
  2162. });
  2163. };
  2164. /**
  2165. * Sets the draggable items that are a part of this list.
  2166. * @param items Items that are a part of this list.
  2167. */
  2168. /**
  2169. * Sets the draggable items that are a part of this list.
  2170. * @template THIS
  2171. * @this {THIS}
  2172. * @param {?} items Items that are a part of this list.
  2173. * @return {THIS}
  2174. */
  2175. DropListRef.prototype.withItems = /**
  2176. * Sets the draggable items that are a part of this list.
  2177. * @template THIS
  2178. * @this {THIS}
  2179. * @param {?} items Items that are a part of this list.
  2180. * @return {THIS}
  2181. */
  2182. function (items) {
  2183. var _this = this;
  2184. (/** @type {?} */ (this))._draggables = items;
  2185. items.forEach((/**
  2186. * @param {?} item
  2187. * @return {?}
  2188. */
  2189. function (item) { return item._withDropContainer((/** @type {?} */ (_this))); }));
  2190. if ((/** @type {?} */ (this)).isDragging()) {
  2191. (/** @type {?} */ (this))._cacheItems();
  2192. }
  2193. return (/** @type {?} */ (this));
  2194. };
  2195. /** Sets the layout direction of the drop list. */
  2196. /**
  2197. * Sets the layout direction of the drop list.
  2198. * @template THIS
  2199. * @this {THIS}
  2200. * @param {?} direction
  2201. * @return {THIS}
  2202. */
  2203. DropListRef.prototype.withDirection = /**
  2204. * Sets the layout direction of the drop list.
  2205. * @template THIS
  2206. * @this {THIS}
  2207. * @param {?} direction
  2208. * @return {THIS}
  2209. */
  2210. function (direction) {
  2211. (/** @type {?} */ (this))._direction = direction;
  2212. return (/** @type {?} */ (this));
  2213. };
  2214. /**
  2215. * Sets the containers that are connected to this one. When two or more containers are
  2216. * connected, the user will be allowed to transfer items between them.
  2217. * @param connectedTo Other containers that the current containers should be connected to.
  2218. */
  2219. /**
  2220. * Sets the containers that are connected to this one. When two or more containers are
  2221. * connected, the user will be allowed to transfer items between them.
  2222. * @template THIS
  2223. * @this {THIS}
  2224. * @param {?} connectedTo Other containers that the current containers should be connected to.
  2225. * @return {THIS}
  2226. */
  2227. DropListRef.prototype.connectedTo = /**
  2228. * Sets the containers that are connected to this one. When two or more containers are
  2229. * connected, the user will be allowed to transfer items between them.
  2230. * @template THIS
  2231. * @this {THIS}
  2232. * @param {?} connectedTo Other containers that the current containers should be connected to.
  2233. * @return {THIS}
  2234. */
  2235. function (connectedTo) {
  2236. (/** @type {?} */ (this))._siblings = connectedTo.slice();
  2237. return (/** @type {?} */ (this));
  2238. };
  2239. /**
  2240. * Sets the orientation of the container.
  2241. * @param orientation New orientation for the container.
  2242. */
  2243. /**
  2244. * Sets the orientation of the container.
  2245. * @template THIS
  2246. * @this {THIS}
  2247. * @param {?} orientation New orientation for the container.
  2248. * @return {THIS}
  2249. */
  2250. DropListRef.prototype.withOrientation = /**
  2251. * Sets the orientation of the container.
  2252. * @template THIS
  2253. * @this {THIS}
  2254. * @param {?} orientation New orientation for the container.
  2255. * @return {THIS}
  2256. */
  2257. function (orientation) {
  2258. (/** @type {?} */ (this))._orientation = orientation;
  2259. return (/** @type {?} */ (this));
  2260. };
  2261. /**
  2262. * Figures out the index of an item in the container.
  2263. * @param item Item whose index should be determined.
  2264. */
  2265. /**
  2266. * Figures out the index of an item in the container.
  2267. * @param {?} item Item whose index should be determined.
  2268. * @return {?}
  2269. */
  2270. DropListRef.prototype.getItemIndex = /**
  2271. * Figures out the index of an item in the container.
  2272. * @param {?} item Item whose index should be determined.
  2273. * @return {?}
  2274. */
  2275. function (item) {
  2276. if (!this._isDragging) {
  2277. return this._draggables.indexOf(item);
  2278. }
  2279. // Items are sorted always by top/left in the cache, however they flow differently in RTL.
  2280. // The rest of the logic still stands no matter what orientation we're in, however
  2281. // we need to invert the array when determining the index.
  2282. /** @type {?} */
  2283. var items = this._orientation === 'horizontal' && this._direction === 'rtl' ?
  2284. this._itemPositions.slice().reverse() : this._itemPositions;
  2285. return findIndex(items, (/**
  2286. * @param {?} currentItem
  2287. * @return {?}
  2288. */
  2289. function (currentItem) { return currentItem.drag === item; }));
  2290. };
  2291. /**
  2292. * Whether the list is able to receive the item that
  2293. * is currently being dragged inside a connected drop list.
  2294. */
  2295. /**
  2296. * Whether the list is able to receive the item that
  2297. * is currently being dragged inside a connected drop list.
  2298. * @return {?}
  2299. */
  2300. DropListRef.prototype.isReceiving = /**
  2301. * Whether the list is able to receive the item that
  2302. * is currently being dragged inside a connected drop list.
  2303. * @return {?}
  2304. */
  2305. function () {
  2306. return this._activeSiblings.size > 0;
  2307. };
  2308. /**
  2309. * Sorts an item inside the container based on its position.
  2310. * @param item Item to be sorted.
  2311. * @param pointerX Position of the item along the X axis.
  2312. * @param pointerY Position of the item along the Y axis.
  2313. * @param pointerDelta Direction in which the pointer is moving along each axis.
  2314. */
  2315. /**
  2316. * Sorts an item inside the container based on its position.
  2317. * @param {?} item Item to be sorted.
  2318. * @param {?} pointerX Position of the item along the X axis.
  2319. * @param {?} pointerY Position of the item along the Y axis.
  2320. * @param {?} pointerDelta Direction in which the pointer is moving along each axis.
  2321. * @return {?}
  2322. */
  2323. DropListRef.prototype._sortItem = /**
  2324. * Sorts an item inside the container based on its position.
  2325. * @param {?} item Item to be sorted.
  2326. * @param {?} pointerX Position of the item along the X axis.
  2327. * @param {?} pointerY Position of the item along the Y axis.
  2328. * @param {?} pointerDelta Direction in which the pointer is moving along each axis.
  2329. * @return {?}
  2330. */
  2331. function (item, pointerX, pointerY, pointerDelta) {
  2332. // Don't sort the item if sorting is disabled or it's out of range.
  2333. if (this.sortingDisabled || !this._isPointerNearDropContainer(pointerX, pointerY)) {
  2334. return;
  2335. }
  2336. /** @type {?} */
  2337. var siblings = this._itemPositions;
  2338. /** @type {?} */
  2339. var newIndex = this._getItemIndexFromPointerPosition(item, pointerX, pointerY, pointerDelta);
  2340. if (newIndex === -1 && siblings.length > 0) {
  2341. return;
  2342. }
  2343. /** @type {?} */
  2344. var isHorizontal = this._orientation === 'horizontal';
  2345. /** @type {?} */
  2346. var currentIndex = findIndex(siblings, (/**
  2347. * @param {?} currentItem
  2348. * @return {?}
  2349. */
  2350. function (currentItem) { return currentItem.drag === item; }));
  2351. /** @type {?} */
  2352. var siblingAtNewPosition = siblings[newIndex];
  2353. /** @type {?} */
  2354. var currentPosition = siblings[currentIndex].clientRect;
  2355. /** @type {?} */
  2356. var newPosition = siblingAtNewPosition.clientRect;
  2357. /** @type {?} */
  2358. var delta = currentIndex > newIndex ? 1 : -1;
  2359. this._previousSwap.drag = siblingAtNewPosition.drag;
  2360. this._previousSwap.delta = isHorizontal ? pointerDelta.x : pointerDelta.y;
  2361. // How many pixels the item's placeholder should be offset.
  2362. /** @type {?} */
  2363. var itemOffset = this._getItemOffsetPx(currentPosition, newPosition, delta);
  2364. // How many pixels all the other items should be offset.
  2365. /** @type {?} */
  2366. var siblingOffset = this._getSiblingOffsetPx(currentIndex, siblings, delta);
  2367. // Save the previous order of the items before moving the item to its new index.
  2368. // We use this to check whether an item has been moved as a result of the sorting.
  2369. /** @type {?} */
  2370. var oldOrder = siblings.slice();
  2371. // Shuffle the array in place.
  2372. moveItemInArray(siblings, currentIndex, newIndex);
  2373. this.sorted.next({
  2374. previousIndex: currentIndex,
  2375. currentIndex: newIndex,
  2376. container: this,
  2377. item: item
  2378. });
  2379. siblings.forEach((/**
  2380. * @param {?} sibling
  2381. * @param {?} index
  2382. * @return {?}
  2383. */
  2384. function (sibling, index) {
  2385. // Don't do anything if the position hasn't changed.
  2386. if (oldOrder[index] === sibling) {
  2387. return;
  2388. }
  2389. /** @type {?} */
  2390. var isDraggedItem = sibling.drag === item;
  2391. /** @type {?} */
  2392. var offset = isDraggedItem ? itemOffset : siblingOffset;
  2393. /** @type {?} */
  2394. var elementToOffset = isDraggedItem ? item.getPlaceholderElement() :
  2395. sibling.drag.getRootElement();
  2396. // Update the offset to reflect the new position.
  2397. sibling.offset += offset;
  2398. // Since we're moving the items with a `transform`, we need to adjust their cached
  2399. // client rects to reflect their new position, as well as swap their positions in the cache.
  2400. // Note that we shouldn't use `getBoundingClientRect` here to update the cache, because the
  2401. // elements may be mid-animation which will give us a wrong result.
  2402. if (isHorizontal) {
  2403. // Round the transforms since some browsers will
  2404. // blur the elements, for sub-pixel transforms.
  2405. elementToOffset.style.transform = "translate3d(" + Math.round(sibling.offset) + "px, 0, 0)";
  2406. adjustClientRect(sibling.clientRect, 0, offset);
  2407. }
  2408. else {
  2409. elementToOffset.style.transform = "translate3d(0, " + Math.round(sibling.offset) + "px, 0)";
  2410. adjustClientRect(sibling.clientRect, offset, 0);
  2411. }
  2412. }));
  2413. };
  2414. /**
  2415. * Checks whether the user's pointer is close to the edges of either the
  2416. * viewport or the drop list and starts the auto-scroll sequence.
  2417. * @param pointerX User's pointer position along the x axis.
  2418. * @param pointerY User's pointer position along the y axis.
  2419. */
  2420. /**
  2421. * Checks whether the user's pointer is close to the edges of either the
  2422. * viewport or the drop list and starts the auto-scroll sequence.
  2423. * @param {?} pointerX User's pointer position along the x axis.
  2424. * @param {?} pointerY User's pointer position along the y axis.
  2425. * @return {?}
  2426. */
  2427. DropListRef.prototype._startScrollingIfNecessary = /**
  2428. * Checks whether the user's pointer is close to the edges of either the
  2429. * viewport or the drop list and starts the auto-scroll sequence.
  2430. * @param {?} pointerX User's pointer position along the x axis.
  2431. * @param {?} pointerY User's pointer position along the y axis.
  2432. * @return {?}
  2433. */
  2434. function (pointerX, pointerY) {
  2435. var _a;
  2436. if (this.autoScrollDisabled) {
  2437. return;
  2438. }
  2439. /** @type {?} */
  2440. var scrollNode;
  2441. /** @type {?} */
  2442. var verticalScrollDirection = 0 /* NONE */;
  2443. /** @type {?} */
  2444. var horizontalScrollDirection = 0 /* NONE */;
  2445. // Check whether we should start scrolling the container.
  2446. if (this._isPointerNearDropContainer(pointerX, pointerY)) {
  2447. /** @type {?} */
  2448. var element = coercion.coerceElement(this.element);
  2449. _a = getElementScrollDirections(element, this._clientRect, pointerX, pointerY), verticalScrollDirection = _a[0], horizontalScrollDirection = _a[1];
  2450. if (verticalScrollDirection || horizontalScrollDirection) {
  2451. scrollNode = element;
  2452. }
  2453. }
  2454. // @breaking-change 9.0.0 Remove null check for _viewportRuler once it's a required parameter.
  2455. // Otherwise check if we can start scrolling the viewport.
  2456. if (this._viewportRuler && !verticalScrollDirection && !horizontalScrollDirection) {
  2457. var _b = this._viewportRuler.getViewportSize(), width = _b.width, height = _b.height;
  2458. /** @type {?} */
  2459. var clientRect = { width: width, height: height, top: 0, right: width, bottom: height, left: 0 };
  2460. verticalScrollDirection = getVerticalScrollDirection(clientRect, pointerY);
  2461. horizontalScrollDirection = getHorizontalScrollDirection(clientRect, pointerX);
  2462. scrollNode = window;
  2463. }
  2464. if (scrollNode && (verticalScrollDirection !== this._verticalScrollDirection ||
  2465. horizontalScrollDirection !== this._horizontalScrollDirection ||
  2466. scrollNode !== this._scrollNode)) {
  2467. this._verticalScrollDirection = verticalScrollDirection;
  2468. this._horizontalScrollDirection = horizontalScrollDirection;
  2469. this._scrollNode = scrollNode;
  2470. if ((verticalScrollDirection || horizontalScrollDirection) && scrollNode) {
  2471. // @breaking-change 9.0.0 Remove null check for `_ngZone` once it is made required.
  2472. if (this._ngZone) {
  2473. this._ngZone.runOutsideAngular(this._startScrollInterval);
  2474. }
  2475. else {
  2476. this._startScrollInterval();
  2477. }
  2478. }
  2479. else {
  2480. this._stopScrolling();
  2481. }
  2482. }
  2483. };
  2484. /** Stops any currently-running auto-scroll sequences. */
  2485. /**
  2486. * Stops any currently-running auto-scroll sequences.
  2487. * @return {?}
  2488. */
  2489. DropListRef.prototype._stopScrolling = /**
  2490. * Stops any currently-running auto-scroll sequences.
  2491. * @return {?}
  2492. */
  2493. function () {
  2494. this._stopScrollTimers.next();
  2495. };
  2496. /** Caches the position of the drop list. */
  2497. /**
  2498. * Caches the position of the drop list.
  2499. * @private
  2500. * @return {?}
  2501. */
  2502. DropListRef.prototype._cacheOwnPosition = /**
  2503. * Caches the position of the drop list.
  2504. * @private
  2505. * @return {?}
  2506. */
  2507. function () {
  2508. /** @type {?} */
  2509. var element = coercion.coerceElement(this.element);
  2510. this._clientRect = getMutableClientRect(element);
  2511. this._scrollPosition = { top: element.scrollTop, left: element.scrollLeft };
  2512. };
  2513. /** Refreshes the position cache of the items and sibling containers. */
  2514. /**
  2515. * Refreshes the position cache of the items and sibling containers.
  2516. * @private
  2517. * @return {?}
  2518. */
  2519. DropListRef.prototype._cacheItemPositions = /**
  2520. * Refreshes the position cache of the items and sibling containers.
  2521. * @private
  2522. * @return {?}
  2523. */
  2524. function () {
  2525. var _this = this;
  2526. /** @type {?} */
  2527. var isHorizontal = this._orientation === 'horizontal';
  2528. this._itemPositions = this._activeDraggables.map((/**
  2529. * @param {?} drag
  2530. * @return {?}
  2531. */
  2532. function (drag) {
  2533. /** @type {?} */
  2534. var elementToMeasure = _this._dragDropRegistry.isDragging(drag) ?
  2535. // If the element is being dragged, we have to measure the
  2536. // placeholder, because the element is hidden.
  2537. drag.getPlaceholderElement() :
  2538. drag.getRootElement();
  2539. return { drag: drag, offset: 0, clientRect: getMutableClientRect(elementToMeasure) };
  2540. })).sort((/**
  2541. * @param {?} a
  2542. * @param {?} b
  2543. * @return {?}
  2544. */
  2545. function (a, b) {
  2546. return isHorizontal ? a.clientRect.left - b.clientRect.left :
  2547. a.clientRect.top - b.clientRect.top;
  2548. }));
  2549. };
  2550. /** Resets the container to its initial state. */
  2551. /**
  2552. * Resets the container to its initial state.
  2553. * @private
  2554. * @return {?}
  2555. */
  2556. DropListRef.prototype._reset = /**
  2557. * Resets the container to its initial state.
  2558. * @private
  2559. * @return {?}
  2560. */
  2561. function () {
  2562. var _this = this;
  2563. this._isDragging = false;
  2564. // TODO(crisbeto): may have to wait for the animations to finish.
  2565. this._activeDraggables.forEach((/**
  2566. * @param {?} item
  2567. * @return {?}
  2568. */
  2569. function (item) { return item.getRootElement().style.transform = ''; }));
  2570. this._siblings.forEach((/**
  2571. * @param {?} sibling
  2572. * @return {?}
  2573. */
  2574. function (sibling) { return sibling._stopReceiving(_this); }));
  2575. this._activeDraggables = [];
  2576. this._itemPositions = [];
  2577. this._previousSwap.drag = null;
  2578. this._previousSwap.delta = 0;
  2579. this._stopScrolling();
  2580. this._removeListeners();
  2581. };
  2582. /**
  2583. * Gets the offset in pixels by which the items that aren't being dragged should be moved.
  2584. * @param currentIndex Index of the item currently being dragged.
  2585. * @param siblings All of the items in the list.
  2586. * @param delta Direction in which the user is moving.
  2587. */
  2588. /**
  2589. * Gets the offset in pixels by which the items that aren't being dragged should be moved.
  2590. * @private
  2591. * @param {?} currentIndex Index of the item currently being dragged.
  2592. * @param {?} siblings All of the items in the list.
  2593. * @param {?} delta Direction in which the user is moving.
  2594. * @return {?}
  2595. */
  2596. DropListRef.prototype._getSiblingOffsetPx = /**
  2597. * Gets the offset in pixels by which the items that aren't being dragged should be moved.
  2598. * @private
  2599. * @param {?} currentIndex Index of the item currently being dragged.
  2600. * @param {?} siblings All of the items in the list.
  2601. * @param {?} delta Direction in which the user is moving.
  2602. * @return {?}
  2603. */
  2604. function (currentIndex, siblings, delta) {
  2605. /** @type {?} */
  2606. var isHorizontal = this._orientation === 'horizontal';
  2607. /** @type {?} */
  2608. var currentPosition = siblings[currentIndex].clientRect;
  2609. /** @type {?} */
  2610. var immediateSibling = siblings[currentIndex + delta * -1];
  2611. /** @type {?} */
  2612. var siblingOffset = currentPosition[isHorizontal ? 'width' : 'height'] * delta;
  2613. if (immediateSibling) {
  2614. /** @type {?} */
  2615. var start = isHorizontal ? 'left' : 'top';
  2616. /** @type {?} */
  2617. var end = isHorizontal ? 'right' : 'bottom';
  2618. // Get the spacing between the start of the current item and the end of the one immediately
  2619. // after it in the direction in which the user is dragging, or vice versa. We add it to the
  2620. // offset in order to push the element to where it will be when it's inline and is influenced
  2621. // by the `margin` of its siblings.
  2622. if (delta === -1) {
  2623. siblingOffset -= immediateSibling.clientRect[start] - currentPosition[end];
  2624. }
  2625. else {
  2626. siblingOffset += currentPosition[start] - immediateSibling.clientRect[end];
  2627. }
  2628. }
  2629. return siblingOffset;
  2630. };
  2631. /**
  2632. * Checks whether the pointer coordinates are close to the drop container.
  2633. * @param pointerX Coordinates along the X axis.
  2634. * @param pointerY Coordinates along the Y axis.
  2635. */
  2636. /**
  2637. * Checks whether the pointer coordinates are close to the drop container.
  2638. * @private
  2639. * @param {?} pointerX Coordinates along the X axis.
  2640. * @param {?} pointerY Coordinates along the Y axis.
  2641. * @return {?}
  2642. */
  2643. DropListRef.prototype._isPointerNearDropContainer = /**
  2644. * Checks whether the pointer coordinates are close to the drop container.
  2645. * @private
  2646. * @param {?} pointerX Coordinates along the X axis.
  2647. * @param {?} pointerY Coordinates along the Y axis.
  2648. * @return {?}
  2649. */
  2650. function (pointerX, pointerY) {
  2651. var _a = this._clientRect, top = _a.top, right = _a.right, bottom = _a.bottom, left = _a.left, width = _a.width, height = _a.height;
  2652. /** @type {?} */
  2653. var xThreshold = width * DROP_PROXIMITY_THRESHOLD;
  2654. /** @type {?} */
  2655. var yThreshold = height * DROP_PROXIMITY_THRESHOLD;
  2656. return pointerY > top - yThreshold && pointerY < bottom + yThreshold &&
  2657. pointerX > left - xThreshold && pointerX < right + xThreshold;
  2658. };
  2659. /**
  2660. * Gets the offset in pixels by which the item that is being dragged should be moved.
  2661. * @param currentPosition Current position of the item.
  2662. * @param newPosition Position of the item where the current item should be moved.
  2663. * @param delta Direction in which the user is moving.
  2664. */
  2665. /**
  2666. * Gets the offset in pixels by which the item that is being dragged should be moved.
  2667. * @private
  2668. * @param {?} currentPosition Current position of the item.
  2669. * @param {?} newPosition Position of the item where the current item should be moved.
  2670. * @param {?} delta Direction in which the user is moving.
  2671. * @return {?}
  2672. */
  2673. DropListRef.prototype._getItemOffsetPx = /**
  2674. * Gets the offset in pixels by which the item that is being dragged should be moved.
  2675. * @private
  2676. * @param {?} currentPosition Current position of the item.
  2677. * @param {?} newPosition Position of the item where the current item should be moved.
  2678. * @param {?} delta Direction in which the user is moving.
  2679. * @return {?}
  2680. */
  2681. function (currentPosition, newPosition, delta) {
  2682. /** @type {?} */
  2683. var isHorizontal = this._orientation === 'horizontal';
  2684. /** @type {?} */
  2685. var itemOffset = isHorizontal ? newPosition.left - currentPosition.left :
  2686. newPosition.top - currentPosition.top;
  2687. // Account for differences in the item width/height.
  2688. if (delta === -1) {
  2689. itemOffset += isHorizontal ? newPosition.width - currentPosition.width :
  2690. newPosition.height - currentPosition.height;
  2691. }
  2692. return itemOffset;
  2693. };
  2694. /**
  2695. * Gets the index of an item in the drop container, based on the position of the user's pointer.
  2696. * @param item Item that is being sorted.
  2697. * @param pointerX Position of the user's pointer along the X axis.
  2698. * @param pointerY Position of the user's pointer along the Y axis.
  2699. * @param delta Direction in which the user is moving their pointer.
  2700. */
  2701. /**
  2702. * Gets the index of an item in the drop container, based on the position of the user's pointer.
  2703. * @private
  2704. * @param {?} item Item that is being sorted.
  2705. * @param {?} pointerX Position of the user's pointer along the X axis.
  2706. * @param {?} pointerY Position of the user's pointer along the Y axis.
  2707. * @param {?=} delta Direction in which the user is moving their pointer.
  2708. * @return {?}
  2709. */
  2710. DropListRef.prototype._getItemIndexFromPointerPosition = /**
  2711. * Gets the index of an item in the drop container, based on the position of the user's pointer.
  2712. * @private
  2713. * @param {?} item Item that is being sorted.
  2714. * @param {?} pointerX Position of the user's pointer along the X axis.
  2715. * @param {?} pointerY Position of the user's pointer along the Y axis.
  2716. * @param {?=} delta Direction in which the user is moving their pointer.
  2717. * @return {?}
  2718. */
  2719. function (item, pointerX, pointerY, delta) {
  2720. var _this = this;
  2721. /** @type {?} */
  2722. var isHorizontal = this._orientation === 'horizontal';
  2723. return findIndex(this._itemPositions, (/**
  2724. * @param {?} __0
  2725. * @param {?} _
  2726. * @param {?} array
  2727. * @return {?}
  2728. */
  2729. function (_a, _, array) {
  2730. var drag = _a.drag, clientRect = _a.clientRect;
  2731. if (drag === item) {
  2732. // If there's only one item left in the container, it must be
  2733. // the dragged item itself so we use it as a reference.
  2734. return array.length < 2;
  2735. }
  2736. if (delta) {
  2737. /** @type {?} */
  2738. var direction = isHorizontal ? delta.x : delta.y;
  2739. // If the user is still hovering over the same item as last time, and they didn't change
  2740. // the direction in which they're dragging, we don't consider it a direction swap.
  2741. if (drag === _this._previousSwap.drag && direction === _this._previousSwap.delta) {
  2742. return false;
  2743. }
  2744. }
  2745. return isHorizontal ?
  2746. // Round these down since most browsers report client rects with
  2747. // sub-pixel precision, whereas the pointer coordinates are rounded to pixels.
  2748. pointerX >= Math.floor(clientRect.left) && pointerX <= Math.floor(clientRect.right) :
  2749. pointerY >= Math.floor(clientRect.top) && pointerY <= Math.floor(clientRect.bottom);
  2750. }));
  2751. };
  2752. /** Caches the current items in the list and their positions. */
  2753. /**
  2754. * Caches the current items in the list and their positions.
  2755. * @private
  2756. * @return {?}
  2757. */
  2758. DropListRef.prototype._cacheItems = /**
  2759. * Caches the current items in the list and their positions.
  2760. * @private
  2761. * @return {?}
  2762. */
  2763. function () {
  2764. this._activeDraggables = this._draggables.slice();
  2765. this._cacheItemPositions();
  2766. this._cacheOwnPosition();
  2767. };
  2768. /**
  2769. * Updates the internal state of the container after a scroll event has happened.
  2770. * @param scrollPosition Object that is keeping track of the scroll position.
  2771. * @param newTop New top scroll position.
  2772. * @param newLeft New left scroll position.
  2773. * @param extraClientRect Extra `ClientRect` object that should be updated, in addition to the
  2774. * ones of the drag items. Useful when the viewport has been scrolled and we also need to update
  2775. * the `ClientRect` of the list.
  2776. */
  2777. /**
  2778. * Updates the internal state of the container after a scroll event has happened.
  2779. * @private
  2780. * @param {?} scrollPosition Object that is keeping track of the scroll position.
  2781. * @param {?} newTop New top scroll position.
  2782. * @param {?} newLeft New left scroll position.
  2783. * @param {?=} extraClientRect Extra `ClientRect` object that should be updated, in addition to the
  2784. * ones of the drag items. Useful when the viewport has been scrolled and we also need to update
  2785. * the `ClientRect` of the list.
  2786. * @return {?}
  2787. */
  2788. DropListRef.prototype._updateAfterScroll = /**
  2789. * Updates the internal state of the container after a scroll event has happened.
  2790. * @private
  2791. * @param {?} scrollPosition Object that is keeping track of the scroll position.
  2792. * @param {?} newTop New top scroll position.
  2793. * @param {?} newLeft New left scroll position.
  2794. * @param {?=} extraClientRect Extra `ClientRect` object that should be updated, in addition to the
  2795. * ones of the drag items. Useful when the viewport has been scrolled and we also need to update
  2796. * the `ClientRect` of the list.
  2797. * @return {?}
  2798. */
  2799. function (scrollPosition, newTop, newLeft, extraClientRect) {
  2800. var _this = this;
  2801. /** @type {?} */
  2802. var topDifference = scrollPosition.top - newTop;
  2803. /** @type {?} */
  2804. var leftDifference = scrollPosition.left - newLeft;
  2805. if (extraClientRect) {
  2806. adjustClientRect(extraClientRect, topDifference, leftDifference);
  2807. }
  2808. // Since we know the amount that the user has scrolled we can shift all of the client rectangles
  2809. // ourselves. This is cheaper than re-measuring everything and we can avoid inconsistent
  2810. // behavior where we might be measuring the element before its position has changed.
  2811. this._itemPositions.forEach((/**
  2812. * @param {?} __0
  2813. * @return {?}
  2814. */
  2815. function (_a) {
  2816. var clientRect = _a.clientRect;
  2817. adjustClientRect(clientRect, topDifference, leftDifference);
  2818. }));
  2819. // We need two loops for this, because we want all of the cached
  2820. // positions to be up-to-date before we re-sort the item.
  2821. this._itemPositions.forEach((/**
  2822. * @param {?} __0
  2823. * @return {?}
  2824. */
  2825. function (_a) {
  2826. var drag = _a.drag;
  2827. if (_this._dragDropRegistry.isDragging(drag)) {
  2828. // We need to re-sort the item manually, because the pointer move
  2829. // events won't be dispatched while the user is scrolling.
  2830. drag._sortFromLastPointerPosition();
  2831. }
  2832. }));
  2833. scrollPosition.top = newTop;
  2834. scrollPosition.left = newLeft;
  2835. };
  2836. /** Removes the event listeners associated with this drop list. */
  2837. /**
  2838. * Removes the event listeners associated with this drop list.
  2839. * @private
  2840. * @return {?}
  2841. */
  2842. DropListRef.prototype._removeListeners = /**
  2843. * Removes the event listeners associated with this drop list.
  2844. * @private
  2845. * @return {?}
  2846. */
  2847. function () {
  2848. coercion.coerceElement(this.element).removeEventListener('scroll', this._handleScroll);
  2849. this._viewportScrollSubscription.unsubscribe();
  2850. };
  2851. /**
  2852. * Checks whether the user's pointer is positioned over the container.
  2853. * @param x Pointer position along the X axis.
  2854. * @param y Pointer position along the Y axis.
  2855. */
  2856. /**
  2857. * Checks whether the user's pointer is positioned over the container.
  2858. * @param {?} x Pointer position along the X axis.
  2859. * @param {?} y Pointer position along the Y axis.
  2860. * @return {?}
  2861. */
  2862. DropListRef.prototype._isOverContainer = /**
  2863. * Checks whether the user's pointer is positioned over the container.
  2864. * @param {?} x Pointer position along the X axis.
  2865. * @param {?} y Pointer position along the Y axis.
  2866. * @return {?}
  2867. */
  2868. function (x, y) {
  2869. return isInsideClientRect(this._clientRect, x, y);
  2870. };
  2871. /**
  2872. * Figures out whether an item should be moved into a sibling
  2873. * drop container, based on its current position.
  2874. * @param item Drag item that is being moved.
  2875. * @param x Position of the item along the X axis.
  2876. * @param y Position of the item along the Y axis.
  2877. */
  2878. /**
  2879. * Figures out whether an item should be moved into a sibling
  2880. * drop container, based on its current position.
  2881. * @param {?} item Drag item that is being moved.
  2882. * @param {?} x Position of the item along the X axis.
  2883. * @param {?} y Position of the item along the Y axis.
  2884. * @return {?}
  2885. */
  2886. DropListRef.prototype._getSiblingContainerFromPosition = /**
  2887. * Figures out whether an item should be moved into a sibling
  2888. * drop container, based on its current position.
  2889. * @param {?} item Drag item that is being moved.
  2890. * @param {?} x Position of the item along the X axis.
  2891. * @param {?} y Position of the item along the Y axis.
  2892. * @return {?}
  2893. */
  2894. function (item, x, y) {
  2895. return this._siblings.find((/**
  2896. * @param {?} sibling
  2897. * @return {?}
  2898. */
  2899. function (sibling) { return sibling._canReceive(item, x, y); }));
  2900. };
  2901. /**
  2902. * Checks whether the drop list can receive the passed-in item.
  2903. * @param item Item that is being dragged into the list.
  2904. * @param x Position of the item along the X axis.
  2905. * @param y Position of the item along the Y axis.
  2906. */
  2907. /**
  2908. * Checks whether the drop list can receive the passed-in item.
  2909. * @param {?} item Item that is being dragged into the list.
  2910. * @param {?} x Position of the item along the X axis.
  2911. * @param {?} y Position of the item along the Y axis.
  2912. * @return {?}
  2913. */
  2914. DropListRef.prototype._canReceive = /**
  2915. * Checks whether the drop list can receive the passed-in item.
  2916. * @param {?} item Item that is being dragged into the list.
  2917. * @param {?} x Position of the item along the X axis.
  2918. * @param {?} y Position of the item along the Y axis.
  2919. * @return {?}
  2920. */
  2921. function (item, x, y) {
  2922. if (!this.enterPredicate(item, this) || !isInsideClientRect(this._clientRect, x, y)) {
  2923. return false;
  2924. }
  2925. /** @type {?} */
  2926. var elementFromPoint = (/** @type {?} */ (this._shadowRoot.elementFromPoint(x, y)));
  2927. // If there's no element at the pointer position, then
  2928. // the client rect is probably scrolled out of the view.
  2929. if (!elementFromPoint) {
  2930. return false;
  2931. }
  2932. /** @type {?} */
  2933. var nativeElement = coercion.coerceElement(this.element);
  2934. // The `ClientRect`, that we're using to find the container over which the user is
  2935. // hovering, doesn't give us any information on whether the element has been scrolled
  2936. // out of the view or whether it's overlapping with other containers. This means that
  2937. // we could end up transferring the item into a container that's invisible or is positioned
  2938. // below another one. We use the result from `elementFromPoint` to get the top-most element
  2939. // at the pointer position and to find whether it's one of the intersecting drop containers.
  2940. return elementFromPoint === nativeElement || nativeElement.contains(elementFromPoint);
  2941. };
  2942. /**
  2943. * Called by one of the connected drop lists when a dragging sequence has started.
  2944. * @param sibling Sibling in which dragging has started.
  2945. */
  2946. /**
  2947. * Called by one of the connected drop lists when a dragging sequence has started.
  2948. * @param {?} sibling Sibling in which dragging has started.
  2949. * @return {?}
  2950. */
  2951. DropListRef.prototype._startReceiving = /**
  2952. * Called by one of the connected drop lists when a dragging sequence has started.
  2953. * @param {?} sibling Sibling in which dragging has started.
  2954. * @return {?}
  2955. */
  2956. function (sibling) {
  2957. /** @type {?} */
  2958. var activeSiblings = this._activeSiblings;
  2959. if (!activeSiblings.has(sibling)) {
  2960. activeSiblings.add(sibling);
  2961. this._cacheOwnPosition();
  2962. this._listenToScrollEvents();
  2963. }
  2964. };
  2965. /**
  2966. * Called by a connected drop list when dragging has stopped.
  2967. * @param sibling Sibling whose dragging has stopped.
  2968. */
  2969. /**
  2970. * Called by a connected drop list when dragging has stopped.
  2971. * @param {?} sibling Sibling whose dragging has stopped.
  2972. * @return {?}
  2973. */
  2974. DropListRef.prototype._stopReceiving = /**
  2975. * Called by a connected drop list when dragging has stopped.
  2976. * @param {?} sibling Sibling whose dragging has stopped.
  2977. * @return {?}
  2978. */
  2979. function (sibling) {
  2980. this._activeSiblings.delete(sibling);
  2981. this._viewportScrollSubscription.unsubscribe();
  2982. };
  2983. /**
  2984. * Starts listening to scroll events on the viewport.
  2985. * Used for updating the internal state of the list.
  2986. */
  2987. /**
  2988. * Starts listening to scroll events on the viewport.
  2989. * Used for updating the internal state of the list.
  2990. * @private
  2991. * @return {?}
  2992. */
  2993. DropListRef.prototype._listenToScrollEvents = /**
  2994. * Starts listening to scroll events on the viewport.
  2995. * Used for updating the internal state of the list.
  2996. * @private
  2997. * @return {?}
  2998. */
  2999. function () {
  3000. var _this = this;
  3001. this._viewportScrollPosition = (/** @type {?} */ (this._viewportRuler)).getViewportScrollPosition();
  3002. this._viewportScrollSubscription = this._dragDropRegistry.scroll.subscribe((/**
  3003. * @return {?}
  3004. */
  3005. function () {
  3006. if (_this.isDragging()) {
  3007. /** @type {?} */
  3008. var newPosition = (/** @type {?} */ (_this._viewportRuler)).getViewportScrollPosition();
  3009. _this._updateAfterScroll(_this._viewportScrollPosition, newPosition.top, newPosition.left, _this._clientRect);
  3010. }
  3011. else if (_this.isReceiving()) {
  3012. _this._cacheOwnPosition();
  3013. }
  3014. }));
  3015. };
  3016. return DropListRef;
  3017. }());
  3018. /**
  3019. * Updates the top/left positions of a `ClientRect`, as well as their bottom/right counterparts.
  3020. * @param {?} clientRect `ClientRect` that should be updated.
  3021. * @param {?} top Amount to add to the `top` position.
  3022. * @param {?} left Amount to add to the `left` position.
  3023. * @return {?}
  3024. */
  3025. function adjustClientRect(clientRect, top, left) {
  3026. clientRect.top += top;
  3027. clientRect.bottom = clientRect.top + clientRect.height;
  3028. clientRect.left += left;
  3029. clientRect.right = clientRect.left + clientRect.width;
  3030. }
  3031. /**
  3032. * Finds the index of an item that matches a predicate function. Used as an equivalent
  3033. * of `Array.prototype.findIndex` which isn't part of the standard Google typings.
  3034. * @template T
  3035. * @param {?} array Array in which to look for matches.
  3036. * @param {?} predicate Function used to determine whether an item is a match.
  3037. * @return {?}
  3038. */
  3039. function findIndex(array, predicate) {
  3040. for (var i = 0; i < array.length; i++) {
  3041. if (predicate(array[i], i, array)) {
  3042. return i;
  3043. }
  3044. }
  3045. return -1;
  3046. }
  3047. /**
  3048. * Checks whether some coordinates are within a `ClientRect`.
  3049. * @param {?} clientRect ClientRect that is being checked.
  3050. * @param {?} x Coordinates along the X axis.
  3051. * @param {?} y Coordinates along the Y axis.
  3052. * @return {?}
  3053. */
  3054. function isInsideClientRect(clientRect, x, y) {
  3055. var top = clientRect.top, bottom = clientRect.bottom, left = clientRect.left, right = clientRect.right;
  3056. return y >= top && y <= bottom && x >= left && x <= right;
  3057. }
  3058. /**
  3059. * Gets a mutable version of an element's bounding `ClientRect`.
  3060. * @param {?} element
  3061. * @return {?}
  3062. */
  3063. function getMutableClientRect(element) {
  3064. /** @type {?} */
  3065. var clientRect = element.getBoundingClientRect();
  3066. // We need to clone the `clientRect` here, because all the values on it are readonly
  3067. // and we need to be able to update them. Also we can't use a spread here, because
  3068. // the values on a `ClientRect` aren't own properties. See:
  3069. // https://developer.mozilla.org/en-US/docs/Web/API/Element/getBoundingClientRect#Notes
  3070. return {
  3071. top: clientRect.top,
  3072. right: clientRect.right,
  3073. bottom: clientRect.bottom,
  3074. left: clientRect.left,
  3075. width: clientRect.width,
  3076. height: clientRect.height
  3077. };
  3078. }
  3079. /**
  3080. * Increments the vertical scroll position of a node.
  3081. * @param {?} node Node whose scroll position should change.
  3082. * @param {?} amount Amount of pixels that the `node` should be scrolled.
  3083. * @return {?}
  3084. */
  3085. function incrementVerticalScroll(node, amount) {
  3086. if (node === window) {
  3087. ((/** @type {?} */ (node))).scrollBy(0, amount);
  3088. }
  3089. else {
  3090. // Ideally we could use `Element.scrollBy` here as well, but IE and Edge don't support it.
  3091. ((/** @type {?} */ (node))).scrollTop += amount;
  3092. }
  3093. }
  3094. /**
  3095. * Increments the horizontal scroll position of a node.
  3096. * @param {?} node Node whose scroll position should change.
  3097. * @param {?} amount Amount of pixels that the `node` should be scrolled.
  3098. * @return {?}
  3099. */
  3100. function incrementHorizontalScroll(node, amount) {
  3101. if (node === window) {
  3102. ((/** @type {?} */ (node))).scrollBy(amount, 0);
  3103. }
  3104. else {
  3105. // Ideally we could use `Element.scrollBy` here as well, but IE and Edge don't support it.
  3106. ((/** @type {?} */ (node))).scrollLeft += amount;
  3107. }
  3108. }
  3109. /**
  3110. * Gets whether the vertical auto-scroll direction of a node.
  3111. * @param {?} clientRect Dimensions of the node.
  3112. * @param {?} pointerY Position of the user's pointer along the y axis.
  3113. * @return {?}
  3114. */
  3115. function getVerticalScrollDirection(clientRect, pointerY) {
  3116. var top = clientRect.top, bottom = clientRect.bottom, height = clientRect.height;
  3117. /** @type {?} */
  3118. var yThreshold = height * SCROLL_PROXIMITY_THRESHOLD;
  3119. if (pointerY >= top - yThreshold && pointerY <= top + yThreshold) {
  3120. return 1 /* UP */;
  3121. }
  3122. else if (pointerY >= bottom - yThreshold && pointerY <= bottom + yThreshold) {
  3123. return 2 /* DOWN */;
  3124. }
  3125. return 0 /* NONE */;
  3126. }
  3127. /**
  3128. * Gets whether the horizontal auto-scroll direction of a node.
  3129. * @param {?} clientRect Dimensions of the node.
  3130. * @param {?} pointerX Position of the user's pointer along the x axis.
  3131. * @return {?}
  3132. */
  3133. function getHorizontalScrollDirection(clientRect, pointerX) {
  3134. var left = clientRect.left, right = clientRect.right, width = clientRect.width;
  3135. /** @type {?} */
  3136. var xThreshold = width * SCROLL_PROXIMITY_THRESHOLD;
  3137. if (pointerX >= left - xThreshold && pointerX <= left + xThreshold) {
  3138. return 1 /* LEFT */;
  3139. }
  3140. else if (pointerX >= right - xThreshold && pointerX <= right + xThreshold) {
  3141. return 2 /* RIGHT */;
  3142. }
  3143. return 0 /* NONE */;
  3144. }
  3145. /**
  3146. * Gets the directions in which an element node should be scrolled,
  3147. * assuming that the user's pointer is already within it scrollable region.
  3148. * @param {?} element Element for which we should calculate the scroll direction.
  3149. * @param {?} clientRect Bounding client rectangle of the element.
  3150. * @param {?} pointerX Position of the user's pointer along the x axis.
  3151. * @param {?} pointerY Position of the user's pointer along the y axis.
  3152. * @return {?}
  3153. */
  3154. function getElementScrollDirections(element, clientRect, pointerX, pointerY) {
  3155. /** @type {?} */
  3156. var computedVertical = getVerticalScrollDirection(clientRect, pointerY);
  3157. /** @type {?} */
  3158. var computedHorizontal = getHorizontalScrollDirection(clientRect, pointerX);
  3159. /** @type {?} */
  3160. var verticalScrollDirection = 0 /* NONE */;
  3161. /** @type {?} */
  3162. var horizontalScrollDirection = 0 /* NONE */;
  3163. // Note that we here we do some extra checks for whether the element is actually scrollable in
  3164. // a certain direction and we only assign the scroll direction if it is. We do this so that we
  3165. // can allow other elements to be scrolled, if the current element can't be scrolled anymore.
  3166. // This allows us to handle cases where the scroll regions of two scrollable elements overlap.
  3167. if (computedVertical) {
  3168. /** @type {?} */
  3169. var scrollTop = element.scrollTop;
  3170. if (computedVertical === 1 /* UP */) {
  3171. if (scrollTop > 0) {
  3172. verticalScrollDirection = 1 /* UP */;
  3173. }
  3174. }
  3175. else if (element.scrollHeight - scrollTop > element.clientHeight) {
  3176. verticalScrollDirection = 2 /* DOWN */;
  3177. }
  3178. }
  3179. if (computedHorizontal) {
  3180. /** @type {?} */
  3181. var scrollLeft = element.scrollLeft;
  3182. if (computedHorizontal === 1 /* LEFT */) {
  3183. if (scrollLeft > 0) {
  3184. horizontalScrollDirection = 1 /* LEFT */;
  3185. }
  3186. }
  3187. else if (element.scrollWidth - scrollLeft > element.clientWidth) {
  3188. horizontalScrollDirection = 2 /* RIGHT */;
  3189. }
  3190. }
  3191. return [verticalScrollDirection, horizontalScrollDirection];
  3192. }
  3193. /**
  3194. * Gets the shadow root of an element, if any.
  3195. * @param {?} element
  3196. * @return {?}
  3197. */
  3198. function getShadowRoot(element) {
  3199. if (platform._supportsShadowDom()) {
  3200. /** @type {?} */
  3201. var rootNode = element.getRootNode ? element.getRootNode() : null;
  3202. if (rootNode instanceof ShadowRoot) {
  3203. return rootNode;
  3204. }
  3205. }
  3206. return null;
  3207. }
  3208. /**
  3209. * @fileoverview added by tsickle
  3210. * @suppress {checkTypes,extraRequire,missingOverride,missingReturn,unusedPrivateMembers,uselessCode} checked by tsc
  3211. */
  3212. /**
  3213. * Event options that can be used to bind an active, capturing event.
  3214. * @type {?}
  3215. */
  3216. var activeCapturingEventOptions = platform.normalizePassiveListenerOptions({
  3217. passive: false,
  3218. capture: true
  3219. });
  3220. /**
  3221. * Service that keeps track of all the drag item and drop container
  3222. * instances, and manages global event listeners on the `document`.
  3223. * \@docs-private
  3224. * @template I, C
  3225. */
  3226. // Note: this class is generic, rather than referencing CdkDrag and CdkDropList directly, in order
  3227. // to avoid circular imports. If we were to reference them here, importing the registry into the
  3228. // classes that are registering themselves will introduce a circular import.
  3229. var DragDropRegistry = /** @class */ (function () {
  3230. function DragDropRegistry(_ngZone, _document) {
  3231. var _this = this;
  3232. this._ngZone = _ngZone;
  3233. /**
  3234. * Registered drop container instances.
  3235. */
  3236. this._dropInstances = new Set();
  3237. /**
  3238. * Registered drag item instances.
  3239. */
  3240. this._dragInstances = new Set();
  3241. /**
  3242. * Drag item instances that are currently being dragged.
  3243. */
  3244. this._activeDragInstances = new Set();
  3245. /**
  3246. * Keeps track of the event listeners that we've bound to the `document`.
  3247. */
  3248. this._globalListeners = new Map();
  3249. /**
  3250. * Emits the `touchmove` or `mousemove` events that are dispatched
  3251. * while the user is dragging a drag item instance.
  3252. */
  3253. this.pointerMove = new rxjs.Subject();
  3254. /**
  3255. * Emits the `touchend` or `mouseup` events that are dispatched
  3256. * while the user is dragging a drag item instance.
  3257. */
  3258. this.pointerUp = new rxjs.Subject();
  3259. /**
  3260. * Emits when the viewport has been scrolled while the user is dragging an item.
  3261. */
  3262. this.scroll = new rxjs.Subject();
  3263. /**
  3264. * Event listener that will prevent the default browser action while the user is dragging.
  3265. * @param event Event whose default action should be prevented.
  3266. */
  3267. this._preventDefaultWhileDragging = (/**
  3268. * @param {?} event
  3269. * @return {?}
  3270. */
  3271. function (event) {
  3272. if (_this._activeDragInstances.size) {
  3273. event.preventDefault();
  3274. }
  3275. });
  3276. this._document = _document;
  3277. }
  3278. /** Adds a drop container to the registry. */
  3279. /**
  3280. * Adds a drop container to the registry.
  3281. * @param {?} drop
  3282. * @return {?}
  3283. */
  3284. DragDropRegistry.prototype.registerDropContainer = /**
  3285. * Adds a drop container to the registry.
  3286. * @param {?} drop
  3287. * @return {?}
  3288. */
  3289. function (drop) {
  3290. if (!this._dropInstances.has(drop)) {
  3291. if (this.getDropContainer(drop.id)) {
  3292. throw Error("Drop instance with id \"" + drop.id + "\" has already been registered.");
  3293. }
  3294. this._dropInstances.add(drop);
  3295. }
  3296. };
  3297. /** Adds a drag item instance to the registry. */
  3298. /**
  3299. * Adds a drag item instance to the registry.
  3300. * @param {?} drag
  3301. * @return {?}
  3302. */
  3303. DragDropRegistry.prototype.registerDragItem = /**
  3304. * Adds a drag item instance to the registry.
  3305. * @param {?} drag
  3306. * @return {?}
  3307. */
  3308. function (drag) {
  3309. var _this = this;
  3310. this._dragInstances.add(drag);
  3311. // The `touchmove` event gets bound once, ahead of time, because WebKit
  3312. // won't preventDefault on a dynamically-added `touchmove` listener.
  3313. // See https://bugs.webkit.org/show_bug.cgi?id=184250.
  3314. if (this._dragInstances.size === 1) {
  3315. this._ngZone.runOutsideAngular((/**
  3316. * @return {?}
  3317. */
  3318. function () {
  3319. // The event handler has to be explicitly active,
  3320. // because newer browsers make it passive by default.
  3321. _this._document.addEventListener('touchmove', _this._preventDefaultWhileDragging, activeCapturingEventOptions);
  3322. }));
  3323. }
  3324. };
  3325. /** Removes a drop container from the registry. */
  3326. /**
  3327. * Removes a drop container from the registry.
  3328. * @param {?} drop
  3329. * @return {?}
  3330. */
  3331. DragDropRegistry.prototype.removeDropContainer = /**
  3332. * Removes a drop container from the registry.
  3333. * @param {?} drop
  3334. * @return {?}
  3335. */
  3336. function (drop) {
  3337. this._dropInstances.delete(drop);
  3338. };
  3339. /** Removes a drag item instance from the registry. */
  3340. /**
  3341. * Removes a drag item instance from the registry.
  3342. * @param {?} drag
  3343. * @return {?}
  3344. */
  3345. DragDropRegistry.prototype.removeDragItem = /**
  3346. * Removes a drag item instance from the registry.
  3347. * @param {?} drag
  3348. * @return {?}
  3349. */
  3350. function (drag) {
  3351. this._dragInstances.delete(drag);
  3352. this.stopDragging(drag);
  3353. if (this._dragInstances.size === 0) {
  3354. this._document.removeEventListener('touchmove', this._preventDefaultWhileDragging, activeCapturingEventOptions);
  3355. }
  3356. };
  3357. /**
  3358. * Starts the dragging sequence for a drag instance.
  3359. * @param drag Drag instance which is being dragged.
  3360. * @param event Event that initiated the dragging.
  3361. */
  3362. /**
  3363. * Starts the dragging sequence for a drag instance.
  3364. * @param {?} drag Drag instance which is being dragged.
  3365. * @param {?} event Event that initiated the dragging.
  3366. * @return {?}
  3367. */
  3368. DragDropRegistry.prototype.startDragging = /**
  3369. * Starts the dragging sequence for a drag instance.
  3370. * @param {?} drag Drag instance which is being dragged.
  3371. * @param {?} event Event that initiated the dragging.
  3372. * @return {?}
  3373. */
  3374. function (drag, event) {
  3375. var _this = this;
  3376. // Do not process the same drag twice to avoid memory leaks and redundant listeners
  3377. if (this._activeDragInstances.has(drag)) {
  3378. return;
  3379. }
  3380. this._activeDragInstances.add(drag);
  3381. if (this._activeDragInstances.size === 1) {
  3382. /** @type {?} */
  3383. var isTouchEvent = event.type.startsWith('touch');
  3384. /** @type {?} */
  3385. var moveEvent = isTouchEvent ? 'touchmove' : 'mousemove';
  3386. /** @type {?} */
  3387. var upEvent = isTouchEvent ? 'touchend' : 'mouseup';
  3388. // We explicitly bind __active__ listeners here, because newer browsers will default to
  3389. // passive ones for `mousemove` and `touchmove`. The events need to be active, because we
  3390. // use `preventDefault` to prevent the page from scrolling while the user is dragging.
  3391. this._globalListeners
  3392. .set(moveEvent, {
  3393. handler: (/**
  3394. * @param {?} e
  3395. * @return {?}
  3396. */
  3397. function (e) { return _this.pointerMove.next((/** @type {?} */ (e))); }),
  3398. options: activeCapturingEventOptions
  3399. })
  3400. .set(upEvent, {
  3401. handler: (/**
  3402. * @param {?} e
  3403. * @return {?}
  3404. */
  3405. function (e) { return _this.pointerUp.next((/** @type {?} */ (e))); }),
  3406. options: true
  3407. })
  3408. .set('scroll', {
  3409. handler: (/**
  3410. * @param {?} e
  3411. * @return {?}
  3412. */
  3413. function (e) { return _this.scroll.next(e); }),
  3414. // Use capturing so that we pick up scroll changes in any scrollable nodes that aren't
  3415. // the document. See https://github.com/angular/components/issues/17144.
  3416. options: true
  3417. })
  3418. // Preventing the default action on `mousemove` isn't enough to disable text selection
  3419. // on Safari so we need to prevent the selection event as well. Alternatively this can
  3420. // be done by setting `user-select: none` on the `body`, however it has causes a style
  3421. // recalculation which can be expensive on pages with a lot of elements.
  3422. .set('selectstart', {
  3423. handler: this._preventDefaultWhileDragging,
  3424. options: activeCapturingEventOptions
  3425. });
  3426. this._ngZone.runOutsideAngular((/**
  3427. * @return {?}
  3428. */
  3429. function () {
  3430. _this._globalListeners.forEach((/**
  3431. * @param {?} config
  3432. * @param {?} name
  3433. * @return {?}
  3434. */
  3435. function (config, name) {
  3436. _this._document.addEventListener(name, config.handler, config.options);
  3437. }));
  3438. }));
  3439. }
  3440. };
  3441. /** Stops dragging a drag item instance. */
  3442. /**
  3443. * Stops dragging a drag item instance.
  3444. * @param {?} drag
  3445. * @return {?}
  3446. */
  3447. DragDropRegistry.prototype.stopDragging = /**
  3448. * Stops dragging a drag item instance.
  3449. * @param {?} drag
  3450. * @return {?}
  3451. */
  3452. function (drag) {
  3453. this._activeDragInstances.delete(drag);
  3454. if (this._activeDragInstances.size === 0) {
  3455. this._clearGlobalListeners();
  3456. }
  3457. };
  3458. /** Gets whether a drag item instance is currently being dragged. */
  3459. /**
  3460. * Gets whether a drag item instance is currently being dragged.
  3461. * @param {?} drag
  3462. * @return {?}
  3463. */
  3464. DragDropRegistry.prototype.isDragging = /**
  3465. * Gets whether a drag item instance is currently being dragged.
  3466. * @param {?} drag
  3467. * @return {?}
  3468. */
  3469. function (drag) {
  3470. return this._activeDragInstances.has(drag);
  3471. };
  3472. /**
  3473. * Gets a drop container by its id.
  3474. * @deprecated No longer being used. To be removed.
  3475. * @breaking-change 8.0.0
  3476. */
  3477. /**
  3478. * Gets a drop container by its id.
  3479. * @deprecated No longer being used. To be removed.
  3480. * \@breaking-change 8.0.0
  3481. * @param {?} id
  3482. * @return {?}
  3483. */
  3484. DragDropRegistry.prototype.getDropContainer = /**
  3485. * Gets a drop container by its id.
  3486. * @deprecated No longer being used. To be removed.
  3487. * \@breaking-change 8.0.0
  3488. * @param {?} id
  3489. * @return {?}
  3490. */
  3491. function (id) {
  3492. return Array.from(this._dropInstances).find((/**
  3493. * @param {?} instance
  3494. * @return {?}
  3495. */
  3496. function (instance) { return instance.id === id; }));
  3497. };
  3498. /**
  3499. * @return {?}
  3500. */
  3501. DragDropRegistry.prototype.ngOnDestroy = /**
  3502. * @return {?}
  3503. */
  3504. function () {
  3505. var _this = this;
  3506. this._dragInstances.forEach((/**
  3507. * @param {?} instance
  3508. * @return {?}
  3509. */
  3510. function (instance) { return _this.removeDragItem(instance); }));
  3511. this._dropInstances.forEach((/**
  3512. * @param {?} instance
  3513. * @return {?}
  3514. */
  3515. function (instance) { return _this.removeDropContainer(instance); }));
  3516. this._clearGlobalListeners();
  3517. this.pointerMove.complete();
  3518. this.pointerUp.complete();
  3519. };
  3520. /** Clears out the global event listeners from the `document`. */
  3521. /**
  3522. * Clears out the global event listeners from the `document`.
  3523. * @private
  3524. * @return {?}
  3525. */
  3526. DragDropRegistry.prototype._clearGlobalListeners = /**
  3527. * Clears out the global event listeners from the `document`.
  3528. * @private
  3529. * @return {?}
  3530. */
  3531. function () {
  3532. var _this = this;
  3533. this._globalListeners.forEach((/**
  3534. * @param {?} config
  3535. * @param {?} name
  3536. * @return {?}
  3537. */
  3538. function (config, name) {
  3539. _this._document.removeEventListener(name, config.handler, config.options);
  3540. }));
  3541. this._globalListeners.clear();
  3542. };
  3543. DragDropRegistry.decorators = [
  3544. { type: core.Injectable, args: [{ providedIn: 'root' },] },
  3545. ];
  3546. /** @nocollapse */
  3547. DragDropRegistry.ctorParameters = function () { return [
  3548. { type: core.NgZone },
  3549. { type: undefined, decorators: [{ type: core.Inject, args: [common.DOCUMENT,] }] }
  3550. ]; };
  3551. /** @nocollapse */ DragDropRegistry.ngInjectableDef = core.ɵɵdefineInjectable({ factory: function DragDropRegistry_Factory() { return new DragDropRegistry(core.ɵɵinject(core.NgZone), core.ɵɵinject(common.DOCUMENT)); }, token: DragDropRegistry, providedIn: "root" });
  3552. return DragDropRegistry;
  3553. }());
  3554. /**
  3555. * @fileoverview added by tsickle
  3556. * @suppress {checkTypes,extraRequire,missingOverride,missingReturn,unusedPrivateMembers,uselessCode} checked by tsc
  3557. */
  3558. /**
  3559. * Default configuration to be used when creating a `DragRef`.
  3560. * @type {?}
  3561. */
  3562. var DEFAULT_CONFIG = {
  3563. dragStartThreshold: 5,
  3564. pointerDirectionChangeThreshold: 5
  3565. };
  3566. /**
  3567. * Service that allows for drag-and-drop functionality to be attached to DOM elements.
  3568. */
  3569. var DragDrop = /** @class */ (function () {
  3570. function DragDrop(_document, _ngZone, _viewportRuler, _dragDropRegistry) {
  3571. this._document = _document;
  3572. this._ngZone = _ngZone;
  3573. this._viewportRuler = _viewportRuler;
  3574. this._dragDropRegistry = _dragDropRegistry;
  3575. }
  3576. /**
  3577. * Turns an element into a draggable item.
  3578. * @param element Element to which to attach the dragging functionality.
  3579. * @param config Object used to configure the dragging behavior.
  3580. */
  3581. /**
  3582. * Turns an element into a draggable item.
  3583. * @template T
  3584. * @param {?} element Element to which to attach the dragging functionality.
  3585. * @param {?=} config Object used to configure the dragging behavior.
  3586. * @return {?}
  3587. */
  3588. DragDrop.prototype.createDrag = /**
  3589. * Turns an element into a draggable item.
  3590. * @template T
  3591. * @param {?} element Element to which to attach the dragging functionality.
  3592. * @param {?=} config Object used to configure the dragging behavior.
  3593. * @return {?}
  3594. */
  3595. function (element, config) {
  3596. if (config === void 0) { config = DEFAULT_CONFIG; }
  3597. return new DragRef(element, config, this._document, this._ngZone, this._viewportRuler, this._dragDropRegistry);
  3598. };
  3599. /**
  3600. * Turns an element into a drop list.
  3601. * @param element Element to which to attach the drop list functionality.
  3602. */
  3603. /**
  3604. * Turns an element into a drop list.
  3605. * @template T
  3606. * @param {?} element Element to which to attach the drop list functionality.
  3607. * @return {?}
  3608. */
  3609. DragDrop.prototype.createDropList = /**
  3610. * Turns an element into a drop list.
  3611. * @template T
  3612. * @param {?} element Element to which to attach the drop list functionality.
  3613. * @return {?}
  3614. */
  3615. function (element) {
  3616. return new DropListRef(element, this._dragDropRegistry, this._document, this._ngZone, this._viewportRuler);
  3617. };
  3618. DragDrop.decorators = [
  3619. { type: core.Injectable, args: [{ providedIn: 'root' },] },
  3620. ];
  3621. /** @nocollapse */
  3622. DragDrop.ctorParameters = function () { return [
  3623. { type: undefined, decorators: [{ type: core.Inject, args: [common.DOCUMENT,] }] },
  3624. { type: core.NgZone },
  3625. { type: scrolling.ViewportRuler },
  3626. { type: DragDropRegistry }
  3627. ]; };
  3628. /** @nocollapse */ DragDrop.ngInjectableDef = core.ɵɵdefineInjectable({ factory: function DragDrop_Factory() { return new DragDrop(core.ɵɵinject(common.DOCUMENT), core.ɵɵinject(core.NgZone), core.ɵɵinject(scrolling.ViewportRuler), core.ɵɵinject(DragDropRegistry)); }, token: DragDrop, providedIn: "root" });
  3629. return DragDrop;
  3630. }());
  3631. /**
  3632. * @fileoverview added by tsickle
  3633. * @suppress {checkTypes,extraRequire,missingOverride,missingReturn,unusedPrivateMembers,uselessCode} checked by tsc
  3634. */
  3635. /**
  3636. * Injection token that is used to provide a CdkDropList instance to CdkDrag.
  3637. * Used for avoiding circular imports.
  3638. * @type {?}
  3639. */
  3640. var CDK_DROP_LIST = new core.InjectionToken('CDK_DROP_LIST');
  3641. /**
  3642. * Injection token that is used to provide a CdkDropList instance to CdkDrag.
  3643. * Used for avoiding circular imports.
  3644. * @deprecated Use `CDK_DROP_LIST` instead.
  3645. * \@breaking-change 8.0.0
  3646. * @type {?}
  3647. */
  3648. var CDK_DROP_LIST_CONTAINER = CDK_DROP_LIST;
  3649. /**
  3650. * @fileoverview added by tsickle
  3651. * @suppress {checkTypes,extraRequire,missingOverride,missingReturn,unusedPrivateMembers,uselessCode} checked by tsc
  3652. */
  3653. /**
  3654. * @fileoverview added by tsickle
  3655. * @suppress {checkTypes,extraRequire,missingOverride,missingReturn,unusedPrivateMembers,uselessCode} checked by tsc
  3656. */
  3657. /**
  3658. * Injection token that can be used for a `CdkDrag` to provide itself as a parent to the
  3659. * drag-specific child directive (`CdkDragHandle`, `CdkDragPreview` etc.). Used primarily
  3660. * to avoid circular imports.
  3661. * \@docs-private
  3662. * @type {?}
  3663. */
  3664. var CDK_DRAG_PARENT = new core.InjectionToken('CDK_DRAG_PARENT');
  3665. /**
  3666. * @fileoverview added by tsickle
  3667. * @suppress {checkTypes,extraRequire,missingOverride,missingReturn,unusedPrivateMembers,uselessCode} checked by tsc
  3668. */
  3669. /**
  3670. * Handle that can be used to drag and CdkDrag instance.
  3671. */
  3672. var CdkDragHandle = /** @class */ (function () {
  3673. function CdkDragHandle(element, parentDrag) {
  3674. this.element = element;
  3675. /**
  3676. * Emits when the state of the handle has changed.
  3677. */
  3678. this._stateChanges = new rxjs.Subject();
  3679. this._disabled = false;
  3680. this._parentDrag = parentDrag;
  3681. toggleNativeDragInteractions(element.nativeElement, false);
  3682. }
  3683. Object.defineProperty(CdkDragHandle.prototype, "disabled", {
  3684. /** Whether starting to drag through this handle is disabled. */
  3685. get: /**
  3686. * Whether starting to drag through this handle is disabled.
  3687. * @return {?}
  3688. */
  3689. function () { return this._disabled; },
  3690. set: /**
  3691. * @param {?} value
  3692. * @return {?}
  3693. */
  3694. function (value) {
  3695. this._disabled = coercion.coerceBooleanProperty(value);
  3696. this._stateChanges.next(this);
  3697. },
  3698. enumerable: true,
  3699. configurable: true
  3700. });
  3701. /**
  3702. * @return {?}
  3703. */
  3704. CdkDragHandle.prototype.ngOnDestroy = /**
  3705. * @return {?}
  3706. */
  3707. function () {
  3708. this._stateChanges.complete();
  3709. };
  3710. CdkDragHandle.decorators = [
  3711. { type: core.Directive, args: [{
  3712. selector: '[cdkDragHandle]',
  3713. host: {
  3714. 'class': 'cdk-drag-handle'
  3715. }
  3716. },] },
  3717. ];
  3718. /** @nocollapse */
  3719. CdkDragHandle.ctorParameters = function () { return [
  3720. { type: core.ElementRef },
  3721. { type: undefined, decorators: [{ type: core.Inject, args: [CDK_DRAG_PARENT,] }, { type: core.Optional }] }
  3722. ]; };
  3723. CdkDragHandle.propDecorators = {
  3724. disabled: [{ type: core.Input, args: ['cdkDragHandleDisabled',] }]
  3725. };
  3726. return CdkDragHandle;
  3727. }());
  3728. /**
  3729. * @fileoverview added by tsickle
  3730. * @suppress {checkTypes,extraRequire,missingOverride,missingReturn,unusedPrivateMembers,uselessCode} checked by tsc
  3731. */
  3732. /**
  3733. * Element that will be used as a template for the placeholder of a CdkDrag when
  3734. * it is being dragged. The placeholder is displayed in place of the element being dragged.
  3735. * @template T
  3736. */
  3737. var CdkDragPlaceholder = /** @class */ (function () {
  3738. function CdkDragPlaceholder(templateRef) {
  3739. this.templateRef = templateRef;
  3740. }
  3741. CdkDragPlaceholder.decorators = [
  3742. { type: core.Directive, args: [{
  3743. selector: 'ng-template[cdkDragPlaceholder]'
  3744. },] },
  3745. ];
  3746. /** @nocollapse */
  3747. CdkDragPlaceholder.ctorParameters = function () { return [
  3748. { type: core.TemplateRef }
  3749. ]; };
  3750. CdkDragPlaceholder.propDecorators = {
  3751. data: [{ type: core.Input }]
  3752. };
  3753. return CdkDragPlaceholder;
  3754. }());
  3755. /**
  3756. * @fileoverview added by tsickle
  3757. * @suppress {checkTypes,extraRequire,missingOverride,missingReturn,unusedPrivateMembers,uselessCode} checked by tsc
  3758. */
  3759. /**
  3760. * Element that will be used as a template for the preview
  3761. * of a CdkDrag when it is being dragged.
  3762. * @template T
  3763. */
  3764. var CdkDragPreview = /** @class */ (function () {
  3765. function CdkDragPreview(templateRef) {
  3766. this.templateRef = templateRef;
  3767. }
  3768. CdkDragPreview.decorators = [
  3769. { type: core.Directive, args: [{
  3770. selector: 'ng-template[cdkDragPreview]'
  3771. },] },
  3772. ];
  3773. /** @nocollapse */
  3774. CdkDragPreview.ctorParameters = function () { return [
  3775. { type: core.TemplateRef }
  3776. ]; };
  3777. CdkDragPreview.propDecorators = {
  3778. data: [{ type: core.Input }]
  3779. };
  3780. return CdkDragPreview;
  3781. }());
  3782. /**
  3783. * @fileoverview added by tsickle
  3784. * @suppress {checkTypes,extraRequire,missingOverride,missingReturn,unusedPrivateMembers,uselessCode} checked by tsc
  3785. */
  3786. /**
  3787. * Injection token that can be used to configure the behavior of `CdkDrag`.
  3788. * @type {?}
  3789. */
  3790. var CDK_DRAG_CONFIG = new core.InjectionToken('CDK_DRAG_CONFIG', {
  3791. providedIn: 'root',
  3792. factory: CDK_DRAG_CONFIG_FACTORY
  3793. });
  3794. /**
  3795. * \@docs-private
  3796. * @return {?}
  3797. */
  3798. function CDK_DRAG_CONFIG_FACTORY() {
  3799. return { dragStartThreshold: 5, pointerDirectionChangeThreshold: 5 };
  3800. }
  3801. /**
  3802. * Element that can be moved inside a CdkDropList container.
  3803. * @template T
  3804. */
  3805. var CdkDrag = /** @class */ (function () {
  3806. function CdkDrag(element, dropContainer, _document, _ngZone, _viewContainerRef, config, _dir, dragDrop, _changeDetectorRef) {
  3807. var _this = this;
  3808. this.element = element;
  3809. this.dropContainer = dropContainer;
  3810. this._document = _document;
  3811. this._ngZone = _ngZone;
  3812. this._viewContainerRef = _viewContainerRef;
  3813. this._dir = _dir;
  3814. this._changeDetectorRef = _changeDetectorRef;
  3815. this._destroyed = new rxjs.Subject();
  3816. /**
  3817. * Amount of milliseconds to wait after the user has put their
  3818. * pointer down before starting to drag the element.
  3819. */
  3820. this.dragStartDelay = 0;
  3821. this._disabled = false;
  3822. /**
  3823. * Emits when the user starts dragging the item.
  3824. */
  3825. this.started = new core.EventEmitter();
  3826. /**
  3827. * Emits when the user has released a drag item, before any animations have started.
  3828. */
  3829. this.released = new core.EventEmitter();
  3830. /**
  3831. * Emits when the user stops dragging an item in the container.
  3832. */
  3833. this.ended = new core.EventEmitter();
  3834. /**
  3835. * Emits when the user has moved the item into a new container.
  3836. */
  3837. this.entered = new core.EventEmitter();
  3838. /**
  3839. * Emits when the user removes the item its container by dragging it into another container.
  3840. */
  3841. this.exited = new core.EventEmitter();
  3842. /**
  3843. * Emits when the user drops the item inside a container.
  3844. */
  3845. this.dropped = new core.EventEmitter();
  3846. /**
  3847. * Emits as the user is dragging the item. Use with caution,
  3848. * because this event will fire for every pixel that the user has dragged.
  3849. */
  3850. this.moved = new rxjs.Observable((/**
  3851. * @param {?} observer
  3852. * @return {?}
  3853. */
  3854. function (observer) {
  3855. /** @type {?} */
  3856. var subscription = _this._dragRef.moved.pipe(operators.map((/**
  3857. * @param {?} movedEvent
  3858. * @return {?}
  3859. */
  3860. function (movedEvent) { return ({
  3861. source: _this,
  3862. pointerPosition: movedEvent.pointerPosition,
  3863. event: movedEvent.event,
  3864. delta: movedEvent.delta,
  3865. distance: movedEvent.distance
  3866. }); }))).subscribe(observer);
  3867. return (/**
  3868. * @return {?}
  3869. */
  3870. function () {
  3871. subscription.unsubscribe();
  3872. });
  3873. }));
  3874. this._dragRef = dragDrop.createDrag(element, config);
  3875. this._dragRef.data = this;
  3876. this._syncInputs(this._dragRef);
  3877. this._handleEvents(this._dragRef);
  3878. }
  3879. Object.defineProperty(CdkDrag.prototype, "boundaryElementSelector", {
  3880. /**
  3881. * Selector that will be used to determine the element to which the draggable's position will
  3882. * be constrained. Matching starts from the element's parent and goes up the DOM until a matching
  3883. * element has been found
  3884. * @deprecated Use `boundaryElement` instead.
  3885. * @breaking-change 9.0.0
  3886. */
  3887. get: /**
  3888. * Selector that will be used to determine the element to which the draggable's position will
  3889. * be constrained. Matching starts from the element's parent and goes up the DOM until a matching
  3890. * element has been found
  3891. * @deprecated Use `boundaryElement` instead.
  3892. * \@breaking-change 9.0.0
  3893. * @return {?}
  3894. */
  3895. function () {
  3896. return typeof this.boundaryElement === 'string' ? this.boundaryElement : (/** @type {?} */ (undefined));
  3897. },
  3898. set: /**
  3899. * @param {?} selector
  3900. * @return {?}
  3901. */
  3902. function (selector) {
  3903. this.boundaryElement = selector;
  3904. },
  3905. enumerable: true,
  3906. configurable: true
  3907. });
  3908. Object.defineProperty(CdkDrag.prototype, "disabled", {
  3909. /** Whether starting to drag this element is disabled. */
  3910. get: /**
  3911. * Whether starting to drag this element is disabled.
  3912. * @return {?}
  3913. */
  3914. function () {
  3915. return this._disabled || (this.dropContainer && this.dropContainer.disabled);
  3916. },
  3917. set: /**
  3918. * @param {?} value
  3919. * @return {?}
  3920. */
  3921. function (value) {
  3922. this._disabled = coercion.coerceBooleanProperty(value);
  3923. this._dragRef.disabled = this._disabled;
  3924. },
  3925. enumerable: true,
  3926. configurable: true
  3927. });
  3928. /**
  3929. * Returns the element that is being used as a placeholder
  3930. * while the current element is being dragged.
  3931. */
  3932. /**
  3933. * Returns the element that is being used as a placeholder
  3934. * while the current element is being dragged.
  3935. * @return {?}
  3936. */
  3937. CdkDrag.prototype.getPlaceholderElement = /**
  3938. * Returns the element that is being used as a placeholder
  3939. * while the current element is being dragged.
  3940. * @return {?}
  3941. */
  3942. function () {
  3943. return this._dragRef.getPlaceholderElement();
  3944. };
  3945. /** Returns the root draggable element. */
  3946. /**
  3947. * Returns the root draggable element.
  3948. * @return {?}
  3949. */
  3950. CdkDrag.prototype.getRootElement = /**
  3951. * Returns the root draggable element.
  3952. * @return {?}
  3953. */
  3954. function () {
  3955. return this._dragRef.getRootElement();
  3956. };
  3957. /** Resets a standalone drag item to its initial position. */
  3958. /**
  3959. * Resets a standalone drag item to its initial position.
  3960. * @return {?}
  3961. */
  3962. CdkDrag.prototype.reset = /**
  3963. * Resets a standalone drag item to its initial position.
  3964. * @return {?}
  3965. */
  3966. function () {
  3967. this._dragRef.reset();
  3968. };
  3969. /**
  3970. * Gets the pixel coordinates of the draggable outside of a drop container.
  3971. */
  3972. /**
  3973. * Gets the pixel coordinates of the draggable outside of a drop container.
  3974. * @return {?}
  3975. */
  3976. CdkDrag.prototype.getFreeDragPosition = /**
  3977. * Gets the pixel coordinates of the draggable outside of a drop container.
  3978. * @return {?}
  3979. */
  3980. function () {
  3981. return this._dragRef.getFreeDragPosition();
  3982. };
  3983. /**
  3984. * @return {?}
  3985. */
  3986. CdkDrag.prototype.ngAfterViewInit = /**
  3987. * @return {?}
  3988. */
  3989. function () {
  3990. var _this = this;
  3991. // We need to wait for the zone to stabilize, in order for the reference
  3992. // element to be in the proper place in the DOM. This is mostly relevant
  3993. // for draggable elements inside portals since they get stamped out in
  3994. // their original DOM position and then they get transferred to the portal.
  3995. this._ngZone.onStable.asObservable()
  3996. .pipe(operators.take(1), operators.takeUntil(this._destroyed))
  3997. .subscribe((/**
  3998. * @return {?}
  3999. */
  4000. function () {
  4001. _this._updateRootElement();
  4002. // Listen for any newly-added handles.
  4003. _this._handles.changes.pipe(operators.startWith(_this._handles),
  4004. // Sync the new handles with the DragRef.
  4005. operators.tap((/**
  4006. * @param {?} handles
  4007. * @return {?}
  4008. */
  4009. function (handles) {
  4010. /** @type {?} */
  4011. var childHandleElements = handles
  4012. .filter((/**
  4013. * @param {?} handle
  4014. * @return {?}
  4015. */
  4016. function (handle) { return handle._parentDrag === _this; }))
  4017. .map((/**
  4018. * @param {?} handle
  4019. * @return {?}
  4020. */
  4021. function (handle) { return handle.element; }));
  4022. _this._dragRef.withHandles(childHandleElements);
  4023. })),
  4024. // Listen if the state of any of the handles changes.
  4025. operators.switchMap((/**
  4026. * @param {?} handles
  4027. * @return {?}
  4028. */
  4029. function (handles) {
  4030. return rxjs.merge.apply(void 0, handles.map((/**
  4031. * @param {?} item
  4032. * @return {?}
  4033. */
  4034. function (item) { return item._stateChanges; })));
  4035. })), operators.takeUntil(_this._destroyed)).subscribe((/**
  4036. * @param {?} handleInstance
  4037. * @return {?}
  4038. */
  4039. function (handleInstance) {
  4040. // Enabled/disable the handle that changed in the DragRef.
  4041. /** @type {?} */
  4042. var dragRef = _this._dragRef;
  4043. /** @type {?} */
  4044. var handle = handleInstance.element.nativeElement;
  4045. handleInstance.disabled ? dragRef.disableHandle(handle) : dragRef.enableHandle(handle);
  4046. }));
  4047. if (_this.freeDragPosition) {
  4048. _this._dragRef.setFreeDragPosition(_this.freeDragPosition);
  4049. }
  4050. }));
  4051. };
  4052. /**
  4053. * @param {?} changes
  4054. * @return {?}
  4055. */
  4056. CdkDrag.prototype.ngOnChanges = /**
  4057. * @param {?} changes
  4058. * @return {?}
  4059. */
  4060. function (changes) {
  4061. /** @type {?} */
  4062. var rootSelectorChange = changes['rootElementSelector'];
  4063. /** @type {?} */
  4064. var positionChange = changes['freeDragPosition'];
  4065. // We don't have to react to the first change since it's being
  4066. // handled in `ngAfterViewInit` where it needs to be deferred.
  4067. if (rootSelectorChange && !rootSelectorChange.firstChange) {
  4068. this._updateRootElement();
  4069. }
  4070. // Skip the first change since it's being handled in `ngAfterViewInit`.
  4071. if (positionChange && !positionChange.firstChange && this.freeDragPosition) {
  4072. this._dragRef.setFreeDragPosition(this.freeDragPosition);
  4073. }
  4074. };
  4075. /**
  4076. * @return {?}
  4077. */
  4078. CdkDrag.prototype.ngOnDestroy = /**
  4079. * @return {?}
  4080. */
  4081. function () {
  4082. this._destroyed.next();
  4083. this._destroyed.complete();
  4084. this._dragRef.dispose();
  4085. };
  4086. /** Syncs the root element with the `DragRef`. */
  4087. /**
  4088. * Syncs the root element with the `DragRef`.
  4089. * @private
  4090. * @return {?}
  4091. */
  4092. CdkDrag.prototype._updateRootElement = /**
  4093. * Syncs the root element with the `DragRef`.
  4094. * @private
  4095. * @return {?}
  4096. */
  4097. function () {
  4098. /** @type {?} */
  4099. var element = this.element.nativeElement;
  4100. /** @type {?} */
  4101. var rootElement = this.rootElementSelector ?
  4102. getClosestMatchingAncestor(element, this.rootElementSelector) : element;
  4103. if (rootElement && rootElement.nodeType !== this._document.ELEMENT_NODE) {
  4104. throw Error("cdkDrag must be attached to an element node. " +
  4105. ("Currently attached to \"" + rootElement.nodeName + "\"."));
  4106. }
  4107. this._dragRef.withRootElement(rootElement || element);
  4108. };
  4109. /** Gets the boundary element, based on the `boundaryElement` value. */
  4110. /**
  4111. * Gets the boundary element, based on the `boundaryElement` value.
  4112. * @private
  4113. * @return {?}
  4114. */
  4115. CdkDrag.prototype._getBoundaryElement = /**
  4116. * Gets the boundary element, based on the `boundaryElement` value.
  4117. * @private
  4118. * @return {?}
  4119. */
  4120. function () {
  4121. /** @type {?} */
  4122. var boundary = this.boundaryElement;
  4123. if (!boundary) {
  4124. return null;
  4125. }
  4126. if (typeof boundary === 'string') {
  4127. return getClosestMatchingAncestor(this.element.nativeElement, boundary);
  4128. }
  4129. /** @type {?} */
  4130. var element = coercion.coerceElement(boundary);
  4131. if (core.isDevMode() && !element.contains(this.element.nativeElement)) {
  4132. throw Error('Draggable element is not inside of the node passed into cdkDragBoundary.');
  4133. }
  4134. return element;
  4135. };
  4136. /** Syncs the inputs of the CdkDrag with the options of the underlying DragRef. */
  4137. /**
  4138. * Syncs the inputs of the CdkDrag with the options of the underlying DragRef.
  4139. * @private
  4140. * @param {?} ref
  4141. * @return {?}
  4142. */
  4143. CdkDrag.prototype._syncInputs = /**
  4144. * Syncs the inputs of the CdkDrag with the options of the underlying DragRef.
  4145. * @private
  4146. * @param {?} ref
  4147. * @return {?}
  4148. */
  4149. function (ref) {
  4150. var _this = this;
  4151. ref.beforeStarted.subscribe((/**
  4152. * @return {?}
  4153. */
  4154. function () {
  4155. if (!ref.isDragging()) {
  4156. /** @type {?} */
  4157. var dir = _this._dir;
  4158. /** @type {?} */
  4159. var placeholder = _this._placeholderTemplate ? {
  4160. template: _this._placeholderTemplate.templateRef,
  4161. context: _this._placeholderTemplate.data,
  4162. viewContainer: _this._viewContainerRef
  4163. } : null;
  4164. /** @type {?} */
  4165. var preview = _this._previewTemplate ? {
  4166. template: _this._previewTemplate.templateRef,
  4167. context: _this._previewTemplate.data,
  4168. viewContainer: _this._viewContainerRef
  4169. } : null;
  4170. ref.disabled = _this.disabled;
  4171. ref.lockAxis = _this.lockAxis;
  4172. ref.dragStartDelay = coercion.coerceNumberProperty(_this.dragStartDelay);
  4173. ref.constrainPosition = _this.constrainPosition;
  4174. ref
  4175. .withBoundaryElement(_this._getBoundaryElement())
  4176. .withPlaceholderTemplate(placeholder)
  4177. .withPreviewTemplate(preview);
  4178. if (dir) {
  4179. ref.withDirection(dir.value);
  4180. }
  4181. }
  4182. }));
  4183. };
  4184. /** Handles the events from the underlying `DragRef`. */
  4185. /**
  4186. * Handles the events from the underlying `DragRef`.
  4187. * @private
  4188. * @param {?} ref
  4189. * @return {?}
  4190. */
  4191. CdkDrag.prototype._handleEvents = /**
  4192. * Handles the events from the underlying `DragRef`.
  4193. * @private
  4194. * @param {?} ref
  4195. * @return {?}
  4196. */
  4197. function (ref) {
  4198. var _this = this;
  4199. ref.started.subscribe((/**
  4200. * @return {?}
  4201. */
  4202. function () {
  4203. _this.started.emit({ source: _this });
  4204. // Since all of these events run outside of change detection,
  4205. // we need to ensure that everything is marked correctly.
  4206. _this._changeDetectorRef.markForCheck();
  4207. }));
  4208. ref.released.subscribe((/**
  4209. * @return {?}
  4210. */
  4211. function () {
  4212. _this.released.emit({ source: _this });
  4213. }));
  4214. ref.ended.subscribe((/**
  4215. * @param {?} event
  4216. * @return {?}
  4217. */
  4218. function (event) {
  4219. _this.ended.emit({ source: _this, distance: event.distance });
  4220. // Since all of these events run outside of change detection,
  4221. // we need to ensure that everything is marked correctly.
  4222. _this._changeDetectorRef.markForCheck();
  4223. }));
  4224. ref.entered.subscribe((/**
  4225. * @param {?} event
  4226. * @return {?}
  4227. */
  4228. function (event) {
  4229. _this.entered.emit({
  4230. container: event.container.data,
  4231. item: _this,
  4232. currentIndex: event.currentIndex
  4233. });
  4234. }));
  4235. ref.exited.subscribe((/**
  4236. * @param {?} event
  4237. * @return {?}
  4238. */
  4239. function (event) {
  4240. _this.exited.emit({
  4241. container: event.container.data,
  4242. item: _this
  4243. });
  4244. }));
  4245. ref.dropped.subscribe((/**
  4246. * @param {?} event
  4247. * @return {?}
  4248. */
  4249. function (event) {
  4250. _this.dropped.emit({
  4251. previousIndex: event.previousIndex,
  4252. currentIndex: event.currentIndex,
  4253. previousContainer: event.previousContainer.data,
  4254. container: event.container.data,
  4255. isPointerOverContainer: event.isPointerOverContainer,
  4256. item: _this,
  4257. distance: event.distance
  4258. });
  4259. }));
  4260. };
  4261. CdkDrag.decorators = [
  4262. { type: core.Directive, args: [{
  4263. selector: '[cdkDrag]',
  4264. exportAs: 'cdkDrag',
  4265. host: {
  4266. 'class': 'cdk-drag',
  4267. '[class.cdk-drag-disabled]': 'disabled',
  4268. '[class.cdk-drag-dragging]': '_dragRef.isDragging()',
  4269. },
  4270. providers: [{ provide: CDK_DRAG_PARENT, useExisting: CdkDrag }]
  4271. },] },
  4272. ];
  4273. /** @nocollapse */
  4274. CdkDrag.ctorParameters = function () { return [
  4275. { type: core.ElementRef },
  4276. { type: undefined, decorators: [{ type: core.Inject, args: [CDK_DROP_LIST,] }, { type: core.Optional }, { type: core.SkipSelf }] },
  4277. { type: undefined, decorators: [{ type: core.Inject, args: [common.DOCUMENT,] }] },
  4278. { type: core.NgZone },
  4279. { type: core.ViewContainerRef },
  4280. { type: undefined, decorators: [{ type: core.Inject, args: [CDK_DRAG_CONFIG,] }] },
  4281. { type: bidi.Directionality, decorators: [{ type: core.Optional }] },
  4282. { type: DragDrop },
  4283. { type: core.ChangeDetectorRef }
  4284. ]; };
  4285. CdkDrag.propDecorators = {
  4286. _handles: [{ type: core.ContentChildren, args: [CdkDragHandle, { descendants: true },] }],
  4287. _previewTemplate: [{ type: core.ContentChild, args: [CdkDragPreview, { static: false },] }],
  4288. _placeholderTemplate: [{ type: core.ContentChild, args: [CdkDragPlaceholder, { static: false },] }],
  4289. data: [{ type: core.Input, args: ['cdkDragData',] }],
  4290. lockAxis: [{ type: core.Input, args: ['cdkDragLockAxis',] }],
  4291. rootElementSelector: [{ type: core.Input, args: ['cdkDragRootElement',] }],
  4292. boundaryElement: [{ type: core.Input, args: ['cdkDragBoundary',] }],
  4293. dragStartDelay: [{ type: core.Input, args: ['cdkDragStartDelay',] }],
  4294. freeDragPosition: [{ type: core.Input, args: ['cdkDragFreeDragPosition',] }],
  4295. disabled: [{ type: core.Input, args: ['cdkDragDisabled',] }],
  4296. constrainPosition: [{ type: core.Input, args: ['cdkDragConstrainPosition',] }],
  4297. started: [{ type: core.Output, args: ['cdkDragStarted',] }],
  4298. released: [{ type: core.Output, args: ['cdkDragReleased',] }],
  4299. ended: [{ type: core.Output, args: ['cdkDragEnded',] }],
  4300. entered: [{ type: core.Output, args: ['cdkDragEntered',] }],
  4301. exited: [{ type: core.Output, args: ['cdkDragExited',] }],
  4302. dropped: [{ type: core.Output, args: ['cdkDragDropped',] }],
  4303. moved: [{ type: core.Output, args: ['cdkDragMoved',] }]
  4304. };
  4305. return CdkDrag;
  4306. }());
  4307. /**
  4308. * Gets the closest ancestor of an element that matches a selector.
  4309. * @param {?} element
  4310. * @param {?} selector
  4311. * @return {?}
  4312. */
  4313. function getClosestMatchingAncestor(element, selector) {
  4314. /** @type {?} */
  4315. var currentElement = (/** @type {?} */ (element.parentElement));
  4316. while (currentElement) {
  4317. // IE doesn't support `matches` so we have to fall back to `msMatchesSelector`.
  4318. if (currentElement.matches ? currentElement.matches(selector) :
  4319. ((/** @type {?} */ (currentElement))).msMatchesSelector(selector)) {
  4320. return currentElement;
  4321. }
  4322. currentElement = currentElement.parentElement;
  4323. }
  4324. return null;
  4325. }
  4326. /**
  4327. * @fileoverview added by tsickle
  4328. * @suppress {checkTypes,extraRequire,missingOverride,missingReturn,unusedPrivateMembers,uselessCode} checked by tsc
  4329. */
  4330. /**
  4331. * Declaratively connects sibling `cdkDropList` instances together. All of the `cdkDropList`
  4332. * elements that are placed inside a `cdkDropListGroup` will be connected to each other
  4333. * automatically. Can be used as an alternative to the `cdkDropListConnectedTo` input
  4334. * from `cdkDropList`.
  4335. * @template T
  4336. */
  4337. var CdkDropListGroup = /** @class */ (function () {
  4338. function CdkDropListGroup() {
  4339. /**
  4340. * Drop lists registered inside the group.
  4341. */
  4342. this._items = new Set();
  4343. this._disabled = false;
  4344. }
  4345. Object.defineProperty(CdkDropListGroup.prototype, "disabled", {
  4346. /** Whether starting a dragging sequence from inside this group is disabled. */
  4347. get: /**
  4348. * Whether starting a dragging sequence from inside this group is disabled.
  4349. * @return {?}
  4350. */
  4351. function () { return this._disabled; },
  4352. set: /**
  4353. * @param {?} value
  4354. * @return {?}
  4355. */
  4356. function (value) {
  4357. this._disabled = coercion.coerceBooleanProperty(value);
  4358. },
  4359. enumerable: true,
  4360. configurable: true
  4361. });
  4362. /**
  4363. * @return {?}
  4364. */
  4365. CdkDropListGroup.prototype.ngOnDestroy = /**
  4366. * @return {?}
  4367. */
  4368. function () {
  4369. this._items.clear();
  4370. };
  4371. CdkDropListGroup.decorators = [
  4372. { type: core.Directive, args: [{
  4373. selector: '[cdkDropListGroup]',
  4374. exportAs: 'cdkDropListGroup',
  4375. },] },
  4376. ];
  4377. CdkDropListGroup.propDecorators = {
  4378. disabled: [{ type: core.Input, args: ['cdkDropListGroupDisabled',] }]
  4379. };
  4380. return CdkDropListGroup;
  4381. }());
  4382. /**
  4383. * @fileoverview added by tsickle
  4384. * @suppress {checkTypes,extraRequire,missingOverride,missingReturn,unusedPrivateMembers,uselessCode} checked by tsc
  4385. */
  4386. /**
  4387. * Counter used to generate unique ids for drop zones.
  4388. * @type {?}
  4389. */
  4390. var _uniqueIdCounter$1 = 0;
  4391. var ɵ0 = undefined;
  4392. // @breaking-change 8.0.0 `CdkDropList` implements `CdkDropListContainer` for backwards
  4393. // compatiblity. The implements clause, as well as all the methods that it enforces can
  4394. // be removed when `CdkDropListContainer` is deleted.
  4395. /**
  4396. * Container that wraps a set of draggable items.
  4397. * @template T
  4398. */
  4399. var CdkDropList = /** @class */ (function () {
  4400. function CdkDropList(element, dragDrop, _changeDetectorRef, _dir, _group) {
  4401. var _this = this;
  4402. this.element = element;
  4403. this._changeDetectorRef = _changeDetectorRef;
  4404. this._dir = _dir;
  4405. this._group = _group;
  4406. /**
  4407. * Emits when the list has been destroyed.
  4408. */
  4409. this._destroyed = new rxjs.Subject();
  4410. /**
  4411. * Other draggable containers that this container is connected to and into which the
  4412. * container's items can be transferred. Can either be references to other drop containers,
  4413. * or their unique IDs.
  4414. */
  4415. this.connectedTo = [];
  4416. /**
  4417. * Direction in which the list is oriented.
  4418. */
  4419. this.orientation = 'vertical';
  4420. /**
  4421. * Unique ID for the drop zone. Can be used as a reference
  4422. * in the `connectedTo` of another `CdkDropList`.
  4423. */
  4424. this.id = "cdk-drop-list-" + _uniqueIdCounter$1++;
  4425. this._disabled = false;
  4426. this._sortingDisabled = false;
  4427. /**
  4428. * Function that is used to determine whether an item
  4429. * is allowed to be moved into a drop container.
  4430. */
  4431. this.enterPredicate = (/**
  4432. * @return {?}
  4433. */
  4434. function () { return true; });
  4435. /**
  4436. * Whether to auto-scroll the view when the user moves their pointer close to the edges.
  4437. */
  4438. this.autoScrollDisabled = false;
  4439. /**
  4440. * Emits when the user drops an item inside the container.
  4441. */
  4442. this.dropped = new core.EventEmitter();
  4443. /**
  4444. * Emits when the user has moved a new drag item into this container.
  4445. */
  4446. this.entered = new core.EventEmitter();
  4447. /**
  4448. * Emits when the user removes an item from the container
  4449. * by dragging it into another container.
  4450. */
  4451. this.exited = new core.EventEmitter();
  4452. /**
  4453. * Emits as the user is swapping items while actively dragging.
  4454. */
  4455. this.sorted = new core.EventEmitter();
  4456. this._dropListRef = dragDrop.createDropList(element);
  4457. this._dropListRef.data = this;
  4458. this._dropListRef.enterPredicate = (/**
  4459. * @param {?} drag
  4460. * @param {?} drop
  4461. * @return {?}
  4462. */
  4463. function (drag, drop) {
  4464. return _this.enterPredicate(drag.data, drop.data);
  4465. });
  4466. this._syncInputs(this._dropListRef);
  4467. this._handleEvents(this._dropListRef);
  4468. CdkDropList._dropLists.push(this);
  4469. if (_group) {
  4470. _group._items.add(this);
  4471. }
  4472. }
  4473. Object.defineProperty(CdkDropList.prototype, "disabled", {
  4474. /** Whether starting a dragging sequence from this container is disabled. */
  4475. get: /**
  4476. * Whether starting a dragging sequence from this container is disabled.
  4477. * @return {?}
  4478. */
  4479. function () {
  4480. return this._disabled || (!!this._group && this._group.disabled);
  4481. },
  4482. set: /**
  4483. * @param {?} value
  4484. * @return {?}
  4485. */
  4486. function (value) {
  4487. this._disabled = coercion.coerceBooleanProperty(value);
  4488. },
  4489. enumerable: true,
  4490. configurable: true
  4491. });
  4492. Object.defineProperty(CdkDropList.prototype, "sortingDisabled", {
  4493. /** Whether sorting within this drop list is disabled. */
  4494. get: /**
  4495. * Whether sorting within this drop list is disabled.
  4496. * @return {?}
  4497. */
  4498. function () { return this._sortingDisabled; },
  4499. set: /**
  4500. * @param {?} value
  4501. * @return {?}
  4502. */
  4503. function (value) {
  4504. this._sortingDisabled = coercion.coerceBooleanProperty(value);
  4505. },
  4506. enumerable: true,
  4507. configurable: true
  4508. });
  4509. /**
  4510. * @return {?}
  4511. */
  4512. CdkDropList.prototype.ngAfterContentInit = /**
  4513. * @return {?}
  4514. */
  4515. function () {
  4516. var _this = this;
  4517. this._draggables.changes
  4518. .pipe(operators.startWith(this._draggables), operators.takeUntil(this._destroyed))
  4519. .subscribe((/**
  4520. * @param {?} items
  4521. * @return {?}
  4522. */
  4523. function (items) {
  4524. _this._dropListRef.withItems(items.map((/**
  4525. * @param {?} drag
  4526. * @return {?}
  4527. */
  4528. function (drag) { return drag._dragRef; })));
  4529. }));
  4530. };
  4531. /**
  4532. * @return {?}
  4533. */
  4534. CdkDropList.prototype.ngOnDestroy = /**
  4535. * @return {?}
  4536. */
  4537. function () {
  4538. /** @type {?} */
  4539. var index = CdkDropList._dropLists.indexOf(this);
  4540. if (index > -1) {
  4541. CdkDropList._dropLists.splice(index, 1);
  4542. }
  4543. if (this._group) {
  4544. this._group._items.delete(this);
  4545. }
  4546. this._dropListRef.dispose();
  4547. this._destroyed.next();
  4548. this._destroyed.complete();
  4549. };
  4550. /** Starts dragging an item. */
  4551. /**
  4552. * Starts dragging an item.
  4553. * @return {?}
  4554. */
  4555. CdkDropList.prototype.start = /**
  4556. * Starts dragging an item.
  4557. * @return {?}
  4558. */
  4559. function () {
  4560. this._dropListRef.start();
  4561. };
  4562. /**
  4563. * Drops an item into this container.
  4564. * @param item Item being dropped into the container.
  4565. * @param currentIndex Index at which the item should be inserted.
  4566. * @param previousContainer Container from which the item got dragged in.
  4567. * @param isPointerOverContainer Whether the user's pointer was over the
  4568. * container when the item was dropped.
  4569. */
  4570. /**
  4571. * Drops an item into this container.
  4572. * @param {?} item Item being dropped into the container.
  4573. * @param {?} currentIndex Index at which the item should be inserted.
  4574. * @param {?} previousContainer Container from which the item got dragged in.
  4575. * @param {?} isPointerOverContainer Whether the user's pointer was over the
  4576. * container when the item was dropped.
  4577. * @return {?}
  4578. */
  4579. CdkDropList.prototype.drop = /**
  4580. * Drops an item into this container.
  4581. * @param {?} item Item being dropped into the container.
  4582. * @param {?} currentIndex Index at which the item should be inserted.
  4583. * @param {?} previousContainer Container from which the item got dragged in.
  4584. * @param {?} isPointerOverContainer Whether the user's pointer was over the
  4585. * container when the item was dropped.
  4586. * @return {?}
  4587. */
  4588. function (item, currentIndex, previousContainer, isPointerOverContainer) {
  4589. this._dropListRef.drop(item._dragRef, currentIndex, ((/** @type {?} */ (previousContainer)))._dropListRef, isPointerOverContainer);
  4590. };
  4591. /**
  4592. * Emits an event to indicate that the user moved an item into the container.
  4593. * @param item Item that was moved into the container.
  4594. * @param pointerX Position of the item along the X axis.
  4595. * @param pointerY Position of the item along the Y axis.
  4596. */
  4597. /**
  4598. * Emits an event to indicate that the user moved an item into the container.
  4599. * @param {?} item Item that was moved into the container.
  4600. * @param {?} pointerX Position of the item along the X axis.
  4601. * @param {?} pointerY Position of the item along the Y axis.
  4602. * @return {?}
  4603. */
  4604. CdkDropList.prototype.enter = /**
  4605. * Emits an event to indicate that the user moved an item into the container.
  4606. * @param {?} item Item that was moved into the container.
  4607. * @param {?} pointerX Position of the item along the X axis.
  4608. * @param {?} pointerY Position of the item along the Y axis.
  4609. * @return {?}
  4610. */
  4611. function (item, pointerX, pointerY) {
  4612. this._dropListRef.enter(item._dragRef, pointerX, pointerY);
  4613. };
  4614. /**
  4615. * Removes an item from the container after it was dragged into another container by the user.
  4616. * @param item Item that was dragged out.
  4617. */
  4618. /**
  4619. * Removes an item from the container after it was dragged into another container by the user.
  4620. * @param {?} item Item that was dragged out.
  4621. * @return {?}
  4622. */
  4623. CdkDropList.prototype.exit = /**
  4624. * Removes an item from the container after it was dragged into another container by the user.
  4625. * @param {?} item Item that was dragged out.
  4626. * @return {?}
  4627. */
  4628. function (item) {
  4629. this._dropListRef.exit(item._dragRef);
  4630. };
  4631. /**
  4632. * Figures out the index of an item in the container.
  4633. * @param item Item whose index should be determined.
  4634. */
  4635. /**
  4636. * Figures out the index of an item in the container.
  4637. * @param {?} item Item whose index should be determined.
  4638. * @return {?}
  4639. */
  4640. CdkDropList.prototype.getItemIndex = /**
  4641. * Figures out the index of an item in the container.
  4642. * @param {?} item Item whose index should be determined.
  4643. * @return {?}
  4644. */
  4645. function (item) {
  4646. return this._dropListRef.getItemIndex(item._dragRef);
  4647. };
  4648. /**
  4649. * Sorts an item inside the container based on its position.
  4650. * @param item Item to be sorted.
  4651. * @param pointerX Position of the item along the X axis.
  4652. * @param pointerY Position of the item along the Y axis.
  4653. * @param pointerDelta Direction in which the pointer is moving along each axis.
  4654. */
  4655. /**
  4656. * Sorts an item inside the container based on its position.
  4657. * @param {?} item Item to be sorted.
  4658. * @param {?} pointerX Position of the item along the X axis.
  4659. * @param {?} pointerY Position of the item along the Y axis.
  4660. * @param {?} pointerDelta Direction in which the pointer is moving along each axis.
  4661. * @return {?}
  4662. */
  4663. CdkDropList.prototype._sortItem = /**
  4664. * Sorts an item inside the container based on its position.
  4665. * @param {?} item Item to be sorted.
  4666. * @param {?} pointerX Position of the item along the X axis.
  4667. * @param {?} pointerY Position of the item along the Y axis.
  4668. * @param {?} pointerDelta Direction in which the pointer is moving along each axis.
  4669. * @return {?}
  4670. */
  4671. function (item, pointerX, pointerY, pointerDelta) {
  4672. return this._dropListRef._sortItem(item._dragRef, pointerX, pointerY, pointerDelta);
  4673. };
  4674. /**
  4675. * Figures out whether an item should be moved into a sibling
  4676. * drop container, based on its current position.
  4677. * @param item Drag item that is being moved.
  4678. * @param x Position of the item along the X axis.
  4679. * @param y Position of the item along the Y axis.
  4680. */
  4681. /**
  4682. * Figures out whether an item should be moved into a sibling
  4683. * drop container, based on its current position.
  4684. * @param {?} item Drag item that is being moved.
  4685. * @param {?} x Position of the item along the X axis.
  4686. * @param {?} y Position of the item along the Y axis.
  4687. * @return {?}
  4688. */
  4689. CdkDropList.prototype._getSiblingContainerFromPosition = /**
  4690. * Figures out whether an item should be moved into a sibling
  4691. * drop container, based on its current position.
  4692. * @param {?} item Drag item that is being moved.
  4693. * @param {?} x Position of the item along the X axis.
  4694. * @param {?} y Position of the item along the Y axis.
  4695. * @return {?}
  4696. */
  4697. function (item, x, y) {
  4698. /** @type {?} */
  4699. var result = this._dropListRef._getSiblingContainerFromPosition(item._dragRef, x, y);
  4700. return result ? result.data : null;
  4701. };
  4702. /**
  4703. * Checks whether the user's pointer is positioned over the container.
  4704. * @param x Pointer position along the X axis.
  4705. * @param y Pointer position along the Y axis.
  4706. */
  4707. /**
  4708. * Checks whether the user's pointer is positioned over the container.
  4709. * @param {?} x Pointer position along the X axis.
  4710. * @param {?} y Pointer position along the Y axis.
  4711. * @return {?}
  4712. */
  4713. CdkDropList.prototype._isOverContainer = /**
  4714. * Checks whether the user's pointer is positioned over the container.
  4715. * @param {?} x Pointer position along the X axis.
  4716. * @param {?} y Pointer position along the Y axis.
  4717. * @return {?}
  4718. */
  4719. function (x, y) {
  4720. return this._dropListRef._isOverContainer(x, y);
  4721. };
  4722. /** Syncs the inputs of the CdkDropList with the options of the underlying DropListRef. */
  4723. /**
  4724. * Syncs the inputs of the CdkDropList with the options of the underlying DropListRef.
  4725. * @private
  4726. * @param {?} ref
  4727. * @return {?}
  4728. */
  4729. CdkDropList.prototype._syncInputs = /**
  4730. * Syncs the inputs of the CdkDropList with the options of the underlying DropListRef.
  4731. * @private
  4732. * @param {?} ref
  4733. * @return {?}
  4734. */
  4735. function (ref) {
  4736. var _this = this;
  4737. if (this._dir) {
  4738. this._dir.change
  4739. .pipe(operators.startWith(this._dir.value), operators.takeUntil(this._destroyed))
  4740. .subscribe((/**
  4741. * @param {?} value
  4742. * @return {?}
  4743. */
  4744. function (value) { return ref.withDirection(value); }));
  4745. }
  4746. ref.beforeStarted.subscribe((/**
  4747. * @return {?}
  4748. */
  4749. function () {
  4750. /** @type {?} */
  4751. var siblings = coercion.coerceArray(_this.connectedTo).map((/**
  4752. * @param {?} drop
  4753. * @return {?}
  4754. */
  4755. function (drop) {
  4756. return typeof drop === 'string' ?
  4757. (/** @type {?} */ (CdkDropList._dropLists.find((/**
  4758. * @param {?} list
  4759. * @return {?}
  4760. */
  4761. function (list) { return list.id === drop; })))) : drop;
  4762. }));
  4763. if (_this._group) {
  4764. _this._group._items.forEach((/**
  4765. * @param {?} drop
  4766. * @return {?}
  4767. */
  4768. function (drop) {
  4769. if (siblings.indexOf(drop) === -1) {
  4770. siblings.push(drop);
  4771. }
  4772. }));
  4773. }
  4774. ref.disabled = _this.disabled;
  4775. ref.lockAxis = _this.lockAxis;
  4776. ref.sortingDisabled = _this.sortingDisabled;
  4777. ref.autoScrollDisabled = _this.autoScrollDisabled;
  4778. ref
  4779. .connectedTo(siblings.filter((/**
  4780. * @param {?} drop
  4781. * @return {?}
  4782. */
  4783. function (drop) { return drop && drop !== _this; })).map((/**
  4784. * @param {?} list
  4785. * @return {?}
  4786. */
  4787. function (list) { return list._dropListRef; })))
  4788. .withOrientation(_this.orientation);
  4789. }));
  4790. };
  4791. /** Handles events from the underlying DropListRef. */
  4792. /**
  4793. * Handles events from the underlying DropListRef.
  4794. * @private
  4795. * @param {?} ref
  4796. * @return {?}
  4797. */
  4798. CdkDropList.prototype._handleEvents = /**
  4799. * Handles events from the underlying DropListRef.
  4800. * @private
  4801. * @param {?} ref
  4802. * @return {?}
  4803. */
  4804. function (ref) {
  4805. var _this = this;
  4806. ref.beforeStarted.subscribe((/**
  4807. * @return {?}
  4808. */
  4809. function () {
  4810. _this._changeDetectorRef.markForCheck();
  4811. }));
  4812. ref.entered.subscribe((/**
  4813. * @param {?} event
  4814. * @return {?}
  4815. */
  4816. function (event) {
  4817. _this.entered.emit({
  4818. container: _this,
  4819. item: event.item.data,
  4820. currentIndex: event.currentIndex
  4821. });
  4822. }));
  4823. ref.exited.subscribe((/**
  4824. * @param {?} event
  4825. * @return {?}
  4826. */
  4827. function (event) {
  4828. _this.exited.emit({
  4829. container: _this,
  4830. item: event.item.data
  4831. });
  4832. _this._changeDetectorRef.markForCheck();
  4833. }));
  4834. ref.sorted.subscribe((/**
  4835. * @param {?} event
  4836. * @return {?}
  4837. */
  4838. function (event) {
  4839. _this.sorted.emit({
  4840. previousIndex: event.previousIndex,
  4841. currentIndex: event.currentIndex,
  4842. container: _this,
  4843. item: event.item.data
  4844. });
  4845. }));
  4846. ref.dropped.subscribe((/**
  4847. * @param {?} event
  4848. * @return {?}
  4849. */
  4850. function (event) {
  4851. _this.dropped.emit({
  4852. previousIndex: event.previousIndex,
  4853. currentIndex: event.currentIndex,
  4854. previousContainer: event.previousContainer.data,
  4855. container: event.container.data,
  4856. item: event.item.data,
  4857. isPointerOverContainer: event.isPointerOverContainer,
  4858. distance: event.distance
  4859. });
  4860. // Mark for check since all of these events run outside of change
  4861. // detection and we're not guaranteed for something else to have triggered it.
  4862. _this._changeDetectorRef.markForCheck();
  4863. }));
  4864. };
  4865. /**
  4866. * Keeps track of the drop lists that are currently on the page.
  4867. */
  4868. CdkDropList._dropLists = [];
  4869. CdkDropList.decorators = [
  4870. { type: core.Directive, args: [{
  4871. selector: '[cdkDropList], cdk-drop-list',
  4872. exportAs: 'cdkDropList',
  4873. providers: [
  4874. // Prevent child drop lists from picking up the same group as their parent.
  4875. { provide: CdkDropListGroup, useValue: ɵ0 },
  4876. { provide: CDK_DROP_LIST_CONTAINER, useExisting: CdkDropList },
  4877. ],
  4878. host: {
  4879. 'class': 'cdk-drop-list',
  4880. '[id]': 'id',
  4881. '[class.cdk-drop-list-disabled]': 'disabled',
  4882. '[class.cdk-drop-list-dragging]': '_dropListRef.isDragging()',
  4883. '[class.cdk-drop-list-receiving]': '_dropListRef.isReceiving()',
  4884. }
  4885. },] },
  4886. ];
  4887. /** @nocollapse */
  4888. CdkDropList.ctorParameters = function () { return [
  4889. { type: core.ElementRef },
  4890. { type: DragDrop },
  4891. { type: core.ChangeDetectorRef },
  4892. { type: bidi.Directionality, decorators: [{ type: core.Optional }] },
  4893. { type: CdkDropListGroup, decorators: [{ type: core.Optional }, { type: core.SkipSelf }] }
  4894. ]; };
  4895. CdkDropList.propDecorators = {
  4896. _draggables: [{ type: core.ContentChildren, args: [core.forwardRef((/**
  4897. * @return {?}
  4898. */
  4899. function () { return CdkDrag; })), {
  4900. // Explicitly set to false since some of the logic below makes assumptions about it.
  4901. // The `.withItems` call below should be updated if we ever need to switch this to `true`.
  4902. descendants: false
  4903. },] }],
  4904. connectedTo: [{ type: core.Input, args: ['cdkDropListConnectedTo',] }],
  4905. data: [{ type: core.Input, args: ['cdkDropListData',] }],
  4906. orientation: [{ type: core.Input, args: ['cdkDropListOrientation',] }],
  4907. id: [{ type: core.Input }],
  4908. lockAxis: [{ type: core.Input, args: ['cdkDropListLockAxis',] }],
  4909. disabled: [{ type: core.Input, args: ['cdkDropListDisabled',] }],
  4910. sortingDisabled: [{ type: core.Input, args: ['cdkDropListSortingDisabled',] }],
  4911. enterPredicate: [{ type: core.Input, args: ['cdkDropListEnterPredicate',] }],
  4912. autoScrollDisabled: [{ type: core.Input, args: ['cdkDropListAutoScrollDisabled',] }],
  4913. dropped: [{ type: core.Output, args: ['cdkDropListDropped',] }],
  4914. entered: [{ type: core.Output, args: ['cdkDropListEntered',] }],
  4915. exited: [{ type: core.Output, args: ['cdkDropListExited',] }],
  4916. sorted: [{ type: core.Output, args: ['cdkDropListSorted',] }]
  4917. };
  4918. return CdkDropList;
  4919. }());
  4920. /**
  4921. * @fileoverview added by tsickle
  4922. * @suppress {checkTypes,extraRequire,missingOverride,missingReturn,unusedPrivateMembers,uselessCode} checked by tsc
  4923. */
  4924. var DragDropModule = /** @class */ (function () {
  4925. function DragDropModule() {
  4926. }
  4927. DragDropModule.decorators = [
  4928. { type: core.NgModule, args: [{
  4929. declarations: [
  4930. CdkDropList,
  4931. CdkDropListGroup,
  4932. CdkDrag,
  4933. CdkDragHandle,
  4934. CdkDragPreview,
  4935. CdkDragPlaceholder,
  4936. ],
  4937. exports: [
  4938. CdkDropList,
  4939. CdkDropListGroup,
  4940. CdkDrag,
  4941. CdkDragHandle,
  4942. CdkDragPreview,
  4943. CdkDragPlaceholder,
  4944. ],
  4945. providers: [
  4946. DragDrop,
  4947. ]
  4948. },] },
  4949. ];
  4950. return DragDropModule;
  4951. }());
  4952. exports.DragDrop = DragDrop;
  4953. exports.DragRef = DragRef;
  4954. exports.DropListRef = DropListRef;
  4955. exports.CdkDropList = CdkDropList;
  4956. exports.CDK_DROP_LIST = CDK_DROP_LIST;
  4957. exports.CDK_DROP_LIST_CONTAINER = CDK_DROP_LIST_CONTAINER;
  4958. exports.moveItemInArray = moveItemInArray;
  4959. exports.transferArrayItem = transferArrayItem;
  4960. exports.copyArrayItem = copyArrayItem;
  4961. exports.DragDropModule = DragDropModule;
  4962. exports.DragDropRegistry = DragDropRegistry;
  4963. exports.CdkDropListGroup = CdkDropListGroup;
  4964. exports.CDK_DRAG_CONFIG_FACTORY = CDK_DRAG_CONFIG_FACTORY;
  4965. exports.CDK_DRAG_CONFIG = CDK_DRAG_CONFIG;
  4966. exports.CdkDrag = CdkDrag;
  4967. exports.CdkDragHandle = CdkDragHandle;
  4968. exports.CdkDragPreview = CdkDragPreview;
  4969. exports.CdkDragPlaceholder = CdkDragPlaceholder;
  4970. exports.ɵb = CDK_DRAG_PARENT;
  4971. Object.defineProperty(exports, '__esModule', { value: true });
  4972. })));
  4973. //# sourceMappingURL=cdk-drag-drop.umd.js.map