grapes.js 2.0 MB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474475476477478479480481482483484485486487488489490491492493494495496497498499500501502503504505506507508509510511512513514515516517518519520521522523524525526527528529530531532533534535536537538539540541542543544545546547548549550551552553554555556557558559560561562563564565566567568569570571572573574575576577578579580581582583584585586587588589590591592593594595596597598599600601602603604605606607608609610611612613614615616617618619620621622623624625626627628629630631632633634635636637638639640641642643644645646647648649650651652653654655656657658659660661662663664665666667668669670671672673674675676677678679680681682683684685686687688689690691692693694695696697698699700701702703704705706707708709710711712713714715716717718719720721722723724725726727728729730731732733734735736737738739740741742743744745746747748749750751752753754755756757758759760761762763764765766767768769770771772773774775776777778779780781782783784785786787788789790791792793794795796797798799800801802803804805806807808809810811812813814815816817818819820821822823824825826827828829830831832833834835836837838839840841842843844845846847848849850851852853854855856857858859860861862863864865866867868869870871872873874875876877878879880881882883884885886887888889890891892893894895896897898899900901902903904905906907908909910911912913914915916917918919920921922923924925926927928929930931932933934935936937938939940941942943944945946947948949950951952953954955956957958959960961962963964965966967968969970971972973974975976977978979980981982983984985986987988989990991992993994995996997998999100010011002100310041005100610071008100910101011101210131014101510161017101810191020102110221023102410251026102710281029103010311032103310341035103610371038103910401041104210431044104510461047104810491050105110521053105410551056105710581059106010611062106310641065106610671068106910701071107210731074107510761077107810791080108110821083108410851086108710881089109010911092109310941095109610971098109911001101110211031104110511061107110811091110111111121113111411151116111711181119112011211122112311241125112611271128112911301131113211331134113511361137113811391140114111421143114411451146114711481149115011511152115311541155115611571158115911601161116211631164116511661167116811691170117111721173117411751176117711781179118011811182118311841185118611871188118911901191119211931194119511961197119811991200120112021203120412051206120712081209121012111212121312141215121612171218121912201221122212231224122512261227122812291230123112321233123412351236123712381239124012411242124312441245124612471248124912501251125212531254125512561257125812591260126112621263126412651266126712681269127012711272127312741275127612771278127912801281128212831284128512861287128812891290129112921293129412951296129712981299130013011302130313041305130613071308130913101311131213131314131513161317131813191320132113221323132413251326132713281329133013311332133313341335133613371338133913401341134213431344134513461347134813491350135113521353135413551356135713581359136013611362136313641365136613671368136913701371137213731374137513761377137813791380138113821383138413851386138713881389139013911392139313941395139613971398139914001401140214031404140514061407140814091410141114121413141414151416141714181419142014211422142314241425142614271428142914301431143214331434143514361437143814391440144114421443144414451446144714481449145014511452145314541455145614571458145914601461146214631464146514661467146814691470147114721473147414751476147714781479148014811482148314841485148614871488148914901491149214931494149514961497149814991500150115021503150415051506150715081509151015111512151315141515151615171518151915201521152215231524152515261527152815291530153115321533153415351536153715381539154015411542154315441545154615471548154915501551155215531554155515561557155815591560156115621563156415651566156715681569157015711572157315741575157615771578157915801581158215831584158515861587158815891590159115921593159415951596159715981599160016011602160316041605160616071608160916101611161216131614161516161617161816191620162116221623162416251626162716281629163016311632163316341635163616371638163916401641164216431644164516461647164816491650165116521653165416551656165716581659166016611662166316641665166616671668166916701671167216731674167516761677167816791680168116821683168416851686168716881689169016911692169316941695169616971698169917001701170217031704170517061707170817091710171117121713171417151716171717181719172017211722172317241725172617271728172917301731173217331734173517361737173817391740174117421743174417451746174717481749175017511752175317541755175617571758175917601761176217631764176517661767176817691770177117721773177417751776177717781779178017811782178317841785178617871788178917901791179217931794179517961797179817991800180118021803180418051806180718081809181018111812181318141815181618171818181918201821182218231824182518261827182818291830183118321833183418351836183718381839184018411842184318441845184618471848184918501851185218531854185518561857185818591860186118621863186418651866186718681869187018711872187318741875187618771878187918801881188218831884188518861887188818891890189118921893189418951896189718981899190019011902190319041905190619071908190919101911191219131914191519161917191819191920192119221923192419251926192719281929193019311932193319341935193619371938193919401941194219431944194519461947194819491950195119521953195419551956195719581959196019611962196319641965196619671968196919701971197219731974197519761977197819791980198119821983198419851986198719881989199019911992199319941995199619971998199920002001200220032004200520062007200820092010201120122013201420152016201720182019202020212022202320242025202620272028202920302031203220332034203520362037203820392040204120422043204420452046204720482049205020512052205320542055205620572058205920602061206220632064206520662067206820692070207120722073207420752076207720782079208020812082208320842085208620872088208920902091209220932094209520962097209820992100210121022103210421052106210721082109211021112112211321142115211621172118211921202121212221232124212521262127212821292130213121322133213421352136213721382139214021412142214321442145214621472148214921502151215221532154215521562157215821592160216121622163216421652166216721682169217021712172217321742175217621772178217921802181218221832184218521862187218821892190219121922193219421952196219721982199220022012202220322042205220622072208220922102211221222132214221522162217221822192220222122222223222422252226222722282229223022312232223322342235223622372238223922402241224222432244224522462247224822492250225122522253225422552256225722582259226022612262226322642265226622672268226922702271227222732274227522762277227822792280228122822283228422852286228722882289229022912292229322942295229622972298229923002301230223032304230523062307230823092310231123122313231423152316231723182319232023212322232323242325232623272328232923302331233223332334233523362337233823392340234123422343234423452346234723482349235023512352235323542355235623572358235923602361236223632364236523662367236823692370237123722373237423752376237723782379238023812382238323842385238623872388238923902391239223932394239523962397239823992400240124022403240424052406240724082409241024112412241324142415241624172418241924202421242224232424242524262427242824292430243124322433243424352436243724382439244024412442244324442445244624472448244924502451245224532454245524562457245824592460246124622463246424652466246724682469247024712472247324742475247624772478247924802481248224832484248524862487248824892490249124922493249424952496249724982499250025012502250325042505250625072508250925102511251225132514251525162517251825192520252125222523252425252526252725282529253025312532253325342535253625372538253925402541254225432544254525462547254825492550255125522553255425552556255725582559256025612562256325642565256625672568256925702571257225732574257525762577257825792580258125822583258425852586258725882589259025912592259325942595259625972598259926002601260226032604260526062607260826092610261126122613261426152616261726182619262026212622262326242625262626272628262926302631263226332634263526362637263826392640264126422643264426452646264726482649265026512652265326542655265626572658265926602661266226632664266526662667266826692670267126722673267426752676267726782679268026812682268326842685268626872688268926902691269226932694269526962697269826992700270127022703270427052706270727082709271027112712271327142715271627172718271927202721272227232724272527262727272827292730273127322733273427352736273727382739274027412742274327442745274627472748274927502751275227532754275527562757275827592760276127622763276427652766276727682769277027712772277327742775277627772778277927802781278227832784278527862787278827892790279127922793279427952796279727982799280028012802280328042805280628072808280928102811281228132814281528162817281828192820282128222823282428252826282728282829283028312832283328342835283628372838283928402841284228432844284528462847284828492850285128522853285428552856285728582859286028612862286328642865286628672868286928702871287228732874287528762877287828792880288128822883288428852886288728882889289028912892289328942895289628972898289929002901290229032904290529062907290829092910291129122913291429152916291729182919292029212922292329242925292629272928292929302931293229332934293529362937293829392940294129422943294429452946294729482949295029512952295329542955295629572958295929602961296229632964296529662967296829692970297129722973297429752976297729782979298029812982298329842985298629872988298929902991299229932994299529962997299829993000300130023003300430053006300730083009301030113012301330143015301630173018301930203021302230233024302530263027302830293030303130323033303430353036303730383039304030413042304330443045304630473048304930503051305230533054305530563057305830593060306130623063306430653066306730683069307030713072307330743075307630773078307930803081308230833084308530863087308830893090309130923093309430953096309730983099310031013102310331043105310631073108310931103111311231133114311531163117311831193120312131223123312431253126312731283129313031313132313331343135313631373138313931403141314231433144314531463147314831493150315131523153315431553156315731583159316031613162316331643165316631673168316931703171317231733174317531763177317831793180318131823183318431853186318731883189319031913192319331943195319631973198319932003201320232033204320532063207320832093210321132123213321432153216321732183219322032213222322332243225322632273228322932303231323232333234323532363237323832393240324132423243324432453246324732483249325032513252325332543255325632573258325932603261326232633264326532663267326832693270327132723273327432753276327732783279328032813282328332843285328632873288328932903291329232933294329532963297329832993300330133023303330433053306330733083309331033113312331333143315331633173318331933203321332233233324332533263327332833293330333133323333333433353336333733383339334033413342334333443345334633473348334933503351335233533354335533563357335833593360336133623363336433653366336733683369337033713372337333743375337633773378337933803381338233833384338533863387338833893390339133923393339433953396339733983399340034013402340334043405340634073408340934103411341234133414341534163417341834193420342134223423342434253426342734283429343034313432343334343435343634373438343934403441344234433444344534463447344834493450345134523453345434553456345734583459346034613462346334643465346634673468346934703471347234733474347534763477347834793480348134823483348434853486348734883489349034913492349334943495349634973498349935003501350235033504350535063507350835093510351135123513351435153516351735183519352035213522352335243525352635273528352935303531353235333534353535363537353835393540354135423543354435453546354735483549355035513552355335543555355635573558355935603561356235633564356535663567356835693570357135723573357435753576357735783579358035813582358335843585358635873588358935903591359235933594359535963597359835993600360136023603360436053606360736083609361036113612361336143615361636173618361936203621362236233624362536263627362836293630363136323633363436353636363736383639364036413642364336443645364636473648364936503651365236533654365536563657365836593660366136623663366436653666366736683669367036713672367336743675367636773678367936803681368236833684368536863687368836893690369136923693369436953696369736983699370037013702370337043705370637073708370937103711371237133714371537163717371837193720372137223723372437253726372737283729373037313732373337343735373637373738373937403741374237433744374537463747374837493750375137523753375437553756375737583759376037613762376337643765376637673768376937703771377237733774377537763777377837793780378137823783378437853786378737883789379037913792379337943795379637973798379938003801380238033804380538063807380838093810381138123813381438153816381738183819382038213822382338243825382638273828382938303831383238333834383538363837383838393840384138423843384438453846384738483849385038513852385338543855385638573858385938603861386238633864386538663867386838693870387138723873387438753876387738783879388038813882388338843885388638873888388938903891389238933894389538963897389838993900390139023903390439053906390739083909391039113912391339143915391639173918391939203921392239233924392539263927392839293930393139323933393439353936393739383939394039413942394339443945394639473948394939503951395239533954395539563957395839593960396139623963396439653966396739683969397039713972397339743975397639773978397939803981398239833984398539863987398839893990399139923993399439953996399739983999400040014002400340044005400640074008400940104011401240134014401540164017401840194020402140224023402440254026402740284029403040314032403340344035403640374038403940404041404240434044404540464047404840494050405140524053405440554056405740584059406040614062406340644065406640674068406940704071407240734074407540764077407840794080408140824083408440854086408740884089409040914092409340944095409640974098409941004101410241034104410541064107410841094110411141124113411441154116411741184119412041214122412341244125412641274128412941304131413241334134413541364137413841394140414141424143414441454146414741484149415041514152415341544155415641574158415941604161416241634164416541664167416841694170417141724173417441754176417741784179418041814182418341844185418641874188418941904191419241934194419541964197419841994200420142024203420442054206420742084209421042114212421342144215421642174218421942204221422242234224422542264227422842294230423142324233423442354236423742384239424042414242424342444245424642474248424942504251425242534254425542564257425842594260426142624263426442654266426742684269427042714272427342744275427642774278427942804281428242834284428542864287428842894290429142924293429442954296429742984299430043014302430343044305430643074308430943104311431243134314431543164317431843194320432143224323432443254326432743284329433043314332433343344335433643374338433943404341434243434344434543464347434843494350435143524353435443554356435743584359436043614362436343644365436643674368436943704371437243734374437543764377437843794380438143824383438443854386438743884389439043914392439343944395439643974398439944004401440244034404440544064407440844094410441144124413441444154416441744184419442044214422442344244425442644274428442944304431443244334434443544364437443844394440444144424443444444454446444744484449445044514452445344544455445644574458445944604461446244634464446544664467446844694470447144724473447444754476447744784479448044814482448344844485448644874488448944904491449244934494449544964497449844994500450145024503450445054506450745084509451045114512451345144515451645174518451945204521452245234524452545264527452845294530453145324533453445354536453745384539454045414542454345444545454645474548454945504551455245534554455545564557455845594560456145624563456445654566456745684569457045714572457345744575457645774578457945804581458245834584458545864587458845894590459145924593459445954596459745984599460046014602460346044605460646074608460946104611461246134614461546164617461846194620462146224623462446254626462746284629463046314632463346344635463646374638463946404641464246434644464546464647464846494650465146524653465446554656465746584659466046614662466346644665466646674668466946704671467246734674467546764677467846794680468146824683468446854686468746884689469046914692469346944695469646974698469947004701470247034704470547064707470847094710471147124713471447154716471747184719472047214722472347244725472647274728472947304731473247334734473547364737473847394740474147424743474447454746474747484749475047514752475347544755475647574758475947604761476247634764476547664767476847694770477147724773477447754776477747784779478047814782478347844785478647874788478947904791479247934794479547964797479847994800480148024803480448054806480748084809481048114812481348144815481648174818481948204821482248234824482548264827482848294830483148324833483448354836483748384839484048414842484348444845484648474848484948504851485248534854485548564857485848594860486148624863486448654866486748684869487048714872487348744875487648774878487948804881488248834884488548864887488848894890489148924893489448954896489748984899490049014902490349044905490649074908490949104911491249134914491549164917491849194920492149224923492449254926492749284929493049314932493349344935493649374938493949404941494249434944494549464947494849494950495149524953495449554956495749584959496049614962496349644965496649674968496949704971497249734974497549764977497849794980498149824983498449854986498749884989499049914992499349944995499649974998499950005001500250035004500550065007500850095010501150125013501450155016501750185019502050215022502350245025502650275028502950305031503250335034503550365037503850395040504150425043504450455046504750485049505050515052505350545055505650575058505950605061506250635064506550665067506850695070507150725073507450755076507750785079508050815082508350845085508650875088508950905091509250935094509550965097509850995100510151025103510451055106510751085109511051115112511351145115511651175118511951205121512251235124512551265127512851295130513151325133513451355136513751385139514051415142514351445145514651475148514951505151515251535154515551565157515851595160516151625163516451655166516751685169517051715172517351745175517651775178517951805181518251835184518551865187518851895190519151925193519451955196519751985199520052015202520352045205520652075208520952105211521252135214521552165217521852195220522152225223522452255226522752285229523052315232523352345235523652375238523952405241524252435244524552465247524852495250525152525253525452555256525752585259526052615262526352645265526652675268526952705271527252735274527552765277527852795280528152825283528452855286528752885289529052915292529352945295529652975298529953005301530253035304530553065307530853095310531153125313531453155316531753185319532053215322532353245325532653275328532953305331533253335334533553365337533853395340534153425343534453455346534753485349535053515352535353545355535653575358535953605361536253635364536553665367536853695370537153725373537453755376537753785379538053815382538353845385538653875388538953905391539253935394539553965397539853995400540154025403540454055406540754085409541054115412541354145415541654175418541954205421542254235424542554265427542854295430543154325433543454355436543754385439544054415442544354445445544654475448544954505451545254535454545554565457545854595460546154625463546454655466546754685469547054715472547354745475547654775478547954805481548254835484548554865487548854895490549154925493549454955496549754985499550055015502550355045505550655075508550955105511551255135514551555165517551855195520552155225523552455255526552755285529553055315532553355345535553655375538553955405541554255435544554555465547554855495550555155525553555455555556555755585559556055615562556355645565556655675568556955705571557255735574557555765577557855795580558155825583558455855586558755885589559055915592559355945595559655975598559956005601560256035604560556065607560856095610561156125613561456155616561756185619562056215622562356245625562656275628562956305631563256335634563556365637563856395640564156425643564456455646564756485649565056515652565356545655565656575658565956605661566256635664566556665667566856695670567156725673567456755676567756785679568056815682568356845685568656875688568956905691569256935694569556965697569856995700570157025703570457055706570757085709571057115712571357145715571657175718571957205721572257235724572557265727572857295730573157325733573457355736573757385739574057415742574357445745574657475748574957505751575257535754575557565757575857595760576157625763576457655766576757685769577057715772577357745775577657775778577957805781578257835784578557865787578857895790579157925793579457955796579757985799580058015802580358045805580658075808580958105811581258135814581558165817581858195820582158225823582458255826582758285829583058315832583358345835583658375838583958405841584258435844584558465847584858495850585158525853585458555856585758585859586058615862586358645865586658675868586958705871587258735874587558765877587858795880588158825883588458855886588758885889589058915892589358945895589658975898589959005901590259035904590559065907590859095910591159125913591459155916591759185919592059215922592359245925592659275928592959305931593259335934593559365937593859395940594159425943594459455946594759485949595059515952595359545955595659575958595959605961596259635964596559665967596859695970597159725973597459755976597759785979598059815982598359845985598659875988598959905991599259935994599559965997599859996000600160026003600460056006600760086009601060116012601360146015601660176018601960206021602260236024602560266027602860296030603160326033603460356036603760386039604060416042604360446045604660476048604960506051605260536054605560566057605860596060606160626063606460656066606760686069607060716072607360746075607660776078607960806081608260836084608560866087608860896090609160926093609460956096609760986099610061016102610361046105610661076108610961106111611261136114611561166117611861196120612161226123612461256126612761286129613061316132613361346135613661376138613961406141614261436144614561466147614861496150615161526153615461556156615761586159616061616162616361646165616661676168616961706171617261736174617561766177617861796180618161826183618461856186618761886189619061916192619361946195619661976198619962006201620262036204620562066207620862096210621162126213621462156216621762186219622062216222622362246225622662276228622962306231623262336234623562366237623862396240624162426243624462456246624762486249625062516252625362546255625662576258625962606261626262636264626562666267626862696270627162726273627462756276627762786279628062816282628362846285628662876288628962906291629262936294629562966297629862996300630163026303630463056306630763086309631063116312631363146315631663176318631963206321632263236324632563266327632863296330633163326333633463356336633763386339634063416342634363446345634663476348634963506351635263536354635563566357635863596360636163626363636463656366636763686369637063716372637363746375637663776378637963806381638263836384638563866387638863896390639163926393639463956396639763986399640064016402640364046405640664076408640964106411641264136414641564166417641864196420642164226423642464256426642764286429643064316432643364346435643664376438643964406441644264436444644564466447644864496450645164526453645464556456645764586459646064616462646364646465646664676468646964706471647264736474647564766477647864796480648164826483648464856486648764886489649064916492649364946495649664976498649965006501650265036504650565066507650865096510651165126513651465156516651765186519652065216522652365246525652665276528652965306531653265336534653565366537653865396540654165426543654465456546654765486549655065516552655365546555655665576558655965606561656265636564656565666567656865696570657165726573657465756576657765786579658065816582658365846585658665876588658965906591659265936594659565966597659865996600660166026603660466056606660766086609661066116612661366146615661666176618661966206621662266236624662566266627662866296630663166326633663466356636663766386639664066416642664366446645664666476648664966506651665266536654665566566657665866596660666166626663666466656666666766686669667066716672667366746675667666776678667966806681668266836684668566866687668866896690669166926693669466956696669766986699670067016702670367046705670667076708670967106711671267136714671567166717671867196720672167226723672467256726672767286729673067316732673367346735673667376738673967406741674267436744674567466747674867496750675167526753675467556756675767586759676067616762676367646765676667676768676967706771677267736774677567766777677867796780678167826783678467856786678767886789679067916792679367946795679667976798679968006801680268036804680568066807680868096810681168126813681468156816681768186819682068216822682368246825682668276828682968306831683268336834683568366837683868396840684168426843684468456846684768486849685068516852685368546855685668576858685968606861686268636864686568666867686868696870687168726873687468756876687768786879688068816882688368846885688668876888688968906891689268936894689568966897689868996900690169026903690469056906690769086909691069116912691369146915691669176918691969206921692269236924692569266927692869296930693169326933693469356936693769386939694069416942694369446945694669476948694969506951695269536954695569566957695869596960696169626963696469656966696769686969697069716972697369746975697669776978697969806981698269836984698569866987698869896990699169926993699469956996699769986999700070017002700370047005700670077008700970107011701270137014701570167017701870197020702170227023702470257026702770287029703070317032703370347035703670377038703970407041704270437044704570467047704870497050705170527053705470557056705770587059706070617062706370647065706670677068706970707071707270737074707570767077707870797080708170827083708470857086708770887089709070917092709370947095709670977098709971007101710271037104710571067107710871097110711171127113711471157116711771187119712071217122712371247125712671277128712971307131713271337134713571367137713871397140714171427143714471457146714771487149715071517152715371547155715671577158715971607161716271637164716571667167716871697170717171727173717471757176717771787179718071817182718371847185718671877188718971907191719271937194719571967197719871997200720172027203720472057206720772087209721072117212721372147215721672177218721972207221722272237224722572267227722872297230723172327233723472357236723772387239724072417242724372447245724672477248724972507251725272537254725572567257725872597260726172627263726472657266726772687269727072717272727372747275727672777278727972807281728272837284728572867287728872897290729172927293729472957296729772987299730073017302730373047305730673077308730973107311731273137314731573167317731873197320732173227323732473257326732773287329733073317332733373347335733673377338733973407341734273437344734573467347734873497350735173527353735473557356735773587359736073617362736373647365736673677368736973707371737273737374737573767377737873797380738173827383738473857386738773887389739073917392739373947395739673977398739974007401740274037404740574067407740874097410741174127413741474157416741774187419742074217422742374247425742674277428742974307431743274337434743574367437743874397440744174427443744474457446744774487449745074517452745374547455745674577458745974607461746274637464746574667467746874697470747174727473747474757476747774787479748074817482748374847485748674877488748974907491749274937494749574967497749874997500750175027503750475057506750775087509751075117512751375147515751675177518751975207521752275237524752575267527752875297530753175327533753475357536753775387539754075417542754375447545754675477548754975507551755275537554755575567557755875597560756175627563756475657566756775687569757075717572757375747575757675777578757975807581758275837584758575867587758875897590759175927593759475957596759775987599760076017602760376047605760676077608760976107611761276137614761576167617761876197620762176227623762476257626762776287629763076317632763376347635763676377638763976407641764276437644764576467647764876497650765176527653765476557656765776587659766076617662766376647665766676677668766976707671767276737674767576767677767876797680768176827683768476857686768776887689769076917692769376947695769676977698769977007701770277037704770577067707770877097710771177127713771477157716771777187719772077217722772377247725772677277728772977307731773277337734773577367737773877397740774177427743774477457746774777487749775077517752775377547755775677577758775977607761776277637764776577667767776877697770777177727773777477757776777777787779778077817782778377847785778677877788778977907791779277937794779577967797779877997800780178027803780478057806780778087809781078117812781378147815781678177818781978207821782278237824782578267827782878297830783178327833783478357836783778387839784078417842784378447845784678477848784978507851785278537854785578567857785878597860786178627863786478657866786778687869787078717872787378747875787678777878787978807881788278837884788578867887788878897890789178927893789478957896789778987899790079017902790379047905790679077908790979107911791279137914791579167917791879197920792179227923792479257926792779287929793079317932793379347935793679377938793979407941794279437944794579467947794879497950795179527953795479557956795779587959796079617962796379647965796679677968796979707971797279737974797579767977797879797980798179827983798479857986798779887989799079917992799379947995799679977998799980008001800280038004800580068007800880098010801180128013801480158016801780188019802080218022802380248025802680278028802980308031803280338034803580368037803880398040804180428043804480458046804780488049805080518052805380548055805680578058805980608061806280638064806580668067806880698070807180728073807480758076807780788079808080818082808380848085808680878088808980908091809280938094809580968097809880998100810181028103810481058106810781088109811081118112811381148115811681178118811981208121812281238124812581268127812881298130813181328133813481358136813781388139814081418142814381448145814681478148814981508151815281538154815581568157815881598160816181628163816481658166816781688169817081718172817381748175817681778178817981808181818281838184818581868187818881898190819181928193819481958196819781988199820082018202820382048205820682078208820982108211821282138214821582168217821882198220822182228223822482258226822782288229823082318232823382348235823682378238823982408241824282438244824582468247824882498250825182528253825482558256825782588259826082618262826382648265826682678268826982708271827282738274827582768277827882798280828182828283828482858286828782888289829082918292829382948295829682978298829983008301830283038304830583068307830883098310831183128313831483158316831783188319832083218322832383248325832683278328832983308331833283338334833583368337833883398340834183428343834483458346834783488349835083518352835383548355835683578358835983608361836283638364836583668367836883698370837183728373837483758376837783788379838083818382838383848385838683878388838983908391839283938394839583968397839883998400840184028403840484058406840784088409841084118412841384148415841684178418841984208421842284238424842584268427842884298430843184328433843484358436843784388439844084418442844384448445844684478448844984508451845284538454845584568457845884598460846184628463846484658466846784688469847084718472847384748475847684778478847984808481848284838484848584868487848884898490849184928493849484958496849784988499850085018502850385048505850685078508850985108511851285138514851585168517851885198520852185228523852485258526852785288529853085318532853385348535853685378538853985408541854285438544854585468547854885498550855185528553855485558556855785588559856085618562856385648565856685678568856985708571857285738574857585768577857885798580858185828583858485858586858785888589859085918592859385948595859685978598859986008601860286038604860586068607860886098610861186128613861486158616861786188619862086218622862386248625862686278628862986308631863286338634863586368637863886398640864186428643864486458646864786488649865086518652865386548655865686578658865986608661866286638664866586668667866886698670867186728673867486758676867786788679868086818682868386848685868686878688868986908691869286938694869586968697869886998700870187028703870487058706870787088709871087118712871387148715871687178718871987208721872287238724872587268727872887298730873187328733873487358736873787388739874087418742874387448745874687478748874987508751875287538754875587568757875887598760876187628763876487658766876787688769877087718772877387748775877687778778877987808781878287838784878587868787878887898790879187928793879487958796879787988799880088018802880388048805880688078808880988108811881288138814881588168817881888198820882188228823882488258826882788288829883088318832883388348835883688378838883988408841884288438844884588468847884888498850885188528853885488558856885788588859886088618862886388648865886688678868886988708871887288738874887588768877887888798880888188828883888488858886888788888889889088918892889388948895889688978898889989008901890289038904890589068907890889098910891189128913891489158916891789188919892089218922892389248925892689278928892989308931893289338934893589368937893889398940894189428943894489458946894789488949895089518952895389548955895689578958895989608961896289638964896589668967896889698970897189728973897489758976897789788979898089818982898389848985898689878988898989908991899289938994899589968997899889999000900190029003900490059006900790089009901090119012901390149015901690179018901990209021902290239024902590269027902890299030903190329033903490359036903790389039904090419042904390449045904690479048904990509051905290539054905590569057905890599060906190629063906490659066906790689069907090719072907390749075907690779078907990809081908290839084908590869087908890899090909190929093909490959096909790989099910091019102910391049105910691079108910991109111911291139114911591169117911891199120912191229123912491259126912791289129913091319132913391349135913691379138913991409141914291439144914591469147914891499150915191529153915491559156915791589159916091619162916391649165916691679168916991709171917291739174917591769177917891799180918191829183918491859186918791889189919091919192919391949195919691979198919992009201920292039204920592069207920892099210921192129213921492159216921792189219922092219222922392249225922692279228922992309231923292339234923592369237923892399240924192429243924492459246924792489249925092519252925392549255925692579258925992609261926292639264926592669267926892699270927192729273927492759276927792789279928092819282928392849285928692879288928992909291929292939294929592969297929892999300930193029303930493059306930793089309931093119312931393149315931693179318931993209321932293239324932593269327932893299330933193329333933493359336933793389339934093419342934393449345934693479348934993509351935293539354935593569357935893599360936193629363936493659366936793689369937093719372937393749375937693779378937993809381938293839384938593869387938893899390939193929393939493959396939793989399940094019402940394049405940694079408940994109411941294139414941594169417941894199420942194229423942494259426942794289429943094319432943394349435943694379438943994409441944294439444944594469447944894499450945194529453945494559456945794589459946094619462946394649465946694679468946994709471947294739474947594769477947894799480948194829483948494859486948794889489949094919492949394949495949694979498949995009501950295039504950595069507950895099510951195129513951495159516951795189519952095219522952395249525952695279528952995309531953295339534953595369537953895399540954195429543954495459546954795489549955095519552955395549555955695579558955995609561956295639564956595669567956895699570957195729573957495759576957795789579958095819582958395849585958695879588958995909591959295939594959595969597959895999600960196029603960496059606960796089609961096119612961396149615961696179618961996209621962296239624962596269627962896299630963196329633963496359636963796389639964096419642964396449645964696479648964996509651965296539654965596569657965896599660966196629663966496659666966796689669967096719672967396749675967696779678967996809681968296839684968596869687968896899690969196929693969496959696969796989699970097019702970397049705970697079708970997109711971297139714971597169717971897199720972197229723972497259726972797289729973097319732973397349735973697379738973997409741974297439744974597469747974897499750975197529753975497559756975797589759976097619762976397649765976697679768976997709771977297739774977597769777977897799780978197829783978497859786978797889789979097919792979397949795979697979798979998009801980298039804980598069807980898099810981198129813981498159816981798189819982098219822982398249825982698279828982998309831983298339834983598369837983898399840984198429843984498459846984798489849985098519852985398549855985698579858985998609861986298639864986598669867986898699870987198729873987498759876987798789879988098819882988398849885988698879888988998909891989298939894989598969897989898999900990199029903990499059906990799089909991099119912991399149915991699179918991999209921992299239924992599269927992899299930993199329933993499359936993799389939994099419942994399449945994699479948994999509951995299539954995599569957995899599960996199629963996499659966996799689969997099719972997399749975997699779978997999809981998299839984998599869987998899899990999199929993999499959996999799989999100001000110002100031000410005100061000710008100091001010011100121001310014100151001610017100181001910020100211002210023100241002510026100271002810029100301003110032100331003410035100361003710038100391004010041100421004310044100451004610047100481004910050100511005210053100541005510056100571005810059100601006110062100631006410065100661006710068100691007010071100721007310074100751007610077100781007910080100811008210083100841008510086100871008810089100901009110092100931009410095100961009710098100991010010101101021010310104101051010610107101081010910110101111011210113101141011510116101171011810119101201012110122101231012410125101261012710128101291013010131101321013310134101351013610137101381013910140101411014210143101441014510146101471014810149101501015110152101531015410155101561015710158101591016010161101621016310164101651016610167101681016910170101711017210173101741017510176101771017810179101801018110182101831018410185101861018710188101891019010191101921019310194101951019610197101981019910200102011020210203102041020510206102071020810209102101021110212102131021410215102161021710218102191022010221102221022310224102251022610227102281022910230102311023210233102341023510236102371023810239102401024110242102431024410245102461024710248102491025010251102521025310254102551025610257102581025910260102611026210263102641026510266102671026810269102701027110272102731027410275102761027710278102791028010281102821028310284102851028610287102881028910290102911029210293102941029510296102971029810299103001030110302103031030410305103061030710308103091031010311103121031310314103151031610317103181031910320103211032210323103241032510326103271032810329103301033110332103331033410335103361033710338103391034010341103421034310344103451034610347103481034910350103511035210353103541035510356103571035810359103601036110362103631036410365103661036710368103691037010371103721037310374103751037610377103781037910380103811038210383103841038510386103871038810389103901039110392103931039410395103961039710398103991040010401104021040310404104051040610407104081040910410104111041210413104141041510416104171041810419104201042110422104231042410425104261042710428104291043010431104321043310434104351043610437104381043910440104411044210443104441044510446104471044810449104501045110452104531045410455104561045710458104591046010461104621046310464104651046610467104681046910470104711047210473104741047510476104771047810479104801048110482104831048410485104861048710488104891049010491104921049310494104951049610497104981049910500105011050210503105041050510506105071050810509105101051110512105131051410515105161051710518105191052010521105221052310524105251052610527105281052910530105311053210533105341053510536105371053810539105401054110542105431054410545105461054710548105491055010551105521055310554105551055610557105581055910560105611056210563105641056510566105671056810569105701057110572105731057410575105761057710578105791058010581105821058310584105851058610587105881058910590105911059210593105941059510596105971059810599106001060110602106031060410605106061060710608106091061010611106121061310614106151061610617106181061910620106211062210623106241062510626106271062810629106301063110632106331063410635106361063710638106391064010641106421064310644106451064610647106481064910650106511065210653106541065510656106571065810659106601066110662106631066410665106661066710668106691067010671106721067310674106751067610677106781067910680106811068210683106841068510686106871068810689106901069110692106931069410695106961069710698106991070010701107021070310704107051070610707107081070910710107111071210713107141071510716107171071810719107201072110722107231072410725107261072710728107291073010731107321073310734107351073610737107381073910740107411074210743107441074510746107471074810749107501075110752107531075410755107561075710758107591076010761107621076310764107651076610767107681076910770107711077210773107741077510776107771077810779107801078110782107831078410785107861078710788107891079010791107921079310794107951079610797107981079910800108011080210803108041080510806108071080810809108101081110812108131081410815108161081710818108191082010821108221082310824108251082610827108281082910830108311083210833108341083510836108371083810839108401084110842108431084410845108461084710848108491085010851108521085310854108551085610857108581085910860108611086210863108641086510866108671086810869108701087110872108731087410875108761087710878108791088010881108821088310884108851088610887108881088910890108911089210893108941089510896108971089810899109001090110902109031090410905109061090710908109091091010911109121091310914109151091610917109181091910920109211092210923109241092510926109271092810929109301093110932109331093410935109361093710938109391094010941109421094310944109451094610947109481094910950109511095210953109541095510956109571095810959109601096110962109631096410965109661096710968109691097010971109721097310974109751097610977109781097910980109811098210983109841098510986109871098810989109901099110992109931099410995109961099710998109991100011001110021100311004110051100611007110081100911010110111101211013110141101511016110171101811019110201102111022110231102411025110261102711028110291103011031110321103311034110351103611037110381103911040110411104211043110441104511046110471104811049110501105111052110531105411055110561105711058110591106011061110621106311064110651106611067110681106911070110711107211073110741107511076110771107811079110801108111082110831108411085110861108711088110891109011091110921109311094110951109611097110981109911100111011110211103111041110511106111071110811109111101111111112111131111411115111161111711118111191112011121111221112311124111251112611127111281112911130111311113211133111341113511136111371113811139111401114111142111431114411145111461114711148111491115011151111521115311154111551115611157111581115911160111611116211163111641116511166111671116811169111701117111172111731117411175111761117711178111791118011181111821118311184111851118611187111881118911190111911119211193111941119511196111971119811199112001120111202112031120411205112061120711208112091121011211112121121311214112151121611217112181121911220112211122211223112241122511226112271122811229112301123111232112331123411235112361123711238112391124011241112421124311244112451124611247112481124911250112511125211253112541125511256112571125811259112601126111262112631126411265112661126711268112691127011271112721127311274112751127611277112781127911280112811128211283112841128511286112871128811289112901129111292112931129411295112961129711298112991130011301113021130311304113051130611307113081130911310113111131211313113141131511316113171131811319113201132111322113231132411325113261132711328113291133011331113321133311334113351133611337113381133911340113411134211343113441134511346113471134811349113501135111352113531135411355113561135711358113591136011361113621136311364113651136611367113681136911370113711137211373113741137511376113771137811379113801138111382113831138411385113861138711388113891139011391113921139311394113951139611397113981139911400114011140211403114041140511406114071140811409114101141111412114131141411415114161141711418114191142011421114221142311424114251142611427114281142911430114311143211433114341143511436114371143811439114401144111442114431144411445114461144711448114491145011451114521145311454114551145611457114581145911460114611146211463114641146511466114671146811469114701147111472114731147411475114761147711478114791148011481114821148311484114851148611487114881148911490114911149211493114941149511496114971149811499115001150111502115031150411505115061150711508115091151011511115121151311514115151151611517115181151911520115211152211523115241152511526115271152811529115301153111532115331153411535115361153711538115391154011541115421154311544115451154611547115481154911550115511155211553115541155511556115571155811559115601156111562115631156411565115661156711568115691157011571115721157311574115751157611577115781157911580115811158211583115841158511586115871158811589115901159111592115931159411595115961159711598115991160011601116021160311604116051160611607116081160911610116111161211613116141161511616116171161811619116201162111622116231162411625116261162711628116291163011631116321163311634116351163611637116381163911640116411164211643116441164511646116471164811649116501165111652116531165411655116561165711658116591166011661116621166311664116651166611667116681166911670116711167211673116741167511676116771167811679116801168111682116831168411685116861168711688116891169011691116921169311694116951169611697116981169911700117011170211703117041170511706117071170811709117101171111712117131171411715117161171711718117191172011721117221172311724117251172611727117281172911730117311173211733117341173511736117371173811739117401174111742117431174411745117461174711748117491175011751117521175311754117551175611757117581175911760117611176211763117641176511766117671176811769117701177111772117731177411775117761177711778117791178011781117821178311784117851178611787117881178911790117911179211793117941179511796117971179811799118001180111802118031180411805118061180711808118091181011811118121181311814118151181611817118181181911820118211182211823118241182511826118271182811829118301183111832118331183411835118361183711838118391184011841118421184311844118451184611847118481184911850118511185211853118541185511856118571185811859118601186111862118631186411865118661186711868118691187011871118721187311874118751187611877118781187911880118811188211883118841188511886118871188811889118901189111892118931189411895118961189711898118991190011901119021190311904119051190611907119081190911910119111191211913119141191511916119171191811919119201192111922119231192411925119261192711928119291193011931119321193311934119351193611937119381193911940119411194211943119441194511946119471194811949119501195111952119531195411955119561195711958119591196011961119621196311964119651196611967119681196911970119711197211973119741197511976119771197811979119801198111982119831198411985119861198711988119891199011991119921199311994119951199611997119981199912000120011200212003120041200512006120071200812009120101201112012120131201412015120161201712018120191202012021120221202312024120251202612027120281202912030120311203212033120341203512036120371203812039120401204112042120431204412045120461204712048120491205012051120521205312054120551205612057120581205912060120611206212063120641206512066120671206812069120701207112072120731207412075120761207712078120791208012081120821208312084120851208612087120881208912090120911209212093120941209512096120971209812099121001210112102121031210412105121061210712108121091211012111121121211312114121151211612117121181211912120121211212212123121241212512126121271212812129121301213112132121331213412135121361213712138121391214012141121421214312144121451214612147121481214912150121511215212153121541215512156121571215812159121601216112162121631216412165121661216712168121691217012171121721217312174121751217612177121781217912180121811218212183121841218512186121871218812189121901219112192121931219412195121961219712198121991220012201122021220312204122051220612207122081220912210122111221212213122141221512216122171221812219122201222112222122231222412225122261222712228122291223012231122321223312234122351223612237122381223912240122411224212243122441224512246122471224812249122501225112252122531225412255122561225712258122591226012261122621226312264122651226612267122681226912270122711227212273122741227512276122771227812279122801228112282122831228412285122861228712288122891229012291122921229312294122951229612297122981229912300123011230212303123041230512306123071230812309123101231112312123131231412315123161231712318123191232012321123221232312324123251232612327123281232912330123311233212333123341233512336123371233812339123401234112342123431234412345123461234712348123491235012351123521235312354123551235612357123581235912360123611236212363123641236512366123671236812369123701237112372123731237412375123761237712378123791238012381123821238312384123851238612387123881238912390123911239212393123941239512396123971239812399124001240112402124031240412405124061240712408124091241012411124121241312414124151241612417124181241912420124211242212423124241242512426124271242812429124301243112432124331243412435124361243712438124391244012441124421244312444124451244612447124481244912450124511245212453124541245512456124571245812459124601246112462124631246412465124661246712468124691247012471124721247312474124751247612477124781247912480124811248212483124841248512486124871248812489124901249112492124931249412495124961249712498124991250012501125021250312504125051250612507125081250912510125111251212513125141251512516125171251812519125201252112522125231252412525125261252712528125291253012531125321253312534125351253612537125381253912540125411254212543125441254512546125471254812549125501255112552125531255412555125561255712558125591256012561125621256312564125651256612567125681256912570125711257212573125741257512576125771257812579125801258112582125831258412585125861258712588125891259012591125921259312594125951259612597125981259912600126011260212603126041260512606126071260812609126101261112612126131261412615126161261712618126191262012621126221262312624126251262612627126281262912630126311263212633126341263512636126371263812639126401264112642126431264412645126461264712648126491265012651126521265312654126551265612657126581265912660126611266212663126641266512666126671266812669126701267112672126731267412675126761267712678126791268012681126821268312684126851268612687126881268912690126911269212693126941269512696126971269812699127001270112702127031270412705127061270712708127091271012711127121271312714127151271612717127181271912720127211272212723127241272512726127271272812729127301273112732127331273412735127361273712738127391274012741127421274312744127451274612747127481274912750127511275212753127541275512756127571275812759127601276112762127631276412765127661276712768127691277012771127721277312774127751277612777127781277912780127811278212783127841278512786127871278812789127901279112792127931279412795127961279712798127991280012801128021280312804128051280612807128081280912810128111281212813128141281512816128171281812819128201282112822128231282412825128261282712828128291283012831128321283312834128351283612837128381283912840128411284212843128441284512846128471284812849128501285112852128531285412855128561285712858128591286012861128621286312864128651286612867128681286912870128711287212873128741287512876128771287812879128801288112882128831288412885128861288712888128891289012891128921289312894128951289612897128981289912900129011290212903129041290512906129071290812909129101291112912129131291412915129161291712918129191292012921129221292312924129251292612927129281292912930129311293212933129341293512936129371293812939129401294112942129431294412945129461294712948129491295012951129521295312954129551295612957129581295912960129611296212963129641296512966129671296812969129701297112972129731297412975129761297712978129791298012981129821298312984129851298612987129881298912990129911299212993129941299512996129971299812999130001300113002130031300413005130061300713008130091301013011130121301313014130151301613017130181301913020130211302213023130241302513026130271302813029130301303113032130331303413035130361303713038130391304013041130421304313044130451304613047130481304913050130511305213053130541305513056130571305813059130601306113062130631306413065130661306713068130691307013071130721307313074130751307613077130781307913080130811308213083130841308513086130871308813089130901309113092130931309413095130961309713098130991310013101131021310313104131051310613107131081310913110131111311213113131141311513116131171311813119131201312113122131231312413125131261312713128131291313013131131321313313134131351313613137131381313913140131411314213143131441314513146131471314813149131501315113152131531315413155131561315713158131591316013161131621316313164131651316613167131681316913170131711317213173131741317513176131771317813179131801318113182131831318413185131861318713188131891319013191131921319313194131951319613197131981319913200132011320213203132041320513206132071320813209132101321113212132131321413215132161321713218132191322013221132221322313224132251322613227132281322913230132311323213233132341323513236132371323813239132401324113242132431324413245132461324713248132491325013251132521325313254132551325613257132581325913260132611326213263132641326513266132671326813269132701327113272132731327413275132761327713278132791328013281132821328313284132851328613287132881328913290132911329213293132941329513296132971329813299133001330113302133031330413305133061330713308133091331013311133121331313314133151331613317133181331913320133211332213323133241332513326133271332813329133301333113332133331333413335133361333713338133391334013341133421334313344133451334613347133481334913350133511335213353133541335513356133571335813359133601336113362133631336413365133661336713368133691337013371133721337313374133751337613377133781337913380133811338213383133841338513386133871338813389133901339113392133931339413395133961339713398133991340013401134021340313404134051340613407134081340913410134111341213413134141341513416134171341813419134201342113422134231342413425134261342713428134291343013431134321343313434134351343613437134381343913440134411344213443134441344513446134471344813449134501345113452134531345413455134561345713458134591346013461134621346313464134651346613467134681346913470134711347213473134741347513476134771347813479134801348113482134831348413485134861348713488134891349013491134921349313494134951349613497134981349913500135011350213503135041350513506135071350813509135101351113512135131351413515135161351713518135191352013521135221352313524135251352613527135281352913530135311353213533135341353513536135371353813539135401354113542135431354413545135461354713548135491355013551135521355313554135551355613557135581355913560135611356213563135641356513566135671356813569135701357113572135731357413575135761357713578135791358013581135821358313584135851358613587135881358913590135911359213593135941359513596135971359813599136001360113602136031360413605136061360713608136091361013611136121361313614136151361613617136181361913620136211362213623136241362513626136271362813629136301363113632136331363413635136361363713638136391364013641136421364313644136451364613647136481364913650136511365213653136541365513656136571365813659136601366113662136631366413665136661366713668136691367013671136721367313674136751367613677136781367913680136811368213683136841368513686136871368813689136901369113692136931369413695136961369713698136991370013701137021370313704137051370613707137081370913710137111371213713137141371513716137171371813719137201372113722137231372413725137261372713728137291373013731137321373313734137351373613737137381373913740137411374213743137441374513746137471374813749137501375113752137531375413755137561375713758137591376013761137621376313764137651376613767137681376913770137711377213773137741377513776137771377813779137801378113782137831378413785137861378713788137891379013791137921379313794137951379613797137981379913800138011380213803138041380513806138071380813809138101381113812138131381413815138161381713818138191382013821138221382313824138251382613827138281382913830138311383213833138341383513836138371383813839138401384113842138431384413845138461384713848138491385013851138521385313854138551385613857138581385913860138611386213863138641386513866138671386813869138701387113872138731387413875138761387713878138791388013881138821388313884138851388613887138881388913890138911389213893138941389513896138971389813899139001390113902139031390413905139061390713908139091391013911139121391313914139151391613917139181391913920139211392213923139241392513926139271392813929139301393113932139331393413935139361393713938139391394013941139421394313944139451394613947139481394913950139511395213953139541395513956139571395813959139601396113962139631396413965139661396713968139691397013971139721397313974139751397613977139781397913980139811398213983139841398513986139871398813989139901399113992139931399413995139961399713998139991400014001140021400314004140051400614007140081400914010140111401214013140141401514016140171401814019140201402114022140231402414025140261402714028140291403014031140321403314034140351403614037140381403914040140411404214043140441404514046140471404814049140501405114052140531405414055140561405714058140591406014061140621406314064140651406614067140681406914070140711407214073140741407514076140771407814079140801408114082140831408414085140861408714088140891409014091140921409314094140951409614097140981409914100141011410214103141041410514106141071410814109141101411114112141131411414115141161411714118141191412014121141221412314124141251412614127141281412914130141311413214133141341413514136141371413814139141401414114142141431414414145141461414714148141491415014151141521415314154141551415614157141581415914160141611416214163141641416514166141671416814169141701417114172141731417414175141761417714178141791418014181141821418314184141851418614187141881418914190141911419214193141941419514196141971419814199142001420114202142031420414205142061420714208142091421014211142121421314214142151421614217142181421914220142211422214223142241422514226142271422814229142301423114232142331423414235142361423714238142391424014241142421424314244142451424614247142481424914250142511425214253142541425514256142571425814259142601426114262142631426414265142661426714268142691427014271142721427314274142751427614277142781427914280142811428214283142841428514286142871428814289142901429114292142931429414295142961429714298142991430014301143021430314304143051430614307143081430914310143111431214313143141431514316143171431814319143201432114322143231432414325143261432714328143291433014331143321433314334143351433614337143381433914340143411434214343143441434514346143471434814349143501435114352143531435414355143561435714358143591436014361143621436314364143651436614367143681436914370143711437214373143741437514376143771437814379143801438114382143831438414385143861438714388143891439014391143921439314394143951439614397143981439914400144011440214403144041440514406144071440814409144101441114412144131441414415144161441714418144191442014421144221442314424144251442614427144281442914430144311443214433144341443514436144371443814439144401444114442144431444414445144461444714448144491445014451144521445314454144551445614457144581445914460144611446214463144641446514466144671446814469144701447114472144731447414475144761447714478144791448014481144821448314484144851448614487144881448914490144911449214493144941449514496144971449814499145001450114502145031450414505145061450714508145091451014511145121451314514145151451614517145181451914520145211452214523145241452514526145271452814529145301453114532145331453414535145361453714538145391454014541145421454314544145451454614547145481454914550145511455214553145541455514556145571455814559145601456114562145631456414565145661456714568145691457014571145721457314574145751457614577145781457914580145811458214583145841458514586145871458814589145901459114592145931459414595145961459714598145991460014601146021460314604146051460614607146081460914610146111461214613146141461514616146171461814619146201462114622146231462414625146261462714628146291463014631146321463314634146351463614637146381463914640146411464214643146441464514646146471464814649146501465114652146531465414655146561465714658146591466014661146621466314664146651466614667146681466914670146711467214673146741467514676146771467814679146801468114682146831468414685146861468714688146891469014691146921469314694146951469614697146981469914700147011470214703147041470514706147071470814709147101471114712147131471414715147161471714718147191472014721147221472314724147251472614727147281472914730147311473214733147341473514736147371473814739147401474114742147431474414745147461474714748147491475014751147521475314754147551475614757147581475914760147611476214763147641476514766147671476814769147701477114772147731477414775147761477714778147791478014781147821478314784147851478614787147881478914790147911479214793147941479514796147971479814799148001480114802148031480414805148061480714808148091481014811148121481314814148151481614817148181481914820148211482214823148241482514826148271482814829148301483114832148331483414835148361483714838148391484014841148421484314844148451484614847148481484914850148511485214853148541485514856148571485814859148601486114862148631486414865148661486714868148691487014871148721487314874148751487614877148781487914880148811488214883148841488514886148871488814889148901489114892148931489414895148961489714898148991490014901149021490314904149051490614907149081490914910149111491214913149141491514916149171491814919149201492114922149231492414925149261492714928149291493014931149321493314934149351493614937149381493914940149411494214943149441494514946149471494814949149501495114952149531495414955149561495714958149591496014961149621496314964149651496614967149681496914970149711497214973149741497514976149771497814979149801498114982149831498414985149861498714988149891499014991149921499314994149951499614997149981499915000150011500215003150041500515006150071500815009150101501115012150131501415015150161501715018150191502015021150221502315024150251502615027150281502915030150311503215033150341503515036150371503815039150401504115042150431504415045150461504715048150491505015051150521505315054150551505615057150581505915060150611506215063150641506515066150671506815069150701507115072150731507415075150761507715078150791508015081150821508315084150851508615087150881508915090150911509215093150941509515096150971509815099151001510115102151031510415105151061510715108151091511015111151121511315114151151511615117151181511915120151211512215123151241512515126151271512815129151301513115132151331513415135151361513715138151391514015141151421514315144151451514615147151481514915150151511515215153151541515515156151571515815159151601516115162151631516415165151661516715168151691517015171151721517315174151751517615177151781517915180151811518215183151841518515186151871518815189151901519115192151931519415195151961519715198151991520015201152021520315204152051520615207152081520915210152111521215213152141521515216152171521815219152201522115222152231522415225152261522715228152291523015231152321523315234152351523615237152381523915240152411524215243152441524515246152471524815249152501525115252152531525415255152561525715258152591526015261152621526315264152651526615267152681526915270152711527215273152741527515276152771527815279152801528115282152831528415285152861528715288152891529015291152921529315294152951529615297152981529915300153011530215303153041530515306153071530815309153101531115312153131531415315153161531715318153191532015321153221532315324153251532615327153281532915330153311533215333153341533515336153371533815339153401534115342153431534415345153461534715348153491535015351153521535315354153551535615357153581535915360153611536215363153641536515366153671536815369153701537115372153731537415375153761537715378153791538015381153821538315384153851538615387153881538915390153911539215393153941539515396153971539815399154001540115402154031540415405154061540715408154091541015411154121541315414154151541615417154181541915420154211542215423154241542515426154271542815429154301543115432154331543415435154361543715438154391544015441154421544315444154451544615447154481544915450154511545215453154541545515456154571545815459154601546115462154631546415465154661546715468154691547015471154721547315474154751547615477154781547915480154811548215483154841548515486154871548815489154901549115492154931549415495154961549715498154991550015501155021550315504155051550615507155081550915510155111551215513155141551515516155171551815519155201552115522155231552415525155261552715528155291553015531155321553315534155351553615537155381553915540155411554215543155441554515546155471554815549155501555115552155531555415555155561555715558155591556015561155621556315564155651556615567155681556915570155711557215573155741557515576155771557815579155801558115582155831558415585155861558715588155891559015591155921559315594155951559615597155981559915600156011560215603156041560515606156071560815609156101561115612156131561415615156161561715618156191562015621156221562315624156251562615627156281562915630156311563215633156341563515636156371563815639156401564115642156431564415645156461564715648156491565015651156521565315654156551565615657156581565915660156611566215663156641566515666156671566815669156701567115672156731567415675156761567715678156791568015681156821568315684156851568615687156881568915690156911569215693156941569515696156971569815699157001570115702157031570415705157061570715708157091571015711157121571315714157151571615717157181571915720157211572215723157241572515726157271572815729157301573115732157331573415735157361573715738157391574015741157421574315744157451574615747157481574915750157511575215753157541575515756157571575815759157601576115762157631576415765157661576715768157691577015771157721577315774157751577615777157781577915780157811578215783157841578515786157871578815789157901579115792157931579415795157961579715798157991580015801158021580315804158051580615807158081580915810158111581215813158141581515816158171581815819158201582115822158231582415825158261582715828158291583015831158321583315834158351583615837158381583915840158411584215843158441584515846158471584815849158501585115852158531585415855158561585715858158591586015861158621586315864158651586615867158681586915870158711587215873158741587515876158771587815879158801588115882158831588415885158861588715888158891589015891158921589315894158951589615897158981589915900159011590215903159041590515906159071590815909159101591115912159131591415915159161591715918159191592015921159221592315924159251592615927159281592915930159311593215933159341593515936159371593815939159401594115942159431594415945159461594715948159491595015951159521595315954159551595615957159581595915960159611596215963159641596515966159671596815969159701597115972159731597415975159761597715978159791598015981159821598315984159851598615987159881598915990159911599215993159941599515996159971599815999160001600116002160031600416005160061600716008160091601016011160121601316014160151601616017160181601916020160211602216023160241602516026160271602816029160301603116032160331603416035160361603716038160391604016041160421604316044160451604616047160481604916050160511605216053160541605516056160571605816059160601606116062160631606416065160661606716068160691607016071160721607316074160751607616077160781607916080160811608216083160841608516086160871608816089160901609116092160931609416095160961609716098160991610016101161021610316104161051610616107161081610916110161111611216113161141611516116161171611816119161201612116122161231612416125161261612716128161291613016131161321613316134161351613616137161381613916140161411614216143161441614516146161471614816149161501615116152161531615416155161561615716158161591616016161161621616316164161651616616167161681616916170161711617216173161741617516176161771617816179161801618116182161831618416185161861618716188161891619016191161921619316194161951619616197161981619916200162011620216203162041620516206162071620816209162101621116212162131621416215162161621716218162191622016221162221622316224162251622616227162281622916230162311623216233162341623516236162371623816239162401624116242162431624416245162461624716248162491625016251162521625316254162551625616257162581625916260162611626216263162641626516266162671626816269162701627116272162731627416275162761627716278162791628016281162821628316284162851628616287162881628916290162911629216293162941629516296162971629816299163001630116302163031630416305163061630716308163091631016311163121631316314163151631616317163181631916320163211632216323163241632516326163271632816329163301633116332163331633416335163361633716338163391634016341163421634316344163451634616347163481634916350163511635216353163541635516356163571635816359163601636116362163631636416365163661636716368163691637016371163721637316374163751637616377163781637916380163811638216383163841638516386163871638816389163901639116392163931639416395163961639716398163991640016401164021640316404164051640616407164081640916410164111641216413164141641516416164171641816419164201642116422164231642416425164261642716428164291643016431164321643316434164351643616437164381643916440164411644216443164441644516446164471644816449164501645116452164531645416455164561645716458164591646016461164621646316464164651646616467164681646916470164711647216473164741647516476164771647816479164801648116482164831648416485164861648716488164891649016491164921649316494164951649616497164981649916500165011650216503165041650516506165071650816509165101651116512165131651416515165161651716518165191652016521165221652316524165251652616527165281652916530165311653216533165341653516536165371653816539165401654116542165431654416545165461654716548165491655016551165521655316554165551655616557165581655916560165611656216563165641656516566165671656816569165701657116572165731657416575165761657716578165791658016581165821658316584165851658616587165881658916590165911659216593165941659516596165971659816599166001660116602166031660416605166061660716608166091661016611166121661316614166151661616617166181661916620166211662216623166241662516626166271662816629166301663116632166331663416635166361663716638166391664016641166421664316644166451664616647166481664916650166511665216653166541665516656166571665816659166601666116662166631666416665166661666716668166691667016671166721667316674166751667616677166781667916680166811668216683166841668516686166871668816689166901669116692166931669416695166961669716698166991670016701167021670316704167051670616707167081670916710167111671216713167141671516716167171671816719167201672116722167231672416725167261672716728167291673016731167321673316734167351673616737167381673916740167411674216743167441674516746167471674816749167501675116752167531675416755167561675716758167591676016761167621676316764167651676616767167681676916770167711677216773167741677516776167771677816779167801678116782167831678416785167861678716788167891679016791167921679316794167951679616797167981679916800168011680216803168041680516806168071680816809168101681116812168131681416815168161681716818168191682016821168221682316824168251682616827168281682916830168311683216833168341683516836168371683816839168401684116842168431684416845168461684716848168491685016851168521685316854168551685616857168581685916860168611686216863168641686516866168671686816869168701687116872168731687416875168761687716878168791688016881168821688316884168851688616887168881688916890168911689216893168941689516896168971689816899169001690116902169031690416905169061690716908169091691016911169121691316914169151691616917169181691916920169211692216923169241692516926169271692816929169301693116932169331693416935169361693716938169391694016941169421694316944169451694616947169481694916950169511695216953169541695516956169571695816959169601696116962169631696416965169661696716968169691697016971169721697316974169751697616977169781697916980169811698216983169841698516986169871698816989169901699116992169931699416995169961699716998169991700017001170021700317004170051700617007170081700917010170111701217013170141701517016170171701817019170201702117022170231702417025170261702717028170291703017031170321703317034170351703617037170381703917040170411704217043170441704517046170471704817049170501705117052170531705417055170561705717058170591706017061170621706317064170651706617067170681706917070170711707217073170741707517076170771707817079170801708117082170831708417085170861708717088170891709017091170921709317094170951709617097170981709917100171011710217103171041710517106171071710817109171101711117112171131711417115171161711717118171191712017121171221712317124171251712617127171281712917130171311713217133171341713517136171371713817139171401714117142171431714417145171461714717148171491715017151171521715317154171551715617157171581715917160171611716217163171641716517166171671716817169171701717117172171731717417175171761717717178171791718017181171821718317184171851718617187171881718917190171911719217193171941719517196171971719817199172001720117202172031720417205172061720717208172091721017211172121721317214172151721617217172181721917220172211722217223172241722517226172271722817229172301723117232172331723417235172361723717238172391724017241172421724317244172451724617247172481724917250172511725217253172541725517256172571725817259172601726117262172631726417265172661726717268172691727017271172721727317274172751727617277172781727917280172811728217283172841728517286172871728817289172901729117292172931729417295172961729717298172991730017301173021730317304173051730617307173081730917310173111731217313173141731517316173171731817319173201732117322173231732417325173261732717328173291733017331173321733317334173351733617337173381733917340173411734217343173441734517346173471734817349173501735117352173531735417355173561735717358173591736017361173621736317364173651736617367173681736917370173711737217373173741737517376173771737817379173801738117382173831738417385173861738717388173891739017391173921739317394173951739617397173981739917400174011740217403174041740517406174071740817409174101741117412174131741417415174161741717418174191742017421174221742317424174251742617427174281742917430174311743217433174341743517436174371743817439174401744117442174431744417445174461744717448174491745017451174521745317454174551745617457174581745917460174611746217463174641746517466174671746817469174701747117472174731747417475174761747717478174791748017481174821748317484174851748617487174881748917490174911749217493174941749517496174971749817499175001750117502175031750417505175061750717508175091751017511175121751317514175151751617517175181751917520175211752217523175241752517526175271752817529175301753117532175331753417535175361753717538175391754017541175421754317544175451754617547175481754917550175511755217553175541755517556175571755817559175601756117562175631756417565175661756717568175691757017571175721757317574175751757617577175781757917580175811758217583175841758517586175871758817589175901759117592175931759417595175961759717598175991760017601176021760317604176051760617607176081760917610176111761217613176141761517616176171761817619176201762117622176231762417625176261762717628176291763017631176321763317634176351763617637176381763917640176411764217643176441764517646176471764817649176501765117652176531765417655176561765717658176591766017661176621766317664176651766617667176681766917670176711767217673176741767517676176771767817679176801768117682176831768417685176861768717688176891769017691176921769317694176951769617697176981769917700177011770217703177041770517706177071770817709177101771117712177131771417715177161771717718177191772017721177221772317724177251772617727177281772917730177311773217733177341773517736177371773817739177401774117742177431774417745177461774717748177491775017751177521775317754177551775617757177581775917760177611776217763177641776517766177671776817769177701777117772177731777417775177761777717778177791778017781177821778317784177851778617787177881778917790177911779217793177941779517796177971779817799178001780117802178031780417805178061780717808178091781017811178121781317814178151781617817178181781917820178211782217823178241782517826178271782817829178301783117832178331783417835178361783717838178391784017841178421784317844178451784617847178481784917850178511785217853178541785517856178571785817859178601786117862178631786417865178661786717868178691787017871178721787317874178751787617877178781787917880178811788217883178841788517886178871788817889178901789117892178931789417895178961789717898178991790017901179021790317904179051790617907179081790917910179111791217913179141791517916179171791817919179201792117922179231792417925179261792717928179291793017931179321793317934179351793617937179381793917940179411794217943179441794517946179471794817949179501795117952179531795417955179561795717958179591796017961179621796317964179651796617967179681796917970179711797217973179741797517976179771797817979179801798117982179831798417985179861798717988179891799017991179921799317994179951799617997179981799918000180011800218003180041800518006180071800818009180101801118012180131801418015180161801718018180191802018021180221802318024180251802618027180281802918030180311803218033180341803518036180371803818039180401804118042180431804418045180461804718048180491805018051180521805318054180551805618057180581805918060180611806218063180641806518066180671806818069180701807118072180731807418075180761807718078180791808018081180821808318084180851808618087180881808918090180911809218093180941809518096180971809818099181001810118102181031810418105181061810718108181091811018111181121811318114181151811618117181181811918120181211812218123181241812518126181271812818129181301813118132181331813418135181361813718138181391814018141181421814318144181451814618147181481814918150181511815218153181541815518156181571815818159181601816118162181631816418165181661816718168181691817018171181721817318174181751817618177181781817918180181811818218183181841818518186181871818818189181901819118192181931819418195181961819718198181991820018201182021820318204182051820618207182081820918210182111821218213182141821518216182171821818219182201822118222182231822418225182261822718228182291823018231182321823318234182351823618237182381823918240182411824218243182441824518246182471824818249182501825118252182531825418255182561825718258182591826018261182621826318264182651826618267182681826918270182711827218273182741827518276182771827818279182801828118282182831828418285182861828718288182891829018291182921829318294182951829618297182981829918300183011830218303183041830518306183071830818309183101831118312183131831418315183161831718318183191832018321183221832318324183251832618327183281832918330183311833218333183341833518336183371833818339183401834118342183431834418345183461834718348183491835018351183521835318354183551835618357183581835918360183611836218363183641836518366183671836818369183701837118372183731837418375183761837718378183791838018381183821838318384183851838618387183881838918390183911839218393183941839518396183971839818399184001840118402184031840418405184061840718408184091841018411184121841318414184151841618417184181841918420184211842218423184241842518426184271842818429184301843118432184331843418435184361843718438184391844018441184421844318444184451844618447184481844918450184511845218453184541845518456184571845818459184601846118462184631846418465184661846718468184691847018471184721847318474184751847618477184781847918480184811848218483184841848518486184871848818489184901849118492184931849418495184961849718498184991850018501185021850318504185051850618507185081850918510185111851218513185141851518516185171851818519185201852118522185231852418525185261852718528185291853018531185321853318534185351853618537185381853918540185411854218543185441854518546185471854818549185501855118552185531855418555185561855718558185591856018561185621856318564185651856618567185681856918570185711857218573185741857518576185771857818579185801858118582185831858418585185861858718588185891859018591185921859318594185951859618597185981859918600186011860218603186041860518606186071860818609186101861118612186131861418615186161861718618186191862018621186221862318624186251862618627186281862918630186311863218633186341863518636186371863818639186401864118642186431864418645186461864718648186491865018651186521865318654186551865618657186581865918660186611866218663186641866518666186671866818669186701867118672186731867418675186761867718678186791868018681186821868318684186851868618687186881868918690186911869218693186941869518696186971869818699187001870118702187031870418705187061870718708187091871018711187121871318714187151871618717187181871918720187211872218723187241872518726187271872818729187301873118732187331873418735187361873718738187391874018741187421874318744187451874618747187481874918750187511875218753187541875518756187571875818759187601876118762187631876418765187661876718768187691877018771187721877318774187751877618777187781877918780187811878218783187841878518786187871878818789187901879118792187931879418795187961879718798187991880018801188021880318804188051880618807188081880918810188111881218813188141881518816188171881818819188201882118822188231882418825188261882718828188291883018831188321883318834188351883618837188381883918840188411884218843188441884518846188471884818849188501885118852188531885418855188561885718858188591886018861188621886318864188651886618867188681886918870188711887218873188741887518876188771887818879188801888118882188831888418885188861888718888188891889018891188921889318894188951889618897188981889918900189011890218903189041890518906189071890818909189101891118912189131891418915189161891718918189191892018921189221892318924189251892618927189281892918930189311893218933189341893518936189371893818939189401894118942189431894418945189461894718948189491895018951189521895318954189551895618957189581895918960189611896218963189641896518966189671896818969189701897118972189731897418975189761897718978189791898018981189821898318984189851898618987189881898918990189911899218993189941899518996189971899818999190001900119002190031900419005190061900719008190091901019011190121901319014190151901619017190181901919020190211902219023190241902519026190271902819029190301903119032190331903419035190361903719038190391904019041190421904319044190451904619047190481904919050190511905219053190541905519056190571905819059190601906119062190631906419065190661906719068190691907019071190721907319074190751907619077190781907919080190811908219083190841908519086190871908819089190901909119092190931909419095190961909719098190991910019101191021910319104191051910619107191081910919110191111911219113191141911519116191171911819119191201912119122191231912419125191261912719128191291913019131191321913319134191351913619137191381913919140191411914219143191441914519146191471914819149191501915119152191531915419155191561915719158191591916019161191621916319164191651916619167191681916919170191711917219173191741917519176191771917819179191801918119182191831918419185191861918719188191891919019191191921919319194191951919619197191981919919200192011920219203192041920519206192071920819209192101921119212192131921419215192161921719218192191922019221192221922319224192251922619227192281922919230192311923219233192341923519236192371923819239192401924119242192431924419245192461924719248192491925019251192521925319254192551925619257192581925919260192611926219263192641926519266192671926819269192701927119272192731927419275192761927719278192791928019281192821928319284192851928619287192881928919290192911929219293192941929519296192971929819299193001930119302193031930419305193061930719308193091931019311193121931319314193151931619317193181931919320193211932219323193241932519326193271932819329193301933119332193331933419335193361933719338193391934019341193421934319344193451934619347193481934919350193511935219353193541935519356193571935819359193601936119362193631936419365193661936719368193691937019371193721937319374193751937619377193781937919380193811938219383193841938519386193871938819389193901939119392193931939419395193961939719398193991940019401194021940319404194051940619407194081940919410194111941219413194141941519416194171941819419194201942119422194231942419425194261942719428194291943019431194321943319434194351943619437194381943919440194411944219443194441944519446194471944819449194501945119452194531945419455194561945719458194591946019461194621946319464194651946619467194681946919470194711947219473194741947519476194771947819479194801948119482194831948419485194861948719488194891949019491194921949319494194951949619497194981949919500195011950219503195041950519506195071950819509195101951119512195131951419515195161951719518195191952019521195221952319524195251952619527195281952919530195311953219533195341953519536195371953819539195401954119542195431954419545195461954719548195491955019551195521955319554195551955619557195581955919560195611956219563195641956519566195671956819569195701957119572195731957419575195761957719578195791958019581195821958319584195851958619587195881958919590195911959219593195941959519596195971959819599196001960119602196031960419605196061960719608196091961019611196121961319614196151961619617196181961919620196211962219623196241962519626196271962819629196301963119632196331963419635196361963719638196391964019641196421964319644196451964619647196481964919650196511965219653196541965519656196571965819659196601966119662196631966419665196661966719668196691967019671196721967319674196751967619677196781967919680196811968219683196841968519686196871968819689196901969119692196931969419695196961969719698196991970019701197021970319704197051970619707197081970919710197111971219713197141971519716197171971819719197201972119722197231972419725197261972719728197291973019731197321973319734197351973619737197381973919740197411974219743197441974519746197471974819749197501975119752197531975419755197561975719758197591976019761197621976319764197651976619767197681976919770197711977219773197741977519776197771977819779197801978119782197831978419785197861978719788197891979019791197921979319794197951979619797197981979919800198011980219803198041980519806198071980819809198101981119812198131981419815198161981719818198191982019821198221982319824198251982619827198281982919830198311983219833198341983519836198371983819839198401984119842198431984419845198461984719848198491985019851198521985319854198551985619857198581985919860198611986219863198641986519866198671986819869198701987119872198731987419875198761987719878198791988019881198821988319884198851988619887198881988919890198911989219893198941989519896198971989819899199001990119902199031990419905199061990719908199091991019911199121991319914199151991619917199181991919920199211992219923199241992519926199271992819929199301993119932199331993419935199361993719938199391994019941199421994319944199451994619947199481994919950199511995219953199541995519956199571995819959199601996119962199631996419965199661996719968199691997019971199721997319974199751997619977199781997919980199811998219983199841998519986199871998819989199901999119992199931999419995199961999719998199992000020001200022000320004200052000620007200082000920010200112001220013200142001520016200172001820019200202002120022200232002420025200262002720028200292003020031200322003320034200352003620037200382003920040200412004220043200442004520046200472004820049200502005120052200532005420055200562005720058200592006020061200622006320064200652006620067200682006920070200712007220073200742007520076200772007820079200802008120082200832008420085200862008720088200892009020091200922009320094200952009620097200982009920100201012010220103201042010520106201072010820109201102011120112201132011420115201162011720118201192012020121201222012320124201252012620127201282012920130201312013220133201342013520136201372013820139201402014120142201432014420145201462014720148201492015020151201522015320154201552015620157201582015920160201612016220163201642016520166201672016820169201702017120172201732017420175201762017720178201792018020181201822018320184201852018620187201882018920190201912019220193201942019520196201972019820199202002020120202202032020420205202062020720208202092021020211202122021320214202152021620217202182021920220202212022220223202242022520226202272022820229202302023120232202332023420235202362023720238202392024020241202422024320244202452024620247202482024920250202512025220253202542025520256202572025820259202602026120262202632026420265202662026720268202692027020271202722027320274202752027620277202782027920280202812028220283202842028520286202872028820289202902029120292202932029420295202962029720298202992030020301203022030320304203052030620307203082030920310203112031220313203142031520316203172031820319203202032120322203232032420325203262032720328203292033020331203322033320334203352033620337203382033920340203412034220343203442034520346203472034820349203502035120352203532035420355203562035720358203592036020361203622036320364203652036620367203682036920370203712037220373203742037520376203772037820379203802038120382203832038420385203862038720388203892039020391203922039320394203952039620397203982039920400204012040220403204042040520406204072040820409204102041120412204132041420415204162041720418204192042020421204222042320424204252042620427204282042920430204312043220433204342043520436204372043820439204402044120442204432044420445204462044720448204492045020451204522045320454204552045620457204582045920460204612046220463204642046520466204672046820469204702047120472204732047420475204762047720478204792048020481204822048320484204852048620487204882048920490204912049220493204942049520496204972049820499205002050120502205032050420505205062050720508205092051020511205122051320514205152051620517205182051920520205212052220523205242052520526205272052820529205302053120532205332053420535205362053720538205392054020541205422054320544205452054620547205482054920550205512055220553205542055520556205572055820559205602056120562205632056420565205662056720568205692057020571205722057320574205752057620577205782057920580205812058220583205842058520586205872058820589205902059120592205932059420595205962059720598205992060020601206022060320604206052060620607206082060920610206112061220613206142061520616206172061820619206202062120622206232062420625206262062720628206292063020631206322063320634206352063620637206382063920640206412064220643206442064520646206472064820649206502065120652206532065420655206562065720658206592066020661206622066320664206652066620667206682066920670206712067220673206742067520676206772067820679206802068120682206832068420685206862068720688206892069020691206922069320694206952069620697206982069920700207012070220703207042070520706207072070820709207102071120712207132071420715207162071720718207192072020721207222072320724207252072620727207282072920730207312073220733207342073520736207372073820739207402074120742207432074420745207462074720748207492075020751207522075320754207552075620757207582075920760207612076220763207642076520766207672076820769207702077120772207732077420775207762077720778207792078020781207822078320784207852078620787207882078920790207912079220793207942079520796207972079820799208002080120802208032080420805208062080720808208092081020811208122081320814208152081620817208182081920820208212082220823208242082520826208272082820829208302083120832208332083420835208362083720838208392084020841208422084320844208452084620847208482084920850208512085220853208542085520856208572085820859208602086120862208632086420865208662086720868208692087020871208722087320874208752087620877208782087920880208812088220883208842088520886208872088820889208902089120892208932089420895208962089720898208992090020901209022090320904209052090620907209082090920910209112091220913209142091520916209172091820919209202092120922209232092420925209262092720928209292093020931209322093320934209352093620937209382093920940209412094220943209442094520946209472094820949209502095120952209532095420955209562095720958209592096020961209622096320964209652096620967209682096920970209712097220973209742097520976209772097820979209802098120982209832098420985209862098720988209892099020991209922099320994209952099620997209982099921000210012100221003210042100521006210072100821009210102101121012210132101421015210162101721018210192102021021210222102321024210252102621027210282102921030210312103221033210342103521036210372103821039210402104121042210432104421045210462104721048210492105021051210522105321054210552105621057210582105921060210612106221063210642106521066210672106821069210702107121072210732107421075210762107721078210792108021081210822108321084210852108621087210882108921090210912109221093210942109521096210972109821099211002110121102211032110421105211062110721108211092111021111211122111321114211152111621117211182111921120211212112221123211242112521126211272112821129211302113121132211332113421135211362113721138211392114021141211422114321144211452114621147211482114921150211512115221153211542115521156211572115821159211602116121162211632116421165211662116721168211692117021171211722117321174211752117621177211782117921180211812118221183211842118521186211872118821189211902119121192211932119421195211962119721198211992120021201212022120321204212052120621207212082120921210212112121221213212142121521216212172121821219212202122121222212232122421225212262122721228212292123021231212322123321234212352123621237212382123921240212412124221243212442124521246212472124821249212502125121252212532125421255212562125721258212592126021261212622126321264212652126621267212682126921270212712127221273212742127521276212772127821279212802128121282212832128421285212862128721288212892129021291212922129321294212952129621297212982129921300213012130221303213042130521306213072130821309213102131121312213132131421315213162131721318213192132021321213222132321324213252132621327213282132921330213312133221333213342133521336213372133821339213402134121342213432134421345213462134721348213492135021351213522135321354213552135621357213582135921360213612136221363213642136521366213672136821369213702137121372213732137421375213762137721378213792138021381213822138321384213852138621387213882138921390213912139221393213942139521396213972139821399214002140121402214032140421405214062140721408214092141021411214122141321414214152141621417214182141921420214212142221423214242142521426214272142821429214302143121432214332143421435214362143721438214392144021441214422144321444214452144621447214482144921450214512145221453214542145521456214572145821459214602146121462214632146421465214662146721468214692147021471214722147321474214752147621477214782147921480214812148221483214842148521486214872148821489214902149121492214932149421495214962149721498214992150021501215022150321504215052150621507215082150921510215112151221513215142151521516215172151821519215202152121522215232152421525215262152721528215292153021531215322153321534215352153621537215382153921540215412154221543215442154521546215472154821549215502155121552215532155421555215562155721558215592156021561215622156321564215652156621567215682156921570215712157221573215742157521576215772157821579215802158121582215832158421585215862158721588215892159021591215922159321594215952159621597215982159921600216012160221603216042160521606216072160821609216102161121612216132161421615216162161721618216192162021621216222162321624216252162621627216282162921630216312163221633216342163521636216372163821639216402164121642216432164421645216462164721648216492165021651216522165321654216552165621657216582165921660216612166221663216642166521666216672166821669216702167121672216732167421675216762167721678216792168021681216822168321684216852168621687216882168921690216912169221693216942169521696216972169821699217002170121702217032170421705217062170721708217092171021711217122171321714217152171621717217182171921720217212172221723217242172521726217272172821729217302173121732217332173421735217362173721738217392174021741217422174321744217452174621747217482174921750217512175221753217542175521756217572175821759217602176121762217632176421765217662176721768217692177021771217722177321774217752177621777217782177921780217812178221783217842178521786217872178821789217902179121792217932179421795217962179721798217992180021801218022180321804218052180621807218082180921810218112181221813218142181521816218172181821819218202182121822218232182421825218262182721828218292183021831218322183321834218352183621837218382183921840218412184221843218442184521846218472184821849218502185121852218532185421855218562185721858218592186021861218622186321864218652186621867218682186921870218712187221873218742187521876218772187821879218802188121882218832188421885218862188721888218892189021891218922189321894218952189621897218982189921900219012190221903219042190521906219072190821909219102191121912219132191421915219162191721918219192192021921219222192321924219252192621927219282192921930219312193221933219342193521936219372193821939219402194121942219432194421945219462194721948219492195021951219522195321954219552195621957219582195921960219612196221963219642196521966219672196821969219702197121972219732197421975219762197721978219792198021981219822198321984219852198621987219882198921990219912199221993219942199521996219972199821999220002200122002220032200422005220062200722008220092201022011220122201322014220152201622017220182201922020220212202222023220242202522026220272202822029220302203122032220332203422035220362203722038220392204022041220422204322044220452204622047220482204922050220512205222053220542205522056220572205822059220602206122062220632206422065220662206722068220692207022071220722207322074220752207622077220782207922080220812208222083220842208522086220872208822089220902209122092220932209422095220962209722098220992210022101221022210322104221052210622107221082210922110221112211222113221142211522116221172211822119221202212122122221232212422125221262212722128221292213022131221322213322134221352213622137221382213922140221412214222143221442214522146221472214822149221502215122152221532215422155221562215722158221592216022161221622216322164221652216622167221682216922170221712217222173221742217522176221772217822179221802218122182221832218422185221862218722188221892219022191221922219322194221952219622197221982219922200222012220222203222042220522206222072220822209222102221122212222132221422215222162221722218222192222022221222222222322224222252222622227222282222922230222312223222233222342223522236222372223822239222402224122242222432224422245222462224722248222492225022251222522225322254222552225622257222582225922260222612226222263222642226522266222672226822269222702227122272222732227422275222762227722278222792228022281222822228322284222852228622287222882228922290222912229222293222942229522296222972229822299223002230122302223032230422305223062230722308223092231022311223122231322314223152231622317223182231922320223212232222323223242232522326223272232822329223302233122332223332233422335223362233722338223392234022341223422234322344223452234622347223482234922350223512235222353223542235522356223572235822359223602236122362223632236422365223662236722368223692237022371223722237322374223752237622377223782237922380223812238222383223842238522386223872238822389223902239122392223932239422395223962239722398223992240022401224022240322404224052240622407224082240922410224112241222413224142241522416224172241822419224202242122422224232242422425224262242722428224292243022431224322243322434224352243622437224382243922440224412244222443224442244522446224472244822449224502245122452224532245422455224562245722458224592246022461224622246322464224652246622467224682246922470224712247222473224742247522476224772247822479224802248122482224832248422485224862248722488224892249022491224922249322494224952249622497224982249922500225012250222503225042250522506225072250822509225102251122512225132251422515225162251722518225192252022521225222252322524225252252622527225282252922530225312253222533225342253522536225372253822539225402254122542225432254422545225462254722548225492255022551225522255322554225552255622557225582255922560225612256222563225642256522566225672256822569225702257122572225732257422575225762257722578225792258022581225822258322584225852258622587225882258922590225912259222593225942259522596225972259822599226002260122602226032260422605226062260722608226092261022611226122261322614226152261622617226182261922620226212262222623226242262522626226272262822629226302263122632226332263422635226362263722638226392264022641226422264322644226452264622647226482264922650226512265222653226542265522656226572265822659226602266122662226632266422665226662266722668226692267022671226722267322674226752267622677226782267922680226812268222683226842268522686226872268822689226902269122692226932269422695226962269722698226992270022701227022270322704227052270622707227082270922710227112271222713227142271522716227172271822719227202272122722227232272422725227262272722728227292273022731227322273322734227352273622737227382273922740227412274222743227442274522746227472274822749227502275122752227532275422755227562275722758227592276022761227622276322764227652276622767227682276922770227712277222773227742277522776227772277822779227802278122782227832278422785227862278722788227892279022791227922279322794227952279622797227982279922800228012280222803228042280522806228072280822809228102281122812228132281422815228162281722818228192282022821228222282322824228252282622827228282282922830228312283222833228342283522836228372283822839228402284122842228432284422845228462284722848228492285022851228522285322854228552285622857228582285922860228612286222863228642286522866228672286822869228702287122872228732287422875228762287722878228792288022881228822288322884228852288622887228882288922890228912289222893228942289522896228972289822899229002290122902229032290422905229062290722908229092291022911229122291322914229152291622917229182291922920229212292222923229242292522926229272292822929229302293122932229332293422935229362293722938229392294022941229422294322944229452294622947229482294922950229512295222953229542295522956229572295822959229602296122962229632296422965229662296722968229692297022971229722297322974229752297622977229782297922980229812298222983229842298522986229872298822989229902299122992229932299422995229962299722998229992300023001230022300323004230052300623007230082300923010230112301223013230142301523016230172301823019230202302123022230232302423025230262302723028230292303023031230322303323034230352303623037230382303923040230412304223043230442304523046230472304823049230502305123052230532305423055230562305723058230592306023061230622306323064230652306623067230682306923070230712307223073230742307523076230772307823079230802308123082230832308423085230862308723088230892309023091230922309323094230952309623097230982309923100231012310223103231042310523106231072310823109231102311123112231132311423115231162311723118231192312023121231222312323124231252312623127231282312923130231312313223133231342313523136231372313823139231402314123142231432314423145231462314723148231492315023151231522315323154231552315623157231582315923160231612316223163231642316523166231672316823169231702317123172231732317423175231762317723178231792318023181231822318323184231852318623187231882318923190231912319223193231942319523196231972319823199232002320123202232032320423205232062320723208232092321023211232122321323214232152321623217232182321923220232212322223223232242322523226232272322823229232302323123232232332323423235232362323723238232392324023241232422324323244232452324623247232482324923250232512325223253232542325523256232572325823259232602326123262232632326423265232662326723268232692327023271232722327323274232752327623277232782327923280232812328223283232842328523286232872328823289232902329123292232932329423295232962329723298232992330023301233022330323304233052330623307233082330923310233112331223313233142331523316233172331823319233202332123322233232332423325233262332723328233292333023331233322333323334233352333623337233382333923340233412334223343233442334523346233472334823349233502335123352233532335423355233562335723358233592336023361233622336323364233652336623367233682336923370233712337223373233742337523376233772337823379233802338123382233832338423385233862338723388233892339023391233922339323394233952339623397233982339923400234012340223403234042340523406234072340823409234102341123412234132341423415234162341723418234192342023421234222342323424234252342623427234282342923430234312343223433234342343523436234372343823439234402344123442234432344423445234462344723448234492345023451234522345323454234552345623457234582345923460234612346223463234642346523466234672346823469234702347123472234732347423475234762347723478234792348023481234822348323484234852348623487234882348923490234912349223493234942349523496234972349823499235002350123502235032350423505235062350723508235092351023511235122351323514235152351623517235182351923520235212352223523235242352523526235272352823529235302353123532235332353423535235362353723538235392354023541235422354323544235452354623547235482354923550235512355223553235542355523556235572355823559235602356123562235632356423565235662356723568235692357023571235722357323574235752357623577235782357923580235812358223583235842358523586235872358823589235902359123592235932359423595235962359723598235992360023601236022360323604236052360623607236082360923610236112361223613236142361523616236172361823619236202362123622236232362423625236262362723628236292363023631236322363323634236352363623637236382363923640236412364223643236442364523646236472364823649236502365123652236532365423655236562365723658236592366023661236622366323664236652366623667236682366923670236712367223673236742367523676236772367823679236802368123682236832368423685236862368723688236892369023691236922369323694236952369623697236982369923700237012370223703237042370523706237072370823709237102371123712237132371423715237162371723718237192372023721237222372323724237252372623727237282372923730237312373223733237342373523736237372373823739237402374123742237432374423745237462374723748237492375023751237522375323754237552375623757237582375923760237612376223763237642376523766237672376823769237702377123772237732377423775237762377723778237792378023781237822378323784237852378623787237882378923790237912379223793237942379523796237972379823799238002380123802238032380423805238062380723808238092381023811238122381323814238152381623817238182381923820238212382223823238242382523826238272382823829238302383123832238332383423835238362383723838238392384023841238422384323844238452384623847238482384923850238512385223853238542385523856238572385823859238602386123862238632386423865238662386723868238692387023871238722387323874238752387623877238782387923880238812388223883238842388523886238872388823889238902389123892238932389423895238962389723898238992390023901239022390323904239052390623907239082390923910239112391223913239142391523916239172391823919239202392123922239232392423925239262392723928239292393023931239322393323934239352393623937239382393923940239412394223943239442394523946239472394823949239502395123952239532395423955239562395723958239592396023961239622396323964239652396623967239682396923970239712397223973239742397523976239772397823979239802398123982239832398423985239862398723988239892399023991239922399323994239952399623997239982399924000240012400224003240042400524006240072400824009240102401124012240132401424015240162401724018240192402024021240222402324024240252402624027240282402924030240312403224033240342403524036240372403824039240402404124042240432404424045240462404724048240492405024051240522405324054240552405624057240582405924060240612406224063240642406524066240672406824069240702407124072240732407424075240762407724078240792408024081240822408324084240852408624087240882408924090240912409224093240942409524096240972409824099241002410124102241032410424105241062410724108241092411024111241122411324114241152411624117241182411924120241212412224123241242412524126241272412824129241302413124132241332413424135241362413724138241392414024141241422414324144241452414624147241482414924150241512415224153241542415524156241572415824159241602416124162241632416424165241662416724168241692417024171241722417324174241752417624177241782417924180241812418224183241842418524186241872418824189241902419124192241932419424195241962419724198241992420024201242022420324204242052420624207242082420924210242112421224213242142421524216242172421824219242202422124222242232422424225242262422724228242292423024231242322423324234242352423624237242382423924240242412424224243242442424524246242472424824249242502425124252242532425424255242562425724258242592426024261242622426324264242652426624267242682426924270242712427224273242742427524276242772427824279242802428124282242832428424285242862428724288242892429024291242922429324294242952429624297242982429924300243012430224303243042430524306243072430824309243102431124312243132431424315243162431724318243192432024321243222432324324243252432624327243282432924330243312433224333243342433524336243372433824339243402434124342243432434424345243462434724348243492435024351243522435324354243552435624357243582435924360243612436224363243642436524366243672436824369243702437124372243732437424375243762437724378243792438024381243822438324384243852438624387243882438924390243912439224393243942439524396243972439824399244002440124402244032440424405244062440724408244092441024411244122441324414244152441624417244182441924420244212442224423244242442524426244272442824429244302443124432244332443424435244362443724438244392444024441244422444324444244452444624447244482444924450244512445224453244542445524456244572445824459244602446124462244632446424465244662446724468244692447024471244722447324474244752447624477244782447924480244812448224483244842448524486244872448824489244902449124492244932449424495244962449724498244992450024501245022450324504245052450624507245082450924510245112451224513245142451524516245172451824519245202452124522245232452424525245262452724528245292453024531245322453324534245352453624537245382453924540245412454224543245442454524546245472454824549245502455124552245532455424555245562455724558245592456024561245622456324564245652456624567245682456924570245712457224573245742457524576245772457824579245802458124582245832458424585245862458724588245892459024591245922459324594245952459624597245982459924600246012460224603246042460524606246072460824609246102461124612246132461424615246162461724618246192462024621246222462324624246252462624627246282462924630246312463224633246342463524636246372463824639246402464124642246432464424645246462464724648246492465024651246522465324654246552465624657246582465924660246612466224663246642466524666246672466824669246702467124672246732467424675246762467724678246792468024681246822468324684246852468624687246882468924690246912469224693246942469524696246972469824699247002470124702247032470424705247062470724708247092471024711247122471324714247152471624717247182471924720247212472224723247242472524726247272472824729247302473124732247332473424735247362473724738247392474024741247422474324744247452474624747247482474924750247512475224753247542475524756247572475824759247602476124762247632476424765247662476724768247692477024771247722477324774247752477624777247782477924780247812478224783247842478524786247872478824789247902479124792247932479424795247962479724798247992480024801248022480324804248052480624807248082480924810248112481224813248142481524816248172481824819248202482124822248232482424825248262482724828248292483024831248322483324834248352483624837248382483924840248412484224843248442484524846248472484824849248502485124852248532485424855248562485724858248592486024861248622486324864248652486624867248682486924870248712487224873248742487524876248772487824879248802488124882248832488424885248862488724888248892489024891248922489324894248952489624897248982489924900249012490224903249042490524906249072490824909249102491124912249132491424915249162491724918249192492024921249222492324924249252492624927249282492924930249312493224933249342493524936249372493824939249402494124942249432494424945249462494724948249492495024951249522495324954249552495624957249582495924960249612496224963249642496524966249672496824969249702497124972249732497424975249762497724978249792498024981249822498324984249852498624987249882498924990249912499224993249942499524996249972499824999250002500125002250032500425005250062500725008250092501025011250122501325014250152501625017250182501925020250212502225023250242502525026250272502825029250302503125032250332503425035250362503725038250392504025041250422504325044250452504625047250482504925050250512505225053250542505525056250572505825059250602506125062250632506425065250662506725068250692507025071250722507325074250752507625077250782507925080250812508225083250842508525086250872508825089250902509125092250932509425095250962509725098250992510025101251022510325104251052510625107251082510925110251112511225113251142511525116251172511825119251202512125122251232512425125251262512725128251292513025131251322513325134251352513625137251382513925140251412514225143251442514525146251472514825149251502515125152251532515425155251562515725158251592516025161251622516325164251652516625167251682516925170251712517225173251742517525176251772517825179251802518125182251832518425185251862518725188251892519025191251922519325194251952519625197251982519925200252012520225203252042520525206252072520825209252102521125212252132521425215252162521725218252192522025221252222522325224252252522625227252282522925230252312523225233252342523525236252372523825239252402524125242252432524425245252462524725248252492525025251252522525325254252552525625257252582525925260252612526225263252642526525266252672526825269252702527125272252732527425275252762527725278252792528025281252822528325284252852528625287252882528925290252912529225293252942529525296252972529825299253002530125302253032530425305253062530725308253092531025311253122531325314253152531625317253182531925320253212532225323253242532525326253272532825329253302533125332253332533425335253362533725338253392534025341253422534325344253452534625347253482534925350253512535225353253542535525356253572535825359253602536125362253632536425365253662536725368253692537025371253722537325374253752537625377253782537925380253812538225383253842538525386253872538825389253902539125392253932539425395253962539725398253992540025401254022540325404254052540625407254082540925410254112541225413254142541525416254172541825419254202542125422254232542425425254262542725428254292543025431254322543325434254352543625437254382543925440254412544225443254442544525446254472544825449254502545125452254532545425455254562545725458254592546025461254622546325464254652546625467254682546925470254712547225473254742547525476254772547825479254802548125482254832548425485254862548725488254892549025491254922549325494254952549625497254982549925500255012550225503255042550525506255072550825509255102551125512255132551425515255162551725518255192552025521255222552325524255252552625527255282552925530255312553225533255342553525536255372553825539255402554125542255432554425545255462554725548255492555025551255522555325554255552555625557255582555925560255612556225563255642556525566255672556825569255702557125572255732557425575255762557725578255792558025581255822558325584255852558625587255882558925590255912559225593255942559525596255972559825599256002560125602256032560425605256062560725608256092561025611256122561325614256152561625617256182561925620256212562225623256242562525626256272562825629256302563125632256332563425635256362563725638256392564025641256422564325644256452564625647256482564925650256512565225653256542565525656256572565825659256602566125662256632566425665256662566725668256692567025671256722567325674256752567625677256782567925680256812568225683256842568525686256872568825689256902569125692256932569425695256962569725698256992570025701257022570325704257052570625707257082570925710257112571225713257142571525716257172571825719257202572125722257232572425725257262572725728257292573025731257322573325734257352573625737257382573925740257412574225743257442574525746257472574825749257502575125752257532575425755257562575725758257592576025761257622576325764257652576625767257682576925770257712577225773257742577525776257772577825779257802578125782257832578425785257862578725788257892579025791257922579325794257952579625797257982579925800258012580225803258042580525806258072580825809258102581125812258132581425815258162581725818258192582025821258222582325824258252582625827258282582925830258312583225833258342583525836258372583825839258402584125842258432584425845258462584725848258492585025851258522585325854258552585625857258582585925860258612586225863258642586525866258672586825869258702587125872258732587425875258762587725878258792588025881258822588325884258852588625887258882588925890258912589225893258942589525896258972589825899259002590125902259032590425905259062590725908259092591025911259122591325914259152591625917259182591925920259212592225923259242592525926259272592825929259302593125932259332593425935259362593725938259392594025941259422594325944259452594625947259482594925950259512595225953259542595525956259572595825959259602596125962259632596425965259662596725968259692597025971259722597325974259752597625977259782597925980259812598225983259842598525986259872598825989259902599125992259932599425995259962599725998259992600026001260022600326004260052600626007260082600926010260112601226013260142601526016260172601826019260202602126022260232602426025260262602726028260292603026031260322603326034260352603626037260382603926040260412604226043260442604526046260472604826049260502605126052260532605426055260562605726058260592606026061260622606326064260652606626067260682606926070260712607226073260742607526076260772607826079260802608126082260832608426085260862608726088260892609026091260922609326094260952609626097260982609926100261012610226103261042610526106261072610826109261102611126112261132611426115261162611726118261192612026121261222612326124261252612626127261282612926130261312613226133261342613526136261372613826139261402614126142261432614426145261462614726148261492615026151261522615326154261552615626157261582615926160261612616226163261642616526166261672616826169261702617126172261732617426175261762617726178261792618026181261822618326184261852618626187261882618926190261912619226193261942619526196261972619826199262002620126202262032620426205262062620726208262092621026211262122621326214262152621626217262182621926220262212622226223262242622526226262272622826229262302623126232262332623426235262362623726238262392624026241262422624326244262452624626247262482624926250262512625226253262542625526256262572625826259262602626126262262632626426265262662626726268262692627026271262722627326274262752627626277262782627926280262812628226283262842628526286262872628826289262902629126292262932629426295262962629726298262992630026301263022630326304263052630626307263082630926310263112631226313263142631526316263172631826319263202632126322263232632426325263262632726328263292633026331263322633326334263352633626337263382633926340263412634226343263442634526346263472634826349263502635126352263532635426355263562635726358263592636026361263622636326364263652636626367263682636926370263712637226373263742637526376263772637826379263802638126382263832638426385263862638726388263892639026391263922639326394263952639626397263982639926400264012640226403264042640526406264072640826409264102641126412264132641426415264162641726418264192642026421264222642326424264252642626427264282642926430264312643226433264342643526436264372643826439264402644126442264432644426445264462644726448264492645026451264522645326454264552645626457264582645926460264612646226463264642646526466264672646826469264702647126472264732647426475264762647726478264792648026481264822648326484264852648626487264882648926490264912649226493264942649526496264972649826499265002650126502265032650426505265062650726508265092651026511265122651326514265152651626517265182651926520265212652226523265242652526526265272652826529265302653126532265332653426535265362653726538265392654026541265422654326544265452654626547265482654926550265512655226553265542655526556265572655826559265602656126562265632656426565265662656726568265692657026571265722657326574265752657626577265782657926580265812658226583265842658526586265872658826589265902659126592265932659426595265962659726598265992660026601266022660326604266052660626607266082660926610266112661226613266142661526616266172661826619266202662126622266232662426625266262662726628266292663026631266322663326634266352663626637266382663926640266412664226643266442664526646266472664826649266502665126652266532665426655266562665726658266592666026661266622666326664266652666626667266682666926670266712667226673266742667526676266772667826679266802668126682266832668426685266862668726688266892669026691266922669326694266952669626697266982669926700267012670226703267042670526706267072670826709267102671126712267132671426715267162671726718267192672026721267222672326724267252672626727267282672926730267312673226733267342673526736267372673826739267402674126742267432674426745267462674726748267492675026751267522675326754267552675626757267582675926760267612676226763267642676526766267672676826769267702677126772267732677426775267762677726778267792678026781267822678326784267852678626787267882678926790267912679226793267942679526796267972679826799268002680126802268032680426805268062680726808268092681026811268122681326814268152681626817268182681926820268212682226823268242682526826268272682826829268302683126832268332683426835268362683726838268392684026841268422684326844268452684626847268482684926850268512685226853268542685526856268572685826859268602686126862268632686426865268662686726868268692687026871268722687326874268752687626877268782687926880268812688226883268842688526886268872688826889268902689126892268932689426895268962689726898268992690026901269022690326904269052690626907269082690926910269112691226913269142691526916269172691826919269202692126922269232692426925269262692726928269292693026931269322693326934269352693626937269382693926940269412694226943269442694526946269472694826949269502695126952269532695426955269562695726958269592696026961269622696326964269652696626967269682696926970269712697226973269742697526976269772697826979269802698126982269832698426985269862698726988269892699026991269922699326994269952699626997269982699927000270012700227003270042700527006270072700827009270102701127012270132701427015270162701727018270192702027021270222702327024270252702627027270282702927030270312703227033270342703527036270372703827039270402704127042270432704427045270462704727048270492705027051270522705327054270552705627057270582705927060270612706227063270642706527066270672706827069270702707127072270732707427075270762707727078270792708027081270822708327084270852708627087270882708927090270912709227093270942709527096270972709827099271002710127102271032710427105271062710727108271092711027111271122711327114271152711627117271182711927120271212712227123271242712527126271272712827129271302713127132271332713427135271362713727138271392714027141271422714327144271452714627147271482714927150271512715227153271542715527156271572715827159271602716127162271632716427165271662716727168271692717027171271722717327174271752717627177271782717927180271812718227183271842718527186271872718827189271902719127192271932719427195271962719727198271992720027201272022720327204272052720627207272082720927210272112721227213272142721527216272172721827219272202722127222272232722427225272262722727228272292723027231272322723327234272352723627237272382723927240272412724227243272442724527246272472724827249272502725127252272532725427255272562725727258272592726027261272622726327264272652726627267272682726927270272712727227273272742727527276272772727827279272802728127282272832728427285272862728727288272892729027291272922729327294272952729627297272982729927300273012730227303273042730527306273072730827309273102731127312273132731427315273162731727318273192732027321273222732327324273252732627327273282732927330273312733227333273342733527336273372733827339273402734127342273432734427345273462734727348273492735027351273522735327354273552735627357273582735927360273612736227363273642736527366273672736827369273702737127372273732737427375273762737727378273792738027381273822738327384273852738627387273882738927390273912739227393273942739527396273972739827399274002740127402274032740427405274062740727408274092741027411274122741327414274152741627417274182741927420274212742227423274242742527426274272742827429274302743127432274332743427435274362743727438274392744027441274422744327444274452744627447274482744927450274512745227453274542745527456274572745827459274602746127462274632746427465274662746727468274692747027471274722747327474274752747627477274782747927480274812748227483274842748527486274872748827489274902749127492274932749427495274962749727498274992750027501275022750327504275052750627507275082750927510275112751227513275142751527516275172751827519275202752127522275232752427525275262752727528275292753027531275322753327534275352753627537275382753927540275412754227543275442754527546275472754827549275502755127552275532755427555275562755727558275592756027561275622756327564275652756627567275682756927570275712757227573275742757527576275772757827579275802758127582275832758427585275862758727588275892759027591275922759327594275952759627597275982759927600276012760227603276042760527606276072760827609276102761127612276132761427615276162761727618276192762027621276222762327624276252762627627276282762927630276312763227633276342763527636276372763827639276402764127642276432764427645276462764727648276492765027651276522765327654276552765627657276582765927660276612766227663276642766527666276672766827669276702767127672276732767427675276762767727678276792768027681276822768327684276852768627687276882768927690276912769227693276942769527696276972769827699277002770127702277032770427705277062770727708277092771027711277122771327714277152771627717277182771927720277212772227723277242772527726277272772827729277302773127732277332773427735277362773727738277392774027741277422774327744277452774627747277482774927750277512775227753277542775527756277572775827759277602776127762277632776427765277662776727768277692777027771277722777327774277752777627777277782777927780277812778227783277842778527786277872778827789277902779127792277932779427795277962779727798277992780027801278022780327804278052780627807278082780927810278112781227813278142781527816278172781827819278202782127822278232782427825278262782727828278292783027831278322783327834278352783627837278382783927840278412784227843278442784527846278472784827849278502785127852278532785427855278562785727858278592786027861278622786327864278652786627867278682786927870278712787227873278742787527876278772787827879278802788127882278832788427885278862788727888278892789027891278922789327894278952789627897278982789927900279012790227903279042790527906279072790827909279102791127912279132791427915279162791727918279192792027921279222792327924279252792627927279282792927930279312793227933279342793527936279372793827939279402794127942279432794427945279462794727948279492795027951279522795327954279552795627957279582795927960279612796227963279642796527966279672796827969279702797127972279732797427975279762797727978279792798027981279822798327984279852798627987279882798927990279912799227993279942799527996279972799827999280002800128002280032800428005280062800728008280092801028011280122801328014280152801628017280182801928020280212802228023280242802528026280272802828029280302803128032280332803428035280362803728038280392804028041280422804328044280452804628047280482804928050280512805228053280542805528056280572805828059280602806128062280632806428065280662806728068280692807028071280722807328074280752807628077280782807928080280812808228083280842808528086280872808828089280902809128092280932809428095280962809728098280992810028101281022810328104281052810628107281082810928110281112811228113281142811528116281172811828119281202812128122281232812428125281262812728128281292813028131281322813328134281352813628137281382813928140281412814228143281442814528146281472814828149281502815128152281532815428155281562815728158281592816028161281622816328164281652816628167281682816928170281712817228173281742817528176281772817828179281802818128182281832818428185281862818728188281892819028191281922819328194281952819628197281982819928200282012820228203282042820528206282072820828209282102821128212282132821428215282162821728218282192822028221282222822328224282252822628227282282822928230282312823228233282342823528236282372823828239282402824128242282432824428245282462824728248282492825028251282522825328254282552825628257282582825928260282612826228263282642826528266282672826828269282702827128272282732827428275282762827728278282792828028281282822828328284282852828628287282882828928290282912829228293282942829528296282972829828299283002830128302283032830428305283062830728308283092831028311283122831328314283152831628317283182831928320283212832228323283242832528326283272832828329283302833128332283332833428335283362833728338283392834028341283422834328344283452834628347283482834928350283512835228353283542835528356283572835828359283602836128362283632836428365283662836728368283692837028371283722837328374283752837628377283782837928380283812838228383283842838528386283872838828389283902839128392283932839428395283962839728398283992840028401284022840328404284052840628407284082840928410284112841228413284142841528416284172841828419284202842128422284232842428425284262842728428284292843028431284322843328434284352843628437284382843928440284412844228443284442844528446284472844828449284502845128452284532845428455284562845728458284592846028461284622846328464284652846628467284682846928470284712847228473284742847528476284772847828479284802848128482284832848428485284862848728488284892849028491284922849328494284952849628497284982849928500285012850228503285042850528506285072850828509285102851128512285132851428515285162851728518285192852028521285222852328524285252852628527285282852928530285312853228533285342853528536285372853828539285402854128542285432854428545285462854728548285492855028551285522855328554285552855628557285582855928560285612856228563285642856528566285672856828569285702857128572285732857428575285762857728578285792858028581285822858328584285852858628587285882858928590285912859228593285942859528596285972859828599286002860128602286032860428605286062860728608286092861028611286122861328614286152861628617286182861928620286212862228623286242862528626286272862828629286302863128632286332863428635286362863728638286392864028641286422864328644286452864628647286482864928650286512865228653286542865528656286572865828659286602866128662286632866428665286662866728668286692867028671286722867328674286752867628677286782867928680286812868228683286842868528686286872868828689286902869128692286932869428695286962869728698286992870028701287022870328704287052870628707287082870928710287112871228713287142871528716287172871828719287202872128722287232872428725287262872728728287292873028731287322873328734287352873628737287382873928740287412874228743287442874528746287472874828749287502875128752287532875428755287562875728758287592876028761287622876328764287652876628767287682876928770287712877228773287742877528776287772877828779287802878128782287832878428785287862878728788287892879028791287922879328794287952879628797287982879928800288012880228803288042880528806288072880828809288102881128812288132881428815288162881728818288192882028821288222882328824288252882628827288282882928830288312883228833288342883528836288372883828839288402884128842288432884428845288462884728848288492885028851288522885328854288552885628857288582885928860288612886228863288642886528866288672886828869288702887128872288732887428875288762887728878288792888028881288822888328884288852888628887288882888928890288912889228893288942889528896288972889828899289002890128902289032890428905289062890728908289092891028911289122891328914289152891628917289182891928920289212892228923289242892528926289272892828929289302893128932289332893428935289362893728938289392894028941289422894328944289452894628947289482894928950289512895228953289542895528956289572895828959289602896128962289632896428965289662896728968289692897028971289722897328974289752897628977289782897928980289812898228983289842898528986289872898828989289902899128992289932899428995289962899728998289992900029001290022900329004290052900629007290082900929010290112901229013290142901529016290172901829019290202902129022290232902429025290262902729028290292903029031290322903329034290352903629037290382903929040290412904229043290442904529046290472904829049290502905129052290532905429055290562905729058290592906029061290622906329064290652906629067290682906929070290712907229073290742907529076290772907829079290802908129082290832908429085290862908729088290892909029091290922909329094290952909629097290982909929100291012910229103291042910529106291072910829109291102911129112291132911429115291162911729118291192912029121291222912329124291252912629127291282912929130291312913229133291342913529136291372913829139291402914129142291432914429145291462914729148291492915029151291522915329154291552915629157291582915929160291612916229163291642916529166291672916829169291702917129172291732917429175291762917729178291792918029181291822918329184291852918629187291882918929190291912919229193291942919529196291972919829199292002920129202292032920429205292062920729208292092921029211292122921329214292152921629217292182921929220292212922229223292242922529226292272922829229292302923129232292332923429235292362923729238292392924029241292422924329244292452924629247292482924929250292512925229253292542925529256292572925829259292602926129262292632926429265292662926729268292692927029271292722927329274292752927629277292782927929280292812928229283292842928529286292872928829289292902929129292292932929429295292962929729298292992930029301293022930329304293052930629307293082930929310293112931229313293142931529316293172931829319293202932129322293232932429325293262932729328293292933029331293322933329334293352933629337293382933929340293412934229343293442934529346293472934829349293502935129352293532935429355293562935729358293592936029361293622936329364293652936629367293682936929370293712937229373293742937529376293772937829379293802938129382293832938429385293862938729388293892939029391293922939329394293952939629397293982939929400294012940229403294042940529406294072940829409294102941129412294132941429415294162941729418294192942029421294222942329424294252942629427294282942929430294312943229433294342943529436294372943829439294402944129442294432944429445294462944729448294492945029451294522945329454294552945629457294582945929460294612946229463294642946529466294672946829469294702947129472294732947429475294762947729478294792948029481294822948329484294852948629487294882948929490294912949229493294942949529496294972949829499295002950129502295032950429505295062950729508295092951029511295122951329514295152951629517295182951929520295212952229523295242952529526295272952829529295302953129532295332953429535295362953729538295392954029541295422954329544295452954629547295482954929550295512955229553295542955529556295572955829559295602956129562295632956429565295662956729568295692957029571295722957329574295752957629577295782957929580295812958229583295842958529586295872958829589295902959129592295932959429595295962959729598295992960029601296022960329604296052960629607296082960929610296112961229613296142961529616296172961829619296202962129622296232962429625296262962729628296292963029631296322963329634296352963629637296382963929640296412964229643296442964529646296472964829649296502965129652296532965429655296562965729658296592966029661296622966329664296652966629667296682966929670296712967229673296742967529676296772967829679296802968129682296832968429685296862968729688296892969029691296922969329694296952969629697296982969929700297012970229703297042970529706297072970829709297102971129712297132971429715297162971729718297192972029721297222972329724297252972629727297282972929730297312973229733297342973529736297372973829739297402974129742297432974429745297462974729748297492975029751297522975329754297552975629757297582975929760297612976229763297642976529766297672976829769297702977129772297732977429775297762977729778297792978029781297822978329784297852978629787297882978929790297912979229793297942979529796297972979829799298002980129802298032980429805298062980729808298092981029811298122981329814298152981629817298182981929820298212982229823298242982529826298272982829829298302983129832298332983429835298362983729838298392984029841298422984329844298452984629847298482984929850298512985229853298542985529856298572985829859298602986129862298632986429865298662986729868298692987029871298722987329874298752987629877298782987929880298812988229883298842988529886298872988829889298902989129892298932989429895298962989729898298992990029901299022990329904299052990629907299082990929910299112991229913299142991529916299172991829919299202992129922299232992429925299262992729928299292993029931299322993329934299352993629937299382993929940299412994229943299442994529946299472994829949299502995129952299532995429955299562995729958299592996029961299622996329964299652996629967299682996929970299712997229973299742997529976299772997829979299802998129982299832998429985299862998729988299892999029991299922999329994299952999629997299982999930000300013000230003300043000530006300073000830009300103001130012300133001430015300163001730018300193002030021300223002330024300253002630027300283002930030300313003230033300343003530036300373003830039300403004130042300433004430045300463004730048300493005030051300523005330054300553005630057300583005930060300613006230063300643006530066300673006830069300703007130072300733007430075300763007730078300793008030081300823008330084300853008630087300883008930090300913009230093300943009530096300973009830099301003010130102301033010430105301063010730108301093011030111301123011330114301153011630117301183011930120301213012230123301243012530126301273012830129301303013130132301333013430135301363013730138301393014030141301423014330144301453014630147301483014930150301513015230153301543015530156301573015830159301603016130162301633016430165301663016730168301693017030171301723017330174301753017630177301783017930180301813018230183301843018530186301873018830189301903019130192301933019430195301963019730198301993020030201302023020330204302053020630207302083020930210302113021230213302143021530216302173021830219302203022130222302233022430225302263022730228302293023030231302323023330234302353023630237302383023930240302413024230243302443024530246302473024830249302503025130252302533025430255302563025730258302593026030261302623026330264302653026630267302683026930270302713027230273302743027530276302773027830279302803028130282302833028430285302863028730288302893029030291302923029330294302953029630297302983029930300303013030230303303043030530306303073030830309303103031130312303133031430315303163031730318303193032030321303223032330324303253032630327303283032930330303313033230333303343033530336303373033830339303403034130342303433034430345303463034730348303493035030351303523035330354303553035630357303583035930360303613036230363303643036530366303673036830369303703037130372303733037430375303763037730378303793038030381303823038330384303853038630387303883038930390303913039230393303943039530396303973039830399304003040130402304033040430405304063040730408304093041030411304123041330414304153041630417304183041930420304213042230423304243042530426304273042830429304303043130432304333043430435304363043730438304393044030441304423044330444304453044630447304483044930450304513045230453304543045530456304573045830459304603046130462304633046430465304663046730468304693047030471304723047330474304753047630477304783047930480304813048230483304843048530486304873048830489304903049130492304933049430495304963049730498304993050030501305023050330504305053050630507305083050930510305113051230513305143051530516305173051830519305203052130522305233052430525305263052730528305293053030531305323053330534305353053630537305383053930540305413054230543305443054530546305473054830549305503055130552305533055430555305563055730558305593056030561305623056330564305653056630567305683056930570305713057230573305743057530576305773057830579305803058130582305833058430585305863058730588305893059030591305923059330594305953059630597305983059930600306013060230603306043060530606306073060830609306103061130612306133061430615306163061730618306193062030621306223062330624306253062630627306283062930630306313063230633306343063530636306373063830639306403064130642306433064430645306463064730648306493065030651306523065330654306553065630657306583065930660306613066230663306643066530666306673066830669306703067130672306733067430675306763067730678306793068030681306823068330684306853068630687306883068930690306913069230693306943069530696306973069830699307003070130702307033070430705307063070730708307093071030711307123071330714307153071630717307183071930720307213072230723307243072530726307273072830729307303073130732307333073430735307363073730738307393074030741307423074330744307453074630747307483074930750307513075230753307543075530756307573075830759307603076130762307633076430765307663076730768307693077030771307723077330774307753077630777307783077930780307813078230783307843078530786307873078830789307903079130792307933079430795307963079730798307993080030801308023080330804308053080630807308083080930810308113081230813308143081530816308173081830819308203082130822308233082430825308263082730828308293083030831308323083330834308353083630837308383083930840308413084230843308443084530846308473084830849308503085130852308533085430855308563085730858308593086030861308623086330864308653086630867308683086930870308713087230873308743087530876308773087830879308803088130882308833088430885308863088730888308893089030891308923089330894308953089630897308983089930900309013090230903309043090530906309073090830909309103091130912309133091430915309163091730918309193092030921309223092330924309253092630927309283092930930309313093230933309343093530936309373093830939309403094130942309433094430945309463094730948309493095030951309523095330954309553095630957309583095930960309613096230963309643096530966309673096830969309703097130972309733097430975309763097730978309793098030981309823098330984309853098630987309883098930990309913099230993309943099530996309973099830999310003100131002310033100431005310063100731008310093101031011310123101331014310153101631017310183101931020310213102231023310243102531026310273102831029310303103131032310333103431035310363103731038310393104031041310423104331044310453104631047310483104931050310513105231053310543105531056310573105831059310603106131062310633106431065310663106731068310693107031071310723107331074310753107631077310783107931080310813108231083310843108531086310873108831089310903109131092310933109431095310963109731098310993110031101311023110331104311053110631107311083110931110311113111231113311143111531116311173111831119311203112131122311233112431125311263112731128311293113031131311323113331134311353113631137311383113931140311413114231143311443114531146311473114831149311503115131152311533115431155311563115731158311593116031161311623116331164311653116631167311683116931170311713117231173311743117531176311773117831179311803118131182311833118431185311863118731188311893119031191311923119331194311953119631197311983119931200312013120231203312043120531206312073120831209312103121131212312133121431215312163121731218312193122031221312223122331224312253122631227312283122931230312313123231233312343123531236312373123831239312403124131242312433124431245312463124731248312493125031251312523125331254312553125631257312583125931260312613126231263312643126531266312673126831269312703127131272312733127431275312763127731278312793128031281312823128331284312853128631287312883128931290312913129231293312943129531296312973129831299313003130131302313033130431305313063130731308313093131031311313123131331314313153131631317313183131931320313213132231323313243132531326313273132831329313303133131332313333133431335313363133731338313393134031341313423134331344313453134631347313483134931350313513135231353313543135531356313573135831359313603136131362313633136431365313663136731368313693137031371313723137331374313753137631377313783137931380313813138231383313843138531386313873138831389313903139131392313933139431395313963139731398313993140031401314023140331404314053140631407314083140931410314113141231413314143141531416314173141831419314203142131422314233142431425314263142731428314293143031431314323143331434314353143631437314383143931440314413144231443314443144531446314473144831449314503145131452314533145431455314563145731458314593146031461314623146331464314653146631467314683146931470314713147231473314743147531476314773147831479314803148131482314833148431485314863148731488314893149031491314923149331494314953149631497314983149931500315013150231503315043150531506315073150831509315103151131512315133151431515315163151731518315193152031521315223152331524315253152631527315283152931530315313153231533315343153531536315373153831539315403154131542315433154431545315463154731548315493155031551315523155331554315553155631557315583155931560315613156231563315643156531566315673156831569315703157131572315733157431575315763157731578315793158031581315823158331584315853158631587315883158931590315913159231593315943159531596315973159831599316003160131602316033160431605316063160731608316093161031611316123161331614316153161631617316183161931620316213162231623316243162531626316273162831629316303163131632316333163431635316363163731638316393164031641316423164331644316453164631647316483164931650316513165231653316543165531656316573165831659316603166131662316633166431665316663166731668316693167031671316723167331674316753167631677316783167931680316813168231683316843168531686316873168831689316903169131692316933169431695316963169731698316993170031701317023170331704317053170631707317083170931710317113171231713317143171531716317173171831719317203172131722317233172431725317263172731728317293173031731317323173331734317353173631737317383173931740317413174231743317443174531746317473174831749317503175131752317533175431755317563175731758317593176031761317623176331764317653176631767317683176931770317713177231773317743177531776317773177831779317803178131782317833178431785317863178731788317893179031791317923179331794317953179631797317983179931800318013180231803318043180531806318073180831809318103181131812318133181431815318163181731818318193182031821318223182331824318253182631827318283182931830318313183231833318343183531836318373183831839318403184131842318433184431845318463184731848318493185031851318523185331854318553185631857318583185931860318613186231863318643186531866318673186831869318703187131872318733187431875318763187731878318793188031881318823188331884318853188631887318883188931890318913189231893318943189531896318973189831899319003190131902319033190431905319063190731908319093191031911319123191331914319153191631917319183191931920319213192231923319243192531926319273192831929319303193131932319333193431935319363193731938319393194031941319423194331944319453194631947319483194931950319513195231953319543195531956319573195831959319603196131962319633196431965319663196731968319693197031971319723197331974319753197631977319783197931980319813198231983319843198531986319873198831989319903199131992319933199431995319963199731998319993200032001320023200332004320053200632007320083200932010320113201232013320143201532016320173201832019320203202132022320233202432025320263202732028320293203032031320323203332034320353203632037320383203932040320413204232043320443204532046320473204832049320503205132052320533205432055320563205732058320593206032061320623206332064320653206632067320683206932070320713207232073320743207532076320773207832079320803208132082320833208432085320863208732088320893209032091320923209332094320953209632097320983209932100321013210232103321043210532106321073210832109321103211132112321133211432115321163211732118321193212032121321223212332124321253212632127321283212932130321313213232133321343213532136321373213832139321403214132142321433214432145321463214732148321493215032151321523215332154321553215632157321583215932160321613216232163321643216532166321673216832169321703217132172321733217432175321763217732178321793218032181321823218332184321853218632187321883218932190321913219232193321943219532196321973219832199322003220132202322033220432205322063220732208322093221032211322123221332214322153221632217322183221932220322213222232223322243222532226322273222832229322303223132232322333223432235322363223732238322393224032241322423224332244322453224632247322483224932250322513225232253322543225532256322573225832259322603226132262322633226432265322663226732268322693227032271322723227332274322753227632277322783227932280322813228232283322843228532286322873228832289322903229132292322933229432295322963229732298322993230032301323023230332304323053230632307323083230932310323113231232313323143231532316323173231832319323203232132322323233232432325323263232732328323293233032331323323233332334323353233632337323383233932340323413234232343323443234532346323473234832349323503235132352323533235432355323563235732358323593236032361323623236332364323653236632367323683236932370323713237232373323743237532376323773237832379323803238132382323833238432385323863238732388323893239032391323923239332394323953239632397323983239932400324013240232403324043240532406324073240832409324103241132412324133241432415324163241732418324193242032421324223242332424324253242632427324283242932430324313243232433324343243532436324373243832439324403244132442324433244432445324463244732448324493245032451324523245332454324553245632457324583245932460324613246232463324643246532466324673246832469324703247132472324733247432475324763247732478324793248032481324823248332484324853248632487324883248932490324913249232493324943249532496324973249832499325003250132502325033250432505325063250732508325093251032511325123251332514325153251632517325183251932520325213252232523325243252532526325273252832529325303253132532325333253432535325363253732538325393254032541325423254332544325453254632547325483254932550325513255232553325543255532556325573255832559325603256132562325633256432565325663256732568325693257032571325723257332574325753257632577325783257932580325813258232583325843258532586325873258832589325903259132592325933259432595325963259732598325993260032601326023260332604326053260632607326083260932610326113261232613326143261532616326173261832619326203262132622326233262432625326263262732628326293263032631326323263332634326353263632637326383263932640326413264232643326443264532646326473264832649326503265132652326533265432655326563265732658326593266032661326623266332664326653266632667326683266932670326713267232673326743267532676326773267832679326803268132682326833268432685326863268732688326893269032691326923269332694326953269632697326983269932700327013270232703327043270532706327073270832709327103271132712327133271432715327163271732718327193272032721327223272332724327253272632727327283272932730327313273232733327343273532736327373273832739327403274132742327433274432745327463274732748327493275032751327523275332754327553275632757327583275932760327613276232763327643276532766327673276832769327703277132772327733277432775327763277732778327793278032781327823278332784327853278632787327883278932790327913279232793327943279532796327973279832799328003280132802328033280432805328063280732808328093281032811328123281332814328153281632817328183281932820328213282232823328243282532826328273282832829328303283132832328333283432835328363283732838328393284032841328423284332844328453284632847328483284932850328513285232853328543285532856328573285832859328603286132862328633286432865328663286732868328693287032871328723287332874328753287632877328783287932880328813288232883328843288532886328873288832889328903289132892328933289432895328963289732898328993290032901329023290332904329053290632907329083290932910329113291232913329143291532916329173291832919329203292132922329233292432925329263292732928329293293032931329323293332934329353293632937329383293932940329413294232943329443294532946329473294832949329503295132952329533295432955329563295732958329593296032961329623296332964329653296632967329683296932970329713297232973329743297532976329773297832979329803298132982329833298432985329863298732988329893299032991329923299332994329953299632997329983299933000330013300233003330043300533006330073300833009330103301133012330133301433015330163301733018330193302033021330223302333024330253302633027330283302933030330313303233033330343303533036330373303833039330403304133042330433304433045330463304733048330493305033051330523305333054330553305633057330583305933060330613306233063330643306533066330673306833069330703307133072330733307433075330763307733078330793308033081330823308333084330853308633087330883308933090330913309233093330943309533096330973309833099331003310133102331033310433105331063310733108331093311033111331123311333114331153311633117331183311933120331213312233123331243312533126331273312833129331303313133132331333313433135331363313733138331393314033141331423314333144331453314633147331483314933150331513315233153331543315533156331573315833159331603316133162331633316433165331663316733168331693317033171331723317333174331753317633177331783317933180331813318233183331843318533186331873318833189331903319133192331933319433195331963319733198331993320033201332023320333204332053320633207332083320933210332113321233213332143321533216332173321833219332203322133222332233322433225332263322733228332293323033231332323323333234332353323633237332383323933240332413324233243332443324533246332473324833249332503325133252332533325433255332563325733258332593326033261332623326333264332653326633267332683326933270332713327233273332743327533276332773327833279332803328133282332833328433285332863328733288332893329033291332923329333294332953329633297332983329933300333013330233303333043330533306333073330833309333103331133312333133331433315333163331733318333193332033321333223332333324333253332633327333283332933330333313333233333333343333533336333373333833339333403334133342333433334433345333463334733348333493335033351333523335333354333553335633357333583335933360333613336233363333643336533366333673336833369333703337133372333733337433375333763337733378333793338033381333823338333384333853338633387333883338933390333913339233393333943339533396333973339833399334003340133402334033340433405334063340733408334093341033411334123341333414334153341633417334183341933420334213342233423334243342533426334273342833429334303343133432334333343433435334363343733438334393344033441334423344333444334453344633447334483344933450334513345233453334543345533456334573345833459334603346133462334633346433465334663346733468334693347033471334723347333474334753347633477334783347933480334813348233483334843348533486334873348833489334903349133492334933349433495334963349733498334993350033501335023350333504335053350633507335083350933510335113351233513335143351533516335173351833519335203352133522335233352433525335263352733528335293353033531335323353333534335353353633537335383353933540335413354233543335443354533546335473354833549335503355133552335533355433555335563355733558335593356033561335623356333564335653356633567335683356933570335713357233573335743357533576335773357833579335803358133582335833358433585335863358733588335893359033591335923359333594335953359633597335983359933600336013360233603336043360533606336073360833609336103361133612336133361433615336163361733618336193362033621336223362333624336253362633627336283362933630336313363233633336343363533636336373363833639336403364133642336433364433645336463364733648336493365033651336523365333654336553365633657336583365933660336613366233663336643366533666336673366833669336703367133672336733367433675336763367733678336793368033681336823368333684336853368633687336883368933690336913369233693336943369533696336973369833699337003370133702337033370433705337063370733708337093371033711337123371333714337153371633717337183371933720337213372233723337243372533726337273372833729337303373133732337333373433735337363373733738337393374033741337423374333744337453374633747337483374933750337513375233753337543375533756337573375833759337603376133762337633376433765337663376733768337693377033771337723377333774337753377633777337783377933780337813378233783337843378533786337873378833789337903379133792337933379433795337963379733798337993380033801338023380333804338053380633807338083380933810338113381233813338143381533816338173381833819338203382133822338233382433825338263382733828338293383033831338323383333834338353383633837338383383933840338413384233843338443384533846338473384833849338503385133852338533385433855338563385733858338593386033861338623386333864338653386633867338683386933870338713387233873338743387533876338773387833879338803388133882338833388433885338863388733888338893389033891338923389333894338953389633897338983389933900339013390233903339043390533906339073390833909339103391133912339133391433915339163391733918339193392033921339223392333924339253392633927339283392933930339313393233933339343393533936339373393833939339403394133942339433394433945339463394733948339493395033951339523395333954339553395633957339583395933960339613396233963339643396533966339673396833969339703397133972339733397433975339763397733978339793398033981339823398333984339853398633987339883398933990339913399233993339943399533996339973399833999340003400134002340033400434005340063400734008340093401034011340123401334014340153401634017340183401934020340213402234023340243402534026340273402834029340303403134032340333403434035340363403734038340393404034041340423404334044340453404634047340483404934050340513405234053340543405534056340573405834059340603406134062340633406434065340663406734068340693407034071340723407334074340753407634077340783407934080340813408234083340843408534086340873408834089340903409134092340933409434095340963409734098340993410034101341023410334104341053410634107341083410934110341113411234113341143411534116341173411834119341203412134122341233412434125341263412734128341293413034131341323413334134341353413634137341383413934140341413414234143341443414534146341473414834149341503415134152341533415434155341563415734158341593416034161341623416334164341653416634167341683416934170341713417234173341743417534176341773417834179341803418134182341833418434185341863418734188341893419034191341923419334194341953419634197341983419934200342013420234203342043420534206342073420834209342103421134212342133421434215342163421734218342193422034221342223422334224342253422634227342283422934230342313423234233342343423534236342373423834239342403424134242342433424434245342463424734248342493425034251342523425334254342553425634257342583425934260342613426234263342643426534266342673426834269342703427134272342733427434275342763427734278342793428034281342823428334284342853428634287342883428934290342913429234293342943429534296342973429834299343003430134302343033430434305343063430734308343093431034311343123431334314343153431634317343183431934320343213432234323343243432534326343273432834329343303433134332343333433434335343363433734338343393434034341343423434334344343453434634347343483434934350343513435234353343543435534356343573435834359343603436134362343633436434365343663436734368343693437034371343723437334374343753437634377343783437934380343813438234383343843438534386343873438834389343903439134392343933439434395343963439734398343993440034401344023440334404344053440634407344083440934410344113441234413344143441534416344173441834419344203442134422344233442434425344263442734428344293443034431344323443334434344353443634437344383443934440344413444234443344443444534446344473444834449344503445134452344533445434455344563445734458344593446034461344623446334464344653446634467344683446934470344713447234473344743447534476344773447834479344803448134482344833448434485344863448734488344893449034491344923449334494344953449634497344983449934500345013450234503345043450534506345073450834509345103451134512345133451434515345163451734518345193452034521345223452334524345253452634527345283452934530345313453234533345343453534536345373453834539345403454134542345433454434545345463454734548345493455034551345523455334554345553455634557345583455934560345613456234563345643456534566345673456834569345703457134572345733457434575345763457734578345793458034581345823458334584345853458634587345883458934590345913459234593345943459534596345973459834599346003460134602346033460434605346063460734608346093461034611346123461334614346153461634617346183461934620346213462234623346243462534626346273462834629346303463134632346333463434635346363463734638346393464034641346423464334644346453464634647346483464934650346513465234653346543465534656346573465834659346603466134662346633466434665346663466734668346693467034671346723467334674346753467634677346783467934680346813468234683346843468534686346873468834689346903469134692346933469434695346963469734698346993470034701347023470334704347053470634707347083470934710347113471234713347143471534716347173471834719347203472134722347233472434725347263472734728347293473034731347323473334734347353473634737347383473934740347413474234743347443474534746347473474834749347503475134752347533475434755347563475734758347593476034761347623476334764347653476634767347683476934770347713477234773347743477534776347773477834779347803478134782347833478434785347863478734788347893479034791347923479334794347953479634797347983479934800348013480234803348043480534806348073480834809348103481134812348133481434815348163481734818348193482034821348223482334824348253482634827348283482934830348313483234833348343483534836348373483834839348403484134842348433484434845348463484734848348493485034851348523485334854348553485634857348583485934860348613486234863348643486534866348673486834869348703487134872348733487434875348763487734878348793488034881348823488334884348853488634887348883488934890348913489234893348943489534896348973489834899349003490134902349033490434905349063490734908349093491034911349123491334914349153491634917349183491934920349213492234923349243492534926349273492834929349303493134932349333493434935349363493734938349393494034941349423494334944349453494634947349483494934950349513495234953349543495534956349573495834959349603496134962349633496434965349663496734968349693497034971349723497334974349753497634977349783497934980349813498234983349843498534986349873498834989349903499134992349933499434995349963499734998349993500035001350023500335004350053500635007350083500935010350113501235013350143501535016350173501835019350203502135022350233502435025350263502735028350293503035031350323503335034350353503635037350383503935040350413504235043350443504535046350473504835049350503505135052350533505435055350563505735058350593506035061350623506335064350653506635067350683506935070350713507235073350743507535076350773507835079350803508135082350833508435085350863508735088350893509035091350923509335094350953509635097350983509935100351013510235103351043510535106351073510835109351103511135112351133511435115351163511735118351193512035121351223512335124351253512635127351283512935130351313513235133351343513535136351373513835139351403514135142351433514435145351463514735148351493515035151351523515335154351553515635157351583515935160351613516235163351643516535166351673516835169351703517135172351733517435175351763517735178351793518035181351823518335184351853518635187351883518935190351913519235193351943519535196351973519835199352003520135202352033520435205352063520735208352093521035211352123521335214352153521635217352183521935220352213522235223352243522535226352273522835229352303523135232352333523435235352363523735238352393524035241352423524335244352453524635247352483524935250352513525235253352543525535256352573525835259352603526135262352633526435265352663526735268352693527035271352723527335274352753527635277352783527935280352813528235283352843528535286352873528835289352903529135292352933529435295352963529735298352993530035301353023530335304353053530635307353083530935310353113531235313353143531535316353173531835319353203532135322353233532435325353263532735328353293533035331353323533335334353353533635337353383533935340353413534235343353443534535346353473534835349353503535135352353533535435355353563535735358353593536035361353623536335364353653536635367353683536935370353713537235373353743537535376353773537835379353803538135382353833538435385353863538735388353893539035391353923539335394353953539635397353983539935400354013540235403354043540535406354073540835409354103541135412354133541435415354163541735418354193542035421354223542335424354253542635427354283542935430354313543235433354343543535436354373543835439354403544135442354433544435445354463544735448354493545035451354523545335454354553545635457354583545935460354613546235463354643546535466354673546835469354703547135472354733547435475354763547735478354793548035481354823548335484354853548635487354883548935490354913549235493354943549535496354973549835499355003550135502355033550435505355063550735508355093551035511355123551335514355153551635517355183551935520355213552235523355243552535526355273552835529355303553135532355333553435535355363553735538355393554035541355423554335544355453554635547355483554935550355513555235553355543555535556355573555835559355603556135562355633556435565355663556735568355693557035571355723557335574355753557635577355783557935580355813558235583355843558535586355873558835589355903559135592355933559435595355963559735598355993560035601356023560335604356053560635607356083560935610356113561235613356143561535616356173561835619356203562135622356233562435625356263562735628356293563035631356323563335634356353563635637356383563935640356413564235643356443564535646356473564835649356503565135652356533565435655356563565735658356593566035661356623566335664356653566635667356683566935670356713567235673356743567535676356773567835679356803568135682356833568435685356863568735688356893569035691356923569335694356953569635697356983569935700357013570235703357043570535706357073570835709357103571135712357133571435715357163571735718357193572035721357223572335724357253572635727357283572935730357313573235733357343573535736357373573835739357403574135742357433574435745357463574735748357493575035751357523575335754357553575635757357583575935760357613576235763357643576535766357673576835769357703577135772357733577435775357763577735778357793578035781357823578335784357853578635787357883578935790357913579235793357943579535796357973579835799358003580135802358033580435805358063580735808358093581035811358123581335814358153581635817358183581935820358213582235823358243582535826358273582835829358303583135832358333583435835358363583735838358393584035841358423584335844358453584635847358483584935850358513585235853358543585535856358573585835859358603586135862358633586435865358663586735868358693587035871358723587335874358753587635877358783587935880358813588235883358843588535886358873588835889358903589135892358933589435895358963589735898358993590035901359023590335904359053590635907359083590935910359113591235913359143591535916359173591835919359203592135922359233592435925359263592735928359293593035931359323593335934359353593635937359383593935940359413594235943359443594535946359473594835949359503595135952359533595435955359563595735958359593596035961359623596335964359653596635967359683596935970359713597235973359743597535976359773597835979359803598135982359833598435985359863598735988359893599035991359923599335994359953599635997359983599936000360013600236003360043600536006360073600836009360103601136012360133601436015360163601736018360193602036021360223602336024360253602636027360283602936030360313603236033360343603536036360373603836039360403604136042360433604436045360463604736048360493605036051360523605336054360553605636057360583605936060360613606236063360643606536066360673606836069360703607136072360733607436075360763607736078360793608036081360823608336084360853608636087360883608936090360913609236093360943609536096360973609836099361003610136102361033610436105361063610736108361093611036111361123611336114361153611636117361183611936120361213612236123361243612536126361273612836129361303613136132361333613436135361363613736138361393614036141361423614336144361453614636147361483614936150361513615236153361543615536156361573615836159361603616136162361633616436165361663616736168361693617036171361723617336174361753617636177361783617936180361813618236183361843618536186361873618836189361903619136192361933619436195361963619736198361993620036201362023620336204362053620636207362083620936210362113621236213362143621536216362173621836219362203622136222362233622436225362263622736228362293623036231362323623336234362353623636237362383623936240362413624236243362443624536246362473624836249362503625136252362533625436255362563625736258362593626036261362623626336264362653626636267362683626936270362713627236273362743627536276362773627836279362803628136282362833628436285362863628736288362893629036291362923629336294362953629636297362983629936300363013630236303363043630536306363073630836309363103631136312363133631436315363163631736318363193632036321363223632336324363253632636327363283632936330363313633236333363343633536336363373633836339363403634136342363433634436345363463634736348363493635036351363523635336354363553635636357363583635936360363613636236363363643636536366363673636836369363703637136372363733637436375363763637736378363793638036381363823638336384363853638636387363883638936390363913639236393363943639536396363973639836399364003640136402364033640436405364063640736408364093641036411364123641336414364153641636417364183641936420364213642236423364243642536426364273642836429364303643136432364333643436435364363643736438364393644036441364423644336444364453644636447364483644936450364513645236453364543645536456364573645836459364603646136462364633646436465364663646736468364693647036471364723647336474364753647636477364783647936480364813648236483364843648536486364873648836489364903649136492364933649436495364963649736498364993650036501365023650336504365053650636507365083650936510365113651236513365143651536516365173651836519365203652136522365233652436525365263652736528365293653036531365323653336534365353653636537365383653936540365413654236543365443654536546365473654836549365503655136552365533655436555365563655736558365593656036561365623656336564365653656636567365683656936570365713657236573365743657536576365773657836579365803658136582365833658436585365863658736588365893659036591365923659336594365953659636597365983659936600366013660236603366043660536606366073660836609366103661136612366133661436615366163661736618366193662036621366223662336624366253662636627366283662936630366313663236633366343663536636366373663836639366403664136642366433664436645366463664736648366493665036651366523665336654366553665636657366583665936660366613666236663366643666536666366673666836669366703667136672366733667436675366763667736678366793668036681366823668336684366853668636687366883668936690366913669236693366943669536696366973669836699367003670136702367033670436705367063670736708367093671036711367123671336714367153671636717367183671936720367213672236723367243672536726367273672836729367303673136732367333673436735367363673736738367393674036741367423674336744367453674636747367483674936750367513675236753367543675536756367573675836759367603676136762367633676436765367663676736768367693677036771367723677336774367753677636777367783677936780367813678236783367843678536786367873678836789367903679136792367933679436795367963679736798367993680036801368023680336804368053680636807368083680936810368113681236813368143681536816368173681836819368203682136822368233682436825368263682736828368293683036831368323683336834368353683636837368383683936840368413684236843368443684536846368473684836849368503685136852368533685436855368563685736858368593686036861368623686336864368653686636867368683686936870368713687236873368743687536876368773687836879368803688136882368833688436885368863688736888368893689036891368923689336894368953689636897368983689936900369013690236903369043690536906369073690836909369103691136912369133691436915369163691736918369193692036921369223692336924369253692636927369283692936930369313693236933369343693536936369373693836939369403694136942369433694436945369463694736948369493695036951369523695336954369553695636957369583695936960369613696236963369643696536966369673696836969369703697136972369733697436975369763697736978369793698036981369823698336984369853698636987369883698936990369913699236993369943699536996369973699836999370003700137002370033700437005370063700737008370093701037011370123701337014370153701637017370183701937020370213702237023370243702537026370273702837029370303703137032370333703437035370363703737038370393704037041370423704337044370453704637047370483704937050370513705237053370543705537056370573705837059370603706137062370633706437065370663706737068370693707037071370723707337074370753707637077370783707937080370813708237083370843708537086370873708837089370903709137092370933709437095370963709737098370993710037101371023710337104371053710637107371083710937110371113711237113371143711537116371173711837119371203712137122371233712437125371263712737128371293713037131371323713337134371353713637137371383713937140371413714237143371443714537146371473714837149371503715137152371533715437155371563715737158371593716037161371623716337164371653716637167371683716937170371713717237173371743717537176371773717837179371803718137182371833718437185371863718737188371893719037191371923719337194371953719637197371983719937200372013720237203372043720537206372073720837209372103721137212372133721437215372163721737218372193722037221372223722337224372253722637227372283722937230372313723237233372343723537236372373723837239372403724137242372433724437245372463724737248372493725037251372523725337254372553725637257372583725937260372613726237263372643726537266372673726837269372703727137272372733727437275372763727737278372793728037281372823728337284372853728637287372883728937290372913729237293372943729537296372973729837299373003730137302373033730437305373063730737308373093731037311373123731337314373153731637317373183731937320373213732237323373243732537326373273732837329373303733137332373333733437335373363733737338373393734037341373423734337344373453734637347373483734937350373513735237353373543735537356373573735837359373603736137362373633736437365373663736737368373693737037371373723737337374373753737637377373783737937380373813738237383373843738537386373873738837389373903739137392373933739437395373963739737398373993740037401374023740337404374053740637407374083740937410374113741237413374143741537416374173741837419374203742137422374233742437425374263742737428374293743037431374323743337434374353743637437374383743937440374413744237443374443744537446374473744837449374503745137452374533745437455374563745737458374593746037461374623746337464374653746637467374683746937470374713747237473374743747537476374773747837479374803748137482374833748437485374863748737488374893749037491374923749337494374953749637497374983749937500375013750237503375043750537506375073750837509375103751137512375133751437515375163751737518375193752037521375223752337524375253752637527375283752937530375313753237533375343753537536375373753837539375403754137542375433754437545375463754737548375493755037551375523755337554375553755637557375583755937560375613756237563375643756537566375673756837569375703757137572375733757437575375763757737578375793758037581375823758337584375853758637587375883758937590375913759237593375943759537596375973759837599376003760137602376033760437605376063760737608376093761037611376123761337614376153761637617376183761937620376213762237623376243762537626376273762837629376303763137632376333763437635376363763737638376393764037641376423764337644376453764637647376483764937650376513765237653376543765537656376573765837659376603766137662376633766437665376663766737668376693767037671376723767337674376753767637677376783767937680376813768237683376843768537686376873768837689376903769137692376933769437695376963769737698376993770037701377023770337704377053770637707377083770937710377113771237713377143771537716377173771837719377203772137722377233772437725377263772737728377293773037731377323773337734377353773637737377383773937740377413774237743377443774537746377473774837749377503775137752377533775437755377563775737758377593776037761377623776337764377653776637767377683776937770377713777237773377743777537776377773777837779377803778137782377833778437785377863778737788377893779037791377923779337794377953779637797377983779937800378013780237803378043780537806378073780837809378103781137812378133781437815378163781737818378193782037821378223782337824378253782637827378283782937830378313783237833378343783537836378373783837839378403784137842378433784437845378463784737848378493785037851378523785337854378553785637857378583785937860378613786237863378643786537866378673786837869378703787137872378733787437875378763787737878378793788037881378823788337884378853788637887378883788937890378913789237893378943789537896378973789837899379003790137902379033790437905379063790737908379093791037911379123791337914379153791637917379183791937920379213792237923379243792537926379273792837929379303793137932379333793437935379363793737938379393794037941379423794337944379453794637947379483794937950379513795237953379543795537956379573795837959379603796137962379633796437965379663796737968379693797037971379723797337974379753797637977379783797937980379813798237983379843798537986379873798837989379903799137992379933799437995379963799737998379993800038001380023800338004380053800638007380083800938010380113801238013380143801538016380173801838019380203802138022380233802438025380263802738028380293803038031380323803338034380353803638037380383803938040380413804238043380443804538046380473804838049380503805138052380533805438055380563805738058380593806038061380623806338064380653806638067380683806938070380713807238073380743807538076380773807838079380803808138082380833808438085380863808738088380893809038091380923809338094380953809638097380983809938100381013810238103381043810538106381073810838109381103811138112381133811438115381163811738118381193812038121381223812338124381253812638127381283812938130381313813238133381343813538136381373813838139381403814138142381433814438145381463814738148381493815038151381523815338154381553815638157381583815938160381613816238163381643816538166381673816838169381703817138172381733817438175381763817738178381793818038181381823818338184381853818638187381883818938190381913819238193381943819538196381973819838199382003820138202382033820438205382063820738208382093821038211382123821338214382153821638217382183821938220382213822238223382243822538226382273822838229382303823138232382333823438235382363823738238382393824038241382423824338244382453824638247382483824938250382513825238253382543825538256382573825838259382603826138262382633826438265382663826738268382693827038271382723827338274382753827638277382783827938280382813828238283382843828538286382873828838289382903829138292382933829438295382963829738298382993830038301383023830338304383053830638307383083830938310383113831238313383143831538316383173831838319383203832138322383233832438325383263832738328383293833038331383323833338334383353833638337383383833938340383413834238343383443834538346383473834838349383503835138352383533835438355383563835738358383593836038361383623836338364383653836638367383683836938370383713837238373383743837538376383773837838379383803838138382383833838438385383863838738388383893839038391383923839338394383953839638397383983839938400384013840238403384043840538406384073840838409384103841138412384133841438415384163841738418384193842038421384223842338424384253842638427384283842938430384313843238433384343843538436384373843838439384403844138442384433844438445384463844738448384493845038451384523845338454384553845638457384583845938460384613846238463384643846538466384673846838469384703847138472384733847438475384763847738478384793848038481384823848338484384853848638487384883848938490384913849238493384943849538496384973849838499385003850138502385033850438505385063850738508385093851038511385123851338514385153851638517385183851938520385213852238523385243852538526385273852838529385303853138532385333853438535385363853738538385393854038541385423854338544385453854638547385483854938550385513855238553385543855538556385573855838559385603856138562385633856438565385663856738568385693857038571385723857338574385753857638577385783857938580385813858238583385843858538586385873858838589385903859138592385933859438595385963859738598385993860038601386023860338604386053860638607386083860938610386113861238613386143861538616386173861838619386203862138622386233862438625386263862738628386293863038631386323863338634386353863638637386383863938640386413864238643386443864538646386473864838649386503865138652386533865438655386563865738658386593866038661386623866338664386653866638667386683866938670386713867238673386743867538676386773867838679386803868138682386833868438685386863868738688386893869038691386923869338694386953869638697386983869938700387013870238703387043870538706387073870838709387103871138712387133871438715387163871738718387193872038721387223872338724387253872638727387283872938730387313873238733387343873538736387373873838739387403874138742387433874438745387463874738748387493875038751387523875338754387553875638757387583875938760387613876238763387643876538766387673876838769387703877138772387733877438775387763877738778387793878038781387823878338784387853878638787387883878938790387913879238793387943879538796387973879838799388003880138802388033880438805388063880738808388093881038811388123881338814388153881638817388183881938820388213882238823388243882538826388273882838829388303883138832388333883438835388363883738838388393884038841388423884338844388453884638847388483884938850388513885238853388543885538856388573885838859388603886138862388633886438865388663886738868388693887038871388723887338874388753887638877388783887938880388813888238883388843888538886388873888838889388903889138892388933889438895388963889738898388993890038901389023890338904389053890638907389083890938910389113891238913389143891538916389173891838919389203892138922389233892438925389263892738928389293893038931389323893338934389353893638937389383893938940389413894238943389443894538946389473894838949389503895138952389533895438955389563895738958389593896038961389623896338964389653896638967389683896938970389713897238973389743897538976389773897838979389803898138982389833898438985389863898738988389893899038991389923899338994389953899638997389983899939000390013900239003390043900539006390073900839009390103901139012390133901439015390163901739018390193902039021390223902339024390253902639027390283902939030390313903239033390343903539036390373903839039390403904139042390433904439045390463904739048390493905039051390523905339054390553905639057390583905939060390613906239063390643906539066390673906839069390703907139072390733907439075390763907739078390793908039081390823908339084390853908639087390883908939090390913909239093390943909539096390973909839099391003910139102391033910439105391063910739108391093911039111391123911339114391153911639117391183911939120391213912239123391243912539126391273912839129391303913139132391333913439135391363913739138391393914039141391423914339144391453914639147391483914939150391513915239153391543915539156391573915839159391603916139162391633916439165391663916739168391693917039171391723917339174391753917639177391783917939180391813918239183391843918539186391873918839189391903919139192391933919439195391963919739198391993920039201392023920339204392053920639207392083920939210392113921239213392143921539216392173921839219392203922139222392233922439225392263922739228392293923039231392323923339234392353923639237392383923939240392413924239243392443924539246392473924839249392503925139252392533925439255392563925739258392593926039261392623926339264392653926639267392683926939270392713927239273392743927539276392773927839279392803928139282392833928439285392863928739288392893929039291392923929339294392953929639297392983929939300393013930239303393043930539306393073930839309393103931139312393133931439315393163931739318393193932039321393223932339324393253932639327393283932939330393313933239333393343933539336393373933839339393403934139342393433934439345393463934739348393493935039351393523935339354393553935639357393583935939360393613936239363393643936539366393673936839369393703937139372393733937439375393763937739378393793938039381393823938339384393853938639387393883938939390393913939239393393943939539396393973939839399394003940139402394033940439405394063940739408394093941039411394123941339414394153941639417394183941939420394213942239423394243942539426394273942839429394303943139432394333943439435394363943739438394393944039441394423944339444394453944639447394483944939450394513945239453394543945539456394573945839459394603946139462394633946439465394663946739468394693947039471394723947339474394753947639477394783947939480394813948239483394843948539486394873948839489394903949139492394933949439495394963949739498394993950039501395023950339504395053950639507395083950939510395113951239513395143951539516395173951839519395203952139522395233952439525395263952739528395293953039531395323953339534395353953639537395383953939540395413954239543395443954539546395473954839549395503955139552395533955439555395563955739558395593956039561395623956339564395653956639567395683956939570395713957239573395743957539576395773957839579395803958139582395833958439585395863958739588395893959039591395923959339594395953959639597395983959939600396013960239603396043960539606396073960839609396103961139612396133961439615396163961739618396193962039621396223962339624396253962639627396283962939630396313963239633396343963539636396373963839639396403964139642396433964439645396463964739648396493965039651396523965339654396553965639657396583965939660396613966239663396643966539666396673966839669396703967139672396733967439675396763967739678396793968039681396823968339684396853968639687396883968939690396913969239693396943969539696396973969839699397003970139702397033970439705397063970739708397093971039711397123971339714397153971639717397183971939720397213972239723397243972539726397273972839729397303973139732397333973439735397363973739738397393974039741397423974339744397453974639747397483974939750397513975239753397543975539756397573975839759397603976139762397633976439765397663976739768397693977039771397723977339774397753977639777397783977939780397813978239783397843978539786397873978839789397903979139792397933979439795397963979739798397993980039801398023980339804398053980639807398083980939810398113981239813398143981539816398173981839819398203982139822398233982439825398263982739828398293983039831398323983339834398353983639837398383983939840398413984239843398443984539846398473984839849398503985139852398533985439855398563985739858398593986039861398623986339864398653986639867398683986939870398713987239873398743987539876398773987839879398803988139882398833988439885398863988739888398893989039891398923989339894398953989639897398983989939900399013990239903399043990539906399073990839909399103991139912399133991439915399163991739918399193992039921399223992339924399253992639927399283992939930399313993239933399343993539936399373993839939399403994139942399433994439945399463994739948399493995039951399523995339954399553995639957399583995939960399613996239963399643996539966399673996839969399703997139972399733997439975399763997739978399793998039981399823998339984399853998639987399883998939990399913999239993399943999539996399973999839999400004000140002400034000440005400064000740008400094001040011400124001340014400154001640017400184001940020400214002240023400244002540026400274002840029400304003140032400334003440035400364003740038400394004040041400424004340044400454004640047400484004940050400514005240053400544005540056400574005840059400604006140062400634006440065400664006740068400694007040071400724007340074400754007640077400784007940080400814008240083400844008540086400874008840089400904009140092400934009440095400964009740098400994010040101401024010340104401054010640107401084010940110401114011240113401144011540116401174011840119401204012140122401234012440125401264012740128401294013040131401324013340134401354013640137401384013940140401414014240143401444014540146401474014840149401504015140152401534015440155401564015740158401594016040161401624016340164401654016640167401684016940170401714017240173401744017540176401774017840179401804018140182401834018440185401864018740188401894019040191401924019340194401954019640197401984019940200402014020240203402044020540206402074020840209402104021140212402134021440215402164021740218402194022040221402224022340224402254022640227402284022940230402314023240233402344023540236402374023840239402404024140242402434024440245402464024740248402494025040251402524025340254402554025640257402584025940260402614026240263402644026540266402674026840269402704027140272402734027440275402764027740278402794028040281402824028340284402854028640287402884028940290402914029240293402944029540296402974029840299403004030140302403034030440305403064030740308403094031040311403124031340314403154031640317403184031940320403214032240323403244032540326403274032840329403304033140332403334033440335403364033740338403394034040341403424034340344403454034640347403484034940350403514035240353403544035540356403574035840359403604036140362403634036440365403664036740368403694037040371403724037340374403754037640377403784037940380403814038240383403844038540386403874038840389403904039140392403934039440395403964039740398403994040040401404024040340404404054040640407404084040940410404114041240413404144041540416404174041840419404204042140422404234042440425404264042740428404294043040431404324043340434404354043640437404384043940440404414044240443404444044540446404474044840449404504045140452404534045440455404564045740458404594046040461404624046340464404654046640467404684046940470404714047240473404744047540476404774047840479404804048140482404834048440485404864048740488404894049040491404924049340494404954049640497404984049940500405014050240503405044050540506405074050840509405104051140512405134051440515405164051740518405194052040521405224052340524405254052640527405284052940530405314053240533405344053540536405374053840539405404054140542405434054440545405464054740548405494055040551405524055340554405554055640557405584055940560405614056240563405644056540566405674056840569405704057140572405734057440575405764057740578405794058040581405824058340584405854058640587405884058940590405914059240593405944059540596405974059840599406004060140602406034060440605406064060740608406094061040611406124061340614406154061640617406184061940620406214062240623406244062540626406274062840629406304063140632406334063440635406364063740638406394064040641406424064340644406454064640647406484064940650406514065240653406544065540656406574065840659406604066140662406634066440665406664066740668406694067040671406724067340674406754067640677406784067940680406814068240683406844068540686406874068840689406904069140692406934069440695406964069740698406994070040701407024070340704407054070640707407084070940710407114071240713407144071540716407174071840719407204072140722407234072440725407264072740728407294073040731407324073340734407354073640737407384073940740407414074240743407444074540746407474074840749407504075140752407534075440755407564075740758407594076040761407624076340764407654076640767407684076940770407714077240773407744077540776407774077840779407804078140782407834078440785407864078740788407894079040791407924079340794407954079640797407984079940800408014080240803408044080540806408074080840809408104081140812408134081440815408164081740818408194082040821408224082340824408254082640827408284082940830408314083240833408344083540836408374083840839408404084140842408434084440845408464084740848408494085040851408524085340854408554085640857408584085940860408614086240863408644086540866408674086840869408704087140872408734087440875408764087740878408794088040881408824088340884408854088640887408884088940890408914089240893408944089540896408974089840899409004090140902409034090440905409064090740908409094091040911409124091340914409154091640917409184091940920409214092240923409244092540926409274092840929409304093140932409334093440935409364093740938409394094040941409424094340944409454094640947409484094940950409514095240953409544095540956409574095840959409604096140962409634096440965409664096740968409694097040971409724097340974409754097640977409784097940980409814098240983409844098540986409874098840989409904099140992409934099440995409964099740998409994100041001410024100341004410054100641007410084100941010410114101241013410144101541016410174101841019410204102141022410234102441025410264102741028410294103041031410324103341034410354103641037410384103941040410414104241043410444104541046410474104841049410504105141052410534105441055410564105741058410594106041061410624106341064410654106641067410684106941070410714107241073410744107541076410774107841079410804108141082410834108441085410864108741088410894109041091410924109341094410954109641097410984109941100411014110241103411044110541106411074110841109411104111141112411134111441115411164111741118411194112041121411224112341124411254112641127411284112941130411314113241133411344113541136411374113841139411404114141142411434114441145411464114741148411494115041151411524115341154411554115641157411584115941160411614116241163411644116541166411674116841169411704117141172411734117441175411764117741178411794118041181411824118341184411854118641187411884118941190411914119241193411944119541196411974119841199412004120141202412034120441205412064120741208412094121041211412124121341214412154121641217412184121941220412214122241223412244122541226412274122841229412304123141232412334123441235412364123741238412394124041241412424124341244412454124641247412484124941250412514125241253412544125541256412574125841259412604126141262412634126441265412664126741268412694127041271412724127341274412754127641277412784127941280412814128241283412844128541286412874128841289412904129141292412934129441295412964129741298412994130041301413024130341304413054130641307413084130941310413114131241313413144131541316413174131841319413204132141322413234132441325413264132741328413294133041331413324133341334413354133641337413384133941340413414134241343413444134541346413474134841349413504135141352413534135441355413564135741358413594136041361413624136341364413654136641367413684136941370413714137241373413744137541376413774137841379413804138141382413834138441385413864138741388413894139041391413924139341394413954139641397413984139941400414014140241403414044140541406414074140841409414104141141412414134141441415414164141741418414194142041421414224142341424414254142641427414284142941430414314143241433414344143541436414374143841439414404144141442414434144441445414464144741448414494145041451414524145341454414554145641457414584145941460414614146241463414644146541466414674146841469414704147141472414734147441475414764147741478414794148041481414824148341484414854148641487414884148941490414914149241493414944149541496414974149841499415004150141502415034150441505415064150741508415094151041511415124151341514415154151641517415184151941520415214152241523415244152541526415274152841529415304153141532415334153441535415364153741538415394154041541415424154341544415454154641547415484154941550415514155241553415544155541556415574155841559415604156141562415634156441565415664156741568415694157041571415724157341574415754157641577415784157941580415814158241583415844158541586415874158841589415904159141592415934159441595415964159741598415994160041601416024160341604416054160641607416084160941610416114161241613416144161541616416174161841619416204162141622416234162441625416264162741628416294163041631416324163341634416354163641637416384163941640416414164241643416444164541646416474164841649416504165141652416534165441655416564165741658416594166041661416624166341664416654166641667416684166941670416714167241673416744167541676416774167841679416804168141682416834168441685416864168741688416894169041691416924169341694416954169641697416984169941700417014170241703417044170541706417074170841709417104171141712417134171441715417164171741718417194172041721417224172341724417254172641727417284172941730417314173241733417344173541736417374173841739417404174141742417434174441745417464174741748417494175041751417524175341754417554175641757417584175941760417614176241763417644176541766417674176841769417704177141772417734177441775417764177741778417794178041781417824178341784417854178641787417884178941790417914179241793417944179541796417974179841799418004180141802418034180441805418064180741808418094181041811418124181341814418154181641817418184181941820418214182241823418244182541826418274182841829418304183141832418334183441835418364183741838418394184041841418424184341844418454184641847418484184941850418514185241853418544185541856418574185841859418604186141862418634186441865418664186741868418694187041871418724187341874418754187641877418784187941880418814188241883418844188541886418874188841889418904189141892418934189441895418964189741898418994190041901419024190341904419054190641907419084190941910419114191241913419144191541916419174191841919419204192141922419234192441925419264192741928419294193041931419324193341934419354193641937419384193941940419414194241943419444194541946419474194841949419504195141952419534195441955419564195741958419594196041961419624196341964419654196641967419684196941970419714197241973419744197541976419774197841979419804198141982419834198441985419864198741988419894199041991419924199341994419954199641997419984199942000420014200242003420044200542006420074200842009420104201142012420134201442015420164201742018420194202042021420224202342024420254202642027420284202942030420314203242033420344203542036420374203842039420404204142042420434204442045420464204742048420494205042051420524205342054420554205642057420584205942060420614206242063420644206542066420674206842069420704207142072420734207442075420764207742078420794208042081420824208342084420854208642087420884208942090420914209242093420944209542096420974209842099421004210142102421034210442105421064210742108421094211042111421124211342114421154211642117421184211942120421214212242123421244212542126421274212842129421304213142132421334213442135421364213742138421394214042141421424214342144421454214642147421484214942150421514215242153421544215542156421574215842159421604216142162421634216442165421664216742168421694217042171421724217342174421754217642177421784217942180421814218242183421844218542186421874218842189421904219142192421934219442195421964219742198421994220042201422024220342204422054220642207422084220942210422114221242213422144221542216422174221842219422204222142222422234222442225422264222742228422294223042231422324223342234422354223642237422384223942240422414224242243422444224542246422474224842249422504225142252422534225442255422564225742258422594226042261422624226342264422654226642267422684226942270422714227242273422744227542276422774227842279422804228142282422834228442285422864228742288422894229042291422924229342294422954229642297422984229942300423014230242303423044230542306423074230842309423104231142312423134231442315423164231742318423194232042321423224232342324423254232642327423284232942330423314233242333423344233542336423374233842339423404234142342423434234442345423464234742348423494235042351423524235342354423554235642357423584235942360423614236242363423644236542366423674236842369423704237142372423734237442375423764237742378423794238042381423824238342384423854238642387423884238942390423914239242393423944239542396423974239842399424004240142402424034240442405424064240742408424094241042411424124241342414424154241642417424184241942420424214242242423424244242542426424274242842429424304243142432424334243442435424364243742438424394244042441424424244342444424454244642447424484244942450424514245242453424544245542456424574245842459424604246142462424634246442465424664246742468424694247042471424724247342474424754247642477424784247942480424814248242483424844248542486424874248842489424904249142492424934249442495424964249742498424994250042501425024250342504425054250642507425084250942510425114251242513425144251542516425174251842519425204252142522425234252442525425264252742528425294253042531425324253342534425354253642537425384253942540425414254242543425444254542546425474254842549425504255142552425534255442555425564255742558425594256042561425624256342564425654256642567425684256942570425714257242573425744257542576425774257842579425804258142582425834258442585425864258742588425894259042591425924259342594425954259642597425984259942600426014260242603426044260542606426074260842609426104261142612426134261442615426164261742618426194262042621426224262342624426254262642627426284262942630426314263242633426344263542636426374263842639426404264142642426434264442645426464264742648426494265042651426524265342654426554265642657426584265942660426614266242663426644266542666426674266842669426704267142672426734267442675426764267742678426794268042681426824268342684426854268642687426884268942690426914269242693426944269542696426974269842699427004270142702427034270442705427064270742708427094271042711427124271342714427154271642717427184271942720427214272242723427244272542726427274272842729427304273142732427334273442735427364273742738427394274042741427424274342744427454274642747427484274942750427514275242753427544275542756427574275842759427604276142762427634276442765427664276742768427694277042771427724277342774427754277642777427784277942780427814278242783427844278542786427874278842789427904279142792427934279442795427964279742798427994280042801428024280342804428054280642807428084280942810428114281242813428144281542816428174281842819428204282142822428234282442825428264282742828428294283042831428324283342834428354283642837428384283942840428414284242843428444284542846428474284842849428504285142852428534285442855428564285742858428594286042861428624286342864428654286642867428684286942870428714287242873428744287542876428774287842879428804288142882428834288442885428864288742888428894289042891428924289342894428954289642897428984289942900429014290242903429044290542906429074290842909429104291142912429134291442915429164291742918429194292042921429224292342924429254292642927429284292942930429314293242933429344293542936429374293842939429404294142942429434294442945429464294742948429494295042951429524295342954429554295642957429584295942960429614296242963429644296542966429674296842969429704297142972429734297442975429764297742978429794298042981429824298342984429854298642987429884298942990429914299242993429944299542996429974299842999430004300143002430034300443005430064300743008430094301043011430124301343014430154301643017430184301943020430214302243023430244302543026430274302843029430304303143032430334303443035430364303743038430394304043041430424304343044430454304643047430484304943050430514305243053430544305543056430574305843059430604306143062430634306443065430664306743068430694307043071430724307343074430754307643077430784307943080430814308243083430844308543086430874308843089430904309143092430934309443095430964309743098430994310043101431024310343104431054310643107431084310943110431114311243113431144311543116431174311843119431204312143122431234312443125431264312743128431294313043131431324313343134431354313643137431384313943140431414314243143431444314543146431474314843149431504315143152431534315443155431564315743158431594316043161431624316343164431654316643167431684316943170431714317243173431744317543176431774317843179431804318143182431834318443185431864318743188431894319043191431924319343194431954319643197431984319943200432014320243203432044320543206432074320843209432104321143212432134321443215432164321743218432194322043221432224322343224432254322643227432284322943230432314323243233432344323543236432374323843239432404324143242432434324443245432464324743248432494325043251432524325343254432554325643257432584325943260432614326243263432644326543266432674326843269432704327143272432734327443275432764327743278432794328043281432824328343284432854328643287432884328943290432914329243293432944329543296432974329843299433004330143302433034330443305433064330743308433094331043311433124331343314433154331643317433184331943320433214332243323433244332543326433274332843329433304333143332433334333443335433364333743338433394334043341433424334343344433454334643347433484334943350433514335243353433544335543356433574335843359433604336143362433634336443365433664336743368433694337043371433724337343374433754337643377433784337943380433814338243383433844338543386433874338843389433904339143392433934339443395433964339743398433994340043401434024340343404434054340643407434084340943410434114341243413434144341543416434174341843419434204342143422434234342443425434264342743428434294343043431434324343343434434354343643437434384343943440434414344243443434444344543446434474344843449434504345143452434534345443455434564345743458434594346043461434624346343464434654346643467434684346943470434714347243473434744347543476434774347843479434804348143482434834348443485434864348743488434894349043491434924349343494434954349643497434984349943500435014350243503435044350543506435074350843509435104351143512435134351443515435164351743518435194352043521435224352343524435254352643527435284352943530435314353243533435344353543536435374353843539435404354143542435434354443545435464354743548435494355043551435524355343554435554355643557435584355943560435614356243563435644356543566435674356843569435704357143572435734357443575435764357743578435794358043581435824358343584435854358643587435884358943590435914359243593435944359543596435974359843599436004360143602436034360443605436064360743608436094361043611436124361343614436154361643617436184361943620436214362243623436244362543626436274362843629436304363143632436334363443635436364363743638436394364043641436424364343644436454364643647436484364943650436514365243653436544365543656436574365843659436604366143662436634366443665436664366743668436694367043671436724367343674436754367643677436784367943680436814368243683436844368543686436874368843689436904369143692436934369443695436964369743698436994370043701437024370343704437054370643707437084370943710437114371243713437144371543716437174371843719437204372143722437234372443725437264372743728437294373043731437324373343734437354373643737437384373943740437414374243743437444374543746437474374843749437504375143752437534375443755437564375743758437594376043761437624376343764437654376643767437684376943770437714377243773437744377543776437774377843779437804378143782437834378443785437864378743788437894379043791437924379343794437954379643797437984379943800438014380243803438044380543806438074380843809438104381143812438134381443815438164381743818438194382043821438224382343824438254382643827438284382943830438314383243833438344383543836438374383843839438404384143842438434384443845438464384743848438494385043851438524385343854438554385643857438584385943860438614386243863438644386543866438674386843869438704387143872438734387443875438764387743878438794388043881438824388343884438854388643887438884388943890438914389243893438944389543896438974389843899439004390143902439034390443905439064390743908439094391043911439124391343914439154391643917439184391943920439214392243923439244392543926439274392843929439304393143932439334393443935439364393743938439394394043941439424394343944439454394643947439484394943950439514395243953439544395543956439574395843959439604396143962439634396443965439664396743968439694397043971439724397343974439754397643977439784397943980439814398243983439844398543986439874398843989439904399143992439934399443995439964399743998439994400044001440024400344004440054400644007440084400944010440114401244013440144401544016440174401844019440204402144022440234402444025440264402744028440294403044031440324403344034440354403644037440384403944040440414404244043440444404544046440474404844049440504405144052440534405444055440564405744058440594406044061440624406344064440654406644067440684406944070440714407244073440744407544076440774407844079440804408144082440834408444085440864408744088440894409044091440924409344094440954409644097440984409944100441014410244103441044410544106441074410844109441104411144112441134411444115441164411744118441194412044121441224412344124441254412644127441284412944130441314413244133441344413544136441374413844139441404414144142441434414444145441464414744148441494415044151441524415344154441554415644157441584415944160441614416244163441644416544166441674416844169441704417144172441734417444175441764417744178441794418044181441824418344184441854418644187441884418944190441914419244193441944419544196441974419844199442004420144202442034420444205442064420744208442094421044211442124421344214442154421644217442184421944220442214422244223442244422544226442274422844229442304423144232442334423444235442364423744238442394424044241442424424344244442454424644247442484424944250442514425244253442544425544256442574425844259442604426144262442634426444265442664426744268442694427044271442724427344274442754427644277442784427944280442814428244283442844428544286442874428844289442904429144292442934429444295442964429744298442994430044301443024430344304443054430644307443084430944310443114431244313443144431544316443174431844319443204432144322443234432444325443264432744328443294433044331443324433344334443354433644337443384433944340443414434244343443444434544346443474434844349443504435144352443534435444355443564435744358443594436044361443624436344364443654436644367443684436944370443714437244373443744437544376443774437844379443804438144382443834438444385443864438744388443894439044391443924439344394443954439644397443984439944400444014440244403444044440544406444074440844409444104441144412444134441444415444164441744418444194442044421444224442344424444254442644427444284442944430444314443244433444344443544436444374443844439444404444144442444434444444445444464444744448444494445044451444524445344454444554445644457444584445944460444614446244463444644446544466444674446844469444704447144472444734447444475444764447744478444794448044481444824448344484444854448644487444884448944490444914449244493444944449544496444974449844499445004450144502445034450444505445064450744508445094451044511445124451344514445154451644517445184451944520445214452244523445244452544526445274452844529445304453144532445334453444535445364453744538445394454044541445424454344544445454454644547445484454944550445514455244553445544455544556445574455844559445604456144562445634456444565445664456744568445694457044571445724457344574445754457644577445784457944580445814458244583445844458544586445874458844589445904459144592445934459444595445964459744598445994460044601446024460344604446054460644607446084460944610446114461244613446144461544616446174461844619446204462144622446234462444625446264462744628446294463044631446324463344634446354463644637446384463944640446414464244643446444464544646446474464844649446504465144652446534465444655446564465744658446594466044661446624466344664446654466644667446684466944670446714467244673446744467544676446774467844679446804468144682446834468444685446864468744688446894469044691446924469344694446954469644697446984469944700447014470244703447044470544706447074470844709447104471144712447134471444715447164471744718447194472044721447224472344724447254472644727447284472944730447314473244733447344473544736447374473844739447404474144742447434474444745447464474744748447494475044751447524475344754447554475644757447584475944760447614476244763447644476544766447674476844769447704477144772447734477444775447764477744778447794478044781447824478344784447854478644787447884478944790447914479244793447944479544796447974479844799448004480144802448034480444805448064480744808448094481044811448124481344814448154481644817448184481944820448214482244823448244482544826448274482844829448304483144832448334483444835448364483744838448394484044841448424484344844448454484644847448484484944850448514485244853448544485544856448574485844859448604486144862448634486444865448664486744868448694487044871448724487344874448754487644877448784487944880448814488244883448844488544886448874488844889448904489144892448934489444895448964489744898448994490044901449024490344904449054490644907449084490944910449114491244913449144491544916449174491844919449204492144922449234492444925449264492744928449294493044931449324493344934449354493644937449384493944940449414494244943449444494544946449474494844949449504495144952449534495444955449564495744958449594496044961449624496344964449654496644967449684496944970449714497244973449744497544976449774497844979449804498144982449834498444985449864498744988449894499044991449924499344994449954499644997449984499945000450014500245003450044500545006450074500845009450104501145012450134501445015450164501745018450194502045021450224502345024450254502645027450284502945030450314503245033450344503545036450374503845039450404504145042450434504445045450464504745048450494505045051450524505345054450554505645057450584505945060450614506245063450644506545066450674506845069450704507145072450734507445075450764507745078450794508045081450824508345084450854508645087450884508945090450914509245093450944509545096450974509845099451004510145102451034510445105451064510745108451094511045111451124511345114451154511645117451184511945120451214512245123451244512545126451274512845129451304513145132451334513445135451364513745138451394514045141451424514345144451454514645147451484514945150451514515245153451544515545156451574515845159451604516145162451634516445165451664516745168451694517045171451724517345174451754517645177451784517945180451814518245183451844518545186451874518845189451904519145192451934519445195451964519745198451994520045201452024520345204452054520645207452084520945210452114521245213452144521545216452174521845219452204522145222452234522445225452264522745228452294523045231452324523345234452354523645237452384523945240452414524245243452444524545246452474524845249452504525145252452534525445255452564525745258452594526045261452624526345264452654526645267452684526945270452714527245273452744527545276452774527845279452804528145282452834528445285452864528745288452894529045291452924529345294452954529645297452984529945300453014530245303453044530545306453074530845309453104531145312453134531445315453164531745318453194532045321453224532345324453254532645327453284532945330453314533245333453344533545336453374533845339453404534145342453434534445345453464534745348453494535045351453524535345354453554535645357453584535945360453614536245363453644536545366453674536845369453704537145372453734537445375453764537745378453794538045381453824538345384453854538645387453884538945390453914539245393453944539545396453974539845399454004540145402454034540445405454064540745408454094541045411454124541345414454154541645417454184541945420454214542245423454244542545426454274542845429454304543145432454334543445435454364543745438454394544045441454424544345444454454544645447454484544945450454514545245453454544545545456454574545845459454604546145462454634546445465454664546745468454694547045471454724547345474454754547645477454784547945480454814548245483454844548545486454874548845489454904549145492454934549445495454964549745498454994550045501455024550345504455054550645507455084550945510455114551245513455144551545516455174551845519455204552145522455234552445525455264552745528455294553045531455324553345534455354553645537455384553945540455414554245543455444554545546455474554845549455504555145552455534555445555455564555745558455594556045561455624556345564455654556645567455684556945570455714557245573455744557545576455774557845579455804558145582455834558445585455864558745588455894559045591455924559345594455954559645597455984559945600456014560245603456044560545606456074560845609456104561145612456134561445615456164561745618456194562045621456224562345624456254562645627456284562945630456314563245633456344563545636456374563845639456404564145642456434564445645456464564745648456494565045651456524565345654456554565645657456584565945660456614566245663456644566545666456674566845669456704567145672456734567445675456764567745678456794568045681456824568345684456854568645687456884568945690456914569245693456944569545696456974569845699457004570145702457034570445705457064570745708457094571045711457124571345714457154571645717457184571945720457214572245723457244572545726457274572845729457304573145732457334573445735457364573745738457394574045741457424574345744457454574645747457484574945750457514575245753457544575545756457574575845759457604576145762457634576445765457664576745768457694577045771457724577345774457754577645777457784577945780457814578245783457844578545786457874578845789457904579145792457934579445795457964579745798457994580045801458024580345804458054580645807458084580945810458114581245813458144581545816458174581845819458204582145822458234582445825458264582745828458294583045831458324583345834458354583645837458384583945840458414584245843458444584545846458474584845849458504585145852458534585445855458564585745858458594586045861458624586345864458654586645867458684586945870458714587245873458744587545876458774587845879458804588145882458834588445885458864588745888458894589045891458924589345894458954589645897458984589945900459014590245903459044590545906459074590845909459104591145912459134591445915459164591745918459194592045921459224592345924459254592645927459284592945930459314593245933459344593545936459374593845939459404594145942459434594445945459464594745948459494595045951459524595345954459554595645957459584595945960459614596245963459644596545966459674596845969459704597145972459734597445975459764597745978459794598045981459824598345984459854598645987459884598945990459914599245993459944599545996459974599845999460004600146002460034600446005460064600746008460094601046011460124601346014460154601646017460184601946020460214602246023460244602546026460274602846029460304603146032460334603446035460364603746038460394604046041460424604346044460454604646047460484604946050460514605246053460544605546056460574605846059460604606146062460634606446065460664606746068460694607046071460724607346074460754607646077460784607946080460814608246083460844608546086460874608846089460904609146092460934609446095460964609746098460994610046101461024610346104461054610646107461084610946110461114611246113461144611546116461174611846119461204612146122461234612446125461264612746128461294613046131461324613346134461354613646137461384613946140461414614246143461444614546146461474614846149461504615146152461534615446155461564615746158461594616046161461624616346164461654616646167461684616946170461714617246173461744617546176461774617846179461804618146182461834618446185461864618746188461894619046191461924619346194461954619646197461984619946200462014620246203462044620546206462074620846209462104621146212462134621446215462164621746218462194622046221462224622346224462254622646227462284622946230462314623246233462344623546236462374623846239462404624146242462434624446245462464624746248462494625046251462524625346254462554625646257462584625946260462614626246263462644626546266462674626846269462704627146272462734627446275462764627746278462794628046281462824628346284462854628646287462884628946290462914629246293462944629546296462974629846299463004630146302463034630446305463064630746308463094631046311463124631346314463154631646317463184631946320463214632246323463244632546326463274632846329463304633146332463334633446335463364633746338463394634046341463424634346344463454634646347463484634946350463514635246353463544635546356463574635846359463604636146362463634636446365463664636746368463694637046371463724637346374463754637646377463784637946380463814638246383463844638546386463874638846389463904639146392463934639446395463964639746398463994640046401464024640346404464054640646407464084640946410464114641246413464144641546416464174641846419464204642146422464234642446425464264642746428464294643046431464324643346434464354643646437464384643946440464414644246443464444644546446464474644846449464504645146452464534645446455464564645746458464594646046461464624646346464464654646646467464684646946470464714647246473464744647546476464774647846479464804648146482464834648446485464864648746488464894649046491464924649346494464954649646497464984649946500465014650246503465044650546506465074650846509465104651146512465134651446515465164651746518465194652046521465224652346524465254652646527465284652946530465314653246533465344653546536465374653846539465404654146542465434654446545465464654746548465494655046551465524655346554465554655646557465584655946560465614656246563465644656546566465674656846569465704657146572465734657446575465764657746578465794658046581465824658346584465854658646587465884658946590465914659246593465944659546596465974659846599466004660146602466034660446605466064660746608466094661046611466124661346614466154661646617466184661946620466214662246623466244662546626466274662846629466304663146632466334663446635466364663746638466394664046641466424664346644466454664646647466484664946650466514665246653466544665546656466574665846659466604666146662466634666446665466664666746668466694667046671466724667346674466754667646677466784667946680466814668246683466844668546686466874668846689466904669146692466934669446695466964669746698466994670046701467024670346704467054670646707467084670946710467114671246713467144671546716467174671846719467204672146722467234672446725467264672746728467294673046731467324673346734467354673646737467384673946740467414674246743467444674546746467474674846749467504675146752467534675446755467564675746758467594676046761467624676346764467654676646767467684676946770467714677246773467744677546776467774677846779467804678146782467834678446785467864678746788467894679046791467924679346794467954679646797467984679946800468014680246803468044680546806468074680846809468104681146812468134681446815468164681746818468194682046821468224682346824468254682646827468284682946830468314683246833468344683546836468374683846839468404684146842468434684446845468464684746848468494685046851468524685346854468554685646857468584685946860468614686246863468644686546866468674686846869468704687146872468734687446875468764687746878468794688046881468824688346884468854688646887468884688946890468914689246893468944689546896468974689846899469004690146902469034690446905469064690746908469094691046911469124691346914469154691646917469184691946920469214692246923469244692546926469274692846929469304693146932469334693446935469364693746938469394694046941469424694346944469454694646947469484694946950469514695246953469544695546956469574695846959469604696146962469634696446965469664696746968469694697046971469724697346974469754697646977469784697946980469814698246983469844698546986469874698846989469904699146992469934699446995469964699746998469994700047001470024700347004470054700647007470084700947010470114701247013470144701547016470174701847019470204702147022470234702447025470264702747028470294703047031470324703347034470354703647037470384703947040470414704247043470444704547046470474704847049470504705147052470534705447055470564705747058470594706047061470624706347064470654706647067470684706947070470714707247073470744707547076470774707847079470804708147082470834708447085470864708747088470894709047091470924709347094470954709647097470984709947100471014710247103471044710547106471074710847109471104711147112471134711447115471164711747118471194712047121471224712347124471254712647127471284712947130471314713247133471344713547136471374713847139471404714147142471434714447145471464714747148471494715047151471524715347154471554715647157471584715947160471614716247163471644716547166471674716847169471704717147172471734717447175471764717747178471794718047181471824718347184471854718647187471884718947190471914719247193471944719547196471974719847199472004720147202472034720447205472064720747208472094721047211472124721347214472154721647217472184721947220472214722247223472244722547226472274722847229472304723147232472334723447235472364723747238472394724047241472424724347244472454724647247472484724947250472514725247253472544725547256472574725847259472604726147262472634726447265472664726747268472694727047271472724727347274472754727647277472784727947280472814728247283472844728547286472874728847289472904729147292472934729447295472964729747298472994730047301473024730347304473054730647307473084730947310473114731247313473144731547316473174731847319473204732147322473234732447325473264732747328473294733047331473324733347334473354733647337473384733947340473414734247343473444734547346473474734847349473504735147352473534735447355473564735747358473594736047361473624736347364473654736647367473684736947370473714737247373473744737547376473774737847379473804738147382473834738447385473864738747388473894739047391473924739347394473954739647397473984739947400474014740247403474044740547406474074740847409474104741147412474134741447415474164741747418474194742047421474224742347424474254742647427474284742947430474314743247433474344743547436474374743847439474404744147442474434744447445474464744747448474494745047451474524745347454474554745647457474584745947460474614746247463474644746547466474674746847469474704747147472474734747447475474764747747478474794748047481474824748347484474854748647487474884748947490474914749247493474944749547496474974749847499475004750147502475034750447505475064750747508475094751047511475124751347514475154751647517475184751947520475214752247523475244752547526475274752847529475304753147532475334753447535475364753747538475394754047541475424754347544475454754647547475484754947550475514755247553475544755547556475574755847559475604756147562475634756447565475664756747568475694757047571475724757347574475754757647577475784757947580475814758247583475844758547586475874758847589475904759147592475934759447595475964759747598475994760047601476024760347604476054760647607476084760947610476114761247613476144761547616476174761847619476204762147622476234762447625476264762747628476294763047631476324763347634476354763647637476384763947640476414764247643476444764547646476474764847649476504765147652476534765447655476564765747658476594766047661476624766347664476654766647667476684766947670476714767247673476744767547676476774767847679476804768147682476834768447685476864768747688476894769047691476924769347694476954769647697476984769947700477014770247703477044770547706477074770847709477104771147712477134771447715477164771747718477194772047721477224772347724477254772647727477284772947730477314773247733477344773547736477374773847739477404774147742477434774447745477464774747748477494775047751477524775347754477554775647757477584775947760477614776247763477644776547766477674776847769477704777147772477734777447775477764777747778477794778047781477824778347784477854778647787477884778947790477914779247793477944779547796477974779847799478004780147802478034780447805478064780747808478094781047811478124781347814478154781647817478184781947820478214782247823478244782547826478274782847829478304783147832478334783447835478364783747838478394784047841478424784347844478454784647847478484784947850478514785247853478544785547856478574785847859478604786147862478634786447865478664786747868478694787047871478724787347874478754787647877478784787947880478814788247883478844788547886478874788847889478904789147892478934789447895478964789747898478994790047901479024790347904479054790647907479084790947910479114791247913479144791547916479174791847919479204792147922479234792447925479264792747928479294793047931479324793347934479354793647937479384793947940479414794247943479444794547946479474794847949479504795147952479534795447955479564795747958479594796047961479624796347964479654796647967479684796947970479714797247973479744797547976479774797847979479804798147982479834798447985479864798747988479894799047991479924799347994479954799647997479984799948000480014800248003480044800548006480074800848009480104801148012480134801448015480164801748018480194802048021480224802348024480254802648027480284802948030480314803248033480344803548036480374803848039480404804148042480434804448045480464804748048480494805048051480524805348054480554805648057480584805948060480614806248063480644806548066480674806848069480704807148072480734807448075480764807748078480794808048081480824808348084480854808648087480884808948090480914809248093480944809548096480974809848099481004810148102481034810448105481064810748108481094811048111481124811348114481154811648117481184811948120481214812248123481244812548126481274812848129481304813148132481334813448135481364813748138481394814048141481424814348144481454814648147481484814948150481514815248153481544815548156481574815848159481604816148162481634816448165481664816748168481694817048171481724817348174481754817648177481784817948180481814818248183481844818548186481874818848189481904819148192481934819448195481964819748198481994820048201482024820348204482054820648207482084820948210482114821248213482144821548216482174821848219482204822148222482234822448225482264822748228482294823048231482324823348234482354823648237482384823948240482414824248243482444824548246482474824848249482504825148252482534825448255482564825748258482594826048261482624826348264482654826648267482684826948270482714827248273482744827548276482774827848279482804828148282482834828448285482864828748288482894829048291482924829348294482954829648297482984829948300483014830248303483044830548306483074830848309483104831148312483134831448315483164831748318483194832048321483224832348324483254832648327483284832948330483314833248333483344833548336483374833848339483404834148342483434834448345483464834748348483494835048351483524835348354483554835648357483584835948360483614836248363483644836548366483674836848369483704837148372483734837448375483764837748378483794838048381483824838348384483854838648387483884838948390483914839248393483944839548396483974839848399484004840148402484034840448405484064840748408484094841048411484124841348414484154841648417484184841948420484214842248423484244842548426484274842848429484304843148432484334843448435484364843748438484394844048441484424844348444484454844648447484484844948450484514845248453484544845548456484574845848459484604846148462484634846448465484664846748468484694847048471484724847348474484754847648477484784847948480484814848248483484844848548486484874848848489484904849148492484934849448495484964849748498484994850048501485024850348504485054850648507485084850948510485114851248513485144851548516485174851848519485204852148522485234852448525485264852748528485294853048531485324853348534485354853648537485384853948540485414854248543485444854548546485474854848549485504855148552485534855448555485564855748558485594856048561485624856348564485654856648567485684856948570485714857248573485744857548576485774857848579485804858148582485834858448585485864858748588485894859048591485924859348594485954859648597485984859948600486014860248603486044860548606486074860848609486104861148612486134861448615486164861748618486194862048621486224862348624486254862648627486284862948630486314863248633486344863548636486374863848639486404864148642486434864448645486464864748648486494865048651486524865348654486554865648657486584865948660486614866248663486644866548666486674866848669486704867148672486734867448675486764867748678486794868048681486824868348684486854868648687486884868948690486914869248693486944869548696486974869848699487004870148702487034870448705487064870748708487094871048711487124871348714487154871648717487184871948720487214872248723487244872548726487274872848729487304873148732487334873448735487364873748738487394874048741487424874348744487454874648747487484874948750487514875248753487544875548756487574875848759487604876148762487634876448765487664876748768487694877048771487724877348774487754877648777487784877948780487814878248783487844878548786487874878848789487904879148792487934879448795487964879748798487994880048801488024880348804488054880648807488084880948810488114881248813488144881548816488174881848819488204882148822488234882448825488264882748828488294883048831488324883348834488354883648837488384883948840488414884248843488444884548846488474884848849488504885148852488534885448855488564885748858488594886048861488624886348864488654886648867488684886948870488714887248873488744887548876488774887848879488804888148882488834888448885488864888748888488894889048891488924889348894488954889648897488984889948900489014890248903489044890548906489074890848909489104891148912489134891448915489164891748918489194892048921489224892348924489254892648927489284892948930489314893248933489344893548936489374893848939489404894148942489434894448945489464894748948489494895048951489524895348954489554895648957489584895948960489614896248963489644896548966489674896848969489704897148972489734897448975489764897748978489794898048981489824898348984489854898648987489884898948990489914899248993489944899548996489974899848999490004900149002490034900449005490064900749008490094901049011490124901349014490154901649017490184901949020490214902249023490244902549026490274902849029490304903149032490334903449035490364903749038490394904049041490424904349044490454904649047490484904949050490514905249053490544905549056490574905849059490604906149062490634906449065490664906749068490694907049071490724907349074490754907649077490784907949080490814908249083490844908549086490874908849089490904909149092490934909449095490964909749098490994910049101491024910349104491054910649107491084910949110491114911249113491144911549116491174911849119491204912149122491234912449125491264912749128491294913049131491324913349134491354913649137491384913949140491414914249143491444914549146491474914849149491504915149152491534915449155491564915749158491594916049161491624916349164491654916649167491684916949170491714917249173491744917549176491774917849179491804918149182491834918449185491864918749188491894919049191491924919349194491954919649197491984919949200492014920249203492044920549206492074920849209492104921149212492134921449215492164921749218492194922049221492224922349224492254922649227492284922949230492314923249233492344923549236492374923849239492404924149242492434924449245492464924749248492494925049251492524925349254492554925649257492584925949260492614926249263492644926549266492674926849269492704927149272492734927449275492764927749278492794928049281492824928349284492854928649287492884928949290492914929249293492944929549296492974929849299493004930149302493034930449305493064930749308493094931049311493124931349314493154931649317493184931949320493214932249323493244932549326493274932849329493304933149332493334933449335493364933749338493394934049341493424934349344493454934649347493484934949350493514935249353493544935549356493574935849359493604936149362493634936449365493664936749368493694937049371493724937349374493754937649377493784937949380493814938249383493844938549386493874938849389493904939149392493934939449395493964939749398493994940049401494024940349404494054940649407494084940949410494114941249413494144941549416494174941849419494204942149422494234942449425494264942749428494294943049431494324943349434494354943649437494384943949440494414944249443494444944549446494474944849449494504945149452494534945449455494564945749458494594946049461494624946349464494654946649467494684946949470494714947249473494744947549476494774947849479494804948149482494834948449485494864948749488494894949049491494924949349494494954949649497494984949949500495014950249503495044950549506495074950849509495104951149512495134951449515495164951749518495194952049521495224952349524495254952649527495284952949530495314953249533495344953549536495374953849539495404954149542495434954449545495464954749548495494955049551495524955349554495554955649557495584955949560495614956249563495644956549566495674956849569495704957149572495734957449575495764957749578495794958049581495824958349584495854958649587495884958949590495914959249593495944959549596495974959849599496004960149602496034960449605496064960749608496094961049611496124961349614496154961649617496184961949620496214962249623496244962549626496274962849629496304963149632496334963449635496364963749638496394964049641496424964349644496454964649647496484964949650496514965249653496544965549656496574965849659496604966149662496634966449665496664966749668496694967049671496724967349674496754967649677496784967949680496814968249683496844968549686496874968849689496904969149692496934969449695496964969749698496994970049701497024970349704497054970649707497084970949710497114971249713497144971549716497174971849719497204972149722497234972449725497264972749728497294973049731497324973349734497354973649737497384973949740497414974249743497444974549746497474974849749497504975149752497534975449755497564975749758497594976049761497624976349764497654976649767497684976949770497714977249773497744977549776497774977849779497804978149782497834978449785497864978749788497894979049791497924979349794497954979649797497984979949800498014980249803498044980549806498074980849809498104981149812498134981449815498164981749818498194982049821498224982349824498254982649827498284982949830498314983249833498344983549836498374983849839498404984149842498434984449845498464984749848498494985049851498524985349854498554985649857498584985949860498614986249863498644986549866498674986849869498704987149872498734987449875498764987749878498794988049881498824988349884498854988649887498884988949890498914989249893498944989549896498974989849899499004990149902499034990449905499064990749908499094991049911499124991349914499154991649917499184991949920499214992249923499244992549926499274992849929499304993149932499334993449935499364993749938499394994049941499424994349944499454994649947499484994949950499514995249953499544995549956499574995849959499604996149962499634996449965499664996749968499694997049971499724997349974499754997649977499784997949980499814998249983499844998549986499874998849989499904999149992499934999449995499964999749998499995000050001500025000350004500055000650007500085000950010500115001250013500145001550016500175001850019500205002150022500235002450025500265002750028500295003050031500325003350034500355003650037500385003950040500415004250043500445004550046500475004850049500505005150052500535005450055500565005750058500595006050061500625006350064500655006650067500685006950070500715007250073500745007550076500775007850079500805008150082500835008450085500865008750088500895009050091500925009350094500955009650097500985009950100501015010250103501045010550106501075010850109501105011150112501135011450115501165011750118501195012050121501225012350124501255012650127501285012950130501315013250133501345013550136501375013850139501405014150142501435014450145501465014750148501495015050151501525015350154501555015650157501585015950160501615016250163501645016550166501675016850169501705017150172501735017450175501765017750178501795018050181501825018350184501855018650187501885018950190501915019250193501945019550196501975019850199502005020150202502035020450205502065020750208502095021050211502125021350214502155021650217502185021950220502215022250223502245022550226502275022850229502305023150232502335023450235502365023750238502395024050241502425024350244502455024650247502485024950250502515025250253502545025550256502575025850259502605026150262502635026450265502665026750268502695027050271502725027350274502755027650277502785027950280502815028250283502845028550286502875028850289502905029150292502935029450295502965029750298502995030050301503025030350304503055030650307503085030950310503115031250313503145031550316503175031850319503205032150322503235032450325503265032750328503295033050331503325033350334503355033650337503385033950340503415034250343503445034550346503475034850349503505035150352503535035450355503565035750358503595036050361503625036350364503655036650367503685036950370503715037250373503745037550376503775037850379503805038150382503835038450385503865038750388503895039050391503925039350394503955039650397503985039950400504015040250403504045040550406504075040850409504105041150412504135041450415504165041750418504195042050421504225042350424504255042650427504285042950430504315043250433504345043550436504375043850439504405044150442504435044450445504465044750448504495045050451504525045350454504555045650457504585045950460504615046250463504645046550466504675046850469504705047150472504735047450475504765047750478504795048050481504825048350484504855048650487504885048950490504915049250493504945049550496504975049850499505005050150502505035050450505505065050750508505095051050511505125051350514505155051650517505185051950520505215052250523505245052550526505275052850529505305053150532505335053450535505365053750538505395054050541505425054350544505455054650547505485054950550505515055250553505545055550556505575055850559505605056150562505635056450565505665056750568505695057050571505725057350574505755057650577505785057950580505815058250583505845058550586505875058850589505905059150592505935059450595505965059750598505995060050601506025060350604506055060650607506085060950610506115061250613506145061550616506175061850619506205062150622506235062450625506265062750628506295063050631506325063350634506355063650637506385063950640506415064250643506445064550646506475064850649506505065150652506535065450655506565065750658506595066050661506625066350664506655066650667506685066950670506715067250673506745067550676506775067850679506805068150682506835068450685506865068750688506895069050691506925069350694506955069650697506985069950700507015070250703507045070550706507075070850709507105071150712507135071450715507165071750718507195072050721507225072350724507255072650727507285072950730507315073250733507345073550736507375073850739507405074150742507435074450745507465074750748507495075050751507525075350754507555075650757507585075950760507615076250763507645076550766507675076850769507705077150772507735077450775507765077750778507795078050781507825078350784507855078650787507885078950790507915079250793507945079550796507975079850799508005080150802508035080450805508065080750808508095081050811508125081350814508155081650817508185081950820508215082250823508245082550826508275082850829508305083150832508335083450835508365083750838508395084050841508425084350844508455084650847508485084950850508515085250853508545085550856508575085850859508605086150862508635086450865508665086750868508695087050871508725087350874508755087650877508785087950880508815088250883508845088550886508875088850889508905089150892508935089450895508965089750898508995090050901509025090350904509055090650907509085090950910509115091250913509145091550916509175091850919509205092150922509235092450925509265092750928509295093050931509325093350934509355093650937509385093950940509415094250943509445094550946509475094850949509505095150952509535095450955509565095750958509595096050961509625096350964509655096650967509685096950970509715097250973509745097550976509775097850979509805098150982509835098450985509865098750988509895099050991509925099350994509955099650997509985099951000510015100251003510045100551006510075100851009510105101151012510135101451015510165101751018510195102051021510225102351024510255102651027510285102951030510315103251033510345103551036510375103851039510405104151042510435104451045510465104751048510495105051051510525105351054510555105651057510585105951060510615106251063510645106551066510675106851069510705107151072510735107451075510765107751078510795108051081510825108351084510855108651087510885108951090510915109251093510945109551096510975109851099511005110151102511035110451105511065110751108511095111051111511125111351114511155111651117511185111951120511215112251123511245112551126511275112851129511305113151132511335113451135511365113751138511395114051141511425114351144511455114651147511485114951150511515115251153511545115551156511575115851159511605116151162511635116451165511665116751168511695117051171511725117351174511755117651177511785117951180511815118251183511845118551186511875118851189511905119151192511935119451195511965119751198511995120051201512025120351204512055120651207512085120951210512115121251213512145121551216512175121851219512205122151222512235122451225512265122751228512295123051231512325123351234512355123651237512385123951240512415124251243512445124551246512475124851249512505125151252512535125451255512565125751258512595126051261512625126351264512655126651267512685126951270512715127251273512745127551276512775127851279512805128151282512835128451285512865128751288512895129051291512925129351294512955129651297512985129951300513015130251303513045130551306513075130851309513105131151312513135131451315513165131751318513195132051321513225132351324513255132651327513285132951330513315133251333513345133551336513375133851339513405134151342513435134451345513465134751348513495135051351513525135351354513555135651357513585135951360513615136251363513645136551366513675136851369513705137151372513735137451375513765137751378513795138051381513825138351384513855138651387513885138951390513915139251393513945139551396513975139851399514005140151402514035140451405514065140751408514095141051411514125141351414514155141651417514185141951420514215142251423514245142551426514275142851429514305143151432514335143451435514365143751438514395144051441514425144351444514455144651447514485144951450514515145251453514545145551456514575145851459514605146151462514635146451465514665146751468514695147051471514725147351474514755147651477514785147951480514815148251483514845148551486514875148851489514905149151492514935149451495514965149751498514995150051501515025150351504515055150651507515085150951510515115151251513515145151551516515175151851519515205152151522515235152451525515265152751528515295153051531515325153351534515355153651537515385153951540515415154251543515445154551546515475154851549515505155151552515535155451555515565155751558515595156051561515625156351564515655156651567515685156951570515715157251573515745157551576515775157851579515805158151582515835158451585515865158751588515895159051591515925159351594515955159651597515985159951600516015160251603516045160551606516075160851609516105161151612516135161451615516165161751618516195162051621516225162351624516255162651627516285162951630516315163251633516345163551636516375163851639516405164151642516435164451645516465164751648516495165051651516525165351654516555165651657516585165951660516615166251663516645166551666516675166851669516705167151672516735167451675516765167751678516795168051681516825168351684516855168651687516885168951690516915169251693516945169551696516975169851699517005170151702517035170451705517065170751708517095171051711517125171351714517155171651717517185171951720517215172251723517245172551726517275172851729517305173151732517335173451735517365173751738517395174051741517425174351744517455174651747517485174951750517515175251753517545175551756517575175851759517605176151762517635176451765517665176751768517695177051771517725177351774517755177651777517785177951780517815178251783517845178551786517875178851789517905179151792517935179451795517965179751798517995180051801518025180351804518055180651807518085180951810518115181251813518145181551816518175181851819518205182151822518235182451825518265182751828518295183051831518325183351834518355183651837518385183951840518415184251843518445184551846518475184851849518505185151852518535185451855518565185751858518595186051861518625186351864518655186651867518685186951870518715187251873518745187551876518775187851879518805188151882518835188451885518865188751888518895189051891518925189351894518955189651897518985189951900519015190251903519045190551906519075190851909519105191151912519135191451915519165191751918519195192051921519225192351924519255192651927519285192951930519315193251933519345193551936519375193851939519405194151942519435194451945519465194751948519495195051951519525195351954519555195651957519585195951960519615196251963519645196551966519675196851969519705197151972519735197451975519765197751978519795198051981519825198351984519855198651987519885198951990519915199251993519945199551996519975199851999520005200152002520035200452005520065200752008520095201052011520125201352014520155201652017520185201952020520215202252023520245202552026520275202852029520305203152032520335203452035520365203752038520395204052041520425204352044520455204652047520485204952050520515205252053520545205552056520575205852059520605206152062520635206452065520665206752068520695207052071520725207352074520755207652077520785207952080520815208252083520845208552086520875208852089520905209152092520935209452095520965209752098520995210052101521025210352104521055210652107521085210952110521115211252113521145211552116521175211852119521205212152122521235212452125521265212752128521295213052131521325213352134521355213652137521385213952140521415214252143521445214552146521475214852149521505215152152521535215452155521565215752158521595216052161521625216352164521655216652167521685216952170521715217252173521745217552176521775217852179521805218152182521835218452185521865218752188521895219052191521925219352194521955219652197521985219952200522015220252203522045220552206522075220852209522105221152212522135221452215522165221752218522195222052221522225222352224522255222652227522285222952230522315223252233522345223552236522375223852239522405224152242522435224452245522465224752248522495225052251522525225352254522555225652257522585225952260522615226252263522645226552266522675226852269522705227152272522735227452275522765227752278522795228052281522825228352284522855228652287522885228952290522915229252293522945229552296522975229852299523005230152302523035230452305523065230752308523095231052311523125231352314523155231652317523185231952320523215232252323523245232552326523275232852329523305233152332523335233452335523365233752338523395234052341523425234352344523455234652347523485234952350523515235252353523545235552356523575235852359523605236152362523635236452365523665236752368523695237052371523725237352374523755237652377523785237952380523815238252383523845238552386523875238852389523905239152392523935239452395523965239752398523995240052401524025240352404524055240652407524085240952410524115241252413524145241552416524175241852419524205242152422524235242452425524265242752428524295243052431524325243352434524355243652437524385243952440524415244252443524445244552446524475244852449524505245152452524535245452455524565245752458524595246052461524625246352464524655246652467524685246952470524715247252473524745247552476524775247852479524805248152482524835248452485524865248752488524895249052491524925249352494524955249652497524985249952500525015250252503525045250552506525075250852509525105251152512525135251452515525165251752518525195252052521525225252352524525255252652527525285252952530525315253252533525345253552536525375253852539525405254152542525435254452545525465254752548525495255052551525525255352554525555255652557525585255952560525615256252563525645256552566525675256852569525705257152572525735257452575525765257752578525795258052581525825258352584525855258652587525885258952590525915259252593525945259552596525975259852599526005260152602526035260452605526065260752608526095261052611526125261352614526155261652617526185261952620526215262252623526245262552626526275262852629526305263152632526335263452635526365263752638526395264052641526425264352644526455264652647526485264952650526515265252653526545265552656526575265852659526605266152662526635266452665526665266752668526695267052671526725267352674526755267652677526785267952680526815268252683526845268552686526875268852689526905269152692526935269452695526965269752698526995270052701527025270352704527055270652707527085270952710527115271252713527145271552716527175271852719527205272152722527235272452725527265272752728527295273052731527325273352734527355273652737527385273952740527415274252743527445274552746527475274852749527505275152752527535275452755527565275752758527595276052761527625276352764527655276652767527685276952770527715277252773527745277552776527775277852779527805278152782527835278452785527865278752788527895279052791527925279352794527955279652797527985279952800528015280252803528045280552806528075280852809528105281152812528135281452815528165281752818528195282052821528225282352824528255282652827528285282952830528315283252833528345283552836528375283852839528405284152842528435284452845528465284752848528495285052851528525285352854528555285652857528585285952860528615286252863528645286552866528675286852869528705287152872528735287452875528765287752878528795288052881528825288352884528855288652887528885288952890528915289252893528945289552896528975289852899529005290152902529035290452905529065290752908529095291052911529125291352914529155291652917529185291952920529215292252923529245292552926529275292852929529305293152932529335293452935529365293752938529395294052941529425294352944529455294652947529485294952950529515295252953529545295552956529575295852959529605296152962529635296452965529665296752968529695297052971529725297352974529755297652977529785297952980529815298252983529845298552986529875298852989529905299152992529935299452995529965299752998529995300053001530025300353004530055300653007530085300953010530115301253013530145301553016530175301853019530205302153022530235302453025530265302753028530295303053031530325303353034530355303653037530385303953040530415304253043530445304553046530475304853049530505305153052530535305453055530565305753058530595306053061530625306353064530655306653067530685306953070530715307253073530745307553076530775307853079530805308153082530835308453085530865308753088530895309053091530925309353094530955309653097530985309953100531015310253103531045310553106531075310853109531105311153112531135311453115531165311753118531195312053121531225312353124531255312653127531285312953130531315313253133531345313553136531375313853139531405314153142531435314453145531465314753148531495315053151531525315353154531555315653157531585315953160531615316253163531645316553166531675316853169531705317153172531735317453175531765317753178531795318053181531825318353184531855318653187531885318953190531915319253193531945319553196531975319853199532005320153202532035320453205532065320753208532095321053211532125321353214532155321653217532185321953220532215322253223532245322553226532275322853229532305323153232532335323453235532365323753238532395324053241532425324353244532455324653247532485324953250532515325253253532545325553256532575325853259532605326153262532635326453265532665326753268532695327053271532725327353274532755327653277532785327953280532815328253283532845328553286532875328853289532905329153292532935329453295532965329753298532995330053301533025330353304533055330653307533085330953310533115331253313533145331553316533175331853319533205332153322533235332453325533265332753328533295333053331533325333353334533355333653337533385333953340533415334253343533445334553346533475334853349533505335153352533535335453355533565335753358533595336053361533625336353364533655336653367533685336953370533715337253373533745337553376533775337853379533805338153382533835338453385533865338753388533895339053391533925339353394533955339653397533985339953400534015340253403534045340553406534075340853409534105341153412534135341453415534165341753418534195342053421534225342353424534255342653427534285342953430534315343253433534345343553436534375343853439534405344153442534435344453445534465344753448534495345053451534525345353454534555345653457534585345953460534615346253463534645346553466534675346853469534705347153472534735347453475534765347753478534795348053481534825348353484534855348653487534885348953490534915349253493534945349553496534975349853499535005350153502535035350453505535065350753508535095351053511535125351353514535155351653517535185351953520535215352253523535245352553526535275352853529535305353153532535335353453535535365353753538535395354053541535425354353544535455354653547535485354953550535515355253553535545355553556535575355853559535605356153562535635356453565535665356753568535695357053571535725357353574535755357653577535785357953580535815358253583535845358553586535875358853589535905359153592535935359453595535965359753598535995360053601536025360353604536055360653607536085360953610536115361253613536145361553616536175361853619536205362153622536235362453625536265362753628536295363053631536325363353634536355363653637536385363953640536415364253643536445364553646536475364853649536505365153652536535365453655536565365753658536595366053661536625366353664536655366653667536685366953670536715367253673536745367553676536775367853679536805368153682536835368453685536865368753688536895369053691536925369353694536955369653697536985369953700537015370253703537045370553706537075370853709537105371153712537135371453715537165371753718537195372053721537225372353724537255372653727537285372953730537315373253733537345373553736537375373853739537405374153742537435374453745537465374753748537495375053751537525375353754537555375653757537585375953760537615376253763537645376553766537675376853769537705377153772537735377453775537765377753778537795378053781537825378353784537855378653787537885378953790537915379253793537945379553796537975379853799538005380153802538035380453805538065380753808538095381053811538125381353814538155381653817538185381953820538215382253823538245382553826538275382853829538305383153832538335383453835538365383753838538395384053841538425384353844538455384653847538485384953850538515385253853538545385553856538575385853859538605386153862538635386453865538665386753868538695387053871538725387353874538755387653877538785387953880538815388253883538845388553886538875388853889538905389153892538935389453895538965389753898538995390053901539025390353904539055390653907539085390953910539115391253913539145391553916539175391853919539205392153922539235392453925539265392753928539295393053931539325393353934539355393653937539385393953940539415394253943539445394553946539475394853949539505395153952539535395453955539565395753958539595396053961539625396353964539655396653967539685396953970539715397253973539745397553976539775397853979539805398153982539835398453985539865398753988539895399053991539925399353994539955399653997539985399954000540015400254003540045400554006540075400854009540105401154012540135401454015540165401754018540195402054021540225402354024540255402654027540285402954030540315403254033540345403554036540375403854039540405404154042540435404454045540465404754048540495405054051540525405354054540555405654057540585405954060540615406254063540645406554066540675406854069540705407154072540735407454075540765407754078540795408054081540825408354084540855408654087540885408954090540915409254093540945409554096540975409854099541005410154102541035410454105541065410754108541095411054111541125411354114541155411654117541185411954120541215412254123541245412554126541275412854129541305413154132541335413454135541365413754138541395414054141541425414354144541455414654147541485414954150541515415254153541545415554156541575415854159541605416154162541635416454165541665416754168541695417054171541725417354174541755417654177541785417954180541815418254183541845418554186541875418854189541905419154192541935419454195541965419754198541995420054201542025420354204542055420654207542085420954210542115421254213542145421554216542175421854219542205422154222542235422454225542265422754228542295423054231542325423354234542355423654237542385423954240542415424254243542445424554246542475424854249542505425154252542535425454255542565425754258542595426054261542625426354264542655426654267542685426954270542715427254273542745427554276542775427854279542805428154282542835428454285542865428754288542895429054291542925429354294542955429654297542985429954300543015430254303543045430554306543075430854309543105431154312543135431454315543165431754318543195432054321543225432354324543255432654327543285432954330543315433254333543345433554336543375433854339543405434154342543435434454345543465434754348543495435054351543525435354354543555435654357543585435954360543615436254363543645436554366543675436854369543705437154372543735437454375543765437754378543795438054381543825438354384543855438654387543885438954390543915439254393543945439554396543975439854399544005440154402544035440454405544065440754408544095441054411544125441354414544155441654417544185441954420544215442254423544245442554426544275442854429544305443154432544335443454435544365443754438544395444054441544425444354444544455444654447544485444954450544515445254453544545445554456544575445854459544605446154462544635446454465544665446754468544695447054471544725447354474544755447654477544785447954480544815448254483544845448554486544875448854489544905449154492544935449454495544965449754498544995450054501545025450354504545055450654507545085450954510545115451254513545145451554516545175451854519545205452154522545235452454525545265452754528545295453054531545325453354534545355453654537545385453954540545415454254543545445454554546545475454854549545505455154552545535455454555545565455754558545595456054561545625456354564545655456654567545685456954570545715457254573545745457554576545775457854579545805458154582545835458454585545865458754588545895459054591545925459354594545955459654597545985459954600546015460254603546045460554606546075460854609546105461154612546135461454615546165461754618546195462054621546225462354624546255462654627546285462954630546315463254633546345463554636546375463854639546405464154642546435464454645546465464754648546495465054651546525465354654546555465654657546585465954660546615466254663546645466554666546675466854669546705467154672546735467454675546765467754678546795468054681546825468354684546855468654687546885468954690546915469254693546945469554696546975469854699547005470154702547035470454705547065470754708547095471054711547125471354714547155471654717547185471954720547215472254723547245472554726547275472854729547305473154732547335473454735547365473754738547395474054741547425474354744547455474654747547485474954750547515475254753547545475554756547575475854759547605476154762547635476454765547665476754768547695477054771547725477354774547755477654777547785477954780547815478254783547845478554786547875478854789547905479154792547935479454795547965479754798547995480054801548025480354804548055480654807548085480954810548115481254813548145481554816548175481854819548205482154822548235482454825548265482754828548295483054831548325483354834548355483654837548385483954840548415484254843548445484554846548475484854849548505485154852548535485454855548565485754858548595486054861548625486354864548655486654867548685486954870548715487254873548745487554876548775487854879548805488154882548835488454885548865488754888548895489054891548925489354894548955489654897548985489954900549015490254903549045490554906549075490854909549105491154912549135491454915549165491754918549195492054921549225492354924549255492654927549285492954930549315493254933549345493554936549375493854939549405494154942549435494454945549465494754948549495495054951549525495354954549555495654957549585495954960549615496254963549645496554966549675496854969549705497154972549735497454975549765497754978549795498054981549825498354984549855498654987549885498954990549915499254993549945499554996549975499854999550005500155002550035500455005550065500755008550095501055011550125501355014550155501655017550185501955020550215502255023550245502555026550275502855029550305503155032550335503455035550365503755038550395504055041550425504355044550455504655047550485504955050550515505255053550545505555056550575505855059550605506155062550635506455065550665506755068550695507055071550725507355074550755507655077550785507955080550815508255083550845508555086550875508855089550905509155092550935509455095550965509755098550995510055101551025510355104551055510655107551085510955110551115511255113551145511555116551175511855119551205512155122551235512455125551265512755128551295513055131551325513355134551355513655137551385513955140551415514255143551445514555146551475514855149551505515155152551535515455155551565515755158551595516055161551625516355164551655516655167551685516955170551715517255173551745517555176551775517855179551805518155182551835518455185551865518755188551895519055191551925519355194551955519655197551985519955200552015520255203552045520555206552075520855209552105521155212552135521455215552165521755218552195522055221552225522355224552255522655227552285522955230552315523255233552345523555236552375523855239552405524155242552435524455245552465524755248552495525055251552525525355254552555525655257552585525955260552615526255263552645526555266552675526855269552705527155272552735527455275552765527755278552795528055281552825528355284552855528655287552885528955290552915529255293552945529555296552975529855299553005530155302553035530455305553065530755308553095531055311553125531355314553155531655317553185531955320553215532255323553245532555326553275532855329553305533155332553335533455335553365533755338553395534055341553425534355344553455534655347553485534955350553515535255353553545535555356553575535855359553605536155362553635536455365553665536755368553695537055371553725537355374553755537655377553785537955380553815538255383553845538555386553875538855389553905539155392553935539455395553965539755398553995540055401554025540355404554055540655407554085540955410554115541255413554145541555416554175541855419554205542155422554235542455425554265542755428554295543055431554325543355434554355543655437554385543955440554415544255443554445544555446554475544855449554505545155452554535545455455554565545755458554595546055461554625546355464554655546655467554685546955470554715547255473554745547555476554775547855479554805548155482554835548455485554865548755488554895549055491554925549355494554955549655497554985549955500555015550255503555045550555506555075550855509555105551155512555135551455515555165551755518555195552055521555225552355524555255552655527555285552955530555315553255533555345553555536555375553855539555405554155542555435554455545555465554755548555495555055551555525555355554555555555655557555585555955560555615556255563555645556555566555675556855569555705557155572555735557455575555765557755578555795558055581555825558355584555855558655587555885558955590555915559255593555945559555596555975559855599556005560155602556035560455605556065560755608556095561055611556125561355614556155561655617556185561955620556215562255623556245562555626556275562855629556305563155632556335563455635556365563755638556395564055641556425564355644556455564655647556485564955650556515565255653556545565555656556575565855659556605566155662556635566455665556665566755668556695567055671556725567355674556755567655677556785567955680556815568255683556845568555686556875568855689556905569155692556935569455695556965569755698556995570055701557025570355704557055570655707557085570955710557115571255713557145571555716557175571855719557205572155722557235572455725557265572755728557295573055731557325573355734557355573655737557385573955740557415574255743557445574555746557475574855749557505575155752557535575455755557565575755758557595576055761557625576355764557655576655767557685576955770557715577255773557745577555776557775577855779557805578155782557835578455785557865578755788557895579055791557925579355794557955579655797557985579955800558015580255803558045580555806558075580855809558105581155812558135581455815558165581755818558195582055821558225582355824558255582655827558285582955830558315583255833558345583555836558375583855839558405584155842558435584455845558465584755848558495585055851558525585355854558555585655857558585585955860558615586255863558645586555866558675586855869558705587155872558735587455875558765587755878558795588055881558825588355884558855588655887558885588955890558915589255893558945589555896558975589855899559005590155902559035590455905559065590755908559095591055911559125591355914559155591655917559185591955920559215592255923559245592555926559275592855929559305593155932559335593455935559365593755938559395594055941559425594355944559455594655947559485594955950559515595255953559545595555956559575595855959559605596155962559635596455965559665596755968559695597055971559725597355974559755597655977559785597955980559815598255983559845598555986559875598855989559905599155992559935599455995559965599755998559995600056001560025600356004560055600656007560085600956010560115601256013560145601556016560175601856019560205602156022560235602456025560265602756028560295603056031560325603356034560355603656037560385603956040560415604256043560445604556046560475604856049560505605156052560535605456055560565605756058560595606056061560625606356064560655606656067560685606956070560715607256073560745607556076560775607856079560805608156082560835608456085560865608756088560895609056091560925609356094560955609656097560985609956100561015610256103561045610556106561075610856109561105611156112561135611456115561165611756118561195612056121561225612356124561255612656127561285612956130561315613256133561345613556136561375613856139561405614156142561435614456145561465614756148561495615056151561525615356154561555615656157561585615956160561615616256163561645616556166561675616856169561705617156172561735617456175561765617756178561795618056181561825618356184561855618656187561885618956190561915619256193561945619556196561975619856199562005620156202562035620456205562065620756208562095621056211562125621356214562155621656217562185621956220562215622256223562245622556226562275622856229562305623156232562335623456235562365623756238562395624056241562425624356244562455624656247562485624956250562515625256253562545625556256562575625856259562605626156262562635626456265562665626756268562695627056271562725627356274562755627656277562785627956280562815628256283562845628556286562875628856289562905629156292562935629456295562965629756298562995630056301563025630356304563055630656307563085630956310563115631256313563145631556316563175631856319563205632156322563235632456325563265632756328563295633056331563325633356334563355633656337563385633956340563415634256343563445634556346563475634856349563505635156352563535635456355563565635756358563595636056361563625636356364563655636656367563685636956370563715637256373563745637556376563775637856379563805638156382563835638456385563865638756388563895639056391563925639356394563955639656397563985639956400564015640256403564045640556406564075640856409564105641156412564135641456415564165641756418564195642056421564225642356424564255642656427564285642956430564315643256433564345643556436564375643856439564405644156442564435644456445564465644756448564495645056451564525645356454564555645656457564585645956460564615646256463564645646556466564675646856469564705647156472564735647456475564765647756478564795648056481564825648356484564855648656487564885648956490
  1. (function webpackUniversalModuleDefinition(root, factory) {
  2. if(typeof exports === 'object' && typeof module === 'object')
  3. module.exports = factory();
  4. else if(typeof define === 'function' && define.amd)
  5. define([], factory);
  6. else if(typeof exports === 'object')
  7. exports["grapesjs"] = factory();
  8. else
  9. root["grapesjs"] = factory();
  10. })(window, function() {
  11. return /******/ (function(modules) { // webpackBootstrap
  12. /******/ // The module cache
  13. /******/ var installedModules = {};
  14. /******/
  15. /******/ // The require function
  16. /******/ function __webpack_require__(moduleId) {
  17. /******/
  18. /******/ // Check if module is in cache
  19. /******/ if(installedModules[moduleId]) {
  20. /******/ return installedModules[moduleId].exports;
  21. /******/ }
  22. /******/ // Create a new module (and put it into the cache)
  23. /******/ var module = installedModules[moduleId] = {
  24. /******/ i: moduleId,
  25. /******/ l: false,
  26. /******/ exports: {}
  27. /******/ };
  28. /******/
  29. /******/ // Execute the module function
  30. /******/ modules[moduleId].call(module.exports, module, module.exports, __webpack_require__);
  31. /******/
  32. /******/ // Flag the module as loaded
  33. /******/ module.l = true;
  34. /******/
  35. /******/ // Return the exports of the module
  36. /******/ return module.exports;
  37. /******/ }
  38. /******/
  39. /******/
  40. /******/ // expose the modules object (__webpack_modules__)
  41. /******/ __webpack_require__.m = modules;
  42. /******/
  43. /******/ // expose the module cache
  44. /******/ __webpack_require__.c = installedModules;
  45. /******/
  46. /******/ // define getter function for harmony exports
  47. /******/ __webpack_require__.d = function(exports, name, getter) {
  48. /******/ if(!__webpack_require__.o(exports, name)) {
  49. /******/ Object.defineProperty(exports, name, { enumerable: true, get: getter });
  50. /******/ }
  51. /******/ };
  52. /******/
  53. /******/ // define __esModule on exports
  54. /******/ __webpack_require__.r = function(exports) {
  55. /******/ if(typeof Symbol !== 'undefined' && Symbol.toStringTag) {
  56. /******/ Object.defineProperty(exports, Symbol.toStringTag, { value: 'Module' });
  57. /******/ }
  58. /******/ Object.defineProperty(exports, '__esModule', { value: true });
  59. /******/ };
  60. /******/
  61. /******/ // create a fake namespace object
  62. /******/ // mode & 1: value is a module id, require it
  63. /******/ // mode & 2: merge all properties of value into the ns
  64. /******/ // mode & 4: return value when already ns object
  65. /******/ // mode & 8|1: behave like require
  66. /******/ __webpack_require__.t = function(value, mode) {
  67. /******/ if(mode & 1) value = __webpack_require__(value);
  68. /******/ if(mode & 8) return value;
  69. /******/ if((mode & 4) && typeof value === 'object' && value && value.__esModule) return value;
  70. /******/ var ns = Object.create(null);
  71. /******/ __webpack_require__.r(ns);
  72. /******/ Object.defineProperty(ns, 'default', { enumerable: true, value: value });
  73. /******/ if(mode & 2 && typeof value != 'string') for(var key in value) __webpack_require__.d(ns, key, function(key) { return value[key]; }.bind(null, key));
  74. /******/ return ns;
  75. /******/ };
  76. /******/
  77. /******/ // getDefaultExport function for compatibility with non-harmony modules
  78. /******/ __webpack_require__.n = function(module) {
  79. /******/ var getter = module && module.__esModule ?
  80. /******/ function getDefault() { return module['default']; } :
  81. /******/ function getModuleExports() { return module; };
  82. /******/ __webpack_require__.d(getter, 'a', getter);
  83. /******/ return getter;
  84. /******/ };
  85. /******/
  86. /******/ // Object.prototype.hasOwnProperty.call
  87. /******/ __webpack_require__.o = function(object, property) { return Object.prototype.hasOwnProperty.call(object, property); };
  88. /******/
  89. /******/ // __webpack_public_path__
  90. /******/ __webpack_require__.p = "";
  91. /******/
  92. /******/
  93. /******/ // Load entry module and return exports
  94. /******/ return __webpack_require__(__webpack_require__.s = "./src/index.js");
  95. /******/ })
  96. /************************************************************************/
  97. /******/ ({
  98. /***/ "./node_modules/@babel/runtime/helpers/arrayWithHoles.js":
  99. /*!***************************************************************!*\
  100. !*** ./node_modules/@babel/runtime/helpers/arrayWithHoles.js ***!
  101. \***************************************************************/
  102. /*! no static exports found */
  103. /***/ (function(module, exports) {
  104. function _arrayWithHoles(arr) {
  105. if (Array.isArray(arr)) return arr;
  106. }
  107. module.exports = _arrayWithHoles;
  108. /***/ }),
  109. /***/ "./node_modules/@babel/runtime/helpers/arrayWithoutHoles.js":
  110. /*!******************************************************************!*\
  111. !*** ./node_modules/@babel/runtime/helpers/arrayWithoutHoles.js ***!
  112. \******************************************************************/
  113. /*! no static exports found */
  114. /***/ (function(module, exports) {
  115. function _arrayWithoutHoles(arr) {
  116. if (Array.isArray(arr)) {
  117. for (var i = 0, arr2 = new Array(arr.length); i < arr.length; i++) {
  118. arr2[i] = arr[i];
  119. }
  120. return arr2;
  121. }
  122. }
  123. module.exports = _arrayWithoutHoles;
  124. /***/ }),
  125. /***/ "./node_modules/@babel/runtime/helpers/classCallCheck.js":
  126. /*!***************************************************************!*\
  127. !*** ./node_modules/@babel/runtime/helpers/classCallCheck.js ***!
  128. \***************************************************************/
  129. /*! no static exports found */
  130. /***/ (function(module, exports) {
  131. function _classCallCheck(instance, Constructor) {
  132. if (!(instance instanceof Constructor)) {
  133. throw new TypeError("Cannot call a class as a function");
  134. }
  135. }
  136. module.exports = _classCallCheck;
  137. /***/ }),
  138. /***/ "./node_modules/@babel/runtime/helpers/createClass.js":
  139. /*!************************************************************!*\
  140. !*** ./node_modules/@babel/runtime/helpers/createClass.js ***!
  141. \************************************************************/
  142. /*! no static exports found */
  143. /***/ (function(module, exports) {
  144. function _defineProperties(target, props) {
  145. for (var i = 0; i < props.length; i++) {
  146. var descriptor = props[i];
  147. descriptor.enumerable = descriptor.enumerable || false;
  148. descriptor.configurable = true;
  149. if ("value" in descriptor) descriptor.writable = true;
  150. Object.defineProperty(target, descriptor.key, descriptor);
  151. }
  152. }
  153. function _createClass(Constructor, protoProps, staticProps) {
  154. if (protoProps) _defineProperties(Constructor.prototype, protoProps);
  155. if (staticProps) _defineProperties(Constructor, staticProps);
  156. return Constructor;
  157. }
  158. module.exports = _createClass;
  159. /***/ }),
  160. /***/ "./node_modules/@babel/runtime/helpers/defineProperty.js":
  161. /*!***************************************************************!*\
  162. !*** ./node_modules/@babel/runtime/helpers/defineProperty.js ***!
  163. \***************************************************************/
  164. /*! no static exports found */
  165. /***/ (function(module, exports) {
  166. function _defineProperty(obj, key, value) {
  167. if (key in obj) {
  168. Object.defineProperty(obj, key, {
  169. value: value,
  170. enumerable: true,
  171. configurable: true,
  172. writable: true
  173. });
  174. } else {
  175. obj[key] = value;
  176. }
  177. return obj;
  178. }
  179. module.exports = _defineProperty;
  180. /***/ }),
  181. /***/ "./node_modules/@babel/runtime/helpers/iterableToArray.js":
  182. /*!****************************************************************!*\
  183. !*** ./node_modules/@babel/runtime/helpers/iterableToArray.js ***!
  184. \****************************************************************/
  185. /*! no static exports found */
  186. /***/ (function(module, exports) {
  187. function _iterableToArray(iter) {
  188. if (Symbol.iterator in Object(iter) || Object.prototype.toString.call(iter) === "[object Arguments]") return Array.from(iter);
  189. }
  190. module.exports = _iterableToArray;
  191. /***/ }),
  192. /***/ "./node_modules/@babel/runtime/helpers/iterableToArrayLimit.js":
  193. /*!*********************************************************************!*\
  194. !*** ./node_modules/@babel/runtime/helpers/iterableToArrayLimit.js ***!
  195. \*********************************************************************/
  196. /*! no static exports found */
  197. /***/ (function(module, exports) {
  198. function _iterableToArrayLimit(arr, i) {
  199. if (!(Symbol.iterator in Object(arr) || Object.prototype.toString.call(arr) === "[object Arguments]")) {
  200. return;
  201. }
  202. var _arr = [];
  203. var _n = true;
  204. var _d = false;
  205. var _e = undefined;
  206. try {
  207. for (var _i = arr[Symbol.iterator](), _s; !(_n = (_s = _i.next()).done); _n = true) {
  208. _arr.push(_s.value);
  209. if (i && _arr.length === i) break;
  210. }
  211. } catch (err) {
  212. _d = true;
  213. _e = err;
  214. } finally {
  215. try {
  216. if (!_n && _i["return"] != null) _i["return"]();
  217. } finally {
  218. if (_d) throw _e;
  219. }
  220. }
  221. return _arr;
  222. }
  223. module.exports = _iterableToArrayLimit;
  224. /***/ }),
  225. /***/ "./node_modules/@babel/runtime/helpers/nonIterableRest.js":
  226. /*!****************************************************************!*\
  227. !*** ./node_modules/@babel/runtime/helpers/nonIterableRest.js ***!
  228. \****************************************************************/
  229. /*! no static exports found */
  230. /***/ (function(module, exports) {
  231. function _nonIterableRest() {
  232. throw new TypeError("Invalid attempt to destructure non-iterable instance");
  233. }
  234. module.exports = _nonIterableRest;
  235. /***/ }),
  236. /***/ "./node_modules/@babel/runtime/helpers/nonIterableSpread.js":
  237. /*!******************************************************************!*\
  238. !*** ./node_modules/@babel/runtime/helpers/nonIterableSpread.js ***!
  239. \******************************************************************/
  240. /*! no static exports found */
  241. /***/ (function(module, exports) {
  242. function _nonIterableSpread() {
  243. throw new TypeError("Invalid attempt to spread non-iterable instance");
  244. }
  245. module.exports = _nonIterableSpread;
  246. /***/ }),
  247. /***/ "./node_modules/@babel/runtime/helpers/objectWithoutProperties.js":
  248. /*!************************************************************************!*\
  249. !*** ./node_modules/@babel/runtime/helpers/objectWithoutProperties.js ***!
  250. \************************************************************************/
  251. /*! no static exports found */
  252. /***/ (function(module, exports, __webpack_require__) {
  253. var objectWithoutPropertiesLoose = __webpack_require__(/*! ./objectWithoutPropertiesLoose */ "./node_modules/@babel/runtime/helpers/objectWithoutPropertiesLoose.js");
  254. function _objectWithoutProperties(source, excluded) {
  255. if (source == null) return {};
  256. var target = objectWithoutPropertiesLoose(source, excluded);
  257. var key, i;
  258. if (Object.getOwnPropertySymbols) {
  259. var sourceSymbolKeys = Object.getOwnPropertySymbols(source);
  260. for (i = 0; i < sourceSymbolKeys.length; i++) {
  261. key = sourceSymbolKeys[i];
  262. if (excluded.indexOf(key) >= 0) continue;
  263. if (!Object.prototype.propertyIsEnumerable.call(source, key)) continue;
  264. target[key] = source[key];
  265. }
  266. }
  267. return target;
  268. }
  269. module.exports = _objectWithoutProperties;
  270. /***/ }),
  271. /***/ "./node_modules/@babel/runtime/helpers/objectWithoutPropertiesLoose.js":
  272. /*!*****************************************************************************!*\
  273. !*** ./node_modules/@babel/runtime/helpers/objectWithoutPropertiesLoose.js ***!
  274. \*****************************************************************************/
  275. /*! no static exports found */
  276. /***/ (function(module, exports) {
  277. function _objectWithoutPropertiesLoose(source, excluded) {
  278. if (source == null) return {};
  279. var target = {};
  280. var sourceKeys = Object.keys(source);
  281. var key, i;
  282. for (i = 0; i < sourceKeys.length; i++) {
  283. key = sourceKeys[i];
  284. if (excluded.indexOf(key) >= 0) continue;
  285. target[key] = source[key];
  286. }
  287. return target;
  288. }
  289. module.exports = _objectWithoutPropertiesLoose;
  290. /***/ }),
  291. /***/ "./node_modules/@babel/runtime/helpers/slicedToArray.js":
  292. /*!**************************************************************!*\
  293. !*** ./node_modules/@babel/runtime/helpers/slicedToArray.js ***!
  294. \**************************************************************/
  295. /*! no static exports found */
  296. /***/ (function(module, exports, __webpack_require__) {
  297. var arrayWithHoles = __webpack_require__(/*! ./arrayWithHoles */ "./node_modules/@babel/runtime/helpers/arrayWithHoles.js");
  298. var iterableToArrayLimit = __webpack_require__(/*! ./iterableToArrayLimit */ "./node_modules/@babel/runtime/helpers/iterableToArrayLimit.js");
  299. var nonIterableRest = __webpack_require__(/*! ./nonIterableRest */ "./node_modules/@babel/runtime/helpers/nonIterableRest.js");
  300. function _slicedToArray(arr, i) {
  301. return arrayWithHoles(arr) || iterableToArrayLimit(arr, i) || nonIterableRest();
  302. }
  303. module.exports = _slicedToArray;
  304. /***/ }),
  305. /***/ "./node_modules/@babel/runtime/helpers/toConsumableArray.js":
  306. /*!******************************************************************!*\
  307. !*** ./node_modules/@babel/runtime/helpers/toConsumableArray.js ***!
  308. \******************************************************************/
  309. /*! no static exports found */
  310. /***/ (function(module, exports, __webpack_require__) {
  311. var arrayWithoutHoles = __webpack_require__(/*! ./arrayWithoutHoles */ "./node_modules/@babel/runtime/helpers/arrayWithoutHoles.js");
  312. var iterableToArray = __webpack_require__(/*! ./iterableToArray */ "./node_modules/@babel/runtime/helpers/iterableToArray.js");
  313. var nonIterableSpread = __webpack_require__(/*! ./nonIterableSpread */ "./node_modules/@babel/runtime/helpers/nonIterableSpread.js");
  314. function _toConsumableArray(arr) {
  315. return arrayWithoutHoles(arr) || iterableToArray(arr) || nonIterableSpread();
  316. }
  317. module.exports = _toConsumableArray;
  318. /***/ }),
  319. /***/ "./node_modules/@babel/runtime/helpers/typeof.js":
  320. /*!*******************************************************!*\
  321. !*** ./node_modules/@babel/runtime/helpers/typeof.js ***!
  322. \*******************************************************/
  323. /*! no static exports found */
  324. /***/ (function(module, exports) {
  325. function _typeof2(obj) { if (typeof Symbol === "function" && typeof Symbol.iterator === "symbol") { _typeof2 = function _typeof2(obj) { return typeof obj; }; } else { _typeof2 = function _typeof2(obj) { return obj && typeof Symbol === "function" && obj.constructor === Symbol && obj !== Symbol.prototype ? "symbol" : typeof obj; }; } return _typeof2(obj); }
  326. function _typeof(obj) {
  327. if (typeof Symbol === "function" && _typeof2(Symbol.iterator) === "symbol") {
  328. module.exports = _typeof = function _typeof(obj) {
  329. return _typeof2(obj);
  330. };
  331. } else {
  332. module.exports = _typeof = function _typeof(obj) {
  333. return obj && typeof Symbol === "function" && obj.constructor === Symbol && obj !== Symbol.prototype ? "symbol" : _typeof2(obj);
  334. };
  335. }
  336. return _typeof(obj);
  337. }
  338. module.exports = _typeof;
  339. /***/ }),
  340. /***/ "./node_modules/backbone-undo/Backbone.Undo.js":
  341. /*!*****************************************************!*\
  342. !*** ./node_modules/backbone-undo/Backbone.Undo.js ***!
  343. \*****************************************************/
  344. /*! no static exports found */
  345. /***/ (function(module, exports, __webpack_require__) {
  346. var __WEBPACK_AMD_DEFINE_FACTORY__, __WEBPACK_AMD_DEFINE_ARRAY__, __WEBPACK_AMD_DEFINE_RESULT__;/*!
  347. * Backbone.Undo.js v0.2
  348. *
  349. * Copyright (c)2013 Oliver Sartun
  350. * Released under the MIT License
  351. *
  352. * Documentation and full license available at
  353. * https://github.com/osartun/Backbone.Undo.js
  354. */
  355. (function (factory) {
  356. if (true) {
  357. // AMD support
  358. !(__WEBPACK_AMD_DEFINE_ARRAY__ = [__webpack_require__(/*! underscore */ "./node_modules/underscore/underscore.js"), __webpack_require__(/*! backbone */ "./node_modules/backbone/backbone.js")], __WEBPACK_AMD_DEFINE_FACTORY__ = (factory),
  359. __WEBPACK_AMD_DEFINE_RESULT__ = (typeof __WEBPACK_AMD_DEFINE_FACTORY__ === 'function' ?
  360. (__WEBPACK_AMD_DEFINE_FACTORY__.apply(exports, __WEBPACK_AMD_DEFINE_ARRAY__)) : __WEBPACK_AMD_DEFINE_FACTORY__),
  361. __WEBPACK_AMD_DEFINE_RESULT__ !== undefined && (module.exports = __WEBPACK_AMD_DEFINE_RESULT__));
  362. } else {}
  363. })(function (_, Backbone) {
  364. var core_slice = Array.prototype.slice;
  365. /**
  366. * As call is faster than apply, this is a faster version of apply as it uses call.
  367. *
  368. * @param {Function} fn The function to execute
  369. * @param {Object} ctx The context the function should be called in
  370. * @param {Array} args The array of arguments that should be applied to the function
  371. * @return Forwards whatever the called function returns
  372. */
  373. function apply (fn, ctx, args) {
  374. return args.length <= 4 ?
  375. fn.call(ctx, args[0], args[1], args[2], args[3]) :
  376. fn.apply(ctx, args);
  377. }
  378. /**
  379. * Uses slice on an array or an array-like object.
  380. *
  381. * @param {Array|Object} arr The array or array-like object.
  382. * @param {Number} [index] The index from where the array should be sliced. Default is 0.
  383. * @return {Array} The sliced array
  384. */
  385. function slice (arr, index) {
  386. return core_slice.call(arr, index);
  387. }
  388. /**
  389. * Checks if an object has one or more specific keys. The keys
  390. * don't have to be an owned property.
  391. * You can call this function either this way:
  392. * hasKeys(obj, ["a", "b", "c"])
  393. * or this way:
  394. * hasKeys(obj, "a", "b", "c")
  395. *
  396. * @param {Object} obj The object to check on
  397. * @param {Array} keys The keys to check for
  398. * @return {Boolean} True, if the object has all those keys
  399. */
  400. function hasKeys (obj, keys) {
  401. if (obj == null) return false;
  402. if (!_.isArray(keys)) {
  403. keys = slice(arguments, 1);
  404. }
  405. return _.all(keys, function (key) {
  406. return key in obj;
  407. });
  408. }
  409. /**
  410. * Returns a number that is unique per call stack. The number gets
  411. * changed after the call stack has been completely processed.
  412. *
  413. * @return {number} MagicFusionIndex
  414. */
  415. var getMagicFusionIndex = (function () {
  416. // If you add several models to a collection or set several
  417. // attributes on a model all in sequence and yet all for
  418. // example in one function, then several Undo-Actions are
  419. // generated.
  420. // If you want to undo your last action only the last model
  421. // would be removed from the collection or the last set
  422. // attribute would be changed back to its previous value.
  423. // To prevent that we have to figure out a way to combine
  424. // all those actions that happened "at the same time".
  425. // Timestamps aren't exact enough. A complex routine could
  426. // run several milliseconds and in that time produce a lot
  427. // of actions with different timestamps.
  428. // Instead we take advantage of the single-threadedness of
  429. // JavaScript:
  430. var callstackWasIndexed = false, magicFusionIndex = -1;
  431. function indexCycle() {
  432. magicFusionIndex++;
  433. callstackWasIndexed = true;
  434. _.defer(function () {
  435. // Here comes the magic. With a Timeout of 0
  436. // milliseconds this function gets called whenever
  437. // the current callstack is completed
  438. callstackWasIndexed = false;
  439. })
  440. }
  441. return function () {
  442. if (!callstackWasIndexed) {
  443. indexCycle();
  444. }
  445. return magicFusionIndex;
  446. }
  447. })();
  448. /**
  449. * To prevent binding a listener several times to one
  450. * object, we register the objects in an ObjectRegistry
  451. *
  452. * @constructor
  453. */
  454. function ObjectRegistry () {
  455. // This uses two different ways of storing
  456. // objects: In case the object has a cid
  457. // (which Backbone objects typically have)
  458. // it uses this cid as an index. That way
  459. // the Array's length attribute doesn't
  460. // change and the object isn't an item
  461. // in the array, but an object-property.
  462. // Otherwise it's added to the Array as an
  463. // item.
  464. // That way we can use the fast property-
  465. // lookup and only have to fall back to
  466. // iterating over the array in case
  467. // non-Backbone-objects are registered.
  468. this.registeredObjects = [];
  469. // To return a list of all registered
  470. // objects in the 'get' method we have to
  471. // store the objects that have a cid in
  472. // an additional array.
  473. this.cidIndexes = [];
  474. }
  475. ObjectRegistry.prototype = {
  476. /**
  477. * Returns whether the object is already registered in this ObjectRegistry or not.
  478. *
  479. * @this {ObjectRegistry}
  480. * @param {Object} obj The object to check
  481. * @return {Boolean} True if the object is already registered
  482. */
  483. isRegistered: function (obj) {
  484. // This is where we get a performance boost
  485. // by using the two different ways of storing
  486. // objects.
  487. return obj && obj.cid ? this.registeredObjects[obj.cid] : _.contains(this.registeredObjects, obj);
  488. },
  489. /**
  490. * Registers an object in this ObjectRegistry.
  491. *
  492. * @this {ObjectRegistry}
  493. * @param {Object} obj The object to register
  494. * @return {undefined}
  495. */
  496. register: function (obj) {
  497. if (!this.isRegistered(obj)) {
  498. if (obj && obj.cid) {
  499. this.registeredObjects[obj.cid] = obj;
  500. this.cidIndexes.push(obj.cid);
  501. } else {
  502. this.registeredObjects.push(obj);
  503. }
  504. return true;
  505. }
  506. return false;
  507. },
  508. /**
  509. * Unregisters an object from this ObjectRegistry.
  510. *
  511. * @this {ObjectRegistry}
  512. * @param {Object} obj The object to unregister
  513. * @return {undefined}
  514. */
  515. unregister: function (obj) {
  516. if (this.isRegistered(obj)) {
  517. if (obj && obj.cid) {
  518. delete this.registeredObjects[obj.cid];
  519. this.cidIndexes.splice(_.indexOf(this.cidIndexes, obj.cid), 1);
  520. } else {
  521. var i = _.indexOf(this.registeredObjects, obj);
  522. this.registeredObjects.splice(i, 1);
  523. }
  524. return true;
  525. }
  526. return false;
  527. },
  528. /**
  529. * Returns an array of all objects that are currently in this ObjectRegistry.
  530. *
  531. * @return {Array} An array of all the objects which are currently in the ObjectRegistry
  532. */
  533. get: function () {
  534. return (_.map(this.cidIndexes, function (cid) {return this.registeredObjects[cid];}, this)).concat(this.registeredObjects);
  535. }
  536. }
  537. /**
  538. * Binds or unbinds the "all"-listener for one or more objects.
  539. *
  540. * @param {String} which Either "on" or "off"
  541. * @param {Object[]} objects Array of the objects on which the "all"-listener should be bound / unbound to
  542. * @param {Function} [fn] The function that should be bound / unbound. Optional in case of "off"
  543. * @param {Object} [ctx] The context the function should be called in
  544. * @return {undefined}
  545. */
  546. function onoff(which, objects, fn, ctx) {
  547. for (var i = 0, l = objects.length, obj; i < l; i++) {
  548. obj = objects[i];
  549. if (!obj) continue;
  550. if (which === "on") {
  551. if (!ctx.objectRegistry.register(obj)) {
  552. // register returned false, so obj was already registered
  553. continue;
  554. }
  555. } else {
  556. if (!ctx.objectRegistry.unregister(obj)) {
  557. // unregister returned false, so obj wasn't registered
  558. continue;
  559. }
  560. }
  561. if (_.isFunction(obj[which])) {
  562. obj[which]("all", fn, ctx);
  563. }
  564. }
  565. }
  566. /**
  567. * Calls the undo/redo-function for a specific action.
  568. *
  569. * @param {String} which Either "undo" or "redo"
  570. * @param {Object} action The Action's attributes
  571. * @return {undefined}
  572. */
  573. function actionUndoRedo (which, action) {
  574. var type = action.type, undoTypes = action.undoTypes, fn = !undoTypes[type] || undoTypes[type][which];
  575. if (_.isFunction(fn)) {
  576. fn(action.object, action.before, action.after, action.options);
  577. }
  578. }
  579. /**
  580. * The main undo/redo function.
  581. *
  582. * @param {String} which Either "undo" or "redo"
  583. * @param {UndoManager} manager The UndoManager-instance on which an "undo"/"redo"-Event is triggered afterwards
  584. * @param {UndoStack} stack The UndoStack on which we perform
  585. * @param {Boolean} magic If true, undoes / redoes all actions with the same magicFusionIndex
  586. * @param {Boolean} everything If true, undoes / redoes every action that had been tracked
  587. * @return {undefined}
  588. */
  589. function managerUndoRedo (which, manager, stack, magic, everything) {
  590. if (stack.isCurrentlyUndoRedoing ||
  591. (which === "undo" && stack.pointer === -1) ||
  592. (which === "redo" && stack.pointer === stack.length - 1)) {
  593. // We're either currently in an undo- / redo-process or
  594. // we reached the end of the stack
  595. return;
  596. }
  597. stack.isCurrentlyUndoRedoing = true;
  598. var action, actions, isUndo = which === "undo";
  599. if (everything) {
  600. // Undo / Redo all steps until you reach the stack's beginning / end
  601. actions = isUndo && stack.pointer === stack.length - 1 || // If at the stack's end calling undo
  602. !isUndo && stack.pointer === -1 ? // or at the stack's beginning calling redo
  603. _.clone(stack.models) : // => Take all the models. Otherwise:
  604. core_slice.apply(stack.models, isUndo ? [0, stack.pointer] : [stack.pointer, stack.length - 1]);
  605. } else {
  606. // Undo / Redo only one step
  607. action = stack.at(isUndo ? stack.pointer : stack.pointer + 1);
  608. actions = magic ? stack.where({"magicFusionIndex": action.get("magicFusionIndex")}) : [action];
  609. }
  610. stack.pointer += (isUndo ? -1 : 1) * actions.length;
  611. while (action = isUndo ? actions.pop() : actions.shift()) {
  612. // Here we're calling the Action's undo / redo method
  613. action[which]();
  614. }
  615. stack.isCurrentlyUndoRedoing = false;
  616. manager.trigger(which, manager);
  617. }
  618. /**
  619. * Checks whether an UndoAction should be created or not. Therefore it checks
  620. * whether a "condition" property is set in the undoTypes-object of the specific
  621. * event type. If not, it returns true. If it's set and a boolean, it returns it.
  622. * If it's a function, it returns its result, converting it into a boolean.
  623. * Otherwise it returns true.
  624. *
  625. * @param {Object} undoTypesType The object within the UndoTypes that holds the function for this event type (i.e. "change")
  626. * @param {Arguments} args The arguments the "condition" function is called with
  627. * @return {Boolean} True, if an UndoAction should be created
  628. */
  629. function validateUndoActionCreation (undoTypesType, args) {
  630. var condition = undoTypesType.condition, type = typeof condition;
  631. return type === "function" ? !!apply(condition, undoTypesType, args) :
  632. type === "boolean" ? condition : true;
  633. }
  634. /**
  635. * Adds an Undo-Action to the stack.
  636. *
  637. * @param {UndoStack} stack The undostack the action should be added to.
  638. * @param {String} type The event type (i.e. "change")
  639. * @param {Arguments} args The arguments passed to the undoTypes' "on"-handler
  640. * @param {OwnedUndoTypes} undoTypes The undoTypes-object which has the "on"-handler
  641. * @return {undefined}
  642. */
  643. function addToStack(stack, type, args, undoTypes) {
  644. if (stack.track && !stack.isCurrentlyUndoRedoing && type in undoTypes &&
  645. validateUndoActionCreation(undoTypes[type], args)) {
  646. // An UndoAction should be created
  647. var res = apply(undoTypes[type]["on"], undoTypes[type], args), diff;
  648. if (hasKeys(res, "object", "before", "after")) {
  649. res.type = type;
  650. res.magicFusionIndex = getMagicFusionIndex();
  651. res.undoTypes = undoTypes;
  652. if (stack.pointer < stack.length - 1) {
  653. // New Actions must always be added to the end of the stack.
  654. // If the pointer is not pointed to the last action in the
  655. // stack, presumably because actions were undone before, then
  656. // all following actions must be discarded
  657. var diff = stack.length - stack.pointer - 1;
  658. while (diff--) {
  659. stack.pop();
  660. }
  661. }
  662. stack.pointer = stack.length;
  663. stack.add(res);
  664. if (stack.length > stack.maximumStackLength) {
  665. stack.shift();
  666. stack.pointer--;
  667. }
  668. }
  669. }
  670. }
  671. /**
  672. * Predefined UndoTypes object with default handlers for the most common events.
  673. * @type {Object}
  674. */
  675. var UndoTypes = {
  676. "add": {
  677. "undo": function (collection, ignore, model, options) {
  678. // Undo add = remove
  679. collection.remove(model, options);
  680. },
  681. "redo": function (collection, ignore, model, options) {
  682. // Redo add = add
  683. if (options.index) {
  684. options.at = options.index;
  685. }
  686. collection.add(model, options);
  687. },
  688. "on": function (model, collection, options) {
  689. return {
  690. object: collection,
  691. before: undefined,
  692. after: model,
  693. options: _.clone(options)
  694. };
  695. }
  696. },
  697. "remove": {
  698. "undo": function (collection, model, ignore, options) {
  699. if ("index" in options) {
  700. options.at = options.index;
  701. }
  702. collection.add(model, options);
  703. },
  704. "redo": function (collection, model, ignore, options) {
  705. collection.remove(model, options);
  706. },
  707. "on": function (model, collection, options) {
  708. return {
  709. object: collection,
  710. before: model,
  711. after: undefined,
  712. options: _.clone(options)
  713. };
  714. }
  715. },
  716. "change": {
  717. "undo": function (model, before, after, options) {
  718. if (_.isEmpty(before)) {
  719. _.each(_.keys(after), model.unset, model);
  720. } else {
  721. model.set(before);
  722. if (options && options.unsetData && options.unsetData.before && options.unsetData.before.length) {
  723. _.each(options.unsetData.before, model.unset, model);
  724. }
  725. }
  726. },
  727. "redo": function (model, before, after, options) {
  728. if (_.isEmpty(after)) {
  729. _.each(_.keys(before), model.unset, model);
  730. } else {
  731. model.set(after);
  732. if (options && options.unsetData && options.unsetData.after && options.unsetData.after.length) {
  733. _.each(options.unsetData.after, model.unset, model);
  734. }
  735. }
  736. },
  737. "on": function (model, options) {
  738. var
  739. afterAttributes = model.changedAttributes(),
  740. keysAfter = _.keys(afterAttributes),
  741. previousAttributes = _.pick(model.previousAttributes(), keysAfter),
  742. keysPrevious = _.keys(previousAttributes),
  743. unsetData = (options || (options = {})).unsetData = {
  744. after: [],
  745. before: []
  746. };
  747. if (keysAfter.length != keysPrevious.length) {
  748. // There are new attributes or old attributes have been unset
  749. if (keysAfter.length > keysPrevious.length) {
  750. // New attributes have been added
  751. _.each(keysAfter, function (val) {
  752. if (!(val in previousAttributes)) {
  753. unsetData.before.push(val);
  754. }
  755. }, this);
  756. } else {
  757. // Old attributes have been unset
  758. _.each(keysPrevious, function (val) {
  759. if (!(val in afterAttributes)) {
  760. unsetData.after.push(val);
  761. }
  762. })
  763. }
  764. }
  765. return {
  766. object: model,
  767. before: previousAttributes,
  768. after: afterAttributes,
  769. options: _.clone(options)
  770. };
  771. }
  772. },
  773. "reset": {
  774. "undo": function (collection, before, after) {
  775. collection.reset(before);
  776. },
  777. "redo": function (collection, before, after) {
  778. collection.reset(after);
  779. },
  780. "on": function (collection, options) {
  781. return {
  782. object: collection,
  783. before: options.previousModels,
  784. after: _.clone(collection.models)
  785. };
  786. }
  787. }
  788. };
  789. /**
  790. * Every UndoManager instance has an own undoTypes object
  791. * which is an instance of OwnedUndoTypes. OwnedUndoTypes'
  792. * prototype is the global UndoTypes object. Changes to the
  793. * global UndoTypes object take effect on every instance of
  794. * UndoManager as the object is its prototype. And yet every
  795. * local UndoTypes object can be changed individually.
  796. *
  797. * @constructor
  798. */
  799. function OwnedUndoTypes () {}
  800. OwnedUndoTypes.prototype = UndoTypes;
  801. /**
  802. * Adds, changes or removes an undo-type from an UndoTypes-object.
  803. * You can call it this way:
  804. * manipulateUndoType (1, "reset", {"on": function () {}}, undoTypes)
  805. * or this way to perform bulk actions:
  806. * manipulateUndoType (1, {"reset": {"on": function () {}}}, undoTypes)
  807. * In case of removing undo-types you can pass an Array for performing
  808. * bulk actions:
  809. * manipulateUndoType(2, ["reset", "change"], undoTypes)
  810. *
  811. * @param {Number} manipType Indicates the kind of action to execute: 0 for add, 1 for change, 2 for remove
  812. * @param {String|Object|Array} undoType The type of undoType that should be added/changed/removed. Can be an object / array to perform bulk actions
  813. * @param {Object} [fns] Object with the functions to add / change. Is optional in case you passed an object as undoType that contains these functions
  814. * @param {OwnedUndoTypes|UndoTypes} undoTypesInstance The undoTypes object to act on
  815. * @return {undefined}
  816. */
  817. function manipulateUndoType (manipType, undoType, fns, undoTypesInstance) {
  818. // manipType, passed by the calling function
  819. // 0: add
  820. // 1: change
  821. // 2: remove
  822. if (typeof undoType === "object") {
  823. // bulk action. Iterate over this data.
  824. return _.each(undoType, function (val, key) {
  825. if (manipType === 2) { // remove
  826. // undoType is an array
  827. manipulateUndoType (manipType, val, fns, undoTypesInstance);
  828. } else {
  829. // undoType is an object
  830. manipulateUndoType (manipType, key, val, fns);
  831. }
  832. })
  833. }
  834. switch (manipType) {
  835. case 0: // add
  836. if (hasKeys(fns, "undo", "redo", "on") && _.all(_.pick(fns, "undo", "redo", "on"), _.isFunction)) {
  837. undoTypesInstance[undoType] = fns;
  838. }
  839. break;
  840. case 1: // change
  841. if (undoTypesInstance[undoType] && _.isObject(fns)) {
  842. // undoTypeInstance[undoType] may be a prototype's property
  843. // So, if we did this _.extend(undoTypeInstance[undoType], fns)
  844. // we would extend the object on the prototype which means
  845. // that this change would have a global effect
  846. // Instead we just want to manipulate this instance. That's why
  847. // we're doing this:
  848. undoTypesInstance[undoType] = _.extend({}, undoTypesInstance[undoType], fns);
  849. }
  850. break;
  851. case 2: // remove
  852. delete undoTypesInstance[undoType];
  853. break;
  854. }
  855. return this;
  856. }
  857. /**
  858. * Instantiating "Action" creates the UndoActions that
  859. * are collected in an UndoStack. It holds all relevant
  860. * data to undo / redo an action and has an undo / redo
  861. * method.
  862. */
  863. var Action = Backbone.Model.extend({
  864. defaults: {
  865. type: null, // "add", "change", "reset", etc.
  866. object: null, // The object on which the action occurred
  867. before: null, // The previous values which were changed with this action
  868. after: null, // The values after this action
  869. magicFusionIndex: null // The magicFusionIndex helps to combine
  870. // all actions that occurred "at the same time" to undo/redo them altogether
  871. },
  872. /**
  873. * Undoes this action.
  874. * @param {OwnedUndoTypes|UndoTypes} undoTypes The undoTypes object which contains the "undo"-handler that should be used
  875. * @return {undefined}
  876. */
  877. undo: function (undoTypes) {
  878. actionUndoRedo("undo", this.attributes);
  879. },
  880. /**
  881. * Redoes this action.
  882. * @param {OwnedUndoTypes|UndoTypes} undoTypes The undoTypes object which contains the "redo"-handler that should be used
  883. * @return {undefined}
  884. */
  885. redo: function (undoTypes) {
  886. actionUndoRedo("redo", this.attributes);
  887. }
  888. }),
  889. /**
  890. * An UndoStack is a collection of UndoActions in
  891. * chronological order.
  892. */
  893. UndoStack = Backbone.Collection.extend({
  894. model: Action,
  895. pointer: -1, // The pointer indicates the index where we are located within the stack. We start at -1
  896. track: false,
  897. isCurrentlyUndoRedoing: false,
  898. maximumStackLength: Infinity,
  899. setMaxLength: function (val) {
  900. this.maximumStackLength = val;
  901. }
  902. }),
  903. /**
  904. * An instance of UndoManager can keep track of
  905. * changes to objects and helps to undo them.
  906. */
  907. UndoManager = Backbone.Model.extend({
  908. defaults: {
  909. maximumStackLength: Infinity,
  910. track: false
  911. },
  912. /**
  913. * The constructor function.
  914. * @param {attr} [attr] Object with parameters. The available parameters are:
  915. * - maximumStackLength {number} Set the undo-stack's maximum size
  916. * - track {boolean} Start tracking changes right away
  917. * @return {undefined}
  918. */
  919. initialize: function (attr) {
  920. this.stack = new UndoStack;
  921. this.objectRegistry = new ObjectRegistry();
  922. this.undoTypes = new OwnedUndoTypes();
  923. // sync the maximumStackLength attribute with our stack
  924. this.stack.setMaxLength(this.get("maximumStackLength"));
  925. this.on("change:maximumStackLength", function (model, value) {
  926. this.stack.setMaxLength(value);
  927. }, this);
  928. // Start tracking, if attr.track == true
  929. if (attr && attr.track) {
  930. this.startTracking();
  931. }
  932. // Register objects passed in the "register" attribute
  933. if (attr && attr.register) {
  934. if (_.isArray(attr.register) || _.isArguments(attr.register)) {
  935. apply(this.register, this, attr.register);
  936. } else {
  937. this.register(attr.register);
  938. }
  939. }
  940. },
  941. /**
  942. * Starts tracking. Changes of registered objects won't be processed until you've called this function
  943. * @return {undefined}
  944. */
  945. startTracking: function () {
  946. this.set("track", true);
  947. this.stack.track = true;
  948. },
  949. /**
  950. * Stops tracking. Afterwards changes of registered objects won't be processed.
  951. * @return {undefined}
  952. */
  953. stopTracking: function () {
  954. this.set("track", false);
  955. this.stack.track = false;
  956. },
  957. /**
  958. * Return the state of the tracking
  959. * @return {boolean}
  960. */
  961. isTracking: function () {
  962. return this.get("track");
  963. },
  964. /**
  965. * This is the "all"-handler which is bound to registered
  966. * objects. It creates an UndoAction from the event and adds
  967. * it to the stack.
  968. *
  969. * @param {String} type The event type
  970. * @return {undefined}
  971. */
  972. _addToStack: function (type) {
  973. addToStack(this.stack, type, slice(arguments, 1), this.undoTypes);
  974. },
  975. /**
  976. * Registers one or more objects to track their changes.
  977. * @param {...Object} obj The object or objects of which changes should be tracked
  978. * @return {undefined}
  979. */
  980. register: function () {
  981. onoff("on", arguments, this._addToStack, this);
  982. },
  983. /**
  984. * Unregisters one or more objects.
  985. * @param {...Object} obj The object or objects of which changes shouldn't be tracked any longer
  986. * @return {undefined}
  987. */
  988. unregister: function () {
  989. onoff("off", arguments, this._addToStack, this);
  990. },
  991. /**
  992. * Unregisters all previously registered objects.
  993. * @return {undefined}
  994. */
  995. unregisterAll: function () {
  996. apply(this.unregister, this, this.objectRegistry.get());
  997. },
  998. /**
  999. * Undoes the last action or the last set of actions in case 'magic' is true.
  1000. * @param {Boolean} [magic] If true, all actions that happened basically at the same time are undone together
  1001. * @return {undefined}
  1002. */
  1003. undo: function (magic) {
  1004. managerUndoRedo("undo", this, this.stack, magic);
  1005. },
  1006. /**
  1007. * Undoes all actions ever tracked by the undo manager
  1008. * @return {undefined}
  1009. */
  1010. undoAll: function () {
  1011. managerUndoRedo("undo", this, this.stack, false, true);
  1012. },
  1013. /**
  1014. * Redoes a previously undone action or a set of actions.
  1015. * @param {Boolean} [magic] If true, all actions that happened basically at the same time are redone together
  1016. * @return {undefined}
  1017. */
  1018. redo: function (magic) {
  1019. managerUndoRedo("redo", this, this.stack, magic);
  1020. },
  1021. /**
  1022. * Redoes all actions ever tracked by the undo manager
  1023. * @return {undefined}
  1024. */
  1025. redoAll: function () {
  1026. managerUndoRedo("redo", this, this.stack, false, true);
  1027. },
  1028. /**
  1029. * Checks if there's an action in the stack that can be undone / redone
  1030. * @param {String} type Either "undo" or "redo"
  1031. * @return {Boolean} True if there is a set of actions which can be undone / redone
  1032. */
  1033. isAvailable: function (type) {
  1034. var s = this.stack, l = s.length;
  1035. switch (type) {
  1036. case "undo": return l > 0 && s.pointer > -1;
  1037. case "redo": return l > 0 && s.pointer < l - 1;
  1038. default: return false;
  1039. }
  1040. },
  1041. /**
  1042. * Sets the stack-reference to the stack of another undoManager.
  1043. * @param {UndoManager} undoManager The undoManager whose stack-reference is set to this stack
  1044. * @return {undefined}
  1045. */
  1046. merge: function (undoManager) {
  1047. // This sets the stack-reference to the stack of another
  1048. // undoManager so that the stack of this other undoManager
  1049. // is used by two different managers.
  1050. // This enables to set up a main-undoManager and besides it
  1051. // several others for special, exceptional cases (by using
  1052. // instance-based custom UndoTypes). Models / collections
  1053. // which need this special treatment are only registered at
  1054. // those special undoManagers. Those special ones are then
  1055. // merged into the main-undoManager to write on its stack.
  1056. // That way it's easier to manage exceptional cases.
  1057. var args = _.isArray(undoManager) ? undoManager : slice(arguments), manager;
  1058. while (manager = args.pop()) {
  1059. if (manager instanceof UndoManager &&
  1060. manager.stack instanceof UndoStack) {
  1061. // set the stack reference to our stack
  1062. manager.stack = this.stack;
  1063. }
  1064. }
  1065. },
  1066. /**
  1067. * Add an UndoType to this specific UndoManager-instance.
  1068. * @param {String} type The event this UndoType is made for
  1069. * @param {Object} fns An object of functions that are called to generate the data for an UndoAction or to process it. Must have the properties "undo", "redo" and "on". Can have the property "condition".
  1070. * @return {undefined}
  1071. */
  1072. addUndoType: function (type, fns) {
  1073. manipulateUndoType(0, type, fns, this.undoTypes);
  1074. },
  1075. /**
  1076. * Overwrite properties of an existing UndoType for this specific UndoManager-instance.
  1077. * @param {String} type The event the UndoType is made for
  1078. * @param {Object} fns An object of functions that are called to generate the data for an UndoAction or to process it. It extends the existing object.
  1079. * @return {undefined}
  1080. */
  1081. changeUndoType: function (type, fns) {
  1082. manipulateUndoType(1, type, fns, this.undoTypes);
  1083. },
  1084. /**
  1085. * Remove one or more UndoTypes of this specific UndoManager-instance to fall back to the global UndoTypes.
  1086. * @param {String|Array} type The event the UndoType that should be removed is made for. You can also pass an array of events.
  1087. * @return {undefined}
  1088. */
  1089. removeUndoType: function (type) {
  1090. manipulateUndoType(2, type, undefined, this.undoTypes);
  1091. },
  1092. /**
  1093. * Removes all actions from the stack.
  1094. * @return {undefined}
  1095. */
  1096. clear: function() {
  1097. this.stack.reset();
  1098. this.stack.pointer = -1;
  1099. }
  1100. });
  1101. _.extend(UndoManager, {
  1102. /**
  1103. * Change the UndoManager's default attributes
  1104. * @param {Object} defaultAttributes An object with the new default values.
  1105. * @return {undefined}
  1106. */
  1107. defaults: function (defaultAttributes) {
  1108. _.extend(UndoManager.prototype.defaults, defaultAttributes);
  1109. },
  1110. /**
  1111. * Add an UndoType to the global UndoTypes-object.
  1112. * @param {String} type The event this UndoType is made for
  1113. * @param {Object} fns An object of functions that are called to generate the data for an UndoAction or to process it. Must have the properties "undo", "redo" and "on". Can have the property "condition".
  1114. * @return {undefined}
  1115. */
  1116. "addUndoType": function (type, fns) {
  1117. manipulateUndoType(0, type, fns, UndoTypes);
  1118. },
  1119. /**
  1120. * Overwrite properties of an existing UndoType in the global UndoTypes-object.
  1121. * @param {String} type The event the UndoType is made for
  1122. * @param {Object} fns An object of functions that are called to generate the data for an UndoAction or to process it. It extends the existing object.
  1123. * @return {undefined}
  1124. */
  1125. "changeUndoType": function (type, fns) {
  1126. manipulateUndoType(1, type, fns, UndoTypes)
  1127. },
  1128. /**
  1129. * Remove one or more UndoTypes of this specific UndoManager-instance to fall back to the global UndoTypes.
  1130. * @param {String|Array} type The event the UndoType that should be removed is made for. You can also pass an array of events.
  1131. * @return {undefined}
  1132. */
  1133. "removeUndoType": function (type) {
  1134. manipulateUndoType(2, type, undefined, UndoTypes);
  1135. }
  1136. })
  1137. return Backbone.UndoManager = UndoManager;
  1138. });
  1139. /***/ }),
  1140. /***/ "./node_modules/backbone/backbone.js":
  1141. /*!*******************************************!*\
  1142. !*** ./node_modules/backbone/backbone.js ***!
  1143. \*******************************************/
  1144. /*! no static exports found */
  1145. /***/ (function(module, exports, __webpack_require__) {
  1146. /* WEBPACK VAR INJECTION */(function(global) {var __WEBPACK_AMD_DEFINE_ARRAY__, __WEBPACK_AMD_DEFINE_RESULT__;// Backbone.js 1.3.3
  1147. // (c) 2010-2016 Jeremy Ashkenas, DocumentCloud and Investigative Reporters & Editors
  1148. // Backbone may be freely distributed under the MIT license.
  1149. // For all details and documentation:
  1150. // http://backbonejs.org
  1151. (function(factory) {
  1152. // Establish the root object, `window` (`self`) in the browser, or `global` on the server.
  1153. // We use `self` instead of `window` for `WebWorker` support.
  1154. var root = (typeof self == 'object' && self.self === self && self) ||
  1155. (typeof global == 'object' && global.global === global && global);
  1156. // Set up Backbone appropriately for the environment. Start with AMD.
  1157. if (true) {
  1158. !(__WEBPACK_AMD_DEFINE_ARRAY__ = [__webpack_require__(/*! underscore */ "./node_modules/underscore/underscore.js"), __webpack_require__(/*! jquery */ "./node_modules/cash-dom/dist/cash.esm.js"), exports], __WEBPACK_AMD_DEFINE_RESULT__ = (function(_, $, exports) {
  1159. // Export global even in AMD case in case this script is loaded with
  1160. // others that may still expect a global Backbone.
  1161. root.Backbone = factory(root, exports, _, $);
  1162. }).apply(exports, __WEBPACK_AMD_DEFINE_ARRAY__),
  1163. __WEBPACK_AMD_DEFINE_RESULT__ !== undefined && (module.exports = __WEBPACK_AMD_DEFINE_RESULT__));
  1164. // Next for Node.js or CommonJS. jQuery may not be needed as a module.
  1165. } else { var _, $; }
  1166. })(function(root, Backbone, _, $) {
  1167. // Initial Setup
  1168. // -------------
  1169. // Save the previous value of the `Backbone` variable, so that it can be
  1170. // restored later on, if `noConflict` is used.
  1171. var previousBackbone = root.Backbone;
  1172. // Create a local reference to a common array method we'll want to use later.
  1173. var slice = Array.prototype.slice;
  1174. // Current version of the library. Keep in sync with `package.json`.
  1175. Backbone.VERSION = '1.3.3';
  1176. // For Backbone's purposes, jQuery, Zepto, Ender, or My Library (kidding) owns
  1177. // the `$` variable.
  1178. Backbone.$ = $;
  1179. // Runs Backbone.js in *noConflict* mode, returning the `Backbone` variable
  1180. // to its previous owner. Returns a reference to this Backbone object.
  1181. Backbone.noConflict = function() {
  1182. root.Backbone = previousBackbone;
  1183. return this;
  1184. };
  1185. // Turn on `emulateHTTP` to support legacy HTTP servers. Setting this option
  1186. // will fake `"PATCH"`, `"PUT"` and `"DELETE"` requests via the `_method` parameter and
  1187. // set a `X-Http-Method-Override` header.
  1188. Backbone.emulateHTTP = false;
  1189. // Turn on `emulateJSON` to support legacy servers that can't deal with direct
  1190. // `application/json` requests ... this will encode the body as
  1191. // `application/x-www-form-urlencoded` instead and will send the model in a
  1192. // form param named `model`.
  1193. Backbone.emulateJSON = false;
  1194. // Proxy Backbone class methods to Underscore functions, wrapping the model's
  1195. // `attributes` object or collection's `models` array behind the scenes.
  1196. //
  1197. // collection.filter(function(model) { return model.get('age') > 10 });
  1198. // collection.each(this.addView);
  1199. //
  1200. // `Function#apply` can be slow so we use the method's arg count, if we know it.
  1201. var addMethod = function(length, method, attribute) {
  1202. switch (length) {
  1203. case 1: return function() {
  1204. return _[method](this[attribute]);
  1205. };
  1206. case 2: return function(value) {
  1207. return _[method](this[attribute], value);
  1208. };
  1209. case 3: return function(iteratee, context) {
  1210. return _[method](this[attribute], cb(iteratee, this), context);
  1211. };
  1212. case 4: return function(iteratee, defaultVal, context) {
  1213. return _[method](this[attribute], cb(iteratee, this), defaultVal, context);
  1214. };
  1215. default: return function() {
  1216. var args = slice.call(arguments);
  1217. args.unshift(this[attribute]);
  1218. return _[method].apply(_, args);
  1219. };
  1220. }
  1221. };
  1222. var addUnderscoreMethods = function(Class, methods, attribute) {
  1223. _.each(methods, function(length, method) {
  1224. if (_[method]) Class.prototype[method] = addMethod(length, method, attribute);
  1225. });
  1226. };
  1227. // Support `collection.sortBy('attr')` and `collection.findWhere({id: 1})`.
  1228. var cb = function(iteratee, instance) {
  1229. if (_.isFunction(iteratee)) return iteratee;
  1230. if (_.isObject(iteratee) && !instance._isModel(iteratee)) return modelMatcher(iteratee);
  1231. if (_.isString(iteratee)) return function(model) { return model.get(iteratee); };
  1232. return iteratee;
  1233. };
  1234. var modelMatcher = function(attrs) {
  1235. var matcher = _.matches(attrs);
  1236. return function(model) {
  1237. return matcher(model.attributes);
  1238. };
  1239. };
  1240. // Backbone.Events
  1241. // ---------------
  1242. // A module that can be mixed in to *any object* in order to provide it with
  1243. // a custom event channel. You may bind a callback to an event with `on` or
  1244. // remove with `off`; `trigger`-ing an event fires all callbacks in
  1245. // succession.
  1246. //
  1247. // var object = {};
  1248. // _.extend(object, Backbone.Events);
  1249. // object.on('expand', function(){ alert('expanded'); });
  1250. // object.trigger('expand');
  1251. //
  1252. var Events = Backbone.Events = {};
  1253. // Regular expression used to split event strings.
  1254. var eventSplitter = /\s+/;
  1255. // Iterates over the standard `event, callback` (as well as the fancy multiple
  1256. // space-separated events `"change blur", callback` and jQuery-style event
  1257. // maps `{event: callback}`).
  1258. var eventsApi = function(iteratee, events, name, callback, opts) {
  1259. var i = 0, names;
  1260. if (name && typeof name === 'object') {
  1261. // Handle event maps.
  1262. if (callback !== void 0 && 'context' in opts && opts.context === void 0) opts.context = callback;
  1263. for (names = _.keys(name); i < names.length ; i++) {
  1264. events = eventsApi(iteratee, events, names[i], name[names[i]], opts);
  1265. }
  1266. } else if (name && eventSplitter.test(name)) {
  1267. // Handle space-separated event names by delegating them individually.
  1268. for (names = name.split(eventSplitter); i < names.length; i++) {
  1269. events = iteratee(events, names[i], callback, opts);
  1270. }
  1271. } else {
  1272. // Finally, standard events.
  1273. events = iteratee(events, name, callback, opts);
  1274. }
  1275. return events;
  1276. };
  1277. // Bind an event to a `callback` function. Passing `"all"` will bind
  1278. // the callback to all events fired.
  1279. Events.on = function(name, callback, context) {
  1280. return internalOn(this, name, callback, context);
  1281. };
  1282. // Guard the `listening` argument from the public API.
  1283. var internalOn = function(obj, name, callback, context, listening) {
  1284. obj._events = eventsApi(onApi, obj._events || {}, name, callback, {
  1285. context: context,
  1286. ctx: obj,
  1287. listening: listening
  1288. });
  1289. if (listening) {
  1290. var listeners = obj._listeners || (obj._listeners = {});
  1291. listeners[listening.id] = listening;
  1292. }
  1293. return obj;
  1294. };
  1295. // Inversion-of-control versions of `on`. Tell *this* object to listen to
  1296. // an event in another object... keeping track of what it's listening to
  1297. // for easier unbinding later.
  1298. Events.listenTo = function(obj, name, callback) {
  1299. if (!obj) return this;
  1300. var id = obj._listenId || (obj._listenId = _.uniqueId('l'));
  1301. var listeningTo = this._listeningTo || (this._listeningTo = {});
  1302. var listening = listeningTo[id];
  1303. // This object is not listening to any other events on `obj` yet.
  1304. // Setup the necessary references to track the listening callbacks.
  1305. if (!listening) {
  1306. var thisId = this._listenId || (this._listenId = _.uniqueId('l'));
  1307. listening = listeningTo[id] = {obj: obj, objId: id, id: thisId, listeningTo: listeningTo, count: 0};
  1308. }
  1309. // Bind callbacks on obj, and keep track of them on listening.
  1310. internalOn(obj, name, callback, this, listening);
  1311. return this;
  1312. };
  1313. // The reducing API that adds a callback to the `events` object.
  1314. var onApi = function(events, name, callback, options) {
  1315. if (callback) {
  1316. var handlers = events[name] || (events[name] = []);
  1317. var context = options.context, ctx = options.ctx, listening = options.listening;
  1318. if (listening) listening.count++;
  1319. handlers.push({callback: callback, context: context, ctx: context || ctx, listening: listening});
  1320. }
  1321. return events;
  1322. };
  1323. // Remove one or many callbacks. If `context` is null, removes all
  1324. // callbacks with that function. If `callback` is null, removes all
  1325. // callbacks for the event. If `name` is null, removes all bound
  1326. // callbacks for all events.
  1327. Events.off = function(name, callback, context) {
  1328. if (!this._events) return this;
  1329. this._events = eventsApi(offApi, this._events, name, callback, {
  1330. context: context,
  1331. listeners: this._listeners
  1332. });
  1333. return this;
  1334. };
  1335. // Tell this object to stop listening to either specific events ... or
  1336. // to every object it's currently listening to.
  1337. Events.stopListening = function(obj, name, callback) {
  1338. var listeningTo = this._listeningTo;
  1339. if (!listeningTo) return this;
  1340. var ids = obj ? [obj._listenId] : _.keys(listeningTo);
  1341. for (var i = 0; i < ids.length; i++) {
  1342. var listening = listeningTo[ids[i]];
  1343. // If listening doesn't exist, this object is not currently
  1344. // listening to obj. Break out early.
  1345. if (!listening) break;
  1346. listening.obj.off(name, callback, this);
  1347. }
  1348. return this;
  1349. };
  1350. // The reducing API that removes a callback from the `events` object.
  1351. var offApi = function(events, name, callback, options) {
  1352. if (!events) return;
  1353. var i = 0, listening;
  1354. var context = options.context, listeners = options.listeners;
  1355. // Delete all events listeners and "drop" events.
  1356. if (!name && !callback && !context) {
  1357. var ids = _.keys(listeners);
  1358. for (; i < ids.length; i++) {
  1359. listening = listeners[ids[i]];
  1360. delete listeners[listening.id];
  1361. delete listening.listeningTo[listening.objId];
  1362. }
  1363. return;
  1364. }
  1365. var names = name ? [name] : _.keys(events);
  1366. for (; i < names.length; i++) {
  1367. name = names[i];
  1368. var handlers = events[name];
  1369. // Bail out if there are no events stored.
  1370. if (!handlers) break;
  1371. // Replace events if there are any remaining. Otherwise, clean up.
  1372. var remaining = [];
  1373. for (var j = 0; j < handlers.length; j++) {
  1374. var handler = handlers[j];
  1375. if (
  1376. callback && callback !== handler.callback &&
  1377. callback !== handler.callback._callback ||
  1378. context && context !== handler.context
  1379. ) {
  1380. remaining.push(handler);
  1381. } else {
  1382. listening = handler.listening;
  1383. if (listening && --listening.count === 0) {
  1384. delete listeners[listening.id];
  1385. delete listening.listeningTo[listening.objId];
  1386. }
  1387. }
  1388. }
  1389. // Update tail event if the list has any events. Otherwise, clean up.
  1390. if (remaining.length) {
  1391. events[name] = remaining;
  1392. } else {
  1393. delete events[name];
  1394. }
  1395. }
  1396. return events;
  1397. };
  1398. // Bind an event to only be triggered a single time. After the first time
  1399. // the callback is invoked, its listener will be removed. If multiple events
  1400. // are passed in using the space-separated syntax, the handler will fire
  1401. // once for each event, not once for a combination of all events.
  1402. Events.once = function(name, callback, context) {
  1403. // Map the event into a `{event: once}` object.
  1404. var events = eventsApi(onceMap, {}, name, callback, _.bind(this.off, this));
  1405. if (typeof name === 'string' && context == null) callback = void 0;
  1406. return this.on(events, callback, context);
  1407. };
  1408. // Inversion-of-control versions of `once`.
  1409. Events.listenToOnce = function(obj, name, callback) {
  1410. // Map the event into a `{event: once}` object.
  1411. var events = eventsApi(onceMap, {}, name, callback, _.bind(this.stopListening, this, obj));
  1412. return this.listenTo(obj, events);
  1413. };
  1414. // Reduces the event callbacks into a map of `{event: onceWrapper}`.
  1415. // `offer` unbinds the `onceWrapper` after it has been called.
  1416. var onceMap = function(map, name, callback, offer) {
  1417. if (callback) {
  1418. var once = map[name] = _.once(function() {
  1419. offer(name, once);
  1420. callback.apply(this, arguments);
  1421. });
  1422. once._callback = callback;
  1423. }
  1424. return map;
  1425. };
  1426. // Trigger one or many events, firing all bound callbacks. Callbacks are
  1427. // passed the same arguments as `trigger` is, apart from the event name
  1428. // (unless you're listening on `"all"`, which will cause your callback to
  1429. // receive the true name of the event as the first argument).
  1430. Events.trigger = function(name) {
  1431. if (!this._events) return this;
  1432. var length = Math.max(0, arguments.length - 1);
  1433. var args = Array(length);
  1434. for (var i = 0; i < length; i++) args[i] = arguments[i + 1];
  1435. eventsApi(triggerApi, this._events, name, void 0, args);
  1436. return this;
  1437. };
  1438. // Handles triggering the appropriate event callbacks.
  1439. var triggerApi = function(objEvents, name, callback, args) {
  1440. if (objEvents) {
  1441. var events = objEvents[name];
  1442. var allEvents = objEvents.all;
  1443. if (events && allEvents) allEvents = allEvents.slice();
  1444. if (events) triggerEvents(events, args);
  1445. if (allEvents) triggerEvents(allEvents, [name].concat(args));
  1446. }
  1447. return objEvents;
  1448. };
  1449. // A difficult-to-believe, but optimized internal dispatch function for
  1450. // triggering events. Tries to keep the usual cases speedy (most internal
  1451. // Backbone events have 3 arguments).
  1452. var triggerEvents = function(events, args) {
  1453. var ev, i = -1, l = events.length, a1 = args[0], a2 = args[1], a3 = args[2];
  1454. switch (args.length) {
  1455. case 0: while (++i < l) (ev = events[i]).callback.call(ev.ctx); return;
  1456. case 1: while (++i < l) (ev = events[i]).callback.call(ev.ctx, a1); return;
  1457. case 2: while (++i < l) (ev = events[i]).callback.call(ev.ctx, a1, a2); return;
  1458. case 3: while (++i < l) (ev = events[i]).callback.call(ev.ctx, a1, a2, a3); return;
  1459. default: while (++i < l) (ev = events[i]).callback.apply(ev.ctx, args); return;
  1460. }
  1461. };
  1462. // Aliases for backwards compatibility.
  1463. Events.bind = Events.on;
  1464. Events.unbind = Events.off;
  1465. // Allow the `Backbone` object to serve as a global event bus, for folks who
  1466. // want global "pubsub" in a convenient place.
  1467. _.extend(Backbone, Events);
  1468. // Backbone.Model
  1469. // --------------
  1470. // Backbone **Models** are the basic data object in the framework --
  1471. // frequently representing a row in a table in a database on your server.
  1472. // A discrete chunk of data and a bunch of useful, related methods for
  1473. // performing computations and transformations on that data.
  1474. // Create a new model with the specified attributes. A client id (`cid`)
  1475. // is automatically generated and assigned for you.
  1476. var Model = Backbone.Model = function(attributes, options) {
  1477. var attrs = attributes || {};
  1478. options || (options = {});
  1479. this.cid = _.uniqueId(this.cidPrefix);
  1480. this.attributes = {};
  1481. if (options.collection) this.collection = options.collection;
  1482. if (options.parse) attrs = this.parse(attrs, options) || {};
  1483. var defaults = _.result(this, 'defaults');
  1484. attrs = _.defaults(_.extend({}, defaults, attrs), defaults);
  1485. this.set(attrs, options);
  1486. this.changed = {};
  1487. this.initialize.apply(this, arguments);
  1488. };
  1489. // Attach all inheritable methods to the Model prototype.
  1490. _.extend(Model.prototype, Events, {
  1491. // A hash of attributes whose current and previous value differ.
  1492. changed: null,
  1493. // The value returned during the last failed validation.
  1494. validationError: null,
  1495. // The default name for the JSON `id` attribute is `"id"`. MongoDB and
  1496. // CouchDB users may want to set this to `"_id"`.
  1497. idAttribute: 'id',
  1498. // The prefix is used to create the client id which is used to identify models locally.
  1499. // You may want to override this if you're experiencing name clashes with model ids.
  1500. cidPrefix: 'c',
  1501. // Initialize is an empty function by default. Override it with your own
  1502. // initialization logic.
  1503. initialize: function(){},
  1504. // Return a copy of the model's `attributes` object.
  1505. toJSON: function(options) {
  1506. return _.clone(this.attributes);
  1507. },
  1508. // Proxy `Backbone.sync` by default -- but override this if you need
  1509. // custom syncing semantics for *this* particular model.
  1510. sync: function() {
  1511. return Backbone.sync.apply(this, arguments);
  1512. },
  1513. // Get the value of an attribute.
  1514. get: function(attr) {
  1515. return this.attributes[attr];
  1516. },
  1517. // Get the HTML-escaped value of an attribute.
  1518. escape: function(attr) {
  1519. return _.escape(this.get(attr));
  1520. },
  1521. // Returns `true` if the attribute contains a value that is not null
  1522. // or undefined.
  1523. has: function(attr) {
  1524. return this.get(attr) != null;
  1525. },
  1526. // Special-cased proxy to underscore's `_.matches` method.
  1527. matches: function(attrs) {
  1528. return !!_.iteratee(attrs, this)(this.attributes);
  1529. },
  1530. // Set a hash of model attributes on the object, firing `"change"`. This is
  1531. // the core primitive operation of a model, updating the data and notifying
  1532. // anyone who needs to know about the change in state. The heart of the beast.
  1533. set: function(key, val, options) {
  1534. if (key == null) return this;
  1535. // Handle both `"key", value` and `{key: value}` -style arguments.
  1536. var attrs;
  1537. if (typeof key === 'object') {
  1538. attrs = key;
  1539. options = val;
  1540. } else {
  1541. (attrs = {})[key] = val;
  1542. }
  1543. options || (options = {});
  1544. // Run validation.
  1545. if (!this._validate(attrs, options)) return false;
  1546. // Extract attributes and options.
  1547. var unset = options.unset;
  1548. var silent = options.silent;
  1549. var changes = [];
  1550. var changing = this._changing;
  1551. this._changing = true;
  1552. if (!changing) {
  1553. this._previousAttributes = _.clone(this.attributes);
  1554. this.changed = {};
  1555. }
  1556. var current = this.attributes;
  1557. var changed = this.changed;
  1558. var prev = this._previousAttributes;
  1559. // For each `set` attribute, update or delete the current value.
  1560. for (var attr in attrs) {
  1561. val = attrs[attr];
  1562. if (!_.isEqual(current[attr], val)) changes.push(attr);
  1563. if (!_.isEqual(prev[attr], val)) {
  1564. changed[attr] = val;
  1565. } else {
  1566. delete changed[attr];
  1567. }
  1568. unset ? delete current[attr] : current[attr] = val;
  1569. }
  1570. // Update the `id`.
  1571. if (this.idAttribute in attrs) this.id = this.get(this.idAttribute);
  1572. // Trigger all relevant attribute changes.
  1573. if (!silent) {
  1574. if (changes.length) this._pending = options;
  1575. for (var i = 0; i < changes.length; i++) {
  1576. this.trigger('change:' + changes[i], this, current[changes[i]], options);
  1577. }
  1578. }
  1579. // You might be wondering why there's a `while` loop here. Changes can
  1580. // be recursively nested within `"change"` events.
  1581. if (changing) return this;
  1582. if (!silent) {
  1583. while (this._pending) {
  1584. options = this._pending;
  1585. this._pending = false;
  1586. this.trigger('change', this, options);
  1587. }
  1588. }
  1589. this._pending = false;
  1590. this._changing = false;
  1591. return this;
  1592. },
  1593. // Remove an attribute from the model, firing `"change"`. `unset` is a noop
  1594. // if the attribute doesn't exist.
  1595. unset: function(attr, options) {
  1596. return this.set(attr, void 0, _.extend({}, options, {unset: true}));
  1597. },
  1598. // Clear all attributes on the model, firing `"change"`.
  1599. clear: function(options) {
  1600. var attrs = {};
  1601. for (var key in this.attributes) attrs[key] = void 0;
  1602. return this.set(attrs, _.extend({}, options, {unset: true}));
  1603. },
  1604. // Determine if the model has changed since the last `"change"` event.
  1605. // If you specify an attribute name, determine if that attribute has changed.
  1606. hasChanged: function(attr) {
  1607. if (attr == null) return !_.isEmpty(this.changed);
  1608. return _.has(this.changed, attr);
  1609. },
  1610. // Return an object containing all the attributes that have changed, or
  1611. // false if there are no changed attributes. Useful for determining what
  1612. // parts of a view need to be updated and/or what attributes need to be
  1613. // persisted to the server. Unset attributes will be set to undefined.
  1614. // You can also pass an attributes object to diff against the model,
  1615. // determining if there *would be* a change.
  1616. changedAttributes: function(diff) {
  1617. if (!diff) return this.hasChanged() ? _.clone(this.changed) : false;
  1618. var old = this._changing ? this._previousAttributes : this.attributes;
  1619. var changed = {};
  1620. for (var attr in diff) {
  1621. var val = diff[attr];
  1622. if (_.isEqual(old[attr], val)) continue;
  1623. changed[attr] = val;
  1624. }
  1625. return _.size(changed) ? changed : false;
  1626. },
  1627. // Get the previous value of an attribute, recorded at the time the last
  1628. // `"change"` event was fired.
  1629. previous: function(attr) {
  1630. if (attr == null || !this._previousAttributes) return null;
  1631. return this._previousAttributes[attr];
  1632. },
  1633. // Get all of the attributes of the model at the time of the previous
  1634. // `"change"` event.
  1635. previousAttributes: function() {
  1636. return _.clone(this._previousAttributes);
  1637. },
  1638. // Fetch the model from the server, merging the response with the model's
  1639. // local attributes. Any changed attributes will trigger a "change" event.
  1640. fetch: function(options) {
  1641. options = _.extend({parse: true}, options);
  1642. var model = this;
  1643. var success = options.success;
  1644. options.success = function(resp) {
  1645. var serverAttrs = options.parse ? model.parse(resp, options) : resp;
  1646. if (!model.set(serverAttrs, options)) return false;
  1647. if (success) success.call(options.context, model, resp, options);
  1648. model.trigger('sync', model, resp, options);
  1649. };
  1650. wrapError(this, options);
  1651. return this.sync('read', this, options);
  1652. },
  1653. // Set a hash of model attributes, and sync the model to the server.
  1654. // If the server returns an attributes hash that differs, the model's
  1655. // state will be `set` again.
  1656. save: function(key, val, options) {
  1657. // Handle both `"key", value` and `{key: value}` -style arguments.
  1658. var attrs;
  1659. if (key == null || typeof key === 'object') {
  1660. attrs = key;
  1661. options = val;
  1662. } else {
  1663. (attrs = {})[key] = val;
  1664. }
  1665. options = _.extend({validate: true, parse: true}, options);
  1666. var wait = options.wait;
  1667. // If we're not waiting and attributes exist, save acts as
  1668. // `set(attr).save(null, opts)` with validation. Otherwise, check if
  1669. // the model will be valid when the attributes, if any, are set.
  1670. if (attrs && !wait) {
  1671. if (!this.set(attrs, options)) return false;
  1672. } else if (!this._validate(attrs, options)) {
  1673. return false;
  1674. }
  1675. // After a successful server-side save, the client is (optionally)
  1676. // updated with the server-side state.
  1677. var model = this;
  1678. var success = options.success;
  1679. var attributes = this.attributes;
  1680. options.success = function(resp) {
  1681. // Ensure attributes are restored during synchronous saves.
  1682. model.attributes = attributes;
  1683. var serverAttrs = options.parse ? model.parse(resp, options) : resp;
  1684. if (wait) serverAttrs = _.extend({}, attrs, serverAttrs);
  1685. if (serverAttrs && !model.set(serverAttrs, options)) return false;
  1686. if (success) success.call(options.context, model, resp, options);
  1687. model.trigger('sync', model, resp, options);
  1688. };
  1689. wrapError(this, options);
  1690. // Set temporary attributes if `{wait: true}` to properly find new ids.
  1691. if (attrs && wait) this.attributes = _.extend({}, attributes, attrs);
  1692. var method = this.isNew() ? 'create' : (options.patch ? 'patch' : 'update');
  1693. if (method === 'patch' && !options.attrs) options.attrs = attrs;
  1694. var xhr = this.sync(method, this, options);
  1695. // Restore attributes.
  1696. this.attributes = attributes;
  1697. return xhr;
  1698. },
  1699. // Destroy this model on the server if it was already persisted.
  1700. // Optimistically removes the model from its collection, if it has one.
  1701. // If `wait: true` is passed, waits for the server to respond before removal.
  1702. destroy: function(options) {
  1703. options = options ? _.clone(options) : {};
  1704. var model = this;
  1705. var success = options.success;
  1706. var wait = options.wait;
  1707. var destroy = function() {
  1708. model.stopListening();
  1709. model.trigger('destroy', model, model.collection, options);
  1710. };
  1711. options.success = function(resp) {
  1712. if (wait) destroy();
  1713. if (success) success.call(options.context, model, resp, options);
  1714. if (!model.isNew()) model.trigger('sync', model, resp, options);
  1715. };
  1716. var xhr = false;
  1717. if (this.isNew()) {
  1718. _.defer(options.success);
  1719. } else {
  1720. wrapError(this, options);
  1721. xhr = this.sync('delete', this, options);
  1722. }
  1723. if (!wait) destroy();
  1724. return xhr;
  1725. },
  1726. // Default URL for the model's representation on the server -- if you're
  1727. // using Backbone's restful methods, override this to change the endpoint
  1728. // that will be called.
  1729. url: function() {
  1730. var base =
  1731. _.result(this, 'urlRoot') ||
  1732. _.result(this.collection, 'url') ||
  1733. urlError();
  1734. if (this.isNew()) return base;
  1735. var id = this.get(this.idAttribute);
  1736. return base.replace(/[^\/]$/, '$&/') + encodeURIComponent(id);
  1737. },
  1738. // **parse** converts a response into the hash of attributes to be `set` on
  1739. // the model. The default implementation is just to pass the response along.
  1740. parse: function(resp, options) {
  1741. return resp;
  1742. },
  1743. // Create a new model with identical attributes to this one.
  1744. clone: function() {
  1745. return new this.constructor(this.attributes);
  1746. },
  1747. // A model is new if it has never been saved to the server, and lacks an id.
  1748. isNew: function() {
  1749. return !this.has(this.idAttribute);
  1750. },
  1751. // Check if the model is currently in a valid state.
  1752. isValid: function(options) {
  1753. return this._validate({}, _.extend({}, options, {validate: true}));
  1754. },
  1755. // Run validation against the next complete set of model attributes,
  1756. // returning `true` if all is well. Otherwise, fire an `"invalid"` event.
  1757. _validate: function(attrs, options) {
  1758. if (!options.validate || !this.validate) return true;
  1759. attrs = _.extend({}, this.attributes, attrs);
  1760. var error = this.validationError = this.validate(attrs, options) || null;
  1761. if (!error) return true;
  1762. this.trigger('invalid', this, error, _.extend(options, {validationError: error}));
  1763. return false;
  1764. }
  1765. });
  1766. // Underscore methods that we want to implement on the Model, mapped to the
  1767. // number of arguments they take.
  1768. var modelMethods = {keys: 1, values: 1, pairs: 1, invert: 1, pick: 0,
  1769. omit: 0, chain: 1, isEmpty: 1};
  1770. // Mix in each Underscore method as a proxy to `Model#attributes`.
  1771. addUnderscoreMethods(Model, modelMethods, 'attributes');
  1772. // Backbone.Collection
  1773. // -------------------
  1774. // If models tend to represent a single row of data, a Backbone Collection is
  1775. // more analogous to a table full of data ... or a small slice or page of that
  1776. // table, or a collection of rows that belong together for a particular reason
  1777. // -- all of the messages in this particular folder, all of the documents
  1778. // belonging to this particular author, and so on. Collections maintain
  1779. // indexes of their models, both in order, and for lookup by `id`.
  1780. // Create a new **Collection**, perhaps to contain a specific type of `model`.
  1781. // If a `comparator` is specified, the Collection will maintain
  1782. // its models in sort order, as they're added and removed.
  1783. var Collection = Backbone.Collection = function(models, options) {
  1784. options || (options = {});
  1785. if (options.model) this.model = options.model;
  1786. if (options.comparator !== void 0) this.comparator = options.comparator;
  1787. this._reset();
  1788. this.initialize.apply(this, arguments);
  1789. if (models) this.reset(models, _.extend({silent: true}, options));
  1790. };
  1791. // Default options for `Collection#set`.
  1792. var setOptions = {add: true, remove: true, merge: true};
  1793. var addOptions = {add: true, remove: false};
  1794. // Splices `insert` into `array` at index `at`.
  1795. var splice = function(array, insert, at) {
  1796. at = Math.min(Math.max(at, 0), array.length);
  1797. var tail = Array(array.length - at);
  1798. var length = insert.length;
  1799. var i;
  1800. for (i = 0; i < tail.length; i++) tail[i] = array[i + at];
  1801. for (i = 0; i < length; i++) array[i + at] = insert[i];
  1802. for (i = 0; i < tail.length; i++) array[i + length + at] = tail[i];
  1803. };
  1804. // Define the Collection's inheritable methods.
  1805. _.extend(Collection.prototype, Events, {
  1806. // The default model for a collection is just a **Backbone.Model**.
  1807. // This should be overridden in most cases.
  1808. model: Model,
  1809. // Initialize is an empty function by default. Override it with your own
  1810. // initialization logic.
  1811. initialize: function(){},
  1812. // The JSON representation of a Collection is an array of the
  1813. // models' attributes.
  1814. toJSON: function(options) {
  1815. return this.map(function(model) { return model.toJSON(options); });
  1816. },
  1817. // Proxy `Backbone.sync` by default.
  1818. sync: function() {
  1819. return Backbone.sync.apply(this, arguments);
  1820. },
  1821. // Add a model, or list of models to the set. `models` may be Backbone
  1822. // Models or raw JavaScript objects to be converted to Models, or any
  1823. // combination of the two.
  1824. add: function(models, options) {
  1825. return this.set(models, _.extend({merge: false}, options, addOptions));
  1826. },
  1827. // Remove a model, or a list of models from the set.
  1828. remove: function(models, options) {
  1829. options = _.extend({}, options);
  1830. var singular = !_.isArray(models);
  1831. models = singular ? [models] : models.slice();
  1832. var removed = this._removeModels(models, options);
  1833. if (!options.silent && removed.length) {
  1834. options.changes = {added: [], merged: [], removed: removed};
  1835. this.trigger('update', this, options);
  1836. }
  1837. return singular ? removed[0] : removed;
  1838. },
  1839. // Update a collection by `set`-ing a new list of models, adding new ones,
  1840. // removing models that are no longer present, and merging models that
  1841. // already exist in the collection, as necessary. Similar to **Model#set**,
  1842. // the core operation for updating the data contained by the collection.
  1843. set: function(models, options) {
  1844. if (models == null) return;
  1845. options = _.extend({}, setOptions, options);
  1846. if (options.parse && !this._isModel(models)) {
  1847. models = this.parse(models, options) || [];
  1848. }
  1849. var singular = !_.isArray(models);
  1850. models = singular ? [models] : models.slice();
  1851. var at = options.at;
  1852. if (at != null) at = +at;
  1853. if (at > this.length) at = this.length;
  1854. if (at < 0) at += this.length + 1;
  1855. var set = [];
  1856. var toAdd = [];
  1857. var toMerge = [];
  1858. var toRemove = [];
  1859. var modelMap = {};
  1860. var add = options.add;
  1861. var merge = options.merge;
  1862. var remove = options.remove;
  1863. var sort = false;
  1864. var sortable = this.comparator && at == null && options.sort !== false;
  1865. var sortAttr = _.isString(this.comparator) ? this.comparator : null;
  1866. // Turn bare objects into model references, and prevent invalid models
  1867. // from being added.
  1868. var model, i;
  1869. for (i = 0; i < models.length; i++) {
  1870. model = models[i];
  1871. // If a duplicate is found, prevent it from being added and
  1872. // optionally merge it into the existing model.
  1873. var existing = this.get(model);
  1874. if (existing) {
  1875. if (merge && model !== existing) {
  1876. var attrs = this._isModel(model) ? model.attributes : model;
  1877. if (options.parse) attrs = existing.parse(attrs, options);
  1878. existing.set(attrs, options);
  1879. toMerge.push(existing);
  1880. if (sortable && !sort) sort = existing.hasChanged(sortAttr);
  1881. }
  1882. if (!modelMap[existing.cid]) {
  1883. modelMap[existing.cid] = true;
  1884. set.push(existing);
  1885. }
  1886. models[i] = existing;
  1887. // If this is a new, valid model, push it to the `toAdd` list.
  1888. } else if (add) {
  1889. model = models[i] = this._prepareModel(model, options);
  1890. if (model) {
  1891. toAdd.push(model);
  1892. this._addReference(model, options);
  1893. modelMap[model.cid] = true;
  1894. set.push(model);
  1895. }
  1896. }
  1897. }
  1898. // Remove stale models.
  1899. if (remove) {
  1900. for (i = 0; i < this.length; i++) {
  1901. model = this.models[i];
  1902. if (!modelMap[model.cid]) toRemove.push(model);
  1903. }
  1904. if (toRemove.length) this._removeModels(toRemove, options);
  1905. }
  1906. // See if sorting is needed, update `length` and splice in new models.
  1907. var orderChanged = false;
  1908. var replace = !sortable && add && remove;
  1909. if (set.length && replace) {
  1910. orderChanged = this.length !== set.length || _.some(this.models, function(m, index) {
  1911. return m !== set[index];
  1912. });
  1913. this.models.length = 0;
  1914. splice(this.models, set, 0);
  1915. this.length = this.models.length;
  1916. } else if (toAdd.length) {
  1917. if (sortable) sort = true;
  1918. splice(this.models, toAdd, at == null ? this.length : at);
  1919. this.length = this.models.length;
  1920. }
  1921. // Silently sort the collection if appropriate.
  1922. if (sort) this.sort({silent: true});
  1923. // Unless silenced, it's time to fire all appropriate add/sort/update events.
  1924. if (!options.silent) {
  1925. for (i = 0; i < toAdd.length; i++) {
  1926. if (at != null) options.index = at + i;
  1927. model = toAdd[i];
  1928. model.trigger('add', model, this, options);
  1929. }
  1930. if (sort || orderChanged) this.trigger('sort', this, options);
  1931. if (toAdd.length || toRemove.length || toMerge.length) {
  1932. options.changes = {
  1933. added: toAdd,
  1934. removed: toRemove,
  1935. merged: toMerge
  1936. };
  1937. this.trigger('update', this, options);
  1938. }
  1939. }
  1940. // Return the added (or merged) model (or models).
  1941. return singular ? models[0] : models;
  1942. },
  1943. // When you have more items than you want to add or remove individually,
  1944. // you can reset the entire set with a new list of models, without firing
  1945. // any granular `add` or `remove` events. Fires `reset` when finished.
  1946. // Useful for bulk operations and optimizations.
  1947. reset: function(models, options) {
  1948. options = options ? _.clone(options) : {};
  1949. for (var i = 0; i < this.models.length; i++) {
  1950. this._removeReference(this.models[i], options);
  1951. }
  1952. options.previousModels = this.models;
  1953. this._reset();
  1954. models = this.add(models, _.extend({silent: true}, options));
  1955. if (!options.silent) this.trigger('reset', this, options);
  1956. return models;
  1957. },
  1958. // Add a model to the end of the collection.
  1959. push: function(model, options) {
  1960. return this.add(model, _.extend({at: this.length}, options));
  1961. },
  1962. // Remove a model from the end of the collection.
  1963. pop: function(options) {
  1964. var model = this.at(this.length - 1);
  1965. return this.remove(model, options);
  1966. },
  1967. // Add a model to the beginning of the collection.
  1968. unshift: function(model, options) {
  1969. return this.add(model, _.extend({at: 0}, options));
  1970. },
  1971. // Remove a model from the beginning of the collection.
  1972. shift: function(options) {
  1973. var model = this.at(0);
  1974. return this.remove(model, options);
  1975. },
  1976. // Slice out a sub-array of models from the collection.
  1977. slice: function() {
  1978. return slice.apply(this.models, arguments);
  1979. },
  1980. // Get a model from the set by id, cid, model object with id or cid
  1981. // properties, or an attributes object that is transformed through modelId.
  1982. get: function(obj) {
  1983. if (obj == null) return void 0;
  1984. return this._byId[obj] ||
  1985. this._byId[this.modelId(obj.attributes || obj)] ||
  1986. obj.cid && this._byId[obj.cid];
  1987. },
  1988. // Returns `true` if the model is in the collection.
  1989. has: function(obj) {
  1990. return this.get(obj) != null;
  1991. },
  1992. // Get the model at the given index.
  1993. at: function(index) {
  1994. if (index < 0) index += this.length;
  1995. return this.models[index];
  1996. },
  1997. // Return models with matching attributes. Useful for simple cases of
  1998. // `filter`.
  1999. where: function(attrs, first) {
  2000. return this[first ? 'find' : 'filter'](attrs);
  2001. },
  2002. // Return the first model with matching attributes. Useful for simple cases
  2003. // of `find`.
  2004. findWhere: function(attrs) {
  2005. return this.where(attrs, true);
  2006. },
  2007. // Force the collection to re-sort itself. You don't need to call this under
  2008. // normal circumstances, as the set will maintain sort order as each item
  2009. // is added.
  2010. sort: function(options) {
  2011. var comparator = this.comparator;
  2012. if (!comparator) throw new Error('Cannot sort a set without a comparator');
  2013. options || (options = {});
  2014. var length = comparator.length;
  2015. if (_.isFunction(comparator)) comparator = _.bind(comparator, this);
  2016. // Run sort based on type of `comparator`.
  2017. if (length === 1 || _.isString(comparator)) {
  2018. this.models = this.sortBy(comparator);
  2019. } else {
  2020. this.models.sort(comparator);
  2021. }
  2022. if (!options.silent) this.trigger('sort', this, options);
  2023. return this;
  2024. },
  2025. // Pluck an attribute from each model in the collection.
  2026. pluck: function(attr) {
  2027. return this.map(attr + '');
  2028. },
  2029. // Fetch the default set of models for this collection, resetting the
  2030. // collection when they arrive. If `reset: true` is passed, the response
  2031. // data will be passed through the `reset` method instead of `set`.
  2032. fetch: function(options) {
  2033. options = _.extend({parse: true}, options);
  2034. var success = options.success;
  2035. var collection = this;
  2036. options.success = function(resp) {
  2037. var method = options.reset ? 'reset' : 'set';
  2038. collection[method](resp, options);
  2039. if (success) success.call(options.context, collection, resp, options);
  2040. collection.trigger('sync', collection, resp, options);
  2041. };
  2042. wrapError(this, options);
  2043. return this.sync('read', this, options);
  2044. },
  2045. // Create a new instance of a model in this collection. Add the model to the
  2046. // collection immediately, unless `wait: true` is passed, in which case we
  2047. // wait for the server to agree.
  2048. create: function(model, options) {
  2049. options = options ? _.clone(options) : {};
  2050. var wait = options.wait;
  2051. model = this._prepareModel(model, options);
  2052. if (!model) return false;
  2053. if (!wait) this.add(model, options);
  2054. var collection = this;
  2055. var success = options.success;
  2056. options.success = function(m, resp, callbackOpts) {
  2057. if (wait) collection.add(m, callbackOpts);
  2058. if (success) success.call(callbackOpts.context, m, resp, callbackOpts);
  2059. };
  2060. model.save(null, options);
  2061. return model;
  2062. },
  2063. // **parse** converts a response into a list of models to be added to the
  2064. // collection. The default implementation is just to pass it through.
  2065. parse: function(resp, options) {
  2066. return resp;
  2067. },
  2068. // Create a new collection with an identical list of models as this one.
  2069. clone: function() {
  2070. return new this.constructor(this.models, {
  2071. model: this.model,
  2072. comparator: this.comparator
  2073. });
  2074. },
  2075. // Define how to uniquely identify models in the collection.
  2076. modelId: function(attrs) {
  2077. return attrs[this.model.prototype.idAttribute || 'id'];
  2078. },
  2079. // Private method to reset all internal state. Called when the collection
  2080. // is first initialized or reset.
  2081. _reset: function() {
  2082. this.length = 0;
  2083. this.models = [];
  2084. this._byId = {};
  2085. },
  2086. // Prepare a hash of attributes (or other model) to be added to this
  2087. // collection.
  2088. _prepareModel: function(attrs, options) {
  2089. if (this._isModel(attrs)) {
  2090. if (!attrs.collection) attrs.collection = this;
  2091. return attrs;
  2092. }
  2093. options = options ? _.clone(options) : {};
  2094. options.collection = this;
  2095. var model = new this.model(attrs, options);
  2096. if (!model.validationError) return model;
  2097. this.trigger('invalid', this, model.validationError, options);
  2098. return false;
  2099. },
  2100. // Internal method called by both remove and set.
  2101. _removeModels: function(models, options) {
  2102. var removed = [];
  2103. for (var i = 0; i < models.length; i++) {
  2104. var model = this.get(models[i]);
  2105. if (!model) continue;
  2106. var index = this.indexOf(model);
  2107. this.models.splice(index, 1);
  2108. this.length--;
  2109. // Remove references before triggering 'remove' event to prevent an
  2110. // infinite loop. #3693
  2111. delete this._byId[model.cid];
  2112. var id = this.modelId(model.attributes);
  2113. if (id != null) delete this._byId[id];
  2114. if (!options.silent) {
  2115. options.index = index;
  2116. model.trigger('remove', model, this, options);
  2117. }
  2118. removed.push(model);
  2119. this._removeReference(model, options);
  2120. }
  2121. return removed;
  2122. },
  2123. // Method for checking whether an object should be considered a model for
  2124. // the purposes of adding to the collection.
  2125. _isModel: function(model) {
  2126. return model instanceof Model;
  2127. },
  2128. // Internal method to create a model's ties to a collection.
  2129. _addReference: function(model, options) {
  2130. this._byId[model.cid] = model;
  2131. var id = this.modelId(model.attributes);
  2132. if (id != null) this._byId[id] = model;
  2133. model.on('all', this._onModelEvent, this);
  2134. },
  2135. // Internal method to sever a model's ties to a collection.
  2136. _removeReference: function(model, options) {
  2137. delete this._byId[model.cid];
  2138. var id = this.modelId(model.attributes);
  2139. if (id != null) delete this._byId[id];
  2140. if (this === model.collection) delete model.collection;
  2141. model.off('all', this._onModelEvent, this);
  2142. },
  2143. // Internal method called every time a model in the set fires an event.
  2144. // Sets need to update their indexes when models change ids. All other
  2145. // events simply proxy through. "add" and "remove" events that originate
  2146. // in other collections are ignored.
  2147. _onModelEvent: function(event, model, collection, options) {
  2148. if (model) {
  2149. if ((event === 'add' || event === 'remove') && collection !== this) return;
  2150. if (event === 'destroy') this.remove(model, options);
  2151. if (event === 'change') {
  2152. var prevId = this.modelId(model.previousAttributes());
  2153. var id = this.modelId(model.attributes);
  2154. if (prevId !== id) {
  2155. if (prevId != null) delete this._byId[prevId];
  2156. if (id != null) this._byId[id] = model;
  2157. }
  2158. }
  2159. }
  2160. this.trigger.apply(this, arguments);
  2161. }
  2162. });
  2163. // Underscore methods that we want to implement on the Collection.
  2164. // 90% of the core usefulness of Backbone Collections is actually implemented
  2165. // right here:
  2166. var collectionMethods = {forEach: 3, each: 3, map: 3, collect: 3, reduce: 0,
  2167. foldl: 0, inject: 0, reduceRight: 0, foldr: 0, find: 3, detect: 3, filter: 3,
  2168. select: 3, reject: 3, every: 3, all: 3, some: 3, any: 3, include: 3, includes: 3,
  2169. contains: 3, invoke: 0, max: 3, min: 3, toArray: 1, size: 1, first: 3,
  2170. head: 3, take: 3, initial: 3, rest: 3, tail: 3, drop: 3, last: 3,
  2171. without: 0, difference: 0, indexOf: 3, shuffle: 1, lastIndexOf: 3,
  2172. isEmpty: 1, chain: 1, sample: 3, partition: 3, groupBy: 3, countBy: 3,
  2173. sortBy: 3, indexBy: 3, findIndex: 3, findLastIndex: 3};
  2174. // Mix in each Underscore method as a proxy to `Collection#models`.
  2175. addUnderscoreMethods(Collection, collectionMethods, 'models');
  2176. // Backbone.View
  2177. // -------------
  2178. // Backbone Views are almost more convention than they are actual code. A View
  2179. // is simply a JavaScript object that represents a logical chunk of UI in the
  2180. // DOM. This might be a single item, an entire list, a sidebar or panel, or
  2181. // even the surrounding frame which wraps your whole app. Defining a chunk of
  2182. // UI as a **View** allows you to define your DOM events declaratively, without
  2183. // having to worry about render order ... and makes it easy for the view to
  2184. // react to specific changes in the state of your models.
  2185. // Creating a Backbone.View creates its initial element outside of the DOM,
  2186. // if an existing element is not provided...
  2187. var View = Backbone.View = function(options) {
  2188. this.cid = _.uniqueId('view');
  2189. _.extend(this, _.pick(options, viewOptions));
  2190. this._ensureElement();
  2191. this.initialize.apply(this, arguments);
  2192. };
  2193. // Cached regex to split keys for `delegate`.
  2194. var delegateEventSplitter = /^(\S+)\s*(.*)$/;
  2195. // List of view options to be set as properties.
  2196. var viewOptions = ['model', 'collection', 'el', 'id', 'attributes', 'className', 'tagName', 'events'];
  2197. // Set up all inheritable **Backbone.View** properties and methods.
  2198. _.extend(View.prototype, Events, {
  2199. // The default `tagName` of a View's element is `"div"`.
  2200. tagName: 'div',
  2201. // jQuery delegate for element lookup, scoped to DOM elements within the
  2202. // current view. This should be preferred to global lookups where possible.
  2203. $: function(selector) {
  2204. return this.$el.find(selector);
  2205. },
  2206. // Initialize is an empty function by default. Override it with your own
  2207. // initialization logic.
  2208. initialize: function(){},
  2209. // **render** is the core function that your view should override, in order
  2210. // to populate its element (`this.el`), with the appropriate HTML. The
  2211. // convention is for **render** to always return `this`.
  2212. render: function() {
  2213. return this;
  2214. },
  2215. // Remove this view by taking the element out of the DOM, and removing any
  2216. // applicable Backbone.Events listeners.
  2217. remove: function() {
  2218. this._removeElement();
  2219. this.stopListening();
  2220. return this;
  2221. },
  2222. // Remove this view's element from the document and all event listeners
  2223. // attached to it. Exposed for subclasses using an alternative DOM
  2224. // manipulation API.
  2225. _removeElement: function() {
  2226. this.$el.remove();
  2227. },
  2228. // Change the view's element (`this.el` property) and re-delegate the
  2229. // view's events on the new element.
  2230. setElement: function(element) {
  2231. this.undelegateEvents();
  2232. this._setElement(element);
  2233. this.delegateEvents();
  2234. return this;
  2235. },
  2236. // Creates the `this.el` and `this.$el` references for this view using the
  2237. // given `el`. `el` can be a CSS selector or an HTML string, a jQuery
  2238. // context or an element. Subclasses can override this to utilize an
  2239. // alternative DOM manipulation API and are only required to set the
  2240. // `this.el` property.
  2241. _setElement: function(el) {
  2242. this.$el = el instanceof Backbone.$ ? el : Backbone.$(el);
  2243. this.el = this.$el[0];
  2244. },
  2245. // Set callbacks, where `this.events` is a hash of
  2246. //
  2247. // *{"event selector": "callback"}*
  2248. //
  2249. // {
  2250. // 'mousedown .title': 'edit',
  2251. // 'click .button': 'save',
  2252. // 'click .open': function(e) { ... }
  2253. // }
  2254. //
  2255. // pairs. Callbacks will be bound to the view, with `this` set properly.
  2256. // Uses event delegation for efficiency.
  2257. // Omitting the selector binds the event to `this.el`.
  2258. delegateEvents: function(events) {
  2259. events || (events = _.result(this, 'events'));
  2260. if (!events) return this;
  2261. this.undelegateEvents();
  2262. for (var key in events) {
  2263. var method = events[key];
  2264. if (!_.isFunction(method)) method = this[method];
  2265. if (!method) continue;
  2266. var match = key.match(delegateEventSplitter);
  2267. this.delegate(match[1], match[2], _.bind(method, this));
  2268. }
  2269. return this;
  2270. },
  2271. // Add a single event listener to the view's element (or a child element
  2272. // using `selector`). This only works for delegate-able events: not `focus`,
  2273. // `blur`, and not `change`, `submit`, and `reset` in Internet Explorer.
  2274. delegate: function(eventName, selector, listener) {
  2275. this.$el.on(eventName + '.delegateEvents' + this.cid, selector, listener);
  2276. return this;
  2277. },
  2278. // Clears all callbacks previously bound to the view by `delegateEvents`.
  2279. // You usually don't need to use this, but may wish to if you have multiple
  2280. // Backbone views attached to the same DOM element.
  2281. undelegateEvents: function() {
  2282. if (this.$el) this.$el.off('.delegateEvents' + this.cid);
  2283. return this;
  2284. },
  2285. // A finer-grained `undelegateEvents` for removing a single delegated event.
  2286. // `selector` and `listener` are both optional.
  2287. undelegate: function(eventName, selector, listener) {
  2288. this.$el.off(eventName + '.delegateEvents' + this.cid, selector, listener);
  2289. return this;
  2290. },
  2291. // Produces a DOM element to be assigned to your view. Exposed for
  2292. // subclasses using an alternative DOM manipulation API.
  2293. _createElement: function(tagName) {
  2294. return document.createElement(tagName);
  2295. },
  2296. // Ensure that the View has a DOM element to render into.
  2297. // If `this.el` is a string, pass it through `$()`, take the first
  2298. // matching element, and re-assign it to `el`. Otherwise, create
  2299. // an element from the `id`, `className` and `tagName` properties.
  2300. _ensureElement: function() {
  2301. if (!this.el) {
  2302. var attrs = _.extend({}, _.result(this, 'attributes'));
  2303. if (this.id) attrs.id = _.result(this, 'id');
  2304. if (this.className) attrs['class'] = _.result(this, 'className');
  2305. this.setElement(this._createElement(_.result(this, 'tagName')));
  2306. this._setAttributes(attrs);
  2307. } else {
  2308. this.setElement(_.result(this, 'el'));
  2309. }
  2310. },
  2311. // Set attributes from a hash on this view's element. Exposed for
  2312. // subclasses using an alternative DOM manipulation API.
  2313. _setAttributes: function(attributes) {
  2314. this.$el.attr(attributes);
  2315. }
  2316. });
  2317. // Backbone.sync
  2318. // -------------
  2319. // Override this function to change the manner in which Backbone persists
  2320. // models to the server. You will be passed the type of request, and the
  2321. // model in question. By default, makes a RESTful Ajax request
  2322. // to the model's `url()`. Some possible customizations could be:
  2323. //
  2324. // * Use `setTimeout` to batch rapid-fire updates into a single request.
  2325. // * Send up the models as XML instead of JSON.
  2326. // * Persist models via WebSockets instead of Ajax.
  2327. //
  2328. // Turn on `Backbone.emulateHTTP` in order to send `PUT` and `DELETE` requests
  2329. // as `POST`, with a `_method` parameter containing the true HTTP method,
  2330. // as well as all requests with the body as `application/x-www-form-urlencoded`
  2331. // instead of `application/json` with the model in a param named `model`.
  2332. // Useful when interfacing with server-side languages like **PHP** that make
  2333. // it difficult to read the body of `PUT` requests.
  2334. Backbone.sync = function(method, model, options) {
  2335. var type = methodMap[method];
  2336. // Default options, unless specified.
  2337. _.defaults(options || (options = {}), {
  2338. emulateHTTP: Backbone.emulateHTTP,
  2339. emulateJSON: Backbone.emulateJSON
  2340. });
  2341. // Default JSON-request options.
  2342. var params = {type: type, dataType: 'json'};
  2343. // Ensure that we have a URL.
  2344. if (!options.url) {
  2345. params.url = _.result(model, 'url') || urlError();
  2346. }
  2347. // Ensure that we have the appropriate request data.
  2348. if (options.data == null && model && (method === 'create' || method === 'update' || method === 'patch')) {
  2349. params.contentType = 'application/json';
  2350. params.data = JSON.stringify(options.attrs || model.toJSON(options));
  2351. }
  2352. // For older servers, emulate JSON by encoding the request into an HTML-form.
  2353. if (options.emulateJSON) {
  2354. params.contentType = 'application/x-www-form-urlencoded';
  2355. params.data = params.data ? {model: params.data} : {};
  2356. }
  2357. // For older servers, emulate HTTP by mimicking the HTTP method with `_method`
  2358. // And an `X-HTTP-Method-Override` header.
  2359. if (options.emulateHTTP && (type === 'PUT' || type === 'DELETE' || type === 'PATCH')) {
  2360. params.type = 'POST';
  2361. if (options.emulateJSON) params.data._method = type;
  2362. var beforeSend = options.beforeSend;
  2363. options.beforeSend = function(xhr) {
  2364. xhr.setRequestHeader('X-HTTP-Method-Override', type);
  2365. if (beforeSend) return beforeSend.apply(this, arguments);
  2366. };
  2367. }
  2368. // Don't process data on a non-GET request.
  2369. if (params.type !== 'GET' && !options.emulateJSON) {
  2370. params.processData = false;
  2371. }
  2372. // Pass along `textStatus` and `errorThrown` from jQuery.
  2373. var error = options.error;
  2374. options.error = function(xhr, textStatus, errorThrown) {
  2375. options.textStatus = textStatus;
  2376. options.errorThrown = errorThrown;
  2377. if (error) error.call(options.context, xhr, textStatus, errorThrown);
  2378. };
  2379. // Make the request, allowing the user to override any Ajax options.
  2380. var xhr = options.xhr = Backbone.ajax(_.extend(params, options));
  2381. model.trigger('request', model, xhr, options);
  2382. return xhr;
  2383. };
  2384. // Map from CRUD to HTTP for our default `Backbone.sync` implementation.
  2385. var methodMap = {
  2386. 'create': 'POST',
  2387. 'update': 'PUT',
  2388. 'patch': 'PATCH',
  2389. 'delete': 'DELETE',
  2390. 'read': 'GET'
  2391. };
  2392. // Set the default implementation of `Backbone.ajax` to proxy through to `$`.
  2393. // Override this if you'd like to use a different library.
  2394. Backbone.ajax = function() {
  2395. return Backbone.$.ajax.apply(Backbone.$, arguments);
  2396. };
  2397. // Backbone.Router
  2398. // ---------------
  2399. // Routers map faux-URLs to actions, and fire events when routes are
  2400. // matched. Creating a new one sets its `routes` hash, if not set statically.
  2401. var Router = Backbone.Router = function(options) {
  2402. options || (options = {});
  2403. if (options.routes) this.routes = options.routes;
  2404. this._bindRoutes();
  2405. this.initialize.apply(this, arguments);
  2406. };
  2407. // Cached regular expressions for matching named param parts and splatted
  2408. // parts of route strings.
  2409. var optionalParam = /\((.*?)\)/g;
  2410. var namedParam = /(\(\?)?:\w+/g;
  2411. var splatParam = /\*\w+/g;
  2412. var escapeRegExp = /[\-{}\[\]+?.,\\\^$|#\s]/g;
  2413. // Set up all inheritable **Backbone.Router** properties and methods.
  2414. _.extend(Router.prototype, Events, {
  2415. // Initialize is an empty function by default. Override it with your own
  2416. // initialization logic.
  2417. initialize: function(){},
  2418. // Manually bind a single named route to a callback. For example:
  2419. //
  2420. // this.route('search/:query/p:num', 'search', function(query, num) {
  2421. // ...
  2422. // });
  2423. //
  2424. route: function(route, name, callback) {
  2425. if (!_.isRegExp(route)) route = this._routeToRegExp(route);
  2426. if (_.isFunction(name)) {
  2427. callback = name;
  2428. name = '';
  2429. }
  2430. if (!callback) callback = this[name];
  2431. var router = this;
  2432. Backbone.history.route(route, function(fragment) {
  2433. var args = router._extractParameters(route, fragment);
  2434. if (router.execute(callback, args, name) !== false) {
  2435. router.trigger.apply(router, ['route:' + name].concat(args));
  2436. router.trigger('route', name, args);
  2437. Backbone.history.trigger('route', router, name, args);
  2438. }
  2439. });
  2440. return this;
  2441. },
  2442. // Execute a route handler with the provided parameters. This is an
  2443. // excellent place to do pre-route setup or post-route cleanup.
  2444. execute: function(callback, args, name) {
  2445. if (callback) callback.apply(this, args);
  2446. },
  2447. // Simple proxy to `Backbone.history` to save a fragment into the history.
  2448. navigate: function(fragment, options) {
  2449. Backbone.history.navigate(fragment, options);
  2450. return this;
  2451. },
  2452. // Bind all defined routes to `Backbone.history`. We have to reverse the
  2453. // order of the routes here to support behavior where the most general
  2454. // routes can be defined at the bottom of the route map.
  2455. _bindRoutes: function() {
  2456. if (!this.routes) return;
  2457. this.routes = _.result(this, 'routes');
  2458. var route, routes = _.keys(this.routes);
  2459. while ((route = routes.pop()) != null) {
  2460. this.route(route, this.routes[route]);
  2461. }
  2462. },
  2463. // Convert a route string into a regular expression, suitable for matching
  2464. // against the current location hash.
  2465. _routeToRegExp: function(route) {
  2466. route = route.replace(escapeRegExp, '\\$&')
  2467. .replace(optionalParam, '(?:$1)?')
  2468. .replace(namedParam, function(match, optional) {
  2469. return optional ? match : '([^/?]+)';
  2470. })
  2471. .replace(splatParam, '([^?]*?)');
  2472. return new RegExp('^' + route + '(?:\\?([\\s\\S]*))?$');
  2473. },
  2474. // Given a route, and a URL fragment that it matches, return the array of
  2475. // extracted decoded parameters. Empty or unmatched parameters will be
  2476. // treated as `null` to normalize cross-browser behavior.
  2477. _extractParameters: function(route, fragment) {
  2478. var params = route.exec(fragment).slice(1);
  2479. return _.map(params, function(param, i) {
  2480. // Don't decode the search params.
  2481. if (i === params.length - 1) return param || null;
  2482. return param ? decodeURIComponent(param) : null;
  2483. });
  2484. }
  2485. });
  2486. // Backbone.History
  2487. // ----------------
  2488. // Handles cross-browser history management, based on either
  2489. // [pushState](http://diveintohtml5.info/history.html) and real URLs, or
  2490. // [onhashchange](https://developer.mozilla.org/en-US/docs/DOM/window.onhashchange)
  2491. // and URL fragments. If the browser supports neither (old IE, natch),
  2492. // falls back to polling.
  2493. var History = Backbone.History = function() {
  2494. this.handlers = [];
  2495. this.checkUrl = _.bind(this.checkUrl, this);
  2496. // Ensure that `History` can be used outside of the browser.
  2497. if (typeof window !== 'undefined') {
  2498. this.location = window.location;
  2499. this.history = window.history;
  2500. }
  2501. };
  2502. // Cached regex for stripping a leading hash/slash and trailing space.
  2503. var routeStripper = /^[#\/]|\s+$/g;
  2504. // Cached regex for stripping leading and trailing slashes.
  2505. var rootStripper = /^\/+|\/+$/g;
  2506. // Cached regex for stripping urls of hash.
  2507. var pathStripper = /#.*$/;
  2508. // Has the history handling already been started?
  2509. History.started = false;
  2510. // Set up all inheritable **Backbone.History** properties and methods.
  2511. _.extend(History.prototype, Events, {
  2512. // The default interval to poll for hash changes, if necessary, is
  2513. // twenty times a second.
  2514. interval: 50,
  2515. // Are we at the app root?
  2516. atRoot: function() {
  2517. var path = this.location.pathname.replace(/[^\/]$/, '$&/');
  2518. return path === this.root && !this.getSearch();
  2519. },
  2520. // Does the pathname match the root?
  2521. matchRoot: function() {
  2522. var path = this.decodeFragment(this.location.pathname);
  2523. var rootPath = path.slice(0, this.root.length - 1) + '/';
  2524. return rootPath === this.root;
  2525. },
  2526. // Unicode characters in `location.pathname` are percent encoded so they're
  2527. // decoded for comparison. `%25` should not be decoded since it may be part
  2528. // of an encoded parameter.
  2529. decodeFragment: function(fragment) {
  2530. return decodeURI(fragment.replace(/%25/g, '%2525'));
  2531. },
  2532. // In IE6, the hash fragment and search params are incorrect if the
  2533. // fragment contains `?`.
  2534. getSearch: function() {
  2535. var match = this.location.href.replace(/#.*/, '').match(/\?.+/);
  2536. return match ? match[0] : '';
  2537. },
  2538. // Gets the true hash value. Cannot use location.hash directly due to bug
  2539. // in Firefox where location.hash will always be decoded.
  2540. getHash: function(window) {
  2541. var match = (window || this).location.href.match(/#(.*)$/);
  2542. return match ? match[1] : '';
  2543. },
  2544. // Get the pathname and search params, without the root.
  2545. getPath: function() {
  2546. var path = this.decodeFragment(
  2547. this.location.pathname + this.getSearch()
  2548. ).slice(this.root.length - 1);
  2549. return path.charAt(0) === '/' ? path.slice(1) : path;
  2550. },
  2551. // Get the cross-browser normalized URL fragment from the path or hash.
  2552. getFragment: function(fragment) {
  2553. if (fragment == null) {
  2554. if (this._usePushState || !this._wantsHashChange) {
  2555. fragment = this.getPath();
  2556. } else {
  2557. fragment = this.getHash();
  2558. }
  2559. }
  2560. return fragment.replace(routeStripper, '');
  2561. },
  2562. // Start the hash change handling, returning `true` if the current URL matches
  2563. // an existing route, and `false` otherwise.
  2564. start: function(options) {
  2565. if (History.started) throw new Error('Backbone.history has already been started');
  2566. History.started = true;
  2567. // Figure out the initial configuration. Do we need an iframe?
  2568. // Is pushState desired ... is it available?
  2569. this.options = _.extend({root: '/'}, this.options, options);
  2570. this.root = this.options.root;
  2571. this._wantsHashChange = this.options.hashChange !== false;
  2572. this._hasHashChange = 'onhashchange' in window && (document.documentMode === void 0 || document.documentMode > 7);
  2573. this._useHashChange = this._wantsHashChange && this._hasHashChange;
  2574. this._wantsPushState = !!this.options.pushState;
  2575. this._hasPushState = !!(this.history && this.history.pushState);
  2576. this._usePushState = this._wantsPushState && this._hasPushState;
  2577. this.fragment = this.getFragment();
  2578. // Normalize root to always include a leading and trailing slash.
  2579. this.root = ('/' + this.root + '/').replace(rootStripper, '/');
  2580. // Transition from hashChange to pushState or vice versa if both are
  2581. // requested.
  2582. if (this._wantsHashChange && this._wantsPushState) {
  2583. // If we've started off with a route from a `pushState`-enabled
  2584. // browser, but we're currently in a browser that doesn't support it...
  2585. if (!this._hasPushState && !this.atRoot()) {
  2586. var rootPath = this.root.slice(0, -1) || '/';
  2587. this.location.replace(rootPath + '#' + this.getPath());
  2588. // Return immediately as browser will do redirect to new url
  2589. return true;
  2590. // Or if we've started out with a hash-based route, but we're currently
  2591. // in a browser where it could be `pushState`-based instead...
  2592. } else if (this._hasPushState && this.atRoot()) {
  2593. this.navigate(this.getHash(), {replace: true});
  2594. }
  2595. }
  2596. // Proxy an iframe to handle location events if the browser doesn't
  2597. // support the `hashchange` event, HTML5 history, or the user wants
  2598. // `hashChange` but not `pushState`.
  2599. if (!this._hasHashChange && this._wantsHashChange && !this._usePushState) {
  2600. this.iframe = document.createElement('iframe');
  2601. this.iframe.src = 'javascript:0';
  2602. this.iframe.style.display = 'none';
  2603. this.iframe.tabIndex = -1;
  2604. var body = document.body;
  2605. // Using `appendChild` will throw on IE < 9 if the document is not ready.
  2606. var iWindow = body.insertBefore(this.iframe, body.firstChild).contentWindow;
  2607. iWindow.document.open();
  2608. iWindow.document.close();
  2609. iWindow.location.hash = '#' + this.fragment;
  2610. }
  2611. // Add a cross-platform `addEventListener` shim for older browsers.
  2612. var addEventListener = window.addEventListener || function(eventName, listener) {
  2613. return attachEvent('on' + eventName, listener);
  2614. };
  2615. // Depending on whether we're using pushState or hashes, and whether
  2616. // 'onhashchange' is supported, determine how we check the URL state.
  2617. if (this._usePushState) {
  2618. addEventListener('popstate', this.checkUrl, false);
  2619. } else if (this._useHashChange && !this.iframe) {
  2620. addEventListener('hashchange', this.checkUrl, false);
  2621. } else if (this._wantsHashChange) {
  2622. this._checkUrlInterval = setInterval(this.checkUrl, this.interval);
  2623. }
  2624. if (!this.options.silent) return this.loadUrl();
  2625. },
  2626. // Disable Backbone.history, perhaps temporarily. Not useful in a real app,
  2627. // but possibly useful for unit testing Routers.
  2628. stop: function() {
  2629. // Add a cross-platform `removeEventListener` shim for older browsers.
  2630. var removeEventListener = window.removeEventListener || function(eventName, listener) {
  2631. return detachEvent('on' + eventName, listener);
  2632. };
  2633. // Remove window listeners.
  2634. if (this._usePushState) {
  2635. removeEventListener('popstate', this.checkUrl, false);
  2636. } else if (this._useHashChange && !this.iframe) {
  2637. removeEventListener('hashchange', this.checkUrl, false);
  2638. }
  2639. // Clean up the iframe if necessary.
  2640. if (this.iframe) {
  2641. document.body.removeChild(this.iframe);
  2642. this.iframe = null;
  2643. }
  2644. // Some environments will throw when clearing an undefined interval.
  2645. if (this._checkUrlInterval) clearInterval(this._checkUrlInterval);
  2646. History.started = false;
  2647. },
  2648. // Add a route to be tested when the fragment changes. Routes added later
  2649. // may override previous routes.
  2650. route: function(route, callback) {
  2651. this.handlers.unshift({route: route, callback: callback});
  2652. },
  2653. // Checks the current URL to see if it has changed, and if it has,
  2654. // calls `loadUrl`, normalizing across the hidden iframe.
  2655. checkUrl: function(e) {
  2656. var current = this.getFragment();
  2657. // If the user pressed the back button, the iframe's hash will have
  2658. // changed and we should use that for comparison.
  2659. if (current === this.fragment && this.iframe) {
  2660. current = this.getHash(this.iframe.contentWindow);
  2661. }
  2662. if (current === this.fragment) return false;
  2663. if (this.iframe) this.navigate(current);
  2664. this.loadUrl();
  2665. },
  2666. // Attempt to load the current URL fragment. If a route succeeds with a
  2667. // match, returns `true`. If no defined routes matches the fragment,
  2668. // returns `false`.
  2669. loadUrl: function(fragment) {
  2670. // If the root doesn't match, no routes can match either.
  2671. if (!this.matchRoot()) return false;
  2672. fragment = this.fragment = this.getFragment(fragment);
  2673. return _.some(this.handlers, function(handler) {
  2674. if (handler.route.test(fragment)) {
  2675. handler.callback(fragment);
  2676. return true;
  2677. }
  2678. });
  2679. },
  2680. // Save a fragment into the hash history, or replace the URL state if the
  2681. // 'replace' option is passed. You are responsible for properly URL-encoding
  2682. // the fragment in advance.
  2683. //
  2684. // The options object can contain `trigger: true` if you wish to have the
  2685. // route callback be fired (not usually desirable), or `replace: true`, if
  2686. // you wish to modify the current URL without adding an entry to the history.
  2687. navigate: function(fragment, options) {
  2688. if (!History.started) return false;
  2689. if (!options || options === true) options = {trigger: !!options};
  2690. // Normalize the fragment.
  2691. fragment = this.getFragment(fragment || '');
  2692. // Don't include a trailing slash on the root.
  2693. var rootPath = this.root;
  2694. if (fragment === '' || fragment.charAt(0) === '?') {
  2695. rootPath = rootPath.slice(0, -1) || '/';
  2696. }
  2697. var url = rootPath + fragment;
  2698. // Strip the hash and decode for matching.
  2699. fragment = this.decodeFragment(fragment.replace(pathStripper, ''));
  2700. if (this.fragment === fragment) return;
  2701. this.fragment = fragment;
  2702. // If pushState is available, we use it to set the fragment as a real URL.
  2703. if (this._usePushState) {
  2704. this.history[options.replace ? 'replaceState' : 'pushState']({}, document.title, url);
  2705. // If hash changes haven't been explicitly disabled, update the hash
  2706. // fragment to store history.
  2707. } else if (this._wantsHashChange) {
  2708. this._updateHash(this.location, fragment, options.replace);
  2709. if (this.iframe && fragment !== this.getHash(this.iframe.contentWindow)) {
  2710. var iWindow = this.iframe.contentWindow;
  2711. // Opening and closing the iframe tricks IE7 and earlier to push a
  2712. // history entry on hash-tag change. When replace is true, we don't
  2713. // want this.
  2714. if (!options.replace) {
  2715. iWindow.document.open();
  2716. iWindow.document.close();
  2717. }
  2718. this._updateHash(iWindow.location, fragment, options.replace);
  2719. }
  2720. // If you've told us that you explicitly don't want fallback hashchange-
  2721. // based history, then `navigate` becomes a page refresh.
  2722. } else {
  2723. return this.location.assign(url);
  2724. }
  2725. if (options.trigger) return this.loadUrl(fragment);
  2726. },
  2727. // Update the hash location, either replacing the current entry, or adding
  2728. // a new one to the browser history.
  2729. _updateHash: function(location, fragment, replace) {
  2730. if (replace) {
  2731. var href = location.href.replace(/(javascript:|#).*$/, '');
  2732. location.replace(href + '#' + fragment);
  2733. } else {
  2734. // Some browsers require that `hash` contains a leading #.
  2735. location.hash = '#' + fragment;
  2736. }
  2737. }
  2738. });
  2739. // Create the default Backbone.history.
  2740. Backbone.history = new History;
  2741. // Helpers
  2742. // -------
  2743. // Helper function to correctly set up the prototype chain for subclasses.
  2744. // Similar to `goog.inherits`, but uses a hash of prototype properties and
  2745. // class properties to be extended.
  2746. var extend = function(protoProps, staticProps) {
  2747. var parent = this;
  2748. var child;
  2749. // The constructor function for the new subclass is either defined by you
  2750. // (the "constructor" property in your `extend` definition), or defaulted
  2751. // by us to simply call the parent constructor.
  2752. if (protoProps && _.has(protoProps, 'constructor')) {
  2753. child = protoProps.constructor;
  2754. } else {
  2755. child = function(){ return parent.apply(this, arguments); };
  2756. }
  2757. // Add static properties to the constructor function, if supplied.
  2758. _.extend(child, parent, staticProps);
  2759. // Set the prototype chain to inherit from `parent`, without calling
  2760. // `parent`'s constructor function and add the prototype properties.
  2761. child.prototype = _.create(parent.prototype, protoProps);
  2762. child.prototype.constructor = child;
  2763. // Set a convenience property in case the parent's prototype is needed
  2764. // later.
  2765. child.__super__ = parent.prototype;
  2766. return child;
  2767. };
  2768. // Set up inheritance for the model, collection, router, view and history.
  2769. Model.extend = Collection.extend = Router.extend = View.extend = History.extend = extend;
  2770. // Throw an error when a URL is needed, and none is supplied.
  2771. var urlError = function() {
  2772. throw new Error('A "url" property or function must be specified');
  2773. };
  2774. // Wrap an optional error callback with a fallback error event.
  2775. var wrapError = function(model, options) {
  2776. var error = options.error;
  2777. options.error = function(resp) {
  2778. if (error) error.call(options.context, model, resp, options);
  2779. model.trigger('error', model, resp, options);
  2780. };
  2781. };
  2782. return Backbone;
  2783. });
  2784. /* WEBPACK VAR INJECTION */}.call(this, __webpack_require__(/*! ./../webpack/buildin/global.js */ "./node_modules/webpack/buildin/global.js")))
  2785. /***/ }),
  2786. /***/ "./node_modules/cash-dom/dist/cash.esm.js":
  2787. /*!************************************************!*\
  2788. !*** ./node_modules/cash-dom/dist/cash.esm.js ***!
  2789. \************************************************/
  2790. /*! exports provided: default */
  2791. /***/ (function(module, __webpack_exports__, __webpack_require__) {
  2792. "use strict";
  2793. __webpack_require__.r(__webpack_exports__);
  2794. /* MIT https://github.com/kenwheeler/cash */
  2795. var doc = document,
  2796. win = window,
  2797. _Array$prototype = Array.prototype,
  2798. filter = _Array$prototype.filter,
  2799. indexOf = _Array$prototype.indexOf,
  2800. map = _Array$prototype.map,
  2801. push = _Array$prototype.push,
  2802. reverse = _Array$prototype.reverse,
  2803. slice = _Array$prototype.slice,
  2804. splice = _Array$prototype.splice;
  2805. var idRe = /^#[\w-]*$/,
  2806. classRe = /^\.[\w-]*$/,
  2807. htmlRe = /<.+>/,
  2808. tagRe = /^\w+$/; // @require ./variables.js
  2809. function find(selector, context) {
  2810. if (context === void 0) {
  2811. context = doc;
  2812. }
  2813. return classRe.test(selector) ? context.getElementsByClassName(selector.slice(1)) : tagRe.test(selector) ? context.getElementsByTagName(selector) : context.querySelectorAll(selector);
  2814. } // @require ./find.js
  2815. // @require ./variables.js
  2816. function Cash(selector, context) {
  2817. if (context === void 0) {
  2818. context = doc;
  2819. }
  2820. if (!selector) return;
  2821. if (selector.__cash) return selector;
  2822. var eles = selector;
  2823. if (isString(selector)) {
  2824. if (context.__cash) context = context[0];
  2825. eles = idRe.test(selector) ? context.getElementById(selector.slice(1)) : htmlRe.test(selector) ? parseHTML(selector) : find(selector, context);
  2826. if (!eles) return;
  2827. } else if (isFunction(selector)) {
  2828. return this.ready(selector); //FIXME: `fn.ready` is not included in `core`, but it's actually a core functionality
  2829. }
  2830. if (eles.nodeType || eles === win) eles = [eles];
  2831. this.length = eles.length;
  2832. for (var i = 0, l = this.length; i < l; i++) {
  2833. this[i] = eles[i];
  2834. }
  2835. }
  2836. function cash(selector, context) {
  2837. return new Cash(selector, context);
  2838. }
  2839. /* PROTOTYPE */
  2840. var fn = cash.fn = cash.prototype = Cash.prototype = {
  2841. constructor: cash,
  2842. __cash: true,
  2843. length: 0,
  2844. splice: splice // Ensures a cash collection gets printed as array-like in Chrome
  2845. }; // @require core/cash.js
  2846. // @require core/variables.js
  2847. fn.get = function (index) {
  2848. if (index === undefined) return slice.call(this);
  2849. return this[index < 0 ? index + this.length : index];
  2850. }; // @require core/cash.js
  2851. // @require ./get.js
  2852. fn.eq = function (index) {
  2853. return cash(this.get(index));
  2854. }; // @require core/cash.js
  2855. // @require ./eq.js
  2856. fn.first = function () {
  2857. return this.eq(0);
  2858. }; // @require core/cash.js
  2859. // @require ./eq.js
  2860. fn.last = function () {
  2861. return this.eq(-1);
  2862. }; // @require core/cash.js
  2863. // @require core/variables.js
  2864. fn.map = function (callback) {
  2865. return cash(map.call(this, function (ele, i) {
  2866. return callback.call(ele, i, ele);
  2867. }));
  2868. }; // @require core/cash.js
  2869. // @require core/variables.js
  2870. fn.slice = function () {
  2871. return cash(slice.apply(this, arguments));
  2872. }; // @require ./cash.js
  2873. var camelCaseRe = /(?:^\w|[A-Z]|\b\w)/g,
  2874. camelCaseWhitespaceRe = /[\s-_]+/g;
  2875. function camelCase(str) {
  2876. return str.replace(camelCaseRe, function (letter, index) {
  2877. return letter[!index ? 'toLowerCase' : 'toUpperCase']();
  2878. }).replace(camelCaseWhitespaceRe, '');
  2879. }
  2880. ;
  2881. cash.camelCase = camelCase; // @require ./cash.js
  2882. function each(arr, callback) {
  2883. for (var i = 0, l = arr.length; i < l; i++) {
  2884. if (callback.call(arr[i], arr[i], i, arr) === false) break;
  2885. }
  2886. }
  2887. cash.each = each; // @require core/cash.js
  2888. // @require core/each.js
  2889. fn.each = function (callback) {
  2890. each(this, function (ele, i) {
  2891. return callback.call(ele, i, ele);
  2892. });
  2893. return this;
  2894. }; // @require core/cash.js
  2895. // @require collection/each.js
  2896. fn.removeProp = function (prop) {
  2897. return this.each(function (i, ele) {
  2898. delete ele[prop];
  2899. });
  2900. }; // @require ./cash.js
  2901. function extend(target) {
  2902. if (target === void 0) {
  2903. target = this;
  2904. }
  2905. var args = arguments,
  2906. length = args.length;
  2907. for (var i = length < 2 ? 0 : 1; i < length; i++) {
  2908. for (var key in args[i]) {
  2909. target[key] = args[i][key];
  2910. }
  2911. }
  2912. return target;
  2913. }
  2914. ;
  2915. cash.extend = fn.extend = extend; // @require ./cash.js
  2916. var guid = 1;
  2917. cash.guid = guid; // @require ./cash.js
  2918. function matches(ele, selector) {
  2919. var matches = ele && (ele.matches || ele.webkitMatchesSelector || ele.mozMatchesSelector || ele.msMatchesSelector || ele.oMatchesSelector);
  2920. return !!matches && matches.call(ele, selector);
  2921. }
  2922. cash.matches = matches; // @require ./cash.js
  2923. function isFunction(x) {
  2924. return typeof x === 'function';
  2925. }
  2926. cash.isFunction = isFunction;
  2927. function isString(x) {
  2928. return typeof x === 'string';
  2929. }
  2930. cash.isString = isString;
  2931. function isNumeric(x) {
  2932. return !isNaN(parseFloat(x)) && isFinite(x);
  2933. }
  2934. cash.isNumeric = isNumeric;
  2935. var isArray = Array.isArray;
  2936. cash.isArray = isArray; // @require core/cash.js
  2937. // @require core/type_checking.js
  2938. // @require collection/each.js
  2939. fn.prop = function (prop, value) {
  2940. if (!prop) return;
  2941. if (isString(prop)) {
  2942. if (arguments.length < 2) return this[0] && this[0][prop];
  2943. return this.each(function (i, ele) {
  2944. ele[prop] = value;
  2945. });
  2946. }
  2947. for (var key in prop) {
  2948. this.prop(key, prop[key]);
  2949. }
  2950. return this;
  2951. }; // @require ./matches.js
  2952. // @require ./type_checking.js
  2953. function getCompareFunction(selector) {
  2954. return isString(selector) ? function (i, ele) {
  2955. return matches(ele, selector);
  2956. } : selector.__cash ? function (i, ele) {
  2957. return selector.is(ele);
  2958. } : function (i, ele, selector) {
  2959. return ele === selector;
  2960. };
  2961. } // @require core/cash.js
  2962. // @require core/get_compare_function.js
  2963. // @require core/type_checking.js
  2964. // @require core/variables.js
  2965. // @require collection/get.js
  2966. fn.filter = function (selector) {
  2967. if (!selector) return cash();
  2968. var comparator = isFunction(selector) ? selector : getCompareFunction(selector);
  2969. return cash(filter.call(this, function (ele, i) {
  2970. return comparator.call(ele, i, ele, selector);
  2971. }));
  2972. }; // @require ./type_checking.js
  2973. var splitValuesRe = /\S+/g;
  2974. function getSplitValues(str) {
  2975. return isString(str) ? str.match(splitValuesRe) || [] : [];
  2976. } // @require core/cash.js
  2977. // @require core/get_split_values.js
  2978. // @require collection/each.js
  2979. fn.hasClass = function (cls) {
  2980. var classes = getSplitValues(cls);
  2981. var check = false;
  2982. if (classes.length) {
  2983. this.each(function (i, ele) {
  2984. check = ele.classList.contains(classes[0]);
  2985. return !check;
  2986. });
  2987. }
  2988. return check;
  2989. }; // @require core/cash.js
  2990. // @require core/get_split_values.js
  2991. // @require collection/each.js
  2992. fn.removeAttr = function (attr) {
  2993. var attrs = getSplitValues(attr);
  2994. if (!attrs.length) return this;
  2995. return this.each(function (i, ele) {
  2996. each(attrs, function (a) {
  2997. ele.removeAttribute(a);
  2998. });
  2999. });
  3000. }; // @require core/cash.js
  3001. // @require core/type_checking.js
  3002. // @require collection/each.js
  3003. // @require ./remove_attr.js
  3004. fn.attr = function (attr, value) {
  3005. if (!attr) return;
  3006. if (isString(attr)) {
  3007. if (arguments.length < 2) {
  3008. if (!this[0]) return;
  3009. var _value = this[0].getAttribute(attr);
  3010. return _value === null ? undefined : _value;
  3011. }
  3012. if (value === null) return this.removeAttr(attr);
  3013. return this.each(function (i, ele) {
  3014. ele.setAttribute(attr, value);
  3015. });
  3016. }
  3017. for (var key in attr) {
  3018. this.attr(key, attr[key]);
  3019. }
  3020. return this;
  3021. }; // @require core/cash.js
  3022. // @require core/each.js
  3023. // @require core/get_split_values.js
  3024. // @require collection/each.js
  3025. fn.toggleClass = function (cls, force) {
  3026. var classes = getSplitValues(cls),
  3027. isForce = force !== undefined;
  3028. if (!classes.length) return this;
  3029. return this.each(function (i, ele) {
  3030. each(classes, function (c) {
  3031. if (isForce) {
  3032. force ? ele.classList.add(c) : ele.classList.remove(c);
  3033. } else {
  3034. ele.classList.toggle(c);
  3035. }
  3036. });
  3037. });
  3038. }; // @require core/cash.js
  3039. // @require ./toggle_class.js
  3040. fn.addClass = function (cls) {
  3041. return this.toggleClass(cls, true);
  3042. }; // @require core/cash.js
  3043. // @require ./attr.js
  3044. // @require ./toggle_class.js
  3045. fn.removeClass = function (cls) {
  3046. return !arguments.length ? this.attr('class', '') : this.toggleClass(cls, false);
  3047. }; // @optional ./add_class.js
  3048. // @optional ./attr.js
  3049. // @optional ./has_class.js
  3050. // @optional ./prop.js
  3051. // @optional ./remove_attr.js
  3052. // @optional ./remove_class.js
  3053. // @optional ./remove_prop.js
  3054. // @optional ./toggle_class.js
  3055. // @require ./cash.js
  3056. function unique(arr) {
  3057. return arr.filter(function (item, index, self) {
  3058. return self.indexOf(item) === index;
  3059. });
  3060. }
  3061. cash.unique = unique; // @require core/cash.js
  3062. // @require core/unique.js
  3063. // @require ./get.js
  3064. fn.add = function (selector, context) {
  3065. return cash(unique(this.get().concat(cash(selector, context).get())));
  3066. }; // @require core/variables.js
  3067. function computeStyle(ele, prop, isVariable) {
  3068. if (ele.nodeType !== 1) return;
  3069. var style = win.getComputedStyle(ele, null);
  3070. return prop ? isVariable ? style.getPropertyValue(prop) : style[prop] : style;
  3071. } // @require ./compute_style.js
  3072. function computeStyleInt(ele, prop) {
  3073. return parseInt(computeStyle(ele, prop), 10) || 0;
  3074. }
  3075. var cssVariableRe = /^--/; // @require ./variables.js
  3076. function isCSSVariable(prop) {
  3077. return cssVariableRe.test(prop);
  3078. } // @require core/camel_case.js
  3079. // @require core/cash.js
  3080. // @require core/each.js
  3081. // @require core/variables.js
  3082. // @require ./is_css_variable.js
  3083. var prefixedProps = {},
  3084. _doc$createElement = doc.createElement('div'),
  3085. style = _doc$createElement.style,
  3086. vendorsPrefixes = ['webkit', 'moz', 'ms', 'o'];
  3087. function getPrefixedProp(prop, isVariable) {
  3088. if (isVariable === void 0) {
  3089. isVariable = isCSSVariable(prop);
  3090. }
  3091. if (isVariable) return prop;
  3092. if (!prefixedProps[prop]) {
  3093. var propCC = camelCase(prop),
  3094. propUC = "" + propCC.charAt(0).toUpperCase() + propCC.slice(1),
  3095. props = (propCC + " " + vendorsPrefixes.join(propUC + " ") + propUC).split(' ');
  3096. each(props, function (p) {
  3097. if (p in style) {
  3098. prefixedProps[prop] = p;
  3099. return false;
  3100. }
  3101. });
  3102. }
  3103. return prefixedProps[prop];
  3104. }
  3105. ;
  3106. cash.prefixedProp = getPrefixedProp; // @require core/type_checking.js
  3107. // @require ./is_css_variable.js
  3108. var numericProps = {
  3109. animationIterationCount: true,
  3110. columnCount: true,
  3111. flexGrow: true,
  3112. flexShrink: true,
  3113. fontWeight: true,
  3114. lineHeight: true,
  3115. opacity: true,
  3116. order: true,
  3117. orphans: true,
  3118. widows: true,
  3119. zIndex: true
  3120. };
  3121. function getSuffixedValue(prop, value, isVariable) {
  3122. if (isVariable === void 0) {
  3123. isVariable = isCSSVariable(prop);
  3124. }
  3125. return !isVariable && !numericProps[prop] && isNumeric(value) ? value + "px" : value;
  3126. } // @require core/cash.js
  3127. // @require core/type_checking.js
  3128. // @require collection/each.js
  3129. // @require ./helpers/compute_style.js
  3130. // @require ./helpers/get_prefixed_prop.js
  3131. // @require ./helpers/get_suffixed_value.js
  3132. // @require ./helpers/is_css_variable.js
  3133. fn.css = function (prop, value) {
  3134. if (isString(prop)) {
  3135. var isVariable = isCSSVariable(prop);
  3136. prop = getPrefixedProp(prop, isVariable);
  3137. if (arguments.length < 2) return this[0] && computeStyle(this[0], prop, isVariable);
  3138. if (!prop) return this;
  3139. value = getSuffixedValue(prop, value, isVariable);
  3140. return this.each(function (i, ele) {
  3141. if (ele.nodeType !== 1) return;
  3142. if (isVariable) {
  3143. ele.style.setProperty(prop, value);
  3144. } else {
  3145. ele.style[prop] = value;
  3146. }
  3147. });
  3148. }
  3149. for (var key in prop) {
  3150. this.css(key, prop[key]);
  3151. }
  3152. return this;
  3153. }; // @optional ./css.js
  3154. var dataNamespace = '__cashData',
  3155. dataAttributeRe = /^data-(.*)/; // @require core/cash.js
  3156. // @require ./helpers/variables.js
  3157. cash.hasData = function (ele) {
  3158. return dataNamespace in ele;
  3159. }; // @require ./variables.js
  3160. function getDataCache(ele) {
  3161. return ele[dataNamespace] = ele[dataNamespace] || {};
  3162. } // @require attributes/attr.js
  3163. // @require ./get_data_cache.js
  3164. function getData(ele, key) {
  3165. var cache = getDataCache(ele);
  3166. if (key) {
  3167. if (!(key in cache)) {
  3168. var value = ele.dataset ? ele.dataset[key] || ele.dataset[camelCase(key)] : cash(ele).attr("data-" + key);
  3169. if (value !== undefined) {
  3170. try {
  3171. value = JSON.parse(value);
  3172. } catch (e) {}
  3173. cache[key] = value;
  3174. }
  3175. }
  3176. return cache[key];
  3177. }
  3178. return cache;
  3179. } // @require ./variables.js
  3180. // @require ./get_data_cache.js
  3181. function removeData(ele, key) {
  3182. if (key === undefined) {
  3183. delete ele[dataNamespace];
  3184. } else {
  3185. delete getDataCache(ele)[key];
  3186. }
  3187. } // @require ./get_data_cache.js
  3188. function setData(ele, key, value) {
  3189. getDataCache(ele)[key] = value;
  3190. } // @require core/cash.js
  3191. // @require core/type_checking.js
  3192. // @require collection/each.js
  3193. // @require ./helpers/get_data.js
  3194. // @require ./helpers/set_data.js
  3195. // @require ./helpers/variables.js
  3196. fn.data = function (name, value) {
  3197. var _this = this;
  3198. if (!name) {
  3199. if (!this[0]) return;
  3200. each(this[0].attributes, function (attr) {
  3201. var match = attr.name.match(dataAttributeRe);
  3202. if (!match) return;
  3203. _this.data(match[1]);
  3204. });
  3205. return getData(this[0]);
  3206. }
  3207. if (isString(name)) {
  3208. if (value === undefined) return this[0] && getData(this[0], name);
  3209. return this.each(function (i, ele) {
  3210. return setData(ele, name, value);
  3211. });
  3212. }
  3213. for (var key in name) {
  3214. this.data(key, name[key]);
  3215. }
  3216. return this;
  3217. }; // @require core/cash.js
  3218. // @require collection/each.js
  3219. // @require ./helpers/remove_data.js
  3220. fn.removeData = function (key) {
  3221. return this.each(function (i, ele) {
  3222. return removeData(ele, key);
  3223. });
  3224. }; // @optional ./data.js
  3225. // @optional ./remove_data.js
  3226. // @require css/helpers/compute_style_int.js
  3227. function getExtraSpace(ele, xAxis) {
  3228. return computeStyleInt(ele, "border" + (xAxis ? 'Left' : 'Top') + "Width") + computeStyleInt(ele, "padding" + (xAxis ? 'Left' : 'Top')) + computeStyleInt(ele, "padding" + (xAxis ? 'Right' : 'Bottom')) + computeStyleInt(ele, "border" + (xAxis ? 'Right' : 'Bottom') + "Width");
  3229. } // @require core/cash.js
  3230. // @require core/each.js
  3231. // @require core/variables.js
  3232. each(['Width', 'Height'], function (prop) {
  3233. fn["inner" + prop] = function () {
  3234. if (!this[0]) return;
  3235. if (this[0] === win) return win["inner" + prop];
  3236. return this[0]["client" + prop];
  3237. };
  3238. }); // @require core/camel_case.js
  3239. // @require core/cash.js
  3240. // @require core/each.js
  3241. // @require core/variables.js
  3242. // @require css/helpers/compute_style.js
  3243. // @require css/helpers/get_suffixed_value.js
  3244. // @require ./helpers/get_extra_space.js
  3245. each(['width', 'height'], function (prop, index) {
  3246. fn[prop] = function (value) {
  3247. if (!this[0]) return value === undefined ? undefined : this;
  3248. if (!arguments.length) {
  3249. if (this[0] === win) return this[0][camelCase("outer-" + prop)];
  3250. return this[0].getBoundingClientRect()[prop] - getExtraSpace(this[0], !index);
  3251. }
  3252. value = parseInt(value, 10);
  3253. return this.each(function (i, ele) {
  3254. if (ele.nodeType !== 1) return;
  3255. var boxSizing = computeStyle(ele, 'boxSizing');
  3256. ele.style[prop] = getSuffixedValue(prop, value + (boxSizing === 'border-box' ? getExtraSpace(ele, !index) : 0));
  3257. });
  3258. };
  3259. }); // @require core/cash.js
  3260. // @require core/each.js
  3261. // @require core/variables.js
  3262. // @require css/helpers/compute_style_int.js
  3263. each(['Width', 'Height'], function (prop, index) {
  3264. fn["outer" + prop] = function (includeMargins) {
  3265. if (!this[0]) return;
  3266. if (this[0] === win) return win["outer" + prop];
  3267. return this[0]["offset" + prop] + (includeMargins ? computeStyleInt(this[0], "margin" + (!index ? 'Left' : 'Top')) + computeStyleInt(this[0], "margin" + (!index ? 'Right' : 'Bottom')) : 0);
  3268. };
  3269. }); // @optional ./inner.js
  3270. // @optional ./normal.js
  3271. // @optional ./outer.js
  3272. function hasNamespaces(ns1, ns2) {
  3273. for (var i = 0, l = ns2.length; i < l; i++) {
  3274. if (ns1.indexOf(ns2[i]) < 0) return false;
  3275. }
  3276. return true;
  3277. } // @require core/each.js
  3278. function removeEventListeners(cache, ele, name) {
  3279. each(cache[name], function (_ref) {
  3280. var namespaces = _ref[0],
  3281. callback = _ref[1];
  3282. ele.removeEventListener(name, callback);
  3283. });
  3284. delete cache[name];
  3285. }
  3286. var eventsNamespace = '__cashEvents',
  3287. eventsNamespacesSeparator = '.'; // @require ./variables.js
  3288. function getEventsCache(ele) {
  3289. return ele[eventsNamespace] = ele[eventsNamespace] || {};
  3290. } // @require core/guid.js
  3291. // @require events/helpers/get_events_cache.js
  3292. function addEvent(ele, name, namespaces, callback) {
  3293. callback.guid = callback.guid || guid++;
  3294. var eventCache = getEventsCache(ele);
  3295. eventCache[name] = eventCache[name] || [];
  3296. eventCache[name].push([namespaces, callback]);
  3297. ele.addEventListener(name, callback);
  3298. } // @require ./variables.js
  3299. function parseEventName(eventName) {
  3300. var parts = eventName.split(eventsNamespacesSeparator);
  3301. return [parts[0], parts.slice(1).sort()]; // [name, namespaces]
  3302. } // @require core/guid.js
  3303. // @require ./get_events_cache.js
  3304. // @require ./has_namespaces.js
  3305. // @require ./parse_event_name.js
  3306. // @require ./remove_event_listeners.js
  3307. function removeEvent(ele, name, namespaces, callback) {
  3308. var cache = getEventsCache(ele);
  3309. if (!name) {
  3310. if (!namespaces || !namespaces.length) {
  3311. for (name in cache) {
  3312. removeEventListeners(cache, ele, name);
  3313. }
  3314. } else {
  3315. for (name in cache) {
  3316. removeEvent(ele, name, namespaces, callback);
  3317. }
  3318. }
  3319. } else {
  3320. var eventCache = cache[name];
  3321. if (!eventCache) return;
  3322. if (callback) callback.guid = callback.guid || guid++;
  3323. cache[name] = eventCache.filter(function (_ref2) {
  3324. var ns = _ref2[0],
  3325. cb = _ref2[1];
  3326. if (callback && cb.guid !== callback.guid || !hasNamespaces(ns, namespaces)) return true;
  3327. ele.removeEventListener(name, cb);
  3328. });
  3329. }
  3330. } // @require core/cash.js
  3331. // @require core/each.js
  3332. // @require collection/each.js
  3333. // @require ./helpers/parse_event_name.js
  3334. // @require ./helpers/remove_event.js
  3335. fn.off = function (eventFullName, callback) {
  3336. var _this2 = this;
  3337. if (eventFullName === undefined) {
  3338. this.each(function (i, ele) {
  3339. return removeEvent(ele);
  3340. });
  3341. } else {
  3342. each(getSplitValues(eventFullName), function (eventFullName) {
  3343. var _parseEventName = parseEventName(eventFullName),
  3344. name = _parseEventName[0],
  3345. namespaces = _parseEventName[1];
  3346. _this2.each(function (i, ele) {
  3347. return removeEvent(ele, name, namespaces, callback);
  3348. });
  3349. });
  3350. }
  3351. return this;
  3352. }; // @require core/cash.js
  3353. // @require core/get_split_values.js
  3354. // @require core/guid.js
  3355. // @require core/matches.js
  3356. // @require core/type_checking.js
  3357. // @require collection/each.js
  3358. // @require ./helpers/variables.js
  3359. // @require ./helpers/add_event.js
  3360. // @require ./helpers/has_namespaces.js
  3361. // @require ./helpers/parse_event_name.js
  3362. // @require ./helpers/remove_event.js
  3363. fn.on = function (eventFullName, selector, callback, _one) {
  3364. var _this3 = this;
  3365. if (!isString(eventFullName)) {
  3366. for (var key in eventFullName) {
  3367. this.on(key, selector, eventFullName[key]);
  3368. }
  3369. return this;
  3370. }
  3371. if (isFunction(selector)) {
  3372. callback = selector;
  3373. selector = false;
  3374. }
  3375. each(getSplitValues(eventFullName), function (eventFullName) {
  3376. var _parseEventName2 = parseEventName(eventFullName),
  3377. name = _parseEventName2[0],
  3378. namespaces = _parseEventName2[1];
  3379. _this3.each(function (i, ele) {
  3380. var finalCallback = function finalCallback(event) {
  3381. if (event.namespace && !hasNamespaces(namespaces, event.namespace.split(eventsNamespacesSeparator))) return;
  3382. var thisArg = ele;
  3383. if (selector) {
  3384. var target = event.target;
  3385. while (!matches(target, selector)) {
  3386. if (target === ele) return;
  3387. target = target.parentNode;
  3388. if (!target) return;
  3389. }
  3390. thisArg = target;
  3391. }
  3392. event.namespace = event.namespace || '';
  3393. var returnValue = callback.call(thisArg, event, event.data);
  3394. if (_one) {
  3395. removeEvent(ele, name, namespaces, finalCallback);
  3396. }
  3397. if (returnValue === false) {
  3398. event.preventDefault();
  3399. event.stopPropagation();
  3400. }
  3401. };
  3402. finalCallback.guid = callback.guid = callback.guid || guid++;
  3403. addEvent(ele, name, namespaces, finalCallback);
  3404. });
  3405. });
  3406. return this;
  3407. }; // @require core/cash.js
  3408. // @require ./on.js
  3409. fn.one = function (eventFullName, delegate, callback) {
  3410. return this.on(eventFullName, delegate, callback, true);
  3411. }; // @require core/cash.js
  3412. // @require core/variables.js
  3413. fn.ready = function (callback) {
  3414. var finalCallback = function finalCallback() {
  3415. return callback(cash);
  3416. };
  3417. if (doc.readyState !== 'loading') {
  3418. setTimeout(finalCallback);
  3419. } else {
  3420. doc.addEventListener('DOMContentLoaded', finalCallback);
  3421. }
  3422. return this;
  3423. }; // @require core/cash.js
  3424. // @require core/type_checking.js
  3425. // @require core/variables.js
  3426. // @require collection/each.js
  3427. // @require ./helpers/parse_event_name.js
  3428. // @require ./helpers/variables.js
  3429. fn.trigger = function (eventFullName, data) {
  3430. var evt = eventFullName;
  3431. if (isString(eventFullName)) {
  3432. var _parseEventName3 = parseEventName(eventFullName),
  3433. name = _parseEventName3[0],
  3434. namespaces = _parseEventName3[1];
  3435. evt = doc.createEvent('HTMLEvents');
  3436. evt.initEvent(name, true, true);
  3437. evt.namespace = namespaces.join(eventsNamespacesSeparator);
  3438. }
  3439. evt.data = data;
  3440. return this.each(function (i, ele) {
  3441. ele.dispatchEvent(evt);
  3442. });
  3443. }; // @optional ./off.js
  3444. // @optional ./on.js
  3445. // @optional ./one.js
  3446. // @optional ./ready.js
  3447. // @optional ./trigger.js
  3448. // @require core/each.js
  3449. function getValueSelectMultiple(ele) {
  3450. var values = [];
  3451. each(ele.options, function (option) {
  3452. if (option.selected && !option.disabled && !option.parentNode.disabled) {
  3453. values.push(option.value);
  3454. }
  3455. });
  3456. return values;
  3457. }
  3458. function getValueSelectSingle(ele) {
  3459. return ele.selectedIndex < 0 ? null : ele.options[ele.selectedIndex].value;
  3460. } // @require ./get_value_select_single.js
  3461. // @require ./get_value_select_multiple.js
  3462. var selectOneRe = /select-one/i,
  3463. selectMultipleRe = /select-multiple/i;
  3464. function getValue(ele) {
  3465. var type = ele.type;
  3466. if (selectOneRe.test(type)) return getValueSelectSingle(ele);
  3467. if (selectMultipleRe.test(type)) return getValueSelectMultiple(ele);
  3468. return ele.value;
  3469. }
  3470. var queryEncodeSpaceRe = /%20/g;
  3471. function queryEncode(prop, value) {
  3472. return "&" + encodeURIComponent(prop) + "=" + encodeURIComponent(value).replace(queryEncodeSpaceRe, '+');
  3473. } // @require core/cash.js
  3474. // @require core/each.js
  3475. // @require core/type_checking.js
  3476. // @require ./helpers/get_value.js
  3477. // @require ./helpers/query_encode.js
  3478. var skippableRe = /file|reset|submit|button|image/i,
  3479. checkableRe = /radio|checkbox/i;
  3480. fn.serialize = function () {
  3481. var query = '';
  3482. this.each(function (i, ele) {
  3483. each(ele.elements || [ele], function (ele) {
  3484. if (ele.disabled || !ele.name || ele.tagName === 'FIELDSET') return;
  3485. if (skippableRe.test(ele.type)) return;
  3486. if (checkableRe.test(ele.type) && !ele.checked) return;
  3487. var value = getValue(ele);
  3488. if (value === undefined) return;
  3489. var values = isArray(value) ? value : [value];
  3490. each(values, function (value) {
  3491. query += queryEncode(ele.name, value);
  3492. });
  3493. });
  3494. });
  3495. return query.substr(1);
  3496. }; // @require core/cash.js
  3497. // @require core/each.js
  3498. // @require core/type_checking.js
  3499. // @require collection/each.js
  3500. // @require ./helpers/get_value.js
  3501. fn.val = function (value) {
  3502. if (value === undefined) return this[0] && getValue(this[0]);
  3503. return this.each(function (i, ele) {
  3504. var isMultiple = selectMultipleRe.test(ele.type),
  3505. eleValue = value === null ? isMultiple ? [] : '' : value;
  3506. if (isMultiple && isArray(eleValue)) {
  3507. each(ele.options, function (option) {
  3508. option.selected = eleValue.indexOf(option.value) >= 0;
  3509. });
  3510. } else {
  3511. ele.value = eleValue;
  3512. }
  3513. });
  3514. }; // @optional ./serialize.js
  3515. // @optional ./val.js
  3516. // @require core/cash.js
  3517. // @require collection/map.js
  3518. fn.clone = function () {
  3519. return this.map(function (i, ele) {
  3520. return ele.cloneNode(true);
  3521. });
  3522. }; // @require core/cash.js
  3523. // @require collection/each.js
  3524. fn.detach = function () {
  3525. return this.each(function (i, ele) {
  3526. if (ele.parentNode) {
  3527. ele.parentNode.removeChild(ele);
  3528. }
  3529. });
  3530. }; // @require ./cash.js
  3531. // @require ./variables.js
  3532. // @require ./type_checking.js
  3533. // @require collection/get.js
  3534. // @require manipulation/detach.js
  3535. var fragmentRe = /^\s*<(\w+)[^>]*>/,
  3536. singleTagRe = /^\s*<(\w+)\s*\/?>(?:<\/\1>)?\s*$/;
  3537. var containers;
  3538. function initContainers() {
  3539. if (containers) return;
  3540. var table = doc.createElement('table'),
  3541. tr = doc.createElement('tr');
  3542. containers = {
  3543. '*': doc.createElement('div'),
  3544. tr: doc.createElement('tbody'),
  3545. td: tr,
  3546. th: tr,
  3547. thead: table,
  3548. tbody: table,
  3549. tfoot: table
  3550. };
  3551. }
  3552. function parseHTML(html) {
  3553. initContainers();
  3554. if (!isString(html)) return [];
  3555. if (singleTagRe.test(html)) return [doc.createElement(RegExp.$1)];
  3556. var fragment = fragmentRe.test(html) && RegExp.$1,
  3557. container = containers[fragment] || containers['*'];
  3558. container.innerHTML = html;
  3559. return cash(container.childNodes).detach().get();
  3560. }
  3561. cash.parseHTML = parseHTML; // @optional ./camel_case.js
  3562. // @optional ./each.js
  3563. // @optional ./export.js
  3564. // @optional ./extend.js
  3565. // @optional ./find.js
  3566. // @optional ./get_compare_function.js
  3567. // @optional ./get_split_values.js
  3568. // @optional ./guid.js
  3569. // @optional ./matches.js
  3570. // @optional ./parse_html.js
  3571. // @optional ./unique.js
  3572. // @optional ./variables.js
  3573. // @require ./cash.js
  3574. // @require ./type_checking.js
  3575. // @require core/cash.js
  3576. fn.empty = function () {
  3577. var ele = this[0];
  3578. if (ele) {
  3579. while (ele.firstChild) {
  3580. ele.removeChild(ele.firstChild);
  3581. }
  3582. }
  3583. return this;
  3584. };
  3585. function insertElement(ele, child, prepend) {
  3586. if (prepend) {
  3587. ele.insertBefore(child, ele.childNodes[0]);
  3588. } else {
  3589. ele.appendChild(child);
  3590. }
  3591. } // @require core/each.js
  3592. // @require core/type_checking.js
  3593. // @require ./insert_element.js
  3594. function insertContent(parent, child, prepend) {
  3595. if (child === undefined) return;
  3596. var isStr = isString(child);
  3597. if (!isStr && child.length) {
  3598. each(child, function (ele) {
  3599. return insertContent(parent, ele, prepend);
  3600. });
  3601. } else {
  3602. each(parent, isStr ? function (ele) {
  3603. ele.insertAdjacentHTML(prepend ? 'afterbegin' : 'beforeend', child);
  3604. } : function (ele, index) {
  3605. return insertElement(ele, !index ? child : child.cloneNode(true), prepend);
  3606. });
  3607. }
  3608. } // @require core/cash.js
  3609. // @require core/each.js
  3610. // @require ./helpers/insert_content.js
  3611. fn.append = function () {
  3612. var _this4 = this;
  3613. each(arguments, function (content) {
  3614. insertContent(_this4, content);
  3615. });
  3616. return this;
  3617. }; // @require core/cash.js
  3618. // @require ./helpers/insert_content.js
  3619. fn.appendTo = function (parent) {
  3620. insertContent(cash(parent), this);
  3621. return this;
  3622. }; // @require core/cash.js
  3623. // @require collection/each.js
  3624. fn.html = function (content) {
  3625. if (content === undefined) return this[0] && this[0].innerHTML;
  3626. var source = content.nodeType ? content[0].outerHTML : content;
  3627. return this.each(function (i, ele) {
  3628. ele.innerHTML = source;
  3629. });
  3630. }; // @require core/cash.js
  3631. // @require collection/each.js
  3632. fn.insertAfter = function (content) {
  3633. var _this5 = this;
  3634. cash(content).each(function (index, ele) {
  3635. var parent = ele.parentNode;
  3636. _this5.each(function (i, e) {
  3637. parent.insertBefore(!index ? e : e.cloneNode(true), ele.nextSibling);
  3638. });
  3639. });
  3640. return this;
  3641. }; // @require core/cash.js
  3642. // @require core/each.js
  3643. // @require core/variables.js
  3644. // @require collection/slice.js
  3645. // @require ./insert_after.js
  3646. fn.after = function () {
  3647. var _this6 = this;
  3648. each(reverse.apply(arguments), function (content) {
  3649. reverse.apply(cash(content).slice()).insertAfter(_this6);
  3650. });
  3651. return this;
  3652. }; // @require core/cash.js
  3653. // @require collection/each.js
  3654. fn.insertBefore = function (selector) {
  3655. var _this7 = this;
  3656. cash(selector).each(function (index, ele) {
  3657. var parent = ele.parentNode;
  3658. _this7.each(function (i, e) {
  3659. parent.insertBefore(!index ? e : e.cloneNode(true), ele);
  3660. });
  3661. });
  3662. return this;
  3663. }; // @require core/cash.js
  3664. // @require core/each.js
  3665. // @require ./insert_before.js
  3666. fn.before = function () {
  3667. var _this8 = this;
  3668. each(arguments, function (content) {
  3669. cash(content).insertBefore(_this8);
  3670. });
  3671. return this;
  3672. }; // @require core/cash.js
  3673. // @require core/each.js
  3674. // @require ./helpers/insert_content.js
  3675. fn.prepend = function () {
  3676. var _this9 = this;
  3677. each(arguments, function (content) {
  3678. insertContent(_this9, content, true);
  3679. });
  3680. return this;
  3681. }; // @require core/cash.js
  3682. // @require core/variables.js
  3683. // @require collection/slice.js
  3684. // @require ./helpers/insert_content.js
  3685. fn.prependTo = function (parent) {
  3686. insertContent(cash(parent), reverse.apply(this.slice()), true);
  3687. return this;
  3688. }; // @require core/cash.js
  3689. // @require events/off.js
  3690. // @require ./detach.js
  3691. fn.remove = function () {
  3692. return this.detach().off();
  3693. }; // @require core/cash.js
  3694. // @require collection/each.js
  3695. // @require collection/slice.js
  3696. // @require ./after.js
  3697. // @require ./remove.js
  3698. fn.replaceWith = function (content) {
  3699. var _this10 = this;
  3700. return this.each(function (i, ele) {
  3701. var parent = ele.parentNode;
  3702. if (!parent) return;
  3703. var $eles = i ? cash(content).clone() : cash(content);
  3704. if (!$eles[0]) {
  3705. _this10.remove();
  3706. return false;
  3707. }
  3708. parent.replaceChild($eles[0], ele);
  3709. cash($eles[0]).after($eles.slice(1));
  3710. });
  3711. }; // @require core/cash.js
  3712. // @require ./replace_with.js
  3713. fn.replaceAll = function (content) {
  3714. cash(content).replaceWith(this);
  3715. return this;
  3716. }; // @require core/cash.js
  3717. // @require collection/each.js
  3718. fn.text = function (content) {
  3719. if (content === undefined) return this[0] ? this[0].textContent : '';
  3720. return this.each(function (i, ele) {
  3721. ele.textContent = content;
  3722. });
  3723. }; // @optional ./after.js
  3724. // @optional ./append.js
  3725. // @optional ./append_to.js
  3726. // @optional ./before.js
  3727. // @optional ./clone.js
  3728. // @optional ./detach.js
  3729. // @optional ./empty.js
  3730. // @optional ./html.js
  3731. // @optional ./insert_after.js
  3732. // @optional ./insert_before.js
  3733. // @optional ./prepend.js
  3734. // @optional ./prepend_to.js
  3735. // @optional ./remove.js
  3736. // @optional ./replace_all.js
  3737. // @optional ./replace_with.js
  3738. // @optional ./text.js
  3739. // @require core/cash.js
  3740. // @require core/variables.js
  3741. var docEle = doc.documentElement;
  3742. fn.offset = function () {
  3743. var ele = this[0];
  3744. if (!ele) return;
  3745. var rect = ele.getBoundingClientRect();
  3746. return {
  3747. top: rect.top + win.pageYOffset - docEle.clientTop,
  3748. left: rect.left + win.pageXOffset - docEle.clientLeft
  3749. };
  3750. }; // @require core/cash.js
  3751. fn.offsetParent = function () {
  3752. return cash(this[0] && this[0].offsetParent);
  3753. }; // @require core/cash.js
  3754. fn.position = function () {
  3755. var ele = this[0];
  3756. if (!ele) return;
  3757. return {
  3758. left: ele.offsetLeft,
  3759. top: ele.offsetTop
  3760. };
  3761. }; // @optional ./offset.js
  3762. // @optional ./offset_parent.js
  3763. // @optional ./position.js
  3764. // @require core/cash.js
  3765. // @require core/matches.js
  3766. // @require core/unique.js
  3767. // @require collection/each.js
  3768. // @require collection/filter.js
  3769. fn.children = function (selector) {
  3770. var result = [];
  3771. this.each(function (i, ele) {
  3772. push.apply(result, ele.children);
  3773. });
  3774. result = cash(unique(result));
  3775. if (!selector) return result;
  3776. return result.filter(function (i, ele) {
  3777. return matches(ele, selector);
  3778. });
  3779. }; // @require core/cash.js
  3780. // @require core/unique.js
  3781. // @require collection/each.js
  3782. fn.contents = function () {
  3783. var result = [];
  3784. this.each(function (i, ele) {
  3785. push.apply(result, ele.tagName === 'IFRAME' ? [ele.contentDocument] : ele.childNodes);
  3786. });
  3787. return cash(result.length && unique(result));
  3788. }; // @require core/cash.js
  3789. // @require core/unique.js
  3790. // @require core/find.js
  3791. // @require core/variables.js
  3792. fn.find = function (selector) {
  3793. var result = [];
  3794. for (var i = 0, l = this.length; i < l; i++) {
  3795. var found = find(selector, this[i]);
  3796. if (found.length) {
  3797. push.apply(result, found);
  3798. }
  3799. }
  3800. return cash(result.length && unique(result));
  3801. }; // @require core/cash.js
  3802. // @require core/find.js
  3803. // @require core/type_checking.js
  3804. // @require collection/filter.js
  3805. fn.has = function (selector) {
  3806. var comparator = isString(selector) ? function (i, ele) {
  3807. return !!find(selector, ele).length;
  3808. } : function (i, ele) {
  3809. return ele.contains(selector);
  3810. };
  3811. return this.filter(comparator);
  3812. }; // @require core/cash.js
  3813. // @require core/get_compare_function.js
  3814. // @require collection/each.js
  3815. fn.is = function (selector) {
  3816. if (!selector || !this[0]) return false;
  3817. var comparator = getCompareFunction(selector);
  3818. var check = false;
  3819. this.each(function (i, ele) {
  3820. check = comparator(i, ele, selector);
  3821. return !check;
  3822. });
  3823. return check;
  3824. }; // @require core/cash.js
  3825. fn.next = function () {
  3826. return cash(this[0] && this[0].nextElementSibling);
  3827. }; // @require core/cash.js
  3828. // @require core/get_compare_function.js
  3829. // @require collection/filter.js
  3830. fn.not = function (selector) {
  3831. if (!selector || !this[0]) return this;
  3832. var comparator = getCompareFunction(selector);
  3833. return this.filter(function (i, ele) {
  3834. return !comparator(i, ele, selector);
  3835. });
  3836. }; // @require core/cash.js
  3837. // @require core/unique.js
  3838. // @require collection/each.js
  3839. fn.parent = function () {
  3840. var result = [];
  3841. this.each(function (i, ele) {
  3842. if (ele && ele.parentNode) {
  3843. result.push(ele.parentNode);
  3844. }
  3845. });
  3846. return cash(unique(result));
  3847. }; // @require core/cash.js
  3848. // @require core/variables.js
  3849. // @require traversal/children.js
  3850. // @require traversal/parent.js
  3851. // @require ./get.js
  3852. //FIXME Ugly file name, is there a better option?
  3853. fn.index = function (ele) {
  3854. var child = ele ? cash(ele)[0] : this[0],
  3855. collection = ele ? this : cash(child).parent().children();
  3856. return indexOf.call(collection, child);
  3857. }; // @optional ./add.js
  3858. // @optional ./each.js
  3859. // @optional ./eq.js
  3860. // @optional ./filter.js
  3861. // @optional ./first.js
  3862. // @optional ./get.js
  3863. // @optional ./indexFn.js
  3864. // @optional ./last.js
  3865. // @optional ./map.js
  3866. // @optional ./slice.js
  3867. // @require core/cash.js
  3868. // @require collection/filter.js
  3869. // @require ./is.js
  3870. // @require ./parent.js
  3871. fn.closest = function (selector) {
  3872. if (!selector || !this[0]) return cash();
  3873. if (this.is(selector)) return this.filter(selector);
  3874. return this.parent().closest(selector);
  3875. }; // @require core/cash.js
  3876. // @require core/matches.js
  3877. // @require core/unique.js
  3878. // @require core/variables.js
  3879. // @require collection/each.js
  3880. fn.parents = function (selector) {
  3881. var result = [];
  3882. var last;
  3883. this.each(function (i, ele) {
  3884. last = ele;
  3885. while (last && last.parentNode && last !== doc.body.parentNode) {
  3886. last = last.parentNode;
  3887. if (!selector || selector && matches(last, selector)) {
  3888. result.push(last);
  3889. }
  3890. }
  3891. });
  3892. return cash(unique(result));
  3893. }; // @require core/cash.js
  3894. fn.prev = function () {
  3895. return cash(this[0] && this[0].previousElementSibling);
  3896. }; // @require core/cash.js
  3897. // @require collection/filter.js
  3898. // @require ./children.js
  3899. // @require ./parent.js
  3900. fn.siblings = function () {
  3901. var ele = this[0];
  3902. return this.parent().children().filter(function (i, child) {
  3903. return child !== ele;
  3904. });
  3905. }; // @optional ./children.js
  3906. // @optional ./closest.js
  3907. // @optional ./contents.js
  3908. // @optional ./find.js
  3909. // @optional ./has.js
  3910. // @optional ./is.js
  3911. // @optional ./next.js
  3912. // @optional ./not.js
  3913. // @optional ./parent.js
  3914. // @optional ./parents.js
  3915. // @optional ./prev.js
  3916. // @optional ./siblings.js
  3917. // @optional attributes/index.js
  3918. // @optional collection/index.js
  3919. // @optional css/index.js
  3920. // @optional data/index.js
  3921. // @optional dimensions/index.js
  3922. // @optional events/index.js
  3923. // @optional forms/index.js
  3924. // @optional manipulation/index.js
  3925. // @optional offset/index.js
  3926. // @optional traversal/index.js
  3927. // @require core/index.js
  3928. /* harmony default export */ __webpack_exports__["default"] = (cash);
  3929. /***/ }),
  3930. /***/ "./node_modules/codemirror-formatting/formatting.js":
  3931. /*!**********************************************************!*\
  3932. !*** ./node_modules/codemirror-formatting/formatting.js ***!
  3933. \**********************************************************/
  3934. /*! no static exports found */
  3935. /***/ (function(module, exports, __webpack_require__) {
  3936. (function(mod) {
  3937. if (true) // CommonJS
  3938. mod(__webpack_require__(/*! codemirror/lib/codemirror */ "./node_modules/codemirror/lib/codemirror.js"));
  3939. else {}
  3940. })(function(CodeMirror) {
  3941. CodeMirror.extendMode("css", {
  3942. commentStart: "/*",
  3943. commentEnd: "*/",
  3944. newlineAfterToken: function(_type, content) {
  3945. return /^[;{}]$/.test(content);
  3946. }
  3947. });
  3948. CodeMirror.extendMode("javascript", {
  3949. commentStart: "/*",
  3950. commentEnd: "*/",
  3951. // FIXME semicolons inside of for
  3952. newlineAfterToken: function(_type, content, textAfter, state) {
  3953. if (this.jsonMode) {
  3954. return /^[\[,{]$/.test(content) || /^}/.test(textAfter);
  3955. } else {
  3956. if (content == ";" && state.lexical && state.lexical.type == ")") return false;
  3957. return /^[;{}]$/.test(content) && !/^;/.test(textAfter);
  3958. }
  3959. }
  3960. });
  3961. var inlineElements = /^(a|abbr|acronym|area|base|bdo|big|br|button|caption|cite|code|col|colgroup|dd|del|dfn|em|frame|hr|iframe|img|input|ins|kbd|label|legend|link|map|object|optgroup|option|param|q|samp|script|select|small|span|strong|sub|sup|textarea|tt|var)$/;
  3962. CodeMirror.extendMode("xml", {
  3963. commentStart: "<!--",
  3964. commentEnd: "-->",
  3965. newlineAfterToken: function(type, content, textAfter, state) {
  3966. var inline = false;
  3967. if (this.configuration == "html")
  3968. inline = state.context ? inlineElements.test(state.context.tagName) : false;
  3969. return !inline && ((type == "tag" && />$/.test(content) && state.context) ||
  3970. /^</.test(textAfter));
  3971. }
  3972. });
  3973. // Comment/uncomment the specified range
  3974. CodeMirror.defineExtension("commentRange", function (isComment, from, to) {
  3975. var cm = this, curMode = CodeMirror.innerMode(cm.getMode(), cm.getTokenAt(from).state).mode;
  3976. cm.operation(function() {
  3977. if (isComment) { // Comment range
  3978. cm.replaceRange(curMode.commentEnd, to);
  3979. cm.replaceRange(curMode.commentStart, from);
  3980. if (from.line == to.line && from.ch == to.ch) // An empty comment inserted - put cursor inside
  3981. cm.setCursor(from.line, from.ch + curMode.commentStart.length);
  3982. } else { // Uncomment range
  3983. var selText = cm.getRange(from, to);
  3984. var startIndex = selText.indexOf(curMode.commentStart);
  3985. var endIndex = selText.lastIndexOf(curMode.commentEnd);
  3986. if (startIndex > -1 && endIndex > -1 && endIndex > startIndex) {
  3987. // Take string till comment start
  3988. selText = selText.substr(0, startIndex) +
  3989. // From comment start till comment end
  3990. selText.substring(startIndex + curMode.commentStart.length, endIndex) +
  3991. // From comment end till string end
  3992. selText.substr(endIndex + curMode.commentEnd.length);
  3993. }
  3994. cm.replaceRange(selText, from, to);
  3995. }
  3996. });
  3997. });
  3998. // Applies automatic mode-aware indentation to the specified range
  3999. CodeMirror.defineExtension("autoIndentRange", function (from, to) {
  4000. var cmInstance = this;
  4001. this.operation(function () {
  4002. for (var i = from.line; i <= to.line; i++) {
  4003. cmInstance.indentLine(i, "smart");
  4004. }
  4005. });
  4006. });
  4007. // Applies automatic formatting to the specified range
  4008. CodeMirror.defineExtension("autoFormatRange", function (from, to) {
  4009. var cm = this;
  4010. var outer = cm.getMode(), text = cm.getRange(from, to).split("\n");
  4011. var state = CodeMirror.copyState(outer, cm.getTokenAt(from).state);
  4012. var tabSize = cm.getOption("tabSize");
  4013. var out = "", lines = 0, atSol = from.ch === 0;
  4014. function newline() {
  4015. out += "\n";
  4016. atSol = true;
  4017. ++lines;
  4018. }
  4019. for (var i = 0; i < text.length; ++i) {
  4020. var stream = new CodeMirror.StringStream(text[i], tabSize);
  4021. while (!stream.eol()) {
  4022. var inner = CodeMirror.innerMode(outer, state);
  4023. var style = outer.token(stream, state), cur = stream.current();
  4024. stream.start = stream.pos;
  4025. if (!atSol || /\S/.test(cur)) {
  4026. out += cur;
  4027. atSol = false;
  4028. }
  4029. if (!atSol && inner.mode.newlineAfterToken &&
  4030. inner.mode.newlineAfterToken(style, cur, stream.string.slice(stream.pos) || text[i+1] || "", inner.state))
  4031. newline();
  4032. }
  4033. if (!stream.pos && outer.blankLine) outer.blankLine(state);
  4034. if (!atSol && i < text.length - 1) newline();
  4035. }
  4036. cm.operation(function () {
  4037. cm.replaceRange(out, from, to);
  4038. for (var cur = from.line + 1, end = from.line + lines; cur <= end; ++cur)
  4039. cm.indentLine(cur, "smart");
  4040. cm.setSelection(from, cm.getCursor(false));
  4041. });
  4042. });
  4043. });
  4044. /***/ }),
  4045. /***/ "./node_modules/codemirror/lib/codemirror.js":
  4046. /*!***************************************************!*\
  4047. !*** ./node_modules/codemirror/lib/codemirror.js ***!
  4048. \***************************************************/
  4049. /*! no static exports found */
  4050. /***/ (function(module, exports, __webpack_require__) {
  4051. // CodeMirror, copyright (c) by Marijn Haverbeke and others
  4052. // Distributed under an MIT license: https://codemirror.net/LICENSE
  4053. // This is CodeMirror (https://codemirror.net), a code editor
  4054. // implemented in JavaScript on top of the browser's DOM.
  4055. //
  4056. // You can find some technical background for some of the code below
  4057. // at http://marijnhaverbeke.nl/blog/#cm-internals .
  4058. (function (global, factory) {
  4059. true ? module.exports = factory() :
  4060. undefined;
  4061. }(this, (function () { 'use strict';
  4062. // Kludges for bugs and behavior differences that can't be feature
  4063. // detected are enabled based on userAgent etc sniffing.
  4064. var userAgent = navigator.userAgent;
  4065. var platform = navigator.platform;
  4066. var gecko = /gecko\/\d/i.test(userAgent);
  4067. var ie_upto10 = /MSIE \d/.test(userAgent);
  4068. var ie_11up = /Trident\/(?:[7-9]|\d{2,})\..*rv:(\d+)/.exec(userAgent);
  4069. var edge = /Edge\/(\d+)/.exec(userAgent);
  4070. var ie = ie_upto10 || ie_11up || edge;
  4071. var ie_version = ie && (ie_upto10 ? document.documentMode || 6 : +(edge || ie_11up)[1]);
  4072. var webkit = !edge && /WebKit\//.test(userAgent);
  4073. var qtwebkit = webkit && /Qt\/\d+\.\d+/.test(userAgent);
  4074. var chrome = !edge && /Chrome\//.test(userAgent);
  4075. var presto = /Opera\//.test(userAgent);
  4076. var safari = /Apple Computer/.test(navigator.vendor);
  4077. var mac_geMountainLion = /Mac OS X 1\d\D([8-9]|\d\d)\D/.test(userAgent);
  4078. var phantom = /PhantomJS/.test(userAgent);
  4079. var ios = !edge && /AppleWebKit/.test(userAgent) && /Mobile\/\w+/.test(userAgent);
  4080. var android = /Android/.test(userAgent);
  4081. // This is woefully incomplete. Suggestions for alternative methods welcome.
  4082. var mobile = ios || android || /webOS|BlackBerry|Opera Mini|Opera Mobi|IEMobile/i.test(userAgent);
  4083. var mac = ios || /Mac/.test(platform);
  4084. var chromeOS = /\bCrOS\b/.test(userAgent);
  4085. var windows = /win/i.test(platform);
  4086. var presto_version = presto && userAgent.match(/Version\/(\d*\.\d*)/);
  4087. if (presto_version) { presto_version = Number(presto_version[1]); }
  4088. if (presto_version && presto_version >= 15) { presto = false; webkit = true; }
  4089. // Some browsers use the wrong event properties to signal cmd/ctrl on OS X
  4090. var flipCtrlCmd = mac && (qtwebkit || presto && (presto_version == null || presto_version < 12.11));
  4091. var captureRightClick = gecko || (ie && ie_version >= 9);
  4092. function classTest(cls) { return new RegExp("(^|\\s)" + cls + "(?:$|\\s)\\s*") }
  4093. var rmClass = function(node, cls) {
  4094. var current = node.className;
  4095. var match = classTest(cls).exec(current);
  4096. if (match) {
  4097. var after = current.slice(match.index + match[0].length);
  4098. node.className = current.slice(0, match.index) + (after ? match[1] + after : "");
  4099. }
  4100. };
  4101. function removeChildren(e) {
  4102. for (var count = e.childNodes.length; count > 0; --count)
  4103. { e.removeChild(e.firstChild); }
  4104. return e
  4105. }
  4106. function removeChildrenAndAdd(parent, e) {
  4107. return removeChildren(parent).appendChild(e)
  4108. }
  4109. function elt(tag, content, className, style) {
  4110. var e = document.createElement(tag);
  4111. if (className) { e.className = className; }
  4112. if (style) { e.style.cssText = style; }
  4113. if (typeof content == "string") { e.appendChild(document.createTextNode(content)); }
  4114. else if (content) { for (var i = 0; i < content.length; ++i) { e.appendChild(content[i]); } }
  4115. return e
  4116. }
  4117. // wrapper for elt, which removes the elt from the accessibility tree
  4118. function eltP(tag, content, className, style) {
  4119. var e = elt(tag, content, className, style);
  4120. e.setAttribute("role", "presentation");
  4121. return e
  4122. }
  4123. var range;
  4124. if (document.createRange) { range = function(node, start, end, endNode) {
  4125. var r = document.createRange();
  4126. r.setEnd(endNode || node, end);
  4127. r.setStart(node, start);
  4128. return r
  4129. }; }
  4130. else { range = function(node, start, end) {
  4131. var r = document.body.createTextRange();
  4132. try { r.moveToElementText(node.parentNode); }
  4133. catch(e) { return r }
  4134. r.collapse(true);
  4135. r.moveEnd("character", end);
  4136. r.moveStart("character", start);
  4137. return r
  4138. }; }
  4139. function contains(parent, child) {
  4140. if (child.nodeType == 3) // Android browser always returns false when child is a textnode
  4141. { child = child.parentNode; }
  4142. if (parent.contains)
  4143. { return parent.contains(child) }
  4144. do {
  4145. if (child.nodeType == 11) { child = child.host; }
  4146. if (child == parent) { return true }
  4147. } while (child = child.parentNode)
  4148. }
  4149. function activeElt() {
  4150. // IE and Edge may throw an "Unspecified Error" when accessing document.activeElement.
  4151. // IE < 10 will throw when accessed while the page is loading or in an iframe.
  4152. // IE > 9 and Edge will throw when accessed in an iframe if document.body is unavailable.
  4153. var activeElement;
  4154. try {
  4155. activeElement = document.activeElement;
  4156. } catch(e) {
  4157. activeElement = document.body || null;
  4158. }
  4159. while (activeElement && activeElement.shadowRoot && activeElement.shadowRoot.activeElement)
  4160. { activeElement = activeElement.shadowRoot.activeElement; }
  4161. return activeElement
  4162. }
  4163. function addClass(node, cls) {
  4164. var current = node.className;
  4165. if (!classTest(cls).test(current)) { node.className += (current ? " " : "") + cls; }
  4166. }
  4167. function joinClasses(a, b) {
  4168. var as = a.split(" ");
  4169. for (var i = 0; i < as.length; i++)
  4170. { if (as[i] && !classTest(as[i]).test(b)) { b += " " + as[i]; } }
  4171. return b
  4172. }
  4173. var selectInput = function(node) { node.select(); };
  4174. if (ios) // Mobile Safari apparently has a bug where select() is broken.
  4175. { selectInput = function(node) { node.selectionStart = 0; node.selectionEnd = node.value.length; }; }
  4176. else if (ie) // Suppress mysterious IE10 errors
  4177. { selectInput = function(node) { try { node.select(); } catch(_e) {} }; }
  4178. function bind(f) {
  4179. var args = Array.prototype.slice.call(arguments, 1);
  4180. return function(){return f.apply(null, args)}
  4181. }
  4182. function copyObj(obj, target, overwrite) {
  4183. if (!target) { target = {}; }
  4184. for (var prop in obj)
  4185. { if (obj.hasOwnProperty(prop) && (overwrite !== false || !target.hasOwnProperty(prop)))
  4186. { target[prop] = obj[prop]; } }
  4187. return target
  4188. }
  4189. // Counts the column offset in a string, taking tabs into account.
  4190. // Used mostly to find indentation.
  4191. function countColumn(string, end, tabSize, startIndex, startValue) {
  4192. if (end == null) {
  4193. end = string.search(/[^\s\u00a0]/);
  4194. if (end == -1) { end = string.length; }
  4195. }
  4196. for (var i = startIndex || 0, n = startValue || 0;;) {
  4197. var nextTab = string.indexOf("\t", i);
  4198. if (nextTab < 0 || nextTab >= end)
  4199. { return n + (end - i) }
  4200. n += nextTab - i;
  4201. n += tabSize - (n % tabSize);
  4202. i = nextTab + 1;
  4203. }
  4204. }
  4205. var Delayed = function() {
  4206. this.id = null;
  4207. this.f = null;
  4208. this.time = 0;
  4209. this.handler = bind(this.onTimeout, this);
  4210. };
  4211. Delayed.prototype.onTimeout = function (self) {
  4212. self.id = 0;
  4213. if (self.time <= +new Date) {
  4214. self.f();
  4215. } else {
  4216. setTimeout(self.handler, self.time - +new Date);
  4217. }
  4218. };
  4219. Delayed.prototype.set = function (ms, f) {
  4220. this.f = f;
  4221. var time = +new Date + ms;
  4222. if (!this.id || time < this.time) {
  4223. clearTimeout(this.id);
  4224. this.id = setTimeout(this.handler, ms);
  4225. this.time = time;
  4226. }
  4227. };
  4228. function indexOf(array, elt) {
  4229. for (var i = 0; i < array.length; ++i)
  4230. { if (array[i] == elt) { return i } }
  4231. return -1
  4232. }
  4233. // Number of pixels added to scroller and sizer to hide scrollbar
  4234. var scrollerGap = 30;
  4235. // Returned or thrown by various protocols to signal 'I'm not
  4236. // handling this'.
  4237. var Pass = {toString: function(){return "CodeMirror.Pass"}};
  4238. // Reused option objects for setSelection & friends
  4239. var sel_dontScroll = {scroll: false}, sel_mouse = {origin: "*mouse"}, sel_move = {origin: "+move"};
  4240. // The inverse of countColumn -- find the offset that corresponds to
  4241. // a particular column.
  4242. function findColumn(string, goal, tabSize) {
  4243. for (var pos = 0, col = 0;;) {
  4244. var nextTab = string.indexOf("\t", pos);
  4245. if (nextTab == -1) { nextTab = string.length; }
  4246. var skipped = nextTab - pos;
  4247. if (nextTab == string.length || col + skipped >= goal)
  4248. { return pos + Math.min(skipped, goal - col) }
  4249. col += nextTab - pos;
  4250. col += tabSize - (col % tabSize);
  4251. pos = nextTab + 1;
  4252. if (col >= goal) { return pos }
  4253. }
  4254. }
  4255. var spaceStrs = [""];
  4256. function spaceStr(n) {
  4257. while (spaceStrs.length <= n)
  4258. { spaceStrs.push(lst(spaceStrs) + " "); }
  4259. return spaceStrs[n]
  4260. }
  4261. function lst(arr) { return arr[arr.length-1] }
  4262. function map(array, f) {
  4263. var out = [];
  4264. for (var i = 0; i < array.length; i++) { out[i] = f(array[i], i); }
  4265. return out
  4266. }
  4267. function insertSorted(array, value, score) {
  4268. var pos = 0, priority = score(value);
  4269. while (pos < array.length && score(array[pos]) <= priority) { pos++; }
  4270. array.splice(pos, 0, value);
  4271. }
  4272. function nothing() {}
  4273. function createObj(base, props) {
  4274. var inst;
  4275. if (Object.create) {
  4276. inst = Object.create(base);
  4277. } else {
  4278. nothing.prototype = base;
  4279. inst = new nothing();
  4280. }
  4281. if (props) { copyObj(props, inst); }
  4282. return inst
  4283. }
  4284. var nonASCIISingleCaseWordChar = /[\u00df\u0587\u0590-\u05f4\u0600-\u06ff\u3040-\u309f\u30a0-\u30ff\u3400-\u4db5\u4e00-\u9fcc\uac00-\ud7af]/;
  4285. function isWordCharBasic(ch) {
  4286. return /\w/.test(ch) || ch > "\x80" &&
  4287. (ch.toUpperCase() != ch.toLowerCase() || nonASCIISingleCaseWordChar.test(ch))
  4288. }
  4289. function isWordChar(ch, helper) {
  4290. if (!helper) { return isWordCharBasic(ch) }
  4291. if (helper.source.indexOf("\\w") > -1 && isWordCharBasic(ch)) { return true }
  4292. return helper.test(ch)
  4293. }
  4294. function isEmpty(obj) {
  4295. for (var n in obj) { if (obj.hasOwnProperty(n) && obj[n]) { return false } }
  4296. return true
  4297. }
  4298. // Extending unicode characters. A series of a non-extending char +
  4299. // any number of extending chars is treated as a single unit as far
  4300. // as editing and measuring is concerned. This is not fully correct,
  4301. // since some scripts/fonts/browsers also treat other configurations
  4302. // of code points as a group.
  4303. var extendingChars = /[\u0300-\u036f\u0483-\u0489\u0591-\u05bd\u05bf\u05c1\u05c2\u05c4\u05c5\u05c7\u0610-\u061a\u064b-\u065e\u0670\u06d6-\u06dc\u06de-\u06e4\u06e7\u06e8\u06ea-\u06ed\u0711\u0730-\u074a\u07a6-\u07b0\u07eb-\u07f3\u0816-\u0819\u081b-\u0823\u0825-\u0827\u0829-\u082d\u0900-\u0902\u093c\u0941-\u0948\u094d\u0951-\u0955\u0962\u0963\u0981\u09bc\u09be\u09c1-\u09c4\u09cd\u09d7\u09e2\u09e3\u0a01\u0a02\u0a3c\u0a41\u0a42\u0a47\u0a48\u0a4b-\u0a4d\u0a51\u0a70\u0a71\u0a75\u0a81\u0a82\u0abc\u0ac1-\u0ac5\u0ac7\u0ac8\u0acd\u0ae2\u0ae3\u0b01\u0b3c\u0b3e\u0b3f\u0b41-\u0b44\u0b4d\u0b56\u0b57\u0b62\u0b63\u0b82\u0bbe\u0bc0\u0bcd\u0bd7\u0c3e-\u0c40\u0c46-\u0c48\u0c4a-\u0c4d\u0c55\u0c56\u0c62\u0c63\u0cbc\u0cbf\u0cc2\u0cc6\u0ccc\u0ccd\u0cd5\u0cd6\u0ce2\u0ce3\u0d3e\u0d41-\u0d44\u0d4d\u0d57\u0d62\u0d63\u0dca\u0dcf\u0dd2-\u0dd4\u0dd6\u0ddf\u0e31\u0e34-\u0e3a\u0e47-\u0e4e\u0eb1\u0eb4-\u0eb9\u0ebb\u0ebc\u0ec8-\u0ecd\u0f18\u0f19\u0f35\u0f37\u0f39\u0f71-\u0f7e\u0f80-\u0f84\u0f86\u0f87\u0f90-\u0f97\u0f99-\u0fbc\u0fc6\u102d-\u1030\u1032-\u1037\u1039\u103a\u103d\u103e\u1058\u1059\u105e-\u1060\u1071-\u1074\u1082\u1085\u1086\u108d\u109d\u135f\u1712-\u1714\u1732-\u1734\u1752\u1753\u1772\u1773\u17b7-\u17bd\u17c6\u17c9-\u17d3\u17dd\u180b-\u180d\u18a9\u1920-\u1922\u1927\u1928\u1932\u1939-\u193b\u1a17\u1a18\u1a56\u1a58-\u1a5e\u1a60\u1a62\u1a65-\u1a6c\u1a73-\u1a7c\u1a7f\u1b00-\u1b03\u1b34\u1b36-\u1b3a\u1b3c\u1b42\u1b6b-\u1b73\u1b80\u1b81\u1ba2-\u1ba5\u1ba8\u1ba9\u1c2c-\u1c33\u1c36\u1c37\u1cd0-\u1cd2\u1cd4-\u1ce0\u1ce2-\u1ce8\u1ced\u1dc0-\u1de6\u1dfd-\u1dff\u200c\u200d\u20d0-\u20f0\u2cef-\u2cf1\u2de0-\u2dff\u302a-\u302f\u3099\u309a\ua66f-\ua672\ua67c\ua67d\ua6f0\ua6f1\ua802\ua806\ua80b\ua825\ua826\ua8c4\ua8e0-\ua8f1\ua926-\ua92d\ua947-\ua951\ua980-\ua982\ua9b3\ua9b6-\ua9b9\ua9bc\uaa29-\uaa2e\uaa31\uaa32\uaa35\uaa36\uaa43\uaa4c\uaab0\uaab2-\uaab4\uaab7\uaab8\uaabe\uaabf\uaac1\uabe5\uabe8\uabed\udc00-\udfff\ufb1e\ufe00-\ufe0f\ufe20-\ufe26\uff9e\uff9f]/;
  4304. function isExtendingChar(ch) { return ch.charCodeAt(0) >= 768 && extendingChars.test(ch) }
  4305. // Returns a number from the range [`0`; `str.length`] unless `pos` is outside that range.
  4306. function skipExtendingChars(str, pos, dir) {
  4307. while ((dir < 0 ? pos > 0 : pos < str.length) && isExtendingChar(str.charAt(pos))) { pos += dir; }
  4308. return pos
  4309. }
  4310. // Returns the value from the range [`from`; `to`] that satisfies
  4311. // `pred` and is closest to `from`. Assumes that at least `to`
  4312. // satisfies `pred`. Supports `from` being greater than `to`.
  4313. function findFirst(pred, from, to) {
  4314. // At any point we are certain `to` satisfies `pred`, don't know
  4315. // whether `from` does.
  4316. var dir = from > to ? -1 : 1;
  4317. for (;;) {
  4318. if (from == to) { return from }
  4319. var midF = (from + to) / 2, mid = dir < 0 ? Math.ceil(midF) : Math.floor(midF);
  4320. if (mid == from) { return pred(mid) ? from : to }
  4321. if (pred(mid)) { to = mid; }
  4322. else { from = mid + dir; }
  4323. }
  4324. }
  4325. // BIDI HELPERS
  4326. function iterateBidiSections(order, from, to, f) {
  4327. if (!order) { return f(from, to, "ltr", 0) }
  4328. var found = false;
  4329. for (var i = 0; i < order.length; ++i) {
  4330. var part = order[i];
  4331. if (part.from < to && part.to > from || from == to && part.to == from) {
  4332. f(Math.max(part.from, from), Math.min(part.to, to), part.level == 1 ? "rtl" : "ltr", i);
  4333. found = true;
  4334. }
  4335. }
  4336. if (!found) { f(from, to, "ltr"); }
  4337. }
  4338. var bidiOther = null;
  4339. function getBidiPartAt(order, ch, sticky) {
  4340. var found;
  4341. bidiOther = null;
  4342. for (var i = 0; i < order.length; ++i) {
  4343. var cur = order[i];
  4344. if (cur.from < ch && cur.to > ch) { return i }
  4345. if (cur.to == ch) {
  4346. if (cur.from != cur.to && sticky == "before") { found = i; }
  4347. else { bidiOther = i; }
  4348. }
  4349. if (cur.from == ch) {
  4350. if (cur.from != cur.to && sticky != "before") { found = i; }
  4351. else { bidiOther = i; }
  4352. }
  4353. }
  4354. return found != null ? found : bidiOther
  4355. }
  4356. // Bidirectional ordering algorithm
  4357. // See http://unicode.org/reports/tr9/tr9-13.html for the algorithm
  4358. // that this (partially) implements.
  4359. // One-char codes used for character types:
  4360. // L (L): Left-to-Right
  4361. // R (R): Right-to-Left
  4362. // r (AL): Right-to-Left Arabic
  4363. // 1 (EN): European Number
  4364. // + (ES): European Number Separator
  4365. // % (ET): European Number Terminator
  4366. // n (AN): Arabic Number
  4367. // , (CS): Common Number Separator
  4368. // m (NSM): Non-Spacing Mark
  4369. // b (BN): Boundary Neutral
  4370. // s (B): Paragraph Separator
  4371. // t (S): Segment Separator
  4372. // w (WS): Whitespace
  4373. // N (ON): Other Neutrals
  4374. // Returns null if characters are ordered as they appear
  4375. // (left-to-right), or an array of sections ({from, to, level}
  4376. // objects) in the order in which they occur visually.
  4377. var bidiOrdering = (function() {
  4378. // Character types for codepoints 0 to 0xff
  4379. var lowTypes = "bbbbbbbbbtstwsbbbbbbbbbbbbbbssstwNN%%%NNNNNN,N,N1111111111NNNNNNNLLLLLLLLLLLLLLLLLLLLLLLLLLNNNNNNLLLLLLLLLLLLLLLLLLLLLLLLLLNNNNbbbbbbsbbbbbbbbbbbbbbbbbbbbbbbbbb,N%%%%NNNNLNNNNN%%11NLNNN1LNNNNNLLLLLLLLLLLLLLLLLLLLLLLNLLLLLLLLLLLLLLLLLLLLLLLLLLLLLLLN";
  4380. // Character types for codepoints 0x600 to 0x6f9
  4381. var arabicTypes = "nnnnnnNNr%%r,rNNmmmmmmmmmmmrrrrrrrrrrrrrrrrrrrrrrrrrrrrrrrrrrrrrrrrrrrrrrrrmmmmmmmmmmmmmmmmmmmmmnnnnnnnnnn%nnrrrmrrrrrrrrrrrrrrrrrrrrrrrrrrrrrrrrrrrrrrrrrrrrrrrrrrrrrrrrrrrrrrrrrrrrrrrrrrrrrrrrrrrrrrrrrrrrrrrrrrrrrmmmmmmmnNmmmmmmrrmmNmmmmrr1111111111";
  4382. function charType(code) {
  4383. if (code <= 0xf7) { return lowTypes.charAt(code) }
  4384. else if (0x590 <= code && code <= 0x5f4) { return "R" }
  4385. else if (0x600 <= code && code <= 0x6f9) { return arabicTypes.charAt(code - 0x600) }
  4386. else if (0x6ee <= code && code <= 0x8ac) { return "r" }
  4387. else if (0x2000 <= code && code <= 0x200b) { return "w" }
  4388. else if (code == 0x200c) { return "b" }
  4389. else { return "L" }
  4390. }
  4391. var bidiRE = /[\u0590-\u05f4\u0600-\u06ff\u0700-\u08ac]/;
  4392. var isNeutral = /[stwN]/, isStrong = /[LRr]/, countsAsLeft = /[Lb1n]/, countsAsNum = /[1n]/;
  4393. function BidiSpan(level, from, to) {
  4394. this.level = level;
  4395. this.from = from; this.to = to;
  4396. }
  4397. return function(str, direction) {
  4398. var outerType = direction == "ltr" ? "L" : "R";
  4399. if (str.length == 0 || direction == "ltr" && !bidiRE.test(str)) { return false }
  4400. var len = str.length, types = [];
  4401. for (var i = 0; i < len; ++i)
  4402. { types.push(charType(str.charCodeAt(i))); }
  4403. // W1. Examine each non-spacing mark (NSM) in the level run, and
  4404. // change the type of the NSM to the type of the previous
  4405. // character. If the NSM is at the start of the level run, it will
  4406. // get the type of sor.
  4407. for (var i$1 = 0, prev = outerType; i$1 < len; ++i$1) {
  4408. var type = types[i$1];
  4409. if (type == "m") { types[i$1] = prev; }
  4410. else { prev = type; }
  4411. }
  4412. // W2. Search backwards from each instance of a European number
  4413. // until the first strong type (R, L, AL, or sor) is found. If an
  4414. // AL is found, change the type of the European number to Arabic
  4415. // number.
  4416. // W3. Change all ALs to R.
  4417. for (var i$2 = 0, cur = outerType; i$2 < len; ++i$2) {
  4418. var type$1 = types[i$2];
  4419. if (type$1 == "1" && cur == "r") { types[i$2] = "n"; }
  4420. else if (isStrong.test(type$1)) { cur = type$1; if (type$1 == "r") { types[i$2] = "R"; } }
  4421. }
  4422. // W4. A single European separator between two European numbers
  4423. // changes to a European number. A single common separator between
  4424. // two numbers of the same type changes to that type.
  4425. for (var i$3 = 1, prev$1 = types[0]; i$3 < len - 1; ++i$3) {
  4426. var type$2 = types[i$3];
  4427. if (type$2 == "+" && prev$1 == "1" && types[i$3+1] == "1") { types[i$3] = "1"; }
  4428. else if (type$2 == "," && prev$1 == types[i$3+1] &&
  4429. (prev$1 == "1" || prev$1 == "n")) { types[i$3] = prev$1; }
  4430. prev$1 = type$2;
  4431. }
  4432. // W5. A sequence of European terminators adjacent to European
  4433. // numbers changes to all European numbers.
  4434. // W6. Otherwise, separators and terminators change to Other
  4435. // Neutral.
  4436. for (var i$4 = 0; i$4 < len; ++i$4) {
  4437. var type$3 = types[i$4];
  4438. if (type$3 == ",") { types[i$4] = "N"; }
  4439. else if (type$3 == "%") {
  4440. var end = (void 0);
  4441. for (end = i$4 + 1; end < len && types[end] == "%"; ++end) {}
  4442. var replace = (i$4 && types[i$4-1] == "!") || (end < len && types[end] == "1") ? "1" : "N";
  4443. for (var j = i$4; j < end; ++j) { types[j] = replace; }
  4444. i$4 = end - 1;
  4445. }
  4446. }
  4447. // W7. Search backwards from each instance of a European number
  4448. // until the first strong type (R, L, or sor) is found. If an L is
  4449. // found, then change the type of the European number to L.
  4450. for (var i$5 = 0, cur$1 = outerType; i$5 < len; ++i$5) {
  4451. var type$4 = types[i$5];
  4452. if (cur$1 == "L" && type$4 == "1") { types[i$5] = "L"; }
  4453. else if (isStrong.test(type$4)) { cur$1 = type$4; }
  4454. }
  4455. // N1. A sequence of neutrals takes the direction of the
  4456. // surrounding strong text if the text on both sides has the same
  4457. // direction. European and Arabic numbers act as if they were R in
  4458. // terms of their influence on neutrals. Start-of-level-run (sor)
  4459. // and end-of-level-run (eor) are used at level run boundaries.
  4460. // N2. Any remaining neutrals take the embedding direction.
  4461. for (var i$6 = 0; i$6 < len; ++i$6) {
  4462. if (isNeutral.test(types[i$6])) {
  4463. var end$1 = (void 0);
  4464. for (end$1 = i$6 + 1; end$1 < len && isNeutral.test(types[end$1]); ++end$1) {}
  4465. var before = (i$6 ? types[i$6-1] : outerType) == "L";
  4466. var after = (end$1 < len ? types[end$1] : outerType) == "L";
  4467. var replace$1 = before == after ? (before ? "L" : "R") : outerType;
  4468. for (var j$1 = i$6; j$1 < end$1; ++j$1) { types[j$1] = replace$1; }
  4469. i$6 = end$1 - 1;
  4470. }
  4471. }
  4472. // Here we depart from the documented algorithm, in order to avoid
  4473. // building up an actual levels array. Since there are only three
  4474. // levels (0, 1, 2) in an implementation that doesn't take
  4475. // explicit embedding into account, we can build up the order on
  4476. // the fly, without following the level-based algorithm.
  4477. var order = [], m;
  4478. for (var i$7 = 0; i$7 < len;) {
  4479. if (countsAsLeft.test(types[i$7])) {
  4480. var start = i$7;
  4481. for (++i$7; i$7 < len && countsAsLeft.test(types[i$7]); ++i$7) {}
  4482. order.push(new BidiSpan(0, start, i$7));
  4483. } else {
  4484. var pos = i$7, at = order.length;
  4485. for (++i$7; i$7 < len && types[i$7] != "L"; ++i$7) {}
  4486. for (var j$2 = pos; j$2 < i$7;) {
  4487. if (countsAsNum.test(types[j$2])) {
  4488. if (pos < j$2) { order.splice(at, 0, new BidiSpan(1, pos, j$2)); }
  4489. var nstart = j$2;
  4490. for (++j$2; j$2 < i$7 && countsAsNum.test(types[j$2]); ++j$2) {}
  4491. order.splice(at, 0, new BidiSpan(2, nstart, j$2));
  4492. pos = j$2;
  4493. } else { ++j$2; }
  4494. }
  4495. if (pos < i$7) { order.splice(at, 0, new BidiSpan(1, pos, i$7)); }
  4496. }
  4497. }
  4498. if (direction == "ltr") {
  4499. if (order[0].level == 1 && (m = str.match(/^\s+/))) {
  4500. order[0].from = m[0].length;
  4501. order.unshift(new BidiSpan(0, 0, m[0].length));
  4502. }
  4503. if (lst(order).level == 1 && (m = str.match(/\s+$/))) {
  4504. lst(order).to -= m[0].length;
  4505. order.push(new BidiSpan(0, len - m[0].length, len));
  4506. }
  4507. }
  4508. return direction == "rtl" ? order.reverse() : order
  4509. }
  4510. })();
  4511. // Get the bidi ordering for the given line (and cache it). Returns
  4512. // false for lines that are fully left-to-right, and an array of
  4513. // BidiSpan objects otherwise.
  4514. function getOrder(line, direction) {
  4515. var order = line.order;
  4516. if (order == null) { order = line.order = bidiOrdering(line.text, direction); }
  4517. return order
  4518. }
  4519. // EVENT HANDLING
  4520. // Lightweight event framework. on/off also work on DOM nodes,
  4521. // registering native DOM handlers.
  4522. var noHandlers = [];
  4523. var on = function(emitter, type, f) {
  4524. if (emitter.addEventListener) {
  4525. emitter.addEventListener(type, f, false);
  4526. } else if (emitter.attachEvent) {
  4527. emitter.attachEvent("on" + type, f);
  4528. } else {
  4529. var map$$1 = emitter._handlers || (emitter._handlers = {});
  4530. map$$1[type] = (map$$1[type] || noHandlers).concat(f);
  4531. }
  4532. };
  4533. function getHandlers(emitter, type) {
  4534. return emitter._handlers && emitter._handlers[type] || noHandlers
  4535. }
  4536. function off(emitter, type, f) {
  4537. if (emitter.removeEventListener) {
  4538. emitter.removeEventListener(type, f, false);
  4539. } else if (emitter.detachEvent) {
  4540. emitter.detachEvent("on" + type, f);
  4541. } else {
  4542. var map$$1 = emitter._handlers, arr = map$$1 && map$$1[type];
  4543. if (arr) {
  4544. var index = indexOf(arr, f);
  4545. if (index > -1)
  4546. { map$$1[type] = arr.slice(0, index).concat(arr.slice(index + 1)); }
  4547. }
  4548. }
  4549. }
  4550. function signal(emitter, type /*, values...*/) {
  4551. var handlers = getHandlers(emitter, type);
  4552. if (!handlers.length) { return }
  4553. var args = Array.prototype.slice.call(arguments, 2);
  4554. for (var i = 0; i < handlers.length; ++i) { handlers[i].apply(null, args); }
  4555. }
  4556. // The DOM events that CodeMirror handles can be overridden by
  4557. // registering a (non-DOM) handler on the editor for the event name,
  4558. // and preventDefault-ing the event in that handler.
  4559. function signalDOMEvent(cm, e, override) {
  4560. if (typeof e == "string")
  4561. { e = {type: e, preventDefault: function() { this.defaultPrevented = true; }}; }
  4562. signal(cm, override || e.type, cm, e);
  4563. return e_defaultPrevented(e) || e.codemirrorIgnore
  4564. }
  4565. function signalCursorActivity(cm) {
  4566. var arr = cm._handlers && cm._handlers.cursorActivity;
  4567. if (!arr) { return }
  4568. var set = cm.curOp.cursorActivityHandlers || (cm.curOp.cursorActivityHandlers = []);
  4569. for (var i = 0; i < arr.length; ++i) { if (indexOf(set, arr[i]) == -1)
  4570. { set.push(arr[i]); } }
  4571. }
  4572. function hasHandler(emitter, type) {
  4573. return getHandlers(emitter, type).length > 0
  4574. }
  4575. // Add on and off methods to a constructor's prototype, to make
  4576. // registering events on such objects more convenient.
  4577. function eventMixin(ctor) {
  4578. ctor.prototype.on = function(type, f) {on(this, type, f);};
  4579. ctor.prototype.off = function(type, f) {off(this, type, f);};
  4580. }
  4581. // Due to the fact that we still support jurassic IE versions, some
  4582. // compatibility wrappers are needed.
  4583. function e_preventDefault(e) {
  4584. if (e.preventDefault) { e.preventDefault(); }
  4585. else { e.returnValue = false; }
  4586. }
  4587. function e_stopPropagation(e) {
  4588. if (e.stopPropagation) { e.stopPropagation(); }
  4589. else { e.cancelBubble = true; }
  4590. }
  4591. function e_defaultPrevented(e) {
  4592. return e.defaultPrevented != null ? e.defaultPrevented : e.returnValue == false
  4593. }
  4594. function e_stop(e) {e_preventDefault(e); e_stopPropagation(e);}
  4595. function e_target(e) {return e.target || e.srcElement}
  4596. function e_button(e) {
  4597. var b = e.which;
  4598. if (b == null) {
  4599. if (e.button & 1) { b = 1; }
  4600. else if (e.button & 2) { b = 3; }
  4601. else if (e.button & 4) { b = 2; }
  4602. }
  4603. if (mac && e.ctrlKey && b == 1) { b = 3; }
  4604. return b
  4605. }
  4606. // Detect drag-and-drop
  4607. var dragAndDrop = function() {
  4608. // There is *some* kind of drag-and-drop support in IE6-8, but I
  4609. // couldn't get it to work yet.
  4610. if (ie && ie_version < 9) { return false }
  4611. var div = elt('div');
  4612. return "draggable" in div || "dragDrop" in div
  4613. }();
  4614. var zwspSupported;
  4615. function zeroWidthElement(measure) {
  4616. if (zwspSupported == null) {
  4617. var test = elt("span", "\u200b");
  4618. removeChildrenAndAdd(measure, elt("span", [test, document.createTextNode("x")]));
  4619. if (measure.firstChild.offsetHeight != 0)
  4620. { zwspSupported = test.offsetWidth <= 1 && test.offsetHeight > 2 && !(ie && ie_version < 8); }
  4621. }
  4622. var node = zwspSupported ? elt("span", "\u200b") :
  4623. elt("span", "\u00a0", null, "display: inline-block; width: 1px; margin-right: -1px");
  4624. node.setAttribute("cm-text", "");
  4625. return node
  4626. }
  4627. // Feature-detect IE's crummy client rect reporting for bidi text
  4628. var badBidiRects;
  4629. function hasBadBidiRects(measure) {
  4630. if (badBidiRects != null) { return badBidiRects }
  4631. var txt = removeChildrenAndAdd(measure, document.createTextNode("A\u062eA"));
  4632. var r0 = range(txt, 0, 1).getBoundingClientRect();
  4633. var r1 = range(txt, 1, 2).getBoundingClientRect();
  4634. removeChildren(measure);
  4635. if (!r0 || r0.left == r0.right) { return false } // Safari returns null in some cases (#2780)
  4636. return badBidiRects = (r1.right - r0.right < 3)
  4637. }
  4638. // See if "".split is the broken IE version, if so, provide an
  4639. // alternative way to split lines.
  4640. var splitLinesAuto = "\n\nb".split(/\n/).length != 3 ? function (string) {
  4641. var pos = 0, result = [], l = string.length;
  4642. while (pos <= l) {
  4643. var nl = string.indexOf("\n", pos);
  4644. if (nl == -1) { nl = string.length; }
  4645. var line = string.slice(pos, string.charAt(nl - 1) == "\r" ? nl - 1 : nl);
  4646. var rt = line.indexOf("\r");
  4647. if (rt != -1) {
  4648. result.push(line.slice(0, rt));
  4649. pos += rt + 1;
  4650. } else {
  4651. result.push(line);
  4652. pos = nl + 1;
  4653. }
  4654. }
  4655. return result
  4656. } : function (string) { return string.split(/\r\n?|\n/); };
  4657. var hasSelection = window.getSelection ? function (te) {
  4658. try { return te.selectionStart != te.selectionEnd }
  4659. catch(e) { return false }
  4660. } : function (te) {
  4661. var range$$1;
  4662. try {range$$1 = te.ownerDocument.selection.createRange();}
  4663. catch(e) {}
  4664. if (!range$$1 || range$$1.parentElement() != te) { return false }
  4665. return range$$1.compareEndPoints("StartToEnd", range$$1) != 0
  4666. };
  4667. var hasCopyEvent = (function () {
  4668. var e = elt("div");
  4669. if ("oncopy" in e) { return true }
  4670. e.setAttribute("oncopy", "return;");
  4671. return typeof e.oncopy == "function"
  4672. })();
  4673. var badZoomedRects = null;
  4674. function hasBadZoomedRects(measure) {
  4675. if (badZoomedRects != null) { return badZoomedRects }
  4676. var node = removeChildrenAndAdd(measure, elt("span", "x"));
  4677. var normal = node.getBoundingClientRect();
  4678. var fromRange = range(node, 0, 1).getBoundingClientRect();
  4679. return badZoomedRects = Math.abs(normal.left - fromRange.left) > 1
  4680. }
  4681. // Known modes, by name and by MIME
  4682. var modes = {}, mimeModes = {};
  4683. // Extra arguments are stored as the mode's dependencies, which is
  4684. // used by (legacy) mechanisms like loadmode.js to automatically
  4685. // load a mode. (Preferred mechanism is the require/define calls.)
  4686. function defineMode(name, mode) {
  4687. if (arguments.length > 2)
  4688. { mode.dependencies = Array.prototype.slice.call(arguments, 2); }
  4689. modes[name] = mode;
  4690. }
  4691. function defineMIME(mime, spec) {
  4692. mimeModes[mime] = spec;
  4693. }
  4694. // Given a MIME type, a {name, ...options} config object, or a name
  4695. // string, return a mode config object.
  4696. function resolveMode(spec) {
  4697. if (typeof spec == "string" && mimeModes.hasOwnProperty(spec)) {
  4698. spec = mimeModes[spec];
  4699. } else if (spec && typeof spec.name == "string" && mimeModes.hasOwnProperty(spec.name)) {
  4700. var found = mimeModes[spec.name];
  4701. if (typeof found == "string") { found = {name: found}; }
  4702. spec = createObj(found, spec);
  4703. spec.name = found.name;
  4704. } else if (typeof spec == "string" && /^[\w\-]+\/[\w\-]+\+xml$/.test(spec)) {
  4705. return resolveMode("application/xml")
  4706. } else if (typeof spec == "string" && /^[\w\-]+\/[\w\-]+\+json$/.test(spec)) {
  4707. return resolveMode("application/json")
  4708. }
  4709. if (typeof spec == "string") { return {name: spec} }
  4710. else { return spec || {name: "null"} }
  4711. }
  4712. // Given a mode spec (anything that resolveMode accepts), find and
  4713. // initialize an actual mode object.
  4714. function getMode(options, spec) {
  4715. spec = resolveMode(spec);
  4716. var mfactory = modes[spec.name];
  4717. if (!mfactory) { return getMode(options, "text/plain") }
  4718. var modeObj = mfactory(options, spec);
  4719. if (modeExtensions.hasOwnProperty(spec.name)) {
  4720. var exts = modeExtensions[spec.name];
  4721. for (var prop in exts) {
  4722. if (!exts.hasOwnProperty(prop)) { continue }
  4723. if (modeObj.hasOwnProperty(prop)) { modeObj["_" + prop] = modeObj[prop]; }
  4724. modeObj[prop] = exts[prop];
  4725. }
  4726. }
  4727. modeObj.name = spec.name;
  4728. if (spec.helperType) { modeObj.helperType = spec.helperType; }
  4729. if (spec.modeProps) { for (var prop$1 in spec.modeProps)
  4730. { modeObj[prop$1] = spec.modeProps[prop$1]; } }
  4731. return modeObj
  4732. }
  4733. // This can be used to attach properties to mode objects from
  4734. // outside the actual mode definition.
  4735. var modeExtensions = {};
  4736. function extendMode(mode, properties) {
  4737. var exts = modeExtensions.hasOwnProperty(mode) ? modeExtensions[mode] : (modeExtensions[mode] = {});
  4738. copyObj(properties, exts);
  4739. }
  4740. function copyState(mode, state) {
  4741. if (state === true) { return state }
  4742. if (mode.copyState) { return mode.copyState(state) }
  4743. var nstate = {};
  4744. for (var n in state) {
  4745. var val = state[n];
  4746. if (val instanceof Array) { val = val.concat([]); }
  4747. nstate[n] = val;
  4748. }
  4749. return nstate
  4750. }
  4751. // Given a mode and a state (for that mode), find the inner mode and
  4752. // state at the position that the state refers to.
  4753. function innerMode(mode, state) {
  4754. var info;
  4755. while (mode.innerMode) {
  4756. info = mode.innerMode(state);
  4757. if (!info || info.mode == mode) { break }
  4758. state = info.state;
  4759. mode = info.mode;
  4760. }
  4761. return info || {mode: mode, state: state}
  4762. }
  4763. function startState(mode, a1, a2) {
  4764. return mode.startState ? mode.startState(a1, a2) : true
  4765. }
  4766. // STRING STREAM
  4767. // Fed to the mode parsers, provides helper functions to make
  4768. // parsers more succinct.
  4769. var StringStream = function(string, tabSize, lineOracle) {
  4770. this.pos = this.start = 0;
  4771. this.string = string;
  4772. this.tabSize = tabSize || 8;
  4773. this.lastColumnPos = this.lastColumnValue = 0;
  4774. this.lineStart = 0;
  4775. this.lineOracle = lineOracle;
  4776. };
  4777. StringStream.prototype.eol = function () {return this.pos >= this.string.length};
  4778. StringStream.prototype.sol = function () {return this.pos == this.lineStart};
  4779. StringStream.prototype.peek = function () {return this.string.charAt(this.pos) || undefined};
  4780. StringStream.prototype.next = function () {
  4781. if (this.pos < this.string.length)
  4782. { return this.string.charAt(this.pos++) }
  4783. };
  4784. StringStream.prototype.eat = function (match) {
  4785. var ch = this.string.charAt(this.pos);
  4786. var ok;
  4787. if (typeof match == "string") { ok = ch == match; }
  4788. else { ok = ch && (match.test ? match.test(ch) : match(ch)); }
  4789. if (ok) {++this.pos; return ch}
  4790. };
  4791. StringStream.prototype.eatWhile = function (match) {
  4792. var start = this.pos;
  4793. while (this.eat(match)){}
  4794. return this.pos > start
  4795. };
  4796. StringStream.prototype.eatSpace = function () {
  4797. var this$1 = this;
  4798. var start = this.pos;
  4799. while (/[\s\u00a0]/.test(this.string.charAt(this.pos))) { ++this$1.pos; }
  4800. return this.pos > start
  4801. };
  4802. StringStream.prototype.skipToEnd = function () {this.pos = this.string.length;};
  4803. StringStream.prototype.skipTo = function (ch) {
  4804. var found = this.string.indexOf(ch, this.pos);
  4805. if (found > -1) {this.pos = found; return true}
  4806. };
  4807. StringStream.prototype.backUp = function (n) {this.pos -= n;};
  4808. StringStream.prototype.column = function () {
  4809. if (this.lastColumnPos < this.start) {
  4810. this.lastColumnValue = countColumn(this.string, this.start, this.tabSize, this.lastColumnPos, this.lastColumnValue);
  4811. this.lastColumnPos = this.start;
  4812. }
  4813. return this.lastColumnValue - (this.lineStart ? countColumn(this.string, this.lineStart, this.tabSize) : 0)
  4814. };
  4815. StringStream.prototype.indentation = function () {
  4816. return countColumn(this.string, null, this.tabSize) -
  4817. (this.lineStart ? countColumn(this.string, this.lineStart, this.tabSize) : 0)
  4818. };
  4819. StringStream.prototype.match = function (pattern, consume, caseInsensitive) {
  4820. if (typeof pattern == "string") {
  4821. var cased = function (str) { return caseInsensitive ? str.toLowerCase() : str; };
  4822. var substr = this.string.substr(this.pos, pattern.length);
  4823. if (cased(substr) == cased(pattern)) {
  4824. if (consume !== false) { this.pos += pattern.length; }
  4825. return true
  4826. }
  4827. } else {
  4828. var match = this.string.slice(this.pos).match(pattern);
  4829. if (match && match.index > 0) { return null }
  4830. if (match && consume !== false) { this.pos += match[0].length; }
  4831. return match
  4832. }
  4833. };
  4834. StringStream.prototype.current = function (){return this.string.slice(this.start, this.pos)};
  4835. StringStream.prototype.hideFirstChars = function (n, inner) {
  4836. this.lineStart += n;
  4837. try { return inner() }
  4838. finally { this.lineStart -= n; }
  4839. };
  4840. StringStream.prototype.lookAhead = function (n) {
  4841. var oracle = this.lineOracle;
  4842. return oracle && oracle.lookAhead(n)
  4843. };
  4844. StringStream.prototype.baseToken = function () {
  4845. var oracle = this.lineOracle;
  4846. return oracle && oracle.baseToken(this.pos)
  4847. };
  4848. // Find the line object corresponding to the given line number.
  4849. function getLine(doc, n) {
  4850. n -= doc.first;
  4851. if (n < 0 || n >= doc.size) { throw new Error("There is no line " + (n + doc.first) + " in the document.") }
  4852. var chunk = doc;
  4853. while (!chunk.lines) {
  4854. for (var i = 0;; ++i) {
  4855. var child = chunk.children[i], sz = child.chunkSize();
  4856. if (n < sz) { chunk = child; break }
  4857. n -= sz;
  4858. }
  4859. }
  4860. return chunk.lines[n]
  4861. }
  4862. // Get the part of a document between two positions, as an array of
  4863. // strings.
  4864. function getBetween(doc, start, end) {
  4865. var out = [], n = start.line;
  4866. doc.iter(start.line, end.line + 1, function (line) {
  4867. var text = line.text;
  4868. if (n == end.line) { text = text.slice(0, end.ch); }
  4869. if (n == start.line) { text = text.slice(start.ch); }
  4870. out.push(text);
  4871. ++n;
  4872. });
  4873. return out
  4874. }
  4875. // Get the lines between from and to, as array of strings.
  4876. function getLines(doc, from, to) {
  4877. var out = [];
  4878. doc.iter(from, to, function (line) { out.push(line.text); }); // iter aborts when callback returns truthy value
  4879. return out
  4880. }
  4881. // Update the height of a line, propagating the height change
  4882. // upwards to parent nodes.
  4883. function updateLineHeight(line, height) {
  4884. var diff = height - line.height;
  4885. if (diff) { for (var n = line; n; n = n.parent) { n.height += diff; } }
  4886. }
  4887. // Given a line object, find its line number by walking up through
  4888. // its parent links.
  4889. function lineNo(line) {
  4890. if (line.parent == null) { return null }
  4891. var cur = line.parent, no = indexOf(cur.lines, line);
  4892. for (var chunk = cur.parent; chunk; cur = chunk, chunk = chunk.parent) {
  4893. for (var i = 0;; ++i) {
  4894. if (chunk.children[i] == cur) { break }
  4895. no += chunk.children[i].chunkSize();
  4896. }
  4897. }
  4898. return no + cur.first
  4899. }
  4900. // Find the line at the given vertical position, using the height
  4901. // information in the document tree.
  4902. function lineAtHeight(chunk, h) {
  4903. var n = chunk.first;
  4904. outer: do {
  4905. for (var i$1 = 0; i$1 < chunk.children.length; ++i$1) {
  4906. var child = chunk.children[i$1], ch = child.height;
  4907. if (h < ch) { chunk = child; continue outer }
  4908. h -= ch;
  4909. n += child.chunkSize();
  4910. }
  4911. return n
  4912. } while (!chunk.lines)
  4913. var i = 0;
  4914. for (; i < chunk.lines.length; ++i) {
  4915. var line = chunk.lines[i], lh = line.height;
  4916. if (h < lh) { break }
  4917. h -= lh;
  4918. }
  4919. return n + i
  4920. }
  4921. function isLine(doc, l) {return l >= doc.first && l < doc.first + doc.size}
  4922. function lineNumberFor(options, i) {
  4923. return String(options.lineNumberFormatter(i + options.firstLineNumber))
  4924. }
  4925. // A Pos instance represents a position within the text.
  4926. function Pos(line, ch, sticky) {
  4927. if ( sticky === void 0 ) sticky = null;
  4928. if (!(this instanceof Pos)) { return new Pos(line, ch, sticky) }
  4929. this.line = line;
  4930. this.ch = ch;
  4931. this.sticky = sticky;
  4932. }
  4933. // Compare two positions, return 0 if they are the same, a negative
  4934. // number when a is less, and a positive number otherwise.
  4935. function cmp(a, b) { return a.line - b.line || a.ch - b.ch }
  4936. function equalCursorPos(a, b) { return a.sticky == b.sticky && cmp(a, b) == 0 }
  4937. function copyPos(x) {return Pos(x.line, x.ch)}
  4938. function maxPos(a, b) { return cmp(a, b) < 0 ? b : a }
  4939. function minPos(a, b) { return cmp(a, b) < 0 ? a : b }
  4940. // Most of the external API clips given positions to make sure they
  4941. // actually exist within the document.
  4942. function clipLine(doc, n) {return Math.max(doc.first, Math.min(n, doc.first + doc.size - 1))}
  4943. function clipPos(doc, pos) {
  4944. if (pos.line < doc.first) { return Pos(doc.first, 0) }
  4945. var last = doc.first + doc.size - 1;
  4946. if (pos.line > last) { return Pos(last, getLine(doc, last).text.length) }
  4947. return clipToLen(pos, getLine(doc, pos.line).text.length)
  4948. }
  4949. function clipToLen(pos, linelen) {
  4950. var ch = pos.ch;
  4951. if (ch == null || ch > linelen) { return Pos(pos.line, linelen) }
  4952. else if (ch < 0) { return Pos(pos.line, 0) }
  4953. else { return pos }
  4954. }
  4955. function clipPosArray(doc, array) {
  4956. var out = [];
  4957. for (var i = 0; i < array.length; i++) { out[i] = clipPos(doc, array[i]); }
  4958. return out
  4959. }
  4960. var SavedContext = function(state, lookAhead) {
  4961. this.state = state;
  4962. this.lookAhead = lookAhead;
  4963. };
  4964. var Context = function(doc, state, line, lookAhead) {
  4965. this.state = state;
  4966. this.doc = doc;
  4967. this.line = line;
  4968. this.maxLookAhead = lookAhead || 0;
  4969. this.baseTokens = null;
  4970. this.baseTokenPos = 1;
  4971. };
  4972. Context.prototype.lookAhead = function (n) {
  4973. var line = this.doc.getLine(this.line + n);
  4974. if (line != null && n > this.maxLookAhead) { this.maxLookAhead = n; }
  4975. return line
  4976. };
  4977. Context.prototype.baseToken = function (n) {
  4978. var this$1 = this;
  4979. if (!this.baseTokens) { return null }
  4980. while (this.baseTokens[this.baseTokenPos] <= n)
  4981. { this$1.baseTokenPos += 2; }
  4982. var type = this.baseTokens[this.baseTokenPos + 1];
  4983. return {type: type && type.replace(/( |^)overlay .*/, ""),
  4984. size: this.baseTokens[this.baseTokenPos] - n}
  4985. };
  4986. Context.prototype.nextLine = function () {
  4987. this.line++;
  4988. if (this.maxLookAhead > 0) { this.maxLookAhead--; }
  4989. };
  4990. Context.fromSaved = function (doc, saved, line) {
  4991. if (saved instanceof SavedContext)
  4992. { return new Context(doc, copyState(doc.mode, saved.state), line, saved.lookAhead) }
  4993. else
  4994. { return new Context(doc, copyState(doc.mode, saved), line) }
  4995. };
  4996. Context.prototype.save = function (copy) {
  4997. var state = copy !== false ? copyState(this.doc.mode, this.state) : this.state;
  4998. return this.maxLookAhead > 0 ? new SavedContext(state, this.maxLookAhead) : state
  4999. };
  5000. // Compute a style array (an array starting with a mode generation
  5001. // -- for invalidation -- followed by pairs of end positions and
  5002. // style strings), which is used to highlight the tokens on the
  5003. // line.
  5004. function highlightLine(cm, line, context, forceToEnd) {
  5005. // A styles array always starts with a number identifying the
  5006. // mode/overlays that it is based on (for easy invalidation).
  5007. var st = [cm.state.modeGen], lineClasses = {};
  5008. // Compute the base array of styles
  5009. runMode(cm, line.text, cm.doc.mode, context, function (end, style) { return st.push(end, style); },
  5010. lineClasses, forceToEnd);
  5011. var state = context.state;
  5012. // Run overlays, adjust style array.
  5013. var loop = function ( o ) {
  5014. context.baseTokens = st;
  5015. var overlay = cm.state.overlays[o], i = 1, at = 0;
  5016. context.state = true;
  5017. runMode(cm, line.text, overlay.mode, context, function (end, style) {
  5018. var start = i;
  5019. // Ensure there's a token end at the current position, and that i points at it
  5020. while (at < end) {
  5021. var i_end = st[i];
  5022. if (i_end > end)
  5023. { st.splice(i, 1, end, st[i+1], i_end); }
  5024. i += 2;
  5025. at = Math.min(end, i_end);
  5026. }
  5027. if (!style) { return }
  5028. if (overlay.opaque) {
  5029. st.splice(start, i - start, end, "overlay " + style);
  5030. i = start + 2;
  5031. } else {
  5032. for (; start < i; start += 2) {
  5033. var cur = st[start+1];
  5034. st[start+1] = (cur ? cur + " " : "") + "overlay " + style;
  5035. }
  5036. }
  5037. }, lineClasses);
  5038. context.state = state;
  5039. context.baseTokens = null;
  5040. context.baseTokenPos = 1;
  5041. };
  5042. for (var o = 0; o < cm.state.overlays.length; ++o) loop( o );
  5043. return {styles: st, classes: lineClasses.bgClass || lineClasses.textClass ? lineClasses : null}
  5044. }
  5045. function getLineStyles(cm, line, updateFrontier) {
  5046. if (!line.styles || line.styles[0] != cm.state.modeGen) {
  5047. var context = getContextBefore(cm, lineNo(line));
  5048. var resetState = line.text.length > cm.options.maxHighlightLength && copyState(cm.doc.mode, context.state);
  5049. var result = highlightLine(cm, line, context);
  5050. if (resetState) { context.state = resetState; }
  5051. line.stateAfter = context.save(!resetState);
  5052. line.styles = result.styles;
  5053. if (result.classes) { line.styleClasses = result.classes; }
  5054. else if (line.styleClasses) { line.styleClasses = null; }
  5055. if (updateFrontier === cm.doc.highlightFrontier)
  5056. { cm.doc.modeFrontier = Math.max(cm.doc.modeFrontier, ++cm.doc.highlightFrontier); }
  5057. }
  5058. return line.styles
  5059. }
  5060. function getContextBefore(cm, n, precise) {
  5061. var doc = cm.doc, display = cm.display;
  5062. if (!doc.mode.startState) { return new Context(doc, true, n) }
  5063. var start = findStartLine(cm, n, precise);
  5064. var saved = start > doc.first && getLine(doc, start - 1).stateAfter;
  5065. var context = saved ? Context.fromSaved(doc, saved, start) : new Context(doc, startState(doc.mode), start);
  5066. doc.iter(start, n, function (line) {
  5067. processLine(cm, line.text, context);
  5068. var pos = context.line;
  5069. line.stateAfter = pos == n - 1 || pos % 5 == 0 || pos >= display.viewFrom && pos < display.viewTo ? context.save() : null;
  5070. context.nextLine();
  5071. });
  5072. if (precise) { doc.modeFrontier = context.line; }
  5073. return context
  5074. }
  5075. // Lightweight form of highlight -- proceed over this line and
  5076. // update state, but don't save a style array. Used for lines that
  5077. // aren't currently visible.
  5078. function processLine(cm, text, context, startAt) {
  5079. var mode = cm.doc.mode;
  5080. var stream = new StringStream(text, cm.options.tabSize, context);
  5081. stream.start = stream.pos = startAt || 0;
  5082. if (text == "") { callBlankLine(mode, context.state); }
  5083. while (!stream.eol()) {
  5084. readToken(mode, stream, context.state);
  5085. stream.start = stream.pos;
  5086. }
  5087. }
  5088. function callBlankLine(mode, state) {
  5089. if (mode.blankLine) { return mode.blankLine(state) }
  5090. if (!mode.innerMode) { return }
  5091. var inner = innerMode(mode, state);
  5092. if (inner.mode.blankLine) { return inner.mode.blankLine(inner.state) }
  5093. }
  5094. function readToken(mode, stream, state, inner) {
  5095. for (var i = 0; i < 10; i++) {
  5096. if (inner) { inner[0] = innerMode(mode, state).mode; }
  5097. var style = mode.token(stream, state);
  5098. if (stream.pos > stream.start) { return style }
  5099. }
  5100. throw new Error("Mode " + mode.name + " failed to advance stream.")
  5101. }
  5102. var Token = function(stream, type, state) {
  5103. this.start = stream.start; this.end = stream.pos;
  5104. this.string = stream.current();
  5105. this.type = type || null;
  5106. this.state = state;
  5107. };
  5108. // Utility for getTokenAt and getLineTokens
  5109. function takeToken(cm, pos, precise, asArray) {
  5110. var doc = cm.doc, mode = doc.mode, style;
  5111. pos = clipPos(doc, pos);
  5112. var line = getLine(doc, pos.line), context = getContextBefore(cm, pos.line, precise);
  5113. var stream = new StringStream(line.text, cm.options.tabSize, context), tokens;
  5114. if (asArray) { tokens = []; }
  5115. while ((asArray || stream.pos < pos.ch) && !stream.eol()) {
  5116. stream.start = stream.pos;
  5117. style = readToken(mode, stream, context.state);
  5118. if (asArray) { tokens.push(new Token(stream, style, copyState(doc.mode, context.state))); }
  5119. }
  5120. return asArray ? tokens : new Token(stream, style, context.state)
  5121. }
  5122. function extractLineClasses(type, output) {
  5123. if (type) { for (;;) {
  5124. var lineClass = type.match(/(?:^|\s+)line-(background-)?(\S+)/);
  5125. if (!lineClass) { break }
  5126. type = type.slice(0, lineClass.index) + type.slice(lineClass.index + lineClass[0].length);
  5127. var prop = lineClass[1] ? "bgClass" : "textClass";
  5128. if (output[prop] == null)
  5129. { output[prop] = lineClass[2]; }
  5130. else if (!(new RegExp("(?:^|\s)" + lineClass[2] + "(?:$|\s)")).test(output[prop]))
  5131. { output[prop] += " " + lineClass[2]; }
  5132. } }
  5133. return type
  5134. }
  5135. // Run the given mode's parser over a line, calling f for each token.
  5136. function runMode(cm, text, mode, context, f, lineClasses, forceToEnd) {
  5137. var flattenSpans = mode.flattenSpans;
  5138. if (flattenSpans == null) { flattenSpans = cm.options.flattenSpans; }
  5139. var curStart = 0, curStyle = null;
  5140. var stream = new StringStream(text, cm.options.tabSize, context), style;
  5141. var inner = cm.options.addModeClass && [null];
  5142. if (text == "") { extractLineClasses(callBlankLine(mode, context.state), lineClasses); }
  5143. while (!stream.eol()) {
  5144. if (stream.pos > cm.options.maxHighlightLength) {
  5145. flattenSpans = false;
  5146. if (forceToEnd) { processLine(cm, text, context, stream.pos); }
  5147. stream.pos = text.length;
  5148. style = null;
  5149. } else {
  5150. style = extractLineClasses(readToken(mode, stream, context.state, inner), lineClasses);
  5151. }
  5152. if (inner) {
  5153. var mName = inner[0].name;
  5154. if (mName) { style = "m-" + (style ? mName + " " + style : mName); }
  5155. }
  5156. if (!flattenSpans || curStyle != style) {
  5157. while (curStart < stream.start) {
  5158. curStart = Math.min(stream.start, curStart + 5000);
  5159. f(curStart, curStyle);
  5160. }
  5161. curStyle = style;
  5162. }
  5163. stream.start = stream.pos;
  5164. }
  5165. while (curStart < stream.pos) {
  5166. // Webkit seems to refuse to render text nodes longer than 57444
  5167. // characters, and returns inaccurate measurements in nodes
  5168. // starting around 5000 chars.
  5169. var pos = Math.min(stream.pos, curStart + 5000);
  5170. f(pos, curStyle);
  5171. curStart = pos;
  5172. }
  5173. }
  5174. // Finds the line to start with when starting a parse. Tries to
  5175. // find a line with a stateAfter, so that it can start with a
  5176. // valid state. If that fails, it returns the line with the
  5177. // smallest indentation, which tends to need the least context to
  5178. // parse correctly.
  5179. function findStartLine(cm, n, precise) {
  5180. var minindent, minline, doc = cm.doc;
  5181. var lim = precise ? -1 : n - (cm.doc.mode.innerMode ? 1000 : 100);
  5182. for (var search = n; search > lim; --search) {
  5183. if (search <= doc.first) { return doc.first }
  5184. var line = getLine(doc, search - 1), after = line.stateAfter;
  5185. if (after && (!precise || search + (after instanceof SavedContext ? after.lookAhead : 0) <= doc.modeFrontier))
  5186. { return search }
  5187. var indented = countColumn(line.text, null, cm.options.tabSize);
  5188. if (minline == null || minindent > indented) {
  5189. minline = search - 1;
  5190. minindent = indented;
  5191. }
  5192. }
  5193. return minline
  5194. }
  5195. function retreatFrontier(doc, n) {
  5196. doc.modeFrontier = Math.min(doc.modeFrontier, n);
  5197. if (doc.highlightFrontier < n - 10) { return }
  5198. var start = doc.first;
  5199. for (var line = n - 1; line > start; line--) {
  5200. var saved = getLine(doc, line).stateAfter;
  5201. // change is on 3
  5202. // state on line 1 looked ahead 2 -- so saw 3
  5203. // test 1 + 2 < 3 should cover this
  5204. if (saved && (!(saved instanceof SavedContext) || line + saved.lookAhead < n)) {
  5205. start = line + 1;
  5206. break
  5207. }
  5208. }
  5209. doc.highlightFrontier = Math.min(doc.highlightFrontier, start);
  5210. }
  5211. // Optimize some code when these features are not used.
  5212. var sawReadOnlySpans = false, sawCollapsedSpans = false;
  5213. function seeReadOnlySpans() {
  5214. sawReadOnlySpans = true;
  5215. }
  5216. function seeCollapsedSpans() {
  5217. sawCollapsedSpans = true;
  5218. }
  5219. // TEXTMARKER SPANS
  5220. function MarkedSpan(marker, from, to) {
  5221. this.marker = marker;
  5222. this.from = from; this.to = to;
  5223. }
  5224. // Search an array of spans for a span matching the given marker.
  5225. function getMarkedSpanFor(spans, marker) {
  5226. if (spans) { for (var i = 0; i < spans.length; ++i) {
  5227. var span = spans[i];
  5228. if (span.marker == marker) { return span }
  5229. } }
  5230. }
  5231. // Remove a span from an array, returning undefined if no spans are
  5232. // left (we don't store arrays for lines without spans).
  5233. function removeMarkedSpan(spans, span) {
  5234. var r;
  5235. for (var i = 0; i < spans.length; ++i)
  5236. { if (spans[i] != span) { (r || (r = [])).push(spans[i]); } }
  5237. return r
  5238. }
  5239. // Add a span to a line.
  5240. function addMarkedSpan(line, span) {
  5241. line.markedSpans = line.markedSpans ? line.markedSpans.concat([span]) : [span];
  5242. span.marker.attachLine(line);
  5243. }
  5244. // Used for the algorithm that adjusts markers for a change in the
  5245. // document. These functions cut an array of spans at a given
  5246. // character position, returning an array of remaining chunks (or
  5247. // undefined if nothing remains).
  5248. function markedSpansBefore(old, startCh, isInsert) {
  5249. var nw;
  5250. if (old) { for (var i = 0; i < old.length; ++i) {
  5251. var span = old[i], marker = span.marker;
  5252. var startsBefore = span.from == null || (marker.inclusiveLeft ? span.from <= startCh : span.from < startCh);
  5253. if (startsBefore || span.from == startCh && marker.type == "bookmark" && (!isInsert || !span.marker.insertLeft)) {
  5254. var endsAfter = span.to == null || (marker.inclusiveRight ? span.to >= startCh : span.to > startCh)
  5255. ;(nw || (nw = [])).push(new MarkedSpan(marker, span.from, endsAfter ? null : span.to));
  5256. }
  5257. } }
  5258. return nw
  5259. }
  5260. function markedSpansAfter(old, endCh, isInsert) {
  5261. var nw;
  5262. if (old) { for (var i = 0; i < old.length; ++i) {
  5263. var span = old[i], marker = span.marker;
  5264. var endsAfter = span.to == null || (marker.inclusiveRight ? span.to >= endCh : span.to > endCh);
  5265. if (endsAfter || span.from == endCh && marker.type == "bookmark" && (!isInsert || span.marker.insertLeft)) {
  5266. var startsBefore = span.from == null || (marker.inclusiveLeft ? span.from <= endCh : span.from < endCh)
  5267. ;(nw || (nw = [])).push(new MarkedSpan(marker, startsBefore ? null : span.from - endCh,
  5268. span.to == null ? null : span.to - endCh));
  5269. }
  5270. } }
  5271. return nw
  5272. }
  5273. // Given a change object, compute the new set of marker spans that
  5274. // cover the line in which the change took place. Removes spans
  5275. // entirely within the change, reconnects spans belonging to the
  5276. // same marker that appear on both sides of the change, and cuts off
  5277. // spans partially within the change. Returns an array of span
  5278. // arrays with one element for each line in (after) the change.
  5279. function stretchSpansOverChange(doc, change) {
  5280. if (change.full) { return null }
  5281. var oldFirst = isLine(doc, change.from.line) && getLine(doc, change.from.line).markedSpans;
  5282. var oldLast = isLine(doc, change.to.line) && getLine(doc, change.to.line).markedSpans;
  5283. if (!oldFirst && !oldLast) { return null }
  5284. var startCh = change.from.ch, endCh = change.to.ch, isInsert = cmp(change.from, change.to) == 0;
  5285. // Get the spans that 'stick out' on both sides
  5286. var first = markedSpansBefore(oldFirst, startCh, isInsert);
  5287. var last = markedSpansAfter(oldLast, endCh, isInsert);
  5288. // Next, merge those two ends
  5289. var sameLine = change.text.length == 1, offset = lst(change.text).length + (sameLine ? startCh : 0);
  5290. if (first) {
  5291. // Fix up .to properties of first
  5292. for (var i = 0; i < first.length; ++i) {
  5293. var span = first[i];
  5294. if (span.to == null) {
  5295. var found = getMarkedSpanFor(last, span.marker);
  5296. if (!found) { span.to = startCh; }
  5297. else if (sameLine) { span.to = found.to == null ? null : found.to + offset; }
  5298. }
  5299. }
  5300. }
  5301. if (last) {
  5302. // Fix up .from in last (or move them into first in case of sameLine)
  5303. for (var i$1 = 0; i$1 < last.length; ++i$1) {
  5304. var span$1 = last[i$1];
  5305. if (span$1.to != null) { span$1.to += offset; }
  5306. if (span$1.from == null) {
  5307. var found$1 = getMarkedSpanFor(first, span$1.marker);
  5308. if (!found$1) {
  5309. span$1.from = offset;
  5310. if (sameLine) { (first || (first = [])).push(span$1); }
  5311. }
  5312. } else {
  5313. span$1.from += offset;
  5314. if (sameLine) { (first || (first = [])).push(span$1); }
  5315. }
  5316. }
  5317. }
  5318. // Make sure we didn't create any zero-length spans
  5319. if (first) { first = clearEmptySpans(first); }
  5320. if (last && last != first) { last = clearEmptySpans(last); }
  5321. var newMarkers = [first];
  5322. if (!sameLine) {
  5323. // Fill gap with whole-line-spans
  5324. var gap = change.text.length - 2, gapMarkers;
  5325. if (gap > 0 && first)
  5326. { for (var i$2 = 0; i$2 < first.length; ++i$2)
  5327. { if (first[i$2].to == null)
  5328. { (gapMarkers || (gapMarkers = [])).push(new MarkedSpan(first[i$2].marker, null, null)); } } }
  5329. for (var i$3 = 0; i$3 < gap; ++i$3)
  5330. { newMarkers.push(gapMarkers); }
  5331. newMarkers.push(last);
  5332. }
  5333. return newMarkers
  5334. }
  5335. // Remove spans that are empty and don't have a clearWhenEmpty
  5336. // option of false.
  5337. function clearEmptySpans(spans) {
  5338. for (var i = 0; i < spans.length; ++i) {
  5339. var span = spans[i];
  5340. if (span.from != null && span.from == span.to && span.marker.clearWhenEmpty !== false)
  5341. { spans.splice(i--, 1); }
  5342. }
  5343. if (!spans.length) { return null }
  5344. return spans
  5345. }
  5346. // Used to 'clip' out readOnly ranges when making a change.
  5347. function removeReadOnlyRanges(doc, from, to) {
  5348. var markers = null;
  5349. doc.iter(from.line, to.line + 1, function (line) {
  5350. if (line.markedSpans) { for (var i = 0; i < line.markedSpans.length; ++i) {
  5351. var mark = line.markedSpans[i].marker;
  5352. if (mark.readOnly && (!markers || indexOf(markers, mark) == -1))
  5353. { (markers || (markers = [])).push(mark); }
  5354. } }
  5355. });
  5356. if (!markers) { return null }
  5357. var parts = [{from: from, to: to}];
  5358. for (var i = 0; i < markers.length; ++i) {
  5359. var mk = markers[i], m = mk.find(0);
  5360. for (var j = 0; j < parts.length; ++j) {
  5361. var p = parts[j];
  5362. if (cmp(p.to, m.from) < 0 || cmp(p.from, m.to) > 0) { continue }
  5363. var newParts = [j, 1], dfrom = cmp(p.from, m.from), dto = cmp(p.to, m.to);
  5364. if (dfrom < 0 || !mk.inclusiveLeft && !dfrom)
  5365. { newParts.push({from: p.from, to: m.from}); }
  5366. if (dto > 0 || !mk.inclusiveRight && !dto)
  5367. { newParts.push({from: m.to, to: p.to}); }
  5368. parts.splice.apply(parts, newParts);
  5369. j += newParts.length - 3;
  5370. }
  5371. }
  5372. return parts
  5373. }
  5374. // Connect or disconnect spans from a line.
  5375. function detachMarkedSpans(line) {
  5376. var spans = line.markedSpans;
  5377. if (!spans) { return }
  5378. for (var i = 0; i < spans.length; ++i)
  5379. { spans[i].marker.detachLine(line); }
  5380. line.markedSpans = null;
  5381. }
  5382. function attachMarkedSpans(line, spans) {
  5383. if (!spans) { return }
  5384. for (var i = 0; i < spans.length; ++i)
  5385. { spans[i].marker.attachLine(line); }
  5386. line.markedSpans = spans;
  5387. }
  5388. // Helpers used when computing which overlapping collapsed span
  5389. // counts as the larger one.
  5390. function extraLeft(marker) { return marker.inclusiveLeft ? -1 : 0 }
  5391. function extraRight(marker) { return marker.inclusiveRight ? 1 : 0 }
  5392. // Returns a number indicating which of two overlapping collapsed
  5393. // spans is larger (and thus includes the other). Falls back to
  5394. // comparing ids when the spans cover exactly the same range.
  5395. function compareCollapsedMarkers(a, b) {
  5396. var lenDiff = a.lines.length - b.lines.length;
  5397. if (lenDiff != 0) { return lenDiff }
  5398. var aPos = a.find(), bPos = b.find();
  5399. var fromCmp = cmp(aPos.from, bPos.from) || extraLeft(a) - extraLeft(b);
  5400. if (fromCmp) { return -fromCmp }
  5401. var toCmp = cmp(aPos.to, bPos.to) || extraRight(a) - extraRight(b);
  5402. if (toCmp) { return toCmp }
  5403. return b.id - a.id
  5404. }
  5405. // Find out whether a line ends or starts in a collapsed span. If
  5406. // so, return the marker for that span.
  5407. function collapsedSpanAtSide(line, start) {
  5408. var sps = sawCollapsedSpans && line.markedSpans, found;
  5409. if (sps) { for (var sp = (void 0), i = 0; i < sps.length; ++i) {
  5410. sp = sps[i];
  5411. if (sp.marker.collapsed && (start ? sp.from : sp.to) == null &&
  5412. (!found || compareCollapsedMarkers(found, sp.marker) < 0))
  5413. { found = sp.marker; }
  5414. } }
  5415. return found
  5416. }
  5417. function collapsedSpanAtStart(line) { return collapsedSpanAtSide(line, true) }
  5418. function collapsedSpanAtEnd(line) { return collapsedSpanAtSide(line, false) }
  5419. function collapsedSpanAround(line, ch) {
  5420. var sps = sawCollapsedSpans && line.markedSpans, found;
  5421. if (sps) { for (var i = 0; i < sps.length; ++i) {
  5422. var sp = sps[i];
  5423. if (sp.marker.collapsed && (sp.from == null || sp.from < ch) && (sp.to == null || sp.to > ch) &&
  5424. (!found || compareCollapsedMarkers(found, sp.marker) < 0)) { found = sp.marker; }
  5425. } }
  5426. return found
  5427. }
  5428. // Test whether there exists a collapsed span that partially
  5429. // overlaps (covers the start or end, but not both) of a new span.
  5430. // Such overlap is not allowed.
  5431. function conflictingCollapsedRange(doc, lineNo$$1, from, to, marker) {
  5432. var line = getLine(doc, lineNo$$1);
  5433. var sps = sawCollapsedSpans && line.markedSpans;
  5434. if (sps) { for (var i = 0; i < sps.length; ++i) {
  5435. var sp = sps[i];
  5436. if (!sp.marker.collapsed) { continue }
  5437. var found = sp.marker.find(0);
  5438. var fromCmp = cmp(found.from, from) || extraLeft(sp.marker) - extraLeft(marker);
  5439. var toCmp = cmp(found.to, to) || extraRight(sp.marker) - extraRight(marker);
  5440. if (fromCmp >= 0 && toCmp <= 0 || fromCmp <= 0 && toCmp >= 0) { continue }
  5441. if (fromCmp <= 0 && (sp.marker.inclusiveRight && marker.inclusiveLeft ? cmp(found.to, from) >= 0 : cmp(found.to, from) > 0) ||
  5442. fromCmp >= 0 && (sp.marker.inclusiveRight && marker.inclusiveLeft ? cmp(found.from, to) <= 0 : cmp(found.from, to) < 0))
  5443. { return true }
  5444. } }
  5445. }
  5446. // A visual line is a line as drawn on the screen. Folding, for
  5447. // example, can cause multiple logical lines to appear on the same
  5448. // visual line. This finds the start of the visual line that the
  5449. // given line is part of (usually that is the line itself).
  5450. function visualLine(line) {
  5451. var merged;
  5452. while (merged = collapsedSpanAtStart(line))
  5453. { line = merged.find(-1, true).line; }
  5454. return line
  5455. }
  5456. function visualLineEnd(line) {
  5457. var merged;
  5458. while (merged = collapsedSpanAtEnd(line))
  5459. { line = merged.find(1, true).line; }
  5460. return line
  5461. }
  5462. // Returns an array of logical lines that continue the visual line
  5463. // started by the argument, or undefined if there are no such lines.
  5464. function visualLineContinued(line) {
  5465. var merged, lines;
  5466. while (merged = collapsedSpanAtEnd(line)) {
  5467. line = merged.find(1, true).line
  5468. ;(lines || (lines = [])).push(line);
  5469. }
  5470. return lines
  5471. }
  5472. // Get the line number of the start of the visual line that the
  5473. // given line number is part of.
  5474. function visualLineNo(doc, lineN) {
  5475. var line = getLine(doc, lineN), vis = visualLine(line);
  5476. if (line == vis) { return lineN }
  5477. return lineNo(vis)
  5478. }
  5479. // Get the line number of the start of the next visual line after
  5480. // the given line.
  5481. function visualLineEndNo(doc, lineN) {
  5482. if (lineN > doc.lastLine()) { return lineN }
  5483. var line = getLine(doc, lineN), merged;
  5484. if (!lineIsHidden(doc, line)) { return lineN }
  5485. while (merged = collapsedSpanAtEnd(line))
  5486. { line = merged.find(1, true).line; }
  5487. return lineNo(line) + 1
  5488. }
  5489. // Compute whether a line is hidden. Lines count as hidden when they
  5490. // are part of a visual line that starts with another line, or when
  5491. // they are entirely covered by collapsed, non-widget span.
  5492. function lineIsHidden(doc, line) {
  5493. var sps = sawCollapsedSpans && line.markedSpans;
  5494. if (sps) { for (var sp = (void 0), i = 0; i < sps.length; ++i) {
  5495. sp = sps[i];
  5496. if (!sp.marker.collapsed) { continue }
  5497. if (sp.from == null) { return true }
  5498. if (sp.marker.widgetNode) { continue }
  5499. if (sp.from == 0 && sp.marker.inclusiveLeft && lineIsHiddenInner(doc, line, sp))
  5500. { return true }
  5501. } }
  5502. }
  5503. function lineIsHiddenInner(doc, line, span) {
  5504. if (span.to == null) {
  5505. var end = span.marker.find(1, true);
  5506. return lineIsHiddenInner(doc, end.line, getMarkedSpanFor(end.line.markedSpans, span.marker))
  5507. }
  5508. if (span.marker.inclusiveRight && span.to == line.text.length)
  5509. { return true }
  5510. for (var sp = (void 0), i = 0; i < line.markedSpans.length; ++i) {
  5511. sp = line.markedSpans[i];
  5512. if (sp.marker.collapsed && !sp.marker.widgetNode && sp.from == span.to &&
  5513. (sp.to == null || sp.to != span.from) &&
  5514. (sp.marker.inclusiveLeft || span.marker.inclusiveRight) &&
  5515. lineIsHiddenInner(doc, line, sp)) { return true }
  5516. }
  5517. }
  5518. // Find the height above the given line.
  5519. function heightAtLine(lineObj) {
  5520. lineObj = visualLine(lineObj);
  5521. var h = 0, chunk = lineObj.parent;
  5522. for (var i = 0; i < chunk.lines.length; ++i) {
  5523. var line = chunk.lines[i];
  5524. if (line == lineObj) { break }
  5525. else { h += line.height; }
  5526. }
  5527. for (var p = chunk.parent; p; chunk = p, p = chunk.parent) {
  5528. for (var i$1 = 0; i$1 < p.children.length; ++i$1) {
  5529. var cur = p.children[i$1];
  5530. if (cur == chunk) { break }
  5531. else { h += cur.height; }
  5532. }
  5533. }
  5534. return h
  5535. }
  5536. // Compute the character length of a line, taking into account
  5537. // collapsed ranges (see markText) that might hide parts, and join
  5538. // other lines onto it.
  5539. function lineLength(line) {
  5540. if (line.height == 0) { return 0 }
  5541. var len = line.text.length, merged, cur = line;
  5542. while (merged = collapsedSpanAtStart(cur)) {
  5543. var found = merged.find(0, true);
  5544. cur = found.from.line;
  5545. len += found.from.ch - found.to.ch;
  5546. }
  5547. cur = line;
  5548. while (merged = collapsedSpanAtEnd(cur)) {
  5549. var found$1 = merged.find(0, true);
  5550. len -= cur.text.length - found$1.from.ch;
  5551. cur = found$1.to.line;
  5552. len += cur.text.length - found$1.to.ch;
  5553. }
  5554. return len
  5555. }
  5556. // Find the longest line in the document.
  5557. function findMaxLine(cm) {
  5558. var d = cm.display, doc = cm.doc;
  5559. d.maxLine = getLine(doc, doc.first);
  5560. d.maxLineLength = lineLength(d.maxLine);
  5561. d.maxLineChanged = true;
  5562. doc.iter(function (line) {
  5563. var len = lineLength(line);
  5564. if (len > d.maxLineLength) {
  5565. d.maxLineLength = len;
  5566. d.maxLine = line;
  5567. }
  5568. });
  5569. }
  5570. // LINE DATA STRUCTURE
  5571. // Line objects. These hold state related to a line, including
  5572. // highlighting info (the styles array).
  5573. var Line = function(text, markedSpans, estimateHeight) {
  5574. this.text = text;
  5575. attachMarkedSpans(this, markedSpans);
  5576. this.height = estimateHeight ? estimateHeight(this) : 1;
  5577. };
  5578. Line.prototype.lineNo = function () { return lineNo(this) };
  5579. eventMixin(Line);
  5580. // Change the content (text, markers) of a line. Automatically
  5581. // invalidates cached information and tries to re-estimate the
  5582. // line's height.
  5583. function updateLine(line, text, markedSpans, estimateHeight) {
  5584. line.text = text;
  5585. if (line.stateAfter) { line.stateAfter = null; }
  5586. if (line.styles) { line.styles = null; }
  5587. if (line.order != null) { line.order = null; }
  5588. detachMarkedSpans(line);
  5589. attachMarkedSpans(line, markedSpans);
  5590. var estHeight = estimateHeight ? estimateHeight(line) : 1;
  5591. if (estHeight != line.height) { updateLineHeight(line, estHeight); }
  5592. }
  5593. // Detach a line from the document tree and its markers.
  5594. function cleanUpLine(line) {
  5595. line.parent = null;
  5596. detachMarkedSpans(line);
  5597. }
  5598. // Convert a style as returned by a mode (either null, or a string
  5599. // containing one or more styles) to a CSS style. This is cached,
  5600. // and also looks for line-wide styles.
  5601. var styleToClassCache = {}, styleToClassCacheWithMode = {};
  5602. function interpretTokenStyle(style, options) {
  5603. if (!style || /^\s*$/.test(style)) { return null }
  5604. var cache = options.addModeClass ? styleToClassCacheWithMode : styleToClassCache;
  5605. return cache[style] ||
  5606. (cache[style] = style.replace(/\S+/g, "cm-$&"))
  5607. }
  5608. // Render the DOM representation of the text of a line. Also builds
  5609. // up a 'line map', which points at the DOM nodes that represent
  5610. // specific stretches of text, and is used by the measuring code.
  5611. // The returned object contains the DOM node, this map, and
  5612. // information about line-wide styles that were set by the mode.
  5613. function buildLineContent(cm, lineView) {
  5614. // The padding-right forces the element to have a 'border', which
  5615. // is needed on Webkit to be able to get line-level bounding
  5616. // rectangles for it (in measureChar).
  5617. var content = eltP("span", null, null, webkit ? "padding-right: .1px" : null);
  5618. var builder = {pre: eltP("pre", [content], "CodeMirror-line"), content: content,
  5619. col: 0, pos: 0, cm: cm,
  5620. trailingSpace: false,
  5621. splitSpaces: cm.getOption("lineWrapping")};
  5622. lineView.measure = {};
  5623. // Iterate over the logical lines that make up this visual line.
  5624. for (var i = 0; i <= (lineView.rest ? lineView.rest.length : 0); i++) {
  5625. var line = i ? lineView.rest[i - 1] : lineView.line, order = (void 0);
  5626. builder.pos = 0;
  5627. builder.addToken = buildToken;
  5628. // Optionally wire in some hacks into the token-rendering
  5629. // algorithm, to deal with browser quirks.
  5630. if (hasBadBidiRects(cm.display.measure) && (order = getOrder(line, cm.doc.direction)))
  5631. { builder.addToken = buildTokenBadBidi(builder.addToken, order); }
  5632. builder.map = [];
  5633. var allowFrontierUpdate = lineView != cm.display.externalMeasured && lineNo(line);
  5634. insertLineContent(line, builder, getLineStyles(cm, line, allowFrontierUpdate));
  5635. if (line.styleClasses) {
  5636. if (line.styleClasses.bgClass)
  5637. { builder.bgClass = joinClasses(line.styleClasses.bgClass, builder.bgClass || ""); }
  5638. if (line.styleClasses.textClass)
  5639. { builder.textClass = joinClasses(line.styleClasses.textClass, builder.textClass || ""); }
  5640. }
  5641. // Ensure at least a single node is present, for measuring.
  5642. if (builder.map.length == 0)
  5643. { builder.map.push(0, 0, builder.content.appendChild(zeroWidthElement(cm.display.measure))); }
  5644. // Store the map and a cache object for the current logical line
  5645. if (i == 0) {
  5646. lineView.measure.map = builder.map;
  5647. lineView.measure.cache = {};
  5648. } else {
  5649. (lineView.measure.maps || (lineView.measure.maps = [])).push(builder.map)
  5650. ;(lineView.measure.caches || (lineView.measure.caches = [])).push({});
  5651. }
  5652. }
  5653. // See issue #2901
  5654. if (webkit) {
  5655. var last = builder.content.lastChild;
  5656. if (/\bcm-tab\b/.test(last.className) || (last.querySelector && last.querySelector(".cm-tab")))
  5657. { builder.content.className = "cm-tab-wrap-hack"; }
  5658. }
  5659. signal(cm, "renderLine", cm, lineView.line, builder.pre);
  5660. if (builder.pre.className)
  5661. { builder.textClass = joinClasses(builder.pre.className, builder.textClass || ""); }
  5662. return builder
  5663. }
  5664. function defaultSpecialCharPlaceholder(ch) {
  5665. var token = elt("span", "\u2022", "cm-invalidchar");
  5666. token.title = "\\u" + ch.charCodeAt(0).toString(16);
  5667. token.setAttribute("aria-label", token.title);
  5668. return token
  5669. }
  5670. // Build up the DOM representation for a single token, and add it to
  5671. // the line map. Takes care to render special characters separately.
  5672. function buildToken(builder, text, style, startStyle, endStyle, css, attributes) {
  5673. if (!text) { return }
  5674. var displayText = builder.splitSpaces ? splitSpaces(text, builder.trailingSpace) : text;
  5675. var special = builder.cm.state.specialChars, mustWrap = false;
  5676. var content;
  5677. if (!special.test(text)) {
  5678. builder.col += text.length;
  5679. content = document.createTextNode(displayText);
  5680. builder.map.push(builder.pos, builder.pos + text.length, content);
  5681. if (ie && ie_version < 9) { mustWrap = true; }
  5682. builder.pos += text.length;
  5683. } else {
  5684. content = document.createDocumentFragment();
  5685. var pos = 0;
  5686. while (true) {
  5687. special.lastIndex = pos;
  5688. var m = special.exec(text);
  5689. var skipped = m ? m.index - pos : text.length - pos;
  5690. if (skipped) {
  5691. var txt = document.createTextNode(displayText.slice(pos, pos + skipped));
  5692. if (ie && ie_version < 9) { content.appendChild(elt("span", [txt])); }
  5693. else { content.appendChild(txt); }
  5694. builder.map.push(builder.pos, builder.pos + skipped, txt);
  5695. builder.col += skipped;
  5696. builder.pos += skipped;
  5697. }
  5698. if (!m) { break }
  5699. pos += skipped + 1;
  5700. var txt$1 = (void 0);
  5701. if (m[0] == "\t") {
  5702. var tabSize = builder.cm.options.tabSize, tabWidth = tabSize - builder.col % tabSize;
  5703. txt$1 = content.appendChild(elt("span", spaceStr(tabWidth), "cm-tab"));
  5704. txt$1.setAttribute("role", "presentation");
  5705. txt$1.setAttribute("cm-text", "\t");
  5706. builder.col += tabWidth;
  5707. } else if (m[0] == "\r" || m[0] == "\n") {
  5708. txt$1 = content.appendChild(elt("span", m[0] == "\r" ? "\u240d" : "\u2424", "cm-invalidchar"));
  5709. txt$1.setAttribute("cm-text", m[0]);
  5710. builder.col += 1;
  5711. } else {
  5712. txt$1 = builder.cm.options.specialCharPlaceholder(m[0]);
  5713. txt$1.setAttribute("cm-text", m[0]);
  5714. if (ie && ie_version < 9) { content.appendChild(elt("span", [txt$1])); }
  5715. else { content.appendChild(txt$1); }
  5716. builder.col += 1;
  5717. }
  5718. builder.map.push(builder.pos, builder.pos + 1, txt$1);
  5719. builder.pos++;
  5720. }
  5721. }
  5722. builder.trailingSpace = displayText.charCodeAt(text.length - 1) == 32;
  5723. if (style || startStyle || endStyle || mustWrap || css) {
  5724. var fullStyle = style || "";
  5725. if (startStyle) { fullStyle += startStyle; }
  5726. if (endStyle) { fullStyle += endStyle; }
  5727. var token = elt("span", [content], fullStyle, css);
  5728. if (attributes) {
  5729. for (var attr in attributes) { if (attributes.hasOwnProperty(attr) && attr != "style" && attr != "class")
  5730. { token.setAttribute(attr, attributes[attr]); } }
  5731. }
  5732. return builder.content.appendChild(token)
  5733. }
  5734. builder.content.appendChild(content);
  5735. }
  5736. // Change some spaces to NBSP to prevent the browser from collapsing
  5737. // trailing spaces at the end of a line when rendering text (issue #1362).
  5738. function splitSpaces(text, trailingBefore) {
  5739. if (text.length > 1 && !/ /.test(text)) { return text }
  5740. var spaceBefore = trailingBefore, result = "";
  5741. for (var i = 0; i < text.length; i++) {
  5742. var ch = text.charAt(i);
  5743. if (ch == " " && spaceBefore && (i == text.length - 1 || text.charCodeAt(i + 1) == 32))
  5744. { ch = "\u00a0"; }
  5745. result += ch;
  5746. spaceBefore = ch == " ";
  5747. }
  5748. return result
  5749. }
  5750. // Work around nonsense dimensions being reported for stretches of
  5751. // right-to-left text.
  5752. function buildTokenBadBidi(inner, order) {
  5753. return function (builder, text, style, startStyle, endStyle, css, attributes) {
  5754. style = style ? style + " cm-force-border" : "cm-force-border";
  5755. var start = builder.pos, end = start + text.length;
  5756. for (;;) {
  5757. // Find the part that overlaps with the start of this text
  5758. var part = (void 0);
  5759. for (var i = 0; i < order.length; i++) {
  5760. part = order[i];
  5761. if (part.to > start && part.from <= start) { break }
  5762. }
  5763. if (part.to >= end) { return inner(builder, text, style, startStyle, endStyle, css, attributes) }
  5764. inner(builder, text.slice(0, part.to - start), style, startStyle, null, css, attributes);
  5765. startStyle = null;
  5766. text = text.slice(part.to - start);
  5767. start = part.to;
  5768. }
  5769. }
  5770. }
  5771. function buildCollapsedSpan(builder, size, marker, ignoreWidget) {
  5772. var widget = !ignoreWidget && marker.widgetNode;
  5773. if (widget) { builder.map.push(builder.pos, builder.pos + size, widget); }
  5774. if (!ignoreWidget && builder.cm.display.input.needsContentAttribute) {
  5775. if (!widget)
  5776. { widget = builder.content.appendChild(document.createElement("span")); }
  5777. widget.setAttribute("cm-marker", marker.id);
  5778. }
  5779. if (widget) {
  5780. builder.cm.display.input.setUneditable(widget);
  5781. builder.content.appendChild(widget);
  5782. }
  5783. builder.pos += size;
  5784. builder.trailingSpace = false;
  5785. }
  5786. // Outputs a number of spans to make up a line, taking highlighting
  5787. // and marked text into account.
  5788. function insertLineContent(line, builder, styles) {
  5789. var spans = line.markedSpans, allText = line.text, at = 0;
  5790. if (!spans) {
  5791. for (var i$1 = 1; i$1 < styles.length; i$1+=2)
  5792. { builder.addToken(builder, allText.slice(at, at = styles[i$1]), interpretTokenStyle(styles[i$1+1], builder.cm.options)); }
  5793. return
  5794. }
  5795. var len = allText.length, pos = 0, i = 1, text = "", style, css;
  5796. var nextChange = 0, spanStyle, spanEndStyle, spanStartStyle, collapsed, attributes;
  5797. for (;;) {
  5798. if (nextChange == pos) { // Update current marker set
  5799. spanStyle = spanEndStyle = spanStartStyle = css = "";
  5800. attributes = null;
  5801. collapsed = null; nextChange = Infinity;
  5802. var foundBookmarks = [], endStyles = (void 0);
  5803. for (var j = 0; j < spans.length; ++j) {
  5804. var sp = spans[j], m = sp.marker;
  5805. if (m.type == "bookmark" && sp.from == pos && m.widgetNode) {
  5806. foundBookmarks.push(m);
  5807. } else if (sp.from <= pos && (sp.to == null || sp.to > pos || m.collapsed && sp.to == pos && sp.from == pos)) {
  5808. if (sp.to != null && sp.to != pos && nextChange > sp.to) {
  5809. nextChange = sp.to;
  5810. spanEndStyle = "";
  5811. }
  5812. if (m.className) { spanStyle += " " + m.className; }
  5813. if (m.css) { css = (css ? css + ";" : "") + m.css; }
  5814. if (m.startStyle && sp.from == pos) { spanStartStyle += " " + m.startStyle; }
  5815. if (m.endStyle && sp.to == nextChange) { (endStyles || (endStyles = [])).push(m.endStyle, sp.to); }
  5816. // support for the old title property
  5817. // https://github.com/codemirror/CodeMirror/pull/5673
  5818. if (m.title) { (attributes || (attributes = {})).title = m.title; }
  5819. if (m.attributes) {
  5820. for (var attr in m.attributes)
  5821. { (attributes || (attributes = {}))[attr] = m.attributes[attr]; }
  5822. }
  5823. if (m.collapsed && (!collapsed || compareCollapsedMarkers(collapsed.marker, m) < 0))
  5824. { collapsed = sp; }
  5825. } else if (sp.from > pos && nextChange > sp.from) {
  5826. nextChange = sp.from;
  5827. }
  5828. }
  5829. if (endStyles) { for (var j$1 = 0; j$1 < endStyles.length; j$1 += 2)
  5830. { if (endStyles[j$1 + 1] == nextChange) { spanEndStyle += " " + endStyles[j$1]; } } }
  5831. if (!collapsed || collapsed.from == pos) { for (var j$2 = 0; j$2 < foundBookmarks.length; ++j$2)
  5832. { buildCollapsedSpan(builder, 0, foundBookmarks[j$2]); } }
  5833. if (collapsed && (collapsed.from || 0) == pos) {
  5834. buildCollapsedSpan(builder, (collapsed.to == null ? len + 1 : collapsed.to) - pos,
  5835. collapsed.marker, collapsed.from == null);
  5836. if (collapsed.to == null) { return }
  5837. if (collapsed.to == pos) { collapsed = false; }
  5838. }
  5839. }
  5840. if (pos >= len) { break }
  5841. var upto = Math.min(len, nextChange);
  5842. while (true) {
  5843. if (text) {
  5844. var end = pos + text.length;
  5845. if (!collapsed) {
  5846. var tokenText = end > upto ? text.slice(0, upto - pos) : text;
  5847. builder.addToken(builder, tokenText, style ? style + spanStyle : spanStyle,
  5848. spanStartStyle, pos + tokenText.length == nextChange ? spanEndStyle : "", css, attributes);
  5849. }
  5850. if (end >= upto) {text = text.slice(upto - pos); pos = upto; break}
  5851. pos = end;
  5852. spanStartStyle = "";
  5853. }
  5854. text = allText.slice(at, at = styles[i++]);
  5855. style = interpretTokenStyle(styles[i++], builder.cm.options);
  5856. }
  5857. }
  5858. }
  5859. // These objects are used to represent the visible (currently drawn)
  5860. // part of the document. A LineView may correspond to multiple
  5861. // logical lines, if those are connected by collapsed ranges.
  5862. function LineView(doc, line, lineN) {
  5863. // The starting line
  5864. this.line = line;
  5865. // Continuing lines, if any
  5866. this.rest = visualLineContinued(line);
  5867. // Number of logical lines in this visual line
  5868. this.size = this.rest ? lineNo(lst(this.rest)) - lineN + 1 : 1;
  5869. this.node = this.text = null;
  5870. this.hidden = lineIsHidden(doc, line);
  5871. }
  5872. // Create a range of LineView objects for the given lines.
  5873. function buildViewArray(cm, from, to) {
  5874. var array = [], nextPos;
  5875. for (var pos = from; pos < to; pos = nextPos) {
  5876. var view = new LineView(cm.doc, getLine(cm.doc, pos), pos);
  5877. nextPos = pos + view.size;
  5878. array.push(view);
  5879. }
  5880. return array
  5881. }
  5882. var operationGroup = null;
  5883. function pushOperation(op) {
  5884. if (operationGroup) {
  5885. operationGroup.ops.push(op);
  5886. } else {
  5887. op.ownsGroup = operationGroup = {
  5888. ops: [op],
  5889. delayedCallbacks: []
  5890. };
  5891. }
  5892. }
  5893. function fireCallbacksForOps(group) {
  5894. // Calls delayed callbacks and cursorActivity handlers until no
  5895. // new ones appear
  5896. var callbacks = group.delayedCallbacks, i = 0;
  5897. do {
  5898. for (; i < callbacks.length; i++)
  5899. { callbacks[i].call(null); }
  5900. for (var j = 0; j < group.ops.length; j++) {
  5901. var op = group.ops[j];
  5902. if (op.cursorActivityHandlers)
  5903. { while (op.cursorActivityCalled < op.cursorActivityHandlers.length)
  5904. { op.cursorActivityHandlers[op.cursorActivityCalled++].call(null, op.cm); } }
  5905. }
  5906. } while (i < callbacks.length)
  5907. }
  5908. function finishOperation(op, endCb) {
  5909. var group = op.ownsGroup;
  5910. if (!group) { return }
  5911. try { fireCallbacksForOps(group); }
  5912. finally {
  5913. operationGroup = null;
  5914. endCb(group);
  5915. }
  5916. }
  5917. var orphanDelayedCallbacks = null;
  5918. // Often, we want to signal events at a point where we are in the
  5919. // middle of some work, but don't want the handler to start calling
  5920. // other methods on the editor, which might be in an inconsistent
  5921. // state or simply not expect any other events to happen.
  5922. // signalLater looks whether there are any handlers, and schedules
  5923. // them to be executed when the last operation ends, or, if no
  5924. // operation is active, when a timeout fires.
  5925. function signalLater(emitter, type /*, values...*/) {
  5926. var arr = getHandlers(emitter, type);
  5927. if (!arr.length) { return }
  5928. var args = Array.prototype.slice.call(arguments, 2), list;
  5929. if (operationGroup) {
  5930. list = operationGroup.delayedCallbacks;
  5931. } else if (orphanDelayedCallbacks) {
  5932. list = orphanDelayedCallbacks;
  5933. } else {
  5934. list = orphanDelayedCallbacks = [];
  5935. setTimeout(fireOrphanDelayed, 0);
  5936. }
  5937. var loop = function ( i ) {
  5938. list.push(function () { return arr[i].apply(null, args); });
  5939. };
  5940. for (var i = 0; i < arr.length; ++i)
  5941. loop( i );
  5942. }
  5943. function fireOrphanDelayed() {
  5944. var delayed = orphanDelayedCallbacks;
  5945. orphanDelayedCallbacks = null;
  5946. for (var i = 0; i < delayed.length; ++i) { delayed[i](); }
  5947. }
  5948. // When an aspect of a line changes, a string is added to
  5949. // lineView.changes. This updates the relevant part of the line's
  5950. // DOM structure.
  5951. function updateLineForChanges(cm, lineView, lineN, dims) {
  5952. for (var j = 0; j < lineView.changes.length; j++) {
  5953. var type = lineView.changes[j];
  5954. if (type == "text") { updateLineText(cm, lineView); }
  5955. else if (type == "gutter") { updateLineGutter(cm, lineView, lineN, dims); }
  5956. else if (type == "class") { updateLineClasses(cm, lineView); }
  5957. else if (type == "widget") { updateLineWidgets(cm, lineView, dims); }
  5958. }
  5959. lineView.changes = null;
  5960. }
  5961. // Lines with gutter elements, widgets or a background class need to
  5962. // be wrapped, and have the extra elements added to the wrapper div
  5963. function ensureLineWrapped(lineView) {
  5964. if (lineView.node == lineView.text) {
  5965. lineView.node = elt("div", null, null, "position: relative");
  5966. if (lineView.text.parentNode)
  5967. { lineView.text.parentNode.replaceChild(lineView.node, lineView.text); }
  5968. lineView.node.appendChild(lineView.text);
  5969. if (ie && ie_version < 8) { lineView.node.style.zIndex = 2; }
  5970. }
  5971. return lineView.node
  5972. }
  5973. function updateLineBackground(cm, lineView) {
  5974. var cls = lineView.bgClass ? lineView.bgClass + " " + (lineView.line.bgClass || "") : lineView.line.bgClass;
  5975. if (cls) { cls += " CodeMirror-linebackground"; }
  5976. if (lineView.background) {
  5977. if (cls) { lineView.background.className = cls; }
  5978. else { lineView.background.parentNode.removeChild(lineView.background); lineView.background = null; }
  5979. } else if (cls) {
  5980. var wrap = ensureLineWrapped(lineView);
  5981. lineView.background = wrap.insertBefore(elt("div", null, cls), wrap.firstChild);
  5982. cm.display.input.setUneditable(lineView.background);
  5983. }
  5984. }
  5985. // Wrapper around buildLineContent which will reuse the structure
  5986. // in display.externalMeasured when possible.
  5987. function getLineContent(cm, lineView) {
  5988. var ext = cm.display.externalMeasured;
  5989. if (ext && ext.line == lineView.line) {
  5990. cm.display.externalMeasured = null;
  5991. lineView.measure = ext.measure;
  5992. return ext.built
  5993. }
  5994. return buildLineContent(cm, lineView)
  5995. }
  5996. // Redraw the line's text. Interacts with the background and text
  5997. // classes because the mode may output tokens that influence these
  5998. // classes.
  5999. function updateLineText(cm, lineView) {
  6000. var cls = lineView.text.className;
  6001. var built = getLineContent(cm, lineView);
  6002. if (lineView.text == lineView.node) { lineView.node = built.pre; }
  6003. lineView.text.parentNode.replaceChild(built.pre, lineView.text);
  6004. lineView.text = built.pre;
  6005. if (built.bgClass != lineView.bgClass || built.textClass != lineView.textClass) {
  6006. lineView.bgClass = built.bgClass;
  6007. lineView.textClass = built.textClass;
  6008. updateLineClasses(cm, lineView);
  6009. } else if (cls) {
  6010. lineView.text.className = cls;
  6011. }
  6012. }
  6013. function updateLineClasses(cm, lineView) {
  6014. updateLineBackground(cm, lineView);
  6015. if (lineView.line.wrapClass)
  6016. { ensureLineWrapped(lineView).className = lineView.line.wrapClass; }
  6017. else if (lineView.node != lineView.text)
  6018. { lineView.node.className = ""; }
  6019. var textClass = lineView.textClass ? lineView.textClass + " " + (lineView.line.textClass || "") : lineView.line.textClass;
  6020. lineView.text.className = textClass || "";
  6021. }
  6022. function updateLineGutter(cm, lineView, lineN, dims) {
  6023. if (lineView.gutter) {
  6024. lineView.node.removeChild(lineView.gutter);
  6025. lineView.gutter = null;
  6026. }
  6027. if (lineView.gutterBackground) {
  6028. lineView.node.removeChild(lineView.gutterBackground);
  6029. lineView.gutterBackground = null;
  6030. }
  6031. if (lineView.line.gutterClass) {
  6032. var wrap = ensureLineWrapped(lineView);
  6033. lineView.gutterBackground = elt("div", null, "CodeMirror-gutter-background " + lineView.line.gutterClass,
  6034. ("left: " + (cm.options.fixedGutter ? dims.fixedPos : -dims.gutterTotalWidth) + "px; width: " + (dims.gutterTotalWidth) + "px"));
  6035. cm.display.input.setUneditable(lineView.gutterBackground);
  6036. wrap.insertBefore(lineView.gutterBackground, lineView.text);
  6037. }
  6038. var markers = lineView.line.gutterMarkers;
  6039. if (cm.options.lineNumbers || markers) {
  6040. var wrap$1 = ensureLineWrapped(lineView);
  6041. var gutterWrap = lineView.gutter = elt("div", null, "CodeMirror-gutter-wrapper", ("left: " + (cm.options.fixedGutter ? dims.fixedPos : -dims.gutterTotalWidth) + "px"));
  6042. cm.display.input.setUneditable(gutterWrap);
  6043. wrap$1.insertBefore(gutterWrap, lineView.text);
  6044. if (lineView.line.gutterClass)
  6045. { gutterWrap.className += " " + lineView.line.gutterClass; }
  6046. if (cm.options.lineNumbers && (!markers || !markers["CodeMirror-linenumbers"]))
  6047. { lineView.lineNumber = gutterWrap.appendChild(
  6048. elt("div", lineNumberFor(cm.options, lineN),
  6049. "CodeMirror-linenumber CodeMirror-gutter-elt",
  6050. ("left: " + (dims.gutterLeft["CodeMirror-linenumbers"]) + "px; width: " + (cm.display.lineNumInnerWidth) + "px"))); }
  6051. if (markers) { for (var k = 0; k < cm.display.gutterSpecs.length; ++k) {
  6052. var id = cm.display.gutterSpecs[k].className, found = markers.hasOwnProperty(id) && markers[id];
  6053. if (found)
  6054. { gutterWrap.appendChild(elt("div", [found], "CodeMirror-gutter-elt",
  6055. ("left: " + (dims.gutterLeft[id]) + "px; width: " + (dims.gutterWidth[id]) + "px"))); }
  6056. } }
  6057. }
  6058. }
  6059. function updateLineWidgets(cm, lineView, dims) {
  6060. if (lineView.alignable) { lineView.alignable = null; }
  6061. for (var node = lineView.node.firstChild, next = (void 0); node; node = next) {
  6062. next = node.nextSibling;
  6063. if (node.className == "CodeMirror-linewidget")
  6064. { lineView.node.removeChild(node); }
  6065. }
  6066. insertLineWidgets(cm, lineView, dims);
  6067. }
  6068. // Build a line's DOM representation from scratch
  6069. function buildLineElement(cm, lineView, lineN, dims) {
  6070. var built = getLineContent(cm, lineView);
  6071. lineView.text = lineView.node = built.pre;
  6072. if (built.bgClass) { lineView.bgClass = built.bgClass; }
  6073. if (built.textClass) { lineView.textClass = built.textClass; }
  6074. updateLineClasses(cm, lineView);
  6075. updateLineGutter(cm, lineView, lineN, dims);
  6076. insertLineWidgets(cm, lineView, dims);
  6077. return lineView.node
  6078. }
  6079. // A lineView may contain multiple logical lines (when merged by
  6080. // collapsed spans). The widgets for all of them need to be drawn.
  6081. function insertLineWidgets(cm, lineView, dims) {
  6082. insertLineWidgetsFor(cm, lineView.line, lineView, dims, true);
  6083. if (lineView.rest) { for (var i = 0; i < lineView.rest.length; i++)
  6084. { insertLineWidgetsFor(cm, lineView.rest[i], lineView, dims, false); } }
  6085. }
  6086. function insertLineWidgetsFor(cm, line, lineView, dims, allowAbove) {
  6087. if (!line.widgets) { return }
  6088. var wrap = ensureLineWrapped(lineView);
  6089. for (var i = 0, ws = line.widgets; i < ws.length; ++i) {
  6090. var widget = ws[i], node = elt("div", [widget.node], "CodeMirror-linewidget");
  6091. if (!widget.handleMouseEvents) { node.setAttribute("cm-ignore-events", "true"); }
  6092. positionLineWidget(widget, node, lineView, dims);
  6093. cm.display.input.setUneditable(node);
  6094. if (allowAbove && widget.above)
  6095. { wrap.insertBefore(node, lineView.gutter || lineView.text); }
  6096. else
  6097. { wrap.appendChild(node); }
  6098. signalLater(widget, "redraw");
  6099. }
  6100. }
  6101. function positionLineWidget(widget, node, lineView, dims) {
  6102. if (widget.noHScroll) {
  6103. (lineView.alignable || (lineView.alignable = [])).push(node);
  6104. var width = dims.wrapperWidth;
  6105. node.style.left = dims.fixedPos + "px";
  6106. if (!widget.coverGutter) {
  6107. width -= dims.gutterTotalWidth;
  6108. node.style.paddingLeft = dims.gutterTotalWidth + "px";
  6109. }
  6110. node.style.width = width + "px";
  6111. }
  6112. if (widget.coverGutter) {
  6113. node.style.zIndex = 5;
  6114. node.style.position = "relative";
  6115. if (!widget.noHScroll) { node.style.marginLeft = -dims.gutterTotalWidth + "px"; }
  6116. }
  6117. }
  6118. function widgetHeight(widget) {
  6119. if (widget.height != null) { return widget.height }
  6120. var cm = widget.doc.cm;
  6121. if (!cm) { return 0 }
  6122. if (!contains(document.body, widget.node)) {
  6123. var parentStyle = "position: relative;";
  6124. if (widget.coverGutter)
  6125. { parentStyle += "margin-left: -" + cm.display.gutters.offsetWidth + "px;"; }
  6126. if (widget.noHScroll)
  6127. { parentStyle += "width: " + cm.display.wrapper.clientWidth + "px;"; }
  6128. removeChildrenAndAdd(cm.display.measure, elt("div", [widget.node], null, parentStyle));
  6129. }
  6130. return widget.height = widget.node.parentNode.offsetHeight
  6131. }
  6132. // Return true when the given mouse event happened in a widget
  6133. function eventInWidget(display, e) {
  6134. for (var n = e_target(e); n != display.wrapper; n = n.parentNode) {
  6135. if (!n || (n.nodeType == 1 && n.getAttribute("cm-ignore-events") == "true") ||
  6136. (n.parentNode == display.sizer && n != display.mover))
  6137. { return true }
  6138. }
  6139. }
  6140. // POSITION MEASUREMENT
  6141. function paddingTop(display) {return display.lineSpace.offsetTop}
  6142. function paddingVert(display) {return display.mover.offsetHeight - display.lineSpace.offsetHeight}
  6143. function paddingH(display) {
  6144. if (display.cachedPaddingH) { return display.cachedPaddingH }
  6145. var e = removeChildrenAndAdd(display.measure, elt("pre", "x", "CodeMirror-line-like"));
  6146. var style = window.getComputedStyle ? window.getComputedStyle(e) : e.currentStyle;
  6147. var data = {left: parseInt(style.paddingLeft), right: parseInt(style.paddingRight)};
  6148. if (!isNaN(data.left) && !isNaN(data.right)) { display.cachedPaddingH = data; }
  6149. return data
  6150. }
  6151. function scrollGap(cm) { return scrollerGap - cm.display.nativeBarWidth }
  6152. function displayWidth(cm) {
  6153. return cm.display.scroller.clientWidth - scrollGap(cm) - cm.display.barWidth
  6154. }
  6155. function displayHeight(cm) {
  6156. return cm.display.scroller.clientHeight - scrollGap(cm) - cm.display.barHeight
  6157. }
  6158. // Ensure the lineView.wrapping.heights array is populated. This is
  6159. // an array of bottom offsets for the lines that make up a drawn
  6160. // line. When lineWrapping is on, there might be more than one
  6161. // height.
  6162. function ensureLineHeights(cm, lineView, rect) {
  6163. var wrapping = cm.options.lineWrapping;
  6164. var curWidth = wrapping && displayWidth(cm);
  6165. if (!lineView.measure.heights || wrapping && lineView.measure.width != curWidth) {
  6166. var heights = lineView.measure.heights = [];
  6167. if (wrapping) {
  6168. lineView.measure.width = curWidth;
  6169. var rects = lineView.text.firstChild.getClientRects();
  6170. for (var i = 0; i < rects.length - 1; i++) {
  6171. var cur = rects[i], next = rects[i + 1];
  6172. if (Math.abs(cur.bottom - next.bottom) > 2)
  6173. { heights.push((cur.bottom + next.top) / 2 - rect.top); }
  6174. }
  6175. }
  6176. heights.push(rect.bottom - rect.top);
  6177. }
  6178. }
  6179. // Find a line map (mapping character offsets to text nodes) and a
  6180. // measurement cache for the given line number. (A line view might
  6181. // contain multiple lines when collapsed ranges are present.)
  6182. function mapFromLineView(lineView, line, lineN) {
  6183. if (lineView.line == line)
  6184. { return {map: lineView.measure.map, cache: lineView.measure.cache} }
  6185. for (var i = 0; i < lineView.rest.length; i++)
  6186. { if (lineView.rest[i] == line)
  6187. { return {map: lineView.measure.maps[i], cache: lineView.measure.caches[i]} } }
  6188. for (var i$1 = 0; i$1 < lineView.rest.length; i$1++)
  6189. { if (lineNo(lineView.rest[i$1]) > lineN)
  6190. { return {map: lineView.measure.maps[i$1], cache: lineView.measure.caches[i$1], before: true} } }
  6191. }
  6192. // Render a line into the hidden node display.externalMeasured. Used
  6193. // when measurement is needed for a line that's not in the viewport.
  6194. function updateExternalMeasurement(cm, line) {
  6195. line = visualLine(line);
  6196. var lineN = lineNo(line);
  6197. var view = cm.display.externalMeasured = new LineView(cm.doc, line, lineN);
  6198. view.lineN = lineN;
  6199. var built = view.built = buildLineContent(cm, view);
  6200. view.text = built.pre;
  6201. removeChildrenAndAdd(cm.display.lineMeasure, built.pre);
  6202. return view
  6203. }
  6204. // Get a {top, bottom, left, right} box (in line-local coordinates)
  6205. // for a given character.
  6206. function measureChar(cm, line, ch, bias) {
  6207. return measureCharPrepared(cm, prepareMeasureForLine(cm, line), ch, bias)
  6208. }
  6209. // Find a line view that corresponds to the given line number.
  6210. function findViewForLine(cm, lineN) {
  6211. if (lineN >= cm.display.viewFrom && lineN < cm.display.viewTo)
  6212. { return cm.display.view[findViewIndex(cm, lineN)] }
  6213. var ext = cm.display.externalMeasured;
  6214. if (ext && lineN >= ext.lineN && lineN < ext.lineN + ext.size)
  6215. { return ext }
  6216. }
  6217. // Measurement can be split in two steps, the set-up work that
  6218. // applies to the whole line, and the measurement of the actual
  6219. // character. Functions like coordsChar, that need to do a lot of
  6220. // measurements in a row, can thus ensure that the set-up work is
  6221. // only done once.
  6222. function prepareMeasureForLine(cm, line) {
  6223. var lineN = lineNo(line);
  6224. var view = findViewForLine(cm, lineN);
  6225. if (view && !view.text) {
  6226. view = null;
  6227. } else if (view && view.changes) {
  6228. updateLineForChanges(cm, view, lineN, getDimensions(cm));
  6229. cm.curOp.forceUpdate = true;
  6230. }
  6231. if (!view)
  6232. { view = updateExternalMeasurement(cm, line); }
  6233. var info = mapFromLineView(view, line, lineN);
  6234. return {
  6235. line: line, view: view, rect: null,
  6236. map: info.map, cache: info.cache, before: info.before,
  6237. hasHeights: false
  6238. }
  6239. }
  6240. // Given a prepared measurement object, measures the position of an
  6241. // actual character (or fetches it from the cache).
  6242. function measureCharPrepared(cm, prepared, ch, bias, varHeight) {
  6243. if (prepared.before) { ch = -1; }
  6244. var key = ch + (bias || ""), found;
  6245. if (prepared.cache.hasOwnProperty(key)) {
  6246. found = prepared.cache[key];
  6247. } else {
  6248. if (!prepared.rect)
  6249. { prepared.rect = prepared.view.text.getBoundingClientRect(); }
  6250. if (!prepared.hasHeights) {
  6251. ensureLineHeights(cm, prepared.view, prepared.rect);
  6252. prepared.hasHeights = true;
  6253. }
  6254. found = measureCharInner(cm, prepared, ch, bias);
  6255. if (!found.bogus) { prepared.cache[key] = found; }
  6256. }
  6257. return {left: found.left, right: found.right,
  6258. top: varHeight ? found.rtop : found.top,
  6259. bottom: varHeight ? found.rbottom : found.bottom}
  6260. }
  6261. var nullRect = {left: 0, right: 0, top: 0, bottom: 0};
  6262. function nodeAndOffsetInLineMap(map$$1, ch, bias) {
  6263. var node, start, end, collapse, mStart, mEnd;
  6264. // First, search the line map for the text node corresponding to,
  6265. // or closest to, the target character.
  6266. for (var i = 0; i < map$$1.length; i += 3) {
  6267. mStart = map$$1[i];
  6268. mEnd = map$$1[i + 1];
  6269. if (ch < mStart) {
  6270. start = 0; end = 1;
  6271. collapse = "left";
  6272. } else if (ch < mEnd) {
  6273. start = ch - mStart;
  6274. end = start + 1;
  6275. } else if (i == map$$1.length - 3 || ch == mEnd && map$$1[i + 3] > ch) {
  6276. end = mEnd - mStart;
  6277. start = end - 1;
  6278. if (ch >= mEnd) { collapse = "right"; }
  6279. }
  6280. if (start != null) {
  6281. node = map$$1[i + 2];
  6282. if (mStart == mEnd && bias == (node.insertLeft ? "left" : "right"))
  6283. { collapse = bias; }
  6284. if (bias == "left" && start == 0)
  6285. { while (i && map$$1[i - 2] == map$$1[i - 3] && map$$1[i - 1].insertLeft) {
  6286. node = map$$1[(i -= 3) + 2];
  6287. collapse = "left";
  6288. } }
  6289. if (bias == "right" && start == mEnd - mStart)
  6290. { while (i < map$$1.length - 3 && map$$1[i + 3] == map$$1[i + 4] && !map$$1[i + 5].insertLeft) {
  6291. node = map$$1[(i += 3) + 2];
  6292. collapse = "right";
  6293. } }
  6294. break
  6295. }
  6296. }
  6297. return {node: node, start: start, end: end, collapse: collapse, coverStart: mStart, coverEnd: mEnd}
  6298. }
  6299. function getUsefulRect(rects, bias) {
  6300. var rect = nullRect;
  6301. if (bias == "left") { for (var i = 0; i < rects.length; i++) {
  6302. if ((rect = rects[i]).left != rect.right) { break }
  6303. } } else { for (var i$1 = rects.length - 1; i$1 >= 0; i$1--) {
  6304. if ((rect = rects[i$1]).left != rect.right) { break }
  6305. } }
  6306. return rect
  6307. }
  6308. function measureCharInner(cm, prepared, ch, bias) {
  6309. var place = nodeAndOffsetInLineMap(prepared.map, ch, bias);
  6310. var node = place.node, start = place.start, end = place.end, collapse = place.collapse;
  6311. var rect;
  6312. if (node.nodeType == 3) { // If it is a text node, use a range to retrieve the coordinates.
  6313. for (var i$1 = 0; i$1 < 4; i$1++) { // Retry a maximum of 4 times when nonsense rectangles are returned
  6314. while (start && isExtendingChar(prepared.line.text.charAt(place.coverStart + start))) { --start; }
  6315. while (place.coverStart + end < place.coverEnd && isExtendingChar(prepared.line.text.charAt(place.coverStart + end))) { ++end; }
  6316. if (ie && ie_version < 9 && start == 0 && end == place.coverEnd - place.coverStart)
  6317. { rect = node.parentNode.getBoundingClientRect(); }
  6318. else
  6319. { rect = getUsefulRect(range(node, start, end).getClientRects(), bias); }
  6320. if (rect.left || rect.right || start == 0) { break }
  6321. end = start;
  6322. start = start - 1;
  6323. collapse = "right";
  6324. }
  6325. if (ie && ie_version < 11) { rect = maybeUpdateRectForZooming(cm.display.measure, rect); }
  6326. } else { // If it is a widget, simply get the box for the whole widget.
  6327. if (start > 0) { collapse = bias = "right"; }
  6328. var rects;
  6329. if (cm.options.lineWrapping && (rects = node.getClientRects()).length > 1)
  6330. { rect = rects[bias == "right" ? rects.length - 1 : 0]; }
  6331. else
  6332. { rect = node.getBoundingClientRect(); }
  6333. }
  6334. if (ie && ie_version < 9 && !start && (!rect || !rect.left && !rect.right)) {
  6335. var rSpan = node.parentNode.getClientRects()[0];
  6336. if (rSpan)
  6337. { rect = {left: rSpan.left, right: rSpan.left + charWidth(cm.display), top: rSpan.top, bottom: rSpan.bottom}; }
  6338. else
  6339. { rect = nullRect; }
  6340. }
  6341. var rtop = rect.top - prepared.rect.top, rbot = rect.bottom - prepared.rect.top;
  6342. var mid = (rtop + rbot) / 2;
  6343. var heights = prepared.view.measure.heights;
  6344. var i = 0;
  6345. for (; i < heights.length - 1; i++)
  6346. { if (mid < heights[i]) { break } }
  6347. var top = i ? heights[i - 1] : 0, bot = heights[i];
  6348. var result = {left: (collapse == "right" ? rect.right : rect.left) - prepared.rect.left,
  6349. right: (collapse == "left" ? rect.left : rect.right) - prepared.rect.left,
  6350. top: top, bottom: bot};
  6351. if (!rect.left && !rect.right) { result.bogus = true; }
  6352. if (!cm.options.singleCursorHeightPerLine) { result.rtop = rtop; result.rbottom = rbot; }
  6353. return result
  6354. }
  6355. // Work around problem with bounding client rects on ranges being
  6356. // returned incorrectly when zoomed on IE10 and below.
  6357. function maybeUpdateRectForZooming(measure, rect) {
  6358. if (!window.screen || screen.logicalXDPI == null ||
  6359. screen.logicalXDPI == screen.deviceXDPI || !hasBadZoomedRects(measure))
  6360. { return rect }
  6361. var scaleX = screen.logicalXDPI / screen.deviceXDPI;
  6362. var scaleY = screen.logicalYDPI / screen.deviceYDPI;
  6363. return {left: rect.left * scaleX, right: rect.right * scaleX,
  6364. top: rect.top * scaleY, bottom: rect.bottom * scaleY}
  6365. }
  6366. function clearLineMeasurementCacheFor(lineView) {
  6367. if (lineView.measure) {
  6368. lineView.measure.cache = {};
  6369. lineView.measure.heights = null;
  6370. if (lineView.rest) { for (var i = 0; i < lineView.rest.length; i++)
  6371. { lineView.measure.caches[i] = {}; } }
  6372. }
  6373. }
  6374. function clearLineMeasurementCache(cm) {
  6375. cm.display.externalMeasure = null;
  6376. removeChildren(cm.display.lineMeasure);
  6377. for (var i = 0; i < cm.display.view.length; i++)
  6378. { clearLineMeasurementCacheFor(cm.display.view[i]); }
  6379. }
  6380. function clearCaches(cm) {
  6381. clearLineMeasurementCache(cm);
  6382. cm.display.cachedCharWidth = cm.display.cachedTextHeight = cm.display.cachedPaddingH = null;
  6383. if (!cm.options.lineWrapping) { cm.display.maxLineChanged = true; }
  6384. cm.display.lineNumChars = null;
  6385. }
  6386. function pageScrollX() {
  6387. // Work around https://bugs.chromium.org/p/chromium/issues/detail?id=489206
  6388. // which causes page_Offset and bounding client rects to use
  6389. // different reference viewports and invalidate our calculations.
  6390. if (chrome && android) { return -(document.body.getBoundingClientRect().left - parseInt(getComputedStyle(document.body).marginLeft)) }
  6391. return window.pageXOffset || (document.documentElement || document.body).scrollLeft
  6392. }
  6393. function pageScrollY() {
  6394. if (chrome && android) { return -(document.body.getBoundingClientRect().top - parseInt(getComputedStyle(document.body).marginTop)) }
  6395. return window.pageYOffset || (document.documentElement || document.body).scrollTop
  6396. }
  6397. function widgetTopHeight(lineObj) {
  6398. var height = 0;
  6399. if (lineObj.widgets) { for (var i = 0; i < lineObj.widgets.length; ++i) { if (lineObj.widgets[i].above)
  6400. { height += widgetHeight(lineObj.widgets[i]); } } }
  6401. return height
  6402. }
  6403. // Converts a {top, bottom, left, right} box from line-local
  6404. // coordinates into another coordinate system. Context may be one of
  6405. // "line", "div" (display.lineDiv), "local"./null (editor), "window",
  6406. // or "page".
  6407. function intoCoordSystem(cm, lineObj, rect, context, includeWidgets) {
  6408. if (!includeWidgets) {
  6409. var height = widgetTopHeight(lineObj);
  6410. rect.top += height; rect.bottom += height;
  6411. }
  6412. if (context == "line") { return rect }
  6413. if (!context) { context = "local"; }
  6414. var yOff = heightAtLine(lineObj);
  6415. if (context == "local") { yOff += paddingTop(cm.display); }
  6416. else { yOff -= cm.display.viewOffset; }
  6417. if (context == "page" || context == "window") {
  6418. var lOff = cm.display.lineSpace.getBoundingClientRect();
  6419. yOff += lOff.top + (context == "window" ? 0 : pageScrollY());
  6420. var xOff = lOff.left + (context == "window" ? 0 : pageScrollX());
  6421. rect.left += xOff; rect.right += xOff;
  6422. }
  6423. rect.top += yOff; rect.bottom += yOff;
  6424. return rect
  6425. }
  6426. // Coverts a box from "div" coords to another coordinate system.
  6427. // Context may be "window", "page", "div", or "local"./null.
  6428. function fromCoordSystem(cm, coords, context) {
  6429. if (context == "div") { return coords }
  6430. var left = coords.left, top = coords.top;
  6431. // First move into "page" coordinate system
  6432. if (context == "page") {
  6433. left -= pageScrollX();
  6434. top -= pageScrollY();
  6435. } else if (context == "local" || !context) {
  6436. var localBox = cm.display.sizer.getBoundingClientRect();
  6437. left += localBox.left;
  6438. top += localBox.top;
  6439. }
  6440. var lineSpaceBox = cm.display.lineSpace.getBoundingClientRect();
  6441. return {left: left - lineSpaceBox.left, top: top - lineSpaceBox.top}
  6442. }
  6443. function charCoords(cm, pos, context, lineObj, bias) {
  6444. if (!lineObj) { lineObj = getLine(cm.doc, pos.line); }
  6445. return intoCoordSystem(cm, lineObj, measureChar(cm, lineObj, pos.ch, bias), context)
  6446. }
  6447. // Returns a box for a given cursor position, which may have an
  6448. // 'other' property containing the position of the secondary cursor
  6449. // on a bidi boundary.
  6450. // A cursor Pos(line, char, "before") is on the same visual line as `char - 1`
  6451. // and after `char - 1` in writing order of `char - 1`
  6452. // A cursor Pos(line, char, "after") is on the same visual line as `char`
  6453. // and before `char` in writing order of `char`
  6454. // Examples (upper-case letters are RTL, lower-case are LTR):
  6455. // Pos(0, 1, ...)
  6456. // before after
  6457. // ab a|b a|b
  6458. // aB a|B aB|
  6459. // Ab |Ab A|b
  6460. // AB B|A B|A
  6461. // Every position after the last character on a line is considered to stick
  6462. // to the last character on the line.
  6463. function cursorCoords(cm, pos, context, lineObj, preparedMeasure, varHeight) {
  6464. lineObj = lineObj || getLine(cm.doc, pos.line);
  6465. if (!preparedMeasure) { preparedMeasure = prepareMeasureForLine(cm, lineObj); }
  6466. function get(ch, right) {
  6467. var m = measureCharPrepared(cm, preparedMeasure, ch, right ? "right" : "left", varHeight);
  6468. if (right) { m.left = m.right; } else { m.right = m.left; }
  6469. return intoCoordSystem(cm, lineObj, m, context)
  6470. }
  6471. var order = getOrder(lineObj, cm.doc.direction), ch = pos.ch, sticky = pos.sticky;
  6472. if (ch >= lineObj.text.length) {
  6473. ch = lineObj.text.length;
  6474. sticky = "before";
  6475. } else if (ch <= 0) {
  6476. ch = 0;
  6477. sticky = "after";
  6478. }
  6479. if (!order) { return get(sticky == "before" ? ch - 1 : ch, sticky == "before") }
  6480. function getBidi(ch, partPos, invert) {
  6481. var part = order[partPos], right = part.level == 1;
  6482. return get(invert ? ch - 1 : ch, right != invert)
  6483. }
  6484. var partPos = getBidiPartAt(order, ch, sticky);
  6485. var other = bidiOther;
  6486. var val = getBidi(ch, partPos, sticky == "before");
  6487. if (other != null) { val.other = getBidi(ch, other, sticky != "before"); }
  6488. return val
  6489. }
  6490. // Used to cheaply estimate the coordinates for a position. Used for
  6491. // intermediate scroll updates.
  6492. function estimateCoords(cm, pos) {
  6493. var left = 0;
  6494. pos = clipPos(cm.doc, pos);
  6495. if (!cm.options.lineWrapping) { left = charWidth(cm.display) * pos.ch; }
  6496. var lineObj = getLine(cm.doc, pos.line);
  6497. var top = heightAtLine(lineObj) + paddingTop(cm.display);
  6498. return {left: left, right: left, top: top, bottom: top + lineObj.height}
  6499. }
  6500. // Positions returned by coordsChar contain some extra information.
  6501. // xRel is the relative x position of the input coordinates compared
  6502. // to the found position (so xRel > 0 means the coordinates are to
  6503. // the right of the character position, for example). When outside
  6504. // is true, that means the coordinates lie outside the line's
  6505. // vertical range.
  6506. function PosWithInfo(line, ch, sticky, outside, xRel) {
  6507. var pos = Pos(line, ch, sticky);
  6508. pos.xRel = xRel;
  6509. if (outside) { pos.outside = outside; }
  6510. return pos
  6511. }
  6512. // Compute the character position closest to the given coordinates.
  6513. // Input must be lineSpace-local ("div" coordinate system).
  6514. function coordsChar(cm, x, y) {
  6515. var doc = cm.doc;
  6516. y += cm.display.viewOffset;
  6517. if (y < 0) { return PosWithInfo(doc.first, 0, null, -1, -1) }
  6518. var lineN = lineAtHeight(doc, y), last = doc.first + doc.size - 1;
  6519. if (lineN > last)
  6520. { return PosWithInfo(doc.first + doc.size - 1, getLine(doc, last).text.length, null, 1, 1) }
  6521. if (x < 0) { x = 0; }
  6522. var lineObj = getLine(doc, lineN);
  6523. for (;;) {
  6524. var found = coordsCharInner(cm, lineObj, lineN, x, y);
  6525. var collapsed = collapsedSpanAround(lineObj, found.ch + (found.xRel > 0 || found.outside > 0 ? 1 : 0));
  6526. if (!collapsed) { return found }
  6527. var rangeEnd = collapsed.find(1);
  6528. if (rangeEnd.line == lineN) { return rangeEnd }
  6529. lineObj = getLine(doc, lineN = rangeEnd.line);
  6530. }
  6531. }
  6532. function wrappedLineExtent(cm, lineObj, preparedMeasure, y) {
  6533. y -= widgetTopHeight(lineObj);
  6534. var end = lineObj.text.length;
  6535. var begin = findFirst(function (ch) { return measureCharPrepared(cm, preparedMeasure, ch - 1).bottom <= y; }, end, 0);
  6536. end = findFirst(function (ch) { return measureCharPrepared(cm, preparedMeasure, ch).top > y; }, begin, end);
  6537. return {begin: begin, end: end}
  6538. }
  6539. function wrappedLineExtentChar(cm, lineObj, preparedMeasure, target) {
  6540. if (!preparedMeasure) { preparedMeasure = prepareMeasureForLine(cm, lineObj); }
  6541. var targetTop = intoCoordSystem(cm, lineObj, measureCharPrepared(cm, preparedMeasure, target), "line").top;
  6542. return wrappedLineExtent(cm, lineObj, preparedMeasure, targetTop)
  6543. }
  6544. // Returns true if the given side of a box is after the given
  6545. // coordinates, in top-to-bottom, left-to-right order.
  6546. function boxIsAfter(box, x, y, left) {
  6547. return box.bottom <= y ? false : box.top > y ? true : (left ? box.left : box.right) > x
  6548. }
  6549. function coordsCharInner(cm, lineObj, lineNo$$1, x, y) {
  6550. // Move y into line-local coordinate space
  6551. y -= heightAtLine(lineObj);
  6552. var preparedMeasure = prepareMeasureForLine(cm, lineObj);
  6553. // When directly calling `measureCharPrepared`, we have to adjust
  6554. // for the widgets at this line.
  6555. var widgetHeight$$1 = widgetTopHeight(lineObj);
  6556. var begin = 0, end = lineObj.text.length, ltr = true;
  6557. var order = getOrder(lineObj, cm.doc.direction);
  6558. // If the line isn't plain left-to-right text, first figure out
  6559. // which bidi section the coordinates fall into.
  6560. if (order) {
  6561. var part = (cm.options.lineWrapping ? coordsBidiPartWrapped : coordsBidiPart)
  6562. (cm, lineObj, lineNo$$1, preparedMeasure, order, x, y);
  6563. ltr = part.level != 1;
  6564. // The awkward -1 offsets are needed because findFirst (called
  6565. // on these below) will treat its first bound as inclusive,
  6566. // second as exclusive, but we want to actually address the
  6567. // characters in the part's range
  6568. begin = ltr ? part.from : part.to - 1;
  6569. end = ltr ? part.to : part.from - 1;
  6570. }
  6571. // A binary search to find the first character whose bounding box
  6572. // starts after the coordinates. If we run across any whose box wrap
  6573. // the coordinates, store that.
  6574. var chAround = null, boxAround = null;
  6575. var ch = findFirst(function (ch) {
  6576. var box = measureCharPrepared(cm, preparedMeasure, ch);
  6577. box.top += widgetHeight$$1; box.bottom += widgetHeight$$1;
  6578. if (!boxIsAfter(box, x, y, false)) { return false }
  6579. if (box.top <= y && box.left <= x) {
  6580. chAround = ch;
  6581. boxAround = box;
  6582. }
  6583. return true
  6584. }, begin, end);
  6585. var baseX, sticky, outside = false;
  6586. // If a box around the coordinates was found, use that
  6587. if (boxAround) {
  6588. // Distinguish coordinates nearer to the left or right side of the box
  6589. var atLeft = x - boxAround.left < boxAround.right - x, atStart = atLeft == ltr;
  6590. ch = chAround + (atStart ? 0 : 1);
  6591. sticky = atStart ? "after" : "before";
  6592. baseX = atLeft ? boxAround.left : boxAround.right;
  6593. } else {
  6594. // (Adjust for extended bound, if necessary.)
  6595. if (!ltr && (ch == end || ch == begin)) { ch++; }
  6596. // To determine which side to associate with, get the box to the
  6597. // left of the character and compare it's vertical position to the
  6598. // coordinates
  6599. sticky = ch == 0 ? "after" : ch == lineObj.text.length ? "before" :
  6600. (measureCharPrepared(cm, preparedMeasure, ch - (ltr ? 1 : 0)).bottom + widgetHeight$$1 <= y) == ltr ?
  6601. "after" : "before";
  6602. // Now get accurate coordinates for this place, in order to get a
  6603. // base X position
  6604. var coords = cursorCoords(cm, Pos(lineNo$$1, ch, sticky), "line", lineObj, preparedMeasure);
  6605. baseX = coords.left;
  6606. outside = y < coords.top ? -1 : y >= coords.bottom ? 1 : 0;
  6607. }
  6608. ch = skipExtendingChars(lineObj.text, ch, 1);
  6609. return PosWithInfo(lineNo$$1, ch, sticky, outside, x - baseX)
  6610. }
  6611. function coordsBidiPart(cm, lineObj, lineNo$$1, preparedMeasure, order, x, y) {
  6612. // Bidi parts are sorted left-to-right, and in a non-line-wrapping
  6613. // situation, we can take this ordering to correspond to the visual
  6614. // ordering. This finds the first part whose end is after the given
  6615. // coordinates.
  6616. var index = findFirst(function (i) {
  6617. var part = order[i], ltr = part.level != 1;
  6618. return boxIsAfter(cursorCoords(cm, Pos(lineNo$$1, ltr ? part.to : part.from, ltr ? "before" : "after"),
  6619. "line", lineObj, preparedMeasure), x, y, true)
  6620. }, 0, order.length - 1);
  6621. var part = order[index];
  6622. // If this isn't the first part, the part's start is also after
  6623. // the coordinates, and the coordinates aren't on the same line as
  6624. // that start, move one part back.
  6625. if (index > 0) {
  6626. var ltr = part.level != 1;
  6627. var start = cursorCoords(cm, Pos(lineNo$$1, ltr ? part.from : part.to, ltr ? "after" : "before"),
  6628. "line", lineObj, preparedMeasure);
  6629. if (boxIsAfter(start, x, y, true) && start.top > y)
  6630. { part = order[index - 1]; }
  6631. }
  6632. return part
  6633. }
  6634. function coordsBidiPartWrapped(cm, lineObj, _lineNo, preparedMeasure, order, x, y) {
  6635. // In a wrapped line, rtl text on wrapping boundaries can do things
  6636. // that don't correspond to the ordering in our `order` array at
  6637. // all, so a binary search doesn't work, and we want to return a
  6638. // part that only spans one line so that the binary search in
  6639. // coordsCharInner is safe. As such, we first find the extent of the
  6640. // wrapped line, and then do a flat search in which we discard any
  6641. // spans that aren't on the line.
  6642. var ref = wrappedLineExtent(cm, lineObj, preparedMeasure, y);
  6643. var begin = ref.begin;
  6644. var end = ref.end;
  6645. if (/\s/.test(lineObj.text.charAt(end - 1))) { end--; }
  6646. var part = null, closestDist = null;
  6647. for (var i = 0; i < order.length; i++) {
  6648. var p = order[i];
  6649. if (p.from >= end || p.to <= begin) { continue }
  6650. var ltr = p.level != 1;
  6651. var endX = measureCharPrepared(cm, preparedMeasure, ltr ? Math.min(end, p.to) - 1 : Math.max(begin, p.from)).right;
  6652. // Weigh against spans ending before this, so that they are only
  6653. // picked if nothing ends after
  6654. var dist = endX < x ? x - endX + 1e9 : endX - x;
  6655. if (!part || closestDist > dist) {
  6656. part = p;
  6657. closestDist = dist;
  6658. }
  6659. }
  6660. if (!part) { part = order[order.length - 1]; }
  6661. // Clip the part to the wrapped line.
  6662. if (part.from < begin) { part = {from: begin, to: part.to, level: part.level}; }
  6663. if (part.to > end) { part = {from: part.from, to: end, level: part.level}; }
  6664. return part
  6665. }
  6666. var measureText;
  6667. // Compute the default text height.
  6668. function textHeight(display) {
  6669. if (display.cachedTextHeight != null) { return display.cachedTextHeight }
  6670. if (measureText == null) {
  6671. measureText = elt("pre", null, "CodeMirror-line-like");
  6672. // Measure a bunch of lines, for browsers that compute
  6673. // fractional heights.
  6674. for (var i = 0; i < 49; ++i) {
  6675. measureText.appendChild(document.createTextNode("x"));
  6676. measureText.appendChild(elt("br"));
  6677. }
  6678. measureText.appendChild(document.createTextNode("x"));
  6679. }
  6680. removeChildrenAndAdd(display.measure, measureText);
  6681. var height = measureText.offsetHeight / 50;
  6682. if (height > 3) { display.cachedTextHeight = height; }
  6683. removeChildren(display.measure);
  6684. return height || 1
  6685. }
  6686. // Compute the default character width.
  6687. function charWidth(display) {
  6688. if (display.cachedCharWidth != null) { return display.cachedCharWidth }
  6689. var anchor = elt("span", "xxxxxxxxxx");
  6690. var pre = elt("pre", [anchor], "CodeMirror-line-like");
  6691. removeChildrenAndAdd(display.measure, pre);
  6692. var rect = anchor.getBoundingClientRect(), width = (rect.right - rect.left) / 10;
  6693. if (width > 2) { display.cachedCharWidth = width; }
  6694. return width || 10
  6695. }
  6696. // Do a bulk-read of the DOM positions and sizes needed to draw the
  6697. // view, so that we don't interleave reading and writing to the DOM.
  6698. function getDimensions(cm) {
  6699. var d = cm.display, left = {}, width = {};
  6700. var gutterLeft = d.gutters.clientLeft;
  6701. for (var n = d.gutters.firstChild, i = 0; n; n = n.nextSibling, ++i) {
  6702. var id = cm.display.gutterSpecs[i].className;
  6703. left[id] = n.offsetLeft + n.clientLeft + gutterLeft;
  6704. width[id] = n.clientWidth;
  6705. }
  6706. return {fixedPos: compensateForHScroll(d),
  6707. gutterTotalWidth: d.gutters.offsetWidth,
  6708. gutterLeft: left,
  6709. gutterWidth: width,
  6710. wrapperWidth: d.wrapper.clientWidth}
  6711. }
  6712. // Computes display.scroller.scrollLeft + display.gutters.offsetWidth,
  6713. // but using getBoundingClientRect to get a sub-pixel-accurate
  6714. // result.
  6715. function compensateForHScroll(display) {
  6716. return display.scroller.getBoundingClientRect().left - display.sizer.getBoundingClientRect().left
  6717. }
  6718. // Returns a function that estimates the height of a line, to use as
  6719. // first approximation until the line becomes visible (and is thus
  6720. // properly measurable).
  6721. function estimateHeight(cm) {
  6722. var th = textHeight(cm.display), wrapping = cm.options.lineWrapping;
  6723. var perLine = wrapping && Math.max(5, cm.display.scroller.clientWidth / charWidth(cm.display) - 3);
  6724. return function (line) {
  6725. if (lineIsHidden(cm.doc, line)) { return 0 }
  6726. var widgetsHeight = 0;
  6727. if (line.widgets) { for (var i = 0; i < line.widgets.length; i++) {
  6728. if (line.widgets[i].height) { widgetsHeight += line.widgets[i].height; }
  6729. } }
  6730. if (wrapping)
  6731. { return widgetsHeight + (Math.ceil(line.text.length / perLine) || 1) * th }
  6732. else
  6733. { return widgetsHeight + th }
  6734. }
  6735. }
  6736. function estimateLineHeights(cm) {
  6737. var doc = cm.doc, est = estimateHeight(cm);
  6738. doc.iter(function (line) {
  6739. var estHeight = est(line);
  6740. if (estHeight != line.height) { updateLineHeight(line, estHeight); }
  6741. });
  6742. }
  6743. // Given a mouse event, find the corresponding position. If liberal
  6744. // is false, it checks whether a gutter or scrollbar was clicked,
  6745. // and returns null if it was. forRect is used by rectangular
  6746. // selections, and tries to estimate a character position even for
  6747. // coordinates beyond the right of the text.
  6748. function posFromMouse(cm, e, liberal, forRect) {
  6749. var display = cm.display;
  6750. if (!liberal && e_target(e).getAttribute("cm-not-content") == "true") { return null }
  6751. var x, y, space = display.lineSpace.getBoundingClientRect();
  6752. // Fails unpredictably on IE[67] when mouse is dragged around quickly.
  6753. try { x = e.clientX - space.left; y = e.clientY - space.top; }
  6754. catch (e) { return null }
  6755. var coords = coordsChar(cm, x, y), line;
  6756. if (forRect && coords.xRel == 1 && (line = getLine(cm.doc, coords.line).text).length == coords.ch) {
  6757. var colDiff = countColumn(line, line.length, cm.options.tabSize) - line.length;
  6758. coords = Pos(coords.line, Math.max(0, Math.round((x - paddingH(cm.display).left) / charWidth(cm.display)) - colDiff));
  6759. }
  6760. return coords
  6761. }
  6762. // Find the view element corresponding to a given line. Return null
  6763. // when the line isn't visible.
  6764. function findViewIndex(cm, n) {
  6765. if (n >= cm.display.viewTo) { return null }
  6766. n -= cm.display.viewFrom;
  6767. if (n < 0) { return null }
  6768. var view = cm.display.view;
  6769. for (var i = 0; i < view.length; i++) {
  6770. n -= view[i].size;
  6771. if (n < 0) { return i }
  6772. }
  6773. }
  6774. // Updates the display.view data structure for a given change to the
  6775. // document. From and to are in pre-change coordinates. Lendiff is
  6776. // the amount of lines added or subtracted by the change. This is
  6777. // used for changes that span multiple lines, or change the way
  6778. // lines are divided into visual lines. regLineChange (below)
  6779. // registers single-line changes.
  6780. function regChange(cm, from, to, lendiff) {
  6781. if (from == null) { from = cm.doc.first; }
  6782. if (to == null) { to = cm.doc.first + cm.doc.size; }
  6783. if (!lendiff) { lendiff = 0; }
  6784. var display = cm.display;
  6785. if (lendiff && to < display.viewTo &&
  6786. (display.updateLineNumbers == null || display.updateLineNumbers > from))
  6787. { display.updateLineNumbers = from; }
  6788. cm.curOp.viewChanged = true;
  6789. if (from >= display.viewTo) { // Change after
  6790. if (sawCollapsedSpans && visualLineNo(cm.doc, from) < display.viewTo)
  6791. { resetView(cm); }
  6792. } else if (to <= display.viewFrom) { // Change before
  6793. if (sawCollapsedSpans && visualLineEndNo(cm.doc, to + lendiff) > display.viewFrom) {
  6794. resetView(cm);
  6795. } else {
  6796. display.viewFrom += lendiff;
  6797. display.viewTo += lendiff;
  6798. }
  6799. } else if (from <= display.viewFrom && to >= display.viewTo) { // Full overlap
  6800. resetView(cm);
  6801. } else if (from <= display.viewFrom) { // Top overlap
  6802. var cut = viewCuttingPoint(cm, to, to + lendiff, 1);
  6803. if (cut) {
  6804. display.view = display.view.slice(cut.index);
  6805. display.viewFrom = cut.lineN;
  6806. display.viewTo += lendiff;
  6807. } else {
  6808. resetView(cm);
  6809. }
  6810. } else if (to >= display.viewTo) { // Bottom overlap
  6811. var cut$1 = viewCuttingPoint(cm, from, from, -1);
  6812. if (cut$1) {
  6813. display.view = display.view.slice(0, cut$1.index);
  6814. display.viewTo = cut$1.lineN;
  6815. } else {
  6816. resetView(cm);
  6817. }
  6818. } else { // Gap in the middle
  6819. var cutTop = viewCuttingPoint(cm, from, from, -1);
  6820. var cutBot = viewCuttingPoint(cm, to, to + lendiff, 1);
  6821. if (cutTop && cutBot) {
  6822. display.view = display.view.slice(0, cutTop.index)
  6823. .concat(buildViewArray(cm, cutTop.lineN, cutBot.lineN))
  6824. .concat(display.view.slice(cutBot.index));
  6825. display.viewTo += lendiff;
  6826. } else {
  6827. resetView(cm);
  6828. }
  6829. }
  6830. var ext = display.externalMeasured;
  6831. if (ext) {
  6832. if (to < ext.lineN)
  6833. { ext.lineN += lendiff; }
  6834. else if (from < ext.lineN + ext.size)
  6835. { display.externalMeasured = null; }
  6836. }
  6837. }
  6838. // Register a change to a single line. Type must be one of "text",
  6839. // "gutter", "class", "widget"
  6840. function regLineChange(cm, line, type) {
  6841. cm.curOp.viewChanged = true;
  6842. var display = cm.display, ext = cm.display.externalMeasured;
  6843. if (ext && line >= ext.lineN && line < ext.lineN + ext.size)
  6844. { display.externalMeasured = null; }
  6845. if (line < display.viewFrom || line >= display.viewTo) { return }
  6846. var lineView = display.view[findViewIndex(cm, line)];
  6847. if (lineView.node == null) { return }
  6848. var arr = lineView.changes || (lineView.changes = []);
  6849. if (indexOf(arr, type) == -1) { arr.push(type); }
  6850. }
  6851. // Clear the view.
  6852. function resetView(cm) {
  6853. cm.display.viewFrom = cm.display.viewTo = cm.doc.first;
  6854. cm.display.view = [];
  6855. cm.display.viewOffset = 0;
  6856. }
  6857. function viewCuttingPoint(cm, oldN, newN, dir) {
  6858. var index = findViewIndex(cm, oldN), diff, view = cm.display.view;
  6859. if (!sawCollapsedSpans || newN == cm.doc.first + cm.doc.size)
  6860. { return {index: index, lineN: newN} }
  6861. var n = cm.display.viewFrom;
  6862. for (var i = 0; i < index; i++)
  6863. { n += view[i].size; }
  6864. if (n != oldN) {
  6865. if (dir > 0) {
  6866. if (index == view.length - 1) { return null }
  6867. diff = (n + view[index].size) - oldN;
  6868. index++;
  6869. } else {
  6870. diff = n - oldN;
  6871. }
  6872. oldN += diff; newN += diff;
  6873. }
  6874. while (visualLineNo(cm.doc, newN) != newN) {
  6875. if (index == (dir < 0 ? 0 : view.length - 1)) { return null }
  6876. newN += dir * view[index - (dir < 0 ? 1 : 0)].size;
  6877. index += dir;
  6878. }
  6879. return {index: index, lineN: newN}
  6880. }
  6881. // Force the view to cover a given range, adding empty view element
  6882. // or clipping off existing ones as needed.
  6883. function adjustView(cm, from, to) {
  6884. var display = cm.display, view = display.view;
  6885. if (view.length == 0 || from >= display.viewTo || to <= display.viewFrom) {
  6886. display.view = buildViewArray(cm, from, to);
  6887. display.viewFrom = from;
  6888. } else {
  6889. if (display.viewFrom > from)
  6890. { display.view = buildViewArray(cm, from, display.viewFrom).concat(display.view); }
  6891. else if (display.viewFrom < from)
  6892. { display.view = display.view.slice(findViewIndex(cm, from)); }
  6893. display.viewFrom = from;
  6894. if (display.viewTo < to)
  6895. { display.view = display.view.concat(buildViewArray(cm, display.viewTo, to)); }
  6896. else if (display.viewTo > to)
  6897. { display.view = display.view.slice(0, findViewIndex(cm, to)); }
  6898. }
  6899. display.viewTo = to;
  6900. }
  6901. // Count the number of lines in the view whose DOM representation is
  6902. // out of date (or nonexistent).
  6903. function countDirtyView(cm) {
  6904. var view = cm.display.view, dirty = 0;
  6905. for (var i = 0; i < view.length; i++) {
  6906. var lineView = view[i];
  6907. if (!lineView.hidden && (!lineView.node || lineView.changes)) { ++dirty; }
  6908. }
  6909. return dirty
  6910. }
  6911. function updateSelection(cm) {
  6912. cm.display.input.showSelection(cm.display.input.prepareSelection());
  6913. }
  6914. function prepareSelection(cm, primary) {
  6915. if ( primary === void 0 ) primary = true;
  6916. var doc = cm.doc, result = {};
  6917. var curFragment = result.cursors = document.createDocumentFragment();
  6918. var selFragment = result.selection = document.createDocumentFragment();
  6919. for (var i = 0; i < doc.sel.ranges.length; i++) {
  6920. if (!primary && i == doc.sel.primIndex) { continue }
  6921. var range$$1 = doc.sel.ranges[i];
  6922. if (range$$1.from().line >= cm.display.viewTo || range$$1.to().line < cm.display.viewFrom) { continue }
  6923. var collapsed = range$$1.empty();
  6924. if (collapsed || cm.options.showCursorWhenSelecting)
  6925. { drawSelectionCursor(cm, range$$1.head, curFragment); }
  6926. if (!collapsed)
  6927. { drawSelectionRange(cm, range$$1, selFragment); }
  6928. }
  6929. return result
  6930. }
  6931. // Draws a cursor for the given range
  6932. function drawSelectionCursor(cm, head, output) {
  6933. var pos = cursorCoords(cm, head, "div", null, null, !cm.options.singleCursorHeightPerLine);
  6934. var cursor = output.appendChild(elt("div", "\u00a0", "CodeMirror-cursor"));
  6935. cursor.style.left = pos.left + "px";
  6936. cursor.style.top = pos.top + "px";
  6937. cursor.style.height = Math.max(0, pos.bottom - pos.top) * cm.options.cursorHeight + "px";
  6938. if (pos.other) {
  6939. // Secondary cursor, shown when on a 'jump' in bi-directional text
  6940. var otherCursor = output.appendChild(elt("div", "\u00a0", "CodeMirror-cursor CodeMirror-secondarycursor"));
  6941. otherCursor.style.display = "";
  6942. otherCursor.style.left = pos.other.left + "px";
  6943. otherCursor.style.top = pos.other.top + "px";
  6944. otherCursor.style.height = (pos.other.bottom - pos.other.top) * .85 + "px";
  6945. }
  6946. }
  6947. function cmpCoords(a, b) { return a.top - b.top || a.left - b.left }
  6948. // Draws the given range as a highlighted selection
  6949. function drawSelectionRange(cm, range$$1, output) {
  6950. var display = cm.display, doc = cm.doc;
  6951. var fragment = document.createDocumentFragment();
  6952. var padding = paddingH(cm.display), leftSide = padding.left;
  6953. var rightSide = Math.max(display.sizerWidth, displayWidth(cm) - display.sizer.offsetLeft) - padding.right;
  6954. var docLTR = doc.direction == "ltr";
  6955. function add(left, top, width, bottom) {
  6956. if (top < 0) { top = 0; }
  6957. top = Math.round(top);
  6958. bottom = Math.round(bottom);
  6959. fragment.appendChild(elt("div", null, "CodeMirror-selected", ("position: absolute; left: " + left + "px;\n top: " + top + "px; width: " + (width == null ? rightSide - left : width) + "px;\n height: " + (bottom - top) + "px")));
  6960. }
  6961. function drawForLine(line, fromArg, toArg) {
  6962. var lineObj = getLine(doc, line);
  6963. var lineLen = lineObj.text.length;
  6964. var start, end;
  6965. function coords(ch, bias) {
  6966. return charCoords(cm, Pos(line, ch), "div", lineObj, bias)
  6967. }
  6968. function wrapX(pos, dir, side) {
  6969. var extent = wrappedLineExtentChar(cm, lineObj, null, pos);
  6970. var prop = (dir == "ltr") == (side == "after") ? "left" : "right";
  6971. var ch = side == "after" ? extent.begin : extent.end - (/\s/.test(lineObj.text.charAt(extent.end - 1)) ? 2 : 1);
  6972. return coords(ch, prop)[prop]
  6973. }
  6974. var order = getOrder(lineObj, doc.direction);
  6975. iterateBidiSections(order, fromArg || 0, toArg == null ? lineLen : toArg, function (from, to, dir, i) {
  6976. var ltr = dir == "ltr";
  6977. var fromPos = coords(from, ltr ? "left" : "right");
  6978. var toPos = coords(to - 1, ltr ? "right" : "left");
  6979. var openStart = fromArg == null && from == 0, openEnd = toArg == null && to == lineLen;
  6980. var first = i == 0, last = !order || i == order.length - 1;
  6981. if (toPos.top - fromPos.top <= 3) { // Single line
  6982. var openLeft = (docLTR ? openStart : openEnd) && first;
  6983. var openRight = (docLTR ? openEnd : openStart) && last;
  6984. var left = openLeft ? leftSide : (ltr ? fromPos : toPos).left;
  6985. var right = openRight ? rightSide : (ltr ? toPos : fromPos).right;
  6986. add(left, fromPos.top, right - left, fromPos.bottom);
  6987. } else { // Multiple lines
  6988. var topLeft, topRight, botLeft, botRight;
  6989. if (ltr) {
  6990. topLeft = docLTR && openStart && first ? leftSide : fromPos.left;
  6991. topRight = docLTR ? rightSide : wrapX(from, dir, "before");
  6992. botLeft = docLTR ? leftSide : wrapX(to, dir, "after");
  6993. botRight = docLTR && openEnd && last ? rightSide : toPos.right;
  6994. } else {
  6995. topLeft = !docLTR ? leftSide : wrapX(from, dir, "before");
  6996. topRight = !docLTR && openStart && first ? rightSide : fromPos.right;
  6997. botLeft = !docLTR && openEnd && last ? leftSide : toPos.left;
  6998. botRight = !docLTR ? rightSide : wrapX(to, dir, "after");
  6999. }
  7000. add(topLeft, fromPos.top, topRight - topLeft, fromPos.bottom);
  7001. if (fromPos.bottom < toPos.top) { add(leftSide, fromPos.bottom, null, toPos.top); }
  7002. add(botLeft, toPos.top, botRight - botLeft, toPos.bottom);
  7003. }
  7004. if (!start || cmpCoords(fromPos, start) < 0) { start = fromPos; }
  7005. if (cmpCoords(toPos, start) < 0) { start = toPos; }
  7006. if (!end || cmpCoords(fromPos, end) < 0) { end = fromPos; }
  7007. if (cmpCoords(toPos, end) < 0) { end = toPos; }
  7008. });
  7009. return {start: start, end: end}
  7010. }
  7011. var sFrom = range$$1.from(), sTo = range$$1.to();
  7012. if (sFrom.line == sTo.line) {
  7013. drawForLine(sFrom.line, sFrom.ch, sTo.ch);
  7014. } else {
  7015. var fromLine = getLine(doc, sFrom.line), toLine = getLine(doc, sTo.line);
  7016. var singleVLine = visualLine(fromLine) == visualLine(toLine);
  7017. var leftEnd = drawForLine(sFrom.line, sFrom.ch, singleVLine ? fromLine.text.length + 1 : null).end;
  7018. var rightStart = drawForLine(sTo.line, singleVLine ? 0 : null, sTo.ch).start;
  7019. if (singleVLine) {
  7020. if (leftEnd.top < rightStart.top - 2) {
  7021. add(leftEnd.right, leftEnd.top, null, leftEnd.bottom);
  7022. add(leftSide, rightStart.top, rightStart.left, rightStart.bottom);
  7023. } else {
  7024. add(leftEnd.right, leftEnd.top, rightStart.left - leftEnd.right, leftEnd.bottom);
  7025. }
  7026. }
  7027. if (leftEnd.bottom < rightStart.top)
  7028. { add(leftSide, leftEnd.bottom, null, rightStart.top); }
  7029. }
  7030. output.appendChild(fragment);
  7031. }
  7032. // Cursor-blinking
  7033. function restartBlink(cm) {
  7034. if (!cm.state.focused) { return }
  7035. var display = cm.display;
  7036. clearInterval(display.blinker);
  7037. var on = true;
  7038. display.cursorDiv.style.visibility = "";
  7039. if (cm.options.cursorBlinkRate > 0)
  7040. { display.blinker = setInterval(function () { return display.cursorDiv.style.visibility = (on = !on) ? "" : "hidden"; },
  7041. cm.options.cursorBlinkRate); }
  7042. else if (cm.options.cursorBlinkRate < 0)
  7043. { display.cursorDiv.style.visibility = "hidden"; }
  7044. }
  7045. function ensureFocus(cm) {
  7046. if (!cm.state.focused) { cm.display.input.focus(); onFocus(cm); }
  7047. }
  7048. function delayBlurEvent(cm) {
  7049. cm.state.delayingBlurEvent = true;
  7050. setTimeout(function () { if (cm.state.delayingBlurEvent) {
  7051. cm.state.delayingBlurEvent = false;
  7052. onBlur(cm);
  7053. } }, 100);
  7054. }
  7055. function onFocus(cm, e) {
  7056. if (cm.state.delayingBlurEvent) { cm.state.delayingBlurEvent = false; }
  7057. if (cm.options.readOnly == "nocursor") { return }
  7058. if (!cm.state.focused) {
  7059. signal(cm, "focus", cm, e);
  7060. cm.state.focused = true;
  7061. addClass(cm.display.wrapper, "CodeMirror-focused");
  7062. // This test prevents this from firing when a context
  7063. // menu is closed (since the input reset would kill the
  7064. // select-all detection hack)
  7065. if (!cm.curOp && cm.display.selForContextMenu != cm.doc.sel) {
  7066. cm.display.input.reset();
  7067. if (webkit) { setTimeout(function () { return cm.display.input.reset(true); }, 20); } // Issue #1730
  7068. }
  7069. cm.display.input.receivedFocus();
  7070. }
  7071. restartBlink(cm);
  7072. }
  7073. function onBlur(cm, e) {
  7074. if (cm.state.delayingBlurEvent) { return }
  7075. if (cm.state.focused) {
  7076. signal(cm, "blur", cm, e);
  7077. cm.state.focused = false;
  7078. rmClass(cm.display.wrapper, "CodeMirror-focused");
  7079. }
  7080. clearInterval(cm.display.blinker);
  7081. setTimeout(function () { if (!cm.state.focused) { cm.display.shift = false; } }, 150);
  7082. }
  7083. // Read the actual heights of the rendered lines, and update their
  7084. // stored heights to match.
  7085. function updateHeightsInViewport(cm) {
  7086. var display = cm.display;
  7087. var prevBottom = display.lineDiv.offsetTop;
  7088. for (var i = 0; i < display.view.length; i++) {
  7089. var cur = display.view[i], wrapping = cm.options.lineWrapping;
  7090. var height = (void 0), width = 0;
  7091. if (cur.hidden) { continue }
  7092. if (ie && ie_version < 8) {
  7093. var bot = cur.node.offsetTop + cur.node.offsetHeight;
  7094. height = bot - prevBottom;
  7095. prevBottom = bot;
  7096. } else {
  7097. var box = cur.node.getBoundingClientRect();
  7098. height = box.bottom - box.top;
  7099. // Check that lines don't extend past the right of the current
  7100. // editor width
  7101. if (!wrapping && cur.text.firstChild)
  7102. { width = cur.text.firstChild.getBoundingClientRect().right - box.left - 1; }
  7103. }
  7104. var diff = cur.line.height - height;
  7105. if (diff > .005 || diff < -.005) {
  7106. updateLineHeight(cur.line, height);
  7107. updateWidgetHeight(cur.line);
  7108. if (cur.rest) { for (var j = 0; j < cur.rest.length; j++)
  7109. { updateWidgetHeight(cur.rest[j]); } }
  7110. }
  7111. if (width > cm.display.sizerWidth) {
  7112. var chWidth = Math.ceil(width / charWidth(cm.display));
  7113. if (chWidth > cm.display.maxLineLength) {
  7114. cm.display.maxLineLength = chWidth;
  7115. cm.display.maxLine = cur.line;
  7116. cm.display.maxLineChanged = true;
  7117. }
  7118. }
  7119. }
  7120. }
  7121. // Read and store the height of line widgets associated with the
  7122. // given line.
  7123. function updateWidgetHeight(line) {
  7124. if (line.widgets) { for (var i = 0; i < line.widgets.length; ++i) {
  7125. var w = line.widgets[i], parent = w.node.parentNode;
  7126. if (parent) { w.height = parent.offsetHeight; }
  7127. } }
  7128. }
  7129. // Compute the lines that are visible in a given viewport (defaults
  7130. // the the current scroll position). viewport may contain top,
  7131. // height, and ensure (see op.scrollToPos) properties.
  7132. function visibleLines(display, doc, viewport) {
  7133. var top = viewport && viewport.top != null ? Math.max(0, viewport.top) : display.scroller.scrollTop;
  7134. top = Math.floor(top - paddingTop(display));
  7135. var bottom = viewport && viewport.bottom != null ? viewport.bottom : top + display.wrapper.clientHeight;
  7136. var from = lineAtHeight(doc, top), to = lineAtHeight(doc, bottom);
  7137. // Ensure is a {from: {line, ch}, to: {line, ch}} object, and
  7138. // forces those lines into the viewport (if possible).
  7139. if (viewport && viewport.ensure) {
  7140. var ensureFrom = viewport.ensure.from.line, ensureTo = viewport.ensure.to.line;
  7141. if (ensureFrom < from) {
  7142. from = ensureFrom;
  7143. to = lineAtHeight(doc, heightAtLine(getLine(doc, ensureFrom)) + display.wrapper.clientHeight);
  7144. } else if (Math.min(ensureTo, doc.lastLine()) >= to) {
  7145. from = lineAtHeight(doc, heightAtLine(getLine(doc, ensureTo)) - display.wrapper.clientHeight);
  7146. to = ensureTo;
  7147. }
  7148. }
  7149. return {from: from, to: Math.max(to, from + 1)}
  7150. }
  7151. // SCROLLING THINGS INTO VIEW
  7152. // If an editor sits on the top or bottom of the window, partially
  7153. // scrolled out of view, this ensures that the cursor is visible.
  7154. function maybeScrollWindow(cm, rect) {
  7155. if (signalDOMEvent(cm, "scrollCursorIntoView")) { return }
  7156. var display = cm.display, box = display.sizer.getBoundingClientRect(), doScroll = null;
  7157. if (rect.top + box.top < 0) { doScroll = true; }
  7158. else if (rect.bottom + box.top > (window.innerHeight || document.documentElement.clientHeight)) { doScroll = false; }
  7159. if (doScroll != null && !phantom) {
  7160. var scrollNode = elt("div", "\u200b", null, ("position: absolute;\n top: " + (rect.top - display.viewOffset - paddingTop(cm.display)) + "px;\n height: " + (rect.bottom - rect.top + scrollGap(cm) + display.barHeight) + "px;\n left: " + (rect.left) + "px; width: " + (Math.max(2, rect.right - rect.left)) + "px;"));
  7161. cm.display.lineSpace.appendChild(scrollNode);
  7162. scrollNode.scrollIntoView(doScroll);
  7163. cm.display.lineSpace.removeChild(scrollNode);
  7164. }
  7165. }
  7166. // Scroll a given position into view (immediately), verifying that
  7167. // it actually became visible (as line heights are accurately
  7168. // measured, the position of something may 'drift' during drawing).
  7169. function scrollPosIntoView(cm, pos, end, margin) {
  7170. if (margin == null) { margin = 0; }
  7171. var rect;
  7172. if (!cm.options.lineWrapping && pos == end) {
  7173. // Set pos and end to the cursor positions around the character pos sticks to
  7174. // If pos.sticky == "before", that is around pos.ch - 1, otherwise around pos.ch
  7175. // If pos == Pos(_, 0, "before"), pos and end are unchanged
  7176. pos = pos.ch ? Pos(pos.line, pos.sticky == "before" ? pos.ch - 1 : pos.ch, "after") : pos;
  7177. end = pos.sticky == "before" ? Pos(pos.line, pos.ch + 1, "before") : pos;
  7178. }
  7179. for (var limit = 0; limit < 5; limit++) {
  7180. var changed = false;
  7181. var coords = cursorCoords(cm, pos);
  7182. var endCoords = !end || end == pos ? coords : cursorCoords(cm, end);
  7183. rect = {left: Math.min(coords.left, endCoords.left),
  7184. top: Math.min(coords.top, endCoords.top) - margin,
  7185. right: Math.max(coords.left, endCoords.left),
  7186. bottom: Math.max(coords.bottom, endCoords.bottom) + margin};
  7187. var scrollPos = calculateScrollPos(cm, rect);
  7188. var startTop = cm.doc.scrollTop, startLeft = cm.doc.scrollLeft;
  7189. if (scrollPos.scrollTop != null) {
  7190. updateScrollTop(cm, scrollPos.scrollTop);
  7191. if (Math.abs(cm.doc.scrollTop - startTop) > 1) { changed = true; }
  7192. }
  7193. if (scrollPos.scrollLeft != null) {
  7194. setScrollLeft(cm, scrollPos.scrollLeft);
  7195. if (Math.abs(cm.doc.scrollLeft - startLeft) > 1) { changed = true; }
  7196. }
  7197. if (!changed) { break }
  7198. }
  7199. return rect
  7200. }
  7201. // Scroll a given set of coordinates into view (immediately).
  7202. function scrollIntoView(cm, rect) {
  7203. var scrollPos = calculateScrollPos(cm, rect);
  7204. if (scrollPos.scrollTop != null) { updateScrollTop(cm, scrollPos.scrollTop); }
  7205. if (scrollPos.scrollLeft != null) { setScrollLeft(cm, scrollPos.scrollLeft); }
  7206. }
  7207. // Calculate a new scroll position needed to scroll the given
  7208. // rectangle into view. Returns an object with scrollTop and
  7209. // scrollLeft properties. When these are undefined, the
  7210. // vertical/horizontal position does not need to be adjusted.
  7211. function calculateScrollPos(cm, rect) {
  7212. var display = cm.display, snapMargin = textHeight(cm.display);
  7213. if (rect.top < 0) { rect.top = 0; }
  7214. var screentop = cm.curOp && cm.curOp.scrollTop != null ? cm.curOp.scrollTop : display.scroller.scrollTop;
  7215. var screen = displayHeight(cm), result = {};
  7216. if (rect.bottom - rect.top > screen) { rect.bottom = rect.top + screen; }
  7217. var docBottom = cm.doc.height + paddingVert(display);
  7218. var atTop = rect.top < snapMargin, atBottom = rect.bottom > docBottom - snapMargin;
  7219. if (rect.top < screentop) {
  7220. result.scrollTop = atTop ? 0 : rect.top;
  7221. } else if (rect.bottom > screentop + screen) {
  7222. var newTop = Math.min(rect.top, (atBottom ? docBottom : rect.bottom) - screen);
  7223. if (newTop != screentop) { result.scrollTop = newTop; }
  7224. }
  7225. var screenleft = cm.curOp && cm.curOp.scrollLeft != null ? cm.curOp.scrollLeft : display.scroller.scrollLeft;
  7226. var screenw = displayWidth(cm) - (cm.options.fixedGutter ? display.gutters.offsetWidth : 0);
  7227. var tooWide = rect.right - rect.left > screenw;
  7228. if (tooWide) { rect.right = rect.left + screenw; }
  7229. if (rect.left < 10)
  7230. { result.scrollLeft = 0; }
  7231. else if (rect.left < screenleft)
  7232. { result.scrollLeft = Math.max(0, rect.left - (tooWide ? 0 : 10)); }
  7233. else if (rect.right > screenw + screenleft - 3)
  7234. { result.scrollLeft = rect.right + (tooWide ? 0 : 10) - screenw; }
  7235. return result
  7236. }
  7237. // Store a relative adjustment to the scroll position in the current
  7238. // operation (to be applied when the operation finishes).
  7239. function addToScrollTop(cm, top) {
  7240. if (top == null) { return }
  7241. resolveScrollToPos(cm);
  7242. cm.curOp.scrollTop = (cm.curOp.scrollTop == null ? cm.doc.scrollTop : cm.curOp.scrollTop) + top;
  7243. }
  7244. // Make sure that at the end of the operation the current cursor is
  7245. // shown.
  7246. function ensureCursorVisible(cm) {
  7247. resolveScrollToPos(cm);
  7248. var cur = cm.getCursor();
  7249. cm.curOp.scrollToPos = {from: cur, to: cur, margin: cm.options.cursorScrollMargin};
  7250. }
  7251. function scrollToCoords(cm, x, y) {
  7252. if (x != null || y != null) { resolveScrollToPos(cm); }
  7253. if (x != null) { cm.curOp.scrollLeft = x; }
  7254. if (y != null) { cm.curOp.scrollTop = y; }
  7255. }
  7256. function scrollToRange(cm, range$$1) {
  7257. resolveScrollToPos(cm);
  7258. cm.curOp.scrollToPos = range$$1;
  7259. }
  7260. // When an operation has its scrollToPos property set, and another
  7261. // scroll action is applied before the end of the operation, this
  7262. // 'simulates' scrolling that position into view in a cheap way, so
  7263. // that the effect of intermediate scroll commands is not ignored.
  7264. function resolveScrollToPos(cm) {
  7265. var range$$1 = cm.curOp.scrollToPos;
  7266. if (range$$1) {
  7267. cm.curOp.scrollToPos = null;
  7268. var from = estimateCoords(cm, range$$1.from), to = estimateCoords(cm, range$$1.to);
  7269. scrollToCoordsRange(cm, from, to, range$$1.margin);
  7270. }
  7271. }
  7272. function scrollToCoordsRange(cm, from, to, margin) {
  7273. var sPos = calculateScrollPos(cm, {
  7274. left: Math.min(from.left, to.left),
  7275. top: Math.min(from.top, to.top) - margin,
  7276. right: Math.max(from.right, to.right),
  7277. bottom: Math.max(from.bottom, to.bottom) + margin
  7278. });
  7279. scrollToCoords(cm, sPos.scrollLeft, sPos.scrollTop);
  7280. }
  7281. // Sync the scrollable area and scrollbars, ensure the viewport
  7282. // covers the visible area.
  7283. function updateScrollTop(cm, val) {
  7284. if (Math.abs(cm.doc.scrollTop - val) < 2) { return }
  7285. if (!gecko) { updateDisplaySimple(cm, {top: val}); }
  7286. setScrollTop(cm, val, true);
  7287. if (gecko) { updateDisplaySimple(cm); }
  7288. startWorker(cm, 100);
  7289. }
  7290. function setScrollTop(cm, val, forceScroll) {
  7291. val = Math.min(cm.display.scroller.scrollHeight - cm.display.scroller.clientHeight, val);
  7292. if (cm.display.scroller.scrollTop == val && !forceScroll) { return }
  7293. cm.doc.scrollTop = val;
  7294. cm.display.scrollbars.setScrollTop(val);
  7295. if (cm.display.scroller.scrollTop != val) { cm.display.scroller.scrollTop = val; }
  7296. }
  7297. // Sync scroller and scrollbar, ensure the gutter elements are
  7298. // aligned.
  7299. function setScrollLeft(cm, val, isScroller, forceScroll) {
  7300. val = Math.min(val, cm.display.scroller.scrollWidth - cm.display.scroller.clientWidth);
  7301. if ((isScroller ? val == cm.doc.scrollLeft : Math.abs(cm.doc.scrollLeft - val) < 2) && !forceScroll) { return }
  7302. cm.doc.scrollLeft = val;
  7303. alignHorizontally(cm);
  7304. if (cm.display.scroller.scrollLeft != val) { cm.display.scroller.scrollLeft = val; }
  7305. cm.display.scrollbars.setScrollLeft(val);
  7306. }
  7307. // SCROLLBARS
  7308. // Prepare DOM reads needed to update the scrollbars. Done in one
  7309. // shot to minimize update/measure roundtrips.
  7310. function measureForScrollbars(cm) {
  7311. var d = cm.display, gutterW = d.gutters.offsetWidth;
  7312. var docH = Math.round(cm.doc.height + paddingVert(cm.display));
  7313. return {
  7314. clientHeight: d.scroller.clientHeight,
  7315. viewHeight: d.wrapper.clientHeight,
  7316. scrollWidth: d.scroller.scrollWidth, clientWidth: d.scroller.clientWidth,
  7317. viewWidth: d.wrapper.clientWidth,
  7318. barLeft: cm.options.fixedGutter ? gutterW : 0,
  7319. docHeight: docH,
  7320. scrollHeight: docH + scrollGap(cm) + d.barHeight,
  7321. nativeBarWidth: d.nativeBarWidth,
  7322. gutterWidth: gutterW
  7323. }
  7324. }
  7325. var NativeScrollbars = function(place, scroll, cm) {
  7326. this.cm = cm;
  7327. var vert = this.vert = elt("div", [elt("div", null, null, "min-width: 1px")], "CodeMirror-vscrollbar");
  7328. var horiz = this.horiz = elt("div", [elt("div", null, null, "height: 100%; min-height: 1px")], "CodeMirror-hscrollbar");
  7329. vert.tabIndex = horiz.tabIndex = -1;
  7330. place(vert); place(horiz);
  7331. on(vert, "scroll", function () {
  7332. if (vert.clientHeight) { scroll(vert.scrollTop, "vertical"); }
  7333. });
  7334. on(horiz, "scroll", function () {
  7335. if (horiz.clientWidth) { scroll(horiz.scrollLeft, "horizontal"); }
  7336. });
  7337. this.checkedZeroWidth = false;
  7338. // Need to set a minimum width to see the scrollbar on IE7 (but must not set it on IE8).
  7339. if (ie && ie_version < 8) { this.horiz.style.minHeight = this.vert.style.minWidth = "18px"; }
  7340. };
  7341. NativeScrollbars.prototype.update = function (measure) {
  7342. var needsH = measure.scrollWidth > measure.clientWidth + 1;
  7343. var needsV = measure.scrollHeight > measure.clientHeight + 1;
  7344. var sWidth = measure.nativeBarWidth;
  7345. if (needsV) {
  7346. this.vert.style.display = "block";
  7347. this.vert.style.bottom = needsH ? sWidth + "px" : "0";
  7348. var totalHeight = measure.viewHeight - (needsH ? sWidth : 0);
  7349. // A bug in IE8 can cause this value to be negative, so guard it.
  7350. this.vert.firstChild.style.height =
  7351. Math.max(0, measure.scrollHeight - measure.clientHeight + totalHeight) + "px";
  7352. } else {
  7353. this.vert.style.display = "";
  7354. this.vert.firstChild.style.height = "0";
  7355. }
  7356. if (needsH) {
  7357. this.horiz.style.display = "block";
  7358. this.horiz.style.right = needsV ? sWidth + "px" : "0";
  7359. this.horiz.style.left = measure.barLeft + "px";
  7360. var totalWidth = measure.viewWidth - measure.barLeft - (needsV ? sWidth : 0);
  7361. this.horiz.firstChild.style.width =
  7362. Math.max(0, measure.scrollWidth - measure.clientWidth + totalWidth) + "px";
  7363. } else {
  7364. this.horiz.style.display = "";
  7365. this.horiz.firstChild.style.width = "0";
  7366. }
  7367. if (!this.checkedZeroWidth && measure.clientHeight > 0) {
  7368. if (sWidth == 0) { this.zeroWidthHack(); }
  7369. this.checkedZeroWidth = true;
  7370. }
  7371. return {right: needsV ? sWidth : 0, bottom: needsH ? sWidth : 0}
  7372. };
  7373. NativeScrollbars.prototype.setScrollLeft = function (pos) {
  7374. if (this.horiz.scrollLeft != pos) { this.horiz.scrollLeft = pos; }
  7375. if (this.disableHoriz) { this.enableZeroWidthBar(this.horiz, this.disableHoriz, "horiz"); }
  7376. };
  7377. NativeScrollbars.prototype.setScrollTop = function (pos) {
  7378. if (this.vert.scrollTop != pos) { this.vert.scrollTop = pos; }
  7379. if (this.disableVert) { this.enableZeroWidthBar(this.vert, this.disableVert, "vert"); }
  7380. };
  7381. NativeScrollbars.prototype.zeroWidthHack = function () {
  7382. var w = mac && !mac_geMountainLion ? "12px" : "18px";
  7383. this.horiz.style.height = this.vert.style.width = w;
  7384. this.horiz.style.pointerEvents = this.vert.style.pointerEvents = "none";
  7385. this.disableHoriz = new Delayed;
  7386. this.disableVert = new Delayed;
  7387. };
  7388. NativeScrollbars.prototype.enableZeroWidthBar = function (bar, delay, type) {
  7389. bar.style.pointerEvents = "auto";
  7390. function maybeDisable() {
  7391. // To find out whether the scrollbar is still visible, we
  7392. // check whether the element under the pixel in the bottom
  7393. // right corner of the scrollbar box is the scrollbar box
  7394. // itself (when the bar is still visible) or its filler child
  7395. // (when the bar is hidden). If it is still visible, we keep
  7396. // it enabled, if it's hidden, we disable pointer events.
  7397. var box = bar.getBoundingClientRect();
  7398. var elt$$1 = type == "vert" ? document.elementFromPoint(box.right - 1, (box.top + box.bottom) / 2)
  7399. : document.elementFromPoint((box.right + box.left) / 2, box.bottom - 1);
  7400. if (elt$$1 != bar) { bar.style.pointerEvents = "none"; }
  7401. else { delay.set(1000, maybeDisable); }
  7402. }
  7403. delay.set(1000, maybeDisable);
  7404. };
  7405. NativeScrollbars.prototype.clear = function () {
  7406. var parent = this.horiz.parentNode;
  7407. parent.removeChild(this.horiz);
  7408. parent.removeChild(this.vert);
  7409. };
  7410. var NullScrollbars = function () {};
  7411. NullScrollbars.prototype.update = function () { return {bottom: 0, right: 0} };
  7412. NullScrollbars.prototype.setScrollLeft = function () {};
  7413. NullScrollbars.prototype.setScrollTop = function () {};
  7414. NullScrollbars.prototype.clear = function () {};
  7415. function updateScrollbars(cm, measure) {
  7416. if (!measure) { measure = measureForScrollbars(cm); }
  7417. var startWidth = cm.display.barWidth, startHeight = cm.display.barHeight;
  7418. updateScrollbarsInner(cm, measure);
  7419. for (var i = 0; i < 4 && startWidth != cm.display.barWidth || startHeight != cm.display.barHeight; i++) {
  7420. if (startWidth != cm.display.barWidth && cm.options.lineWrapping)
  7421. { updateHeightsInViewport(cm); }
  7422. updateScrollbarsInner(cm, measureForScrollbars(cm));
  7423. startWidth = cm.display.barWidth; startHeight = cm.display.barHeight;
  7424. }
  7425. }
  7426. // Re-synchronize the fake scrollbars with the actual size of the
  7427. // content.
  7428. function updateScrollbarsInner(cm, measure) {
  7429. var d = cm.display;
  7430. var sizes = d.scrollbars.update(measure);
  7431. d.sizer.style.paddingRight = (d.barWidth = sizes.right) + "px";
  7432. d.sizer.style.paddingBottom = (d.barHeight = sizes.bottom) + "px";
  7433. d.heightForcer.style.borderBottom = sizes.bottom + "px solid transparent";
  7434. if (sizes.right && sizes.bottom) {
  7435. d.scrollbarFiller.style.display = "block";
  7436. d.scrollbarFiller.style.height = sizes.bottom + "px";
  7437. d.scrollbarFiller.style.width = sizes.right + "px";
  7438. } else { d.scrollbarFiller.style.display = ""; }
  7439. if (sizes.bottom && cm.options.coverGutterNextToScrollbar && cm.options.fixedGutter) {
  7440. d.gutterFiller.style.display = "block";
  7441. d.gutterFiller.style.height = sizes.bottom + "px";
  7442. d.gutterFiller.style.width = measure.gutterWidth + "px";
  7443. } else { d.gutterFiller.style.display = ""; }
  7444. }
  7445. var scrollbarModel = {"native": NativeScrollbars, "null": NullScrollbars};
  7446. function initScrollbars(cm) {
  7447. if (cm.display.scrollbars) {
  7448. cm.display.scrollbars.clear();
  7449. if (cm.display.scrollbars.addClass)
  7450. { rmClass(cm.display.wrapper, cm.display.scrollbars.addClass); }
  7451. }
  7452. cm.display.scrollbars = new scrollbarModel[cm.options.scrollbarStyle](function (node) {
  7453. cm.display.wrapper.insertBefore(node, cm.display.scrollbarFiller);
  7454. // Prevent clicks in the scrollbars from killing focus
  7455. on(node, "mousedown", function () {
  7456. if (cm.state.focused) { setTimeout(function () { return cm.display.input.focus(); }, 0); }
  7457. });
  7458. node.setAttribute("cm-not-content", "true");
  7459. }, function (pos, axis) {
  7460. if (axis == "horizontal") { setScrollLeft(cm, pos); }
  7461. else { updateScrollTop(cm, pos); }
  7462. }, cm);
  7463. if (cm.display.scrollbars.addClass)
  7464. { addClass(cm.display.wrapper, cm.display.scrollbars.addClass); }
  7465. }
  7466. // Operations are used to wrap a series of changes to the editor
  7467. // state in such a way that each change won't have to update the
  7468. // cursor and display (which would be awkward, slow, and
  7469. // error-prone). Instead, display updates are batched and then all
  7470. // combined and executed at once.
  7471. var nextOpId = 0;
  7472. // Start a new operation.
  7473. function startOperation(cm) {
  7474. cm.curOp = {
  7475. cm: cm,
  7476. viewChanged: false, // Flag that indicates that lines might need to be redrawn
  7477. startHeight: cm.doc.height, // Used to detect need to update scrollbar
  7478. forceUpdate: false, // Used to force a redraw
  7479. updateInput: 0, // Whether to reset the input textarea
  7480. typing: false, // Whether this reset should be careful to leave existing text (for compositing)
  7481. changeObjs: null, // Accumulated changes, for firing change events
  7482. cursorActivityHandlers: null, // Set of handlers to fire cursorActivity on
  7483. cursorActivityCalled: 0, // Tracks which cursorActivity handlers have been called already
  7484. selectionChanged: false, // Whether the selection needs to be redrawn
  7485. updateMaxLine: false, // Set when the widest line needs to be determined anew
  7486. scrollLeft: null, scrollTop: null, // Intermediate scroll position, not pushed to DOM yet
  7487. scrollToPos: null, // Used to scroll to a specific position
  7488. focus: false,
  7489. id: ++nextOpId // Unique ID
  7490. };
  7491. pushOperation(cm.curOp);
  7492. }
  7493. // Finish an operation, updating the display and signalling delayed events
  7494. function endOperation(cm) {
  7495. var op = cm.curOp;
  7496. if (op) { finishOperation(op, function (group) {
  7497. for (var i = 0; i < group.ops.length; i++)
  7498. { group.ops[i].cm.curOp = null; }
  7499. endOperations(group);
  7500. }); }
  7501. }
  7502. // The DOM updates done when an operation finishes are batched so
  7503. // that the minimum number of relayouts are required.
  7504. function endOperations(group) {
  7505. var ops = group.ops;
  7506. for (var i = 0; i < ops.length; i++) // Read DOM
  7507. { endOperation_R1(ops[i]); }
  7508. for (var i$1 = 0; i$1 < ops.length; i$1++) // Write DOM (maybe)
  7509. { endOperation_W1(ops[i$1]); }
  7510. for (var i$2 = 0; i$2 < ops.length; i$2++) // Read DOM
  7511. { endOperation_R2(ops[i$2]); }
  7512. for (var i$3 = 0; i$3 < ops.length; i$3++) // Write DOM (maybe)
  7513. { endOperation_W2(ops[i$3]); }
  7514. for (var i$4 = 0; i$4 < ops.length; i$4++) // Read DOM
  7515. { endOperation_finish(ops[i$4]); }
  7516. }
  7517. function endOperation_R1(op) {
  7518. var cm = op.cm, display = cm.display;
  7519. maybeClipScrollbars(cm);
  7520. if (op.updateMaxLine) { findMaxLine(cm); }
  7521. op.mustUpdate = op.viewChanged || op.forceUpdate || op.scrollTop != null ||
  7522. op.scrollToPos && (op.scrollToPos.from.line < display.viewFrom ||
  7523. op.scrollToPos.to.line >= display.viewTo) ||
  7524. display.maxLineChanged && cm.options.lineWrapping;
  7525. op.update = op.mustUpdate &&
  7526. new DisplayUpdate(cm, op.mustUpdate && {top: op.scrollTop, ensure: op.scrollToPos}, op.forceUpdate);
  7527. }
  7528. function endOperation_W1(op) {
  7529. op.updatedDisplay = op.mustUpdate && updateDisplayIfNeeded(op.cm, op.update);
  7530. }
  7531. function endOperation_R2(op) {
  7532. var cm = op.cm, display = cm.display;
  7533. if (op.updatedDisplay) { updateHeightsInViewport(cm); }
  7534. op.barMeasure = measureForScrollbars(cm);
  7535. // If the max line changed since it was last measured, measure it,
  7536. // and ensure the document's width matches it.
  7537. // updateDisplay_W2 will use these properties to do the actual resizing
  7538. if (display.maxLineChanged && !cm.options.lineWrapping) {
  7539. op.adjustWidthTo = measureChar(cm, display.maxLine, display.maxLine.text.length).left + 3;
  7540. cm.display.sizerWidth = op.adjustWidthTo;
  7541. op.barMeasure.scrollWidth =
  7542. Math.max(display.scroller.clientWidth, display.sizer.offsetLeft + op.adjustWidthTo + scrollGap(cm) + cm.display.barWidth);
  7543. op.maxScrollLeft = Math.max(0, display.sizer.offsetLeft + op.adjustWidthTo - displayWidth(cm));
  7544. }
  7545. if (op.updatedDisplay || op.selectionChanged)
  7546. { op.preparedSelection = display.input.prepareSelection(); }
  7547. }
  7548. function endOperation_W2(op) {
  7549. var cm = op.cm;
  7550. if (op.adjustWidthTo != null) {
  7551. cm.display.sizer.style.minWidth = op.adjustWidthTo + "px";
  7552. if (op.maxScrollLeft < cm.doc.scrollLeft)
  7553. { setScrollLeft(cm, Math.min(cm.display.scroller.scrollLeft, op.maxScrollLeft), true); }
  7554. cm.display.maxLineChanged = false;
  7555. }
  7556. var takeFocus = op.focus && op.focus == activeElt();
  7557. if (op.preparedSelection)
  7558. { cm.display.input.showSelection(op.preparedSelection, takeFocus); }
  7559. if (op.updatedDisplay || op.startHeight != cm.doc.height)
  7560. { updateScrollbars(cm, op.barMeasure); }
  7561. if (op.updatedDisplay)
  7562. { setDocumentHeight(cm, op.barMeasure); }
  7563. if (op.selectionChanged) { restartBlink(cm); }
  7564. if (cm.state.focused && op.updateInput)
  7565. { cm.display.input.reset(op.typing); }
  7566. if (takeFocus) { ensureFocus(op.cm); }
  7567. }
  7568. function endOperation_finish(op) {
  7569. var cm = op.cm, display = cm.display, doc = cm.doc;
  7570. if (op.updatedDisplay) { postUpdateDisplay(cm, op.update); }
  7571. // Abort mouse wheel delta measurement, when scrolling explicitly
  7572. if (display.wheelStartX != null && (op.scrollTop != null || op.scrollLeft != null || op.scrollToPos))
  7573. { display.wheelStartX = display.wheelStartY = null; }
  7574. // Propagate the scroll position to the actual DOM scroller
  7575. if (op.scrollTop != null) { setScrollTop(cm, op.scrollTop, op.forceScroll); }
  7576. if (op.scrollLeft != null) { setScrollLeft(cm, op.scrollLeft, true, true); }
  7577. // If we need to scroll a specific position into view, do so.
  7578. if (op.scrollToPos) {
  7579. var rect = scrollPosIntoView(cm, clipPos(doc, op.scrollToPos.from),
  7580. clipPos(doc, op.scrollToPos.to), op.scrollToPos.margin);
  7581. maybeScrollWindow(cm, rect);
  7582. }
  7583. // Fire events for markers that are hidden/unidden by editing or
  7584. // undoing
  7585. var hidden = op.maybeHiddenMarkers, unhidden = op.maybeUnhiddenMarkers;
  7586. if (hidden) { for (var i = 0; i < hidden.length; ++i)
  7587. { if (!hidden[i].lines.length) { signal(hidden[i], "hide"); } } }
  7588. if (unhidden) { for (var i$1 = 0; i$1 < unhidden.length; ++i$1)
  7589. { if (unhidden[i$1].lines.length) { signal(unhidden[i$1], "unhide"); } } }
  7590. if (display.wrapper.offsetHeight)
  7591. { doc.scrollTop = cm.display.scroller.scrollTop; }
  7592. // Fire change events, and delayed event handlers
  7593. if (op.changeObjs)
  7594. { signal(cm, "changes", cm, op.changeObjs); }
  7595. if (op.update)
  7596. { op.update.finish(); }
  7597. }
  7598. // Run the given function in an operation
  7599. function runInOp(cm, f) {
  7600. if (cm.curOp) { return f() }
  7601. startOperation(cm);
  7602. try { return f() }
  7603. finally { endOperation(cm); }
  7604. }
  7605. // Wraps a function in an operation. Returns the wrapped function.
  7606. function operation(cm, f) {
  7607. return function() {
  7608. if (cm.curOp) { return f.apply(cm, arguments) }
  7609. startOperation(cm);
  7610. try { return f.apply(cm, arguments) }
  7611. finally { endOperation(cm); }
  7612. }
  7613. }
  7614. // Used to add methods to editor and doc instances, wrapping them in
  7615. // operations.
  7616. function methodOp(f) {
  7617. return function() {
  7618. if (this.curOp) { return f.apply(this, arguments) }
  7619. startOperation(this);
  7620. try { return f.apply(this, arguments) }
  7621. finally { endOperation(this); }
  7622. }
  7623. }
  7624. function docMethodOp(f) {
  7625. return function() {
  7626. var cm = this.cm;
  7627. if (!cm || cm.curOp) { return f.apply(this, arguments) }
  7628. startOperation(cm);
  7629. try { return f.apply(this, arguments) }
  7630. finally { endOperation(cm); }
  7631. }
  7632. }
  7633. // HIGHLIGHT WORKER
  7634. function startWorker(cm, time) {
  7635. if (cm.doc.highlightFrontier < cm.display.viewTo)
  7636. { cm.state.highlight.set(time, bind(highlightWorker, cm)); }
  7637. }
  7638. function highlightWorker(cm) {
  7639. var doc = cm.doc;
  7640. if (doc.highlightFrontier >= cm.display.viewTo) { return }
  7641. var end = +new Date + cm.options.workTime;
  7642. var context = getContextBefore(cm, doc.highlightFrontier);
  7643. var changedLines = [];
  7644. doc.iter(context.line, Math.min(doc.first + doc.size, cm.display.viewTo + 500), function (line) {
  7645. if (context.line >= cm.display.viewFrom) { // Visible
  7646. var oldStyles = line.styles;
  7647. var resetState = line.text.length > cm.options.maxHighlightLength ? copyState(doc.mode, context.state) : null;
  7648. var highlighted = highlightLine(cm, line, context, true);
  7649. if (resetState) { context.state = resetState; }
  7650. line.styles = highlighted.styles;
  7651. var oldCls = line.styleClasses, newCls = highlighted.classes;
  7652. if (newCls) { line.styleClasses = newCls; }
  7653. else if (oldCls) { line.styleClasses = null; }
  7654. var ischange = !oldStyles || oldStyles.length != line.styles.length ||
  7655. oldCls != newCls && (!oldCls || !newCls || oldCls.bgClass != newCls.bgClass || oldCls.textClass != newCls.textClass);
  7656. for (var i = 0; !ischange && i < oldStyles.length; ++i) { ischange = oldStyles[i] != line.styles[i]; }
  7657. if (ischange) { changedLines.push(context.line); }
  7658. line.stateAfter = context.save();
  7659. context.nextLine();
  7660. } else {
  7661. if (line.text.length <= cm.options.maxHighlightLength)
  7662. { processLine(cm, line.text, context); }
  7663. line.stateAfter = context.line % 5 == 0 ? context.save() : null;
  7664. context.nextLine();
  7665. }
  7666. if (+new Date > end) {
  7667. startWorker(cm, cm.options.workDelay);
  7668. return true
  7669. }
  7670. });
  7671. doc.highlightFrontier = context.line;
  7672. doc.modeFrontier = Math.max(doc.modeFrontier, context.line);
  7673. if (changedLines.length) { runInOp(cm, function () {
  7674. for (var i = 0; i < changedLines.length; i++)
  7675. { regLineChange(cm, changedLines[i], "text"); }
  7676. }); }
  7677. }
  7678. // DISPLAY DRAWING
  7679. var DisplayUpdate = function(cm, viewport, force) {
  7680. var display = cm.display;
  7681. this.viewport = viewport;
  7682. // Store some values that we'll need later (but don't want to force a relayout for)
  7683. this.visible = visibleLines(display, cm.doc, viewport);
  7684. this.editorIsHidden = !display.wrapper.offsetWidth;
  7685. this.wrapperHeight = display.wrapper.clientHeight;
  7686. this.wrapperWidth = display.wrapper.clientWidth;
  7687. this.oldDisplayWidth = displayWidth(cm);
  7688. this.force = force;
  7689. this.dims = getDimensions(cm);
  7690. this.events = [];
  7691. };
  7692. DisplayUpdate.prototype.signal = function (emitter, type) {
  7693. if (hasHandler(emitter, type))
  7694. { this.events.push(arguments); }
  7695. };
  7696. DisplayUpdate.prototype.finish = function () {
  7697. var this$1 = this;
  7698. for (var i = 0; i < this.events.length; i++)
  7699. { signal.apply(null, this$1.events[i]); }
  7700. };
  7701. function maybeClipScrollbars(cm) {
  7702. var display = cm.display;
  7703. if (!display.scrollbarsClipped && display.scroller.offsetWidth) {
  7704. display.nativeBarWidth = display.scroller.offsetWidth - display.scroller.clientWidth;
  7705. display.heightForcer.style.height = scrollGap(cm) + "px";
  7706. display.sizer.style.marginBottom = -display.nativeBarWidth + "px";
  7707. display.sizer.style.borderRightWidth = scrollGap(cm) + "px";
  7708. display.scrollbarsClipped = true;
  7709. }
  7710. }
  7711. function selectionSnapshot(cm) {
  7712. if (cm.hasFocus()) { return null }
  7713. var active = activeElt();
  7714. if (!active || !contains(cm.display.lineDiv, active)) { return null }
  7715. var result = {activeElt: active};
  7716. if (window.getSelection) {
  7717. var sel = window.getSelection();
  7718. if (sel.anchorNode && sel.extend && contains(cm.display.lineDiv, sel.anchorNode)) {
  7719. result.anchorNode = sel.anchorNode;
  7720. result.anchorOffset = sel.anchorOffset;
  7721. result.focusNode = sel.focusNode;
  7722. result.focusOffset = sel.focusOffset;
  7723. }
  7724. }
  7725. return result
  7726. }
  7727. function restoreSelection(snapshot) {
  7728. if (!snapshot || !snapshot.activeElt || snapshot.activeElt == activeElt()) { return }
  7729. snapshot.activeElt.focus();
  7730. if (snapshot.anchorNode && contains(document.body, snapshot.anchorNode) && contains(document.body, snapshot.focusNode)) {
  7731. var sel = window.getSelection(), range$$1 = document.createRange();
  7732. range$$1.setEnd(snapshot.anchorNode, snapshot.anchorOffset);
  7733. range$$1.collapse(false);
  7734. sel.removeAllRanges();
  7735. sel.addRange(range$$1);
  7736. sel.extend(snapshot.focusNode, snapshot.focusOffset);
  7737. }
  7738. }
  7739. // Does the actual updating of the line display. Bails out
  7740. // (returning false) when there is nothing to be done and forced is
  7741. // false.
  7742. function updateDisplayIfNeeded(cm, update) {
  7743. var display = cm.display, doc = cm.doc;
  7744. if (update.editorIsHidden) {
  7745. resetView(cm);
  7746. return false
  7747. }
  7748. // Bail out if the visible area is already rendered and nothing changed.
  7749. if (!update.force &&
  7750. update.visible.from >= display.viewFrom && update.visible.to <= display.viewTo &&
  7751. (display.updateLineNumbers == null || display.updateLineNumbers >= display.viewTo) &&
  7752. display.renderedView == display.view && countDirtyView(cm) == 0)
  7753. { return false }
  7754. if (maybeUpdateLineNumberWidth(cm)) {
  7755. resetView(cm);
  7756. update.dims = getDimensions(cm);
  7757. }
  7758. // Compute a suitable new viewport (from & to)
  7759. var end = doc.first + doc.size;
  7760. var from = Math.max(update.visible.from - cm.options.viewportMargin, doc.first);
  7761. var to = Math.min(end, update.visible.to + cm.options.viewportMargin);
  7762. if (display.viewFrom < from && from - display.viewFrom < 20) { from = Math.max(doc.first, display.viewFrom); }
  7763. if (display.viewTo > to && display.viewTo - to < 20) { to = Math.min(end, display.viewTo); }
  7764. if (sawCollapsedSpans) {
  7765. from = visualLineNo(cm.doc, from);
  7766. to = visualLineEndNo(cm.doc, to);
  7767. }
  7768. var different = from != display.viewFrom || to != display.viewTo ||
  7769. display.lastWrapHeight != update.wrapperHeight || display.lastWrapWidth != update.wrapperWidth;
  7770. adjustView(cm, from, to);
  7771. display.viewOffset = heightAtLine(getLine(cm.doc, display.viewFrom));
  7772. // Position the mover div to align with the current scroll position
  7773. cm.display.mover.style.top = display.viewOffset + "px";
  7774. var toUpdate = countDirtyView(cm);
  7775. if (!different && toUpdate == 0 && !update.force && display.renderedView == display.view &&
  7776. (display.updateLineNumbers == null || display.updateLineNumbers >= display.viewTo))
  7777. { return false }
  7778. // For big changes, we hide the enclosing element during the
  7779. // update, since that speeds up the operations on most browsers.
  7780. var selSnapshot = selectionSnapshot(cm);
  7781. if (toUpdate > 4) { display.lineDiv.style.display = "none"; }
  7782. patchDisplay(cm, display.updateLineNumbers, update.dims);
  7783. if (toUpdate > 4) { display.lineDiv.style.display = ""; }
  7784. display.renderedView = display.view;
  7785. // There might have been a widget with a focused element that got
  7786. // hidden or updated, if so re-focus it.
  7787. restoreSelection(selSnapshot);
  7788. // Prevent selection and cursors from interfering with the scroll
  7789. // width and height.
  7790. removeChildren(display.cursorDiv);
  7791. removeChildren(display.selectionDiv);
  7792. display.gutters.style.height = display.sizer.style.minHeight = 0;
  7793. if (different) {
  7794. display.lastWrapHeight = update.wrapperHeight;
  7795. display.lastWrapWidth = update.wrapperWidth;
  7796. startWorker(cm, 400);
  7797. }
  7798. display.updateLineNumbers = null;
  7799. return true
  7800. }
  7801. function postUpdateDisplay(cm, update) {
  7802. var viewport = update.viewport;
  7803. for (var first = true;; first = false) {
  7804. if (!first || !cm.options.lineWrapping || update.oldDisplayWidth == displayWidth(cm)) {
  7805. // Clip forced viewport to actual scrollable area.
  7806. if (viewport && viewport.top != null)
  7807. { viewport = {top: Math.min(cm.doc.height + paddingVert(cm.display) - displayHeight(cm), viewport.top)}; }
  7808. // Updated line heights might result in the drawn area not
  7809. // actually covering the viewport. Keep looping until it does.
  7810. update.visible = visibleLines(cm.display, cm.doc, viewport);
  7811. if (update.visible.from >= cm.display.viewFrom && update.visible.to <= cm.display.viewTo)
  7812. { break }
  7813. }
  7814. if (!updateDisplayIfNeeded(cm, update)) { break }
  7815. updateHeightsInViewport(cm);
  7816. var barMeasure = measureForScrollbars(cm);
  7817. updateSelection(cm);
  7818. updateScrollbars(cm, barMeasure);
  7819. setDocumentHeight(cm, barMeasure);
  7820. update.force = false;
  7821. }
  7822. update.signal(cm, "update", cm);
  7823. if (cm.display.viewFrom != cm.display.reportedViewFrom || cm.display.viewTo != cm.display.reportedViewTo) {
  7824. update.signal(cm, "viewportChange", cm, cm.display.viewFrom, cm.display.viewTo);
  7825. cm.display.reportedViewFrom = cm.display.viewFrom; cm.display.reportedViewTo = cm.display.viewTo;
  7826. }
  7827. }
  7828. function updateDisplaySimple(cm, viewport) {
  7829. var update = new DisplayUpdate(cm, viewport);
  7830. if (updateDisplayIfNeeded(cm, update)) {
  7831. updateHeightsInViewport(cm);
  7832. postUpdateDisplay(cm, update);
  7833. var barMeasure = measureForScrollbars(cm);
  7834. updateSelection(cm);
  7835. updateScrollbars(cm, barMeasure);
  7836. setDocumentHeight(cm, barMeasure);
  7837. update.finish();
  7838. }
  7839. }
  7840. // Sync the actual display DOM structure with display.view, removing
  7841. // nodes for lines that are no longer in view, and creating the ones
  7842. // that are not there yet, and updating the ones that are out of
  7843. // date.
  7844. function patchDisplay(cm, updateNumbersFrom, dims) {
  7845. var display = cm.display, lineNumbers = cm.options.lineNumbers;
  7846. var container = display.lineDiv, cur = container.firstChild;
  7847. function rm(node) {
  7848. var next = node.nextSibling;
  7849. // Works around a throw-scroll bug in OS X Webkit
  7850. if (webkit && mac && cm.display.currentWheelTarget == node)
  7851. { node.style.display = "none"; }
  7852. else
  7853. { node.parentNode.removeChild(node); }
  7854. return next
  7855. }
  7856. var view = display.view, lineN = display.viewFrom;
  7857. // Loop over the elements in the view, syncing cur (the DOM nodes
  7858. // in display.lineDiv) with the view as we go.
  7859. for (var i = 0; i < view.length; i++) {
  7860. var lineView = view[i];
  7861. if (lineView.hidden) ; else if (!lineView.node || lineView.node.parentNode != container) { // Not drawn yet
  7862. var node = buildLineElement(cm, lineView, lineN, dims);
  7863. container.insertBefore(node, cur);
  7864. } else { // Already drawn
  7865. while (cur != lineView.node) { cur = rm(cur); }
  7866. var updateNumber = lineNumbers && updateNumbersFrom != null &&
  7867. updateNumbersFrom <= lineN && lineView.lineNumber;
  7868. if (lineView.changes) {
  7869. if (indexOf(lineView.changes, "gutter") > -1) { updateNumber = false; }
  7870. updateLineForChanges(cm, lineView, lineN, dims);
  7871. }
  7872. if (updateNumber) {
  7873. removeChildren(lineView.lineNumber);
  7874. lineView.lineNumber.appendChild(document.createTextNode(lineNumberFor(cm.options, lineN)));
  7875. }
  7876. cur = lineView.node.nextSibling;
  7877. }
  7878. lineN += lineView.size;
  7879. }
  7880. while (cur) { cur = rm(cur); }
  7881. }
  7882. function updateGutterSpace(display) {
  7883. var width = display.gutters.offsetWidth;
  7884. display.sizer.style.marginLeft = width + "px";
  7885. }
  7886. function setDocumentHeight(cm, measure) {
  7887. cm.display.sizer.style.minHeight = measure.docHeight + "px";
  7888. cm.display.heightForcer.style.top = measure.docHeight + "px";
  7889. cm.display.gutters.style.height = (measure.docHeight + cm.display.barHeight + scrollGap(cm)) + "px";
  7890. }
  7891. // Re-align line numbers and gutter marks to compensate for
  7892. // horizontal scrolling.
  7893. function alignHorizontally(cm) {
  7894. var display = cm.display, view = display.view;
  7895. if (!display.alignWidgets && (!display.gutters.firstChild || !cm.options.fixedGutter)) { return }
  7896. var comp = compensateForHScroll(display) - display.scroller.scrollLeft + cm.doc.scrollLeft;
  7897. var gutterW = display.gutters.offsetWidth, left = comp + "px";
  7898. for (var i = 0; i < view.length; i++) { if (!view[i].hidden) {
  7899. if (cm.options.fixedGutter) {
  7900. if (view[i].gutter)
  7901. { view[i].gutter.style.left = left; }
  7902. if (view[i].gutterBackground)
  7903. { view[i].gutterBackground.style.left = left; }
  7904. }
  7905. var align = view[i].alignable;
  7906. if (align) { for (var j = 0; j < align.length; j++)
  7907. { align[j].style.left = left; } }
  7908. } }
  7909. if (cm.options.fixedGutter)
  7910. { display.gutters.style.left = (comp + gutterW) + "px"; }
  7911. }
  7912. // Used to ensure that the line number gutter is still the right
  7913. // size for the current document size. Returns true when an update
  7914. // is needed.
  7915. function maybeUpdateLineNumberWidth(cm) {
  7916. if (!cm.options.lineNumbers) { return false }
  7917. var doc = cm.doc, last = lineNumberFor(cm.options, doc.first + doc.size - 1), display = cm.display;
  7918. if (last.length != display.lineNumChars) {
  7919. var test = display.measure.appendChild(elt("div", [elt("div", last)],
  7920. "CodeMirror-linenumber CodeMirror-gutter-elt"));
  7921. var innerW = test.firstChild.offsetWidth, padding = test.offsetWidth - innerW;
  7922. display.lineGutter.style.width = "";
  7923. display.lineNumInnerWidth = Math.max(innerW, display.lineGutter.offsetWidth - padding) + 1;
  7924. display.lineNumWidth = display.lineNumInnerWidth + padding;
  7925. display.lineNumChars = display.lineNumInnerWidth ? last.length : -1;
  7926. display.lineGutter.style.width = display.lineNumWidth + "px";
  7927. updateGutterSpace(cm.display);
  7928. return true
  7929. }
  7930. return false
  7931. }
  7932. function getGutters(gutters, lineNumbers) {
  7933. var result = [], sawLineNumbers = false;
  7934. for (var i = 0; i < gutters.length; i++) {
  7935. var name = gutters[i], style = null;
  7936. if (typeof name != "string") { style = name.style; name = name.className; }
  7937. if (name == "CodeMirror-linenumbers") {
  7938. if (!lineNumbers) { continue }
  7939. else { sawLineNumbers = true; }
  7940. }
  7941. result.push({className: name, style: style});
  7942. }
  7943. if (lineNumbers && !sawLineNumbers) { result.push({className: "CodeMirror-linenumbers", style: null}); }
  7944. return result
  7945. }
  7946. // Rebuild the gutter elements, ensure the margin to the left of the
  7947. // code matches their width.
  7948. function renderGutters(display) {
  7949. var gutters = display.gutters, specs = display.gutterSpecs;
  7950. removeChildren(gutters);
  7951. display.lineGutter = null;
  7952. for (var i = 0; i < specs.length; ++i) {
  7953. var ref = specs[i];
  7954. var className = ref.className;
  7955. var style = ref.style;
  7956. var gElt = gutters.appendChild(elt("div", null, "CodeMirror-gutter " + className));
  7957. if (style) { gElt.style.cssText = style; }
  7958. if (className == "CodeMirror-linenumbers") {
  7959. display.lineGutter = gElt;
  7960. gElt.style.width = (display.lineNumWidth || 1) + "px";
  7961. }
  7962. }
  7963. gutters.style.display = specs.length ? "" : "none";
  7964. updateGutterSpace(display);
  7965. }
  7966. function updateGutters(cm) {
  7967. renderGutters(cm.display);
  7968. regChange(cm);
  7969. alignHorizontally(cm);
  7970. }
  7971. // The display handles the DOM integration, both for input reading
  7972. // and content drawing. It holds references to DOM nodes and
  7973. // display-related state.
  7974. function Display(place, doc, input, options) {
  7975. var d = this;
  7976. this.input = input;
  7977. // Covers bottom-right square when both scrollbars are present.
  7978. d.scrollbarFiller = elt("div", null, "CodeMirror-scrollbar-filler");
  7979. d.scrollbarFiller.setAttribute("cm-not-content", "true");
  7980. // Covers bottom of gutter when coverGutterNextToScrollbar is on
  7981. // and h scrollbar is present.
  7982. d.gutterFiller = elt("div", null, "CodeMirror-gutter-filler");
  7983. d.gutterFiller.setAttribute("cm-not-content", "true");
  7984. // Will contain the actual code, positioned to cover the viewport.
  7985. d.lineDiv = eltP("div", null, "CodeMirror-code");
  7986. // Elements are added to these to represent selection and cursors.
  7987. d.selectionDiv = elt("div", null, null, "position: relative; z-index: 1");
  7988. d.cursorDiv = elt("div", null, "CodeMirror-cursors");
  7989. // A visibility: hidden element used to find the size of things.
  7990. d.measure = elt("div", null, "CodeMirror-measure");
  7991. // When lines outside of the viewport are measured, they are drawn in this.
  7992. d.lineMeasure = elt("div", null, "CodeMirror-measure");
  7993. // Wraps everything that needs to exist inside the vertically-padded coordinate system
  7994. d.lineSpace = eltP("div", [d.measure, d.lineMeasure, d.selectionDiv, d.cursorDiv, d.lineDiv],
  7995. null, "position: relative; outline: none");
  7996. var lines = eltP("div", [d.lineSpace], "CodeMirror-lines");
  7997. // Moved around its parent to cover visible view.
  7998. d.mover = elt("div", [lines], null, "position: relative");
  7999. // Set to the height of the document, allowing scrolling.
  8000. d.sizer = elt("div", [d.mover], "CodeMirror-sizer");
  8001. d.sizerWidth = null;
  8002. // Behavior of elts with overflow: auto and padding is
  8003. // inconsistent across browsers. This is used to ensure the
  8004. // scrollable area is big enough.
  8005. d.heightForcer = elt("div", null, null, "position: absolute; height: " + scrollerGap + "px; width: 1px;");
  8006. // Will contain the gutters, if any.
  8007. d.gutters = elt("div", null, "CodeMirror-gutters");
  8008. d.lineGutter = null;
  8009. // Actual scrollable element.
  8010. d.scroller = elt("div", [d.sizer, d.heightForcer, d.gutters], "CodeMirror-scroll");
  8011. d.scroller.setAttribute("tabIndex", "-1");
  8012. // The element in which the editor lives.
  8013. d.wrapper = elt("div", [d.scrollbarFiller, d.gutterFiller, d.scroller], "CodeMirror");
  8014. // Work around IE7 z-index bug (not perfect, hence IE7 not really being supported)
  8015. if (ie && ie_version < 8) { d.gutters.style.zIndex = -1; d.scroller.style.paddingRight = 0; }
  8016. if (!webkit && !(gecko && mobile)) { d.scroller.draggable = true; }
  8017. if (place) {
  8018. if (place.appendChild) { place.appendChild(d.wrapper); }
  8019. else { place(d.wrapper); }
  8020. }
  8021. // Current rendered range (may be bigger than the view window).
  8022. d.viewFrom = d.viewTo = doc.first;
  8023. d.reportedViewFrom = d.reportedViewTo = doc.first;
  8024. // Information about the rendered lines.
  8025. d.view = [];
  8026. d.renderedView = null;
  8027. // Holds info about a single rendered line when it was rendered
  8028. // for measurement, while not in view.
  8029. d.externalMeasured = null;
  8030. // Empty space (in pixels) above the view
  8031. d.viewOffset = 0;
  8032. d.lastWrapHeight = d.lastWrapWidth = 0;
  8033. d.updateLineNumbers = null;
  8034. d.nativeBarWidth = d.barHeight = d.barWidth = 0;
  8035. d.scrollbarsClipped = false;
  8036. // Used to only resize the line number gutter when necessary (when
  8037. // the amount of lines crosses a boundary that makes its width change)
  8038. d.lineNumWidth = d.lineNumInnerWidth = d.lineNumChars = null;
  8039. // Set to true when a non-horizontal-scrolling line widget is
  8040. // added. As an optimization, line widget aligning is skipped when
  8041. // this is false.
  8042. d.alignWidgets = false;
  8043. d.cachedCharWidth = d.cachedTextHeight = d.cachedPaddingH = null;
  8044. // Tracks the maximum line length so that the horizontal scrollbar
  8045. // can be kept static when scrolling.
  8046. d.maxLine = null;
  8047. d.maxLineLength = 0;
  8048. d.maxLineChanged = false;
  8049. // Used for measuring wheel scrolling granularity
  8050. d.wheelDX = d.wheelDY = d.wheelStartX = d.wheelStartY = null;
  8051. // True when shift is held down.
  8052. d.shift = false;
  8053. // Used to track whether anything happened since the context menu
  8054. // was opened.
  8055. d.selForContextMenu = null;
  8056. d.activeTouch = null;
  8057. d.gutterSpecs = getGutters(options.gutters, options.lineNumbers);
  8058. renderGutters(d);
  8059. input.init(d);
  8060. }
  8061. // Since the delta values reported on mouse wheel events are
  8062. // unstandardized between browsers and even browser versions, and
  8063. // generally horribly unpredictable, this code starts by measuring
  8064. // the scroll effect that the first few mouse wheel events have,
  8065. // and, from that, detects the way it can convert deltas to pixel
  8066. // offsets afterwards.
  8067. //
  8068. // The reason we want to know the amount a wheel event will scroll
  8069. // is that it gives us a chance to update the display before the
  8070. // actual scrolling happens, reducing flickering.
  8071. var wheelSamples = 0, wheelPixelsPerUnit = null;
  8072. // Fill in a browser-detected starting value on browsers where we
  8073. // know one. These don't have to be accurate -- the result of them
  8074. // being wrong would just be a slight flicker on the first wheel
  8075. // scroll (if it is large enough).
  8076. if (ie) { wheelPixelsPerUnit = -.53; }
  8077. else if (gecko) { wheelPixelsPerUnit = 15; }
  8078. else if (chrome) { wheelPixelsPerUnit = -.7; }
  8079. else if (safari) { wheelPixelsPerUnit = -1/3; }
  8080. function wheelEventDelta(e) {
  8081. var dx = e.wheelDeltaX, dy = e.wheelDeltaY;
  8082. if (dx == null && e.detail && e.axis == e.HORIZONTAL_AXIS) { dx = e.detail; }
  8083. if (dy == null && e.detail && e.axis == e.VERTICAL_AXIS) { dy = e.detail; }
  8084. else if (dy == null) { dy = e.wheelDelta; }
  8085. return {x: dx, y: dy}
  8086. }
  8087. function wheelEventPixels(e) {
  8088. var delta = wheelEventDelta(e);
  8089. delta.x *= wheelPixelsPerUnit;
  8090. delta.y *= wheelPixelsPerUnit;
  8091. return delta
  8092. }
  8093. function onScrollWheel(cm, e) {
  8094. var delta = wheelEventDelta(e), dx = delta.x, dy = delta.y;
  8095. var display = cm.display, scroll = display.scroller;
  8096. // Quit if there's nothing to scroll here
  8097. var canScrollX = scroll.scrollWidth > scroll.clientWidth;
  8098. var canScrollY = scroll.scrollHeight > scroll.clientHeight;
  8099. if (!(dx && canScrollX || dy && canScrollY)) { return }
  8100. // Webkit browsers on OS X abort momentum scrolls when the target
  8101. // of the scroll event is removed from the scrollable element.
  8102. // This hack (see related code in patchDisplay) makes sure the
  8103. // element is kept around.
  8104. if (dy && mac && webkit) {
  8105. outer: for (var cur = e.target, view = display.view; cur != scroll; cur = cur.parentNode) {
  8106. for (var i = 0; i < view.length; i++) {
  8107. if (view[i].node == cur) {
  8108. cm.display.currentWheelTarget = cur;
  8109. break outer
  8110. }
  8111. }
  8112. }
  8113. }
  8114. // On some browsers, horizontal scrolling will cause redraws to
  8115. // happen before the gutter has been realigned, causing it to
  8116. // wriggle around in a most unseemly way. When we have an
  8117. // estimated pixels/delta value, we just handle horizontal
  8118. // scrolling entirely here. It'll be slightly off from native, but
  8119. // better than glitching out.
  8120. if (dx && !gecko && !presto && wheelPixelsPerUnit != null) {
  8121. if (dy && canScrollY)
  8122. { updateScrollTop(cm, Math.max(0, scroll.scrollTop + dy * wheelPixelsPerUnit)); }
  8123. setScrollLeft(cm, Math.max(0, scroll.scrollLeft + dx * wheelPixelsPerUnit));
  8124. // Only prevent default scrolling if vertical scrolling is
  8125. // actually possible. Otherwise, it causes vertical scroll
  8126. // jitter on OSX trackpads when deltaX is small and deltaY
  8127. // is large (issue #3579)
  8128. if (!dy || (dy && canScrollY))
  8129. { e_preventDefault(e); }
  8130. display.wheelStartX = null; // Abort measurement, if in progress
  8131. return
  8132. }
  8133. // 'Project' the visible viewport to cover the area that is being
  8134. // scrolled into view (if we know enough to estimate it).
  8135. if (dy && wheelPixelsPerUnit != null) {
  8136. var pixels = dy * wheelPixelsPerUnit;
  8137. var top = cm.doc.scrollTop, bot = top + display.wrapper.clientHeight;
  8138. if (pixels < 0) { top = Math.max(0, top + pixels - 50); }
  8139. else { bot = Math.min(cm.doc.height, bot + pixels + 50); }
  8140. updateDisplaySimple(cm, {top: top, bottom: bot});
  8141. }
  8142. if (wheelSamples < 20) {
  8143. if (display.wheelStartX == null) {
  8144. display.wheelStartX = scroll.scrollLeft; display.wheelStartY = scroll.scrollTop;
  8145. display.wheelDX = dx; display.wheelDY = dy;
  8146. setTimeout(function () {
  8147. if (display.wheelStartX == null) { return }
  8148. var movedX = scroll.scrollLeft - display.wheelStartX;
  8149. var movedY = scroll.scrollTop - display.wheelStartY;
  8150. var sample = (movedY && display.wheelDY && movedY / display.wheelDY) ||
  8151. (movedX && display.wheelDX && movedX / display.wheelDX);
  8152. display.wheelStartX = display.wheelStartY = null;
  8153. if (!sample) { return }
  8154. wheelPixelsPerUnit = (wheelPixelsPerUnit * wheelSamples + sample) / (wheelSamples + 1);
  8155. ++wheelSamples;
  8156. }, 200);
  8157. } else {
  8158. display.wheelDX += dx; display.wheelDY += dy;
  8159. }
  8160. }
  8161. }
  8162. // Selection objects are immutable. A new one is created every time
  8163. // the selection changes. A selection is one or more non-overlapping
  8164. // (and non-touching) ranges, sorted, and an integer that indicates
  8165. // which one is the primary selection (the one that's scrolled into
  8166. // view, that getCursor returns, etc).
  8167. var Selection = function(ranges, primIndex) {
  8168. this.ranges = ranges;
  8169. this.primIndex = primIndex;
  8170. };
  8171. Selection.prototype.primary = function () { return this.ranges[this.primIndex] };
  8172. Selection.prototype.equals = function (other) {
  8173. var this$1 = this;
  8174. if (other == this) { return true }
  8175. if (other.primIndex != this.primIndex || other.ranges.length != this.ranges.length) { return false }
  8176. for (var i = 0; i < this.ranges.length; i++) {
  8177. var here = this$1.ranges[i], there = other.ranges[i];
  8178. if (!equalCursorPos(here.anchor, there.anchor) || !equalCursorPos(here.head, there.head)) { return false }
  8179. }
  8180. return true
  8181. };
  8182. Selection.prototype.deepCopy = function () {
  8183. var this$1 = this;
  8184. var out = [];
  8185. for (var i = 0; i < this.ranges.length; i++)
  8186. { out[i] = new Range(copyPos(this$1.ranges[i].anchor), copyPos(this$1.ranges[i].head)); }
  8187. return new Selection(out, this.primIndex)
  8188. };
  8189. Selection.prototype.somethingSelected = function () {
  8190. var this$1 = this;
  8191. for (var i = 0; i < this.ranges.length; i++)
  8192. { if (!this$1.ranges[i].empty()) { return true } }
  8193. return false
  8194. };
  8195. Selection.prototype.contains = function (pos, end) {
  8196. var this$1 = this;
  8197. if (!end) { end = pos; }
  8198. for (var i = 0; i < this.ranges.length; i++) {
  8199. var range = this$1.ranges[i];
  8200. if (cmp(end, range.from()) >= 0 && cmp(pos, range.to()) <= 0)
  8201. { return i }
  8202. }
  8203. return -1
  8204. };
  8205. var Range = function(anchor, head) {
  8206. this.anchor = anchor; this.head = head;
  8207. };
  8208. Range.prototype.from = function () { return minPos(this.anchor, this.head) };
  8209. Range.prototype.to = function () { return maxPos(this.anchor, this.head) };
  8210. Range.prototype.empty = function () { return this.head.line == this.anchor.line && this.head.ch == this.anchor.ch };
  8211. // Take an unsorted, potentially overlapping set of ranges, and
  8212. // build a selection out of it. 'Consumes' ranges array (modifying
  8213. // it).
  8214. function normalizeSelection(cm, ranges, primIndex) {
  8215. var mayTouch = cm && cm.options.selectionsMayTouch;
  8216. var prim = ranges[primIndex];
  8217. ranges.sort(function (a, b) { return cmp(a.from(), b.from()); });
  8218. primIndex = indexOf(ranges, prim);
  8219. for (var i = 1; i < ranges.length; i++) {
  8220. var cur = ranges[i], prev = ranges[i - 1];
  8221. var diff = cmp(prev.to(), cur.from());
  8222. if (mayTouch && !cur.empty() ? diff > 0 : diff >= 0) {
  8223. var from = minPos(prev.from(), cur.from()), to = maxPos(prev.to(), cur.to());
  8224. var inv = prev.empty() ? cur.from() == cur.head : prev.from() == prev.head;
  8225. if (i <= primIndex) { --primIndex; }
  8226. ranges.splice(--i, 2, new Range(inv ? to : from, inv ? from : to));
  8227. }
  8228. }
  8229. return new Selection(ranges, primIndex)
  8230. }
  8231. function simpleSelection(anchor, head) {
  8232. return new Selection([new Range(anchor, head || anchor)], 0)
  8233. }
  8234. // Compute the position of the end of a change (its 'to' property
  8235. // refers to the pre-change end).
  8236. function changeEnd(change) {
  8237. if (!change.text) { return change.to }
  8238. return Pos(change.from.line + change.text.length - 1,
  8239. lst(change.text).length + (change.text.length == 1 ? change.from.ch : 0))
  8240. }
  8241. // Adjust a position to refer to the post-change position of the
  8242. // same text, or the end of the change if the change covers it.
  8243. function adjustForChange(pos, change) {
  8244. if (cmp(pos, change.from) < 0) { return pos }
  8245. if (cmp(pos, change.to) <= 0) { return changeEnd(change) }
  8246. var line = pos.line + change.text.length - (change.to.line - change.from.line) - 1, ch = pos.ch;
  8247. if (pos.line == change.to.line) { ch += changeEnd(change).ch - change.to.ch; }
  8248. return Pos(line, ch)
  8249. }
  8250. function computeSelAfterChange(doc, change) {
  8251. var out = [];
  8252. for (var i = 0; i < doc.sel.ranges.length; i++) {
  8253. var range = doc.sel.ranges[i];
  8254. out.push(new Range(adjustForChange(range.anchor, change),
  8255. adjustForChange(range.head, change)));
  8256. }
  8257. return normalizeSelection(doc.cm, out, doc.sel.primIndex)
  8258. }
  8259. function offsetPos(pos, old, nw) {
  8260. if (pos.line == old.line)
  8261. { return Pos(nw.line, pos.ch - old.ch + nw.ch) }
  8262. else
  8263. { return Pos(nw.line + (pos.line - old.line), pos.ch) }
  8264. }
  8265. // Used by replaceSelections to allow moving the selection to the
  8266. // start or around the replaced test. Hint may be "start" or "around".
  8267. function computeReplacedSel(doc, changes, hint) {
  8268. var out = [];
  8269. var oldPrev = Pos(doc.first, 0), newPrev = oldPrev;
  8270. for (var i = 0; i < changes.length; i++) {
  8271. var change = changes[i];
  8272. var from = offsetPos(change.from, oldPrev, newPrev);
  8273. var to = offsetPos(changeEnd(change), oldPrev, newPrev);
  8274. oldPrev = change.to;
  8275. newPrev = to;
  8276. if (hint == "around") {
  8277. var range = doc.sel.ranges[i], inv = cmp(range.head, range.anchor) < 0;
  8278. out[i] = new Range(inv ? to : from, inv ? from : to);
  8279. } else {
  8280. out[i] = new Range(from, from);
  8281. }
  8282. }
  8283. return new Selection(out, doc.sel.primIndex)
  8284. }
  8285. // Used to get the editor into a consistent state again when options change.
  8286. function loadMode(cm) {
  8287. cm.doc.mode = getMode(cm.options, cm.doc.modeOption);
  8288. resetModeState(cm);
  8289. }
  8290. function resetModeState(cm) {
  8291. cm.doc.iter(function (line) {
  8292. if (line.stateAfter) { line.stateAfter = null; }
  8293. if (line.styles) { line.styles = null; }
  8294. });
  8295. cm.doc.modeFrontier = cm.doc.highlightFrontier = cm.doc.first;
  8296. startWorker(cm, 100);
  8297. cm.state.modeGen++;
  8298. if (cm.curOp) { regChange(cm); }
  8299. }
  8300. // DOCUMENT DATA STRUCTURE
  8301. // By default, updates that start and end at the beginning of a line
  8302. // are treated specially, in order to make the association of line
  8303. // widgets and marker elements with the text behave more intuitive.
  8304. function isWholeLineUpdate(doc, change) {
  8305. return change.from.ch == 0 && change.to.ch == 0 && lst(change.text) == "" &&
  8306. (!doc.cm || doc.cm.options.wholeLineUpdateBefore)
  8307. }
  8308. // Perform a change on the document data structure.
  8309. function updateDoc(doc, change, markedSpans, estimateHeight$$1) {
  8310. function spansFor(n) {return markedSpans ? markedSpans[n] : null}
  8311. function update(line, text, spans) {
  8312. updateLine(line, text, spans, estimateHeight$$1);
  8313. signalLater(line, "change", line, change);
  8314. }
  8315. function linesFor(start, end) {
  8316. var result = [];
  8317. for (var i = start; i < end; ++i)
  8318. { result.push(new Line(text[i], spansFor(i), estimateHeight$$1)); }
  8319. return result
  8320. }
  8321. var from = change.from, to = change.to, text = change.text;
  8322. var firstLine = getLine(doc, from.line), lastLine = getLine(doc, to.line);
  8323. var lastText = lst(text), lastSpans = spansFor(text.length - 1), nlines = to.line - from.line;
  8324. // Adjust the line structure
  8325. if (change.full) {
  8326. doc.insert(0, linesFor(0, text.length));
  8327. doc.remove(text.length, doc.size - text.length);
  8328. } else if (isWholeLineUpdate(doc, change)) {
  8329. // This is a whole-line replace. Treated specially to make
  8330. // sure line objects move the way they are supposed to.
  8331. var added = linesFor(0, text.length - 1);
  8332. update(lastLine, lastLine.text, lastSpans);
  8333. if (nlines) { doc.remove(from.line, nlines); }
  8334. if (added.length) { doc.insert(from.line, added); }
  8335. } else if (firstLine == lastLine) {
  8336. if (text.length == 1) {
  8337. update(firstLine, firstLine.text.slice(0, from.ch) + lastText + firstLine.text.slice(to.ch), lastSpans);
  8338. } else {
  8339. var added$1 = linesFor(1, text.length - 1);
  8340. added$1.push(new Line(lastText + firstLine.text.slice(to.ch), lastSpans, estimateHeight$$1));
  8341. update(firstLine, firstLine.text.slice(0, from.ch) + text[0], spansFor(0));
  8342. doc.insert(from.line + 1, added$1);
  8343. }
  8344. } else if (text.length == 1) {
  8345. update(firstLine, firstLine.text.slice(0, from.ch) + text[0] + lastLine.text.slice(to.ch), spansFor(0));
  8346. doc.remove(from.line + 1, nlines);
  8347. } else {
  8348. update(firstLine, firstLine.text.slice(0, from.ch) + text[0], spansFor(0));
  8349. update(lastLine, lastText + lastLine.text.slice(to.ch), lastSpans);
  8350. var added$2 = linesFor(1, text.length - 1);
  8351. if (nlines > 1) { doc.remove(from.line + 1, nlines - 1); }
  8352. doc.insert(from.line + 1, added$2);
  8353. }
  8354. signalLater(doc, "change", doc, change);
  8355. }
  8356. // Call f for all linked documents.
  8357. function linkedDocs(doc, f, sharedHistOnly) {
  8358. function propagate(doc, skip, sharedHist) {
  8359. if (doc.linked) { for (var i = 0; i < doc.linked.length; ++i) {
  8360. var rel = doc.linked[i];
  8361. if (rel.doc == skip) { continue }
  8362. var shared = sharedHist && rel.sharedHist;
  8363. if (sharedHistOnly && !shared) { continue }
  8364. f(rel.doc, shared);
  8365. propagate(rel.doc, doc, shared);
  8366. } }
  8367. }
  8368. propagate(doc, null, true);
  8369. }
  8370. // Attach a document to an editor.
  8371. function attachDoc(cm, doc) {
  8372. if (doc.cm) { throw new Error("This document is already in use.") }
  8373. cm.doc = doc;
  8374. doc.cm = cm;
  8375. estimateLineHeights(cm);
  8376. loadMode(cm);
  8377. setDirectionClass(cm);
  8378. if (!cm.options.lineWrapping) { findMaxLine(cm); }
  8379. cm.options.mode = doc.modeOption;
  8380. regChange(cm);
  8381. }
  8382. function setDirectionClass(cm) {
  8383. (cm.doc.direction == "rtl" ? addClass : rmClass)(cm.display.lineDiv, "CodeMirror-rtl");
  8384. }
  8385. function directionChanged(cm) {
  8386. runInOp(cm, function () {
  8387. setDirectionClass(cm);
  8388. regChange(cm);
  8389. });
  8390. }
  8391. function History(startGen) {
  8392. // Arrays of change events and selections. Doing something adds an
  8393. // event to done and clears undo. Undoing moves events from done
  8394. // to undone, redoing moves them in the other direction.
  8395. this.done = []; this.undone = [];
  8396. this.undoDepth = Infinity;
  8397. // Used to track when changes can be merged into a single undo
  8398. // event
  8399. this.lastModTime = this.lastSelTime = 0;
  8400. this.lastOp = this.lastSelOp = null;
  8401. this.lastOrigin = this.lastSelOrigin = null;
  8402. // Used by the isClean() method
  8403. this.generation = this.maxGeneration = startGen || 1;
  8404. }
  8405. // Create a history change event from an updateDoc-style change
  8406. // object.
  8407. function historyChangeFromChange(doc, change) {
  8408. var histChange = {from: copyPos(change.from), to: changeEnd(change), text: getBetween(doc, change.from, change.to)};
  8409. attachLocalSpans(doc, histChange, change.from.line, change.to.line + 1);
  8410. linkedDocs(doc, function (doc) { return attachLocalSpans(doc, histChange, change.from.line, change.to.line + 1); }, true);
  8411. return histChange
  8412. }
  8413. // Pop all selection events off the end of a history array. Stop at
  8414. // a change event.
  8415. function clearSelectionEvents(array) {
  8416. while (array.length) {
  8417. var last = lst(array);
  8418. if (last.ranges) { array.pop(); }
  8419. else { break }
  8420. }
  8421. }
  8422. // Find the top change event in the history. Pop off selection
  8423. // events that are in the way.
  8424. function lastChangeEvent(hist, force) {
  8425. if (force) {
  8426. clearSelectionEvents(hist.done);
  8427. return lst(hist.done)
  8428. } else if (hist.done.length && !lst(hist.done).ranges) {
  8429. return lst(hist.done)
  8430. } else if (hist.done.length > 1 && !hist.done[hist.done.length - 2].ranges) {
  8431. hist.done.pop();
  8432. return lst(hist.done)
  8433. }
  8434. }
  8435. // Register a change in the history. Merges changes that are within
  8436. // a single operation, or are close together with an origin that
  8437. // allows merging (starting with "+") into a single event.
  8438. function addChangeToHistory(doc, change, selAfter, opId) {
  8439. var hist = doc.history;
  8440. hist.undone.length = 0;
  8441. var time = +new Date, cur;
  8442. var last;
  8443. if ((hist.lastOp == opId ||
  8444. hist.lastOrigin == change.origin && change.origin &&
  8445. ((change.origin.charAt(0) == "+" && hist.lastModTime > time - (doc.cm ? doc.cm.options.historyEventDelay : 500)) ||
  8446. change.origin.charAt(0) == "*")) &&
  8447. (cur = lastChangeEvent(hist, hist.lastOp == opId))) {
  8448. // Merge this change into the last event
  8449. last = lst(cur.changes);
  8450. if (cmp(change.from, change.to) == 0 && cmp(change.from, last.to) == 0) {
  8451. // Optimized case for simple insertion -- don't want to add
  8452. // new changesets for every character typed
  8453. last.to = changeEnd(change);
  8454. } else {
  8455. // Add new sub-event
  8456. cur.changes.push(historyChangeFromChange(doc, change));
  8457. }
  8458. } else {
  8459. // Can not be merged, start a new event.
  8460. var before = lst(hist.done);
  8461. if (!before || !before.ranges)
  8462. { pushSelectionToHistory(doc.sel, hist.done); }
  8463. cur = {changes: [historyChangeFromChange(doc, change)],
  8464. generation: hist.generation};
  8465. hist.done.push(cur);
  8466. while (hist.done.length > hist.undoDepth) {
  8467. hist.done.shift();
  8468. if (!hist.done[0].ranges) { hist.done.shift(); }
  8469. }
  8470. }
  8471. hist.done.push(selAfter);
  8472. hist.generation = ++hist.maxGeneration;
  8473. hist.lastModTime = hist.lastSelTime = time;
  8474. hist.lastOp = hist.lastSelOp = opId;
  8475. hist.lastOrigin = hist.lastSelOrigin = change.origin;
  8476. if (!last) { signal(doc, "historyAdded"); }
  8477. }
  8478. function selectionEventCanBeMerged(doc, origin, prev, sel) {
  8479. var ch = origin.charAt(0);
  8480. return ch == "*" ||
  8481. ch == "+" &&
  8482. prev.ranges.length == sel.ranges.length &&
  8483. prev.somethingSelected() == sel.somethingSelected() &&
  8484. new Date - doc.history.lastSelTime <= (doc.cm ? doc.cm.options.historyEventDelay : 500)
  8485. }
  8486. // Called whenever the selection changes, sets the new selection as
  8487. // the pending selection in the history, and pushes the old pending
  8488. // selection into the 'done' array when it was significantly
  8489. // different (in number of selected ranges, emptiness, or time).
  8490. function addSelectionToHistory(doc, sel, opId, options) {
  8491. var hist = doc.history, origin = options && options.origin;
  8492. // A new event is started when the previous origin does not match
  8493. // the current, or the origins don't allow matching. Origins
  8494. // starting with * are always merged, those starting with + are
  8495. // merged when similar and close together in time.
  8496. if (opId == hist.lastSelOp ||
  8497. (origin && hist.lastSelOrigin == origin &&
  8498. (hist.lastModTime == hist.lastSelTime && hist.lastOrigin == origin ||
  8499. selectionEventCanBeMerged(doc, origin, lst(hist.done), sel))))
  8500. { hist.done[hist.done.length - 1] = sel; }
  8501. else
  8502. { pushSelectionToHistory(sel, hist.done); }
  8503. hist.lastSelTime = +new Date;
  8504. hist.lastSelOrigin = origin;
  8505. hist.lastSelOp = opId;
  8506. if (options && options.clearRedo !== false)
  8507. { clearSelectionEvents(hist.undone); }
  8508. }
  8509. function pushSelectionToHistory(sel, dest) {
  8510. var top = lst(dest);
  8511. if (!(top && top.ranges && top.equals(sel)))
  8512. { dest.push(sel); }
  8513. }
  8514. // Used to store marked span information in the history.
  8515. function attachLocalSpans(doc, change, from, to) {
  8516. var existing = change["spans_" + doc.id], n = 0;
  8517. doc.iter(Math.max(doc.first, from), Math.min(doc.first + doc.size, to), function (line) {
  8518. if (line.markedSpans)
  8519. { (existing || (existing = change["spans_" + doc.id] = {}))[n] = line.markedSpans; }
  8520. ++n;
  8521. });
  8522. }
  8523. // When un/re-doing restores text containing marked spans, those
  8524. // that have been explicitly cleared should not be restored.
  8525. function removeClearedSpans(spans) {
  8526. if (!spans) { return null }
  8527. var out;
  8528. for (var i = 0; i < spans.length; ++i) {
  8529. if (spans[i].marker.explicitlyCleared) { if (!out) { out = spans.slice(0, i); } }
  8530. else if (out) { out.push(spans[i]); }
  8531. }
  8532. return !out ? spans : out.length ? out : null
  8533. }
  8534. // Retrieve and filter the old marked spans stored in a change event.
  8535. function getOldSpans(doc, change) {
  8536. var found = change["spans_" + doc.id];
  8537. if (!found) { return null }
  8538. var nw = [];
  8539. for (var i = 0; i < change.text.length; ++i)
  8540. { nw.push(removeClearedSpans(found[i])); }
  8541. return nw
  8542. }
  8543. // Used for un/re-doing changes from the history. Combines the
  8544. // result of computing the existing spans with the set of spans that
  8545. // existed in the history (so that deleting around a span and then
  8546. // undoing brings back the span).
  8547. function mergeOldSpans(doc, change) {
  8548. var old = getOldSpans(doc, change);
  8549. var stretched = stretchSpansOverChange(doc, change);
  8550. if (!old) { return stretched }
  8551. if (!stretched) { return old }
  8552. for (var i = 0; i < old.length; ++i) {
  8553. var oldCur = old[i], stretchCur = stretched[i];
  8554. if (oldCur && stretchCur) {
  8555. spans: for (var j = 0; j < stretchCur.length; ++j) {
  8556. var span = stretchCur[j];
  8557. for (var k = 0; k < oldCur.length; ++k)
  8558. { if (oldCur[k].marker == span.marker) { continue spans } }
  8559. oldCur.push(span);
  8560. }
  8561. } else if (stretchCur) {
  8562. old[i] = stretchCur;
  8563. }
  8564. }
  8565. return old
  8566. }
  8567. // Used both to provide a JSON-safe object in .getHistory, and, when
  8568. // detaching a document, to split the history in two
  8569. function copyHistoryArray(events, newGroup, instantiateSel) {
  8570. var copy = [];
  8571. for (var i = 0; i < events.length; ++i) {
  8572. var event = events[i];
  8573. if (event.ranges) {
  8574. copy.push(instantiateSel ? Selection.prototype.deepCopy.call(event) : event);
  8575. continue
  8576. }
  8577. var changes = event.changes, newChanges = [];
  8578. copy.push({changes: newChanges});
  8579. for (var j = 0; j < changes.length; ++j) {
  8580. var change = changes[j], m = (void 0);
  8581. newChanges.push({from: change.from, to: change.to, text: change.text});
  8582. if (newGroup) { for (var prop in change) { if (m = prop.match(/^spans_(\d+)$/)) {
  8583. if (indexOf(newGroup, Number(m[1])) > -1) {
  8584. lst(newChanges)[prop] = change[prop];
  8585. delete change[prop];
  8586. }
  8587. } } }
  8588. }
  8589. }
  8590. return copy
  8591. }
  8592. // The 'scroll' parameter given to many of these indicated whether
  8593. // the new cursor position should be scrolled into view after
  8594. // modifying the selection.
  8595. // If shift is held or the extend flag is set, extends a range to
  8596. // include a given position (and optionally a second position).
  8597. // Otherwise, simply returns the range between the given positions.
  8598. // Used for cursor motion and such.
  8599. function extendRange(range, head, other, extend) {
  8600. if (extend) {
  8601. var anchor = range.anchor;
  8602. if (other) {
  8603. var posBefore = cmp(head, anchor) < 0;
  8604. if (posBefore != (cmp(other, anchor) < 0)) {
  8605. anchor = head;
  8606. head = other;
  8607. } else if (posBefore != (cmp(head, other) < 0)) {
  8608. head = other;
  8609. }
  8610. }
  8611. return new Range(anchor, head)
  8612. } else {
  8613. return new Range(other || head, head)
  8614. }
  8615. }
  8616. // Extend the primary selection range, discard the rest.
  8617. function extendSelection(doc, head, other, options, extend) {
  8618. if (extend == null) { extend = doc.cm && (doc.cm.display.shift || doc.extend); }
  8619. setSelection(doc, new Selection([extendRange(doc.sel.primary(), head, other, extend)], 0), options);
  8620. }
  8621. // Extend all selections (pos is an array of selections with length
  8622. // equal the number of selections)
  8623. function extendSelections(doc, heads, options) {
  8624. var out = [];
  8625. var extend = doc.cm && (doc.cm.display.shift || doc.extend);
  8626. for (var i = 0; i < doc.sel.ranges.length; i++)
  8627. { out[i] = extendRange(doc.sel.ranges[i], heads[i], null, extend); }
  8628. var newSel = normalizeSelection(doc.cm, out, doc.sel.primIndex);
  8629. setSelection(doc, newSel, options);
  8630. }
  8631. // Updates a single range in the selection.
  8632. function replaceOneSelection(doc, i, range, options) {
  8633. var ranges = doc.sel.ranges.slice(0);
  8634. ranges[i] = range;
  8635. setSelection(doc, normalizeSelection(doc.cm, ranges, doc.sel.primIndex), options);
  8636. }
  8637. // Reset the selection to a single range.
  8638. function setSimpleSelection(doc, anchor, head, options) {
  8639. setSelection(doc, simpleSelection(anchor, head), options);
  8640. }
  8641. // Give beforeSelectionChange handlers a change to influence a
  8642. // selection update.
  8643. function filterSelectionChange(doc, sel, options) {
  8644. var obj = {
  8645. ranges: sel.ranges,
  8646. update: function(ranges) {
  8647. var this$1 = this;
  8648. this.ranges = [];
  8649. for (var i = 0; i < ranges.length; i++)
  8650. { this$1.ranges[i] = new Range(clipPos(doc, ranges[i].anchor),
  8651. clipPos(doc, ranges[i].head)); }
  8652. },
  8653. origin: options && options.origin
  8654. };
  8655. signal(doc, "beforeSelectionChange", doc, obj);
  8656. if (doc.cm) { signal(doc.cm, "beforeSelectionChange", doc.cm, obj); }
  8657. if (obj.ranges != sel.ranges) { return normalizeSelection(doc.cm, obj.ranges, obj.ranges.length - 1) }
  8658. else { return sel }
  8659. }
  8660. function setSelectionReplaceHistory(doc, sel, options) {
  8661. var done = doc.history.done, last = lst(done);
  8662. if (last && last.ranges) {
  8663. done[done.length - 1] = sel;
  8664. setSelectionNoUndo(doc, sel, options);
  8665. } else {
  8666. setSelection(doc, sel, options);
  8667. }
  8668. }
  8669. // Set a new selection.
  8670. function setSelection(doc, sel, options) {
  8671. setSelectionNoUndo(doc, sel, options);
  8672. addSelectionToHistory(doc, doc.sel, doc.cm ? doc.cm.curOp.id : NaN, options);
  8673. }
  8674. function setSelectionNoUndo(doc, sel, options) {
  8675. if (hasHandler(doc, "beforeSelectionChange") || doc.cm && hasHandler(doc.cm, "beforeSelectionChange"))
  8676. { sel = filterSelectionChange(doc, sel, options); }
  8677. var bias = options && options.bias ||
  8678. (cmp(sel.primary().head, doc.sel.primary().head) < 0 ? -1 : 1);
  8679. setSelectionInner(doc, skipAtomicInSelection(doc, sel, bias, true));
  8680. if (!(options && options.scroll === false) && doc.cm)
  8681. { ensureCursorVisible(doc.cm); }
  8682. }
  8683. function setSelectionInner(doc, sel) {
  8684. if (sel.equals(doc.sel)) { return }
  8685. doc.sel = sel;
  8686. if (doc.cm) {
  8687. doc.cm.curOp.updateInput = 1;
  8688. doc.cm.curOp.selectionChanged = true;
  8689. signalCursorActivity(doc.cm);
  8690. }
  8691. signalLater(doc, "cursorActivity", doc);
  8692. }
  8693. // Verify that the selection does not partially select any atomic
  8694. // marked ranges.
  8695. function reCheckSelection(doc) {
  8696. setSelectionInner(doc, skipAtomicInSelection(doc, doc.sel, null, false));
  8697. }
  8698. // Return a selection that does not partially select any atomic
  8699. // ranges.
  8700. function skipAtomicInSelection(doc, sel, bias, mayClear) {
  8701. var out;
  8702. for (var i = 0; i < sel.ranges.length; i++) {
  8703. var range = sel.ranges[i];
  8704. var old = sel.ranges.length == doc.sel.ranges.length && doc.sel.ranges[i];
  8705. var newAnchor = skipAtomic(doc, range.anchor, old && old.anchor, bias, mayClear);
  8706. var newHead = skipAtomic(doc, range.head, old && old.head, bias, mayClear);
  8707. if (out || newAnchor != range.anchor || newHead != range.head) {
  8708. if (!out) { out = sel.ranges.slice(0, i); }
  8709. out[i] = new Range(newAnchor, newHead);
  8710. }
  8711. }
  8712. return out ? normalizeSelection(doc.cm, out, sel.primIndex) : sel
  8713. }
  8714. function skipAtomicInner(doc, pos, oldPos, dir, mayClear) {
  8715. var line = getLine(doc, pos.line);
  8716. if (line.markedSpans) { for (var i = 0; i < line.markedSpans.length; ++i) {
  8717. var sp = line.markedSpans[i], m = sp.marker;
  8718. // Determine if we should prevent the cursor being placed to the left/right of an atomic marker
  8719. // Historically this was determined using the inclusiveLeft/Right option, but the new way to control it
  8720. // is with selectLeft/Right
  8721. var preventCursorLeft = ("selectLeft" in m) ? !m.selectLeft : m.inclusiveLeft;
  8722. var preventCursorRight = ("selectRight" in m) ? !m.selectRight : m.inclusiveRight;
  8723. if ((sp.from == null || (preventCursorLeft ? sp.from <= pos.ch : sp.from < pos.ch)) &&
  8724. (sp.to == null || (preventCursorRight ? sp.to >= pos.ch : sp.to > pos.ch))) {
  8725. if (mayClear) {
  8726. signal(m, "beforeCursorEnter");
  8727. if (m.explicitlyCleared) {
  8728. if (!line.markedSpans) { break }
  8729. else {--i; continue}
  8730. }
  8731. }
  8732. if (!m.atomic) { continue }
  8733. if (oldPos) {
  8734. var near = m.find(dir < 0 ? 1 : -1), diff = (void 0);
  8735. if (dir < 0 ? preventCursorRight : preventCursorLeft)
  8736. { near = movePos(doc, near, -dir, near && near.line == pos.line ? line : null); }
  8737. if (near && near.line == pos.line && (diff = cmp(near, oldPos)) && (dir < 0 ? diff < 0 : diff > 0))
  8738. { return skipAtomicInner(doc, near, pos, dir, mayClear) }
  8739. }
  8740. var far = m.find(dir < 0 ? -1 : 1);
  8741. if (dir < 0 ? preventCursorLeft : preventCursorRight)
  8742. { far = movePos(doc, far, dir, far.line == pos.line ? line : null); }
  8743. return far ? skipAtomicInner(doc, far, pos, dir, mayClear) : null
  8744. }
  8745. } }
  8746. return pos
  8747. }
  8748. // Ensure a given position is not inside an atomic range.
  8749. function skipAtomic(doc, pos, oldPos, bias, mayClear) {
  8750. var dir = bias || 1;
  8751. var found = skipAtomicInner(doc, pos, oldPos, dir, mayClear) ||
  8752. (!mayClear && skipAtomicInner(doc, pos, oldPos, dir, true)) ||
  8753. skipAtomicInner(doc, pos, oldPos, -dir, mayClear) ||
  8754. (!mayClear && skipAtomicInner(doc, pos, oldPos, -dir, true));
  8755. if (!found) {
  8756. doc.cantEdit = true;
  8757. return Pos(doc.first, 0)
  8758. }
  8759. return found
  8760. }
  8761. function movePos(doc, pos, dir, line) {
  8762. if (dir < 0 && pos.ch == 0) {
  8763. if (pos.line > doc.first) { return clipPos(doc, Pos(pos.line - 1)) }
  8764. else { return null }
  8765. } else if (dir > 0 && pos.ch == (line || getLine(doc, pos.line)).text.length) {
  8766. if (pos.line < doc.first + doc.size - 1) { return Pos(pos.line + 1, 0) }
  8767. else { return null }
  8768. } else {
  8769. return new Pos(pos.line, pos.ch + dir)
  8770. }
  8771. }
  8772. function selectAll(cm) {
  8773. cm.setSelection(Pos(cm.firstLine(), 0), Pos(cm.lastLine()), sel_dontScroll);
  8774. }
  8775. // UPDATING
  8776. // Allow "beforeChange" event handlers to influence a change
  8777. function filterChange(doc, change, update) {
  8778. var obj = {
  8779. canceled: false,
  8780. from: change.from,
  8781. to: change.to,
  8782. text: change.text,
  8783. origin: change.origin,
  8784. cancel: function () { return obj.canceled = true; }
  8785. };
  8786. if (update) { obj.update = function (from, to, text, origin) {
  8787. if (from) { obj.from = clipPos(doc, from); }
  8788. if (to) { obj.to = clipPos(doc, to); }
  8789. if (text) { obj.text = text; }
  8790. if (origin !== undefined) { obj.origin = origin; }
  8791. }; }
  8792. signal(doc, "beforeChange", doc, obj);
  8793. if (doc.cm) { signal(doc.cm, "beforeChange", doc.cm, obj); }
  8794. if (obj.canceled) {
  8795. if (doc.cm) { doc.cm.curOp.updateInput = 2; }
  8796. return null
  8797. }
  8798. return {from: obj.from, to: obj.to, text: obj.text, origin: obj.origin}
  8799. }
  8800. // Apply a change to a document, and add it to the document's
  8801. // history, and propagating it to all linked documents.
  8802. function makeChange(doc, change, ignoreReadOnly) {
  8803. if (doc.cm) {
  8804. if (!doc.cm.curOp) { return operation(doc.cm, makeChange)(doc, change, ignoreReadOnly) }
  8805. if (doc.cm.state.suppressEdits) { return }
  8806. }
  8807. if (hasHandler(doc, "beforeChange") || doc.cm && hasHandler(doc.cm, "beforeChange")) {
  8808. change = filterChange(doc, change, true);
  8809. if (!change) { return }
  8810. }
  8811. // Possibly split or suppress the update based on the presence
  8812. // of read-only spans in its range.
  8813. var split = sawReadOnlySpans && !ignoreReadOnly && removeReadOnlyRanges(doc, change.from, change.to);
  8814. if (split) {
  8815. for (var i = split.length - 1; i >= 0; --i)
  8816. { makeChangeInner(doc, {from: split[i].from, to: split[i].to, text: i ? [""] : change.text, origin: change.origin}); }
  8817. } else {
  8818. makeChangeInner(doc, change);
  8819. }
  8820. }
  8821. function makeChangeInner(doc, change) {
  8822. if (change.text.length == 1 && change.text[0] == "" && cmp(change.from, change.to) == 0) { return }
  8823. var selAfter = computeSelAfterChange(doc, change);
  8824. addChangeToHistory(doc, change, selAfter, doc.cm ? doc.cm.curOp.id : NaN);
  8825. makeChangeSingleDoc(doc, change, selAfter, stretchSpansOverChange(doc, change));
  8826. var rebased = [];
  8827. linkedDocs(doc, function (doc, sharedHist) {
  8828. if (!sharedHist && indexOf(rebased, doc.history) == -1) {
  8829. rebaseHist(doc.history, change);
  8830. rebased.push(doc.history);
  8831. }
  8832. makeChangeSingleDoc(doc, change, null, stretchSpansOverChange(doc, change));
  8833. });
  8834. }
  8835. // Revert a change stored in a document's history.
  8836. function makeChangeFromHistory(doc, type, allowSelectionOnly) {
  8837. var suppress = doc.cm && doc.cm.state.suppressEdits;
  8838. if (suppress && !allowSelectionOnly) { return }
  8839. var hist = doc.history, event, selAfter = doc.sel;
  8840. var source = type == "undo" ? hist.done : hist.undone, dest = type == "undo" ? hist.undone : hist.done;
  8841. // Verify that there is a useable event (so that ctrl-z won't
  8842. // needlessly clear selection events)
  8843. var i = 0;
  8844. for (; i < source.length; i++) {
  8845. event = source[i];
  8846. if (allowSelectionOnly ? event.ranges && !event.equals(doc.sel) : !event.ranges)
  8847. { break }
  8848. }
  8849. if (i == source.length) { return }
  8850. hist.lastOrigin = hist.lastSelOrigin = null;
  8851. for (;;) {
  8852. event = source.pop();
  8853. if (event.ranges) {
  8854. pushSelectionToHistory(event, dest);
  8855. if (allowSelectionOnly && !event.equals(doc.sel)) {
  8856. setSelection(doc, event, {clearRedo: false});
  8857. return
  8858. }
  8859. selAfter = event;
  8860. } else if (suppress) {
  8861. source.push(event);
  8862. return
  8863. } else { break }
  8864. }
  8865. // Build up a reverse change object to add to the opposite history
  8866. // stack (redo when undoing, and vice versa).
  8867. var antiChanges = [];
  8868. pushSelectionToHistory(selAfter, dest);
  8869. dest.push({changes: antiChanges, generation: hist.generation});
  8870. hist.generation = event.generation || ++hist.maxGeneration;
  8871. var filter = hasHandler(doc, "beforeChange") || doc.cm && hasHandler(doc.cm, "beforeChange");
  8872. var loop = function ( i ) {
  8873. var change = event.changes[i];
  8874. change.origin = type;
  8875. if (filter && !filterChange(doc, change, false)) {
  8876. source.length = 0;
  8877. return {}
  8878. }
  8879. antiChanges.push(historyChangeFromChange(doc, change));
  8880. var after = i ? computeSelAfterChange(doc, change) : lst(source);
  8881. makeChangeSingleDoc(doc, change, after, mergeOldSpans(doc, change));
  8882. if (!i && doc.cm) { doc.cm.scrollIntoView({from: change.from, to: changeEnd(change)}); }
  8883. var rebased = [];
  8884. // Propagate to the linked documents
  8885. linkedDocs(doc, function (doc, sharedHist) {
  8886. if (!sharedHist && indexOf(rebased, doc.history) == -1) {
  8887. rebaseHist(doc.history, change);
  8888. rebased.push(doc.history);
  8889. }
  8890. makeChangeSingleDoc(doc, change, null, mergeOldSpans(doc, change));
  8891. });
  8892. };
  8893. for (var i$1 = event.changes.length - 1; i$1 >= 0; --i$1) {
  8894. var returned = loop( i$1 );
  8895. if ( returned ) return returned.v;
  8896. }
  8897. }
  8898. // Sub-views need their line numbers shifted when text is added
  8899. // above or below them in the parent document.
  8900. function shiftDoc(doc, distance) {
  8901. if (distance == 0) { return }
  8902. doc.first += distance;
  8903. doc.sel = new Selection(map(doc.sel.ranges, function (range) { return new Range(
  8904. Pos(range.anchor.line + distance, range.anchor.ch),
  8905. Pos(range.head.line + distance, range.head.ch)
  8906. ); }), doc.sel.primIndex);
  8907. if (doc.cm) {
  8908. regChange(doc.cm, doc.first, doc.first - distance, distance);
  8909. for (var d = doc.cm.display, l = d.viewFrom; l < d.viewTo; l++)
  8910. { regLineChange(doc.cm, l, "gutter"); }
  8911. }
  8912. }
  8913. // More lower-level change function, handling only a single document
  8914. // (not linked ones).
  8915. function makeChangeSingleDoc(doc, change, selAfter, spans) {
  8916. if (doc.cm && !doc.cm.curOp)
  8917. { return operation(doc.cm, makeChangeSingleDoc)(doc, change, selAfter, spans) }
  8918. if (change.to.line < doc.first) {
  8919. shiftDoc(doc, change.text.length - 1 - (change.to.line - change.from.line));
  8920. return
  8921. }
  8922. if (change.from.line > doc.lastLine()) { return }
  8923. // Clip the change to the size of this doc
  8924. if (change.from.line < doc.first) {
  8925. var shift = change.text.length - 1 - (doc.first - change.from.line);
  8926. shiftDoc(doc, shift);
  8927. change = {from: Pos(doc.first, 0), to: Pos(change.to.line + shift, change.to.ch),
  8928. text: [lst(change.text)], origin: change.origin};
  8929. }
  8930. var last = doc.lastLine();
  8931. if (change.to.line > last) {
  8932. change = {from: change.from, to: Pos(last, getLine(doc, last).text.length),
  8933. text: [change.text[0]], origin: change.origin};
  8934. }
  8935. change.removed = getBetween(doc, change.from, change.to);
  8936. if (!selAfter) { selAfter = computeSelAfterChange(doc, change); }
  8937. if (doc.cm) { makeChangeSingleDocInEditor(doc.cm, change, spans); }
  8938. else { updateDoc(doc, change, spans); }
  8939. setSelectionNoUndo(doc, selAfter, sel_dontScroll);
  8940. if (doc.cantEdit && skipAtomic(doc, Pos(doc.firstLine(), 0)))
  8941. { doc.cantEdit = false; }
  8942. }
  8943. // Handle the interaction of a change to a document with the editor
  8944. // that this document is part of.
  8945. function makeChangeSingleDocInEditor(cm, change, spans) {
  8946. var doc = cm.doc, display = cm.display, from = change.from, to = change.to;
  8947. var recomputeMaxLength = false, checkWidthStart = from.line;
  8948. if (!cm.options.lineWrapping) {
  8949. checkWidthStart = lineNo(visualLine(getLine(doc, from.line)));
  8950. doc.iter(checkWidthStart, to.line + 1, function (line) {
  8951. if (line == display.maxLine) {
  8952. recomputeMaxLength = true;
  8953. return true
  8954. }
  8955. });
  8956. }
  8957. if (doc.sel.contains(change.from, change.to) > -1)
  8958. { signalCursorActivity(cm); }
  8959. updateDoc(doc, change, spans, estimateHeight(cm));
  8960. if (!cm.options.lineWrapping) {
  8961. doc.iter(checkWidthStart, from.line + change.text.length, function (line) {
  8962. var len = lineLength(line);
  8963. if (len > display.maxLineLength) {
  8964. display.maxLine = line;
  8965. display.maxLineLength = len;
  8966. display.maxLineChanged = true;
  8967. recomputeMaxLength = false;
  8968. }
  8969. });
  8970. if (recomputeMaxLength) { cm.curOp.updateMaxLine = true; }
  8971. }
  8972. retreatFrontier(doc, from.line);
  8973. startWorker(cm, 400);
  8974. var lendiff = change.text.length - (to.line - from.line) - 1;
  8975. // Remember that these lines changed, for updating the display
  8976. if (change.full)
  8977. { regChange(cm); }
  8978. else if (from.line == to.line && change.text.length == 1 && !isWholeLineUpdate(cm.doc, change))
  8979. { regLineChange(cm, from.line, "text"); }
  8980. else
  8981. { regChange(cm, from.line, to.line + 1, lendiff); }
  8982. var changesHandler = hasHandler(cm, "changes"), changeHandler = hasHandler(cm, "change");
  8983. if (changeHandler || changesHandler) {
  8984. var obj = {
  8985. from: from, to: to,
  8986. text: change.text,
  8987. removed: change.removed,
  8988. origin: change.origin
  8989. };
  8990. if (changeHandler) { signalLater(cm, "change", cm, obj); }
  8991. if (changesHandler) { (cm.curOp.changeObjs || (cm.curOp.changeObjs = [])).push(obj); }
  8992. }
  8993. cm.display.selForContextMenu = null;
  8994. }
  8995. function replaceRange(doc, code, from, to, origin) {
  8996. var assign;
  8997. if (!to) { to = from; }
  8998. if (cmp(to, from) < 0) { (assign = [to, from], from = assign[0], to = assign[1]); }
  8999. if (typeof code == "string") { code = doc.splitLines(code); }
  9000. makeChange(doc, {from: from, to: to, text: code, origin: origin});
  9001. }
  9002. // Rebasing/resetting history to deal with externally-sourced changes
  9003. function rebaseHistSelSingle(pos, from, to, diff) {
  9004. if (to < pos.line) {
  9005. pos.line += diff;
  9006. } else if (from < pos.line) {
  9007. pos.line = from;
  9008. pos.ch = 0;
  9009. }
  9010. }
  9011. // Tries to rebase an array of history events given a change in the
  9012. // document. If the change touches the same lines as the event, the
  9013. // event, and everything 'behind' it, is discarded. If the change is
  9014. // before the event, the event's positions are updated. Uses a
  9015. // copy-on-write scheme for the positions, to avoid having to
  9016. // reallocate them all on every rebase, but also avoid problems with
  9017. // shared position objects being unsafely updated.
  9018. function rebaseHistArray(array, from, to, diff) {
  9019. for (var i = 0; i < array.length; ++i) {
  9020. var sub = array[i], ok = true;
  9021. if (sub.ranges) {
  9022. if (!sub.copied) { sub = array[i] = sub.deepCopy(); sub.copied = true; }
  9023. for (var j = 0; j < sub.ranges.length; j++) {
  9024. rebaseHistSelSingle(sub.ranges[j].anchor, from, to, diff);
  9025. rebaseHistSelSingle(sub.ranges[j].head, from, to, diff);
  9026. }
  9027. continue
  9028. }
  9029. for (var j$1 = 0; j$1 < sub.changes.length; ++j$1) {
  9030. var cur = sub.changes[j$1];
  9031. if (to < cur.from.line) {
  9032. cur.from = Pos(cur.from.line + diff, cur.from.ch);
  9033. cur.to = Pos(cur.to.line + diff, cur.to.ch);
  9034. } else if (from <= cur.to.line) {
  9035. ok = false;
  9036. break
  9037. }
  9038. }
  9039. if (!ok) {
  9040. array.splice(0, i + 1);
  9041. i = 0;
  9042. }
  9043. }
  9044. }
  9045. function rebaseHist(hist, change) {
  9046. var from = change.from.line, to = change.to.line, diff = change.text.length - (to - from) - 1;
  9047. rebaseHistArray(hist.done, from, to, diff);
  9048. rebaseHistArray(hist.undone, from, to, diff);
  9049. }
  9050. // Utility for applying a change to a line by handle or number,
  9051. // returning the number and optionally registering the line as
  9052. // changed.
  9053. function changeLine(doc, handle, changeType, op) {
  9054. var no = handle, line = handle;
  9055. if (typeof handle == "number") { line = getLine(doc, clipLine(doc, handle)); }
  9056. else { no = lineNo(handle); }
  9057. if (no == null) { return null }
  9058. if (op(line, no) && doc.cm) { regLineChange(doc.cm, no, changeType); }
  9059. return line
  9060. }
  9061. // The document is represented as a BTree consisting of leaves, with
  9062. // chunk of lines in them, and branches, with up to ten leaves or
  9063. // other branch nodes below them. The top node is always a branch
  9064. // node, and is the document object itself (meaning it has
  9065. // additional methods and properties).
  9066. //
  9067. // All nodes have parent links. The tree is used both to go from
  9068. // line numbers to line objects, and to go from objects to numbers.
  9069. // It also indexes by height, and is used to convert between height
  9070. // and line object, and to find the total height of the document.
  9071. //
  9072. // See also http://marijnhaverbeke.nl/blog/codemirror-line-tree.html
  9073. function LeafChunk(lines) {
  9074. var this$1 = this;
  9075. this.lines = lines;
  9076. this.parent = null;
  9077. var height = 0;
  9078. for (var i = 0; i < lines.length; ++i) {
  9079. lines[i].parent = this$1;
  9080. height += lines[i].height;
  9081. }
  9082. this.height = height;
  9083. }
  9084. LeafChunk.prototype = {
  9085. chunkSize: function() { return this.lines.length },
  9086. // Remove the n lines at offset 'at'.
  9087. removeInner: function(at, n) {
  9088. var this$1 = this;
  9089. for (var i = at, e = at + n; i < e; ++i) {
  9090. var line = this$1.lines[i];
  9091. this$1.height -= line.height;
  9092. cleanUpLine(line);
  9093. signalLater(line, "delete");
  9094. }
  9095. this.lines.splice(at, n);
  9096. },
  9097. // Helper used to collapse a small branch into a single leaf.
  9098. collapse: function(lines) {
  9099. lines.push.apply(lines, this.lines);
  9100. },
  9101. // Insert the given array of lines at offset 'at', count them as
  9102. // having the given height.
  9103. insertInner: function(at, lines, height) {
  9104. var this$1 = this;
  9105. this.height += height;
  9106. this.lines = this.lines.slice(0, at).concat(lines).concat(this.lines.slice(at));
  9107. for (var i = 0; i < lines.length; ++i) { lines[i].parent = this$1; }
  9108. },
  9109. // Used to iterate over a part of the tree.
  9110. iterN: function(at, n, op) {
  9111. var this$1 = this;
  9112. for (var e = at + n; at < e; ++at)
  9113. { if (op(this$1.lines[at])) { return true } }
  9114. }
  9115. };
  9116. function BranchChunk(children) {
  9117. var this$1 = this;
  9118. this.children = children;
  9119. var size = 0, height = 0;
  9120. for (var i = 0; i < children.length; ++i) {
  9121. var ch = children[i];
  9122. size += ch.chunkSize(); height += ch.height;
  9123. ch.parent = this$1;
  9124. }
  9125. this.size = size;
  9126. this.height = height;
  9127. this.parent = null;
  9128. }
  9129. BranchChunk.prototype = {
  9130. chunkSize: function() { return this.size },
  9131. removeInner: function(at, n) {
  9132. var this$1 = this;
  9133. this.size -= n;
  9134. for (var i = 0; i < this.children.length; ++i) {
  9135. var child = this$1.children[i], sz = child.chunkSize();
  9136. if (at < sz) {
  9137. var rm = Math.min(n, sz - at), oldHeight = child.height;
  9138. child.removeInner(at, rm);
  9139. this$1.height -= oldHeight - child.height;
  9140. if (sz == rm) { this$1.children.splice(i--, 1); child.parent = null; }
  9141. if ((n -= rm) == 0) { break }
  9142. at = 0;
  9143. } else { at -= sz; }
  9144. }
  9145. // If the result is smaller than 25 lines, ensure that it is a
  9146. // single leaf node.
  9147. if (this.size - n < 25 &&
  9148. (this.children.length > 1 || !(this.children[0] instanceof LeafChunk))) {
  9149. var lines = [];
  9150. this.collapse(lines);
  9151. this.children = [new LeafChunk(lines)];
  9152. this.children[0].parent = this;
  9153. }
  9154. },
  9155. collapse: function(lines) {
  9156. var this$1 = this;
  9157. for (var i = 0; i < this.children.length; ++i) { this$1.children[i].collapse(lines); }
  9158. },
  9159. insertInner: function(at, lines, height) {
  9160. var this$1 = this;
  9161. this.size += lines.length;
  9162. this.height += height;
  9163. for (var i = 0; i < this.children.length; ++i) {
  9164. var child = this$1.children[i], sz = child.chunkSize();
  9165. if (at <= sz) {
  9166. child.insertInner(at, lines, height);
  9167. if (child.lines && child.lines.length > 50) {
  9168. // To avoid memory thrashing when child.lines is huge (e.g. first view of a large file), it's never spliced.
  9169. // Instead, small slices are taken. They're taken in order because sequential memory accesses are fastest.
  9170. var remaining = child.lines.length % 25 + 25;
  9171. for (var pos = remaining; pos < child.lines.length;) {
  9172. var leaf = new LeafChunk(child.lines.slice(pos, pos += 25));
  9173. child.height -= leaf.height;
  9174. this$1.children.splice(++i, 0, leaf);
  9175. leaf.parent = this$1;
  9176. }
  9177. child.lines = child.lines.slice(0, remaining);
  9178. this$1.maybeSpill();
  9179. }
  9180. break
  9181. }
  9182. at -= sz;
  9183. }
  9184. },
  9185. // When a node has grown, check whether it should be split.
  9186. maybeSpill: function() {
  9187. if (this.children.length <= 10) { return }
  9188. var me = this;
  9189. do {
  9190. var spilled = me.children.splice(me.children.length - 5, 5);
  9191. var sibling = new BranchChunk(spilled);
  9192. if (!me.parent) { // Become the parent node
  9193. var copy = new BranchChunk(me.children);
  9194. copy.parent = me;
  9195. me.children = [copy, sibling];
  9196. me = copy;
  9197. } else {
  9198. me.size -= sibling.size;
  9199. me.height -= sibling.height;
  9200. var myIndex = indexOf(me.parent.children, me);
  9201. me.parent.children.splice(myIndex + 1, 0, sibling);
  9202. }
  9203. sibling.parent = me.parent;
  9204. } while (me.children.length > 10)
  9205. me.parent.maybeSpill();
  9206. },
  9207. iterN: function(at, n, op) {
  9208. var this$1 = this;
  9209. for (var i = 0; i < this.children.length; ++i) {
  9210. var child = this$1.children[i], sz = child.chunkSize();
  9211. if (at < sz) {
  9212. var used = Math.min(n, sz - at);
  9213. if (child.iterN(at, used, op)) { return true }
  9214. if ((n -= used) == 0) { break }
  9215. at = 0;
  9216. } else { at -= sz; }
  9217. }
  9218. }
  9219. };
  9220. // Line widgets are block elements displayed above or below a line.
  9221. var LineWidget = function(doc, node, options) {
  9222. var this$1 = this;
  9223. if (options) { for (var opt in options) { if (options.hasOwnProperty(opt))
  9224. { this$1[opt] = options[opt]; } } }
  9225. this.doc = doc;
  9226. this.node = node;
  9227. };
  9228. LineWidget.prototype.clear = function () {
  9229. var this$1 = this;
  9230. var cm = this.doc.cm, ws = this.line.widgets, line = this.line, no = lineNo(line);
  9231. if (no == null || !ws) { return }
  9232. for (var i = 0; i < ws.length; ++i) { if (ws[i] == this$1) { ws.splice(i--, 1); } }
  9233. if (!ws.length) { line.widgets = null; }
  9234. var height = widgetHeight(this);
  9235. updateLineHeight(line, Math.max(0, line.height - height));
  9236. if (cm) {
  9237. runInOp(cm, function () {
  9238. adjustScrollWhenAboveVisible(cm, line, -height);
  9239. regLineChange(cm, no, "widget");
  9240. });
  9241. signalLater(cm, "lineWidgetCleared", cm, this, no);
  9242. }
  9243. };
  9244. LineWidget.prototype.changed = function () {
  9245. var this$1 = this;
  9246. var oldH = this.height, cm = this.doc.cm, line = this.line;
  9247. this.height = null;
  9248. var diff = widgetHeight(this) - oldH;
  9249. if (!diff) { return }
  9250. if (!lineIsHidden(this.doc, line)) { updateLineHeight(line, line.height + diff); }
  9251. if (cm) {
  9252. runInOp(cm, function () {
  9253. cm.curOp.forceUpdate = true;
  9254. adjustScrollWhenAboveVisible(cm, line, diff);
  9255. signalLater(cm, "lineWidgetChanged", cm, this$1, lineNo(line));
  9256. });
  9257. }
  9258. };
  9259. eventMixin(LineWidget);
  9260. function adjustScrollWhenAboveVisible(cm, line, diff) {
  9261. if (heightAtLine(line) < ((cm.curOp && cm.curOp.scrollTop) || cm.doc.scrollTop))
  9262. { addToScrollTop(cm, diff); }
  9263. }
  9264. function addLineWidget(doc, handle, node, options) {
  9265. var widget = new LineWidget(doc, node, options);
  9266. var cm = doc.cm;
  9267. if (cm && widget.noHScroll) { cm.display.alignWidgets = true; }
  9268. changeLine(doc, handle, "widget", function (line) {
  9269. var widgets = line.widgets || (line.widgets = []);
  9270. if (widget.insertAt == null) { widgets.push(widget); }
  9271. else { widgets.splice(Math.min(widgets.length - 1, Math.max(0, widget.insertAt)), 0, widget); }
  9272. widget.line = line;
  9273. if (cm && !lineIsHidden(doc, line)) {
  9274. var aboveVisible = heightAtLine(line) < doc.scrollTop;
  9275. updateLineHeight(line, line.height + widgetHeight(widget));
  9276. if (aboveVisible) { addToScrollTop(cm, widget.height); }
  9277. cm.curOp.forceUpdate = true;
  9278. }
  9279. return true
  9280. });
  9281. if (cm) { signalLater(cm, "lineWidgetAdded", cm, widget, typeof handle == "number" ? handle : lineNo(handle)); }
  9282. return widget
  9283. }
  9284. // TEXTMARKERS
  9285. // Created with markText and setBookmark methods. A TextMarker is a
  9286. // handle that can be used to clear or find a marked position in the
  9287. // document. Line objects hold arrays (markedSpans) containing
  9288. // {from, to, marker} object pointing to such marker objects, and
  9289. // indicating that such a marker is present on that line. Multiple
  9290. // lines may point to the same marker when it spans across lines.
  9291. // The spans will have null for their from/to properties when the
  9292. // marker continues beyond the start/end of the line. Markers have
  9293. // links back to the lines they currently touch.
  9294. // Collapsed markers have unique ids, in order to be able to order
  9295. // them, which is needed for uniquely determining an outer marker
  9296. // when they overlap (they may nest, but not partially overlap).
  9297. var nextMarkerId = 0;
  9298. var TextMarker = function(doc, type) {
  9299. this.lines = [];
  9300. this.type = type;
  9301. this.doc = doc;
  9302. this.id = ++nextMarkerId;
  9303. };
  9304. // Clear the marker.
  9305. TextMarker.prototype.clear = function () {
  9306. var this$1 = this;
  9307. if (this.explicitlyCleared) { return }
  9308. var cm = this.doc.cm, withOp = cm && !cm.curOp;
  9309. if (withOp) { startOperation(cm); }
  9310. if (hasHandler(this, "clear")) {
  9311. var found = this.find();
  9312. if (found) { signalLater(this, "clear", found.from, found.to); }
  9313. }
  9314. var min = null, max = null;
  9315. for (var i = 0; i < this.lines.length; ++i) {
  9316. var line = this$1.lines[i];
  9317. var span = getMarkedSpanFor(line.markedSpans, this$1);
  9318. if (cm && !this$1.collapsed) { regLineChange(cm, lineNo(line), "text"); }
  9319. else if (cm) {
  9320. if (span.to != null) { max = lineNo(line); }
  9321. if (span.from != null) { min = lineNo(line); }
  9322. }
  9323. line.markedSpans = removeMarkedSpan(line.markedSpans, span);
  9324. if (span.from == null && this$1.collapsed && !lineIsHidden(this$1.doc, line) && cm)
  9325. { updateLineHeight(line, textHeight(cm.display)); }
  9326. }
  9327. if (cm && this.collapsed && !cm.options.lineWrapping) { for (var i$1 = 0; i$1 < this.lines.length; ++i$1) {
  9328. var visual = visualLine(this$1.lines[i$1]), len = lineLength(visual);
  9329. if (len > cm.display.maxLineLength) {
  9330. cm.display.maxLine = visual;
  9331. cm.display.maxLineLength = len;
  9332. cm.display.maxLineChanged = true;
  9333. }
  9334. } }
  9335. if (min != null && cm && this.collapsed) { regChange(cm, min, max + 1); }
  9336. this.lines.length = 0;
  9337. this.explicitlyCleared = true;
  9338. if (this.atomic && this.doc.cantEdit) {
  9339. this.doc.cantEdit = false;
  9340. if (cm) { reCheckSelection(cm.doc); }
  9341. }
  9342. if (cm) { signalLater(cm, "markerCleared", cm, this, min, max); }
  9343. if (withOp) { endOperation(cm); }
  9344. if (this.parent) { this.parent.clear(); }
  9345. };
  9346. // Find the position of the marker in the document. Returns a {from,
  9347. // to} object by default. Side can be passed to get a specific side
  9348. // -- 0 (both), -1 (left), or 1 (right). When lineObj is true, the
  9349. // Pos objects returned contain a line object, rather than a line
  9350. // number (used to prevent looking up the same line twice).
  9351. TextMarker.prototype.find = function (side, lineObj) {
  9352. var this$1 = this;
  9353. if (side == null && this.type == "bookmark") { side = 1; }
  9354. var from, to;
  9355. for (var i = 0; i < this.lines.length; ++i) {
  9356. var line = this$1.lines[i];
  9357. var span = getMarkedSpanFor(line.markedSpans, this$1);
  9358. if (span.from != null) {
  9359. from = Pos(lineObj ? line : lineNo(line), span.from);
  9360. if (side == -1) { return from }
  9361. }
  9362. if (span.to != null) {
  9363. to = Pos(lineObj ? line : lineNo(line), span.to);
  9364. if (side == 1) { return to }
  9365. }
  9366. }
  9367. return from && {from: from, to: to}
  9368. };
  9369. // Signals that the marker's widget changed, and surrounding layout
  9370. // should be recomputed.
  9371. TextMarker.prototype.changed = function () {
  9372. var this$1 = this;
  9373. var pos = this.find(-1, true), widget = this, cm = this.doc.cm;
  9374. if (!pos || !cm) { return }
  9375. runInOp(cm, function () {
  9376. var line = pos.line, lineN = lineNo(pos.line);
  9377. var view = findViewForLine(cm, lineN);
  9378. if (view) {
  9379. clearLineMeasurementCacheFor(view);
  9380. cm.curOp.selectionChanged = cm.curOp.forceUpdate = true;
  9381. }
  9382. cm.curOp.updateMaxLine = true;
  9383. if (!lineIsHidden(widget.doc, line) && widget.height != null) {
  9384. var oldHeight = widget.height;
  9385. widget.height = null;
  9386. var dHeight = widgetHeight(widget) - oldHeight;
  9387. if (dHeight)
  9388. { updateLineHeight(line, line.height + dHeight); }
  9389. }
  9390. signalLater(cm, "markerChanged", cm, this$1);
  9391. });
  9392. };
  9393. TextMarker.prototype.attachLine = function (line) {
  9394. if (!this.lines.length && this.doc.cm) {
  9395. var op = this.doc.cm.curOp;
  9396. if (!op.maybeHiddenMarkers || indexOf(op.maybeHiddenMarkers, this) == -1)
  9397. { (op.maybeUnhiddenMarkers || (op.maybeUnhiddenMarkers = [])).push(this); }
  9398. }
  9399. this.lines.push(line);
  9400. };
  9401. TextMarker.prototype.detachLine = function (line) {
  9402. this.lines.splice(indexOf(this.lines, line), 1);
  9403. if (!this.lines.length && this.doc.cm) {
  9404. var op = this.doc.cm.curOp
  9405. ;(op.maybeHiddenMarkers || (op.maybeHiddenMarkers = [])).push(this);
  9406. }
  9407. };
  9408. eventMixin(TextMarker);
  9409. // Create a marker, wire it up to the right lines, and
  9410. function markText(doc, from, to, options, type) {
  9411. // Shared markers (across linked documents) are handled separately
  9412. // (markTextShared will call out to this again, once per
  9413. // document).
  9414. if (options && options.shared) { return markTextShared(doc, from, to, options, type) }
  9415. // Ensure we are in an operation.
  9416. if (doc.cm && !doc.cm.curOp) { return operation(doc.cm, markText)(doc, from, to, options, type) }
  9417. var marker = new TextMarker(doc, type), diff = cmp(from, to);
  9418. if (options) { copyObj(options, marker, false); }
  9419. // Don't connect empty markers unless clearWhenEmpty is false
  9420. if (diff > 0 || diff == 0 && marker.clearWhenEmpty !== false)
  9421. { return marker }
  9422. if (marker.replacedWith) {
  9423. // Showing up as a widget implies collapsed (widget replaces text)
  9424. marker.collapsed = true;
  9425. marker.widgetNode = eltP("span", [marker.replacedWith], "CodeMirror-widget");
  9426. if (!options.handleMouseEvents) { marker.widgetNode.setAttribute("cm-ignore-events", "true"); }
  9427. if (options.insertLeft) { marker.widgetNode.insertLeft = true; }
  9428. }
  9429. if (marker.collapsed) {
  9430. if (conflictingCollapsedRange(doc, from.line, from, to, marker) ||
  9431. from.line != to.line && conflictingCollapsedRange(doc, to.line, from, to, marker))
  9432. { throw new Error("Inserting collapsed marker partially overlapping an existing one") }
  9433. seeCollapsedSpans();
  9434. }
  9435. if (marker.addToHistory)
  9436. { addChangeToHistory(doc, {from: from, to: to, origin: "markText"}, doc.sel, NaN); }
  9437. var curLine = from.line, cm = doc.cm, updateMaxLine;
  9438. doc.iter(curLine, to.line + 1, function (line) {
  9439. if (cm && marker.collapsed && !cm.options.lineWrapping && visualLine(line) == cm.display.maxLine)
  9440. { updateMaxLine = true; }
  9441. if (marker.collapsed && curLine != from.line) { updateLineHeight(line, 0); }
  9442. addMarkedSpan(line, new MarkedSpan(marker,
  9443. curLine == from.line ? from.ch : null,
  9444. curLine == to.line ? to.ch : null));
  9445. ++curLine;
  9446. });
  9447. // lineIsHidden depends on the presence of the spans, so needs a second pass
  9448. if (marker.collapsed) { doc.iter(from.line, to.line + 1, function (line) {
  9449. if (lineIsHidden(doc, line)) { updateLineHeight(line, 0); }
  9450. }); }
  9451. if (marker.clearOnEnter) { on(marker, "beforeCursorEnter", function () { return marker.clear(); }); }
  9452. if (marker.readOnly) {
  9453. seeReadOnlySpans();
  9454. if (doc.history.done.length || doc.history.undone.length)
  9455. { doc.clearHistory(); }
  9456. }
  9457. if (marker.collapsed) {
  9458. marker.id = ++nextMarkerId;
  9459. marker.atomic = true;
  9460. }
  9461. if (cm) {
  9462. // Sync editor state
  9463. if (updateMaxLine) { cm.curOp.updateMaxLine = true; }
  9464. if (marker.collapsed)
  9465. { regChange(cm, from.line, to.line + 1); }
  9466. else if (marker.className || marker.startStyle || marker.endStyle || marker.css ||
  9467. marker.attributes || marker.title)
  9468. { for (var i = from.line; i <= to.line; i++) { regLineChange(cm, i, "text"); } }
  9469. if (marker.atomic) { reCheckSelection(cm.doc); }
  9470. signalLater(cm, "markerAdded", cm, marker);
  9471. }
  9472. return marker
  9473. }
  9474. // SHARED TEXTMARKERS
  9475. // A shared marker spans multiple linked documents. It is
  9476. // implemented as a meta-marker-object controlling multiple normal
  9477. // markers.
  9478. var SharedTextMarker = function(markers, primary) {
  9479. var this$1 = this;
  9480. this.markers = markers;
  9481. this.primary = primary;
  9482. for (var i = 0; i < markers.length; ++i)
  9483. { markers[i].parent = this$1; }
  9484. };
  9485. SharedTextMarker.prototype.clear = function () {
  9486. var this$1 = this;
  9487. if (this.explicitlyCleared) { return }
  9488. this.explicitlyCleared = true;
  9489. for (var i = 0; i < this.markers.length; ++i)
  9490. { this$1.markers[i].clear(); }
  9491. signalLater(this, "clear");
  9492. };
  9493. SharedTextMarker.prototype.find = function (side, lineObj) {
  9494. return this.primary.find(side, lineObj)
  9495. };
  9496. eventMixin(SharedTextMarker);
  9497. function markTextShared(doc, from, to, options, type) {
  9498. options = copyObj(options);
  9499. options.shared = false;
  9500. var markers = [markText(doc, from, to, options, type)], primary = markers[0];
  9501. var widget = options.widgetNode;
  9502. linkedDocs(doc, function (doc) {
  9503. if (widget) { options.widgetNode = widget.cloneNode(true); }
  9504. markers.push(markText(doc, clipPos(doc, from), clipPos(doc, to), options, type));
  9505. for (var i = 0; i < doc.linked.length; ++i)
  9506. { if (doc.linked[i].isParent) { return } }
  9507. primary = lst(markers);
  9508. });
  9509. return new SharedTextMarker(markers, primary)
  9510. }
  9511. function findSharedMarkers(doc) {
  9512. return doc.findMarks(Pos(doc.first, 0), doc.clipPos(Pos(doc.lastLine())), function (m) { return m.parent; })
  9513. }
  9514. function copySharedMarkers(doc, markers) {
  9515. for (var i = 0; i < markers.length; i++) {
  9516. var marker = markers[i], pos = marker.find();
  9517. var mFrom = doc.clipPos(pos.from), mTo = doc.clipPos(pos.to);
  9518. if (cmp(mFrom, mTo)) {
  9519. var subMark = markText(doc, mFrom, mTo, marker.primary, marker.primary.type);
  9520. marker.markers.push(subMark);
  9521. subMark.parent = marker;
  9522. }
  9523. }
  9524. }
  9525. function detachSharedMarkers(markers) {
  9526. var loop = function ( i ) {
  9527. var marker = markers[i], linked = [marker.primary.doc];
  9528. linkedDocs(marker.primary.doc, function (d) { return linked.push(d); });
  9529. for (var j = 0; j < marker.markers.length; j++) {
  9530. var subMarker = marker.markers[j];
  9531. if (indexOf(linked, subMarker.doc) == -1) {
  9532. subMarker.parent = null;
  9533. marker.markers.splice(j--, 1);
  9534. }
  9535. }
  9536. };
  9537. for (var i = 0; i < markers.length; i++) loop( i );
  9538. }
  9539. var nextDocId = 0;
  9540. var Doc = function(text, mode, firstLine, lineSep, direction) {
  9541. if (!(this instanceof Doc)) { return new Doc(text, mode, firstLine, lineSep, direction) }
  9542. if (firstLine == null) { firstLine = 0; }
  9543. BranchChunk.call(this, [new LeafChunk([new Line("", null)])]);
  9544. this.first = firstLine;
  9545. this.scrollTop = this.scrollLeft = 0;
  9546. this.cantEdit = false;
  9547. this.cleanGeneration = 1;
  9548. this.modeFrontier = this.highlightFrontier = firstLine;
  9549. var start = Pos(firstLine, 0);
  9550. this.sel = simpleSelection(start);
  9551. this.history = new History(null);
  9552. this.id = ++nextDocId;
  9553. this.modeOption = mode;
  9554. this.lineSep = lineSep;
  9555. this.direction = (direction == "rtl") ? "rtl" : "ltr";
  9556. this.extend = false;
  9557. if (typeof text == "string") { text = this.splitLines(text); }
  9558. updateDoc(this, {from: start, to: start, text: text});
  9559. setSelection(this, simpleSelection(start), sel_dontScroll);
  9560. };
  9561. Doc.prototype = createObj(BranchChunk.prototype, {
  9562. constructor: Doc,
  9563. // Iterate over the document. Supports two forms -- with only one
  9564. // argument, it calls that for each line in the document. With
  9565. // three, it iterates over the range given by the first two (with
  9566. // the second being non-inclusive).
  9567. iter: function(from, to, op) {
  9568. if (op) { this.iterN(from - this.first, to - from, op); }
  9569. else { this.iterN(this.first, this.first + this.size, from); }
  9570. },
  9571. // Non-public interface for adding and removing lines.
  9572. insert: function(at, lines) {
  9573. var height = 0;
  9574. for (var i = 0; i < lines.length; ++i) { height += lines[i].height; }
  9575. this.insertInner(at - this.first, lines, height);
  9576. },
  9577. remove: function(at, n) { this.removeInner(at - this.first, n); },
  9578. // From here, the methods are part of the public interface. Most
  9579. // are also available from CodeMirror (editor) instances.
  9580. getValue: function(lineSep) {
  9581. var lines = getLines(this, this.first, this.first + this.size);
  9582. if (lineSep === false) { return lines }
  9583. return lines.join(lineSep || this.lineSeparator())
  9584. },
  9585. setValue: docMethodOp(function(code) {
  9586. var top = Pos(this.first, 0), last = this.first + this.size - 1;
  9587. makeChange(this, {from: top, to: Pos(last, getLine(this, last).text.length),
  9588. text: this.splitLines(code), origin: "setValue", full: true}, true);
  9589. if (this.cm) { scrollToCoords(this.cm, 0, 0); }
  9590. setSelection(this, simpleSelection(top), sel_dontScroll);
  9591. }),
  9592. replaceRange: function(code, from, to, origin) {
  9593. from = clipPos(this, from);
  9594. to = to ? clipPos(this, to) : from;
  9595. replaceRange(this, code, from, to, origin);
  9596. },
  9597. getRange: function(from, to, lineSep) {
  9598. var lines = getBetween(this, clipPos(this, from), clipPos(this, to));
  9599. if (lineSep === false) { return lines }
  9600. return lines.join(lineSep || this.lineSeparator())
  9601. },
  9602. getLine: function(line) {var l = this.getLineHandle(line); return l && l.text},
  9603. getLineHandle: function(line) {if (isLine(this, line)) { return getLine(this, line) }},
  9604. getLineNumber: function(line) {return lineNo(line)},
  9605. getLineHandleVisualStart: function(line) {
  9606. if (typeof line == "number") { line = getLine(this, line); }
  9607. return visualLine(line)
  9608. },
  9609. lineCount: function() {return this.size},
  9610. firstLine: function() {return this.first},
  9611. lastLine: function() {return this.first + this.size - 1},
  9612. clipPos: function(pos) {return clipPos(this, pos)},
  9613. getCursor: function(start) {
  9614. var range$$1 = this.sel.primary(), pos;
  9615. if (start == null || start == "head") { pos = range$$1.head; }
  9616. else if (start == "anchor") { pos = range$$1.anchor; }
  9617. else if (start == "end" || start == "to" || start === false) { pos = range$$1.to(); }
  9618. else { pos = range$$1.from(); }
  9619. return pos
  9620. },
  9621. listSelections: function() { return this.sel.ranges },
  9622. somethingSelected: function() {return this.sel.somethingSelected()},
  9623. setCursor: docMethodOp(function(line, ch, options) {
  9624. setSimpleSelection(this, clipPos(this, typeof line == "number" ? Pos(line, ch || 0) : line), null, options);
  9625. }),
  9626. setSelection: docMethodOp(function(anchor, head, options) {
  9627. setSimpleSelection(this, clipPos(this, anchor), clipPos(this, head || anchor), options);
  9628. }),
  9629. extendSelection: docMethodOp(function(head, other, options) {
  9630. extendSelection(this, clipPos(this, head), other && clipPos(this, other), options);
  9631. }),
  9632. extendSelections: docMethodOp(function(heads, options) {
  9633. extendSelections(this, clipPosArray(this, heads), options);
  9634. }),
  9635. extendSelectionsBy: docMethodOp(function(f, options) {
  9636. var heads = map(this.sel.ranges, f);
  9637. extendSelections(this, clipPosArray(this, heads), options);
  9638. }),
  9639. setSelections: docMethodOp(function(ranges, primary, options) {
  9640. var this$1 = this;
  9641. if (!ranges.length) { return }
  9642. var out = [];
  9643. for (var i = 0; i < ranges.length; i++)
  9644. { out[i] = new Range(clipPos(this$1, ranges[i].anchor),
  9645. clipPos(this$1, ranges[i].head)); }
  9646. if (primary == null) { primary = Math.min(ranges.length - 1, this.sel.primIndex); }
  9647. setSelection(this, normalizeSelection(this.cm, out, primary), options);
  9648. }),
  9649. addSelection: docMethodOp(function(anchor, head, options) {
  9650. var ranges = this.sel.ranges.slice(0);
  9651. ranges.push(new Range(clipPos(this, anchor), clipPos(this, head || anchor)));
  9652. setSelection(this, normalizeSelection(this.cm, ranges, ranges.length - 1), options);
  9653. }),
  9654. getSelection: function(lineSep) {
  9655. var this$1 = this;
  9656. var ranges = this.sel.ranges, lines;
  9657. for (var i = 0; i < ranges.length; i++) {
  9658. var sel = getBetween(this$1, ranges[i].from(), ranges[i].to());
  9659. lines = lines ? lines.concat(sel) : sel;
  9660. }
  9661. if (lineSep === false) { return lines }
  9662. else { return lines.join(lineSep || this.lineSeparator()) }
  9663. },
  9664. getSelections: function(lineSep) {
  9665. var this$1 = this;
  9666. var parts = [], ranges = this.sel.ranges;
  9667. for (var i = 0; i < ranges.length; i++) {
  9668. var sel = getBetween(this$1, ranges[i].from(), ranges[i].to());
  9669. if (lineSep !== false) { sel = sel.join(lineSep || this$1.lineSeparator()); }
  9670. parts[i] = sel;
  9671. }
  9672. return parts
  9673. },
  9674. replaceSelection: function(code, collapse, origin) {
  9675. var dup = [];
  9676. for (var i = 0; i < this.sel.ranges.length; i++)
  9677. { dup[i] = code; }
  9678. this.replaceSelections(dup, collapse, origin || "+input");
  9679. },
  9680. replaceSelections: docMethodOp(function(code, collapse, origin) {
  9681. var this$1 = this;
  9682. var changes = [], sel = this.sel;
  9683. for (var i = 0; i < sel.ranges.length; i++) {
  9684. var range$$1 = sel.ranges[i];
  9685. changes[i] = {from: range$$1.from(), to: range$$1.to(), text: this$1.splitLines(code[i]), origin: origin};
  9686. }
  9687. var newSel = collapse && collapse != "end" && computeReplacedSel(this, changes, collapse);
  9688. for (var i$1 = changes.length - 1; i$1 >= 0; i$1--)
  9689. { makeChange(this$1, changes[i$1]); }
  9690. if (newSel) { setSelectionReplaceHistory(this, newSel); }
  9691. else if (this.cm) { ensureCursorVisible(this.cm); }
  9692. }),
  9693. undo: docMethodOp(function() {makeChangeFromHistory(this, "undo");}),
  9694. redo: docMethodOp(function() {makeChangeFromHistory(this, "redo");}),
  9695. undoSelection: docMethodOp(function() {makeChangeFromHistory(this, "undo", true);}),
  9696. redoSelection: docMethodOp(function() {makeChangeFromHistory(this, "redo", true);}),
  9697. setExtending: function(val) {this.extend = val;},
  9698. getExtending: function() {return this.extend},
  9699. historySize: function() {
  9700. var hist = this.history, done = 0, undone = 0;
  9701. for (var i = 0; i < hist.done.length; i++) { if (!hist.done[i].ranges) { ++done; } }
  9702. for (var i$1 = 0; i$1 < hist.undone.length; i$1++) { if (!hist.undone[i$1].ranges) { ++undone; } }
  9703. return {undo: done, redo: undone}
  9704. },
  9705. clearHistory: function() {this.history = new History(this.history.maxGeneration);},
  9706. markClean: function() {
  9707. this.cleanGeneration = this.changeGeneration(true);
  9708. },
  9709. changeGeneration: function(forceSplit) {
  9710. if (forceSplit)
  9711. { this.history.lastOp = this.history.lastSelOp = this.history.lastOrigin = null; }
  9712. return this.history.generation
  9713. },
  9714. isClean: function (gen) {
  9715. return this.history.generation == (gen || this.cleanGeneration)
  9716. },
  9717. getHistory: function() {
  9718. return {done: copyHistoryArray(this.history.done),
  9719. undone: copyHistoryArray(this.history.undone)}
  9720. },
  9721. setHistory: function(histData) {
  9722. var hist = this.history = new History(this.history.maxGeneration);
  9723. hist.done = copyHistoryArray(histData.done.slice(0), null, true);
  9724. hist.undone = copyHistoryArray(histData.undone.slice(0), null, true);
  9725. },
  9726. setGutterMarker: docMethodOp(function(line, gutterID, value) {
  9727. return changeLine(this, line, "gutter", function (line) {
  9728. var markers = line.gutterMarkers || (line.gutterMarkers = {});
  9729. markers[gutterID] = value;
  9730. if (!value && isEmpty(markers)) { line.gutterMarkers = null; }
  9731. return true
  9732. })
  9733. }),
  9734. clearGutter: docMethodOp(function(gutterID) {
  9735. var this$1 = this;
  9736. this.iter(function (line) {
  9737. if (line.gutterMarkers && line.gutterMarkers[gutterID]) {
  9738. changeLine(this$1, line, "gutter", function () {
  9739. line.gutterMarkers[gutterID] = null;
  9740. if (isEmpty(line.gutterMarkers)) { line.gutterMarkers = null; }
  9741. return true
  9742. });
  9743. }
  9744. });
  9745. }),
  9746. lineInfo: function(line) {
  9747. var n;
  9748. if (typeof line == "number") {
  9749. if (!isLine(this, line)) { return null }
  9750. n = line;
  9751. line = getLine(this, line);
  9752. if (!line) { return null }
  9753. } else {
  9754. n = lineNo(line);
  9755. if (n == null) { return null }
  9756. }
  9757. return {line: n, handle: line, text: line.text, gutterMarkers: line.gutterMarkers,
  9758. textClass: line.textClass, bgClass: line.bgClass, wrapClass: line.wrapClass,
  9759. widgets: line.widgets}
  9760. },
  9761. addLineClass: docMethodOp(function(handle, where, cls) {
  9762. return changeLine(this, handle, where == "gutter" ? "gutter" : "class", function (line) {
  9763. var prop = where == "text" ? "textClass"
  9764. : where == "background" ? "bgClass"
  9765. : where == "gutter" ? "gutterClass" : "wrapClass";
  9766. if (!line[prop]) { line[prop] = cls; }
  9767. else if (classTest(cls).test(line[prop])) { return false }
  9768. else { line[prop] += " " + cls; }
  9769. return true
  9770. })
  9771. }),
  9772. removeLineClass: docMethodOp(function(handle, where, cls) {
  9773. return changeLine(this, handle, where == "gutter" ? "gutter" : "class", function (line) {
  9774. var prop = where == "text" ? "textClass"
  9775. : where == "background" ? "bgClass"
  9776. : where == "gutter" ? "gutterClass" : "wrapClass";
  9777. var cur = line[prop];
  9778. if (!cur) { return false }
  9779. else if (cls == null) { line[prop] = null; }
  9780. else {
  9781. var found = cur.match(classTest(cls));
  9782. if (!found) { return false }
  9783. var end = found.index + found[0].length;
  9784. line[prop] = cur.slice(0, found.index) + (!found.index || end == cur.length ? "" : " ") + cur.slice(end) || null;
  9785. }
  9786. return true
  9787. })
  9788. }),
  9789. addLineWidget: docMethodOp(function(handle, node, options) {
  9790. return addLineWidget(this, handle, node, options)
  9791. }),
  9792. removeLineWidget: function(widget) { widget.clear(); },
  9793. markText: function(from, to, options) {
  9794. return markText(this, clipPos(this, from), clipPos(this, to), options, options && options.type || "range")
  9795. },
  9796. setBookmark: function(pos, options) {
  9797. var realOpts = {replacedWith: options && (options.nodeType == null ? options.widget : options),
  9798. insertLeft: options && options.insertLeft,
  9799. clearWhenEmpty: false, shared: options && options.shared,
  9800. handleMouseEvents: options && options.handleMouseEvents};
  9801. pos = clipPos(this, pos);
  9802. return markText(this, pos, pos, realOpts, "bookmark")
  9803. },
  9804. findMarksAt: function(pos) {
  9805. pos = clipPos(this, pos);
  9806. var markers = [], spans = getLine(this, pos.line).markedSpans;
  9807. if (spans) { for (var i = 0; i < spans.length; ++i) {
  9808. var span = spans[i];
  9809. if ((span.from == null || span.from <= pos.ch) &&
  9810. (span.to == null || span.to >= pos.ch))
  9811. { markers.push(span.marker.parent || span.marker); }
  9812. } }
  9813. return markers
  9814. },
  9815. findMarks: function(from, to, filter) {
  9816. from = clipPos(this, from); to = clipPos(this, to);
  9817. var found = [], lineNo$$1 = from.line;
  9818. this.iter(from.line, to.line + 1, function (line) {
  9819. var spans = line.markedSpans;
  9820. if (spans) { for (var i = 0; i < spans.length; i++) {
  9821. var span = spans[i];
  9822. if (!(span.to != null && lineNo$$1 == from.line && from.ch >= span.to ||
  9823. span.from == null && lineNo$$1 != from.line ||
  9824. span.from != null && lineNo$$1 == to.line && span.from >= to.ch) &&
  9825. (!filter || filter(span.marker)))
  9826. { found.push(span.marker.parent || span.marker); }
  9827. } }
  9828. ++lineNo$$1;
  9829. });
  9830. return found
  9831. },
  9832. getAllMarks: function() {
  9833. var markers = [];
  9834. this.iter(function (line) {
  9835. var sps = line.markedSpans;
  9836. if (sps) { for (var i = 0; i < sps.length; ++i)
  9837. { if (sps[i].from != null) { markers.push(sps[i].marker); } } }
  9838. });
  9839. return markers
  9840. },
  9841. posFromIndex: function(off) {
  9842. var ch, lineNo$$1 = this.first, sepSize = this.lineSeparator().length;
  9843. this.iter(function (line) {
  9844. var sz = line.text.length + sepSize;
  9845. if (sz > off) { ch = off; return true }
  9846. off -= sz;
  9847. ++lineNo$$1;
  9848. });
  9849. return clipPos(this, Pos(lineNo$$1, ch))
  9850. },
  9851. indexFromPos: function (coords) {
  9852. coords = clipPos(this, coords);
  9853. var index = coords.ch;
  9854. if (coords.line < this.first || coords.ch < 0) { return 0 }
  9855. var sepSize = this.lineSeparator().length;
  9856. this.iter(this.first, coords.line, function (line) { // iter aborts when callback returns a truthy value
  9857. index += line.text.length + sepSize;
  9858. });
  9859. return index
  9860. },
  9861. copy: function(copyHistory) {
  9862. var doc = new Doc(getLines(this, this.first, this.first + this.size),
  9863. this.modeOption, this.first, this.lineSep, this.direction);
  9864. doc.scrollTop = this.scrollTop; doc.scrollLeft = this.scrollLeft;
  9865. doc.sel = this.sel;
  9866. doc.extend = false;
  9867. if (copyHistory) {
  9868. doc.history.undoDepth = this.history.undoDepth;
  9869. doc.setHistory(this.getHistory());
  9870. }
  9871. return doc
  9872. },
  9873. linkedDoc: function(options) {
  9874. if (!options) { options = {}; }
  9875. var from = this.first, to = this.first + this.size;
  9876. if (options.from != null && options.from > from) { from = options.from; }
  9877. if (options.to != null && options.to < to) { to = options.to; }
  9878. var copy = new Doc(getLines(this, from, to), options.mode || this.modeOption, from, this.lineSep, this.direction);
  9879. if (options.sharedHist) { copy.history = this.history
  9880. ; }(this.linked || (this.linked = [])).push({doc: copy, sharedHist: options.sharedHist});
  9881. copy.linked = [{doc: this, isParent: true, sharedHist: options.sharedHist}];
  9882. copySharedMarkers(copy, findSharedMarkers(this));
  9883. return copy
  9884. },
  9885. unlinkDoc: function(other) {
  9886. var this$1 = this;
  9887. if (other instanceof CodeMirror) { other = other.doc; }
  9888. if (this.linked) { for (var i = 0; i < this.linked.length; ++i) {
  9889. var link = this$1.linked[i];
  9890. if (link.doc != other) { continue }
  9891. this$1.linked.splice(i, 1);
  9892. other.unlinkDoc(this$1);
  9893. detachSharedMarkers(findSharedMarkers(this$1));
  9894. break
  9895. } }
  9896. // If the histories were shared, split them again
  9897. if (other.history == this.history) {
  9898. var splitIds = [other.id];
  9899. linkedDocs(other, function (doc) { return splitIds.push(doc.id); }, true);
  9900. other.history = new History(null);
  9901. other.history.done = copyHistoryArray(this.history.done, splitIds);
  9902. other.history.undone = copyHistoryArray(this.history.undone, splitIds);
  9903. }
  9904. },
  9905. iterLinkedDocs: function(f) {linkedDocs(this, f);},
  9906. getMode: function() {return this.mode},
  9907. getEditor: function() {return this.cm},
  9908. splitLines: function(str) {
  9909. if (this.lineSep) { return str.split(this.lineSep) }
  9910. return splitLinesAuto(str)
  9911. },
  9912. lineSeparator: function() { return this.lineSep || "\n" },
  9913. setDirection: docMethodOp(function (dir) {
  9914. if (dir != "rtl") { dir = "ltr"; }
  9915. if (dir == this.direction) { return }
  9916. this.direction = dir;
  9917. this.iter(function (line) { return line.order = null; });
  9918. if (this.cm) { directionChanged(this.cm); }
  9919. })
  9920. });
  9921. // Public alias.
  9922. Doc.prototype.eachLine = Doc.prototype.iter;
  9923. // Kludge to work around strange IE behavior where it'll sometimes
  9924. // re-fire a series of drag-related events right after the drop (#1551)
  9925. var lastDrop = 0;
  9926. function onDrop(e) {
  9927. var cm = this;
  9928. clearDragCursor(cm);
  9929. if (signalDOMEvent(cm, e) || eventInWidget(cm.display, e))
  9930. { return }
  9931. e_preventDefault(e);
  9932. if (ie) { lastDrop = +new Date; }
  9933. var pos = posFromMouse(cm, e, true), files = e.dataTransfer.files;
  9934. if (!pos || cm.isReadOnly()) { return }
  9935. // Might be a file drop, in which case we simply extract the text
  9936. // and insert it.
  9937. if (files && files.length && window.FileReader && window.File) {
  9938. var n = files.length, text = Array(n), read = 0;
  9939. var loadFile = function (file, i) {
  9940. if (cm.options.allowDropFileTypes &&
  9941. indexOf(cm.options.allowDropFileTypes, file.type) == -1)
  9942. { return }
  9943. var reader = new FileReader;
  9944. reader.onload = operation(cm, function () {
  9945. var content = reader.result;
  9946. if (/[\x00-\x08\x0e-\x1f]{2}/.test(content)) { content = ""; }
  9947. text[i] = content;
  9948. if (++read == n) {
  9949. pos = clipPos(cm.doc, pos);
  9950. var change = {from: pos, to: pos,
  9951. text: cm.doc.splitLines(text.join(cm.doc.lineSeparator())),
  9952. origin: "paste"};
  9953. makeChange(cm.doc, change);
  9954. setSelectionReplaceHistory(cm.doc, simpleSelection(pos, changeEnd(change)));
  9955. }
  9956. });
  9957. reader.readAsText(file);
  9958. };
  9959. for (var i = 0; i < n; ++i) { loadFile(files[i], i); }
  9960. } else { // Normal drop
  9961. // Don't do a replace if the drop happened inside of the selected text.
  9962. if (cm.state.draggingText && cm.doc.sel.contains(pos) > -1) {
  9963. cm.state.draggingText(e);
  9964. // Ensure the editor is re-focused
  9965. setTimeout(function () { return cm.display.input.focus(); }, 20);
  9966. return
  9967. }
  9968. try {
  9969. var text$1 = e.dataTransfer.getData("Text");
  9970. if (text$1) {
  9971. var selected;
  9972. if (cm.state.draggingText && !cm.state.draggingText.copy)
  9973. { selected = cm.listSelections(); }
  9974. setSelectionNoUndo(cm.doc, simpleSelection(pos, pos));
  9975. if (selected) { for (var i$1 = 0; i$1 < selected.length; ++i$1)
  9976. { replaceRange(cm.doc, "", selected[i$1].anchor, selected[i$1].head, "drag"); } }
  9977. cm.replaceSelection(text$1, "around", "paste");
  9978. cm.display.input.focus();
  9979. }
  9980. }
  9981. catch(e){}
  9982. }
  9983. }
  9984. function onDragStart(cm, e) {
  9985. if (ie && (!cm.state.draggingText || +new Date - lastDrop < 100)) { e_stop(e); return }
  9986. if (signalDOMEvent(cm, e) || eventInWidget(cm.display, e)) { return }
  9987. e.dataTransfer.setData("Text", cm.getSelection());
  9988. e.dataTransfer.effectAllowed = "copyMove";
  9989. // Use dummy image instead of default browsers image.
  9990. // Recent Safari (~6.0.2) have a tendency to segfault when this happens, so we don't do it there.
  9991. if (e.dataTransfer.setDragImage && !safari) {
  9992. var img = elt("img", null, null, "position: fixed; left: 0; top: 0;");
  9993. img.src = "data:image/gif;base64,R0lGODlhAQABAAAAACH5BAEKAAEALAAAAAABAAEAAAICTAEAOw==";
  9994. if (presto) {
  9995. img.width = img.height = 1;
  9996. cm.display.wrapper.appendChild(img);
  9997. // Force a relayout, or Opera won't use our image for some obscure reason
  9998. img._top = img.offsetTop;
  9999. }
  10000. e.dataTransfer.setDragImage(img, 0, 0);
  10001. if (presto) { img.parentNode.removeChild(img); }
  10002. }
  10003. }
  10004. function onDragOver(cm, e) {
  10005. var pos = posFromMouse(cm, e);
  10006. if (!pos) { return }
  10007. var frag = document.createDocumentFragment();
  10008. drawSelectionCursor(cm, pos, frag);
  10009. if (!cm.display.dragCursor) {
  10010. cm.display.dragCursor = elt("div", null, "CodeMirror-cursors CodeMirror-dragcursors");
  10011. cm.display.lineSpace.insertBefore(cm.display.dragCursor, cm.display.cursorDiv);
  10012. }
  10013. removeChildrenAndAdd(cm.display.dragCursor, frag);
  10014. }
  10015. function clearDragCursor(cm) {
  10016. if (cm.display.dragCursor) {
  10017. cm.display.lineSpace.removeChild(cm.display.dragCursor);
  10018. cm.display.dragCursor = null;
  10019. }
  10020. }
  10021. // These must be handled carefully, because naively registering a
  10022. // handler for each editor will cause the editors to never be
  10023. // garbage collected.
  10024. function forEachCodeMirror(f) {
  10025. if (!document.getElementsByClassName) { return }
  10026. var byClass = document.getElementsByClassName("CodeMirror"), editors = [];
  10027. for (var i = 0; i < byClass.length; i++) {
  10028. var cm = byClass[i].CodeMirror;
  10029. if (cm) { editors.push(cm); }
  10030. }
  10031. if (editors.length) { editors[0].operation(function () {
  10032. for (var i = 0; i < editors.length; i++) { f(editors[i]); }
  10033. }); }
  10034. }
  10035. var globalsRegistered = false;
  10036. function ensureGlobalHandlers() {
  10037. if (globalsRegistered) { return }
  10038. registerGlobalHandlers();
  10039. globalsRegistered = true;
  10040. }
  10041. function registerGlobalHandlers() {
  10042. // When the window resizes, we need to refresh active editors.
  10043. var resizeTimer;
  10044. on(window, "resize", function () {
  10045. if (resizeTimer == null) { resizeTimer = setTimeout(function () {
  10046. resizeTimer = null;
  10047. forEachCodeMirror(onResize);
  10048. }, 100); }
  10049. });
  10050. // When the window loses focus, we want to show the editor as blurred
  10051. on(window, "blur", function () { return forEachCodeMirror(onBlur); });
  10052. }
  10053. // Called when the window resizes
  10054. function onResize(cm) {
  10055. var d = cm.display;
  10056. // Might be a text scaling operation, clear size caches.
  10057. d.cachedCharWidth = d.cachedTextHeight = d.cachedPaddingH = null;
  10058. d.scrollbarsClipped = false;
  10059. cm.setSize();
  10060. }
  10061. var keyNames = {
  10062. 3: "Pause", 8: "Backspace", 9: "Tab", 13: "Enter", 16: "Shift", 17: "Ctrl", 18: "Alt",
  10063. 19: "Pause", 20: "CapsLock", 27: "Esc", 32: "Space", 33: "PageUp", 34: "PageDown", 35: "End",
  10064. 36: "Home", 37: "Left", 38: "Up", 39: "Right", 40: "Down", 44: "PrintScrn", 45: "Insert",
  10065. 46: "Delete", 59: ";", 61: "=", 91: "Mod", 92: "Mod", 93: "Mod",
  10066. 106: "*", 107: "=", 109: "-", 110: ".", 111: "/", 145: "ScrollLock",
  10067. 173: "-", 186: ";", 187: "=", 188: ",", 189: "-", 190: ".", 191: "/", 192: "`", 219: "[", 220: "\\",
  10068. 221: "]", 222: "'", 63232: "Up", 63233: "Down", 63234: "Left", 63235: "Right", 63272: "Delete",
  10069. 63273: "Home", 63275: "End", 63276: "PageUp", 63277: "PageDown", 63302: "Insert"
  10070. };
  10071. // Number keys
  10072. for (var i = 0; i < 10; i++) { keyNames[i + 48] = keyNames[i + 96] = String(i); }
  10073. // Alphabetic keys
  10074. for (var i$1 = 65; i$1 <= 90; i$1++) { keyNames[i$1] = String.fromCharCode(i$1); }
  10075. // Function keys
  10076. for (var i$2 = 1; i$2 <= 12; i$2++) { keyNames[i$2 + 111] = keyNames[i$2 + 63235] = "F" + i$2; }
  10077. var keyMap = {};
  10078. keyMap.basic = {
  10079. "Left": "goCharLeft", "Right": "goCharRight", "Up": "goLineUp", "Down": "goLineDown",
  10080. "End": "goLineEnd", "Home": "goLineStartSmart", "PageUp": "goPageUp", "PageDown": "goPageDown",
  10081. "Delete": "delCharAfter", "Backspace": "delCharBefore", "Shift-Backspace": "delCharBefore",
  10082. "Tab": "defaultTab", "Shift-Tab": "indentAuto",
  10083. "Enter": "newlineAndIndent", "Insert": "toggleOverwrite",
  10084. "Esc": "singleSelection"
  10085. };
  10086. // Note that the save and find-related commands aren't defined by
  10087. // default. User code or addons can define them. Unknown commands
  10088. // are simply ignored.
  10089. keyMap.pcDefault = {
  10090. "Ctrl-A": "selectAll", "Ctrl-D": "deleteLine", "Ctrl-Z": "undo", "Shift-Ctrl-Z": "redo", "Ctrl-Y": "redo",
  10091. "Ctrl-Home": "goDocStart", "Ctrl-End": "goDocEnd", "Ctrl-Up": "goLineUp", "Ctrl-Down": "goLineDown",
  10092. "Ctrl-Left": "goGroupLeft", "Ctrl-Right": "goGroupRight", "Alt-Left": "goLineStart", "Alt-Right": "goLineEnd",
  10093. "Ctrl-Backspace": "delGroupBefore", "Ctrl-Delete": "delGroupAfter", "Ctrl-S": "save", "Ctrl-F": "find",
  10094. "Ctrl-G": "findNext", "Shift-Ctrl-G": "findPrev", "Shift-Ctrl-F": "replace", "Shift-Ctrl-R": "replaceAll",
  10095. "Ctrl-[": "indentLess", "Ctrl-]": "indentMore",
  10096. "Ctrl-U": "undoSelection", "Shift-Ctrl-U": "redoSelection", "Alt-U": "redoSelection",
  10097. "fallthrough": "basic"
  10098. };
  10099. // Very basic readline/emacs-style bindings, which are standard on Mac.
  10100. keyMap.emacsy = {
  10101. "Ctrl-F": "goCharRight", "Ctrl-B": "goCharLeft", "Ctrl-P": "goLineUp", "Ctrl-N": "goLineDown",
  10102. "Alt-F": "goWordRight", "Alt-B": "goWordLeft", "Ctrl-A": "goLineStart", "Ctrl-E": "goLineEnd",
  10103. "Ctrl-V": "goPageDown", "Shift-Ctrl-V": "goPageUp", "Ctrl-D": "delCharAfter", "Ctrl-H": "delCharBefore",
  10104. "Alt-D": "delWordAfter", "Alt-Backspace": "delWordBefore", "Ctrl-K": "killLine", "Ctrl-T": "transposeChars",
  10105. "Ctrl-O": "openLine"
  10106. };
  10107. keyMap.macDefault = {
  10108. "Cmd-A": "selectAll", "Cmd-D": "deleteLine", "Cmd-Z": "undo", "Shift-Cmd-Z": "redo", "Cmd-Y": "redo",
  10109. "Cmd-Home": "goDocStart", "Cmd-Up": "goDocStart", "Cmd-End": "goDocEnd", "Cmd-Down": "goDocEnd", "Alt-Left": "goGroupLeft",
  10110. "Alt-Right": "goGroupRight", "Cmd-Left": "goLineLeft", "Cmd-Right": "goLineRight", "Alt-Backspace": "delGroupBefore",
  10111. "Ctrl-Alt-Backspace": "delGroupAfter", "Alt-Delete": "delGroupAfter", "Cmd-S": "save", "Cmd-F": "find",
  10112. "Cmd-G": "findNext", "Shift-Cmd-G": "findPrev", "Cmd-Alt-F": "replace", "Shift-Cmd-Alt-F": "replaceAll",
  10113. "Cmd-[": "indentLess", "Cmd-]": "indentMore", "Cmd-Backspace": "delWrappedLineLeft", "Cmd-Delete": "delWrappedLineRight",
  10114. "Cmd-U": "undoSelection", "Shift-Cmd-U": "redoSelection", "Ctrl-Up": "goDocStart", "Ctrl-Down": "goDocEnd",
  10115. "fallthrough": ["basic", "emacsy"]
  10116. };
  10117. keyMap["default"] = mac ? keyMap.macDefault : keyMap.pcDefault;
  10118. // KEYMAP DISPATCH
  10119. function normalizeKeyName(name) {
  10120. var parts = name.split(/-(?!$)/);
  10121. name = parts[parts.length - 1];
  10122. var alt, ctrl, shift, cmd;
  10123. for (var i = 0; i < parts.length - 1; i++) {
  10124. var mod = parts[i];
  10125. if (/^(cmd|meta|m)$/i.test(mod)) { cmd = true; }
  10126. else if (/^a(lt)?$/i.test(mod)) { alt = true; }
  10127. else if (/^(c|ctrl|control)$/i.test(mod)) { ctrl = true; }
  10128. else if (/^s(hift)?$/i.test(mod)) { shift = true; }
  10129. else { throw new Error("Unrecognized modifier name: " + mod) }
  10130. }
  10131. if (alt) { name = "Alt-" + name; }
  10132. if (ctrl) { name = "Ctrl-" + name; }
  10133. if (cmd) { name = "Cmd-" + name; }
  10134. if (shift) { name = "Shift-" + name; }
  10135. return name
  10136. }
  10137. // This is a kludge to keep keymaps mostly working as raw objects
  10138. // (backwards compatibility) while at the same time support features
  10139. // like normalization and multi-stroke key bindings. It compiles a
  10140. // new normalized keymap, and then updates the old object to reflect
  10141. // this.
  10142. function normalizeKeyMap(keymap) {
  10143. var copy = {};
  10144. for (var keyname in keymap) { if (keymap.hasOwnProperty(keyname)) {
  10145. var value = keymap[keyname];
  10146. if (/^(name|fallthrough|(de|at)tach)$/.test(keyname)) { continue }
  10147. if (value == "...") { delete keymap[keyname]; continue }
  10148. var keys = map(keyname.split(" "), normalizeKeyName);
  10149. for (var i = 0; i < keys.length; i++) {
  10150. var val = (void 0), name = (void 0);
  10151. if (i == keys.length - 1) {
  10152. name = keys.join(" ");
  10153. val = value;
  10154. } else {
  10155. name = keys.slice(0, i + 1).join(" ");
  10156. val = "...";
  10157. }
  10158. var prev = copy[name];
  10159. if (!prev) { copy[name] = val; }
  10160. else if (prev != val) { throw new Error("Inconsistent bindings for " + name) }
  10161. }
  10162. delete keymap[keyname];
  10163. } }
  10164. for (var prop in copy) { keymap[prop] = copy[prop]; }
  10165. return keymap
  10166. }
  10167. function lookupKey(key, map$$1, handle, context) {
  10168. map$$1 = getKeyMap(map$$1);
  10169. var found = map$$1.call ? map$$1.call(key, context) : map$$1[key];
  10170. if (found === false) { return "nothing" }
  10171. if (found === "...") { return "multi" }
  10172. if (found != null && handle(found)) { return "handled" }
  10173. if (map$$1.fallthrough) {
  10174. if (Object.prototype.toString.call(map$$1.fallthrough) != "[object Array]")
  10175. { return lookupKey(key, map$$1.fallthrough, handle, context) }
  10176. for (var i = 0; i < map$$1.fallthrough.length; i++) {
  10177. var result = lookupKey(key, map$$1.fallthrough[i], handle, context);
  10178. if (result) { return result }
  10179. }
  10180. }
  10181. }
  10182. // Modifier key presses don't count as 'real' key presses for the
  10183. // purpose of keymap fallthrough.
  10184. function isModifierKey(value) {
  10185. var name = typeof value == "string" ? value : keyNames[value.keyCode];
  10186. return name == "Ctrl" || name == "Alt" || name == "Shift" || name == "Mod"
  10187. }
  10188. function addModifierNames(name, event, noShift) {
  10189. var base = name;
  10190. if (event.altKey && base != "Alt") { name = "Alt-" + name; }
  10191. if ((flipCtrlCmd ? event.metaKey : event.ctrlKey) && base != "Ctrl") { name = "Ctrl-" + name; }
  10192. if ((flipCtrlCmd ? event.ctrlKey : event.metaKey) && base != "Cmd") { name = "Cmd-" + name; }
  10193. if (!noShift && event.shiftKey && base != "Shift") { name = "Shift-" + name; }
  10194. return name
  10195. }
  10196. // Look up the name of a key as indicated by an event object.
  10197. function keyName(event, noShift) {
  10198. if (presto && event.keyCode == 34 && event["char"]) { return false }
  10199. var name = keyNames[event.keyCode];
  10200. if (name == null || event.altGraphKey) { return false }
  10201. // Ctrl-ScrollLock has keyCode 3, same as Ctrl-Pause,
  10202. // so we'll use event.code when available (Chrome 48+, FF 38+, Safari 10.1+)
  10203. if (event.keyCode == 3 && event.code) { name = event.code; }
  10204. return addModifierNames(name, event, noShift)
  10205. }
  10206. function getKeyMap(val) {
  10207. return typeof val == "string" ? keyMap[val] : val
  10208. }
  10209. // Helper for deleting text near the selection(s), used to implement
  10210. // backspace, delete, and similar functionality.
  10211. function deleteNearSelection(cm, compute) {
  10212. var ranges = cm.doc.sel.ranges, kill = [];
  10213. // Build up a set of ranges to kill first, merging overlapping
  10214. // ranges.
  10215. for (var i = 0; i < ranges.length; i++) {
  10216. var toKill = compute(ranges[i]);
  10217. while (kill.length && cmp(toKill.from, lst(kill).to) <= 0) {
  10218. var replaced = kill.pop();
  10219. if (cmp(replaced.from, toKill.from) < 0) {
  10220. toKill.from = replaced.from;
  10221. break
  10222. }
  10223. }
  10224. kill.push(toKill);
  10225. }
  10226. // Next, remove those actual ranges.
  10227. runInOp(cm, function () {
  10228. for (var i = kill.length - 1; i >= 0; i--)
  10229. { replaceRange(cm.doc, "", kill[i].from, kill[i].to, "+delete"); }
  10230. ensureCursorVisible(cm);
  10231. });
  10232. }
  10233. function moveCharLogically(line, ch, dir) {
  10234. var target = skipExtendingChars(line.text, ch + dir, dir);
  10235. return target < 0 || target > line.text.length ? null : target
  10236. }
  10237. function moveLogically(line, start, dir) {
  10238. var ch = moveCharLogically(line, start.ch, dir);
  10239. return ch == null ? null : new Pos(start.line, ch, dir < 0 ? "after" : "before")
  10240. }
  10241. function endOfLine(visually, cm, lineObj, lineNo, dir) {
  10242. if (visually) {
  10243. var order = getOrder(lineObj, cm.doc.direction);
  10244. if (order) {
  10245. var part = dir < 0 ? lst(order) : order[0];
  10246. var moveInStorageOrder = (dir < 0) == (part.level == 1);
  10247. var sticky = moveInStorageOrder ? "after" : "before";
  10248. var ch;
  10249. // With a wrapped rtl chunk (possibly spanning multiple bidi parts),
  10250. // it could be that the last bidi part is not on the last visual line,
  10251. // since visual lines contain content order-consecutive chunks.
  10252. // Thus, in rtl, we are looking for the first (content-order) character
  10253. // in the rtl chunk that is on the last line (that is, the same line
  10254. // as the last (content-order) character).
  10255. if (part.level > 0 || cm.doc.direction == "rtl") {
  10256. var prep = prepareMeasureForLine(cm, lineObj);
  10257. ch = dir < 0 ? lineObj.text.length - 1 : 0;
  10258. var targetTop = measureCharPrepared(cm, prep, ch).top;
  10259. ch = findFirst(function (ch) { return measureCharPrepared(cm, prep, ch).top == targetTop; }, (dir < 0) == (part.level == 1) ? part.from : part.to - 1, ch);
  10260. if (sticky == "before") { ch = moveCharLogically(lineObj, ch, 1); }
  10261. } else { ch = dir < 0 ? part.to : part.from; }
  10262. return new Pos(lineNo, ch, sticky)
  10263. }
  10264. }
  10265. return new Pos(lineNo, dir < 0 ? lineObj.text.length : 0, dir < 0 ? "before" : "after")
  10266. }
  10267. function moveVisually(cm, line, start, dir) {
  10268. var bidi = getOrder(line, cm.doc.direction);
  10269. if (!bidi) { return moveLogically(line, start, dir) }
  10270. if (start.ch >= line.text.length) {
  10271. start.ch = line.text.length;
  10272. start.sticky = "before";
  10273. } else if (start.ch <= 0) {
  10274. start.ch = 0;
  10275. start.sticky = "after";
  10276. }
  10277. var partPos = getBidiPartAt(bidi, start.ch, start.sticky), part = bidi[partPos];
  10278. if (cm.doc.direction == "ltr" && part.level % 2 == 0 && (dir > 0 ? part.to > start.ch : part.from < start.ch)) {
  10279. // Case 1: We move within an ltr part in an ltr editor. Even with wrapped lines,
  10280. // nothing interesting happens.
  10281. return moveLogically(line, start, dir)
  10282. }
  10283. var mv = function (pos, dir) { return moveCharLogically(line, pos instanceof Pos ? pos.ch : pos, dir); };
  10284. var prep;
  10285. var getWrappedLineExtent = function (ch) {
  10286. if (!cm.options.lineWrapping) { return {begin: 0, end: line.text.length} }
  10287. prep = prep || prepareMeasureForLine(cm, line);
  10288. return wrappedLineExtentChar(cm, line, prep, ch)
  10289. };
  10290. var wrappedLineExtent = getWrappedLineExtent(start.sticky == "before" ? mv(start, -1) : start.ch);
  10291. if (cm.doc.direction == "rtl" || part.level == 1) {
  10292. var moveInStorageOrder = (part.level == 1) == (dir < 0);
  10293. var ch = mv(start, moveInStorageOrder ? 1 : -1);
  10294. if (ch != null && (!moveInStorageOrder ? ch >= part.from && ch >= wrappedLineExtent.begin : ch <= part.to && ch <= wrappedLineExtent.end)) {
  10295. // Case 2: We move within an rtl part or in an rtl editor on the same visual line
  10296. var sticky = moveInStorageOrder ? "before" : "after";
  10297. return new Pos(start.line, ch, sticky)
  10298. }
  10299. }
  10300. // Case 3: Could not move within this bidi part in this visual line, so leave
  10301. // the current bidi part
  10302. var searchInVisualLine = function (partPos, dir, wrappedLineExtent) {
  10303. var getRes = function (ch, moveInStorageOrder) { return moveInStorageOrder
  10304. ? new Pos(start.line, mv(ch, 1), "before")
  10305. : new Pos(start.line, ch, "after"); };
  10306. for (; partPos >= 0 && partPos < bidi.length; partPos += dir) {
  10307. var part = bidi[partPos];
  10308. var moveInStorageOrder = (dir > 0) == (part.level != 1);
  10309. var ch = moveInStorageOrder ? wrappedLineExtent.begin : mv(wrappedLineExtent.end, -1);
  10310. if (part.from <= ch && ch < part.to) { return getRes(ch, moveInStorageOrder) }
  10311. ch = moveInStorageOrder ? part.from : mv(part.to, -1);
  10312. if (wrappedLineExtent.begin <= ch && ch < wrappedLineExtent.end) { return getRes(ch, moveInStorageOrder) }
  10313. }
  10314. };
  10315. // Case 3a: Look for other bidi parts on the same visual line
  10316. var res = searchInVisualLine(partPos + dir, dir, wrappedLineExtent);
  10317. if (res) { return res }
  10318. // Case 3b: Look for other bidi parts on the next visual line
  10319. var nextCh = dir > 0 ? wrappedLineExtent.end : mv(wrappedLineExtent.begin, -1);
  10320. if (nextCh != null && !(dir > 0 && nextCh == line.text.length)) {
  10321. res = searchInVisualLine(dir > 0 ? 0 : bidi.length - 1, dir, getWrappedLineExtent(nextCh));
  10322. if (res) { return res }
  10323. }
  10324. // Case 4: Nowhere to move
  10325. return null
  10326. }
  10327. // Commands are parameter-less actions that can be performed on an
  10328. // editor, mostly used for keybindings.
  10329. var commands = {
  10330. selectAll: selectAll,
  10331. singleSelection: function (cm) { return cm.setSelection(cm.getCursor("anchor"), cm.getCursor("head"), sel_dontScroll); },
  10332. killLine: function (cm) { return deleteNearSelection(cm, function (range) {
  10333. if (range.empty()) {
  10334. var len = getLine(cm.doc, range.head.line).text.length;
  10335. if (range.head.ch == len && range.head.line < cm.lastLine())
  10336. { return {from: range.head, to: Pos(range.head.line + 1, 0)} }
  10337. else
  10338. { return {from: range.head, to: Pos(range.head.line, len)} }
  10339. } else {
  10340. return {from: range.from(), to: range.to()}
  10341. }
  10342. }); },
  10343. deleteLine: function (cm) { return deleteNearSelection(cm, function (range) { return ({
  10344. from: Pos(range.from().line, 0),
  10345. to: clipPos(cm.doc, Pos(range.to().line + 1, 0))
  10346. }); }); },
  10347. delLineLeft: function (cm) { return deleteNearSelection(cm, function (range) { return ({
  10348. from: Pos(range.from().line, 0), to: range.from()
  10349. }); }); },
  10350. delWrappedLineLeft: function (cm) { return deleteNearSelection(cm, function (range) {
  10351. var top = cm.charCoords(range.head, "div").top + 5;
  10352. var leftPos = cm.coordsChar({left: 0, top: top}, "div");
  10353. return {from: leftPos, to: range.from()}
  10354. }); },
  10355. delWrappedLineRight: function (cm) { return deleteNearSelection(cm, function (range) {
  10356. var top = cm.charCoords(range.head, "div").top + 5;
  10357. var rightPos = cm.coordsChar({left: cm.display.lineDiv.offsetWidth + 100, top: top}, "div");
  10358. return {from: range.from(), to: rightPos }
  10359. }); },
  10360. undo: function (cm) { return cm.undo(); },
  10361. redo: function (cm) { return cm.redo(); },
  10362. undoSelection: function (cm) { return cm.undoSelection(); },
  10363. redoSelection: function (cm) { return cm.redoSelection(); },
  10364. goDocStart: function (cm) { return cm.extendSelection(Pos(cm.firstLine(), 0)); },
  10365. goDocEnd: function (cm) { return cm.extendSelection(Pos(cm.lastLine())); },
  10366. goLineStart: function (cm) { return cm.extendSelectionsBy(function (range) { return lineStart(cm, range.head.line); },
  10367. {origin: "+move", bias: 1}
  10368. ); },
  10369. goLineStartSmart: function (cm) { return cm.extendSelectionsBy(function (range) { return lineStartSmart(cm, range.head); },
  10370. {origin: "+move", bias: 1}
  10371. ); },
  10372. goLineEnd: function (cm) { return cm.extendSelectionsBy(function (range) { return lineEnd(cm, range.head.line); },
  10373. {origin: "+move", bias: -1}
  10374. ); },
  10375. goLineRight: function (cm) { return cm.extendSelectionsBy(function (range) {
  10376. var top = cm.cursorCoords(range.head, "div").top + 5;
  10377. return cm.coordsChar({left: cm.display.lineDiv.offsetWidth + 100, top: top}, "div")
  10378. }, sel_move); },
  10379. goLineLeft: function (cm) { return cm.extendSelectionsBy(function (range) {
  10380. var top = cm.cursorCoords(range.head, "div").top + 5;
  10381. return cm.coordsChar({left: 0, top: top}, "div")
  10382. }, sel_move); },
  10383. goLineLeftSmart: function (cm) { return cm.extendSelectionsBy(function (range) {
  10384. var top = cm.cursorCoords(range.head, "div").top + 5;
  10385. var pos = cm.coordsChar({left: 0, top: top}, "div");
  10386. if (pos.ch < cm.getLine(pos.line).search(/\S/)) { return lineStartSmart(cm, range.head) }
  10387. return pos
  10388. }, sel_move); },
  10389. goLineUp: function (cm) { return cm.moveV(-1, "line"); },
  10390. goLineDown: function (cm) { return cm.moveV(1, "line"); },
  10391. goPageUp: function (cm) { return cm.moveV(-1, "page"); },
  10392. goPageDown: function (cm) { return cm.moveV(1, "page"); },
  10393. goCharLeft: function (cm) { return cm.moveH(-1, "char"); },
  10394. goCharRight: function (cm) { return cm.moveH(1, "char"); },
  10395. goColumnLeft: function (cm) { return cm.moveH(-1, "column"); },
  10396. goColumnRight: function (cm) { return cm.moveH(1, "column"); },
  10397. goWordLeft: function (cm) { return cm.moveH(-1, "word"); },
  10398. goGroupRight: function (cm) { return cm.moveH(1, "group"); },
  10399. goGroupLeft: function (cm) { return cm.moveH(-1, "group"); },
  10400. goWordRight: function (cm) { return cm.moveH(1, "word"); },
  10401. delCharBefore: function (cm) { return cm.deleteH(-1, "char"); },
  10402. delCharAfter: function (cm) { return cm.deleteH(1, "char"); },
  10403. delWordBefore: function (cm) { return cm.deleteH(-1, "word"); },
  10404. delWordAfter: function (cm) { return cm.deleteH(1, "word"); },
  10405. delGroupBefore: function (cm) { return cm.deleteH(-1, "group"); },
  10406. delGroupAfter: function (cm) { return cm.deleteH(1, "group"); },
  10407. indentAuto: function (cm) { return cm.indentSelection("smart"); },
  10408. indentMore: function (cm) { return cm.indentSelection("add"); },
  10409. indentLess: function (cm) { return cm.indentSelection("subtract"); },
  10410. insertTab: function (cm) { return cm.replaceSelection("\t"); },
  10411. insertSoftTab: function (cm) {
  10412. var spaces = [], ranges = cm.listSelections(), tabSize = cm.options.tabSize;
  10413. for (var i = 0; i < ranges.length; i++) {
  10414. var pos = ranges[i].from();
  10415. var col = countColumn(cm.getLine(pos.line), pos.ch, tabSize);
  10416. spaces.push(spaceStr(tabSize - col % tabSize));
  10417. }
  10418. cm.replaceSelections(spaces);
  10419. },
  10420. defaultTab: function (cm) {
  10421. if (cm.somethingSelected()) { cm.indentSelection("add"); }
  10422. else { cm.execCommand("insertTab"); }
  10423. },
  10424. // Swap the two chars left and right of each selection's head.
  10425. // Move cursor behind the two swapped characters afterwards.
  10426. //
  10427. // Doesn't consider line feeds a character.
  10428. // Doesn't scan more than one line above to find a character.
  10429. // Doesn't do anything on an empty line.
  10430. // Doesn't do anything with non-empty selections.
  10431. transposeChars: function (cm) { return runInOp(cm, function () {
  10432. var ranges = cm.listSelections(), newSel = [];
  10433. for (var i = 0; i < ranges.length; i++) {
  10434. if (!ranges[i].empty()) { continue }
  10435. var cur = ranges[i].head, line = getLine(cm.doc, cur.line).text;
  10436. if (line) {
  10437. if (cur.ch == line.length) { cur = new Pos(cur.line, cur.ch - 1); }
  10438. if (cur.ch > 0) {
  10439. cur = new Pos(cur.line, cur.ch + 1);
  10440. cm.replaceRange(line.charAt(cur.ch - 1) + line.charAt(cur.ch - 2),
  10441. Pos(cur.line, cur.ch - 2), cur, "+transpose");
  10442. } else if (cur.line > cm.doc.first) {
  10443. var prev = getLine(cm.doc, cur.line - 1).text;
  10444. if (prev) {
  10445. cur = new Pos(cur.line, 1);
  10446. cm.replaceRange(line.charAt(0) + cm.doc.lineSeparator() +
  10447. prev.charAt(prev.length - 1),
  10448. Pos(cur.line - 1, prev.length - 1), cur, "+transpose");
  10449. }
  10450. }
  10451. }
  10452. newSel.push(new Range(cur, cur));
  10453. }
  10454. cm.setSelections(newSel);
  10455. }); },
  10456. newlineAndIndent: function (cm) { return runInOp(cm, function () {
  10457. var sels = cm.listSelections();
  10458. for (var i = sels.length - 1; i >= 0; i--)
  10459. { cm.replaceRange(cm.doc.lineSeparator(), sels[i].anchor, sels[i].head, "+input"); }
  10460. sels = cm.listSelections();
  10461. for (var i$1 = 0; i$1 < sels.length; i$1++)
  10462. { cm.indentLine(sels[i$1].from().line, null, true); }
  10463. ensureCursorVisible(cm);
  10464. }); },
  10465. openLine: function (cm) { return cm.replaceSelection("\n", "start"); },
  10466. toggleOverwrite: function (cm) { return cm.toggleOverwrite(); }
  10467. };
  10468. function lineStart(cm, lineN) {
  10469. var line = getLine(cm.doc, lineN);
  10470. var visual = visualLine(line);
  10471. if (visual != line) { lineN = lineNo(visual); }
  10472. return endOfLine(true, cm, visual, lineN, 1)
  10473. }
  10474. function lineEnd(cm, lineN) {
  10475. var line = getLine(cm.doc, lineN);
  10476. var visual = visualLineEnd(line);
  10477. if (visual != line) { lineN = lineNo(visual); }
  10478. return endOfLine(true, cm, line, lineN, -1)
  10479. }
  10480. function lineStartSmart(cm, pos) {
  10481. var start = lineStart(cm, pos.line);
  10482. var line = getLine(cm.doc, start.line);
  10483. var order = getOrder(line, cm.doc.direction);
  10484. if (!order || order[0].level == 0) {
  10485. var firstNonWS = Math.max(0, line.text.search(/\S/));
  10486. var inWS = pos.line == start.line && pos.ch <= firstNonWS && pos.ch;
  10487. return Pos(start.line, inWS ? 0 : firstNonWS, start.sticky)
  10488. }
  10489. return start
  10490. }
  10491. // Run a handler that was bound to a key.
  10492. function doHandleBinding(cm, bound, dropShift) {
  10493. if (typeof bound == "string") {
  10494. bound = commands[bound];
  10495. if (!bound) { return false }
  10496. }
  10497. // Ensure previous input has been read, so that the handler sees a
  10498. // consistent view of the document
  10499. cm.display.input.ensurePolled();
  10500. var prevShift = cm.display.shift, done = false;
  10501. try {
  10502. if (cm.isReadOnly()) { cm.state.suppressEdits = true; }
  10503. if (dropShift) { cm.display.shift = false; }
  10504. done = bound(cm) != Pass;
  10505. } finally {
  10506. cm.display.shift = prevShift;
  10507. cm.state.suppressEdits = false;
  10508. }
  10509. return done
  10510. }
  10511. function lookupKeyForEditor(cm, name, handle) {
  10512. for (var i = 0; i < cm.state.keyMaps.length; i++) {
  10513. var result = lookupKey(name, cm.state.keyMaps[i], handle, cm);
  10514. if (result) { return result }
  10515. }
  10516. return (cm.options.extraKeys && lookupKey(name, cm.options.extraKeys, handle, cm))
  10517. || lookupKey(name, cm.options.keyMap, handle, cm)
  10518. }
  10519. // Note that, despite the name, this function is also used to check
  10520. // for bound mouse clicks.
  10521. var stopSeq = new Delayed;
  10522. function dispatchKey(cm, name, e, handle) {
  10523. var seq = cm.state.keySeq;
  10524. if (seq) {
  10525. if (isModifierKey(name)) { return "handled" }
  10526. if (/\'$/.test(name))
  10527. { cm.state.keySeq = null; }
  10528. else
  10529. { stopSeq.set(50, function () {
  10530. if (cm.state.keySeq == seq) {
  10531. cm.state.keySeq = null;
  10532. cm.display.input.reset();
  10533. }
  10534. }); }
  10535. if (dispatchKeyInner(cm, seq + " " + name, e, handle)) { return true }
  10536. }
  10537. return dispatchKeyInner(cm, name, e, handle)
  10538. }
  10539. function dispatchKeyInner(cm, name, e, handle) {
  10540. var result = lookupKeyForEditor(cm, name, handle);
  10541. if (result == "multi")
  10542. { cm.state.keySeq = name; }
  10543. if (result == "handled")
  10544. { signalLater(cm, "keyHandled", cm, name, e); }
  10545. if (result == "handled" || result == "multi") {
  10546. e_preventDefault(e);
  10547. restartBlink(cm);
  10548. }
  10549. return !!result
  10550. }
  10551. // Handle a key from the keydown event.
  10552. function handleKeyBinding(cm, e) {
  10553. var name = keyName(e, true);
  10554. if (!name) { return false }
  10555. if (e.shiftKey && !cm.state.keySeq) {
  10556. // First try to resolve full name (including 'Shift-'). Failing
  10557. // that, see if there is a cursor-motion command (starting with
  10558. // 'go') bound to the keyname without 'Shift-'.
  10559. return dispatchKey(cm, "Shift-" + name, e, function (b) { return doHandleBinding(cm, b, true); })
  10560. || dispatchKey(cm, name, e, function (b) {
  10561. if (typeof b == "string" ? /^go[A-Z]/.test(b) : b.motion)
  10562. { return doHandleBinding(cm, b) }
  10563. })
  10564. } else {
  10565. return dispatchKey(cm, name, e, function (b) { return doHandleBinding(cm, b); })
  10566. }
  10567. }
  10568. // Handle a key from the keypress event
  10569. function handleCharBinding(cm, e, ch) {
  10570. return dispatchKey(cm, "'" + ch + "'", e, function (b) { return doHandleBinding(cm, b, true); })
  10571. }
  10572. var lastStoppedKey = null;
  10573. function onKeyDown(e) {
  10574. var cm = this;
  10575. cm.curOp.focus = activeElt();
  10576. if (signalDOMEvent(cm, e)) { return }
  10577. // IE does strange things with escape.
  10578. if (ie && ie_version < 11 && e.keyCode == 27) { e.returnValue = false; }
  10579. var code = e.keyCode;
  10580. cm.display.shift = code == 16 || e.shiftKey;
  10581. var handled = handleKeyBinding(cm, e);
  10582. if (presto) {
  10583. lastStoppedKey = handled ? code : null;
  10584. // Opera has no cut event... we try to at least catch the key combo
  10585. if (!handled && code == 88 && !hasCopyEvent && (mac ? e.metaKey : e.ctrlKey))
  10586. { cm.replaceSelection("", null, "cut"); }
  10587. }
  10588. // Turn mouse into crosshair when Alt is held on Mac.
  10589. if (code == 18 && !/\bCodeMirror-crosshair\b/.test(cm.display.lineDiv.className))
  10590. { showCrossHair(cm); }
  10591. }
  10592. function showCrossHair(cm) {
  10593. var lineDiv = cm.display.lineDiv;
  10594. addClass(lineDiv, "CodeMirror-crosshair");
  10595. function up(e) {
  10596. if (e.keyCode == 18 || !e.altKey) {
  10597. rmClass(lineDiv, "CodeMirror-crosshair");
  10598. off(document, "keyup", up);
  10599. off(document, "mouseover", up);
  10600. }
  10601. }
  10602. on(document, "keyup", up);
  10603. on(document, "mouseover", up);
  10604. }
  10605. function onKeyUp(e) {
  10606. if (e.keyCode == 16) { this.doc.sel.shift = false; }
  10607. signalDOMEvent(this, e);
  10608. }
  10609. function onKeyPress(e) {
  10610. var cm = this;
  10611. if (eventInWidget(cm.display, e) || signalDOMEvent(cm, e) || e.ctrlKey && !e.altKey || mac && e.metaKey) { return }
  10612. var keyCode = e.keyCode, charCode = e.charCode;
  10613. if (presto && keyCode == lastStoppedKey) {lastStoppedKey = null; e_preventDefault(e); return}
  10614. if ((presto && (!e.which || e.which < 10)) && handleKeyBinding(cm, e)) { return }
  10615. var ch = String.fromCharCode(charCode == null ? keyCode : charCode);
  10616. // Some browsers fire keypress events for backspace
  10617. if (ch == "\x08") { return }
  10618. if (handleCharBinding(cm, e, ch)) { return }
  10619. cm.display.input.onKeyPress(e);
  10620. }
  10621. var DOUBLECLICK_DELAY = 400;
  10622. var PastClick = function(time, pos, button) {
  10623. this.time = time;
  10624. this.pos = pos;
  10625. this.button = button;
  10626. };
  10627. PastClick.prototype.compare = function (time, pos, button) {
  10628. return this.time + DOUBLECLICK_DELAY > time &&
  10629. cmp(pos, this.pos) == 0 && button == this.button
  10630. };
  10631. var lastClick, lastDoubleClick;
  10632. function clickRepeat(pos, button) {
  10633. var now = +new Date;
  10634. if (lastDoubleClick && lastDoubleClick.compare(now, pos, button)) {
  10635. lastClick = lastDoubleClick = null;
  10636. return "triple"
  10637. } else if (lastClick && lastClick.compare(now, pos, button)) {
  10638. lastDoubleClick = new PastClick(now, pos, button);
  10639. lastClick = null;
  10640. return "double"
  10641. } else {
  10642. lastClick = new PastClick(now, pos, button);
  10643. lastDoubleClick = null;
  10644. return "single"
  10645. }
  10646. }
  10647. // A mouse down can be a single click, double click, triple click,
  10648. // start of selection drag, start of text drag, new cursor
  10649. // (ctrl-click), rectangle drag (alt-drag), or xwin
  10650. // middle-click-paste. Or it might be a click on something we should
  10651. // not interfere with, such as a scrollbar or widget.
  10652. function onMouseDown(e) {
  10653. var cm = this, display = cm.display;
  10654. if (signalDOMEvent(cm, e) || display.activeTouch && display.input.supportsTouch()) { return }
  10655. display.input.ensurePolled();
  10656. display.shift = e.shiftKey;
  10657. if (eventInWidget(display, e)) {
  10658. if (!webkit) {
  10659. // Briefly turn off draggability, to allow widgets to do
  10660. // normal dragging things.
  10661. display.scroller.draggable = false;
  10662. setTimeout(function () { return display.scroller.draggable = true; }, 100);
  10663. }
  10664. return
  10665. }
  10666. if (clickInGutter(cm, e)) { return }
  10667. var pos = posFromMouse(cm, e), button = e_button(e), repeat = pos ? clickRepeat(pos, button) : "single";
  10668. window.focus();
  10669. // #3261: make sure, that we're not starting a second selection
  10670. if (button == 1 && cm.state.selectingText)
  10671. { cm.state.selectingText(e); }
  10672. if (pos && handleMappedButton(cm, button, pos, repeat, e)) { return }
  10673. if (button == 1) {
  10674. if (pos) { leftButtonDown(cm, pos, repeat, e); }
  10675. else if (e_target(e) == display.scroller) { e_preventDefault(e); }
  10676. } else if (button == 2) {
  10677. if (pos) { extendSelection(cm.doc, pos); }
  10678. setTimeout(function () { return display.input.focus(); }, 20);
  10679. } else if (button == 3) {
  10680. if (captureRightClick) { cm.display.input.onContextMenu(e); }
  10681. else { delayBlurEvent(cm); }
  10682. }
  10683. }
  10684. function handleMappedButton(cm, button, pos, repeat, event) {
  10685. var name = "Click";
  10686. if (repeat == "double") { name = "Double" + name; }
  10687. else if (repeat == "triple") { name = "Triple" + name; }
  10688. name = (button == 1 ? "Left" : button == 2 ? "Middle" : "Right") + name;
  10689. return dispatchKey(cm, addModifierNames(name, event), event, function (bound) {
  10690. if (typeof bound == "string") { bound = commands[bound]; }
  10691. if (!bound) { return false }
  10692. var done = false;
  10693. try {
  10694. if (cm.isReadOnly()) { cm.state.suppressEdits = true; }
  10695. done = bound(cm, pos) != Pass;
  10696. } finally {
  10697. cm.state.suppressEdits = false;
  10698. }
  10699. return done
  10700. })
  10701. }
  10702. function configureMouse(cm, repeat, event) {
  10703. var option = cm.getOption("configureMouse");
  10704. var value = option ? option(cm, repeat, event) : {};
  10705. if (value.unit == null) {
  10706. var rect = chromeOS ? event.shiftKey && event.metaKey : event.altKey;
  10707. value.unit = rect ? "rectangle" : repeat == "single" ? "char" : repeat == "double" ? "word" : "line";
  10708. }
  10709. if (value.extend == null || cm.doc.extend) { value.extend = cm.doc.extend || event.shiftKey; }
  10710. if (value.addNew == null) { value.addNew = mac ? event.metaKey : event.ctrlKey; }
  10711. if (value.moveOnDrag == null) { value.moveOnDrag = !(mac ? event.altKey : event.ctrlKey); }
  10712. return value
  10713. }
  10714. function leftButtonDown(cm, pos, repeat, event) {
  10715. if (ie) { setTimeout(bind(ensureFocus, cm), 0); }
  10716. else { cm.curOp.focus = activeElt(); }
  10717. var behavior = configureMouse(cm, repeat, event);
  10718. var sel = cm.doc.sel, contained;
  10719. if (cm.options.dragDrop && dragAndDrop && !cm.isReadOnly() &&
  10720. repeat == "single" && (contained = sel.contains(pos)) > -1 &&
  10721. (cmp((contained = sel.ranges[contained]).from(), pos) < 0 || pos.xRel > 0) &&
  10722. (cmp(contained.to(), pos) > 0 || pos.xRel < 0))
  10723. { leftButtonStartDrag(cm, event, pos, behavior); }
  10724. else
  10725. { leftButtonSelect(cm, event, pos, behavior); }
  10726. }
  10727. // Start a text drag. When it ends, see if any dragging actually
  10728. // happen, and treat as a click if it didn't.
  10729. function leftButtonStartDrag(cm, event, pos, behavior) {
  10730. var display = cm.display, moved = false;
  10731. var dragEnd = operation(cm, function (e) {
  10732. if (webkit) { display.scroller.draggable = false; }
  10733. cm.state.draggingText = false;
  10734. off(display.wrapper.ownerDocument, "mouseup", dragEnd);
  10735. off(display.wrapper.ownerDocument, "mousemove", mouseMove);
  10736. off(display.scroller, "dragstart", dragStart);
  10737. off(display.scroller, "drop", dragEnd);
  10738. if (!moved) {
  10739. e_preventDefault(e);
  10740. if (!behavior.addNew)
  10741. { extendSelection(cm.doc, pos, null, null, behavior.extend); }
  10742. // Work around unexplainable focus problem in IE9 (#2127) and Chrome (#3081)
  10743. if (webkit || ie && ie_version == 9)
  10744. { setTimeout(function () {display.wrapper.ownerDocument.body.focus(); display.input.focus();}, 20); }
  10745. else
  10746. { display.input.focus(); }
  10747. }
  10748. });
  10749. var mouseMove = function(e2) {
  10750. moved = moved || Math.abs(event.clientX - e2.clientX) + Math.abs(event.clientY - e2.clientY) >= 10;
  10751. };
  10752. var dragStart = function () { return moved = true; };
  10753. // Let the drag handler handle this.
  10754. if (webkit) { display.scroller.draggable = true; }
  10755. cm.state.draggingText = dragEnd;
  10756. dragEnd.copy = !behavior.moveOnDrag;
  10757. // IE's approach to draggable
  10758. if (display.scroller.dragDrop) { display.scroller.dragDrop(); }
  10759. on(display.wrapper.ownerDocument, "mouseup", dragEnd);
  10760. on(display.wrapper.ownerDocument, "mousemove", mouseMove);
  10761. on(display.scroller, "dragstart", dragStart);
  10762. on(display.scroller, "drop", dragEnd);
  10763. delayBlurEvent(cm);
  10764. setTimeout(function () { return display.input.focus(); }, 20);
  10765. }
  10766. function rangeForUnit(cm, pos, unit) {
  10767. if (unit == "char") { return new Range(pos, pos) }
  10768. if (unit == "word") { return cm.findWordAt(pos) }
  10769. if (unit == "line") { return new Range(Pos(pos.line, 0), clipPos(cm.doc, Pos(pos.line + 1, 0))) }
  10770. var result = unit(cm, pos);
  10771. return new Range(result.from, result.to)
  10772. }
  10773. // Normal selection, as opposed to text dragging.
  10774. function leftButtonSelect(cm, event, start, behavior) {
  10775. var display = cm.display, doc = cm.doc;
  10776. e_preventDefault(event);
  10777. var ourRange, ourIndex, startSel = doc.sel, ranges = startSel.ranges;
  10778. if (behavior.addNew && !behavior.extend) {
  10779. ourIndex = doc.sel.contains(start);
  10780. if (ourIndex > -1)
  10781. { ourRange = ranges[ourIndex]; }
  10782. else
  10783. { ourRange = new Range(start, start); }
  10784. } else {
  10785. ourRange = doc.sel.primary();
  10786. ourIndex = doc.sel.primIndex;
  10787. }
  10788. if (behavior.unit == "rectangle") {
  10789. if (!behavior.addNew) { ourRange = new Range(start, start); }
  10790. start = posFromMouse(cm, event, true, true);
  10791. ourIndex = -1;
  10792. } else {
  10793. var range$$1 = rangeForUnit(cm, start, behavior.unit);
  10794. if (behavior.extend)
  10795. { ourRange = extendRange(ourRange, range$$1.anchor, range$$1.head, behavior.extend); }
  10796. else
  10797. { ourRange = range$$1; }
  10798. }
  10799. if (!behavior.addNew) {
  10800. ourIndex = 0;
  10801. setSelection(doc, new Selection([ourRange], 0), sel_mouse);
  10802. startSel = doc.sel;
  10803. } else if (ourIndex == -1) {
  10804. ourIndex = ranges.length;
  10805. setSelection(doc, normalizeSelection(cm, ranges.concat([ourRange]), ourIndex),
  10806. {scroll: false, origin: "*mouse"});
  10807. } else if (ranges.length > 1 && ranges[ourIndex].empty() && behavior.unit == "char" && !behavior.extend) {
  10808. setSelection(doc, normalizeSelection(cm, ranges.slice(0, ourIndex).concat(ranges.slice(ourIndex + 1)), 0),
  10809. {scroll: false, origin: "*mouse"});
  10810. startSel = doc.sel;
  10811. } else {
  10812. replaceOneSelection(doc, ourIndex, ourRange, sel_mouse);
  10813. }
  10814. var lastPos = start;
  10815. function extendTo(pos) {
  10816. if (cmp(lastPos, pos) == 0) { return }
  10817. lastPos = pos;
  10818. if (behavior.unit == "rectangle") {
  10819. var ranges = [], tabSize = cm.options.tabSize;
  10820. var startCol = countColumn(getLine(doc, start.line).text, start.ch, tabSize);
  10821. var posCol = countColumn(getLine(doc, pos.line).text, pos.ch, tabSize);
  10822. var left = Math.min(startCol, posCol), right = Math.max(startCol, posCol);
  10823. for (var line = Math.min(start.line, pos.line), end = Math.min(cm.lastLine(), Math.max(start.line, pos.line));
  10824. line <= end; line++) {
  10825. var text = getLine(doc, line).text, leftPos = findColumn(text, left, tabSize);
  10826. if (left == right)
  10827. { ranges.push(new Range(Pos(line, leftPos), Pos(line, leftPos))); }
  10828. else if (text.length > leftPos)
  10829. { ranges.push(new Range(Pos(line, leftPos), Pos(line, findColumn(text, right, tabSize)))); }
  10830. }
  10831. if (!ranges.length) { ranges.push(new Range(start, start)); }
  10832. setSelection(doc, normalizeSelection(cm, startSel.ranges.slice(0, ourIndex).concat(ranges), ourIndex),
  10833. {origin: "*mouse", scroll: false});
  10834. cm.scrollIntoView(pos);
  10835. } else {
  10836. var oldRange = ourRange;
  10837. var range$$1 = rangeForUnit(cm, pos, behavior.unit);
  10838. var anchor = oldRange.anchor, head;
  10839. if (cmp(range$$1.anchor, anchor) > 0) {
  10840. head = range$$1.head;
  10841. anchor = minPos(oldRange.from(), range$$1.anchor);
  10842. } else {
  10843. head = range$$1.anchor;
  10844. anchor = maxPos(oldRange.to(), range$$1.head);
  10845. }
  10846. var ranges$1 = startSel.ranges.slice(0);
  10847. ranges$1[ourIndex] = bidiSimplify(cm, new Range(clipPos(doc, anchor), head));
  10848. setSelection(doc, normalizeSelection(cm, ranges$1, ourIndex), sel_mouse);
  10849. }
  10850. }
  10851. var editorSize = display.wrapper.getBoundingClientRect();
  10852. // Used to ensure timeout re-tries don't fire when another extend
  10853. // happened in the meantime (clearTimeout isn't reliable -- at
  10854. // least on Chrome, the timeouts still happen even when cleared,
  10855. // if the clear happens after their scheduled firing time).
  10856. var counter = 0;
  10857. function extend(e) {
  10858. var curCount = ++counter;
  10859. var cur = posFromMouse(cm, e, true, behavior.unit == "rectangle");
  10860. if (!cur) { return }
  10861. if (cmp(cur, lastPos) != 0) {
  10862. cm.curOp.focus = activeElt();
  10863. extendTo(cur);
  10864. var visible = visibleLines(display, doc);
  10865. if (cur.line >= visible.to || cur.line < visible.from)
  10866. { setTimeout(operation(cm, function () {if (counter == curCount) { extend(e); }}), 150); }
  10867. } else {
  10868. var outside = e.clientY < editorSize.top ? -20 : e.clientY > editorSize.bottom ? 20 : 0;
  10869. if (outside) { setTimeout(operation(cm, function () {
  10870. if (counter != curCount) { return }
  10871. display.scroller.scrollTop += outside;
  10872. extend(e);
  10873. }), 50); }
  10874. }
  10875. }
  10876. function done(e) {
  10877. cm.state.selectingText = false;
  10878. counter = Infinity;
  10879. // If e is null or undefined we interpret this as someone trying
  10880. // to explicitly cancel the selection rather than the user
  10881. // letting go of the mouse button.
  10882. if (e) {
  10883. e_preventDefault(e);
  10884. display.input.focus();
  10885. }
  10886. off(display.wrapper.ownerDocument, "mousemove", move);
  10887. off(display.wrapper.ownerDocument, "mouseup", up);
  10888. doc.history.lastSelOrigin = null;
  10889. }
  10890. var move = operation(cm, function (e) {
  10891. if (e.buttons === 0 || !e_button(e)) { done(e); }
  10892. else { extend(e); }
  10893. });
  10894. var up = operation(cm, done);
  10895. cm.state.selectingText = up;
  10896. on(display.wrapper.ownerDocument, "mousemove", move);
  10897. on(display.wrapper.ownerDocument, "mouseup", up);
  10898. }
  10899. // Used when mouse-selecting to adjust the anchor to the proper side
  10900. // of a bidi jump depending on the visual position of the head.
  10901. function bidiSimplify(cm, range$$1) {
  10902. var anchor = range$$1.anchor;
  10903. var head = range$$1.head;
  10904. var anchorLine = getLine(cm.doc, anchor.line);
  10905. if (cmp(anchor, head) == 0 && anchor.sticky == head.sticky) { return range$$1 }
  10906. var order = getOrder(anchorLine);
  10907. if (!order) { return range$$1 }
  10908. var index = getBidiPartAt(order, anchor.ch, anchor.sticky), part = order[index];
  10909. if (part.from != anchor.ch && part.to != anchor.ch) { return range$$1 }
  10910. var boundary = index + ((part.from == anchor.ch) == (part.level != 1) ? 0 : 1);
  10911. if (boundary == 0 || boundary == order.length) { return range$$1 }
  10912. // Compute the relative visual position of the head compared to the
  10913. // anchor (<0 is to the left, >0 to the right)
  10914. var leftSide;
  10915. if (head.line != anchor.line) {
  10916. leftSide = (head.line - anchor.line) * (cm.doc.direction == "ltr" ? 1 : -1) > 0;
  10917. } else {
  10918. var headIndex = getBidiPartAt(order, head.ch, head.sticky);
  10919. var dir = headIndex - index || (head.ch - anchor.ch) * (part.level == 1 ? -1 : 1);
  10920. if (headIndex == boundary - 1 || headIndex == boundary)
  10921. { leftSide = dir < 0; }
  10922. else
  10923. { leftSide = dir > 0; }
  10924. }
  10925. var usePart = order[boundary + (leftSide ? -1 : 0)];
  10926. var from = leftSide == (usePart.level == 1);
  10927. var ch = from ? usePart.from : usePart.to, sticky = from ? "after" : "before";
  10928. return anchor.ch == ch && anchor.sticky == sticky ? range$$1 : new Range(new Pos(anchor.line, ch, sticky), head)
  10929. }
  10930. // Determines whether an event happened in the gutter, and fires the
  10931. // handlers for the corresponding event.
  10932. function gutterEvent(cm, e, type, prevent) {
  10933. var mX, mY;
  10934. if (e.touches) {
  10935. mX = e.touches[0].clientX;
  10936. mY = e.touches[0].clientY;
  10937. } else {
  10938. try { mX = e.clientX; mY = e.clientY; }
  10939. catch(e) { return false }
  10940. }
  10941. if (mX >= Math.floor(cm.display.gutters.getBoundingClientRect().right)) { return false }
  10942. if (prevent) { e_preventDefault(e); }
  10943. var display = cm.display;
  10944. var lineBox = display.lineDiv.getBoundingClientRect();
  10945. if (mY > lineBox.bottom || !hasHandler(cm, type)) { return e_defaultPrevented(e) }
  10946. mY -= lineBox.top - display.viewOffset;
  10947. for (var i = 0; i < cm.display.gutterSpecs.length; ++i) {
  10948. var g = display.gutters.childNodes[i];
  10949. if (g && g.getBoundingClientRect().right >= mX) {
  10950. var line = lineAtHeight(cm.doc, mY);
  10951. var gutter = cm.display.gutterSpecs[i];
  10952. signal(cm, type, cm, line, gutter.className, e);
  10953. return e_defaultPrevented(e)
  10954. }
  10955. }
  10956. }
  10957. function clickInGutter(cm, e) {
  10958. return gutterEvent(cm, e, "gutterClick", true)
  10959. }
  10960. // CONTEXT MENU HANDLING
  10961. // To make the context menu work, we need to briefly unhide the
  10962. // textarea (making it as unobtrusive as possible) to let the
  10963. // right-click take effect on it.
  10964. function onContextMenu(cm, e) {
  10965. if (eventInWidget(cm.display, e) || contextMenuInGutter(cm, e)) { return }
  10966. if (signalDOMEvent(cm, e, "contextmenu")) { return }
  10967. if (!captureRightClick) { cm.display.input.onContextMenu(e); }
  10968. }
  10969. function contextMenuInGutter(cm, e) {
  10970. if (!hasHandler(cm, "gutterContextMenu")) { return false }
  10971. return gutterEvent(cm, e, "gutterContextMenu", false)
  10972. }
  10973. function themeChanged(cm) {
  10974. cm.display.wrapper.className = cm.display.wrapper.className.replace(/\s*cm-s-\S+/g, "") +
  10975. cm.options.theme.replace(/(^|\s)\s*/g, " cm-s-");
  10976. clearCaches(cm);
  10977. }
  10978. var Init = {toString: function(){return "CodeMirror.Init"}};
  10979. var defaults = {};
  10980. var optionHandlers = {};
  10981. function defineOptions(CodeMirror) {
  10982. var optionHandlers = CodeMirror.optionHandlers;
  10983. function option(name, deflt, handle, notOnInit) {
  10984. CodeMirror.defaults[name] = deflt;
  10985. if (handle) { optionHandlers[name] =
  10986. notOnInit ? function (cm, val, old) {if (old != Init) { handle(cm, val, old); }} : handle; }
  10987. }
  10988. CodeMirror.defineOption = option;
  10989. // Passed to option handlers when there is no old value.
  10990. CodeMirror.Init = Init;
  10991. // These two are, on init, called from the constructor because they
  10992. // have to be initialized before the editor can start at all.
  10993. option("value", "", function (cm, val) { return cm.setValue(val); }, true);
  10994. option("mode", null, function (cm, val) {
  10995. cm.doc.modeOption = val;
  10996. loadMode(cm);
  10997. }, true);
  10998. option("indentUnit", 2, loadMode, true);
  10999. option("indentWithTabs", false);
  11000. option("smartIndent", true);
  11001. option("tabSize", 4, function (cm) {
  11002. resetModeState(cm);
  11003. clearCaches(cm);
  11004. regChange(cm);
  11005. }, true);
  11006. option("lineSeparator", null, function (cm, val) {
  11007. cm.doc.lineSep = val;
  11008. if (!val) { return }
  11009. var newBreaks = [], lineNo = cm.doc.first;
  11010. cm.doc.iter(function (line) {
  11011. for (var pos = 0;;) {
  11012. var found = line.text.indexOf(val, pos);
  11013. if (found == -1) { break }
  11014. pos = found + val.length;
  11015. newBreaks.push(Pos(lineNo, found));
  11016. }
  11017. lineNo++;
  11018. });
  11019. for (var i = newBreaks.length - 1; i >= 0; i--)
  11020. { replaceRange(cm.doc, val, newBreaks[i], Pos(newBreaks[i].line, newBreaks[i].ch + val.length)); }
  11021. });
  11022. option("specialChars", /[\u0000-\u001f\u007f-\u009f\u00ad\u061c\u200b-\u200f\u2028\u2029\ufeff\ufff9-\ufffc]/g, function (cm, val, old) {
  11023. cm.state.specialChars = new RegExp(val.source + (val.test("\t") ? "" : "|\t"), "g");
  11024. if (old != Init) { cm.refresh(); }
  11025. });
  11026. option("specialCharPlaceholder", defaultSpecialCharPlaceholder, function (cm) { return cm.refresh(); }, true);
  11027. option("electricChars", true);
  11028. option("inputStyle", mobile ? "contenteditable" : "textarea", function () {
  11029. throw new Error("inputStyle can not (yet) be changed in a running editor") // FIXME
  11030. }, true);
  11031. option("spellcheck", false, function (cm, val) { return cm.getInputField().spellcheck = val; }, true);
  11032. option("autocorrect", false, function (cm, val) { return cm.getInputField().autocorrect = val; }, true);
  11033. option("autocapitalize", false, function (cm, val) { return cm.getInputField().autocapitalize = val; }, true);
  11034. option("rtlMoveVisually", !windows);
  11035. option("wholeLineUpdateBefore", true);
  11036. option("theme", "default", function (cm) {
  11037. themeChanged(cm);
  11038. updateGutters(cm);
  11039. }, true);
  11040. option("keyMap", "default", function (cm, val, old) {
  11041. var next = getKeyMap(val);
  11042. var prev = old != Init && getKeyMap(old);
  11043. if (prev && prev.detach) { prev.detach(cm, next); }
  11044. if (next.attach) { next.attach(cm, prev || null); }
  11045. });
  11046. option("extraKeys", null);
  11047. option("configureMouse", null);
  11048. option("lineWrapping", false, wrappingChanged, true);
  11049. option("gutters", [], function (cm, val) {
  11050. cm.display.gutterSpecs = getGutters(val, cm.options.lineNumbers);
  11051. updateGutters(cm);
  11052. }, true);
  11053. option("fixedGutter", true, function (cm, val) {
  11054. cm.display.gutters.style.left = val ? compensateForHScroll(cm.display) + "px" : "0";
  11055. cm.refresh();
  11056. }, true);
  11057. option("coverGutterNextToScrollbar", false, function (cm) { return updateScrollbars(cm); }, true);
  11058. option("scrollbarStyle", "native", function (cm) {
  11059. initScrollbars(cm);
  11060. updateScrollbars(cm);
  11061. cm.display.scrollbars.setScrollTop(cm.doc.scrollTop);
  11062. cm.display.scrollbars.setScrollLeft(cm.doc.scrollLeft);
  11063. }, true);
  11064. option("lineNumbers", false, function (cm, val) {
  11065. cm.display.gutterSpecs = getGutters(cm.options.gutters, val);
  11066. updateGutters(cm);
  11067. }, true);
  11068. option("firstLineNumber", 1, updateGutters, true);
  11069. option("lineNumberFormatter", function (integer) { return integer; }, updateGutters, true);
  11070. option("showCursorWhenSelecting", false, updateSelection, true);
  11071. option("resetSelectionOnContextMenu", true);
  11072. option("lineWiseCopyCut", true);
  11073. option("pasteLinesPerSelection", true);
  11074. option("selectionsMayTouch", false);
  11075. option("readOnly", false, function (cm, val) {
  11076. if (val == "nocursor") {
  11077. onBlur(cm);
  11078. cm.display.input.blur();
  11079. }
  11080. cm.display.input.readOnlyChanged(val);
  11081. });
  11082. option("disableInput", false, function (cm, val) {if (!val) { cm.display.input.reset(); }}, true);
  11083. option("dragDrop", true, dragDropChanged);
  11084. option("allowDropFileTypes", null);
  11085. option("cursorBlinkRate", 530);
  11086. option("cursorScrollMargin", 0);
  11087. option("cursorHeight", 1, updateSelection, true);
  11088. option("singleCursorHeightPerLine", true, updateSelection, true);
  11089. option("workTime", 100);
  11090. option("workDelay", 100);
  11091. option("flattenSpans", true, resetModeState, true);
  11092. option("addModeClass", false, resetModeState, true);
  11093. option("pollInterval", 100);
  11094. option("undoDepth", 200, function (cm, val) { return cm.doc.history.undoDepth = val; });
  11095. option("historyEventDelay", 1250);
  11096. option("viewportMargin", 10, function (cm) { return cm.refresh(); }, true);
  11097. option("maxHighlightLength", 10000, resetModeState, true);
  11098. option("moveInputWithCursor", true, function (cm, val) {
  11099. if (!val) { cm.display.input.resetPosition(); }
  11100. });
  11101. option("tabindex", null, function (cm, val) { return cm.display.input.getField().tabIndex = val || ""; });
  11102. option("autofocus", null);
  11103. option("direction", "ltr", function (cm, val) { return cm.doc.setDirection(val); }, true);
  11104. option("phrases", null);
  11105. }
  11106. function dragDropChanged(cm, value, old) {
  11107. var wasOn = old && old != Init;
  11108. if (!value != !wasOn) {
  11109. var funcs = cm.display.dragFunctions;
  11110. var toggle = value ? on : off;
  11111. toggle(cm.display.scroller, "dragstart", funcs.start);
  11112. toggle(cm.display.scroller, "dragenter", funcs.enter);
  11113. toggle(cm.display.scroller, "dragover", funcs.over);
  11114. toggle(cm.display.scroller, "dragleave", funcs.leave);
  11115. toggle(cm.display.scroller, "drop", funcs.drop);
  11116. }
  11117. }
  11118. function wrappingChanged(cm) {
  11119. if (cm.options.lineWrapping) {
  11120. addClass(cm.display.wrapper, "CodeMirror-wrap");
  11121. cm.display.sizer.style.minWidth = "";
  11122. cm.display.sizerWidth = null;
  11123. } else {
  11124. rmClass(cm.display.wrapper, "CodeMirror-wrap");
  11125. findMaxLine(cm);
  11126. }
  11127. estimateLineHeights(cm);
  11128. regChange(cm);
  11129. clearCaches(cm);
  11130. setTimeout(function () { return updateScrollbars(cm); }, 100);
  11131. }
  11132. // A CodeMirror instance represents an editor. This is the object
  11133. // that user code is usually dealing with.
  11134. function CodeMirror(place, options) {
  11135. var this$1 = this;
  11136. if (!(this instanceof CodeMirror)) { return new CodeMirror(place, options) }
  11137. this.options = options = options ? copyObj(options) : {};
  11138. // Determine effective options based on given values and defaults.
  11139. copyObj(defaults, options, false);
  11140. var doc = options.value;
  11141. if (typeof doc == "string") { doc = new Doc(doc, options.mode, null, options.lineSeparator, options.direction); }
  11142. else if (options.mode) { doc.modeOption = options.mode; }
  11143. this.doc = doc;
  11144. var input = new CodeMirror.inputStyles[options.inputStyle](this);
  11145. var display = this.display = new Display(place, doc, input, options);
  11146. display.wrapper.CodeMirror = this;
  11147. themeChanged(this);
  11148. if (options.lineWrapping)
  11149. { this.display.wrapper.className += " CodeMirror-wrap"; }
  11150. initScrollbars(this);
  11151. this.state = {
  11152. keyMaps: [], // stores maps added by addKeyMap
  11153. overlays: [], // highlighting overlays, as added by addOverlay
  11154. modeGen: 0, // bumped when mode/overlay changes, used to invalidate highlighting info
  11155. overwrite: false,
  11156. delayingBlurEvent: false,
  11157. focused: false,
  11158. suppressEdits: false, // used to disable editing during key handlers when in readOnly mode
  11159. pasteIncoming: -1, cutIncoming: -1, // help recognize paste/cut edits in input.poll
  11160. selectingText: false,
  11161. draggingText: false,
  11162. highlight: new Delayed(), // stores highlight worker timeout
  11163. keySeq: null, // Unfinished key sequence
  11164. specialChars: null
  11165. };
  11166. if (options.autofocus && !mobile) { display.input.focus(); }
  11167. // Override magic textarea content restore that IE sometimes does
  11168. // on our hidden textarea on reload
  11169. if (ie && ie_version < 11) { setTimeout(function () { return this$1.display.input.reset(true); }, 20); }
  11170. registerEventHandlers(this);
  11171. ensureGlobalHandlers();
  11172. startOperation(this);
  11173. this.curOp.forceUpdate = true;
  11174. attachDoc(this, doc);
  11175. if ((options.autofocus && !mobile) || this.hasFocus())
  11176. { setTimeout(bind(onFocus, this), 20); }
  11177. else
  11178. { onBlur(this); }
  11179. for (var opt in optionHandlers) { if (optionHandlers.hasOwnProperty(opt))
  11180. { optionHandlers[opt](this$1, options[opt], Init); } }
  11181. maybeUpdateLineNumberWidth(this);
  11182. if (options.finishInit) { options.finishInit(this); }
  11183. for (var i = 0; i < initHooks.length; ++i) { initHooks[i](this$1); }
  11184. endOperation(this);
  11185. // Suppress optimizelegibility in Webkit, since it breaks text
  11186. // measuring on line wrapping boundaries.
  11187. if (webkit && options.lineWrapping &&
  11188. getComputedStyle(display.lineDiv).textRendering == "optimizelegibility")
  11189. { display.lineDiv.style.textRendering = "auto"; }
  11190. }
  11191. // The default configuration options.
  11192. CodeMirror.defaults = defaults;
  11193. // Functions to run when options are changed.
  11194. CodeMirror.optionHandlers = optionHandlers;
  11195. // Attach the necessary event handlers when initializing the editor
  11196. function registerEventHandlers(cm) {
  11197. var d = cm.display;
  11198. on(d.scroller, "mousedown", operation(cm, onMouseDown));
  11199. // Older IE's will not fire a second mousedown for a double click
  11200. if (ie && ie_version < 11)
  11201. { on(d.scroller, "dblclick", operation(cm, function (e) {
  11202. if (signalDOMEvent(cm, e)) { return }
  11203. var pos = posFromMouse(cm, e);
  11204. if (!pos || clickInGutter(cm, e) || eventInWidget(cm.display, e)) { return }
  11205. e_preventDefault(e);
  11206. var word = cm.findWordAt(pos);
  11207. extendSelection(cm.doc, word.anchor, word.head);
  11208. })); }
  11209. else
  11210. { on(d.scroller, "dblclick", function (e) { return signalDOMEvent(cm, e) || e_preventDefault(e); }); }
  11211. // Some browsers fire contextmenu *after* opening the menu, at
  11212. // which point we can't mess with it anymore. Context menu is
  11213. // handled in onMouseDown for these browsers.
  11214. on(d.scroller, "contextmenu", function (e) { return onContextMenu(cm, e); });
  11215. // Used to suppress mouse event handling when a touch happens
  11216. var touchFinished, prevTouch = {end: 0};
  11217. function finishTouch() {
  11218. if (d.activeTouch) {
  11219. touchFinished = setTimeout(function () { return d.activeTouch = null; }, 1000);
  11220. prevTouch = d.activeTouch;
  11221. prevTouch.end = +new Date;
  11222. }
  11223. }
  11224. function isMouseLikeTouchEvent(e) {
  11225. if (e.touches.length != 1) { return false }
  11226. var touch = e.touches[0];
  11227. return touch.radiusX <= 1 && touch.radiusY <= 1
  11228. }
  11229. function farAway(touch, other) {
  11230. if (other.left == null) { return true }
  11231. var dx = other.left - touch.left, dy = other.top - touch.top;
  11232. return dx * dx + dy * dy > 20 * 20
  11233. }
  11234. on(d.scroller, "touchstart", function (e) {
  11235. if (!signalDOMEvent(cm, e) && !isMouseLikeTouchEvent(e) && !clickInGutter(cm, e)) {
  11236. d.input.ensurePolled();
  11237. clearTimeout(touchFinished);
  11238. var now = +new Date;
  11239. d.activeTouch = {start: now, moved: false,
  11240. prev: now - prevTouch.end <= 300 ? prevTouch : null};
  11241. if (e.touches.length == 1) {
  11242. d.activeTouch.left = e.touches[0].pageX;
  11243. d.activeTouch.top = e.touches[0].pageY;
  11244. }
  11245. }
  11246. });
  11247. on(d.scroller, "touchmove", function () {
  11248. if (d.activeTouch) { d.activeTouch.moved = true; }
  11249. });
  11250. on(d.scroller, "touchend", function (e) {
  11251. var touch = d.activeTouch;
  11252. if (touch && !eventInWidget(d, e) && touch.left != null &&
  11253. !touch.moved && new Date - touch.start < 300) {
  11254. var pos = cm.coordsChar(d.activeTouch, "page"), range;
  11255. if (!touch.prev || farAway(touch, touch.prev)) // Single tap
  11256. { range = new Range(pos, pos); }
  11257. else if (!touch.prev.prev || farAway(touch, touch.prev.prev)) // Double tap
  11258. { range = cm.findWordAt(pos); }
  11259. else // Triple tap
  11260. { range = new Range(Pos(pos.line, 0), clipPos(cm.doc, Pos(pos.line + 1, 0))); }
  11261. cm.setSelection(range.anchor, range.head);
  11262. cm.focus();
  11263. e_preventDefault(e);
  11264. }
  11265. finishTouch();
  11266. });
  11267. on(d.scroller, "touchcancel", finishTouch);
  11268. // Sync scrolling between fake scrollbars and real scrollable
  11269. // area, ensure viewport is updated when scrolling.
  11270. on(d.scroller, "scroll", function () {
  11271. if (d.scroller.clientHeight) {
  11272. updateScrollTop(cm, d.scroller.scrollTop);
  11273. setScrollLeft(cm, d.scroller.scrollLeft, true);
  11274. signal(cm, "scroll", cm);
  11275. }
  11276. });
  11277. // Listen to wheel events in order to try and update the viewport on time.
  11278. on(d.scroller, "mousewheel", function (e) { return onScrollWheel(cm, e); });
  11279. on(d.scroller, "DOMMouseScroll", function (e) { return onScrollWheel(cm, e); });
  11280. // Prevent wrapper from ever scrolling
  11281. on(d.wrapper, "scroll", function () { return d.wrapper.scrollTop = d.wrapper.scrollLeft = 0; });
  11282. d.dragFunctions = {
  11283. enter: function (e) {if (!signalDOMEvent(cm, e)) { e_stop(e); }},
  11284. over: function (e) {if (!signalDOMEvent(cm, e)) { onDragOver(cm, e); e_stop(e); }},
  11285. start: function (e) { return onDragStart(cm, e); },
  11286. drop: operation(cm, onDrop),
  11287. leave: function (e) {if (!signalDOMEvent(cm, e)) { clearDragCursor(cm); }}
  11288. };
  11289. var inp = d.input.getField();
  11290. on(inp, "keyup", function (e) { return onKeyUp.call(cm, e); });
  11291. on(inp, "keydown", operation(cm, onKeyDown));
  11292. on(inp, "keypress", operation(cm, onKeyPress));
  11293. on(inp, "focus", function (e) { return onFocus(cm, e); });
  11294. on(inp, "blur", function (e) { return onBlur(cm, e); });
  11295. }
  11296. var initHooks = [];
  11297. CodeMirror.defineInitHook = function (f) { return initHooks.push(f); };
  11298. // Indent the given line. The how parameter can be "smart",
  11299. // "add"/null, "subtract", or "prev". When aggressive is false
  11300. // (typically set to true for forced single-line indents), empty
  11301. // lines are not indented, and places where the mode returns Pass
  11302. // are left alone.
  11303. function indentLine(cm, n, how, aggressive) {
  11304. var doc = cm.doc, state;
  11305. if (how == null) { how = "add"; }
  11306. if (how == "smart") {
  11307. // Fall back to "prev" when the mode doesn't have an indentation
  11308. // method.
  11309. if (!doc.mode.indent) { how = "prev"; }
  11310. else { state = getContextBefore(cm, n).state; }
  11311. }
  11312. var tabSize = cm.options.tabSize;
  11313. var line = getLine(doc, n), curSpace = countColumn(line.text, null, tabSize);
  11314. if (line.stateAfter) { line.stateAfter = null; }
  11315. var curSpaceString = line.text.match(/^\s*/)[0], indentation;
  11316. if (!aggressive && !/\S/.test(line.text)) {
  11317. indentation = 0;
  11318. how = "not";
  11319. } else if (how == "smart") {
  11320. indentation = doc.mode.indent(state, line.text.slice(curSpaceString.length), line.text);
  11321. if (indentation == Pass || indentation > 150) {
  11322. if (!aggressive) { return }
  11323. how = "prev";
  11324. }
  11325. }
  11326. if (how == "prev") {
  11327. if (n > doc.first) { indentation = countColumn(getLine(doc, n-1).text, null, tabSize); }
  11328. else { indentation = 0; }
  11329. } else if (how == "add") {
  11330. indentation = curSpace + cm.options.indentUnit;
  11331. } else if (how == "subtract") {
  11332. indentation = curSpace - cm.options.indentUnit;
  11333. } else if (typeof how == "number") {
  11334. indentation = curSpace + how;
  11335. }
  11336. indentation = Math.max(0, indentation);
  11337. var indentString = "", pos = 0;
  11338. if (cm.options.indentWithTabs)
  11339. { for (var i = Math.floor(indentation / tabSize); i; --i) {pos += tabSize; indentString += "\t";} }
  11340. if (pos < indentation) { indentString += spaceStr(indentation - pos); }
  11341. if (indentString != curSpaceString) {
  11342. replaceRange(doc, indentString, Pos(n, 0), Pos(n, curSpaceString.length), "+input");
  11343. line.stateAfter = null;
  11344. return true
  11345. } else {
  11346. // Ensure that, if the cursor was in the whitespace at the start
  11347. // of the line, it is moved to the end of that space.
  11348. for (var i$1 = 0; i$1 < doc.sel.ranges.length; i$1++) {
  11349. var range = doc.sel.ranges[i$1];
  11350. if (range.head.line == n && range.head.ch < curSpaceString.length) {
  11351. var pos$1 = Pos(n, curSpaceString.length);
  11352. replaceOneSelection(doc, i$1, new Range(pos$1, pos$1));
  11353. break
  11354. }
  11355. }
  11356. }
  11357. }
  11358. // This will be set to a {lineWise: bool, text: [string]} object, so
  11359. // that, when pasting, we know what kind of selections the copied
  11360. // text was made out of.
  11361. var lastCopied = null;
  11362. function setLastCopied(newLastCopied) {
  11363. lastCopied = newLastCopied;
  11364. }
  11365. function applyTextInput(cm, inserted, deleted, sel, origin) {
  11366. var doc = cm.doc;
  11367. cm.display.shift = false;
  11368. if (!sel) { sel = doc.sel; }
  11369. var recent = +new Date - 200;
  11370. var paste = origin == "paste" || cm.state.pasteIncoming > recent;
  11371. var textLines = splitLinesAuto(inserted), multiPaste = null;
  11372. // When pasting N lines into N selections, insert one line per selection
  11373. if (paste && sel.ranges.length > 1) {
  11374. if (lastCopied && lastCopied.text.join("\n") == inserted) {
  11375. if (sel.ranges.length % lastCopied.text.length == 0) {
  11376. multiPaste = [];
  11377. for (var i = 0; i < lastCopied.text.length; i++)
  11378. { multiPaste.push(doc.splitLines(lastCopied.text[i])); }
  11379. }
  11380. } else if (textLines.length == sel.ranges.length && cm.options.pasteLinesPerSelection) {
  11381. multiPaste = map(textLines, function (l) { return [l]; });
  11382. }
  11383. }
  11384. var updateInput = cm.curOp.updateInput;
  11385. // Normal behavior is to insert the new text into every selection
  11386. for (var i$1 = sel.ranges.length - 1; i$1 >= 0; i$1--) {
  11387. var range$$1 = sel.ranges[i$1];
  11388. var from = range$$1.from(), to = range$$1.to();
  11389. if (range$$1.empty()) {
  11390. if (deleted && deleted > 0) // Handle deletion
  11391. { from = Pos(from.line, from.ch - deleted); }
  11392. else if (cm.state.overwrite && !paste) // Handle overwrite
  11393. { to = Pos(to.line, Math.min(getLine(doc, to.line).text.length, to.ch + lst(textLines).length)); }
  11394. else if (paste && lastCopied && lastCopied.lineWise && lastCopied.text.join("\n") == inserted)
  11395. { from = to = Pos(from.line, 0); }
  11396. }
  11397. var changeEvent = {from: from, to: to, text: multiPaste ? multiPaste[i$1 % multiPaste.length] : textLines,
  11398. origin: origin || (paste ? "paste" : cm.state.cutIncoming > recent ? "cut" : "+input")};
  11399. makeChange(cm.doc, changeEvent);
  11400. signalLater(cm, "inputRead", cm, changeEvent);
  11401. }
  11402. if (inserted && !paste)
  11403. { triggerElectric(cm, inserted); }
  11404. ensureCursorVisible(cm);
  11405. if (cm.curOp.updateInput < 2) { cm.curOp.updateInput = updateInput; }
  11406. cm.curOp.typing = true;
  11407. cm.state.pasteIncoming = cm.state.cutIncoming = -1;
  11408. }
  11409. function handlePaste(e, cm) {
  11410. var pasted = e.clipboardData && e.clipboardData.getData("Text");
  11411. if (pasted) {
  11412. e.preventDefault();
  11413. if (!cm.isReadOnly() && !cm.options.disableInput)
  11414. { runInOp(cm, function () { return applyTextInput(cm, pasted, 0, null, "paste"); }); }
  11415. return true
  11416. }
  11417. }
  11418. function triggerElectric(cm, inserted) {
  11419. // When an 'electric' character is inserted, immediately trigger a reindent
  11420. if (!cm.options.electricChars || !cm.options.smartIndent) { return }
  11421. var sel = cm.doc.sel;
  11422. for (var i = sel.ranges.length - 1; i >= 0; i--) {
  11423. var range$$1 = sel.ranges[i];
  11424. if (range$$1.head.ch > 100 || (i && sel.ranges[i - 1].head.line == range$$1.head.line)) { continue }
  11425. var mode = cm.getModeAt(range$$1.head);
  11426. var indented = false;
  11427. if (mode.electricChars) {
  11428. for (var j = 0; j < mode.electricChars.length; j++)
  11429. { if (inserted.indexOf(mode.electricChars.charAt(j)) > -1) {
  11430. indented = indentLine(cm, range$$1.head.line, "smart");
  11431. break
  11432. } }
  11433. } else if (mode.electricInput) {
  11434. if (mode.electricInput.test(getLine(cm.doc, range$$1.head.line).text.slice(0, range$$1.head.ch)))
  11435. { indented = indentLine(cm, range$$1.head.line, "smart"); }
  11436. }
  11437. if (indented) { signalLater(cm, "electricInput", cm, range$$1.head.line); }
  11438. }
  11439. }
  11440. function copyableRanges(cm) {
  11441. var text = [], ranges = [];
  11442. for (var i = 0; i < cm.doc.sel.ranges.length; i++) {
  11443. var line = cm.doc.sel.ranges[i].head.line;
  11444. var lineRange = {anchor: Pos(line, 0), head: Pos(line + 1, 0)};
  11445. ranges.push(lineRange);
  11446. text.push(cm.getRange(lineRange.anchor, lineRange.head));
  11447. }
  11448. return {text: text, ranges: ranges}
  11449. }
  11450. function disableBrowserMagic(field, spellcheck, autocorrect, autocapitalize) {
  11451. field.setAttribute("autocorrect", autocorrect ? "" : "off");
  11452. field.setAttribute("autocapitalize", autocapitalize ? "" : "off");
  11453. field.setAttribute("spellcheck", !!spellcheck);
  11454. }
  11455. function hiddenTextarea() {
  11456. var te = elt("textarea", null, null, "position: absolute; bottom: -1em; padding: 0; width: 1px; height: 1em; outline: none");
  11457. var div = elt("div", [te], null, "overflow: hidden; position: relative; width: 3px; height: 0px;");
  11458. // The textarea is kept positioned near the cursor to prevent the
  11459. // fact that it'll be scrolled into view on input from scrolling
  11460. // our fake cursor out of view. On webkit, when wrap=off, paste is
  11461. // very slow. So make the area wide instead.
  11462. if (webkit) { te.style.width = "1000px"; }
  11463. else { te.setAttribute("wrap", "off"); }
  11464. // If border: 0; -- iOS fails to open keyboard (issue #1287)
  11465. if (ios) { te.style.border = "1px solid black"; }
  11466. disableBrowserMagic(te);
  11467. return div
  11468. }
  11469. // The publicly visible API. Note that methodOp(f) means
  11470. // 'wrap f in an operation, performed on its `this` parameter'.
  11471. // This is not the complete set of editor methods. Most of the
  11472. // methods defined on the Doc type are also injected into
  11473. // CodeMirror.prototype, for backwards compatibility and
  11474. // convenience.
  11475. function addEditorMethods(CodeMirror) {
  11476. var optionHandlers = CodeMirror.optionHandlers;
  11477. var helpers = CodeMirror.helpers = {};
  11478. CodeMirror.prototype = {
  11479. constructor: CodeMirror,
  11480. focus: function(){window.focus(); this.display.input.focus();},
  11481. setOption: function(option, value) {
  11482. var options = this.options, old = options[option];
  11483. if (options[option] == value && option != "mode") { return }
  11484. options[option] = value;
  11485. if (optionHandlers.hasOwnProperty(option))
  11486. { operation(this, optionHandlers[option])(this, value, old); }
  11487. signal(this, "optionChange", this, option);
  11488. },
  11489. getOption: function(option) {return this.options[option]},
  11490. getDoc: function() {return this.doc},
  11491. addKeyMap: function(map$$1, bottom) {
  11492. this.state.keyMaps[bottom ? "push" : "unshift"](getKeyMap(map$$1));
  11493. },
  11494. removeKeyMap: function(map$$1) {
  11495. var maps = this.state.keyMaps;
  11496. for (var i = 0; i < maps.length; ++i)
  11497. { if (maps[i] == map$$1 || maps[i].name == map$$1) {
  11498. maps.splice(i, 1);
  11499. return true
  11500. } }
  11501. },
  11502. addOverlay: methodOp(function(spec, options) {
  11503. var mode = spec.token ? spec : CodeMirror.getMode(this.options, spec);
  11504. if (mode.startState) { throw new Error("Overlays may not be stateful.") }
  11505. insertSorted(this.state.overlays,
  11506. {mode: mode, modeSpec: spec, opaque: options && options.opaque,
  11507. priority: (options && options.priority) || 0},
  11508. function (overlay) { return overlay.priority; });
  11509. this.state.modeGen++;
  11510. regChange(this);
  11511. }),
  11512. removeOverlay: methodOp(function(spec) {
  11513. var this$1 = this;
  11514. var overlays = this.state.overlays;
  11515. for (var i = 0; i < overlays.length; ++i) {
  11516. var cur = overlays[i].modeSpec;
  11517. if (cur == spec || typeof spec == "string" && cur.name == spec) {
  11518. overlays.splice(i, 1);
  11519. this$1.state.modeGen++;
  11520. regChange(this$1);
  11521. return
  11522. }
  11523. }
  11524. }),
  11525. indentLine: methodOp(function(n, dir, aggressive) {
  11526. if (typeof dir != "string" && typeof dir != "number") {
  11527. if (dir == null) { dir = this.options.smartIndent ? "smart" : "prev"; }
  11528. else { dir = dir ? "add" : "subtract"; }
  11529. }
  11530. if (isLine(this.doc, n)) { indentLine(this, n, dir, aggressive); }
  11531. }),
  11532. indentSelection: methodOp(function(how) {
  11533. var this$1 = this;
  11534. var ranges = this.doc.sel.ranges, end = -1;
  11535. for (var i = 0; i < ranges.length; i++) {
  11536. var range$$1 = ranges[i];
  11537. if (!range$$1.empty()) {
  11538. var from = range$$1.from(), to = range$$1.to();
  11539. var start = Math.max(end, from.line);
  11540. end = Math.min(this$1.lastLine(), to.line - (to.ch ? 0 : 1)) + 1;
  11541. for (var j = start; j < end; ++j)
  11542. { indentLine(this$1, j, how); }
  11543. var newRanges = this$1.doc.sel.ranges;
  11544. if (from.ch == 0 && ranges.length == newRanges.length && newRanges[i].from().ch > 0)
  11545. { replaceOneSelection(this$1.doc, i, new Range(from, newRanges[i].to()), sel_dontScroll); }
  11546. } else if (range$$1.head.line > end) {
  11547. indentLine(this$1, range$$1.head.line, how, true);
  11548. end = range$$1.head.line;
  11549. if (i == this$1.doc.sel.primIndex) { ensureCursorVisible(this$1); }
  11550. }
  11551. }
  11552. }),
  11553. // Fetch the parser token for a given character. Useful for hacks
  11554. // that want to inspect the mode state (say, for completion).
  11555. getTokenAt: function(pos, precise) {
  11556. return takeToken(this, pos, precise)
  11557. },
  11558. getLineTokens: function(line, precise) {
  11559. return takeToken(this, Pos(line), precise, true)
  11560. },
  11561. getTokenTypeAt: function(pos) {
  11562. pos = clipPos(this.doc, pos);
  11563. var styles = getLineStyles(this, getLine(this.doc, pos.line));
  11564. var before = 0, after = (styles.length - 1) / 2, ch = pos.ch;
  11565. var type;
  11566. if (ch == 0) { type = styles[2]; }
  11567. else { for (;;) {
  11568. var mid = (before + after) >> 1;
  11569. if ((mid ? styles[mid * 2 - 1] : 0) >= ch) { after = mid; }
  11570. else if (styles[mid * 2 + 1] < ch) { before = mid + 1; }
  11571. else { type = styles[mid * 2 + 2]; break }
  11572. } }
  11573. var cut = type ? type.indexOf("overlay ") : -1;
  11574. return cut < 0 ? type : cut == 0 ? null : type.slice(0, cut - 1)
  11575. },
  11576. getModeAt: function(pos) {
  11577. var mode = this.doc.mode;
  11578. if (!mode.innerMode) { return mode }
  11579. return CodeMirror.innerMode(mode, this.getTokenAt(pos).state).mode
  11580. },
  11581. getHelper: function(pos, type) {
  11582. return this.getHelpers(pos, type)[0]
  11583. },
  11584. getHelpers: function(pos, type) {
  11585. var this$1 = this;
  11586. var found = [];
  11587. if (!helpers.hasOwnProperty(type)) { return found }
  11588. var help = helpers[type], mode = this.getModeAt(pos);
  11589. if (typeof mode[type] == "string") {
  11590. if (help[mode[type]]) { found.push(help[mode[type]]); }
  11591. } else if (mode[type]) {
  11592. for (var i = 0; i < mode[type].length; i++) {
  11593. var val = help[mode[type][i]];
  11594. if (val) { found.push(val); }
  11595. }
  11596. } else if (mode.helperType && help[mode.helperType]) {
  11597. found.push(help[mode.helperType]);
  11598. } else if (help[mode.name]) {
  11599. found.push(help[mode.name]);
  11600. }
  11601. for (var i$1 = 0; i$1 < help._global.length; i$1++) {
  11602. var cur = help._global[i$1];
  11603. if (cur.pred(mode, this$1) && indexOf(found, cur.val) == -1)
  11604. { found.push(cur.val); }
  11605. }
  11606. return found
  11607. },
  11608. getStateAfter: function(line, precise) {
  11609. var doc = this.doc;
  11610. line = clipLine(doc, line == null ? doc.first + doc.size - 1: line);
  11611. return getContextBefore(this, line + 1, precise).state
  11612. },
  11613. cursorCoords: function(start, mode) {
  11614. var pos, range$$1 = this.doc.sel.primary();
  11615. if (start == null) { pos = range$$1.head; }
  11616. else if (typeof start == "object") { pos = clipPos(this.doc, start); }
  11617. else { pos = start ? range$$1.from() : range$$1.to(); }
  11618. return cursorCoords(this, pos, mode || "page")
  11619. },
  11620. charCoords: function(pos, mode) {
  11621. return charCoords(this, clipPos(this.doc, pos), mode || "page")
  11622. },
  11623. coordsChar: function(coords, mode) {
  11624. coords = fromCoordSystem(this, coords, mode || "page");
  11625. return coordsChar(this, coords.left, coords.top)
  11626. },
  11627. lineAtHeight: function(height, mode) {
  11628. height = fromCoordSystem(this, {top: height, left: 0}, mode || "page").top;
  11629. return lineAtHeight(this.doc, height + this.display.viewOffset)
  11630. },
  11631. heightAtLine: function(line, mode, includeWidgets) {
  11632. var end = false, lineObj;
  11633. if (typeof line == "number") {
  11634. var last = this.doc.first + this.doc.size - 1;
  11635. if (line < this.doc.first) { line = this.doc.first; }
  11636. else if (line > last) { line = last; end = true; }
  11637. lineObj = getLine(this.doc, line);
  11638. } else {
  11639. lineObj = line;
  11640. }
  11641. return intoCoordSystem(this, lineObj, {top: 0, left: 0}, mode || "page", includeWidgets || end).top +
  11642. (end ? this.doc.height - heightAtLine(lineObj) : 0)
  11643. },
  11644. defaultTextHeight: function() { return textHeight(this.display) },
  11645. defaultCharWidth: function() { return charWidth(this.display) },
  11646. getViewport: function() { return {from: this.display.viewFrom, to: this.display.viewTo}},
  11647. addWidget: function(pos, node, scroll, vert, horiz) {
  11648. var display = this.display;
  11649. pos = cursorCoords(this, clipPos(this.doc, pos));
  11650. var top = pos.bottom, left = pos.left;
  11651. node.style.position = "absolute";
  11652. node.setAttribute("cm-ignore-events", "true");
  11653. this.display.input.setUneditable(node);
  11654. display.sizer.appendChild(node);
  11655. if (vert == "over") {
  11656. top = pos.top;
  11657. } else if (vert == "above" || vert == "near") {
  11658. var vspace = Math.max(display.wrapper.clientHeight, this.doc.height),
  11659. hspace = Math.max(display.sizer.clientWidth, display.lineSpace.clientWidth);
  11660. // Default to positioning above (if specified and possible); otherwise default to positioning below
  11661. if ((vert == 'above' || pos.bottom + node.offsetHeight > vspace) && pos.top > node.offsetHeight)
  11662. { top = pos.top - node.offsetHeight; }
  11663. else if (pos.bottom + node.offsetHeight <= vspace)
  11664. { top = pos.bottom; }
  11665. if (left + node.offsetWidth > hspace)
  11666. { left = hspace - node.offsetWidth; }
  11667. }
  11668. node.style.top = top + "px";
  11669. node.style.left = node.style.right = "";
  11670. if (horiz == "right") {
  11671. left = display.sizer.clientWidth - node.offsetWidth;
  11672. node.style.right = "0px";
  11673. } else {
  11674. if (horiz == "left") { left = 0; }
  11675. else if (horiz == "middle") { left = (display.sizer.clientWidth - node.offsetWidth) / 2; }
  11676. node.style.left = left + "px";
  11677. }
  11678. if (scroll)
  11679. { scrollIntoView(this, {left: left, top: top, right: left + node.offsetWidth, bottom: top + node.offsetHeight}); }
  11680. },
  11681. triggerOnKeyDown: methodOp(onKeyDown),
  11682. triggerOnKeyPress: methodOp(onKeyPress),
  11683. triggerOnKeyUp: onKeyUp,
  11684. triggerOnMouseDown: methodOp(onMouseDown),
  11685. execCommand: function(cmd) {
  11686. if (commands.hasOwnProperty(cmd))
  11687. { return commands[cmd].call(null, this) }
  11688. },
  11689. triggerElectric: methodOp(function(text) { triggerElectric(this, text); }),
  11690. findPosH: function(from, amount, unit, visually) {
  11691. var this$1 = this;
  11692. var dir = 1;
  11693. if (amount < 0) { dir = -1; amount = -amount; }
  11694. var cur = clipPos(this.doc, from);
  11695. for (var i = 0; i < amount; ++i) {
  11696. cur = findPosH(this$1.doc, cur, dir, unit, visually);
  11697. if (cur.hitSide) { break }
  11698. }
  11699. return cur
  11700. },
  11701. moveH: methodOp(function(dir, unit) {
  11702. var this$1 = this;
  11703. this.extendSelectionsBy(function (range$$1) {
  11704. if (this$1.display.shift || this$1.doc.extend || range$$1.empty())
  11705. { return findPosH(this$1.doc, range$$1.head, dir, unit, this$1.options.rtlMoveVisually) }
  11706. else
  11707. { return dir < 0 ? range$$1.from() : range$$1.to() }
  11708. }, sel_move);
  11709. }),
  11710. deleteH: methodOp(function(dir, unit) {
  11711. var sel = this.doc.sel, doc = this.doc;
  11712. if (sel.somethingSelected())
  11713. { doc.replaceSelection("", null, "+delete"); }
  11714. else
  11715. { deleteNearSelection(this, function (range$$1) {
  11716. var other = findPosH(doc, range$$1.head, dir, unit, false);
  11717. return dir < 0 ? {from: other, to: range$$1.head} : {from: range$$1.head, to: other}
  11718. }); }
  11719. }),
  11720. findPosV: function(from, amount, unit, goalColumn) {
  11721. var this$1 = this;
  11722. var dir = 1, x = goalColumn;
  11723. if (amount < 0) { dir = -1; amount = -amount; }
  11724. var cur = clipPos(this.doc, from);
  11725. for (var i = 0; i < amount; ++i) {
  11726. var coords = cursorCoords(this$1, cur, "div");
  11727. if (x == null) { x = coords.left; }
  11728. else { coords.left = x; }
  11729. cur = findPosV(this$1, coords, dir, unit);
  11730. if (cur.hitSide) { break }
  11731. }
  11732. return cur
  11733. },
  11734. moveV: methodOp(function(dir, unit) {
  11735. var this$1 = this;
  11736. var doc = this.doc, goals = [];
  11737. var collapse = !this.display.shift && !doc.extend && doc.sel.somethingSelected();
  11738. doc.extendSelectionsBy(function (range$$1) {
  11739. if (collapse)
  11740. { return dir < 0 ? range$$1.from() : range$$1.to() }
  11741. var headPos = cursorCoords(this$1, range$$1.head, "div");
  11742. if (range$$1.goalColumn != null) { headPos.left = range$$1.goalColumn; }
  11743. goals.push(headPos.left);
  11744. var pos = findPosV(this$1, headPos, dir, unit);
  11745. if (unit == "page" && range$$1 == doc.sel.primary())
  11746. { addToScrollTop(this$1, charCoords(this$1, pos, "div").top - headPos.top); }
  11747. return pos
  11748. }, sel_move);
  11749. if (goals.length) { for (var i = 0; i < doc.sel.ranges.length; i++)
  11750. { doc.sel.ranges[i].goalColumn = goals[i]; } }
  11751. }),
  11752. // Find the word at the given position (as returned by coordsChar).
  11753. findWordAt: function(pos) {
  11754. var doc = this.doc, line = getLine(doc, pos.line).text;
  11755. var start = pos.ch, end = pos.ch;
  11756. if (line) {
  11757. var helper = this.getHelper(pos, "wordChars");
  11758. if ((pos.sticky == "before" || end == line.length) && start) { --start; } else { ++end; }
  11759. var startChar = line.charAt(start);
  11760. var check = isWordChar(startChar, helper)
  11761. ? function (ch) { return isWordChar(ch, helper); }
  11762. : /\s/.test(startChar) ? function (ch) { return /\s/.test(ch); }
  11763. : function (ch) { return (!/\s/.test(ch) && !isWordChar(ch)); };
  11764. while (start > 0 && check(line.charAt(start - 1))) { --start; }
  11765. while (end < line.length && check(line.charAt(end))) { ++end; }
  11766. }
  11767. return new Range(Pos(pos.line, start), Pos(pos.line, end))
  11768. },
  11769. toggleOverwrite: function(value) {
  11770. if (value != null && value == this.state.overwrite) { return }
  11771. if (this.state.overwrite = !this.state.overwrite)
  11772. { addClass(this.display.cursorDiv, "CodeMirror-overwrite"); }
  11773. else
  11774. { rmClass(this.display.cursorDiv, "CodeMirror-overwrite"); }
  11775. signal(this, "overwriteToggle", this, this.state.overwrite);
  11776. },
  11777. hasFocus: function() { return this.display.input.getField() == activeElt() },
  11778. isReadOnly: function() { return !!(this.options.readOnly || this.doc.cantEdit) },
  11779. scrollTo: methodOp(function (x, y) { scrollToCoords(this, x, y); }),
  11780. getScrollInfo: function() {
  11781. var scroller = this.display.scroller;
  11782. return {left: scroller.scrollLeft, top: scroller.scrollTop,
  11783. height: scroller.scrollHeight - scrollGap(this) - this.display.barHeight,
  11784. width: scroller.scrollWidth - scrollGap(this) - this.display.barWidth,
  11785. clientHeight: displayHeight(this), clientWidth: displayWidth(this)}
  11786. },
  11787. scrollIntoView: methodOp(function(range$$1, margin) {
  11788. if (range$$1 == null) {
  11789. range$$1 = {from: this.doc.sel.primary().head, to: null};
  11790. if (margin == null) { margin = this.options.cursorScrollMargin; }
  11791. } else if (typeof range$$1 == "number") {
  11792. range$$1 = {from: Pos(range$$1, 0), to: null};
  11793. } else if (range$$1.from == null) {
  11794. range$$1 = {from: range$$1, to: null};
  11795. }
  11796. if (!range$$1.to) { range$$1.to = range$$1.from; }
  11797. range$$1.margin = margin || 0;
  11798. if (range$$1.from.line != null) {
  11799. scrollToRange(this, range$$1);
  11800. } else {
  11801. scrollToCoordsRange(this, range$$1.from, range$$1.to, range$$1.margin);
  11802. }
  11803. }),
  11804. setSize: methodOp(function(width, height) {
  11805. var this$1 = this;
  11806. var interpret = function (val) { return typeof val == "number" || /^\d+$/.test(String(val)) ? val + "px" : val; };
  11807. if (width != null) { this.display.wrapper.style.width = interpret(width); }
  11808. if (height != null) { this.display.wrapper.style.height = interpret(height); }
  11809. if (this.options.lineWrapping) { clearLineMeasurementCache(this); }
  11810. var lineNo$$1 = this.display.viewFrom;
  11811. this.doc.iter(lineNo$$1, this.display.viewTo, function (line) {
  11812. if (line.widgets) { for (var i = 0; i < line.widgets.length; i++)
  11813. { if (line.widgets[i].noHScroll) { regLineChange(this$1, lineNo$$1, "widget"); break } } }
  11814. ++lineNo$$1;
  11815. });
  11816. this.curOp.forceUpdate = true;
  11817. signal(this, "refresh", this);
  11818. }),
  11819. operation: function(f){return runInOp(this, f)},
  11820. startOperation: function(){return startOperation(this)},
  11821. endOperation: function(){return endOperation(this)},
  11822. refresh: methodOp(function() {
  11823. var oldHeight = this.display.cachedTextHeight;
  11824. regChange(this);
  11825. this.curOp.forceUpdate = true;
  11826. clearCaches(this);
  11827. scrollToCoords(this, this.doc.scrollLeft, this.doc.scrollTop);
  11828. updateGutterSpace(this.display);
  11829. if (oldHeight == null || Math.abs(oldHeight - textHeight(this.display)) > .5)
  11830. { estimateLineHeights(this); }
  11831. signal(this, "refresh", this);
  11832. }),
  11833. swapDoc: methodOp(function(doc) {
  11834. var old = this.doc;
  11835. old.cm = null;
  11836. // Cancel the current text selection if any (#5821)
  11837. if (this.state.selectingText) { this.state.selectingText(); }
  11838. attachDoc(this, doc);
  11839. clearCaches(this);
  11840. this.display.input.reset();
  11841. scrollToCoords(this, doc.scrollLeft, doc.scrollTop);
  11842. this.curOp.forceScroll = true;
  11843. signalLater(this, "swapDoc", this, old);
  11844. return old
  11845. }),
  11846. phrase: function(phraseText) {
  11847. var phrases = this.options.phrases;
  11848. return phrases && Object.prototype.hasOwnProperty.call(phrases, phraseText) ? phrases[phraseText] : phraseText
  11849. },
  11850. getInputField: function(){return this.display.input.getField()},
  11851. getWrapperElement: function(){return this.display.wrapper},
  11852. getScrollerElement: function(){return this.display.scroller},
  11853. getGutterElement: function(){return this.display.gutters}
  11854. };
  11855. eventMixin(CodeMirror);
  11856. CodeMirror.registerHelper = function(type, name, value) {
  11857. if (!helpers.hasOwnProperty(type)) { helpers[type] = CodeMirror[type] = {_global: []}; }
  11858. helpers[type][name] = value;
  11859. };
  11860. CodeMirror.registerGlobalHelper = function(type, name, predicate, value) {
  11861. CodeMirror.registerHelper(type, name, value);
  11862. helpers[type]._global.push({pred: predicate, val: value});
  11863. };
  11864. }
  11865. // Used for horizontal relative motion. Dir is -1 or 1 (left or
  11866. // right), unit can be "char", "column" (like char, but doesn't
  11867. // cross line boundaries), "word" (across next word), or "group" (to
  11868. // the start of next group of word or non-word-non-whitespace
  11869. // chars). The visually param controls whether, in right-to-left
  11870. // text, direction 1 means to move towards the next index in the
  11871. // string, or towards the character to the right of the current
  11872. // position. The resulting position will have a hitSide=true
  11873. // property if it reached the end of the document.
  11874. function findPosH(doc, pos, dir, unit, visually) {
  11875. var oldPos = pos;
  11876. var origDir = dir;
  11877. var lineObj = getLine(doc, pos.line);
  11878. function findNextLine() {
  11879. var l = pos.line + dir;
  11880. if (l < doc.first || l >= doc.first + doc.size) { return false }
  11881. pos = new Pos(l, pos.ch, pos.sticky);
  11882. return lineObj = getLine(doc, l)
  11883. }
  11884. function moveOnce(boundToLine) {
  11885. var next;
  11886. if (visually) {
  11887. next = moveVisually(doc.cm, lineObj, pos, dir);
  11888. } else {
  11889. next = moveLogically(lineObj, pos, dir);
  11890. }
  11891. if (next == null) {
  11892. if (!boundToLine && findNextLine())
  11893. { pos = endOfLine(visually, doc.cm, lineObj, pos.line, dir); }
  11894. else
  11895. { return false }
  11896. } else {
  11897. pos = next;
  11898. }
  11899. return true
  11900. }
  11901. if (unit == "char") {
  11902. moveOnce();
  11903. } else if (unit == "column") {
  11904. moveOnce(true);
  11905. } else if (unit == "word" || unit == "group") {
  11906. var sawType = null, group = unit == "group";
  11907. var helper = doc.cm && doc.cm.getHelper(pos, "wordChars");
  11908. for (var first = true;; first = false) {
  11909. if (dir < 0 && !moveOnce(!first)) { break }
  11910. var cur = lineObj.text.charAt(pos.ch) || "\n";
  11911. var type = isWordChar(cur, helper) ? "w"
  11912. : group && cur == "\n" ? "n"
  11913. : !group || /\s/.test(cur) ? null
  11914. : "p";
  11915. if (group && !first && !type) { type = "s"; }
  11916. if (sawType && sawType != type) {
  11917. if (dir < 0) {dir = 1; moveOnce(); pos.sticky = "after";}
  11918. break
  11919. }
  11920. if (type) { sawType = type; }
  11921. if (dir > 0 && !moveOnce(!first)) { break }
  11922. }
  11923. }
  11924. var result = skipAtomic(doc, pos, oldPos, origDir, true);
  11925. if (equalCursorPos(oldPos, result)) { result.hitSide = true; }
  11926. return result
  11927. }
  11928. // For relative vertical movement. Dir may be -1 or 1. Unit can be
  11929. // "page" or "line". The resulting position will have a hitSide=true
  11930. // property if it reached the end of the document.
  11931. function findPosV(cm, pos, dir, unit) {
  11932. var doc = cm.doc, x = pos.left, y;
  11933. if (unit == "page") {
  11934. var pageSize = Math.min(cm.display.wrapper.clientHeight, window.innerHeight || document.documentElement.clientHeight);
  11935. var moveAmount = Math.max(pageSize - .5 * textHeight(cm.display), 3);
  11936. y = (dir > 0 ? pos.bottom : pos.top) + dir * moveAmount;
  11937. } else if (unit == "line") {
  11938. y = dir > 0 ? pos.bottom + 3 : pos.top - 3;
  11939. }
  11940. var target;
  11941. for (;;) {
  11942. target = coordsChar(cm, x, y);
  11943. if (!target.outside) { break }
  11944. if (dir < 0 ? y <= 0 : y >= doc.height) { target.hitSide = true; break }
  11945. y += dir * 5;
  11946. }
  11947. return target
  11948. }
  11949. // CONTENTEDITABLE INPUT STYLE
  11950. var ContentEditableInput = function(cm) {
  11951. this.cm = cm;
  11952. this.lastAnchorNode = this.lastAnchorOffset = this.lastFocusNode = this.lastFocusOffset = null;
  11953. this.polling = new Delayed();
  11954. this.composing = null;
  11955. this.gracePeriod = false;
  11956. this.readDOMTimeout = null;
  11957. };
  11958. ContentEditableInput.prototype.init = function (display) {
  11959. var this$1 = this;
  11960. var input = this, cm = input.cm;
  11961. var div = input.div = display.lineDiv;
  11962. disableBrowserMagic(div, cm.options.spellcheck, cm.options.autocorrect, cm.options.autocapitalize);
  11963. on(div, "paste", function (e) {
  11964. if (signalDOMEvent(cm, e) || handlePaste(e, cm)) { return }
  11965. // IE doesn't fire input events, so we schedule a read for the pasted content in this way
  11966. if (ie_version <= 11) { setTimeout(operation(cm, function () { return this$1.updateFromDOM(); }), 20); }
  11967. });
  11968. on(div, "compositionstart", function (e) {
  11969. this$1.composing = {data: e.data, done: false};
  11970. });
  11971. on(div, "compositionupdate", function (e) {
  11972. if (!this$1.composing) { this$1.composing = {data: e.data, done: false}; }
  11973. });
  11974. on(div, "compositionend", function (e) {
  11975. if (this$1.composing) {
  11976. if (e.data != this$1.composing.data) { this$1.readFromDOMSoon(); }
  11977. this$1.composing.done = true;
  11978. }
  11979. });
  11980. on(div, "touchstart", function () { return input.forceCompositionEnd(); });
  11981. on(div, "input", function () {
  11982. if (!this$1.composing) { this$1.readFromDOMSoon(); }
  11983. });
  11984. function onCopyCut(e) {
  11985. if (signalDOMEvent(cm, e)) { return }
  11986. if (cm.somethingSelected()) {
  11987. setLastCopied({lineWise: false, text: cm.getSelections()});
  11988. if (e.type == "cut") { cm.replaceSelection("", null, "cut"); }
  11989. } else if (!cm.options.lineWiseCopyCut) {
  11990. return
  11991. } else {
  11992. var ranges = copyableRanges(cm);
  11993. setLastCopied({lineWise: true, text: ranges.text});
  11994. if (e.type == "cut") {
  11995. cm.operation(function () {
  11996. cm.setSelections(ranges.ranges, 0, sel_dontScroll);
  11997. cm.replaceSelection("", null, "cut");
  11998. });
  11999. }
  12000. }
  12001. if (e.clipboardData) {
  12002. e.clipboardData.clearData();
  12003. var content = lastCopied.text.join("\n");
  12004. // iOS exposes the clipboard API, but seems to discard content inserted into it
  12005. e.clipboardData.setData("Text", content);
  12006. if (e.clipboardData.getData("Text") == content) {
  12007. e.preventDefault();
  12008. return
  12009. }
  12010. }
  12011. // Old-fashioned briefly-focus-a-textarea hack
  12012. var kludge = hiddenTextarea(), te = kludge.firstChild;
  12013. cm.display.lineSpace.insertBefore(kludge, cm.display.lineSpace.firstChild);
  12014. te.value = lastCopied.text.join("\n");
  12015. var hadFocus = document.activeElement;
  12016. selectInput(te);
  12017. setTimeout(function () {
  12018. cm.display.lineSpace.removeChild(kludge);
  12019. hadFocus.focus();
  12020. if (hadFocus == div) { input.showPrimarySelection(); }
  12021. }, 50);
  12022. }
  12023. on(div, "copy", onCopyCut);
  12024. on(div, "cut", onCopyCut);
  12025. };
  12026. ContentEditableInput.prototype.prepareSelection = function () {
  12027. var result = prepareSelection(this.cm, false);
  12028. result.focus = this.cm.state.focused;
  12029. return result
  12030. };
  12031. ContentEditableInput.prototype.showSelection = function (info, takeFocus) {
  12032. if (!info || !this.cm.display.view.length) { return }
  12033. if (info.focus || takeFocus) { this.showPrimarySelection(); }
  12034. this.showMultipleSelections(info);
  12035. };
  12036. ContentEditableInput.prototype.getSelection = function () {
  12037. return this.cm.display.wrapper.ownerDocument.getSelection()
  12038. };
  12039. ContentEditableInput.prototype.showPrimarySelection = function () {
  12040. var sel = this.getSelection(), cm = this.cm, prim = cm.doc.sel.primary();
  12041. var from = prim.from(), to = prim.to();
  12042. if (cm.display.viewTo == cm.display.viewFrom || from.line >= cm.display.viewTo || to.line < cm.display.viewFrom) {
  12043. sel.removeAllRanges();
  12044. return
  12045. }
  12046. var curAnchor = domToPos(cm, sel.anchorNode, sel.anchorOffset);
  12047. var curFocus = domToPos(cm, sel.focusNode, sel.focusOffset);
  12048. if (curAnchor && !curAnchor.bad && curFocus && !curFocus.bad &&
  12049. cmp(minPos(curAnchor, curFocus), from) == 0 &&
  12050. cmp(maxPos(curAnchor, curFocus), to) == 0)
  12051. { return }
  12052. var view = cm.display.view;
  12053. var start = (from.line >= cm.display.viewFrom && posToDOM(cm, from)) ||
  12054. {node: view[0].measure.map[2], offset: 0};
  12055. var end = to.line < cm.display.viewTo && posToDOM(cm, to);
  12056. if (!end) {
  12057. var measure = view[view.length - 1].measure;
  12058. var map$$1 = measure.maps ? measure.maps[measure.maps.length - 1] : measure.map;
  12059. end = {node: map$$1[map$$1.length - 1], offset: map$$1[map$$1.length - 2] - map$$1[map$$1.length - 3]};
  12060. }
  12061. if (!start || !end) {
  12062. sel.removeAllRanges();
  12063. return
  12064. }
  12065. var old = sel.rangeCount && sel.getRangeAt(0), rng;
  12066. try { rng = range(start.node, start.offset, end.offset, end.node); }
  12067. catch(e) {} // Our model of the DOM might be outdated, in which case the range we try to set can be impossible
  12068. if (rng) {
  12069. if (!gecko && cm.state.focused) {
  12070. sel.collapse(start.node, start.offset);
  12071. if (!rng.collapsed) {
  12072. sel.removeAllRanges();
  12073. sel.addRange(rng);
  12074. }
  12075. } else {
  12076. sel.removeAllRanges();
  12077. sel.addRange(rng);
  12078. }
  12079. if (old && sel.anchorNode == null) { sel.addRange(old); }
  12080. else if (gecko) { this.startGracePeriod(); }
  12081. }
  12082. this.rememberSelection();
  12083. };
  12084. ContentEditableInput.prototype.startGracePeriod = function () {
  12085. var this$1 = this;
  12086. clearTimeout(this.gracePeriod);
  12087. this.gracePeriod = setTimeout(function () {
  12088. this$1.gracePeriod = false;
  12089. if (this$1.selectionChanged())
  12090. { this$1.cm.operation(function () { return this$1.cm.curOp.selectionChanged = true; }); }
  12091. }, 20);
  12092. };
  12093. ContentEditableInput.prototype.showMultipleSelections = function (info) {
  12094. removeChildrenAndAdd(this.cm.display.cursorDiv, info.cursors);
  12095. removeChildrenAndAdd(this.cm.display.selectionDiv, info.selection);
  12096. };
  12097. ContentEditableInput.prototype.rememberSelection = function () {
  12098. var sel = this.getSelection();
  12099. this.lastAnchorNode = sel.anchorNode; this.lastAnchorOffset = sel.anchorOffset;
  12100. this.lastFocusNode = sel.focusNode; this.lastFocusOffset = sel.focusOffset;
  12101. };
  12102. ContentEditableInput.prototype.selectionInEditor = function () {
  12103. var sel = this.getSelection();
  12104. if (!sel.rangeCount) { return false }
  12105. var node = sel.getRangeAt(0).commonAncestorContainer;
  12106. return contains(this.div, node)
  12107. };
  12108. ContentEditableInput.prototype.focus = function () {
  12109. if (this.cm.options.readOnly != "nocursor") {
  12110. if (!this.selectionInEditor())
  12111. { this.showSelection(this.prepareSelection(), true); }
  12112. this.div.focus();
  12113. }
  12114. };
  12115. ContentEditableInput.prototype.blur = function () { this.div.blur(); };
  12116. ContentEditableInput.prototype.getField = function () { return this.div };
  12117. ContentEditableInput.prototype.supportsTouch = function () { return true };
  12118. ContentEditableInput.prototype.receivedFocus = function () {
  12119. var input = this;
  12120. if (this.selectionInEditor())
  12121. { this.pollSelection(); }
  12122. else
  12123. { runInOp(this.cm, function () { return input.cm.curOp.selectionChanged = true; }); }
  12124. function poll() {
  12125. if (input.cm.state.focused) {
  12126. input.pollSelection();
  12127. input.polling.set(input.cm.options.pollInterval, poll);
  12128. }
  12129. }
  12130. this.polling.set(this.cm.options.pollInterval, poll);
  12131. };
  12132. ContentEditableInput.prototype.selectionChanged = function () {
  12133. var sel = this.getSelection();
  12134. return sel.anchorNode != this.lastAnchorNode || sel.anchorOffset != this.lastAnchorOffset ||
  12135. sel.focusNode != this.lastFocusNode || sel.focusOffset != this.lastFocusOffset
  12136. };
  12137. ContentEditableInput.prototype.pollSelection = function () {
  12138. if (this.readDOMTimeout != null || this.gracePeriod || !this.selectionChanged()) { return }
  12139. var sel = this.getSelection(), cm = this.cm;
  12140. // On Android Chrome (version 56, at least), backspacing into an
  12141. // uneditable block element will put the cursor in that element,
  12142. // and then, because it's not editable, hide the virtual keyboard.
  12143. // Because Android doesn't allow us to actually detect backspace
  12144. // presses in a sane way, this code checks for when that happens
  12145. // and simulates a backspace press in this case.
  12146. if (android && chrome && this.cm.display.gutterSpecs.length && isInGutter(sel.anchorNode)) {
  12147. this.cm.triggerOnKeyDown({type: "keydown", keyCode: 8, preventDefault: Math.abs});
  12148. this.blur();
  12149. this.focus();
  12150. return
  12151. }
  12152. if (this.composing) { return }
  12153. this.rememberSelection();
  12154. var anchor = domToPos(cm, sel.anchorNode, sel.anchorOffset);
  12155. var head = domToPos(cm, sel.focusNode, sel.focusOffset);
  12156. if (anchor && head) { runInOp(cm, function () {
  12157. setSelection(cm.doc, simpleSelection(anchor, head), sel_dontScroll);
  12158. if (anchor.bad || head.bad) { cm.curOp.selectionChanged = true; }
  12159. }); }
  12160. };
  12161. ContentEditableInput.prototype.pollContent = function () {
  12162. if (this.readDOMTimeout != null) {
  12163. clearTimeout(this.readDOMTimeout);
  12164. this.readDOMTimeout = null;
  12165. }
  12166. var cm = this.cm, display = cm.display, sel = cm.doc.sel.primary();
  12167. var from = sel.from(), to = sel.to();
  12168. if (from.ch == 0 && from.line > cm.firstLine())
  12169. { from = Pos(from.line - 1, getLine(cm.doc, from.line - 1).length); }
  12170. if (to.ch == getLine(cm.doc, to.line).text.length && to.line < cm.lastLine())
  12171. { to = Pos(to.line + 1, 0); }
  12172. if (from.line < display.viewFrom || to.line > display.viewTo - 1) { return false }
  12173. var fromIndex, fromLine, fromNode;
  12174. if (from.line == display.viewFrom || (fromIndex = findViewIndex(cm, from.line)) == 0) {
  12175. fromLine = lineNo(display.view[0].line);
  12176. fromNode = display.view[0].node;
  12177. } else {
  12178. fromLine = lineNo(display.view[fromIndex].line);
  12179. fromNode = display.view[fromIndex - 1].node.nextSibling;
  12180. }
  12181. var toIndex = findViewIndex(cm, to.line);
  12182. var toLine, toNode;
  12183. if (toIndex == display.view.length - 1) {
  12184. toLine = display.viewTo - 1;
  12185. toNode = display.lineDiv.lastChild;
  12186. } else {
  12187. toLine = lineNo(display.view[toIndex + 1].line) - 1;
  12188. toNode = display.view[toIndex + 1].node.previousSibling;
  12189. }
  12190. if (!fromNode) { return false }
  12191. var newText = cm.doc.splitLines(domTextBetween(cm, fromNode, toNode, fromLine, toLine));
  12192. var oldText = getBetween(cm.doc, Pos(fromLine, 0), Pos(toLine, getLine(cm.doc, toLine).text.length));
  12193. while (newText.length > 1 && oldText.length > 1) {
  12194. if (lst(newText) == lst(oldText)) { newText.pop(); oldText.pop(); toLine--; }
  12195. else if (newText[0] == oldText[0]) { newText.shift(); oldText.shift(); fromLine++; }
  12196. else { break }
  12197. }
  12198. var cutFront = 0, cutEnd = 0;
  12199. var newTop = newText[0], oldTop = oldText[0], maxCutFront = Math.min(newTop.length, oldTop.length);
  12200. while (cutFront < maxCutFront && newTop.charCodeAt(cutFront) == oldTop.charCodeAt(cutFront))
  12201. { ++cutFront; }
  12202. var newBot = lst(newText), oldBot = lst(oldText);
  12203. var maxCutEnd = Math.min(newBot.length - (newText.length == 1 ? cutFront : 0),
  12204. oldBot.length - (oldText.length == 1 ? cutFront : 0));
  12205. while (cutEnd < maxCutEnd &&
  12206. newBot.charCodeAt(newBot.length - cutEnd - 1) == oldBot.charCodeAt(oldBot.length - cutEnd - 1))
  12207. { ++cutEnd; }
  12208. // Try to move start of change to start of selection if ambiguous
  12209. if (newText.length == 1 && oldText.length == 1 && fromLine == from.line) {
  12210. while (cutFront && cutFront > from.ch &&
  12211. newBot.charCodeAt(newBot.length - cutEnd - 1) == oldBot.charCodeAt(oldBot.length - cutEnd - 1)) {
  12212. cutFront--;
  12213. cutEnd++;
  12214. }
  12215. }
  12216. newText[newText.length - 1] = newBot.slice(0, newBot.length - cutEnd).replace(/^\u200b+/, "");
  12217. newText[0] = newText[0].slice(cutFront).replace(/\u200b+$/, "");
  12218. var chFrom = Pos(fromLine, cutFront);
  12219. var chTo = Pos(toLine, oldText.length ? lst(oldText).length - cutEnd : 0);
  12220. if (newText.length > 1 || newText[0] || cmp(chFrom, chTo)) {
  12221. replaceRange(cm.doc, newText, chFrom, chTo, "+input");
  12222. return true
  12223. }
  12224. };
  12225. ContentEditableInput.prototype.ensurePolled = function () {
  12226. this.forceCompositionEnd();
  12227. };
  12228. ContentEditableInput.prototype.reset = function () {
  12229. this.forceCompositionEnd();
  12230. };
  12231. ContentEditableInput.prototype.forceCompositionEnd = function () {
  12232. if (!this.composing) { return }
  12233. clearTimeout(this.readDOMTimeout);
  12234. this.composing = null;
  12235. this.updateFromDOM();
  12236. this.div.blur();
  12237. this.div.focus();
  12238. };
  12239. ContentEditableInput.prototype.readFromDOMSoon = function () {
  12240. var this$1 = this;
  12241. if (this.readDOMTimeout != null) { return }
  12242. this.readDOMTimeout = setTimeout(function () {
  12243. this$1.readDOMTimeout = null;
  12244. if (this$1.composing) {
  12245. if (this$1.composing.done) { this$1.composing = null; }
  12246. else { return }
  12247. }
  12248. this$1.updateFromDOM();
  12249. }, 80);
  12250. };
  12251. ContentEditableInput.prototype.updateFromDOM = function () {
  12252. var this$1 = this;
  12253. if (this.cm.isReadOnly() || !this.pollContent())
  12254. { runInOp(this.cm, function () { return regChange(this$1.cm); }); }
  12255. };
  12256. ContentEditableInput.prototype.setUneditable = function (node) {
  12257. node.contentEditable = "false";
  12258. };
  12259. ContentEditableInput.prototype.onKeyPress = function (e) {
  12260. if (e.charCode == 0 || this.composing) { return }
  12261. e.preventDefault();
  12262. if (!this.cm.isReadOnly())
  12263. { operation(this.cm, applyTextInput)(this.cm, String.fromCharCode(e.charCode == null ? e.keyCode : e.charCode), 0); }
  12264. };
  12265. ContentEditableInput.prototype.readOnlyChanged = function (val) {
  12266. this.div.contentEditable = String(val != "nocursor");
  12267. };
  12268. ContentEditableInput.prototype.onContextMenu = function () {};
  12269. ContentEditableInput.prototype.resetPosition = function () {};
  12270. ContentEditableInput.prototype.needsContentAttribute = true;
  12271. function posToDOM(cm, pos) {
  12272. var view = findViewForLine(cm, pos.line);
  12273. if (!view || view.hidden) { return null }
  12274. var line = getLine(cm.doc, pos.line);
  12275. var info = mapFromLineView(view, line, pos.line);
  12276. var order = getOrder(line, cm.doc.direction), side = "left";
  12277. if (order) {
  12278. var partPos = getBidiPartAt(order, pos.ch);
  12279. side = partPos % 2 ? "right" : "left";
  12280. }
  12281. var result = nodeAndOffsetInLineMap(info.map, pos.ch, side);
  12282. result.offset = result.collapse == "right" ? result.end : result.start;
  12283. return result
  12284. }
  12285. function isInGutter(node) {
  12286. for (var scan = node; scan; scan = scan.parentNode)
  12287. { if (/CodeMirror-gutter-wrapper/.test(scan.className)) { return true } }
  12288. return false
  12289. }
  12290. function badPos(pos, bad) { if (bad) { pos.bad = true; } return pos }
  12291. function domTextBetween(cm, from, to, fromLine, toLine) {
  12292. var text = "", closing = false, lineSep = cm.doc.lineSeparator(), extraLinebreak = false;
  12293. function recognizeMarker(id) { return function (marker) { return marker.id == id; } }
  12294. function close() {
  12295. if (closing) {
  12296. text += lineSep;
  12297. if (extraLinebreak) { text += lineSep; }
  12298. closing = extraLinebreak = false;
  12299. }
  12300. }
  12301. function addText(str) {
  12302. if (str) {
  12303. close();
  12304. text += str;
  12305. }
  12306. }
  12307. function walk(node) {
  12308. if (node.nodeType == 1) {
  12309. var cmText = node.getAttribute("cm-text");
  12310. if (cmText) {
  12311. addText(cmText);
  12312. return
  12313. }
  12314. var markerID = node.getAttribute("cm-marker"), range$$1;
  12315. if (markerID) {
  12316. var found = cm.findMarks(Pos(fromLine, 0), Pos(toLine + 1, 0), recognizeMarker(+markerID));
  12317. if (found.length && (range$$1 = found[0].find(0)))
  12318. { addText(getBetween(cm.doc, range$$1.from, range$$1.to).join(lineSep)); }
  12319. return
  12320. }
  12321. if (node.getAttribute("contenteditable") == "false") { return }
  12322. var isBlock = /^(pre|div|p|li|table|br)$/i.test(node.nodeName);
  12323. if (!/^br$/i.test(node.nodeName) && node.textContent.length == 0) { return }
  12324. if (isBlock) { close(); }
  12325. for (var i = 0; i < node.childNodes.length; i++)
  12326. { walk(node.childNodes[i]); }
  12327. if (/^(pre|p)$/i.test(node.nodeName)) { extraLinebreak = true; }
  12328. if (isBlock) { closing = true; }
  12329. } else if (node.nodeType == 3) {
  12330. addText(node.nodeValue.replace(/\u200b/g, "").replace(/\u00a0/g, " "));
  12331. }
  12332. }
  12333. for (;;) {
  12334. walk(from);
  12335. if (from == to) { break }
  12336. from = from.nextSibling;
  12337. extraLinebreak = false;
  12338. }
  12339. return text
  12340. }
  12341. function domToPos(cm, node, offset) {
  12342. var lineNode;
  12343. if (node == cm.display.lineDiv) {
  12344. lineNode = cm.display.lineDiv.childNodes[offset];
  12345. if (!lineNode) { return badPos(cm.clipPos(Pos(cm.display.viewTo - 1)), true) }
  12346. node = null; offset = 0;
  12347. } else {
  12348. for (lineNode = node;; lineNode = lineNode.parentNode) {
  12349. if (!lineNode || lineNode == cm.display.lineDiv) { return null }
  12350. if (lineNode.parentNode && lineNode.parentNode == cm.display.lineDiv) { break }
  12351. }
  12352. }
  12353. for (var i = 0; i < cm.display.view.length; i++) {
  12354. var lineView = cm.display.view[i];
  12355. if (lineView.node == lineNode)
  12356. { return locateNodeInLineView(lineView, node, offset) }
  12357. }
  12358. }
  12359. function locateNodeInLineView(lineView, node, offset) {
  12360. var wrapper = lineView.text.firstChild, bad = false;
  12361. if (!node || !contains(wrapper, node)) { return badPos(Pos(lineNo(lineView.line), 0), true) }
  12362. if (node == wrapper) {
  12363. bad = true;
  12364. node = wrapper.childNodes[offset];
  12365. offset = 0;
  12366. if (!node) {
  12367. var line = lineView.rest ? lst(lineView.rest) : lineView.line;
  12368. return badPos(Pos(lineNo(line), line.text.length), bad)
  12369. }
  12370. }
  12371. var textNode = node.nodeType == 3 ? node : null, topNode = node;
  12372. if (!textNode && node.childNodes.length == 1 && node.firstChild.nodeType == 3) {
  12373. textNode = node.firstChild;
  12374. if (offset) { offset = textNode.nodeValue.length; }
  12375. }
  12376. while (topNode.parentNode != wrapper) { topNode = topNode.parentNode; }
  12377. var measure = lineView.measure, maps = measure.maps;
  12378. function find(textNode, topNode, offset) {
  12379. for (var i = -1; i < (maps ? maps.length : 0); i++) {
  12380. var map$$1 = i < 0 ? measure.map : maps[i];
  12381. for (var j = 0; j < map$$1.length; j += 3) {
  12382. var curNode = map$$1[j + 2];
  12383. if (curNode == textNode || curNode == topNode) {
  12384. var line = lineNo(i < 0 ? lineView.line : lineView.rest[i]);
  12385. var ch = map$$1[j] + offset;
  12386. if (offset < 0 || curNode != textNode) { ch = map$$1[j + (offset ? 1 : 0)]; }
  12387. return Pos(line, ch)
  12388. }
  12389. }
  12390. }
  12391. }
  12392. var found = find(textNode, topNode, offset);
  12393. if (found) { return badPos(found, bad) }
  12394. // FIXME this is all really shaky. might handle the few cases it needs to handle, but likely to cause problems
  12395. for (var after = topNode.nextSibling, dist = textNode ? textNode.nodeValue.length - offset : 0; after; after = after.nextSibling) {
  12396. found = find(after, after.firstChild, 0);
  12397. if (found)
  12398. { return badPos(Pos(found.line, found.ch - dist), bad) }
  12399. else
  12400. { dist += after.textContent.length; }
  12401. }
  12402. for (var before = topNode.previousSibling, dist$1 = offset; before; before = before.previousSibling) {
  12403. found = find(before, before.firstChild, -1);
  12404. if (found)
  12405. { return badPos(Pos(found.line, found.ch + dist$1), bad) }
  12406. else
  12407. { dist$1 += before.textContent.length; }
  12408. }
  12409. }
  12410. // TEXTAREA INPUT STYLE
  12411. var TextareaInput = function(cm) {
  12412. this.cm = cm;
  12413. // See input.poll and input.reset
  12414. this.prevInput = "";
  12415. // Flag that indicates whether we expect input to appear real soon
  12416. // now (after some event like 'keypress' or 'input') and are
  12417. // polling intensively.
  12418. this.pollingFast = false;
  12419. // Self-resetting timeout for the poller
  12420. this.polling = new Delayed();
  12421. // Used to work around IE issue with selection being forgotten when focus moves away from textarea
  12422. this.hasSelection = false;
  12423. this.composing = null;
  12424. };
  12425. TextareaInput.prototype.init = function (display) {
  12426. var this$1 = this;
  12427. var input = this, cm = this.cm;
  12428. this.createField(display);
  12429. var te = this.textarea;
  12430. display.wrapper.insertBefore(this.wrapper, display.wrapper.firstChild);
  12431. // Needed to hide big blue blinking cursor on Mobile Safari (doesn't seem to work in iOS 8 anymore)
  12432. if (ios) { te.style.width = "0px"; }
  12433. on(te, "input", function () {
  12434. if (ie && ie_version >= 9 && this$1.hasSelection) { this$1.hasSelection = null; }
  12435. input.poll();
  12436. });
  12437. on(te, "paste", function (e) {
  12438. if (signalDOMEvent(cm, e) || handlePaste(e, cm)) { return }
  12439. cm.state.pasteIncoming = +new Date;
  12440. input.fastPoll();
  12441. });
  12442. function prepareCopyCut(e) {
  12443. if (signalDOMEvent(cm, e)) { return }
  12444. if (cm.somethingSelected()) {
  12445. setLastCopied({lineWise: false, text: cm.getSelections()});
  12446. } else if (!cm.options.lineWiseCopyCut) {
  12447. return
  12448. } else {
  12449. var ranges = copyableRanges(cm);
  12450. setLastCopied({lineWise: true, text: ranges.text});
  12451. if (e.type == "cut") {
  12452. cm.setSelections(ranges.ranges, null, sel_dontScroll);
  12453. } else {
  12454. input.prevInput = "";
  12455. te.value = ranges.text.join("\n");
  12456. selectInput(te);
  12457. }
  12458. }
  12459. if (e.type == "cut") { cm.state.cutIncoming = +new Date; }
  12460. }
  12461. on(te, "cut", prepareCopyCut);
  12462. on(te, "copy", prepareCopyCut);
  12463. on(display.scroller, "paste", function (e) {
  12464. if (eventInWidget(display, e) || signalDOMEvent(cm, e)) { return }
  12465. if (!te.dispatchEvent) {
  12466. cm.state.pasteIncoming = +new Date;
  12467. input.focus();
  12468. return
  12469. }
  12470. // Pass the `paste` event to the textarea so it's handled by its event listener.
  12471. var event = new Event("paste");
  12472. event.clipboardData = e.clipboardData;
  12473. te.dispatchEvent(event);
  12474. });
  12475. // Prevent normal selection in the editor (we handle our own)
  12476. on(display.lineSpace, "selectstart", function (e) {
  12477. if (!eventInWidget(display, e)) { e_preventDefault(e); }
  12478. });
  12479. on(te, "compositionstart", function () {
  12480. var start = cm.getCursor("from");
  12481. if (input.composing) { input.composing.range.clear(); }
  12482. input.composing = {
  12483. start: start,
  12484. range: cm.markText(start, cm.getCursor("to"), {className: "CodeMirror-composing"})
  12485. };
  12486. });
  12487. on(te, "compositionend", function () {
  12488. if (input.composing) {
  12489. input.poll();
  12490. input.composing.range.clear();
  12491. input.composing = null;
  12492. }
  12493. });
  12494. };
  12495. TextareaInput.prototype.createField = function (_display) {
  12496. // Wraps and hides input textarea
  12497. this.wrapper = hiddenTextarea();
  12498. // The semihidden textarea that is focused when the editor is
  12499. // focused, and receives input.
  12500. this.textarea = this.wrapper.firstChild;
  12501. };
  12502. TextareaInput.prototype.prepareSelection = function () {
  12503. // Redraw the selection and/or cursor
  12504. var cm = this.cm, display = cm.display, doc = cm.doc;
  12505. var result = prepareSelection(cm);
  12506. // Move the hidden textarea near the cursor to prevent scrolling artifacts
  12507. if (cm.options.moveInputWithCursor) {
  12508. var headPos = cursorCoords(cm, doc.sel.primary().head, "div");
  12509. var wrapOff = display.wrapper.getBoundingClientRect(), lineOff = display.lineDiv.getBoundingClientRect();
  12510. result.teTop = Math.max(0, Math.min(display.wrapper.clientHeight - 10,
  12511. headPos.top + lineOff.top - wrapOff.top));
  12512. result.teLeft = Math.max(0, Math.min(display.wrapper.clientWidth - 10,
  12513. headPos.left + lineOff.left - wrapOff.left));
  12514. }
  12515. return result
  12516. };
  12517. TextareaInput.prototype.showSelection = function (drawn) {
  12518. var cm = this.cm, display = cm.display;
  12519. removeChildrenAndAdd(display.cursorDiv, drawn.cursors);
  12520. removeChildrenAndAdd(display.selectionDiv, drawn.selection);
  12521. if (drawn.teTop != null) {
  12522. this.wrapper.style.top = drawn.teTop + "px";
  12523. this.wrapper.style.left = drawn.teLeft + "px";
  12524. }
  12525. };
  12526. // Reset the input to correspond to the selection (or to be empty,
  12527. // when not typing and nothing is selected)
  12528. TextareaInput.prototype.reset = function (typing) {
  12529. if (this.contextMenuPending || this.composing) { return }
  12530. var cm = this.cm;
  12531. if (cm.somethingSelected()) {
  12532. this.prevInput = "";
  12533. var content = cm.getSelection();
  12534. this.textarea.value = content;
  12535. if (cm.state.focused) { selectInput(this.textarea); }
  12536. if (ie && ie_version >= 9) { this.hasSelection = content; }
  12537. } else if (!typing) {
  12538. this.prevInput = this.textarea.value = "";
  12539. if (ie && ie_version >= 9) { this.hasSelection = null; }
  12540. }
  12541. };
  12542. TextareaInput.prototype.getField = function () { return this.textarea };
  12543. TextareaInput.prototype.supportsTouch = function () { return false };
  12544. TextareaInput.prototype.focus = function () {
  12545. if (this.cm.options.readOnly != "nocursor" && (!mobile || activeElt() != this.textarea)) {
  12546. try { this.textarea.focus(); }
  12547. catch (e) {} // IE8 will throw if the textarea is display: none or not in DOM
  12548. }
  12549. };
  12550. TextareaInput.prototype.blur = function () { this.textarea.blur(); };
  12551. TextareaInput.prototype.resetPosition = function () {
  12552. this.wrapper.style.top = this.wrapper.style.left = 0;
  12553. };
  12554. TextareaInput.prototype.receivedFocus = function () { this.slowPoll(); };
  12555. // Poll for input changes, using the normal rate of polling. This
  12556. // runs as long as the editor is focused.
  12557. TextareaInput.prototype.slowPoll = function () {
  12558. var this$1 = this;
  12559. if (this.pollingFast) { return }
  12560. this.polling.set(this.cm.options.pollInterval, function () {
  12561. this$1.poll();
  12562. if (this$1.cm.state.focused) { this$1.slowPoll(); }
  12563. });
  12564. };
  12565. // When an event has just come in that is likely to add or change
  12566. // something in the input textarea, we poll faster, to ensure that
  12567. // the change appears on the screen quickly.
  12568. TextareaInput.prototype.fastPoll = function () {
  12569. var missed = false, input = this;
  12570. input.pollingFast = true;
  12571. function p() {
  12572. var changed = input.poll();
  12573. if (!changed && !missed) {missed = true; input.polling.set(60, p);}
  12574. else {input.pollingFast = false; input.slowPoll();}
  12575. }
  12576. input.polling.set(20, p);
  12577. };
  12578. // Read input from the textarea, and update the document to match.
  12579. // When something is selected, it is present in the textarea, and
  12580. // selected (unless it is huge, in which case a placeholder is
  12581. // used). When nothing is selected, the cursor sits after previously
  12582. // seen text (can be empty), which is stored in prevInput (we must
  12583. // not reset the textarea when typing, because that breaks IME).
  12584. TextareaInput.prototype.poll = function () {
  12585. var this$1 = this;
  12586. var cm = this.cm, input = this.textarea, prevInput = this.prevInput;
  12587. // Since this is called a *lot*, try to bail out as cheaply as
  12588. // possible when it is clear that nothing happened. hasSelection
  12589. // will be the case when there is a lot of text in the textarea,
  12590. // in which case reading its value would be expensive.
  12591. if (this.contextMenuPending || !cm.state.focused ||
  12592. (hasSelection(input) && !prevInput && !this.composing) ||
  12593. cm.isReadOnly() || cm.options.disableInput || cm.state.keySeq)
  12594. { return false }
  12595. var text = input.value;
  12596. // If nothing changed, bail.
  12597. if (text == prevInput && !cm.somethingSelected()) { return false }
  12598. // Work around nonsensical selection resetting in IE9/10, and
  12599. // inexplicable appearance of private area unicode characters on
  12600. // some key combos in Mac (#2689).
  12601. if (ie && ie_version >= 9 && this.hasSelection === text ||
  12602. mac && /[\uf700-\uf7ff]/.test(text)) {
  12603. cm.display.input.reset();
  12604. return false
  12605. }
  12606. if (cm.doc.sel == cm.display.selForContextMenu) {
  12607. var first = text.charCodeAt(0);
  12608. if (first == 0x200b && !prevInput) { prevInput = "\u200b"; }
  12609. if (first == 0x21da) { this.reset(); return this.cm.execCommand("undo") }
  12610. }
  12611. // Find the part of the input that is actually new
  12612. var same = 0, l = Math.min(prevInput.length, text.length);
  12613. while (same < l && prevInput.charCodeAt(same) == text.charCodeAt(same)) { ++same; }
  12614. runInOp(cm, function () {
  12615. applyTextInput(cm, text.slice(same), prevInput.length - same,
  12616. null, this$1.composing ? "*compose" : null);
  12617. // Don't leave long text in the textarea, since it makes further polling slow
  12618. if (text.length > 1000 || text.indexOf("\n") > -1) { input.value = this$1.prevInput = ""; }
  12619. else { this$1.prevInput = text; }
  12620. if (this$1.composing) {
  12621. this$1.composing.range.clear();
  12622. this$1.composing.range = cm.markText(this$1.composing.start, cm.getCursor("to"),
  12623. {className: "CodeMirror-composing"});
  12624. }
  12625. });
  12626. return true
  12627. };
  12628. TextareaInput.prototype.ensurePolled = function () {
  12629. if (this.pollingFast && this.poll()) { this.pollingFast = false; }
  12630. };
  12631. TextareaInput.prototype.onKeyPress = function () {
  12632. if (ie && ie_version >= 9) { this.hasSelection = null; }
  12633. this.fastPoll();
  12634. };
  12635. TextareaInput.prototype.onContextMenu = function (e) {
  12636. var input = this, cm = input.cm, display = cm.display, te = input.textarea;
  12637. if (input.contextMenuPending) { input.contextMenuPending(); }
  12638. var pos = posFromMouse(cm, e), scrollPos = display.scroller.scrollTop;
  12639. if (!pos || presto) { return } // Opera is difficult.
  12640. // Reset the current text selection only if the click is done outside of the selection
  12641. // and 'resetSelectionOnContextMenu' option is true.
  12642. var reset = cm.options.resetSelectionOnContextMenu;
  12643. if (reset && cm.doc.sel.contains(pos) == -1)
  12644. { operation(cm, setSelection)(cm.doc, simpleSelection(pos), sel_dontScroll); }
  12645. var oldCSS = te.style.cssText, oldWrapperCSS = input.wrapper.style.cssText;
  12646. var wrapperBox = input.wrapper.offsetParent.getBoundingClientRect();
  12647. input.wrapper.style.cssText = "position: static";
  12648. te.style.cssText = "position: absolute; width: 30px; height: 30px;\n top: " + (e.clientY - wrapperBox.top - 5) + "px; left: " + (e.clientX - wrapperBox.left - 5) + "px;\n z-index: 1000; background: " + (ie ? "rgba(255, 255, 255, .05)" : "transparent") + ";\n outline: none; border-width: 0; outline: none; overflow: hidden; opacity: .05; filter: alpha(opacity=5);";
  12649. var oldScrollY;
  12650. if (webkit) { oldScrollY = window.scrollY; } // Work around Chrome issue (#2712)
  12651. display.input.focus();
  12652. if (webkit) { window.scrollTo(null, oldScrollY); }
  12653. display.input.reset();
  12654. // Adds "Select all" to context menu in FF
  12655. if (!cm.somethingSelected()) { te.value = input.prevInput = " "; }
  12656. input.contextMenuPending = rehide;
  12657. display.selForContextMenu = cm.doc.sel;
  12658. clearTimeout(display.detectingSelectAll);
  12659. // Select-all will be greyed out if there's nothing to select, so
  12660. // this adds a zero-width space so that we can later check whether
  12661. // it got selected.
  12662. function prepareSelectAllHack() {
  12663. if (te.selectionStart != null) {
  12664. var selected = cm.somethingSelected();
  12665. var extval = "\u200b" + (selected ? te.value : "");
  12666. te.value = "\u21da"; // Used to catch context-menu undo
  12667. te.value = extval;
  12668. input.prevInput = selected ? "" : "\u200b";
  12669. te.selectionStart = 1; te.selectionEnd = extval.length;
  12670. // Re-set this, in case some other handler touched the
  12671. // selection in the meantime.
  12672. display.selForContextMenu = cm.doc.sel;
  12673. }
  12674. }
  12675. function rehide() {
  12676. if (input.contextMenuPending != rehide) { return }
  12677. input.contextMenuPending = false;
  12678. input.wrapper.style.cssText = oldWrapperCSS;
  12679. te.style.cssText = oldCSS;
  12680. if (ie && ie_version < 9) { display.scrollbars.setScrollTop(display.scroller.scrollTop = scrollPos); }
  12681. // Try to detect the user choosing select-all
  12682. if (te.selectionStart != null) {
  12683. if (!ie || (ie && ie_version < 9)) { prepareSelectAllHack(); }
  12684. var i = 0, poll = function () {
  12685. if (display.selForContextMenu == cm.doc.sel && te.selectionStart == 0 &&
  12686. te.selectionEnd > 0 && input.prevInput == "\u200b") {
  12687. operation(cm, selectAll)(cm);
  12688. } else if (i++ < 10) {
  12689. display.detectingSelectAll = setTimeout(poll, 500);
  12690. } else {
  12691. display.selForContextMenu = null;
  12692. display.input.reset();
  12693. }
  12694. };
  12695. display.detectingSelectAll = setTimeout(poll, 200);
  12696. }
  12697. }
  12698. if (ie && ie_version >= 9) { prepareSelectAllHack(); }
  12699. if (captureRightClick) {
  12700. e_stop(e);
  12701. var mouseup = function () {
  12702. off(window, "mouseup", mouseup);
  12703. setTimeout(rehide, 20);
  12704. };
  12705. on(window, "mouseup", mouseup);
  12706. } else {
  12707. setTimeout(rehide, 50);
  12708. }
  12709. };
  12710. TextareaInput.prototype.readOnlyChanged = function (val) {
  12711. if (!val) { this.reset(); }
  12712. this.textarea.disabled = val == "nocursor";
  12713. };
  12714. TextareaInput.prototype.setUneditable = function () {};
  12715. TextareaInput.prototype.needsContentAttribute = false;
  12716. function fromTextArea(textarea, options) {
  12717. options = options ? copyObj(options) : {};
  12718. options.value = textarea.value;
  12719. if (!options.tabindex && textarea.tabIndex)
  12720. { options.tabindex = textarea.tabIndex; }
  12721. if (!options.placeholder && textarea.placeholder)
  12722. { options.placeholder = textarea.placeholder; }
  12723. // Set autofocus to true if this textarea is focused, or if it has
  12724. // autofocus and no other element is focused.
  12725. if (options.autofocus == null) {
  12726. var hasFocus = activeElt();
  12727. options.autofocus = hasFocus == textarea ||
  12728. textarea.getAttribute("autofocus") != null && hasFocus == document.body;
  12729. }
  12730. function save() {textarea.value = cm.getValue();}
  12731. var realSubmit;
  12732. if (textarea.form) {
  12733. on(textarea.form, "submit", save);
  12734. // Deplorable hack to make the submit method do the right thing.
  12735. if (!options.leaveSubmitMethodAlone) {
  12736. var form = textarea.form;
  12737. realSubmit = form.submit;
  12738. try {
  12739. var wrappedSubmit = form.submit = function () {
  12740. save();
  12741. form.submit = realSubmit;
  12742. form.submit();
  12743. form.submit = wrappedSubmit;
  12744. };
  12745. } catch(e) {}
  12746. }
  12747. }
  12748. options.finishInit = function (cm) {
  12749. cm.save = save;
  12750. cm.getTextArea = function () { return textarea; };
  12751. cm.toTextArea = function () {
  12752. cm.toTextArea = isNaN; // Prevent this from being ran twice
  12753. save();
  12754. textarea.parentNode.removeChild(cm.getWrapperElement());
  12755. textarea.style.display = "";
  12756. if (textarea.form) {
  12757. off(textarea.form, "submit", save);
  12758. if (!options.leaveSubmitMethodAlone && typeof textarea.form.submit == "function")
  12759. { textarea.form.submit = realSubmit; }
  12760. }
  12761. };
  12762. };
  12763. textarea.style.display = "none";
  12764. var cm = CodeMirror(function (node) { return textarea.parentNode.insertBefore(node, textarea.nextSibling); },
  12765. options);
  12766. return cm
  12767. }
  12768. function addLegacyProps(CodeMirror) {
  12769. CodeMirror.off = off;
  12770. CodeMirror.on = on;
  12771. CodeMirror.wheelEventPixels = wheelEventPixels;
  12772. CodeMirror.Doc = Doc;
  12773. CodeMirror.splitLines = splitLinesAuto;
  12774. CodeMirror.countColumn = countColumn;
  12775. CodeMirror.findColumn = findColumn;
  12776. CodeMirror.isWordChar = isWordCharBasic;
  12777. CodeMirror.Pass = Pass;
  12778. CodeMirror.signal = signal;
  12779. CodeMirror.Line = Line;
  12780. CodeMirror.changeEnd = changeEnd;
  12781. CodeMirror.scrollbarModel = scrollbarModel;
  12782. CodeMirror.Pos = Pos;
  12783. CodeMirror.cmpPos = cmp;
  12784. CodeMirror.modes = modes;
  12785. CodeMirror.mimeModes = mimeModes;
  12786. CodeMirror.resolveMode = resolveMode;
  12787. CodeMirror.getMode = getMode;
  12788. CodeMirror.modeExtensions = modeExtensions;
  12789. CodeMirror.extendMode = extendMode;
  12790. CodeMirror.copyState = copyState;
  12791. CodeMirror.startState = startState;
  12792. CodeMirror.innerMode = innerMode;
  12793. CodeMirror.commands = commands;
  12794. CodeMirror.keyMap = keyMap;
  12795. CodeMirror.keyName = keyName;
  12796. CodeMirror.isModifierKey = isModifierKey;
  12797. CodeMirror.lookupKey = lookupKey;
  12798. CodeMirror.normalizeKeyMap = normalizeKeyMap;
  12799. CodeMirror.StringStream = StringStream;
  12800. CodeMirror.SharedTextMarker = SharedTextMarker;
  12801. CodeMirror.TextMarker = TextMarker;
  12802. CodeMirror.LineWidget = LineWidget;
  12803. CodeMirror.e_preventDefault = e_preventDefault;
  12804. CodeMirror.e_stopPropagation = e_stopPropagation;
  12805. CodeMirror.e_stop = e_stop;
  12806. CodeMirror.addClass = addClass;
  12807. CodeMirror.contains = contains;
  12808. CodeMirror.rmClass = rmClass;
  12809. CodeMirror.keyNames = keyNames;
  12810. }
  12811. // EDITOR CONSTRUCTOR
  12812. defineOptions(CodeMirror);
  12813. addEditorMethods(CodeMirror);
  12814. // Set up methods on CodeMirror's prototype to redirect to the editor's document.
  12815. var dontDelegate = "iter insert remove copy getEditor constructor".split(" ");
  12816. for (var prop in Doc.prototype) { if (Doc.prototype.hasOwnProperty(prop) && indexOf(dontDelegate, prop) < 0)
  12817. { CodeMirror.prototype[prop] = (function(method) {
  12818. return function() {return method.apply(this.doc, arguments)}
  12819. })(Doc.prototype[prop]); } }
  12820. eventMixin(Doc);
  12821. CodeMirror.inputStyles = {"textarea": TextareaInput, "contenteditable": ContentEditableInput};
  12822. // Extra arguments are stored as the mode's dependencies, which is
  12823. // used by (legacy) mechanisms like loadmode.js to automatically
  12824. // load a mode. (Preferred mechanism is the require/define calls.)
  12825. CodeMirror.defineMode = function(name/*, mode, …*/) {
  12826. if (!CodeMirror.defaults.mode && name != "null") { CodeMirror.defaults.mode = name; }
  12827. defineMode.apply(this, arguments);
  12828. };
  12829. CodeMirror.defineMIME = defineMIME;
  12830. // Minimal default mode.
  12831. CodeMirror.defineMode("null", function () { return ({token: function (stream) { return stream.skipToEnd(); }}); });
  12832. CodeMirror.defineMIME("text/plain", "null");
  12833. // EXTENSIONS
  12834. CodeMirror.defineExtension = function (name, func) {
  12835. CodeMirror.prototype[name] = func;
  12836. };
  12837. CodeMirror.defineDocExtension = function (name, func) {
  12838. Doc.prototype[name] = func;
  12839. };
  12840. CodeMirror.fromTextArea = fromTextArea;
  12841. addLegacyProps(CodeMirror);
  12842. CodeMirror.version = "5.49.2";
  12843. return CodeMirror;
  12844. })));
  12845. /***/ }),
  12846. /***/ "./node_modules/codemirror/mode/css/css.js":
  12847. /*!*************************************************!*\
  12848. !*** ./node_modules/codemirror/mode/css/css.js ***!
  12849. \*************************************************/
  12850. /*! no static exports found */
  12851. /***/ (function(module, exports, __webpack_require__) {
  12852. // CodeMirror, copyright (c) by Marijn Haverbeke and others
  12853. // Distributed under an MIT license: https://codemirror.net/LICENSE
  12854. (function(mod) {
  12855. if (true) // CommonJS
  12856. mod(__webpack_require__(/*! ../../lib/codemirror */ "./node_modules/codemirror/lib/codemirror.js"));
  12857. else {}
  12858. })(function(CodeMirror) {
  12859. "use strict";
  12860. CodeMirror.defineMode("css", function(config, parserConfig) {
  12861. var inline = parserConfig.inline
  12862. if (!parserConfig.propertyKeywords) parserConfig = CodeMirror.resolveMode("text/css");
  12863. var indentUnit = config.indentUnit,
  12864. tokenHooks = parserConfig.tokenHooks,
  12865. documentTypes = parserConfig.documentTypes || {},
  12866. mediaTypes = parserConfig.mediaTypes || {},
  12867. mediaFeatures = parserConfig.mediaFeatures || {},
  12868. mediaValueKeywords = parserConfig.mediaValueKeywords || {},
  12869. propertyKeywords = parserConfig.propertyKeywords || {},
  12870. nonStandardPropertyKeywords = parserConfig.nonStandardPropertyKeywords || {},
  12871. fontProperties = parserConfig.fontProperties || {},
  12872. counterDescriptors = parserConfig.counterDescriptors || {},
  12873. colorKeywords = parserConfig.colorKeywords || {},
  12874. valueKeywords = parserConfig.valueKeywords || {},
  12875. allowNested = parserConfig.allowNested,
  12876. lineComment = parserConfig.lineComment,
  12877. supportsAtComponent = parserConfig.supportsAtComponent === true;
  12878. var type, override;
  12879. function ret(style, tp) { type = tp; return style; }
  12880. // Tokenizers
  12881. function tokenBase(stream, state) {
  12882. var ch = stream.next();
  12883. if (tokenHooks[ch]) {
  12884. var result = tokenHooks[ch](stream, state);
  12885. if (result !== false) return result;
  12886. }
  12887. if (ch == "@") {
  12888. stream.eatWhile(/[\w\\\-]/);
  12889. return ret("def", stream.current());
  12890. } else if (ch == "=" || (ch == "~" || ch == "|") && stream.eat("=")) {
  12891. return ret(null, "compare");
  12892. } else if (ch == "\"" || ch == "'") {
  12893. state.tokenize = tokenString(ch);
  12894. return state.tokenize(stream, state);
  12895. } else if (ch == "#") {
  12896. stream.eatWhile(/[\w\\\-]/);
  12897. return ret("atom", "hash");
  12898. } else if (ch == "!") {
  12899. stream.match(/^\s*\w*/);
  12900. return ret("keyword", "important");
  12901. } else if (/\d/.test(ch) || ch == "." && stream.eat(/\d/)) {
  12902. stream.eatWhile(/[\w.%]/);
  12903. return ret("number", "unit");
  12904. } else if (ch === "-") {
  12905. if (/[\d.]/.test(stream.peek())) {
  12906. stream.eatWhile(/[\w.%]/);
  12907. return ret("number", "unit");
  12908. } else if (stream.match(/^-[\w\\\-]*/)) {
  12909. stream.eatWhile(/[\w\\\-]/);
  12910. if (stream.match(/^\s*:/, false))
  12911. return ret("variable-2", "variable-definition");
  12912. return ret("variable-2", "variable");
  12913. } else if (stream.match(/^\w+-/)) {
  12914. return ret("meta", "meta");
  12915. }
  12916. } else if (/[,+>*\/]/.test(ch)) {
  12917. return ret(null, "select-op");
  12918. } else if (ch == "." && stream.match(/^-?[_a-z][_a-z0-9-]*/i)) {
  12919. return ret("qualifier", "qualifier");
  12920. } else if (/[:;{}\[\]\(\)]/.test(ch)) {
  12921. return ret(null, ch);
  12922. } else if (stream.match(/[\w-.]+(?=\()/)) {
  12923. if (/^(url(-prefix)?|domain|regexp)$/.test(stream.current().toLowerCase())) {
  12924. state.tokenize = tokenParenthesized;
  12925. }
  12926. return ret("variable callee", "variable");
  12927. } else if (/[\w\\\-]/.test(ch)) {
  12928. stream.eatWhile(/[\w\\\-]/);
  12929. return ret("property", "word");
  12930. } else {
  12931. return ret(null, null);
  12932. }
  12933. }
  12934. function tokenString(quote) {
  12935. return function(stream, state) {
  12936. var escaped = false, ch;
  12937. while ((ch = stream.next()) != null) {
  12938. if (ch == quote && !escaped) {
  12939. if (quote == ")") stream.backUp(1);
  12940. break;
  12941. }
  12942. escaped = !escaped && ch == "\\";
  12943. }
  12944. if (ch == quote || !escaped && quote != ")") state.tokenize = null;
  12945. return ret("string", "string");
  12946. };
  12947. }
  12948. function tokenParenthesized(stream, state) {
  12949. stream.next(); // Must be '('
  12950. if (!stream.match(/\s*[\"\')]/, false))
  12951. state.tokenize = tokenString(")");
  12952. else
  12953. state.tokenize = null;
  12954. return ret(null, "(");
  12955. }
  12956. // Context management
  12957. function Context(type, indent, prev) {
  12958. this.type = type;
  12959. this.indent = indent;
  12960. this.prev = prev;
  12961. }
  12962. function pushContext(state, stream, type, indent) {
  12963. state.context = new Context(type, stream.indentation() + (indent === false ? 0 : indentUnit), state.context);
  12964. return type;
  12965. }
  12966. function popContext(state) {
  12967. if (state.context.prev)
  12968. state.context = state.context.prev;
  12969. return state.context.type;
  12970. }
  12971. function pass(type, stream, state) {
  12972. return states[state.context.type](type, stream, state);
  12973. }
  12974. function popAndPass(type, stream, state, n) {
  12975. for (var i = n || 1; i > 0; i--)
  12976. state.context = state.context.prev;
  12977. return pass(type, stream, state);
  12978. }
  12979. // Parser
  12980. function wordAsValue(stream) {
  12981. var word = stream.current().toLowerCase();
  12982. if (valueKeywords.hasOwnProperty(word))
  12983. override = "atom";
  12984. else if (colorKeywords.hasOwnProperty(word))
  12985. override = "keyword";
  12986. else
  12987. override = "variable";
  12988. }
  12989. var states = {};
  12990. states.top = function(type, stream, state) {
  12991. if (type == "{") {
  12992. return pushContext(state, stream, "block");
  12993. } else if (type == "}" && state.context.prev) {
  12994. return popContext(state);
  12995. } else if (supportsAtComponent && /@component/i.test(type)) {
  12996. return pushContext(state, stream, "atComponentBlock");
  12997. } else if (/^@(-moz-)?document$/i.test(type)) {
  12998. return pushContext(state, stream, "documentTypes");
  12999. } else if (/^@(media|supports|(-moz-)?document|import)$/i.test(type)) {
  13000. return pushContext(state, stream, "atBlock");
  13001. } else if (/^@(font-face|counter-style)/i.test(type)) {
  13002. state.stateArg = type;
  13003. return "restricted_atBlock_before";
  13004. } else if (/^@(-(moz|ms|o|webkit)-)?keyframes$/i.test(type)) {
  13005. return "keyframes";
  13006. } else if (type && type.charAt(0) == "@") {
  13007. return pushContext(state, stream, "at");
  13008. } else if (type == "hash") {
  13009. override = "builtin";
  13010. } else if (type == "word") {
  13011. override = "tag";
  13012. } else if (type == "variable-definition") {
  13013. return "maybeprop";
  13014. } else if (type == "interpolation") {
  13015. return pushContext(state, stream, "interpolation");
  13016. } else if (type == ":") {
  13017. return "pseudo";
  13018. } else if (allowNested && type == "(") {
  13019. return pushContext(state, stream, "parens");
  13020. }
  13021. return state.context.type;
  13022. };
  13023. states.block = function(type, stream, state) {
  13024. if (type == "word") {
  13025. var word = stream.current().toLowerCase();
  13026. if (propertyKeywords.hasOwnProperty(word)) {
  13027. override = "property";
  13028. return "maybeprop";
  13029. } else if (nonStandardPropertyKeywords.hasOwnProperty(word)) {
  13030. override = "string-2";
  13031. return "maybeprop";
  13032. } else if (allowNested) {
  13033. override = stream.match(/^\s*:(?:\s|$)/, false) ? "property" : "tag";
  13034. return "block";
  13035. } else {
  13036. override += " error";
  13037. return "maybeprop";
  13038. }
  13039. } else if (type == "meta") {
  13040. return "block";
  13041. } else if (!allowNested && (type == "hash" || type == "qualifier")) {
  13042. override = "error";
  13043. return "block";
  13044. } else {
  13045. return states.top(type, stream, state);
  13046. }
  13047. };
  13048. states.maybeprop = function(type, stream, state) {
  13049. if (type == ":") return pushContext(state, stream, "prop");
  13050. return pass(type, stream, state);
  13051. };
  13052. states.prop = function(type, stream, state) {
  13053. if (type == ";") return popContext(state);
  13054. if (type == "{" && allowNested) return pushContext(state, stream, "propBlock");
  13055. if (type == "}" || type == "{") return popAndPass(type, stream, state);
  13056. if (type == "(") return pushContext(state, stream, "parens");
  13057. if (type == "hash" && !/^#([0-9a-fA-f]{3,4}|[0-9a-fA-f]{6}|[0-9a-fA-f]{8})$/.test(stream.current())) {
  13058. override += " error";
  13059. } else if (type == "word") {
  13060. wordAsValue(stream);
  13061. } else if (type == "interpolation") {
  13062. return pushContext(state, stream, "interpolation");
  13063. }
  13064. return "prop";
  13065. };
  13066. states.propBlock = function(type, _stream, state) {
  13067. if (type == "}") return popContext(state);
  13068. if (type == "word") { override = "property"; return "maybeprop"; }
  13069. return state.context.type;
  13070. };
  13071. states.parens = function(type, stream, state) {
  13072. if (type == "{" || type == "}") return popAndPass(type, stream, state);
  13073. if (type == ")") return popContext(state);
  13074. if (type == "(") return pushContext(state, stream, "parens");
  13075. if (type == "interpolation") return pushContext(state, stream, "interpolation");
  13076. if (type == "word") wordAsValue(stream);
  13077. return "parens";
  13078. };
  13079. states.pseudo = function(type, stream, state) {
  13080. if (type == "meta") return "pseudo";
  13081. if (type == "word") {
  13082. override = "variable-3";
  13083. return state.context.type;
  13084. }
  13085. return pass(type, stream, state);
  13086. };
  13087. states.documentTypes = function(type, stream, state) {
  13088. if (type == "word" && documentTypes.hasOwnProperty(stream.current())) {
  13089. override = "tag";
  13090. return state.context.type;
  13091. } else {
  13092. return states.atBlock(type, stream, state);
  13093. }
  13094. };
  13095. states.atBlock = function(type, stream, state) {
  13096. if (type == "(") return pushContext(state, stream, "atBlock_parens");
  13097. if (type == "}" || type == ";") return popAndPass(type, stream, state);
  13098. if (type == "{") return popContext(state) && pushContext(state, stream, allowNested ? "block" : "top");
  13099. if (type == "interpolation") return pushContext(state, stream, "interpolation");
  13100. if (type == "word") {
  13101. var word = stream.current().toLowerCase();
  13102. if (word == "only" || word == "not" || word == "and" || word == "or")
  13103. override = "keyword";
  13104. else if (mediaTypes.hasOwnProperty(word))
  13105. override = "attribute";
  13106. else if (mediaFeatures.hasOwnProperty(word))
  13107. override = "property";
  13108. else if (mediaValueKeywords.hasOwnProperty(word))
  13109. override = "keyword";
  13110. else if (propertyKeywords.hasOwnProperty(word))
  13111. override = "property";
  13112. else if (nonStandardPropertyKeywords.hasOwnProperty(word))
  13113. override = "string-2";
  13114. else if (valueKeywords.hasOwnProperty(word))
  13115. override = "atom";
  13116. else if (colorKeywords.hasOwnProperty(word))
  13117. override = "keyword";
  13118. else
  13119. override = "error";
  13120. }
  13121. return state.context.type;
  13122. };
  13123. states.atComponentBlock = function(type, stream, state) {
  13124. if (type == "}")
  13125. return popAndPass(type, stream, state);
  13126. if (type == "{")
  13127. return popContext(state) && pushContext(state, stream, allowNested ? "block" : "top", false);
  13128. if (type == "word")
  13129. override = "error";
  13130. return state.context.type;
  13131. };
  13132. states.atBlock_parens = function(type, stream, state) {
  13133. if (type == ")") return popContext(state);
  13134. if (type == "{" || type == "}") return popAndPass(type, stream, state, 2);
  13135. return states.atBlock(type, stream, state);
  13136. };
  13137. states.restricted_atBlock_before = function(type, stream, state) {
  13138. if (type == "{")
  13139. return pushContext(state, stream, "restricted_atBlock");
  13140. if (type == "word" && state.stateArg == "@counter-style") {
  13141. override = "variable";
  13142. return "restricted_atBlock_before";
  13143. }
  13144. return pass(type, stream, state);
  13145. };
  13146. states.restricted_atBlock = function(type, stream, state) {
  13147. if (type == "}") {
  13148. state.stateArg = null;
  13149. return popContext(state);
  13150. }
  13151. if (type == "word") {
  13152. if ((state.stateArg == "@font-face" && !fontProperties.hasOwnProperty(stream.current().toLowerCase())) ||
  13153. (state.stateArg == "@counter-style" && !counterDescriptors.hasOwnProperty(stream.current().toLowerCase())))
  13154. override = "error";
  13155. else
  13156. override = "property";
  13157. return "maybeprop";
  13158. }
  13159. return "restricted_atBlock";
  13160. };
  13161. states.keyframes = function(type, stream, state) {
  13162. if (type == "word") { override = "variable"; return "keyframes"; }
  13163. if (type == "{") return pushContext(state, stream, "top");
  13164. return pass(type, stream, state);
  13165. };
  13166. states.at = function(type, stream, state) {
  13167. if (type == ";") return popContext(state);
  13168. if (type == "{" || type == "}") return popAndPass(type, stream, state);
  13169. if (type == "word") override = "tag";
  13170. else if (type == "hash") override = "builtin";
  13171. return "at";
  13172. };
  13173. states.interpolation = function(type, stream, state) {
  13174. if (type == "}") return popContext(state);
  13175. if (type == "{" || type == ";") return popAndPass(type, stream, state);
  13176. if (type == "word") override = "variable";
  13177. else if (type != "variable" && type != "(" && type != ")") override = "error";
  13178. return "interpolation";
  13179. };
  13180. return {
  13181. startState: function(base) {
  13182. return {tokenize: null,
  13183. state: inline ? "block" : "top",
  13184. stateArg: null,
  13185. context: new Context(inline ? "block" : "top", base || 0, null)};
  13186. },
  13187. token: function(stream, state) {
  13188. if (!state.tokenize && stream.eatSpace()) return null;
  13189. var style = (state.tokenize || tokenBase)(stream, state);
  13190. if (style && typeof style == "object") {
  13191. type = style[1];
  13192. style = style[0];
  13193. }
  13194. override = style;
  13195. if (type != "comment")
  13196. state.state = states[state.state](type, stream, state);
  13197. return override;
  13198. },
  13199. indent: function(state, textAfter) {
  13200. var cx = state.context, ch = textAfter && textAfter.charAt(0);
  13201. var indent = cx.indent;
  13202. if (cx.type == "prop" && (ch == "}" || ch == ")")) cx = cx.prev;
  13203. if (cx.prev) {
  13204. if (ch == "}" && (cx.type == "block" || cx.type == "top" ||
  13205. cx.type == "interpolation" || cx.type == "restricted_atBlock")) {
  13206. // Resume indentation from parent context.
  13207. cx = cx.prev;
  13208. indent = cx.indent;
  13209. } else if (ch == ")" && (cx.type == "parens" || cx.type == "atBlock_parens") ||
  13210. ch == "{" && (cx.type == "at" || cx.type == "atBlock")) {
  13211. // Dedent relative to current context.
  13212. indent = Math.max(0, cx.indent - indentUnit);
  13213. }
  13214. }
  13215. return indent;
  13216. },
  13217. electricChars: "}",
  13218. blockCommentStart: "/*",
  13219. blockCommentEnd: "*/",
  13220. blockCommentContinue: " * ",
  13221. lineComment: lineComment,
  13222. fold: "brace"
  13223. };
  13224. });
  13225. function keySet(array) {
  13226. var keys = {};
  13227. for (var i = 0; i < array.length; ++i) {
  13228. keys[array[i].toLowerCase()] = true;
  13229. }
  13230. return keys;
  13231. }
  13232. var documentTypes_ = [
  13233. "domain", "regexp", "url", "url-prefix"
  13234. ], documentTypes = keySet(documentTypes_);
  13235. var mediaTypes_ = [
  13236. "all", "aural", "braille", "handheld", "print", "projection", "screen",
  13237. "tty", "tv", "embossed"
  13238. ], mediaTypes = keySet(mediaTypes_);
  13239. var mediaFeatures_ = [
  13240. "width", "min-width", "max-width", "height", "min-height", "max-height",
  13241. "device-width", "min-device-width", "max-device-width", "device-height",
  13242. "min-device-height", "max-device-height", "aspect-ratio",
  13243. "min-aspect-ratio", "max-aspect-ratio", "device-aspect-ratio",
  13244. "min-device-aspect-ratio", "max-device-aspect-ratio", "color", "min-color",
  13245. "max-color", "color-index", "min-color-index", "max-color-index",
  13246. "monochrome", "min-monochrome", "max-monochrome", "resolution",
  13247. "min-resolution", "max-resolution", "scan", "grid", "orientation",
  13248. "device-pixel-ratio", "min-device-pixel-ratio", "max-device-pixel-ratio",
  13249. "pointer", "any-pointer", "hover", "any-hover"
  13250. ], mediaFeatures = keySet(mediaFeatures_);
  13251. var mediaValueKeywords_ = [
  13252. "landscape", "portrait", "none", "coarse", "fine", "on-demand", "hover",
  13253. "interlace", "progressive"
  13254. ], mediaValueKeywords = keySet(mediaValueKeywords_);
  13255. var propertyKeywords_ = [
  13256. "align-content", "align-items", "align-self", "alignment-adjust",
  13257. "alignment-baseline", "anchor-point", "animation", "animation-delay",
  13258. "animation-direction", "animation-duration", "animation-fill-mode",
  13259. "animation-iteration-count", "animation-name", "animation-play-state",
  13260. "animation-timing-function", "appearance", "azimuth", "backface-visibility",
  13261. "background", "background-attachment", "background-blend-mode", "background-clip",
  13262. "background-color", "background-image", "background-origin", "background-position",
  13263. "background-repeat", "background-size", "baseline-shift", "binding",
  13264. "bleed", "bookmark-label", "bookmark-level", "bookmark-state",
  13265. "bookmark-target", "border", "border-bottom", "border-bottom-color",
  13266. "border-bottom-left-radius", "border-bottom-right-radius",
  13267. "border-bottom-style", "border-bottom-width", "border-collapse",
  13268. "border-color", "border-image", "border-image-outset",
  13269. "border-image-repeat", "border-image-slice", "border-image-source",
  13270. "border-image-width", "border-left", "border-left-color",
  13271. "border-left-style", "border-left-width", "border-radius", "border-right",
  13272. "border-right-color", "border-right-style", "border-right-width",
  13273. "border-spacing", "border-style", "border-top", "border-top-color",
  13274. "border-top-left-radius", "border-top-right-radius", "border-top-style",
  13275. "border-top-width", "border-width", "bottom", "box-decoration-break",
  13276. "box-shadow", "box-sizing", "break-after", "break-before", "break-inside",
  13277. "caption-side", "caret-color", "clear", "clip", "color", "color-profile", "column-count",
  13278. "column-fill", "column-gap", "column-rule", "column-rule-color",
  13279. "column-rule-style", "column-rule-width", "column-span", "column-width",
  13280. "columns", "content", "counter-increment", "counter-reset", "crop", "cue",
  13281. "cue-after", "cue-before", "cursor", "direction", "display",
  13282. "dominant-baseline", "drop-initial-after-adjust",
  13283. "drop-initial-after-align", "drop-initial-before-adjust",
  13284. "drop-initial-before-align", "drop-initial-size", "drop-initial-value",
  13285. "elevation", "empty-cells", "fit", "fit-position", "flex", "flex-basis",
  13286. "flex-direction", "flex-flow", "flex-grow", "flex-shrink", "flex-wrap",
  13287. "float", "float-offset", "flow-from", "flow-into", "font", "font-feature-settings",
  13288. "font-family", "font-kerning", "font-language-override", "font-size", "font-size-adjust",
  13289. "font-stretch", "font-style", "font-synthesis", "font-variant",
  13290. "font-variant-alternates", "font-variant-caps", "font-variant-east-asian",
  13291. "font-variant-ligatures", "font-variant-numeric", "font-variant-position",
  13292. "font-weight", "grid", "grid-area", "grid-auto-columns", "grid-auto-flow",
  13293. "grid-auto-rows", "grid-column", "grid-column-end", "grid-column-gap",
  13294. "grid-column-start", "grid-gap", "grid-row", "grid-row-end", "grid-row-gap",
  13295. "grid-row-start", "grid-template", "grid-template-areas", "grid-template-columns",
  13296. "grid-template-rows", "hanging-punctuation", "height", "hyphens",
  13297. "icon", "image-orientation", "image-rendering", "image-resolution",
  13298. "inline-box-align", "justify-content", "justify-items", "justify-self", "left", "letter-spacing",
  13299. "line-break", "line-height", "line-stacking", "line-stacking-ruby",
  13300. "line-stacking-shift", "line-stacking-strategy", "list-style",
  13301. "list-style-image", "list-style-position", "list-style-type", "margin",
  13302. "margin-bottom", "margin-left", "margin-right", "margin-top",
  13303. "marks", "marquee-direction", "marquee-loop",
  13304. "marquee-play-count", "marquee-speed", "marquee-style", "max-height",
  13305. "max-width", "min-height", "min-width", "mix-blend-mode", "move-to", "nav-down", "nav-index",
  13306. "nav-left", "nav-right", "nav-up", "object-fit", "object-position",
  13307. "opacity", "order", "orphans", "outline",
  13308. "outline-color", "outline-offset", "outline-style", "outline-width",
  13309. "overflow", "overflow-style", "overflow-wrap", "overflow-x", "overflow-y",
  13310. "padding", "padding-bottom", "padding-left", "padding-right", "padding-top",
  13311. "page", "page-break-after", "page-break-before", "page-break-inside",
  13312. "page-policy", "pause", "pause-after", "pause-before", "perspective",
  13313. "perspective-origin", "pitch", "pitch-range", "place-content", "place-items", "place-self", "play-during", "position",
  13314. "presentation-level", "punctuation-trim", "quotes", "region-break-after",
  13315. "region-break-before", "region-break-inside", "region-fragment",
  13316. "rendering-intent", "resize", "rest", "rest-after", "rest-before", "richness",
  13317. "right", "rotation", "rotation-point", "ruby-align", "ruby-overhang",
  13318. "ruby-position", "ruby-span", "shape-image-threshold", "shape-inside", "shape-margin",
  13319. "shape-outside", "size", "speak", "speak-as", "speak-header",
  13320. "speak-numeral", "speak-punctuation", "speech-rate", "stress", "string-set",
  13321. "tab-size", "table-layout", "target", "target-name", "target-new",
  13322. "target-position", "text-align", "text-align-last", "text-decoration",
  13323. "text-decoration-color", "text-decoration-line", "text-decoration-skip",
  13324. "text-decoration-style", "text-emphasis", "text-emphasis-color",
  13325. "text-emphasis-position", "text-emphasis-style", "text-height",
  13326. "text-indent", "text-justify", "text-outline", "text-overflow", "text-shadow",
  13327. "text-size-adjust", "text-space-collapse", "text-transform", "text-underline-position",
  13328. "text-wrap", "top", "transform", "transform-origin", "transform-style",
  13329. "transition", "transition-delay", "transition-duration",
  13330. "transition-property", "transition-timing-function", "unicode-bidi",
  13331. "user-select", "vertical-align", "visibility", "voice-balance", "voice-duration",
  13332. "voice-family", "voice-pitch", "voice-range", "voice-rate", "voice-stress",
  13333. "voice-volume", "volume", "white-space", "widows", "width", "will-change", "word-break",
  13334. "word-spacing", "word-wrap", "z-index",
  13335. // SVG-specific
  13336. "clip-path", "clip-rule", "mask", "enable-background", "filter", "flood-color",
  13337. "flood-opacity", "lighting-color", "stop-color", "stop-opacity", "pointer-events",
  13338. "color-interpolation", "color-interpolation-filters",
  13339. "color-rendering", "fill", "fill-opacity", "fill-rule", "image-rendering",
  13340. "marker", "marker-end", "marker-mid", "marker-start", "shape-rendering", "stroke",
  13341. "stroke-dasharray", "stroke-dashoffset", "stroke-linecap", "stroke-linejoin",
  13342. "stroke-miterlimit", "stroke-opacity", "stroke-width", "text-rendering",
  13343. "baseline-shift", "dominant-baseline", "glyph-orientation-horizontal",
  13344. "glyph-orientation-vertical", "text-anchor", "writing-mode"
  13345. ], propertyKeywords = keySet(propertyKeywords_);
  13346. var nonStandardPropertyKeywords_ = [
  13347. "scrollbar-arrow-color", "scrollbar-base-color", "scrollbar-dark-shadow-color",
  13348. "scrollbar-face-color", "scrollbar-highlight-color", "scrollbar-shadow-color",
  13349. "scrollbar-3d-light-color", "scrollbar-track-color", "shape-inside",
  13350. "searchfield-cancel-button", "searchfield-decoration", "searchfield-results-button",
  13351. "searchfield-results-decoration", "zoom"
  13352. ], nonStandardPropertyKeywords = keySet(nonStandardPropertyKeywords_);
  13353. var fontProperties_ = [
  13354. "font-family", "src", "unicode-range", "font-variant", "font-feature-settings",
  13355. "font-stretch", "font-weight", "font-style"
  13356. ], fontProperties = keySet(fontProperties_);
  13357. var counterDescriptors_ = [
  13358. "additive-symbols", "fallback", "negative", "pad", "prefix", "range",
  13359. "speak-as", "suffix", "symbols", "system"
  13360. ], counterDescriptors = keySet(counterDescriptors_);
  13361. var colorKeywords_ = [
  13362. "aliceblue", "antiquewhite", "aqua", "aquamarine", "azure", "beige",
  13363. "bisque", "black", "blanchedalmond", "blue", "blueviolet", "brown",
  13364. "burlywood", "cadetblue", "chartreuse", "chocolate", "coral", "cornflowerblue",
  13365. "cornsilk", "crimson", "cyan", "darkblue", "darkcyan", "darkgoldenrod",
  13366. "darkgray", "darkgreen", "darkkhaki", "darkmagenta", "darkolivegreen",
  13367. "darkorange", "darkorchid", "darkred", "darksalmon", "darkseagreen",
  13368. "darkslateblue", "darkslategray", "darkturquoise", "darkviolet",
  13369. "deeppink", "deepskyblue", "dimgray", "dodgerblue", "firebrick",
  13370. "floralwhite", "forestgreen", "fuchsia", "gainsboro", "ghostwhite",
  13371. "gold", "goldenrod", "gray", "grey", "green", "greenyellow", "honeydew",
  13372. "hotpink", "indianred", "indigo", "ivory", "khaki", "lavender",
  13373. "lavenderblush", "lawngreen", "lemonchiffon", "lightblue", "lightcoral",
  13374. "lightcyan", "lightgoldenrodyellow", "lightgray", "lightgreen", "lightpink",
  13375. "lightsalmon", "lightseagreen", "lightskyblue", "lightslategray",
  13376. "lightsteelblue", "lightyellow", "lime", "limegreen", "linen", "magenta",
  13377. "maroon", "mediumaquamarine", "mediumblue", "mediumorchid", "mediumpurple",
  13378. "mediumseagreen", "mediumslateblue", "mediumspringgreen", "mediumturquoise",
  13379. "mediumvioletred", "midnightblue", "mintcream", "mistyrose", "moccasin",
  13380. "navajowhite", "navy", "oldlace", "olive", "olivedrab", "orange", "orangered",
  13381. "orchid", "palegoldenrod", "palegreen", "paleturquoise", "palevioletred",
  13382. "papayawhip", "peachpuff", "peru", "pink", "plum", "powderblue",
  13383. "purple", "rebeccapurple", "red", "rosybrown", "royalblue", "saddlebrown",
  13384. "salmon", "sandybrown", "seagreen", "seashell", "sienna", "silver", "skyblue",
  13385. "slateblue", "slategray", "snow", "springgreen", "steelblue", "tan",
  13386. "teal", "thistle", "tomato", "turquoise", "violet", "wheat", "white",
  13387. "whitesmoke", "yellow", "yellowgreen"
  13388. ], colorKeywords = keySet(colorKeywords_);
  13389. var valueKeywords_ = [
  13390. "above", "absolute", "activeborder", "additive", "activecaption", "afar",
  13391. "after-white-space", "ahead", "alias", "all", "all-scroll", "alphabetic", "alternate",
  13392. "always", "amharic", "amharic-abegede", "antialiased", "appworkspace",
  13393. "arabic-indic", "armenian", "asterisks", "attr", "auto", "auto-flow", "avoid", "avoid-column", "avoid-page",
  13394. "avoid-region", "background", "backwards", "baseline", "below", "bidi-override", "binary",
  13395. "bengali", "blink", "block", "block-axis", "bold", "bolder", "border", "border-box",
  13396. "both", "bottom", "break", "break-all", "break-word", "bullets", "button", "button-bevel",
  13397. "buttonface", "buttonhighlight", "buttonshadow", "buttontext", "calc", "cambodian",
  13398. "capitalize", "caps-lock-indicator", "caption", "captiontext", "caret",
  13399. "cell", "center", "checkbox", "circle", "cjk-decimal", "cjk-earthly-branch",
  13400. "cjk-heavenly-stem", "cjk-ideographic", "clear", "clip", "close-quote",
  13401. "col-resize", "collapse", "color", "color-burn", "color-dodge", "column", "column-reverse",
  13402. "compact", "condensed", "contain", "content", "contents",
  13403. "content-box", "context-menu", "continuous", "copy", "counter", "counters", "cover", "crop",
  13404. "cross", "crosshair", "currentcolor", "cursive", "cyclic", "darken", "dashed", "decimal",
  13405. "decimal-leading-zero", "default", "default-button", "dense", "destination-atop",
  13406. "destination-in", "destination-out", "destination-over", "devanagari", "difference",
  13407. "disc", "discard", "disclosure-closed", "disclosure-open", "document",
  13408. "dot-dash", "dot-dot-dash",
  13409. "dotted", "double", "down", "e-resize", "ease", "ease-in", "ease-in-out", "ease-out",
  13410. "element", "ellipse", "ellipsis", "embed", "end", "ethiopic", "ethiopic-abegede",
  13411. "ethiopic-abegede-am-et", "ethiopic-abegede-gez", "ethiopic-abegede-ti-er",
  13412. "ethiopic-abegede-ti-et", "ethiopic-halehame-aa-er",
  13413. "ethiopic-halehame-aa-et", "ethiopic-halehame-am-et",
  13414. "ethiopic-halehame-gez", "ethiopic-halehame-om-et",
  13415. "ethiopic-halehame-sid-et", "ethiopic-halehame-so-et",
  13416. "ethiopic-halehame-ti-er", "ethiopic-halehame-ti-et", "ethiopic-halehame-tig",
  13417. "ethiopic-numeric", "ew-resize", "exclusion", "expanded", "extends", "extra-condensed",
  13418. "extra-expanded", "fantasy", "fast", "fill", "fixed", "flat", "flex", "flex-end", "flex-start", "footnotes",
  13419. "forwards", "from", "geometricPrecision", "georgian", "graytext", "grid", "groove",
  13420. "gujarati", "gurmukhi", "hand", "hangul", "hangul-consonant", "hard-light", "hebrew",
  13421. "help", "hidden", "hide", "higher", "highlight", "highlighttext",
  13422. "hiragana", "hiragana-iroha", "horizontal", "hsl", "hsla", "hue", "icon", "ignore",
  13423. "inactiveborder", "inactivecaption", "inactivecaptiontext", "infinite",
  13424. "infobackground", "infotext", "inherit", "initial", "inline", "inline-axis",
  13425. "inline-block", "inline-flex", "inline-grid", "inline-table", "inset", "inside", "intrinsic", "invert",
  13426. "italic", "japanese-formal", "japanese-informal", "justify", "kannada",
  13427. "katakana", "katakana-iroha", "keep-all", "khmer",
  13428. "korean-hangul-formal", "korean-hanja-formal", "korean-hanja-informal",
  13429. "landscape", "lao", "large", "larger", "left", "level", "lighter", "lighten",
  13430. "line-through", "linear", "linear-gradient", "lines", "list-item", "listbox", "listitem",
  13431. "local", "logical", "loud", "lower", "lower-alpha", "lower-armenian",
  13432. "lower-greek", "lower-hexadecimal", "lower-latin", "lower-norwegian",
  13433. "lower-roman", "lowercase", "ltr", "luminosity", "malayalam", "match", "matrix", "matrix3d",
  13434. "media-controls-background", "media-current-time-display",
  13435. "media-fullscreen-button", "media-mute-button", "media-play-button",
  13436. "media-return-to-realtime-button", "media-rewind-button",
  13437. "media-seek-back-button", "media-seek-forward-button", "media-slider",
  13438. "media-sliderthumb", "media-time-remaining-display", "media-volume-slider",
  13439. "media-volume-slider-container", "media-volume-sliderthumb", "medium",
  13440. "menu", "menulist", "menulist-button", "menulist-text",
  13441. "menulist-textfield", "menutext", "message-box", "middle", "min-intrinsic",
  13442. "mix", "mongolian", "monospace", "move", "multiple", "multiply", "myanmar", "n-resize",
  13443. "narrower", "ne-resize", "nesw-resize", "no-close-quote", "no-drop",
  13444. "no-open-quote", "no-repeat", "none", "normal", "not-allowed", "nowrap",
  13445. "ns-resize", "numbers", "numeric", "nw-resize", "nwse-resize", "oblique", "octal", "opacity", "open-quote",
  13446. "optimizeLegibility", "optimizeSpeed", "oriya", "oromo", "outset",
  13447. "outside", "outside-shape", "overlay", "overline", "padding", "padding-box",
  13448. "painted", "page", "paused", "persian", "perspective", "plus-darker", "plus-lighter",
  13449. "pointer", "polygon", "portrait", "pre", "pre-line", "pre-wrap", "preserve-3d",
  13450. "progress", "push-button", "radial-gradient", "radio", "read-only",
  13451. "read-write", "read-write-plaintext-only", "rectangle", "region",
  13452. "relative", "repeat", "repeating-linear-gradient",
  13453. "repeating-radial-gradient", "repeat-x", "repeat-y", "reset", "reverse",
  13454. "rgb", "rgba", "ridge", "right", "rotate", "rotate3d", "rotateX", "rotateY",
  13455. "rotateZ", "round", "row", "row-resize", "row-reverse", "rtl", "run-in", "running",
  13456. "s-resize", "sans-serif", "saturation", "scale", "scale3d", "scaleX", "scaleY", "scaleZ", "screen",
  13457. "scroll", "scrollbar", "scroll-position", "se-resize", "searchfield",
  13458. "searchfield-cancel-button", "searchfield-decoration",
  13459. "searchfield-results-button", "searchfield-results-decoration", "self-start", "self-end",
  13460. "semi-condensed", "semi-expanded", "separate", "serif", "show", "sidama",
  13461. "simp-chinese-formal", "simp-chinese-informal", "single",
  13462. "skew", "skewX", "skewY", "skip-white-space", "slide", "slider-horizontal",
  13463. "slider-vertical", "sliderthumb-horizontal", "sliderthumb-vertical", "slow",
  13464. "small", "small-caps", "small-caption", "smaller", "soft-light", "solid", "somali",
  13465. "source-atop", "source-in", "source-out", "source-over", "space", "space-around", "space-between", "space-evenly", "spell-out", "square",
  13466. "square-button", "start", "static", "status-bar", "stretch", "stroke", "sub",
  13467. "subpixel-antialiased", "super", "sw-resize", "symbolic", "symbols", "system-ui", "table",
  13468. "table-caption", "table-cell", "table-column", "table-column-group",
  13469. "table-footer-group", "table-header-group", "table-row", "table-row-group",
  13470. "tamil",
  13471. "telugu", "text", "text-bottom", "text-top", "textarea", "textfield", "thai",
  13472. "thick", "thin", "threeddarkshadow", "threedface", "threedhighlight",
  13473. "threedlightshadow", "threedshadow", "tibetan", "tigre", "tigrinya-er",
  13474. "tigrinya-er-abegede", "tigrinya-et", "tigrinya-et-abegede", "to", "top",
  13475. "trad-chinese-formal", "trad-chinese-informal", "transform",
  13476. "translate", "translate3d", "translateX", "translateY", "translateZ",
  13477. "transparent", "ultra-condensed", "ultra-expanded", "underline", "unset", "up",
  13478. "upper-alpha", "upper-armenian", "upper-greek", "upper-hexadecimal",
  13479. "upper-latin", "upper-norwegian", "upper-roman", "uppercase", "urdu", "url",
  13480. "var", "vertical", "vertical-text", "visible", "visibleFill", "visiblePainted",
  13481. "visibleStroke", "visual", "w-resize", "wait", "wave", "wider",
  13482. "window", "windowframe", "windowtext", "words", "wrap", "wrap-reverse", "x-large", "x-small", "xor",
  13483. "xx-large", "xx-small"
  13484. ], valueKeywords = keySet(valueKeywords_);
  13485. var allWords = documentTypes_.concat(mediaTypes_).concat(mediaFeatures_).concat(mediaValueKeywords_)
  13486. .concat(propertyKeywords_).concat(nonStandardPropertyKeywords_).concat(colorKeywords_)
  13487. .concat(valueKeywords_);
  13488. CodeMirror.registerHelper("hintWords", "css", allWords);
  13489. function tokenCComment(stream, state) {
  13490. var maybeEnd = false, ch;
  13491. while ((ch = stream.next()) != null) {
  13492. if (maybeEnd && ch == "/") {
  13493. state.tokenize = null;
  13494. break;
  13495. }
  13496. maybeEnd = (ch == "*");
  13497. }
  13498. return ["comment", "comment"];
  13499. }
  13500. CodeMirror.defineMIME("text/css", {
  13501. documentTypes: documentTypes,
  13502. mediaTypes: mediaTypes,
  13503. mediaFeatures: mediaFeatures,
  13504. mediaValueKeywords: mediaValueKeywords,
  13505. propertyKeywords: propertyKeywords,
  13506. nonStandardPropertyKeywords: nonStandardPropertyKeywords,
  13507. fontProperties: fontProperties,
  13508. counterDescriptors: counterDescriptors,
  13509. colorKeywords: colorKeywords,
  13510. valueKeywords: valueKeywords,
  13511. tokenHooks: {
  13512. "/": function(stream, state) {
  13513. if (!stream.eat("*")) return false;
  13514. state.tokenize = tokenCComment;
  13515. return tokenCComment(stream, state);
  13516. }
  13517. },
  13518. name: "css"
  13519. });
  13520. CodeMirror.defineMIME("text/x-scss", {
  13521. mediaTypes: mediaTypes,
  13522. mediaFeatures: mediaFeatures,
  13523. mediaValueKeywords: mediaValueKeywords,
  13524. propertyKeywords: propertyKeywords,
  13525. nonStandardPropertyKeywords: nonStandardPropertyKeywords,
  13526. colorKeywords: colorKeywords,
  13527. valueKeywords: valueKeywords,
  13528. fontProperties: fontProperties,
  13529. allowNested: true,
  13530. lineComment: "//",
  13531. tokenHooks: {
  13532. "/": function(stream, state) {
  13533. if (stream.eat("/")) {
  13534. stream.skipToEnd();
  13535. return ["comment", "comment"];
  13536. } else if (stream.eat("*")) {
  13537. state.tokenize = tokenCComment;
  13538. return tokenCComment(stream, state);
  13539. } else {
  13540. return ["operator", "operator"];
  13541. }
  13542. },
  13543. ":": function(stream) {
  13544. if (stream.match(/\s*\{/, false))
  13545. return [null, null]
  13546. return false;
  13547. },
  13548. "$": function(stream) {
  13549. stream.match(/^[\w-]+/);
  13550. if (stream.match(/^\s*:/, false))
  13551. return ["variable-2", "variable-definition"];
  13552. return ["variable-2", "variable"];
  13553. },
  13554. "#": function(stream) {
  13555. if (!stream.eat("{")) return false;
  13556. return [null, "interpolation"];
  13557. }
  13558. },
  13559. name: "css",
  13560. helperType: "scss"
  13561. });
  13562. CodeMirror.defineMIME("text/x-less", {
  13563. mediaTypes: mediaTypes,
  13564. mediaFeatures: mediaFeatures,
  13565. mediaValueKeywords: mediaValueKeywords,
  13566. propertyKeywords: propertyKeywords,
  13567. nonStandardPropertyKeywords: nonStandardPropertyKeywords,
  13568. colorKeywords: colorKeywords,
  13569. valueKeywords: valueKeywords,
  13570. fontProperties: fontProperties,
  13571. allowNested: true,
  13572. lineComment: "//",
  13573. tokenHooks: {
  13574. "/": function(stream, state) {
  13575. if (stream.eat("/")) {
  13576. stream.skipToEnd();
  13577. return ["comment", "comment"];
  13578. } else if (stream.eat("*")) {
  13579. state.tokenize = tokenCComment;
  13580. return tokenCComment(stream, state);
  13581. } else {
  13582. return ["operator", "operator"];
  13583. }
  13584. },
  13585. "@": function(stream) {
  13586. if (stream.eat("{")) return [null, "interpolation"];
  13587. if (stream.match(/^(charset|document|font-face|import|(-(moz|ms|o|webkit)-)?keyframes|media|namespace|page|supports)\b/i, false)) return false;
  13588. stream.eatWhile(/[\w\\\-]/);
  13589. if (stream.match(/^\s*:/, false))
  13590. return ["variable-2", "variable-definition"];
  13591. return ["variable-2", "variable"];
  13592. },
  13593. "&": function() {
  13594. return ["atom", "atom"];
  13595. }
  13596. },
  13597. name: "css",
  13598. helperType: "less"
  13599. });
  13600. CodeMirror.defineMIME("text/x-gss", {
  13601. documentTypes: documentTypes,
  13602. mediaTypes: mediaTypes,
  13603. mediaFeatures: mediaFeatures,
  13604. propertyKeywords: propertyKeywords,
  13605. nonStandardPropertyKeywords: nonStandardPropertyKeywords,
  13606. fontProperties: fontProperties,
  13607. counterDescriptors: counterDescriptors,
  13608. colorKeywords: colorKeywords,
  13609. valueKeywords: valueKeywords,
  13610. supportsAtComponent: true,
  13611. tokenHooks: {
  13612. "/": function(stream, state) {
  13613. if (!stream.eat("*")) return false;
  13614. state.tokenize = tokenCComment;
  13615. return tokenCComment(stream, state);
  13616. }
  13617. },
  13618. name: "css",
  13619. helperType: "gss"
  13620. });
  13621. });
  13622. /***/ }),
  13623. /***/ "./node_modules/codemirror/mode/htmlmixed/htmlmixed.js":
  13624. /*!*************************************************************!*\
  13625. !*** ./node_modules/codemirror/mode/htmlmixed/htmlmixed.js ***!
  13626. \*************************************************************/
  13627. /*! no static exports found */
  13628. /***/ (function(module, exports, __webpack_require__) {
  13629. // CodeMirror, copyright (c) by Marijn Haverbeke and others
  13630. // Distributed under an MIT license: https://codemirror.net/LICENSE
  13631. (function(mod) {
  13632. if (true) // CommonJS
  13633. mod(__webpack_require__(/*! ../../lib/codemirror */ "./node_modules/codemirror/lib/codemirror.js"), __webpack_require__(/*! ../xml/xml */ "./node_modules/codemirror/mode/xml/xml.js"), __webpack_require__(/*! ../javascript/javascript */ "./node_modules/codemirror/mode/javascript/javascript.js"), __webpack_require__(/*! ../css/css */ "./node_modules/codemirror/mode/css/css.js"));
  13634. else {}
  13635. })(function(CodeMirror) {
  13636. "use strict";
  13637. var defaultTags = {
  13638. script: [
  13639. ["lang", /(javascript|babel)/i, "javascript"],
  13640. ["type", /^(?:text|application)\/(?:x-)?(?:java|ecma)script$|^module$|^$/i, "javascript"],
  13641. ["type", /./, "text/plain"],
  13642. [null, null, "javascript"]
  13643. ],
  13644. style: [
  13645. ["lang", /^css$/i, "css"],
  13646. ["type", /^(text\/)?(x-)?(stylesheet|css)$/i, "css"],
  13647. ["type", /./, "text/plain"],
  13648. [null, null, "css"]
  13649. ]
  13650. };
  13651. function maybeBackup(stream, pat, style) {
  13652. var cur = stream.current(), close = cur.search(pat);
  13653. if (close > -1) {
  13654. stream.backUp(cur.length - close);
  13655. } else if (cur.match(/<\/?$/)) {
  13656. stream.backUp(cur.length);
  13657. if (!stream.match(pat, false)) stream.match(cur);
  13658. }
  13659. return style;
  13660. }
  13661. var attrRegexpCache = {};
  13662. function getAttrRegexp(attr) {
  13663. var regexp = attrRegexpCache[attr];
  13664. if (regexp) return regexp;
  13665. return attrRegexpCache[attr] = new RegExp("\\s+" + attr + "\\s*=\\s*('|\")?([^'\"]+)('|\")?\\s*");
  13666. }
  13667. function getAttrValue(text, attr) {
  13668. var match = text.match(getAttrRegexp(attr))
  13669. return match ? /^\s*(.*?)\s*$/.exec(match[2])[1] : ""
  13670. }
  13671. function getTagRegexp(tagName, anchored) {
  13672. return new RegExp((anchored ? "^" : "") + "<\/\s*" + tagName + "\s*>", "i");
  13673. }
  13674. function addTags(from, to) {
  13675. for (var tag in from) {
  13676. var dest = to[tag] || (to[tag] = []);
  13677. var source = from[tag];
  13678. for (var i = source.length - 1; i >= 0; i--)
  13679. dest.unshift(source[i])
  13680. }
  13681. }
  13682. function findMatchingMode(tagInfo, tagText) {
  13683. for (var i = 0; i < tagInfo.length; i++) {
  13684. var spec = tagInfo[i];
  13685. if (!spec[0] || spec[1].test(getAttrValue(tagText, spec[0]))) return spec[2];
  13686. }
  13687. }
  13688. CodeMirror.defineMode("htmlmixed", function (config, parserConfig) {
  13689. var htmlMode = CodeMirror.getMode(config, {
  13690. name: "xml",
  13691. htmlMode: true,
  13692. multilineTagIndentFactor: parserConfig.multilineTagIndentFactor,
  13693. multilineTagIndentPastTag: parserConfig.multilineTagIndentPastTag
  13694. });
  13695. var tags = {};
  13696. var configTags = parserConfig && parserConfig.tags, configScript = parserConfig && parserConfig.scriptTypes;
  13697. addTags(defaultTags, tags);
  13698. if (configTags) addTags(configTags, tags);
  13699. if (configScript) for (var i = configScript.length - 1; i >= 0; i--)
  13700. tags.script.unshift(["type", configScript[i].matches, configScript[i].mode])
  13701. function html(stream, state) {
  13702. var style = htmlMode.token(stream, state.htmlState), tag = /\btag\b/.test(style), tagName
  13703. if (tag && !/[<>\s\/]/.test(stream.current()) &&
  13704. (tagName = state.htmlState.tagName && state.htmlState.tagName.toLowerCase()) &&
  13705. tags.hasOwnProperty(tagName)) {
  13706. state.inTag = tagName + " "
  13707. } else if (state.inTag && tag && />$/.test(stream.current())) {
  13708. var inTag = /^([\S]+) (.*)/.exec(state.inTag)
  13709. state.inTag = null
  13710. var modeSpec = stream.current() == ">" && findMatchingMode(tags[inTag[1]], inTag[2])
  13711. var mode = CodeMirror.getMode(config, modeSpec)
  13712. var endTagA = getTagRegexp(inTag[1], true), endTag = getTagRegexp(inTag[1], false);
  13713. state.token = function (stream, state) {
  13714. if (stream.match(endTagA, false)) {
  13715. state.token = html;
  13716. state.localState = state.localMode = null;
  13717. return null;
  13718. }
  13719. return maybeBackup(stream, endTag, state.localMode.token(stream, state.localState));
  13720. };
  13721. state.localMode = mode;
  13722. state.localState = CodeMirror.startState(mode, htmlMode.indent(state.htmlState, "", ""));
  13723. } else if (state.inTag) {
  13724. state.inTag += stream.current()
  13725. if (stream.eol()) state.inTag += " "
  13726. }
  13727. return style;
  13728. };
  13729. return {
  13730. startState: function () {
  13731. var state = CodeMirror.startState(htmlMode);
  13732. return {token: html, inTag: null, localMode: null, localState: null, htmlState: state};
  13733. },
  13734. copyState: function (state) {
  13735. var local;
  13736. if (state.localState) {
  13737. local = CodeMirror.copyState(state.localMode, state.localState);
  13738. }
  13739. return {token: state.token, inTag: state.inTag,
  13740. localMode: state.localMode, localState: local,
  13741. htmlState: CodeMirror.copyState(htmlMode, state.htmlState)};
  13742. },
  13743. token: function (stream, state) {
  13744. return state.token(stream, state);
  13745. },
  13746. indent: function (state, textAfter, line) {
  13747. if (!state.localMode || /^\s*<\//.test(textAfter))
  13748. return htmlMode.indent(state.htmlState, textAfter, line);
  13749. else if (state.localMode.indent)
  13750. return state.localMode.indent(state.localState, textAfter, line);
  13751. else
  13752. return CodeMirror.Pass;
  13753. },
  13754. innerMode: function (state) {
  13755. return {state: state.localState || state.htmlState, mode: state.localMode || htmlMode};
  13756. }
  13757. };
  13758. }, "xml", "javascript", "css");
  13759. CodeMirror.defineMIME("text/html", "htmlmixed");
  13760. });
  13761. /***/ }),
  13762. /***/ "./node_modules/codemirror/mode/javascript/javascript.js":
  13763. /*!***************************************************************!*\
  13764. !*** ./node_modules/codemirror/mode/javascript/javascript.js ***!
  13765. \***************************************************************/
  13766. /*! no static exports found */
  13767. /***/ (function(module, exports, __webpack_require__) {
  13768. // CodeMirror, copyright (c) by Marijn Haverbeke and others
  13769. // Distributed under an MIT license: https://codemirror.net/LICENSE
  13770. (function(mod) {
  13771. if (true) // CommonJS
  13772. mod(__webpack_require__(/*! ../../lib/codemirror */ "./node_modules/codemirror/lib/codemirror.js"));
  13773. else {}
  13774. })(function(CodeMirror) {
  13775. "use strict";
  13776. CodeMirror.defineMode("javascript", function(config, parserConfig) {
  13777. var indentUnit = config.indentUnit;
  13778. var statementIndent = parserConfig.statementIndent;
  13779. var jsonldMode = parserConfig.jsonld;
  13780. var jsonMode = parserConfig.json || jsonldMode;
  13781. var isTS = parserConfig.typescript;
  13782. var wordRE = parserConfig.wordCharacters || /[\w$\xa1-\uffff]/;
  13783. // Tokenizer
  13784. var keywords = function(){
  13785. function kw(type) {return {type: type, style: "keyword"};}
  13786. var A = kw("keyword a"), B = kw("keyword b"), C = kw("keyword c"), D = kw("keyword d");
  13787. var operator = kw("operator"), atom = {type: "atom", style: "atom"};
  13788. return {
  13789. "if": kw("if"), "while": A, "with": A, "else": B, "do": B, "try": B, "finally": B,
  13790. "return": D, "break": D, "continue": D, "new": kw("new"), "delete": C, "void": C, "throw": C,
  13791. "debugger": kw("debugger"), "var": kw("var"), "const": kw("var"), "let": kw("var"),
  13792. "function": kw("function"), "catch": kw("catch"),
  13793. "for": kw("for"), "switch": kw("switch"), "case": kw("case"), "default": kw("default"),
  13794. "in": operator, "typeof": operator, "instanceof": operator,
  13795. "true": atom, "false": atom, "null": atom, "undefined": atom, "NaN": atom, "Infinity": atom,
  13796. "this": kw("this"), "class": kw("class"), "super": kw("atom"),
  13797. "yield": C, "export": kw("export"), "import": kw("import"), "extends": C,
  13798. "await": C
  13799. };
  13800. }();
  13801. var isOperatorChar = /[+\-*&%=<>!?|~^@]/;
  13802. var isJsonldKeyword = /^@(context|id|value|language|type|container|list|set|reverse|index|base|vocab|graph)"/;
  13803. function readRegexp(stream) {
  13804. var escaped = false, next, inSet = false;
  13805. while ((next = stream.next()) != null) {
  13806. if (!escaped) {
  13807. if (next == "/" && !inSet) return;
  13808. if (next == "[") inSet = true;
  13809. else if (inSet && next == "]") inSet = false;
  13810. }
  13811. escaped = !escaped && next == "\\";
  13812. }
  13813. }
  13814. // Used as scratch variables to communicate multiple values without
  13815. // consing up tons of objects.
  13816. var type, content;
  13817. function ret(tp, style, cont) {
  13818. type = tp; content = cont;
  13819. return style;
  13820. }
  13821. function tokenBase(stream, state) {
  13822. var ch = stream.next();
  13823. if (ch == '"' || ch == "'") {
  13824. state.tokenize = tokenString(ch);
  13825. return state.tokenize(stream, state);
  13826. } else if (ch == "." && stream.match(/^\d[\d_]*(?:[eE][+\-]?[\d_]+)?/)) {
  13827. return ret("number", "number");
  13828. } else if (ch == "." && stream.match("..")) {
  13829. return ret("spread", "meta");
  13830. } else if (/[\[\]{}\(\),;\:\.]/.test(ch)) {
  13831. return ret(ch);
  13832. } else if (ch == "=" && stream.eat(">")) {
  13833. return ret("=>", "operator");
  13834. } else if (ch == "0" && stream.match(/^(?:x[\dA-Fa-f_]+|o[0-7_]+|b[01_]+)n?/)) {
  13835. return ret("number", "number");
  13836. } else if (/\d/.test(ch)) {
  13837. stream.match(/^[\d_]*(?:n|(?:\.[\d_]*)?(?:[eE][+\-]?[\d_]+)?)?/);
  13838. return ret("number", "number");
  13839. } else if (ch == "/") {
  13840. if (stream.eat("*")) {
  13841. state.tokenize = tokenComment;
  13842. return tokenComment(stream, state);
  13843. } else if (stream.eat("/")) {
  13844. stream.skipToEnd();
  13845. return ret("comment", "comment");
  13846. } else if (expressionAllowed(stream, state, 1)) {
  13847. readRegexp(stream);
  13848. stream.match(/^\b(([gimyus])(?![gimyus]*\2))+\b/);
  13849. return ret("regexp", "string-2");
  13850. } else {
  13851. stream.eat("=");
  13852. return ret("operator", "operator", stream.current());
  13853. }
  13854. } else if (ch == "`") {
  13855. state.tokenize = tokenQuasi;
  13856. return tokenQuasi(stream, state);
  13857. } else if (ch == "#") {
  13858. stream.skipToEnd();
  13859. return ret("error", "error");
  13860. } else if (ch == "<" && stream.match("!--") || ch == "-" && stream.match("->")) {
  13861. stream.skipToEnd()
  13862. return ret("comment", "comment")
  13863. } else if (isOperatorChar.test(ch)) {
  13864. if (ch != ">" || !state.lexical || state.lexical.type != ">") {
  13865. if (stream.eat("=")) {
  13866. if (ch == "!" || ch == "=") stream.eat("=")
  13867. } else if (/[<>*+\-]/.test(ch)) {
  13868. stream.eat(ch)
  13869. if (ch == ">") stream.eat(ch)
  13870. }
  13871. }
  13872. return ret("operator", "operator", stream.current());
  13873. } else if (wordRE.test(ch)) {
  13874. stream.eatWhile(wordRE);
  13875. var word = stream.current()
  13876. if (state.lastType != ".") {
  13877. if (keywords.propertyIsEnumerable(word)) {
  13878. var kw = keywords[word]
  13879. return ret(kw.type, kw.style, word)
  13880. }
  13881. if (word == "async" && stream.match(/^(\s|\/\*.*?\*\/)*[\[\(\w]/, false))
  13882. return ret("async", "keyword", word)
  13883. }
  13884. return ret("variable", "variable", word)
  13885. }
  13886. }
  13887. function tokenString(quote) {
  13888. return function(stream, state) {
  13889. var escaped = false, next;
  13890. if (jsonldMode && stream.peek() == "@" && stream.match(isJsonldKeyword)){
  13891. state.tokenize = tokenBase;
  13892. return ret("jsonld-keyword", "meta");
  13893. }
  13894. while ((next = stream.next()) != null) {
  13895. if (next == quote && !escaped) break;
  13896. escaped = !escaped && next == "\\";
  13897. }
  13898. if (!escaped) state.tokenize = tokenBase;
  13899. return ret("string", "string");
  13900. };
  13901. }
  13902. function tokenComment(stream, state) {
  13903. var maybeEnd = false, ch;
  13904. while (ch = stream.next()) {
  13905. if (ch == "/" && maybeEnd) {
  13906. state.tokenize = tokenBase;
  13907. break;
  13908. }
  13909. maybeEnd = (ch == "*");
  13910. }
  13911. return ret("comment", "comment");
  13912. }
  13913. function tokenQuasi(stream, state) {
  13914. var escaped = false, next;
  13915. while ((next = stream.next()) != null) {
  13916. if (!escaped && (next == "`" || next == "$" && stream.eat("{"))) {
  13917. state.tokenize = tokenBase;
  13918. break;
  13919. }
  13920. escaped = !escaped && next == "\\";
  13921. }
  13922. return ret("quasi", "string-2", stream.current());
  13923. }
  13924. var brackets = "([{}])";
  13925. // This is a crude lookahead trick to try and notice that we're
  13926. // parsing the argument patterns for a fat-arrow function before we
  13927. // actually hit the arrow token. It only works if the arrow is on
  13928. // the same line as the arguments and there's no strange noise
  13929. // (comments) in between. Fallback is to only notice when we hit the
  13930. // arrow, and not declare the arguments as locals for the arrow
  13931. // body.
  13932. function findFatArrow(stream, state) {
  13933. if (state.fatArrowAt) state.fatArrowAt = null;
  13934. var arrow = stream.string.indexOf("=>", stream.start);
  13935. if (arrow < 0) return;
  13936. if (isTS) { // Try to skip TypeScript return type declarations after the arguments
  13937. var m = /:\s*(?:\w+(?:<[^>]*>|\[\])?|\{[^}]*\})\s*$/.exec(stream.string.slice(stream.start, arrow))
  13938. if (m) arrow = m.index
  13939. }
  13940. var depth = 0, sawSomething = false;
  13941. for (var pos = arrow - 1; pos >= 0; --pos) {
  13942. var ch = stream.string.charAt(pos);
  13943. var bracket = brackets.indexOf(ch);
  13944. if (bracket >= 0 && bracket < 3) {
  13945. if (!depth) { ++pos; break; }
  13946. if (--depth == 0) { if (ch == "(") sawSomething = true; break; }
  13947. } else if (bracket >= 3 && bracket < 6) {
  13948. ++depth;
  13949. } else if (wordRE.test(ch)) {
  13950. sawSomething = true;
  13951. } else if (/["'\/`]/.test(ch)) {
  13952. for (;; --pos) {
  13953. if (pos == 0) return
  13954. var next = stream.string.charAt(pos - 1)
  13955. if (next == ch && stream.string.charAt(pos - 2) != "\\") { pos--; break }
  13956. }
  13957. } else if (sawSomething && !depth) {
  13958. ++pos;
  13959. break;
  13960. }
  13961. }
  13962. if (sawSomething && !depth) state.fatArrowAt = pos;
  13963. }
  13964. // Parser
  13965. var atomicTypes = {"atom": true, "number": true, "variable": true, "string": true, "regexp": true, "this": true, "jsonld-keyword": true};
  13966. function JSLexical(indented, column, type, align, prev, info) {
  13967. this.indented = indented;
  13968. this.column = column;
  13969. this.type = type;
  13970. this.prev = prev;
  13971. this.info = info;
  13972. if (align != null) this.align = align;
  13973. }
  13974. function inScope(state, varname) {
  13975. for (var v = state.localVars; v; v = v.next)
  13976. if (v.name == varname) return true;
  13977. for (var cx = state.context; cx; cx = cx.prev) {
  13978. for (var v = cx.vars; v; v = v.next)
  13979. if (v.name == varname) return true;
  13980. }
  13981. }
  13982. function parseJS(state, style, type, content, stream) {
  13983. var cc = state.cc;
  13984. // Communicate our context to the combinators.
  13985. // (Less wasteful than consing up a hundred closures on every call.)
  13986. cx.state = state; cx.stream = stream; cx.marked = null, cx.cc = cc; cx.style = style;
  13987. if (!state.lexical.hasOwnProperty("align"))
  13988. state.lexical.align = true;
  13989. while(true) {
  13990. var combinator = cc.length ? cc.pop() : jsonMode ? expression : statement;
  13991. if (combinator(type, content)) {
  13992. while(cc.length && cc[cc.length - 1].lex)
  13993. cc.pop()();
  13994. if (cx.marked) return cx.marked;
  13995. if (type == "variable" && inScope(state, content)) return "variable-2";
  13996. return style;
  13997. }
  13998. }
  13999. }
  14000. // Combinator utils
  14001. var cx = {state: null, column: null, marked: null, cc: null};
  14002. function pass() {
  14003. for (var i = arguments.length - 1; i >= 0; i--) cx.cc.push(arguments[i]);
  14004. }
  14005. function cont() {
  14006. pass.apply(null, arguments);
  14007. return true;
  14008. }
  14009. function inList(name, list) {
  14010. for (var v = list; v; v = v.next) if (v.name == name) return true
  14011. return false;
  14012. }
  14013. function register(varname) {
  14014. var state = cx.state;
  14015. cx.marked = "def";
  14016. if (state.context) {
  14017. if (state.lexical.info == "var" && state.context && state.context.block) {
  14018. // FIXME function decls are also not block scoped
  14019. var newContext = registerVarScoped(varname, state.context)
  14020. if (newContext != null) {
  14021. state.context = newContext
  14022. return
  14023. }
  14024. } else if (!inList(varname, state.localVars)) {
  14025. state.localVars = new Var(varname, state.localVars)
  14026. return
  14027. }
  14028. }
  14029. // Fall through means this is global
  14030. if (parserConfig.globalVars && !inList(varname, state.globalVars))
  14031. state.globalVars = new Var(varname, state.globalVars)
  14032. }
  14033. function registerVarScoped(varname, context) {
  14034. if (!context) {
  14035. return null
  14036. } else if (context.block) {
  14037. var inner = registerVarScoped(varname, context.prev)
  14038. if (!inner) return null
  14039. if (inner == context.prev) return context
  14040. return new Context(inner, context.vars, true)
  14041. } else if (inList(varname, context.vars)) {
  14042. return context
  14043. } else {
  14044. return new Context(context.prev, new Var(varname, context.vars), false)
  14045. }
  14046. }
  14047. function isModifier(name) {
  14048. return name == "public" || name == "private" || name == "protected" || name == "abstract" || name == "readonly"
  14049. }
  14050. // Combinators
  14051. function Context(prev, vars, block) { this.prev = prev; this.vars = vars; this.block = block }
  14052. function Var(name, next) { this.name = name; this.next = next }
  14053. var defaultVars = new Var("this", new Var("arguments", null))
  14054. function pushcontext() {
  14055. cx.state.context = new Context(cx.state.context, cx.state.localVars, false)
  14056. cx.state.localVars = defaultVars
  14057. }
  14058. function pushblockcontext() {
  14059. cx.state.context = new Context(cx.state.context, cx.state.localVars, true)
  14060. cx.state.localVars = null
  14061. }
  14062. function popcontext() {
  14063. cx.state.localVars = cx.state.context.vars
  14064. cx.state.context = cx.state.context.prev
  14065. }
  14066. popcontext.lex = true
  14067. function pushlex(type, info) {
  14068. var result = function() {
  14069. var state = cx.state, indent = state.indented;
  14070. if (state.lexical.type == "stat") indent = state.lexical.indented;
  14071. else for (var outer = state.lexical; outer && outer.type == ")" && outer.align; outer = outer.prev)
  14072. indent = outer.indented;
  14073. state.lexical = new JSLexical(indent, cx.stream.column(), type, null, state.lexical, info);
  14074. };
  14075. result.lex = true;
  14076. return result;
  14077. }
  14078. function poplex() {
  14079. var state = cx.state;
  14080. if (state.lexical.prev) {
  14081. if (state.lexical.type == ")")
  14082. state.indented = state.lexical.indented;
  14083. state.lexical = state.lexical.prev;
  14084. }
  14085. }
  14086. poplex.lex = true;
  14087. function expect(wanted) {
  14088. function exp(type) {
  14089. if (type == wanted) return cont();
  14090. else if (wanted == ";" || type == "}" || type == ")" || type == "]") return pass();
  14091. else return cont(exp);
  14092. };
  14093. return exp;
  14094. }
  14095. function statement(type, value) {
  14096. if (type == "var") return cont(pushlex("vardef", value), vardef, expect(";"), poplex);
  14097. if (type == "keyword a") return cont(pushlex("form"), parenExpr, statement, poplex);
  14098. if (type == "keyword b") return cont(pushlex("form"), statement, poplex);
  14099. if (type == "keyword d") return cx.stream.match(/^\s*$/, false) ? cont() : cont(pushlex("stat"), maybeexpression, expect(";"), poplex);
  14100. if (type == "debugger") return cont(expect(";"));
  14101. if (type == "{") return cont(pushlex("}"), pushblockcontext, block, poplex, popcontext);
  14102. if (type == ";") return cont();
  14103. if (type == "if") {
  14104. if (cx.state.lexical.info == "else" && cx.state.cc[cx.state.cc.length - 1] == poplex)
  14105. cx.state.cc.pop()();
  14106. return cont(pushlex("form"), parenExpr, statement, poplex, maybeelse);
  14107. }
  14108. if (type == "function") return cont(functiondef);
  14109. if (type == "for") return cont(pushlex("form"), forspec, statement, poplex);
  14110. if (type == "class" || (isTS && value == "interface")) {
  14111. cx.marked = "keyword"
  14112. return cont(pushlex("form", type == "class" ? type : value), className, poplex)
  14113. }
  14114. if (type == "variable") {
  14115. if (isTS && value == "declare") {
  14116. cx.marked = "keyword"
  14117. return cont(statement)
  14118. } else if (isTS && (value == "module" || value == "enum" || value == "type") && cx.stream.match(/^\s*\w/, false)) {
  14119. cx.marked = "keyword"
  14120. if (value == "enum") return cont(enumdef);
  14121. else if (value == "type") return cont(typename, expect("operator"), typeexpr, expect(";"));
  14122. else return cont(pushlex("form"), pattern, expect("{"), pushlex("}"), block, poplex, poplex)
  14123. } else if (isTS && value == "namespace") {
  14124. cx.marked = "keyword"
  14125. return cont(pushlex("form"), expression, statement, poplex)
  14126. } else if (isTS && value == "abstract") {
  14127. cx.marked = "keyword"
  14128. return cont(statement)
  14129. } else {
  14130. return cont(pushlex("stat"), maybelabel);
  14131. }
  14132. }
  14133. if (type == "switch") return cont(pushlex("form"), parenExpr, expect("{"), pushlex("}", "switch"), pushblockcontext,
  14134. block, poplex, poplex, popcontext);
  14135. if (type == "case") return cont(expression, expect(":"));
  14136. if (type == "default") return cont(expect(":"));
  14137. if (type == "catch") return cont(pushlex("form"), pushcontext, maybeCatchBinding, statement, poplex, popcontext);
  14138. if (type == "export") return cont(pushlex("stat"), afterExport, poplex);
  14139. if (type == "import") return cont(pushlex("stat"), afterImport, poplex);
  14140. if (type == "async") return cont(statement)
  14141. if (value == "@") return cont(expression, statement)
  14142. return pass(pushlex("stat"), expression, expect(";"), poplex);
  14143. }
  14144. function maybeCatchBinding(type) {
  14145. if (type == "(") return cont(funarg, expect(")"))
  14146. }
  14147. function expression(type, value) {
  14148. return expressionInner(type, value, false);
  14149. }
  14150. function expressionNoComma(type, value) {
  14151. return expressionInner(type, value, true);
  14152. }
  14153. function parenExpr(type) {
  14154. if (type != "(") return pass()
  14155. return cont(pushlex(")"), expression, expect(")"), poplex)
  14156. }
  14157. function expressionInner(type, value, noComma) {
  14158. if (cx.state.fatArrowAt == cx.stream.start) {
  14159. var body = noComma ? arrowBodyNoComma : arrowBody;
  14160. if (type == "(") return cont(pushcontext, pushlex(")"), commasep(funarg, ")"), poplex, expect("=>"), body, popcontext);
  14161. else if (type == "variable") return pass(pushcontext, pattern, expect("=>"), body, popcontext);
  14162. }
  14163. var maybeop = noComma ? maybeoperatorNoComma : maybeoperatorComma;
  14164. if (atomicTypes.hasOwnProperty(type)) return cont(maybeop);
  14165. if (type == "function") return cont(functiondef, maybeop);
  14166. if (type == "class" || (isTS && value == "interface")) { cx.marked = "keyword"; return cont(pushlex("form"), classExpression, poplex); }
  14167. if (type == "keyword c" || type == "async") return cont(noComma ? expressionNoComma : expression);
  14168. if (type == "(") return cont(pushlex(")"), maybeexpression, expect(")"), poplex, maybeop);
  14169. if (type == "operator" || type == "spread") return cont(noComma ? expressionNoComma : expression);
  14170. if (type == "[") return cont(pushlex("]"), arrayLiteral, poplex, maybeop);
  14171. if (type == "{") return contCommasep(objprop, "}", null, maybeop);
  14172. if (type == "quasi") return pass(quasi, maybeop);
  14173. if (type == "new") return cont(maybeTarget(noComma));
  14174. if (type == "import") return cont(expression);
  14175. return cont();
  14176. }
  14177. function maybeexpression(type) {
  14178. if (type.match(/[;\}\)\],]/)) return pass();
  14179. return pass(expression);
  14180. }
  14181. function maybeoperatorComma(type, value) {
  14182. if (type == ",") return cont(expression);
  14183. return maybeoperatorNoComma(type, value, false);
  14184. }
  14185. function maybeoperatorNoComma(type, value, noComma) {
  14186. var me = noComma == false ? maybeoperatorComma : maybeoperatorNoComma;
  14187. var expr = noComma == false ? expression : expressionNoComma;
  14188. if (type == "=>") return cont(pushcontext, noComma ? arrowBodyNoComma : arrowBody, popcontext);
  14189. if (type == "operator") {
  14190. if (/\+\+|--/.test(value) || isTS && value == "!") return cont(me);
  14191. if (isTS && value == "<" && cx.stream.match(/^([^>]|<.*?>)*>\s*\(/, false))
  14192. return cont(pushlex(">"), commasep(typeexpr, ">"), poplex, me);
  14193. if (value == "?") return cont(expression, expect(":"), expr);
  14194. return cont(expr);
  14195. }
  14196. if (type == "quasi") { return pass(quasi, me); }
  14197. if (type == ";") return;
  14198. if (type == "(") return contCommasep(expressionNoComma, ")", "call", me);
  14199. if (type == ".") return cont(property, me);
  14200. if (type == "[") return cont(pushlex("]"), maybeexpression, expect("]"), poplex, me);
  14201. if (isTS && value == "as") { cx.marked = "keyword"; return cont(typeexpr, me) }
  14202. if (type == "regexp") {
  14203. cx.state.lastType = cx.marked = "operator"
  14204. cx.stream.backUp(cx.stream.pos - cx.stream.start - 1)
  14205. return cont(expr)
  14206. }
  14207. }
  14208. function quasi(type, value) {
  14209. if (type != "quasi") return pass();
  14210. if (value.slice(value.length - 2) != "${") return cont(quasi);
  14211. return cont(expression, continueQuasi);
  14212. }
  14213. function continueQuasi(type) {
  14214. if (type == "}") {
  14215. cx.marked = "string-2";
  14216. cx.state.tokenize = tokenQuasi;
  14217. return cont(quasi);
  14218. }
  14219. }
  14220. function arrowBody(type) {
  14221. findFatArrow(cx.stream, cx.state);
  14222. return pass(type == "{" ? statement : expression);
  14223. }
  14224. function arrowBodyNoComma(type) {
  14225. findFatArrow(cx.stream, cx.state);
  14226. return pass(type == "{" ? statement : expressionNoComma);
  14227. }
  14228. function maybeTarget(noComma) {
  14229. return function(type) {
  14230. if (type == ".") return cont(noComma ? targetNoComma : target);
  14231. else if (type == "variable" && isTS) return cont(maybeTypeArgs, noComma ? maybeoperatorNoComma : maybeoperatorComma)
  14232. else return pass(noComma ? expressionNoComma : expression);
  14233. };
  14234. }
  14235. function target(_, value) {
  14236. if (value == "target") { cx.marked = "keyword"; return cont(maybeoperatorComma); }
  14237. }
  14238. function targetNoComma(_, value) {
  14239. if (value == "target") { cx.marked = "keyword"; return cont(maybeoperatorNoComma); }
  14240. }
  14241. function maybelabel(type) {
  14242. if (type == ":") return cont(poplex, statement);
  14243. return pass(maybeoperatorComma, expect(";"), poplex);
  14244. }
  14245. function property(type) {
  14246. if (type == "variable") {cx.marked = "property"; return cont();}
  14247. }
  14248. function objprop(type, value) {
  14249. if (type == "async") {
  14250. cx.marked = "property";
  14251. return cont(objprop);
  14252. } else if (type == "variable" || cx.style == "keyword") {
  14253. cx.marked = "property";
  14254. if (value == "get" || value == "set") return cont(getterSetter);
  14255. var m // Work around fat-arrow-detection complication for detecting typescript typed arrow params
  14256. if (isTS && cx.state.fatArrowAt == cx.stream.start && (m = cx.stream.match(/^\s*:\s*/, false)))
  14257. cx.state.fatArrowAt = cx.stream.pos + m[0].length
  14258. return cont(afterprop);
  14259. } else if (type == "number" || type == "string") {
  14260. cx.marked = jsonldMode ? "property" : (cx.style + " property");
  14261. return cont(afterprop);
  14262. } else if (type == "jsonld-keyword") {
  14263. return cont(afterprop);
  14264. } else if (isTS && isModifier(value)) {
  14265. cx.marked = "keyword"
  14266. return cont(objprop)
  14267. } else if (type == "[") {
  14268. return cont(expression, maybetype, expect("]"), afterprop);
  14269. } else if (type == "spread") {
  14270. return cont(expressionNoComma, afterprop);
  14271. } else if (value == "*") {
  14272. cx.marked = "keyword";
  14273. return cont(objprop);
  14274. } else if (type == ":") {
  14275. return pass(afterprop)
  14276. }
  14277. }
  14278. function getterSetter(type) {
  14279. if (type != "variable") return pass(afterprop);
  14280. cx.marked = "property";
  14281. return cont(functiondef);
  14282. }
  14283. function afterprop(type) {
  14284. if (type == ":") return cont(expressionNoComma);
  14285. if (type == "(") return pass(functiondef);
  14286. }
  14287. function commasep(what, end, sep) {
  14288. function proceed(type, value) {
  14289. if (sep ? sep.indexOf(type) > -1 : type == ",") {
  14290. var lex = cx.state.lexical;
  14291. if (lex.info == "call") lex.pos = (lex.pos || 0) + 1;
  14292. return cont(function(type, value) {
  14293. if (type == end || value == end) return pass()
  14294. return pass(what)
  14295. }, proceed);
  14296. }
  14297. if (type == end || value == end) return cont();
  14298. if (sep && sep.indexOf(";") > -1) return pass(what)
  14299. return cont(expect(end));
  14300. }
  14301. return function(type, value) {
  14302. if (type == end || value == end) return cont();
  14303. return pass(what, proceed);
  14304. };
  14305. }
  14306. function contCommasep(what, end, info) {
  14307. for (var i = 3; i < arguments.length; i++)
  14308. cx.cc.push(arguments[i]);
  14309. return cont(pushlex(end, info), commasep(what, end), poplex);
  14310. }
  14311. function block(type) {
  14312. if (type == "}") return cont();
  14313. return pass(statement, block);
  14314. }
  14315. function maybetype(type, value) {
  14316. if (isTS) {
  14317. if (type == ":") return cont(typeexpr);
  14318. if (value == "?") return cont(maybetype);
  14319. }
  14320. }
  14321. function maybetypeOrIn(type, value) {
  14322. if (isTS && (type == ":" || value == "in")) return cont(typeexpr)
  14323. }
  14324. function mayberettype(type) {
  14325. if (isTS && type == ":") {
  14326. if (cx.stream.match(/^\s*\w+\s+is\b/, false)) return cont(expression, isKW, typeexpr)
  14327. else return cont(typeexpr)
  14328. }
  14329. }
  14330. function isKW(_, value) {
  14331. if (value == "is") {
  14332. cx.marked = "keyword"
  14333. return cont()
  14334. }
  14335. }
  14336. function typeexpr(type, value) {
  14337. if (value == "keyof" || value == "typeof" || value == "infer") {
  14338. cx.marked = "keyword"
  14339. return cont(value == "typeof" ? expressionNoComma : typeexpr)
  14340. }
  14341. if (type == "variable" || value == "void") {
  14342. cx.marked = "type"
  14343. return cont(afterType)
  14344. }
  14345. if (value == "|" || value == "&") return cont(typeexpr)
  14346. if (type == "string" || type == "number" || type == "atom") return cont(afterType);
  14347. if (type == "[") return cont(pushlex("]"), commasep(typeexpr, "]", ","), poplex, afterType)
  14348. if (type == "{") return cont(pushlex("}"), commasep(typeprop, "}", ",;"), poplex, afterType)
  14349. if (type == "(") return cont(commasep(typearg, ")"), maybeReturnType, afterType)
  14350. if (type == "<") return cont(commasep(typeexpr, ">"), typeexpr)
  14351. }
  14352. function maybeReturnType(type) {
  14353. if (type == "=>") return cont(typeexpr)
  14354. }
  14355. function typeprop(type, value) {
  14356. if (type == "variable" || cx.style == "keyword") {
  14357. cx.marked = "property"
  14358. return cont(typeprop)
  14359. } else if (value == "?" || type == "number" || type == "string") {
  14360. return cont(typeprop)
  14361. } else if (type == ":") {
  14362. return cont(typeexpr)
  14363. } else if (type == "[") {
  14364. return cont(expect("variable"), maybetypeOrIn, expect("]"), typeprop)
  14365. } else if (type == "(") {
  14366. return pass(functiondecl, typeprop)
  14367. }
  14368. }
  14369. function typearg(type, value) {
  14370. if (type == "variable" && cx.stream.match(/^\s*[?:]/, false) || value == "?") return cont(typearg)
  14371. if (type == ":") return cont(typeexpr)
  14372. if (type == "spread") return cont(typearg)
  14373. return pass(typeexpr)
  14374. }
  14375. function afterType(type, value) {
  14376. if (value == "<") return cont(pushlex(">"), commasep(typeexpr, ">"), poplex, afterType)
  14377. if (value == "|" || type == "." || value == "&") return cont(typeexpr)
  14378. if (type == "[") return cont(typeexpr, expect("]"), afterType)
  14379. if (value == "extends" || value == "implements") { cx.marked = "keyword"; return cont(typeexpr) }
  14380. if (value == "?") return cont(typeexpr, expect(":"), typeexpr)
  14381. }
  14382. function maybeTypeArgs(_, value) {
  14383. if (value == "<") return cont(pushlex(">"), commasep(typeexpr, ">"), poplex, afterType)
  14384. }
  14385. function typeparam() {
  14386. return pass(typeexpr, maybeTypeDefault)
  14387. }
  14388. function maybeTypeDefault(_, value) {
  14389. if (value == "=") return cont(typeexpr)
  14390. }
  14391. function vardef(_, value) {
  14392. if (value == "enum") {cx.marked = "keyword"; return cont(enumdef)}
  14393. return pass(pattern, maybetype, maybeAssign, vardefCont);
  14394. }
  14395. function pattern(type, value) {
  14396. if (isTS && isModifier(value)) { cx.marked = "keyword"; return cont(pattern) }
  14397. if (type == "variable") { register(value); return cont(); }
  14398. if (type == "spread") return cont(pattern);
  14399. if (type == "[") return contCommasep(eltpattern, "]");
  14400. if (type == "{") return contCommasep(proppattern, "}");
  14401. }
  14402. function proppattern(type, value) {
  14403. if (type == "variable" && !cx.stream.match(/^\s*:/, false)) {
  14404. register(value);
  14405. return cont(maybeAssign);
  14406. }
  14407. if (type == "variable") cx.marked = "property";
  14408. if (type == "spread") return cont(pattern);
  14409. if (type == "}") return pass();
  14410. if (type == "[") return cont(expression, expect(']'), expect(':'), proppattern);
  14411. return cont(expect(":"), pattern, maybeAssign);
  14412. }
  14413. function eltpattern() {
  14414. return pass(pattern, maybeAssign)
  14415. }
  14416. function maybeAssign(_type, value) {
  14417. if (value == "=") return cont(expressionNoComma);
  14418. }
  14419. function vardefCont(type) {
  14420. if (type == ",") return cont(vardef);
  14421. }
  14422. function maybeelse(type, value) {
  14423. if (type == "keyword b" && value == "else") return cont(pushlex("form", "else"), statement, poplex);
  14424. }
  14425. function forspec(type, value) {
  14426. if (value == "await") return cont(forspec);
  14427. if (type == "(") return cont(pushlex(")"), forspec1, poplex);
  14428. }
  14429. function forspec1(type) {
  14430. if (type == "var") return cont(vardef, forspec2);
  14431. if (type == "variable") return cont(forspec2);
  14432. return pass(forspec2)
  14433. }
  14434. function forspec2(type, value) {
  14435. if (type == ")") return cont()
  14436. if (type == ";") return cont(forspec2)
  14437. if (value == "in" || value == "of") { cx.marked = "keyword"; return cont(expression, forspec2) }
  14438. return pass(expression, forspec2)
  14439. }
  14440. function functiondef(type, value) {
  14441. if (value == "*") {cx.marked = "keyword"; return cont(functiondef);}
  14442. if (type == "variable") {register(value); return cont(functiondef);}
  14443. if (type == "(") return cont(pushcontext, pushlex(")"), commasep(funarg, ")"), poplex, mayberettype, statement, popcontext);
  14444. if (isTS && value == "<") return cont(pushlex(">"), commasep(typeparam, ">"), poplex, functiondef)
  14445. }
  14446. function functiondecl(type, value) {
  14447. if (value == "*") {cx.marked = "keyword"; return cont(functiondecl);}
  14448. if (type == "variable") {register(value); return cont(functiondecl);}
  14449. if (type == "(") return cont(pushcontext, pushlex(")"), commasep(funarg, ")"), poplex, mayberettype, popcontext);
  14450. if (isTS && value == "<") return cont(pushlex(">"), commasep(typeparam, ">"), poplex, functiondecl)
  14451. }
  14452. function typename(type, value) {
  14453. if (type == "keyword" || type == "variable") {
  14454. cx.marked = "type"
  14455. return cont(typename)
  14456. } else if (value == "<") {
  14457. return cont(pushlex(">"), commasep(typeparam, ">"), poplex)
  14458. }
  14459. }
  14460. function funarg(type, value) {
  14461. if (value == "@") cont(expression, funarg)
  14462. if (type == "spread") return cont(funarg);
  14463. if (isTS && isModifier(value)) { cx.marked = "keyword"; return cont(funarg); }
  14464. if (isTS && type == "this") return cont(maybetype, maybeAssign)
  14465. return pass(pattern, maybetype, maybeAssign);
  14466. }
  14467. function classExpression(type, value) {
  14468. // Class expressions may have an optional name.
  14469. if (type == "variable") return className(type, value);
  14470. return classNameAfter(type, value);
  14471. }
  14472. function className(type, value) {
  14473. if (type == "variable") {register(value); return cont(classNameAfter);}
  14474. }
  14475. function classNameAfter(type, value) {
  14476. if (value == "<") return cont(pushlex(">"), commasep(typeparam, ">"), poplex, classNameAfter)
  14477. if (value == "extends" || value == "implements" || (isTS && type == ",")) {
  14478. if (value == "implements") cx.marked = "keyword";
  14479. return cont(isTS ? typeexpr : expression, classNameAfter);
  14480. }
  14481. if (type == "{") return cont(pushlex("}"), classBody, poplex);
  14482. }
  14483. function classBody(type, value) {
  14484. if (type == "async" ||
  14485. (type == "variable" &&
  14486. (value == "static" || value == "get" || value == "set" || (isTS && isModifier(value))) &&
  14487. cx.stream.match(/^\s+[\w$\xa1-\uffff]/, false))) {
  14488. cx.marked = "keyword";
  14489. return cont(classBody);
  14490. }
  14491. if (type == "variable" || cx.style == "keyword") {
  14492. cx.marked = "property";
  14493. return cont(isTS ? classfield : functiondef, classBody);
  14494. }
  14495. if (type == "number" || type == "string") return cont(isTS ? classfield : functiondef, classBody);
  14496. if (type == "[")
  14497. return cont(expression, maybetype, expect("]"), isTS ? classfield : functiondef, classBody)
  14498. if (value == "*") {
  14499. cx.marked = "keyword";
  14500. return cont(classBody);
  14501. }
  14502. if (isTS && type == "(") return pass(functiondecl, classBody)
  14503. if (type == ";" || type == ",") return cont(classBody);
  14504. if (type == "}") return cont();
  14505. if (value == "@") return cont(expression, classBody)
  14506. }
  14507. function classfield(type, value) {
  14508. if (value == "?") return cont(classfield)
  14509. if (type == ":") return cont(typeexpr, maybeAssign)
  14510. if (value == "=") return cont(expressionNoComma)
  14511. var context = cx.state.lexical.prev, isInterface = context && context.info == "interface"
  14512. return pass(isInterface ? functiondecl : functiondef)
  14513. }
  14514. function afterExport(type, value) {
  14515. if (value == "*") { cx.marked = "keyword"; return cont(maybeFrom, expect(";")); }
  14516. if (value == "default") { cx.marked = "keyword"; return cont(expression, expect(";")); }
  14517. if (type == "{") return cont(commasep(exportField, "}"), maybeFrom, expect(";"));
  14518. return pass(statement);
  14519. }
  14520. function exportField(type, value) {
  14521. if (value == "as") { cx.marked = "keyword"; return cont(expect("variable")); }
  14522. if (type == "variable") return pass(expressionNoComma, exportField);
  14523. }
  14524. function afterImport(type) {
  14525. if (type == "string") return cont();
  14526. if (type == "(") return pass(expression);
  14527. return pass(importSpec, maybeMoreImports, maybeFrom);
  14528. }
  14529. function importSpec(type, value) {
  14530. if (type == "{") return contCommasep(importSpec, "}");
  14531. if (type == "variable") register(value);
  14532. if (value == "*") cx.marked = "keyword";
  14533. return cont(maybeAs);
  14534. }
  14535. function maybeMoreImports(type) {
  14536. if (type == ",") return cont(importSpec, maybeMoreImports)
  14537. }
  14538. function maybeAs(_type, value) {
  14539. if (value == "as") { cx.marked = "keyword"; return cont(importSpec); }
  14540. }
  14541. function maybeFrom(_type, value) {
  14542. if (value == "from") { cx.marked = "keyword"; return cont(expression); }
  14543. }
  14544. function arrayLiteral(type) {
  14545. if (type == "]") return cont();
  14546. return pass(commasep(expressionNoComma, "]"));
  14547. }
  14548. function enumdef() {
  14549. return pass(pushlex("form"), pattern, expect("{"), pushlex("}"), commasep(enummember, "}"), poplex, poplex)
  14550. }
  14551. function enummember() {
  14552. return pass(pattern, maybeAssign);
  14553. }
  14554. function isContinuedStatement(state, textAfter) {
  14555. return state.lastType == "operator" || state.lastType == "," ||
  14556. isOperatorChar.test(textAfter.charAt(0)) ||
  14557. /[,.]/.test(textAfter.charAt(0));
  14558. }
  14559. function expressionAllowed(stream, state, backUp) {
  14560. return state.tokenize == tokenBase &&
  14561. /^(?:operator|sof|keyword [bcd]|case|new|export|default|spread|[\[{}\(,;:]|=>)$/.test(state.lastType) ||
  14562. (state.lastType == "quasi" && /\{\s*$/.test(stream.string.slice(0, stream.pos - (backUp || 0))))
  14563. }
  14564. // Interface
  14565. return {
  14566. startState: function(basecolumn) {
  14567. var state = {
  14568. tokenize: tokenBase,
  14569. lastType: "sof",
  14570. cc: [],
  14571. lexical: new JSLexical((basecolumn || 0) - indentUnit, 0, "block", false),
  14572. localVars: parserConfig.localVars,
  14573. context: parserConfig.localVars && new Context(null, null, false),
  14574. indented: basecolumn || 0
  14575. };
  14576. if (parserConfig.globalVars && typeof parserConfig.globalVars == "object")
  14577. state.globalVars = parserConfig.globalVars;
  14578. return state;
  14579. },
  14580. token: function(stream, state) {
  14581. if (stream.sol()) {
  14582. if (!state.lexical.hasOwnProperty("align"))
  14583. state.lexical.align = false;
  14584. state.indented = stream.indentation();
  14585. findFatArrow(stream, state);
  14586. }
  14587. if (state.tokenize != tokenComment && stream.eatSpace()) return null;
  14588. var style = state.tokenize(stream, state);
  14589. if (type == "comment") return style;
  14590. state.lastType = type == "operator" && (content == "++" || content == "--") ? "incdec" : type;
  14591. return parseJS(state, style, type, content, stream);
  14592. },
  14593. indent: function(state, textAfter) {
  14594. if (state.tokenize == tokenComment) return CodeMirror.Pass;
  14595. if (state.tokenize != tokenBase) return 0;
  14596. var firstChar = textAfter && textAfter.charAt(0), lexical = state.lexical, top
  14597. // Kludge to prevent 'maybelse' from blocking lexical scope pops
  14598. if (!/^\s*else\b/.test(textAfter)) for (var i = state.cc.length - 1; i >= 0; --i) {
  14599. var c = state.cc[i];
  14600. if (c == poplex) lexical = lexical.prev;
  14601. else if (c != maybeelse) break;
  14602. }
  14603. while ((lexical.type == "stat" || lexical.type == "form") &&
  14604. (firstChar == "}" || ((top = state.cc[state.cc.length - 1]) &&
  14605. (top == maybeoperatorComma || top == maybeoperatorNoComma) &&
  14606. !/^[,\.=+\-*:?[\(]/.test(textAfter))))
  14607. lexical = lexical.prev;
  14608. if (statementIndent && lexical.type == ")" && lexical.prev.type == "stat")
  14609. lexical = lexical.prev;
  14610. var type = lexical.type, closing = firstChar == type;
  14611. if (type == "vardef") return lexical.indented + (state.lastType == "operator" || state.lastType == "," ? lexical.info.length + 1 : 0);
  14612. else if (type == "form" && firstChar == "{") return lexical.indented;
  14613. else if (type == "form") return lexical.indented + indentUnit;
  14614. else if (type == "stat")
  14615. return lexical.indented + (isContinuedStatement(state, textAfter) ? statementIndent || indentUnit : 0);
  14616. else if (lexical.info == "switch" && !closing && parserConfig.doubleIndentSwitch != false)
  14617. return lexical.indented + (/^(?:case|default)\b/.test(textAfter) ? indentUnit : 2 * indentUnit);
  14618. else if (lexical.align) return lexical.column + (closing ? 0 : 1);
  14619. else return lexical.indented + (closing ? 0 : indentUnit);
  14620. },
  14621. electricInput: /^\s*(?:case .*?:|default:|\{|\})$/,
  14622. blockCommentStart: jsonMode ? null : "/*",
  14623. blockCommentEnd: jsonMode ? null : "*/",
  14624. blockCommentContinue: jsonMode ? null : " * ",
  14625. lineComment: jsonMode ? null : "//",
  14626. fold: "brace",
  14627. closeBrackets: "()[]{}''\"\"``",
  14628. helperType: jsonMode ? "json" : "javascript",
  14629. jsonldMode: jsonldMode,
  14630. jsonMode: jsonMode,
  14631. expressionAllowed: expressionAllowed,
  14632. skipExpression: function(state) {
  14633. var top = state.cc[state.cc.length - 1]
  14634. if (top == expression || top == expressionNoComma) state.cc.pop()
  14635. }
  14636. };
  14637. });
  14638. CodeMirror.registerHelper("wordChars", "javascript", /[\w$]/);
  14639. CodeMirror.defineMIME("text/javascript", "javascript");
  14640. CodeMirror.defineMIME("text/ecmascript", "javascript");
  14641. CodeMirror.defineMIME("application/javascript", "javascript");
  14642. CodeMirror.defineMIME("application/x-javascript", "javascript");
  14643. CodeMirror.defineMIME("application/ecmascript", "javascript");
  14644. CodeMirror.defineMIME("application/json", {name: "javascript", json: true});
  14645. CodeMirror.defineMIME("application/x-json", {name: "javascript", json: true});
  14646. CodeMirror.defineMIME("application/ld+json", {name: "javascript", jsonld: true});
  14647. CodeMirror.defineMIME("text/typescript", { name: "javascript", typescript: true });
  14648. CodeMirror.defineMIME("application/typescript", { name: "javascript", typescript: true });
  14649. });
  14650. /***/ }),
  14651. /***/ "./node_modules/codemirror/mode/xml/xml.js":
  14652. /*!*************************************************!*\
  14653. !*** ./node_modules/codemirror/mode/xml/xml.js ***!
  14654. \*************************************************/
  14655. /*! no static exports found */
  14656. /***/ (function(module, exports, __webpack_require__) {
  14657. // CodeMirror, copyright (c) by Marijn Haverbeke and others
  14658. // Distributed under an MIT license: https://codemirror.net/LICENSE
  14659. (function(mod) {
  14660. if (true) // CommonJS
  14661. mod(__webpack_require__(/*! ../../lib/codemirror */ "./node_modules/codemirror/lib/codemirror.js"));
  14662. else {}
  14663. })(function(CodeMirror) {
  14664. "use strict";
  14665. var htmlConfig = {
  14666. autoSelfClosers: {'area': true, 'base': true, 'br': true, 'col': true, 'command': true,
  14667. 'embed': true, 'frame': true, 'hr': true, 'img': true, 'input': true,
  14668. 'keygen': true, 'link': true, 'meta': true, 'param': true, 'source': true,
  14669. 'track': true, 'wbr': true, 'menuitem': true},
  14670. implicitlyClosed: {'dd': true, 'li': true, 'optgroup': true, 'option': true, 'p': true,
  14671. 'rp': true, 'rt': true, 'tbody': true, 'td': true, 'tfoot': true,
  14672. 'th': true, 'tr': true},
  14673. contextGrabbers: {
  14674. 'dd': {'dd': true, 'dt': true},
  14675. 'dt': {'dd': true, 'dt': true},
  14676. 'li': {'li': true},
  14677. 'option': {'option': true, 'optgroup': true},
  14678. 'optgroup': {'optgroup': true},
  14679. 'p': {'address': true, 'article': true, 'aside': true, 'blockquote': true, 'dir': true,
  14680. 'div': true, 'dl': true, 'fieldset': true, 'footer': true, 'form': true,
  14681. 'h1': true, 'h2': true, 'h3': true, 'h4': true, 'h5': true, 'h6': true,
  14682. 'header': true, 'hgroup': true, 'hr': true, 'menu': true, 'nav': true, 'ol': true,
  14683. 'p': true, 'pre': true, 'section': true, 'table': true, 'ul': true},
  14684. 'rp': {'rp': true, 'rt': true},
  14685. 'rt': {'rp': true, 'rt': true},
  14686. 'tbody': {'tbody': true, 'tfoot': true},
  14687. 'td': {'td': true, 'th': true},
  14688. 'tfoot': {'tbody': true},
  14689. 'th': {'td': true, 'th': true},
  14690. 'thead': {'tbody': true, 'tfoot': true},
  14691. 'tr': {'tr': true}
  14692. },
  14693. doNotIndent: {"pre": true},
  14694. allowUnquoted: true,
  14695. allowMissing: true,
  14696. caseFold: true
  14697. }
  14698. var xmlConfig = {
  14699. autoSelfClosers: {},
  14700. implicitlyClosed: {},
  14701. contextGrabbers: {},
  14702. doNotIndent: {},
  14703. allowUnquoted: false,
  14704. allowMissing: false,
  14705. allowMissingTagName: false,
  14706. caseFold: false
  14707. }
  14708. CodeMirror.defineMode("xml", function(editorConf, config_) {
  14709. var indentUnit = editorConf.indentUnit
  14710. var config = {}
  14711. var defaults = config_.htmlMode ? htmlConfig : xmlConfig
  14712. for (var prop in defaults) config[prop] = defaults[prop]
  14713. for (var prop in config_) config[prop] = config_[prop]
  14714. // Return variables for tokenizers
  14715. var type, setStyle;
  14716. function inText(stream, state) {
  14717. function chain(parser) {
  14718. state.tokenize = parser;
  14719. return parser(stream, state);
  14720. }
  14721. var ch = stream.next();
  14722. if (ch == "<") {
  14723. if (stream.eat("!")) {
  14724. if (stream.eat("[")) {
  14725. if (stream.match("CDATA[")) return chain(inBlock("atom", "]]>"));
  14726. else return null;
  14727. } else if (stream.match("--")) {
  14728. return chain(inBlock("comment", "-->"));
  14729. } else if (stream.match("DOCTYPE", true, true)) {
  14730. stream.eatWhile(/[\w\._\-]/);
  14731. return chain(doctype(1));
  14732. } else {
  14733. return null;
  14734. }
  14735. } else if (stream.eat("?")) {
  14736. stream.eatWhile(/[\w\._\-]/);
  14737. state.tokenize = inBlock("meta", "?>");
  14738. return "meta";
  14739. } else {
  14740. type = stream.eat("/") ? "closeTag" : "openTag";
  14741. state.tokenize = inTag;
  14742. return "tag bracket";
  14743. }
  14744. } else if (ch == "&") {
  14745. var ok;
  14746. if (stream.eat("#")) {
  14747. if (stream.eat("x")) {
  14748. ok = stream.eatWhile(/[a-fA-F\d]/) && stream.eat(";");
  14749. } else {
  14750. ok = stream.eatWhile(/[\d]/) && stream.eat(";");
  14751. }
  14752. } else {
  14753. ok = stream.eatWhile(/[\w\.\-:]/) && stream.eat(";");
  14754. }
  14755. return ok ? "atom" : "error";
  14756. } else {
  14757. stream.eatWhile(/[^&<]/);
  14758. return null;
  14759. }
  14760. }
  14761. inText.isInText = true;
  14762. function inTag(stream, state) {
  14763. var ch = stream.next();
  14764. if (ch == ">" || (ch == "/" && stream.eat(">"))) {
  14765. state.tokenize = inText;
  14766. type = ch == ">" ? "endTag" : "selfcloseTag";
  14767. return "tag bracket";
  14768. } else if (ch == "=") {
  14769. type = "equals";
  14770. return null;
  14771. } else if (ch == "<") {
  14772. state.tokenize = inText;
  14773. state.state = baseState;
  14774. state.tagName = state.tagStart = null;
  14775. var next = state.tokenize(stream, state);
  14776. return next ? next + " tag error" : "tag error";
  14777. } else if (/[\'\"]/.test(ch)) {
  14778. state.tokenize = inAttribute(ch);
  14779. state.stringStartCol = stream.column();
  14780. return state.tokenize(stream, state);
  14781. } else {
  14782. stream.match(/^[^\s\u00a0=<>\"\']*[^\s\u00a0=<>\"\'\/]/);
  14783. return "word";
  14784. }
  14785. }
  14786. function inAttribute(quote) {
  14787. var closure = function(stream, state) {
  14788. while (!stream.eol()) {
  14789. if (stream.next() == quote) {
  14790. state.tokenize = inTag;
  14791. break;
  14792. }
  14793. }
  14794. return "string";
  14795. };
  14796. closure.isInAttribute = true;
  14797. return closure;
  14798. }
  14799. function inBlock(style, terminator) {
  14800. return function(stream, state) {
  14801. while (!stream.eol()) {
  14802. if (stream.match(terminator)) {
  14803. state.tokenize = inText;
  14804. break;
  14805. }
  14806. stream.next();
  14807. }
  14808. return style;
  14809. }
  14810. }
  14811. function doctype(depth) {
  14812. return function(stream, state) {
  14813. var ch;
  14814. while ((ch = stream.next()) != null) {
  14815. if (ch == "<") {
  14816. state.tokenize = doctype(depth + 1);
  14817. return state.tokenize(stream, state);
  14818. } else if (ch == ">") {
  14819. if (depth == 1) {
  14820. state.tokenize = inText;
  14821. break;
  14822. } else {
  14823. state.tokenize = doctype(depth - 1);
  14824. return state.tokenize(stream, state);
  14825. }
  14826. }
  14827. }
  14828. return "meta";
  14829. };
  14830. }
  14831. function Context(state, tagName, startOfLine) {
  14832. this.prev = state.context;
  14833. this.tagName = tagName;
  14834. this.indent = state.indented;
  14835. this.startOfLine = startOfLine;
  14836. if (config.doNotIndent.hasOwnProperty(tagName) || (state.context && state.context.noIndent))
  14837. this.noIndent = true;
  14838. }
  14839. function popContext(state) {
  14840. if (state.context) state.context = state.context.prev;
  14841. }
  14842. function maybePopContext(state, nextTagName) {
  14843. var parentTagName;
  14844. while (true) {
  14845. if (!state.context) {
  14846. return;
  14847. }
  14848. parentTagName = state.context.tagName;
  14849. if (!config.contextGrabbers.hasOwnProperty(parentTagName) ||
  14850. !config.contextGrabbers[parentTagName].hasOwnProperty(nextTagName)) {
  14851. return;
  14852. }
  14853. popContext(state);
  14854. }
  14855. }
  14856. function baseState(type, stream, state) {
  14857. if (type == "openTag") {
  14858. state.tagStart = stream.column();
  14859. return tagNameState;
  14860. } else if (type == "closeTag") {
  14861. return closeTagNameState;
  14862. } else {
  14863. return baseState;
  14864. }
  14865. }
  14866. function tagNameState(type, stream, state) {
  14867. if (type == "word") {
  14868. state.tagName = stream.current();
  14869. setStyle = "tag";
  14870. return attrState;
  14871. } else if (config.allowMissingTagName && type == "endTag") {
  14872. setStyle = "tag bracket";
  14873. return attrState(type, stream, state);
  14874. } else {
  14875. setStyle = "error";
  14876. return tagNameState;
  14877. }
  14878. }
  14879. function closeTagNameState(type, stream, state) {
  14880. if (type == "word") {
  14881. var tagName = stream.current();
  14882. if (state.context && state.context.tagName != tagName &&
  14883. config.implicitlyClosed.hasOwnProperty(state.context.tagName))
  14884. popContext(state);
  14885. if ((state.context && state.context.tagName == tagName) || config.matchClosing === false) {
  14886. setStyle = "tag";
  14887. return closeState;
  14888. } else {
  14889. setStyle = "tag error";
  14890. return closeStateErr;
  14891. }
  14892. } else if (config.allowMissingTagName && type == "endTag") {
  14893. setStyle = "tag bracket";
  14894. return closeState(type, stream, state);
  14895. } else {
  14896. setStyle = "error";
  14897. return closeStateErr;
  14898. }
  14899. }
  14900. function closeState(type, _stream, state) {
  14901. if (type != "endTag") {
  14902. setStyle = "error";
  14903. return closeState;
  14904. }
  14905. popContext(state);
  14906. return baseState;
  14907. }
  14908. function closeStateErr(type, stream, state) {
  14909. setStyle = "error";
  14910. return closeState(type, stream, state);
  14911. }
  14912. function attrState(type, _stream, state) {
  14913. if (type == "word") {
  14914. setStyle = "attribute";
  14915. return attrEqState;
  14916. } else if (type == "endTag" || type == "selfcloseTag") {
  14917. var tagName = state.tagName, tagStart = state.tagStart;
  14918. state.tagName = state.tagStart = null;
  14919. if (type == "selfcloseTag" ||
  14920. config.autoSelfClosers.hasOwnProperty(tagName)) {
  14921. maybePopContext(state, tagName);
  14922. } else {
  14923. maybePopContext(state, tagName);
  14924. state.context = new Context(state, tagName, tagStart == state.indented);
  14925. }
  14926. return baseState;
  14927. }
  14928. setStyle = "error";
  14929. return attrState;
  14930. }
  14931. function attrEqState(type, stream, state) {
  14932. if (type == "equals") return attrValueState;
  14933. if (!config.allowMissing) setStyle = "error";
  14934. return attrState(type, stream, state);
  14935. }
  14936. function attrValueState(type, stream, state) {
  14937. if (type == "string") return attrContinuedState;
  14938. if (type == "word" && config.allowUnquoted) {setStyle = "string"; return attrState;}
  14939. setStyle = "error";
  14940. return attrState(type, stream, state);
  14941. }
  14942. function attrContinuedState(type, stream, state) {
  14943. if (type == "string") return attrContinuedState;
  14944. return attrState(type, stream, state);
  14945. }
  14946. return {
  14947. startState: function(baseIndent) {
  14948. var state = {tokenize: inText,
  14949. state: baseState,
  14950. indented: baseIndent || 0,
  14951. tagName: null, tagStart: null,
  14952. context: null}
  14953. if (baseIndent != null) state.baseIndent = baseIndent
  14954. return state
  14955. },
  14956. token: function(stream, state) {
  14957. if (!state.tagName && stream.sol())
  14958. state.indented = stream.indentation();
  14959. if (stream.eatSpace()) return null;
  14960. type = null;
  14961. var style = state.tokenize(stream, state);
  14962. if ((style || type) && style != "comment") {
  14963. setStyle = null;
  14964. state.state = state.state(type || style, stream, state);
  14965. if (setStyle)
  14966. style = setStyle == "error" ? style + " error" : setStyle;
  14967. }
  14968. return style;
  14969. },
  14970. indent: function(state, textAfter, fullLine) {
  14971. var context = state.context;
  14972. // Indent multi-line strings (e.g. css).
  14973. if (state.tokenize.isInAttribute) {
  14974. if (state.tagStart == state.indented)
  14975. return state.stringStartCol + 1;
  14976. else
  14977. return state.indented + indentUnit;
  14978. }
  14979. if (context && context.noIndent) return CodeMirror.Pass;
  14980. if (state.tokenize != inTag && state.tokenize != inText)
  14981. return fullLine ? fullLine.match(/^(\s*)/)[0].length : 0;
  14982. // Indent the starts of attribute names.
  14983. if (state.tagName) {
  14984. if (config.multilineTagIndentPastTag !== false)
  14985. return state.tagStart + state.tagName.length + 2;
  14986. else
  14987. return state.tagStart + indentUnit * (config.multilineTagIndentFactor || 1);
  14988. }
  14989. if (config.alignCDATA && /<!\[CDATA\[/.test(textAfter)) return 0;
  14990. var tagAfter = textAfter && /^<(\/)?([\w_:\.-]*)/.exec(textAfter);
  14991. if (tagAfter && tagAfter[1]) { // Closing tag spotted
  14992. while (context) {
  14993. if (context.tagName == tagAfter[2]) {
  14994. context = context.prev;
  14995. break;
  14996. } else if (config.implicitlyClosed.hasOwnProperty(context.tagName)) {
  14997. context = context.prev;
  14998. } else {
  14999. break;
  15000. }
  15001. }
  15002. } else if (tagAfter) { // Opening tag spotted
  15003. while (context) {
  15004. var grabbers = config.contextGrabbers[context.tagName];
  15005. if (grabbers && grabbers.hasOwnProperty(tagAfter[2]))
  15006. context = context.prev;
  15007. else
  15008. break;
  15009. }
  15010. }
  15011. while (context && context.prev && !context.startOfLine)
  15012. context = context.prev;
  15013. if (context) return context.indent + indentUnit;
  15014. else return state.baseIndent || 0;
  15015. },
  15016. electricInput: /<\/[\s\w:]+>$/,
  15017. blockCommentStart: "<!--",
  15018. blockCommentEnd: "-->",
  15019. configuration: config.htmlMode ? "html" : "xml",
  15020. helperType: config.htmlMode ? "html" : "xml",
  15021. skipAttribute: function(state) {
  15022. if (state.state == attrValueState)
  15023. state.state = attrState
  15024. },
  15025. xmlCurrentTag: function(state) {
  15026. return state.tagName ? {name: state.tagName, close: state.type == "closeTag"} : null
  15027. },
  15028. xmlCurrentContext: function(state) {
  15029. var context = []
  15030. for (var cx = state.context; cx; cx = cx.prev)
  15031. if (cx.tagName) context.push(cx.tagName)
  15032. return context.reverse()
  15033. }
  15034. };
  15035. });
  15036. CodeMirror.defineMIME("text/xml", "xml");
  15037. CodeMirror.defineMIME("application/xml", "xml");
  15038. if (!CodeMirror.mimeModes.hasOwnProperty("text/html"))
  15039. CodeMirror.defineMIME("text/html", {name: "xml", htmlMode: true});
  15040. });
  15041. /***/ }),
  15042. /***/ "./node_modules/keymaster/keymaster.js":
  15043. /*!*********************************************!*\
  15044. !*** ./node_modules/keymaster/keymaster.js ***!
  15045. \*********************************************/
  15046. /*! no static exports found */
  15047. /***/ (function(module, exports, __webpack_require__) {
  15048. // keymaster.js
  15049. // (c) 2011-2013 Thomas Fuchs
  15050. // keymaster.js may be freely distributed under the MIT license.
  15051. ;(function(global){
  15052. var k,
  15053. _handlers = {},
  15054. _mods = { 16: false, 18: false, 17: false, 91: false },
  15055. _scope = 'all',
  15056. // modifier keys
  15057. _MODIFIERS = {
  15058. '⇧': 16, shift: 16,
  15059. '⌥': 18, alt: 18, option: 18,
  15060. '⌃': 17, ctrl: 17, control: 17,
  15061. '⌘': 91, command: 91
  15062. },
  15063. // special keys
  15064. _MAP = {
  15065. backspace: 8, tab: 9, clear: 12,
  15066. enter: 13, 'return': 13,
  15067. esc: 27, escape: 27, space: 32,
  15068. left: 37, up: 38,
  15069. right: 39, down: 40,
  15070. del: 46, 'delete': 46,
  15071. home: 36, end: 35,
  15072. pageup: 33, pagedown: 34,
  15073. ',': 188, '.': 190, '/': 191,
  15074. '`': 192, '-': 189, '=': 187,
  15075. ';': 186, '\'': 222,
  15076. '[': 219, ']': 221, '\\': 220
  15077. },
  15078. code = function(x){
  15079. return _MAP[x] || x.toUpperCase().charCodeAt(0);
  15080. },
  15081. _downKeys = [];
  15082. for(k=1;k<20;k++) _MAP['f'+k] = 111+k;
  15083. // IE doesn't support Array#indexOf, so have a simple replacement
  15084. function index(array, item){
  15085. var i = array.length;
  15086. while(i--) if(array[i]===item) return i;
  15087. return -1;
  15088. }
  15089. // for comparing mods before unassignment
  15090. function compareArray(a1, a2) {
  15091. if (a1.length != a2.length) return false;
  15092. for (var i = 0; i < a1.length; i++) {
  15093. if (a1[i] !== a2[i]) return false;
  15094. }
  15095. return true;
  15096. }
  15097. var modifierMap = {
  15098. 16:'shiftKey',
  15099. 18:'altKey',
  15100. 17:'ctrlKey',
  15101. 91:'metaKey'
  15102. };
  15103. function updateModifierKey(event) {
  15104. for(k in _mods) _mods[k] = event[modifierMap[k]];
  15105. };
  15106. // handle keydown event
  15107. function dispatch(event) {
  15108. var key, handler, k, i, modifiersMatch, scope;
  15109. key = event.keyCode;
  15110. if (index(_downKeys, key) == -1) {
  15111. _downKeys.push(key);
  15112. }
  15113. // if a modifier key, set the key.<modifierkeyname> property to true and return
  15114. if(key == 93 || key == 224) key = 91; // right command on webkit, command on Gecko
  15115. if(key in _mods) {
  15116. _mods[key] = true;
  15117. // 'assignKey' from inside this closure is exported to window.key
  15118. for(k in _MODIFIERS) if(_MODIFIERS[k] == key) assignKey[k] = true;
  15119. return;
  15120. }
  15121. updateModifierKey(event);
  15122. // see if we need to ignore the keypress (filter() can can be overridden)
  15123. // by default ignore key presses if a select, textarea, or input is focused
  15124. if(!assignKey.filter.call(this, event)) return;
  15125. // abort if no potentially matching shortcuts found
  15126. if (!(key in _handlers)) return;
  15127. scope = getScope();
  15128. // for each potential shortcut
  15129. for (i = 0; i < _handlers[key].length; i++) {
  15130. handler = _handlers[key][i];
  15131. // see if it's in the current scope
  15132. if(handler.scope == scope || handler.scope == 'all'){
  15133. // check if modifiers match if any
  15134. modifiersMatch = handler.mods.length > 0;
  15135. for(k in _mods)
  15136. if((!_mods[k] && index(handler.mods, +k) > -1) ||
  15137. (_mods[k] && index(handler.mods, +k) == -1)) modifiersMatch = false;
  15138. // call the handler and stop the event if neccessary
  15139. if((handler.mods.length == 0 && !_mods[16] && !_mods[18] && !_mods[17] && !_mods[91]) || modifiersMatch){
  15140. if(handler.method(event, handler)===false){
  15141. if(event.preventDefault) event.preventDefault();
  15142. else event.returnValue = false;
  15143. if(event.stopPropagation) event.stopPropagation();
  15144. if(event.cancelBubble) event.cancelBubble = true;
  15145. }
  15146. }
  15147. }
  15148. }
  15149. };
  15150. // unset modifier keys on keyup
  15151. function clearModifier(event){
  15152. var key = event.keyCode, k,
  15153. i = index(_downKeys, key);
  15154. // remove key from _downKeys
  15155. if (i >= 0) {
  15156. _downKeys.splice(i, 1);
  15157. }
  15158. if(key == 93 || key == 224) key = 91;
  15159. if(key in _mods) {
  15160. _mods[key] = false;
  15161. for(k in _MODIFIERS) if(_MODIFIERS[k] == key) assignKey[k] = false;
  15162. }
  15163. };
  15164. function resetModifiers() {
  15165. for(k in _mods) _mods[k] = false;
  15166. for(k in _MODIFIERS) assignKey[k] = false;
  15167. };
  15168. // parse and assign shortcut
  15169. function assignKey(key, scope, method){
  15170. var keys, mods;
  15171. keys = getKeys(key);
  15172. if (method === undefined) {
  15173. method = scope;
  15174. scope = 'all';
  15175. }
  15176. // for each shortcut
  15177. for (var i = 0; i < keys.length; i++) {
  15178. // set modifier keys if any
  15179. mods = [];
  15180. key = keys[i].split('+');
  15181. if (key.length > 1){
  15182. mods = getMods(key);
  15183. key = [key[key.length-1]];
  15184. }
  15185. // convert to keycode and...
  15186. key = key[0]
  15187. key = code(key);
  15188. // ...store handler
  15189. if (!(key in _handlers)) _handlers[key] = [];
  15190. _handlers[key].push({ shortcut: keys[i], scope: scope, method: method, key: keys[i], mods: mods });
  15191. }
  15192. };
  15193. // unbind all handlers for given key in current scope
  15194. function unbindKey(key, scope) {
  15195. var multipleKeys, keys,
  15196. mods = [],
  15197. i, j, obj;
  15198. multipleKeys = getKeys(key);
  15199. for (j = 0; j < multipleKeys.length; j++) {
  15200. keys = multipleKeys[j].split('+');
  15201. if (keys.length > 1) {
  15202. mods = getMods(keys);
  15203. key = keys[keys.length - 1];
  15204. }
  15205. key = code(key);
  15206. if (scope === undefined) {
  15207. scope = getScope();
  15208. }
  15209. if (!_handlers[key]) {
  15210. return;
  15211. }
  15212. for (i = 0; i < _handlers[key].length; i++) {
  15213. obj = _handlers[key][i];
  15214. // only clear handlers if correct scope and mods match
  15215. if (obj.scope === scope && compareArray(obj.mods, mods)) {
  15216. _handlers[key][i] = {};
  15217. }
  15218. }
  15219. }
  15220. };
  15221. // Returns true if the key with code 'keyCode' is currently down
  15222. // Converts strings into key codes.
  15223. function isPressed(keyCode) {
  15224. if (typeof(keyCode)=='string') {
  15225. keyCode = code(keyCode);
  15226. }
  15227. return index(_downKeys, keyCode) != -1;
  15228. }
  15229. function getPressedKeyCodes() {
  15230. return _downKeys.slice(0);
  15231. }
  15232. function filter(event){
  15233. var tagName = (event.target || event.srcElement).tagName;
  15234. // ignore keypressed in any elements that support keyboard data input
  15235. return !(tagName == 'INPUT' || tagName == 'SELECT' || tagName == 'TEXTAREA');
  15236. }
  15237. // initialize key.<modifier> to false
  15238. for(k in _MODIFIERS) assignKey[k] = false;
  15239. // set current scope (default 'all')
  15240. function setScope(scope){ _scope = scope || 'all' };
  15241. function getScope(){ return _scope || 'all' };
  15242. // delete all handlers for a given scope
  15243. function deleteScope(scope){
  15244. var key, handlers, i;
  15245. for (key in _handlers) {
  15246. handlers = _handlers[key];
  15247. for (i = 0; i < handlers.length; ) {
  15248. if (handlers[i].scope === scope) handlers.splice(i, 1);
  15249. else i++;
  15250. }
  15251. }
  15252. };
  15253. // abstract key logic for assign and unassign
  15254. function getKeys(key) {
  15255. var keys;
  15256. key = key.replace(/\s/g, '');
  15257. keys = key.split(',');
  15258. if ((keys[keys.length - 1]) == '') {
  15259. keys[keys.length - 2] += ',';
  15260. }
  15261. return keys;
  15262. }
  15263. // abstract mods logic for assign and unassign
  15264. function getMods(key) {
  15265. var mods = key.slice(0, key.length - 1);
  15266. for (var mi = 0; mi < mods.length; mi++)
  15267. mods[mi] = _MODIFIERS[mods[mi]];
  15268. return mods;
  15269. }
  15270. // cross-browser events
  15271. function addEvent(object, event, method) {
  15272. if (object.addEventListener)
  15273. object.addEventListener(event, method, false);
  15274. else if(object.attachEvent)
  15275. object.attachEvent('on'+event, function(){ method(window.event) });
  15276. };
  15277. // set the handlers globally on document
  15278. addEvent(document, 'keydown', function(event) { dispatch(event) }); // Passing _scope to a callback to ensure it remains the same by execution. Fixes #48
  15279. addEvent(document, 'keyup', clearModifier);
  15280. // reset modifiers to false whenever the window is (re)focused.
  15281. addEvent(window, 'focus', resetModifiers);
  15282. // store previously defined key
  15283. var previousKey = global.key;
  15284. // restore previously defined key and return reference to our key object
  15285. function noConflict() {
  15286. var k = global.key;
  15287. global.key = previousKey;
  15288. return k;
  15289. }
  15290. // set window.key and window.key.set/get/deleteScope, and the default filter
  15291. global.key = assignKey;
  15292. global.key.setScope = setScope;
  15293. global.key.getScope = getScope;
  15294. global.key.deleteScope = deleteScope;
  15295. global.key.filter = filter;
  15296. global.key.isPressed = isPressed;
  15297. global.key.getPressedKeyCodes = getPressedKeyCodes;
  15298. global.key.noConflict = noConflict;
  15299. global.key.unbind = unbindKey;
  15300. if(true) module.exports = assignKey;
  15301. })(this);
  15302. /***/ }),
  15303. /***/ "./node_modules/process/browser.js":
  15304. /*!*****************************************!*\
  15305. !*** ./node_modules/process/browser.js ***!
  15306. \*****************************************/
  15307. /*! no static exports found */
  15308. /***/ (function(module, exports) {
  15309. // shim for using process in browser
  15310. var process = module.exports = {};
  15311. // cached from whatever global is present so that test runners that stub it
  15312. // don't break things. But we need to wrap it in a try catch in case it is
  15313. // wrapped in strict mode code which doesn't define any globals. It's inside a
  15314. // function because try/catches deoptimize in certain engines.
  15315. var cachedSetTimeout;
  15316. var cachedClearTimeout;
  15317. function defaultSetTimout() {
  15318. throw new Error('setTimeout has not been defined');
  15319. }
  15320. function defaultClearTimeout () {
  15321. throw new Error('clearTimeout has not been defined');
  15322. }
  15323. (function () {
  15324. try {
  15325. if (typeof setTimeout === 'function') {
  15326. cachedSetTimeout = setTimeout;
  15327. } else {
  15328. cachedSetTimeout = defaultSetTimout;
  15329. }
  15330. } catch (e) {
  15331. cachedSetTimeout = defaultSetTimout;
  15332. }
  15333. try {
  15334. if (typeof clearTimeout === 'function') {
  15335. cachedClearTimeout = clearTimeout;
  15336. } else {
  15337. cachedClearTimeout = defaultClearTimeout;
  15338. }
  15339. } catch (e) {
  15340. cachedClearTimeout = defaultClearTimeout;
  15341. }
  15342. } ())
  15343. function runTimeout(fun) {
  15344. if (cachedSetTimeout === setTimeout) {
  15345. //normal enviroments in sane situations
  15346. return setTimeout(fun, 0);
  15347. }
  15348. // if setTimeout wasn't available but was latter defined
  15349. if ((cachedSetTimeout === defaultSetTimout || !cachedSetTimeout) && setTimeout) {
  15350. cachedSetTimeout = setTimeout;
  15351. return setTimeout(fun, 0);
  15352. }
  15353. try {
  15354. // when when somebody has screwed with setTimeout but no I.E. maddness
  15355. return cachedSetTimeout(fun, 0);
  15356. } catch(e){
  15357. try {
  15358. // When we are in I.E. but the script has been evaled so I.E. doesn't trust the global object when called normally
  15359. return cachedSetTimeout.call(null, fun, 0);
  15360. } catch(e){
  15361. // same as above but when it's a version of I.E. that must have the global object for 'this', hopfully our context correct otherwise it will throw a global error
  15362. return cachedSetTimeout.call(this, fun, 0);
  15363. }
  15364. }
  15365. }
  15366. function runClearTimeout(marker) {
  15367. if (cachedClearTimeout === clearTimeout) {
  15368. //normal enviroments in sane situations
  15369. return clearTimeout(marker);
  15370. }
  15371. // if clearTimeout wasn't available but was latter defined
  15372. if ((cachedClearTimeout === defaultClearTimeout || !cachedClearTimeout) && clearTimeout) {
  15373. cachedClearTimeout = clearTimeout;
  15374. return clearTimeout(marker);
  15375. }
  15376. try {
  15377. // when when somebody has screwed with setTimeout but no I.E. maddness
  15378. return cachedClearTimeout(marker);
  15379. } catch (e){
  15380. try {
  15381. // When we are in I.E. but the script has been evaled so I.E. doesn't trust the global object when called normally
  15382. return cachedClearTimeout.call(null, marker);
  15383. } catch (e){
  15384. // same as above but when it's a version of I.E. that must have the global object for 'this', hopfully our context correct otherwise it will throw a global error.
  15385. // Some versions of I.E. have different rules for clearTimeout vs setTimeout
  15386. return cachedClearTimeout.call(this, marker);
  15387. }
  15388. }
  15389. }
  15390. var queue = [];
  15391. var draining = false;
  15392. var currentQueue;
  15393. var queueIndex = -1;
  15394. function cleanUpNextTick() {
  15395. if (!draining || !currentQueue) {
  15396. return;
  15397. }
  15398. draining = false;
  15399. if (currentQueue.length) {
  15400. queue = currentQueue.concat(queue);
  15401. } else {
  15402. queueIndex = -1;
  15403. }
  15404. if (queue.length) {
  15405. drainQueue();
  15406. }
  15407. }
  15408. function drainQueue() {
  15409. if (draining) {
  15410. return;
  15411. }
  15412. var timeout = runTimeout(cleanUpNextTick);
  15413. draining = true;
  15414. var len = queue.length;
  15415. while(len) {
  15416. currentQueue = queue;
  15417. queue = [];
  15418. while (++queueIndex < len) {
  15419. if (currentQueue) {
  15420. currentQueue[queueIndex].run();
  15421. }
  15422. }
  15423. queueIndex = -1;
  15424. len = queue.length;
  15425. }
  15426. currentQueue = null;
  15427. draining = false;
  15428. runClearTimeout(timeout);
  15429. }
  15430. process.nextTick = function (fun) {
  15431. var args = new Array(arguments.length - 1);
  15432. if (arguments.length > 1) {
  15433. for (var i = 1; i < arguments.length; i++) {
  15434. args[i - 1] = arguments[i];
  15435. }
  15436. }
  15437. queue.push(new Item(fun, args));
  15438. if (queue.length === 1 && !draining) {
  15439. runTimeout(drainQueue);
  15440. }
  15441. };
  15442. // v8 likes predictible objects
  15443. function Item(fun, array) {
  15444. this.fun = fun;
  15445. this.array = array;
  15446. }
  15447. Item.prototype.run = function () {
  15448. this.fun.apply(null, this.array);
  15449. };
  15450. process.title = 'browser';
  15451. process.browser = true;
  15452. process.env = {};
  15453. process.argv = [];
  15454. process.version = ''; // empty string to avoid regexp issues
  15455. process.versions = {};
  15456. function noop() {}
  15457. process.on = noop;
  15458. process.addListener = noop;
  15459. process.once = noop;
  15460. process.off = noop;
  15461. process.removeListener = noop;
  15462. process.removeAllListeners = noop;
  15463. process.emit = noop;
  15464. process.prependListener = noop;
  15465. process.prependOnceListener = noop;
  15466. process.listeners = function (name) { return [] }
  15467. process.binding = function (name) {
  15468. throw new Error('process.binding is not supported');
  15469. };
  15470. process.cwd = function () { return '/' };
  15471. process.chdir = function (dir) {
  15472. throw new Error('process.chdir is not supported');
  15473. };
  15474. process.umask = function() { return 0; };
  15475. /***/ }),
  15476. /***/ "./node_modules/promise-polyfill/src/finally.js":
  15477. /*!******************************************************!*\
  15478. !*** ./node_modules/promise-polyfill/src/finally.js ***!
  15479. \******************************************************/
  15480. /*! exports provided: default */
  15481. /***/ (function(module, __webpack_exports__, __webpack_require__) {
  15482. "use strict";
  15483. __webpack_require__.r(__webpack_exports__);
  15484. /**
  15485. * @this {Promise}
  15486. */
  15487. function finallyConstructor(callback) {
  15488. var constructor = this.constructor;
  15489. return this.then(function (value) {
  15490. // @ts-ignore
  15491. return constructor.resolve(callback()).then(function () {
  15492. return value;
  15493. });
  15494. }, function (reason) {
  15495. // @ts-ignore
  15496. return constructor.resolve(callback()).then(function () {
  15497. // @ts-ignore
  15498. return constructor.reject(reason);
  15499. });
  15500. });
  15501. }
  15502. /* harmony default export */ __webpack_exports__["default"] = (finallyConstructor);
  15503. /***/ }),
  15504. /***/ "./node_modules/promise-polyfill/src/index.js":
  15505. /*!****************************************************!*\
  15506. !*** ./node_modules/promise-polyfill/src/index.js ***!
  15507. \****************************************************/
  15508. /*! exports provided: default */
  15509. /***/ (function(module, __webpack_exports__, __webpack_require__) {
  15510. "use strict";
  15511. __webpack_require__.r(__webpack_exports__);
  15512. /* WEBPACK VAR INJECTION */(function(setImmediate) {/* harmony import */ var _finally__WEBPACK_IMPORTED_MODULE_0__ = __webpack_require__(/*! ./finally */ "./node_modules/promise-polyfill/src/finally.js");
  15513. // Store setTimeout reference so promise-polyfill will be unaffected by
  15514. // other code modifying setTimeout (like sinon.useFakeTimers())
  15515. var setTimeoutFunc = setTimeout;
  15516. function isArray(x) {
  15517. return Boolean(x && typeof x.length !== 'undefined');
  15518. }
  15519. function noop() {} // Polyfill for Function.prototype.bind
  15520. function bind(fn, thisArg) {
  15521. return function () {
  15522. fn.apply(thisArg, arguments);
  15523. };
  15524. }
  15525. /**
  15526. * @constructor
  15527. * @param {Function} fn
  15528. */
  15529. function Promise(fn) {
  15530. if (!(this instanceof Promise)) throw new TypeError('Promises must be constructed via new');
  15531. if (typeof fn !== 'function') throw new TypeError('not a function');
  15532. /** @type {!number} */
  15533. this._state = 0;
  15534. /** @type {!boolean} */
  15535. this._handled = false;
  15536. /** @type {Promise|undefined} */
  15537. this._value = undefined;
  15538. /** @type {!Array<!Function>} */
  15539. this._deferreds = [];
  15540. doResolve(fn, this);
  15541. }
  15542. function handle(self, deferred) {
  15543. while (self._state === 3) {
  15544. self = self._value;
  15545. }
  15546. if (self._state === 0) {
  15547. self._deferreds.push(deferred);
  15548. return;
  15549. }
  15550. self._handled = true;
  15551. Promise._immediateFn(function () {
  15552. var cb = self._state === 1 ? deferred.onFulfilled : deferred.onRejected;
  15553. if (cb === null) {
  15554. (self._state === 1 ? resolve : reject)(deferred.promise, self._value);
  15555. return;
  15556. }
  15557. var ret;
  15558. try {
  15559. ret = cb(self._value);
  15560. } catch (e) {
  15561. reject(deferred.promise, e);
  15562. return;
  15563. }
  15564. resolve(deferred.promise, ret);
  15565. });
  15566. }
  15567. function resolve(self, newValue) {
  15568. try {
  15569. // Promise Resolution Procedure: https://github.com/promises-aplus/promises-spec#the-promise-resolution-procedure
  15570. if (newValue === self) throw new TypeError('A promise cannot be resolved with itself.');
  15571. if (newValue && (typeof newValue === 'object' || typeof newValue === 'function')) {
  15572. var then = newValue.then;
  15573. if (newValue instanceof Promise) {
  15574. self._state = 3;
  15575. self._value = newValue;
  15576. finale(self);
  15577. return;
  15578. } else if (typeof then === 'function') {
  15579. doResolve(bind(then, newValue), self);
  15580. return;
  15581. }
  15582. }
  15583. self._state = 1;
  15584. self._value = newValue;
  15585. finale(self);
  15586. } catch (e) {
  15587. reject(self, e);
  15588. }
  15589. }
  15590. function reject(self, newValue) {
  15591. self._state = 2;
  15592. self._value = newValue;
  15593. finale(self);
  15594. }
  15595. function finale(self) {
  15596. if (self._state === 2 && self._deferreds.length === 0) {
  15597. Promise._immediateFn(function () {
  15598. if (!self._handled) {
  15599. Promise._unhandledRejectionFn(self._value);
  15600. }
  15601. });
  15602. }
  15603. for (var i = 0, len = self._deferreds.length; i < len; i++) {
  15604. handle(self, self._deferreds[i]);
  15605. }
  15606. self._deferreds = null;
  15607. }
  15608. /**
  15609. * @constructor
  15610. */
  15611. function Handler(onFulfilled, onRejected, promise) {
  15612. this.onFulfilled = typeof onFulfilled === 'function' ? onFulfilled : null;
  15613. this.onRejected = typeof onRejected === 'function' ? onRejected : null;
  15614. this.promise = promise;
  15615. }
  15616. /**
  15617. * Take a potentially misbehaving resolver function and make sure
  15618. * onFulfilled and onRejected are only called once.
  15619. *
  15620. * Makes no guarantees about asynchrony.
  15621. */
  15622. function doResolve(fn, self) {
  15623. var done = false;
  15624. try {
  15625. fn(function (value) {
  15626. if (done) return;
  15627. done = true;
  15628. resolve(self, value);
  15629. }, function (reason) {
  15630. if (done) return;
  15631. done = true;
  15632. reject(self, reason);
  15633. });
  15634. } catch (ex) {
  15635. if (done) return;
  15636. done = true;
  15637. reject(self, ex);
  15638. }
  15639. }
  15640. Promise.prototype['catch'] = function (onRejected) {
  15641. return this.then(null, onRejected);
  15642. };
  15643. Promise.prototype.then = function (onFulfilled, onRejected) {
  15644. // @ts-ignore
  15645. var prom = new this.constructor(noop);
  15646. handle(this, new Handler(onFulfilled, onRejected, prom));
  15647. return prom;
  15648. };
  15649. Promise.prototype['finally'] = _finally__WEBPACK_IMPORTED_MODULE_0__["default"];
  15650. Promise.all = function (arr) {
  15651. return new Promise(function (resolve, reject) {
  15652. if (!isArray(arr)) {
  15653. return reject(new TypeError('Promise.all accepts an array'));
  15654. }
  15655. var args = Array.prototype.slice.call(arr);
  15656. if (args.length === 0) return resolve([]);
  15657. var remaining = args.length;
  15658. function res(i, val) {
  15659. try {
  15660. if (val && (typeof val === 'object' || typeof val === 'function')) {
  15661. var then = val.then;
  15662. if (typeof then === 'function') {
  15663. then.call(val, function (val) {
  15664. res(i, val);
  15665. }, reject);
  15666. return;
  15667. }
  15668. }
  15669. args[i] = val;
  15670. if (--remaining === 0) {
  15671. resolve(args);
  15672. }
  15673. } catch (ex) {
  15674. reject(ex);
  15675. }
  15676. }
  15677. for (var i = 0; i < args.length; i++) {
  15678. res(i, args[i]);
  15679. }
  15680. });
  15681. };
  15682. Promise.resolve = function (value) {
  15683. if (value && typeof value === 'object' && value.constructor === Promise) {
  15684. return value;
  15685. }
  15686. return new Promise(function (resolve) {
  15687. resolve(value);
  15688. });
  15689. };
  15690. Promise.reject = function (value) {
  15691. return new Promise(function (resolve, reject) {
  15692. reject(value);
  15693. });
  15694. };
  15695. Promise.race = function (arr) {
  15696. return new Promise(function (resolve, reject) {
  15697. if (!isArray(arr)) {
  15698. return reject(new TypeError('Promise.race accepts an array'));
  15699. }
  15700. for (var i = 0, len = arr.length; i < len; i++) {
  15701. Promise.resolve(arr[i]).then(resolve, reject);
  15702. }
  15703. });
  15704. }; // Use polyfill for setImmediate for performance gains
  15705. Promise._immediateFn = // @ts-ignore
  15706. typeof setImmediate === 'function' && function (fn) {
  15707. // @ts-ignore
  15708. setImmediate(fn);
  15709. } || function (fn) {
  15710. setTimeoutFunc(fn, 0);
  15711. };
  15712. Promise._unhandledRejectionFn = function _unhandledRejectionFn(err) {
  15713. if (typeof console !== 'undefined' && console) {
  15714. console.warn('Possible Unhandled Promise Rejection:', err); // eslint-disable-line no-console
  15715. }
  15716. };
  15717. /* harmony default export */ __webpack_exports__["default"] = (Promise);
  15718. /* WEBPACK VAR INJECTION */}.call(this, __webpack_require__(/*! ./../../timers-browserify/main.js */ "./node_modules/timers-browserify/main.js").setImmediate))
  15719. /***/ }),
  15720. /***/ "./node_modules/setimmediate/setImmediate.js":
  15721. /*!***************************************************!*\
  15722. !*** ./node_modules/setimmediate/setImmediate.js ***!
  15723. \***************************************************/
  15724. /*! no static exports found */
  15725. /***/ (function(module, exports, __webpack_require__) {
  15726. /* WEBPACK VAR INJECTION */(function(global, process) {(function (global, undefined) {
  15727. "use strict";
  15728. if (global.setImmediate) {
  15729. return;
  15730. }
  15731. var nextHandle = 1; // Spec says greater than zero
  15732. var tasksByHandle = {};
  15733. var currentlyRunningATask = false;
  15734. var doc = global.document;
  15735. var registerImmediate;
  15736. function setImmediate(callback) {
  15737. // Callback can either be a function or a string
  15738. if (typeof callback !== "function") {
  15739. callback = new Function("" + callback);
  15740. }
  15741. // Copy function arguments
  15742. var args = new Array(arguments.length - 1);
  15743. for (var i = 0; i < args.length; i++) {
  15744. args[i] = arguments[i + 1];
  15745. }
  15746. // Store and register the task
  15747. var task = { callback: callback, args: args };
  15748. tasksByHandle[nextHandle] = task;
  15749. registerImmediate(nextHandle);
  15750. return nextHandle++;
  15751. }
  15752. function clearImmediate(handle) {
  15753. delete tasksByHandle[handle];
  15754. }
  15755. function run(task) {
  15756. var callback = task.callback;
  15757. var args = task.args;
  15758. switch (args.length) {
  15759. case 0:
  15760. callback();
  15761. break;
  15762. case 1:
  15763. callback(args[0]);
  15764. break;
  15765. case 2:
  15766. callback(args[0], args[1]);
  15767. break;
  15768. case 3:
  15769. callback(args[0], args[1], args[2]);
  15770. break;
  15771. default:
  15772. callback.apply(undefined, args);
  15773. break;
  15774. }
  15775. }
  15776. function runIfPresent(handle) {
  15777. // From the spec: "Wait until any invocations of this algorithm started before this one have completed."
  15778. // So if we're currently running a task, we'll need to delay this invocation.
  15779. if (currentlyRunningATask) {
  15780. // Delay by doing a setTimeout. setImmediate was tried instead, but in Firefox 7 it generated a
  15781. // "too much recursion" error.
  15782. setTimeout(runIfPresent, 0, handle);
  15783. } else {
  15784. var task = tasksByHandle[handle];
  15785. if (task) {
  15786. currentlyRunningATask = true;
  15787. try {
  15788. run(task);
  15789. } finally {
  15790. clearImmediate(handle);
  15791. currentlyRunningATask = false;
  15792. }
  15793. }
  15794. }
  15795. }
  15796. function installNextTickImplementation() {
  15797. registerImmediate = function(handle) {
  15798. process.nextTick(function () { runIfPresent(handle); });
  15799. };
  15800. }
  15801. function canUsePostMessage() {
  15802. // The test against `importScripts` prevents this implementation from being installed inside a web worker,
  15803. // where `global.postMessage` means something completely different and can't be used for this purpose.
  15804. if (global.postMessage && !global.importScripts) {
  15805. var postMessageIsAsynchronous = true;
  15806. var oldOnMessage = global.onmessage;
  15807. global.onmessage = function() {
  15808. postMessageIsAsynchronous = false;
  15809. };
  15810. global.postMessage("", "*");
  15811. global.onmessage = oldOnMessage;
  15812. return postMessageIsAsynchronous;
  15813. }
  15814. }
  15815. function installPostMessageImplementation() {
  15816. // Installs an event handler on `global` for the `message` event: see
  15817. // * https://developer.mozilla.org/en/DOM/window.postMessage
  15818. // * http://www.whatwg.org/specs/web-apps/current-work/multipage/comms.html#crossDocumentMessages
  15819. var messagePrefix = "setImmediate$" + Math.random() + "$";
  15820. var onGlobalMessage = function(event) {
  15821. if (event.source === global &&
  15822. typeof event.data === "string" &&
  15823. event.data.indexOf(messagePrefix) === 0) {
  15824. runIfPresent(+event.data.slice(messagePrefix.length));
  15825. }
  15826. };
  15827. if (global.addEventListener) {
  15828. global.addEventListener("message", onGlobalMessage, false);
  15829. } else {
  15830. global.attachEvent("onmessage", onGlobalMessage);
  15831. }
  15832. registerImmediate = function(handle) {
  15833. global.postMessage(messagePrefix + handle, "*");
  15834. };
  15835. }
  15836. function installMessageChannelImplementation() {
  15837. var channel = new MessageChannel();
  15838. channel.port1.onmessage = function(event) {
  15839. var handle = event.data;
  15840. runIfPresent(handle);
  15841. };
  15842. registerImmediate = function(handle) {
  15843. channel.port2.postMessage(handle);
  15844. };
  15845. }
  15846. function installReadyStateChangeImplementation() {
  15847. var html = doc.documentElement;
  15848. registerImmediate = function(handle) {
  15849. // Create a <script> element; its readystatechange event will be fired asynchronously once it is inserted
  15850. // into the document. Do so, thus queuing up the task. Remember to clean up once it's been called.
  15851. var script = doc.createElement("script");
  15852. script.onreadystatechange = function () {
  15853. runIfPresent(handle);
  15854. script.onreadystatechange = null;
  15855. html.removeChild(script);
  15856. script = null;
  15857. };
  15858. html.appendChild(script);
  15859. };
  15860. }
  15861. function installSetTimeoutImplementation() {
  15862. registerImmediate = function(handle) {
  15863. setTimeout(runIfPresent, 0, handle);
  15864. };
  15865. }
  15866. // If supported, we should attach to the prototype of global, since that is where setTimeout et al. live.
  15867. var attachTo = Object.getPrototypeOf && Object.getPrototypeOf(global);
  15868. attachTo = attachTo && attachTo.setTimeout ? attachTo : global;
  15869. // Don't get fooled by e.g. browserify environments.
  15870. if ({}.toString.call(global.process) === "[object process]") {
  15871. // For Node.js before 0.9
  15872. installNextTickImplementation();
  15873. } else if (canUsePostMessage()) {
  15874. // For non-IE10 modern browsers
  15875. installPostMessageImplementation();
  15876. } else if (global.MessageChannel) {
  15877. // For web workers, where supported
  15878. installMessageChannelImplementation();
  15879. } else if (doc && "onreadystatechange" in doc.createElement("script")) {
  15880. // For IE 6–8
  15881. installReadyStateChangeImplementation();
  15882. } else {
  15883. // For older browsers
  15884. installSetTimeoutImplementation();
  15885. }
  15886. attachTo.setImmediate = setImmediate;
  15887. attachTo.clearImmediate = clearImmediate;
  15888. }(typeof self === "undefined" ? typeof global === "undefined" ? this : global : self));
  15889. /* WEBPACK VAR INJECTION */}.call(this, __webpack_require__(/*! ./../webpack/buildin/global.js */ "./node_modules/webpack/buildin/global.js"), __webpack_require__(/*! ./../process/browser.js */ "./node_modules/process/browser.js")))
  15890. /***/ }),
  15891. /***/ "./node_modules/timers-browserify/main.js":
  15892. /*!************************************************!*\
  15893. !*** ./node_modules/timers-browserify/main.js ***!
  15894. \************************************************/
  15895. /*! no static exports found */
  15896. /***/ (function(module, exports, __webpack_require__) {
  15897. /* WEBPACK VAR INJECTION */(function(global) {var scope = (typeof global !== "undefined" && global) ||
  15898. (typeof self !== "undefined" && self) ||
  15899. window;
  15900. var apply = Function.prototype.apply;
  15901. // DOM APIs, for completeness
  15902. exports.setTimeout = function() {
  15903. return new Timeout(apply.call(setTimeout, scope, arguments), clearTimeout);
  15904. };
  15905. exports.setInterval = function() {
  15906. return new Timeout(apply.call(setInterval, scope, arguments), clearInterval);
  15907. };
  15908. exports.clearTimeout =
  15909. exports.clearInterval = function(timeout) {
  15910. if (timeout) {
  15911. timeout.close();
  15912. }
  15913. };
  15914. function Timeout(id, clearFn) {
  15915. this._id = id;
  15916. this._clearFn = clearFn;
  15917. }
  15918. Timeout.prototype.unref = Timeout.prototype.ref = function() {};
  15919. Timeout.prototype.close = function() {
  15920. this._clearFn.call(scope, this._id);
  15921. };
  15922. // Does not start the time, just sets up the members needed.
  15923. exports.enroll = function(item, msecs) {
  15924. clearTimeout(item._idleTimeoutId);
  15925. item._idleTimeout = msecs;
  15926. };
  15927. exports.unenroll = function(item) {
  15928. clearTimeout(item._idleTimeoutId);
  15929. item._idleTimeout = -1;
  15930. };
  15931. exports._unrefActive = exports.active = function(item) {
  15932. clearTimeout(item._idleTimeoutId);
  15933. var msecs = item._idleTimeout;
  15934. if (msecs >= 0) {
  15935. item._idleTimeoutId = setTimeout(function onTimeout() {
  15936. if (item._onTimeout)
  15937. item._onTimeout();
  15938. }, msecs);
  15939. }
  15940. };
  15941. // setimmediate attaches itself to the global object
  15942. __webpack_require__(/*! setimmediate */ "./node_modules/setimmediate/setImmediate.js");
  15943. // On some exotic environments, it's not clear which object `setimmediate` was
  15944. // able to install onto. Search each possibility in the same order as the
  15945. // `setimmediate` library.
  15946. exports.setImmediate = (typeof self !== "undefined" && self.setImmediate) ||
  15947. (typeof global !== "undefined" && global.setImmediate) ||
  15948. (this && this.setImmediate);
  15949. exports.clearImmediate = (typeof self !== "undefined" && self.clearImmediate) ||
  15950. (typeof global !== "undefined" && global.clearImmediate) ||
  15951. (this && this.clearImmediate);
  15952. /* WEBPACK VAR INJECTION */}.call(this, __webpack_require__(/*! ./../webpack/buildin/global.js */ "./node_modules/webpack/buildin/global.js")))
  15953. /***/ }),
  15954. /***/ "./node_modules/underscore/underscore.js":
  15955. /*!***********************************************!*\
  15956. !*** ./node_modules/underscore/underscore.js ***!
  15957. \***********************************************/
  15958. /*! no static exports found */
  15959. /***/ (function(module, exports, __webpack_require__) {
  15960. /* WEBPACK VAR INJECTION */(function(global, module) {var __WEBPACK_AMD_DEFINE_ARRAY__, __WEBPACK_AMD_DEFINE_RESULT__;// Underscore.js 1.9.1
  15961. // http://underscorejs.org
  15962. // (c) 2009-2018 Jeremy Ashkenas, DocumentCloud and Investigative Reporters & Editors
  15963. // Underscore may be freely distributed under the MIT license.
  15964. (function() {
  15965. // Baseline setup
  15966. // --------------
  15967. // Establish the root object, `window` (`self`) in the browser, `global`
  15968. // on the server, or `this` in some virtual machines. We use `self`
  15969. // instead of `window` for `WebWorker` support.
  15970. var root = typeof self == 'object' && self.self === self && self ||
  15971. typeof global == 'object' && global.global === global && global ||
  15972. this ||
  15973. {};
  15974. // Save the previous value of the `_` variable.
  15975. var previousUnderscore = root._;
  15976. // Save bytes in the minified (but not gzipped) version:
  15977. var ArrayProto = Array.prototype, ObjProto = Object.prototype;
  15978. var SymbolProto = typeof Symbol !== 'undefined' ? Symbol.prototype : null;
  15979. // Create quick reference variables for speed access to core prototypes.
  15980. var push = ArrayProto.push,
  15981. slice = ArrayProto.slice,
  15982. toString = ObjProto.toString,
  15983. hasOwnProperty = ObjProto.hasOwnProperty;
  15984. // All **ECMAScript 5** native function implementations that we hope to use
  15985. // are declared here.
  15986. var nativeIsArray = Array.isArray,
  15987. nativeKeys = Object.keys,
  15988. nativeCreate = Object.create;
  15989. // Naked function reference for surrogate-prototype-swapping.
  15990. var Ctor = function(){};
  15991. // Create a safe reference to the Underscore object for use below.
  15992. var _ = function(obj) {
  15993. if (obj instanceof _) return obj;
  15994. if (!(this instanceof _)) return new _(obj);
  15995. this._wrapped = obj;
  15996. };
  15997. // Export the Underscore object for **Node.js**, with
  15998. // backwards-compatibility for their old module API. If we're in
  15999. // the browser, add `_` as a global object.
  16000. // (`nodeType` is checked to ensure that `module`
  16001. // and `exports` are not HTML elements.)
  16002. if ( true && !exports.nodeType) {
  16003. if ( true && !module.nodeType && module.exports) {
  16004. exports = module.exports = _;
  16005. }
  16006. exports._ = _;
  16007. } else {
  16008. root._ = _;
  16009. }
  16010. // Current version.
  16011. _.VERSION = '1.9.1';
  16012. // Internal function that returns an efficient (for current engines) version
  16013. // of the passed-in callback, to be repeatedly applied in other Underscore
  16014. // functions.
  16015. var optimizeCb = function(func, context, argCount) {
  16016. if (context === void 0) return func;
  16017. switch (argCount == null ? 3 : argCount) {
  16018. case 1: return function(value) {
  16019. return func.call(context, value);
  16020. };
  16021. // The 2-argument case is omitted because we’re not using it.
  16022. case 3: return function(value, index, collection) {
  16023. return func.call(context, value, index, collection);
  16024. };
  16025. case 4: return function(accumulator, value, index, collection) {
  16026. return func.call(context, accumulator, value, index, collection);
  16027. };
  16028. }
  16029. return function() {
  16030. return func.apply(context, arguments);
  16031. };
  16032. };
  16033. var builtinIteratee;
  16034. // An internal function to generate callbacks that can be applied to each
  16035. // element in a collection, returning the desired result — either `identity`,
  16036. // an arbitrary callback, a property matcher, or a property accessor.
  16037. var cb = function(value, context, argCount) {
  16038. if (_.iteratee !== builtinIteratee) return _.iteratee(value, context);
  16039. if (value == null) return _.identity;
  16040. if (_.isFunction(value)) return optimizeCb(value, context, argCount);
  16041. if (_.isObject(value) && !_.isArray(value)) return _.matcher(value);
  16042. return _.property(value);
  16043. };
  16044. // External wrapper for our callback generator. Users may customize
  16045. // `_.iteratee` if they want additional predicate/iteratee shorthand styles.
  16046. // This abstraction hides the internal-only argCount argument.
  16047. _.iteratee = builtinIteratee = function(value, context) {
  16048. return cb(value, context, Infinity);
  16049. };
  16050. // Some functions take a variable number of arguments, or a few expected
  16051. // arguments at the beginning and then a variable number of values to operate
  16052. // on. This helper accumulates all remaining arguments past the function’s
  16053. // argument length (or an explicit `startIndex`), into an array that becomes
  16054. // the last argument. Similar to ES6’s "rest parameter".
  16055. var restArguments = function(func, startIndex) {
  16056. startIndex = startIndex == null ? func.length - 1 : +startIndex;
  16057. return function() {
  16058. var length = Math.max(arguments.length - startIndex, 0),
  16059. rest = Array(length),
  16060. index = 0;
  16061. for (; index < length; index++) {
  16062. rest[index] = arguments[index + startIndex];
  16063. }
  16064. switch (startIndex) {
  16065. case 0: return func.call(this, rest);
  16066. case 1: return func.call(this, arguments[0], rest);
  16067. case 2: return func.call(this, arguments[0], arguments[1], rest);
  16068. }
  16069. var args = Array(startIndex + 1);
  16070. for (index = 0; index < startIndex; index++) {
  16071. args[index] = arguments[index];
  16072. }
  16073. args[startIndex] = rest;
  16074. return func.apply(this, args);
  16075. };
  16076. };
  16077. // An internal function for creating a new object that inherits from another.
  16078. var baseCreate = function(prototype) {
  16079. if (!_.isObject(prototype)) return {};
  16080. if (nativeCreate) return nativeCreate(prototype);
  16081. Ctor.prototype = prototype;
  16082. var result = new Ctor;
  16083. Ctor.prototype = null;
  16084. return result;
  16085. };
  16086. var shallowProperty = function(key) {
  16087. return function(obj) {
  16088. return obj == null ? void 0 : obj[key];
  16089. };
  16090. };
  16091. var has = function(obj, path) {
  16092. return obj != null && hasOwnProperty.call(obj, path);
  16093. }
  16094. var deepGet = function(obj, path) {
  16095. var length = path.length;
  16096. for (var i = 0; i < length; i++) {
  16097. if (obj == null) return void 0;
  16098. obj = obj[path[i]];
  16099. }
  16100. return length ? obj : void 0;
  16101. };
  16102. // Helper for collection methods to determine whether a collection
  16103. // should be iterated as an array or as an object.
  16104. // Related: http://people.mozilla.org/~jorendorff/es6-draft.html#sec-tolength
  16105. // Avoids a very nasty iOS 8 JIT bug on ARM-64. #2094
  16106. var MAX_ARRAY_INDEX = Math.pow(2, 53) - 1;
  16107. var getLength = shallowProperty('length');
  16108. var isArrayLike = function(collection) {
  16109. var length = getLength(collection);
  16110. return typeof length == 'number' && length >= 0 && length <= MAX_ARRAY_INDEX;
  16111. };
  16112. // Collection Functions
  16113. // --------------------
  16114. // The cornerstone, an `each` implementation, aka `forEach`.
  16115. // Handles raw objects in addition to array-likes. Treats all
  16116. // sparse array-likes as if they were dense.
  16117. _.each = _.forEach = function(obj, iteratee, context) {
  16118. iteratee = optimizeCb(iteratee, context);
  16119. var i, length;
  16120. if (isArrayLike(obj)) {
  16121. for (i = 0, length = obj.length; i < length; i++) {
  16122. iteratee(obj[i], i, obj);
  16123. }
  16124. } else {
  16125. var keys = _.keys(obj);
  16126. for (i = 0, length = keys.length; i < length; i++) {
  16127. iteratee(obj[keys[i]], keys[i], obj);
  16128. }
  16129. }
  16130. return obj;
  16131. };
  16132. // Return the results of applying the iteratee to each element.
  16133. _.map = _.collect = function(obj, iteratee, context) {
  16134. iteratee = cb(iteratee, context);
  16135. var keys = !isArrayLike(obj) && _.keys(obj),
  16136. length = (keys || obj).length,
  16137. results = Array(length);
  16138. for (var index = 0; index < length; index++) {
  16139. var currentKey = keys ? keys[index] : index;
  16140. results[index] = iteratee(obj[currentKey], currentKey, obj);
  16141. }
  16142. return results;
  16143. };
  16144. // Create a reducing function iterating left or right.
  16145. var createReduce = function(dir) {
  16146. // Wrap code that reassigns argument variables in a separate function than
  16147. // the one that accesses `arguments.length` to avoid a perf hit. (#1991)
  16148. var reducer = function(obj, iteratee, memo, initial) {
  16149. var keys = !isArrayLike(obj) && _.keys(obj),
  16150. length = (keys || obj).length,
  16151. index = dir > 0 ? 0 : length - 1;
  16152. if (!initial) {
  16153. memo = obj[keys ? keys[index] : index];
  16154. index += dir;
  16155. }
  16156. for (; index >= 0 && index < length; index += dir) {
  16157. var currentKey = keys ? keys[index] : index;
  16158. memo = iteratee(memo, obj[currentKey], currentKey, obj);
  16159. }
  16160. return memo;
  16161. };
  16162. return function(obj, iteratee, memo, context) {
  16163. var initial = arguments.length >= 3;
  16164. return reducer(obj, optimizeCb(iteratee, context, 4), memo, initial);
  16165. };
  16166. };
  16167. // **Reduce** builds up a single result from a list of values, aka `inject`,
  16168. // or `foldl`.
  16169. _.reduce = _.foldl = _.inject = createReduce(1);
  16170. // The right-associative version of reduce, also known as `foldr`.
  16171. _.reduceRight = _.foldr = createReduce(-1);
  16172. // Return the first value which passes a truth test. Aliased as `detect`.
  16173. _.find = _.detect = function(obj, predicate, context) {
  16174. var keyFinder = isArrayLike(obj) ? _.findIndex : _.findKey;
  16175. var key = keyFinder(obj, predicate, context);
  16176. if (key !== void 0 && key !== -1) return obj[key];
  16177. };
  16178. // Return all the elements that pass a truth test.
  16179. // Aliased as `select`.
  16180. _.filter = _.select = function(obj, predicate, context) {
  16181. var results = [];
  16182. predicate = cb(predicate, context);
  16183. _.each(obj, function(value, index, list) {
  16184. if (predicate(value, index, list)) results.push(value);
  16185. });
  16186. return results;
  16187. };
  16188. // Return all the elements for which a truth test fails.
  16189. _.reject = function(obj, predicate, context) {
  16190. return _.filter(obj, _.negate(cb(predicate)), context);
  16191. };
  16192. // Determine whether all of the elements match a truth test.
  16193. // Aliased as `all`.
  16194. _.every = _.all = function(obj, predicate, context) {
  16195. predicate = cb(predicate, context);
  16196. var keys = !isArrayLike(obj) && _.keys(obj),
  16197. length = (keys || obj).length;
  16198. for (var index = 0; index < length; index++) {
  16199. var currentKey = keys ? keys[index] : index;
  16200. if (!predicate(obj[currentKey], currentKey, obj)) return false;
  16201. }
  16202. return true;
  16203. };
  16204. // Determine if at least one element in the object matches a truth test.
  16205. // Aliased as `any`.
  16206. _.some = _.any = function(obj, predicate, context) {
  16207. predicate = cb(predicate, context);
  16208. var keys = !isArrayLike(obj) && _.keys(obj),
  16209. length = (keys || obj).length;
  16210. for (var index = 0; index < length; index++) {
  16211. var currentKey = keys ? keys[index] : index;
  16212. if (predicate(obj[currentKey], currentKey, obj)) return true;
  16213. }
  16214. return false;
  16215. };
  16216. // Determine if the array or object contains a given item (using `===`).
  16217. // Aliased as `includes` and `include`.
  16218. _.contains = _.includes = _.include = function(obj, item, fromIndex, guard) {
  16219. if (!isArrayLike(obj)) obj = _.values(obj);
  16220. if (typeof fromIndex != 'number' || guard) fromIndex = 0;
  16221. return _.indexOf(obj, item, fromIndex) >= 0;
  16222. };
  16223. // Invoke a method (with arguments) on every item in a collection.
  16224. _.invoke = restArguments(function(obj, path, args) {
  16225. var contextPath, func;
  16226. if (_.isFunction(path)) {
  16227. func = path;
  16228. } else if (_.isArray(path)) {
  16229. contextPath = path.slice(0, -1);
  16230. path = path[path.length - 1];
  16231. }
  16232. return _.map(obj, function(context) {
  16233. var method = func;
  16234. if (!method) {
  16235. if (contextPath && contextPath.length) {
  16236. context = deepGet(context, contextPath);
  16237. }
  16238. if (context == null) return void 0;
  16239. method = context[path];
  16240. }
  16241. return method == null ? method : method.apply(context, args);
  16242. });
  16243. });
  16244. // Convenience version of a common use case of `map`: fetching a property.
  16245. _.pluck = function(obj, key) {
  16246. return _.map(obj, _.property(key));
  16247. };
  16248. // Convenience version of a common use case of `filter`: selecting only objects
  16249. // containing specific `key:value` pairs.
  16250. _.where = function(obj, attrs) {
  16251. return _.filter(obj, _.matcher(attrs));
  16252. };
  16253. // Convenience version of a common use case of `find`: getting the first object
  16254. // containing specific `key:value` pairs.
  16255. _.findWhere = function(obj, attrs) {
  16256. return _.find(obj, _.matcher(attrs));
  16257. };
  16258. // Return the maximum element (or element-based computation).
  16259. _.max = function(obj, iteratee, context) {
  16260. var result = -Infinity, lastComputed = -Infinity,
  16261. value, computed;
  16262. if (iteratee == null || typeof iteratee == 'number' && typeof obj[0] != 'object' && obj != null) {
  16263. obj = isArrayLike(obj) ? obj : _.values(obj);
  16264. for (var i = 0, length = obj.length; i < length; i++) {
  16265. value = obj[i];
  16266. if (value != null && value > result) {
  16267. result = value;
  16268. }
  16269. }
  16270. } else {
  16271. iteratee = cb(iteratee, context);
  16272. _.each(obj, function(v, index, list) {
  16273. computed = iteratee(v, index, list);
  16274. if (computed > lastComputed || computed === -Infinity && result === -Infinity) {
  16275. result = v;
  16276. lastComputed = computed;
  16277. }
  16278. });
  16279. }
  16280. return result;
  16281. };
  16282. // Return the minimum element (or element-based computation).
  16283. _.min = function(obj, iteratee, context) {
  16284. var result = Infinity, lastComputed = Infinity,
  16285. value, computed;
  16286. if (iteratee == null || typeof iteratee == 'number' && typeof obj[0] != 'object' && obj != null) {
  16287. obj = isArrayLike(obj) ? obj : _.values(obj);
  16288. for (var i = 0, length = obj.length; i < length; i++) {
  16289. value = obj[i];
  16290. if (value != null && value < result) {
  16291. result = value;
  16292. }
  16293. }
  16294. } else {
  16295. iteratee = cb(iteratee, context);
  16296. _.each(obj, function(v, index, list) {
  16297. computed = iteratee(v, index, list);
  16298. if (computed < lastComputed || computed === Infinity && result === Infinity) {
  16299. result = v;
  16300. lastComputed = computed;
  16301. }
  16302. });
  16303. }
  16304. return result;
  16305. };
  16306. // Shuffle a collection.
  16307. _.shuffle = function(obj) {
  16308. return _.sample(obj, Infinity);
  16309. };
  16310. // Sample **n** random values from a collection using the modern version of the
  16311. // [Fisher-Yates shuffle](http://en.wikipedia.org/wiki/Fisher–Yates_shuffle).
  16312. // If **n** is not specified, returns a single random element.
  16313. // The internal `guard` argument allows it to work with `map`.
  16314. _.sample = function(obj, n, guard) {
  16315. if (n == null || guard) {
  16316. if (!isArrayLike(obj)) obj = _.values(obj);
  16317. return obj[_.random(obj.length - 1)];
  16318. }
  16319. var sample = isArrayLike(obj) ? _.clone(obj) : _.values(obj);
  16320. var length = getLength(sample);
  16321. n = Math.max(Math.min(n, length), 0);
  16322. var last = length - 1;
  16323. for (var index = 0; index < n; index++) {
  16324. var rand = _.random(index, last);
  16325. var temp = sample[index];
  16326. sample[index] = sample[rand];
  16327. sample[rand] = temp;
  16328. }
  16329. return sample.slice(0, n);
  16330. };
  16331. // Sort the object's values by a criterion produced by an iteratee.
  16332. _.sortBy = function(obj, iteratee, context) {
  16333. var index = 0;
  16334. iteratee = cb(iteratee, context);
  16335. return _.pluck(_.map(obj, function(value, key, list) {
  16336. return {
  16337. value: value,
  16338. index: index++,
  16339. criteria: iteratee(value, key, list)
  16340. };
  16341. }).sort(function(left, right) {
  16342. var a = left.criteria;
  16343. var b = right.criteria;
  16344. if (a !== b) {
  16345. if (a > b || a === void 0) return 1;
  16346. if (a < b || b === void 0) return -1;
  16347. }
  16348. return left.index - right.index;
  16349. }), 'value');
  16350. };
  16351. // An internal function used for aggregate "group by" operations.
  16352. var group = function(behavior, partition) {
  16353. return function(obj, iteratee, context) {
  16354. var result = partition ? [[], []] : {};
  16355. iteratee = cb(iteratee, context);
  16356. _.each(obj, function(value, index) {
  16357. var key = iteratee(value, index, obj);
  16358. behavior(result, value, key);
  16359. });
  16360. return result;
  16361. };
  16362. };
  16363. // Groups the object's values by a criterion. Pass either a string attribute
  16364. // to group by, or a function that returns the criterion.
  16365. _.groupBy = group(function(result, value, key) {
  16366. if (has(result, key)) result[key].push(value); else result[key] = [value];
  16367. });
  16368. // Indexes the object's values by a criterion, similar to `groupBy`, but for
  16369. // when you know that your index values will be unique.
  16370. _.indexBy = group(function(result, value, key) {
  16371. result[key] = value;
  16372. });
  16373. // Counts instances of an object that group by a certain criterion. Pass
  16374. // either a string attribute to count by, or a function that returns the
  16375. // criterion.
  16376. _.countBy = group(function(result, value, key) {
  16377. if (has(result, key)) result[key]++; else result[key] = 1;
  16378. });
  16379. var reStrSymbol = /[^\ud800-\udfff]|[\ud800-\udbff][\udc00-\udfff]|[\ud800-\udfff]/g;
  16380. // Safely create a real, live array from anything iterable.
  16381. _.toArray = function(obj) {
  16382. if (!obj) return [];
  16383. if (_.isArray(obj)) return slice.call(obj);
  16384. if (_.isString(obj)) {
  16385. // Keep surrogate pair characters together
  16386. return obj.match(reStrSymbol);
  16387. }
  16388. if (isArrayLike(obj)) return _.map(obj, _.identity);
  16389. return _.values(obj);
  16390. };
  16391. // Return the number of elements in an object.
  16392. _.size = function(obj) {
  16393. if (obj == null) return 0;
  16394. return isArrayLike(obj) ? obj.length : _.keys(obj).length;
  16395. };
  16396. // Split a collection into two arrays: one whose elements all satisfy the given
  16397. // predicate, and one whose elements all do not satisfy the predicate.
  16398. _.partition = group(function(result, value, pass) {
  16399. result[pass ? 0 : 1].push(value);
  16400. }, true);
  16401. // Array Functions
  16402. // ---------------
  16403. // Get the first element of an array. Passing **n** will return the first N
  16404. // values in the array. Aliased as `head` and `take`. The **guard** check
  16405. // allows it to work with `_.map`.
  16406. _.first = _.head = _.take = function(array, n, guard) {
  16407. if (array == null || array.length < 1) return n == null ? void 0 : [];
  16408. if (n == null || guard) return array[0];
  16409. return _.initial(array, array.length - n);
  16410. };
  16411. // Returns everything but the last entry of the array. Especially useful on
  16412. // the arguments object. Passing **n** will return all the values in
  16413. // the array, excluding the last N.
  16414. _.initial = function(array, n, guard) {
  16415. return slice.call(array, 0, Math.max(0, array.length - (n == null || guard ? 1 : n)));
  16416. };
  16417. // Get the last element of an array. Passing **n** will return the last N
  16418. // values in the array.
  16419. _.last = function(array, n, guard) {
  16420. if (array == null || array.length < 1) return n == null ? void 0 : [];
  16421. if (n == null || guard) return array[array.length - 1];
  16422. return _.rest(array, Math.max(0, array.length - n));
  16423. };
  16424. // Returns everything but the first entry of the array. Aliased as `tail` and `drop`.
  16425. // Especially useful on the arguments object. Passing an **n** will return
  16426. // the rest N values in the array.
  16427. _.rest = _.tail = _.drop = function(array, n, guard) {
  16428. return slice.call(array, n == null || guard ? 1 : n);
  16429. };
  16430. // Trim out all falsy values from an array.
  16431. _.compact = function(array) {
  16432. return _.filter(array, Boolean);
  16433. };
  16434. // Internal implementation of a recursive `flatten` function.
  16435. var flatten = function(input, shallow, strict, output) {
  16436. output = output || [];
  16437. var idx = output.length;
  16438. for (var i = 0, length = getLength(input); i < length; i++) {
  16439. var value = input[i];
  16440. if (isArrayLike(value) && (_.isArray(value) || _.isArguments(value))) {
  16441. // Flatten current level of array or arguments object.
  16442. if (shallow) {
  16443. var j = 0, len = value.length;
  16444. while (j < len) output[idx++] = value[j++];
  16445. } else {
  16446. flatten(value, shallow, strict, output);
  16447. idx = output.length;
  16448. }
  16449. } else if (!strict) {
  16450. output[idx++] = value;
  16451. }
  16452. }
  16453. return output;
  16454. };
  16455. // Flatten out an array, either recursively (by default), or just one level.
  16456. _.flatten = function(array, shallow) {
  16457. return flatten(array, shallow, false);
  16458. };
  16459. // Return a version of the array that does not contain the specified value(s).
  16460. _.without = restArguments(function(array, otherArrays) {
  16461. return _.difference(array, otherArrays);
  16462. });
  16463. // Produce a duplicate-free version of the array. If the array has already
  16464. // been sorted, you have the option of using a faster algorithm.
  16465. // The faster algorithm will not work with an iteratee if the iteratee
  16466. // is not a one-to-one function, so providing an iteratee will disable
  16467. // the faster algorithm.
  16468. // Aliased as `unique`.
  16469. _.uniq = _.unique = function(array, isSorted, iteratee, context) {
  16470. if (!_.isBoolean(isSorted)) {
  16471. context = iteratee;
  16472. iteratee = isSorted;
  16473. isSorted = false;
  16474. }
  16475. if (iteratee != null) iteratee = cb(iteratee, context);
  16476. var result = [];
  16477. var seen = [];
  16478. for (var i = 0, length = getLength(array); i < length; i++) {
  16479. var value = array[i],
  16480. computed = iteratee ? iteratee(value, i, array) : value;
  16481. if (isSorted && !iteratee) {
  16482. if (!i || seen !== computed) result.push(value);
  16483. seen = computed;
  16484. } else if (iteratee) {
  16485. if (!_.contains(seen, computed)) {
  16486. seen.push(computed);
  16487. result.push(value);
  16488. }
  16489. } else if (!_.contains(result, value)) {
  16490. result.push(value);
  16491. }
  16492. }
  16493. return result;
  16494. };
  16495. // Produce an array that contains the union: each distinct element from all of
  16496. // the passed-in arrays.
  16497. _.union = restArguments(function(arrays) {
  16498. return _.uniq(flatten(arrays, true, true));
  16499. });
  16500. // Produce an array that contains every item shared between all the
  16501. // passed-in arrays.
  16502. _.intersection = function(array) {
  16503. var result = [];
  16504. var argsLength = arguments.length;
  16505. for (var i = 0, length = getLength(array); i < length; i++) {
  16506. var item = array[i];
  16507. if (_.contains(result, item)) continue;
  16508. var j;
  16509. for (j = 1; j < argsLength; j++) {
  16510. if (!_.contains(arguments[j], item)) break;
  16511. }
  16512. if (j === argsLength) result.push(item);
  16513. }
  16514. return result;
  16515. };
  16516. // Take the difference between one array and a number of other arrays.
  16517. // Only the elements present in just the first array will remain.
  16518. _.difference = restArguments(function(array, rest) {
  16519. rest = flatten(rest, true, true);
  16520. return _.filter(array, function(value){
  16521. return !_.contains(rest, value);
  16522. });
  16523. });
  16524. // Complement of _.zip. Unzip accepts an array of arrays and groups
  16525. // each array's elements on shared indices.
  16526. _.unzip = function(array) {
  16527. var length = array && _.max(array, getLength).length || 0;
  16528. var result = Array(length);
  16529. for (var index = 0; index < length; index++) {
  16530. result[index] = _.pluck(array, index);
  16531. }
  16532. return result;
  16533. };
  16534. // Zip together multiple lists into a single array -- elements that share
  16535. // an index go together.
  16536. _.zip = restArguments(_.unzip);
  16537. // Converts lists into objects. Pass either a single array of `[key, value]`
  16538. // pairs, or two parallel arrays of the same length -- one of keys, and one of
  16539. // the corresponding values. Passing by pairs is the reverse of _.pairs.
  16540. _.object = function(list, values) {
  16541. var result = {};
  16542. for (var i = 0, length = getLength(list); i < length; i++) {
  16543. if (values) {
  16544. result[list[i]] = values[i];
  16545. } else {
  16546. result[list[i][0]] = list[i][1];
  16547. }
  16548. }
  16549. return result;
  16550. };
  16551. // Generator function to create the findIndex and findLastIndex functions.
  16552. var createPredicateIndexFinder = function(dir) {
  16553. return function(array, predicate, context) {
  16554. predicate = cb(predicate, context);
  16555. var length = getLength(array);
  16556. var index = dir > 0 ? 0 : length - 1;
  16557. for (; index >= 0 && index < length; index += dir) {
  16558. if (predicate(array[index], index, array)) return index;
  16559. }
  16560. return -1;
  16561. };
  16562. };
  16563. // Returns the first index on an array-like that passes a predicate test.
  16564. _.findIndex = createPredicateIndexFinder(1);
  16565. _.findLastIndex = createPredicateIndexFinder(-1);
  16566. // Use a comparator function to figure out the smallest index at which
  16567. // an object should be inserted so as to maintain order. Uses binary search.
  16568. _.sortedIndex = function(array, obj, iteratee, context) {
  16569. iteratee = cb(iteratee, context, 1);
  16570. var value = iteratee(obj);
  16571. var low = 0, high = getLength(array);
  16572. while (low < high) {
  16573. var mid = Math.floor((low + high) / 2);
  16574. if (iteratee(array[mid]) < value) low = mid + 1; else high = mid;
  16575. }
  16576. return low;
  16577. };
  16578. // Generator function to create the indexOf and lastIndexOf functions.
  16579. var createIndexFinder = function(dir, predicateFind, sortedIndex) {
  16580. return function(array, item, idx) {
  16581. var i = 0, length = getLength(array);
  16582. if (typeof idx == 'number') {
  16583. if (dir > 0) {
  16584. i = idx >= 0 ? idx : Math.max(idx + length, i);
  16585. } else {
  16586. length = idx >= 0 ? Math.min(idx + 1, length) : idx + length + 1;
  16587. }
  16588. } else if (sortedIndex && idx && length) {
  16589. idx = sortedIndex(array, item);
  16590. return array[idx] === item ? idx : -1;
  16591. }
  16592. if (item !== item) {
  16593. idx = predicateFind(slice.call(array, i, length), _.isNaN);
  16594. return idx >= 0 ? idx + i : -1;
  16595. }
  16596. for (idx = dir > 0 ? i : length - 1; idx >= 0 && idx < length; idx += dir) {
  16597. if (array[idx] === item) return idx;
  16598. }
  16599. return -1;
  16600. };
  16601. };
  16602. // Return the position of the first occurrence of an item in an array,
  16603. // or -1 if the item is not included in the array.
  16604. // If the array is large and already in sort order, pass `true`
  16605. // for **isSorted** to use binary search.
  16606. _.indexOf = createIndexFinder(1, _.findIndex, _.sortedIndex);
  16607. _.lastIndexOf = createIndexFinder(-1, _.findLastIndex);
  16608. // Generate an integer Array containing an arithmetic progression. A port of
  16609. // the native Python `range()` function. See
  16610. // [the Python documentation](http://docs.python.org/library/functions.html#range).
  16611. _.range = function(start, stop, step) {
  16612. if (stop == null) {
  16613. stop = start || 0;
  16614. start = 0;
  16615. }
  16616. if (!step) {
  16617. step = stop < start ? -1 : 1;
  16618. }
  16619. var length = Math.max(Math.ceil((stop - start) / step), 0);
  16620. var range = Array(length);
  16621. for (var idx = 0; idx < length; idx++, start += step) {
  16622. range[idx] = start;
  16623. }
  16624. return range;
  16625. };
  16626. // Chunk a single array into multiple arrays, each containing `count` or fewer
  16627. // items.
  16628. _.chunk = function(array, count) {
  16629. if (count == null || count < 1) return [];
  16630. var result = [];
  16631. var i = 0, length = array.length;
  16632. while (i < length) {
  16633. result.push(slice.call(array, i, i += count));
  16634. }
  16635. return result;
  16636. };
  16637. // Function (ahem) Functions
  16638. // ------------------
  16639. // Determines whether to execute a function as a constructor
  16640. // or a normal function with the provided arguments.
  16641. var executeBound = function(sourceFunc, boundFunc, context, callingContext, args) {
  16642. if (!(callingContext instanceof boundFunc)) return sourceFunc.apply(context, args);
  16643. var self = baseCreate(sourceFunc.prototype);
  16644. var result = sourceFunc.apply(self, args);
  16645. if (_.isObject(result)) return result;
  16646. return self;
  16647. };
  16648. // Create a function bound to a given object (assigning `this`, and arguments,
  16649. // optionally). Delegates to **ECMAScript 5**'s native `Function.bind` if
  16650. // available.
  16651. _.bind = restArguments(function(func, context, args) {
  16652. if (!_.isFunction(func)) throw new TypeError('Bind must be called on a function');
  16653. var bound = restArguments(function(callArgs) {
  16654. return executeBound(func, bound, context, this, args.concat(callArgs));
  16655. });
  16656. return bound;
  16657. });
  16658. // Partially apply a function by creating a version that has had some of its
  16659. // arguments pre-filled, without changing its dynamic `this` context. _ acts
  16660. // as a placeholder by default, allowing any combination of arguments to be
  16661. // pre-filled. Set `_.partial.placeholder` for a custom placeholder argument.
  16662. _.partial = restArguments(function(func, boundArgs) {
  16663. var placeholder = _.partial.placeholder;
  16664. var bound = function() {
  16665. var position = 0, length = boundArgs.length;
  16666. var args = Array(length);
  16667. for (var i = 0; i < length; i++) {
  16668. args[i] = boundArgs[i] === placeholder ? arguments[position++] : boundArgs[i];
  16669. }
  16670. while (position < arguments.length) args.push(arguments[position++]);
  16671. return executeBound(func, bound, this, this, args);
  16672. };
  16673. return bound;
  16674. });
  16675. _.partial.placeholder = _;
  16676. // Bind a number of an object's methods to that object. Remaining arguments
  16677. // are the method names to be bound. Useful for ensuring that all callbacks
  16678. // defined on an object belong to it.
  16679. _.bindAll = restArguments(function(obj, keys) {
  16680. keys = flatten(keys, false, false);
  16681. var index = keys.length;
  16682. if (index < 1) throw new Error('bindAll must be passed function names');
  16683. while (index--) {
  16684. var key = keys[index];
  16685. obj[key] = _.bind(obj[key], obj);
  16686. }
  16687. });
  16688. // Memoize an expensive function by storing its results.
  16689. _.memoize = function(func, hasher) {
  16690. var memoize = function(key) {
  16691. var cache = memoize.cache;
  16692. var address = '' + (hasher ? hasher.apply(this, arguments) : key);
  16693. if (!has(cache, address)) cache[address] = func.apply(this, arguments);
  16694. return cache[address];
  16695. };
  16696. memoize.cache = {};
  16697. return memoize;
  16698. };
  16699. // Delays a function for the given number of milliseconds, and then calls
  16700. // it with the arguments supplied.
  16701. _.delay = restArguments(function(func, wait, args) {
  16702. return setTimeout(function() {
  16703. return func.apply(null, args);
  16704. }, wait);
  16705. });
  16706. // Defers a function, scheduling it to run after the current call stack has
  16707. // cleared.
  16708. _.defer = _.partial(_.delay, _, 1);
  16709. // Returns a function, that, when invoked, will only be triggered at most once
  16710. // during a given window of time. Normally, the throttled function will run
  16711. // as much as it can, without ever going more than once per `wait` duration;
  16712. // but if you'd like to disable the execution on the leading edge, pass
  16713. // `{leading: false}`. To disable execution on the trailing edge, ditto.
  16714. _.throttle = function(func, wait, options) {
  16715. var timeout, context, args, result;
  16716. var previous = 0;
  16717. if (!options) options = {};
  16718. var later = function() {
  16719. previous = options.leading === false ? 0 : _.now();
  16720. timeout = null;
  16721. result = func.apply(context, args);
  16722. if (!timeout) context = args = null;
  16723. };
  16724. var throttled = function() {
  16725. var now = _.now();
  16726. if (!previous && options.leading === false) previous = now;
  16727. var remaining = wait - (now - previous);
  16728. context = this;
  16729. args = arguments;
  16730. if (remaining <= 0 || remaining > wait) {
  16731. if (timeout) {
  16732. clearTimeout(timeout);
  16733. timeout = null;
  16734. }
  16735. previous = now;
  16736. result = func.apply(context, args);
  16737. if (!timeout) context = args = null;
  16738. } else if (!timeout && options.trailing !== false) {
  16739. timeout = setTimeout(later, remaining);
  16740. }
  16741. return result;
  16742. };
  16743. throttled.cancel = function() {
  16744. clearTimeout(timeout);
  16745. previous = 0;
  16746. timeout = context = args = null;
  16747. };
  16748. return throttled;
  16749. };
  16750. // Returns a function, that, as long as it continues to be invoked, will not
  16751. // be triggered. The function will be called after it stops being called for
  16752. // N milliseconds. If `immediate` is passed, trigger the function on the
  16753. // leading edge, instead of the trailing.
  16754. _.debounce = function(func, wait, immediate) {
  16755. var timeout, result;
  16756. var later = function(context, args) {
  16757. timeout = null;
  16758. if (args) result = func.apply(context, args);
  16759. };
  16760. var debounced = restArguments(function(args) {
  16761. if (timeout) clearTimeout(timeout);
  16762. if (immediate) {
  16763. var callNow = !timeout;
  16764. timeout = setTimeout(later, wait);
  16765. if (callNow) result = func.apply(this, args);
  16766. } else {
  16767. timeout = _.delay(later, wait, this, args);
  16768. }
  16769. return result;
  16770. });
  16771. debounced.cancel = function() {
  16772. clearTimeout(timeout);
  16773. timeout = null;
  16774. };
  16775. return debounced;
  16776. };
  16777. // Returns the first function passed as an argument to the second,
  16778. // allowing you to adjust arguments, run code before and after, and
  16779. // conditionally execute the original function.
  16780. _.wrap = function(func, wrapper) {
  16781. return _.partial(wrapper, func);
  16782. };
  16783. // Returns a negated version of the passed-in predicate.
  16784. _.negate = function(predicate) {
  16785. return function() {
  16786. return !predicate.apply(this, arguments);
  16787. };
  16788. };
  16789. // Returns a function that is the composition of a list of functions, each
  16790. // consuming the return value of the function that follows.
  16791. _.compose = function() {
  16792. var args = arguments;
  16793. var start = args.length - 1;
  16794. return function() {
  16795. var i = start;
  16796. var result = args[start].apply(this, arguments);
  16797. while (i--) result = args[i].call(this, result);
  16798. return result;
  16799. };
  16800. };
  16801. // Returns a function that will only be executed on and after the Nth call.
  16802. _.after = function(times, func) {
  16803. return function() {
  16804. if (--times < 1) {
  16805. return func.apply(this, arguments);
  16806. }
  16807. };
  16808. };
  16809. // Returns a function that will only be executed up to (but not including) the Nth call.
  16810. _.before = function(times, func) {
  16811. var memo;
  16812. return function() {
  16813. if (--times > 0) {
  16814. memo = func.apply(this, arguments);
  16815. }
  16816. if (times <= 1) func = null;
  16817. return memo;
  16818. };
  16819. };
  16820. // Returns a function that will be executed at most one time, no matter how
  16821. // often you call it. Useful for lazy initialization.
  16822. _.once = _.partial(_.before, 2);
  16823. _.restArguments = restArguments;
  16824. // Object Functions
  16825. // ----------------
  16826. // Keys in IE < 9 that won't be iterated by `for key in ...` and thus missed.
  16827. var hasEnumBug = !{toString: null}.propertyIsEnumerable('toString');
  16828. var nonEnumerableProps = ['valueOf', 'isPrototypeOf', 'toString',
  16829. 'propertyIsEnumerable', 'hasOwnProperty', 'toLocaleString'];
  16830. var collectNonEnumProps = function(obj, keys) {
  16831. var nonEnumIdx = nonEnumerableProps.length;
  16832. var constructor = obj.constructor;
  16833. var proto = _.isFunction(constructor) && constructor.prototype || ObjProto;
  16834. // Constructor is a special case.
  16835. var prop = 'constructor';
  16836. if (has(obj, prop) && !_.contains(keys, prop)) keys.push(prop);
  16837. while (nonEnumIdx--) {
  16838. prop = nonEnumerableProps[nonEnumIdx];
  16839. if (prop in obj && obj[prop] !== proto[prop] && !_.contains(keys, prop)) {
  16840. keys.push(prop);
  16841. }
  16842. }
  16843. };
  16844. // Retrieve the names of an object's own properties.
  16845. // Delegates to **ECMAScript 5**'s native `Object.keys`.
  16846. _.keys = function(obj) {
  16847. if (!_.isObject(obj)) return [];
  16848. if (nativeKeys) return nativeKeys(obj);
  16849. var keys = [];
  16850. for (var key in obj) if (has(obj, key)) keys.push(key);
  16851. // Ahem, IE < 9.
  16852. if (hasEnumBug) collectNonEnumProps(obj, keys);
  16853. return keys;
  16854. };
  16855. // Retrieve all the property names of an object.
  16856. _.allKeys = function(obj) {
  16857. if (!_.isObject(obj)) return [];
  16858. var keys = [];
  16859. for (var key in obj) keys.push(key);
  16860. // Ahem, IE < 9.
  16861. if (hasEnumBug) collectNonEnumProps(obj, keys);
  16862. return keys;
  16863. };
  16864. // Retrieve the values of an object's properties.
  16865. _.values = function(obj) {
  16866. var keys = _.keys(obj);
  16867. var length = keys.length;
  16868. var values = Array(length);
  16869. for (var i = 0; i < length; i++) {
  16870. values[i] = obj[keys[i]];
  16871. }
  16872. return values;
  16873. };
  16874. // Returns the results of applying the iteratee to each element of the object.
  16875. // In contrast to _.map it returns an object.
  16876. _.mapObject = function(obj, iteratee, context) {
  16877. iteratee = cb(iteratee, context);
  16878. var keys = _.keys(obj),
  16879. length = keys.length,
  16880. results = {};
  16881. for (var index = 0; index < length; index++) {
  16882. var currentKey = keys[index];
  16883. results[currentKey] = iteratee(obj[currentKey], currentKey, obj);
  16884. }
  16885. return results;
  16886. };
  16887. // Convert an object into a list of `[key, value]` pairs.
  16888. // The opposite of _.object.
  16889. _.pairs = function(obj) {
  16890. var keys = _.keys(obj);
  16891. var length = keys.length;
  16892. var pairs = Array(length);
  16893. for (var i = 0; i < length; i++) {
  16894. pairs[i] = [keys[i], obj[keys[i]]];
  16895. }
  16896. return pairs;
  16897. };
  16898. // Invert the keys and values of an object. The values must be serializable.
  16899. _.invert = function(obj) {
  16900. var result = {};
  16901. var keys = _.keys(obj);
  16902. for (var i = 0, length = keys.length; i < length; i++) {
  16903. result[obj[keys[i]]] = keys[i];
  16904. }
  16905. return result;
  16906. };
  16907. // Return a sorted list of the function names available on the object.
  16908. // Aliased as `methods`.
  16909. _.functions = _.methods = function(obj) {
  16910. var names = [];
  16911. for (var key in obj) {
  16912. if (_.isFunction(obj[key])) names.push(key);
  16913. }
  16914. return names.sort();
  16915. };
  16916. // An internal function for creating assigner functions.
  16917. var createAssigner = function(keysFunc, defaults) {
  16918. return function(obj) {
  16919. var length = arguments.length;
  16920. if (defaults) obj = Object(obj);
  16921. if (length < 2 || obj == null) return obj;
  16922. for (var index = 1; index < length; index++) {
  16923. var source = arguments[index],
  16924. keys = keysFunc(source),
  16925. l = keys.length;
  16926. for (var i = 0; i < l; i++) {
  16927. var key = keys[i];
  16928. if (!defaults || obj[key] === void 0) obj[key] = source[key];
  16929. }
  16930. }
  16931. return obj;
  16932. };
  16933. };
  16934. // Extend a given object with all the properties in passed-in object(s).
  16935. _.extend = createAssigner(_.allKeys);
  16936. // Assigns a given object with all the own properties in the passed-in object(s).
  16937. // (https://developer.mozilla.org/docs/Web/JavaScript/Reference/Global_Objects/Object/assign)
  16938. _.extendOwn = _.assign = createAssigner(_.keys);
  16939. // Returns the first key on an object that passes a predicate test.
  16940. _.findKey = function(obj, predicate, context) {
  16941. predicate = cb(predicate, context);
  16942. var keys = _.keys(obj), key;
  16943. for (var i = 0, length = keys.length; i < length; i++) {
  16944. key = keys[i];
  16945. if (predicate(obj[key], key, obj)) return key;
  16946. }
  16947. };
  16948. // Internal pick helper function to determine if `obj` has key `key`.
  16949. var keyInObj = function(value, key, obj) {
  16950. return key in obj;
  16951. };
  16952. // Return a copy of the object only containing the whitelisted properties.
  16953. _.pick = restArguments(function(obj, keys) {
  16954. var result = {}, iteratee = keys[0];
  16955. if (obj == null) return result;
  16956. if (_.isFunction(iteratee)) {
  16957. if (keys.length > 1) iteratee = optimizeCb(iteratee, keys[1]);
  16958. keys = _.allKeys(obj);
  16959. } else {
  16960. iteratee = keyInObj;
  16961. keys = flatten(keys, false, false);
  16962. obj = Object(obj);
  16963. }
  16964. for (var i = 0, length = keys.length; i < length; i++) {
  16965. var key = keys[i];
  16966. var value = obj[key];
  16967. if (iteratee(value, key, obj)) result[key] = value;
  16968. }
  16969. return result;
  16970. });
  16971. // Return a copy of the object without the blacklisted properties.
  16972. _.omit = restArguments(function(obj, keys) {
  16973. var iteratee = keys[0], context;
  16974. if (_.isFunction(iteratee)) {
  16975. iteratee = _.negate(iteratee);
  16976. if (keys.length > 1) context = keys[1];
  16977. } else {
  16978. keys = _.map(flatten(keys, false, false), String);
  16979. iteratee = function(value, key) {
  16980. return !_.contains(keys, key);
  16981. };
  16982. }
  16983. return _.pick(obj, iteratee, context);
  16984. });
  16985. // Fill in a given object with default properties.
  16986. _.defaults = createAssigner(_.allKeys, true);
  16987. // Creates an object that inherits from the given prototype object.
  16988. // If additional properties are provided then they will be added to the
  16989. // created object.
  16990. _.create = function(prototype, props) {
  16991. var result = baseCreate(prototype);
  16992. if (props) _.extendOwn(result, props);
  16993. return result;
  16994. };
  16995. // Create a (shallow-cloned) duplicate of an object.
  16996. _.clone = function(obj) {
  16997. if (!_.isObject(obj)) return obj;
  16998. return _.isArray(obj) ? obj.slice() : _.extend({}, obj);
  16999. };
  17000. // Invokes interceptor with the obj, and then returns obj.
  17001. // The primary purpose of this method is to "tap into" a method chain, in
  17002. // order to perform operations on intermediate results within the chain.
  17003. _.tap = function(obj, interceptor) {
  17004. interceptor(obj);
  17005. return obj;
  17006. };
  17007. // Returns whether an object has a given set of `key:value` pairs.
  17008. _.isMatch = function(object, attrs) {
  17009. var keys = _.keys(attrs), length = keys.length;
  17010. if (object == null) return !length;
  17011. var obj = Object(object);
  17012. for (var i = 0; i < length; i++) {
  17013. var key = keys[i];
  17014. if (attrs[key] !== obj[key] || !(key in obj)) return false;
  17015. }
  17016. return true;
  17017. };
  17018. // Internal recursive comparison function for `isEqual`.
  17019. var eq, deepEq;
  17020. eq = function(a, b, aStack, bStack) {
  17021. // Identical objects are equal. `0 === -0`, but they aren't identical.
  17022. // See the [Harmony `egal` proposal](http://wiki.ecmascript.org/doku.php?id=harmony:egal).
  17023. if (a === b) return a !== 0 || 1 / a === 1 / b;
  17024. // `null` or `undefined` only equal to itself (strict comparison).
  17025. if (a == null || b == null) return false;
  17026. // `NaN`s are equivalent, but non-reflexive.
  17027. if (a !== a) return b !== b;
  17028. // Exhaust primitive checks
  17029. var type = typeof a;
  17030. if (type !== 'function' && type !== 'object' && typeof b != 'object') return false;
  17031. return deepEq(a, b, aStack, bStack);
  17032. };
  17033. // Internal recursive comparison function for `isEqual`.
  17034. deepEq = function(a, b, aStack, bStack) {
  17035. // Unwrap any wrapped objects.
  17036. if (a instanceof _) a = a._wrapped;
  17037. if (b instanceof _) b = b._wrapped;
  17038. // Compare `[[Class]]` names.
  17039. var className = toString.call(a);
  17040. if (className !== toString.call(b)) return false;
  17041. switch (className) {
  17042. // Strings, numbers, regular expressions, dates, and booleans are compared by value.
  17043. case '[object RegExp]':
  17044. // RegExps are coerced to strings for comparison (Note: '' + /a/i === '/a/i')
  17045. case '[object String]':
  17046. // Primitives and their corresponding object wrappers are equivalent; thus, `"5"` is
  17047. // equivalent to `new String("5")`.
  17048. return '' + a === '' + b;
  17049. case '[object Number]':
  17050. // `NaN`s are equivalent, but non-reflexive.
  17051. // Object(NaN) is equivalent to NaN.
  17052. if (+a !== +a) return +b !== +b;
  17053. // An `egal` comparison is performed for other numeric values.
  17054. return +a === 0 ? 1 / +a === 1 / b : +a === +b;
  17055. case '[object Date]':
  17056. case '[object Boolean]':
  17057. // Coerce dates and booleans to numeric primitive values. Dates are compared by their
  17058. // millisecond representations. Note that invalid dates with millisecond representations
  17059. // of `NaN` are not equivalent.
  17060. return +a === +b;
  17061. case '[object Symbol]':
  17062. return SymbolProto.valueOf.call(a) === SymbolProto.valueOf.call(b);
  17063. }
  17064. var areArrays = className === '[object Array]';
  17065. if (!areArrays) {
  17066. if (typeof a != 'object' || typeof b != 'object') return false;
  17067. // Objects with different constructors are not equivalent, but `Object`s or `Array`s
  17068. // from different frames are.
  17069. var aCtor = a.constructor, bCtor = b.constructor;
  17070. if (aCtor !== bCtor && !(_.isFunction(aCtor) && aCtor instanceof aCtor &&
  17071. _.isFunction(bCtor) && bCtor instanceof bCtor)
  17072. && ('constructor' in a && 'constructor' in b)) {
  17073. return false;
  17074. }
  17075. }
  17076. // Assume equality for cyclic structures. The algorithm for detecting cyclic
  17077. // structures is adapted from ES 5.1 section 15.12.3, abstract operation `JO`.
  17078. // Initializing stack of traversed objects.
  17079. // It's done here since we only need them for objects and arrays comparison.
  17080. aStack = aStack || [];
  17081. bStack = bStack || [];
  17082. var length = aStack.length;
  17083. while (length--) {
  17084. // Linear search. Performance is inversely proportional to the number of
  17085. // unique nested structures.
  17086. if (aStack[length] === a) return bStack[length] === b;
  17087. }
  17088. // Add the first object to the stack of traversed objects.
  17089. aStack.push(a);
  17090. bStack.push(b);
  17091. // Recursively compare objects and arrays.
  17092. if (areArrays) {
  17093. // Compare array lengths to determine if a deep comparison is necessary.
  17094. length = a.length;
  17095. if (length !== b.length) return false;
  17096. // Deep compare the contents, ignoring non-numeric properties.
  17097. while (length--) {
  17098. if (!eq(a[length], b[length], aStack, bStack)) return false;
  17099. }
  17100. } else {
  17101. // Deep compare objects.
  17102. var keys = _.keys(a), key;
  17103. length = keys.length;
  17104. // Ensure that both objects contain the same number of properties before comparing deep equality.
  17105. if (_.keys(b).length !== length) return false;
  17106. while (length--) {
  17107. // Deep compare each member
  17108. key = keys[length];
  17109. if (!(has(b, key) && eq(a[key], b[key], aStack, bStack))) return false;
  17110. }
  17111. }
  17112. // Remove the first object from the stack of traversed objects.
  17113. aStack.pop();
  17114. bStack.pop();
  17115. return true;
  17116. };
  17117. // Perform a deep comparison to check if two objects are equal.
  17118. _.isEqual = function(a, b) {
  17119. return eq(a, b);
  17120. };
  17121. // Is a given array, string, or object empty?
  17122. // An "empty" object has no enumerable own-properties.
  17123. _.isEmpty = function(obj) {
  17124. if (obj == null) return true;
  17125. if (isArrayLike(obj) && (_.isArray(obj) || _.isString(obj) || _.isArguments(obj))) return obj.length === 0;
  17126. return _.keys(obj).length === 0;
  17127. };
  17128. // Is a given value a DOM element?
  17129. _.isElement = function(obj) {
  17130. return !!(obj && obj.nodeType === 1);
  17131. };
  17132. // Is a given value an array?
  17133. // Delegates to ECMA5's native Array.isArray
  17134. _.isArray = nativeIsArray || function(obj) {
  17135. return toString.call(obj) === '[object Array]';
  17136. };
  17137. // Is a given variable an object?
  17138. _.isObject = function(obj) {
  17139. var type = typeof obj;
  17140. return type === 'function' || type === 'object' && !!obj;
  17141. };
  17142. // Add some isType methods: isArguments, isFunction, isString, isNumber, isDate, isRegExp, isError, isMap, isWeakMap, isSet, isWeakSet.
  17143. _.each(['Arguments', 'Function', 'String', 'Number', 'Date', 'RegExp', 'Error', 'Symbol', 'Map', 'WeakMap', 'Set', 'WeakSet'], function(name) {
  17144. _['is' + name] = function(obj) {
  17145. return toString.call(obj) === '[object ' + name + ']';
  17146. };
  17147. });
  17148. // Define a fallback version of the method in browsers (ahem, IE < 9), where
  17149. // there isn't any inspectable "Arguments" type.
  17150. if (!_.isArguments(arguments)) {
  17151. _.isArguments = function(obj) {
  17152. return has(obj, 'callee');
  17153. };
  17154. }
  17155. // Optimize `isFunction` if appropriate. Work around some typeof bugs in old v8,
  17156. // IE 11 (#1621), Safari 8 (#1929), and PhantomJS (#2236).
  17157. var nodelist = root.document && root.document.childNodes;
  17158. if ( true && typeof Int8Array != 'object' && typeof nodelist != 'function') {
  17159. _.isFunction = function(obj) {
  17160. return typeof obj == 'function' || false;
  17161. };
  17162. }
  17163. // Is a given object a finite number?
  17164. _.isFinite = function(obj) {
  17165. return !_.isSymbol(obj) && isFinite(obj) && !isNaN(parseFloat(obj));
  17166. };
  17167. // Is the given value `NaN`?
  17168. _.isNaN = function(obj) {
  17169. return _.isNumber(obj) && isNaN(obj);
  17170. };
  17171. // Is a given value a boolean?
  17172. _.isBoolean = function(obj) {
  17173. return obj === true || obj === false || toString.call(obj) === '[object Boolean]';
  17174. };
  17175. // Is a given value equal to null?
  17176. _.isNull = function(obj) {
  17177. return obj === null;
  17178. };
  17179. // Is a given variable undefined?
  17180. _.isUndefined = function(obj) {
  17181. return obj === void 0;
  17182. };
  17183. // Shortcut function for checking if an object has a given property directly
  17184. // on itself (in other words, not on a prototype).
  17185. _.has = function(obj, path) {
  17186. if (!_.isArray(path)) {
  17187. return has(obj, path);
  17188. }
  17189. var length = path.length;
  17190. for (var i = 0; i < length; i++) {
  17191. var key = path[i];
  17192. if (obj == null || !hasOwnProperty.call(obj, key)) {
  17193. return false;
  17194. }
  17195. obj = obj[key];
  17196. }
  17197. return !!length;
  17198. };
  17199. // Utility Functions
  17200. // -----------------
  17201. // Run Underscore.js in *noConflict* mode, returning the `_` variable to its
  17202. // previous owner. Returns a reference to the Underscore object.
  17203. _.noConflict = function() {
  17204. root._ = previousUnderscore;
  17205. return this;
  17206. };
  17207. // Keep the identity function around for default iteratees.
  17208. _.identity = function(value) {
  17209. return value;
  17210. };
  17211. // Predicate-generating functions. Often useful outside of Underscore.
  17212. _.constant = function(value) {
  17213. return function() {
  17214. return value;
  17215. };
  17216. };
  17217. _.noop = function(){};
  17218. // Creates a function that, when passed an object, will traverse that object’s
  17219. // properties down the given `path`, specified as an array of keys or indexes.
  17220. _.property = function(path) {
  17221. if (!_.isArray(path)) {
  17222. return shallowProperty(path);
  17223. }
  17224. return function(obj) {
  17225. return deepGet(obj, path);
  17226. };
  17227. };
  17228. // Generates a function for a given object that returns a given property.
  17229. _.propertyOf = function(obj) {
  17230. if (obj == null) {
  17231. return function(){};
  17232. }
  17233. return function(path) {
  17234. return !_.isArray(path) ? obj[path] : deepGet(obj, path);
  17235. };
  17236. };
  17237. // Returns a predicate for checking whether an object has a given set of
  17238. // `key:value` pairs.
  17239. _.matcher = _.matches = function(attrs) {
  17240. attrs = _.extendOwn({}, attrs);
  17241. return function(obj) {
  17242. return _.isMatch(obj, attrs);
  17243. };
  17244. };
  17245. // Run a function **n** times.
  17246. _.times = function(n, iteratee, context) {
  17247. var accum = Array(Math.max(0, n));
  17248. iteratee = optimizeCb(iteratee, context, 1);
  17249. for (var i = 0; i < n; i++) accum[i] = iteratee(i);
  17250. return accum;
  17251. };
  17252. // Return a random integer between min and max (inclusive).
  17253. _.random = function(min, max) {
  17254. if (max == null) {
  17255. max = min;
  17256. min = 0;
  17257. }
  17258. return min + Math.floor(Math.random() * (max - min + 1));
  17259. };
  17260. // A (possibly faster) way to get the current timestamp as an integer.
  17261. _.now = Date.now || function() {
  17262. return new Date().getTime();
  17263. };
  17264. // List of HTML entities for escaping.
  17265. var escapeMap = {
  17266. '&': '&amp;',
  17267. '<': '&lt;',
  17268. '>': '&gt;',
  17269. '"': '&quot;',
  17270. "'": '&#x27;',
  17271. '`': '&#x60;'
  17272. };
  17273. var unescapeMap = _.invert(escapeMap);
  17274. // Functions for escaping and unescaping strings to/from HTML interpolation.
  17275. var createEscaper = function(map) {
  17276. var escaper = function(match) {
  17277. return map[match];
  17278. };
  17279. // Regexes for identifying a key that needs to be escaped.
  17280. var source = '(?:' + _.keys(map).join('|') + ')';
  17281. var testRegexp = RegExp(source);
  17282. var replaceRegexp = RegExp(source, 'g');
  17283. return function(string) {
  17284. string = string == null ? '' : '' + string;
  17285. return testRegexp.test(string) ? string.replace(replaceRegexp, escaper) : string;
  17286. };
  17287. };
  17288. _.escape = createEscaper(escapeMap);
  17289. _.unescape = createEscaper(unescapeMap);
  17290. // Traverses the children of `obj` along `path`. If a child is a function, it
  17291. // is invoked with its parent as context. Returns the value of the final
  17292. // child, or `fallback` if any child is undefined.
  17293. _.result = function(obj, path, fallback) {
  17294. if (!_.isArray(path)) path = [path];
  17295. var length = path.length;
  17296. if (!length) {
  17297. return _.isFunction(fallback) ? fallback.call(obj) : fallback;
  17298. }
  17299. for (var i = 0; i < length; i++) {
  17300. var prop = obj == null ? void 0 : obj[path[i]];
  17301. if (prop === void 0) {
  17302. prop = fallback;
  17303. i = length; // Ensure we don't continue iterating.
  17304. }
  17305. obj = _.isFunction(prop) ? prop.call(obj) : prop;
  17306. }
  17307. return obj;
  17308. };
  17309. // Generate a unique integer id (unique within the entire client session).
  17310. // Useful for temporary DOM ids.
  17311. var idCounter = 0;
  17312. _.uniqueId = function(prefix) {
  17313. var id = ++idCounter + '';
  17314. return prefix ? prefix + id : id;
  17315. };
  17316. // By default, Underscore uses ERB-style template delimiters, change the
  17317. // following template settings to use alternative delimiters.
  17318. _.templateSettings = {
  17319. evaluate: /<%([\s\S]+?)%>/g,
  17320. interpolate: /<%=([\s\S]+?)%>/g,
  17321. escape: /<%-([\s\S]+?)%>/g
  17322. };
  17323. // When customizing `templateSettings`, if you don't want to define an
  17324. // interpolation, evaluation or escaping regex, we need one that is
  17325. // guaranteed not to match.
  17326. var noMatch = /(.)^/;
  17327. // Certain characters need to be escaped so that they can be put into a
  17328. // string literal.
  17329. var escapes = {
  17330. "'": "'",
  17331. '\\': '\\',
  17332. '\r': 'r',
  17333. '\n': 'n',
  17334. '\u2028': 'u2028',
  17335. '\u2029': 'u2029'
  17336. };
  17337. var escapeRegExp = /\\|'|\r|\n|\u2028|\u2029/g;
  17338. var escapeChar = function(match) {
  17339. return '\\' + escapes[match];
  17340. };
  17341. // JavaScript micro-templating, similar to John Resig's implementation.
  17342. // Underscore templating handles arbitrary delimiters, preserves whitespace,
  17343. // and correctly escapes quotes within interpolated code.
  17344. // NB: `oldSettings` only exists for backwards compatibility.
  17345. _.template = function(text, settings, oldSettings) {
  17346. if (!settings && oldSettings) settings = oldSettings;
  17347. settings = _.defaults({}, settings, _.templateSettings);
  17348. // Combine delimiters into one regular expression via alternation.
  17349. var matcher = RegExp([
  17350. (settings.escape || noMatch).source,
  17351. (settings.interpolate || noMatch).source,
  17352. (settings.evaluate || noMatch).source
  17353. ].join('|') + '|$', 'g');
  17354. // Compile the template source, escaping string literals appropriately.
  17355. var index = 0;
  17356. var source = "__p+='";
  17357. text.replace(matcher, function(match, escape, interpolate, evaluate, offset) {
  17358. source += text.slice(index, offset).replace(escapeRegExp, escapeChar);
  17359. index = offset + match.length;
  17360. if (escape) {
  17361. source += "'+\n((__t=(" + escape + "))==null?'':_.escape(__t))+\n'";
  17362. } else if (interpolate) {
  17363. source += "'+\n((__t=(" + interpolate + "))==null?'':__t)+\n'";
  17364. } else if (evaluate) {
  17365. source += "';\n" + evaluate + "\n__p+='";
  17366. }
  17367. // Adobe VMs need the match returned to produce the correct offset.
  17368. return match;
  17369. });
  17370. source += "';\n";
  17371. // If a variable is not specified, place data values in local scope.
  17372. if (!settings.variable) source = 'with(obj||{}){\n' + source + '}\n';
  17373. source = "var __t,__p='',__j=Array.prototype.join," +
  17374. "print=function(){__p+=__j.call(arguments,'');};\n" +
  17375. source + 'return __p;\n';
  17376. var render;
  17377. try {
  17378. render = new Function(settings.variable || 'obj', '_', source);
  17379. } catch (e) {
  17380. e.source = source;
  17381. throw e;
  17382. }
  17383. var template = function(data) {
  17384. return render.call(this, data, _);
  17385. };
  17386. // Provide the compiled source as a convenience for precompilation.
  17387. var argument = settings.variable || 'obj';
  17388. template.source = 'function(' + argument + '){\n' + source + '}';
  17389. return template;
  17390. };
  17391. // Add a "chain" function. Start chaining a wrapped Underscore object.
  17392. _.chain = function(obj) {
  17393. var instance = _(obj);
  17394. instance._chain = true;
  17395. return instance;
  17396. };
  17397. // OOP
  17398. // ---------------
  17399. // If Underscore is called as a function, it returns a wrapped object that
  17400. // can be used OO-style. This wrapper holds altered versions of all the
  17401. // underscore functions. Wrapped objects may be chained.
  17402. // Helper function to continue chaining intermediate results.
  17403. var chainResult = function(instance, obj) {
  17404. return instance._chain ? _(obj).chain() : obj;
  17405. };
  17406. // Add your own custom functions to the Underscore object.
  17407. _.mixin = function(obj) {
  17408. _.each(_.functions(obj), function(name) {
  17409. var func = _[name] = obj[name];
  17410. _.prototype[name] = function() {
  17411. var args = [this._wrapped];
  17412. push.apply(args, arguments);
  17413. return chainResult(this, func.apply(_, args));
  17414. };
  17415. });
  17416. return _;
  17417. };
  17418. // Add all of the Underscore functions to the wrapper object.
  17419. _.mixin(_);
  17420. // Add all mutator Array functions to the wrapper.
  17421. _.each(['pop', 'push', 'reverse', 'shift', 'sort', 'splice', 'unshift'], function(name) {
  17422. var method = ArrayProto[name];
  17423. _.prototype[name] = function() {
  17424. var obj = this._wrapped;
  17425. method.apply(obj, arguments);
  17426. if ((name === 'shift' || name === 'splice') && obj.length === 0) delete obj[0];
  17427. return chainResult(this, obj);
  17428. };
  17429. });
  17430. // Add all accessor Array functions to the wrapper.
  17431. _.each(['concat', 'join', 'slice'], function(name) {
  17432. var method = ArrayProto[name];
  17433. _.prototype[name] = function() {
  17434. return chainResult(this, method.apply(this._wrapped, arguments));
  17435. };
  17436. });
  17437. // Extracts the result from a wrapped and chained object.
  17438. _.prototype.value = function() {
  17439. return this._wrapped;
  17440. };
  17441. // Provide unwrapping proxy for some methods used in engine operations
  17442. // such as arithmetic and JSON stringification.
  17443. _.prototype.valueOf = _.prototype.toJSON = _.prototype.value;
  17444. _.prototype.toString = function() {
  17445. return String(this._wrapped);
  17446. };
  17447. // AMD registration happens at the end for compatibility with AMD loaders
  17448. // that may not enforce next-turn semantics on modules. Even though general
  17449. // practice for AMD registration is to be anonymous, underscore registers
  17450. // as a named module because, like jQuery, it is a base library that is
  17451. // popular enough to be bundled in a third party lib, but not be part of
  17452. // an AMD load request. Those cases could generate an error when an
  17453. // anonymous define() is called outside of a loader request.
  17454. if (true) {
  17455. !(__WEBPACK_AMD_DEFINE_ARRAY__ = [], __WEBPACK_AMD_DEFINE_RESULT__ = (function() {
  17456. return _;
  17457. }).apply(exports, __WEBPACK_AMD_DEFINE_ARRAY__),
  17458. __WEBPACK_AMD_DEFINE_RESULT__ !== undefined && (module.exports = __WEBPACK_AMD_DEFINE_RESULT__));
  17459. }
  17460. }());
  17461. /* WEBPACK VAR INJECTION */}.call(this, __webpack_require__(/*! ./../webpack/buildin/global.js */ "./node_modules/webpack/buildin/global.js"), __webpack_require__(/*! ./../webpack/buildin/module.js */ "./node_modules/webpack/buildin/module.js")(module)))
  17462. /***/ }),
  17463. /***/ "./node_modules/webpack/buildin/global.js":
  17464. /*!***********************************!*\
  17465. !*** (webpack)/buildin/global.js ***!
  17466. \***********************************/
  17467. /*! no static exports found */
  17468. /***/ (function(module, exports) {
  17469. var g;
  17470. // This works in non-strict mode
  17471. g = (function() {
  17472. return this;
  17473. })();
  17474. try {
  17475. // This works if eval is allowed (see CSP)
  17476. g = g || new Function("return this")();
  17477. } catch (e) {
  17478. // This works if the window reference is available
  17479. if (typeof window === "object") g = window;
  17480. }
  17481. // g can still be undefined, but nothing to do about it...
  17482. // We return undefined, instead of nothing here, so it's
  17483. // easier to handle this case. if(!global) { ...}
  17484. module.exports = g;
  17485. /***/ }),
  17486. /***/ "./node_modules/webpack/buildin/module.js":
  17487. /*!***********************************!*\
  17488. !*** (webpack)/buildin/module.js ***!
  17489. \***********************************/
  17490. /*! no static exports found */
  17491. /***/ (function(module, exports) {
  17492. module.exports = function(module) {
  17493. if (!module.webpackPolyfill) {
  17494. module.deprecate = function() {};
  17495. module.paths = [];
  17496. // module.parent = undefined by default
  17497. if (!module.children) module.children = [];
  17498. Object.defineProperty(module, "loaded", {
  17499. enumerable: true,
  17500. get: function() {
  17501. return module.l;
  17502. }
  17503. });
  17504. Object.defineProperty(module, "id", {
  17505. enumerable: true,
  17506. get: function() {
  17507. return module.i;
  17508. }
  17509. });
  17510. module.webpackPolyfill = 1;
  17511. }
  17512. return module;
  17513. };
  17514. /***/ }),
  17515. /***/ "./src/asset_manager/config/config.js":
  17516. /*!********************************************!*\
  17517. !*** ./src/asset_manager/config/config.js ***!
  17518. \********************************************/
  17519. /*! exports provided: default */
  17520. /***/ (function(module, __webpack_exports__, __webpack_require__) {
  17521. "use strict";
  17522. __webpack_require__.r(__webpack_exports__);
  17523. /* harmony default export */ __webpack_exports__["default"] = ({
  17524. // Default assets
  17525. // eg. [
  17526. // 'https://...image1.png',
  17527. // 'https://...image2.png',
  17528. // {type: 'image', src: 'https://...image3.png', someOtherCustomProp: 1},
  17529. // ..
  17530. // ]
  17531. assets: [],
  17532. // Content to add where there is no assets to show
  17533. // eg. 'No <b>assets</b> here, drag to upload'
  17534. noAssets: '',
  17535. // Style prefix
  17536. stylePrefix: 'am-',
  17537. // Upload endpoint, set `false` to disable upload
  17538. // upload: 'https://endpoint/upload/assets',
  17539. // upload: false,
  17540. upload: 0,
  17541. // The name used in POST to pass uploaded files
  17542. uploadName: 'files',
  17543. // Custom headers to pass with the upload request
  17544. headers: {},
  17545. // Custom parameters to pass with the upload request, eg. csrf token
  17546. params: {},
  17547. // The credentials setting for the upload request, eg. 'include', 'omit'
  17548. credentials: 'include',
  17549. // Allow uploading multiple files per request.
  17550. // If disabled filename will not have '[]' appended
  17551. multiUpload: true,
  17552. // If true, tries to add automatically uploaded assets.
  17553. // To make it work the server should respond with a JSON containing assets
  17554. // in a data key, eg:
  17555. // {
  17556. // data: [
  17557. // 'https://.../image.png',
  17558. // ...
  17559. // {src: 'https://.../image2.png'},
  17560. // ...
  17561. // ]
  17562. // }
  17563. autoAdd: 1,
  17564. // To upload your assets, the module uses Fetch API, with this option you
  17565. // overwrite it with something else.
  17566. // It should return a Promise
  17567. // @example
  17568. // customFetch: (url, options) => axios(url, { data: options.body }),
  17569. customFetch: '',
  17570. // Custom uploadFile function.
  17571. // Differently from the `customFetch` option, this gives a total control
  17572. // over the uploading process, but you also have to emit all `asset:upload:*` events
  17573. // by yourself (if you need to use them somewhere)
  17574. // @example
  17575. // uploadFile: (e) => {
  17576. // var files = e.dataTransfer ? e.dataTransfer.files : e.target.files;
  17577. // // ...send somewhere
  17578. // }
  17579. uploadFile: '',
  17580. // In the absence of 'uploadFile' or 'upload' assets will be embedded as Base64
  17581. embedAsBase64: 1,
  17582. // Handle the image url submit from the built-in 'Add image' form
  17583. // @example
  17584. // handleAdd: (textFromInput) => {
  17585. // // some check...
  17586. // editor.AssetManager.add(textFromInput);
  17587. // }
  17588. handleAdd: '',
  17589. // Enable an upload dropzone on the entire editor (not document) when dragging
  17590. // files over it
  17591. // If active the dropzone disable/hide the upload dropzone in asset modal,
  17592. // otherwise you will get double drops (#507)
  17593. dropzone: 0,
  17594. // Open the asset manager once files are been dropped via the dropzone
  17595. openAssetsOnDrop: 1,
  17596. // Any dropzone content to append inside dropzone element
  17597. dropzoneContent: '',
  17598. //method called before upload, on return false upload is canceled.
  17599. // @example
  17600. // beforeUpload: (files) => {
  17601. // // logic...
  17602. // var stopUpload = true;
  17603. // if(stopUpload) return false;
  17604. // }
  17605. beforeUpload: null,
  17606. // Toggles visiblity of assets url input
  17607. showUrlInput: true
  17608. });
  17609. /***/ }),
  17610. /***/ "./src/asset_manager/index.js":
  17611. /*!************************************!*\
  17612. !*** ./src/asset_manager/index.js ***!
  17613. \************************************/
  17614. /*! exports provided: default */
  17615. /***/ (function(module, __webpack_exports__, __webpack_require__) {
  17616. "use strict";
  17617. __webpack_require__.r(__webpack_exports__);
  17618. /* harmony import */ var _config_config__WEBPACK_IMPORTED_MODULE_0__ = __webpack_require__(/*! ./config/config */ "./src/asset_manager/config/config.js");
  17619. /* harmony import */ var _model_Assets__WEBPACK_IMPORTED_MODULE_1__ = __webpack_require__(/*! ./model/Assets */ "./src/asset_manager/model/Assets.js");
  17620. /* harmony import */ var _view_AssetsView__WEBPACK_IMPORTED_MODULE_2__ = __webpack_require__(/*! ./view/AssetsView */ "./src/asset_manager/view/AssetsView.js");
  17621. /* harmony import */ var _view_FileUploader__WEBPACK_IMPORTED_MODULE_3__ = __webpack_require__(/*! ./view/FileUploader */ "./src/asset_manager/view/FileUploader.js");
  17622. /**
  17623. * You can customize the initial state of the module from the editor initialization, by passing the following [Configuration Object](https://github.com/artf/grapesjs/blob/master/src/asset_manager/config/config.js)
  17624. * ```js
  17625. * const editor = grapesjs.init({
  17626. * assetManager: {
  17627. * // options
  17628. * }
  17629. * })
  17630. * ```
  17631. *
  17632. * Once the editor is instantiated you can use its API. Before using these methods you should get the module from the instance
  17633. *
  17634. * ```js
  17635. * const assetManager = editor.AssetManager;
  17636. * ```
  17637. *
  17638. * * [add](#add)
  17639. * * [get](#get)
  17640. * * [getAll](#getall)
  17641. * * [getAllVisible](#getallvisible)
  17642. * * [remove](#remove)
  17643. * * [store](#store)
  17644. * * [load](#load)
  17645. * * [getContainer](#getcontainer)
  17646. * * [getAssetsEl](#getassetsel)
  17647. * * [addType](#addtype)
  17648. * * [getType](#gettype)
  17649. * * [getTypes](#gettypes)
  17650. *
  17651. * @module AssetManager
  17652. */
  17653. /* harmony default export */ __webpack_exports__["default"] = (function () {
  17654. var c = {};
  17655. var assets, am, fu;
  17656. return {
  17657. /**
  17658. * Name of the module
  17659. * @type {String}
  17660. * @private
  17661. */
  17662. name: 'AssetManager',
  17663. /**
  17664. * Mandatory for the storage manager
  17665. * @type {String}
  17666. * @private
  17667. */
  17668. storageKey: 'assets',
  17669. getConfig: function getConfig() {
  17670. return c;
  17671. },
  17672. /**
  17673. * Initialize module
  17674. * @param {Object} config Configurations
  17675. * @private
  17676. */
  17677. init: function init(config) {
  17678. var _this = this;
  17679. c = config || {};
  17680. for (var name in _config_config__WEBPACK_IMPORTED_MODULE_0__["default"]) {
  17681. if (!(name in c)) c[name] = _config_config__WEBPACK_IMPORTED_MODULE_0__["default"][name];
  17682. }
  17683. var ppfx = c.pStylePrefix;
  17684. var em = c.em;
  17685. if (ppfx) {
  17686. c.stylePrefix = ppfx + c.stylePrefix;
  17687. } // Global assets collection
  17688. assets = new _model_Assets__WEBPACK_IMPORTED_MODULE_1__["default"]([]);
  17689. var obj = {
  17690. // Collection visible in asset manager
  17691. collection: new _model_Assets__WEBPACK_IMPORTED_MODULE_1__["default"]([]),
  17692. globalCollection: assets,
  17693. config: c
  17694. };
  17695. fu = new _view_FileUploader__WEBPACK_IMPORTED_MODULE_3__["default"](obj);
  17696. obj.fu = fu;
  17697. am = new _view_AssetsView__WEBPACK_IMPORTED_MODULE_2__["default"](obj); // Setup the sync between the global and public collections
  17698. assets.listenTo(assets, 'add', function (model) {
  17699. _this.getAllVisible().add(model);
  17700. em && em.trigger('asset:add', model);
  17701. });
  17702. assets.listenTo(assets, 'remove', function (model) {
  17703. _this.getAllVisible().remove(model);
  17704. em && em.trigger('asset:remove', model);
  17705. });
  17706. return this;
  17707. },
  17708. /**
  17709. * Add new asset/s to the collection. URLs are supposed to be unique
  17710. * @param {string|Object|Array<string>|Array<Object>} asset URL strings or an objects representing the resource.
  17711. * @param {Object} [opts] Options
  17712. * @return {Model}
  17713. * @example
  17714. * // In case of strings, would be interpreted as images
  17715. * assetManager.add('http://img.jpg');
  17716. * assetManager.add(['http://img.jpg', './path/to/img.png']);
  17717. *
  17718. * // Using objects you could indicate the type and other meta informations
  17719. * assetManager.add({
  17720. * src: 'http://img.jpg',
  17721. * //type: 'image', //image is default
  17722. * height: 300,
  17723. * width: 200,
  17724. * });
  17725. * assetManager.add([{
  17726. * src: 'http://img.jpg',
  17727. * },{
  17728. * src: './path/to/img.png',
  17729. * }]);
  17730. */
  17731. add: function add(asset) {
  17732. var opts = arguments.length > 1 && arguments[1] !== undefined ? arguments[1] : {};
  17733. // Put the model at the beginning
  17734. if (typeof opts.at == 'undefined') {
  17735. opts.at = 0;
  17736. }
  17737. return assets.add(asset, opts);
  17738. },
  17739. /**
  17740. * Returns the asset by URL
  17741. * @param {string} src URL of the asset
  17742. * @return {Object} Object representing the asset
  17743. * @example
  17744. * var asset = assetManager.get('http://img.jpg');
  17745. */
  17746. get: function get(src) {
  17747. return assets.where({
  17748. src: src
  17749. })[0];
  17750. },
  17751. /**
  17752. * Return the global collection, containing all the assets
  17753. * @return {Collection}
  17754. */
  17755. getAll: function getAll() {
  17756. return assets;
  17757. },
  17758. /**
  17759. * Return the visible collection, which containes assets actually rendered
  17760. * @return {Collection}
  17761. */
  17762. getAllVisible: function getAllVisible() {
  17763. return am.collection;
  17764. },
  17765. /**
  17766. * Remove the asset by its URL
  17767. * @param {string} src URL of the asset
  17768. * @return {this}
  17769. * @example
  17770. * assetManager.remove('http://img.jpg');
  17771. */
  17772. remove: function remove(src) {
  17773. var asset = this.get(src);
  17774. this.getAll().remove(asset);
  17775. return this;
  17776. },
  17777. /**
  17778. * Store assets data to the selected storage
  17779. * @param {Boolean} noStore If true, won't store
  17780. * @return {Object} Data to store
  17781. * @example
  17782. * var assets = assetManager.store();
  17783. */
  17784. store: function store(noStore) {
  17785. var obj = {};
  17786. var assets = JSON.stringify(this.getAll().toJSON());
  17787. obj[this.storageKey] = assets;
  17788. if (!noStore && c.stm) c.stm.store(obj);
  17789. return obj;
  17790. },
  17791. /**
  17792. * Load data from the passed object.
  17793. * The fetched data will be added to the collection.
  17794. * @param {Object} data Object of data to load
  17795. * @return {Object} Loaded assets
  17796. * @example
  17797. * var assets = assetManager.load({
  17798. * assets: [...]
  17799. * })
  17800. *
  17801. */
  17802. load: function load() {
  17803. var data = arguments.length > 0 && arguments[0] !== undefined ? arguments[0] : {};
  17804. var name = this.storageKey;
  17805. var assets = data[name] || [];
  17806. if (typeof assets == 'string') {
  17807. try {
  17808. assets = JSON.parse(data[name]);
  17809. } catch (err) {}
  17810. }
  17811. if (assets && assets.length) {
  17812. this.getAll().reset(assets);
  17813. }
  17814. return assets;
  17815. },
  17816. /**
  17817. * Return the Asset Manager Container
  17818. * @return {HTMLElement}
  17819. */
  17820. getContainer: function getContainer() {
  17821. return am.el;
  17822. },
  17823. /**
  17824. * Get assets element container
  17825. * @return {HTMLElement}
  17826. */
  17827. getAssetsEl: function getAssetsEl() {
  17828. return am.el.querySelector('[data-el=assets]');
  17829. },
  17830. /**
  17831. * Render assets
  17832. * @param {array} assets Assets to render, without the argument will render
  17833. * all global assets
  17834. * @return {HTMLElement}
  17835. * @example
  17836. * // Render all assets
  17837. * assetManager.render();
  17838. *
  17839. * // Render some of the assets
  17840. * const assets = assetManager.getAll();
  17841. * assetManager.render(assets.filter(
  17842. * asset => asset.get('category') == 'cats'
  17843. * ));
  17844. */
  17845. render: function render(assets) {
  17846. var toRender = assets || this.getAll().models;
  17847. if (!am.rendered) {
  17848. am.render();
  17849. }
  17850. am.collection.reset(toRender);
  17851. return this.getContainer();
  17852. },
  17853. /**
  17854. * Add new type. If you want to get more about type definition we suggest to read the [module's page](/modules/Assets.html)
  17855. * @param {string} id Type ID
  17856. * @param {Object} definition Definition of the type. Each definition contains
  17857. * `model` (business logic), `view` (presentation logic)
  17858. * and `isType` function which recognize the type of the
  17859. * passed entity
  17860. * @example
  17861. * assetManager.addType('my-type', {
  17862. * model: {},
  17863. * view: {},
  17864. * isType: (value) => {},
  17865. * })
  17866. */
  17867. addType: function addType(id, definition) {
  17868. this.getAll().addType(id, definition);
  17869. },
  17870. /**
  17871. * Get type
  17872. * @param {string} id Type ID
  17873. * @return {Object} Type definition
  17874. */
  17875. getType: function getType(id) {
  17876. return this.getAll().getType(id);
  17877. },
  17878. /**
  17879. * Get types
  17880. * @return {Array}
  17881. */
  17882. getTypes: function getTypes() {
  17883. return this.getAll().getTypes();
  17884. },
  17885. //-------
  17886. AssetsView: function AssetsView() {
  17887. return am;
  17888. },
  17889. FileUploader: function FileUploader() {
  17890. return fu;
  17891. },
  17892. onLoad: function onLoad() {
  17893. this.getAll().reset(c.assets);
  17894. },
  17895. postRender: function postRender(editorView) {
  17896. c.dropzone && fu.initDropzone(editorView);
  17897. },
  17898. /**
  17899. * Set new target
  17900. * @param {Object} m Model
  17901. * @private
  17902. * */
  17903. setTarget: function setTarget(m) {
  17904. am.collection.target = m;
  17905. },
  17906. /**
  17907. * Set callback after asset was selected
  17908. * @param {Object} f Callback function
  17909. * @private
  17910. * */
  17911. onSelect: function onSelect(f) {
  17912. am.collection.onSelect = f;
  17913. },
  17914. /**
  17915. * Set callback to fire when the asset is clicked
  17916. * @param {function} func
  17917. * @private
  17918. */
  17919. onClick: function onClick(func) {
  17920. c.onClick = func;
  17921. },
  17922. /**
  17923. * Set callback to fire when the asset is double clicked
  17924. * @param {function} func
  17925. * @private
  17926. */
  17927. onDblClick: function onDblClick(func) {
  17928. c.onDblClick = func;
  17929. }
  17930. };
  17931. });
  17932. /***/ }),
  17933. /***/ "./src/asset_manager/model/Asset.js":
  17934. /*!******************************************!*\
  17935. !*** ./src/asset_manager/model/Asset.js ***!
  17936. \******************************************/
  17937. /*! exports provided: default */
  17938. /***/ (function(module, __webpack_exports__, __webpack_require__) {
  17939. "use strict";
  17940. __webpack_require__.r(__webpack_exports__);
  17941. /* harmony import */ var backbone__WEBPACK_IMPORTED_MODULE_0__ = __webpack_require__(/*! backbone */ "./node_modules/backbone/backbone.js");
  17942. /* harmony import */ var backbone__WEBPACK_IMPORTED_MODULE_0___default = /*#__PURE__*/__webpack_require__.n(backbone__WEBPACK_IMPORTED_MODULE_0__);
  17943. /* harmony default export */ __webpack_exports__["default"] = (backbone__WEBPACK_IMPORTED_MODULE_0___default.a.Model.extend({
  17944. idAttribute: 'src',
  17945. defaults: {
  17946. type: '',
  17947. src: ''
  17948. },
  17949. /**
  17950. * Get filename of the asset
  17951. * @return {string}
  17952. * @private
  17953. * */
  17954. getFilename: function getFilename() {
  17955. return this.get('src').split('/').pop();
  17956. },
  17957. /**
  17958. * Get extension of the asset
  17959. * @return {string}
  17960. * @private
  17961. * */
  17962. getExtension: function getExtension() {
  17963. return this.getFilename().split('.').pop();
  17964. }
  17965. }));
  17966. /***/ }),
  17967. /***/ "./src/asset_manager/model/AssetImage.js":
  17968. /*!***********************************************!*\
  17969. !*** ./src/asset_manager/model/AssetImage.js ***!
  17970. \***********************************************/
  17971. /*! exports provided: default */
  17972. /***/ (function(module, __webpack_exports__, __webpack_require__) {
  17973. "use strict";
  17974. __webpack_require__.r(__webpack_exports__);
  17975. /* harmony import */ var _babel_runtime_helpers_defineProperty__WEBPACK_IMPORTED_MODULE_0__ = __webpack_require__(/*! @babel/runtime/helpers/defineProperty */ "./node_modules/@babel/runtime/helpers/defineProperty.js");
  17976. /* harmony import */ var _babel_runtime_helpers_defineProperty__WEBPACK_IMPORTED_MODULE_0___default = /*#__PURE__*/__webpack_require__.n(_babel_runtime_helpers_defineProperty__WEBPACK_IMPORTED_MODULE_0__);
  17977. /* harmony import */ var _Asset__WEBPACK_IMPORTED_MODULE_1__ = __webpack_require__(/*! ./Asset */ "./src/asset_manager/model/Asset.js");
  17978. function ownKeys(object, enumerableOnly) { var keys = Object.keys(object); if (Object.getOwnPropertySymbols) { var symbols = Object.getOwnPropertySymbols(object); if (enumerableOnly) symbols = symbols.filter(function (sym) { return Object.getOwnPropertyDescriptor(object, sym).enumerable; }); keys.push.apply(keys, symbols); } return keys; }
  17979. function _objectSpread(target) { for (var i = 1; i < arguments.length; i++) { var source = arguments[i] != null ? arguments[i] : {}; if (i % 2) { ownKeys(source, true).forEach(function (key) { _babel_runtime_helpers_defineProperty__WEBPACK_IMPORTED_MODULE_0___default()(target, key, source[key]); }); } else if (Object.getOwnPropertyDescriptors) { Object.defineProperties(target, Object.getOwnPropertyDescriptors(source)); } else { ownKeys(source).forEach(function (key) { Object.defineProperty(target, key, Object.getOwnPropertyDescriptor(source, key)); }); } } return target; }
  17980. /* harmony default export */ __webpack_exports__["default"] = (_Asset__WEBPACK_IMPORTED_MODULE_1__["default"].extend({
  17981. defaults: _objectSpread({}, _Asset__WEBPACK_IMPORTED_MODULE_1__["default"].prototype.defaults, {
  17982. type: 'image',
  17983. unitDim: 'px',
  17984. height: 0,
  17985. width: 0
  17986. })
  17987. }));
  17988. /***/ }),
  17989. /***/ "./src/asset_manager/model/Assets.js":
  17990. /*!*******************************************!*\
  17991. !*** ./src/asset_manager/model/Assets.js ***!
  17992. \*******************************************/
  17993. /*! exports provided: default */
  17994. /***/ (function(module, __webpack_exports__, __webpack_require__) {
  17995. "use strict";
  17996. __webpack_require__.r(__webpack_exports__);
  17997. /* harmony import */ var backbone__WEBPACK_IMPORTED_MODULE_0__ = __webpack_require__(/*! backbone */ "./node_modules/backbone/backbone.js");
  17998. /* harmony import */ var backbone__WEBPACK_IMPORTED_MODULE_0___default = /*#__PURE__*/__webpack_require__.n(backbone__WEBPACK_IMPORTED_MODULE_0__);
  17999. /* harmony import */ var _AssetImage__WEBPACK_IMPORTED_MODULE_1__ = __webpack_require__(/*! ./AssetImage */ "./src/asset_manager/model/AssetImage.js");
  18000. /* harmony import */ var _view_AssetImageView__WEBPACK_IMPORTED_MODULE_2__ = __webpack_require__(/*! ./../view/AssetImageView */ "./src/asset_manager/view/AssetImageView.js");
  18001. /* harmony import */ var domain_abstract_model_TypeableCollection__WEBPACK_IMPORTED_MODULE_3__ = __webpack_require__(/*! domain_abstract/model/TypeableCollection */ "./src/domain_abstract/model/TypeableCollection.js");
  18002. /* harmony default export */ __webpack_exports__["default"] = (backbone__WEBPACK_IMPORTED_MODULE_0___default.a.Collection.extend(domain_abstract_model_TypeableCollection__WEBPACK_IMPORTED_MODULE_3__["default"]).extend({
  18003. types: [{
  18004. id: 'image',
  18005. model: _AssetImage__WEBPACK_IMPORTED_MODULE_1__["default"],
  18006. view: _view_AssetImageView__WEBPACK_IMPORTED_MODULE_2__["default"],
  18007. isType: function isType(value) {
  18008. if (typeof value == 'string') {
  18009. return {
  18010. type: 'image',
  18011. src: value
  18012. };
  18013. }
  18014. return value;
  18015. }
  18016. }]
  18017. }));
  18018. /***/ }),
  18019. /***/ "./src/asset_manager/view/AssetImageView.js":
  18020. /*!**************************************************!*\
  18021. !*** ./src/asset_manager/view/AssetImageView.js ***!
  18022. \**************************************************/
  18023. /*! exports provided: default */
  18024. /***/ (function(module, __webpack_exports__, __webpack_require__) {
  18025. "use strict";
  18026. __webpack_require__.r(__webpack_exports__);
  18027. /* harmony import */ var underscore__WEBPACK_IMPORTED_MODULE_0__ = __webpack_require__(/*! underscore */ "./node_modules/underscore/underscore.js");
  18028. /* harmony import */ var underscore__WEBPACK_IMPORTED_MODULE_0___default = /*#__PURE__*/__webpack_require__.n(underscore__WEBPACK_IMPORTED_MODULE_0__);
  18029. /* harmony import */ var _AssetView__WEBPACK_IMPORTED_MODULE_1__ = __webpack_require__(/*! ./AssetView */ "./src/asset_manager/view/AssetView.js");
  18030. /* harmony default export */ __webpack_exports__["default"] = (_AssetView__WEBPACK_IMPORTED_MODULE_1__["default"].extend({
  18031. events: {
  18032. 'click [data-toggle=asset-remove]': 'onRemove',
  18033. click: 'onClick',
  18034. dblclick: 'onDblClick'
  18035. },
  18036. getPreview: function getPreview() {
  18037. var pfx = this.pfx;
  18038. var src = this.model.get('src');
  18039. return "\n <div class=\"".concat(pfx, "preview\" style=\"background-image: url('").concat(src, "');\"></div>\n <div class=\"").concat(pfx, "preview-bg ").concat(this.ppfx, "checker-bg\"></div>\n ");
  18040. },
  18041. getInfo: function getInfo() {
  18042. var pfx = this.pfx;
  18043. var model = this.model;
  18044. var name = model.get('name');
  18045. var width = model.get('width');
  18046. var height = model.get('height');
  18047. var unit = model.get('unitDim');
  18048. var dim = width && height ? "".concat(width, "x").concat(height).concat(unit) : '';
  18049. name = name || model.getFilename();
  18050. return "\n <div class=\"".concat(pfx, "name\">").concat(name, "</div>\n <div class=\"").concat(pfx, "dimensions\">").concat(dim, "</div>\n ");
  18051. },
  18052. init: function init(o) {
  18053. var pfx = this.pfx;
  18054. this.className += " ".concat(pfx, "asset-image");
  18055. },
  18056. /**
  18057. * Triggered when the asset is clicked
  18058. * @private
  18059. * */
  18060. onClick: function onClick() {
  18061. var onClick = this.config.onClick;
  18062. var model = this.model;
  18063. this.collection.trigger('deselectAll');
  18064. this.$el.addClass(this.pfx + 'highlight');
  18065. if (Object(underscore__WEBPACK_IMPORTED_MODULE_0__["isFunction"])(onClick)) {
  18066. onClick(model);
  18067. } else {
  18068. this.updateTarget(this.collection.target);
  18069. }
  18070. },
  18071. /**
  18072. * Triggered when the asset is double clicked
  18073. * @private
  18074. * */
  18075. onDblClick: function onDblClick() {
  18076. var em = this.em,
  18077. model = this.model;
  18078. var onDblClick = this.config.onDblClick;
  18079. if (Object(underscore__WEBPACK_IMPORTED_MODULE_0__["isFunction"])(onDblClick)) {
  18080. onDblClick(model);
  18081. } else {
  18082. this.updateTarget(this.collection.target);
  18083. em && em.get('Modal').close();
  18084. }
  18085. var onSelect = this.collection.onSelect;
  18086. Object(underscore__WEBPACK_IMPORTED_MODULE_0__["isFunction"])(onSelect) && onSelect(model);
  18087. },
  18088. /**
  18089. * Remove asset from collection
  18090. * @private
  18091. * */
  18092. onRemove: function onRemove(e) {
  18093. e.stopImmediatePropagation();
  18094. this.model.collection.remove(this.model);
  18095. }
  18096. }));
  18097. /***/ }),
  18098. /***/ "./src/asset_manager/view/AssetView.js":
  18099. /*!*********************************************!*\
  18100. !*** ./src/asset_manager/view/AssetView.js ***!
  18101. \*********************************************/
  18102. /*! exports provided: default */
  18103. /***/ (function(module, __webpack_exports__, __webpack_require__) {
  18104. "use strict";
  18105. __webpack_require__.r(__webpack_exports__);
  18106. /* harmony import */ var backbone__WEBPACK_IMPORTED_MODULE_0__ = __webpack_require__(/*! backbone */ "./node_modules/backbone/backbone.js");
  18107. /* harmony import */ var backbone__WEBPACK_IMPORTED_MODULE_0___default = /*#__PURE__*/__webpack_require__.n(backbone__WEBPACK_IMPORTED_MODULE_0__);
  18108. /* harmony import */ var underscore__WEBPACK_IMPORTED_MODULE_1__ = __webpack_require__(/*! underscore */ "./node_modules/underscore/underscore.js");
  18109. /* harmony import */ var underscore__WEBPACK_IMPORTED_MODULE_1___default = /*#__PURE__*/__webpack_require__.n(underscore__WEBPACK_IMPORTED_MODULE_1__);
  18110. /* harmony default export */ __webpack_exports__["default"] = (backbone__WEBPACK_IMPORTED_MODULE_0___default.a.View.extend({
  18111. initialize: function initialize() {
  18112. var o = arguments.length > 0 && arguments[0] !== undefined ? arguments[0] : {};
  18113. this.options = o;
  18114. this.collection = o.collection;
  18115. var config = o.config || {};
  18116. this.config = config;
  18117. this.pfx = config.stylePrefix || '';
  18118. this.ppfx = config.pStylePrefix || '';
  18119. this.em = config.em;
  18120. this.className = this.pfx + 'asset';
  18121. this.listenTo(this.model, 'destroy remove', this.remove);
  18122. this.model.view = this;
  18123. var init = this.init && this.init.bind(this);
  18124. init && init(o);
  18125. },
  18126. template: function template() {
  18127. var pfx = this.pfx;
  18128. return "\n <div class=\"".concat(pfx, "preview-cont\">\n ").concat(this.getPreview(), "\n </div>\n <div class=\"").concat(pfx, "meta\">\n ").concat(this.getInfo(), "\n </div>\n <div class=\"").concat(pfx, "close\" data-toggle=\"asset-remove\">\n &Cross;\n </div>\n ");
  18129. },
  18130. /**
  18131. * Update target if exists
  18132. * @param {Model} target
  18133. * @private
  18134. * */
  18135. updateTarget: function updateTarget(target) {
  18136. if (target && target.set) {
  18137. target.set('attributes', Object(underscore__WEBPACK_IMPORTED_MODULE_1__["clone"])(target.get('attributes')));
  18138. target.set('src', this.model.get('src'));
  18139. }
  18140. },
  18141. getPreview: function getPreview() {
  18142. return '';
  18143. },
  18144. getInfo: function getInfo() {
  18145. return '';
  18146. },
  18147. render: function render() {
  18148. var el = this.el;
  18149. el.innerHTML = this.template(this, this.model);
  18150. el.className = this.className;
  18151. return this;
  18152. }
  18153. }));
  18154. /***/ }),
  18155. /***/ "./src/asset_manager/view/AssetsView.js":
  18156. /*!**********************************************!*\
  18157. !*** ./src/asset_manager/view/AssetsView.js ***!
  18158. \**********************************************/
  18159. /*! exports provided: default */
  18160. /***/ (function(module, __webpack_exports__, __webpack_require__) {
  18161. "use strict";
  18162. __webpack_require__.r(__webpack_exports__);
  18163. /* harmony import */ var _babel_runtime_helpers_objectWithoutProperties__WEBPACK_IMPORTED_MODULE_0__ = __webpack_require__(/*! @babel/runtime/helpers/objectWithoutProperties */ "./node_modules/@babel/runtime/helpers/objectWithoutProperties.js");
  18164. /* harmony import */ var _babel_runtime_helpers_objectWithoutProperties__WEBPACK_IMPORTED_MODULE_0___default = /*#__PURE__*/__webpack_require__.n(_babel_runtime_helpers_objectWithoutProperties__WEBPACK_IMPORTED_MODULE_0__);
  18165. /* harmony import */ var backbone__WEBPACK_IMPORTED_MODULE_1__ = __webpack_require__(/*! backbone */ "./node_modules/backbone/backbone.js");
  18166. /* harmony import */ var backbone__WEBPACK_IMPORTED_MODULE_1___default = /*#__PURE__*/__webpack_require__.n(backbone__WEBPACK_IMPORTED_MODULE_1__);
  18167. /* harmony default export */ __webpack_exports__["default"] = (backbone__WEBPACK_IMPORTED_MODULE_1___default.a.View.extend({
  18168. events: {
  18169. submit: 'handleSubmit'
  18170. },
  18171. template: function template(_ref) {
  18172. var pfx = _ref.pfx,
  18173. ppfx = _ref.ppfx,
  18174. em = _ref.em,
  18175. view = _babel_runtime_helpers_objectWithoutProperties__WEBPACK_IMPORTED_MODULE_0___default()(_ref, ["pfx", "ppfx", "em"]);
  18176. var form = '';
  18177. if (this.config.showUrlInput) {
  18178. form = "\n <form class=\"".concat(pfx, "add-asset\">\n <div class=\"").concat(ppfx, "field ").concat(pfx, "add-field\">\n <input placeholder=\"").concat(em && em.t('assetManager.inputPlh'), "\"/>\n </div>\n <button class=\"").concat(ppfx, "btn-prim\">").concat(em && em.t('assetManager.addButton'), "</button>\n <div style=\"clear:both\"></div>\n </form>\n ");
  18179. }
  18180. return "\n <div class=\"".concat(pfx, "assets-cont\">\n <div class=\"").concat(pfx, "assets-header\">\n ").concat(form, "\n </div>\n <div class=\"").concat(pfx, "assets\" data-el=\"assets\"></div>\n <div style=\"clear:both\"></div>\n </div>\n ");
  18181. },
  18182. initialize: function initialize(o) {
  18183. this.options = o;
  18184. this.config = o.config;
  18185. this.pfx = this.config.stylePrefix || '';
  18186. this.ppfx = this.config.pStylePrefix || '';
  18187. this.em = this.config.em;
  18188. var coll = this.collection;
  18189. this.listenTo(coll, 'reset', this.renderAssets);
  18190. this.listenTo(coll, 'add', this.addToAsset);
  18191. this.listenTo(coll, 'remove', this.removedAsset);
  18192. this.listenTo(coll, 'deselectAll', this.deselectAll);
  18193. },
  18194. /**
  18195. * Add new asset to the collection via string
  18196. * @param {Event} e Event object
  18197. * @return {this}
  18198. * @private
  18199. */
  18200. handleSubmit: function handleSubmit(e) {
  18201. e.preventDefault();
  18202. var input = this.getAddInput();
  18203. var url = input && input.value.trim();
  18204. var handleAdd = this.config.handleAdd;
  18205. if (!url) {
  18206. return;
  18207. }
  18208. input.value = '';
  18209. this.getAssetsEl().scrollTop = 0;
  18210. if (handleAdd) {
  18211. handleAdd.bind(this)(url);
  18212. } else {
  18213. this.options.globalCollection.add(url, {
  18214. at: 0
  18215. });
  18216. }
  18217. },
  18218. /**
  18219. * Returns assets element
  18220. * @return {HTMLElement}
  18221. * @private
  18222. */
  18223. getAssetsEl: function getAssetsEl() {
  18224. //if(!this.assets) // Not able to cache as after the rerender it losses the ref
  18225. return this.el.querySelector(".".concat(this.pfx, "assets"));
  18226. },
  18227. /**
  18228. * Returns input url element
  18229. * @return {HTMLElement}
  18230. * @private
  18231. */
  18232. getAddInput: function getAddInput() {
  18233. if (!this.inputUrl || !this.inputUrl.value) this.inputUrl = this.el.querySelector(".".concat(this.pfx, "add-asset input"));
  18234. return this.inputUrl;
  18235. },
  18236. /**
  18237. * Triggered when an asset is removed
  18238. * @param {Asset} model Removed asset
  18239. * @private
  18240. */
  18241. removedAsset: function removedAsset(model) {
  18242. if (!this.collection.length) {
  18243. this.toggleNoAssets();
  18244. }
  18245. },
  18246. /**
  18247. * Add asset to collection
  18248. * @private
  18249. * */
  18250. addToAsset: function addToAsset(model) {
  18251. if (this.collection.length == 1) {
  18252. this.toggleNoAssets(1);
  18253. }
  18254. this.addAsset(model);
  18255. },
  18256. /**
  18257. * Add new asset to collection
  18258. * @param Object Model
  18259. * @param Object Fragment collection
  18260. * @return Object Object created
  18261. * @private
  18262. * */
  18263. addAsset: function addAsset(model) {
  18264. var fragmentEl = arguments.length > 1 && arguments[1] !== undefined ? arguments[1] : null;
  18265. var fragment = fragmentEl;
  18266. var collection = this.collection;
  18267. var config = this.config;
  18268. var rendered = new model.typeView({
  18269. model: model,
  18270. collection: collection,
  18271. config: config
  18272. }).render().el;
  18273. if (fragment) {
  18274. fragment.appendChild(rendered);
  18275. } else {
  18276. var assetsEl = this.getAssetsEl();
  18277. if (assetsEl) {
  18278. assetsEl.insertBefore(rendered, assetsEl.firstChild);
  18279. }
  18280. }
  18281. return rendered;
  18282. },
  18283. /**
  18284. * Checks if to show noAssets
  18285. * @param {Boolean} hide
  18286. * @private
  18287. */
  18288. toggleNoAssets: function toggleNoAssets(hide) {
  18289. var assetsEl = this.$el.find(".".concat(this.pfx, "assets"));
  18290. if (hide) {
  18291. assetsEl.empty();
  18292. } else {
  18293. var noAssets = this.config.noAssets;
  18294. noAssets && assetsEl.append(noAssets);
  18295. }
  18296. },
  18297. /**
  18298. * Deselect all assets
  18299. * @private
  18300. * */
  18301. deselectAll: function deselectAll() {
  18302. var pfx = this.pfx;
  18303. this.$el.find(".".concat(pfx, "highlight")).removeClass("".concat(pfx, "highlight"));
  18304. },
  18305. renderAssets: function renderAssets() {
  18306. var _this = this;
  18307. var fragment = document.createDocumentFragment();
  18308. var assets = this.$el.find(".".concat(this.pfx, "assets"));
  18309. assets.empty();
  18310. this.toggleNoAssets(this.collection.length);
  18311. this.collection.each(function (model) {
  18312. return _this.addAsset(model, fragment);
  18313. });
  18314. assets.append(fragment);
  18315. },
  18316. render: function render() {
  18317. var fuRendered = this.options.fu.render().el;
  18318. this.$el.empty();
  18319. this.$el.append(fuRendered).append(this.template(this));
  18320. this.el.className = "".concat(this.ppfx, "asset-manager");
  18321. this.renderAssets();
  18322. this.rendered = 1;
  18323. return this;
  18324. }
  18325. }));
  18326. /***/ }),
  18327. /***/ "./src/asset_manager/view/FileUploader.js":
  18328. /*!************************************************!*\
  18329. !*** ./src/asset_manager/view/FileUploader.js ***!
  18330. \************************************************/
  18331. /*! exports provided: default */
  18332. /***/ (function(module, __webpack_exports__, __webpack_require__) {
  18333. "use strict";
  18334. __webpack_require__.r(__webpack_exports__);
  18335. /* harmony import */ var underscore__WEBPACK_IMPORTED_MODULE_0__ = __webpack_require__(/*! underscore */ "./node_modules/underscore/underscore.js");
  18336. /* harmony import */ var underscore__WEBPACK_IMPORTED_MODULE_0___default = /*#__PURE__*/__webpack_require__.n(underscore__WEBPACK_IMPORTED_MODULE_0__);
  18337. /* harmony import */ var backbone__WEBPACK_IMPORTED_MODULE_1__ = __webpack_require__(/*! backbone */ "./node_modules/backbone/backbone.js");
  18338. /* harmony import */ var backbone__WEBPACK_IMPORTED_MODULE_1___default = /*#__PURE__*/__webpack_require__.n(backbone__WEBPACK_IMPORTED_MODULE_1__);
  18339. /* harmony import */ var utils_fetch__WEBPACK_IMPORTED_MODULE_2__ = __webpack_require__(/*! utils/fetch */ "./src/utils/fetch.js");
  18340. /* harmony default export */ __webpack_exports__["default"] = (backbone__WEBPACK_IMPORTED_MODULE_1___default.a.View.extend({
  18341. template: Object(underscore__WEBPACK_IMPORTED_MODULE_0__["template"])("\n <form>\n <div id=\"<%= pfx %>title\"><%= title %></div>\n <input type=\"file\" id=\"<%= uploadId %>\" name=\"file\" accept=\"*/*\" <%= disabled ? 'disabled' : '' %> <%= multiUpload ? 'multiple' : '' %>/>\n <div style=\"clear:both;\"></div>\n </form>\n "),
  18342. events: {},
  18343. initialize: function initialize() {
  18344. var opts = arguments.length > 0 && arguments[0] !== undefined ? arguments[0] : {};
  18345. this.options = opts;
  18346. var c = opts.config || {};
  18347. this.config = c;
  18348. this.em = this.config.em;
  18349. this.pfx = c.stylePrefix || '';
  18350. this.ppfx = c.pStylePrefix || '';
  18351. this.target = this.options.globalCollection || {};
  18352. this.uploadId = this.pfx + 'uploadFile';
  18353. this.disabled = c.disableUpload !== undefined ? c.disableUpload : !c.upload && !c.embedAsBase64;
  18354. this.multiUpload = c.multiUpload !== undefined ? c.multiUpload : true;
  18355. this.events['change #' + this.uploadId] = 'uploadFile';
  18356. var uploadFile = c.uploadFile;
  18357. if (uploadFile) {
  18358. this.uploadFile = uploadFile.bind(this);
  18359. } else if (!c.upload && c.embedAsBase64) {
  18360. this.uploadFile = this.constructor.embedAsBase64;
  18361. }
  18362. this.delegateEvents();
  18363. },
  18364. /**
  18365. * Triggered before the upload is started
  18366. * @private
  18367. */
  18368. onUploadStart: function onUploadStart() {
  18369. var em = this.config.em;
  18370. em && em.trigger('asset:upload:start');
  18371. },
  18372. /**
  18373. * Triggered after the upload is ended
  18374. * @param {Object|string} res End result
  18375. * @private
  18376. */
  18377. onUploadEnd: function onUploadEnd(res) {
  18378. var $el = this.$el,
  18379. config = this.config;
  18380. var em = config.em;
  18381. em && em.trigger('asset:upload:end', res);
  18382. var input = $el.find('input');
  18383. input && input.val('');
  18384. },
  18385. /**
  18386. * Triggered on upload error
  18387. * @param {Object} err Error
  18388. * @private
  18389. */
  18390. onUploadError: function onUploadError(err) {
  18391. var em = this.config.em;
  18392. console.error(err);
  18393. this.onUploadEnd(err);
  18394. em && em.trigger('asset:upload:error', err);
  18395. },
  18396. /**
  18397. * Triggered on upload response
  18398. * @param {string} text Response text
  18399. * @private
  18400. */
  18401. onUploadResponse: function onUploadResponse(text, clb) {
  18402. var em = this.config.em;
  18403. var config = this.config;
  18404. var target = this.target;
  18405. var json;
  18406. try {
  18407. json = typeof text === 'string' ? JSON.parse(text) : text;
  18408. } catch (e) {
  18409. json = text;
  18410. }
  18411. em && em.trigger('asset:upload:response', json);
  18412. if (config.autoAdd && target) {
  18413. target.add(json.data, {
  18414. at: 0
  18415. });
  18416. }
  18417. this.onUploadEnd(text);
  18418. clb && clb(json);
  18419. },
  18420. /**
  18421. * Upload files
  18422. * @param {Object} e Event
  18423. * @return {Promise}
  18424. * @private
  18425. * */
  18426. uploadFile: function uploadFile(e, clb) {
  18427. var _this = this;
  18428. var files = e.dataTransfer ? e.dataTransfer.files : e.target.files;
  18429. var config = this.config;
  18430. var beforeUpload = config.beforeUpload;
  18431. var beforeUploadResponse = beforeUpload && beforeUpload(files);
  18432. if (beforeUploadResponse === false) return;
  18433. var body = new FormData();
  18434. var params = config.params,
  18435. customFetch = config.customFetch;
  18436. for (var param in params) {
  18437. body.append(param, params[param]);
  18438. }
  18439. if (this.multiUpload) {
  18440. for (var i = 0; i < files.length; i++) {
  18441. body.append("".concat(config.uploadName, "[]"), files[i]);
  18442. }
  18443. } else if (files.length) {
  18444. body.append(config.uploadName, files[0]);
  18445. }
  18446. var target = this.target;
  18447. var url = config.upload;
  18448. var headers = config.headers;
  18449. var reqHead = 'X-Requested-With';
  18450. if (typeof headers[reqHead] == 'undefined') {
  18451. headers[reqHead] = 'XMLHttpRequest';
  18452. }
  18453. if (url) {
  18454. this.onUploadStart();
  18455. var fetchOpts = {
  18456. method: 'post',
  18457. credentials: config.credentials || 'include',
  18458. headers: headers,
  18459. body: body
  18460. };
  18461. var fetchResult = customFetch ? customFetch(url, fetchOpts) : Object(utils_fetch__WEBPACK_IMPORTED_MODULE_2__["default"])(url, fetchOpts).then(function (res) {
  18462. return (res.status / 200 | 0) == 1 ? res.text() : res.text().then(function (text) {
  18463. return Promise.reject(text);
  18464. });
  18465. });
  18466. return fetchResult.then(function (text) {
  18467. return _this.onUploadResponse(text, clb);
  18468. }).catch(function (err) {
  18469. return _this.onUploadError(err);
  18470. });
  18471. }
  18472. },
  18473. /**
  18474. * Make input file droppable
  18475. * @private
  18476. * */
  18477. initDrop: function initDrop() {
  18478. var that = this;
  18479. if (!this.uploadForm) {
  18480. this.uploadForm = this.$el.find('form').get(0);
  18481. if ('draggable' in this.uploadForm) {
  18482. var uploadFile = this.uploadFile;
  18483. this.uploadForm.ondragover = function () {
  18484. this.className = that.pfx + 'hover';
  18485. return false;
  18486. };
  18487. this.uploadForm.ondragleave = function () {
  18488. this.className = '';
  18489. return false;
  18490. };
  18491. this.uploadForm.ondrop = function (e) {
  18492. this.className = '';
  18493. e.preventDefault();
  18494. that.uploadFile(e);
  18495. return;
  18496. };
  18497. }
  18498. }
  18499. },
  18500. initDropzone: function initDropzone(ev) {
  18501. var _this2 = this;
  18502. var addedCls = 0;
  18503. var c = this.config;
  18504. var em = ev.model;
  18505. var edEl = ev.el;
  18506. var editor = em.get('Editor');
  18507. var container = em.get('Config').el;
  18508. var frameEl = em.get('Canvas').getBody();
  18509. var ppfx = this.ppfx;
  18510. var updatedCls = "".concat(ppfx, "dropzone-active");
  18511. var dropzoneCls = "".concat(ppfx, "dropzone");
  18512. var cleanEditorElCls = function cleanEditorElCls() {
  18513. edEl.className = edEl.className.replace(updatedCls, '').trim();
  18514. addedCls = 0;
  18515. };
  18516. var onDragOver = function onDragOver() {
  18517. if (!addedCls) {
  18518. edEl.className += " ".concat(updatedCls);
  18519. addedCls = 1;
  18520. }
  18521. return false;
  18522. };
  18523. var onDragLeave = function onDragLeave() {
  18524. cleanEditorElCls();
  18525. return false;
  18526. };
  18527. var onDrop = function onDrop(e) {
  18528. cleanEditorElCls();
  18529. e.preventDefault();
  18530. e.stopPropagation();
  18531. _this2.uploadFile(e);
  18532. if (c.openAssetsOnDrop && editor) {
  18533. var target = editor.getSelected();
  18534. editor.runCommand('open-assets', {
  18535. target: target,
  18536. onSelect: function onSelect() {
  18537. editor.Modal.close();
  18538. editor.AssetManager.setTarget(null);
  18539. }
  18540. });
  18541. }
  18542. return false;
  18543. };
  18544. ev.$el.append("<div class=\"".concat(dropzoneCls, "\">").concat(c.dropzoneContent, "</div>"));
  18545. cleanEditorElCls();
  18546. if ('draggable' in edEl) {
  18547. [edEl, frameEl].forEach(function (item) {
  18548. item.ondragover = onDragOver;
  18549. item.ondragleave = onDragLeave;
  18550. item.ondrop = onDrop;
  18551. });
  18552. }
  18553. },
  18554. render: function render() {
  18555. var $el = this.$el,
  18556. pfx = this.pfx,
  18557. em = this.em;
  18558. $el.html(this.template({
  18559. title: em && em.t('assetManager.uploadTitle'),
  18560. uploadId: this.uploadId,
  18561. disabled: this.disabled,
  18562. multiUpload: this.multiUpload,
  18563. pfx: pfx
  18564. }));
  18565. this.initDrop();
  18566. $el.attr('class', pfx + 'file-uploader');
  18567. return this;
  18568. }
  18569. }, {
  18570. embedAsBase64: function embedAsBase64(e, clb) {
  18571. var _this3 = this;
  18572. // List files dropped
  18573. var files = e.dataTransfer ? e.dataTransfer.files : e.target.files;
  18574. var response = {
  18575. data: []
  18576. }; // Unlikely, widely supported now
  18577. if (!FileReader) {
  18578. this.onUploadError(new Error('Unsupported platform, FileReader is not defined'));
  18579. return;
  18580. }
  18581. var promises = [];
  18582. var mimeTypeMatcher = /^(.+)\/(.+)$/;
  18583. var _iteratorNormalCompletion = true;
  18584. var _didIteratorError = false;
  18585. var _iteratorError = undefined;
  18586. try {
  18587. var _loop = function _loop() {
  18588. var file = _step.value;
  18589. // For each file a reader (to read the base64 URL)
  18590. // and a promise (to track and merge results and errors)
  18591. var promise = new Promise(function (resolve, reject) {
  18592. var reader = new FileReader();
  18593. reader.addEventListener('load', function (event) {
  18594. var type;
  18595. var name = file.name; // Try to find the MIME type of the file.
  18596. var match = mimeTypeMatcher.exec(file.type);
  18597. if (match) {
  18598. type = match[1]; // The first part in the MIME, "image" in image/png
  18599. } else {
  18600. type = file.type;
  18601. }
  18602. /*
  18603. // Show local video files, http://jsfiddle.net/dsbonev/cCCZ2/embedded/result,js,html,css/
  18604. var URL = window.URL || window.webkitURL
  18605. var file = this.files[0]
  18606. var type = file.type
  18607. var videoNode = document.createElement('video');
  18608. var canPlay = videoNode.canPlayType(type) // can use also for 'audio' types
  18609. if (canPlay === '') canPlay = 'no'
  18610. var message = 'Can play type "' + type + '": ' + canPlay
  18611. var isError = canPlay === 'no'
  18612. displayMessage(message, isError)
  18613. if (isError) {
  18614. return
  18615. }
  18616. var fileURL = URL.createObjectURL(file)
  18617. videoNode.src = fileURL
  18618. */
  18619. // If it's an image, try to find its size
  18620. if (type === 'image') {
  18621. var data = {
  18622. src: reader.result,
  18623. name: name,
  18624. type: type,
  18625. height: 0,
  18626. width: 0
  18627. };
  18628. var image = new Image();
  18629. image.addEventListener('error', function (error) {
  18630. reject(error);
  18631. });
  18632. image.addEventListener('load', function () {
  18633. data.height = image.height;
  18634. data.width = image.width;
  18635. resolve(data);
  18636. });
  18637. image.src = data.src;
  18638. } else if (type) {
  18639. // Not an image, but has a type
  18640. resolve({
  18641. src: reader.result,
  18642. name: name,
  18643. type: type
  18644. });
  18645. } else {
  18646. // No type found, resolve with the URL only
  18647. resolve(reader.result);
  18648. }
  18649. });
  18650. reader.addEventListener('error', function (error) {
  18651. reject(error);
  18652. });
  18653. reader.addEventListener('abort', function (error) {
  18654. reject('Aborted');
  18655. });
  18656. reader.readAsDataURL(file);
  18657. });
  18658. promises.push(promise);
  18659. };
  18660. for (var _iterator = files[Symbol.iterator](), _step; !(_iteratorNormalCompletion = (_step = _iterator.next()).done); _iteratorNormalCompletion = true) {
  18661. _loop();
  18662. }
  18663. } catch (err) {
  18664. _didIteratorError = true;
  18665. _iteratorError = err;
  18666. } finally {
  18667. try {
  18668. if (!_iteratorNormalCompletion && _iterator.return != null) {
  18669. _iterator.return();
  18670. }
  18671. } finally {
  18672. if (_didIteratorError) {
  18673. throw _iteratorError;
  18674. }
  18675. }
  18676. }
  18677. Promise.all(promises).then(function (data) {
  18678. response.data = data;
  18679. _this3.onUploadResponse(response, clb);
  18680. }, function (error) {
  18681. _this3.onUploadError(error);
  18682. });
  18683. }
  18684. }));
  18685. /***/ }),
  18686. /***/ "./src/block_manager/config/config.js":
  18687. /*!********************************************!*\
  18688. !*** ./src/block_manager/config/config.js ***!
  18689. \********************************************/
  18690. /*! exports provided: default */
  18691. /***/ (function(module, __webpack_exports__, __webpack_require__) {
  18692. "use strict";
  18693. __webpack_require__.r(__webpack_exports__);
  18694. /* harmony default export */ __webpack_exports__["default"] = ({
  18695. // Specify the element to use as a container, string (query) or HTMLElement
  18696. // With the empty value, nothing will be rendered
  18697. appendTo: '',
  18698. // Append blocks to canvas on click
  18699. appendOnClick: 0,
  18700. blocks: []
  18701. });
  18702. /***/ }),
  18703. /***/ "./src/block_manager/index.js":
  18704. /*!************************************!*\
  18705. !*** ./src/block_manager/index.js ***!
  18706. \************************************/
  18707. /*! exports provided: default */
  18708. /***/ (function(module, __webpack_exports__, __webpack_require__) {
  18709. "use strict";
  18710. __webpack_require__.r(__webpack_exports__);
  18711. /* harmony import */ var _babel_runtime_helpers_defineProperty__WEBPACK_IMPORTED_MODULE_0__ = __webpack_require__(/*! @babel/runtime/helpers/defineProperty */ "./node_modules/@babel/runtime/helpers/defineProperty.js");
  18712. /* harmony import */ var _babel_runtime_helpers_defineProperty__WEBPACK_IMPORTED_MODULE_0___default = /*#__PURE__*/__webpack_require__.n(_babel_runtime_helpers_defineProperty__WEBPACK_IMPORTED_MODULE_0__);
  18713. /* harmony import */ var underscore__WEBPACK_IMPORTED_MODULE_1__ = __webpack_require__(/*! underscore */ "./node_modules/underscore/underscore.js");
  18714. /* harmony import */ var underscore__WEBPACK_IMPORTED_MODULE_1___default = /*#__PURE__*/__webpack_require__.n(underscore__WEBPACK_IMPORTED_MODULE_1__);
  18715. /* harmony import */ var _config_config__WEBPACK_IMPORTED_MODULE_2__ = __webpack_require__(/*! ./config/config */ "./src/block_manager/config/config.js");
  18716. /* harmony import */ var _model_Blocks__WEBPACK_IMPORTED_MODULE_3__ = __webpack_require__(/*! ./model/Blocks */ "./src/block_manager/model/Blocks.js");
  18717. /* harmony import */ var _model_Categories__WEBPACK_IMPORTED_MODULE_4__ = __webpack_require__(/*! ./model/Categories */ "./src/block_manager/model/Categories.js");
  18718. /* harmony import */ var _view_BlocksView__WEBPACK_IMPORTED_MODULE_5__ = __webpack_require__(/*! ./view/BlocksView */ "./src/block_manager/view/BlocksView.js");
  18719. function ownKeys(object, enumerableOnly) { var keys = Object.keys(object); if (Object.getOwnPropertySymbols) { var symbols = Object.getOwnPropertySymbols(object); if (enumerableOnly) symbols = symbols.filter(function (sym) { return Object.getOwnPropertyDescriptor(object, sym).enumerable; }); keys.push.apply(keys, symbols); } return keys; }
  18720. function _objectSpread(target) { for (var i = 1; i < arguments.length; i++) { var source = arguments[i] != null ? arguments[i] : {}; if (i % 2) { ownKeys(source, true).forEach(function (key) { _babel_runtime_helpers_defineProperty__WEBPACK_IMPORTED_MODULE_0___default()(target, key, source[key]); }); } else if (Object.getOwnPropertyDescriptors) { Object.defineProperties(target, Object.getOwnPropertyDescriptors(source)); } else { ownKeys(source).forEach(function (key) { Object.defineProperty(target, key, Object.getOwnPropertyDescriptor(source, key)); }); } } return target; }
  18721. /**
  18722. * You can customize the initial state of the module from the editor initialization, by passing the following [Configuration Object](https://github.com/artf/grapesjs/blob/master/src/block_manager/config/config.js)
  18723. * ```js
  18724. * const editor = grapesjs.init({
  18725. * blockManager: {
  18726. * // options
  18727. * }
  18728. * })
  18729. * ```
  18730. *
  18731. * Once the editor is instantiated you can use its API. Before using these methods you should get the module from the instance
  18732. *
  18733. * ```js
  18734. * const blockManager = editor.BlockManager;
  18735. * ```
  18736. * * [add](#add)
  18737. * * [get](#get)
  18738. * * [getAll](#getall)
  18739. * * [getAllVisible](#getallvisible)
  18740. * * [remove](#remove)
  18741. * * [getConfig](#getconfig)
  18742. * * [getCategories](#getcategories)
  18743. * * [getContainer](#getcontainer)
  18744. * * [render](#render)
  18745. *
  18746. * @module BlockManager
  18747. */
  18748. /* harmony default export */ __webpack_exports__["default"] = (function () {
  18749. var c = {};
  18750. var blocks, blocksVisible, blocksView;
  18751. var categories = [];
  18752. return {
  18753. /**
  18754. * Name of the module
  18755. * @type {String}
  18756. * @private
  18757. */
  18758. name: 'BlockManager',
  18759. /**
  18760. * Initialize module. Automatically called with a new instance of the editor
  18761. * @param {Object} config Configurations
  18762. * @return {this}
  18763. * @private
  18764. */
  18765. init: function init(config) {
  18766. c = config || {};
  18767. var em = c.em;
  18768. for (var name in _config_config__WEBPACK_IMPORTED_MODULE_2__["default"]) {
  18769. if (!(name in c)) {
  18770. c[name] = _config_config__WEBPACK_IMPORTED_MODULE_2__["default"][name];
  18771. }
  18772. } // Global blocks collection
  18773. blocks = new _model_Blocks__WEBPACK_IMPORTED_MODULE_3__["default"]([]);
  18774. blocksVisible = new _model_Blocks__WEBPACK_IMPORTED_MODULE_3__["default"]([]);
  18775. categories = new _model_Categories__WEBPACK_IMPORTED_MODULE_4__["default"]();
  18776. blocksView = new _view_BlocksView__WEBPACK_IMPORTED_MODULE_5__["default"]({
  18777. collection: blocksVisible,
  18778. categories: categories
  18779. }, c); // Setup the sync between the global and public collections
  18780. blocks.listenTo(blocks, 'add', function (model) {
  18781. blocksVisible.add(model);
  18782. em && em.trigger('block:add', model);
  18783. });
  18784. blocks.listenTo(blocks, 'remove', function (model) {
  18785. blocksVisible.remove(model);
  18786. em && em.trigger('block:remove', model);
  18787. });
  18788. blocks.listenTo(blocks, 'reset', function (coll) {
  18789. blocksVisible.reset(coll.models);
  18790. });
  18791. return this;
  18792. },
  18793. /**
  18794. * Get configuration object
  18795. * @return {Object}
  18796. */
  18797. getConfig: function getConfig() {
  18798. return c;
  18799. },
  18800. /**
  18801. * Load default blocks if the collection is empty
  18802. */
  18803. onLoad: function onLoad() {
  18804. var blocks = this.getAll();
  18805. !blocks.length && blocks.reset(c.blocks);
  18806. },
  18807. postRender: function postRender() {
  18808. var elTo = this.getConfig().appendTo;
  18809. if (elTo) {
  18810. var el = Object(underscore__WEBPACK_IMPORTED_MODULE_1__["isElement"])(elTo) ? elTo : document.querySelector(elTo);
  18811. el.appendChild(this.render());
  18812. }
  18813. },
  18814. /**
  18815. * Add new block to the collection.
  18816. * @param {string} id Block id
  18817. * @param {Object} opts Options
  18818. * @param {string} opts.label Name of the block
  18819. * @param {string} opts.content HTML content
  18820. * @param {string|Object} opts.category Group the block inside a catgegory.
  18821. * You should pass objects with id property, eg:
  18822. * {id: 'some-uid', label: 'My category'}
  18823. * The string will be converted in:
  18824. * 'someid' => {id: 'someid', label: 'someid'}
  18825. * @param {Object} [opts.attributes={}] Block attributes
  18826. * @return {Block} Added block
  18827. * @example
  18828. * blockManager.add('h1-block', {
  18829. * label: 'Heading',
  18830. * content: '<h1>Put your title here</h1>',
  18831. * category: 'Basic',
  18832. * attributes: {
  18833. * title: 'Insert h1 block'
  18834. * }
  18835. * });
  18836. */
  18837. add: function add(id, opts) {
  18838. var obj = opts || {};
  18839. obj.id = id;
  18840. return blocks.add(obj);
  18841. },
  18842. /**
  18843. * Return the block by id
  18844. * @param {string} id Block id
  18845. * @example
  18846. * const block = blockManager.get('h1-block');
  18847. * console.log(JSON.stringify(block));
  18848. * // {label: 'Heading', content: '<h1>Put your ...', ...}
  18849. */
  18850. get: function get(id) {
  18851. return blocks.get(id);
  18852. },
  18853. /**
  18854. * Return all blocks
  18855. * @return {Collection}
  18856. * @example
  18857. * const blocks = blockManager.getAll();
  18858. * console.log(JSON.stringify(blocks));
  18859. * // [{label: 'Heading', content: '<h1>Put your ...'}, ...]
  18860. */
  18861. getAll: function getAll() {
  18862. return blocks;
  18863. },
  18864. /**
  18865. * Return the visible collection, which containes blocks actually rendered
  18866. * @return {Collection}
  18867. */
  18868. getAllVisible: function getAllVisible() {
  18869. return blocksVisible;
  18870. },
  18871. /**
  18872. * Remove a block by id
  18873. * @param {string} id Block id
  18874. * @return {Block} Removed block
  18875. */
  18876. remove: function remove(id) {
  18877. return blocks.remove(id);
  18878. },
  18879. /**
  18880. * Get all available categories.
  18881. * It's possible to add categories only within blocks via 'add()' method
  18882. * @return {Array|Collection}
  18883. */
  18884. getCategories: function getCategories() {
  18885. return categories;
  18886. },
  18887. /**
  18888. * Return the Blocks container element
  18889. * @return {HTMLElement}
  18890. */
  18891. getContainer: function getContainer() {
  18892. return blocksView.el;
  18893. },
  18894. /**
  18895. * Render blocks
  18896. * @param {Array} blocks Blocks to render, without the argument will render all global blocks
  18897. * @param {Object} [opts={}] Options
  18898. * @param {Boolean} [opts.external] Render blocks in a new container (HTMLElement will be returned)
  18899. * @param {Boolean} [opts.ignoreCategories] Render blocks without categories
  18900. * @return {HTMLElement} Rendered element
  18901. * @example
  18902. * // Render all blocks (inside the global collection)
  18903. * blockManager.render();
  18904. *
  18905. * // Render new set of blocks
  18906. * const blocks = blockManager.getAll();
  18907. * const filtered = blocks.filter(block => block.get('category') == 'sections')
  18908. *
  18909. * blockManager.render(filtered);
  18910. * // Or a new set from an array
  18911. * blockManager.render([
  18912. * {label: 'Label text', content: '<div>Content</div>'}
  18913. * ]);
  18914. *
  18915. * // Back to blocks from the global collection
  18916. * blockManager.render();
  18917. *
  18918. * // You can also render your blocks outside of the main block container
  18919. * const newBlocksEl = blockManager.render(filtered, { external: true });
  18920. * document.getElementById('some-id').appendChild(newBlocksEl);
  18921. */
  18922. render: function render(blocks) {
  18923. var opts = arguments.length > 1 && arguments[1] !== undefined ? arguments[1] : {};
  18924. var toRender = blocks || this.getAll().models;
  18925. if (opts.external) {
  18926. return new _view_BlocksView__WEBPACK_IMPORTED_MODULE_5__["default"]({
  18927. collection: new _model_Blocks__WEBPACK_IMPORTED_MODULE_3__["default"](toRender),
  18928. categories: categories
  18929. }, _objectSpread({}, c, {}, opts)).render().el;
  18930. }
  18931. if (!blocksView.rendered) {
  18932. blocksView.render();
  18933. blocksView.rendered = 1;
  18934. }
  18935. blocksView.updateConfig(opts);
  18936. blocksView.collection.reset(toRender);
  18937. return this.getContainer();
  18938. }
  18939. };
  18940. });
  18941. /***/ }),
  18942. /***/ "./src/block_manager/model/Block.js":
  18943. /*!******************************************!*\
  18944. !*** ./src/block_manager/model/Block.js ***!
  18945. \******************************************/
  18946. /*! exports provided: default */
  18947. /***/ (function(module, __webpack_exports__, __webpack_require__) {
  18948. "use strict";
  18949. __webpack_require__.r(__webpack_exports__);
  18950. /* harmony import */ var backbone__WEBPACK_IMPORTED_MODULE_0__ = __webpack_require__(/*! backbone */ "./node_modules/backbone/backbone.js");
  18951. /* harmony import */ var backbone__WEBPACK_IMPORTED_MODULE_0___default = /*#__PURE__*/__webpack_require__.n(backbone__WEBPACK_IMPORTED_MODULE_0__);
  18952. /* harmony import */ var _Category__WEBPACK_IMPORTED_MODULE_1__ = __webpack_require__(/*! ./Category */ "./src/block_manager/model/Category.js");
  18953. /* harmony default export */ __webpack_exports__["default"] = (backbone__WEBPACK_IMPORTED_MODULE_0___default.a.Model.extend({
  18954. defaults: {
  18955. // If true, triggers an 'active' event on dropped component
  18956. activate: 0,
  18957. // If true, the dropped component will be selected
  18958. select: 0,
  18959. // If true, all IDs of dropped component and its style will be changed
  18960. resetId: 0,
  18961. // Block label
  18962. label: '',
  18963. // Disable the drag of the block
  18964. disable: 0,
  18965. // HTML string for the media of the block, eg. SVG icon, image, etc.
  18966. media: '',
  18967. content: '',
  18968. category: '',
  18969. attributes: {}
  18970. },
  18971. initialize: function initialize() {
  18972. var opts = arguments.length > 0 && arguments[0] !== undefined ? arguments[0] : {};
  18973. var category = this.get('category');
  18974. if (category) {
  18975. if (typeof category == 'string') {
  18976. var catObj = new _Category__WEBPACK_IMPORTED_MODULE_1__["default"]({
  18977. id: category,
  18978. label: category
  18979. });
  18980. }
  18981. }
  18982. }
  18983. }));
  18984. /***/ }),
  18985. /***/ "./src/block_manager/model/Blocks.js":
  18986. /*!*******************************************!*\
  18987. !*** ./src/block_manager/model/Blocks.js ***!
  18988. \*******************************************/
  18989. /*! exports provided: default */
  18990. /***/ (function(module, __webpack_exports__, __webpack_require__) {
  18991. "use strict";
  18992. __webpack_require__.r(__webpack_exports__);
  18993. /* harmony import */ var backbone__WEBPACK_IMPORTED_MODULE_0__ = __webpack_require__(/*! backbone */ "./node_modules/backbone/backbone.js");
  18994. /* harmony import */ var backbone__WEBPACK_IMPORTED_MODULE_0___default = /*#__PURE__*/__webpack_require__.n(backbone__WEBPACK_IMPORTED_MODULE_0__);
  18995. /* harmony import */ var _Block__WEBPACK_IMPORTED_MODULE_1__ = __webpack_require__(/*! ./Block */ "./src/block_manager/model/Block.js");
  18996. /* harmony default export */ __webpack_exports__["default"] = (backbone__WEBPACK_IMPORTED_MODULE_0___default.a.Collection.extend({
  18997. model: _Block__WEBPACK_IMPORTED_MODULE_1__["default"]
  18998. }));
  18999. /***/ }),
  19000. /***/ "./src/block_manager/model/Categories.js":
  19001. /*!***********************************************!*\
  19002. !*** ./src/block_manager/model/Categories.js ***!
  19003. \***********************************************/
  19004. /*! exports provided: default */
  19005. /***/ (function(module, __webpack_exports__, __webpack_require__) {
  19006. "use strict";
  19007. __webpack_require__.r(__webpack_exports__);
  19008. /* harmony import */ var backbone__WEBPACK_IMPORTED_MODULE_0__ = __webpack_require__(/*! backbone */ "./node_modules/backbone/backbone.js");
  19009. /* harmony import */ var backbone__WEBPACK_IMPORTED_MODULE_0___default = /*#__PURE__*/__webpack_require__.n(backbone__WEBPACK_IMPORTED_MODULE_0__);
  19010. /* harmony import */ var _Category__WEBPACK_IMPORTED_MODULE_1__ = __webpack_require__(/*! ./Category */ "./src/block_manager/model/Category.js");
  19011. /* harmony default export */ __webpack_exports__["default"] = (backbone__WEBPACK_IMPORTED_MODULE_0___default.a.Collection.extend({
  19012. model: _Category__WEBPACK_IMPORTED_MODULE_1__["default"]
  19013. }));
  19014. /***/ }),
  19015. /***/ "./src/block_manager/model/Category.js":
  19016. /*!*********************************************!*\
  19017. !*** ./src/block_manager/model/Category.js ***!
  19018. \*********************************************/
  19019. /*! exports provided: default */
  19020. /***/ (function(module, __webpack_exports__, __webpack_require__) {
  19021. "use strict";
  19022. __webpack_require__.r(__webpack_exports__);
  19023. /* harmony import */ var backbone__WEBPACK_IMPORTED_MODULE_0__ = __webpack_require__(/*! backbone */ "./node_modules/backbone/backbone.js");
  19024. /* harmony import */ var backbone__WEBPACK_IMPORTED_MODULE_0___default = /*#__PURE__*/__webpack_require__.n(backbone__WEBPACK_IMPORTED_MODULE_0__);
  19025. /* harmony default export */ __webpack_exports__["default"] = (backbone__WEBPACK_IMPORTED_MODULE_0___default.a.Model.extend({
  19026. defaults: {
  19027. id: '',
  19028. label: '',
  19029. open: true,
  19030. attributes: {}
  19031. }
  19032. }));
  19033. /***/ }),
  19034. /***/ "./src/block_manager/view/BlockView.js":
  19035. /*!*********************************************!*\
  19036. !*** ./src/block_manager/view/BlockView.js ***!
  19037. \*********************************************/
  19038. /*! exports provided: default */
  19039. /***/ (function(module, __webpack_exports__, __webpack_require__) {
  19040. "use strict";
  19041. __webpack_require__.r(__webpack_exports__);
  19042. /* harmony import */ var backbone__WEBPACK_IMPORTED_MODULE_0__ = __webpack_require__(/*! backbone */ "./node_modules/backbone/backbone.js");
  19043. /* harmony import */ var backbone__WEBPACK_IMPORTED_MODULE_0___default = /*#__PURE__*/__webpack_require__.n(backbone__WEBPACK_IMPORTED_MODULE_0__);
  19044. /* harmony import */ var underscore__WEBPACK_IMPORTED_MODULE_1__ = __webpack_require__(/*! underscore */ "./node_modules/underscore/underscore.js");
  19045. /* harmony import */ var underscore__WEBPACK_IMPORTED_MODULE_1___default = /*#__PURE__*/__webpack_require__.n(underscore__WEBPACK_IMPORTED_MODULE_1__);
  19046. /* harmony import */ var utils_mixins__WEBPACK_IMPORTED_MODULE_2__ = __webpack_require__(/*! utils/mixins */ "./src/utils/mixins.js");
  19047. /* harmony default export */ __webpack_exports__["default"] = (backbone__WEBPACK_IMPORTED_MODULE_0___default.a.View.extend({
  19048. events: {
  19049. click: 'handleClick',
  19050. mousedown: 'startDrag',
  19051. dragstart: 'handleDragStart',
  19052. drag: 'handleDrag',
  19053. dragend: 'handleDragEnd'
  19054. },
  19055. initialize: function initialize(o) {
  19056. var config = arguments.length > 1 && arguments[1] !== undefined ? arguments[1] : {};
  19057. var model = this.model;
  19058. this.em = config.em;
  19059. this.config = config;
  19060. this.endDrag = this.endDrag.bind(this);
  19061. this.ppfx = config.pStylePrefix || '';
  19062. this.listenTo(model, 'destroy remove', this.remove);
  19063. this.listenTo(model, 'change', this.render);
  19064. },
  19065. handleClick: function handleClick() {
  19066. var config = this.config,
  19067. model = this.model,
  19068. em = this.em;
  19069. if (!config.appendOnClick) return;
  19070. var sorter = config.getSorter();
  19071. var content = model.get('content');
  19072. var selected = em.getSelected();
  19073. sorter.setDropContent(content);
  19074. var target, valid; // If there is a selected component, try first to append
  19075. // the block inside, otherwise, try to place it as a next sibling
  19076. if (selected) {
  19077. valid = sorter.validTarget(selected.getEl(), content);
  19078. if (valid.valid) {
  19079. target = selected;
  19080. } else {
  19081. var parent = selected.parent();
  19082. valid = sorter.validTarget(parent.getEl(), content);
  19083. if (valid.valid) target = parent;
  19084. }
  19085. } // If no target found yet, try to append the block to the wrapper
  19086. if (!target) {
  19087. var wrapper = em.getWrapper();
  19088. valid = sorter.validTarget(wrapper.getEl(), content);
  19089. if (valid.valid) target = wrapper;
  19090. }
  19091. var result = target && target.append(content)[0];
  19092. result && em.setSelected(result, {
  19093. scroll: 1
  19094. });
  19095. },
  19096. /**
  19097. * Start block dragging
  19098. * @private
  19099. */
  19100. startDrag: function startDrag(e) {
  19101. var config = this.config,
  19102. em = this.em,
  19103. model = this.model;
  19104. var disable = model.get('disable'); //Right or middel click
  19105. if (e.button !== 0 || !config.getSorter || this.el.draggable || disable) return;
  19106. em.refreshCanvas();
  19107. var sorter = config.getSorter();
  19108. sorter.setDragHelper(this.el, e);
  19109. sorter.setDropContent(this.model.get('content'));
  19110. sorter.startSort(this.el);
  19111. Object(utils_mixins__WEBPACK_IMPORTED_MODULE_2__["on"])(document, 'mouseup', this.endDrag);
  19112. },
  19113. handleDragStart: function handleDragStart(ev) {
  19114. var em = this.em,
  19115. model = this.model;
  19116. var content = model.get('content');
  19117. var isObj = Object(underscore__WEBPACK_IMPORTED_MODULE_1__["isObject"])(content);
  19118. var data = isObj ? JSON.stringify(content) : content;
  19119. em.set('dragResult'); // Note: data are not available on dragenter for security reason,
  19120. // we have to use dragContent as we need it for the Sorter context
  19121. // IE11 supports only 'text' data type
  19122. ev.dataTransfer.setData('text', data);
  19123. em.set('dragContent', content);
  19124. em.trigger('block:drag:start', model, ev);
  19125. },
  19126. handleDrag: function handleDrag(ev) {
  19127. this.em.trigger('block:drag', this.model, ev);
  19128. },
  19129. handleDragEnd: function handleDragEnd() {
  19130. var em = this.em,
  19131. model = this.model;
  19132. var result = em.get('dragResult');
  19133. if (result) {
  19134. var oldKey = 'activeOnRender';
  19135. var oldActive = result.get && result.get(oldKey);
  19136. if (model.get('activate') || oldActive) {
  19137. result.trigger('active');
  19138. result.set(oldKey, 0);
  19139. }
  19140. if (model.get('select')) {
  19141. em.setSelected(result);
  19142. }
  19143. if (model.get('resetId')) {
  19144. result.onAll(function (model) {
  19145. return model.resetId();
  19146. });
  19147. }
  19148. }
  19149. em.set({
  19150. dragResult: null,
  19151. dragContent: null
  19152. });
  19153. em.trigger('block:drag:stop', result, model);
  19154. },
  19155. /**
  19156. * Drop block
  19157. * @private
  19158. */
  19159. endDrag: function endDrag(e) {
  19160. Object(utils_mixins__WEBPACK_IMPORTED_MODULE_2__["off"])(document, 'mouseup', this.endDrag);
  19161. var sorter = this.config.getSorter(); // After dropping the block in the canvas the mouseup event is not yet
  19162. // triggerd on 'this.doc' and so clicking outside, the sorter, tries to move
  19163. // things (throws false positives). As this method just need to drop away
  19164. // the block helper I use the trick of 'moved = 0' to void those errors.
  19165. sorter.moved = 0;
  19166. sorter.endMove();
  19167. },
  19168. render: function render() {
  19169. var em = this.em,
  19170. el = this.el,
  19171. ppfx = this.ppfx,
  19172. model = this.model;
  19173. var disable = model.get('disable');
  19174. var attr = model.get('attributes') || {};
  19175. var cls = attr.class || '';
  19176. var className = "".concat(ppfx, "block");
  19177. var label = em && em.t("blockManager.labels.".concat(model.id)) || model.get('label');
  19178. var render = model.get('render');
  19179. var media = model.get('media');
  19180. var clsAdd = disable ? "".concat(className, "--disable") : "".concat(ppfx, "four-color-h");
  19181. el.className = "".concat(cls, " ").concat(className, " ").concat(ppfx, "one-bg ").concat(clsAdd).trim();
  19182. el.innerHTML = "\n ".concat(media ? "<div class=\"".concat(className, "__media\">").concat(media, "</div>") : '', "\n <div class=\"").concat(className, "-label\">").concat(label, "</div>\n ");
  19183. el.title = el.textContent.trim();
  19184. el.setAttribute('draggable', Object(utils_mixins__WEBPACK_IMPORTED_MODULE_2__["hasDnd"])(em) && !disable ? true : false);
  19185. var result = render && render({
  19186. el: el,
  19187. model: model,
  19188. className: className,
  19189. prefix: ppfx
  19190. });
  19191. if (result) el.innerHTML = result;
  19192. return this;
  19193. }
  19194. }));
  19195. /***/ }),
  19196. /***/ "./src/block_manager/view/BlocksView.js":
  19197. /*!**********************************************!*\
  19198. !*** ./src/block_manager/view/BlocksView.js ***!
  19199. \**********************************************/
  19200. /*! exports provided: default */
  19201. /***/ (function(module, __webpack_exports__, __webpack_require__) {
  19202. "use strict";
  19203. __webpack_require__.r(__webpack_exports__);
  19204. /* harmony import */ var _babel_runtime_helpers_defineProperty__WEBPACK_IMPORTED_MODULE_0__ = __webpack_require__(/*! @babel/runtime/helpers/defineProperty */ "./node_modules/@babel/runtime/helpers/defineProperty.js");
  19205. /* harmony import */ var _babel_runtime_helpers_defineProperty__WEBPACK_IMPORTED_MODULE_0___default = /*#__PURE__*/__webpack_require__.n(_babel_runtime_helpers_defineProperty__WEBPACK_IMPORTED_MODULE_0__);
  19206. /* harmony import */ var backbone__WEBPACK_IMPORTED_MODULE_1__ = __webpack_require__(/*! backbone */ "./node_modules/backbone/backbone.js");
  19207. /* harmony import */ var backbone__WEBPACK_IMPORTED_MODULE_1___default = /*#__PURE__*/__webpack_require__.n(backbone__WEBPACK_IMPORTED_MODULE_1__);
  19208. /* harmony import */ var underscore__WEBPACK_IMPORTED_MODULE_2__ = __webpack_require__(/*! underscore */ "./node_modules/underscore/underscore.js");
  19209. /* harmony import */ var underscore__WEBPACK_IMPORTED_MODULE_2___default = /*#__PURE__*/__webpack_require__.n(underscore__WEBPACK_IMPORTED_MODULE_2__);
  19210. /* harmony import */ var _BlockView__WEBPACK_IMPORTED_MODULE_3__ = __webpack_require__(/*! ./BlockView */ "./src/block_manager/view/BlockView.js");
  19211. /* harmony import */ var _CategoryView__WEBPACK_IMPORTED_MODULE_4__ = __webpack_require__(/*! ./CategoryView */ "./src/block_manager/view/CategoryView.js");
  19212. function ownKeys(object, enumerableOnly) { var keys = Object.keys(object); if (Object.getOwnPropertySymbols) { var symbols = Object.getOwnPropertySymbols(object); if (enumerableOnly) symbols = symbols.filter(function (sym) { return Object.getOwnPropertyDescriptor(object, sym).enumerable; }); keys.push.apply(keys, symbols); } return keys; }
  19213. function _objectSpread(target) { for (var i = 1; i < arguments.length; i++) { var source = arguments[i] != null ? arguments[i] : {}; if (i % 2) { ownKeys(source, true).forEach(function (key) { _babel_runtime_helpers_defineProperty__WEBPACK_IMPORTED_MODULE_0___default()(target, key, source[key]); }); } else if (Object.getOwnPropertyDescriptors) { Object.defineProperties(target, Object.getOwnPropertyDescriptors(source)); } else { ownKeys(source).forEach(function (key) { Object.defineProperty(target, key, Object.getOwnPropertyDescriptor(source, key)); }); } } return target; }
  19214. /* harmony default export */ __webpack_exports__["default"] = (backbone__WEBPACK_IMPORTED_MODULE_1___default.a.View.extend({
  19215. initialize: function initialize(opts, config) {
  19216. Object(underscore__WEBPACK_IMPORTED_MODULE_2__["bindAll"])(this, 'getSorter', 'onDrag', 'onDrop');
  19217. this.config = config || {};
  19218. this.categories = opts.categories || '';
  19219. this.renderedCategories = [];
  19220. var ppfx = this.config.pStylePrefix || '';
  19221. this.ppfx = ppfx;
  19222. this.noCatClass = "".concat(ppfx, "blocks-no-cat");
  19223. this.blockContClass = "".concat(ppfx, "blocks-c");
  19224. this.catsClass = "".concat(ppfx, "block-categories");
  19225. var coll = this.collection;
  19226. this.listenTo(coll, 'add', this.addTo);
  19227. this.listenTo(coll, 'reset', this.render);
  19228. this.em = this.config.em;
  19229. this.tac = 'test-tac';
  19230. this.grabbingCls = this.ppfx + 'grabbing';
  19231. if (this.em) {
  19232. this.config.getSorter = this.getSorter;
  19233. this.canvas = this.em.get('Canvas');
  19234. }
  19235. },
  19236. updateConfig: function updateConfig() {
  19237. var opts = arguments.length > 0 && arguments[0] !== undefined ? arguments[0] : {};
  19238. this.config = _objectSpread({}, this.config, {}, opts);
  19239. },
  19240. /**
  19241. * Get sorter
  19242. * @private
  19243. */
  19244. getSorter: function getSorter() {
  19245. if (!this.em) return;
  19246. if (!this.sorter) {
  19247. var utils = this.em.get('Utils');
  19248. var canvas = this.canvas;
  19249. this.sorter = new utils.Sorter({
  19250. container: canvas.getBody(),
  19251. placer: canvas.getPlacerEl(),
  19252. containerSel: '*',
  19253. itemSel: '*',
  19254. pfx: this.ppfx,
  19255. onStart: this.onDrag,
  19256. onEndMove: this.onDrop,
  19257. onMove: this.onMove,
  19258. document: canvas.getFrameEl().contentDocument,
  19259. direction: 'a',
  19260. wmargin: 1,
  19261. nested: 1,
  19262. em: this.em,
  19263. canvasRelative: 1
  19264. });
  19265. }
  19266. return this.sorter;
  19267. },
  19268. /**
  19269. * Callback when block is on drag
  19270. * @private
  19271. */
  19272. onDrag: function onDrag(e) {
  19273. this.em.stopDefault();
  19274. this.em.trigger('block:drag:start', e);
  19275. },
  19276. onMove: function onMove(e) {
  19277. this.em.trigger('block:drag:move', e);
  19278. },
  19279. /**
  19280. * Callback when block is dropped
  19281. * @private
  19282. */
  19283. onDrop: function onDrop(model) {
  19284. var em = this.em;
  19285. em.runDefault();
  19286. if (model && model.get) {
  19287. if (model.get('activeOnRender')) {
  19288. model.trigger('active');
  19289. model.set('activeOnRender', 0);
  19290. }
  19291. em.trigger('block:drag:stop', model);
  19292. }
  19293. },
  19294. /**
  19295. * Add new model to the collection
  19296. * @param {Model} model
  19297. * @private
  19298. * */
  19299. addTo: function addTo(model) {
  19300. this.add(model);
  19301. },
  19302. /**
  19303. * Render new model inside the view
  19304. * @param {Model} model
  19305. * @param {Object} fragment Fragment collection
  19306. * @private
  19307. * */
  19308. add: function add(model, fragment) {
  19309. var config = this.config;
  19310. var frag = fragment || null;
  19311. var view = new _BlockView__WEBPACK_IMPORTED_MODULE_3__["default"]({
  19312. model: model,
  19313. attributes: model.get('attributes')
  19314. }, config);
  19315. var rendered = view.render().el;
  19316. var category = model.get('category'); // Check for categories
  19317. if (category && this.categories && !config.ignoreCategories) {
  19318. if (Object(underscore__WEBPACK_IMPORTED_MODULE_2__["isString"])(category)) {
  19319. category = {
  19320. id: category,
  19321. label: category
  19322. };
  19323. } else if (Object(underscore__WEBPACK_IMPORTED_MODULE_2__["isObject"])(category) && !category.id) {
  19324. category.id = category.label;
  19325. }
  19326. var catModel = this.categories.add(category);
  19327. var catId = catModel.get('id');
  19328. var catView = this.renderedCategories[catId];
  19329. var categories = this.getCategoriesEl();
  19330. model.set('category', catModel);
  19331. if (!catView && categories) {
  19332. catView = new _CategoryView__WEBPACK_IMPORTED_MODULE_4__["default"]({
  19333. model: catModel
  19334. }, this.config).render();
  19335. this.renderedCategories[catId] = catView;
  19336. categories.appendChild(catView.el);
  19337. }
  19338. catView && catView.append(rendered);
  19339. return;
  19340. }
  19341. if (frag) frag.appendChild(rendered);else this.append(rendered);
  19342. },
  19343. getCategoriesEl: function getCategoriesEl() {
  19344. if (!this.catsEl) {
  19345. this.catsEl = this.el.querySelector(".".concat(this.catsClass));
  19346. }
  19347. return this.catsEl;
  19348. },
  19349. getBlocksEl: function getBlocksEl() {
  19350. if (!this.blocksEl) {
  19351. this.blocksEl = this.el.querySelector(".".concat(this.noCatClass, " .").concat(this.blockContClass));
  19352. }
  19353. return this.blocksEl;
  19354. },
  19355. append: function append(el) {
  19356. var blocks = this.getBlocksEl();
  19357. blocks && blocks.appendChild(el);
  19358. },
  19359. render: function render() {
  19360. var _this = this;
  19361. var ppfx = this.ppfx;
  19362. var frag = document.createDocumentFragment();
  19363. this.catsEl = null;
  19364. this.blocksEl = null;
  19365. this.renderedCategories = [];
  19366. this.el.innerHTML = "\n <div class=\"".concat(this.catsClass, "\"></div>\n <div class=\"").concat(this.noCatClass, "\">\n <div class=\"").concat(this.blockContClass, "\"></div>\n </div>\n ");
  19367. this.collection.each(function (model) {
  19368. return _this.add(model, frag);
  19369. });
  19370. this.append(frag);
  19371. var cls = "".concat(this.blockContClass, "s ").concat(ppfx, "one-bg ").concat(ppfx, "two-color");
  19372. this.$el.addClass(cls);
  19373. return this;
  19374. }
  19375. }));
  19376. /***/ }),
  19377. /***/ "./src/block_manager/view/CategoryView.js":
  19378. /*!************************************************!*\
  19379. !*** ./src/block_manager/view/CategoryView.js ***!
  19380. \************************************************/
  19381. /*! exports provided: default */
  19382. /***/ (function(module, __webpack_exports__, __webpack_require__) {
  19383. "use strict";
  19384. __webpack_require__.r(__webpack_exports__);
  19385. /* harmony import */ var underscore__WEBPACK_IMPORTED_MODULE_0__ = __webpack_require__(/*! underscore */ "./node_modules/underscore/underscore.js");
  19386. /* harmony import */ var underscore__WEBPACK_IMPORTED_MODULE_0___default = /*#__PURE__*/__webpack_require__.n(underscore__WEBPACK_IMPORTED_MODULE_0__);
  19387. /* harmony import */ var backbone__WEBPACK_IMPORTED_MODULE_1__ = __webpack_require__(/*! backbone */ "./node_modules/backbone/backbone.js");
  19388. /* harmony import */ var backbone__WEBPACK_IMPORTED_MODULE_1___default = /*#__PURE__*/__webpack_require__.n(backbone__WEBPACK_IMPORTED_MODULE_1__);
  19389. /* harmony default export */ __webpack_exports__["default"] = (backbone__WEBPACK_IMPORTED_MODULE_1___default.a.View.extend({
  19390. template: Object(underscore__WEBPACK_IMPORTED_MODULE_0__["template"])("\n <div class=\"<%= pfx %>title\">\n <i class=\"<%= pfx %>caret-icon\"></i>\n <%= label %>\n </div>\n <div class=\"<%= pfx %>blocks-c\"></div>\n "),
  19391. events: {},
  19392. initialize: function initialize() {
  19393. var o = arguments.length > 0 && arguments[0] !== undefined ? arguments[0] : {};
  19394. var config = arguments.length > 1 && arguments[1] !== undefined ? arguments[1] : {};
  19395. this.config = config;
  19396. var pfx = config.pStylePrefix || '';
  19397. this.em = config.em;
  19398. this.pfx = pfx;
  19399. this.caretR = 'fa fa-caret-right';
  19400. this.caretD = 'fa fa-caret-down';
  19401. this.iconClass = "".concat(pfx, "caret-icon");
  19402. this.activeClass = "".concat(pfx, "open");
  19403. this.className = "".concat(pfx, "block-category");
  19404. this.events["click .".concat(pfx, "title")] = 'toggle';
  19405. this.listenTo(this.model, 'change:open', this.updateVisibility);
  19406. this.delegateEvents();
  19407. },
  19408. updateVisibility: function updateVisibility() {
  19409. if (this.model.get('open')) this.open();else this.close();
  19410. },
  19411. open: function open() {
  19412. this.el.className = "".concat(this.className, " ").concat(this.activeClass);
  19413. this.getIconEl().className = "".concat(this.iconClass, " ").concat(this.caretD);
  19414. this.getBlocksEl().style.display = '';
  19415. },
  19416. close: function close() {
  19417. this.el.className = this.className;
  19418. this.getIconEl().className = "".concat(this.iconClass, " ").concat(this.caretR);
  19419. this.getBlocksEl().style.display = 'none';
  19420. },
  19421. toggle: function toggle() {
  19422. var model = this.model;
  19423. model.set('open', !model.get('open'));
  19424. },
  19425. getIconEl: function getIconEl() {
  19426. if (!this.iconEl) {
  19427. this.iconEl = this.el.querySelector('.' + this.iconClass);
  19428. }
  19429. return this.iconEl;
  19430. },
  19431. getBlocksEl: function getBlocksEl() {
  19432. if (!this.blocksEl) {
  19433. this.blocksEl = this.el.querySelector('.' + this.pfx + 'blocks-c');
  19434. }
  19435. return this.blocksEl;
  19436. },
  19437. append: function append(el) {
  19438. this.getBlocksEl().appendChild(el);
  19439. },
  19440. render: function render() {
  19441. var em = this.em,
  19442. el = this.el,
  19443. $el = this.$el,
  19444. model = this.model;
  19445. var label = em.t("blockManager.categories.".concat(model.id)) || model.get('label');
  19446. el.innerHTML = this.template({
  19447. pfx: this.pfx,
  19448. label: label
  19449. });
  19450. el.className = this.className;
  19451. $el.css({
  19452. order: model.get('order')
  19453. });
  19454. this.updateVisibility();
  19455. return this;
  19456. }
  19457. }));
  19458. /***/ }),
  19459. /***/ "./src/canvas/config/config.js":
  19460. /*!*************************************!*\
  19461. !*** ./src/canvas/config/config.js ***!
  19462. \*************************************/
  19463. /*! exports provided: default */
  19464. /***/ (function(module, __webpack_exports__, __webpack_require__) {
  19465. "use strict";
  19466. __webpack_require__.r(__webpack_exports__);
  19467. /* harmony default export */ __webpack_exports__["default"] = ({
  19468. stylePrefix: 'cv-',
  19469. /*
  19470. * Append external scripts to the `<head>` of the iframe.
  19471. * Be aware that these scripts will not be printed in the export code
  19472. * @example
  19473. * scripts: [ 'https://...1.js', 'https://...2.js' ]
  19474. * * // or passing objects as attributes
  19475. * scripts: [ { src: '/file.js', someattr: 'value' }, ... ]
  19476. */
  19477. scripts: [],
  19478. /*
  19479. * Append external styles to the `<head>` of the iframe
  19480. * Be aware that these styles will not be printed in the export code
  19481. * @example
  19482. * styles: [ 'https://...1.css', 'https://...2.css' ]
  19483. * // or passing objects as attributes
  19484. * scripts: [ { href: '/style.css', someattr: 'value' }, ... ]
  19485. */
  19486. styles: [],
  19487. /**
  19488. * Add custom badge naming strategy
  19489. * @example
  19490. * customBadgeLabel: function(component) {
  19491. * return component.getName();
  19492. * }
  19493. */
  19494. customBadgeLabel: '',
  19495. /**
  19496. * Indicate when to start the auto scroll of the canvas on component/block dragging (value in px )
  19497. */
  19498. autoscrollLimit: 50,
  19499. /**
  19500. * When some textable component is selected and focused (eg. input or text component) the editor
  19501. * stops some commands (eg. disables the copy/paste of components with CTRL+C/V to allow the copy/paste of the text).
  19502. * This option allows to customize, by a selector, which element should not be considered textable
  19503. */
  19504. notTextable: ['button', 'a', 'input[type=checkbox]', 'input[type=radio]']
  19505. });
  19506. /***/ }),
  19507. /***/ "./src/canvas/index.js":
  19508. /*!*****************************!*\
  19509. !*** ./src/canvas/index.js ***!
  19510. \*****************************/
  19511. /*! exports provided: default */
  19512. /***/ (function(module, __webpack_exports__, __webpack_require__) {
  19513. "use strict";
  19514. __webpack_require__.r(__webpack_exports__);
  19515. /* harmony import */ var _babel_runtime_helpers_toConsumableArray__WEBPACK_IMPORTED_MODULE_0__ = __webpack_require__(/*! @babel/runtime/helpers/toConsumableArray */ "./node_modules/@babel/runtime/helpers/toConsumableArray.js");
  19516. /* harmony import */ var _babel_runtime_helpers_toConsumableArray__WEBPACK_IMPORTED_MODULE_0___default = /*#__PURE__*/__webpack_require__.n(_babel_runtime_helpers_toConsumableArray__WEBPACK_IMPORTED_MODULE_0__);
  19517. /* harmony import */ var _babel_runtime_helpers_defineProperty__WEBPACK_IMPORTED_MODULE_1__ = __webpack_require__(/*! @babel/runtime/helpers/defineProperty */ "./node_modules/@babel/runtime/helpers/defineProperty.js");
  19518. /* harmony import */ var _babel_runtime_helpers_defineProperty__WEBPACK_IMPORTED_MODULE_1___default = /*#__PURE__*/__webpack_require__.n(_babel_runtime_helpers_defineProperty__WEBPACK_IMPORTED_MODULE_1__);
  19519. /* harmony import */ var utils_mixins__WEBPACK_IMPORTED_MODULE_2__ = __webpack_require__(/*! utils/mixins */ "./src/utils/mixins.js");
  19520. /* harmony import */ var underscore__WEBPACK_IMPORTED_MODULE_3__ = __webpack_require__(/*! underscore */ "./node_modules/underscore/underscore.js");
  19521. /* harmony import */ var underscore__WEBPACK_IMPORTED_MODULE_3___default = /*#__PURE__*/__webpack_require__.n(underscore__WEBPACK_IMPORTED_MODULE_3__);
  19522. /* harmony import */ var utils_Droppable__WEBPACK_IMPORTED_MODULE_4__ = __webpack_require__(/*! utils/Droppable */ "./src/utils/Droppable.js");
  19523. /* harmony import */ var _config_config__WEBPACK_IMPORTED_MODULE_5__ = __webpack_require__(/*! ./config/config */ "./src/canvas/config/config.js");
  19524. /* harmony import */ var _model_Canvas__WEBPACK_IMPORTED_MODULE_6__ = __webpack_require__(/*! ./model/Canvas */ "./src/canvas/model/Canvas.js");
  19525. /* harmony import */ var _view_CanvasView__WEBPACK_IMPORTED_MODULE_7__ = __webpack_require__(/*! ./view/CanvasView */ "./src/canvas/view/CanvasView.js");
  19526. function ownKeys(object, enumerableOnly) { var keys = Object.keys(object); if (Object.getOwnPropertySymbols) { var symbols = Object.getOwnPropertySymbols(object); if (enumerableOnly) symbols = symbols.filter(function (sym) { return Object.getOwnPropertyDescriptor(object, sym).enumerable; }); keys.push.apply(keys, symbols); } return keys; }
  19527. function _objectSpread(target) { for (var i = 1; i < arguments.length; i++) { var source = arguments[i] != null ? arguments[i] : {}; if (i % 2) { ownKeys(source, true).forEach(function (key) { _babel_runtime_helpers_defineProperty__WEBPACK_IMPORTED_MODULE_1___default()(target, key, source[key]); }); } else if (Object.getOwnPropertyDescriptors) { Object.defineProperties(target, Object.getOwnPropertyDescriptors(source)); } else { ownKeys(source).forEach(function (key) { Object.defineProperty(target, key, Object.getOwnPropertyDescriptor(source, key)); }); } } return target; }
  19528. /**
  19529. * You can customize the initial state of the module from the editor initialization, by passing the following [Configuration Object](https://github.com/artf/grapesjs/blob/master/src/canvas/config/config.js)
  19530. * ```js
  19531. * const editor = grapesjs.init({
  19532. * canvas: {
  19533. * // options
  19534. * }
  19535. * })
  19536. * ```
  19537. *
  19538. * Once the editor is instantiated you can use its API. Before using these methods you should get the module from the instance
  19539. *
  19540. * ```js
  19541. * const canvas = editor.Canvas;
  19542. * ```
  19543. *
  19544. * * [getConfig](#getconfig)
  19545. * * [getElement](#getelement)
  19546. * * [getFrameEl](#getframeel)
  19547. * * [getWindow](#getwindow)
  19548. * * [getDocument](#getdocument)
  19549. * * [getBody](#getbody)
  19550. * * [getWrapperEl](#getwrapperel)
  19551. * * [setCustomBadgeLabel](#setcustombadgelabel)
  19552. * * [hasFocus](#hasfocus)
  19553. * * [scrollTo](#scrollto)
  19554. * * [setZoom](#setzoom)
  19555. * * [getZoom](#getzoom)
  19556. *
  19557. * @module Canvas
  19558. */
  19559. var _window = window,
  19560. requestAnimationFrame = _window.requestAnimationFrame;
  19561. /* harmony default export */ __webpack_exports__["default"] = (function () {
  19562. var c = {};
  19563. var canvas;
  19564. var frameRect;
  19565. var CanvasView;
  19566. return {
  19567. /**
  19568. * Used inside RTE
  19569. * @private
  19570. */
  19571. getCanvasView: function getCanvasView() {
  19572. return CanvasView;
  19573. },
  19574. /**
  19575. * Name of the module
  19576. * @type {String}
  19577. * @private
  19578. */
  19579. name: 'Canvas',
  19580. /**
  19581. * Initialize module. Automatically called with a new instance of the editor
  19582. * @param {Object} config Configurations
  19583. * @private
  19584. */
  19585. init: function init() {
  19586. var config = arguments.length > 0 && arguments[0] !== undefined ? arguments[0] : {};
  19587. c = _objectSpread({}, _config_config__WEBPACK_IMPORTED_MODULE_5__["default"], {}, config, {
  19588. module: this
  19589. });
  19590. this.em = c.em;
  19591. var ppfx = c.pStylePrefix;
  19592. if (ppfx) c.stylePrefix = ppfx + c.stylePrefix;
  19593. canvas = new _model_Canvas__WEBPACK_IMPORTED_MODULE_6__["default"](config);
  19594. CanvasView = new _view_CanvasView__WEBPACK_IMPORTED_MODULE_7__["default"]({
  19595. model: canvas,
  19596. config: c
  19597. });
  19598. var cm = c.em.get('DomComponents');
  19599. if (cm) this.setWrapper(cm);
  19600. this.model = canvas;
  19601. this.startAutoscroll = this.startAutoscroll.bind(this);
  19602. this.stopAutoscroll = this.stopAutoscroll.bind(this);
  19603. return this;
  19604. },
  19605. /**
  19606. * Get the configuration object
  19607. * @return {Object}
  19608. */
  19609. getConfig: function getConfig() {
  19610. return c;
  19611. },
  19612. /**
  19613. * Add wrapper
  19614. * @param {Object} wrp Wrapper
  19615. * @private
  19616. * */
  19617. setWrapper: function setWrapper(wrp) {
  19618. canvas.set('wrapper', wrp);
  19619. },
  19620. /**
  19621. * Get the canvas element
  19622. * @return {HTMLElement}
  19623. */
  19624. getElement: function getElement() {
  19625. return CanvasView.el;
  19626. },
  19627. getFrame: function getFrame(index) {
  19628. return index ? this.getFrames()[index] : canvas.get('frame');
  19629. },
  19630. /**
  19631. * Get the iframe element of the canvas
  19632. * @return {HTMLIFrameElement}
  19633. */
  19634. getFrameEl: function getFrameEl() {
  19635. var _CanvasView = CanvasView,
  19636. frame = _CanvasView.frame;
  19637. return frame && frame.el;
  19638. },
  19639. getFramesEl: function getFramesEl() {
  19640. return CanvasView.framesArea;
  19641. },
  19642. /**
  19643. * Get the window instance of the iframe element
  19644. * @return {Window}
  19645. */
  19646. getWindow: function getWindow() {
  19647. return this.getFrameEl().contentWindow;
  19648. },
  19649. /**
  19650. * Get the document of the iframe element
  19651. * @return {HTMLDocument}
  19652. */
  19653. getDocument: function getDocument() {
  19654. var frame = this.getFrameEl();
  19655. return frame && frame.contentDocument;
  19656. },
  19657. /**
  19658. * Get the body of the iframe element
  19659. * @return {HTMLBodyElement}
  19660. */
  19661. getBody: function getBody() {
  19662. var doc = this.getDocument();
  19663. return doc && doc.body;
  19664. },
  19665. /**
  19666. * Get the wrapper element containing all the components
  19667. * @return {HTMLElement}
  19668. */
  19669. getWrapperEl: function getWrapperEl() {
  19670. var body = this.getBody();
  19671. return body && body.querySelector('#wrapper');
  19672. },
  19673. _getCompFrame: function _getCompFrame(compView) {
  19674. return compView && compView._getFrame();
  19675. },
  19676. _getLocalEl: function _getLocalEl(globalEl, compView, method) {
  19677. var result = globalEl;
  19678. var frameView = this._getCompFrame(compView);
  19679. result = frameView ? frameView[method]() : result;
  19680. return result;
  19681. },
  19682. /**
  19683. * Returns element containing all global canvas tools
  19684. * @return {HTMLElement}
  19685. * @private
  19686. */
  19687. getGlobalToolsEl: function getGlobalToolsEl() {
  19688. return CanvasView.toolsGlobEl;
  19689. },
  19690. /**
  19691. * Returns element containing all canvas tools
  19692. * @return {HTMLElement}
  19693. * @private
  19694. */
  19695. getToolsEl: function getToolsEl(compView) {
  19696. return this._getLocalEl(CanvasView.toolsEl, compView, 'getToolsEl');
  19697. },
  19698. /**
  19699. * Returns highlighter element
  19700. * @return {HTMLElement}
  19701. * @private
  19702. */
  19703. getHighlighter: function getHighlighter(compView) {
  19704. return this._getLocalEl(CanvasView.hlEl, compView, 'getHighlighter');
  19705. },
  19706. /**
  19707. * Returns badge element
  19708. * @return {HTMLElement}
  19709. * @private
  19710. */
  19711. getBadgeEl: function getBadgeEl(compView) {
  19712. return this._getLocalEl(CanvasView.badgeEl, compView, 'getBadgeEl');
  19713. },
  19714. /**
  19715. * Returns placer element
  19716. * @return {HTMLElement}
  19717. * @private
  19718. */
  19719. getPlacerEl: function getPlacerEl() {
  19720. return CanvasView.placerEl;
  19721. },
  19722. /**
  19723. * Returns ghost element
  19724. * @return {HTMLElement}
  19725. * @private
  19726. */
  19727. getGhostEl: function getGhostEl() {
  19728. return CanvasView.ghostEl;
  19729. },
  19730. /**
  19731. * Returns toolbar element
  19732. * @return {HTMLElement}
  19733. * @private
  19734. */
  19735. getToolbarEl: function getToolbarEl() {
  19736. return CanvasView.toolbarEl;
  19737. },
  19738. /**
  19739. * Returns resizer element
  19740. * @return {HTMLElement}
  19741. * @private
  19742. */
  19743. getResizerEl: function getResizerEl() {
  19744. return CanvasView.resizerEl;
  19745. },
  19746. /**
  19747. * Returns offset viewer element
  19748. * @return {HTMLElement}
  19749. * @private
  19750. */
  19751. getOffsetViewerEl: function getOffsetViewerEl(compView) {
  19752. return this._getLocalEl(CanvasView.offsetEl, compView, 'getOffsetViewerEl');
  19753. },
  19754. /**
  19755. * Returns fixed offset viewer element
  19756. * @return {HTMLElement}
  19757. * @private
  19758. */
  19759. getFixedOffsetViewerEl: function getFixedOffsetViewerEl() {
  19760. return CanvasView.fixedOffsetEl;
  19761. },
  19762. /**
  19763. * Render canvas
  19764. * @private
  19765. * */
  19766. render: function render() {
  19767. return CanvasView.render().el;
  19768. },
  19769. /**
  19770. * Get frame position
  19771. * @return {Object}
  19772. * @private
  19773. */
  19774. getOffset: function getOffset() {
  19775. var frameOff = this.offset(this.getFrameEl());
  19776. var canvasOff = this.offset(this.getElement());
  19777. return {
  19778. top: frameOff.top - canvasOff.top,
  19779. left: frameOff.left - canvasOff.left
  19780. };
  19781. },
  19782. /**
  19783. * Get the offset of the passed component element
  19784. * @param {HTMLElement} el
  19785. * @return {Object}
  19786. * @private
  19787. */
  19788. offset: function offset(el) {
  19789. return CanvasView.offset(el);
  19790. },
  19791. /**
  19792. * Set custom badge naming strategy
  19793. * @param {Function} f
  19794. * @example
  19795. * canvas.setCustomBadgeLabel(function(component){
  19796. * return component.getName();
  19797. * });
  19798. */
  19799. setCustomBadgeLabel: function setCustomBadgeLabel(f) {
  19800. c.customBadgeLabel = f;
  19801. },
  19802. /**
  19803. * Get element position relative to the canvas
  19804. * @param {HTMLElement} el
  19805. * @return {Object}
  19806. * @private
  19807. */
  19808. getElementPos: function getElementPos(el, opts) {
  19809. return CanvasView.getElementPos(el, opts);
  19810. },
  19811. /**
  19812. * Returns element's offsets like margins and paddings
  19813. * @param {HTMLElement} el
  19814. * @return {Object}
  19815. * @private
  19816. */
  19817. getElementOffsets: function getElementOffsets(el) {
  19818. return CanvasView.getElementOffsets(el);
  19819. },
  19820. /**
  19821. * Get canvas rectangular data
  19822. * @returns {Object}
  19823. */
  19824. getRect: function getRect() {
  19825. var _CanvasView$getPositi = CanvasView.getPosition(),
  19826. top = _CanvasView$getPositi.top,
  19827. left = _CanvasView$getPositi.left;
  19828. return _objectSpread({}, CanvasView.getCanvasOffset(), {
  19829. topScroll: top,
  19830. leftScroll: left
  19831. });
  19832. },
  19833. /**
  19834. * This method comes handy when you need to attach something like toolbars
  19835. * to elements inside the canvas, dealing with all relative position,
  19836. * offsets, etc. and returning as result the object with positions which are
  19837. * viewable by the user (when the canvas is scrolled the top edge of the element
  19838. * is not viewable by the user anymore so the new top edge is the one of the canvas)
  19839. *
  19840. * The target should be visible before being passed here as invisible elements
  19841. * return empty string as width
  19842. * @param {HTMLElement} target The target in this case could be the toolbar
  19843. * @param {HTMLElement} element The element on which I'd attach the toolbar
  19844. * @param {Object} options Custom options
  19845. * @param {Boolean} options.toRight Set to true if you want the toolbar attached to the right
  19846. * @return {Object}
  19847. * @private
  19848. */
  19849. getTargetToElementDim: function getTargetToElementDim(target, element) {
  19850. var options = arguments.length > 2 && arguments[2] !== undefined ? arguments[2] : {};
  19851. var opts = options || {};
  19852. var canvasPos = CanvasView.getPosition();
  19853. if (!canvasPos) return;
  19854. var pos = opts.elPos || CanvasView.getElementPos(element);
  19855. var toRight = options.toRight || 0;
  19856. var targetHeight = opts.targetHeight || target.offsetHeight;
  19857. var targetWidth = opts.targetWidth || target.offsetWidth;
  19858. var eventToTrigger = opts.event || null;
  19859. var elTop = pos.top - targetHeight;
  19860. var elLeft = pos.left;
  19861. elLeft += toRight ? pos.width : 0;
  19862. elLeft = toRight ? elLeft - targetWidth : elLeft;
  19863. var leftPos = elLeft < canvasPos.left ? canvasPos.left : elLeft;
  19864. var topPos = elTop < canvasPos.top ? canvasPos.top : elTop;
  19865. topPos = topPos > pos.top + pos.height ? pos.top + pos.height : topPos;
  19866. var result = {
  19867. top: topPos,
  19868. left: leftPos,
  19869. elementTop: pos.top,
  19870. elementLeft: pos.left,
  19871. elementWidth: pos.width,
  19872. elementHeight: pos.height,
  19873. targetWidth: target.offsetWidth,
  19874. targetHeight: target.offsetHeight,
  19875. canvasTop: canvasPos.top,
  19876. canvasLeft: canvasPos.left,
  19877. canvasWidth: canvasPos.width,
  19878. canvasHeight: canvasPos.height
  19879. }; // In this way I can catch data and also change the position strategy
  19880. if (eventToTrigger && c.em) {
  19881. c.em.trigger(eventToTrigger, result);
  19882. }
  19883. return result;
  19884. },
  19885. canvasRectOffset: function canvasRectOffset(el, pos) {
  19886. var _this = this;
  19887. var opts = arguments.length > 2 && arguments[2] !== undefined ? arguments[2] : {};
  19888. var getFrameElFromDoc = function getFrameElFromDoc(doc) {
  19889. var defaultView = doc.defaultView;
  19890. return defaultView && defaultView.frameElement;
  19891. };
  19892. var rectOff = function rectOff(el) {
  19893. var top = arguments.length > 1 && arguments[1] !== undefined ? arguments[1] : 1;
  19894. var pos = arguments.length > 2 ? arguments[2] : undefined;
  19895. var zoom = _this.em.getZoomDecimal();
  19896. var side = top ? 'top' : 'left';
  19897. var doc = el.ownerDocument;
  19898. var _ref = opts.offset ? getFrameElFromDoc(doc) : {},
  19899. _ref$offsetTop = _ref.offsetTop,
  19900. offsetTop = _ref$offsetTop === void 0 ? 0 : _ref$offsetTop,
  19901. _ref$offsetLeft = _ref.offsetLeft,
  19902. offsetLeft = _ref$offsetLeft === void 0 ? 0 : _ref$offsetLeft;
  19903. var _ref2 = doc.body || {},
  19904. _ref2$scrollTop = _ref2.scrollTop,
  19905. scrollTop = _ref2$scrollTop === void 0 ? 0 : _ref2$scrollTop,
  19906. _ref2$scrollLeft = _ref2.scrollLeft,
  19907. scrollLeft = _ref2$scrollLeft === void 0 ? 0 : _ref2$scrollLeft;
  19908. var scroll = top ? scrollTop : scrollLeft;
  19909. var offset = top ? offsetTop : offsetLeft; // if (!top) {
  19910. // console.log('LEFT', { posLeft: pos[side], scroll, offset }, el);
  19911. // }
  19912. return pos[side] - (scroll - offset) * zoom;
  19913. };
  19914. return {
  19915. top: rectOff(el, 1, pos),
  19916. left: rectOff(el, 0, pos)
  19917. };
  19918. },
  19919. getTargetToElementFixed: function getTargetToElementFixed(el, elToMove) {
  19920. var opts = arguments.length > 2 && arguments[2] !== undefined ? arguments[2] : {};
  19921. var pos = opts.pos || this.getElementPos(el);
  19922. var cvOff = opts.canvasOff || this.canvasRectOffset(el, pos);
  19923. var toolbarH = elToMove.offsetHeight || 0;
  19924. var toolbarW = elToMove.offsetWidth || 0;
  19925. var elRight = pos.left + pos.width;
  19926. var cv = this.getCanvasView();
  19927. var frCvOff = cv.getPosition();
  19928. var frameOffset = cv.getFrameOffset(el);
  19929. var event = opts.event;
  19930. var top = -toolbarH;
  19931. var left = pos.width - toolbarW;
  19932. left = pos.left < -left ? -pos.left : left;
  19933. left = elRight > frCvOff.width ? left - (elRight - frCvOff.width) : left; // Scroll with the window if the top edge is reached and the
  19934. // element is bigger than the canvas
  19935. var fullHeight = pos.height + toolbarH;
  19936. var elIsShort = fullHeight < frameOffset.height;
  19937. if (cvOff.top < toolbarH) {
  19938. if (elIsShort) {
  19939. top = top + fullHeight;
  19940. } else {
  19941. top = -cvOff.top < pos.height ? -cvOff.top : pos.height;
  19942. }
  19943. }
  19944. var result = {
  19945. top: top,
  19946. left: left,
  19947. canvasOffsetTop: cvOff.top,
  19948. canvasOffsetLeft: cvOff.left
  19949. }; // In this way I can catch data and also change the position strategy
  19950. event && this.em.trigger(event, result);
  19951. return result;
  19952. },
  19953. /**
  19954. * Instead of simply returning e.clientX and e.clientY this function
  19955. * calculates also the offset based on the canvas. This is helpful when you
  19956. * need to get X and Y position while moving between the editor area and
  19957. * canvas area, which is in the iframe
  19958. * @param {Event} e
  19959. * @return {Object}
  19960. * @private
  19961. */
  19962. getMouseRelativePos: function getMouseRelativePos(e, options) {
  19963. var opts = options || {};
  19964. var addTop = 0;
  19965. var addLeft = 0;
  19966. var subWinOffset = opts.subWinOffset;
  19967. var doc = e.target.ownerDocument;
  19968. var win = doc.defaultView || doc.parentWindow;
  19969. var frame = win.frameElement;
  19970. var yOffset = subWinOffset ? win.pageYOffset : 0;
  19971. var xOffset = subWinOffset ? win.pageXOffset : 0;
  19972. if (frame) {
  19973. var frameRect = frame.getBoundingClientRect();
  19974. addTop = frameRect.top || 0;
  19975. addLeft = frameRect.left || 0;
  19976. }
  19977. return {
  19978. y: e.clientY + addTop - yOffset,
  19979. x: e.clientX + addLeft - xOffset
  19980. };
  19981. },
  19982. /**
  19983. * X and Y mouse position relative to the canvas
  19984. * @param {Event} ev
  19985. * @return {Object}
  19986. * @private
  19987. */
  19988. getMouseRelativeCanvas: function getMouseRelativeCanvas(ev, opts) {
  19989. var zoom = this.getZoomDecimal();
  19990. var _CanvasView$getPositi2 = CanvasView.getPosition(opts),
  19991. top = _CanvasView$getPositi2.top,
  19992. left = _CanvasView$getPositi2.left;
  19993. return {
  19994. y: ev.clientY * zoom + top,
  19995. x: ev.clientX * zoom + left
  19996. };
  19997. },
  19998. /**
  19999. * Check if the canvas is focused
  20000. * @return {Boolean}
  20001. */
  20002. hasFocus: function hasFocus() {
  20003. return this.getDocument().hasFocus();
  20004. },
  20005. /**
  20006. * Detects if some input is focused (input elements, text components, etc.)
  20007. * @return {Boolean}
  20008. * @private
  20009. */
  20010. isInputFocused: function isInputFocused() {
  20011. var doc = this.getDocument();
  20012. var toIgnore = ['body'].concat(_babel_runtime_helpers_toConsumableArray__WEBPACK_IMPORTED_MODULE_0___default()(this.getConfig().notTextable));
  20013. var focused = doc && doc.activeElement;
  20014. return focused && !toIgnore.some(function (item) {
  20015. return focused.matches(item);
  20016. });
  20017. },
  20018. /**
  20019. * Scroll canvas to the element if it's not visible. The scrolling is
  20020. * executed via `scrollIntoView` API and options of this method are
  20021. * passed to it. For instance, you can scroll smoothly by using
  20022. * `{ behavior: 'smooth' }`.
  20023. * @param {HTMLElement|Component} el
  20024. * @param {Object} [opts={}] Options, same as options for `scrollIntoView`
  20025. * @param {Boolean} [opts.force=false] Force the scroll, even if the element is already visible
  20026. * @example
  20027. * const selected = editor.getSelected();
  20028. * // Scroll smoothly (this behavior can be polyfilled)
  20029. * canvas.scrollTo(selected, { behavior: 'smooth' });
  20030. * // Force the scroll, even if the element is alredy visible
  20031. * canvas.scrollTo(selected, { force: true });
  20032. */
  20033. scrollTo: function scrollTo(el) {
  20034. var opts = arguments.length > 1 && arguments[1] !== undefined ? arguments[1] : {};
  20035. var elem = Object(utils_mixins__WEBPACK_IMPORTED_MODULE_2__["getElement"])(el);
  20036. var view = elem && Object(utils_mixins__WEBPACK_IMPORTED_MODULE_2__["getViewEl"])(elem);
  20037. view && view.scrollIntoView(opts);
  20038. },
  20039. /**
  20040. * Start autoscroll
  20041. * @private
  20042. */
  20043. startAutoscroll: function startAutoscroll(frame) {
  20044. var fr = frame && frame.view || this.em.getCurrentFrame();
  20045. fr && fr.startAutoscroll();
  20046. },
  20047. /**
  20048. * Stop autoscroll
  20049. * @private
  20050. */
  20051. stopAutoscroll: function stopAutoscroll(frame) {
  20052. var fr = frame && frame.view || this.em.getCurrentFrame();
  20053. fr && fr.stopAutoscroll();
  20054. },
  20055. postRender: function postRender() {
  20056. if (Object(utils_mixins__WEBPACK_IMPORTED_MODULE_2__["hasDnd"])(c.em)) this.droppable = new utils_Droppable__WEBPACK_IMPORTED_MODULE_4__["default"](c.em);
  20057. },
  20058. /**
  20059. * Set zoom value
  20060. * @param {Number} value The zoom value, from 0 to 100
  20061. * @returns {this}
  20062. */
  20063. setZoom: function setZoom(value) {
  20064. canvas.set('zoom', parseFloat(value));
  20065. return this;
  20066. },
  20067. /**
  20068. * Get zoom value
  20069. * @returns {Number}
  20070. */
  20071. getZoom: function getZoom() {
  20072. return parseFloat(canvas.get('zoom'));
  20073. },
  20074. getZoomDecimal: function getZoomDecimal() {
  20075. return this.getZoom() / 100;
  20076. },
  20077. getZoomMultiplier: function getZoomMultiplier() {
  20078. var zoom = this.getZoomDecimal();
  20079. return zoom ? 1 / zoom : 1;
  20080. },
  20081. toggleFramesEvents: function toggleFramesEvents(on) {
  20082. var _this$getFramesEl = this.getFramesEl(),
  20083. style = _this$getFramesEl.style;
  20084. style.pointerEvents = on ? '' : 'none';
  20085. },
  20086. /**
  20087. * Returns wrapper element
  20088. * @return {HTMLElement}
  20089. * ????
  20090. * @private
  20091. */
  20092. getFrameWrapperEl: function getFrameWrapperEl() {
  20093. return CanvasView.frame.getWrapper();
  20094. },
  20095. getFrames: function getFrames() {
  20096. return canvas.get('frames').map(function (item) {
  20097. return item;
  20098. });
  20099. },
  20100. /**
  20101. * Add new frame to the canvas
  20102. * @param {Object} props Frame properties
  20103. * @returns {Frame}
  20104. * @example
  20105. *
  20106. editor.Canvas.addFrame({
  20107. name: 'Mobile home page',
  20108. x: 100, // Position in canvas
  20109. y: 100,
  20110. width: 500, // Frame dimensions
  20111. height: 600,
  20112. // device: 'DEVICE-ID',
  20113. components: [
  20114. '<h1 class="testh">Title frame</h1>',
  20115. '<p class="testp">Paragraph frame</p>',
  20116. ],
  20117. styles: `
  20118. .testh { color: red; }
  20119. .testp { color: blue; }
  20120. `,
  20121. });
  20122. */
  20123. addFrame: function addFrame() {
  20124. var props = arguments.length > 0 && arguments[0] !== undefined ? arguments[0] : {};
  20125. var opts = arguments.length > 1 && arguments[1] !== undefined ? arguments[1] : {};
  20126. return canvas.get('frames').add(_objectSpread({}, props), _objectSpread({}, opts, {
  20127. em: this.em
  20128. }));
  20129. }
  20130. };
  20131. });
  20132. /***/ }),
  20133. /***/ "./src/canvas/model/Canvas.js":
  20134. /*!************************************!*\
  20135. !*** ./src/canvas/model/Canvas.js ***!
  20136. \************************************/
  20137. /*! exports provided: default */
  20138. /***/ (function(module, __webpack_exports__, __webpack_require__) {
  20139. "use strict";
  20140. __webpack_require__.r(__webpack_exports__);
  20141. /* harmony import */ var backbone__WEBPACK_IMPORTED_MODULE_0__ = __webpack_require__(/*! backbone */ "./node_modules/backbone/backbone.js");
  20142. /* harmony import */ var backbone__WEBPACK_IMPORTED_MODULE_0___default = /*#__PURE__*/__webpack_require__.n(backbone__WEBPACK_IMPORTED_MODULE_0__);
  20143. /* harmony import */ var _Frame__WEBPACK_IMPORTED_MODULE_1__ = __webpack_require__(/*! ./Frame */ "./src/canvas/model/Frame.js");
  20144. /* harmony import */ var _Frames__WEBPACK_IMPORTED_MODULE_2__ = __webpack_require__(/*! ./Frames */ "./src/canvas/model/Frames.js");
  20145. /* harmony default export */ __webpack_exports__["default"] = (backbone__WEBPACK_IMPORTED_MODULE_0___default.a.Model.extend({
  20146. defaults: {
  20147. frame: '',
  20148. frames: '',
  20149. wrapper: '',
  20150. rulers: false,
  20151. zoom: 100,
  20152. x: 0,
  20153. y: 0
  20154. },
  20155. initialize: function initialize() {
  20156. var config = arguments.length > 0 && arguments[0] !== undefined ? arguments[0] : {};
  20157. var em = config.em;
  20158. var _config$styles = config.styles,
  20159. styles = _config$styles === void 0 ? [] : _config$styles,
  20160. _config$scripts = config.scripts,
  20161. scripts = _config$scripts === void 0 ? [] : _config$scripts;
  20162. var root = em && em.getWrapper();
  20163. var css = em && em.getStyle();
  20164. var frame = new _Frame__WEBPACK_IMPORTED_MODULE_1__["default"]({
  20165. root: root,
  20166. styles: css
  20167. }, config);
  20168. styles.forEach(function (style) {
  20169. return frame.addLink(style);
  20170. });
  20171. scripts.forEach(function (script) {
  20172. return frame.addScript(script);
  20173. });
  20174. this.em = em;
  20175. this.set('frame', frame);
  20176. this.set('frames', new _Frames__WEBPACK_IMPORTED_MODULE_2__["default"]([frame], config));
  20177. this.listenTo(this, 'change:zoom', this.onZoomChange);
  20178. this.listenTo(em, 'change:device', this.updateDevice);
  20179. },
  20180. updateDevice: function updateDevice() {
  20181. var em = this.em;
  20182. var device = em.getDeviceModel();
  20183. var model = em.getCurrentFrameModel();
  20184. if (model && device) {
  20185. var _device$attributes = device.attributes,
  20186. width = _device$attributes.width,
  20187. height = _device$attributes.height;
  20188. model.set({
  20189. width: width,
  20190. height: height
  20191. });
  20192. }
  20193. },
  20194. onZoomChange: function onZoomChange() {
  20195. var zoom = this.get('zoom');
  20196. zoom < 1 && this.set('zoom', 1);
  20197. }
  20198. }));
  20199. /***/ }),
  20200. /***/ "./src/canvas/model/Frame.js":
  20201. /*!***********************************!*\
  20202. !*** ./src/canvas/model/Frame.js ***!
  20203. \***********************************/
  20204. /*! exports provided: default */
  20205. /***/ (function(module, __webpack_exports__, __webpack_require__) {
  20206. "use strict";
  20207. __webpack_require__.r(__webpack_exports__);
  20208. /* harmony import */ var _babel_runtime_helpers_defineProperty__WEBPACK_IMPORTED_MODULE_0__ = __webpack_require__(/*! @babel/runtime/helpers/defineProperty */ "./node_modules/@babel/runtime/helpers/defineProperty.js");
  20209. /* harmony import */ var _babel_runtime_helpers_defineProperty__WEBPACK_IMPORTED_MODULE_0___default = /*#__PURE__*/__webpack_require__.n(_babel_runtime_helpers_defineProperty__WEBPACK_IMPORTED_MODULE_0__);
  20210. /* harmony import */ var _babel_runtime_helpers_toConsumableArray__WEBPACK_IMPORTED_MODULE_1__ = __webpack_require__(/*! @babel/runtime/helpers/toConsumableArray */ "./node_modules/@babel/runtime/helpers/toConsumableArray.js");
  20211. /* harmony import */ var _babel_runtime_helpers_toConsumableArray__WEBPACK_IMPORTED_MODULE_1___default = /*#__PURE__*/__webpack_require__.n(_babel_runtime_helpers_toConsumableArray__WEBPACK_IMPORTED_MODULE_1__);
  20212. /* harmony import */ var backbone__WEBPACK_IMPORTED_MODULE_2__ = __webpack_require__(/*! backbone */ "./node_modules/backbone/backbone.js");
  20213. /* harmony import */ var backbone__WEBPACK_IMPORTED_MODULE_2___default = /*#__PURE__*/__webpack_require__.n(backbone__WEBPACK_IMPORTED_MODULE_2__);
  20214. /* harmony import */ var dom_components_model_Component__WEBPACK_IMPORTED_MODULE_3__ = __webpack_require__(/*! dom_components/model/Component */ "./src/dom_components/model/Component.js");
  20215. /* harmony import */ var css_composer_model_CssRules__WEBPACK_IMPORTED_MODULE_4__ = __webpack_require__(/*! css_composer/model/CssRules */ "./src/css_composer/model/CssRules.js");
  20216. /* harmony import */ var underscore__WEBPACK_IMPORTED_MODULE_5__ = __webpack_require__(/*! underscore */ "./node_modules/underscore/underscore.js");
  20217. /* harmony import */ var underscore__WEBPACK_IMPORTED_MODULE_5___default = /*#__PURE__*/__webpack_require__.n(underscore__WEBPACK_IMPORTED_MODULE_5__);
  20218. function ownKeys(object, enumerableOnly) { var keys = Object.keys(object); if (Object.getOwnPropertySymbols) { var symbols = Object.getOwnPropertySymbols(object); if (enumerableOnly) symbols = symbols.filter(function (sym) { return Object.getOwnPropertyDescriptor(object, sym).enumerable; }); keys.push.apply(keys, symbols); } return keys; }
  20219. function _objectSpread(target) { for (var i = 1; i < arguments.length; i++) { var source = arguments[i] != null ? arguments[i] : {}; if (i % 2) { ownKeys(source, true).forEach(function (key) { _babel_runtime_helpers_defineProperty__WEBPACK_IMPORTED_MODULE_0___default()(target, key, source[key]); }); } else if (Object.getOwnPropertyDescriptors) { Object.defineProperties(target, Object.getOwnPropertyDescriptors(source)); } else { ownKeys(source).forEach(function (key) { Object.defineProperty(target, key, Object.getOwnPropertyDescriptor(source, key)); }); } } return target; }
  20220. /* harmony default export */ __webpack_exports__["default"] = (backbone__WEBPACK_IMPORTED_MODULE_2___default.a.Model.extend({
  20221. defaults: {
  20222. wrapper: '',
  20223. width: null,
  20224. height: null,
  20225. head: '',
  20226. x: 0,
  20227. y: 0,
  20228. root: 0,
  20229. components: 0,
  20230. styles: 0,
  20231. attributes: {}
  20232. },
  20233. initialize: function initialize(props) {
  20234. var opts = arguments.length > 1 && arguments[1] !== undefined ? arguments[1] : {};
  20235. var _this$attributes = this.attributes,
  20236. root = _this$attributes.root,
  20237. styles = _this$attributes.styles,
  20238. components = _this$attributes.components;
  20239. this.set('head', []);
  20240. this.em = opts.em;
  20241. var modOpts = {
  20242. em: opts.em,
  20243. config: opts.em.get('DomComponents').getConfig(),
  20244. frame: this
  20245. };
  20246. !root && this.set('root', new dom_components_model_Component__WEBPACK_IMPORTED_MODULE_3__["default"]({
  20247. type: 'wrapper',
  20248. components: components || []
  20249. }, modOpts));
  20250. (!styles || Object(underscore__WEBPACK_IMPORTED_MODULE_5__["isString"])(styles)) && this.set('styles', new css_composer_model_CssRules__WEBPACK_IMPORTED_MODULE_4__["default"](styles, modOpts));
  20251. },
  20252. remove: function remove() {
  20253. this.view = 0;
  20254. var coll = this.collection;
  20255. return coll && coll.remove(this);
  20256. },
  20257. getHead: function getHead() {
  20258. return _babel_runtime_helpers_toConsumableArray__WEBPACK_IMPORTED_MODULE_1___default()(this.get('head'));
  20259. },
  20260. setHead: function setHead(value) {
  20261. return this.set('head', _babel_runtime_helpers_toConsumableArray__WEBPACK_IMPORTED_MODULE_1___default()(value));
  20262. },
  20263. addHeadItem: function addHeadItem(item) {
  20264. var head = this.getHead();
  20265. head.push(item);
  20266. this.setHead(head);
  20267. },
  20268. getHeadByAttr: function getHeadByAttr(attr, value, tag) {
  20269. var head = this.getHead();
  20270. return head.filter(function (item) {
  20271. return item.attributes && item.attributes[attr] == value && (!tag || tag === item.tag);
  20272. })[0];
  20273. },
  20274. removeHeadByAttr: function removeHeadByAttr(attr, value, tag) {
  20275. var head = this.getHead();
  20276. var item = this.getHeadByAttr(attr, value, tag);
  20277. var index = head.indexOf(item);
  20278. if (index >= 0) {
  20279. head.splice(index, 1);
  20280. this.setHead(head);
  20281. }
  20282. },
  20283. addLink: function addLink(href) {
  20284. var tag = 'link';
  20285. !this.getHeadByAttr('href', href, tag) && this.addHeadItem({
  20286. tag: tag,
  20287. attributes: {
  20288. href: href,
  20289. rel: 'stylesheet'
  20290. }
  20291. });
  20292. },
  20293. removeLink: function removeLink(href) {
  20294. this.removeHeadByAttr('href', href, 'link');
  20295. },
  20296. addScript: function addScript(src) {
  20297. var tag = 'script';
  20298. !this.getHeadByAttr('src', src, tag) && this.addHeadItem({
  20299. tag: tag,
  20300. attributes: {
  20301. src: src
  20302. }
  20303. });
  20304. },
  20305. removeScript: function removeScript(src) {
  20306. this.removeHeadByAttr('src', src, 'script');
  20307. },
  20308. _emitUpdated: function _emitUpdated() {
  20309. var data = arguments.length > 0 && arguments[0] !== undefined ? arguments[0] : {};
  20310. this.em.trigger('frame:updated', _objectSpread({
  20311. frame: this
  20312. }, data));
  20313. }
  20314. }));
  20315. /***/ }),
  20316. /***/ "./src/canvas/model/Frames.js":
  20317. /*!************************************!*\
  20318. !*** ./src/canvas/model/Frames.js ***!
  20319. \************************************/
  20320. /*! exports provided: default */
  20321. /***/ (function(module, __webpack_exports__, __webpack_require__) {
  20322. "use strict";
  20323. __webpack_require__.r(__webpack_exports__);
  20324. /* harmony import */ var underscore__WEBPACK_IMPORTED_MODULE_0__ = __webpack_require__(/*! underscore */ "./node_modules/underscore/underscore.js");
  20325. /* harmony import */ var underscore__WEBPACK_IMPORTED_MODULE_0___default = /*#__PURE__*/__webpack_require__.n(underscore__WEBPACK_IMPORTED_MODULE_0__);
  20326. /* harmony import */ var backbone__WEBPACK_IMPORTED_MODULE_1__ = __webpack_require__(/*! backbone */ "./node_modules/backbone/backbone.js");
  20327. /* harmony import */ var backbone__WEBPACK_IMPORTED_MODULE_1___default = /*#__PURE__*/__webpack_require__.n(backbone__WEBPACK_IMPORTED_MODULE_1__);
  20328. /* harmony import */ var _Frame__WEBPACK_IMPORTED_MODULE_2__ = __webpack_require__(/*! ./Frame */ "./src/canvas/model/Frame.js");
  20329. /* harmony default export */ __webpack_exports__["default"] = (backbone__WEBPACK_IMPORTED_MODULE_1___default.a.Collection.extend({
  20330. model: _Frame__WEBPACK_IMPORTED_MODULE_2__["default"],
  20331. initialize: function initialize() {
  20332. Object(underscore__WEBPACK_IMPORTED_MODULE_0__["bindAll"])(this, 'itemLoaded');
  20333. },
  20334. itemLoaded: function itemLoaded() {
  20335. this.loadedItems++;
  20336. if (this.loadedItems >= this.itemsToLoad) {
  20337. this.trigger('loaded:all');
  20338. this.listenToLoadItems(0);
  20339. }
  20340. },
  20341. listenToLoad: function listenToLoad() {
  20342. this.loadedItems = 0;
  20343. this.itemsToLoad = this.length;
  20344. this.listenToLoadItems(1);
  20345. },
  20346. listenToLoadItems: function listenToLoadItems(on) {
  20347. var _this = this;
  20348. this.forEach(function (item) {
  20349. return item[on ? 'on' : 'off']('loaded', _this.itemLoaded);
  20350. });
  20351. }
  20352. }));
  20353. /***/ }),
  20354. /***/ "./src/canvas/view/CanvasView.js":
  20355. /*!***************************************!*\
  20356. !*** ./src/canvas/view/CanvasView.js ***!
  20357. \***************************************/
  20358. /*! exports provided: default */
  20359. /***/ (function(module, __webpack_exports__, __webpack_require__) {
  20360. "use strict";
  20361. __webpack_require__.r(__webpack_exports__);
  20362. /* harmony import */ var _babel_runtime_helpers_defineProperty__WEBPACK_IMPORTED_MODULE_0__ = __webpack_require__(/*! @babel/runtime/helpers/defineProperty */ "./node_modules/@babel/runtime/helpers/defineProperty.js");
  20363. /* harmony import */ var _babel_runtime_helpers_defineProperty__WEBPACK_IMPORTED_MODULE_0___default = /*#__PURE__*/__webpack_require__.n(_babel_runtime_helpers_defineProperty__WEBPACK_IMPORTED_MODULE_0__);
  20364. /* harmony import */ var backbone__WEBPACK_IMPORTED_MODULE_1__ = __webpack_require__(/*! backbone */ "./node_modules/backbone/backbone.js");
  20365. /* harmony import */ var backbone__WEBPACK_IMPORTED_MODULE_1___default = /*#__PURE__*/__webpack_require__.n(backbone__WEBPACK_IMPORTED_MODULE_1__);
  20366. /* harmony import */ var underscore__WEBPACK_IMPORTED_MODULE_2__ = __webpack_require__(/*! underscore */ "./node_modules/underscore/underscore.js");
  20367. /* harmony import */ var underscore__WEBPACK_IMPORTED_MODULE_2___default = /*#__PURE__*/__webpack_require__.n(underscore__WEBPACK_IMPORTED_MODULE_2__);
  20368. /* harmony import */ var utils_mixins__WEBPACK_IMPORTED_MODULE_3__ = __webpack_require__(/*! utils/mixins */ "./src/utils/mixins.js");
  20369. /* harmony import */ var _FramesView__WEBPACK_IMPORTED_MODULE_4__ = __webpack_require__(/*! ./FramesView */ "./src/canvas/view/FramesView.js");
  20370. function ownKeys(object, enumerableOnly) { var keys = Object.keys(object); if (Object.getOwnPropertySymbols) { var symbols = Object.getOwnPropertySymbols(object); if (enumerableOnly) symbols = symbols.filter(function (sym) { return Object.getOwnPropertyDescriptor(object, sym).enumerable; }); keys.push.apply(keys, symbols); } return keys; }
  20371. function _objectSpread(target) { for (var i = 1; i < arguments.length; i++) { var source = arguments[i] != null ? arguments[i] : {}; if (i % 2) { ownKeys(source, true).forEach(function (key) { _babel_runtime_helpers_defineProperty__WEBPACK_IMPORTED_MODULE_0___default()(target, key, source[key]); }); } else if (Object.getOwnPropertyDescriptors) { Object.defineProperties(target, Object.getOwnPropertyDescriptors(source)); } else { ownKeys(source).forEach(function (key) { Object.defineProperty(target, key, Object.getOwnPropertyDescriptor(source, key)); }); } } return target; }
  20372. var $ = backbone__WEBPACK_IMPORTED_MODULE_1___default.a.$;
  20373. var timerZoom;
  20374. /* harmony default export */ __webpack_exports__["default"] = (backbone__WEBPACK_IMPORTED_MODULE_1___default.a.View.extend({
  20375. events: {
  20376. wheel: 'onWheel'
  20377. },
  20378. template: function template() {
  20379. var pfx = this.pfx;
  20380. return "\n <div class=\"".concat(pfx, "canvas__frames\" data-frames></div>\n <div id=\"").concat(pfx, "tools\" class=\"").concat(pfx, "canvas__tools\" data-tools></div>\n ");
  20381. },
  20382. initialize: function initialize(o) {
  20383. Object(underscore__WEBPACK_IMPORTED_MODULE_2__["bindAll"])(this, 'clearOff', 'onKeyPress', 'onCanvasMove');
  20384. Object(utils_mixins__WEBPACK_IMPORTED_MODULE_3__["on"])(window, 'scroll resize', this.clearOff);
  20385. var model = this.model;
  20386. var frames = model.get('frames');
  20387. this.config = o.config || {};
  20388. this.em = this.config.em || {};
  20389. this.pfx = this.config.stylePrefix || '';
  20390. this.ppfx = this.config.pStylePrefix || '';
  20391. this.className = this.config.stylePrefix + 'canvas';
  20392. var em = this.em,
  20393. config = this.config;
  20394. this.frames = new _FramesView__WEBPACK_IMPORTED_MODULE_4__["default"]({
  20395. collection: frames,
  20396. config: _objectSpread({}, config, {
  20397. canvasView: this,
  20398. renderContent: 1
  20399. })
  20400. });
  20401. this.listenTo(em, 'change:canvasOffset', this.clearOff);
  20402. this.listenTo(em, 'component:selected', this.checkSelected);
  20403. this.listenTo(model, 'change:zoom change:x change:y', this.updateFrames);
  20404. this.listenTo(frames, 'loaded:all', function () {
  20405. return em.trigger('loaded');
  20406. });
  20407. this.toggleListeners(1);
  20408. },
  20409. checkSelected: function checkSelected(component) {
  20410. var opts = arguments.length > 1 && arguments[1] !== undefined ? arguments[1] : {};
  20411. var scroll = opts.scroll;
  20412. var currFrame = this.em.get('currentFrame');
  20413. scroll && component.views.forEach(function (view) {
  20414. view._getFrame() !== currFrame && view.scrollIntoView(scroll);
  20415. });
  20416. },
  20417. remove: function remove() {
  20418. backbone__WEBPACK_IMPORTED_MODULE_1___default.a.View.prototype.remove.apply(this, arguments);
  20419. this.toggleListeners();
  20420. },
  20421. preventDefault: function preventDefault(ev) {
  20422. if (ev) {
  20423. ev.preventDefault();
  20424. ev._parentEvent && ev._parentEvent.preventDefault();
  20425. }
  20426. },
  20427. onCanvasMove: function onCanvasMove(ev) {// const data = { x: ev.clientX, y: ev.clientY };
  20428. // const data2 = this.em.get('Canvas').getMouseRelativeCanvas(ev);
  20429. // const data3 = this.em.get('Canvas').getMouseRelativePos(ev);
  20430. // this.em.trigger('canvas:over', data, data2, data3);
  20431. },
  20432. toggleListeners: function toggleListeners(enable) {
  20433. var el = this.el;
  20434. var fn = enable ? utils_mixins__WEBPACK_IMPORTED_MODULE_3__["on"] : utils_mixins__WEBPACK_IMPORTED_MODULE_3__["off"];
  20435. fn(document, 'keypress', this.onKeyPress); // fn(el, 'mousemove dragover', this.onCanvasMove);
  20436. },
  20437. onKeyPress: function onKeyPress(ev) {
  20438. var em = this.em;
  20439. var key = Object(utils_mixins__WEBPACK_IMPORTED_MODULE_3__["getKeyChar"])(ev);
  20440. if (key === ' ' && em.getZoomDecimal() !== 1) {
  20441. this.preventDefault(ev);
  20442. em.get('Editor').runCommand('core:canvas-move');
  20443. }
  20444. },
  20445. onWheel: function onWheel(ev) {
  20446. if ((ev.ctrlKey || ev.metaKey) && this.em.getConfig('multiFrames')) {
  20447. this.preventDefault(ev);
  20448. var model = this.model;
  20449. var delta = Math.max(-1, Math.min(1, ev.wheelDelta || -ev.detail));
  20450. var zoom = model.get('zoom');
  20451. model.set('zoom', zoom + delta * 2);
  20452. }
  20453. },
  20454. updateFrames: function updateFrames(ev) {
  20455. var em = this.em,
  20456. model = this.model;
  20457. var _model$attributes = model.attributes,
  20458. x = _model$attributes.x,
  20459. y = _model$attributes.y;
  20460. var zoom = this.getZoom();
  20461. var defOpts = {
  20462. preserveSelected: 1
  20463. };
  20464. var mpl = zoom ? 1 / zoom : 1;
  20465. this.framesArea.style.transform = "scale(".concat(zoom, ") translate(").concat(x * mpl, "px, ").concat(y * mpl, "px)");
  20466. this.clearOff();
  20467. em.stopDefault(defOpts);
  20468. em.trigger('canvas:update', ev);
  20469. timerZoom && clearTimeout(timerZoom);
  20470. timerZoom = setTimeout(function () {
  20471. return em.runDefault(defOpts);
  20472. }, 300);
  20473. },
  20474. getZoom: function getZoom() {
  20475. return this.em.getZoomDecimal();
  20476. },
  20477. /**
  20478. * Checks if the element is visible in the canvas's viewport
  20479. * @param {HTMLElement} el
  20480. * @return {Boolean}
  20481. */
  20482. isElInViewport: function isElInViewport(el) {
  20483. var elem = Object(utils_mixins__WEBPACK_IMPORTED_MODULE_3__["getElement"])(el);
  20484. var rect = Object(utils_mixins__WEBPACK_IMPORTED_MODULE_3__["getElRect"])(elem);
  20485. var frameRect = this.getFrameOffset(elem);
  20486. var rTop = rect.top;
  20487. var rLeft = rect.left;
  20488. return rTop >= 0 && rLeft >= 0 && rTop <= frameRect.height && rLeft <= frameRect.width;
  20489. },
  20490. /**
  20491. * Get the offset of the element
  20492. * @param {HTMLElement} el
  20493. * @return {Object}
  20494. */
  20495. offset: function offset(el) {
  20496. var opts = arguments.length > 1 && arguments[1] !== undefined ? arguments[1] : {};
  20497. var rect = Object(utils_mixins__WEBPACK_IMPORTED_MODULE_3__["getElRect"])(el);
  20498. var docBody = el.ownerDocument.body;
  20499. var noScroll = opts.noScroll;
  20500. return {
  20501. top: rect.top + (noScroll ? 0 : docBody.scrollTop),
  20502. left: rect.left + (noScroll ? 0 : docBody.scrollLeft),
  20503. width: rect.width,
  20504. height: rect.height
  20505. };
  20506. },
  20507. /**
  20508. * Cleare cached offsets
  20509. * @private
  20510. */
  20511. clearOff: function clearOff() {
  20512. this.frmOff = null;
  20513. this.cvsOff = null;
  20514. },
  20515. /**
  20516. * Return frame offset
  20517. * @return {Object}
  20518. * @private
  20519. */
  20520. getFrameOffset: function getFrameOffset(el) {
  20521. if (!this.frmOff || el) {
  20522. var frEl = el ? el.ownerDocument.defaultView.frameElement : this.frame.el;
  20523. this.frmOff = this.offset(frEl);
  20524. }
  20525. return this.frmOff;
  20526. },
  20527. /**
  20528. * Return canvas offset
  20529. * @return {Object}
  20530. * @private
  20531. */
  20532. getCanvasOffset: function getCanvasOffset() {
  20533. if (!this.cvsOff) this.cvsOff = this.offset(this.el);
  20534. return this.cvsOff;
  20535. },
  20536. /**
  20537. * Returns element's rect info
  20538. * @param {HTMLElement} el
  20539. * @return {Object}
  20540. * @private
  20541. */
  20542. getElementPos: function getElementPos(el, opts) {
  20543. var zoom = this.getZoom();
  20544. var opt = opts || {};
  20545. var frmOff = this.getFrameOffset(el);
  20546. var cvsOff = this.getCanvasOffset();
  20547. var eo = this.offset(el, opts);
  20548. var frmTop = opt.avoidFrameOffset ? 0 : frmOff.top;
  20549. var frmLeft = opt.avoidFrameOffset ? 0 : frmOff.left;
  20550. var top = eo.top * zoom + frmTop - cvsOff.top;
  20551. var left = eo.left * zoom + frmLeft - cvsOff.left;
  20552. var height = eo.height * zoom;
  20553. var width = eo.width * zoom;
  20554. return {
  20555. top: top,
  20556. left: left,
  20557. height: height,
  20558. width: width,
  20559. zoom: zoom,
  20560. rect: eo
  20561. };
  20562. },
  20563. /**
  20564. * Returns element's offsets like margins and paddings
  20565. * @param {HTMLElement} el
  20566. * @return {Object}
  20567. * @private
  20568. */
  20569. getElementOffsets: function getElementOffsets(el) {
  20570. var _this = this;
  20571. if (!el || Object(utils_mixins__WEBPACK_IMPORTED_MODULE_3__["isTextNode"])(el)) return {};
  20572. var result = {};
  20573. var styles = window.getComputedStyle(el);
  20574. ['marginTop', 'marginRight', 'marginBottom', 'marginLeft', 'paddingTop', 'paddingRight', 'paddingBottom', 'paddingLeft'].forEach(function (offset) {
  20575. result[offset] = parseFloat(styles[offset]) * _this.getZoom();
  20576. });
  20577. return result;
  20578. },
  20579. /**
  20580. * Returns position data of the canvas element
  20581. * @return {Object} obj Position object
  20582. * @private
  20583. */
  20584. getPosition: function getPosition() {
  20585. var opts = arguments.length > 0 && arguments[0] !== undefined ? arguments[0] : {};
  20586. var doc = this.frame.el.contentDocument;
  20587. if (!doc) return;
  20588. var bEl = doc.body;
  20589. var zoom = this.getZoom();
  20590. var fo = this.getFrameOffset();
  20591. var co = this.getCanvasOffset();
  20592. var noScroll = opts.noScroll;
  20593. return {
  20594. top: fo.top + (noScroll ? 0 : bEl.scrollTop) * zoom - co.top,
  20595. left: fo.left + (noScroll ? 0 : bEl.scrollLeft) * zoom - co.left,
  20596. width: co.width,
  20597. height: co.height
  20598. };
  20599. },
  20600. /**
  20601. * Update javascript of a specific component passed by its View
  20602. * @param {View} view Component's View
  20603. * @private
  20604. */
  20605. updateScript: function updateScript(view) {
  20606. var model = view.model;
  20607. var id = model.getId();
  20608. if (!view.scriptContainer) {
  20609. view.scriptContainer = $("<div data-id=\"".concat(id, "\">"));
  20610. this.getJsContainer().appendChild(view.scriptContainer.get(0));
  20611. }
  20612. view.el.id = id;
  20613. view.scriptContainer.html(''); // In editor, I make use of setTimeout as during the append process of elements
  20614. // those will not be available immediately, therefore 'item' variable
  20615. var script = document.createElement('script');
  20616. script.innerHTML = "\n setTimeout(function() {\n var item = document.getElementById('".concat(id, "');\n if (!item) return;\n (function(){\n ").concat(model.getScriptString(), ";\n }.bind(item))()\n }, 1);"); // #873
  20617. // Adding setTimeout will make js components work on init of the editor
  20618. setTimeout(function () {
  20619. return view.scriptContainer.get(0).appendChild(script);
  20620. }, 0);
  20621. },
  20622. /**
  20623. * Get javascript container
  20624. * @private
  20625. */
  20626. getJsContainer: function getJsContainer(view) {
  20627. var frameView = this.getFrameView(view);
  20628. return frameView && frameView.getJsContainer();
  20629. },
  20630. getFrameView: function getFrameView(view) {
  20631. return view && view._getFrame() || this.em.get('currentFrame');
  20632. },
  20633. render: function render() {
  20634. var el = this.el,
  20635. $el = this.$el,
  20636. ppfx = this.ppfx,
  20637. model = this.model,
  20638. em = this.em,
  20639. frames = this.frames;
  20640. var cssc = em.get('CssComposer');
  20641. var wrapper = model.get('wrapper');
  20642. $el.html(this.template());
  20643. var $frames = $el.find('[data-frames]');
  20644. this.framesArea = $frames.get(0);
  20645. this.wrapper = wrapper;
  20646. if (wrapper && typeof wrapper.render == 'function') {
  20647. model.get('frame').set({
  20648. wrapper: wrapper,
  20649. root: wrapper.getWrapper(),
  20650. styles: cssc.getAll()
  20651. });
  20652. }
  20653. var toolsWrp = $el.find('[data-tools]');
  20654. this.toolsWrapper = toolsWrp.get(0);
  20655. toolsWrp.append("\n <div class=\"".concat(ppfx, "tools ").concat(ppfx, "tools-gl\" style=\"pointer-events:none\">\n <div class=\"").concat(ppfx, "placeholder\">\n <div class=\"").concat(ppfx, "placeholder-int\"></div>\n </div>\n </div>\n <div id=\"").concat(ppfx, "tools\" style=\"pointer-events:none\">\n <div class=\"").concat(ppfx, "badge\"></div>\n <div class=\"").concat(ppfx, "ghost\"></div>\n <div class=\"").concat(ppfx, "toolbar\" style=\"pointer-events:all\"></div>\n <div class=\"").concat(ppfx, "resizer\"></div>\n <div class=\"").concat(ppfx, "offset-v\"></div>\n <div class=\"").concat(ppfx, "offset-fixed-v\"></div>\n </div>\n "));
  20656. var toolsEl = el.querySelector("#".concat(ppfx, "tools"));
  20657. this.hlEl = el.querySelector(".".concat(ppfx, "highlighter"));
  20658. this.badgeEl = el.querySelector(".".concat(ppfx, "badge"));
  20659. this.placerEl = el.querySelector(".".concat(ppfx, "placeholder"));
  20660. this.ghostEl = el.querySelector(".".concat(ppfx, "ghost"));
  20661. this.toolbarEl = el.querySelector(".".concat(ppfx, "toolbar"));
  20662. this.resizerEl = el.querySelector(".".concat(ppfx, "resizer"));
  20663. this.offsetEl = el.querySelector(".".concat(ppfx, "offset-v"));
  20664. this.fixedOffsetEl = el.querySelector(".".concat(ppfx, "offset-fixed-v"));
  20665. this.toolsGlobEl = el.querySelector(".".concat(ppfx, "tools-gl"));
  20666. this.toolsEl = toolsEl;
  20667. this.el.className = this.className; // Render all frames
  20668. var frms = model.get('frames');
  20669. frms.listenToLoad();
  20670. frames.render();
  20671. em.setCurrentFrame(frms.at(0).view);
  20672. $frames.append(frames.el);
  20673. this.frame = frms.at(0).view;
  20674. return this;
  20675. }
  20676. }));
  20677. /***/ }),
  20678. /***/ "./src/canvas/view/FrameView.js":
  20679. /*!**************************************!*\
  20680. !*** ./src/canvas/view/FrameView.js ***!
  20681. \**************************************/
  20682. /*! exports provided: default */
  20683. /***/ (function(module, __webpack_exports__, __webpack_require__) {
  20684. "use strict";
  20685. __webpack_require__.r(__webpack_exports__);
  20686. /* harmony import */ var _babel_runtime_helpers_toConsumableArray__WEBPACK_IMPORTED_MODULE_0__ = __webpack_require__(/*! @babel/runtime/helpers/toConsumableArray */ "./node_modules/@babel/runtime/helpers/toConsumableArray.js");
  20687. /* harmony import */ var _babel_runtime_helpers_toConsumableArray__WEBPACK_IMPORTED_MODULE_0___default = /*#__PURE__*/__webpack_require__.n(_babel_runtime_helpers_toConsumableArray__WEBPACK_IMPORTED_MODULE_0__);
  20688. /* harmony import */ var _babel_runtime_helpers_defineProperty__WEBPACK_IMPORTED_MODULE_1__ = __webpack_require__(/*! @babel/runtime/helpers/defineProperty */ "./node_modules/@babel/runtime/helpers/defineProperty.js");
  20689. /* harmony import */ var _babel_runtime_helpers_defineProperty__WEBPACK_IMPORTED_MODULE_1___default = /*#__PURE__*/__webpack_require__.n(_babel_runtime_helpers_defineProperty__WEBPACK_IMPORTED_MODULE_1__);
  20690. /* harmony import */ var backbone__WEBPACK_IMPORTED_MODULE_2__ = __webpack_require__(/*! backbone */ "./node_modules/backbone/backbone.js");
  20691. /* harmony import */ var backbone__WEBPACK_IMPORTED_MODULE_2___default = /*#__PURE__*/__webpack_require__.n(backbone__WEBPACK_IMPORTED_MODULE_2__);
  20692. /* harmony import */ var underscore__WEBPACK_IMPORTED_MODULE_3__ = __webpack_require__(/*! underscore */ "./node_modules/underscore/underscore.js");
  20693. /* harmony import */ var underscore__WEBPACK_IMPORTED_MODULE_3___default = /*#__PURE__*/__webpack_require__.n(underscore__WEBPACK_IMPORTED_MODULE_3__);
  20694. /* harmony import */ var css_composer_view_CssRulesView__WEBPACK_IMPORTED_MODULE_4__ = __webpack_require__(/*! css_composer/view/CssRulesView */ "./src/css_composer/view/CssRulesView.js");
  20695. /* harmony import */ var dom_components_view_ComponentView__WEBPACK_IMPORTED_MODULE_5__ = __webpack_require__(/*! dom_components/view/ComponentView */ "./src/dom_components/view/ComponentView.js");
  20696. /* harmony import */ var utils_dom__WEBPACK_IMPORTED_MODULE_6__ = __webpack_require__(/*! utils/dom */ "./src/utils/dom.js");
  20697. /* harmony import */ var utils_mixins__WEBPACK_IMPORTED_MODULE_7__ = __webpack_require__(/*! utils/mixins */ "./src/utils/mixins.js");
  20698. function ownKeys(object, enumerableOnly) { var keys = Object.keys(object); if (Object.getOwnPropertySymbols) { var symbols = Object.getOwnPropertySymbols(object); if (enumerableOnly) symbols = symbols.filter(function (sym) { return Object.getOwnPropertyDescriptor(object, sym).enumerable; }); keys.push.apply(keys, symbols); } return keys; }
  20699. function _objectSpread(target) { for (var i = 1; i < arguments.length; i++) { var source = arguments[i] != null ? arguments[i] : {}; if (i % 2) { ownKeys(source, true).forEach(function (key) { _babel_runtime_helpers_defineProperty__WEBPACK_IMPORTED_MODULE_1___default()(target, key, source[key]); }); } else if (Object.getOwnPropertyDescriptors) { Object.defineProperties(target, Object.getOwnPropertyDescriptors(source)); } else { ownKeys(source).forEach(function (key) { Object.defineProperty(target, key, Object.getOwnPropertyDescriptor(source, key)); }); } } return target; }
  20700. /* harmony default export */ __webpack_exports__["default"] = (backbone__WEBPACK_IMPORTED_MODULE_2___default.a.View.extend({
  20701. tagName: 'iframe',
  20702. attributes: {
  20703. allowfullscreen: 'allowfullscreen',
  20704. 'data-frame-el': true
  20705. },
  20706. initialize: function initialize(o) {
  20707. Object(underscore__WEBPACK_IMPORTED_MODULE_3__["bindAll"])(this, 'updateClientY', 'stopAutoscroll', 'autoscroll', '_emitUpdate');
  20708. var model = this.model,
  20709. el = this.el;
  20710. this.config = _objectSpread({}, o.config || {}, {
  20711. frameView: this
  20712. });
  20713. this.ppfx = this.config.pStylePrefix || '';
  20714. this.em = this.config.em;
  20715. this.listenTo(model, 'change:head', this.updateHead);
  20716. model.view = this;
  20717. Object(utils_mixins__WEBPACK_IMPORTED_MODULE_7__["setViewEl"])(el, this);
  20718. },
  20719. /**
  20720. * Update `<head>` content of the frame
  20721. */
  20722. updateHead: function updateHead() {
  20723. var headEl = this.getHead();
  20724. Object(utils_dom__WEBPACK_IMPORTED_MODULE_6__["empty"])(headEl);
  20725. Object(utils_dom__WEBPACK_IMPORTED_MODULE_6__["appendVNodes"])(headEl, this.model.getHead());
  20726. },
  20727. getEl: function getEl() {
  20728. return this.el;
  20729. },
  20730. getWindow: function getWindow() {
  20731. return this.getEl().contentWindow;
  20732. },
  20733. getDoc: function getDoc() {
  20734. return this.getEl().contentDocument;
  20735. },
  20736. getHead: function getHead() {
  20737. return this.getDoc().querySelector('head');
  20738. },
  20739. getBody: function getBody() {
  20740. return this.getDoc().querySelector('body');
  20741. },
  20742. getWrapper: function getWrapper() {
  20743. return this.getBody().querySelector('[data-gjs-type=wrapper]');
  20744. },
  20745. getJsContainer: function getJsContainer() {
  20746. if (!this.jsContainer) {
  20747. this.jsContainer = Object(utils_dom__WEBPACK_IMPORTED_MODULE_6__["createEl"])('div', {
  20748. class: "".concat(this.ppfx, "js-cont")
  20749. });
  20750. }
  20751. return this.jsContainer;
  20752. },
  20753. getToolsEl: function getToolsEl() {
  20754. var frameWrapView = this.config.frameWrapView;
  20755. return frameWrapView && frameWrapView.elTools;
  20756. },
  20757. getGlobalToolsEl: function getGlobalToolsEl() {
  20758. return this.em.get('Canvas').getGlobalToolsEl();
  20759. },
  20760. getHighlighter: function getHighlighter() {
  20761. return this._getTool('[data-hl]');
  20762. },
  20763. getBadgeEl: function getBadgeEl() {
  20764. return this._getTool('[data-badge]');
  20765. },
  20766. getOffsetViewerEl: function getOffsetViewerEl() {
  20767. return this._getTool('[data-offset]');
  20768. },
  20769. getRect: function getRect() {
  20770. if (!this.rect) {
  20771. this.rect = this.el.getBoundingClientRect();
  20772. }
  20773. return this.rect;
  20774. },
  20775. /**
  20776. * Get rect data, not affected by the canvas zoom
  20777. */
  20778. getOffsetRect: function getOffsetRect() {
  20779. var el = this.el;
  20780. var _this$getBody = this.getBody(),
  20781. scrollTop = _this$getBody.scrollTop,
  20782. scrollLeft = _this$getBody.scrollLeft;
  20783. var height = el.offsetHeight;
  20784. var width = el.offsetWidth;
  20785. return {
  20786. top: el.offsetTop,
  20787. left: el.offsetLeft,
  20788. height: height,
  20789. width: width,
  20790. scrollTop: scrollTop,
  20791. scrollLeft: scrollLeft,
  20792. scrollBottom: scrollTop + height,
  20793. scrollRight: scrollLeft + width
  20794. };
  20795. },
  20796. _getTool: function _getTool(name) {
  20797. var toolsEl = this.getToolsEl();
  20798. if (!this[name]) {
  20799. this[name] = toolsEl.querySelector(name);
  20800. }
  20801. return this[name];
  20802. },
  20803. remove: function remove() {
  20804. var root = this.root,
  20805. model = this.model;
  20806. this._toggleEffects();
  20807. backbone__WEBPACK_IMPORTED_MODULE_2___default.a.View.prototype.remove.apply(this, arguments);
  20808. root.remove();
  20809. model.remove();
  20810. },
  20811. startAutoscroll: function startAutoscroll() {
  20812. var _this = this;
  20813. this.lastMaxHeight = this.getWrapper().offsetHeight - this.el.offsetHeight; // By detaching those from the stack avoid browsers lags
  20814. // Noticeable with "fast" drag of blocks
  20815. setTimeout(function () {
  20816. _this._toggleAutoscrollFx(1);
  20817. requestAnimationFrame(_this.autoscroll);
  20818. }, 0);
  20819. },
  20820. autoscroll: function autoscroll() {
  20821. if (this.dragging) {
  20822. var canvas = this.em.get('Canvas');
  20823. var win = this.getWindow();
  20824. var body = this.getBody();
  20825. var actualTop = body.scrollTop;
  20826. var clientY = this.lastClientY || 0;
  20827. var limitTop = canvas.getConfig().autoscrollLimit;
  20828. var limitBottom = this.getRect().height - limitTop;
  20829. var nextTop = actualTop;
  20830. if (clientY < limitTop) {
  20831. nextTop -= limitTop - clientY;
  20832. }
  20833. if (clientY > limitBottom) {
  20834. nextTop += clientY - limitBottom;
  20835. }
  20836. if (nextTop !== actualTop && nextTop > 0 && nextTop < this.lastMaxHeight) {
  20837. var toolsEl = this.getGlobalToolsEl();
  20838. toolsEl.style.opacity = 0;
  20839. this.showGlobalTools();
  20840. win.scrollTo(0, nextTop);
  20841. }
  20842. requestAnimationFrame(this.autoscroll);
  20843. }
  20844. },
  20845. updateClientY: function updateClientY(ev) {
  20846. ev.preventDefault();
  20847. this.lastClientY = Object(utils_mixins__WEBPACK_IMPORTED_MODULE_7__["getPointerEvent"])(ev).clientY * this.em.getZoomDecimal();
  20848. },
  20849. showGlobalTools: Object(underscore__WEBPACK_IMPORTED_MODULE_3__["debounce"])(function () {
  20850. this.getGlobalToolsEl().style.opacity = '';
  20851. }, 50),
  20852. stopAutoscroll: function stopAutoscroll() {
  20853. this.dragging && this._toggleAutoscrollFx();
  20854. },
  20855. _toggleAutoscrollFx: function _toggleAutoscrollFx(enable) {
  20856. this.dragging = enable;
  20857. var win = this.getWindow();
  20858. var method = enable ? 'on' : 'off';
  20859. var mt = {
  20860. on: utils_mixins__WEBPACK_IMPORTED_MODULE_7__["on"],
  20861. off: utils_mixins__WEBPACK_IMPORTED_MODULE_7__["off"]
  20862. };
  20863. mt[method](win, 'mousemove dragover', this.updateClientY);
  20864. mt[method](win, 'mouseup', this.stopAutoscroll);
  20865. },
  20866. render: function render() {
  20867. var el = this.el,
  20868. $el = this.$el,
  20869. ppfx = this.ppfx,
  20870. config = this.config;
  20871. $el.attr({
  20872. class: ppfx + 'frame'
  20873. });
  20874. if (config.scripts.length) {
  20875. this.renderScripts();
  20876. } else if (config.renderContent) {
  20877. el.onload = this.renderBody.bind(this);
  20878. }
  20879. return this;
  20880. },
  20881. renderScripts: function renderScripts() {
  20882. var _this2 = this;
  20883. var el = this.el,
  20884. config = this.config;
  20885. var appendScript = function appendScript(scripts) {
  20886. if (scripts.length > 0) {
  20887. var src = scripts.shift();
  20888. var scriptEl = Object(utils_dom__WEBPACK_IMPORTED_MODULE_6__["createEl"])('script', _objectSpread({
  20889. type: 'text/javascript'
  20890. }, Object(underscore__WEBPACK_IMPORTED_MODULE_3__["isString"])(src) ? {
  20891. src: src
  20892. } : src));
  20893. scriptEl.onerror = scriptEl.onload = appendScript.bind(null, scripts);
  20894. el.contentDocument.head.appendChild(scriptEl);
  20895. } else {
  20896. _this2.renderBody();
  20897. }
  20898. };
  20899. el.onload = function () {
  20900. return appendScript(_babel_runtime_helpers_toConsumableArray__WEBPACK_IMPORTED_MODULE_0___default()(config.scripts));
  20901. };
  20902. },
  20903. renderBody: function renderBody() {
  20904. var _this3 = this;
  20905. var config = this.config,
  20906. model = this.model,
  20907. ppfx = this.ppfx;
  20908. var root = model.get('root');
  20909. var styles = model.get('styles');
  20910. var em = config.em;
  20911. var doc = this.getDoc();
  20912. var head = this.getHead();
  20913. var body = this.getBody();
  20914. var win = this.getWindow();
  20915. var conf = em.get('Config');
  20916. var extStyles = [];
  20917. config.styles.forEach(function (href) {
  20918. return extStyles.push(Object(underscore__WEBPACK_IMPORTED_MODULE_3__["isString"])(href) ? {
  20919. tag: 'link',
  20920. attributes: {
  20921. href: href,
  20922. rel: 'stylesheet'
  20923. }
  20924. } : {
  20925. tag: 'link',
  20926. attributes: _objectSpread({
  20927. rel: 'stylesheet'
  20928. }, href)
  20929. });
  20930. });
  20931. extStyles.length && Object(utils_dom__WEBPACK_IMPORTED_MODULE_6__["appendVNodes"])(head, extStyles);
  20932. var colorWarn = '#ffca6f'; // I need all this styles to make the editor work properly
  20933. // Remove `html { height: 100%;}` from the baseCss as it gives jumpings
  20934. // effects (on ENTER) with RTE like CKEditor (maybe some bug there?!?)
  20935. // With `body {height: auto;}` jumps in CKEditor are removed but in
  20936. // Firefox is impossible to drag stuff in empty canvas, so bring back
  20937. // `body {height: 100%;}`.
  20938. // For the moment I give the priority to Firefox as it might be
  20939. // CKEditor's issue
  20940. Object(utils_dom__WEBPACK_IMPORTED_MODULE_6__["append"])(body, "<style>\n ".concat(conf.baseCss || '', "\n\n .").concat(ppfx, "dashed *[data-highlightable] {\n outline: 1px dashed rgba(170,170,170,0.7);\n outline-offset: -2px;\n }\n\n .").concat(ppfx, "selected {\n outline: 3px solid #3b97e3 !important;\n outline-offset: -3px;\n }\n\n .").concat(ppfx, "selected-parent {\n outline: 2px solid ").concat(colorWarn, " !important\n }\n\n .").concat(ppfx, "no-select {\n user-select: none;\n -webkit-user-select:none;\n -moz-user-select: none;\n }\n\n .").concat(ppfx, "freezed {\n opacity: 0.5;\n pointer-events: none;\n }\n\n .").concat(ppfx, "no-pointer {\n pointer-events: none;\n }\n\n .").concat(ppfx, "plh-image {\n background: #f5f5f5;\n border: none;\n height: 100px;\n width: 100px;\n display: block;\n outline: 3px solid #ffca6f;\n cursor: pointer;\n outline-offset: -2px\n }\n\n .").concat(ppfx, "grabbing {\n cursor: grabbing;\n cursor: -webkit-grabbing;\n }\n\n .").concat(ppfx, "is__grabbing {\n overflow-x: hidden;\n }\n\n .").concat(ppfx, "is__grabbing,\n .").concat(ppfx, "is__grabbing * {\n cursor: grabbing !important;\n }\n\n ").concat(conf.canvasCss || '', "\n ").concat(conf.protectedCss || '', "\n </style>"));
  20941. this.root = new dom_components_view_ComponentView__WEBPACK_IMPORTED_MODULE_5__["default"]({
  20942. model: root,
  20943. config: _objectSpread({}, root.config, {
  20944. frameView: this
  20945. })
  20946. }).render();
  20947. Object(utils_dom__WEBPACK_IMPORTED_MODULE_6__["append"])(body, this.root.el);
  20948. Object(utils_dom__WEBPACK_IMPORTED_MODULE_6__["append"])(body, new css_composer_view_CssRulesView__WEBPACK_IMPORTED_MODULE_4__["default"]({
  20949. collection: styles,
  20950. config: _objectSpread({}, em.get('CssComposer').getConfig(), {
  20951. frameView: this
  20952. })
  20953. }).render().el);
  20954. Object(utils_dom__WEBPACK_IMPORTED_MODULE_6__["append"])(body, this.getJsContainer()); // em.trigger('loaded'); // I need to manage only the first one maybe
  20955. //this.updateOffset(); // TOFIX (check if I need it)
  20956. // Avoid some default behaviours
  20957. Object(utils_mixins__WEBPACK_IMPORTED_MODULE_7__["on"])(body, 'click', function (ev) {
  20958. return ev && ev.target.tagName == 'A' && ev.preventDefault();
  20959. });
  20960. Object(utils_mixins__WEBPACK_IMPORTED_MODULE_7__["on"])(body, 'submit', function (ev) {
  20961. return ev && ev.preventDefault();
  20962. }); // When the iframe is focused the event dispatcher is not the same so
  20963. // I need to delegate all events to the parent document
  20964. [{
  20965. event: 'keydown keyup keypress',
  20966. class: 'KeyboardEvent'
  20967. }, {
  20968. event: 'mousemove',
  20969. class: 'MouseEvent'
  20970. }, {
  20971. event: 'wheel',
  20972. class: 'WheelEvent'
  20973. }].forEach(function (obj) {
  20974. return obj.event.split(' ').forEach(function (event) {
  20975. doc.addEventListener(event, function (ev) {
  20976. return _this3.el.dispatchEvent(Object(utils_dom__WEBPACK_IMPORTED_MODULE_6__["createCustomEvent"])(ev, obj.class));
  20977. });
  20978. });
  20979. });
  20980. this._toggleEffects(1);
  20981. model.trigger('loaded');
  20982. },
  20983. _toggleEffects: function _toggleEffects(enable) {
  20984. var method = enable ? utils_mixins__WEBPACK_IMPORTED_MODULE_7__["on"] : utils_mixins__WEBPACK_IMPORTED_MODULE_7__["off"];
  20985. var win = this.getWindow();
  20986. method(win, "".concat(utils_dom__WEBPACK_IMPORTED_MODULE_6__["motionsEv"], " resize"), this._emitUpdate);
  20987. },
  20988. _emitUpdate: function _emitUpdate() {
  20989. this.model._emitUpdated();
  20990. }
  20991. }));
  20992. /***/ }),
  20993. /***/ "./src/canvas/view/FrameWrapView.js":
  20994. /*!******************************************!*\
  20995. !*** ./src/canvas/view/FrameWrapView.js ***!
  20996. \******************************************/
  20997. /*! exports provided: default */
  20998. /***/ (function(module, __webpack_exports__, __webpack_require__) {
  20999. "use strict";
  21000. __webpack_require__.r(__webpack_exports__);
  21001. /* harmony import */ var _babel_runtime_helpers_defineProperty__WEBPACK_IMPORTED_MODULE_0__ = __webpack_require__(/*! @babel/runtime/helpers/defineProperty */ "./node_modules/@babel/runtime/helpers/defineProperty.js");
  21002. /* harmony import */ var _babel_runtime_helpers_defineProperty__WEBPACK_IMPORTED_MODULE_0___default = /*#__PURE__*/__webpack_require__.n(_babel_runtime_helpers_defineProperty__WEBPACK_IMPORTED_MODULE_0__);
  21003. /* harmony import */ var backbone__WEBPACK_IMPORTED_MODULE_1__ = __webpack_require__(/*! backbone */ "./node_modules/backbone/backbone.js");
  21004. /* harmony import */ var backbone__WEBPACK_IMPORTED_MODULE_1___default = /*#__PURE__*/__webpack_require__.n(backbone__WEBPACK_IMPORTED_MODULE_1__);
  21005. /* harmony import */ var _FrameView__WEBPACK_IMPORTED_MODULE_2__ = __webpack_require__(/*! ./FrameView */ "./src/canvas/view/FrameView.js");
  21006. /* harmony import */ var underscore__WEBPACK_IMPORTED_MODULE_3__ = __webpack_require__(/*! underscore */ "./node_modules/underscore/underscore.js");
  21007. /* harmony import */ var underscore__WEBPACK_IMPORTED_MODULE_3___default = /*#__PURE__*/__webpack_require__.n(underscore__WEBPACK_IMPORTED_MODULE_3__);
  21008. /* harmony import */ var utils_dom__WEBPACK_IMPORTED_MODULE_4__ = __webpack_require__(/*! utils/dom */ "./src/utils/dom.js");
  21009. /* harmony import */ var utils_Dragger__WEBPACK_IMPORTED_MODULE_5__ = __webpack_require__(/*! utils/Dragger */ "./src/utils/Dragger.js");
  21010. function ownKeys(object, enumerableOnly) { var keys = Object.keys(object); if (Object.getOwnPropertySymbols) { var symbols = Object.getOwnPropertySymbols(object); if (enumerableOnly) symbols = symbols.filter(function (sym) { return Object.getOwnPropertyDescriptor(object, sym).enumerable; }); keys.push.apply(keys, symbols); } return keys; }
  21011. function _objectSpread(target) { for (var i = 1; i < arguments.length; i++) { var source = arguments[i] != null ? arguments[i] : {}; if (i % 2) { ownKeys(source, true).forEach(function (key) { _babel_runtime_helpers_defineProperty__WEBPACK_IMPORTED_MODULE_0___default()(target, key, source[key]); }); } else if (Object.getOwnPropertyDescriptors) { Object.defineProperties(target, Object.getOwnPropertyDescriptors(source)); } else { ownKeys(source).forEach(function (key) { Object.defineProperty(target, key, Object.getOwnPropertyDescriptor(source, key)); }); } } return target; }
  21012. /* harmony default export */ __webpack_exports__["default"] = (backbone__WEBPACK_IMPORTED_MODULE_1___default.a.View.extend({
  21013. events: {
  21014. 'click [data-action-remove]': 'remove',
  21015. 'mousedown [data-action-move]': 'startDrag'
  21016. },
  21017. initialize: function initialize() {
  21018. var opts = arguments.length > 0 && arguments[0] !== undefined ? arguments[0] : {};
  21019. var conf = arguments.length > 1 && arguments[1] !== undefined ? arguments[1] : {};
  21020. Object(underscore__WEBPACK_IMPORTED_MODULE_3__["bindAll"])(this, 'onScroll', 'frameLoaded', 'updateOffset', 'remove', 'startDrag');
  21021. var model = this.model;
  21022. var config = _objectSpread({}, opts.config || conf, {
  21023. frameWrapView: this
  21024. });
  21025. var canvasView = config.canvasView,
  21026. em = config.em;
  21027. this.cv = canvasView;
  21028. this.config = config;
  21029. this.em = em;
  21030. this.canvas = em && em.get('Canvas');
  21031. this.ppfx = config.pStylePrefix || '';
  21032. this.frame = new _FrameView__WEBPACK_IMPORTED_MODULE_2__["default"]({
  21033. model: model,
  21034. config: config
  21035. });
  21036. this.classAnim = "".concat(this.ppfx, "frame-wrapper--anim");
  21037. this.listenTo(model, 'loaded', this.frameLoaded);
  21038. this.listenTo(model, 'change:x change:y', this.updatePos);
  21039. this.listenTo(model, 'change:width change:height', this.updateSize);
  21040. this.updatePos();
  21041. this.setupDragger();
  21042. },
  21043. setupDragger: function setupDragger() {
  21044. var _this = this;
  21045. var canvas = this.canvas,
  21046. model = this.model;
  21047. var dragX, dragY, zoom;
  21048. var toggleEffects = function toggleEffects(on) {
  21049. canvas.toggleFramesEvents(on);
  21050. };
  21051. this.dragger = new utils_Dragger__WEBPACK_IMPORTED_MODULE_5__["default"]({
  21052. onStart: function onStart() {
  21053. var _model$attributes = model.attributes,
  21054. x = _model$attributes.x,
  21055. y = _model$attributes.y;
  21056. zoom = _this.em.getZoomMultiplier();
  21057. dragX = x;
  21058. dragY = y;
  21059. toggleEffects();
  21060. },
  21061. onEnd: function onEnd() {
  21062. return toggleEffects(1);
  21063. },
  21064. setPosition: function setPosition(posOpts) {
  21065. model.set({
  21066. x: dragX + posOpts.x * zoom,
  21067. y: dragY + posOpts.y * zoom
  21068. });
  21069. }
  21070. });
  21071. },
  21072. startDrag: function startDrag(ev) {
  21073. ev && this.dragger.start(ev);
  21074. },
  21075. remove: function remove() {
  21076. backbone__WEBPACK_IMPORTED_MODULE_1___default.a.View.prototype.remove.apply(this, arguments);
  21077. this.frame.remove();
  21078. return this;
  21079. },
  21080. updateOffset: Object(underscore__WEBPACK_IMPORTED_MODULE_3__["debounce"])(function () {
  21081. var em = this.em,
  21082. $el = this.$el,
  21083. frame = this.frame;
  21084. em.runDefault({
  21085. preserveSelected: 1
  21086. });
  21087. $el.removeClass(this.classAnim);
  21088. frame.model._emitUpdated();
  21089. }),
  21090. updatePos: function updatePos(md) {
  21091. var model = this.model,
  21092. el = this.el;
  21093. var _model$attributes2 = model.attributes,
  21094. x = _model$attributes2.x,
  21095. y = _model$attributes2.y;
  21096. var style = el.style;
  21097. this.frame.rect = 0;
  21098. style.left = isNaN(x) ? x : "".concat(x, "px");
  21099. style.top = isNaN(y) ? y : "".concat(y, "px");
  21100. md && this.updateOffset();
  21101. },
  21102. updateSize: Object(underscore__WEBPACK_IMPORTED_MODULE_3__["debounce"])(function () {
  21103. this.updateDim();
  21104. }),
  21105. /**
  21106. * Update dimensions of the frame
  21107. * @private
  21108. */
  21109. updateDim: function updateDim() {
  21110. var em = this.em,
  21111. el = this.el,
  21112. $el = this.$el,
  21113. model = this.model,
  21114. classAnim = this.classAnim;
  21115. var _model$attributes3 = model.attributes,
  21116. width = _model$attributes3.width,
  21117. height = _model$attributes3.height;
  21118. var style = el.style;
  21119. var currW = style.width || '';
  21120. var currH = style.height || '';
  21121. var newW = width || '';
  21122. var newH = height || '';
  21123. var noChanges = currW == newW && currH == newH;
  21124. var un = 'px';
  21125. this.frame.rect = 0;
  21126. $el.addClass(classAnim);
  21127. style.width = Object(underscore__WEBPACK_IMPORTED_MODULE_3__["isNumber"])(newW) ? "".concat(newW).concat(un) : newW;
  21128. style.height = Object(underscore__WEBPACK_IMPORTED_MODULE_3__["isNumber"])(newH) ? "".concat(newH).concat(un) : newH; // Set width and height from DOM (should be done only once)
  21129. if (Object(underscore__WEBPACK_IMPORTED_MODULE_3__["isNull"])(width) || Object(underscore__WEBPACK_IMPORTED_MODULE_3__["isNull"])(height)) {
  21130. var newDims = _objectSpread({}, !width ? {
  21131. width: el.offsetWidth
  21132. } : {}, {}, !height ? {
  21133. height: el.offsetHeight
  21134. } : {});
  21135. model.set(newDims, {
  21136. silent: 1
  21137. });
  21138. } // Prevent fixed highlighting box which appears when on
  21139. // component hover during the animation
  21140. em.stopDefault({
  21141. preserveSelected: 1
  21142. });
  21143. noChanges ? this.updateOffset() : $el.one(utils_dom__WEBPACK_IMPORTED_MODULE_4__["motionsEv"], this.updateOffset);
  21144. },
  21145. onScroll: function onScroll() {
  21146. var frame = this.frame,
  21147. em = this.em;
  21148. em.trigger('frame:scroll', {
  21149. frame: frame,
  21150. body: frame.getBody(),
  21151. target: frame.getWindow()
  21152. });
  21153. },
  21154. frameLoaded: function frameLoaded() {
  21155. var frame = this.frame;
  21156. frame.getWindow().onscroll = this.onScroll;
  21157. this.updateDim();
  21158. },
  21159. render: function render() {
  21160. var frame = this.frame,
  21161. $el = this.$el,
  21162. ppfx = this.ppfx,
  21163. cv = this.cv,
  21164. model = this.model,
  21165. el = this.el;
  21166. var onRender = model.attributes.onRender;
  21167. frame.render();
  21168. $el.empty().attr({
  21169. class: "".concat(ppfx, "frame-wrapper")
  21170. }).append("\n <div class=\"".concat(ppfx, "frame-wrapper__top gjs-two-color\" data-frame-top>\n <div class=\"").concat(ppfx, "frame-wrapper__name\" data-action-move>\n ").concat(model.get('name') || '', "\n </div>\n <div class=\"").concat(ppfx, "frame-wrapper__top-r\">\n <div class=\"").concat(ppfx, "frame-wrapper__icon\" data-action-remove style=\"display: none\">\n <svg viewBox=\"0 0 24 24\"><path d=\"M19 4h-3.5l-1-1h-5l-1 1H5v2h14M6 19c0 1.1.9 2 2 2h8c1.1 0 2-.9 2-2V7H6v12z\"></path></svg>\n </div>\n </div>\n </div>\n <div class=\"").concat(ppfx, "frame-wrapper__right\" data-frame-right></div>\n <div class=\"").concat(ppfx, "frame-wrapper__left\" data-frame-left></div>\n <div class=\"").concat(ppfx, "frame-wrapper__bottom\" data-frame-bottom></div>\n ")).append(frame.el);
  21171. var elTools = Object(utils_dom__WEBPACK_IMPORTED_MODULE_4__["createEl"])('div', {
  21172. class: "".concat(ppfx, "tools"),
  21173. style: 'pointer-events:none; opacity: 0'
  21174. }, "\n <div class=\"".concat(ppfx, "highlighter\" data-hl></div>\n <div class=\"").concat(ppfx, "badge\" data-badge></div>\n <div class=\"").concat(ppfx, "placeholder\">\n <div class=\"").concat(ppfx, "placeholder-int\"></div>\n </div>\n <div class=\"").concat(ppfx, "ghost\"></div>\n <div class=\"").concat(ppfx, "toolbar\" style=\"pointer-events:all\"></div>\n <div class=\"").concat(ppfx, "resizer\"></div>\n <div class=\"").concat(ppfx, "offset-v\" data-offset>\n <div class=\"gjs-marginName\" data-offset-m>\n <div class=\"gjs-margin-v-el gjs-margin-v-top\" data-offset-m-t></div>\n <div class=\"gjs-margin-v-el gjs-margin-v-bottom\" data-offset-m-b></div>\n <div class=\"gjs-margin-v-el gjs-margin-v-left\" data-offset-m-l></div>\n <div class=\"gjs-margin-v-el gjs-margin-v-right\" data-offset-m-r></div>\n </div>\n <div class=\"gjs-paddingName\" data-offset-m>\n <div class=\"gjs-padding-v-el gjs-padding-v-top\" data-offset-p-t></div>\n <div class=\"gjs-padding-v-el gjs-padding-v-bottom\" data-offset-p-b></div>\n <div class=\"gjs-padding-v-el gjs-padding-v-left\" data-offset-p-l></div>\n <div class=\"gjs-padding-v-el gjs-padding-v-right\" data-offset-p-r></div>\n </div>\n </div>\n <div class=\"").concat(ppfx, "offset-fixed-v\"></div>\n "));
  21175. this.elTools = elTools;
  21176. cv.toolsWrapper.appendChild(elTools); // TODO remove on frame remove
  21177. onRender && onRender({
  21178. el: el,
  21179. elTop: el.querySelector('[data-frame-top]'),
  21180. elRight: el.querySelector('[data-frame-right]'),
  21181. elBottom: el.querySelector('[data-frame-bottom]'),
  21182. elLeft: el.querySelector('[data-frame-left]'),
  21183. frame: model,
  21184. frameWrapperView: this,
  21185. remove: this.remove,
  21186. startDrag: this.startDrag
  21187. });
  21188. return this;
  21189. }
  21190. }));
  21191. /***/ }),
  21192. /***/ "./src/canvas/view/FramesView.js":
  21193. /*!***************************************!*\
  21194. !*** ./src/canvas/view/FramesView.js ***!
  21195. \***************************************/
  21196. /*! exports provided: default */
  21197. /***/ (function(module, __webpack_exports__, __webpack_require__) {
  21198. "use strict";
  21199. __webpack_require__.r(__webpack_exports__);
  21200. /* harmony import */ var domain_abstract_view_DomainViews__WEBPACK_IMPORTED_MODULE_0__ = __webpack_require__(/*! domain_abstract/view/DomainViews */ "./src/domain_abstract/view/DomainViews.js");
  21201. /* harmony import */ var _FrameWrapView__WEBPACK_IMPORTED_MODULE_1__ = __webpack_require__(/*! ./FrameWrapView */ "./src/canvas/view/FrameWrapView.js");
  21202. /* harmony default export */ __webpack_exports__["default"] = (domain_abstract_view_DomainViews__WEBPACK_IMPORTED_MODULE_0__["default"].extend({
  21203. itemView: _FrameWrapView__WEBPACK_IMPORTED_MODULE_1__["default"],
  21204. autoAdd: 1,
  21205. init: function init() {
  21206. this.listenTo(this.collection, 'reset', this.render);
  21207. },
  21208. onRender: function onRender() {
  21209. var config = this.config,
  21210. $el = this.$el;
  21211. var em = config.em;
  21212. em && $el.attr({
  21213. class: "".concat(em.getConfig('stylePrefix'), "frames")
  21214. });
  21215. }
  21216. }));
  21217. /***/ }),
  21218. /***/ "./src/code_manager/config/config.js":
  21219. /*!*******************************************!*\
  21220. !*** ./src/code_manager/config/config.js ***!
  21221. \*******************************************/
  21222. /*! exports provided: default */
  21223. /***/ (function(module, __webpack_exports__, __webpack_require__) {
  21224. "use strict";
  21225. __webpack_require__.r(__webpack_exports__);
  21226. /* harmony default export */ __webpack_exports__["default"] = ({
  21227. // Style prefix
  21228. stylePrefix: 'cm-',
  21229. inlineCss: false
  21230. });
  21231. /***/ }),
  21232. /***/ "./src/code_manager/index.js":
  21233. /*!***********************************!*\
  21234. !*** ./src/code_manager/index.js ***!
  21235. \***********************************/
  21236. /*! exports provided: default */
  21237. /***/ (function(module, __webpack_exports__, __webpack_require__) {
  21238. "use strict";
  21239. __webpack_require__.r(__webpack_exports__);
  21240. /* harmony import */ var underscore__WEBPACK_IMPORTED_MODULE_0__ = __webpack_require__(/*! underscore */ "./node_modules/underscore/underscore.js");
  21241. /* harmony import */ var underscore__WEBPACK_IMPORTED_MODULE_0___default = /*#__PURE__*/__webpack_require__.n(underscore__WEBPACK_IMPORTED_MODULE_0__);
  21242. /* harmony import */ var _config_config__WEBPACK_IMPORTED_MODULE_1__ = __webpack_require__(/*! ./config/config */ "./src/code_manager/config/config.js");
  21243. /* harmony import */ var _model_HtmlGenerator__WEBPACK_IMPORTED_MODULE_2__ = __webpack_require__(/*! ./model/HtmlGenerator */ "./src/code_manager/model/HtmlGenerator.js");
  21244. /* harmony import */ var _model_CssGenerator__WEBPACK_IMPORTED_MODULE_3__ = __webpack_require__(/*! ./model/CssGenerator */ "./src/code_manager/model/CssGenerator.js");
  21245. /* harmony import */ var _model_JsonGenerator__WEBPACK_IMPORTED_MODULE_4__ = __webpack_require__(/*! ./model/JsonGenerator */ "./src/code_manager/model/JsonGenerator.js");
  21246. /* harmony import */ var _model_JsGenerator__WEBPACK_IMPORTED_MODULE_5__ = __webpack_require__(/*! ./model/JsGenerator */ "./src/code_manager/model/JsGenerator.js");
  21247. /* harmony import */ var _model_CodeMirrorEditor__WEBPACK_IMPORTED_MODULE_6__ = __webpack_require__(/*! ./model/CodeMirrorEditor */ "./src/code_manager/model/CodeMirrorEditor.js");
  21248. /* harmony import */ var _view_EditorView__WEBPACK_IMPORTED_MODULE_7__ = __webpack_require__(/*! ./view/EditorView */ "./src/code_manager/view/EditorView.js");
  21249. /**
  21250. * - [addGenerator](#addgenerator)
  21251. * - [getGenerator](#getgenerator)
  21252. * - [getGenerators](#getgenerators)
  21253. * - [addViewer](#addviewer)
  21254. * - [getViewer](#getviewer)
  21255. * - [getViewers](#getviewers)
  21256. * - [updateViewer](#updateviewer)
  21257. * - [getCode](#getcode)
  21258. *
  21259. *
  21260. * Before using methods you should get first the module from the editor instance, in this way:
  21261. *
  21262. * ```js
  21263. * var codeManager = editor.CodeManager;
  21264. * ```
  21265. *
  21266. * @module CodeManager
  21267. */
  21268. /* harmony default export */ __webpack_exports__["default"] = (function () {
  21269. var c = {};
  21270. var generators = {},
  21271. defGenerators = {},
  21272. viewers = {},
  21273. defViewers = {};
  21274. var defaultViewer = 'CodeMirror';
  21275. return {
  21276. getConfig: function getConfig() {
  21277. return c;
  21278. },
  21279. config: c,
  21280. EditorView: _view_EditorView__WEBPACK_IMPORTED_MODULE_7__["default"],
  21281. /**
  21282. * Name of the module
  21283. * @type {String}
  21284. * @private
  21285. */
  21286. name: 'CodeManager',
  21287. /**
  21288. * Initialize module. Automatically called with a new instance of the editor
  21289. * @param {Object} config Configurations
  21290. */
  21291. init: function init(config) {
  21292. c = config || {};
  21293. for (var name in _config_config__WEBPACK_IMPORTED_MODULE_1__["default"]) {
  21294. if (!(name in c)) c[name] = _config_config__WEBPACK_IMPORTED_MODULE_1__["default"][name];
  21295. }
  21296. var ppfx = c.pStylePrefix;
  21297. if (ppfx) c.stylePrefix = ppfx + c.stylePrefix;
  21298. defGenerators.html = new _model_HtmlGenerator__WEBPACK_IMPORTED_MODULE_2__["default"]();
  21299. defGenerators.css = new _model_CssGenerator__WEBPACK_IMPORTED_MODULE_3__["default"]();
  21300. defGenerators.json = new _model_JsonGenerator__WEBPACK_IMPORTED_MODULE_4__["default"]();
  21301. defGenerators.js = new _model_JsGenerator__WEBPACK_IMPORTED_MODULE_5__["default"]();
  21302. defViewers.CodeMirror = new _model_CodeMirrorEditor__WEBPACK_IMPORTED_MODULE_6__["default"]();
  21303. this.loadDefaultGenerators().loadDefaultViewers();
  21304. return this;
  21305. },
  21306. /**
  21307. * Add new code generator to the collection
  21308. * @param {string} id Code generator ID
  21309. * @param {Object} generator Code generator wrapper
  21310. * @param {Function} generator.build Function that builds the code
  21311. * @return {this}
  21312. * @example
  21313. * codeManager.addGenerator('html7',{
  21314. * build: function(model){
  21315. * return 'myCode';
  21316. * }
  21317. * });
  21318. * */
  21319. addGenerator: function addGenerator(id, generator) {
  21320. generators[id] = generator;
  21321. return this;
  21322. },
  21323. /**
  21324. * Get code generator by id
  21325. * @param {string} id Code generator ID
  21326. * @return {Object|null}
  21327. * @example
  21328. * var generator = codeManager.getGenerator('html7');
  21329. * generator.build = function(model){
  21330. * //extend
  21331. * };
  21332. * */
  21333. getGenerator: function getGenerator(id) {
  21334. return generators[id] || null;
  21335. },
  21336. /**
  21337. * Returns all code generators
  21338. * @return {Array<Object>}
  21339. * */
  21340. getGenerators: function getGenerators() {
  21341. return generators;
  21342. },
  21343. /**
  21344. * Add new code viewer
  21345. * @param {string} id Code viewer ID
  21346. * @param {Object} viewer Code viewer wrapper
  21347. * @param {Function} viewer.init Set element on which viewer will be displayed
  21348. * @param {Function} viewer.setContent Set content to the viewer
  21349. * @return {this}
  21350. * @example
  21351. * codeManager.addViewer('ace',{
  21352. * init: function(el){
  21353. * var ace = require('ace-editor');
  21354. * this.editor = ace.edit(el.id);
  21355. * },
  21356. * setContent: function(code){
  21357. * this.editor.setValue(code);
  21358. * }
  21359. * });
  21360. * */
  21361. addViewer: function addViewer(id, viewer) {
  21362. viewers[id] = viewer;
  21363. return this;
  21364. },
  21365. /**
  21366. * Get code viewer by id
  21367. * @param {string} id Code viewer ID
  21368. * @return {Object|null}
  21369. * @example
  21370. * var viewer = codeManager.getViewer('ace');
  21371. * */
  21372. getViewer: function getViewer(id) {
  21373. return viewers[id] || null;
  21374. },
  21375. /**
  21376. * Returns all code viewers
  21377. * @return {Array<Object>}
  21378. * */
  21379. getViewers: function getViewers() {
  21380. return viewers;
  21381. },
  21382. createViewer: function createViewer() {
  21383. var opts = arguments.length > 0 && arguments[0] !== undefined ? arguments[0] : {};
  21384. var type = !Object(underscore__WEBPACK_IMPORTED_MODULE_0__["isUndefined"])(opts.type) ? opts.type : defaultViewer;
  21385. var viewer = this.getViewer(type) && this.getViewer(type).clone();
  21386. var cont = document.createElement('div');
  21387. var txtarea = document.createElement('textarea');
  21388. cont.appendChild(txtarea);
  21389. viewer.set(opts);
  21390. viewer.init(txtarea);
  21391. viewer.setElement(cont);
  21392. return viewer;
  21393. },
  21394. /**
  21395. * Update code viewer content
  21396. * @param {Object} viewer Viewer instance
  21397. * @param {string} code Code string
  21398. * @example
  21399. * var AceViewer = codeManager.getViewer('ace');
  21400. * // ...
  21401. * var viewer = AceViewer.init(el);
  21402. * // ...
  21403. * codeManager.updateViewer(AceViewer, 'code');
  21404. * */
  21405. updateViewer: function updateViewer(viewer, code) {
  21406. viewer.setContent(code);
  21407. },
  21408. /**
  21409. * Get code from model
  21410. * @param {Object} model Any kind of model that will be passed to the build method of generator
  21411. * @param {string} genId Code generator id
  21412. * @param {Object} [opt] Options
  21413. * @return {string}
  21414. * @example
  21415. * var codeStr = codeManager.getCode(model, 'html');
  21416. * */
  21417. getCode: function getCode(model, genId) {
  21418. var opt = arguments.length > 2 && arguments[2] !== undefined ? arguments[2] : {};
  21419. opt.em = c.em;
  21420. var generator = this.getGenerator(genId);
  21421. return generator ? generator.build(model, opt) : '';
  21422. },
  21423. /**
  21424. * Load default code generators
  21425. * @return {this}
  21426. * @private
  21427. * */
  21428. loadDefaultGenerators: function loadDefaultGenerators() {
  21429. for (var id in defGenerators) {
  21430. this.addGenerator(id, defGenerators[id]);
  21431. }
  21432. return this;
  21433. },
  21434. /**
  21435. * Load default code viewers
  21436. * @return {this}
  21437. * @private
  21438. * */
  21439. loadDefaultViewers: function loadDefaultViewers() {
  21440. for (var id in defViewers) {
  21441. this.addViewer(id, defViewers[id]);
  21442. }
  21443. return this;
  21444. }
  21445. };
  21446. });
  21447. /***/ }),
  21448. /***/ "./src/code_manager/model/CodeMirrorEditor.js":
  21449. /*!****************************************************!*\
  21450. !*** ./src/code_manager/model/CodeMirrorEditor.js ***!
  21451. \****************************************************/
  21452. /*! exports provided: default */
  21453. /***/ (function(module, __webpack_exports__, __webpack_require__) {
  21454. "use strict";
  21455. __webpack_require__.r(__webpack_exports__);
  21456. /* harmony import */ var _babel_runtime_helpers_defineProperty__WEBPACK_IMPORTED_MODULE_0__ = __webpack_require__(/*! @babel/runtime/helpers/defineProperty */ "./node_modules/@babel/runtime/helpers/defineProperty.js");
  21457. /* harmony import */ var _babel_runtime_helpers_defineProperty__WEBPACK_IMPORTED_MODULE_0___default = /*#__PURE__*/__webpack_require__.n(_babel_runtime_helpers_defineProperty__WEBPACK_IMPORTED_MODULE_0__);
  21458. /* harmony import */ var underscore__WEBPACK_IMPORTED_MODULE_1__ = __webpack_require__(/*! underscore */ "./node_modules/underscore/underscore.js");
  21459. /* harmony import */ var underscore__WEBPACK_IMPORTED_MODULE_1___default = /*#__PURE__*/__webpack_require__.n(underscore__WEBPACK_IMPORTED_MODULE_1__);
  21460. /* harmony import */ var backbone__WEBPACK_IMPORTED_MODULE_2__ = __webpack_require__(/*! backbone */ "./node_modules/backbone/backbone.js");
  21461. /* harmony import */ var backbone__WEBPACK_IMPORTED_MODULE_2___default = /*#__PURE__*/__webpack_require__.n(backbone__WEBPACK_IMPORTED_MODULE_2__);
  21462. /* harmony import */ var codemirror_lib_codemirror__WEBPACK_IMPORTED_MODULE_3__ = __webpack_require__(/*! codemirror/lib/codemirror */ "./node_modules/codemirror/lib/codemirror.js");
  21463. /* harmony import */ var codemirror_lib_codemirror__WEBPACK_IMPORTED_MODULE_3___default = /*#__PURE__*/__webpack_require__.n(codemirror_lib_codemirror__WEBPACK_IMPORTED_MODULE_3__);
  21464. /* harmony import */ var codemirror_mode_htmlmixed_htmlmixed__WEBPACK_IMPORTED_MODULE_4__ = __webpack_require__(/*! codemirror/mode/htmlmixed/htmlmixed */ "./node_modules/codemirror/mode/htmlmixed/htmlmixed.js");
  21465. /* harmony import */ var codemirror_mode_htmlmixed_htmlmixed__WEBPACK_IMPORTED_MODULE_4___default = /*#__PURE__*/__webpack_require__.n(codemirror_mode_htmlmixed_htmlmixed__WEBPACK_IMPORTED_MODULE_4__);
  21466. /* harmony import */ var codemirror_mode_css_css__WEBPACK_IMPORTED_MODULE_5__ = __webpack_require__(/*! codemirror/mode/css/css */ "./node_modules/codemirror/mode/css/css.js");
  21467. /* harmony import */ var codemirror_mode_css_css__WEBPACK_IMPORTED_MODULE_5___default = /*#__PURE__*/__webpack_require__.n(codemirror_mode_css_css__WEBPACK_IMPORTED_MODULE_5__);
  21468. /* harmony import */ var codemirror_formatting__WEBPACK_IMPORTED_MODULE_6__ = __webpack_require__(/*! codemirror-formatting */ "./node_modules/codemirror-formatting/formatting.js");
  21469. /* harmony import */ var codemirror_formatting__WEBPACK_IMPORTED_MODULE_6___default = /*#__PURE__*/__webpack_require__.n(codemirror_formatting__WEBPACK_IMPORTED_MODULE_6__);
  21470. function ownKeys(object, enumerableOnly) { var keys = Object.keys(object); if (Object.getOwnPropertySymbols) { var symbols = Object.getOwnPropertySymbols(object); if (enumerableOnly) symbols = symbols.filter(function (sym) { return Object.getOwnPropertyDescriptor(object, sym).enumerable; }); keys.push.apply(keys, symbols); } return keys; }
  21471. function _objectSpread(target) { for (var i = 1; i < arguments.length; i++) { var source = arguments[i] != null ? arguments[i] : {}; if (i % 2) { ownKeys(source, true).forEach(function (key) { _babel_runtime_helpers_defineProperty__WEBPACK_IMPORTED_MODULE_0___default()(target, key, source[key]); }); } else if (Object.getOwnPropertyDescriptors) { Object.defineProperties(target, Object.getOwnPropertyDescriptors(source)); } else { ownKeys(source).forEach(function (key) { Object.defineProperty(target, key, Object.getOwnPropertyDescriptor(source, key)); }); } } return target; }
  21472. /* harmony default export */ __webpack_exports__["default"] = (backbone__WEBPACK_IMPORTED_MODULE_2___default.a.Model.extend({
  21473. defaults: {
  21474. input: '',
  21475. label: '',
  21476. codeName: '',
  21477. theme: 'hopscotch',
  21478. readOnly: true,
  21479. lineNumbers: true
  21480. },
  21481. /** @inheritdoc */
  21482. init: function init(el) {
  21483. Object(underscore__WEBPACK_IMPORTED_MODULE_1__["bindAll"])(this, 'onChange');
  21484. this.editor = codemirror_lib_codemirror__WEBPACK_IMPORTED_MODULE_3___default.a.fromTextArea(el, _objectSpread({
  21485. dragDrop: false,
  21486. lineWrapping: true,
  21487. mode: this.get('codeName')
  21488. }, this.attributes));
  21489. this.element = el;
  21490. this.editor.on('change', this.onChange);
  21491. return this;
  21492. },
  21493. onChange: function onChange() {
  21494. this.trigger('update', this);
  21495. },
  21496. getEditor: function getEditor() {
  21497. return this.editor;
  21498. },
  21499. /**
  21500. * The element where the viewer is attached
  21501. * @return {HTMLElement}
  21502. */
  21503. getElement: function getElement() {
  21504. return this.element;
  21505. },
  21506. /**
  21507. * Set the element which contains the viewer attached.
  21508. * Generally, it should be just a textarea, but some editor might require
  21509. * a container for it some in that case this method can be used
  21510. * @param {HTMLElement} el
  21511. * @return {self}
  21512. */
  21513. setElement: function setElement(el) {
  21514. this.element = el;
  21515. return this;
  21516. },
  21517. /**
  21518. * Refresh the viewer
  21519. * @return {self}
  21520. */
  21521. refresh: function refresh() {
  21522. this.getEditor().refresh();
  21523. return this;
  21524. },
  21525. /**
  21526. * Focus the viewer
  21527. * @return {self}
  21528. */
  21529. focus: function focus() {
  21530. this.getEditor().focus();
  21531. return this;
  21532. },
  21533. getContent: function getContent() {
  21534. var ed = this.getEditor();
  21535. return ed && ed.getValue();
  21536. },
  21537. /** @inheritdoc */
  21538. setContent: function setContent(v) {
  21539. var _this = this;
  21540. var opts = arguments.length > 1 && arguments[1] !== undefined ? arguments[1] : {};
  21541. var editor = this.editor;
  21542. if (!editor) return;
  21543. editor.setValue(v);
  21544. if (editor.autoFormatRange) {
  21545. codemirror_lib_codemirror__WEBPACK_IMPORTED_MODULE_3___default.a.commands.selectAll(editor);
  21546. editor.autoFormatRange(editor.getCursor(true), editor.getCursor(false));
  21547. codemirror_lib_codemirror__WEBPACK_IMPORTED_MODULE_3___default.a.commands.goDocStart(editor);
  21548. }
  21549. !opts.noRefresh && setTimeout(function () {
  21550. return _this.refresh();
  21551. });
  21552. }
  21553. }));
  21554. /***/ }),
  21555. /***/ "./src/code_manager/model/CssGenerator.js":
  21556. /*!************************************************!*\
  21557. !*** ./src/code_manager/model/CssGenerator.js ***!
  21558. \************************************************/
  21559. /*! exports provided: default */
  21560. /***/ (function(module, __webpack_exports__, __webpack_require__) {
  21561. "use strict";
  21562. __webpack_require__.r(__webpack_exports__);
  21563. /* harmony import */ var backbone__WEBPACK_IMPORTED_MODULE_0__ = __webpack_require__(/*! backbone */ "./node_modules/backbone/backbone.js");
  21564. /* harmony import */ var backbone__WEBPACK_IMPORTED_MODULE_0___default = /*#__PURE__*/__webpack_require__.n(backbone__WEBPACK_IMPORTED_MODULE_0__);
  21565. /* harmony import */ var underscore__WEBPACK_IMPORTED_MODULE_1__ = __webpack_require__(/*! underscore */ "./node_modules/underscore/underscore.js");
  21566. /* harmony import */ var underscore__WEBPACK_IMPORTED_MODULE_1___default = /*#__PURE__*/__webpack_require__.n(underscore__WEBPACK_IMPORTED_MODULE_1__);
  21567. var maxValue = Number.MAX_VALUE;
  21568. /* harmony default export */ __webpack_exports__["default"] = (backbone__WEBPACK_IMPORTED_MODULE_0___default.a.Model.extend({
  21569. initialize: function initialize() {
  21570. this.compCls = [];
  21571. this.ids = [];
  21572. },
  21573. /**
  21574. * Get CSS from a component
  21575. * @param {Model} model
  21576. * @return {String}
  21577. */
  21578. buildFromModel: function buildFromModel(model) {
  21579. var _this = this;
  21580. var opts = arguments.length > 1 && arguments[1] !== undefined ? arguments[1] : {};
  21581. var code = '';
  21582. var em = this.em;
  21583. var avoidInline = em && em.getConfig('avoidInlineStyle');
  21584. var style = model.styleToString();
  21585. var classes = model.get('classes');
  21586. var wrapperIsBody = opts.wrapperIsBody;
  21587. var isWrapper = model.get('wrapper');
  21588. this.ids.push("#".concat(model.getId())); // Let's know what classes I've found
  21589. classes.each(function (model) {
  21590. return _this.compCls.push(model.getFullName());
  21591. });
  21592. if (!avoidInline && style) {
  21593. var selector = "#".concat(model.getId());
  21594. selector = wrapperIsBody && isWrapper ? 'body' : selector;
  21595. code = "".concat(selector, "{").concat(style, "}");
  21596. }
  21597. var components = model.components();
  21598. components.each(function (model) {
  21599. return code += _this.buildFromModel(model, opts);
  21600. });
  21601. return code;
  21602. },
  21603. build: function build(model) {
  21604. var _this2 = this;
  21605. var opts = arguments.length > 1 && arguments[1] !== undefined ? arguments[1] : {};
  21606. var cssc = opts.cssc;
  21607. var em = opts.em || '';
  21608. this.em = em;
  21609. this.compCls = [];
  21610. this.ids = [];
  21611. var code = this.buildFromModel(model, opts);
  21612. var clearStyles = Object(underscore__WEBPACK_IMPORTED_MODULE_1__["isUndefined"])(opts.clearStyles) && em ? em.getConfig('clearStyles') : opts.clearStyles;
  21613. if (cssc) {
  21614. var rules = cssc.getAll();
  21615. var atRules = {};
  21616. var dump = [];
  21617. rules.each(function (rule) {
  21618. var atRule = rule.getAtRule();
  21619. if (atRule) {
  21620. var mRules = atRules[atRule];
  21621. if (mRules) {
  21622. mRules.push(rule);
  21623. } else {
  21624. atRules[atRule] = [rule];
  21625. }
  21626. return;
  21627. }
  21628. code += _this2.buildFromRule(rule, dump, opts);
  21629. });
  21630. this.sortMediaObject(atRules).forEach(function (item) {
  21631. var rulesStr = '';
  21632. var atRule = item.key;
  21633. var mRules = item.value;
  21634. mRules.forEach(function (rule) {
  21635. var ruleStr = _this2.buildFromRule(rule, dump, opts);
  21636. if (rule.get('singleAtRule')) {
  21637. code += "".concat(atRule, "{").concat(ruleStr, "}");
  21638. } else {
  21639. rulesStr += ruleStr;
  21640. }
  21641. });
  21642. if (rulesStr) {
  21643. code += "".concat(atRule, "{").concat(rulesStr, "}");
  21644. }
  21645. });
  21646. em && clearStyles && rules.remove(dump);
  21647. }
  21648. return code;
  21649. },
  21650. /**
  21651. * Get CSS from the rule model
  21652. * @param {Model} rule
  21653. * @return {string} CSS string
  21654. */
  21655. buildFromRule: function buildFromRule(rule, dump) {
  21656. var _this3 = this;
  21657. var opts = arguments.length > 2 && arguments[2] !== undefined ? arguments[2] : {};
  21658. var result = '';
  21659. var selectorStrNoAdd = rule.selectorsToString({
  21660. skipAdd: 1
  21661. });
  21662. var selectorsAdd = rule.get('selectorsAdd');
  21663. var singleAtRule = rule.get('singleAtRule');
  21664. var found; // This will not render a rule if there is no its component
  21665. rule.get('selectors').each(function (selector) {
  21666. var name = selector.getFullName();
  21667. if (_this3.compCls.indexOf(name) >= 0 || _this3.ids.indexOf(name) >= 0 || opts.keepUnusedStyles) {
  21668. found = 1;
  21669. }
  21670. });
  21671. if (selectorStrNoAdd && found || selectorsAdd || singleAtRule) {
  21672. var block = rule.getDeclaration();
  21673. block && (result += block);
  21674. } else {
  21675. dump.push(rule);
  21676. }
  21677. return result;
  21678. },
  21679. /**
  21680. * Get the numeric length of the media query string
  21681. * @param {String} mediaQuery Media query string
  21682. * @return {Number}
  21683. */
  21684. getQueryLength: function getQueryLength(mediaQuery) {
  21685. var length = /(-?\d*\.?\d+)\w{0,}/.exec(mediaQuery);
  21686. if (!length) return maxValue;
  21687. return parseFloat(length[1]);
  21688. },
  21689. /**
  21690. * Return a sorted array from media query object
  21691. * @param {Object} items
  21692. * @return {Array}
  21693. */
  21694. sortMediaObject: function sortMediaObject() {
  21695. var _this4 = this;
  21696. var items = arguments.length > 0 && arguments[0] !== undefined ? arguments[0] : {};
  21697. var itemsArr = [];
  21698. Object(underscore__WEBPACK_IMPORTED_MODULE_1__["each"])(items, function (value, key) {
  21699. return itemsArr.push({
  21700. key: key,
  21701. value: value
  21702. });
  21703. });
  21704. return itemsArr.sort(function (a, b) {
  21705. var isMobFirst = [a.key, b.key].every(function (mquery) {
  21706. return mquery.indexOf('min-width') !== -1;
  21707. });
  21708. var left = isMobFirst ? a.key : b.key;
  21709. var right = isMobFirst ? b.key : a.key;
  21710. return _this4.getQueryLength(left) - _this4.getQueryLength(right);
  21711. });
  21712. }
  21713. }));
  21714. /***/ }),
  21715. /***/ "./src/code_manager/model/HtmlGenerator.js":
  21716. /*!*************************************************!*\
  21717. !*** ./src/code_manager/model/HtmlGenerator.js ***!
  21718. \*************************************************/
  21719. /*! exports provided: default */
  21720. /***/ (function(module, __webpack_exports__, __webpack_require__) {
  21721. "use strict";
  21722. __webpack_require__.r(__webpack_exports__);
  21723. /* harmony import */ var _babel_runtime_helpers_defineProperty__WEBPACK_IMPORTED_MODULE_0__ = __webpack_require__(/*! @babel/runtime/helpers/defineProperty */ "./node_modules/@babel/runtime/helpers/defineProperty.js");
  21724. /* harmony import */ var _babel_runtime_helpers_defineProperty__WEBPACK_IMPORTED_MODULE_0___default = /*#__PURE__*/__webpack_require__.n(_babel_runtime_helpers_defineProperty__WEBPACK_IMPORTED_MODULE_0__);
  21725. /* harmony import */ var backbone__WEBPACK_IMPORTED_MODULE_1__ = __webpack_require__(/*! backbone */ "./node_modules/backbone/backbone.js");
  21726. /* harmony import */ var backbone__WEBPACK_IMPORTED_MODULE_1___default = /*#__PURE__*/__webpack_require__.n(backbone__WEBPACK_IMPORTED_MODULE_1__);
  21727. function ownKeys(object, enumerableOnly) { var keys = Object.keys(object); if (Object.getOwnPropertySymbols) { var symbols = Object.getOwnPropertySymbols(object); if (enumerableOnly) symbols = symbols.filter(function (sym) { return Object.getOwnPropertyDescriptor(object, sym).enumerable; }); keys.push.apply(keys, symbols); } return keys; }
  21728. function _objectSpread(target) { for (var i = 1; i < arguments.length; i++) { var source = arguments[i] != null ? arguments[i] : {}; if (i % 2) { ownKeys(source, true).forEach(function (key) { _babel_runtime_helpers_defineProperty__WEBPACK_IMPORTED_MODULE_0___default()(target, key, source[key]); }); } else if (Object.getOwnPropertyDescriptors) { Object.defineProperties(target, Object.getOwnPropertyDescriptors(source)); } else { ownKeys(source).forEach(function (key) { Object.defineProperty(target, key, Object.getOwnPropertyDescriptor(source, key)); }); } } return target; }
  21729. /* harmony default export */ __webpack_exports__["default"] = (backbone__WEBPACK_IMPORTED_MODULE_1___default.a.Model.extend({
  21730. build: function build(model) {
  21731. var opts = arguments.length > 1 && arguments[1] !== undefined ? arguments[1] : {};
  21732. var models = model.get('components');
  21733. if (opts.exportWrapper) {
  21734. return model.toHTML(_objectSpread({}, opts.wrapperIsBody && {
  21735. tag: 'body'
  21736. }));
  21737. }
  21738. return this.buildModels(models);
  21739. },
  21740. buildModels: function buildModels(models) {
  21741. var code = '';
  21742. models.each(function (model) {
  21743. code += model.toHTML();
  21744. });
  21745. return code;
  21746. }
  21747. }));
  21748. /***/ }),
  21749. /***/ "./src/code_manager/model/JsGenerator.js":
  21750. /*!***********************************************!*\
  21751. !*** ./src/code_manager/model/JsGenerator.js ***!
  21752. \***********************************************/
  21753. /*! exports provided: default */
  21754. /***/ (function(module, __webpack_exports__, __webpack_require__) {
  21755. "use strict";
  21756. __webpack_require__.r(__webpack_exports__);
  21757. /* harmony import */ var underscore__WEBPACK_IMPORTED_MODULE_0__ = __webpack_require__(/*! underscore */ "./node_modules/underscore/underscore.js");
  21758. /* harmony import */ var underscore__WEBPACK_IMPORTED_MODULE_0___default = /*#__PURE__*/__webpack_require__.n(underscore__WEBPACK_IMPORTED_MODULE_0__);
  21759. /* harmony import */ var backbone__WEBPACK_IMPORTED_MODULE_1__ = __webpack_require__(/*! backbone */ "./node_modules/backbone/backbone.js");
  21760. /* harmony import */ var backbone__WEBPACK_IMPORTED_MODULE_1___default = /*#__PURE__*/__webpack_require__.n(backbone__WEBPACK_IMPORTED_MODULE_1__);
  21761. /* harmony default export */ __webpack_exports__["default"] = (backbone__WEBPACK_IMPORTED_MODULE_1___default.a.Model.extend({
  21762. mapModel: function mapModel(model) {
  21763. var code = '';
  21764. var script = model.get('script-export') || model.get('script');
  21765. var type = model.get('type');
  21766. var comps = model.get('components');
  21767. var id = model.getId();
  21768. if (script) {
  21769. // If the component has scripts we need to expose his ID
  21770. var attr = model.get('attributes');
  21771. attr = Object(underscore__WEBPACK_IMPORTED_MODULE_0__["extend"])({}, attr, {
  21772. id: id
  21773. });
  21774. model.set('attributes', attr, {
  21775. silent: 1
  21776. });
  21777. var scrStr = model.getScriptString(script); // If the script was updated, I'll put its code in a separate container
  21778. if (model.get('scriptUpdated')) {
  21779. this.mapJs[type + '-' + id] = {
  21780. ids: [id],
  21781. code: scrStr
  21782. };
  21783. } else {
  21784. var mapType = this.mapJs[type];
  21785. if (mapType) {
  21786. mapType.ids.push(id);
  21787. } else {
  21788. this.mapJs[type] = {
  21789. ids: [id],
  21790. code: scrStr
  21791. };
  21792. }
  21793. }
  21794. }
  21795. comps.each(function (model) {
  21796. code += this.mapModel(model);
  21797. }, this);
  21798. return code;
  21799. },
  21800. build: function build(model) {
  21801. this.mapJs = {};
  21802. this.mapModel(model);
  21803. var code = '';
  21804. for (var type in this.mapJs) {
  21805. var mapType = this.mapJs[type];
  21806. var ids = '#' + mapType.ids.join(', #');
  21807. code += "\n var items = document.querySelectorAll('".concat(ids, "');\n for (var i = 0, len = items.length; i < len; i++) {\n (function(){").concat(mapType.code, "}.bind(items[i]))();\n }");
  21808. }
  21809. return code;
  21810. }
  21811. }));
  21812. /***/ }),
  21813. /***/ "./src/code_manager/model/JsonGenerator.js":
  21814. /*!*************************************************!*\
  21815. !*** ./src/code_manager/model/JsonGenerator.js ***!
  21816. \*************************************************/
  21817. /*! exports provided: default */
  21818. /***/ (function(module, __webpack_exports__, __webpack_require__) {
  21819. "use strict";
  21820. __webpack_require__.r(__webpack_exports__);
  21821. /* harmony import */ var underscore__WEBPACK_IMPORTED_MODULE_0__ = __webpack_require__(/*! underscore */ "./node_modules/underscore/underscore.js");
  21822. /* harmony import */ var underscore__WEBPACK_IMPORTED_MODULE_0___default = /*#__PURE__*/__webpack_require__.n(underscore__WEBPACK_IMPORTED_MODULE_0__);
  21823. /* harmony import */ var backbone__WEBPACK_IMPORTED_MODULE_1__ = __webpack_require__(/*! backbone */ "./node_modules/backbone/backbone.js");
  21824. /* harmony import */ var backbone__WEBPACK_IMPORTED_MODULE_1___default = /*#__PURE__*/__webpack_require__.n(backbone__WEBPACK_IMPORTED_MODULE_1__);
  21825. /* harmony default export */ __webpack_exports__["default"] = (backbone__WEBPACK_IMPORTED_MODULE_1___default.a.Model.extend({
  21826. /** @inheritdoc */
  21827. build: function build(model) {
  21828. var json = model.toJSON();
  21829. this.beforeEach(json);
  21830. Object(underscore__WEBPACK_IMPORTED_MODULE_0__["each"])(json, function (v, attr) {
  21831. var obj = json[attr];
  21832. if (obj instanceof backbone__WEBPACK_IMPORTED_MODULE_1___default.a.Model) {
  21833. json[attr] = this.build(obj);
  21834. } else if (obj instanceof backbone__WEBPACK_IMPORTED_MODULE_1___default.a.Collection) {
  21835. var coll = obj;
  21836. json[attr] = [];
  21837. if (coll.length) {
  21838. coll.each(function (el, index) {
  21839. json[attr][index] = this.build(el);
  21840. }, this);
  21841. }
  21842. }
  21843. }, this);
  21844. return json;
  21845. },
  21846. /**
  21847. * Execute on each object
  21848. * @param {Object} obj
  21849. */
  21850. beforeEach: function beforeEach(obj) {
  21851. delete obj.status;
  21852. }
  21853. }));
  21854. /***/ }),
  21855. /***/ "./src/code_manager/view/EditorView.js":
  21856. /*!*********************************************!*\
  21857. !*** ./src/code_manager/view/EditorView.js ***!
  21858. \*********************************************/
  21859. /*! exports provided: default */
  21860. /***/ (function(module, __webpack_exports__, __webpack_require__) {
  21861. "use strict";
  21862. __webpack_require__.r(__webpack_exports__);
  21863. /* harmony import */ var underscore__WEBPACK_IMPORTED_MODULE_0__ = __webpack_require__(/*! underscore */ "./node_modules/underscore/underscore.js");
  21864. /* harmony import */ var underscore__WEBPACK_IMPORTED_MODULE_0___default = /*#__PURE__*/__webpack_require__.n(underscore__WEBPACK_IMPORTED_MODULE_0__);
  21865. /* harmony import */ var backbone__WEBPACK_IMPORTED_MODULE_1__ = __webpack_require__(/*! backbone */ "./node_modules/backbone/backbone.js");
  21866. /* harmony import */ var backbone__WEBPACK_IMPORTED_MODULE_1___default = /*#__PURE__*/__webpack_require__.n(backbone__WEBPACK_IMPORTED_MODULE_1__);
  21867. /* harmony default export */ __webpack_exports__["default"] = (backbone__WEBPACK_IMPORTED_MODULE_1___default.a.View.extend({
  21868. template: Object(underscore__WEBPACK_IMPORTED_MODULE_0__["template"])("\n <div class=\"<%= pfx %>editor\" id=\"<%= pfx %><%= codeName %>\">\n \t<div id=\"<%= pfx %>title\"><%= label %></div>\n \t<div id=\"<%= pfx %>code\"></div>\n </div>"),
  21869. initialize: function initialize(o) {
  21870. this.config = o.config || {};
  21871. this.pfx = this.config.stylePrefix;
  21872. },
  21873. render: function render() {
  21874. var obj = this.model.toJSON();
  21875. obj.pfx = this.pfx;
  21876. this.$el.html(this.template(obj));
  21877. this.$el.attr('class', this.pfx + 'editor-c');
  21878. this.$el.find('#' + this.pfx + 'code').append(this.model.get('input'));
  21879. return this;
  21880. }
  21881. }));
  21882. /***/ }),
  21883. /***/ "./src/commands/config/config.js":
  21884. /*!***************************************!*\
  21885. !*** ./src/commands/config/config.js ***!
  21886. \***************************************/
  21887. /*! exports provided: default */
  21888. /***/ (function(module, __webpack_exports__, __webpack_require__) {
  21889. "use strict";
  21890. __webpack_require__.r(__webpack_exports__);
  21891. /* harmony default export */ __webpack_exports__["default"] = ({
  21892. stylePrefix: 'com-',
  21893. // Default array of commands
  21894. defaults: [],
  21895. // If true, stateful commands (with `run` and `stop` methods) can't be runned multiple times.
  21896. // So, if the command is already active, running it again will not execute the `run` method
  21897. strict: 1
  21898. });
  21899. /***/ }),
  21900. /***/ "./src/commands/index.js":
  21901. /*!*******************************!*\
  21902. !*** ./src/commands/index.js ***!
  21903. \*******************************/
  21904. /*! exports provided: default */
  21905. /***/ (function(module, __webpack_exports__, __webpack_require__) {
  21906. "use strict";
  21907. __webpack_require__.r(__webpack_exports__);
  21908. /* harmony import */ var _babel_runtime_helpers_toConsumableArray__WEBPACK_IMPORTED_MODULE_0__ = __webpack_require__(/*! @babel/runtime/helpers/toConsumableArray */ "./node_modules/@babel/runtime/helpers/toConsumableArray.js");
  21909. /* harmony import */ var _babel_runtime_helpers_toConsumableArray__WEBPACK_IMPORTED_MODULE_0___default = /*#__PURE__*/__webpack_require__.n(_babel_runtime_helpers_toConsumableArray__WEBPACK_IMPORTED_MODULE_0__);
  21910. /* harmony import */ var _babel_runtime_helpers_defineProperty__WEBPACK_IMPORTED_MODULE_1__ = __webpack_require__(/*! @babel/runtime/helpers/defineProperty */ "./node_modules/@babel/runtime/helpers/defineProperty.js");
  21911. /* harmony import */ var _babel_runtime_helpers_defineProperty__WEBPACK_IMPORTED_MODULE_1___default = /*#__PURE__*/__webpack_require__.n(_babel_runtime_helpers_defineProperty__WEBPACK_IMPORTED_MODULE_1__);
  21912. /* harmony import */ var underscore__WEBPACK_IMPORTED_MODULE_2__ = __webpack_require__(/*! underscore */ "./node_modules/underscore/underscore.js");
  21913. /* harmony import */ var underscore__WEBPACK_IMPORTED_MODULE_2___default = /*#__PURE__*/__webpack_require__.n(underscore__WEBPACK_IMPORTED_MODULE_2__);
  21914. /* harmony import */ var _view_CommandAbstract__WEBPACK_IMPORTED_MODULE_3__ = __webpack_require__(/*! ./view/CommandAbstract */ "./src/commands/view/CommandAbstract.js");
  21915. /* harmony import */ var _config_config__WEBPACK_IMPORTED_MODULE_4__ = __webpack_require__(/*! ./config/config */ "./src/commands/config/config.js");
  21916. /* harmony import */ var dom_components_model_Component__WEBPACK_IMPORTED_MODULE_5__ = __webpack_require__(/*! dom_components/model/Component */ "./src/dom_components/model/Component.js");
  21917. function ownKeys(object, enumerableOnly) { var keys = Object.keys(object); if (Object.getOwnPropertySymbols) { var symbols = Object.getOwnPropertySymbols(object); if (enumerableOnly) symbols = symbols.filter(function (sym) { return Object.getOwnPropertyDescriptor(object, sym).enumerable; }); keys.push.apply(keys, symbols); } return keys; }
  21918. function _objectSpread(target) { for (var i = 1; i < arguments.length; i++) { var source = arguments[i] != null ? arguments[i] : {}; if (i % 2) { ownKeys(source, true).forEach(function (key) { _babel_runtime_helpers_defineProperty__WEBPACK_IMPORTED_MODULE_1___default()(target, key, source[key]); }); } else if (Object.getOwnPropertyDescriptors) { Object.defineProperties(target, Object.getOwnPropertyDescriptors(source)); } else { ownKeys(source).forEach(function (key) { Object.defineProperty(target, key, Object.getOwnPropertyDescriptor(source, key)); }); } } return target; }
  21919. /**
  21920. * You can customize the initial state of the module from the editor initialization, by passing the following [Configuration Object](https://github.com/artf/grapesjs/blob/master/src/commands/config/config.js)
  21921. * ```js
  21922. * const editor = grapesjs.init({
  21923. * commands: {
  21924. * // options
  21925. * }
  21926. * })
  21927. * ```
  21928. *
  21929. * Once the editor is instantiated you can use its API. Before using these methods you should get the module from the instance
  21930. *
  21931. * ```js
  21932. * const commands = editor.Commands;
  21933. * ```
  21934. *
  21935. * * [add](#add)
  21936. * * [get](#get)
  21937. * * [getAll](#getall)
  21938. * * [extend](#extend)
  21939. * * [has](#has)
  21940. * * [run](#run)
  21941. * * [stop](#stop)
  21942. * * [isActive](#isactive)
  21943. * * [getActive](#getactive)
  21944. *
  21945. * @module Commands
  21946. */
  21947. /* harmony default export */ __webpack_exports__["default"] = (function () {
  21948. var em;
  21949. var c = {};
  21950. var commands = {};
  21951. var defaultCommands = {};
  21952. var active = {};
  21953. var commandsDef = [['preview', 'Preview', 'preview'], ['resize', 'Resize', 'resize'], ['fullscreen', 'Fullscreen', 'fullscreen'], ['copy', 'CopyComponent'], ['paste', 'PasteComponent'], ['canvas-move', 'CanvasMove'], ['canvas-clear', 'CanvasClear'], ['open-code', 'ExportTemplate', 'export-template'], ['open-layers', 'OpenLayers', 'open-layers'], ['open-styles', 'OpenStyleManager', 'open-sm'], ['open-traits', 'OpenTraitManager', 'open-tm'], ['open-blocks', 'OpenBlocks', 'open-blocks'], ['open-assets', 'OpenAssets', 'open-assets'], ['component-select', 'SelectComponent', 'select-comp'], ['component-outline', 'SwitchVisibility', 'sw-visibility'], ['component-offset', 'ShowOffset', 'show-offset'], ['component-move', 'MoveComponent', 'move-comp'], ['component-next', 'ComponentNext'], ['component-prev', 'ComponentPrev'], ['component-enter', 'ComponentEnter'], ['component-exit', 'ComponentExit', 'select-parent'], ['component-delete', 'ComponentDelete'], ['component-style-clear', 'ComponentStyleClear'], ['component-drag', 'ComponentDrag']]; // Need it here as it would be used below
  21954. var add = function add(id, obj) {
  21955. if (Object(underscore__WEBPACK_IMPORTED_MODULE_2__["isFunction"])(obj)) obj = {
  21956. run: obj
  21957. };
  21958. if (!obj.stop) obj.noStop = 1;
  21959. delete obj.initialize;
  21960. obj.id = id;
  21961. commands[id] = _view_CommandAbstract__WEBPACK_IMPORTED_MODULE_3__["default"].extend(obj);
  21962. return this;
  21963. };
  21964. return {
  21965. CommandAbstract: _view_CommandAbstract__WEBPACK_IMPORTED_MODULE_3__["default"],
  21966. /**
  21967. * Name of the module
  21968. * @type {String}
  21969. * @private
  21970. */
  21971. name: 'Commands',
  21972. /**
  21973. * Initialize module. Automatically called with a new instance of the editor
  21974. * @param {Object} config Configurations
  21975. * @private
  21976. */
  21977. init: function init() {
  21978. var config = arguments.length > 0 && arguments[0] !== undefined ? arguments[0] : {};
  21979. c = _objectSpread({}, _config_config__WEBPACK_IMPORTED_MODULE_4__["default"], {}, config);
  21980. em = c.em;
  21981. var ppfx = c.pStylePrefix;
  21982. if (ppfx) c.stylePrefix = ppfx + c.stylePrefix; // Load commands passed via configuration
  21983. for (var k in c.defaults) {
  21984. var obj = c.defaults[k];
  21985. if (obj.id) this.add(obj.id, obj);
  21986. }
  21987. defaultCommands['tlb-delete'] = {
  21988. run: function run(ed) {
  21989. return ed.runCommand('core:component-delete');
  21990. }
  21991. };
  21992. defaultCommands['tlb-clone'] = {
  21993. run: function run(ed) {
  21994. ed.runCommand('core:copy');
  21995. ed.runCommand('core:paste');
  21996. }
  21997. };
  21998. defaultCommands['tlb-move'] = {
  21999. run: function run(ed, sender) {
  22000. var opts = arguments.length > 2 && arguments[2] !== undefined ? arguments[2] : {};
  22001. var dragger;
  22002. var em = ed.getModel();
  22003. var event = opts && opts.event;
  22004. var target = opts.target;
  22005. var sel = target || ed.getSelected();
  22006. var selAll = target ? [target] : _babel_runtime_helpers_toConsumableArray__WEBPACK_IMPORTED_MODULE_0___default()(ed.getSelectedAll());
  22007. var nativeDrag = event && event.type == 'dragstart';
  22008. var defComOptions = {
  22009. preserveSelected: 1
  22010. };
  22011. var modes = ['absolute', 'translate'];
  22012. var mode = sel.get('dmode') || em.get('dmode');
  22013. var hideTlb = function hideTlb() {
  22014. return em.stopDefault(defComOptions);
  22015. };
  22016. var altMode = Object(underscore__WEBPACK_IMPORTED_MODULE_2__["includes"])(modes, mode);
  22017. selAll.forEach(function (sel) {
  22018. return sel.trigger('disable');
  22019. });
  22020. if (!sel || !sel.get('draggable')) {
  22021. return em.logWarning('The element is not draggable');
  22022. } // Without setTimeout the ghost image disappears
  22023. nativeDrag ? setTimeout(hideTlb, 0) : hideTlb();
  22024. var onStart = function onStart(data) {
  22025. em.trigger("".concat(dom_components_model_Component__WEBPACK_IMPORTED_MODULE_5__["eventDrag"], ":start"), data);
  22026. };
  22027. var onDrag = function onDrag(data) {
  22028. em.trigger(dom_components_model_Component__WEBPACK_IMPORTED_MODULE_5__["eventDrag"], data);
  22029. };
  22030. var onEnd = function onEnd(e, opts, data) {
  22031. em.runDefault(defComOptions);
  22032. selAll.forEach(function (sel) {
  22033. return sel.set('status', 'selected');
  22034. });
  22035. ed.select(selAll);
  22036. sel.emitUpdate();
  22037. em.trigger("".concat(dom_components_model_Component__WEBPACK_IMPORTED_MODULE_5__["eventDrag"], ":end"), data); // Dirty patch to prevent parent selection on drop
  22038. (altMode || data.cancelled) && em.set('_cmpDrag', 1);
  22039. };
  22040. if (altMode) {
  22041. // TODO move grabbing func in editor/canvas from the Sorter
  22042. dragger = ed.runCommand('core:component-drag', {
  22043. guidesInfo: 1,
  22044. mode: mode,
  22045. target: sel,
  22046. onStart: onStart,
  22047. onDrag: onDrag,
  22048. onEnd: onEnd,
  22049. event: event
  22050. });
  22051. } else {
  22052. if (nativeDrag) {
  22053. event.dataTransfer.setDragImage(sel.view.el, 0, 0); //sel.set('status', 'freezed');
  22054. }
  22055. var cmdMove = ed.Commands.get('move-comp');
  22056. cmdMove.onStart = onStart;
  22057. cmdMove.onDrag = onDrag;
  22058. cmdMove.onEndMoveFromModel = onEnd;
  22059. cmdMove.initSorterFromModels(selAll);
  22060. }
  22061. selAll.forEach(function (sel) {
  22062. return sel.set('status', 'freezed-selected');
  22063. });
  22064. }
  22065. }; // Core commands
  22066. defaultCommands['core:undo'] = function (e) {
  22067. return e.UndoManager.undo();
  22068. };
  22069. defaultCommands['core:redo'] = function (e) {
  22070. return e.UndoManager.redo();
  22071. };
  22072. commandsDef.forEach(function (item) {
  22073. var oldCmd = item[2];
  22074. var cmd = __webpack_require__("./src/commands/view sync recursive ^\\.\\/.*$")("./".concat(item[1])).default;
  22075. var cmdName = "core:".concat(item[0]);
  22076. defaultCommands[cmdName] = cmd;
  22077. if (oldCmd) {
  22078. defaultCommands[oldCmd] = cmd; // Propogate old commands (can be removed once we stop to call old commands)
  22079. ['run', 'stop'].forEach(function (name) {
  22080. em.on("".concat(name, ":").concat(oldCmd), function () {
  22081. var _em;
  22082. for (var _len = arguments.length, args = new Array(_len), _key = 0; _key < _len; _key++) {
  22083. args[_key] = arguments[_key];
  22084. }
  22085. return (_em = em).trigger.apply(_em, ["".concat(name, ":").concat(cmdName)].concat(args));
  22086. });
  22087. });
  22088. }
  22089. });
  22090. if (c.em) c.model = c.em.get('Canvas');
  22091. this.loadDefaultCommands();
  22092. return this;
  22093. },
  22094. /**
  22095. * Add new command to the collection
  22096. * @param {string} id Command's ID
  22097. * @param {Object|Function} command Object representing your command,
  22098. * By passing just a function it's intended as a stateless command
  22099. * (just like passing an object with only `run` method).
  22100. * @return {this}
  22101. * @example
  22102. * commands.add('myCommand', {
  22103. * run(editor, sender) {
  22104. * alert('Hello world!');
  22105. * },
  22106. * stop(editor, sender) {
  22107. * },
  22108. * });
  22109. * // As a function
  22110. * commands.add('myCommand2', editor => { ... });
  22111. * */
  22112. add: add,
  22113. /**
  22114. * Get command by ID
  22115. * @param {string} id Command's ID
  22116. * @return {Object} Object representing the command
  22117. * @example
  22118. * var myCommand = commands.get('myCommand');
  22119. * myCommand.run();
  22120. * */
  22121. get: function get(id) {
  22122. var el = commands[id];
  22123. if (Object(underscore__WEBPACK_IMPORTED_MODULE_2__["isFunction"])(el)) {
  22124. el = new el(c);
  22125. commands[id] = el;
  22126. } else if (!el) {
  22127. em.logWarning("'".concat(id, "' command not found"));
  22128. }
  22129. return el;
  22130. },
  22131. /**
  22132. * Extend the command. The command to extend should be defined as an object
  22133. * @param {string} id Command's ID
  22134. * @param {Object} Object with the new command functions
  22135. * @returns {this}
  22136. * @example
  22137. * commands.extend('old-command', {
  22138. * someInnerFunction() {
  22139. * // ...
  22140. * }
  22141. * });
  22142. * */
  22143. extend: function extend(id) {
  22144. var cmd = arguments.length > 1 && arguments[1] !== undefined ? arguments[1] : {};
  22145. var command = this.get(id);
  22146. if (command) {
  22147. var cmdObj = _objectSpread({}, command.constructor.prototype, {}, cmd);
  22148. this.add(id, cmdObj); // Extend also old name commands if exist
  22149. var oldCmd = commandsDef.filter(function (cmd) {
  22150. return "core:".concat(cmd[0]) === id && cmd[2];
  22151. })[0];
  22152. oldCmd && this.add(oldCmd[2], cmdObj);
  22153. }
  22154. return this;
  22155. },
  22156. /**
  22157. * Check if command exists
  22158. * @param {string} id Command's ID
  22159. * @return {Boolean}
  22160. * */
  22161. has: function has(id) {
  22162. return !!commands[id];
  22163. },
  22164. /**
  22165. * Get an object containing all the commands
  22166. * @return {Object}
  22167. */
  22168. getAll: function getAll() {
  22169. return commands;
  22170. },
  22171. /**
  22172. * Execute the command
  22173. * @param {String} id Command ID
  22174. * @param {Object} [options={}] Options
  22175. * @return {*} The return is defined by the command
  22176. * @example
  22177. * commands.run('myCommand', { someOption: 1 });
  22178. */
  22179. run: function run(id) {
  22180. var options = arguments.length > 1 && arguments[1] !== undefined ? arguments[1] : {};
  22181. return this.runCommand(this.get(id), options);
  22182. },
  22183. /**
  22184. * Stop the command
  22185. * @param {String} id Command ID
  22186. * @param {Object} [options={}] Options
  22187. * @return {*} The return is defined by the command
  22188. * @example
  22189. * commands.stop('myCommand', { someOption: 1 });
  22190. */
  22191. stop: function stop(id) {
  22192. var options = arguments.length > 1 && arguments[1] !== undefined ? arguments[1] : {};
  22193. return this.stopCommand(this.get(id), options);
  22194. },
  22195. /**
  22196. * Check if the command is active. You activate commands with `run`
  22197. * and disable them with `stop`. If the command was created without `stop`
  22198. * method it can't be registered as active
  22199. * @param {String} id Command id
  22200. * @return {Boolean}
  22201. * @example
  22202. * const cId = 'some-command';
  22203. * commands.run(cId);
  22204. * commands.isActive(cId);
  22205. * // -> true
  22206. * commands.stop(cId);
  22207. * commands.isActive(cId);
  22208. * // -> false
  22209. */
  22210. isActive: function isActive(id) {
  22211. return this.getActive().hasOwnProperty(id);
  22212. },
  22213. /**
  22214. * Get all active commands
  22215. * @return {Object}
  22216. * @example
  22217. * console.log(commands.getActive());
  22218. * // -> { someCommand: itsLastReturn, anotherOne: ... };
  22219. */
  22220. getActive: function getActive() {
  22221. return active;
  22222. },
  22223. /**
  22224. * Load default commands
  22225. * @return {this}
  22226. * @private
  22227. * */
  22228. loadDefaultCommands: function loadDefaultCommands() {
  22229. for (var id in defaultCommands) {
  22230. this.add(id, defaultCommands[id]);
  22231. }
  22232. return this;
  22233. },
  22234. /**
  22235. * Run command via its object
  22236. * @param {Object} command
  22237. * @param {Object} options
  22238. * @return {*} Result of the command
  22239. * @private
  22240. */
  22241. runCommand: function runCommand(command) {
  22242. var options = arguments.length > 1 && arguments[1] !== undefined ? arguments[1] : {};
  22243. var result;
  22244. if (command && command.run) {
  22245. var id = command.id;
  22246. var editor = em.get('Editor');
  22247. if (!this.isActive(id) || options.force || !c.strict) {
  22248. result = command.callRun(editor, options);
  22249. if (id && command.stop && !command.noStop && !options.abort) {
  22250. active[id] = result;
  22251. }
  22252. }
  22253. }
  22254. return result;
  22255. },
  22256. /**
  22257. * Stop the command
  22258. * @param {Object} command
  22259. * @param {Object} options
  22260. * @return {*} Result of the command
  22261. * @private
  22262. */
  22263. stopCommand: function stopCommand(command) {
  22264. var options = arguments.length > 1 && arguments[1] !== undefined ? arguments[1] : {};
  22265. var result;
  22266. if (command && command.run) {
  22267. var id = command.id;
  22268. var editor = em.get('Editor');
  22269. if (this.isActive(id) || options.force || !c.strict) {
  22270. if (id) delete active[id];
  22271. result = command.callStop(editor, options);
  22272. }
  22273. }
  22274. return result;
  22275. },
  22276. /**
  22277. * Create anonymous Command instance
  22278. * @param {Object} command Command object
  22279. * @return {Command}
  22280. * @private
  22281. * */
  22282. create: function create(command) {
  22283. if (!command.stop) command.noStop = 1;
  22284. var cmd = _view_CommandAbstract__WEBPACK_IMPORTED_MODULE_3__["default"].extend(command);
  22285. return new cmd(c);
  22286. }
  22287. };
  22288. });
  22289. /***/ }),
  22290. /***/ "./src/commands/view sync recursive ^\\.\\/.*$":
  22291. /*!*****************************************!*\
  22292. !*** ./src/commands/view sync ^\.\/.*$ ***!
  22293. \*****************************************/
  22294. /*! no static exports found */
  22295. /***/ (function(module, exports, __webpack_require__) {
  22296. var map = {
  22297. "./CanvasClear": "./src/commands/view/CanvasClear.js",
  22298. "./CanvasClear.js": "./src/commands/view/CanvasClear.js",
  22299. "./CanvasMove": "./src/commands/view/CanvasMove.js",
  22300. "./CanvasMove.js": "./src/commands/view/CanvasMove.js",
  22301. "./CommandAbstract": "./src/commands/view/CommandAbstract.js",
  22302. "./CommandAbstract.js": "./src/commands/view/CommandAbstract.js",
  22303. "./ComponentDelete": "./src/commands/view/ComponentDelete.js",
  22304. "./ComponentDelete.js": "./src/commands/view/ComponentDelete.js",
  22305. "./ComponentDrag": "./src/commands/view/ComponentDrag.js",
  22306. "./ComponentDrag.js": "./src/commands/view/ComponentDrag.js",
  22307. "./ComponentEnter": "./src/commands/view/ComponentEnter.js",
  22308. "./ComponentEnter.js": "./src/commands/view/ComponentEnter.js",
  22309. "./ComponentExit": "./src/commands/view/ComponentExit.js",
  22310. "./ComponentExit.js": "./src/commands/view/ComponentExit.js",
  22311. "./ComponentNext": "./src/commands/view/ComponentNext.js",
  22312. "./ComponentNext.js": "./src/commands/view/ComponentNext.js",
  22313. "./ComponentPrev": "./src/commands/view/ComponentPrev.js",
  22314. "./ComponentPrev.js": "./src/commands/view/ComponentPrev.js",
  22315. "./ComponentStyleClear": "./src/commands/view/ComponentStyleClear.js",
  22316. "./ComponentStyleClear.js": "./src/commands/view/ComponentStyleClear.js",
  22317. "./CopyComponent": "./src/commands/view/CopyComponent.js",
  22318. "./CopyComponent.js": "./src/commands/view/CopyComponent.js",
  22319. "./DeleteComponent": "./src/commands/view/DeleteComponent.js",
  22320. "./DeleteComponent.js": "./src/commands/view/DeleteComponent.js",
  22321. "./ExportTemplate": "./src/commands/view/ExportTemplate.js",
  22322. "./ExportTemplate.js": "./src/commands/view/ExportTemplate.js",
  22323. "./Fullscreen": "./src/commands/view/Fullscreen.js",
  22324. "./Fullscreen.js": "./src/commands/view/Fullscreen.js",
  22325. "./MoveComponent": "./src/commands/view/MoveComponent.js",
  22326. "./MoveComponent.js": "./src/commands/view/MoveComponent.js",
  22327. "./OpenAssets": "./src/commands/view/OpenAssets.js",
  22328. "./OpenAssets.js": "./src/commands/view/OpenAssets.js",
  22329. "./OpenBlocks": "./src/commands/view/OpenBlocks.js",
  22330. "./OpenBlocks.js": "./src/commands/view/OpenBlocks.js",
  22331. "./OpenLayers": "./src/commands/view/OpenLayers.js",
  22332. "./OpenLayers.js": "./src/commands/view/OpenLayers.js",
  22333. "./OpenStyleManager": "./src/commands/view/OpenStyleManager.js",
  22334. "./OpenStyleManager.js": "./src/commands/view/OpenStyleManager.js",
  22335. "./OpenTraitManager": "./src/commands/view/OpenTraitManager.js",
  22336. "./OpenTraitManager.js": "./src/commands/view/OpenTraitManager.js",
  22337. "./PasteComponent": "./src/commands/view/PasteComponent.js",
  22338. "./PasteComponent.js": "./src/commands/view/PasteComponent.js",
  22339. "./Preview": "./src/commands/view/Preview.js",
  22340. "./Preview.js": "./src/commands/view/Preview.js",
  22341. "./Resize": "./src/commands/view/Resize.js",
  22342. "./Resize.js": "./src/commands/view/Resize.js",
  22343. "./SelectComponent": "./src/commands/view/SelectComponent.js",
  22344. "./SelectComponent.js": "./src/commands/view/SelectComponent.js",
  22345. "./SelectPosition": "./src/commands/view/SelectPosition.js",
  22346. "./SelectPosition.js": "./src/commands/view/SelectPosition.js",
  22347. "./ShowOffset": "./src/commands/view/ShowOffset.js",
  22348. "./ShowOffset.js": "./src/commands/view/ShowOffset.js",
  22349. "./SwitchVisibility": "./src/commands/view/SwitchVisibility.js",
  22350. "./SwitchVisibility.js": "./src/commands/view/SwitchVisibility.js"
  22351. };
  22352. function webpackContext(req) {
  22353. var id = webpackContextResolve(req);
  22354. return __webpack_require__(id);
  22355. }
  22356. function webpackContextResolve(req) {
  22357. if(!__webpack_require__.o(map, req)) {
  22358. var e = new Error("Cannot find module '" + req + "'");
  22359. e.code = 'MODULE_NOT_FOUND';
  22360. throw e;
  22361. }
  22362. return map[req];
  22363. }
  22364. webpackContext.keys = function webpackContextKeys() {
  22365. return Object.keys(map);
  22366. };
  22367. webpackContext.resolve = webpackContextResolve;
  22368. module.exports = webpackContext;
  22369. webpackContext.id = "./src/commands/view sync recursive ^\\.\\/.*$";
  22370. /***/ }),
  22371. /***/ "./src/commands/view/CanvasClear.js":
  22372. /*!******************************************!*\
  22373. !*** ./src/commands/view/CanvasClear.js ***!
  22374. \******************************************/
  22375. /*! exports provided: default */
  22376. /***/ (function(module, __webpack_exports__, __webpack_require__) {
  22377. "use strict";
  22378. __webpack_require__.r(__webpack_exports__);
  22379. /* harmony default export */ __webpack_exports__["default"] = ({
  22380. run: function run(ed) {
  22381. ed.DomComponents.clear();
  22382. ed.CssComposer.clear();
  22383. }
  22384. });
  22385. /***/ }),
  22386. /***/ "./src/commands/view/CanvasMove.js":
  22387. /*!*****************************************!*\
  22388. !*** ./src/commands/view/CanvasMove.js ***!
  22389. \*****************************************/
  22390. /*! exports provided: default */
  22391. /***/ (function(module, __webpack_exports__, __webpack_require__) {
  22392. "use strict";
  22393. __webpack_require__.r(__webpack_exports__);
  22394. /* harmony import */ var underscore__WEBPACK_IMPORTED_MODULE_0__ = __webpack_require__(/*! underscore */ "./node_modules/underscore/underscore.js");
  22395. /* harmony import */ var underscore__WEBPACK_IMPORTED_MODULE_0___default = /*#__PURE__*/__webpack_require__.n(underscore__WEBPACK_IMPORTED_MODULE_0__);
  22396. /* harmony import */ var utils_mixins__WEBPACK_IMPORTED_MODULE_1__ = __webpack_require__(/*! utils/mixins */ "./src/utils/mixins.js");
  22397. /* harmony import */ var utils_Dragger__WEBPACK_IMPORTED_MODULE_2__ = __webpack_require__(/*! utils/Dragger */ "./src/utils/Dragger.js");
  22398. /* harmony default export */ __webpack_exports__["default"] = ({
  22399. run: function run(ed) {
  22400. Object(underscore__WEBPACK_IMPORTED_MODULE_0__["bindAll"])(this, 'onKeyUp', 'enableDragger', 'disableDragger');
  22401. this.editor = ed;
  22402. this.canvasModel = this.canvas.getCanvasView().model;
  22403. this.toggleMove(1);
  22404. },
  22405. stop: function stop(ed) {
  22406. this.toggleMove();
  22407. this.disableDragger();
  22408. },
  22409. onKeyUp: function onKeyUp(ev) {
  22410. if (Object(utils_mixins__WEBPACK_IMPORTED_MODULE_1__["getKeyChar"])(ev) === ' ') {
  22411. this.editor.stopCommand(this.id);
  22412. }
  22413. },
  22414. enableDragger: function enableDragger(ev) {
  22415. this.toggleDragger(1, ev);
  22416. },
  22417. disableDragger: function disableDragger(ev) {
  22418. this.toggleDragger(0, ev);
  22419. },
  22420. toggleDragger: function toggleDragger(enable, ev) {
  22421. var canvasModel = this.canvasModel,
  22422. em = this.em;
  22423. var dragger = this.dragger;
  22424. var methodCls = enable ? 'add' : 'remove';
  22425. this.getCanvas().classList[methodCls]("".concat(this.ppfx, "is__grabbing"));
  22426. if (!dragger) {
  22427. dragger = new utils_Dragger__WEBPACK_IMPORTED_MODULE_2__["default"]({
  22428. getPosition: function getPosition() {
  22429. return {
  22430. x: canvasModel.get('x'),
  22431. y: canvasModel.get('y')
  22432. };
  22433. },
  22434. setPosition: function setPosition(_ref) {
  22435. var x = _ref.x,
  22436. y = _ref.y;
  22437. canvasModel.set({
  22438. x: x,
  22439. y: y
  22440. });
  22441. },
  22442. onStart: function onStart(ev, dragger) {
  22443. em.trigger('canvas:move:start', dragger);
  22444. },
  22445. onDrag: function onDrag(ev, dragger) {
  22446. em.trigger('canvas:move', dragger);
  22447. },
  22448. onEnd: function onEnd(ev, dragger) {
  22449. em.trigger('canvas:move:end', dragger);
  22450. }
  22451. });
  22452. this.dragger = dragger;
  22453. }
  22454. enable ? dragger.start(ev) : dragger.stop();
  22455. },
  22456. toggleMove: function toggleMove(enable) {
  22457. var ppfx = this.ppfx;
  22458. var methodCls = enable ? 'add' : 'remove';
  22459. var methodEv = enable ? 'on' : 'off';
  22460. var methodsEv = {
  22461. on: utils_mixins__WEBPACK_IMPORTED_MODULE_1__["on"],
  22462. off: utils_mixins__WEBPACK_IMPORTED_MODULE_1__["off"]
  22463. };
  22464. var canvas = this.getCanvas();
  22465. var classes = ["".concat(ppfx, "is__grab")];
  22466. !enable && classes.push("".concat(ppfx, "is__grabbing"));
  22467. classes.forEach(function (cls) {
  22468. return canvas.classList[methodCls](cls);
  22469. });
  22470. methodsEv[methodEv](document, 'keyup', this.onKeyUp);
  22471. methodsEv[methodEv](canvas, 'mousedown', this.enableDragger);
  22472. methodsEv[methodEv](document, 'mouseup', this.disableDragger);
  22473. }
  22474. });
  22475. /***/ }),
  22476. /***/ "./src/commands/view/CommandAbstract.js":
  22477. /*!**********************************************!*\
  22478. !*** ./src/commands/view/CommandAbstract.js ***!
  22479. \**********************************************/
  22480. /*! exports provided: default */
  22481. /***/ (function(module, __webpack_exports__, __webpack_require__) {
  22482. "use strict";
  22483. __webpack_require__.r(__webpack_exports__);
  22484. /* harmony import */ var backbone__WEBPACK_IMPORTED_MODULE_0__ = __webpack_require__(/*! backbone */ "./node_modules/backbone/backbone.js");
  22485. /* harmony import */ var backbone__WEBPACK_IMPORTED_MODULE_0___default = /*#__PURE__*/__webpack_require__.n(backbone__WEBPACK_IMPORTED_MODULE_0__);
  22486. var $ = backbone__WEBPACK_IMPORTED_MODULE_0___default.a.$;
  22487. /* harmony default export */ __webpack_exports__["default"] = (backbone__WEBPACK_IMPORTED_MODULE_0___default.a.View.extend({
  22488. /**
  22489. * Initialize method that can't be removed
  22490. * @param {Object} o Options
  22491. * @private
  22492. * */
  22493. initialize: function initialize(o) {
  22494. this.config = o || {};
  22495. this.editorModel = this.em = this.config.em || {};
  22496. this.pfx = this.config.stylePrefix;
  22497. this.ppfx = this.config.pStylePrefix;
  22498. this.hoverClass = this.pfx + 'hover';
  22499. this.badgeClass = this.pfx + 'badge';
  22500. this.plhClass = this.pfx + 'placeholder';
  22501. this.freezClass = this.ppfx + 'freezed';
  22502. this.canvas = this.em.get && this.em.get('Canvas');
  22503. if (this.em.get) this.setElement(this.getCanvas());
  22504. if (this.canvas) {
  22505. this.$canvas = this.$el; // this.$wrapper = $(this.getCanvasWrapper());
  22506. // this.frameEl = this.canvas.getFrameEl();
  22507. this.canvasTool = this.getCanvasTools(); // this.bodyEl = this.getCanvasBody();
  22508. }
  22509. this.init(this.config);
  22510. },
  22511. /**
  22512. * On frame scroll callback
  22513. * @param {[type]} e [description]
  22514. * @return {[type]} [description]
  22515. */
  22516. onFrameScroll: function onFrameScroll(e) {},
  22517. /**
  22518. * Returns canval element
  22519. * @return {HTMLElement}
  22520. */
  22521. getCanvas: function getCanvas() {
  22522. return this.canvas.getElement();
  22523. },
  22524. /**
  22525. * Get canvas body element
  22526. * @return {HTMLElement}
  22527. */
  22528. getCanvasBody: function getCanvasBody() {
  22529. return this.canvas.getBody();
  22530. },
  22531. /**
  22532. * Get canvas wrapper element
  22533. * @return {HTMLElement}
  22534. */
  22535. getCanvasWrapper: function getCanvasWrapper() {
  22536. return this.canvas.getWrapperEl();
  22537. },
  22538. /**
  22539. * Get canvas wrapper element
  22540. * @return {HTMLElement}
  22541. */
  22542. getCanvasTools: function getCanvasTools() {
  22543. return this.canvas.getToolsEl();
  22544. },
  22545. /**
  22546. * Get the offset of the element
  22547. * @param {HTMLElement} el
  22548. * @return {Object}
  22549. */
  22550. offset: function offset(el) {
  22551. var rect = el.getBoundingClientRect();
  22552. return {
  22553. top: rect.top + el.ownerDocument.body.scrollTop,
  22554. left: rect.left + el.ownerDocument.body.scrollLeft
  22555. };
  22556. },
  22557. /**
  22558. * Callback triggered after initialize
  22559. * @param {Object} o Options
  22560. * @private
  22561. * */
  22562. init: function init(o) {},
  22563. /**
  22564. * Method that run command
  22565. * @param {Object} editor Editor instance
  22566. * @param {Object} [options={}] Options
  22567. * @private
  22568. * */
  22569. callRun: function callRun(editor) {
  22570. var options = arguments.length > 1 && arguments[1] !== undefined ? arguments[1] : {};
  22571. var id = this.id;
  22572. editor.trigger("run:".concat(id, ":before"), options);
  22573. if (options && options.abort) {
  22574. editor.trigger("abort:".concat(id), options);
  22575. return;
  22576. }
  22577. var sender = options.sender || editor;
  22578. var result = this.run(editor, sender, options);
  22579. editor.trigger("run:".concat(id), result, options);
  22580. editor.trigger('run', id, result, options);
  22581. return result;
  22582. },
  22583. /**
  22584. * Method that run command
  22585. * @param {Object} editor Editor instance
  22586. * @param {Object} [options={}] Options
  22587. * @private
  22588. * */
  22589. callStop: function callStop(editor) {
  22590. var options = arguments.length > 1 && arguments[1] !== undefined ? arguments[1] : {};
  22591. var id = this.id;
  22592. var sender = options.sender || editor;
  22593. editor.trigger("stop:".concat(id, ":before"), options);
  22594. var result = this.stop(editor, sender, options);
  22595. editor.trigger("stop:".concat(id), result, options);
  22596. editor.trigger('stop', id, result, options);
  22597. return result;
  22598. },
  22599. /**
  22600. * Stop current command
  22601. */
  22602. stopCommand: function stopCommand() {
  22603. this.em.get('Commands').stop(this.id);
  22604. },
  22605. /**
  22606. * Method that run command
  22607. * @param {Object} em Editor model
  22608. * @param {Object} sender Button sender
  22609. * @private
  22610. * */
  22611. run: function run(em, sender) {},
  22612. /**
  22613. * Method that stop command
  22614. * @param {Object} em Editor model
  22615. * @param {Object} sender Button sender
  22616. * @private
  22617. * */
  22618. stop: function stop(em, sender) {}
  22619. }));
  22620. /***/ }),
  22621. /***/ "./src/commands/view/ComponentDelete.js":
  22622. /*!**********************************************!*\
  22623. !*** ./src/commands/view/ComponentDelete.js ***!
  22624. \**********************************************/
  22625. /*! exports provided: default */
  22626. /***/ (function(module, __webpack_exports__, __webpack_require__) {
  22627. "use strict";
  22628. __webpack_require__.r(__webpack_exports__);
  22629. /* harmony import */ var _babel_runtime_helpers_toConsumableArray__WEBPACK_IMPORTED_MODULE_0__ = __webpack_require__(/*! @babel/runtime/helpers/toConsumableArray */ "./node_modules/@babel/runtime/helpers/toConsumableArray.js");
  22630. /* harmony import */ var _babel_runtime_helpers_toConsumableArray__WEBPACK_IMPORTED_MODULE_0___default = /*#__PURE__*/__webpack_require__.n(_babel_runtime_helpers_toConsumableArray__WEBPACK_IMPORTED_MODULE_0__);
  22631. /* harmony import */ var underscore__WEBPACK_IMPORTED_MODULE_1__ = __webpack_require__(/*! underscore */ "./node_modules/underscore/underscore.js");
  22632. /* harmony import */ var underscore__WEBPACK_IMPORTED_MODULE_1___default = /*#__PURE__*/__webpack_require__.n(underscore__WEBPACK_IMPORTED_MODULE_1__);
  22633. /* harmony default export */ __webpack_exports__["default"] = ({
  22634. run: function run(ed, sender) {
  22635. var _this = this;
  22636. var opts = arguments.length > 2 && arguments[2] !== undefined ? arguments[2] : {};
  22637. var components = opts.component || ed.getSelectedAll();
  22638. components = Object(underscore__WEBPACK_IMPORTED_MODULE_1__["isArray"])(components) ? _babel_runtime_helpers_toConsumableArray__WEBPACK_IMPORTED_MODULE_0___default()(components) : [components]; // It's important to deselect components first otherwise,
  22639. // with undo, the component will be set with the wrong `collection`
  22640. ed.select(null);
  22641. components.forEach(function (component) {
  22642. if (!component || !component.get('removable')) {
  22643. return _this.em.logWarning('The element is not removable', {
  22644. component: component
  22645. });
  22646. }
  22647. component.remove();
  22648. });
  22649. return components;
  22650. }
  22651. });
  22652. /***/ }),
  22653. /***/ "./src/commands/view/ComponentDrag.js":
  22654. /*!********************************************!*\
  22655. !*** ./src/commands/view/ComponentDrag.js ***!
  22656. \********************************************/
  22657. /*! exports provided: default */
  22658. /***/ (function(module, __webpack_exports__, __webpack_require__) {
  22659. "use strict";
  22660. __webpack_require__.r(__webpack_exports__);
  22661. /* harmony import */ var _babel_runtime_helpers_defineProperty__WEBPACK_IMPORTED_MODULE_0__ = __webpack_require__(/*! @babel/runtime/helpers/defineProperty */ "./node_modules/@babel/runtime/helpers/defineProperty.js");
  22662. /* harmony import */ var _babel_runtime_helpers_defineProperty__WEBPACK_IMPORTED_MODULE_0___default = /*#__PURE__*/__webpack_require__.n(_babel_runtime_helpers_defineProperty__WEBPACK_IMPORTED_MODULE_0__);
  22663. /* harmony import */ var underscore__WEBPACK_IMPORTED_MODULE_1__ = __webpack_require__(/*! underscore */ "./node_modules/underscore/underscore.js");
  22664. /* harmony import */ var underscore__WEBPACK_IMPORTED_MODULE_1___default = /*#__PURE__*/__webpack_require__.n(underscore__WEBPACK_IMPORTED_MODULE_1__);
  22665. /* harmony import */ var utils_Dragger__WEBPACK_IMPORTED_MODULE_2__ = __webpack_require__(/*! utils/Dragger */ "./src/utils/Dragger.js");
  22666. function ownKeys(object, enumerableOnly) { var keys = Object.keys(object); if (Object.getOwnPropertySymbols) { var symbols = Object.getOwnPropertySymbols(object); if (enumerableOnly) symbols = symbols.filter(function (sym) { return Object.getOwnPropertyDescriptor(object, sym).enumerable; }); keys.push.apply(keys, symbols); } return keys; }
  22667. function _objectSpread(target) { for (var i = 1; i < arguments.length; i++) { var source = arguments[i] != null ? arguments[i] : {}; if (i % 2) { ownKeys(source, true).forEach(function (key) { _babel_runtime_helpers_defineProperty__WEBPACK_IMPORTED_MODULE_0___default()(target, key, source[key]); }); } else if (Object.getOwnPropertyDescriptors) { Object.defineProperties(target, Object.getOwnPropertyDescriptors(source)); } else { ownKeys(source).forEach(function (key) { Object.defineProperty(target, key, Object.getOwnPropertyDescriptor(source, key)); }); } } return target; }
  22668. var evName = 'dmode';
  22669. /* harmony default export */ __webpack_exports__["default"] = ({
  22670. run: function run(editor, sender) {
  22671. var _this = this;
  22672. var opts = arguments.length > 2 && arguments[2] !== undefined ? arguments[2] : {};
  22673. Object(underscore__WEBPACK_IMPORTED_MODULE_1__["bindAll"])(this, 'setPosition', 'onStart', 'onDrag', 'onEnd', 'getPosition', 'getGuidesStatic', 'renderGuide', 'getGuidesTarget');
  22674. var target = opts.target,
  22675. event = opts.event,
  22676. mode = opts.mode,
  22677. _opts$dragger = opts.dragger,
  22678. dragger = _opts$dragger === void 0 ? {} : _opts$dragger;
  22679. var el = target.getEl();
  22680. var config = _objectSpread({
  22681. doc: el.ownerDocument,
  22682. onStart: this.onStart,
  22683. onEnd: this.onEnd,
  22684. onDrag: this.onDrag,
  22685. getPosition: this.getPosition,
  22686. setPosition: this.setPosition,
  22687. guidesStatic: function guidesStatic() {
  22688. return _this.guidesStatic;
  22689. },
  22690. guidesTarget: function guidesTarget() {
  22691. return _this.guidesTarget;
  22692. }
  22693. }, dragger);
  22694. this.setupGuides();
  22695. this.opts = opts;
  22696. this.editor = editor;
  22697. this.em = editor.getModel();
  22698. this.target = target;
  22699. this.isTran = mode == 'translate';
  22700. this.guidesContainer = this.getGuidesContainer();
  22701. this.guidesTarget = this.getGuidesTarget();
  22702. this.guidesStatic = this.getGuidesStatic();
  22703. var drg = this.dragger;
  22704. if (!drg) {
  22705. drg = new utils_Dragger__WEBPACK_IMPORTED_MODULE_2__["default"](config);
  22706. this.dragger = drg;
  22707. } else {
  22708. drg.setOptions(config);
  22709. }
  22710. event && drg.start(event);
  22711. this.toggleDrag(1);
  22712. this.em.trigger("".concat(evName, ":start"), this.getEventOpts());
  22713. return drg;
  22714. },
  22715. getEventOpts: function getEventOpts() {
  22716. return {
  22717. mode: this.opts.mode,
  22718. target: this.target,
  22719. guidesTarget: this.guidesTarget,
  22720. guidesStatic: this.guidesStatic
  22721. };
  22722. },
  22723. stop: function stop() {
  22724. this.toggleDrag();
  22725. },
  22726. setupGuides: function setupGuides() {
  22727. (this.guides || []).forEach(function (item) {
  22728. var guide = item.guide;
  22729. guide && guide.parentNode.removeChild(guide);
  22730. });
  22731. this.guides = [];
  22732. },
  22733. getGuidesContainer: function getGuidesContainer() {
  22734. var _this2 = this;
  22735. var guidesEl = this.guidesEl;
  22736. if (!guidesEl) {
  22737. var editor = this.editor,
  22738. em = this.em,
  22739. opts = this.opts;
  22740. var pfx = editor.getConfig('stylePrefix');
  22741. var elInfoX = document.createElement('div');
  22742. var elInfoY = document.createElement('div');
  22743. var guideContent = "<div class=\"".concat(pfx, "guide-info__line ").concat(pfx, "danger-bg\">\n <div class=\"").concat(pfx, "guide-info__content ").concat(pfx, "danger-color\"></div>\n </div>");
  22744. guidesEl = document.createElement('div');
  22745. guidesEl.className = "".concat(pfx, "guides");
  22746. elInfoX.className = "".concat(pfx, "guide-info ").concat(pfx, "guide-info__x");
  22747. elInfoY.className = "".concat(pfx, "guide-info ").concat(pfx, "guide-info__y");
  22748. elInfoX.innerHTML = guideContent;
  22749. elInfoY.innerHTML = guideContent;
  22750. guidesEl.appendChild(elInfoX);
  22751. guidesEl.appendChild(elInfoY);
  22752. editor.Canvas.getGlobalToolsEl().appendChild(guidesEl);
  22753. this.guidesEl = guidesEl;
  22754. this.elGuideInfoX = elInfoX;
  22755. this.elGuideInfoY = elInfoY;
  22756. this.elGuideInfoContentX = elInfoX.querySelector(".".concat(pfx, "guide-info__content"));
  22757. this.elGuideInfoContentY = elInfoY.querySelector(".".concat(pfx, "guide-info__content"));
  22758. em.on('canvas:update frame:scroll', Object(underscore__WEBPACK_IMPORTED_MODULE_1__["debounce"])(function () {
  22759. _this2.updateGuides();
  22760. opts.debug && _this2.guides.forEach(function (item) {
  22761. return _this2.renderGuide(item);
  22762. });
  22763. }, 200));
  22764. }
  22765. return guidesEl;
  22766. },
  22767. getGuidesStatic: function getGuidesStatic() {
  22768. var _this3 = this;
  22769. var result = [];
  22770. var el = this.target.getEl();
  22771. var _el$parentNode = el.parentNode,
  22772. parentNode = _el$parentNode === void 0 ? {} : _el$parentNode;
  22773. Object(underscore__WEBPACK_IMPORTED_MODULE_1__["each"])(parentNode.children, function (item) {
  22774. return result = result.concat(el !== item ? _this3.getElementGuides(item) : []);
  22775. });
  22776. return result.concat(this.getElementGuides(parentNode));
  22777. },
  22778. getGuidesTarget: function getGuidesTarget() {
  22779. return this.getElementGuides(this.target.getEl());
  22780. },
  22781. updateGuides: function updateGuides(guides) {
  22782. var _this4 = this;
  22783. var lastEl, lastPos;
  22784. (guides || this.guides).forEach(function (item) {
  22785. var origin = item.origin;
  22786. var pos = lastEl === origin ? lastPos : _this4.getElementPos(origin);
  22787. lastEl = origin;
  22788. lastPos = pos;
  22789. Object(underscore__WEBPACK_IMPORTED_MODULE_1__["each"])(_this4.getGuidePosUpdate(item, pos), function (val, key) {
  22790. return item[key] = val;
  22791. });
  22792. item.originRect = pos;
  22793. });
  22794. },
  22795. getGuidePosUpdate: function getGuidePosUpdate(item, rect) {
  22796. var result = {};
  22797. var top = rect.top,
  22798. height = rect.height,
  22799. left = rect.left,
  22800. width = rect.width;
  22801. switch (item.type) {
  22802. case 't':
  22803. result.y = top;
  22804. break;
  22805. case 'b':
  22806. result.y = top + height;
  22807. break;
  22808. case 'l':
  22809. result.x = left;
  22810. break;
  22811. case 'r':
  22812. result.x = left + width;
  22813. break;
  22814. case 'x':
  22815. result.x = left + width / 2;
  22816. break;
  22817. case 'y':
  22818. result.y = top + height / 2;
  22819. break;
  22820. }
  22821. return result;
  22822. },
  22823. renderGuide: function renderGuide() {
  22824. var item = arguments.length > 0 && arguments[0] !== undefined ? arguments[0] : {};
  22825. var el = item.guide || document.createElement('div');
  22826. var un = 'px';
  22827. var guideSize = item.active ? 2 : 1;
  22828. var numEl = el.children[0];
  22829. el.style = "position: absolute; background-color: ".concat(item.active ? 'green' : 'red', ";");
  22830. if (!el.children.length) {
  22831. numEl = document.createElement('div');
  22832. numEl.style = 'position: absolute; color: red; padding: 5px; top: 0; left: 0;';
  22833. el.appendChild(numEl);
  22834. }
  22835. if (item.y) {
  22836. el.style.width = '100%';
  22837. el.style.height = "".concat(guideSize).concat(un);
  22838. el.style.top = "".concat(item.y).concat(un);
  22839. el.style.left = 0;
  22840. } else {
  22841. el.style.width = "".concat(guideSize).concat(un);
  22842. el.style.height = '100%';
  22843. el.style.left = "".concat(item.x).concat(un);
  22844. el.style.top = "0".concat(un);
  22845. }
  22846. !item.guide && this.guidesContainer.appendChild(el);
  22847. return el;
  22848. },
  22849. getElementPos: function getElementPos(el) {
  22850. return this.editor.Canvas.getElementPos(el, {
  22851. noScroll: 1
  22852. });
  22853. },
  22854. getElementGuides: function getElementGuides(el) {
  22855. var _this5 = this;
  22856. var opts = this.opts;
  22857. var originRect = this.getElementPos(el);
  22858. var top = originRect.top,
  22859. height = originRect.height,
  22860. left = originRect.left,
  22861. width = originRect.width;
  22862. var guides = [{
  22863. type: 't',
  22864. y: top
  22865. }, // Top
  22866. {
  22867. type: 'b',
  22868. y: top + height
  22869. }, // Bottom
  22870. {
  22871. type: 'l',
  22872. x: left
  22873. }, // Left
  22874. {
  22875. type: 'r',
  22876. x: left + width
  22877. }, // Right
  22878. {
  22879. type: 'x',
  22880. x: left + width / 2
  22881. }, // Mid x
  22882. {
  22883. type: 'y',
  22884. y: top + height / 2
  22885. } // Mid y
  22886. ].map(function (item) {
  22887. return _objectSpread({}, item, {
  22888. origin: el,
  22889. originRect: originRect,
  22890. guide: opts.debug && _this5.renderGuide(item)
  22891. });
  22892. });
  22893. guides.forEach(function (item) {
  22894. return _this5.guides.push(item);
  22895. });
  22896. return guides;
  22897. },
  22898. getTranslate: function getTranslate(transform) {
  22899. var axis = arguments.length > 1 && arguments[1] !== undefined ? arguments[1] : 'x';
  22900. var result = 0;
  22901. (transform || '').split(' ').forEach(function (item) {
  22902. var itemStr = item.trim();
  22903. var fn = "translate".concat(axis.toUpperCase(), "(");
  22904. if (itemStr.indexOf(fn) === 0) result = parseFloat(itemStr.replace(fn, ''));
  22905. });
  22906. return result;
  22907. },
  22908. setTranslate: function setTranslate(transform, axis, value) {
  22909. var fn = "translate".concat(axis.toUpperCase(), "(");
  22910. var val = "".concat(fn).concat(value, ")");
  22911. var result = (transform || '').split(' ').map(function (item) {
  22912. var itemStr = item.trim();
  22913. if (itemStr.indexOf(fn) === 0) item = val;
  22914. return item;
  22915. }).join(' ');
  22916. if (result.indexOf(fn) < 0) result += " ".concat(val);
  22917. return result;
  22918. },
  22919. getPosition: function getPosition() {
  22920. var target = this.target,
  22921. isTran = this.isTran;
  22922. var _target$getStyle = target.getStyle(),
  22923. left = _target$getStyle.left,
  22924. top = _target$getStyle.top,
  22925. transform = _target$getStyle.transform;
  22926. var x = 0;
  22927. var y = 0;
  22928. if (isTran) {
  22929. x = this.getTranslate(transform);
  22930. y = this.getTranslate(transform, 'y');
  22931. } else {
  22932. x = parseFloat(left);
  22933. y = parseFloat(top);
  22934. }
  22935. return {
  22936. x: x,
  22937. y: y
  22938. };
  22939. },
  22940. setPosition: function setPosition(_ref) {
  22941. var x = _ref.x,
  22942. y = _ref.y,
  22943. end = _ref.end,
  22944. position = _ref.position,
  22945. width = _ref.width,
  22946. height = _ref.height;
  22947. var target = this.target,
  22948. isTran = this.isTran;
  22949. var unit = 'px';
  22950. var en = !end ? 1 : ''; // this will trigger the final change
  22951. var left = "".concat(x).concat(unit);
  22952. var top = "".concat(y).concat(unit);
  22953. if (isTran) {
  22954. var transform = target.getStyle()['transform'] || '';
  22955. transform = this.setTranslate(transform, 'x', left);
  22956. transform = this.setTranslate(transform, 'y', top);
  22957. return target.addStyle({
  22958. transform: transform,
  22959. en: en
  22960. }, {
  22961. avoidStore: !end
  22962. });
  22963. }
  22964. var adds = {
  22965. position: position,
  22966. width: width,
  22967. height: height
  22968. };
  22969. var style = {
  22970. left: left,
  22971. top: top,
  22972. en: en
  22973. };
  22974. Object(underscore__WEBPACK_IMPORTED_MODULE_1__["keys"])(adds).forEach(function (add) {
  22975. var prop = adds[add];
  22976. if (prop) style[add] = prop;
  22977. });
  22978. target.addStyle(style, {
  22979. avoidStore: !end
  22980. });
  22981. },
  22982. _getDragData: function _getDragData() {
  22983. var target = this.target;
  22984. return {
  22985. target: target,
  22986. parent: target.parent(),
  22987. index: target.index()
  22988. };
  22989. },
  22990. onStart: function onStart() {
  22991. var target = this.target,
  22992. editor = this.editor,
  22993. isTran = this.isTran,
  22994. opts = this.opts;
  22995. var center = opts.center,
  22996. onStart = opts.onStart;
  22997. var Canvas = editor.Canvas;
  22998. var style = target.getStyle();
  22999. var position = 'absolute';
  23000. onStart && onStart(this._getDragData());
  23001. if (isTran) return;
  23002. if (style.position !== position) {
  23003. var _Canvas$offset = Canvas.offset(target.getEl()),
  23004. left = _Canvas$offset.left,
  23005. top = _Canvas$offset.top,
  23006. width = _Canvas$offset.width,
  23007. height = _Canvas$offset.height; // Check if to center the target to the pointer position
  23008. if (center) {
  23009. var _Canvas$getMouseRelat = Canvas.getMouseRelativeCanvas(event),
  23010. x = _Canvas$getMouseRelat.x,
  23011. y = _Canvas$getMouseRelat.y;
  23012. left = x;
  23013. top = y;
  23014. }
  23015. this.setPosition({
  23016. x: left,
  23017. y: top,
  23018. width: "".concat(width, "px"),
  23019. height: "".concat(height, "px"),
  23020. position: position
  23021. });
  23022. }
  23023. },
  23024. onDrag: function onDrag() {
  23025. var _this6 = this;
  23026. var guidesTarget = this.guidesTarget,
  23027. opts = this.opts;
  23028. var onDrag = opts.onDrag;
  23029. this.updateGuides(guidesTarget);
  23030. opts.debug && guidesTarget.forEach(function (item) {
  23031. return _this6.renderGuide(item);
  23032. });
  23033. opts.guidesInfo && this.renderGuideInfo(guidesTarget.filter(function (item) {
  23034. return item.active;
  23035. }));
  23036. onDrag && onDrag(this._getDragData());
  23037. },
  23038. onEnd: function onEnd(ev, dragger) {
  23039. var opt = arguments.length > 2 && arguments[2] !== undefined ? arguments[2] : {};
  23040. var editor = this.editor,
  23041. opts = this.opts,
  23042. id = this.id;
  23043. var onEnd = opts.onEnd;
  23044. onEnd && onEnd(ev, opt, _objectSpread({
  23045. event: ev
  23046. }, opt, {}, this._getDragData()));
  23047. editor.stopCommand(id);
  23048. this.hideGuidesInfo();
  23049. this.em.trigger("".concat(evName, ":end"), this.getEventOpts());
  23050. },
  23051. hideGuidesInfo: function hideGuidesInfo() {
  23052. var _this7 = this;
  23053. ['X', 'Y'].forEach(function (item) {
  23054. var guide = _this7["elGuideInfo".concat(item)];
  23055. if (guide) guide.style.display = 'none';
  23056. });
  23057. },
  23058. /**
  23059. * Render guides with spacing information
  23060. */
  23061. renderGuideInfo: function renderGuideInfo() {
  23062. var _this8 = this;
  23063. var guides = arguments.length > 0 && arguments[0] !== undefined ? arguments[0] : [];
  23064. var guidesStatic = this.guidesStatic;
  23065. this.hideGuidesInfo();
  23066. guides.forEach(function (item) {
  23067. var origin = item.origin,
  23068. x = item.x;
  23069. var rectOrigin = _this8.getElementPos(origin);
  23070. var axis = Object(underscore__WEBPACK_IMPORTED_MODULE_1__["isUndefined"])(x) ? 'y' : 'x';
  23071. var isY = axis === 'y';
  23072. var origEdge1 = rectOrigin[isY ? 'left' : 'top'];
  23073. var origEdge1Raw = rectOrigin.rect[isY ? 'left' : 'top'];
  23074. var origEdge2 = isY ? origEdge1 + rectOrigin.width : origEdge1 + rectOrigin.height;
  23075. var origEdge2Raw = isY ? origEdge1Raw + rectOrigin.rect.width : origEdge1Raw + rectOrigin.rect.height;
  23076. var elGuideInfo = _this8["elGuideInfo".concat(axis.toUpperCase())];
  23077. var elGuideInfoCnt = _this8["elGuideInfoContent".concat(axis.toUpperCase())];
  23078. var guideInfoStyle = elGuideInfo.style; // Find the nearest element
  23079. var res = guidesStatic.filter(function (stat) {
  23080. return stat.type === item.type;
  23081. }).map(function (stat) {
  23082. var _stat$originRect = stat.originRect,
  23083. left = _stat$originRect.left,
  23084. width = _stat$originRect.width,
  23085. top = _stat$originRect.top,
  23086. height = _stat$originRect.height;
  23087. var statEdge1 = isY ? left : top;
  23088. var statEdge2 = isY ? left + width : top + height;
  23089. return {
  23090. gap: statEdge2 < origEdge1 ? origEdge1 - statEdge2 : statEdge1 - origEdge2,
  23091. guide: stat
  23092. };
  23093. }).filter(function (item) {
  23094. return item.gap > 0;
  23095. }).sort(function (a, b) {
  23096. return a.gap - b.gap;
  23097. }).map(function (item) {
  23098. return item.guide;
  23099. })[0];
  23100. if (res) {
  23101. var _res$originRect = res.originRect,
  23102. left = _res$originRect.left,
  23103. width = _res$originRect.width,
  23104. top = _res$originRect.top,
  23105. height = _res$originRect.height,
  23106. rect = _res$originRect.rect;
  23107. var isEdge1 = isY ? left < rectOrigin.left : top < rectOrigin.top;
  23108. var statEdge1 = isY ? left : top;
  23109. var statEdge1Raw = isY ? rect.left : rect.top;
  23110. var statEdge2 = isY ? left + width : top + height;
  23111. var statEdge2Raw = isY ? rect.left + rect.width : rect.top + rect.height;
  23112. var posFirst = isY ? item.y : item.x;
  23113. var posSecond = isEdge1 ? statEdge2 : origEdge2;
  23114. var pos2 = "".concat(posFirst, "px");
  23115. var size = isEdge1 ? origEdge1 - statEdge2 : statEdge1 - origEdge2;
  23116. var sizeRaw = isEdge1 ? origEdge1Raw - statEdge2Raw : statEdge1Raw - origEdge2Raw;
  23117. guideInfoStyle.display = '';
  23118. guideInfoStyle[isY ? 'top' : 'left'] = pos2;
  23119. guideInfoStyle[isY ? 'left' : 'top'] = "".concat(posSecond, "px");
  23120. guideInfoStyle[isY ? 'width' : 'height'] = "".concat(size, "px");
  23121. elGuideInfoCnt.innerHTML = "".concat(Math.round(sizeRaw), "px");
  23122. _this8.em.trigger("".concat(evName, ":active"), _objectSpread({}, _this8.getEventOpts(), {
  23123. guide: item,
  23124. guidesStatic: guidesStatic,
  23125. matched: res,
  23126. posFirst: posFirst,
  23127. posSecond: posSecond,
  23128. size: size,
  23129. sizeRaw: sizeRaw,
  23130. elGuideInfo: elGuideInfo,
  23131. elGuideInfoCnt: elGuideInfoCnt
  23132. }));
  23133. }
  23134. });
  23135. },
  23136. toggleDrag: function toggleDrag(enable) {
  23137. var ppfx = this.ppfx,
  23138. editor = this.editor;
  23139. var methodCls = enable ? 'add' : 'remove';
  23140. var classes = ["".concat(ppfx, "is__grabbing")];
  23141. var Canvas = editor.Canvas;
  23142. var body = Canvas.getBody();
  23143. classes.forEach(function (cls) {
  23144. return body.classList[methodCls](cls);
  23145. });
  23146. Canvas[enable ? 'startAutoscroll' : 'stopAutoscroll']();
  23147. }
  23148. });
  23149. /***/ }),
  23150. /***/ "./src/commands/view/ComponentEnter.js":
  23151. /*!*********************************************!*\
  23152. !*** ./src/commands/view/ComponentEnter.js ***!
  23153. \*********************************************/
  23154. /*! exports provided: default */
  23155. /***/ (function(module, __webpack_exports__, __webpack_require__) {
  23156. "use strict";
  23157. __webpack_require__.r(__webpack_exports__);
  23158. /* harmony default export */ __webpack_exports__["default"] = ({
  23159. run: function run(ed) {
  23160. if (!ed.Canvas.hasFocus()) return;
  23161. var toSelect = [];
  23162. ed.getSelectedAll().forEach(function (component) {
  23163. var coll = component.components();
  23164. var next = coll && coll.at(0);
  23165. next && toSelect.push(next);
  23166. });
  23167. toSelect.length && ed.select(toSelect);
  23168. }
  23169. });
  23170. /***/ }),
  23171. /***/ "./src/commands/view/ComponentExit.js":
  23172. /*!********************************************!*\
  23173. !*** ./src/commands/view/ComponentExit.js ***!
  23174. \********************************************/
  23175. /*! exports provided: default */
  23176. /***/ (function(module, __webpack_exports__, __webpack_require__) {
  23177. "use strict";
  23178. __webpack_require__.r(__webpack_exports__);
  23179. /* harmony default export */ __webpack_exports__["default"] = ({
  23180. run: function run(ed, snd) {
  23181. var opts = arguments.length > 2 && arguments[2] !== undefined ? arguments[2] : {};
  23182. if (!ed.Canvas.hasFocus() && !opts.force) return;
  23183. var toSelect = [];
  23184. ed.getSelectedAll().forEach(function (component) {
  23185. var next = component.parent(); // Recurse through the parent() chain until a selectable parent is found
  23186. while (next && !next.get('selectable')) {
  23187. next = next.parent();
  23188. }
  23189. next && toSelect.push(next);
  23190. });
  23191. toSelect.length && ed.select(toSelect);
  23192. }
  23193. });
  23194. /***/ }),
  23195. /***/ "./src/commands/view/ComponentNext.js":
  23196. /*!********************************************!*\
  23197. !*** ./src/commands/view/ComponentNext.js ***!
  23198. \********************************************/
  23199. /*! exports provided: default */
  23200. /***/ (function(module, __webpack_exports__, __webpack_require__) {
  23201. "use strict";
  23202. __webpack_require__.r(__webpack_exports__);
  23203. /* harmony default export */ __webpack_exports__["default"] = ({
  23204. run: function run(ed) {
  23205. if (!ed.Canvas.hasFocus()) return;
  23206. var toSelect = [];
  23207. ed.getSelectedAll().forEach(function (component) {
  23208. var coll = component.collection;
  23209. var at = coll.indexOf(component);
  23210. var next = coll.at(at + 1);
  23211. toSelect.push(next || component);
  23212. });
  23213. toSelect.length && ed.select(toSelect);
  23214. }
  23215. });
  23216. /***/ }),
  23217. /***/ "./src/commands/view/ComponentPrev.js":
  23218. /*!********************************************!*\
  23219. !*** ./src/commands/view/ComponentPrev.js ***!
  23220. \********************************************/
  23221. /*! exports provided: default */
  23222. /***/ (function(module, __webpack_exports__, __webpack_require__) {
  23223. "use strict";
  23224. __webpack_require__.r(__webpack_exports__);
  23225. /* harmony default export */ __webpack_exports__["default"] = ({
  23226. run: function run(ed) {
  23227. if (!ed.Canvas.hasFocus()) return;
  23228. var toSelect = [];
  23229. ed.getSelectedAll().forEach(function (component) {
  23230. var coll = component.collection;
  23231. var at = coll.indexOf(component);
  23232. var next = coll.at(at - 1);
  23233. toSelect.push(next && at - 1 >= 0 ? next : component);
  23234. });
  23235. toSelect.length && ed.select(toSelect);
  23236. }
  23237. });
  23238. /***/ }),
  23239. /***/ "./src/commands/view/ComponentStyleClear.js":
  23240. /*!**************************************************!*\
  23241. !*** ./src/commands/view/ComponentStyleClear.js ***!
  23242. \**************************************************/
  23243. /*! exports provided: default */
  23244. /***/ (function(module, __webpack_exports__, __webpack_require__) {
  23245. "use strict";
  23246. __webpack_require__.r(__webpack_exports__);
  23247. /* harmony import */ var underscore__WEBPACK_IMPORTED_MODULE_0__ = __webpack_require__(/*! underscore */ "./node_modules/underscore/underscore.js");
  23248. /* harmony import */ var underscore__WEBPACK_IMPORTED_MODULE_0___default = /*#__PURE__*/__webpack_require__.n(underscore__WEBPACK_IMPORTED_MODULE_0__);
  23249. /* harmony default export */ __webpack_exports__["default"] = ({
  23250. run: function run(ed, sender) {
  23251. var opts = arguments.length > 2 && arguments[2] !== undefined ? arguments[2] : {};
  23252. var target = opts.target;
  23253. var dc = ed.DomComponents;
  23254. var type = target.get('type');
  23255. var len = dc.getWrapper().find("[data-gjs-type=\"".concat(type, "\"]")).length;
  23256. var toRemove = [];
  23257. if (!len) {
  23258. var rules = ed.CssComposer.getAll();
  23259. var toClear = target.get('style-signature');
  23260. toClear = Object(underscore__WEBPACK_IMPORTED_MODULE_0__["isArray"])(toClear) ? toClear : [toClear];
  23261. rules.forEach(function (rule) {
  23262. var selector = rule.selectorsToString();
  23263. toClear.forEach(function (part) {
  23264. part && selector.indexOf(part) >= 0 && toRemove.push(rule);
  23265. });
  23266. });
  23267. rules.remove(toRemove);
  23268. }
  23269. return toRemove;
  23270. }
  23271. });
  23272. /***/ }),
  23273. /***/ "./src/commands/view/CopyComponent.js":
  23274. /*!********************************************!*\
  23275. !*** ./src/commands/view/CopyComponent.js ***!
  23276. \********************************************/
  23277. /*! exports provided: default */
  23278. /***/ (function(module, __webpack_exports__, __webpack_require__) {
  23279. "use strict";
  23280. __webpack_require__.r(__webpack_exports__);
  23281. /* harmony import */ var _babel_runtime_helpers_toConsumableArray__WEBPACK_IMPORTED_MODULE_0__ = __webpack_require__(/*! @babel/runtime/helpers/toConsumableArray */ "./node_modules/@babel/runtime/helpers/toConsumableArray.js");
  23282. /* harmony import */ var _babel_runtime_helpers_toConsumableArray__WEBPACK_IMPORTED_MODULE_0___default = /*#__PURE__*/__webpack_require__.n(_babel_runtime_helpers_toConsumableArray__WEBPACK_IMPORTED_MODULE_0__);
  23283. /* harmony default export */ __webpack_exports__["default"] = ({
  23284. run: function run(ed) {
  23285. var em = ed.getModel();
  23286. var models = _babel_runtime_helpers_toConsumableArray__WEBPACK_IMPORTED_MODULE_0___default()(ed.getSelectedAll());
  23287. if (models.length) {
  23288. em.set('clipboard', models);
  23289. }
  23290. }
  23291. });
  23292. /***/ }),
  23293. /***/ "./src/commands/view/DeleteComponent.js":
  23294. /*!**********************************************!*\
  23295. !*** ./src/commands/view/DeleteComponent.js ***!
  23296. \**********************************************/
  23297. /*! exports provided: default */
  23298. /***/ (function(module, __webpack_exports__, __webpack_require__) {
  23299. "use strict";
  23300. __webpack_require__.r(__webpack_exports__);
  23301. /* harmony import */ var underscore__WEBPACK_IMPORTED_MODULE_0__ = __webpack_require__(/*! underscore */ "./node_modules/underscore/underscore.js");
  23302. /* harmony import */ var underscore__WEBPACK_IMPORTED_MODULE_0___default = /*#__PURE__*/__webpack_require__.n(underscore__WEBPACK_IMPORTED_MODULE_0__);
  23303. /* harmony import */ var backbone__WEBPACK_IMPORTED_MODULE_1__ = __webpack_require__(/*! backbone */ "./node_modules/backbone/backbone.js");
  23304. /* harmony import */ var backbone__WEBPACK_IMPORTED_MODULE_1___default = /*#__PURE__*/__webpack_require__.n(backbone__WEBPACK_IMPORTED_MODULE_1__);
  23305. /* harmony import */ var _SelectComponent__WEBPACK_IMPORTED_MODULE_2__ = __webpack_require__(/*! ./SelectComponent */ "./src/commands/view/SelectComponent.js");
  23306. var $ = backbone__WEBPACK_IMPORTED_MODULE_1___default.a.$;
  23307. /* harmony default export */ __webpack_exports__["default"] = (Object(underscore__WEBPACK_IMPORTED_MODULE_0__["extend"])({}, _SelectComponent__WEBPACK_IMPORTED_MODULE_2__["default"], {
  23308. init: function init(o) {
  23309. Object(underscore__WEBPACK_IMPORTED_MODULE_0__["bindAll"])(this, 'startDelete', 'stopDelete', 'onDelete');
  23310. this.hoverClass = this.pfx + 'hover-delete';
  23311. this.badgeClass = this.pfx + 'badge-red';
  23312. },
  23313. enable: function enable() {
  23314. var that = this;
  23315. this.$el.find('*').mouseover(this.startDelete).mouseout(this.stopDelete).click(this.onDelete);
  23316. },
  23317. /**
  23318. * Start command
  23319. * @param {Object} e
  23320. * @private
  23321. */
  23322. startDelete: function startDelete(e) {
  23323. e.stopPropagation();
  23324. var $this = $(e.target); // Show badge if possible
  23325. if ($this.data('model').get('removable')) {
  23326. $this.addClass(this.hoverClass);
  23327. this.attachBadge($this.get(0));
  23328. }
  23329. },
  23330. /**
  23331. * Stop command
  23332. * @param {Object} e
  23333. * @private
  23334. */
  23335. stopDelete: function stopDelete(e) {
  23336. e.stopPropagation();
  23337. var $this = $(e.target);
  23338. $this.removeClass(this.hoverClass); // Hide badge if possible
  23339. if (this.badge) this.badge.css({
  23340. left: -1000,
  23341. top: -1000
  23342. });
  23343. },
  23344. /**
  23345. * Delete command
  23346. * @param {Object} e
  23347. * @private
  23348. */
  23349. onDelete: function onDelete(e) {
  23350. e.stopPropagation();
  23351. var $this = $(e.target); // Do nothing in case can't remove
  23352. if (!$this.data('model').get('removable')) return;
  23353. $this.data('model').destroy();
  23354. this.removeBadge();
  23355. this.clean();
  23356. },
  23357. /**
  23358. * Updates badge label
  23359. * @param {Object} model
  23360. * @private
  23361. * */
  23362. updateBadgeLabel: function updateBadgeLabel(model) {
  23363. this.badge.html('Remove ' + model.getName());
  23364. }
  23365. }));
  23366. /***/ }),
  23367. /***/ "./src/commands/view/ExportTemplate.js":
  23368. /*!*********************************************!*\
  23369. !*** ./src/commands/view/ExportTemplate.js ***!
  23370. \*********************************************/
  23371. /*! exports provided: default */
  23372. /***/ (function(module, __webpack_exports__, __webpack_require__) {
  23373. "use strict";
  23374. __webpack_require__.r(__webpack_exports__);
  23375. /* harmony import */ var backbone__WEBPACK_IMPORTED_MODULE_0__ = __webpack_require__(/*! backbone */ "./node_modules/backbone/backbone.js");
  23376. /* harmony import */ var backbone__WEBPACK_IMPORTED_MODULE_0___default = /*#__PURE__*/__webpack_require__.n(backbone__WEBPACK_IMPORTED_MODULE_0__);
  23377. var $ = backbone__WEBPACK_IMPORTED_MODULE_0___default.a.$;
  23378. /* harmony default export */ __webpack_exports__["default"] = ({
  23379. run: function run(editor, sender) {
  23380. var _this = this;
  23381. var opts = arguments.length > 2 && arguments[2] !== undefined ? arguments[2] : {};
  23382. sender && sender.set && sender.set('active', 0);
  23383. var config = editor.getConfig();
  23384. var modal = editor.Modal;
  23385. var pfx = config.stylePrefix;
  23386. this.cm = editor.CodeManager || null;
  23387. if (!this.$editors) {
  23388. var oHtmlEd = this.buildEditor('htmlmixed', 'hopscotch', 'HTML');
  23389. var oCsslEd = this.buildEditor('css', 'hopscotch', 'CSS');
  23390. this.htmlEditor = oHtmlEd.el;
  23391. this.cssEditor = oCsslEd.el;
  23392. var $editors = $("<div class=\"".concat(pfx, "export-dl\"></div>"));
  23393. $editors.append(oHtmlEd.$el).append(oCsslEd.$el);
  23394. this.$editors = $editors;
  23395. }
  23396. modal.open({
  23397. title: config.textViewCode,
  23398. content: this.$editors
  23399. }).getModel().once('change:open', function () {
  23400. return editor.stopCommand(_this.id);
  23401. });
  23402. this.htmlEditor.setContent(editor.getHtml());
  23403. this.cssEditor.setContent(editor.getCss());
  23404. },
  23405. stop: function stop(editor) {
  23406. var modal = editor.Modal;
  23407. modal && modal.close();
  23408. },
  23409. buildEditor: function buildEditor(codeName, theme, label) {
  23410. var input = document.createElement('textarea');
  23411. !this.codeMirror && (this.codeMirror = this.cm.getViewer('CodeMirror'));
  23412. var el = this.codeMirror.clone().set({
  23413. label: label,
  23414. codeName: codeName,
  23415. theme: theme,
  23416. input: input
  23417. });
  23418. var $el = new this.cm.EditorView({
  23419. model: el,
  23420. config: this.cm.getConfig()
  23421. }).render().$el;
  23422. el.init(input);
  23423. return {
  23424. el: el,
  23425. $el: $el
  23426. };
  23427. }
  23428. });
  23429. /***/ }),
  23430. /***/ "./src/commands/view/Fullscreen.js":
  23431. /*!*****************************************!*\
  23432. !*** ./src/commands/view/Fullscreen.js ***!
  23433. \*****************************************/
  23434. /*! exports provided: default */
  23435. /***/ (function(module, __webpack_exports__, __webpack_require__) {
  23436. "use strict";
  23437. __webpack_require__.r(__webpack_exports__);
  23438. /* harmony import */ var underscore__WEBPACK_IMPORTED_MODULE_0__ = __webpack_require__(/*! underscore */ "./node_modules/underscore/underscore.js");
  23439. /* harmony import */ var underscore__WEBPACK_IMPORTED_MODULE_0___default = /*#__PURE__*/__webpack_require__.n(underscore__WEBPACK_IMPORTED_MODULE_0__);
  23440. /* harmony default export */ __webpack_exports__["default"] = ({
  23441. /**
  23442. * Check if fullscreen mode is enabled
  23443. * @return {Boolean}
  23444. */
  23445. isEnabled: function isEnabled() {
  23446. var d = document;
  23447. if (d.fullscreenElement || d.webkitFullscreenElement || d.mozFullScreenElement) return 1;else return 0;
  23448. },
  23449. /**
  23450. * Enable fullscreen mode and return browser prefix
  23451. * @param {HTMLElement} el
  23452. * @return {string}
  23453. */
  23454. enable: function enable(el) {
  23455. var pfx = '';
  23456. if (el.requestFullscreen) el.requestFullscreen();else if (el.webkitRequestFullscreen) {
  23457. pfx = 'webkit';
  23458. el.webkitRequestFullscreen();
  23459. } else if (el.mozRequestFullScreen) {
  23460. pfx = 'moz';
  23461. el.mozRequestFullScreen();
  23462. } else if (el.msRequestFullscreen) el.msRequestFullscreen();else console.warn('Fullscreen not supported');
  23463. return pfx;
  23464. },
  23465. /**
  23466. * Disable fullscreen mode
  23467. */
  23468. disable: function disable() {
  23469. var d = document;
  23470. if (this.isEnabled()) {
  23471. if (d.exitFullscreen) d.exitFullscreen();else if (d.webkitExitFullscreen) d.webkitExitFullscreen();else if (d.mozCancelFullScreen) d.mozCancelFullScreen();else if (d.msExitFullscreen) d.msExitFullscreen();
  23472. }
  23473. },
  23474. /**
  23475. * Triggered when the state of the fullscreen is changed. Inside detects if
  23476. * it's enabled
  23477. * @param {strinf} pfx Browser prefix
  23478. * @param {Event} e
  23479. */
  23480. fsChanged: function fsChanged(pfx, e) {
  23481. var d = document;
  23482. var ev = (pfx || '') + 'fullscreenchange';
  23483. if (!this.isEnabled()) {
  23484. this.stop(null, this.sender);
  23485. document.removeEventListener(ev, this.fsChanged);
  23486. }
  23487. },
  23488. run: function run(editor, sender) {
  23489. var opts = arguments.length > 2 && arguments[2] !== undefined ? arguments[2] : {};
  23490. this.sender = sender;
  23491. var target = opts.target;
  23492. var targetEl = Object(underscore__WEBPACK_IMPORTED_MODULE_0__["isElement"])(target) ? target : document.querySelector(target);
  23493. var pfx = this.enable(targetEl || editor.getContainer());
  23494. this.fsChanged = this.fsChanged.bind(this, pfx);
  23495. document.addEventListener(pfx + 'fullscreenchange', this.fsChanged);
  23496. editor.trigger('change:canvasOffset');
  23497. },
  23498. stop: function stop(editor, sender) {
  23499. if (sender && sender.set) sender.set('active', false);
  23500. this.disable();
  23501. if (editor) editor.trigger('change:canvasOffset');
  23502. }
  23503. });
  23504. /***/ }),
  23505. /***/ "./src/commands/view/MoveComponent.js":
  23506. /*!********************************************!*\
  23507. !*** ./src/commands/view/MoveComponent.js ***!
  23508. \********************************************/
  23509. /*! exports provided: default */
  23510. /***/ (function(module, __webpack_exports__, __webpack_require__) {
  23511. "use strict";
  23512. __webpack_require__.r(__webpack_exports__);
  23513. /* harmony import */ var underscore__WEBPACK_IMPORTED_MODULE_0__ = __webpack_require__(/*! underscore */ "./node_modules/underscore/underscore.js");
  23514. /* harmony import */ var underscore__WEBPACK_IMPORTED_MODULE_0___default = /*#__PURE__*/__webpack_require__.n(underscore__WEBPACK_IMPORTED_MODULE_0__);
  23515. /* harmony import */ var backbone__WEBPACK_IMPORTED_MODULE_1__ = __webpack_require__(/*! backbone */ "./node_modules/backbone/backbone.js");
  23516. /* harmony import */ var backbone__WEBPACK_IMPORTED_MODULE_1___default = /*#__PURE__*/__webpack_require__.n(backbone__WEBPACK_IMPORTED_MODULE_1__);
  23517. /* harmony import */ var utils_mixins__WEBPACK_IMPORTED_MODULE_2__ = __webpack_require__(/*! utils/mixins */ "./src/utils/mixins.js");
  23518. /* harmony import */ var _SelectComponent__WEBPACK_IMPORTED_MODULE_3__ = __webpack_require__(/*! ./SelectComponent */ "./src/commands/view/SelectComponent.js");
  23519. /* harmony import */ var _SelectPosition__WEBPACK_IMPORTED_MODULE_4__ = __webpack_require__(/*! ./SelectPosition */ "./src/commands/view/SelectPosition.js");
  23520. var $ = backbone__WEBPACK_IMPORTED_MODULE_1___default.a.$;
  23521. /* harmony default export */ __webpack_exports__["default"] = (Object(underscore__WEBPACK_IMPORTED_MODULE_0__["extend"])({}, _SelectPosition__WEBPACK_IMPORTED_MODULE_4__["default"], _SelectComponent__WEBPACK_IMPORTED_MODULE_3__["default"], {
  23522. init: function init(o) {
  23523. _SelectComponent__WEBPACK_IMPORTED_MODULE_3__["default"].init.apply(this, arguments);
  23524. Object(underscore__WEBPACK_IMPORTED_MODULE_0__["bindAll"])(this, 'initSorter', 'rollback', 'onEndMove');
  23525. this.opt = o;
  23526. this.hoverClass = this.ppfx + 'highlighter-warning';
  23527. this.badgeClass = this.ppfx + 'badge-warning';
  23528. this.noSelClass = this.ppfx + 'no-select';
  23529. },
  23530. enable: function enable() {
  23531. for (var _len = arguments.length, args = new Array(_len), _key = 0; _key < _len; _key++) {
  23532. args[_key] = arguments[_key];
  23533. }
  23534. _SelectComponent__WEBPACK_IMPORTED_MODULE_3__["default"].enable.apply(this, args);
  23535. this.getBadgeEl().addClass(this.badgeClass);
  23536. this.getHighlighterEl().addClass(this.hoverClass);
  23537. var wp = this.$wrapper;
  23538. wp.css('cursor', 'move');
  23539. wp.on('mousedown', this.initSorter); // Avoid strange moving behavior
  23540. wp.addClass(this.noSelClass);
  23541. },
  23542. /**
  23543. * Overwrite for doing nothing
  23544. * @private
  23545. */
  23546. toggleClipboard: function toggleClipboard() {},
  23547. /**
  23548. * Delegate sorting
  23549. * @param {Event} e
  23550. * @private
  23551. * */
  23552. initSorter: function initSorter(e) {
  23553. var el = $(e.target).data('model');
  23554. var drag = el.get('draggable');
  23555. if (!drag) return; // Avoid badge showing on move
  23556. this.cacheEl = null;
  23557. this.startSelectPosition(e.target, this.frameEl.contentDocument);
  23558. this.sorter.draggable = drag;
  23559. this.sorter.onEndMove = this.onEndMove.bind(this);
  23560. this.stopSelectComponent();
  23561. this.$wrapper.off('mousedown', this.initSorter);
  23562. Object(utils_mixins__WEBPACK_IMPORTED_MODULE_2__["on"])(this.getContentWindow(), 'keydown', this.rollback);
  23563. },
  23564. /**
  23565. * Init sorter from model
  23566. * @param {Object} model
  23567. * @private
  23568. */
  23569. initSorterFromModel: function initSorterFromModel(model) {
  23570. var drag = model.get('draggable');
  23571. if (!drag) return; // Avoid badge showing on move
  23572. this.cacheEl = null;
  23573. var el = model.view.el;
  23574. this.startSelectPosition(el, this.frameEl.contentDocument);
  23575. this.sorter.draggable = drag;
  23576. this.sorter.onEndMove = this.onEndMoveFromModel.bind(this);
  23577. /*
  23578. this.sorter.setDragHelper(el);
  23579. var dragHelper = this.sorter.dragHelper;
  23580. dragHelper.className = this.ppfx + 'drag-helper';
  23581. dragHelper.innerHTML = '';
  23582. dragHelper.backgroundColor = 'white';
  23583. */
  23584. this.stopSelectComponent();
  23585. Object(utils_mixins__WEBPACK_IMPORTED_MODULE_2__["on"])(this.getContentWindow(), 'keydown', this.rollback);
  23586. },
  23587. /**
  23588. * Init sorter from models
  23589. * @param {Object} model
  23590. * @private
  23591. */
  23592. initSorterFromModels: function initSorterFromModels(models) {
  23593. // TODO: if one only check for `draggable`
  23594. // Avoid badge showing on move
  23595. this.cacheEl = null;
  23596. var lastModel = models[models.length - 1];
  23597. var frame = (this.em.get('currentFrame') || {}).model;
  23598. var el = lastModel.getEl(frame);
  23599. var doc = el.ownerDocument;
  23600. this.startSelectPosition(el, doc, {
  23601. onStart: this.onStart
  23602. });
  23603. this.sorter.draggable = lastModel.get('draggable');
  23604. this.sorter.toMove = models;
  23605. this.sorter.onMoveClb = this.onDrag;
  23606. this.sorter.onEndMove = this.onEndMoveFromModel.bind(this);
  23607. this.stopSelectComponent();
  23608. Object(utils_mixins__WEBPACK_IMPORTED_MODULE_2__["on"])(this.getContentWindow(), 'keydown', this.rollback);
  23609. },
  23610. onEndMoveFromModel: function onEndMoveFromModel() {
  23611. Object(utils_mixins__WEBPACK_IMPORTED_MODULE_2__["off"])(this.getContentWindow(), 'keydown', this.rollback);
  23612. },
  23613. /**
  23614. * Callback after sorting
  23615. * @private
  23616. */
  23617. onEndMove: function onEndMove() {
  23618. this.enable();
  23619. Object(utils_mixins__WEBPACK_IMPORTED_MODULE_2__["off"])(this.getContentWindow(), 'keydown', this.rollback);
  23620. },
  23621. /**
  23622. * Say what to do after the component was selected (selectComponent)
  23623. * @param {Event} e
  23624. * @param {Object} Selected element
  23625. * @private
  23626. * */
  23627. onSelect: function onSelect(e, el) {},
  23628. /**
  23629. * Used to bring the previous situation before start moving the component
  23630. * @param {Event} e
  23631. * @param {Boolean} Indicates if rollback in anycase
  23632. * @private
  23633. * */
  23634. rollback: function rollback(e, force) {
  23635. var key = e.which || e.keyCode;
  23636. if (key == 27 || force) {
  23637. this.sorter.moved = false;
  23638. this.sorter.endMove();
  23639. }
  23640. return;
  23641. },
  23642. /**
  23643. * Returns badge element
  23644. * @return {HTMLElement}
  23645. * @private
  23646. */
  23647. getBadgeEl: function getBadgeEl() {
  23648. if (!this.$badge) this.$badge = $(this.getBadge());
  23649. return this.$badge;
  23650. },
  23651. /**
  23652. * Returns highlighter element
  23653. * @return {HTMLElement}
  23654. * @private
  23655. */
  23656. getHighlighterEl: function getHighlighterEl() {
  23657. if (!this.$hl) this.$hl = $(this.canvas.getHighlighter());
  23658. return this.$hl;
  23659. },
  23660. stop: function stop() {
  23661. for (var _len2 = arguments.length, args = new Array(_len2), _key2 = 0; _key2 < _len2; _key2++) {
  23662. args[_key2] = arguments[_key2];
  23663. }
  23664. _SelectComponent__WEBPACK_IMPORTED_MODULE_3__["default"].stop.apply(this, args);
  23665. this.getBadgeEl().removeClass(this.badgeClass);
  23666. this.getHighlighterEl().removeClass(this.hoverClass);
  23667. var wp = this.$wrapper;
  23668. wp.css('cursor', '').unbind().removeClass(this.noSelClass);
  23669. }
  23670. }));
  23671. /***/ }),
  23672. /***/ "./src/commands/view/OpenAssets.js":
  23673. /*!*****************************************!*\
  23674. !*** ./src/commands/view/OpenAssets.js ***!
  23675. \*****************************************/
  23676. /*! exports provided: default */
  23677. /***/ (function(module, __webpack_exports__, __webpack_require__) {
  23678. "use strict";
  23679. __webpack_require__.r(__webpack_exports__);
  23680. /* harmony default export */ __webpack_exports__["default"] = ({
  23681. run: function run(editor, sender) {
  23682. var _this = this;
  23683. var opts = arguments.length > 2 && arguments[2] !== undefined ? arguments[2] : {};
  23684. var modal = editor.Modal;
  23685. var am = editor.AssetManager;
  23686. var config = am.getConfig();
  23687. var amContainer = am.getContainer();
  23688. var title = opts.modalTitle || editor.t('assetManager.modalTitle') || '';
  23689. var types = opts.types;
  23690. var accept = opts.accept;
  23691. am.setTarget(opts.target);
  23692. am.onClick(opts.onClick);
  23693. am.onDblClick(opts.onDblClick);
  23694. am.onSelect(opts.onSelect);
  23695. if (!this.rendered || types) {
  23696. var assets = am.getAll().filter(function (i) {
  23697. return 1;
  23698. });
  23699. if (types && types.length) {
  23700. assets = assets.filter(function (a) {
  23701. return types.indexOf(a.get('type')) !== -1;
  23702. });
  23703. }
  23704. am.render(assets);
  23705. this.rendered = 1;
  23706. }
  23707. if (accept) {
  23708. var uploadEl = amContainer.querySelector("input#".concat(config.stylePrefix, "uploadFile"));
  23709. uploadEl && uploadEl.setAttribute('accept', accept);
  23710. }
  23711. modal.open({
  23712. title: title,
  23713. content: amContainer
  23714. }).getModel().once('change:open', function () {
  23715. return editor.stopCommand(_this.id);
  23716. });
  23717. return this;
  23718. },
  23719. stop: function stop(editor) {
  23720. editor.Modal.close();
  23721. return this;
  23722. }
  23723. });
  23724. /***/ }),
  23725. /***/ "./src/commands/view/OpenBlocks.js":
  23726. /*!*****************************************!*\
  23727. !*** ./src/commands/view/OpenBlocks.js ***!
  23728. \*****************************************/
  23729. /*! exports provided: default */
  23730. /***/ (function(module, __webpack_exports__, __webpack_require__) {
  23731. "use strict";
  23732. __webpack_require__.r(__webpack_exports__);
  23733. /* harmony default export */ __webpack_exports__["default"] = ({
  23734. run: function run(editor, sender) {
  23735. var bm = editor.BlockManager;
  23736. var pn = editor.Panels;
  23737. if (!this.blocks) {
  23738. bm.render();
  23739. var id = 'views-container';
  23740. var blocks = document.createElement('div');
  23741. var panels = pn.getPanel(id) || pn.addPanel({
  23742. id: id
  23743. });
  23744. blocks.appendChild(bm.getContainer());
  23745. panels.set('appendContent', blocks).trigger('change:appendContent');
  23746. this.blocks = blocks;
  23747. }
  23748. this.blocks.style.display = 'block';
  23749. },
  23750. stop: function stop() {
  23751. var blocks = this.blocks;
  23752. blocks && (blocks.style.display = 'none');
  23753. }
  23754. });
  23755. /***/ }),
  23756. /***/ "./src/commands/view/OpenLayers.js":
  23757. /*!*****************************************!*\
  23758. !*** ./src/commands/view/OpenLayers.js ***!
  23759. \*****************************************/
  23760. /*! exports provided: default */
  23761. /***/ (function(module, __webpack_exports__, __webpack_require__) {
  23762. "use strict";
  23763. __webpack_require__.r(__webpack_exports__);
  23764. /* harmony import */ var backbone__WEBPACK_IMPORTED_MODULE_0__ = __webpack_require__(/*! backbone */ "./node_modules/backbone/backbone.js");
  23765. /* harmony import */ var backbone__WEBPACK_IMPORTED_MODULE_0___default = /*#__PURE__*/__webpack_require__.n(backbone__WEBPACK_IMPORTED_MODULE_0__);
  23766. /* harmony import */ var navigator__WEBPACK_IMPORTED_MODULE_1__ = __webpack_require__(/*! navigator */ "./src/navigator/index.js");
  23767. var $ = backbone__WEBPACK_IMPORTED_MODULE_0___default.a.$;
  23768. /* harmony default export */ __webpack_exports__["default"] = ({
  23769. run: function run(editor) {
  23770. var lm = editor.LayerManager;
  23771. var pn = editor.Panels;
  23772. if (!this.layers) {
  23773. var id = 'views-container';
  23774. var layers = document.createElement('div');
  23775. var panels = pn.getPanel(id) || pn.addPanel({
  23776. id: id
  23777. });
  23778. layers.appendChild(lm.render());
  23779. panels.set('appendContent', layers).trigger('change:appendContent');
  23780. this.layers = layers;
  23781. }
  23782. this.layers.style.display = 'block';
  23783. },
  23784. stop: function stop() {
  23785. var layers = this.layers;
  23786. layers && (layers.style.display = 'none');
  23787. }
  23788. });
  23789. /***/ }),
  23790. /***/ "./src/commands/view/OpenStyleManager.js":
  23791. /*!***********************************************!*\
  23792. !*** ./src/commands/view/OpenStyleManager.js ***!
  23793. \***********************************************/
  23794. /*! exports provided: default */
  23795. /***/ (function(module, __webpack_exports__, __webpack_require__) {
  23796. "use strict";
  23797. __webpack_require__.r(__webpack_exports__);
  23798. /* harmony import */ var backbone__WEBPACK_IMPORTED_MODULE_0__ = __webpack_require__(/*! backbone */ "./node_modules/backbone/backbone.js");
  23799. /* harmony import */ var backbone__WEBPACK_IMPORTED_MODULE_0___default = /*#__PURE__*/__webpack_require__.n(backbone__WEBPACK_IMPORTED_MODULE_0__);
  23800. var $ = backbone__WEBPACK_IMPORTED_MODULE_0___default.a.$;
  23801. /* harmony default export */ __webpack_exports__["default"] = ({
  23802. run: function run(em, sender) {
  23803. this.sender = sender;
  23804. if (!this.$cn) {
  23805. var config = em.getConfig(),
  23806. panels = em.Panels; // Main container
  23807. this.$cn = $('<div></div>'); // Secondary container
  23808. this.$cn2 = $('<div></div>');
  23809. this.$cn.append(this.$cn2); // Device Manager
  23810. var dvm = em.DeviceManager;
  23811. if (dvm && config.showDevices) {
  23812. var devicePanel = panels.addPanel({
  23813. id: 'devices-c'
  23814. });
  23815. devicePanel.set('appendContent', dvm.render()).trigger('change:appendContent');
  23816. } // Class Manager container
  23817. var clm = em.SelectorManager;
  23818. if (clm) this.$cn2.append(clm.render([]));
  23819. this.$cn2.append(em.StyleManager.render());
  23820. var smConfig = em.StyleManager.getConfig();
  23821. var pfx = smConfig.stylePrefix; // Create header
  23822. this.$header = $("<div class=\"".concat(pfx, "header\">").concat(em.t('styleManager.empty'), "</div>"));
  23823. this.$cn.append(this.$header); // Create panel if not exists
  23824. if (!panels.getPanel('views-container')) this.panel = panels.addPanel({
  23825. id: 'views-container'
  23826. });else this.panel = panels.getPanel('views-container'); // Add all containers to the panel
  23827. this.panel.set('appendContent', this.$cn).trigger('change:appendContent');
  23828. this.target = em.editor;
  23829. this.listenTo(this.target, 'component:toggled', this.toggleSm);
  23830. }
  23831. this.toggleSm();
  23832. },
  23833. /**
  23834. * Toggle Style Manager visibility
  23835. * @private
  23836. */
  23837. toggleSm: function toggleSm() {
  23838. var target = this.target,
  23839. sender = this.sender;
  23840. if (sender && sender.get && !sender.get('active')) return;
  23841. var _target$get$getConfig = target.get('SelectorManager').getConfig(),
  23842. componentFirst = _target$get$getConfig.componentFirst;
  23843. var selectedAll = target.getSelectedAll().length;
  23844. if (selectedAll === 1 || selectedAll > 1 && componentFirst) {
  23845. this.$cn2.show();
  23846. this.$header.hide();
  23847. } else {
  23848. this.$cn2.hide();
  23849. this.$header.show();
  23850. }
  23851. },
  23852. stop: function stop() {
  23853. // Hide secondary container if exists
  23854. if (this.$cn2) this.$cn2.hide(); // Hide header container if exists
  23855. if (this.$header) this.$header.hide();
  23856. }
  23857. });
  23858. /***/ }),
  23859. /***/ "./src/commands/view/OpenTraitManager.js":
  23860. /*!***********************************************!*\
  23861. !*** ./src/commands/view/OpenTraitManager.js ***!
  23862. \***********************************************/
  23863. /*! exports provided: default */
  23864. /***/ (function(module, __webpack_exports__, __webpack_require__) {
  23865. "use strict";
  23866. __webpack_require__.r(__webpack_exports__);
  23867. /* harmony import */ var backbone__WEBPACK_IMPORTED_MODULE_0__ = __webpack_require__(/*! backbone */ "./node_modules/backbone/backbone.js");
  23868. /* harmony import */ var backbone__WEBPACK_IMPORTED_MODULE_0___default = /*#__PURE__*/__webpack_require__.n(backbone__WEBPACK_IMPORTED_MODULE_0__);
  23869. var $ = backbone__WEBPACK_IMPORTED_MODULE_0___default.a.$;
  23870. /* harmony default export */ __webpack_exports__["default"] = ({
  23871. run: function run(editor, sender) {
  23872. this.sender = sender;
  23873. var em = editor.getModel();
  23874. var config = editor.Config;
  23875. var pfx = config.stylePrefix;
  23876. var tm = editor.TraitManager;
  23877. var panelC;
  23878. if (!this.$cn) {
  23879. var tmView = tm.getTraitsViewer();
  23880. var confTm = tm.getConfig();
  23881. this.$cn = $('<div></div>');
  23882. this.$cn2 = $('<div></div>');
  23883. this.$cn.append(this.$cn2);
  23884. this.$header = $('<div>').append("<div class=\"".concat(confTm.stylePrefix, "header\">").concat(em.t('traitManager.empty'), "</div>"));
  23885. this.$cn.append(this.$header);
  23886. this.$cn2.append("<div class=\"".concat(pfx, "traits-label\">").concat(em.t('traitManager.label'), "</div>"));
  23887. this.$cn2.append(tmView.render().el);
  23888. var panels = editor.Panels;
  23889. if (!panels.getPanel('views-container')) panelC = panels.addPanel({
  23890. id: 'views-container'
  23891. });else panelC = panels.getPanel('views-container');
  23892. panelC.set('appendContent', this.$cn.get(0)).trigger('change:appendContent');
  23893. this.target = editor.getModel();
  23894. this.listenTo(this.target, 'component:toggled', this.toggleTm);
  23895. }
  23896. this.toggleTm();
  23897. },
  23898. /**
  23899. * Toggle Trait Manager visibility
  23900. * @private
  23901. */
  23902. toggleTm: function toggleTm() {
  23903. var sender = this.sender;
  23904. if (sender && sender.get && !sender.get('active')) return;
  23905. if (this.target.getSelectedAll().length === 1) {
  23906. this.$cn2.show();
  23907. this.$header.hide();
  23908. } else {
  23909. this.$cn2.hide();
  23910. this.$header.show();
  23911. }
  23912. },
  23913. stop: function stop() {
  23914. this.$cn2 && this.$cn2.hide();
  23915. this.$header && this.$header.hide();
  23916. }
  23917. });
  23918. /***/ }),
  23919. /***/ "./src/commands/view/PasteComponent.js":
  23920. /*!*********************************************!*\
  23921. !*** ./src/commands/view/PasteComponent.js ***!
  23922. \*********************************************/
  23923. /*! exports provided: default */
  23924. /***/ (function(module, __webpack_exports__, __webpack_require__) {
  23925. "use strict";
  23926. __webpack_require__.r(__webpack_exports__);
  23927. /* harmony import */ var underscore__WEBPACK_IMPORTED_MODULE_0__ = __webpack_require__(/*! underscore */ "./node_modules/underscore/underscore.js");
  23928. /* harmony import */ var underscore__WEBPACK_IMPORTED_MODULE_0___default = /*#__PURE__*/__webpack_require__.n(underscore__WEBPACK_IMPORTED_MODULE_0__);
  23929. /* harmony default export */ __webpack_exports__["default"] = ({
  23930. run: function run(ed) {
  23931. var em = ed.getModel();
  23932. var clp = em.get('clipboard');
  23933. var selected = ed.getSelected();
  23934. if (clp && selected) {
  23935. ed.getSelectedAll().forEach(function (comp) {
  23936. if (!comp) return;
  23937. var coll = comp.collection;
  23938. var at = coll.indexOf(comp) + 1;
  23939. var copyable = clp.filter(function (cop) {
  23940. return cop.get('copyable');
  23941. });
  23942. var added;
  23943. if (Object(underscore__WEBPACK_IMPORTED_MODULE_0__["contains"])(clp, comp) && comp.get('copyable')) {
  23944. added = coll.add(comp.clone(), {
  23945. at: at
  23946. });
  23947. } else {
  23948. added = coll.add(copyable.map(function (cop) {
  23949. return cop.clone();
  23950. }), {
  23951. at: at
  23952. });
  23953. }
  23954. added = Object(underscore__WEBPACK_IMPORTED_MODULE_0__["isArray"])(added) ? added : [added];
  23955. added.forEach(function (add) {
  23956. return ed.trigger('component:paste', add);
  23957. });
  23958. });
  23959. selected.emitUpdate();
  23960. }
  23961. }
  23962. });
  23963. /***/ }),
  23964. /***/ "./src/commands/view/Preview.js":
  23965. /*!**************************************!*\
  23966. !*** ./src/commands/view/Preview.js ***!
  23967. \**************************************/
  23968. /*! exports provided: default */
  23969. /***/ (function(module, __webpack_exports__, __webpack_require__) {
  23970. "use strict";
  23971. __webpack_require__.r(__webpack_exports__);
  23972. /* harmony import */ var underscore__WEBPACK_IMPORTED_MODULE_0__ = __webpack_require__(/*! underscore */ "./node_modules/underscore/underscore.js");
  23973. /* harmony import */ var underscore__WEBPACK_IMPORTED_MODULE_0___default = /*#__PURE__*/__webpack_require__.n(underscore__WEBPACK_IMPORTED_MODULE_0__);
  23974. var cmdVis = 'sw-visibility';
  23975. /* harmony default export */ __webpack_exports__["default"] = ({
  23976. getPanels: function getPanels(editor) {
  23977. if (!this.panels) {
  23978. this.panels = editor.Panels.getPanels();
  23979. }
  23980. return this.panels;
  23981. },
  23982. tglPointers: function tglPointers(editor, val) {
  23983. var body = editor.Canvas.getBody();
  23984. var elP = body.querySelectorAll(".".concat(this.ppfx, "no-pointer"));
  23985. Object(underscore__WEBPACK_IMPORTED_MODULE_0__["each"])(elP, function (item) {
  23986. return item.style.pointerEvents = val ? '' : 'all';
  23987. });
  23988. },
  23989. run: function run(editor, sender) {
  23990. var _this = this;
  23991. this.sender = sender;
  23992. if (!this.shouldRunSwVisibility) {
  23993. this.shouldRunSwVisibility = editor.Commands.isActive(cmdVis);
  23994. }
  23995. this.shouldRunSwVisibility && editor.stopCommand(cmdVis);
  23996. editor.getModel().stopDefault();
  23997. var panels = this.getPanels(editor);
  23998. var canvas = editor.Canvas.getElement();
  23999. var editorEl = editor.getEl();
  24000. var pfx = editor.Config.stylePrefix;
  24001. if (!this.helper) {
  24002. var helper = document.createElement('span');
  24003. helper.className = "".concat(pfx, "off-prv fa fa-eye-slash");
  24004. editorEl.appendChild(helper);
  24005. helper.onclick = function () {
  24006. return _this.stopCommand();
  24007. };
  24008. this.helper = helper;
  24009. }
  24010. this.helper.style.display = 'inline-block';
  24011. this.tglPointers(editor);
  24012. panels.forEach(function (panel) {
  24013. return panel.set('visible', false);
  24014. });
  24015. var canvasS = canvas.style;
  24016. canvasS.width = '100%';
  24017. canvasS.height = '100%';
  24018. canvasS.top = '0';
  24019. canvasS.left = '0';
  24020. canvasS.padding = '0';
  24021. canvasS.margin = '0';
  24022. editor.refresh();
  24023. },
  24024. stop: function stop(editor) {
  24025. var _this$sender = this.sender,
  24026. sender = _this$sender === void 0 ? {} : _this$sender;
  24027. sender.set && sender.set('active', 0);
  24028. var panels = this.getPanels(editor);
  24029. if (this.shouldRunSwVisibility) {
  24030. editor.runCommand(cmdVis);
  24031. this.shouldRunSwVisibility = false;
  24032. }
  24033. editor.getModel().runDefault();
  24034. panels.forEach(function (panel) {
  24035. return panel.set('visible', true);
  24036. });
  24037. var canvas = editor.Canvas.getElement();
  24038. canvas.setAttribute('style', '');
  24039. if (this.helper) {
  24040. this.helper.style.display = 'none';
  24041. }
  24042. editor.refresh();
  24043. this.tglPointers(editor, 1);
  24044. }
  24045. });
  24046. /***/ }),
  24047. /***/ "./src/commands/view/Resize.js":
  24048. /*!*************************************!*\
  24049. !*** ./src/commands/view/Resize.js ***!
  24050. \*************************************/
  24051. /*! exports provided: default */
  24052. /***/ (function(module, __webpack_exports__, __webpack_require__) {
  24053. "use strict";
  24054. __webpack_require__.r(__webpack_exports__);
  24055. /* harmony default export */ __webpack_exports__["default"] = ({
  24056. run: function run(editor, sender, opts) {
  24057. var opt = opts || {};
  24058. var el = opt.el || '';
  24059. var canvas = editor.Canvas;
  24060. var canvasResizer = this.canvasResizer;
  24061. var options = opt.options || {};
  24062. var canvasView = canvas.getCanvasView();
  24063. options.appendTo = canvas.getResizerEl();
  24064. options.prefix = editor.getConfig().stylePrefix;
  24065. options.posFetcher = canvasView.getElementPos.bind(canvasView);
  24066. options.mousePosFetcher = canvas.getMouseRelativePos; // Create the resizer for the canvas if not yet created
  24067. if (!canvasResizer || opt.forceNew) {
  24068. this.canvasResizer = editor.Utils.Resizer.init(options);
  24069. canvasResizer = this.canvasResizer;
  24070. }
  24071. canvasResizer.setOptions(options);
  24072. canvasResizer.blur();
  24073. canvasResizer.focus(el);
  24074. return canvasResizer;
  24075. },
  24076. stop: function stop() {
  24077. var resizer = this.canvasResizer;
  24078. resizer && resizer.blur();
  24079. }
  24080. });
  24081. /***/ }),
  24082. /***/ "./src/commands/view/SelectComponent.js":
  24083. /*!**********************************************!*\
  24084. !*** ./src/commands/view/SelectComponent.js ***!
  24085. \**********************************************/
  24086. /*! exports provided: default */
  24087. /***/ (function(module, __webpack_exports__, __webpack_require__) {
  24088. "use strict";
  24089. __webpack_require__.r(__webpack_exports__);
  24090. /* harmony import */ var _babel_runtime_helpers_typeof__WEBPACK_IMPORTED_MODULE_0__ = __webpack_require__(/*! @babel/runtime/helpers/typeof */ "./node_modules/@babel/runtime/helpers/typeof.js");
  24091. /* harmony import */ var _babel_runtime_helpers_typeof__WEBPACK_IMPORTED_MODULE_0___default = /*#__PURE__*/__webpack_require__.n(_babel_runtime_helpers_typeof__WEBPACK_IMPORTED_MODULE_0__);
  24092. /* harmony import */ var _babel_runtime_helpers_defineProperty__WEBPACK_IMPORTED_MODULE_1__ = __webpack_require__(/*! @babel/runtime/helpers/defineProperty */ "./node_modules/@babel/runtime/helpers/defineProperty.js");
  24093. /* harmony import */ var _babel_runtime_helpers_defineProperty__WEBPACK_IMPORTED_MODULE_1___default = /*#__PURE__*/__webpack_require__.n(_babel_runtime_helpers_defineProperty__WEBPACK_IMPORTED_MODULE_1__);
  24094. /* harmony import */ var backbone__WEBPACK_IMPORTED_MODULE_2__ = __webpack_require__(/*! backbone */ "./node_modules/backbone/backbone.js");
  24095. /* harmony import */ var backbone__WEBPACK_IMPORTED_MODULE_2___default = /*#__PURE__*/__webpack_require__.n(backbone__WEBPACK_IMPORTED_MODULE_2__);
  24096. /* harmony import */ var underscore__WEBPACK_IMPORTED_MODULE_3__ = __webpack_require__(/*! underscore */ "./node_modules/underscore/underscore.js");
  24097. /* harmony import */ var underscore__WEBPACK_IMPORTED_MODULE_3___default = /*#__PURE__*/__webpack_require__.n(underscore__WEBPACK_IMPORTED_MODULE_3__);
  24098. /* harmony import */ var utils_mixins__WEBPACK_IMPORTED_MODULE_4__ = __webpack_require__(/*! utils/mixins */ "./src/utils/mixins.js");
  24099. /* harmony import */ var dom_components_view_ToolbarView__WEBPACK_IMPORTED_MODULE_5__ = __webpack_require__(/*! dom_components/view/ToolbarView */ "./src/dom_components/view/ToolbarView.js");
  24100. /* harmony import */ var dom_components_model_Toolbar__WEBPACK_IMPORTED_MODULE_6__ = __webpack_require__(/*! dom_components/model/Toolbar */ "./src/dom_components/model/Toolbar.js");
  24101. function ownKeys(object, enumerableOnly) { var keys = Object.keys(object); if (Object.getOwnPropertySymbols) { var symbols = Object.getOwnPropertySymbols(object); if (enumerableOnly) symbols = symbols.filter(function (sym) { return Object.getOwnPropertyDescriptor(object, sym).enumerable; }); keys.push.apply(keys, symbols); } return keys; }
  24102. function _objectSpread(target) { for (var i = 1; i < arguments.length; i++) { var source = arguments[i] != null ? arguments[i] : {}; if (i % 2) { ownKeys(source, true).forEach(function (key) { _babel_runtime_helpers_defineProperty__WEBPACK_IMPORTED_MODULE_1___default()(target, key, source[key]); }); } else if (Object.getOwnPropertyDescriptors) { Object.defineProperties(target, Object.getOwnPropertyDescriptors(source)); } else { ownKeys(source).forEach(function (key) { Object.defineProperty(target, key, Object.getOwnPropertyDescriptor(source, key)); }); } } return target; }
  24103. var $ = backbone__WEBPACK_IMPORTED_MODULE_2___default.a.$;
  24104. var showOffsets;
  24105. /**
  24106. * This command is responsible for show selecting components and displaying
  24107. * all the necessary tools around (component toolbar, badge, highlight box, etc.)
  24108. *
  24109. * The command manages different boxes to display tools and when something in
  24110. * the canvas is updated, the command triggers the appropriate method to update
  24111. * their position (across multiple frames/components):
  24112. * - Global Tools (updateToolsGlobal/updateGlobalPos)
  24113. * This box contains tools intended to be displayed only on ONE component per time,
  24114. * like Component Toolbar (updated by updateToolbar/updateToolbarPos), this means
  24115. * you won't be able to see more than one Component Toolbar (even with multiple
  24116. * frames or multiple selected components)
  24117. * - Local Tools (updateToolsLocal/updateLocalPos)
  24118. * Each frame in the canvas has its own local box, so we're able to see more than
  24119. * one active container at the same time. When you put a mouse over an element
  24120. * you can see stuff like the highlight box, badge, margins/paddings offsets, etc.
  24121. * so those elements are inside the Local Tools box
  24122. *
  24123. *
  24124. */
  24125. /* harmony default export */ __webpack_exports__["default"] = ({
  24126. init: function init(o) {
  24127. Object(underscore__WEBPACK_IMPORTED_MODULE_3__["bindAll"])(this, 'onHover', 'onOut', 'onClick', 'onFrameScroll', 'onFrameUpdated');
  24128. },
  24129. enable: function enable() {
  24130. this.frameOff = this.canvasOff = this.adjScroll = null;
  24131. this.startSelectComponent();
  24132. showOffsets = 1;
  24133. },
  24134. /**
  24135. * Start select component event
  24136. * @private
  24137. * */
  24138. startSelectComponent: function startSelectComponent() {
  24139. this.toggleSelectComponent(1);
  24140. this.em.getSelected() && this.onSelect();
  24141. },
  24142. /**
  24143. * Stop select component event
  24144. * @private
  24145. * */
  24146. stopSelectComponent: function stopSelectComponent() {
  24147. this.toggleSelectComponent();
  24148. },
  24149. /**
  24150. * Toggle select component event
  24151. * @private
  24152. * */
  24153. toggleSelectComponent: function toggleSelectComponent(enable) {
  24154. var _this = this;
  24155. var em = this.em;
  24156. var method = enable ? 'on' : 'off';
  24157. var methods = {
  24158. on: utils_mixins__WEBPACK_IMPORTED_MODULE_4__["on"],
  24159. off: utils_mixins__WEBPACK_IMPORTED_MODULE_4__["off"]
  24160. };
  24161. var trigger = function trigger(win, body) {
  24162. methods[method](body, 'mouseover', _this.onHover);
  24163. methods[method](body, 'mouseleave', _this.onOut);
  24164. methods[method](body, 'click touchend', _this.onClick);
  24165. methods[method](win, 'scroll', _this.onFrameScroll);
  24166. };
  24167. methods[method](window, 'resize', this.onFrameUpdated);
  24168. em[method]('component:toggled', this.onSelect, this);
  24169. em[method]('change:componentHovered', this.onHovered, this);
  24170. em[method]('component:resize component:styleUpdate component:input', this.updateGlobalPos, this);
  24171. em[method]('change:canvasOffset', this.updateAttached, this);
  24172. em[method]('frame:updated', this.onFrameUpdated, this);
  24173. em.get('Canvas').getFrames().forEach(function (frame) {
  24174. var view = frame.view;
  24175. view && trigger(view.getWindow(), view.getBody());
  24176. });
  24177. },
  24178. /**
  24179. * Hover command
  24180. * @param {Object} e
  24181. * @private
  24182. */
  24183. onHover: function onHover(e) {
  24184. e.stopPropagation();
  24185. var trg = e.target;
  24186. var view = Object(utils_mixins__WEBPACK_IMPORTED_MODULE_4__["getViewEl"])(trg);
  24187. var frameView = view && view._getFrame();
  24188. var $el = $(trg);
  24189. var model = $el.data('model'); // Get first valid model
  24190. if (!model) {
  24191. var parent = $el.parent();
  24192. while (!model && parent.length > 0) {
  24193. model = parent.data('model');
  24194. parent = parent.parent();
  24195. }
  24196. } // Get first valid hoverable model
  24197. if (model && !model.get('hoverable')) {
  24198. var _parent = model && model.parent();
  24199. while (_parent && !_parent.get('hoverable')) {
  24200. _parent = _parent.parent();
  24201. }
  24202. model = _parent;
  24203. }
  24204. this.currentDoc = trg.ownerDocument;
  24205. this.em.setHovered(model);
  24206. frameView && this.em.set('currentFrame', frameView);
  24207. },
  24208. onFrameUpdated: function onFrameUpdated() {
  24209. this.updateLocalPos();
  24210. this.updateGlobalPos();
  24211. },
  24212. onHovered: function onHovered(em, component) {
  24213. var _this2 = this;
  24214. var result = {};
  24215. if (component) {
  24216. component.views.forEach(function (view) {
  24217. var el = view.el;
  24218. var pos = _this2.getElementPos(el);
  24219. result = {
  24220. el: el,
  24221. pos: pos,
  24222. component: component,
  24223. view: Object(utils_mixins__WEBPACK_IMPORTED_MODULE_4__["getViewEl"])(el)
  24224. };
  24225. _this2.updateToolsLocal(result);
  24226. if (el.ownerDocument === _this2.currentDoc) _this2.elHovered = result;
  24227. });
  24228. }
  24229. },
  24230. /**
  24231. * Say what to do after the component was selected
  24232. * @param {Object} e
  24233. * @param {Object} el
  24234. * @private
  24235. * */
  24236. onSelect: Object(underscore__WEBPACK_IMPORTED_MODULE_3__["debounce"])(function () {
  24237. var em = this.em;
  24238. var component = em.getSelected();
  24239. var currentFrame = em.get('currentFrame') || {};
  24240. var view = component && component.getView(currentFrame.model);
  24241. var el = view && view.el;
  24242. var result = {};
  24243. if (el) {
  24244. var pos = this.getElementPos(el);
  24245. result = {
  24246. el: el,
  24247. pos: pos,
  24248. component: component,
  24249. view: Object(utils_mixins__WEBPACK_IMPORTED_MODULE_4__["getViewEl"])(el)
  24250. };
  24251. }
  24252. this.elSelected = result;
  24253. this.updateToolsGlobal(); // This will hide some elements from the select component
  24254. this.updateToolsLocal(result);
  24255. }),
  24256. updateGlobalPos: function updateGlobalPos() {
  24257. var sel = this.getElSelected();
  24258. if (!sel.el) return;
  24259. sel.pos = this.getElementPos(sel.el);
  24260. this.updateToolsGlobal();
  24261. },
  24262. updateLocalPos: function updateLocalPos() {
  24263. var sel = this.getElHovered();
  24264. if (!sel.el) return;
  24265. sel.pos = this.getElementPos(sel.el);
  24266. this.updateToolsLocal();
  24267. },
  24268. getElHovered: function getElHovered() {
  24269. return this.elHovered || {};
  24270. },
  24271. getElSelected: function getElSelected() {
  24272. return this.elSelected || {};
  24273. },
  24274. onOut: function onOut() {
  24275. var _this3 = this;
  24276. this.currentDoc = null;
  24277. this.em.setHovered(0);
  24278. this.canvas.getFrames().forEach(function (frame) {
  24279. var view = frame.view;
  24280. var el = view && view.getToolsEl();
  24281. el && _this3.toggleToolsEl(0, 0, {
  24282. el: el
  24283. });
  24284. });
  24285. },
  24286. toggleToolsEl: function toggleToolsEl(on, view) {
  24287. var opts = arguments.length > 2 && arguments[2] !== undefined ? arguments[2] : {};
  24288. var el = opts.el || this.canvas.getToolsEl(view);
  24289. el && (el.style.opacity = on ? 1 : 0);
  24290. return el || {};
  24291. },
  24292. /**
  24293. * Show element offset viewer
  24294. * @param {HTMLElement} el
  24295. * @param {Object} pos
  24296. */
  24297. showElementOffset: function showElementOffset(el, pos) {
  24298. var opts = arguments.length > 2 && arguments[2] !== undefined ? arguments[2] : {};
  24299. if (!showOffsets) return;
  24300. this.editor.runCommand('show-offset', {
  24301. el: el,
  24302. elPos: pos,
  24303. view: opts.view,
  24304. force: 1,
  24305. top: 0,
  24306. left: 0
  24307. });
  24308. },
  24309. /**
  24310. * Hide element offset viewer
  24311. * @param {HTMLElement} el
  24312. * @param {Object} pos
  24313. */
  24314. hideElementOffset: function hideElementOffset(view) {
  24315. this.editor.stopCommand('show-offset', {
  24316. view: view
  24317. });
  24318. },
  24319. /**
  24320. * Show fixed element offset viewer
  24321. * @param {HTMLElement} el
  24322. * @param {Object} pos
  24323. */
  24324. showFixedElementOffset: function showFixedElementOffset(el, pos) {
  24325. this.editor.runCommand('show-offset', {
  24326. el: el,
  24327. elPos: pos,
  24328. state: 'Fixed'
  24329. });
  24330. },
  24331. /**
  24332. * Hide fixed element offset viewer
  24333. * @param {HTMLElement} el
  24334. * @param {Object} pos
  24335. */
  24336. hideFixedElementOffset: function hideFixedElementOffset(el, pos) {
  24337. if (this.editor) this.editor.stopCommand('show-offset', {
  24338. state: 'Fixed'
  24339. });
  24340. },
  24341. /**
  24342. * Hide Highlighter element
  24343. */
  24344. hideHighlighter: function hideHighlighter(view) {
  24345. this.canvas.getHighlighter(view).style.opacity = 0;
  24346. },
  24347. /**
  24348. * On element click
  24349. * @param {Event} e
  24350. * @private
  24351. */
  24352. onClick: function onClick(ev) {
  24353. ev.stopPropagation();
  24354. ev.preventDefault();
  24355. var em = this.em;
  24356. if (em.get('_cmpDrag')) return em.set('_cmpDrag');
  24357. var $el = $(ev.target);
  24358. var model = $el.data('model');
  24359. if (!model) {
  24360. var parent = $el.parent();
  24361. while (!model && parent.length > 0) {
  24362. model = parent.data('model');
  24363. parent = parent.parent();
  24364. }
  24365. }
  24366. if (model) {
  24367. if (model.get('selectable')) {
  24368. this.select(model, ev);
  24369. } else {
  24370. var _parent2 = model.parent();
  24371. while (_parent2 && !_parent2.get('selectable')) {
  24372. _parent2 = _parent2.parent();
  24373. }
  24374. this.select(_parent2, ev);
  24375. }
  24376. }
  24377. },
  24378. /**
  24379. * Select component
  24380. * @param {Component} model
  24381. * @param {Event} event
  24382. */
  24383. select: function select(model) {
  24384. var event = arguments.length > 1 && arguments[1] !== undefined ? arguments[1] : {};
  24385. if (!model) return;
  24386. var ctrlKey = event.ctrlKey || event.metaKey;
  24387. var shiftKey = event.shiftKey;
  24388. var editor = this.editor,
  24389. em = this.em;
  24390. var multiple = editor.getConfig('multipleSelection');
  24391. if (ctrlKey && multiple) {
  24392. editor.selectToggle(model);
  24393. } else if (shiftKey && multiple) {
  24394. em.clearSelection(editor.Canvas.getWindow());
  24395. var coll = model.collection;
  24396. var index = coll.indexOf(model);
  24397. var selAll = editor.getSelectedAll();
  24398. var min, max; // Fin min and max siblings
  24399. editor.getSelectedAll().forEach(function (sel) {
  24400. var selColl = sel.collection;
  24401. var selIndex = selColl.indexOf(sel);
  24402. if (selColl === coll) {
  24403. if (selIndex < index) {
  24404. // First model BEFORE the selected one
  24405. min = Object(underscore__WEBPACK_IMPORTED_MODULE_3__["isUndefined"])(min) ? selIndex : Math.max(min, selIndex);
  24406. } else if (selIndex > index) {
  24407. // First model AFTER the selected one
  24408. max = Object(underscore__WEBPACK_IMPORTED_MODULE_3__["isUndefined"])(max) ? selIndex : Math.min(max, selIndex);
  24409. }
  24410. }
  24411. });
  24412. if (!Object(underscore__WEBPACK_IMPORTED_MODULE_3__["isUndefined"])(min)) {
  24413. while (min !== index) {
  24414. editor.selectAdd(coll.at(min));
  24415. min++;
  24416. }
  24417. }
  24418. if (!Object(underscore__WEBPACK_IMPORTED_MODULE_3__["isUndefined"])(max)) {
  24419. while (max !== index) {
  24420. editor.selectAdd(coll.at(max));
  24421. max--;
  24422. }
  24423. }
  24424. editor.selectAdd(model);
  24425. } else {
  24426. editor.select(model, {
  24427. scroll: {}
  24428. });
  24429. }
  24430. this.initResize(model);
  24431. },
  24432. /**
  24433. * Update badge for the component
  24434. * @param {Object} Component
  24435. * @param {Object} pos Position object
  24436. * @private
  24437. * */
  24438. updateBadge: function updateBadge(el, pos) {
  24439. var opts = arguments.length > 2 && arguments[2] !== undefined ? arguments[2] : {};
  24440. var model = $(el).data('model');
  24441. if (!model || !model.get('badgable')) return;
  24442. var badge = this.getBadge(opts);
  24443. if (!opts.posOnly) {
  24444. var config = this.canvas.getConfig();
  24445. var icon = model.getIcon();
  24446. var ppfx = config.pStylePrefix || '';
  24447. var clsBadge = "".concat(ppfx, "badge");
  24448. var customeLabel = config.customBadgeLabel;
  24449. var badgeLabel = "".concat(icon ? "<div class=\"".concat(clsBadge, "__icon\">").concat(icon, "</div>") : '', "\n <div class=\"").concat(clsBadge, "__name\">").concat(model.getName(), "</div>");
  24450. badge.innerHTML = customeLabel ? customeLabel(model) : badgeLabel;
  24451. }
  24452. var un = 'px';
  24453. var bStyle = badge.style;
  24454. bStyle.display = 'block';
  24455. var badgeH = badge ? badge.offsetHeight : 0;
  24456. var posTop = 0 - badgeH;
  24457. var top = opts.topOff - badgeH < 0 ? -opts.topOff : posTop;
  24458. var left = opts.leftOff < 0 ? -opts.leftOff : 0;
  24459. bStyle.top = top + un;
  24460. bStyle.left = left + un;
  24461. },
  24462. /**
  24463. * Update highlighter element
  24464. * @param {HTMLElement} el
  24465. * @param {Object} pos Position object
  24466. * @private
  24467. */
  24468. showHighlighter: function showHighlighter(view) {
  24469. this.canvas.getHighlighter(view).style.opacity = '';
  24470. },
  24471. /**
  24472. * Init resizer on the element if possible
  24473. * @param {HTMLElement|Component} elem
  24474. * @private
  24475. */
  24476. initResize: function initResize(elem) {
  24477. var em = this.em,
  24478. canvas = this.canvas;
  24479. var editor = em ? em.get('Editor') : '';
  24480. var config = em ? em.get('Config') : '';
  24481. var pfx = config.stylePrefix || '';
  24482. var resizeClass = "".concat(pfx, "resizing");
  24483. var model = !Object(underscore__WEBPACK_IMPORTED_MODULE_3__["isElement"])(elem) && Object(utils_mixins__WEBPACK_IMPORTED_MODULE_4__["isTaggableNode"])(elem) ? elem : em.getSelected();
  24484. var resizable = model.get('resizable');
  24485. var el = Object(underscore__WEBPACK_IMPORTED_MODULE_3__["isElement"])(elem) ? elem : model.getEl();
  24486. var options = {};
  24487. var modelToStyle;
  24488. var toggleBodyClass = function toggleBodyClass(method, e, opts) {
  24489. var docs = opts.docs;
  24490. docs && docs.forEach(function (doc) {
  24491. var body = doc.body;
  24492. var cls = body.className || '';
  24493. body.className = (method == 'add' ? "".concat(cls, " ").concat(resizeClass) : cls.replace(resizeClass, '')).trim();
  24494. });
  24495. };
  24496. if (editor && resizable) {
  24497. options = {
  24498. // Here the resizer is updated with the current element height and width
  24499. onStart: function onStart(e) {
  24500. var opts = arguments.length > 1 && arguments[1] !== undefined ? arguments[1] : {};
  24501. var el = opts.el,
  24502. config = opts.config,
  24503. resizer = opts.resizer;
  24504. var keyHeight = config.keyHeight,
  24505. keyWidth = config.keyWidth,
  24506. currentUnit = config.currentUnit,
  24507. keepAutoHeight = config.keepAutoHeight,
  24508. keepAutoWidth = config.keepAutoWidth;
  24509. toggleBodyClass('add', e, opts);
  24510. modelToStyle = em.get('StyleManager').getModelToStyle(model);
  24511. canvas.toggleFramesEvents();
  24512. var computedStyle = getComputedStyle(el);
  24513. var modelStyle = modelToStyle.getStyle();
  24514. var currentWidth = modelStyle[keyWidth];
  24515. config.autoWidth = keepAutoWidth && currentWidth === 'auto';
  24516. if (isNaN(parseFloat(currentWidth))) {
  24517. currentWidth = computedStyle[keyWidth];
  24518. }
  24519. var currentHeight = modelStyle[keyHeight];
  24520. config.autoHeight = keepAutoHeight && currentHeight === 'auto';
  24521. if (isNaN(parseFloat(currentHeight))) {
  24522. currentHeight = computedStyle[keyHeight];
  24523. }
  24524. resizer.startDim.w = parseFloat(currentWidth);
  24525. resizer.startDim.h = parseFloat(currentHeight);
  24526. showOffsets = 0;
  24527. if (currentUnit) {
  24528. config.unitHeight = Object(utils_mixins__WEBPACK_IMPORTED_MODULE_4__["getUnitFromValue"])(currentHeight);
  24529. config.unitWidth = Object(utils_mixins__WEBPACK_IMPORTED_MODULE_4__["getUnitFromValue"])(currentWidth);
  24530. }
  24531. },
  24532. // Update all positioned elements (eg. component toolbar)
  24533. onMove: function onMove() {
  24534. editor.trigger('component:resize');
  24535. },
  24536. onEnd: function onEnd(e, opts) {
  24537. toggleBodyClass('remove', e, opts);
  24538. editor.trigger('component:resize');
  24539. canvas.toggleFramesEvents(1);
  24540. showOffsets = 1;
  24541. },
  24542. updateTarget: function updateTarget(el, rect) {
  24543. var options = arguments.length > 2 && arguments[2] !== undefined ? arguments[2] : {};
  24544. if (!modelToStyle) {
  24545. return;
  24546. }
  24547. var store = options.store,
  24548. selectedHandler = options.selectedHandler,
  24549. config = options.config;
  24550. var keyHeight = config.keyHeight,
  24551. keyWidth = config.keyWidth,
  24552. autoHeight = config.autoHeight,
  24553. autoWidth = config.autoWidth,
  24554. unitWidth = config.unitWidth,
  24555. unitHeight = config.unitHeight;
  24556. var onlyHeight = ['tc', 'bc'].indexOf(selectedHandler) >= 0;
  24557. var onlyWidth = ['cl', 'cr'].indexOf(selectedHandler) >= 0;
  24558. var style = {};
  24559. var en = !store ? 1 : ''; // this will trigger the final change
  24560. if (!onlyHeight) {
  24561. var bodyw = canvas.getBody().offsetWidth;
  24562. var width = rect.w < bodyw ? rect.w : bodyw;
  24563. style[keyWidth] = autoWidth ? 'auto' : "".concat(width).concat(unitWidth);
  24564. }
  24565. if (!onlyWidth) {
  24566. style[keyHeight] = autoHeight ? 'auto' : "".concat(rect.h).concat(unitHeight);
  24567. }
  24568. modelToStyle.addStyle(_objectSpread({}, style, {
  24569. en: en
  24570. }), {
  24571. avoidStore: !store
  24572. });
  24573. var updateEvent = "update:component:style";
  24574. var eventToListen = "".concat(updateEvent, ":").concat(keyHeight, " ").concat(updateEvent, ":").concat(keyWidth);
  24575. em && em.trigger(eventToListen, null, null, {
  24576. noEmit: 1
  24577. });
  24578. }
  24579. };
  24580. if (_babel_runtime_helpers_typeof__WEBPACK_IMPORTED_MODULE_0___default()(resizable) == 'object') {
  24581. options = _objectSpread({}, options, {}, resizable);
  24582. }
  24583. this.resizer = editor.runCommand('resize', {
  24584. el: el,
  24585. options: options,
  24586. force: 1
  24587. });
  24588. } else {
  24589. editor.stopCommand('resize');
  24590. this.resizer = null;
  24591. }
  24592. },
  24593. /**
  24594. * Update toolbar if the component has one
  24595. * @param {Object} mod
  24596. */
  24597. updateToolbar: function updateToolbar(mod) {
  24598. var em = this.config.em;
  24599. var model = mod == em ? em.getSelected() : mod;
  24600. var toolbarEl = this.canvas.getToolbarEl();
  24601. var toolbarStyle = toolbarEl.style;
  24602. if (!model) {
  24603. // By putting `toolbarStyle.display = 'none'` will cause kind
  24604. // of freezed effect with component selection (probably by iframe
  24605. // switching)
  24606. toolbarStyle.opacity = 0;
  24607. return;
  24608. }
  24609. var toolbar = model.get('toolbar');
  24610. var showToolbar = em.get('Config').showToolbar;
  24611. if (showToolbar && toolbar && toolbar.length) {
  24612. toolbarStyle.opacity = '';
  24613. toolbarStyle.display = '';
  24614. if (!this.toolbar) {
  24615. toolbarEl.innerHTML = '';
  24616. this.toolbar = new dom_components_model_Toolbar__WEBPACK_IMPORTED_MODULE_6__["default"](toolbar);
  24617. var toolbarView = new dom_components_view_ToolbarView__WEBPACK_IMPORTED_MODULE_5__["default"]({
  24618. collection: this.toolbar,
  24619. editor: this.editor,
  24620. em: em
  24621. });
  24622. toolbarEl.appendChild(toolbarView.render().el);
  24623. }
  24624. this.toolbar.reset(toolbar);
  24625. toolbarStyle.top = '-100px';
  24626. toolbarStyle.left = 0;
  24627. } else {
  24628. toolbarStyle.display = 'none';
  24629. }
  24630. },
  24631. /**
  24632. * Update toolbar positions
  24633. * @param {HTMLElement} el
  24634. * @param {Object} pos
  24635. */
  24636. updateToolbarPos: function updateToolbarPos(pos) {
  24637. var unit = 'px';
  24638. var _this$canvas$getToolb = this.canvas.getToolbarEl(),
  24639. style = _this$canvas$getToolb.style;
  24640. style.top = "".concat(pos.top).concat(unit);
  24641. style.left = "".concat(pos.left).concat(unit);
  24642. style.opacity = '';
  24643. },
  24644. /**
  24645. * Return canvas dimensions and positions
  24646. * @return {Object}
  24647. */
  24648. getCanvasPosition: function getCanvasPosition() {
  24649. return this.canvas.getCanvasView().getPosition();
  24650. },
  24651. /**
  24652. * Returns badge element
  24653. * @return {HTMLElement}
  24654. * @private
  24655. */
  24656. getBadge: function getBadge() {
  24657. var opts = arguments.length > 0 && arguments[0] !== undefined ? arguments[0] : {};
  24658. return this.canvas.getBadgeEl(opts.view);
  24659. },
  24660. /**
  24661. * On frame scroll callback
  24662. * @private
  24663. */
  24664. onFrameScroll: function onFrameScroll() {
  24665. this.updateTools();
  24666. },
  24667. updateTools: function updateTools() {
  24668. this.updateToolsLocal();
  24669. this.updateGlobalPos();
  24670. },
  24671. isCompSelected: function isCompSelected(comp) {
  24672. return comp && comp.get('status') === 'selected';
  24673. },
  24674. /**
  24675. * Update tools visible on hover
  24676. * @param {HTMLElement} el
  24677. * @param {Object} pos
  24678. */
  24679. updateToolsLocal: function updateToolsLocal(data) {
  24680. var _ref = data || this.getElHovered(),
  24681. el = _ref.el,
  24682. pos = _ref.pos,
  24683. view = _ref.view,
  24684. component = _ref.component;
  24685. if (!el) {
  24686. this.lastHovered = 0;
  24687. return;
  24688. }
  24689. var isHoverEn = component.get('hoverable');
  24690. var isNewEl = this.lastHovered !== el;
  24691. var badgeOpts = isNewEl ? {} : {
  24692. posOnly: 1
  24693. };
  24694. if (isNewEl && isHoverEn) {
  24695. this.lastHovered = el;
  24696. this.showHighlighter(view);
  24697. this.showElementOffset(el, pos, {
  24698. view: view
  24699. });
  24700. }
  24701. if (this.isCompSelected(component)) {
  24702. this.hideHighlighter(view);
  24703. this.hideElementOffset(view);
  24704. }
  24705. var unit = 'px';
  24706. var _this$toggleToolsEl = this.toggleToolsEl(1, view),
  24707. style = _this$toggleToolsEl.style;
  24708. var frameOff = this.canvas.canvasRectOffset(el, pos);
  24709. var topOff = frameOff.top;
  24710. var leftOff = frameOff.left;
  24711. this.updateBadge(el, pos, _objectSpread({}, badgeOpts, {
  24712. view: view,
  24713. topOff: topOff,
  24714. leftOff: leftOff
  24715. }));
  24716. style.top = topOff + unit;
  24717. style.left = leftOff + unit;
  24718. style.width = pos.width + unit;
  24719. style.height = pos.height + unit;
  24720. },
  24721. updateToolsGlobal: function updateToolsGlobal() {
  24722. var _this$getElSelected = this.getElSelected(),
  24723. el = _this$getElSelected.el,
  24724. pos = _this$getElSelected.pos,
  24725. component = _this$getElSelected.component;
  24726. if (!el) {
  24727. this.toggleToolsEl(); // Hides toolbar
  24728. this.lastSelected = 0;
  24729. return;
  24730. }
  24731. var canvas = this.canvas;
  24732. var isNewEl = this.lastSelected !== el;
  24733. if (isNewEl) {
  24734. this.lastSelected = el;
  24735. this.updateToolbar(component);
  24736. }
  24737. var unit = 'px';
  24738. var _this$toggleToolsEl2 = this.toggleToolsEl(1),
  24739. style = _this$toggleToolsEl2.style;
  24740. var targetToElem = canvas.getTargetToElementFixed(el, canvas.getToolbarEl(), {
  24741. pos: pos
  24742. });
  24743. var topOff = targetToElem.canvasOffsetTop;
  24744. var leftOff = targetToElem.canvasOffsetLeft;
  24745. style.top = topOff + unit;
  24746. style.left = leftOff + unit;
  24747. style.width = pos.width + unit;
  24748. style.height = pos.height + unit;
  24749. this.updateToolbarPos({
  24750. top: targetToElem.top,
  24751. left: targetToElem.left
  24752. }); // const { resizer, em } = this;
  24753. // const model = em.getSelected();
  24754. // const el = model && model.getEl();
  24755. // if (!el) return;
  24756. // if (el && this.elSelected !== el) {
  24757. // this.elSelected = el;
  24758. // const pos = this.getElementPos(el);
  24759. // this.updateToolbarPos(el, pos);
  24760. // this.showFixedElementOffset(el, pos);
  24761. // resizer && resizer.updateContainer();
  24762. // }
  24763. },
  24764. /**
  24765. * Update attached elements, eg. component toolbar
  24766. */
  24767. updateAttached: Object(underscore__WEBPACK_IMPORTED_MODULE_3__["debounce"])(function () {
  24768. this.updateToolsGlobal();
  24769. }),
  24770. /**
  24771. * Returns element's data info
  24772. * @param {HTMLElement} el
  24773. * @return {Object}
  24774. * @private
  24775. */
  24776. getElementPos: function getElementPos(el) {
  24777. return this.canvas.getCanvasView().getElementPos(el);
  24778. },
  24779. /**
  24780. * Hide badge
  24781. * @private
  24782. * */
  24783. hideBadge: function hideBadge() {
  24784. this.getBadge().style.display = 'none';
  24785. },
  24786. /**
  24787. * Clean previous model from different states
  24788. * @param {Component} model
  24789. * @private
  24790. */
  24791. cleanPrevious: function cleanPrevious(model) {
  24792. model && model.set({
  24793. status: '',
  24794. state: ''
  24795. });
  24796. },
  24797. /**
  24798. * Returns content window
  24799. * @private
  24800. */
  24801. getContentWindow: function getContentWindow() {
  24802. return this.canvas.getWindow();
  24803. },
  24804. run: function run(editor) {
  24805. this.editor = editor && editor.get('Editor');
  24806. this.enable();
  24807. },
  24808. stop: function stop(ed, sender) {
  24809. var opts = arguments.length > 2 && arguments[2] !== undefined ? arguments[2] : {};
  24810. var em = this.em,
  24811. editor = this.editor;
  24812. this.stopSelectComponent();
  24813. !opts.preserveSelected && em.setSelected(null);
  24814. this.onOut();
  24815. this.toggleToolsEl();
  24816. editor && editor.stopCommand('resize');
  24817. this.editor = 0;
  24818. }
  24819. });
  24820. /***/ }),
  24821. /***/ "./src/commands/view/SelectPosition.js":
  24822. /*!*********************************************!*\
  24823. !*** ./src/commands/view/SelectPosition.js ***!
  24824. \*********************************************/
  24825. /*! exports provided: default */
  24826. /***/ (function(module, __webpack_exports__, __webpack_require__) {
  24827. "use strict";
  24828. __webpack_require__.r(__webpack_exports__);
  24829. /* harmony import */ var backbone__WEBPACK_IMPORTED_MODULE_0__ = __webpack_require__(/*! backbone */ "./node_modules/backbone/backbone.js");
  24830. /* harmony import */ var backbone__WEBPACK_IMPORTED_MODULE_0___default = /*#__PURE__*/__webpack_require__.n(backbone__WEBPACK_IMPORTED_MODULE_0__);
  24831. var $ = backbone__WEBPACK_IMPORTED_MODULE_0___default.a.$;
  24832. /* harmony default export */ __webpack_exports__["default"] = ({
  24833. /**
  24834. * Start select position event
  24835. * @param {HTMLElement} trg
  24836. * @private
  24837. * */
  24838. startSelectPosition: function startSelectPosition(trg, doc) {
  24839. var _this = this;
  24840. var opts = arguments.length > 2 && arguments[2] !== undefined ? arguments[2] : {};
  24841. this.isPointed = false;
  24842. var utils = this.editorModel.get('Utils');
  24843. var container = trg.ownerDocument.body;
  24844. if (utils && !this.sorter) this.sorter = new utils.Sorter({
  24845. container: container,
  24846. placer: this.canvas.getPlacerEl(),
  24847. containerSel: '*',
  24848. itemSel: '*',
  24849. pfx: this.ppfx,
  24850. direction: 'a',
  24851. document: doc,
  24852. wmargin: 1,
  24853. nested: 1,
  24854. em: this.editorModel,
  24855. canvasRelative: 1,
  24856. scale: function scale() {
  24857. return _this.em.getZoomDecimal();
  24858. }
  24859. });
  24860. if (opts.onStart) this.sorter.onStart = opts.onStart;
  24861. trg && this.sorter.startSort(trg, {
  24862. container: container
  24863. });
  24864. },
  24865. /**
  24866. * Get frame position
  24867. * @return {Object}
  24868. * @private
  24869. */
  24870. getOffsetDim: function getOffsetDim() {
  24871. var frameOff = this.offset(this.canvas.getFrameEl());
  24872. var canvasOff = this.offset(this.canvas.getElement());
  24873. var top = frameOff.top - canvasOff.top;
  24874. var left = frameOff.left - canvasOff.left;
  24875. return {
  24876. top: top,
  24877. left: left
  24878. };
  24879. },
  24880. /**
  24881. * Stop select position event
  24882. * @private
  24883. * */
  24884. stopSelectPosition: function stopSelectPosition() {
  24885. this.posTargetCollection = null;
  24886. this.posIndex = this.posMethod == 'after' && this.cDim.length !== 0 ? this.posIndex + 1 : this.posIndex; //Normalize
  24887. if (this.sorter) {
  24888. this.sorter.moved = 0;
  24889. this.sorter.endMove();
  24890. }
  24891. if (this.cDim) {
  24892. this.posIsLastEl = this.cDim.length !== 0 && this.posMethod == 'after' && this.posIndex == this.cDim.length;
  24893. this.posTargetEl = this.cDim.length === 0 ? $(this.outsideElem) : !this.posIsLastEl && this.cDim[this.posIndex] ? $(this.cDim[this.posIndex][5]).parent() : $(this.outsideElem);
  24894. this.posTargetModel = this.posTargetEl.data('model');
  24895. this.posTargetCollection = this.posTargetEl.data('model-comp');
  24896. }
  24897. },
  24898. /**
  24899. * Enabel select position
  24900. * @private
  24901. */
  24902. enable: function enable() {
  24903. this.startSelectPosition();
  24904. },
  24905. /**
  24906. * Check if the pointer is near to the float component
  24907. * @param {number} index
  24908. * @param {string} method
  24909. * @param {Array<Array>} dims
  24910. * @return {Boolean}
  24911. * @private
  24912. * */
  24913. nearFloat: function nearFloat(index, method, dims) {
  24914. var i = index || 0;
  24915. var m = method || 'before';
  24916. var len = dims.length;
  24917. var isLast = len !== 0 && m == 'after' && i == len;
  24918. if (len !== 0 && (!isLast && !dims[i][4] || dims[i - 1] && !dims[i - 1][4] || isLast && !dims[i - 1][4])) return 1;
  24919. return 0;
  24920. },
  24921. run: function run() {
  24922. this.enable();
  24923. },
  24924. stop: function stop() {
  24925. this.stopSelectPosition();
  24926. this.$wrapper.css('cursor', '');
  24927. this.$wrapper.unbind();
  24928. }
  24929. });
  24930. /***/ }),
  24931. /***/ "./src/commands/view/ShowOffset.js":
  24932. /*!*****************************************!*\
  24933. !*** ./src/commands/view/ShowOffset.js ***!
  24934. \*****************************************/
  24935. /*! exports provided: default */
  24936. /***/ (function(module, __webpack_exports__, __webpack_require__) {
  24937. "use strict";
  24938. __webpack_require__.r(__webpack_exports__);
  24939. /* harmony import */ var _babel_runtime_helpers_defineProperty__WEBPACK_IMPORTED_MODULE_0__ = __webpack_require__(/*! @babel/runtime/helpers/defineProperty */ "./node_modules/@babel/runtime/helpers/defineProperty.js");
  24940. /* harmony import */ var _babel_runtime_helpers_defineProperty__WEBPACK_IMPORTED_MODULE_0___default = /*#__PURE__*/__webpack_require__.n(_babel_runtime_helpers_defineProperty__WEBPACK_IMPORTED_MODULE_0__);
  24941. /* harmony import */ var backbone__WEBPACK_IMPORTED_MODULE_1__ = __webpack_require__(/*! backbone */ "./node_modules/backbone/backbone.js");
  24942. /* harmony import */ var backbone__WEBPACK_IMPORTED_MODULE_1___default = /*#__PURE__*/__webpack_require__.n(backbone__WEBPACK_IMPORTED_MODULE_1__);
  24943. /* harmony import */ var underscore__WEBPACK_IMPORTED_MODULE_2__ = __webpack_require__(/*! underscore */ "./node_modules/underscore/underscore.js");
  24944. /* harmony import */ var underscore__WEBPACK_IMPORTED_MODULE_2___default = /*#__PURE__*/__webpack_require__.n(underscore__WEBPACK_IMPORTED_MODULE_2__);
  24945. /* harmony import */ var utils_mixins__WEBPACK_IMPORTED_MODULE_3__ = __webpack_require__(/*! utils/mixins */ "./src/utils/mixins.js");
  24946. function ownKeys(object, enumerableOnly) { var keys = Object.keys(object); if (Object.getOwnPropertySymbols) { var symbols = Object.getOwnPropertySymbols(object); if (enumerableOnly) symbols = symbols.filter(function (sym) { return Object.getOwnPropertyDescriptor(object, sym).enumerable; }); keys.push.apply(keys, symbols); } return keys; }
  24947. function _objectSpread(target) { for (var i = 1; i < arguments.length; i++) { var source = arguments[i] != null ? arguments[i] : {}; if (i % 2) { ownKeys(source, true).forEach(function (key) { _babel_runtime_helpers_defineProperty__WEBPACK_IMPORTED_MODULE_0___default()(target, key, source[key]); }); } else if (Object.getOwnPropertyDescriptors) { Object.defineProperties(target, Object.getOwnPropertyDescriptors(source)); } else { ownKeys(source).forEach(function (key) { Object.defineProperty(target, key, Object.getOwnPropertyDescriptor(source, key)); }); } } return target; }
  24948. var $ = backbone__WEBPACK_IMPORTED_MODULE_1___default.a.$;
  24949. /* harmony default export */ __webpack_exports__["default"] = ({
  24950. getOffsetMethod: function getOffsetMethod(state) {
  24951. var method = state || '';
  24952. return 'get' + method + 'OffsetViewerEl';
  24953. },
  24954. run: function run(editor, sender, opts) {
  24955. var opt = opts || {};
  24956. var state = opt.state || '';
  24957. var config = editor.getConfig();
  24958. var zoom = this.em.getZoomDecimal();
  24959. var el = opt.el || '';
  24960. if (!config.showOffsets || Object(utils_mixins__WEBPACK_IMPORTED_MODULE_3__["isTextNode"])(el) || !config.showOffsetsSelected && state == 'Fixed') {
  24961. editor.stopCommand(this.id, opts);
  24962. return;
  24963. }
  24964. var canvas = editor.Canvas;
  24965. var pos = _objectSpread({}, opt.elPos || canvas.getElementPos(el));
  24966. if (!Object(underscore__WEBPACK_IMPORTED_MODULE_2__["isUndefined"])(opt.top)) {
  24967. pos.top = opt.top;
  24968. }
  24969. if (!Object(underscore__WEBPACK_IMPORTED_MODULE_2__["isUndefined"])(opt.left)) {
  24970. pos.left = opt.left;
  24971. }
  24972. var style = window.getComputedStyle(el);
  24973. var ppfx = this.ppfx;
  24974. var stateVar = state + 'State';
  24975. var method = this.getOffsetMethod(state);
  24976. var offsetViewer = canvas[method](opts.view);
  24977. offsetViewer.style.opacity = '';
  24978. var marginT = this['marginT' + state];
  24979. var marginB = this['marginB' + state];
  24980. var marginL = this['marginL' + state];
  24981. var marginR = this['marginR' + state];
  24982. var padT = this['padT' + state];
  24983. var padB = this['padB' + state];
  24984. var padL = this['padL' + state];
  24985. var padR = this['padR' + state];
  24986. if (offsetViewer.childNodes.length) {
  24987. this[stateVar] = '1';
  24988. marginT = offsetViewer.querySelector('[data-offset-m-t]');
  24989. marginB = offsetViewer.querySelector('[data-offset-m-b]');
  24990. marginL = offsetViewer.querySelector('[data-offset-m-l]');
  24991. marginR = offsetViewer.querySelector('[data-offset-m-r]');
  24992. padT = offsetViewer.querySelector('[data-offset-p-t]');
  24993. padB = offsetViewer.querySelector('[data-offset-p-b]');
  24994. padL = offsetViewer.querySelector('[data-offset-p-l]');
  24995. padR = offsetViewer.querySelector('[data-offset-p-r]');
  24996. }
  24997. if (!this[stateVar]) {
  24998. var stateLow = state.toLowerCase();
  24999. var marginName = stateLow + 'margin-v';
  25000. var paddingName = stateLow + 'padding-v';
  25001. var marginV = $("<div class=\"".concat(ppfx, "marginName\">")).get(0);
  25002. var paddingV = $("<div class=\"".concat(ppfx, "paddingName\">")).get(0);
  25003. var marginEls = ppfx + marginName + '-el';
  25004. var paddingEls = ppfx + paddingName + '-el';
  25005. var fullMargName = "".concat(marginEls, " ").concat(ppfx + marginName);
  25006. var fullPadName = "".concat(paddingEls, " ").concat(ppfx + paddingName);
  25007. marginT = $("<div class=\"".concat(fullMargName, "-top\"></div>")).get(0);
  25008. marginB = $("<div class=\"".concat(fullMargName, "-bottom\"></div>")).get(0);
  25009. marginL = $("<div class=\"".concat(fullMargName, "-left\"></div>")).get(0);
  25010. marginR = $("<div class=\"".concat(fullMargName, "-right\"></div>")).get(0);
  25011. padT = $("<div class=\"".concat(fullPadName, "-top\"></div>")).get(0);
  25012. padB = $("<div class=\"".concat(fullPadName, "-bottom\"></div>")).get(0);
  25013. padL = $("<div class=\"".concat(fullPadName, "-left\"></div>")).get(0);
  25014. padR = $("<div class=\"".concat(fullPadName, "-right\"></div>")).get(0);
  25015. this['marginT' + state] = marginT;
  25016. this['marginB' + state] = marginB;
  25017. this['marginL' + state] = marginL;
  25018. this['marginR' + state] = marginR;
  25019. this['padT' + state] = padT;
  25020. this['padB' + state] = padB;
  25021. this['padL' + state] = padL;
  25022. this['padR' + state] = padR;
  25023. marginV.appendChild(marginT);
  25024. marginV.appendChild(marginB);
  25025. marginV.appendChild(marginL);
  25026. marginV.appendChild(marginR);
  25027. paddingV.appendChild(padT);
  25028. paddingV.appendChild(padB);
  25029. paddingV.appendChild(padL);
  25030. paddingV.appendChild(padR);
  25031. offsetViewer.appendChild(marginV);
  25032. offsetViewer.appendChild(paddingV);
  25033. this[stateVar] = '1';
  25034. }
  25035. var unit = 'px';
  25036. var marginLeftSt = parseFloat(style.marginLeft.replace(unit, '')) * zoom;
  25037. var marginRightSt = parseFloat(style.marginRight.replace(unit, '')) * zoom;
  25038. var marginTopSt = parseFloat(style.marginTop.replace(unit, '')) * zoom;
  25039. var marginBottomSt = parseFloat(style.marginBottom.replace(unit, '')) * zoom;
  25040. var mtStyle = marginT.style;
  25041. var mbStyle = marginB.style;
  25042. var mlStyle = marginL.style;
  25043. var mrStyle = marginR.style;
  25044. var ptStyle = padT.style;
  25045. var pbStyle = padB.style;
  25046. var plStyle = padL.style;
  25047. var prStyle = padR.style;
  25048. var posLeft = parseFloat(pos.left);
  25049. var widthEl = parseFloat(style.width) * zoom + unit; // Margin style
  25050. mtStyle.height = marginTopSt + unit;
  25051. mtStyle.width = widthEl;
  25052. mtStyle.top = pos.top - marginTopSt + unit;
  25053. mtStyle.left = posLeft + unit;
  25054. mbStyle.height = marginBottomSt + unit;
  25055. mbStyle.width = widthEl;
  25056. mbStyle.top = pos.top + pos.height + unit;
  25057. mbStyle.left = posLeft + unit;
  25058. var marginSideH = pos.height + marginTopSt + marginBottomSt + unit;
  25059. var marginSideT = pos.top - marginTopSt + unit;
  25060. mlStyle.height = marginSideH;
  25061. mlStyle.width = marginLeftSt + unit;
  25062. mlStyle.top = marginSideT;
  25063. mlStyle.left = posLeft - marginLeftSt + unit;
  25064. mrStyle.height = marginSideH;
  25065. mrStyle.width = marginRightSt + unit;
  25066. mrStyle.top = marginSideT;
  25067. mrStyle.left = posLeft + pos.width + unit; // Padding style
  25068. var padTop = parseFloat(style.paddingTop) * zoom;
  25069. ptStyle.height = padTop + unit; // ptStyle.width = widthEl;
  25070. // ptStyle.top = pos.top + unit;
  25071. // ptStyle.left = posLeft + unit;
  25072. var padBot = parseFloat(style.paddingBottom) * zoom;
  25073. pbStyle.height = padBot + unit; // pbStyle.width = widthEl;
  25074. // pbStyle.top = pos.top + pos.height - padBot + unit;
  25075. // pbStyle.left = posLeft + unit;
  25076. var padSideH = pos.height - padBot - padTop + unit;
  25077. var padSideT = pos.top + padTop + unit;
  25078. plStyle.height = padSideH;
  25079. plStyle.width = parseFloat(style.paddingLeft) * zoom + unit;
  25080. plStyle.top = padSideT; // plStyle.left = pos.left + unit;
  25081. // plStyle.right = 0;
  25082. var padRight = parseFloat(style.paddingRight) * zoom;
  25083. prStyle.height = padSideH;
  25084. prStyle.width = padRight + unit;
  25085. prStyle.top = padSideT; // prStyle.left = pos.left + pos.width - padRight + unit;
  25086. // prStyle.left = 0;
  25087. },
  25088. stop: function stop(editor, sender) {
  25089. var opts = arguments.length > 2 && arguments[2] !== undefined ? arguments[2] : {};
  25090. var opt = opts || {};
  25091. var state = opt.state || '';
  25092. var method = this.getOffsetMethod(state);
  25093. var canvas = editor.Canvas;
  25094. var offsetViewer = canvas[method](opts.view);
  25095. offsetViewer.style.opacity = 0;
  25096. }
  25097. });
  25098. /***/ }),
  25099. /***/ "./src/commands/view/SwitchVisibility.js":
  25100. /*!***********************************************!*\
  25101. !*** ./src/commands/view/SwitchVisibility.js ***!
  25102. \***********************************************/
  25103. /*! exports provided: default */
  25104. /***/ (function(module, __webpack_exports__, __webpack_require__) {
  25105. "use strict";
  25106. __webpack_require__.r(__webpack_exports__);
  25107. /* harmony default export */ __webpack_exports__["default"] = ({
  25108. run: function run(ed) {
  25109. this.toggleVis(ed);
  25110. },
  25111. stop: function stop(ed) {
  25112. this.toggleVis(ed, 0);
  25113. },
  25114. toggleVis: function toggleVis(ed) {
  25115. var _this = this;
  25116. var active = arguments.length > 1 && arguments[1] !== undefined ? arguments[1] : 1;
  25117. if (!ed.Commands.isActive('preview')) {
  25118. var method = active ? 'add' : 'remove';
  25119. ed.Canvas.getFrames().forEach(function (frame) {
  25120. frame.view.getBody().classList[method]("".concat(_this.ppfx, "dashed"));
  25121. });
  25122. }
  25123. }
  25124. });
  25125. /***/ }),
  25126. /***/ "./src/css_composer/config/config.js":
  25127. /*!*******************************************!*\
  25128. !*** ./src/css_composer/config/config.js ***!
  25129. \*******************************************/
  25130. /*! exports provided: default */
  25131. /***/ (function(module, __webpack_exports__, __webpack_require__) {
  25132. "use strict";
  25133. __webpack_require__.r(__webpack_exports__);
  25134. /* harmony default export */ __webpack_exports__["default"] = ({
  25135. // Style prefix
  25136. stylePrefix: 'css-',
  25137. // Custom CSS string to render on top
  25138. staticRules: '',
  25139. // Default CSS style
  25140. rules: []
  25141. });
  25142. /***/ }),
  25143. /***/ "./src/css_composer/index.js":
  25144. /*!***********************************!*\
  25145. !*** ./src/css_composer/index.js ***!
  25146. \***********************************/
  25147. /*! exports provided: default */
  25148. /***/ (function(module, __webpack_exports__, __webpack_require__) {
  25149. "use strict";
  25150. __webpack_require__.r(__webpack_exports__);
  25151. /* harmony import */ var _babel_runtime_helpers_defineProperty__WEBPACK_IMPORTED_MODULE_0__ = __webpack_require__(/*! @babel/runtime/helpers/defineProperty */ "./node_modules/@babel/runtime/helpers/defineProperty.js");
  25152. /* harmony import */ var _babel_runtime_helpers_defineProperty__WEBPACK_IMPORTED_MODULE_0___default = /*#__PURE__*/__webpack_require__.n(_babel_runtime_helpers_defineProperty__WEBPACK_IMPORTED_MODULE_0__);
  25153. /* harmony import */ var underscore__WEBPACK_IMPORTED_MODULE_1__ = __webpack_require__(/*! underscore */ "./node_modules/underscore/underscore.js");
  25154. /* harmony import */ var underscore__WEBPACK_IMPORTED_MODULE_1___default = /*#__PURE__*/__webpack_require__.n(underscore__WEBPACK_IMPORTED_MODULE_1__);
  25155. /* harmony import */ var _config_config__WEBPACK_IMPORTED_MODULE_2__ = __webpack_require__(/*! ./config/config */ "./src/css_composer/config/config.js");
  25156. /* harmony import */ var _model_CssRule__WEBPACK_IMPORTED_MODULE_3__ = __webpack_require__(/*! ./model/CssRule */ "./src/css_composer/model/CssRule.js");
  25157. /* harmony import */ var _model_CssRules__WEBPACK_IMPORTED_MODULE_4__ = __webpack_require__(/*! ./model/CssRules */ "./src/css_composer/model/CssRules.js");
  25158. /* harmony import */ var _view_CssRulesView__WEBPACK_IMPORTED_MODULE_5__ = __webpack_require__(/*! ./view/CssRulesView */ "./src/css_composer/view/CssRulesView.js");
  25159. /* harmony import */ var selector_manager_model_Selectors__WEBPACK_IMPORTED_MODULE_6__ = __webpack_require__(/*! selector_manager/model/Selectors */ "./src/selector_manager/model/Selectors.js");
  25160. /* harmony import */ var selector_manager_model_Selector__WEBPACK_IMPORTED_MODULE_7__ = __webpack_require__(/*! selector_manager/model/Selector */ "./src/selector_manager/model/Selector.js");
  25161. function ownKeys(object, enumerableOnly) { var keys = Object.keys(object); if (Object.getOwnPropertySymbols) { var symbols = Object.getOwnPropertySymbols(object); if (enumerableOnly) symbols = symbols.filter(function (sym) { return Object.getOwnPropertyDescriptor(object, sym).enumerable; }); keys.push.apply(keys, symbols); } return keys; }
  25162. function _objectSpread(target) { for (var i = 1; i < arguments.length; i++) { var source = arguments[i] != null ? arguments[i] : {}; if (i % 2) { ownKeys(source, true).forEach(function (key) { _babel_runtime_helpers_defineProperty__WEBPACK_IMPORTED_MODULE_0___default()(target, key, source[key]); }); } else if (Object.getOwnPropertyDescriptors) { Object.defineProperties(target, Object.getOwnPropertyDescriptors(source)); } else { ownKeys(source).forEach(function (key) { Object.defineProperty(target, key, Object.getOwnPropertyDescriptor(source, key)); }); } } return target; }
  25163. /**
  25164. * This module contains and manage CSS rules for the template inside the canvas.
  25165. * You can customize the initial state of the module from the editor initialization, by passing the following [Configuration Object](https://github.com/artf/grapesjs/blob/master/src/css_composer/config/config.js)
  25166. * ```js
  25167. * const editor = grapesjs.init({
  25168. * cssComposer: {
  25169. * // options
  25170. * }
  25171. * })
  25172. * ```
  25173. *
  25174. * Once the editor is instantiated you can use its API. Before using these methods you should get the module from the instance
  25175. *
  25176. * ```js
  25177. * const cssComposer = editor.CssComposer;
  25178. * ```
  25179. *
  25180. * * [load](#load)
  25181. * * [store](#store)
  25182. * * [add](#add)
  25183. * * [get](#get)
  25184. * * [getAll](#getall)
  25185. * * [clear](#clear)
  25186. * * [setRule](#setrule)
  25187. * * [getRule](#getrule)
  25188. *
  25189. * @module CssComposer
  25190. */
  25191. /* harmony default export */ __webpack_exports__["default"] = (function () {
  25192. var em;
  25193. var c = {};
  25194. var rules, rulesView;
  25195. return {
  25196. Selectors: selector_manager_model_Selectors__WEBPACK_IMPORTED_MODULE_6__["default"],
  25197. /**
  25198. * Name of the module
  25199. * @type {String}
  25200. * @private
  25201. */
  25202. name: 'CssComposer',
  25203. getConfig: function getConfig() {
  25204. return c;
  25205. },
  25206. /**
  25207. * Mandatory for the storage manager
  25208. * @type {String}
  25209. * @private
  25210. */
  25211. storageKey: function storageKey() {
  25212. var keys = [];
  25213. var smc = c.stm && c.stm.getConfig() || {};
  25214. if (smc.storeCss) keys.push('css');
  25215. if (smc.storeStyles) keys.push('styles');
  25216. return keys;
  25217. },
  25218. /**
  25219. * Initializes module. Automatically called with a new instance of the editor
  25220. * @param {Object} config Configurations
  25221. * @private
  25222. */
  25223. init: function init(config) {
  25224. c = config || {};
  25225. for (var name in _config_config__WEBPACK_IMPORTED_MODULE_2__["default"]) {
  25226. if (!(name in c)) c[name] = _config_config__WEBPACK_IMPORTED_MODULE_2__["default"][name];
  25227. }
  25228. var ppfx = c.pStylePrefix;
  25229. if (ppfx) c.stylePrefix = ppfx + c.stylePrefix;
  25230. var elStyle = c.em && c.em.config.style || '';
  25231. c.rules = elStyle || c.rules;
  25232. em = c.em;
  25233. rules = new _model_CssRules__WEBPACK_IMPORTED_MODULE_4__["default"]([], c);
  25234. rulesView = new _view_CssRulesView__WEBPACK_IMPORTED_MODULE_5__["default"]({
  25235. collection: rules,
  25236. config: c
  25237. });
  25238. return this;
  25239. },
  25240. /**
  25241. * On load callback
  25242. * @private
  25243. */
  25244. onLoad: function onLoad() {
  25245. rules.add(c.rules);
  25246. },
  25247. /**
  25248. * Do stuff after load
  25249. * @param {Editor} em
  25250. * @private
  25251. */
  25252. postLoad: function postLoad(em) {
  25253. var _this = this;
  25254. var ev = 'add remove';
  25255. var rules = this.getAll();
  25256. var um = em.get('UndoManager');
  25257. um && um.add(rules);
  25258. em.stopListening(rules, ev, this.handleChange);
  25259. em.listenTo(rules, ev, this.handleChange);
  25260. rules.each(function (rule) {
  25261. return _this.handleChange(rule, {
  25262. avoidStore: 1
  25263. });
  25264. });
  25265. },
  25266. /**
  25267. * Handle rule changes
  25268. * @private
  25269. */
  25270. handleChange: function handleChange(model) {
  25271. var opts = arguments.length > 1 && arguments[1] !== undefined ? arguments[1] : {};
  25272. var ev = 'change:style';
  25273. var um = em.get('UndoManager');
  25274. um && um.add(model);
  25275. var handleUpdates = em.handleUpdates.bind(em);
  25276. em.stopListening(model, ev, handleUpdates);
  25277. em.listenTo(model, ev, handleUpdates);
  25278. !opts.avoidStore && handleUpdates('', '', opts);
  25279. },
  25280. /**
  25281. * Load data from the passed object, if the object is empty will try to fetch them
  25282. * autonomously from the storage manager.
  25283. * The fetched data will be added to the collection
  25284. * @param {Object} data Object of data to load
  25285. * @return {Object} Loaded rules
  25286. */
  25287. load: function load(data) {
  25288. var d = data || '';
  25289. if (!d && c.stm) {
  25290. d = c.em.getCacheLoad();
  25291. }
  25292. var obj = d.styles || '';
  25293. if (d.styles) {
  25294. try {
  25295. obj = JSON.parse(d.styles);
  25296. } catch (err) {}
  25297. } else if (d.css) {
  25298. obj = c.em.get('Parser').parseCss(d.css);
  25299. }
  25300. if (Object(underscore__WEBPACK_IMPORTED_MODULE_1__["isArray"])(obj)) {
  25301. obj.length && rules.reset(obj);
  25302. } else if (obj) {
  25303. rules.reset(obj);
  25304. }
  25305. return obj;
  25306. },
  25307. /**
  25308. * Store data to the selected storage
  25309. * @param {Boolean} noStore If true, won't store
  25310. * @return {Object} Data to store
  25311. */
  25312. store: function store(noStore) {
  25313. if (!c.stm) return;
  25314. var obj = {};
  25315. var keys = this.storageKey();
  25316. if (keys.indexOf('css') >= 0) obj.css = c.em.getCss();
  25317. if (keys.indexOf('styles') >= 0) obj.styles = JSON.stringify(rules);
  25318. if (!noStore) c.stm.store(obj);
  25319. return obj;
  25320. },
  25321. /**
  25322. * Add new rule to the collection, if not yet exists with the same selectors
  25323. * @param {Array<Selector>} selectors Array of selectors
  25324. * @param {String} state Css rule state
  25325. * @param {String} width For which device this style is oriented
  25326. * @param {Object} opts Other options for the rule
  25327. * @return {Model}
  25328. * @example
  25329. * var sm = editor.SelectorManager;
  25330. * var sel1 = sm.add('myClass1');
  25331. * var sel2 = sm.add('myClass2');
  25332. * var rule = cssComposer.add([sel1, sel2], 'hover');
  25333. * rule.set('style', {
  25334. * width: '100px',
  25335. * color: '#fff',
  25336. * });
  25337. * */
  25338. add: function add(selectors, state, width) {
  25339. var opts = arguments.length > 3 && arguments[3] !== undefined ? arguments[3] : {};
  25340. var s = state || '';
  25341. var w = width || '';
  25342. var opt = _objectSpread({}, opts);
  25343. var rule = this.get(selectors, s, w, opt); // do not create rules that were found before
  25344. // unless this is a single at-rule, for which multiple declarations
  25345. // make sense (e.g. multiple `@font-type`s)
  25346. if (rule && rule.config && !rule.config.singleAtRule) {
  25347. return rule;
  25348. } else {
  25349. opt.state = s;
  25350. opt.mediaText = w;
  25351. opt.selectors = '';
  25352. rule = new _model_CssRule__WEBPACK_IMPORTED_MODULE_3__["default"](opt, c);
  25353. rule.get('selectors').add(selectors);
  25354. rules.add(rule);
  25355. return rule;
  25356. }
  25357. },
  25358. /**
  25359. * Get the rule
  25360. * @param {Array<Selector>} selectors Array of selectors
  25361. * @param {String} state Css rule state
  25362. * @param {String} width For which device this style is oriented
  25363. * @param {Object} ruleProps Other rule props
  25364. * @return {Model|null}
  25365. * @example
  25366. * var sm = editor.SelectorManager;
  25367. * var sel1 = sm.add('myClass1');
  25368. * var sel2 = sm.add('myClass2');
  25369. * var rule = cssComposer.get([sel1, sel2], 'hover');
  25370. * // Update the style
  25371. * rule.set('style', {
  25372. * width: '300px',
  25373. * color: '#000',
  25374. * });
  25375. * */
  25376. get: function get(selectors, state, width, ruleProps) {
  25377. var rule = null;
  25378. rules.each(function (m) {
  25379. if (rule) return;
  25380. if (m.compare(selectors, state, width, ruleProps)) rule = m;
  25381. });
  25382. return rule;
  25383. },
  25384. /**
  25385. * Get the collection of rules
  25386. * @return {Collection}
  25387. * */
  25388. getAll: function getAll() {
  25389. return rules;
  25390. },
  25391. /**
  25392. * Remove all rules
  25393. * @return {this}
  25394. */
  25395. clear: function clear() {
  25396. this.getAll().reset();
  25397. return this;
  25398. },
  25399. /**
  25400. * Add a raw collection of rule objects
  25401. * This method overrides styles, in case, of already defined rule
  25402. * @param {Array<Object>} data Array of rule objects, eg . [{selectors: ['class1'], style: {....}}, ..]
  25403. * @param {Object} opts Options
  25404. * @return {Array<Model>}
  25405. * @private
  25406. */
  25407. addCollection: function addCollection(data) {
  25408. var opts = arguments.length > 1 && arguments[1] !== undefined ? arguments[1] : {};
  25409. var result = [];
  25410. var d = data instanceof Array ? data : [data];
  25411. for (var i = 0, l = d.length; i < l; i++) {
  25412. var rule = d[i] || {};
  25413. if (!rule.selectors) continue;
  25414. var sm = c.em && c.em.get('SelectorManager');
  25415. if (!sm) console.warn('Selector Manager not found');
  25416. var sl = rule.selectors;
  25417. var sels = sl instanceof Array ? sl : [sl];
  25418. var newSels = [];
  25419. for (var j = 0, le = sels.length; j < le; j++) {
  25420. var selec = sm.add(sels[j]);
  25421. newSels.push(selec);
  25422. }
  25423. var modelExists = this.get(newSels, rule.state, rule.mediaText, rule);
  25424. var model = this.add(newSels, rule.state, rule.mediaText, rule);
  25425. var updateStyle = !modelExists || !opts.avoidUpdateStyle;
  25426. var style = rule.style || {};
  25427. if (updateStyle) {
  25428. var styleUpdate = opts.extend ? _objectSpread({}, model.get('style'), {}, style) : style;
  25429. model.set('style', styleUpdate);
  25430. }
  25431. result.push(model);
  25432. }
  25433. return result;
  25434. },
  25435. /**
  25436. * Add/update the CSS rule with a generic selector
  25437. * @param {string} selectors Selector, eg. '.myclass'
  25438. * @param {Object} style Style properties and values
  25439. * @param {Object} [opts={}] Additional properties
  25440. * @param {String} [opts.atRuleType=''] At-rule type, eg. 'media'
  25441. * @param {String} [opts.atRuleParams=''] At-rule parameters, eg. '(min-width: 500px)'
  25442. * @return {CssRule} The new/updated rule
  25443. * @example
  25444. * // Simple class-based rule
  25445. * const rule = cc.setRule('.class1.class2', { color: 'red' });
  25446. * console.log(rule.toCSS()) // output: .class1.class2 { color: red }
  25447. * // With state and other mixed selector
  25448. * const rule = cc.setRule('.class1.class2:hover, div#myid', { color: 'red' });
  25449. * // output: .class1.class2:hover, div#myid { color: red }
  25450. * // With media
  25451. * const rule = cc.setRule('.class1:hover', { color: 'red' }, {
  25452. * atRuleType: 'media',
  25453. * atRuleParams: '(min-width: 500px)',
  25454. * });
  25455. * // output: @media (min-width: 500px) { .class1:hover { color: red } }
  25456. */
  25457. setRule: function setRule(selectors, style) {
  25458. var opts = arguments.length > 2 && arguments[2] !== undefined ? arguments[2] : {};
  25459. var atRuleType = opts.atRuleType,
  25460. atRuleParams = opts.atRuleParams;
  25461. var node = em.get('Parser').parserCss.checkNode({
  25462. selectors: selectors,
  25463. style: style
  25464. })[0];
  25465. var state = node.state,
  25466. selectorsAdd = node.selectorsAdd;
  25467. var sm = em.get('SelectorManager');
  25468. var selector = sm.add(node.selectors);
  25469. var rule = this.add(selector, state, atRuleParams, {
  25470. selectorsAdd: selectorsAdd,
  25471. atRule: atRuleType
  25472. });
  25473. rule.setStyle(style, opts);
  25474. return rule;
  25475. },
  25476. /**
  25477. * Get the CSS rule by a generic selector
  25478. * @param {string} selectors Selector, eg. '.myclass:hover'
  25479. * @param {String} [opts.atRuleType=''] At-rule type, eg. 'media'
  25480. * @param {String} [opts.atRuleParams=''] At-rule parameters, eg. '(min-width: 500px)'
  25481. * @return {CssRule}
  25482. * @example
  25483. * const rule = cc.getRule('.myclass1:hover');
  25484. * const rule2 = cc.getRule('.myclass1:hover, div#myid');
  25485. * const rule3 = cc.getRule('.myclass1', {
  25486. * atRuleType: 'media',
  25487. * atRuleParams: '(min-width: 500px)',
  25488. * });
  25489. */
  25490. getRule: function getRule(selectors) {
  25491. var opts = arguments.length > 1 && arguments[1] !== undefined ? arguments[1] : {};
  25492. var sm = em.get('SelectorManager');
  25493. var node = em.get('Parser').parserCss.checkNode({
  25494. selectors: selectors
  25495. })[0];
  25496. var selector = sm.get(node.selectors);
  25497. var state = node.state,
  25498. selectorsAdd = node.selectorsAdd;
  25499. var atRuleType = opts.atRuleType,
  25500. atRuleParams = opts.atRuleParams;
  25501. return selector && this.get(selector, state, atRuleParams, {
  25502. selectorsAdd: selectorsAdd,
  25503. atRule: atRuleType
  25504. });
  25505. },
  25506. /**
  25507. * Add/update the CSS rule with id selector
  25508. * @param {string} name Id selector name, eg. 'my-id'
  25509. * @param {Object} style Style properties and values
  25510. * @param {Object} [opts={}] Custom options, like `state` and `mediaText`
  25511. * @return {CssRule} The new/updated rule
  25512. * @private
  25513. * @example
  25514. * const rule = cc.setIdRule('myid', { color: 'red' });
  25515. * const ruleHover = cc.setIdRule('myid', { color: 'blue' }, { state: 'hover' });
  25516. * // This will add current CSS:
  25517. * // #myid { color: red }
  25518. * // #myid:hover { color: blue }
  25519. */
  25520. setIdRule: function setIdRule(name) {
  25521. var style = arguments.length > 1 && arguments[1] !== undefined ? arguments[1] : {};
  25522. var opts = arguments.length > 2 && arguments[2] !== undefined ? arguments[2] : {};
  25523. var state = opts.state || '';
  25524. var media = opts.mediaText || em.getCurrentMedia();
  25525. var sm = em.get('SelectorManager');
  25526. var selector = sm.add({
  25527. name: name,
  25528. type: selector_manager_model_Selector__WEBPACK_IMPORTED_MODULE_7__["default"].TYPE_ID
  25529. });
  25530. var rule = this.add(selector, state, media);
  25531. rule.setStyle(style, opts);
  25532. return rule;
  25533. },
  25534. /**
  25535. * Get the CSS rule by id selector
  25536. * @param {string} name Id selector name, eg. 'my-id'
  25537. * @param {Object} [opts={}] Custom options, like `state` and `mediaText`
  25538. * @return {CssRule}
  25539. * @private
  25540. * @example
  25541. * const rule = cc.getIdRule('myid');
  25542. * const ruleHover = cc.setIdRule('myid', { state: 'hover' });
  25543. */
  25544. getIdRule: function getIdRule(name) {
  25545. var opts = arguments.length > 1 && arguments[1] !== undefined ? arguments[1] : {};
  25546. var state = opts.state || '';
  25547. var media = opts.mediaText || em.getCurrentMedia();
  25548. var selector = em.get('SelectorManager').get(name, selector_manager_model_Selector__WEBPACK_IMPORTED_MODULE_7__["default"].TYPE_ID);
  25549. return selector && this.get(selector, state, media);
  25550. },
  25551. /**
  25552. * Add/update the CSS rule with class selector
  25553. * @param {string} name Class selector name, eg. 'my-class'
  25554. * @param {Object} style Style properties and values
  25555. * @param {Object} [opts={}] Custom options, like `state` and `mediaText`
  25556. * @return {CssRule} The new/updated rule
  25557. * @private
  25558. * @example
  25559. * const rule = cc.setClassRule('myclass', { color: 'red' });
  25560. * const ruleHover = cc.setClassRule('myclass', { color: 'blue' }, { state: 'hover' });
  25561. * // This will add current CSS:
  25562. * // .myclass { color: red }
  25563. * // .myclass:hover { color: blue }
  25564. */
  25565. setClassRule: function setClassRule(name) {
  25566. var style = arguments.length > 1 && arguments[1] !== undefined ? arguments[1] : {};
  25567. var opts = arguments.length > 2 && arguments[2] !== undefined ? arguments[2] : {};
  25568. var state = opts.state || '';
  25569. var media = opts.mediaText || em.getCurrentMedia();
  25570. var sm = em.get('SelectorManager');
  25571. var selector = sm.add({
  25572. name: name,
  25573. type: selector_manager_model_Selector__WEBPACK_IMPORTED_MODULE_7__["default"].TYPE_CLASS
  25574. });
  25575. var rule = this.add(selector, state, media);
  25576. rule.setStyle(style, opts);
  25577. return rule;
  25578. },
  25579. /**
  25580. * Get the CSS rule by class selector
  25581. * @param {string} name Class selector name, eg. 'my-class'
  25582. * @param {Object} [opts={}] Custom options, like `state` and `mediaText`
  25583. * @return {CssRule}
  25584. * @private
  25585. * @example
  25586. * const rule = cc.getClassRule('myclass');
  25587. * const ruleHover = cc.getClassRule('myclass', { state: 'hover' });
  25588. */
  25589. getClassRule: function getClassRule(name) {
  25590. var opts = arguments.length > 1 && arguments[1] !== undefined ? arguments[1] : {};
  25591. var state = opts.state || '';
  25592. var media = opts.mediaText || em.getCurrentMedia();
  25593. var selector = em.get('SelectorManager').get(name, selector_manager_model_Selector__WEBPACK_IMPORTED_MODULE_7__["default"].TYPE_CLASS);
  25594. return selector && this.get(selector, state, media);
  25595. },
  25596. /**
  25597. * Render the block of CSS rules
  25598. * @return {HTMLElement}
  25599. * @private
  25600. */
  25601. render: function render() {
  25602. return rulesView.render().el;
  25603. }
  25604. };
  25605. });
  25606. /***/ }),
  25607. /***/ "./src/css_composer/model/CssRule.js":
  25608. /*!*******************************************!*\
  25609. !*** ./src/css_composer/model/CssRule.js ***!
  25610. \*******************************************/
  25611. /*! exports provided: default */
  25612. /***/ (function(module, __webpack_exports__, __webpack_require__) {
  25613. "use strict";
  25614. __webpack_require__.r(__webpack_exports__);
  25615. /* harmony import */ var underscore__WEBPACK_IMPORTED_MODULE_0__ = __webpack_require__(/*! underscore */ "./node_modules/underscore/underscore.js");
  25616. /* harmony import */ var underscore__WEBPACK_IMPORTED_MODULE_0___default = /*#__PURE__*/__webpack_require__.n(underscore__WEBPACK_IMPORTED_MODULE_0__);
  25617. /* harmony import */ var backbone__WEBPACK_IMPORTED_MODULE_1__ = __webpack_require__(/*! backbone */ "./node_modules/backbone/backbone.js");
  25618. /* harmony import */ var backbone__WEBPACK_IMPORTED_MODULE_1___default = /*#__PURE__*/__webpack_require__.n(backbone__WEBPACK_IMPORTED_MODULE_1__);
  25619. /* harmony import */ var domain_abstract_model_Styleable__WEBPACK_IMPORTED_MODULE_2__ = __webpack_require__(/*! domain_abstract/model/Styleable */ "./src/domain_abstract/model/Styleable.js");
  25620. /* harmony import */ var selector_manager_model_Selectors__WEBPACK_IMPORTED_MODULE_3__ = __webpack_require__(/*! selector_manager/model/Selectors */ "./src/selector_manager/model/Selectors.js");
  25621. var _window = window,
  25622. CSS = _window.CSS;
  25623. /* harmony default export */ __webpack_exports__["default"] = (backbone__WEBPACK_IMPORTED_MODULE_1___default.a.Model.extend(domain_abstract_model_Styleable__WEBPACK_IMPORTED_MODULE_2__["default"]).extend({
  25624. defaults: {
  25625. // Css selectors
  25626. selectors: {},
  25627. // Additional string css selectors
  25628. selectorsAdd: '',
  25629. // Css properties style
  25630. style: {},
  25631. // On which device width this rule should be rendered, eg. @media (max-width: 1000px)
  25632. mediaText: '',
  25633. // State of the rule, eg: hover | pressed | focused
  25634. state: '',
  25635. // Indicates if the rule is stylable
  25636. stylable: true,
  25637. // Type of at-rule, eg. 'media', 'font-face', etc.
  25638. atRuleType: '',
  25639. // This particolar property is used only on at-rules, like 'page' or
  25640. // 'font-face', where the block containes only style declarations
  25641. singleAtRule: 0,
  25642. // If true, sets '!important' on all properties
  25643. // You can use an array to specify properties to set important
  25644. // Used in view
  25645. important: 0
  25646. },
  25647. initialize: function initialize(c) {
  25648. var opt = arguments.length > 1 && arguments[1] !== undefined ? arguments[1] : {};
  25649. this.config = c || {};
  25650. var em = opt.em;
  25651. var selectors = this.config.selectors || [];
  25652. this.em = em;
  25653. if (em) {
  25654. var sm = em.get('SelectorManager');
  25655. var slct = [];
  25656. selectors.forEach(function (selector) {
  25657. slct.push(sm.add(selector));
  25658. });
  25659. selectors = slct;
  25660. }
  25661. this.set('selectors', new selector_manager_model_Selectors__WEBPACK_IMPORTED_MODULE_3__["default"](selectors));
  25662. },
  25663. /**
  25664. * Returns an at-rule statement if possible, eg. '@media (...)', '@keyframes'
  25665. * @return {string}
  25666. */
  25667. getAtRule: function getAtRule() {
  25668. var type = this.get('atRuleType');
  25669. var condition = this.get('mediaText'); // Avoid breaks with the last condition
  25670. var typeStr = type ? "@".concat(type) : condition ? '@media' : '';
  25671. return typeStr + (condition && typeStr ? " ".concat(condition) : '');
  25672. },
  25673. /**
  25674. * Return selectors fo the rule as a string
  25675. * @return {string}
  25676. */
  25677. selectorsToString: function selectorsToString() {
  25678. var opts = arguments.length > 0 && arguments[0] !== undefined ? arguments[0] : {};
  25679. var result = [];
  25680. var em = this.em;
  25681. var state = this.get('state');
  25682. var wrapper = this.get('wrapper');
  25683. var addSelector = this.get('selectorsAdd');
  25684. var isBody = wrapper && em && em.getConfig('wrapperIsBody');
  25685. var selOpts = {
  25686. escape: function escape(str) {
  25687. return CSS && CSS.escape ? CSS.escape(str) : str;
  25688. }
  25689. };
  25690. var selectors = isBody ? 'body' : this.get('selectors').getFullString(0, selOpts);
  25691. var stateStr = state && !opts.skipState ? ":".concat(state) : '';
  25692. selectors && result.push("".concat(selectors).concat(stateStr));
  25693. addSelector && !opts.skipAdd && result.push(addSelector);
  25694. return result.join(', ');
  25695. },
  25696. /**
  25697. * Get declaration block
  25698. * @param {Object} [opts={}] Options
  25699. * @return {string}
  25700. */
  25701. getDeclaration: function getDeclaration() {
  25702. var opts = arguments.length > 0 && arguments[0] !== undefined ? arguments[0] : {};
  25703. var result = '';
  25704. var selectors = this.selectorsToString();
  25705. var style = this.styleToString(opts);
  25706. var singleAtRule = this.get('singleAtRule');
  25707. if ((selectors || singleAtRule) && style) {
  25708. result = singleAtRule ? style : "".concat(selectors, "{").concat(style, "}");
  25709. }
  25710. return result;
  25711. },
  25712. /**
  25713. * Returns CSS string of the rule
  25714. * @param {Object} [opts={}] Options
  25715. * @return {string}
  25716. */
  25717. toCSS: function toCSS() {
  25718. var opts = arguments.length > 0 && arguments[0] !== undefined ? arguments[0] : {};
  25719. var result = '';
  25720. var atRule = this.getAtRule();
  25721. var block = this.getDeclaration(opts);
  25722. block && (result = block);
  25723. if (atRule && result) {
  25724. result = "".concat(atRule, "{").concat(result, "}");
  25725. }
  25726. return result;
  25727. },
  25728. toJSON: function toJSON() {
  25729. for (var _len = arguments.length, args = new Array(_len), _key = 0; _key < _len; _key++) {
  25730. args[_key] = arguments[_key];
  25731. }
  25732. var obj = backbone__WEBPACK_IMPORTED_MODULE_1___default.a.Model.prototype.toJSON.apply(this, args);
  25733. if (this.em.getConfig('avoidDefaults')) {
  25734. var defaults = this.defaults;
  25735. Object(underscore__WEBPACK_IMPORTED_MODULE_0__["forEach"])(defaults, function (value, key) {
  25736. if (obj[key] === value) {
  25737. delete obj[key];
  25738. }
  25739. });
  25740. if (Object(underscore__WEBPACK_IMPORTED_MODULE_0__["isEmpty"])(obj.selectors)) delete obj.selectors;
  25741. if (Object(underscore__WEBPACK_IMPORTED_MODULE_0__["isEmpty"])(obj.style)) delete obj.style;
  25742. }
  25743. return obj;
  25744. },
  25745. /**
  25746. * Compare the actual model with parameters
  25747. * @param {Object} selectors Collection of selectors
  25748. * @param {String} state Css rule state
  25749. * @param {String} width For which device this style is oriented
  25750. * @param {Object} ruleProps Other rule props
  25751. * @return {Boolean}
  25752. * @private
  25753. */
  25754. compare: function compare(selectors, state, width) {
  25755. var ruleProps = arguments.length > 3 && arguments[3] !== undefined ? arguments[3] : {};
  25756. var st = state || '';
  25757. var wd = width || '';
  25758. var selectorsAdd = ruleProps.selectorsAdd || '';
  25759. var atRuleType = ruleProps.atRuleType || '';
  25760. var cId = 'cid'; //var a1 = _.pluck(selectors.models || selectors, cId);
  25761. //var a2 = _.pluck(this.get('selectors').models, cId);
  25762. if (!(selectors instanceof Array) && !selectors.models) selectors = [selectors];
  25763. var a1 = Object(underscore__WEBPACK_IMPORTED_MODULE_0__["map"])(selectors.models || selectors, function (model) {
  25764. return model.get('name');
  25765. });
  25766. var a2 = Object(underscore__WEBPACK_IMPORTED_MODULE_0__["map"])(this.get('selectors').models, function (model) {
  25767. return model.get('name');
  25768. });
  25769. var f = false;
  25770. if (a1.length !== a2.length) return f;
  25771. for (var i = 0; i < a1.length; i++) {
  25772. var re = 0;
  25773. for (var j = 0; j < a2.length; j++) {
  25774. if (a1[i] === a2[j]) re = 1;
  25775. }
  25776. if (re === 0) return f;
  25777. }
  25778. if (this.get('state') !== st || this.get('mediaText') !== wd || this.get('selectorsAdd') !== selectorsAdd || this.get('atRuleType') !== atRuleType) {
  25779. return f;
  25780. }
  25781. return true;
  25782. }
  25783. }));
  25784. /***/ }),
  25785. /***/ "./src/css_composer/model/CssRules.js":
  25786. /*!********************************************!*\
  25787. !*** ./src/css_composer/model/CssRules.js ***!
  25788. \********************************************/
  25789. /*! exports provided: default */
  25790. /***/ (function(module, __webpack_exports__, __webpack_require__) {
  25791. "use strict";
  25792. __webpack_require__.r(__webpack_exports__);
  25793. /* harmony import */ var backbone__WEBPACK_IMPORTED_MODULE_0__ = __webpack_require__(/*! backbone */ "./node_modules/backbone/backbone.js");
  25794. /* harmony import */ var backbone__WEBPACK_IMPORTED_MODULE_0___default = /*#__PURE__*/__webpack_require__.n(backbone__WEBPACK_IMPORTED_MODULE_0__);
  25795. /* harmony import */ var _CssRule__WEBPACK_IMPORTED_MODULE_1__ = __webpack_require__(/*! ./CssRule */ "./src/css_composer/model/CssRule.js");
  25796. /* harmony default export */ __webpack_exports__["default"] = (backbone__WEBPACK_IMPORTED_MODULE_0___default.a.Collection.extend({
  25797. model: _CssRule__WEBPACK_IMPORTED_MODULE_1__["default"],
  25798. initialize: function initialize(models, opt) {
  25799. var _this = this;
  25800. // Inject editor
  25801. if (opt && opt.em) this.editor = opt.em; // This will put the listener post CssComposer.postLoad
  25802. setTimeout(function () {
  25803. return _this.on('remove', _this.onRemove);
  25804. });
  25805. },
  25806. onRemove: function onRemove(removed) {
  25807. var em = this.editor;
  25808. em.stopListening(removed);
  25809. em.get('UndoManager').remove(removed);
  25810. },
  25811. add: function add(models) {
  25812. var opt = arguments.length > 1 && arguments[1] !== undefined ? arguments[1] : {};
  25813. if (typeof models === 'string') {
  25814. models = this.editor.get('Parser').parseCss(models);
  25815. }
  25816. opt.em = this.editor;
  25817. return backbone__WEBPACK_IMPORTED_MODULE_0___default.a.Collection.prototype.add.apply(this, [models, opt]);
  25818. }
  25819. }));
  25820. /***/ }),
  25821. /***/ "./src/css_composer/view/CssGroupRuleView.js":
  25822. /*!***************************************************!*\
  25823. !*** ./src/css_composer/view/CssGroupRuleView.js ***!
  25824. \***************************************************/
  25825. /*! exports provided: default */
  25826. /***/ (function(module, __webpack_exports__, __webpack_require__) {
  25827. "use strict";
  25828. __webpack_require__.r(__webpack_exports__);
  25829. /* harmony import */ var _CssRuleView__WEBPACK_IMPORTED_MODULE_0__ = __webpack_require__(/*! ./CssRuleView */ "./src/css_composer/view/CssRuleView.js");
  25830. /* harmony default export */ __webpack_exports__["default"] = (_CssRuleView__WEBPACK_IMPORTED_MODULE_0__["default"].extend({
  25831. _createElement: function _createElement(tagName) {
  25832. return document.createTextNode('');
  25833. },
  25834. render: function render() {
  25835. var model = this.model;
  25836. var important = model.get('important');
  25837. this.el.textContent = model.getDeclaration({
  25838. important: important
  25839. });
  25840. return this;
  25841. }
  25842. }));
  25843. /***/ }),
  25844. /***/ "./src/css_composer/view/CssRuleView.js":
  25845. /*!**********************************************!*\
  25846. !*** ./src/css_composer/view/CssRuleView.js ***!
  25847. \**********************************************/
  25848. /*! exports provided: default */
  25849. /***/ (function(module, __webpack_exports__, __webpack_require__) {
  25850. "use strict";
  25851. __webpack_require__.r(__webpack_exports__);
  25852. /* harmony import */ var backbone__WEBPACK_IMPORTED_MODULE_0__ = __webpack_require__(/*! backbone */ "./node_modules/backbone/backbone.js");
  25853. /* harmony import */ var backbone__WEBPACK_IMPORTED_MODULE_0___default = /*#__PURE__*/__webpack_require__.n(backbone__WEBPACK_IMPORTED_MODULE_0__);
  25854. /* harmony default export */ __webpack_exports__["default"] = (backbone__WEBPACK_IMPORTED_MODULE_0___default.a.View.extend({
  25855. tagName: 'style',
  25856. initialize: function initialize() {
  25857. var o = arguments.length > 0 && arguments[0] !== undefined ? arguments[0] : {};
  25858. this.config = o.config || {};
  25859. var model = this.model;
  25860. var toTrack = 'change:style change:state change:mediaText';
  25861. this.listenTo(model, toTrack, this.render);
  25862. this.listenTo(model, 'destroy remove', this.remove);
  25863. this.listenTo(model.get('selectors'), 'change', this.render);
  25864. },
  25865. render: function render() {
  25866. var model = this.model;
  25867. var important = model.get('important');
  25868. this.el.innerHTML = this.model.toCSS({
  25869. important: important
  25870. });
  25871. return this;
  25872. }
  25873. }));
  25874. /***/ }),
  25875. /***/ "./src/css_composer/view/CssRulesView.js":
  25876. /*!***********************************************!*\
  25877. !*** ./src/css_composer/view/CssRulesView.js ***!
  25878. \***********************************************/
  25879. /*! exports provided: default */
  25880. /***/ (function(module, __webpack_exports__, __webpack_require__) {
  25881. "use strict";
  25882. __webpack_require__.r(__webpack_exports__);
  25883. /* harmony import */ var backbone__WEBPACK_IMPORTED_MODULE_0__ = __webpack_require__(/*! backbone */ "./node_modules/backbone/backbone.js");
  25884. /* harmony import */ var backbone__WEBPACK_IMPORTED_MODULE_0___default = /*#__PURE__*/__webpack_require__.n(backbone__WEBPACK_IMPORTED_MODULE_0__);
  25885. /* harmony import */ var _CssRuleView__WEBPACK_IMPORTED_MODULE_1__ = __webpack_require__(/*! ./CssRuleView */ "./src/css_composer/view/CssRuleView.js");
  25886. /* harmony import */ var _CssGroupRuleView__WEBPACK_IMPORTED_MODULE_2__ = __webpack_require__(/*! ./CssGroupRuleView */ "./src/css_composer/view/CssGroupRuleView.js");
  25887. var $ = backbone__WEBPACK_IMPORTED_MODULE_0___default.a.$;
  25888. var getBlockId = function getBlockId(pfx, order) {
  25889. return "".concat(pfx).concat(order ? "-".concat(parseFloat(order)) : '');
  25890. };
  25891. /* harmony default export */ __webpack_exports__["default"] = (backbone__WEBPACK_IMPORTED_MODULE_0___default.a.View.extend({
  25892. initialize: function initialize(o) {
  25893. var config = o.config || {};
  25894. this.atRules = {};
  25895. this.config = config;
  25896. this.em = config.em;
  25897. this.pfx = config.stylePrefix || '';
  25898. this.className = this.pfx + 'rules';
  25899. var coll = this.collection;
  25900. this.listenTo(coll, 'add', this.addTo);
  25901. this.listenTo(coll, 'reset', this.render);
  25902. },
  25903. /**
  25904. * Add to collection
  25905. * @param {Object} model
  25906. * @private
  25907. * */
  25908. addTo: function addTo(model) {
  25909. this.addToCollection(model);
  25910. },
  25911. /**
  25912. * Add new object to collection
  25913. * @param {Object} model
  25914. * @param {Object} fragmentEl
  25915. * @return {Object}
  25916. * @private
  25917. * */
  25918. addToCollection: function addToCollection(model, fragmentEl) {
  25919. // If the render is not yet started
  25920. if (!this.renderStarted) {
  25921. return;
  25922. }
  25923. var fragment = fragmentEl || null;
  25924. var config = this.config;
  25925. var opts = {
  25926. model: model,
  25927. config: config
  25928. };
  25929. var rendered, view; // I have to render keyframes of the same name together
  25930. // Unfortunately at the moment I didn't find the way of appending them
  25931. // if not staticly, via appendData
  25932. if (model.get('atRuleType') === 'keyframes') {
  25933. var atRule = model.getAtRule();
  25934. var atRuleEl = this.atRules[atRule];
  25935. if (!atRuleEl) {
  25936. var styleEl = document.createElement('style');
  25937. atRuleEl = document.createTextNode('');
  25938. styleEl.appendChild(document.createTextNode("".concat(atRule, "{")));
  25939. styleEl.appendChild(atRuleEl);
  25940. styleEl.appendChild(document.createTextNode("}"));
  25941. this.atRules[atRule] = atRuleEl;
  25942. rendered = styleEl;
  25943. }
  25944. view = new _CssGroupRuleView__WEBPACK_IMPORTED_MODULE_2__["default"](opts);
  25945. atRuleEl.appendData(view.render().el.textContent);
  25946. } else {
  25947. view = new _CssRuleView__WEBPACK_IMPORTED_MODULE_1__["default"](opts);
  25948. rendered = view.render().el;
  25949. }
  25950. var clsName = this.className;
  25951. var mediaText = model.get('mediaText');
  25952. var defaultBlockId = getBlockId(clsName);
  25953. var blockId = defaultBlockId; // If the rule contains a media query it might have a different container
  25954. // for it (eg. rules created with Device Manager)
  25955. if (mediaText) {
  25956. blockId = getBlockId(clsName, this.getMediaWidth(mediaText));
  25957. }
  25958. if (rendered) {
  25959. var container = fragment || this.el;
  25960. var contRules; // Try to find a specific container for the rule (if it
  25961. // containes a media query), otherwise get the default one
  25962. try {
  25963. contRules = container.querySelector("#".concat(blockId));
  25964. } catch (e) {}
  25965. if (!contRules) {
  25966. contRules = container.querySelector("#".concat(defaultBlockId));
  25967. }
  25968. contRules.appendChild(rendered);
  25969. }
  25970. return rendered;
  25971. },
  25972. getMediaWidth: function getMediaWidth(mediaText) {
  25973. return mediaText && mediaText.replace("(".concat(this.em.getConfig('mediaCondition'), ": "), '').replace(')', '');
  25974. },
  25975. render: function render() {
  25976. var _this = this;
  25977. this.renderStarted = 1;
  25978. this.atRules = {};
  25979. var em = this.em,
  25980. $el = this.$el,
  25981. className = this.className,
  25982. collection = this.collection;
  25983. var frag = document.createDocumentFragment();
  25984. $el.empty(); // Create devices related DOM structure, ensure also to have a default container
  25985. var prs = em.get('DeviceManager').getAll().pluck('priority');
  25986. prs.every(function (pr) {
  25987. return pr;
  25988. }) && prs.unshift(0);
  25989. prs.forEach(function (pr) {
  25990. return $("<div id=\"".concat(getBlockId(className, pr), "\"></div>")).appendTo(frag);
  25991. });
  25992. collection.each(function (model) {
  25993. return _this.addToCollection(model, frag);
  25994. });
  25995. $el.append(frag);
  25996. $el.attr('class', className);
  25997. return this;
  25998. }
  25999. }));
  26000. /***/ }),
  26001. /***/ "./src/device_manager/config/config.js":
  26002. /*!*********************************************!*\
  26003. !*** ./src/device_manager/config/config.js ***!
  26004. \*********************************************/
  26005. /*! exports provided: default */
  26006. /***/ (function(module, __webpack_exports__, __webpack_require__) {
  26007. "use strict";
  26008. __webpack_require__.r(__webpack_exports__);
  26009. /* harmony default export */ __webpack_exports__["default"] = ({
  26010. devices: []
  26011. });
  26012. /***/ }),
  26013. /***/ "./src/device_manager/index.js":
  26014. /*!*************************************!*\
  26015. !*** ./src/device_manager/index.js ***!
  26016. \*************************************/
  26017. /*! exports provided: default */
  26018. /***/ (function(module, __webpack_exports__, __webpack_require__) {
  26019. "use strict";
  26020. __webpack_require__.r(__webpack_exports__);
  26021. /* harmony import */ var _babel_runtime_helpers_defineProperty__WEBPACK_IMPORTED_MODULE_0__ = __webpack_require__(/*! @babel/runtime/helpers/defineProperty */ "./node_modules/@babel/runtime/helpers/defineProperty.js");
  26022. /* harmony import */ var _babel_runtime_helpers_defineProperty__WEBPACK_IMPORTED_MODULE_0___default = /*#__PURE__*/__webpack_require__.n(_babel_runtime_helpers_defineProperty__WEBPACK_IMPORTED_MODULE_0__);
  26023. /* harmony import */ var _config_config__WEBPACK_IMPORTED_MODULE_1__ = __webpack_require__(/*! ./config/config */ "./src/device_manager/config/config.js");
  26024. /* harmony import */ var _model_Devices__WEBPACK_IMPORTED_MODULE_2__ = __webpack_require__(/*! ./model/Devices */ "./src/device_manager/model/Devices.js");
  26025. /* harmony import */ var _view_DevicesView__WEBPACK_IMPORTED_MODULE_3__ = __webpack_require__(/*! ./view/DevicesView */ "./src/device_manager/view/DevicesView.js");
  26026. function ownKeys(object, enumerableOnly) { var keys = Object.keys(object); if (Object.getOwnPropertySymbols) { var symbols = Object.getOwnPropertySymbols(object); if (enumerableOnly) symbols = symbols.filter(function (sym) { return Object.getOwnPropertyDescriptor(object, sym).enumerable; }); keys.push.apply(keys, symbols); } return keys; }
  26027. function _objectSpread(target) { for (var i = 1; i < arguments.length; i++) { var source = arguments[i] != null ? arguments[i] : {}; if (i % 2) { ownKeys(source, true).forEach(function (key) { _babel_runtime_helpers_defineProperty__WEBPACK_IMPORTED_MODULE_0___default()(target, key, source[key]); }); } else if (Object.getOwnPropertyDescriptors) { Object.defineProperties(target, Object.getOwnPropertyDescriptors(source)); } else { ownKeys(source).forEach(function (key) { Object.defineProperty(target, key, Object.getOwnPropertyDescriptor(source, key)); }); } } return target; }
  26028. /**
  26029. * You can customize the initial state of the module from the editor initialization, by passing the following [Configuration Object](https://github.com/artf/grapesjs/blob/master/src/device_manager/config/config.js)
  26030. * ```js
  26031. * const editor = grapesjs.init({
  26032. * deviceManager: {
  26033. * // options
  26034. * }
  26035. * })
  26036. * ```
  26037. *
  26038. * Once the editor is instantiated you can use its API. Before using these methods you should get the module from the instance
  26039. *
  26040. * ```js
  26041. * const deviceManager = editor.DeviceManager;
  26042. * ```
  26043. *
  26044. * * [add](#add)
  26045. * * [get](#get)
  26046. * * [getAll](#getAll)
  26047. *
  26048. * @module DeviceManager
  26049. */
  26050. /* harmony default export */ __webpack_exports__["default"] = (function () {
  26051. var c = {};
  26052. var devices, view;
  26053. return {
  26054. /**
  26055. * Name of the module
  26056. * @type {String}
  26057. * @private
  26058. */
  26059. name: 'DeviceManager',
  26060. /**
  26061. * Initialize module. Automatically called with a new instance of the editor
  26062. * @param {Object} config Configurations
  26063. * @param {Array<Object>} [config.devices=[]] Default devices
  26064. * @example
  26065. * ...
  26066. * {
  26067. * devices: [
  26068. * {name: 'Desktop', width: ''}
  26069. * {name: 'Tablet', width: '991px'}
  26070. * ],
  26071. * }
  26072. * ...
  26073. * @return {this}
  26074. * @private
  26075. */
  26076. init: function init(config) {
  26077. var _this = this;
  26078. c = config || {};
  26079. for (var name in _config_config__WEBPACK_IMPORTED_MODULE_1__["default"]) {
  26080. if (!(name in c)) c[name] = _config_config__WEBPACK_IMPORTED_MODULE_1__["default"][name];
  26081. }
  26082. devices = new _model_Devices__WEBPACK_IMPORTED_MODULE_2__["default"]();
  26083. (c.devices || []).forEach(function (dv) {
  26084. return _this.add(dv.id || dv.name, dv.width, dv);
  26085. });
  26086. view = new _view_DevicesView__WEBPACK_IMPORTED_MODULE_3__["default"]({
  26087. collection: devices,
  26088. config: c
  26089. });
  26090. return this;
  26091. },
  26092. /**
  26093. * Add new device to the collection. URLs are supposed to be unique
  26094. * @param {String} id Device id
  26095. * @param {String} width Width of the device
  26096. * @param {Object} [opts] Custom options
  26097. * @returns {Device} Added device
  26098. * @example
  26099. * deviceManager.add('tablet', '900px');
  26100. * deviceManager.add('tablet2', '900px', {
  26101. * height: '300px',
  26102. * // At first, GrapesJS tries to localize the name by device id.
  26103. * // In case is not found, the `name` property is used (or `id` if name is missing)
  26104. * name: 'Tablet 2',
  26105. * widthMedia: '810px', // the width that will be used for the CSS media
  26106. * });
  26107. */
  26108. add: function add(id, width) {
  26109. var opts = arguments.length > 2 && arguments[2] !== undefined ? arguments[2] : {};
  26110. var obj = _objectSpread({}, opts, {
  26111. id: id,
  26112. name: opts.name || id,
  26113. width: width
  26114. });
  26115. return devices.add(obj);
  26116. },
  26117. /**
  26118. * Return device by name
  26119. * @param {string} name Name of the device
  26120. * @example
  26121. * var device = deviceManager.get('Tablet');
  26122. * console.log(JSON.stringify(device));
  26123. * // {name: 'Tablet', width: '900px'}
  26124. */
  26125. get: function get(name) {
  26126. return devices.get(name);
  26127. },
  26128. /**
  26129. * Return all devices
  26130. * @return {Collection}
  26131. * @example
  26132. * var devices = deviceManager.getAll();
  26133. * console.log(JSON.stringify(devices));
  26134. * // [{name: 'Desktop', width: ''}, ...]
  26135. */
  26136. getAll: function getAll() {
  26137. return devices;
  26138. },
  26139. /**
  26140. * Render devices
  26141. * @return {string} HTML string
  26142. * @private
  26143. */
  26144. render: function render() {
  26145. return view.render().el;
  26146. }
  26147. };
  26148. });
  26149. /***/ }),
  26150. /***/ "./src/device_manager/model/Device.js":
  26151. /*!********************************************!*\
  26152. !*** ./src/device_manager/model/Device.js ***!
  26153. \********************************************/
  26154. /*! exports provided: default */
  26155. /***/ (function(module, __webpack_exports__, __webpack_require__) {
  26156. "use strict";
  26157. __webpack_require__.r(__webpack_exports__);
  26158. /* harmony import */ var backbone__WEBPACK_IMPORTED_MODULE_0__ = __webpack_require__(/*! backbone */ "./node_modules/backbone/backbone.js");
  26159. /* harmony import */ var backbone__WEBPACK_IMPORTED_MODULE_0___default = /*#__PURE__*/__webpack_require__.n(backbone__WEBPACK_IMPORTED_MODULE_0__);
  26160. /* harmony default export */ __webpack_exports__["default"] = (backbone__WEBPACK_IMPORTED_MODULE_0___default.a.Model.extend({
  26161. idAttribute: 'name',
  26162. defaults: {
  26163. name: '',
  26164. // Width to set for the editor iframe
  26165. width: null,
  26166. // Height to set for the editor iframe
  26167. height: '',
  26168. // The width which will be used in media queries,
  26169. // If empty the width will be used
  26170. widthMedia: null,
  26171. // Setup the order of media queries
  26172. priority: null
  26173. },
  26174. initialize: function initialize() {
  26175. var _this = this;
  26176. this.get('widthMedia') === null && this.set('widthMedia', this.get('width'));
  26177. this.get('width') === null && this.set('width', this.get('widthMedia'));
  26178. !this.get('priority') && this.set('priority', parseFloat(this.get('widthMedia')) || 0);
  26179. var toCheck = ['width', 'height', 'widthMedia'];
  26180. toCheck.forEach(function (prop) {
  26181. return _this.checkUnit(prop);
  26182. });
  26183. },
  26184. checkUnit: function checkUnit(prop) {
  26185. var pr = this.get(prop) || '';
  26186. var noUnit = (parseFloat(pr) || 0).toString() === pr.toString();
  26187. noUnit && this.set(prop, "".concat(pr, "px"));
  26188. }
  26189. }));
  26190. /***/ }),
  26191. /***/ "./src/device_manager/model/Devices.js":
  26192. /*!*********************************************!*\
  26193. !*** ./src/device_manager/model/Devices.js ***!
  26194. \*********************************************/
  26195. /*! exports provided: default */
  26196. /***/ (function(module, __webpack_exports__, __webpack_require__) {
  26197. "use strict";
  26198. __webpack_require__.r(__webpack_exports__);
  26199. /* harmony import */ var backbone__WEBPACK_IMPORTED_MODULE_0__ = __webpack_require__(/*! backbone */ "./node_modules/backbone/backbone.js");
  26200. /* harmony import */ var backbone__WEBPACK_IMPORTED_MODULE_0___default = /*#__PURE__*/__webpack_require__.n(backbone__WEBPACK_IMPORTED_MODULE_0__);
  26201. /* harmony import */ var _Device__WEBPACK_IMPORTED_MODULE_1__ = __webpack_require__(/*! ./Device */ "./src/device_manager/model/Device.js");
  26202. /* harmony default export */ __webpack_exports__["default"] = (backbone__WEBPACK_IMPORTED_MODULE_0___default.a.Collection.extend({
  26203. model: _Device__WEBPACK_IMPORTED_MODULE_1__["default"],
  26204. comparator: function comparator(left, right) {
  26205. var max = Number.MAX_VALUE;
  26206. return (right.get('priority') || max) - (left.get('priority') || max);
  26207. },
  26208. getSorted: function getSorted() {
  26209. return this.sort();
  26210. }
  26211. }));
  26212. /***/ }),
  26213. /***/ "./src/device_manager/view/DevicesView.js":
  26214. /*!************************************************!*\
  26215. !*** ./src/device_manager/view/DevicesView.js ***!
  26216. \************************************************/
  26217. /*! exports provided: default */
  26218. /***/ (function(module, __webpack_exports__, __webpack_require__) {
  26219. "use strict";
  26220. __webpack_require__.r(__webpack_exports__);
  26221. /* harmony import */ var underscore__WEBPACK_IMPORTED_MODULE_0__ = __webpack_require__(/*! underscore */ "./node_modules/underscore/underscore.js");
  26222. /* harmony import */ var underscore__WEBPACK_IMPORTED_MODULE_0___default = /*#__PURE__*/__webpack_require__.n(underscore__WEBPACK_IMPORTED_MODULE_0__);
  26223. /* harmony import */ var backbone__WEBPACK_IMPORTED_MODULE_1__ = __webpack_require__(/*! backbone */ "./node_modules/backbone/backbone.js");
  26224. /* harmony import */ var backbone__WEBPACK_IMPORTED_MODULE_1___default = /*#__PURE__*/__webpack_require__.n(backbone__WEBPACK_IMPORTED_MODULE_1__);
  26225. /* harmony default export */ __webpack_exports__["default"] = (backbone__WEBPACK_IMPORTED_MODULE_1___default.a.View.extend({
  26226. template: Object(underscore__WEBPACK_IMPORTED_MODULE_0__["template"])("\n <div class=\"<%= ppfx %>device-label\"><%= deviceLabel %></div>\n <div class=\"<%= ppfx %>field <%= ppfx %>select\">\n <span id=\"<%= ppfx %>input-holder\">\n <select class=\"<%= ppfx %>devices\"></select>\n </span>\n <div class=\"<%= ppfx %>sel-arrow\">\n <div class=\"<%= ppfx %>d-s-arrow\"></div>\n </div>\n </div>\n <button style=\"display:none\" class=\"<%= ppfx %>add-trasp\">+</button>"),
  26227. events: {
  26228. change: 'updateDevice'
  26229. },
  26230. initialize: function initialize(o) {
  26231. this.config = o.config || {};
  26232. this.em = this.config.em;
  26233. this.ppfx = this.config.pStylePrefix || '';
  26234. this.events['click .' + this.ppfx + 'add-trasp'] = this.startAdd;
  26235. this.listenTo(this.em, 'change:device', this.updateSelect);
  26236. this.delegateEvents();
  26237. },
  26238. /**
  26239. * Start adding new device
  26240. * @return {[type]} [description]
  26241. * @private
  26242. */
  26243. startAdd: function startAdd() {},
  26244. /**
  26245. * Update device of the editor
  26246. * @private
  26247. */
  26248. updateDevice: function updateDevice() {
  26249. var em = this.em;
  26250. if (em) {
  26251. var devEl = this.devicesEl;
  26252. var val = devEl ? devEl.val() : '';
  26253. em.set('device', val);
  26254. }
  26255. },
  26256. /**
  26257. * Update select value on device update
  26258. * @private
  26259. */
  26260. updateSelect: function updateSelect() {
  26261. var em = this.em;
  26262. var devEl = this.devicesEl;
  26263. if (em && em.getDeviceModel && devEl) {
  26264. var device = em.getDeviceModel();
  26265. var name = device ? device.get('name') : '';
  26266. devEl.val(name);
  26267. }
  26268. },
  26269. /**
  26270. * Return devices options
  26271. * @return {string} String of options
  26272. * @private
  26273. */
  26274. getOptions: function getOptions() {
  26275. var collection = this.collection,
  26276. em = this.em;
  26277. var result = '';
  26278. collection.each(function (device) {
  26279. var _device$attributes = device.attributes,
  26280. name = _device$attributes.name,
  26281. id = _device$attributes.id;
  26282. var label = em && em.t && em.t("deviceManager.devices.".concat(id)) || name;
  26283. result += "<option value=\"".concat(name, "\">").concat(label, "</option>");
  26284. });
  26285. return result;
  26286. },
  26287. render: function render() {
  26288. var em = this.em,
  26289. ppfx = this.ppfx,
  26290. $el = this.$el,
  26291. el = this.el;
  26292. $el.html(this.template({
  26293. ppfx: ppfx,
  26294. deviceLabel: em && em.t && em.t('deviceManager.device')
  26295. }));
  26296. this.devicesEl = $el.find(".".concat(ppfx, "devices"));
  26297. this.devicesEl.append(this.getOptions());
  26298. el.className = "".concat(ppfx, "devices-c");
  26299. return this;
  26300. }
  26301. }));
  26302. /***/ }),
  26303. /***/ "./src/dom_components/config/config.js":
  26304. /*!*********************************************!*\
  26305. !*** ./src/dom_components/config/config.js ***!
  26306. \*********************************************/
  26307. /*! exports provided: default */
  26308. /***/ (function(module, __webpack_exports__, __webpack_require__) {
  26309. "use strict";
  26310. __webpack_require__.r(__webpack_exports__);
  26311. /* harmony default export */ __webpack_exports__["default"] = ({
  26312. stylePrefix: 'comp-',
  26313. wrapperId: 'wrapper',
  26314. wrapperName: 'Body',
  26315. // Default wrapper configuration
  26316. wrapper: {
  26317. removable: false,
  26318. copyable: false,
  26319. draggable: false,
  26320. components: [],
  26321. traits: [],
  26322. stylable: ['background', 'background-color', 'background-image', 'background-repeat', 'background-attachment', 'background-position', 'background-size']
  26323. },
  26324. // Could be used for default components
  26325. components: [],
  26326. // If the component is draggable you can drag the component itself (not only from the toolbar)
  26327. draggableComponents: 1,
  26328. // Generally, if you don't edit the wrapper in the editor, like
  26329. // custom attributes, you don't need the wrapper stored in your JSON
  26330. // structure, but in case you need it you can use this option.
  26331. // If you have `config.avoidInlineStyle` disabled the wrapper will be stored
  26332. // as we need to store inlined style.
  26333. storeWrapper: 0,
  26334. /**
  26335. * You can setup a custom component definiton processor before adding it into the editor.
  26336. * It might be useful to transform custom objects (es. some framework specific JSX) to GrapesJS component one.
  26337. * This custom function will be executed on ANY new added component to the editor so make smart checks/conditions
  26338. * to avoid doing useless executions
  26339. * By default, GrapesJS supports already elements generated from React JSX preset
  26340. * @example
  26341. * processor: (obj) => {
  26342. * if (obj.$$typeof) { // eg. this is a React Element
  26343. * const gjsComponent = {
  26344. * type: obj.type,
  26345. * components: obj.props.children,
  26346. * ...
  26347. * };
  26348. * ...
  26349. * return gjsComponent;
  26350. * }
  26351. * }
  26352. */
  26353. processor: 0,
  26354. // List of void elements
  26355. voidElements: ['area', 'base', 'br', 'col', 'embed', 'hr', 'img', 'input', 'keygen', 'link', 'menuitem', 'meta', 'param', 'source', 'track', 'wbr']
  26356. });
  26357. /***/ }),
  26358. /***/ "./src/dom_components/index.js":
  26359. /*!*************************************!*\
  26360. !*** ./src/dom_components/index.js ***!
  26361. \*************************************/
  26362. /*! exports provided: default */
  26363. /***/ (function(module, __webpack_exports__, __webpack_require__) {
  26364. "use strict";
  26365. __webpack_require__.r(__webpack_exports__);
  26366. /* harmony import */ var _babel_runtime_helpers_typeof__WEBPACK_IMPORTED_MODULE_0__ = __webpack_require__(/*! @babel/runtime/helpers/typeof */ "./node_modules/@babel/runtime/helpers/typeof.js");
  26367. /* harmony import */ var _babel_runtime_helpers_typeof__WEBPACK_IMPORTED_MODULE_0___default = /*#__PURE__*/__webpack_require__.n(_babel_runtime_helpers_typeof__WEBPACK_IMPORTED_MODULE_0__);
  26368. /* harmony import */ var _babel_runtime_helpers_defineProperty__WEBPACK_IMPORTED_MODULE_1__ = __webpack_require__(/*! @babel/runtime/helpers/defineProperty */ "./node_modules/@babel/runtime/helpers/defineProperty.js");
  26369. /* harmony import */ var _babel_runtime_helpers_defineProperty__WEBPACK_IMPORTED_MODULE_1___default = /*#__PURE__*/__webpack_require__.n(_babel_runtime_helpers_defineProperty__WEBPACK_IMPORTED_MODULE_1__);
  26370. /* harmony import */ var backbone__WEBPACK_IMPORTED_MODULE_2__ = __webpack_require__(/*! backbone */ "./node_modules/backbone/backbone.js");
  26371. /* harmony import */ var backbone__WEBPACK_IMPORTED_MODULE_2___default = /*#__PURE__*/__webpack_require__.n(backbone__WEBPACK_IMPORTED_MODULE_2__);
  26372. /* harmony import */ var underscore__WEBPACK_IMPORTED_MODULE_3__ = __webpack_require__(/*! underscore */ "./node_modules/underscore/underscore.js");
  26373. /* harmony import */ var underscore__WEBPACK_IMPORTED_MODULE_3___default = /*#__PURE__*/__webpack_require__.n(underscore__WEBPACK_IMPORTED_MODULE_3__);
  26374. /* harmony import */ var _config_config__WEBPACK_IMPORTED_MODULE_4__ = __webpack_require__(/*! ./config/config */ "./src/dom_components/config/config.js");
  26375. /* harmony import */ var _model_Component__WEBPACK_IMPORTED_MODULE_5__ = __webpack_require__(/*! ./model/Component */ "./src/dom_components/model/Component.js");
  26376. /* harmony import */ var _model_Components__WEBPACK_IMPORTED_MODULE_6__ = __webpack_require__(/*! ./model/Components */ "./src/dom_components/model/Components.js");
  26377. /* harmony import */ var _view_ComponentView__WEBPACK_IMPORTED_MODULE_7__ = __webpack_require__(/*! ./view/ComponentView */ "./src/dom_components/view/ComponentView.js");
  26378. /* harmony import */ var _view_ComponentsView__WEBPACK_IMPORTED_MODULE_8__ = __webpack_require__(/*! ./view/ComponentsView */ "./src/dom_components/view/ComponentsView.js");
  26379. /* harmony import */ var _model_ComponentTableCell__WEBPACK_IMPORTED_MODULE_9__ = __webpack_require__(/*! ./model/ComponentTableCell */ "./src/dom_components/model/ComponentTableCell.js");
  26380. /* harmony import */ var _view_ComponentTableCellView__WEBPACK_IMPORTED_MODULE_10__ = __webpack_require__(/*! ./view/ComponentTableCellView */ "./src/dom_components/view/ComponentTableCellView.js");
  26381. /* harmony import */ var _model_ComponentTableRow__WEBPACK_IMPORTED_MODULE_11__ = __webpack_require__(/*! ./model/ComponentTableRow */ "./src/dom_components/model/ComponentTableRow.js");
  26382. /* harmony import */ var _view_ComponentTableRowView__WEBPACK_IMPORTED_MODULE_12__ = __webpack_require__(/*! ./view/ComponentTableRowView */ "./src/dom_components/view/ComponentTableRowView.js");
  26383. /* harmony import */ var _model_ComponentTable__WEBPACK_IMPORTED_MODULE_13__ = __webpack_require__(/*! ./model/ComponentTable */ "./src/dom_components/model/ComponentTable.js");
  26384. /* harmony import */ var _view_ComponentTableView__WEBPACK_IMPORTED_MODULE_14__ = __webpack_require__(/*! ./view/ComponentTableView */ "./src/dom_components/view/ComponentTableView.js");
  26385. /* harmony import */ var _model_ComponentTableHead__WEBPACK_IMPORTED_MODULE_15__ = __webpack_require__(/*! ./model/ComponentTableHead */ "./src/dom_components/model/ComponentTableHead.js");
  26386. /* harmony import */ var _view_ComponentTableHeadView__WEBPACK_IMPORTED_MODULE_16__ = __webpack_require__(/*! ./view/ComponentTableHeadView */ "./src/dom_components/view/ComponentTableHeadView.js");
  26387. /* harmony import */ var _model_ComponentTableBody__WEBPACK_IMPORTED_MODULE_17__ = __webpack_require__(/*! ./model/ComponentTableBody */ "./src/dom_components/model/ComponentTableBody.js");
  26388. /* harmony import */ var _view_ComponentTableBodyView__WEBPACK_IMPORTED_MODULE_18__ = __webpack_require__(/*! ./view/ComponentTableBodyView */ "./src/dom_components/view/ComponentTableBodyView.js");
  26389. /* harmony import */ var _model_ComponentTableFoot__WEBPACK_IMPORTED_MODULE_19__ = __webpack_require__(/*! ./model/ComponentTableFoot */ "./src/dom_components/model/ComponentTableFoot.js");
  26390. /* harmony import */ var _view_ComponentTableFootView__WEBPACK_IMPORTED_MODULE_20__ = __webpack_require__(/*! ./view/ComponentTableFootView */ "./src/dom_components/view/ComponentTableFootView.js");
  26391. /* harmony import */ var _model_ComponentMap__WEBPACK_IMPORTED_MODULE_21__ = __webpack_require__(/*! ./model/ComponentMap */ "./src/dom_components/model/ComponentMap.js");
  26392. /* harmony import */ var _view_ComponentMapView__WEBPACK_IMPORTED_MODULE_22__ = __webpack_require__(/*! ./view/ComponentMapView */ "./src/dom_components/view/ComponentMapView.js");
  26393. /* harmony import */ var _model_ComponentLink__WEBPACK_IMPORTED_MODULE_23__ = __webpack_require__(/*! ./model/ComponentLink */ "./src/dom_components/model/ComponentLink.js");
  26394. /* harmony import */ var _view_ComponentLinkView__WEBPACK_IMPORTED_MODULE_24__ = __webpack_require__(/*! ./view/ComponentLinkView */ "./src/dom_components/view/ComponentLinkView.js");
  26395. /* harmony import */ var _model_ComponentLabel__WEBPACK_IMPORTED_MODULE_25__ = __webpack_require__(/*! ./model/ComponentLabel */ "./src/dom_components/model/ComponentLabel.js");
  26396. /* harmony import */ var _view_ComponentLabelView__WEBPACK_IMPORTED_MODULE_26__ = __webpack_require__(/*! ./view/ComponentLabelView */ "./src/dom_components/view/ComponentLabelView.js");
  26397. /* harmony import */ var _model_ComponentVideo__WEBPACK_IMPORTED_MODULE_27__ = __webpack_require__(/*! ./model/ComponentVideo */ "./src/dom_components/model/ComponentVideo.js");
  26398. /* harmony import */ var _view_ComponentVideoView__WEBPACK_IMPORTED_MODULE_28__ = __webpack_require__(/*! ./view/ComponentVideoView */ "./src/dom_components/view/ComponentVideoView.js");
  26399. /* harmony import */ var _model_ComponentImage__WEBPACK_IMPORTED_MODULE_29__ = __webpack_require__(/*! ./model/ComponentImage */ "./src/dom_components/model/ComponentImage.js");
  26400. /* harmony import */ var _view_ComponentImageView__WEBPACK_IMPORTED_MODULE_30__ = __webpack_require__(/*! ./view/ComponentImageView */ "./src/dom_components/view/ComponentImageView.js");
  26401. /* harmony import */ var _model_ComponentScript__WEBPACK_IMPORTED_MODULE_31__ = __webpack_require__(/*! ./model/ComponentScript */ "./src/dom_components/model/ComponentScript.js");
  26402. /* harmony import */ var _view_ComponentScriptView__WEBPACK_IMPORTED_MODULE_32__ = __webpack_require__(/*! ./view/ComponentScriptView */ "./src/dom_components/view/ComponentScriptView.js");
  26403. /* harmony import */ var _model_ComponentSvg__WEBPACK_IMPORTED_MODULE_33__ = __webpack_require__(/*! ./model/ComponentSvg */ "./src/dom_components/model/ComponentSvg.js");
  26404. /* harmony import */ var _model_ComponentSvgIn__WEBPACK_IMPORTED_MODULE_34__ = __webpack_require__(/*! ./model/ComponentSvgIn */ "./src/dom_components/model/ComponentSvgIn.js");
  26405. /* harmony import */ var _view_ComponentSvgView__WEBPACK_IMPORTED_MODULE_35__ = __webpack_require__(/*! ./view/ComponentSvgView */ "./src/dom_components/view/ComponentSvgView.js");
  26406. /* harmony import */ var _model_ComponentComment__WEBPACK_IMPORTED_MODULE_36__ = __webpack_require__(/*! ./model/ComponentComment */ "./src/dom_components/model/ComponentComment.js");
  26407. /* harmony import */ var _view_ComponentCommentView__WEBPACK_IMPORTED_MODULE_37__ = __webpack_require__(/*! ./view/ComponentCommentView */ "./src/dom_components/view/ComponentCommentView.js");
  26408. /* harmony import */ var _model_ComponentTextNode__WEBPACK_IMPORTED_MODULE_38__ = __webpack_require__(/*! ./model/ComponentTextNode */ "./src/dom_components/model/ComponentTextNode.js");
  26409. /* harmony import */ var _view_ComponentTextNodeView__WEBPACK_IMPORTED_MODULE_39__ = __webpack_require__(/*! ./view/ComponentTextNodeView */ "./src/dom_components/view/ComponentTextNodeView.js");
  26410. /* harmony import */ var _model_ComponentText__WEBPACK_IMPORTED_MODULE_40__ = __webpack_require__(/*! ./model/ComponentText */ "./src/dom_components/model/ComponentText.js");
  26411. /* harmony import */ var _view_ComponentTextView__WEBPACK_IMPORTED_MODULE_41__ = __webpack_require__(/*! ./view/ComponentTextView */ "./src/dom_components/view/ComponentTextView.js");
  26412. /* harmony import */ var _model_ComponentWrapper__WEBPACK_IMPORTED_MODULE_42__ = __webpack_require__(/*! ./model/ComponentWrapper */ "./src/dom_components/model/ComponentWrapper.js");
  26413. function ownKeys(object, enumerableOnly) { var keys = Object.keys(object); if (Object.getOwnPropertySymbols) { var symbols = Object.getOwnPropertySymbols(object); if (enumerableOnly) symbols = symbols.filter(function (sym) { return Object.getOwnPropertyDescriptor(object, sym).enumerable; }); keys.push.apply(keys, symbols); } return keys; }
  26414. function _objectSpread(target) { for (var i = 1; i < arguments.length; i++) { var source = arguments[i] != null ? arguments[i] : {}; if (i % 2) { ownKeys(source, true).forEach(function (key) { _babel_runtime_helpers_defineProperty__WEBPACK_IMPORTED_MODULE_1___default()(target, key, source[key]); }); } else if (Object.getOwnPropertyDescriptors) { Object.defineProperties(target, Object.getOwnPropertyDescriptors(source)); } else { ownKeys(source).forEach(function (key) { Object.defineProperty(target, key, Object.getOwnPropertyDescriptor(source, key)); }); } } return target; }
  26415. /**
  26416. * With this module is possible to manage components inside the canvas. You can customize the initial state of the module from the editor initialization, by passing the following [Configuration Object](https://github.com/artf/grapesjs/blob/master/src/dom_components/config/config.js)
  26417. * ```js
  26418. * const editor = grapesjs.init({
  26419. * domComponents: {
  26420. * // options
  26421. * }
  26422. * })
  26423. * ```
  26424. *
  26425. * Once the editor is instantiated you can use its API. Before using these methods you should get the module from the instance
  26426. *
  26427. * ```js
  26428. * const domComponents = editor.DomComponents;
  26429. * ```
  26430. *
  26431. * * [getWrapper](#getwrapper)
  26432. * * [getComponents](#getcomponents)
  26433. * * [addComponent](#addcomponent)
  26434. * * [clear](#clear)
  26435. * * [load](#load)
  26436. * * [store](#store)
  26437. * * [addType](#addtype)
  26438. * * [getType](#gettype)
  26439. * * [getTypes](#gettypes)
  26440. * * [render](#render)
  26441. *
  26442. * @module DomComponents
  26443. */
  26444. /* harmony default export */ __webpack_exports__["default"] = (function () {
  26445. var c = {};
  26446. var em;
  26447. var componentsById = {};
  26448. var component, componentView;
  26449. var componentTypes = [{
  26450. id: 'cell',
  26451. model: _model_ComponentTableCell__WEBPACK_IMPORTED_MODULE_9__["default"],
  26452. view: _view_ComponentTableCellView__WEBPACK_IMPORTED_MODULE_10__["default"]
  26453. }, {
  26454. id: 'row',
  26455. model: _model_ComponentTableRow__WEBPACK_IMPORTED_MODULE_11__["default"],
  26456. view: _view_ComponentTableRowView__WEBPACK_IMPORTED_MODULE_12__["default"]
  26457. }, {
  26458. id: 'table',
  26459. model: _model_ComponentTable__WEBPACK_IMPORTED_MODULE_13__["default"],
  26460. view: _view_ComponentTableView__WEBPACK_IMPORTED_MODULE_14__["default"]
  26461. }, {
  26462. id: 'thead',
  26463. model: _model_ComponentTableHead__WEBPACK_IMPORTED_MODULE_15__["default"],
  26464. view: _view_ComponentTableHeadView__WEBPACK_IMPORTED_MODULE_16__["default"]
  26465. }, {
  26466. id: 'tbody',
  26467. model: _model_ComponentTableBody__WEBPACK_IMPORTED_MODULE_17__["default"],
  26468. view: _view_ComponentTableBodyView__WEBPACK_IMPORTED_MODULE_18__["default"]
  26469. }, {
  26470. id: 'tfoot',
  26471. model: _model_ComponentTableFoot__WEBPACK_IMPORTED_MODULE_19__["default"],
  26472. view: _view_ComponentTableFootView__WEBPACK_IMPORTED_MODULE_20__["default"]
  26473. }, {
  26474. id: 'map',
  26475. model: _model_ComponentMap__WEBPACK_IMPORTED_MODULE_21__["default"],
  26476. view: _view_ComponentMapView__WEBPACK_IMPORTED_MODULE_22__["default"]
  26477. }, {
  26478. id: 'link',
  26479. model: _model_ComponentLink__WEBPACK_IMPORTED_MODULE_23__["default"],
  26480. view: _view_ComponentLinkView__WEBPACK_IMPORTED_MODULE_24__["default"]
  26481. }, {
  26482. id: 'label',
  26483. model: _model_ComponentLabel__WEBPACK_IMPORTED_MODULE_25__["default"],
  26484. view: _view_ComponentLabelView__WEBPACK_IMPORTED_MODULE_26__["default"]
  26485. }, {
  26486. id: 'video',
  26487. model: _model_ComponentVideo__WEBPACK_IMPORTED_MODULE_27__["default"],
  26488. view: _view_ComponentVideoView__WEBPACK_IMPORTED_MODULE_28__["default"]
  26489. }, {
  26490. id: 'image',
  26491. model: _model_ComponentImage__WEBPACK_IMPORTED_MODULE_29__["default"],
  26492. view: _view_ComponentImageView__WEBPACK_IMPORTED_MODULE_30__["default"]
  26493. }, {
  26494. id: 'script',
  26495. model: _model_ComponentScript__WEBPACK_IMPORTED_MODULE_31__["default"],
  26496. view: _view_ComponentScriptView__WEBPACK_IMPORTED_MODULE_32__["default"]
  26497. }, {
  26498. id: 'svg-in',
  26499. model: _model_ComponentSvgIn__WEBPACK_IMPORTED_MODULE_34__["default"],
  26500. view: _view_ComponentSvgView__WEBPACK_IMPORTED_MODULE_35__["default"]
  26501. }, {
  26502. id: 'svg',
  26503. model: _model_ComponentSvg__WEBPACK_IMPORTED_MODULE_33__["default"],
  26504. view: _view_ComponentSvgView__WEBPACK_IMPORTED_MODULE_35__["default"]
  26505. }, {
  26506. id: 'comment',
  26507. model: _model_ComponentComment__WEBPACK_IMPORTED_MODULE_36__["default"],
  26508. view: _view_ComponentCommentView__WEBPACK_IMPORTED_MODULE_37__["default"]
  26509. }, {
  26510. id: 'textnode',
  26511. model: _model_ComponentTextNode__WEBPACK_IMPORTED_MODULE_38__["default"],
  26512. view: _view_ComponentTextNodeView__WEBPACK_IMPORTED_MODULE_39__["default"]
  26513. }, {
  26514. id: 'text',
  26515. model: _model_ComponentText__WEBPACK_IMPORTED_MODULE_40__["default"],
  26516. view: _view_ComponentTextView__WEBPACK_IMPORTED_MODULE_41__["default"]
  26517. }, {
  26518. id: 'wrapper',
  26519. model: _model_ComponentWrapper__WEBPACK_IMPORTED_MODULE_42__["default"],
  26520. view: _view_ComponentView__WEBPACK_IMPORTED_MODULE_7__["default"]
  26521. }, {
  26522. id: 'default',
  26523. model: _model_Component__WEBPACK_IMPORTED_MODULE_5__["default"],
  26524. view: _view_ComponentView__WEBPACK_IMPORTED_MODULE_7__["default"]
  26525. }];
  26526. return {
  26527. Component: _model_Component__WEBPACK_IMPORTED_MODULE_5__["default"],
  26528. Components: _model_Components__WEBPACK_IMPORTED_MODULE_6__["default"],
  26529. ComponentsView: _view_ComponentsView__WEBPACK_IMPORTED_MODULE_8__["default"],
  26530. componentTypes: componentTypes,
  26531. componentsById: componentsById,
  26532. /**
  26533. * Name of the module
  26534. * @type {String}
  26535. * @private
  26536. */
  26537. name: 'DomComponents',
  26538. /**
  26539. * Returns config
  26540. * @return {Object} Config object
  26541. * @private
  26542. */
  26543. getConfig: function getConfig() {
  26544. return c;
  26545. },
  26546. /**
  26547. * Mandatory for the storage manager
  26548. * @type {String}
  26549. * @private
  26550. */
  26551. storageKey: function storageKey() {
  26552. var keys = [];
  26553. var smc = c.stm && c.stm.getConfig() || {};
  26554. if (smc.storeHtml) keys.push('html');
  26555. if (smc.storeComponents) keys.push('components');
  26556. return keys;
  26557. },
  26558. /**
  26559. * Initialize module. Called on a new instance of the editor with configurations passed
  26560. * inside 'domComponents' field
  26561. * @param {Object} config Configurations
  26562. * @private
  26563. */
  26564. init: function init(config) {
  26565. var _this = this;
  26566. c = config || {};
  26567. em = c.em;
  26568. this.em = em;
  26569. if (em) {
  26570. c.components = em.config.components || c.components;
  26571. }
  26572. for (var name in _config_config__WEBPACK_IMPORTED_MODULE_4__["default"]) {
  26573. if (!(name in c)) c[name] = _config_config__WEBPACK_IMPORTED_MODULE_4__["default"][name];
  26574. }
  26575. var ppfx = c.pStylePrefix;
  26576. if (ppfx) c.stylePrefix = ppfx + c.stylePrefix; // Load dependencies
  26577. if (em) {
  26578. c.modal = em.get('Modal') || '';
  26579. c.am = em.get('AssetManager') || '';
  26580. em.get('Parser').compTypes = componentTypes;
  26581. em.on('change:componentHovered', this.componentHovered, this);
  26582. var selected = em.get('selected');
  26583. em.listenTo(selected, 'add', function (sel, c, opts) {
  26584. return _this.selectAdd(sel, opts);
  26585. });
  26586. em.listenTo(selected, 'remove', function (sel, c, opts) {
  26587. return _this.selectRemove(sel, opts);
  26588. });
  26589. } // Build wrapper
  26590. var components = c.components;
  26591. var wrapper = _objectSpread({}, c.wrapper);
  26592. wrapper['custom-name'] = c.wrapperName;
  26593. wrapper.wrapper = 1;
  26594. wrapper.type = 'wrapper'; // Components might be a wrapper
  26595. if (components && components.constructor === Object && components.wrapper) {
  26596. wrapper = _objectSpread({}, components);
  26597. components = components.components || [];
  26598. wrapper.components = []; // Have to put back the real object of components
  26599. if (em) {
  26600. em.config.components = components;
  26601. c.components = components;
  26602. }
  26603. }
  26604. component = new _model_Component__WEBPACK_IMPORTED_MODULE_5__["default"](wrapper, {
  26605. em: em,
  26606. config: c,
  26607. componentTypes: componentTypes,
  26608. domc: this
  26609. });
  26610. component.set({
  26611. attributes: {
  26612. id: 'wrapper'
  26613. }
  26614. });
  26615. componentView = new _view_ComponentView__WEBPACK_IMPORTED_MODULE_7__["default"]({
  26616. model: component,
  26617. config: c,
  26618. componentTypes: componentTypes
  26619. });
  26620. return this;
  26621. },
  26622. /**
  26623. * On load callback
  26624. * @private
  26625. */
  26626. onLoad: function onLoad() {
  26627. this.setComponents(c.components);
  26628. },
  26629. /**
  26630. * Do stuff after load
  26631. * @param {Editor} em
  26632. * @private
  26633. */
  26634. postLoad: function postLoad(em) {
  26635. this.handleChanges(this.getWrapper(), null, {
  26636. avoidStore: 1
  26637. });
  26638. },
  26639. /**
  26640. * Handle component changes
  26641. * @private
  26642. */
  26643. handleChanges: function handleChanges(model, value) {
  26644. var _this2 = this;
  26645. var opts = arguments.length > 2 && arguments[2] !== undefined ? arguments[2] : {};
  26646. var comps = model.components();
  26647. var um = em.get('UndoManager');
  26648. var handleUpdates = em.handleUpdates.bind(em);
  26649. var handleChanges = this.handleChanges.bind(this);
  26650. var handleChangesColl = this.handleChangesColl.bind(this);
  26651. var handleRemoves = this.handleRemoves.bind(this);
  26652. um && um.add(model);
  26653. um && comps && um.add(comps);
  26654. var evn = 'change:style change:content change:attributes change:src';
  26655. [[model, evn, handleUpdates], [model, 'change:components', handleChangesColl], [comps, 'add', handleChanges], [comps, 'remove', handleRemoves], [model.get('classes'), 'add remove', handleUpdates]].forEach(function (els) {
  26656. em.stopListening(els[0], els[1], els[2]);
  26657. em.listenTo(els[0], els[1], els[2]);
  26658. });
  26659. !opts.avoidStore && handleUpdates('', '', opts);
  26660. comps.each(function (model) {
  26661. return _this2.handleChanges(model, value, opts);
  26662. });
  26663. },
  26664. handleChangesColl: function handleChangesColl(model, coll) {
  26665. var um = em.get('UndoManager');
  26666. if (um && coll instanceof backbone__WEBPACK_IMPORTED_MODULE_2___default.a.Collection) {
  26667. var handleChanges = this.handleChanges.bind(this);
  26668. var handleRemoves = this.handleRemoves.bind(this);
  26669. um.add(coll);
  26670. [[coll, 'add', handleChanges], [coll, 'remove', handleRemoves]].forEach(function (els) {
  26671. em.stopListening(els[0], els[1], els[2]);
  26672. em.listenTo(els[0], els[1], els[2]);
  26673. });
  26674. }
  26675. },
  26676. /**
  26677. * Triggered when some component is removed
  26678. * @private
  26679. * */
  26680. handleRemoves: function handleRemoves(model, value) {
  26681. var opts = arguments.length > 2 && arguments[2] !== undefined ? arguments[2] : {};
  26682. !opts.avoidStore && em.handleUpdates(model, value, opts);
  26683. },
  26684. /**
  26685. * Load components from the passed object, if the object is empty will try to fetch them
  26686. * autonomously from the selected storage
  26687. * The fetched data will be added to the collection
  26688. * @param {Object} data Object of data to load
  26689. * @return {Object} Loaded data
  26690. */
  26691. load: function load() {
  26692. var data = arguments.length > 0 && arguments[0] !== undefined ? arguments[0] : '';
  26693. var em = this.em;
  26694. var result = '';
  26695. if (!data && c.stm) {
  26696. data = c.em.getCacheLoad();
  26697. }
  26698. var _data = data,
  26699. components = _data.components,
  26700. html = _data.html;
  26701. if (components) {
  26702. if (Object(underscore__WEBPACK_IMPORTED_MODULE_3__["isObject"])(components) || Object(underscore__WEBPACK_IMPORTED_MODULE_3__["isArray"])(components)) {
  26703. result = components;
  26704. } else {
  26705. try {
  26706. result = JSON.parse(components);
  26707. } catch (err) {
  26708. em && em.logError(err);
  26709. }
  26710. }
  26711. } else if (html) {
  26712. result = html;
  26713. }
  26714. var isObj = result && result.constructor === Object;
  26715. if (result && result.length || isObj) {
  26716. this.clear(); // If the result is an object I consider it the wrapper
  26717. if (isObj) {
  26718. this.getWrapper().set(result);
  26719. } else {
  26720. this.getComponents().add(result);
  26721. }
  26722. }
  26723. return result;
  26724. },
  26725. /**
  26726. * Store components on the selected storage
  26727. * @param {Boolean} noStore If true, won't store
  26728. * @return {Object} Data to store
  26729. */
  26730. store: function store(noStore) {
  26731. if (!c.stm) {
  26732. return;
  26733. }
  26734. var obj = {};
  26735. var keys = this.storageKey();
  26736. if (keys.indexOf('html') >= 0) {
  26737. obj.html = c.em.getHtml();
  26738. }
  26739. if (keys.indexOf('components') >= 0) {
  26740. var _em = this.em; // const storeWrap = (em && !em.getConfig('avoidInlineStyle')) || c.storeWrapper;
  26741. var storeWrap = c.storeWrapper;
  26742. var toStore = storeWrap ? this.getWrapper() : this.getComponents();
  26743. obj.components = JSON.stringify(toStore);
  26744. }
  26745. if (!noStore) {
  26746. c.stm.store(obj);
  26747. }
  26748. return obj;
  26749. },
  26750. /**
  26751. * Returns privately the main wrapper
  26752. * @return {Object}
  26753. * @private
  26754. */
  26755. getComponent: function getComponent() {
  26756. return component;
  26757. },
  26758. /**
  26759. * Returns root component inside the canvas. Something like `<body>` inside HTML page
  26760. * The wrapper doesn't differ from the original Component Model
  26761. * @return {Component} Root Component
  26762. * @example
  26763. * // Change background of the wrapper and set some attribute
  26764. * var wrapper = domComponents.getWrapper();
  26765. * wrapper.set('style', {'background-color': 'red'});
  26766. * wrapper.set('attributes', {'title': 'Hello!'});
  26767. */
  26768. getWrapper: function getWrapper() {
  26769. return this.getComponent();
  26770. },
  26771. /**
  26772. * Returns wrapper's children collection. Once you have the collection you can
  26773. * add other Components(Models) inside. Each component can have several nested
  26774. * components inside and you can nest them as more as you wish.
  26775. * @return {Components} Collection of components
  26776. * @example
  26777. * // Let's add some component
  26778. * var wrapperChildren = domComponents.getComponents();
  26779. * var comp1 = wrapperChildren.add({
  26780. * style: { 'background-color': 'red'}
  26781. * });
  26782. * var comp2 = wrapperChildren.add({
  26783. * tagName: 'span',
  26784. * attributes: { title: 'Hello!'}
  26785. * });
  26786. * // Now let's add an other one inside first component
  26787. * // First we have to get the collection inside. Each
  26788. * // component has 'components' property
  26789. * var comp1Children = comp1.get('components');
  26790. * // Procede as before. You could also add multiple objects
  26791. * comp1Children.add([
  26792. * { style: { 'background-color': 'blue'}},
  26793. * { style: { height: '100px', width: '100px'}}
  26794. * ]);
  26795. * // Remove comp2
  26796. * wrapperChildren.remove(comp2);
  26797. */
  26798. getComponents: function getComponents() {
  26799. return this.getWrapper().get('components');
  26800. },
  26801. /**
  26802. * Add new components to the wrapper's children. It's the same
  26803. * as 'domComponents.getComponents().add(...)'
  26804. * @param {Object|Component|Array<Object>} component Component/s to add
  26805. * @param {string} [component.tagName='div'] Tag name
  26806. * @param {string} [component.type=''] Type of the component. Available: ''(default), 'text', 'image'
  26807. * @param {boolean} [component.removable=true] If component is removable
  26808. * @param {boolean} [component.draggable=true] If is possible to move the component around the structure
  26809. * @param {boolean} [component.droppable=true] If is possible to drop inside other components
  26810. * @param {boolean} [component.badgable=true] If the badge is visible when the component is selected
  26811. * @param {boolean} [component.stylable=true] If is possible to style component
  26812. * @param {boolean} [component.copyable=true] If is possible to copy&paste the component
  26813. * @param {string} [component.content=''] String inside component
  26814. * @param {Object} [component.style={}] Style object
  26815. * @param {Object} [component.attributes={}] Attribute object
  26816. * @return {Component|Array<Component>} Component/s added
  26817. * @example
  26818. * // Example of a new component with some extra property
  26819. * var comp1 = domComponents.addComponent({
  26820. * tagName: 'div',
  26821. * removable: true, // Can't remove it
  26822. * draggable: true, // Can't move it
  26823. * copyable: true, // Disable copy/past
  26824. * content: 'Content text', // Text inside component
  26825. * style: { color: 'red'},
  26826. * attributes: { title: 'here' }
  26827. * });
  26828. */
  26829. addComponent: function addComponent(component) {
  26830. return this.getComponents().add(component);
  26831. },
  26832. /**
  26833. * Render and returns wrapper element with all components inside.
  26834. * Once the wrapper is rendered, and it's what happens when you init the editor,
  26835. * the all new components will be added automatically and property changes are all
  26836. * updated immediately
  26837. * @return {HTMLElement}
  26838. */
  26839. render: function render() {
  26840. return componentView.render().el;
  26841. },
  26842. /**
  26843. * Remove all components
  26844. * @return {this}
  26845. */
  26846. clear: function clear() {
  26847. this.getComponents().map(function (i) {
  26848. return i;
  26849. }).forEach(function (i) {
  26850. return i.remove();
  26851. });
  26852. return this;
  26853. },
  26854. /**
  26855. * Set components
  26856. * @param {Object|string} components HTML string or components model
  26857. * @return {this}
  26858. * @private
  26859. */
  26860. setComponents: function setComponents(components) {
  26861. this.clear().addComponent(components);
  26862. },
  26863. /**
  26864. * Add new component type.
  26865. * Read more about this in [Define New Component](https://grapesjs.com/docs/modules/Components.html#define-new-component)
  26866. * @param {string} type Component ID
  26867. * @param {Object} methods Component methods
  26868. * @return {this}
  26869. */
  26870. addType: function addType(type, methods) {
  26871. var em = this.em;
  26872. var _methods$model = methods.model,
  26873. model = _methods$model === void 0 ? {} : _methods$model,
  26874. _methods$view = methods.view,
  26875. view = _methods$view === void 0 ? {} : _methods$view,
  26876. isComponent = methods.isComponent,
  26877. extend = methods.extend,
  26878. extendView = methods.extendView,
  26879. _methods$extendFn = methods.extendFn,
  26880. extendFn = _methods$extendFn === void 0 ? [] : _methods$extendFn,
  26881. _methods$extendFnView = methods.extendFnView,
  26882. extendFnView = _methods$extendFnView === void 0 ? [] : _methods$extendFnView;
  26883. var compType = this.getType(type);
  26884. var extendType = this.getType(extend);
  26885. var extendViewType = this.getType(extendView);
  26886. var typeToExtend = extendType ? extendType : compType ? compType : this.getType('default');
  26887. var modelToExt = typeToExtend.model;
  26888. var viewToExt = extendViewType ? extendViewType.view : typeToExtend.view; // Function for extending source object methods
  26889. var getExtendedObj = function getExtendedObj(fns, target, srcToExt) {
  26890. return fns.reduce(function (res, next) {
  26891. var fn = target[next];
  26892. var parentFn = srcToExt.prototype[next];
  26893. if (fn && parentFn) {
  26894. res[next] = function () {
  26895. parentFn.bind(this).apply(void 0, arguments);
  26896. fn.bind(this).apply(void 0, arguments);
  26897. };
  26898. }
  26899. return res;
  26900. }, {});
  26901. }; // If the model/view is a simple object I need to extend it
  26902. if (_babel_runtime_helpers_typeof__WEBPACK_IMPORTED_MODULE_0___default()(model) === 'object') {
  26903. methods.model = modelToExt.extend(_objectSpread({}, model, {}, getExtendedObj(extendFn, model, modelToExt), {
  26904. defaults: _objectSpread({}, modelToExt.prototype.defaults, {}, Object(underscore__WEBPACK_IMPORTED_MODULE_3__["result"])(model, 'defaults') || {})
  26905. }), {
  26906. isComponent: compType && !extendType && !isComponent ? modelToExt.isComponent : isComponent || function () {
  26907. return 0;
  26908. }
  26909. });
  26910. }
  26911. if (_babel_runtime_helpers_typeof__WEBPACK_IMPORTED_MODULE_0___default()(view) === 'object') {
  26912. methods.view = viewToExt.extend(_objectSpread({}, view, {}, getExtendedObj(extendFnView, view, viewToExt)));
  26913. }
  26914. if (compType) {
  26915. compType.model = methods.model;
  26916. compType.view = methods.view;
  26917. } else {
  26918. methods.id = type;
  26919. componentTypes.unshift(methods);
  26920. }
  26921. var event = "component:type:".concat(compType ? 'update' : 'add');
  26922. em && em.trigger(event, compType || methods);
  26923. return this;
  26924. },
  26925. /**
  26926. * Get component type.
  26927. * Read more about this in [Define New Component](https://grapesjs.com/docs/modules/Components.html#define-new-component)
  26928. * @param {string} type Component ID
  26929. * @return {Object} Component type defintion, eg. `{ model: ..., view: ... }`
  26930. */
  26931. getType: function getType(type) {
  26932. var df = componentTypes;
  26933. for (var it = 0; it < df.length; it++) {
  26934. var dfId = df[it].id;
  26935. if (dfId == type) {
  26936. return df[it];
  26937. }
  26938. }
  26939. return;
  26940. },
  26941. /**
  26942. * Remove component type
  26943. * @param {string} type Component ID
  26944. * @returns {Object|undefined} Removed component type, undefined otherwise
  26945. */
  26946. removeType: function removeType(id) {
  26947. var df = componentTypes;
  26948. var type = this.getType(id);
  26949. if (!type) return;
  26950. var index = df.indexOf(type);
  26951. df.splice(index, 1);
  26952. return type;
  26953. },
  26954. /**
  26955. * Return the array of all types
  26956. * @return {Array}
  26957. */
  26958. getTypes: function getTypes() {
  26959. return componentTypes;
  26960. },
  26961. selectAdd: function selectAdd(component) {
  26962. var _this3 = this;
  26963. var opts = arguments.length > 1 && arguments[1] !== undefined ? arguments[1] : {};
  26964. if (component) {
  26965. component.set({
  26966. status: 'selected'
  26967. });
  26968. ['component:selected', 'component:toggled'].forEach(function (event) {
  26969. return _this3.em.trigger(event, component, opts);
  26970. });
  26971. }
  26972. },
  26973. selectRemove: function selectRemove(component) {
  26974. var _this4 = this;
  26975. var opts = arguments.length > 1 && arguments[1] !== undefined ? arguments[1] : {};
  26976. if (component) {
  26977. var _em2 = this.em;
  26978. component.set({
  26979. status: '',
  26980. state: ''
  26981. });
  26982. ['component:deselected', 'component:toggled'].forEach(function (event) {
  26983. return _this4.em.trigger(event, component, opts);
  26984. });
  26985. }
  26986. },
  26987. /**
  26988. * Triggered when the component is hovered
  26989. * @private
  26990. */
  26991. componentHovered: function componentHovered() {
  26992. var em = c.em;
  26993. var model = em.get('componentHovered');
  26994. var previous = em.previous('componentHovered');
  26995. var state = 'hovered'; // Deselect the previous component
  26996. previous && previous.get('status') == state && previous.set({
  26997. status: '',
  26998. state: ''
  26999. });
  27000. model && Object(underscore__WEBPACK_IMPORTED_MODULE_3__["isEmpty"])(model.get('status')) && model.set('status', state);
  27001. },
  27002. allById: function allById() {
  27003. return componentsById;
  27004. }
  27005. };
  27006. });
  27007. /***/ }),
  27008. /***/ "./src/dom_components/model/Component.js":
  27009. /*!***********************************************!*\
  27010. !*** ./src/dom_components/model/Component.js ***!
  27011. \***********************************************/
  27012. /*! exports provided: eventDrag, default */
  27013. /***/ (function(module, __webpack_exports__, __webpack_require__) {
  27014. "use strict";
  27015. __webpack_require__.r(__webpack_exports__);
  27016. /* harmony export (binding) */ __webpack_require__.d(__webpack_exports__, "eventDrag", function() { return eventDrag; });
  27017. /* harmony import */ var _babel_runtime_helpers_typeof__WEBPACK_IMPORTED_MODULE_0__ = __webpack_require__(/*! @babel/runtime/helpers/typeof */ "./node_modules/@babel/runtime/helpers/typeof.js");
  27018. /* harmony import */ var _babel_runtime_helpers_typeof__WEBPACK_IMPORTED_MODULE_0___default = /*#__PURE__*/__webpack_require__.n(_babel_runtime_helpers_typeof__WEBPACK_IMPORTED_MODULE_0__);
  27019. /* harmony import */ var _babel_runtime_helpers_defineProperty__WEBPACK_IMPORTED_MODULE_1__ = __webpack_require__(/*! @babel/runtime/helpers/defineProperty */ "./node_modules/@babel/runtime/helpers/defineProperty.js");
  27020. /* harmony import */ var _babel_runtime_helpers_defineProperty__WEBPACK_IMPORTED_MODULE_1___default = /*#__PURE__*/__webpack_require__.n(_babel_runtime_helpers_defineProperty__WEBPACK_IMPORTED_MODULE_1__);
  27021. /* harmony import */ var underscore__WEBPACK_IMPORTED_MODULE_2__ = __webpack_require__(/*! underscore */ "./node_modules/underscore/underscore.js");
  27022. /* harmony import */ var underscore__WEBPACK_IMPORTED_MODULE_2___default = /*#__PURE__*/__webpack_require__.n(underscore__WEBPACK_IMPORTED_MODULE_2__);
  27023. /* harmony import */ var utils_mixins__WEBPACK_IMPORTED_MODULE_3__ = __webpack_require__(/*! utils/mixins */ "./src/utils/mixins.js");
  27024. /* harmony import */ var domain_abstract_model_Styleable__WEBPACK_IMPORTED_MODULE_4__ = __webpack_require__(/*! domain_abstract/model/Styleable */ "./src/domain_abstract/model/Styleable.js");
  27025. /* harmony import */ var backbone__WEBPACK_IMPORTED_MODULE_5__ = __webpack_require__(/*! backbone */ "./node_modules/backbone/backbone.js");
  27026. /* harmony import */ var backbone__WEBPACK_IMPORTED_MODULE_5___default = /*#__PURE__*/__webpack_require__.n(backbone__WEBPACK_IMPORTED_MODULE_5__);
  27027. /* harmony import */ var _Components__WEBPACK_IMPORTED_MODULE_6__ = __webpack_require__(/*! ./Components */ "./src/dom_components/model/Components.js");
  27028. /* harmony import */ var selector_manager_model_Selector__WEBPACK_IMPORTED_MODULE_7__ = __webpack_require__(/*! selector_manager/model/Selector */ "./src/selector_manager/model/Selector.js");
  27029. /* harmony import */ var selector_manager_model_Selectors__WEBPACK_IMPORTED_MODULE_8__ = __webpack_require__(/*! selector_manager/model/Selectors */ "./src/selector_manager/model/Selectors.js");
  27030. /* harmony import */ var trait_manager_model_Traits__WEBPACK_IMPORTED_MODULE_9__ = __webpack_require__(/*! trait_manager/model/Traits */ "./src/trait_manager/model/Traits.js");
  27031. function ownKeys(object, enumerableOnly) { var keys = Object.keys(object); if (Object.getOwnPropertySymbols) { var symbols = Object.getOwnPropertySymbols(object); if (enumerableOnly) symbols = symbols.filter(function (sym) { return Object.getOwnPropertyDescriptor(object, sym).enumerable; }); keys.push.apply(keys, symbols); } return keys; }
  27032. function _objectSpread(target) { for (var i = 1; i < arguments.length; i++) { var source = arguments[i] != null ? arguments[i] : {}; if (i % 2) { ownKeys(source, true).forEach(function (key) { _babel_runtime_helpers_defineProperty__WEBPACK_IMPORTED_MODULE_1___default()(target, key, source[key]); }); } else if (Object.getOwnPropertyDescriptors) { Object.defineProperties(target, Object.getOwnPropertyDescriptors(source)); } else { ownKeys(source).forEach(function (key) { Object.defineProperty(target, key, Object.getOwnPropertyDescriptor(source, key)); }); } } return target; }
  27033. var componentList = {};
  27034. var componentIndex = 0;
  27035. var escapeRegExp = function escapeRegExp(str) {
  27036. return str.replace(/[|\\{}()[\]^$+*?.]/g, '\\$&');
  27037. };
  27038. var avoidInline = function avoidInline(em) {
  27039. return em && em.getConfig('avoidInlineStyle');
  27040. };
  27041. var eventDrag = 'component:drag';
  27042. /**
  27043. * The Component object represents a single node of our template structure, so when you update its properties the changes are
  27044. * immediately reflected on the canvas and in the code to export (indeed, when you ask to export the code we just go through all
  27045. * the tree of nodes).
  27046. * An example on how to update properties:
  27047. * ```js
  27048. * component.set({
  27049. * tagName: 'span',
  27050. * attributes: { ... },
  27051. * removable: false,
  27052. * });
  27053. * component.get('tagName');
  27054. * // -> 'span'
  27055. * ```
  27056. *
  27057. * @typedef Component
  27058. * @property {String} [type=''] Component type, eg. `text`, `image`, `video`, etc.
  27059. * @property {String} [tagName='div'] HTML tag of the component, eg. `span`. Default: `div`
  27060. * @property {Object} [attributes={}] Key-value object of the component's attributes, eg. `{ title: 'Hello' }` Default: `{}`
  27061. * @property {String} [name=''] Name of the component. Will be used, for example, in Layers and badges
  27062. * @property {Boolean} [removable=true] When `true` the component is removable from the canvas, default: `true`
  27063. * @property {Boolean|String} [draggable=true] Indicates if it's possible to drag the component inside others.
  27064. * You can also specify a query string to indentify elements,
  27065. * eg. `'.some-class[title=Hello], [data-gjs-type=column]'` means you can drag the component only inside elements
  27066. * containing `some-class` class and `Hello` title, and `column` components. Default: `true`
  27067. * @property {Boolean|String} [droppable=true] Indicates if it's possible to drop other components inside. You can use
  27068. * a query string as with `draggable`. Default: `true`
  27069. * @property {Boolean} [badgable=true] Set to false if you don't want to see the badge (with the name) over the component. Default: `true`
  27070. * @property {Boolean|Array<String>} [stylable=true] True if it's possible to style the component.
  27071. * You can also indicate an array of CSS properties which is possible to style, eg. `['color', 'width']`, all other properties
  27072. * will be hidden from the style manager. Default: `true`
  27073. * @property {Array<String>} [stylable-require=[]] Indicate an array of style properties to show up which has been marked as `toRequire`. Default: `[]`
  27074. * @property {Array<String>} [unstylable=[]] Indicate an array of style properties which should be hidden from the style manager. Default: `[]`
  27075. * @property {Array<String>} [style-signature=''] This option comes handy when you need to remove or export strictly component-specific rules. Be default, if this option is not empty, the editor will remove rules when there are no components, of that type, in the canvas. Eg. '['.navbar', '[navbar-']'. Default: `''`
  27076. * @property {Boolean} [highlightable=true] It can be highlighted with 'dotted' borders if true. Default: `true`
  27077. * @property {Boolean} [copyable=true] True if it's possible to clone the component. Default: `true`
  27078. * @property {Boolean} [resizable=false] Indicates if it's possible to resize the component. It's also possible to pass an object as [options for the Resizer](https://github.com/artf/grapesjs/blob/master/src/utils/Resizer.js). Default: `false`
  27079. * @property {Boolean} [editable=false] Allow to edit the content of the component (used on Text components). Default: `false`
  27080. * @property {Boolean} [layerable=true] Set to `false` if you need to hide the component inside Layers. Default: `true`
  27081. * @property {Boolean} [selectable=true] Allow component to be selected when clicked. Default: `true`
  27082. * @property {Boolean} [hoverable=true] Shows a highlight outline when hovering on the element if `true`. Default: `true`
  27083. * @property {Boolean} [void=false] This property is used by the HTML exporter as void elements don't have closing tags, eg. `<br/>`, `<hr/>`, etc. Default: `false`
  27084. * @property {String} [content=''] Content of the component (not escaped) which will be appended before children rendering. Default: `''`
  27085. * @property {String} [icon=''] Component's icon, this string will be inserted before the name (in Layers and badge), eg. it can be an HTML string '<i class="fa fa-square-o"></i>'. Default: `''`
  27086. * @property {String|Function} [script=''] Component's javascript. More about it [here](/modules/Components-js.html). Default: `''`
  27087. * @property {String|Function} [script-export=''] You can specify javascript available only in export functions (eg. when you get the HTML).
  27088. * If this property is defined it will overwrite the `script` one (in export functions). Default: `''`
  27089. * @property {Array<Object|String>} [traits=''] Component's traits. More about it [here](/modules/Traits.html). Default: `['id', 'title']`
  27090. * @property {Array<String>} [propagate=[]] Indicates an array of properties which will be inhereted by all NEW appended children.
  27091. * For example if you create a component likes this: `{ removable: false, draggable: false, propagate: ['removable', 'draggable'] }`
  27092. * and append some new component inside, the new added component will get the exact same properties indicated in the `propagate` array (and the `propagate` property itself). Default: `[]`
  27093. * @property {Array<Object>} [toolbar=null] Set an array of items to show up inside the toolbar when the component is selected (move, clone, delete).
  27094. * Eg. `toolbar: [ { attributes: {class: 'fa fa-arrows'}, command: 'tlb-move' }, ... ]`.
  27095. * By default, when `toolbar` property is falsy the editor will add automatically commands like `move`, `delete`, etc. based on its properties.
  27096. * @property {Collection<Component>} [components=null] Children components. Default: `null`
  27097. */
  27098. var Component = backbone__WEBPACK_IMPORTED_MODULE_5___default.a.Model.extend(domain_abstract_model_Styleable__WEBPACK_IMPORTED_MODULE_4__["default"]).extend({
  27099. defaults: {
  27100. tagName: 'div',
  27101. type: '',
  27102. name: '',
  27103. removable: true,
  27104. draggable: true,
  27105. droppable: true,
  27106. badgable: true,
  27107. stylable: true,
  27108. 'stylable-require': '',
  27109. 'style-signature': '',
  27110. unstylable: '',
  27111. highlightable: true,
  27112. copyable: true,
  27113. resizable: false,
  27114. editable: false,
  27115. layerable: true,
  27116. selectable: true,
  27117. hoverable: true,
  27118. void: false,
  27119. state: '',
  27120. // Indicates if the component is in some CSS state like ':hover', ':active', etc.
  27121. status: '',
  27122. // State, eg. 'selected'
  27123. content: '',
  27124. icon: '',
  27125. style: '',
  27126. // Component related style
  27127. classes: '',
  27128. // Array of classes
  27129. script: '',
  27130. 'script-export': '',
  27131. attributes: '',
  27132. traits: ['id', 'title'],
  27133. propagate: '',
  27134. dmode: '',
  27135. toolbar: null
  27136. },
  27137. /**
  27138. * Hook method, called once the model is created
  27139. */
  27140. init: function init() {},
  27141. /**
  27142. * Hook method, called when the model has been updated (eg. updated some model's property)
  27143. * @param {String} property Property name, if triggered after some property update
  27144. * @param {*} value Property value, if triggered after some property update
  27145. * @param {*} previous Property previous value, if triggered after some property update
  27146. */
  27147. updated: function updated(property, value, previous) {},
  27148. /**
  27149. * Hook method, called once the model has been removed
  27150. */
  27151. removed: function removed() {},
  27152. initialize: function initialize() {
  27153. var _this = this;
  27154. var props = arguments.length > 0 && arguments[0] !== undefined ? arguments[0] : {};
  27155. var opt = arguments.length > 1 && arguments[1] !== undefined ? arguments[1] : {};
  27156. var em = opt.em; // Propagate properties from parent if indicated
  27157. var parent = this.parent();
  27158. var parentAttr = parent && parent.attributes;
  27159. if (parentAttr && parentAttr.propagate) {
  27160. var newAttr = {};
  27161. var toPropagate = parentAttr.propagate;
  27162. toPropagate.forEach(function (prop) {
  27163. return newAttr[prop] = parent.get(prop);
  27164. });
  27165. newAttr.propagate = toPropagate;
  27166. newAttr = _objectSpread({}, newAttr, {}, props);
  27167. this.set(newAttr);
  27168. }
  27169. var propagate = this.get('propagate');
  27170. propagate && this.set('propagate', Object(underscore__WEBPACK_IMPORTED_MODULE_2__["isArray"])(propagate) ? propagate : [propagate]); // Check void elements
  27171. if (opt && opt.config && opt.config.voidElements.indexOf(this.get('tagName')) >= 0) {
  27172. this.set('void', true);
  27173. }
  27174. opt.em = em;
  27175. this.opt = opt;
  27176. this.em = em;
  27177. this.frame = opt.frame;
  27178. this.config = opt.config || {};
  27179. this.set('attributes', _objectSpread({}, this.defaults.attributes || {}, {}, this.get('attributes') || {}));
  27180. this.ccid = Component.createId(this);
  27181. this.initClasses();
  27182. this.initTraits();
  27183. this.initComponents();
  27184. this.initToolbar();
  27185. this.listenTo(this, 'change:script', this.scriptUpdated);
  27186. this.listenTo(this, 'change:tagName', this.tagUpdated);
  27187. this.listenTo(this, 'change:attributes', this.attrUpdated);
  27188. this.listenTo(this, 'change:attributes:id', this._idUpdated);
  27189. this.set('status', '');
  27190. this.views = []; // Register global updates for collection properties
  27191. ['classes', 'traits', 'components'].forEach(function (name) {
  27192. var events = "add remove ".concat(name !== 'components' ? 'change' : '');
  27193. _this.listenTo(_this.get(name), events.trim(), function () {
  27194. for (var _len = arguments.length, args = new Array(_len), _key = 0; _key < _len; _key++) {
  27195. args[_key] = arguments[_key];
  27196. }
  27197. return _this.emitUpdate.apply(_this, [name].concat(args));
  27198. });
  27199. });
  27200. if (!opt.temporary) {
  27201. this.init();
  27202. em && em.trigger('component:create', this);
  27203. }
  27204. },
  27205. /**
  27206. * Check component's type
  27207. * @param {string} type Component type
  27208. * @return {Boolean}
  27209. * @example
  27210. * component.is('image')
  27211. * // -> false
  27212. */
  27213. is: function is(type) {
  27214. return !!(this.get('type') == type);
  27215. },
  27216. /**
  27217. * Return all the propeties
  27218. * @returns {Object}
  27219. */
  27220. props: function props() {
  27221. return this.attributes;
  27222. },
  27223. /**
  27224. * Get the index of the component in the parent collection.
  27225. * @return {Number}
  27226. */
  27227. index: function index() {
  27228. var collection = this.collection;
  27229. return collection && collection.indexOf(this);
  27230. },
  27231. /**
  27232. * Change the drag mode of the component.
  27233. * To get more about this feature read: https://github.com/artf/grapesjs/issues/1936
  27234. * @param {String} value Drag mode, options: 'absolute' | 'translate'
  27235. * @returns {this}
  27236. */
  27237. setDragMode: function setDragMode(value) {
  27238. return this.set('dmode', value);
  27239. },
  27240. /**
  27241. * Find inner components by query string.
  27242. * **ATTENTION**: this method works only with already rendered component
  27243. * @param {String} query Query string
  27244. * @return {Array} Array of components
  27245. * @example
  27246. * component.find('div > .class');
  27247. * // -> [Component, Component, ...]
  27248. */
  27249. find: function find(query) {
  27250. var result = [];
  27251. var $els = this.view.$el.find(query);
  27252. $els.each(function (i) {
  27253. var $el = $els.eq(i);
  27254. var model = $el.data('model');
  27255. model && result.push(model);
  27256. });
  27257. return result;
  27258. },
  27259. /**
  27260. * Find all inner components by component type.
  27261. * The advantage of this method over `find` is that you can use it
  27262. * also before rendering the component
  27263. * @param {String} type Component type
  27264. * @returns {Array<Component>}
  27265. * @example
  27266. * const allImages = component.findType('image');
  27267. * console.log(allImages[0]) // prints the first found component
  27268. */
  27269. findType: function findType(type) {
  27270. var result = [];
  27271. var find = function find(components) {
  27272. return components.forEach(function (item) {
  27273. item.is(type) && result.push(item);
  27274. find(item.components());
  27275. });
  27276. };
  27277. find(this.components());
  27278. return result;
  27279. },
  27280. /**
  27281. * Find the closest parent component by query string.
  27282. * **ATTENTION**: this method works only with already rendered component
  27283. * @param {string} query Query string
  27284. * @return {Component}
  27285. * @example
  27286. * component.closest('div.some-class');
  27287. * // -> Component
  27288. */
  27289. closest: function closest(query) {
  27290. var result = this.view.$el.closest(query);
  27291. return result.length && result.data('model');
  27292. },
  27293. /**
  27294. * Find the closest parent component by its type.
  27295. * The advantage of this method over `closest` is that you can use it
  27296. * also before rendering the component
  27297. * @param {String} type Component type
  27298. * @returns {Component} Found component, otherwise `undefined`
  27299. * @example
  27300. * const Section = component.closestType('section');
  27301. * console.log(Section);
  27302. */
  27303. closestType: function closestType(type) {
  27304. var parent = this.parent();
  27305. while (parent && !parent.is(type)) {
  27306. parent = parent.parent();
  27307. }
  27308. return parent;
  27309. },
  27310. /**
  27311. * Once the tag is updated I have to remove the node and replace it
  27312. * @private
  27313. */
  27314. tagUpdated: function tagUpdated() {
  27315. var coll = this.collection;
  27316. var at = coll.indexOf(this);
  27317. coll.remove(this);
  27318. coll.add(this, {
  27319. at: at
  27320. });
  27321. },
  27322. /**
  27323. * Replace a component with another one
  27324. * @param {String|Component} el Component or HTML string
  27325. * @return {Component|Array<Component>} New added component/s
  27326. * @example
  27327. * component.replaceWith('<div>Some new content</div>');
  27328. * // -> Component
  27329. */
  27330. replaceWith: function replaceWith(el) {
  27331. var coll = this.collection;
  27332. var at = coll.indexOf(this);
  27333. coll.remove(this);
  27334. return coll.add(el, {
  27335. at: at
  27336. });
  27337. },
  27338. /**
  27339. * Emit changes for each updated attribute
  27340. * @private
  27341. */
  27342. attrUpdated: function attrUpdated(m, v) {
  27343. var _this2 = this;
  27344. var opts = arguments.length > 2 && arguments[2] !== undefined ? arguments[2] : {};
  27345. var attrs = this.get('attributes'); // Handle classes
  27346. var classes = attrs.class;
  27347. classes && this.setClass(classes);
  27348. delete attrs.class; // Handle style
  27349. var style = attrs.style;
  27350. style && this.setStyle(style);
  27351. delete attrs.style;
  27352. var attrPrev = _objectSpread({}, this.previous('attributes'));
  27353. var diff = Object(utils_mixins__WEBPACK_IMPORTED_MODULE_3__["shallowDiff"])(attrPrev, this.get('attributes'));
  27354. Object(underscore__WEBPACK_IMPORTED_MODULE_2__["keys"])(diff).forEach(function (pr) {
  27355. return _this2.trigger("change:attributes:".concat(pr), _this2, diff[pr], opts);
  27356. });
  27357. },
  27358. /**
  27359. * Update attributes of the component
  27360. * @param {Object} attrs Key value attributes
  27361. * @return {this}
  27362. * @example
  27363. * component.setAttributes({ id: 'test', 'data-key': 'value' });
  27364. */
  27365. setAttributes: function setAttributes(attrs) {
  27366. var opts = arguments.length > 1 && arguments[1] !== undefined ? arguments[1] : {};
  27367. this.set('attributes', _objectSpread({}, attrs), opts);
  27368. return this;
  27369. },
  27370. /**
  27371. * Add attributes to the component
  27372. * @param {Object} attrs Key value attributes
  27373. * @return {this}
  27374. * @example
  27375. * component.addAttributes({ 'data-key': 'value' });
  27376. */
  27377. addAttributes: function addAttributes(attrs) {
  27378. var newAttrs = _objectSpread({}, this.getAttributes(), {}, attrs);
  27379. this.setAttributes(newAttrs);
  27380. return this;
  27381. },
  27382. /**
  27383. * Get the style of the component
  27384. * @return {Object}
  27385. */
  27386. getStyle: function getStyle() {
  27387. var em = this.em;
  27388. if (em && em.getConfig('avoidInlineStyle')) {
  27389. var state = em.get('state');
  27390. var cc = em.get('CssComposer');
  27391. var rule = cc.getIdRule(this.getId(), {
  27392. state: state
  27393. });
  27394. this.rule = rule;
  27395. if (rule) {
  27396. return rule.getStyle();
  27397. }
  27398. }
  27399. return domain_abstract_model_Styleable__WEBPACK_IMPORTED_MODULE_4__["default"].getStyle.call(this);
  27400. },
  27401. /**
  27402. * Set the style on the component
  27403. * @param {Object} prop Key value style object
  27404. * @return {Object}
  27405. * @example
  27406. * component.setStyle({ color: 'red' });
  27407. */
  27408. setStyle: function setStyle() {
  27409. var _this3 = this;
  27410. var prop = arguments.length > 0 && arguments[0] !== undefined ? arguments[0] : {};
  27411. var opts = arguments.length > 1 && arguments[1] !== undefined ? arguments[1] : {};
  27412. var em = this.em;
  27413. var opt = this.opt;
  27414. if (em && em.getConfig('avoidInlineStyle') && !opt.temporary) {
  27415. var style = this.get('style') || {};
  27416. prop = Object(underscore__WEBPACK_IMPORTED_MODULE_2__["isString"])(prop) ? this.parseStyle(prop) : prop;
  27417. prop = _objectSpread({}, prop, {}, style);
  27418. var state = em.get('state');
  27419. var cc = em.get('CssComposer');
  27420. var propOrig = this.getStyle();
  27421. this.rule = cc.setIdRule(this.getId(), prop, _objectSpread({}, opts, {
  27422. state: state
  27423. }));
  27424. var diff = Object(utils_mixins__WEBPACK_IMPORTED_MODULE_3__["shallowDiff"])(propOrig, prop);
  27425. this.set('style', {}, {
  27426. silent: 1
  27427. });
  27428. Object(underscore__WEBPACK_IMPORTED_MODULE_2__["keys"])(diff).forEach(function (pr) {
  27429. return _this3.trigger("change:style:".concat(pr));
  27430. });
  27431. } else {
  27432. prop = domain_abstract_model_Styleable__WEBPACK_IMPORTED_MODULE_4__["default"].setStyle.apply(this, arguments);
  27433. }
  27434. return prop;
  27435. },
  27436. /**
  27437. * Return all component's attributes
  27438. * @return {Object}
  27439. */
  27440. getAttributes: function getAttributes() {
  27441. var em = this.em;
  27442. var classes = [];
  27443. var attributes = _objectSpread({}, this.get('attributes'));
  27444. var sm = em && em.get('SelectorManager');
  27445. var id = this.getId(); // Add classes
  27446. this.get('classes').forEach(function (cls) {
  27447. return classes.push(Object(underscore__WEBPACK_IMPORTED_MODULE_2__["isString"])(cls) ? cls : cls.get('name'));
  27448. });
  27449. classes.length && (attributes.class = classes.join(' ')); // Check if we need an ID on the component
  27450. if (!Object(underscore__WEBPACK_IMPORTED_MODULE_2__["has"])(attributes, 'id')) {
  27451. var hasStyle; // If we don't rely on inline styling we have to check
  27452. // for the ID selector
  27453. if (avoidInline(em)) {
  27454. hasStyle = sm && sm.get(id, sm.Selector.TYPE_ID);
  27455. } else if (!Object(underscore__WEBPACK_IMPORTED_MODULE_2__["isEmpty"])(this.getStyle())) {
  27456. hasStyle = 1;
  27457. }
  27458. if (hasStyle) {
  27459. attributes.id = this.getId();
  27460. }
  27461. }
  27462. return attributes;
  27463. },
  27464. /**
  27465. * Add classes
  27466. * @param {Array<String>|String} classes Array or string of classes
  27467. * @return {Array} Array of added selectors
  27468. * @example
  27469. * model.addClass('class1');
  27470. * model.addClass('class1 class2');
  27471. * model.addClass(['class1', 'class2']);
  27472. * // -> [SelectorObject, ...]
  27473. */
  27474. addClass: function addClass(classes) {
  27475. var added = this.em.get('SelectorManager').addClass(classes);
  27476. return this.get('classes').add(added);
  27477. },
  27478. /**
  27479. * Set classes (resets current collection)
  27480. * @param {Array<String>|String} classes Array or string of classes
  27481. * @return {Array} Array of added selectors
  27482. * @example
  27483. * model.setClass('class1');
  27484. * model.setClass('class1 class2');
  27485. * model.setClass(['class1', 'class2']);
  27486. * // -> [SelectorObject, ...]
  27487. */
  27488. setClass: function setClass(classes) {
  27489. this.get('classes').reset();
  27490. return this.addClass(classes);
  27491. },
  27492. /**
  27493. * Remove classes
  27494. * @param {Array<String>|String} classes Array or string of classes
  27495. * @return {Array} Array of removed selectors
  27496. * @example
  27497. * model.removeClass('class1');
  27498. * model.removeClass('class1 class2');
  27499. * model.removeClass(['class1', 'class2']);
  27500. * // -> [SelectorObject, ...]
  27501. */
  27502. removeClass: function removeClass(classes) {
  27503. var removed = [];
  27504. classes = Object(underscore__WEBPACK_IMPORTED_MODULE_2__["isArray"])(classes) ? classes : [classes];
  27505. var selectors = this.get('classes');
  27506. var type = selector_manager_model_Selector__WEBPACK_IMPORTED_MODULE_7__["default"].TYPE_CLASS;
  27507. classes.forEach(function (classe) {
  27508. var classes = classe.split(' ');
  27509. classes.forEach(function (name) {
  27510. var selector = selectors.where({
  27511. name: name,
  27512. type: type
  27513. })[0];
  27514. selector && removed.push(selectors.remove(selector));
  27515. });
  27516. });
  27517. return removed;
  27518. },
  27519. /**
  27520. * Returns component's classes as an array of strings
  27521. * @return {Array}
  27522. */
  27523. getClasses: function getClasses() {
  27524. var attr = this.getAttributes();
  27525. var classStr = attr.class;
  27526. return classStr ? classStr.split(' ') : [];
  27527. },
  27528. initClasses: function initClasses() {
  27529. var event = 'change:classes';
  27530. var toListen = [this, event, this.initClasses];
  27531. var cls = this.get('classes') || [];
  27532. var clsArr = Object(underscore__WEBPACK_IMPORTED_MODULE_2__["isString"])(cls) ? cls.split(' ') : cls;
  27533. this.stopListening.apply(this, toListen);
  27534. var classes = this.normalizeClasses(clsArr);
  27535. var selectors = new selector_manager_model_Selectors__WEBPACK_IMPORTED_MODULE_8__["default"]([]);
  27536. this.set('classes', selectors);
  27537. selectors.add(classes);
  27538. this.listenTo.apply(this, toListen);
  27539. return this;
  27540. },
  27541. initComponents: function initComponents() {
  27542. var event = 'change:components';
  27543. var toListen = [this, event, this.initComponents];
  27544. this.stopListening.apply(this, toListen); // Have to add components after the init, otherwise the parent
  27545. // is not visible
  27546. var comps = new _Components__WEBPACK_IMPORTED_MODULE_6__["default"](null, this.opt);
  27547. comps.parent = this;
  27548. var components = this.get('components');
  27549. var addChild = !this.opt.avoidChildren;
  27550. this.set('components', comps);
  27551. addChild && comps.add(Object(underscore__WEBPACK_IMPORTED_MODULE_2__["isFunction"])(components) ? components(this) : components);
  27552. this.listenTo.apply(this, toListen);
  27553. return this;
  27554. },
  27555. initTraits: function initTraits(changed) {
  27556. var em = this.em;
  27557. var event = 'change:traits';
  27558. var toListen = [this, event, this.initTraits];
  27559. this.stopListening.apply(this, toListen);
  27560. this.loadTraits();
  27561. var attrs = _objectSpread({}, this.get('attributes'));
  27562. var traits = this.get('traits');
  27563. traits.each(function (trait) {
  27564. if (!trait.get('changeProp')) {
  27565. var name = trait.get('name');
  27566. var value = trait.getInitValue();
  27567. if (name && value) attrs[name] = value;
  27568. }
  27569. });
  27570. traits.length && this.set('attributes', attrs);
  27571. this.listenTo.apply(this, toListen);
  27572. changed && em && em.trigger('component:toggled');
  27573. return this;
  27574. },
  27575. /**
  27576. * Add new component children
  27577. * @param {Component|String} components Component to add
  27578. * @param {Object} [opts={}] Options, same as in `model.add()`(from backbone)
  27579. * @return {Array} Array of appended components
  27580. * @example
  27581. * someComponent.get('components').length // -> 0
  27582. * const videoComponent = someComponent.append('<video></video><div></div>')[0];
  27583. * // This will add 2 components (`video` and `div`) to your `someComponent`
  27584. * someComponent.get('components').length // -> 2
  27585. * // You can pass components directly
  27586. * otherComponent.append(otherComponent2);
  27587. * otherComponent.append([otherComponent3, otherComponent4]);
  27588. */
  27589. append: function append(components) {
  27590. var opts = arguments.length > 1 && arguments[1] !== undefined ? arguments[1] : {};
  27591. var result = this.components().add(components, opts);
  27592. return Object(underscore__WEBPACK_IMPORTED_MODULE_2__["isArray"])(result) ? result : [result];
  27593. },
  27594. /**
  27595. * Set new collection if `components` are provided, otherwise the
  27596. * current collection is returned
  27597. * @param {Component|String} [components] Components to set
  27598. * @return {Collection|Array<Component>}
  27599. * @example
  27600. * // Set new collection
  27601. * component.components('<span></span><div></div>');
  27602. * // Get current collection
  27603. * const collection = component.components();
  27604. * console.log(collection.length);
  27605. * // -> 2
  27606. */
  27607. components: function components(_components) {
  27608. var coll = this.get('components');
  27609. if (Object(underscore__WEBPACK_IMPORTED_MODULE_2__["isUndefined"])(_components)) {
  27610. return coll;
  27611. } else {
  27612. coll.reset();
  27613. return _components && this.append(_components);
  27614. }
  27615. },
  27616. /**
  27617. * Remove all inner components
  27618. * * @return {this}
  27619. */
  27620. empty: function empty() {
  27621. var opts = arguments.length > 0 && arguments[0] !== undefined ? arguments[0] : {};
  27622. this.components().reset(null, opts);
  27623. return this;
  27624. },
  27625. /**
  27626. * Get the parent component, if exists
  27627. * @return {Component}
  27628. * @example
  27629. * component.parent();
  27630. * // -> Component
  27631. */
  27632. parent: function parent() {
  27633. var coll = this.collection;
  27634. return coll && coll.parent;
  27635. },
  27636. /**
  27637. * Script updated
  27638. * @private
  27639. */
  27640. scriptUpdated: function scriptUpdated() {
  27641. this.set('scriptUpdated', 1);
  27642. },
  27643. /**
  27644. * Init toolbar
  27645. * @private
  27646. */
  27647. initToolbar: function initToolbar() {
  27648. var em = this.em;
  27649. var model = this;
  27650. var ppfx = em && em.getConfig('stylePrefix') || '';
  27651. if (!model.get('toolbar')) {
  27652. var tb = [];
  27653. if (model.collection) {
  27654. tb.push({
  27655. attributes: {
  27656. class: 'fa fa-arrow-up'
  27657. },
  27658. command: function command(ed) {
  27659. return ed.runCommand('core:component-exit', {
  27660. force: 1
  27661. });
  27662. }
  27663. });
  27664. }
  27665. if (model.get('draggable')) {
  27666. tb.push({
  27667. attributes: {
  27668. class: "fa fa-arrows ".concat(ppfx, "no-touch-actions"),
  27669. draggable: true
  27670. },
  27671. //events: hasDnd(this.em) ? { dragstart: 'execCommand' } : '',
  27672. command: 'tlb-move'
  27673. });
  27674. }
  27675. if (model.get('copyable')) {
  27676. tb.push({
  27677. attributes: {
  27678. class: 'fa fa-clone'
  27679. },
  27680. command: 'tlb-clone'
  27681. });
  27682. }
  27683. if (model.get('removable')) {
  27684. tb.push({
  27685. attributes: {
  27686. class: 'fa fa-trash-o'
  27687. },
  27688. command: 'tlb-delete'
  27689. });
  27690. }
  27691. model.set('toolbar', tb);
  27692. }
  27693. },
  27694. /**
  27695. * Load traits
  27696. * @param {Array} traits
  27697. * @private
  27698. */
  27699. loadTraits: function loadTraits(traits) {
  27700. var opts = arguments.length > 1 && arguments[1] !== undefined ? arguments[1] : {};
  27701. traits = traits || this.get('traits');
  27702. traits = Object(underscore__WEBPACK_IMPORTED_MODULE_2__["isFunction"])(traits) ? traits(this) : traits;
  27703. if (!(traits instanceof trait_manager_model_Traits__WEBPACK_IMPORTED_MODULE_9__["default"])) {
  27704. var trt = new trait_manager_model_Traits__WEBPACK_IMPORTED_MODULE_9__["default"]([], this.opt);
  27705. trt.setTarget(this);
  27706. if (traits.length) {
  27707. traits.forEach(function (tr) {
  27708. return tr.attributes && delete tr.attributes.value;
  27709. });
  27710. trt.add(traits);
  27711. }
  27712. this.set('traits', trt, opts);
  27713. }
  27714. return this;
  27715. },
  27716. /**
  27717. * Get the trait by id/name
  27718. * @param {String} id The `id` or `name` of the trait
  27719. * @return {Trait} Trait model
  27720. * @example
  27721. * const traitTitle = component.getTrait('title');
  27722. * traitTitle && traitTitle.set('label', 'New label');
  27723. */
  27724. getTrait: function getTrait(id) {
  27725. return this.get('traits').filter(function (trait) {
  27726. return trait.get('id') === id || trait.get('name') === id;
  27727. })[0];
  27728. },
  27729. /**
  27730. * Update a trait
  27731. * @param {String} id The `id` or `name` of the trait
  27732. * @param {Object} props Object with the props to update
  27733. * @return {this}
  27734. * @example
  27735. * component.updateTrait('title', {
  27736. * type: 'select',
  27737. * options: [ 'Option 1', 'Option 2' ],
  27738. * });
  27739. */
  27740. updateTrait: function updateTrait(id, props) {
  27741. var em = this.em;
  27742. var trait = this.getTrait(id);
  27743. trait && trait.set(props);
  27744. em && em.trigger('component:toggled');
  27745. return this;
  27746. },
  27747. /**
  27748. * Get the trait position index by id/name. Useful in case you want to
  27749. * replace some trait, at runtime, with something else.
  27750. * @param {String} id The `id` or `name` of the trait
  27751. * @return {Number} Index position of the current trait
  27752. * @example
  27753. * const traitTitle = component.getTraitIndex('title');
  27754. * console.log(traitTitle); // 1
  27755. */
  27756. getTraitIndex: function getTraitIndex(id) {
  27757. var trait = this.getTrait(id);
  27758. return trait ? this.get('traits').indexOf(trait) : trait;
  27759. },
  27760. /**
  27761. * Remove trait/s by id/s.
  27762. * @param {String|Array<String>} id The `id`/`name` of the trait (or an array)
  27763. * @return {Array} Array of removed traits
  27764. * @example
  27765. * component.removeTrait('title');
  27766. * component.removeTrait(['title', 'id']);
  27767. */
  27768. removeTrait: function removeTrait(id) {
  27769. var _this4 = this;
  27770. var em = this.em;
  27771. var ids = Object(underscore__WEBPACK_IMPORTED_MODULE_2__["isArray"])(id) ? id : [id];
  27772. var toRemove = ids.map(function (id) {
  27773. return _this4.getTrait(id);
  27774. });
  27775. var removed = this.get('traits').remove(toRemove);
  27776. em && em.trigger('component:toggled');
  27777. return removed;
  27778. },
  27779. /**
  27780. * Add trait/s by id/s.
  27781. * @param {String|Object|Array<String|Object>} trait Trait to add (or an array of traits)
  27782. * @param {Options} opts Options for the add
  27783. * @return {Array} Array of added traits
  27784. * @example
  27785. * component.addTrait('title', { at: 1 }); // Add title trait (`at` option is the position index)
  27786. * component.addTrait({
  27787. * type: 'checkbox',
  27788. * name: 'disabled',
  27789. * });
  27790. * component.addTrait(['title', {...}, ...]);
  27791. */
  27792. addTrait: function addTrait(trait) {
  27793. var opts = arguments.length > 1 && arguments[1] !== undefined ? arguments[1] : {};
  27794. var em = this.em;
  27795. var added = this.get('traits').add(trait, opts);
  27796. em && em.trigger('component:toggled');
  27797. return added;
  27798. },
  27799. /**
  27800. * Normalize input classes from array to array of objects
  27801. * @param {Array} arr
  27802. * @return {Array}
  27803. * @private
  27804. */
  27805. normalizeClasses: function normalizeClasses(arr) {
  27806. var res = [];
  27807. var em = this.em;
  27808. if (!em) return;
  27809. var clm = em.get('SelectorManager');
  27810. if (!clm) return;
  27811. arr.forEach(function (val) {
  27812. var name = '';
  27813. if (typeof val === 'string') name = val;else name = val.name;
  27814. var model = clm.add(name);
  27815. res.push(model);
  27816. });
  27817. return res;
  27818. },
  27819. /**
  27820. * Override original clone method
  27821. * @private
  27822. */
  27823. clone: function clone() {
  27824. var em = this.em;
  27825. var style = this.getStyle();
  27826. var attr = _objectSpread({}, this.attributes);
  27827. var opts = _objectSpread({}, this.opt);
  27828. attr.attributes = _objectSpread({}, attr.attributes);
  27829. delete attr.attributes.id;
  27830. attr.components = [];
  27831. attr.classes = [];
  27832. attr.traits = [];
  27833. this.get('components').each(function (md, i) {
  27834. attr.components[i] = md.clone();
  27835. });
  27836. this.get('traits').each(function (md, i) {
  27837. attr.traits[i] = md.clone();
  27838. });
  27839. this.get('classes').each(function (md, i) {
  27840. attr.classes[i] = md.get('name');
  27841. });
  27842. attr.status = '';
  27843. attr.view = '';
  27844. opts.collection = null;
  27845. if (em && em.getConfig('avoidInlineStyle') && !Object(underscore__WEBPACK_IMPORTED_MODULE_2__["isEmpty"])(style)) {
  27846. attr.style = style;
  27847. }
  27848. var cloned = new this.constructor(attr, opts);
  27849. var event = 'component:clone';
  27850. em && em.trigger(event, cloned);
  27851. this.trigger(event, cloned);
  27852. return cloned;
  27853. },
  27854. /**
  27855. * Get the name of the component
  27856. * @return {String}
  27857. * */
  27858. getName: function getName() {
  27859. var em = this.em;
  27860. var _this$attributes = this.attributes,
  27861. type = _this$attributes.type,
  27862. tagName = _this$attributes.tagName;
  27863. var cName = this.get('name');
  27864. var isDiv = tagName == 'div';
  27865. var tag = isDiv ? 'box' : tagName;
  27866. var defName = type || tag;
  27867. var nameTag = !type && tagName && !isDiv && tagName;
  27868. var i18nPfx = 'domComponents.names.';
  27869. var i18nName = cName && em && em.t("".concat(i18nPfx).concat(cName));
  27870. var i18nNameTag = nameTag && em && em.t("".concat(i18nPfx).concat(nameTag));
  27871. var i18nDefName = em && (em.t("".concat(i18nPfx).concat(type)) || em.t("".concat(i18nPfx).concat(tagName)));
  27872. return this.get('custom-name') || // Used in Layers (when the user changes the name)
  27873. i18nName || cName || // Component name (check if there is a i18n string for it)
  27874. i18nNameTag || Object(utils_mixins__WEBPACK_IMPORTED_MODULE_3__["capitalize"])(nameTag) || // Try name by tag if there is no valid type
  27875. i18nDefName || Object(utils_mixins__WEBPACK_IMPORTED_MODULE_3__["capitalize"])(defName) // Use the default name
  27876. ;
  27877. },
  27878. /**
  27879. * Get the icon string
  27880. * @return {String}
  27881. */
  27882. getIcon: function getIcon() {
  27883. var icon = this.get('icon');
  27884. return icon ? icon + ' ' : '';
  27885. },
  27886. /**
  27887. * Return HTML string of the component
  27888. * @param {Object} [opts={}] Options
  27889. * @param {String} [opts.tag] Custom tagName
  27890. * @param {Object|Function} [opts.attributes=null] You can pass an object of custom attributes to replace
  27891. * with the current one or you can even pass a function to generate attributes dynamically
  27892. * @return {String} HTML string
  27893. * @example
  27894. * // Simple HTML return
  27895. * component.set({ tagName: 'span' });
  27896. * component.setAttributes({ title: 'Hello' });
  27897. * component.toHTML();
  27898. * // -> <span title="Hello"></span>
  27899. *
  27900. * // Custom attributes
  27901. * component.toHTML({ attributes: { 'data-test': 'Hello' } });
  27902. * // -> <span data-test="Hello"></span>
  27903. *
  27904. * // Custom dynamic attributes
  27905. * component.toHTML({
  27906. * attributes(component, attributes) {
  27907. * if (component.get('tagName') == 'span') {
  27908. * attributes.title = 'Custom attribute';
  27909. * }
  27910. * return attributes;
  27911. * },
  27912. * });
  27913. * // -> <span title="Custom attribute"></span>
  27914. */
  27915. toHTML: function toHTML() {
  27916. var opts = arguments.length > 0 && arguments[0] !== undefined ? arguments[0] : {};
  27917. var model = this;
  27918. var attrs = [];
  27919. var customTag = opts.tag;
  27920. var tag = customTag || model.get('tagName');
  27921. var sTag = model.get('void');
  27922. var customAttr = opts.attributes;
  27923. var attributes = this.getAttrToHTML();
  27924. delete opts.tag; // Get custom attributes if requested
  27925. if (customAttr) {
  27926. if (Object(underscore__WEBPACK_IMPORTED_MODULE_2__["isFunction"])(customAttr)) {
  27927. attributes = customAttr(model, attributes) || {};
  27928. } else if (Object(underscore__WEBPACK_IMPORTED_MODULE_2__["isObject"])(customAttr)) {
  27929. attributes = customAttr;
  27930. }
  27931. }
  27932. for (var attr in attributes) {
  27933. var val = attributes[attr];
  27934. var value = Object(underscore__WEBPACK_IMPORTED_MODULE_2__["isString"])(val) ? val.replace(/"/g, '&quot;') : val;
  27935. if (!Object(underscore__WEBPACK_IMPORTED_MODULE_2__["isUndefined"])(value)) {
  27936. if (Object(underscore__WEBPACK_IMPORTED_MODULE_2__["isBoolean"])(value)) {
  27937. value && attrs.push(attr);
  27938. } else {
  27939. attrs.push("".concat(attr, "=\"").concat(value, "\""));
  27940. }
  27941. }
  27942. }
  27943. var attrString = attrs.length ? " ".concat(attrs.join(' ')) : '';
  27944. var code = "<".concat(tag).concat(attrString).concat(sTag ? '/' : '', ">").concat(model.get('content'));
  27945. model.get('components').each(function (comp) {
  27946. return code += comp.toHTML(opts);
  27947. });
  27948. !sTag && (code += "</".concat(tag, ">"));
  27949. return code;
  27950. },
  27951. /**
  27952. * Returns object of attributes for HTML
  27953. * @return {Object}
  27954. * @private
  27955. */
  27956. getAttrToHTML: function getAttrToHTML() {
  27957. var attr = this.getAttributes();
  27958. delete attr.style;
  27959. return attr;
  27960. },
  27961. /**
  27962. * Return a shallow copy of the model's attributes for JSON
  27963. * stringification.
  27964. * @return {Object}
  27965. * @private
  27966. */
  27967. toJSON: function toJSON() {
  27968. for (var _len2 = arguments.length, args = new Array(_len2), _key2 = 0; _key2 < _len2; _key2++) {
  27969. args[_key2] = arguments[_key2];
  27970. }
  27971. var obj = backbone__WEBPACK_IMPORTED_MODULE_5___default.a.Model.prototype.toJSON.apply(this, args);
  27972. obj.attributes = this.getAttributes();
  27973. delete obj.attributes.class;
  27974. delete obj.toolbar;
  27975. delete obj.traits;
  27976. if (this.em.getConfig('avoidDefaults')) {
  27977. var defaults = Object(underscore__WEBPACK_IMPORTED_MODULE_2__["result"])(this, 'defaults');
  27978. Object(underscore__WEBPACK_IMPORTED_MODULE_2__["forEach"])(defaults, function (value, key) {
  27979. if (['type', 'content'].indexOf(key) === -1 && obj[key] === value) {
  27980. delete obj[key];
  27981. }
  27982. });
  27983. if (Object(underscore__WEBPACK_IMPORTED_MODULE_2__["isEmpty"])(obj.type)) {
  27984. delete obj.type;
  27985. }
  27986. Object(underscore__WEBPACK_IMPORTED_MODULE_2__["forEach"])(['attributes', 'style'], function (prop) {
  27987. if (Object(underscore__WEBPACK_IMPORTED_MODULE_2__["isEmpty"])(defaults[prop]) && Object(underscore__WEBPACK_IMPORTED_MODULE_2__["isEmpty"])(obj[prop])) {
  27988. delete obj[prop];
  27989. }
  27990. });
  27991. Object(underscore__WEBPACK_IMPORTED_MODULE_2__["forEach"])(['classes', 'components'], function (prop) {
  27992. if (Object(underscore__WEBPACK_IMPORTED_MODULE_2__["isEmpty"])(defaults[prop]) && !obj[prop].length) {
  27993. delete obj[prop];
  27994. }
  27995. });
  27996. }
  27997. return obj;
  27998. },
  27999. /**
  28000. * Return the component id
  28001. * @return {String}
  28002. */
  28003. getId: function getId() {
  28004. var attrs = this.get('attributes') || {};
  28005. return attrs.id || this.ccid || this.cid;
  28006. },
  28007. /**
  28008. * Set new id on the component
  28009. * @param {String} id
  28010. * @return {this}
  28011. */
  28012. setId: function setId(id, opts) {
  28013. var attrs = _objectSpread({}, this.get('attributes'));
  28014. attrs.id = id;
  28015. this.set('attributes', attrs, opts);
  28016. return this;
  28017. },
  28018. /**
  28019. * Get the DOM element of the component.
  28020. * This works only if the component is already rendered
  28021. * @param {Frame} frame Specific frame from which taking the element
  28022. * @return {HTMLElement}
  28023. */
  28024. getEl: function getEl(frame) {
  28025. var view = this.getView(frame);
  28026. return view && view.el;
  28027. },
  28028. /**
  28029. * Get the View of the component.
  28030. * This works only if the component is already rendered
  28031. * @param {Frame} frame Get View of a specific frame
  28032. * @return {ComponentView}
  28033. */
  28034. getView: function getView(frame) {
  28035. var view = this.view,
  28036. views = this.views;
  28037. if (frame) {
  28038. view = views.filter(function (view) {
  28039. return view._getFrame() === frame.view;
  28040. })[0];
  28041. }
  28042. return view;
  28043. },
  28044. getCurrentView: function getCurrentView() {
  28045. var frame = (this.em.get('currentFrame') || {}).model;
  28046. return this.getView(frame);
  28047. },
  28048. /**
  28049. * Return script in string format, cleans 'function() {..' from scripts
  28050. * if it's a function
  28051. * @param {string|Function} script
  28052. * @return {string}
  28053. * @private
  28054. */
  28055. getScriptString: function getScriptString(script) {
  28056. var _this5 = this;
  28057. var scr = script || this.get('script');
  28058. if (!scr) {
  28059. return scr;
  28060. } // Need to convert script functions to strings
  28061. if (typeof scr == 'function') {
  28062. var scrStr = scr.toString().trim();
  28063. scrStr = scrStr.replace(/^function[\s\w]*\(\)\s?\{/, '').replace(/\}$/, '');
  28064. scr = scrStr.trim();
  28065. }
  28066. var config = this.em.getConfig();
  28067. var tagVarStart = escapeRegExp(config.tagVarStart || '{[ ');
  28068. var tagVarEnd = escapeRegExp(config.tagVarEnd || ' ]}');
  28069. var reg = new RegExp("".concat(tagVarStart, "([\\w\\d-]*)").concat(tagVarEnd), 'g');
  28070. scr = scr.replace(reg, function (match, v) {
  28071. // If at least one match is found I have to track this change for a
  28072. // better optimization inside JS generator
  28073. _this5.scriptUpdated();
  28074. var result = _this5.attributes[v] || '';
  28075. return Object(underscore__WEBPACK_IMPORTED_MODULE_2__["isArray"])(result) || _babel_runtime_helpers_typeof__WEBPACK_IMPORTED_MODULE_0___default()(result) == 'object' ? JSON.stringify(result) : result;
  28076. });
  28077. return scr;
  28078. },
  28079. emitUpdate: function emitUpdate(property) {
  28080. var em = this.em;
  28081. var event = 'component:update' + (property ? ":".concat(property) : '');
  28082. for (var _len3 = arguments.length, args = new Array(_len3 > 1 ? _len3 - 1 : 0), _key3 = 1; _key3 < _len3; _key3++) {
  28083. args[_key3 - 1] = arguments[_key3];
  28084. }
  28085. property && this.updated.apply(this, [property, property && this.get(property), property && this.previous(property)].concat(args));
  28086. this.trigger.apply(this, [event].concat(args));
  28087. em && em.trigger.apply(em, [event, this].concat(args));
  28088. },
  28089. /**
  28090. * Execute callback function on itself and all inner components
  28091. * @param {Function} clb Callback function, the model is passed as an argument
  28092. * @return {this}
  28093. * @example
  28094. * component.onAll(component => {
  28095. * // do something with component
  28096. * })
  28097. */
  28098. onAll: function onAll(clb) {
  28099. if (Object(underscore__WEBPACK_IMPORTED_MODULE_2__["isFunction"])(clb)) {
  28100. clb(this);
  28101. this.components().forEach(function (model) {
  28102. return model.onAll(clb);
  28103. });
  28104. }
  28105. return this;
  28106. },
  28107. /**
  28108. * Remove the component
  28109. * @return {this}
  28110. */
  28111. remove: function remove() {
  28112. var coll = this.collection;
  28113. return coll && coll.remove(this);
  28114. },
  28115. /**
  28116. * Reset id of the component and any of its style rule
  28117. * @param {Object} [opts={}] Options
  28118. * @return {this}
  28119. * @private
  28120. */
  28121. resetId: function resetId() {
  28122. var opts = arguments.length > 0 && arguments[0] !== undefined ? arguments[0] : {};
  28123. var em = this.em;
  28124. var oldId = this.getId();
  28125. if (!oldId) return;
  28126. var newId = Component.createId(this);
  28127. this.setId(newId);
  28128. var rule = em && em.get('CssComposer').getIdRule(oldId);
  28129. var selector = rule && rule.get('selectors').at(0);
  28130. selector && selector.set('name', newId);
  28131. return this;
  28132. },
  28133. _getStyleRule: function _getStyleRule() {
  28134. var _ref = arguments.length > 0 && arguments[0] !== undefined ? arguments[0] : {},
  28135. id = _ref.id;
  28136. var em = this.em;
  28137. var idS = id || this.getId();
  28138. return em && em.get('CssComposer').getIdRule(idS);
  28139. },
  28140. _getStyleSelector: function _getStyleSelector(opts) {
  28141. var rule = this._getStyleRule(opts);
  28142. return rule && rule.get('selectors').at(0);
  28143. },
  28144. _idUpdated: function _idUpdated(m, v) {
  28145. var opts = arguments.length > 2 && arguments[2] !== undefined ? arguments[2] : {};
  28146. if (opts.idUpdate) return;
  28147. var ccid = this.ccid;
  28148. var _ref2 = this.get('attributes') || {},
  28149. id = _ref2.id;
  28150. var idPrev = (this.previous('attributes') || {}).id || ccid;
  28151. var list = Component.getList(this); // If the ID already exists I need to rollback to the old one
  28152. if (list[id]) {
  28153. return this.setId(idPrev, {
  28154. idUpdate: 1
  28155. });
  28156. } // Remove the old ID reference and add the new one
  28157. delete list[idPrev];
  28158. list[id] = this;
  28159. this.ccid = id; // Update the style selector name
  28160. var selector = this._getStyleSelector({
  28161. id: idPrev
  28162. });
  28163. selector && selector.set({
  28164. name: id,
  28165. label: id
  28166. });
  28167. }
  28168. }, {
  28169. /**
  28170. * Detect if the passed element is a valid component.
  28171. * In case the element is valid an object abstracted
  28172. * from the element will be returned
  28173. * @param {HTMLElement}
  28174. * @return {Object}
  28175. * @private
  28176. */
  28177. isComponent: function isComponent(el) {
  28178. return {
  28179. tagName: el.tagName ? el.tagName.toLowerCase() : ''
  28180. };
  28181. },
  28182. ensureInList: function ensureInList(model) {
  28183. var list = Component.getList(model);
  28184. var id = model.getId();
  28185. var current = list[id];
  28186. if (!current) {
  28187. // Insert in list
  28188. list[id] = model;
  28189. } else if (current !== model) {
  28190. // Create new ID
  28191. var nextId = Component.getIncrementId(id, list);
  28192. model.setId(nextId);
  28193. list[nextId] = model;
  28194. }
  28195. model.components().forEach(function (i) {
  28196. return Component.ensureInList(i);
  28197. });
  28198. },
  28199. /**
  28200. * Relying simply on the number of components becomes a problem when you
  28201. * store and load them back, you might hit collisions with new components
  28202. * @param {Model} model
  28203. * @return {string}
  28204. * @private
  28205. */
  28206. createId: function createId(model) {
  28207. var list = Component.getList(model);
  28208. var _model$get = model.get('attributes'),
  28209. id = _model$get.id;
  28210. var nextId;
  28211. if (id) {
  28212. nextId = Component.getIncrementId(id, list);
  28213. model.setId(nextId);
  28214. } else {
  28215. nextId = Component.getNewId(list);
  28216. }
  28217. list[nextId] = model;
  28218. return nextId;
  28219. },
  28220. getNewId: function getNewId(list) {
  28221. var count = Object.keys(list).length; // Testing 1000000 components with `+ 2` returns 0 collisions
  28222. var ilen = count.toString().length + 2;
  28223. var uid = (Math.random() + 1.1).toString(36).slice(-ilen);
  28224. var newId = "i".concat(uid);
  28225. while (list[newId]) {
  28226. newId = Component.getNewId(list);
  28227. }
  28228. return newId;
  28229. },
  28230. getIncrementId: function getIncrementId(id, list) {
  28231. var counter = 1;
  28232. var newId = id;
  28233. while (list[newId]) {
  28234. counter++;
  28235. newId = "".concat(id, "-").concat(counter);
  28236. }
  28237. return newId;
  28238. },
  28239. /**
  28240. * The list of components is taken from the Components module.
  28241. * Initially, the list, was set statically on the Component object but it was
  28242. * not ok, as it was shared between multiple editor instances
  28243. */
  28244. getList: function getList(model) {
  28245. var domc = model.opt && model.opt.domc;
  28246. return domc ? domc.componentsById : {};
  28247. },
  28248. /**
  28249. * This method checks, for each parsed component and style object
  28250. * (are not Components/CSSRules yet), for duplicated id and fixes them
  28251. * This method is used in Components.js just after the parsing
  28252. */
  28253. checkId: function checkId(components) {
  28254. var styles = arguments.length > 1 && arguments[1] !== undefined ? arguments[1] : [];
  28255. var list = arguments.length > 2 && arguments[2] !== undefined ? arguments[2] : {};
  28256. var comps = Object(underscore__WEBPACK_IMPORTED_MODULE_2__["isArray"])(components) ? components : [components];
  28257. comps.forEach(function (comp) {
  28258. var _comp$attributes = comp.attributes,
  28259. attributes = _comp$attributes === void 0 ? {} : _comp$attributes,
  28260. components = comp.components;
  28261. var id = attributes.id; // Check if we have collisions with current components
  28262. if (id && list[id]) {
  28263. var newId = Component.getIncrementId(id, list);
  28264. attributes.id = newId; // Update passed styles
  28265. Object(underscore__WEBPACK_IMPORTED_MODULE_2__["isArray"])(styles) && styles.forEach(function (style) {
  28266. var selectors = style.selectors;
  28267. selectors.forEach(function (sel, idx) {
  28268. if (sel === "#".concat(id)) selectors[idx] = "#".concat(newId);
  28269. });
  28270. });
  28271. }
  28272. components && Component.checkId(components, styles, list);
  28273. });
  28274. }
  28275. });
  28276. /* harmony default export */ __webpack_exports__["default"] = (Component);
  28277. /***/ }),
  28278. /***/ "./src/dom_components/model/ComponentComment.js":
  28279. /*!******************************************************!*\
  28280. !*** ./src/dom_components/model/ComponentComment.js ***!
  28281. \******************************************************/
  28282. /*! exports provided: default */
  28283. /***/ (function(module, __webpack_exports__, __webpack_require__) {
  28284. "use strict";
  28285. __webpack_require__.r(__webpack_exports__);
  28286. /* harmony import */ var _babel_runtime_helpers_defineProperty__WEBPACK_IMPORTED_MODULE_0__ = __webpack_require__(/*! @babel/runtime/helpers/defineProperty */ "./node_modules/@babel/runtime/helpers/defineProperty.js");
  28287. /* harmony import */ var _babel_runtime_helpers_defineProperty__WEBPACK_IMPORTED_MODULE_0___default = /*#__PURE__*/__webpack_require__.n(_babel_runtime_helpers_defineProperty__WEBPACK_IMPORTED_MODULE_0__);
  28288. /* harmony import */ var _ComponentTextNode__WEBPACK_IMPORTED_MODULE_1__ = __webpack_require__(/*! ./ComponentTextNode */ "./src/dom_components/model/ComponentTextNode.js");
  28289. function ownKeys(object, enumerableOnly) { var keys = Object.keys(object); if (Object.getOwnPropertySymbols) { var symbols = Object.getOwnPropertySymbols(object); if (enumerableOnly) symbols = symbols.filter(function (sym) { return Object.getOwnPropertyDescriptor(object, sym).enumerable; }); keys.push.apply(keys, symbols); } return keys; }
  28290. function _objectSpread(target) { for (var i = 1; i < arguments.length; i++) { var source = arguments[i] != null ? arguments[i] : {}; if (i % 2) { ownKeys(source, true).forEach(function (key) { _babel_runtime_helpers_defineProperty__WEBPACK_IMPORTED_MODULE_0___default()(target, key, source[key]); }); } else if (Object.getOwnPropertyDescriptors) { Object.defineProperties(target, Object.getOwnPropertyDescriptors(source)); } else { ownKeys(source).forEach(function (key) { Object.defineProperty(target, key, Object.getOwnPropertyDescriptor(source, key)); }); } } return target; }
  28291. /* harmony default export */ __webpack_exports__["default"] = (_ComponentTextNode__WEBPACK_IMPORTED_MODULE_1__["default"].extend({
  28292. defaults: _objectSpread({}, _ComponentTextNode__WEBPACK_IMPORTED_MODULE_1__["default"].prototype.defaults),
  28293. toHTML: function toHTML() {
  28294. return "<!--".concat(this.get('content'), "-->");
  28295. }
  28296. }, {
  28297. isComponent: function isComponent(el) {
  28298. if (el.nodeType == 8) {
  28299. return {
  28300. tagName: 'NULL',
  28301. type: 'comment',
  28302. content: el.textContent
  28303. };
  28304. }
  28305. }
  28306. }));
  28307. /***/ }),
  28308. /***/ "./src/dom_components/model/ComponentImage.js":
  28309. /*!****************************************************!*\
  28310. !*** ./src/dom_components/model/ComponentImage.js ***!
  28311. \****************************************************/
  28312. /*! exports provided: default */
  28313. /***/ (function(module, __webpack_exports__, __webpack_require__) {
  28314. "use strict";
  28315. __webpack_require__.r(__webpack_exports__);
  28316. /* harmony import */ var _babel_runtime_helpers_defineProperty__WEBPACK_IMPORTED_MODULE_0__ = __webpack_require__(/*! @babel/runtime/helpers/defineProperty */ "./node_modules/@babel/runtime/helpers/defineProperty.js");
  28317. /* harmony import */ var _babel_runtime_helpers_defineProperty__WEBPACK_IMPORTED_MODULE_0___default = /*#__PURE__*/__webpack_require__.n(_babel_runtime_helpers_defineProperty__WEBPACK_IMPORTED_MODULE_0__);
  28318. /* harmony import */ var underscore__WEBPACK_IMPORTED_MODULE_1__ = __webpack_require__(/*! underscore */ "./node_modules/underscore/underscore.js");
  28319. /* harmony import */ var underscore__WEBPACK_IMPORTED_MODULE_1___default = /*#__PURE__*/__webpack_require__.n(underscore__WEBPACK_IMPORTED_MODULE_1__);
  28320. /* harmony import */ var _Component__WEBPACK_IMPORTED_MODULE_2__ = __webpack_require__(/*! ./Component */ "./src/dom_components/model/Component.js");
  28321. function ownKeys(object, enumerableOnly) { var keys = Object.keys(object); if (Object.getOwnPropertySymbols) { var symbols = Object.getOwnPropertySymbols(object); if (enumerableOnly) symbols = symbols.filter(function (sym) { return Object.getOwnPropertyDescriptor(object, sym).enumerable; }); keys.push.apply(keys, symbols); } return keys; }
  28322. function _objectSpread(target) { for (var i = 1; i < arguments.length; i++) { var source = arguments[i] != null ? arguments[i] : {}; if (i % 2) { ownKeys(source, true).forEach(function (key) { _babel_runtime_helpers_defineProperty__WEBPACK_IMPORTED_MODULE_0___default()(target, key, source[key]); }); } else if (Object.getOwnPropertyDescriptors) { Object.defineProperties(target, Object.getOwnPropertyDescriptors(source)); } else { ownKeys(source).forEach(function (key) { Object.defineProperty(target, key, Object.getOwnPropertyDescriptor(source, key)); }); } } return target; }
  28323. var svgAttrs = 'xmlns="http://www.w3.org/2000/svg" width="100" viewBox="0 0 24 24" style="fill: rgba(0,0,0,0.15); transform: scale(0.75)"';
  28324. /* harmony default export */ __webpack_exports__["default"] = (_Component__WEBPACK_IMPORTED_MODULE_2__["default"].extend({
  28325. defaults: _objectSpread({}, _Component__WEBPACK_IMPORTED_MODULE_2__["default"].prototype.defaults, {
  28326. type: 'image',
  28327. tagName: 'img',
  28328. void: 1,
  28329. droppable: 0,
  28330. editable: 1,
  28331. highlightable: 0,
  28332. resizable: {
  28333. ratioDefault: 1
  28334. },
  28335. traits: ['alt'],
  28336. src: "<svg ".concat(svgAttrs, ">\n <path d=\"M8.5 13.5l2.5 3 3.5-4.5 4.5 6H5m16 1V5a2 2 0 0 0-2-2H5c-1.1 0-2 .9-2 2v14c0 1.1.9 2 2 2h14c1.1 0 2-.9 2-2z\"></path>\n </svg>"),
  28337. // Fallback image in case the src can't be loaded
  28338. // If you use SVG, xmlns="http://www.w3.org/2000/svg" is required
  28339. fallback: "<svg ".concat(svgAttrs, ">\n <path d=\"M2.28 3L1 4.27l2 2V19c0 1.1.9 2 2 2h12.73l2 2L21 21.72 2.28 3m2.55 0L21 19.17V5a2 2 0 0 0-2-2H4.83M8.5 13.5l2.5 3 1-1.25L14.73 18H5l3.5-4.5z\"></path>\n </svg>"),
  28340. // File to load asynchronously once the model is rendered
  28341. file: ''
  28342. }),
  28343. initialize: function initialize(o, opt) {
  28344. _Component__WEBPACK_IMPORTED_MODULE_2__["default"].prototype.initialize.apply(this, arguments);
  28345. var attr = this.get('attributes');
  28346. if (attr.src) this.set('src', attr.src);
  28347. },
  28348. initToolbar: function initToolbar() {
  28349. for (var _len = arguments.length, args = new Array(_len), _key = 0; _key < _len; _key++) {
  28350. args[_key] = arguments[_key];
  28351. }
  28352. _Component__WEBPACK_IMPORTED_MODULE_2__["default"].prototype.initToolbar.apply(this, args);
  28353. var em = this.em;
  28354. if (em) {
  28355. var cmd = em.get('Commands');
  28356. var cmdName = 'image-editor'; // Add Image Editor button only if the default command exists
  28357. if (cmd.has(cmdName)) {
  28358. var hasButtonBool = false;
  28359. var tb = this.get('toolbar');
  28360. for (var i = 0; i < tb.length; i++) {
  28361. if (tb[i].command === 'image-editor') {
  28362. hasButtonBool = true;
  28363. break;
  28364. }
  28365. }
  28366. if (!hasButtonBool) {
  28367. tb.push({
  28368. attributes: {
  28369. class: 'fa fa-pencil'
  28370. },
  28371. command: cmdName
  28372. });
  28373. this.set('toolbar', tb);
  28374. }
  28375. }
  28376. }
  28377. },
  28378. /**
  28379. * Returns object of attributes for HTML
  28380. * @return {Object}
  28381. * @private
  28382. */
  28383. getAttrToHTML: function getAttrToHTML() {
  28384. for (var _len2 = arguments.length, args = new Array(_len2), _key2 = 0; _key2 < _len2; _key2++) {
  28385. args[_key2] = arguments[_key2];
  28386. }
  28387. var attr = _Component__WEBPACK_IMPORTED_MODULE_2__["default"].prototype.getAttrToHTML.apply(this, args);
  28388. var src = this.getSrcResult();
  28389. if (src) attr.src = src;
  28390. return attr;
  28391. },
  28392. getSrcResult: function getSrcResult() {
  28393. var opt = arguments.length > 0 && arguments[0] !== undefined ? arguments[0] : {};
  28394. var src = this.get(opt.fallback ? 'fallback' : 'src') || '';
  28395. var result = src;
  28396. if (src && src.substr(0, 4) === '<svg') {
  28397. result = "data:image/svg+xml;base64,".concat(window.btoa(src));
  28398. }
  28399. return result;
  28400. },
  28401. isDefaultSrc: function isDefaultSrc() {
  28402. return this.get('src') === Object(underscore__WEBPACK_IMPORTED_MODULE_1__["result"])(this, 'defaults').src;
  28403. },
  28404. /**
  28405. * Parse uri
  28406. * @param {string} uri
  28407. * @return {object}
  28408. * @private
  28409. */
  28410. parseUri: function parseUri(uri) {
  28411. var el = document.createElement('a');
  28412. el.href = uri;
  28413. var query = {};
  28414. var qrs = el.search.substring(1).split('&');
  28415. for (var i = 0; i < qrs.length; i++) {
  28416. var pair = qrs[i].split('=');
  28417. var name = decodeURIComponent(pair[0]);
  28418. if (name) query[name] = decodeURIComponent(pair[1]);
  28419. }
  28420. return {
  28421. hostname: el.hostname,
  28422. pathname: el.pathname,
  28423. protocol: el.protocol,
  28424. search: el.search,
  28425. hash: el.hash,
  28426. port: el.port,
  28427. query: query
  28428. };
  28429. }
  28430. }, {
  28431. /**
  28432. * Detect if the passed element is a valid component.
  28433. * In case the element is valid an object abstracted
  28434. * from the element will be returned
  28435. * @param {HTMLElement}
  28436. * @return {Object}
  28437. * @private
  28438. */
  28439. isComponent: function isComponent(el) {
  28440. var result = '';
  28441. if (el.tagName == 'IMG') {
  28442. result = {
  28443. type: 'image'
  28444. };
  28445. }
  28446. return result;
  28447. }
  28448. }));
  28449. /***/ }),
  28450. /***/ "./src/dom_components/model/ComponentLabel.js":
  28451. /*!****************************************************!*\
  28452. !*** ./src/dom_components/model/ComponentLabel.js ***!
  28453. \****************************************************/
  28454. /*! exports provided: default */
  28455. /***/ (function(module, __webpack_exports__, __webpack_require__) {
  28456. "use strict";
  28457. __webpack_require__.r(__webpack_exports__);
  28458. /* harmony import */ var _babel_runtime_helpers_defineProperty__WEBPACK_IMPORTED_MODULE_0__ = __webpack_require__(/*! @babel/runtime/helpers/defineProperty */ "./node_modules/@babel/runtime/helpers/defineProperty.js");
  28459. /* harmony import */ var _babel_runtime_helpers_defineProperty__WEBPACK_IMPORTED_MODULE_0___default = /*#__PURE__*/__webpack_require__.n(_babel_runtime_helpers_defineProperty__WEBPACK_IMPORTED_MODULE_0__);
  28460. /* harmony import */ var _ComponentText__WEBPACK_IMPORTED_MODULE_1__ = __webpack_require__(/*! ./ComponentText */ "./src/dom_components/model/ComponentText.js");
  28461. function ownKeys(object, enumerableOnly) { var keys = Object.keys(object); if (Object.getOwnPropertySymbols) { var symbols = Object.getOwnPropertySymbols(object); if (enumerableOnly) symbols = symbols.filter(function (sym) { return Object.getOwnPropertyDescriptor(object, sym).enumerable; }); keys.push.apply(keys, symbols); } return keys; }
  28462. function _objectSpread(target) { for (var i = 1; i < arguments.length; i++) { var source = arguments[i] != null ? arguments[i] : {}; if (i % 2) { ownKeys(source, true).forEach(function (key) { _babel_runtime_helpers_defineProperty__WEBPACK_IMPORTED_MODULE_0___default()(target, key, source[key]); }); } else if (Object.getOwnPropertyDescriptors) { Object.defineProperties(target, Object.getOwnPropertyDescriptors(source)); } else { ownKeys(source).forEach(function (key) { Object.defineProperty(target, key, Object.getOwnPropertyDescriptor(source, key)); }); } } return target; }
  28463. /* harmony default export */ __webpack_exports__["default"] = (_ComponentText__WEBPACK_IMPORTED_MODULE_1__["default"].extend({
  28464. defaults: _objectSpread({}, _ComponentText__WEBPACK_IMPORTED_MODULE_1__["default"].prototype.defaults, {
  28465. tagName: 'label',
  28466. traits: ['id', 'title', 'for']
  28467. })
  28468. }, {
  28469. isComponent: function isComponent(el) {
  28470. if (el.tagName == 'LABEL') {
  28471. return {
  28472. type: 'label'
  28473. };
  28474. }
  28475. }
  28476. }));
  28477. /***/ }),
  28478. /***/ "./src/dom_components/model/ComponentLink.js":
  28479. /*!***************************************************!*\
  28480. !*** ./src/dom_components/model/ComponentLink.js ***!
  28481. \***************************************************/
  28482. /*! exports provided: default */
  28483. /***/ (function(module, __webpack_exports__, __webpack_require__) {
  28484. "use strict";
  28485. __webpack_require__.r(__webpack_exports__);
  28486. /* harmony import */ var _babel_runtime_helpers_defineProperty__WEBPACK_IMPORTED_MODULE_0__ = __webpack_require__(/*! @babel/runtime/helpers/defineProperty */ "./node_modules/@babel/runtime/helpers/defineProperty.js");
  28487. /* harmony import */ var _babel_runtime_helpers_defineProperty__WEBPACK_IMPORTED_MODULE_0___default = /*#__PURE__*/__webpack_require__.n(_babel_runtime_helpers_defineProperty__WEBPACK_IMPORTED_MODULE_0__);
  28488. /* harmony import */ var _ComponentText__WEBPACK_IMPORTED_MODULE_1__ = __webpack_require__(/*! ./ComponentText */ "./src/dom_components/model/ComponentText.js");
  28489. function ownKeys(object, enumerableOnly) { var keys = Object.keys(object); if (Object.getOwnPropertySymbols) { var symbols = Object.getOwnPropertySymbols(object); if (enumerableOnly) symbols = symbols.filter(function (sym) { return Object.getOwnPropertyDescriptor(object, sym).enumerable; }); keys.push.apply(keys, symbols); } return keys; }
  28490. function _objectSpread(target) { for (var i = 1; i < arguments.length; i++) { var source = arguments[i] != null ? arguments[i] : {}; if (i % 2) { ownKeys(source, true).forEach(function (key) { _babel_runtime_helpers_defineProperty__WEBPACK_IMPORTED_MODULE_0___default()(target, key, source[key]); }); } else if (Object.getOwnPropertyDescriptors) { Object.defineProperties(target, Object.getOwnPropertyDescriptors(source)); } else { ownKeys(source).forEach(function (key) { Object.defineProperty(target, key, Object.getOwnPropertyDescriptor(source, key)); }); } } return target; }
  28491. /* harmony default export */ __webpack_exports__["default"] = (_ComponentText__WEBPACK_IMPORTED_MODULE_1__["default"].extend({
  28492. defaults: _objectSpread({}, _ComponentText__WEBPACK_IMPORTED_MODULE_1__["default"].prototype.defaults, {
  28493. type: 'link',
  28494. tagName: 'a',
  28495. traits: ['title', 'href', 'target']
  28496. }),
  28497. /**
  28498. * Returns object of attributes for HTML
  28499. * @return {Object}
  28500. * @private
  28501. */
  28502. getAttrToHTML: function getAttrToHTML() {
  28503. for (var _len = arguments.length, args = new Array(_len), _key = 0; _key < _len; _key++) {
  28504. args[_key] = arguments[_key];
  28505. }
  28506. var attr = _ComponentText__WEBPACK_IMPORTED_MODULE_1__["default"].prototype.getAttrToHTML.apply(this, args);
  28507. delete attr.onmousedown;
  28508. return attr;
  28509. }
  28510. }, {
  28511. isComponent: function isComponent(el) {
  28512. var result;
  28513. var avoidEdit;
  28514. if (el.tagName == 'A') {
  28515. result = {
  28516. type: 'link',
  28517. editable: 0
  28518. }; // The link is editable only if, at least, one of its
  28519. // children is a text node (not empty one)
  28520. var children = el.childNodes;
  28521. var len = children.length;
  28522. if (!len) delete result.editable;
  28523. for (var i = 0; i < len; i++) {
  28524. var child = children[i];
  28525. if (child.nodeType == 3 && child.textContent.trim() != '') {
  28526. delete result.editable;
  28527. break;
  28528. }
  28529. }
  28530. }
  28531. return result;
  28532. }
  28533. }));
  28534. /***/ }),
  28535. /***/ "./src/dom_components/model/ComponentMap.js":
  28536. /*!**************************************************!*\
  28537. !*** ./src/dom_components/model/ComponentMap.js ***!
  28538. \**************************************************/
  28539. /*! exports provided: default */
  28540. /***/ (function(module, __webpack_exports__, __webpack_require__) {
  28541. "use strict";
  28542. __webpack_require__.r(__webpack_exports__);
  28543. /* harmony import */ var _babel_runtime_helpers_defineProperty__WEBPACK_IMPORTED_MODULE_0__ = __webpack_require__(/*! @babel/runtime/helpers/defineProperty */ "./node_modules/@babel/runtime/helpers/defineProperty.js");
  28544. /* harmony import */ var _babel_runtime_helpers_defineProperty__WEBPACK_IMPORTED_MODULE_0___default = /*#__PURE__*/__webpack_require__.n(_babel_runtime_helpers_defineProperty__WEBPACK_IMPORTED_MODULE_0__);
  28545. /* harmony import */ var _ComponentImage__WEBPACK_IMPORTED_MODULE_1__ = __webpack_require__(/*! ./ComponentImage */ "./src/dom_components/model/ComponentImage.js");
  28546. /* harmony import */ var _Component__WEBPACK_IMPORTED_MODULE_2__ = __webpack_require__(/*! ./Component */ "./src/dom_components/model/Component.js");
  28547. function ownKeys(object, enumerableOnly) { var keys = Object.keys(object); if (Object.getOwnPropertySymbols) { var symbols = Object.getOwnPropertySymbols(object); if (enumerableOnly) symbols = symbols.filter(function (sym) { return Object.getOwnPropertyDescriptor(object, sym).enumerable; }); keys.push.apply(keys, symbols); } return keys; }
  28548. function _objectSpread(target) { for (var i = 1; i < arguments.length; i++) { var source = arguments[i] != null ? arguments[i] : {}; if (i % 2) { ownKeys(source, true).forEach(function (key) { _babel_runtime_helpers_defineProperty__WEBPACK_IMPORTED_MODULE_0___default()(target, key, source[key]); }); } else if (Object.getOwnPropertyDescriptors) { Object.defineProperties(target, Object.getOwnPropertyDescriptors(source)); } else { ownKeys(source).forEach(function (key) { Object.defineProperty(target, key, Object.getOwnPropertyDescriptor(source, key)); }); } } return target; }
  28549. /* harmony default export */ __webpack_exports__["default"] = (_ComponentImage__WEBPACK_IMPORTED_MODULE_1__["default"].extend({
  28550. defaults: _objectSpread({}, _ComponentImage__WEBPACK_IMPORTED_MODULE_1__["default"].prototype.defaults, {
  28551. type: 'map',
  28552. src: '',
  28553. void: 0,
  28554. mapUrl: 'https://maps.google.com/maps',
  28555. tagName: 'iframe',
  28556. mapType: 'q',
  28557. address: '',
  28558. zoom: '1',
  28559. attributes: {
  28560. frameborder: 0
  28561. },
  28562. toolbar: _Component__WEBPACK_IMPORTED_MODULE_2__["default"].prototype.defaults.toolbar,
  28563. traits: [{
  28564. label: 'Address',
  28565. name: 'address',
  28566. placeholder: 'eg. London, UK',
  28567. changeProp: 1
  28568. }, {
  28569. type: 'select',
  28570. label: 'Map type',
  28571. name: 'mapType',
  28572. changeProp: 1,
  28573. options: [{
  28574. value: 'q',
  28575. name: 'Roadmap'
  28576. }, {
  28577. value: 'w',
  28578. name: 'Satellite'
  28579. }]
  28580. }, {
  28581. label: 'Zoom',
  28582. name: 'zoom',
  28583. type: 'range',
  28584. min: '1',
  28585. max: '20',
  28586. changeProp: 1
  28587. }]
  28588. }),
  28589. initialize: function initialize(o, opt) {
  28590. if (this.get('src')) this.parseFromSrc();else this.updateSrc();
  28591. _ComponentImage__WEBPACK_IMPORTED_MODULE_1__["default"].prototype.initialize.apply(this, arguments);
  28592. this.listenTo(this, 'change:address change:zoom change:mapType', this.updateSrc);
  28593. },
  28594. updateSrc: function updateSrc() {
  28595. this.set('src', this.getMapUrl());
  28596. },
  28597. /**
  28598. * Returns url of the map
  28599. * @return {string}
  28600. * @private
  28601. */
  28602. getMapUrl: function getMapUrl() {
  28603. var md = this;
  28604. var addr = md.get('address');
  28605. var zoom = md.get('zoom');
  28606. var type = md.get('mapType');
  28607. var size = '';
  28608. addr = addr ? '&q=' + addr : '';
  28609. zoom = zoom ? '&z=' + zoom : '';
  28610. type = type ? '&t=' + type : '';
  28611. var result = md.get('mapUrl') + '?' + addr + zoom + type;
  28612. result += '&output=embed';
  28613. return result;
  28614. },
  28615. /**
  28616. * Set attributes by src string
  28617. * @private
  28618. */
  28619. parseFromSrc: function parseFromSrc() {
  28620. var uri = this.parseUri(this.get('src'));
  28621. var qr = uri.query;
  28622. if (qr.q) this.set('address', qr.q);
  28623. if (qr.z) this.set('zoom', qr.z);
  28624. if (qr.t) this.set('mapType', qr.t);
  28625. }
  28626. }, {
  28627. /**
  28628. * Detect if the passed element is a valid component.
  28629. * In case the element is valid an object abstracted
  28630. * from the element will be returned
  28631. * @param {HTMLElement}
  28632. * @return {Object}
  28633. * @private
  28634. */
  28635. isComponent: function isComponent(el) {
  28636. var result = '';
  28637. if (el.tagName == 'IFRAME' && /maps\.google\.com/.test(el.src)) {
  28638. result = {
  28639. type: 'map',
  28640. src: el.src
  28641. };
  28642. }
  28643. return result;
  28644. }
  28645. }));
  28646. /***/ }),
  28647. /***/ "./src/dom_components/model/ComponentScript.js":
  28648. /*!*****************************************************!*\
  28649. !*** ./src/dom_components/model/ComponentScript.js ***!
  28650. \*****************************************************/
  28651. /*! exports provided: default */
  28652. /***/ (function(module, __webpack_exports__, __webpack_require__) {
  28653. "use strict";
  28654. __webpack_require__.r(__webpack_exports__);
  28655. /* harmony import */ var _babel_runtime_helpers_defineProperty__WEBPACK_IMPORTED_MODULE_0__ = __webpack_require__(/*! @babel/runtime/helpers/defineProperty */ "./node_modules/@babel/runtime/helpers/defineProperty.js");
  28656. /* harmony import */ var _babel_runtime_helpers_defineProperty__WEBPACK_IMPORTED_MODULE_0___default = /*#__PURE__*/__webpack_require__.n(_babel_runtime_helpers_defineProperty__WEBPACK_IMPORTED_MODULE_0__);
  28657. /* harmony import */ var _Component__WEBPACK_IMPORTED_MODULE_1__ = __webpack_require__(/*! ./Component */ "./src/dom_components/model/Component.js");
  28658. function ownKeys(object, enumerableOnly) { var keys = Object.keys(object); if (Object.getOwnPropertySymbols) { var symbols = Object.getOwnPropertySymbols(object); if (enumerableOnly) symbols = symbols.filter(function (sym) { return Object.getOwnPropertyDescriptor(object, sym).enumerable; }); keys.push.apply(keys, symbols); } return keys; }
  28659. function _objectSpread(target) { for (var i = 1; i < arguments.length; i++) { var source = arguments[i] != null ? arguments[i] : {}; if (i % 2) { ownKeys(source, true).forEach(function (key) { _babel_runtime_helpers_defineProperty__WEBPACK_IMPORTED_MODULE_0___default()(target, key, source[key]); }); } else if (Object.getOwnPropertyDescriptors) { Object.defineProperties(target, Object.getOwnPropertyDescriptors(source)); } else { ownKeys(source).forEach(function (key) { Object.defineProperty(target, key, Object.getOwnPropertyDescriptor(source, key)); }); } } return target; }
  28660. /* harmony default export */ __webpack_exports__["default"] = (_Component__WEBPACK_IMPORTED_MODULE_1__["default"].extend({
  28661. defaults: _objectSpread({}, _Component__WEBPACK_IMPORTED_MODULE_1__["default"].prototype.defaults, {
  28662. type: 'script',
  28663. droppable: false,
  28664. draggable: false,
  28665. layerable: false
  28666. })
  28667. }, {
  28668. isComponent: function isComponent(el) {
  28669. if (el.tagName == 'SCRIPT') {
  28670. var result = {
  28671. type: 'script'
  28672. };
  28673. if (el.src) {
  28674. result.src = el.src;
  28675. result.onload = el.onload;
  28676. }
  28677. return result;
  28678. }
  28679. }
  28680. }));
  28681. /***/ }),
  28682. /***/ "./src/dom_components/model/ComponentSvg.js":
  28683. /*!**************************************************!*\
  28684. !*** ./src/dom_components/model/ComponentSvg.js ***!
  28685. \**************************************************/
  28686. /*! exports provided: default */
  28687. /***/ (function(module, __webpack_exports__, __webpack_require__) {
  28688. "use strict";
  28689. __webpack_require__.r(__webpack_exports__);
  28690. /* harmony import */ var _babel_runtime_helpers_defineProperty__WEBPACK_IMPORTED_MODULE_0__ = __webpack_require__(/*! @babel/runtime/helpers/defineProperty */ "./node_modules/@babel/runtime/helpers/defineProperty.js");
  28691. /* harmony import */ var _babel_runtime_helpers_defineProperty__WEBPACK_IMPORTED_MODULE_0___default = /*#__PURE__*/__webpack_require__.n(_babel_runtime_helpers_defineProperty__WEBPACK_IMPORTED_MODULE_0__);
  28692. /* harmony import */ var _Component__WEBPACK_IMPORTED_MODULE_1__ = __webpack_require__(/*! ./Component */ "./src/dom_components/model/Component.js");
  28693. function ownKeys(object, enumerableOnly) { var keys = Object.keys(object); if (Object.getOwnPropertySymbols) { var symbols = Object.getOwnPropertySymbols(object); if (enumerableOnly) symbols = symbols.filter(function (sym) { return Object.getOwnPropertyDescriptor(object, sym).enumerable; }); keys.push.apply(keys, symbols); } return keys; }
  28694. function _objectSpread(target) { for (var i = 1; i < arguments.length; i++) { var source = arguments[i] != null ? arguments[i] : {}; if (i % 2) { ownKeys(source, true).forEach(function (key) { _babel_runtime_helpers_defineProperty__WEBPACK_IMPORTED_MODULE_0___default()(target, key, source[key]); }); } else if (Object.getOwnPropertyDescriptors) { Object.defineProperties(target, Object.getOwnPropertyDescriptors(source)); } else { ownKeys(source).forEach(function (key) { Object.defineProperty(target, key, Object.getOwnPropertyDescriptor(source, key)); }); } } return target; }
  28695. /* harmony default export */ __webpack_exports__["default"] = (_Component__WEBPACK_IMPORTED_MODULE_1__["default"].extend({
  28696. defaults: _objectSpread({}, _Component__WEBPACK_IMPORTED_MODULE_1__["default"].prototype.defaults, {
  28697. resizable: {
  28698. ratioDefault: 1
  28699. },
  28700. highlightable: 0
  28701. }),
  28702. getName: function getName() {
  28703. var name = this.get('tagName');
  28704. var customName = this.get('custom-name');
  28705. name = name.charAt(0).toUpperCase() + name.slice(1);
  28706. return customName || name;
  28707. }
  28708. }, {
  28709. isComponent: function isComponent(el) {
  28710. if (SVGElement && el instanceof SVGElement) {
  28711. return {
  28712. tagName: el.tagName,
  28713. type: 'svg'
  28714. };
  28715. }
  28716. }
  28717. }));
  28718. /***/ }),
  28719. /***/ "./src/dom_components/model/ComponentSvgIn.js":
  28720. /*!****************************************************!*\
  28721. !*** ./src/dom_components/model/ComponentSvgIn.js ***!
  28722. \****************************************************/
  28723. /*! exports provided: default */
  28724. /***/ (function(module, __webpack_exports__, __webpack_require__) {
  28725. "use strict";
  28726. __webpack_require__.r(__webpack_exports__);
  28727. /* harmony import */ var _babel_runtime_helpers_defineProperty__WEBPACK_IMPORTED_MODULE_0__ = __webpack_require__(/*! @babel/runtime/helpers/defineProperty */ "./node_modules/@babel/runtime/helpers/defineProperty.js");
  28728. /* harmony import */ var _babel_runtime_helpers_defineProperty__WEBPACK_IMPORTED_MODULE_0___default = /*#__PURE__*/__webpack_require__.n(_babel_runtime_helpers_defineProperty__WEBPACK_IMPORTED_MODULE_0__);
  28729. /* harmony import */ var _ComponentSvg__WEBPACK_IMPORTED_MODULE_1__ = __webpack_require__(/*! ./ComponentSvg */ "./src/dom_components/model/ComponentSvg.js");
  28730. function ownKeys(object, enumerableOnly) { var keys = Object.keys(object); if (Object.getOwnPropertySymbols) { var symbols = Object.getOwnPropertySymbols(object); if (enumerableOnly) symbols = symbols.filter(function (sym) { return Object.getOwnPropertyDescriptor(object, sym).enumerable; }); keys.push.apply(keys, symbols); } return keys; }
  28731. function _objectSpread(target) { for (var i = 1; i < arguments.length; i++) { var source = arguments[i] != null ? arguments[i] : {}; if (i % 2) { ownKeys(source, true).forEach(function (key) { _babel_runtime_helpers_defineProperty__WEBPACK_IMPORTED_MODULE_0___default()(target, key, source[key]); }); } else if (Object.getOwnPropertyDescriptors) { Object.defineProperties(target, Object.getOwnPropertyDescriptors(source)); } else { ownKeys(source).forEach(function (key) { Object.defineProperty(target, key, Object.getOwnPropertyDescriptor(source, key)); }); } } return target; }
  28732. /**
  28733. * Component for inner SVG elements
  28734. */
  28735. /* harmony default export */ __webpack_exports__["default"] = (_ComponentSvg__WEBPACK_IMPORTED_MODULE_1__["default"].extend({
  28736. defaults: _objectSpread({}, _ComponentSvg__WEBPACK_IMPORTED_MODULE_1__["default"].prototype.defaults, {
  28737. selectable: false,
  28738. hoverable: false,
  28739. layerable: false
  28740. })
  28741. }, {
  28742. isComponent: function isComponent(el) {
  28743. if (_ComponentSvg__WEBPACK_IMPORTED_MODULE_1__["default"].isComponent(el) && el.tagName.toLowerCase() !== 'svg') {
  28744. return {
  28745. tagName: el.tagName,
  28746. type: 'svg-in'
  28747. };
  28748. }
  28749. }
  28750. }));
  28751. /***/ }),
  28752. /***/ "./src/dom_components/model/ComponentTable.js":
  28753. /*!****************************************************!*\
  28754. !*** ./src/dom_components/model/ComponentTable.js ***!
  28755. \****************************************************/
  28756. /*! exports provided: default */
  28757. /***/ (function(module, __webpack_exports__, __webpack_require__) {
  28758. "use strict";
  28759. __webpack_require__.r(__webpack_exports__);
  28760. /* harmony import */ var _babel_runtime_helpers_defineProperty__WEBPACK_IMPORTED_MODULE_0__ = __webpack_require__(/*! @babel/runtime/helpers/defineProperty */ "./node_modules/@babel/runtime/helpers/defineProperty.js");
  28761. /* harmony import */ var _babel_runtime_helpers_defineProperty__WEBPACK_IMPORTED_MODULE_0___default = /*#__PURE__*/__webpack_require__.n(_babel_runtime_helpers_defineProperty__WEBPACK_IMPORTED_MODULE_0__);
  28762. /* harmony import */ var _Component__WEBPACK_IMPORTED_MODULE_1__ = __webpack_require__(/*! ./Component */ "./src/dom_components/model/Component.js");
  28763. function ownKeys(object, enumerableOnly) { var keys = Object.keys(object); if (Object.getOwnPropertySymbols) { var symbols = Object.getOwnPropertySymbols(object); if (enumerableOnly) symbols = symbols.filter(function (sym) { return Object.getOwnPropertyDescriptor(object, sym).enumerable; }); keys.push.apply(keys, symbols); } return keys; }
  28764. function _objectSpread(target) { for (var i = 1; i < arguments.length; i++) { var source = arguments[i] != null ? arguments[i] : {}; if (i % 2) { ownKeys(source, true).forEach(function (key) { _babel_runtime_helpers_defineProperty__WEBPACK_IMPORTED_MODULE_0___default()(target, key, source[key]); }); } else if (Object.getOwnPropertyDescriptors) { Object.defineProperties(target, Object.getOwnPropertyDescriptors(source)); } else { ownKeys(source).forEach(function (key) { Object.defineProperty(target, key, Object.getOwnPropertyDescriptor(source, key)); }); } } return target; }
  28765. /* harmony default export */ __webpack_exports__["default"] = (_Component__WEBPACK_IMPORTED_MODULE_1__["default"].extend({
  28766. defaults: _objectSpread({}, _Component__WEBPACK_IMPORTED_MODULE_1__["default"].prototype.defaults, {
  28767. type: 'table',
  28768. tagName: 'table',
  28769. droppable: ['tbody', 'thead', 'tfoot']
  28770. }),
  28771. initialize: function initialize(o, opt) {
  28772. _Component__WEBPACK_IMPORTED_MODULE_1__["default"].prototype.initialize.apply(this, arguments);
  28773. var components = this.get('components');
  28774. !components.length && components.add({
  28775. type: 'tbody'
  28776. });
  28777. }
  28778. }, {
  28779. isComponent: function isComponent(el) {
  28780. var result = '';
  28781. if (el.tagName == 'TABLE') {
  28782. result = {
  28783. type: 'table'
  28784. };
  28785. }
  28786. return result;
  28787. }
  28788. }));
  28789. /***/ }),
  28790. /***/ "./src/dom_components/model/ComponentTableBody.js":
  28791. /*!********************************************************!*\
  28792. !*** ./src/dom_components/model/ComponentTableBody.js ***!
  28793. \********************************************************/
  28794. /*! exports provided: default */
  28795. /***/ (function(module, __webpack_exports__, __webpack_require__) {
  28796. "use strict";
  28797. __webpack_require__.r(__webpack_exports__);
  28798. /* harmony import */ var _babel_runtime_helpers_defineProperty__WEBPACK_IMPORTED_MODULE_0__ = __webpack_require__(/*! @babel/runtime/helpers/defineProperty */ "./node_modules/@babel/runtime/helpers/defineProperty.js");
  28799. /* harmony import */ var _babel_runtime_helpers_defineProperty__WEBPACK_IMPORTED_MODULE_0___default = /*#__PURE__*/__webpack_require__.n(_babel_runtime_helpers_defineProperty__WEBPACK_IMPORTED_MODULE_0__);
  28800. /* harmony import */ var _Component__WEBPACK_IMPORTED_MODULE_1__ = __webpack_require__(/*! ./Component */ "./src/dom_components/model/Component.js");
  28801. function ownKeys(object, enumerableOnly) { var keys = Object.keys(object); if (Object.getOwnPropertySymbols) { var symbols = Object.getOwnPropertySymbols(object); if (enumerableOnly) symbols = symbols.filter(function (sym) { return Object.getOwnPropertyDescriptor(object, sym).enumerable; }); keys.push.apply(keys, symbols); } return keys; }
  28802. function _objectSpread(target) { for (var i = 1; i < arguments.length; i++) { var source = arguments[i] != null ? arguments[i] : {}; if (i % 2) { ownKeys(source, true).forEach(function (key) { _babel_runtime_helpers_defineProperty__WEBPACK_IMPORTED_MODULE_0___default()(target, key, source[key]); }); } else if (Object.getOwnPropertyDescriptors) { Object.defineProperties(target, Object.getOwnPropertyDescriptors(source)); } else { ownKeys(source).forEach(function (key) { Object.defineProperty(target, key, Object.getOwnPropertyDescriptor(source, key)); }); } } return target; }
  28803. /* harmony default export */ __webpack_exports__["default"] = (_Component__WEBPACK_IMPORTED_MODULE_1__["default"].extend({
  28804. defaults: _objectSpread({}, _Component__WEBPACK_IMPORTED_MODULE_1__["default"].prototype.defaults, {
  28805. type: 'tbody',
  28806. tagName: 'tbody',
  28807. draggable: ['table'],
  28808. droppable: ['tr'],
  28809. columns: 1,
  28810. rows: 1
  28811. }),
  28812. initialize: function initialize(o, opt) {
  28813. _Component__WEBPACK_IMPORTED_MODULE_1__["default"].prototype.initialize.apply(this, arguments);
  28814. var components = this.get('components');
  28815. var columns = this.get('columns');
  28816. var rows = this.get('rows'); // Init components if empty
  28817. if (!components.length) {
  28818. var rowsToAdd = [];
  28819. while (rows--) {
  28820. var columnsToAdd = [];
  28821. var clm = columns;
  28822. while (clm--) {
  28823. columnsToAdd.push({
  28824. type: 'cell',
  28825. classes: ['cell']
  28826. });
  28827. }
  28828. rowsToAdd.push({
  28829. type: 'row',
  28830. classes: ['row'],
  28831. components: columnsToAdd
  28832. });
  28833. }
  28834. components.add(rowsToAdd);
  28835. }
  28836. }
  28837. }, {
  28838. isComponent: function isComponent(el) {
  28839. var result = '';
  28840. if (el.tagName == 'TBODY') {
  28841. result = {
  28842. type: 'tbody'
  28843. };
  28844. }
  28845. return result;
  28846. }
  28847. }));
  28848. /***/ }),
  28849. /***/ "./src/dom_components/model/ComponentTableCell.js":
  28850. /*!********************************************************!*\
  28851. !*** ./src/dom_components/model/ComponentTableCell.js ***!
  28852. \********************************************************/
  28853. /*! exports provided: default */
  28854. /***/ (function(module, __webpack_exports__, __webpack_require__) {
  28855. "use strict";
  28856. __webpack_require__.r(__webpack_exports__);
  28857. /* harmony import */ var _babel_runtime_helpers_defineProperty__WEBPACK_IMPORTED_MODULE_0__ = __webpack_require__(/*! @babel/runtime/helpers/defineProperty */ "./node_modules/@babel/runtime/helpers/defineProperty.js");
  28858. /* harmony import */ var _babel_runtime_helpers_defineProperty__WEBPACK_IMPORTED_MODULE_0___default = /*#__PURE__*/__webpack_require__.n(_babel_runtime_helpers_defineProperty__WEBPACK_IMPORTED_MODULE_0__);
  28859. /* harmony import */ var _Component__WEBPACK_IMPORTED_MODULE_1__ = __webpack_require__(/*! ./Component */ "./src/dom_components/model/Component.js");
  28860. function ownKeys(object, enumerableOnly) { var keys = Object.keys(object); if (Object.getOwnPropertySymbols) { var symbols = Object.getOwnPropertySymbols(object); if (enumerableOnly) symbols = symbols.filter(function (sym) { return Object.getOwnPropertyDescriptor(object, sym).enumerable; }); keys.push.apply(keys, symbols); } return keys; }
  28861. function _objectSpread(target) { for (var i = 1; i < arguments.length; i++) { var source = arguments[i] != null ? arguments[i] : {}; if (i % 2) { ownKeys(source, true).forEach(function (key) { _babel_runtime_helpers_defineProperty__WEBPACK_IMPORTED_MODULE_0___default()(target, key, source[key]); }); } else if (Object.getOwnPropertyDescriptors) { Object.defineProperties(target, Object.getOwnPropertyDescriptors(source)); } else { ownKeys(source).forEach(function (key) { Object.defineProperty(target, key, Object.getOwnPropertyDescriptor(source, key)); }); } } return target; }
  28862. /* harmony default export */ __webpack_exports__["default"] = (_Component__WEBPACK_IMPORTED_MODULE_1__["default"].extend({
  28863. defaults: _objectSpread({}, _Component__WEBPACK_IMPORTED_MODULE_1__["default"].prototype.defaults, {
  28864. type: 'cell',
  28865. tagName: 'td',
  28866. draggable: ['tr']
  28867. })
  28868. }, {
  28869. isComponent: function isComponent(el) {
  28870. var result = '';
  28871. var tag = el.tagName;
  28872. if (tag == 'TD' || tag == 'TH') {
  28873. result = {
  28874. type: 'cell',
  28875. tagName: tag.toLowerCase()
  28876. };
  28877. }
  28878. return result;
  28879. }
  28880. }));
  28881. /***/ }),
  28882. /***/ "./src/dom_components/model/ComponentTableFoot.js":
  28883. /*!********************************************************!*\
  28884. !*** ./src/dom_components/model/ComponentTableFoot.js ***!
  28885. \********************************************************/
  28886. /*! exports provided: default */
  28887. /***/ (function(module, __webpack_exports__, __webpack_require__) {
  28888. "use strict";
  28889. __webpack_require__.r(__webpack_exports__);
  28890. /* harmony import */ var _babel_runtime_helpers_defineProperty__WEBPACK_IMPORTED_MODULE_0__ = __webpack_require__(/*! @babel/runtime/helpers/defineProperty */ "./node_modules/@babel/runtime/helpers/defineProperty.js");
  28891. /* harmony import */ var _babel_runtime_helpers_defineProperty__WEBPACK_IMPORTED_MODULE_0___default = /*#__PURE__*/__webpack_require__.n(_babel_runtime_helpers_defineProperty__WEBPACK_IMPORTED_MODULE_0__);
  28892. /* harmony import */ var _ComponentTableBody__WEBPACK_IMPORTED_MODULE_1__ = __webpack_require__(/*! ./ComponentTableBody */ "./src/dom_components/model/ComponentTableBody.js");
  28893. function ownKeys(object, enumerableOnly) { var keys = Object.keys(object); if (Object.getOwnPropertySymbols) { var symbols = Object.getOwnPropertySymbols(object); if (enumerableOnly) symbols = symbols.filter(function (sym) { return Object.getOwnPropertyDescriptor(object, sym).enumerable; }); keys.push.apply(keys, symbols); } return keys; }
  28894. function _objectSpread(target) { for (var i = 1; i < arguments.length; i++) { var source = arguments[i] != null ? arguments[i] : {}; if (i % 2) { ownKeys(source, true).forEach(function (key) { _babel_runtime_helpers_defineProperty__WEBPACK_IMPORTED_MODULE_0___default()(target, key, source[key]); }); } else if (Object.getOwnPropertyDescriptors) { Object.defineProperties(target, Object.getOwnPropertyDescriptors(source)); } else { ownKeys(source).forEach(function (key) { Object.defineProperty(target, key, Object.getOwnPropertyDescriptor(source, key)); }); } } return target; }
  28895. /* harmony default export */ __webpack_exports__["default"] = (_ComponentTableBody__WEBPACK_IMPORTED_MODULE_1__["default"].extend({
  28896. defaults: _objectSpread({}, _ComponentTableBody__WEBPACK_IMPORTED_MODULE_1__["default"].prototype.defaults, {
  28897. type: 'tfoot',
  28898. tagName: 'tfoot'
  28899. })
  28900. }, {
  28901. isComponent: function isComponent(el) {
  28902. var result = '';
  28903. if (el.tagName == 'TFOOT') {
  28904. result = {
  28905. type: 'tfoot'
  28906. };
  28907. }
  28908. return result;
  28909. }
  28910. }));
  28911. /***/ }),
  28912. /***/ "./src/dom_components/model/ComponentTableHead.js":
  28913. /*!********************************************************!*\
  28914. !*** ./src/dom_components/model/ComponentTableHead.js ***!
  28915. \********************************************************/
  28916. /*! exports provided: default */
  28917. /***/ (function(module, __webpack_exports__, __webpack_require__) {
  28918. "use strict";
  28919. __webpack_require__.r(__webpack_exports__);
  28920. /* harmony import */ var _babel_runtime_helpers_defineProperty__WEBPACK_IMPORTED_MODULE_0__ = __webpack_require__(/*! @babel/runtime/helpers/defineProperty */ "./node_modules/@babel/runtime/helpers/defineProperty.js");
  28921. /* harmony import */ var _babel_runtime_helpers_defineProperty__WEBPACK_IMPORTED_MODULE_0___default = /*#__PURE__*/__webpack_require__.n(_babel_runtime_helpers_defineProperty__WEBPACK_IMPORTED_MODULE_0__);
  28922. /* harmony import */ var _ComponentTableBody__WEBPACK_IMPORTED_MODULE_1__ = __webpack_require__(/*! ./ComponentTableBody */ "./src/dom_components/model/ComponentTableBody.js");
  28923. function ownKeys(object, enumerableOnly) { var keys = Object.keys(object); if (Object.getOwnPropertySymbols) { var symbols = Object.getOwnPropertySymbols(object); if (enumerableOnly) symbols = symbols.filter(function (sym) { return Object.getOwnPropertyDescriptor(object, sym).enumerable; }); keys.push.apply(keys, symbols); } return keys; }
  28924. function _objectSpread(target) { for (var i = 1; i < arguments.length; i++) { var source = arguments[i] != null ? arguments[i] : {}; if (i % 2) { ownKeys(source, true).forEach(function (key) { _babel_runtime_helpers_defineProperty__WEBPACK_IMPORTED_MODULE_0___default()(target, key, source[key]); }); } else if (Object.getOwnPropertyDescriptors) { Object.defineProperties(target, Object.getOwnPropertyDescriptors(source)); } else { ownKeys(source).forEach(function (key) { Object.defineProperty(target, key, Object.getOwnPropertyDescriptor(source, key)); }); } } return target; }
  28925. /* harmony default export */ __webpack_exports__["default"] = (_ComponentTableBody__WEBPACK_IMPORTED_MODULE_1__["default"].extend({
  28926. defaults: _objectSpread({}, _ComponentTableBody__WEBPACK_IMPORTED_MODULE_1__["default"].prototype.defaults, {
  28927. type: 'thead',
  28928. tagName: 'thead'
  28929. })
  28930. }, {
  28931. isComponent: function isComponent(el) {
  28932. var result = '';
  28933. if (el.tagName == 'THEAD') {
  28934. result = {
  28935. type: 'thead'
  28936. };
  28937. }
  28938. return result;
  28939. }
  28940. }));
  28941. /***/ }),
  28942. /***/ "./src/dom_components/model/ComponentTableRow.js":
  28943. /*!*******************************************************!*\
  28944. !*** ./src/dom_components/model/ComponentTableRow.js ***!
  28945. \*******************************************************/
  28946. /*! exports provided: default */
  28947. /***/ (function(module, __webpack_exports__, __webpack_require__) {
  28948. "use strict";
  28949. __webpack_require__.r(__webpack_exports__);
  28950. /* harmony import */ var _babel_runtime_helpers_defineProperty__WEBPACK_IMPORTED_MODULE_0__ = __webpack_require__(/*! @babel/runtime/helpers/defineProperty */ "./node_modules/@babel/runtime/helpers/defineProperty.js");
  28951. /* harmony import */ var _babel_runtime_helpers_defineProperty__WEBPACK_IMPORTED_MODULE_0___default = /*#__PURE__*/__webpack_require__.n(_babel_runtime_helpers_defineProperty__WEBPACK_IMPORTED_MODULE_0__);
  28952. /* harmony import */ var _Component__WEBPACK_IMPORTED_MODULE_1__ = __webpack_require__(/*! ./Component */ "./src/dom_components/model/Component.js");
  28953. function ownKeys(object, enumerableOnly) { var keys = Object.keys(object); if (Object.getOwnPropertySymbols) { var symbols = Object.getOwnPropertySymbols(object); if (enumerableOnly) symbols = symbols.filter(function (sym) { return Object.getOwnPropertyDescriptor(object, sym).enumerable; }); keys.push.apply(keys, symbols); } return keys; }
  28954. function _objectSpread(target) { for (var i = 1; i < arguments.length; i++) { var source = arguments[i] != null ? arguments[i] : {}; if (i % 2) { ownKeys(source, true).forEach(function (key) { _babel_runtime_helpers_defineProperty__WEBPACK_IMPORTED_MODULE_0___default()(target, key, source[key]); }); } else if (Object.getOwnPropertyDescriptors) { Object.defineProperties(target, Object.getOwnPropertyDescriptors(source)); } else { ownKeys(source).forEach(function (key) { Object.defineProperty(target, key, Object.getOwnPropertyDescriptor(source, key)); }); } } return target; }
  28955. /* harmony default export */ __webpack_exports__["default"] = (_Component__WEBPACK_IMPORTED_MODULE_1__["default"].extend({
  28956. defaults: _objectSpread({}, _Component__WEBPACK_IMPORTED_MODULE_1__["default"].prototype.defaults, {
  28957. tagName: 'tr',
  28958. draggable: ['thead', 'tbody', 'tfoot'],
  28959. droppable: ['th', 'td']
  28960. })
  28961. }, {
  28962. isComponent: function isComponent(el) {
  28963. return el.tagName == 'TR' && true;
  28964. }
  28965. }));
  28966. /***/ }),
  28967. /***/ "./src/dom_components/model/ComponentText.js":
  28968. /*!***************************************************!*\
  28969. !*** ./src/dom_components/model/ComponentText.js ***!
  28970. \***************************************************/
  28971. /*! exports provided: default */
  28972. /***/ (function(module, __webpack_exports__, __webpack_require__) {
  28973. "use strict";
  28974. __webpack_require__.r(__webpack_exports__);
  28975. /* harmony import */ var _babel_runtime_helpers_defineProperty__WEBPACK_IMPORTED_MODULE_0__ = __webpack_require__(/*! @babel/runtime/helpers/defineProperty */ "./node_modules/@babel/runtime/helpers/defineProperty.js");
  28976. /* harmony import */ var _babel_runtime_helpers_defineProperty__WEBPACK_IMPORTED_MODULE_0___default = /*#__PURE__*/__webpack_require__.n(_babel_runtime_helpers_defineProperty__WEBPACK_IMPORTED_MODULE_0__);
  28977. /* harmony import */ var _Component__WEBPACK_IMPORTED_MODULE_1__ = __webpack_require__(/*! ./Component */ "./src/dom_components/model/Component.js");
  28978. function ownKeys(object, enumerableOnly) { var keys = Object.keys(object); if (Object.getOwnPropertySymbols) { var symbols = Object.getOwnPropertySymbols(object); if (enumerableOnly) symbols = symbols.filter(function (sym) { return Object.getOwnPropertyDescriptor(object, sym).enumerable; }); keys.push.apply(keys, symbols); } return keys; }
  28979. function _objectSpread(target) { for (var i = 1; i < arguments.length; i++) { var source = arguments[i] != null ? arguments[i] : {}; if (i % 2) { ownKeys(source, true).forEach(function (key) { _babel_runtime_helpers_defineProperty__WEBPACK_IMPORTED_MODULE_0___default()(target, key, source[key]); }); } else if (Object.getOwnPropertyDescriptors) { Object.defineProperties(target, Object.getOwnPropertyDescriptors(source)); } else { ownKeys(source).forEach(function (key) { Object.defineProperty(target, key, Object.getOwnPropertyDescriptor(source, key)); }); } } return target; }
  28980. /* harmony default export */ __webpack_exports__["default"] = (_Component__WEBPACK_IMPORTED_MODULE_1__["default"].extend({
  28981. defaults: _objectSpread({}, _Component__WEBPACK_IMPORTED_MODULE_1__["default"].prototype.defaults, {
  28982. type: 'text',
  28983. droppable: false,
  28984. editable: true
  28985. }),
  28986. toHTML: function toHTML() {
  28987. this.trigger('sync:content', {
  28988. silent: 1
  28989. });
  28990. return _Component__WEBPACK_IMPORTED_MODULE_1__["default"].prototype.toHTML.apply(this, arguments);
  28991. }
  28992. }));
  28993. /***/ }),
  28994. /***/ "./src/dom_components/model/ComponentTextNode.js":
  28995. /*!*******************************************************!*\
  28996. !*** ./src/dom_components/model/ComponentTextNode.js ***!
  28997. \*******************************************************/
  28998. /*! exports provided: default */
  28999. /***/ (function(module, __webpack_exports__, __webpack_require__) {
  29000. "use strict";
  29001. __webpack_require__.r(__webpack_exports__);
  29002. /* harmony import */ var _babel_runtime_helpers_defineProperty__WEBPACK_IMPORTED_MODULE_0__ = __webpack_require__(/*! @babel/runtime/helpers/defineProperty */ "./node_modules/@babel/runtime/helpers/defineProperty.js");
  29003. /* harmony import */ var _babel_runtime_helpers_defineProperty__WEBPACK_IMPORTED_MODULE_0___default = /*#__PURE__*/__webpack_require__.n(_babel_runtime_helpers_defineProperty__WEBPACK_IMPORTED_MODULE_0__);
  29004. /* harmony import */ var _Component__WEBPACK_IMPORTED_MODULE_1__ = __webpack_require__(/*! ./Component */ "./src/dom_components/model/Component.js");
  29005. function ownKeys(object, enumerableOnly) { var keys = Object.keys(object); if (Object.getOwnPropertySymbols) { var symbols = Object.getOwnPropertySymbols(object); if (enumerableOnly) symbols = symbols.filter(function (sym) { return Object.getOwnPropertyDescriptor(object, sym).enumerable; }); keys.push.apply(keys, symbols); } return keys; }
  29006. function _objectSpread(target) { for (var i = 1; i < arguments.length; i++) { var source = arguments[i] != null ? arguments[i] : {}; if (i % 2) { ownKeys(source, true).forEach(function (key) { _babel_runtime_helpers_defineProperty__WEBPACK_IMPORTED_MODULE_0___default()(target, key, source[key]); }); } else if (Object.getOwnPropertyDescriptors) { Object.defineProperties(target, Object.getOwnPropertyDescriptors(source)); } else { ownKeys(source).forEach(function (key) { Object.defineProperty(target, key, Object.getOwnPropertyDescriptor(source, key)); }); } } return target; }
  29007. /* harmony default export */ __webpack_exports__["default"] = (_Component__WEBPACK_IMPORTED_MODULE_1__["default"].extend({
  29008. defaults: _objectSpread({}, _Component__WEBPACK_IMPORTED_MODULE_1__["default"].prototype.defaults, {
  29009. droppable: false,
  29010. layerable: false,
  29011. editable: true
  29012. }),
  29013. toHTML: function toHTML() {
  29014. return this.get('content').replace(/&/g, '&amp;').replace(/</g, '&lt;').replace(/>/g, '&gt;').replace(/"/g, '&quot;').replace(/'/g, '&#039;');
  29015. }
  29016. }, {
  29017. isComponent: function isComponent(el) {
  29018. var result = '';
  29019. if (el.nodeType === 3) {
  29020. result = {
  29021. type: 'textnode',
  29022. content: el.textContent
  29023. };
  29024. }
  29025. return result;
  29026. }
  29027. }));
  29028. /***/ }),
  29029. /***/ "./src/dom_components/model/ComponentVideo.js":
  29030. /*!****************************************************!*\
  29031. !*** ./src/dom_components/model/ComponentVideo.js ***!
  29032. \****************************************************/
  29033. /*! exports provided: default */
  29034. /***/ (function(module, __webpack_exports__, __webpack_require__) {
  29035. "use strict";
  29036. __webpack_require__.r(__webpack_exports__);
  29037. /* harmony import */ var _babel_runtime_helpers_defineProperty__WEBPACK_IMPORTED_MODULE_0__ = __webpack_require__(/*! @babel/runtime/helpers/defineProperty */ "./node_modules/@babel/runtime/helpers/defineProperty.js");
  29038. /* harmony import */ var _babel_runtime_helpers_defineProperty__WEBPACK_IMPORTED_MODULE_0___default = /*#__PURE__*/__webpack_require__.n(_babel_runtime_helpers_defineProperty__WEBPACK_IMPORTED_MODULE_0__);
  29039. /* harmony import */ var _ComponentImage__WEBPACK_IMPORTED_MODULE_1__ = __webpack_require__(/*! ./ComponentImage */ "./src/dom_components/model/ComponentImage.js");
  29040. /* harmony import */ var _Component__WEBPACK_IMPORTED_MODULE_2__ = __webpack_require__(/*! ./Component */ "./src/dom_components/model/Component.js");
  29041. function ownKeys(object, enumerableOnly) { var keys = Object.keys(object); if (Object.getOwnPropertySymbols) { var symbols = Object.getOwnPropertySymbols(object); if (enumerableOnly) symbols = symbols.filter(function (sym) { return Object.getOwnPropertyDescriptor(object, sym).enumerable; }); keys.push.apply(keys, symbols); } return keys; }
  29042. function _objectSpread(target) { for (var i = 1; i < arguments.length; i++) { var source = arguments[i] != null ? arguments[i] : {}; if (i % 2) { ownKeys(source, true).forEach(function (key) { _babel_runtime_helpers_defineProperty__WEBPACK_IMPORTED_MODULE_0___default()(target, key, source[key]); }); } else if (Object.getOwnPropertyDescriptors) { Object.defineProperties(target, Object.getOwnPropertyDescriptors(source)); } else { ownKeys(source).forEach(function (key) { Object.defineProperty(target, key, Object.getOwnPropertyDescriptor(source, key)); }); } } return target; }
  29043. var yt = 'yt';
  29044. var vi = 'vi';
  29045. var ytnc = 'ytnc';
  29046. /* harmony default export */ __webpack_exports__["default"] = (_ComponentImage__WEBPACK_IMPORTED_MODULE_1__["default"].extend({
  29047. defaults: _objectSpread({}, _ComponentImage__WEBPACK_IMPORTED_MODULE_1__["default"].prototype.defaults, {
  29048. type: 'video',
  29049. tagName: 'video',
  29050. videoId: '',
  29051. void: 0,
  29052. provider: 'so',
  29053. // on change of provider, traits are switched
  29054. ytUrl: 'https://www.youtube.com/embed/',
  29055. ytncUrl: 'https://www.youtube-nocookie.com/embed/',
  29056. viUrl: 'https://player.vimeo.com/video/',
  29057. loop: 0,
  29058. poster: '',
  29059. muted: 0,
  29060. autoplay: 0,
  29061. controls: 1,
  29062. color: '',
  29063. rel: 1,
  29064. // YT related videos
  29065. modestbranding: 0,
  29066. // YT modest branding
  29067. sources: [],
  29068. attributes: {
  29069. allowfullscreen: 'allowfullscreen'
  29070. },
  29071. toolbar: _Component__WEBPACK_IMPORTED_MODULE_2__["default"].prototype.defaults.toolbar
  29072. }),
  29073. initialize: function initialize(o, opt) {
  29074. var traits = [];
  29075. var prov = this.get('provider');
  29076. switch (prov) {
  29077. case yt:
  29078. case ytnc:
  29079. traits = this.getYoutubeTraits();
  29080. break;
  29081. case vi:
  29082. traits = this.getVimeoTraits();
  29083. break;
  29084. default:
  29085. traits = this.getSourceTraits();
  29086. }
  29087. if (this.get('src')) this.parseFromSrc();
  29088. this.set('traits', traits);
  29089. _ComponentImage__WEBPACK_IMPORTED_MODULE_1__["default"].prototype.initialize.apply(this, arguments);
  29090. this.listenTo(this, 'change:provider', this.updateTraits);
  29091. this.listenTo(this, 'change:videoId change:provider', this.updateSrc);
  29092. },
  29093. initToolbar: function initToolbar() {
  29094. for (var _len = arguments.length, args = new Array(_len), _key = 0; _key < _len; _key++) {
  29095. args[_key] = arguments[_key];
  29096. }
  29097. _Component__WEBPACK_IMPORTED_MODULE_2__["default"].prototype.initToolbar.apply(this, args);
  29098. },
  29099. /**
  29100. * Set attributes by src string
  29101. */
  29102. parseFromSrc: function parseFromSrc() {
  29103. var prov = this.get('provider');
  29104. var uri = this.parseUri(this.get('src'));
  29105. var qr = uri.query;
  29106. switch (prov) {
  29107. case yt:
  29108. case ytnc:
  29109. case vi:
  29110. var videoId = uri.pathname.split('/').pop();
  29111. this.set('videoId', videoId);
  29112. if (qr.autoplay) this.set('autoplay', 1);
  29113. if (qr.loop) this.set('loop', 1);
  29114. if (parseInt(qr.controls) === 0) this.set('controls', 0);
  29115. if (qr.color) this.set('color', qr.color);
  29116. if (qr.rel === '0') this.set('rel', 0);
  29117. if (qr.modestbranding === '1') this.set('modestbranding', 1);
  29118. break;
  29119. default:
  29120. }
  29121. },
  29122. /**
  29123. * Update src on change of video ID
  29124. * @private
  29125. */
  29126. updateSrc: function updateSrc() {
  29127. var prov = this.get('provider');
  29128. switch (prov) {
  29129. case yt:
  29130. this.set('src', this.getYoutubeSrc());
  29131. break;
  29132. case ytnc:
  29133. this.set('src', this.getYoutubeNoCookieSrc());
  29134. break;
  29135. case vi:
  29136. this.set('src', this.getVimeoSrc());
  29137. break;
  29138. }
  29139. },
  29140. /**
  29141. * Returns object of attributes for HTML
  29142. * @return {Object}
  29143. * @private
  29144. */
  29145. getAttrToHTML: function getAttrToHTML() {
  29146. for (var _len2 = arguments.length, args = new Array(_len2), _key2 = 0; _key2 < _len2; _key2++) {
  29147. args[_key2] = arguments[_key2];
  29148. }
  29149. var attr = _ComponentImage__WEBPACK_IMPORTED_MODULE_1__["default"].prototype.getAttrToHTML.apply(this, args);
  29150. var prov = this.get('provider');
  29151. switch (prov) {
  29152. case yt:
  29153. case ytnc:
  29154. case vi:
  29155. break;
  29156. default:
  29157. if (this.get('loop')) attr.loop = 'loop';
  29158. if (this.get('autoplay')) attr.autoplay = 'autoplay';
  29159. if (this.get('controls')) attr.controls = 'controls';
  29160. }
  29161. return attr;
  29162. },
  29163. /**
  29164. * Update traits by provider
  29165. * @private
  29166. */
  29167. updateTraits: function updateTraits() {
  29168. var prov = this.get('provider');
  29169. var traits = this.getSourceTraits();
  29170. switch (prov) {
  29171. case yt:
  29172. case ytnc:
  29173. this.set('tagName', 'iframe');
  29174. traits = this.getYoutubeTraits();
  29175. break;
  29176. case vi:
  29177. this.set('tagName', 'iframe');
  29178. traits = this.getVimeoTraits();
  29179. break;
  29180. default:
  29181. this.set('tagName', 'video');
  29182. }
  29183. this.loadTraits(traits);
  29184. this.em.trigger('component:toggled');
  29185. },
  29186. // Listen provider change and switch traits, in TraitView listen traits change
  29187. /**
  29188. * Return the provider trait
  29189. * @return {Object}
  29190. * @private
  29191. */
  29192. getProviderTrait: function getProviderTrait() {
  29193. return {
  29194. type: 'select',
  29195. label: 'Provider',
  29196. name: 'provider',
  29197. changeProp: 1,
  29198. options: [{
  29199. value: 'so',
  29200. name: 'HTML5 Source'
  29201. }, {
  29202. value: yt,
  29203. name: 'Youtube'
  29204. }, {
  29205. value: ytnc,
  29206. name: 'Youtube (no cookie)'
  29207. }, {
  29208. value: vi,
  29209. name: 'Vimeo'
  29210. }]
  29211. };
  29212. },
  29213. /**
  29214. * Return traits for the source provider
  29215. * @return {Array<Object>}
  29216. * @private
  29217. */
  29218. getSourceTraits: function getSourceTraits() {
  29219. return [this.getProviderTrait(), {
  29220. label: 'Source',
  29221. name: 'src',
  29222. placeholder: 'eg. ./media/video.mp4',
  29223. changeProp: 1
  29224. }, {
  29225. label: 'Poster',
  29226. name: 'poster',
  29227. placeholder: 'eg. ./media/image.jpg' // changeProp: 1
  29228. }, this.getAutoplayTrait(), this.getLoopTrait(), this.getControlsTrait()];
  29229. },
  29230. /**
  29231. * Return traits for the source provider
  29232. * @return {Array<Object>}
  29233. * @private
  29234. */
  29235. getYoutubeTraits: function getYoutubeTraits() {
  29236. return [this.getProviderTrait(), {
  29237. label: 'Video ID',
  29238. name: 'videoId',
  29239. placeholder: 'eg. jNQXAC9IVRw',
  29240. changeProp: 1
  29241. }, this.getAutoplayTrait(), this.getLoopTrait(), this.getControlsTrait(), {
  29242. type: 'checkbox',
  29243. label: 'Related',
  29244. name: 'rel',
  29245. changeProp: 1
  29246. }, {
  29247. type: 'checkbox',
  29248. label: 'Modest',
  29249. name: 'modestbranding',
  29250. changeProp: 1
  29251. }];
  29252. },
  29253. /**
  29254. * Return traits for the source provider
  29255. * @return {Array<Object>}
  29256. * @private
  29257. */
  29258. getVimeoTraits: function getVimeoTraits() {
  29259. return [this.getProviderTrait(), {
  29260. label: 'Video ID',
  29261. name: 'videoId',
  29262. placeholder: 'eg. 123456789',
  29263. changeProp: 1
  29264. }, {
  29265. label: 'Color',
  29266. name: 'color',
  29267. placeholder: 'eg. FF0000',
  29268. changeProp: 1
  29269. }, this.getAutoplayTrait(), this.getLoopTrait()];
  29270. },
  29271. /**
  29272. * Return object trait
  29273. * @return {Object}
  29274. * @private
  29275. */
  29276. getAutoplayTrait: function getAutoplayTrait() {
  29277. return {
  29278. type: 'checkbox',
  29279. label: 'Autoplay',
  29280. name: 'autoplay',
  29281. changeProp: 1
  29282. };
  29283. },
  29284. /**
  29285. * Return object trait
  29286. * @return {Object}
  29287. * @private
  29288. */
  29289. getLoopTrait: function getLoopTrait() {
  29290. return {
  29291. type: 'checkbox',
  29292. label: 'Loop',
  29293. name: 'loop',
  29294. changeProp: 1
  29295. };
  29296. },
  29297. /**
  29298. * Return object trait
  29299. * @return {Object}
  29300. * @private
  29301. */
  29302. getControlsTrait: function getControlsTrait() {
  29303. return {
  29304. type: 'checkbox',
  29305. label: 'Controls',
  29306. name: 'controls',
  29307. changeProp: 1
  29308. };
  29309. },
  29310. /**
  29311. * Returns url to youtube video
  29312. * @return {string}
  29313. * @private
  29314. */
  29315. getYoutubeSrc: function getYoutubeSrc() {
  29316. var id = this.get('videoId');
  29317. var url = this.get('ytUrl');
  29318. url += id + '?';
  29319. url += this.get('autoplay') ? '&autoplay=1' : '';
  29320. url += !this.get('controls') ? '&controls=0&showinfo=0' : ''; // Loop works only with playlist enabled
  29321. // https://stackoverflow.com/questions/25779966/youtube-iframe-loop-doesnt-work
  29322. url += this.get('loop') ? "&loop=1&playlist=".concat(id) : '';
  29323. url += this.get('rel') ? '' : '&rel=0';
  29324. url += this.get('modestbranding') ? '&modestbranding=1' : '';
  29325. return url;
  29326. },
  29327. /**
  29328. * Returns url to youtube no cookie video
  29329. * @return {string}
  29330. * @private
  29331. */
  29332. getYoutubeNoCookieSrc: function getYoutubeNoCookieSrc() {
  29333. var url = this.getYoutubeSrc();
  29334. url = url.replace(this.get('ytUrl'), this.get('ytncUrl'));
  29335. return url;
  29336. },
  29337. /**
  29338. * Returns url to vimeo video
  29339. * @return {string}
  29340. * @private
  29341. */
  29342. getVimeoSrc: function getVimeoSrc() {
  29343. var url = this.get('viUrl');
  29344. url += this.get('videoId') + '?';
  29345. url += this.get('autoplay') ? '&autoplay=1' : '';
  29346. url += this.get('loop') ? '&loop=1' : '';
  29347. url += !this.get('controls') ? '&title=0&portrait=0&badge=0' : '';
  29348. url += this.get('color') ? '&color=' + this.get('color') : '';
  29349. return url;
  29350. }
  29351. }, {
  29352. /**
  29353. * Detect if the passed element is a valid component.
  29354. * In case the element is valid an object abstracted
  29355. * from the element will be returned
  29356. * @param {HTMLElement}
  29357. * @return {Object}
  29358. * @private
  29359. */
  29360. isComponent: function isComponent(el) {
  29361. var result = '';
  29362. var isYtProv = /youtube\.com\/embed/.test(el.src);
  29363. var isYtncProv = /youtube-nocookie\.com\/embed/.test(el.src);
  29364. var isViProv = /player\.vimeo\.com\/video/.test(el.src);
  29365. var isExtProv = isYtProv || isYtncProv || isViProv;
  29366. if (el.tagName == 'VIDEO' || el.tagName == 'IFRAME' && isExtProv) {
  29367. result = {
  29368. type: 'video'
  29369. };
  29370. if (el.src) result.src = el.src;
  29371. if (isExtProv) {
  29372. if (isYtProv) result.provider = yt;else if (isYtncProv) result.provider = ytnc;else if (isViProv) result.provider = vi;
  29373. }
  29374. }
  29375. return result;
  29376. }
  29377. }));
  29378. /***/ }),
  29379. /***/ "./src/dom_components/model/ComponentWrapper.js":
  29380. /*!******************************************************!*\
  29381. !*** ./src/dom_components/model/ComponentWrapper.js ***!
  29382. \******************************************************/
  29383. /*! exports provided: default */
  29384. /***/ (function(module, __webpack_exports__, __webpack_require__) {
  29385. "use strict";
  29386. __webpack_require__.r(__webpack_exports__);
  29387. /* harmony import */ var _Component__WEBPACK_IMPORTED_MODULE_0__ = __webpack_require__(/*! ./Component */ "./src/dom_components/model/Component.js");
  29388. // We need this one just to identify better the wrapper type
  29389. /* harmony default export */ __webpack_exports__["default"] = (_Component__WEBPACK_IMPORTED_MODULE_0__["default"].extend({}, {
  29390. isComponent: function isComponent() {
  29391. return false;
  29392. }
  29393. }));
  29394. /***/ }),
  29395. /***/ "./src/dom_components/model/Components.js":
  29396. /*!************************************************!*\
  29397. !*** ./src/dom_components/model/Components.js ***!
  29398. \************************************************/
  29399. /*! exports provided: default */
  29400. /***/ (function(module, __webpack_exports__, __webpack_require__) {
  29401. "use strict";
  29402. __webpack_require__.r(__webpack_exports__);
  29403. /* harmony import */ var _babel_runtime_helpers_typeof__WEBPACK_IMPORTED_MODULE_0__ = __webpack_require__(/*! @babel/runtime/helpers/typeof */ "./node_modules/@babel/runtime/helpers/typeof.js");
  29404. /* harmony import */ var _babel_runtime_helpers_typeof__WEBPACK_IMPORTED_MODULE_0___default = /*#__PURE__*/__webpack_require__.n(_babel_runtime_helpers_typeof__WEBPACK_IMPORTED_MODULE_0__);
  29405. /* harmony import */ var _babel_runtime_helpers_defineProperty__WEBPACK_IMPORTED_MODULE_1__ = __webpack_require__(/*! @babel/runtime/helpers/defineProperty */ "./node_modules/@babel/runtime/helpers/defineProperty.js");
  29406. /* harmony import */ var _babel_runtime_helpers_defineProperty__WEBPACK_IMPORTED_MODULE_1___default = /*#__PURE__*/__webpack_require__.n(_babel_runtime_helpers_defineProperty__WEBPACK_IMPORTED_MODULE_1__);
  29407. /* harmony import */ var backbone__WEBPACK_IMPORTED_MODULE_2__ = __webpack_require__(/*! backbone */ "./node_modules/backbone/backbone.js");
  29408. /* harmony import */ var backbone__WEBPACK_IMPORTED_MODULE_2___default = /*#__PURE__*/__webpack_require__.n(backbone__WEBPACK_IMPORTED_MODULE_2__);
  29409. /* harmony import */ var underscore__WEBPACK_IMPORTED_MODULE_3__ = __webpack_require__(/*! underscore */ "./node_modules/underscore/underscore.js");
  29410. /* harmony import */ var underscore__WEBPACK_IMPORTED_MODULE_3___default = /*#__PURE__*/__webpack_require__.n(underscore__WEBPACK_IMPORTED_MODULE_3__);
  29411. function ownKeys(object, enumerableOnly) { var keys = Object.keys(object); if (Object.getOwnPropertySymbols) { var symbols = Object.getOwnPropertySymbols(object); if (enumerableOnly) symbols = symbols.filter(function (sym) { return Object.getOwnPropertyDescriptor(object, sym).enumerable; }); keys.push.apply(keys, symbols); } return keys; }
  29412. function _objectSpread(target) { for (var i = 1; i < arguments.length; i++) { var source = arguments[i] != null ? arguments[i] : {}; if (i % 2) { ownKeys(source, true).forEach(function (key) { _babel_runtime_helpers_defineProperty__WEBPACK_IMPORTED_MODULE_1___default()(target, key, source[key]); }); } else if (Object.getOwnPropertyDescriptors) { Object.defineProperties(target, Object.getOwnPropertyDescriptors(source)); } else { ownKeys(source).forEach(function (key) { Object.defineProperty(target, key, Object.getOwnPropertyDescriptor(source, key)); }); } } return target; }
  29413. var Component;
  29414. /* harmony default export */ __webpack_exports__["default"] = (backbone__WEBPACK_IMPORTED_MODULE_2___default.a.Collection.extend({
  29415. initialize: function initialize(models) {
  29416. var opt = arguments.length > 1 && arguments[1] !== undefined ? arguments[1] : {};
  29417. this.opt = opt;
  29418. this.listenTo(this, 'add', this.onAdd);
  29419. this.listenTo(this, 'remove', this.removeChildren);
  29420. this.listenTo(this, 'reset', this.resetChildren);
  29421. this.config = opt.config;
  29422. this.em = opt.em;
  29423. this.domc = opt.domc;
  29424. },
  29425. resetChildren: function resetChildren(models) {
  29426. var _this = this;
  29427. var opts = arguments.length > 1 && arguments[1] !== undefined ? arguments[1] : {};
  29428. var coll = this;
  29429. var _opts$previousModels = opts.previousModels,
  29430. previousModels = _opts$previousModels === void 0 ? [] : _opts$previousModels;
  29431. previousModels.forEach(function (md) {
  29432. return _this.removeChildren(md, coll, opts);
  29433. });
  29434. models.each(function (model) {
  29435. return _this.onAdd(model);
  29436. });
  29437. },
  29438. removeChildren: function removeChildren(removed, coll) {
  29439. var _this2 = this;
  29440. var opts = arguments.length > 2 && arguments[2] !== undefined ? arguments[2] : {};
  29441. var domc = this.domc,
  29442. em = this.em;
  29443. var allByID = domc ? domc.allById() : {};
  29444. if (!opts.temporary) {
  29445. // Remove the component from the gloabl list
  29446. var id = removed.getId();
  29447. var sels = em.get('SelectorManager').getAll();
  29448. var rules = em.get('CssComposer').getAll();
  29449. delete allByID[id]; // Remove all component related styles
  29450. var rulesRemoved = rules.remove(rules.filter(function (r) {
  29451. return r.getSelectors().getFullString() === "#".concat(id);
  29452. })); // Clean selectors
  29453. sels.remove(rulesRemoved.map(function (rule) {
  29454. return rule.getSelectors().at(0);
  29455. }));
  29456. if (!removed.opt.temporary) {
  29457. var cm = em.get('Commands');
  29458. var hasSign = removed.get('style-signature');
  29459. var optStyle = {
  29460. target: removed
  29461. };
  29462. hasSign && cm.run('core:component-style-clear', optStyle);
  29463. removed.removed();
  29464. em.trigger('component:remove', removed);
  29465. }
  29466. var _inner = removed.components();
  29467. _inner.forEach(function (it) {
  29468. return _this2.removeChildren(it, coll, opts);
  29469. }); // removed.empty(opts);
  29470. } // Remove stuff registered in DomComponents.handleChanges
  29471. var inner = removed.components();
  29472. var um = em.get('UndoManager');
  29473. em.stopListening(inner);
  29474. em.stopListening(removed);
  29475. em.stopListening(removed.get('classes'));
  29476. um.remove(removed);
  29477. um.remove(inner);
  29478. },
  29479. model: function model(attrs, options) {
  29480. var opt = options.collection.opt;
  29481. var em = opt.em;
  29482. var model;
  29483. var df = em.get('DomComponents').componentTypes;
  29484. options.em = em;
  29485. options.config = opt.config;
  29486. options.componentTypes = df;
  29487. options.domc = opt.domc;
  29488. for (var it = 0; it < df.length; it++) {
  29489. var dfId = df[it].id;
  29490. if (dfId == attrs.type) {
  29491. model = df[it].model;
  29492. break;
  29493. }
  29494. } // If no model found, get the default one
  29495. if (!model) {
  29496. model = df[df.length - 1].model;
  29497. em && attrs.type && em.logWarning("Component type '".concat(attrs.type, "' not found"), {
  29498. attrs: attrs,
  29499. options: options
  29500. });
  29501. }
  29502. return new model(attrs, options);
  29503. },
  29504. parseString: function parseString(value) {
  29505. var opt = arguments.length > 1 && arguments[1] !== undefined ? arguments[1] : {};
  29506. var em = this.em;
  29507. var domc = this.opt.domc;
  29508. var cssc = em.get('CssComposer');
  29509. var parsed = em.get('Parser').parseHtml(value); // We need this to avoid duplicate IDs
  29510. if (!Component) Component = __webpack_require__(/*! ./Component */ "./src/dom_components/model/Component.js").default;
  29511. Component.checkId(parsed.html, parsed.css, domc.componentsById);
  29512. if (parsed.css && cssc && !opt.temporary) {
  29513. cssc.addCollection(parsed.css, _objectSpread({}, opt, {
  29514. extend: 1
  29515. }));
  29516. }
  29517. return parsed.html;
  29518. },
  29519. add: function add(models) {
  29520. var _this3 = this;
  29521. var opt = arguments.length > 1 && arguments[1] !== undefined ? arguments[1] : {};
  29522. if (Object(underscore__WEBPACK_IMPORTED_MODULE_3__["isString"])(models)) {
  29523. models = this.parseString(models, opt);
  29524. } else if (Object(underscore__WEBPACK_IMPORTED_MODULE_3__["isArray"])(models)) {
  29525. models.forEach(function (item, index) {
  29526. if (Object(underscore__WEBPACK_IMPORTED_MODULE_3__["isString"])(item)) {
  29527. models[index] = _this3.parseString(item, opt);
  29528. }
  29529. });
  29530. }
  29531. var isMult = Object(underscore__WEBPACK_IMPORTED_MODULE_3__["isArray"])(models);
  29532. models = (isMult ? models : [models]).filter(function (i) {
  29533. return i;
  29534. }).map(function (model) {
  29535. return _this3.processDef(model);
  29536. });
  29537. models = isMult ? models : models[0];
  29538. return backbone__WEBPACK_IMPORTED_MODULE_2___default.a.Collection.prototype.add.apply(this, [models, opt]);
  29539. },
  29540. /**
  29541. * Process component definition.
  29542. */
  29543. processDef: function processDef(mdl) {
  29544. // Avoid processing Models
  29545. if (mdl.cid && mdl.ccid) return mdl;
  29546. var em = this.em,
  29547. _this$config = this.config,
  29548. config = _this$config === void 0 ? {} : _this$config;
  29549. var processor = config.processor;
  29550. var model = mdl;
  29551. if (processor) {
  29552. model = _objectSpread({}, model); // Avoid 'Cannot delete property ...'
  29553. var modelPr = processor(model);
  29554. if (modelPr) {
  29555. Object(underscore__WEBPACK_IMPORTED_MODULE_3__["each"])(model, function (val, key) {
  29556. return delete model[key];
  29557. });
  29558. Object(underscore__WEBPACK_IMPORTED_MODULE_3__["extend"])(model, modelPr);
  29559. }
  29560. } // React JSX preset
  29561. if (model.$$typeof && _babel_runtime_helpers_typeof__WEBPACK_IMPORTED_MODULE_0___default()(model.props) == 'object') {
  29562. model = _objectSpread({}, model);
  29563. model.props = _objectSpread({}, model.props);
  29564. var domc = em.get('DomComponents');
  29565. var parser = em.get('Parser');
  29566. var parserHtml = parser.parserHtml;
  29567. Object(underscore__WEBPACK_IMPORTED_MODULE_3__["each"])(model, function (value, key) {
  29568. if (!Object(underscore__WEBPACK_IMPORTED_MODULE_3__["includes"])(['props', 'type'], key)) delete model[key];
  29569. });
  29570. var _model = model,
  29571. props = _model.props;
  29572. var comps = props.children;
  29573. delete props.children;
  29574. delete model.props;
  29575. var res = parserHtml.splitPropsFromAttr(props);
  29576. model.attributes = res.attrs;
  29577. if (comps) {
  29578. model.components = comps;
  29579. }
  29580. if (!model.type) {
  29581. model.type = 'textnode';
  29582. } else if (!domc.getType(model.type)) {
  29583. model.tagName = model.type;
  29584. delete model.type;
  29585. }
  29586. Object(underscore__WEBPACK_IMPORTED_MODULE_3__["extend"])(model, res.props);
  29587. }
  29588. return model;
  29589. },
  29590. onAdd: function onAdd(model, c) {
  29591. var opts = arguments.length > 2 && arguments[2] !== undefined ? arguments[2] : {};
  29592. var domc = this.domc,
  29593. em = this.em;
  29594. var style = model.getStyle();
  29595. var avoidInline = em && em.getConfig('avoidInlineStyle');
  29596. domc && domc.Component.ensureInList(model);
  29597. if (!Object(underscore__WEBPACK_IMPORTED_MODULE_3__["isEmpty"])(style) && !avoidInline && em && em.get && em.getConfig('forceClass') && !opts.temporary) {
  29598. var name = model.cid;
  29599. var rule = em.get('CssComposer').setClassRule(name, style);
  29600. model.setStyle({});
  29601. model.addClass(name);
  29602. }
  29603. }
  29604. }));
  29605. /***/ }),
  29606. /***/ "./src/dom_components/model/Toolbar.js":
  29607. /*!*********************************************!*\
  29608. !*** ./src/dom_components/model/Toolbar.js ***!
  29609. \*********************************************/
  29610. /*! exports provided: default */
  29611. /***/ (function(module, __webpack_exports__, __webpack_require__) {
  29612. "use strict";
  29613. __webpack_require__.r(__webpack_exports__);
  29614. /* harmony import */ var backbone__WEBPACK_IMPORTED_MODULE_0__ = __webpack_require__(/*! backbone */ "./node_modules/backbone/backbone.js");
  29615. /* harmony import */ var backbone__WEBPACK_IMPORTED_MODULE_0___default = /*#__PURE__*/__webpack_require__.n(backbone__WEBPACK_IMPORTED_MODULE_0__);
  29616. /* harmony import */ var _ToolbarButton__WEBPACK_IMPORTED_MODULE_1__ = __webpack_require__(/*! ./ToolbarButton */ "./src/dom_components/model/ToolbarButton.js");
  29617. /* harmony default export */ __webpack_exports__["default"] = (backbone__WEBPACK_IMPORTED_MODULE_0___default.a.Collection.extend({
  29618. model: _ToolbarButton__WEBPACK_IMPORTED_MODULE_1__["default"]
  29619. }));
  29620. /***/ }),
  29621. /***/ "./src/dom_components/model/ToolbarButton.js":
  29622. /*!***************************************************!*\
  29623. !*** ./src/dom_components/model/ToolbarButton.js ***!
  29624. \***************************************************/
  29625. /*! exports provided: default */
  29626. /***/ (function(module, __webpack_exports__, __webpack_require__) {
  29627. "use strict";
  29628. __webpack_require__.r(__webpack_exports__);
  29629. /* harmony import */ var backbone__WEBPACK_IMPORTED_MODULE_0__ = __webpack_require__(/*! backbone */ "./node_modules/backbone/backbone.js");
  29630. /* harmony import */ var backbone__WEBPACK_IMPORTED_MODULE_0___default = /*#__PURE__*/__webpack_require__.n(backbone__WEBPACK_IMPORTED_MODULE_0__);
  29631. /* harmony default export */ __webpack_exports__["default"] = (backbone__WEBPACK_IMPORTED_MODULE_0___default.a.Model.extend({
  29632. defaults: {
  29633. command: '',
  29634. attributes: {}
  29635. }
  29636. }));
  29637. /***/ }),
  29638. /***/ "./src/dom_components/view/ComponentCommentView.js":
  29639. /*!*********************************************************!*\
  29640. !*** ./src/dom_components/view/ComponentCommentView.js ***!
  29641. \*********************************************************/
  29642. /*! exports provided: default */
  29643. /***/ (function(module, __webpack_exports__, __webpack_require__) {
  29644. "use strict";
  29645. __webpack_require__.r(__webpack_exports__);
  29646. /* harmony import */ var _ComponentTextNodeView__WEBPACK_IMPORTED_MODULE_0__ = __webpack_require__(/*! ./ComponentTextNodeView */ "./src/dom_components/view/ComponentTextNodeView.js");
  29647. /* harmony default export */ __webpack_exports__["default"] = (_ComponentTextNodeView__WEBPACK_IMPORTED_MODULE_0__["default"].extend({
  29648. _createElement: function _createElement() {
  29649. return document.createComment(this.model.get('content'));
  29650. }
  29651. }));
  29652. /***/ }),
  29653. /***/ "./src/dom_components/view/ComponentImageView.js":
  29654. /*!*******************************************************!*\
  29655. !*** ./src/dom_components/view/ComponentImageView.js ***!
  29656. \*******************************************************/
  29657. /*! exports provided: default */
  29658. /***/ (function(module, __webpack_exports__, __webpack_require__) {
  29659. "use strict";
  29660. __webpack_require__.r(__webpack_exports__);
  29661. /* harmony import */ var underscore__WEBPACK_IMPORTED_MODULE_0__ = __webpack_require__(/*! underscore */ "./node_modules/underscore/underscore.js");
  29662. /* harmony import */ var underscore__WEBPACK_IMPORTED_MODULE_0___default = /*#__PURE__*/__webpack_require__.n(underscore__WEBPACK_IMPORTED_MODULE_0__);
  29663. /* harmony import */ var _ComponentView__WEBPACK_IMPORTED_MODULE_1__ = __webpack_require__(/*! ./ComponentView */ "./src/dom_components/view/ComponentView.js");
  29664. /* harmony default export */ __webpack_exports__["default"] = (_ComponentView__WEBPACK_IMPORTED_MODULE_1__["default"].extend({
  29665. tagName: 'img',
  29666. events: {
  29667. dblclick: 'onActive',
  29668. click: 'initResize',
  29669. error: 'onError',
  29670. dragstart: 'noDrag'
  29671. },
  29672. initialize: function initialize(o) {
  29673. var model = this.model;
  29674. _ComponentView__WEBPACK_IMPORTED_MODULE_1__["default"].prototype.initialize.apply(this, arguments);
  29675. this.listenTo(model, 'change:src', this.updateSrc);
  29676. this.classEmpty = "".concat(this.ppfx, "plh-image");
  29677. var config = this.config;
  29678. config.modal && (this.modal = config.modal);
  29679. config.am && (this.am = config.am);
  29680. this.fetchFile();
  29681. },
  29682. /**
  29683. * Fetch file if exists
  29684. */
  29685. fetchFile: function fetchFile() {
  29686. if (this.modelOpt.temporary) return;
  29687. var model = this.model;
  29688. var file = model.get('file');
  29689. if (file) {
  29690. var fu = this.em.get('AssetManager').FileUploader();
  29691. fu.uploadFile({
  29692. dataTransfer: {
  29693. files: [file]
  29694. }
  29695. }, function (res) {
  29696. var obj = res && res.data && res.data[0];
  29697. var src = obj && (Object(underscore__WEBPACK_IMPORTED_MODULE_0__["isString"])(obj) ? obj : obj.src);
  29698. src && model.set({
  29699. src: src
  29700. });
  29701. });
  29702. model.set('file', '');
  29703. }
  29704. },
  29705. /**
  29706. * Update src attribute
  29707. * @private
  29708. * */
  29709. updateSrc: function updateSrc() {
  29710. var model = this.model,
  29711. classEmpty = this.classEmpty,
  29712. $el = this.$el;
  29713. var src = model.getSrcResult();
  29714. var srcExists = src && !model.isDefaultSrc();
  29715. model.addAttributes({
  29716. src: src
  29717. });
  29718. $el[srcExists ? 'removeClass' : 'addClass'](classEmpty);
  29719. },
  29720. /**
  29721. * Open dialog for image changing
  29722. * @param {Object} e Event
  29723. * @private
  29724. * */
  29725. onActive: function onActive(ev) {
  29726. ev && ev.stopPropagation();
  29727. var em = this.opts.config.em;
  29728. var editor = em ? em.get('Editor') : '';
  29729. if (editor && this.model.get('editable')) {
  29730. editor.runCommand('open-assets', {
  29731. target: this.model,
  29732. types: ['image'],
  29733. accept: 'image/*',
  29734. onSelect: function onSelect() {
  29735. editor.Modal.close();
  29736. editor.AssetManager.setTarget(null);
  29737. }
  29738. });
  29739. }
  29740. },
  29741. onError: function onError() {
  29742. var fallback = this.model.getSrcResult({
  29743. fallback: 1
  29744. });
  29745. if (fallback) this.el.src = fallback;
  29746. },
  29747. noDrag: function noDrag(ev) {
  29748. ev.preventDefault();
  29749. return false;
  29750. },
  29751. render: function render() {
  29752. this.renderAttributes();
  29753. this.updateSrc();
  29754. var $el = this.$el,
  29755. model = this.model;
  29756. var cls = $el.attr('class') || '';
  29757. !model.get('src') && $el.attr('class', "".concat(cls, " ").concat(this.classEmpty).trim());
  29758. this.postRender();
  29759. return this;
  29760. }
  29761. }));
  29762. /***/ }),
  29763. /***/ "./src/dom_components/view/ComponentLabelView.js":
  29764. /*!*******************************************************!*\
  29765. !*** ./src/dom_components/view/ComponentLabelView.js ***!
  29766. \*******************************************************/
  29767. /*! exports provided: default */
  29768. /***/ (function(module, __webpack_exports__, __webpack_require__) {
  29769. "use strict";
  29770. __webpack_require__.r(__webpack_exports__);
  29771. /* harmony import */ var _ComponentLinkView__WEBPACK_IMPORTED_MODULE_0__ = __webpack_require__(/*! ./ComponentLinkView */ "./src/dom_components/view/ComponentLinkView.js");
  29772. /* harmony default export */ __webpack_exports__["default"] = (_ComponentLinkView__WEBPACK_IMPORTED_MODULE_0__["default"].extend({
  29773. tagName: 'span' // Avoid Firefox bug with label editing #2332
  29774. }));
  29775. /***/ }),
  29776. /***/ "./src/dom_components/view/ComponentLinkView.js":
  29777. /*!******************************************************!*\
  29778. !*** ./src/dom_components/view/ComponentLinkView.js ***!
  29779. \******************************************************/
  29780. /*! exports provided: default */
  29781. /***/ (function(module, __webpack_exports__, __webpack_require__) {
  29782. "use strict";
  29783. __webpack_require__.r(__webpack_exports__);
  29784. /* harmony import */ var _ComponentTextView__WEBPACK_IMPORTED_MODULE_0__ = __webpack_require__(/*! ./ComponentTextView */ "./src/dom_components/view/ComponentTextView.js");
  29785. /* harmony default export */ __webpack_exports__["default"] = (_ComponentTextView__WEBPACK_IMPORTED_MODULE_0__["default"].extend({
  29786. render: function render() {
  29787. for (var _len = arguments.length, args = new Array(_len), _key = 0; _key < _len; _key++) {
  29788. args[_key] = arguments[_key];
  29789. }
  29790. _ComponentTextView__WEBPACK_IMPORTED_MODULE_0__["default"].prototype.render.apply(this, args); // I need capturing instead of bubbling as bubbled clicks from other
  29791. // children will execute the link event
  29792. this.el.addEventListener('click', this.prevDef, true);
  29793. return this;
  29794. }
  29795. }));
  29796. /***/ }),
  29797. /***/ "./src/dom_components/view/ComponentMapView.js":
  29798. /*!*****************************************************!*\
  29799. !*** ./src/dom_components/view/ComponentMapView.js ***!
  29800. \*****************************************************/
  29801. /*! exports provided: default */
  29802. /***/ (function(module, __webpack_exports__, __webpack_require__) {
  29803. "use strict";
  29804. __webpack_require__.r(__webpack_exports__);
  29805. /* harmony import */ var backbone__WEBPACK_IMPORTED_MODULE_0__ = __webpack_require__(/*! backbone */ "./node_modules/backbone/backbone.js");
  29806. /* harmony import */ var backbone__WEBPACK_IMPORTED_MODULE_0___default = /*#__PURE__*/__webpack_require__.n(backbone__WEBPACK_IMPORTED_MODULE_0__);
  29807. /* harmony import */ var _ComponentImageView__WEBPACK_IMPORTED_MODULE_1__ = __webpack_require__(/*! ./ComponentImageView */ "./src/dom_components/view/ComponentImageView.js");
  29808. /* harmony default export */ __webpack_exports__["default"] = (_ComponentImageView__WEBPACK_IMPORTED_MODULE_1__["default"].extend({
  29809. tagName: 'div',
  29810. events: {},
  29811. initialize: function initialize(o) {
  29812. _ComponentImageView__WEBPACK_IMPORTED_MODULE_1__["default"].prototype.initialize.apply(this, arguments);
  29813. this.classEmpty = this.ppfx + 'plh-map';
  29814. },
  29815. /**
  29816. * Update the map on the canvas
  29817. * @private
  29818. */
  29819. updateSrc: function updateSrc() {
  29820. this.getIframe().src = this.model.get('src');
  29821. },
  29822. getIframe: function getIframe() {
  29823. if (!this.iframe) {
  29824. var ifrm = document.createElement('iframe');
  29825. ifrm.src = this.model.get('src');
  29826. ifrm.frameBorder = 0;
  29827. ifrm.style.height = '100%';
  29828. ifrm.style.width = '100%';
  29829. ifrm.className = this.ppfx + 'no-pointer';
  29830. this.iframe = ifrm;
  29831. }
  29832. return this.iframe;
  29833. },
  29834. render: function render() {
  29835. for (var _len = arguments.length, args = new Array(_len), _key = 0; _key < _len; _key++) {
  29836. args[_key] = arguments[_key];
  29837. }
  29838. _ComponentImageView__WEBPACK_IMPORTED_MODULE_1__["default"].prototype.render.apply(this, args);
  29839. this.updateClasses();
  29840. this.el.appendChild(this.getIframe());
  29841. return this;
  29842. }
  29843. }));
  29844. /***/ }),
  29845. /***/ "./src/dom_components/view/ComponentScriptView.js":
  29846. /*!********************************************************!*\
  29847. !*** ./src/dom_components/view/ComponentScriptView.js ***!
  29848. \********************************************************/
  29849. /*! exports provided: default */
  29850. /***/ (function(module, __webpack_exports__, __webpack_require__) {
  29851. "use strict";
  29852. __webpack_require__.r(__webpack_exports__);
  29853. /* harmony import */ var backbone__WEBPACK_IMPORTED_MODULE_0__ = __webpack_require__(/*! backbone */ "./node_modules/backbone/backbone.js");
  29854. /* harmony import */ var backbone__WEBPACK_IMPORTED_MODULE_0___default = /*#__PURE__*/__webpack_require__.n(backbone__WEBPACK_IMPORTED_MODULE_0__);
  29855. /* harmony import */ var _ComponentImageView__WEBPACK_IMPORTED_MODULE_1__ = __webpack_require__(/*! ./ComponentImageView */ "./src/dom_components/view/ComponentImageView.js");
  29856. /* harmony default export */ __webpack_exports__["default"] = (_ComponentImageView__WEBPACK_IMPORTED_MODULE_1__["default"].extend({
  29857. tagName: 'script',
  29858. events: {},
  29859. render: function render() {
  29860. var model = this.model;
  29861. var src = model.get('src');
  29862. var em = this.em;
  29863. var scriptCount = em && em.get('scriptCount') ? em.get('scriptCount') : 0;
  29864. var content = ''; // If it's an external script
  29865. if (src) {
  29866. var onload = model.get('onload');
  29867. var svar = 'script' + scriptCount;
  29868. var svarNext = 'script' + (scriptCount + 1);
  29869. content = 'var ' + svar + " = document.createElement('script');\n" + svar + '.onload = function(){\n' + (onload ? onload + '();\n' : '') + 'typeof ' + svarNext + "Start == 'function' && " + svarNext + 'Start();\n' + '};\n' + svar + ".src = '" + src + "';\n" + 'function ' + svar + 'Start() { document.body.appendChild(' + svar + '); };\n' + (!scriptCount ? svar + 'Start();' : '');
  29870. if (em) {
  29871. em.set('scriptCount', scriptCount + 1);
  29872. }
  29873. } else {
  29874. content = model.get('content');
  29875. }
  29876. this.el.innerHTML = content;
  29877. return this;
  29878. }
  29879. }));
  29880. /***/ }),
  29881. /***/ "./src/dom_components/view/ComponentSvgView.js":
  29882. /*!*****************************************************!*\
  29883. !*** ./src/dom_components/view/ComponentSvgView.js ***!
  29884. \*****************************************************/
  29885. /*! exports provided: default */
  29886. /***/ (function(module, __webpack_exports__, __webpack_require__) {
  29887. "use strict";
  29888. __webpack_require__.r(__webpack_exports__);
  29889. /* harmony import */ var _ComponentView__WEBPACK_IMPORTED_MODULE_0__ = __webpack_require__(/*! ./ComponentView */ "./src/dom_components/view/ComponentView.js");
  29890. /* harmony default export */ __webpack_exports__["default"] = (_ComponentView__WEBPACK_IMPORTED_MODULE_0__["default"].extend({
  29891. _createElement: function _createElement(tagName) {
  29892. return document.createElementNS('http://www.w3.org/2000/svg', tagName);
  29893. }
  29894. }));
  29895. /***/ }),
  29896. /***/ "./src/dom_components/view/ComponentTableBodyView.js":
  29897. /*!***********************************************************!*\
  29898. !*** ./src/dom_components/view/ComponentTableBodyView.js ***!
  29899. \***********************************************************/
  29900. /*! exports provided: default */
  29901. /***/ (function(module, __webpack_exports__, __webpack_require__) {
  29902. "use strict";
  29903. __webpack_require__.r(__webpack_exports__);
  29904. /* harmony import */ var _ComponentView__WEBPACK_IMPORTED_MODULE_0__ = __webpack_require__(/*! ./ComponentView */ "./src/dom_components/view/ComponentView.js");
  29905. /* harmony default export */ __webpack_exports__["default"] = (_ComponentView__WEBPACK_IMPORTED_MODULE_0__["default"].extend({}));
  29906. /***/ }),
  29907. /***/ "./src/dom_components/view/ComponentTableCellView.js":
  29908. /*!***********************************************************!*\
  29909. !*** ./src/dom_components/view/ComponentTableCellView.js ***!
  29910. \***********************************************************/
  29911. /*! exports provided: default */
  29912. /***/ (function(module, __webpack_exports__, __webpack_require__) {
  29913. "use strict";
  29914. __webpack_require__.r(__webpack_exports__);
  29915. /* harmony import */ var _ComponentView__WEBPACK_IMPORTED_MODULE_0__ = __webpack_require__(/*! ./ComponentView */ "./src/dom_components/view/ComponentView.js");
  29916. /* harmony default export */ __webpack_exports__["default"] = (_ComponentView__WEBPACK_IMPORTED_MODULE_0__["default"].extend({}));
  29917. /***/ }),
  29918. /***/ "./src/dom_components/view/ComponentTableFootView.js":
  29919. /*!***********************************************************!*\
  29920. !*** ./src/dom_components/view/ComponentTableFootView.js ***!
  29921. \***********************************************************/
  29922. /*! exports provided: default */
  29923. /***/ (function(module, __webpack_exports__, __webpack_require__) {
  29924. "use strict";
  29925. __webpack_require__.r(__webpack_exports__);
  29926. /* harmony import */ var _ComponentView__WEBPACK_IMPORTED_MODULE_0__ = __webpack_require__(/*! ./ComponentView */ "./src/dom_components/view/ComponentView.js");
  29927. /* harmony default export */ __webpack_exports__["default"] = (_ComponentView__WEBPACK_IMPORTED_MODULE_0__["default"].extend({}));
  29928. /***/ }),
  29929. /***/ "./src/dom_components/view/ComponentTableHeadView.js":
  29930. /*!***********************************************************!*\
  29931. !*** ./src/dom_components/view/ComponentTableHeadView.js ***!
  29932. \***********************************************************/
  29933. /*! exports provided: default */
  29934. /***/ (function(module, __webpack_exports__, __webpack_require__) {
  29935. "use strict";
  29936. __webpack_require__.r(__webpack_exports__);
  29937. /* harmony import */ var _ComponentView__WEBPACK_IMPORTED_MODULE_0__ = __webpack_require__(/*! ./ComponentView */ "./src/dom_components/view/ComponentView.js");
  29938. /* harmony default export */ __webpack_exports__["default"] = (_ComponentView__WEBPACK_IMPORTED_MODULE_0__["default"].extend({}));
  29939. /***/ }),
  29940. /***/ "./src/dom_components/view/ComponentTableRowView.js":
  29941. /*!**********************************************************!*\
  29942. !*** ./src/dom_components/view/ComponentTableRowView.js ***!
  29943. \**********************************************************/
  29944. /*! exports provided: default */
  29945. /***/ (function(module, __webpack_exports__, __webpack_require__) {
  29946. "use strict";
  29947. __webpack_require__.r(__webpack_exports__);
  29948. /* harmony import */ var _ComponentView__WEBPACK_IMPORTED_MODULE_0__ = __webpack_require__(/*! ./ComponentView */ "./src/dom_components/view/ComponentView.js");
  29949. /* harmony default export */ __webpack_exports__["default"] = (_ComponentView__WEBPACK_IMPORTED_MODULE_0__["default"].extend({}));
  29950. /***/ }),
  29951. /***/ "./src/dom_components/view/ComponentTableView.js":
  29952. /*!*******************************************************!*\
  29953. !*** ./src/dom_components/view/ComponentTableView.js ***!
  29954. \*******************************************************/
  29955. /*! exports provided: default */
  29956. /***/ (function(module, __webpack_exports__, __webpack_require__) {
  29957. "use strict";
  29958. __webpack_require__.r(__webpack_exports__);
  29959. /* harmony import */ var _ComponentView__WEBPACK_IMPORTED_MODULE_0__ = __webpack_require__(/*! ./ComponentView */ "./src/dom_components/view/ComponentView.js");
  29960. /* harmony default export */ __webpack_exports__["default"] = (_ComponentView__WEBPACK_IMPORTED_MODULE_0__["default"].extend({
  29961. events: {}
  29962. }));
  29963. /***/ }),
  29964. /***/ "./src/dom_components/view/ComponentTextNodeView.js":
  29965. /*!**********************************************************!*\
  29966. !*** ./src/dom_components/view/ComponentTextNodeView.js ***!
  29967. \**********************************************************/
  29968. /*! exports provided: default */
  29969. /***/ (function(module, __webpack_exports__, __webpack_require__) {
  29970. "use strict";
  29971. __webpack_require__.r(__webpack_exports__);
  29972. /* harmony import */ var backbone__WEBPACK_IMPORTED_MODULE_0__ = __webpack_require__(/*! backbone */ "./node_modules/backbone/backbone.js");
  29973. /* harmony import */ var backbone__WEBPACK_IMPORTED_MODULE_0___default = /*#__PURE__*/__webpack_require__.n(backbone__WEBPACK_IMPORTED_MODULE_0__);
  29974. /* harmony default export */ __webpack_exports__["default"] = (backbone__WEBPACK_IMPORTED_MODULE_0___default.a.View.extend({
  29975. initialize: function initialize() {
  29976. var $el = this.$el,
  29977. model = this.model;
  29978. $el.data('model', model);
  29979. model.view = this;
  29980. },
  29981. _createElement: function _createElement() {
  29982. return document.createTextNode(this.model.get('content'));
  29983. }
  29984. }));
  29985. /***/ }),
  29986. /***/ "./src/dom_components/view/ComponentTextView.js":
  29987. /*!******************************************************!*\
  29988. !*** ./src/dom_components/view/ComponentTextView.js ***!
  29989. \******************************************************/
  29990. /*! exports provided: default */
  29991. /***/ (function(module, __webpack_exports__, __webpack_require__) {
  29992. "use strict";
  29993. __webpack_require__.r(__webpack_exports__);
  29994. /* harmony import */ var _babel_runtime_helpers_defineProperty__WEBPACK_IMPORTED_MODULE_0__ = __webpack_require__(/*! @babel/runtime/helpers/defineProperty */ "./node_modules/@babel/runtime/helpers/defineProperty.js");
  29995. /* harmony import */ var _babel_runtime_helpers_defineProperty__WEBPACK_IMPORTED_MODULE_0___default = /*#__PURE__*/__webpack_require__.n(_babel_runtime_helpers_defineProperty__WEBPACK_IMPORTED_MODULE_0__);
  29996. /* harmony import */ var utils_mixins__WEBPACK_IMPORTED_MODULE_1__ = __webpack_require__(/*! utils/mixins */ "./src/utils/mixins.js");
  29997. /* harmony import */ var _ComponentView__WEBPACK_IMPORTED_MODULE_2__ = __webpack_require__(/*! ./ComponentView */ "./src/dom_components/view/ComponentView.js");
  29998. function ownKeys(object, enumerableOnly) { var keys = Object.keys(object); if (Object.getOwnPropertySymbols) { var symbols = Object.getOwnPropertySymbols(object); if (enumerableOnly) symbols = symbols.filter(function (sym) { return Object.getOwnPropertyDescriptor(object, sym).enumerable; }); keys.push.apply(keys, symbols); } return keys; }
  29999. function _objectSpread(target) { for (var i = 1; i < arguments.length; i++) { var source = arguments[i] != null ? arguments[i] : {}; if (i % 2) { ownKeys(source, true).forEach(function (key) { _babel_runtime_helpers_defineProperty__WEBPACK_IMPORTED_MODULE_0___default()(target, key, source[key]); }); } else if (Object.getOwnPropertyDescriptors) { Object.defineProperties(target, Object.getOwnPropertyDescriptors(source)); } else { ownKeys(source).forEach(function (key) { Object.defineProperty(target, key, Object.getOwnPropertyDescriptor(source, key)); }); } } return target; }
  30000. var compProt = _ComponentView__WEBPACK_IMPORTED_MODULE_2__["default"].prototype;
  30001. /* harmony default export */ __webpack_exports__["default"] = (_ComponentView__WEBPACK_IMPORTED_MODULE_2__["default"].extend({
  30002. events: {
  30003. dblclick: 'onActive',
  30004. input: 'onInput'
  30005. },
  30006. initialize: function initialize(o) {
  30007. compProt.initialize.apply(this, arguments);
  30008. this.disableEditing = this.disableEditing.bind(this);
  30009. var model = this.model;
  30010. var em = this.em;
  30011. this.listenTo(model, 'focus', this.onActive);
  30012. this.listenTo(model, 'change:content', this.updateContentText);
  30013. this.listenTo(model, 'sync:content', this.syncContent);
  30014. this.rte = em && em.get('RichTextEditor');
  30015. },
  30016. updateContentText: function updateContentText(m, v) {
  30017. var opts = arguments.length > 2 && arguments[2] !== undefined ? arguments[2] : {};
  30018. !opts.fromDisable && this.disableEditing();
  30019. },
  30020. /**
  30021. * Enable element content editing
  30022. * @private
  30023. * */
  30024. onActive: function onActive(e) {
  30025. // We place this before stopPropagation in case of nested
  30026. // text components will not block the editing (#1394)
  30027. if (this.rteEnabled || !this.model.get('editable')) {
  30028. return;
  30029. }
  30030. e && e.stopPropagation && e.stopPropagation();
  30031. var rte = this.rte,
  30032. em = this.em;
  30033. if (rte) {
  30034. try {
  30035. this.activeRte = rte.enable(this, this.activeRte);
  30036. } catch (err) {
  30037. em.logError(err);
  30038. }
  30039. }
  30040. this.toggleEvents(1);
  30041. },
  30042. onDisable: function onDisable() {
  30043. this.disableEditing();
  30044. },
  30045. /**
  30046. * Disable element content editing
  30047. * @private
  30048. * */
  30049. disableEditing: function disableEditing() {
  30050. var model = this.model,
  30051. rte = this.rte,
  30052. activeRte = this.activeRte,
  30053. em = this.em;
  30054. var editable = model.get('editable');
  30055. if (rte && editable) {
  30056. try {
  30057. rte.disable(this, activeRte);
  30058. } catch (err) {
  30059. em.logError(err);
  30060. }
  30061. this.syncContent();
  30062. }
  30063. this.toggleEvents();
  30064. },
  30065. /**
  30066. * get content from RTE
  30067. * @return string
  30068. */
  30069. getContent: function getContent() {
  30070. var rte = this.rte;
  30071. var _ref = rte || {},
  30072. activeRte = _ref.activeRte;
  30073. var content = '';
  30074. if (activeRte && typeof activeRte.getContent === 'function') {
  30075. content = activeRte.getContent();
  30076. } else {
  30077. content = this.getChildrenContainer().innerHTML;
  30078. }
  30079. return content;
  30080. },
  30081. /**
  30082. * Merge content from the DOM to the model
  30083. */
  30084. syncContent: function syncContent() {
  30085. var opts = arguments.length > 0 && arguments[0] !== undefined ? arguments[0] : {};
  30086. var model = this.model,
  30087. rte = this.rte,
  30088. rteEnabled = this.rteEnabled;
  30089. if (!rteEnabled && !opts.force) return;
  30090. var content = this.getContent();
  30091. var comps = model.components();
  30092. var contentOpt = _objectSpread({
  30093. fromDisable: 1
  30094. }, opts);
  30095. comps.length && comps.reset(null, opts);
  30096. model.set('content', '', contentOpt); // If there is a custom RTE the content is just baked staticly
  30097. // inside 'content'
  30098. if (rte.customRte) {
  30099. model.set('content', content, contentOpt);
  30100. } else {
  30101. var clean = function clean(model) {
  30102. var textable = !!model.get('textable');
  30103. var selectable = !['text', 'default', ''].some(function (type) {
  30104. return model.is(type);
  30105. }) || textable;
  30106. model.set(_objectSpread({
  30107. _innertext: !selectable,
  30108. editable: selectable && model.get('editable'),
  30109. selectable: selectable,
  30110. hoverable: selectable,
  30111. removable: textable,
  30112. draggable: textable,
  30113. highlightable: 0,
  30114. copyable: textable
  30115. }, !textable && {
  30116. toolbar: ''
  30117. }), opts);
  30118. model.get('components').each(function (model) {
  30119. return clean(model);
  30120. });
  30121. }; // Avoid re-render on reset with silent option
  30122. !opts.silent && model.trigger('change:content', model, '', contentOpt);
  30123. comps.add(content, opts);
  30124. comps.each(function (model) {
  30125. return clean(model);
  30126. });
  30127. comps.trigger('resetNavigator');
  30128. }
  30129. },
  30130. getModelsFromEl: function getModelsFromEl(el) {
  30131. var result = [];
  30132. var children = (el || this.el).childNodes;
  30133. for (var index = 0; index < children.length; index++) {
  30134. var child = children[index];
  30135. var model = child.__cashData && child.__cashData.model;
  30136. if (model) {
  30137. model.components = this.getModelsFromEl(child);
  30138. if (model.get('content')) {
  30139. model.attributes.content = child.textContent;
  30140. } // TODO add attributes;
  30141. result.push(model);
  30142. }
  30143. }
  30144. return result;
  30145. },
  30146. /**
  30147. * Callback on input event
  30148. * @param {Event} e
  30149. */
  30150. onInput: function onInput() {
  30151. var em = this.em;
  30152. var evPfx = 'component';
  30153. var ev = ["".concat(evPfx, ":update"), "".concat(evPfx, ":input")].join(' '); // Update toolbars
  30154. em && em.trigger(ev, this.model);
  30155. },
  30156. /**
  30157. * Isolate disable propagation method
  30158. * @param {Event}
  30159. * @private
  30160. * */
  30161. disablePropagation: function disablePropagation(e) {
  30162. e.stopPropagation();
  30163. },
  30164. /**
  30165. * Enable/Disable events
  30166. * @param {Boolean} enable
  30167. */
  30168. toggleEvents: function toggleEvents(enable) {
  30169. var em = this.em;
  30170. var mixins = {
  30171. on: utils_mixins__WEBPACK_IMPORTED_MODULE_1__["on"],
  30172. off: utils_mixins__WEBPACK_IMPORTED_MODULE_1__["off"]
  30173. };
  30174. var method = enable ? 'on' : 'off';
  30175. em.setEditing(enable);
  30176. this.rteEnabled = !!enable; // The ownerDocument is from the frame
  30177. var elDocs = [this.el.ownerDocument, document];
  30178. mixins.off(elDocs, 'mousedown', this.disableEditing);
  30179. mixins[method](elDocs, 'mousedown', this.disableEditing);
  30180. em[method]('toolbar:run:before', this.disableEditing); // Avoid closing edit mode on component click
  30181. this.$el.off('mousedown', this.disablePropagation);
  30182. this.$el[method]('mousedown', this.disablePropagation); // Fixes #2210 but use this also as a replacement
  30183. // of this fix: bd7b804f3b46eb45b4398304b2345ce870f232d2
  30184. if (this.config.draggableComponents) {
  30185. var el = this.el;
  30186. while (el) {
  30187. el.draggable = enable ? !1 : !0; // Note: el.parentNode is sometimes null here
  30188. el = el.parentNode;
  30189. el && el.tagName == 'BODY' && (el = 0);
  30190. }
  30191. }
  30192. }
  30193. }));
  30194. /***/ }),
  30195. /***/ "./src/dom_components/view/ComponentVideoView.js":
  30196. /*!*******************************************************!*\
  30197. !*** ./src/dom_components/view/ComponentVideoView.js ***!
  30198. \*******************************************************/
  30199. /*! exports provided: default */
  30200. /***/ (function(module, __webpack_exports__, __webpack_require__) {
  30201. "use strict";
  30202. __webpack_require__.r(__webpack_exports__);
  30203. /* harmony import */ var _ComponentImageView__WEBPACK_IMPORTED_MODULE_0__ = __webpack_require__(/*! ./ComponentImageView */ "./src/dom_components/view/ComponentImageView.js");
  30204. /* harmony import */ var _ComponentView__WEBPACK_IMPORTED_MODULE_1__ = __webpack_require__(/*! ./ComponentView */ "./src/dom_components/view/ComponentView.js");
  30205. /* harmony default export */ __webpack_exports__["default"] = (_ComponentImageView__WEBPACK_IMPORTED_MODULE_0__["default"].extend({
  30206. tagName: 'div',
  30207. events: {},
  30208. initialize: function initialize(o) {
  30209. _ComponentView__WEBPACK_IMPORTED_MODULE_1__["default"].prototype.initialize.apply(this, arguments);
  30210. var model = this.model;
  30211. var props = ['loop', 'autoplay', 'controls', 'color', 'rel', 'modestbranding', 'poster'];
  30212. var events = props.map(function (p) {
  30213. return "change:".concat(p);
  30214. }).join(' ');
  30215. this.listenTo(model, 'change:provider', this.updateProvider);
  30216. this.listenTo(model, 'change:src', this.updateSrc);
  30217. this.listenTo(model, events, this.updateVideo);
  30218. },
  30219. /**
  30220. * Rerender on update of the provider
  30221. * @private
  30222. */
  30223. updateProvider: function updateProvider() {
  30224. var prov = this.model.get('provider');
  30225. this.el.innerHTML = '';
  30226. this.el.appendChild(this.renderByProvider(prov));
  30227. },
  30228. /**
  30229. * Update the source of the video
  30230. * @private
  30231. */
  30232. updateSrc: function updateSrc() {
  30233. var model = this.model,
  30234. videoEl = this.videoEl;
  30235. if (!videoEl) return;
  30236. var prov = model.get('provider');
  30237. var src = model.get('src');
  30238. switch (prov) {
  30239. case 'yt':
  30240. src = model.getYoutubeSrc();
  30241. break;
  30242. case 'ytnc':
  30243. src = model.getYoutubeNoCookieSrc();
  30244. break;
  30245. case 'vi':
  30246. src = model.getVimeoSrc();
  30247. break;
  30248. }
  30249. videoEl.src = src;
  30250. },
  30251. /**
  30252. * Update video parameters
  30253. * @private
  30254. */
  30255. updateVideo: function updateVideo() {
  30256. var prov = this.model.get('provider');
  30257. var videoEl = this.videoEl;
  30258. var md = this.model;
  30259. switch (prov) {
  30260. case 'yt':
  30261. case 'ytnc':
  30262. case 'vi':
  30263. this.model.trigger('change:videoId');
  30264. break;
  30265. default:
  30266. videoEl.loop = md.get('loop');
  30267. videoEl.autoplay = md.get('autoplay');
  30268. videoEl.controls = md.get('controls');
  30269. videoEl.poster = md.get('poster');
  30270. }
  30271. },
  30272. renderByProvider: function renderByProvider(prov) {
  30273. var videoEl;
  30274. switch (prov) {
  30275. case 'yt':
  30276. videoEl = this.renderYoutube();
  30277. break;
  30278. case 'ytnc':
  30279. videoEl = this.renderYoutubeNoCookie();
  30280. break;
  30281. case 'vi':
  30282. videoEl = this.renderVimeo();
  30283. break;
  30284. default:
  30285. videoEl = this.renderSource();
  30286. }
  30287. this.videoEl = videoEl;
  30288. return videoEl;
  30289. },
  30290. renderSource: function renderSource() {
  30291. var el = document.createElement('video');
  30292. el.src = this.model.get('src');
  30293. this.initVideoEl(el);
  30294. return el;
  30295. },
  30296. renderYoutube: function renderYoutube() {
  30297. var el = document.createElement('iframe');
  30298. el.src = this.model.getYoutubeSrc();
  30299. el.frameBorder = 0;
  30300. el.setAttribute('allowfullscreen', true);
  30301. this.initVideoEl(el);
  30302. return el;
  30303. },
  30304. renderYoutubeNoCookie: function renderYoutubeNoCookie() {
  30305. var el = document.createElement('iframe');
  30306. el.src = this.model.getYoutubeNoCookieSrc();
  30307. el.frameBorder = 0;
  30308. el.setAttribute('allowfullscreen', true);
  30309. this.initVideoEl(el);
  30310. return el;
  30311. },
  30312. renderVimeo: function renderVimeo() {
  30313. var el = document.createElement('iframe');
  30314. el.src = this.model.getVimeoSrc();
  30315. el.frameBorder = 0;
  30316. el.setAttribute('allowfullscreen', true);
  30317. this.initVideoEl(el);
  30318. return el;
  30319. },
  30320. initVideoEl: function initVideoEl(el) {
  30321. el.className = this.ppfx + 'no-pointer';
  30322. el.style.height = '100%';
  30323. el.style.width = '100%';
  30324. },
  30325. render: function render() {
  30326. for (var _len = arguments.length, args = new Array(_len), _key = 0; _key < _len; _key++) {
  30327. args[_key] = arguments[_key];
  30328. }
  30329. _ComponentImageView__WEBPACK_IMPORTED_MODULE_0__["default"].prototype.render.apply(this, args);
  30330. this.updateClasses();
  30331. var prov = this.model.get('provider');
  30332. this.el.appendChild(this.renderByProvider(prov));
  30333. this.updateVideo();
  30334. return this;
  30335. }
  30336. }));
  30337. /***/ }),
  30338. /***/ "./src/dom_components/view/ComponentView.js":
  30339. /*!**************************************************!*\
  30340. !*** ./src/dom_components/view/ComponentView.js ***!
  30341. \**************************************************/
  30342. /*! exports provided: default */
  30343. /***/ (function(module, __webpack_exports__, __webpack_require__) {
  30344. "use strict";
  30345. __webpack_require__.r(__webpack_exports__);
  30346. /* harmony import */ var _babel_runtime_helpers_defineProperty__WEBPACK_IMPORTED_MODULE_0__ = __webpack_require__(/*! @babel/runtime/helpers/defineProperty */ "./node_modules/@babel/runtime/helpers/defineProperty.js");
  30347. /* harmony import */ var _babel_runtime_helpers_defineProperty__WEBPACK_IMPORTED_MODULE_0___default = /*#__PURE__*/__webpack_require__.n(_babel_runtime_helpers_defineProperty__WEBPACK_IMPORTED_MODULE_0__);
  30348. /* harmony import */ var backbone__WEBPACK_IMPORTED_MODULE_1__ = __webpack_require__(/*! backbone */ "./node_modules/backbone/backbone.js");
  30349. /* harmony import */ var backbone__WEBPACK_IMPORTED_MODULE_1___default = /*#__PURE__*/__webpack_require__.n(backbone__WEBPACK_IMPORTED_MODULE_1__);
  30350. /* harmony import */ var underscore__WEBPACK_IMPORTED_MODULE_2__ = __webpack_require__(/*! underscore */ "./node_modules/underscore/underscore.js");
  30351. /* harmony import */ var underscore__WEBPACK_IMPORTED_MODULE_2___default = /*#__PURE__*/__webpack_require__.n(underscore__WEBPACK_IMPORTED_MODULE_2__);
  30352. /* harmony import */ var _model_Components__WEBPACK_IMPORTED_MODULE_3__ = __webpack_require__(/*! ../model/Components */ "./src/dom_components/model/Components.js");
  30353. /* harmony import */ var _ComponentsView__WEBPACK_IMPORTED_MODULE_4__ = __webpack_require__(/*! ./ComponentsView */ "./src/dom_components/view/ComponentsView.js");
  30354. /* harmony import */ var selector_manager_model_Selectors__WEBPACK_IMPORTED_MODULE_5__ = __webpack_require__(/*! selector_manager/model/Selectors */ "./src/selector_manager/model/Selectors.js");
  30355. /* harmony import */ var utils_dom__WEBPACK_IMPORTED_MODULE_6__ = __webpack_require__(/*! utils/dom */ "./src/utils/dom.js");
  30356. /* harmony import */ var utils_mixins__WEBPACK_IMPORTED_MODULE_7__ = __webpack_require__(/*! utils/mixins */ "./src/utils/mixins.js");
  30357. function ownKeys(object, enumerableOnly) { var keys = Object.keys(object); if (Object.getOwnPropertySymbols) { var symbols = Object.getOwnPropertySymbols(object); if (enumerableOnly) symbols = symbols.filter(function (sym) { return Object.getOwnPropertyDescriptor(object, sym).enumerable; }); keys.push.apply(keys, symbols); } return keys; }
  30358. function _objectSpread(target) { for (var i = 1; i < arguments.length; i++) { var source = arguments[i] != null ? arguments[i] : {}; if (i % 2) { ownKeys(source, true).forEach(function (key) { _babel_runtime_helpers_defineProperty__WEBPACK_IMPORTED_MODULE_0___default()(target, key, source[key]); }); } else if (Object.getOwnPropertyDescriptors) { Object.defineProperties(target, Object.getOwnPropertyDescriptors(source)); } else { ownKeys(source).forEach(function (key) { Object.defineProperty(target, key, Object.getOwnPropertyDescriptor(source, key)); }); } } return target; }
  30359. /* harmony default export */ __webpack_exports__["default"] = (backbone__WEBPACK_IMPORTED_MODULE_1___default.a.View.extend({
  30360. className: function className() {
  30361. return this.getClasses();
  30362. },
  30363. tagName: function tagName() {
  30364. return this.model.get('tagName');
  30365. },
  30366. initialize: function initialize() {
  30367. var opt = arguments.length > 0 && arguments[0] !== undefined ? arguments[0] : {};
  30368. var model = this.model;
  30369. var config = opt.config || {};
  30370. var em = config.em;
  30371. var modelOpt = model.opt || {};
  30372. var $el = this.$el,
  30373. el = this.el;
  30374. var draggableComponents = config.draggableComponents;
  30375. this.opts = opt;
  30376. this.modelOpt = modelOpt;
  30377. this.config = config;
  30378. this.em = em || '';
  30379. this.pfx = config.stylePrefix || '';
  30380. this.ppfx = config.pStylePrefix || '';
  30381. this.attr = model.get('attributes');
  30382. this.classe = this.attr.class || [];
  30383. this.listenTo(model, 'change:style', this.updateStyle);
  30384. this.listenTo(model, 'change:attributes change:_innertext', this.renderAttributes);
  30385. this.listenTo(model, 'change:highlightable', this.updateHighlight);
  30386. this.listenTo(model, 'change:status', this.updateStatus);
  30387. this.listenTo(model, 'change:script', this.reset);
  30388. this.listenTo(model, 'change:content', this.updateContent);
  30389. this.listenTo(model, 'change', this.handleChange);
  30390. this.listenTo(model, 'active', this.onActive);
  30391. this.listenTo(model, 'disable', this.onDisable);
  30392. $el.data('model', model);
  30393. Object(utils_mixins__WEBPACK_IMPORTED_MODULE_7__["setViewEl"])(el, this);
  30394. model.view = this;
  30395. this._getFrame() && model.views.push(this);
  30396. this.initClasses();
  30397. this.initComponents({
  30398. avoidRender: 1
  30399. });
  30400. this.events = _objectSpread({}, this.events, {}, draggableComponents && {
  30401. dragstart: 'handleDragStart'
  30402. });
  30403. this.delegateEvents();
  30404. !modelOpt.temporary && this.init(this._clbObj());
  30405. },
  30406. _clbObj: function _clbObj() {
  30407. var em = this.em,
  30408. model = this.model,
  30409. el = this.el;
  30410. return {
  30411. editor: em && em.getEditor(),
  30412. model: model,
  30413. el: el
  30414. };
  30415. },
  30416. /**
  30417. * Initialize callback
  30418. */
  30419. init: function init() {},
  30420. /**
  30421. * Remove callback
  30422. */
  30423. removed: function removed() {},
  30424. /**
  30425. * Callback executed when the `active` event is triggered on component
  30426. */
  30427. onActive: function onActive() {},
  30428. /**
  30429. * Callback executed when the `disable` event is triggered on component
  30430. */
  30431. onDisable: function onDisable() {},
  30432. remove: function remove() {
  30433. var view = this;
  30434. backbone__WEBPACK_IMPORTED_MODULE_1___default.a.View.prototype.remove.apply(view, arguments);
  30435. var model = view.model;
  30436. var frame = view._getFrame() || {};
  30437. var frameM = frame.model;
  30438. model.components().forEach(function (comp) {
  30439. var view = comp.getView(frameM);
  30440. view && view.remove();
  30441. });
  30442. var views = model.views;
  30443. views.splice(views.indexOf(view), 1);
  30444. view.removed(view._clbObj());
  30445. view.$el.data({
  30446. model: '',
  30447. collection: '',
  30448. view: ''
  30449. });
  30450. delete view.model;
  30451. delete view.$el;
  30452. delete view.el.__gjsv;
  30453. delete view.childrenView;
  30454. delete view.scriptContainer;
  30455. delete view.opts; // delete view.el;
  30456. return view;
  30457. },
  30458. handleDragStart: function handleDragStart(event) {
  30459. event.preventDefault();
  30460. event.stopPropagation();
  30461. this.em.get('Commands').run('tlb-move', {
  30462. target: this.model,
  30463. event: event
  30464. });
  30465. },
  30466. initClasses: function initClasses() {
  30467. var model = this.model;
  30468. var event = 'change:classes';
  30469. var classes = model.get('classes');
  30470. if (classes instanceof selector_manager_model_Selectors__WEBPACK_IMPORTED_MODULE_5__["default"]) {
  30471. this.stopListening(model, event, this.initClasses);
  30472. this.listenTo(model, event, this.initClasses);
  30473. this.listenTo(classes, 'add remove change', this.updateClasses);
  30474. classes.length && this.importClasses();
  30475. }
  30476. },
  30477. initComponents: function initComponents() {
  30478. var opts = arguments.length > 0 && arguments[0] !== undefined ? arguments[0] : {};
  30479. var model = this.model,
  30480. $el = this.$el,
  30481. childrenView = this.childrenView;
  30482. var event = 'change:components';
  30483. var comps = model.get('components');
  30484. var toListen = [model, event, this.initComponents];
  30485. if (comps instanceof _model_Components__WEBPACK_IMPORTED_MODULE_3__["default"]) {
  30486. $el.data('collection', comps);
  30487. childrenView && childrenView.remove();
  30488. this.stopListening.apply(this, toListen);
  30489. !opts.avoidRender && this.renderChildren();
  30490. this.listenTo.apply(this, toListen);
  30491. }
  30492. },
  30493. /**
  30494. * Handle any property change
  30495. * @private
  30496. */
  30497. handleChange: function handleChange() {
  30498. var model = this.model;
  30499. var chgArr = Object(underscore__WEBPACK_IMPORTED_MODULE_2__["keys"])(model.changed);
  30500. if (chgArr.length === 1 && chgArr[0] === 'status') return;
  30501. model.emitUpdate();
  30502. for (var prop in model.changed) {
  30503. model.emitUpdate(prop);
  30504. }
  30505. },
  30506. /**
  30507. * Import, if possible, classes inside main container
  30508. * @private
  30509. * */
  30510. importClasses: function importClasses() {
  30511. var clm = this.config.em.get('SelectorManager');
  30512. if (clm) {
  30513. this.model.get('classes').each(function (m) {
  30514. clm.add(m.get('name'));
  30515. });
  30516. }
  30517. },
  30518. /**
  30519. * Update item on status change
  30520. * @param {Event} e
  30521. * @private
  30522. * */
  30523. updateStatus: function updateStatus() {
  30524. var opts = arguments.length > 0 && arguments[0] !== undefined ? arguments[0] : {};
  30525. var em = this.em;
  30526. var el = this.el;
  30527. var status = this.model.get('status');
  30528. var pfx = this.pfx;
  30529. var ppfx = this.ppfx;
  30530. var selectedCls = "".concat(ppfx, "selected");
  30531. var selectedParentCls = "".concat(selectedCls, "-parent");
  30532. var freezedCls = "".concat(ppfx, "freezed");
  30533. var hoveredCls = "".concat(ppfx, "hovered");
  30534. var toRemove = [selectedCls, selectedParentCls, freezedCls, hoveredCls];
  30535. this.$el.removeClass(toRemove.join(' '));
  30536. var actualCls = el.getAttribute('class') || '';
  30537. var cls = '';
  30538. switch (status) {
  30539. case 'selected':
  30540. cls = "".concat(actualCls, " ").concat(selectedCls);
  30541. break;
  30542. case 'selected-parent':
  30543. cls = "".concat(actualCls, " ").concat(selectedParentCls);
  30544. break;
  30545. case 'freezed':
  30546. cls = "".concat(actualCls, " ").concat(freezedCls);
  30547. break;
  30548. case 'freezed-selected':
  30549. cls = "".concat(actualCls, " ").concat(freezedCls, " ").concat(selectedCls);
  30550. break;
  30551. case 'hovered':
  30552. cls = !opts.avoidHover ? "".concat(actualCls, " ").concat(hoveredCls) : '';
  30553. break;
  30554. }
  30555. cls = cls.trim();
  30556. cls && el.setAttribute('class', cls);
  30557. },
  30558. /**
  30559. * Update highlight attribute
  30560. * @private
  30561. * */
  30562. updateHighlight: function updateHighlight() {
  30563. var hl = this.model.get('highlightable');
  30564. this.setAttribute('data-highlightable', hl ? 1 : '');
  30565. },
  30566. /**
  30567. * Update style attribute
  30568. * @private
  30569. * */
  30570. updateStyle: function updateStyle() {
  30571. var model = this.model,
  30572. em = this.em,
  30573. el = this.el;
  30574. if (em && em.getConfig('avoidInlineStyle')) {
  30575. if (model.get('_innertext')) {
  30576. el.removeAttribute('id');
  30577. } else {
  30578. el.id = model.getId();
  30579. }
  30580. var style = model.getStyle();
  30581. !Object(underscore__WEBPACK_IMPORTED_MODULE_2__["isEmpty"])(style) && model.setStyle(style);
  30582. } else {
  30583. this.setAttribute('style', model.styleToString());
  30584. }
  30585. },
  30586. /**
  30587. * Update classe attribute
  30588. * @private
  30589. * */
  30590. updateClasses: function updateClasses() {
  30591. var str = this.model.get('classes').pluck('name').join(' ');
  30592. this.setAttribute('class', str); // Regenerate status class
  30593. this.updateStatus();
  30594. },
  30595. /**
  30596. * Update single attribute
  30597. * @param {[type]} name [description]
  30598. * @param {[type]} value [description]
  30599. */
  30600. setAttribute: function setAttribute(name, value) {
  30601. var el = this.$el;
  30602. value ? el.attr(name, value) : el.removeAttr(name);
  30603. },
  30604. /**
  30605. * Get classes from attributes.
  30606. * This method is called before initialize
  30607. *
  30608. * @return {Array}|null
  30609. * @private
  30610. * */
  30611. getClasses: function getClasses() {
  30612. return this.model.getClasses().join(' ');
  30613. },
  30614. /**
  30615. * Update attributes
  30616. * @private
  30617. * */
  30618. updateAttributes: function updateAttributes() {
  30619. var attrs = [];
  30620. var model = this.model,
  30621. $el = this.$el,
  30622. el = this.el,
  30623. config = this.config;
  30624. var _model$attributes = model.attributes,
  30625. highlightable = _model$attributes.highlightable,
  30626. textable = _model$attributes.textable,
  30627. type = _model$attributes.type,
  30628. _innertext = _model$attributes._innertext;
  30629. var draggableComponents = config.draggableComponents;
  30630. var defaultAttr = _objectSpread({
  30631. 'data-gjs-type': type || 'default'
  30632. }, draggableComponents && !_innertext ? {
  30633. draggable: true
  30634. } : {}, {}, highlightable ? {
  30635. 'data-highlightable': 1
  30636. } : {}, {}, textable ? {
  30637. contenteditable: 'false',
  30638. 'data-gjs-textable': 'true'
  30639. } : {}); // Remove all current attributes
  30640. Object(underscore__WEBPACK_IMPORTED_MODULE_2__["each"])(el.attributes, function (attr) {
  30641. return attrs.push(attr.nodeName);
  30642. });
  30643. attrs.forEach(function (attr) {
  30644. return $el.removeAttr(attr);
  30645. });
  30646. var attr = _objectSpread({}, defaultAttr, {}, model.getAttributes()); // Remove all `false` attributes
  30647. Object(underscore__WEBPACK_IMPORTED_MODULE_2__["keys"])(attr).forEach(function (key) {
  30648. return attr[key] === false && delete attr[key];
  30649. });
  30650. $el.attr(attr);
  30651. this.updateStyle();
  30652. },
  30653. /**
  30654. * Update component content
  30655. * @private
  30656. * */
  30657. updateContent: function updateContent() {
  30658. this.getChildrenContainer().innerHTML = this.model.get('content');
  30659. },
  30660. /**
  30661. * Prevent default helper
  30662. * @param {Event} e
  30663. * @private
  30664. */
  30665. prevDef: function prevDef(e) {
  30666. e.preventDefault();
  30667. },
  30668. /**
  30669. * Render component's script
  30670. * @private
  30671. */
  30672. updateScript: function updateScript() {
  30673. var model = this.model,
  30674. em = this.em;
  30675. if (!model.get('script')) return;
  30676. em && em.get('Canvas').getCanvasView().updateScript(this);
  30677. },
  30678. /**
  30679. * Return children container
  30680. * Differently from a simple component where children container is the
  30681. * component itself
  30682. * <my-comp>
  30683. * <!--
  30684. * <child></child> ...
  30685. * -->
  30686. * </my-comp>
  30687. * You could have the children container more deeper
  30688. * <my-comp>
  30689. * <div></div>
  30690. * <div></div>
  30691. * <div>
  30692. * <div>
  30693. * <!--
  30694. * <child></child> ...
  30695. * -->
  30696. * </div>
  30697. * </div>
  30698. * </my-comp>
  30699. * @return HTMLElement
  30700. * @private
  30701. */
  30702. getChildrenContainer: function getChildrenContainer() {
  30703. var container = this.el;
  30704. if (typeof this.getChildrenSelector == 'function') {
  30705. container = this.el.querySelector(this.getChildrenSelector());
  30706. } else if (typeof this.getTemplate == 'function') {// Need to find deepest first child
  30707. }
  30708. return container;
  30709. },
  30710. /**
  30711. * This returns rect informations not affected by the canvas zoom.
  30712. * The method `getBoundingClientRect` doesn't work here and we
  30713. * have to take in account offsetParent
  30714. */
  30715. getOffsetRect: function getOffsetRect() {
  30716. var rect = {};
  30717. var target = this.el;
  30718. var gtop = 0;
  30719. var gleft = 0;
  30720. var assignRect = function assignRect(el) {
  30721. var offsetParent = el.offsetParent;
  30722. if (offsetParent) {
  30723. gtop += offsetParent.offsetTop;
  30724. gleft += offsetParent.offsetLeft;
  30725. assignRect(offsetParent);
  30726. } else {
  30727. rect.top = target.offsetTop + gtop;
  30728. rect.left = target.offsetLeft + gleft;
  30729. rect.bottom = rect.top + target.offsetHeight;
  30730. rect.right = rect.left + target.offsetWidth;
  30731. }
  30732. };
  30733. assignRect(target);
  30734. return rect;
  30735. },
  30736. isInViewport: function isInViewport() {
  30737. var _ref = arguments.length > 0 && arguments[0] !== undefined ? arguments[0] : {},
  30738. rect = _ref.rect;
  30739. var el = this.el;
  30740. var elDoc = el.ownerDocument;
  30741. var body = elDoc.body;
  30742. var frameElement = elDoc.defaultView.frameElement;
  30743. var _ref2 = rect || this.getOffsetRect(),
  30744. top = _ref2.top,
  30745. left = _ref2.left;
  30746. var frame = this._getFrame().getOffsetRect();
  30747. return top >= frame.scrollTop && left >= frame.scrollLeft && top <= frame.scrollBottom && left <= frameElement.offsetWidth + body.scrollLeft;
  30748. },
  30749. scrollIntoView: function scrollIntoView() {
  30750. var opts = arguments.length > 0 && arguments[0] !== undefined ? arguments[0] : {};
  30751. var rect = this.getOffsetRect();
  30752. var isInViewport = this.isInViewport({
  30753. rect: rect
  30754. });
  30755. if (!isInViewport || opts.force) {
  30756. var el = this.el; // PATCH: scrollIntoView won't work with multiple requests from iframes
  30757. if (opts.behavior !== 'smooth') {
  30758. el.ownerDocument.defaultView.scrollTo(0, rect.top);
  30759. } else {
  30760. el.scrollIntoView(_objectSpread({
  30761. behavior: 'smooth',
  30762. block: 'nearest'
  30763. }, opts));
  30764. }
  30765. }
  30766. },
  30767. /**
  30768. * Recreate the element of the view
  30769. */
  30770. reset: function reset() {
  30771. var el = this.el;
  30772. this.el = '';
  30773. this._ensureElement();
  30774. this._setData();
  30775. Object(utils_dom__WEBPACK_IMPORTED_MODULE_6__["replaceWith"])(el, this.el);
  30776. this.render();
  30777. },
  30778. _setData: function _setData() {
  30779. var model = this.model;
  30780. var collection = model.components();
  30781. var view = this;
  30782. this.$el.data({
  30783. model: model,
  30784. collection: collection,
  30785. view: view
  30786. });
  30787. },
  30788. _getFrame: function _getFrame() {
  30789. return this.config.frameView;
  30790. },
  30791. /**
  30792. * Render children components
  30793. * @private
  30794. */
  30795. renderChildren: function renderChildren() {
  30796. this.updateContent();
  30797. var container = this.getChildrenContainer();
  30798. var view = this.childrenView || new _ComponentsView__WEBPACK_IMPORTED_MODULE_4__["default"]({
  30799. collection: this.model.get('components'),
  30800. config: this.config,
  30801. componentTypes: this.opts.componentTypes
  30802. });
  30803. view.render(container);
  30804. this.childrenView = view;
  30805. var childNodes = Array.prototype.slice.call(view.el.childNodes);
  30806. for (var i = 0, len = childNodes.length; i < len; i++) {
  30807. container.appendChild(childNodes.shift());
  30808. }
  30809. },
  30810. renderAttributes: function renderAttributes() {
  30811. this.updateAttributes();
  30812. this.updateClasses();
  30813. },
  30814. render: function render() {
  30815. this.renderAttributes();
  30816. if (this.modelOpt.temporary) return this;
  30817. this.renderChildren();
  30818. this.updateScript();
  30819. Object(utils_mixins__WEBPACK_IMPORTED_MODULE_7__["setViewEl"])(this.el, this);
  30820. this.postRender();
  30821. return this;
  30822. },
  30823. postRender: function postRender() {
  30824. var em = this.em,
  30825. model = this.model,
  30826. modelOpt = this.modelOpt;
  30827. if (!modelOpt.temporary) {
  30828. this.onRender(this._clbObj());
  30829. em && em.trigger('component:mount', model);
  30830. }
  30831. },
  30832. onRender: function onRender() {}
  30833. }));
  30834. /***/ }),
  30835. /***/ "./src/dom_components/view/ComponentsView.js":
  30836. /*!***************************************************!*\
  30837. !*** ./src/dom_components/view/ComponentsView.js ***!
  30838. \***************************************************/
  30839. /*! exports provided: default */
  30840. /***/ (function(module, __webpack_exports__, __webpack_require__) {
  30841. "use strict";
  30842. __webpack_require__.r(__webpack_exports__);
  30843. /* harmony import */ var backbone__WEBPACK_IMPORTED_MODULE_0__ = __webpack_require__(/*! backbone */ "./node_modules/backbone/backbone.js");
  30844. /* harmony import */ var backbone__WEBPACK_IMPORTED_MODULE_0___default = /*#__PURE__*/__webpack_require__.n(backbone__WEBPACK_IMPORTED_MODULE_0__);
  30845. /* harmony import */ var underscore__WEBPACK_IMPORTED_MODULE_1__ = __webpack_require__(/*! underscore */ "./node_modules/underscore/underscore.js");
  30846. /* harmony import */ var underscore__WEBPACK_IMPORTED_MODULE_1___default = /*#__PURE__*/__webpack_require__.n(underscore__WEBPACK_IMPORTED_MODULE_1__);
  30847. /* harmony default export */ __webpack_exports__["default"] = (backbone__WEBPACK_IMPORTED_MODULE_0___default.a.View.extend({
  30848. initialize: function initialize(o) {
  30849. this.opts = o || {};
  30850. this.config = o.config || {};
  30851. this.em = this.config.em;
  30852. var coll = this.collection;
  30853. this.listenTo(coll, 'add', this.addTo);
  30854. this.listenTo(coll, 'reset', this.resetChildren);
  30855. this.listenTo(coll, 'remove', this.removeChildren);
  30856. },
  30857. removeChildren: function removeChildren(removed, coll) {
  30858. var _this = this;
  30859. var opts = arguments.length > 2 && arguments[2] !== undefined ? arguments[2] : {};
  30860. removed.views.forEach(function (view) {
  30861. if (!view) return;
  30862. var childrenView = view.childrenView,
  30863. scriptContainer = view.scriptContainer;
  30864. childrenView && childrenView.stopListening();
  30865. scriptContainer && scriptContainer.remove();
  30866. view.remove.apply(view);
  30867. });
  30868. var inner = removed.components();
  30869. inner.forEach(function (it) {
  30870. return _this.removeChildren(it, coll, opts);
  30871. });
  30872. },
  30873. /**
  30874. * Add to collection
  30875. * @param {Model} model
  30876. * @param {Collection} coll
  30877. * @param {Object} opts
  30878. * @private
  30879. * */
  30880. addTo: function addTo(model) {
  30881. var coll = arguments.length > 1 && arguments[1] !== undefined ? arguments[1] : {};
  30882. var opts = arguments.length > 2 && arguments[2] !== undefined ? arguments[2] : {};
  30883. var em = this.config.em;
  30884. var i = this.collection.indexOf(model);
  30885. this.addToCollection(model, null, i);
  30886. if (em && !opts.temporary) {
  30887. var triggerAdd = function triggerAdd(model) {
  30888. em.trigger('component:add', model);
  30889. model.components().forEach(function (comp) {
  30890. return triggerAdd(comp);
  30891. });
  30892. };
  30893. triggerAdd(model);
  30894. }
  30895. },
  30896. /**
  30897. * Add new object to collection
  30898. * @param {Object} Model
  30899. * @param {Object} Fragment collection
  30900. * @param {Integer} Index of append
  30901. *
  30902. * @return {Object} Object rendered
  30903. * @private
  30904. * */
  30905. addToCollection: function addToCollection(model, fragmentEl, index) {
  30906. if (!this.compView) this.compView = __webpack_require__(/*! ./ComponentView */ "./src/dom_components/view/ComponentView.js").default;
  30907. var config = this.config,
  30908. opts = this.opts,
  30909. em = this.em;
  30910. var fragment = fragmentEl || null;
  30911. var _config$frameView = config.frameView,
  30912. frameView = _config$frameView === void 0 ? {} : _config$frameView;
  30913. var sameFrameView = frameView.model && model.getView(frameView.model);
  30914. var dt = opts.componentTypes || em && em.get('DomComponents').getTypes();
  30915. var type = model.get('type');
  30916. var viewObject = this.compView;
  30917. for (var it = 0; it < dt.length; it++) {
  30918. if (dt[it].id == type) {
  30919. viewObject = dt[it].view;
  30920. break;
  30921. }
  30922. }
  30923. var view = sameFrameView || new viewObject({
  30924. model: model,
  30925. config: config,
  30926. componentTypes: dt
  30927. });
  30928. var rendered = view.render().el;
  30929. if (fragment) {
  30930. fragment.appendChild(rendered);
  30931. } else {
  30932. var parent = this.parentEl;
  30933. var children = parent.childNodes;
  30934. if (!Object(underscore__WEBPACK_IMPORTED_MODULE_1__["isUndefined"])(index)) {
  30935. var lastIndex = children.length == index; // If the added model is the last of collection
  30936. // need to change the logic of append
  30937. if (lastIndex) {
  30938. index--;
  30939. } // In case the added is new in the collection index will be -1
  30940. if (lastIndex || !children.length) {
  30941. parent.appendChild(rendered);
  30942. } else {
  30943. parent.insertBefore(rendered, children[index]);
  30944. }
  30945. } else {
  30946. parent.appendChild(rendered);
  30947. }
  30948. }
  30949. return rendered;
  30950. },
  30951. resetChildren: function resetChildren(models) {
  30952. var _this2 = this;
  30953. var _ref = arguments.length > 1 && arguments[1] !== undefined ? arguments[1] : {},
  30954. _ref$previousModels = _ref.previousModels,
  30955. previousModels = _ref$previousModels === void 0 ? [] : _ref$previousModels;
  30956. this.parentEl.innerHTML = '';
  30957. previousModels.forEach(function (md) {
  30958. return _this2.removeChildren(md, _this2.collection);
  30959. });
  30960. models.each(function (model) {
  30961. return _this2.addToCollection(model);
  30962. });
  30963. },
  30964. render: function render(parent) {
  30965. var _this3 = this;
  30966. var el = this.el;
  30967. var frag = document.createDocumentFragment();
  30968. this.parentEl = parent || this.el;
  30969. this.collection.each(function (model) {
  30970. return _this3.addToCollection(model, frag);
  30971. });
  30972. el.innerHTML = '';
  30973. el.appendChild(frag);
  30974. return this;
  30975. }
  30976. }));
  30977. /***/ }),
  30978. /***/ "./src/dom_components/view/ToolbarButtonView.js":
  30979. /*!******************************************************!*\
  30980. !*** ./src/dom_components/view/ToolbarButtonView.js ***!
  30981. \******************************************************/
  30982. /*! exports provided: default */
  30983. /***/ (function(module, __webpack_exports__, __webpack_require__) {
  30984. "use strict";
  30985. __webpack_require__.r(__webpack_exports__);
  30986. /* harmony import */ var _babel_runtime_helpers_defineProperty__WEBPACK_IMPORTED_MODULE_0__ = __webpack_require__(/*! @babel/runtime/helpers/defineProperty */ "./node_modules/@babel/runtime/helpers/defineProperty.js");
  30987. /* harmony import */ var _babel_runtime_helpers_defineProperty__WEBPACK_IMPORTED_MODULE_0___default = /*#__PURE__*/__webpack_require__.n(_babel_runtime_helpers_defineProperty__WEBPACK_IMPORTED_MODULE_0__);
  30988. /* harmony import */ var backbone__WEBPACK_IMPORTED_MODULE_1__ = __webpack_require__(/*! backbone */ "./node_modules/backbone/backbone.js");
  30989. /* harmony import */ var backbone__WEBPACK_IMPORTED_MODULE_1___default = /*#__PURE__*/__webpack_require__.n(backbone__WEBPACK_IMPORTED_MODULE_1__);
  30990. function ownKeys(object, enumerableOnly) { var keys = Object.keys(object); if (Object.getOwnPropertySymbols) { var symbols = Object.getOwnPropertySymbols(object); if (enumerableOnly) symbols = symbols.filter(function (sym) { return Object.getOwnPropertyDescriptor(object, sym).enumerable; }); keys.push.apply(keys, symbols); } return keys; }
  30991. function _objectSpread(target) { for (var i = 1; i < arguments.length; i++) { var source = arguments[i] != null ? arguments[i] : {}; if (i % 2) { ownKeys(source, true).forEach(function (key) { _babel_runtime_helpers_defineProperty__WEBPACK_IMPORTED_MODULE_0___default()(target, key, source[key]); }); } else if (Object.getOwnPropertyDescriptors) { Object.defineProperties(target, Object.getOwnPropertyDescriptors(source)); } else { ownKeys(source).forEach(function (key) { Object.defineProperty(target, key, Object.getOwnPropertyDescriptor(source, key)); }); } } return target; }
  30992. /* harmony default export */ __webpack_exports__["default"] = (backbone__WEBPACK_IMPORTED_MODULE_1___default.a.View.extend({
  30993. events: function events() {
  30994. return this.model.get('events') || {
  30995. mousedown: 'handleClick'
  30996. };
  30997. },
  30998. attributes: function attributes() {
  30999. return this.model.get('attributes');
  31000. },
  31001. initialize: function initialize() {
  31002. var opts = arguments.length > 0 && arguments[0] !== undefined ? arguments[0] : {};
  31003. var _opts$config = opts.config,
  31004. config = _opts$config === void 0 ? {} : _opts$config;
  31005. this.em = config.em;
  31006. this.editor = config.editor;
  31007. },
  31008. handleClick: function handleClick(event) {
  31009. event.preventDefault();
  31010. event.stopPropagation();
  31011. /*
  31012. * Since the toolbar lives outside the canvas frame, the event's
  31013. * generated on it have clientX and clientY relative to the page.
  31014. *
  31015. * This causes issues during events like dragging, where they depend
  31016. * on the clientX and clientY.
  31017. *
  31018. * This makes sure the offsets are calculated.
  31019. *
  31020. * More information on
  31021. * https://github.com/artf/grapesjs/issues/2372
  31022. * https://github.com/artf/grapesjs/issues/2207
  31023. */
  31024. var editor = this.editor,
  31025. em = this.em;
  31026. var _editor$Canvas$getFra = editor.Canvas.getFrameEl().getBoundingClientRect(),
  31027. left = _editor$Canvas$getFra.left,
  31028. top = _editor$Canvas$getFra.top;
  31029. var calibrated = _objectSpread({}, event, {
  31030. clientX: event.clientX - left,
  31031. clientY: event.clientY - top
  31032. });
  31033. em.trigger('toolbar:run:before');
  31034. this.execCommand(calibrated);
  31035. },
  31036. execCommand: function execCommand(event) {
  31037. var opts = {
  31038. event: event
  31039. };
  31040. var command = this.model.get('command');
  31041. var editor = this.editor;
  31042. if (typeof command === 'function') {
  31043. command(editor, null, opts);
  31044. }
  31045. if (typeof command === 'string') {
  31046. editor.runCommand(command, opts);
  31047. }
  31048. },
  31049. render: function render() {
  31050. var editor = this.editor,
  31051. $el = this.$el,
  31052. model = this.model;
  31053. var id = model.get('id');
  31054. var label = model.get('label');
  31055. var pfx = editor.getConfig('stylePrefix');
  31056. $el.addClass("".concat(pfx, "toolbar-item"));
  31057. id && $el.addClass("".concat(pfx, "toolbar-item__").concat(id));
  31058. label && $el.append(label);
  31059. return this;
  31060. }
  31061. }));
  31062. /***/ }),
  31063. /***/ "./src/dom_components/view/ToolbarView.js":
  31064. /*!************************************************!*\
  31065. !*** ./src/dom_components/view/ToolbarView.js ***!
  31066. \************************************************/
  31067. /*! exports provided: default */
  31068. /***/ (function(module, __webpack_exports__, __webpack_require__) {
  31069. "use strict";
  31070. __webpack_require__.r(__webpack_exports__);
  31071. /* harmony import */ var domain_abstract_view_DomainViews__WEBPACK_IMPORTED_MODULE_0__ = __webpack_require__(/*! domain_abstract/view/DomainViews */ "./src/domain_abstract/view/DomainViews.js");
  31072. /* harmony import */ var _ToolbarButtonView__WEBPACK_IMPORTED_MODULE_1__ = __webpack_require__(/*! ./ToolbarButtonView */ "./src/dom_components/view/ToolbarButtonView.js");
  31073. /* harmony default export */ __webpack_exports__["default"] = (domain_abstract_view_DomainViews__WEBPACK_IMPORTED_MODULE_0__["default"].extend({
  31074. itemView: _ToolbarButtonView__WEBPACK_IMPORTED_MODULE_1__["default"],
  31075. initialize: function initialize() {
  31076. var opts = arguments.length > 0 && arguments[0] !== undefined ? arguments[0] : {};
  31077. this.config = {
  31078. editor: opts.editor || '',
  31079. em: opts.em
  31080. };
  31081. this.listenTo(this.collection, 'reset', this.render);
  31082. }
  31083. }));
  31084. /***/ }),
  31085. /***/ "./src/domain_abstract/model/Styleable.js":
  31086. /*!************************************************!*\
  31087. !*** ./src/domain_abstract/model/Styleable.js ***!
  31088. \************************************************/
  31089. /*! exports provided: default */
  31090. /***/ (function(module, __webpack_exports__, __webpack_require__) {
  31091. "use strict";
  31092. __webpack_require__.r(__webpack_exports__);
  31093. /* harmony import */ var _babel_runtime_helpers_defineProperty__WEBPACK_IMPORTED_MODULE_0__ = __webpack_require__(/*! @babel/runtime/helpers/defineProperty */ "./node_modules/@babel/runtime/helpers/defineProperty.js");
  31094. /* harmony import */ var _babel_runtime_helpers_defineProperty__WEBPACK_IMPORTED_MODULE_0___default = /*#__PURE__*/__webpack_require__.n(_babel_runtime_helpers_defineProperty__WEBPACK_IMPORTED_MODULE_0__);
  31095. /* harmony import */ var underscore__WEBPACK_IMPORTED_MODULE_1__ = __webpack_require__(/*! underscore */ "./node_modules/underscore/underscore.js");
  31096. /* harmony import */ var underscore__WEBPACK_IMPORTED_MODULE_1___default = /*#__PURE__*/__webpack_require__.n(underscore__WEBPACK_IMPORTED_MODULE_1__);
  31097. /* harmony import */ var utils_mixins__WEBPACK_IMPORTED_MODULE_2__ = __webpack_require__(/*! utils/mixins */ "./src/utils/mixins.js");
  31098. /* harmony import */ var parser_model_ParserHtml__WEBPACK_IMPORTED_MODULE_3__ = __webpack_require__(/*! parser/model/ParserHtml */ "./src/parser/model/ParserHtml.js");
  31099. function ownKeys(object, enumerableOnly) { var keys = Object.keys(object); if (Object.getOwnPropertySymbols) { var symbols = Object.getOwnPropertySymbols(object); if (enumerableOnly) symbols = symbols.filter(function (sym) { return Object.getOwnPropertyDescriptor(object, sym).enumerable; }); keys.push.apply(keys, symbols); } return keys; }
  31100. function _objectSpread(target) { for (var i = 1; i < arguments.length; i++) { var source = arguments[i] != null ? arguments[i] : {}; if (i % 2) { ownKeys(source, true).forEach(function (key) { _babel_runtime_helpers_defineProperty__WEBPACK_IMPORTED_MODULE_0___default()(target, key, source[key]); }); } else if (Object.getOwnPropertyDescriptors) { Object.defineProperties(target, Object.getOwnPropertyDescriptors(source)); } else { ownKeys(source).forEach(function (key) { Object.defineProperty(target, key, Object.getOwnPropertyDescriptor(source, key)); }); } } return target; }
  31101. var parseStyle = Object(parser_model_ParserHtml__WEBPACK_IMPORTED_MODULE_3__["default"])().parseStyle;
  31102. /* harmony default export */ __webpack_exports__["default"] = ({
  31103. parseStyle: parseStyle,
  31104. /**
  31105. * To trigger the style change event on models I have to
  31106. * pass a new object instance
  31107. * @param {Object} prop
  31108. * @return {Object}
  31109. */
  31110. extendStyle: function extendStyle(prop) {
  31111. return _objectSpread({}, this.getStyle(), {}, prop);
  31112. },
  31113. /**
  31114. * Get style object
  31115. * @return {Object}
  31116. */
  31117. getStyle: function getStyle() {
  31118. var style = this.get('style') || {};
  31119. return _objectSpread({}, style);
  31120. },
  31121. /**
  31122. * Set new style object
  31123. * @param {Object|string} prop
  31124. * @param {Object} opts
  31125. * @return {Object} Applied properties
  31126. */
  31127. setStyle: function setStyle() {
  31128. var _this = this;
  31129. var prop = arguments.length > 0 && arguments[0] !== undefined ? arguments[0] : {};
  31130. var opts = arguments.length > 1 && arguments[1] !== undefined ? arguments[1] : {};
  31131. if (Object(underscore__WEBPACK_IMPORTED_MODULE_1__["isString"])(prop)) {
  31132. prop = parseStyle(prop);
  31133. }
  31134. var propOrig = this.getStyle();
  31135. var propNew = _objectSpread({}, prop);
  31136. this.set('style', propNew, opts);
  31137. var diff = Object(utils_mixins__WEBPACK_IMPORTED_MODULE_2__["shallowDiff"])(propOrig, propNew);
  31138. Object(underscore__WEBPACK_IMPORTED_MODULE_1__["keys"])(diff).forEach(function (pr) {
  31139. var em = _this.em;
  31140. _this.trigger("change:style:".concat(pr));
  31141. if (em) {
  31142. em.trigger("styleable:change", _this, pr);
  31143. em.trigger("styleable:change:".concat(pr), _this, pr);
  31144. }
  31145. });
  31146. return propNew;
  31147. },
  31148. /**
  31149. * Add style property
  31150. * @param {Object|string} prop
  31151. * @param {string} value
  31152. * @example
  31153. * this.addStyle({color: 'red'});
  31154. * this.addStyle('color', 'blue');
  31155. */
  31156. addStyle: function addStyle(prop) {
  31157. var value = arguments.length > 1 && arguments[1] !== undefined ? arguments[1] : '';
  31158. var opts = arguments.length > 2 && arguments[2] !== undefined ? arguments[2] : {};
  31159. if (typeof prop == 'string') {
  31160. prop = {
  31161. prop: value
  31162. };
  31163. } else {
  31164. opts = value || {};
  31165. }
  31166. prop = this.extendStyle(prop);
  31167. this.setStyle(prop, opts);
  31168. },
  31169. /**
  31170. * Remove style property
  31171. * @param {string} prop
  31172. */
  31173. removeStyle: function removeStyle(prop) {
  31174. var style = this.getStyle();
  31175. delete style[prop];
  31176. this.setStyle(style);
  31177. },
  31178. /**
  31179. * Returns string of style properties
  31180. * @param {Object} [opts={}] Options
  31181. * @return {String}
  31182. */
  31183. styleToString: function styleToString() {
  31184. var opts = arguments.length > 0 && arguments[0] !== undefined ? arguments[0] : {};
  31185. var result = [];
  31186. var style = this.getStyle();
  31187. for (var prop in style) {
  31188. var imp = opts.important;
  31189. var important = Object(underscore__WEBPACK_IMPORTED_MODULE_1__["isArray"])(imp) ? imp.indexOf(prop) >= 0 : imp;
  31190. var value = "".concat(style[prop]).concat(important ? ' !important' : '');
  31191. var propPrv = prop.substr(0, 2) == '__';
  31192. value && !propPrv && result.push("".concat(prop, ":").concat(value, ";"));
  31193. }
  31194. return result.join('');
  31195. },
  31196. getSelectors: function getSelectors() {
  31197. return this.get('selectors') || this.get('classes');
  31198. },
  31199. getSelectorsString: function getSelectorsString() {
  31200. return this.selectorsToString ? this.selectorsToString() : this.getSelectors().getFullString();
  31201. }
  31202. });
  31203. /***/ }),
  31204. /***/ "./src/domain_abstract/model/TypeableCollection.js":
  31205. /*!*********************************************************!*\
  31206. !*** ./src/domain_abstract/model/TypeableCollection.js ***!
  31207. \*********************************************************/
  31208. /*! exports provided: default */
  31209. /***/ (function(module, __webpack_exports__, __webpack_require__) {
  31210. "use strict";
  31211. __webpack_require__.r(__webpack_exports__);
  31212. /* harmony import */ var underscore__WEBPACK_IMPORTED_MODULE_0__ = __webpack_require__(/*! underscore */ "./node_modules/underscore/underscore.js");
  31213. /* harmony import */ var underscore__WEBPACK_IMPORTED_MODULE_0___default = /*#__PURE__*/__webpack_require__.n(underscore__WEBPACK_IMPORTED_MODULE_0__);
  31214. /* harmony import */ var backbone__WEBPACK_IMPORTED_MODULE_1__ = __webpack_require__(/*! backbone */ "./node_modules/backbone/backbone.js");
  31215. /* harmony import */ var backbone__WEBPACK_IMPORTED_MODULE_1___default = /*#__PURE__*/__webpack_require__.n(backbone__WEBPACK_IMPORTED_MODULE_1__);
  31216. var Model = backbone__WEBPACK_IMPORTED_MODULE_1___default.a.Model;
  31217. var View = backbone__WEBPACK_IMPORTED_MODULE_1___default.a.View;
  31218. /* harmony default export */ __webpack_exports__["default"] = ({
  31219. types: [],
  31220. initialize: function initialize(models, opts) {
  31221. var _this = this;
  31222. this.model = function () {
  31223. var attrs = arguments.length > 0 && arguments[0] !== undefined ? arguments[0] : {};
  31224. var options = arguments.length > 1 && arguments[1] !== undefined ? arguments[1] : {};
  31225. var Model, View, type;
  31226. if (attrs && attrs.type) {
  31227. var baseType = _this.getBaseType();
  31228. type = _this.getType(attrs.type);
  31229. Model = type ? type.model : baseType.model;
  31230. View = type ? type.view : baseType.view;
  31231. } else {
  31232. var typeFound = _this.recognizeType(attrs);
  31233. type = typeFound.type;
  31234. Model = type.model;
  31235. View = type.view;
  31236. attrs = typeFound.attributes;
  31237. }
  31238. var model = new Model(attrs, options);
  31239. model.typeView = View;
  31240. return model;
  31241. };
  31242. var init = this.init && this.init.bind(this);
  31243. init && init();
  31244. },
  31245. /**
  31246. * Recognize type by any value
  31247. * @param {mixed} value
  31248. * @return {Object} Found type
  31249. */
  31250. recognizeType: function recognizeType(value) {
  31251. var types = this.getTypes();
  31252. for (var i = 0; i < types.length; i++) {
  31253. var type = types[i];
  31254. var typeFound = type.isType(value);
  31255. typeFound = typeof typeFound == 'boolean' && typeFound ? {
  31256. type: type.id
  31257. } : typeFound;
  31258. if (typeFound) {
  31259. return {
  31260. type: type,
  31261. attributes: typeFound
  31262. };
  31263. }
  31264. } // If, for any reason, the type is not found it'll return the base one
  31265. return {
  31266. type: this.getBaseType(),
  31267. attributes: value
  31268. };
  31269. },
  31270. /**
  31271. * Returns the base type (last object in the stack)
  31272. * @return {Object}
  31273. */
  31274. getBaseType: function getBaseType() {
  31275. var types = this.getTypes();
  31276. return types[types.length - 1];
  31277. },
  31278. /**
  31279. * Get types
  31280. * @return {Array}
  31281. */
  31282. getTypes: function getTypes() {
  31283. return this.types;
  31284. },
  31285. /**
  31286. * Get type
  31287. * @param {string} id Type ID
  31288. * @return {Object} Type definition
  31289. */
  31290. getType: function getType(id) {
  31291. var types = this.getTypes();
  31292. for (var i = 0; i < types.length; i++) {
  31293. var type = types[i];
  31294. if (type.id === id) {
  31295. return type;
  31296. }
  31297. }
  31298. },
  31299. /**
  31300. * Add new type
  31301. * @param {string} id Type ID
  31302. * @param {Object} definition Definition of the type. Each definition contains
  31303. * `model` (business logic), `view` (presentation logic)
  31304. * and `isType` function which recognize the type of the
  31305. * passed entity
  31306. * addType('my-type', {
  31307. * model: {},
  31308. * view: {},
  31309. * isType: (value) => {},
  31310. * })
  31311. */
  31312. addType: function addType(id, definition) {
  31313. var type = this.getType(id);
  31314. var baseType = this.getBaseType();
  31315. var ModelInst = type ? type.model : baseType.model;
  31316. var ViewInst = type ? type.view : baseType.view;
  31317. var model = definition.model,
  31318. view = definition.view,
  31319. isType = definition.isType;
  31320. model = model instanceof Model || Object(underscore__WEBPACK_IMPORTED_MODULE_0__["isFunction"])(model) ? model : ModelInst.extend(model || {});
  31321. view = view instanceof View || Object(underscore__WEBPACK_IMPORTED_MODULE_0__["isFunction"])(view) ? view : ViewInst.extend(view || {});
  31322. if (type) {
  31323. type.model = model;
  31324. type.view = view;
  31325. type.isType = isType || type.isType;
  31326. } else {
  31327. definition.id = id;
  31328. definition.model = model;
  31329. definition.view = view;
  31330. definition.isType = isType || function (value) {
  31331. if (value && value.type == id) {
  31332. return true;
  31333. }
  31334. };
  31335. this.getTypes().unshift(definition);
  31336. }
  31337. }
  31338. });
  31339. /***/ }),
  31340. /***/ "./src/domain_abstract/ui/Input.js":
  31341. /*!*****************************************!*\
  31342. !*** ./src/domain_abstract/ui/Input.js ***!
  31343. \*****************************************/
  31344. /*! exports provided: default */
  31345. /***/ (function(module, __webpack_exports__, __webpack_require__) {
  31346. "use strict";
  31347. __webpack_require__.r(__webpack_exports__);
  31348. /* harmony import */ var backbone__WEBPACK_IMPORTED_MODULE_0__ = __webpack_require__(/*! backbone */ "./node_modules/backbone/backbone.js");
  31349. /* harmony import */ var backbone__WEBPACK_IMPORTED_MODULE_0___default = /*#__PURE__*/__webpack_require__.n(backbone__WEBPACK_IMPORTED_MODULE_0__);
  31350. var $ = backbone__WEBPACK_IMPORTED_MODULE_0___default.a.$;
  31351. /* harmony default export */ __webpack_exports__["default"] = (backbone__WEBPACK_IMPORTED_MODULE_0___default.a.View.extend({
  31352. events: {
  31353. change: 'handleChange'
  31354. },
  31355. template: function template() {
  31356. return "<span class=\"".concat(this.holderClass(), "\"></span>");
  31357. },
  31358. inputClass: function inputClass() {
  31359. return "".concat(this.ppfx, "field");
  31360. },
  31361. holderClass: function holderClass() {
  31362. return "".concat(this.ppfx, "input-holder");
  31363. },
  31364. initialize: function initialize() {
  31365. var opts = arguments.length > 0 && arguments[0] !== undefined ? arguments[0] : {};
  31366. var ppfx = opts.ppfx || '';
  31367. this.opts = opts;
  31368. this.ppfx = ppfx;
  31369. this.em = opts.target || {};
  31370. this.listenTo(this.model, 'change:value', this.handleModelChange);
  31371. },
  31372. /**
  31373. * Fired when the element of the property is updated
  31374. */
  31375. elementUpdated: function elementUpdated() {
  31376. this.model.trigger('el:change');
  31377. },
  31378. /**
  31379. * Set value to the input element
  31380. * @param {string} value
  31381. */
  31382. setValue: function setValue(value) {
  31383. var model = this.model;
  31384. var val = value || model.get('defaults');
  31385. var input = this.getInputEl();
  31386. input && (input.value = val);
  31387. },
  31388. /**
  31389. * Updates the view when the model is changed
  31390. * */
  31391. handleModelChange: function handleModelChange(model, value, opts) {
  31392. this.setValue(value, opts);
  31393. },
  31394. /**
  31395. * Handled when the view is changed
  31396. */
  31397. handleChange: function handleChange(e) {
  31398. e.stopPropagation();
  31399. var value = this.getInputEl().value;
  31400. this.model.set({
  31401. value: value
  31402. }, {
  31403. fromInput: 1
  31404. });
  31405. this.elementUpdated();
  31406. },
  31407. /**
  31408. * Get the input element
  31409. * @return {HTMLElement}
  31410. */
  31411. getInputEl: function getInputEl() {
  31412. if (!this.inputEl) {
  31413. var model = this.model;
  31414. var plh = model.get('placeholder') || model.get('defaults') || '';
  31415. this.inputEl = $("<input type=\"text\" placeholder=\"".concat(plh, "\">"));
  31416. }
  31417. return this.inputEl.get(0);
  31418. },
  31419. render: function render() {
  31420. this.inputEl = null;
  31421. var el = this.$el;
  31422. el.addClass(this.inputClass());
  31423. el.html(this.template());
  31424. el.find(".".concat(this.holderClass())).append(this.getInputEl());
  31425. return this;
  31426. }
  31427. }));
  31428. /***/ }),
  31429. /***/ "./src/domain_abstract/ui/InputColor.js":
  31430. /*!**********************************************!*\
  31431. !*** ./src/domain_abstract/ui/InputColor.js ***!
  31432. \**********************************************/
  31433. /*! exports provided: default */
  31434. /***/ (function(module, __webpack_exports__, __webpack_require__) {
  31435. "use strict";
  31436. __webpack_require__.r(__webpack_exports__);
  31437. /* harmony import */ var _babel_runtime_helpers_defineProperty__WEBPACK_IMPORTED_MODULE_0__ = __webpack_require__(/*! @babel/runtime/helpers/defineProperty */ "./node_modules/@babel/runtime/helpers/defineProperty.js");
  31438. /* harmony import */ var _babel_runtime_helpers_defineProperty__WEBPACK_IMPORTED_MODULE_0___default = /*#__PURE__*/__webpack_require__.n(_babel_runtime_helpers_defineProperty__WEBPACK_IMPORTED_MODULE_0__);
  31439. /* harmony import */ var backbone__WEBPACK_IMPORTED_MODULE_1__ = __webpack_require__(/*! backbone */ "./node_modules/backbone/backbone.js");
  31440. /* harmony import */ var backbone__WEBPACK_IMPORTED_MODULE_1___default = /*#__PURE__*/__webpack_require__.n(backbone__WEBPACK_IMPORTED_MODULE_1__);
  31441. /* harmony import */ var underscore__WEBPACK_IMPORTED_MODULE_2__ = __webpack_require__(/*! underscore */ "./node_modules/underscore/underscore.js");
  31442. /* harmony import */ var underscore__WEBPACK_IMPORTED_MODULE_2___default = /*#__PURE__*/__webpack_require__.n(underscore__WEBPACK_IMPORTED_MODULE_2__);
  31443. /* harmony import */ var utils_ColorPicker__WEBPACK_IMPORTED_MODULE_3__ = __webpack_require__(/*! utils/ColorPicker */ "./src/utils/ColorPicker.js");
  31444. /* harmony import */ var _Input__WEBPACK_IMPORTED_MODULE_4__ = __webpack_require__(/*! ./Input */ "./src/domain_abstract/ui/Input.js");
  31445. function ownKeys(object, enumerableOnly) { var keys = Object.keys(object); if (Object.getOwnPropertySymbols) { var symbols = Object.getOwnPropertySymbols(object); if (enumerableOnly) symbols = symbols.filter(function (sym) { return Object.getOwnPropertyDescriptor(object, sym).enumerable; }); keys.push.apply(keys, symbols); } return keys; }
  31446. function _objectSpread(target) { for (var i = 1; i < arguments.length; i++) { var source = arguments[i] != null ? arguments[i] : {}; if (i % 2) { ownKeys(source, true).forEach(function (key) { _babel_runtime_helpers_defineProperty__WEBPACK_IMPORTED_MODULE_0___default()(target, key, source[key]); }); } else if (Object.getOwnPropertyDescriptors) { Object.defineProperties(target, Object.getOwnPropertyDescriptors(source)); } else { ownKeys(source).forEach(function (key) { Object.defineProperty(target, key, Object.getOwnPropertyDescriptor(source, key)); }); } } return target; }
  31447. var $ = backbone__WEBPACK_IMPORTED_MODULE_1___default.a.$;
  31448. Object(utils_ColorPicker__WEBPACK_IMPORTED_MODULE_3__["default"])($);
  31449. /* harmony default export */ __webpack_exports__["default"] = (_Input__WEBPACK_IMPORTED_MODULE_4__["default"].extend({
  31450. template: function template() {
  31451. var ppfx = this.ppfx;
  31452. return "\n <div class=\"".concat(this.holderClass(), "\"></div>\n <div class=\"").concat(ppfx, "field-colorp\">\n <div class=\"").concat(ppfx, "field-colorp-c\" data-colorp-c>\n <div class=\"").concat(ppfx, "checker-bg\"></div>\n </div>\n </div>\n ");
  31453. },
  31454. inputClass: function inputClass() {
  31455. var ppfx = this.ppfx;
  31456. return "".concat(ppfx, "field ").concat(ppfx, "field-color");
  31457. },
  31458. holderClass: function holderClass() {
  31459. return "".concat(this.ppfx, "input-holder");
  31460. },
  31461. /**
  31462. * Set value to the model
  31463. * @param {string} val
  31464. * @param {Object} opts
  31465. */
  31466. setValue: function setValue(val) {
  31467. var opts = arguments.length > 1 && arguments[1] !== undefined ? arguments[1] : {};
  31468. var model = this.model;
  31469. var def = model.get('defaults');
  31470. var value = !Object(underscore__WEBPACK_IMPORTED_MODULE_2__["isUndefined"])(val) ? val : !Object(underscore__WEBPACK_IMPORTED_MODULE_2__["isUndefined"])(def) ? def : '';
  31471. var inputEl = this.getInputEl();
  31472. var colorEl = this.getColorEl();
  31473. var valueClr = value != 'none' ? value : '';
  31474. inputEl.value = value;
  31475. colorEl.get(0).style.backgroundColor = valueClr; // This prevents from adding multiple thumbs in spectrum
  31476. if (opts.fromTarget || opts.fromInput && !opts.avoidStore) {
  31477. colorEl.spectrum('set', valueClr);
  31478. this.noneColor = value == 'none';
  31479. }
  31480. },
  31481. /**
  31482. * Get the color input element
  31483. * @return {HTMLElement}
  31484. */
  31485. getColorEl: function getColorEl() {
  31486. if (!this.colorEl) {
  31487. var em = this.em;
  31488. var self = this;
  31489. var ppfx = this.ppfx;
  31490. var model = this.model;
  31491. var colorEl = $("<div class=\"".concat(this.ppfx, "field-color-picker\"></div>"));
  31492. var cpStyle = colorEl.get(0).style;
  31493. var elToAppend = em && em.config ? em.config.el : '';
  31494. var colorPickerConfig = em && em.getConfig && em.getConfig('colorPicker') || {};
  31495. var getColor = function getColor(color) {
  31496. var cl = color.getAlpha() == 1 ? color.toHexString() : color.toRgbString();
  31497. return cl.replace(/ /g, '');
  31498. };
  31499. var changed = 0;
  31500. var previousColor;
  31501. this.$el.find("[data-colorp-c]").append(colorEl);
  31502. colorEl.spectrum(_objectSpread({
  31503. containerClassName: "".concat(ppfx, "one-bg ").concat(ppfx, "two-color"),
  31504. appendTo: elToAppend || 'body',
  31505. maxSelectionSize: 8,
  31506. showPalette: true,
  31507. showAlpha: true,
  31508. chooseText: 'Ok',
  31509. cancelText: '⨯',
  31510. palette: []
  31511. }, colorPickerConfig, {
  31512. move: function move(color) {
  31513. var cl = getColor(color);
  31514. cpStyle.backgroundColor = cl;
  31515. model.setValueFromInput(cl, 0);
  31516. },
  31517. change: function change(color) {
  31518. changed = 1;
  31519. var cl = getColor(color);
  31520. cpStyle.backgroundColor = cl;
  31521. model.setValueFromInput(0, 0); // for UndoManager
  31522. model.setValueFromInput(cl);
  31523. self.noneColor = 0;
  31524. },
  31525. show: function show(color) {
  31526. changed = 0;
  31527. previousColor = getColor(color);
  31528. },
  31529. hide: function hide(color) {
  31530. if (!changed && previousColor) {
  31531. if (self.noneColor) {
  31532. previousColor = '';
  31533. }
  31534. cpStyle.backgroundColor = previousColor;
  31535. colorEl.spectrum('set', previousColor);
  31536. model.setValueFromInput(previousColor, 0);
  31537. }
  31538. }
  31539. }));
  31540. em && em.on && em.on('component:selected', function () {
  31541. changed = 1;
  31542. colorEl.spectrum('hide');
  31543. });
  31544. this.colorEl = colorEl;
  31545. }
  31546. return this.colorEl;
  31547. },
  31548. render: function render() {
  31549. _Input__WEBPACK_IMPORTED_MODULE_4__["default"].prototype.render.call(this); // This will make the color input available on render
  31550. this.getColorEl();
  31551. return this;
  31552. }
  31553. }));
  31554. /***/ }),
  31555. /***/ "./src/domain_abstract/ui/InputNumber.js":
  31556. /*!***********************************************!*\
  31557. !*** ./src/domain_abstract/ui/InputNumber.js ***!
  31558. \***********************************************/
  31559. /*! exports provided: default */
  31560. /***/ (function(module, __webpack_exports__, __webpack_require__) {
  31561. "use strict";
  31562. __webpack_require__.r(__webpack_exports__);
  31563. /* harmony import */ var backbone__WEBPACK_IMPORTED_MODULE_0__ = __webpack_require__(/*! backbone */ "./node_modules/backbone/backbone.js");
  31564. /* harmony import */ var backbone__WEBPACK_IMPORTED_MODULE_0___default = /*#__PURE__*/__webpack_require__.n(backbone__WEBPACK_IMPORTED_MODULE_0__);
  31565. /* harmony import */ var underscore__WEBPACK_IMPORTED_MODULE_1__ = __webpack_require__(/*! underscore */ "./node_modules/underscore/underscore.js");
  31566. /* harmony import */ var underscore__WEBPACK_IMPORTED_MODULE_1___default = /*#__PURE__*/__webpack_require__.n(underscore__WEBPACK_IMPORTED_MODULE_1__);
  31567. /* harmony import */ var utils_mixins__WEBPACK_IMPORTED_MODULE_2__ = __webpack_require__(/*! utils/mixins */ "./src/utils/mixins.js");
  31568. /* harmony import */ var _Input__WEBPACK_IMPORTED_MODULE_3__ = __webpack_require__(/*! ./Input */ "./src/domain_abstract/ui/Input.js");
  31569. var $ = backbone__WEBPACK_IMPORTED_MODULE_0___default.a.$;
  31570. /* harmony default export */ __webpack_exports__["default"] = (_Input__WEBPACK_IMPORTED_MODULE_3__["default"].extend({
  31571. events: {
  31572. 'change input': 'handleChange',
  31573. 'change select': 'handleUnitChange',
  31574. 'click [data-arrow-up]': 'upArrowClick',
  31575. 'click [data-arrow-down]': 'downArrowClick',
  31576. 'mousedown [data-arrows]': 'downIncrement'
  31577. },
  31578. template: function template() {
  31579. var ppfx = this.ppfx;
  31580. return "\n <span class=\"".concat(ppfx, "input-holder\"></span>\n <span class=\"").concat(ppfx, "field-units\"></span>\n <div class=\"").concat(ppfx, "field-arrows\" data-arrows>\n <div class=\"").concat(ppfx, "field-arrow-u\" data-arrow-up></div>\n <div class=\"").concat(ppfx, "field-arrow-d\" data-arrow-down></div>\n </div>\n ");
  31581. },
  31582. inputClass: function inputClass() {
  31583. var ppfx = this.ppfx;
  31584. return this.opts.contClass || "".concat(ppfx, "field ").concat(ppfx, "field-integer");
  31585. },
  31586. initialize: function initialize() {
  31587. var opts = arguments.length > 0 && arguments[0] !== undefined ? arguments[0] : {};
  31588. _Input__WEBPACK_IMPORTED_MODULE_3__["default"].prototype.initialize.apply(this, arguments);
  31589. Object(underscore__WEBPACK_IMPORTED_MODULE_1__["bindAll"])(this, 'moveIncrement', 'upIncrement');
  31590. this.doc = document;
  31591. this.listenTo(this.model, 'change:unit', this.handleModelChange);
  31592. },
  31593. /**
  31594. * Set value to the model
  31595. * @param {string} value
  31596. * @param {Object} opts
  31597. */
  31598. setValue: function setValue(value, opts) {
  31599. var opt = opts || {};
  31600. var valid = this.validateInputValue(value, {
  31601. deepCheck: 1
  31602. });
  31603. var validObj = {
  31604. value: valid.value
  31605. }; // If found some unit value
  31606. if (valid.unit || valid.force) {
  31607. validObj.unit = valid.unit;
  31608. }
  31609. this.model.set(validObj, opt); // Generally I get silent when I need to reflect data to view without
  31610. // reupdating the target
  31611. if (opt.silent) {
  31612. this.handleModelChange();
  31613. }
  31614. },
  31615. /**
  31616. * Handled when the view is changed
  31617. */
  31618. handleChange: function handleChange(e) {
  31619. e.stopPropagation();
  31620. this.setValue(this.getInputEl().value);
  31621. this.elementUpdated();
  31622. },
  31623. /**
  31624. * Handled when the view is changed
  31625. */
  31626. handleUnitChange: function handleUnitChange(e) {
  31627. e.stopPropagation();
  31628. var value = this.getUnitEl().value;
  31629. this.model.set('unit', value);
  31630. this.elementUpdated();
  31631. },
  31632. /**
  31633. * Fired when the element of the property is updated
  31634. */
  31635. elementUpdated: function elementUpdated() {
  31636. this.model.trigger('el:change');
  31637. },
  31638. /**
  31639. * Updates the view when the model is changed
  31640. * */
  31641. handleModelChange: function handleModelChange() {
  31642. var model = this.model;
  31643. this.getInputEl().value = model.get('value');
  31644. var unitEl = this.getUnitEl();
  31645. unitEl && (unitEl.value = model.get('unit') || '');
  31646. },
  31647. /**
  31648. * Get the unit element
  31649. * @return {HTMLElement}
  31650. */
  31651. getUnitEl: function getUnitEl() {
  31652. if (!this.unitEl) {
  31653. var model = this.model;
  31654. var units = model.get('units') || [];
  31655. if (units.length) {
  31656. var options = [];
  31657. units.forEach(function (unit) {
  31658. var selected = unit == model.get('unit') ? 'selected' : '';
  31659. options.push("<option ".concat(selected, ">").concat(unit, "</option>"));
  31660. });
  31661. var temp = document.createElement('div');
  31662. temp.innerHTML = "<select class=\"".concat(this.ppfx, "input-unit\">").concat(options.join(''), "</select>");
  31663. this.unitEl = temp.firstChild;
  31664. }
  31665. }
  31666. return this.unitEl;
  31667. },
  31668. /**
  31669. * Invoked when the up arrow is clicked
  31670. * */
  31671. upArrowClick: function upArrowClick() {
  31672. var model = this.model;
  31673. var step = model.get('step');
  31674. var value = parseInt(model.get('value'), 10);
  31675. value = this.normalizeValue(value + step);
  31676. var valid = this.validateInputValue(value);
  31677. model.set('value', valid.value);
  31678. this.elementUpdated();
  31679. },
  31680. /**
  31681. * Invoked when the down arrow is clicked
  31682. * */
  31683. downArrowClick: function downArrowClick() {
  31684. var model = this.model;
  31685. var step = model.get('step');
  31686. var value = parseInt(model.get('value'), 10);
  31687. var val = this.normalizeValue(value - step);
  31688. var valid = this.validateInputValue(val);
  31689. model.set('value', valid.value);
  31690. this.elementUpdated();
  31691. },
  31692. /**
  31693. * Change easily integer input value with click&drag method
  31694. * @param Event
  31695. *
  31696. * @return void
  31697. * */
  31698. downIncrement: function downIncrement(e) {
  31699. e.preventDefault();
  31700. this.moved = 0;
  31701. var value = this.model.get('value');
  31702. value = this.normalizeValue(value);
  31703. this.current = {
  31704. y: e.pageY,
  31705. val: value
  31706. };
  31707. Object(utils_mixins__WEBPACK_IMPORTED_MODULE_2__["on"])(this.doc, 'mousemove', this.moveIncrement);
  31708. Object(utils_mixins__WEBPACK_IMPORTED_MODULE_2__["on"])(this.doc, 'mouseup', this.upIncrement);
  31709. },
  31710. /** While the increment is clicked, moving the mouse will update input value
  31711. * @param Object
  31712. *
  31713. * @return bool
  31714. * */
  31715. moveIncrement: function moveIncrement(ev) {
  31716. this.moved = 1;
  31717. var model = this.model;
  31718. var step = model.get('step');
  31719. var data = this.current;
  31720. var pos = this.normalizeValue(data.val + (data.y - ev.pageY) * step);
  31721. this.prValue = this.validateInputValue(pos).value;
  31722. model.set('value', this.prValue, {
  31723. avoidStore: 1
  31724. });
  31725. return false;
  31726. },
  31727. /**
  31728. * Stop moveIncrement method
  31729. * */
  31730. upIncrement: function upIncrement() {
  31731. var model = this.model;
  31732. var step = model.get('step');
  31733. Object(utils_mixins__WEBPACK_IMPORTED_MODULE_2__["off"])(this.doc, 'mouseup', this.upIncrement);
  31734. Object(utils_mixins__WEBPACK_IMPORTED_MODULE_2__["off"])(this.doc, 'mousemove', this.moveIncrement);
  31735. if (this.prValue && this.moved) {
  31736. var value = this.prValue - step;
  31737. model.set('value', value, {
  31738. avoidStore: 1
  31739. }).set('value', value + step);
  31740. this.elementUpdated();
  31741. }
  31742. },
  31743. normalizeValue: function normalizeValue(value) {
  31744. var defValue = arguments.length > 1 && arguments[1] !== undefined ? arguments[1] : 0;
  31745. var model = this.model;
  31746. var step = model.get('step');
  31747. var stepDecimals = 0;
  31748. if (isNaN(value)) {
  31749. return defValue;
  31750. }
  31751. value = parseFloat(value);
  31752. if (Math.floor(value) !== value) {
  31753. var side = step.toString().split('.')[1];
  31754. stepDecimals = side ? side.length : 0;
  31755. }
  31756. return stepDecimals ? parseFloat(value.toFixed(stepDecimals)) : value;
  31757. },
  31758. /**
  31759. * Validate input value
  31760. * @param {String} value Raw value
  31761. * @param {Object} opts Options
  31762. * @return {Object} Validated string
  31763. */
  31764. validateInputValue: function validateInputValue(value, opts) {
  31765. var force = 0;
  31766. var opt = opts || {};
  31767. var model = this.model;
  31768. var defValue = ''; //model.get('defaults');
  31769. var val = !Object(underscore__WEBPACK_IMPORTED_MODULE_1__["isUndefined"])(value) ? value : defValue;
  31770. var units = model.get('units') || [];
  31771. var unit = model.get('unit') || units.length && units[0] || '';
  31772. var max = model.get('max');
  31773. var min = model.get('min');
  31774. if (opt.deepCheck) {
  31775. var fixed = model.get('fixedValues') || [];
  31776. if (val) {
  31777. // If the value is one of the fixed values I leave it as it is
  31778. var regFixed = new RegExp('^' + fixed.join('|'), 'g');
  31779. if (fixed.length && regFixed.test(val)) {
  31780. val = val.match(regFixed)[0];
  31781. unit = '';
  31782. force = 1;
  31783. } else {
  31784. var valCopy = val + '';
  31785. val += ''; // Make it suitable for replace
  31786. val = parseFloat(val.replace(',', '.'));
  31787. val = !isNaN(val) ? val : defValue;
  31788. var uN = valCopy.replace(val, ''); // Check if exists as unit
  31789. if (Object(underscore__WEBPACK_IMPORTED_MODULE_1__["indexOf"])(units, uN) >= 0) unit = uN;
  31790. }
  31791. }
  31792. }
  31793. if (!Object(underscore__WEBPACK_IMPORTED_MODULE_1__["isUndefined"])(max) && max !== '') val = val > max ? max : val;
  31794. if (!Object(underscore__WEBPACK_IMPORTED_MODULE_1__["isUndefined"])(min) && min !== '') val = val < min ? min : val;
  31795. return {
  31796. force: force,
  31797. value: val,
  31798. unit: unit
  31799. };
  31800. },
  31801. render: function render() {
  31802. _Input__WEBPACK_IMPORTED_MODULE_3__["default"].prototype.render.call(this);
  31803. this.unitEl = null;
  31804. var unit = this.getUnitEl();
  31805. unit && this.$el.find(".".concat(this.ppfx, "field-units")).get(0).appendChild(unit);
  31806. return this;
  31807. }
  31808. }));
  31809. /***/ }),
  31810. /***/ "./src/domain_abstract/view/DomainViews.js":
  31811. /*!*************************************************!*\
  31812. !*** ./src/domain_abstract/view/DomainViews.js ***!
  31813. \*************************************************/
  31814. /*! exports provided: default */
  31815. /***/ (function(module, __webpack_exports__, __webpack_require__) {
  31816. "use strict";
  31817. __webpack_require__.r(__webpack_exports__);
  31818. /* harmony import */ var underscore__WEBPACK_IMPORTED_MODULE_0__ = __webpack_require__(/*! underscore */ "./node_modules/underscore/underscore.js");
  31819. /* harmony import */ var underscore__WEBPACK_IMPORTED_MODULE_0___default = /*#__PURE__*/__webpack_require__.n(underscore__WEBPACK_IMPORTED_MODULE_0__);
  31820. /* harmony import */ var backbone__WEBPACK_IMPORTED_MODULE_1__ = __webpack_require__(/*! backbone */ "./node_modules/backbone/backbone.js");
  31821. /* harmony import */ var backbone__WEBPACK_IMPORTED_MODULE_1___default = /*#__PURE__*/__webpack_require__.n(backbone__WEBPACK_IMPORTED_MODULE_1__);
  31822. /* harmony default export */ __webpack_exports__["default"] = (backbone__WEBPACK_IMPORTED_MODULE_1___default.a.View.extend({
  31823. // Default view
  31824. itemView: '',
  31825. // Defines the View per type
  31826. itemsView: '',
  31827. itemType: 'type',
  31828. autoAdd: 0,
  31829. initialize: function initialize() {
  31830. var opts = arguments.length > 0 && arguments[0] !== undefined ? arguments[0] : {};
  31831. var config = arguments.length > 1 ? arguments[1] : undefined;
  31832. this.config = config || opts.config || {};
  31833. this.autoAdd && this.listenTo(this.collection, 'add', this.addTo);
  31834. this.items = [];
  31835. this.init();
  31836. },
  31837. init: function init() {},
  31838. /**
  31839. * Add new model to the collection
  31840. * @param {Model} model
  31841. * @private
  31842. * */
  31843. addTo: function addTo(model) {
  31844. this.add(model);
  31845. },
  31846. itemViewNotFound: function itemViewNotFound(type) {
  31847. var config = this.config,
  31848. ns = this.ns;
  31849. var em = config.em;
  31850. var warn = "".concat(ns ? "[".concat(ns, "]: ") : '', "'").concat(type, "' type not found");
  31851. em && em.logWarning(warn);
  31852. },
  31853. /**
  31854. * Render new model inside the view
  31855. * @param {Model} model
  31856. * @param {Object} fragment Fragment collection
  31857. * @private
  31858. * */
  31859. add: function add(model, fragment) {
  31860. var config = this.config,
  31861. reuseView = this.reuseView,
  31862. items = this.items,
  31863. _this$itemsView = this.itemsView,
  31864. itemsView = _this$itemsView === void 0 ? {} : _this$itemsView;
  31865. var inputTypes = ['button', 'checkbox', 'color', 'date', 'datetime-local', 'email', 'file', 'hidden', 'image', 'month', 'number', 'password', 'radio', 'range', 'reset', 'search', 'submit', 'tel', 'text', 'time', 'url', 'week'];
  31866. var frag = fragment || null;
  31867. var itemView = this.itemView;
  31868. var typeField = model.get(this.itemType);
  31869. var view;
  31870. if (itemsView[typeField]) {
  31871. itemView = itemsView[typeField];
  31872. } else if (typeField && !itemsView[typeField] && !Object(underscore__WEBPACK_IMPORTED_MODULE_0__["includes"])(inputTypes, typeField)) {
  31873. this.itemViewNotFound(typeField);
  31874. }
  31875. if (model.view && reuseView) {
  31876. view = model.view;
  31877. } else {
  31878. view = new itemView({
  31879. model: model,
  31880. config: config
  31881. }, config);
  31882. }
  31883. items && items.push(view);
  31884. var rendered = view.render().el;
  31885. if (frag) frag.appendChild(rendered);else this.$el.append(rendered);
  31886. },
  31887. render: function render() {
  31888. var frag = document.createDocumentFragment();
  31889. this.clearItems();
  31890. this.$el.empty();
  31891. if (this.collection.length) this.collection.each(function (model) {
  31892. this.add(model, frag);
  31893. }, this);
  31894. this.$el.append(frag);
  31895. this.onRender();
  31896. return this;
  31897. },
  31898. onRender: function onRender() {},
  31899. remove: function remove() {
  31900. this.clearItems();
  31901. backbone__WEBPACK_IMPORTED_MODULE_1___default.a.View.prototype.remove.apply(this, arguments);
  31902. },
  31903. clearItems: function clearItems() {
  31904. var items = this.items || []; // TODO Traits do not update the target anymore
  31905. // items.forEach(item => item.remove());
  31906. // this.items = [];
  31907. }
  31908. }));
  31909. /***/ }),
  31910. /***/ "./src/editor/config/config.js":
  31911. /*!*************************************!*\
  31912. !*** ./src/editor/config/config.js ***!
  31913. \*************************************/
  31914. /*! exports provided: default */
  31915. /***/ (function(module, __webpack_exports__, __webpack_require__) {
  31916. "use strict";
  31917. __webpack_require__.r(__webpack_exports__);
  31918. /* harmony default export */ __webpack_exports__["default"] = ({
  31919. // Style prefix
  31920. stylePrefix: 'gjs-',
  31921. // HTML string or object of components
  31922. components: '',
  31923. // CSS string or object of rules
  31924. style: '',
  31925. // If true, will fetch HTML and CSS from selected container
  31926. fromElement: 0,
  31927. // Show an alert before unload the page with unsaved changes
  31928. noticeOnUnload: true,
  31929. // Show paddings and margins
  31930. showOffsets: false,
  31931. // Show paddings and margins on selected component
  31932. showOffsetsSelected: false,
  31933. // On creation of a new Component (via object), if the 'style' attribute is not
  31934. // empty, all those roles will be moved in its new class
  31935. forceClass: true,
  31936. // Height for the editor container
  31937. height: '900px',
  31938. // Width for the editor container
  31939. width: '100%',
  31940. // Type of logs to print with the logger (by default is used the devtool console).
  31941. // Available by default: debug, info, warning, error
  31942. // You can use `false` to disable all of them or `true` to print all of them
  31943. log: ['warning', 'error'],
  31944. // By default Grapes injects base CSS into the canvas. For example, it sets body margin to 0
  31945. // and sets a default background color of white. This CSS is desired in most cases.
  31946. // use this property if you wish to overwrite the base CSS to your own CSS. This is most
  31947. // useful if for example your template is not based off a document with 0 as body margin.
  31948. baseCss: "\n * {\n box-sizing: border-box;\n }\n html, body, [data-gjs-type=wrapper] {\n min-height: 100%;\n }\n body {\n margin: 0;\n height: 100%;\n background-color: #fff\n }\n [data-gjs-type=wrapper] {\n overflow: auto;\n overflow-x: hidden;\n }\n\n * ::-webkit-scrollbar-track {\n background: rgba(0, 0, 0, 0.1)\n }\n\n * ::-webkit-scrollbar-thumb {\n background: rgba(255, 255, 255, 0.2)\n }\n\n * ::-webkit-scrollbar {\n width: 10px\n }\n ",
  31949. // CSS that could only be seen (for instance, inside the code viewer)
  31950. protectedCss: '* { box-sizing: border-box; } body {margin: 0;}',
  31951. // CSS for the iframe which containing the canvas, useful if you need to custom something inside
  31952. // (eg. the style of the selected component)
  31953. canvasCss: '',
  31954. // Default command
  31955. defaultCommand: 'select-comp',
  31956. // Show a toolbar when the component is selected
  31957. showToolbar: 1,
  31958. // Allow script tag importing
  31959. allowScripts: 0,
  31960. // If true render a select of available devices
  31961. showDevices: 1,
  31962. // When enabled, on device change media rules won't be created
  31963. devicePreviewMode: 0,
  31964. // THe condition to use for media queries, eg. 'max-width'
  31965. // Comes handy for mobile-first cases
  31966. mediaCondition: 'max-width',
  31967. // Starting tag for variable inside scripts in Components
  31968. tagVarStart: '{[ ',
  31969. // Ending tag for variable inside scripts in Components
  31970. tagVarEnd: ' ]}',
  31971. // When false, removes empty text nodes when parsed, unless they contain a space
  31972. keepEmptyTextNodes: 0,
  31973. // Return JS of components inside HTML from 'editor.getHtml()'
  31974. jsInHtml: true,
  31975. // Enable native HTML5 drag and drop
  31976. nativeDnD: 1,
  31977. // Enable multiple selection
  31978. multipleSelection: 1,
  31979. // Show the wrapper component in the final code, eg. in editor.getHtml()
  31980. exportWrapper: 0,
  31981. // The wrapper, if visible, will be shown as a `<body>`
  31982. wrapperIsBody: 1,
  31983. // Usually when you update the `style` of the component this changes the
  31984. // element's `style` attribute. Unfortunately, inline styling doesn't allow
  31985. // use of media queries (@media) or even pseudo selectors (eg. :hover).
  31986. // When `avoidInlineStyle` is true all styles are inserted inside the css rule
  31987. // @deprecated Don't use this option, we don't support inline styling anymore
  31988. avoidInlineStyle: 1,
  31989. // Avoid default properties from storable JSON data, like `components` and `styles`.
  31990. // With this option enabled your data will be smaller (usefull if need to
  31991. // save some storage space)
  31992. avoidDefaults: 1,
  31993. // (experimental)
  31994. // The structure of components is always on the screen but it's not the same
  31995. // for style rules. When you delete a component you might leave a lot of styles
  31996. // which will never be used again, therefore they might be removed.
  31997. // With this option set to true, styles not used from the CSS generator (so in
  31998. // any case where `CssGenerator.build` is used) will be removed automatically.
  31999. // But be careful, not always leaving the style not used mean you wouldn't
  32000. // use it later, but this option comes really handy when deal with big templates.
  32001. clearStyles: 0,
  32002. // Specify the global drag mode of components. By default, components are moved
  32003. // following the HTML flow. Two other options are available:
  32004. // 'absolute' - Move components absolutely (design tools way)
  32005. // 'translate' - Use translate CSS from transform property
  32006. // To get more about this feature read: https://github.com/artf/grapesjs/issues/1936
  32007. dragMode: 0,
  32008. // Import asynchronously CSS to use as icons
  32009. cssIcons: 'https://cdnjs.cloudflare.com/ajax/libs/font-awesome/4.7.0/css/font-awesome.min.css',
  32010. // Dom element
  32011. el: '',
  32012. // Configurations for I18n
  32013. i18n: {},
  32014. // Configurations for Undo Manager
  32015. undoManager: {},
  32016. //Configurations for Asset Manager
  32017. assetManager: {},
  32018. //Configurations for Canvas
  32019. canvas: {},
  32020. //Configurations for Layers
  32021. layers: {},
  32022. //Configurations for Storage Manager
  32023. storageManager: {},
  32024. //Configurations for Rich Text Editor
  32025. richTextEditor: {},
  32026. //Configurations for DomComponents
  32027. domComponents: {},
  32028. //Configurations for Modal Dialog
  32029. modal: {},
  32030. //Configurations for Code Manager
  32031. codeManager: {},
  32032. //Configurations for Panels
  32033. panels: {},
  32034. //Configurations for Commands
  32035. commands: {},
  32036. //Configurations for Css Composer
  32037. cssComposer: {},
  32038. //Configurations for Selector Manager
  32039. selectorManager: {},
  32040. //Configurations for Device Manager
  32041. deviceManager: {
  32042. devices: [{
  32043. id: 'desktop',
  32044. name: 'Desktop',
  32045. width: ''
  32046. }, {
  32047. id: 'tablet',
  32048. name: 'Tablet',
  32049. width: '768px',
  32050. widthMedia: '992px'
  32051. }, {
  32052. id: 'mobileLandscape',
  32053. name: 'Mobile landscape',
  32054. width: '568px',
  32055. widthMedia: '768px'
  32056. }, {
  32057. id: 'mobilePortrait',
  32058. name: 'Mobile portrait',
  32059. width: '320px',
  32060. widthMedia: '480px'
  32061. }]
  32062. },
  32063. //Configurations for Style Manager
  32064. styleManager: {
  32065. sectors: [{
  32066. name: 'General',
  32067. open: false,
  32068. buildProps: ['float', 'display', 'position', 'top', 'right', 'left', 'bottom']
  32069. }, {
  32070. name: 'Flex',
  32071. open: false,
  32072. buildProps: ['flex-direction', 'flex-wrap', 'justify-content', 'align-items', 'align-content', 'order', 'flex-basis', 'flex-grow', 'flex-shrink', 'align-self']
  32073. }, {
  32074. name: 'Dimension',
  32075. open: false,
  32076. buildProps: ['width', 'height', 'max-width', 'min-height', 'margin', 'padding']
  32077. }, {
  32078. name: 'Typography',
  32079. open: false,
  32080. buildProps: ['font-family', 'font-size', 'font-weight', 'letter-spacing', 'color', 'line-height', 'text-align', 'text-shadow'],
  32081. properties: [{
  32082. property: 'text-align',
  32083. list: [{
  32084. value: 'left',
  32085. className: 'fa fa-align-left'
  32086. }, {
  32087. value: 'center',
  32088. className: 'fa fa-align-center'
  32089. }, {
  32090. value: 'right',
  32091. className: 'fa fa-align-right'
  32092. }, {
  32093. value: 'justify',
  32094. className: 'fa fa-align-justify'
  32095. }]
  32096. }]
  32097. }, {
  32098. name: 'Decorations',
  32099. open: false,
  32100. buildProps: ['border-radius-c', 'background-color', 'border-radius', 'border', 'box-shadow', 'background']
  32101. }, {
  32102. name: 'Extra',
  32103. open: false,
  32104. buildProps: ['transition', 'perspective', 'transform']
  32105. }]
  32106. },
  32107. // Configurations for Block Manager
  32108. blockManager: {},
  32109. // Configurations for Trait Manager
  32110. traitManager: {},
  32111. // Texts
  32112. textViewCode: 'Code',
  32113. // Keep unused styles within the editor
  32114. keepUnusedStyles: 0,
  32115. // TODO
  32116. multiFrames: 0
  32117. });
  32118. /***/ }),
  32119. /***/ "./src/editor/index.js":
  32120. /*!*****************************!*\
  32121. !*** ./src/editor/index.js ***!
  32122. \*****************************/
  32123. /*! exports provided: default */
  32124. /***/ (function(module, __webpack_exports__, __webpack_require__) {
  32125. "use strict";
  32126. __webpack_require__.r(__webpack_exports__);
  32127. /* harmony import */ var _babel_runtime_helpers_defineProperty__WEBPACK_IMPORTED_MODULE_0__ = __webpack_require__(/*! @babel/runtime/helpers/defineProperty */ "./node_modules/@babel/runtime/helpers/defineProperty.js");
  32128. /* harmony import */ var _babel_runtime_helpers_defineProperty__WEBPACK_IMPORTED_MODULE_0___default = /*#__PURE__*/__webpack_require__.n(_babel_runtime_helpers_defineProperty__WEBPACK_IMPORTED_MODULE_0__);
  32129. /* harmony import */ var cash_dom__WEBPACK_IMPORTED_MODULE_1__ = __webpack_require__(/*! cash-dom */ "./node_modules/cash-dom/dist/cash.esm.js");
  32130. /* harmony import */ var _config_config__WEBPACK_IMPORTED_MODULE_2__ = __webpack_require__(/*! ./config/config */ "./src/editor/config/config.js");
  32131. /* harmony import */ var _model_Editor__WEBPACK_IMPORTED_MODULE_3__ = __webpack_require__(/*! ./model/Editor */ "./src/editor/model/Editor.js");
  32132. /* harmony import */ var _view_EditorView__WEBPACK_IMPORTED_MODULE_4__ = __webpack_require__(/*! ./view/EditorView */ "./src/editor/view/EditorView.js");
  32133. function ownKeys(object, enumerableOnly) { var keys = Object.keys(object); if (Object.getOwnPropertySymbols) { var symbols = Object.getOwnPropertySymbols(object); if (enumerableOnly) symbols = symbols.filter(function (sym) { return Object.getOwnPropertyDescriptor(object, sym).enumerable; }); keys.push.apply(keys, symbols); } return keys; }
  32134. function _objectSpread(target) { for (var i = 1; i < arguments.length; i++) { var source = arguments[i] != null ? arguments[i] : {}; if (i % 2) { ownKeys(source, true).forEach(function (key) { _babel_runtime_helpers_defineProperty__WEBPACK_IMPORTED_MODULE_0___default()(target, key, source[key]); }); } else if (Object.getOwnPropertyDescriptors) { Object.defineProperties(target, Object.getOwnPropertyDescriptors(source)); } else { ownKeys(source).forEach(function (key) { Object.defineProperty(target, key, Object.getOwnPropertyDescriptor(source, key)); }); } } return target; }
  32135. /**
  32136. * Editor contains the top level API which you'll probably use to customize the editor or extend it with plugins.
  32137. * You get the Editor instance on init method and you can pass options via its [Configuration Object](https://github.com/artf/grapesjs/blob/master/src/editor/config/config.js)
  32138. *
  32139. * ```js
  32140. * const editor = grapesjs.init({
  32141. * // options
  32142. * });
  32143. * ```
  32144. *
  32145. * ## Available Events
  32146. *
  32147. * You can make use of available events in this way
  32148. * ```js
  32149. * editor.on('EVENT-NAME', (some, argument) => {
  32150. * // do something
  32151. * })
  32152. * ```
  32153. *
  32154. * ### Components
  32155. * * `component:create` - Component is created (only the model, is not yet mounted in the canvas), called after the init() method
  32156. * * `component:mount` - Component is mounted to an element and rendered in canvas
  32157. * * `component:add` - Triggered when a new component is added to the editor, the model is passed as an argument to the callback
  32158. * * `component:remove` - Triggered when a component is removed, the model is passed as an argument to the callback
  32159. * * `component:clone` - Triggered when a component is cloned, the new model is passed as an argument to the callback
  32160. * * `component:update` - Triggered when a component is updated (moved, styled, etc.), the model is passed as an argument to the callback
  32161. * * `component:update:{propertyName}` - Listen any property change, the model is passed as an argument to the callback
  32162. * * `component:styleUpdate` - Triggered when the style of the component is updated, the model is passed as an argument to the callback
  32163. * * `component:styleUpdate:{propertyName}` - Listen for a specific style property change, the model is passed as an argument to the callback
  32164. * * `component:selected` - New component selected, the selected model is passed as an argument to the callback
  32165. * * `component:deselected` - Component deselected, the deselected model is passed as an argument to the callback
  32166. * * `component:toggled` - Component selection changed, toggled model is passed as an argument to the callback
  32167. * * `component:type:add` - New component type added, the new type is passed as an argument to the callback
  32168. * * `component:type:update` - Component type updated, the updated type is passed as an argument to the callback
  32169. * * `component:drag:start` - Component drag started. Passed an object, to the callback, containing the `target` (component to drag), `parent` (parent of the component) and `index` (component index in the parent)
  32170. * * `component:drag` - During component drag. Passed the same object as in `component:drag:start` event, but in this case, `parent` and `index` are updated by the current pointer
  32171. * * `component:drag:end` - Component drag ended. Passed the same object as in `component:drag:start` event, but in this case, `parent` and `index` are updated by the final pointer
  32172. * ### Blocks
  32173. * * `block:add` - New block added
  32174. * * `block:remove` - Block removed
  32175. * * `block:drag:start` - Started dragging block, model of the block is passed as an argument
  32176. * * `block:drag` - Dragging block, the block's model and the drag event are passed as arguments
  32177. * * `block:drag:stop` - Dragging of the block is stopped. As agruments for the callback you get, the dropped component model (if dropped successfully) and the model of the block
  32178. * ### Assets
  32179. * * `asset:add` - New asset added
  32180. * * `asset:remove` - Asset removed
  32181. * * `asset:upload:start` - Before the upload is started
  32182. * * `asset:upload:end` - After the upload is ended
  32183. * * `asset:upload:error` - On any error in upload, passes the error as an argument
  32184. * * `asset:upload:response` - On upload response, passes the result as an argument
  32185. * ### Keymaps
  32186. * * `keymap:add` - New keymap added. The new keyamp object is passed as an argument
  32187. * * `keymap:remove` - Keymap removed. The removed keyamp object is passed as an argument
  32188. * * `keymap:emit` - Some keymap emitted, in arguments you get keymapId, shortcutUsed, Event
  32189. * * `keymap:emit:{keymapId}` - `keymapId` emitted, in arguments you get keymapId, shortcutUsed, Event
  32190. * ### Style Manager
  32191. * * `styleManager:update:target` - The target (Component or CSSRule) is changed
  32192. * * `styleManager:change` - Triggered on style property change from new selected component, the view of the property is passed as an argument to the callback
  32193. * * `styleManager:change:{propertyName}` - As above but for a specific style property
  32194. * ### Storages
  32195. * * `storage:start` - Before the storage request is started
  32196. * * `storage:start:store` - Before the store request. The object to store is passed as an argumnet (which you can edit)
  32197. * * `storage:start:load` - Before the load request. Items to load are passed as an argumnet (which you can edit)
  32198. * * `storage:load` - Triggered when something was loaded from the storage, loaded object passed as an argumnet
  32199. * * `storage:store` - Triggered when something is stored to the storage, stored object passed as an argumnet
  32200. * * `storage:end` - After the storage request is ended
  32201. * * `storage:end:store` - After the store request
  32202. * * `storage:end:load` - After the load request
  32203. * * `storage:error` - On any error on storage request, passes the error as an argument
  32204. * * `storage:error:store` - Error on store request, passes the error as an argument
  32205. * * `storage:error:load` - Error on load request, passes the error as an argument
  32206. * ### Canvas
  32207. * * `canvas:dragenter` - When something is dragged inside the canvas, `DataTransfer` instance passed as an argument
  32208. * * `canvas:dragover` - When something is dragging on canvas, `DataTransfer` instance passed as an argument
  32209. * * `canvas:drop` - Something is dropped in canvas, `DataTransfer` instance and the dropped model are passed as arguments
  32210. * * `canvas:dragend` - When a drag operation is ended, `DataTransfer` instance passed as an argument
  32211. * * `canvas:dragdata` - On any dataTransfer parse, `DataTransfer` instance and the `result` are passed as arguments.
  32212. * By changing `result.content` you're able to customize what is dropped
  32213. * ### Selectors
  32214. * * `selector:add` - New selector is add. Passes the new selector as an argument
  32215. * * `selector:remove` - Selector removed. Passes the removed selector as an argument
  32216. * * `selector:update` - Selector updated. Passes the updated selector as an argument
  32217. * * `selector:state` - State changed. Passes the new state value as an argument
  32218. * ### RTE
  32219. * * `rte:enable` - RTE enabled. The view, on which RTE is enabled, is passed as an argument
  32220. * * `rte:disable` - RTE disabled. The view, on which RTE is disabled, is passed as an argument
  32221. * ### Modal
  32222. * * `modal:open` - Modal is opened
  32223. * * `modal:close` - Modal is closed
  32224. * ### Commands
  32225. * * `run:{commandName}` - Triggered when some command is called to run (eg. editor.runCommand('preview'))
  32226. * * `stop:{commandName}` - Triggered when some command is called to stop (eg. editor.stopCommand('preview'))
  32227. * * `run:{commandName}:before` - Triggered before the command is called
  32228. * * `stop:{commandName}:before` - Triggered before the command is called to stop
  32229. * * `abort:{commandName}` - Triggered when the command execution is aborted (`editor.on(`run:preview:before`, opts => opts.abort = 1);`)
  32230. * * `run` - Triggered on run of any command. The id and the result are passed as arguments to the callback
  32231. * * `stop` - Triggered on stop of any command. The id and the result are passed as arguments to the callback
  32232. * ### General
  32233. * * `canvasScroll` - Canvas is scrolled
  32234. * * `update` - The structure of the template is updated (its HTML/CSS)
  32235. * * `undo` - Undo executed
  32236. * * `redo` - Redo executed
  32237. * * `load` - Editor is loaded
  32238. *
  32239. * @module Editor
  32240. */
  32241. /* harmony default export */ __webpack_exports__["default"] = (function () {
  32242. var config = arguments.length > 0 && arguments[0] !== undefined ? arguments[0] : {};
  32243. var c = _objectSpread({}, _config_config__WEBPACK_IMPORTED_MODULE_2__["default"], {}, config);
  32244. c.pStylePrefix = c.stylePrefix;
  32245. var em = new _model_Editor__WEBPACK_IMPORTED_MODULE_3__["default"](c);
  32246. var editorView = new _view_EditorView__WEBPACK_IMPORTED_MODULE_4__["default"]({
  32247. model: em,
  32248. config: c
  32249. });
  32250. return {
  32251. $: cash_dom__WEBPACK_IMPORTED_MODULE_1__["default"],
  32252. /**
  32253. * @property {EditorModel}
  32254. * @private
  32255. */
  32256. editor: em,
  32257. /**
  32258. * Initialize editor model
  32259. * @return {this}
  32260. * @private
  32261. */
  32262. init: function init() {
  32263. var _this = this;
  32264. var opts = arguments.length > 0 && arguments[0] !== undefined ? arguments[0] : {};
  32265. em.init(this, _objectSpread({}, c, {}, opts));
  32266. ['I18n', 'Utils', 'Config', 'Commands', 'Keymaps', 'Modal', 'Panels', 'Canvas', 'Parser', 'CodeManager', 'UndoManager', 'RichTextEditor', 'DomComponents', ['Components', 'DomComponents'], 'LayerManager', ['Layers', 'LayerManager'], 'CssComposer', ['Css', 'CssComposer'], 'StorageManager', ['Storage', 'StorageManager'], 'AssetManager', ['Assets', 'AssetManager'], 'BlockManager', ['Blocks', 'BlockManager'], 'TraitManager', ['Traits', 'TraitManager'], 'SelectorManager', ['Selectors', 'SelectorManager'], 'StyleManager', ['Styles', 'StyleManager'], 'DeviceManager', ['Devices', 'DeviceManager']].forEach(function (prop) {
  32267. if (Array.isArray(prop)) {
  32268. _this[prop[0]] = em.get(prop[1]);
  32269. } else {
  32270. _this[prop] = em.get(prop);
  32271. }
  32272. }); // Do post render stuff after the iframe is loaded otherwise it'll
  32273. // be empty during tests
  32274. em.on('loaded', function () {
  32275. _this.UndoManager.clear();
  32276. em.get('modules').forEach(function (module) {
  32277. module.postRender && module.postRender(editorView);
  32278. });
  32279. });
  32280. return this;
  32281. },
  32282. /**
  32283. * Returns configuration object
  32284. * @param {string} [prop] Property name
  32285. * @return {any} Returns the configuration object or
  32286. * the value of the specified property
  32287. */
  32288. getConfig: function getConfig(prop) {
  32289. return em.getConfig(prop);
  32290. },
  32291. /**
  32292. * Returns HTML built inside canvas
  32293. * @return {string} HTML string
  32294. */
  32295. getHtml: function getHtml(opts) {
  32296. return em.getHtml(opts);
  32297. },
  32298. /**
  32299. * Returns CSS built inside canvas
  32300. * @param {Object} [opts={}] Options
  32301. * @param {Boolean} [opts.avoidProtected=false] Don't include protected CSS
  32302. * @return {string} CSS string
  32303. */
  32304. getCss: function getCss(opts) {
  32305. return em.getCss(opts);
  32306. },
  32307. /**
  32308. * Returns JS of all components
  32309. * @return {string} JS string
  32310. */
  32311. getJs: function getJs() {
  32312. return em.getJs();
  32313. },
  32314. /**
  32315. * Return the complete tree of components. Use `getWrapper` to include also the wrapper
  32316. * @return {Components}
  32317. */
  32318. getComponents: function getComponents() {
  32319. return em.get('DomComponents').getComponents();
  32320. },
  32321. /**
  32322. * Return the wrapper and its all components
  32323. * @return {Component}
  32324. */
  32325. getWrapper: function getWrapper() {
  32326. return em.get('DomComponents').getWrapper();
  32327. },
  32328. /**
  32329. * Set components inside editor's canvas. This method overrides actual components
  32330. * @param {Array<Object>|Object|string} components HTML string or components model
  32331. * @return {this}
  32332. * @example
  32333. * editor.setComponents('<div class="cls">New component</div>');
  32334. * // or
  32335. * editor.setComponents({
  32336. * type: 'text',
  32337. * classes:['cls'],
  32338. * content: 'New component'
  32339. * });
  32340. */
  32341. setComponents: function setComponents(components) {
  32342. em.setComponents(components);
  32343. return this;
  32344. },
  32345. /**
  32346. * Add components
  32347. * @param {Array<Object>|Object|string} components HTML string or components model
  32348. * @param {Object} opts Options
  32349. * @param {Boolean} [opts.avoidUpdateStyle=false] If the HTML string contains styles,
  32350. * by default, they will be created and, if already exist, updated. When this option
  32351. * is true, styles already created will not be updated.
  32352. * @return {Array<Component>}
  32353. * @example
  32354. * editor.addComponents('<div class="cls">New component</div>');
  32355. * // or
  32356. * editor.addComponents({
  32357. * type: 'text',
  32358. * classes:['cls'],
  32359. * content: 'New component'
  32360. * });
  32361. */
  32362. addComponents: function addComponents(components, opts) {
  32363. return this.getWrapper().append(components, opts);
  32364. },
  32365. /**
  32366. * Returns style in JSON format object
  32367. * @return {Object}
  32368. */
  32369. getStyle: function getStyle() {
  32370. return em.get('CssComposer').getAll();
  32371. },
  32372. /**
  32373. * Set style inside editor's canvas. This method overrides actual style
  32374. * @param {Array<Object>|Object|string} style CSS string or style model
  32375. * @return {this}
  32376. * @example
  32377. * editor.setStyle('.cls{color: red}');
  32378. * //or
  32379. * editor.setStyle({
  32380. * selectors: ['cls']
  32381. * style: { color: 'red' }
  32382. * });
  32383. */
  32384. setStyle: function setStyle(style) {
  32385. em.setStyle(style);
  32386. return this;
  32387. },
  32388. /**
  32389. * Returns the last selected component, if there is one
  32390. * @return {Model}
  32391. */
  32392. getSelected: function getSelected() {
  32393. return em.getSelected();
  32394. },
  32395. /**
  32396. * Returns an array of all selected components
  32397. * @return {Array}
  32398. */
  32399. getSelectedAll: function getSelectedAll() {
  32400. return em.getSelectedAll();
  32401. },
  32402. /**
  32403. * Get a stylable entity from the selected component.
  32404. * If you select a component without classes the entity is the Component
  32405. * itself and all changes will go inside its 'style' attribute. Otherwise,
  32406. * if the selected component has one or more classes, the function will
  32407. * return the corresponding CSS Rule
  32408. * @return {Model}
  32409. */
  32410. getSelectedToStyle: function getSelectedToStyle() {
  32411. var selected = em.getSelected();
  32412. if (selected) {
  32413. return this.StyleManager.getModelToStyle(selected);
  32414. }
  32415. },
  32416. /**
  32417. * Select a component
  32418. * @param {Component|HTMLElement} el Component to select
  32419. * @param {Object} [opts] Options
  32420. * @param {Boolean} [opts.scroll] Scroll canvas to the selected element
  32421. * @return {this}
  32422. * @example
  32423. * // Select dropped block
  32424. * editor.on('block:drag:stop', function(model) {
  32425. * editor.select(model);
  32426. * });
  32427. */
  32428. select: function select(el, opts) {
  32429. em.setSelected(el, opts);
  32430. return this;
  32431. },
  32432. /**
  32433. * Add component to selection
  32434. * @param {Component|HTMLElement|Array} el Component to select
  32435. * @return {this}
  32436. * @example
  32437. * editor.selectAdd(model);
  32438. */
  32439. selectAdd: function selectAdd(el) {
  32440. em.addSelected(el);
  32441. return this;
  32442. },
  32443. /**
  32444. * Remove component from selection
  32445. * @param {Component|HTMLElement|Array} el Component to select
  32446. * @return {this}
  32447. * @example
  32448. * editor.selectRemove(model);
  32449. */
  32450. selectRemove: function selectRemove(el) {
  32451. em.removeSelected(el);
  32452. return this;
  32453. },
  32454. /**
  32455. * Toggle component selection
  32456. * @param {Component|HTMLElement|Array} el Component to select
  32457. * @return {this}
  32458. * @example
  32459. * editor.selectToggle(model);
  32460. */
  32461. selectToggle: function selectToggle(el) {
  32462. em.toggleSelected(el);
  32463. return this;
  32464. },
  32465. /**
  32466. * Set device to the editor. If the device exists it will
  32467. * change the canvas to the proper width
  32468. * @param {string} name Name of the device
  32469. * @return {this}
  32470. * @example
  32471. * editor.setDevice('Tablet');
  32472. */
  32473. setDevice: function setDevice(name) {
  32474. em.set('device', name);
  32475. return this;
  32476. },
  32477. /**
  32478. * Return the actual active device
  32479. * @return {string} Device name
  32480. * @example
  32481. * var device = editor.getDevice();
  32482. * console.log(device);
  32483. * // 'Tablet'
  32484. */
  32485. getDevice: function getDevice() {
  32486. return em.get('device');
  32487. },
  32488. /**
  32489. * Execute command
  32490. * @param {string} id Command ID
  32491. * @param {Object} options Custom options
  32492. * @return {*} The return is defined by the command
  32493. * @example
  32494. * editor.runCommand('myCommand', {someValue: 1});
  32495. */
  32496. runCommand: function runCommand(id) {
  32497. var options = arguments.length > 1 && arguments[1] !== undefined ? arguments[1] : {};
  32498. return em.get('Commands').run(id, options);
  32499. },
  32500. /**
  32501. * Stop the command if stop method was provided
  32502. * @param {string} id Command ID
  32503. * @param {Object} options Custom options
  32504. * @return {*} The return is defined by the command
  32505. * @example
  32506. * editor.stopCommand('myCommand', {someValue: 1});
  32507. */
  32508. stopCommand: function stopCommand(id) {
  32509. var options = arguments.length > 1 && arguments[1] !== undefined ? arguments[1] : {};
  32510. return em.get('Commands').stop(id, options);
  32511. },
  32512. /**
  32513. * Store data to the current storage
  32514. * @param {Function} clb Callback function
  32515. * @return {Object} Stored data
  32516. */
  32517. store: function store(clb) {
  32518. return em.store(clb);
  32519. },
  32520. /**
  32521. * Load data from the current storage
  32522. * @param {Function} clb Callback function
  32523. * @return {Object} Stored data
  32524. */
  32525. load: function load(clb) {
  32526. return em.load(clb);
  32527. },
  32528. /**
  32529. * Returns container element. The one which was indicated as 'container'
  32530. * on init method
  32531. * @return {HTMLElement}
  32532. */
  32533. getContainer: function getContainer() {
  32534. return c.el;
  32535. },
  32536. /**
  32537. * Return the count of changes made to the content and not yet stored.
  32538. * This count resets at any `store()`
  32539. * @return {number}
  32540. */
  32541. getDirtyCount: function getDirtyCount() {
  32542. return em.getDirtyCount();
  32543. },
  32544. /**
  32545. * Update editor dimensions and refresh data useful for positioning of tools
  32546. *
  32547. * This method could be useful when you update, for example, some position
  32548. * of the editor element (eg. canvas, panels, etc.) with CSS, where without
  32549. * refresh you'll get misleading position of tools (eg. rich text editor,
  32550. * component highlighter, etc.)
  32551. *
  32552. * @private
  32553. */
  32554. refresh: function refresh() {
  32555. em.refreshCanvas();
  32556. },
  32557. /**
  32558. * Replace the built-in Rich Text Editor with a custom one.
  32559. * @param {Object} obj Custom RTE Interface
  32560. * @example
  32561. * editor.setCustomRte({
  32562. * // Function for enabling custom RTE
  32563. * // el is the HTMLElement of the double clicked Text Component
  32564. * // rte is the same instance you have returned the first time you call
  32565. * // enable(). This is useful if need to check if the RTE is already enabled so
  32566. * // ion this case you'll need to return the RTE and the end of the function
  32567. * enable: function(el, rte) {
  32568. * rte = new MyCustomRte(el, {}); // this depends on the Custom RTE API
  32569. * ...
  32570. * return rte; // return the RTE instance
  32571. * },
  32572. *
  32573. * // Disable the editor, called for example when you unfocus the Text Component
  32574. * disable: function(el, rte) {
  32575. * rte.blur(); // this depends on the Custom RTE API
  32576. * }
  32577. *
  32578. * // Called when the Text Component is focused again. If you returned the RTE instance
  32579. * // from the enable function, the enable won't be called again instead will call focus,
  32580. * // in this case to avoid double binding of the editor
  32581. * focus: function (el, rte) {
  32582. * rte.focus(); // this depends on the Custom RTE API
  32583. * }
  32584. * });
  32585. */
  32586. setCustomRte: function setCustomRte(obj) {
  32587. this.RichTextEditor.customRte = obj;
  32588. },
  32589. /**
  32590. * Replace the default CSS parser with a custom one.
  32591. * The parser function receives a CSS string as a parameter and expects
  32592. * an array of CSSRule objects as a result. If you need to remove the
  32593. * custom parser, pass `null` as the argument
  32594. * @param {Function|null} parser Parser function
  32595. * @return {this}
  32596. * @example
  32597. * editor.setCustomParserCss(css => {
  32598. * const result = [];
  32599. * // ... parse the CSS string
  32600. * result.push({
  32601. * selectors: '.someclass, div .otherclass',
  32602. * style: { color: 'red' }
  32603. * })
  32604. * // ...
  32605. * return result;
  32606. * });
  32607. */
  32608. setCustomParserCss: function setCustomParserCss(parser) {
  32609. this.Parser.getConfig().parserCss = parser;
  32610. return this;
  32611. },
  32612. /**
  32613. * Change the global drag mode of components.
  32614. * To get more about this feature read: https://github.com/artf/grapesjs/issues/1936
  32615. * @param {String} value Drag mode, options: 'absolute' | 'translate'
  32616. * @returns {this}
  32617. */
  32618. setDragMode: function setDragMode(value) {
  32619. em.setDragMode(value);
  32620. return this;
  32621. },
  32622. /**
  32623. * Trigger event log message
  32624. * @param {*} msg Message to log
  32625. * @param {Object} [opts={}] Custom options
  32626. * @param {String} [opts.ns=''] Namespace of the log (eg. to use in plugins)
  32627. * @param {String} [opts.level='debug'] Level of the log, `debug`, `info`, `warning`, `error`
  32628. * @return {this}
  32629. * @example
  32630. * editor.log('Something done!', { ns: 'from-plugin-x', level: 'info' });
  32631. * // This will trigger following events
  32632. * // `log`, `log:info`, `log-from-plugin-x`, `log-from-plugin-x:info`
  32633. * // Callbacks of those events will always receive the message and
  32634. * // options, as arguments, eg:
  32635. * // editor.on('log:info', (msg, opts) => console.info(msg, opts))
  32636. */
  32637. log: function log(msg) {
  32638. var opts = arguments.length > 1 && arguments[1] !== undefined ? arguments[1] : {};
  32639. em.log(msg, opts);
  32640. return this;
  32641. },
  32642. /**
  32643. * Translate label
  32644. * @param {String} key Label to translate
  32645. * @param {Object} [opts] Options for the translation
  32646. * @param {Object} [opts.params] Params for the translation
  32647. * @param {Boolean} [opts.noWarn] Avoid warnings in case of missing resources
  32648. * @returns {String}
  32649. * @example
  32650. * editor.t('msg');
  32651. * // use params
  32652. * editor.t('msg2', { params: { test: 'hello' } });
  32653. * // custom local
  32654. * editor.t('msg2', { params: { test: 'hello' }, l: 'it' });
  32655. */
  32656. t: function t() {
  32657. return em.t.apply(em, arguments);
  32658. },
  32659. /**
  32660. * Attach event
  32661. * @param {string} event Event name
  32662. * @param {Function} callback Callback function
  32663. * @return {this}
  32664. */
  32665. on: function on(event, callback) {
  32666. em.on(event, callback);
  32667. return this;
  32668. },
  32669. /**
  32670. * Attach event and detach it after the first run
  32671. * @param {string} event Event name
  32672. * @param {Function} callback Callback function
  32673. * @return {this}
  32674. */
  32675. once: function once(event, callback) {
  32676. em.once(event, callback);
  32677. return this;
  32678. },
  32679. /**
  32680. * Detach event
  32681. * @param {string} event Event name
  32682. * @param {Function} callback Callback function
  32683. * @return {this}
  32684. */
  32685. off: function off(event, callback) {
  32686. em.off(event, callback);
  32687. return this;
  32688. },
  32689. /**
  32690. * Trigger event
  32691. * @param {string} event Event to trigger
  32692. * @return {this}
  32693. */
  32694. trigger: function trigger(event) {
  32695. em.trigger.apply(em, arguments);
  32696. return this;
  32697. },
  32698. /**
  32699. * Destroy the editor
  32700. */
  32701. destroy: function destroy() {
  32702. return em.destroyAll();
  32703. },
  32704. /**
  32705. * Returns editor element
  32706. * @return {HTMLElement}
  32707. * @private
  32708. */
  32709. getEl: function getEl() {
  32710. return editorView.el;
  32711. },
  32712. /**
  32713. * Returns editor model
  32714. * @return {Model}
  32715. * @private
  32716. */
  32717. getModel: function getModel() {
  32718. return em;
  32719. },
  32720. /**
  32721. * Render editor
  32722. * @return {HTMLElement}
  32723. */
  32724. render: function render() {
  32725. editorView.render();
  32726. return editorView.el;
  32727. }
  32728. };
  32729. });
  32730. /***/ }),
  32731. /***/ "./src/editor/model/Editor.js":
  32732. /*!************************************!*\
  32733. !*** ./src/editor/model/Editor.js ***!
  32734. \************************************/
  32735. /*! exports provided: default */
  32736. /***/ (function(module, __webpack_exports__, __webpack_require__) {
  32737. "use strict";
  32738. __webpack_require__.r(__webpack_exports__);
  32739. /* harmony import */ var _babel_runtime_helpers_defineProperty__WEBPACK_IMPORTED_MODULE_0__ = __webpack_require__(/*! @babel/runtime/helpers/defineProperty */ "./node_modules/@babel/runtime/helpers/defineProperty.js");
  32740. /* harmony import */ var _babel_runtime_helpers_defineProperty__WEBPACK_IMPORTED_MODULE_0___default = /*#__PURE__*/__webpack_require__.n(_babel_runtime_helpers_defineProperty__WEBPACK_IMPORTED_MODULE_0__);
  32741. /* harmony import */ var underscore__WEBPACK_IMPORTED_MODULE_1__ = __webpack_require__(/*! underscore */ "./node_modules/underscore/underscore.js");
  32742. /* harmony import */ var underscore__WEBPACK_IMPORTED_MODULE_1___default = /*#__PURE__*/__webpack_require__.n(underscore__WEBPACK_IMPORTED_MODULE_1__);
  32743. /* harmony import */ var cash_dom__WEBPACK_IMPORTED_MODULE_2__ = __webpack_require__(/*! cash-dom */ "./node_modules/cash-dom/dist/cash.esm.js");
  32744. /* harmony import */ var backbone__WEBPACK_IMPORTED_MODULE_3__ = __webpack_require__(/*! backbone */ "./node_modules/backbone/backbone.js");
  32745. /* harmony import */ var backbone__WEBPACK_IMPORTED_MODULE_3___default = /*#__PURE__*/__webpack_require__.n(backbone__WEBPACK_IMPORTED_MODULE_3__);
  32746. /* harmony import */ var utils_extender__WEBPACK_IMPORTED_MODULE_4__ = __webpack_require__(/*! utils/extender */ "./src/utils/extender.js");
  32747. /* harmony import */ var utils_mixins__WEBPACK_IMPORTED_MODULE_5__ = __webpack_require__(/*! utils/mixins */ "./src/utils/mixins.js");
  32748. function ownKeys(object, enumerableOnly) { var keys = Object.keys(object); if (Object.getOwnPropertySymbols) { var symbols = Object.getOwnPropertySymbols(object); if (enumerableOnly) symbols = symbols.filter(function (sym) { return Object.getOwnPropertyDescriptor(object, sym).enumerable; }); keys.push.apply(keys, symbols); } return keys; }
  32749. function _objectSpread(target) { for (var i = 1; i < arguments.length; i++) { var source = arguments[i] != null ? arguments[i] : {}; if (i % 2) { ownKeys(source, true).forEach(function (key) { _babel_runtime_helpers_defineProperty__WEBPACK_IMPORTED_MODULE_0___default()(target, key, source[key]); }); } else if (Object.getOwnPropertyDescriptors) { Object.defineProperties(target, Object.getOwnPropertyDescriptors(source)); } else { ownKeys(source).forEach(function (key) { Object.defineProperty(target, key, Object.getOwnPropertyDescriptor(source, key)); }); } } return target; }
  32750. backbone__WEBPACK_IMPORTED_MODULE_3___default.a.$ = cash_dom__WEBPACK_IMPORTED_MODULE_2__["default"];
  32751. var deps = [__webpack_require__(/*! utils */ "./src/utils/index.js"), __webpack_require__(/*! i18n */ "./src/i18n/index.js"), __webpack_require__(/*! keymaps */ "./src/keymaps/index.js"), __webpack_require__(/*! undo_manager */ "./src/undo_manager/index.js"), __webpack_require__(/*! storage_manager */ "./src/storage_manager/index.js"), __webpack_require__(/*! device_manager */ "./src/device_manager/index.js"), __webpack_require__(/*! parser */ "./src/parser/index.js"), __webpack_require__(/*! selector_manager */ "./src/selector_manager/index.js"), __webpack_require__(/*! style_manager */ "./src/style_manager/index.js"), __webpack_require__(/*! modal_dialog */ "./src/modal_dialog/index.js"), __webpack_require__(/*! code_manager */ "./src/code_manager/index.js"), __webpack_require__(/*! panels */ "./src/panels/index.js"), __webpack_require__(/*! rich_text_editor */ "./src/rich_text_editor/index.js"), __webpack_require__(/*! asset_manager */ "./src/asset_manager/index.js"), __webpack_require__(/*! css_composer */ "./src/css_composer/index.js"), __webpack_require__(/*! trait_manager */ "./src/trait_manager/index.js"), __webpack_require__(/*! dom_components */ "./src/dom_components/index.js"), __webpack_require__(/*! navigator */ "./src/navigator/index.js"), __webpack_require__(/*! canvas */ "./src/canvas/index.js"), __webpack_require__(/*! commands */ "./src/commands/index.js"), __webpack_require__(/*! block_manager */ "./src/block_manager/index.js")];
  32752. var Collection = backbone__WEBPACK_IMPORTED_MODULE_3___default.a.Collection;
  32753. var timedInterval;
  32754. var updateItr;
  32755. Object(utils_extender__WEBPACK_IMPORTED_MODULE_4__["default"])({
  32756. Backbone: backbone__WEBPACK_IMPORTED_MODULE_3___default.a,
  32757. $: backbone__WEBPACK_IMPORTED_MODULE_3___default.a.$
  32758. });
  32759. var logs = {
  32760. debug: console.log,
  32761. info: console.info,
  32762. warning: console.warn,
  32763. error: console.error
  32764. };
  32765. /* harmony default export */ __webpack_exports__["default"] = (backbone__WEBPACK_IMPORTED_MODULE_3___default.a.Model.extend({
  32766. defaults: function defaults() {
  32767. return {
  32768. editing: 0,
  32769. selected: new Collection(),
  32770. clipboard: null,
  32771. dmode: 0,
  32772. componentHovered: null,
  32773. previousModel: null,
  32774. changesCount: 0,
  32775. storables: [],
  32776. modules: [],
  32777. toLoad: [],
  32778. opened: {},
  32779. device: ''
  32780. };
  32781. },
  32782. initialize: function initialize() {
  32783. var _this = this;
  32784. var c = arguments.length > 0 && arguments[0] !== undefined ? arguments[0] : {};
  32785. this.config = c;
  32786. this.set('Config', c);
  32787. this.set('modules', []);
  32788. this.set('toLoad', []);
  32789. this.set('storables', []);
  32790. this.set('selected', new Collection());
  32791. this.set('dmode', c.dragMode);
  32792. var el = c.el;
  32793. var log = c.log;
  32794. var toLog = log === true ? Object(underscore__WEBPACK_IMPORTED_MODULE_1__["keys"])(logs) : Object(underscore__WEBPACK_IMPORTED_MODULE_1__["isArray"])(log) ? log : [];
  32795. Object(underscore__WEBPACK_IMPORTED_MODULE_1__["bindAll"])(this, 'initBaseColorPicker');
  32796. if (el && c.fromElement) this.config.components = el.innerHTML;
  32797. this.attrsOrig = el ? Object(underscore__WEBPACK_IMPORTED_MODULE_1__["toArray"])(el.attributes).reduce(function (res, next) {
  32798. res[next.nodeName] = next.nodeValue;
  32799. return res;
  32800. }, {}) : ''; // Load modules
  32801. deps.forEach(function (name) {
  32802. return _this.loadModule(name);
  32803. });
  32804. this.on('change:componentHovered', this.componentHovered, this);
  32805. this.on('change:changesCount', this.updateChanges, this);
  32806. toLog.forEach(function (e) {
  32807. return _this.listenLog(e);
  32808. }); // Deprecations
  32809. [{
  32810. from: 'change:selectedComponent',
  32811. to: 'component:toggled'
  32812. }].forEach(function (event) {
  32813. var eventFrom = event.from;
  32814. var eventTo = event.to;
  32815. _this.listenTo(_this, eventFrom, function () {
  32816. for (var _len = arguments.length, args = new Array(_len), _key = 0; _key < _len; _key++) {
  32817. args[_key] = arguments[_key];
  32818. }
  32819. _this.trigger.apply(_this, [eventTo].concat(args));
  32820. _this.logWarning("The event '".concat(eventFrom, "' is deprecated, replace it with '").concat(eventTo, "'"));
  32821. });
  32822. });
  32823. },
  32824. getContainer: function getContainer() {
  32825. return this.config.el;
  32826. },
  32827. listenLog: function listenLog(event) {
  32828. this.listenTo(this, "log:".concat(event), logs[event]);
  32829. },
  32830. /**
  32831. * Get configurations
  32832. * @param {string} [prop] Property name
  32833. * @return {any} Returns the configuration object or
  32834. * the value of the specified property
  32835. */
  32836. getConfig: function getConfig(prop) {
  32837. var config = this.config;
  32838. return Object(underscore__WEBPACK_IMPORTED_MODULE_1__["isUndefined"])(prop) ? config : config[prop];
  32839. },
  32840. /**
  32841. * Should be called after all modules and plugins are loaded
  32842. * @param {Function} clb
  32843. * @private
  32844. */
  32845. loadOnStart: function loadOnStart() {
  32846. var _this2 = this;
  32847. var clb = arguments.length > 0 && arguments[0] !== undefined ? arguments[0] : null;
  32848. var sm = this.get('StorageManager'); // Generally, with `onLoad`, the module will try to load the data from
  32849. // its configurations
  32850. this.get('toLoad').forEach(function (module) {
  32851. module.onLoad();
  32852. }); // Stuff to do post load
  32853. var postLoad = function postLoad() {
  32854. var modules = _this2.get('modules');
  32855. modules.forEach(function (module) {
  32856. return module.postLoad && module.postLoad(_this2);
  32857. });
  32858. clb && clb();
  32859. };
  32860. if (sm && sm.canAutoload()) {
  32861. this.load(postLoad);
  32862. } else {
  32863. postLoad();
  32864. }
  32865. },
  32866. /**
  32867. * Set the alert before unload in case it's requested
  32868. * and there are unsaved changes
  32869. * @private
  32870. */
  32871. updateChanges: function updateChanges() {
  32872. var _this3 = this;
  32873. var stm = this.get('StorageManager');
  32874. var changes = this.get('changesCount');
  32875. updateItr && clearTimeout(updateItr);
  32876. updateItr = setTimeout(function () {
  32877. return _this3.trigger('update');
  32878. });
  32879. if (this.config.noticeOnUnload) {
  32880. window.onbeforeunload = changes ? function (e) {
  32881. return 1;
  32882. } : null;
  32883. }
  32884. if (stm.isAutosave() && changes >= stm.getStepsBeforeSave()) {
  32885. this.store();
  32886. }
  32887. },
  32888. /**
  32889. * Load generic module
  32890. * @param {String} moduleName Module name
  32891. * @return {this}
  32892. * @private
  32893. */
  32894. loadModule: function loadModule(moduleName) {
  32895. var config = this.config;
  32896. var Module = moduleName.default || moduleName;
  32897. var Mod = new Module();
  32898. var name = Mod.name.charAt(0).toLowerCase() + Mod.name.slice(1);
  32899. var cfgParent = !Object(underscore__WEBPACK_IMPORTED_MODULE_1__["isUndefined"])(config[name]) ? config[name] : config[Mod.name];
  32900. var cfg = cfgParent || {};
  32901. var sm = this.get('StorageManager');
  32902. cfg.pStylePrefix = config.pStylePrefix || '';
  32903. if (!Object(underscore__WEBPACK_IMPORTED_MODULE_1__["isUndefined"])(cfgParent) && !cfgParent) {
  32904. cfg._disable = 1;
  32905. }
  32906. if (Mod.storageKey && Mod.store && Mod.load && sm) {
  32907. cfg.stm = sm; // DomComponents should be load before CSS Composer
  32908. var mth = name == 'domComponents' ? 'unshift' : 'push';
  32909. this.get('storables')[mth](Mod);
  32910. }
  32911. cfg.em = this;
  32912. Mod.init(_objectSpread({}, cfg)); // Bind the module to the editor model if public
  32913. !Mod.private && this.set(Mod.name, Mod);
  32914. Mod.onLoad && this.get('toLoad').push(Mod);
  32915. this.get('modules').push(Mod);
  32916. return this;
  32917. },
  32918. /**
  32919. * Initialize editor model and set editor instance
  32920. * @param {Editor} editor Editor instance
  32921. * @return {this}
  32922. * @private
  32923. */
  32924. init: function init(editor) {
  32925. var opts = arguments.length > 1 && arguments[1] !== undefined ? arguments[1] : {};
  32926. if (this.destroyed) {
  32927. this.initialize(opts);
  32928. this.destroyed = 0;
  32929. }
  32930. this.set('Editor', editor);
  32931. },
  32932. getEditor: function getEditor() {
  32933. return this.get('Editor');
  32934. },
  32935. /**
  32936. * This method handles updates on the editor and tries to store them
  32937. * if requested and if the changesCount is exceeded
  32938. * @param {Object} model
  32939. * @param {any} val Value
  32940. * @param {Object} opt Options
  32941. * @private
  32942. * */
  32943. handleUpdates: function handleUpdates(model, val) {
  32944. var _this4 = this;
  32945. var opt = arguments.length > 2 && arguments[2] !== undefined ? arguments[2] : {};
  32946. // Component has been added temporarily - do not update storage or record changes
  32947. if (opt.temporary) {
  32948. return;
  32949. }
  32950. timedInterval && clearInterval(timedInterval);
  32951. timedInterval = setTimeout(function () {
  32952. if (!opt.avoidStore) {
  32953. _this4.set('changesCount', _this4.get('changesCount') + 1, opt);
  32954. }
  32955. }, 0);
  32956. },
  32957. /**
  32958. * Callback on component hover
  32959. * @param {Object} Model
  32960. * @param {Mixed} New value
  32961. * @param {Object} Options
  32962. * @private
  32963. * */
  32964. componentHovered: function componentHovered(editor, component, options) {
  32965. var prev = this.previous('componentHovered');
  32966. prev && this.trigger('component:unhovered', prev, options);
  32967. component && this.trigger('component:hovered', component, options);
  32968. },
  32969. /**
  32970. * Returns model of the selected component
  32971. * @return {Component|null}
  32972. * @private
  32973. */
  32974. getSelected: function getSelected() {
  32975. return this.get('selected').last();
  32976. },
  32977. /**
  32978. * Returns an array of all selected components
  32979. * @return {Array}
  32980. * @private
  32981. */
  32982. getSelectedAll: function getSelectedAll() {
  32983. return this.get('selected').models;
  32984. },
  32985. /**
  32986. * Select a component
  32987. * @param {Component|HTMLElement} el Component to select
  32988. * @param {Object} [opts={}] Options, optional
  32989. * @private
  32990. */
  32991. setSelected: function setSelected(el) {
  32992. var _this5 = this;
  32993. var opts = arguments.length > 1 && arguments[1] !== undefined ? arguments[1] : {};
  32994. var multiple = Object(underscore__WEBPACK_IMPORTED_MODULE_1__["isArray"])(el);
  32995. var els = multiple ? el : [el];
  32996. var selected = this.get('selected');
  32997. var added; // If an array is passed remove all selected
  32998. // expect those yet to be selected
  32999. multiple && this.removeSelected(selected.filter(function (s) {
  33000. return !Object(underscore__WEBPACK_IMPORTED_MODULE_1__["contains"])(els, s);
  33001. }));
  33002. els.forEach(function (el) {
  33003. var model = Object(utils_mixins__WEBPACK_IMPORTED_MODULE_5__["getModel"])(el, cash_dom__WEBPACK_IMPORTED_MODULE_2__["default"]);
  33004. if (model && !model.get('selectable')) return;
  33005. !multiple && _this5.removeSelected(selected.filter(function (s) {
  33006. return s !== model;
  33007. }));
  33008. _this5.addSelected(model, opts);
  33009. added = model;
  33010. });
  33011. },
  33012. /**
  33013. * Add component to selection
  33014. * @param {Component|HTMLElement} el Component to select
  33015. * @param {Object} [opts={}] Options, optional
  33016. * @private
  33017. */
  33018. addSelected: function addSelected(el) {
  33019. var _this6 = this;
  33020. var opts = arguments.length > 1 && arguments[1] !== undefined ? arguments[1] : {};
  33021. var model = Object(utils_mixins__WEBPACK_IMPORTED_MODULE_5__["getModel"])(el, cash_dom__WEBPACK_IMPORTED_MODULE_2__["default"]);
  33022. var models = Object(underscore__WEBPACK_IMPORTED_MODULE_1__["isArray"])(model) ? model : [model];
  33023. models.forEach(function (model) {
  33024. if (model && !model.get('selectable')) return;
  33025. var selected = _this6.get('selected');
  33026. opts.forceChange && selected.remove(model, opts);
  33027. selected.push(model, opts);
  33028. });
  33029. },
  33030. /**
  33031. * Remove component from selection
  33032. * @param {Component|HTMLElement} el Component to select
  33033. * @param {Object} [opts={}] Options, optional
  33034. * @private
  33035. */
  33036. removeSelected: function removeSelected(el) {
  33037. var opts = arguments.length > 1 && arguments[1] !== undefined ? arguments[1] : {};
  33038. this.get('selected').remove(Object(utils_mixins__WEBPACK_IMPORTED_MODULE_5__["getModel"])(el, cash_dom__WEBPACK_IMPORTED_MODULE_2__["default"]), opts);
  33039. },
  33040. /**
  33041. * Toggle component selection
  33042. * @param {Component|HTMLElement} el Component to select
  33043. * @param {Object} [opts={}] Options, optional
  33044. * @private
  33045. */
  33046. toggleSelected: function toggleSelected(el) {
  33047. var _this7 = this;
  33048. var opts = arguments.length > 1 && arguments[1] !== undefined ? arguments[1] : {};
  33049. var model = Object(utils_mixins__WEBPACK_IMPORTED_MODULE_5__["getModel"])(el, cash_dom__WEBPACK_IMPORTED_MODULE_2__["default"]);
  33050. var models = Object(underscore__WEBPACK_IMPORTED_MODULE_1__["isArray"])(model) ? model : [model];
  33051. models.forEach(function (model) {
  33052. if (_this7.get('selected').contains(model)) {
  33053. _this7.removeSelected(model, opts);
  33054. } else {
  33055. _this7.addSelected(model, opts);
  33056. }
  33057. });
  33058. },
  33059. /**
  33060. * Hover a component
  33061. * @param {Component|HTMLElement} el Component to select
  33062. * @param {Object} [opts={}] Options, optional
  33063. * @private
  33064. */
  33065. setHovered: function setHovered(el) {
  33066. var opts = arguments.length > 1 && arguments[1] !== undefined ? arguments[1] : {};
  33067. var model = Object(utils_mixins__WEBPACK_IMPORTED_MODULE_5__["getModel"])(el, cash_dom__WEBPACK_IMPORTED_MODULE_2__["default"]);
  33068. if (model && !model.get('hoverable')) return;
  33069. opts.forceChange && this.set('componentHovered', '');
  33070. this.set('componentHovered', model, opts);
  33071. },
  33072. getHovered: function getHovered() {
  33073. return this.get('componentHovered');
  33074. },
  33075. /**
  33076. * Set components inside editor's canvas. This method overrides actual components
  33077. * @param {Object|string} components HTML string or components model
  33078. * @return {this}
  33079. * @private
  33080. */
  33081. setComponents: function setComponents(components) {
  33082. return this.get('DomComponents').setComponents(components);
  33083. },
  33084. /**
  33085. * Returns components model from the editor's canvas
  33086. * @return {Components}
  33087. * @private
  33088. */
  33089. getComponents: function getComponents() {
  33090. var cmp = this.get('DomComponents');
  33091. var cm = this.get('CodeManager');
  33092. if (!cmp || !cm) return;
  33093. var wrp = cmp.getComponents();
  33094. return cm.getCode(wrp, 'json');
  33095. },
  33096. /**
  33097. * Set style inside editor's canvas. This method overrides actual style
  33098. * @param {Object|string} style CSS string or style model
  33099. * @return {this}
  33100. * @private
  33101. */
  33102. setStyle: function setStyle(style) {
  33103. var rules = this.get('CssComposer').getAll();
  33104. for (var i = 0, len = rules.length; i < len; i++) {
  33105. rules.pop();
  33106. }
  33107. rules.add(style);
  33108. return this;
  33109. },
  33110. /**
  33111. * Returns rules/style model from the editor's canvas
  33112. * @return {Rules}
  33113. * @private
  33114. */
  33115. getStyle: function getStyle() {
  33116. return this.get('CssComposer').getAll();
  33117. },
  33118. /**
  33119. * Change the selector state
  33120. * @param {String} value State value
  33121. * @returns {this}
  33122. */
  33123. setState: function setState(value) {
  33124. this.set('state', value);
  33125. return this;
  33126. },
  33127. /**
  33128. * Get the current selector state
  33129. * @returns {String}
  33130. */
  33131. getState: function getState() {
  33132. return this.get('state');
  33133. },
  33134. /**
  33135. * Returns HTML built inside canvas
  33136. * @return {string} HTML string
  33137. * @private
  33138. */
  33139. getHtml: function getHtml() {
  33140. var config = this.config;
  33141. var exportWrapper = config.exportWrapper;
  33142. var wrapperIsBody = config.wrapperIsBody;
  33143. var js = config.jsInHtml ? this.getJs() : '';
  33144. var wrp = this.get('DomComponents').getComponent();
  33145. var html = this.get('CodeManager').getCode(wrp, 'html', {
  33146. exportWrapper: exportWrapper,
  33147. wrapperIsBody: wrapperIsBody
  33148. });
  33149. html += js ? "<script>".concat(js, "</script>") : '';
  33150. return html;
  33151. },
  33152. /**
  33153. * Returns CSS built inside canvas
  33154. * @param {Object} [opts={}] Options
  33155. * @return {string} CSS string
  33156. * @private
  33157. */
  33158. getCss: function getCss() {
  33159. var opts = arguments.length > 0 && arguments[0] !== undefined ? arguments[0] : {};
  33160. var config = this.config;
  33161. var wrapperIsBody = config.wrapperIsBody;
  33162. var avoidProt = opts.avoidProtected;
  33163. var keepUnusedStyles = !Object(underscore__WEBPACK_IMPORTED_MODULE_1__["isUndefined"])(opts.keepUnusedStyles) ? opts.keepUnusedStyles : config.keepUnusedStyles;
  33164. var cssc = this.get('CssComposer');
  33165. var wrp = this.get('DomComponents').getComponent();
  33166. var protCss = !avoidProt ? config.protectedCss : '';
  33167. return protCss + this.get('CodeManager').getCode(wrp, 'css', {
  33168. cssc: cssc,
  33169. wrapperIsBody: wrapperIsBody,
  33170. keepUnusedStyles: keepUnusedStyles
  33171. });
  33172. },
  33173. /**
  33174. * Returns JS of all components
  33175. * @return {string} JS string
  33176. * @private
  33177. */
  33178. getJs: function getJs() {
  33179. var wrp = this.get('DomComponents').getWrapper();
  33180. return this.get('CodeManager').getCode(wrp, 'js').trim();
  33181. },
  33182. /**
  33183. * Store data to the current storage
  33184. * @param {Function} clb Callback function
  33185. * @return {Object} Stored data
  33186. * @private
  33187. */
  33188. store: function store(clb) {
  33189. var _this8 = this;
  33190. var sm = this.get('StorageManager');
  33191. var store = {};
  33192. if (!sm) return; // Fetch what to store
  33193. this.get('storables').forEach(function (m) {
  33194. var obj = m.store(1);
  33195. for (var el in obj) {
  33196. store[el] = obj[el];
  33197. }
  33198. });
  33199. sm.store(store, function (res) {
  33200. clb && clb(res);
  33201. _this8.set('changesCount', 0);
  33202. _this8.trigger('storage:store', store);
  33203. });
  33204. return store;
  33205. },
  33206. /**
  33207. * Load data from the current storage
  33208. * @param {Function} clb Callback function
  33209. * @private
  33210. */
  33211. load: function load() {
  33212. var _this9 = this;
  33213. var clb = arguments.length > 0 && arguments[0] !== undefined ? arguments[0] : null;
  33214. this.getCacheLoad(1, function (res) {
  33215. _this9.get('storables').forEach(function (module) {
  33216. return module.load(res);
  33217. });
  33218. clb && clb(res);
  33219. });
  33220. },
  33221. /**
  33222. * Returns cached load
  33223. * @param {Boolean} force Force to reload
  33224. * @param {Function} clb Callback function
  33225. * @return {Object}
  33226. * @private
  33227. */
  33228. getCacheLoad: function getCacheLoad(force, clb) {
  33229. var _this10 = this;
  33230. if (this.cacheLoad && !force) return this.cacheLoad;
  33231. var sm = this.get('StorageManager');
  33232. var load = [];
  33233. if (!sm) return {};
  33234. this.get('storables').forEach(function (m) {
  33235. var key = m.storageKey;
  33236. key = Object(underscore__WEBPACK_IMPORTED_MODULE_1__["isFunction"])(key) ? key() : key;
  33237. var keys = Object(underscore__WEBPACK_IMPORTED_MODULE_1__["isArray"])(key) ? key : [key];
  33238. keys.forEach(function (k) {
  33239. return load.push(k);
  33240. });
  33241. });
  33242. sm.load(load, function (res) {
  33243. _this10.cacheLoad = res;
  33244. clb && clb(res);
  33245. setTimeout(function () {
  33246. return _this10.trigger('storage:load', res);
  33247. });
  33248. });
  33249. },
  33250. /**
  33251. * Returns device model by name
  33252. * @return {Device|null}
  33253. * @private
  33254. */
  33255. getDeviceModel: function getDeviceModel() {
  33256. var name = this.get('device');
  33257. return this.get('DeviceManager').get(name);
  33258. },
  33259. /**
  33260. * Run default command if setted
  33261. * @param {Object} [opts={}] Options
  33262. * @private
  33263. */
  33264. runDefault: function runDefault() {
  33265. var opts = arguments.length > 0 && arguments[0] !== undefined ? arguments[0] : {};
  33266. var command = this.get('Commands').get(this.config.defaultCommand);
  33267. if (!command || this.defaultRunning) return;
  33268. command.stop(this, this, opts);
  33269. command.run(this, this, opts);
  33270. this.defaultRunning = 1;
  33271. },
  33272. /**
  33273. * Stop default command
  33274. * @param {Object} [opts={}] Options
  33275. * @private
  33276. */
  33277. stopDefault: function stopDefault() {
  33278. var opts = arguments.length > 0 && arguments[0] !== undefined ? arguments[0] : {};
  33279. var commands = this.get('Commands');
  33280. var command = commands.get(this.config.defaultCommand);
  33281. if (!command) return;
  33282. command.stop(this, this, opts);
  33283. this.defaultRunning = 0;
  33284. },
  33285. /**
  33286. * Update canvas dimensions and refresh data useful for tools positioning
  33287. * @private
  33288. */
  33289. refreshCanvas: function refreshCanvas() {
  33290. this.set('canvasOffset', null);
  33291. this.set('canvasOffset', this.get('Canvas').getOffset());
  33292. },
  33293. /**
  33294. * Clear all selected stuf inside the window, sometimes is useful to call before
  33295. * doing some dragging opearation
  33296. * @param {Window} win If not passed the current one will be used
  33297. * @private
  33298. */
  33299. clearSelection: function clearSelection(win) {
  33300. var w = win || window;
  33301. w.getSelection().removeAllRanges();
  33302. },
  33303. /**
  33304. * Get the current media text
  33305. * @return {string}
  33306. */
  33307. getCurrentMedia: function getCurrentMedia() {
  33308. var config = this.config;
  33309. var device = this.getDeviceModel();
  33310. var condition = config.mediaCondition;
  33311. var preview = config.devicePreviewMode;
  33312. var width = device && device.get('widthMedia');
  33313. return device && width && !preview ? "(".concat(condition, ": ").concat(width, ")") : '';
  33314. },
  33315. /**
  33316. * Return the component wrapper
  33317. * @return {Component}
  33318. */
  33319. getWrapper: function getWrapper() {
  33320. return this.get('DomComponents').getWrapper();
  33321. },
  33322. setCurrentFrame: function setCurrentFrame(frameView) {
  33323. return this.set('currentFrame', frameView);
  33324. },
  33325. getCurrentFrame: function getCurrentFrame() {
  33326. return this.get('currentFrame');
  33327. },
  33328. getCurrentFrameModel: function getCurrentFrameModel() {
  33329. return (this.getCurrentFrame() || {}).model;
  33330. },
  33331. /**
  33332. * Return the count of changes made to the content and not yet stored.
  33333. * This count resets at any `store()`
  33334. * @return {number}
  33335. */
  33336. getDirtyCount: function getDirtyCount() {
  33337. return this.get('changesCount');
  33338. },
  33339. getZoomDecimal: function getZoomDecimal() {
  33340. return this.get('Canvas').getZoomDecimal();
  33341. },
  33342. getZoomMultiplier: function getZoomMultiplier() {
  33343. return this.get('Canvas').getZoomMultiplier();
  33344. },
  33345. setDragMode: function setDragMode(value) {
  33346. return this.set('dmode', value);
  33347. },
  33348. t: function t() {
  33349. var _this$get;
  33350. return (_this$get = this.get('I18n')).t.apply(_this$get, arguments);
  33351. },
  33352. /**
  33353. * Returns true if the editor is in absolute mode
  33354. * @returns {Boolean}
  33355. */
  33356. inAbsoluteMode: function inAbsoluteMode() {
  33357. return this.get('dmode') === 'absolute';
  33358. },
  33359. /**
  33360. * Destroy editor
  33361. */
  33362. destroyAll: function destroyAll() {
  33363. var config = this.config;
  33364. var editor = this.getEditor();
  33365. var _ref = config.grapesjs || {},
  33366. _ref$editors = _ref.editors,
  33367. editors = _ref$editors === void 0 ? [] : _ref$editors;
  33368. var _this$attributes = this.attributes,
  33369. DomComponents = _this$attributes.DomComponents,
  33370. CssComposer = _this$attributes.CssComposer,
  33371. UndoManager = _this$attributes.UndoManager,
  33372. Panels = _this$attributes.Panels,
  33373. Canvas = _this$attributes.Canvas,
  33374. Keymaps = _this$attributes.Keymaps,
  33375. RichTextEditor = _this$attributes.RichTextEditor;
  33376. this.stopDefault();
  33377. DomComponents.clear();
  33378. CssComposer.clear();
  33379. UndoManager.clear().removeAll();
  33380. Panels.getPanels().reset();
  33381. Canvas.getCanvasView().remove();
  33382. Keymaps.removeAll();
  33383. RichTextEditor.destroy();
  33384. this.view.remove();
  33385. this.stopListening();
  33386. this.clear({
  33387. silent: true
  33388. });
  33389. this.destroyed = 1;
  33390. editors.splice(editors.indexOf(editor), 1);
  33391. Object(cash_dom__WEBPACK_IMPORTED_MODULE_2__["default"])(config.el).empty().attr(this.attrsOrig);
  33392. },
  33393. setEditing: function setEditing(value) {
  33394. this.set('editing', value);
  33395. return this;
  33396. },
  33397. isEditing: function isEditing() {
  33398. return !!this.get('editing');
  33399. },
  33400. log: function log(msg) {
  33401. var opts = arguments.length > 1 && arguments[1] !== undefined ? arguments[1] : {};
  33402. var ns = opts.ns,
  33403. _opts$level = opts.level,
  33404. level = _opts$level === void 0 ? 'debug' : _opts$level;
  33405. this.trigger('log', msg, opts);
  33406. level && this.trigger("log:".concat(level), msg, opts);
  33407. if (ns) {
  33408. var logNs = "log-".concat(ns);
  33409. this.trigger(logNs, msg, opts);
  33410. level && this.trigger("".concat(logNs, ":").concat(level), msg, opts);
  33411. }
  33412. },
  33413. logInfo: function logInfo(msg, opts) {
  33414. this.log(msg, _objectSpread({}, opts, {
  33415. level: 'info'
  33416. }));
  33417. },
  33418. logWarning: function logWarning(msg, opts) {
  33419. this.log(msg, _objectSpread({}, opts, {
  33420. level: 'warning'
  33421. }));
  33422. },
  33423. logError: function logError(msg, opts) {
  33424. this.log(msg, _objectSpread({}, opts, {
  33425. level: 'error'
  33426. }));
  33427. },
  33428. initBaseColorPicker: function initBaseColorPicker(el) {
  33429. var opts = arguments.length > 1 && arguments[1] !== undefined ? arguments[1] : {};
  33430. var config = this.getConfig();
  33431. var _config$colorPicker = config.colorPicker,
  33432. colorPicker = _config$colorPicker === void 0 ? {} : _config$colorPicker;
  33433. var elToAppend = config.el;
  33434. var ppfx = config.stylePrefix;
  33435. return Object(cash_dom__WEBPACK_IMPORTED_MODULE_2__["default"])(el).spectrum(_objectSpread({
  33436. containerClassName: "".concat(ppfx, "one-bg ").concat(ppfx, "two-color"),
  33437. appendTo: elToAppend || 'body',
  33438. maxSelectionSize: 8,
  33439. showPalette: true,
  33440. palette: [],
  33441. showAlpha: true,
  33442. chooseText: 'Ok',
  33443. cancelText: '⨯'
  33444. }, opts, {}, colorPicker));
  33445. },
  33446. /**
  33447. * Set/get data from the HTMLElement
  33448. * @param {HTMLElement} el
  33449. * @param {string} name Data name
  33450. * @param {any} value Date value
  33451. * @return {any}
  33452. * @private
  33453. */
  33454. data: function data(el, name, value) {
  33455. var varName = '_gjs-data';
  33456. if (!el[varName]) {
  33457. el[varName] = {};
  33458. }
  33459. if (Object(underscore__WEBPACK_IMPORTED_MODULE_1__["isUndefined"])(value)) {
  33460. return el[varName][name];
  33461. } else {
  33462. el[varName][name] = value;
  33463. }
  33464. }
  33465. }));
  33466. /***/ }),
  33467. /***/ "./src/editor/view/EditorView.js":
  33468. /*!***************************************!*\
  33469. !*** ./src/editor/view/EditorView.js ***!
  33470. \***************************************/
  33471. /*! exports provided: default */
  33472. /***/ (function(module, __webpack_exports__, __webpack_require__) {
  33473. "use strict";
  33474. __webpack_require__.r(__webpack_exports__);
  33475. /* harmony import */ var backbone__WEBPACK_IMPORTED_MODULE_0__ = __webpack_require__(/*! backbone */ "./node_modules/backbone/backbone.js");
  33476. /* harmony import */ var backbone__WEBPACK_IMPORTED_MODULE_0___default = /*#__PURE__*/__webpack_require__.n(backbone__WEBPACK_IMPORTED_MODULE_0__);
  33477. /* harmony import */ var utils_mixins__WEBPACK_IMPORTED_MODULE_1__ = __webpack_require__(/*! utils/mixins */ "./src/utils/mixins.js");
  33478. var $ = backbone__WEBPACK_IMPORTED_MODULE_0___default.a.$;
  33479. /* harmony default export */ __webpack_exports__["default"] = (backbone__WEBPACK_IMPORTED_MODULE_0___default.a.View.extend({
  33480. initialize: function initialize() {
  33481. var _this = this;
  33482. var model = this.model;
  33483. model.view = this;
  33484. this.conf = model.config;
  33485. this.pn = model.get('Panels');
  33486. this.cv = model.get('Canvas');
  33487. model.on('loaded', function () {
  33488. _this.pn.active();
  33489. _this.pn.disableButtons();
  33490. setTimeout(function () {
  33491. model.runDefault();
  33492. model.trigger('load', model.get('Editor'));
  33493. });
  33494. });
  33495. },
  33496. render: function render() {
  33497. var model = this.model,
  33498. $el = this.$el,
  33499. conf = this.conf;
  33500. var pfx = conf.stylePrefix;
  33501. var contEl = $(conf.el || "body ".concat(conf.container));
  33502. Object(utils_mixins__WEBPACK_IMPORTED_MODULE_1__["appendStyles"])(conf.cssIcons, {
  33503. unique: 1,
  33504. prepand: 1
  33505. });
  33506. $el.empty();
  33507. if (conf.width) contEl.css('width', conf.width);
  33508. if (conf.height) contEl.css('height', conf.height);
  33509. $el.append(this.cv.render());
  33510. $el.append(this.pn.render());
  33511. $el.attr('class', "".concat(pfx, "editor ").concat(pfx, "one-bg ").concat(pfx, "two-color"));
  33512. contEl.addClass("".concat(pfx, "editor-cont")).empty().append($el);
  33513. return this;
  33514. }
  33515. }));
  33516. /***/ }),
  33517. /***/ "./src/i18n/config.js":
  33518. /*!****************************!*\
  33519. !*** ./src/i18n/config.js ***!
  33520. \****************************/
  33521. /*! exports provided: default */
  33522. /***/ (function(module, __webpack_exports__, __webpack_require__) {
  33523. "use strict";
  33524. __webpack_require__.r(__webpack_exports__);
  33525. /* harmony import */ var _locale_en__WEBPACK_IMPORTED_MODULE_0__ = __webpack_require__(/*! ./locale/en */ "./src/i18n/locale/en.js");
  33526. /* harmony default export */ __webpack_exports__["default"] = ({
  33527. // Locale value
  33528. locale: 'en',
  33529. // Fallback locale
  33530. localeFallback: 'en',
  33531. // Detect locale by checking browser language
  33532. detectLocale: 1,
  33533. // Show warnings when some of the i18n resources are missing
  33534. debug: 0,
  33535. // Messages to translate
  33536. messages: {
  33537. en: _locale_en__WEBPACK_IMPORTED_MODULE_0__["default"]
  33538. }
  33539. });
  33540. /***/ }),
  33541. /***/ "./src/i18n/index.js":
  33542. /*!***************************!*\
  33543. !*** ./src/i18n/index.js ***!
  33544. \***************************/
  33545. /*! exports provided: default */
  33546. /***/ (function(module, __webpack_exports__, __webpack_require__) {
  33547. "use strict";
  33548. __webpack_require__.r(__webpack_exports__);
  33549. /* harmony import */ var _babel_runtime_helpers_defineProperty__WEBPACK_IMPORTED_MODULE_0__ = __webpack_require__(/*! @babel/runtime/helpers/defineProperty */ "./node_modules/@babel/runtime/helpers/defineProperty.js");
  33550. /* harmony import */ var _babel_runtime_helpers_defineProperty__WEBPACK_IMPORTED_MODULE_0___default = /*#__PURE__*/__webpack_require__.n(_babel_runtime_helpers_defineProperty__WEBPACK_IMPORTED_MODULE_0__);
  33551. /* harmony import */ var _babel_runtime_helpers_typeof__WEBPACK_IMPORTED_MODULE_1__ = __webpack_require__(/*! @babel/runtime/helpers/typeof */ "./node_modules/@babel/runtime/helpers/typeof.js");
  33552. /* harmony import */ var _babel_runtime_helpers_typeof__WEBPACK_IMPORTED_MODULE_1___default = /*#__PURE__*/__webpack_require__.n(_babel_runtime_helpers_typeof__WEBPACK_IMPORTED_MODULE_1__);
  33553. /* harmony import */ var underscore__WEBPACK_IMPORTED_MODULE_2__ = __webpack_require__(/*! underscore */ "./node_modules/underscore/underscore.js");
  33554. /* harmony import */ var underscore__WEBPACK_IMPORTED_MODULE_2___default = /*#__PURE__*/__webpack_require__.n(underscore__WEBPACK_IMPORTED_MODULE_2__);
  33555. /* harmony import */ var _config__WEBPACK_IMPORTED_MODULE_3__ = __webpack_require__(/*! ./config */ "./src/i18n/config.js");
  33556. function ownKeys(object, enumerableOnly) { var keys = Object.keys(object); if (Object.getOwnPropertySymbols) { var symbols = Object.getOwnPropertySymbols(object); if (enumerableOnly) symbols = symbols.filter(function (sym) { return Object.getOwnPropertyDescriptor(object, sym).enumerable; }); keys.push.apply(keys, symbols); } return keys; }
  33557. function _objectSpread(target) { for (var i = 1; i < arguments.length; i++) { var source = arguments[i] != null ? arguments[i] : {}; if (i % 2) { ownKeys(source, true).forEach(function (key) { _babel_runtime_helpers_defineProperty__WEBPACK_IMPORTED_MODULE_0___default()(target, key, source[key]); }); } else if (Object.getOwnPropertyDescriptors) { Object.defineProperties(target, Object.getOwnPropertyDescriptors(source)); } else { ownKeys(source).forEach(function (key) { Object.defineProperty(target, key, Object.getOwnPropertyDescriptor(source, key)); }); } } return target; }
  33558. /**
  33559. * You can customize the initial state of the module from the editor initialization, by passing the following [Configuration Object](https://github.com/artf/grapesjs/blob/master/src/i18n/config.js)
  33560. * ```js
  33561. * const editor = grapesjs.init({
  33562. * i18n: {
  33563. * locale: 'en',
  33564. * localeFallback: 'en',
  33565. * messages: {
  33566. * it: { hello: 'Ciao', ... },
  33567. * ...
  33568. * }
  33569. * }
  33570. * })
  33571. * ```
  33572. *
  33573. * Once the editor is instantiated you can use its API. Before using these methods you should get the module from the instance
  33574. *
  33575. * ```js
  33576. * const i18n = editor.I18n;
  33577. * ```
  33578. *
  33579. * ### Events
  33580. * * `i18n:add` - New set of messages is added
  33581. * * `i18n:update` - The set of messages is updated
  33582. * * `i18n:locale` - Locale changed
  33583. *
  33584. * @module I18n
  33585. */
  33586. var isObj = function isObj(el) {
  33587. return !Array.isArray(el) && el !== null && _babel_runtime_helpers_typeof__WEBPACK_IMPORTED_MODULE_1___default()(el) === 'object';
  33588. };
  33589. var deepAssign = function deepAssign() {
  33590. var target = _objectSpread({}, arguments.length <= 0 ? undefined : arguments[0]);
  33591. for (var i = 1; i < arguments.length; i++) {
  33592. var source = _objectSpread({}, i < 0 || arguments.length <= i ? undefined : arguments[i]);
  33593. for (var key in source) {
  33594. var targValue = target[key];
  33595. var srcValue = source[key];
  33596. if (isObj(targValue) && isObj(srcValue)) {
  33597. target[key] = deepAssign(targValue, srcValue);
  33598. } else {
  33599. target[key] = srcValue;
  33600. }
  33601. }
  33602. }
  33603. return target;
  33604. };
  33605. /* harmony default export */ __webpack_exports__["default"] = (function () {
  33606. return {
  33607. name: 'I18n',
  33608. config: _config__WEBPACK_IMPORTED_MODULE_3__["default"],
  33609. /**
  33610. * Initialize module
  33611. * @param {Object} config Configurations
  33612. * @private
  33613. */
  33614. init: function init() {
  33615. var opts = arguments.length > 0 && arguments[0] !== undefined ? arguments[0] : {};
  33616. this.config = _objectSpread({}, _config__WEBPACK_IMPORTED_MODULE_3__["default"], {}, opts, {
  33617. messages: _objectSpread({}, _config__WEBPACK_IMPORTED_MODULE_3__["default"].messages, {}, opts.messages || {})
  33618. });
  33619. if (this.config.detectLocale) {
  33620. this.config.locale = this._localLang();
  33621. }
  33622. this.em = opts.em;
  33623. return this;
  33624. },
  33625. /**
  33626. * Get module configurations
  33627. * @returns {Object} Configuration object
  33628. */
  33629. getConfig: function getConfig() {
  33630. return this.config;
  33631. },
  33632. /**
  33633. * Update current locale
  33634. * @param {String} locale Locale value
  33635. * @returns {this}
  33636. * @example
  33637. * i18n.setLocale('it');
  33638. */
  33639. setLocale: function setLocale(locale) {
  33640. var em = this.em,
  33641. config = this.config;
  33642. var evObj = {
  33643. value: locale,
  33644. valuePrev: config.locale
  33645. };
  33646. em && em.trigger('i18n:locale', evObj);
  33647. config.locale = locale;
  33648. return this;
  33649. },
  33650. /**
  33651. * Get current locale
  33652. * @returns {String} Current locale value
  33653. */
  33654. getLocale: function getLocale() {
  33655. return this.config.locale;
  33656. },
  33657. /**
  33658. * Get all messages
  33659. * @param {String} [lang] Specify the language of messages to return
  33660. * @param {Object} [opts] Options
  33661. * @param {Boolean} [opts.debug] Show warnings in case of missing language
  33662. * @returns {Object}
  33663. * @example
  33664. * i18n.getMessages();
  33665. * // -> { en: { hello: '...' }, ... }
  33666. * i18n.getMessages('en');
  33667. * // -> { hello: '...' }
  33668. */
  33669. getMessages: function getMessages(lang) {
  33670. var opts = arguments.length > 1 && arguments[1] !== undefined ? arguments[1] : {};
  33671. var messages = this.config.messages;
  33672. lang && !messages[lang] && this._debug("'".concat(lang, "' i18n lang not found"), opts);
  33673. return lang ? messages[lang] : messages;
  33674. },
  33675. /**
  33676. * Set new set of messages
  33677. * @param {Object} msg Set of messages
  33678. * @returns {this}
  33679. * @example
  33680. * i18n.getMessages();
  33681. * // -> { en: { msg1: 'Msg 1', msg2: 'Msg 2', } }
  33682. * i18n.setMessages({ en: { msg2: 'Msg 2 up', msg3: 'Msg 3', } });
  33683. * // Set replaced
  33684. * i18n.getMessages();
  33685. * // -> { en: { msg2: 'Msg 2 up', msg3: 'Msg 3', } }
  33686. */
  33687. setMessages: function setMessages(msg) {
  33688. var em = this.em,
  33689. config = this.config;
  33690. config.messages = msg;
  33691. em && em.trigger('i18n:update', msg);
  33692. return this;
  33693. },
  33694. /**
  33695. * Update messages
  33696. * @param {Object} msg Set of messages to add
  33697. * @returns {this}
  33698. * @example
  33699. * i18n.getMessages();
  33700. * // -> { en: { msg1: 'Msg 1', msg2: 'Msg 2', } }
  33701. * i18n.addMessages({ en: { msg2: 'Msg 2 up', msg3: 'Msg 3', } });
  33702. * // Set updated
  33703. * i18n.getMessages();
  33704. * // -> { en: { msg1: 'Msg 1', msg2: 'Msg 2 up', msg3: 'Msg 3', } }
  33705. */
  33706. addMessages: function addMessages(msg) {
  33707. var em = this.em;
  33708. var messages = this.config.messages;
  33709. em && em.trigger('i18n:add', msg);
  33710. this.setMessages(deepAssign(messages, msg));
  33711. return this;
  33712. },
  33713. /**
  33714. * Translate the locale message
  33715. * @param {String} key Label to translate
  33716. * @param {Object} [opts] Options for the translation
  33717. * @param {Object} [opts.params] Params for the translation
  33718. * @param {Boolean} [opts.debug] Show warnings in case of missing resources
  33719. * @returns {String}
  33720. * @example
  33721. * obj.setMessages({
  33722. * en: { msg: 'Msg', msg2: 'Msg {test}'},
  33723. * it: { msg2: 'Msg {test} it'},
  33724. * });
  33725. * obj.t('msg');
  33726. * // -> outputs `Msg`
  33727. * obj.t('msg2', { params: { test: 'hello' } }); // use params
  33728. * // -> outputs `Msg hello`
  33729. * obj.t('msg2', { l: 'it', params: { test: 'hello' } }); // custom local
  33730. * // -> outputs `Msg hello it`
  33731. */
  33732. t: function t(key) {
  33733. var opts = arguments.length > 1 && arguments[1] !== undefined ? arguments[1] : {};
  33734. var config = this.config;
  33735. var param = opts.params || {};
  33736. var locale = opts.l || this.getLocale();
  33737. var localeFlb = opts.lFlb || config.localeFallback;
  33738. var result = this._getMsg(key, locale, opts); // Try with fallback
  33739. if (!result) result = this._getMsg(key, localeFlb, opts);
  33740. !result && this._debug("'".concat(key, "' i18n key not found in '").concat(locale, "' lang"), opts);
  33741. result = result && Object(underscore__WEBPACK_IMPORTED_MODULE_2__["isString"])(result) ? this._addParams(result, param) : result;
  33742. return result;
  33743. },
  33744. _localLang: function _localLang() {
  33745. var nav = window.navigator || {};
  33746. var lang = nav.language || nav.userLanguage;
  33747. return lang ? lang.split('-')[0] : 'en';
  33748. },
  33749. _addParams: function _addParams(str, params) {
  33750. var reg = new RegExp("{([\\w\\d-]*)}", 'g');
  33751. return str.replace(reg, function (m, val) {
  33752. return params[val] || '';
  33753. }).trim();
  33754. },
  33755. _getMsg: function _getMsg(key, locale) {
  33756. var opts = arguments.length > 2 && arguments[2] !== undefined ? arguments[2] : {};
  33757. var msgSet = this.getMessages(locale, opts); // Lang set is missing
  33758. if (!msgSet) return;
  33759. var result = msgSet[key]; // Check for nested getter
  33760. if (!result && key.indexOf('.') > 0) {
  33761. result = key.split('.').reduce(function (lang, key) {
  33762. if (Object(underscore__WEBPACK_IMPORTED_MODULE_2__["isUndefined"])(lang)) return;
  33763. return lang[key];
  33764. }, msgSet);
  33765. }
  33766. return result;
  33767. },
  33768. _debug: function _debug(str) {
  33769. var opts = arguments.length > 1 && arguments[1] !== undefined ? arguments[1] : {};
  33770. var em = this.em,
  33771. config = this.config;
  33772. (opts.debug || config.debug) && em && em.logWarning(str);
  33773. }
  33774. };
  33775. });
  33776. /***/ }),
  33777. /***/ "./src/i18n/locale/en.js":
  33778. /*!*******************************!*\
  33779. !*** ./src/i18n/locale/en.js ***!
  33780. \*******************************/
  33781. /*! exports provided: default */
  33782. /***/ (function(module, __webpack_exports__, __webpack_require__) {
  33783. "use strict";
  33784. __webpack_require__.r(__webpack_exports__);
  33785. var traitInputAttr = {
  33786. placeholder: 'eg. Text here'
  33787. };
  33788. /* harmony default export */ __webpack_exports__["default"] = ({
  33789. assetManager: {
  33790. addButton: 'Add image',
  33791. inputPlh: 'http://path/to/the/image.jpg',
  33792. modalTitle: 'Select Image',
  33793. uploadTitle: 'Drop files here or click to upload'
  33794. },
  33795. // Here just as a reference, GrapesJS core doesn't contain any block,
  33796. // so this should be omitted from other local files
  33797. blockManager: {
  33798. labels: {// 'block-id': 'Block Label',
  33799. },
  33800. categories: {// 'category-id': 'Category Label',
  33801. }
  33802. },
  33803. domComponents: {
  33804. names: {
  33805. '': 'Box',
  33806. wrapper: 'Body',
  33807. text: 'Text',
  33808. comment: 'Comment',
  33809. image: 'Image',
  33810. video: 'Video',
  33811. label: 'Label',
  33812. link: 'Link',
  33813. map: 'Map',
  33814. tfoot: 'Table foot',
  33815. tbody: 'Table body',
  33816. thead: 'Table head',
  33817. table: 'Table',
  33818. row: 'Table row',
  33819. cell: 'Table cell'
  33820. }
  33821. },
  33822. deviceManager: {
  33823. device: 'Device',
  33824. devices: {
  33825. desktop: 'Desktop',
  33826. tablet: 'Tablet',
  33827. mobileLandscape: 'Mobile Landscape',
  33828. mobilePortrait: 'Mobile Portrait'
  33829. }
  33830. },
  33831. panels: {
  33832. buttons: {
  33833. titles: {
  33834. preview: 'Preview',
  33835. fullscreen: 'Fullscreen',
  33836. 'sw-visibility': 'View components',
  33837. 'export-template': 'View code',
  33838. 'open-sm': 'Open Style Manager',
  33839. 'open-tm': 'Settings',
  33840. 'open-layers': 'Open Layer Manager',
  33841. 'open-blocks': 'Open Blocks'
  33842. }
  33843. }
  33844. },
  33845. selectorManager: {
  33846. label: 'Classes',
  33847. selected: 'Selected',
  33848. emptyState: '- State -',
  33849. states: {
  33850. hover: 'Hover',
  33851. active: 'Click',
  33852. 'nth-of-type(2n)': 'Even/Odd'
  33853. }
  33854. },
  33855. styleManager: {
  33856. empty: 'Select an element before using Style Manager',
  33857. layer: 'Layer',
  33858. fileButton: 'Images',
  33859. sectors: {
  33860. general: 'General',
  33861. layout: 'Layout',
  33862. typography: 'Typography',
  33863. decorations: 'Decorations',
  33864. extra: 'Extra',
  33865. flex: 'Flex',
  33866. dimension: 'Dimension'
  33867. },
  33868. // The core library generates the name by their `property` name
  33869. properties: {// float: 'Float',
  33870. }
  33871. },
  33872. traitManager: {
  33873. empty: 'Select an element before using Trait Manager',
  33874. label: 'Component settings',
  33875. traits: {
  33876. // The core library generates the name by their `name` property
  33877. labels: {// id: 'Id',
  33878. // alt: 'Alt',
  33879. // title: 'Title',
  33880. // href: 'Href',
  33881. },
  33882. // In a simple trait, like text input, these are used on input attributes
  33883. attributes: {
  33884. id: traitInputAttr,
  33885. alt: traitInputAttr,
  33886. title: traitInputAttr,
  33887. href: {
  33888. placeholder: 'eg. https://google.com'
  33889. }
  33890. },
  33891. // In a trait like select, these are used to translate option names
  33892. options: {
  33893. target: {
  33894. false: 'This window',
  33895. _blank: 'New window'
  33896. }
  33897. }
  33898. }
  33899. }
  33900. });
  33901. /***/ }),
  33902. /***/ "./src/index.js":
  33903. /*!**********************!*\
  33904. !*** ./src/index.js ***!
  33905. \**********************/
  33906. /*! exports provided: default */
  33907. /***/ (function(module, __webpack_exports__, __webpack_require__) {
  33908. "use strict";
  33909. __webpack_require__.r(__webpack_exports__);
  33910. /* harmony import */ var _babel_runtime_helpers_defineProperty__WEBPACK_IMPORTED_MODULE_0__ = __webpack_require__(/*! @babel/runtime/helpers/defineProperty */ "./node_modules/@babel/runtime/helpers/defineProperty.js");
  33911. /* harmony import */ var _babel_runtime_helpers_defineProperty__WEBPACK_IMPORTED_MODULE_0___default = /*#__PURE__*/__webpack_require__.n(_babel_runtime_helpers_defineProperty__WEBPACK_IMPORTED_MODULE_0__);
  33912. /* harmony import */ var cash_dom__WEBPACK_IMPORTED_MODULE_1__ = __webpack_require__(/*! cash-dom */ "./node_modules/cash-dom/dist/cash.esm.js");
  33913. /* harmony import */ var _editor__WEBPACK_IMPORTED_MODULE_2__ = __webpack_require__(/*! ./editor */ "./src/editor/index.js");
  33914. /* harmony import */ var underscore__WEBPACK_IMPORTED_MODULE_3__ = __webpack_require__(/*! underscore */ "./node_modules/underscore/underscore.js");
  33915. /* harmony import */ var underscore__WEBPACK_IMPORTED_MODULE_3___default = /*#__PURE__*/__webpack_require__.n(underscore__WEBPACK_IMPORTED_MODULE_3__);
  33916. /* harmony import */ var utils_polyfills__WEBPACK_IMPORTED_MODULE_4__ = __webpack_require__(/*! utils/polyfills */ "./src/utils/polyfills.js");
  33917. /* harmony import */ var _plugin_manager__WEBPACK_IMPORTED_MODULE_5__ = __webpack_require__(/*! ./plugin_manager */ "./src/plugin_manager/index.js");
  33918. function ownKeys(object, enumerableOnly) { var keys = Object.keys(object); if (Object.getOwnPropertySymbols) { var symbols = Object.getOwnPropertySymbols(object); if (enumerableOnly) symbols = symbols.filter(function (sym) { return Object.getOwnPropertyDescriptor(object, sym).enumerable; }); keys.push.apply(keys, symbols); } return keys; }
  33919. function _objectSpread(target) { for (var i = 1; i < arguments.length; i++) { var source = arguments[i] != null ? arguments[i] : {}; if (i % 2) { ownKeys(source, true).forEach(function (key) { _babel_runtime_helpers_defineProperty__WEBPACK_IMPORTED_MODULE_0___default()(target, key, source[key]); }); } else if (Object.getOwnPropertyDescriptors) { Object.defineProperties(target, Object.getOwnPropertyDescriptors(source)); } else { ownKeys(source).forEach(function (key) { Object.defineProperty(target, key, Object.getOwnPropertyDescriptor(source, key)); }); } } return target; }
  33920. Object(utils_polyfills__WEBPACK_IMPORTED_MODULE_4__["default"])();
  33921. var plugins = new _plugin_manager__WEBPACK_IMPORTED_MODULE_5__["default"]();
  33922. var editors = [];
  33923. var defaultConfig = {
  33924. // If true renders editor on init
  33925. autorender: 1,
  33926. // Array of plugins to init
  33927. plugins: [],
  33928. // Custom options for plugins
  33929. pluginsOpts: {}
  33930. };
  33931. /* harmony default export */ __webpack_exports__["default"] = ({
  33932. $: cash_dom__WEBPACK_IMPORTED_MODULE_1__["default"],
  33933. editors: editors,
  33934. plugins: plugins,
  33935. // Will be replaced on build
  33936. version: '0.16.12',
  33937. /**
  33938. * Initialize the editor with passed options
  33939. * @param {Object} config Configuration object
  33940. * @param {string|HTMLElement} config.container Selector which indicates where render the editor
  33941. * @param {Boolean} [config.autorender=true] If true, auto-render the content
  33942. * @param {Array} [config.plugins=[]] Array of plugins to execute on start
  33943. * @param {Object} [config.pluginsOpts={}] Custom options for plugins
  33944. * @return {Editor} Editor instance
  33945. * @example
  33946. * var editor = grapesjs.init({
  33947. * container: '#myeditor',
  33948. * components: '<article class="hello">Hello world</article>',
  33949. * style: '.hello{color: red}',
  33950. * })
  33951. */
  33952. init: function init() {
  33953. var config = arguments.length > 0 && arguments[0] !== undefined ? arguments[0] : {};
  33954. var els = config.container;
  33955. if (!els) throw new Error("'container' is required");
  33956. config = _objectSpread({}, defaultConfig, {}, config, {
  33957. grapesjs: this
  33958. });
  33959. config.el = Object(underscore__WEBPACK_IMPORTED_MODULE_3__["isElement"])(els) ? els : document.querySelector(els);
  33960. var editor = new _editor__WEBPACK_IMPORTED_MODULE_2__["default"](config).init(); // Load plugins
  33961. config.plugins.forEach(function (pluginId) {
  33962. var plugin = plugins.get(pluginId);
  33963. var plgOptions = config.pluginsOpts[pluginId] || {}; // Try to search in global context
  33964. if (!plugin) {
  33965. var wplg = window[pluginId];
  33966. plugin = wplg && wplg.default ? wplg.default : wplg;
  33967. }
  33968. if (plugin) {
  33969. plugin(editor, plgOptions);
  33970. } else if (Object(underscore__WEBPACK_IMPORTED_MODULE_3__["isFunction"])(pluginId)) {
  33971. pluginId(editor, plgOptions);
  33972. } else {
  33973. console.warn("Plugin ".concat(pluginId, " not found"));
  33974. }
  33975. }); // Execute `onLoad` on modules once all plugins are initialized.
  33976. // A plugin might have extended/added some custom type so this
  33977. // is a good point to load stuff like components, css rules, etc.
  33978. editor.getModel().loadOnStart();
  33979. config.autorender && editor.render();
  33980. editors.push(editor);
  33981. return editor;
  33982. }
  33983. });
  33984. /***/ }),
  33985. /***/ "./src/keymaps/index.js":
  33986. /*!******************************!*\
  33987. !*** ./src/keymaps/index.js ***!
  33988. \******************************/
  33989. /*! exports provided: default */
  33990. /***/ (function(module, __webpack_exports__, __webpack_require__) {
  33991. "use strict";
  33992. __webpack_require__.r(__webpack_exports__);
  33993. /* harmony import */ var _babel_runtime_helpers_typeof__WEBPACK_IMPORTED_MODULE_0__ = __webpack_require__(/*! @babel/runtime/helpers/typeof */ "./node_modules/@babel/runtime/helpers/typeof.js");
  33994. /* harmony import */ var _babel_runtime_helpers_typeof__WEBPACK_IMPORTED_MODULE_0___default = /*#__PURE__*/__webpack_require__.n(_babel_runtime_helpers_typeof__WEBPACK_IMPORTED_MODULE_0__);
  33995. /* harmony import */ var _babel_runtime_helpers_defineProperty__WEBPACK_IMPORTED_MODULE_1__ = __webpack_require__(/*! @babel/runtime/helpers/defineProperty */ "./node_modules/@babel/runtime/helpers/defineProperty.js");
  33996. /* harmony import */ var _babel_runtime_helpers_defineProperty__WEBPACK_IMPORTED_MODULE_1___default = /*#__PURE__*/__webpack_require__.n(_babel_runtime_helpers_defineProperty__WEBPACK_IMPORTED_MODULE_1__);
  33997. /* harmony import */ var underscore__WEBPACK_IMPORTED_MODULE_2__ = __webpack_require__(/*! underscore */ "./node_modules/underscore/underscore.js");
  33998. /* harmony import */ var underscore__WEBPACK_IMPORTED_MODULE_2___default = /*#__PURE__*/__webpack_require__.n(underscore__WEBPACK_IMPORTED_MODULE_2__);
  33999. /* harmony import */ var keymaster__WEBPACK_IMPORTED_MODULE_3__ = __webpack_require__(/*! keymaster */ "./node_modules/keymaster/keymaster.js");
  34000. /* harmony import */ var keymaster__WEBPACK_IMPORTED_MODULE_3___default = /*#__PURE__*/__webpack_require__.n(keymaster__WEBPACK_IMPORTED_MODULE_3__);
  34001. function ownKeys(object, enumerableOnly) { var keys = Object.keys(object); if (Object.getOwnPropertySymbols) { var symbols = Object.getOwnPropertySymbols(object); if (enumerableOnly) symbols = symbols.filter(function (sym) { return Object.getOwnPropertyDescriptor(object, sym).enumerable; }); keys.push.apply(keys, symbols); } return keys; }
  34002. function _objectSpread(target) { for (var i = 1; i < arguments.length; i++) { var source = arguments[i] != null ? arguments[i] : {}; if (i % 2) { ownKeys(source, true).forEach(function (key) { _babel_runtime_helpers_defineProperty__WEBPACK_IMPORTED_MODULE_1___default()(target, key, source[key]); }); } else if (Object.getOwnPropertyDescriptors) { Object.defineProperties(target, Object.getOwnPropertyDescriptors(source)); } else { ownKeys(source).forEach(function (key) { Object.defineProperty(target, key, Object.getOwnPropertyDescriptor(source, key)); }); } } return target; }
  34003. /**
  34004. * You can customize the initial state of the module from the editor initialization
  34005. * ```js
  34006. * const editor = grapesjs.init({
  34007. * keymaps: {
  34008. * // Object of keymaps
  34009. * defaults: {
  34010. * 'your-namespace:keymap-name' {
  34011. * keys: '⌘+z, ctrl+z',
  34012. * handler: 'some-command-id'
  34013. * },
  34014. * ...
  34015. * }
  34016. * }
  34017. * })
  34018. * ```
  34019. *
  34020. * Once the editor is instantiated you can use its API. Before using these methods you should get the module from the instance
  34021. *
  34022. * ```js
  34023. * const keymaps = editor.Keymaps;
  34024. * ```
  34025. *
  34026. * * [getConfig](#getconfig)
  34027. * * [add](#add)
  34028. * * [get](#get)
  34029. * * [getAll](#getAll)
  34030. * * [remove](#remove)
  34031. * * [removeAll](#removeall)
  34032. *
  34033. * @module Keymaps
  34034. */
  34035. /* harmony default export */ __webpack_exports__["default"] = (function () {
  34036. var em;
  34037. var config;
  34038. var keymaps = {};
  34039. var configDef = {
  34040. defaults: {
  34041. 'core:undo': {
  34042. keys: '⌘+z, ctrl+z',
  34043. handler: 'core:undo'
  34044. },
  34045. 'core:redo': {
  34046. keys: '⌘+shift+z, ctrl+shift+z',
  34047. handler: 'core:redo'
  34048. },
  34049. 'core:copy': {
  34050. keys: '⌘+c, ctrl+c',
  34051. handler: 'core:copy'
  34052. },
  34053. 'core:paste': {
  34054. keys: '⌘+v, ctrl+v',
  34055. handler: 'core:paste'
  34056. },
  34057. 'core:component-next': {
  34058. keys: 's',
  34059. handler: 'core:component-next'
  34060. },
  34061. 'core:component-prev': {
  34062. keys: 'w',
  34063. handler: 'core:component-prev'
  34064. },
  34065. 'core:component-enter': {
  34066. keys: 'd',
  34067. handler: 'core:component-enter'
  34068. },
  34069. 'core:component-exit': {
  34070. keys: 'a',
  34071. handler: 'core:component-exit'
  34072. },
  34073. 'core:component-delete': {
  34074. keys: 'backspace, delete',
  34075. handler: 'core:component-delete'
  34076. }
  34077. }
  34078. };
  34079. return {
  34080. keymaster: keymaster__WEBPACK_IMPORTED_MODULE_3___default.a,
  34081. name: 'Keymaps',
  34082. /**
  34083. * Get module configurations
  34084. * @return {Object} Configuration object
  34085. */
  34086. getConfig: function getConfig() {
  34087. return config;
  34088. },
  34089. /**
  34090. * Initialize module
  34091. * @param {Object} config Configurations
  34092. * @private
  34093. */
  34094. init: function init() {
  34095. var opts = arguments.length > 0 && arguments[0] !== undefined ? arguments[0] : {};
  34096. config = _objectSpread({}, configDef, {}, opts);
  34097. em = config.em;
  34098. this.em = em;
  34099. return this;
  34100. },
  34101. onLoad: function onLoad() {
  34102. var defKeys = config.defaults;
  34103. for (var id in defKeys) {
  34104. var value = defKeys[id];
  34105. this.add(id, value.keys, value.handler);
  34106. }
  34107. },
  34108. /**
  34109. * Add new keymap
  34110. * @param {string} id Keymap id
  34111. * @param {string} keys Keymap keys, eg. `ctrl+a`, `⌘+z, ctrl+z`
  34112. * @param {Function|string} handler Keymap handler, might be a function
  34113. * @param {Object} [opts={}] Options
  34114. * @return {Object} Added keymap
  34115. * or just a command id as a string
  34116. * @example
  34117. * // 'ns' is just a custom namespace
  34118. * keymaps.add('ns:my-keymap', '⌘+j, ⌘+u, ctrl+j, alt+u', editor => {
  34119. * console.log('do stuff');
  34120. * });
  34121. * // or
  34122. * keymaps.add('ns:my-keymap', '⌘+s, ctrl+s', 'some-gjs-command');
  34123. *
  34124. * // listen to events
  34125. * editor.on('keymap:emit', (id, shortcut, e) => {
  34126. * // ...
  34127. * })
  34128. */
  34129. add: function add(id, keys, handler) {
  34130. var opts = arguments.length > 3 && arguments[3] !== undefined ? arguments[3] : {};
  34131. var em = this.em;
  34132. var cmd = em.get('Commands');
  34133. var editor = em.getEditor();
  34134. var canvas = em.get('Canvas');
  34135. var keymap = {
  34136. id: id,
  34137. keys: keys,
  34138. handler: handler
  34139. };
  34140. var pk = keymaps[id];
  34141. pk && this.remove(id);
  34142. keymaps[id] = keymap;
  34143. keymaster__WEBPACK_IMPORTED_MODULE_3___default()(keys, function (e, h) {
  34144. // It's safer putting handlers resolution inside the callback
  34145. var opt = {
  34146. event: e,
  34147. h: h
  34148. };
  34149. handler = Object(underscore__WEBPACK_IMPORTED_MODULE_2__["isString"])(handler) ? cmd.get(handler) : handler;
  34150. opts.prevent && canvas.getCanvasView().preventDefault(e);
  34151. var ableTorun = !em.isEditing() && !editor.Canvas.isInputFocused();
  34152. if (ableTorun || opts.force) {
  34153. _babel_runtime_helpers_typeof__WEBPACK_IMPORTED_MODULE_0___default()(handler) == 'object' ? handler.run(editor, 0, opt) : handler(editor, 0, opt);
  34154. var args = [id, h.shortcut, e];
  34155. em.trigger.apply(em, ['keymap:emit'].concat(args));
  34156. em.trigger.apply(em, ["keymap:emit:".concat(id)].concat(args));
  34157. }
  34158. });
  34159. em.trigger('keymap:add', keymap);
  34160. return keymap;
  34161. },
  34162. /**
  34163. * Get the keymap by id
  34164. * @param {string} id Keymap id
  34165. * @return {Object} Keymap object
  34166. * @example
  34167. * keymaps.get('ns:my-keymap');
  34168. * // -> {keys, handler};
  34169. */
  34170. get: function get(id) {
  34171. return keymaps[id];
  34172. },
  34173. /**
  34174. * Get all keymaps
  34175. * @return {Object}
  34176. * @example
  34177. * keymaps.getAll();
  34178. * // -> {id1: {}, id2: {}};
  34179. */
  34180. getAll: function getAll() {
  34181. return keymaps;
  34182. },
  34183. /**
  34184. * Remove the keymap by id
  34185. * @param {string} id Keymap id
  34186. * @return {Object} Removed keymap
  34187. * @example
  34188. * keymaps.remove('ns:my-keymap');
  34189. * // -> {keys, handler};
  34190. */
  34191. remove: function remove(id) {
  34192. var em = this.em;
  34193. var keymap = this.get(id);
  34194. if (keymap) {
  34195. delete keymaps[id];
  34196. keymaster__WEBPACK_IMPORTED_MODULE_3___default.a.unbind(keymap.keys);
  34197. em && em.trigger('keymap:remove', keymap);
  34198. return keymap;
  34199. }
  34200. },
  34201. /**
  34202. * Remove all binded keymaps
  34203. * @return {this}
  34204. */
  34205. removeAll: function removeAll() {
  34206. var _this = this;
  34207. Object.keys(keymaps).forEach(function (keymap) {
  34208. return _this.remove(keymap);
  34209. });
  34210. return this;
  34211. }
  34212. };
  34213. });
  34214. /***/ }),
  34215. /***/ "./src/modal_dialog/config/config.js":
  34216. /*!*******************************************!*\
  34217. !*** ./src/modal_dialog/config/config.js ***!
  34218. \*******************************************/
  34219. /*! exports provided: default */
  34220. /***/ (function(module, __webpack_exports__, __webpack_require__) {
  34221. "use strict";
  34222. __webpack_require__.r(__webpack_exports__);
  34223. /* harmony default export */ __webpack_exports__["default"] = ({
  34224. stylePrefix: 'mdl-',
  34225. title: '',
  34226. content: '',
  34227. backdrop: true
  34228. });
  34229. /***/ }),
  34230. /***/ "./src/modal_dialog/index.js":
  34231. /*!***********************************!*\
  34232. !*** ./src/modal_dialog/index.js ***!
  34233. \***********************************/
  34234. /*! exports provided: default */
  34235. /***/ (function(module, __webpack_exports__, __webpack_require__) {
  34236. "use strict";
  34237. __webpack_require__.r(__webpack_exports__);
  34238. /* harmony import */ var _babel_runtime_helpers_defineProperty__WEBPACK_IMPORTED_MODULE_0__ = __webpack_require__(/*! @babel/runtime/helpers/defineProperty */ "./node_modules/@babel/runtime/helpers/defineProperty.js");
  34239. /* harmony import */ var _babel_runtime_helpers_defineProperty__WEBPACK_IMPORTED_MODULE_0___default = /*#__PURE__*/__webpack_require__.n(_babel_runtime_helpers_defineProperty__WEBPACK_IMPORTED_MODULE_0__);
  34240. /* harmony import */ var _config_config__WEBPACK_IMPORTED_MODULE_1__ = __webpack_require__(/*! ./config/config */ "./src/modal_dialog/config/config.js");
  34241. /* harmony import */ var _model_Modal__WEBPACK_IMPORTED_MODULE_2__ = __webpack_require__(/*! ./model/Modal */ "./src/modal_dialog/model/Modal.js");
  34242. /* harmony import */ var _view_ModalView__WEBPACK_IMPORTED_MODULE_3__ = __webpack_require__(/*! ./view/ModalView */ "./src/modal_dialog/view/ModalView.js");
  34243. function ownKeys(object, enumerableOnly) { var keys = Object.keys(object); if (Object.getOwnPropertySymbols) { var symbols = Object.getOwnPropertySymbols(object); if (enumerableOnly) symbols = symbols.filter(function (sym) { return Object.getOwnPropertyDescriptor(object, sym).enumerable; }); keys.push.apply(keys, symbols); } return keys; }
  34244. function _objectSpread(target) { for (var i = 1; i < arguments.length; i++) { var source = arguments[i] != null ? arguments[i] : {}; if (i % 2) { ownKeys(source, true).forEach(function (key) { _babel_runtime_helpers_defineProperty__WEBPACK_IMPORTED_MODULE_0___default()(target, key, source[key]); }); } else if (Object.getOwnPropertyDescriptors) { Object.defineProperties(target, Object.getOwnPropertyDescriptors(source)); } else { ownKeys(source).forEach(function (key) { Object.defineProperty(target, key, Object.getOwnPropertyDescriptor(source, key)); }); } } return target; }
  34245. /**
  34246. * You can customize the initial state of the module from the editor initialization, by passing the following [Configuration Object](https://github.com/artf/grapesjs/blob/master/src/modal_dialog/config/config.js)
  34247. * ```js
  34248. * const editor = grapesjs.init({
  34249. * modal: {
  34250. * // options
  34251. * }
  34252. * })
  34253. * ```
  34254. *
  34255. * Once the editor is instantiated you can use its API. Before using these methods you should get the module from the instance
  34256. *
  34257. * ```js
  34258. * const modal = editor.Modal;
  34259. * ```
  34260. *
  34261. * * [open](#open)
  34262. * * [close](#close)
  34263. * * [isOpen](#isopen)
  34264. * * [setTitle](#settitle)
  34265. * * [getTitle](#gettitle)
  34266. * * [setContent](#setcontent)
  34267. * * [getContent](#getcontent)
  34268. * * [onceClose](#onceclose)
  34269. * * [onceOpen](#onceopen)
  34270. *
  34271. * @module Modal
  34272. */
  34273. /* harmony default export */ __webpack_exports__["default"] = (function () {
  34274. var c = {};
  34275. var model, modal;
  34276. var triggerEvent = function triggerEvent(enable, em) {
  34277. em && em.trigger("modal:".concat(enable ? 'open' : 'close'));
  34278. };
  34279. return {
  34280. /**
  34281. * Name of the module
  34282. * @type {String}
  34283. * @private
  34284. */
  34285. name: 'Modal',
  34286. getConfig: function getConfig() {
  34287. return c;
  34288. },
  34289. /**
  34290. * Initialize module. Automatically called with a new instance of the editor
  34291. * @param {Object} config Configurations
  34292. * @private
  34293. */
  34294. init: function init() {
  34295. var config = arguments.length > 0 && arguments[0] !== undefined ? arguments[0] : {};
  34296. c = _objectSpread({}, _config_config__WEBPACK_IMPORTED_MODULE_1__["default"], {}, config);
  34297. var em = c.em;
  34298. this.em = em;
  34299. var ppfx = c.pStylePrefix;
  34300. if (ppfx) c.stylePrefix = ppfx + c.stylePrefix;
  34301. model = new _model_Modal__WEBPACK_IMPORTED_MODULE_2__["default"](c);
  34302. model.on('change:open', function (m, enb) {
  34303. return triggerEvent(enb, em);
  34304. });
  34305. modal = new _view_ModalView__WEBPACK_IMPORTED_MODULE_3__["default"]({
  34306. model: model,
  34307. config: c
  34308. });
  34309. return this;
  34310. },
  34311. postRender: function postRender(view) {
  34312. var el = view.model.getConfig().el || view.el;
  34313. this.render().appendTo(el);
  34314. },
  34315. /**
  34316. * Open the modal window
  34317. * @param {Object} [opts={}] Options
  34318. * @param {String|HTMLElement} [opts.title] Title to set for the modal
  34319. * @param {String|HTMLElement} [opts.content] Content to set for the modal
  34320. * @return {this}
  34321. */
  34322. open: function open() {
  34323. var opts = arguments.length > 0 && arguments[0] !== undefined ? arguments[0] : {};
  34324. opts.title && this.setTitle(opts.title);
  34325. opts.content && this.setContent(opts.content);
  34326. modal.show();
  34327. return this;
  34328. },
  34329. /**
  34330. * Close the modal window
  34331. * @return {this}
  34332. */
  34333. close: function close() {
  34334. modal.hide();
  34335. return this;
  34336. },
  34337. /**
  34338. * Execute callback when the modal will be closed.
  34339. * The callback will be called one only time
  34340. * @param {Function} clb
  34341. * @returns {this}
  34342. */
  34343. onceClose: function onceClose(clb) {
  34344. this.em.once('modal:close', clb);
  34345. return this;
  34346. },
  34347. /**
  34348. * Execute callback when the modal will be opened.
  34349. * The callback will be called one only time
  34350. * @param {Function} clb
  34351. * @returns {this}
  34352. */
  34353. onceOpen: function onceOpen(clb) {
  34354. this.em.once('modal:open', clb);
  34355. return this;
  34356. },
  34357. /**
  34358. * Checks if the modal window is open
  34359. * @return {Boolean}
  34360. */
  34361. isOpen: function isOpen() {
  34362. return !!model.get('open');
  34363. },
  34364. /**
  34365. * Set the title to the modal window
  34366. * @param {string} title Title
  34367. * @return {this}
  34368. * @example
  34369. * modal.setTitle('New title');
  34370. */
  34371. setTitle: function setTitle(title) {
  34372. model.set('title', title);
  34373. return this;
  34374. },
  34375. /**
  34376. * Returns the title of the modal window
  34377. * @return {string}
  34378. */
  34379. getTitle: function getTitle() {
  34380. return model.get('title');
  34381. },
  34382. /**
  34383. * Set the content of the modal window
  34384. * @param {string|HTMLElement} content Content
  34385. * @return {this}
  34386. * @example
  34387. * modal.setContent('<div>Some HTML content</div>');
  34388. */
  34389. setContent: function setContent(content) {
  34390. model.set('content', ' ');
  34391. model.set('content', content);
  34392. return this;
  34393. },
  34394. /**
  34395. * Get the content of the modal window
  34396. * @return {string}
  34397. */
  34398. getContent: function getContent() {
  34399. return model.get('content');
  34400. },
  34401. /**
  34402. * Returns content element
  34403. * @return {HTMLElement}
  34404. * @private
  34405. */
  34406. getContentEl: function getContentEl() {
  34407. return modal.getContent().get(0);
  34408. },
  34409. /**
  34410. * Returns modal model
  34411. * @return {Model}
  34412. * @private
  34413. */
  34414. getModel: function getModel() {
  34415. return model;
  34416. },
  34417. /**
  34418. * Render the modal window
  34419. * @return {HTMLElement}
  34420. * @private
  34421. */
  34422. render: function render() {
  34423. return modal.render().$el;
  34424. }
  34425. };
  34426. });
  34427. /***/ }),
  34428. /***/ "./src/modal_dialog/model/Modal.js":
  34429. /*!*****************************************!*\
  34430. !*** ./src/modal_dialog/model/Modal.js ***!
  34431. \*****************************************/
  34432. /*! exports provided: default */
  34433. /***/ (function(module, __webpack_exports__, __webpack_require__) {
  34434. "use strict";
  34435. __webpack_require__.r(__webpack_exports__);
  34436. /* harmony import */ var backbone__WEBPACK_IMPORTED_MODULE_0__ = __webpack_require__(/*! backbone */ "./node_modules/backbone/backbone.js");
  34437. /* harmony import */ var backbone__WEBPACK_IMPORTED_MODULE_0___default = /*#__PURE__*/__webpack_require__.n(backbone__WEBPACK_IMPORTED_MODULE_0__);
  34438. /* harmony default export */ __webpack_exports__["default"] = (backbone__WEBPACK_IMPORTED_MODULE_0___default.a.Model.extend({
  34439. defaults: {
  34440. title: '',
  34441. content: '',
  34442. open: false
  34443. }
  34444. }));
  34445. /***/ }),
  34446. /***/ "./src/modal_dialog/view/ModalView.js":
  34447. /*!********************************************!*\
  34448. !*** ./src/modal_dialog/view/ModalView.js ***!
  34449. \********************************************/
  34450. /*! exports provided: default */
  34451. /***/ (function(module, __webpack_exports__, __webpack_require__) {
  34452. "use strict";
  34453. __webpack_require__.r(__webpack_exports__);
  34454. /* harmony import */ var backbone__WEBPACK_IMPORTED_MODULE_0__ = __webpack_require__(/*! backbone */ "./node_modules/backbone/backbone.js");
  34455. /* harmony import */ var backbone__WEBPACK_IMPORTED_MODULE_0___default = /*#__PURE__*/__webpack_require__.n(backbone__WEBPACK_IMPORTED_MODULE_0__);
  34456. /* harmony default export */ __webpack_exports__["default"] = (backbone__WEBPACK_IMPORTED_MODULE_0___default.a.View.extend({
  34457. template: function template(_ref) {
  34458. var pfx = _ref.pfx,
  34459. ppfx = _ref.ppfx,
  34460. content = _ref.content,
  34461. title = _ref.title;
  34462. return "<div class=\"".concat(pfx, "dialog ").concat(ppfx, "one-bg ").concat(ppfx, "two-color\">\n <div class=\"").concat(pfx, "header\">\n <div class=\"").concat(pfx, "title\">").concat(title, "</div>\n <div class=\"").concat(pfx, "btn-close\" data-close-modal>&Cross;</div>\n </div>\n <div class=\"").concat(pfx, "content\">\n <div id=\"").concat(pfx, "c\">").concat(content, "</div>\n <div style=\"clear:both\"></div>\n </div>\n </div>\n <div class=\"").concat(pfx, "collector\" style=\"display: none\"></div>");
  34463. },
  34464. events: {
  34465. click: 'onClick',
  34466. 'click [data-close-modal]': 'hide'
  34467. },
  34468. initialize: function initialize(o) {
  34469. var model = this.model;
  34470. var config = o.config || {};
  34471. var pfx = config.stylePrefix || '';
  34472. this.config = config;
  34473. this.pfx = pfx;
  34474. this.ppfx = config.pStylePrefix || '';
  34475. this.listenTo(model, 'change:open', this.updateOpen);
  34476. this.listenTo(model, 'change:title', this.updateTitle);
  34477. this.listenTo(model, 'change:content', this.updateContent);
  34478. },
  34479. onClick: function onClick(e) {
  34480. var bkd = this.config.backdrop;
  34481. bkd && e.target === this.el && this.hide();
  34482. },
  34483. /**
  34484. * Returns collector element
  34485. * @return {HTMLElement}
  34486. * @private
  34487. */
  34488. getCollector: function getCollector() {
  34489. if (!this.$collector) this.$collector = this.$el.find('.' + this.pfx + 'collector');
  34490. return this.$collector;
  34491. },
  34492. /**
  34493. * Returns content element
  34494. * @return {HTMLElement}
  34495. * @private
  34496. */
  34497. getContent: function getContent() {
  34498. var pfx = this.pfx;
  34499. if (!this.$content) {
  34500. this.$content = this.$el.find(".".concat(pfx, "content #").concat(pfx, "c"));
  34501. }
  34502. return this.$content;
  34503. },
  34504. /**
  34505. * Returns title element
  34506. * @return {HTMLElement}
  34507. * @private
  34508. */
  34509. getTitle: function getTitle() {
  34510. if (!this.$title) this.$title = this.$el.find('.' + this.pfx + 'title');
  34511. return this.$title.get(0);
  34512. },
  34513. /**
  34514. * Update content
  34515. * @private
  34516. * */
  34517. updateContent: function updateContent() {
  34518. var content = this.getContent();
  34519. var children = content.children();
  34520. var coll = this.getCollector();
  34521. var body = this.model.get('content');
  34522. children.length && coll.append(children);
  34523. content.empty().append(body);
  34524. },
  34525. /**
  34526. * Update title
  34527. * @private
  34528. * */
  34529. updateTitle: function updateTitle() {
  34530. var title = this.getTitle();
  34531. if (title) title.innerHTML = this.model.get('title');
  34532. },
  34533. /**
  34534. * Update open
  34535. * @private
  34536. * */
  34537. updateOpen: function updateOpen() {
  34538. this.el.style.display = this.model.get('open') ? '' : 'none';
  34539. },
  34540. /**
  34541. * Hide modal
  34542. * @private
  34543. * */
  34544. hide: function hide() {
  34545. this.model.set('open', 0);
  34546. },
  34547. /**
  34548. * Show modal
  34549. * @private
  34550. * */
  34551. show: function show() {
  34552. this.model.set('open', 1);
  34553. },
  34554. render: function render() {
  34555. var el = this.$el;
  34556. var pfx = this.pfx;
  34557. var ppfx = this.ppfx;
  34558. var obj = this.model.toJSON();
  34559. obj.pfx = this.pfx;
  34560. obj.ppfx = this.ppfx;
  34561. el.html(this.template(obj));
  34562. el.attr('class', "".concat(pfx, "container"));
  34563. this.updateOpen();
  34564. return this;
  34565. }
  34566. }));
  34567. /***/ }),
  34568. /***/ "./src/navigator/config/config.js":
  34569. /*!****************************************!*\
  34570. !*** ./src/navigator/config/config.js ***!
  34571. \****************************************/
  34572. /*! exports provided: default */
  34573. /***/ (function(module, __webpack_exports__, __webpack_require__) {
  34574. "use strict";
  34575. __webpack_require__.r(__webpack_exports__);
  34576. /* harmony default export */ __webpack_exports__["default"] = ({
  34577. stylePrefix: '',
  34578. // Specify the element to use as a container, string (query) or HTMLElement
  34579. // With the empty value, nothing will be rendered
  34580. appendTo: '',
  34581. // Enable/Disable globally the possibility to sort layers
  34582. sortable: 1,
  34583. // Enable/Disable globally the possibility to hide layers
  34584. hidable: 1,
  34585. // Hide textnodes
  34586. hideTextnode: 1,
  34587. // Indicate a query string of the element to be selected as the root of layers.
  34588. // By default the root is the wrapper
  34589. root: '',
  34590. // Indicates if the wrapper is visible in layers
  34591. showWrapper: 1,
  34592. // Show hovered components in canvas
  34593. showHover: 1,
  34594. // Scroll to selected component in Canvas when it's selected in Layers
  34595. // true, false or `scrollIntoView`-like options,
  34596. // `block: 'nearest'` avoids the issue of window scolling
  34597. scrollCanvas: {
  34598. behavior: 'smooth',
  34599. block: 'nearest'
  34600. },
  34601. // Scroll to selected component in Layers when it's selected in Canvas
  34602. // true, false or `scrollIntoView`-like options
  34603. scrollLayers: {
  34604. behavior: 'auto',
  34605. block: 'nearest'
  34606. },
  34607. // Highlight when a layer component is hovered
  34608. highlightHover: 1
  34609. });
  34610. /***/ }),
  34611. /***/ "./src/navigator/index.js":
  34612. /*!********************************!*\
  34613. !*** ./src/navigator/index.js ***!
  34614. \********************************/
  34615. /*! exports provided: default */
  34616. /***/ (function(module, __webpack_exports__, __webpack_require__) {
  34617. "use strict";
  34618. __webpack_require__.r(__webpack_exports__);
  34619. /* harmony import */ var _babel_runtime_helpers_defineProperty__WEBPACK_IMPORTED_MODULE_0__ = __webpack_require__(/*! @babel/runtime/helpers/defineProperty */ "./node_modules/@babel/runtime/helpers/defineProperty.js");
  34620. /* harmony import */ var _babel_runtime_helpers_defineProperty__WEBPACK_IMPORTED_MODULE_0___default = /*#__PURE__*/__webpack_require__.n(_babel_runtime_helpers_defineProperty__WEBPACK_IMPORTED_MODULE_0__);
  34621. /* harmony import */ var _config_config__WEBPACK_IMPORTED_MODULE_1__ = __webpack_require__(/*! ./config/config */ "./src/navigator/config/config.js");
  34622. /* harmony import */ var _view_ItemView__WEBPACK_IMPORTED_MODULE_2__ = __webpack_require__(/*! ./view/ItemView */ "./src/navigator/view/ItemView.js");
  34623. /* harmony import */ var underscore__WEBPACK_IMPORTED_MODULE_3__ = __webpack_require__(/*! underscore */ "./node_modules/underscore/underscore.js");
  34624. /* harmony import */ var underscore__WEBPACK_IMPORTED_MODULE_3___default = /*#__PURE__*/__webpack_require__.n(underscore__WEBPACK_IMPORTED_MODULE_3__);
  34625. function ownKeys(object, enumerableOnly) { var keys = Object.keys(object); if (Object.getOwnPropertySymbols) { var symbols = Object.getOwnPropertySymbols(object); if (enumerableOnly) symbols = symbols.filter(function (sym) { return Object.getOwnPropertyDescriptor(object, sym).enumerable; }); keys.push.apply(keys, symbols); } return keys; }
  34626. function _objectSpread(target) { for (var i = 1; i < arguments.length; i++) { var source = arguments[i] != null ? arguments[i] : {}; if (i % 2) { ownKeys(source, true).forEach(function (key) { _babel_runtime_helpers_defineProperty__WEBPACK_IMPORTED_MODULE_0___default()(target, key, source[key]); }); } else if (Object.getOwnPropertyDescriptors) { Object.defineProperties(target, Object.getOwnPropertyDescriptors(source)); } else { ownKeys(source).forEach(function (key) { Object.defineProperty(target, key, Object.getOwnPropertyDescriptor(source, key)); }); } } return target; }
  34627. /* harmony default export */ __webpack_exports__["default"] = (function () {
  34628. var em;
  34629. var layers;
  34630. var config = {};
  34631. return {
  34632. name: 'LayerManager',
  34633. init: function init() {
  34634. var opts = arguments.length > 0 && arguments[0] !== undefined ? arguments[0] : {};
  34635. config = _objectSpread({}, _config_config__WEBPACK_IMPORTED_MODULE_1__["default"], {}, opts);
  34636. config.stylePrefix = opts.pStylePrefix;
  34637. em = config.em;
  34638. return this;
  34639. },
  34640. getConfig: function getConfig() {
  34641. return config;
  34642. },
  34643. onLoad: function onLoad() {
  34644. layers = new _view_ItemView__WEBPACK_IMPORTED_MODULE_2__["default"]({
  34645. level: 0,
  34646. config: config,
  34647. opened: config.opened || {},
  34648. model: em.get('DomComponents').getWrapper()
  34649. });
  34650. em && em.on('component:selected', this.componentChanged);
  34651. this.componentChanged();
  34652. },
  34653. postRender: function postRender() {
  34654. var elTo = config.appendTo;
  34655. var root = config.root;
  34656. root && this.setRoot(root);
  34657. if (elTo) {
  34658. var el = Object(underscore__WEBPACK_IMPORTED_MODULE_3__["isElement"])(elTo) ? elTo : document.querySelector(elTo);
  34659. el.appendChild(this.render());
  34660. }
  34661. },
  34662. /**
  34663. * Set new root for layers
  34664. * @param {HTMLElement|Component|String} el Component to be set as the root
  34665. * @return {self}
  34666. */
  34667. setRoot: function setRoot(el) {
  34668. layers.setRoot(el);
  34669. return this;
  34670. },
  34671. /**
  34672. * Get the root of layers
  34673. * @return {Component}
  34674. */
  34675. getRoot: function getRoot() {
  34676. return layers.model;
  34677. },
  34678. /**
  34679. * Return the view of layers
  34680. * @return {View}
  34681. */
  34682. getAll: function getAll() {
  34683. return layers;
  34684. },
  34685. /**
  34686. * Triggered when the selected component is changed
  34687. * @private
  34688. */
  34689. componentChanged: function componentChanged(selected) {
  34690. var opts = arguments.length > 1 && arguments[1] !== undefined ? arguments[1] : {};
  34691. if (opts.fromLayers) return;
  34692. var opened = em.get('opened');
  34693. var model = em.getSelected();
  34694. var scroll = config.scrollLayers;
  34695. var parent = model && model.collection ? model.collection.parent : null;
  34696. for (var cid in opened) {
  34697. opened[cid].set('open', 0);
  34698. }
  34699. while (parent) {
  34700. parent.set('open', 1);
  34701. opened[parent.cid] = parent;
  34702. parent = parent.collection ? parent.collection.parent : null;
  34703. }
  34704. if (model && scroll) {
  34705. var el = model.viewLayer && model.viewLayer.el;
  34706. el && el.scrollIntoView(scroll);
  34707. }
  34708. },
  34709. render: function render() {
  34710. return layers.render().el;
  34711. }
  34712. };
  34713. });
  34714. /***/ }),
  34715. /***/ "./src/navigator/view/ItemView.js":
  34716. /*!****************************************!*\
  34717. !*** ./src/navigator/view/ItemView.js ***!
  34718. \****************************************/
  34719. /*! exports provided: default */
  34720. /***/ (function(module, __webpack_exports__, __webpack_require__) {
  34721. "use strict";
  34722. __webpack_require__.r(__webpack_exports__);
  34723. /* harmony import */ var underscore__WEBPACK_IMPORTED_MODULE_0__ = __webpack_require__(/*! underscore */ "./node_modules/underscore/underscore.js");
  34724. /* harmony import */ var underscore__WEBPACK_IMPORTED_MODULE_0___default = /*#__PURE__*/__webpack_require__.n(underscore__WEBPACK_IMPORTED_MODULE_0__);
  34725. /* harmony import */ var utils_mixins__WEBPACK_IMPORTED_MODULE_1__ = __webpack_require__(/*! utils/mixins */ "./src/utils/mixins.js");
  34726. /* harmony import */ var backbone__WEBPACK_IMPORTED_MODULE_2__ = __webpack_require__(/*! backbone */ "./node_modules/backbone/backbone.js");
  34727. /* harmony import */ var backbone__WEBPACK_IMPORTED_MODULE_2___default = /*#__PURE__*/__webpack_require__.n(backbone__WEBPACK_IMPORTED_MODULE_2__);
  34728. /* harmony import */ var dom_components_view_ComponentView__WEBPACK_IMPORTED_MODULE_3__ = __webpack_require__(/*! dom_components/view/ComponentView */ "./src/dom_components/view/ComponentView.js");
  34729. /* harmony import */ var dom_components_model_Component__WEBPACK_IMPORTED_MODULE_4__ = __webpack_require__(/*! dom_components/model/Component */ "./src/dom_components/model/Component.js");
  34730. var inputProp = 'contentEditable';
  34731. var $ = backbone__WEBPACK_IMPORTED_MODULE_2___default.a.$;
  34732. var ItemsView;
  34733. /* harmony default export */ __webpack_exports__["default"] = (backbone__WEBPACK_IMPORTED_MODULE_2___default.a.View.extend({
  34734. events: {
  34735. 'mousedown [data-toggle-move]': 'startSort',
  34736. 'touchstart [data-toggle-move]': 'startSort',
  34737. 'click [data-toggle-visible]': 'toggleVisibility',
  34738. 'click [data-toggle-select]': 'handleSelect',
  34739. 'mouseover [data-toggle-select]': 'handleHover',
  34740. 'click [data-toggle-open]': 'toggleOpening',
  34741. 'dblclick [data-name]': 'handleEdit',
  34742. 'focusout [data-name]': 'handleEditEnd'
  34743. },
  34744. template: function template(model) {
  34745. var pfx = this.pfx,
  34746. ppfx = this.ppfx,
  34747. config = this.config,
  34748. clsNoEdit = this.clsNoEdit;
  34749. var hidable = config.hidable;
  34750. var count = this.countChildren(model);
  34751. var addClass = !count ? this.clsNoChild : '';
  34752. var clsTitle = "".concat(this.clsTitle, " ").concat(addClass);
  34753. var clsTitleC = "".concat(this.clsTitleC, " ").concat(ppfx, "one-bg");
  34754. var clsCaret = "".concat(this.clsCaret, " fa fa-chevron-right");
  34755. var clsInput = "".concat(this.inputNameCls, " ").concat(clsNoEdit, " ").concat(ppfx, "no-app");
  34756. var level = this.level + 1;
  34757. var gut = "".concat(30 + level * 10, "px");
  34758. var name = model.getName();
  34759. var icon = model.getIcon();
  34760. var clsBase = "".concat(pfx, "layer");
  34761. return "\n ".concat(hidable ? "<i class=\"".concat(pfx, "layer-vis fa fa-eye ").concat(this.isVisible() ? '' : 'fa-eye-slash', "\" data-toggle-visible></i>") : '', "\n <div class=\"").concat(clsTitleC, "\">\n <div class=\"").concat(clsTitle, "\" style=\"padding-left: ").concat(gut, "\" data-toggle-select>\n <div class=\"").concat(pfx, "layer-title-inn\">\n <i class=\"").concat(clsCaret, "\" data-toggle-open></i>\n ").concat(icon ? "<span class=\"".concat(clsBase, "__icon\">").concat(icon, "</span>") : '', "\n <span class=\"").concat(clsInput, "\" data-name>").concat(name, "</span>\n </div>\n </div>\n </div>\n <div class=\"").concat(this.clsCount, "\" data-count>").concat(count || '', "</div>\n <div class=\"").concat(this.clsMove, "\" data-toggle-move>\n <i class=\"fa fa-arrows\"></i>\n </div>\n <div class=\"").concat(this.clsChildren, "\"></div>");
  34762. },
  34763. initialize: function initialize() {
  34764. var o = arguments.length > 0 && arguments[0] !== undefined ? arguments[0] : {};
  34765. this.opt = o;
  34766. this.level = o.level;
  34767. this.config = o.config;
  34768. this.em = o.config.em;
  34769. this.ppfx = this.em.get('Config').stylePrefix;
  34770. this.sorter = o.sorter || '';
  34771. this.pfx = this.config.stylePrefix;
  34772. this.parentView = o.parentView;
  34773. var pfx = this.pfx;
  34774. var ppfx = this.ppfx;
  34775. var model = this.model;
  34776. var components = model.get('components');
  34777. var type = model.get('type') || 'default';
  34778. model.set('open', false);
  34779. this.listenTo(components, 'remove add reset', this.checkChildren);
  34780. this.listenTo(model, 'change:status', this.updateStatus);
  34781. this.listenTo(model, 'change:open', this.updateOpening);
  34782. this.listenTo(model, 'change:layerable', this.updateLayerable);
  34783. this.listenTo(model, 'change:style:display', this.updateVisibility);
  34784. this.className = "".concat(pfx, "layer ").concat(pfx, "layer__t-").concat(type, " no-select ").concat(ppfx, "two-color");
  34785. this.inputNameCls = "".concat(ppfx, "layer-name");
  34786. this.clsTitleC = "".concat(pfx, "layer-title-c");
  34787. this.clsTitle = "".concat(pfx, "layer-title");
  34788. this.clsCaret = "".concat(pfx, "layer-caret");
  34789. this.clsCount = "".concat(pfx, "layer-count");
  34790. this.clsMove = "".concat(pfx, "layer-move");
  34791. this.clsChildren = "".concat(pfx, "layer-children");
  34792. this.clsNoChild = "".concat(pfx, "layer-no-chld");
  34793. this.clsEdit = "".concat(this.inputNameCls, "--edit");
  34794. this.clsNoEdit = "".concat(this.inputNameCls, "--no-edit");
  34795. this.$el.data('model', model);
  34796. this.$el.data('collection', components);
  34797. model.viewLayer = this;
  34798. },
  34799. getVisibilityEl: function getVisibilityEl() {
  34800. if (!this.eyeEl) {
  34801. this.eyeEl = this.$el.children(".".concat(this.pfx, "layer-vis"));
  34802. }
  34803. return this.eyeEl;
  34804. },
  34805. updateVisibility: function updateVisibility() {
  34806. var pfx = this.pfx;
  34807. var model = this.model;
  34808. var hClass = "".concat(pfx, "layer-hidden");
  34809. var hideIcon = 'fa-eye-slash';
  34810. var hidden = model.getStyle().display == 'none';
  34811. var method = hidden ? 'addClass' : 'removeClass';
  34812. this.$el[method](hClass);
  34813. this.getVisibilityEl()[method](hideIcon);
  34814. },
  34815. /**
  34816. * Toggle visibility
  34817. * @param Event
  34818. *
  34819. * @return void
  34820. * */
  34821. toggleVisibility: function toggleVisibility(e) {
  34822. e && e.stopPropagation();
  34823. var model = this.model;
  34824. var prevDspKey = '__prev-display';
  34825. var prevDisplay = model.get(prevDspKey);
  34826. var style = model.getStyle();
  34827. var display = style.display;
  34828. var hidden = display == 'none';
  34829. if (hidden) {
  34830. delete style.display;
  34831. if (prevDisplay) {
  34832. style.display = prevDisplay;
  34833. model.unset(prevDspKey);
  34834. }
  34835. } else {
  34836. display && model.set(prevDspKey, display);
  34837. style.display = 'none';
  34838. }
  34839. model.setStyle(style);
  34840. },
  34841. /**
  34842. * Handle the edit of the component name
  34843. */
  34844. handleEdit: function handleEdit(e) {
  34845. e && e.stopPropagation();
  34846. var em = this.em,
  34847. $el = this.$el,
  34848. clsNoEdit = this.clsNoEdit,
  34849. clsEdit = this.clsEdit;
  34850. var inputEl = this.getInputName();
  34851. inputEl[inputProp] = true;
  34852. inputEl.focus();
  34853. em && em.setEditing(1);
  34854. $el.find(".".concat(this.inputNameCls)).removeClass(clsNoEdit).addClass(clsEdit);
  34855. },
  34856. /**
  34857. * Handle with the end of editing of the component name
  34858. */
  34859. handleEditEnd: function handleEditEnd(e) {
  34860. e && e.stopPropagation();
  34861. var em = this.em,
  34862. $el = this.$el,
  34863. clsNoEdit = this.clsNoEdit,
  34864. clsEdit = this.clsEdit;
  34865. var inputEl = this.getInputName();
  34866. var name = inputEl.textContent;
  34867. inputEl.scrollLeft = 0;
  34868. inputEl[inputProp] = false;
  34869. this.model.set({
  34870. 'custom-name': name
  34871. });
  34872. em && em.setEditing(0);
  34873. $el.find(".".concat(this.inputNameCls)).addClass(clsNoEdit).removeClass(clsEdit);
  34874. },
  34875. /**
  34876. * Get the input containing the name of the component
  34877. * @return {HTMLElement}
  34878. */
  34879. getInputName: function getInputName() {
  34880. if (!this.inputName) {
  34881. this.inputName = this.el.querySelector(".".concat(this.inputNameCls));
  34882. }
  34883. return this.inputName;
  34884. },
  34885. /**
  34886. * Update item opening
  34887. *
  34888. * @return void
  34889. * */
  34890. updateOpening: function updateOpening() {
  34891. var opened = this.opt.opened || {};
  34892. var model = this.model;
  34893. var chvDown = 'fa-chevron-down';
  34894. if (model.get('open')) {
  34895. this.$el.addClass('open');
  34896. this.getCaret().addClass(chvDown);
  34897. opened[model.cid] = model;
  34898. } else {
  34899. this.$el.removeClass('open');
  34900. this.getCaret().removeClass(chvDown);
  34901. delete opened[model.cid];
  34902. }
  34903. },
  34904. /**
  34905. * Toggle item opening
  34906. * @param {Object} e
  34907. *
  34908. * @return void
  34909. * */
  34910. toggleOpening: function toggleOpening(e) {
  34911. e.stopPropagation();
  34912. if (!this.model.get('components').length) return;
  34913. this.model.set('open', !this.model.get('open'));
  34914. },
  34915. /**
  34916. * Handle component selection
  34917. */
  34918. handleSelect: function handleSelect(e) {
  34919. e.stopPropagation();
  34920. var em = this.em,
  34921. config = this.config;
  34922. if (em) {
  34923. var model = this.model;
  34924. em.setSelected(model, {
  34925. fromLayers: 1
  34926. });
  34927. var scroll = config.scrollCanvas;
  34928. scroll && model.views.forEach(function (view) {
  34929. return view.scrollIntoView(scroll);
  34930. });
  34931. }
  34932. },
  34933. /**
  34934. * Handle component selection
  34935. */
  34936. handleHover: function handleHover(e) {
  34937. e.stopPropagation();
  34938. var em = this.em,
  34939. config = this.config,
  34940. model = this.model;
  34941. em && config.showHover && em.setHovered(model, {
  34942. fromLayers: 1
  34943. });
  34944. },
  34945. /**
  34946. * Delegate to sorter
  34947. * @param Event
  34948. * */
  34949. startSort: function startSort(e) {
  34950. e.stopPropagation();
  34951. var em = this.em,
  34952. sorter = this.sorter; // Right or middel click
  34953. if (e.button && e.button !== 0) return;
  34954. if (sorter) {
  34955. sorter.onStart = function (data) {
  34956. return em.trigger("".concat(dom_components_model_Component__WEBPACK_IMPORTED_MODULE_4__["eventDrag"], ":start"), data);
  34957. };
  34958. sorter.onMoveClb = function (data) {
  34959. return em.trigger(dom_components_model_Component__WEBPACK_IMPORTED_MODULE_4__["eventDrag"], data);
  34960. };
  34961. sorter.startSort(e.target);
  34962. }
  34963. },
  34964. /**
  34965. * Freeze item
  34966. * @return void
  34967. * */
  34968. freeze: function freeze() {
  34969. this.$el.addClass(this.pfx + 'opac50');
  34970. this.model.set('open', 0);
  34971. },
  34972. /**
  34973. * Unfreeze item
  34974. * @return void
  34975. * */
  34976. unfreeze: function unfreeze() {
  34977. this.$el.removeClass(this.pfx + 'opac50');
  34978. },
  34979. /**
  34980. * Update item on status change
  34981. * @param Event
  34982. * */
  34983. updateStatus: function updateStatus(e) {
  34984. dom_components_view_ComponentView__WEBPACK_IMPORTED_MODULE_3__["default"].prototype.updateStatus.apply(this, [{
  34985. avoidHover: !this.config.highlightHover
  34986. }]);
  34987. },
  34988. /**
  34989. * Check if component is visible
  34990. *
  34991. * @return bool
  34992. * */
  34993. isVisible: function isVisible() {
  34994. var css = this.model.get('style'),
  34995. pr = css.display;
  34996. if (pr && pr == 'none') return;
  34997. return 1;
  34998. },
  34999. /**
  35000. * Update item aspect after children changes
  35001. *
  35002. * @return void
  35003. * */
  35004. checkChildren: function checkChildren() {
  35005. var model = this.model,
  35006. clsNoChild = this.clsNoChild;
  35007. var count = this.countChildren(model);
  35008. var title = this.$el.children(".".concat(this.clsTitleC)).children(".".concat(this.clsTitle));
  35009. var cnt = this.cnt;
  35010. if (!cnt) {
  35011. cnt = this.$el.children('[data-count]').get(0);
  35012. this.cnt = cnt;
  35013. }
  35014. title[count ? 'removeClass' : 'addClass'](clsNoChild);
  35015. if (cnt) cnt.innerHTML = count || '';
  35016. !count && model.set('open', 0);
  35017. },
  35018. /**
  35019. * Count children inside model
  35020. * @param {Object} model
  35021. * @return {number}
  35022. * @private
  35023. */
  35024. countChildren: function countChildren(model) {
  35025. var count = 0;
  35026. model.get('components').each(function (m) {
  35027. var isCountable = this.opt.isCountable;
  35028. var hide = this.config.hideTextnode;
  35029. if (isCountable && !isCountable(m, hide)) return;
  35030. count++;
  35031. }, this);
  35032. return count;
  35033. },
  35034. getCaret: function getCaret() {
  35035. if (!this.caret || !this.caret.length) {
  35036. var pfx = this.pfx;
  35037. this.caret = this.$el.children(".".concat(this.clsTitleC)).find(".".concat(this.clsCaret));
  35038. }
  35039. return this.caret;
  35040. },
  35041. setRoot: function setRoot(el) {
  35042. el = Object(underscore__WEBPACK_IMPORTED_MODULE_0__["isString"])(el) ? this.em.getWrapper().find(el)[0] : el;
  35043. var model = Object(utils_mixins__WEBPACK_IMPORTED_MODULE_1__["getModel"])(el, $);
  35044. if (!model) return;
  35045. this.stopListening();
  35046. this.model = model;
  35047. this.initialize(this.opt);
  35048. this.render();
  35049. },
  35050. updateLayerable: function updateLayerable() {
  35051. var parentView = this.parentView;
  35052. var toRerender = parentView || this;
  35053. toRerender.render();
  35054. },
  35055. render: function render() {
  35056. var model = this.model,
  35057. config = this.config,
  35058. pfx = this.pfx,
  35059. ppfx = this.ppfx,
  35060. opt = this.opt;
  35061. var isCountable = opt.isCountable;
  35062. var hidden = isCountable && !isCountable(model, config.hideTextnode);
  35063. var vis = this.isVisible();
  35064. var el = this.$el.empty();
  35065. var level = this.level + 1;
  35066. if (Object(underscore__WEBPACK_IMPORTED_MODULE_0__["isUndefined"])(ItemsView)) {
  35067. ItemsView = __webpack_require__(/*! ./ItemsView */ "./src/navigator/view/ItemsView.js").default;
  35068. }
  35069. var children = new ItemsView({
  35070. collection: model.get('components'),
  35071. config: this.config,
  35072. sorter: this.sorter,
  35073. opened: this.opt.opened,
  35074. parentView: this,
  35075. parent: model,
  35076. level: level
  35077. }).render().$el;
  35078. if (!this.config.showWrapper && level === 1) {
  35079. el.append(children);
  35080. } else {
  35081. el.html(this.template(model));
  35082. el.find(".".concat(this.clsChildren)).append(children);
  35083. }
  35084. if (!model.get('draggable') || !this.config.sortable) {
  35085. el.children(".".concat(this.clsMove)).remove();
  35086. }
  35087. !vis && (this.className += " ".concat(pfx, "hide"));
  35088. hidden && (this.className += " ".concat(ppfx, "hidden"));
  35089. el.attr('class', this.className);
  35090. this.updateOpening();
  35091. this.updateStatus();
  35092. this.updateVisibility();
  35093. return this;
  35094. }
  35095. }));
  35096. /***/ }),
  35097. /***/ "./src/navigator/view/ItemsView.js":
  35098. /*!*****************************************!*\
  35099. !*** ./src/navigator/view/ItemsView.js ***!
  35100. \*****************************************/
  35101. /*! exports provided: default */
  35102. /***/ (function(module, __webpack_exports__, __webpack_require__) {
  35103. "use strict";
  35104. __webpack_require__.r(__webpack_exports__);
  35105. /* harmony import */ var backbone__WEBPACK_IMPORTED_MODULE_0__ = __webpack_require__(/*! backbone */ "./node_modules/backbone/backbone.js");
  35106. /* harmony import */ var backbone__WEBPACK_IMPORTED_MODULE_0___default = /*#__PURE__*/__webpack_require__.n(backbone__WEBPACK_IMPORTED_MODULE_0__);
  35107. /* harmony import */ var _ItemView__WEBPACK_IMPORTED_MODULE_1__ = __webpack_require__(/*! ./ItemView */ "./src/navigator/view/ItemView.js");
  35108. /* harmony import */ var dom_components_model_Component__WEBPACK_IMPORTED_MODULE_2__ = __webpack_require__(/*! dom_components/model/Component */ "./src/dom_components/model/Component.js");
  35109. /* harmony default export */ __webpack_exports__["default"] = (backbone__WEBPACK_IMPORTED_MODULE_0___default.a.View.extend({
  35110. initialize: function initialize() {
  35111. var o = arguments.length > 0 && arguments[0] !== undefined ? arguments[0] : {};
  35112. this.opt = o;
  35113. var config = o.config || {};
  35114. this.level = o.level;
  35115. this.config = config;
  35116. this.preview = o.preview;
  35117. this.ppfx = config.pStylePrefix || '';
  35118. this.pfx = config.stylePrefix || '';
  35119. this.parent = o.parent;
  35120. this.parentView = o.parentView;
  35121. var pfx = this.pfx;
  35122. var ppfx = this.ppfx;
  35123. var parent = this.parent;
  35124. var coll = this.collection;
  35125. this.listenTo(coll, 'add', this.addTo);
  35126. this.listenTo(coll, 'reset resetNavigator', this.render);
  35127. this.listenTo(coll, 'remove', this.removeChildren);
  35128. this.className = "".concat(pfx, "layers");
  35129. var em = config.em;
  35130. if (config.sortable && !this.opt.sorter) {
  35131. var utils = em.get('Utils');
  35132. this.opt.sorter = new utils.Sorter({
  35133. container: config.sortContainer || this.el,
  35134. containerSel: ".".concat(this.className),
  35135. itemSel: ".".concat(pfx, "layer"),
  35136. ignoreViewChildren: 1,
  35137. onEndMove: function onEndMove(created, sorter, data) {
  35138. var srcModel = sorter.getSourceModel();
  35139. em.setSelected(srcModel, {
  35140. forceChange: 1
  35141. });
  35142. em.trigger("".concat(dom_components_model_Component__WEBPACK_IMPORTED_MODULE_2__["eventDrag"], ":end"), data);
  35143. },
  35144. avoidSelectOnEnd: 1,
  35145. nested: 1,
  35146. ppfx: ppfx,
  35147. pfx: pfx
  35148. });
  35149. }
  35150. this.sorter = this.opt.sorter || ''; // For the sorter
  35151. this.$el.data('collection', coll);
  35152. parent && this.$el.data('model', parent);
  35153. },
  35154. removeChildren: function removeChildren(removed) {
  35155. var view = removed.viewLayer;
  35156. if (!view) return;
  35157. view.remove();
  35158. removed.viewLayer = 0;
  35159. },
  35160. /**
  35161. * Add to collection
  35162. * @param Object Model
  35163. *
  35164. * @return Object
  35165. * */
  35166. addTo: function addTo(model) {
  35167. var i = this.collection.indexOf(model);
  35168. this.addToCollection(model, null, i);
  35169. },
  35170. /**
  35171. * Add new object to collection
  35172. * @param Object Model
  35173. * @param Object Fragment collection
  35174. * @param integer Index of append
  35175. *
  35176. * @return Object Object created
  35177. * */
  35178. addToCollection: function addToCollection(model, fragmentEl, index) {
  35179. var level = this.level,
  35180. parentView = this.parentView;
  35181. var fragment = fragmentEl || null;
  35182. var viewObject = _ItemView__WEBPACK_IMPORTED_MODULE_1__["default"];
  35183. var view = new viewObject({
  35184. level: level,
  35185. model: model,
  35186. parentView: parentView,
  35187. config: this.config,
  35188. sorter: this.sorter,
  35189. isCountable: this.isCountable,
  35190. opened: this.opt.opened
  35191. });
  35192. var rendered = view.render().el;
  35193. if (fragment) {
  35194. fragment.appendChild(rendered);
  35195. } else {
  35196. if (typeof index != 'undefined') {
  35197. var method = 'before'; // If the added model is the last of collection
  35198. // need to change the logic of append
  35199. if (this.$el.children().length == index) {
  35200. index--;
  35201. method = 'after';
  35202. } // In case the added is new in the collection index will be -1
  35203. if (index < 0) {
  35204. this.$el.append(rendered);
  35205. } else this.$el.children().eq(index)[method](rendered);
  35206. } else this.$el.append(rendered);
  35207. }
  35208. return rendered;
  35209. },
  35210. /**
  35211. * Check if the model could be count by the navigator
  35212. * @param {Object} model
  35213. * @return {Boolean}
  35214. * @private
  35215. */
  35216. isCountable: function isCountable(model, hide) {
  35217. var type = model.get('type');
  35218. var tag = model.get('tagName');
  35219. if ((type == 'textnode' || tag == 'br') && hide || !model.get('layerable')) {
  35220. return false;
  35221. }
  35222. return true;
  35223. },
  35224. render: function render() {
  35225. var _this = this;
  35226. var frag = document.createDocumentFragment();
  35227. var el = this.el;
  35228. el.innerHTML = '';
  35229. this.collection.each(function (model) {
  35230. return _this.addToCollection(model, frag);
  35231. });
  35232. el.appendChild(frag);
  35233. el.className = this.className;
  35234. return this;
  35235. }
  35236. }));
  35237. /***/ }),
  35238. /***/ "./src/panels/config/config.js":
  35239. /*!*************************************!*\
  35240. !*** ./src/panels/config/config.js ***!
  35241. \*************************************/
  35242. /*! exports provided: default */
  35243. /***/ (function(module, __webpack_exports__, __webpack_require__) {
  35244. "use strict";
  35245. __webpack_require__.r(__webpack_exports__);
  35246. var swv = 'sw-visibility';
  35247. var expt = 'export-template';
  35248. var osm = 'open-sm';
  35249. var otm = 'open-tm';
  35250. var ola = 'open-layers';
  35251. var obl = 'open-blocks';
  35252. var ful = 'fullscreen';
  35253. var prv = 'preview';
  35254. /* harmony default export */ __webpack_exports__["default"] = ({
  35255. stylePrefix: 'pn-',
  35256. // Default panels fa-sliders for features
  35257. defaults: [{
  35258. id: 'commands',
  35259. buttons: [{}]
  35260. }, {
  35261. id: 'options',
  35262. buttons: [{
  35263. active: true,
  35264. id: swv,
  35265. className: 'fa fa-square-o',
  35266. command: swv,
  35267. context: swv,
  35268. attributes: {
  35269. title: 'View components'
  35270. }
  35271. }, {
  35272. id: prv,
  35273. className: 'fa fa-eye',
  35274. command: prv,
  35275. context: prv,
  35276. attributes: {
  35277. title: 'Preview'
  35278. }
  35279. }, {
  35280. id: ful,
  35281. className: 'fa fa-arrows-alt',
  35282. command: ful,
  35283. context: ful,
  35284. attributes: {
  35285. title: 'Fullscreen'
  35286. }
  35287. }, {
  35288. id: expt,
  35289. className: 'fa fa-code',
  35290. command: expt,
  35291. attributes: {
  35292. title: 'View code'
  35293. }
  35294. }]
  35295. }, {
  35296. id: 'views',
  35297. buttons: [{
  35298. id: osm,
  35299. className: 'fa fa-paint-brush',
  35300. command: osm,
  35301. active: true,
  35302. togglable: 0,
  35303. attributes: {
  35304. title: 'Open Style Manager'
  35305. }
  35306. }, {
  35307. id: otm,
  35308. className: 'fa fa-cog',
  35309. command: otm,
  35310. togglable: 0,
  35311. attributes: {
  35312. title: 'Settings'
  35313. }
  35314. }, {
  35315. id: ola,
  35316. className: 'fa fa-bars',
  35317. command: ola,
  35318. togglable: 0,
  35319. attributes: {
  35320. title: 'Open Layer Manager'
  35321. }
  35322. }, {
  35323. id: obl,
  35324. className: 'fa fa-th-large',
  35325. command: obl,
  35326. togglable: 0,
  35327. attributes: {
  35328. title: 'Open Blocks'
  35329. }
  35330. }]
  35331. }],
  35332. // Editor model
  35333. em: null,
  35334. // Delay before show children buttons (in milliseconds)
  35335. delayBtnsShow: 300
  35336. });
  35337. /***/ }),
  35338. /***/ "./src/panels/index.js":
  35339. /*!*****************************!*\
  35340. !*** ./src/panels/index.js ***!
  35341. \*****************************/
  35342. /*! exports provided: default */
  35343. /***/ (function(module, __webpack_exports__, __webpack_require__) {
  35344. "use strict";
  35345. __webpack_require__.r(__webpack_exports__);
  35346. /* harmony import */ var _config_config__WEBPACK_IMPORTED_MODULE_0__ = __webpack_require__(/*! ./config/config */ "./src/panels/config/config.js");
  35347. /* harmony import */ var _model_Panel__WEBPACK_IMPORTED_MODULE_1__ = __webpack_require__(/*! ./model/Panel */ "./src/panels/model/Panel.js");
  35348. /* harmony import */ var _model_Panels__WEBPACK_IMPORTED_MODULE_2__ = __webpack_require__(/*! ./model/Panels */ "./src/panels/model/Panels.js");
  35349. /* harmony import */ var _view_PanelView__WEBPACK_IMPORTED_MODULE_3__ = __webpack_require__(/*! ./view/PanelView */ "./src/panels/view/PanelView.js");
  35350. /* harmony import */ var _view_PanelsView__WEBPACK_IMPORTED_MODULE_4__ = __webpack_require__(/*! ./view/PanelsView */ "./src/panels/view/PanelsView.js");
  35351. /**
  35352. * You can customize the initial state of the module from the editor initialization, by passing the following [Configuration Object](https://github.com/artf/grapesjs/blob/master/src/panels/config/config.js)
  35353. * ```js
  35354. * const editor = grapesjs.init({
  35355. * panels: {
  35356. * // options
  35357. * }
  35358. * })
  35359. * ```
  35360. *
  35361. * Once the editor is instantiated you can use its API. Before using these methods you should get the module from the instance
  35362. *
  35363. * ```js
  35364. * const panelManager = editor.Panels;
  35365. * ```
  35366. *
  35367. * * [addPanel](#addpanel)
  35368. * * [addButton](#addbutton)
  35369. * * [getButton](#getbutton)
  35370. * * [getPanel](#getpanel)
  35371. * * [getPanels](#getpanels)
  35372. * * [getPanelsEl](#getpanelsel)
  35373. * * [removePanel](#removepanel)
  35374. * * [removeButton](#removebutton)
  35375. *
  35376. * @module Panels
  35377. */
  35378. /* harmony default export */ __webpack_exports__["default"] = (function () {
  35379. var c = {};
  35380. var panels, PanelsViewObj;
  35381. return {
  35382. /**
  35383. * Name of the module
  35384. * @type {String}
  35385. * @private
  35386. */
  35387. name: 'Panels',
  35388. /**
  35389. * Initialize module. Automatically called with a new instance of the editor
  35390. * @param {Object} config Configurations
  35391. * @private
  35392. */
  35393. init: function init(config) {
  35394. c = config || {};
  35395. for (var name in _config_config__WEBPACK_IMPORTED_MODULE_0__["default"]) {
  35396. if (!(name in c)) c[name] = _config_config__WEBPACK_IMPORTED_MODULE_0__["default"][name];
  35397. }
  35398. var ppfx = c.pStylePrefix;
  35399. if (ppfx) c.stylePrefix = ppfx + c.stylePrefix;
  35400. panels = new _model_Panels__WEBPACK_IMPORTED_MODULE_2__["default"](c.defaults);
  35401. PanelsViewObj = new _view_PanelsView__WEBPACK_IMPORTED_MODULE_4__["default"]({
  35402. collection: panels,
  35403. config: c
  35404. });
  35405. return this;
  35406. },
  35407. /**
  35408. * Returns the collection of panels
  35409. * @return {Collection} Collection of panel
  35410. */
  35411. getPanels: function getPanels() {
  35412. return panels;
  35413. },
  35414. /**
  35415. * Returns panels element
  35416. * @return {HTMLElement}
  35417. */
  35418. getPanelsEl: function getPanelsEl() {
  35419. return PanelsViewObj.el;
  35420. },
  35421. /**
  35422. * Add new panel to the collection
  35423. * @param {Object|Panel} panel Object with right properties or an instance of Panel
  35424. * @return {Panel} Added panel. Useful in case passed argument was an Object
  35425. * @example
  35426. * var newPanel = panelManager.addPanel({
  35427. * id: 'myNewPanel',
  35428. * visible : true,
  35429. * buttons : [...],
  35430. * });
  35431. */
  35432. addPanel: function addPanel(panel) {
  35433. return panels.add(panel);
  35434. },
  35435. /**
  35436. * Remove a panel from the collection
  35437. * @param {Object|Panel|String} panel Object with right properties or an instance of Panel or Painel id
  35438. * @return {Panel} Removed panel. Useful in case passed argument was an Object
  35439. * @example
  35440. * const newPanel = panelManager.removePanel({
  35441. * id: 'myNewPanel',
  35442. * visible : true,
  35443. * buttons : [...],
  35444. * });
  35445. *
  35446. * const newPanel = panelManager.removePanel('myNewPanel');
  35447. *
  35448. */
  35449. removePanel: function removePanel(panel) {
  35450. return panels.remove(panel);
  35451. },
  35452. /**
  35453. * Get panel by ID
  35454. * @param {string} id Id string
  35455. * @return {Panel|null}
  35456. * @example
  35457. * var myPanel = panelManager.getPanel('myNewPanel');
  35458. */
  35459. getPanel: function getPanel(id) {
  35460. var res = panels.where({
  35461. id: id
  35462. });
  35463. return res.length ? res[0] : null;
  35464. },
  35465. /**
  35466. * Add button to the panel
  35467. * @param {string} panelId Panel's ID
  35468. * @param {Object|Button} button Button object or instance of Button
  35469. * @return {Button|null} Added button. Useful in case passed button was an Object
  35470. * @example
  35471. * var newButton = panelManager.addButton('myNewPanel',{
  35472. * id: 'myNewButton',
  35473. * className: 'someClass',
  35474. * command: 'someCommand',
  35475. * attributes: { title: 'Some title'},
  35476. * active: false,
  35477. * });
  35478. * // It's also possible to pass the command as an object
  35479. * // with .run and .stop methods
  35480. * ...
  35481. * command: {
  35482. * run: function(editor) {
  35483. * ...
  35484. * },
  35485. * stop: function(editor) {
  35486. * ...
  35487. * }
  35488. * },
  35489. * // Or simply like a function which will be evaluated as a single .run command
  35490. * ...
  35491. * command: function(editor) {
  35492. * ...
  35493. * }
  35494. */
  35495. addButton: function addButton(panelId, button) {
  35496. var pn = this.getPanel(panelId);
  35497. return pn ? pn.get('buttons').add(button) : null;
  35498. },
  35499. /**
  35500. * Remove button from the panel
  35501. * @param {String} panelId Panel's ID
  35502. * @param {String} buttonId Button's ID
  35503. * @return {Button|null} Removed button.
  35504. * @example
  35505. * const removedButton = panelManager.addButton('myNewPanel',{
  35506. * id: 'myNewButton',
  35507. * className: 'someClass',
  35508. * command: 'someCommand',
  35509. * attributes: { title: 'Some title'},
  35510. * active: false,
  35511. * });
  35512. *
  35513. * const removedButton = panelManager.removeButton('myNewPanel', 'myNewButton');
  35514. *
  35515. */
  35516. removeButton: function removeButton(panelId, button) {
  35517. var pn = this.getPanel(panelId);
  35518. return pn && pn.get('buttons').remove(button);
  35519. },
  35520. /**
  35521. * Get button from the panel
  35522. * @param {string} panelId Panel's ID
  35523. * @param {string} id Button's ID
  35524. * @return {Button|null}
  35525. * @example
  35526. * var button = panelManager.getButton('myPanel','myButton');
  35527. */
  35528. getButton: function getButton(panelId, id) {
  35529. var pn = this.getPanel(panelId);
  35530. if (pn) {
  35531. var res = pn.get('buttons').where({
  35532. id: id
  35533. });
  35534. return res.length ? res[0] : null;
  35535. }
  35536. return null;
  35537. },
  35538. /**
  35539. * Render panels and buttons
  35540. * @return {HTMLElement}
  35541. * @private
  35542. */
  35543. render: function render() {
  35544. return PanelsViewObj.render().el;
  35545. },
  35546. /**
  35547. * Active activable buttons
  35548. * @private
  35549. */
  35550. active: function active() {
  35551. this.getPanels().each(function (p) {
  35552. p.get('buttons').each(function (btn) {
  35553. btn.get('active') && btn.trigger('updateActive');
  35554. });
  35555. });
  35556. },
  35557. /**
  35558. * Disable buttons flagged as disabled
  35559. * @private
  35560. */
  35561. disableButtons: function disableButtons() {
  35562. this.getPanels().each(function (p) {
  35563. p.get('buttons').each(function (btn) {
  35564. if (btn.get('disable')) btn.trigger('change:disable');
  35565. });
  35566. });
  35567. },
  35568. Panel: _model_Panel__WEBPACK_IMPORTED_MODULE_1__["default"]
  35569. };
  35570. });
  35571. /***/ }),
  35572. /***/ "./src/panels/model/Button.js":
  35573. /*!************************************!*\
  35574. !*** ./src/panels/model/Button.js ***!
  35575. \************************************/
  35576. /*! exports provided: default */
  35577. /***/ (function(module, __webpack_exports__, __webpack_require__) {
  35578. "use strict";
  35579. __webpack_require__.r(__webpack_exports__);
  35580. /* harmony import */ var backbone__WEBPACK_IMPORTED_MODULE_0__ = __webpack_require__(/*! backbone */ "./node_modules/backbone/backbone.js");
  35581. /* harmony import */ var backbone__WEBPACK_IMPORTED_MODULE_0___default = /*#__PURE__*/__webpack_require__.n(backbone__WEBPACK_IMPORTED_MODULE_0__);
  35582. /* harmony default export */ __webpack_exports__["default"] = (backbone__WEBPACK_IMPORTED_MODULE_0___default.a.Model.extend({
  35583. defaults: {
  35584. id: '',
  35585. label: '',
  35586. tagName: 'span',
  35587. className: '',
  35588. command: '',
  35589. context: '',
  35590. buttons: [],
  35591. attributes: {},
  35592. options: {},
  35593. active: false,
  35594. dragDrop: false,
  35595. togglable: true,
  35596. runDefaultCommand: true,
  35597. stopDefaultCommand: false,
  35598. disable: false
  35599. },
  35600. initialize: function initialize(options) {
  35601. if (this.get('buttons').length) {
  35602. var Buttons = __webpack_require__(/*! ./Buttons */ "./src/panels/model/Buttons.js").default;
  35603. this.set('buttons', new Buttons(this.get('buttons')));
  35604. }
  35605. }
  35606. }));
  35607. /***/ }),
  35608. /***/ "./src/panels/model/Buttons.js":
  35609. /*!*************************************!*\
  35610. !*** ./src/panels/model/Buttons.js ***!
  35611. \*************************************/
  35612. /*! exports provided: default */
  35613. /***/ (function(module, __webpack_exports__, __webpack_require__) {
  35614. "use strict";
  35615. __webpack_require__.r(__webpack_exports__);
  35616. /* harmony import */ var backbone__WEBPACK_IMPORTED_MODULE_0__ = __webpack_require__(/*! backbone */ "./node_modules/backbone/backbone.js");
  35617. /* harmony import */ var backbone__WEBPACK_IMPORTED_MODULE_0___default = /*#__PURE__*/__webpack_require__.n(backbone__WEBPACK_IMPORTED_MODULE_0__);
  35618. /* harmony import */ var _Button__WEBPACK_IMPORTED_MODULE_1__ = __webpack_require__(/*! ./Button */ "./src/panels/model/Button.js");
  35619. /* harmony default export */ __webpack_exports__["default"] = (backbone__WEBPACK_IMPORTED_MODULE_0___default.a.Collection.extend({
  35620. model: _Button__WEBPACK_IMPORTED_MODULE_1__["default"],
  35621. /**
  35622. * Deactivate all buttons, except one passed
  35623. * @param {Object} except Model to ignore
  35624. * @param {Boolean} r Recursive flag
  35625. *
  35626. * @return void
  35627. * */
  35628. deactivateAllExceptOne: function deactivateAllExceptOne(except, r) {
  35629. this.forEach(function (model, index) {
  35630. if (model !== except) {
  35631. model.set('active', false);
  35632. if (r && model.get('buttons').length) model.get('buttons').deactivateAllExceptOne(except, r);
  35633. }
  35634. });
  35635. },
  35636. /**
  35637. * Deactivate all buttons
  35638. * @param {String} ctx Context string
  35639. *
  35640. * @return void
  35641. * */
  35642. deactivateAll: function deactivateAll(ctx, sender) {
  35643. var context = ctx || '';
  35644. this.forEach(function (model) {
  35645. if (model.get('context') == context && model !== sender) {
  35646. model.set('active', false, {
  35647. silent: 1
  35648. });
  35649. model.trigger('updateActive', {
  35650. fromCollection: 1
  35651. });
  35652. }
  35653. });
  35654. },
  35655. /**
  35656. * Disables all buttons
  35657. * @param {String} ctx Context string
  35658. *
  35659. * @return void
  35660. * */
  35661. disableAllButtons: function disableAllButtons(ctx) {
  35662. var context = ctx || '';
  35663. this.forEach(function (model, index) {
  35664. if (model.get('context') == context) {
  35665. model.set('disable', true);
  35666. }
  35667. });
  35668. },
  35669. /**
  35670. * Disables all buttons, except one passed
  35671. * @param {Object} except Model to ignore
  35672. * @param {Boolean} r Recursive flag
  35673. *
  35674. * @return void
  35675. * */
  35676. disableAllButtonsExceptOne: function disableAllButtonsExceptOne(except, r) {
  35677. this.forEach(function (model, index) {
  35678. if (model !== except) {
  35679. model.set('disable', true);
  35680. if (r && model.get('buttons').length) model.get('buttons').disableAllButtonsExceptOne(except, r);
  35681. }
  35682. });
  35683. }
  35684. }));
  35685. /***/ }),
  35686. /***/ "./src/panels/model/Panel.js":
  35687. /*!***********************************!*\
  35688. !*** ./src/panels/model/Panel.js ***!
  35689. \***********************************/
  35690. /*! exports provided: default */
  35691. /***/ (function(module, __webpack_exports__, __webpack_require__) {
  35692. "use strict";
  35693. __webpack_require__.r(__webpack_exports__);
  35694. /* harmony import */ var backbone__WEBPACK_IMPORTED_MODULE_0__ = __webpack_require__(/*! backbone */ "./node_modules/backbone/backbone.js");
  35695. /* harmony import */ var backbone__WEBPACK_IMPORTED_MODULE_0___default = /*#__PURE__*/__webpack_require__.n(backbone__WEBPACK_IMPORTED_MODULE_0__);
  35696. /* harmony import */ var _Buttons__WEBPACK_IMPORTED_MODULE_1__ = __webpack_require__(/*! ./Buttons */ "./src/panels/model/Buttons.js");
  35697. /* harmony default export */ __webpack_exports__["default"] = (backbone__WEBPACK_IMPORTED_MODULE_0___default.a.Model.extend({
  35698. defaults: {
  35699. id: '',
  35700. content: '',
  35701. visible: true,
  35702. buttons: [],
  35703. attributes: {}
  35704. },
  35705. initialize: function initialize(options) {
  35706. this.btn = this.get('buttons') || [];
  35707. this.buttons = new _Buttons__WEBPACK_IMPORTED_MODULE_1__["default"](this.btn);
  35708. this.set('buttons', this.buttons);
  35709. }
  35710. }));
  35711. /***/ }),
  35712. /***/ "./src/panels/model/Panels.js":
  35713. /*!************************************!*\
  35714. !*** ./src/panels/model/Panels.js ***!
  35715. \************************************/
  35716. /*! exports provided: default */
  35717. /***/ (function(module, __webpack_exports__, __webpack_require__) {
  35718. "use strict";
  35719. __webpack_require__.r(__webpack_exports__);
  35720. /* harmony import */ var backbone__WEBPACK_IMPORTED_MODULE_0__ = __webpack_require__(/*! backbone */ "./node_modules/backbone/backbone.js");
  35721. /* harmony import */ var backbone__WEBPACK_IMPORTED_MODULE_0___default = /*#__PURE__*/__webpack_require__.n(backbone__WEBPACK_IMPORTED_MODULE_0__);
  35722. /* harmony import */ var _Panel__WEBPACK_IMPORTED_MODULE_1__ = __webpack_require__(/*! ./Panel */ "./src/panels/model/Panel.js");
  35723. /* harmony default export */ __webpack_exports__["default"] = (backbone__WEBPACK_IMPORTED_MODULE_0___default.a.Collection.extend({
  35724. model: _Panel__WEBPACK_IMPORTED_MODULE_1__["default"]
  35725. }));
  35726. /***/ }),
  35727. /***/ "./src/panels/view/ButtonView.js":
  35728. /*!***************************************!*\
  35729. !*** ./src/panels/view/ButtonView.js ***!
  35730. \***************************************/
  35731. /*! exports provided: default */
  35732. /***/ (function(module, __webpack_exports__, __webpack_require__) {
  35733. "use strict";
  35734. __webpack_require__.r(__webpack_exports__);
  35735. /* harmony import */ var _babel_runtime_helpers_defineProperty__WEBPACK_IMPORTED_MODULE_0__ = __webpack_require__(/*! @babel/runtime/helpers/defineProperty */ "./node_modules/@babel/runtime/helpers/defineProperty.js");
  35736. /* harmony import */ var _babel_runtime_helpers_defineProperty__WEBPACK_IMPORTED_MODULE_0___default = /*#__PURE__*/__webpack_require__.n(_babel_runtime_helpers_defineProperty__WEBPACK_IMPORTED_MODULE_0__);
  35737. /* harmony import */ var backbone__WEBPACK_IMPORTED_MODULE_1__ = __webpack_require__(/*! backbone */ "./node_modules/backbone/backbone.js");
  35738. /* harmony import */ var backbone__WEBPACK_IMPORTED_MODULE_1___default = /*#__PURE__*/__webpack_require__.n(backbone__WEBPACK_IMPORTED_MODULE_1__);
  35739. /* harmony import */ var underscore__WEBPACK_IMPORTED_MODULE_2__ = __webpack_require__(/*! underscore */ "./node_modules/underscore/underscore.js");
  35740. /* harmony import */ var underscore__WEBPACK_IMPORTED_MODULE_2___default = /*#__PURE__*/__webpack_require__.n(underscore__WEBPACK_IMPORTED_MODULE_2__);
  35741. function ownKeys(object, enumerableOnly) { var keys = Object.keys(object); if (Object.getOwnPropertySymbols) { var symbols = Object.getOwnPropertySymbols(object); if (enumerableOnly) symbols = symbols.filter(function (sym) { return Object.getOwnPropertyDescriptor(object, sym).enumerable; }); keys.push.apply(keys, symbols); } return keys; }
  35742. function _objectSpread(target) { for (var i = 1; i < arguments.length; i++) { var source = arguments[i] != null ? arguments[i] : {}; if (i % 2) { ownKeys(source, true).forEach(function (key) { _babel_runtime_helpers_defineProperty__WEBPACK_IMPORTED_MODULE_0___default()(target, key, source[key]); }); } else if (Object.getOwnPropertyDescriptors) { Object.defineProperties(target, Object.getOwnPropertyDescriptors(source)); } else { ownKeys(source).forEach(function (key) { Object.defineProperty(target, key, Object.getOwnPropertyDescriptor(source, key)); }); } } return target; }
  35743. var $ = backbone__WEBPACK_IMPORTED_MODULE_1___default.a.$;
  35744. /* harmony default export */ __webpack_exports__["default"] = (backbone__WEBPACK_IMPORTED_MODULE_1___default.a.View.extend({
  35745. tagName: function tagName() {
  35746. return this.model.get('tagName');
  35747. },
  35748. events: {
  35749. click: 'clicked'
  35750. },
  35751. initialize: function initialize(o) {
  35752. var cls = this.model.get('className');
  35753. this.config = o.config || {};
  35754. this.em = this.config.em || {};
  35755. var pfx = this.config.stylePrefix || '';
  35756. var ppfx = this.config.pStylePrefix || '';
  35757. this.pfx = pfx;
  35758. this.ppfx = this.config.pStylePrefix || '';
  35759. this.id = pfx + this.model.get('id');
  35760. this.activeCls = "".concat(pfx, "active ").concat(ppfx, "four-color");
  35761. this.disableCls = "".concat(ppfx, "disabled");
  35762. this.btnsVisCls = "".concat(pfx, "visible");
  35763. this.className = pfx + 'btn' + (cls ? ' ' + cls : '');
  35764. this.listenTo(this.model, 'change', this.render);
  35765. this.listenTo(this.model, 'change:active updateActive', this.updateActive);
  35766. this.listenTo(this.model, 'checkActive', this.checkActive);
  35767. this.listenTo(this.model, 'change:bntsVis', this.updateBtnsVis);
  35768. this.listenTo(this.model, 'change:attributes', this.updateAttributes);
  35769. this.listenTo(this.model, 'change:className', this.updateClassName);
  35770. this.listenTo(this.model, 'change:disable', this.updateDisable);
  35771. if (this.em && this.em.get) this.commands = this.em.get('Commands');
  35772. },
  35773. /**
  35774. * Updates class name of the button
  35775. *
  35776. * @return void
  35777. * */
  35778. updateClassName: function updateClassName() {
  35779. var model = this.model,
  35780. pfx = this.pfx;
  35781. var cls = model.get('className');
  35782. var attrCls = model.get('attributes').class;
  35783. var classStr = "".concat(attrCls ? attrCls : '', " ").concat(pfx, "btn ").concat(cls ? cls : '');
  35784. this.$el.attr('class', classStr.trim());
  35785. },
  35786. /**
  35787. * Updates attributes of the button
  35788. *
  35789. * @return void
  35790. * */
  35791. updateAttributes: function updateAttributes() {
  35792. var em = this.em,
  35793. model = this.model,
  35794. $el = this.$el;
  35795. var attr = model.get('attributes') || {};
  35796. var title = em && em.t && em.t("panels.buttons.titles.".concat(model.id));
  35797. $el.attr(attr);
  35798. title && $el.attr({
  35799. title: title
  35800. });
  35801. this.updateClassName();
  35802. },
  35803. /**
  35804. * Updates visibility of children buttons
  35805. *
  35806. * @return void
  35807. * */
  35808. updateBtnsVis: function updateBtnsVis() {
  35809. if (!this.$buttons) return;
  35810. if (this.model.get('bntsVis')) this.$buttons.addClass(this.btnsVisCls);else this.$buttons.removeClass(this.btnsVisCls);
  35811. },
  35812. /**
  35813. * Update active status of the button
  35814. *
  35815. * @return void
  35816. * */
  35817. updateActive: function updateActive() {
  35818. var opts = arguments.length > 0 && arguments[0] !== undefined ? arguments[0] : {};
  35819. var model = this.model,
  35820. commands = this.commands,
  35821. $el = this.$el,
  35822. activeCls = this.activeCls;
  35823. var fromCollection = opts.fromCollection;
  35824. var context = model.get('context');
  35825. var options = model.get('options');
  35826. var commandName = model.get('command');
  35827. var command = {};
  35828. if (commands && Object(underscore__WEBPACK_IMPORTED_MODULE_2__["isString"])(commandName)) {
  35829. command = commands.get(commandName) || {};
  35830. } else if (Object(underscore__WEBPACK_IMPORTED_MODULE_2__["isFunction"])(commandName)) {
  35831. command = commands.create({
  35832. run: commandName
  35833. });
  35834. } else if (commandName !== null && Object(underscore__WEBPACK_IMPORTED_MODULE_2__["isObject"])(commandName)) {
  35835. command = commands.create(commandName);
  35836. }
  35837. if (model.get('active')) {
  35838. !fromCollection && model.collection.deactivateAll(context, model);
  35839. model.set('active', true, {
  35840. silent: true
  35841. }).trigger('checkActive');
  35842. commands.runCommand(command, _objectSpread({}, options, {
  35843. sender: model
  35844. })); // Disable button if the command has no stop method
  35845. command.noStop && model.set('active', false);
  35846. } else {
  35847. $el.removeClass(activeCls);
  35848. commands.stopCommand(command, _objectSpread({}, options, {
  35849. sender: model,
  35850. force: 1
  35851. }));
  35852. }
  35853. },
  35854. updateDisable: function updateDisable() {
  35855. var disableCls = this.disableCls,
  35856. model = this.model;
  35857. var disable = model.get('disable');
  35858. this.$el[disable ? 'addClass' : 'removeClass'](disableCls);
  35859. },
  35860. /**
  35861. * Update active style status
  35862. *
  35863. * @return void
  35864. * */
  35865. checkActive: function checkActive() {
  35866. var model = this.model,
  35867. $el = this.$el,
  35868. activeCls = this.activeCls;
  35869. model.get('active') ? $el.addClass(activeCls) : $el.removeClass(activeCls);
  35870. },
  35871. /**
  35872. * Triggered when button is clicked
  35873. * @param {Object} e Event
  35874. *
  35875. * @return void
  35876. * */
  35877. clicked: function clicked(e) {
  35878. if (this.model.get('bntsVis')) return;
  35879. if (this.model.get('disable')) return;
  35880. this.toggleActive();
  35881. },
  35882. toggleActive: function toggleActive() {
  35883. var model = this.model;
  35884. var _model$attributes = model.attributes,
  35885. active = _model$attributes.active,
  35886. togglable = _model$attributes.togglable;
  35887. if (active && !togglable) return;
  35888. model.set('active', !active); // If the stop is requested
  35889. var command = this.em.get('Commands').get('select-comp');
  35890. if (active) {
  35891. if (model.get('runDefaultCommand')) this.em.runDefault();
  35892. } else {
  35893. if (model.get('stopDefaultCommand')) this.em.stopDefault();
  35894. }
  35895. },
  35896. render: function render() {
  35897. var label = this.model.get('label');
  35898. var $el = this.$el;
  35899. $el.empty();
  35900. this.updateAttributes();
  35901. label && $el.append(label);
  35902. this.checkActive();
  35903. this.updateDisable();
  35904. return this;
  35905. }
  35906. }));
  35907. /***/ }),
  35908. /***/ "./src/panels/view/ButtonsView.js":
  35909. /*!****************************************!*\
  35910. !*** ./src/panels/view/ButtonsView.js ***!
  35911. \****************************************/
  35912. /*! exports provided: default */
  35913. /***/ (function(module, __webpack_exports__, __webpack_require__) {
  35914. "use strict";
  35915. __webpack_require__.r(__webpack_exports__);
  35916. /* harmony import */ var backbone__WEBPACK_IMPORTED_MODULE_0__ = __webpack_require__(/*! backbone */ "./node_modules/backbone/backbone.js");
  35917. /* harmony import */ var backbone__WEBPACK_IMPORTED_MODULE_0___default = /*#__PURE__*/__webpack_require__.n(backbone__WEBPACK_IMPORTED_MODULE_0__);
  35918. /* harmony import */ var _ButtonView__WEBPACK_IMPORTED_MODULE_1__ = __webpack_require__(/*! ./ButtonView */ "./src/panels/view/ButtonView.js");
  35919. /* harmony import */ var underscore__WEBPACK_IMPORTED_MODULE_2__ = __webpack_require__(/*! underscore */ "./node_modules/underscore/underscore.js");
  35920. /* harmony import */ var underscore__WEBPACK_IMPORTED_MODULE_2___default = /*#__PURE__*/__webpack_require__.n(underscore__WEBPACK_IMPORTED_MODULE_2__);
  35921. /* harmony default export */ __webpack_exports__["default"] = (backbone__WEBPACK_IMPORTED_MODULE_0___default.a.View.extend({
  35922. initialize: function initialize(o) {
  35923. this.opt = o || {};
  35924. this.config = this.opt.config || {};
  35925. this.pfx = this.config.stylePrefix || '';
  35926. this.parentM = this.opt.parentM || null;
  35927. this.listenTo(this.collection, 'add', this.addTo);
  35928. this.listenTo(this.collection, 'reset remove', this.render);
  35929. this.className = this.pfx + 'buttons';
  35930. },
  35931. /**
  35932. * Add to collection
  35933. * @param Object Model
  35934. *
  35935. * @return Object
  35936. * */
  35937. addTo: function addTo(model) {
  35938. this.addToCollection(model);
  35939. },
  35940. /**
  35941. * Add new object to collection
  35942. * @param Object Model
  35943. * @param Object Fragment collection
  35944. *
  35945. * @return Object Object created
  35946. * */
  35947. addToCollection: function addToCollection(model, fragmentEl) {
  35948. var fragment = fragmentEl || null;
  35949. var viewObject = _ButtonView__WEBPACK_IMPORTED_MODULE_1__["default"];
  35950. var view = new viewObject({
  35951. model: model,
  35952. config: this.config,
  35953. parentM: this.parentM
  35954. });
  35955. var rendered = view.render().el;
  35956. if (fragment) {
  35957. fragment.appendChild(rendered);
  35958. } else {
  35959. this.$el.append(rendered);
  35960. }
  35961. return rendered;
  35962. },
  35963. render: function render() {
  35964. var fragment = document.createDocumentFragment();
  35965. this.$el.empty();
  35966. this.collection.each(function (model) {
  35967. this.addToCollection(model, fragment);
  35968. }, this);
  35969. this.$el.append(fragment);
  35970. this.$el.attr('class', Object(underscore__WEBPACK_IMPORTED_MODULE_2__["result"])(this, 'className'));
  35971. return this;
  35972. }
  35973. }));
  35974. /***/ }),
  35975. /***/ "./src/panels/view/PanelView.js":
  35976. /*!**************************************!*\
  35977. !*** ./src/panels/view/PanelView.js ***!
  35978. \**************************************/
  35979. /*! exports provided: default */
  35980. /***/ (function(module, __webpack_exports__, __webpack_require__) {
  35981. "use strict";
  35982. __webpack_require__.r(__webpack_exports__);
  35983. /* harmony import */ var _babel_runtime_helpers_defineProperty__WEBPACK_IMPORTED_MODULE_0__ = __webpack_require__(/*! @babel/runtime/helpers/defineProperty */ "./node_modules/@babel/runtime/helpers/defineProperty.js");
  35984. /* harmony import */ var _babel_runtime_helpers_defineProperty__WEBPACK_IMPORTED_MODULE_0___default = /*#__PURE__*/__webpack_require__.n(_babel_runtime_helpers_defineProperty__WEBPACK_IMPORTED_MODULE_0__);
  35985. /* harmony import */ var backbone__WEBPACK_IMPORTED_MODULE_1__ = __webpack_require__(/*! backbone */ "./node_modules/backbone/backbone.js");
  35986. /* harmony import */ var backbone__WEBPACK_IMPORTED_MODULE_1___default = /*#__PURE__*/__webpack_require__.n(backbone__WEBPACK_IMPORTED_MODULE_1__);
  35987. /* harmony import */ var _ButtonsView__WEBPACK_IMPORTED_MODULE_2__ = __webpack_require__(/*! ./ButtonsView */ "./src/panels/view/ButtonsView.js");
  35988. function ownKeys(object, enumerableOnly) { var keys = Object.keys(object); if (Object.getOwnPropertySymbols) { var symbols = Object.getOwnPropertySymbols(object); if (enumerableOnly) symbols = symbols.filter(function (sym) { return Object.getOwnPropertyDescriptor(object, sym).enumerable; }); keys.push.apply(keys, symbols); } return keys; }
  35989. function _objectSpread(target) { for (var i = 1; i < arguments.length; i++) { var source = arguments[i] != null ? arguments[i] : {}; if (i % 2) { ownKeys(source, true).forEach(function (key) { _babel_runtime_helpers_defineProperty__WEBPACK_IMPORTED_MODULE_0___default()(target, key, source[key]); }); } else if (Object.getOwnPropertyDescriptors) { Object.defineProperties(target, Object.getOwnPropertyDescriptors(source)); } else { ownKeys(source).forEach(function (key) { Object.defineProperty(target, key, Object.getOwnPropertyDescriptor(source, key)); }); } } return target; }
  35990. /* harmony default export */ __webpack_exports__["default"] = (backbone__WEBPACK_IMPORTED_MODULE_1___default.a.View.extend({
  35991. initialize: function initialize(o) {
  35992. var config = o.config || {};
  35993. var model = this.model;
  35994. this.config = config;
  35995. this.pfx = config.stylePrefix || '';
  35996. this.ppfx = config.pStylePrefix || '';
  35997. this.buttons = model.get('buttons');
  35998. this.className = this.pfx + 'panel';
  35999. this.id = this.pfx + model.get('id');
  36000. this.listenTo(model, 'change:appendContent', this.appendContent);
  36001. this.listenTo(model, 'change:content', this.updateContent);
  36002. this.listenTo(model, 'change:visible', this.toggleVisible);
  36003. model.view = this;
  36004. },
  36005. /**
  36006. * Append content of the panel
  36007. * */
  36008. appendContent: function appendContent() {
  36009. this.$el.append(this.model.get('appendContent'));
  36010. },
  36011. /**
  36012. * Update content
  36013. * */
  36014. updateContent: function updateContent() {
  36015. this.$el.html(this.model.get('content'));
  36016. },
  36017. toggleVisible: function toggleVisible() {
  36018. if (!this.model.get('visible')) {
  36019. this.$el.addClass("".concat(this.ppfx, "hidden"));
  36020. return;
  36021. }
  36022. this.$el.removeClass("".concat(this.ppfx, "hidden"));
  36023. },
  36024. attributes: function attributes() {
  36025. return this.model.get('attributes');
  36026. },
  36027. initResize: function initResize() {
  36028. var em = this.config.em;
  36029. var editor = em ? em.get('Editor') : '';
  36030. var resizable = this.model.get('resizable');
  36031. if (editor && resizable) {
  36032. var resz = resizable === true ? [1, 1, 1, 1] : resizable;
  36033. var resLen = resz.length;
  36034. var tc,
  36035. cr,
  36036. bc,
  36037. cl = 0; // Choose which sides of the panel are resizable
  36038. if (resLen == 2) {
  36039. tc = resz[0];
  36040. bc = resz[0];
  36041. cr = resz[1];
  36042. cl = resz[1];
  36043. } else if (resLen == 4) {
  36044. tc = resz[0];
  36045. cr = resz[1];
  36046. bc = resz[2];
  36047. cl = resz[3];
  36048. }
  36049. var resizer = editor.Utils.Resizer.init(_objectSpread({
  36050. tc: tc,
  36051. cr: cr,
  36052. bc: bc,
  36053. cl: cl,
  36054. tl: 0,
  36055. tr: 0,
  36056. bl: 0,
  36057. br: 0,
  36058. appendTo: this.el,
  36059. silentFrames: 1,
  36060. avoidContainerUpdate: 1,
  36061. prefix: editor.getConfig().stylePrefix,
  36062. onEnd: function onEnd() {
  36063. em && em.trigger('change:canvasOffset');
  36064. },
  36065. posFetcher: function posFetcher(el, _ref) {
  36066. var target = _ref.target;
  36067. var style = el.style;
  36068. var config = resizer.getConfig();
  36069. var keyWidth = config.keyWidth;
  36070. var keyHeight = config.keyHeight;
  36071. var rect = el.getBoundingClientRect();
  36072. var forContainer = target == 'container';
  36073. var styleWidth = style[keyWidth];
  36074. var styleHeight = style[keyHeight];
  36075. var width = styleWidth && !forContainer ? parseFloat(styleWidth) : rect.width;
  36076. var height = styleHeight && !forContainer ? parseFloat(styleHeight) : rect.height;
  36077. return {
  36078. left: 0,
  36079. top: 0,
  36080. width: width,
  36081. height: height
  36082. };
  36083. }
  36084. }, resizable));
  36085. resizer.blur = function () {};
  36086. resizer.focus(this.el);
  36087. }
  36088. },
  36089. render: function render() {
  36090. var $el = this.$el;
  36091. var ppfx = this.ppfx;
  36092. var cls = "".concat(this.className, " ").concat(this.id, " ").concat(ppfx, "one-bg ").concat(ppfx, "two-color");
  36093. $el.addClass(cls);
  36094. if (this.buttons.length) {
  36095. var buttons = new _ButtonsView__WEBPACK_IMPORTED_MODULE_2__["default"]({
  36096. collection: this.buttons,
  36097. config: this.config
  36098. });
  36099. $el.append(buttons.render().el);
  36100. }
  36101. $el.append(this.model.get('content'));
  36102. return this;
  36103. }
  36104. }));
  36105. /***/ }),
  36106. /***/ "./src/panels/view/PanelsView.js":
  36107. /*!***************************************!*\
  36108. !*** ./src/panels/view/PanelsView.js ***!
  36109. \***************************************/
  36110. /*! exports provided: default */
  36111. /***/ (function(module, __webpack_exports__, __webpack_require__) {
  36112. "use strict";
  36113. __webpack_require__.r(__webpack_exports__);
  36114. /* harmony import */ var backbone__WEBPACK_IMPORTED_MODULE_0__ = __webpack_require__(/*! backbone */ "./node_modules/backbone/backbone.js");
  36115. /* harmony import */ var backbone__WEBPACK_IMPORTED_MODULE_0___default = /*#__PURE__*/__webpack_require__.n(backbone__WEBPACK_IMPORTED_MODULE_0__);
  36116. /* harmony import */ var _PanelView__WEBPACK_IMPORTED_MODULE_1__ = __webpack_require__(/*! ./PanelView */ "./src/panels/view/PanelView.js");
  36117. /* harmony default export */ __webpack_exports__["default"] = (backbone__WEBPACK_IMPORTED_MODULE_0___default.a.View.extend({
  36118. initialize: function initialize(o) {
  36119. this.opt = o || {};
  36120. this.config = this.opt.config || {};
  36121. this.pfx = this.config.stylePrefix || '';
  36122. var items = this.collection;
  36123. this.listenTo(items, 'add', this.addTo);
  36124. this.listenTo(items, 'reset', this.render);
  36125. this.listenTo(items, 'remove', this.onRemove);
  36126. this.className = this.pfx + 'panels';
  36127. },
  36128. onRemove: function onRemove(model) {
  36129. var view = model.view;
  36130. view && view.remove();
  36131. },
  36132. /**
  36133. * Add to collection
  36134. * @param Object Model
  36135. *
  36136. * @return Object
  36137. * @private
  36138. * */
  36139. addTo: function addTo(model) {
  36140. this.addToCollection(model);
  36141. },
  36142. /**
  36143. * Add new object to collection
  36144. * @param Object Model
  36145. * @param Object Fragment collection
  36146. * @param integer Index of append
  36147. *
  36148. * @return Object Object created
  36149. * @private
  36150. * */
  36151. addToCollection: function addToCollection(model, fragmentEl) {
  36152. var fragment = fragmentEl || null;
  36153. var config = this.config;
  36154. var el = model.get('el');
  36155. var view = new _PanelView__WEBPACK_IMPORTED_MODULE_1__["default"]({
  36156. el: el,
  36157. model: model,
  36158. config: config
  36159. });
  36160. var rendered = view.render().el;
  36161. var appendTo = model.get('appendTo'); // Do nothing if the panel was requested to be another element
  36162. if (el) {} else if (appendTo) {
  36163. var appendEl = document.querySelector(appendTo);
  36164. appendEl.appendChild(rendered);
  36165. } else {
  36166. if (fragment) {
  36167. fragment.appendChild(rendered);
  36168. } else {
  36169. this.$el.append(rendered);
  36170. }
  36171. }
  36172. view.initResize();
  36173. return rendered;
  36174. },
  36175. render: function render() {
  36176. var _this = this;
  36177. var $el = this.$el;
  36178. var frag = document.createDocumentFragment();
  36179. $el.empty();
  36180. this.collection.each(function (model) {
  36181. return _this.addToCollection(model, frag);
  36182. });
  36183. $el.append(frag);
  36184. $el.attr('class', this.className);
  36185. return this;
  36186. }
  36187. }));
  36188. /***/ }),
  36189. /***/ "./src/parser/config/config.js":
  36190. /*!*************************************!*\
  36191. !*** ./src/parser/config/config.js ***!
  36192. \*************************************/
  36193. /*! exports provided: default */
  36194. /***/ (function(module, __webpack_exports__, __webpack_require__) {
  36195. "use strict";
  36196. __webpack_require__.r(__webpack_exports__);
  36197. /* harmony default export */ __webpack_exports__["default"] = ({
  36198. textTags: ['br', 'b', 'i', 'u', 'a', 'ul', 'ol'],
  36199. // Custom CSS parser
  36200. parserCss: null,
  36201. // Custom HTML parser
  36202. parserHtml: null
  36203. });
  36204. /***/ }),
  36205. /***/ "./src/parser/index.js":
  36206. /*!*****************************!*\
  36207. !*** ./src/parser/index.js ***!
  36208. \*****************************/
  36209. /*! exports provided: default */
  36210. /***/ (function(module, __webpack_exports__, __webpack_require__) {
  36211. "use strict";
  36212. __webpack_require__.r(__webpack_exports__);
  36213. /* harmony import */ var _babel_runtime_helpers_defineProperty__WEBPACK_IMPORTED_MODULE_0__ = __webpack_require__(/*! @babel/runtime/helpers/defineProperty */ "./node_modules/@babel/runtime/helpers/defineProperty.js");
  36214. /* harmony import */ var _babel_runtime_helpers_defineProperty__WEBPACK_IMPORTED_MODULE_0___default = /*#__PURE__*/__webpack_require__.n(_babel_runtime_helpers_defineProperty__WEBPACK_IMPORTED_MODULE_0__);
  36215. /* harmony import */ var _config_config__WEBPACK_IMPORTED_MODULE_1__ = __webpack_require__(/*! ./config/config */ "./src/parser/config/config.js");
  36216. /* harmony import */ var _model_ParserCss__WEBPACK_IMPORTED_MODULE_2__ = __webpack_require__(/*! ./model/ParserCss */ "./src/parser/model/ParserCss.js");
  36217. /* harmony import */ var _model_ParserHtml__WEBPACK_IMPORTED_MODULE_3__ = __webpack_require__(/*! ./model/ParserHtml */ "./src/parser/model/ParserHtml.js");
  36218. function ownKeys(object, enumerableOnly) { var keys = Object.keys(object); if (Object.getOwnPropertySymbols) { var symbols = Object.getOwnPropertySymbols(object); if (enumerableOnly) symbols = symbols.filter(function (sym) { return Object.getOwnPropertyDescriptor(object, sym).enumerable; }); keys.push.apply(keys, symbols); } return keys; }
  36219. function _objectSpread(target) { for (var i = 1; i < arguments.length; i++) { var source = arguments[i] != null ? arguments[i] : {}; if (i % 2) { ownKeys(source, true).forEach(function (key) { _babel_runtime_helpers_defineProperty__WEBPACK_IMPORTED_MODULE_0___default()(target, key, source[key]); }); } else if (Object.getOwnPropertyDescriptors) { Object.defineProperties(target, Object.getOwnPropertyDescriptors(source)); } else { ownKeys(source).forEach(function (key) { Object.defineProperty(target, key, Object.getOwnPropertyDescriptor(source, key)); }); } } return target; }
  36220. /* harmony default export */ __webpack_exports__["default"] = (function () {
  36221. var conf = {};
  36222. var pHtml, pCss;
  36223. return {
  36224. compTypes: '',
  36225. parserCss: null,
  36226. parserHtml: null,
  36227. /**
  36228. * Name of the module
  36229. * @type {String}
  36230. * @private
  36231. */
  36232. name: 'Parser',
  36233. /**
  36234. * Get config object
  36235. * @return {Object}
  36236. */
  36237. getConfig: function getConfig() {
  36238. return conf;
  36239. },
  36240. /**
  36241. * Initialize module. Automatically called with a new instance of the editor
  36242. * @param {Object} config Configurations
  36243. * @param {Array<Object>} [config.blocks=[]] Default blocks
  36244. * @return {this}
  36245. * @example
  36246. * ...
  36247. * {
  36248. * blocks: [
  36249. * {id:'h1-block' label: 'Heading', content:'<h1>...</h1>'},
  36250. * ...
  36251. * ],
  36252. * }
  36253. * ...
  36254. */
  36255. init: function init() {
  36256. var config = arguments.length > 0 && arguments[0] !== undefined ? arguments[0] : {};
  36257. conf = _objectSpread({}, _config_config__WEBPACK_IMPORTED_MODULE_1__["default"], {}, config);
  36258. conf.Parser = this;
  36259. pHtml = new _model_ParserHtml__WEBPACK_IMPORTED_MODULE_3__["default"](conf);
  36260. pCss = new _model_ParserCss__WEBPACK_IMPORTED_MODULE_2__["default"](conf);
  36261. this.em = conf.em;
  36262. this.parserCss = pCss;
  36263. this.parserHtml = pHtml;
  36264. return this;
  36265. },
  36266. /**
  36267. * Parse HTML string and return valid model
  36268. * @param {string} str HTML string
  36269. * @return {Object}
  36270. */
  36271. parseHtml: function parseHtml(str) {
  36272. var em = this.em,
  36273. compTypes = this.compTypes;
  36274. pHtml.compTypes = em ? em.get('DomComponents').getTypes() : compTypes;
  36275. return pHtml.parse(str, pCss);
  36276. },
  36277. /**
  36278. * Parse CSS string and return valid model
  36279. * @param {string} str CSS string
  36280. * @return {Array<Object>}
  36281. */
  36282. parseCss: function parseCss(str) {
  36283. return pCss.parse(str);
  36284. }
  36285. };
  36286. });
  36287. /***/ }),
  36288. /***/ "./src/parser/model/BrowserParserCss.js":
  36289. /*!**********************************************!*\
  36290. !*** ./src/parser/model/BrowserParserCss.js ***!
  36291. \**********************************************/
  36292. /*! exports provided: parseSelector, parseStyle, parseCondition, createNode, parseNode, default */
  36293. /***/ (function(module, __webpack_exports__, __webpack_require__) {
  36294. "use strict";
  36295. __webpack_require__.r(__webpack_exports__);
  36296. /* harmony export (binding) */ __webpack_require__.d(__webpack_exports__, "parseSelector", function() { return parseSelector; });
  36297. /* harmony export (binding) */ __webpack_require__.d(__webpack_exports__, "parseStyle", function() { return parseStyle; });
  36298. /* harmony export (binding) */ __webpack_require__.d(__webpack_exports__, "parseCondition", function() { return parseCondition; });
  36299. /* harmony export (binding) */ __webpack_require__.d(__webpack_exports__, "createNode", function() { return createNode; });
  36300. /* harmony export (binding) */ __webpack_require__.d(__webpack_exports__, "parseNode", function() { return parseNode; });
  36301. /* harmony import */ var underscore__WEBPACK_IMPORTED_MODULE_0__ = __webpack_require__(/*! underscore */ "./node_modules/underscore/underscore.js");
  36302. /* harmony import */ var underscore__WEBPACK_IMPORTED_MODULE_0___default = /*#__PURE__*/__webpack_require__.n(underscore__WEBPACK_IMPORTED_MODULE_0__);
  36303. // At-rules
  36304. // https://developer.mozilla.org/it/docs/Web/API/CSSRule#Type_constants
  36305. var atRules = {
  36306. 4: 'media',
  36307. 5: 'font-face',
  36308. 6: 'page',
  36309. 7: 'keyframes',
  36310. 11: 'counter-style',
  36311. 12: 'supports',
  36312. 13: 'document',
  36313. 14: 'font-feature-values',
  36314. 15: 'viewport'
  36315. };
  36316. var atRuleKeys = Object(underscore__WEBPACK_IMPORTED_MODULE_0__["keys"])(atRules);
  36317. var singleAtRules = ['5', '6', '11', '15'];
  36318. var singleAtRulesNames = ['font-face', 'page', 'counter-style', 'viewport'];
  36319. /**
  36320. * Parse selector string to array.
  36321. * Only classe based are valid as CSS rules inside editor, not valid
  36322. * selectors will be dropped as additional
  36323. * It's ok with the last part of the string as state (:hover, :active)
  36324. * @param {string} str Selectors string
  36325. * @return {Object}
  36326. * @example
  36327. * var res = parseSelector('.test1, .test1.test2, .test2 .test3');
  36328. * console.log(res);
  36329. * // {
  36330. * //result: [['test1'], ['test1', 'test2']],
  36331. * //add: ['.test2 .test3']
  36332. * //}
  36333. */
  36334. var parseSelector = function parseSelector() {
  36335. var str = arguments.length > 0 && arguments[0] !== undefined ? arguments[0] : '';
  36336. var add = [];
  36337. var result = [];
  36338. var sels = str.split(',');
  36339. for (var i = 0, len = sels.length; i < len; i++) {
  36340. var sel = sels[i].trim(); // Will accept only concatenated classes and last
  36341. // class might be with state (eg. :hover), nothing else.
  36342. // Can also accept SINGLE ID selectors, eg. `#myid`, `#myid:hover`
  36343. // Composed are not valid: `#myid.some-class`, `#myid.some-class:hover`
  36344. if (/^(\.{1}[\w\-]+)+(:{1,2}[\w\-()]+)?$/gi.test(sel) || /^(#{1}[\w\-]+){1}(:{1,2}[\w\-()]+)?$/gi.test(sel)) {
  36345. var cls = sel.split('.').filter(Boolean);
  36346. result.push(cls);
  36347. } else {
  36348. add.push(sel);
  36349. }
  36350. }
  36351. return {
  36352. result: result,
  36353. add: add
  36354. };
  36355. };
  36356. /**
  36357. * Parse style declarations of the node
  36358. * @param {CSSRule} node
  36359. * @return {Object}
  36360. */
  36361. var parseStyle = function parseStyle(node) {
  36362. var stl = node.style;
  36363. var style = {};
  36364. for (var i = 0, len = stl.length; i < len; i++) {
  36365. var propName = stl[i];
  36366. var propValue = stl.getPropertyValue(propName);
  36367. var important = stl.getPropertyPriority(propName);
  36368. style[propName] = "".concat(propValue).concat(important ? " !".concat(important) : '');
  36369. }
  36370. return style;
  36371. };
  36372. /**
  36373. * Get the condition when possible
  36374. * @param {CSSRule} node
  36375. * @return {string}
  36376. */
  36377. var parseCondition = function parseCondition(node) {
  36378. var condition = node.conditionText || node.media && node.media.mediaText || node.name || node.selectorText || '';
  36379. return condition.trim();
  36380. };
  36381. /**
  36382. * Create node for the editor
  36383. * @param {Array<String>} selectors Array containing strings of classes
  36384. * @param {Object} style Key-value object of style declarations
  36385. * @return {Object}
  36386. */
  36387. var createNode = function createNode(selectors) {
  36388. var style = arguments.length > 1 && arguments[1] !== undefined ? arguments[1] : {};
  36389. var opts = arguments.length > 2 && arguments[2] !== undefined ? arguments[2] : {};
  36390. var node = {};
  36391. var selLen = selectors.length;
  36392. var lastClass = selectors[selLen - 1];
  36393. var stateArr = lastClass ? lastClass.split(/:(.+)/) : [];
  36394. var state = stateArr[1];
  36395. var atRule = opts.atRule,
  36396. selectorsAdd = opts.selectorsAdd,
  36397. mediaText = opts.mediaText;
  36398. var singleAtRule = singleAtRulesNames.indexOf(atRule) >= 0;
  36399. singleAtRule && (node.singleAtRule = 1);
  36400. atRule && (node.atRuleType = atRule);
  36401. selectorsAdd && (node.selectorsAdd = selectorsAdd);
  36402. mediaText && (node.mediaText = mediaText); // Isolate the state from selectors
  36403. if (state) {
  36404. selectors[selLen - 1] = stateArr[0];
  36405. node.state = state;
  36406. stateArr.splice(stateArr.length - 1, 1);
  36407. }
  36408. node.selectors = selectors;
  36409. node.style = style;
  36410. return node;
  36411. };
  36412. /**
  36413. * Fetch data from node
  36414. * @param {StyleSheet|CSSRule} el
  36415. * @return {Array<Object>}
  36416. */
  36417. var parseNode = function parseNode(el) {
  36418. var result = [];
  36419. var nodes = el.cssRules || [];
  36420. for (var i = 0, len = nodes.length; i < len; i++) {
  36421. var node = nodes[i];
  36422. var type = node.type.toString();
  36423. var singleAtRule = 0;
  36424. var atRuleType = '';
  36425. var condition = ''; // keyText is for CSSKeyframeRule
  36426. var sels = node.selectorText || node.keyText;
  36427. var isSingleAtRule = singleAtRules.indexOf(type) >= 0; // Check if the node is an at-rule
  36428. if (isSingleAtRule) {
  36429. singleAtRule = 1;
  36430. atRuleType = atRules[type];
  36431. condition = parseCondition(node);
  36432. } else if (atRuleKeys.indexOf(type) >= 0) {
  36433. var subRules = parseNode(node);
  36434. condition = parseCondition(node);
  36435. for (var s = 0, lens = subRules.length; s < lens; s++) {
  36436. var subRule = subRules[s];
  36437. condition && (subRule.mediaText = condition);
  36438. subRule.atRuleType = atRules[type];
  36439. }
  36440. result = result.concat(subRules);
  36441. }
  36442. if (!sels && !isSingleAtRule) continue;
  36443. var style = parseStyle(node);
  36444. var selsParsed = parseSelector(sels);
  36445. var selsAdd = selsParsed.add;
  36446. sels = selsParsed.result;
  36447. var lastRule = void 0; // For each group of selectors
  36448. for (var k = 0, len3 = sels.length; k < len3; k++) {
  36449. var model = createNode(sels[k], style, {
  36450. atRule: atRules[type]
  36451. });
  36452. result.push(model);
  36453. lastRule = model;
  36454. } // Need to push somewhere not class-based selectors, if some rule was
  36455. // created will push them there, otherwise will create a new rule
  36456. if (selsAdd.length) {
  36457. var selsAddStr = selsAdd.join(', ');
  36458. if (lastRule) {
  36459. lastRule.selectorsAdd = selsAddStr;
  36460. } else {
  36461. var _model = {
  36462. selectors: [],
  36463. selectorsAdd: selsAddStr,
  36464. style: style
  36465. };
  36466. singleAtRule && (_model.singleAtRule = singleAtRule);
  36467. atRuleType && (_model.atRuleType = atRuleType);
  36468. condition && (_model.mediaText = condition);
  36469. result.push(_model);
  36470. }
  36471. } // console.log('LAST PUSH', result[result.length - 1]);
  36472. }
  36473. return result;
  36474. };
  36475. /**
  36476. * Parse CSS string and return the array of objects
  36477. * @param {String} str CSS string
  36478. * @return {Array<Object>} Array of objects for the definition of CSSRules
  36479. */
  36480. /* harmony default export */ __webpack_exports__["default"] = (function (str) {
  36481. var el = document.createElement('style');
  36482. el.innerHTML = str; // There is no .sheet before adding it to the <head>
  36483. document.head.appendChild(el);
  36484. var sheet = el.sheet;
  36485. document.head.removeChild(el);
  36486. return parseNode(sheet);
  36487. });
  36488. /***/ }),
  36489. /***/ "./src/parser/model/ParserCss.js":
  36490. /*!***************************************!*\
  36491. !*** ./src/parser/model/ParserCss.js ***!
  36492. \***************************************/
  36493. /*! exports provided: default */
  36494. /***/ (function(module, __webpack_exports__, __webpack_require__) {
  36495. "use strict";
  36496. __webpack_require__.r(__webpack_exports__);
  36497. /* harmony import */ var underscore__WEBPACK_IMPORTED_MODULE_0__ = __webpack_require__(/*! underscore */ "./node_modules/underscore/underscore.js");
  36498. /* harmony import */ var underscore__WEBPACK_IMPORTED_MODULE_0___default = /*#__PURE__*/__webpack_require__.n(underscore__WEBPACK_IMPORTED_MODULE_0__);
  36499. /* harmony import */ var _BrowserParserCss__WEBPACK_IMPORTED_MODULE_1__ = __webpack_require__(/*! ./BrowserParserCss */ "./src/parser/model/BrowserParserCss.js");
  36500. /* harmony default export */ __webpack_exports__["default"] = (function () {
  36501. var config = arguments.length > 0 && arguments[0] !== undefined ? arguments[0] : {};
  36502. return {
  36503. /**
  36504. * Parse CSS string to a desired model object
  36505. * @param {String} str CSS string
  36506. * @return {Array<Object>}
  36507. */
  36508. parse: function parse(str) {
  36509. var _this = this;
  36510. var result = [];
  36511. var parserCss = config.parserCss,
  36512. _config$em = config.em,
  36513. em = _config$em === void 0 ? {} : _config$em;
  36514. var editor = em && em.get && em.get('Editor');
  36515. var nodes = parserCss ? parserCss(str, editor) : Object(_BrowserParserCss__WEBPACK_IMPORTED_MODULE_1__["default"])(str);
  36516. nodes.forEach(function (node) {
  36517. return result = result.concat(_this.checkNode(node));
  36518. });
  36519. return result;
  36520. },
  36521. /**
  36522. * Check the returned node from a custom parser and transforms it to
  36523. * a valid object for the CSS composer
  36524. * @return {[type]}
  36525. */
  36526. checkNode: function checkNode(node) {
  36527. var _node = node,
  36528. selectors = _node.selectors,
  36529. style = _node.style;
  36530. if (Object(underscore__WEBPACK_IMPORTED_MODULE_0__["isString"])(selectors)) {
  36531. var nodes = [];
  36532. var selsParsed = Object(_BrowserParserCss__WEBPACK_IMPORTED_MODULE_1__["parseSelector"])(selectors);
  36533. var classSets = selsParsed.result;
  36534. var selectorsAdd = selsParsed.add.join(', ');
  36535. var opts = {
  36536. atRule: node.atRule,
  36537. mediaText: node.params
  36538. };
  36539. if (classSets.length) {
  36540. classSets.forEach(function (classSet) {
  36541. nodes.push(Object(_BrowserParserCss__WEBPACK_IMPORTED_MODULE_1__["createNode"])(classSet, style, opts));
  36542. });
  36543. } else {
  36544. nodes.push(Object(_BrowserParserCss__WEBPACK_IMPORTED_MODULE_1__["createNode"])([], style, opts));
  36545. }
  36546. if (selectorsAdd) {
  36547. var lastNode = nodes[nodes.length - 1];
  36548. lastNode.selectorsAdd = selectorsAdd;
  36549. }
  36550. node = nodes;
  36551. }
  36552. return node;
  36553. }
  36554. };
  36555. });
  36556. /***/ }),
  36557. /***/ "./src/parser/model/ParserHtml.js":
  36558. /*!****************************************!*\
  36559. !*** ./src/parser/model/ParserHtml.js ***!
  36560. \****************************************/
  36561. /*! exports provided: default */
  36562. /***/ (function(module, __webpack_exports__, __webpack_require__) {
  36563. "use strict";
  36564. __webpack_require__.r(__webpack_exports__);
  36565. /* harmony import */ var _babel_runtime_helpers_typeof__WEBPACK_IMPORTED_MODULE_0__ = __webpack_require__(/*! @babel/runtime/helpers/typeof */ "./node_modules/@babel/runtime/helpers/typeof.js");
  36566. /* harmony import */ var _babel_runtime_helpers_typeof__WEBPACK_IMPORTED_MODULE_0___default = /*#__PURE__*/__webpack_require__.n(_babel_runtime_helpers_typeof__WEBPACK_IMPORTED_MODULE_0__);
  36567. /* harmony import */ var underscore__WEBPACK_IMPORTED_MODULE_1__ = __webpack_require__(/*! underscore */ "./node_modules/underscore/underscore.js");
  36568. /* harmony import */ var underscore__WEBPACK_IMPORTED_MODULE_1___default = /*#__PURE__*/__webpack_require__.n(underscore__WEBPACK_IMPORTED_MODULE_1__);
  36569. /* harmony default export */ __webpack_exports__["default"] = (function (config) {
  36570. var TEXT_NODE = 'span';
  36571. var c = config;
  36572. var modelAttrStart = 'data-gjs-';
  36573. return {
  36574. compTypes: '',
  36575. modelAttrStart: modelAttrStart,
  36576. /**
  36577. * Extract component props from an attribute object
  36578. * @param {Object} attr
  36579. * @returns {Object} An object containing props and attributes without them
  36580. */
  36581. splitPropsFromAttr: function splitPropsFromAttr() {
  36582. var _this = this;
  36583. var attr = arguments.length > 0 && arguments[0] !== undefined ? arguments[0] : {};
  36584. var props = {};
  36585. var attrs = {};
  36586. Object(underscore__WEBPACK_IMPORTED_MODULE_1__["each"])(attr, function (value, key) {
  36587. if (key.indexOf(_this.modelAttrStart) === 0) {
  36588. var modelAttr = key.replace(modelAttrStart, '');
  36589. var valueLen = value.length;
  36590. var valStr = value && Object(underscore__WEBPACK_IMPORTED_MODULE_1__["isString"])(value);
  36591. var firstChar = valStr && value.substr(0, 1);
  36592. var lastChar = valStr && value.substr(valueLen - 1);
  36593. value = value === 'true' ? true : value;
  36594. value = value === 'false' ? false : value; // Try to parse JSON where it's possible
  36595. // I can get false positive here (eg. a selector '[data-attr]')
  36596. // so put it under try/catch and let fail silently
  36597. try {
  36598. value = firstChar == '{' && lastChar == '}' || firstChar == '[' && lastChar == ']' ? JSON.parse(value) : value;
  36599. } catch (e) {}
  36600. props[modelAttr] = value;
  36601. } else {
  36602. attrs[key] = value;
  36603. }
  36604. });
  36605. return {
  36606. props: props,
  36607. attrs: attrs
  36608. };
  36609. },
  36610. /**
  36611. * Parse style string to object
  36612. * @param {string} str
  36613. * @return {Object}
  36614. * @example
  36615. * var stl = ParserHtml.parseStyle('color:black; width:100px; test:value;');
  36616. * console.log(stl);
  36617. * // {color: 'black', width: '100px', test: 'value'}
  36618. */
  36619. parseStyle: function parseStyle(str) {
  36620. var result = {};
  36621. var decls = str.split(';');
  36622. for (var i = 0, len = decls.length; i < len; i++) {
  36623. var decl = decls[i].trim();
  36624. if (!decl) continue;
  36625. var prop = decl.split(':');
  36626. result[prop[0].trim()] = prop.slice(1).join(':').trim();
  36627. }
  36628. return result;
  36629. },
  36630. /**
  36631. * Parse class string to array
  36632. * @param {string} str
  36633. * @return {Array<string>}
  36634. * @example
  36635. * var res = ParserHtml.parseClass('test1 test2 test3');
  36636. * console.log(res);
  36637. * // ['test1', 'test2', 'test3']
  36638. */
  36639. parseClass: function parseClass(str) {
  36640. var result = [];
  36641. var cls = str.split(' ');
  36642. for (var i = 0, len = cls.length; i < len; i++) {
  36643. var cl = cls[i].trim();
  36644. if (!cl) continue;
  36645. result.push(cl);
  36646. }
  36647. return result;
  36648. },
  36649. /**
  36650. * Get data from the node element
  36651. * @param {HTMLElement} el DOM element to traverse
  36652. * @return {Array<Object>}
  36653. */
  36654. parseNode: function parseNode(el) {
  36655. var result = [];
  36656. var nodes = el.childNodes;
  36657. for (var i = 0, len = nodes.length; i < len; i++) {
  36658. var node = nodes[i];
  36659. var attrs = node.attributes || [];
  36660. var attrsLen = attrs.length;
  36661. var nodePrev = result[result.length - 1];
  36662. var nodeChild = node.childNodes.length;
  36663. var ct = this.compTypes;
  36664. var model = {}; // Start with understanding what kind of component it is
  36665. if (ct) {
  36666. var obj = '';
  36667. var type = node.getAttribute && node.getAttribute("".concat(modelAttrStart, "type")); // If the type is already defined, use it
  36668. if (type) {
  36669. model = {
  36670. type: type
  36671. };
  36672. } else {
  36673. // Iterate over all available Component Types and
  36674. // the first with a valid result will be that component
  36675. for (var it = 0; it < ct.length; it++) {
  36676. var compType = ct[it];
  36677. obj = compType.model.isComponent(node);
  36678. if (obj) {
  36679. if (_babel_runtime_helpers_typeof__WEBPACK_IMPORTED_MODULE_0___default()(obj) !== 'object') {
  36680. obj = {
  36681. type: compType.id
  36682. };
  36683. }
  36684. break;
  36685. }
  36686. }
  36687. model = obj;
  36688. }
  36689. } // Set tag name if not yet done
  36690. if (!model.tagName) {
  36691. model.tagName = node.tagName ? node.tagName.toLowerCase() : '';
  36692. }
  36693. if (attrsLen) {
  36694. model.attributes = {};
  36695. } // Parse attributes
  36696. for (var j = 0; j < attrsLen; j++) {
  36697. var nodeName = attrs[j].nodeName;
  36698. var nodeValue = attrs[j].nodeValue; // Isolate attributes
  36699. if (nodeName == 'style') {
  36700. model.style = this.parseStyle(nodeValue);
  36701. } else if (nodeName == 'class') {
  36702. model.classes = this.parseClass(nodeValue);
  36703. } else if (nodeName == 'contenteditable') {
  36704. continue;
  36705. } else if (nodeName.indexOf(modelAttrStart) === 0) {
  36706. var modelAttr = nodeName.replace(modelAttrStart, '');
  36707. var valueLen = nodeValue.length;
  36708. var firstChar = nodeValue && nodeValue.substr(0, 1);
  36709. var lastChar = nodeValue && nodeValue.substr(valueLen - 1);
  36710. nodeValue = nodeValue === 'true' ? true : nodeValue;
  36711. nodeValue = nodeValue === 'false' ? false : nodeValue; // Try to parse JSON where it's possible
  36712. // I can get false positive here (eg. a selector '[data-attr]')
  36713. // so put it under try/catch and let fail silently
  36714. try {
  36715. nodeValue = firstChar == '{' && lastChar == '}' || firstChar == '[' && lastChar == ']' ? JSON.parse(nodeValue) : nodeValue;
  36716. } catch (e) {}
  36717. model[modelAttr] = nodeValue;
  36718. } else {
  36719. model.attributes[nodeName] = nodeValue;
  36720. }
  36721. } // Check for nested elements but avoid it if already provided
  36722. if (nodeChild && !model.components) {
  36723. // Avoid infinite nested text nodes
  36724. var firstChild = node.childNodes[0]; // If there is only one child and it's a TEXTNODE
  36725. // just make it content of the current node
  36726. if (nodeChild === 1 && firstChild.nodeType === 3) {
  36727. !model.type && (model.type = 'text');
  36728. model.content = firstChild.nodeValue;
  36729. } else {
  36730. model.components = this.parseNode(node);
  36731. }
  36732. } // Check if it's a text node and if could be moved to the prevous model
  36733. if (model.type == 'textnode') {
  36734. if (nodePrev && nodePrev.type == 'textnode') {
  36735. nodePrev.content += model.content;
  36736. continue;
  36737. } // Throw away empty nodes (keep spaces)
  36738. if (!config.keepEmptyTextNodes) {
  36739. var content = node.nodeValue;
  36740. if (content != ' ' && !content.trim()) {
  36741. continue;
  36742. }
  36743. }
  36744. } // If all children are texts and there is some textnode the parent should
  36745. // be text too otherwise I'm unable to edit texnodes
  36746. var comps = model.components;
  36747. if (!model.type && comps) {
  36748. var allTxt = 1;
  36749. var foundTextNode = 0;
  36750. for (var ci = 0; ci < comps.length; ci++) {
  36751. var comp = comps[ci];
  36752. var cType = comp.type;
  36753. if (['text', 'textnode'].indexOf(cType) < 0 && c.textTags.indexOf(comp.tagName) < 0) {
  36754. allTxt = 0;
  36755. break;
  36756. }
  36757. if (cType == 'textnode') {
  36758. foundTextNode = 1;
  36759. }
  36760. }
  36761. if (allTxt && foundTextNode) {
  36762. model.type = 'text';
  36763. }
  36764. } // If tagName is still empty and is not a textnode, do not push it
  36765. if (!model.tagName && model.type != 'textnode') {
  36766. continue;
  36767. }
  36768. result.push(model);
  36769. }
  36770. return result;
  36771. },
  36772. /**
  36773. * Parse HTML string to a desired model object
  36774. * @param {string} str HTML string
  36775. * @param {ParserCss} parserCss In case there is style tags inside HTML
  36776. * @return {Object}
  36777. */
  36778. parse: function parse(str, parserCss) {
  36779. var config = c.em && c.em.get('Config') || {};
  36780. var res = {
  36781. html: '',
  36782. css: ''
  36783. };
  36784. var el = document.createElement('div');
  36785. el.innerHTML = str;
  36786. var scripts = el.querySelectorAll('script');
  36787. var i = scripts.length; // Remove all scripts
  36788. if (!config.allowScripts) {
  36789. while (i--) {
  36790. scripts[i].parentNode.removeChild(scripts[i]);
  36791. }
  36792. } // Detach style tags and parse them
  36793. if (parserCss) {
  36794. var styleStr = '';
  36795. var styles = el.querySelectorAll('style');
  36796. var j = styles.length;
  36797. while (j--) {
  36798. styleStr = styles[j].innerHTML + styleStr;
  36799. styles[j].parentNode.removeChild(styles[j]);
  36800. }
  36801. if (styleStr) res.css = parserCss.parse(styleStr);
  36802. }
  36803. var result = this.parseNode(el);
  36804. if (result.length == 1) result = result[0];
  36805. res.html = result;
  36806. return res;
  36807. }
  36808. };
  36809. });
  36810. /***/ }),
  36811. /***/ "./src/plugin_manager/config/config.js":
  36812. /*!*********************************************!*\
  36813. !*** ./src/plugin_manager/config/config.js ***!
  36814. \*********************************************/
  36815. /*! exports provided: default */
  36816. /***/ (function(module, __webpack_exports__, __webpack_require__) {
  36817. "use strict";
  36818. __webpack_require__.r(__webpack_exports__);
  36819. /* harmony default export */ __webpack_exports__["default"] = ({
  36820. plugins: []
  36821. });
  36822. /***/ }),
  36823. /***/ "./src/plugin_manager/index.js":
  36824. /*!*************************************!*\
  36825. !*** ./src/plugin_manager/index.js ***!
  36826. \*************************************/
  36827. /*! exports provided: default */
  36828. /***/ (function(module, __webpack_exports__, __webpack_require__) {
  36829. "use strict";
  36830. __webpack_require__.r(__webpack_exports__);
  36831. /* harmony import */ var _config_config__WEBPACK_IMPORTED_MODULE_0__ = __webpack_require__(/*! ./config/config */ "./src/plugin_manager/config/config.js");
  36832. /* harmony default export */ __webpack_exports__["default"] = (function (config) {
  36833. var c = config || {}; // Set default options
  36834. for (var name in _config_config__WEBPACK_IMPORTED_MODULE_0__["default"]) {
  36835. if (!(name in c)) c[name] = _config_config__WEBPACK_IMPORTED_MODULE_0__["default"][name];
  36836. }
  36837. var plugins = {};
  36838. return {
  36839. /**
  36840. * Add new plugin. Plugins could not be overwritten
  36841. * @param {string} id Plugin ID
  36842. * @param {Function} plugin Function which contains all plugin logic
  36843. * @return {Function} The plugin function
  36844. * @example
  36845. * PluginManager.add('some-plugin', function(editor){
  36846. * editor.Commands.add('new-command', {
  36847. * run: function(editor, senderBtn){
  36848. * console.log('Executed new-command');
  36849. * }
  36850. * })
  36851. * });
  36852. */
  36853. add: function add(id, plugin) {
  36854. if (plugins[id]) {
  36855. return plugins[id];
  36856. }
  36857. plugins[id] = plugin;
  36858. return plugin;
  36859. },
  36860. /**
  36861. * Returns plugin by ID
  36862. * @param {string} id Plugin ID
  36863. * @return {Function|undefined} Plugin
  36864. * @example
  36865. * var plugin = PluginManager.get('some-plugin');
  36866. * plugin(editor);
  36867. */
  36868. get: function get(id) {
  36869. return plugins[id];
  36870. },
  36871. /**
  36872. * Returns object with all plugins
  36873. * @return {Object}
  36874. */
  36875. getAll: function getAll() {
  36876. return plugins;
  36877. }
  36878. };
  36879. });
  36880. /***/ }),
  36881. /***/ "./src/rich_text_editor/config/config.js":
  36882. /*!***********************************************!*\
  36883. !*** ./src/rich_text_editor/config/config.js ***!
  36884. \***********************************************/
  36885. /*! exports provided: default */
  36886. /***/ (function(module, __webpack_exports__, __webpack_require__) {
  36887. "use strict";
  36888. __webpack_require__.r(__webpack_exports__);
  36889. /* harmony default export */ __webpack_exports__["default"] = ({
  36890. stylePrefix: 'rte-',
  36891. // If true, moves the toolbar below the element when the top canvas
  36892. // edge is reached
  36893. adjustToolbar: 1,
  36894. // Default RTE actions
  36895. actions: ['bold', 'italic', 'underline', 'strikethrough', 'link']
  36896. });
  36897. /***/ }),
  36898. /***/ "./src/rich_text_editor/index.js":
  36899. /*!***************************************!*\
  36900. !*** ./src/rich_text_editor/index.js ***!
  36901. \***************************************/
  36902. /*! exports provided: default */
  36903. /***/ (function(module, __webpack_exports__, __webpack_require__) {
  36904. "use strict";
  36905. __webpack_require__.r(__webpack_exports__);
  36906. /* harmony import */ var _babel_runtime_helpers_toConsumableArray__WEBPACK_IMPORTED_MODULE_0__ = __webpack_require__(/*! @babel/runtime/helpers/toConsumableArray */ "./node_modules/@babel/runtime/helpers/toConsumableArray.js");
  36907. /* harmony import */ var _babel_runtime_helpers_toConsumableArray__WEBPACK_IMPORTED_MODULE_0___default = /*#__PURE__*/__webpack_require__.n(_babel_runtime_helpers_toConsumableArray__WEBPACK_IMPORTED_MODULE_0__);
  36908. /* harmony import */ var _babel_runtime_helpers_defineProperty__WEBPACK_IMPORTED_MODULE_1__ = __webpack_require__(/*! @babel/runtime/helpers/defineProperty */ "./node_modules/@babel/runtime/helpers/defineProperty.js");
  36909. /* harmony import */ var _babel_runtime_helpers_defineProperty__WEBPACK_IMPORTED_MODULE_1___default = /*#__PURE__*/__webpack_require__.n(_babel_runtime_helpers_defineProperty__WEBPACK_IMPORTED_MODULE_1__);
  36910. /* harmony import */ var _model_RichTextEditor__WEBPACK_IMPORTED_MODULE_2__ = __webpack_require__(/*! ./model/RichTextEditor */ "./src/rich_text_editor/model/RichTextEditor.js");
  36911. /* harmony import */ var utils_mixins__WEBPACK_IMPORTED_MODULE_3__ = __webpack_require__(/*! utils/mixins */ "./src/utils/mixins.js");
  36912. /* harmony import */ var _config_config__WEBPACK_IMPORTED_MODULE_4__ = __webpack_require__(/*! ./config/config */ "./src/rich_text_editor/config/config.js");
  36913. function ownKeys(object, enumerableOnly) { var keys = Object.keys(object); if (Object.getOwnPropertySymbols) { var symbols = Object.getOwnPropertySymbols(object); if (enumerableOnly) symbols = symbols.filter(function (sym) { return Object.getOwnPropertyDescriptor(object, sym).enumerable; }); keys.push.apply(keys, symbols); } return keys; }
  36914. function _objectSpread(target) { for (var i = 1; i < arguments.length; i++) { var source = arguments[i] != null ? arguments[i] : {}; if (i % 2) { ownKeys(source, true).forEach(function (key) { _babel_runtime_helpers_defineProperty__WEBPACK_IMPORTED_MODULE_1___default()(target, key, source[key]); }); } else if (Object.getOwnPropertyDescriptors) { Object.defineProperties(target, Object.getOwnPropertyDescriptors(source)); } else { ownKeys(source).forEach(function (key) { Object.defineProperty(target, key, Object.getOwnPropertyDescriptor(source, key)); }); } } return target; }
  36915. /**
  36916. * This module allows to customize the built-in toolbar of the Rich Text Editor and use commands from the [HTML Editing APIs](https://developer.mozilla.org/en-US/docs/Web/API/Document/execCommand).
  36917. * It's highly recommended to keep this toolbar as small as possible, especially from styling commands (eg. 'fontSize') and leave this task to the Style Manager
  36918. *
  36919. * You can customize the initial state of the module from the editor initialization, by passing the following [Configuration Object](https://github.com/artf/grapesjs/blob/master/src/rich_text_editor/config/config.js)
  36920. * ```js
  36921. * const editor = grapesjs.init({
  36922. * richTextEditor: {
  36923. * // options
  36924. * }
  36925. * })
  36926. * ```
  36927. *
  36928. * Once the editor is instantiated you can use its API. Before using these methods you should get the module from the instance
  36929. *
  36930. * ```js
  36931. * const rte = editor.RichTextEditor;
  36932. * ```
  36933. *
  36934. * * [add](#add)
  36935. * * [get](#get)
  36936. * * [getAll](#getall)
  36937. * * [remove](#remove)
  36938. * * [getToolbarEl](#gettoolbarel)
  36939. *
  36940. * @module RichTextEditor
  36941. */
  36942. /* harmony default export */ __webpack_exports__["default"] = (function () {
  36943. var config = {};
  36944. var toolbar, actions, lastEl, lastElPos, globalRte;
  36945. var hideToolbar = function hideToolbar() {
  36946. var style = toolbar.style;
  36947. var size = '-1000px';
  36948. style.top = size;
  36949. style.left = size;
  36950. style.display = 'none';
  36951. };
  36952. return {
  36953. customRte: null,
  36954. /**
  36955. * Name of the module
  36956. * @type {String}
  36957. * @private
  36958. */
  36959. name: 'RichTextEditor',
  36960. getConfig: function getConfig() {
  36961. return config;
  36962. },
  36963. /**
  36964. * Initialize module. Automatically called with a new instance of the editor
  36965. * @param {Object} opts Options
  36966. * @private
  36967. */
  36968. init: function init() {
  36969. var opts = arguments.length > 0 && arguments[0] !== undefined ? arguments[0] : {};
  36970. config = _objectSpread({}, _config_config__WEBPACK_IMPORTED_MODULE_4__["default"], {}, opts);
  36971. var ppfx = config.pStylePrefix;
  36972. if (ppfx) {
  36973. config.stylePrefix = ppfx + config.stylePrefix;
  36974. }
  36975. this.pfx = config.stylePrefix;
  36976. actions = config.actions || [];
  36977. toolbar = document.createElement('div');
  36978. toolbar.className = "".concat(ppfx, "rte-toolbar ").concat(ppfx, "one-bg");
  36979. globalRte = this.initRte(document.createElement('div')); //Avoid closing on toolbar clicking
  36980. Object(utils_mixins__WEBPACK_IMPORTED_MODULE_3__["on"])(toolbar, 'mousedown', function (e) {
  36981. return e.stopPropagation();
  36982. });
  36983. return this;
  36984. },
  36985. destroy: function destroy() {
  36986. var customRte = this.customRte;
  36987. globalRte && globalRte.destroy();
  36988. customRte && customRte.destroy && customRte.destroy();
  36989. toolbar = 0;
  36990. globalRte = 0;
  36991. this.actionbar = 0;
  36992. this.actions = 0;
  36993. },
  36994. /**
  36995. * Post render callback
  36996. * @param {View} ev
  36997. * @private
  36998. */
  36999. postRender: function postRender(ev) {
  37000. var canvas = ev.model.get('Canvas');
  37001. toolbar.style.pointerEvents = 'all';
  37002. hideToolbar();
  37003. canvas.getToolsEl().appendChild(toolbar);
  37004. },
  37005. /**
  37006. * Init the built-in RTE
  37007. * @param {HTMLElement} el
  37008. * @return {RichTextEditor}
  37009. * @private
  37010. */
  37011. initRte: function initRte(el) {
  37012. var pfx = this.pfx;
  37013. var actionbarContainer = toolbar;
  37014. var actionbar = this.actionbar;
  37015. var actions = this.actions || _babel_runtime_helpers_toConsumableArray__WEBPACK_IMPORTED_MODULE_0___default()(config.actions);
  37016. var classes = {
  37017. actionbar: "".concat(pfx, "actionbar"),
  37018. button: "".concat(pfx, "action"),
  37019. active: "".concat(pfx, "active"),
  37020. inactive: "".concat(pfx, "inactive"),
  37021. disabled: "".concat(pfx, "disabled")
  37022. };
  37023. var rte = new _model_RichTextEditor__WEBPACK_IMPORTED_MODULE_2__["default"]({
  37024. el: el,
  37025. classes: classes,
  37026. actions: actions,
  37027. actionbar: actionbar,
  37028. actionbarContainer: actionbarContainer
  37029. });
  37030. globalRte && globalRte.setEl(el);
  37031. if (rte.actionbar) {
  37032. this.actionbar = rte.actionbar;
  37033. }
  37034. if (rte.actions) {
  37035. this.actions = rte.actions;
  37036. }
  37037. return rte;
  37038. },
  37039. /**
  37040. * Add a new action to the built-in RTE toolbar
  37041. * @param {string} name Action name
  37042. * @param {Object} action Action options
  37043. * @example
  37044. * rte.add('bold', {
  37045. * icon: '<b>B</b>',
  37046. * attributes: {title: 'Bold'},
  37047. * result: rte => rte.exec('bold')
  37048. * });
  37049. * rte.add('link', {
  37050. * icon: document.getElementById('t'),
  37051. * attributes: {title: 'Link',}
  37052. * // Example on it's easy to wrap a selected content
  37053. * result: rte => rte.insertHTML(`<a href="#">${rte.selection()}</a>`)
  37054. * });
  37055. * // An example with fontSize
  37056. * rte.add('fontSize', {
  37057. * icon: `<select class="gjs-field">
  37058. * <option>1</option>
  37059. * <option>4</option>
  37060. * <option>7</option>
  37061. * </select>`,
  37062. * // Bind the 'result' on 'change' listener
  37063. * event: 'change',
  37064. * result: (rte, action) => rte.exec('fontSize', action.btn.firstChild.value),
  37065. * // Callback on any input change (mousedown, keydown, etc..)
  37066. * update: (rte, action) => {
  37067. * const value = rte.doc.queryCommandValue(action.name);
  37068. * if (value != 'false') { // value is a string
  37069. * action.btn.firstChild.value = value;
  37070. * }
  37071. * }
  37072. * })
  37073. * // An example with state
  37074. * const isValidAnchor = (rte) => {
  37075. * // a utility function to help determine if the selected is a valid anchor node
  37076. * const anchor = rte.selection().anchorNode;
  37077. * const parentNode = anchor && anchor.parentNode;
  37078. * const nextSibling = anchor && anchor.nextSibling;
  37079. * return (parentNode && parentNode.nodeName == 'A') || (nextSibling && nextSibling.nodeName == 'A')
  37080. * }
  37081. * rte.add('toggleAnchor', {
  37082. * icon: `<span style="transform:rotate(45deg)">&supdsub;</span>`,
  37083. * state: (rte, doc) => {
  37084. * if (rte && rte.selection()) {
  37085. * // `btnState` is a integer, -1 for disabled, 0 for inactive, 1 for active
  37086. * return isValidAnchor(rte) ? btnState.ACTIVE : btnState.INACTIVE;
  37087. * } else {
  37088. * return btnState.INACTIVE;
  37089. * }
  37090. * },
  37091. * result: (rte, action) => {
  37092. * if (isValidAnchor(rte)) {
  37093. * rte.exec('unlink');
  37094. * } else {
  37095. * rte.insertHTML(`<a class="link" href="">${rte.selection()}</a>`);
  37096. * }
  37097. * }
  37098. * })
  37099. */
  37100. add: function add(name) {
  37101. var action = arguments.length > 1 && arguments[1] !== undefined ? arguments[1] : {};
  37102. action.name = name;
  37103. globalRte.addAction(action, {
  37104. sync: 1
  37105. });
  37106. },
  37107. /**
  37108. * Get the action by its name
  37109. * @param {string} name Action name
  37110. * @return {Object}
  37111. * @example
  37112. * const action = rte.get('bold');
  37113. * // {name: 'bold', ...}
  37114. */
  37115. get: function get(name) {
  37116. var result;
  37117. globalRte.getActions().forEach(function (action) {
  37118. if (action.name == name) {
  37119. result = action;
  37120. }
  37121. });
  37122. return result;
  37123. },
  37124. /**
  37125. * Get all actions
  37126. * @return {Array}
  37127. */
  37128. getAll: function getAll() {
  37129. return globalRte.getActions();
  37130. },
  37131. /**
  37132. * Remove the action from the toolbar
  37133. * @param {string} name
  37134. * @return {Object} Removed action
  37135. * @example
  37136. * const action = rte.remove('bold');
  37137. * // {name: 'bold', ...}
  37138. */
  37139. remove: function remove(name) {
  37140. var actions = this.getAll();
  37141. var action = this.get(name);
  37142. if (action) {
  37143. var btn = action.btn;
  37144. var index = actions.indexOf(action);
  37145. btn.parentNode.removeChild(btn);
  37146. actions.splice(index, 1);
  37147. }
  37148. return action;
  37149. },
  37150. /**
  37151. * Get the toolbar element
  37152. * @return {HTMLElement}
  37153. */
  37154. getToolbarEl: function getToolbarEl() {
  37155. return toolbar;
  37156. },
  37157. /**
  37158. * Triggered when the offset of the editor is changed
  37159. * @private
  37160. */
  37161. updatePosition: function updatePosition() {
  37162. var un = 'px';
  37163. var canvas = config.em.get('Canvas');
  37164. var _toolbar = toolbar,
  37165. style = _toolbar.style;
  37166. var pos = canvas.getTargetToElementFixed(lastEl, toolbar, {
  37167. event: 'rteToolbarPosUpdate'
  37168. });
  37169. style.top = pos.top + un;
  37170. style.left = 0 + un;
  37171. },
  37172. /**
  37173. * Enable rich text editor on the element
  37174. * @param {View} view Component view
  37175. * @param {Object} rte The instance of already defined RTE
  37176. * @private
  37177. * */
  37178. enable: function enable(view, rte) {
  37179. lastEl = view.el;
  37180. var canvas = config.em.get('Canvas');
  37181. var em = config.em;
  37182. var el = view.getChildrenContainer();
  37183. var customRte = this.customRte;
  37184. lastElPos = canvas.getElementPos(lastEl);
  37185. toolbar.style.display = '';
  37186. rte = customRte ? customRte.enable(el, rte) : this.initRte(el).enable();
  37187. if (em) {
  37188. setTimeout(this.updatePosition.bind(this), 0);
  37189. var event = 'change:canvasOffset canvasScroll frame:scroll component:update';
  37190. em.off(event, this.updatePosition, this);
  37191. em.on(event, this.updatePosition, this);
  37192. em.trigger('rte:enable', view, rte);
  37193. }
  37194. return rte;
  37195. },
  37196. /**
  37197. * Unbind rich text editor from the element
  37198. * @param {View} view
  37199. * @param {Object} rte The instance of already defined RTE
  37200. * @private
  37201. * */
  37202. disable: function disable(view, rte) {
  37203. var em = config.em;
  37204. var customRte = this.customRte;
  37205. var el = view.getChildrenContainer();
  37206. if (customRte) {
  37207. customRte.disable(el, rte);
  37208. } else {
  37209. rte && rte.disable();
  37210. }
  37211. hideToolbar();
  37212. em && em.trigger('rte:disable', view, rte);
  37213. }
  37214. };
  37215. });
  37216. /***/ }),
  37217. /***/ "./src/rich_text_editor/model/RichTextEditor.js":
  37218. /*!******************************************************!*\
  37219. !*** ./src/rich_text_editor/model/RichTextEditor.js ***!
  37220. \******************************************************/
  37221. /*! exports provided: default */
  37222. /***/ (function(module, __webpack_exports__, __webpack_require__) {
  37223. "use strict";
  37224. __webpack_require__.r(__webpack_exports__);
  37225. /* harmony export (binding) */ __webpack_require__.d(__webpack_exports__, "default", function() { return RichTextEditor; });
  37226. /* harmony import */ var _babel_runtime_helpers_defineProperty__WEBPACK_IMPORTED_MODULE_0__ = __webpack_require__(/*! @babel/runtime/helpers/defineProperty */ "./node_modules/@babel/runtime/helpers/defineProperty.js");
  37227. /* harmony import */ var _babel_runtime_helpers_defineProperty__WEBPACK_IMPORTED_MODULE_0___default = /*#__PURE__*/__webpack_require__.n(_babel_runtime_helpers_defineProperty__WEBPACK_IMPORTED_MODULE_0__);
  37228. /* harmony import */ var _babel_runtime_helpers_classCallCheck__WEBPACK_IMPORTED_MODULE_1__ = __webpack_require__(/*! @babel/runtime/helpers/classCallCheck */ "./node_modules/@babel/runtime/helpers/classCallCheck.js");
  37229. /* harmony import */ var _babel_runtime_helpers_classCallCheck__WEBPACK_IMPORTED_MODULE_1___default = /*#__PURE__*/__webpack_require__.n(_babel_runtime_helpers_classCallCheck__WEBPACK_IMPORTED_MODULE_1__);
  37230. /* harmony import */ var _babel_runtime_helpers_createClass__WEBPACK_IMPORTED_MODULE_2__ = __webpack_require__(/*! @babel/runtime/helpers/createClass */ "./node_modules/@babel/runtime/helpers/createClass.js");
  37231. /* harmony import */ var _babel_runtime_helpers_createClass__WEBPACK_IMPORTED_MODULE_2___default = /*#__PURE__*/__webpack_require__.n(_babel_runtime_helpers_createClass__WEBPACK_IMPORTED_MODULE_2__);
  37232. /* harmony import */ var utils_mixins__WEBPACK_IMPORTED_MODULE_3__ = __webpack_require__(/*! utils/mixins */ "./src/utils/mixins.js");
  37233. function ownKeys(object, enumerableOnly) { var keys = Object.keys(object); if (Object.getOwnPropertySymbols) { var symbols = Object.getOwnPropertySymbols(object); if (enumerableOnly) symbols = symbols.filter(function (sym) { return Object.getOwnPropertyDescriptor(object, sym).enumerable; }); keys.push.apply(keys, symbols); } return keys; }
  37234. function _objectSpread(target) { for (var i = 1; i < arguments.length; i++) { var source = arguments[i] != null ? arguments[i] : {}; if (i % 2) { ownKeys(source, true).forEach(function (key) { _babel_runtime_helpers_defineProperty__WEBPACK_IMPORTED_MODULE_0___default()(target, key, source[key]); }); } else if (Object.getOwnPropertyDescriptors) { Object.defineProperties(target, Object.getOwnPropertyDescriptors(source)); } else { ownKeys(source).forEach(function (key) { Object.defineProperty(target, key, Object.getOwnPropertyDescriptor(source, key)); }); } } return target; }
  37235. // The initial version of this RTE was borrowed from https://github.com/jaredreich/pell
  37236. // and adapted to the GrapesJS's need
  37237. var RTE_KEY = '_rte';
  37238. var btnState = {
  37239. ACTIVE: 1,
  37240. INACTIVE: 0,
  37241. DISABLED: -1
  37242. };
  37243. var isValidAnchor = function isValidAnchor(rte) {
  37244. var anchor = rte.selection().anchorNode;
  37245. var parentNode = anchor && anchor.parentNode;
  37246. var nextSibling = anchor && anchor.nextSibling;
  37247. return parentNode && parentNode.nodeName == 'A' || nextSibling && nextSibling.nodeName == 'A';
  37248. };
  37249. var defActions = {
  37250. bold: {
  37251. name: 'bold',
  37252. icon: '<b>B</b>',
  37253. attributes: {
  37254. title: 'Bold'
  37255. },
  37256. result: function result(rte) {
  37257. return rte.exec('bold');
  37258. }
  37259. },
  37260. italic: {
  37261. name: 'italic',
  37262. icon: '<i>I</i>',
  37263. attributes: {
  37264. title: 'Italic'
  37265. },
  37266. result: function result(rte) {
  37267. return rte.exec('italic');
  37268. }
  37269. },
  37270. underline: {
  37271. name: 'underline',
  37272. icon: '<u>U</u>',
  37273. attributes: {
  37274. title: 'Underline'
  37275. },
  37276. result: function result(rte) {
  37277. return rte.exec('underline');
  37278. }
  37279. },
  37280. strikethrough: {
  37281. name: 'strikethrough',
  37282. icon: '<strike>S</strike>',
  37283. attributes: {
  37284. title: 'Strike-through'
  37285. },
  37286. result: function result(rte) {
  37287. return rte.exec('strikeThrough');
  37288. }
  37289. },
  37290. link: {
  37291. icon: "<span style=\"transform:rotate(45deg)\">&supdsub;</span>",
  37292. name: 'link',
  37293. attributes: {
  37294. style: 'font-size:1.4rem;padding:0 4px 2px;',
  37295. title: 'Link'
  37296. },
  37297. state: function state(rte, doc) {
  37298. if (rte && rte.selection()) {
  37299. return isValidAnchor(rte) ? btnState.ACTIVE : btnState.INACTIVE;
  37300. } else {
  37301. return btnState.INACTIVE;
  37302. }
  37303. },
  37304. result: function result(rte) {
  37305. if (isValidAnchor(rte)) {
  37306. rte.exec('unlink');
  37307. } else {
  37308. rte.insertHTML("<a class=\"link\" href=\"\">".concat(rte.selection(), "</a>"));
  37309. }
  37310. }
  37311. }
  37312. };
  37313. var RichTextEditor =
  37314. /*#__PURE__*/
  37315. function () {
  37316. function RichTextEditor() {
  37317. var _this = this;
  37318. var settings = arguments.length > 0 && arguments[0] !== undefined ? arguments[0] : {};
  37319. _babel_runtime_helpers_classCallCheck__WEBPACK_IMPORTED_MODULE_1___default()(this, RichTextEditor);
  37320. var el = settings.el;
  37321. if (el[RTE_KEY]) {
  37322. return el[RTE_KEY];
  37323. }
  37324. el[RTE_KEY] = this;
  37325. this.setEl(el);
  37326. this.updateActiveActions = this.updateActiveActions.bind(this);
  37327. var settAct = settings.actions || [];
  37328. settAct.forEach(function (action, i) {
  37329. if (typeof action === 'string') {
  37330. action = defActions[action];
  37331. } else if (defActions[action.name]) {
  37332. action = _objectSpread({}, defActions[action.name], {}, action);
  37333. }
  37334. settAct[i] = action;
  37335. });
  37336. var actions = settAct.length ? settAct : Object.keys(defActions).map(function (action) {
  37337. return defActions[action];
  37338. });
  37339. settings.classes = _objectSpread({}, {
  37340. actionbar: 'actionbar',
  37341. button: 'action',
  37342. active: 'active',
  37343. disabled: 'disabled',
  37344. inactive: 'inactive'
  37345. }, {}, settings.classes);
  37346. var classes = settings.classes;
  37347. var actionbar = settings.actionbar;
  37348. this.actionbar = actionbar;
  37349. this.settings = settings;
  37350. this.classes = classes;
  37351. this.actions = actions;
  37352. if (!actionbar) {
  37353. var actionbarCont = settings.actionbarContainer;
  37354. actionbar = document.createElement('div');
  37355. actionbar.className = classes.actionbar;
  37356. actionbarCont.appendChild(actionbar);
  37357. this.actionbar = actionbar;
  37358. actions.forEach(function (action) {
  37359. return _this.addAction(action);
  37360. });
  37361. }
  37362. settings.styleWithCSS && this.exec('styleWithCSS');
  37363. this.syncActions();
  37364. return this;
  37365. }
  37366. _babel_runtime_helpers_createClass__WEBPACK_IMPORTED_MODULE_2___default()(RichTextEditor, [{
  37367. key: "destroy",
  37368. value: function destroy() {
  37369. this.el = 0;
  37370. this.doc = 0;
  37371. this.actionbar = 0;
  37372. this.settings = {};
  37373. this.classes = {};
  37374. this.actions = [];
  37375. }
  37376. }, {
  37377. key: "setEl",
  37378. value: function setEl(el) {
  37379. this.el = el;
  37380. this.doc = el.ownerDocument;
  37381. }
  37382. }, {
  37383. key: "updateActiveActions",
  37384. value: function updateActiveActions() {
  37385. var _this2 = this;
  37386. this.getActions().forEach(function (action) {
  37387. var btn = action.btn;
  37388. var update = action.update;
  37389. var _this2$classes = _objectSpread({}, _this2.classes),
  37390. active = _this2$classes.active,
  37391. inactive = _this2$classes.inactive,
  37392. disabled = _this2$classes.disabled;
  37393. var state = action.state;
  37394. var name = action.name;
  37395. var doc = _this2.doc;
  37396. btn.className = btn.className.replace(active, '').trim();
  37397. btn.className = btn.className.replace(inactive, '').trim();
  37398. btn.className = btn.className.replace(disabled, '').trim(); // if there is a state function, which depicts the state,
  37399. // i.e. `active`, `disabled`, then call it
  37400. if (state) {
  37401. switch (state(_this2, doc)) {
  37402. case btnState.ACTIVE:
  37403. btn.className += " ".concat(active);
  37404. break;
  37405. case btnState.INACTIVE:
  37406. btn.className += " ".concat(inactive);
  37407. break;
  37408. case btnState.DISABLED:
  37409. btn.className += " ".concat(disabled);
  37410. break;
  37411. }
  37412. } else {
  37413. // otherwise default to checking if the name command is supported & enabled
  37414. if (doc.queryCommandSupported(name) && doc.queryCommandState(name)) {
  37415. btn.className += " ".concat(active);
  37416. }
  37417. }
  37418. update && update(_this2, action);
  37419. });
  37420. }
  37421. }, {
  37422. key: "enable",
  37423. value: function enable() {
  37424. if (this.enabled) {
  37425. return this;
  37426. }
  37427. this.actionbarEl().style.display = '';
  37428. this.el.contentEditable = true;
  37429. Object(utils_mixins__WEBPACK_IMPORTED_MODULE_3__["on"])(this.el, 'mouseup keyup', this.updateActiveActions);
  37430. this.syncActions();
  37431. this.updateActiveActions();
  37432. this.el.focus();
  37433. this.enabled = 1;
  37434. return this;
  37435. }
  37436. }, {
  37437. key: "disable",
  37438. value: function disable() {
  37439. this.actionbarEl().style.display = 'none';
  37440. this.el.contentEditable = false;
  37441. Object(utils_mixins__WEBPACK_IMPORTED_MODULE_3__["off"])(this.el, 'mouseup keyup', this.updateActiveActions);
  37442. this.enabled = 0;
  37443. return this;
  37444. }
  37445. /**
  37446. * Sync actions with the current RTE
  37447. */
  37448. }, {
  37449. key: "syncActions",
  37450. value: function syncActions() {
  37451. var _this3 = this;
  37452. this.getActions().forEach(function (action) {
  37453. if (_this3.settings.actionbar) {
  37454. if (!action.state || action.state && action.state(_this3, _this3.doc) >= 0) {
  37455. var event = action.event || 'click';
  37456. action.btn["on".concat(event)] = function (e) {
  37457. action.result(_this3, action);
  37458. _this3.updateActiveActions();
  37459. };
  37460. }
  37461. }
  37462. });
  37463. }
  37464. /**
  37465. * Add new action to the actionbar
  37466. * @param {Object} action
  37467. * @param {Object} [opts={}]
  37468. */
  37469. }, {
  37470. key: "addAction",
  37471. value: function addAction(action) {
  37472. var opts = arguments.length > 1 && arguments[1] !== undefined ? arguments[1] : {};
  37473. var sync = opts.sync;
  37474. var btn = document.createElement('span');
  37475. var icon = action.icon;
  37476. var attr = action.attributes || {};
  37477. btn.className = this.classes.button;
  37478. action.btn = btn;
  37479. for (var key in attr) {
  37480. btn.setAttribute(key, attr[key]);
  37481. }
  37482. if (typeof icon == 'string') {
  37483. btn.innerHTML = icon;
  37484. } else {
  37485. btn.appendChild(icon);
  37486. }
  37487. this.actionbarEl().appendChild(btn);
  37488. if (sync) {
  37489. this.actions.push(action);
  37490. this.syncActions();
  37491. }
  37492. }
  37493. /**
  37494. * Get the array of current actions
  37495. * @return {Array}
  37496. */
  37497. }, {
  37498. key: "getActions",
  37499. value: function getActions() {
  37500. return this.actions;
  37501. }
  37502. /**
  37503. * Returns the Selection instance
  37504. * @return {Selection}
  37505. */
  37506. }, {
  37507. key: "selection",
  37508. value: function selection() {
  37509. return this.doc.getSelection();
  37510. }
  37511. /**
  37512. * Execute the command
  37513. * @param {string} command Command name
  37514. * @param {any} [value=null Command's arguments
  37515. */
  37516. }, {
  37517. key: "exec",
  37518. value: function exec(command) {
  37519. var value = arguments.length > 1 && arguments[1] !== undefined ? arguments[1] : null;
  37520. this.doc.execCommand(command, false, value);
  37521. }
  37522. /**
  37523. * Get the actionbar element
  37524. * @return {HTMLElement}
  37525. */
  37526. }, {
  37527. key: "actionbarEl",
  37528. value: function actionbarEl() {
  37529. return this.actionbar;
  37530. }
  37531. /**
  37532. * Set custom HTML to the selection, useful as the default 'insertHTML' command
  37533. * doesn't work in the same way on all browsers
  37534. * @param {string} value HTML string
  37535. */
  37536. }, {
  37537. key: "insertHTML",
  37538. value: function insertHTML(value) {
  37539. var lastNode;
  37540. var doc = this.doc;
  37541. var sel = doc.getSelection();
  37542. if (sel && sel.rangeCount) {
  37543. var node = doc.createElement('div');
  37544. var range = sel.getRangeAt(0);
  37545. range.deleteContents();
  37546. node.innerHTML = value;
  37547. Array.prototype.slice.call(node.childNodes).forEach(function (nd) {
  37548. range.insertNode(nd);
  37549. lastNode = nd;
  37550. });
  37551. sel.removeAllRanges();
  37552. sel.addRange(range);
  37553. this.el.focus();
  37554. }
  37555. }
  37556. }]);
  37557. return RichTextEditor;
  37558. }();
  37559. /***/ }),
  37560. /***/ "./src/selector_manager/config/config.js":
  37561. /*!***********************************************!*\
  37562. !*** ./src/selector_manager/config/config.js ***!
  37563. \***********************************************/
  37564. /*! exports provided: default */
  37565. /***/ (function(module, __webpack_exports__, __webpack_require__) {
  37566. "use strict";
  37567. __webpack_require__.r(__webpack_exports__);
  37568. /* harmony default export */ __webpack_exports__["default"] = ({
  37569. // Style prefix
  37570. stylePrefix: 'clm-',
  37571. // Specify the element to use as a container, string (query) or HTMLElement
  37572. // With the empty value, nothing will be rendered
  37573. appendTo: '',
  37574. // Default selectors
  37575. selectors: [],
  37576. // States
  37577. states: [{
  37578. name: 'hover'
  37579. }, {
  37580. name: 'active'
  37581. }, {
  37582. name: 'nth-of-type(2n)'
  37583. }],
  37584. // Custom selector name escaping strategy, eg.
  37585. // name => name.replace(' ', '_')
  37586. escapeName: 0,
  37587. // Custom selected name strategy (the string you see after 'Selected')
  37588. // ({ result, state, target }) => {
  37589. // return `${result} - ID: ${target.getId()}`
  37590. // }
  37591. selectedName: 0,
  37592. // Icon used to add new selector
  37593. iconAdd: '<svg viewBox="0 0 24 24"><path d="M19 13h-6v6h-2v-6H5v-2h6V5h2v6h6v2z"></path></svg>',
  37594. // Icon used to sync styles
  37595. iconSync: '<svg viewBox="0 0 24 24"><path d="M12 18c-3.31 0-6-2.69-6-6 0-1 .25-1.97.7-2.8L5.24 7.74A7.93 7.93 0 0 0 4 12c0 4.42 3.58 8 8 8v3l4-4-4-4m0-11V1L8 5l4 4V6c3.31 0 6 2.69 6 6 0 1-.25 1.97-.7 2.8l1.46 1.46A7.93 7.93 0 0 0 20 12c0-4.42-3.58-8-8-8z"></path></svg>',
  37596. // Icon to show when the selector is enabled
  37597. iconTagOn: '<svg viewBox="0 0 24 24"><path d="M19 19H5V5h10V3H5c-1.11 0-2 .89-2 2v14c0 1.1.9 2 2 2h14c1.1 0 2-.9 2-2v-8h-2m-11.09-.92L6.5 11.5 11 16 21 6l-1.41-1.42L11 13.17l-3.09-3.09z"></path></svg>',
  37598. // Icon to show when the selector is disabled
  37599. iconTagOff: '<svg viewBox="0 0 24 24"><path d="M19 3H5c-1.11 0-2 .89-2 2v14c0 1.1.9 2 2 2h14c1.1 0 2-.9 2-2V5a2 2 0 0 0-2-2m0 2v14H5V5h14z"></path></svg>',
  37600. // Icon used to remove the selector
  37601. iconTagRemove: '<svg viewBox="0 0 24 24"><path d="M19 6.41L17.59 5 12 10.59 6.41 5 5 6.41 10.59 12 5 17.59 6.41 19 12 13.41 17.59 19 19 17.59 13.41 12 19 6.41z"></path></svg>',
  37602. /**
  37603. * Custom render function for the Select Manager
  37604. * @example
  37605. * render: ({ el, labelHead, labelStates, labelInfo, }) => {
  37606. * // You can use the default `el` to extend/edit the current
  37607. * // DOM element of the Selector Manager
  37608. * const someEl = document.createElement('div');
  37609. * // ...
  37610. * el.appendChild(someEl);
  37611. * // no need to return anything from the function
  37612. *
  37613. * // Create and return a new DOM element
  37614. * const newEl = document.createElement('div');
  37615. * // ...
  37616. * return newEl;
  37617. *
  37618. * // Return an HTML string for a completely different layout.
  37619. * // Use `data-*` attributes to make the module recognize some elements:
  37620. * // `data-states` - Where to append state `<option>` elements (or just write yours)
  37621. * // `data-selectors` - Where to append selectors
  37622. * // `data-input` - Input element which is used to add new selectors
  37623. * // `data-add` - Element which triggers the add of a new selector on click
  37624. * // `data-sync-style` - Element which triggers the sync of styles (visible with `componentFirst` enabled)
  37625. * // `data-selected` - Where to print selected selectors
  37626. * return `
  37627. * <div class="my-sm-header">
  37628. * <div>${labelHead}</div>
  37629. * <div>
  37630. * <select data-states>
  37631. * <option value="">${labelStates}</option>
  37632. * </select>
  37633. * </div>
  37634. * </div>
  37635. * <div class="my-sm-body">
  37636. * <div data-selectors></div>
  37637. * <input data-input/>
  37638. * <span data-add>Add</span>
  37639. * <span data-sync-style>Sync</span>
  37640. * </div>
  37641. * <div class="my-sm-info">
  37642. * <div>${labelInfo}</div>
  37643. * <div data-selected></div>
  37644. * </div>
  37645. * `;
  37646. * }
  37647. */
  37648. render: 0,
  37649. // When you select a component in the canvas the selected Model (Component or CSS Rule)
  37650. // is passed to the StyleManager which will be then able to be styled, these are the cases:
  37651. // * Selected component doesn't have any classes: Component will be passed
  37652. // * Selected component has at least one class: The CSS Rule will be passed
  37653. //
  37654. // With this option enabled, also in the second case, the Component will be passed.
  37655. // This method allows to avoid styling classes directly and make, for example, some
  37656. // unintended changes below the visible canvas area (when components share same classes)
  37657. componentFirst: 0
  37658. });
  37659. /***/ }),
  37660. /***/ "./src/selector_manager/index.js":
  37661. /*!***************************************!*\
  37662. !*** ./src/selector_manager/index.js ***!
  37663. \***************************************/
  37664. /*! exports provided: default */
  37665. /***/ (function(module, __webpack_exports__, __webpack_require__) {
  37666. "use strict";
  37667. __webpack_require__.r(__webpack_exports__);
  37668. /* harmony import */ var _babel_runtime_helpers_defineProperty__WEBPACK_IMPORTED_MODULE_0__ = __webpack_require__(/*! @babel/runtime/helpers/defineProperty */ "./node_modules/@babel/runtime/helpers/defineProperty.js");
  37669. /* harmony import */ var _babel_runtime_helpers_defineProperty__WEBPACK_IMPORTED_MODULE_0___default = /*#__PURE__*/__webpack_require__.n(_babel_runtime_helpers_defineProperty__WEBPACK_IMPORTED_MODULE_0__);
  37670. /* harmony import */ var underscore__WEBPACK_IMPORTED_MODULE_1__ = __webpack_require__(/*! underscore */ "./node_modules/underscore/underscore.js");
  37671. /* harmony import */ var underscore__WEBPACK_IMPORTED_MODULE_1___default = /*#__PURE__*/__webpack_require__.n(underscore__WEBPACK_IMPORTED_MODULE_1__);
  37672. /* harmony import */ var utils_mixins__WEBPACK_IMPORTED_MODULE_2__ = __webpack_require__(/*! utils/mixins */ "./src/utils/mixins.js");
  37673. /* harmony import */ var _config_config__WEBPACK_IMPORTED_MODULE_3__ = __webpack_require__(/*! ./config/config */ "./src/selector_manager/config/config.js");
  37674. /* harmony import */ var _model_Selector__WEBPACK_IMPORTED_MODULE_4__ = __webpack_require__(/*! ./model/Selector */ "./src/selector_manager/model/Selector.js");
  37675. /* harmony import */ var _model_Selectors__WEBPACK_IMPORTED_MODULE_5__ = __webpack_require__(/*! ./model/Selectors */ "./src/selector_manager/model/Selectors.js");
  37676. /* harmony import */ var _view_ClassTagsView__WEBPACK_IMPORTED_MODULE_6__ = __webpack_require__(/*! ./view/ClassTagsView */ "./src/selector_manager/view/ClassTagsView.js");
  37677. function ownKeys(object, enumerableOnly) { var keys = Object.keys(object); if (Object.getOwnPropertySymbols) { var symbols = Object.getOwnPropertySymbols(object); if (enumerableOnly) symbols = symbols.filter(function (sym) { return Object.getOwnPropertyDescriptor(object, sym).enumerable; }); keys.push.apply(keys, symbols); } return keys; }
  37678. function _objectSpread(target) { for (var i = 1; i < arguments.length; i++) { var source = arguments[i] != null ? arguments[i] : {}; if (i % 2) { ownKeys(source, true).forEach(function (key) { _babel_runtime_helpers_defineProperty__WEBPACK_IMPORTED_MODULE_0___default()(target, key, source[key]); }); } else if (Object.getOwnPropertyDescriptors) { Object.defineProperties(target, Object.getOwnPropertyDescriptors(source)); } else { ownKeys(source).forEach(function (key) { Object.defineProperty(target, key, Object.getOwnPropertyDescriptor(source, key)); }); } } return target; }
  37679. /**
  37680. * Selectors in GrapesJS are used in CSS Composer inside Rules and in Components as classes. To illustrate this concept let's take
  37681. * a look at this code:
  37682. *
  37683. * ```css
  37684. * span > #send-btn.btn{
  37685. * ...
  37686. * }
  37687. * ```
  37688. * ```html
  37689. * <span>
  37690. * <button id="send-btn" class="btn"></button>
  37691. * </span>
  37692. * ```
  37693. *
  37694. * In this scenario we get:
  37695. * * span -> selector of type `tag`
  37696. * * send-btn -> selector of type `id`
  37697. * * btn -> selector of type `class`
  37698. *
  37699. * So, for example, being `btn` the same class entity it'll be easier to refactor and track things.
  37700. *
  37701. * You can customize the initial state of the module from the editor initialization, by passing the following [Configuration Object](https://github.com/artf/grapesjs/blob/master/src/selector_manager/config/config.js)
  37702. * ```js
  37703. * const editor = grapesjs.init({
  37704. * selectorManager: {
  37705. * // options
  37706. * }
  37707. * })
  37708. * ```
  37709. *
  37710. * Once the editor is instantiated you can use its API. Before using these methods you should get the module from the instance
  37711. *
  37712. * ```js
  37713. * const selectorManager = editor.SelectorManager;
  37714. * ```
  37715. *
  37716. * * [getConfig](#getconfig)
  37717. * * [add](#add)
  37718. * * [addClass](#addclass)
  37719. * * [get](#get)
  37720. * * [getAll](#getall)
  37721. * * [setState](#setstate)
  37722. * * [getState](#getstate)
  37723. *
  37724. * @module SelectorManager
  37725. */
  37726. var isId = function isId(str) {
  37727. return Object(underscore__WEBPACK_IMPORTED_MODULE_1__["isString"])(str) && str[0] == '#';
  37728. };
  37729. var isClass = function isClass(str) {
  37730. return Object(underscore__WEBPACK_IMPORTED_MODULE_1__["isString"])(str) && str[0] == '.';
  37731. };
  37732. /* harmony default export */ __webpack_exports__["default"] = (function (config) {
  37733. var c = config || {};
  37734. var selectors;
  37735. return {
  37736. Selector: _model_Selector__WEBPACK_IMPORTED_MODULE_4__["default"],
  37737. Selectors: _model_Selectors__WEBPACK_IMPORTED_MODULE_5__["default"],
  37738. /**
  37739. * Name of the module
  37740. * @type {String}
  37741. * @private
  37742. */
  37743. name: 'SelectorManager',
  37744. /**
  37745. * Get configuration object
  37746. * @return {Object}
  37747. */
  37748. getConfig: function getConfig() {
  37749. return c;
  37750. },
  37751. /**
  37752. * Initialize module. Automatically called with a new instance of the editor
  37753. * @param {Object} config Configurations
  37754. * @return {this}
  37755. * @private
  37756. */
  37757. init: function init() {
  37758. var conf = arguments.length > 0 && arguments[0] !== undefined ? arguments[0] : {};
  37759. c = _objectSpread({}, _config_config__WEBPACK_IMPORTED_MODULE_3__["default"], {}, conf);
  37760. var em = c.em;
  37761. var ppfx = c.pStylePrefix;
  37762. this.em = em;
  37763. if (ppfx) {
  37764. c.stylePrefix = ppfx + c.stylePrefix;
  37765. }
  37766. this.selectorTags = new _view_ClassTagsView__WEBPACK_IMPORTED_MODULE_6__["default"]({
  37767. collection: new _model_Selectors__WEBPACK_IMPORTED_MODULE_5__["default"]([], {
  37768. em: em,
  37769. config: c
  37770. }),
  37771. config: c
  37772. }); // Global selectors container
  37773. selectors = new _model_Selectors__WEBPACK_IMPORTED_MODULE_5__["default"](c.selectors);
  37774. selectors.on('add', function (model) {
  37775. return em.trigger('selector:add', model);
  37776. });
  37777. selectors.on('remove', function (model) {
  37778. return em.trigger('selector:remove', model);
  37779. });
  37780. selectors.on('change', function (model) {
  37781. return em.trigger('selector:update', model, model.previousAttributes(), model.changedAttributes());
  37782. });
  37783. em.on('change:state', function (m, value) {
  37784. return em.trigger('selector:state', value);
  37785. });
  37786. return this;
  37787. },
  37788. postRender: function postRender() {
  37789. var elTo = this.getConfig().appendTo;
  37790. if (elTo) {
  37791. var el = Object(underscore__WEBPACK_IMPORTED_MODULE_1__["isElement"])(elTo) ? elTo : document.querySelector(elTo);
  37792. el.appendChild(this.render([]));
  37793. }
  37794. },
  37795. select: function select(value) {
  37796. var opts = arguments.length > 1 && arguments[1] !== undefined ? arguments[1] : {};
  37797. var targets = Array.isArray(value) ? value : [value];
  37798. var toSelect = this.em.get('StyleManager').setTarget(targets, opts);
  37799. var res = toSelect.filter(function (i) {
  37800. return i;
  37801. }).map(function (sel) {
  37802. return Object(utils_mixins__WEBPACK_IMPORTED_MODULE_2__["isComponent"])(sel) ? sel : Object(utils_mixins__WEBPACK_IMPORTED_MODULE_2__["isRule"])(sel) && !sel.get('selectorsAdd') ? sel : sel.getSelectorsString();
  37803. });
  37804. this.selectorTags.componentChanged({
  37805. targets: res
  37806. });
  37807. return this;
  37808. },
  37809. /**
  37810. * Change the selector state
  37811. * @param {String} value State value
  37812. * @returns {this}
  37813. * @example
  37814. * selectorManager.setState('hover');
  37815. */
  37816. setState: function setState(value) {
  37817. this.em.setState(value);
  37818. return this;
  37819. },
  37820. /**
  37821. * Get the current selector state
  37822. * @returns {String}
  37823. */
  37824. getState: function getState() {
  37825. return this.em.setState();
  37826. },
  37827. addSelector: function addSelector(name) {
  37828. var opt = arguments.length > 1 && arguments[1] !== undefined ? arguments[1] : {};
  37829. var opts = _objectSpread({}, opt);
  37830. if (Object(underscore__WEBPACK_IMPORTED_MODULE_1__["isObject"])(name)) {
  37831. opts = name;
  37832. } else {
  37833. opts.name = name;
  37834. }
  37835. if (isId(opts.name)) {
  37836. opts.name = opts.name.substr(1);
  37837. opts.type = _model_Selector__WEBPACK_IMPORTED_MODULE_4__["default"].TYPE_ID;
  37838. } else if (isClass(opts.name)) {
  37839. opts.name = opts.name.substr(1);
  37840. }
  37841. if (opts.label && !opts.name) {
  37842. opts.name = this.escapeName(opts.label);
  37843. }
  37844. var cname = opts.name;
  37845. var selector = cname ? this.get(cname, opts.type) : selectors.where(opts)[0];
  37846. if (!selector) {
  37847. return selectors.add(opts, {
  37848. config: c
  37849. });
  37850. }
  37851. return selector;
  37852. },
  37853. getSelector: function getSelector(name) {
  37854. var type = arguments.length > 1 && arguments[1] !== undefined ? arguments[1] : _model_Selector__WEBPACK_IMPORTED_MODULE_4__["default"].TYPE_CLASS;
  37855. if (isId(name)) {
  37856. name = name.substr(1);
  37857. type = _model_Selector__WEBPACK_IMPORTED_MODULE_4__["default"].TYPE_ID;
  37858. } else if (isClass(name)) {
  37859. name = name.substr(1);
  37860. }
  37861. return selectors.where({
  37862. name: name,
  37863. type: type
  37864. })[0];
  37865. },
  37866. /**
  37867. * Add a new selector to collection if it's not already exists. Class type is a default one
  37868. * @param {String|Array} name Selector/s name
  37869. * @param {Object} opts Selector options
  37870. * @param {String} [opts.label=''] Label for the selector, if it's not provided the label will be the same as the name
  37871. * @param {String} [opts.type=1] Type of the selector. At the moment, only 'class' (1) is available
  37872. * @return {Model|Array}
  37873. * @example
  37874. * const selector = selectorManager.add('selectorName');
  37875. * // Same as
  37876. * const selector = selectorManager.add('selectorName', {
  37877. * type: 1,
  37878. * label: 'selectorName'
  37879. * });
  37880. * // Multiple selectors
  37881. * const selectors = selectorManager.add(['.class1', '.class2', '#id1']);
  37882. * */
  37883. add: function add(name) {
  37884. var _this = this;
  37885. var opts = arguments.length > 1 && arguments[1] !== undefined ? arguments[1] : {};
  37886. if (Object(underscore__WEBPACK_IMPORTED_MODULE_1__["isArray"])(name)) {
  37887. return name.map(function (item) {
  37888. return _this.addSelector(item, opts);
  37889. });
  37890. } else {
  37891. return this.addSelector(name, opts);
  37892. }
  37893. },
  37894. /**
  37895. * Add class selectors
  37896. * @param {Array|string} classes Array or string of classes
  37897. * @return {Array} Array of added selectors
  37898. * @example
  37899. * sm.addClass('class1');
  37900. * sm.addClass('class1 class2');
  37901. * sm.addClass(['class1', 'class2']);
  37902. * // -> [SelectorObject, ...]
  37903. */
  37904. addClass: function addClass(classes) {
  37905. var _this2 = this;
  37906. var added = [];
  37907. if (Object(underscore__WEBPACK_IMPORTED_MODULE_1__["isString"])(classes)) {
  37908. classes = classes.trim().split(' ');
  37909. }
  37910. classes.forEach(function (name) {
  37911. return added.push(_this2.addSelector(name));
  37912. });
  37913. return added;
  37914. },
  37915. /**
  37916. * Get the selector by its name
  37917. * @param {String|Array} name Selector name
  37918. * @param {String} type Selector type
  37919. * @return {Model|Array}
  37920. * @example
  37921. * const selector = selectorManager.get('selectorName');
  37922. * // or get an array
  37923. * const selectors = selectorManager.get(['class1', 'class2']);
  37924. * */
  37925. get: function get(name, type) {
  37926. var _this3 = this;
  37927. if (Object(underscore__WEBPACK_IMPORTED_MODULE_1__["isArray"])(name)) {
  37928. var result = [];
  37929. var _selectors = name.map(function (item) {
  37930. return _this3.getSelector(item);
  37931. }).filter(function (item) {
  37932. return item;
  37933. });
  37934. _selectors.forEach(function (item) {
  37935. return result.indexOf(item) < 0 && result.push(item);
  37936. });
  37937. return result;
  37938. } else {
  37939. return this.getSelector(name, type);
  37940. }
  37941. },
  37942. /**
  37943. * Get all selectors
  37944. * @return {Collection}
  37945. * */
  37946. getAll: function getAll() {
  37947. return selectors;
  37948. },
  37949. /**
  37950. * Return escaped selector name
  37951. * @param {String} name Selector name to escape
  37952. * @returns {String} Escaped name
  37953. */
  37954. escapeName: function escapeName(name) {
  37955. var _c = c,
  37956. escapeName = _c.escapeName;
  37957. return escapeName ? escapeName(name) : _model_Selector__WEBPACK_IMPORTED_MODULE_4__["default"].escapeName(name);
  37958. },
  37959. /**
  37960. * Render class selectors. If an array of selectors is provided a new instance of the collection will be rendered
  37961. * @param {Array<Object>} selectors
  37962. * @return {HTMLElement}
  37963. * @private
  37964. */
  37965. render: function render(selectors) {
  37966. if (selectors) {
  37967. this.selectorTags = new _view_ClassTagsView__WEBPACK_IMPORTED_MODULE_6__["default"]({
  37968. collection: new _model_Selectors__WEBPACK_IMPORTED_MODULE_5__["default"](selectors),
  37969. config: c
  37970. });
  37971. return this.selectorTags.render().el;
  37972. } else return this.selectorTags.render().el;
  37973. }
  37974. };
  37975. });
  37976. /***/ }),
  37977. /***/ "./src/selector_manager/model/Selector.js":
  37978. /*!************************************************!*\
  37979. !*** ./src/selector_manager/model/Selector.js ***!
  37980. \************************************************/
  37981. /*! exports provided: default */
  37982. /***/ (function(module, __webpack_exports__, __webpack_require__) {
  37983. "use strict";
  37984. __webpack_require__.r(__webpack_exports__);
  37985. /* harmony import */ var backbone__WEBPACK_IMPORTED_MODULE_0__ = __webpack_require__(/*! backbone */ "./node_modules/backbone/backbone.js");
  37986. /* harmony import */ var backbone__WEBPACK_IMPORTED_MODULE_0___default = /*#__PURE__*/__webpack_require__.n(backbone__WEBPACK_IMPORTED_MODULE_0__);
  37987. var TYPE_CLASS = 1;
  37988. var TYPE_ID = 2;
  37989. var Selector = backbone__WEBPACK_IMPORTED_MODULE_0___default.a.Model.extend({
  37990. idAttribute: 'name',
  37991. defaults: {
  37992. name: '',
  37993. label: '',
  37994. // Type of the selector
  37995. type: TYPE_CLASS,
  37996. // If not active it's not selectable by the style manager (uncheckboxed)
  37997. active: true,
  37998. // Can't be seen by the style manager, therefore even by the user
  37999. // Will be rendered only in export code
  38000. private: false,
  38001. // If true, can't be removed from the attacched element
  38002. protected: false
  38003. },
  38004. initialize: function initialize(props) {
  38005. var opts = arguments.length > 1 && arguments[1] !== undefined ? arguments[1] : {};
  38006. var _opts$config = opts.config,
  38007. config = _opts$config === void 0 ? {} : _opts$config;
  38008. var name = this.get('name');
  38009. var label = this.get('label');
  38010. if (!name) {
  38011. this.set('name', label);
  38012. } else if (!label) {
  38013. this.set('label', name);
  38014. }
  38015. var namePreEsc = this.get('name');
  38016. var escapeName = config.escapeName;
  38017. var nameEsc = escapeName ? escapeName(namePreEsc) : Selector.escapeName(namePreEsc);
  38018. this.set('name', nameEsc);
  38019. },
  38020. /**
  38021. * Get full selector name
  38022. * @return {string}
  38023. */
  38024. getFullName: function getFullName() {
  38025. var opts = arguments.length > 0 && arguments[0] !== undefined ? arguments[0] : {};
  38026. var escape = opts.escape;
  38027. var name = this.get('name');
  38028. var init = '';
  38029. switch (this.get('type')) {
  38030. case TYPE_CLASS:
  38031. init = '.';
  38032. break;
  38033. case TYPE_ID:
  38034. init = '#';
  38035. break;
  38036. }
  38037. return init + (escape ? escape(name) : name);
  38038. }
  38039. }, {
  38040. // All type selectors: https://developer.mozilla.org/it/docs/Web/CSS/CSS_Selectors
  38041. // Here I define only what I need
  38042. TYPE_CLASS: TYPE_CLASS,
  38043. TYPE_ID: TYPE_ID,
  38044. /**
  38045. * Escape string
  38046. * @param {string} name
  38047. * @return {string}
  38048. * @private
  38049. */
  38050. escapeName: function escapeName(name) {
  38051. return "".concat(name).trim().replace(/([^a-z0-9\w-\:]+)/gi, '-');
  38052. }
  38053. });
  38054. /* harmony default export */ __webpack_exports__["default"] = (Selector);
  38055. /***/ }),
  38056. /***/ "./src/selector_manager/model/Selectors.js":
  38057. /*!*************************************************!*\
  38058. !*** ./src/selector_manager/model/Selectors.js ***!
  38059. \*************************************************/
  38060. /*! exports provided: default */
  38061. /***/ (function(module, __webpack_exports__, __webpack_require__) {
  38062. "use strict";
  38063. __webpack_require__.r(__webpack_exports__);
  38064. /* harmony import */ var underscore__WEBPACK_IMPORTED_MODULE_0__ = __webpack_require__(/*! underscore */ "./node_modules/underscore/underscore.js");
  38065. /* harmony import */ var underscore__WEBPACK_IMPORTED_MODULE_0___default = /*#__PURE__*/__webpack_require__.n(underscore__WEBPACK_IMPORTED_MODULE_0__);
  38066. /* harmony import */ var backbone__WEBPACK_IMPORTED_MODULE_1__ = __webpack_require__(/*! backbone */ "./node_modules/backbone/backbone.js");
  38067. /* harmony import */ var backbone__WEBPACK_IMPORTED_MODULE_1___default = /*#__PURE__*/__webpack_require__.n(backbone__WEBPACK_IMPORTED_MODULE_1__);
  38068. /* harmony import */ var _Selector__WEBPACK_IMPORTED_MODULE_2__ = __webpack_require__(/*! ./Selector */ "./src/selector_manager/model/Selector.js");
  38069. /* harmony default export */ __webpack_exports__["default"] = (backbone__WEBPACK_IMPORTED_MODULE_1___default.a.Collection.extend({
  38070. model: _Selector__WEBPACK_IMPORTED_MODULE_2__["default"],
  38071. modelId: function modelId(attr) {
  38072. return "".concat(attr.name, "_").concat(attr.type || _Selector__WEBPACK_IMPORTED_MODULE_2__["default"].TYPE_CLASS);
  38073. },
  38074. getStyleable: function getStyleable() {
  38075. return Object(underscore__WEBPACK_IMPORTED_MODULE_0__["filter"])(this.models, function (item) {
  38076. return item.get('active') && !item.get('private');
  38077. });
  38078. },
  38079. getValid: function getValid() {
  38080. var _ref = arguments.length > 0 && arguments[0] !== undefined ? arguments[0] : {},
  38081. noDisabled = _ref.noDisabled;
  38082. return Object(underscore__WEBPACK_IMPORTED_MODULE_0__["filter"])(this.models, function (item) {
  38083. return !item.get('private');
  38084. }).filter(function (item) {
  38085. return noDisabled ? item.get('active') : 1;
  38086. });
  38087. },
  38088. getFullString: function getFullString(collection) {
  38089. var opts = arguments.length > 1 && arguments[1] !== undefined ? arguments[1] : {};
  38090. var result = [];
  38091. var coll = collection || this;
  38092. coll.forEach(function (selector) {
  38093. return result.push(selector.getFullName(opts));
  38094. });
  38095. return result.join('').trim();
  38096. }
  38097. }));
  38098. /***/ }),
  38099. /***/ "./src/selector_manager/view/ClassTagView.js":
  38100. /*!***************************************************!*\
  38101. !*** ./src/selector_manager/view/ClassTagView.js ***!
  38102. \***************************************************/
  38103. /*! exports provided: default */
  38104. /***/ (function(module, __webpack_exports__, __webpack_require__) {
  38105. "use strict";
  38106. __webpack_require__.r(__webpack_exports__);
  38107. /* harmony import */ var backbone__WEBPACK_IMPORTED_MODULE_0__ = __webpack_require__(/*! backbone */ "./node_modules/backbone/backbone.js");
  38108. /* harmony import */ var backbone__WEBPACK_IMPORTED_MODULE_0___default = /*#__PURE__*/__webpack_require__.n(backbone__WEBPACK_IMPORTED_MODULE_0__);
  38109. var inputProp = 'contentEditable';
  38110. /* harmony default export */ __webpack_exports__["default"] = (backbone__WEBPACK_IMPORTED_MODULE_0___default.a.View.extend({
  38111. template: function template() {
  38112. var pfx = this.pfx,
  38113. model = this.model,
  38114. config = this.config;
  38115. var label = model.get('label') || '';
  38116. return "\n <span id=\"".concat(pfx, "checkbox\" class=\"").concat(pfx, "tag-status\" data-tag-status></span>\n <span id=\"").concat(pfx, "tag-label\" data-tag-name>").concat(label, "</span>\n <span id=\"").concat(pfx, "close\" class=\"").concat(pfx, "tag-close\" data-tag-remove>\n ").concat(config.iconTagRemove, "\n </span>\n ");
  38117. },
  38118. events: {
  38119. 'click [data-tag-remove]': 'removeTag',
  38120. 'click [data-tag-status]': 'changeStatus',
  38121. 'dblclick [data-tag-name]': 'startEditTag',
  38122. 'focusout [data-tag-name]': 'endEditTag'
  38123. },
  38124. initialize: function initialize(o) {
  38125. var config = o.config || {};
  38126. this.config = config;
  38127. this.coll = o.coll || null;
  38128. this.pfx = config.stylePrefix || '';
  38129. this.ppfx = config.pStylePrefix || '';
  38130. this.em = config.em;
  38131. this.listenTo(this.model, 'change:active', this.updateStatus);
  38132. },
  38133. /**
  38134. * Returns the element which containes the anme of the tag
  38135. * @return {HTMLElement}
  38136. */
  38137. getInputEl: function getInputEl() {
  38138. if (!this.inputEl) {
  38139. this.inputEl = this.el.querySelector('[data-tag-name]');
  38140. }
  38141. return this.inputEl;
  38142. },
  38143. /**
  38144. * Start editing tag
  38145. * @private
  38146. */
  38147. startEditTag: function startEditTag() {
  38148. var em = this.em;
  38149. var inputEl = this.getInputEl();
  38150. inputEl[inputProp] = true;
  38151. inputEl.focus();
  38152. em && em.setEditing(1);
  38153. },
  38154. /**
  38155. * End editing tag. If the class typed already exists the
  38156. * old one will be restored otherwise will be changed
  38157. * @private
  38158. */
  38159. endEditTag: function endEditTag() {
  38160. var model = this.model;
  38161. var inputEl = this.getInputEl();
  38162. var label = inputEl.textContent;
  38163. var em = this.em;
  38164. var sm = em && em.get('SelectorManager');
  38165. inputEl[inputProp] = false;
  38166. em && em.setEditing(0);
  38167. if (sm) {
  38168. var name = sm.escapeName(label);
  38169. if (sm.get(name)) {
  38170. inputEl.innerText = model.get('label');
  38171. } else {
  38172. model.set({
  38173. name: name,
  38174. label: label
  38175. });
  38176. }
  38177. }
  38178. },
  38179. /**
  38180. * Update status of the tag
  38181. * @private
  38182. */
  38183. changeStatus: function changeStatus() {
  38184. var model = this.model;
  38185. model.set('active', !model.get('active'));
  38186. },
  38187. /**
  38188. * Remove tag from the selected component
  38189. * @param {Object} e
  38190. * @private
  38191. */
  38192. removeTag: function removeTag() {
  38193. var em = this.em,
  38194. model = this.model;
  38195. var targets = em && em.getSelectedAll();
  38196. targets.forEach(function (sel) {
  38197. !model.get('protected') && sel && sel.getSelectors().remove(model);
  38198. });
  38199. },
  38200. /**
  38201. * Update status of the checkbox
  38202. * @private
  38203. */
  38204. updateStatus: function updateStatus() {
  38205. var model = this.model,
  38206. $el = this.$el,
  38207. config = this.config;
  38208. var iconTagOn = config.iconTagOn,
  38209. iconTagOff = config.iconTagOff;
  38210. var $chk = $el.find('[data-tag-status]');
  38211. if (model.get('active')) {
  38212. $chk.html(iconTagOn);
  38213. $el.removeClass('opac50');
  38214. } else {
  38215. $chk.html(iconTagOff);
  38216. $el.addClass('opac50');
  38217. }
  38218. },
  38219. render: function render() {
  38220. var pfx = this.pfx;
  38221. var ppfx = this.ppfx;
  38222. this.$el.html(this.template());
  38223. this.$el.attr('class', "".concat(pfx, "tag ").concat(ppfx, "three-bg"));
  38224. this.updateStatus();
  38225. return this;
  38226. }
  38227. }));
  38228. /***/ }),
  38229. /***/ "./src/selector_manager/view/ClassTagsView.js":
  38230. /*!****************************************************!*\
  38231. !*** ./src/selector_manager/view/ClassTagsView.js ***!
  38232. \****************************************************/
  38233. /*! exports provided: default */
  38234. /***/ (function(module, __webpack_exports__, __webpack_require__) {
  38235. "use strict";
  38236. __webpack_require__.r(__webpack_exports__);
  38237. /* harmony import */ var _babel_runtime_helpers_toConsumableArray__WEBPACK_IMPORTED_MODULE_0__ = __webpack_require__(/*! @babel/runtime/helpers/toConsumableArray */ "./node_modules/@babel/runtime/helpers/toConsumableArray.js");
  38238. /* harmony import */ var _babel_runtime_helpers_toConsumableArray__WEBPACK_IMPORTED_MODULE_0___default = /*#__PURE__*/__webpack_require__.n(_babel_runtime_helpers_toConsumableArray__WEBPACK_IMPORTED_MODULE_0__);
  38239. /* harmony import */ var underscore__WEBPACK_IMPORTED_MODULE_1__ = __webpack_require__(/*! underscore */ "./node_modules/underscore/underscore.js");
  38240. /* harmony import */ var underscore__WEBPACK_IMPORTED_MODULE_1___default = /*#__PURE__*/__webpack_require__.n(underscore__WEBPACK_IMPORTED_MODULE_1__);
  38241. /* harmony import */ var backbone__WEBPACK_IMPORTED_MODULE_2__ = __webpack_require__(/*! backbone */ "./node_modules/backbone/backbone.js");
  38242. /* harmony import */ var backbone__WEBPACK_IMPORTED_MODULE_2___default = /*#__PURE__*/__webpack_require__.n(backbone__WEBPACK_IMPORTED_MODULE_2__);
  38243. /* harmony import */ var _ClassTagView__WEBPACK_IMPORTED_MODULE_3__ = __webpack_require__(/*! ./ClassTagView */ "./src/selector_manager/view/ClassTagView.js");
  38244. /* harmony default export */ __webpack_exports__["default"] = (backbone__WEBPACK_IMPORTED_MODULE_2___default.a.View.extend({
  38245. template: function template(_ref) {
  38246. var labelInfo = _ref.labelInfo,
  38247. labelStates = _ref.labelStates,
  38248. labelHead = _ref.labelHead,
  38249. iconSync = _ref.iconSync,
  38250. iconAdd = _ref.iconAdd,
  38251. pfx = _ref.pfx,
  38252. ppfx = _ref.ppfx;
  38253. return "\n <div id=\"".concat(pfx, "up\" class=\"").concat(pfx, "header\">\n <div id=\"").concat(pfx, "label\" class=\"").concat(pfx, "header-label\">").concat(labelHead, "</div>\n <div id=\"").concat(pfx, "status-c\" class=\"").concat(pfx, "header-status\">\n <span id=\"").concat(pfx, "input-c\" data-states-c>\n <div class=\"").concat(ppfx, "field ").concat(ppfx, "select\">\n <span id=\"").concat(ppfx, "input-holder\">\n <select id=\"").concat(pfx, "states\" data-states>\n <option value=\"\">").concat(labelStates, "</option>\n </select>\n </span>\n <div class=\"").concat(ppfx, "sel-arrow\">\n <div class=\"").concat(ppfx, "d-s-arrow\"></div>\n </div>\n </div>\n </span>\n </div>\n </div>\n <div id=\"").concat(pfx, "tags-field\" class=\"").concat(ppfx, "field\">\n <div id=\"").concat(pfx, "tags-c\" data-selectors></div>\n <input id=\"").concat(pfx, "new\" data-input/>\n <span id=\"").concat(pfx, "add-tag\" class=\"").concat(pfx, "tags-btn ").concat(pfx, "tags-btn__add\" data-add>\n ").concat(iconAdd, "\n </span>\n <span class=\"").concat(pfx, "tags-btn ").concat(pfx, "tags-btn__sync\" style=\"display: none\" data-sync-style>\n ").concat(iconSync, "\n </span>\n </div>\n <div class=\"").concat(pfx, "sels-info\">\n <div class=\"").concat(pfx, "label-sel\">").concat(labelInfo, ":</div>\n <div class=\"").concat(pfx, "sels\" data-selected></div>\n <div style=\"clear:both\"></div>\n </div>");
  38254. },
  38255. events: {
  38256. 'change [data-states]': 'stateChanged',
  38257. 'click [data-add]': 'startNewTag',
  38258. 'focusout [data-input]': 'endNewTag',
  38259. 'keyup [data-input]': 'onInputKeyUp',
  38260. 'click [data-sync-style]': 'syncStyle'
  38261. },
  38262. initialize: function initialize() {
  38263. var o = arguments.length > 0 && arguments[0] !== undefined ? arguments[0] : {};
  38264. this.config = o.config || {};
  38265. this.pfx = this.config.stylePrefix || '';
  38266. this.ppfx = this.config.pStylePrefix || '';
  38267. this.className = this.pfx + 'tags';
  38268. this.stateInputId = this.pfx + 'states';
  38269. this.stateInputC = this.pfx + 'input-c';
  38270. this.states = this.config.states || [];
  38271. var em = this.config.em;
  38272. var emitter = this.getStyleEmitter();
  38273. var coll = this.collection;
  38274. this.target = this.config.em;
  38275. this.em = em;
  38276. var toList = 'component:toggled component:update:classes';
  38277. var toListCls = 'component:update:classes change:state';
  38278. this.listenTo(em, toList, this.componentChanged);
  38279. this.listenTo(emitter, 'styleManager:update', this.componentChanged);
  38280. this.listenTo(em, toListCls, this.__handleStateChange);
  38281. this.listenTo(em, 'styleable:change change:device', this.checkSync); // component:styleUpdate
  38282. this.listenTo(coll, 'add', this.addNew);
  38283. this.listenTo(coll, 'reset', this.renderClasses);
  38284. this.listenTo(coll, 'remove', this.tagRemoved);
  38285. this.delegateEvents();
  38286. },
  38287. syncStyle: function syncStyle() {
  38288. var em = this.em;
  38289. var target = this.getTarget();
  38290. var cssC = em.get('CssComposer');
  38291. var opts = {
  38292. noDisabled: 1
  38293. };
  38294. var selectors = this.getCommonSelectors({
  38295. opts: opts
  38296. });
  38297. var state = em.get('state');
  38298. var mediaText = em.getCurrentMedia();
  38299. var ruleComponents = [];
  38300. var rule = cssC.get(selectors, state, mediaText) || cssC.add(selectors, state, mediaText);
  38301. var style;
  38302. this.getTargets().forEach(function (target) {
  38303. var ruleComponent = cssC.getIdRule(target.getId(), {
  38304. state: state,
  38305. mediaText: mediaText
  38306. });
  38307. style = ruleComponent.getStyle();
  38308. ruleComponent.setStyle({});
  38309. ruleComponents.push(ruleComponent);
  38310. });
  38311. style && rule.addStyle(style);
  38312. em.trigger('component:toggled');
  38313. em.trigger('component:sync-style', {
  38314. component: target,
  38315. selectors: selectors,
  38316. mediaText: mediaText,
  38317. rule: rule,
  38318. ruleComponents: ruleComponents,
  38319. state: state
  38320. });
  38321. },
  38322. getStyleEmitter: function getStyleEmitter() {
  38323. var em = this.em;
  38324. var sm = em && em.get('StyleManager');
  38325. var emitter = sm && sm.getEmitter();
  38326. return emitter || {};
  38327. },
  38328. /**
  38329. * Triggered when a tag is removed from collection
  38330. * @param {Object} model Removed model
  38331. * @private
  38332. */
  38333. tagRemoved: function tagRemoved(model) {
  38334. this.updateStateVis();
  38335. },
  38336. /**
  38337. * Create select input with states
  38338. * @return {string} String of options
  38339. * @private
  38340. */
  38341. getStateOptions: function getStateOptions() {
  38342. var states = this.states,
  38343. em = this.em;
  38344. var result = [];
  38345. states.forEach(function (state) {
  38346. return result.push("<option value=\"".concat(state.name, "\">").concat(em.t("selectorManager.states.".concat(state.name)) || state.label || state.name, "</option>"));
  38347. });
  38348. return result.join('');
  38349. },
  38350. /**
  38351. * Add new model
  38352. * @param {Object} model
  38353. * @private
  38354. */
  38355. addNew: function addNew(model) {
  38356. this.addToClasses(model);
  38357. },
  38358. /**
  38359. * Start tag creation
  38360. * @param {Object} e
  38361. * @private
  38362. */
  38363. startNewTag: function startNewTag() {
  38364. this.$addBtn.css({
  38365. display: 'none'
  38366. });
  38367. this.$input.show().focus();
  38368. },
  38369. /**
  38370. * End tag creation
  38371. * @param {Object} e
  38372. * @private
  38373. */
  38374. endNewTag: function endNewTag() {
  38375. this.$addBtn.css({
  38376. display: ''
  38377. });
  38378. this.$input.hide().val('');
  38379. },
  38380. /**
  38381. * Checks what to do on keyup event
  38382. * @param {Object} e
  38383. * @private
  38384. */
  38385. onInputKeyUp: function onInputKeyUp(e) {
  38386. if (e.keyCode === 13) this.addNewTag(this.$input.val());else if (e.keyCode === 27) this.endNewTag();
  38387. },
  38388. checkStates: function checkStates() {
  38389. var state = this.em.getState();
  38390. var statesEl = this.getStates();
  38391. statesEl && statesEl.val(state);
  38392. },
  38393. /**
  38394. * Triggered when component is changed
  38395. * @param {Object} e
  38396. * @private
  38397. */
  38398. componentChanged: Object(underscore__WEBPACK_IMPORTED_MODULE_1__["debounce"])(function () {
  38399. var _ref2 = arguments.length > 0 && arguments[0] !== undefined ? arguments[0] : {},
  38400. targets = _ref2.targets;
  38401. this.updateSelection(targets);
  38402. }),
  38403. updateSelection: function updateSelection(targets) {
  38404. var trgs = targets || this.getTargets();
  38405. trgs = Object(underscore__WEBPACK_IMPORTED_MODULE_1__["isArray"])(trgs) ? trgs : [trgs];
  38406. var selectors = [];
  38407. if (trgs && trgs.length) {
  38408. selectors = this.getCommonSelectors({
  38409. targets: trgs
  38410. });
  38411. this.checkSync({
  38412. validSelectors: selectors
  38413. });
  38414. }
  38415. this.collection.reset(selectors);
  38416. this.updateStateVis(trgs);
  38417. return selectors;
  38418. },
  38419. getCommonSelectors: function getCommonSelectors() {
  38420. var _ref3 = arguments.length > 0 && arguments[0] !== undefined ? arguments[0] : {},
  38421. targets = _ref3.targets,
  38422. _ref3$opts = _ref3.opts,
  38423. opts = _ref3$opts === void 0 ? {} : _ref3$opts;
  38424. var trgs = targets || this.getTargets();
  38425. var selectors = trgs.map(function (tr) {
  38426. return tr.getSelectors && tr.getSelectors().getValid(opts);
  38427. }).filter(function (i) {
  38428. return i;
  38429. });
  38430. return this._commonSelectors.apply(this, _babel_runtime_helpers_toConsumableArray__WEBPACK_IMPORTED_MODULE_0___default()(selectors));
  38431. },
  38432. _commonSelectors: function _commonSelectors() {
  38433. var _this = this;
  38434. for (var _len = arguments.length, args = new Array(_len), _key = 0; _key < _len; _key++) {
  38435. args[_key] = arguments[_key];
  38436. }
  38437. if (!args.length) return [];
  38438. if (args.length === 1) return args[0];
  38439. if (args.length === 2) return args[0].filter(function (item) {
  38440. return args[1].indexOf(item) >= 0;
  38441. });
  38442. return args.slice(1).reduce(function (acc, item) {
  38443. return _this._commonSelectors(acc, item);
  38444. }, args[0]);
  38445. },
  38446. checkSync: Object(underscore__WEBPACK_IMPORTED_MODULE_1__["debounce"])(function () {
  38447. var $btnSyncEl = this.$btnSyncEl,
  38448. config = this.config,
  38449. collection = this.collection;
  38450. var target = this.getTarget();
  38451. var hasStyle;
  38452. if (target && config.componentFirst && collection.length) {
  38453. var style = target.getStyle();
  38454. hasStyle = !Object(underscore__WEBPACK_IMPORTED_MODULE_1__["isEmpty"])(style);
  38455. }
  38456. $btnSyncEl && $btnSyncEl[hasStyle ? 'show' : 'hide']();
  38457. }),
  38458. getTarget: function getTarget() {
  38459. return this.target.getSelected();
  38460. },
  38461. getTargets: function getTargets() {
  38462. return this.target.getSelectedAll();
  38463. },
  38464. /**
  38465. * Update states visibility. Hides states in case there is no tags
  38466. * inside collection
  38467. * @private
  38468. */
  38469. updateStateVis: function updateStateVis(target) {
  38470. var em = this.em;
  38471. var avoidInline = em && em.getConfig('avoidInlineStyle');
  38472. var display = this.collection.length || avoidInline ? '' : 'none';
  38473. this.getStatesC().css('display', display);
  38474. this.updateSelector(target);
  38475. },
  38476. __handleStateChange: function __handleStateChange() {
  38477. this.updateSelector(this.getTargets());
  38478. },
  38479. /**
  38480. * Update selector helper
  38481. * @return {this}
  38482. * @private
  38483. */
  38484. updateSelector: function updateSelector(targets) {
  38485. var _this2 = this;
  38486. var elSel = this.el.querySelector('[data-selected]');
  38487. var result = [];
  38488. var trgs = targets || this.getTargets();
  38489. trgs = Object(underscore__WEBPACK_IMPORTED_MODULE_1__["isArray"])(trgs) ? trgs : [trgs];
  38490. trgs.forEach(function (target) {
  38491. return result.push(_this2.__getName(target));
  38492. });
  38493. elSel && (elSel.innerHTML = result.join(', '));
  38494. this.checkStates();
  38495. },
  38496. __getName: function __getName(target) {
  38497. var pfx = this.pfx,
  38498. config = this.config,
  38499. em = this.em;
  38500. var selectedName = config.selectedName,
  38501. componentFirst = config.componentFirst;
  38502. var result;
  38503. if (Object(underscore__WEBPACK_IMPORTED_MODULE_1__["isString"])(target)) {
  38504. result = "<span class=\"".concat(pfx, "sel-gen\">").concat(target, "</span>");
  38505. } else {
  38506. if (!target || !target.get) return;
  38507. var selectors = target.getSelectors().getStyleable();
  38508. var state = em.get('state');
  38509. var idRes = target.getId ? "<span class=\"".concat(pfx, "sel-cmp\">").concat(target.getName(), "</span><span class=\"").concat(pfx, "sel-id\">#").concat(target.getId(), "</span>") : '';
  38510. result = this.collection.getFullString(selectors);
  38511. result = result ? "<span class=\"".concat(pfx, "sel-rule\">").concat(result, "</span>") : target.get('selectorsAdd') || idRes;
  38512. result = componentFirst && idRes ? idRes : result;
  38513. result += state ? "<span class=\"".concat(pfx, "sel-state\">:").concat(state, "</span>") : '';
  38514. result = selectedName ? selectedName({
  38515. result: result,
  38516. state: state,
  38517. target: target
  38518. }) : result;
  38519. }
  38520. return result && "<span class=\"".concat(pfx, "sel\">").concat(result, "</span>");
  38521. },
  38522. /**
  38523. * Triggered when the select with states is changed
  38524. * @param {Object} e
  38525. * @private
  38526. */
  38527. stateChanged: function stateChanged(ev) {
  38528. var em = this.em;
  38529. var value = ev.target.value;
  38530. em.set('state', value);
  38531. },
  38532. /**
  38533. * Add new tag to collection, if possible, and to the component
  38534. * @param {Object} e
  38535. * @private
  38536. */
  38537. addNewTag: function addNewTag(label) {
  38538. var _this3 = this;
  38539. var em = this.em;
  38540. if (!label.trim()) return;
  38541. if (em) {
  38542. var sm = em.get('SelectorManager');
  38543. var model = sm.add({
  38544. label: label
  38545. });
  38546. this.getTargets().forEach(function (target) {
  38547. target.getSelectors().add(model);
  38548. _this3.collection.add(model);
  38549. _this3.updateStateVis();
  38550. });
  38551. }
  38552. this.endNewTag();
  38553. },
  38554. /**
  38555. * Add new object to collection
  38556. * @param {Object} model Model
  38557. * @param {Object} fragmentEl Fragment collection
  38558. * @return {Object} Object created
  38559. * @private
  38560. * */
  38561. addToClasses: function addToClasses(model) {
  38562. var fragmentEl = arguments.length > 1 && arguments[1] !== undefined ? arguments[1] : null;
  38563. var fragment = fragmentEl;
  38564. var classes = this.getClasses();
  38565. var rendered = new _ClassTagView__WEBPACK_IMPORTED_MODULE_3__["default"]({
  38566. model: model,
  38567. config: this.config,
  38568. coll: this.collection
  38569. }).render().el;
  38570. fragment ? fragment.appendChild(rendered) : classes.append(rendered);
  38571. return rendered;
  38572. },
  38573. /**
  38574. * Render the collection of classes
  38575. * @private
  38576. */
  38577. renderClasses: function renderClasses() {
  38578. var _this4 = this;
  38579. var frag = document.createDocumentFragment();
  38580. var classes = this.getClasses();
  38581. classes.empty();
  38582. this.collection.each(function (model) {
  38583. return _this4.addToClasses(model, frag);
  38584. });
  38585. classes.append(frag);
  38586. },
  38587. /**
  38588. * Return classes element
  38589. * @return {HTMLElement}
  38590. * @private
  38591. */
  38592. getClasses: function getClasses() {
  38593. return this.$el.find('[data-selectors]');
  38594. },
  38595. /**
  38596. * Return states element
  38597. * @return {HTMLElement}
  38598. * @private
  38599. */
  38600. getStates: function getStates() {
  38601. if (!this.$states) {
  38602. var el = this.$el.find('[data-states]');
  38603. this.$states = el[0] && el;
  38604. }
  38605. return this.$states;
  38606. },
  38607. /**
  38608. * Return states container element
  38609. * @return {HTMLElement}
  38610. * @private
  38611. */
  38612. getStatesC: function getStatesC() {
  38613. if (!this.$statesC) this.$statesC = this.$el.find('#' + this.stateInputC);
  38614. return this.$statesC;
  38615. },
  38616. render: function render() {
  38617. var em = this.em,
  38618. pfx = this.pfx,
  38619. ppfx = this.ppfx,
  38620. config = this.config,
  38621. $el = this.$el,
  38622. el = this.el;
  38623. var render = config.render,
  38624. iconSync = config.iconSync,
  38625. iconAdd = config.iconAdd;
  38626. var tmpOpts = {
  38627. iconSync: iconSync,
  38628. iconAdd: iconAdd,
  38629. labelHead: em.t('selectorManager.label'),
  38630. labelStates: em.t('selectorManager.emptyState'),
  38631. labelInfo: em.t('selectorManager.selected'),
  38632. ppfx: ppfx,
  38633. pfx: pfx,
  38634. el: el
  38635. };
  38636. $el.html(this.template(tmpOpts));
  38637. var renderRes = render && render(tmpOpts);
  38638. renderRes && renderRes !== el && $el.empty().append(renderRes);
  38639. this.$input = $el.find('[data-input]');
  38640. this.$addBtn = $el.find('[data-add]');
  38641. this.$classes = $el.find('#' + pfx + 'tags-c');
  38642. this.$btnSyncEl = $el.find('[data-sync-style]');
  38643. this.$input.hide();
  38644. var statesEl = this.getStates();
  38645. statesEl && statesEl.append(this.getStateOptions());
  38646. this.renderClasses();
  38647. $el.attr('class', "".concat(this.className, " ").concat(ppfx, "one-bg ").concat(ppfx, "two-color"));
  38648. return this;
  38649. }
  38650. }));
  38651. /***/ }),
  38652. /***/ "./src/storage_manager/config/config.js":
  38653. /*!**********************************************!*\
  38654. !*** ./src/storage_manager/config/config.js ***!
  38655. \**********************************************/
  38656. /*! exports provided: default */
  38657. /***/ (function(module, __webpack_exports__, __webpack_require__) {
  38658. "use strict";
  38659. __webpack_require__.r(__webpack_exports__);
  38660. /* harmony default export */ __webpack_exports__["default"] = ({
  38661. // Prefix identifier that will be used inside storing and loading
  38662. id: 'gjs-',
  38663. // Enable/Disable autosaving
  38664. autosave: 1,
  38665. // Indicates if load data inside editor after init
  38666. autoload: 1,
  38667. // Indicates which storage to use. Available: local | remote
  38668. type: 'local',
  38669. // If autosave enabled, indicates how many steps (general changes to structure)
  38670. // need to be done before save. Useful with remoteStorage to reduce remote calls
  38671. stepsBeforeSave: 1,
  38672. //Enable/Disable components model (JSON format)
  38673. storeComponents: 1,
  38674. //Enable/Disable styles model (JSON format)
  38675. storeStyles: 1,
  38676. //Enable/Disable saving HTML template
  38677. storeHtml: 1,
  38678. //Enable/Disable saving CSS template
  38679. storeCss: 1,
  38680. // ONLY FOR LOCAL STORAGE
  38681. // If enabled, checks if browser supports Local Storage
  38682. checkLocal: 1,
  38683. // ONLY FOR REMOTE STORAGE
  38684. // Custom parameters to pass with the remote storage request, eg. csrf token
  38685. params: {},
  38686. // Custom headers for the remote storage request
  38687. headers: {},
  38688. // Endpoint where to save all stuff
  38689. urlStore: '',
  38690. // Endpoint where to fetch data
  38691. urlLoad: '',
  38692. //Callback before request
  38693. beforeSend: function beforeSend(jqXHR, settings) {},
  38694. //Callback after request
  38695. onComplete: function onComplete(jqXHR, status) {},
  38696. // set contentType paramater of $.ajax
  38697. // true: application/json; charset=utf-8'
  38698. // false: 'x-www-form-urlencoded'
  38699. contentTypeJson: true,
  38700. credentials: 'include',
  38701. // Pass custom options to fetch API (remote storage)
  38702. // You can pass a simple object: { someOption: 'someValue' }
  38703. // or a function wich returns and object to add:
  38704. // currentOpts => {
  38705. // return currentOpts.method === 'post' ? { method: 'patch' } : {};
  38706. // }
  38707. fetchOptions: ''
  38708. });
  38709. /***/ }),
  38710. /***/ "./src/storage_manager/index.js":
  38711. /*!**************************************!*\
  38712. !*** ./src/storage_manager/index.js ***!
  38713. \**************************************/
  38714. /*! exports provided: default */
  38715. /***/ (function(module, __webpack_exports__, __webpack_require__) {
  38716. "use strict";
  38717. __webpack_require__.r(__webpack_exports__);
  38718. /* harmony import */ var _babel_runtime_helpers_defineProperty__WEBPACK_IMPORTED_MODULE_0__ = __webpack_require__(/*! @babel/runtime/helpers/defineProperty */ "./node_modules/@babel/runtime/helpers/defineProperty.js");
  38719. /* harmony import */ var _babel_runtime_helpers_defineProperty__WEBPACK_IMPORTED_MODULE_0___default = /*#__PURE__*/__webpack_require__.n(_babel_runtime_helpers_defineProperty__WEBPACK_IMPORTED_MODULE_0__);
  38720. /* harmony import */ var _config_config__WEBPACK_IMPORTED_MODULE_1__ = __webpack_require__(/*! ./config/config */ "./src/storage_manager/config/config.js");
  38721. /* harmony import */ var _model_LocalStorage__WEBPACK_IMPORTED_MODULE_2__ = __webpack_require__(/*! ./model/LocalStorage */ "./src/storage_manager/model/LocalStorage.js");
  38722. /* harmony import */ var _model_RemoteStorage__WEBPACK_IMPORTED_MODULE_3__ = __webpack_require__(/*! ./model/RemoteStorage */ "./src/storage_manager/model/RemoteStorage.js");
  38723. function ownKeys(object, enumerableOnly) { var keys = Object.keys(object); if (Object.getOwnPropertySymbols) { var symbols = Object.getOwnPropertySymbols(object); if (enumerableOnly) symbols = symbols.filter(function (sym) { return Object.getOwnPropertyDescriptor(object, sym).enumerable; }); keys.push.apply(keys, symbols); } return keys; }
  38724. function _objectSpread(target) { for (var i = 1; i < arguments.length; i++) { var source = arguments[i] != null ? arguments[i] : {}; if (i % 2) { ownKeys(source, true).forEach(function (key) { _babel_runtime_helpers_defineProperty__WEBPACK_IMPORTED_MODULE_0___default()(target, key, source[key]); }); } else if (Object.getOwnPropertyDescriptors) { Object.defineProperties(target, Object.getOwnPropertyDescriptors(source)); } else { ownKeys(source).forEach(function (key) { Object.defineProperty(target, key, Object.getOwnPropertyDescriptor(source, key)); }); } } return target; }
  38725. /**
  38726. * You can customize the initial state of the module from the editor initialization, by passing the following [Configuration Object](https://github.com/artf/grapesjs/blob/master/src/storage_manager/config/config.js)
  38727. * ```js
  38728. * const editor = grapesjs.init({
  38729. * storageManager: {
  38730. * // options
  38731. * }
  38732. * })
  38733. * ```
  38734. *
  38735. * Once the editor is instantiated you can use its API. Before using these methods you should get the module from the instance
  38736. *
  38737. * ```js
  38738. * const storageManager = editor.StorageManager;
  38739. * ```
  38740. *
  38741. * * [getConfig](#getconfig)
  38742. * * [isAutosave](#isautosave)
  38743. * * [setAutosave](#setautosave)
  38744. * * [getStepsBeforeSave](#getstepsbeforesave)
  38745. * * [setStepsBeforeSave](#setstepsbeforesave)
  38746. * * [setStepsBeforeSave](#setstepsbeforesave)
  38747. * * [getStorages](#getstorages)
  38748. * * [getCurrent](#getcurrent)
  38749. * * [getCurrentStorage](#getcurrentstorage)
  38750. * * [setCurrent](#setcurrent)
  38751. * * [add](#add)
  38752. * * [get](#get)
  38753. * * [store](#store)
  38754. * * [load](#load)
  38755. *
  38756. * @module StorageManager
  38757. */
  38758. /* harmony default export */ __webpack_exports__["default"] = (function () {
  38759. var c = {};
  38760. var em;
  38761. var storages = {};
  38762. var defaultStorages = {};
  38763. var eventStart = 'storage:start';
  38764. var eventEnd = 'storage:end';
  38765. var eventError = 'storage:error';
  38766. return {
  38767. /**
  38768. * Name of the module
  38769. * @type {String}
  38770. * @private
  38771. */
  38772. name: 'StorageManager',
  38773. /**
  38774. * Initialize module. Automatically called with a new instance of the editor
  38775. * @param {Object} config Configurations
  38776. * @param {string} [config.id='gjs-'] The prefix for the fields, useful to differentiate storing/loading
  38777. * with multiple editors on the same page. For example, in local storage, the item of HTML will be saved like 'gjs-html'
  38778. * @param {Boolean} [config.autosave=true] Indicates if autosave mode is enabled, works in conjunction with stepsBeforeSave
  38779. * @param {number} [config.stepsBeforeSave=1] If autosave enabled, indicates how many steps/changes are necessary
  38780. * before autosave is triggered
  38781. * @param {string} [config.type='local'] Default storage type. Available: 'local' | 'remote' | ''(do not store)
  38782. * @private
  38783. * @example
  38784. * ...
  38785. * {
  38786. * autosave: false,
  38787. * type: 'remote',
  38788. * }
  38789. * ...
  38790. */
  38791. init: function init() {
  38792. var config = arguments.length > 0 && arguments[0] !== undefined ? arguments[0] : {};
  38793. c = _objectSpread({}, _config_config__WEBPACK_IMPORTED_MODULE_1__["default"], {}, config);
  38794. em = c.em;
  38795. if (c._disable) c.type = 0;
  38796. defaultStorages.remote = new _model_RemoteStorage__WEBPACK_IMPORTED_MODULE_3__["default"](c);
  38797. defaultStorages.local = new _model_LocalStorage__WEBPACK_IMPORTED_MODULE_2__["default"](c);
  38798. c.currentStorage = c.type;
  38799. this.loadDefaultProviders().setCurrent(c.type);
  38800. return this;
  38801. },
  38802. /**
  38803. * Get configuration object
  38804. * @return {Object}
  38805. * */
  38806. getConfig: function getConfig() {
  38807. return c;
  38808. },
  38809. /**
  38810. * Checks if autosave is enabled
  38811. * @return {Boolean}
  38812. * */
  38813. isAutosave: function isAutosave() {
  38814. return !!c.autosave;
  38815. },
  38816. /**
  38817. * Set autosave value
  38818. * @param {Boolean} v
  38819. * @return {this}
  38820. * */
  38821. setAutosave: function setAutosave(v) {
  38822. c.autosave = !!v;
  38823. return this;
  38824. },
  38825. /**
  38826. * Returns number of steps required before trigger autosave
  38827. * @return {number}
  38828. * */
  38829. getStepsBeforeSave: function getStepsBeforeSave() {
  38830. return c.stepsBeforeSave;
  38831. },
  38832. /**
  38833. * Set steps required before trigger autosave
  38834. * @param {number} v
  38835. * @return {this}
  38836. * */
  38837. setStepsBeforeSave: function setStepsBeforeSave(v) {
  38838. c.stepsBeforeSave = v;
  38839. return this;
  38840. },
  38841. /**
  38842. * Add new storage
  38843. * @param {string} id Storage ID
  38844. * @param {Object} storage Storage wrapper
  38845. * @param {Function} storage.load Load method
  38846. * @param {Function} storage.store Store method
  38847. * @return {this}
  38848. * @example
  38849. * storageManager.add('local2', {
  38850. * load: function(keys, clb, clbErr) {
  38851. * var res = {};
  38852. * for (var i = 0, len = keys.length; i < len; i++){
  38853. * var v = localStorage.getItem(keys[i]);
  38854. * if(v) res[keys[i]] = v;
  38855. * }
  38856. * clb(res); // might be called inside some async method
  38857. * // In case of errors...
  38858. * // clbErr('Went something wrong');
  38859. * },
  38860. * store: function(data, clb, clbErr) {
  38861. * for(var key in data)
  38862. * localStorage.setItem(key, data[key]);
  38863. * clb(); // might be called inside some async method
  38864. * }
  38865. * });
  38866. * */
  38867. add: function add(id, storage) {
  38868. storages[id] = storage;
  38869. return this;
  38870. },
  38871. /**
  38872. * Returns storage by id
  38873. * @param {string} id Storage ID
  38874. * @return {Object|null}
  38875. * */
  38876. get: function get(id) {
  38877. return storages[id] || null;
  38878. },
  38879. /**
  38880. * Returns all storages
  38881. * @return {Array}
  38882. * */
  38883. getStorages: function getStorages() {
  38884. return storages;
  38885. },
  38886. /**
  38887. * Returns current storage type
  38888. * @return {string}
  38889. * */
  38890. getCurrent: function getCurrent() {
  38891. return c.currentStorage;
  38892. },
  38893. /**
  38894. * Set current storage type
  38895. * @param {string} id Storage ID
  38896. * @return {this}
  38897. * */
  38898. setCurrent: function setCurrent(id) {
  38899. c.currentStorage = id;
  38900. return this;
  38901. },
  38902. /**
  38903. * Store key-value resources in the current storage
  38904. * @param {Object} data Data in key-value format, eg. {item1: value1, item2: value2}
  38905. * @param {Function} clb Callback function
  38906. * @return {Object|null}
  38907. * @example
  38908. * storageManager.store({item1: value1, item2: value2});
  38909. * */
  38910. store: function store(data, clb) {
  38911. var _this = this;
  38912. var st = this.get(this.getCurrent());
  38913. var toStore = {};
  38914. this.onStart('store', data);
  38915. for (var key in data) {
  38916. toStore[c.id + key] = data[key];
  38917. }
  38918. return st ? st.store(toStore, function (res) {
  38919. clb && clb(res);
  38920. _this.onEnd('store', res);
  38921. }, function (err) {
  38922. _this.onError('store', err);
  38923. }) : null;
  38924. },
  38925. /**
  38926. * Load resource from the current storage by keys
  38927. * @param {string|Array<string>} keys Keys to load
  38928. * @param {Function} clb Callback function
  38929. * @example
  38930. * storageManager.load(['item1', 'item2'], res => {
  38931. * // res -> {item1: value1, item2: value2}
  38932. * });
  38933. * storageManager.load('item1', res => {
  38934. * // res -> {item1: value1}
  38935. * });
  38936. * */
  38937. load: function load(keys, clb) {
  38938. var _this2 = this;
  38939. var st = this.get(this.getCurrent());
  38940. var keysF = [];
  38941. var result = {};
  38942. if (typeof keys === 'string') keys = [keys];
  38943. this.onStart('load', keys);
  38944. for (var i = 0, len = keys.length; i < len; i++) {
  38945. keysF.push(c.id + keys[i]);
  38946. }
  38947. if (st) {
  38948. st.load(keysF, function (res) {
  38949. // Restore keys name
  38950. var reg = new RegExp('^' + c.id + '');
  38951. for (var itemKey in res) {
  38952. var itemKeyR = itemKey.replace(reg, '');
  38953. result[itemKeyR] = res[itemKey];
  38954. }
  38955. clb && clb(result);
  38956. _this2.onEnd('load', result);
  38957. }, function (err) {
  38958. clb && clb(result);
  38959. _this2.onError('load', err);
  38960. });
  38961. } else {
  38962. clb && clb(result);
  38963. }
  38964. },
  38965. /**
  38966. * Load default storages
  38967. * @return {this}
  38968. * @private
  38969. * */
  38970. loadDefaultProviders: function loadDefaultProviders() {
  38971. for (var id in defaultStorages) {
  38972. this.add(id, defaultStorages[id]);
  38973. }
  38974. return this;
  38975. },
  38976. /**
  38977. * Get current storage
  38978. * @return {Storage}
  38979. * */
  38980. getCurrentStorage: function getCurrentStorage() {
  38981. return this.get(this.getCurrent());
  38982. },
  38983. /**
  38984. * On start callback
  38985. * @private
  38986. */
  38987. onStart: function onStart(ctx, data) {
  38988. if (em) {
  38989. em.trigger(eventStart);
  38990. ctx && em.trigger("".concat(eventStart, ":").concat(ctx), data);
  38991. }
  38992. },
  38993. /**
  38994. * On end callback
  38995. * @private
  38996. */
  38997. onEnd: function onEnd(ctx, data) {
  38998. if (em) {
  38999. em.trigger(eventEnd);
  39000. ctx && em.trigger("".concat(eventEnd, ":").concat(ctx), data);
  39001. }
  39002. },
  39003. /**
  39004. * On error callback
  39005. * @private
  39006. */
  39007. onError: function onError(ctx, data) {
  39008. if (em) {
  39009. em.trigger(eventError, data);
  39010. ctx && em.trigger("".concat(eventError, ":").concat(ctx), data);
  39011. this.onEnd(ctx, data);
  39012. }
  39013. },
  39014. /**
  39015. * Check if autoload is possible
  39016. * @return {Boolean}
  39017. * @private
  39018. * */
  39019. canAutoload: function canAutoload() {
  39020. var storage = this.getCurrentStorage();
  39021. return storage && this.getConfig().autoload;
  39022. }
  39023. };
  39024. });
  39025. /***/ }),
  39026. /***/ "./src/storage_manager/model/LocalStorage.js":
  39027. /*!***************************************************!*\
  39028. !*** ./src/storage_manager/model/LocalStorage.js ***!
  39029. \***************************************************/
  39030. /*! exports provided: default */
  39031. /***/ (function(module, __webpack_exports__, __webpack_require__) {
  39032. "use strict";
  39033. __webpack_require__.r(__webpack_exports__);
  39034. /* harmony import */ var backbone__WEBPACK_IMPORTED_MODULE_0__ = __webpack_require__(/*! backbone */ "./node_modules/backbone/backbone.js");
  39035. /* harmony import */ var backbone__WEBPACK_IMPORTED_MODULE_0___default = /*#__PURE__*/__webpack_require__.n(backbone__WEBPACK_IMPORTED_MODULE_0__);
  39036. /* harmony default export */ __webpack_exports__["default"] = (backbone__WEBPACK_IMPORTED_MODULE_0___default.a.Model.extend({
  39037. defaults: {
  39038. checkLocal: true
  39039. },
  39040. /**
  39041. * @private
  39042. */
  39043. store: function store(data, clb) {
  39044. this.checkStorageEnvironment();
  39045. for (var key in data) {
  39046. localStorage.setItem(key, data[key]);
  39047. }
  39048. if (typeof clb == 'function') {
  39049. clb();
  39050. }
  39051. },
  39052. /**
  39053. * @private
  39054. */
  39055. load: function load(keys, clb) {
  39056. this.checkStorageEnvironment();
  39057. var result = {};
  39058. for (var i = 0, len = keys.length; i < len; i++) {
  39059. var value = localStorage.getItem(keys[i]);
  39060. if (value) result[keys[i]] = value;
  39061. }
  39062. if (typeof clb == 'function') {
  39063. clb(result);
  39064. }
  39065. return result;
  39066. },
  39067. /**
  39068. * @private
  39069. */
  39070. remove: function remove(keys) {
  39071. this.checkStorageEnvironment();
  39072. for (var i = 0, len = keys.length; i < len; i++) {
  39073. localStorage.removeItem(keys[i]);
  39074. }
  39075. },
  39076. /**
  39077. * Check storage environment
  39078. * @private
  39079. * */
  39080. checkStorageEnvironment: function checkStorageEnvironment() {
  39081. if (this.get('checkLocal') && !localStorage) console.warn("Your browser doesn't support localStorage");
  39082. }
  39083. }));
  39084. /***/ }),
  39085. /***/ "./src/storage_manager/model/RemoteStorage.js":
  39086. /*!****************************************************!*\
  39087. !*** ./src/storage_manager/model/RemoteStorage.js ***!
  39088. \****************************************************/
  39089. /*! exports provided: default */
  39090. /***/ (function(module, __webpack_exports__, __webpack_require__) {
  39091. "use strict";
  39092. __webpack_require__.r(__webpack_exports__);
  39093. /* harmony import */ var _babel_runtime_helpers_defineProperty__WEBPACK_IMPORTED_MODULE_0__ = __webpack_require__(/*! @babel/runtime/helpers/defineProperty */ "./node_modules/@babel/runtime/helpers/defineProperty.js");
  39094. /* harmony import */ var _babel_runtime_helpers_defineProperty__WEBPACK_IMPORTED_MODULE_0___default = /*#__PURE__*/__webpack_require__.n(_babel_runtime_helpers_defineProperty__WEBPACK_IMPORTED_MODULE_0__);
  39095. /* harmony import */ var backbone__WEBPACK_IMPORTED_MODULE_1__ = __webpack_require__(/*! backbone */ "./node_modules/backbone/backbone.js");
  39096. /* harmony import */ var backbone__WEBPACK_IMPORTED_MODULE_1___default = /*#__PURE__*/__webpack_require__.n(backbone__WEBPACK_IMPORTED_MODULE_1__);
  39097. /* harmony import */ var utils_fetch__WEBPACK_IMPORTED_MODULE_2__ = __webpack_require__(/*! utils/fetch */ "./src/utils/fetch.js");
  39098. /* harmony import */ var underscore__WEBPACK_IMPORTED_MODULE_3__ = __webpack_require__(/*! underscore */ "./node_modules/underscore/underscore.js");
  39099. /* harmony import */ var underscore__WEBPACK_IMPORTED_MODULE_3___default = /*#__PURE__*/__webpack_require__.n(underscore__WEBPACK_IMPORTED_MODULE_3__);
  39100. function ownKeys(object, enumerableOnly) { var keys = Object.keys(object); if (Object.getOwnPropertySymbols) { var symbols = Object.getOwnPropertySymbols(object); if (enumerableOnly) symbols = symbols.filter(function (sym) { return Object.getOwnPropertyDescriptor(object, sym).enumerable; }); keys.push.apply(keys, symbols); } return keys; }
  39101. function _objectSpread(target) { for (var i = 1; i < arguments.length; i++) { var source = arguments[i] != null ? arguments[i] : {}; if (i % 2) { ownKeys(source, true).forEach(function (key) { _babel_runtime_helpers_defineProperty__WEBPACK_IMPORTED_MODULE_0___default()(target, key, source[key]); }); } else if (Object.getOwnPropertyDescriptors) { Object.defineProperties(target, Object.getOwnPropertyDescriptors(source)); } else { ownKeys(source).forEach(function (key) { Object.defineProperty(target, key, Object.getOwnPropertyDescriptor(source, key)); }); } } return target; }
  39102. /* harmony default export */ __webpack_exports__["default"] = (backbone__WEBPACK_IMPORTED_MODULE_1___default.a.Model.extend({
  39103. fetch: utils_fetch__WEBPACK_IMPORTED_MODULE_2__["default"],
  39104. defaults: {
  39105. urlStore: '',
  39106. urlLoad: '',
  39107. params: {},
  39108. beforeSend: function beforeSend() {},
  39109. onComplete: function onComplete() {},
  39110. contentTypeJson: false,
  39111. credentials: 'include',
  39112. fetchOptions: ''
  39113. },
  39114. /**
  39115. * Triggered before the request is started
  39116. * @private
  39117. */
  39118. onStart: function onStart() {
  39119. var em = this.get('em');
  39120. var before = this.get('beforeSend');
  39121. before && before();
  39122. },
  39123. /**
  39124. * Triggered on request error
  39125. * @param {Object} err Error
  39126. * @param {Function} [clbErr] Error callback
  39127. * @private
  39128. */
  39129. onError: function onError(err, clbErr) {
  39130. if (clbErr) {
  39131. clbErr(err);
  39132. } else {
  39133. var em = this.get('em');
  39134. console.error(err);
  39135. em && em.trigger('storage:error', err);
  39136. }
  39137. },
  39138. /**
  39139. * Triggered on request response
  39140. * @param {string} text Response text
  39141. * @private
  39142. */
  39143. onResponse: function onResponse(text, clb) {
  39144. var em = this.get('em');
  39145. var complete = this.get('onComplete');
  39146. var typeJson = this.get('contentTypeJson');
  39147. var parsable = text && typeof text === 'string';
  39148. var res = typeJson && parsable ? JSON.parse(text) : text;
  39149. complete && complete(res);
  39150. clb && clb(res);
  39151. em && em.trigger('storage:response', res);
  39152. },
  39153. store: function store(data, clb, clbErr) {
  39154. var body = {};
  39155. for (var key in data) {
  39156. body[key] = data[key];
  39157. }
  39158. this.request(this.get('urlStore'), {
  39159. body: body
  39160. }, clb, clbErr);
  39161. },
  39162. load: function load(keys, clb, clbErr) {
  39163. this.request(this.get('urlLoad'), {
  39164. method: 'get'
  39165. }, clb, clbErr);
  39166. },
  39167. /**
  39168. * Execute remote request
  39169. * @param {string} url Url
  39170. * @param {Object} [opts={}] Options
  39171. * @param {Function} [clb=null] Callback
  39172. * @param {Function} [clbErr=null] Error callback
  39173. * @private
  39174. */
  39175. request: function request(url) {
  39176. var _this = this;
  39177. var opts = arguments.length > 1 && arguments[1] !== undefined ? arguments[1] : {};
  39178. var clb = arguments.length > 2 && arguments[2] !== undefined ? arguments[2] : null;
  39179. var clbErr = arguments.length > 3 && arguments[3] !== undefined ? arguments[3] : null;
  39180. var typeJson = this.get('contentTypeJson');
  39181. var headers = this.get('headers') || {};
  39182. var params = this.get('params');
  39183. var reqHead = 'X-Requested-With';
  39184. var typeHead = 'Content-Type';
  39185. var bodyObj = opts.body || {};
  39186. var fetchOptions;
  39187. var body;
  39188. for (var param in params) {
  39189. bodyObj[param] = params[param];
  39190. }
  39191. if (Object(underscore__WEBPACK_IMPORTED_MODULE_3__["isUndefined"])(headers[reqHead])) {
  39192. headers[reqHead] = 'XMLHttpRequest';
  39193. } // With `fetch`, have to send FormData without any 'Content-Type'
  39194. // https://stackoverflow.com/questions/39280438/fetch-missing-boundary-in-multipart-form-data-post
  39195. if (Object(underscore__WEBPACK_IMPORTED_MODULE_3__["isUndefined"])(headers[typeHead]) && typeJson) {
  39196. headers[typeHead] = 'application/json; charset=utf-8';
  39197. }
  39198. if (typeJson) {
  39199. body = JSON.stringify(bodyObj);
  39200. } else {
  39201. body = new FormData();
  39202. for (var bodyKey in bodyObj) {
  39203. body.append(bodyKey, bodyObj[bodyKey]);
  39204. }
  39205. }
  39206. fetchOptions = {
  39207. method: opts.method || 'post',
  39208. credentials: this.get('credentials'),
  39209. headers: headers
  39210. }; // Body should only be included on POST method
  39211. if (fetchOptions.method === 'post') {
  39212. fetchOptions.body = body;
  39213. }
  39214. var fetchOpts = this.get('fetchOptions') || {};
  39215. var addOpts = Object(underscore__WEBPACK_IMPORTED_MODULE_3__["isFunction"])(fetchOpts) ? fetchOpts(fetchOptions) : fetchOptions;
  39216. this.onStart();
  39217. this.fetch(url, _objectSpread({}, fetchOptions, {}, addOpts || {})).then(function (res) {
  39218. return (res.status / 200 | 0) == 1 ? res.text() : res.text().then(function (text) {
  39219. return Promise.reject(text);
  39220. });
  39221. }).then(function (text) {
  39222. return _this.onResponse(text, clb);
  39223. }).catch(function (err) {
  39224. return _this.onError(err, clbErr);
  39225. });
  39226. }
  39227. }));
  39228. /***/ }),
  39229. /***/ "./src/style_manager/config/config.js":
  39230. /*!********************************************!*\
  39231. !*** ./src/style_manager/config/config.js ***!
  39232. \********************************************/
  39233. /*! exports provided: default */
  39234. /***/ (function(module, __webpack_exports__, __webpack_require__) {
  39235. "use strict";
  39236. __webpack_require__.r(__webpack_exports__);
  39237. /* harmony default export */ __webpack_exports__["default"] = ({
  39238. stylePrefix: 'sm-',
  39239. sectors: [],
  39240. // Specify the element to use as a container, string (query) or HTMLElement
  39241. // With the empty value, nothing will be rendered
  39242. appendTo: '',
  39243. // Hide the property in case it's not stylable for the
  39244. // selected component (each component has 'stylable' property)
  39245. hideNotStylable: true,
  39246. // Highlight changed properties of the selected component
  39247. highlightChanged: true,
  39248. // Highlight computed properties of the selected component
  39249. highlightComputed: true,
  39250. // Show computed properties of the selected component, if this value
  39251. // is set to false, highlightComputed will not take effect
  39252. showComputed: true,
  39253. // Adds the possibility to clear property value from the target style
  39254. clearProperties: 0,
  39255. // Properties not to take in account for computed styles
  39256. avoidComputed: ['width', 'height']
  39257. });
  39258. /***/ }),
  39259. /***/ "./src/style_manager/index.js":
  39260. /*!************************************!*\
  39261. !*** ./src/style_manager/index.js ***!
  39262. \************************************/
  39263. /*! exports provided: default */
  39264. /***/ (function(module, __webpack_exports__, __webpack_require__) {
  39265. "use strict";
  39266. __webpack_require__.r(__webpack_exports__);
  39267. /* harmony import */ var _babel_runtime_helpers_defineProperty__WEBPACK_IMPORTED_MODULE_0__ = __webpack_require__(/*! @babel/runtime/helpers/defineProperty */ "./node_modules/@babel/runtime/helpers/defineProperty.js");
  39268. /* harmony import */ var _babel_runtime_helpers_defineProperty__WEBPACK_IMPORTED_MODULE_0___default = /*#__PURE__*/__webpack_require__.n(_babel_runtime_helpers_defineProperty__WEBPACK_IMPORTED_MODULE_0__);
  39269. /* harmony import */ var underscore__WEBPACK_IMPORTED_MODULE_1__ = __webpack_require__(/*! underscore */ "./node_modules/underscore/underscore.js");
  39270. /* harmony import */ var underscore__WEBPACK_IMPORTED_MODULE_1___default = /*#__PURE__*/__webpack_require__.n(underscore__WEBPACK_IMPORTED_MODULE_1__);
  39271. /* harmony import */ var _config_config__WEBPACK_IMPORTED_MODULE_2__ = __webpack_require__(/*! ./config/config */ "./src/style_manager/config/config.js");
  39272. /* harmony import */ var _model_Sectors__WEBPACK_IMPORTED_MODULE_3__ = __webpack_require__(/*! ./model/Sectors */ "./src/style_manager/model/Sectors.js");
  39273. /* harmony import */ var _model_Properties__WEBPACK_IMPORTED_MODULE_4__ = __webpack_require__(/*! ./model/Properties */ "./src/style_manager/model/Properties.js");
  39274. /* harmony import */ var _view_SectorsView__WEBPACK_IMPORTED_MODULE_5__ = __webpack_require__(/*! ./view/SectorsView */ "./src/style_manager/view/SectorsView.js");
  39275. function ownKeys(object, enumerableOnly) { var keys = Object.keys(object); if (Object.getOwnPropertySymbols) { var symbols = Object.getOwnPropertySymbols(object); if (enumerableOnly) symbols = symbols.filter(function (sym) { return Object.getOwnPropertyDescriptor(object, sym).enumerable; }); keys.push.apply(keys, symbols); } return keys; }
  39276. function _objectSpread(target) { for (var i = 1; i < arguments.length; i++) { var source = arguments[i] != null ? arguments[i] : {}; if (i % 2) { ownKeys(source, true).forEach(function (key) { _babel_runtime_helpers_defineProperty__WEBPACK_IMPORTED_MODULE_0___default()(target, key, source[key]); }); } else if (Object.getOwnPropertyDescriptors) { Object.defineProperties(target, Object.getOwnPropertyDescriptors(source)); } else { ownKeys(source).forEach(function (key) { Object.defineProperty(target, key, Object.getOwnPropertyDescriptor(source, key)); }); } } return target; }
  39277. /**
  39278. * With Style Manager you build categories (called sectors) of CSS properties which could be used to customize the style of components.
  39279. * You can customize the initial state of the module from the editor initialization, by passing the following [Configuration Object](https://github.com/artf/grapesjs/blob/master/src/style_manager/config/config.js)
  39280. * ```js
  39281. * const editor = grapesjs.init({
  39282. * styleManager: {
  39283. * // options
  39284. * }
  39285. * })
  39286. * ```
  39287. *
  39288. * Once the editor is instantiated you can use its API. Before using these methods you should get the module from the instance
  39289. *
  39290. * ```js
  39291. * const styleManager = editor.StyleManager;
  39292. * ```
  39293. *
  39294. * * [getConfig](#getconfig)
  39295. * * [addSector](#addsector)
  39296. * * [getSector](#getsector)
  39297. * * [removeSector](#removesector)
  39298. * * [getSectors](#getsectors)
  39299. * * [addProperty](#addproperty)
  39300. * * [getProperty](#getproperty)
  39301. * * [removeProperty](#removeproperty)
  39302. * * [getProperties](#getproperties)
  39303. * * [getModelToStyle](#getmodeltostyle)
  39304. * * [addType](#addtype)
  39305. * * [getType](#gettype)
  39306. * * [getTypes](#gettypes)
  39307. * * [createType](#createtype)
  39308. *
  39309. * @module StyleManager
  39310. */
  39311. /* harmony default export */ __webpack_exports__["default"] = (function () {
  39312. var c = {};
  39313. var properties;
  39314. var sectors, SectView;
  39315. return {
  39316. /**
  39317. * Name of the module
  39318. * @type {String}
  39319. * @private
  39320. */
  39321. name: 'StyleManager',
  39322. /**
  39323. * Get configuration object
  39324. * @return {Object}
  39325. */
  39326. getConfig: function getConfig() {
  39327. return c;
  39328. },
  39329. /**
  39330. * Initialize module. Automatically called with a new instance of the editor
  39331. * @param {Object} config Configurations
  39332. * @private
  39333. */
  39334. init: function init(config) {
  39335. c = _objectSpread({}, _config_config__WEBPACK_IMPORTED_MODULE_2__["default"], {}, config);
  39336. var ppfx = c.pStylePrefix;
  39337. this.em = c.em;
  39338. if (ppfx) c.stylePrefix = ppfx + c.stylePrefix;
  39339. properties = new _model_Properties__WEBPACK_IMPORTED_MODULE_4__["default"]();
  39340. sectors = new _model_Sectors__WEBPACK_IMPORTED_MODULE_3__["default"]([], c);
  39341. SectView = new _view_SectorsView__WEBPACK_IMPORTED_MODULE_5__["default"]({
  39342. collection: sectors,
  39343. target: c.em,
  39344. config: c
  39345. });
  39346. return this;
  39347. },
  39348. onLoad: function onLoad() {
  39349. // Use silent as sectors' view will be created and rendered on StyleManager.render
  39350. sectors.add(c.sectors, {
  39351. silent: true
  39352. });
  39353. },
  39354. postRender: function postRender() {
  39355. var elTo = this.getConfig().appendTo;
  39356. if (elTo) {
  39357. var el = Object(underscore__WEBPACK_IMPORTED_MODULE_1__["isElement"])(elTo) ? elTo : document.querySelector(elTo);
  39358. el.appendChild(this.render());
  39359. }
  39360. },
  39361. /**
  39362. * Add new sector to the collection. If the sector with the same id already exists,
  39363. * that one will be returned
  39364. * @param {string} id Sector id
  39365. * @param {Object} sector Object representing sector
  39366. * @param {string} [sector.name=''] Sector's label
  39367. * @param {Boolean} [sector.open=true] Indicates if the sector should be opened
  39368. * @param {Array<Object>} [sector.properties=[]] Array of properties
  39369. * @param {Object} [options={}] Options
  39370. * @return {Sector} Added Sector
  39371. * @example
  39372. * var sector = styleManager.addSector('mySector',{
  39373. * name: 'My sector',
  39374. * open: true,
  39375. * properties: [{ name: 'My property'}]
  39376. * }, { at: 0 });
  39377. * // With `at: 0` we place the new sector at the beginning of the collection
  39378. * */
  39379. addSector: function addSector(id, sector) {
  39380. var opts = arguments.length > 2 && arguments[2] !== undefined ? arguments[2] : {};
  39381. var result = this.getSector(id);
  39382. if (!result) {
  39383. sector.id = id;
  39384. result = sectors.add(sector, opts);
  39385. }
  39386. return result;
  39387. },
  39388. /**
  39389. * Get sector by id
  39390. * @param {string} id Sector id
  39391. * @return {Sector|null}
  39392. * @example
  39393. * var sector = styleManager.getSector('mySector');
  39394. * */
  39395. getSector: function getSector(id) {
  39396. var opts = arguments.length > 1 && arguments[1] !== undefined ? arguments[1] : {};
  39397. var res = sectors.where({
  39398. id: id
  39399. })[0];
  39400. !res && opts.warn && this._logNoSector(id);
  39401. return res;
  39402. },
  39403. /**
  39404. * Remove a sector by id
  39405. * @param {string} id Sector id
  39406. * @return {Sector} Removed sector
  39407. * @example
  39408. * const removed = styleManager.removeSector('mySector');
  39409. */
  39410. removeSector: function removeSector(id) {
  39411. return this.getSectors().remove(this.getSector(id, {
  39412. warn: 1
  39413. }));
  39414. },
  39415. /**
  39416. * Get all sectors
  39417. * @return {Sectors} Collection of sectors
  39418. * */
  39419. getSectors: function getSectors() {
  39420. return sectors;
  39421. },
  39422. /**
  39423. * Add property to the sector identified by id
  39424. * @param {string} sectorId Sector id
  39425. * @param {Object} property Property object
  39426. * @param {string} [property.name=''] Name of the property
  39427. * @param {string} [property.property=''] CSS property, eg. `min-height`
  39428. * @param {string} [property.type=''] Type of the property: integer | radio | select | color | file | composite | stack
  39429. * @param {Array<string>} [property.units=[]] Unit of measure available, eg. ['px','%','em']. Only for integer type
  39430. * @param {string} [property.unit=''] Default selected unit from `units`. Only for integer type
  39431. * @param {number} [property.min=null] Min possible value. Only for integer type
  39432. * @param {number} [property.max=null] Max possible value. Only for integer type
  39433. * @param {string} [property.defaults=''] Default value
  39434. * @param {string} [property.info=''] Some description
  39435. * @param {string} [property.icon=''] Class name. If exists no text will be displayed
  39436. * @param {Boolean} [property.preview=false] Show layers preview. Only for stack type
  39437. * @param {string} [property.functionName=''] Indicates if value need to be wrapped in some function, for istance `transform: rotate(90deg)`
  39438. * @param {Array<Object>} [property.properties=[]] Nested properties for composite and stack type
  39439. * @param {Array<Object>} [property.layers=[]] Layers for stack properties
  39440. * @param {Array<Object>} [property.list=[]] List of possible options for radio and select types
  39441. * @param {Object} [options={}] Options
  39442. * @return {Property|null} Added Property or `null` in case sector doesn't exist
  39443. * @example
  39444. * var property = styleManager.addProperty('mySector',{
  39445. * name: 'Minimum height',
  39446. * property: 'min-height',
  39447. * type: 'select',
  39448. * defaults: '100px',
  39449. * list: [{
  39450. * value: '100px',
  39451. * name: '100',
  39452. * },{
  39453. * value: '200px',
  39454. * name: '200',
  39455. * }],
  39456. * }, { at: 0 });
  39457. * // With `at: 0` we place the new property at the beginning of the collection
  39458. */
  39459. addProperty: function addProperty(sectorId, property) {
  39460. var opts = arguments.length > 2 && arguments[2] !== undefined ? arguments[2] : {};
  39461. var sector = this.getSector(sectorId, {
  39462. warn: 1
  39463. });
  39464. var prop = null;
  39465. if (sector) prop = sector.get('properties').add(property, opts);
  39466. return prop;
  39467. },
  39468. /**
  39469. * Get property by its CSS name and sector id
  39470. * @param {string} sectorId Sector id
  39471. * @param {string} name CSS property name, eg. 'min-height'
  39472. * @return {Property|null}
  39473. * @example
  39474. * var property = styleManager.getProperty('mySector','min-height');
  39475. */
  39476. getProperty: function getProperty(sectorId, name) {
  39477. var sector = this.getSector(sectorId, {
  39478. warn: 1
  39479. });
  39480. var prop = null;
  39481. if (sector) {
  39482. prop = sector.get('properties').where({
  39483. property: name
  39484. });
  39485. prop = prop.length == 1 ? prop[0] : prop;
  39486. }
  39487. return prop;
  39488. },
  39489. /**
  39490. * Remove a property from the sector
  39491. * @param {string} sectorId Sector id
  39492. * @param {string} name CSS property name, eg. 'min-height'
  39493. * @return {Property} Removed property
  39494. * @example
  39495. * const property = styleManager.removeProperty('mySector', 'min-height');
  39496. */
  39497. removeProperty: function removeProperty(sectorId, name) {
  39498. var props = this.getProperties(sectorId);
  39499. return props && props.remove(this.getProperty(sectorId, name));
  39500. },
  39501. /**
  39502. * Get properties of the sector
  39503. * @param {string} sectorId Sector id
  39504. * @return {Properties} Collection of properties
  39505. * @example
  39506. * var properties = styleManager.getProperties('mySector');
  39507. */
  39508. getProperties: function getProperties(sectorId) {
  39509. var props = null;
  39510. var sector = this.getSector(sectorId, {
  39511. warn: 1
  39512. });
  39513. if (sector) props = sector.get('properties');
  39514. return props;
  39515. },
  39516. /**
  39517. * Get what to style inside Style Manager. If you select the component
  39518. * without classes the entity is the Component itself and all changes will
  39519. * go inside its 'style' property. Otherwise, if the selected component has
  39520. * one or more classes, the function will return the corresponding CSS Rule
  39521. * @param {Model} model
  39522. * @return {Model}
  39523. */
  39524. getModelToStyle: function getModelToStyle(model) {
  39525. var options = arguments.length > 1 && arguments[1] !== undefined ? arguments[1] : {};
  39526. var em = c.em;
  39527. var skipAdd = options.skipAdd;
  39528. var classes = model.get('classes');
  39529. var id = model.getId();
  39530. if (em) {
  39531. var config = em.getConfig();
  39532. var um = em.get('UndoManager');
  39533. var cssC = em.get('CssComposer');
  39534. var sm = em.get('SelectorManager');
  39535. var smConf = sm ? sm.getConfig() : {};
  39536. var state = !config.devicePreviewMode ? em.get('state') : '';
  39537. var valid = classes.getStyleable();
  39538. var hasClasses = valid.length;
  39539. var useClasses = !smConf.componentFirst || options.useClasses;
  39540. var opts = {
  39541. state: state
  39542. };
  39543. var rule; // I stop undo manager here as after adding the CSSRule (generally after
  39544. // selecting the component) and calling undo() it will remove the rule from
  39545. // the collection, therefore updating it in style manager will not affect it
  39546. // #268
  39547. um.stop();
  39548. if (hasClasses && useClasses) {
  39549. var deviceW = em.getCurrentMedia();
  39550. rule = cssC.get(valid, state, deviceW);
  39551. if (!rule && !skipAdd) {
  39552. rule = cssC.add(valid, state, deviceW);
  39553. }
  39554. } else if (config.avoidInlineStyle) {
  39555. rule = cssC.getIdRule(id, opts);
  39556. !rule && !skipAdd && (rule = cssC.setIdRule(id, {}, opts));
  39557. if (model.is('wrapper')) rule.set('wrapper', 1);
  39558. }
  39559. rule && (model = rule);
  39560. um.start();
  39561. }
  39562. return model;
  39563. },
  39564. /**
  39565. * Add new property type
  39566. * @param {string} id Type ID
  39567. * @param {Object} definition Definition of the type. Each definition contains
  39568. * `model` (business logic), `view` (presentation logic)
  39569. * and `isType` function which recognize the type of the
  39570. * passed entity
  39571. *@example
  39572. * styleManager.addType('my-type', {
  39573. * model: {},
  39574. * view: {},
  39575. * isType: (value) => {
  39576. * if (value && value.type == 'my-type') {
  39577. * return value;
  39578. * }
  39579. * },
  39580. * })
  39581. */
  39582. addType: function addType(id, definition) {
  39583. properties.addType(id, definition);
  39584. },
  39585. /**
  39586. * Get type
  39587. * @param {string} id Type ID
  39588. * @return {Object} Type definition
  39589. */
  39590. getType: function getType(id) {
  39591. return properties.getType(id);
  39592. },
  39593. /**
  39594. * Get all types
  39595. * @return {Array}
  39596. */
  39597. getTypes: function getTypes() {
  39598. return properties.getTypes();
  39599. },
  39600. /**
  39601. * Create new property from type
  39602. * @param {string} id Type ID
  39603. * @param {Object} [options={}] Options
  39604. * @param {Object} [options.model={}] Custom model object
  39605. * @param {Object} [options.view={}] Custom view object
  39606. * @return {PropertyView}
  39607. * @example
  39608. * const propView = styleManager.createType('integer', {
  39609. * model: {units: ['px', 'rem']}
  39610. * });
  39611. * propView.render();
  39612. * propView.model.on('change:value', ...);
  39613. * someContainer.appendChild(propView.el);
  39614. */
  39615. createType: function createType(id) {
  39616. var _ref = arguments.length > 1 && arguments[1] !== undefined ? arguments[1] : {},
  39617. _ref$model = _ref.model,
  39618. model = _ref$model === void 0 ? {} : _ref$model,
  39619. _ref$view = _ref.view,
  39620. view = _ref$view === void 0 ? {} : _ref$view;
  39621. var type = this.getType(id);
  39622. if (type) {
  39623. return new type.view(_objectSpread({
  39624. model: new type.model(model),
  39625. config: c
  39626. }, view));
  39627. }
  39628. },
  39629. /**
  39630. * Select different target for the Style Manager.
  39631. * It could be a Component, CSSRule, or a string of any CSS selector
  39632. * @param {Component|CSSRule|String} target
  39633. * @return {Styleable} A Component or CSSRule
  39634. */
  39635. setTarget: function setTarget(target, opts) {
  39636. return SectView.setTarget(target, opts);
  39637. },
  39638. getEmitter: function getEmitter() {
  39639. return SectView.propTarget;
  39640. },
  39641. /**
  39642. * Render sectors and properties
  39643. * @return {HTMLElement}
  39644. * @private
  39645. * */
  39646. render: function render() {
  39647. return SectView.render().el;
  39648. },
  39649. _logNoSector: function _logNoSector(sectorId) {
  39650. var em = this.em;
  39651. em && em.logWarning("'".concat(sectorId, "' sector not found"));
  39652. }
  39653. };
  39654. });
  39655. /***/ }),
  39656. /***/ "./src/style_manager/model/Layer.js":
  39657. /*!******************************************!*\
  39658. !*** ./src/style_manager/model/Layer.js ***!
  39659. \******************************************/
  39660. /*! exports provided: default */
  39661. /***/ (function(module, __webpack_exports__, __webpack_require__) {
  39662. "use strict";
  39663. __webpack_require__.r(__webpack_exports__);
  39664. /* harmony import */ var backbone__WEBPACK_IMPORTED_MODULE_0__ = __webpack_require__(/*! backbone */ "./node_modules/backbone/backbone.js");
  39665. /* harmony import */ var backbone__WEBPACK_IMPORTED_MODULE_0___default = /*#__PURE__*/__webpack_require__.n(backbone__WEBPACK_IMPORTED_MODULE_0__);
  39666. /* harmony import */ var _Properties__WEBPACK_IMPORTED_MODULE_1__ = __webpack_require__(/*! ./Properties */ "./src/style_manager/model/Properties.js");
  39667. /* harmony default export */ __webpack_exports__["default"] = (backbone__WEBPACK_IMPORTED_MODULE_0___default.a.Model.extend({
  39668. defaults: {
  39669. index: '',
  39670. value: '',
  39671. values: {},
  39672. active: false,
  39673. preview: false,
  39674. properties: []
  39675. },
  39676. initialize: function initialize() {
  39677. var prp = this.get('properties');
  39678. var value = this.get('value');
  39679. this.set('properties', prp instanceof _Properties__WEBPACK_IMPORTED_MODULE_1__["default"] ? prp : new _Properties__WEBPACK_IMPORTED_MODULE_1__["default"](prp));
  39680. var props = this.get('properties');
  39681. props.forEach(this.onPropAdd, this);
  39682. this.listenTo(props, 'add', this.onPropAdd); // If there is no value I'll try to get it from values
  39683. // I need value setted to make preview working
  39684. if (!value) {
  39685. var val = '';
  39686. var values = this.get('values');
  39687. for (var prop in values) {
  39688. val += ' ' + values[prop];
  39689. }
  39690. this.set('value', val.trim());
  39691. }
  39692. },
  39693. onPropAdd: function onPropAdd(prop) {
  39694. var coll = this.collection;
  39695. prop.parent = coll && coll.property;
  39696. },
  39697. /**
  39698. * Get property at some index
  39699. * @param {Number} index
  39700. * @return {Object}
  39701. */
  39702. getPropertyAt: function getPropertyAt(index) {
  39703. return this.get('properties').at(index);
  39704. },
  39705. getPropertyValue: function getPropertyValue(property) {
  39706. var result = '';
  39707. this.get('properties').each(function (prop) {
  39708. if (prop.get('property') == property) {
  39709. result = prop.getFullValue();
  39710. }
  39711. });
  39712. return result;
  39713. },
  39714. getFullValue: function getFullValue() {
  39715. var result = [];
  39716. this.get('properties').each(function (prop) {
  39717. return result.push(prop.getFullValue());
  39718. });
  39719. return result.join(' ').trim();
  39720. }
  39721. }));
  39722. /***/ }),
  39723. /***/ "./src/style_manager/model/Layers.js":
  39724. /*!*******************************************!*\
  39725. !*** ./src/style_manager/model/Layers.js ***!
  39726. \*******************************************/
  39727. /*! exports provided: default */
  39728. /***/ (function(module, __webpack_exports__, __webpack_require__) {
  39729. "use strict";
  39730. __webpack_require__.r(__webpack_exports__);
  39731. /* harmony import */ var _babel_runtime_helpers_defineProperty__WEBPACK_IMPORTED_MODULE_0__ = __webpack_require__(/*! @babel/runtime/helpers/defineProperty */ "./node_modules/@babel/runtime/helpers/defineProperty.js");
  39732. /* harmony import */ var _babel_runtime_helpers_defineProperty__WEBPACK_IMPORTED_MODULE_0___default = /*#__PURE__*/__webpack_require__.n(_babel_runtime_helpers_defineProperty__WEBPACK_IMPORTED_MODULE_0__);
  39733. /* harmony import */ var underscore__WEBPACK_IMPORTED_MODULE_1__ = __webpack_require__(/*! underscore */ "./node_modules/underscore/underscore.js");
  39734. /* harmony import */ var underscore__WEBPACK_IMPORTED_MODULE_1___default = /*#__PURE__*/__webpack_require__.n(underscore__WEBPACK_IMPORTED_MODULE_1__);
  39735. /* harmony import */ var backbone__WEBPACK_IMPORTED_MODULE_2__ = __webpack_require__(/*! backbone */ "./node_modules/backbone/backbone.js");
  39736. /* harmony import */ var backbone__WEBPACK_IMPORTED_MODULE_2___default = /*#__PURE__*/__webpack_require__.n(backbone__WEBPACK_IMPORTED_MODULE_2__);
  39737. /* harmony import */ var _Layer__WEBPACK_IMPORTED_MODULE_3__ = __webpack_require__(/*! ./Layer */ "./src/style_manager/model/Layer.js");
  39738. function ownKeys(object, enumerableOnly) { var keys = Object.keys(object); if (Object.getOwnPropertySymbols) { var symbols = Object.getOwnPropertySymbols(object); if (enumerableOnly) symbols = symbols.filter(function (sym) { return Object.getOwnPropertyDescriptor(object, sym).enumerable; }); keys.push.apply(keys, symbols); } return keys; }
  39739. function _objectSpread(target) { for (var i = 1; i < arguments.length; i++) { var source = arguments[i] != null ? arguments[i] : {}; if (i % 2) { ownKeys(source, true).forEach(function (key) { _babel_runtime_helpers_defineProperty__WEBPACK_IMPORTED_MODULE_0___default()(target, key, source[key]); }); } else if (Object.getOwnPropertyDescriptors) { Object.defineProperties(target, Object.getOwnPropertyDescriptors(source)); } else { ownKeys(source).forEach(function (key) { Object.defineProperty(target, key, Object.getOwnPropertyDescriptor(source, key)); }); } } return target; }
  39740. /* harmony default export */ __webpack_exports__["default"] = (backbone__WEBPACK_IMPORTED_MODULE_2___default.a.Collection.extend({
  39741. model: _Layer__WEBPACK_IMPORTED_MODULE_3__["default"],
  39742. initialize: function initialize() {
  39743. this.idx = 1;
  39744. this.on('add', this.onAdd);
  39745. this.on('reset', this.onReset);
  39746. },
  39747. onAdd: function onAdd(model, c, opts) {
  39748. if (!opts.noIncrement) model.set('index', this.idx++);
  39749. opts.active && this.active(this.indexOf(model));
  39750. },
  39751. onReset: function onReset() {
  39752. this.idx = 1;
  39753. },
  39754. getSeparator: function getSeparator() {
  39755. var property = this.property;
  39756. return property ? property.get('layerSeparator') : ', ';
  39757. },
  39758. /**
  39759. * Get layers from a value string (for not detached properties),
  39760. * example of input:
  39761. * `layer1Value, layer2Value, layer3Value, ...`
  39762. * @param {string} value
  39763. * @return {Array}
  39764. * @private
  39765. */
  39766. getLayersFromValue: function getLayersFromValue(value) {
  39767. var _this = this;
  39768. var layers = []; // Remove spaces inside functions, eg:
  39769. // From: 1px 1px rgba(2px, 2px, 2px), 2px 2px rgba(3px, 3px, 3px)
  39770. // To: 1px 1px rgba(2px,2px,2px), 2px 2px rgba(3px,3px,3px)
  39771. value.replace(/\(([\w\s,.]*)\)/g, function (match) {
  39772. var cleaned = match.replace(/,\s*/g, ',');
  39773. value = value.replace(match, cleaned);
  39774. });
  39775. var layerValues = value ? value.split(this.getSeparator()) : [];
  39776. layerValues.forEach(function (layerValue) {
  39777. layers.push({
  39778. properties: _this.properties.parseValue(layerValue)
  39779. });
  39780. });
  39781. return layers;
  39782. },
  39783. /**
  39784. * Get layers from a style object (for detached properties),
  39785. * example of input:
  39786. * {
  39787. * subPropname1: sub-propvalue11, sub-propvalue12, sub-propvalue13, ...
  39788. * subPropname2: sub-propvalue21, sub-propvalue22, sub-propvalue23, ...
  39789. * subPropname3: sub-propvalue31, sub-propvalue32, sub-propvalue33, ...
  39790. * }
  39791. * @param {Object} styleObj
  39792. * @return {Array}
  39793. * @private
  39794. */
  39795. getLayersFromStyle: function getLayersFromStyle(styleObj) {
  39796. var layers = [];
  39797. var properties = this.properties;
  39798. properties.each(function (propModel) {
  39799. var style = styleObj[propModel.get('property')];
  39800. var values = style ? style.split(', ') : [];
  39801. values.forEach(function (value, i) {
  39802. value = propModel.parseValue(value.trim()).value;
  39803. var layer = layers[i];
  39804. var propertyObj = _objectSpread({}, propModel.attributes, {}, {
  39805. value: value
  39806. });
  39807. if (layer) {
  39808. layer.properties.push(propertyObj);
  39809. } else {
  39810. layers[i] = {
  39811. properties: [propertyObj]
  39812. };
  39813. }
  39814. });
  39815. }); // Now whit all layers in, will check missing properties
  39816. layers.forEach(function (layer) {
  39817. var layerProprs = layer.properties.map(function (prop) {
  39818. return prop.property;
  39819. });
  39820. properties.each(function (propModel) {
  39821. var propertyName = propModel.get('property');
  39822. if (layerProprs.indexOf(propertyName) < 0) {
  39823. layer.properties.push(_objectSpread({}, propModel.attributes));
  39824. }
  39825. });
  39826. });
  39827. return layers;
  39828. },
  39829. active: function active(index) {
  39830. this.each(function (layer) {
  39831. return layer.set('active', 0);
  39832. });
  39833. var layer = this.at(index);
  39834. layer && layer.set('active', 1);
  39835. },
  39836. getFullValue: function getFullValue() {
  39837. var result = [];
  39838. this.each(function (layer) {
  39839. return result.push(layer.getFullValue());
  39840. });
  39841. return result.join(this.getSeparator());
  39842. },
  39843. getPropertyValues: function getPropertyValues(property, defValue) {
  39844. var result = [];
  39845. this.each(function (layer) {
  39846. var value = layer.getPropertyValue(property);
  39847. value ? result.push(value) : !Object(underscore__WEBPACK_IMPORTED_MODULE_1__["isUndefined"])(defValue) && result.push(defValue);
  39848. });
  39849. return result.join(', ');
  39850. }
  39851. }));
  39852. /***/ }),
  39853. /***/ "./src/style_manager/model/Properties.js":
  39854. /*!***********************************************!*\
  39855. !*** ./src/style_manager/model/Properties.js ***!
  39856. \***********************************************/
  39857. /*! exports provided: default */
  39858. /***/ (function(module, __webpack_exports__, __webpack_require__) {
  39859. "use strict";
  39860. __webpack_require__.r(__webpack_exports__);
  39861. /* harmony import */ var _babel_runtime_helpers_defineProperty__WEBPACK_IMPORTED_MODULE_0__ = __webpack_require__(/*! @babel/runtime/helpers/defineProperty */ "./node_modules/@babel/runtime/helpers/defineProperty.js");
  39862. /* harmony import */ var _babel_runtime_helpers_defineProperty__WEBPACK_IMPORTED_MODULE_0___default = /*#__PURE__*/__webpack_require__.n(_babel_runtime_helpers_defineProperty__WEBPACK_IMPORTED_MODULE_0__);
  39863. /* harmony import */ var backbone__WEBPACK_IMPORTED_MODULE_1__ = __webpack_require__(/*! backbone */ "./node_modules/backbone/backbone.js");
  39864. /* harmony import */ var backbone__WEBPACK_IMPORTED_MODULE_1___default = /*#__PURE__*/__webpack_require__.n(backbone__WEBPACK_IMPORTED_MODULE_1__);
  39865. /* harmony import */ var domain_abstract_model_TypeableCollection__WEBPACK_IMPORTED_MODULE_2__ = __webpack_require__(/*! domain_abstract/model/TypeableCollection */ "./src/domain_abstract/model/TypeableCollection.js");
  39866. /* harmony import */ var _Property__WEBPACK_IMPORTED_MODULE_3__ = __webpack_require__(/*! ./Property */ "./src/style_manager/model/Property.js");
  39867. /* harmony import */ var _PropertyStack__WEBPACK_IMPORTED_MODULE_4__ = __webpack_require__(/*! ./PropertyStack */ "./src/style_manager/model/PropertyStack.js");
  39868. /* harmony import */ var _view_PropertyStackView__WEBPACK_IMPORTED_MODULE_5__ = __webpack_require__(/*! ./../view/PropertyStackView */ "./src/style_manager/view/PropertyStackView.js");
  39869. /* harmony import */ var _PropertyComposite__WEBPACK_IMPORTED_MODULE_6__ = __webpack_require__(/*! ./PropertyComposite */ "./src/style_manager/model/PropertyComposite.js");
  39870. /* harmony import */ var _view_PropertyCompositeView__WEBPACK_IMPORTED_MODULE_7__ = __webpack_require__(/*! ./../view/PropertyCompositeView */ "./src/style_manager/view/PropertyCompositeView.js");
  39871. /* harmony import */ var _view_PropertyFileView__WEBPACK_IMPORTED_MODULE_8__ = __webpack_require__(/*! ./../view/PropertyFileView */ "./src/style_manager/view/PropertyFileView.js");
  39872. /* harmony import */ var _view_PropertyColorView__WEBPACK_IMPORTED_MODULE_9__ = __webpack_require__(/*! ./../view/PropertyColorView */ "./src/style_manager/view/PropertyColorView.js");
  39873. /* harmony import */ var _PropertySelect__WEBPACK_IMPORTED_MODULE_10__ = __webpack_require__(/*! ./PropertySelect */ "./src/style_manager/model/PropertySelect.js");
  39874. /* harmony import */ var _view_PropertySelectView__WEBPACK_IMPORTED_MODULE_11__ = __webpack_require__(/*! ./../view/PropertySelectView */ "./src/style_manager/view/PropertySelectView.js");
  39875. /* harmony import */ var _PropertyRadio__WEBPACK_IMPORTED_MODULE_12__ = __webpack_require__(/*! ./PropertyRadio */ "./src/style_manager/model/PropertyRadio.js");
  39876. /* harmony import */ var _view_PropertyRadioView__WEBPACK_IMPORTED_MODULE_13__ = __webpack_require__(/*! ./../view/PropertyRadioView */ "./src/style_manager/view/PropertyRadioView.js");
  39877. /* harmony import */ var _PropertySlider__WEBPACK_IMPORTED_MODULE_14__ = __webpack_require__(/*! ./PropertySlider */ "./src/style_manager/model/PropertySlider.js");
  39878. /* harmony import */ var _view_PropertySliderView__WEBPACK_IMPORTED_MODULE_15__ = __webpack_require__(/*! ./../view/PropertySliderView */ "./src/style_manager/view/PropertySliderView.js");
  39879. /* harmony import */ var _PropertyInteger__WEBPACK_IMPORTED_MODULE_16__ = __webpack_require__(/*! ./PropertyInteger */ "./src/style_manager/model/PropertyInteger.js");
  39880. /* harmony import */ var _view_PropertyIntegerView__WEBPACK_IMPORTED_MODULE_17__ = __webpack_require__(/*! ./../view/PropertyIntegerView */ "./src/style_manager/view/PropertyIntegerView.js");
  39881. /* harmony import */ var _view_PropertyView__WEBPACK_IMPORTED_MODULE_18__ = __webpack_require__(/*! ./../view/PropertyView */ "./src/style_manager/view/PropertyView.js");
  39882. function ownKeys(object, enumerableOnly) { var keys = Object.keys(object); if (Object.getOwnPropertySymbols) { var symbols = Object.getOwnPropertySymbols(object); if (enumerableOnly) symbols = symbols.filter(function (sym) { return Object.getOwnPropertyDescriptor(object, sym).enumerable; }); keys.push.apply(keys, symbols); } return keys; }
  39883. function _objectSpread(target) { for (var i = 1; i < arguments.length; i++) { var source = arguments[i] != null ? arguments[i] : {}; if (i % 2) { ownKeys(source, true).forEach(function (key) { _babel_runtime_helpers_defineProperty__WEBPACK_IMPORTED_MODULE_0___default()(target, key, source[key]); }); } else if (Object.getOwnPropertyDescriptors) { Object.defineProperties(target, Object.getOwnPropertyDescriptors(source)); } else { ownKeys(source).forEach(function (key) { Object.defineProperty(target, key, Object.getOwnPropertyDescriptor(source, key)); }); } } return target; }
  39884. /* harmony default export */ __webpack_exports__["default"] = (backbone__WEBPACK_IMPORTED_MODULE_1___default.a.Collection.extend(domain_abstract_model_TypeableCollection__WEBPACK_IMPORTED_MODULE_2__["default"]).extend({
  39885. types: [{
  39886. id: 'stack',
  39887. model: _PropertyStack__WEBPACK_IMPORTED_MODULE_4__["default"],
  39888. view: _view_PropertyStackView__WEBPACK_IMPORTED_MODULE_5__["default"],
  39889. isType: function isType(value) {
  39890. if (value && value.type == 'stack') {
  39891. return value;
  39892. }
  39893. }
  39894. }, {
  39895. id: 'composite',
  39896. model: _PropertyComposite__WEBPACK_IMPORTED_MODULE_6__["default"],
  39897. view: _view_PropertyCompositeView__WEBPACK_IMPORTED_MODULE_7__["default"],
  39898. isType: function isType(value) {
  39899. if (value && value.type == 'composite') {
  39900. return value;
  39901. }
  39902. }
  39903. }, {
  39904. id: 'file',
  39905. model: _Property__WEBPACK_IMPORTED_MODULE_3__["default"],
  39906. view: _view_PropertyFileView__WEBPACK_IMPORTED_MODULE_8__["default"],
  39907. isType: function isType(value) {
  39908. if (value && value.type == 'file') {
  39909. return value;
  39910. }
  39911. }
  39912. }, {
  39913. id: 'color',
  39914. model: _Property__WEBPACK_IMPORTED_MODULE_3__["default"],
  39915. view: _view_PropertyColorView__WEBPACK_IMPORTED_MODULE_9__["default"],
  39916. isType: function isType(value) {
  39917. if (value && value.type == 'color') {
  39918. return value;
  39919. }
  39920. }
  39921. }, {
  39922. id: 'select',
  39923. model: _PropertySelect__WEBPACK_IMPORTED_MODULE_10__["default"],
  39924. view: _view_PropertySelectView__WEBPACK_IMPORTED_MODULE_11__["default"],
  39925. isType: function isType(value) {
  39926. if (value && value.type == 'select') {
  39927. return value;
  39928. }
  39929. }
  39930. }, {
  39931. id: 'radio',
  39932. model: _PropertyRadio__WEBPACK_IMPORTED_MODULE_12__["default"],
  39933. view: _view_PropertyRadioView__WEBPACK_IMPORTED_MODULE_13__["default"],
  39934. isType: function isType(value) {
  39935. if (value && value.type == 'radio') {
  39936. return value;
  39937. }
  39938. }
  39939. }, {
  39940. id: 'slider',
  39941. model: _PropertySlider__WEBPACK_IMPORTED_MODULE_14__["default"],
  39942. view: _view_PropertySliderView__WEBPACK_IMPORTED_MODULE_15__["default"],
  39943. isType: function isType(value) {
  39944. if (value && value.type == 'slider') {
  39945. return value;
  39946. }
  39947. }
  39948. }, {
  39949. id: 'integer',
  39950. model: _PropertyInteger__WEBPACK_IMPORTED_MODULE_16__["default"],
  39951. view: _view_PropertyIntegerView__WEBPACK_IMPORTED_MODULE_17__["default"],
  39952. isType: function isType(value) {
  39953. if (value && value.type == 'integer') {
  39954. return value;
  39955. }
  39956. }
  39957. }, {
  39958. id: 'base',
  39959. model: _Property__WEBPACK_IMPORTED_MODULE_3__["default"],
  39960. view: _view_PropertyView__WEBPACK_IMPORTED_MODULE_18__["default"],
  39961. isType: function isType(value) {
  39962. value.type = 'base';
  39963. return value;
  39964. }
  39965. }],
  39966. deepClone: function deepClone() {
  39967. var collection = this.clone();
  39968. collection.reset(collection.map(function (model) {
  39969. var cloned = model.clone();
  39970. cloned.typeView = model.typeView;
  39971. return cloned;
  39972. }));
  39973. return collection;
  39974. },
  39975. /**
  39976. * Parse a value and return an array splitted by properties
  39977. * @param {string} value
  39978. * @return {Array}
  39979. * @return
  39980. */
  39981. parseValue: function parseValue(value) {
  39982. var _this = this;
  39983. var properties = [];
  39984. var values = value.split(' ');
  39985. values.forEach(function (value, i) {
  39986. var property = _this.at(i);
  39987. if (!property) return;
  39988. properties.push(_objectSpread({}, property.attributes, {}, {
  39989. value: value
  39990. }));
  39991. });
  39992. return properties;
  39993. },
  39994. getFullValue: function getFullValue() {
  39995. var result = '';
  39996. this.each(function (model) {
  39997. return result += "".concat(model.getFullValue(), " ");
  39998. });
  39999. return result.trim();
  40000. }
  40001. }));
  40002. /***/ }),
  40003. /***/ "./src/style_manager/model/Property.js":
  40004. /*!*********************************************!*\
  40005. !*** ./src/style_manager/model/Property.js ***!
  40006. \*********************************************/
  40007. /*! exports provided: default */
  40008. /***/ (function(module, __webpack_exports__, __webpack_require__) {
  40009. "use strict";
  40010. __webpack_require__.r(__webpack_exports__);
  40011. /* harmony import */ var _babel_runtime_helpers_defineProperty__WEBPACK_IMPORTED_MODULE_0__ = __webpack_require__(/*! @babel/runtime/helpers/defineProperty */ "./node_modules/@babel/runtime/helpers/defineProperty.js");
  40012. /* harmony import */ var _babel_runtime_helpers_defineProperty__WEBPACK_IMPORTED_MODULE_0___default = /*#__PURE__*/__webpack_require__.n(_babel_runtime_helpers_defineProperty__WEBPACK_IMPORTED_MODULE_0__);
  40013. /* harmony import */ var backbone__WEBPACK_IMPORTED_MODULE_1__ = __webpack_require__(/*! backbone */ "./node_modules/backbone/backbone.js");
  40014. /* harmony import */ var backbone__WEBPACK_IMPORTED_MODULE_1___default = /*#__PURE__*/__webpack_require__.n(backbone__WEBPACK_IMPORTED_MODULE_1__);
  40015. /* harmony import */ var underscore__WEBPACK_IMPORTED_MODULE_2__ = __webpack_require__(/*! underscore */ "./node_modules/underscore/underscore.js");
  40016. /* harmony import */ var underscore__WEBPACK_IMPORTED_MODULE_2___default = /*#__PURE__*/__webpack_require__.n(underscore__WEBPACK_IMPORTED_MODULE_2__);
  40017. /* harmony import */ var utils_mixins__WEBPACK_IMPORTED_MODULE_3__ = __webpack_require__(/*! utils/mixins */ "./src/utils/mixins.js");
  40018. function ownKeys(object, enumerableOnly) { var keys = Object.keys(object); if (Object.getOwnPropertySymbols) { var symbols = Object.getOwnPropertySymbols(object); if (enumerableOnly) symbols = symbols.filter(function (sym) { return Object.getOwnPropertyDescriptor(object, sym).enumerable; }); keys.push.apply(keys, symbols); } return keys; }
  40019. function _objectSpread(target) { for (var i = 1; i < arguments.length; i++) { var source = arguments[i] != null ? arguments[i] : {}; if (i % 2) { ownKeys(source, true).forEach(function (key) { _babel_runtime_helpers_defineProperty__WEBPACK_IMPORTED_MODULE_0___default()(target, key, source[key]); }); } else if (Object.getOwnPropertyDescriptors) { Object.defineProperties(target, Object.getOwnPropertyDescriptors(source)); } else { ownKeys(source).forEach(function (key) { Object.defineProperty(target, key, Object.getOwnPropertyDescriptor(source, key)); }); } } return target; }
  40020. var Property = backbone__WEBPACK_IMPORTED_MODULE_1___default.a.Model.extend({
  40021. defaults: {
  40022. name: '',
  40023. property: '',
  40024. type: '',
  40025. defaults: '',
  40026. info: '',
  40027. value: '',
  40028. icon: '',
  40029. functionName: '',
  40030. status: '',
  40031. visible: true,
  40032. fixedValues: ['initial', 'inherit'],
  40033. // If true, the property will be forced to be full width
  40034. full: 0,
  40035. // If true to the value will be added '!important'
  40036. important: 0,
  40037. // If true, will be hidden by default and will show up only for targets
  40038. // which require this property (via `stylable-require`)
  40039. // Use case:
  40040. // you can add all SVG CSS properties with toRequire as true
  40041. // and then require them on SVG Components
  40042. toRequire: 0,
  40043. // Specifies dependency on other properties of the selected object.
  40044. // Property is shown only when all conditions are matched.
  40045. //
  40046. // example: { display: ['flex', 'block'], position: ['absolute'] };
  40047. // in this case the property is only shown when display is
  40048. // of value 'flex' or 'block' AND position is 'absolute'
  40049. requires: null,
  40050. // Specifies dependency on properties of the parent of the selected object.
  40051. // Property is shown only when all conditions are matched.
  40052. requiresParent: null
  40053. },
  40054. initialize: function initialize() {
  40055. var props = arguments.length > 0 && arguments[0] !== undefined ? arguments[0] : {};
  40056. var opts = arguments.length > 1 && arguments[1] !== undefined ? arguments[1] : {};
  40057. var id = this.get('id') || '';
  40058. var name = this.get('name') || '';
  40059. !this.get('property') && this.set('property', (name || id).replace(/ /g, '-'));
  40060. var prop = this.get('property');
  40061. !this.get('id') && this.set('id', prop);
  40062. !name && this.set('name', Object(utils_mixins__WEBPACK_IMPORTED_MODULE_3__["capitalize"])(prop).replace(/-/g, ' '));
  40063. Property.callInit(this, props, opts);
  40064. },
  40065. init: function init() {},
  40066. /**
  40067. * Clear the value
  40068. * @return {this}
  40069. */
  40070. clearValue: function clearValue() {
  40071. var opts = arguments.length > 0 && arguments[0] !== undefined ? arguments[0] : {};
  40072. this.set({
  40073. value: undefined,
  40074. status: ''
  40075. }, opts);
  40076. return this;
  40077. },
  40078. /**
  40079. * Update value
  40080. * @param {any} value
  40081. * @param {Boolen} [complete=true] Indicates if it's a final state
  40082. * @param {Object} [opts={}] Options
  40083. */
  40084. setValue: function setValue(value) {
  40085. var complete = arguments.length > 1 && arguments[1] !== undefined ? arguments[1] : 1;
  40086. var opts = arguments.length > 2 && arguments[2] !== undefined ? arguments[2] : {};
  40087. var parsed = this.parseValue(value);
  40088. var avoidStore = !complete;
  40089. !avoidStore && this.set({
  40090. value: ''
  40091. }, {
  40092. avoidStore: avoidStore,
  40093. silent: true
  40094. });
  40095. this.set(parsed, _objectSpread({
  40096. avoidStore: avoidStore
  40097. }, opts));
  40098. },
  40099. /**
  40100. * Like `setValue` but, in addition, prevents the update of the input element
  40101. * as the changes should come from the input itself.
  40102. * This method is useful with the definition of custom properties
  40103. * @param {any} value
  40104. * @param {Boolen} [complete=true] Indicates if it's a final state
  40105. * @param {Object} [opts={}] Options
  40106. */
  40107. setValueFromInput: function setValueFromInput(value, complete) {
  40108. var opts = arguments.length > 2 && arguments[2] !== undefined ? arguments[2] : {};
  40109. this.setValue(value, complete, _objectSpread({}, opts, {
  40110. fromInput: 1
  40111. }));
  40112. },
  40113. /**
  40114. * Parse a raw value, generally fetched from the target, for this property
  40115. * @param {string} value Raw value string
  40116. * @return {Object}
  40117. * @example
  40118. * // example with an Input type
  40119. * prop.parseValue('translateX(10deg)');
  40120. * // -> { value: 10, unit: 'deg', functionName: 'translateX' }
  40121. *
  40122. */
  40123. parseValue: function parseValue(value) {
  40124. var opts = arguments.length > 1 && arguments[1] !== undefined ? arguments[1] : {};
  40125. var result = {
  40126. value: value
  40127. };
  40128. var imp = '!important';
  40129. if (Object(underscore__WEBPACK_IMPORTED_MODULE_2__["isString"])(value) && value.indexOf(imp) !== -1) {
  40130. result.value = value.replace(imp, '').trim();
  40131. result.important = 1;
  40132. }
  40133. if (!this.get('functionName') && !opts.complete) {
  40134. return result;
  40135. }
  40136. var args = [];
  40137. var valueStr = "".concat(result.value);
  40138. var start = valueStr.indexOf('(') + 1;
  40139. var end = valueStr.lastIndexOf(')');
  40140. var functionName = valueStr.substring(0, start - 1);
  40141. if (functionName) result.functionName = functionName;
  40142. args.push(start); // Will try even if the last closing parentheses is not found
  40143. if (end >= 0) {
  40144. args.push(end);
  40145. }
  40146. result.value = String.prototype.substring.apply(valueStr, args);
  40147. if (opts.numeric) {
  40148. var num = parseFloat(result.value);
  40149. result.unit = result.value.replace(num, '');
  40150. result.value = num;
  40151. }
  40152. return result;
  40153. },
  40154. /**
  40155. * Helper function to safely split a string of values.
  40156. * Useful when style values are inside functions
  40157. * eg:
  40158. * -> input: 'value(1,2,4), 123, value(4,5)' -- default separator: ','
  40159. * -> output: ['value(1,2,4)', '123', 'value(4,5)']
  40160. * @param {String} values Values to split
  40161. * @param {String} [separator] Separator
  40162. */
  40163. splitValues: function splitValues(values) {
  40164. var separator = arguments.length > 1 && arguments[1] !== undefined ? arguments[1] : ',';
  40165. var res = [];
  40166. var op = '(';
  40167. var cl = ')';
  40168. var curr = '';
  40169. var acc = 0;
  40170. (values || '').split('').forEach(function (str) {
  40171. if (str == op) {
  40172. acc++;
  40173. curr = curr + op;
  40174. } else if (str == cl && acc > 0) {
  40175. acc--;
  40176. curr = curr + cl;
  40177. } else if (str === separator && acc == 0) {
  40178. res.push(curr);
  40179. curr = '';
  40180. } else {
  40181. curr = curr + str;
  40182. }
  40183. });
  40184. curr !== '' && res.push(curr);
  40185. return res.map(function (i) {
  40186. return i.trim();
  40187. });
  40188. },
  40189. /**
  40190. * Get the default value
  40191. * @return {string}
  40192. * @private
  40193. */
  40194. getDefaultValue: function getDefaultValue() {
  40195. return this.get('defaults');
  40196. },
  40197. /**
  40198. * Get a complete value of the property.
  40199. * This probably will replace the getValue when all
  40200. * properties models will be splitted
  40201. * @param {string} val Custom value to replace the one on the model
  40202. * @return {string}
  40203. * @private
  40204. */
  40205. getFullValue: function getFullValue(val) {
  40206. var fn = this.get('functionName');
  40207. var def = this.getDefaultValue();
  40208. var value = Object(underscore__WEBPACK_IMPORTED_MODULE_2__["isUndefined"])(val) ? this.get('value') : val;
  40209. var hasValue = !Object(underscore__WEBPACK_IMPORTED_MODULE_2__["isUndefined"])(value) && value !== '';
  40210. if (value && def && value === def) {
  40211. return def;
  40212. }
  40213. if (fn && hasValue) {
  40214. value = "".concat(fn, "(").concat(value, ")");
  40215. }
  40216. if (hasValue && this.get('important')) {
  40217. value = "".concat(value, " !important");
  40218. }
  40219. return value || '';
  40220. }
  40221. }, {
  40222. callParentInit: function callParentInit(property, ctx, props) {
  40223. var opts = arguments.length > 3 && arguments[3] !== undefined ? arguments[3] : {};
  40224. property.prototype.initialize.apply(ctx, [props, _objectSpread({}, opts, {
  40225. skipInit: 1
  40226. })]);
  40227. },
  40228. callInit: function callInit(context, props) {
  40229. var opts = arguments.length > 2 && arguments[2] !== undefined ? arguments[2] : {};
  40230. !opts.skipInit && context.init(props, opts);
  40231. }
  40232. });
  40233. /* harmony default export */ __webpack_exports__["default"] = (Property);
  40234. /***/ }),
  40235. /***/ "./src/style_manager/model/PropertyComposite.js":
  40236. /*!******************************************************!*\
  40237. !*** ./src/style_manager/model/PropertyComposite.js ***!
  40238. \******************************************************/
  40239. /*! exports provided: default */
  40240. /***/ (function(module, __webpack_exports__, __webpack_require__) {
  40241. "use strict";
  40242. __webpack_require__.r(__webpack_exports__);
  40243. /* harmony import */ var _babel_runtime_helpers_defineProperty__WEBPACK_IMPORTED_MODULE_0__ = __webpack_require__(/*! @babel/runtime/helpers/defineProperty */ "./node_modules/@babel/runtime/helpers/defineProperty.js");
  40244. /* harmony import */ var _babel_runtime_helpers_defineProperty__WEBPACK_IMPORTED_MODULE_0___default = /*#__PURE__*/__webpack_require__.n(_babel_runtime_helpers_defineProperty__WEBPACK_IMPORTED_MODULE_0__);
  40245. /* harmony import */ var _Property__WEBPACK_IMPORTED_MODULE_1__ = __webpack_require__(/*! ./Property */ "./src/style_manager/model/Property.js");
  40246. function ownKeys(object, enumerableOnly) { var keys = Object.keys(object); if (Object.getOwnPropertySymbols) { var symbols = Object.getOwnPropertySymbols(object); if (enumerableOnly) symbols = symbols.filter(function (sym) { return Object.getOwnPropertyDescriptor(object, sym).enumerable; }); keys.push.apply(keys, symbols); } return keys; }
  40247. function _objectSpread(target) { for (var i = 1; i < arguments.length; i++) { var source = arguments[i] != null ? arguments[i] : {}; if (i % 2) { ownKeys(source, true).forEach(function (key) { _babel_runtime_helpers_defineProperty__WEBPACK_IMPORTED_MODULE_0___default()(target, key, source[key]); }); } else if (Object.getOwnPropertyDescriptors) { Object.defineProperties(target, Object.getOwnPropertyDescriptors(source)); } else { ownKeys(source).forEach(function (key) { Object.defineProperty(target, key, Object.getOwnPropertyDescriptor(source, key)); }); } } return target; }
  40248. /* harmony default export */ __webpack_exports__["default"] = (_Property__WEBPACK_IMPORTED_MODULE_1__["default"].extend({
  40249. defaults: _objectSpread({}, _Property__WEBPACK_IMPORTED_MODULE_1__["default"].prototype.defaults, {
  40250. // 'background' is a good example where to make a difference
  40251. // between detached and not
  40252. //
  40253. // - NOT detached (default)
  40254. // background: url(..) no-repeat center ...;
  40255. // - Detached
  40256. // background-image: url();
  40257. // background-repeat: repeat;
  40258. // ...
  40259. detached: 0,
  40260. // Array of sub properties
  40261. properties: [],
  40262. // Separator between properties
  40263. separator: ' '
  40264. }),
  40265. initialize: function initialize() {
  40266. var props = arguments.length > 0 && arguments[0] !== undefined ? arguments[0] : {};
  40267. var opts = arguments.length > 1 && arguments[1] !== undefined ? arguments[1] : {};
  40268. _Property__WEBPACK_IMPORTED_MODULE_1__["default"].callParentInit(_Property__WEBPACK_IMPORTED_MODULE_1__["default"], this, props, opts);
  40269. var properties = this.get('properties') || [];
  40270. var Properties = __webpack_require__(/*! ./Properties */ "./src/style_manager/model/Properties.js").default;
  40271. this.set('properties', new Properties(properties));
  40272. this.listenTo(this, 'change:value', this.updateValues);
  40273. _Property__WEBPACK_IMPORTED_MODULE_1__["default"].callInit(this, props, opts);
  40274. },
  40275. /**
  40276. * Clear the value
  40277. * @return {this}
  40278. */
  40279. clearValue: function clearValue() {
  40280. var opts = arguments.length > 0 && arguments[0] !== undefined ? arguments[0] : {};
  40281. this.get('properties').each(function (property) {
  40282. return property.clearValue();
  40283. });
  40284. return _Property__WEBPACK_IMPORTED_MODULE_1__["default"].prototype.clearValue.apply(this, arguments);
  40285. },
  40286. /**
  40287. * Update property values
  40288. */
  40289. updateValues: function updateValues() {
  40290. var values = this.getFullValue().split(this.getSplitSeparator());
  40291. this.get('properties').each(function (property, i) {
  40292. var len = values.length; // Try to get value from a shorthand:
  40293. // 11px -> 11px 11px 11px 11xp
  40294. // 11px 22px -> 11px 22px 11px 22xp
  40295. var value = values[i] || values[i % len + (len != 1 && len % 2 ? 1 : 0)]; // There some issue with UndoManager
  40296. //property.setValue(value, 0, {fromParent: 1});
  40297. });
  40298. },
  40299. /**
  40300. * Split by sperator but avoid it inside parenthesis
  40301. * @return {RegExp}
  40302. */
  40303. getSplitSeparator: function getSplitSeparator() {
  40304. return new RegExp("".concat(this.get('separator'), "(?![^\\(]*\\))"));
  40305. },
  40306. /**
  40307. * Returns default value
  40308. * @param {Boolean} defaultProps Force to get defaults from properties
  40309. * @return {string}
  40310. */
  40311. getDefaultValue: function getDefaultValue(defaultProps) {
  40312. var value = this.get('defaults');
  40313. if (value && !defaultProps) {
  40314. return value;
  40315. }
  40316. value = '';
  40317. var properties = this.get('properties');
  40318. properties.each(function (prop, index) {
  40319. return value += "".concat(prop.getDefaultValue(), " ");
  40320. });
  40321. return value.trim();
  40322. },
  40323. getFullValue: function getFullValue() {
  40324. if (this.get('detached')) {
  40325. return '';
  40326. }
  40327. return this.get('properties').getFullValue();
  40328. },
  40329. /**
  40330. * Get property at some index
  40331. * @param {Number} index
  40332. * @return {Object}
  40333. */
  40334. getPropertyAt: function getPropertyAt(index) {
  40335. return this.get('properties').at(index);
  40336. }
  40337. }));
  40338. /***/ }),
  40339. /***/ "./src/style_manager/model/PropertyFactory.js":
  40340. /*!****************************************************!*\
  40341. !*** ./src/style_manager/model/PropertyFactory.js ***!
  40342. \****************************************************/
  40343. /*! exports provided: default */
  40344. /***/ (function(module, __webpack_exports__, __webpack_require__) {
  40345. "use strict";
  40346. __webpack_require__.r(__webpack_exports__);
  40347. /* harmony default export */ __webpack_exports__["default"] = (function () {
  40348. return {
  40349. /**
  40350. * Build props object by their name
  40351. * @param {Array<string>|string} props Array of properties name
  40352. * @return {Array<Object>}
  40353. */
  40354. build: function build(props) {
  40355. var objs = [];
  40356. var dftFixedValues = ['initial', 'inherit'];
  40357. if (typeof props === 'string') props = [props];
  40358. for (var i = 0, len = props.length; i < len; i++) {
  40359. var obj = {};
  40360. var prop = props[i];
  40361. obj.property = prop; // Property
  40362. switch (prop) {
  40363. case 'border-radius-c':
  40364. obj.property = 'border-radius';
  40365. break;
  40366. } // Fixed values
  40367. switch (prop) {
  40368. case 'top':
  40369. case 'right':
  40370. case 'bottom':
  40371. case 'left':
  40372. case 'margin-top':
  40373. case 'margin-right':
  40374. case 'margin-bottom':
  40375. case 'margin-left':
  40376. case 'padding-top':
  40377. case 'padding-right':
  40378. case 'padding-bottom':
  40379. case 'padding-left':
  40380. case 'width':
  40381. case 'max-width':
  40382. case 'min-width':
  40383. case 'height':
  40384. case 'max-height':
  40385. case 'min-height':
  40386. case 'flex-basis':
  40387. obj.fixedValues = ['initial', 'inherit', 'auto'];
  40388. break;
  40389. case 'font-size':
  40390. obj.fixedValues = ['medium', 'xx-small', 'x-small', 'small', 'large', 'x-large', 'xx-large', 'smaller', 'larger', 'length', 'initial', 'inherit'];
  40391. break;
  40392. case 'letter-spacing':
  40393. case 'line-height':
  40394. obj.fixedValues = ['normal', 'initial', 'inherit'];
  40395. break;
  40396. } // Type
  40397. switch (prop) {
  40398. case 'float':
  40399. case 'position':
  40400. case 'text-align':
  40401. obj.type = 'radio';
  40402. break;
  40403. case 'display':
  40404. case 'flex-direction':
  40405. case 'flex-wrap':
  40406. case 'justify-content':
  40407. case 'align-items':
  40408. case 'align-content':
  40409. case 'align-self':
  40410. case 'font-family':
  40411. case 'font-weight':
  40412. case 'border-style':
  40413. case 'box-shadow-type':
  40414. case 'background-repeat':
  40415. case 'background-position':
  40416. case 'background-attachment':
  40417. case 'background-size':
  40418. case 'transition-property':
  40419. case 'transition-timing-function':
  40420. case 'cursor':
  40421. case 'overflow':
  40422. case 'overflow-x':
  40423. case 'overflow-y':
  40424. obj.type = 'select';
  40425. break;
  40426. case 'top':
  40427. case 'right':
  40428. case 'bottom':
  40429. case 'left':
  40430. case 'margin-top':
  40431. case 'margin-right':
  40432. case 'margin-bottom':
  40433. case 'margin-left':
  40434. case 'padding-top':
  40435. case 'padding-right':
  40436. case 'padding-bottom':
  40437. case 'padding-left':
  40438. case 'min-height':
  40439. case 'min-width':
  40440. case 'max-height':
  40441. case 'max-width':
  40442. case 'width':
  40443. case 'height':
  40444. case 'font-size':
  40445. case 'letter-spacing':
  40446. case 'line-height':
  40447. case 'text-shadow-h':
  40448. case 'text-shadow-v':
  40449. case 'text-shadow-blur':
  40450. case 'border-radius-c':
  40451. case 'border-top-left-radius':
  40452. case 'border-top-right-radius':
  40453. case 'border-bottom-left-radius':
  40454. case 'border-bottom-right-radius':
  40455. case 'border-width':
  40456. case 'box-shadow-h':
  40457. case 'box-shadow-v':
  40458. case 'box-shadow-blur':
  40459. case 'box-shadow-spread':
  40460. case 'transition-duration':
  40461. case 'perspective':
  40462. case 'transform-rotate-x':
  40463. case 'transform-rotate-y':
  40464. case 'transform-rotate-z':
  40465. case 'transform-scale-x':
  40466. case 'transform-scale-y':
  40467. case 'transform-scale-z':
  40468. case 'order':
  40469. case 'flex-grow':
  40470. case 'flex-shrink':
  40471. case 'flex-basis':
  40472. obj.type = 'integer';
  40473. break;
  40474. case 'margin':
  40475. case 'padding':
  40476. case 'border-radius':
  40477. case 'border':
  40478. case 'transform':
  40479. obj.type = 'composite';
  40480. break;
  40481. case 'color':
  40482. case 'text-shadow-color':
  40483. case 'background-color':
  40484. case 'border-color':
  40485. case 'box-shadow-color':
  40486. obj.type = 'color';
  40487. break;
  40488. case 'text-shadow':
  40489. case 'box-shadow':
  40490. case 'background':
  40491. case 'transition':
  40492. obj.type = 'stack';
  40493. break;
  40494. case 'background-image':
  40495. obj.type = 'file';
  40496. break;
  40497. } // Defaults
  40498. switch (prop) {
  40499. case 'float':
  40500. case 'background-color':
  40501. case 'text-shadow':
  40502. obj.defaults = 'none';
  40503. break;
  40504. case 'display':
  40505. obj.defaults = 'block';
  40506. break;
  40507. case 'flex-direction':
  40508. obj.defaults = 'row';
  40509. break;
  40510. case 'flex-wrap':
  40511. obj.defaults = 'nowrap';
  40512. break;
  40513. case 'justify-content':
  40514. obj.defaults = 'flex-start';
  40515. break;
  40516. case 'align-items':
  40517. obj.defaults = 'stretch';
  40518. break;
  40519. case 'align-content':
  40520. obj.defaults = 'stretch';
  40521. break;
  40522. case 'align-self':
  40523. obj.defaults = 'auto';
  40524. break;
  40525. case 'position':
  40526. obj.defaults = 'static';
  40527. break;
  40528. case 'margin-top':
  40529. case 'margin-right':
  40530. case 'margin-bottom':
  40531. case 'margin-left':
  40532. case 'padding-top':
  40533. case 'padding-right':
  40534. case 'padding-bottom':
  40535. case 'padding-left':
  40536. case 'text-shadow-h':
  40537. case 'text-shadow-v':
  40538. case 'text-shadow-blur':
  40539. case 'border-radius-c':
  40540. case 'box-shadow-h':
  40541. case 'box-shadow-v':
  40542. case 'box-shadow-spread':
  40543. case 'perspective':
  40544. case 'transform-rotate-x':
  40545. case 'transform-rotate-y':
  40546. case 'transform-rotate-z':
  40547. case 'order':
  40548. case 'flex-grow':
  40549. obj.defaults = 0;
  40550. break;
  40551. case 'border-top-left-radius':
  40552. case 'border-top-right-radius':
  40553. case 'border-bottom-left-radius':
  40554. case 'border-bottom-right-radius':
  40555. obj.defaults = '0px';
  40556. break;
  40557. case 'transform-scale-x':
  40558. case 'transform-scale-y':
  40559. case 'transform-scale-z':
  40560. case 'flex-shrink':
  40561. obj.defaults = 1;
  40562. break;
  40563. case 'box-shadow-blur':
  40564. obj.defaults = '5px';
  40565. break;
  40566. case 'top':
  40567. case 'right':
  40568. case 'bottom':
  40569. case 'left':
  40570. case 'min-height':
  40571. case 'min-width':
  40572. case 'max-height':
  40573. case 'max-width':
  40574. case 'width':
  40575. case 'height':
  40576. case 'background-size':
  40577. case 'cursor':
  40578. case 'flex-basis':
  40579. obj.defaults = 'auto';
  40580. break;
  40581. case 'font-family':
  40582. obj.defaults = 'Arial, Helvetica, sans-serif';
  40583. break;
  40584. case 'font-size':
  40585. case 'border-width':
  40586. obj.defaults = 'medium';
  40587. break;
  40588. case 'font-weight':
  40589. obj.defaults = '400';
  40590. break;
  40591. case 'letter-spacing':
  40592. case 'line-height':
  40593. obj.defaults = 'normal';
  40594. break;
  40595. case 'color':
  40596. case 'text-shadow-color':
  40597. case 'border-color':
  40598. case 'box-shadow-color':
  40599. obj.defaults = 'black';
  40600. break;
  40601. case 'text-align':
  40602. obj.defaults = 'left';
  40603. break;
  40604. case 'border-style':
  40605. obj.defaults = 'solid';
  40606. break;
  40607. case 'box-shadow-type':
  40608. obj.defaults = '';
  40609. break;
  40610. case 'background-repeat':
  40611. obj.defaults = 'repeat';
  40612. break;
  40613. case 'background-position':
  40614. obj.defaults = 'left top';
  40615. break;
  40616. case 'background-attachment':
  40617. obj.defaults = 'scroll';
  40618. break;
  40619. case 'transition-property':
  40620. obj.defaults = 'width';
  40621. break;
  40622. case 'transition-duration':
  40623. obj.defaults = '2';
  40624. break;
  40625. case 'transition-timing-function':
  40626. obj.defaults = 'ease';
  40627. break;
  40628. case 'overflow':
  40629. case 'overflow-x':
  40630. case 'overflow-y':
  40631. obj.defaults = 'visible';
  40632. break;
  40633. }
  40634. /*
  40635. * Add styleable dependency on other properties. Allows properties to be
  40636. * dynamically hidden or shown based on values of other properties.
  40637. *
  40638. * Property will be styleable if all of the properties (keys) in the
  40639. * requires object have any of the values specified in the array.
  40640. */
  40641. switch (prop) {
  40642. case 'flex-direction':
  40643. case 'flex-wrap':
  40644. case 'justify-content':
  40645. case 'align-items':
  40646. case 'align-content':
  40647. obj.requires = {
  40648. display: ['flex']
  40649. };
  40650. break;
  40651. case 'order':
  40652. case 'flex-basis':
  40653. case 'flex-grow':
  40654. case 'flex-shrink':
  40655. case 'align-self':
  40656. obj.requiresParent = {
  40657. display: ['flex']
  40658. };
  40659. break;
  40660. } // Units
  40661. switch (prop) {
  40662. case 'top':
  40663. case 'bottom':
  40664. case 'margin-top':
  40665. case 'margin-bottom':
  40666. case 'padding-top':
  40667. case 'padding-bottom':
  40668. case 'min-height':
  40669. case 'max-height':
  40670. case 'height':
  40671. obj.units = ['px', '%', 'vh'];
  40672. break;
  40673. case 'right':
  40674. case 'left':
  40675. case 'margin-right':
  40676. case 'margin-left':
  40677. case 'padding-right':
  40678. case 'padding-left':
  40679. case 'min-width':
  40680. case 'max-width':
  40681. case 'width':
  40682. obj.units = ['px', '%', 'vw'];
  40683. break;
  40684. case 'flex-basis':
  40685. obj.units = ['px', '%', 'vw', 'vh'];
  40686. break;
  40687. case 'text-shadow-v':
  40688. case 'text-shadow-h':
  40689. case 'text-shadow-blur':
  40690. case 'border-radius-c':
  40691. case 'border-top-left-radius':
  40692. case 'border-top-right-radius':
  40693. case 'border-bottom-left-radius':
  40694. case 'border-bottom-right-radius':
  40695. case 'box-shadow-h':
  40696. case 'box-shadow-v':
  40697. obj.units = ['px', '%'];
  40698. break;
  40699. case 'font-size':
  40700. case 'letter-spacing':
  40701. case 'line-height':
  40702. obj.units = ['px', 'em', 'rem', '%'];
  40703. break;
  40704. case 'border-width':
  40705. obj.units = ['px', 'em'];
  40706. break;
  40707. case 'box-shadow-blur':
  40708. case 'box-shadow-spread':
  40709. case 'perspective':
  40710. obj.units = ['px'];
  40711. break;
  40712. case 'transition-duration':
  40713. obj.units = ['s'];
  40714. break;
  40715. case 'transform-rotate-x':
  40716. case 'transform-rotate-y':
  40717. case 'transform-rotate-z':
  40718. obj.units = ['deg'];
  40719. break;
  40720. } // Min/Max
  40721. switch (prop) {
  40722. case 'padding-top':
  40723. case 'padding-right':
  40724. case 'padding-bottom':
  40725. case 'padding-left':
  40726. case 'min-height':
  40727. case 'min-width':
  40728. case 'max-height':
  40729. case 'max-width':
  40730. case 'width':
  40731. case 'height':
  40732. case 'font-size':
  40733. case 'text-shadow-blur':
  40734. case 'border-radius-c':
  40735. case 'border-top-left-radius':
  40736. case 'border-top-right-radius':
  40737. case 'border-bottom-left-radius':
  40738. case 'border-bottom-right-radius':
  40739. case 'border-width':
  40740. case 'box-shadow-blur':
  40741. case 'transition-duration':
  40742. case 'perspective':
  40743. case 'flex-basis':
  40744. obj.min = 0;
  40745. break;
  40746. } // Preview
  40747. switch (prop) {
  40748. case 'text-shadow':
  40749. case 'box-shadow':
  40750. case 'background':
  40751. obj.preview = true;
  40752. break;
  40753. } // Detached
  40754. switch (prop) {
  40755. case 'background':
  40756. obj.detached = true;
  40757. break;
  40758. } // Functions
  40759. switch (prop) {
  40760. case 'transform-rotate-x':
  40761. obj.functionName = 'rotateX';
  40762. break;
  40763. case 'transform-rotate-y':
  40764. obj.functionName = 'rotateY';
  40765. break;
  40766. case 'transform-rotate-z':
  40767. obj.functionName = 'rotateZ';
  40768. break;
  40769. case 'transform-scale-x':
  40770. obj.functionName = 'scaleX';
  40771. break;
  40772. case 'transform-scale-y':
  40773. obj.functionName = 'scaleY';
  40774. break;
  40775. case 'transform-scale-z':
  40776. obj.functionName = 'scaleZ';
  40777. break;
  40778. case 'background-image':
  40779. obj.functionName = 'url';
  40780. break;
  40781. } // Options
  40782. switch (prop) {
  40783. case 'float':
  40784. obj.list = [{
  40785. value: 'none'
  40786. }, {
  40787. value: 'left'
  40788. }, {
  40789. value: 'right'
  40790. }];
  40791. break;
  40792. case 'display':
  40793. obj.list = [{
  40794. value: 'block'
  40795. }, {
  40796. value: 'inline'
  40797. }, {
  40798. value: 'inline-block'
  40799. }, {
  40800. value: 'flex'
  40801. }, {
  40802. value: 'none'
  40803. }];
  40804. break;
  40805. case 'flex-direction':
  40806. obj.list = [{
  40807. value: 'row'
  40808. }, {
  40809. value: 'row-reverse'
  40810. }, {
  40811. value: 'column'
  40812. }, {
  40813. value: 'column-reverse'
  40814. }];
  40815. break;
  40816. case 'flex-wrap':
  40817. obj.list = [{
  40818. value: 'nowrap'
  40819. }, {
  40820. value: 'wrap'
  40821. }, {
  40822. value: 'wrap-reverse'
  40823. }];
  40824. break;
  40825. case 'justify-content':
  40826. obj.list = [{
  40827. value: 'flex-start'
  40828. }, {
  40829. value: 'flex-end'
  40830. }, {
  40831. value: 'center'
  40832. }, {
  40833. value: 'space-between'
  40834. }, {
  40835. value: 'space-around'
  40836. }, {
  40837. value: 'space-evenly'
  40838. }];
  40839. break;
  40840. case 'align-items':
  40841. obj.list = [{
  40842. value: 'flex-start'
  40843. }, {
  40844. value: 'flex-end'
  40845. }, {
  40846. value: 'center'
  40847. }, {
  40848. value: 'baseline'
  40849. }, {
  40850. value: 'stretch'
  40851. }];
  40852. break;
  40853. case 'align-content':
  40854. obj.list = [{
  40855. value: 'flex-start'
  40856. }, {
  40857. value: 'flex-end'
  40858. }, {
  40859. value: 'center'
  40860. }, {
  40861. value: 'space-between'
  40862. }, {
  40863. value: 'space-around'
  40864. }, {
  40865. value: 'stretch'
  40866. }];
  40867. break;
  40868. case 'align-self':
  40869. obj.list = [{
  40870. value: 'auto'
  40871. }, {
  40872. value: 'flex-start'
  40873. }, {
  40874. value: 'flex-end'
  40875. }, {
  40876. value: 'center'
  40877. }, {
  40878. value: 'baseline'
  40879. }, {
  40880. value: 'stretch'
  40881. }];
  40882. break;
  40883. case 'position':
  40884. obj.list = [{
  40885. value: 'static'
  40886. }, {
  40887. value: 'relative'
  40888. }, {
  40889. value: 'absolute'
  40890. }, {
  40891. value: 'fixed'
  40892. }];
  40893. break;
  40894. case 'font-family':
  40895. var ss = ', sans-serif';
  40896. var fonts = ['Arial, Helvetica' + ss, 'Arial Black, Gadget' + ss, 'Brush Script MT' + ss, 'Comic Sans MS, cursive' + ss, 'Courier New, Courier, monospace', 'Georgia, serif', 'Helvetica, serif', 'Impact, Charcoal' + ss, 'Lucida Sans Unicode, Lucida Grande' + ss, 'Tahoma, Geneva' + ss, 'Times New Roman, Times, serif', 'Trebuchet MS, Helvetica' + ss, 'Verdana, Geneva' + ss];
  40897. obj.list = [];
  40898. for (var j = 0, l = fonts.length; j < l; j++) {
  40899. var font = {};
  40900. font.value = fonts[j];
  40901. font.name = fonts[j].split(',')[0];
  40902. obj.list.push(font);
  40903. }
  40904. break;
  40905. case 'font-weight':
  40906. obj.list = [{
  40907. value: '100',
  40908. name: 'Thin'
  40909. }, {
  40910. value: '200',
  40911. name: 'Extra-Light'
  40912. }, {
  40913. value: '300',
  40914. name: 'Light'
  40915. }, {
  40916. value: '400',
  40917. name: 'Normal'
  40918. }, {
  40919. value: '500',
  40920. name: 'Medium'
  40921. }, {
  40922. value: '600',
  40923. name: 'Semi-Bold'
  40924. }, {
  40925. value: '700',
  40926. name: 'Bold'
  40927. }, {
  40928. value: '800',
  40929. name: 'Extra-Bold'
  40930. }, {
  40931. value: '900',
  40932. name: 'Ultra-Bold'
  40933. }];
  40934. break;
  40935. case 'text-align':
  40936. obj.list = [{
  40937. value: 'left'
  40938. }, {
  40939. value: 'center'
  40940. }, {
  40941. value: 'right'
  40942. }, {
  40943. value: 'justify'
  40944. }];
  40945. break;
  40946. case 'border-style':
  40947. obj.list = [{
  40948. value: 'none'
  40949. }, {
  40950. value: 'solid'
  40951. }, {
  40952. value: 'dotted'
  40953. }, {
  40954. value: 'dashed'
  40955. }, {
  40956. value: 'double'
  40957. }, {
  40958. value: 'groove'
  40959. }, {
  40960. value: 'ridge'
  40961. }, {
  40962. value: 'inset'
  40963. }, {
  40964. value: 'outset'
  40965. }];
  40966. break;
  40967. case 'box-shadow-type':
  40968. obj.list = [{
  40969. value: '',
  40970. name: 'Outside'
  40971. }, {
  40972. value: 'inset',
  40973. name: 'Inside'
  40974. }];
  40975. break;
  40976. case 'background-repeat':
  40977. obj.list = [{
  40978. value: 'repeat'
  40979. }, {
  40980. value: 'repeat-x'
  40981. }, {
  40982. value: 'repeat-y'
  40983. }, {
  40984. value: 'no-repeat'
  40985. }];
  40986. break;
  40987. case 'background-position':
  40988. obj.list = [{
  40989. value: 'left top'
  40990. }, {
  40991. value: 'left center'
  40992. }, {
  40993. value: 'left bottom'
  40994. }, {
  40995. value: 'right top'
  40996. }, {
  40997. value: 'right center'
  40998. }, {
  40999. value: 'right bottom'
  41000. }, {
  41001. value: 'center top'
  41002. }, {
  41003. value: 'center center'
  41004. }, {
  41005. value: 'center bottom'
  41006. }];
  41007. break;
  41008. case 'background-attachment':
  41009. obj.list = [{
  41010. value: 'scroll'
  41011. }, {
  41012. value: 'fixed'
  41013. }, {
  41014. value: 'local'
  41015. }];
  41016. break;
  41017. case 'background-size':
  41018. obj.list = [{
  41019. value: 'auto'
  41020. }, {
  41021. value: 'cover'
  41022. }, {
  41023. value: 'contain'
  41024. }];
  41025. break;
  41026. case 'transition-property':
  41027. obj.list = [{
  41028. value: 'all'
  41029. }, {
  41030. value: 'width'
  41031. }, {
  41032. value: 'height'
  41033. }, {
  41034. value: 'background-color'
  41035. }, {
  41036. value: 'transform'
  41037. }, {
  41038. value: 'box-shadow'
  41039. }, {
  41040. value: 'opacity'
  41041. }];
  41042. break;
  41043. case 'transition-timing-function':
  41044. obj.list = [{
  41045. value: 'linear'
  41046. }, {
  41047. value: 'ease'
  41048. }, {
  41049. value: 'ease-in'
  41050. }, {
  41051. value: 'ease-out'
  41052. }, {
  41053. value: 'ease-in-out'
  41054. }];
  41055. break;
  41056. case 'cursor':
  41057. obj.list = [{
  41058. value: 'auto'
  41059. }, {
  41060. value: 'pointer'
  41061. }, {
  41062. value: 'copy'
  41063. }, {
  41064. value: 'crosshair'
  41065. }, {
  41066. value: 'grab'
  41067. }, {
  41068. value: 'grabbing'
  41069. }, {
  41070. value: 'help'
  41071. }, {
  41072. value: 'move'
  41073. }, {
  41074. value: 'text'
  41075. }];
  41076. break;
  41077. case 'overflow':
  41078. case 'overflow-x':
  41079. case 'overflow-y':
  41080. obj.list = [{
  41081. value: 'visible'
  41082. }, {
  41083. value: 'hidden'
  41084. }, {
  41085. value: 'scroll'
  41086. }, {
  41087. value: 'auto'
  41088. }];
  41089. break;
  41090. } // Properties
  41091. switch (prop) {
  41092. case 'margin':
  41093. obj.properties = this.build(['margin-top', 'margin-right', 'margin-bottom', 'margin-left']);
  41094. break;
  41095. case 'padding':
  41096. obj.properties = this.build(['padding-top', 'padding-right', 'padding-bottom', 'padding-left']);
  41097. break;
  41098. case 'text-shadow':
  41099. obj.properties = this.build(['text-shadow-h', 'text-shadow-v', 'text-shadow-blur', 'text-shadow-color']);
  41100. break;
  41101. case 'border':
  41102. obj.properties = this.build(['border-width', 'border-style', 'border-color']);
  41103. break;
  41104. case 'border-radius':
  41105. obj.properties = this.build(['border-top-left-radius', 'border-top-right-radius', 'border-bottom-right-radius', 'border-bottom-left-radius']);
  41106. break;
  41107. case 'box-shadow':
  41108. obj.properties = this.build(['box-shadow-h', 'box-shadow-v', 'box-shadow-blur', 'box-shadow-spread', 'box-shadow-color', 'box-shadow-type']);
  41109. break;
  41110. case 'background':
  41111. obj.properties = this.build(['background-image', 'background-repeat', 'background-position', 'background-attachment', 'background-size']);
  41112. break;
  41113. case 'transition':
  41114. obj.properties = this.build(['transition-property', 'transition-duration', 'transition-timing-function']);
  41115. break;
  41116. case 'transform':
  41117. obj.properties = this.build(['transform-rotate-x', 'transform-rotate-y', 'transform-rotate-z', 'transform-scale-x', 'transform-scale-y', 'transform-scale-z']);
  41118. break;
  41119. }
  41120. objs.push(obj);
  41121. }
  41122. return objs;
  41123. }
  41124. };
  41125. });
  41126. /***/ }),
  41127. /***/ "./src/style_manager/model/PropertyInteger.js":
  41128. /*!****************************************************!*\
  41129. !*** ./src/style_manager/model/PropertyInteger.js ***!
  41130. \****************************************************/
  41131. /*! exports provided: default */
  41132. /***/ (function(module, __webpack_exports__, __webpack_require__) {
  41133. "use strict";
  41134. __webpack_require__.r(__webpack_exports__);
  41135. /* harmony import */ var _babel_runtime_helpers_defineProperty__WEBPACK_IMPORTED_MODULE_0__ = __webpack_require__(/*! @babel/runtime/helpers/defineProperty */ "./node_modules/@babel/runtime/helpers/defineProperty.js");
  41136. /* harmony import */ var _babel_runtime_helpers_defineProperty__WEBPACK_IMPORTED_MODULE_0___default = /*#__PURE__*/__webpack_require__.n(_babel_runtime_helpers_defineProperty__WEBPACK_IMPORTED_MODULE_0__);
  41137. /* harmony import */ var underscore__WEBPACK_IMPORTED_MODULE_1__ = __webpack_require__(/*! underscore */ "./node_modules/underscore/underscore.js");
  41138. /* harmony import */ var underscore__WEBPACK_IMPORTED_MODULE_1___default = /*#__PURE__*/__webpack_require__.n(underscore__WEBPACK_IMPORTED_MODULE_1__);
  41139. /* harmony import */ var _Property__WEBPACK_IMPORTED_MODULE_2__ = __webpack_require__(/*! ./Property */ "./src/style_manager/model/Property.js");
  41140. /* harmony import */ var domain_abstract_ui_InputNumber__WEBPACK_IMPORTED_MODULE_3__ = __webpack_require__(/*! domain_abstract/ui/InputNumber */ "./src/domain_abstract/ui/InputNumber.js");
  41141. function ownKeys(object, enumerableOnly) { var keys = Object.keys(object); if (Object.getOwnPropertySymbols) { var symbols = Object.getOwnPropertySymbols(object); if (enumerableOnly) symbols = symbols.filter(function (sym) { return Object.getOwnPropertyDescriptor(object, sym).enumerable; }); keys.push.apply(keys, symbols); } return keys; }
  41142. function _objectSpread(target) { for (var i = 1; i < arguments.length; i++) { var source = arguments[i] != null ? arguments[i] : {}; if (i % 2) { ownKeys(source, true).forEach(function (key) { _babel_runtime_helpers_defineProperty__WEBPACK_IMPORTED_MODULE_0___default()(target, key, source[key]); }); } else if (Object.getOwnPropertyDescriptors) { Object.defineProperties(target, Object.getOwnPropertyDescriptors(source)); } else { ownKeys(source).forEach(function (key) { Object.defineProperty(target, key, Object.getOwnPropertyDescriptor(source, key)); }); } } return target; }
  41143. /* harmony default export */ __webpack_exports__["default"] = (_Property__WEBPACK_IMPORTED_MODULE_2__["default"].extend({
  41144. defaults: _objectSpread({}, _Property__WEBPACK_IMPORTED_MODULE_2__["default"].prototype.defaults, {
  41145. // Array of units, eg. ['px', '%']
  41146. units: [],
  41147. // Selected unit, eg. 'px'
  41148. unit: '',
  41149. // Integer value steps
  41150. step: 1,
  41151. // Minimum value
  41152. min: '',
  41153. // Maximum value
  41154. max: ''
  41155. }),
  41156. initialize: function initialize() {
  41157. var props = arguments.length > 0 && arguments[0] !== undefined ? arguments[0] : {};
  41158. var opts = arguments.length > 1 && arguments[1] !== undefined ? arguments[1] : {};
  41159. _Property__WEBPACK_IMPORTED_MODULE_2__["default"].callParentInit(_Property__WEBPACK_IMPORTED_MODULE_2__["default"], this, props, opts);
  41160. var unit = this.get('unit');
  41161. var units = this.get('units');
  41162. this.input = new domain_abstract_ui_InputNumber__WEBPACK_IMPORTED_MODULE_3__["default"]({
  41163. model: this
  41164. });
  41165. if (units.length && !unit) {
  41166. this.set('unit', units[0]);
  41167. }
  41168. _Property__WEBPACK_IMPORTED_MODULE_2__["default"].callInit(this, props, opts);
  41169. },
  41170. clearValue: function clearValue() {
  41171. var opts = arguments.length > 0 && arguments[0] !== undefined ? arguments[0] : {};
  41172. this.set({
  41173. value: undefined,
  41174. unit: undefined
  41175. }, opts);
  41176. return this;
  41177. },
  41178. parseValue: function parseValue(val) {
  41179. var parsed = _Property__WEBPACK_IMPORTED_MODULE_2__["default"].prototype.parseValue.apply(this, arguments);
  41180. var _this$input$validateI = this.input.validateInputValue(parsed.value, {
  41181. deepCheck: 1
  41182. }),
  41183. value = _this$input$validateI.value,
  41184. unit = _this$input$validateI.unit;
  41185. parsed.value = value;
  41186. parsed.unit = unit;
  41187. return parsed;
  41188. },
  41189. getFullValue: function getFullValue() {
  41190. var value = this.get('value');
  41191. var unit = this.get('unit');
  41192. value = !Object(underscore__WEBPACK_IMPORTED_MODULE_1__["isUndefined"])(value) ? value : '';
  41193. unit = !Object(underscore__WEBPACK_IMPORTED_MODULE_1__["isUndefined"])(unit) && value ? unit : '';
  41194. value = "".concat(value).concat(unit);
  41195. return _Property__WEBPACK_IMPORTED_MODULE_2__["default"].prototype.getFullValue.apply(this, [value]);
  41196. }
  41197. }));
  41198. /***/ }),
  41199. /***/ "./src/style_manager/model/PropertyRadio.js":
  41200. /*!**************************************************!*\
  41201. !*** ./src/style_manager/model/PropertyRadio.js ***!
  41202. \**************************************************/
  41203. /*! exports provided: default */
  41204. /***/ (function(module, __webpack_exports__, __webpack_require__) {
  41205. "use strict";
  41206. __webpack_require__.r(__webpack_exports__);
  41207. /* harmony import */ var _babel_runtime_helpers_toConsumableArray__WEBPACK_IMPORTED_MODULE_0__ = __webpack_require__(/*! @babel/runtime/helpers/toConsumableArray */ "./node_modules/@babel/runtime/helpers/toConsumableArray.js");
  41208. /* harmony import */ var _babel_runtime_helpers_toConsumableArray__WEBPACK_IMPORTED_MODULE_0___default = /*#__PURE__*/__webpack_require__.n(_babel_runtime_helpers_toConsumableArray__WEBPACK_IMPORTED_MODULE_0__);
  41209. /* harmony import */ var _babel_runtime_helpers_defineProperty__WEBPACK_IMPORTED_MODULE_1__ = __webpack_require__(/*! @babel/runtime/helpers/defineProperty */ "./node_modules/@babel/runtime/helpers/defineProperty.js");
  41210. /* harmony import */ var _babel_runtime_helpers_defineProperty__WEBPACK_IMPORTED_MODULE_1___default = /*#__PURE__*/__webpack_require__.n(_babel_runtime_helpers_defineProperty__WEBPACK_IMPORTED_MODULE_1__);
  41211. /* harmony import */ var _Property__WEBPACK_IMPORTED_MODULE_2__ = __webpack_require__(/*! ./Property */ "./src/style_manager/model/Property.js");
  41212. function ownKeys(object, enumerableOnly) { var keys = Object.keys(object); if (Object.getOwnPropertySymbols) { var symbols = Object.getOwnPropertySymbols(object); if (enumerableOnly) symbols = symbols.filter(function (sym) { return Object.getOwnPropertyDescriptor(object, sym).enumerable; }); keys.push.apply(keys, symbols); } return keys; }
  41213. function _objectSpread(target) { for (var i = 1; i < arguments.length; i++) { var source = arguments[i] != null ? arguments[i] : {}; if (i % 2) { ownKeys(source, true).forEach(function (key) { _babel_runtime_helpers_defineProperty__WEBPACK_IMPORTED_MODULE_1___default()(target, key, source[key]); }); } else if (Object.getOwnPropertyDescriptors) { Object.defineProperties(target, Object.getOwnPropertyDescriptors(source)); } else { ownKeys(source).forEach(function (key) { Object.defineProperty(target, key, Object.getOwnPropertyDescriptor(source, key)); }); } } return target; }
  41214. /* harmony default export */ __webpack_exports__["default"] = (_Property__WEBPACK_IMPORTED_MODULE_2__["default"].extend({
  41215. defaults: function defaults() {
  41216. return _objectSpread({}, _Property__WEBPACK_IMPORTED_MODULE_2__["default"].prototype.defaults, {
  41217. // Array of options, eg. [{name: 'Label ', value: '100'}]
  41218. options: [],
  41219. full: 1
  41220. });
  41221. },
  41222. initialize: function initialize() {
  41223. for (var _len = arguments.length, args = new Array(_len), _key = 0; _key < _len; _key++) {
  41224. args[_key] = arguments[_key];
  41225. }
  41226. _Property__WEBPACK_IMPORTED_MODULE_2__["default"].prototype.initialize.apply(this, args);
  41227. this.listenTo(this, 'change:options', this.onOptionChange);
  41228. },
  41229. onOptionChange: function onOptionChange() {
  41230. this.set('list', this.get('options'));
  41231. },
  41232. getOptions: function getOptions() {
  41233. var _this$attributes = this.attributes,
  41234. options = _this$attributes.options,
  41235. list = _this$attributes.list;
  41236. return options && options.length ? options : list;
  41237. },
  41238. setOptions: function setOptions() {
  41239. var opts = arguments.length > 0 && arguments[0] !== undefined ? arguments[0] : [];
  41240. this.set('options', opts);
  41241. return this;
  41242. },
  41243. addOption: function addOption(opt) {
  41244. if (opt) {
  41245. var opts = this.getOptions();
  41246. this.setOptions([].concat(_babel_runtime_helpers_toConsumableArray__WEBPACK_IMPORTED_MODULE_0___default()(opts), [opt]));
  41247. }
  41248. return this;
  41249. }
  41250. }));
  41251. /***/ }),
  41252. /***/ "./src/style_manager/model/PropertySelect.js":
  41253. /*!***************************************************!*\
  41254. !*** ./src/style_manager/model/PropertySelect.js ***!
  41255. \***************************************************/
  41256. /*! exports provided: default */
  41257. /***/ (function(module, __webpack_exports__, __webpack_require__) {
  41258. "use strict";
  41259. __webpack_require__.r(__webpack_exports__);
  41260. /* harmony import */ var _babel_runtime_helpers_defineProperty__WEBPACK_IMPORTED_MODULE_0__ = __webpack_require__(/*! @babel/runtime/helpers/defineProperty */ "./node_modules/@babel/runtime/helpers/defineProperty.js");
  41261. /* harmony import */ var _babel_runtime_helpers_defineProperty__WEBPACK_IMPORTED_MODULE_0___default = /*#__PURE__*/__webpack_require__.n(_babel_runtime_helpers_defineProperty__WEBPACK_IMPORTED_MODULE_0__);
  41262. /* harmony import */ var _PropertyRadio__WEBPACK_IMPORTED_MODULE_1__ = __webpack_require__(/*! ./PropertyRadio */ "./src/style_manager/model/PropertyRadio.js");
  41263. function ownKeys(object, enumerableOnly) { var keys = Object.keys(object); if (Object.getOwnPropertySymbols) { var symbols = Object.getOwnPropertySymbols(object); if (enumerableOnly) symbols = symbols.filter(function (sym) { return Object.getOwnPropertyDescriptor(object, sym).enumerable; }); keys.push.apply(keys, symbols); } return keys; }
  41264. function _objectSpread(target) { for (var i = 1; i < arguments.length; i++) { var source = arguments[i] != null ? arguments[i] : {}; if (i % 2) { ownKeys(source, true).forEach(function (key) { _babel_runtime_helpers_defineProperty__WEBPACK_IMPORTED_MODULE_0___default()(target, key, source[key]); }); } else if (Object.getOwnPropertyDescriptors) { Object.defineProperties(target, Object.getOwnPropertyDescriptors(source)); } else { ownKeys(source).forEach(function (key) { Object.defineProperty(target, key, Object.getOwnPropertyDescriptor(source, key)); }); } } return target; }
  41265. /* harmony default export */ __webpack_exports__["default"] = (_PropertyRadio__WEBPACK_IMPORTED_MODULE_1__["default"].extend({
  41266. defaults: function defaults() {
  41267. return _objectSpread({}, _PropertyRadio__WEBPACK_IMPORTED_MODULE_1__["default"].prototype.defaults(), {
  41268. full: 0
  41269. });
  41270. }
  41271. }));
  41272. /***/ }),
  41273. /***/ "./src/style_manager/model/PropertySlider.js":
  41274. /*!***************************************************!*\
  41275. !*** ./src/style_manager/model/PropertySlider.js ***!
  41276. \***************************************************/
  41277. /*! exports provided: default */
  41278. /***/ (function(module, __webpack_exports__, __webpack_require__) {
  41279. "use strict";
  41280. __webpack_require__.r(__webpack_exports__);
  41281. /* harmony import */ var _babel_runtime_helpers_defineProperty__WEBPACK_IMPORTED_MODULE_0__ = __webpack_require__(/*! @babel/runtime/helpers/defineProperty */ "./node_modules/@babel/runtime/helpers/defineProperty.js");
  41282. /* harmony import */ var _babel_runtime_helpers_defineProperty__WEBPACK_IMPORTED_MODULE_0___default = /*#__PURE__*/__webpack_require__.n(_babel_runtime_helpers_defineProperty__WEBPACK_IMPORTED_MODULE_0__);
  41283. /* harmony import */ var _PropertyInteger__WEBPACK_IMPORTED_MODULE_1__ = __webpack_require__(/*! ./PropertyInteger */ "./src/style_manager/model/PropertyInteger.js");
  41284. function ownKeys(object, enumerableOnly) { var keys = Object.keys(object); if (Object.getOwnPropertySymbols) { var symbols = Object.getOwnPropertySymbols(object); if (enumerableOnly) symbols = symbols.filter(function (sym) { return Object.getOwnPropertyDescriptor(object, sym).enumerable; }); keys.push.apply(keys, symbols); } return keys; }
  41285. function _objectSpread(target) { for (var i = 1; i < arguments.length; i++) { var source = arguments[i] != null ? arguments[i] : {}; if (i % 2) { ownKeys(source, true).forEach(function (key) { _babel_runtime_helpers_defineProperty__WEBPACK_IMPORTED_MODULE_0___default()(target, key, source[key]); }); } else if (Object.getOwnPropertyDescriptors) { Object.defineProperties(target, Object.getOwnPropertyDescriptors(source)); } else { ownKeys(source).forEach(function (key) { Object.defineProperty(target, key, Object.getOwnPropertyDescriptor(source, key)); }); } } return target; }
  41286. /* harmony default export */ __webpack_exports__["default"] = (_PropertyInteger__WEBPACK_IMPORTED_MODULE_1__["default"].extend({
  41287. defaults: _objectSpread({}, _PropertyInteger__WEBPACK_IMPORTED_MODULE_1__["default"].prototype.defaults, {
  41288. showInput: 1
  41289. })
  41290. }));
  41291. /***/ }),
  41292. /***/ "./src/style_manager/model/PropertyStack.js":
  41293. /*!**************************************************!*\
  41294. !*** ./src/style_manager/model/PropertyStack.js ***!
  41295. \**************************************************/
  41296. /*! exports provided: default */
  41297. /***/ (function(module, __webpack_exports__, __webpack_require__) {
  41298. "use strict";
  41299. __webpack_require__.r(__webpack_exports__);
  41300. /* harmony import */ var _babel_runtime_helpers_defineProperty__WEBPACK_IMPORTED_MODULE_0__ = __webpack_require__(/*! @babel/runtime/helpers/defineProperty */ "./node_modules/@babel/runtime/helpers/defineProperty.js");
  41301. /* harmony import */ var _babel_runtime_helpers_defineProperty__WEBPACK_IMPORTED_MODULE_0___default = /*#__PURE__*/__webpack_require__.n(_babel_runtime_helpers_defineProperty__WEBPACK_IMPORTED_MODULE_0__);
  41302. /* harmony import */ var underscore__WEBPACK_IMPORTED_MODULE_1__ = __webpack_require__(/*! underscore */ "./node_modules/underscore/underscore.js");
  41303. /* harmony import */ var underscore__WEBPACK_IMPORTED_MODULE_1___default = /*#__PURE__*/__webpack_require__.n(underscore__WEBPACK_IMPORTED_MODULE_1__);
  41304. /* harmony import */ var _PropertyComposite__WEBPACK_IMPORTED_MODULE_2__ = __webpack_require__(/*! ./PropertyComposite */ "./src/style_manager/model/PropertyComposite.js");
  41305. /* harmony import */ var _Layers__WEBPACK_IMPORTED_MODULE_3__ = __webpack_require__(/*! ./Layers */ "./src/style_manager/model/Layers.js");
  41306. function ownKeys(object, enumerableOnly) { var keys = Object.keys(object); if (Object.getOwnPropertySymbols) { var symbols = Object.getOwnPropertySymbols(object); if (enumerableOnly) symbols = symbols.filter(function (sym) { return Object.getOwnPropertyDescriptor(object, sym).enumerable; }); keys.push.apply(keys, symbols); } return keys; }
  41307. function _objectSpread(target) { for (var i = 1; i < arguments.length; i++) { var source = arguments[i] != null ? arguments[i] : {}; if (i % 2) { ownKeys(source, true).forEach(function (key) { _babel_runtime_helpers_defineProperty__WEBPACK_IMPORTED_MODULE_0___default()(target, key, source[key]); }); } else if (Object.getOwnPropertyDescriptors) { Object.defineProperties(target, Object.getOwnPropertyDescriptors(source)); } else { ownKeys(source).forEach(function (key) { Object.defineProperty(target, key, Object.getOwnPropertyDescriptor(source, key)); }); } } return target; }
  41308. /* harmony default export */ __webpack_exports__["default"] = (_PropertyComposite__WEBPACK_IMPORTED_MODULE_2__["default"].extend({
  41309. defaults: _objectSpread({}, _PropertyComposite__WEBPACK_IMPORTED_MODULE_2__["default"].prototype.defaults, {
  41310. // Array of layers (which contain properties)
  41311. layers: [],
  41312. // The separator used to join layer values
  41313. layerSeparator: ', ',
  41314. // Prepend new layers in the list
  41315. prepend: 0,
  41316. // Layer preview
  41317. preview: 0
  41318. }),
  41319. initialize: function initialize() {
  41320. var props = arguments.length > 0 && arguments[0] !== undefined ? arguments[0] : {};
  41321. var opts = arguments.length > 1 && arguments[1] !== undefined ? arguments[1] : {};
  41322. _PropertyComposite__WEBPACK_IMPORTED_MODULE_2__["default"].callParentInit(_PropertyComposite__WEBPACK_IMPORTED_MODULE_2__["default"], this, props, opts);
  41323. var layers = this.get('layers');
  41324. var layersColl = new _Layers__WEBPACK_IMPORTED_MODULE_3__["default"](layers);
  41325. layersColl.property = this;
  41326. layersColl.properties = this.get('properties');
  41327. this.set('layers', layersColl);
  41328. _PropertyComposite__WEBPACK_IMPORTED_MODULE_2__["default"].callInit(this, props, opts);
  41329. },
  41330. getLayers: function getLayers() {
  41331. return this.get('layers');
  41332. },
  41333. getCurrentLayer: function getCurrentLayer() {
  41334. return this.getLayers().filter(function (layer) {
  41335. return layer.get('active');
  41336. })[0];
  41337. },
  41338. getFullValue: function getFullValue() {
  41339. return this.get('detached') ? '' : this.get('layers').getFullValue();
  41340. },
  41341. getValueFromStyle: function getValueFromStyle() {
  41342. var styles = arguments.length > 0 && arguments[0] !== undefined ? arguments[0] : {};
  41343. var layers = this.getLayers().getLayersFromStyle(styles);
  41344. return new _Layers__WEBPACK_IMPORTED_MODULE_3__["default"](layers).getFullValue();
  41345. },
  41346. clearValue: function clearValue() {
  41347. this.getLayers().reset();
  41348. return _PropertyComposite__WEBPACK_IMPORTED_MODULE_2__["default"].prototype.clearValue.apply(this, arguments);
  41349. },
  41350. getValueFromTarget: function getValueFromTarget(target) {
  41351. var _this$attributes = this.attributes,
  41352. detached = _this$attributes.detached,
  41353. property = _this$attributes.property,
  41354. properties = _this$attributes.properties;
  41355. var style = target.getStyle();
  41356. var validStyles = {};
  41357. properties.forEach(function (prop) {
  41358. var name = prop.get('property');
  41359. var value = style[name];
  41360. if (value) validStyles[name] = value;
  41361. });
  41362. return !detached ? style[property] : Object(underscore__WEBPACK_IMPORTED_MODULE_1__["keys"])(validStyles).length ? validStyles : '';
  41363. },
  41364. /**
  41365. * This method allows to customize layers returned from the target
  41366. * @param {Object} target
  41367. * @return {Array} Should return an array of layers
  41368. * @example
  41369. * // return example
  41370. * [
  41371. * {
  41372. * properties: [
  41373. * { property: 'width', ... }
  41374. * { property: 'height', ... }
  41375. * ]
  41376. * }
  41377. * ]
  41378. */
  41379. getLayersFromTarget: function getLayersFromTarget(target) {
  41380. return;
  41381. }
  41382. }));
  41383. /***/ }),
  41384. /***/ "./src/style_manager/model/Sector.js":
  41385. /*!*******************************************!*\
  41386. !*** ./src/style_manager/model/Sector.js ***!
  41387. \*******************************************/
  41388. /*! exports provided: default */
  41389. /***/ (function(module, __webpack_exports__, __webpack_require__) {
  41390. "use strict";
  41391. __webpack_require__.r(__webpack_exports__);
  41392. /* harmony import */ var backbone__WEBPACK_IMPORTED_MODULE_0__ = __webpack_require__(/*! backbone */ "./node_modules/backbone/backbone.js");
  41393. /* harmony import */ var backbone__WEBPACK_IMPORTED_MODULE_0___default = /*#__PURE__*/__webpack_require__.n(backbone__WEBPACK_IMPORTED_MODULE_0__);
  41394. /* harmony import */ var underscore__WEBPACK_IMPORTED_MODULE_1__ = __webpack_require__(/*! underscore */ "./node_modules/underscore/underscore.js");
  41395. /* harmony import */ var underscore__WEBPACK_IMPORTED_MODULE_1___default = /*#__PURE__*/__webpack_require__.n(underscore__WEBPACK_IMPORTED_MODULE_1__);
  41396. /* harmony import */ var _Properties__WEBPACK_IMPORTED_MODULE_2__ = __webpack_require__(/*! ./Properties */ "./src/style_manager/model/Properties.js");
  41397. /* harmony import */ var _PropertyFactory__WEBPACK_IMPORTED_MODULE_3__ = __webpack_require__(/*! ./PropertyFactory */ "./src/style_manager/model/PropertyFactory.js");
  41398. /* harmony default export */ __webpack_exports__["default"] = (backbone__WEBPACK_IMPORTED_MODULE_0___default.a.Model.extend({
  41399. defaults: {
  41400. id: '',
  41401. name: '',
  41402. open: true,
  41403. buildProps: '',
  41404. extendBuilded: 1,
  41405. properties: []
  41406. },
  41407. initialize: function initialize(opts) {
  41408. var o = opts || {};
  41409. var builded = this.buildProperties(o.buildProps);
  41410. var name = this.get('name') || '';
  41411. var props = [];
  41412. !this.get('id') && this.set('id', name.replace(/ /g, '_').toLowerCase());
  41413. if (!builded) props = this.get('properties');else props = this.extendProperties(builded);
  41414. var propsModel = new _Properties__WEBPACK_IMPORTED_MODULE_2__["default"](props);
  41415. propsModel.sector = this;
  41416. this.set('properties', propsModel);
  41417. },
  41418. /**
  41419. * Extend properties
  41420. * @param {Array<Object>} props Start properties
  41421. * @param {Array<Object>} moProps Model props
  41422. * @param {Boolean} ex Returns the same amount of passed model props
  41423. * @return {Array<Object>} Final props
  41424. * @private
  41425. */
  41426. extendProperties: function extendProperties(props, moProps, ex) {
  41427. var pLen = props.length;
  41428. var mProps = moProps || this.get('properties');
  41429. var ext = this.get('extendBuilded');
  41430. var isolated = [];
  41431. for (var i = 0, len = mProps.length; i < len; i++) {
  41432. var mProp = mProps[i];
  41433. var found = 0;
  41434. for (var j = 0; j < pLen; j++) {
  41435. var prop = props[j];
  41436. if (mProp.property == prop.property || mProp.id == prop.property) {
  41437. // Check for nested properties
  41438. var mPProps = mProp.properties;
  41439. if (mPProps && mPProps.length) {
  41440. mProp.properties = this.extendProperties(prop.properties || [], mPProps, 1);
  41441. }
  41442. props[j] = ext ? Object(underscore__WEBPACK_IMPORTED_MODULE_1__["extend"])(prop, mProp) : mProp;
  41443. isolated[j] = props[j];
  41444. found = 1;
  41445. continue;
  41446. }
  41447. }
  41448. if (!found) {
  41449. props.push(mProp);
  41450. isolated.push(mProp);
  41451. }
  41452. }
  41453. return ex ? isolated.filter(function (i) {
  41454. return i;
  41455. }) : props;
  41456. },
  41457. /**
  41458. * Build properties
  41459. * @param {Array<string>} propr Array of props as sting
  41460. * @return {Array<Object>}
  41461. * @private
  41462. */
  41463. buildProperties: function buildProperties(props) {
  41464. var r;
  41465. var buildP = props || [];
  41466. if (!buildP.length) return;
  41467. if (!this.propFactory) this.propFactory = new _PropertyFactory__WEBPACK_IMPORTED_MODULE_3__["default"]();
  41468. r = this.propFactory.build(buildP);
  41469. return r;
  41470. }
  41471. }));
  41472. /***/ }),
  41473. /***/ "./src/style_manager/model/Sectors.js":
  41474. /*!********************************************!*\
  41475. !*** ./src/style_manager/model/Sectors.js ***!
  41476. \********************************************/
  41477. /*! exports provided: default */
  41478. /***/ (function(module, __webpack_exports__, __webpack_require__) {
  41479. "use strict";
  41480. __webpack_require__.r(__webpack_exports__);
  41481. /* harmony import */ var backbone__WEBPACK_IMPORTED_MODULE_0__ = __webpack_require__(/*! backbone */ "./node_modules/backbone/backbone.js");
  41482. /* harmony import */ var backbone__WEBPACK_IMPORTED_MODULE_0___default = /*#__PURE__*/__webpack_require__.n(backbone__WEBPACK_IMPORTED_MODULE_0__);
  41483. /* harmony import */ var _Sector__WEBPACK_IMPORTED_MODULE_1__ = __webpack_require__(/*! ./Sector */ "./src/style_manager/model/Sector.js");
  41484. /* harmony default export */ __webpack_exports__["default"] = (backbone__WEBPACK_IMPORTED_MODULE_0___default.a.Collection.extend({
  41485. model: _Sector__WEBPACK_IMPORTED_MODULE_1__["default"]
  41486. }));
  41487. /***/ }),
  41488. /***/ "./src/style_manager/view/LayerView.js":
  41489. /*!*********************************************!*\
  41490. !*** ./src/style_manager/view/LayerView.js ***!
  41491. \*********************************************/
  41492. /*! exports provided: default */
  41493. /***/ (function(module, __webpack_exports__, __webpack_require__) {
  41494. "use strict";
  41495. __webpack_require__.r(__webpack_exports__);
  41496. /* harmony import */ var underscore__WEBPACK_IMPORTED_MODULE_0__ = __webpack_require__(/*! underscore */ "./node_modules/underscore/underscore.js");
  41497. /* harmony import */ var underscore__WEBPACK_IMPORTED_MODULE_0___default = /*#__PURE__*/__webpack_require__.n(underscore__WEBPACK_IMPORTED_MODULE_0__);
  41498. /* harmony import */ var backbone__WEBPACK_IMPORTED_MODULE_1__ = __webpack_require__(/*! backbone */ "./node_modules/backbone/backbone.js");
  41499. /* harmony import */ var backbone__WEBPACK_IMPORTED_MODULE_1___default = /*#__PURE__*/__webpack_require__.n(backbone__WEBPACK_IMPORTED_MODULE_1__);
  41500. /* harmony import */ var _PropertiesView__WEBPACK_IMPORTED_MODULE_2__ = __webpack_require__(/*! ./PropertiesView */ "./src/style_manager/view/PropertiesView.js");
  41501. /* harmony default export */ __webpack_exports__["default"] = (backbone__WEBPACK_IMPORTED_MODULE_1___default.a.View.extend({
  41502. events: {
  41503. click: 'active',
  41504. 'click [data-close-layer]': 'removeItem',
  41505. 'mousedown [data-move-layer]': 'initSorter',
  41506. 'touchstart [data-move-layer]': 'initSorter'
  41507. },
  41508. template: function template(model) {
  41509. var pfx = this.pfx,
  41510. ppfx = this.ppfx,
  41511. em = this.em;
  41512. var label = "".concat(em && em.t('styleManager.layer'), " ").concat(model.get('index'));
  41513. return "\n <div id=\"".concat(pfx, "move\" class=\"").concat(ppfx, "no-touch-actions\" data-move-layer>\n <i class=\"fa fa-arrows\"></i>\n </div>\n <div id=\"").concat(pfx, "label\">").concat(label, "</div>\n <div id=\"").concat(pfx, "preview-box\">\n \t<div id=\"").concat(pfx, "preview\" data-preview></div>\n </div>\n <div id=\"").concat(pfx, "close-layer\" class=\"").concat(pfx, "btn-close\" data-close-layer>\n &Cross;\n </div>\n <div id=\"").concat(pfx, "inputs\" data-properties></div>\n <div style=\"clear:both\"></div>\n ");
  41514. },
  41515. initialize: function initialize() {
  41516. var o = arguments.length > 0 && arguments[0] !== undefined ? arguments[0] : {};
  41517. var model = this.model;
  41518. this.stackModel = o.stackModel;
  41519. this.config = o.config || {};
  41520. this.em = this.config.em;
  41521. this.pfx = this.config.stylePrefix || '';
  41522. this.ppfx = this.config.pStylePrefix || '';
  41523. this.sorter = o.sorter || null;
  41524. this.propsConfig = o.propsConfig || {};
  41525. this.customPreview = o.onPreview;
  41526. this.listenTo(model, 'destroy remove', this.remove);
  41527. this.listenTo(model, 'change:active', this.updateVisibility);
  41528. this.listenTo(model.get('properties'), 'change', this.updatePreview); // For the sorter
  41529. model.view = this;
  41530. model.set({
  41531. droppable: 0,
  41532. draggable: 1
  41533. });
  41534. this.$el.data('model', model);
  41535. },
  41536. /**
  41537. * Delegate sorting
  41538. * @param {Event} e
  41539. * */
  41540. initSorter: function initSorter(e) {
  41541. if (this.sorter) this.sorter.startSort(this.el);
  41542. },
  41543. removeItem: function removeItem(ev) {
  41544. ev && ev.stopPropagation();
  41545. this.remove();
  41546. },
  41547. remove: function remove() {
  41548. var opts = arguments.length > 0 && arguments[0] !== undefined ? arguments[0] : {};
  41549. var model = this.model,
  41550. props = this.props;
  41551. var coll = model.collection;
  41552. var stackModel = this.stackModel;
  41553. backbone__WEBPACK_IMPORTED_MODULE_1___default.a.View.prototype.remove.apply(this, arguments);
  41554. coll && coll.contains(model) && coll.remove(model);
  41555. if (stackModel && stackModel.set) {
  41556. stackModel.set({
  41557. stackIndex: null
  41558. }, {
  41559. silent: true
  41560. });
  41561. !opts.fromTarget && stackModel.trigger('updateValue');
  41562. }
  41563. props && props.remove();
  41564. },
  41565. /**
  41566. * Default method for changing preview box
  41567. * @param {Collection} props
  41568. * @param {Element} $el
  41569. */
  41570. onPreview: function onPreview(value) {
  41571. var stackModel = this.stackModel;
  41572. var detach = stackModel && stackModel.get('detached');
  41573. var values = value.split(' ');
  41574. var lim = 3;
  41575. var result = [];
  41576. var resultObj = {};
  41577. this.model.get('properties').each(function (prop, index) {
  41578. var property = prop.get('property');
  41579. var value = detach ? prop.getFullValue() : values[index] || '';
  41580. if (value) {
  41581. if (prop.get('type') == 'integer') {
  41582. var valueInt = parseInt(value, 10);
  41583. var unit = value.replace(valueInt, '');
  41584. valueInt = !isNaN(valueInt) ? valueInt : 0;
  41585. valueInt = valueInt > lim ? lim : valueInt;
  41586. valueInt = valueInt < -lim ? -lim : valueInt;
  41587. value = valueInt + unit;
  41588. }
  41589. }
  41590. result.push(value);
  41591. resultObj[property] = value;
  41592. });
  41593. return detach ? resultObj : result.join(' ');
  41594. },
  41595. updatePreview: function updatePreview() {
  41596. var stackModel = this.stackModel;
  41597. var customPreview = this.customPreview;
  41598. var previewEl = this.getPreviewEl();
  41599. var value = this.model.getFullValue();
  41600. var preview = customPreview ? customPreview(value) : this.onPreview(value);
  41601. if (preview && stackModel && previewEl) {
  41602. var style = previewEl.style;
  41603. if (Object(underscore__WEBPACK_IMPORTED_MODULE_0__["isString"])(preview)) {
  41604. style[stackModel.get('property')] = preview;
  41605. } else {
  41606. var prvStr = [];
  41607. Object(underscore__WEBPACK_IMPORTED_MODULE_0__["each"])(preview, function (val, prop) {
  41608. return prvStr.push("".concat(prop, ":").concat(val));
  41609. });
  41610. previewEl.setAttribute('style', prvStr.join(';'));
  41611. }
  41612. }
  41613. },
  41614. getPropertiesWrapper: function getPropertiesWrapper() {
  41615. if (!this.propsWrapEl) {
  41616. this.propsWrapEl = this.el.querySelector('[data-properties]');
  41617. }
  41618. return this.propsWrapEl;
  41619. },
  41620. getPreviewEl: function getPreviewEl() {
  41621. if (!this.previewEl) {
  41622. this.previewEl = this.el.querySelector('[data-preview]');
  41623. }
  41624. return this.previewEl;
  41625. },
  41626. active: function active() {
  41627. var model = this.model;
  41628. var collection = model.collection;
  41629. collection.active(collection.indexOf(model));
  41630. },
  41631. updateVisibility: function updateVisibility() {
  41632. var pfx = this.pfx;
  41633. var wrapEl = this.getPropertiesWrapper();
  41634. var active = this.model.get('active');
  41635. wrapEl.style.display = active ? '' : 'none';
  41636. this.$el[active ? 'addClass' : 'removeClass']("".concat(pfx, "active"));
  41637. },
  41638. render: function render() {
  41639. var propsConfig = this.propsConfig;
  41640. var model = this.model,
  41641. el = this.el,
  41642. pfx = this.pfx;
  41643. var preview = model.get('preview');
  41644. var properties = new _PropertiesView__WEBPACK_IMPORTED_MODULE_2__["default"]({
  41645. collection: model.get('properties'),
  41646. config: this.config,
  41647. target: propsConfig.target,
  41648. customValue: propsConfig.customValue,
  41649. propTarget: propsConfig.propTarget,
  41650. onChange: propsConfig.onChange
  41651. });
  41652. var propsEl = properties.render().el;
  41653. el.innerHTML = this.template(model);
  41654. el.className = "".concat(pfx, "layer").concat(!preview ? " ".concat(pfx, "no-preview") : '');
  41655. this.props = properties;
  41656. this.getPropertiesWrapper().appendChild(propsEl);
  41657. this.updateVisibility();
  41658. this.updatePreview();
  41659. return this;
  41660. }
  41661. }));
  41662. /***/ }),
  41663. /***/ "./src/style_manager/view/LayersView.js":
  41664. /*!**********************************************!*\
  41665. !*** ./src/style_manager/view/LayersView.js ***!
  41666. \**********************************************/
  41667. /*! exports provided: default */
  41668. /***/ (function(module, __webpack_exports__, __webpack_require__) {
  41669. "use strict";
  41670. __webpack_require__.r(__webpack_exports__);
  41671. /* harmony import */ var backbone__WEBPACK_IMPORTED_MODULE_0__ = __webpack_require__(/*! backbone */ "./node_modules/backbone/backbone.js");
  41672. /* harmony import */ var backbone__WEBPACK_IMPORTED_MODULE_0___default = /*#__PURE__*/__webpack_require__.n(backbone__WEBPACK_IMPORTED_MODULE_0__);
  41673. /* harmony import */ var _LayerView__WEBPACK_IMPORTED_MODULE_1__ = __webpack_require__(/*! ./LayerView */ "./src/style_manager/view/LayerView.js");
  41674. /* harmony default export */ __webpack_exports__["default"] = (backbone__WEBPACK_IMPORTED_MODULE_0___default.a.View.extend({
  41675. initialize: function initialize(o) {
  41676. this.config = o.config || {};
  41677. this.stackModel = o.stackModel;
  41678. this.preview = o.preview;
  41679. this.pfx = this.config.stylePrefix || '';
  41680. this.ppfx = this.config.pStylePrefix || '';
  41681. this.propsConfig = o.propsConfig;
  41682. var pfx = this.pfx;
  41683. var ppfx = this.ppfx;
  41684. var collection = this.collection;
  41685. this.className = "".concat(pfx, "layers ").concat(ppfx, "field");
  41686. this.listenTo(collection, 'add', this.addTo);
  41687. this.listenTo(collection, 'deselectAll', this.deselectAll);
  41688. this.listenTo(collection, 'reset', this.reset);
  41689. this.items = [];
  41690. var em = this.config.em || '';
  41691. var utils = em ? em.get('Utils') : '';
  41692. this.sorter = utils ? new utils.Sorter({
  41693. container: this.el,
  41694. ignoreViewChildren: 1,
  41695. containerSel: ".".concat(pfx, "layers"),
  41696. itemSel: ".".concat(pfx, "layer"),
  41697. pfx: this.config.pStylePrefix
  41698. }) : ''; // For the Sorter
  41699. collection.view = this;
  41700. this.$el.data('model', collection);
  41701. this.$el.data('collection', collection);
  41702. },
  41703. /**
  41704. * Add to collection
  41705. * @param Object Model
  41706. *
  41707. * @return Object
  41708. * */
  41709. addTo: function addTo(model) {
  41710. var i = this.collection.indexOf(model);
  41711. this.addToCollection(model, null, i);
  41712. },
  41713. /**
  41714. * Add new object to collection
  41715. * @param Object Model
  41716. * @param Object Fragment collection
  41717. * @param {number} index Index of append
  41718. *
  41719. * @return Object Object created
  41720. * */
  41721. addToCollection: function addToCollection(model, fragmentEl, index) {
  41722. var fragment = fragmentEl || null;
  41723. var stackModel = this.stackModel;
  41724. var config = this.config;
  41725. var sorter = this.sorter;
  41726. var propsConfig = this.propsConfig;
  41727. if (typeof this.preview !== 'undefined') {
  41728. model.set('preview', this.preview);
  41729. }
  41730. var view = new _LayerView__WEBPACK_IMPORTED_MODULE_1__["default"]({
  41731. model: model,
  41732. config: config,
  41733. sorter: sorter,
  41734. stackModel: stackModel,
  41735. propsConfig: propsConfig
  41736. });
  41737. var rendered = view.render().el;
  41738. this.items.push(view);
  41739. if (fragment) {
  41740. fragment.appendChild(rendered);
  41741. } else {
  41742. if (typeof index != 'undefined') {
  41743. var method = 'before'; // If the added model is the last of collection
  41744. // need to change the logic of append
  41745. if (this.$el.children().length == index) {
  41746. index--;
  41747. method = 'after';
  41748. } // In case the added is new in the collection index will be -1
  41749. if (index < 0) {
  41750. this.$el.append(rendered);
  41751. } else this.$el.children().eq(index)[method](rendered);
  41752. } else this.$el.append(rendered);
  41753. }
  41754. return rendered;
  41755. },
  41756. /**
  41757. * Deselect all
  41758. *
  41759. * @return void
  41760. * */
  41761. deselectAll: function deselectAll() {
  41762. this.$el.find('.' + this.pfx + 'layer').removeClass(this.pfx + 'active');
  41763. },
  41764. reset: function reset(coll, opts) {
  41765. this.clearItems(opts);
  41766. this.render();
  41767. },
  41768. render: function render() {
  41769. var fragment = document.createDocumentFragment();
  41770. this.$el.empty();
  41771. this.collection.each(function (model) {
  41772. this.addToCollection(model, fragment);
  41773. }, this);
  41774. this.$el.append(fragment);
  41775. this.$el.attr('class', this.className);
  41776. if (this.sorter) this.sorter.plh = null;
  41777. return this;
  41778. },
  41779. remove: function remove() {
  41780. this.clearItems();
  41781. backbone__WEBPACK_IMPORTED_MODULE_0___default.a.View.prototype.remove.apply(this, arguments);
  41782. },
  41783. clearItems: function clearItems(opts) {
  41784. this.items.forEach(function (item) {
  41785. return item.remove(opts);
  41786. });
  41787. this.items = [];
  41788. }
  41789. }));
  41790. /***/ }),
  41791. /***/ "./src/style_manager/view/PropertiesView.js":
  41792. /*!**************************************************!*\
  41793. !*** ./src/style_manager/view/PropertiesView.js ***!
  41794. \**************************************************/
  41795. /*! exports provided: default */
  41796. /***/ (function(module, __webpack_exports__, __webpack_require__) {
  41797. "use strict";
  41798. __webpack_require__.r(__webpack_exports__);
  41799. /* harmony import */ var backbone__WEBPACK_IMPORTED_MODULE_0__ = __webpack_require__(/*! backbone */ "./node_modules/backbone/backbone.js");
  41800. /* harmony import */ var backbone__WEBPACK_IMPORTED_MODULE_0___default = /*#__PURE__*/__webpack_require__.n(backbone__WEBPACK_IMPORTED_MODULE_0__);
  41801. /* harmony import */ var utils_dom__WEBPACK_IMPORTED_MODULE_1__ = __webpack_require__(/*! utils/dom */ "./src/utils/dom.js");
  41802. /* harmony default export */ __webpack_exports__["default"] = (backbone__WEBPACK_IMPORTED_MODULE_0___default.a.View.extend({
  41803. initialize: function initialize(o) {
  41804. this.config = o.config || {};
  41805. this.pfx = this.config.stylePrefix || '';
  41806. this.target = o.target || {};
  41807. this.propTarget = o.propTarget || {};
  41808. this.onChange = o.onChange;
  41809. this.onInputRender = o.onInputRender || {};
  41810. this.customValue = o.customValue || {};
  41811. this.properties = [];
  41812. var coll = this.collection;
  41813. this.listenTo(coll, 'add', this.addTo);
  41814. this.listenTo(coll, 'reset', this.render);
  41815. },
  41816. addTo: function addTo(model, coll, opts) {
  41817. this.add(model, null, opts);
  41818. },
  41819. add: function add(model, frag) {
  41820. var opts = arguments.length > 2 && arguments[2] !== undefined ? arguments[2] : {};
  41821. var appendTo = frag || this.el;
  41822. var view = new model.typeView({
  41823. model: model,
  41824. name: model.get('name'),
  41825. id: this.pfx + model.get('property'),
  41826. target: this.target,
  41827. propTarget: this.propTarget,
  41828. onChange: this.onChange,
  41829. onInputRender: this.onInputRender,
  41830. config: this.config
  41831. });
  41832. if (model.get('type') != 'composite') {
  41833. view.customValue = this.customValue;
  41834. }
  41835. view.render();
  41836. var rendered = view.el;
  41837. this.properties.push(view);
  41838. view.updateVisibility();
  41839. Object(utils_dom__WEBPACK_IMPORTED_MODULE_1__["appendAtIndex"])(appendTo, rendered, opts.at);
  41840. },
  41841. render: function render() {
  41842. var _this = this;
  41843. var $el = this.$el;
  41844. this.clearItems();
  41845. var fragment = document.createDocumentFragment();
  41846. this.collection.each(function (model) {
  41847. return _this.add(model, fragment);
  41848. });
  41849. $el.empty();
  41850. $el.append(fragment);
  41851. $el.attr('class', "".concat(this.pfx, "properties"));
  41852. return this;
  41853. },
  41854. remove: function remove() {
  41855. backbone__WEBPACK_IMPORTED_MODULE_0___default.a.View.prototype.remove.apply(this, arguments);
  41856. this.clearItems();
  41857. },
  41858. clearItems: function clearItems() {
  41859. this.properties.forEach(function (item) {
  41860. return item.remove();
  41861. });
  41862. this.properties = [];
  41863. }
  41864. }));
  41865. /***/ }),
  41866. /***/ "./src/style_manager/view/PropertyColorView.js":
  41867. /*!*****************************************************!*\
  41868. !*** ./src/style_manager/view/PropertyColorView.js ***!
  41869. \*****************************************************/
  41870. /*! exports provided: default */
  41871. /***/ (function(module, __webpack_exports__, __webpack_require__) {
  41872. "use strict";
  41873. __webpack_require__.r(__webpack_exports__);
  41874. /* harmony import */ var _babel_runtime_helpers_defineProperty__WEBPACK_IMPORTED_MODULE_0__ = __webpack_require__(/*! @babel/runtime/helpers/defineProperty */ "./node_modules/@babel/runtime/helpers/defineProperty.js");
  41875. /* harmony import */ var _babel_runtime_helpers_defineProperty__WEBPACK_IMPORTED_MODULE_0___default = /*#__PURE__*/__webpack_require__.n(_babel_runtime_helpers_defineProperty__WEBPACK_IMPORTED_MODULE_0__);
  41876. /* harmony import */ var _PropertyIntegerView__WEBPACK_IMPORTED_MODULE_1__ = __webpack_require__(/*! ./PropertyIntegerView */ "./src/style_manager/view/PropertyIntegerView.js");
  41877. /* harmony import */ var domain_abstract_ui_InputColor__WEBPACK_IMPORTED_MODULE_2__ = __webpack_require__(/*! domain_abstract/ui/InputColor */ "./src/domain_abstract/ui/InputColor.js");
  41878. function ownKeys(object, enumerableOnly) { var keys = Object.keys(object); if (Object.getOwnPropertySymbols) { var symbols = Object.getOwnPropertySymbols(object); if (enumerableOnly) symbols = symbols.filter(function (sym) { return Object.getOwnPropertyDescriptor(object, sym).enumerable; }); keys.push.apply(keys, symbols); } return keys; }
  41879. function _objectSpread(target) { for (var i = 1; i < arguments.length; i++) { var source = arguments[i] != null ? arguments[i] : {}; if (i % 2) { ownKeys(source, true).forEach(function (key) { _babel_runtime_helpers_defineProperty__WEBPACK_IMPORTED_MODULE_0___default()(target, key, source[key]); }); } else if (Object.getOwnPropertyDescriptors) { Object.defineProperties(target, Object.getOwnPropertyDescriptors(source)); } else { ownKeys(source).forEach(function (key) { Object.defineProperty(target, key, Object.getOwnPropertyDescriptor(source, key)); }); } } return target; }
  41880. /* harmony default export */ __webpack_exports__["default"] = (_PropertyIntegerView__WEBPACK_IMPORTED_MODULE_1__["default"].extend({
  41881. setValue: function setValue(value) {
  41882. var opts = arguments.length > 1 && arguments[1] !== undefined ? arguments[1] : {};
  41883. opts = _objectSpread({}, opts, {
  41884. silent: 1
  41885. });
  41886. this.inputInst.setValue(value, opts);
  41887. },
  41888. onRender: function onRender() {
  41889. if (!this.input) {
  41890. var ppfx = this.ppfx;
  41891. var inputColor = new domain_abstract_ui_InputColor__WEBPACK_IMPORTED_MODULE_2__["default"]({
  41892. target: this.target,
  41893. model: this.model,
  41894. ppfx: ppfx
  41895. });
  41896. var input = inputColor.render();
  41897. this.el.querySelector(".".concat(ppfx, "fields")).appendChild(input.el);
  41898. this.$input = input.inputEl;
  41899. this.$color = input.colorEl;
  41900. this.input = this.$input.get(0);
  41901. this.inputInst = input;
  41902. }
  41903. }
  41904. }));
  41905. /***/ }),
  41906. /***/ "./src/style_manager/view/PropertyCompositeView.js":
  41907. /*!*********************************************************!*\
  41908. !*** ./src/style_manager/view/PropertyCompositeView.js ***!
  41909. \*********************************************************/
  41910. /*! exports provided: default */
  41911. /***/ (function(module, __webpack_exports__, __webpack_require__) {
  41912. "use strict";
  41913. __webpack_require__.r(__webpack_exports__);
  41914. /* harmony import */ var _babel_runtime_helpers_defineProperty__WEBPACK_IMPORTED_MODULE_0__ = __webpack_require__(/*! @babel/runtime/helpers/defineProperty */ "./node_modules/@babel/runtime/helpers/defineProperty.js");
  41915. /* harmony import */ var _babel_runtime_helpers_defineProperty__WEBPACK_IMPORTED_MODULE_0___default = /*#__PURE__*/__webpack_require__.n(_babel_runtime_helpers_defineProperty__WEBPACK_IMPORTED_MODULE_0__);
  41916. /* harmony import */ var backbone__WEBPACK_IMPORTED_MODULE_1__ = __webpack_require__(/*! backbone */ "./node_modules/backbone/backbone.js");
  41917. /* harmony import */ var backbone__WEBPACK_IMPORTED_MODULE_1___default = /*#__PURE__*/__webpack_require__.n(backbone__WEBPACK_IMPORTED_MODULE_1__);
  41918. /* harmony import */ var _PropertyView__WEBPACK_IMPORTED_MODULE_2__ = __webpack_require__(/*! ./PropertyView */ "./src/style_manager/view/PropertyView.js");
  41919. function ownKeys(object, enumerableOnly) { var keys = Object.keys(object); if (Object.getOwnPropertySymbols) { var symbols = Object.getOwnPropertySymbols(object); if (enumerableOnly) symbols = symbols.filter(function (sym) { return Object.getOwnPropertyDescriptor(object, sym).enumerable; }); keys.push.apply(keys, symbols); } return keys; }
  41920. function _objectSpread(target) { for (var i = 1; i < arguments.length; i++) { var source = arguments[i] != null ? arguments[i] : {}; if (i % 2) { ownKeys(source, true).forEach(function (key) { _babel_runtime_helpers_defineProperty__WEBPACK_IMPORTED_MODULE_0___default()(target, key, source[key]); }); } else if (Object.getOwnPropertyDescriptors) { Object.defineProperties(target, Object.getOwnPropertyDescriptors(source)); } else { ownKeys(source).forEach(function (key) { Object.defineProperty(target, key, Object.getOwnPropertyDescriptor(source, key)); }); } } return target; }
  41921. var $ = backbone__WEBPACK_IMPORTED_MODULE_1___default.a.$;
  41922. /* harmony default export */ __webpack_exports__["default"] = (_PropertyView__WEBPACK_IMPORTED_MODULE_2__["default"].extend({
  41923. templateInput: function templateInput() {
  41924. var pfx = this.pfx;
  41925. return "\n <div class=\"".concat(pfx, "field ").concat(pfx, "composite\">\n <span id=\"").concat(pfx, "input-holder\"></span>\n </div>\n ");
  41926. },
  41927. inputValueChanged: function inputValueChanged() {
  41928. // If it's not detached (eg. 'padding: 1px 2px 3px 4px;') it will follow
  41929. // the same flow of PropertyView
  41930. if (!this.model.get('detached')) {
  41931. for (var _len = arguments.length, args = new Array(_len), _key = 0; _key < _len; _key++) {
  41932. args[_key] = arguments[_key];
  41933. }
  41934. _PropertyView__WEBPACK_IMPORTED_MODULE_2__["default"].prototype.inputValueChanged.apply(this, args);
  41935. }
  41936. },
  41937. clear: function clear(e) {
  41938. var props = this.properties;
  41939. props && props.forEach(function (propView) {
  41940. return propView.clear();
  41941. });
  41942. _PropertyView__WEBPACK_IMPORTED_MODULE_2__["default"].prototype.clear.apply(this, arguments);
  41943. },
  41944. /**
  41945. * Renders input
  41946. * */
  41947. onRender: function onRender() {
  41948. var model = this.model;
  41949. var props = model.get('properties') || [];
  41950. var self = this;
  41951. this.properties = [];
  41952. if (props.length) {
  41953. if (!this.$input) {
  41954. this.$input = $('<input type="hidden" value="0">');
  41955. this.input = this.$input.get(0);
  41956. }
  41957. if (!this.props) {
  41958. this.props = model.get('properties');
  41959. }
  41960. if (!this.$props) {
  41961. //Not yet supported nested composite
  41962. this.props.each(function (prop, index) {
  41963. if (prop && prop.get('type') == 'composite') {
  41964. this.props.remove(prop);
  41965. console.warn('Nested composite types not yet allowed.');
  41966. }
  41967. prop.parent = model;
  41968. }, this);
  41969. var PropertiesView = __webpack_require__(/*! ./PropertiesView */ "./src/style_manager/view/PropertiesView.js").default;
  41970. var propsView = new PropertiesView(this.getPropsConfig());
  41971. this.$props = propsView.render().$el;
  41972. this.properties = propsView.properties;
  41973. this.$el.find("#".concat(this.pfx, "input-holder")).append(this.$props);
  41974. }
  41975. }
  41976. },
  41977. /**
  41978. * Returns configurations that should be past to properties
  41979. * @param {Object} opts
  41980. * @return {Object}
  41981. */
  41982. getPropsConfig: function getPropsConfig(opts) {
  41983. var that = this;
  41984. var model = this.model;
  41985. var result = {
  41986. config: _objectSpread({}, this.config, {
  41987. highlightComputed: 0
  41988. }),
  41989. collection: this.props,
  41990. target: this.target,
  41991. propTarget: this.propTarget,
  41992. // On any change made to children I need to update composite value
  41993. onChange: function onChange(el, view, opts) {
  41994. model.set('value', model.getFullValue(), opts);
  41995. },
  41996. // Each child property will receive a full composite string, eg. '0px 0px 10px 0px'
  41997. // I need to extract from that string the corresponding one to that property.
  41998. customValue: function customValue(property, mIndex) {
  41999. return that.valueOnIndex(mIndex, property);
  42000. }
  42001. }; // If detached let follow its standard flow
  42002. if (model.get('detached')) {
  42003. delete result.onChange;
  42004. }
  42005. return result;
  42006. },
  42007. /**
  42008. * Extract string from composite value
  42009. * @param {number} index Index
  42010. * @param {Object} view Property view
  42011. * @return {string}
  42012. * */
  42013. valueOnIndex: function valueOnIndex(index, view) {
  42014. var value;
  42015. var targetValue = this.getTargetValue({
  42016. ignoreDefault: 1
  42017. }); // If the target value of the composite is not empty I'll fetch
  42018. // the corresponding value from the requested index, otherwise try
  42019. // to get the value of the sub-property
  42020. if (targetValue) {
  42021. var values = targetValue.split(this.model.getSplitSeparator());
  42022. value = values[index];
  42023. } else {
  42024. value = view && view.getTargetValue({
  42025. ignoreCustomValue: 1,
  42026. ignoreDefault: 1
  42027. });
  42028. }
  42029. return value;
  42030. },
  42031. clearCached: function clearCached() {
  42032. _PropertyView__WEBPACK_IMPORTED_MODULE_2__["default"].prototype.clearCached.apply(this, arguments);
  42033. this.$input = null;
  42034. this.props = null;
  42035. this.$props = null;
  42036. }
  42037. }));
  42038. /***/ }),
  42039. /***/ "./src/style_manager/view/PropertyFileView.js":
  42040. /*!****************************************************!*\
  42041. !*** ./src/style_manager/view/PropertyFileView.js ***!
  42042. \****************************************************/
  42043. /*! exports provided: default */
  42044. /***/ (function(module, __webpack_exports__, __webpack_require__) {
  42045. "use strict";
  42046. __webpack_require__.r(__webpack_exports__);
  42047. /* harmony import */ var underscore__WEBPACK_IMPORTED_MODULE_0__ = __webpack_require__(/*! underscore */ "./node_modules/underscore/underscore.js");
  42048. /* harmony import */ var underscore__WEBPACK_IMPORTED_MODULE_0___default = /*#__PURE__*/__webpack_require__.n(underscore__WEBPACK_IMPORTED_MODULE_0__);
  42049. /* harmony import */ var backbone__WEBPACK_IMPORTED_MODULE_1__ = __webpack_require__(/*! backbone */ "./node_modules/backbone/backbone.js");
  42050. /* harmony import */ var backbone__WEBPACK_IMPORTED_MODULE_1___default = /*#__PURE__*/__webpack_require__.n(backbone__WEBPACK_IMPORTED_MODULE_1__);
  42051. /* harmony import */ var _PropertyView__WEBPACK_IMPORTED_MODULE_2__ = __webpack_require__(/*! ./PropertyView */ "./src/style_manager/view/PropertyView.js");
  42052. var $ = backbone__WEBPACK_IMPORTED_MODULE_1___default.a.$;
  42053. /* harmony default export */ __webpack_exports__["default"] = (_PropertyView__WEBPACK_IMPORTED_MODULE_2__["default"].extend({
  42054. templateInput: function templateInput() {
  42055. var pfx = this.pfx,
  42056. em = this.em;
  42057. return "\n <div class=\"".concat(pfx, "field ").concat(pfx, "file\">\n <div id='").concat(pfx, "input-holder'>\n <div class=\"").concat(pfx, "btn-c\">\n <button class=\"").concat(pfx, "btn\" id=\"").concat(pfx, "images\" type=\"button\">\n ").concat(em.t('styleManager.fileButton'), "\n </button>\n </div>\n <div style=\"clear:both;\"></div>\n </div>\n <div id=\"").concat(pfx, "preview-box\">\n <div id=\"").concat(pfx, "preview-file\"></div>\n <div id=\"").concat(pfx, "close\">&Cross;</div>\n </div>\n </div>\n ");
  42058. },
  42059. init: function init() {
  42060. var em = this.em;
  42061. this.modal = em.get('Modal');
  42062. this.am = em.get('AssetManager');
  42063. this.events['click #' + this.pfx + 'close'] = 'removeFile';
  42064. this.events['click #' + this.pfx + 'images'] = 'openAssetManager';
  42065. this.delegateEvents();
  42066. },
  42067. onRender: function onRender() {
  42068. if (!this.$input) {
  42069. var plh = this.model.getDefaultValue();
  42070. this.$input = $("<input placeholder=\"".concat(plh, "\">"));
  42071. }
  42072. if (!this.$preview) {
  42073. this.$preview = this.$el.find('#' + this.pfx + 'preview-file');
  42074. }
  42075. if (!this.$previewBox) {
  42076. this.$previewBox = this.$el.find('#' + this.pfx + 'preview-box');
  42077. }
  42078. this.setValue(this.componentValue, 0);
  42079. },
  42080. clearCached: function clearCached() {
  42081. _PropertyView__WEBPACK_IMPORTED_MODULE_2__["default"].prototype.clearCached.apply(this, arguments);
  42082. this.$preview = null;
  42083. this.$previewBox = null;
  42084. },
  42085. setValue: function setValue(value, f) {
  42086. _PropertyView__WEBPACK_IMPORTED_MODULE_2__["default"].prototype.setValue.apply(this, arguments);
  42087. this.setPreviewView(value && value != this.model.getDefaultValue());
  42088. this.setPreview(value);
  42089. },
  42090. /**
  42091. * Change visibility of the preview box
  42092. * @param bool Visibility
  42093. *
  42094. * @return void
  42095. * */
  42096. setPreviewView: function setPreviewView(v) {
  42097. var pv = this.$previewBox;
  42098. pv && pv[v ? 'addClass' : 'removeClass']("".concat(this.pfx, "show"));
  42099. pv && pv.css({
  42100. display: v ? 'block' : 'none'
  42101. });
  42102. },
  42103. /**
  42104. * Spread url
  42105. * @param string Url
  42106. *
  42107. * @return void
  42108. * */
  42109. spreadUrl: function spreadUrl(url) {
  42110. this.model.set('value', url);
  42111. this.setPreviewView(1);
  42112. },
  42113. /**
  42114. * Shows file preview
  42115. * @param string Value
  42116. * */
  42117. setPreview: function setPreview(value) {
  42118. var preview = this.$preview;
  42119. value = value && value.indexOf('url(') < 0 ? "url(".concat(value, ")") : value;
  42120. preview && preview.css('background-image', value);
  42121. },
  42122. /** @inheritdoc */
  42123. cleanValue: function cleanValue() {
  42124. this.setPreviewView(0);
  42125. this.model.set({
  42126. value: ''
  42127. }, {
  42128. silent: true
  42129. });
  42130. },
  42131. /**
  42132. * Remove file from input
  42133. *
  42134. * @return void
  42135. * */
  42136. removeFile: function removeFile() {
  42137. this.model.set('value', this.model.getDefaultValue());
  42138. for (var _len = arguments.length, args = new Array(_len), _key = 0; _key < _len; _key++) {
  42139. args[_key] = arguments[_key];
  42140. }
  42141. _PropertyView__WEBPACK_IMPORTED_MODULE_2__["default"].prototype.cleanValue.apply(this, args);
  42142. this.setPreviewView(0);
  42143. },
  42144. /**
  42145. * Open dialog for image selecting
  42146. * @param {Object} e Event
  42147. *
  42148. * @return void
  42149. * */
  42150. openAssetManager: function openAssetManager(e) {
  42151. var _this = this;
  42152. var em = this.em,
  42153. modal = this.modal;
  42154. var editor = em ? em.get('Editor') : '';
  42155. if (editor) {
  42156. editor.runCommand('open-assets', {
  42157. types: ['image'],
  42158. accept: 'image/*',
  42159. target: this.getTargetModel(),
  42160. onClick: function onClick() {},
  42161. onDblClick: function onDblClick() {},
  42162. onSelect: function onSelect(asset) {
  42163. modal.close();
  42164. var url = Object(underscore__WEBPACK_IMPORTED_MODULE_0__["isString"])(asset) ? asset : asset.get('src');
  42165. _this.spreadUrl(url);
  42166. }
  42167. });
  42168. }
  42169. }
  42170. }));
  42171. /***/ }),
  42172. /***/ "./src/style_manager/view/PropertyIntegerView.js":
  42173. /*!*******************************************************!*\
  42174. !*** ./src/style_manager/view/PropertyIntegerView.js ***!
  42175. \*******************************************************/
  42176. /*! exports provided: default */
  42177. /***/ (function(module, __webpack_exports__, __webpack_require__) {
  42178. "use strict";
  42179. __webpack_require__.r(__webpack_exports__);
  42180. /* harmony import */ var backbone__WEBPACK_IMPORTED_MODULE_0__ = __webpack_require__(/*! backbone */ "./node_modules/backbone/backbone.js");
  42181. /* harmony import */ var backbone__WEBPACK_IMPORTED_MODULE_0___default = /*#__PURE__*/__webpack_require__.n(backbone__WEBPACK_IMPORTED_MODULE_0__);
  42182. /* harmony import */ var _PropertyView__WEBPACK_IMPORTED_MODULE_1__ = __webpack_require__(/*! ./PropertyView */ "./src/style_manager/view/PropertyView.js");
  42183. var $ = backbone__WEBPACK_IMPORTED_MODULE_0___default.a.$;
  42184. /* harmony default export */ __webpack_exports__["default"] = (_PropertyView__WEBPACK_IMPORTED_MODULE_1__["default"].extend({
  42185. templateInput: function templateInput() {
  42186. return '';
  42187. },
  42188. init: function init() {
  42189. var model = this.model;
  42190. this.listenTo(model, 'change:unit', this.modelValueChanged);
  42191. this.listenTo(model, 'el:change', this.elementUpdated);
  42192. this.listenTo(model, 'change:units', this.render);
  42193. },
  42194. setValue: function setValue(value) {
  42195. var parsed = this.model.parseValue(value);
  42196. value = "".concat(parsed.value).concat(parsed.unit);
  42197. this.inputInst.setValue(value, {
  42198. silent: 1
  42199. });
  42200. },
  42201. onRender: function onRender() {
  42202. var ppfx = this.ppfx;
  42203. if (!this.input) {
  42204. var input = this.model.input;
  42205. input.ppfx = ppfx;
  42206. input.render();
  42207. var fields = this.el.querySelector(".".concat(ppfx, "fields"));
  42208. fields.appendChild(input.el);
  42209. this.$input = input.inputEl;
  42210. this.unit = input.unitEl;
  42211. this.$unit = $(this.unit);
  42212. this.input = this.$input.get(0);
  42213. this.inputInst = input;
  42214. }
  42215. },
  42216. clearCached: function clearCached() {
  42217. _PropertyView__WEBPACK_IMPORTED_MODULE_1__["default"].prototype.clearCached.apply(this, arguments);
  42218. this.unit = null;
  42219. this.$unit = null;
  42220. }
  42221. }));
  42222. /***/ }),
  42223. /***/ "./src/style_manager/view/PropertyRadioView.js":
  42224. /*!*****************************************************!*\
  42225. !*** ./src/style_manager/view/PropertyRadioView.js ***!
  42226. \*****************************************************/
  42227. /*! exports provided: default */
  42228. /***/ (function(module, __webpack_exports__, __webpack_require__) {
  42229. "use strict";
  42230. __webpack_require__.r(__webpack_exports__);
  42231. /* harmony import */ var _PropertyView__WEBPACK_IMPORTED_MODULE_0__ = __webpack_require__(/*! ./PropertyView */ "./src/style_manager/view/PropertyView.js");
  42232. /* harmony default export */ __webpack_exports__["default"] = (_PropertyView__WEBPACK_IMPORTED_MODULE_0__["default"].extend({
  42233. templateInput: function templateInput() {
  42234. var pfx = this.pfx;
  42235. var ppfx = this.ppfx;
  42236. return "\n <div class=\"".concat(ppfx, "field ").concat(ppfx, "field-radio\">\n </div>\n ");
  42237. },
  42238. onRender: function onRender() {
  42239. var pfx = this.pfx;
  42240. var ppfx = this.ppfx;
  42241. var itemCls = "".concat(ppfx, "radio-item-label");
  42242. var model = this.model;
  42243. var prop = model.get('property');
  42244. var options = model.get('list') || model.get('options') || [];
  42245. var cid = model.cid;
  42246. var clsInput = "".concat(pfx, "radio ").concat(pfx, "radio-").concat(prop);
  42247. if (!this.input) {
  42248. if (options && options.length) {
  42249. var inputStr = '';
  42250. options.forEach(function (el) {
  42251. var cl = el.className ? "".concat(el.className, " ").concat(pfx, "icon ").concat(itemCls) : '';
  42252. var id = "".concat(prop, "-").concat(el.value, "-").concat(cid);
  42253. var labelTxt = el.name || el.value;
  42254. var titleAttr = el.title ? "title=\"".concat(el.title, "\"") : '';
  42255. inputStr += "\n <div class=\"".concat(ppfx, "radio-item\">\n <input type=\"radio\" class=\"").concat(clsInput, "\" id=\"").concat(id, "\" name=\"").concat(prop, "-").concat(cid, "\" value=\"").concat(el.value, "\"/>\n <label class=\"").concat(cl || itemCls, "\" ").concat(titleAttr, " for=\"").concat(id, "\">").concat(cl ? '' : labelTxt, "</label>\n </div>\n ");
  42256. });
  42257. var inputHld = this.el.querySelector(".".concat(ppfx, "field"));
  42258. inputHld.innerHTML = "<div class=\"".concat(ppfx, "radio-items\">").concat(inputStr, "</div>");
  42259. this.input = inputHld.firstChild;
  42260. }
  42261. }
  42262. },
  42263. getInputValue: function getInputValue() {
  42264. var inputChk = this.getCheckedEl();
  42265. return inputChk ? inputChk.value : '';
  42266. },
  42267. getCheckedEl: function getCheckedEl() {
  42268. var input = this.getInputEl();
  42269. return input ? input.querySelector('input:checked') : '';
  42270. },
  42271. setValue: function setValue(value) {
  42272. var model = this.model;
  42273. var val = value || model.get('value') || model.getDefaultValue();
  42274. var input = this.getInputEl();
  42275. var inputIn = input ? input.querySelector("[value=\"".concat(val, "\"]")) : '';
  42276. if (inputIn) {
  42277. inputIn.checked = true;
  42278. } else {
  42279. var inputChk = this.getCheckedEl();
  42280. inputChk && (inputChk.checked = false);
  42281. }
  42282. }
  42283. }));
  42284. /***/ }),
  42285. /***/ "./src/style_manager/view/PropertySelectView.js":
  42286. /*!******************************************************!*\
  42287. !*** ./src/style_manager/view/PropertySelectView.js ***!
  42288. \******************************************************/
  42289. /*! exports provided: default */
  42290. /***/ (function(module, __webpack_exports__, __webpack_require__) {
  42291. "use strict";
  42292. __webpack_require__.r(__webpack_exports__);
  42293. /* harmony import */ var backbone__WEBPACK_IMPORTED_MODULE_0__ = __webpack_require__(/*! backbone */ "./node_modules/backbone/backbone.js");
  42294. /* harmony import */ var backbone__WEBPACK_IMPORTED_MODULE_0___default = /*#__PURE__*/__webpack_require__.n(backbone__WEBPACK_IMPORTED_MODULE_0__);
  42295. /* harmony import */ var _PropertyView__WEBPACK_IMPORTED_MODULE_1__ = __webpack_require__(/*! ./PropertyView */ "./src/style_manager/view/PropertyView.js");
  42296. var $ = backbone__WEBPACK_IMPORTED_MODULE_0___default.a.$;
  42297. /* harmony default export */ __webpack_exports__["default"] = (_PropertyView__WEBPACK_IMPORTED_MODULE_1__["default"].extend({
  42298. templateInput: function templateInput() {
  42299. var pfx = this.pfx;
  42300. var ppfx = this.ppfx;
  42301. return "\n <div class=\"".concat(ppfx, "field ").concat(ppfx, "select\">\n <span id=\"").concat(pfx, "input-holder\"></span>\n <div class=\"").concat(ppfx, "sel-arrow\">\n <div class=\"").concat(ppfx, "d-s-arrow\"></div>\n </div>\n </div>\n ");
  42302. },
  42303. initialize: function initialize() {
  42304. for (var _len = arguments.length, args = new Array(_len), _key = 0; _key < _len; _key++) {
  42305. args[_key] = arguments[_key];
  42306. }
  42307. _PropertyView__WEBPACK_IMPORTED_MODULE_1__["default"].prototype.initialize.apply(this, args);
  42308. this.listenTo(this.model, 'change:options', this.updateOptions);
  42309. },
  42310. updateOptions: function updateOptions() {
  42311. this.input = null;
  42312. this.onRender();
  42313. },
  42314. onRender: function onRender() {
  42315. var pfx = this.pfx;
  42316. var options = this.model.getOptions();
  42317. if (!this.input) {
  42318. var optionsStr = '';
  42319. options.forEach(function (option) {
  42320. var name = option.name || option.value;
  42321. var style = option.style ? option.style.replace(/"/g, '&quot;') : '';
  42322. var styleAttr = style ? "style=\"".concat(style, "\"") : '';
  42323. var value = option.value.replace(/"/g, '&quot;');
  42324. optionsStr += "<option value=\"".concat(value, "\" ").concat(styleAttr, ">").concat(name, "</option>");
  42325. });
  42326. var inputH = this.el.querySelector("#".concat(pfx, "input-holder"));
  42327. inputH.innerHTML = "<select>".concat(optionsStr, "</select>");
  42328. this.input = inputH.firstChild;
  42329. }
  42330. }
  42331. }));
  42332. /***/ }),
  42333. /***/ "./src/style_manager/view/PropertySliderView.js":
  42334. /*!******************************************************!*\
  42335. !*** ./src/style_manager/view/PropertySliderView.js ***!
  42336. \******************************************************/
  42337. /*! exports provided: default */
  42338. /***/ (function(module, __webpack_exports__, __webpack_require__) {
  42339. "use strict";
  42340. __webpack_require__.r(__webpack_exports__);
  42341. /* harmony import */ var _babel_runtime_helpers_defineProperty__WEBPACK_IMPORTED_MODULE_0__ = __webpack_require__(/*! @babel/runtime/helpers/defineProperty */ "./node_modules/@babel/runtime/helpers/defineProperty.js");
  42342. /* harmony import */ var _babel_runtime_helpers_defineProperty__WEBPACK_IMPORTED_MODULE_0___default = /*#__PURE__*/__webpack_require__.n(_babel_runtime_helpers_defineProperty__WEBPACK_IMPORTED_MODULE_0__);
  42343. /* harmony import */ var _PropertyIntegerView__WEBPACK_IMPORTED_MODULE_1__ = __webpack_require__(/*! ./PropertyIntegerView */ "./src/style_manager/view/PropertyIntegerView.js");
  42344. function ownKeys(object, enumerableOnly) { var keys = Object.keys(object); if (Object.getOwnPropertySymbols) { var symbols = Object.getOwnPropertySymbols(object); if (enumerableOnly) symbols = symbols.filter(function (sym) { return Object.getOwnPropertyDescriptor(object, sym).enumerable; }); keys.push.apply(keys, symbols); } return keys; }
  42345. function _objectSpread(target) { for (var i = 1; i < arguments.length; i++) { var source = arguments[i] != null ? arguments[i] : {}; if (i % 2) { ownKeys(source, true).forEach(function (key) { _babel_runtime_helpers_defineProperty__WEBPACK_IMPORTED_MODULE_0___default()(target, key, source[key]); }); } else if (Object.getOwnPropertyDescriptors) { Object.defineProperties(target, Object.getOwnPropertyDescriptors(source)); } else { ownKeys(source).forEach(function (key) { Object.defineProperty(target, key, Object.getOwnPropertyDescriptor(source, key)); }); } } return target; }
  42346. /* harmony default export */ __webpack_exports__["default"] = (_PropertyIntegerView__WEBPACK_IMPORTED_MODULE_1__["default"].extend({
  42347. events: function events() {
  42348. return _objectSpread({}, _PropertyIntegerView__WEBPACK_IMPORTED_MODULE_1__["default"].prototype.events, {
  42349. 'change [type=range]': 'inputValueChanged',
  42350. 'input [type=range]': 'inputValueChangedSoft',
  42351. change: ''
  42352. });
  42353. },
  42354. templateInput: function templateInput(model) {
  42355. var ppfx = this.ppfx;
  42356. return "\n <div class=\"".concat(ppfx, "field ").concat(ppfx, "field-range\">\n <input type=\"range\"\n min=\"").concat(model.get('min'), "\"\n max=\"").concat(model.get('max'), "\"\n step=\"").concat(model.get('step'), "\"/>\n </div>\n ");
  42357. },
  42358. getSliderEl: function getSliderEl() {
  42359. if (!this.slider) {
  42360. this.slider = this.el.querySelector('input[type=range]');
  42361. }
  42362. return this.slider;
  42363. },
  42364. inputValueChanged: function inputValueChanged() {
  42365. var model = this.model;
  42366. var step = model.get('step');
  42367. this.getInputEl().value = this.getSliderEl().value;
  42368. var value = this.getInputValue() - step;
  42369. model.set('value', value, {
  42370. avoidStore: 1
  42371. }).set('value', value + step);
  42372. this.elementUpdated();
  42373. },
  42374. inputValueChangedSoft: function inputValueChangedSoft() {
  42375. this.getInputEl().value = this.getSliderEl().value;
  42376. this.model.set('value', this.getInputValue(), {
  42377. avoidStore: 1
  42378. });
  42379. this.elementUpdated();
  42380. },
  42381. setValue: function setValue(value) {
  42382. var parsed = this.model.parseValue(value);
  42383. this.getSliderEl().value = parseFloat(parsed.value);
  42384. _PropertyIntegerView__WEBPACK_IMPORTED_MODULE_1__["default"].prototype.setValue.apply(this, arguments);
  42385. },
  42386. onRender: function onRender() {
  42387. _PropertyIntegerView__WEBPACK_IMPORTED_MODULE_1__["default"].prototype.onRender.apply(this, arguments);
  42388. if (!this.model.get('showInput')) {
  42389. this.inputInst.el.style.display = 'none';
  42390. }
  42391. },
  42392. clearCached: function clearCached() {
  42393. _PropertyIntegerView__WEBPACK_IMPORTED_MODULE_1__["default"].prototype.clearCached.apply(this, arguments);
  42394. this.slider = null;
  42395. }
  42396. }));
  42397. /***/ }),
  42398. /***/ "./src/style_manager/view/PropertyStackView.js":
  42399. /*!*****************************************************!*\
  42400. !*** ./src/style_manager/view/PropertyStackView.js ***!
  42401. \*****************************************************/
  42402. /*! exports provided: default */
  42403. /***/ (function(module, __webpack_exports__, __webpack_require__) {
  42404. "use strict";
  42405. __webpack_require__.r(__webpack_exports__);
  42406. /* harmony import */ var _babel_runtime_helpers_defineProperty__WEBPACK_IMPORTED_MODULE_0__ = __webpack_require__(/*! @babel/runtime/helpers/defineProperty */ "./node_modules/@babel/runtime/helpers/defineProperty.js");
  42407. /* harmony import */ var _babel_runtime_helpers_defineProperty__WEBPACK_IMPORTED_MODULE_0___default = /*#__PURE__*/__webpack_require__.n(_babel_runtime_helpers_defineProperty__WEBPACK_IMPORTED_MODULE_0__);
  42408. /* harmony import */ var underscore__WEBPACK_IMPORTED_MODULE_1__ = __webpack_require__(/*! underscore */ "./node_modules/underscore/underscore.js");
  42409. /* harmony import */ var underscore__WEBPACK_IMPORTED_MODULE_1___default = /*#__PURE__*/__webpack_require__.n(underscore__WEBPACK_IMPORTED_MODULE_1__);
  42410. /* harmony import */ var _PropertyCompositeView__WEBPACK_IMPORTED_MODULE_2__ = __webpack_require__(/*! ./PropertyCompositeView */ "./src/style_manager/view/PropertyCompositeView.js");
  42411. /* harmony import */ var _LayersView__WEBPACK_IMPORTED_MODULE_3__ = __webpack_require__(/*! ./LayersView */ "./src/style_manager/view/LayersView.js");
  42412. /* harmony import */ var code_manager_model_CssGenerator__WEBPACK_IMPORTED_MODULE_4__ = __webpack_require__(/*! code_manager/model/CssGenerator */ "./src/code_manager/model/CssGenerator.js");
  42413. function ownKeys(object, enumerableOnly) { var keys = Object.keys(object); if (Object.getOwnPropertySymbols) { var symbols = Object.getOwnPropertySymbols(object); if (enumerableOnly) symbols = symbols.filter(function (sym) { return Object.getOwnPropertyDescriptor(object, sym).enumerable; }); keys.push.apply(keys, symbols); } return keys; }
  42414. function _objectSpread(target) { for (var i = 1; i < arguments.length; i++) { var source = arguments[i] != null ? arguments[i] : {}; if (i % 2) { ownKeys(source, true).forEach(function (key) { _babel_runtime_helpers_defineProperty__WEBPACK_IMPORTED_MODULE_0___default()(target, key, source[key]); }); } else if (Object.getOwnPropertyDescriptors) { Object.defineProperties(target, Object.getOwnPropertyDescriptors(source)); } else { ownKeys(source).forEach(function (key) { Object.defineProperty(target, key, Object.getOwnPropertyDescriptor(source, key)); }); } } return target; }
  42415. var cssGen = new code_manager_model_CssGenerator__WEBPACK_IMPORTED_MODULE_4__["default"]();
  42416. /* harmony default export */ __webpack_exports__["default"] = (_PropertyCompositeView__WEBPACK_IMPORTED_MODULE_2__["default"].extend({
  42417. templateInput: function templateInput() {
  42418. var pfx = this.pfx;
  42419. var ppfx = this.ppfx;
  42420. return "\n <div class=\"".concat(pfx, "field ").concat(pfx, "stack\">\n <button type=\"button\" id=\"").concat(pfx, "add\" data-add-layer>+</button>\n <div data-layers-wrapper></div>\n </div>\n ");
  42421. },
  42422. init: function init() {
  42423. var model = this.model;
  42424. var pfx = this.pfx;
  42425. model.set('stackIndex', null);
  42426. this.events["click [data-add-layer]"] = 'addLayer';
  42427. this.listenTo(model, 'change:stackIndex', this.indexChanged);
  42428. this.listenTo(model, 'updateValue', this.inputValueChanged);
  42429. this.delegateEvents();
  42430. var propsConfig = this.getPropsConfig();
  42431. this.layers = new _LayersView__WEBPACK_IMPORTED_MODULE_3__["default"]({
  42432. collection: this.getLayers(),
  42433. stackModel: model,
  42434. preview: model.get('preview'),
  42435. config: this.config,
  42436. propsConfig: propsConfig
  42437. });
  42438. var PropertiesView = __webpack_require__(/*! ./PropertiesView */ "./src/style_manager/view/PropertiesView.js").default;
  42439. this.propsView = new PropertiesView({
  42440. target: this.target,
  42441. collection: model.get('properties'),
  42442. stackModel: model,
  42443. config: this.config,
  42444. onChange: propsConfig.onChange,
  42445. propTarget: propsConfig.propTarget
  42446. });
  42447. },
  42448. /**
  42449. * Fired when the target is updated.
  42450. * With detached mode the component will be always empty as its value
  42451. * so we gonna check all props and find if it has any difference
  42452. * */
  42453. targetUpdated: function targetUpdated() {
  42454. var _this = this;
  42455. var data;
  42456. if (!this.model.get('detached')) {
  42457. for (var _len = arguments.length, args = new Array(_len), _key = 0; _key < _len; _key++) {
  42458. args[_key] = arguments[_key];
  42459. }
  42460. data = _PropertyCompositeView__WEBPACK_IMPORTED_MODULE_2__["default"].prototype.targetUpdated.apply(this, args);
  42461. } else {
  42462. data = this._getTargetData();
  42463. this.setStatus(data.status);
  42464. this.checkVisibility();
  42465. } // I have to wait the update of inner properites (like visibility)
  42466. // before render layers
  42467. setTimeout(function () {
  42468. return _this.refreshLayers(data);
  42469. });
  42470. },
  42471. /**
  42472. * Returns the collection of layers
  42473. * @return {Collection}
  42474. */
  42475. getLayers: function getLayers() {
  42476. return this.model.get('layers');
  42477. },
  42478. /**
  42479. * Triggered when another layer has been selected.
  42480. * This allow to move all rendered properties to a new
  42481. * selected layer
  42482. * @param {Event}
  42483. *
  42484. * @return {Object}
  42485. * */
  42486. indexChanged: function indexChanged(e) {
  42487. var model = this.model;
  42488. this.getLayers().active(model.get('stackIndex'));
  42489. },
  42490. addLayer: function addLayer() {
  42491. var model = this.model;
  42492. var layers = this.getLayers();
  42493. var prepend = model.get('prepend');
  42494. var properties = model.get('properties').deepClone();
  42495. properties.each(function (property) {
  42496. return property.set('value', '');
  42497. });
  42498. var layer = layers.add({
  42499. properties: properties
  42500. }, _objectSpread({
  42501. active: 1
  42502. }, prepend && {
  42503. at: 0
  42504. })); // In detached mode inputValueChanged will add new 'layer value'
  42505. // to all subprops
  42506. this.inputValueChanged({
  42507. up: 1
  42508. }); // This will set subprops with a new default values
  42509. model.set('stackIndex', layers.indexOf(layer));
  42510. },
  42511. inputValueChanged: function inputValueChanged() {
  42512. var opts = arguments.length > 0 && arguments[0] !== undefined ? arguments[0] : {};
  42513. var model = this.model;
  42514. opts.up && this.elementUpdated(); // If not detached I'll just put all the values from layers to property
  42515. // eg. background: layer1Value, layer2Value, layer3Value, ...
  42516. if (!model.get('detached')) {
  42517. model.set('value', this.getLayerValues());
  42518. } else {
  42519. model.get('properties').each(function (prop) {
  42520. return prop.trigger('change:value');
  42521. });
  42522. }
  42523. },
  42524. /**
  42525. * There is no need to handle input update by the property itself,
  42526. * this will be done by layers
  42527. * @private
  42528. */
  42529. setValue: function setValue() {},
  42530. /**
  42531. * Create value by layers
  42532. * @return string
  42533. * */
  42534. getLayerValues: function getLayerValues() {
  42535. return this.getLayers().getFullValue();
  42536. },
  42537. _getClassRule: function _getClassRule() {
  42538. var opts = arguments.length > 0 && arguments[0] !== undefined ? arguments[0] : {};
  42539. var em = this.em;
  42540. var _opts$skipAdd = opts.skipAdd,
  42541. skipAdd = _opts$skipAdd === void 0 ? 1 : _opts$skipAdd;
  42542. var selected = em.getSelected();
  42543. var targetAlt = em.get('StyleManager').getModelToStyle(selected, {
  42544. skipAdd: skipAdd,
  42545. useClasses: 1
  42546. });
  42547. return targetAlt !== selected && targetAlt;
  42548. },
  42549. /**
  42550. * Return the parent style rule of the passed one
  42551. * @private
  42552. */
  42553. _getParentTarget: function _getParentTarget(target) {
  42554. var opts = arguments.length > 1 && arguments[1] !== undefined ? arguments[1] : {};
  42555. var em = this.em,
  42556. model = this.model;
  42557. var property = model.get('property');
  42558. var isValid = opts.isValid || function (rule) {
  42559. return rule.getStyle()[property];
  42560. };
  42561. var targetsDevice = em.get('CssComposer').getAll().filter(function (rule) {
  42562. return rule.selectorsToString() === target.getSelectorsString();
  42563. });
  42564. var map = targetsDevice.reduce(function (acc, rule) {
  42565. acc[rule.getAtRule()] = rule;
  42566. return acc;
  42567. }, {});
  42568. var mapSorted = cssGen.sortMediaObject(map);
  42569. var sortedRules = mapSorted.map(function (item) {
  42570. return item.value;
  42571. });
  42572. var currIndex = sortedRules.indexOf(target);
  42573. var rulesToCheck = sortedRules.splice(0, currIndex);
  42574. var result;
  42575. for (var i = rulesToCheck.length - 1; i > -1; i--) {
  42576. var rule = rulesToCheck[i];
  42577. if (isValid(rule)) {
  42578. // only for not detached
  42579. result = rule;
  42580. break;
  42581. }
  42582. }
  42583. return result;
  42584. },
  42585. /**
  42586. * Refresh layers
  42587. * */
  42588. refreshLayers: function refreshLayers() {
  42589. var opts = arguments.length > 0 && arguments[0] !== undefined ? arguments[0] : {};
  42590. var layersObj = [];
  42591. var model = this.model,
  42592. em = this.em;
  42593. var layers = this.getLayers();
  42594. var detached = model.get('detached');
  42595. var property = model.get('property');
  42596. var target = this.getTarget();
  42597. var valueComput = this.getComputedValue();
  42598. var selected = em.getSelected();
  42599. var updateOpts = {
  42600. fromTarget: 1
  42601. };
  42602. var resultValue, style, targetAlt, targetAltDevice, valueTargetAlt, valueTrgAltDvc; // With detached layers values will be assigned to their properties
  42603. if (detached) {
  42604. style = opts.targetValue || {};
  42605. var hasDetachedStyle = function hasDetachedStyle(rule) {
  42606. var name = model.get('properties').at(0).get('property');
  42607. return rule && !Object(underscore__WEBPACK_IMPORTED_MODULE_1__["isUndefined"])(rule.getStyle()[name]);
  42608. }; // If the style object is empty but the target has a computed value,
  42609. // that means the style might exist in some other place
  42610. if (!Object(underscore__WEBPACK_IMPORTED_MODULE_1__["keys"])(style).length && valueComput && selected) {
  42611. // Styles of the same target but with a higher rule
  42612. var parentOpts = {
  42613. isValid: function isValid(rule) {
  42614. return hasDetachedStyle(rule);
  42615. }
  42616. };
  42617. targetAltDevice = this._getParentTarget(target, parentOpts);
  42618. if (targetAltDevice) {
  42619. style = targetAltDevice.getStyle();
  42620. } else {
  42621. // The target is a component but the style is in the class rules
  42622. targetAlt = this._getClassRule();
  42623. valueTargetAlt = hasDetachedStyle(targetAlt) && targetAlt.getStyle();
  42624. targetAltDevice = !valueTargetAlt && this._getParentTarget(this._getClassRule({
  42625. skipAdd: 0
  42626. }), parentOpts);
  42627. valueTrgAltDvc = hasDetachedStyle(targetAltDevice) && targetAltDevice.getStyle();
  42628. style = valueTargetAlt || valueTrgAltDvc || {};
  42629. }
  42630. }
  42631. resultValue = style;
  42632. layersObj = layers.getLayersFromStyle(style);
  42633. } else {
  42634. var valueTrg = this.getTargetValue({
  42635. ignoreDefault: 1
  42636. });
  42637. var value = valueTrg; // Try to check if the style is in another rule
  42638. if (!value && valueComput) {
  42639. // Styles of the same target but with a higher rule
  42640. targetAltDevice = this._getParentTarget(target);
  42641. if (targetAltDevice) {
  42642. value = targetAltDevice.getStyle()[property];
  42643. } else {
  42644. // Computed value is not always reliable due to the browser's CSSOM parser
  42645. // here we try to look for the style in class rules
  42646. targetAlt = this._getClassRule();
  42647. valueTargetAlt = targetAlt && targetAlt.getStyle()[property];
  42648. targetAltDevice = !valueTargetAlt && this._getParentTarget(this._getClassRule({
  42649. skipAdd: 0
  42650. }));
  42651. valueTrgAltDvc = targetAltDevice && targetAltDevice.getStyle()[property];
  42652. value = valueTargetAlt || valueTrgAltDvc || valueComput;
  42653. }
  42654. }
  42655. value = value == model.getDefaultValue() ? '' : value;
  42656. resultValue = value;
  42657. layersObj = layers.getLayersFromValue(value);
  42658. }
  42659. var toAdd = model.getLayersFromTarget(target, {
  42660. resultValue: resultValue,
  42661. layersObj: layersObj
  42662. }) || layersObj;
  42663. layers.reset(null, updateOpts);
  42664. layers.add(toAdd, updateOpts);
  42665. model.set({
  42666. stackIndex: null
  42667. }, {
  42668. silent: true
  42669. });
  42670. },
  42671. getTargetValue: function getTargetValue() {
  42672. var opts = arguments.length > 0 && arguments[0] !== undefined ? arguments[0] : {};
  42673. var model = this.model;
  42674. var detached = model.attributes.detached;
  42675. var target = this.getTarget();
  42676. var result = _PropertyCompositeView__WEBPACK_IMPORTED_MODULE_2__["default"].prototype.getTargetValue.call(this, opts); // It might happen that the browser split properties on CSSOM parse
  42677. if (Object(underscore__WEBPACK_IMPORTED_MODULE_1__["isUndefined"])(result) && !detached) {
  42678. result = model.getValueFromStyle(target.getStyle());
  42679. } else if (detached) {
  42680. result = model.getValueFromTarget(target);
  42681. }
  42682. return result;
  42683. },
  42684. getPropsConfig: function getPropsConfig() {
  42685. var self = this;
  42686. var model = self.model;
  42687. return {
  42688. target: self.target,
  42689. propTarget: self.propTarget,
  42690. // Things to do when a single sub-property is changed
  42691. onChange: function onChange(el, view, opt) {
  42692. var subModel = view.model;
  42693. if (model.get('detached')) {
  42694. var subProp = subModel.get('property');
  42695. var defVal = subModel.getDefaultValue();
  42696. var values = self.getLayers().getPropertyValues(subProp, defVal);
  42697. view.updateTargetStyle(values, null, opt);
  42698. } else {
  42699. // Update only if there is an actual update (to avoid changes for computed styles)
  42700. // ps: status is calculated in `targetUpdated` method
  42701. if (model.get('status') == 'updated') {
  42702. var value = model.getFullValue();
  42703. model.set('value', value, opt); // Try to remove detached properties
  42704. !value && view.updateTargetStyle(value, null, opt);
  42705. }
  42706. }
  42707. }
  42708. };
  42709. },
  42710. onRender: function onRender() {
  42711. var el = this.el,
  42712. layers = this.layers,
  42713. propsView = this.propsView;
  42714. var fieldEl = el.querySelector('[data-layers-wrapper]');
  42715. propsView.render(); // Will use it to propogate changes
  42716. fieldEl.appendChild(layers.render().el);
  42717. }
  42718. }));
  42719. /***/ }),
  42720. /***/ "./src/style_manager/view/PropertyView.js":
  42721. /*!************************************************!*\
  42722. !*** ./src/style_manager/view/PropertyView.js ***!
  42723. \************************************************/
  42724. /*! exports provided: default */
  42725. /***/ (function(module, __webpack_exports__, __webpack_require__) {
  42726. "use strict";
  42727. __webpack_require__.r(__webpack_exports__);
  42728. /* harmony import */ var _babel_runtime_helpers_objectWithoutProperties__WEBPACK_IMPORTED_MODULE_0__ = __webpack_require__(/*! @babel/runtime/helpers/objectWithoutProperties */ "./node_modules/@babel/runtime/helpers/objectWithoutProperties.js");
  42729. /* harmony import */ var _babel_runtime_helpers_objectWithoutProperties__WEBPACK_IMPORTED_MODULE_0___default = /*#__PURE__*/__webpack_require__.n(_babel_runtime_helpers_objectWithoutProperties__WEBPACK_IMPORTED_MODULE_0__);
  42730. /* harmony import */ var _babel_runtime_helpers_defineProperty__WEBPACK_IMPORTED_MODULE_1__ = __webpack_require__(/*! @babel/runtime/helpers/defineProperty */ "./node_modules/@babel/runtime/helpers/defineProperty.js");
  42731. /* harmony import */ var _babel_runtime_helpers_defineProperty__WEBPACK_IMPORTED_MODULE_1___default = /*#__PURE__*/__webpack_require__.n(_babel_runtime_helpers_defineProperty__WEBPACK_IMPORTED_MODULE_1__);
  42732. /* harmony import */ var backbone__WEBPACK_IMPORTED_MODULE_2__ = __webpack_require__(/*! backbone */ "./node_modules/backbone/backbone.js");
  42733. /* harmony import */ var backbone__WEBPACK_IMPORTED_MODULE_2___default = /*#__PURE__*/__webpack_require__.n(backbone__WEBPACK_IMPORTED_MODULE_2__);
  42734. /* harmony import */ var underscore__WEBPACK_IMPORTED_MODULE_3__ = __webpack_require__(/*! underscore */ "./node_modules/underscore/underscore.js");
  42735. /* harmony import */ var underscore__WEBPACK_IMPORTED_MODULE_3___default = /*#__PURE__*/__webpack_require__.n(underscore__WEBPACK_IMPORTED_MODULE_3__);
  42736. /* harmony import */ var utils_mixins__WEBPACK_IMPORTED_MODULE_4__ = __webpack_require__(/*! utils/mixins */ "./src/utils/mixins.js");
  42737. function ownKeys(object, enumerableOnly) { var keys = Object.keys(object); if (Object.getOwnPropertySymbols) { var symbols = Object.getOwnPropertySymbols(object); if (enumerableOnly) symbols = symbols.filter(function (sym) { return Object.getOwnPropertyDescriptor(object, sym).enumerable; }); keys.push.apply(keys, symbols); } return keys; }
  42738. function _objectSpread(target) { for (var i = 1; i < arguments.length; i++) { var source = arguments[i] != null ? arguments[i] : {}; if (i % 2) { ownKeys(source, true).forEach(function (key) { _babel_runtime_helpers_defineProperty__WEBPACK_IMPORTED_MODULE_1___default()(target, key, source[key]); }); } else if (Object.getOwnPropertyDescriptors) { Object.defineProperties(target, Object.getOwnPropertyDescriptors(source)); } else { ownKeys(source).forEach(function (key) { Object.defineProperty(target, key, Object.getOwnPropertyDescriptor(source, key)); }); } } return target; }
  42739. var clearProp = 'data-clear-style';
  42740. /* harmony default export */ __webpack_exports__["default"] = (backbone__WEBPACK_IMPORTED_MODULE_2___default.a.View.extend({
  42741. template: function template(model) {
  42742. var pfx = this.pfx;
  42743. return "\n <div class=\"".concat(pfx, "label\">\n ").concat(this.templateLabel(model), "\n </div>\n <div class=\"").concat(this.ppfx, "fields\">\n ").concat(this.templateInput(model), "\n </div>\n ");
  42744. },
  42745. templateLabel: function templateLabel(model) {
  42746. var pfx = this.pfx,
  42747. em = this.em;
  42748. var parent = model.parent;
  42749. var _model$attributes = model.attributes,
  42750. _model$attributes$ico = _model$attributes.icon,
  42751. icon = _model$attributes$ico === void 0 ? '' : _model$attributes$ico,
  42752. _model$attributes$inf = _model$attributes.info,
  42753. info = _model$attributes$inf === void 0 ? '' : _model$attributes$inf,
  42754. id = _model$attributes.id,
  42755. name = _model$attributes.name;
  42756. var label = em && em.t("styleManager.properties.".concat(id)) || name;
  42757. return "\n <span class=\"".concat(pfx, "icon ").concat(icon, "\" title=\"").concat(info, "\">\n ").concat(label, "\n </span>\n ").concat(!parent ? "<b class=\"".concat(pfx, "clear\" ").concat(clearProp, ">&Cross;</b>") : '', "\n ");
  42758. },
  42759. templateInput: function templateInput(model) {
  42760. return "\n <div class=\"".concat(this.ppfx, "field\">\n <input placeholder=\"").concat(model.getDefaultValue(), "\"/>\n </div>\n ");
  42761. },
  42762. events: _babel_runtime_helpers_defineProperty__WEBPACK_IMPORTED_MODULE_1___default()({
  42763. change: 'inputValueChanged'
  42764. }, "click [".concat(clearProp, "]"), 'clear'),
  42765. initialize: function initialize() {
  42766. var _this = this;
  42767. var o = arguments.length > 0 && arguments[0] !== undefined ? arguments[0] : {};
  42768. Object(underscore__WEBPACK_IMPORTED_MODULE_3__["bindAll"])(this, 'targetUpdated');
  42769. this.config = o.config || {};
  42770. var em = this.config.em;
  42771. this.em = em;
  42772. this.pfx = this.config.stylePrefix || '';
  42773. this.ppfx = this.config.pStylePrefix || '';
  42774. this.target = o.target || {};
  42775. this.propTarget = o.propTarget || {};
  42776. this.onChange = o.onChange;
  42777. this.onInputRender = o.onInputRender || {};
  42778. this.customValue = o.customValue || {};
  42779. var model = this.model;
  42780. this.property = model.get('property');
  42781. this.input = null;
  42782. var pfx = this.pfx;
  42783. this.inputHolderId = '#' + pfx + 'input-holder';
  42784. this.sector = model.collection && model.collection.sector;
  42785. model.view = this;
  42786. if (!model.get('value')) {
  42787. model.set('value', model.getDefaultValue());
  42788. }
  42789. em && em.on("update:component:style:".concat(this.property), this.targetUpdated); //em && em.on(`styleable:change:${this.property}`, this.targetUpdated);
  42790. // Listening to changes of properties in this.requires, so that styleable
  42791. // changes based on other properties are propagated
  42792. var requires = model.get('requires');
  42793. requires && Object.keys(requires).forEach(function (property) {
  42794. em && em.on("component:styleUpdate:".concat(property), _this.targetUpdated);
  42795. });
  42796. this.listenTo(this.propTarget, 'update styleManager:update', this.targetUpdated);
  42797. this.listenTo(model, 'destroy remove', this.remove);
  42798. this.listenTo(model, 'change:value', this.modelValueChanged);
  42799. this.listenTo(model, 'targetUpdated', this.targetUpdated);
  42800. this.listenTo(model, 'change:visible', this.updateVisibility);
  42801. this.listenTo(model, 'change:status', this.updateStatus);
  42802. this.listenTo(model, 'change:name change:className change:full', this.render);
  42803. var init = this.init && this.init.bind(this);
  42804. init && init();
  42805. },
  42806. /**
  42807. * Triggers when the status changes. The status indicates if the value of
  42808. * the proprerty is changed or inherited
  42809. * @private
  42810. */
  42811. updateStatus: function updateStatus() {
  42812. var model = this.model;
  42813. var status = model.get('status');
  42814. var parent = model.parent;
  42815. var pfx = this.pfx;
  42816. var ppfx = this.ppfx;
  42817. var config = this.config;
  42818. var updatedCls = "".concat(ppfx, "four-color");
  42819. var computedCls = "".concat(ppfx, "color-warn");
  42820. var labelEl = this.$el.children(".".concat(pfx, "label"));
  42821. var clearStyleEl = this.getClearEl();
  42822. var clearStyle = clearStyleEl ? clearStyleEl.style : {};
  42823. labelEl.removeClass("".concat(updatedCls, " ").concat(computedCls));
  42824. clearStyle.display = 'none';
  42825. switch (status) {
  42826. case 'updated':
  42827. !parent && labelEl.addClass(updatedCls);
  42828. if (config.clearProperties) {
  42829. clearStyle.display = 'inline';
  42830. }
  42831. break;
  42832. case 'computed':
  42833. labelEl.addClass(computedCls);
  42834. break;
  42835. }
  42836. },
  42837. /**
  42838. * Clear the property from the target
  42839. */
  42840. clear: function clear(ev) {
  42841. var _this2 = this;
  42842. ev && ev.stopPropagation();
  42843. this.model.clearValue(); // Skip one stack with setTimeout to avoid inconsistencies (eg. visible on padding composite clear)
  42844. setTimeout(function () {
  42845. return _this2.targetUpdated();
  42846. });
  42847. },
  42848. /**
  42849. * Get clear element
  42850. * @return {HTMLElement}
  42851. */
  42852. getClearEl: function getClearEl() {
  42853. if (!this.clearEl) {
  42854. this.clearEl = this.el.querySelector("[".concat(clearProp, "]"));
  42855. }
  42856. return this.clearEl;
  42857. },
  42858. /**
  42859. * Returns selected target which should have 'style' property
  42860. * @return {Model|null}
  42861. */
  42862. getTarget: function getTarget() {
  42863. return this.getTargetModel();
  42864. },
  42865. getTargets: function getTargets() {
  42866. var targets = this.propTarget.targets;
  42867. return targets || [this.getTarget()];
  42868. },
  42869. /**
  42870. * Returns Styleable model
  42871. * @return {Model|null}
  42872. */
  42873. getTargetModel: function getTargetModel() {
  42874. return this.propTarget && this.propTarget.model;
  42875. },
  42876. /**
  42877. * Returns helper Styleable model
  42878. * @return {Model|null}
  42879. */
  42880. getHelperModel: function getHelperModel() {
  42881. return this.propTarget && this.propTarget.helper;
  42882. },
  42883. /**
  42884. * Triggers when the value of element input/s is changed, so have to update
  42885. * the value of the model which will propogate those changes to the target
  42886. */
  42887. inputValueChanged: function inputValueChanged(ev) {
  42888. ev && ev.stopPropagation();
  42889. this.model.setValueFromInput(this.getInputValue());
  42890. this.elementUpdated();
  42891. },
  42892. /**
  42893. * Fired when the element of the property is updated
  42894. */
  42895. elementUpdated: function elementUpdated() {
  42896. this.setStatus('updated');
  42897. },
  42898. setStatus: function setStatus(value) {
  42899. this.model.set('status', value);
  42900. var parent = this.model.parent;
  42901. parent && value == 'updated' && parent.set('status', value);
  42902. },
  42903. emitUpdateTarget: Object(underscore__WEBPACK_IMPORTED_MODULE_3__["debounce"])(function () {
  42904. var em = this.config.em;
  42905. em && em.trigger('styleManager:update:target', this.getTarget());
  42906. }),
  42907. _getTargetData: function _getTargetData() {
  42908. var model = this.model,
  42909. config = this.config;
  42910. var targetValue = this.getTargetValue({
  42911. ignoreDefault: 1
  42912. });
  42913. var defaultValue = model.getDefaultValue();
  42914. var computedValue = this.getComputedValue();
  42915. var value = '';
  42916. var status = '';
  42917. if (targetValue) {
  42918. value = targetValue;
  42919. if (config.highlightChanged) {
  42920. status = 'updated';
  42921. }
  42922. } else if (computedValue && config.showComputed && computedValue != defaultValue) {
  42923. value = computedValue;
  42924. if (config.highlightComputed) {
  42925. status = 'computed';
  42926. }
  42927. } else {
  42928. value = defaultValue;
  42929. status = '';
  42930. }
  42931. return {
  42932. value: value,
  42933. status: status,
  42934. targetValue: targetValue,
  42935. defaultValue: defaultValue,
  42936. computedValue: computedValue
  42937. };
  42938. },
  42939. /**
  42940. * Fired when the target is changed
  42941. * */
  42942. targetUpdated: function targetUpdated(mod, val) {
  42943. var opts = arguments.length > 2 && arguments[2] !== undefined ? arguments[2] : {};
  42944. this.emitUpdateTarget();
  42945. if (!this.checkVisibility()) {
  42946. return;
  42947. }
  42948. var config = this.config;
  42949. var em = config.em;
  42950. var model = this.model;
  42951. var property = model.get('property');
  42952. var _this$_getTargetData = this._getTargetData(),
  42953. status = _this$_getTargetData.status,
  42954. value = _this$_getTargetData.value,
  42955. targetData = _babel_runtime_helpers_objectWithoutProperties__WEBPACK_IMPORTED_MODULE_0___default()(_this$_getTargetData, ["status", "value"]);
  42956. var data = _objectSpread({
  42957. status: status,
  42958. value: value
  42959. }, targetData);
  42960. this.setStatus(status);
  42961. model.setValue(value, 0, _objectSpread({
  42962. fromTarget: 1
  42963. }, opts));
  42964. if (em) {
  42965. em.trigger('styleManager:change', this, property, value, data);
  42966. em.trigger("styleManager:change:".concat(property), this, value, data);
  42967. this._emitUpdate(data);
  42968. }
  42969. return data;
  42970. },
  42971. _emitUpdate: function _emitUpdate() {
  42972. var addData = arguments.length > 0 && arguments[0] !== undefined ? arguments[0] : {};
  42973. var em = this.em,
  42974. model = this.model;
  42975. if (!em) return;
  42976. var property = model.get('property');
  42977. var data = _objectSpread({}, this._getEventData(), {}, addData);
  42978. var id = data.id;
  42979. em.trigger('style:update', data);
  42980. em.trigger("style:update:".concat(property), data);
  42981. property !== id && em.trigger("style:update:".concat(id), data);
  42982. },
  42983. _getEventData: function _getEventData() {
  42984. var model = this.model;
  42985. return {
  42986. propertyView: this,
  42987. targets: this.getTargets(),
  42988. value: model.getFullValue(),
  42989. property: model,
  42990. id: model.get('id'),
  42991. name: model.get('property')
  42992. };
  42993. },
  42994. checkVisibility: function checkVisibility() {
  42995. var result = 1; // Check if need to hide the property
  42996. if (this.config.hideNotStylable) {
  42997. if (!this.isTargetStylable() || !this.isComponentStylable()) {
  42998. this.hide();
  42999. result = 0;
  43000. } else {
  43001. this.show();
  43002. } // Sector is not passed to Composite and Stack types
  43003. if (this.sector) {
  43004. this.sector.trigger('updateVisibility');
  43005. }
  43006. }
  43007. return result;
  43008. },
  43009. /**
  43010. * Get the value of this property from the target (eg, Component, CSSRule)
  43011. * @param {Object} [opts] Options
  43012. * @param {Boolean} [options.fetchFromFunction]
  43013. * @param {Boolean} [options.ignoreDefault]
  43014. * @return string
  43015. * @private
  43016. */
  43017. getTargetValue: function getTargetValue() {
  43018. var opts = arguments.length > 0 && arguments[0] !== undefined ? arguments[0] : {};
  43019. var result;
  43020. var model = this.model;
  43021. var target = this.getTargetModel();
  43022. var customFetchValue = this.customValue;
  43023. if (!target) {
  43024. return result;
  43025. }
  43026. result = target.getStyle()[model.get('property')];
  43027. if (!result && !opts.ignoreDefault) {
  43028. result = model.getDefaultValue();
  43029. }
  43030. if (typeof customFetchValue == 'function' && !opts.ignoreCustomValue) {
  43031. var index = model.collection.indexOf(model);
  43032. var customValue = customFetchValue(this, index, result);
  43033. if (customValue) {
  43034. result = customValue;
  43035. }
  43036. }
  43037. return result;
  43038. },
  43039. /**
  43040. * Returns computed value
  43041. * @return {String}
  43042. * @private
  43043. */
  43044. getComputedValue: function getComputedValue() {
  43045. var target = this.propTarget;
  43046. var computed = target.computed || {};
  43047. var computedDef = target.computedDefault || {};
  43048. var avoid = this.config.avoidComputed || [];
  43049. var property = this.model.get('property');
  43050. var notToSkip = avoid.indexOf(property) < 0;
  43051. var value = computed[property];
  43052. var valueDef = computedDef[Object(utils_mixins__WEBPACK_IMPORTED_MODULE_4__["camelCase"])(property)];
  43053. return computed && notToSkip && valueDef !== value && value || '';
  43054. },
  43055. /**
  43056. * Returns value from input
  43057. * @return {string}
  43058. */
  43059. getInputValue: function getInputValue() {
  43060. var input = this.getInputEl();
  43061. return input ? input.value : '';
  43062. },
  43063. /**
  43064. * Triggers when the `value` of the model changes, so the target and
  43065. * the input element should be updated
  43066. * @param {Object} e Event
  43067. * @param {Mixed} val Value
  43068. * @param {Object} opt Options
  43069. * */
  43070. modelValueChanged: function modelValueChanged(e, val) {
  43071. var _this3 = this;
  43072. var opt = arguments.length > 2 && arguments[2] !== undefined ? arguments[2] : {};
  43073. var model = this.model;
  43074. var value = model.getFullValue(); // Avoid element update if the change comes from it
  43075. if (!opt.fromInput) {
  43076. this.setValue(value);
  43077. } // Avoid target update if the changes comes from it
  43078. if (!opt.fromTarget) {
  43079. this.getTargets().forEach(function (target) {
  43080. return _this3.__updateTarget(target, opt);
  43081. });
  43082. }
  43083. },
  43084. __updateTarget: function __updateTarget(target) {
  43085. var opt = arguments.length > 1 && arguments[1] !== undefined ? arguments[1] : {};
  43086. var model = this.model;
  43087. var em = this.config.em;
  43088. var prop = model.get('property');
  43089. var value = model.getFullValue();
  43090. var onChange = this.onChange; // Check if component is allowed to be styled
  43091. if (!target || !this.isTargetStylable(target) || !this.isComponentStylable()) {
  43092. return;
  43093. } // Avoid target update if the changes comes from it
  43094. if (!opt.fromTarget) {
  43095. // The onChange is used by Composite/Stack properties, so I'd avoid sending
  43096. // it back if the change comes from one of those
  43097. if (onChange && !opt.fromParent) {
  43098. onChange(target, this, opt);
  43099. } else {
  43100. this.updateTargetStyle(value, null, _objectSpread({}, opt, {
  43101. target: target
  43102. }));
  43103. }
  43104. } // TODO: use target if componentFirst
  43105. var component = em && em.getSelected();
  43106. if (em && component) {
  43107. !opt.noEmit && em.trigger('component:update', component);
  43108. em.trigger('component:styleUpdate', component, prop);
  43109. em.trigger("component:styleUpdate:".concat(prop), component);
  43110. }
  43111. this._emitUpdate();
  43112. },
  43113. /**
  43114. * Update target style
  43115. * @param {string} value
  43116. * @param {string} name
  43117. * @param {Object} opts
  43118. */
  43119. updateTargetStyle: function updateTargetStyle(value) {
  43120. var name = arguments.length > 1 && arguments[1] !== undefined ? arguments[1] : '';
  43121. var opts = arguments.length > 2 && arguments[2] !== undefined ? arguments[2] : {};
  43122. var property = name || this.model.get('property');
  43123. var target = opts.target || this.getTarget();
  43124. var style = target.getStyle();
  43125. if (value) {
  43126. style[property] = value;
  43127. } else {
  43128. delete style[property];
  43129. } // Forces to trigger the change (for UndoManager)
  43130. if (opts.avoidStore) {
  43131. style.__ = 1;
  43132. } else {
  43133. delete style.__;
  43134. }
  43135. target.setStyle(style, opts); // Helper is used by `states` like ':hover' to show its preview
  43136. var helper = this.getHelperModel();
  43137. helper && helper.setStyle(style, opts);
  43138. },
  43139. /**
  43140. * Check if target is stylable with this property
  43141. * The target could be the Component as the CSS Rule
  43142. * @return {Boolean}
  43143. */
  43144. isTargetStylable: function isTargetStylable(target) {
  43145. var trg = target || this.getTarget();
  43146. var model = this.model;
  43147. var id = model.get('id');
  43148. var property = model.get('property');
  43149. var toRequire = model.get('toRequire');
  43150. var unstylable = trg.get('unstylable');
  43151. var stylableReq = trg.get('stylable-require');
  43152. var requires = model.get('requires');
  43153. var requiresParent = model.get('requiresParent');
  43154. var sectors = this.sector ? this.sector.collection : null;
  43155. var selected = this.em ? this.em.getSelected() : null;
  43156. var stylable = trg.get('stylable'); // Stylable could also be an array indicating with which property
  43157. // the target could be styled
  43158. if (Object(underscore__WEBPACK_IMPORTED_MODULE_3__["isArray"])(stylable)) {
  43159. stylable = stylable.indexOf(property) >= 0;
  43160. } // Check if the property was signed as unstylable
  43161. if (Object(underscore__WEBPACK_IMPORTED_MODULE_3__["isArray"])(unstylable)) {
  43162. stylable = unstylable.indexOf(property) < 0;
  43163. } // Check if the property is available only if requested
  43164. if (toRequire) {
  43165. stylable = !target || stylableReq && (stylableReq.indexOf(id) >= 0 || stylableReq.indexOf(property) >= 0);
  43166. } // Check if the property is available based on other property's values
  43167. if (sectors && requires) {
  43168. var properties = Object.keys(requires);
  43169. sectors.each(function (sector) {
  43170. sector.get('properties').each(function (model) {
  43171. if (Object(underscore__WEBPACK_IMPORTED_MODULE_3__["includes"])(properties, model.id)) {
  43172. var values = requires[model.id];
  43173. stylable = stylable && Object(underscore__WEBPACK_IMPORTED_MODULE_3__["includes"])(values, model.get('value'));
  43174. }
  43175. });
  43176. });
  43177. } // Check if the property is available based on parent's property values
  43178. if (requiresParent) {
  43179. var parent = selected && selected.parent();
  43180. var parentEl = parent && parent.getEl();
  43181. if (parentEl) {
  43182. var styles = window.getComputedStyle(parentEl);
  43183. Object(underscore__WEBPACK_IMPORTED_MODULE_3__["each"])(requiresParent, function (values, property) {
  43184. stylable = stylable && styles[property] && Object(underscore__WEBPACK_IMPORTED_MODULE_3__["includes"])(values, styles[property]);
  43185. });
  43186. } else {
  43187. stylable = false;
  43188. }
  43189. }
  43190. return stylable;
  43191. },
  43192. /**
  43193. * Check if the selected component is stylable with this property
  43194. * The target could be the Component as the CSS Rule
  43195. * @return {Boolean}
  43196. */
  43197. isComponentStylable: function isComponentStylable() {
  43198. var em = this.em;
  43199. var component = em && em.getSelected();
  43200. if (!component) {
  43201. return true;
  43202. }
  43203. return this.isTargetStylable(component);
  43204. },
  43205. /**
  43206. * Passed a raw value you have to update the input element, generally
  43207. * is the value fetched from targets, so you can receive values with
  43208. * functions, units, etc. (eg. `rotateY(45deg)`)
  43209. * get also
  43210. * @param {string} value
  43211. * @private
  43212. */
  43213. setRawValue: function setRawValue(value) {
  43214. this.setValue(this.model.parseValue(value));
  43215. },
  43216. /**
  43217. * Update the element input.
  43218. * Usually the value is a result of `model.getFullValue()`
  43219. * @param {String} value The value from the model
  43220. * */
  43221. setValue: function setValue(value) {
  43222. var model = this.model;
  43223. var val = Object(underscore__WEBPACK_IMPORTED_MODULE_3__["isUndefined"])(value) ? model.getDefaultValue() : value;
  43224. var input = this.getInputEl();
  43225. input && (input.value = val);
  43226. },
  43227. getInputEl: function getInputEl() {
  43228. if (!this.input) {
  43229. this.input = this.el.querySelector('input');
  43230. }
  43231. return this.input;
  43232. },
  43233. updateVisibility: function updateVisibility() {
  43234. this.el.style.display = this.model.get('visible') ? 'block' : 'none';
  43235. },
  43236. show: function show() {
  43237. this.model.set('visible', 1);
  43238. },
  43239. hide: function hide() {
  43240. this.model.set('visible', 0);
  43241. },
  43242. /**
  43243. * Clean input
  43244. * */
  43245. cleanValue: function cleanValue() {
  43246. this.setValue('');
  43247. },
  43248. clearCached: function clearCached() {
  43249. this.clearEl = null;
  43250. this.input = null;
  43251. this.$input = null;
  43252. },
  43253. render: function render() {
  43254. this.clearCached();
  43255. var pfx = this.pfx;
  43256. var model = this.model;
  43257. var el = this.el;
  43258. var property = model.get('property');
  43259. var full = model.get('full');
  43260. var cls = model.get('className') || '';
  43261. var className = "".concat(pfx, "property");
  43262. el.innerHTML = this.template(model);
  43263. el.className = "".concat(className, " ").concat(pfx).concat(model.get('type'), " ").concat(className, "__").concat(property, " ").concat(cls).trim();
  43264. el.className += full ? " ".concat(className, "--full") : '';
  43265. this.updateStatus();
  43266. var onRender = this.onRender && this.onRender.bind(this);
  43267. onRender && onRender();
  43268. this.setValue(model.get('value'), {
  43269. fromTarget: 1
  43270. });
  43271. }
  43272. }));
  43273. /***/ }),
  43274. /***/ "./src/style_manager/view/SectorView.js":
  43275. /*!**********************************************!*\
  43276. !*** ./src/style_manager/view/SectorView.js ***!
  43277. \**********************************************/
  43278. /*! exports provided: default */
  43279. /***/ (function(module, __webpack_exports__, __webpack_require__) {
  43280. "use strict";
  43281. __webpack_require__.r(__webpack_exports__);
  43282. /* harmony import */ var backbone__WEBPACK_IMPORTED_MODULE_0__ = __webpack_require__(/*! backbone */ "./node_modules/backbone/backbone.js");
  43283. /* harmony import */ var backbone__WEBPACK_IMPORTED_MODULE_0___default = /*#__PURE__*/__webpack_require__.n(backbone__WEBPACK_IMPORTED_MODULE_0__);
  43284. /* harmony import */ var underscore__WEBPACK_IMPORTED_MODULE_1__ = __webpack_require__(/*! underscore */ "./node_modules/underscore/underscore.js");
  43285. /* harmony import */ var underscore__WEBPACK_IMPORTED_MODULE_1___default = /*#__PURE__*/__webpack_require__.n(underscore__WEBPACK_IMPORTED_MODULE_1__);
  43286. /* harmony import */ var _PropertiesView__WEBPACK_IMPORTED_MODULE_2__ = __webpack_require__(/*! ./PropertiesView */ "./src/style_manager/view/PropertiesView.js");
  43287. /* harmony default export */ __webpack_exports__["default"] = (backbone__WEBPACK_IMPORTED_MODULE_0___default.a.View.extend({
  43288. template: Object(underscore__WEBPACK_IMPORTED_MODULE_1__["template"])("\n <div class=\"<%= pfx %>title\" data-sector-title>\n <i id=\"<%= pfx %>caret\" class=\"fa\"></i>\n <%= label %>\n </div>"),
  43289. events: {
  43290. 'click [data-sector-title]': 'toggle'
  43291. },
  43292. initialize: function initialize(o) {
  43293. this.config = o.config || {};
  43294. this.em = this.config.em;
  43295. this.pfx = this.config.stylePrefix || '';
  43296. this.target = o.target || {};
  43297. this.propTarget = o.propTarget || {};
  43298. this.caretR = 'fa-caret-right';
  43299. this.caretD = 'fa-caret-down';
  43300. var model = this.model;
  43301. this.listenTo(model, 'change:open', this.updateOpen);
  43302. this.listenTo(model, 'updateVisibility', this.updateVisibility);
  43303. this.listenTo(model, 'destroy remove', this.remove);
  43304. },
  43305. /**
  43306. * If all properties are hidden this will hide the sector
  43307. */
  43308. updateVisibility: function updateVisibility() {
  43309. var show;
  43310. this.model.get('properties').each(function (prop) {
  43311. if (prop.get('visible')) {
  43312. show = 1;
  43313. }
  43314. });
  43315. this.el.style.display = show ? 'block' : 'none';
  43316. },
  43317. /**
  43318. * Update visibility
  43319. */
  43320. updateOpen: function updateOpen() {
  43321. if (this.model.get('open')) this.show();else this.hide();
  43322. },
  43323. /**
  43324. * Show the content of the sector
  43325. * */
  43326. show: function show() {
  43327. this.$el.addClass(this.pfx + 'open');
  43328. this.getPropertiesEl().style.display = '';
  43329. this.$caret.removeClass(this.caretR).addClass(this.caretD);
  43330. },
  43331. /**
  43332. * Hide the content of the sector
  43333. * */
  43334. hide: function hide() {
  43335. this.$el.removeClass(this.pfx + 'open');
  43336. this.getPropertiesEl().style.display = 'none';
  43337. this.$caret.removeClass(this.caretD).addClass(this.caretR);
  43338. },
  43339. getPropertiesEl: function getPropertiesEl() {
  43340. return this.$el.find(".".concat(this.pfx, "properties")).get(0);
  43341. },
  43342. /**
  43343. * Toggle visibility
  43344. * */
  43345. toggle: function toggle(e) {
  43346. var v = this.model.get('open') ? 0 : 1;
  43347. this.model.set('open', v);
  43348. },
  43349. render: function render() {
  43350. var pfx = this.pfx,
  43351. model = this.model,
  43352. em = this.em,
  43353. $el = this.$el;
  43354. var _model$attributes = model.attributes,
  43355. id = _model$attributes.id,
  43356. name = _model$attributes.name;
  43357. var label = em && em.t("styleManager.sectors.".concat(id)) || name;
  43358. $el.html(this.template({
  43359. pfx: pfx,
  43360. label: label
  43361. }));
  43362. this.$caret = $el.find("#".concat(pfx, "caret"));
  43363. this.renderProperties();
  43364. $el.attr('class', "".concat(pfx, "sector ").concat(pfx, "sector__").concat(id, " no-select"));
  43365. this.updateOpen();
  43366. return this;
  43367. },
  43368. renderProperties: function renderProperties() {
  43369. var objs = this.model.get('properties');
  43370. if (objs) {
  43371. var view = new _PropertiesView__WEBPACK_IMPORTED_MODULE_2__["default"]({
  43372. collection: objs,
  43373. target: this.target,
  43374. propTarget: this.propTarget,
  43375. config: this.config
  43376. });
  43377. this.$el.append(view.render().el);
  43378. }
  43379. }
  43380. }));
  43381. /***/ }),
  43382. /***/ "./src/style_manager/view/SectorsView.js":
  43383. /*!***********************************************!*\
  43384. !*** ./src/style_manager/view/SectorsView.js ***!
  43385. \***********************************************/
  43386. /*! exports provided: default */
  43387. /***/ (function(module, __webpack_exports__, __webpack_require__) {
  43388. "use strict";
  43389. __webpack_require__.r(__webpack_exports__);
  43390. /* harmony import */ var _babel_runtime_helpers_defineProperty__WEBPACK_IMPORTED_MODULE_0__ = __webpack_require__(/*! @babel/runtime/helpers/defineProperty */ "./node_modules/@babel/runtime/helpers/defineProperty.js");
  43391. /* harmony import */ var _babel_runtime_helpers_defineProperty__WEBPACK_IMPORTED_MODULE_0___default = /*#__PURE__*/__webpack_require__.n(_babel_runtime_helpers_defineProperty__WEBPACK_IMPORTED_MODULE_0__);
  43392. /* harmony import */ var backbone__WEBPACK_IMPORTED_MODULE_1__ = __webpack_require__(/*! backbone */ "./node_modules/backbone/backbone.js");
  43393. /* harmony import */ var backbone__WEBPACK_IMPORTED_MODULE_1___default = /*#__PURE__*/__webpack_require__.n(backbone__WEBPACK_IMPORTED_MODULE_1__);
  43394. /* harmony import */ var underscore__WEBPACK_IMPORTED_MODULE_2__ = __webpack_require__(/*! underscore */ "./node_modules/underscore/underscore.js");
  43395. /* harmony import */ var underscore__WEBPACK_IMPORTED_MODULE_2___default = /*#__PURE__*/__webpack_require__.n(underscore__WEBPACK_IMPORTED_MODULE_2__);
  43396. /* harmony import */ var utils_mixins__WEBPACK_IMPORTED_MODULE_3__ = __webpack_require__(/*! utils/mixins */ "./src/utils/mixins.js");
  43397. /* harmony import */ var utils_dom__WEBPACK_IMPORTED_MODULE_4__ = __webpack_require__(/*! utils/dom */ "./src/utils/dom.js");
  43398. /* harmony import */ var _SectorView__WEBPACK_IMPORTED_MODULE_5__ = __webpack_require__(/*! ./SectorView */ "./src/style_manager/view/SectorView.js");
  43399. function ownKeys(object, enumerableOnly) { var keys = Object.keys(object); if (Object.getOwnPropertySymbols) { var symbols = Object.getOwnPropertySymbols(object); if (enumerableOnly) symbols = symbols.filter(function (sym) { return Object.getOwnPropertyDescriptor(object, sym).enumerable; }); keys.push.apply(keys, symbols); } return keys; }
  43400. function _objectSpread(target) { for (var i = 1; i < arguments.length; i++) { var source = arguments[i] != null ? arguments[i] : {}; if (i % 2) { ownKeys(source, true).forEach(function (key) { _babel_runtime_helpers_defineProperty__WEBPACK_IMPORTED_MODULE_0___default()(target, key, source[key]); }); } else if (Object.getOwnPropertyDescriptors) { Object.defineProperties(target, Object.getOwnPropertyDescriptors(source)); } else { ownKeys(source).forEach(function (key) { Object.defineProperty(target, key, Object.getOwnPropertyDescriptor(source, key)); }); } } return target; }
  43401. var helperCls = 'hc-state';
  43402. /* harmony default export */ __webpack_exports__["default"] = (backbone__WEBPACK_IMPORTED_MODULE_1___default.a.View.extend({
  43403. initialize: function initialize() {
  43404. var o = arguments.length > 0 && arguments[0] !== undefined ? arguments[0] : {};
  43405. var config = o.config || {};
  43406. this.pfx = config.stylePrefix || '';
  43407. this.ppfx = config.pStylePrefix || '';
  43408. this.target = o.target || {};
  43409. this.config = config; // The target that will emit events for properties
  43410. var target = {};
  43411. Object(underscore__WEBPACK_IMPORTED_MODULE_2__["extend"])(target, backbone__WEBPACK_IMPORTED_MODULE_1___default.a.Events);
  43412. var body = document.body;
  43413. var dummy = document.createElement("el-".concat(new Date().getTime()));
  43414. body.appendChild(dummy);
  43415. target.computedDefault = _objectSpread({}, window.getComputedStyle(dummy));
  43416. body.removeChild(dummy);
  43417. this.propTarget = target;
  43418. var coll = this.collection;
  43419. var events = 'component:toggled component:update:classes change:state change:device frame:resized';
  43420. this.listenTo(coll, 'add', this.addTo);
  43421. this.listenTo(coll, 'reset', this.render);
  43422. this.listenTo(this.target, events, this.targetUpdated);
  43423. },
  43424. /**
  43425. * Add to collection
  43426. * @param {Object} model Model
  43427. * @return {Object}
  43428. * @private
  43429. * */
  43430. addTo: function addTo(model, coll) {
  43431. var opts = arguments.length > 2 && arguments[2] !== undefined ? arguments[2] : {};
  43432. this.addToCollection(model, null, opts);
  43433. },
  43434. toggleStateCls: function toggleStateCls() {
  43435. var targets = arguments.length > 0 && arguments[0] !== undefined ? arguments[0] : [];
  43436. var enable = arguments.length > 1 ? arguments[1] : undefined;
  43437. targets.forEach(function (trg) {
  43438. var el = trg.getEl();
  43439. el && el.classList && el.classList[enable ? 'add' : 'remove'](helperCls);
  43440. });
  43441. },
  43442. /**
  43443. * Fired when target is updated
  43444. * @private
  43445. */
  43446. targetUpdated: function targetUpdated(trg) {
  43447. var em = this.target;
  43448. var pt = this.propTarget;
  43449. var targets = em.getSelectedAll();
  43450. var model = em.getSelected();
  43451. var mdToClear = trg && !!trg.toHTML ? trg : model; // Clean components
  43452. mdToClear && this.toggleStateCls([mdToClear]);
  43453. if (!model) return;
  43454. var config = em.get('Config');
  43455. var state = !config.devicePreviewMode ? em.get('state') : '';
  43456. var _em$get$getConfig = em.get('SelectorManager').getConfig(),
  43457. componentFirst = _em$get$getConfig.componentFirst;
  43458. var el = model.getEl();
  43459. pt.helper = null;
  43460. pt.targets = null; // Create computed style container
  43461. if (el && Object(utils_mixins__WEBPACK_IMPORTED_MODULE_3__["isTaggableNode"])(el)) {
  43462. var stateStr = state ? ":".concat(state) : null;
  43463. pt.computed = window.getComputedStyle(el, stateStr);
  43464. } // Create a new rule for the state as a helper
  43465. var appendStateRule = function appendStateRule() {
  43466. var style = arguments.length > 0 && arguments[0] !== undefined ? arguments[0] : {};
  43467. var cc = em.get('CssComposer');
  43468. var rules = cc.getAll();
  43469. var helperRule = cc.getClassRule(helperCls);
  43470. if (!helperRule) {
  43471. helperRule = cc.setClassRule(helperCls);
  43472. } else {
  43473. // I will make it last again, otherwise it could be overridden
  43474. rules.remove(helperRule);
  43475. rules.add(helperRule);
  43476. }
  43477. helperRule.set('important', 1);
  43478. helperRule.setStyle(style);
  43479. pt.helper = helperRule;
  43480. };
  43481. model = em.get('StyleManager').getModelToStyle(model);
  43482. if (state) {
  43483. appendStateRule(model.getStyle());
  43484. this.toggleStateCls(targets, 1);
  43485. }
  43486. pt.model = model;
  43487. if (componentFirst) pt.targets = targets;
  43488. pt.trigger('update');
  43489. },
  43490. /**
  43491. * Select different target for the Style Manager.
  43492. * It could be a Component, CSSRule, or a string of any CSS selector
  43493. * @param {Component|CSSRule|String|Array<Component|CSSRule|String>} target
  43494. * @return {Array<Styleable>} Array of Components/CSSRules
  43495. */
  43496. setTarget: function setTarget(target) {
  43497. var opts = arguments.length > 1 && arguments[1] !== undefined ? arguments[1] : {};
  43498. var em = this.target;
  43499. var trgs = Object(underscore__WEBPACK_IMPORTED_MODULE_2__["isArray"])(target) ? target : [target];
  43500. var targetIsClass = opts.targetIsClass,
  43501. stylable = opts.stylable;
  43502. var models = [];
  43503. trgs.forEach(function (target) {
  43504. var model = target;
  43505. if (Object(underscore__WEBPACK_IMPORTED_MODULE_2__["isString"])(target)) {
  43506. var rule;
  43507. var rules = em.get('CssComposer').getAll();
  43508. if (targetIsClass) {
  43509. rule = rules.filter(function (rule) {
  43510. return rule.get('selectors').getFullString() === target;
  43511. })[0];
  43512. }
  43513. if (!rule) {
  43514. rule = rules.filter(function (rule) {
  43515. return rule.get('selectorsAdd') === target;
  43516. })[0];
  43517. }
  43518. if (!rule) {
  43519. rule = rules.add({
  43520. selectors: [],
  43521. selectorsAdd: target
  43522. });
  43523. }
  43524. stylable && rule.set({
  43525. stylable: stylable
  43526. });
  43527. model = rule;
  43528. }
  43529. models.push(model);
  43530. });
  43531. var pt = this.propTarget;
  43532. pt.targets = models;
  43533. pt.trigger('update');
  43534. return models;
  43535. },
  43536. /**
  43537. * Add new object to collection
  43538. * @param {Object} model Model
  43539. * @param {Object} fragmentEl collection
  43540. * @return {Object} Object created
  43541. * @private
  43542. * */
  43543. addToCollection: function addToCollection(model, fragmentEl) {
  43544. var opts = arguments.length > 2 && arguments[2] !== undefined ? arguments[2] : {};
  43545. var pfx = this.pfx,
  43546. target = this.target,
  43547. propTarget = this.propTarget,
  43548. config = this.config,
  43549. el = this.el;
  43550. var appendTo = fragmentEl || el;
  43551. var rendered = new _SectorView__WEBPACK_IMPORTED_MODULE_5__["default"]({
  43552. model: model,
  43553. id: "".concat(pfx).concat(model.get('id')),
  43554. name: model.get('name'),
  43555. properties: model.get('properties'),
  43556. target: target,
  43557. propTarget: propTarget,
  43558. config: config
  43559. }).render().el;
  43560. Object(utils_dom__WEBPACK_IMPORTED_MODULE_4__["appendAtIndex"])(appendTo, rendered, opts.at);
  43561. return rendered;
  43562. },
  43563. render: function render() {
  43564. var _this = this;
  43565. var frag = document.createDocumentFragment();
  43566. var $el = this.$el;
  43567. var pfx = this.pfx;
  43568. var ppfx = this.ppfx;
  43569. $el.empty();
  43570. this.collection.each(function (model) {
  43571. return _this.addToCollection(model, frag);
  43572. });
  43573. $el.append(frag);
  43574. $el.addClass("".concat(pfx, "sectors ").concat(ppfx, "one-bg ").concat(ppfx, "two-color"));
  43575. return this;
  43576. }
  43577. }));
  43578. /***/ }),
  43579. /***/ "./src/trait_manager/config/config.js":
  43580. /*!********************************************!*\
  43581. !*** ./src/trait_manager/config/config.js ***!
  43582. \********************************************/
  43583. /*! exports provided: default */
  43584. /***/ (function(module, __webpack_exports__, __webpack_require__) {
  43585. "use strict";
  43586. __webpack_require__.r(__webpack_exports__);
  43587. /* harmony default export */ __webpack_exports__["default"] = ({
  43588. stylePrefix: 'trt-',
  43589. // Specify the element to use as a container, string (query) or HTMLElement
  43590. // With the empty value, nothing will be rendered
  43591. appendTo: '',
  43592. // Default options for the target input
  43593. optionsTarget: [{
  43594. value: false
  43595. }, {
  43596. value: '_blank'
  43597. }]
  43598. });
  43599. /***/ }),
  43600. /***/ "./src/trait_manager/index.js":
  43601. /*!************************************!*\
  43602. !*** ./src/trait_manager/index.js ***!
  43603. \************************************/
  43604. /*! exports provided: default */
  43605. /***/ (function(module, __webpack_exports__, __webpack_require__) {
  43606. "use strict";
  43607. __webpack_require__.r(__webpack_exports__);
  43608. /* harmony import */ var underscore__WEBPACK_IMPORTED_MODULE_0__ = __webpack_require__(/*! underscore */ "./node_modules/underscore/underscore.js");
  43609. /* harmony import */ var underscore__WEBPACK_IMPORTED_MODULE_0___default = /*#__PURE__*/__webpack_require__.n(underscore__WEBPACK_IMPORTED_MODULE_0__);
  43610. /* harmony import */ var _config_config__WEBPACK_IMPORTED_MODULE_1__ = __webpack_require__(/*! ./config/config */ "./src/trait_manager/config/config.js");
  43611. /* harmony import */ var _view_TraitsView__WEBPACK_IMPORTED_MODULE_2__ = __webpack_require__(/*! ./view/TraitsView */ "./src/trait_manager/view/TraitsView.js");
  43612. /* harmony default export */ __webpack_exports__["default"] = (function () {
  43613. var c = {};
  43614. var TraitsViewer;
  43615. return {
  43616. TraitsView: _view_TraitsView__WEBPACK_IMPORTED_MODULE_2__["default"],
  43617. /**
  43618. * Name of the module
  43619. * @type {String}
  43620. * @private
  43621. */
  43622. name: 'TraitManager',
  43623. /**
  43624. * Get configuration object
  43625. * @return {Object}
  43626. * @private
  43627. */
  43628. getConfig: function getConfig() {
  43629. return c;
  43630. },
  43631. /**
  43632. * Initialize module. Automatically called with a new instance of the editor
  43633. * @param {Object} config Configurations
  43634. */
  43635. init: function init() {
  43636. var config = arguments.length > 0 && arguments[0] !== undefined ? arguments[0] : {};
  43637. c = config;
  43638. Object(underscore__WEBPACK_IMPORTED_MODULE_0__["defaults"])(c, _config_config__WEBPACK_IMPORTED_MODULE_1__["default"]);
  43639. var ppfx = c.pStylePrefix;
  43640. ppfx && (c.stylePrefix = "".concat(ppfx).concat(c.stylePrefix));
  43641. TraitsViewer = new _view_TraitsView__WEBPACK_IMPORTED_MODULE_2__["default"]({
  43642. collection: [],
  43643. editor: c.em,
  43644. config: c
  43645. });
  43646. return this;
  43647. },
  43648. postRender: function postRender() {
  43649. var elTo = this.getConfig().appendTo;
  43650. if (elTo) {
  43651. var el = Object(underscore__WEBPACK_IMPORTED_MODULE_0__["isElement"])(elTo) ? elTo : document.querySelector(elTo);
  43652. el.appendChild(this.render());
  43653. }
  43654. },
  43655. /**
  43656. *
  43657. * Get Traits viewer
  43658. * @private
  43659. */
  43660. getTraitsViewer: function getTraitsViewer() {
  43661. return TraitsViewer;
  43662. },
  43663. /**
  43664. * Add new trait type
  43665. * @param {string} name Type name
  43666. * @param {Object} methods Object representing the trait
  43667. */
  43668. addType: function addType(name, trait) {
  43669. var itemView = TraitsViewer.itemView;
  43670. TraitsViewer.itemsView[name] = itemView.extend(trait);
  43671. },
  43672. /**
  43673. * Get trait type
  43674. * @param {string} name Type name
  43675. * @return {Object}
  43676. */
  43677. getType: function getType(name) {
  43678. return TraitsViewer.itemsView[name];
  43679. },
  43680. render: function render() {
  43681. return TraitsViewer.render().el;
  43682. }
  43683. };
  43684. });
  43685. /***/ }),
  43686. /***/ "./src/trait_manager/model/Trait.js":
  43687. /*!******************************************!*\
  43688. !*** ./src/trait_manager/model/Trait.js ***!
  43689. \******************************************/
  43690. /*! exports provided: default */
  43691. /***/ (function(module, __webpack_exports__, __webpack_require__) {
  43692. "use strict";
  43693. __webpack_require__.r(__webpack_exports__);
  43694. /* harmony import */ var _babel_runtime_helpers_defineProperty__WEBPACK_IMPORTED_MODULE_0__ = __webpack_require__(/*! @babel/runtime/helpers/defineProperty */ "./node_modules/@babel/runtime/helpers/defineProperty.js");
  43695. /* harmony import */ var _babel_runtime_helpers_defineProperty__WEBPACK_IMPORTED_MODULE_0___default = /*#__PURE__*/__webpack_require__.n(_babel_runtime_helpers_defineProperty__WEBPACK_IMPORTED_MODULE_0__);
  43696. /* harmony import */ var backbone__WEBPACK_IMPORTED_MODULE_1__ = __webpack_require__(/*! backbone */ "./node_modules/backbone/backbone.js");
  43697. /* harmony import */ var backbone__WEBPACK_IMPORTED_MODULE_1___default = /*#__PURE__*/__webpack_require__.n(backbone__WEBPACK_IMPORTED_MODULE_1__);
  43698. /* harmony import */ var underscore__WEBPACK_IMPORTED_MODULE_2__ = __webpack_require__(/*! underscore */ "./node_modules/underscore/underscore.js");
  43699. /* harmony import */ var underscore__WEBPACK_IMPORTED_MODULE_2___default = /*#__PURE__*/__webpack_require__.n(underscore__WEBPACK_IMPORTED_MODULE_2__);
  43700. function ownKeys(object, enumerableOnly) { var keys = Object.keys(object); if (Object.getOwnPropertySymbols) { var symbols = Object.getOwnPropertySymbols(object); if (enumerableOnly) symbols = symbols.filter(function (sym) { return Object.getOwnPropertyDescriptor(object, sym).enumerable; }); keys.push.apply(keys, symbols); } return keys; }
  43701. function _objectSpread(target) { for (var i = 1; i < arguments.length; i++) { var source = arguments[i] != null ? arguments[i] : {}; if (i % 2) { ownKeys(source, true).forEach(function (key) { _babel_runtime_helpers_defineProperty__WEBPACK_IMPORTED_MODULE_0___default()(target, key, source[key]); }); } else if (Object.getOwnPropertyDescriptors) { Object.defineProperties(target, Object.getOwnPropertyDescriptors(source)); } else { ownKeys(source).forEach(function (key) { Object.defineProperty(target, key, Object.getOwnPropertyDescriptor(source, key)); }); } } return target; }
  43702. /* harmony default export */ __webpack_exports__["default"] = (backbone__WEBPACK_IMPORTED_MODULE_1___default.a.Model.extend({
  43703. defaults: {
  43704. type: 'text',
  43705. // text, number, range, select
  43706. label: '',
  43707. name: '',
  43708. min: '',
  43709. max: '',
  43710. unit: '',
  43711. step: 1,
  43712. value: '',
  43713. target: '',
  43714. default: '',
  43715. placeholder: '',
  43716. changeProp: 0,
  43717. options: []
  43718. },
  43719. initialize: function initialize() {
  43720. var target = this.get('target');
  43721. var name = this.get('name');
  43722. var changeProp = this.get('changeProp');
  43723. if (target) {
  43724. this.target = target;
  43725. this.unset('target');
  43726. var targetEvent = changeProp ? "change:".concat(name) : "change:attributes:".concat(name);
  43727. this.listenTo(target, targetEvent, this.targetUpdated);
  43728. }
  43729. },
  43730. /**
  43731. * Return all the propeties
  43732. * @returns {Object}
  43733. */
  43734. props: function props() {
  43735. return this.attributes;
  43736. },
  43737. targetUpdated: function targetUpdated() {
  43738. var value = this.getTargetValue();
  43739. this.set({
  43740. value: value
  43741. }, {
  43742. fromTarget: 1
  43743. });
  43744. },
  43745. getTargetValue: function getTargetValue() {
  43746. var name = this.get('name');
  43747. var target = this.target;
  43748. var value;
  43749. if (this.get('changeProp')) {
  43750. value = target.get(name);
  43751. } else {
  43752. value = target.getAttributes()[name];
  43753. }
  43754. return !Object(underscore__WEBPACK_IMPORTED_MODULE_2__["isUndefined"])(value) ? value : '';
  43755. },
  43756. setTargetValue: function setTargetValue(value) {
  43757. var opts = arguments.length > 1 && arguments[1] !== undefined ? arguments[1] : {};
  43758. var target = this.target;
  43759. var name = this.get('name');
  43760. if (Object(underscore__WEBPACK_IMPORTED_MODULE_2__["isUndefined"])(value)) return;
  43761. var valueToSet = value;
  43762. if (value === 'false') {
  43763. valueToSet = false;
  43764. } else if (value === 'true') {
  43765. valueToSet = true;
  43766. }
  43767. if (this.get('changeProp')) {
  43768. target.set(name, valueToSet, opts);
  43769. } else {
  43770. var attrs = _objectSpread({}, target.get('attributes'));
  43771. attrs[name] = valueToSet;
  43772. target.set('attributes', attrs, opts);
  43773. }
  43774. },
  43775. setValueFromInput: function setValueFromInput(value) {
  43776. var final = arguments.length > 1 && arguments[1] !== undefined ? arguments[1] : 1;
  43777. var opts = arguments.length > 2 && arguments[2] !== undefined ? arguments[2] : {};
  43778. var toSet = {
  43779. value: value
  43780. };
  43781. this.set(toSet, _objectSpread({}, opts, {
  43782. avoidStore: 1
  43783. })); // Have to trigger the change
  43784. if (final) {
  43785. this.set('value', '', opts);
  43786. this.set(toSet, opts);
  43787. }
  43788. },
  43789. /**
  43790. * Get the initial value of the trait
  43791. * @return {string}
  43792. */
  43793. getInitValue: function getInitValue() {
  43794. var target = this.target;
  43795. var name = this.get('name');
  43796. var value;
  43797. if (target) {
  43798. var attrs = target.get('attributes');
  43799. value = this.get('changeProp') ? target.get(name) : attrs[name];
  43800. }
  43801. return value || this.get('value') || this.get('default');
  43802. }
  43803. }));
  43804. /***/ }),
  43805. /***/ "./src/trait_manager/model/TraitFactory.js":
  43806. /*!*************************************************!*\
  43807. !*** ./src/trait_manager/model/TraitFactory.js ***!
  43808. \*************************************************/
  43809. /*! exports provided: default */
  43810. /***/ (function(module, __webpack_exports__, __webpack_require__) {
  43811. "use strict";
  43812. __webpack_require__.r(__webpack_exports__);
  43813. /* harmony default export */ __webpack_exports__["default"] = (function () {
  43814. var config = arguments.length > 0 && arguments[0] !== undefined ? arguments[0] : {};
  43815. return {
  43816. /**
  43817. * Build props object by their name
  43818. * @param {Array<string>|string} props Array of properties name
  43819. * @return {Array<Object>}
  43820. */
  43821. build: function build(props) {
  43822. var objs = [];
  43823. if (typeof props === 'string') props = [props];
  43824. for (var i = 0; i < props.length; i++) {
  43825. var obj = {};
  43826. var prop = props[i];
  43827. obj.name = prop; // Define type
  43828. switch (prop) {
  43829. case 'target':
  43830. obj.type = 'select';
  43831. break;
  43832. } // Define options
  43833. switch (prop) {
  43834. case 'target':
  43835. obj.options = config.optionsTarget;
  43836. break;
  43837. }
  43838. objs.push(obj);
  43839. }
  43840. return objs;
  43841. }
  43842. };
  43843. });
  43844. /***/ }),
  43845. /***/ "./src/trait_manager/model/Traits.js":
  43846. /*!*******************************************!*\
  43847. !*** ./src/trait_manager/model/Traits.js ***!
  43848. \*******************************************/
  43849. /*! exports provided: default */
  43850. /***/ (function(module, __webpack_exports__, __webpack_require__) {
  43851. "use strict";
  43852. __webpack_require__.r(__webpack_exports__);
  43853. /* harmony import */ var backbone__WEBPACK_IMPORTED_MODULE_0__ = __webpack_require__(/*! backbone */ "./node_modules/backbone/backbone.js");
  43854. /* harmony import */ var backbone__WEBPACK_IMPORTED_MODULE_0___default = /*#__PURE__*/__webpack_require__.n(backbone__WEBPACK_IMPORTED_MODULE_0__);
  43855. /* harmony import */ var underscore__WEBPACK_IMPORTED_MODULE_1__ = __webpack_require__(/*! underscore */ "./node_modules/underscore/underscore.js");
  43856. /* harmony import */ var underscore__WEBPACK_IMPORTED_MODULE_1___default = /*#__PURE__*/__webpack_require__.n(underscore__WEBPACK_IMPORTED_MODULE_1__);
  43857. /* harmony import */ var _Trait__WEBPACK_IMPORTED_MODULE_2__ = __webpack_require__(/*! ./Trait */ "./src/trait_manager/model/Trait.js");
  43858. /* harmony import */ var _TraitFactory__WEBPACK_IMPORTED_MODULE_3__ = __webpack_require__(/*! ./TraitFactory */ "./src/trait_manager/model/TraitFactory.js");
  43859. /* harmony default export */ __webpack_exports__["default"] = (backbone__WEBPACK_IMPORTED_MODULE_0___default.a.Collection.extend({
  43860. model: _Trait__WEBPACK_IMPORTED_MODULE_2__["default"],
  43861. initialize: function initialize(coll) {
  43862. var options = arguments.length > 1 && arguments[1] !== undefined ? arguments[1] : {};
  43863. this.em = options.em || '';
  43864. this.listenTo(this, 'add', this.handleAdd);
  43865. this.listenTo(this, 'reset', this.handleReset);
  43866. },
  43867. handleReset: function handleReset(coll) {
  43868. var _ref = arguments.length > 1 && arguments[1] !== undefined ? arguments[1] : {},
  43869. _ref$previousModels = _ref.previousModels,
  43870. previousModels = _ref$previousModels === void 0 ? [] : _ref$previousModels;
  43871. previousModels.forEach(function (model) {
  43872. return model.trigger('remove');
  43873. });
  43874. },
  43875. handleAdd: function handleAdd(model) {
  43876. var target = this.target;
  43877. if (target) {
  43878. model.target = target;
  43879. }
  43880. },
  43881. setTarget: function setTarget(target) {
  43882. this.target = target;
  43883. },
  43884. add: function add(models, opt) {
  43885. var em = this.em; // Use TraitFactory if necessary
  43886. if (Object(underscore__WEBPACK_IMPORTED_MODULE_1__["isString"])(models) || Object(underscore__WEBPACK_IMPORTED_MODULE_1__["isArray"])(models)) {
  43887. var tm = em && em.get && em.get('TraitManager');
  43888. var tmOpts = tm && tm.getConfig();
  43889. var tf = Object(_TraitFactory__WEBPACK_IMPORTED_MODULE_3__["default"])(tmOpts);
  43890. if (Object(underscore__WEBPACK_IMPORTED_MODULE_1__["isString"])(models)) {
  43891. models = [models];
  43892. }
  43893. for (var i = 0, len = models.length; i < len; i++) {
  43894. var str = models[i];
  43895. var model = Object(underscore__WEBPACK_IMPORTED_MODULE_1__["isString"])(str) ? tf.build(str)[0] : str;
  43896. model.target = this.target;
  43897. models[i] = model;
  43898. }
  43899. }
  43900. return backbone__WEBPACK_IMPORTED_MODULE_0___default.a.Collection.prototype.add.apply(this, [models, opt]);
  43901. }
  43902. }));
  43903. /***/ }),
  43904. /***/ "./src/trait_manager/view/TraitButtonView.js":
  43905. /*!***************************************************!*\
  43906. !*** ./src/trait_manager/view/TraitButtonView.js ***!
  43907. \***************************************************/
  43908. /*! exports provided: default */
  43909. /***/ (function(module, __webpack_exports__, __webpack_require__) {
  43910. "use strict";
  43911. __webpack_require__.r(__webpack_exports__);
  43912. /* harmony import */ var underscore__WEBPACK_IMPORTED_MODULE_0__ = __webpack_require__(/*! underscore */ "./node_modules/underscore/underscore.js");
  43913. /* harmony import */ var underscore__WEBPACK_IMPORTED_MODULE_0___default = /*#__PURE__*/__webpack_require__.n(underscore__WEBPACK_IMPORTED_MODULE_0__);
  43914. /* harmony import */ var _TraitView__WEBPACK_IMPORTED_MODULE_1__ = __webpack_require__(/*! ./TraitView */ "./src/trait_manager/view/TraitView.js");
  43915. /* harmony default export */ __webpack_exports__["default"] = (_TraitView__WEBPACK_IMPORTED_MODULE_1__["default"].extend({
  43916. events: {
  43917. 'click button': 'handleClick'
  43918. },
  43919. templateInput: '',
  43920. handleClick: function handleClick() {
  43921. var model = this.model,
  43922. em = this.em;
  43923. var command = model.get('command');
  43924. if (command) {
  43925. if (Object(underscore__WEBPACK_IMPORTED_MODULE_0__["isString"])(command)) {
  43926. em.get('Commands').run(command);
  43927. } else {
  43928. command(em.get('Editor'), model);
  43929. }
  43930. }
  43931. },
  43932. renderLabel: function renderLabel() {
  43933. if (this.model.get('label')) {
  43934. _TraitView__WEBPACK_IMPORTED_MODULE_1__["default"].prototype.renderLabel.apply(this, arguments);
  43935. }
  43936. },
  43937. getInputEl: function getInputEl() {
  43938. var model = this.model,
  43939. ppfx = this.ppfx;
  43940. var _model$props = model.props(),
  43941. labelButton = _model$props.labelButton,
  43942. text = _model$props.text,
  43943. full = _model$props.full;
  43944. var label = labelButton || text;
  43945. var className = "".concat(ppfx, "btn");
  43946. var input = "<button type=\"button\" class=\"".concat(className, "-prim").concat(full ? " ".concat(className, "--full") : '', "\">").concat(label, "</button>");
  43947. return input;
  43948. }
  43949. }));
  43950. /***/ }),
  43951. /***/ "./src/trait_manager/view/TraitCheckboxView.js":
  43952. /*!*****************************************************!*\
  43953. !*** ./src/trait_manager/view/TraitCheckboxView.js ***!
  43954. \*****************************************************/
  43955. /*! exports provided: default */
  43956. /***/ (function(module, __webpack_exports__, __webpack_require__) {
  43957. "use strict";
  43958. __webpack_require__.r(__webpack_exports__);
  43959. /* harmony import */ var underscore__WEBPACK_IMPORTED_MODULE_0__ = __webpack_require__(/*! underscore */ "./node_modules/underscore/underscore.js");
  43960. /* harmony import */ var underscore__WEBPACK_IMPORTED_MODULE_0___default = /*#__PURE__*/__webpack_require__.n(underscore__WEBPACK_IMPORTED_MODULE_0__);
  43961. /* harmony import */ var _TraitView__WEBPACK_IMPORTED_MODULE_1__ = __webpack_require__(/*! ./TraitView */ "./src/trait_manager/view/TraitView.js");
  43962. /* harmony default export */ __webpack_exports__["default"] = (_TraitView__WEBPACK_IMPORTED_MODULE_1__["default"].extend({
  43963. appendInput: 0,
  43964. templateInput: function templateInput() {
  43965. var ppfx = this.ppfx,
  43966. clsField = this.clsField;
  43967. return "<label class=\"".concat(clsField, "\" data-input>\n <i class=\"").concat(ppfx, "chk-icon\"></i>\n </label>");
  43968. },
  43969. /**
  43970. * Fires when the input is changed
  43971. * @private
  43972. */
  43973. onChange: function onChange() {
  43974. var value = this.getInputElem().checked;
  43975. this.model.set('value', this.getCheckedValue(value));
  43976. },
  43977. getCheckedValue: function getCheckedValue(checked) {
  43978. var result = checked;
  43979. var _this$model$attribute = this.model.attributes,
  43980. valueTrue = _this$model$attribute.valueTrue,
  43981. valueFalse = _this$model$attribute.valueFalse;
  43982. if (result && !Object(underscore__WEBPACK_IMPORTED_MODULE_0__["isUndefined"])(valueTrue)) {
  43983. result = valueTrue;
  43984. }
  43985. if (!result && !Object(underscore__WEBPACK_IMPORTED_MODULE_0__["isUndefined"])(valueFalse)) {
  43986. result = valueFalse;
  43987. }
  43988. return result;
  43989. },
  43990. /**
  43991. * Returns input element
  43992. * @return {HTMLElement}
  43993. * @private
  43994. */
  43995. getInputEl: function getInputEl() {
  43996. var toInit = !this.$input;
  43997. for (var _len = arguments.length, args = new Array(_len), _key = 0; _key < _len; _key++) {
  43998. args[_key] = arguments[_key];
  43999. }
  44000. var el = _TraitView__WEBPACK_IMPORTED_MODULE_1__["default"].prototype.getInputEl.apply(this, args);
  44001. if (toInit) {
  44002. var checked, targetValue;
  44003. var model = this.model,
  44004. target = this.target;
  44005. var _model$attributes = model.attributes,
  44006. valueTrue = _model$attributes.valueTrue,
  44007. valueFalse = _model$attributes.valueFalse;
  44008. var name = model.get('name');
  44009. if (model.get('changeProp')) {
  44010. checked = target.get(name);
  44011. targetValue = checked;
  44012. } else {
  44013. targetValue = target.get('attributes')[name];
  44014. checked = targetValue || targetValue === '' ? !0 : !1;
  44015. }
  44016. if (!Object(underscore__WEBPACK_IMPORTED_MODULE_0__["isUndefined"])(valueFalse) && targetValue === valueFalse) {
  44017. checked = !1;
  44018. }
  44019. el.checked = checked;
  44020. }
  44021. return el;
  44022. }
  44023. }));
  44024. /***/ }),
  44025. /***/ "./src/trait_manager/view/TraitColorView.js":
  44026. /*!**************************************************!*\
  44027. !*** ./src/trait_manager/view/TraitColorView.js ***!
  44028. \**************************************************/
  44029. /*! exports provided: default */
  44030. /***/ (function(module, __webpack_exports__, __webpack_require__) {
  44031. "use strict";
  44032. __webpack_require__.r(__webpack_exports__);
  44033. /* harmony import */ var _TraitView__WEBPACK_IMPORTED_MODULE_0__ = __webpack_require__(/*! ./TraitView */ "./src/trait_manager/view/TraitView.js");
  44034. /* harmony import */ var domain_abstract_ui_InputColor__WEBPACK_IMPORTED_MODULE_1__ = __webpack_require__(/*! domain_abstract/ui/InputColor */ "./src/domain_abstract/ui/InputColor.js");
  44035. /* harmony default export */ __webpack_exports__["default"] = (_TraitView__WEBPACK_IMPORTED_MODULE_0__["default"].extend({
  44036. templateInput: '',
  44037. /**
  44038. * Returns input element
  44039. * @return {HTMLElement}
  44040. * @private
  44041. */
  44042. getInputEl: function getInputEl() {
  44043. if (!this.input) {
  44044. var model = this.model;
  44045. var value = this.getModelValue();
  44046. var inputColor = new domain_abstract_ui_InputColor__WEBPACK_IMPORTED_MODULE_1__["default"]({
  44047. model: model,
  44048. target: this.config.em,
  44049. contClass: this.ppfx + 'field-color',
  44050. ppfx: this.ppfx
  44051. });
  44052. var input = inputColor.render();
  44053. input.setValue(value, {
  44054. fromTarget: 1
  44055. });
  44056. this.input = input.el;
  44057. }
  44058. return this.input;
  44059. }
  44060. }));
  44061. /***/ }),
  44062. /***/ "./src/trait_manager/view/TraitNumberView.js":
  44063. /*!***************************************************!*\
  44064. !*** ./src/trait_manager/view/TraitNumberView.js ***!
  44065. \***************************************************/
  44066. /*! exports provided: default */
  44067. /***/ (function(module, __webpack_exports__, __webpack_require__) {
  44068. "use strict";
  44069. __webpack_require__.r(__webpack_exports__);
  44070. /* harmony import */ var _TraitView__WEBPACK_IMPORTED_MODULE_0__ = __webpack_require__(/*! ./TraitView */ "./src/trait_manager/view/TraitView.js");
  44071. /* harmony import */ var domain_abstract_ui_InputNumber__WEBPACK_IMPORTED_MODULE_1__ = __webpack_require__(/*! domain_abstract/ui/InputNumber */ "./src/domain_abstract/ui/InputNumber.js");
  44072. /* harmony default export */ __webpack_exports__["default"] = (_TraitView__WEBPACK_IMPORTED_MODULE_0__["default"].extend({
  44073. getValueForTarget: function getValueForTarget() {
  44074. var model = this.model;
  44075. var _model$attributes = model.attributes,
  44076. value = _model$attributes.value,
  44077. unit = _model$attributes.unit;
  44078. return value ? value + unit : '';
  44079. },
  44080. /**
  44081. * Returns input element
  44082. * @return {HTMLElement}
  44083. * @private
  44084. */
  44085. getInputEl: function getInputEl() {
  44086. if (!this.input) {
  44087. var value = this.getModelValue();
  44088. var inputNumber = new domain_abstract_ui_InputNumber__WEBPACK_IMPORTED_MODULE_1__["default"]({
  44089. contClass: this.ppfx + 'field-int',
  44090. model: this.model,
  44091. ppfx: this.ppfx
  44092. });
  44093. this.input = inputNumber.render();
  44094. this.$input = this.input.inputEl;
  44095. this.$unit = this.input.unitEl;
  44096. this.model.set('value', value);
  44097. this.$input.val(value);
  44098. this.input = inputNumber.el;
  44099. }
  44100. return this.input;
  44101. }
  44102. }));
  44103. /***/ }),
  44104. /***/ "./src/trait_manager/view/TraitSelectView.js":
  44105. /*!***************************************************!*\
  44106. !*** ./src/trait_manager/view/TraitSelectView.js ***!
  44107. \***************************************************/
  44108. /*! exports provided: default */
  44109. /***/ (function(module, __webpack_exports__, __webpack_require__) {
  44110. "use strict";
  44111. __webpack_require__.r(__webpack_exports__);
  44112. /* harmony import */ var backbone__WEBPACK_IMPORTED_MODULE_0__ = __webpack_require__(/*! backbone */ "./node_modules/backbone/backbone.js");
  44113. /* harmony import */ var backbone__WEBPACK_IMPORTED_MODULE_0___default = /*#__PURE__*/__webpack_require__.n(backbone__WEBPACK_IMPORTED_MODULE_0__);
  44114. /* harmony import */ var underscore__WEBPACK_IMPORTED_MODULE_1__ = __webpack_require__(/*! underscore */ "./node_modules/underscore/underscore.js");
  44115. /* harmony import */ var underscore__WEBPACK_IMPORTED_MODULE_1___default = /*#__PURE__*/__webpack_require__.n(underscore__WEBPACK_IMPORTED_MODULE_1__);
  44116. /* harmony import */ var _TraitView__WEBPACK_IMPORTED_MODULE_2__ = __webpack_require__(/*! ./TraitView */ "./src/trait_manager/view/TraitView.js");
  44117. var $ = backbone__WEBPACK_IMPORTED_MODULE_0___default.a.$;
  44118. /* harmony default export */ __webpack_exports__["default"] = (_TraitView__WEBPACK_IMPORTED_MODULE_2__["default"].extend({
  44119. init: function init() {
  44120. this.listenTo(this.model, 'change:options', this.rerender);
  44121. },
  44122. templateInput: function templateInput() {
  44123. var ppfx = this.ppfx,
  44124. clsField = this.clsField;
  44125. return "<div class=\"".concat(clsField, "\">\n <div data-input></div>\n <div class=\"").concat(ppfx, "sel-arrow\">\n <div class=\"").concat(ppfx, "d-s-arrow\"></div>\n </div>\n </div>");
  44126. },
  44127. /**
  44128. * Returns input element
  44129. * @return {HTMLElement}
  44130. * @private
  44131. */
  44132. getInputEl: function getInputEl() {
  44133. if (!this.$input) {
  44134. var model = this.model,
  44135. em = this.em;
  44136. var propName = model.get('name');
  44137. var opts = model.get('options') || [];
  44138. var input = '<select>';
  44139. opts.forEach(function (el) {
  44140. var attrs = '';
  44141. var name, value, style;
  44142. if (Object(underscore__WEBPACK_IMPORTED_MODULE_1__["isString"])(el)) {
  44143. name = el;
  44144. value = el;
  44145. } else {
  44146. name = el.name || el.label || el.value;
  44147. value = "".concat(Object(underscore__WEBPACK_IMPORTED_MODULE_1__["isUndefined"])(el.value) ? el.id : el.value).replace(/"/g, '&quot;');
  44148. style = el.style ? el.style.replace(/"/g, '&quot;') : '';
  44149. attrs += style ? " style=\"".concat(style, "\"") : '';
  44150. }
  44151. var resultName = em.t("traitManager.traits.options.".concat(propName, ".").concat(value)) || name;
  44152. input += "<option value=\"".concat(value, "\"").concat(attrs, ">").concat(resultName, "</option>");
  44153. });
  44154. input += '</select>';
  44155. this.$input = $(input);
  44156. var val = model.getTargetValue();
  44157. !Object(underscore__WEBPACK_IMPORTED_MODULE_1__["isUndefined"])(val) && this.$input.val(val);
  44158. }
  44159. return this.$input.get(0);
  44160. }
  44161. }));
  44162. /***/ }),
  44163. /***/ "./src/trait_manager/view/TraitView.js":
  44164. /*!*********************************************!*\
  44165. !*** ./src/trait_manager/view/TraitView.js ***!
  44166. \*********************************************/
  44167. /*! exports provided: default */
  44168. /***/ (function(module, __webpack_exports__, __webpack_require__) {
  44169. "use strict";
  44170. __webpack_require__.r(__webpack_exports__);
  44171. /* harmony import */ var _babel_runtime_helpers_defineProperty__WEBPACK_IMPORTED_MODULE_0__ = __webpack_require__(/*! @babel/runtime/helpers/defineProperty */ "./node_modules/@babel/runtime/helpers/defineProperty.js");
  44172. /* harmony import */ var _babel_runtime_helpers_defineProperty__WEBPACK_IMPORTED_MODULE_0___default = /*#__PURE__*/__webpack_require__.n(_babel_runtime_helpers_defineProperty__WEBPACK_IMPORTED_MODULE_0__);
  44173. /* harmony import */ var _babel_runtime_helpers_slicedToArray__WEBPACK_IMPORTED_MODULE_1__ = __webpack_require__(/*! @babel/runtime/helpers/slicedToArray */ "./node_modules/@babel/runtime/helpers/slicedToArray.js");
  44174. /* harmony import */ var _babel_runtime_helpers_slicedToArray__WEBPACK_IMPORTED_MODULE_1___default = /*#__PURE__*/__webpack_require__.n(_babel_runtime_helpers_slicedToArray__WEBPACK_IMPORTED_MODULE_1__);
  44175. /* harmony import */ var backbone__WEBPACK_IMPORTED_MODULE_2__ = __webpack_require__(/*! backbone */ "./node_modules/backbone/backbone.js");
  44176. /* harmony import */ var backbone__WEBPACK_IMPORTED_MODULE_2___default = /*#__PURE__*/__webpack_require__.n(backbone__WEBPACK_IMPORTED_MODULE_2__);
  44177. /* harmony import */ var underscore__WEBPACK_IMPORTED_MODULE_3__ = __webpack_require__(/*! underscore */ "./node_modules/underscore/underscore.js");
  44178. /* harmony import */ var underscore__WEBPACK_IMPORTED_MODULE_3___default = /*#__PURE__*/__webpack_require__.n(underscore__WEBPACK_IMPORTED_MODULE_3__);
  44179. /* harmony import */ var utils_mixins__WEBPACK_IMPORTED_MODULE_4__ = __webpack_require__(/*! utils/mixins */ "./src/utils/mixins.js");
  44180. function ownKeys(object, enumerableOnly) { var keys = Object.keys(object); if (Object.getOwnPropertySymbols) { var symbols = Object.getOwnPropertySymbols(object); if (enumerableOnly) symbols = symbols.filter(function (sym) { return Object.getOwnPropertyDescriptor(object, sym).enumerable; }); keys.push.apply(keys, symbols); } return keys; }
  44181. function _objectSpread(target) { for (var i = 1; i < arguments.length; i++) { var source = arguments[i] != null ? arguments[i] : {}; if (i % 2) { ownKeys(source, true).forEach(function (key) { _babel_runtime_helpers_defineProperty__WEBPACK_IMPORTED_MODULE_0___default()(target, key, source[key]); }); } else if (Object.getOwnPropertyDescriptors) { Object.defineProperties(target, Object.getOwnPropertyDescriptors(source)); } else { ownKeys(source).forEach(function (key) { Object.defineProperty(target, key, Object.getOwnPropertyDescriptor(source, key)); }); } } return target; }
  44182. var $ = backbone__WEBPACK_IMPORTED_MODULE_2___default.a.$;
  44183. /* harmony default export */ __webpack_exports__["default"] = (backbone__WEBPACK_IMPORTED_MODULE_2___default.a.View.extend({
  44184. events: {},
  44185. eventCapture: ['change'],
  44186. appendInput: 1,
  44187. attributes: function attributes() {
  44188. return this.model.get('attributes');
  44189. },
  44190. templateLabel: function templateLabel() {
  44191. var ppfx = this.ppfx;
  44192. var label = this.getLabel();
  44193. return "<div class=\"".concat(ppfx, "label\" title=\"").concat(label, "\">").concat(label, "</div>");
  44194. },
  44195. templateInput: function templateInput() {
  44196. var clsField = this.clsField;
  44197. return "<div class=\"".concat(clsField, "\" data-input></div>");
  44198. },
  44199. initialize: function initialize() {
  44200. var _this = this;
  44201. var o = arguments.length > 0 && arguments[0] !== undefined ? arguments[0] : {};
  44202. var _o$config = o.config,
  44203. config = _o$config === void 0 ? {} : _o$config;
  44204. var model = this.model,
  44205. eventCapture = this.eventCapture;
  44206. var target = model.target;
  44207. var type = model.attributes.type;
  44208. this.config = config;
  44209. this.em = config.em;
  44210. this.pfx = config.stylePrefix || '';
  44211. this.ppfx = config.pStylePrefix || '';
  44212. this.target = target;
  44213. var ppfx = this.ppfx;
  44214. this.clsField = "".concat(ppfx, "field ").concat(ppfx, "field-").concat(type);
  44215. [['change:value', this.onValueChange], ['remove', this.removeView]].forEach(function (_ref) {
  44216. var _ref2 = _babel_runtime_helpers_slicedToArray__WEBPACK_IMPORTED_MODULE_1___default()(_ref, 2),
  44217. event = _ref2[0],
  44218. clb = _ref2[1];
  44219. model.off(event, clb);
  44220. _this.listenTo(model, event, clb);
  44221. });
  44222. model.view = this;
  44223. this.listenTo(model, 'change:label', this.render);
  44224. this.listenTo(model, 'change:placeholder', this.rerender);
  44225. eventCapture.forEach(function (event) {
  44226. return _this.events[event] = 'onChange';
  44227. });
  44228. this.delegateEvents();
  44229. this.init();
  44230. },
  44231. getClbOpts: function getClbOpts() {
  44232. return {
  44233. component: this.target,
  44234. trait: this.model,
  44235. elInput: this.getInputElem()
  44236. };
  44237. },
  44238. removeView: function removeView() {
  44239. this.remove();
  44240. this.removed();
  44241. },
  44242. init: function init() {},
  44243. removed: function removed() {},
  44244. onRender: function onRender() {},
  44245. onUpdate: function onUpdate() {},
  44246. onEvent: function onEvent() {},
  44247. /**
  44248. * Fires when the input is changed
  44249. * @private
  44250. */
  44251. onChange: function onChange(event) {
  44252. var el = this.getInputElem();
  44253. if (el && !Object(underscore__WEBPACK_IMPORTED_MODULE_3__["isUndefined"])(el.value)) {
  44254. this.model.set('value', el.value);
  44255. }
  44256. this.onEvent(_objectSpread({}, this.getClbOpts(), {
  44257. event: event
  44258. }));
  44259. },
  44260. getValueForTarget: function getValueForTarget() {
  44261. return this.model.get('value');
  44262. },
  44263. setInputValue: function setInputValue(value) {
  44264. var el = this.getInputElem();
  44265. el && (el.value = value);
  44266. },
  44267. /**
  44268. * On change callback
  44269. * @private
  44270. */
  44271. onValueChange: function onValueChange(model, value) {
  44272. var opts = arguments.length > 2 && arguments[2] !== undefined ? arguments[2] : {};
  44273. if (opts.fromTarget) {
  44274. this.setInputValue(model.get('value'));
  44275. this.postUpdate();
  44276. } else {
  44277. var val = this.getValueForTarget();
  44278. model.setTargetValue(val, opts);
  44279. }
  44280. },
  44281. /**
  44282. * Render label
  44283. * @private
  44284. */
  44285. renderLabel: function renderLabel() {
  44286. var $el = this.$el,
  44287. target = this.target;
  44288. var label = this.getLabel();
  44289. var tpl = this.templateLabel(target);
  44290. if (this.createLabel) {
  44291. tpl = this.createLabel({
  44292. label: label,
  44293. component: target,
  44294. trait: this
  44295. }) || '';
  44296. }
  44297. $el.find('[data-label]').append(tpl);
  44298. },
  44299. /**
  44300. * Returns label for the input
  44301. * @return {string}
  44302. * @private
  44303. */
  44304. getLabel: function getLabel() {
  44305. var em = this.em;
  44306. var _this$model$attribute = this.model.attributes,
  44307. label = _this$model$attribute.label,
  44308. name = _this$model$attribute.name;
  44309. return em.t("traitManager.traits.labels.".concat(name)) || Object(utils_mixins__WEBPACK_IMPORTED_MODULE_4__["capitalize"])(label || name).replace(/-/g, ' ');
  44310. },
  44311. /**
  44312. * Returns current target component
  44313. */
  44314. getComponent: function getComponent() {
  44315. return this.target;
  44316. },
  44317. /**
  44318. * Returns input element
  44319. * @return {HTMLElement}
  44320. * @private
  44321. */
  44322. getInputEl: function getInputEl() {
  44323. if (!this.$input) {
  44324. var em = this.em,
  44325. model = this.model;
  44326. var md = model;
  44327. var name = model.attributes.name;
  44328. var plh = md.get('placeholder') || md.get('default') || '';
  44329. var type = md.get('type') || 'text';
  44330. var min = md.get('min');
  44331. var max = md.get('max');
  44332. var value = this.getModelValue();
  44333. var input = $("<input type=\"".concat(type, "\" placeholder=\"").concat(plh, "\">"));
  44334. var i18nAttr = em.t("traitManager.traits.attributes.".concat(name)) || {};
  44335. input.attr(i18nAttr);
  44336. if (!Object(underscore__WEBPACK_IMPORTED_MODULE_3__["isUndefined"])(value)) {
  44337. md.set({
  44338. value: value
  44339. }, {
  44340. silent: true
  44341. });
  44342. input.prop('value', value);
  44343. }
  44344. if (min) {
  44345. input.prop('min', min);
  44346. }
  44347. if (max) {
  44348. input.prop('max', max);
  44349. }
  44350. this.$input = input;
  44351. }
  44352. return this.$input.get(0);
  44353. },
  44354. getInputElem: function getInputElem() {
  44355. var input = this.input,
  44356. $input = this.$input;
  44357. return input || $input && $input.get && $input.get(0) || this.getElInput();
  44358. },
  44359. getModelValue: function getModelValue() {
  44360. var value;
  44361. var model = this.model;
  44362. var target = this.target;
  44363. var name = model.get('name');
  44364. if (model.get('changeProp')) {
  44365. value = target.get(name);
  44366. } else {
  44367. var attrs = target.get('attributes');
  44368. value = model.get('value') || attrs[name];
  44369. }
  44370. return !Object(underscore__WEBPACK_IMPORTED_MODULE_3__["isUndefined"])(value) ? value : '';
  44371. },
  44372. getElInput: function getElInput() {
  44373. return this.elInput;
  44374. },
  44375. /**
  44376. * Renders input
  44377. * @private
  44378. * */
  44379. renderField: function renderField() {
  44380. var $el = this.$el,
  44381. appendInput = this.appendInput,
  44382. model = this.model;
  44383. var inputs = $el.find('[data-input]');
  44384. var el = inputs[inputs.length - 1];
  44385. var tpl = model.el;
  44386. if (!tpl) {
  44387. tpl = this.createInput ? this.createInput(this.getClbOpts()) : this.getInputEl();
  44388. }
  44389. if (Object(underscore__WEBPACK_IMPORTED_MODULE_3__["isString"])(tpl)) {
  44390. el.innerHTML = tpl;
  44391. this.elInput = el.firstChild;
  44392. } else {
  44393. appendInput ? el.appendChild(tpl) : el.insertBefore(tpl, el.firstChild);
  44394. this.elInput = tpl;
  44395. }
  44396. model.el = this.elInput;
  44397. },
  44398. hasLabel: function hasLabel() {
  44399. var label = this.model.attributes.label;
  44400. return !this.noLabel && label !== false;
  44401. },
  44402. rerender: function rerender() {
  44403. this.model.el = null;
  44404. this.render();
  44405. },
  44406. postUpdate: function postUpdate() {
  44407. this.onUpdate(this.getClbOpts());
  44408. },
  44409. render: function render() {
  44410. var $el = this.$el,
  44411. pfx = this.pfx,
  44412. ppfx = this.ppfx,
  44413. model = this.model;
  44414. var type = model.attributes.type;
  44415. var hasLabel = this.hasLabel && this.hasLabel();
  44416. var cls = "".concat(pfx, "trait");
  44417. this.$input = null;
  44418. var tmpl = "<div class=\"".concat(cls, "\">\n ").concat(hasLabel ? "<div class=\"".concat(ppfx, "label-wrp\" data-label></div>") : '', "\n <div class=\"").concat(ppfx, "field-wrp ").concat(ppfx, "field-wrp--").concat(type, "\" data-input>\n ").concat(this.templateInput ? Object(underscore__WEBPACK_IMPORTED_MODULE_3__["isFunction"])(this.templateInput) ? this.templateInput(this.getClbOpts()) : this.templateInput : '', "\n </div>\n </div>");
  44419. $el.empty().append(tmpl);
  44420. hasLabel && this.renderLabel();
  44421. this.renderField();
  44422. this.el.className = "".concat(cls, "__wrp");
  44423. this.postUpdate();
  44424. this.onRender(this.getClbOpts());
  44425. return this;
  44426. }
  44427. }));
  44428. /***/ }),
  44429. /***/ "./src/trait_manager/view/TraitsView.js":
  44430. /*!**********************************************!*\
  44431. !*** ./src/trait_manager/view/TraitsView.js ***!
  44432. \**********************************************/
  44433. /*! exports provided: default */
  44434. /***/ (function(module, __webpack_exports__, __webpack_require__) {
  44435. "use strict";
  44436. __webpack_require__.r(__webpack_exports__);
  44437. /* harmony import */ var domain_abstract_view_DomainViews__WEBPACK_IMPORTED_MODULE_0__ = __webpack_require__(/*! domain_abstract/view/DomainViews */ "./src/domain_abstract/view/DomainViews.js");
  44438. /* harmony import */ var _TraitView__WEBPACK_IMPORTED_MODULE_1__ = __webpack_require__(/*! ./TraitView */ "./src/trait_manager/view/TraitView.js");
  44439. /* harmony import */ var _TraitSelectView__WEBPACK_IMPORTED_MODULE_2__ = __webpack_require__(/*! ./TraitSelectView */ "./src/trait_manager/view/TraitSelectView.js");
  44440. /* harmony import */ var _TraitCheckboxView__WEBPACK_IMPORTED_MODULE_3__ = __webpack_require__(/*! ./TraitCheckboxView */ "./src/trait_manager/view/TraitCheckboxView.js");
  44441. /* harmony import */ var _TraitNumberView__WEBPACK_IMPORTED_MODULE_4__ = __webpack_require__(/*! ./TraitNumberView */ "./src/trait_manager/view/TraitNumberView.js");
  44442. /* harmony import */ var _TraitColorView__WEBPACK_IMPORTED_MODULE_5__ = __webpack_require__(/*! ./TraitColorView */ "./src/trait_manager/view/TraitColorView.js");
  44443. /* harmony import */ var _TraitButtonView__WEBPACK_IMPORTED_MODULE_6__ = __webpack_require__(/*! ./TraitButtonView */ "./src/trait_manager/view/TraitButtonView.js");
  44444. /* harmony default export */ __webpack_exports__["default"] = (domain_abstract_view_DomainViews__WEBPACK_IMPORTED_MODULE_0__["default"].extend({
  44445. ns: 'Traits',
  44446. itemView: _TraitView__WEBPACK_IMPORTED_MODULE_1__["default"],
  44447. reuseView: 1,
  44448. itemsView: {
  44449. text: _TraitView__WEBPACK_IMPORTED_MODULE_1__["default"],
  44450. number: _TraitNumberView__WEBPACK_IMPORTED_MODULE_4__["default"],
  44451. select: _TraitSelectView__WEBPACK_IMPORTED_MODULE_2__["default"],
  44452. checkbox: _TraitCheckboxView__WEBPACK_IMPORTED_MODULE_3__["default"],
  44453. color: _TraitColorView__WEBPACK_IMPORTED_MODULE_5__["default"],
  44454. button: _TraitButtonView__WEBPACK_IMPORTED_MODULE_6__["default"]
  44455. },
  44456. initialize: function initialize() {
  44457. var o = arguments.length > 0 && arguments[0] !== undefined ? arguments[0] : {};
  44458. var config = o.config || {};
  44459. this.config = config;
  44460. this.em = o.editor;
  44461. this.pfx = config.stylePrefix || '';
  44462. this.ppfx = config.pStylePrefix || '';
  44463. this.className = this.pfx + 'traits';
  44464. var toListen = 'component:toggled';
  44465. this.listenTo(this.em, toListen, this.updatedCollection);
  44466. this.updatedCollection();
  44467. },
  44468. /**
  44469. * Update view collection
  44470. * @private
  44471. */
  44472. updatedCollection: function updatedCollection() {
  44473. var ppfx = this.ppfx;
  44474. var comp = this.em.getSelected();
  44475. this.el.className = "".concat(this.className, " ").concat(ppfx, "one-bg ").concat(ppfx, "two-color");
  44476. this.collection = comp ? comp.get('traits') : [];
  44477. this.render();
  44478. }
  44479. }));
  44480. /***/ }),
  44481. /***/ "./src/undo_manager/index.js":
  44482. /*!***********************************!*\
  44483. !*** ./src/undo_manager/index.js ***!
  44484. \***********************************/
  44485. /*! exports provided: default */
  44486. /***/ (function(module, __webpack_exports__, __webpack_require__) {
  44487. "use strict";
  44488. __webpack_require__.r(__webpack_exports__);
  44489. /* harmony import */ var _babel_runtime_helpers_defineProperty__WEBPACK_IMPORTED_MODULE_0__ = __webpack_require__(/*! @babel/runtime/helpers/defineProperty */ "./node_modules/@babel/runtime/helpers/defineProperty.js");
  44490. /* harmony import */ var _babel_runtime_helpers_defineProperty__WEBPACK_IMPORTED_MODULE_0___default = /*#__PURE__*/__webpack_require__.n(_babel_runtime_helpers_defineProperty__WEBPACK_IMPORTED_MODULE_0__);
  44491. /* harmony import */ var backbone_undo__WEBPACK_IMPORTED_MODULE_1__ = __webpack_require__(/*! backbone-undo */ "./node_modules/backbone-undo/Backbone.Undo.js");
  44492. /* harmony import */ var backbone_undo__WEBPACK_IMPORTED_MODULE_1___default = /*#__PURE__*/__webpack_require__.n(backbone_undo__WEBPACK_IMPORTED_MODULE_1__);
  44493. function ownKeys(object, enumerableOnly) { var keys = Object.keys(object); if (Object.getOwnPropertySymbols) { var symbols = Object.getOwnPropertySymbols(object); if (enumerableOnly) symbols = symbols.filter(function (sym) { return Object.getOwnPropertyDescriptor(object, sym).enumerable; }); keys.push.apply(keys, symbols); } return keys; }
  44494. function _objectSpread(target) { for (var i = 1; i < arguments.length; i++) { var source = arguments[i] != null ? arguments[i] : {}; if (i % 2) { ownKeys(source, true).forEach(function (key) { _babel_runtime_helpers_defineProperty__WEBPACK_IMPORTED_MODULE_0___default()(target, key, source[key]); }); } else if (Object.getOwnPropertyDescriptors) { Object.defineProperties(target, Object.getOwnPropertyDescriptors(source)); } else { ownKeys(source).forEach(function (key) { Object.defineProperty(target, key, Object.getOwnPropertyDescriptor(source, key)); }); } } return target; }
  44495. /**
  44496. * This module allows to manage the stack of changes applied in canvas.
  44497. * Once the editor is instantiated you can use its API. Before using these methods you should get the module from the instance
  44498. *
  44499. * ```js
  44500. * const um = editor.UndoManager;
  44501. * ```
  44502. *
  44503. * * [getConfig](#getconfig)
  44504. * * [add](#add)
  44505. * * [remove](#remove)
  44506. * * [removeAll](#removeall)
  44507. * * [start](#start)
  44508. * * [stop](#stop)
  44509. * * [undo](#undo)
  44510. * * [undoAll](#undoall)
  44511. * * [redo](#redo)
  44512. * * [redoAll](#redoall)
  44513. * * [hasUndo](#hasundo)
  44514. * * [hasRedo](#hasredo)
  44515. * * [getStack](#getstack)
  44516. * * [clear](#clear)
  44517. *
  44518. * @module UndoManager
  44519. */
  44520. /* harmony default export */ __webpack_exports__["default"] = (function () {
  44521. var em;
  44522. var um;
  44523. var config;
  44524. var beforeCache;
  44525. var configDef = {
  44526. maximumStackLength: 500
  44527. };
  44528. return {
  44529. name: 'UndoManager',
  44530. /**
  44531. * Initialize module
  44532. * @param {Object} config Configurations
  44533. * @private
  44534. */
  44535. init: function init() {
  44536. var opts = arguments.length > 0 && arguments[0] !== undefined ? arguments[0] : {};
  44537. config = _objectSpread({}, opts, {}, configDef);
  44538. em = config.em;
  44539. this.em = em;
  44540. um = new backbone_undo__WEBPACK_IMPORTED_MODULE_1___default.a(_objectSpread({
  44541. track: true,
  44542. register: []
  44543. }, config));
  44544. um.changeUndoType('change', {
  44545. condition: false
  44546. });
  44547. um.changeUndoType('add', {
  44548. on: function on(model, collection) {
  44549. var options = arguments.length > 2 && arguments[2] !== undefined ? arguments[2] : {};
  44550. if (options.avoidStore) return;
  44551. return {
  44552. object: collection,
  44553. before: undefined,
  44554. after: model,
  44555. options: _objectSpread({}, options)
  44556. };
  44557. }
  44558. });
  44559. um.changeUndoType('remove', {
  44560. on: function on(model, collection) {
  44561. var options = arguments.length > 2 && arguments[2] !== undefined ? arguments[2] : {};
  44562. if (options.avoidStore) return;
  44563. return {
  44564. object: collection,
  44565. before: model,
  44566. after: undefined,
  44567. options: _objectSpread({}, options)
  44568. };
  44569. }
  44570. });
  44571. var customUndoType = {
  44572. on: function on(object, value) {
  44573. var opt = arguments.length > 2 && arguments[2] !== undefined ? arguments[2] : {};
  44574. !beforeCache && (beforeCache = object.previousAttributes());
  44575. if (opt.avoidStore) {
  44576. return;
  44577. } else {
  44578. var result = {
  44579. object: object,
  44580. before: beforeCache,
  44581. after: object.toJSON()
  44582. };
  44583. beforeCache = null;
  44584. return result;
  44585. }
  44586. },
  44587. undo: function undo(model, bf, af, opt) {
  44588. model.set(bf);
  44589. },
  44590. redo: function redo(model, bf, af, opt) {
  44591. model.set(af);
  44592. }
  44593. };
  44594. var events = ['style', 'attributes', 'content', 'src'];
  44595. events.forEach(function (ev) {
  44596. return um.addUndoType("change:".concat(ev), customUndoType);
  44597. });
  44598. um.on('undo redo', function () {
  44599. return em.trigger('component:toggled change:canvasOffset');
  44600. });
  44601. ['undo', 'redo'].forEach(function (ev) {
  44602. return um.on(ev, function () {
  44603. return em.trigger(ev);
  44604. });
  44605. });
  44606. return this;
  44607. },
  44608. /**
  44609. * Get module configurations
  44610. * @return {Object} Configuration object
  44611. * @example
  44612. * const config = um.getConfig();
  44613. * // { ... }
  44614. */
  44615. getConfig: function getConfig() {
  44616. return config;
  44617. },
  44618. /**
  44619. * Add an entity (Model/Collection) to track
  44620. * Note: New Components and CSSRules will be added automatically
  44621. * @param {Model|Collection} entity Entity to track
  44622. * @return {this}
  44623. * @example
  44624. * um.add(someModelOrCollection);
  44625. */
  44626. add: function add(entity) {
  44627. um.register(entity);
  44628. return this;
  44629. },
  44630. /**
  44631. * Remove and stop tracking the entity (Model/Collection)
  44632. * @param {Model|Collection} entity Entity to remove
  44633. * @return {this}
  44634. * @example
  44635. * um.remove(someModelOrCollection);
  44636. */
  44637. remove: function remove(entity) {
  44638. um.unregister(entity);
  44639. return this;
  44640. },
  44641. /**
  44642. * Remove all entities
  44643. * @return {this}
  44644. * @example
  44645. * um.removeAll();
  44646. */
  44647. removeAll: function removeAll() {
  44648. um.unregisterAll();
  44649. return this;
  44650. },
  44651. /**
  44652. * Start/resume tracking changes
  44653. * @return {this}
  44654. * @example
  44655. * um.start();
  44656. */
  44657. start: function start() {
  44658. um.startTracking();
  44659. return this;
  44660. },
  44661. /**
  44662. * Stop tracking changes
  44663. * @return {this}
  44664. * @example
  44665. * um.stop();
  44666. */
  44667. stop: function stop() {
  44668. um.stopTracking();
  44669. return this;
  44670. },
  44671. /**
  44672. * Undo last change
  44673. * @return {this}
  44674. * @example
  44675. * um.undo();
  44676. */
  44677. undo: function undo() {
  44678. var all = arguments.length > 0 && arguments[0] !== undefined ? arguments[0] : true;
  44679. !em.isEditing() && um.undo(all);
  44680. return this;
  44681. },
  44682. /**
  44683. * Undo all changes
  44684. * @return {this}
  44685. * @example
  44686. * um.undoAll();
  44687. */
  44688. undoAll: function undoAll() {
  44689. um.undoAll();
  44690. return this;
  44691. },
  44692. /**
  44693. * Redo last change
  44694. * @return {this}
  44695. * @example
  44696. * um.redo();
  44697. */
  44698. redo: function redo() {
  44699. var all = arguments.length > 0 && arguments[0] !== undefined ? arguments[0] : true;
  44700. !em.isEditing() && um.redo(all);
  44701. return this;
  44702. },
  44703. /**
  44704. * Redo all changes
  44705. * @return {this}
  44706. * @example
  44707. * um.redoAll();
  44708. */
  44709. redoAll: function redoAll() {
  44710. um.redoAll();
  44711. return this;
  44712. },
  44713. /**
  44714. * Checks if exists an available undo
  44715. * @return {Boolean}
  44716. * @example
  44717. * um.hasUndo();
  44718. */
  44719. hasUndo: function hasUndo() {
  44720. return um.isAvailable('undo');
  44721. },
  44722. /**
  44723. * Checks if exists an available redo
  44724. * @return {Boolean}
  44725. * @example
  44726. * um.hasRedo();
  44727. */
  44728. hasRedo: function hasRedo() {
  44729. return um.isAvailable('redo');
  44730. },
  44731. /**
  44732. * Get stack of changes
  44733. * @return {Collection}
  44734. * @example
  44735. * const stack = um.getStack();
  44736. * stack.each(item => ...);
  44737. */
  44738. getStack: function getStack() {
  44739. return um.stack;
  44740. },
  44741. /**
  44742. * Get grouped undo manager stack.
  44743. * The difference between `getStack` is when you do multiple operations at a time,
  44744. * like appending multiple components:
  44745. * `editor.getWrapper().append(`<div>C1</div><div>C2</div>`);`
  44746. * `getStack` will return a collection length of 2.
  44747. * `getStackGroup` instead will group them as a single operation (the first
  44748. * inserted component will be returned in the list) by returning an array length of 1.
  44749. * @return {Array}
  44750. */
  44751. getStackGroup: function getStackGroup() {
  44752. var result = [];
  44753. var inserted = [];
  44754. this.getStack().forEach(function (item) {
  44755. var index = item.get('magicFusionIndex');
  44756. if (inserted.indexOf(index) < 0) {
  44757. inserted.push(index);
  44758. result.push(item);
  44759. }
  44760. });
  44761. return result;
  44762. },
  44763. getPointer: function getPointer() {
  44764. return this.getStack().pointer;
  44765. },
  44766. /**
  44767. * Clear the stack
  44768. * @return {this}
  44769. * @example
  44770. * um.clear();
  44771. */
  44772. clear: function clear() {
  44773. um.clear();
  44774. return this;
  44775. },
  44776. getInstance: function getInstance() {
  44777. return um;
  44778. }
  44779. };
  44780. });
  44781. /***/ }),
  44782. /***/ "./src/utils/ColorPicker.js":
  44783. /*!**********************************!*\
  44784. !*** ./src/utils/ColorPicker.js ***!
  44785. \**********************************/
  44786. /*! exports provided: default */
  44787. /***/ (function(module, __webpack_exports__, __webpack_require__) {
  44788. "use strict";
  44789. __webpack_require__.r(__webpack_exports__);
  44790. /* harmony import */ var _babel_runtime_helpers_typeof__WEBPACK_IMPORTED_MODULE_0__ = __webpack_require__(/*! @babel/runtime/helpers/typeof */ "./node_modules/@babel/runtime/helpers/typeof.js");
  44791. /* harmony import */ var _babel_runtime_helpers_typeof__WEBPACK_IMPORTED_MODULE_0___default = /*#__PURE__*/__webpack_require__.n(_babel_runtime_helpers_typeof__WEBPACK_IMPORTED_MODULE_0__);
  44792. // Without jquery I have to update few stuff
  44793. //
  44794. // Spectrum Colorpicker v1.8.0
  44795. // https://github.com/bgrins/spectrum
  44796. // Author: Brian Grinstead
  44797. // License: MIT
  44798. /* harmony default export */ __webpack_exports__["default"] = (function ($, undefined) {
  44799. 'use strict';
  44800. var defaultOpts = {
  44801. // Callbacks
  44802. beforeShow: noop,
  44803. move: noop,
  44804. change: noop,
  44805. show: noop,
  44806. hide: noop,
  44807. // Options
  44808. color: false,
  44809. flat: false,
  44810. showInput: false,
  44811. allowEmpty: false,
  44812. showButtons: true,
  44813. clickoutFiresChange: true,
  44814. showInitial: false,
  44815. showPalette: false,
  44816. showPaletteOnly: false,
  44817. hideAfterPaletteSelect: false,
  44818. togglePaletteOnly: false,
  44819. showSelectionPalette: true,
  44820. localStorageKey: false,
  44821. appendTo: 'body',
  44822. maxSelectionSize: 7,
  44823. cancelText: 'cancel',
  44824. chooseText: 'choose',
  44825. togglePaletteMoreText: 'more',
  44826. togglePaletteLessText: 'less',
  44827. clearText: 'Clear Color Selection',
  44828. noColorSelectedText: 'No Color Selected',
  44829. preferredFormat: false,
  44830. className: '',
  44831. // Deprecated - use containerClassName and replacerClassName instead.
  44832. containerClassName: '',
  44833. replacerClassName: '',
  44834. showAlpha: false,
  44835. theme: 'sp-light',
  44836. palette: [['#ffffff', '#000000', '#ff0000', '#ff8000', '#ffff00', '#008000', '#0000ff', '#4b0082', '#9400d3']],
  44837. selectionPalette: [],
  44838. disabled: false,
  44839. offset: null
  44840. },
  44841. spectrums = [],
  44842. IE = !!/msie/i.exec(window.navigator.userAgent),
  44843. rgbaSupport = function () {
  44844. function contains(str, substr) {
  44845. return !!~('' + str).indexOf(substr);
  44846. }
  44847. var elem = document.createElement('div');
  44848. var style = elem.style;
  44849. style.cssText = 'background-color:rgba(0,0,0,.5)';
  44850. return contains(style.backgroundColor, 'rgba') || contains(style.backgroundColor, 'hsla');
  44851. }(),
  44852. replaceInput = ["<div class='sp-replacer'>", "<div class='sp-preview'><div class='sp-preview-inner'></div></div>", "<div class='sp-dd'>&#9660;</div>", '</div>'].join(''),
  44853. markup = function () {
  44854. // IE does not support gradients with multiple stops, so we need to simulate
  44855. // that for the rainbow slider with 8 divs that each have a single gradient
  44856. var gradientFix = '';
  44857. if (IE) {
  44858. for (var i = 1; i <= 6; i++) {
  44859. gradientFix += "<div class='sp-" + i + "'></div>";
  44860. }
  44861. }
  44862. return ["<div class='sp-container sp-hidden'>", "<div class='sp-palette-container'>", "<div class='sp-palette sp-thumb sp-cf'></div>", "<div class='sp-palette-button-container sp-cf'>", "<button type='button' class='sp-palette-toggle'></button>", '</div>', '</div>', "<div class='sp-picker-container'>", "<div class='sp-top sp-cf'>", "<div class='sp-fill'></div>", "<div class='sp-top-inner'>", "<div class='sp-color'>", "<div class='sp-sat'>", "<div class='sp-val'>", "<div class='sp-dragger'></div>", '</div>', '</div>', '</div>', "<div class='sp-clear sp-clear-display'>", '</div>', "<div class='sp-hue'>", "<div class='sp-slider'></div>", gradientFix, '</div>', '</div>', "<div class='sp-alpha'><div class='sp-alpha-inner'><div class='sp-alpha-handle'></div></div></div>", '</div>', "<div class='sp-input-container sp-cf'>", "<input class='sp-input' type='text' spellcheck='false' />", '</div>', "<div class='sp-initial sp-thumb sp-cf'></div>", "<div class='sp-button-container sp-cf'>", "<a class='sp-cancel' href='#'></a>", "<button type='button' class='sp-choose'></button>", '</div>', '</div>', '</div>'].join('');
  44863. }();
  44864. function paletteTemplate(p, color, className, opts) {
  44865. var html = [];
  44866. for (var i = 0; i < p.length; i++) {
  44867. var current = p[i];
  44868. if (current) {
  44869. var tiny = tinycolor(current);
  44870. var c = tiny.toHsl().l < 0.5 ? 'sp-thumb-el sp-thumb-dark' : 'sp-thumb-el sp-thumb-light';
  44871. c += tinycolor.equals(color, current) ? ' sp-thumb-active' : '';
  44872. var formattedString = tiny.toString(opts.preferredFormat || 'rgb');
  44873. var swatchStyle = rgbaSupport ? 'background-color:' + tiny.toRgbString() : 'filter:' + tiny.toFilter();
  44874. html.push('<span title="' + formattedString + '" data-color="' + tiny.toRgbString() + '" class="' + c + '"><span class="sp-thumb-inner" style="' + swatchStyle + ';"></span></span>');
  44875. } else {
  44876. var cls = 'sp-clear-display';
  44877. html.push($('<div />').append($('<span data-color="" style="background-color:transparent;" class="' + cls + '"></span>').attr('title', opts.noColorSelectedText)).html());
  44878. }
  44879. }
  44880. return "<div class='sp-cf " + className + "'>" + html.join('') + '</div>';
  44881. }
  44882. function hideAll() {
  44883. for (var i = 0; i < spectrums.length; i++) {
  44884. if (spectrums[i]) {
  44885. spectrums[i].hide();
  44886. }
  44887. }
  44888. }
  44889. function instanceOptions(o, callbackContext) {
  44890. var opts = $.extend({}, defaultOpts, o);
  44891. opts.callbacks = {
  44892. move: bind(opts.move, callbackContext),
  44893. change: bind(opts.change, callbackContext),
  44894. show: bind(opts.show, callbackContext),
  44895. hide: bind(opts.hide, callbackContext),
  44896. beforeShow: bind(opts.beforeShow, callbackContext)
  44897. };
  44898. return opts;
  44899. }
  44900. function spectrum(element, o) {
  44901. var opts = instanceOptions(o, element),
  44902. flat = opts.flat,
  44903. showSelectionPalette = opts.showSelectionPalette,
  44904. localStorageKey = opts.localStorageKey,
  44905. theme = opts.theme,
  44906. callbacks = opts.callbacks,
  44907. resize = throttle(reflow, 10),
  44908. visible = false,
  44909. isDragging = false,
  44910. dragWidth = 0,
  44911. dragHeight = 0,
  44912. dragHelperHeight = 0,
  44913. slideHeight = 0,
  44914. slideWidth = 0,
  44915. alphaWidth = 0,
  44916. alphaSlideHelperWidth = 0,
  44917. slideHelperHeight = 0,
  44918. currentHue = 0,
  44919. currentSaturation = 0,
  44920. currentValue = 0,
  44921. currentAlpha = 1,
  44922. palette = [],
  44923. paletteArray = [],
  44924. paletteLookup = {},
  44925. selectionPalette = opts.selectionPalette.slice(0),
  44926. maxSelectionSize = opts.maxSelectionSize,
  44927. draggingClass = 'sp-dragging',
  44928. shiftMovementDirection = null;
  44929. var doc = element.ownerDocument,
  44930. body = doc.body,
  44931. boundElement = $(element),
  44932. disabled = false,
  44933. container = $(markup, doc).addClass(theme),
  44934. pickerContainer = container.find('.sp-picker-container'),
  44935. dragger = container.find('.sp-color'),
  44936. dragHelper = container.find('.sp-dragger'),
  44937. slider = container.find('.sp-hue'),
  44938. slideHelper = container.find('.sp-slider'),
  44939. alphaSliderInner = container.find('.sp-alpha-inner'),
  44940. alphaSlider = container.find('.sp-alpha'),
  44941. alphaSlideHelper = container.find('.sp-alpha-handle'),
  44942. textInput = container.find('.sp-input'),
  44943. paletteContainer = container.find('.sp-palette'),
  44944. initialColorContainer = container.find('.sp-initial'),
  44945. cancelButton = container.find('.sp-cancel'),
  44946. clearButton = container.find('.sp-clear'),
  44947. chooseButton = container.find('.sp-choose'),
  44948. toggleButton = container.find('.sp-palette-toggle'),
  44949. isInput = boundElement.is('input'),
  44950. isInputTypeColor = isInput && boundElement.attr('type') === 'color' && inputTypeColorSupport(),
  44951. shouldReplace = isInput && !flat,
  44952. replacer = shouldReplace ? $(replaceInput).addClass(theme).addClass(opts.className).addClass(opts.replacerClassName) : $([]),
  44953. offsetElement = shouldReplace ? replacer : boundElement,
  44954. previewElement = replacer.find('.sp-preview-inner'),
  44955. initialColor = opts.color || isInput && boundElement.val(),
  44956. colorOnShow = false,
  44957. currentPreferredFormat = opts.preferredFormat,
  44958. clickoutFiresChange = !opts.showButtons || opts.clickoutFiresChange,
  44959. isEmpty = !initialColor,
  44960. allowEmpty = opts.allowEmpty && !isInputTypeColor;
  44961. function applyOptions() {
  44962. if (opts.showPaletteOnly) {
  44963. opts.showPalette = true;
  44964. }
  44965. toggleButton.text(opts.showPaletteOnly ? opts.togglePaletteMoreText : opts.togglePaletteLessText);
  44966. if (opts.palette) {
  44967. palette = opts.palette.slice(0);
  44968. paletteArray = $.isArray(palette[0]) ? palette : [palette];
  44969. paletteLookup = {};
  44970. for (var i = 0; i < paletteArray.length; i++) {
  44971. for (var j = 0; j < paletteArray[i].length; j++) {
  44972. var rgb = tinycolor(paletteArray[i][j]).toRgbString();
  44973. paletteLookup[rgb] = true;
  44974. }
  44975. }
  44976. }
  44977. container.toggleClass('sp-flat', flat);
  44978. container.toggleClass('sp-input-disabled', !opts.showInput);
  44979. container.toggleClass('sp-alpha-enabled', opts.showAlpha);
  44980. container.toggleClass('sp-clear-enabled', allowEmpty);
  44981. container.toggleClass('sp-buttons-disabled', !opts.showButtons);
  44982. container.toggleClass('sp-palette-buttons-disabled', !opts.togglePaletteOnly);
  44983. container.toggleClass('sp-palette-disabled', !opts.showPalette);
  44984. container.toggleClass('sp-palette-only', opts.showPaletteOnly);
  44985. container.toggleClass('sp-initial-disabled', !opts.showInitial);
  44986. container.addClass(opts.className).addClass(opts.containerClassName);
  44987. reflow();
  44988. }
  44989. function initialize() {
  44990. if (IE) {
  44991. container.find('*:not(input)').attr('unselectable', 'on');
  44992. }
  44993. applyOptions();
  44994. if (shouldReplace) {
  44995. boundElement.after(replacer).hide();
  44996. }
  44997. if (!allowEmpty) {
  44998. clearButton.hide();
  44999. }
  45000. if (flat) {
  45001. boundElement.after(container).hide();
  45002. } else {
  45003. var appendTo = opts.appendTo === 'parent' ? boundElement.parent() : $(opts.appendTo);
  45004. if (appendTo.length !== 1) {
  45005. appendTo = $('body');
  45006. }
  45007. appendTo.append(container);
  45008. }
  45009. updateSelectionPaletteFromStorage();
  45010. offsetElement.bind('click.spectrum touchstart.spectrum', function (e) {
  45011. if (!disabled) {
  45012. toggle();
  45013. }
  45014. e.stopPropagation();
  45015. if (!$(e.target).is('input')) {
  45016. e.preventDefault();
  45017. }
  45018. });
  45019. if (boundElement.is(':disabled') || opts.disabled === true) {
  45020. disable();
  45021. } // Prevent clicks from bubbling up to document. This would cause it to be hidden.
  45022. container.click(stopPropagation); // Handle user typed input
  45023. textInput.change(setFromTextInput);
  45024. textInput.bind('paste', function () {
  45025. setTimeout(setFromTextInput, 1);
  45026. });
  45027. textInput.keydown(function (e) {
  45028. if (e.keyCode == 13) {
  45029. setFromTextInput();
  45030. }
  45031. });
  45032. cancelButton.text(opts.cancelText);
  45033. cancelButton.bind('click.spectrum', function (e) {
  45034. e.stopPropagation();
  45035. e.preventDefault();
  45036. revert();
  45037. hide();
  45038. });
  45039. clearButton.attr('title', opts.clearText);
  45040. clearButton.bind('click.spectrum', function (e) {
  45041. e.stopPropagation();
  45042. e.preventDefault();
  45043. isEmpty = true;
  45044. move();
  45045. if (flat) {
  45046. //for the flat style, this is a change event
  45047. updateOriginalInput(true);
  45048. }
  45049. });
  45050. chooseButton.text(opts.chooseText);
  45051. chooseButton.bind('click.spectrum', function (e) {
  45052. e.stopPropagation();
  45053. e.preventDefault();
  45054. if (IE && textInput.is(':focus')) {
  45055. textInput.trigger('change');
  45056. }
  45057. if (isValid()) {
  45058. updateOriginalInput(true);
  45059. hide();
  45060. }
  45061. });
  45062. toggleButton.text(opts.showPaletteOnly ? opts.togglePaletteMoreText : opts.togglePaletteLessText);
  45063. toggleButton.bind('click.spectrum', function (e) {
  45064. e.stopPropagation();
  45065. e.preventDefault();
  45066. opts.showPaletteOnly = !opts.showPaletteOnly; // To make sure the Picker area is drawn on the right, next to the
  45067. // Palette area (and not below the palette), first move the Palette
  45068. // to the left to make space for the picker, plus 5px extra.
  45069. // The 'applyOptions' function puts the whole container back into place
  45070. // and takes care of the button-text and the sp-palette-only CSS class.
  45071. if (!opts.showPaletteOnly && !flat) {
  45072. container.css('left', '-=' + (pickerContainer.outerWidth(true) + 5));
  45073. }
  45074. applyOptions();
  45075. });
  45076. draggable(alphaSlider, function (dragX, dragY, e) {
  45077. currentAlpha = dragX / alphaWidth;
  45078. isEmpty = false;
  45079. if (e.shiftKey) {
  45080. currentAlpha = Math.round(currentAlpha * 10) / 10;
  45081. }
  45082. move();
  45083. }, dragStart, dragStop);
  45084. draggable(slider, function (dragX, dragY) {
  45085. currentHue = parseFloat(dragY / slideHeight);
  45086. isEmpty = false;
  45087. if (!opts.showAlpha) {
  45088. currentAlpha = 1;
  45089. }
  45090. move();
  45091. }, dragStart, dragStop);
  45092. draggable(dragger, function (dragX, dragY, e) {
  45093. // shift+drag should snap the movement to either the x or y axis.
  45094. if (!e.shiftKey) {
  45095. shiftMovementDirection = null;
  45096. } else if (!shiftMovementDirection) {
  45097. var oldDragX = currentSaturation * dragWidth;
  45098. var oldDragY = dragHeight - currentValue * dragHeight;
  45099. var furtherFromX = Math.abs(dragX - oldDragX) > Math.abs(dragY - oldDragY);
  45100. shiftMovementDirection = furtherFromX ? 'x' : 'y';
  45101. }
  45102. var setSaturation = !shiftMovementDirection || shiftMovementDirection === 'x';
  45103. var setValue = !shiftMovementDirection || shiftMovementDirection === 'y';
  45104. if (setSaturation) {
  45105. currentSaturation = parseFloat(dragX / dragWidth);
  45106. }
  45107. if (setValue) {
  45108. currentValue = parseFloat((dragHeight - dragY) / dragHeight);
  45109. }
  45110. isEmpty = false;
  45111. if (!opts.showAlpha) {
  45112. currentAlpha = 1;
  45113. }
  45114. move();
  45115. }, dragStart, dragStop);
  45116. if (!!initialColor) {
  45117. _set(initialColor); // In case color was black - update the preview UI and set the format
  45118. // since the set function will not run (default color is black).
  45119. updateUI();
  45120. currentPreferredFormat = opts.preferredFormat || tinycolor(initialColor).format;
  45121. addColorToSelectionPalette(initialColor);
  45122. } else {
  45123. updateUI();
  45124. }
  45125. if (flat) {
  45126. show();
  45127. }
  45128. function paletteElementClick(e) {
  45129. if (e.data && e.data.ignore) {
  45130. _set($(e.target).closest('.sp-thumb-el').data('color'));
  45131. move();
  45132. } else {
  45133. _set($(e.target).closest('.sp-thumb-el').data('color'));
  45134. move();
  45135. updateOriginalInput(true);
  45136. if (opts.hideAfterPaletteSelect) {
  45137. hide();
  45138. }
  45139. }
  45140. return false;
  45141. }
  45142. var paletteEvent = IE ? 'mousedown.spectrum' : 'click.spectrum touchstart.spectrum';
  45143. paletteContainer.delegate('.sp-thumb-el', paletteEvent, paletteElementClick);
  45144. initialColorContainer.delegate('.sp-thumb-el:nth-child(1)', paletteEvent, {
  45145. ignore: true
  45146. }, paletteElementClick);
  45147. }
  45148. function updateSelectionPaletteFromStorage() {
  45149. if (localStorageKey && window.localStorage) {
  45150. // Migrate old palettes over to new format. May want to remove this eventually.
  45151. try {
  45152. var oldPalette = window.localStorage[localStorageKey].split(',#');
  45153. if (oldPalette.length > 1) {
  45154. delete window.localStorage[localStorageKey];
  45155. $.each(oldPalette, function (i, c) {
  45156. addColorToSelectionPalette(c);
  45157. });
  45158. }
  45159. } catch (e) {}
  45160. try {
  45161. selectionPalette = window.localStorage[localStorageKey].split(';');
  45162. } catch (e) {}
  45163. }
  45164. }
  45165. function addColorToSelectionPalette(color) {
  45166. if (showSelectionPalette) {
  45167. var rgb = tinycolor(color).toRgbString();
  45168. if (!paletteLookup[rgb] && $.inArray(rgb, selectionPalette) === -1) {
  45169. selectionPalette.push(rgb);
  45170. while (selectionPalette.length > maxSelectionSize) {
  45171. selectionPalette.shift();
  45172. }
  45173. }
  45174. if (localStorageKey && window.localStorage) {
  45175. try {
  45176. window.localStorage[localStorageKey] = selectionPalette.join(';');
  45177. } catch (e) {}
  45178. }
  45179. }
  45180. }
  45181. function getUniqueSelectionPalette() {
  45182. var unique = [];
  45183. if (opts.showPalette) {
  45184. for (var i = 0; i < selectionPalette.length; i++) {
  45185. var rgb = tinycolor(selectionPalette[i]).toRgbString();
  45186. if (!paletteLookup[rgb]) {
  45187. unique.push(selectionPalette[i]);
  45188. }
  45189. }
  45190. }
  45191. return unique.reverse().slice(0, opts.maxSelectionSize);
  45192. }
  45193. function drawPalette() {
  45194. var currentColor = get();
  45195. var html = $.map(paletteArray, function (palette, i) {
  45196. return paletteTemplate(palette, currentColor, 'sp-palette-row sp-palette-row-' + i, opts);
  45197. });
  45198. updateSelectionPaletteFromStorage();
  45199. if (selectionPalette) {
  45200. html.push(paletteTemplate(getUniqueSelectionPalette(), currentColor, 'sp-palette-row sp-palette-row-selection', opts));
  45201. }
  45202. paletteContainer.html(html.join(''));
  45203. }
  45204. function drawInitial() {
  45205. if (opts.showInitial) {
  45206. var initial = colorOnShow;
  45207. var current = get();
  45208. initialColorContainer.html(paletteTemplate([initial, current], current, 'sp-palette-row-initial', opts));
  45209. }
  45210. }
  45211. function dragStart() {
  45212. if (dragHeight <= 0 || dragWidth <= 0 || slideHeight <= 0) {
  45213. reflow();
  45214. }
  45215. isDragging = true;
  45216. container.addClass(draggingClass);
  45217. shiftMovementDirection = null;
  45218. boundElement.trigger('dragstart.spectrum', [get()]);
  45219. }
  45220. function dragStop() {
  45221. isDragging = false;
  45222. container.removeClass(draggingClass);
  45223. boundElement.trigger('dragstop.spectrum', [get()]);
  45224. }
  45225. function setFromTextInput() {
  45226. var value = textInput.val();
  45227. if ((value === null || value === '') && allowEmpty) {
  45228. _set(null);
  45229. updateOriginalInput(true);
  45230. } else {
  45231. var tiny = tinycolor(value);
  45232. if (tiny.isValid()) {
  45233. _set(tiny);
  45234. updateOriginalInput(true);
  45235. } else {
  45236. textInput.addClass('sp-validation-error');
  45237. }
  45238. }
  45239. }
  45240. function toggle() {
  45241. if (visible) {
  45242. hide();
  45243. } else {
  45244. show();
  45245. }
  45246. }
  45247. function show() {
  45248. var event = $.Event('beforeShow.spectrum');
  45249. if (visible) {
  45250. reflow();
  45251. return;
  45252. }
  45253. boundElement.trigger('beforeShow.spectrum', [get()]);
  45254. if (callbacks.beforeShow(get()) === false || event.isDefaultPrevented()) {
  45255. return;
  45256. }
  45257. hideAll();
  45258. visible = true;
  45259. var $doc = $(doc);
  45260. $doc.bind('keydown.spectrum', onkeydown);
  45261. $doc.bind('click.spectrum', clickout);
  45262. $(window).bind('resize.spectrum', resize);
  45263. replacer.addClass('sp-active');
  45264. container.removeClass('sp-hidden');
  45265. reflow();
  45266. updateUI();
  45267. colorOnShow = get();
  45268. drawInitial();
  45269. callbacks.show(colorOnShow);
  45270. boundElement.trigger('show.spectrum', [colorOnShow]);
  45271. }
  45272. function onkeydown(e) {
  45273. // Close on ESC
  45274. if (e.keyCode === 27) {
  45275. hide();
  45276. }
  45277. }
  45278. function clickout(e) {
  45279. // Return on right click.
  45280. if (e.button == 2) {
  45281. return;
  45282. } // If a drag event was happening during the mouseup, don't hide
  45283. // on click.
  45284. if (isDragging) {
  45285. return;
  45286. }
  45287. if (clickoutFiresChange) {
  45288. updateOriginalInput(true);
  45289. } else {
  45290. revert();
  45291. }
  45292. hide();
  45293. }
  45294. function hide() {
  45295. // Return if hiding is unnecessary
  45296. if (!visible || flat) {
  45297. return;
  45298. }
  45299. visible = false;
  45300. $(doc).unbind('keydown.spectrum', onkeydown);
  45301. $(doc).unbind('click.spectrum', clickout);
  45302. $(window).unbind('resize.spectrum', resize);
  45303. replacer.removeClass('sp-active');
  45304. container.addClass('sp-hidden');
  45305. callbacks.hide(get());
  45306. boundElement.trigger('hide.spectrum', [get()]);
  45307. }
  45308. function revert() {
  45309. _set(colorOnShow, true);
  45310. }
  45311. function _set(color, ignoreFormatChange) {
  45312. if (tinycolor.equals(color, get())) {
  45313. // Update UI just in case a validation error needs
  45314. // to be cleared.
  45315. updateUI();
  45316. return;
  45317. }
  45318. var newColor, newHsv;
  45319. if (!color && allowEmpty) {
  45320. isEmpty = true;
  45321. } else {
  45322. isEmpty = false;
  45323. newColor = tinycolor(color);
  45324. newHsv = newColor.toHsv();
  45325. currentHue = newHsv.h % 360 / 360;
  45326. currentSaturation = newHsv.s;
  45327. currentValue = newHsv.v;
  45328. currentAlpha = newHsv.a;
  45329. }
  45330. updateUI();
  45331. if (newColor && newColor.isValid() && !ignoreFormatChange) {
  45332. currentPreferredFormat = opts.preferredFormat || newColor.getFormat();
  45333. }
  45334. }
  45335. function get(opts) {
  45336. opts = opts || {};
  45337. if (allowEmpty && isEmpty) {
  45338. return null;
  45339. }
  45340. return tinycolor.fromRatio({
  45341. h: currentHue,
  45342. s: currentSaturation,
  45343. v: currentValue,
  45344. a: Math.round(currentAlpha * 100) / 100
  45345. }, {
  45346. format: opts.format || currentPreferredFormat
  45347. });
  45348. }
  45349. function isValid() {
  45350. return !textInput.hasClass('sp-validation-error');
  45351. }
  45352. function move() {
  45353. updateUI();
  45354. callbacks.move(get());
  45355. boundElement.trigger('move.spectrum', [get()]);
  45356. }
  45357. function updateUI() {
  45358. textInput.removeClass('sp-validation-error');
  45359. updateHelperLocations(); // Update dragger background color (gradients take care of saturation and value).
  45360. var flatColor = tinycolor.fromRatio({
  45361. h: currentHue,
  45362. s: 1,
  45363. v: 1
  45364. });
  45365. dragger.css('background-color', flatColor.toHexString()); // Get a format that alpha will be included in (hex and names ignore alpha)
  45366. var format = currentPreferredFormat;
  45367. if (currentAlpha < 1 && !(currentAlpha === 0 && format === 'name')) {
  45368. if (format === 'hex' || format === 'hex3' || format === 'hex6' || format === 'name') {
  45369. format = 'rgb';
  45370. }
  45371. }
  45372. var realColor = get({
  45373. format: format
  45374. }),
  45375. displayColor = ''; //reset background info for preview element
  45376. previewElement.removeClass('sp-clear-display');
  45377. previewElement.css('background-color', 'transparent');
  45378. if (!realColor && allowEmpty) {
  45379. // Update the replaced elements background with icon indicating no color selection
  45380. previewElement.addClass('sp-clear-display');
  45381. } else {
  45382. var realHex = realColor.toHexString(),
  45383. realRgb = realColor.toRgbString(); // Update the replaced elements background color (with actual selected color)
  45384. if (rgbaSupport || realColor.alpha === 1) {
  45385. previewElement.css('background-color', realRgb);
  45386. } else {
  45387. previewElement.css('background-color', 'transparent');
  45388. previewElement.css('filter', realColor.toFilter());
  45389. }
  45390. if (opts.showAlpha) {
  45391. var rgb = realColor.toRgb();
  45392. rgb.a = 0;
  45393. var realAlpha = tinycolor(rgb).toRgbString();
  45394. var gradient = 'linear-gradient(left, ' + realAlpha + ', ' + realHex + ')';
  45395. if (IE) {
  45396. alphaSliderInner.css('filter', tinycolor(realAlpha).toFilter({
  45397. gradientType: 1
  45398. }, realHex));
  45399. } else {
  45400. alphaSliderInner.css('background', '-webkit-' + gradient);
  45401. alphaSliderInner.css('background', '-moz-' + gradient);
  45402. alphaSliderInner.css('background', '-ms-' + gradient); // Use current syntax gradient on unprefixed property.
  45403. alphaSliderInner.css('background', 'linear-gradient(to right, ' + realAlpha + ', ' + realHex + ')');
  45404. }
  45405. }
  45406. displayColor = realColor.toString(format);
  45407. } // Update the text entry input as it changes happen
  45408. if (opts.showInput) {
  45409. textInput.val(displayColor);
  45410. }
  45411. if (opts.showPalette) {
  45412. drawPalette();
  45413. }
  45414. drawInitial();
  45415. }
  45416. function updateHelperLocations() {
  45417. var s = currentSaturation;
  45418. var v = currentValue;
  45419. if (allowEmpty && isEmpty) {
  45420. //if selected color is empty, hide the helpers
  45421. alphaSlideHelper.hide();
  45422. slideHelper.hide();
  45423. dragHelper.hide();
  45424. } else {
  45425. //make sure helpers are visible
  45426. alphaSlideHelper.show();
  45427. slideHelper.show();
  45428. dragHelper.show(); // Where to show the little circle in that displays your current selected color
  45429. var dragX = s * dragWidth;
  45430. var dragY = dragHeight - v * dragHeight;
  45431. dragX = Math.max(-dragHelperHeight, Math.min(dragWidth - dragHelperHeight, dragX - dragHelperHeight));
  45432. dragY = Math.max(-dragHelperHeight, Math.min(dragHeight - dragHelperHeight, dragY - dragHelperHeight));
  45433. dragHelper.css({
  45434. top: dragY + 'px',
  45435. left: dragX + 'px'
  45436. });
  45437. var alphaX = currentAlpha * alphaWidth;
  45438. alphaSlideHelper.css({
  45439. left: alphaX - alphaSlideHelperWidth / 2 + 'px'
  45440. }); // Where to show the bar that displays your current selected hue
  45441. var slideY = currentHue * slideHeight;
  45442. slideHelper.css({
  45443. top: slideY - slideHelperHeight + 'px'
  45444. });
  45445. }
  45446. }
  45447. function updateOriginalInput(fireCallback) {
  45448. var color = get(),
  45449. displayColor = '',
  45450. hasChanged = !tinycolor.equals(color, colorOnShow);
  45451. if (color) {
  45452. displayColor = color.toString(currentPreferredFormat); // Update the selection palette with the current color
  45453. addColorToSelectionPalette(color);
  45454. }
  45455. if (isInput) {
  45456. boundElement.val(displayColor);
  45457. }
  45458. if (fireCallback && hasChanged) {
  45459. callbacks.change(color);
  45460. boundElement.trigger('change', [color]);
  45461. }
  45462. }
  45463. function reflow() {
  45464. if (!visible) {
  45465. return; // Calculations would be useless and wouldn't be reliable anyways
  45466. }
  45467. dragWidth = dragger.width();
  45468. dragHeight = dragger.height();
  45469. dragHelperHeight = dragHelper.height();
  45470. slideWidth = slider.width();
  45471. slideHeight = slider.height();
  45472. slideHelperHeight = slideHelper.height();
  45473. alphaWidth = alphaSlider.width();
  45474. alphaSlideHelperWidth = alphaSlideHelper.width();
  45475. if (!flat) {
  45476. container.css('position', 'absolute');
  45477. if (opts.offset) {
  45478. container.offset(opts.offset);
  45479. } else {
  45480. container.offset(getOffset(container, offsetElement));
  45481. }
  45482. }
  45483. updateHelperLocations();
  45484. if (opts.showPalette) {
  45485. drawPalette();
  45486. }
  45487. boundElement.trigger('reflow.spectrum');
  45488. }
  45489. function destroy() {
  45490. boundElement.show();
  45491. offsetElement.unbind('click.spectrum touchstart.spectrum');
  45492. container.remove();
  45493. replacer.remove();
  45494. spectrums[spect.id] = null;
  45495. }
  45496. function option(optionName, optionValue) {
  45497. if (optionName === undefined) {
  45498. return $.extend({}, opts);
  45499. }
  45500. if (optionValue === undefined) {
  45501. return opts[optionName];
  45502. }
  45503. opts[optionName] = optionValue;
  45504. if (optionName === 'preferredFormat') {
  45505. currentPreferredFormat = opts.preferredFormat;
  45506. }
  45507. applyOptions();
  45508. }
  45509. function enable() {
  45510. disabled = false;
  45511. boundElement.attr('disabled', false);
  45512. offsetElement.removeClass('sp-disabled');
  45513. }
  45514. function disable() {
  45515. hide();
  45516. disabled = true;
  45517. boundElement.attr('disabled', true);
  45518. offsetElement.addClass('sp-disabled');
  45519. }
  45520. function setOffset(coord) {
  45521. opts.offset = coord;
  45522. reflow();
  45523. }
  45524. initialize();
  45525. var spect = {
  45526. show: show,
  45527. hide: hide,
  45528. toggle: toggle,
  45529. reflow: reflow,
  45530. option: option,
  45531. enable: enable,
  45532. disable: disable,
  45533. offset: setOffset,
  45534. set: function set(c) {
  45535. _set(c);
  45536. updateOriginalInput();
  45537. },
  45538. get: get,
  45539. destroy: destroy,
  45540. container: container
  45541. };
  45542. spect.id = spectrums.push(spect) - 1;
  45543. return spect;
  45544. }
  45545. /**
  45546. * checkOffset - get the offset below/above and left/right element depending on screen position
  45547. * Thanks https://github.com/jquery/jquery-ui/blob/master/ui/jquery.ui.datepicker.js
  45548. */
  45549. function getOffset(picker, input) {
  45550. var extraY = 0;
  45551. var dpWidth = picker.outerWidth();
  45552. var dpHeight = picker.outerHeight();
  45553. var inputHeight = input.outerHeight();
  45554. var doc = picker[0].ownerDocument;
  45555. var docElem = doc.documentElement;
  45556. var cW = docElem.clientWidth;
  45557. var cH = docElem.clientHeight;
  45558. var scL = $(doc).scrollLeft();
  45559. var scT = $(doc).scrollTop();
  45560. var viewWidth = cW + scL;
  45561. var viewHeight = cH + scT;
  45562. var offset = input.offset();
  45563. offset.top += inputHeight;
  45564. offset.left -= Math.min(offset.left, offset.left + dpWidth > viewWidth && viewWidth > dpWidth ? Math.abs(offset.left + dpWidth - viewWidth) : 0);
  45565. offset.top -= Math.min(offset.top, offset.top + dpHeight > viewHeight && viewHeight > dpHeight ? Math.abs(dpHeight + inputHeight - extraY) : extraY);
  45566. return offset;
  45567. }
  45568. /**
  45569. * noop - do nothing
  45570. */
  45571. function noop() {}
  45572. /**
  45573. * stopPropagation - makes the code only doing this a little easier to read in line
  45574. */
  45575. function stopPropagation(e) {
  45576. e.stopPropagation();
  45577. }
  45578. /**
  45579. * Create a function bound to a given object
  45580. * Thanks to underscore.js
  45581. */
  45582. function bind(func, obj) {
  45583. var slice = Array.prototype.slice;
  45584. var args = slice.call(arguments, 2);
  45585. return function () {
  45586. return func.apply(obj, args.concat(slice.call(arguments)));
  45587. };
  45588. }
  45589. /**
  45590. * Lightweight drag helper. Handles containment within the element, so that
  45591. * when dragging, the x is within [0,element.width] and y is within [0,element.height]
  45592. */
  45593. function draggable(element, onmove, onstart, onstop) {
  45594. onmove = onmove || function () {};
  45595. onstart = onstart || function () {};
  45596. onstop = onstop || function () {};
  45597. var doc = document;
  45598. var dragging = false;
  45599. var offset = {};
  45600. var maxHeight = 0;
  45601. var maxWidth = 0;
  45602. var hasTouch = 'ontouchstart' in window;
  45603. var duringDragEvents = {};
  45604. duringDragEvents['selectstart'] = prevent;
  45605. duringDragEvents['dragstart'] = prevent;
  45606. duringDragEvents['touchmove mousemove'] = move;
  45607. duringDragEvents['touchend mouseup'] = stop;
  45608. function prevent(e) {
  45609. if (e.stopPropagation) {
  45610. e.stopPropagation();
  45611. }
  45612. if (e.preventDefault) {
  45613. e.preventDefault();
  45614. }
  45615. e.returnValue = false;
  45616. }
  45617. function move(e) {
  45618. if (dragging) {
  45619. // Mouseup happened outside of window
  45620. if (IE && doc.documentMode < 9 && !e.button) {
  45621. return stop();
  45622. }
  45623. var t0 = e && e.touches && e.touches[0];
  45624. var pageX = t0 && t0.pageX || e.pageX;
  45625. var pageY = t0 && t0.pageY || e.pageY;
  45626. var dragX = Math.max(0, Math.min(pageX - offset.left, maxWidth));
  45627. var dragY = Math.max(0, Math.min(pageY - offset.top, maxHeight));
  45628. if (hasTouch) {
  45629. // Stop scrolling in iOS
  45630. prevent(e);
  45631. }
  45632. onmove.apply(element, [dragX, dragY, e]);
  45633. }
  45634. }
  45635. function start(e) {
  45636. var rightclick = e.which ? e.which == 3 : e.button == 2;
  45637. if (!rightclick && !dragging) {
  45638. if (onstart.apply(element, arguments) !== false) {
  45639. dragging = true;
  45640. maxHeight = $(element).height();
  45641. maxWidth = $(element).width();
  45642. offset = $(element).offset();
  45643. $(doc).bind(duringDragEvents);
  45644. $(doc.body).addClass('sp-dragging');
  45645. move(e);
  45646. prevent(e);
  45647. }
  45648. }
  45649. }
  45650. function stop() {
  45651. if (dragging) {
  45652. $(doc).unbind(duringDragEvents);
  45653. $(doc.body).removeClass('sp-dragging'); // Wait a tick before notifying observers to allow the click event
  45654. // to fire in Chrome.
  45655. setTimeout(function () {
  45656. onstop.apply(element, arguments);
  45657. }, 0);
  45658. }
  45659. dragging = false;
  45660. }
  45661. $(element).bind('touchstart mousedown', start);
  45662. }
  45663. function throttle(func, wait, debounce) {
  45664. var timeout;
  45665. return function () {
  45666. var context = this,
  45667. args = arguments;
  45668. var throttler = function throttler() {
  45669. timeout = null;
  45670. func.apply(context, args);
  45671. };
  45672. if (debounce) clearTimeout(timeout);
  45673. if (debounce || !timeout) timeout = setTimeout(throttler, wait);
  45674. };
  45675. }
  45676. function inputTypeColorSupport() {
  45677. return $.fn.spectrum.inputTypeColorSupport();
  45678. }
  45679. /**
  45680. * Define a jQuery plugin
  45681. */
  45682. var dataID = 'spectrum.id';
  45683. $.fn.spectrum = function (opts, extra) {
  45684. if (typeof opts == 'string') {
  45685. var returnValue = this;
  45686. var args = Array.prototype.slice.call(arguments, 1);
  45687. this.each(function () {
  45688. var spect = spectrums[$(this).data(dataID)];
  45689. if (spect) {
  45690. var method = spect[opts];
  45691. if (!method) {
  45692. throw new Error("Spectrum: no such method: '" + opts + "'");
  45693. }
  45694. if (opts == 'get') {
  45695. returnValue = spect.get();
  45696. } else if (opts == 'container') {
  45697. returnValue = spect.container;
  45698. } else if (opts == 'option') {
  45699. returnValue = spect.option.apply(spect, args);
  45700. } else if (opts == 'destroy') {
  45701. spect.destroy();
  45702. $(this).removeData(dataID);
  45703. } else {
  45704. method.apply(spect, args);
  45705. }
  45706. }
  45707. });
  45708. return returnValue;
  45709. } // Initializing a new instance of spectrum
  45710. return this.spectrum('destroy').each(function () {
  45711. var options = $.extend({}, opts, $(this).data());
  45712. var spect = spectrum(this, options);
  45713. $(this).data(dataID, spect.id);
  45714. });
  45715. };
  45716. $.fn.spectrum.load = true;
  45717. $.fn.spectrum.loadOpts = {};
  45718. $.fn.spectrum.draggable = draggable;
  45719. $.fn.spectrum.defaults = defaultOpts;
  45720. $.fn.spectrum.inputTypeColorSupport = function inputTypeColorSupport() {
  45721. if (typeof inputTypeColorSupport._cachedResult === 'undefined') {
  45722. var colorInput = $("<input type='color'/>")[0]; // if color element is supported, value will default to not null
  45723. inputTypeColorSupport._cachedResult = colorInput.type === 'color' && colorInput.value !== '';
  45724. }
  45725. return inputTypeColorSupport._cachedResult;
  45726. };
  45727. $.spectrum = {};
  45728. $.spectrum.localization = {};
  45729. $.spectrum.palettes = {};
  45730. $.fn.spectrum.processNativeColorInputs = function () {
  45731. var colorInputs = $('input[type=color]');
  45732. if (colorInputs.length && !inputTypeColorSupport()) {
  45733. colorInputs.spectrum({
  45734. preferredFormat: 'hex6'
  45735. });
  45736. }
  45737. }; // TinyColor v1.1.2
  45738. // https://github.com/bgrins/TinyColor
  45739. // Brian Grinstead, MIT License
  45740. //(function() {
  45741. var trimLeft = /^[\s,#]+/,
  45742. trimRight = /\s+$/,
  45743. tinyCounter = 0,
  45744. math = Math,
  45745. mathRound = math.round,
  45746. mathMin = math.min,
  45747. mathMax = math.max,
  45748. mathRandom = math.random;
  45749. var tinycolor = function tinycolor(color, opts) {
  45750. color = color ? color : '';
  45751. opts = opts || {}; // If input is already a tinycolor, return itself
  45752. if (color instanceof tinycolor) {
  45753. return color;
  45754. } // If we are called as a function, call using new instead
  45755. if (!(this instanceof tinycolor)) {
  45756. return new tinycolor(color, opts);
  45757. }
  45758. var rgb = inputToRGB(color);
  45759. this._originalInput = color, this._r = rgb.r, this._g = rgb.g, this._b = rgb.b, this._a = rgb.a, this._roundA = mathRound(100 * this._a) / 100, this._format = opts.format || rgb.format;
  45760. this._gradientType = opts.gradientType; // Don't let the range of [0,255] come back in [0,1].
  45761. // Potentially lose a little bit of precision here, but will fix issues where
  45762. // .5 gets interpreted as half of the total, instead of half of 1
  45763. // If it was supposed to be 128, this was already taken care of by `inputToRgb`
  45764. if (this._r < 1) {
  45765. this._r = mathRound(this._r);
  45766. }
  45767. if (this._g < 1) {
  45768. this._g = mathRound(this._g);
  45769. }
  45770. if (this._b < 1) {
  45771. this._b = mathRound(this._b);
  45772. }
  45773. this._ok = rgb.ok;
  45774. this._tc_id = tinyCounter++;
  45775. };
  45776. tinycolor.prototype = {
  45777. isDark: function isDark() {
  45778. return this.getBrightness() < 128;
  45779. },
  45780. isLight: function isLight() {
  45781. return !this.isDark();
  45782. },
  45783. isValid: function isValid() {
  45784. return this._ok;
  45785. },
  45786. getOriginalInput: function getOriginalInput() {
  45787. return this._originalInput;
  45788. },
  45789. getFormat: function getFormat() {
  45790. return this._format;
  45791. },
  45792. getAlpha: function getAlpha() {
  45793. return this._a;
  45794. },
  45795. getBrightness: function getBrightness() {
  45796. var rgb = this.toRgb();
  45797. return (rgb.r * 299 + rgb.g * 587 + rgb.b * 114) / 1000;
  45798. },
  45799. setAlpha: function setAlpha(value) {
  45800. this._a = boundAlpha(value);
  45801. this._roundA = mathRound(100 * this._a) / 100;
  45802. return this;
  45803. },
  45804. toHsv: function toHsv() {
  45805. var hsv = rgbToHsv(this._r, this._g, this._b);
  45806. return {
  45807. h: hsv.h * 360,
  45808. s: hsv.s,
  45809. v: hsv.v,
  45810. a: this._a
  45811. };
  45812. },
  45813. toHsvString: function toHsvString() {
  45814. var hsv = rgbToHsv(this._r, this._g, this._b);
  45815. var h = mathRound(hsv.h * 360),
  45816. s = mathRound(hsv.s * 100),
  45817. v = mathRound(hsv.v * 100);
  45818. return this._a == 1 ? 'hsv(' + h + ', ' + s + '%, ' + v + '%)' : 'hsva(' + h + ', ' + s + '%, ' + v + '%, ' + this._roundA + ')';
  45819. },
  45820. toHsl: function toHsl() {
  45821. var hsl = rgbToHsl(this._r, this._g, this._b);
  45822. return {
  45823. h: hsl.h * 360,
  45824. s: hsl.s,
  45825. l: hsl.l,
  45826. a: this._a
  45827. };
  45828. },
  45829. toHslString: function toHslString() {
  45830. var hsl = rgbToHsl(this._r, this._g, this._b);
  45831. var h = mathRound(hsl.h * 360),
  45832. s = mathRound(hsl.s * 100),
  45833. l = mathRound(hsl.l * 100);
  45834. return this._a == 1 ? 'hsl(' + h + ', ' + s + '%, ' + l + '%)' : 'hsla(' + h + ', ' + s + '%, ' + l + '%, ' + this._roundA + ')';
  45835. },
  45836. toHex: function toHex(allow3Char) {
  45837. return rgbToHex(this._r, this._g, this._b, allow3Char);
  45838. },
  45839. toHexString: function toHexString(allow3Char) {
  45840. return '#' + this.toHex(allow3Char);
  45841. },
  45842. toHex8: function toHex8() {
  45843. return rgbaToHex(this._r, this._g, this._b, this._a);
  45844. },
  45845. toHex8String: function toHex8String() {
  45846. return '#' + this.toHex8();
  45847. },
  45848. toRgb: function toRgb() {
  45849. return {
  45850. r: mathRound(this._r),
  45851. g: mathRound(this._g),
  45852. b: mathRound(this._b),
  45853. a: this._a
  45854. };
  45855. },
  45856. toRgbString: function toRgbString() {
  45857. return this._a == 1 ? 'rgb(' + mathRound(this._r) + ', ' + mathRound(this._g) + ', ' + mathRound(this._b) + ')' : 'rgba(' + mathRound(this._r) + ', ' + mathRound(this._g) + ', ' + mathRound(this._b) + ', ' + this._roundA + ')';
  45858. },
  45859. toPercentageRgb: function toPercentageRgb() {
  45860. return {
  45861. r: mathRound(bound01(this._r, 255) * 100) + '%',
  45862. g: mathRound(bound01(this._g, 255) * 100) + '%',
  45863. b: mathRound(bound01(this._b, 255) * 100) + '%',
  45864. a: this._a
  45865. };
  45866. },
  45867. toPercentageRgbString: function toPercentageRgbString() {
  45868. return this._a == 1 ? 'rgb(' + mathRound(bound01(this._r, 255) * 100) + '%, ' + mathRound(bound01(this._g, 255) * 100) + '%, ' + mathRound(bound01(this._b, 255) * 100) + '%)' : 'rgba(' + mathRound(bound01(this._r, 255) * 100) + '%, ' + mathRound(bound01(this._g, 255) * 100) + '%, ' + mathRound(bound01(this._b, 255) * 100) + '%, ' + this._roundA + ')';
  45869. },
  45870. toName: function toName() {
  45871. if (this._a === 0) {
  45872. return 'transparent';
  45873. }
  45874. if (this._a < 1) {
  45875. return false;
  45876. }
  45877. return hexNames[rgbToHex(this._r, this._g, this._b, true)] || false;
  45878. },
  45879. toFilter: function toFilter(secondColor) {
  45880. var hex8String = '#' + rgbaToHex(this._r, this._g, this._b, this._a);
  45881. var secondHex8String = hex8String;
  45882. var gradientType = this._gradientType ? 'GradientType = 1, ' : '';
  45883. if (secondColor) {
  45884. var s = tinycolor(secondColor);
  45885. secondHex8String = s.toHex8String();
  45886. }
  45887. return 'progid:DXImageTransform.Microsoft.gradient(' + gradientType + 'startColorstr=' + hex8String + ',endColorstr=' + secondHex8String + ')';
  45888. },
  45889. toString: function toString(format) {
  45890. var formatSet = !!format;
  45891. format = format || this._format;
  45892. var formattedString = false;
  45893. var hasAlpha = this._a < 1 && this._a >= 0;
  45894. var needsAlphaFormat = !formatSet && hasAlpha && (format === 'hex' || format === 'hex6' || format === 'hex3' || format === 'name');
  45895. if (needsAlphaFormat) {
  45896. // Special case for "transparent", all other non-alpha formats
  45897. // will return rgba when there is transparency.
  45898. if (format === 'name' && this._a === 0) {
  45899. return this.toName();
  45900. }
  45901. return this.toRgbString();
  45902. }
  45903. if (format === 'rgb') {
  45904. formattedString = this.toRgbString();
  45905. }
  45906. if (format === 'prgb') {
  45907. formattedString = this.toPercentageRgbString();
  45908. }
  45909. if (format === 'hex' || format === 'hex6') {
  45910. formattedString = this.toHexString();
  45911. }
  45912. if (format === 'hex3') {
  45913. formattedString = this.toHexString(true);
  45914. }
  45915. if (format === 'hex8') {
  45916. formattedString = this.toHex8String();
  45917. }
  45918. if (format === 'name') {
  45919. formattedString = this.toName();
  45920. }
  45921. if (format === 'hsl') {
  45922. formattedString = this.toHslString();
  45923. }
  45924. if (format === 'hsv') {
  45925. formattedString = this.toHsvString();
  45926. }
  45927. return formattedString || this.toHexString();
  45928. },
  45929. _applyModification: function _applyModification(fn, args) {
  45930. var color = fn.apply(null, [this].concat([].slice.call(args)));
  45931. this._r = color._r;
  45932. this._g = color._g;
  45933. this._b = color._b;
  45934. this.setAlpha(color._a);
  45935. return this;
  45936. },
  45937. lighten: function lighten() {
  45938. return this._applyModification(_lighten, arguments);
  45939. },
  45940. brighten: function brighten() {
  45941. return this._applyModification(_brighten, arguments);
  45942. },
  45943. darken: function darken() {
  45944. return this._applyModification(_darken, arguments);
  45945. },
  45946. desaturate: function desaturate() {
  45947. return this._applyModification(_desaturate, arguments);
  45948. },
  45949. saturate: function saturate() {
  45950. return this._applyModification(_saturate, arguments);
  45951. },
  45952. greyscale: function greyscale() {
  45953. return this._applyModification(_greyscale, arguments);
  45954. },
  45955. spin: function spin() {
  45956. return this._applyModification(_spin, arguments);
  45957. },
  45958. _applyCombination: function _applyCombination(fn, args) {
  45959. return fn.apply(null, [this].concat([].slice.call(args)));
  45960. },
  45961. analogous: function analogous() {
  45962. return this._applyCombination(_analogous, arguments);
  45963. },
  45964. complement: function complement() {
  45965. return this._applyCombination(_complement, arguments);
  45966. },
  45967. monochromatic: function monochromatic() {
  45968. return this._applyCombination(_monochromatic, arguments);
  45969. },
  45970. splitcomplement: function splitcomplement() {
  45971. return this._applyCombination(_splitcomplement, arguments);
  45972. },
  45973. triad: function triad() {
  45974. return this._applyCombination(_triad, arguments);
  45975. },
  45976. tetrad: function tetrad() {
  45977. return this._applyCombination(_tetrad, arguments);
  45978. }
  45979. }; // If input is an object, force 1 into "1.0" to handle ratios properly
  45980. // String input requires "1.0" as input, so 1 will be treated as 1
  45981. tinycolor.fromRatio = function (color, opts) {
  45982. if (_babel_runtime_helpers_typeof__WEBPACK_IMPORTED_MODULE_0___default()(color) == 'object') {
  45983. var newColor = {};
  45984. for (var i in color) {
  45985. if (color.hasOwnProperty(i)) {
  45986. if (i === 'a') {
  45987. newColor[i] = color[i];
  45988. } else {
  45989. newColor[i] = convertToPercentage(color[i]);
  45990. }
  45991. }
  45992. }
  45993. color = newColor;
  45994. }
  45995. return tinycolor(color, opts);
  45996. }; // Given a string or object, convert that input to RGB
  45997. // Possible string inputs:
  45998. //
  45999. // "red"
  46000. // "#f00" or "f00"
  46001. // "#ff0000" or "ff0000"
  46002. // "#ff000000" or "ff000000"
  46003. // "rgb 255 0 0" or "rgb (255, 0, 0)"
  46004. // "rgb 1.0 0 0" or "rgb (1, 0, 0)"
  46005. // "rgba (255, 0, 0, 1)" or "rgba 255, 0, 0, 1"
  46006. // "rgba (1.0, 0, 0, 1)" or "rgba 1.0, 0, 0, 1"
  46007. // "hsl(0, 100%, 50%)" or "hsl 0 100% 50%"
  46008. // "hsla(0, 100%, 50%, 1)" or "hsla 0 100% 50%, 1"
  46009. // "hsv(0, 100%, 100%)" or "hsv 0 100% 100%"
  46010. //
  46011. function inputToRGB(color) {
  46012. var rgb = {
  46013. r: 0,
  46014. g: 0,
  46015. b: 0
  46016. };
  46017. var a = 1;
  46018. var ok = false;
  46019. var format = false;
  46020. if (typeof color == 'string') {
  46021. color = stringInputToObject(color);
  46022. }
  46023. if (_babel_runtime_helpers_typeof__WEBPACK_IMPORTED_MODULE_0___default()(color) == 'object') {
  46024. if (color.hasOwnProperty('r') && color.hasOwnProperty('g') && color.hasOwnProperty('b')) {
  46025. rgb = rgbToRgb(color.r, color.g, color.b);
  46026. ok = true;
  46027. format = String(color.r).substr(-1) === '%' ? 'prgb' : 'rgb';
  46028. } else if (color.hasOwnProperty('h') && color.hasOwnProperty('s') && color.hasOwnProperty('v')) {
  46029. color.s = convertToPercentage(color.s);
  46030. color.v = convertToPercentage(color.v);
  46031. rgb = hsvToRgb(color.h, color.s, color.v);
  46032. ok = true;
  46033. format = 'hsv';
  46034. } else if (color.hasOwnProperty('h') && color.hasOwnProperty('s') && color.hasOwnProperty('l')) {
  46035. color.s = convertToPercentage(color.s);
  46036. color.l = convertToPercentage(color.l);
  46037. rgb = hslToRgb(color.h, color.s, color.l);
  46038. ok = true;
  46039. format = 'hsl';
  46040. }
  46041. if (color.hasOwnProperty('a')) {
  46042. a = color.a;
  46043. }
  46044. }
  46045. a = boundAlpha(a);
  46046. return {
  46047. ok: ok,
  46048. format: color.format || format,
  46049. r: mathMin(255, mathMax(rgb.r, 0)),
  46050. g: mathMin(255, mathMax(rgb.g, 0)),
  46051. b: mathMin(255, mathMax(rgb.b, 0)),
  46052. a: a
  46053. };
  46054. } // Conversion Functions
  46055. // --------------------
  46056. // `rgbToHsl`, `rgbToHsv`, `hslToRgb`, `hsvToRgb` modified from:
  46057. // <http://mjijackson.com/2008/02/rgb-to-hsl-and-rgb-to-hsv-color-model-conversion-algorithms-in-javascript>
  46058. // `rgbToRgb`
  46059. // Handle bounds / percentage checking to conform to CSS color spec
  46060. // <http://www.w3.org/TR/css3-color/>
  46061. // *Assumes:* r, g, b in [0, 255] or [0, 1]
  46062. // *Returns:* { r, g, b } in [0, 255]
  46063. function rgbToRgb(r, g, b) {
  46064. return {
  46065. r: bound01(r, 255) * 255,
  46066. g: bound01(g, 255) * 255,
  46067. b: bound01(b, 255) * 255
  46068. };
  46069. } // `rgbToHsl`
  46070. // Converts an RGB color value to HSL.
  46071. // *Assumes:* r, g, and b are contained in [0, 255] or [0, 1]
  46072. // *Returns:* { h, s, l } in [0,1]
  46073. function rgbToHsl(r, g, b) {
  46074. r = bound01(r, 255);
  46075. g = bound01(g, 255);
  46076. b = bound01(b, 255);
  46077. var max = mathMax(r, g, b),
  46078. min = mathMin(r, g, b);
  46079. var h,
  46080. s,
  46081. l = (max + min) / 2;
  46082. if (max == min) {
  46083. h = s = 0; // achromatic
  46084. } else {
  46085. var d = max - min;
  46086. s = l > 0.5 ? d / (2 - max - min) : d / (max + min);
  46087. switch (max) {
  46088. case r:
  46089. h = (g - b) / d + (g < b ? 6 : 0);
  46090. break;
  46091. case g:
  46092. h = (b - r) / d + 2;
  46093. break;
  46094. case b:
  46095. h = (r - g) / d + 4;
  46096. break;
  46097. }
  46098. h /= 6;
  46099. }
  46100. return {
  46101. h: h,
  46102. s: s,
  46103. l: l
  46104. };
  46105. } // `hslToRgb`
  46106. // Converts an HSL color value to RGB.
  46107. // *Assumes:* h is contained in [0, 1] or [0, 360] and s and l are contained [0, 1] or [0, 100]
  46108. // *Returns:* { r, g, b } in the set [0, 255]
  46109. function hslToRgb(h, s, l) {
  46110. var r, g, b;
  46111. h = bound01(h, 360);
  46112. s = bound01(s, 100);
  46113. l = bound01(l, 100);
  46114. function hue2rgb(p, q, t) {
  46115. if (t < 0) t += 1;
  46116. if (t > 1) t -= 1;
  46117. if (t < 1 / 6) return p + (q - p) * 6 * t;
  46118. if (t < 1 / 2) return q;
  46119. if (t < 2 / 3) return p + (q - p) * (2 / 3 - t) * 6;
  46120. return p;
  46121. }
  46122. if (s === 0) {
  46123. r = g = b = l; // achromatic
  46124. } else {
  46125. var q = l < 0.5 ? l * (1 + s) : l + s - l * s;
  46126. var p = 2 * l - q;
  46127. r = hue2rgb(p, q, h + 1 / 3);
  46128. g = hue2rgb(p, q, h);
  46129. b = hue2rgb(p, q, h - 1 / 3);
  46130. }
  46131. return {
  46132. r: r * 255,
  46133. g: g * 255,
  46134. b: b * 255
  46135. };
  46136. } // `rgbToHsv`
  46137. // Converts an RGB color value to HSV
  46138. // *Assumes:* r, g, and b are contained in the set [0, 255] or [0, 1]
  46139. // *Returns:* { h, s, v } in [0,1]
  46140. function rgbToHsv(r, g, b) {
  46141. r = bound01(r, 255);
  46142. g = bound01(g, 255);
  46143. b = bound01(b, 255);
  46144. var max = mathMax(r, g, b),
  46145. min = mathMin(r, g, b);
  46146. var h,
  46147. s,
  46148. v = max;
  46149. var d = max - min;
  46150. s = max === 0 ? 0 : d / max;
  46151. if (max == min) {
  46152. h = 0; // achromatic
  46153. } else {
  46154. switch (max) {
  46155. case r:
  46156. h = (g - b) / d + (g < b ? 6 : 0);
  46157. break;
  46158. case g:
  46159. h = (b - r) / d + 2;
  46160. break;
  46161. case b:
  46162. h = (r - g) / d + 4;
  46163. break;
  46164. }
  46165. h /= 6;
  46166. }
  46167. return {
  46168. h: h,
  46169. s: s,
  46170. v: v
  46171. };
  46172. } // `hsvToRgb`
  46173. // Converts an HSV color value to RGB.
  46174. // *Assumes:* h is contained in [0, 1] or [0, 360] and s and v are contained in [0, 1] or [0, 100]
  46175. // *Returns:* { r, g, b } in the set [0, 255]
  46176. function hsvToRgb(h, s, v) {
  46177. h = bound01(h, 360) * 6;
  46178. s = bound01(s, 100);
  46179. v = bound01(v, 100);
  46180. var i = math.floor(h),
  46181. f = h - i,
  46182. p = v * (1 - s),
  46183. q = v * (1 - f * s),
  46184. t = v * (1 - (1 - f) * s),
  46185. mod = i % 6,
  46186. r = [v, q, p, p, t, v][mod],
  46187. g = [t, v, v, q, p, p][mod],
  46188. b = [p, p, t, v, v, q][mod];
  46189. return {
  46190. r: r * 255,
  46191. g: g * 255,
  46192. b: b * 255
  46193. };
  46194. } // `rgbToHex`
  46195. // Converts an RGB color to hex
  46196. // Assumes r, g, and b are contained in the set [0, 255]
  46197. // Returns a 3 or 6 character hex
  46198. function rgbToHex(r, g, b, allow3Char) {
  46199. var hex = [pad2(mathRound(r).toString(16)), pad2(mathRound(g).toString(16)), pad2(mathRound(b).toString(16))]; // Return a 3 character hex if possible
  46200. if (allow3Char && hex[0].charAt(0) == hex[0].charAt(1) && hex[1].charAt(0) == hex[1].charAt(1) && hex[2].charAt(0) == hex[2].charAt(1)) {
  46201. return hex[0].charAt(0) + hex[1].charAt(0) + hex[2].charAt(0);
  46202. }
  46203. return hex.join('');
  46204. } // `rgbaToHex`
  46205. // Converts an RGBA color plus alpha transparency to hex
  46206. // Assumes r, g, b and a are contained in the set [0, 255]
  46207. // Returns an 8 character hex
  46208. function rgbaToHex(r, g, b, a) {
  46209. var hex = [pad2(convertDecimalToHex(a)), pad2(mathRound(r).toString(16)), pad2(mathRound(g).toString(16)), pad2(mathRound(b).toString(16))];
  46210. return hex.join('');
  46211. } // `equals`
  46212. // Can be called with any tinycolor input
  46213. tinycolor.equals = function (color1, color2) {
  46214. if (!color1 || !color2) {
  46215. return false;
  46216. }
  46217. return tinycolor(color1).toRgbString() == tinycolor(color2).toRgbString();
  46218. };
  46219. tinycolor.random = function () {
  46220. return tinycolor.fromRatio({
  46221. r: mathRandom(),
  46222. g: mathRandom(),
  46223. b: mathRandom()
  46224. });
  46225. }; // Modification Functions
  46226. // ----------------------
  46227. // Thanks to less.js for some of the basics here
  46228. // <https://github.com/cloudhead/less.js/blob/master/lib/less/functions.js>
  46229. function _desaturate(color, amount) {
  46230. amount = amount === 0 ? 0 : amount || 10;
  46231. var hsl = tinycolor(color).toHsl();
  46232. hsl.s -= amount / 100;
  46233. hsl.s = clamp01(hsl.s);
  46234. return tinycolor(hsl);
  46235. }
  46236. function _saturate(color, amount) {
  46237. amount = amount === 0 ? 0 : amount || 10;
  46238. var hsl = tinycolor(color).toHsl();
  46239. hsl.s += amount / 100;
  46240. hsl.s = clamp01(hsl.s);
  46241. return tinycolor(hsl);
  46242. }
  46243. function _greyscale(color) {
  46244. return tinycolor(color).desaturate(100);
  46245. }
  46246. function _lighten(color, amount) {
  46247. amount = amount === 0 ? 0 : amount || 10;
  46248. var hsl = tinycolor(color).toHsl();
  46249. hsl.l += amount / 100;
  46250. hsl.l = clamp01(hsl.l);
  46251. return tinycolor(hsl);
  46252. }
  46253. function _brighten(color, amount) {
  46254. amount = amount === 0 ? 0 : amount || 10;
  46255. var rgb = tinycolor(color).toRgb();
  46256. rgb.r = mathMax(0, mathMin(255, rgb.r - mathRound(255 * -(amount / 100))));
  46257. rgb.g = mathMax(0, mathMin(255, rgb.g - mathRound(255 * -(amount / 100))));
  46258. rgb.b = mathMax(0, mathMin(255, rgb.b - mathRound(255 * -(amount / 100))));
  46259. return tinycolor(rgb);
  46260. }
  46261. function _darken(color, amount) {
  46262. amount = amount === 0 ? 0 : amount || 10;
  46263. var hsl = tinycolor(color).toHsl();
  46264. hsl.l -= amount / 100;
  46265. hsl.l = clamp01(hsl.l);
  46266. return tinycolor(hsl);
  46267. } // Spin takes a positive or negative amount within [-360, 360] indicating the change of hue.
  46268. // Values outside of this range will be wrapped into this range.
  46269. function _spin(color, amount) {
  46270. var hsl = tinycolor(color).toHsl();
  46271. var hue = (mathRound(hsl.h) + amount) % 360;
  46272. hsl.h = hue < 0 ? 360 + hue : hue;
  46273. return tinycolor(hsl);
  46274. } // Combination Functions
  46275. // ---------------------
  46276. // Thanks to jQuery xColor for some of the ideas behind these
  46277. // <https://github.com/infusion/jQuery-xcolor/blob/master/jquery.xcolor.js>
  46278. function _complement(color) {
  46279. var hsl = tinycolor(color).toHsl();
  46280. hsl.h = (hsl.h + 180) % 360;
  46281. return tinycolor(hsl);
  46282. }
  46283. function _triad(color) {
  46284. var hsl = tinycolor(color).toHsl();
  46285. var h = hsl.h;
  46286. return [tinycolor(color), tinycolor({
  46287. h: (h + 120) % 360,
  46288. s: hsl.s,
  46289. l: hsl.l
  46290. }), tinycolor({
  46291. h: (h + 240) % 360,
  46292. s: hsl.s,
  46293. l: hsl.l
  46294. })];
  46295. }
  46296. function _tetrad(color) {
  46297. var hsl = tinycolor(color).toHsl();
  46298. var h = hsl.h;
  46299. return [tinycolor(color), tinycolor({
  46300. h: (h + 90) % 360,
  46301. s: hsl.s,
  46302. l: hsl.l
  46303. }), tinycolor({
  46304. h: (h + 180) % 360,
  46305. s: hsl.s,
  46306. l: hsl.l
  46307. }), tinycolor({
  46308. h: (h + 270) % 360,
  46309. s: hsl.s,
  46310. l: hsl.l
  46311. })];
  46312. }
  46313. function _splitcomplement(color) {
  46314. var hsl = tinycolor(color).toHsl();
  46315. var h = hsl.h;
  46316. return [tinycolor(color), tinycolor({
  46317. h: (h + 72) % 360,
  46318. s: hsl.s,
  46319. l: hsl.l
  46320. }), tinycolor({
  46321. h: (h + 216) % 360,
  46322. s: hsl.s,
  46323. l: hsl.l
  46324. })];
  46325. }
  46326. function _analogous(color, results, slices) {
  46327. results = results || 6;
  46328. slices = slices || 30;
  46329. var hsl = tinycolor(color).toHsl();
  46330. var part = 360 / slices;
  46331. var ret = [tinycolor(color)];
  46332. for (hsl.h = (hsl.h - (part * results >> 1) + 720) % 360; --results;) {
  46333. hsl.h = (hsl.h + part) % 360;
  46334. ret.push(tinycolor(hsl));
  46335. }
  46336. return ret;
  46337. }
  46338. function _monochromatic(color, results) {
  46339. results = results || 6;
  46340. var hsv = tinycolor(color).toHsv();
  46341. var h = hsv.h,
  46342. s = hsv.s,
  46343. v = hsv.v;
  46344. var ret = [];
  46345. var modification = 1 / results;
  46346. while (results--) {
  46347. ret.push(tinycolor({
  46348. h: h,
  46349. s: s,
  46350. v: v
  46351. }));
  46352. v = (v + modification) % 1;
  46353. }
  46354. return ret;
  46355. } // Utility Functions
  46356. // ---------------------
  46357. tinycolor.mix = function (color1, color2, amount) {
  46358. amount = amount === 0 ? 0 : amount || 50;
  46359. var rgb1 = tinycolor(color1).toRgb();
  46360. var rgb2 = tinycolor(color2).toRgb();
  46361. var p = amount / 100;
  46362. var w = p * 2 - 1;
  46363. var a = rgb2.a - rgb1.a;
  46364. var w1;
  46365. if (w * a == -1) {
  46366. w1 = w;
  46367. } else {
  46368. w1 = (w + a) / (1 + w * a);
  46369. }
  46370. w1 = (w1 + 1) / 2;
  46371. var w2 = 1 - w1;
  46372. var rgba = {
  46373. r: rgb2.r * w1 + rgb1.r * w2,
  46374. g: rgb2.g * w1 + rgb1.g * w2,
  46375. b: rgb2.b * w1 + rgb1.b * w2,
  46376. a: rgb2.a * p + rgb1.a * (1 - p)
  46377. };
  46378. return tinycolor(rgba);
  46379. }; // Readability Functions
  46380. // ---------------------
  46381. // <http://www.w3.org/TR/AERT#color-contrast>
  46382. // `readability`
  46383. // Analyze the 2 colors and returns an object with the following properties:
  46384. // `brightness`: difference in brightness between the two colors
  46385. // `color`: difference in color/hue between the two colors
  46386. tinycolor.readability = function (color1, color2) {
  46387. var c1 = tinycolor(color1);
  46388. var c2 = tinycolor(color2);
  46389. var rgb1 = c1.toRgb();
  46390. var rgb2 = c2.toRgb();
  46391. var brightnessA = c1.getBrightness();
  46392. var brightnessB = c2.getBrightness();
  46393. var colorDiff = Math.max(rgb1.r, rgb2.r) - Math.min(rgb1.r, rgb2.r) + Math.max(rgb1.g, rgb2.g) - Math.min(rgb1.g, rgb2.g) + Math.max(rgb1.b, rgb2.b) - Math.min(rgb1.b, rgb2.b);
  46394. return {
  46395. brightness: Math.abs(brightnessA - brightnessB),
  46396. color: colorDiff
  46397. };
  46398. }; // `readable`
  46399. // http://www.w3.org/TR/AERT#color-contrast
  46400. // Ensure that foreground and background color combinations provide sufficient contrast.
  46401. // *Example*
  46402. // tinycolor.isReadable("#000", "#111") => false
  46403. tinycolor.isReadable = function (color1, color2) {
  46404. var readability = tinycolor.readability(color1, color2);
  46405. return readability.brightness > 125 && readability.color > 500;
  46406. }; // `mostReadable`
  46407. // Given a base color and a list of possible foreground or background
  46408. // colors for that base, returns the most readable color.
  46409. // *Example*
  46410. // tinycolor.mostReadable("#123", ["#fff", "#000"]) => "#000"
  46411. tinycolor.mostReadable = function (baseColor, colorList) {
  46412. var bestColor = null;
  46413. var bestScore = 0;
  46414. var bestIsReadable = false;
  46415. for (var i = 0; i < colorList.length; i++) {
  46416. // We normalize both around the "acceptable" breaking point,
  46417. // but rank brightness constrast higher than hue.
  46418. var readability = tinycolor.readability(baseColor, colorList[i]);
  46419. var readable = readability.brightness > 125 && readability.color > 500;
  46420. var score = 3 * (readability.brightness / 125) + readability.color / 500;
  46421. if (readable && !bestIsReadable || readable && bestIsReadable && score > bestScore || !readable && !bestIsReadable && score > bestScore) {
  46422. bestIsReadable = readable;
  46423. bestScore = score;
  46424. bestColor = tinycolor(colorList[i]);
  46425. }
  46426. }
  46427. return bestColor;
  46428. }; // Big List of Colors
  46429. // ------------------
  46430. // <http://www.w3.org/TR/css3-color/#svg-color>
  46431. var names = tinycolor.names = {
  46432. aliceblue: 'f0f8ff',
  46433. antiquewhite: 'faebd7',
  46434. aqua: '0ff',
  46435. aquamarine: '7fffd4',
  46436. azure: 'f0ffff',
  46437. beige: 'f5f5dc',
  46438. bisque: 'ffe4c4',
  46439. black: '000',
  46440. blanchedalmond: 'ffebcd',
  46441. blue: '00f',
  46442. blueviolet: '8a2be2',
  46443. brown: 'a52a2a',
  46444. burlywood: 'deb887',
  46445. burntsienna: 'ea7e5d',
  46446. cadetblue: '5f9ea0',
  46447. chartreuse: '7fff00',
  46448. chocolate: 'd2691e',
  46449. coral: 'ff7f50',
  46450. cornflowerblue: '6495ed',
  46451. cornsilk: 'fff8dc',
  46452. crimson: 'dc143c',
  46453. cyan: '0ff',
  46454. darkblue: '00008b',
  46455. darkcyan: '008b8b',
  46456. darkgoldenrod: 'b8860b',
  46457. darkgray: 'a9a9a9',
  46458. darkgreen: '006400',
  46459. darkgrey: 'a9a9a9',
  46460. darkkhaki: 'bdb76b',
  46461. darkmagenta: '8b008b',
  46462. darkolivegreen: '556b2f',
  46463. darkorange: 'ff8c00',
  46464. darkorchid: '9932cc',
  46465. darkred: '8b0000',
  46466. darksalmon: 'e9967a',
  46467. darkseagreen: '8fbc8f',
  46468. darkslateblue: '483d8b',
  46469. darkslategray: '2f4f4f',
  46470. darkslategrey: '2f4f4f',
  46471. darkturquoise: '00ced1',
  46472. darkviolet: '9400d3',
  46473. deeppink: 'ff1493',
  46474. deepskyblue: '00bfff',
  46475. dimgray: '696969',
  46476. dimgrey: '696969',
  46477. dodgerblue: '1e90ff',
  46478. firebrick: 'b22222',
  46479. floralwhite: 'fffaf0',
  46480. forestgreen: '228b22',
  46481. fuchsia: 'f0f',
  46482. gainsboro: 'dcdcdc',
  46483. ghostwhite: 'f8f8ff',
  46484. gold: 'ffd700',
  46485. goldenrod: 'daa520',
  46486. gray: '808080',
  46487. green: '008000',
  46488. greenyellow: 'adff2f',
  46489. grey: '808080',
  46490. honeydew: 'f0fff0',
  46491. hotpink: 'ff69b4',
  46492. indianred: 'cd5c5c',
  46493. indigo: '4b0082',
  46494. ivory: 'fffff0',
  46495. khaki: 'f0e68c',
  46496. lavender: 'e6e6fa',
  46497. lavenderblush: 'fff0f5',
  46498. lawngreen: '7cfc00',
  46499. lemonchiffon: 'fffacd',
  46500. lightblue: 'add8e6',
  46501. lightcoral: 'f08080',
  46502. lightcyan: 'e0ffff',
  46503. lightgoldenrodyellow: 'fafad2',
  46504. lightgray: 'd3d3d3',
  46505. lightgreen: '90ee90',
  46506. lightgrey: 'd3d3d3',
  46507. lightpink: 'ffb6c1',
  46508. lightsalmon: 'ffa07a',
  46509. lightseagreen: '20b2aa',
  46510. lightskyblue: '87cefa',
  46511. lightslategray: '789',
  46512. lightslategrey: '789',
  46513. lightsteelblue: 'b0c4de',
  46514. lightyellow: 'ffffe0',
  46515. lime: '0f0',
  46516. limegreen: '32cd32',
  46517. linen: 'faf0e6',
  46518. magenta: 'f0f',
  46519. maroon: '800000',
  46520. mediumaquamarine: '66cdaa',
  46521. mediumblue: '0000cd',
  46522. mediumorchid: 'ba55d3',
  46523. mediumpurple: '9370db',
  46524. mediumseagreen: '3cb371',
  46525. mediumslateblue: '7b68ee',
  46526. mediumspringgreen: '00fa9a',
  46527. mediumturquoise: '48d1cc',
  46528. mediumvioletred: 'c71585',
  46529. midnightblue: '191970',
  46530. mintcream: 'f5fffa',
  46531. mistyrose: 'ffe4e1',
  46532. moccasin: 'ffe4b5',
  46533. navajowhite: 'ffdead',
  46534. navy: '000080',
  46535. oldlace: 'fdf5e6',
  46536. olive: '808000',
  46537. olivedrab: '6b8e23',
  46538. orange: 'ffa500',
  46539. orangered: 'ff4500',
  46540. orchid: 'da70d6',
  46541. palegoldenrod: 'eee8aa',
  46542. palegreen: '98fb98',
  46543. paleturquoise: 'afeeee',
  46544. palevioletred: 'db7093',
  46545. papayawhip: 'ffefd5',
  46546. peachpuff: 'ffdab9',
  46547. peru: 'cd853f',
  46548. pink: 'ffc0cb',
  46549. plum: 'dda0dd',
  46550. powderblue: 'b0e0e6',
  46551. purple: '800080',
  46552. rebeccapurple: '663399',
  46553. red: 'f00',
  46554. rosybrown: 'bc8f8f',
  46555. royalblue: '4169e1',
  46556. saddlebrown: '8b4513',
  46557. salmon: 'fa8072',
  46558. sandybrown: 'f4a460',
  46559. seagreen: '2e8b57',
  46560. seashell: 'fff5ee',
  46561. sienna: 'a0522d',
  46562. silver: 'c0c0c0',
  46563. skyblue: '87ceeb',
  46564. slateblue: '6a5acd',
  46565. slategray: '708090',
  46566. slategrey: '708090',
  46567. snow: 'fffafa',
  46568. springgreen: '00ff7f',
  46569. steelblue: '4682b4',
  46570. tan: 'd2b48c',
  46571. teal: '008080',
  46572. thistle: 'd8bfd8',
  46573. tomato: 'ff6347',
  46574. turquoise: '40e0d0',
  46575. violet: 'ee82ee',
  46576. wheat: 'f5deb3',
  46577. white: 'fff',
  46578. whitesmoke: 'f5f5f5',
  46579. yellow: 'ff0',
  46580. yellowgreen: '9acd32'
  46581. }; // Make it easy to access colors via `hexNames[hex]`
  46582. var hexNames = tinycolor.hexNames = flip(names); // Utilities
  46583. // ---------
  46584. // `{ 'name1': 'val1' }` becomes `{ 'val1': 'name1' }`
  46585. function flip(o) {
  46586. var flipped = {};
  46587. for (var i in o) {
  46588. if (o.hasOwnProperty(i)) {
  46589. flipped[o[i]] = i;
  46590. }
  46591. }
  46592. return flipped;
  46593. } // Return a valid alpha value [0,1] with all invalid values being set to 1
  46594. function boundAlpha(a) {
  46595. a = parseFloat(a);
  46596. if (isNaN(a) || a < 0 || a > 1) {
  46597. a = 1;
  46598. }
  46599. return a;
  46600. } // Take input from [0, n] and return it as [0, 1]
  46601. function bound01(n, max) {
  46602. if (isOnePointZero(n)) {
  46603. n = '100%';
  46604. }
  46605. var processPercent = isPercentage(n);
  46606. n = mathMin(max, mathMax(0, parseFloat(n))); // Automatically convert percentage into number
  46607. if (processPercent) {
  46608. n = parseInt(n * max, 10) / 100;
  46609. } // Handle floating point rounding errors
  46610. if (math.abs(n - max) < 0.000001) {
  46611. return 1;
  46612. } // Convert into [0, 1] range if it isn't already
  46613. return n % max / parseFloat(max);
  46614. } // Force a number between 0 and 1
  46615. function clamp01(val) {
  46616. return mathMin(1, mathMax(0, val));
  46617. } // Parse a base-16 hex value into a base-10 integer
  46618. function parseIntFromHex(val) {
  46619. return parseInt(val, 16);
  46620. } // Need to handle 1.0 as 100%, since once it is a number, there is no difference between it and 1
  46621. // <http://stackoverflow.com/questions/7422072/javascript-how-to-detect-number-as-a-decimal-including-1-0>
  46622. function isOnePointZero(n) {
  46623. return typeof n == 'string' && n.indexOf('.') != -1 && parseFloat(n) === 1;
  46624. } // Check to see if string passed in is a percentage
  46625. function isPercentage(n) {
  46626. return typeof n === 'string' && n.indexOf('%') != -1;
  46627. } // Force a hex value to have 2 characters
  46628. function pad2(c) {
  46629. return c.length == 1 ? '0' + c : '' + c;
  46630. } // Replace a decimal with it's percentage value
  46631. function convertToPercentage(n) {
  46632. if (n <= 1) {
  46633. n = n * 100 + '%';
  46634. }
  46635. return n;
  46636. } // Converts a decimal to a hex value
  46637. function convertDecimalToHex(d) {
  46638. return Math.round(parseFloat(d) * 255).toString(16);
  46639. } // Converts a hex value to a decimal
  46640. function convertHexToDecimal(h) {
  46641. return parseIntFromHex(h) / 255;
  46642. }
  46643. var matchers = function () {
  46644. // <http://www.w3.org/TR/css3-values/#integers>
  46645. var CSS_INTEGER = '[-\\+]?\\d+%?'; // <http://www.w3.org/TR/css3-values/#number-value>
  46646. var CSS_NUMBER = '[-\\+]?\\d*\\.\\d+%?'; // Allow positive/negative integer/number. Don't capture the either/or, just the entire outcome.
  46647. var CSS_UNIT = '(?:' + CSS_NUMBER + ')|(?:' + CSS_INTEGER + ')'; // Actual matching.
  46648. // Parentheses and commas are optional, but not required.
  46649. // Whitespace can take the place of commas or opening paren
  46650. var PERMISSIVE_MATCH3 = '[\\s|\\(]+(' + CSS_UNIT + ')[,|\\s]+(' + CSS_UNIT + ')[,|\\s]+(' + CSS_UNIT + ')\\s*\\)?';
  46651. var PERMISSIVE_MATCH4 = '[\\s|\\(]+(' + CSS_UNIT + ')[,|\\s]+(' + CSS_UNIT + ')[,|\\s]+(' + CSS_UNIT + ')[,|\\s]+(' + CSS_UNIT + ')\\s*\\)?';
  46652. return {
  46653. rgb: new RegExp('rgb' + PERMISSIVE_MATCH3),
  46654. rgba: new RegExp('rgba' + PERMISSIVE_MATCH4),
  46655. hsl: new RegExp('hsl' + PERMISSIVE_MATCH3),
  46656. hsla: new RegExp('hsla' + PERMISSIVE_MATCH4),
  46657. hsv: new RegExp('hsv' + PERMISSIVE_MATCH3),
  46658. hsva: new RegExp('hsva' + PERMISSIVE_MATCH4),
  46659. hex3: /^([0-9a-fA-F]{1})([0-9a-fA-F]{1})([0-9a-fA-F]{1})$/,
  46660. hex6: /^([0-9a-fA-F]{2})([0-9a-fA-F]{2})([0-9a-fA-F]{2})$/,
  46661. hex8: /^([0-9a-fA-F]{2})([0-9a-fA-F]{2})([0-9a-fA-F]{2})([0-9a-fA-F]{2})$/
  46662. };
  46663. }(); // `stringInputToObject`
  46664. // Permissive string parsing. Take in a number of formats, and output an object
  46665. // based on detected format. Returns `{ r, g, b }` or `{ h, s, l }` or `{ h, s, v}`
  46666. function stringInputToObject(color) {
  46667. color = color.replace(trimLeft, '').replace(trimRight, '').toLowerCase();
  46668. var named = false;
  46669. if (names[color]) {
  46670. color = names[color];
  46671. named = true;
  46672. } else if (color == 'transparent') {
  46673. return {
  46674. r: 0,
  46675. g: 0,
  46676. b: 0,
  46677. a: 0,
  46678. format: 'name'
  46679. };
  46680. } // Try to match string input using regular expressions.
  46681. // Keep most of the number bounding out of this function - don't worry about [0,1] or [0,100] or [0,360]
  46682. // Just return an object and let the conversion functions handle that.
  46683. // This way the result will be the same whether the tinycolor is initialized with string or object.
  46684. var match;
  46685. if (match = matchers.rgb.exec(color)) {
  46686. return {
  46687. r: match[1],
  46688. g: match[2],
  46689. b: match[3]
  46690. };
  46691. }
  46692. if (match = matchers.rgba.exec(color)) {
  46693. return {
  46694. r: match[1],
  46695. g: match[2],
  46696. b: match[3],
  46697. a: match[4]
  46698. };
  46699. }
  46700. if (match = matchers.hsl.exec(color)) {
  46701. return {
  46702. h: match[1],
  46703. s: match[2],
  46704. l: match[3]
  46705. };
  46706. }
  46707. if (match = matchers.hsla.exec(color)) {
  46708. return {
  46709. h: match[1],
  46710. s: match[2],
  46711. l: match[3],
  46712. a: match[4]
  46713. };
  46714. }
  46715. if (match = matchers.hsv.exec(color)) {
  46716. return {
  46717. h: match[1],
  46718. s: match[2],
  46719. v: match[3]
  46720. };
  46721. }
  46722. if (match = matchers.hsva.exec(color)) {
  46723. return {
  46724. h: match[1],
  46725. s: match[2],
  46726. v: match[3],
  46727. a: match[4]
  46728. };
  46729. }
  46730. if (match = matchers.hex8.exec(color)) {
  46731. return {
  46732. a: convertHexToDecimal(match[1]),
  46733. r: parseIntFromHex(match[2]),
  46734. g: parseIntFromHex(match[3]),
  46735. b: parseIntFromHex(match[4]),
  46736. format: named ? 'name' : 'hex8'
  46737. };
  46738. }
  46739. if (match = matchers.hex6.exec(color)) {
  46740. return {
  46741. r: parseIntFromHex(match[1]),
  46742. g: parseIntFromHex(match[2]),
  46743. b: parseIntFromHex(match[3]),
  46744. format: named ? 'name' : 'hex'
  46745. };
  46746. }
  46747. if (match = matchers.hex3.exec(color)) {
  46748. return {
  46749. r: parseIntFromHex(match[1] + '' + match[1]),
  46750. g: parseIntFromHex(match[2] + '' + match[2]),
  46751. b: parseIntFromHex(match[3] + '' + match[3]),
  46752. format: named ? 'name' : 'hex'
  46753. };
  46754. }
  46755. return false;
  46756. }
  46757. window.tinycolor = tinycolor; //})();
  46758. $(function () {
  46759. if ($.fn.spectrum.load) {
  46760. $.fn.spectrum.processNativeColorInputs();
  46761. }
  46762. });
  46763. });
  46764. /***/ }),
  46765. /***/ "./src/utils/Dragger.js":
  46766. /*!******************************!*\
  46767. !*** ./src/utils/Dragger.js ***!
  46768. \******************************/
  46769. /*! exports provided: default */
  46770. /***/ (function(module, __webpack_exports__, __webpack_require__) {
  46771. "use strict";
  46772. __webpack_require__.r(__webpack_exports__);
  46773. /* harmony export (binding) */ __webpack_require__.d(__webpack_exports__, "default", function() { return Dragger; });
  46774. /* harmony import */ var _babel_runtime_helpers_defineProperty__WEBPACK_IMPORTED_MODULE_0__ = __webpack_require__(/*! @babel/runtime/helpers/defineProperty */ "./node_modules/@babel/runtime/helpers/defineProperty.js");
  46775. /* harmony import */ var _babel_runtime_helpers_defineProperty__WEBPACK_IMPORTED_MODULE_0___default = /*#__PURE__*/__webpack_require__.n(_babel_runtime_helpers_defineProperty__WEBPACK_IMPORTED_MODULE_0__);
  46776. /* harmony import */ var _babel_runtime_helpers_classCallCheck__WEBPACK_IMPORTED_MODULE_1__ = __webpack_require__(/*! @babel/runtime/helpers/classCallCheck */ "./node_modules/@babel/runtime/helpers/classCallCheck.js");
  46777. /* harmony import */ var _babel_runtime_helpers_classCallCheck__WEBPACK_IMPORTED_MODULE_1___default = /*#__PURE__*/__webpack_require__.n(_babel_runtime_helpers_classCallCheck__WEBPACK_IMPORTED_MODULE_1__);
  46778. /* harmony import */ var _babel_runtime_helpers_createClass__WEBPACK_IMPORTED_MODULE_2__ = __webpack_require__(/*! @babel/runtime/helpers/createClass */ "./node_modules/@babel/runtime/helpers/createClass.js");
  46779. /* harmony import */ var _babel_runtime_helpers_createClass__WEBPACK_IMPORTED_MODULE_2___default = /*#__PURE__*/__webpack_require__.n(_babel_runtime_helpers_createClass__WEBPACK_IMPORTED_MODULE_2__);
  46780. /* harmony import */ var underscore__WEBPACK_IMPORTED_MODULE_3__ = __webpack_require__(/*! underscore */ "./node_modules/underscore/underscore.js");
  46781. /* harmony import */ var underscore__WEBPACK_IMPORTED_MODULE_3___default = /*#__PURE__*/__webpack_require__.n(underscore__WEBPACK_IMPORTED_MODULE_3__);
  46782. /* harmony import */ var utils_mixins__WEBPACK_IMPORTED_MODULE_4__ = __webpack_require__(/*! utils/mixins */ "./src/utils/mixins.js");
  46783. function ownKeys(object, enumerableOnly) { var keys = Object.keys(object); if (Object.getOwnPropertySymbols) { var symbols = Object.getOwnPropertySymbols(object); if (enumerableOnly) symbols = symbols.filter(function (sym) { return Object.getOwnPropertyDescriptor(object, sym).enumerable; }); keys.push.apply(keys, symbols); } return keys; }
  46784. function _objectSpread(target) { for (var i = 1; i < arguments.length; i++) { var source = arguments[i] != null ? arguments[i] : {}; if (i % 2) { ownKeys(source, true).forEach(function (key) { _babel_runtime_helpers_defineProperty__WEBPACK_IMPORTED_MODULE_0___default()(target, key, source[key]); }); } else if (Object.getOwnPropertyDescriptors) { Object.defineProperties(target, Object.getOwnPropertyDescriptors(source)); } else { ownKeys(source).forEach(function (key) { Object.defineProperty(target, key, Object.getOwnPropertyDescriptor(source, key)); }); } } return target; }
  46785. var resetPos = function resetPos() {
  46786. return {
  46787. x: 0,
  46788. y: 0
  46789. };
  46790. };
  46791. var Dragger =
  46792. /*#__PURE__*/
  46793. function () {
  46794. /**
  46795. * Init the dragger
  46796. * @param {Object} opts
  46797. */
  46798. function Dragger() {
  46799. var opts = arguments.length > 0 && arguments[0] !== undefined ? arguments[0] : {};
  46800. _babel_runtime_helpers_classCallCheck__WEBPACK_IMPORTED_MODULE_1___default()(this, Dragger);
  46801. this.opts = {
  46802. /**
  46803. * Element on which the drag will be executed. By default, the document will be used
  46804. */
  46805. container: null,
  46806. /**
  46807. * Callback on start
  46808. * onStart(ev, dragger) {
  46809. * console.log('pointer start', dragger.startPointer, 'position start', dragger.startPosition);
  46810. * },
  46811. */
  46812. onStart: null,
  46813. /**
  46814. * Callback on drag
  46815. * onDrag(ev, dragger) {
  46816. * console.log('pointer', dragger.currentPointer, 'position', dragger.position, 'delta', dragger.delta);
  46817. * },
  46818. */
  46819. onDrag: null,
  46820. /**
  46821. * Callback on drag
  46822. * onEnd(ev, dragger) {
  46823. * console.log('pointer', dragger.currentPointer, 'position', dragger.position, 'delta', dragger.delta);
  46824. * },
  46825. */
  46826. onEnd: null,
  46827. /**
  46828. * Indicate a callback where to pass an object with new coordinates
  46829. */
  46830. setPosition: null,
  46831. /**
  46832. * Indicate a callback where to get initial coordinates.
  46833. * getPosition: () => {
  46834. * ...
  46835. * return { x: 10, y: 100 }
  46836. * }
  46837. */
  46838. getPosition: null,
  46839. // Static guides to be snapped
  46840. guidesStatic: null,
  46841. // Target guides that will snap to static one
  46842. guidesTarget: null,
  46843. // Offset before snap to guides
  46844. snapOffset: 5,
  46845. // Document on which listen to pointer events
  46846. doc: 0,
  46847. // Scale result points, can also be a function
  46848. scale: 1
  46849. };
  46850. Object(underscore__WEBPACK_IMPORTED_MODULE_3__["bindAll"])(this, 'drag', 'stop', 'keyHandle', 'handleScroll');
  46851. this.setOptions(opts);
  46852. this.delta = resetPos();
  46853. return this;
  46854. }
  46855. /**
  46856. * Update options
  46857. * @param {Object} options
  46858. */
  46859. _babel_runtime_helpers_createClass__WEBPACK_IMPORTED_MODULE_2___default()(Dragger, [{
  46860. key: "setOptions",
  46861. value: function setOptions() {
  46862. var opts = arguments.length > 0 && arguments[0] !== undefined ? arguments[0] : {};
  46863. this.opts = _objectSpread({}, this.opts, {}, opts);
  46864. }
  46865. }, {
  46866. key: "toggleDrag",
  46867. value: function toggleDrag(enable) {
  46868. var docs = this.getDocumentEl();
  46869. var container = this.getContainerEl();
  46870. var win = this.getWindowEl();
  46871. var method = enable ? 'on' : 'off';
  46872. var methods = {
  46873. on: utils_mixins__WEBPACK_IMPORTED_MODULE_4__["on"],
  46874. off: utils_mixins__WEBPACK_IMPORTED_MODULE_4__["off"]
  46875. };
  46876. methods[method](container, 'mousemove dragover', this.drag);
  46877. methods[method](docs, 'mouseup dragend touchend', this.stop);
  46878. methods[method](docs, 'keydown', this.keyHandle);
  46879. methods[method](win, 'scroll', this.handleScroll);
  46880. }
  46881. }, {
  46882. key: "handleScroll",
  46883. value: function handleScroll() {
  46884. var lastScroll = this.lastScroll,
  46885. delta = this.delta;
  46886. var actualScroll = this.getScrollInfo();
  46887. var scrollDiff = {
  46888. x: actualScroll.x - lastScroll.x,
  46889. y: actualScroll.y - lastScroll.y
  46890. };
  46891. this.move(delta.x + scrollDiff.x, delta.y + scrollDiff.y);
  46892. this.lastScrollDiff = scrollDiff;
  46893. }
  46894. /**
  46895. * Start dragging
  46896. * @param {Event} e
  46897. */
  46898. }, {
  46899. key: "start",
  46900. value: function start(ev) {
  46901. var opts = this.opts;
  46902. var onStart = opts.onStart;
  46903. this.toggleDrag(1);
  46904. this.startPointer = this.getPointerPos(ev);
  46905. this.guidesStatic = Object(underscore__WEBPACK_IMPORTED_MODULE_3__["result"])(opts, 'guidesStatic') || [];
  46906. this.guidesTarget = Object(underscore__WEBPACK_IMPORTED_MODULE_3__["result"])(opts, 'guidesTarget') || [];
  46907. Object(underscore__WEBPACK_IMPORTED_MODULE_3__["isFunction"])(onStart) && onStart(ev, this);
  46908. this.startPosition = this.getStartPosition();
  46909. this.lastScrollDiff = resetPos();
  46910. this.globScrollDiff = resetPos();
  46911. this.drag(ev);
  46912. }
  46913. /**
  46914. * Drag event
  46915. * @param {Event} event
  46916. */
  46917. }, {
  46918. key: "drag",
  46919. value: function drag(ev) {
  46920. var _this = this;
  46921. var opts = this.opts,
  46922. lastScrollDiff = this.lastScrollDiff,
  46923. globScrollDiff = this.globScrollDiff;
  46924. var onDrag = opts.onDrag;
  46925. var startPointer = this.startPointer;
  46926. var currentPos = this.getPointerPos(ev);
  46927. var glDiff = {
  46928. x: globScrollDiff.x + lastScrollDiff.x,
  46929. y: globScrollDiff.y + lastScrollDiff.y
  46930. };
  46931. this.globScrollDiff = glDiff;
  46932. var delta = {
  46933. x: currentPos.x - startPointer.x + glDiff.x,
  46934. y: currentPos.y - startPointer.y + glDiff.y
  46935. };
  46936. this.lastScrollDiff = resetPos();
  46937. var lockedAxis = this.lockedAxis; // Lock one axis
  46938. if (ev.shiftKey) {
  46939. lockedAxis = !lockedAxis && this.detectAxisLock(delta.x, delta.y);
  46940. } else {
  46941. lockedAxis = null;
  46942. }
  46943. if (lockedAxis === 'x') {
  46944. delta.x = startPointer.x;
  46945. } else if (lockedAxis === 'y') {
  46946. delta.y = startPointer.y;
  46947. }
  46948. var moveDelta = function moveDelta(delta) {
  46949. ['x', 'y'].forEach(function (co) {
  46950. return delta[co] = delta[co] * Object(underscore__WEBPACK_IMPORTED_MODULE_3__["result"])(opts, 'scale');
  46951. });
  46952. _this.delta = delta;
  46953. _this.move(delta.x, delta.y);
  46954. Object(underscore__WEBPACK_IMPORTED_MODULE_3__["isFunction"])(onDrag) && onDrag(ev, _this);
  46955. };
  46956. var deltaPre = _objectSpread({}, delta);
  46957. this.currentPointer = currentPos;
  46958. this.lockedAxis = lockedAxis;
  46959. this.lastScroll = this.getScrollInfo();
  46960. moveDelta(delta);
  46961. if (this.guidesTarget.length) {
  46962. var _this$snapGuides = this.snapGuides(deltaPre),
  46963. newDelta = _this$snapGuides.newDelta,
  46964. trgX = _this$snapGuides.trgX,
  46965. trgY = _this$snapGuides.trgY;
  46966. (trgX || trgY) && moveDelta(newDelta);
  46967. } // In case the mouse button was released outside of the window
  46968. ev.which === 0 && this.stop(ev);
  46969. }
  46970. /**
  46971. * Check if the delta hits some guide
  46972. */
  46973. }, {
  46974. key: "snapGuides",
  46975. value: function snapGuides(delta) {
  46976. var _this2 = this;
  46977. var newDelta = delta;
  46978. var trgX = this.trgX,
  46979. trgY = this.trgY;
  46980. this.guidesTarget.forEach(function (trg) {
  46981. // Skip the guide if its locked axis already exists
  46982. if (trg.x && _this2.trgX || trg.y && _this2.trgY) return;
  46983. trg.active = 0;
  46984. _this2.guidesStatic.forEach(function (stat) {
  46985. if (trg.y && stat.x || trg.x && stat.y) return;
  46986. var isY = trg.y && stat.y;
  46987. var axs = isY ? 'y' : 'x';
  46988. var trgPoint = trg[axs];
  46989. var statPoint = stat[axs];
  46990. var deltaPoint = delta[axs];
  46991. var trgGuide = isY ? trgY : trgX;
  46992. if (_this2.isPointIn(trgPoint, statPoint)) {
  46993. if (Object(underscore__WEBPACK_IMPORTED_MODULE_3__["isUndefined"])(trgGuide)) {
  46994. var trgValue = deltaPoint - (trgPoint - statPoint);
  46995. _this2.setGuideLock(trg, trgValue);
  46996. }
  46997. }
  46998. });
  46999. });
  47000. trgX = this.trgX;
  47001. trgY = this.trgY;
  47002. ['x', 'y'].forEach(function (co) {
  47003. var axis = co.toUpperCase();
  47004. var trg = _this2["trg".concat(axis)];
  47005. if (trg && !_this2.isPointIn(delta[co], trg.lock)) {
  47006. _this2.setGuideLock(trg, null);
  47007. trg = null;
  47008. }
  47009. if (trg && !Object(underscore__WEBPACK_IMPORTED_MODULE_3__["isUndefined"])(trg.lock)) {
  47010. newDelta[co] = trg.lock;
  47011. }
  47012. });
  47013. return {
  47014. newDelta: newDelta,
  47015. trgX: this.trgX,
  47016. trgY: this.trgY
  47017. };
  47018. }
  47019. }, {
  47020. key: "isPointIn",
  47021. value: function isPointIn(src, trg) {
  47022. var _ref = arguments.length > 2 && arguments[2] !== undefined ? arguments[2] : {},
  47023. offset = _ref.offset;
  47024. var ofst = offset || this.opts.snapOffset;
  47025. return src >= trg && src <= trg + ofst || src <= trg && src >= trg - ofst;
  47026. }
  47027. }, {
  47028. key: "setGuideLock",
  47029. value: function setGuideLock(guide, value) {
  47030. var axis = !Object(underscore__WEBPACK_IMPORTED_MODULE_3__["isUndefined"])(guide.x) ? 'X' : 'Y';
  47031. var trgName = "trg".concat(axis);
  47032. if (value !== null) {
  47033. guide.active = 1;
  47034. guide.lock = value;
  47035. this[trgName] = guide;
  47036. } else {
  47037. delete guide.active;
  47038. delete guide.lock;
  47039. delete this[trgName];
  47040. }
  47041. return guide;
  47042. }
  47043. /**
  47044. * Stop dragging
  47045. */
  47046. }, {
  47047. key: "stop",
  47048. value: function stop(ev) {
  47049. var opts = arguments.length > 1 && arguments[1] !== undefined ? arguments[1] : {};
  47050. var delta = this.delta;
  47051. var cancelled = opts.cancel;
  47052. var x = cancelled ? 0 : delta.x;
  47053. var y = cancelled ? 0 : delta.y;
  47054. this.toggleDrag();
  47055. this.lockedAxis = null;
  47056. this.move(x, y, 1);
  47057. var onEnd = this.opts.onEnd;
  47058. Object(underscore__WEBPACK_IMPORTED_MODULE_3__["isFunction"])(onEnd) && onEnd(ev, this, {
  47059. cancelled: cancelled
  47060. });
  47061. }
  47062. }, {
  47063. key: "keyHandle",
  47064. value: function keyHandle(ev) {
  47065. if (Object(utils_mixins__WEBPACK_IMPORTED_MODULE_4__["isEscKey"])(ev)) {
  47066. this.stop(ev, {
  47067. cancel: 1
  47068. });
  47069. }
  47070. }
  47071. /**
  47072. * Move the element
  47073. * @param {integer} x
  47074. * @param {integer} y
  47075. */
  47076. }, {
  47077. key: "move",
  47078. value: function move(x, y, end) {
  47079. var el = this.el,
  47080. opts = this.opts;
  47081. var pos = this.startPosition;
  47082. if (!pos) return;
  47083. var setPosition = opts.setPosition;
  47084. var xPos = pos.x + x;
  47085. var yPos = pos.y + y;
  47086. this.position = {
  47087. x: xPos,
  47088. y: yPos,
  47089. end: end
  47090. };
  47091. Object(underscore__WEBPACK_IMPORTED_MODULE_3__["isFunction"])(setPosition) && setPosition(this.position);
  47092. if (el) {
  47093. el.style.left = "".concat(xPos, "px");
  47094. el.style.top = "".concat(yPos, "px");
  47095. }
  47096. }
  47097. }, {
  47098. key: "getContainerEl",
  47099. value: function getContainerEl() {
  47100. var container = this.opts.container;
  47101. return container ? [container] : this.getDocumentEl();
  47102. }
  47103. }, {
  47104. key: "getWindowEl",
  47105. value: function getWindowEl() {
  47106. var cont = this.getContainerEl();
  47107. return cont.map(function (item) {
  47108. var doc = item.ownerDocument || item;
  47109. return doc.defaultView || doc.parentWindow;
  47110. });
  47111. }
  47112. /**
  47113. * Returns documents
  47114. */
  47115. }, {
  47116. key: "getDocumentEl",
  47117. value: function getDocumentEl(el) {
  47118. var doc = this.opts.doc;
  47119. el = el || this.el;
  47120. if (!this.docs) {
  47121. var docs = [document];
  47122. el && docs.push(el.ownerDocument);
  47123. doc && docs.push(doc);
  47124. this.docs = docs;
  47125. }
  47126. return this.docs;
  47127. }
  47128. /**
  47129. * Get mouse coordinates
  47130. * @param {Event} event
  47131. * @return {Object}
  47132. */
  47133. }, {
  47134. key: "getPointerPos",
  47135. value: function getPointerPos(ev) {
  47136. var getPos = this.opts.getPointerPosition;
  47137. var pEv = Object(utils_mixins__WEBPACK_IMPORTED_MODULE_4__["getPointerEvent"])(ev);
  47138. return getPos ? getPos(ev) : {
  47139. x: pEv.clientX,
  47140. y: pEv.clientY
  47141. };
  47142. }
  47143. }, {
  47144. key: "getStartPosition",
  47145. value: function getStartPosition() {
  47146. var el = this.el,
  47147. opts = this.opts;
  47148. var getPos = opts.getPosition;
  47149. var result = resetPos();
  47150. if (Object(underscore__WEBPACK_IMPORTED_MODULE_3__["isFunction"])(getPos)) {
  47151. result = getPos();
  47152. } else if (el) {
  47153. result = {
  47154. x: parseFloat(el.style.left),
  47155. y: parseFloat(el.style.top)
  47156. };
  47157. }
  47158. return result;
  47159. }
  47160. }, {
  47161. key: "getScrollInfo",
  47162. value: function getScrollInfo() {
  47163. var doc = this.opts.doc;
  47164. var body = doc && doc.body;
  47165. return {
  47166. y: body ? body.scrollTop : 0,
  47167. x: body ? body.scrollLeft : 0
  47168. };
  47169. }
  47170. }, {
  47171. key: "detectAxisLock",
  47172. value: function detectAxisLock(x, y) {
  47173. var relX = x;
  47174. var relY = y;
  47175. var absX = Math.abs(relX);
  47176. var absY = Math.abs(relY); // Vertical or Horizontal lock
  47177. if (relY >= absX || relY <= -absX) {
  47178. return 'x';
  47179. } else if (relX > absY || relX < -absY) {
  47180. return 'y';
  47181. }
  47182. }
  47183. }]);
  47184. return Dragger;
  47185. }();
  47186. /***/ }),
  47187. /***/ "./src/utils/Droppable.js":
  47188. /*!********************************!*\
  47189. !*** ./src/utils/Droppable.js ***!
  47190. \********************************/
  47191. /*! exports provided: default */
  47192. /***/ (function(module, __webpack_exports__, __webpack_require__) {
  47193. "use strict";
  47194. __webpack_require__.r(__webpack_exports__);
  47195. /* harmony export (binding) */ __webpack_require__.d(__webpack_exports__, "default", function() { return Droppable; });
  47196. /* harmony import */ var _babel_runtime_helpers_classCallCheck__WEBPACK_IMPORTED_MODULE_0__ = __webpack_require__(/*! @babel/runtime/helpers/classCallCheck */ "./node_modules/@babel/runtime/helpers/classCallCheck.js");
  47197. /* harmony import */ var _babel_runtime_helpers_classCallCheck__WEBPACK_IMPORTED_MODULE_0___default = /*#__PURE__*/__webpack_require__.n(_babel_runtime_helpers_classCallCheck__WEBPACK_IMPORTED_MODULE_0__);
  47198. /* harmony import */ var _babel_runtime_helpers_createClass__WEBPACK_IMPORTED_MODULE_1__ = __webpack_require__(/*! @babel/runtime/helpers/createClass */ "./node_modules/@babel/runtime/helpers/createClass.js");
  47199. /* harmony import */ var _babel_runtime_helpers_createClass__WEBPACK_IMPORTED_MODULE_1___default = /*#__PURE__*/__webpack_require__.n(_babel_runtime_helpers_createClass__WEBPACK_IMPORTED_MODULE_1__);
  47200. /* harmony import */ var utils_mixins__WEBPACK_IMPORTED_MODULE_2__ = __webpack_require__(/*! utils/mixins */ "./src/utils/mixins.js");
  47201. /* harmony import */ var underscore__WEBPACK_IMPORTED_MODULE_3__ = __webpack_require__(/*! underscore */ "./node_modules/underscore/underscore.js");
  47202. /* harmony import */ var underscore__WEBPACK_IMPORTED_MODULE_3___default = /*#__PURE__*/__webpack_require__.n(underscore__WEBPACK_IMPORTED_MODULE_3__);
  47203. /*
  47204. This class makes the canvas droppable
  47205. */
  47206. var Droppable =
  47207. /*#__PURE__*/
  47208. function () {
  47209. function Droppable(em, rootEl) {
  47210. var _this = this;
  47211. _babel_runtime_helpers_classCallCheck__WEBPACK_IMPORTED_MODULE_0___default()(this, Droppable);
  47212. this.em = em;
  47213. var el = rootEl || em.get('Canvas').getFrames().map(function (frame) {
  47214. return frame.get('root').getEl();
  47215. });
  47216. var els = Array.isArray(el) ? el : [el];
  47217. this.el = el;
  47218. this.counter = 0;
  47219. Object(underscore__WEBPACK_IMPORTED_MODULE_3__["bindAll"])(this, 'handleDragEnter', 'handleDragOver', 'handleDrop', 'handleDragLeave');
  47220. els.forEach(function (el) {
  47221. return _this.toggleEffects(el, 1);
  47222. });
  47223. return this;
  47224. }
  47225. _babel_runtime_helpers_createClass__WEBPACK_IMPORTED_MODULE_1___default()(Droppable, [{
  47226. key: "toggleEffects",
  47227. value: function toggleEffects(el, enable) {
  47228. var methods = {
  47229. on: utils_mixins__WEBPACK_IMPORTED_MODULE_2__["on"],
  47230. off: utils_mixins__WEBPACK_IMPORTED_MODULE_2__["off"]
  47231. };
  47232. var method = enable ? 'on' : 'off';
  47233. methods[method](el, 'dragenter', this.handleDragEnter);
  47234. methods[method](el, 'dragover', this.handleDragOver);
  47235. methods[method](el, 'drop', this.handleDrop);
  47236. methods[method](el, 'dragleave', this.handleDragLeave);
  47237. }
  47238. }, {
  47239. key: "endDrop",
  47240. value: function endDrop(cancel, ev) {
  47241. var em = this.em,
  47242. dragStop = this.dragStop;
  47243. this.counter = 0;
  47244. this.over = 0;
  47245. dragStop && dragStop(cancel);
  47246. em.runDefault({
  47247. preserveSelected: 1
  47248. });
  47249. em.trigger('canvas:dragend', ev);
  47250. }
  47251. }, {
  47252. key: "handleDragLeave",
  47253. value: function handleDragLeave(ev) {
  47254. this.updateCounter(-1, ev);
  47255. }
  47256. }, {
  47257. key: "updateCounter",
  47258. value: function updateCounter(value, ev) {
  47259. this.counter += value;
  47260. this.counter === 0 && this.endDrop(1, ev);
  47261. }
  47262. }, {
  47263. key: "handleDragEnter",
  47264. value: function handleDragEnter(ev) {
  47265. var _this2 = this;
  47266. var em = this.em;
  47267. var dt = ev.dataTransfer;
  47268. this.updateCounter(1, ev);
  47269. if (this.over) return;
  47270. this.over = 1;
  47271. var utils = em.get('Utils');
  47272. var canvas = em.get('Canvas');
  47273. var container = canvas.getBody(); // For security reason I can't read the drag data on dragenter, but
  47274. // as I need it for the Sorter context I will use `dragContent` or just
  47275. // any not empty element
  47276. var content = em.get('dragContent') || '<br>';
  47277. var dragStop, dragContent;
  47278. em.stopDefault();
  47279. if (em.inAbsoluteMode()) {
  47280. var wrapper = em.get('DomComponents').getWrapper();
  47281. var target = wrapper.append({})[0];
  47282. var dragger = em.get('Commands').run('core:component-drag', {
  47283. event: ev,
  47284. guidesInfo: 1,
  47285. center: 1,
  47286. target: target,
  47287. onEnd: function onEnd(ev, dragger, _ref) {
  47288. var cancelled = _ref.cancelled;
  47289. if (!cancelled) {
  47290. var comp = wrapper.append(content)[0];
  47291. var _target$getStyle = target.getStyle(),
  47292. left = _target$getStyle.left,
  47293. top = _target$getStyle.top,
  47294. position = _target$getStyle.position;
  47295. comp.addStyle({
  47296. left: left,
  47297. top: top,
  47298. position: position
  47299. });
  47300. _this2.handleDragEnd(comp, dt);
  47301. }
  47302. target.remove();
  47303. }
  47304. });
  47305. dragStop = function dragStop(cancel) {
  47306. return dragger.stop(ev, {
  47307. cancel: cancel
  47308. });
  47309. };
  47310. dragContent = function dragContent(cnt) {
  47311. return content = cnt;
  47312. };
  47313. } else {
  47314. var sorter = new utils.Sorter({
  47315. em: em,
  47316. wmargin: 1,
  47317. nested: 1,
  47318. canvasRelative: 1,
  47319. direction: 'a',
  47320. container: container,
  47321. placer: canvas.getPlacerEl(),
  47322. containerSel: '*',
  47323. itemSel: '*',
  47324. pfx: 'gjs-',
  47325. onEndMove: function onEndMove(model) {
  47326. return _this2.handleDragEnd(model, dt);
  47327. },
  47328. document: canvas.getFrameEl().contentDocument
  47329. });
  47330. sorter.setDropContent(content);
  47331. sorter.startSort();
  47332. this.sorter = sorter;
  47333. dragStop = function dragStop(cancel) {
  47334. cancel && (sorter.moved = 0);
  47335. sorter.endMove();
  47336. };
  47337. dragContent = function dragContent(content) {
  47338. return sorter.setDropContent(content);
  47339. };
  47340. }
  47341. this.dragStop = dragStop;
  47342. this.dragContent = dragContent;
  47343. em.trigger('canvas:dragenter', dt, content);
  47344. }
  47345. }, {
  47346. key: "handleDragEnd",
  47347. value: function handleDragEnd(model, dt) {
  47348. if (!model) return;
  47349. var em = this.em;
  47350. em.set('dragResult', model);
  47351. em.trigger('canvas:drop', dt, model);
  47352. }
  47353. /**
  47354. * Always need to have this handler active for enabling the drop
  47355. * @param {Event} ev
  47356. */
  47357. }, {
  47358. key: "handleDragOver",
  47359. value: function handleDragOver(ev) {
  47360. ev.preventDefault();
  47361. this.em.trigger('canvas:dragover', ev);
  47362. }
  47363. }, {
  47364. key: "handleDrop",
  47365. value: function handleDrop(ev) {
  47366. ev.preventDefault();
  47367. var dragContent = this.dragContent;
  47368. var dt = ev.dataTransfer;
  47369. var content = this.getContentByData(dt).content;
  47370. ev.target.style.border = '';
  47371. content && dragContent && dragContent(content);
  47372. this.endDrop(!content, ev);
  47373. }
  47374. }, {
  47375. key: "getContentByData",
  47376. value: function getContentByData(dataTransfer) {
  47377. var em = this.em;
  47378. var types = dataTransfer.types;
  47379. var files = dataTransfer.files || [];
  47380. var dragContent = em.get('dragContent');
  47381. var content = dataTransfer.getData('text');
  47382. if (files.length) {
  47383. content = [];
  47384. for (var i = 0; i < files.length; i++) {
  47385. var file = files[i];
  47386. var type = file.type.split('/')[0];
  47387. if (type == 'image') {
  47388. content.push({
  47389. type: type,
  47390. file: file,
  47391. attributes: {
  47392. alt: file.name
  47393. }
  47394. });
  47395. }
  47396. }
  47397. } else if (dragContent) {
  47398. content = dragContent;
  47399. } else if (Object(underscore__WEBPACK_IMPORTED_MODULE_3__["indexOf"])(types, 'text/html') >= 0) {
  47400. content = dataTransfer.getData('text/html').replace(/<\/?meta[^>]*>/g, '');
  47401. } else if (Object(underscore__WEBPACK_IMPORTED_MODULE_3__["indexOf"])(types, 'text/uri-list') >= 0) {
  47402. content = {
  47403. type: 'link',
  47404. attributes: {
  47405. href: content
  47406. },
  47407. content: content
  47408. };
  47409. } else if (Object(underscore__WEBPACK_IMPORTED_MODULE_3__["indexOf"])(types, 'text/json') >= 0) {
  47410. var json = dataTransfer.getData('text/json');
  47411. json && (content = JSON.parse(json));
  47412. }
  47413. var result = {
  47414. content: content
  47415. };
  47416. em.trigger('canvas:dragdata', dataTransfer, result);
  47417. return result;
  47418. }
  47419. }]);
  47420. return Droppable;
  47421. }();
  47422. /***/ }),
  47423. /***/ "./src/utils/Resizer.js":
  47424. /*!******************************!*\
  47425. !*** ./src/utils/Resizer.js ***!
  47426. \******************************/
  47427. /*! exports provided: default */
  47428. /***/ (function(module, __webpack_exports__, __webpack_require__) {
  47429. "use strict";
  47430. __webpack_require__.r(__webpack_exports__);
  47431. /* harmony import */ var _babel_runtime_helpers_defineProperty__WEBPACK_IMPORTED_MODULE_0__ = __webpack_require__(/*! @babel/runtime/helpers/defineProperty */ "./node_modules/@babel/runtime/helpers/defineProperty.js");
  47432. /* harmony import */ var _babel_runtime_helpers_defineProperty__WEBPACK_IMPORTED_MODULE_0___default = /*#__PURE__*/__webpack_require__.n(_babel_runtime_helpers_defineProperty__WEBPACK_IMPORTED_MODULE_0__);
  47433. /* harmony import */ var _babel_runtime_helpers_classCallCheck__WEBPACK_IMPORTED_MODULE_1__ = __webpack_require__(/*! @babel/runtime/helpers/classCallCheck */ "./node_modules/@babel/runtime/helpers/classCallCheck.js");
  47434. /* harmony import */ var _babel_runtime_helpers_classCallCheck__WEBPACK_IMPORTED_MODULE_1___default = /*#__PURE__*/__webpack_require__.n(_babel_runtime_helpers_classCallCheck__WEBPACK_IMPORTED_MODULE_1__);
  47435. /* harmony import */ var _babel_runtime_helpers_createClass__WEBPACK_IMPORTED_MODULE_2__ = __webpack_require__(/*! @babel/runtime/helpers/createClass */ "./node_modules/@babel/runtime/helpers/createClass.js");
  47436. /* harmony import */ var _babel_runtime_helpers_createClass__WEBPACK_IMPORTED_MODULE_2___default = /*#__PURE__*/__webpack_require__.n(_babel_runtime_helpers_createClass__WEBPACK_IMPORTED_MODULE_2__);
  47437. /* harmony import */ var underscore__WEBPACK_IMPORTED_MODULE_3__ = __webpack_require__(/*! underscore */ "./node_modules/underscore/underscore.js");
  47438. /* harmony import */ var underscore__WEBPACK_IMPORTED_MODULE_3___default = /*#__PURE__*/__webpack_require__.n(underscore__WEBPACK_IMPORTED_MODULE_3__);
  47439. /* harmony import */ var utils_mixins__WEBPACK_IMPORTED_MODULE_4__ = __webpack_require__(/*! utils/mixins */ "./src/utils/mixins.js");
  47440. function ownKeys(object, enumerableOnly) { var keys = Object.keys(object); if (Object.getOwnPropertySymbols) { var symbols = Object.getOwnPropertySymbols(object); if (enumerableOnly) symbols = symbols.filter(function (sym) { return Object.getOwnPropertyDescriptor(object, sym).enumerable; }); keys.push.apply(keys, symbols); } return keys; }
  47441. function _objectSpread(target) { for (var i = 1; i < arguments.length; i++) { var source = arguments[i] != null ? arguments[i] : {}; if (i % 2) { ownKeys(source, true).forEach(function (key) { _babel_runtime_helpers_defineProperty__WEBPACK_IMPORTED_MODULE_0___default()(target, key, source[key]); }); } else if (Object.getOwnPropertyDescriptors) { Object.defineProperties(target, Object.getOwnPropertyDescriptors(source)); } else { ownKeys(source).forEach(function (key) { Object.defineProperty(target, key, Object.getOwnPropertyDescriptor(source, key)); }); } } return target; }
  47442. var defaultOpts = {
  47443. // Function which returns custom X and Y coordinates of the mouse
  47444. mousePosFetcher: null,
  47445. // Indicates custom target updating strategy
  47446. updateTarget: null,
  47447. // Function which gets HTMLElement as an arg and returns it relative position
  47448. ratioDefault: 0,
  47449. posFetcher: null,
  47450. onStart: null,
  47451. onMove: null,
  47452. onEnd: null,
  47453. onUpdateContainer: function onUpdateContainer() {},
  47454. // Resize unit step
  47455. step: 1,
  47456. // Minimum dimension
  47457. minDim: 32,
  47458. // Maximum dimension
  47459. maxDim: '',
  47460. // Unit used for height resizing
  47461. unitHeight: 'px',
  47462. // Unit used for width resizing
  47463. unitWidth: 'px',
  47464. // The key used for height resizing
  47465. keyHeight: 'height',
  47466. // The key used for width resizing
  47467. keyWidth: 'width',
  47468. // If true, will override unitHeight and unitWidth, on start, with units
  47469. // from the current focused element (currently used only in SelectComponent)
  47470. currentUnit: 1,
  47471. // With this option active the mousemove event won't be altered when
  47472. // the pointer comes over iframes
  47473. silentFrames: 0,
  47474. // If true the container of handlers won't be updated
  47475. avoidContainerUpdate: 0,
  47476. // If height is 'auto', this setting will preserve it and only update width
  47477. keepAutoHeight: false,
  47478. // If width is 'auto', this setting will preserve it and only update height
  47479. keepAutoWidth: false,
  47480. // When keepAutoHeight is true and the height has the value 'auto', this is set to true and height isn't updated
  47481. autoHeight: false,
  47482. // When keepAutoWidth is true and the width has the value 'auto', this is set to true and width isn't updated
  47483. autoWidth: false,
  47484. // Handlers
  47485. tl: 1,
  47486. // Top left
  47487. tc: 1,
  47488. // Top center
  47489. tr: 1,
  47490. // Top right
  47491. cl: 1,
  47492. // Center left
  47493. cr: 1,
  47494. // Center right
  47495. bl: 1,
  47496. // Bottom left
  47497. bc: 1,
  47498. // Bottom center
  47499. br: 1 // Bottom right
  47500. };
  47501. var createHandler = function createHandler(name, opts) {
  47502. var pfx = opts.prefix || '';
  47503. var el = document.createElement('i');
  47504. el.className = pfx + 'resizer-h ' + pfx + 'resizer-h-' + name;
  47505. el.setAttribute('data-' + pfx + 'handler', name);
  47506. return el;
  47507. };
  47508. var getBoundingRect = function getBoundingRect(el, win) {
  47509. var w = win || window;
  47510. var rect = el.getBoundingClientRect();
  47511. return {
  47512. left: rect.left + w.pageXOffset,
  47513. top: rect.top + w.pageYOffset,
  47514. width: rect.width,
  47515. height: rect.height
  47516. };
  47517. };
  47518. var Resizer =
  47519. /*#__PURE__*/
  47520. function () {
  47521. /**
  47522. * Init the Resizer with options
  47523. * @param {Object} options
  47524. */
  47525. function Resizer() {
  47526. var opts = arguments.length > 0 && arguments[0] !== undefined ? arguments[0] : {};
  47527. _babel_runtime_helpers_classCallCheck__WEBPACK_IMPORTED_MODULE_1___default()(this, Resizer);
  47528. this.setOptions(opts);
  47529. Object(underscore__WEBPACK_IMPORTED_MODULE_3__["bindAll"])(this, 'handleKeyDown', 'handleMouseDown', 'move', 'stop');
  47530. return this;
  47531. }
  47532. /**
  47533. * Get current connfiguration options
  47534. * @return {Object}
  47535. */
  47536. _babel_runtime_helpers_createClass__WEBPACK_IMPORTED_MODULE_2___default()(Resizer, [{
  47537. key: "getConfig",
  47538. value: function getConfig() {
  47539. return this.opts;
  47540. }
  47541. /**
  47542. * Setup options
  47543. * @param {Object} options
  47544. */
  47545. }, {
  47546. key: "setOptions",
  47547. value: function setOptions() {
  47548. var options = arguments.length > 0 && arguments[0] !== undefined ? arguments[0] : {};
  47549. this.opts = Object(underscore__WEBPACK_IMPORTED_MODULE_3__["defaults"])(options, defaultOpts);
  47550. this.setup();
  47551. }
  47552. /**
  47553. * Setup resizer
  47554. */
  47555. }, {
  47556. key: "setup",
  47557. value: function setup() {
  47558. var opts = this.opts;
  47559. var pfx = opts.prefix || '';
  47560. var appendTo = opts.appendTo || document.body;
  47561. var container = this.container; // Create container if not yet exist
  47562. if (!container) {
  47563. container = document.createElement('div');
  47564. container.className = "".concat(pfx, "resizer-c");
  47565. appendTo.appendChild(container);
  47566. this.container = container;
  47567. }
  47568. while (container.firstChild) {
  47569. container.removeChild(container.firstChild);
  47570. } // Create handlers
  47571. var handlers = {};
  47572. ['tl', 'tc', 'tr', 'cl', 'cr', 'bl', 'bc', 'br'].forEach(function (hdl) {
  47573. return handlers[hdl] = opts[hdl] ? createHandler(hdl, opts) : '';
  47574. });
  47575. for (var n in handlers) {
  47576. var handler = handlers[n];
  47577. handler && container.appendChild(handler);
  47578. }
  47579. this.handlers = handlers;
  47580. this.mousePosFetcher = opts.mousePosFetcher;
  47581. this.updateTarget = opts.updateTarget;
  47582. this.posFetcher = opts.posFetcher;
  47583. this.onStart = opts.onStart;
  47584. this.onMove = opts.onMove;
  47585. this.onEnd = opts.onEnd;
  47586. this.onUpdateContainer = opts.onUpdateContainer;
  47587. }
  47588. /**
  47589. * Toggle iframes pointer event
  47590. * @param {Boolean} silent If true, iframes will be silented
  47591. */
  47592. }, {
  47593. key: "toggleFrames",
  47594. value: function toggleFrames(silent) {
  47595. if (this.opts.silentFrames) {
  47596. var frames = document.querySelectorAll('iframe');
  47597. Object(underscore__WEBPACK_IMPORTED_MODULE_3__["each"])(frames, function (frame) {
  47598. return frame.style.pointerEvents = silent ? 'none' : '';
  47599. });
  47600. }
  47601. }
  47602. /**
  47603. * Detects if the passed element is a resize handler
  47604. * @param {HTMLElement} el
  47605. * @return {Boolean}
  47606. */
  47607. }, {
  47608. key: "isHandler",
  47609. value: function isHandler(el) {
  47610. var handlers = this.handlers;
  47611. for (var n in handlers) {
  47612. if (handlers[n] === el) return true;
  47613. }
  47614. return false;
  47615. }
  47616. /**
  47617. * Returns the focused element
  47618. * @return {HTMLElement}
  47619. */
  47620. }, {
  47621. key: "getFocusedEl",
  47622. value: function getFocusedEl() {
  47623. return this.el;
  47624. }
  47625. /**
  47626. * Returns documents
  47627. */
  47628. }, {
  47629. key: "getDocumentEl",
  47630. value: function getDocumentEl() {
  47631. return [this.el.ownerDocument, document];
  47632. }
  47633. /**
  47634. * Return element position
  47635. * @param {HTMLElement} el
  47636. * @param {Object} opts Custom options
  47637. * @return {Object}
  47638. */
  47639. }, {
  47640. key: "getElementPos",
  47641. value: function getElementPos(el) {
  47642. var opts = arguments.length > 1 && arguments[1] !== undefined ? arguments[1] : {};
  47643. var posFetcher = this.posFetcher || '';
  47644. return posFetcher ? posFetcher(el, opts) : getBoundingRect(el);
  47645. }
  47646. /**
  47647. * Focus resizer on the element, attaches handlers to it
  47648. * @param {HTMLElement} el
  47649. */
  47650. }, {
  47651. key: "focus",
  47652. value: function focus(el) {
  47653. // Avoid focusing on already focused element
  47654. if (el && el === this.el) {
  47655. return;
  47656. }
  47657. this.el = el;
  47658. this.updateContainer({
  47659. forceShow: 1
  47660. });
  47661. Object(utils_mixins__WEBPACK_IMPORTED_MODULE_4__["on"])(this.getDocumentEl(), 'mousedown', this.handleMouseDown);
  47662. }
  47663. /**
  47664. * Blur from element
  47665. */
  47666. }, {
  47667. key: "blur",
  47668. value: function blur() {
  47669. this.container.style.display = 'none';
  47670. if (this.el) {
  47671. Object(utils_mixins__WEBPACK_IMPORTED_MODULE_4__["off"])(this.getDocumentEl(), 'mousedown', this.handleMouseDown);
  47672. this.el = null;
  47673. }
  47674. }
  47675. /**
  47676. * Start resizing
  47677. * @param {Event} e
  47678. */
  47679. }, {
  47680. key: "start",
  47681. value: function start(e) {
  47682. //Right or middel click
  47683. if (e.button !== 0) return;
  47684. e.preventDefault();
  47685. e.stopPropagation();
  47686. var el = this.el;
  47687. var resizer = this;
  47688. var config = this.opts || {};
  47689. var attrName = 'data-' + config.prefix + 'handler';
  47690. var rect = this.getElementPos(el, {
  47691. target: 'el'
  47692. });
  47693. this.handlerAttr = e.target.getAttribute(attrName);
  47694. this.clickedHandler = e.target;
  47695. this.startDim = {
  47696. t: rect.top,
  47697. l: rect.left,
  47698. w: rect.width,
  47699. h: rect.height
  47700. };
  47701. this.rectDim = {
  47702. t: rect.top,
  47703. l: rect.left,
  47704. w: rect.width,
  47705. h: rect.height
  47706. };
  47707. this.startPos = {
  47708. x: e.clientX,
  47709. y: e.clientY
  47710. }; // Listen events
  47711. var doc = this.getDocumentEl();
  47712. Object(utils_mixins__WEBPACK_IMPORTED_MODULE_4__["on"])(doc, 'mousemove', this.move);
  47713. Object(utils_mixins__WEBPACK_IMPORTED_MODULE_4__["on"])(doc, 'keydown', this.handleKeyDown);
  47714. Object(utils_mixins__WEBPACK_IMPORTED_MODULE_4__["on"])(doc, 'mouseup', this.stop);
  47715. Object(underscore__WEBPACK_IMPORTED_MODULE_3__["isFunction"])(this.onStart) && this.onStart(e, {
  47716. docs: doc,
  47717. config: config,
  47718. el: el,
  47719. resizer: resizer
  47720. });
  47721. this.toggleFrames(1);
  47722. this.move(e);
  47723. }
  47724. /**
  47725. * While resizing
  47726. * @param {Event} e
  47727. */
  47728. }, {
  47729. key: "move",
  47730. value: function move(e) {
  47731. var onMove = this.onMove;
  47732. var mouseFetch = this.mousePosFetcher;
  47733. var currentPos = mouseFetch ? mouseFetch(e) : {
  47734. x: e.clientX,
  47735. y: e.clientY
  47736. };
  47737. this.currentPos = currentPos;
  47738. this.delta = {
  47739. x: currentPos.x - this.startPos.x,
  47740. y: currentPos.y - this.startPos.y
  47741. };
  47742. this.keys = {
  47743. shift: e.shiftKey,
  47744. ctrl: e.ctrlKey,
  47745. alt: e.altKey
  47746. };
  47747. this.rectDim = this.calc(this);
  47748. this.updateRect(0); // Move callback
  47749. onMove && onMove(e); // In case the mouse button was released outside of the window
  47750. if (e.which === 0) {
  47751. this.stop(e);
  47752. }
  47753. }
  47754. /**
  47755. * Stop resizing
  47756. * @param {Event} e
  47757. */
  47758. }, {
  47759. key: "stop",
  47760. value: function stop(e) {
  47761. var config = this.opts;
  47762. var doc = this.getDocumentEl();
  47763. Object(utils_mixins__WEBPACK_IMPORTED_MODULE_4__["off"])(doc, 'mousemove', this.move);
  47764. Object(utils_mixins__WEBPACK_IMPORTED_MODULE_4__["off"])(doc, 'keydown', this.handleKeyDown);
  47765. Object(utils_mixins__WEBPACK_IMPORTED_MODULE_4__["off"])(doc, 'mouseup', this.stop);
  47766. this.updateRect(1);
  47767. this.toggleFrames();
  47768. Object(underscore__WEBPACK_IMPORTED_MODULE_3__["isFunction"])(this.onEnd) && this.onEnd(e, {
  47769. docs: doc,
  47770. config: config
  47771. });
  47772. }
  47773. /**
  47774. * Update rect
  47775. */
  47776. }, {
  47777. key: "updateRect",
  47778. value: function updateRect(store) {
  47779. var el = this.el;
  47780. var resizer = this;
  47781. var config = this.opts;
  47782. var rect = this.rectDim;
  47783. var updateTarget = this.updateTarget;
  47784. var selectedHandler = this.getSelectedHandler();
  47785. var unitHeight = config.unitHeight,
  47786. unitWidth = config.unitWidth,
  47787. keyWidth = config.keyWidth,
  47788. keyHeight = config.keyHeight; // Use custom updating strategy if requested
  47789. if (Object(underscore__WEBPACK_IMPORTED_MODULE_3__["isFunction"])(updateTarget)) {
  47790. updateTarget(el, rect, {
  47791. store: store,
  47792. selectedHandler: selectedHandler,
  47793. resizer: resizer,
  47794. config: config
  47795. });
  47796. } else {
  47797. var elStyle = el.style;
  47798. elStyle[keyWidth] = rect.w + unitWidth;
  47799. elStyle[keyHeight] = rect.h + unitHeight;
  47800. }
  47801. this.updateContainer();
  47802. }
  47803. }, {
  47804. key: "updateContainer",
  47805. value: function updateContainer() {
  47806. var opt = arguments.length > 0 && arguments[0] !== undefined ? arguments[0] : {};
  47807. var opts = this.opts,
  47808. container = this.container,
  47809. el = this.el;
  47810. var style = container.style;
  47811. if (!opts.avoidContainerUpdate && el) {
  47812. // On component resize container fits the tool,
  47813. // to check if this update is required somewhere else point
  47814. // const toUpdate = ['left', 'top', 'width', 'height'];
  47815. // const rectEl = this.getElementPos(el, { target: 'container' });
  47816. // toUpdate.forEach(pos => (style[pos] = `${rectEl[pos]}px`));
  47817. if (opt.forceShow) style.display = 'block';
  47818. }
  47819. this.onUpdateContainer({
  47820. el: container,
  47821. resizer: this,
  47822. opts: _objectSpread({}, opts, {}, opt)
  47823. });
  47824. }
  47825. /**
  47826. * Get selected handler name
  47827. * @return {string}
  47828. */
  47829. }, {
  47830. key: "getSelectedHandler",
  47831. value: function getSelectedHandler() {
  47832. var handlers = this.handlers;
  47833. if (!this.selectedHandler) {
  47834. return;
  47835. }
  47836. for (var n in handlers) {
  47837. if (handlers[n] === this.selectedHandler) return n;
  47838. }
  47839. }
  47840. /**
  47841. * Handle ESC key
  47842. * @param {Event} e
  47843. */
  47844. }, {
  47845. key: "handleKeyDown",
  47846. value: function handleKeyDown(e) {
  47847. if (e.keyCode === 27) {
  47848. // Rollback to initial dimensions
  47849. this.rectDim = this.startDim;
  47850. this.stop(e);
  47851. }
  47852. }
  47853. /**
  47854. * Handle mousedown to check if it's possible to start resizing
  47855. * @param {Event} e
  47856. */
  47857. }, {
  47858. key: "handleMouseDown",
  47859. value: function handleMouseDown(e) {
  47860. var el = e.target;
  47861. if (this.isHandler(el)) {
  47862. this.selectedHandler = el;
  47863. this.start(e);
  47864. } else if (el !== this.el) {
  47865. this.selectedHandler = '';
  47866. this.blur();
  47867. }
  47868. }
  47869. /**
  47870. * All positioning logic
  47871. * @return {Object}
  47872. */
  47873. }, {
  47874. key: "calc",
  47875. value: function calc(data) {
  47876. var value;
  47877. var opts = this.opts || {};
  47878. var step = opts.step;
  47879. var startDim = this.startDim;
  47880. var minDim = opts.minDim;
  47881. var maxDim = opts.maxDim;
  47882. var deltaX = data.delta.x;
  47883. var deltaY = data.delta.y;
  47884. var startW = startDim.w;
  47885. var startH = startDim.h;
  47886. var box = {
  47887. t: 0,
  47888. l: 0,
  47889. w: startW,
  47890. h: startH
  47891. };
  47892. if (!data) return;
  47893. var attr = data.handlerAttr;
  47894. if (~attr.indexOf('r')) {
  47895. value = Object(utils_mixins__WEBPACK_IMPORTED_MODULE_4__["normalizeFloat"])(startW + deltaX * step, step);
  47896. value = Math.max(minDim, value);
  47897. maxDim && (value = Math.min(maxDim, value));
  47898. box.w = value;
  47899. }
  47900. if (~attr.indexOf('b')) {
  47901. value = Object(utils_mixins__WEBPACK_IMPORTED_MODULE_4__["normalizeFloat"])(startH + deltaY * step, step);
  47902. value = Math.max(minDim, value);
  47903. maxDim && (value = Math.min(maxDim, value));
  47904. box.h = value;
  47905. }
  47906. if (~attr.indexOf('l')) {
  47907. value = Object(utils_mixins__WEBPACK_IMPORTED_MODULE_4__["normalizeFloat"])(startW - deltaX * step, step);
  47908. value = Math.max(minDim, value);
  47909. maxDim && (value = Math.min(maxDim, value));
  47910. box.w = value;
  47911. }
  47912. if (~attr.indexOf('t')) {
  47913. value = Object(utils_mixins__WEBPACK_IMPORTED_MODULE_4__["normalizeFloat"])(startH - deltaY * step, step);
  47914. value = Math.max(minDim, value);
  47915. maxDim && (value = Math.min(maxDim, value));
  47916. box.h = value;
  47917. } // Enforce aspect ratio (unless shift key is being held)
  47918. var ratioActive = opts.ratioDefault ? !data.keys.shift : data.keys.shift;
  47919. if (attr.indexOf('c') < 0 && ratioActive) {
  47920. var ratio = startDim.w / startDim.h;
  47921. if (box.w / box.h > ratio) {
  47922. box.h = Math.round(box.w / ratio);
  47923. } else {
  47924. box.w = Math.round(box.h * ratio);
  47925. }
  47926. }
  47927. if (~attr.indexOf('l')) {
  47928. box.l = startDim.w - box.w;
  47929. }
  47930. if (~attr.indexOf('t')) {
  47931. box.t = startDim.h - box.h;
  47932. }
  47933. return box;
  47934. }
  47935. }]);
  47936. return Resizer;
  47937. }();
  47938. /* harmony default export */ __webpack_exports__["default"] = ({
  47939. init: function init(opts) {
  47940. return new Resizer(opts);
  47941. }
  47942. });
  47943. /***/ }),
  47944. /***/ "./src/utils/Sorter.js":
  47945. /*!*****************************!*\
  47946. !*** ./src/utils/Sorter.js ***!
  47947. \*****************************/
  47948. /*! exports provided: default */
  47949. /***/ (function(module, __webpack_exports__, __webpack_require__) {
  47950. "use strict";
  47951. __webpack_require__.r(__webpack_exports__);
  47952. /* harmony import */ var _babel_runtime_helpers_defineProperty__WEBPACK_IMPORTED_MODULE_0__ = __webpack_require__(/*! @babel/runtime/helpers/defineProperty */ "./node_modules/@babel/runtime/helpers/defineProperty.js");
  47953. /* harmony import */ var _babel_runtime_helpers_defineProperty__WEBPACK_IMPORTED_MODULE_0___default = /*#__PURE__*/__webpack_require__.n(_babel_runtime_helpers_defineProperty__WEBPACK_IMPORTED_MODULE_0__);
  47954. /* harmony import */ var backbone__WEBPACK_IMPORTED_MODULE_1__ = __webpack_require__(/*! backbone */ "./node_modules/backbone/backbone.js");
  47955. /* harmony import */ var backbone__WEBPACK_IMPORTED_MODULE_1___default = /*#__PURE__*/__webpack_require__.n(backbone__WEBPACK_IMPORTED_MODULE_1__);
  47956. /* harmony import */ var underscore__WEBPACK_IMPORTED_MODULE_2__ = __webpack_require__(/*! underscore */ "./node_modules/underscore/underscore.js");
  47957. /* harmony import */ var underscore__WEBPACK_IMPORTED_MODULE_2___default = /*#__PURE__*/__webpack_require__.n(underscore__WEBPACK_IMPORTED_MODULE_2__);
  47958. /* harmony import */ var utils_mixins__WEBPACK_IMPORTED_MODULE_3__ = __webpack_require__(/*! utils/mixins */ "./src/utils/mixins.js");
  47959. function ownKeys(object, enumerableOnly) { var keys = Object.keys(object); if (Object.getOwnPropertySymbols) { var symbols = Object.getOwnPropertySymbols(object); if (enumerableOnly) symbols = symbols.filter(function (sym) { return Object.getOwnPropertyDescriptor(object, sym).enumerable; }); keys.push.apply(keys, symbols); } return keys; }
  47960. function _objectSpread(target) { for (var i = 1; i < arguments.length; i++) { var source = arguments[i] != null ? arguments[i] : {}; if (i % 2) { ownKeys(source, true).forEach(function (key) { _babel_runtime_helpers_defineProperty__WEBPACK_IMPORTED_MODULE_0___default()(target, key, source[key]); }); } else if (Object.getOwnPropertyDescriptors) { Object.defineProperties(target, Object.getOwnPropertyDescriptors(source)); } else { ownKeys(source).forEach(function (key) { Object.defineProperty(target, key, Object.getOwnPropertyDescriptor(source, key)); }); } } return target; }
  47961. var $ = backbone__WEBPACK_IMPORTED_MODULE_1___default.a.$;
  47962. /* harmony default export */ __webpack_exports__["default"] = (backbone__WEBPACK_IMPORTED_MODULE_1___default.a.View.extend({
  47963. initialize: function initialize(opt) {
  47964. this.opt = opt || {};
  47965. Object(underscore__WEBPACK_IMPORTED_MODULE_2__["bindAll"])(this, 'startSort', 'onMove', 'endMove', 'rollback', 'updateOffset', 'moveDragHelper');
  47966. var o = opt || {};
  47967. this.elT = 0;
  47968. this.elL = 0;
  47969. this.borderOffset = o.borderOffset || 10;
  47970. var el = o.container;
  47971. this.el = typeof el === 'string' ? document.querySelector(el) : el;
  47972. this.$el = $(this.el);
  47973. this.containerSel = o.containerSel || 'div';
  47974. this.itemSel = o.itemSel || 'div';
  47975. this.draggable = o.draggable || true;
  47976. this.nested = o.nested || 0;
  47977. this.pfx = o.pfx || '';
  47978. this.ppfx = o.ppfx || '';
  47979. this.freezeClass = o.freezeClass || this.pfx + 'freezed';
  47980. this.onStart = o.onStart || '';
  47981. this.onEndMove = o.onEndMove || '';
  47982. this.direction = o.direction || 'v'; // v (vertical), h (horizontal), a (auto)
  47983. this.onMoveClb = o.onMove || '';
  47984. this.relative = o.relative || 0;
  47985. this.ignoreViewChildren = o.ignoreViewChildren || 0;
  47986. this.ignoreModels = o.ignoreModels || 0;
  47987. this.plh = o.placer || ''; // Frame offset
  47988. this.wmargin = o.wmargin || 0;
  47989. this.offTop = o.offsetTop || 0;
  47990. this.offLeft = o.offsetLeft || 0;
  47991. this.document = o.document || document;
  47992. this.$document = $(this.document);
  47993. this.dropContent = null;
  47994. this.em = o.em || '';
  47995. this.dragHelper = null;
  47996. this.canvasRelative = o.canvasRelative || 0;
  47997. this.selectOnEnd = !o.avoidSelectOnEnd;
  47998. this.scale = o.scale;
  47999. this.activeTextModel = null;
  48000. if (this.em && this.em.on) {
  48001. this.em.on('change:canvasOffset', this.updateOffset);
  48002. this.updateOffset();
  48003. }
  48004. },
  48005. getScale: function getScale() {
  48006. return Object(underscore__WEBPACK_IMPORTED_MODULE_2__["result"])(this, scale) || 1;
  48007. },
  48008. getContainerEl: function getContainerEl(elem) {
  48009. if (elem) this.el = elem;
  48010. if (!this.el) {
  48011. var el = this.opt.container;
  48012. this.el = typeof el === 'string' ? document.querySelector(el) : el;
  48013. this.$el = $(this.el);
  48014. }
  48015. return this.el;
  48016. },
  48017. getDocuments: function getDocuments(el) {
  48018. var em = this.em;
  48019. var elDoc = el ? el.ownerDocument : em && em.get('Canvas').getBody().ownerDocument;
  48020. var docs = [document];
  48021. elDoc && docs.push(elDoc);
  48022. return docs;
  48023. },
  48024. /**
  48025. * Triggered when the offset of the editro is changed
  48026. */
  48027. updateOffset: function updateOffset() {
  48028. var offset = this.em.get('canvasOffset') || {};
  48029. this.offTop = offset.top;
  48030. this.offLeft = offset.left;
  48031. },
  48032. /**
  48033. * Set content to drop
  48034. * @param {String|Object} content
  48035. */
  48036. setDropContent: function setDropContent(content) {
  48037. this.dropModel = null;
  48038. this.dropContent = content;
  48039. },
  48040. updateTextViewCursorPosition: function updateTextViewCursorPosition(e) {
  48041. var Canvas = this.em.get('Canvas');
  48042. var targetDoc = Canvas.getDocument();
  48043. var range = null;
  48044. if (targetDoc.caretRangeFromPoint) {
  48045. // Chrome
  48046. var poiner = Object(utils_mixins__WEBPACK_IMPORTED_MODULE_3__["getPointerEvent"])(e);
  48047. range = targetDoc.caretRangeFromPoint(poiner.clientX, poiner.clientY);
  48048. } else if (e.rangeParent) {
  48049. // Firefox
  48050. range = targetDoc.createRange();
  48051. range.setStart(e.rangeParent, e.rangeOffset);
  48052. }
  48053. var sel = Canvas.getWindow().getSelection();
  48054. Canvas.getFrameEl().focus();
  48055. sel.removeAllRanges();
  48056. range && sel.addRange(range);
  48057. },
  48058. setContentEditable: function setContentEditable(model, mode) {
  48059. if (model) {
  48060. var el = model.getEl();
  48061. if (el.contentEditable != mode) el.contentEditable = mode;
  48062. }
  48063. },
  48064. /**
  48065. * Toggle cursor while sorting
  48066. * @param {Boolean} active
  48067. */
  48068. toggleSortCursor: function toggleSortCursor(active) {
  48069. var em = this.em;
  48070. var cv = em && em.get('Canvas'); // Avoid updating body className as it causes a huge repaint
  48071. // Noticeable with "fast" drag of blocks
  48072. cv && (active ? cv.startAutoscroll() : cv.stopAutoscroll());
  48073. },
  48074. /**
  48075. * Set drag helper
  48076. * @param {HTMLElement} el
  48077. * @param {Event} event
  48078. */
  48079. setDragHelper: function setDragHelper(el, event) {
  48080. var ev = event || '';
  48081. var clonedEl = el.cloneNode(1);
  48082. var rect = el.getBoundingClientRect();
  48083. var computed = getComputedStyle(el);
  48084. var style = '';
  48085. for (var i = 0; i < computed.length; i++) {
  48086. var prop = computed[i];
  48087. style += "".concat(prop, ":").concat(computed.getPropertyValue(prop), ";");
  48088. }
  48089. document.body.appendChild(clonedEl);
  48090. clonedEl.className += " ".concat(this.pfx, "bdrag");
  48091. clonedEl.setAttribute('style', style);
  48092. this.dragHelper = clonedEl;
  48093. clonedEl.style.width = "".concat(rect.width, "px");
  48094. clonedEl.style.height = "".concat(rect.height, "px");
  48095. ev && this.moveDragHelper(ev); // Listen mouse move events
  48096. if (this.em) {
  48097. $(this.em.get('Canvas').getBody().ownerDocument).off('mousemove', this.moveDragHelper).on('mousemove', this.moveDragHelper);
  48098. }
  48099. $(document).off('mousemove', this.moveDragHelper).on('mousemove', this.moveDragHelper);
  48100. },
  48101. /**
  48102. * Update the position of the helper
  48103. * @param {Event} e
  48104. */
  48105. moveDragHelper: function moveDragHelper(e) {
  48106. var doc = e.target.ownerDocument;
  48107. if (!this.dragHelper || !doc) {
  48108. return;
  48109. }
  48110. var posY = e.pageY;
  48111. var posX = e.pageX;
  48112. var addTop = 0;
  48113. var addLeft = 0;
  48114. var window = doc.defaultView || doc.parentWindow;
  48115. var frame = window.frameElement;
  48116. var dragHelperStyle = this.dragHelper.style; // If frame is present that means mouse has moved over the editor's canvas,
  48117. // which is rendered inside the iframe and the mouse move event comes from
  48118. // the iframe, not the parent window. Mouse position relative to the frame's
  48119. // parent window needs to account for the frame's position relative to the
  48120. // parent window.
  48121. if (frame) {
  48122. var frameRect = frame.getBoundingClientRect();
  48123. addTop = frameRect.top + document.documentElement.scrollTop;
  48124. addLeft = frameRect.left + document.documentElement.scrollLeft;
  48125. posY = e.clientY;
  48126. posX = e.clientX;
  48127. }
  48128. dragHelperStyle.top = posY + addTop + 'px';
  48129. dragHelperStyle.left = posX + addLeft + 'px';
  48130. },
  48131. /**
  48132. * Returns true if the element matches with selector
  48133. * @param {Element} el
  48134. * @param {String} selector
  48135. * @return {Boolean}
  48136. */
  48137. matches: function matches(el, selector, useBody) {
  48138. return utils_mixins__WEBPACK_IMPORTED_MODULE_3__["matches"].call(el, selector);
  48139. },
  48140. /**
  48141. * Closest parent
  48142. * @param {Element} el
  48143. * @param {String} selector
  48144. * @return {Element|null}
  48145. */
  48146. closest: function closest(el, selector) {
  48147. if (!el) return;
  48148. var elem = el.parentNode;
  48149. while (elem && elem.nodeType === 1) {
  48150. if (this.matches(elem, selector)) return elem;
  48151. elem = elem.parentNode;
  48152. }
  48153. return null;
  48154. },
  48155. /**
  48156. * Get the offset of the element
  48157. * @param {HTMLElement} el
  48158. * @return {Object}
  48159. */
  48160. offset: function offset(el) {
  48161. var rect = el.getBoundingClientRect();
  48162. return {
  48163. top: rect.top + document.body.scrollTop,
  48164. left: rect.left + document.body.scrollLeft
  48165. };
  48166. },
  48167. /**
  48168. * Create placeholder
  48169. * @return {HTMLElement}
  48170. */
  48171. createPlaceholder: function createPlaceholder() {
  48172. var pfx = this.pfx;
  48173. var el = document.createElement('div');
  48174. var ins = document.createElement('div');
  48175. el.className = pfx + 'placeholder';
  48176. el.style.display = 'none';
  48177. el.style['pointer-events'] = 'none';
  48178. ins.className = pfx + 'placeholder-int';
  48179. el.appendChild(ins);
  48180. return el;
  48181. },
  48182. /**
  48183. * Picking component to move
  48184. * @param {HTMLElement} src
  48185. * */
  48186. startSort: function startSort(src) {
  48187. var opts = arguments.length > 1 && arguments[1] !== undefined ? arguments[1] : {};
  48188. var em = this.em;
  48189. var itemSel = this.itemSel;
  48190. var contSel = this.containerSel;
  48191. var container = this.getContainerEl(opts.container);
  48192. var docs = this.getDocuments(src);
  48193. var onStart = this.onStart;
  48194. var srcModel;
  48195. var plh = this.plh;
  48196. this.dropModel = null;
  48197. this.target = null;
  48198. this.prevTarget = null;
  48199. this.moved = 0; // Check if the start element is a valid one, if not get the
  48200. // closest valid one
  48201. if (src && !this.matches(src, "".concat(itemSel, ", ").concat(contSel))) {
  48202. src = this.closest(src, itemSel);
  48203. }
  48204. this.eV = src; // Create placeholder if not yet exists
  48205. if (!plh) {
  48206. plh = this.createPlaceholder();
  48207. container.appendChild(plh);
  48208. this.plh = plh;
  48209. }
  48210. if (src) {
  48211. srcModel = this.getSourceModel(src);
  48212. srcModel && srcModel.set && srcModel.set('status', 'freezed');
  48213. this.srcModel = srcModel;
  48214. }
  48215. Object(utils_mixins__WEBPACK_IMPORTED_MODULE_3__["on"])(container, 'mousemove dragover', this.onMove);
  48216. Object(utils_mixins__WEBPACK_IMPORTED_MODULE_3__["on"])(docs, 'mouseup dragend touchend', this.endMove);
  48217. Object(utils_mixins__WEBPACK_IMPORTED_MODULE_3__["on"])(docs, 'keydown', this.rollback);
  48218. onStart && onStart({
  48219. target: srcModel,
  48220. parent: srcModel && srcModel.parent(),
  48221. index: srcModel && srcModel.index()
  48222. }); // Avoid strange effects on dragging
  48223. em && em.clearSelection();
  48224. this.toggleSortCursor(1);
  48225. em && em.trigger('sorter:drag:start', src, srcModel);
  48226. },
  48227. /**
  48228. * Get the model from HTMLElement target
  48229. * @return {Model|null}
  48230. */
  48231. getTargetModel: function getTargetModel(el) {
  48232. var elem = el || this.target;
  48233. return $(elem).data('model');
  48234. },
  48235. /**
  48236. * Get the model of the current source element (element to drag)
  48237. * @return {Model}
  48238. */
  48239. getSourceModel: function getSourceModel(source) {
  48240. var _this = this;
  48241. var _ref = arguments.length > 1 && arguments[1] !== undefined ? arguments[1] : {},
  48242. target = _ref.target,
  48243. _ref$avoidChildren = _ref.avoidChildren,
  48244. avoidChildren = _ref$avoidChildren === void 0 ? 1 : _ref$avoidChildren;
  48245. var em = this.em,
  48246. eV = this.eV;
  48247. var src = source || eV;
  48248. var dropModel = this.dropModel,
  48249. dropContent = this.dropContent;
  48250. var isTextable = function isTextable(src) {
  48251. return src && target && src.opt && src.opt.avoidChildren && _this.isTextableActive(src, target);
  48252. };
  48253. if (dropContent && em) {
  48254. if (isTextable(dropModel)) {
  48255. dropModel = null;
  48256. }
  48257. if (!dropModel) {
  48258. var comps = em.get('DomComponents').getComponents();
  48259. var opts = {
  48260. avoidChildren: avoidChildren,
  48261. avoidStore: 1,
  48262. avoidUpdateStyle: 1
  48263. };
  48264. var tempModel = comps.add(dropContent, _objectSpread({}, opts, {
  48265. temporary: 1
  48266. }));
  48267. dropModel = comps.remove(tempModel, opts);
  48268. dropModel = dropModel instanceof Array ? dropModel[0] : dropModel;
  48269. this.dropModel = dropModel;
  48270. if (isTextable(dropModel)) {
  48271. return this.getSourceModel(src, {
  48272. target: target,
  48273. avoidChildren: 0
  48274. });
  48275. }
  48276. }
  48277. return dropModel;
  48278. }
  48279. return src && $(src).data('model');
  48280. },
  48281. /**
  48282. * Highlight target
  48283. * @param {Model|null} model
  48284. */
  48285. selectTargetModel: function selectTargetModel(model) {
  48286. if (model instanceof backbone__WEBPACK_IMPORTED_MODULE_1___default.a.Collection) {
  48287. return;
  48288. }
  48289. var targetModel = this.targetModel; // Reset the previous model but not if it's the same as the source
  48290. // https://github.com/artf/grapesjs/issues/2478#issuecomment-570314736
  48291. if (targetModel && targetModel !== this.srcModel) {
  48292. targetModel.set('status', '');
  48293. }
  48294. if (model && model.set) {
  48295. model.set('status', 'selected-parent');
  48296. this.targetModel = model;
  48297. }
  48298. },
  48299. /**
  48300. * During move
  48301. * @param {Event} e
  48302. * */
  48303. onMove: function onMove(e) {
  48304. var ev = e;
  48305. var em = this.em,
  48306. onMoveClb = this.onMoveClb,
  48307. plh = this.plh;
  48308. this.moved = 1; // Turn placeholder visibile
  48309. var dsp = plh.style.display;
  48310. if (!dsp || dsp === 'none') plh.style.display = 'block'; // Cache all necessary positions
  48311. var eO = this.offset(this.el);
  48312. this.elT = this.wmargin ? Math.abs(eO.top) : eO.top;
  48313. this.elL = this.wmargin ? Math.abs(eO.left) : eO.left;
  48314. var rY = e.pageY - this.elT + this.el.scrollTop;
  48315. var rX = e.pageX - this.elL + this.el.scrollLeft;
  48316. if (this.canvasRelative && em) {
  48317. var mousePos = em.get('Canvas').getMouseRelativeCanvas(e, {
  48318. noScroll: 1
  48319. });
  48320. rX = mousePos.x;
  48321. rY = mousePos.y;
  48322. }
  48323. this.rX = rX;
  48324. this.rY = rY;
  48325. this.eventMove = e; //var targetNew = this.getTargetFromEl(e.target);
  48326. var sourceModel = this.getSourceModel();
  48327. var dims = this.dimsFromTarget(e.target, rX, rY);
  48328. var target = this.target;
  48329. var targetModel = target && this.getTargetModel(target);
  48330. this.selectTargetModel(targetModel);
  48331. if (!targetModel) plh.style.display = 'none';
  48332. if (!target) return;
  48333. this.lastDims = dims;
  48334. var pos = this.findPosition(dims, rX, rY);
  48335. if (this.isTextableActive(sourceModel, targetModel)) {
  48336. this.activeTextModel = targetModel;
  48337. this.setContentEditable(targetModel, true);
  48338. plh.style.display = 'none';
  48339. this.lastPos = pos;
  48340. this.updateTextViewCursorPosition(ev);
  48341. } else {
  48342. this.disableTextable();
  48343. this.activeTextModel = null; // If there is a significant changes with the pointer
  48344. if (!this.lastPos || this.lastPos.index != pos.index || this.lastPos.method != pos.method) {
  48345. this.movePlaceholder(this.plh, dims, pos, this.prevTargetDim);
  48346. if (!this.$plh) this.$plh = $(this.plh); // With canvasRelative the offset is calculated automatically for
  48347. // each element
  48348. if (!this.canvasRelative) {
  48349. if (this.offTop) this.$plh.css('top', '+=' + this.offTop + 'px');
  48350. if (this.offLeft) this.$plh.css('left', '+=' + this.offLeft + 'px');
  48351. }
  48352. this.lastPos = pos;
  48353. }
  48354. }
  48355. Object(underscore__WEBPACK_IMPORTED_MODULE_2__["isFunction"])(onMoveClb) && onMoveClb({
  48356. event: e,
  48357. target: sourceModel,
  48358. parent: targetModel,
  48359. index: pos.index + (pos.method == 'after' ? 1 : 0)
  48360. });
  48361. em && em.trigger('sorter:drag', {
  48362. target: target,
  48363. targetModel: targetModel,
  48364. sourceModel: sourceModel,
  48365. dims: dims,
  48366. pos: pos,
  48367. x: rX,
  48368. y: rY
  48369. });
  48370. },
  48371. isTextableActive: function isTextableActive(src, trg) {
  48372. return src && src.get && src.get('textable') && trg && trg.is('text');
  48373. },
  48374. disableTextable: function disableTextable() {
  48375. var activeTextModel = this.activeTextModel;
  48376. activeTextModel && activeTextModel.getView().disableEditing();
  48377. },
  48378. /**
  48379. * Returns true if the elements is in flow, so is not in flow where
  48380. * for example the component is with float:left
  48381. * @param {HTMLElement} el
  48382. * @param {HTMLElement} parent
  48383. * @return {Boolean}
  48384. * @private
  48385. * */
  48386. isInFlow: function isInFlow(el, parent) {
  48387. if (!el) return false;
  48388. parent = parent || document.body;
  48389. var ch = -1,
  48390. h;
  48391. var elem = el;
  48392. h = elem.offsetHeight;
  48393. if (
  48394. /*h < ch || */
  48395. !this.styleInFlow(elem, parent)) return false;else return true;
  48396. },
  48397. /**
  48398. * Check if el has style to be in flow
  48399. * @param {HTMLElement} el
  48400. * @param {HTMLElement} parent
  48401. * @return {Boolean}
  48402. * @private
  48403. */
  48404. styleInFlow: function styleInFlow(el, parent) {
  48405. if (Object(utils_mixins__WEBPACK_IMPORTED_MODULE_3__["isTextNode"])(el)) return;
  48406. var style = el.style || {};
  48407. var $el = $(el);
  48408. var $parent = parent && $(parent);
  48409. if (style.overflow && style.overflow !== 'visible') return;
  48410. if ($el.css('float') !== 'none') return;
  48411. if ($parent && $parent.css('display') == 'flex' && $parent.css('flex-direction') !== 'column') return;
  48412. switch (style.position) {
  48413. case 'static':
  48414. case 'relative':
  48415. case '':
  48416. break;
  48417. default:
  48418. return;
  48419. }
  48420. switch (el.tagName) {
  48421. case 'TR':
  48422. case 'TBODY':
  48423. case 'THEAD':
  48424. case 'TFOOT':
  48425. return true;
  48426. }
  48427. switch ($el.css('display')) {
  48428. case 'block':
  48429. case 'list-item':
  48430. case 'table':
  48431. case 'flex':
  48432. return true;
  48433. }
  48434. return;
  48435. },
  48436. /**
  48437. * Check if the target is valid with the actual source
  48438. * @param {HTMLElement} trg
  48439. * @return {Boolean}
  48440. */
  48441. validTarget: function validTarget(trg, src) {
  48442. var trgModel = this.getTargetModel(trg);
  48443. var srcModel = this.getSourceModel(src, {
  48444. target: trgModel
  48445. });
  48446. src = srcModel && srcModel.view && srcModel.view.el;
  48447. trg = trgModel && trgModel.view && trgModel.view.el;
  48448. var result = {
  48449. valid: true,
  48450. src: src,
  48451. srcModel: srcModel,
  48452. trg: trg,
  48453. trgModel: trgModel
  48454. };
  48455. if (!src || !trg) {
  48456. result.valid = false;
  48457. return result;
  48458. } // check if the source is draggable in target
  48459. var draggable = srcModel.get('draggable');
  48460. draggable = draggable instanceof Array ? draggable.join(', ') : draggable;
  48461. result.dragInfo = draggable;
  48462. draggable = Object(underscore__WEBPACK_IMPORTED_MODULE_2__["isString"])(draggable) ? this.matches(trg, draggable) : draggable;
  48463. result.draggable = draggable; // Check if the target could accept the source
  48464. var droppable = trgModel.get('droppable');
  48465. droppable = droppable instanceof backbone__WEBPACK_IMPORTED_MODULE_1___default.a.Collection ? 1 : droppable;
  48466. droppable = droppable instanceof Array ? droppable.join(', ') : droppable;
  48467. result.dropInfo = droppable;
  48468. droppable = Object(underscore__WEBPACK_IMPORTED_MODULE_2__["isString"])(droppable) ? this.matches(src, droppable) : droppable;
  48469. droppable = draggable && this.isTextableActive(srcModel, trgModel) ? 1 : droppable;
  48470. result.droppable = droppable;
  48471. if (!droppable || !draggable) {
  48472. result.valid = false;
  48473. }
  48474. return result;
  48475. },
  48476. /**
  48477. * Get dimensions of nodes relative to the coordinates
  48478. * @param {HTMLElement} target
  48479. * @param {number} rX Relative X position
  48480. * @param {number} rY Relative Y position
  48481. * @return {Array<Array>}
  48482. */
  48483. dimsFromTarget: function dimsFromTarget(target, rX, rY) {
  48484. var em = this.em;
  48485. var dims = [];
  48486. if (!target) {
  48487. return dims;
  48488. } // Select the first valuable target
  48489. if (!this.matches(target, "".concat(this.itemSel, ", ").concat(this.containerSel))) {
  48490. target = this.closest(target, this.itemSel);
  48491. } // If draggable is an array the target will be one of those
  48492. if (this.draggable instanceof Array) {
  48493. target = this.closest(target, this.draggable.join(','));
  48494. }
  48495. if (!target) {
  48496. return dims;
  48497. } // Check if the target is different from the previous one
  48498. if (this.prevTarget && this.prevTarget != target) {
  48499. this.prevTarget = null;
  48500. } // New target found
  48501. if (!this.prevTarget) {
  48502. this.targetP = this.closest(target, this.containerSel); // Check if the source is valid with the target
  48503. var validResult = this.validTarget(target);
  48504. em && em.trigger('sorter:drag:validation', validResult);
  48505. if (!validResult.valid && this.targetP) {
  48506. return this.dimsFromTarget(this.targetP, rX, rY);
  48507. }
  48508. this.prevTarget = target;
  48509. this.prevTargetDim = this.getDim(target);
  48510. this.cacheDimsP = this.getChildrenDim(this.targetP);
  48511. this.cacheDims = this.getChildrenDim(target);
  48512. } // If the target is the previous one will return the cached dims
  48513. if (this.prevTarget == target) dims = this.cacheDims; // Target when I will drop element to sort
  48514. this.target = this.prevTarget; // Generally, on any new target the poiner enters inside its area and
  48515. // triggers nearBorders(), so have to take care of this
  48516. if (this.nearBorders(this.prevTargetDim, rX, rY) || !this.nested && !this.cacheDims.length) {
  48517. var targetParent = this.targetP;
  48518. if (targetParent && this.validTarget(targetParent).valid) {
  48519. dims = this.cacheDimsP;
  48520. this.target = targetParent;
  48521. }
  48522. }
  48523. this.lastPos = null;
  48524. return dims;
  48525. },
  48526. /**
  48527. * Get valid target from element
  48528. * This method should replace dimsFromTarget()
  48529. * @param {HTMLElement} el
  48530. * @return {HTMLElement}
  48531. */
  48532. getTargetFromEl: function getTargetFromEl(el) {
  48533. var target = el;
  48534. var targetParent;
  48535. var targetPrev = this.targetPrev;
  48536. var em = this.em;
  48537. var containerSel = this.containerSel;
  48538. var itemSel = this.itemSel; // Select the first valuable target
  48539. if (!this.matches(target, "".concat(itemSel, ", ").concat(containerSel))) {
  48540. target = this.closest(target, itemSel);
  48541. } // If draggable is an array the target will be one of those
  48542. // TODO check if this options is used somewhere
  48543. if (this.draggable instanceof Array) {
  48544. target = this.closest(target, this.draggable.join(','));
  48545. } // Check if the target is different from the previous one
  48546. if (targetPrev && targetPrev != target) {
  48547. this.targetPrev = '';
  48548. } // New target found
  48549. if (!this.targetPrev) {
  48550. targetParent = this.closest(target, containerSel); // If the current target is not valid (src/trg reasons) try with
  48551. // the parent one (if exists)
  48552. var validResult = this.validTarget(target);
  48553. em && em.trigger('sorter:drag:validation', validResult);
  48554. if (!validResult.valid && targetParent) {
  48555. return this.getTargetFromEl(targetParent);
  48556. }
  48557. this.targetPrev = target;
  48558. } // Generally, on any new target the poiner enters inside its area and
  48559. // triggers nearBorders(), so have to take care of this
  48560. if (this.nearElBorders(target)) {
  48561. targetParent = this.closest(target, containerSel);
  48562. if (targetParent && this.validTarget(targetParent).valid) {
  48563. target = targetParent;
  48564. }
  48565. }
  48566. return target;
  48567. },
  48568. /**
  48569. * Check if the current pointer is neare to element borders
  48570. * @return {Boolen}
  48571. */
  48572. nearElBorders: function nearElBorders(el) {
  48573. var off = 10;
  48574. var rect = el.getBoundingClientRect();
  48575. var body = el.ownerDocument.body;
  48576. var _this$getCurrentPos = this.getCurrentPos(),
  48577. x = _this$getCurrentPos.x,
  48578. y = _this$getCurrentPos.y;
  48579. var top = rect.top + body.scrollTop;
  48580. var left = rect.left + body.scrollLeft;
  48581. var width = rect.width;
  48582. var height = rect.height;
  48583. if (y < top + off || // near top edge
  48584. y > top + height - off || // near bottom edge
  48585. x < left + off || // near left edge
  48586. x > left + width - off // near right edge
  48587. ) {
  48588. return 1;
  48589. }
  48590. },
  48591. getCurrentPos: function getCurrentPos() {
  48592. var ev = this.eventMove;
  48593. var x = ev.pageX || 0;
  48594. var y = ev.pageY || 0;
  48595. return {
  48596. x: x,
  48597. y: y
  48598. };
  48599. },
  48600. /**
  48601. * Returns dimensions and positions about the element
  48602. * @param {HTMLElement} el
  48603. * @return {Array<number>}
  48604. */
  48605. getDim: function getDim(el) {
  48606. var em = this.em,
  48607. canvasRelative = this.canvasRelative;
  48608. var top, left, height, width;
  48609. if (canvasRelative && em) {
  48610. var canvas = em.get('Canvas');
  48611. var pos = canvas.getElementPos(el, {
  48612. noScroll: 1
  48613. });
  48614. var elOffsets = canvas.getElementOffsets(el);
  48615. top = pos.top - elOffsets.marginTop;
  48616. left = pos.left - elOffsets.marginLeft;
  48617. height = pos.height + elOffsets.marginTop + elOffsets.marginBottom;
  48618. width = pos.width + elOffsets.marginLeft + elOffsets.marginRight;
  48619. } else {
  48620. var o = this.offset(el);
  48621. top = this.relative ? el.offsetTop : o.top - (this.wmargin ? -1 : 1) * this.elT;
  48622. left = this.relative ? el.offsetLeft : o.left - (this.wmargin ? -1 : 1) * this.elL;
  48623. height = el.offsetHeight;
  48624. width = el.offsetWidth;
  48625. }
  48626. return [top, left, height, width];
  48627. },
  48628. /**
  48629. * Get children dimensions
  48630. * @param {HTMLELement} el Element root
  48631. * @retun {Array}
  48632. * */
  48633. getChildrenDim: function getChildrenDim(trg) {
  48634. var _this2 = this;
  48635. var dims = [];
  48636. if (!trg) return dims; // Get children based on getChildrenContainer
  48637. var trgModel = this.getTargetModel(trg);
  48638. if (trgModel && trgModel.view && !this.ignoreViewChildren) {
  48639. var view = trgModel.getCurrentView ? trgModel.getCurrentView() : trgModel.view;
  48640. trg = view.getChildrenContainer();
  48641. }
  48642. Object(underscore__WEBPACK_IMPORTED_MODULE_2__["each"])(trg.children, function (el, i) {
  48643. var model = Object(utils_mixins__WEBPACK_IMPORTED_MODULE_3__["getModel"])(el, $);
  48644. var elIndex = model && model.index ? model.index() : i;
  48645. if (!Object(utils_mixins__WEBPACK_IMPORTED_MODULE_3__["isTextNode"])(el) && !_this2.matches(el, _this2.itemSel)) {
  48646. return;
  48647. }
  48648. var dim = _this2.getDim(el);
  48649. var dir = _this2.direction;
  48650. if (dir == 'v') dir = true;else if (dir == 'h') dir = false;else dir = _this2.isInFlow(el, trg);
  48651. dim.push(dir, el, elIndex);
  48652. dims.push(dim);
  48653. });
  48654. return dims;
  48655. },
  48656. /**
  48657. * Check if the coordinates are near to the borders
  48658. * @param {Array<number>} dim
  48659. * @param {number} rX Relative X position
  48660. * @param {number} rY Relative Y position
  48661. * @return {Boolean}
  48662. * */
  48663. nearBorders: function nearBorders(dim, rX, rY) {
  48664. var result = 0;
  48665. var off = this.borderOffset;
  48666. var x = rX || 0;
  48667. var y = rY || 0;
  48668. var t = dim[0];
  48669. var l = dim[1];
  48670. var h = dim[2];
  48671. var w = dim[3];
  48672. if (t + off > y || y > t + h - off || l + off > x || x > l + w - off) result = 1;
  48673. return !!result;
  48674. },
  48675. /**
  48676. * Find the position based on passed dimensions and coordinates
  48677. * @param {Array<Array>} dims Dimensions of nodes to parse
  48678. * @param {number} posX X coordindate
  48679. * @param {number} posY Y coordindate
  48680. * @retun {Object}
  48681. * */
  48682. findPosition: function findPosition(dims, posX, posY) {
  48683. var result = {
  48684. index: 0,
  48685. indexEl: 0,
  48686. method: 'before'
  48687. };
  48688. var leftLimit = 0,
  48689. xLimit = 0,
  48690. dimRight = 0,
  48691. yLimit = 0,
  48692. xCenter = 0,
  48693. yCenter = 0,
  48694. dimDown = 0,
  48695. dim = 0; // Each dim is: Top, Left, Height, Width
  48696. for (var i = 0, len = dims.length; i < len; i++) {
  48697. dim = dims[i]; // Right position of the element. Left + Width
  48698. dimRight = dim[1] + dim[3]; // Bottom position of the element. Top + Height
  48699. dimDown = dim[0] + dim[2]; // X center position of the element. Left + (Width / 2)
  48700. xCenter = dim[1] + dim[3] / 2; // Y center position of the element. Top + (Height / 2)
  48701. yCenter = dim[0] + dim[2] / 2; // Skip if over the limits
  48702. if (xLimit && dim[1] > xLimit || yLimit && yCenter >= yLimit || // >= avoid issue with clearfixes
  48703. leftLimit && dimRight < leftLimit) continue;
  48704. result.index = i;
  48705. result.indexEl = dim[6]; // If it's not in flow (like 'float' element)
  48706. if (!dim[4]) {
  48707. if (posY < dimDown) yLimit = dimDown; //If x lefter than center
  48708. if (posX < xCenter) {
  48709. xLimit = xCenter;
  48710. result.method = 'before';
  48711. } else {
  48712. leftLimit = xCenter;
  48713. result.method = 'after';
  48714. }
  48715. } else {
  48716. // If y upper than center
  48717. if (posY < yCenter) {
  48718. result.method = 'before';
  48719. break;
  48720. } else result.method = 'after'; // After last element
  48721. }
  48722. }
  48723. return result;
  48724. },
  48725. /**
  48726. * Updates the position of the placeholder
  48727. * @param {HTMLElement} phl
  48728. * @param {Array<Array>} dims
  48729. * @param {Object} pos Position object
  48730. * @param {Array<number>} trgDim target dimensions
  48731. * */
  48732. movePlaceholder: function movePlaceholder(plh, dims, pos, trgDim) {
  48733. var marg = 0,
  48734. t = 0,
  48735. l = 0,
  48736. w = 0,
  48737. h = 0,
  48738. un = 'px',
  48739. margI = 5,
  48740. method = pos.method;
  48741. var elDim = dims[pos.index]; // Placeholder orientation
  48742. plh.classList.remove('vertical');
  48743. plh.classList.add('horizontal');
  48744. if (elDim) {
  48745. // If it's not in flow (like 'float' element)
  48746. if (!elDim[4]) {
  48747. w = 'auto';
  48748. h = elDim[2] - marg * 2 + un;
  48749. t = elDim[0] + marg;
  48750. l = method == 'before' ? elDim[1] - marg : elDim[1] + elDim[3] - marg;
  48751. plh.classList.remove('horizontal');
  48752. plh.classList.add('vertical');
  48753. } else {
  48754. w = elDim[3] + un;
  48755. h = 'auto';
  48756. t = method == 'before' ? elDim[0] - marg : elDim[0] + elDim[2] - marg;
  48757. l = elDim[1];
  48758. }
  48759. } else {
  48760. if (!this.nested) {
  48761. plh.style.display = 'none';
  48762. return;
  48763. }
  48764. if (trgDim) {
  48765. t = trgDim[0] + margI;
  48766. l = trgDim[1] + margI;
  48767. w = parseInt(trgDim[3]) - margI * 2 + un;
  48768. h = 'auto';
  48769. }
  48770. }
  48771. plh.style.top = t + un;
  48772. plh.style.left = l + un;
  48773. if (w) plh.style.width = w;
  48774. if (h) plh.style.height = h;
  48775. },
  48776. /**
  48777. * Leave item
  48778. * @param event
  48779. *
  48780. * @return void
  48781. * */
  48782. endMove: function endMove(e) {
  48783. var _this3 = this;
  48784. var src = this.eV;
  48785. var moved = [];
  48786. var docs = this.getDocuments();
  48787. var container = this.getContainerEl();
  48788. var onEndMove = this.onEndMove;
  48789. var target = this.target,
  48790. lastPos = this.lastPos;
  48791. var srcModel;
  48792. Object(utils_mixins__WEBPACK_IMPORTED_MODULE_3__["off"])(container, 'mousemove dragover', this.onMove);
  48793. Object(utils_mixins__WEBPACK_IMPORTED_MODULE_3__["off"])(docs, 'mouseup dragend touchend', this.endMove);
  48794. Object(utils_mixins__WEBPACK_IMPORTED_MODULE_3__["off"])(docs, 'keydown', this.rollback);
  48795. this.plh.style.display = 'none';
  48796. if (src) {
  48797. srcModel = this.getSourceModel();
  48798. if (this.selectOnEnd && srcModel && srcModel.set) {
  48799. srcModel.set('status', '');
  48800. srcModel.set('status', 'selected');
  48801. }
  48802. }
  48803. if (this.moved) {
  48804. var toMove = this.toMove;
  48805. var toMoveArr = Object(underscore__WEBPACK_IMPORTED_MODULE_2__["isArray"])(toMove) ? toMove : toMove ? [toMove] : [src];
  48806. toMoveArr.forEach(function (model) {
  48807. moved.push(_this3.move(target, model, lastPos));
  48808. });
  48809. }
  48810. if (this.plh) this.plh.style.display = 'none';
  48811. var dragHelper = this.dragHelper;
  48812. if (dragHelper) {
  48813. dragHelper.parentNode.removeChild(dragHelper);
  48814. this.dragHelper = null;
  48815. }
  48816. this.disableTextable();
  48817. this.selectTargetModel();
  48818. this.toggleSortCursor();
  48819. this.toMove = null;
  48820. this.eventMove = 0;
  48821. this.dropModel = null;
  48822. if (Object(underscore__WEBPACK_IMPORTED_MODULE_2__["isFunction"])(onEndMove)) {
  48823. var data = {
  48824. target: srcModel,
  48825. parent: srcModel && srcModel.parent(),
  48826. index: srcModel && srcModel.index()
  48827. };
  48828. moved.length ? moved.forEach(function (m) {
  48829. return onEndMove(m, _this3, data);
  48830. }) : onEndMove(null, this, _objectSpread({}, data, {
  48831. cancelled: 1
  48832. }));
  48833. }
  48834. },
  48835. /**
  48836. * Move component to new position
  48837. * @param {HTMLElement} dst Destination target
  48838. * @param {HTMLElement} src Element to move
  48839. * @param {Object} pos Object with position coordinates
  48840. * */
  48841. move: function move(dst, src, pos) {
  48842. var em = this.em,
  48843. activeTextModel = this.activeTextModel,
  48844. dropContent = this.dropContent;
  48845. var srcEl = Object(utils_mixins__WEBPACK_IMPORTED_MODULE_3__["getElement"])(src);
  48846. em && em.trigger('component:dragEnd:before', dst, srcEl, pos); // @depricated
  48847. var warns = [];
  48848. var index = pos.indexEl;
  48849. var modelToDrop, modelTemp, created;
  48850. var validResult = this.validTarget(dst, srcEl);
  48851. var targetCollection = $(dst).data('collection');
  48852. var model = validResult.srcModel;
  48853. var droppable = validResult.droppable;
  48854. var draggable = validResult.draggable;
  48855. var dropInfo = validResult.dropInfo;
  48856. var dragInfo = validResult.dragInfo;
  48857. var trgModel = validResult.trgModel;
  48858. droppable = trgModel instanceof backbone__WEBPACK_IMPORTED_MODULE_1___default.a.Collection ? 1 : droppable;
  48859. var isTextableActive = this.isTextableActive(model, trgModel);
  48860. if (targetCollection && droppable && draggable) {
  48861. index = pos.method === 'after' ? index + 1 : index;
  48862. var opts = {
  48863. at: index,
  48864. noIncrement: 1
  48865. };
  48866. if (!dropContent) {
  48867. // Putting `avoidStore` here will make the UndoManager behave wrong
  48868. opts.temporary = 1;
  48869. modelTemp = targetCollection.add({}, _objectSpread({}, opts));
  48870. if (model.collection) {
  48871. modelToDrop = model.collection.remove(model, {
  48872. temporary: 1
  48873. });
  48874. }
  48875. } else {
  48876. modelToDrop = dropContent;
  48877. opts.silent = false;
  48878. opts.avoidUpdateStyle = 1;
  48879. }
  48880. if (isTextableActive) {
  48881. var viewActive = activeTextModel.getView();
  48882. activeTextModel.trigger('active');
  48883. var activeRte = viewActive.activeRte;
  48884. var modelEl = model.getEl();
  48885. delete model.opt.temporary;
  48886. model.getView().render();
  48887. modelEl.setAttribute('data-gjs-textable', 'true');
  48888. var outerHTML = modelEl.outerHTML;
  48889. activeRte.insertHTML && activeRte.insertHTML(outerHTML);
  48890. } else {
  48891. created = targetCollection.add(modelToDrop, opts);
  48892. }
  48893. if (!dropContent) {
  48894. targetCollection.remove(modelTemp);
  48895. } else {
  48896. this.dropContent = null;
  48897. } // This will cause to recalculate children dimensions
  48898. this.prevTarget = null;
  48899. } else {
  48900. if (!targetCollection) {
  48901. warns.push('Target collection not found');
  48902. }
  48903. if (!droppable) {
  48904. warns.push("Target is not droppable, accepts [".concat(dropInfo, "]"));
  48905. }
  48906. if (!draggable) {
  48907. warns.push("Component not draggable, acceptable by [".concat(dragInfo, "]"));
  48908. }
  48909. console.warn('Invalid target position: ' + warns.join(', '));
  48910. }
  48911. em && em.trigger('component:dragEnd', targetCollection, modelToDrop, warns); // @depricated
  48912. em && em.trigger('sorter:drag:end', {
  48913. targetCollection: targetCollection,
  48914. modelToDrop: modelToDrop,
  48915. warns: warns,
  48916. validResult: validResult,
  48917. dst: dst,
  48918. srcEl: srcEl
  48919. });
  48920. return created;
  48921. },
  48922. /**
  48923. * Rollback to previous situation
  48924. * @param {Event}
  48925. * @param {Bool} Indicates if rollback in anycase
  48926. * */
  48927. rollback: function rollback(e) {
  48928. Object(utils_mixins__WEBPACK_IMPORTED_MODULE_3__["off"])(this.getDocuments(), 'keydown', this.rollback);
  48929. var key = e.which || e.keyCode;
  48930. if (key == 27) {
  48931. this.moved = 0;
  48932. this.endMove();
  48933. }
  48934. }
  48935. }));
  48936. /***/ }),
  48937. /***/ "./src/utils/dom.js":
  48938. /*!**************************!*\
  48939. !*** ./src/utils/dom.js ***!
  48940. \**************************/
  48941. /*! exports provided: motionsEv, empty, replaceWith, appendAtIndex, append, createEl, createCustomEvent, appendVNodes */
  48942. /***/ (function(module, __webpack_exports__, __webpack_require__) {
  48943. "use strict";
  48944. __webpack_require__.r(__webpack_exports__);
  48945. /* harmony export (binding) */ __webpack_require__.d(__webpack_exports__, "motionsEv", function() { return motionsEv; });
  48946. /* harmony export (binding) */ __webpack_require__.d(__webpack_exports__, "empty", function() { return empty; });
  48947. /* harmony export (binding) */ __webpack_require__.d(__webpack_exports__, "replaceWith", function() { return replaceWith; });
  48948. /* harmony export (binding) */ __webpack_require__.d(__webpack_exports__, "appendAtIndex", function() { return appendAtIndex; });
  48949. /* harmony export (binding) */ __webpack_require__.d(__webpack_exports__, "append", function() { return append; });
  48950. /* harmony export (binding) */ __webpack_require__.d(__webpack_exports__, "createEl", function() { return createEl; });
  48951. /* harmony export (binding) */ __webpack_require__.d(__webpack_exports__, "createCustomEvent", function() { return createCustomEvent; });
  48952. /* harmony export (binding) */ __webpack_require__.d(__webpack_exports__, "appendVNodes", function() { return appendVNodes; });
  48953. /* harmony import */ var underscore__WEBPACK_IMPORTED_MODULE_0__ = __webpack_require__(/*! underscore */ "./node_modules/underscore/underscore.js");
  48954. /* harmony import */ var underscore__WEBPACK_IMPORTED_MODULE_0___default = /*#__PURE__*/__webpack_require__.n(underscore__WEBPACK_IMPORTED_MODULE_0__);
  48955. // DOM helpers
  48956. var KEY_TAG = 'tag';
  48957. var KEY_ATTR = 'attributes';
  48958. var KEY_CHILD = 'children';
  48959. var motionsEv = 'transitionend oTransitionEnd transitionend webkitTransitionEnd';
  48960. var empty = function empty(node) {
  48961. while (node.firstChild) {
  48962. node.removeChild(node.firstChild);
  48963. }
  48964. };
  48965. var replaceWith = function replaceWith(oldEl, newEl) {
  48966. oldEl.parentNode.replaceChild(newEl, oldEl);
  48967. };
  48968. var appendAtIndex = function appendAtIndex(parent, child, index) {
  48969. var childNodes = parent.childNodes;
  48970. var total = childNodes.length;
  48971. var at = Object(underscore__WEBPACK_IMPORTED_MODULE_0__["isUndefined"])(index) ? total : index;
  48972. if (Object(underscore__WEBPACK_IMPORTED_MODULE_0__["isString"])(child)) {
  48973. parent.insertAdjacentHTML('beforeEnd', child);
  48974. child = parent.lastChild;
  48975. parent.removeChild(child);
  48976. }
  48977. if (at >= total) {
  48978. parent.appendChild(child);
  48979. } else {
  48980. parent.insertBefore(child, childNodes[at]);
  48981. }
  48982. };
  48983. var append = function append(parent, child) {
  48984. return appendAtIndex(parent, child);
  48985. };
  48986. var createEl = function createEl(tag) {
  48987. var attrs = arguments.length > 1 && arguments[1] !== undefined ? arguments[1] : '';
  48988. var child = arguments.length > 2 ? arguments[2] : undefined;
  48989. var el = document.createElement(tag);
  48990. attrs && Object(underscore__WEBPACK_IMPORTED_MODULE_0__["each"])(attrs, function (value, key) {
  48991. return el.setAttribute(key, value);
  48992. });
  48993. if (child) {
  48994. if (Object(underscore__WEBPACK_IMPORTED_MODULE_0__["isString"])(child)) el.innerHTML = child;else el.appendChild(child);
  48995. }
  48996. return el;
  48997. }; // Unfortunately just creating `KeyboardEvent(e.type, e)` is not enough,
  48998. // the keyCode/which will be always `0`. Even if it's an old/deprecated
  48999. // property keymaster (and many others) still use it... using `defineProperty`
  49000. // hack seems the only way
  49001. var createCustomEvent = function createCustomEvent(e, cls) {
  49002. var oEvent;
  49003. try {
  49004. oEvent = new window[cls](e.type, e);
  49005. } catch (e) {
  49006. oEvent = document.createEvent(cls);
  49007. oEvent.initEvent(e.type, true, true);
  49008. }
  49009. oEvent.keyCodeVal = e.keyCode;
  49010. oEvent._parentEvent = e;
  49011. ['keyCode', 'which'].forEach(function (prop) {
  49012. Object.defineProperty(oEvent, prop, {
  49013. get: function get() {
  49014. return this.keyCodeVal;
  49015. }
  49016. });
  49017. });
  49018. return oEvent;
  49019. };
  49020. /**
  49021. * Append an array of vNodes to an element
  49022. * @param {HTMLElement} node HTML element
  49023. * @param {Array} vNodes Array of node objects
  49024. */
  49025. var appendVNodes = function appendVNodes(node) {
  49026. var vNodes = arguments.length > 1 && arguments[1] !== undefined ? arguments[1] : [];
  49027. var vNodesArr = Array.isArray(vNodes) ? vNodes : [vNodes];
  49028. vNodesArr.forEach(function (vnode) {
  49029. var tag = vnode[KEY_TAG] || 'div';
  49030. var attr = vnode[KEY_ATTR] || {};
  49031. var el = document.createElement(tag);
  49032. Object(underscore__WEBPACK_IMPORTED_MODULE_0__["each"])(attr, function (value, key) {
  49033. el.setAttribute(key, value);
  49034. });
  49035. node.appendChild(el);
  49036. });
  49037. };
  49038. /***/ }),
  49039. /***/ "./src/utils/extender.js":
  49040. /*!*******************************!*\
  49041. !*** ./src/utils/extender.js ***!
  49042. \*******************************/
  49043. /*! exports provided: default */
  49044. /***/ (function(module, __webpack_exports__, __webpack_require__) {
  49045. "use strict";
  49046. __webpack_require__.r(__webpack_exports__);
  49047. /* harmony import */ var underscore__WEBPACK_IMPORTED_MODULE_0__ = __webpack_require__(/*! underscore */ "./node_modules/underscore/underscore.js");
  49048. /* harmony import */ var underscore__WEBPACK_IMPORTED_MODULE_0___default = /*#__PURE__*/__webpack_require__.n(underscore__WEBPACK_IMPORTED_MODULE_0__);
  49049. /* harmony default export */ __webpack_exports__["default"] = (function (_ref) {
  49050. var $ = _ref.$;
  49051. if ($ && $.prototype.constructor.name !== 'jQuery') {
  49052. var fn = $.fn; // Additional helpers
  49053. fn.hide = function () {
  49054. return this.css('display', 'none');
  49055. };
  49056. fn.show = function () {
  49057. return this.css('display', 'block');
  49058. };
  49059. fn.focus = function () {
  49060. var el = this.get(0);
  49061. el && el.focus();
  49062. return this;
  49063. }; // For SVGs in IE
  49064. // (fn.removeClass = function(c) {
  49065. // if (!arguments.length) {
  49066. // return this.attr('class', '');
  49067. // }
  49068. // const classes = isString(c) && c.match(/\S+/g);
  49069. // return classes
  49070. // ? this.each(function(el) {
  49071. // each(classes, function(c) {
  49072. // if (el.classList) {
  49073. // el.classList.remove(c);
  49074. // } else {
  49075. // const val = el.className;
  49076. // const bval = el.className.baseVal;
  49077. // if (!isUndefined(bval)) {
  49078. // val.baseVal = bval.replace(c, '');
  49079. // } else {
  49080. // el.className = val.replace(c, '');
  49081. // }
  49082. // }
  49083. // });
  49084. // })
  49085. // : this;
  49086. // }),
  49087. // (fn.remove = function() {
  49088. // return this.each(node => {
  49089. // return node.parentNode && node.parentNode.removeChild(node);
  49090. // });
  49091. // }),
  49092. // For spectrum compatibility
  49093. fn.bind = function (ev, h) {
  49094. return this.on(ev, h);
  49095. };
  49096. fn.unbind = function (ev, h) {
  49097. if (Object(underscore__WEBPACK_IMPORTED_MODULE_0__["isObject"])(ev)) {
  49098. for (var name in ev) {
  49099. ev.hasOwnProperty(name) && this.off(name, ev[name]);
  49100. }
  49101. return this;
  49102. } else {
  49103. return this.off(ev, h);
  49104. }
  49105. };
  49106. fn.click = function (h) {
  49107. return h ? this.on('click', h) : this.trigger('click');
  49108. };
  49109. fn.change = function (h) {
  49110. return h ? this.on('change', h) : this.trigger('change');
  49111. };
  49112. fn.keydown = function (h) {
  49113. return h ? this.on('keydown', h) : this.trigger('keydown');
  49114. };
  49115. fn.delegate = function (selector, events, data, handler) {
  49116. if (!handler) {
  49117. handler = data;
  49118. }
  49119. return this.on(events, selector, function (e) {
  49120. e.data = data;
  49121. handler(e);
  49122. });
  49123. };
  49124. fn.scrollLeft = function () {
  49125. var el = this.get(0);
  49126. el = el.nodeType == 9 ? el.defaultView : el;
  49127. var win = el instanceof Window ? el : null;
  49128. return win ? win.pageXOffset : el.scrollLeft || 0;
  49129. };
  49130. fn.scrollTop = function () {
  49131. var el = this.get(0);
  49132. el = el.nodeType == 9 ? el.defaultView : el;
  49133. var win = el instanceof Window ? el : null;
  49134. return win ? win.pageYOffset : el.scrollTop || 0;
  49135. };
  49136. var offset = $.prototype.offset;
  49137. fn.offset = function (coords) {
  49138. var top, left;
  49139. if (coords) {
  49140. top = coords.top;
  49141. left = coords.left;
  49142. }
  49143. if (typeof top != 'undefined') {
  49144. this.css('top', "".concat(top, "px"));
  49145. }
  49146. if (typeof left != 'undefined') {
  49147. this.css('left', "".concat(left, "px"));
  49148. }
  49149. return offset.call(this);
  49150. };
  49151. $.map = function (items, clb) {
  49152. var ar = [];
  49153. for (var i = 0; i < items.length; i++) {
  49154. ar.push(clb(items[i], i));
  49155. }
  49156. return ar;
  49157. };
  49158. var indexOf = Array.prototype.indexOf;
  49159. $.inArray = function (val, arr, i) {
  49160. return arr == null ? -1 : indexOf.call(arr, val, i);
  49161. };
  49162. $.Event = function (src, props) {
  49163. if (!(this instanceof $.Event)) {
  49164. return new $.Event(src, props);
  49165. }
  49166. this.type = src;
  49167. this.isDefaultPrevented = function () {
  49168. return false;
  49169. };
  49170. };
  49171. }
  49172. });
  49173. /***/ }),
  49174. /***/ "./src/utils/fetch.js":
  49175. /*!****************************!*\
  49176. !*** ./src/utils/fetch.js ***!
  49177. \****************************/
  49178. /*! exports provided: default */
  49179. /***/ (function(module, __webpack_exports__, __webpack_require__) {
  49180. "use strict";
  49181. __webpack_require__.r(__webpack_exports__);
  49182. /* harmony import */ var promise_polyfill__WEBPACK_IMPORTED_MODULE_0__ = __webpack_require__(/*! promise-polyfill */ "./node_modules/promise-polyfill/src/index.js");
  49183. window.Promise = window.Promise || promise_polyfill__WEBPACK_IMPORTED_MODULE_0__["default"];
  49184. /* harmony default export */ __webpack_exports__["default"] = (typeof fetch == 'function' ? fetch.bind() : function (url, options) {
  49185. return new promise_polyfill__WEBPACK_IMPORTED_MODULE_0__["default"](function (res, rej) {
  49186. var req = new XMLHttpRequest();
  49187. req.open(options.method || 'get', url);
  49188. req.withCredentials = options.credentials == 'include';
  49189. for (var k in options.headers || {}) {
  49190. req.setRequestHeader(k, options.headers[k]);
  49191. }
  49192. req.onload = function (e) {
  49193. return res({
  49194. status: req.status,
  49195. statusText: req.statusText,
  49196. text: function text() {
  49197. return promise_polyfill__WEBPACK_IMPORTED_MODULE_0__["default"].resolve(req.responseText);
  49198. }
  49199. });
  49200. };
  49201. req.onerror = rej; // Actually, fetch doesn't support onProgress feature
  49202. if (req.upload && options.onProgress) {
  49203. req.upload.onprogress = options.onProgress;
  49204. } // Include body only if present
  49205. options.body ? req.send(options.body) : req.send();
  49206. });
  49207. });
  49208. /***/ }),
  49209. /***/ "./src/utils/index.js":
  49210. /*!****************************!*\
  49211. !*** ./src/utils/index.js ***!
  49212. \****************************/
  49213. /*! exports provided: default */
  49214. /***/ (function(module, __webpack_exports__, __webpack_require__) {
  49215. "use strict";
  49216. __webpack_require__.r(__webpack_exports__);
  49217. /* harmony import */ var _Dragger__WEBPACK_IMPORTED_MODULE_0__ = __webpack_require__(/*! ./Dragger */ "./src/utils/Dragger.js");
  49218. /* harmony import */ var _Sorter__WEBPACK_IMPORTED_MODULE_1__ = __webpack_require__(/*! ./Sorter */ "./src/utils/Sorter.js");
  49219. /* harmony import */ var _Resizer__WEBPACK_IMPORTED_MODULE_2__ = __webpack_require__(/*! ./Resizer */ "./src/utils/Resizer.js");
  49220. /* harmony default export */ __webpack_exports__["default"] = (function () {
  49221. return {
  49222. /**
  49223. * Name of the module
  49224. * @type {String}
  49225. * @private
  49226. */
  49227. name: 'Utils',
  49228. /**
  49229. * Initialize module
  49230. */
  49231. init: function init() {
  49232. return this;
  49233. },
  49234. Sorter: _Sorter__WEBPACK_IMPORTED_MODULE_1__["default"],
  49235. Resizer: _Resizer__WEBPACK_IMPORTED_MODULE_2__["default"],
  49236. Dragger: _Dragger__WEBPACK_IMPORTED_MODULE_0__["default"]
  49237. };
  49238. });
  49239. /***/ }),
  49240. /***/ "./src/utils/mixins.js":
  49241. /*!*****************************!*\
  49242. !*** ./src/utils/mixins.js ***!
  49243. \*****************************/
  49244. /*! exports provided: isCommentNode, isTaggableNode, on, off, hasDnd, upFirst, matches, getModel, getElRect, camelCase, isTextNode, getKeyCode, getKeyChar, isEscKey, getElement, shallowDiff, normalizeFloat, getPointerEvent, getUnitFromValue, capitalize, getViewEl, setViewEl, appendStyles, isComponent, isRule */
  49245. /***/ (function(module, __webpack_exports__, __webpack_require__) {
  49246. "use strict";
  49247. __webpack_require__.r(__webpack_exports__);
  49248. /* harmony export (binding) */ __webpack_require__.d(__webpack_exports__, "isCommentNode", function() { return isCommentNode; });
  49249. /* harmony export (binding) */ __webpack_require__.d(__webpack_exports__, "isTaggableNode", function() { return isTaggableNode; });
  49250. /* harmony export (binding) */ __webpack_require__.d(__webpack_exports__, "on", function() { return on; });
  49251. /* harmony export (binding) */ __webpack_require__.d(__webpack_exports__, "off", function() { return off; });
  49252. /* harmony export (binding) */ __webpack_require__.d(__webpack_exports__, "hasDnd", function() { return hasDnd; });
  49253. /* harmony export (binding) */ __webpack_require__.d(__webpack_exports__, "upFirst", function() { return upFirst; });
  49254. /* harmony export (binding) */ __webpack_require__.d(__webpack_exports__, "matches", function() { return matches; });
  49255. /* harmony export (binding) */ __webpack_require__.d(__webpack_exports__, "getModel", function() { return getModel; });
  49256. /* harmony export (binding) */ __webpack_require__.d(__webpack_exports__, "getElRect", function() { return getElRect; });
  49257. /* harmony export (binding) */ __webpack_require__.d(__webpack_exports__, "camelCase", function() { return camelCase; });
  49258. /* harmony export (binding) */ __webpack_require__.d(__webpack_exports__, "isTextNode", function() { return isTextNode; });
  49259. /* harmony export (binding) */ __webpack_require__.d(__webpack_exports__, "getKeyCode", function() { return getKeyCode; });
  49260. /* harmony export (binding) */ __webpack_require__.d(__webpack_exports__, "getKeyChar", function() { return getKeyChar; });
  49261. /* harmony export (binding) */ __webpack_require__.d(__webpack_exports__, "isEscKey", function() { return isEscKey; });
  49262. /* harmony export (binding) */ __webpack_require__.d(__webpack_exports__, "getElement", function() { return getElement; });
  49263. /* harmony export (binding) */ __webpack_require__.d(__webpack_exports__, "shallowDiff", function() { return shallowDiff; });
  49264. /* harmony export (binding) */ __webpack_require__.d(__webpack_exports__, "normalizeFloat", function() { return normalizeFloat; });
  49265. /* harmony export (binding) */ __webpack_require__.d(__webpack_exports__, "getPointerEvent", function() { return getPointerEvent; });
  49266. /* harmony export (binding) */ __webpack_require__.d(__webpack_exports__, "getUnitFromValue", function() { return getUnitFromValue; });
  49267. /* harmony export (binding) */ __webpack_require__.d(__webpack_exports__, "capitalize", function() { return capitalize; });
  49268. /* harmony export (binding) */ __webpack_require__.d(__webpack_exports__, "getViewEl", function() { return getViewEl; });
  49269. /* harmony export (binding) */ __webpack_require__.d(__webpack_exports__, "setViewEl", function() { return setViewEl; });
  49270. /* harmony export (binding) */ __webpack_require__.d(__webpack_exports__, "appendStyles", function() { return appendStyles; });
  49271. /* harmony export (binding) */ __webpack_require__.d(__webpack_exports__, "isComponent", function() { return isComponent; });
  49272. /* harmony export (binding) */ __webpack_require__.d(__webpack_exports__, "isRule", function() { return isRule; });
  49273. /* harmony import */ var _babel_runtime_helpers_toConsumableArray__WEBPACK_IMPORTED_MODULE_0__ = __webpack_require__(/*! @babel/runtime/helpers/toConsumableArray */ "./node_modules/@babel/runtime/helpers/toConsumableArray.js");
  49274. /* harmony import */ var _babel_runtime_helpers_toConsumableArray__WEBPACK_IMPORTED_MODULE_0___default = /*#__PURE__*/__webpack_require__.n(_babel_runtime_helpers_toConsumableArray__WEBPACK_IMPORTED_MODULE_0__);
  49275. /* harmony import */ var underscore__WEBPACK_IMPORTED_MODULE_1__ = __webpack_require__(/*! underscore */ "./node_modules/underscore/underscore.js");
  49276. /* harmony import */ var underscore__WEBPACK_IMPORTED_MODULE_1___default = /*#__PURE__*/__webpack_require__.n(underscore__WEBPACK_IMPORTED_MODULE_1__);
  49277. var elProt = window.Element.prototype;
  49278. var matches = elProt.matches || elProt.webkitMatchesSelector || elProt.mozMatchesSelector || elProt.msMatchesSelector;
  49279. /**
  49280. * Import styles asynchronously
  49281. * @param {String|Array<String>} styles
  49282. */
  49283. var appendStyles = function appendStyles(styles) {
  49284. var opts = arguments.length > 1 && arguments[1] !== undefined ? arguments[1] : {};
  49285. var stls = Object(underscore__WEBPACK_IMPORTED_MODULE_1__["isArray"])(styles) ? _babel_runtime_helpers_toConsumableArray__WEBPACK_IMPORTED_MODULE_0___default()(styles) : [styles];
  49286. if (stls.length) {
  49287. var href = stls.shift();
  49288. if (href && (!opts.unique || !document.querySelector("link[href=\"".concat(href, "\"]")))) {
  49289. var _document = document,
  49290. head = _document.head;
  49291. var link = document.createElement('link');
  49292. link.href = href;
  49293. link.rel = 'stylesheet';
  49294. if (opts.prepand) {
  49295. head.insertBefore(link, head.firstChild);
  49296. } else {
  49297. head.appendChild(link);
  49298. }
  49299. }
  49300. appendStyles(stls);
  49301. }
  49302. };
  49303. /**
  49304. * Returns shallow diff between 2 objects
  49305. * @param {Object} objOrig
  49306. * @param {Objec} objNew
  49307. * @return {Object}
  49308. * @example
  49309. * var a = {foo: 'bar', baz: 1, faz: 'sop'};
  49310. * var b = {foo: 'bar', baz: 2, bar: ''};
  49311. * shallowDiff(a, b);
  49312. * // -> {baz: 2, faz: null, bar: ''};
  49313. */
  49314. var shallowDiff = function shallowDiff(objOrig, objNew) {
  49315. var result = {};
  49316. var keysNew = Object(underscore__WEBPACK_IMPORTED_MODULE_1__["keys"])(objNew);
  49317. for (var prop in objOrig) {
  49318. if (objOrig.hasOwnProperty(prop)) {
  49319. var origValue = objOrig[prop];
  49320. var newValue = objNew[prop];
  49321. if (keysNew.indexOf(prop) >= 0) {
  49322. if (origValue !== newValue) {
  49323. result[prop] = newValue;
  49324. }
  49325. } else {
  49326. result[prop] = null;
  49327. }
  49328. }
  49329. }
  49330. for (var _prop in objNew) {
  49331. if (objNew.hasOwnProperty(_prop)) {
  49332. if (Object(underscore__WEBPACK_IMPORTED_MODULE_1__["isUndefined"])(objOrig[_prop])) {
  49333. result[_prop] = objNew[_prop];
  49334. }
  49335. }
  49336. }
  49337. return result;
  49338. };
  49339. var on = function on(el, ev, fn) {
  49340. ev = ev.split(/\s+/);
  49341. el = el instanceof Array ? el : [el];
  49342. var _loop = function _loop(i) {
  49343. el.forEach(function (elem) {
  49344. return elem.addEventListener(ev[i], fn);
  49345. });
  49346. };
  49347. for (var i = 0; i < ev.length; ++i) {
  49348. _loop(i);
  49349. }
  49350. };
  49351. var off = function off(el, ev, fn) {
  49352. ev = ev.split(/\s+/);
  49353. el = el instanceof Array ? el : [el];
  49354. var _loop2 = function _loop2(i) {
  49355. el.forEach(function (elem) {
  49356. return elem.removeEventListener(ev[i], fn);
  49357. });
  49358. };
  49359. for (var i = 0; i < ev.length; ++i) {
  49360. _loop2(i);
  49361. }
  49362. };
  49363. var getUnitFromValue = function getUnitFromValue(value) {
  49364. return value.replace(parseFloat(value), '');
  49365. };
  49366. var upFirst = function upFirst(value) {
  49367. return value[0].toUpperCase() + value.toLowerCase().slice(1);
  49368. };
  49369. var camelCase = function camelCase(value) {
  49370. var values = value.split('-').filter(String);
  49371. return values[0].toLowerCase() + values.slice(1).map(upFirst);
  49372. };
  49373. var normalizeFloat = function normalizeFloat(value) {
  49374. var step = arguments.length > 1 && arguments[1] !== undefined ? arguments[1] : 1;
  49375. var valueDef = arguments.length > 2 && arguments[2] !== undefined ? arguments[2] : 0;
  49376. var stepDecimals = 0;
  49377. if (isNaN(value)) return valueDef;
  49378. value = parseFloat(value);
  49379. if (Math.floor(value) !== value) {
  49380. var side = step.toString().split('.')[1];
  49381. stepDecimals = side ? side.length : 0;
  49382. }
  49383. return stepDecimals ? parseFloat(value.toFixed(stepDecimals)) : value;
  49384. };
  49385. var hasDnd = function hasDnd(em) {
  49386. return 'draggable' in document.createElement('i') && (em ? em.get('Config').nativeDnD : 1);
  49387. };
  49388. /**
  49389. * Ensure to fetch the element from the input argument
  49390. * @param {HTMLElement|Component} el Component or HTML element
  49391. * @return {HTMLElement}
  49392. */
  49393. var getElement = function getElement(el) {
  49394. if (Object(underscore__WEBPACK_IMPORTED_MODULE_1__["isElement"])(el) || isTextNode(el)) {
  49395. return el;
  49396. } else if (el && el.getEl) {
  49397. return el.getEl();
  49398. }
  49399. };
  49400. /**
  49401. * Check if element is a text node
  49402. * @param {HTMLElement} el
  49403. * @return {Boolean}
  49404. */
  49405. var isTextNode = function isTextNode(el) {
  49406. return el && el.nodeType === 3;
  49407. };
  49408. /**
  49409. * Check if element is a comment node
  49410. * @param {HTMLElement} el
  49411. * @return {Boolean}
  49412. */
  49413. var isCommentNode = function isCommentNode(el) {
  49414. return el && el.nodeType === 8;
  49415. };
  49416. /**
  49417. * Check if element is a comment node
  49418. * @param {HTMLElement} el
  49419. * @return {Boolean}
  49420. */
  49421. var isTaggableNode = function isTaggableNode(el) {
  49422. return el && !isTextNode(el) && !isCommentNode(el);
  49423. };
  49424. /**
  49425. * Ensure to fetch the model from the input argument
  49426. * @param {HTMLElement|Component} el Component or HTML element
  49427. * @return {Component}
  49428. */
  49429. var getModel = function getModel(el, $) {
  49430. var model = el;
  49431. Object(underscore__WEBPACK_IMPORTED_MODULE_1__["isElement"])(el) && (model = $(el).data('model'));
  49432. return model;
  49433. };
  49434. var getElRect = function getElRect(el) {
  49435. var def = {
  49436. top: 0,
  49437. left: 0,
  49438. width: 0,
  49439. height: 0
  49440. };
  49441. if (!el) return def;
  49442. var rectText;
  49443. if (isTextNode(el)) {
  49444. var range = document.createRange();
  49445. range.selectNode(el);
  49446. rectText = range.getBoundingClientRect();
  49447. range.detach();
  49448. }
  49449. return rectText || (el.getBoundingClientRect ? el.getBoundingClientRect() : def);
  49450. };
  49451. /**
  49452. * Get cross-device pointer event
  49453. * @param {Event} ev
  49454. * @return {Event}
  49455. */
  49456. var getPointerEvent = function getPointerEvent(ev) {
  49457. return ev.touches && ev.touches[0] ? ev.touches[0] : ev;
  49458. };
  49459. /**
  49460. * Get cross-browser keycode
  49461. * @param {Event} ev
  49462. * @return {Number}
  49463. */
  49464. var getKeyCode = function getKeyCode(ev) {
  49465. return ev.which || ev.keyCode;
  49466. };
  49467. var getKeyChar = function getKeyChar(ev) {
  49468. return String.fromCharCode(getKeyCode(ev));
  49469. };
  49470. var isEscKey = function isEscKey(ev) {
  49471. return getKeyCode(ev) === 27;
  49472. };
  49473. var capitalize = function capitalize(str) {
  49474. return str && str.charAt(0).toUpperCase() + str.substring(1);
  49475. };
  49476. var isComponent = function isComponent(obj) {
  49477. return obj && obj.toHTML;
  49478. };
  49479. var isRule = function isRule(obj) {
  49480. return obj && obj.toCSS;
  49481. };
  49482. var getViewEl = function getViewEl(el) {
  49483. return el.__gjsv;
  49484. };
  49485. var setViewEl = function setViewEl(el, view) {
  49486. el.__gjsv = view;
  49487. };
  49488. /***/ }),
  49489. /***/ "./src/utils/polyfills.js":
  49490. /*!********************************!*\
  49491. !*** ./src/utils/polyfills.js ***!
  49492. \********************************/
  49493. /*! exports provided: default */
  49494. /***/ (function(module, __webpack_exports__, __webpack_require__) {
  49495. "use strict";
  49496. __webpack_require__.r(__webpack_exports__);
  49497. /**
  49498. * File made for IE/Edge support
  49499. * https://github.com/artf/grapesjs/issues/214
  49500. */
  49501. /* harmony default export */ __webpack_exports__["default"] = (function () {
  49502. /**
  49503. * Check if IE/Edge
  49504. * @return {Boolean}
  49505. */
  49506. var isIE = function isIE() {
  49507. var match;
  49508. var agent = window.navigator.userAgent;
  49509. var rules = [['edge', /Edge\/([0-9\._]+)/], ['ie', /MSIE\s(7\.0)/], ['ie', /MSIE\s([0-9\.]+);.*Trident\/[4-7].0/], ['ie', /Trident\/7\.0.*rv\:([0-9\.]+).*\).*Gecko$/]];
  49510. for (var i = 0; i < rules.length; i++) {
  49511. var rule = rules[i];
  49512. match = rule[1].exec(agent);
  49513. if (match) break;
  49514. }
  49515. return !!match;
  49516. };
  49517. if (isIE()) {
  49518. var originalCreateHTMLDocument = DOMImplementation.prototype.createHTMLDocument;
  49519. DOMImplementation.prototype.createHTMLDocument = function (title) {
  49520. if (!title) title = '';
  49521. return originalCreateHTMLDocument.apply(document.implementation, [title]);
  49522. };
  49523. }
  49524. });
  49525. /***/ })
  49526. /******/ })["default"];
  49527. });