Dialogs.js 371 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474475476477478479480481482483484485486487488489490491492493494495496497498499500501502503504505506507508509510511512513514515516517518519520521522523524525526527528529530531532533534535536537538539540541542543544545546547548549550551552553554555556557558559560561562563564565566567568569570571572573574575576577578579580581582583584585586587588589590591592593594595596597598599600601602603604605606607608609610611612613614615616617618619620621622623624625626627628629630631632633634635636637638639640641642643644645646647648649650651652653654655656657658659660661662663664665666667668669670671672673674675676677678679680681682683684685686687688689690691692693694695696697698699700701702703704705706707708709710711712713714715716717718719720721722723724725726727728729730731732733734735736737738739740741742743744745746747748749750751752753754755756757758759760761762763764765766767768769770771772773774775776777778779780781782783784785786787788789790791792793794795796797798799800801802803804805806807808809810811812813814815816817818819820821822823824825826827828829830831832833834835836837838839840841842843844845846847848849850851852853854855856857858859860861862863864865866867868869870871872873874875876877878879880881882883884885886887888889890891892893894895896897898899900901902903904905906907908909910911912913914915916917918919920921922923924925926927928929930931932933934935936937938939940941942943944945946947948949950951952953954955956957958959960961962963964965966967968969970971972973974975976977978979980981982983984985986987988989990991992993994995996997998999100010011002100310041005100610071008100910101011101210131014101510161017101810191020102110221023102410251026102710281029103010311032103310341035103610371038103910401041104210431044104510461047104810491050105110521053105410551056105710581059106010611062106310641065106610671068106910701071107210731074107510761077107810791080108110821083108410851086108710881089109010911092109310941095109610971098109911001101110211031104110511061107110811091110111111121113111411151116111711181119112011211122112311241125112611271128112911301131113211331134113511361137113811391140114111421143114411451146114711481149115011511152115311541155115611571158115911601161116211631164116511661167116811691170117111721173117411751176117711781179118011811182118311841185118611871188118911901191119211931194119511961197119811991200120112021203120412051206120712081209121012111212121312141215121612171218121912201221122212231224122512261227122812291230123112321233123412351236123712381239124012411242124312441245124612471248124912501251125212531254125512561257125812591260126112621263126412651266126712681269127012711272127312741275127612771278127912801281128212831284128512861287128812891290129112921293129412951296129712981299130013011302130313041305130613071308130913101311131213131314131513161317131813191320132113221323132413251326132713281329133013311332133313341335133613371338133913401341134213431344134513461347134813491350135113521353135413551356135713581359136013611362136313641365136613671368136913701371137213731374137513761377137813791380138113821383138413851386138713881389139013911392139313941395139613971398139914001401140214031404140514061407140814091410141114121413141414151416141714181419142014211422142314241425142614271428142914301431143214331434143514361437143814391440144114421443144414451446144714481449145014511452145314541455145614571458145914601461146214631464146514661467146814691470147114721473147414751476147714781479148014811482148314841485148614871488148914901491149214931494149514961497149814991500150115021503150415051506150715081509151015111512151315141515151615171518151915201521152215231524152515261527152815291530153115321533153415351536153715381539154015411542154315441545154615471548154915501551155215531554155515561557155815591560156115621563156415651566156715681569157015711572157315741575157615771578157915801581158215831584158515861587158815891590159115921593159415951596159715981599160016011602160316041605160616071608160916101611161216131614161516161617161816191620162116221623162416251626162716281629163016311632163316341635163616371638163916401641164216431644164516461647164816491650165116521653165416551656165716581659166016611662166316641665166616671668166916701671167216731674167516761677167816791680168116821683168416851686168716881689169016911692169316941695169616971698169917001701170217031704170517061707170817091710171117121713171417151716171717181719172017211722172317241725172617271728172917301731173217331734173517361737173817391740174117421743174417451746174717481749175017511752175317541755175617571758175917601761176217631764176517661767176817691770177117721773177417751776177717781779178017811782178317841785178617871788178917901791179217931794179517961797179817991800180118021803180418051806180718081809181018111812181318141815181618171818181918201821182218231824182518261827182818291830183118321833183418351836183718381839184018411842184318441845184618471848184918501851185218531854185518561857185818591860186118621863186418651866186718681869187018711872187318741875187618771878187918801881188218831884188518861887188818891890189118921893189418951896189718981899190019011902190319041905190619071908190919101911191219131914191519161917191819191920192119221923192419251926192719281929193019311932193319341935193619371938193919401941194219431944194519461947194819491950195119521953195419551956195719581959196019611962196319641965196619671968196919701971197219731974197519761977197819791980198119821983198419851986198719881989199019911992199319941995199619971998199920002001200220032004200520062007200820092010201120122013201420152016201720182019202020212022202320242025202620272028202920302031203220332034203520362037203820392040204120422043204420452046204720482049205020512052205320542055205620572058205920602061206220632064206520662067206820692070207120722073207420752076207720782079208020812082208320842085208620872088208920902091209220932094209520962097209820992100210121022103210421052106210721082109211021112112211321142115211621172118211921202121212221232124212521262127212821292130213121322133213421352136213721382139214021412142214321442145214621472148214921502151215221532154215521562157215821592160216121622163216421652166216721682169217021712172217321742175217621772178217921802181218221832184218521862187218821892190219121922193219421952196219721982199220022012202220322042205220622072208220922102211221222132214221522162217221822192220222122222223222422252226222722282229223022312232223322342235223622372238223922402241224222432244224522462247224822492250225122522253225422552256225722582259226022612262226322642265226622672268226922702271227222732274227522762277227822792280228122822283228422852286228722882289229022912292229322942295229622972298229923002301230223032304230523062307230823092310231123122313231423152316231723182319232023212322232323242325232623272328232923302331233223332334233523362337233823392340234123422343234423452346234723482349235023512352235323542355235623572358235923602361236223632364236523662367236823692370237123722373237423752376237723782379238023812382238323842385238623872388238923902391239223932394239523962397239823992400240124022403240424052406240724082409241024112412241324142415241624172418241924202421242224232424242524262427242824292430243124322433243424352436243724382439244024412442244324442445244624472448244924502451245224532454245524562457245824592460246124622463246424652466246724682469247024712472247324742475247624772478247924802481248224832484248524862487248824892490249124922493249424952496249724982499250025012502250325042505250625072508250925102511251225132514251525162517251825192520252125222523252425252526252725282529253025312532253325342535253625372538253925402541254225432544254525462547254825492550255125522553255425552556255725582559256025612562256325642565256625672568256925702571257225732574257525762577257825792580258125822583258425852586258725882589259025912592259325942595259625972598259926002601260226032604260526062607260826092610261126122613261426152616261726182619262026212622262326242625262626272628262926302631263226332634263526362637263826392640264126422643264426452646264726482649265026512652265326542655265626572658265926602661266226632664266526662667266826692670267126722673267426752676267726782679268026812682268326842685268626872688268926902691269226932694269526962697269826992700270127022703270427052706270727082709271027112712271327142715271627172718271927202721272227232724272527262727272827292730273127322733273427352736273727382739274027412742274327442745274627472748274927502751275227532754275527562757275827592760276127622763276427652766276727682769277027712772277327742775277627772778277927802781278227832784278527862787278827892790279127922793279427952796279727982799280028012802280328042805280628072808280928102811281228132814281528162817281828192820282128222823282428252826282728282829283028312832283328342835283628372838283928402841284228432844284528462847284828492850285128522853285428552856285728582859286028612862286328642865286628672868286928702871287228732874287528762877287828792880288128822883288428852886288728882889289028912892289328942895289628972898289929002901290229032904290529062907290829092910291129122913291429152916291729182919292029212922292329242925292629272928292929302931293229332934293529362937293829392940294129422943294429452946294729482949295029512952295329542955295629572958295929602961296229632964296529662967296829692970297129722973297429752976297729782979298029812982298329842985298629872988298929902991299229932994299529962997299829993000300130023003300430053006300730083009301030113012301330143015301630173018301930203021302230233024302530263027302830293030303130323033303430353036303730383039304030413042304330443045304630473048304930503051305230533054305530563057305830593060306130623063306430653066306730683069307030713072307330743075307630773078307930803081308230833084308530863087308830893090309130923093309430953096309730983099310031013102310331043105310631073108310931103111311231133114311531163117311831193120312131223123312431253126312731283129313031313132313331343135313631373138313931403141314231433144314531463147314831493150315131523153315431553156315731583159316031613162316331643165316631673168316931703171317231733174317531763177317831793180318131823183318431853186318731883189319031913192319331943195319631973198319932003201320232033204320532063207320832093210321132123213321432153216321732183219322032213222322332243225322632273228322932303231323232333234323532363237323832393240324132423243324432453246324732483249325032513252325332543255325632573258325932603261326232633264326532663267326832693270327132723273327432753276327732783279328032813282328332843285328632873288328932903291329232933294329532963297329832993300330133023303330433053306330733083309331033113312331333143315331633173318331933203321332233233324332533263327332833293330333133323333333433353336333733383339334033413342334333443345334633473348334933503351335233533354335533563357335833593360336133623363336433653366336733683369337033713372337333743375337633773378337933803381338233833384338533863387338833893390339133923393339433953396339733983399340034013402340334043405340634073408340934103411341234133414341534163417341834193420342134223423342434253426342734283429343034313432343334343435343634373438343934403441344234433444344534463447344834493450345134523453345434553456345734583459346034613462346334643465346634673468346934703471347234733474347534763477347834793480348134823483348434853486348734883489349034913492349334943495349634973498349935003501350235033504350535063507350835093510351135123513351435153516351735183519352035213522352335243525352635273528352935303531353235333534353535363537353835393540354135423543354435453546354735483549355035513552355335543555355635573558355935603561356235633564356535663567356835693570357135723573357435753576357735783579358035813582358335843585358635873588358935903591359235933594359535963597359835993600360136023603360436053606360736083609361036113612361336143615361636173618361936203621362236233624362536263627362836293630363136323633363436353636363736383639364036413642364336443645364636473648364936503651365236533654365536563657365836593660366136623663366436653666366736683669367036713672367336743675367636773678367936803681368236833684368536863687368836893690369136923693369436953696369736983699370037013702370337043705370637073708370937103711371237133714371537163717371837193720372137223723372437253726372737283729373037313732373337343735373637373738373937403741374237433744374537463747374837493750375137523753375437553756375737583759376037613762376337643765376637673768376937703771377237733774377537763777377837793780378137823783378437853786378737883789379037913792379337943795379637973798379938003801380238033804380538063807380838093810381138123813381438153816381738183819382038213822382338243825382638273828382938303831383238333834383538363837383838393840384138423843384438453846384738483849385038513852385338543855385638573858385938603861386238633864386538663867386838693870387138723873387438753876387738783879388038813882388338843885388638873888388938903891389238933894389538963897389838993900390139023903390439053906390739083909391039113912391339143915391639173918391939203921392239233924392539263927392839293930393139323933393439353936393739383939394039413942394339443945394639473948394939503951395239533954395539563957395839593960396139623963396439653966396739683969397039713972397339743975397639773978397939803981398239833984398539863987398839893990399139923993399439953996399739983999400040014002400340044005400640074008400940104011401240134014401540164017401840194020402140224023402440254026402740284029403040314032403340344035403640374038403940404041404240434044404540464047404840494050405140524053405440554056405740584059406040614062406340644065406640674068406940704071407240734074407540764077407840794080408140824083408440854086408740884089409040914092409340944095409640974098409941004101410241034104410541064107410841094110411141124113411441154116411741184119412041214122412341244125412641274128412941304131413241334134413541364137413841394140414141424143414441454146414741484149415041514152415341544155415641574158415941604161416241634164416541664167416841694170417141724173417441754176417741784179418041814182418341844185418641874188418941904191419241934194419541964197419841994200420142024203420442054206420742084209421042114212421342144215421642174218421942204221422242234224422542264227422842294230423142324233423442354236423742384239424042414242424342444245424642474248424942504251425242534254425542564257425842594260426142624263426442654266426742684269427042714272427342744275427642774278427942804281428242834284428542864287428842894290429142924293429442954296429742984299430043014302430343044305430643074308430943104311431243134314431543164317431843194320432143224323432443254326432743284329433043314332433343344335433643374338433943404341434243434344434543464347434843494350435143524353435443554356435743584359436043614362436343644365436643674368436943704371437243734374437543764377437843794380438143824383438443854386438743884389439043914392439343944395439643974398439944004401440244034404440544064407440844094410441144124413441444154416441744184419442044214422442344244425442644274428442944304431443244334434443544364437443844394440444144424443444444454446444744484449445044514452445344544455445644574458445944604461446244634464446544664467446844694470447144724473447444754476447744784479448044814482448344844485448644874488448944904491449244934494449544964497449844994500450145024503450445054506450745084509451045114512451345144515451645174518451945204521452245234524452545264527452845294530453145324533453445354536453745384539454045414542454345444545454645474548454945504551455245534554455545564557455845594560456145624563456445654566456745684569457045714572457345744575457645774578457945804581458245834584458545864587458845894590459145924593459445954596459745984599460046014602460346044605460646074608460946104611461246134614461546164617461846194620462146224623462446254626462746284629463046314632463346344635463646374638463946404641464246434644464546464647464846494650465146524653465446554656465746584659466046614662466346644665466646674668466946704671467246734674467546764677467846794680468146824683468446854686468746884689469046914692469346944695469646974698469947004701470247034704470547064707470847094710471147124713471447154716471747184719472047214722472347244725472647274728472947304731473247334734473547364737473847394740474147424743474447454746474747484749475047514752475347544755475647574758475947604761476247634764476547664767476847694770477147724773477447754776477747784779478047814782478347844785478647874788478947904791479247934794479547964797479847994800480148024803480448054806480748084809481048114812481348144815481648174818481948204821482248234824482548264827482848294830483148324833483448354836483748384839484048414842484348444845484648474848484948504851485248534854485548564857485848594860486148624863486448654866486748684869487048714872487348744875487648774878487948804881488248834884488548864887488848894890489148924893489448954896489748984899490049014902490349044905490649074908490949104911491249134914491549164917491849194920492149224923492449254926492749284929493049314932493349344935493649374938493949404941494249434944494549464947494849494950495149524953495449554956495749584959496049614962496349644965496649674968496949704971497249734974497549764977497849794980498149824983498449854986498749884989499049914992499349944995499649974998499950005001500250035004500550065007500850095010501150125013501450155016501750185019502050215022502350245025502650275028502950305031503250335034503550365037503850395040504150425043504450455046504750485049505050515052505350545055505650575058505950605061506250635064506550665067506850695070507150725073507450755076507750785079508050815082508350845085508650875088508950905091509250935094509550965097509850995100510151025103510451055106510751085109511051115112511351145115511651175118511951205121512251235124512551265127512851295130513151325133513451355136513751385139514051415142514351445145514651475148514951505151515251535154515551565157515851595160516151625163516451655166516751685169517051715172517351745175517651775178517951805181518251835184518551865187518851895190519151925193519451955196519751985199520052015202520352045205520652075208520952105211521252135214521552165217521852195220522152225223522452255226522752285229523052315232523352345235523652375238523952405241524252435244524552465247524852495250525152525253525452555256525752585259526052615262526352645265526652675268526952705271527252735274527552765277527852795280528152825283528452855286528752885289529052915292529352945295529652975298529953005301530253035304530553065307530853095310531153125313531453155316531753185319532053215322532353245325532653275328532953305331533253335334533553365337533853395340534153425343534453455346534753485349535053515352535353545355535653575358535953605361536253635364536553665367536853695370537153725373537453755376537753785379538053815382538353845385538653875388538953905391539253935394539553965397539853995400540154025403540454055406540754085409541054115412541354145415541654175418541954205421542254235424542554265427542854295430543154325433543454355436543754385439544054415442544354445445544654475448544954505451545254535454545554565457545854595460546154625463546454655466546754685469547054715472547354745475547654775478547954805481548254835484548554865487548854895490549154925493549454955496549754985499550055015502550355045505550655075508550955105511551255135514551555165517551855195520552155225523552455255526552755285529553055315532553355345535553655375538553955405541554255435544554555465547554855495550555155525553555455555556555755585559556055615562556355645565556655675568556955705571557255735574557555765577557855795580558155825583558455855586558755885589559055915592559355945595559655975598559956005601560256035604560556065607560856095610561156125613561456155616561756185619562056215622562356245625562656275628562956305631563256335634563556365637563856395640564156425643564456455646564756485649565056515652565356545655565656575658565956605661566256635664566556665667566856695670567156725673567456755676567756785679568056815682568356845685568656875688568956905691569256935694569556965697569856995700570157025703570457055706570757085709571057115712571357145715571657175718571957205721572257235724572557265727572857295730573157325733573457355736573757385739574057415742574357445745574657475748574957505751575257535754575557565757575857595760576157625763576457655766576757685769577057715772577357745775577657775778577957805781578257835784578557865787578857895790579157925793579457955796579757985799580058015802580358045805580658075808580958105811581258135814581558165817581858195820582158225823582458255826582758285829583058315832583358345835583658375838583958405841584258435844584558465847584858495850585158525853585458555856585758585859586058615862586358645865586658675868586958705871587258735874587558765877587858795880588158825883588458855886588758885889589058915892589358945895589658975898589959005901590259035904590559065907590859095910591159125913591459155916591759185919592059215922592359245925592659275928592959305931593259335934593559365937593859395940594159425943594459455946594759485949595059515952595359545955595659575958595959605961596259635964596559665967596859695970597159725973597459755976597759785979598059815982598359845985598659875988598959905991599259935994599559965997599859996000600160026003600460056006600760086009601060116012601360146015601660176018601960206021602260236024602560266027602860296030603160326033603460356036603760386039604060416042604360446045604660476048604960506051605260536054605560566057605860596060606160626063606460656066606760686069607060716072607360746075607660776078607960806081608260836084608560866087608860896090609160926093609460956096609760986099610061016102610361046105610661076108610961106111611261136114611561166117611861196120612161226123612461256126612761286129613061316132613361346135613661376138613961406141614261436144614561466147614861496150615161526153615461556156615761586159616061616162616361646165616661676168616961706171617261736174617561766177617861796180618161826183618461856186618761886189619061916192619361946195619661976198619962006201620262036204620562066207620862096210621162126213621462156216621762186219622062216222622362246225622662276228622962306231623262336234623562366237623862396240624162426243624462456246624762486249625062516252625362546255625662576258625962606261626262636264626562666267626862696270627162726273627462756276627762786279628062816282628362846285628662876288628962906291629262936294629562966297629862996300630163026303630463056306630763086309631063116312631363146315631663176318631963206321632263236324632563266327632863296330633163326333633463356336633763386339634063416342634363446345634663476348634963506351635263536354635563566357635863596360636163626363636463656366636763686369637063716372637363746375637663776378637963806381638263836384638563866387638863896390639163926393639463956396639763986399640064016402640364046405640664076408640964106411641264136414641564166417641864196420642164226423642464256426642764286429643064316432643364346435643664376438643964406441644264436444644564466447644864496450645164526453645464556456645764586459646064616462646364646465646664676468646964706471647264736474647564766477647864796480648164826483648464856486648764886489649064916492649364946495649664976498649965006501650265036504650565066507650865096510651165126513651465156516651765186519652065216522652365246525652665276528652965306531653265336534653565366537653865396540654165426543654465456546654765486549655065516552655365546555655665576558655965606561656265636564656565666567656865696570657165726573657465756576657765786579658065816582658365846585658665876588658965906591659265936594659565966597659865996600660166026603660466056606660766086609661066116612661366146615661666176618661966206621662266236624662566266627662866296630663166326633663466356636663766386639664066416642664366446645664666476648664966506651665266536654665566566657665866596660666166626663666466656666666766686669667066716672667366746675667666776678667966806681668266836684668566866687668866896690669166926693669466956696669766986699670067016702670367046705670667076708670967106711671267136714671567166717671867196720672167226723672467256726672767286729673067316732673367346735673667376738673967406741674267436744674567466747674867496750675167526753675467556756675767586759676067616762676367646765676667676768676967706771677267736774677567766777677867796780678167826783678467856786678767886789679067916792679367946795679667976798679968006801680268036804680568066807680868096810681168126813681468156816681768186819682068216822682368246825682668276828682968306831683268336834683568366837683868396840684168426843684468456846684768486849685068516852685368546855685668576858685968606861686268636864686568666867686868696870687168726873687468756876687768786879688068816882688368846885688668876888688968906891689268936894689568966897689868996900690169026903690469056906690769086909691069116912691369146915691669176918691969206921692269236924692569266927692869296930693169326933693469356936693769386939694069416942694369446945694669476948694969506951695269536954695569566957695869596960696169626963696469656966696769686969697069716972697369746975697669776978697969806981698269836984698569866987698869896990699169926993699469956996699769986999700070017002700370047005700670077008700970107011701270137014701570167017701870197020702170227023702470257026702770287029703070317032703370347035703670377038703970407041704270437044704570467047704870497050705170527053705470557056705770587059706070617062706370647065706670677068706970707071707270737074707570767077707870797080708170827083708470857086708770887089709070917092709370947095709670977098709971007101710271037104710571067107710871097110711171127113711471157116711771187119712071217122712371247125712671277128712971307131713271337134713571367137713871397140714171427143714471457146714771487149715071517152715371547155715671577158715971607161716271637164716571667167716871697170717171727173717471757176717771787179718071817182718371847185718671877188718971907191719271937194719571967197719871997200720172027203720472057206720772087209721072117212721372147215721672177218721972207221722272237224722572267227722872297230723172327233723472357236723772387239724072417242724372447245724672477248724972507251725272537254725572567257725872597260726172627263726472657266726772687269727072717272727372747275727672777278727972807281728272837284728572867287728872897290729172927293729472957296729772987299730073017302730373047305730673077308730973107311731273137314731573167317731873197320732173227323732473257326732773287329733073317332733373347335733673377338733973407341734273437344734573467347734873497350735173527353735473557356735773587359736073617362736373647365736673677368736973707371737273737374737573767377737873797380738173827383738473857386738773887389739073917392739373947395739673977398739974007401740274037404740574067407740874097410741174127413741474157416741774187419742074217422742374247425742674277428742974307431743274337434743574367437743874397440744174427443744474457446744774487449745074517452745374547455745674577458745974607461746274637464746574667467746874697470747174727473747474757476747774787479748074817482748374847485748674877488748974907491749274937494749574967497749874997500750175027503750475057506750775087509751075117512751375147515751675177518751975207521752275237524752575267527752875297530753175327533753475357536753775387539754075417542754375447545754675477548754975507551755275537554755575567557755875597560756175627563756475657566756775687569757075717572757375747575757675777578757975807581758275837584758575867587758875897590759175927593759475957596759775987599760076017602760376047605760676077608760976107611761276137614761576167617761876197620762176227623762476257626762776287629763076317632763376347635763676377638763976407641764276437644764576467647764876497650765176527653765476557656765776587659766076617662766376647665766676677668766976707671767276737674767576767677767876797680768176827683768476857686768776887689769076917692769376947695769676977698769977007701770277037704770577067707770877097710771177127713771477157716771777187719772077217722772377247725772677277728772977307731773277337734773577367737773877397740774177427743774477457746774777487749775077517752775377547755775677577758775977607761776277637764776577667767776877697770777177727773777477757776777777787779778077817782778377847785778677877788778977907791779277937794779577967797779877997800780178027803780478057806780778087809781078117812781378147815781678177818781978207821782278237824782578267827782878297830783178327833783478357836783778387839784078417842784378447845784678477848784978507851785278537854785578567857785878597860786178627863786478657866786778687869787078717872787378747875787678777878787978807881788278837884788578867887788878897890789178927893789478957896789778987899790079017902790379047905790679077908790979107911791279137914791579167917791879197920792179227923792479257926792779287929793079317932793379347935793679377938793979407941794279437944794579467947794879497950795179527953795479557956795779587959796079617962796379647965796679677968796979707971797279737974797579767977797879797980798179827983798479857986798779887989799079917992799379947995799679977998799980008001800280038004800580068007800880098010801180128013801480158016801780188019802080218022802380248025802680278028802980308031803280338034803580368037803880398040804180428043804480458046804780488049805080518052805380548055805680578058805980608061806280638064806580668067806880698070807180728073807480758076807780788079808080818082808380848085808680878088808980908091809280938094809580968097809880998100810181028103810481058106810781088109811081118112811381148115811681178118811981208121812281238124812581268127812881298130813181328133813481358136813781388139814081418142814381448145814681478148814981508151815281538154815581568157815881598160816181628163816481658166816781688169817081718172817381748175817681778178817981808181818281838184818581868187818881898190819181928193819481958196819781988199820082018202820382048205820682078208820982108211821282138214821582168217821882198220822182228223822482258226822782288229823082318232823382348235823682378238823982408241824282438244824582468247824882498250825182528253825482558256825782588259826082618262826382648265826682678268826982708271827282738274827582768277827882798280828182828283828482858286828782888289829082918292829382948295829682978298829983008301830283038304830583068307830883098310831183128313831483158316831783188319832083218322832383248325832683278328832983308331833283338334833583368337833883398340834183428343834483458346834783488349835083518352835383548355835683578358835983608361836283638364836583668367836883698370837183728373837483758376837783788379838083818382838383848385838683878388838983908391839283938394839583968397839883998400840184028403840484058406840784088409841084118412841384148415841684178418841984208421842284238424842584268427842884298430843184328433843484358436843784388439844084418442844384448445844684478448844984508451845284538454845584568457845884598460846184628463846484658466846784688469847084718472847384748475847684778478847984808481848284838484848584868487848884898490849184928493849484958496849784988499850085018502850385048505850685078508850985108511851285138514851585168517851885198520852185228523852485258526852785288529853085318532853385348535853685378538853985408541854285438544854585468547854885498550855185528553855485558556855785588559856085618562856385648565856685678568856985708571857285738574857585768577857885798580858185828583858485858586858785888589859085918592859385948595859685978598859986008601860286038604860586068607860886098610861186128613861486158616861786188619862086218622862386248625862686278628862986308631863286338634863586368637863886398640864186428643864486458646864786488649865086518652865386548655865686578658865986608661866286638664866586668667866886698670867186728673867486758676867786788679868086818682868386848685868686878688868986908691869286938694869586968697869886998700870187028703870487058706870787088709871087118712871387148715871687178718871987208721872287238724872587268727872887298730873187328733873487358736873787388739874087418742874387448745874687478748874987508751875287538754875587568757875887598760876187628763876487658766876787688769877087718772877387748775877687778778877987808781878287838784878587868787878887898790879187928793879487958796879787988799880088018802880388048805880688078808880988108811881288138814881588168817881888198820882188228823882488258826882788288829883088318832883388348835883688378838883988408841884288438844884588468847884888498850885188528853885488558856885788588859886088618862886388648865886688678868886988708871887288738874887588768877887888798880888188828883888488858886888788888889889088918892889388948895889688978898889989008901890289038904890589068907890889098910891189128913891489158916891789188919892089218922892389248925892689278928892989308931893289338934893589368937893889398940894189428943894489458946894789488949895089518952895389548955895689578958895989608961896289638964896589668967896889698970897189728973897489758976897789788979898089818982898389848985898689878988898989908991899289938994899589968997899889999000900190029003900490059006900790089009901090119012901390149015901690179018901990209021902290239024902590269027902890299030903190329033903490359036903790389039904090419042904390449045904690479048904990509051905290539054905590569057905890599060906190629063906490659066906790689069907090719072907390749075907690779078907990809081908290839084908590869087908890899090909190929093909490959096909790989099910091019102910391049105910691079108910991109111911291139114911591169117911891199120912191229123912491259126912791289129913091319132913391349135913691379138913991409141914291439144914591469147914891499150915191529153915491559156915791589159916091619162916391649165916691679168916991709171917291739174917591769177917891799180918191829183918491859186918791889189919091919192919391949195919691979198919992009201920292039204920592069207920892099210921192129213921492159216921792189219922092219222922392249225922692279228922992309231923292339234923592369237923892399240924192429243924492459246924792489249925092519252925392549255925692579258925992609261926292639264926592669267926892699270927192729273927492759276927792789279928092819282928392849285928692879288928992909291929292939294929592969297929892999300930193029303930493059306930793089309931093119312931393149315931693179318931993209321932293239324932593269327932893299330933193329333933493359336933793389339934093419342934393449345934693479348934993509351935293539354935593569357935893599360936193629363936493659366936793689369937093719372937393749375937693779378937993809381938293839384938593869387938893899390939193929393939493959396939793989399940094019402940394049405940694079408940994109411941294139414941594169417941894199420942194229423942494259426942794289429943094319432943394349435943694379438943994409441944294439444944594469447944894499450945194529453945494559456945794589459946094619462946394649465946694679468946994709471947294739474947594769477947894799480948194829483948494859486948794889489949094919492949394949495949694979498949995009501950295039504950595069507950895099510951195129513951495159516951795189519952095219522952395249525952695279528952995309531953295339534953595369537953895399540954195429543954495459546954795489549955095519552955395549555955695579558955995609561956295639564956595669567956895699570957195729573957495759576957795789579958095819582958395849585958695879588958995909591959295939594959595969597959895999600960196029603960496059606960796089609961096119612961396149615961696179618961996209621962296239624962596269627962896299630963196329633963496359636963796389639964096419642964396449645964696479648964996509651965296539654965596569657965896599660966196629663966496659666966796689669967096719672967396749675967696779678967996809681968296839684968596869687968896899690969196929693969496959696969796989699970097019702970397049705970697079708970997109711971297139714971597169717971897199720972197229723972497259726972797289729973097319732973397349735973697379738973997409741974297439744974597469747974897499750975197529753975497559756975797589759976097619762976397649765976697679768976997709771977297739774977597769777977897799780978197829783978497859786978797889789979097919792979397949795979697979798979998009801980298039804980598069807980898099810981198129813981498159816981798189819982098219822982398249825982698279828982998309831983298339834983598369837983898399840984198429843984498459846984798489849985098519852985398549855985698579858985998609861986298639864986598669867986898699870987198729873987498759876987798789879988098819882988398849885988698879888988998909891989298939894989598969897989898999900990199029903990499059906990799089909991099119912991399149915991699179918991999209921992299239924992599269927992899299930993199329933993499359936993799389939994099419942994399449945994699479948994999509951995299539954995599569957995899599960996199629963996499659966996799689969997099719972997399749975997699779978997999809981998299839984998599869987998899899990999199929993999499959996999799989999100001000110002100031000410005100061000710008100091001010011100121001310014100151001610017100181001910020100211002210023100241002510026100271002810029100301003110032100331003410035100361003710038100391004010041100421004310044100451004610047100481004910050100511005210053100541005510056100571005810059100601006110062100631006410065100661006710068100691007010071100721007310074100751007610077100781007910080100811008210083100841008510086100871008810089100901009110092100931009410095100961009710098100991010010101101021010310104101051010610107101081010910110101111011210113101141011510116101171011810119101201012110122101231012410125101261012710128101291013010131101321013310134101351013610137101381013910140101411014210143101441014510146101471014810149101501015110152101531015410155101561015710158101591016010161101621016310164101651016610167101681016910170101711017210173101741017510176101771017810179101801018110182101831018410185101861018710188101891019010191101921019310194101951019610197101981019910200102011020210203102041020510206102071020810209102101021110212102131021410215102161021710218102191022010221102221022310224102251022610227102281022910230102311023210233102341023510236102371023810239102401024110242102431024410245102461024710248102491025010251102521025310254102551025610257102581025910260102611026210263102641026510266102671026810269102701027110272102731027410275102761027710278102791028010281102821028310284102851028610287102881028910290102911029210293102941029510296102971029810299103001030110302103031030410305103061030710308103091031010311103121031310314103151031610317103181031910320103211032210323103241032510326103271032810329103301033110332103331033410335103361033710338103391034010341103421034310344103451034610347103481034910350103511035210353103541035510356103571035810359103601036110362103631036410365103661036710368103691037010371103721037310374103751037610377103781037910380103811038210383103841038510386103871038810389103901039110392103931039410395103961039710398103991040010401104021040310404104051040610407104081040910410104111041210413104141041510416104171041810419104201042110422104231042410425104261042710428104291043010431104321043310434104351043610437104381043910440104411044210443104441044510446104471044810449104501045110452104531045410455104561045710458104591046010461104621046310464104651046610467104681046910470104711047210473104741047510476104771047810479104801048110482104831048410485104861048710488104891049010491104921049310494104951049610497104981049910500105011050210503105041050510506105071050810509105101051110512105131051410515105161051710518105191052010521105221052310524105251052610527105281052910530105311053210533105341053510536105371053810539105401054110542105431054410545105461054710548105491055010551105521055310554105551055610557105581055910560105611056210563105641056510566105671056810569105701057110572105731057410575105761057710578105791058010581105821058310584105851058610587105881058910590105911059210593105941059510596105971059810599106001060110602106031060410605106061060710608106091061010611106121061310614106151061610617106181061910620106211062210623106241062510626106271062810629106301063110632106331063410635106361063710638106391064010641106421064310644106451064610647106481064910650106511065210653106541065510656106571065810659106601066110662106631066410665106661066710668106691067010671106721067310674106751067610677106781067910680106811068210683106841068510686106871068810689106901069110692106931069410695106961069710698106991070010701107021070310704107051070610707107081070910710107111071210713107141071510716107171071810719107201072110722107231072410725107261072710728107291073010731107321073310734107351073610737107381073910740107411074210743107441074510746107471074810749107501075110752107531075410755107561075710758107591076010761107621076310764107651076610767107681076910770107711077210773107741077510776107771077810779107801078110782107831078410785107861078710788107891079010791107921079310794107951079610797107981079910800108011080210803108041080510806108071080810809108101081110812108131081410815108161081710818108191082010821108221082310824108251082610827108281082910830108311083210833108341083510836108371083810839108401084110842108431084410845108461084710848108491085010851108521085310854108551085610857108581085910860108611086210863108641086510866108671086810869108701087110872108731087410875108761087710878108791088010881108821088310884108851088610887108881088910890108911089210893108941089510896108971089810899109001090110902109031090410905109061090710908109091091010911109121091310914109151091610917109181091910920109211092210923109241092510926109271092810929109301093110932109331093410935109361093710938109391094010941109421094310944109451094610947109481094910950109511095210953109541095510956109571095810959109601096110962109631096410965109661096710968109691097010971109721097310974109751097610977109781097910980109811098210983109841098510986109871098810989109901099110992109931099410995109961099710998109991100011001110021100311004110051100611007110081100911010110111101211013110141101511016110171101811019110201102111022110231102411025110261102711028110291103011031110321103311034110351103611037110381103911040110411104211043110441104511046110471104811049110501105111052110531105411055110561105711058110591106011061110621106311064110651106611067110681106911070110711107211073110741107511076110771107811079110801108111082110831108411085110861108711088110891109011091110921109311094110951109611097110981109911100111011110211103111041110511106111071110811109111101111111112111131111411115111161111711118111191112011121111221112311124111251112611127111281112911130111311113211133111341113511136111371113811139111401114111142111431114411145111461114711148111491115011151111521115311154111551115611157111581115911160111611116211163111641116511166111671116811169111701117111172111731117411175111761117711178111791118011181111821118311184111851118611187111881118911190111911119211193111941119511196111971119811199112001120111202112031120411205112061120711208112091121011211112121121311214112151121611217112181121911220112211122211223112241122511226112271122811229112301123111232112331123411235112361123711238112391124011241112421124311244112451124611247112481124911250112511125211253112541125511256112571125811259112601126111262112631126411265112661126711268112691127011271112721127311274112751127611277112781127911280112811128211283112841128511286112871128811289112901129111292112931129411295112961129711298112991130011301113021130311304113051130611307113081130911310113111131211313113141131511316113171131811319113201132111322113231132411325113261132711328113291133011331113321133311334113351133611337113381133911340113411134211343113441134511346113471134811349113501135111352113531135411355113561135711358113591136011361113621136311364113651136611367113681136911370113711137211373113741137511376113771137811379113801138111382113831138411385113861138711388113891139011391113921139311394113951139611397113981139911400114011140211403114041140511406114071140811409114101141111412114131141411415114161141711418114191142011421114221142311424114251142611427114281142911430114311143211433114341143511436114371143811439114401144111442114431144411445114461144711448114491145011451114521145311454114551145611457114581145911460114611146211463114641146511466114671146811469114701147111472114731147411475114761147711478114791148011481114821148311484114851148611487114881148911490114911149211493114941149511496114971149811499115001150111502115031150411505115061150711508115091151011511115121151311514115151151611517115181151911520115211152211523115241152511526115271152811529115301153111532115331153411535115361153711538115391154011541115421154311544115451154611547115481154911550115511155211553115541155511556115571155811559115601156111562115631156411565115661156711568115691157011571115721157311574115751157611577115781157911580115811158211583115841158511586115871158811589115901159111592115931159411595115961159711598115991160011601116021160311604116051160611607116081160911610116111161211613116141161511616116171161811619116201162111622116231162411625116261162711628116291163011631116321163311634116351163611637116381163911640116411164211643116441164511646116471164811649116501165111652116531165411655116561165711658116591166011661116621166311664116651166611667116681166911670116711167211673116741167511676116771167811679116801168111682116831168411685116861168711688116891169011691116921169311694116951169611697116981169911700117011170211703117041170511706117071170811709117101171111712117131171411715117161171711718117191172011721117221172311724117251172611727117281172911730117311173211733117341173511736117371173811739117401174111742117431174411745117461174711748117491175011751117521175311754117551175611757117581175911760117611176211763117641176511766117671176811769117701177111772117731177411775117761177711778117791178011781117821178311784117851178611787117881178911790117911179211793117941179511796117971179811799118001180111802118031180411805118061180711808118091181011811118121181311814118151181611817118181181911820118211182211823118241182511826118271182811829118301183111832118331183411835118361183711838118391184011841118421184311844118451184611847118481184911850118511185211853118541185511856118571185811859118601186111862118631186411865118661186711868118691187011871118721187311874118751187611877118781187911880118811188211883118841188511886118871188811889118901189111892118931189411895118961189711898118991190011901119021190311904119051190611907119081190911910119111191211913119141191511916119171191811919119201192111922119231192411925119261192711928119291193011931119321193311934119351193611937119381193911940119411194211943119441194511946119471194811949119501195111952119531195411955119561195711958119591196011961119621196311964119651196611967119681196911970119711197211973119741197511976119771197811979119801198111982119831198411985119861198711988119891199011991119921199311994119951199611997119981199912000120011200212003120041200512006120071200812009120101201112012120131201412015120161201712018120191202012021120221202312024120251202612027120281202912030120311203212033120341203512036120371203812039120401204112042120431204412045120461204712048120491205012051120521205312054120551205612057120581205912060120611206212063120641206512066120671206812069120701207112072120731207412075120761207712078120791208012081120821208312084120851208612087120881208912090120911209212093120941209512096120971209812099121001210112102121031210412105121061210712108121091211012111121121211312114121151211612117121181211912120121211212212123121241212512126121271212812129121301213112132121331213412135121361213712138121391214012141121421214312144121451214612147121481214912150121511215212153121541215512156121571215812159121601216112162121631216412165121661216712168121691217012171121721217312174121751217612177121781217912180121811218212183121841218512186121871218812189121901219112192121931219412195121961219712198121991220012201122021220312204122051220612207122081220912210122111221212213122141221512216122171221812219122201222112222122231222412225122261222712228122291223012231122321223312234122351223612237122381223912240122411224212243122441224512246122471224812249122501225112252122531225412255122561225712258122591226012261122621226312264122651226612267122681226912270122711227212273122741227512276122771227812279122801228112282122831228412285122861228712288122891229012291122921229312294122951229612297122981229912300123011230212303123041230512306123071230812309123101231112312123131231412315123161231712318123191232012321123221232312324123251232612327123281232912330123311233212333123341233512336123371233812339123401234112342123431234412345123461234712348123491235012351123521235312354123551235612357123581235912360123611236212363123641236512366123671236812369123701237112372123731237412375123761237712378123791238012381123821238312384123851238612387123881238912390123911239212393123941239512396123971239812399124001240112402124031240412405124061240712408124091241012411124121241312414124151241612417124181241912420124211242212423124241242512426124271242812429124301243112432124331243412435124361243712438124391244012441124421244312444124451244612447124481244912450124511245212453124541245512456124571245812459124601246112462124631246412465124661246712468124691247012471124721247312474124751247612477124781247912480124811248212483124841248512486124871248812489124901249112492124931249412495124961249712498124991250012501125021250312504125051250612507125081250912510125111251212513125141251512516125171251812519125201252112522125231252412525125261252712528125291253012531125321253312534125351253612537125381253912540125411254212543125441254512546125471254812549125501255112552125531255412555125561255712558125591256012561125621256312564125651256612567125681256912570125711257212573125741257512576125771257812579125801258112582125831258412585125861258712588125891259012591125921259312594125951259612597125981259912600126011260212603126041260512606126071260812609126101261112612126131261412615126161261712618126191262012621126221262312624126251262612627126281262912630126311263212633126341263512636126371263812639126401264112642126431264412645126461264712648126491265012651126521265312654126551265612657126581265912660126611266212663126641266512666126671266812669126701267112672126731267412675126761267712678126791268012681126821268312684126851268612687126881268912690126911269212693126941269512696126971269812699127001270112702127031270412705127061270712708127091271012711127121271312714127151271612717127181271912720127211272212723127241272512726127271272812729127301273112732127331273412735127361273712738127391274012741127421274312744127451274612747127481274912750127511275212753127541275512756127571275812759127601276112762127631276412765127661276712768127691277012771127721277312774127751277612777127781277912780127811278212783127841278512786127871278812789127901279112792127931279412795127961279712798127991280012801128021280312804128051280612807128081280912810128111281212813128141281512816128171281812819128201282112822128231282412825128261282712828128291283012831128321283312834128351283612837128381283912840128411284212843128441284512846128471284812849128501285112852128531285412855128561285712858128591286012861128621286312864128651286612867128681286912870128711287212873128741287512876128771287812879128801288112882128831288412885128861288712888128891289012891128921289312894128951289612897128981289912900129011290212903129041290512906129071290812909129101291112912129131291412915129161291712918129191292012921129221292312924129251292612927129281292912930129311293212933129341293512936129371293812939129401294112942129431294412945129461294712948129491295012951129521295312954129551295612957129581295912960129611296212963129641296512966129671296812969129701297112972129731297412975129761297712978129791298012981129821298312984129851298612987129881298912990129911299212993129941299512996129971299812999130001300113002130031300413005130061300713008130091301013011130121301313014130151301613017130181301913020130211302213023130241302513026130271302813029130301303113032130331303413035130361303713038130391304013041130421304313044130451304613047130481304913050130511305213053130541305513056130571305813059130601306113062130631306413065130661306713068130691307013071130721307313074130751307613077130781307913080130811308213083130841308513086130871308813089130901309113092130931309413095130961309713098130991310013101131021310313104131051310613107131081310913110131111311213113131141311513116131171311813119131201312113122131231312413125131261312713128131291313013131131321313313134131351313613137131381313913140131411314213143131441314513146131471314813149131501315113152131531315413155131561315713158131591316013161131621316313164131651316613167131681316913170131711317213173131741317513176131771317813179131801318113182131831318413185131861318713188131891319013191131921319313194131951319613197131981319913200132011320213203132041320513206132071320813209132101321113212132131321413215132161321713218132191322013221132221322313224132251322613227132281322913230132311323213233132341323513236132371323813239132401324113242132431324413245132461324713248132491325013251132521325313254132551325613257132581325913260132611326213263132641326513266132671326813269132701327113272132731327413275132761327713278132791328013281132821328313284132851328613287132881328913290132911329213293132941329513296132971329813299133001330113302133031330413305133061330713308133091331013311133121331313314133151331613317133181331913320133211332213323133241332513326133271332813329133301333113332133331333413335133361333713338133391334013341133421334313344133451334613347133481334913350133511335213353133541335513356133571335813359133601336113362133631336413365133661336713368133691337013371133721337313374133751337613377133781337913380133811338213383133841338513386133871338813389133901339113392133931339413395133961339713398133991340013401134021340313404134051340613407134081340913410134111341213413134141341513416134171341813419134201342113422134231342413425134261342713428134291343013431134321343313434134351343613437134381343913440134411344213443134441344513446134471344813449134501345113452134531345413455134561345713458134591346013461134621346313464134651346613467134681346913470134711347213473134741347513476134771347813479134801348113482134831348413485134861348713488134891349013491134921349313494134951349613497134981349913500135011350213503135041350513506135071350813509135101351113512135131351413515135161351713518135191352013521135221352313524135251352613527135281352913530135311353213533135341353513536135371353813539135401354113542135431354413545135461354713548135491355013551135521355313554135551355613557135581355913560135611356213563135641356513566135671356813569135701357113572135731357413575135761357713578135791358013581135821358313584135851358613587135881358913590135911359213593135941359513596135971359813599136001360113602136031360413605136061360713608136091361013611136121361313614136151361613617136181361913620136211362213623136241362513626136271362813629136301363113632136331363413635136361363713638136391364013641136421364313644136451364613647136481364913650136511365213653136541365513656136571365813659136601366113662136631366413665136661366713668136691367013671136721367313674136751367613677136781367913680136811368213683136841368513686136871368813689136901369113692136931369413695136961369713698136991370013701137021370313704137051370613707137081370913710137111371213713137141371513716137171371813719137201372113722137231372413725137261372713728137291373013731137321373313734137351373613737137381373913740137411374213743137441374513746137471374813749137501375113752137531375413755137561375713758137591376013761137621376313764137651376613767137681376913770137711377213773137741377513776137771377813779137801378113782137831378413785137861378713788137891379013791137921379313794137951379613797137981379913800138011380213803138041380513806138071380813809138101381113812138131381413815138161381713818138191382013821138221382313824138251382613827138281382913830138311383213833138341383513836138371383813839138401384113842138431384413845138461384713848138491385013851138521385313854138551385613857138581385913860138611386213863138641386513866138671386813869138701387113872138731387413875138761387713878138791388013881138821388313884138851388613887138881388913890138911389213893138941389513896138971389813899139001390113902139031390413905139061390713908139091391013911139121391313914139151391613917139181391913920139211392213923139241392513926139271392813929139301393113932139331393413935139361393713938139391394013941139421394313944139451394613947139481394913950139511395213953139541395513956139571395813959139601396113962139631396413965139661396713968139691397013971139721397313974139751397613977139781397913980139811398213983139841398513986139871398813989139901399113992139931399413995139961399713998139991400014001140021400314004140051400614007140081400914010140111401214013140141401514016140171401814019140201402114022140231402414025140261402714028140291403014031140321403314034140351403614037140381403914040140411404214043140441404514046140471404814049140501405114052140531405414055140561405714058140591406014061140621406314064140651406614067140681406914070140711407214073140741407514076140771407814079140801408114082140831408414085140861408714088140891409014091140921409314094140951409614097140981409914100141011410214103141041410514106141071410814109141101411114112141131411414115141161411714118141191412014121141221412314124141251412614127141281412914130141311413214133141341413514136141371413814139141401414114142141431414414145141461414714148141491415014151141521415314154141551415614157141581415914160141611416214163141641416514166141671416814169141701417114172141731417414175141761417714178141791418014181141821418314184141851418614187141881418914190141911419214193141941419514196141971419814199142001420114202142031420414205142061420714208142091421014211142121421314214142151421614217142181421914220142211422214223142241422514226142271422814229142301423114232142331423414235142361423714238142391424014241142421424314244142451424614247142481424914250142511425214253142541425514256142571425814259142601426114262142631426414265142661426714268142691427014271142721427314274142751427614277142781427914280142811428214283
  1. /**
  2. * Copyright (c) 2006-2020, JGraph Ltd
  3. * Copyright (c) 2006-2020, draw.io AG
  4. */
  5. var StorageDialog = function(editorUi, fn, rowLimit)
  6. {
  7. rowLimit = (rowLimit != null) ? rowLimit : 2;
  8. var div = document.createElement('div');
  9. div.style.textAlign = 'center';
  10. div.style.whiteSpace = 'nowrap';
  11. div.style.paddingTop = '0px';
  12. div.style.paddingBottom = '20px';
  13. var buttons = document.createElement('div');
  14. buttons.style.border = '1px solid #d3d3d3';
  15. buttons.style.borderWidth = '1px 0px 1px 0px';
  16. buttons.style.padding = '10px 0px 20px 0px';
  17. var count = 0, totalBtns = 0;
  18. var container = document.createElement('div');
  19. container.style.paddingTop = '2px';
  20. buttons.appendChild(container);
  21. var p3 = document.createElement('p');
  22. function addLogo(img, title, mode, clientName, labels, clientFn)
  23. {
  24. totalBtns++;
  25. if (++count > rowLimit)
  26. {
  27. mxUtils.br(container);
  28. count = 1;
  29. }
  30. var button = document.createElement('a');
  31. button.style.overflow = 'hidden';
  32. button.style.display = 'inline-block';
  33. button.className = 'geBaseButton';
  34. button.style.boxSizing = 'border-box';
  35. button.style.fontSize = '11px';
  36. button.style.position = 'relative';
  37. button.style.margin = '4px';
  38. button.style.marginTop = '8px';
  39. button.style.marginBottom = '0px';
  40. button.style.padding = '8px 10px 8px 10px';
  41. button.style.width = '88px';
  42. button.style.height = '100px';
  43. button.style.whiteSpace = 'nowrap';
  44. button.setAttribute('title', title);
  45. var label = document.createElement('div');
  46. label.style.textOverflow = 'ellipsis';
  47. label.style.overflow = 'hidden';
  48. label.style.position = 'absolute';
  49. label.style.bottom = '8px';
  50. label.style.left = '0px';
  51. label.style.right = '0px';
  52. mxUtils.write(label, title);
  53. button.appendChild(label);
  54. if (img != null)
  55. {
  56. var logo = document.createElement('img');
  57. logo.setAttribute('src', img);
  58. logo.setAttribute('border', '0');
  59. logo.setAttribute('align', 'absmiddle');
  60. logo.style.width = '60px';
  61. logo.style.height = '60px';
  62. logo.style.paddingBottom = '6px';
  63. button.appendChild(logo);
  64. }
  65. else
  66. {
  67. label.style.paddingTop = '5px';
  68. label.style.whiteSpace = 'normal';
  69. // Handles special case
  70. if (mxClient.IS_IOS)
  71. {
  72. button.style.padding = '0px 10px 20px 10px';
  73. button.style.top = '6px';
  74. }
  75. else if (mxClient.IS_FF)
  76. {
  77. label.style.paddingTop = '0px';
  78. label.style.marginTop = '-2px';
  79. }
  80. }
  81. if (labels != null)
  82. {
  83. for (var i = 0; i < labels.length; i++)
  84. {
  85. mxUtils.br(label);
  86. mxUtils.write(label, labels[i]);
  87. }
  88. }
  89. function initButton()
  90. {
  91. mxEvent.addListener(button, 'click', (clientFn != null) ? clientFn : function()
  92. {
  93. if (mode == App.MODE_GOOGLE && editorUi.spinner.spin(document.body, mxResources.get('authorizing')))
  94. {
  95. // Tries immediate authentication
  96. editorUi.drive.checkToken(mxUtils.bind(this, function()
  97. {
  98. editorUi.spinner.stop();
  99. editorUi.setMode(mode, true);
  100. fn();
  101. }));
  102. }
  103. else if (mode == App.MODE_ONEDRIVE && editorUi.spinner.spin(document.body, mxResources.get('authorizing')))
  104. {
  105. // Tries immediate authentication
  106. editorUi.oneDrive.checkToken(mxUtils.bind(this, function()
  107. {
  108. editorUi.spinner.stop();
  109. editorUi.setMode(mode, true);
  110. fn();
  111. }), function(err)
  112. {
  113. editorUi.spinner.stop();
  114. editorUi.handleError(err);
  115. });
  116. }
  117. else
  118. {
  119. editorUi.setMode(mode, true);
  120. fn();
  121. }
  122. });
  123. };
  124. // Supports lazy loading
  125. if (clientName != null && editorUi[clientName] == null)
  126. {
  127. logo.style.visibility = 'hidden';
  128. mxUtils.setOpacity(label, 10);
  129. var size = 12;
  130. var spinner = new Spinner({
  131. lines: 12, // The number of lines to draw
  132. length: size, // The length of each line
  133. width: 5, // The line thickness
  134. radius: 10, // The radius of the inner circle
  135. rotate: 0, // The rotation offset
  136. color: Editor.isDarkMode() ? '#c0c0c0' : '#000', // #rgb or #rrggbb
  137. speed: 1.5, // Rounds per second
  138. trail: 60, // Afterglow percentage
  139. shadow: false, // Whether to render a shadow
  140. hwaccel: false, // Whether to use hardware acceleration
  141. top: '40%',
  142. zIndex: 2e9 // The z-index (defaults to 2000000000)
  143. });
  144. spinner.spin(button);
  145. // Timeout after 30 secs
  146. var timeout = window.setTimeout(function()
  147. {
  148. if (editorUi[clientName] == null)
  149. {
  150. spinner.stop();
  151. button.style.display = 'none';
  152. }
  153. }, 30000);
  154. editorUi.addListener('clientLoaded', mxUtils.bind(this, function(sender, evt)
  155. {
  156. if (editorUi[clientName] != null && evt.getProperty('client') == editorUi[clientName])
  157. {
  158. window.clearTimeout(timeout);
  159. mxUtils.setOpacity(label, 100);
  160. logo.style.visibility = '';
  161. spinner.stop();
  162. initButton();
  163. if (clientName == 'drive' && p3.parentNode != null)
  164. {
  165. p3.parentNode.removeChild(p3);
  166. }
  167. }
  168. }));
  169. }
  170. else
  171. {
  172. initButton();
  173. }
  174. container.appendChild(button);
  175. };
  176. var hd = document.createElement('p');
  177. hd.style.cssText = 'font-size:22px;padding:4px 0 16px 0;margin:0;color:gray;';
  178. mxUtils.write(hd, mxResources.get('saveDiagramsTo') + ':');
  179. div.appendChild(hd);
  180. var addButtons = function()
  181. {
  182. count = 0;
  183. if (typeof window.DriveClient === 'function')
  184. {
  185. addLogo(IMAGE_PATH + '/google-drive-logo.svg', mxResources.get('googleDrive'), App.MODE_GOOGLE, 'drive');
  186. }
  187. if (typeof window.OneDriveClient === 'function')
  188. {
  189. addLogo(IMAGE_PATH + '/onedrive-logo.svg', mxResources.get('oneDrive'), App.MODE_ONEDRIVE, 'oneDrive');
  190. }
  191. if (urlParams['noDevice'] != '1')
  192. {
  193. addLogo(IMAGE_PATH + '/osa_drive-harddisk.png', mxResources.get('device'), App.MODE_DEVICE);
  194. }
  195. if (isLocalStorage && (urlParams['browser'] == '1' || urlParams['offline'] == '1'))
  196. {
  197. addLogo(IMAGE_PATH + '/osa_database.png', mxResources.get('browser'), App.MODE_BROWSER);
  198. }
  199. if (typeof window.DropboxClient === 'function')
  200. {
  201. addLogo(IMAGE_PATH + '/dropbox-logo.svg', mxResources.get('dropbox'), App.MODE_DROPBOX, 'dropbox');
  202. }
  203. if (editorUi.gitHub != null)
  204. {
  205. addLogo(IMAGE_PATH + '/github-logo.svg', mxResources.get('github'), App.MODE_GITHUB, 'gitHub');
  206. }
  207. if (editorUi.gitLab != null)
  208. {
  209. addLogo(IMAGE_PATH + '/gitlab-logo.svg', mxResources.get('gitlab'), App.MODE_GITLAB, 'gitLab');
  210. }
  211. };
  212. div.appendChild(buttons);
  213. addButtons();
  214. var later = document.createElement('span');
  215. later.style.position = 'absolute';
  216. later.style.cursor = 'pointer';
  217. later.style.bottom = '27px';
  218. later.style.color = 'gray';
  219. later.style.userSelect = 'none';
  220. later.style.textAlign = 'center';
  221. later.style.left = '50%';
  222. mxUtils.setPrefixedStyle(later.style, 'transform', 'translate(-50%,0)');
  223. mxUtils.write(later, mxResources.get('decideLater'));
  224. div.appendChild(later);
  225. mxEvent.addListener(later, 'click', function()
  226. {
  227. editorUi.hideDialog();
  228. var prev = Editor.useLocalStorage;
  229. editorUi.createFile(editorUi.defaultFilename,
  230. null, null, null, null, null, null, true);
  231. Editor.useLocalStorage = prev;
  232. });
  233. // Checks if Google Drive is missing after a 5 sec delay
  234. if (mxClient.IS_SVG && isLocalStorage && urlParams['gapi'] != '0' &&
  235. (document.documentMode == null || document.documentMode >= 10))
  236. {
  237. window.setTimeout(function()
  238. {
  239. if (editorUi.drive == null)
  240. {
  241. // To check for Disconnect plugin in chrome use mxClient.IS_GC and check for URL:
  242. // chrome-extension://jeoacafpbcihiomhlakheieifhpjdfeo/scripts/vendor/jquery/jquery-2.0.3.min.map
  243. p3.style.padding = '7px';
  244. p3.style.fontSize = '9pt';
  245. p3.style.marginTop = '-14px';
  246. p3.innerHTML = '<a style="background-color:#dcdcdc;padding:6px;color:black;text-decoration:none;" ' +
  247. 'href="https://www.drawio.com/doc/faq/google-drive-connection-problems" target="_blank">' +
  248. '<img border="0" src="' + mxGraph.prototype.warningImage.src + '" align="absmiddle" ' +
  249. 'style="margin-top:-4px"> ' + mxResources.get('googleDriveMissingClickHere') + '</a>';
  250. div.appendChild(p3);
  251. }
  252. }, 5000);
  253. }
  254. this.container = div;
  255. };
  256. /**
  257. * Constructs a dialog for creating new files from templates.
  258. */
  259. var SplashDialog = function(editorUi)
  260. {
  261. var div = document.createElement('div');
  262. div.style.textAlign = 'center';
  263. if (mxClient.IS_CHROMEAPP || EditorUi.isElectronApp)
  264. {
  265. var elt = editorUi.addLanguageMenu(div, false, '28px');
  266. if (elt != null)
  267. {
  268. elt.style.bottom = '24px';
  269. }
  270. }
  271. var logo = document.createElement('img');
  272. logo.setAttribute('border', '0');
  273. logo.setAttribute('align', 'absmiddle');
  274. logo.style.width = '32px';
  275. logo.style.height = '32px';
  276. logo.style.marginRight = '8px';
  277. logo.style.marginTop = '-4px';
  278. var buttons = document.createElement('div');
  279. buttons.style.margin = '8px 0px 0px 0px';
  280. buttons.style.padding = '18px 0px 24px 0px';
  281. var service = '';
  282. if (editorUi.mode == App.MODE_GOOGLE)
  283. {
  284. logo.src = IMAGE_PATH + '/google-drive-logo.svg';
  285. service = mxResources.get('googleDrive');
  286. }
  287. else if (editorUi.mode == App.MODE_DROPBOX)
  288. {
  289. logo.src = IMAGE_PATH + '/dropbox-logo.svg';
  290. service = mxResources.get('dropbox');
  291. }
  292. else if (editorUi.mode == App.MODE_ONEDRIVE)
  293. {
  294. logo.src = IMAGE_PATH + '/onedrive-logo.svg';
  295. service = mxResources.get('oneDrive');
  296. }
  297. else if (editorUi.mode == App.MODE_GITHUB)
  298. {
  299. logo.src = IMAGE_PATH + '/github-logo.svg';
  300. service = mxResources.get('github');
  301. }
  302. else if (editorUi.mode == App.MODE_GITLAB)
  303. {
  304. logo.src = IMAGE_PATH + '/gitlab-logo.svg';
  305. service = mxResources.get('gitlab');
  306. }
  307. else if (editorUi.mode == App.MODE_BROWSER)
  308. {
  309. logo.src = IMAGE_PATH + '/osa_database.png';
  310. service = mxResources.get('browser');
  311. }
  312. else if (editorUi.mode == App.MODE_TRELLO)
  313. {
  314. logo.src = IMAGE_PATH + '/trello-logo.svg';
  315. service = mxResources.get('trello');
  316. }
  317. else
  318. {
  319. logo.src = IMAGE_PATH + '/osa_drive-harddisk.png';
  320. buttons.style.paddingBottom = '10px';
  321. buttons.style.paddingTop = '30px';
  322. service = mxResources.get('device');
  323. }
  324. var btn = document.createElement('button');
  325. btn.className = 'geBigButton';
  326. btn.style.marginBottom = '8px';
  327. btn.style.fontSize = '18px';
  328. btn.style.padding = '10px';
  329. btn.style.width = '340px';
  330. if (!mxClient.IS_CHROMEAPP && !EditorUi.isElectronApp)
  331. {
  332. buttons.style.border = '1px solid #d3d3d3';
  333. buttons.style.borderWidth = '1px 0px 1px 0px';
  334. var table = document.createElement('table');
  335. var tbody = document.createElement('tbody');
  336. var row = document.createElement('tr');
  337. var left = document.createElement('td');
  338. var right = document.createElement('td');
  339. table.setAttribute('align', 'center');
  340. left.appendChild(logo);
  341. var title = document.createElement('div');
  342. title.style.fontSize = '22px';
  343. title.style.paddingBottom = '6px';
  344. title.style.color = 'gray';
  345. mxUtils.write(title, service);
  346. right.style.textAlign = 'left';
  347. right.appendChild(title);
  348. row.appendChild(left);
  349. row.appendChild(right);
  350. tbody.appendChild(row);
  351. table.appendChild(tbody);
  352. div.appendChild(table);
  353. var change = document.createElement('span');
  354. change.style.cssText = 'position:absolute;cursor:pointer;bottom:27px;color:gray;userSelect:none;text-align:center;left:50%;';
  355. mxUtils.setPrefixedStyle(change.style, 'transform', 'translate(-50%,0)');
  356. mxUtils.write(change, mxResources.get('changeStorage'));
  357. mxEvent.addListener(change, 'click', function()
  358. {
  359. editorUi.hideDialog(false);
  360. editorUi.setMode(null);
  361. editorUi.clearMode();
  362. editorUi.showSplash(true);
  363. });
  364. div.appendChild(change);
  365. }
  366. else
  367. {
  368. buttons.style.padding = '42px 0px 10px 0px';
  369. btn.style.marginBottom = '12px';
  370. }
  371. mxUtils.write(btn, mxResources.get('createNewDiagram'));
  372. mxEvent.addListener(btn, 'click', function()
  373. {
  374. editorUi.hideDialog();
  375. editorUi.actions.get('new').funct();
  376. });
  377. buttons.appendChild(btn);
  378. mxUtils.br(buttons);
  379. var btn = document.createElement('button');
  380. btn.className = 'geBigButton';
  381. btn.style.marginBottom = '22px';
  382. btn.style.fontSize = '18px';
  383. btn.style.padding = '10px';
  384. btn.style.width = '340px';
  385. mxUtils.write(btn, mxResources.get('openExistingDiagram'));
  386. mxEvent.addListener(btn, 'click', function()
  387. {
  388. editorUi.actions.get('open').funct();
  389. });
  390. buttons.appendChild(btn);
  391. var storage = 'undefined';
  392. if (editorUi.mode == App.MODE_GOOGLE)
  393. {
  394. storage = mxResources.get('googleDrive');
  395. }
  396. else if (editorUi.mode == App.MODE_DROPBOX)
  397. {
  398. storage = mxResources.get('dropbox');
  399. }
  400. else if (editorUi.mode == App.MODE_ONEDRIVE)
  401. {
  402. storage = mxResources.get('oneDrive');
  403. }
  404. else if (editorUi.mode == App.MODE_GITHUB)
  405. {
  406. storage = mxResources.get('github');
  407. }
  408. else if (editorUi.mode == App.MODE_GITLAB)
  409. {
  410. storage = mxResources.get('gitlab');
  411. }
  412. else if (editorUi.mode == App.MODE_TRELLO)
  413. {
  414. storage = mxResources.get('trello');
  415. }
  416. else if (editorUi.mode == App.MODE_DEVICE)
  417. {
  418. storage = mxResources.get('device');
  419. }
  420. else if (editorUi.mode == App.MODE_BROWSER)
  421. {
  422. storage = mxResources.get('browser');
  423. }
  424. if (!mxClient.IS_CHROMEAPP && !EditorUi.isElectronApp)
  425. {
  426. function addLogout(logout)
  427. {
  428. btn.style.marginBottom = '24px';
  429. var link = document.createElement('a');
  430. link.style.display = 'inline-block';
  431. link.style.color = 'gray';
  432. link.style.cursor = 'pointer';
  433. link.style.marginTop = '6px';
  434. mxUtils.write(link, mxResources.get('signOut'));
  435. // Makes room after last big buttons
  436. btn.style.marginBottom = '16px';
  437. buttons.style.paddingBottom = '18px';
  438. mxEvent.addListener(link, 'click', function()
  439. {
  440. editorUi.confirm(mxResources.get('areYouSure'), function()
  441. {
  442. logout();
  443. });
  444. });
  445. buttons.appendChild(link);
  446. };
  447. if (editorUi.mode == App.MODE_GOOGLE && editorUi.drive != null)
  448. {
  449. var driveUsers = editorUi.drive.getUsersList();
  450. if (driveUsers.length > 0)
  451. {
  452. var title = document.createElement('span');
  453. title.style.marginTop = '6px';
  454. mxUtils.write(title, mxResources.get('changeUser') + ':');
  455. // Makes room after last big buttons
  456. btn.style.marginBottom = '16px';
  457. buttons.style.paddingBottom = '18px';
  458. buttons.appendChild(title);
  459. var usersSelect = document.createElement('select');
  460. usersSelect.style.marginLeft = '4px';
  461. usersSelect.style.width = '140px';
  462. for (var i = 0; i < driveUsers.length; i++)
  463. {
  464. var option = document.createElement('option');
  465. mxUtils.write(option, driveUsers[i].displayName);
  466. option.value = i;
  467. usersSelect.appendChild(option);
  468. //More info (email) about the user in a disabled option
  469. option = document.createElement('option');
  470. option.innerHTML = '&nbsp;&nbsp;&nbsp;';
  471. mxUtils.write(option, '<' + driveUsers[i].email + '>');
  472. option.setAttribute('disabled', 'disabled');
  473. usersSelect.appendChild(option);
  474. }
  475. //Add account option
  476. var option = document.createElement('option');
  477. mxUtils.write(option, mxResources.get('addAccount'));
  478. option.value = driveUsers.length;
  479. usersSelect.appendChild(option);
  480. mxEvent.addListener(usersSelect, 'change', function()
  481. {
  482. var userIndex = usersSelect.value;
  483. var existingAccount = driveUsers.length != userIndex;
  484. if (existingAccount)
  485. {
  486. editorUi.drive.setUser(driveUsers[userIndex]);
  487. }
  488. editorUi.drive.authorize(existingAccount, function()
  489. {
  490. editorUi.setMode(App.MODE_GOOGLE);
  491. editorUi.hideDialog();
  492. editorUi.showSplash();
  493. }, function(resp)
  494. {
  495. editorUi.handleError(resp, null, function()
  496. {
  497. editorUi.hideDialog();
  498. editorUi.showSplash();
  499. });
  500. }, true);
  501. });
  502. buttons.appendChild(usersSelect);
  503. }
  504. else
  505. {
  506. addLogout(function()
  507. {
  508. editorUi.drive.logout();
  509. });
  510. }
  511. }
  512. else if (editorUi.mode == App.MODE_ONEDRIVE && editorUi.oneDrive != null && !editorUi.oneDrive.noLogout)
  513. {
  514. addLogout(function()
  515. {
  516. editorUi.oneDrive.logout();
  517. });
  518. }
  519. else if (editorUi.mode == App.MODE_GITHUB && editorUi.gitHub != null)
  520. {
  521. addLogout(function()
  522. {
  523. editorUi.gitHub.logout();
  524. editorUi.openLink('https://www.github.com/logout');
  525. });
  526. }
  527. else if (editorUi.mode == App.MODE_GITLAB && editorUi.gitLab != null)
  528. {
  529. addLogout(function()
  530. {
  531. editorUi.gitLab.logout();
  532. // Must use POST request to sign out of GitLab
  533. // see https://gitlab.com/gitlab-org/gitlab/-/issues/202291
  534. var form = document.createElement('form');
  535. form.setAttribute('method', 'post');
  536. form.setAttribute('action', DRAWIO_GITLAB_URL + '/users/sign_out');
  537. form.setAttribute('target', '_blank');
  538. document.body.appendChild(form);
  539. form.submit();
  540. form.parentNode.removeChild(form);
  541. });
  542. }
  543. else if (editorUi.mode == App.MODE_TRELLO && editorUi.trello != null)
  544. {
  545. if (editorUi.trello.isAuthorized())
  546. {
  547. addLogout(function()
  548. {
  549. editorUi.trello.logout();
  550. });
  551. }
  552. }
  553. else if (editorUi.mode == App.MODE_DROPBOX && editorUi.dropbox != null)
  554. {
  555. // NOTE: Dropbox has a logout option in the picker
  556. addLogout(function()
  557. {
  558. editorUi.dropbox.logout();
  559. editorUi.openLink('https://www.dropbox.com/logout');
  560. });
  561. }
  562. }
  563. div.appendChild(buttons);
  564. this.container = div;
  565. };
  566. /**
  567. * Constructs a new embed dialog
  568. */
  569. var EmbedDialog = function(editorUi, result, timeout, ignoreSize, previewFn, title, tweet, previewTitle, filename)
  570. {
  571. tweet = (tweet != null) ? tweet : 'Check out the diagram I made using @drawio';
  572. var div = document.createElement('div');
  573. var maxSize = 500000;
  574. var maxFbSize = 51200;
  575. var maxTwitterSize = 7168;
  576. // Checks if result is a link
  577. var validUrl = /^https?:\/\//.test(result) || /^mailto:\/\//.test(result);
  578. if (title != null)
  579. {
  580. mxUtils.write(div, title);
  581. }
  582. else
  583. {
  584. mxUtils.write(div, mxResources.get((result.length < maxSize) ?
  585. ((validUrl) ? 'link' : 'mainEmbedNotice') : 'preview') + ':');
  586. }
  587. mxUtils.br(div);
  588. var size = document.createElement('div');
  589. size.style.position = 'absolute';
  590. size.style.top = '30px';
  591. size.style.right = '30px';
  592. size.style.color = 'gray';
  593. mxUtils.write(size, editorUi.formatFileSize(result.length));
  594. div.appendChild(size);
  595. // Using DIV for faster rendering
  596. var text = document.createElement('textarea');
  597. text.setAttribute('autocomplete', 'off');
  598. text.setAttribute('autocorrect', 'off');
  599. text.setAttribute('autocapitalize', 'off');
  600. text.setAttribute('spellcheck', 'false');
  601. text.style.fontFamily = 'monospace';
  602. text.style.wordBreak = 'break-all';
  603. text.style.marginTop = '10px';
  604. text.style.resize = 'none';
  605. text.style.height = '150px';
  606. text.style.width = '440px';
  607. text.style.border = '1px solid gray';
  608. text.value = mxResources.get('updatingDocument');
  609. div.appendChild(text);
  610. mxUtils.br(div);
  611. this.init = function()
  612. {
  613. window.setTimeout(function()
  614. {
  615. if (result.length < maxSize)
  616. {
  617. text.value = result;
  618. text.focus();
  619. if (mxClient.IS_GC || mxClient.IS_FF || document.documentMode >= 5)
  620. {
  621. text.select();
  622. }
  623. else
  624. {
  625. document.execCommand('selectAll', false, null);
  626. }
  627. }
  628. else
  629. {
  630. text.setAttribute('readonly', 'true');
  631. text.value = mxResources.get('tooLargeUseDownload');
  632. }
  633. }, 0);
  634. };
  635. var buttons = document.createElement('div');
  636. buttons.style.position = 'absolute';
  637. buttons.style.bottom = '36px';
  638. buttons.style.right = '32px';
  639. var previewBtn = null;
  640. // Loads forever in IE9
  641. if (EmbedDialog.showPreviewOption && !mxIsElectron &&
  642. (!mxClient.IS_CHROMEAPP || validUrl) && !navigator.standalone && (validUrl ||
  643. (mxClient.IS_SVG && (document.documentMode == null || document.documentMode > 9))))
  644. {
  645. previewBtn = mxUtils.button((previewTitle != null) ? previewTitle :
  646. mxResources.get((result.length < maxSize) ? 'preview' : 'openInNewWindow'), function()
  647. {
  648. var value = (result.length < maxSize) ? text.value : result;
  649. if (previewFn != null)
  650. {
  651. previewFn(value);
  652. }
  653. else
  654. {
  655. if (validUrl)
  656. {
  657. try
  658. {
  659. var win = editorUi.openLink(value);
  660. if (win != null && (timeout == null || timeout > 0))
  661. {
  662. window.setTimeout(mxUtils.bind(this, function()
  663. {
  664. try
  665. {
  666. if (win != null && win.location.href != null &&
  667. win.location.href.substring(0, 8) != value.substring(0, 8))
  668. {
  669. win.close();
  670. editorUi.handleError({message: mxResources.get('drawingTooLarge')});
  671. }
  672. }
  673. catch (e)
  674. {
  675. // ignore
  676. }
  677. }), timeout || 500);
  678. }
  679. }
  680. catch (e)
  681. {
  682. editorUi.handleError({message: e.message || mxResources.get('drawingTooLarge')});
  683. }
  684. }
  685. else
  686. {
  687. var wnd = window.open();
  688. var doc = (wnd != null) ? wnd.document : null;
  689. if (doc != null)
  690. {
  691. doc.writeln('<html><head><title>' +
  692. mxUtils.htmlEntities(mxResources.get('preview')) +
  693. '</title><meta charset="utf-8"></head><body>' +
  694. (result.substring(0, 7) == '<iframe' ? result :
  695. mxUtils.htmlEntities(result)) + '</body></html>');
  696. doc.close();
  697. }
  698. else
  699. {
  700. editorUi.handleError({message: mxResources.get('errorUpdatingPreview')});
  701. }
  702. }
  703. }
  704. });
  705. previewBtn.className = 'geBtn';
  706. buttons.appendChild(previewBtn);
  707. }
  708. if (!validUrl || result.length > 7500)
  709. {
  710. var downloadBtn = mxUtils.button(mxResources.get(mxIsElectron ? 'save' : 'download'), function()
  711. {
  712. editorUi.hideDialog();
  713. editorUi.saveData((filename != null) ? filename : 'embed.txt', 'txt', result, 'text/plain');
  714. });
  715. downloadBtn.className = 'geBtn';
  716. buttons.appendChild(downloadBtn);
  717. }
  718. // Twitter-intent does not allow more characters, must be pasted manually
  719. if (validUrl && (!editorUi.isOffline() || mxClient.IS_CHROMEAPP))
  720. {
  721. if (result.length < maxFbSize)
  722. {
  723. var fbBtn = mxUtils.button('', function()
  724. {
  725. try
  726. {
  727. var url = 'https://www.facebook.com/sharer.php?p[url]=' +
  728. encodeURIComponent(text.value);
  729. editorUi.openLink(url);
  730. }
  731. catch (e)
  732. {
  733. editorUi.handleError({message: e.message || mxResources.get('drawingTooLarge')});
  734. }
  735. });
  736. var img = document.createElement('img');
  737. img.setAttribute('src', Editor.facebookImage);
  738. img.setAttribute('width', '18');
  739. img.setAttribute('height', '18');
  740. img.setAttribute('border', '0');
  741. fbBtn.appendChild(img);
  742. fbBtn.setAttribute('title', mxResources.get('facebook') + ' (' +
  743. editorUi.formatFileSize(maxFbSize) + ' max)');
  744. fbBtn.style.verticalAlign = 'bottom';
  745. fbBtn.style.paddingTop = '4px';
  746. fbBtn.style.minWidth = '46px'
  747. fbBtn.className = 'geBtn';
  748. buttons.appendChild(fbBtn);
  749. }
  750. if (result.length < maxTwitterSize)
  751. {
  752. var tweetBtn = mxUtils.button('', function()
  753. {
  754. try
  755. {
  756. var url = 'https://twitter.com/intent/tweet?text=' +
  757. encodeURIComponent(tweet) + '&url=' +
  758. encodeURIComponent(text.value);
  759. editorUi.openLink(url);
  760. }
  761. catch (e)
  762. {
  763. editorUi.handleError({message: e.message || mxResources.get('drawingTooLarge')});
  764. }
  765. });
  766. var img = document.createElement('img');
  767. img.setAttribute('src', Editor.tweetImage);
  768. img.setAttribute('width', '18');
  769. img.setAttribute('height', '18');
  770. img.setAttribute('border', '0');
  771. img.style.marginBottom = '5px'
  772. tweetBtn.appendChild(img);
  773. tweetBtn.setAttribute('title', mxResources.get('twitter') + ' (' +
  774. editorUi.formatFileSize(maxTwitterSize) + ' max)');
  775. tweetBtn.style.verticalAlign = 'bottom';
  776. tweetBtn.style.paddingTop = '4px';
  777. tweetBtn.style.minWidth = '46px'
  778. tweetBtn.className = 'geBtn';
  779. buttons.appendChild(tweetBtn);
  780. }
  781. }
  782. if (!editorUi.isOffline() && result.length < maxSize)
  783. {
  784. var emailBtn = mxUtils.button('', function()
  785. {
  786. try
  787. {
  788. var url = 'mailto:?subject=' +
  789. encodeURIComponent(filename || editorUi.defaultFilename) + '&body=' +
  790. encodeURIComponent(text.value);
  791. editorUi.openLink(url);
  792. }
  793. catch (e)
  794. {
  795. editorUi.handleError({message: e.message || mxResources.get('drawingTooLarge')});
  796. }
  797. });
  798. var img = document.createElement('img');
  799. img.className = 'geAdaptiveAsset';
  800. img.setAttribute('src', Editor.mailImage);
  801. img.setAttribute('width', '18');
  802. img.setAttribute('height', '18');
  803. img.setAttribute('border', '0');
  804. img.style.marginBottom = '5px'
  805. emailBtn.appendChild(img);
  806. emailBtn.style.verticalAlign = 'bottom';
  807. emailBtn.style.paddingTop = '4px';
  808. emailBtn.style.minWidth = '46px'
  809. emailBtn.className = 'geBtn';
  810. buttons.appendChild(emailBtn);
  811. }
  812. var closeBtn = mxUtils.button(mxResources.get('close'), function()
  813. {
  814. editorUi.hideDialog();
  815. });
  816. buttons.appendChild(closeBtn);
  817. var copyBtn = mxUtils.button(mxResources.get('copy'), function()
  818. {
  819. text.focus();
  820. if (mxClient.IS_GC || mxClient.IS_FF || document.documentMode >= 5)
  821. {
  822. text.select();
  823. }
  824. else
  825. {
  826. document.execCommand('selectAll', false, null);
  827. }
  828. document.execCommand('copy');
  829. editorUi.alert(mxResources.get('copiedToClipboard'));
  830. });
  831. if (result.length < maxSize)
  832. {
  833. // Does not work in Safari and shows annoying dialog for IE11-
  834. if (!mxClient.IS_SF && document.documentMode == null)
  835. {
  836. buttons.appendChild(copyBtn);
  837. copyBtn.className = 'geBtn gePrimaryBtn';
  838. closeBtn.className = 'geBtn';
  839. }
  840. else
  841. {
  842. closeBtn.className = 'geBtn gePrimaryBtn';
  843. }
  844. }
  845. else if (previewBtn != null)
  846. {
  847. buttons.appendChild(previewBtn);
  848. closeBtn.className = 'geBtn';
  849. previewBtn.className = 'geBtn gePrimaryBtn';
  850. }
  851. div.appendChild(buttons);
  852. this.container = div;
  853. };
  854. /**
  855. * Add embed dialog option.
  856. */
  857. EmbedDialog.showPreviewOption = true;
  858. /**
  859. * Constructs a dialog for embedding the diagram in Google Sites.
  860. */
  861. var GoogleSitesDialog = function(editorUi, publicUrl)
  862. {
  863. var div = document.createElement('div');
  864. var graph = editorUi.editor.graph;
  865. var bounds = graph.getGraphBounds();
  866. var scale = graph.view.scale;
  867. var x0 = Math.floor(bounds.x / scale - graph.view.translate.x);
  868. var y0 = Math.floor(bounds.y / scale - graph.view.translate.y);
  869. mxUtils.write(div, mxResources.get('googleGadget') + ':');
  870. mxUtils.br(div);
  871. var gadgetInput = document.createElement('input');
  872. gadgetInput.setAttribute('type', 'text');
  873. gadgetInput.style.marginBottom = '8px';
  874. gadgetInput.style.marginTop = '2px';
  875. gadgetInput.style.width = '410px';
  876. div.appendChild(gadgetInput);
  877. mxUtils.br(div);
  878. this.init = function()
  879. {
  880. gadgetInput.focus();
  881. if (mxClient.IS_GC || mxClient.IS_FF || document.documentMode >= 5)
  882. {
  883. gadgetInput.select();
  884. }
  885. else
  886. {
  887. document.execCommand('selectAll', false, null);
  888. }
  889. };
  890. mxUtils.write(div, mxResources.get('top') + ':');
  891. var topInput = document.createElement('input');
  892. topInput.setAttribute('type', 'text');
  893. topInput.setAttribute('size', '4');
  894. topInput.style.marginRight = '16px';
  895. topInput.style.marginLeft = '4px';
  896. topInput.value = x0;
  897. div.appendChild(topInput);
  898. mxUtils.write(div, mxResources.get('height') + ':');
  899. var heightInput = document.createElement('input');
  900. heightInput.setAttribute('type', 'text');
  901. heightInput.setAttribute('size', '4');
  902. heightInput.style.marginLeft = '4px';
  903. heightInput.value = Math.ceil(bounds.height / scale);
  904. div.appendChild(heightInput);
  905. mxUtils.br(div);
  906. var hr = document.createElement('hr');
  907. hr.setAttribute('size', '1');
  908. hr.style.marginBottom = '16px';
  909. hr.style.marginTop = '16px';
  910. div.appendChild(hr);
  911. mxUtils.write(div, mxResources.get('publicDiagramUrl') + ':');
  912. mxUtils.br(div);
  913. var urlInput = document.createElement('input');
  914. urlInput.setAttribute('type', 'text');
  915. urlInput.setAttribute('size', '28');
  916. urlInput.style.marginBottom = '8px';
  917. urlInput.style.marginTop = '2px';
  918. urlInput.style.width = '410px';
  919. urlInput.value = publicUrl || '';
  920. div.appendChild(urlInput);
  921. mxUtils.br(div);
  922. mxUtils.write(div, mxResources.get('borderWidth') + ':');
  923. var borderInput = document.createElement('input');
  924. borderInput.setAttribute('type', 'text');
  925. borderInput.setAttribute('size', '3');
  926. borderInput.style.marginBottom = '8px';
  927. borderInput.style.marginLeft = '4px';
  928. borderInput.value = '0';
  929. div.appendChild(borderInput);
  930. mxUtils.br(div);
  931. var panCheckBox = document.createElement('input');
  932. panCheckBox.setAttribute('type', 'checkbox');
  933. panCheckBox.setAttribute('checked', 'checked');
  934. panCheckBox.defaultChecked = true;
  935. panCheckBox.style.marginLeft = '16px';
  936. div.appendChild(panCheckBox);
  937. mxUtils.write(div, mxResources.get('pan') + ' ');
  938. var zoomCheckBox = document.createElement('input');
  939. zoomCheckBox.setAttribute('type', 'checkbox');
  940. zoomCheckBox.setAttribute('checked', 'checked');
  941. zoomCheckBox.defaultChecked = true;
  942. zoomCheckBox.style.marginLeft = '8px';
  943. div.appendChild(zoomCheckBox);
  944. mxUtils.write(div, mxResources.get('zoom') + ' ');
  945. var editCheckBox = document.createElement('input');
  946. editCheckBox.setAttribute('type', 'checkbox');
  947. editCheckBox.style.marginLeft = '8px';
  948. editCheckBox.setAttribute('title', window.location.href);
  949. div.appendChild(editCheckBox);
  950. mxUtils.write(div, mxResources.get('edit') + ' ');
  951. var editBlankCheckBox = document.createElement('input');
  952. editBlankCheckBox.setAttribute('type', 'checkbox');
  953. editBlankCheckBox.style.marginLeft = '8px';
  954. div.appendChild(editBlankCheckBox);
  955. mxUtils.write(div, mxResources.get('asNew') + ' ');
  956. mxUtils.br(div);
  957. var resizeCheckBox = document.createElement('input');
  958. resizeCheckBox.setAttribute('type', 'checkbox');
  959. resizeCheckBox.setAttribute('checked', 'checked');
  960. resizeCheckBox.defaultChecked = true;
  961. resizeCheckBox.style.marginLeft = '16px';
  962. div.appendChild(resizeCheckBox);
  963. mxUtils.write(div, mxResources.get('resize') + ' ');
  964. var fitCheckBox = document.createElement('input');
  965. fitCheckBox.setAttribute('type', 'checkbox');
  966. fitCheckBox.style.marginLeft = '8px';
  967. div.appendChild(fitCheckBox);
  968. mxUtils.write(div, mxResources.get('fit') + ' ');
  969. var embedCheckBox = document.createElement('input');
  970. embedCheckBox.setAttribute('type', 'checkbox');
  971. embedCheckBox.style.marginLeft = '8px';
  972. div.appendChild(embedCheckBox);
  973. mxUtils.write(div, mxResources.get('embed') + ' ');
  974. var node = null;
  975. var s = editorUi.getBasenames().join(';');
  976. var file = editorUi.getCurrentFile();
  977. function update()
  978. {
  979. var title = (file != null && file.getTitle() != null) ? file.getTitle() : this.defaultFilename;
  980. if (embedCheckBox.checked && urlInput.value != '')
  981. {
  982. var encUrl = encodeURIComponent(mxUtils.htmlEntities(urlInput.value));
  983. var gurl = 'https://www.draw.io/gadget.xml?type=4&diagram=' + encUrl;
  984. if (title != null)
  985. {
  986. gurl += '&title=' + encodeURIComponent(title);
  987. }
  988. if (s.length > 0)
  989. {
  990. gurl += '&s=' + s;
  991. }
  992. if (borderInput.value != '' && borderInput.value != '0')
  993. {
  994. gurl += '&border=' + borderInput.value;
  995. }
  996. if (heightInput.value != '')
  997. {
  998. gurl += '&height=' + heightInput.value;
  999. }
  1000. gurl += '&pan=' + ((panCheckBox.checked) ? '1': '0');
  1001. gurl += '&zoom=' + ((zoomCheckBox.checked) ? '1': '0');
  1002. gurl += '&fit=' + ((fitCheckBox.checked) ? '1': '0');
  1003. gurl += '&resize=' + ((resizeCheckBox.checked) ? '1': '0');
  1004. gurl += '&x0=' + Number(topInput.value);
  1005. gurl += '&y0=' + y0;
  1006. if (graph.mathEnabled)
  1007. {
  1008. gurl += '&math=1';
  1009. }
  1010. if (editBlankCheckBox.checked)
  1011. {
  1012. gurl += '&edit=_blank';
  1013. }
  1014. else if (editCheckBox.checked)
  1015. {
  1016. gurl += '&edit=' + encodeURIComponent(mxUtils.htmlEntities(window.location.href));
  1017. }
  1018. gadgetInput.value = gurl;
  1019. }
  1020. else if (file.constructor == DriveFile || file.constructor == DropboxFile)
  1021. {
  1022. var gurl = 'https://www.draw.io/gadget.xml?embed=0&diagram=';
  1023. if (urlInput.value != '')
  1024. {
  1025. gurl += encodeURIComponent(mxUtils.htmlEntities(urlInput.value)) + '&type=3';
  1026. }
  1027. else
  1028. {
  1029. gurl += file.getHash().substring(1);
  1030. if (file.constructor == DropboxFile)
  1031. {
  1032. gurl += '&type=2';
  1033. }
  1034. else
  1035. {
  1036. gurl += '&type=1';
  1037. }
  1038. }
  1039. if (title != null)
  1040. {
  1041. gurl += '&title=' + encodeURIComponent(title);
  1042. }
  1043. if (heightInput.value != '')
  1044. {
  1045. var h = parseInt(heightInput.value) + parseInt(topInput.value);
  1046. gurl += '&height=' + h;
  1047. }
  1048. gadgetInput.value = gurl;
  1049. }
  1050. else
  1051. {
  1052. gadgetInput.value = '';
  1053. }
  1054. };
  1055. mxEvent.addListener(panCheckBox, 'change', update);
  1056. mxEvent.addListener(zoomCheckBox, 'change', update);
  1057. mxEvent.addListener(resizeCheckBox, 'change', update);
  1058. mxEvent.addListener(fitCheckBox, 'change', update);
  1059. mxEvent.addListener(editCheckBox, 'change', update);
  1060. mxEvent.addListener(editBlankCheckBox, 'change', update);
  1061. mxEvent.addListener(embedCheckBox, 'change', update);
  1062. mxEvent.addListener(heightInput, 'change', update);
  1063. mxEvent.addListener(topInput, 'change', update);
  1064. mxEvent.addListener(borderInput, 'change', update);
  1065. mxEvent.addListener(urlInput, 'change', update);
  1066. update();
  1067. mxEvent.addListener(gadgetInput, 'click', function()
  1068. {
  1069. gadgetInput.focus();
  1070. if (mxClient.IS_GC || mxClient.IS_FF || document.documentMode >= 5)
  1071. {
  1072. gadgetInput.select();
  1073. }
  1074. else
  1075. {
  1076. document.execCommand('selectAll', false, null);
  1077. }
  1078. });
  1079. var buttons = document.createElement('div');
  1080. buttons.style.paddingTop = '12px';
  1081. buttons.style.textAlign = 'right';
  1082. var closeBtn = mxUtils.button(mxResources.get('close'), function()
  1083. {
  1084. editorUi.hideDialog();
  1085. });
  1086. closeBtn.className = 'geBtn gePrimaryBtn';
  1087. buttons.appendChild(closeBtn);
  1088. div.appendChild(buttons);
  1089. this.container = div;
  1090. };
  1091. /**
  1092. * Constructs a new parse dialog.
  1093. */
  1094. var CreateGraphDialog = function(editorUi, title, type)
  1095. {
  1096. var div = document.createElement('div');
  1097. div.style.textAlign = 'right';
  1098. this.init = function()
  1099. {
  1100. var container = document.createElement('div');
  1101. container.style.position = 'relative';
  1102. container.style.border = '1px solid gray';
  1103. container.style.boxSizing = 'border-box';
  1104. container.style.width = '100%';
  1105. container.style.height = '360px';
  1106. container.style.overflow = 'hidden';
  1107. container.style.marginBottom = '16px';
  1108. mxEvent.disableContextMenu(container);
  1109. div.appendChild(container);
  1110. var graph = new Graph(container);
  1111. graph.setCellsCloneable(true);
  1112. graph.setPanning(true);
  1113. graph.setAllowDanglingEdges(false);
  1114. graph.connectionHandler.select = false;
  1115. graph.view.setTranslate(20, 20);
  1116. graph.border = 20;
  1117. graph.panningHandler.useLeftButtonForPanning = true;
  1118. // Fixes in-place editor position
  1119. if (mxClient.IS_SVG && graph.view.getDrawPane() != null)
  1120. {
  1121. var root = graph.view.getDrawPane().ownerSVGElement;
  1122. if (root != null)
  1123. {
  1124. root.style.position = 'absolute';
  1125. }
  1126. }
  1127. var vertexStyle = 'rounded=1;';
  1128. var edgeStyle = 'curved=1;';
  1129. var startStyle = 'ellipse';
  1130. // FIXME: Does not work in iPad
  1131. graph.cellRenderer.installCellOverlayListeners = function(state, overlay, shape)
  1132. {
  1133. mxCellRenderer.prototype.installCellOverlayListeners.apply(this, arguments);
  1134. mxEvent.addListener(shape.node, (mxClient.IS_POINTER) ? 'pointerdown' : 'mousedown', function (evt)
  1135. {
  1136. overlay.fireEvent(new mxEventObject('pointerdown', 'event', evt, 'state', state));
  1137. });
  1138. if (!mxClient.IS_POINTER && mxClient.IS_TOUCH)
  1139. {
  1140. mxEvent.addListener(shape.node, 'touchstart', function (evt)
  1141. {
  1142. overlay.fireEvent(new mxEventObject('pointerdown', 'event', evt, 'state', state));
  1143. });
  1144. }
  1145. };
  1146. graph.getAllConnectionConstraints = function()
  1147. {
  1148. return null;
  1149. };
  1150. // Keeps highlight behind overlays
  1151. graph.connectionHandler.marker.highlight.keepOnTop = false;
  1152. graph.connectionHandler.createEdgeState = function(me)
  1153. {
  1154. var edge = graph.createEdge(null, null, null, null, null, edgeStyle);
  1155. return new mxCellState(this.graph.view, edge, this.graph.getCellStyle(edge));
  1156. };
  1157. // Gets the default parent for inserting new cells. This
  1158. // is normally the first child of the root (ie. layer 0).
  1159. var parent = graph.getDefaultParent();
  1160. var addOverlay = mxUtils.bind(this, function(cell)
  1161. {
  1162. // Creates a new overlay with an image and a tooltip
  1163. var overlay = new mxCellOverlay(this.connectImage, 'Add outgoing');
  1164. overlay.cursor = 'hand';
  1165. // Installs a handler for clicks on the overlay
  1166. overlay.addListener(mxEvent.CLICK, function(sender, evt2)
  1167. {
  1168. // TODO: Add menu for picking next shape
  1169. graph.connectionHandler.reset();
  1170. graph.clearSelection();
  1171. var geo = graph.getCellGeometry(cell);
  1172. var v2;
  1173. executeLayout(function()
  1174. {
  1175. v2 = graph.insertVertex(parent, null, 'Entry', geo.x, geo.y, 80, 30, vertexStyle);
  1176. addOverlay(v2);
  1177. graph.view.refresh(v2);
  1178. graph.insertEdge(parent, null, '', cell, v2, edgeStyle);
  1179. }, function()
  1180. {
  1181. graph.scrollCellToVisible(v2);
  1182. });
  1183. });
  1184. // FIXME: Does not work in iPad (inserts loop)
  1185. overlay.addListener('pointerdown', function(sender, eo)
  1186. {
  1187. var evt2 = eo.getProperty('event');
  1188. var state = eo.getProperty('state');
  1189. graph.popupMenuHandler.hideMenu();
  1190. graph.stopEditing(false);
  1191. var pt = mxUtils.convertPoint(graph.container,
  1192. mxEvent.getClientX(evt2), mxEvent.getClientY(evt2));
  1193. graph.connectionHandler.start(state, pt.x, pt.y);
  1194. graph.isMouseDown = true;
  1195. graph.isMouseTrigger = mxEvent.isMouseEvent(evt2);
  1196. mxEvent.consume(evt2);
  1197. });
  1198. // Sets the overlay for the cell in the graph
  1199. graph.addCellOverlay(cell, overlay);
  1200. });
  1201. // Adds cells to the model in a single step
  1202. graph.getModel().beginUpdate();
  1203. var v1;
  1204. try
  1205. {
  1206. v1 = graph.insertVertex(parent, null, 'Start', 0, 0, 80, 30, startStyle);
  1207. addOverlay(v1);
  1208. }
  1209. finally
  1210. {
  1211. // Updates the display
  1212. graph.getModel().endUpdate();
  1213. }
  1214. var layout;
  1215. if (type == 'horizontalTree')
  1216. {
  1217. layout = new mxCompactTreeLayout(graph);
  1218. layout.edgeRouting = false;
  1219. layout.levelDistance = 30;
  1220. layout.sortEdges = true;
  1221. edgeStyle = 'edgeStyle=elbowEdgeStyle;elbow=horizontal;';
  1222. }
  1223. else if (type == 'verticalTree')
  1224. {
  1225. layout = new mxCompactTreeLayout(graph, false);
  1226. layout.edgeRouting = false;
  1227. layout.levelDistance = 30;
  1228. layout.sortEdges = true;
  1229. edgeStyle = 'edgeStyle=elbowEdgeStyle;elbow=vertical;';
  1230. }
  1231. else if (type == 'radialTree')
  1232. {
  1233. layout = new mxRadialTreeLayout(graph, false);
  1234. layout.edgeRouting = false;
  1235. layout.levelDistance = 80;
  1236. }
  1237. else if (type == 'verticalFlow')
  1238. {
  1239. layout = new mxHierarchicalLayout(graph, mxConstants.DIRECTION_NORTH);
  1240. }
  1241. else if (type == 'horizontalFlow')
  1242. {
  1243. layout = new mxHierarchicalLayout(graph, mxConstants.DIRECTION_WEST);
  1244. }
  1245. else if (type == 'circle')
  1246. {
  1247. layout = new mxCircleLayout(graph);
  1248. }
  1249. else
  1250. {
  1251. layout = new mxFastOrganicLayout(graph, false);
  1252. layout.forceConstant = 80;
  1253. }
  1254. if (layout != null)
  1255. {
  1256. var executeLayout = function(change, post)
  1257. {
  1258. graph.getModel().beginUpdate();
  1259. try
  1260. {
  1261. if (change != null)
  1262. {
  1263. change();
  1264. }
  1265. layout.execute(graph.getDefaultParent(), v1);
  1266. }
  1267. catch (e)
  1268. {
  1269. throw e;
  1270. }
  1271. finally
  1272. {
  1273. // New API for animating graph layout results asynchronously
  1274. var morph = new mxMorphing(graph);
  1275. morph.addListener(mxEvent.DONE, mxUtils.bind(this, function()
  1276. {
  1277. graph.getModel().endUpdate();
  1278. if (post != null)
  1279. {
  1280. post();
  1281. }
  1282. }));
  1283. morph.startAnimation();
  1284. }
  1285. };
  1286. var edgeHandleConnect = mxEdgeHandler.prototype.connect;
  1287. mxEdgeHandler.prototype.connect = function(edge, terminal, isSource, isClone, me)
  1288. {
  1289. edgeHandleConnect.apply(this, arguments);
  1290. executeLayout();
  1291. };
  1292. graph.resizeCell = function()
  1293. {
  1294. mxGraph.prototype.resizeCell.apply(this, arguments);
  1295. executeLayout();
  1296. };
  1297. graph.connectionHandler.addListener(mxEvent.CONNECT, function()
  1298. {
  1299. executeLayout();
  1300. });
  1301. }
  1302. var cancelBtn = mxUtils.button(mxResources.get('close'), function()
  1303. {
  1304. editorUi.confirm(mxResources.get('areYouSure'), function()
  1305. {
  1306. editorUi.hideDialog();
  1307. });
  1308. })
  1309. cancelBtn.className = 'geBtn';
  1310. if (editorUi.editor.cancelFirst)
  1311. {
  1312. div.appendChild(cancelBtn);
  1313. }
  1314. var okBtn = mxUtils.button(mxResources.get('insert'), function(evt)
  1315. {
  1316. graph.clearCellOverlays();
  1317. var cells = graph.getModel().getChildren(graph.getDefaultParent());
  1318. var pt = (mxEvent.isAltDown(evt)) ?
  1319. editorUi.editor.graph.getFreeInsertPoint() :
  1320. editorUi.editor.graph.getCenterInsertPoint(
  1321. graph.getBoundingBoxFromGeometry(cells, true));
  1322. cells = editorUi.editor.graph.importCells(cells, pt.x, pt.y);
  1323. var view = editorUi.editor.graph.view;
  1324. var temp = view.getBounds(cells);
  1325. if (temp != null)
  1326. {
  1327. temp.x -= view.translate.x;
  1328. temp.y -= view.translate.y;
  1329. editorUi.editor.graph.scrollRectToVisible(temp);
  1330. editorUi.editor.graph.setSelectionCells(cells);
  1331. }
  1332. editorUi.hideDialog();
  1333. });
  1334. div.appendChild(okBtn);
  1335. okBtn.className = 'geBtn gePrimaryBtn';
  1336. if (!editorUi.editor.cancelFirst)
  1337. {
  1338. div.appendChild(cancelBtn);
  1339. }
  1340. this.graph = graph;
  1341. };
  1342. this.container = div;
  1343. };
  1344. /**
  1345. *
  1346. */
  1347. CreateGraphDialog.prototype.connectImage = new mxImage((mxClient.IS_SVG) ? 'data:image/png;base64,iVBORw0KGgoAAAANSUhEUgAAABoAAAAaCAYAAACpSkzOAAAAGXRFWHRTb2Z0d2FyZQBBZG9iZSBJbWFnZVJlYWR5ccllPAAAAyJpVFh0WE1MOmNvbS5hZG9iZS54bXAAAAAAADw/eHBhY2tldCBiZWdpbj0i77u/IiBpZD0iVzVNME1wQ2VoaUh6cmVTek5UY3prYzlkIj8+IDx4OnhtcG1ldGEgeG1sbnM6eD0iYWRvYmU6bnM6bWV0YS8iIHg6eG1wdGs9IkFkb2JlIFhNUCBDb3JlIDUuMC1jMDYwIDYxLjEzNDc3NywgMjAxMC8wMi8xMi0xNzozMjowMCAgICAgICAgIj4gPHJkZjpSREYgeG1sbnM6cmRmPSJodHRwOi8vd3d3LnczLm9yZy8xOTk5LzAyLzIyLXJkZi1zeW50YXgtbnMjIj4gPHJkZjpEZXNjcmlwdGlvbiByZGY6YWJvdXQ9IiIgeG1sbnM6eG1wPSJodHRwOi8vbnMuYWRvYmUuY29tL3hhcC8xLjAvIiB4bWxuczp4bXBNTT0iaHR0cDovL25zLmFkb2JlLmNvbS94YXAvMS4wL21tLyIgeG1sbnM6c3RSZWY9Imh0dHA6Ly9ucy5hZG9iZS5jb20veGFwLzEuMC9zVHlwZS9SZXNvdXJjZVJlZiMiIHhtcDpDcmVhdG9yVG9vbD0iQWRvYmUgUGhvdG9zaG9wIENTNSBNYWNpbnRvc2giIHhtcE1NOkluc3RhbmNlSUQ9InhtcC5paWQ6RjQ3OTk0QjMyRDcyMTFFNThGQThGNDVBMjNBMjFDMzkiIHhtcE1NOkRvY3VtZW50SUQ9InhtcC5kaWQ6RjQ3OTk0QjQyRDcyMTFFNThGQThGNDVBMjNBMjFDMzkiPiA8eG1wTU06RGVyaXZlZEZyb20gc3RSZWY6aW5zdGFuY2VJRD0ieG1wLmlpZDoyRjA0N0I2MjJENzExMUU1OEZBOEY0NUEyM0EyMUMzOSIgc3RSZWY6ZG9jdW1lbnRJRD0ieG1wLmRpZDpGNDc5OTRCMjJENzIxMUU1OEZBOEY0NUEyM0EyMUMzOSIvPiA8L3JkZjpEZXNjcmlwdGlvbj4gPC9yZGY6UkRGPiA8L3g6eG1wbWV0YT4gPD94cGFja2V0IGVuZD0iciI/PjIf+MgAAATlSURBVHjanFZraFxFFD735u4ru3ls0yZG26ShgmJoKK1J2vhIYzBgRdtIURHyw1hQUH9IxIgI2h8iCEUF/1RRlNQYCsYfCTHVhiTtNolpZCEStqSC22xIsrs1bDfu7t37Gs/cO3Ozxs1DBw73zpk555vzmHNGgJ0NYatFgmNLYUHYUoHASMz5ijmgVLmxgfKCUiBxC4ACJAeSG8nb1dVVOTc3dyoSibwWDofPBIPBJzo7O8vpGtvjpDICGztxkciECpF2LS0tvZtOpwNkk5FKpcYXFxffwL1+JuPgllPj8nk1F6RoaGjoKCqZ5ApljZDZO4SMRA0SuG2QUJIQRV8HxMOM9vf3H0ZZH9Nhg20MMl2QkFwjIyNHWlpahtADnuUMwLcRHX5aNSBjCJYEsSSLUeLEbhGe3ytCmQtA1/XY+Pj46dbW1iDuyCJp9BC5ycBj4hoeHq5ra2sbw0Xn1ZgBZ+dVkA1Lc+6p0Ck2p0QS4Ox9EhwpEylYcmBg4LH29vYQLilIOt0u5FhDfevNZDI/u93uw6PLOrwTUtjxrbPYbhD42WgMrF8JmR894ICmCgnQjVe8Xu8pXEkzMJKbuo5oNPomBbm1ZsD7s2kwFA1JZ6QBUXWT1nmGNc/qoMgavDcrQzxjQGFh4aOYIJ0sFAXcEtui4uLiVjr5KpSBVFYDDZVrWUaKRRWSAYeK0fmKykgDXbVoNaPChRuyqdDv97czL5nXxQbq6empQmsaklkDBiNpSwFVrmr2P6UyicD5piI4f8wHh0oEm8/p4h8pyGiEWvVQd3e3nxtjAzU1NR2jP7NRBWQ8GbdEzzJAmc0V3RR4cI8Dvmwuhc8fKUFA0d6/ltHg5p+Kuaejo6OeY0jcNJ/PV00ZS0nFUoZRvvFS1bZFsKHCCQ2Pl8H0chY+C96B6ZUsrCQ1qKtwQVFRURW/QhIXMAzDPAZ6BgOr8tTa8dDxCmiYGApaJbJMxSzV+brE8pdgWkcpY5dbMF1AR9XH8/xu2ilef48bvn92n82ZwHh+8ssqTEXS9p7dHisiiURikd8PbpExNTU1UVNTA3V3Y7lC16n0gpB/NwpNcZjfa7dScC4Qh0kOQCwnlEgi3F/hMVl9fX0zvKrzSk2lfXjRhj0eT/2rvWG4+Pta3oJY7XfC3hInXAv/ldeFLx8shQ+eqQL0UAAz7ylkpej5eNZRVBWL6BU6ef14OYiY1oqyTtmsavr/5koaRucT1pzx+ZpL1+GV5nLutksUgIcmtwTRiuuVZXnU5XId7A2swJkfFsymRWC91hHg1Viw6x23+7vn9sPJ+j20BE1hCXqSWaNSQ8ScbknRZWxub1PGCw/fBV+c3AeijlUbY5bBjEqr9GuYZP4jP41WudGSC6erTRCqdGZm5i1WvXWeDHnbBCZGc2Nj4wBl/hZOwrmBBfgmlID1HmGJutHaF+tKoevp/XCgstDkjo2NtWKLuc6AVN4mNjY+s1XQxoenOoFuDPHGtnRbJj9ej5GvL0dI7+giuRyMk1giazc+DP6vgUDgOJVlOv7R+PJ12QIeL6SyeDz+Kfp8ZrNWjgDTsVjsQ7qXyTjztXJhm9ePxFLfMTg4eG9tbe1RTP9KFFYQfHliYmIS69kCC7jKYmKwxxD5P88tkVkqbPPcIps9t4T/+HjcuJ/s5BFJgf4WYABCtxGuxIZ90gAAAABJRU5ErkJggg==' :
  1348. IMAGE_PATH + '/handle-connect.png', 26, 26);
  1349. /**
  1350. * Constructs a new parse dialog.
  1351. */
  1352. var BackgroundImageDialog = function(editorUi, applyFn, img, color, showColor)
  1353. {
  1354. var graph = editorUi.editor.graph;
  1355. var div = document.createElement('div');
  1356. div.style.whiteSpace = 'nowrap';
  1357. var h3 = document.createElement('h2');
  1358. mxUtils.write(h3, mxResources.get('background'));
  1359. h3.style.marginTop = '0px';
  1360. div.appendChild(h3);
  1361. var isPageLink = img != null && img.originalSrc != null;
  1362. var pageFound = false;
  1363. var urlRadio = document.createElement('input');
  1364. urlRadio.style.cssText = 'margin-right:8px;margin-bottom:8px;';
  1365. urlRadio.setAttribute('value', 'url');
  1366. urlRadio.setAttribute('type', 'radio');
  1367. urlRadio.setAttribute('name', 'geBackgroundImageDialogOption');
  1368. var pageRadio = document.createElement('input');
  1369. pageRadio.style.cssText = 'margin-right:8px;margin-bottom:8px;';
  1370. pageRadio.setAttribute('value', 'url');
  1371. pageRadio.setAttribute('type', 'radio');
  1372. pageRadio.setAttribute('name', 'geBackgroundImageDialogOption');
  1373. var urlInput = document.createElement('input');
  1374. urlInput.setAttribute('type', 'text');
  1375. urlInput.style.marginBottom = '8px';
  1376. urlInput.style.width = '360px';
  1377. urlInput.value = (isPageLink || img == null) ? '' : img.src;
  1378. var pageSelect = document.createElement('select');
  1379. pageSelect.style.width = '360px';
  1380. if (editorUi.pages != null)
  1381. {
  1382. for (var i = 0; i < editorUi.pages.length; i++)
  1383. {
  1384. var pageOption = document.createElement('option');
  1385. mxUtils.write(pageOption, editorUi.pages[i].getName() ||
  1386. mxResources.get('pageWithNumber', [i + 1]));
  1387. pageOption.setAttribute('value', 'data:page/id,' +
  1388. editorUi.pages[i].getId());
  1389. if (editorUi.pages[i] == editorUi.currentPage)
  1390. {
  1391. pageOption.setAttribute('disabled', 'disabled');
  1392. }
  1393. if (img != null && img.originalSrc == pageOption.getAttribute('value'))
  1394. {
  1395. pageOption.setAttribute('selected', 'selected');
  1396. pageFound = true;
  1397. }
  1398. pageSelect.appendChild(pageOption);
  1399. }
  1400. }
  1401. if (!isPageLink && (editorUi.pages == null || editorUi.pages.length == 1))
  1402. {
  1403. urlRadio.style.display = 'none';
  1404. pageRadio.style.display = 'none';
  1405. pageSelect.style.display = 'none';
  1406. }
  1407. var notFoundOption = document.createElement('option');
  1408. var resetting = false;
  1409. var ignoreEvt = false;
  1410. var urlChanged = function(evt, done)
  1411. {
  1412. // Skips blur event if called from apply button
  1413. if (!resetting && (evt == null || !ignoreEvt))
  1414. {
  1415. if (pageRadio.checked)
  1416. {
  1417. if (done != null)
  1418. {
  1419. done((notFoundOption.selected) ? null : pageSelect.value);
  1420. }
  1421. }
  1422. else if (urlInput.value != '' && !editorUi.isOffline())
  1423. {
  1424. urlInput.value = mxUtils.trim(urlInput.value);
  1425. editorUi.loadImage(urlInput.value, function(img)
  1426. {
  1427. widthInput.value = img.width;
  1428. heightInput.value = img.height;
  1429. if (done != null)
  1430. {
  1431. done(urlInput.value);
  1432. }
  1433. }, function()
  1434. {
  1435. editorUi.showError(mxResources.get('error'), mxResources.get('fileNotFound'), mxResources.get('ok'));
  1436. widthInput.value = '';
  1437. heightInput.value = '';
  1438. if (done != null)
  1439. {
  1440. done(null);
  1441. }
  1442. });
  1443. }
  1444. else
  1445. {
  1446. widthInput.value = '';
  1447. heightInput.value = '';
  1448. if (done != null)
  1449. {
  1450. done('');
  1451. }
  1452. }
  1453. }
  1454. };
  1455. var openFiles = mxUtils.bind(this, function(files)
  1456. {
  1457. editorUi.importFiles(files, 0, 0, editorUi.maxBackgroundSize, function(data, mimeType, x, y, w, h)
  1458. {
  1459. urlInput.value = data;
  1460. urlChanged();
  1461. urlInput.focus();
  1462. }, function()
  1463. {
  1464. // No post processing
  1465. }, function(file)
  1466. {
  1467. // Handles only images
  1468. return file.type.substring(0, 6) == 'image/';
  1469. }, function(queue)
  1470. {
  1471. // Invokes elements of queue in order
  1472. for (var i = 0; i < queue.length; i++)
  1473. {
  1474. queue[i]();
  1475. }
  1476. }, true, editorUi.maxBackgroundBytes, editorUi.maxBackgroundBytes, true);
  1477. });
  1478. this.init = function()
  1479. {
  1480. if (isPageLink)
  1481. {
  1482. pageSelect.focus();
  1483. }
  1484. else
  1485. {
  1486. urlInput.focus();
  1487. }
  1488. mxEvent.addListener(pageSelect, 'focus', function()
  1489. {
  1490. urlRadio.removeAttribute('checked');
  1491. pageRadio.setAttribute('checked', 'checked');
  1492. pageRadio.checked = true;
  1493. });
  1494. mxEvent.addListener(urlInput, 'focus', function()
  1495. {
  1496. pageRadio.removeAttribute('checked');
  1497. urlRadio.setAttribute('checked', 'checked');
  1498. urlRadio.checked = true;
  1499. });
  1500. // Installs drag and drop handler for local images and links
  1501. if (Graph.fileSupport)
  1502. {
  1503. urlInput.setAttribute('placeholder', mxResources.get('dragImagesHere'));
  1504. // Setup the dnd listeners
  1505. var dlg = div.parentNode;
  1506. var dropElt = null;
  1507. mxEvent.addListener(dlg, 'dragleave', function(evt)
  1508. {
  1509. if (dropElt != null)
  1510. {
  1511. dropElt.parentNode.removeChild(dropElt);
  1512. dropElt = null;
  1513. }
  1514. evt.stopPropagation();
  1515. evt.preventDefault();
  1516. });
  1517. mxEvent.addListener(dlg, 'dragover', mxUtils.bind(this, function(evt)
  1518. {
  1519. // IE 10 does not implement pointer-events so it can't have a drop highlight
  1520. if (dropElt == null && (!mxClient.IS_IE || document.documentMode > 10))
  1521. {
  1522. dropElt = editorUi.highlightElement(dlg);
  1523. }
  1524. evt.stopPropagation();
  1525. evt.preventDefault();
  1526. }));
  1527. mxEvent.addListener(dlg, 'drop', mxUtils.bind(this, function(evt)
  1528. {
  1529. if (dropElt != null)
  1530. {
  1531. dropElt.parentNode.removeChild(dropElt);
  1532. dropElt = null;
  1533. }
  1534. if (evt.dataTransfer.files.length > 0)
  1535. {
  1536. openFiles(evt.dataTransfer.files);
  1537. }
  1538. else if (mxUtils.indexOf(evt.dataTransfer.types, 'text/uri-list') >= 0)
  1539. {
  1540. var uri = evt.dataTransfer.getData('text/uri-list');
  1541. if ((/\.(gif|jpg|jpeg|tiff|png|svg)$/i).test(uri))
  1542. {
  1543. urlInput.value = decodeURIComponent(uri);
  1544. urlChanged();
  1545. }
  1546. }
  1547. evt.stopPropagation();
  1548. evt.preventDefault();
  1549. }), false);
  1550. }
  1551. };
  1552. div.appendChild(urlRadio);
  1553. div.appendChild(urlInput);
  1554. mxUtils.br(div);
  1555. var span = document.createElement('span');
  1556. span.style.marginLeft = '30px';
  1557. mxUtils.write(span, mxResources.get('width') + ':');
  1558. div.appendChild(span);
  1559. var widthInput = document.createElement('input');
  1560. widthInput.setAttribute('type', 'text');
  1561. widthInput.style.width = '60px';
  1562. widthInput.style.marginLeft = '8px';
  1563. widthInput.style.marginRight = '16px';
  1564. widthInput.value = (img != null && !isPageLink) ? img.width : '';
  1565. div.appendChild(widthInput);
  1566. mxUtils.write(div, mxResources.get('height') + ':');
  1567. var heightInput = document.createElement('input');
  1568. heightInput.setAttribute('type', 'text');
  1569. heightInput.style.width = '60px';
  1570. heightInput.style.marginLeft = '8px';
  1571. heightInput.style.marginRight = '16px';
  1572. heightInput.value = (img != null && !isPageLink) ? img.height : '';
  1573. div.appendChild(heightInput);
  1574. mxUtils.br(div);
  1575. mxUtils.br(div);
  1576. mxEvent.addListener(urlInput, 'change', urlChanged);
  1577. ImageDialog.filePicked = function(data)
  1578. {
  1579. if (data.action == google.picker.Action.PICKED)
  1580. {
  1581. if (data.docs[0].thumbnails != null)
  1582. {
  1583. var thumb = data.docs[0].thumbnails[data.docs[0].thumbnails.length - 1];
  1584. if (thumb != null)
  1585. {
  1586. urlInput.value = thumb.url;
  1587. urlChanged();
  1588. }
  1589. }
  1590. }
  1591. urlInput.focus();
  1592. };
  1593. div.appendChild(pageRadio);
  1594. div.appendChild(pageSelect);
  1595. mxUtils.br(div);
  1596. mxUtils.br(div);
  1597. if (isPageLink)
  1598. {
  1599. pageRadio.setAttribute('checked', 'checked');
  1600. pageRadio.checked = true;
  1601. }
  1602. else
  1603. {
  1604. urlRadio.setAttribute('checked', 'checked');
  1605. urlRadio.checked = true;
  1606. }
  1607. if (!pageFound && pageRadio.checked)
  1608. {
  1609. mxUtils.write(notFoundOption, mxResources.get('pageNotFound'));
  1610. notFoundOption.setAttribute('disabled', 'disabled');
  1611. notFoundOption.setAttribute('selected', 'selected');
  1612. notFoundOption.setAttribute('value', 'pageNotFound');
  1613. pageSelect.appendChild(notFoundOption);
  1614. mxEvent.addListener(pageSelect, 'change', function()
  1615. {
  1616. if (notFoundOption.parentNode != null && !notFoundOption.selected)
  1617. {
  1618. notFoundOption.parentNode.removeChild(notFoundOption);
  1619. }
  1620. });
  1621. }
  1622. var bgDiv = document.createElement('div');
  1623. bgDiv.style.display = (showColor) ? 'inline-flex' : 'none';
  1624. bgDiv.style.alignItems = 'center';
  1625. bgDiv.style.cursor = 'default';
  1626. bgDiv.style.minWidth = '40%';
  1627. bgDiv.style.height = '20px';
  1628. var cb = document.createElement('input');
  1629. cb.setAttribute('type', 'checkbox');
  1630. cb.style.margin = '0px 10px 0px 4px';
  1631. cb.style.verticalAlign = 'bottom';
  1632. cb.defaultChecked = color != mxConstants.NONE && color != null;
  1633. cb.checked = cb.defaultChecked;
  1634. bgDiv.appendChild(cb);
  1635. mxUtils.write(bgDiv, mxResources.get('fillColor'));
  1636. var shadowDiv = bgDiv.cloneNode(false);
  1637. var shadow = document.createElement('input');
  1638. shadow.setAttribute('type', 'checkbox');
  1639. shadow.style.margin = '0px 10px 0px 30px';
  1640. shadow.style.verticalAlign = 'bottom';
  1641. shadow.defaultChecked = graph.shadowVisible;
  1642. shadow.checked = shadow.defaultChecked;
  1643. shadowDiv.appendChild(shadow);
  1644. mxUtils.write(shadowDiv, mxResources.get('shadow'));
  1645. if (!mxClient.IS_SVG || mxClient.IS_SF)
  1646. {
  1647. shadow.setAttribute('disabled', 'disabled');
  1648. }
  1649. mxEvent.addListener(shadowDiv, 'click', function(evt)
  1650. {
  1651. if (mxEvent.getSource(evt) != shadow)
  1652. {
  1653. shadow.checked = !shadow.checked;
  1654. }
  1655. });
  1656. // TODO: Move createColorButton to editorUi
  1657. var backgroundButton = document.createElement('button');
  1658. backgroundButton.style.width = '36px';
  1659. backgroundButton.style.height = '18px';
  1660. backgroundButton.style.cursor = 'pointer';
  1661. backgroundButton.style.marginLeft = '10px';
  1662. backgroundButton.style.backgroundPosition = 'center center';
  1663. backgroundButton.style.backgroundRepeat = 'no-repeat';
  1664. backgroundButton.style.verticalAlign = 'bottom';
  1665. backgroundButton.className = 'geColorBtn';
  1666. var newBackgroundColor = color;
  1667. function updateBackgroundColor()
  1668. {
  1669. if (newBackgroundColor == null || newBackgroundColor == mxConstants.NONE)
  1670. {
  1671. backgroundButton.style.display = 'none';
  1672. cb.checked = false;
  1673. }
  1674. else
  1675. {
  1676. backgroundButton.style.backgroundColor = newBackgroundColor;
  1677. backgroundButton.style.display = '';
  1678. cb.checked = true;
  1679. }
  1680. };
  1681. updateBackgroundColor();
  1682. mxEvent.addListener(bgDiv, 'click', function(evt)
  1683. {
  1684. if (mxEvent.getSource(evt) != cb)
  1685. {
  1686. cb.checked = !cb.checked;
  1687. }
  1688. if (cb.checked)
  1689. {
  1690. newBackgroundColor = '#ffffff';
  1691. }
  1692. else
  1693. {
  1694. newBackgroundColor = null;
  1695. }
  1696. updateBackgroundColor();
  1697. });
  1698. mxEvent.addListener(backgroundButton, 'click', function(evt)
  1699. {
  1700. editorUi.pickColor(newBackgroundColor || 'none', function(color)
  1701. {
  1702. newBackgroundColor = color;
  1703. updateBackgroundColor();
  1704. });
  1705. mxEvent.consume(evt);
  1706. });
  1707. bgDiv.appendChild(backgroundButton);
  1708. div.appendChild(bgDiv);
  1709. div.appendChild(shadowDiv);
  1710. mxUtils.br(div);
  1711. var btns = document.createElement('div');
  1712. btns.style.marginTop = '30px';
  1713. btns.style.textAlign = 'right';
  1714. var cancelBtn = mxUtils.button(mxResources.get('cancel'), function()
  1715. {
  1716. resetting = true;
  1717. editorUi.hideDialog();
  1718. });
  1719. cancelBtn.className = 'geBtn';
  1720. if (editorUi.editor.cancelFirst)
  1721. {
  1722. btns.appendChild(cancelBtn);
  1723. }
  1724. var resetBtn = mxUtils.button(mxResources.get('reset'), function()
  1725. {
  1726. urlInput.value = '';
  1727. widthInput.value = '';
  1728. heightInput.value = '';
  1729. urlRadio.checked = true;
  1730. newBackgroundColor = mxConstants.NONE;
  1731. updateBackgroundColor();
  1732. resetting = false;
  1733. });
  1734. mxEvent.addGestureListeners(resetBtn, function()
  1735. {
  1736. // Blocks processing a image URL while clicking reset
  1737. resetting = true;
  1738. });
  1739. resetBtn.className = 'geBtn';
  1740. resetBtn.width = '100';
  1741. btns.appendChild(resetBtn);
  1742. if (Graph.fileSupport)
  1743. {
  1744. var fileInput = document.createElement('input');
  1745. fileInput.setAttribute('multiple', 'multiple');
  1746. fileInput.setAttribute('type', 'file');
  1747. mxEvent.addListener(fileInput, 'change', function(evt)
  1748. {
  1749. if (fileInput.files != null)
  1750. {
  1751. openFiles(fileInput.files);
  1752. // Resets input to force change event for same file (type reset required for IE)
  1753. fileInput.type = '';
  1754. fileInput.type = 'file';
  1755. fileInput.value = '';
  1756. }
  1757. });
  1758. fileInput.style.display = 'none';
  1759. div.appendChild(fileInput);
  1760. var btn = mxUtils.button(mxResources.get('open'), function()
  1761. {
  1762. fileInput.click();
  1763. });
  1764. btn.className = 'geBtn';
  1765. btns.appendChild(btn);
  1766. }
  1767. applyBtn = mxUtils.button(mxResources.get('apply'), function()
  1768. {
  1769. editorUi.hideDialog();
  1770. urlChanged(null, function(url)
  1771. {
  1772. applyFn((url != '' && url != null) ? new mxImage(url, widthInput.value,
  1773. heightInput.value) : null, url == null, newBackgroundColor,
  1774. (!mxClient.IS_SVG || mxClient.IS_SF) ? null : shadow.checked);
  1775. });
  1776. });
  1777. mxEvent.addGestureListeners(applyBtn, function()
  1778. {
  1779. ignoreEvt = true;
  1780. });
  1781. applyBtn.className = 'geBtn gePrimaryBtn';
  1782. btns.appendChild(applyBtn);
  1783. if (!editorUi.editor.cancelFirst)
  1784. {
  1785. btns.appendChild(cancelBtn);
  1786. }
  1787. div.appendChild(btns);
  1788. this.container = div;
  1789. };
  1790. /**
  1791. * Constructs a new parse dialog.
  1792. */
  1793. var ParseDialog = function(editorUi, title, defaultType)
  1794. {
  1795. var plantUmlExample = '@startuml\nskinparam shadowing false\nAlice -> Bob: Authentication Request\nBob --> Alice: Authentication Response\n\n' +
  1796. 'Alice -> Bob: Another authentication Request\nAlice <-- Bob: Another authentication Response\n@enduml';
  1797. var insertPoint = editorUi.editor.graph.getFreeInsertPoint();
  1798. function parse(text, type, evt)
  1799. {
  1800. var lines = text.split('\n');
  1801. if (type == 'plantUmlPng' || type == 'plantUmlSvg' || type == 'plantUmlTxt')
  1802. {
  1803. if (editorUi.spinner.spin(document.body, mxResources.get('inserting')))
  1804. {
  1805. var graph = editorUi.editor.graph;
  1806. var format = (type == 'plantUmlTxt') ? 'txt' :
  1807. ((type == 'plantUmlPng') ? 'png' : 'svg');
  1808. function insertPlantUmlImage(text, format, data, w, h)
  1809. {
  1810. insertPoint = (mxEvent.isAltDown(evt)) ? insertPoint : graph.getCenterInsertPoint(new mxRectangle(0, 0, w, h));
  1811. var cell = null;
  1812. graph.getModel().beginUpdate();
  1813. try
  1814. {
  1815. cell = (format == 'txt') ?
  1816. editorUi.insertAsPreText(data, insertPoint.x, insertPoint.y) :
  1817. graph.insertVertex(null, null, null, insertPoint.x, insertPoint.y,
  1818. w, h, 'shape=image;noLabel=1;verticalAlign=top;aspect=fixed;imageAspect=0;' +
  1819. 'image=' + editorUi.convertDataUri(data) + ';')
  1820. graph.setAttributeForCell(cell, 'plantUmlData',
  1821. JSON.stringify({data: text, format: format},
  1822. null, 2));
  1823. }
  1824. finally
  1825. {
  1826. graph.getModel().endUpdate();
  1827. }
  1828. if (cell != null)
  1829. {
  1830. graph.setSelectionCell(cell);
  1831. graph.scrollCellToVisible(cell);
  1832. }
  1833. };
  1834. // Hardcoded response for default settings
  1835. if (text == plantUmlExample && format == 'svg')
  1836. {
  1837. window.setTimeout(function()
  1838. {
  1839. editorUi.spinner.stop();
  1840. insertPlantUmlImage(text, format, 'data:image/svg+xml;base64,PD94bWwgdmVyc2lvbj0iMS4wIiBlbmNvZGluZz0iVVRGLTgiIHN0YW5kYWxvbmU9Im5vIj8+PHN2ZyB4bWxucz0iaHR0cDovL3d3dy53My5vcmcvMjAwMC9zdmciIHhtbG5zOnhsaW5rPSJodHRwOi8vd3d3LnczLm9yZy8xOTk5L3hsaW5rIiBjb250ZW50U2NyaXB0VHlwZT0iYXBwbGljYXRpb24vZWNtYXNjcmlwdCIgY29udGVudFN0eWxlVHlwZT0idGV4dC9jc3MiIGhlaWdodD0iMjEycHgiIHByZXNlcnZlQXNwZWN0UmF0aW89Im5vbmUiIHN0eWxlPSJ3aWR0aDoyOTVweDtoZWlnaHQ6MjEycHg7IiB2ZXJzaW9uPSIxLjEiIHZpZXdCb3g9IjAgMCAyOTUgMjEyIiB3aWR0aD0iMjk1cHgiIHpvb21BbmRQYW49Im1hZ25pZnkiPjxkZWZzLz48Zz48bGluZSBzdHlsZT0ic3Ryb2tlOiAjQTgwMDM2OyBzdHJva2Utd2lkdGg6IDEuMDsgc3Ryb2tlLWRhc2hhcnJheTogNS4wLDUuMDsiIHgxPSIzMSIgeDI9IjMxIiB5MT0iMzQuNDg4MyIgeTI9IjE3MS43MzA1Ii8+PGxpbmUgc3R5bGU9InN0cm9rZTogI0E4MDAzNjsgc3Ryb2tlLXdpZHRoOiAxLjA7IHN0cm9rZS1kYXNoYXJyYXk6IDUuMCw1LjA7IiB4MT0iMjY0LjUiIHgyPSIyNjQuNSIgeTE9IjM0LjQ4ODMiIHkyPSIxNzEuNzMwNSIvPjxyZWN0IGZpbGw9IiNGRUZFQ0UiIGhlaWdodD0iMzAuNDg4MyIgc3R5bGU9InN0cm9rZTogI0E4MDAzNjsgc3Ryb2tlLXdpZHRoOiAxLjU7IiB3aWR0aD0iNDciIHg9IjgiIHk9IjMiLz48dGV4dCBmaWxsPSIjMDAwMDAwIiBmb250LWZhbWlseT0ic2Fucy1zZXJpZiIgZm9udC1zaXplPSIxNCIgbGVuZ3RoQWRqdXN0PSJzcGFjaW5nQW5kR2x5cGhzIiB0ZXh0TGVuZ3RoPSIzMyIgeD0iMTUiIHk9IjIzLjUzNTIiPkFsaWNlPC90ZXh0PjxyZWN0IGZpbGw9IiNGRUZFQ0UiIGhlaWdodD0iMzAuNDg4MyIgc3R5bGU9InN0cm9rZTogI0E4MDAzNjsgc3Ryb2tlLXdpZHRoOiAxLjU7IiB3aWR0aD0iNDciIHg9IjgiIHk9IjE3MC43MzA1Ii8+PHRleHQgZmlsbD0iIzAwMDAwMCIgZm9udC1mYW1pbHk9InNhbnMtc2VyaWYiIGZvbnQtc2l6ZT0iMTQiIGxlbmd0aEFkanVzdD0ic3BhY2luZ0FuZEdseXBocyIgdGV4dExlbmd0aD0iMzMiIHg9IjE1IiB5PSIxOTEuMjY1NiI+QWxpY2U8L3RleHQ+PHJlY3QgZmlsbD0iI0ZFRkVDRSIgaGVpZ2h0PSIzMC40ODgzIiBzdHlsZT0ic3Ryb2tlOiAjQTgwMDM2OyBzdHJva2Utd2lkdGg6IDEuNTsiIHdpZHRoPSI0MCIgeD0iMjQ0LjUiIHk9IjMiLz48dGV4dCBmaWxsPSIjMDAwMDAwIiBmb250LWZhbWlseT0ic2Fucy1zZXJpZiIgZm9udC1zaXplPSIxNCIgbGVuZ3RoQWRqdXN0PSJzcGFjaW5nQW5kR2x5cGhzIiB0ZXh0TGVuZ3RoPSIyNiIgeD0iMjUxLjUiIHk9IjIzLjUzNTIiPkJvYjwvdGV4dD48cmVjdCBmaWxsPSIjRkVGRUNFIiBoZWlnaHQ9IjMwLjQ4ODMiIHN0eWxlPSJzdHJva2U6ICNBODAwMzY7IHN0cm9rZS13aWR0aDogMS41OyIgd2lkdGg9IjQwIiB4PSIyNDQuNSIgeT0iMTcwLjczMDUiLz48dGV4dCBmaWxsPSIjMDAwMDAwIiBmb250LWZhbWlseT0ic2Fucy1zZXJpZiIgZm9udC1zaXplPSIxNCIgbGVuZ3RoQWRqdXN0PSJzcGFjaW5nQW5kR2x5cGhzIiB0ZXh0TGVuZ3RoPSIyNiIgeD0iMjUxLjUiIHk9IjE5MS4yNjU2Ij5Cb2I8L3RleHQ+PHBvbHlnb24gZmlsbD0iI0E4MDAzNiIgcG9pbnRzPSIyNTIuNSw2MS43OTg4LDI2Mi41LDY1Ljc5ODgsMjUyLjUsNjkuNzk4OCwyNTYuNSw2NS43OTg4IiBzdHlsZT0ic3Ryb2tlOiAjQTgwMDM2OyBzdHJva2Utd2lkdGg6IDEuMDsiLz48bGluZSBzdHlsZT0ic3Ryb2tlOiAjQTgwMDM2OyBzdHJva2Utd2lkdGg6IDEuMDsiIHgxPSIzMS41IiB4Mj0iMjU4LjUiIHkxPSI2NS43OTg4IiB5Mj0iNjUuNzk4OCIvPjx0ZXh0IGZpbGw9IiMwMDAwMDAiIGZvbnQtZmFtaWx5PSJzYW5zLXNlcmlmIiBmb250LXNpemU9IjEzIiBsZW5ndGhBZGp1c3Q9InNwYWNpbmdBbmRHbHlwaHMiIHRleHRMZW5ndGg9IjE0NyIgeD0iMzguNSIgeT0iNjEuMDU2NiI+QXV0aGVudGljYXRpb24gUmVxdWVzdDwvdGV4dD48cG9seWdvbiBmaWxsPSIjQTgwMDM2IiBwb2ludHM9IjQyLjUsOTEuMTA5NCwzMi41LDk1LjEwOTQsNDIuNSw5OS4xMDk0LDM4LjUsOTUuMTA5NCIgc3R5bGU9InN0cm9rZTogI0E4MDAzNjsgc3Ryb2tlLXdpZHRoOiAxLjA7Ii8+PGxpbmUgc3R5bGU9InN0cm9rZTogI0E4MDAzNjsgc3Ryb2tlLXdpZHRoOiAxLjA7IHN0cm9rZS1kYXNoYXJyYXk6IDIuMCwyLjA7IiB4MT0iMzYuNSIgeDI9IjI2My41IiB5MT0iOTUuMTA5NCIgeTI9Ijk1LjEwOTQiLz48dGV4dCBmaWxsPSIjMDAwMDAwIiBmb250LWZhbWlseT0ic2Fucy1zZXJpZiIgZm9udC1zaXplPSIxMyIgbGVuZ3RoQWRqdXN0PSJzcGFjaW5nQW5kR2x5cGhzIiB0ZXh0TGVuZ3RoPSIxNTciIHg9IjQ4LjUiIHk9IjkwLjM2NzIiPkF1dGhlbnRpY2F0aW9uIFJlc3BvbnNlPC90ZXh0Pjxwb2x5Z29uIGZpbGw9IiNBODAwMzYiIHBvaW50cz0iMjUyLjUsMTIwLjQxOTksMjYyLjUsMTI0LjQxOTksMjUyLjUsMTI4LjQxOTksMjU2LjUsMTI0LjQxOTkiIHN0eWxlPSJzdHJva2U6ICNBODAwMzY7IHN0cm9rZS13aWR0aDogMS4wOyIvPjxsaW5lIHN0eWxlPSJzdHJva2U6ICNBODAwMzY7IHN0cm9rZS13aWR0aDogMS4wOyIgeDE9IjMxLjUiIHgyPSIyNTguNSIgeTE9IjEyNC40MTk5IiB5Mj0iMTI0LjQxOTkiLz48dGV4dCBmaWxsPSIjMDAwMDAwIiBmb250LWZhbWlseT0ic2Fucy1zZXJpZiIgZm9udC1zaXplPSIxMyIgbGVuZ3RoQWRqdXN0PSJzcGFjaW5nQW5kR2x5cGhzIiB0ZXh0TGVuZ3RoPSIxOTkiIHg9IjM4LjUiIHk9IjExOS42Nzc3Ij5Bbm90aGVyIGF1dGhlbnRpY2F0aW9uIFJlcXVlc3Q8L3RleHQ+PHBvbHlnb24gZmlsbD0iI0E4MDAzNiIgcG9pbnRzPSI0Mi41LDE0OS43MzA1LDMyLjUsMTUzLjczMDUsNDIuNSwxNTcuNzMwNSwzOC41LDE1My43MzA1IiBzdHlsZT0ic3Ryb2tlOiAjQTgwMDM2OyBzdHJva2Utd2lkdGg6IDEuMDsiLz48bGluZSBzdHlsZT0ic3Ryb2tlOiAjQTgwMDM2OyBzdHJva2Utd2lkdGg6IDEuMDsgc3Ryb2tlLWRhc2hhcnJheTogMi4wLDIuMDsiIHgxPSIzNi41IiB4Mj0iMjYzLjUiIHkxPSIxNTMuNzMwNSIgeTI9IjE1My43MzA1Ii8+PHRleHQgZmlsbD0iIzAwMDAwMCIgZm9udC1mYW1pbHk9InNhbnMtc2VyaWYiIGZvbnQtc2l6ZT0iMTMiIGxlbmd0aEFkanVzdD0ic3BhY2luZ0FuZEdseXBocyIgdGV4dExlbmd0aD0iMjA5IiB4PSI0OC41IiB5PSIxNDguOTg4MyI+QW5vdGhlciBhdXRoZW50aWNhdGlvbiBSZXNwb25zZTwvdGV4dD48IS0tTUQ1PVs3ZjNlNGQwYzkwMWVmZGJjNTdlYjQ0MjQ5YTNiODE5N10KQHN0YXJ0dW1sDQpza2lucGFyYW0gc2hhZG93aW5nIGZhbHNlDQpBbGljZSAtPiBCb2I6IEF1dGhlbnRpY2F0aW9uIFJlcXVlc3QNCkJvYiAtIC0+IEFsaWNlOiBBdXRoZW50aWNhdGlvbiBSZXNwb25zZQ0KDQpBbGljZSAtPiBCb2I6IEFub3RoZXIgYXV0aGVudGljYXRpb24gUmVxdWVzdA0KQWxpY2UgPC0gLSBCb2I6IEFub3RoZXIgYXV0aGVudGljYXRpb24gUmVzcG9uc2UNCkBlbmR1bWwNCgpQbGFudFVNTCB2ZXJzaW9uIDEuMjAyMC4wMihTdW4gTWFyIDAxIDA0OjIyOjA3IENTVCAyMDIwKQooTUlUIHNvdXJjZSBkaXN0cmlidXRpb24pCkphdmEgUnVudGltZTogT3BlbkpESyBSdW50aW1lIEVudmlyb25tZW50CkpWTTogT3BlbkpESyA2NC1CaXQgU2VydmVyIFZNCkphdmEgVmVyc2lvbjogMTIrMzMKT3BlcmF0aW5nIFN5c3RlbTogTWFjIE9TIFgKRGVmYXVsdCBFbmNvZGluZzogVVRGLTgKTGFuZ3VhZ2U6IGVuCkNvdW50cnk6IFVTCi0tPjwvZz48L3N2Zz4=',
  1841. 295, 212);
  1842. }, 200);
  1843. }
  1844. else
  1845. {
  1846. editorUi.generatePlantUmlImage(text, format, function(data, w, h)
  1847. {
  1848. editorUi.spinner.stop();
  1849. insertPlantUmlImage(text, format, data, w, h);
  1850. }, function(e)
  1851. {
  1852. editorUi.handleError(e);
  1853. });
  1854. }
  1855. }
  1856. }
  1857. else if (type == 'mermaid' || type == 'mermaid2drawio')
  1858. {
  1859. if (editorUi.spinner.spin(document.body, mxResources.get('inserting')))
  1860. {
  1861. var k = 0;
  1862. while (k < lines.length && (lines[k].trim().length == 0 ||
  1863. lines[k].substring(0, 2) == '%%'))
  1864. {
  1865. k++;
  1866. }
  1867. if (lines[k].trim() == '---')
  1868. {
  1869. do
  1870. {
  1871. k++;
  1872. }
  1873. while (k < lines.length && lines[k].trim() != '---');
  1874. k++;
  1875. }
  1876. var diagramType = lines[k].trim().toLowerCase();
  1877. var sp = diagramType.indexOf(' ');
  1878. diagramType = diagramType.substring(0, sp > 0 ? sp : diagramType.length);
  1879. // TODO Better to add only what we support?
  1880. var inDrawioFormat = typeof mxMermaidToDrawio !== 'undefined' &&
  1881. type == 'mermaid2drawio' && diagramType != 'gantt' &&
  1882. diagramType != 'pie' && diagramType != 'timeline' &&
  1883. diagramType != 'quadrantchart' && diagramType != 'c4context' &&
  1884. diagramType != 'block-beta' && diagramType != 'zenuml' &&
  1885. diagramType != 'xychart-beta' && diagramType != 'sankey-beta';
  1886. var graph = editorUi.editor.graph;
  1887. if (inDrawioFormat)
  1888. {
  1889. mxMermaidToDrawio.addListener(mxUtils.bind(this, function(modelXml)
  1890. {
  1891. editorUi.spinner.stop();
  1892. graph.setSelectionCells(editorUi.importXml(modelXml,
  1893. Math.max(insertPoint.x, 20),
  1894. Math.max(insertPoint.y, 20),
  1895. true, null, null, true));
  1896. graph.scrollCellToVisible(graph.getSelectionCell());
  1897. }));
  1898. }
  1899. editorUi.generateMermaidImage(text, null, function(data, w, h)
  1900. {
  1901. if (inDrawioFormat) return;
  1902. insertPoint = (mxEvent.isAltDown(evt)) ? insertPoint : graph.getCenterInsertPoint(new mxRectangle(0, 0, w, h));
  1903. editorUi.spinner.stop();
  1904. var cell = null;
  1905. graph.getModel().beginUpdate();
  1906. try
  1907. {
  1908. cell = graph.insertVertex(null, null, null, insertPoint.x, insertPoint.y,
  1909. w, h, 'shape=image;noLabel=1;verticalAlign=top;imageAspect=1;' +
  1910. 'image=' + data + ';')
  1911. graph.setAttributeForCell(cell, 'mermaidData',
  1912. JSON.stringify({data: text}, null, 2));
  1913. }
  1914. finally
  1915. {
  1916. graph.getModel().endUpdate();
  1917. }
  1918. if (cell != null)
  1919. {
  1920. graph.setSelectionCell(cell);
  1921. graph.scrollCellToVisible(cell);
  1922. }
  1923. }, function(e)
  1924. {
  1925. if (typeof mxMermaidToDrawio !== 'undefined')
  1926. {
  1927. mxMermaidToDrawio.resetListeners();
  1928. }
  1929. editorUi.handleError(e);
  1930. });
  1931. }
  1932. }
  1933. else if (type == 'table')
  1934. {
  1935. var tableCell = null;
  1936. var cells = [];
  1937. var dx = 0;
  1938. var pkMap = {};
  1939. //First pass to find primary keys
  1940. for (var i = 0; i < lines.length; i++)
  1941. {
  1942. var line = mxUtils.trim(lines[i]);
  1943. if (line.substring(0, 11).toLowerCase() == 'primary key')
  1944. {
  1945. var pk = line.match(/\((.+)\)/);
  1946. if (pk && pk[1])
  1947. {
  1948. pkMap[pk[1]] = true;
  1949. }
  1950. lines.splice(i, 1);
  1951. }
  1952. else if (line.toLowerCase().indexOf('primary key') > 0)
  1953. {
  1954. pkMap[line.split(' ')[0]] = true;
  1955. lines[i] = mxUtils.trim(line.replace(/primary key/i, ''));
  1956. }
  1957. }
  1958. for (var i = 0; i < lines.length; i++)
  1959. {
  1960. var tmp = mxUtils.trim(lines[i]);
  1961. if (tmp.substring(0, 12).toLowerCase() == 'create table')
  1962. {
  1963. var name = mxUtils.trim(tmp.substring(12));
  1964. if (name.charAt(name.length - 1) == '(')
  1965. {
  1966. name = mxUtils.trim(name.substring(0, name.length - 1));
  1967. }
  1968. tableCell = new mxCell(name, new mxGeometry(dx, 0, 160, 30),
  1969. 'shape=table;startSize=30;container=1;collapsible=1;childLayout=tableLayout;' +
  1970. 'fixedRows=1;rowLines=0;fontStyle=1;align=center;resizeLast=1;');
  1971. tableCell.vertex = true;
  1972. cells.push(tableCell);
  1973. var size = editorUi.editor.graph.getPreferredSizeForCell(rowCell);
  1974. if (size != null)
  1975. {
  1976. tableCell.geometry.width = size.width + 10;
  1977. }
  1978. }
  1979. else if (tableCell != null && tmp.charAt(0) == ')')
  1980. {
  1981. dx += tableCell.geometry.width + 40;
  1982. tableCell = null;
  1983. }
  1984. else if (tmp != '(' && tableCell != null)
  1985. {
  1986. var name = tmp.substring(0, (tmp.charAt(tmp.length - 1) == ',') ? tmp.length - 1 : tmp.length);
  1987. var pk = pkMap[name.split(' ')[0]];
  1988. var rowCell = new mxCell('', new mxGeometry(0, 0, 160, 30),
  1989. 'shape=tableRow;horizontal=0;startSize=0;swimlaneHead=0;swimlaneBody=0;fillColor=none;' +
  1990. 'collapsible=0;dropTarget=0;points=[[0,0.5],[1,0.5]];portConstraint=eastwest;' +
  1991. 'strokeColor=inherit;top=0;left=0;right=0;bottom=' + (pk ? '1' : '0') + ';');
  1992. rowCell.vertex = true;
  1993. var left = new mxCell(pk ? 'PK' : '', new mxGeometry(0, 0, 30, 30),
  1994. 'shape=partialRectangle;overflow=hidden;connectable=0;fillColor=none;' +
  1995. 'strokeColor=inherit;top=0;left=0;bottom=0;right=0;' +
  1996. (pk ? 'fontStyle=1;' : ''));
  1997. left.vertex = true;
  1998. rowCell.insert(left);
  1999. var right = new mxCell(name, new mxGeometry(30, 0, 130, 30),
  2000. 'shape=partialRectangle;overflow=hidden;connectable=0;fillColor=none;align=left;' +
  2001. 'strokeColor=inherit;top=0;left=0;bottom=0;right=0;spacingLeft=6;' +
  2002. (pk ? 'fontStyle=5;' : ''));
  2003. right.vertex = true;
  2004. rowCell.insert(right);
  2005. var size = editorUi.editor.graph.getPreferredSizeForCell(right);
  2006. if (size != null && tableCell.geometry.width < size.width + 30)
  2007. {
  2008. tableCell.geometry.width = Math.min(320, Math.max(tableCell.geometry.width, size.width + 30));
  2009. }
  2010. tableCell.insert(rowCell, pk? 0 : null);
  2011. tableCell.geometry.height += 30;
  2012. }
  2013. }
  2014. if (cells.length > 0)
  2015. {
  2016. var graph = editorUi.editor.graph;
  2017. insertPoint = (mxEvent.isAltDown(evt)) ? insertPoint :
  2018. graph.getCenterInsertPoint(graph.getBoundingBoxFromGeometry(cells, true));
  2019. graph.setSelectionCells(graph.importCells(cells, insertPoint.x, insertPoint.y));
  2020. graph.scrollCellToVisible(graph.getSelectionCell());
  2021. }
  2022. }
  2023. else if (type == 'list')
  2024. {
  2025. if (lines.length > 0)
  2026. {
  2027. var graph = editorUi.editor.graph;
  2028. var listCell = null;
  2029. var cells = [];
  2030. var x0 = 0;
  2031. for (var i = 0; i < lines.length; i++)
  2032. {
  2033. if (lines[i].charAt(0) != ';')
  2034. {
  2035. if (lines[i].length == 0)
  2036. {
  2037. listCell = null;
  2038. }
  2039. else
  2040. {
  2041. if (listCell == null)
  2042. {
  2043. listCell = new mxCell(lines[i], new mxGeometry(x0, 0, 160, 26 + 4),
  2044. 'swimlane;fontStyle=1;childLayout=stackLayout;horizontal=1;startSize=26;horizontalStack=0;resizeParent=1;resizeParentMax=0;resizeLast=0;collapsible=1;marginBottom=0;');
  2045. listCell.vertex = true;
  2046. cells.push(listCell);
  2047. var size = graph.getPreferredSizeForCell(listCell);
  2048. if (size != null && listCell.geometry.width < size.width + 10)
  2049. {
  2050. listCell.geometry.width = size.width + 10;
  2051. }
  2052. x0 += listCell.geometry.width + 40;
  2053. }
  2054. else if (lines[i] == '--')
  2055. {
  2056. var divider = new mxCell('', new mxGeometry(0, 0, 40, 8), 'line;strokeWidth=1;fillColor=none;align=left;verticalAlign=middle;spacingTop=-1;spacingLeft=3;spacingRight=3;rotatable=0;labelPosition=right;points=[];portConstraint=eastwest;');
  2057. divider.vertex = true;
  2058. listCell.geometry.height += divider.geometry.height;
  2059. listCell.insert(divider);
  2060. }
  2061. else if (lines[i].length > 0)
  2062. {
  2063. var field = new mxCell(lines[i], new mxGeometry(0, 0, 60, 26), 'text;strokeColor=none;fillColor=none;align=left;verticalAlign=top;spacingLeft=4;spacingRight=4;overflow=hidden;rotatable=0;points=[[0,0.5],[1,0.5]];portConstraint=eastwest;');
  2064. field.vertex = true;
  2065. var size = graph.getPreferredSizeForCell(field);
  2066. if (size != null && field.geometry.width < size.width)
  2067. {
  2068. field.geometry.width = size.width;
  2069. }
  2070. listCell.geometry.width = Math.max(listCell.geometry.width, field.geometry.width);
  2071. listCell.geometry.height += field.geometry.height;
  2072. listCell.insert(field);
  2073. }
  2074. }
  2075. }
  2076. }
  2077. if (cells.length > 0)
  2078. {
  2079. insertPoint = (mxEvent.isAltDown(evt)) ? insertPoint :
  2080. graph.getCenterInsertPoint(graph.getBoundingBoxFromGeometry(cells, true));
  2081. graph.getModel().beginUpdate();
  2082. try
  2083. {
  2084. cells = graph.importCells(cells, insertPoint.x, insertPoint.y);
  2085. var inserted = [];
  2086. for (var i = 0; i < cells.length; i++)
  2087. {
  2088. inserted.push(cells[i]);
  2089. inserted = inserted.concat(cells[i].children);
  2090. }
  2091. graph.fireEvent(new mxEventObject('cellsInserted', 'cells', inserted));
  2092. }
  2093. finally
  2094. {
  2095. graph.getModel().endUpdate();
  2096. }
  2097. graph.setSelectionCells(cells);
  2098. graph.scrollCellToVisible(graph.getSelectionCell());
  2099. }
  2100. }
  2101. }
  2102. else
  2103. {
  2104. var vertices = new Object();
  2105. var cells = [];
  2106. function getOrCreateVertex(id)
  2107. {
  2108. var vertex = vertices[id];
  2109. if (vertex == null)
  2110. {
  2111. vertex = new mxCell(id, new mxGeometry(0, 0, 80, 30), 'whiteSpace=wrap;html=1;');
  2112. vertex.vertex = true;
  2113. vertices[id] = vertex;
  2114. cells.push(vertex);
  2115. }
  2116. return vertex;
  2117. };
  2118. for (var i = 0; i < lines.length; i++)
  2119. {
  2120. if (lines[i].charAt(0) != ';')
  2121. {
  2122. var values = lines[i].split('->');
  2123. if (values.length >= 2)
  2124. {
  2125. var source = getOrCreateVertex(values[0]);
  2126. var target = getOrCreateVertex(values[values.length - 1]);
  2127. var edge = new mxCell((values.length > 2) ? values[1] : '', new mxGeometry());
  2128. edge.edge = true;
  2129. edge.geometry.relative = true;
  2130. source.insertEdge(edge, true);
  2131. target.insertEdge(edge, false);
  2132. cells.push(edge);
  2133. }
  2134. }
  2135. }
  2136. if (cells.length > 0)
  2137. {
  2138. var container = document.createElement('div');
  2139. container.style.visibility = 'hidden';
  2140. document.body.appendChild(container);
  2141. // Temporary graph for running the layout
  2142. var graph = new Graph(container);
  2143. graph.getModel().beginUpdate();
  2144. try
  2145. {
  2146. cells = graph.importCells(cells);
  2147. for (var i = 0; i < cells.length; i++)
  2148. {
  2149. if (graph.getModel().isVertex(cells[i]))
  2150. {
  2151. var size = graph.getPreferredSizeForCell(cells[i]);
  2152. cells[i].geometry.width = Math.max(cells[i].geometry.width, size.width);
  2153. cells[i].geometry.height = Math.max(cells[i].geometry.height, size.height);
  2154. }
  2155. }
  2156. var runEdgeLayout = true;
  2157. if (type == 'horizontalFlow' || type == 'verticalFlow')
  2158. {
  2159. var flowLayout = new mxHierarchicalLayout(graph,
  2160. (type == 'horizontalFlow') ?
  2161. mxConstants.DIRECTION_WEST :
  2162. mxConstants.DIRECTION_NORTH);
  2163. flowLayout.execute(graph.getDefaultParent(), cells);
  2164. runEdgeLayout = false;
  2165. }
  2166. else if (type == 'circle')
  2167. {
  2168. var circleLayout = new mxCircleLayout(graph);
  2169. circleLayout.execute(graph.getDefaultParent());
  2170. }
  2171. else
  2172. {
  2173. var layout = new mxFastOrganicLayout(graph);
  2174. layout.disableEdgeStyle = false;
  2175. layout.forceConstant = 180;
  2176. layout.execute(graph.getDefaultParent());
  2177. }
  2178. if (runEdgeLayout)
  2179. {
  2180. var edgeLayout = new mxParallelEdgeLayout(graph);
  2181. edgeLayout.spacing = 30;
  2182. edgeLayout.execute(graph.getDefaultParent());
  2183. }
  2184. }
  2185. finally
  2186. {
  2187. graph.getModel().endUpdate();
  2188. }
  2189. graph.clearCellOverlays();
  2190. // Copy to actual graph
  2191. var inserted = [];
  2192. editorUi.editor.graph.getModel().beginUpdate();
  2193. try
  2194. {
  2195. cells = graph.getModel().getChildren(graph.getDefaultParent());
  2196. insertPoint = (mxEvent.isAltDown(evt)) ? insertPoint :
  2197. editorUi.editor.graph.getCenterInsertPoint(graph.getBoundingBoxFromGeometry(cells, true));
  2198. inserted = editorUi.editor.graph.importCells(cells, insertPoint.x, insertPoint.y)
  2199. editorUi.editor.graph.fireEvent(new mxEventObject('cellsInserted', 'cells', inserted));
  2200. }
  2201. finally
  2202. {
  2203. editorUi.editor.graph.getModel().endUpdate();
  2204. }
  2205. editorUi.editor.graph.setSelectionCells(inserted);
  2206. editorUi.editor.graph.scrollCellToVisible(editorUi.editor.graph.getSelectionCell());
  2207. graph.destroy();
  2208. container.parentNode.removeChild(container);
  2209. }
  2210. }
  2211. };
  2212. var div = document.createElement('div');
  2213. div.style.textAlign = 'right';
  2214. var textarea = document.createElement('textarea');
  2215. textarea.style.boxSizing = 'border-box';
  2216. textarea.style.resize = 'none';
  2217. textarea.style.width = '100%';
  2218. textarea.style.height = '354px';
  2219. textarea.style.marginBottom = '16px';
  2220. var typeSelect = document.createElement('select');
  2221. typeSelect.className = 'geBtn';
  2222. if (defaultType == 'formatSql' || (defaultType == 'mermaid' &&
  2223. editorUi.getServiceName() != 'draw.io' && editorUi.getServiceName() != 'atlassian'))
  2224. {
  2225. typeSelect.style.display = 'none';
  2226. }
  2227. var listOption = document.createElement('option');
  2228. listOption.setAttribute('value', 'list');
  2229. mxUtils.write(listOption, mxResources.get('list'));
  2230. if (defaultType != 'plantUml' && defaultType != 'mermaid')
  2231. {
  2232. typeSelect.appendChild(listOption);
  2233. }
  2234. if (defaultType == null || defaultType == 'fromText')
  2235. {
  2236. listOption.setAttribute('selected', 'selected');
  2237. }
  2238. var tableOption = document.createElement('option');
  2239. tableOption.setAttribute('value', 'table');
  2240. mxUtils.write(tableOption, mxResources.get('formatSql'));
  2241. if (defaultType == 'formatSql')
  2242. {
  2243. typeSelect.appendChild(tableOption);
  2244. tableOption.setAttribute('selected', 'selected');
  2245. }
  2246. var mermaidOption = document.createElement('option');
  2247. mermaidOption.setAttribute('value', 'mermaid');
  2248. mxUtils.write(mermaidOption, mxResources.get('image'));
  2249. if (defaultType == 'mermaid')
  2250. {
  2251. if (typeof mxMermaidToDrawio !== 'undefined')
  2252. {
  2253. var mermaid2drawioOption = document.createElement('option');
  2254. mermaid2drawioOption.setAttribute('value', 'mermaid2drawio');
  2255. mermaid2drawioOption.setAttribute('selected', 'selected');
  2256. mxUtils.write(mermaid2drawioOption, mxResources.get('diagram'));
  2257. typeSelect.appendChild(mermaid2drawioOption);
  2258. }
  2259. else
  2260. {
  2261. typeSelect.style.display = 'none';
  2262. }
  2263. }
  2264. typeSelect.appendChild(mermaidOption);
  2265. var diagramOption = document.createElement('option');
  2266. diagramOption.setAttribute('value', 'diagram');
  2267. mxUtils.write(diagramOption, mxResources.get('diagram'));
  2268. var circleOption = document.createElement('option');
  2269. circleOption.setAttribute('value', 'circle');
  2270. mxUtils.write(circleOption, mxResources.get('circle'));
  2271. var horizontalFlowOption = document.createElement('option');
  2272. horizontalFlowOption.setAttribute('value', 'horizontalFlow');
  2273. mxUtils.write(horizontalFlowOption, mxResources.get('horizontalFlow'));
  2274. var verticalFlowOption = document.createElement('option');
  2275. verticalFlowOption.setAttribute('value', 'verticalFlow');
  2276. mxUtils.write(verticalFlowOption, mxResources.get('verticalFlow'));
  2277. if (defaultType != 'plantUml' && defaultType != 'mermaid')
  2278. {
  2279. typeSelect.appendChild(diagramOption);
  2280. typeSelect.appendChild(circleOption);
  2281. typeSelect.appendChild(horizontalFlowOption);
  2282. typeSelect.appendChild(verticalFlowOption);
  2283. }
  2284. var plantUmlSvgOption = document.createElement('option');
  2285. plantUmlSvgOption.setAttribute('value', 'plantUmlSvg');
  2286. mxUtils.write(plantUmlSvgOption, mxResources.get('plantUml') + ' (' + mxResources.get('formatSvg') + ')');
  2287. if (defaultType == 'plantUml')
  2288. {
  2289. plantUmlSvgOption.setAttribute('selected', 'selected');
  2290. }
  2291. var plantUmlPngOption = document.createElement('option');
  2292. plantUmlPngOption.setAttribute('value', 'plantUmlPng');
  2293. mxUtils.write(plantUmlPngOption, mxResources.get('plantUml') + ' (' + mxResources.get('formatPng') + ')');
  2294. var plantUmlTxtOption = document.createElement('option');
  2295. plantUmlTxtOption.setAttribute('value', 'plantUmlTxt');
  2296. mxUtils.write(plantUmlTxtOption, mxResources.get('plantUml') + ' (' + mxResources.get('text') + ')');
  2297. // Disabled for invalid hosts via CORS headers
  2298. if (EditorUi.enablePlantUml && Graph.fileSupport &&
  2299. !editorUi.isOffline() && defaultType == 'plantUml')
  2300. {
  2301. typeSelect.appendChild(plantUmlSvgOption);
  2302. typeSelect.appendChild(plantUmlPngOption);
  2303. typeSelect.appendChild(plantUmlTxtOption);
  2304. }
  2305. function getDefaultValue()
  2306. {
  2307. if (typeSelect.value == 'list')
  2308. {
  2309. return 'Person\n-name: String\n-birthDate: Date\n--\n+getName(): String\n+setName(String): void\n+isBirthday(): boolean\n\n' +
  2310. 'Address\n-street: String\n-city: String\n-state: String';
  2311. }
  2312. else if (typeSelect.value == 'mermaid' || typeSelect.value == 'mermaid2drawio')
  2313. {
  2314. return 'graph TD;\n A-->B;\n A-->C;\n B-->D;\n C-->D;';
  2315. }
  2316. else if (typeSelect.value == 'table')
  2317. {
  2318. return 'CREATE TABLE Suppliers\n(\nsupplier_id int NOT NULL PRIMARY KEY,\n' +
  2319. 'supplier_name char(50) NOT NULL,\ncontact_name char(50),\n);\n' +
  2320. 'CREATE TABLE Customers\n(\ncustomer_id int NOT NULL PRIMARY KEY,\n' +
  2321. 'customer_name char(50) NOT NULL,\naddress char(50),\n' +
  2322. 'city char(50),\nstate char(25),\nzip_code char(10)\n);\n';
  2323. }
  2324. else if (typeSelect.value == 'plantUmlPng')
  2325. {
  2326. return '@startuml\nskinparam backgroundcolor transparent\nskinparam shadowing false\nAlice -> Bob: Authentication Request\nBob --> Alice: Authentication Response\n\nAlice -> Bob: Another authentication Request\nAlice <-- Bob: Another authentication Response\n@enduml';
  2327. }
  2328. else if (typeSelect.value == 'plantUmlSvg' || typeSelect.value == 'plantUmlTxt')
  2329. {
  2330. return plantUmlExample;
  2331. }
  2332. else
  2333. {
  2334. return ';Example:\na->b\nb->edge label->c\nc->a\n';
  2335. }
  2336. };
  2337. var defaultValue = getDefaultValue();
  2338. textarea.value = defaultValue;
  2339. div.appendChild(textarea);
  2340. this.init = function()
  2341. {
  2342. textarea.focus();
  2343. };
  2344. // Enables dropping files
  2345. if (Graph.fileSupport)
  2346. {
  2347. function handleDrop(evt)
  2348. {
  2349. evt.stopPropagation();
  2350. evt.preventDefault();
  2351. if (evt.dataTransfer.files.length > 0)
  2352. {
  2353. var file = evt.dataTransfer.files[0];
  2354. var reader = new FileReader();
  2355. reader.onload = function(e) { textarea.value = e.target.result; };
  2356. reader.readAsText(file);
  2357. }
  2358. };
  2359. function handleDragOver(evt)
  2360. {
  2361. evt.stopPropagation();
  2362. evt.preventDefault();
  2363. };
  2364. // Setup the dnd listeners.
  2365. textarea.addEventListener('dragover', handleDragOver, false);
  2366. textarea.addEventListener('drop', handleDrop, false);
  2367. }
  2368. div.appendChild(typeSelect);
  2369. mxEvent.addListener(typeSelect, 'change', function()
  2370. {
  2371. var newDefaultValue = getDefaultValue();
  2372. if (textarea.value.length == 0 || textarea.value == defaultValue)
  2373. {
  2374. defaultValue = newDefaultValue;
  2375. textarea.value = defaultValue;
  2376. }
  2377. });
  2378. if (!editorUi.isOffline() && (defaultType == 'mermaid' || defaultType == 'plantUml'))
  2379. {
  2380. var helpBtn = mxUtils.button(mxResources.get('help'), function()
  2381. {
  2382. editorUi.openLink((defaultType == 'mermaid') ?
  2383. 'https://mermaid-js.github.io/mermaid/#/' :
  2384. 'https://plantuml.com/');
  2385. });
  2386. helpBtn.className = 'geBtn';
  2387. div.appendChild(helpBtn);
  2388. }
  2389. var cancelBtn = mxUtils.button(mxResources.get('close'), function()
  2390. {
  2391. if (textarea.value == defaultValue)
  2392. {
  2393. editorUi.hideDialog();
  2394. }
  2395. else
  2396. {
  2397. editorUi.confirm(mxResources.get('areYouSure'), function()
  2398. {
  2399. editorUi.hideDialog();
  2400. });
  2401. }
  2402. });
  2403. cancelBtn.className = 'geBtn';
  2404. if (editorUi.editor.cancelFirst)
  2405. {
  2406. div.appendChild(cancelBtn);
  2407. }
  2408. var okBtn = mxUtils.button(mxResources.get('insert'), function(evt)
  2409. {
  2410. try
  2411. {
  2412. editorUi.hideDialog();
  2413. parse(textarea.value, typeSelect.value, evt);
  2414. }
  2415. catch (e)
  2416. {
  2417. editorUi.handleError(e);
  2418. }
  2419. });
  2420. okBtn.className = 'geBtn gePrimaryBtn';
  2421. div.appendChild(okBtn);
  2422. if (!editorUi.editor.cancelFirst)
  2423. {
  2424. div.appendChild(cancelBtn);
  2425. }
  2426. this.container = div;
  2427. };
  2428. /**
  2429. * Constructs a new dialog for creating files from templates.
  2430. */
  2431. var NewDialog = function(editorUi, compact, showName, callback, createOnly, cancelCallback,
  2432. leftHighlight, rightHighlight, rightHighlightBorder, itemPadding, templateFile,
  2433. recentDocsCallback, searchDocsCallback, openExtDocCallback, showImport, createButtonLabel, customTempCallback, withoutType)
  2434. {
  2435. var ww = window.innerWidth || document.documentElement.clientWidth || document.body.clientWidth;
  2436. var smallScreen = ww < 500;
  2437. showName = (showName != null) ? showName : true;
  2438. createOnly = (createOnly != null) ? createOnly : false;
  2439. leftHighlight = (leftHighlight != null) ? leftHighlight : (Editor.isDarkMode() ? Editor.darkColor : '#ebf2f9');
  2440. rightHighlight = (rightHighlight != null) ? rightHighlight : (Editor.isDarkMode() ? '#fff' : '#e6eff8');
  2441. rightHighlightBorder = (rightHighlightBorder != null) ? rightHighlightBorder : (Editor.isDarkMode() ? '2px dashed #00a8ff' : '2px solid #29b6f2');
  2442. templateFile = (templateFile != null) ? templateFile : EditorUi.templateFile;
  2443. var outer = document.createElement('div');
  2444. outer.style.userSelect = 'none';
  2445. outer.style.height = '100%';
  2446. var header = document.createElement('div');
  2447. header.style.whiteSpace = 'nowrap';
  2448. header.style.height = '46px';
  2449. if (showName)
  2450. {
  2451. outer.appendChild(header);
  2452. }
  2453. var logo = document.createElement('img');
  2454. logo.setAttribute('border', '0');
  2455. logo.setAttribute('align', 'absmiddle');
  2456. logo.style.width = '40px';
  2457. logo.style.height = '40px';
  2458. logo.style.marginRight = '10px';
  2459. logo.style.paddingBottom = '4px';
  2460. if (editorUi.mode == App.MODE_GOOGLE)
  2461. {
  2462. logo.src = IMAGE_PATH + '/google-drive-logo.svg';
  2463. }
  2464. else if (editorUi.mode == App.MODE_DROPBOX)
  2465. {
  2466. logo.src = IMAGE_PATH + '/dropbox-logo.svg';
  2467. }
  2468. else if (editorUi.mode == App.MODE_ONEDRIVE)
  2469. {
  2470. logo.src = IMAGE_PATH + '/onedrive-logo.svg';
  2471. }
  2472. else if (editorUi.mode == App.MODE_GITHUB)
  2473. {
  2474. logo.src = IMAGE_PATH + '/github-logo.svg';
  2475. }
  2476. else if (editorUi.mode == App.MODE_GITLAB)
  2477. {
  2478. logo.src = IMAGE_PATH + '/gitlab-logo.svg';
  2479. }
  2480. else if (editorUi.mode == App.MODE_TRELLO)
  2481. {
  2482. logo.src = IMAGE_PATH + '/trello-logo.svg';
  2483. }
  2484. else if (editorUi.mode == App.MODE_BROWSER)
  2485. {
  2486. logo.src = IMAGE_PATH + '/osa_database.png';
  2487. }
  2488. else
  2489. {
  2490. logo.src = IMAGE_PATH + '/osa_drive-harddisk.png';
  2491. }
  2492. if (!compact && !smallScreen && showName)
  2493. {
  2494. header.appendChild(logo);
  2495. }
  2496. if (showName)
  2497. {
  2498. mxUtils.write(header, (smallScreen? mxResources.get('name') : ((editorUi.mode == null || editorUi.mode == App.MODE_GOOGLE ||
  2499. editorUi.mode == App.MODE_BROWSER) ? mxResources.get('diagramName') : mxResources.get('filename'))) + ':');
  2500. }
  2501. var ext = '.drawio';
  2502. if (editorUi.mode == App.MODE_GOOGLE && editorUi.drive != null)
  2503. {
  2504. ext = editorUi.drive.extension;
  2505. }
  2506. else if (editorUi.mode == App.MODE_DROPBOX && editorUi.dropbox != null)
  2507. {
  2508. ext = editorUi.dropbox.extension;
  2509. }
  2510. else if (editorUi.mode == App.MODE_ONEDRIVE && editorUi.oneDrive != null)
  2511. {
  2512. ext = editorUi.oneDrive.extension;
  2513. }
  2514. else if (editorUi.mode == App.MODE_GITHUB && editorUi.gitHub != null)
  2515. {
  2516. ext = editorUi.gitHub.extension;
  2517. }
  2518. else if (editorUi.mode == App.MODE_GITLAB && editorUi.gitLab != null)
  2519. {
  2520. ext = editorUi.gitLab.extension;
  2521. }
  2522. else if (editorUi.mode == App.MODE_TRELLO && editorUi.trello != null)
  2523. {
  2524. ext = editorUi.trello.extension;
  2525. }
  2526. var nameInput = document.createElement('input');
  2527. nameInput.setAttribute('value', editorUi.defaultFilename + ext);
  2528. nameInput.style.marginLeft = '10px';
  2529. nameInput.style.width = (compact || smallScreen) ? '144px' : '244px';
  2530. this.init = function()
  2531. {
  2532. if (showName)
  2533. {
  2534. Editor.selectFilename(nameInput);
  2535. }
  2536. if (div.parentNode != null && div.parentNode.parentNode != null)
  2537. {
  2538. mxEvent.addGestureListeners(div.parentNode.parentNode, mxUtils.bind(this, function(evt)
  2539. {
  2540. if (editorUi.sidebar != null)
  2541. {
  2542. editorUi.sidebar.hideTooltip();
  2543. }
  2544. }), null, null);
  2545. }
  2546. };
  2547. // Adds filetype dropdown
  2548. if (showName)
  2549. {
  2550. header.appendChild(nameInput);
  2551. if (withoutType)
  2552. {
  2553. nameInput.style.width = (compact || smallScreen) ? '350px' : '450px';
  2554. }
  2555. else
  2556. {
  2557. if (editorUi.editor.diagramFileTypes != null)
  2558. {
  2559. var typeSelect = FilenameDialog.createFileTypes(editorUi, nameInput, editorUi.editor.diagramFileTypes);
  2560. typeSelect.style.marginLeft = '6px';
  2561. typeSelect.style.width = (compact || smallScreen) ? '80px' : '180px';
  2562. header.appendChild(typeSelect);
  2563. }
  2564. }
  2565. }
  2566. var hasTabs = false;
  2567. var i0 = 0;
  2568. // Dynamic loading
  2569. function addTemplates(smallSize)
  2570. {
  2571. //smallSize: Reduce template button size to fit 4 in a row
  2572. if (smallSize != null)
  2573. {
  2574. w = h = smallSize? 135 : 140;
  2575. }
  2576. var first = true;
  2577. //TODO support paging of external templates
  2578. if (templates != null)
  2579. {
  2580. while (i0 < templates.length && (first || mxUtils.mod(i0, 30) != 0))
  2581. {
  2582. var tmp = templates[i0++];
  2583. var btn = addButton(tmp.url, tmp.libs, tmp.title, tmp.tooltip? tmp.tooltip : tmp.title,
  2584. tmp.select, tmp.imgUrl, tmp.info, tmp.onClick, tmp.preview, tmp.noImg, tmp.clibs,
  2585. tmp.type);
  2586. if (first)
  2587. {
  2588. btn.click();
  2589. }
  2590. first = false;
  2591. }
  2592. }
  2593. };
  2594. var spinner = new Spinner({
  2595. lines: 12, // The number of lines to draw
  2596. length: 10, // The length of each line
  2597. width: 5, // The line thickness
  2598. radius: 10, // The radius of the inner circle
  2599. rotate: 0, // The rotation offset
  2600. color: '#000', // #rgb or #rrggbb
  2601. speed: 1.5, // Rounds per second
  2602. trail: 60, // Afterglow percentage
  2603. shadow: false, // Whether to render a shadow
  2604. hwaccel: false, // Whether to use hardware acceleration
  2605. top: '40%',
  2606. zIndex: 2e9 // The z-index (defaults to 2000000000)
  2607. });
  2608. var createButton = mxUtils.button(createButtonLabel || mxResources.get('create'), function()
  2609. {
  2610. createButton.setAttribute('disabled', 'disabled');
  2611. create();
  2612. createButton.removeAttribute('disabled');
  2613. });
  2614. createButton.className = 'geBtn gePrimaryBtn';
  2615. var magnifyImage = document.createElement('img');
  2616. magnifyImage.setAttribute('src', Editor.magnifyImage);
  2617. magnifyImage.setAttribute('title', mxResources.get('preview'));
  2618. magnifyImage.className = 'geAdaptiveAsset geActiveButton';
  2619. magnifyImage.style.position = 'absolute';
  2620. magnifyImage.style.borderRadius = '16px';
  2621. magnifyImage.style.background = 'white';
  2622. magnifyImage.style.cursor = 'default';
  2623. magnifyImage.style.padding = '2px';
  2624. magnifyImage.style.opacity = '0.8';
  2625. magnifyImage.style.height = '16px';
  2626. magnifyImage.style.right = '2px';
  2627. magnifyImage.style.top = '2px';
  2628. // Shows a tooltip with the rendered template
  2629. var loading = false;
  2630. var extImg = null;
  2631. var wasVisible = false;
  2632. function showTooltip(xml, x, y, elt, title, url)
  2633. {
  2634. // Checks if dialog still visible
  2635. if (xml != null && mxUtils.isAncestorNode(document.body, elt))
  2636. {
  2637. var doc = mxUtils.parseXml(xml);
  2638. var tempNode = Editor.parseDiagramNode(doc.documentElement, null, true);
  2639. var codec = new mxCodec(tempNode.ownerDocument);
  2640. var model = new mxGraphModel();
  2641. codec.decode(tempNode, model);
  2642. var cells = model.root.children;
  2643. var ww = window.innerWidth || document.documentElement.clientWidth || document.body.clientWidth;
  2644. var wh = window.innerHeight || document.documentElement.clientHeight || document.body.clientHeight;
  2645. // TODO: Use maxscreensize
  2646. editorUi.sidebar.createTooltip(elt, cells, Math.min(ww - 120, 1000), Math.min(wh - 120, 800),
  2647. (title != null) ? mxResources.get(title) : null,
  2648. true, new mxPoint(x, y), true, function()
  2649. {
  2650. wasVisible = editorUi.sidebar.tooltip != null &&
  2651. editorUi.sidebar.tooltip.style.display != 'none';
  2652. if (url != null)
  2653. {
  2654. selectElement(elt, null, null, url, infoObj, clibs);
  2655. }
  2656. }, true, false);
  2657. }
  2658. };
  2659. if (recentDocsCallback || searchDocsCallback)
  2660. {
  2661. var tabsEl = [];
  2662. var oldTemplates = null, origCategories = null, origCustomCatCount = null;
  2663. var setActiveTab = function(index)
  2664. {
  2665. createButton.setAttribute('disabled', 'disabled');
  2666. for (var i = 0; i < tabsEl.length; i++)
  2667. {
  2668. if (i == index)
  2669. tabsEl[i].className = 'geBtn gePrimaryBtn';
  2670. else
  2671. tabsEl[i].className = 'geBtn';
  2672. }
  2673. }
  2674. hasTabs = true;
  2675. var tabs = document.createElement('div');
  2676. tabs.style.whiteSpace = 'nowrap';
  2677. tabs.style.height = '30px';
  2678. outer.appendChild(tabs);
  2679. var templatesTab = mxUtils.button(mxResources.get('Templates', null, 'Templates'), function()
  2680. {
  2681. list.style.display = '';
  2682. searchBox.style.display = '';
  2683. div.style.left = '160px';
  2684. setActiveTab(0);
  2685. div.scrollTop = 0;
  2686. div.innerText = '';
  2687. i0 = 0;
  2688. if (oldTemplates != templates)
  2689. {
  2690. templates = oldTemplates;
  2691. categories = origCategories;
  2692. customCatCount = origCustomCatCount;
  2693. list.innerText = '';
  2694. initUi();
  2695. oldTemplates = null;
  2696. }
  2697. });
  2698. tabsEl.push(templatesTab);
  2699. tabs.appendChild(templatesTab);
  2700. var getExtTemplates = function(isSearch)
  2701. {
  2702. list.style.display = 'none';
  2703. searchBox.style.display = 'none';
  2704. div.style.left = '30px';
  2705. setActiveTab(isSearch? -1 : 1); //deselect all of them if isSearch
  2706. if (oldTemplates == null)
  2707. {
  2708. oldTemplates = templates;
  2709. }
  2710. div.scrollTop = 0;
  2711. div.innerText = '';
  2712. spinner.spin(div);
  2713. var callback2 = function(docList, errorMsg, searchImportCats)
  2714. {
  2715. i0 = 0;
  2716. spinner.stop();
  2717. templates = docList;
  2718. searchImportCats = searchImportCats || {};
  2719. var importListsCount = 0;
  2720. for (var cat in searchImportCats)
  2721. {
  2722. importListsCount += searchImportCats[cat].length;
  2723. }
  2724. if (errorMsg)
  2725. {
  2726. div.innerText = errorMsg;
  2727. }
  2728. else if (docList.length == 0 && importListsCount == 0)
  2729. {
  2730. div.innerText = mxResources.get('noDiagrams', null, 'No Diagrams Found');
  2731. }
  2732. else
  2733. {
  2734. div.innerText = '';
  2735. if (importListsCount > 0)
  2736. {
  2737. list.style.display = '';
  2738. div.style.left = '160px';
  2739. list.innerText = '';
  2740. customCatCount = 0;
  2741. categories = {'draw.io': docList};
  2742. for (var cat in searchImportCats)
  2743. {
  2744. categories[cat] = searchImportCats[cat];
  2745. }
  2746. initUi();
  2747. }
  2748. else
  2749. {
  2750. addTemplates(true);
  2751. }
  2752. }
  2753. }
  2754. if (isSearch)
  2755. {
  2756. searchDocsCallback(searchInput.value, callback2);
  2757. }
  2758. else
  2759. {
  2760. recentDocsCallback(callback2);
  2761. }
  2762. }
  2763. if (recentDocsCallback)
  2764. {
  2765. var recentTab = mxUtils.button(mxResources.get('Recent', null, 'Recent'), function()
  2766. {
  2767. getExtTemplates();
  2768. });
  2769. tabs.appendChild(recentTab);
  2770. tabsEl.push(recentTab);
  2771. }
  2772. if (searchDocsCallback)
  2773. {
  2774. var searchTab = document.createElement('span');
  2775. searchTab.style.marginLeft = '10px';
  2776. searchTab.innerText = mxResources.get('search') + ':';
  2777. tabs.appendChild(searchTab);
  2778. var searchInput = document.createElement('input');
  2779. searchInput.style.marginRight = '10px';
  2780. searchInput.style.marginLeft = '10px';
  2781. searchInput.style.width = '220px';
  2782. mxEvent.addListener(searchInput, 'keypress', function(e)
  2783. {
  2784. if (e.keyCode == 13)
  2785. {
  2786. getExtTemplates(true);
  2787. }
  2788. });
  2789. tabs.appendChild(searchInput);
  2790. var searchBtn = mxUtils.button(mxResources.get('search'), function()
  2791. {
  2792. getExtTemplates(true);
  2793. });
  2794. searchBtn.className = 'geBtn';
  2795. tabs.appendChild(searchBtn);
  2796. }
  2797. setActiveTab(0);
  2798. }
  2799. var templateLibs = null;
  2800. var templateClibs = null;
  2801. var templateXml = null;
  2802. var selectedElt = null;
  2803. var templateExtUrl = null;
  2804. var templateRealUrl = null;
  2805. var templateInfoObj = null;
  2806. var lastAiXml = null;
  2807. var lastAiTitle = null;
  2808. function createSmartTemplateContent()
  2809. {
  2810. var content = document.createElement('div');
  2811. content.style.position = 'absolute';
  2812. content.style.overflow = 'visible';
  2813. content.style.left = '8px';
  2814. content.style.right = '8px';
  2815. content.style.bottom = '8px';
  2816. content.style.top = '8px';
  2817. mxUtils.write(content, mxResources.get('describeYourDiagram') + ':');
  2818. mxUtils.br(content);
  2819. var description = document.createElement('input');
  2820. description.setAttribute('type', 'text');
  2821. description.setAttribute('placeholder', mxResources.get('processForHiringNewEmployee'));
  2822. description.style.width = '100%';
  2823. description.style.marginTop = '6px';
  2824. description.style.marginBottom = '4px';
  2825. description.style.boxSizing = 'border-box';
  2826. content.appendChild(description);
  2827. content.init = function()
  2828. {
  2829. description.focus();
  2830. };
  2831. mxUtils.br(content);
  2832. var preview = document.createElement('div');
  2833. preview.style.top = '86px'
  2834. preview.style.left = '2px';
  2835. preview.style.right = '2px';
  2836. preview.style.bottom = '2px';
  2837. preview.style.position = 'absolute';
  2838. preview.style.border = '1px solid #424242';
  2839. var previewText = document.createElement('div');
  2840. previewText.style.boxSizing = 'border-box';
  2841. previewText.style.position = 'relative';
  2842. previewText.style.textAlign = 'center';
  2843. previewText.style.top = '50%';
  2844. mxUtils.write(previewText, mxResources.get('blankDiagram'));
  2845. preview.appendChild(previewText);
  2846. // Adds diagram type options
  2847. var typeSelect = document.createElement('select');
  2848. typeSelect.className = 'geBtn';
  2849. typeSelect.style.maxWidth = '160px';
  2850. typeSelect.style.marginLeft = '0px';
  2851. var option = document.createElement('option');
  2852. mxUtils.write(option, mxResources.get('diagramType'));
  2853. option.setAttribute('value', '');
  2854. typeSelect.appendChild(option);
  2855. for (var i = 0; i < EditorUi.mermaidDiagramTypes.length; i++)
  2856. {
  2857. var option = document.createElement('option');
  2858. var type = EditorUi.mermaidDiagramTypes[i];
  2859. var key = type;
  2860. if (type == urlParams['smart-template-type'])
  2861. {
  2862. option.setAttribute('selected', 'selected');
  2863. }
  2864. // Maps types to translations
  2865. if (key == 'erDiagram')
  2866. {
  2867. key = 'entityRelationshipDiagram';
  2868. }
  2869. var title = mxResources.get(key, null, key.charAt(0).toUpperCase() +
  2870. key.substring(1).replace(/[A-Z]/g, ' $&'));
  2871. option.setAttribute('value', type);
  2872. mxUtils.write(option, title);
  2873. typeSelect.appendChild(option);
  2874. }
  2875. var button = mxUtils.button(mxResources.get('generate'), function()
  2876. {
  2877. var desc = description.value;
  2878. var type = typeSelect.value.replace(/([A-Z])/g, " $1").toLowerCase();
  2879. var prompt = 'Write the declaration code for a detailed and complex ' +
  2880. (type != '' ? type : 'graph') + ' that shows "' + (desc != '' ? desc :
  2881. 'something random') + '" using correct MermaidJS syntax and do not ' +
  2882. 'provide additional text in your response.';
  2883. var type = ((typeSelect.value != '') ? (' (' + mxUtils.trim(
  2884. mxUtils.getTextContent(typeSelect.options[
  2885. typeSelect.selectedIndex])) + ')') : '');
  2886. var useMermaidFormat = typeSelect.value == 'gantt' || typeSelect.value == 'pie' ||
  2887. typeSelect.value == 'timeline' || typeSelect.value == 'quadrantchart' ||
  2888. typeSelect.value == 'c4context';
  2889. var title = description.value + type;
  2890. if (typeof mxMermaidToDrawio !== 'undefined')
  2891. {
  2892. mxMermaidToDrawio.addListener(mxUtils.bind(this, function(modelXml)
  2893. {
  2894. if (!useMermaidFormat)
  2895. {
  2896. templateXml = modelXml;
  2897. lastAiXml = templateXml;
  2898. lastAiTitle = 'Smart Template: ' + title;
  2899. }
  2900. }));
  2901. }
  2902. if (editorUi.spinner.spin(document.body, mxResources.get('loading')))
  2903. {
  2904. editorUi.generateOpenAiMermaidDiagram(prompt,
  2905. function(mermaidData, imageData, w, h)
  2906. {
  2907. editorUi.spinner.stop();
  2908. preview.innerHTML = '';
  2909. var img = document.createElement('img');
  2910. img.setAttribute('title', title);
  2911. img.src = 'data:image/svg+xml;base64,' +
  2912. imageData.substring(imageData.indexOf(',') + 1);
  2913. img.style.cursor = 'pointer';
  2914. img.style.width = '100%';
  2915. img.style.height = '100%';
  2916. preview.appendChild(img);
  2917. var xml = editorUi.createMermaidXml(mermaidData,
  2918. EditorUi.defaultMermaidConfig,
  2919. imageData, w, h, title);
  2920. // Updates template XML for insert button
  2921. var previewXml = '<mxfile><diagram>' + Graph.compress(xml) + '</diagram></mxfile>';
  2922. if (useMermaidFormat || typeof mxMermaidToDrawio === 'undefined')
  2923. {
  2924. templateXml = xml;
  2925. lastAiXml = xml;
  2926. }
  2927. var magnify = magnifyImage.cloneNode(true);
  2928. preview.appendChild(magnify);
  2929. var mouseDownHandler = function(evt)
  2930. {
  2931. wasVisible = editorUi.sidebar.tooltip != null &&
  2932. editorUi.sidebar.tooltip.style.display != 'none';
  2933. };
  2934. var mouseUpHandler = function(evt)
  2935. {
  2936. if (!wasVisible)
  2937. {
  2938. showTooltip(previewXml, mxEvent.getClientX(evt),
  2939. mxEvent.getClientY(evt), img, title);
  2940. }
  2941. };
  2942. mxEvent.addGestureListeners(img, mouseDownHandler, null, mouseUpHandler);
  2943. mxEvent.addGestureListeners(magnify, mouseDownHandler, null, mouseUpHandler);
  2944. }, function(e)
  2945. {
  2946. editorUi.spinner.stop();
  2947. if (mxMermaidToDrawio.resetListeners != null)
  2948. {
  2949. mxMermaidToDrawio.resetListeners();
  2950. }
  2951. editorUi.handleError(e);
  2952. }
  2953. );
  2954. }
  2955. });
  2956. button.setAttribute('disabled', 'disabled');
  2957. button.className = 'geBtn gePrimaryBtn';
  2958. var updateState = function()
  2959. {
  2960. window.setTimeout(function()
  2961. {
  2962. if (description.value != '')
  2963. {
  2964. button.removeAttribute('disabled');
  2965. }
  2966. else
  2967. {
  2968. button.setAttribute('disabled', 'disabled');
  2969. }
  2970. }, 0);
  2971. };
  2972. var temp = urlParams['smart-template'];
  2973. if (temp != null && temp != '1')
  2974. {
  2975. description.value = decodeURIComponent(temp);
  2976. updateState();
  2977. if (urlParams['smart-template-generate'] == '1')
  2978. {
  2979. window.setTimeout(function()
  2980. {
  2981. button.click();
  2982. }, 0);
  2983. }
  2984. }
  2985. mxEvent.addListener(description, 'change', updateState);
  2986. mxEvent.addListener(description, 'keydown', updateState);
  2987. mxEvent.addListener(description, 'cut', updateState);
  2988. mxEvent.addListener(description, 'paste', updateState);
  2989. mxEvent.addListener(description, 'keydown', function(e)
  2990. {
  2991. if (e.keyCode == 13)
  2992. {
  2993. button.click();
  2994. }
  2995. });
  2996. var buttons = document.createElement('div');
  2997. buttons.style.height = '40px';
  2998. buttons.style.marginTop = '4px';
  2999. buttons.style.marginBottom = '4px';
  3000. buttons.style.whiteSpace = 'nowrap';
  3001. buttons.style.overflowX = 'auto';
  3002. buttons.style.overflowY = 'hidden';
  3003. buttons.appendChild(typeSelect);
  3004. buttons.appendChild(button);
  3005. content.appendChild(buttons);
  3006. content.appendChild(preview);
  3007. return content;
  3008. };
  3009. function create()
  3010. {
  3011. if (templateXml != null && templateXml == lastAiXml)
  3012. {
  3013. EditorUi.logEvent({category: 'OPENAI-DIAGRAM',
  3014. action: 'templateGenerated',
  3015. label: lastAiTitle});
  3016. }
  3017. if (templateExtUrl && openExtDocCallback != null)
  3018. {
  3019. if (!showName)
  3020. {
  3021. editorUi.hideDialog();
  3022. }
  3023. openExtDocCallback(templateExtUrl, templateInfoObj, nameInput.value);
  3024. }
  3025. else if (callback)
  3026. {
  3027. if (!showName)
  3028. {
  3029. editorUi.hideDialog();
  3030. }
  3031. callback(templateXml, nameInput.value, templateRealUrl, templateLibs);
  3032. }
  3033. else
  3034. {
  3035. var title = nameInput.value;
  3036. if (title != null && title.length > 0)
  3037. {
  3038. function doSave(mode, folderId, filename)
  3039. {
  3040. editorUi.createFile(filename, templateXml, (templateLibs != null &&
  3041. templateLibs.length > 0) ? templateLibs : null, mode, function()
  3042. {
  3043. editorUi.hideDialog();
  3044. }, null, folderId, null, (templateClibs != null &&
  3045. templateClibs.length > 0) ? templateClibs : null);
  3046. };
  3047. if (editorUi.mode == App.MODE_GOOGLE || editorUi.mode == App.MODE_ONEDRIVE)
  3048. {
  3049. var dlg = new SaveDialog(editorUi, title, mxUtils.bind(this, function(input, mode, folderId)
  3050. {
  3051. doSave(mode, folderId, input.value);
  3052. }), null, null, null, null, editorUi.mode);
  3053. editorUi.showDialog(dlg.container, 420, 150, true, false);
  3054. dlg.init();
  3055. }
  3056. else
  3057. {
  3058. editorUi.pickFolder(editorUi.mode, function(folderId)
  3059. {
  3060. doSave(editorUi.mode, folderId, title);
  3061. }, editorUi.mode != App.MODE_GOOGLE ||
  3062. editorUi.stateArg == null ||
  3063. editorUi.stateArg.folderId == null);
  3064. }
  3065. }
  3066. }
  3067. };
  3068. var div = document.createElement('div');
  3069. div.style.border = '1px solid #d3d3d3';
  3070. div.style.position = 'absolute';
  3071. div.style.left = '160px';
  3072. div.style.right = '34px';
  3073. var divTop = (showName) ? 72 : 40;
  3074. divTop += hasTabs? 30 : 0;
  3075. div.style.top = divTop + 'px';
  3076. div.style.bottom = '68px';
  3077. div.style.margin = '6px 0 0 -1px';
  3078. div.style.padding = '6px';
  3079. div.style.overflow = 'auto';
  3080. var searchBox = document.createElement('div');
  3081. searchBox.style.cssText = 'position:absolute;left:30px;width:128px;top:' + divTop +
  3082. 'px;height:22px;margin-top: 6px;white-space: nowrap;';
  3083. var tmplSearchInput = document.createElement('input');
  3084. tmplSearchInput.style.cssText = 'width:105px;height:16px;border:1px solid #d3d3d3;' +
  3085. 'padding: 3px 20px 3px 3px;font-size: 12px;border-radius:0px;';
  3086. tmplSearchInput.setAttribute('placeholder', mxResources.get('search'));
  3087. tmplSearchInput.setAttribute('type', 'text');
  3088. searchBox.appendChild(tmplSearchInput);
  3089. var cross = document.createElement('img');
  3090. cross.setAttribute('src', Editor.magnifyImage);
  3091. cross.setAttribute('title', mxResources.get('search'));
  3092. cross.className = 'geAdaptiveAsset';
  3093. cross.style.position = 'relative';
  3094. cross.style.cursor = 'pointer';
  3095. cross.style.opacity = '0.5';
  3096. cross.style.height = '16px';
  3097. cross.style.left = '-20px';
  3098. cross.style.top = '4px';
  3099. // Needed to block event transparency in IE
  3100. cross.style.background = 'url(\'' + editorUi.editor.transparentImage + '\')';
  3101. searchBox.appendChild(cross);
  3102. mxEvent.addListener(cross, 'click', function()
  3103. {
  3104. if (cross.getAttribute('src') != Editor.magnifyImage)
  3105. {
  3106. cross.setAttribute('src', Editor.magnifyImage);
  3107. cross.setAttribute('title', mxResources.get('search'));
  3108. tmplSearchInput.value = '';
  3109. resetTemplates();
  3110. }
  3111. tmplSearchInput.focus();
  3112. });
  3113. mxEvent.addListener(tmplSearchInput, 'keydown', mxUtils.bind(this, function(evt)
  3114. {
  3115. if (evt.keyCode == 13 /* Enter */)
  3116. {
  3117. filterTemplates();
  3118. mxEvent.consume(evt);
  3119. }
  3120. }));
  3121. mxEvent.addListener(tmplSearchInput, 'keyup', mxUtils.bind(this, function(evt)
  3122. {
  3123. if (tmplSearchInput.value == '')
  3124. {
  3125. cross.setAttribute('src', Editor.magnifyImage);
  3126. cross.setAttribute('title', mxResources.get('search'));
  3127. }
  3128. else
  3129. {
  3130. cross.setAttribute('src', Editor.crossImage);
  3131. cross.setAttribute('title', mxResources.get('reset'));
  3132. }
  3133. }));
  3134. divTop += 23;
  3135. var list = document.createElement('div');
  3136. list.style.cssText = 'position:absolute;left:30px;width:128px;top:' + divTop + 'px;bottom:68px;margin-top:6px;overflow:auto;border:1px solid #d3d3d3;';
  3137. mxEvent.addListener(div, 'scroll', function()
  3138. {
  3139. editorUi.sidebar.hideTooltip();
  3140. });
  3141. var w = 140;
  3142. var h = w;
  3143. var generateElt = null;
  3144. var generateBackground = 'url(' + Editor.sparklesImage + ')';
  3145. function selectElement(elt, xml, libs, extUrl, infoObj, clibs, realUrl)
  3146. {
  3147. if (selectedElt != elt)
  3148. {
  3149. if (selectedElt != null)
  3150. {
  3151. selectedElt.style.backgroundColor = 'transparent';
  3152. selectedElt.style.border = '2px solid transparent';
  3153. if (selectedElt.getElementsByTagName('table').length > 0)
  3154. {
  3155. selectedElt.getElementsByTagName('table')[0].style.visibility = 'visible';
  3156. }
  3157. if (selectedElt == generateElt)
  3158. {
  3159. generateElt.style.backgroundImage = generateBackground;
  3160. generateElt.style.backgroundPosition = 'center center';
  3161. generateElt.style.backgroundRepeat = 'no-repeat';
  3162. generateElt.style.backgroundSize = 'contain';
  3163. generateInput.style.visibility = 'hidden';
  3164. generateButton.style.visibility = 'hidden';
  3165. helpGenerate.style.visibility = 'hidden';
  3166. editGenerate.style.visibility = 'hidden';
  3167. magnifyGenerate.style.visibility = (lastAiXml != null) ? 'visible' : 'hidden';
  3168. generateElt.getElementsByTagName('table')[0].style.visibility = 'visible';
  3169. }
  3170. }
  3171. if (elt.style.backgroundImage != '' && elt.getElementsByTagName('table').length > 0)
  3172. {
  3173. elt.getElementsByTagName('table')[0].style.visibility = 'hidden';
  3174. }
  3175. if (elt == generateElt)
  3176. {
  3177. xml = lastAiXml;
  3178. if (xml != null)
  3179. {
  3180. magnifyGenerate.style.visibility = 'visible';
  3181. magnifyGenerate.style.visibility = (lastAiXml != null) ? 'visible' : 'hidden';
  3182. editGenerate.style.visibility = 'visible';
  3183. }
  3184. else
  3185. {
  3186. generateInput.style.visibility = 'visible';
  3187. generateButton.style.visibility = 'visible';
  3188. helpGenerate.style.visibility = 'visible';
  3189. editGenerate.style.visibility = 'hidden';
  3190. magnifyGenerate.style.visibility = 'hidden';
  3191. }
  3192. }
  3193. createButton.removeAttribute('disabled');
  3194. templateXml = xml;
  3195. templateLibs = libs;
  3196. templateClibs = clibs;
  3197. selectedElt = elt;
  3198. templateExtUrl = extUrl;
  3199. templateRealUrl = realUrl;
  3200. templateInfoObj = infoObj;
  3201. selectedElt.style.border = rightHighlightBorder;
  3202. return true;
  3203. }
  3204. else
  3205. {
  3206. return false;
  3207. }
  3208. };
  3209. var generateInput = document.createElement('textarea');
  3210. generateInput.setAttribute('placeholder', mxResources.get('describeYourDiagram'));
  3211. generateInput.style.position = 'absolute';
  3212. generateInput.style.fontFamily = 'sans-serif';
  3213. generateInput.style.outline = 'none';
  3214. generateInput.style.left = '0px';
  3215. generateInput.style.right = '0px';
  3216. generateInput.style.top = '0px';
  3217. generateInput.style.bottom = '38px';
  3218. generateInput.style.resize = 'none';
  3219. generateInput.style.boxSizing = 'border-box';
  3220. generateInput.style.fontSize = '12px';
  3221. generateInput.style.border = 'none';
  3222. generateInput.style.margin = '8px';
  3223. var generateButton = document.createElement('button');
  3224. generateButton.className = 'geBtn gePrimaryBtn';
  3225. generateButton.style.position = 'absolute';
  3226. generateButton.style.bottom = '0px';
  3227. generateButton.style.height = '30px';
  3228. generateButton.style.right = '0px';
  3229. generateButton.style.left = '0px';
  3230. generateButton.style.margin = '8px';
  3231. generateButton.style.fontSize = '14px';
  3232. generateButton.style.borderRadius = '4px';
  3233. generateButton.setAttribute('disabled', 'disabled');
  3234. generateButton.setAttribute('title', mxResources.get('ok'));
  3235. mxUtils.write(generateButton, mxResources.get('ok'));
  3236. var magnifyGenerate = magnifyImage.cloneNode(true);
  3237. var generatePreviewWasVisible = false;
  3238. var mouseDownHandler = function(evt)
  3239. {
  3240. generatePreviewWasVisible = editorUi.sidebar.tooltip != null &&
  3241. editorUi.sidebar.tooltip.style.display != 'none';
  3242. };
  3243. var mouseUpHandler = function(evt)
  3244. {
  3245. if (!generatePreviewWasVisible && lastAiXml != null)
  3246. {
  3247. var previewXml = '<mxfile><diagram>' + Graph.compress(lastAiXml) + '</diagram></mxfile>';
  3248. showTooltip(previewXml, mxEvent.getClientX(evt),
  3249. mxEvent.getClientY(evt), generateElt,
  3250. lastAiTitle);
  3251. }
  3252. };
  3253. mxEvent.addGestureListeners(magnifyGenerate, mouseDownHandler, null, mouseUpHandler);
  3254. var editGenerate = magnifyImage.cloneNode(true);
  3255. editGenerate.setAttribute('src', Editor.editImage);
  3256. editGenerate.setAttribute('title', mxResources.get('edit'));
  3257. editGenerate.style.right = '';
  3258. editGenerate.style.left = '2px';
  3259. var helpGenerate = magnifyImage.cloneNode(true);
  3260. helpGenerate.setAttribute('src', Editor.helpImage);
  3261. helpGenerate.setAttribute('title', mxResources.get('help'));
  3262. helpGenerate.style.opacity = '1';
  3263. helpGenerate.style.right = '-8px';
  3264. helpGenerate.style.top = '-8px';
  3265. mxEvent.addListener(helpGenerate, 'click', function(evt)
  3266. {
  3267. editorUi.openLink('https://www.drawio.com/blog/write-query-generate-diagram');
  3268. mxEvent.consume(evt);
  3269. });
  3270. generateInput.style.visibility = 'hidden';
  3271. generateButton.style.visibility = 'hidden';
  3272. editGenerate.style.visibility = 'hidden';
  3273. helpGenerate.style.visibility = 'hidden';
  3274. magnifyGenerate.style.visibility = 'hidden';
  3275. function createGenerate()
  3276. {
  3277. generateElt.style.backgroundImage = '';
  3278. generateElt.getElementsByTagName('table')[0].style.visibility = 'hidden';
  3279. generateInput.style.visibility = 'visible';
  3280. generateButton.style.visibility = 'visible';
  3281. helpGenerate.style.visibility = 'visible';
  3282. editGenerate.style.visibility = 'hidden';
  3283. magnifyGenerate.style.visibility = 'hidden';
  3284. generateInput.focus();
  3285. if (mxClient.IS_GC || mxClient.IS_FF || document.documentMode >= 5)
  3286. {
  3287. generateInput.select();
  3288. }
  3289. else
  3290. {
  3291. document.execCommand('selectAll', false, null);
  3292. }
  3293. };
  3294. mxEvent.addListener(editGenerate, 'click', createGenerate);
  3295. function updateGenerateButtonState()
  3296. {
  3297. if (generateInput.value != '')
  3298. {
  3299. generateButton.removeAttribute('disabled');
  3300. }
  3301. else
  3302. {
  3303. generateButton.setAttribute('disabled', 'disabled');
  3304. }
  3305. };
  3306. mxEvent.addListener(generateInput, 'input', updateGenerateButtonState);
  3307. function stopInput()
  3308. {
  3309. generateInput.style.visibility = 'hidden';
  3310. generateButton.style.visibility = 'hidden';
  3311. helpGenerate.style.visibility = 'hidden';
  3312. generateElt.style.backgroundImage = generateBackground;
  3313. generateElt.style.backgroundSize = 'contain';
  3314. editGenerate.style.visibility = 'visible';
  3315. magnifyGenerate.style.visibility = 'visible';
  3316. };
  3317. function generateDiagram(cancel)
  3318. {
  3319. var desc = mxUtils.trim(generateInput.value);
  3320. if (!cancel && desc != '')
  3321. {
  3322. generateInput.style.visibility = 'hidden';
  3323. generateButton.style.visibility = 'hidden';
  3324. helpGenerate.style.visibility = 'hidden';
  3325. var listenerTriggered = false;
  3326. var prompt = 'Write a detailed and complex MermaidJS declaration for ' +
  3327. '"' + (desc != '' ? desc : 'something random') + '" ' +
  3328. 'using correct MermaidJS syntax and do not ' +
  3329. 'provide additional text in your response.';
  3330. if (typeof mxMermaidToDrawio !== 'undefined')
  3331. {
  3332. mxMermaidToDrawio.addListener(mxUtils.bind(this, function(modelXml)
  3333. {
  3334. if (modelXml != editorUi.emptyDiagramXml)
  3335. {
  3336. listenerTriggered = true;
  3337. templateXml = modelXml;
  3338. }
  3339. }));
  3340. }
  3341. generateElt.style.backgroundImage = 'url(' + Editor.spinImage + ')';
  3342. generateElt.style.backgroundSize = '12px 12px';
  3343. editorUi.generateOpenAiMermaidDiagram(prompt,
  3344. function(mermaidData, imageData, w, h)
  3345. {
  3346. if (selectedElt == generateElt && generateInput.style.visibility == 'hidden')
  3347. {
  3348. generateBackground = 'url(' + 'data:image/svg+xml;base64,' +
  3349. imageData.substring(imageData.indexOf(',') + 1) + ')';
  3350. generateElt.setAttribute('title', desc);
  3351. // Updates template XML for insert button
  3352. var xml = (listenerTriggered) ? templateXml :
  3353. editorUi.createMermaidXml(mermaidData,
  3354. EditorUi.defaultMermaidConfig,
  3355. imageData, w, h, desc);
  3356. templateXml = xml;
  3357. lastAiXml = xml;
  3358. lastAiTitle = desc;
  3359. stopInput();
  3360. }
  3361. }, function(e)
  3362. {
  3363. if (selectedElt == generateElt)
  3364. {
  3365. generateInput.style.visibility = 'visible';
  3366. generateButton.style.visibility = 'visible';
  3367. helpGenerate.style.visibility = 'visible';
  3368. editGenerate.style.visibility = 'visible';
  3369. magnifyGenerate.style.visibility = 'visible';
  3370. editorUi.handleError(e);
  3371. }
  3372. }
  3373. );
  3374. }
  3375. else if (lastAiTitle != null)
  3376. {
  3377. generateInput.value = lastAiTitle;
  3378. stopInput();
  3379. }
  3380. };
  3381. mxEvent.addListener(generateButton, 'click', function()
  3382. {
  3383. generateDiagram();
  3384. });
  3385. mxEvent.addListener(generateInput, 'keydown', function(evt)
  3386. {
  3387. if (evt.keyCode == 13 && !mxEvent.isShiftDown(evt))
  3388. {
  3389. generateDiagram();
  3390. mxEvent.consume(evt);
  3391. }
  3392. else if (evt.keyCode == 27)
  3393. {
  3394. generateDiagram(true);
  3395. mxEvent.consume(evt);
  3396. }
  3397. });
  3398. function addButton(url, libs, title, tooltip, select, imgUrl, infoObj, onClick, preview, noImg, clibs, templateType)
  3399. {
  3400. var elt = null;
  3401. if (templateType != 'generative' || generateElt == null)
  3402. {
  3403. elt = document.createElement('div');
  3404. elt.className = 'geTemplate geAdaptiveAsset';
  3405. elt.style.backgroundOrigin = 'content-box';
  3406. elt.style.backgroundPosition = 'center center';
  3407. elt.style.backgroundRepeat = 'no-repeat';
  3408. elt.style.backgroundSize = 'contain';
  3409. elt.style.boxSizing = 'border-box';
  3410. elt.style.borderRadius = '12px';
  3411. elt.style.position = 'relative';
  3412. elt.style.height = w + 'px';
  3413. elt.style.width = h + 'px';
  3414. elt.style.padding = '4px';
  3415. elt.style.border = '2px solid transparent';
  3416. var xmlData = null, realUrl = url;
  3417. if (title != null)
  3418. {
  3419. elt.setAttribute('title', mxResources.get(title, null, title));
  3420. }
  3421. else if (tooltip != null && tooltip.length > 0)
  3422. {
  3423. elt.setAttribute('title', tooltip);
  3424. }
  3425. }
  3426. else
  3427. {
  3428. elt = generateElt;
  3429. }
  3430. function loadXmlData(url, callback)
  3431. {
  3432. if (xmlData == null)
  3433. {
  3434. realUrl = url;
  3435. if (/^https?:\/\//.test(realUrl))
  3436. {
  3437. realUrl = editorUi.editor.isCorsEnabledForUrl(realUrl) ? realUrl :
  3438. PROXY_URL + '?url=' + encodeURIComponent(realUrl);
  3439. }
  3440. else
  3441. {
  3442. realUrl = TEMPLATE_PATH + '/' + realUrl;
  3443. }
  3444. mxUtils.get(realUrl, mxUtils.bind(this, function(req)
  3445. {
  3446. if (req.getStatus() >= 200 && req.getStatus() <= 299)
  3447. {
  3448. xmlData = req.getText();
  3449. callback(xmlData, realUrl);
  3450. }
  3451. else
  3452. {
  3453. callback(xmlData, realUrl);
  3454. }
  3455. }));
  3456. }
  3457. else
  3458. {
  3459. callback(xmlData, realUrl);
  3460. }
  3461. };
  3462. function loadTooltip(evt, tooltipTitle)
  3463. {
  3464. if (url != null && !loading && editorUi.sidebar.currentElt != elt)
  3465. {
  3466. editorUi.sidebar.hideTooltip();
  3467. if (extImg != null)
  3468. {
  3469. //Create a diagram with the image to use the same code
  3470. //Note: Without compression it doesn't work for some reason. Find out why later
  3471. var xml = '<mxfile><diagram>' + Graph.compress('<mxGraphModel><root><mxCell id="0"/><mxCell id="1" parent="0"/>' +
  3472. '<mxCell id="2" value="" style="shape=image;image=' + extImg.src + ';imageAspect=1;" parent="1" vertex="1">' +
  3473. '<mxGeometry width="' + extImg.naturalWidth + '" height="' + extImg.naturalHeight + '" as="geometry" />' +
  3474. '</mxCell></root></mxGraphModel>') + '</diagram></mxfile>';
  3475. showTooltip(xml, mxEvent.getClientX(evt), mxEvent.getClientY(evt), title, url);
  3476. return;
  3477. }
  3478. editorUi.sidebar.currentElt = elt;
  3479. loading = true;
  3480. loadXmlData(url, function(xml)
  3481. {
  3482. if (loading && editorUi.sidebar.currentElt == elt)
  3483. {
  3484. try
  3485. {
  3486. showTooltip(xml, mxEvent.getClientX(evt),
  3487. mxEvent.getClientY(evt), elt,
  3488. tooltipTitle);
  3489. }
  3490. catch (e)
  3491. {
  3492. editorUi.sidebar.currentElt = null;
  3493. editorUi.handleError(e);
  3494. }
  3495. }
  3496. loading = false;
  3497. });
  3498. }
  3499. else
  3500. {
  3501. editorUi.sidebar.hideTooltip();
  3502. }
  3503. };
  3504. function createTable()
  3505. {
  3506. var table = document.createElement('table');
  3507. table.setAttribute('width', '100%');
  3508. table.setAttribute('height', '100%');
  3509. table.style.background = Editor.isDarkMode() ? 'transparent' : 'rgba(255,255,255,0.85)';
  3510. table.style.lineHeight = '1.3em';
  3511. table.style.border = 'none';
  3512. var tbody = document.createElement('tbody');
  3513. var row = document.createElement('tr');
  3514. var td = document.createElement('td');
  3515. td.setAttribute('align', 'center');
  3516. td.setAttribute('valign', 'middle');
  3517. var span = document.createElement('span');
  3518. span.style.display = 'inline-block';
  3519. span.style.padding = '2px 8px';
  3520. span.style.userSelect = 'none';
  3521. span.style.borderRadius = '8px';
  3522. span.style.background = 'rgba(255,255,255,0.7)';
  3523. span.style.overflow = 'hidden';
  3524. span.style.textOverflow = 'ellipsis';
  3525. span.style.maxWidth = (w - 34) + 'px';
  3526. mxUtils.write(span, mxResources.get(title, null, title));
  3527. td.appendChild(span);
  3528. row.appendChild(td);
  3529. tbody.appendChild(row);
  3530. table.appendChild(tbody);
  3531. return table;
  3532. };
  3533. if (imgUrl != null)
  3534. {
  3535. elt.style.display = 'inline-flex';
  3536. elt.style.justifyContent = 'center';
  3537. elt.style.alignItems = 'center';
  3538. var img = document.createElement('img');
  3539. img.setAttribute('src', imgUrl);
  3540. img.setAttribute('alt', tooltip);
  3541. img.style.maxWidth = w + 'px';
  3542. img.style.maxHeight = h + 'px';
  3543. extImg = img;
  3544. var fallbackImgUrl = imgUrl.replace('.drawio.xml', '').replace('.drawio', '').replace('.xml', '');
  3545. elt.appendChild(img);
  3546. img.onerror = function()
  3547. {
  3548. if (this.src != fallbackImgUrl)
  3549. {
  3550. this.src = fallbackImgUrl;
  3551. }
  3552. else
  3553. {
  3554. this.src = Editor.errorImage;
  3555. this.onerror = null;
  3556. }
  3557. };
  3558. mxEvent.addGestureListeners(elt, mxUtils.bind(this, function(evt)
  3559. {
  3560. selectElement(elt, null, null, url, infoObj, clibs);
  3561. }), null, null);
  3562. mxEvent.addListener(elt, 'dblclick', function(evt)
  3563. {
  3564. create();
  3565. mxEvent.consume(evt);
  3566. });
  3567. }
  3568. else if (!noImg && url != null && url.length > 0)
  3569. {
  3570. var png = preview || (TEMPLATE_PATH + '/' + url.substring(0, url.length - 4) + '.png');
  3571. elt.style.backgroundImage = 'url(' + png + ')';
  3572. if (title != null)
  3573. {
  3574. elt.appendChild(createTable());
  3575. }
  3576. function activate(doCreate)
  3577. {
  3578. if (spinner.spin(div))
  3579. {
  3580. loadXmlData(url, function(xml, realUrl)
  3581. {
  3582. spinner.stop();
  3583. if (xml != null)
  3584. {
  3585. selectElement(elt, xml, libs, null, null, clibs, realUrl);
  3586. if (doCreate)
  3587. {
  3588. create();
  3589. }
  3590. }
  3591. });
  3592. }
  3593. };
  3594. mxEvent.addGestureListeners(elt, mxUtils.bind(this, function(evt)
  3595. {
  3596. activate();
  3597. }), null, null);
  3598. mxEvent.addListener(elt, 'dblclick', function(evt)
  3599. {
  3600. activate(true);
  3601. mxEvent.consume(evt);
  3602. });
  3603. }
  3604. else
  3605. {
  3606. elt.appendChild(createTable());
  3607. if (templateType == 'generative' && generateElt == null)
  3608. {
  3609. elt.style.backgroundImage = generateBackground;
  3610. elt.style.overflow = 'visible';
  3611. elt.appendChild(magnifyGenerate);
  3612. elt.appendChild(editGenerate);
  3613. elt.appendChild(generateInput);
  3614. elt.appendChild(generateButton);
  3615. elt.appendChild(helpGenerate);
  3616. generateElt = elt;
  3617. }
  3618. if (select)
  3619. {
  3620. selectElement(elt);
  3621. }
  3622. if (onClick != null)
  3623. {
  3624. mxEvent.addGestureListeners(elt, null, null, mxUtils.bind(this, function(evt)
  3625. {
  3626. selectElement(elt, null, null, url, infoObj);
  3627. }));
  3628. mxEvent.addListener(elt, 'click', onClick);
  3629. }
  3630. else
  3631. {
  3632. mxEvent.addListener(elt, 'click', function(evt)
  3633. {
  3634. if (selectElement(elt, null, null, url, infoObj) && templateType == 'generative')
  3635. {
  3636. if (lastAiXml == null)
  3637. {
  3638. createGenerate();
  3639. }
  3640. }
  3641. });
  3642. mxEvent.addListener(elt, 'dblclick', function(evt)
  3643. {
  3644. if (templateType != 'generative')
  3645. {
  3646. create();
  3647. }
  3648. else if (generateInput.style.visibility == 'hidden')
  3649. {
  3650. createGenerate();
  3651. }
  3652. mxEvent.consume(evt);
  3653. });
  3654. }
  3655. }
  3656. // Adds preview button
  3657. if (url != null)
  3658. {
  3659. var magnify = magnifyImage.cloneNode(true);
  3660. elt.appendChild(magnify);
  3661. mxEvent.addGestureListeners(magnify, mxUtils.bind(this, function(evt)
  3662. {
  3663. wasVisible = editorUi.sidebar.currentElt == elt;
  3664. }), null, null);
  3665. mxEvent.addListener(magnify, 'click', mxUtils.bind(this, function(evt)
  3666. {
  3667. if (!wasVisible)
  3668. {
  3669. loadTooltip(evt, (title != null) ? title : tooltip);
  3670. }
  3671. mxEvent.consume(evt);
  3672. }));
  3673. }
  3674. div.appendChild(elt);
  3675. return elt;
  3676. };
  3677. var categories = {}, subCategories = {}, customCats = {};
  3678. var customCatCount = 0, firstInitUi = true;
  3679. var currentEntry = null, lastEntry = null;
  3680. // Adds local basic templates
  3681. categories['basic'] = [{title: 'blankDiagram'}];
  3682. var templates = categories['basic'];
  3683. if (Editor.enableChatGpt &&
  3684. editorUi.isExternalDataComms() &&
  3685. editorUi.getServiceName() == 'draw.io' &&
  3686. typeof mxMermaidToDrawio !== 'undefined' &&
  3687. window.isMermaidEnabled)
  3688. {
  3689. categories['basic'].push({title: 'generate', type: 'generative'});
  3690. }
  3691. if (Editor.enableChatGpt &&
  3692. editorUi.isExternalDataComms() &&
  3693. editorUi.getServiceName() == 'draw.io' &&
  3694. typeof mxMermaidToDrawio !== 'undefined' &&
  3695. window.isMermaidEnabled)
  3696. {
  3697. categories['smartTemplate'] = {content: createSmartTemplateContent()};
  3698. }
  3699. function resetTemplates()
  3700. {
  3701. if (lastEntry != null)
  3702. {
  3703. lastEntry.click();
  3704. lastEntry = null;
  3705. }
  3706. };
  3707. function filterTemplates()
  3708. {
  3709. var searchTerms = tmplSearchInput.value;
  3710. if (searchTerms == '')
  3711. {
  3712. resetTemplates();
  3713. return;
  3714. }
  3715. if (NewDialog.tagsList[templateFile] == null)
  3716. {
  3717. var tagsList = {};
  3718. for (var cat in categories)
  3719. {
  3720. if (categories[cat].content == null)
  3721. {
  3722. var templateList = categories[cat];
  3723. for (var i = 0; i < templateList.length; i++)
  3724. {
  3725. var temp = templateList[i];
  3726. if (temp.tags != null)
  3727. {
  3728. var tags = temp.tags.toLowerCase().split(';');
  3729. for (var j = 0; j < tags.length; j++)
  3730. {
  3731. if (tagsList[tags[j]] == null)
  3732. {
  3733. tagsList[tags[j]] = [];
  3734. }
  3735. tagsList[tags[j]].push(temp);
  3736. }
  3737. }
  3738. }
  3739. }
  3740. }
  3741. NewDialog.tagsList[templateFile] = tagsList;
  3742. }
  3743. var tmp = searchTerms.toLowerCase().split(' ');
  3744. tagsList = NewDialog.tagsList[templateFile];
  3745. if (customCatCount > 0 && tagsList.__tagsList__ == null)
  3746. {
  3747. for (var cat in customCats)
  3748. {
  3749. var templateList = customCats[cat];
  3750. for (var i = 0; i < templateList.length; i++)
  3751. {
  3752. var temp = templateList[i];
  3753. var tags = temp.title.split(' ');
  3754. tags.push(cat);
  3755. for (var j = 0; j < tags.length; j++)
  3756. {
  3757. var tag = tags[j].toLowerCase();
  3758. if (tagsList[tag] == null)
  3759. {
  3760. tagsList[tag] = [];
  3761. }
  3762. tagsList[tag].push(temp);
  3763. }
  3764. }
  3765. }
  3766. tagsList.__tagsList__ = true;
  3767. }
  3768. var results = [], resMap = {}, index = 0;
  3769. for (var i = 0; i < tmp.length; i++)
  3770. {
  3771. if (tmp[i].length > 0)
  3772. {
  3773. var list = tagsList[tmp[i]];
  3774. var tmpResMap = {};
  3775. results = [];
  3776. if (list != null)
  3777. {
  3778. for (var j = 0; j < list.length; j++)
  3779. {
  3780. var temp = list[j];
  3781. //ANDing terms
  3782. if ((index == 0) == (resMap[temp.url] == null))
  3783. {
  3784. tmpResMap[temp.url] = true;
  3785. results.push(temp);
  3786. }
  3787. }
  3788. }
  3789. resMap = tmpResMap;
  3790. index++;
  3791. }
  3792. }
  3793. div.scrollTop = 0;
  3794. div.innerText = '';
  3795. i0 = 0;
  3796. var msgDiv = document.createElement('div');
  3797. msgDiv.style.cssText = 'border: 1px solid #D3D3D3; padding: 6px; background: #F5F5F5;';
  3798. mxUtils.write(msgDiv, mxResources.get(results.length == 0 ? 'noResultsFor' : 'resultsFor', [searchTerms]));
  3799. div.appendChild(msgDiv);
  3800. if (currentEntry != null && lastEntry == null)
  3801. {
  3802. currentEntry.style.backgroundColor = '';
  3803. lastEntry = currentEntry;
  3804. currentEntry = msgDiv; //To prevebt NPE later
  3805. }
  3806. templates = results;
  3807. oldTemplates = null;
  3808. addTemplates(false);
  3809. };
  3810. function initUi()
  3811. {
  3812. if (firstInitUi)
  3813. {
  3814. firstInitUi = false;
  3815. mxEvent.addListener(div, 'scroll', function(evt)
  3816. {
  3817. if (div.scrollTop + div.clientHeight >= div.scrollHeight)
  3818. {
  3819. addTemplates();
  3820. mxEvent.consume(evt);
  3821. }
  3822. });
  3823. }
  3824. if (customCatCount > 0)
  3825. {
  3826. var titleCss = 'font-weight: bold;background: #f9f9f9;padding: 5px 0 5px 0;text-align: center;';
  3827. var title = document.createElement('div');
  3828. title.style.cssText = titleCss;
  3829. mxUtils.write(title, mxResources.get('custom'));
  3830. list.appendChild(title);
  3831. for (var cat in customCats)
  3832. {
  3833. var entry = document.createElement('div');
  3834. var label = cat;
  3835. var templateList = customCats[cat];
  3836. if (label.length > 18)
  3837. {
  3838. label = label.substring(0, 18) + '&hellip;';
  3839. }
  3840. entry.style.cssText = 'display:block;cursor:pointer;padding:6px;white-space:nowrap;margin-bottom:-1px;overflow:hidden;text-overflow:ellipsis;user-select:none;';
  3841. entry.setAttribute('title', label + ' (' + templateList.length + ')');
  3842. mxUtils.write(entry, entry.getAttribute('title'));
  3843. if (itemPadding != null)
  3844. {
  3845. entry.style.padding = itemPadding;
  3846. }
  3847. list.appendChild(entry);
  3848. (function(cat2, entry2)
  3849. {
  3850. mxEvent.addListener(entry, 'click', function()
  3851. {
  3852. if (currentEntry != entry2)
  3853. {
  3854. currentEntry.style.backgroundColor = '';
  3855. currentEntry = entry2;
  3856. currentEntry.style.backgroundColor = leftHighlight;
  3857. div.scrollTop = 0;
  3858. div.innerText = '';
  3859. i0 = 0;
  3860. templates = customCats[cat2];
  3861. oldTemplates = null;
  3862. addTemplates(false);
  3863. }
  3864. });
  3865. })(cat, entry);
  3866. }
  3867. title = document.createElement('div');
  3868. title.style.cssText = titleCss;
  3869. mxUtils.write(title, 'draw.io');
  3870. list.appendChild(title);
  3871. }
  3872. function getEntryTitle(cat, templateList)
  3873. {
  3874. var label = mxResources.get(cat, null,
  3875. cat.substring(0, 1).toUpperCase() +
  3876. cat.substring(1));
  3877. if (label.length > 18)
  3878. {
  3879. label = label.substring(0, 18) + '&hellip;';
  3880. }
  3881. return label + ((templateList != null) ?
  3882. ' (' + templateList.length + ')' : '');
  3883. };
  3884. function addEntryHandler(cat, entry, subCat)
  3885. {
  3886. mxEvent.addListener(entry, 'click', function()
  3887. {
  3888. if (currentEntry != entry)
  3889. {
  3890. if (currentEntry != null)
  3891. {
  3892. currentEntry.style.backgroundColor = '';
  3893. }
  3894. currentEntry = entry;
  3895. currentEntry.style.backgroundColor = leftHighlight;
  3896. div.scrollTop = 0;
  3897. div.innerText = '';
  3898. i0 = 0;
  3899. if (categories[cat].content != null)
  3900. {
  3901. div.appendChild(categories[cat].content);
  3902. templateXml = lastAiXml;
  3903. templates = null;
  3904. if (categories[cat].content.init != null)
  3905. {
  3906. categories[cat].content.init();
  3907. }
  3908. }
  3909. else
  3910. {
  3911. templates = subCat? subCategories[cat][subCat] : categories[cat];
  3912. oldTemplates = null;
  3913. addTemplates(false);
  3914. }
  3915. }
  3916. });
  3917. // Selects smart template section
  3918. if (urlParams['smart-template'] != null && cat == 'smartTemplate')
  3919. {
  3920. entry.click();
  3921. }
  3922. };
  3923. for (var cat in categories)
  3924. {
  3925. var templateList = null;
  3926. var clickElem = null;
  3927. if (categories[cat].content != null)
  3928. {
  3929. var entry = document.createElement(subCats? 'ul' : 'div');
  3930. var title = getEntryTitle(cat);
  3931. entry.style.cssText = 'display:block;cursor:pointer;padding:6px;white-space:nowrap;margin-bottom:-1px;overflow:hidden;text-overflow:ellipsis;user-select:none;transition: all 0.5s;';
  3932. entry.setAttribute('title', title);
  3933. mxUtils.write(entry, title);
  3934. list.appendChild(entry);
  3935. clickElem = entry;
  3936. }
  3937. else
  3938. {
  3939. var subCats = subCategories[cat];
  3940. var entry = document.createElement(subCats? 'ul' : 'div');
  3941. var clickElem = entry;
  3942. templateList = categories[cat];
  3943. var entryTitle = getEntryTitle(cat, templateList);
  3944. if (subCats != null)
  3945. {
  3946. var entryLi = document.createElement('li');
  3947. var entryDiv = document.createElement('div');
  3948. entryDiv.className = 'geTempTreeCaret';
  3949. entryDiv.setAttribute('title', entryTitle);
  3950. mxUtils.write(entryDiv, entryTitle);
  3951. clickElem = entryDiv;
  3952. entryLi.appendChild(entryDiv);
  3953. //We support one level deep only
  3954. var subUl = document.createElement('ul');
  3955. subUl.className = 'geTempTreeNested';
  3956. subUl.style.visibility = 'hidden';
  3957. for (var subCat in subCats)
  3958. {
  3959. var subLi = document.createElement('li');
  3960. var subTitle = getEntryTitle(subCat, subCats[subCat]);
  3961. subLi.setAttribute('title', subTitle);
  3962. mxUtils.write(subLi, subTitle);
  3963. addEntryHandler(cat, subLi, subCat);
  3964. subUl.appendChild(subLi);
  3965. }
  3966. entryLi.appendChild(subUl);
  3967. entry.className = 'geTempTree';
  3968. entry.appendChild(entryLi);
  3969. (function(subUl2, entryDiv2)
  3970. {
  3971. mxEvent.addListener(entryDiv2, 'click', function()
  3972. {
  3973. subUl2.style.visibility = 'visible';
  3974. subUl2.classList.toggle('geTempTreeActive');
  3975. if (subUl2.classList.toggle('geTempTreeNested'))
  3976. {
  3977. //Must hide sub elements to allow click on elements above it
  3978. setTimeout(function()
  3979. {
  3980. subUl2.style.visibility = 'hidden';
  3981. }, 550);
  3982. }
  3983. entryDiv2.classList.toggle('geTempTreeCaret-down');
  3984. });
  3985. })(subUl, entryDiv);
  3986. }
  3987. else
  3988. {
  3989. entry.style.cssText = 'display:block;cursor:pointer;padding:6px;white-space:nowrap;margin-bottom:-1px;overflow:hidden;text-overflow:ellipsis;user-select:none;transition: all 0.5s;';
  3990. entry.setAttribute('title', entryTitle);
  3991. mxUtils.write(entry, entryTitle);
  3992. }
  3993. if (itemPadding != null)
  3994. {
  3995. entry.style.padding = itemPadding;
  3996. }
  3997. list.appendChild(entry);
  3998. }
  3999. addEntryHandler(cat, clickElem);
  4000. if (currentEntry == null)
  4001. {
  4002. clickElem.click();
  4003. }
  4004. }
  4005. addTemplates(false);
  4006. };
  4007. if (!compact)
  4008. {
  4009. outer.appendChild(searchBox);
  4010. outer.appendChild(list);
  4011. outer.appendChild(div);
  4012. var indexLoaded = false;
  4013. var realUrl = templateFile;
  4014. if (/^https?:\/\//.test(realUrl) && !editorUi.editor.isCorsEnabledForUrl(realUrl))
  4015. {
  4016. realUrl = PROXY_URL + '?url=' + encodeURIComponent(realUrl);
  4017. }
  4018. function loadDrawioTemplates()
  4019. {
  4020. mxUtils.get(realUrl, function(req)
  4021. {
  4022. // Workaround for index loaded 3 times in iOS offline mode
  4023. if (!indexLoaded)
  4024. {
  4025. indexLoaded = true;
  4026. var tmpDoc = req.getXml();
  4027. var node = tmpDoc.documentElement.firstChild;
  4028. var clibs = {};
  4029. while (node != null)
  4030. {
  4031. if (typeof(node.getAttribute) !== 'undefined')
  4032. {
  4033. if (node.nodeName == 'parsererror')
  4034. {
  4035. if (window.console != null)
  4036. {
  4037. console.log('Parser error in ' +
  4038. templateFile + ': ' +
  4039. node.textContent);
  4040. }
  4041. }
  4042. else if (node.nodeName == 'clibs')
  4043. {
  4044. var name = node.getAttribute('name');
  4045. var adds = node.getElementsByTagName('add');
  4046. var temp = [];
  4047. for (var i = 0; i < adds.length; i++)
  4048. {
  4049. temp.push(encodeURIComponent(mxUtils.getTextContent(adds[i])));
  4050. }
  4051. if (name != null && temp.length > 0)
  4052. {
  4053. clibs[name] = temp.join(';');
  4054. }
  4055. }
  4056. else
  4057. {
  4058. var url = node.getAttribute('url');
  4059. if (url != null)
  4060. {
  4061. var category = node.getAttribute('section');
  4062. var subCategory = node.getAttribute('subsection');
  4063. if (category == null)
  4064. {
  4065. var slash = url.indexOf('/');
  4066. category = url.substring(0, slash);
  4067. if (subCategory == null)
  4068. {
  4069. var nextSlash = url.indexOf('/', slash + 1);
  4070. if (nextSlash > -1)
  4071. {
  4072. subCategory = url.substring(slash + 1, nextSlash);
  4073. }
  4074. }
  4075. }
  4076. var list = categories[category];
  4077. if (list == null)
  4078. {
  4079. list = [];
  4080. categories[category] = list;
  4081. }
  4082. var tempLibs = node.getAttribute('clibs');
  4083. if (clibs[tempLibs] != null)
  4084. {
  4085. tempLibs = clibs[tempLibs];
  4086. }
  4087. var tempObj = {url: node.getAttribute('url'), libs: node.getAttribute('libs'),
  4088. title: node.getAttribute('title'), tooltip: node.getAttribute('name') || node.getAttribute('url'),
  4089. preview: node.getAttribute('preview'), clibs: tempLibs, tags: node.getAttribute('tags')};
  4090. list.push(tempObj);
  4091. if (subCategory != null)
  4092. {
  4093. var subCats = subCategories[category];
  4094. if (subCats == null)
  4095. {
  4096. subCats = {};
  4097. subCategories[category] = subCats;
  4098. }
  4099. var subCatList = subCats[subCategory];
  4100. if (subCatList == null)
  4101. {
  4102. subCatList = [];
  4103. subCats[subCategory] = subCatList;
  4104. }
  4105. subCatList.push(tempObj);
  4106. }
  4107. }
  4108. }
  4109. }
  4110. node = node.nextSibling;
  4111. }
  4112. spinner.stop();
  4113. initUi();
  4114. }
  4115. });
  4116. };
  4117. spinner.spin(div);
  4118. if (customTempCallback != null)
  4119. {
  4120. customTempCallback(function(cats, count)
  4121. {
  4122. customCats = cats;
  4123. customCatCount = count;
  4124. //Custom templates doesn't change after being loaded, so cache them here. Also, only count is overridden
  4125. origCustomCatCount = count;
  4126. loadDrawioTemplates();
  4127. },
  4128. loadDrawioTemplates); //In case of an error, just load draw.io templates only
  4129. }
  4130. else
  4131. {
  4132. loadDrawioTemplates();
  4133. }
  4134. //draw.io templates doesn't change after being loaded, so cache them here
  4135. origCategories = categories;
  4136. }
  4137. mxEvent.addListener(nameInput, 'keypress', function(e)
  4138. {
  4139. if (editorUi.dialog.container.firstChild == outer &&
  4140. e.keyCode == 13)
  4141. {
  4142. create();
  4143. }
  4144. });
  4145. var btns = document.createElement('div');
  4146. btns.style.marginTop = (compact) ? '4px' : '16px';
  4147. btns.style.textAlign = 'right';
  4148. btns.style.position = 'absolute';
  4149. btns.style.left = '40px';
  4150. btns.style.bottom = '24px';
  4151. btns.style.right = '40px';
  4152. var cancelBtn = mxUtils.button(mxResources.get('cancel'), function()
  4153. {
  4154. if (cancelCallback != null)
  4155. {
  4156. cancelCallback();
  4157. }
  4158. editorUi.hideDialog(true);
  4159. });
  4160. cancelBtn.className = 'geBtn';
  4161. if (editorUi.editor.cancelFirst && (!createOnly || cancelCallback != null))
  4162. {
  4163. btns.appendChild(cancelBtn);
  4164. }
  4165. if (!compact && urlParams['embed'] != '1' && !createOnly && !mxClient.IS_ANDROID &&
  4166. !mxClient.IS_IOS && urlParams['noDevice'] != '1')
  4167. {
  4168. var fromTmpBtn = mxUtils.button(mxResources.get('fromTemplateUrl'), function()
  4169. {
  4170. var dlg = new FilenameDialog(editorUi, '', mxResources.get('create'), function(fileUrl)
  4171. {
  4172. if (fileUrl != null && fileUrl.length > 0)
  4173. {
  4174. editorUi.editor.loadUrl(editorUi.editor.getProxiedUrl(fileUrl), function(data)
  4175. {
  4176. templateXml = data;
  4177. templateLibs = null;
  4178. templateRealURl = fileUrl;
  4179. editorUi.hideDialog();
  4180. create();
  4181. }, function(err)
  4182. {
  4183. editorUi.handleError(err);
  4184. });
  4185. }
  4186. }, mxResources.get('url'), null, null, null, false);
  4187. editorUi.showDialog(dlg.container, 300, 80, true, true);
  4188. dlg.init();
  4189. });
  4190. fromTmpBtn.className = 'geBtn';
  4191. btns.appendChild(fromTmpBtn);
  4192. }
  4193. if (Graph.fileSupport && showImport)
  4194. {
  4195. var importBtn = mxUtils.button(mxResources.get('import'), function()
  4196. {
  4197. if (editorUi.newDlgFileInputElt == null)
  4198. {
  4199. var fileInput = document.createElement('input');
  4200. fileInput.setAttribute('multiple', 'multiple');
  4201. fileInput.setAttribute('type', 'file');
  4202. mxEvent.addListener(fileInput, 'change', function(evt)
  4203. {
  4204. editorUi.openFiles(fileInput.files, true);
  4205. fileInput.value = '';
  4206. });
  4207. fileInput.style.display = 'none';
  4208. document.body.appendChild(fileInput);
  4209. editorUi.newDlgFileInputElt = fileInput;
  4210. }
  4211. editorUi.newDlgFileInputElt.click();
  4212. });
  4213. importBtn.className = 'geBtn';
  4214. btns.appendChild(importBtn);
  4215. }
  4216. btns.appendChild(createButton);
  4217. if (!editorUi.editor.cancelFirst && callback == null && (!createOnly || cancelCallback != null))
  4218. {
  4219. btns.appendChild(cancelBtn);
  4220. }
  4221. outer.appendChild(btns);
  4222. this.container = outer;
  4223. };
  4224. NewDialog.tagsList = {};
  4225. /**
  4226. *
  4227. */
  4228. var SaveDialog = function(editorUi, title, saveFn, disabledModes, data, mimeType, base64Encoded, defaultMode)
  4229. {
  4230. var div = document.createElement('div');
  4231. div.style.display = 'flex';
  4232. div.style.flexWrap = 'wrap';
  4233. div.style.whiteSpace = 'nowrap';
  4234. var table = document.createElement('div');
  4235. table.style.display = 'grid';
  4236. table.style.gap = '5px 8px';
  4237. table.style.gridAutoRows = 'auto auto 44px';
  4238. table.style.gridAutoColumns = '0fr minmax(0,1fr)';
  4239. table.style.width = '100%';
  4240. var preview = null;
  4241. var copyBtn = null;
  4242. // Disables SVG preview if SVG is not supported in browser
  4243. if (data != null && mimeType != null && (mimeType.substring(0, 6) == 'image/' &&
  4244. (mimeType.substring(0, 9) != 'image/svg' || mxClient.IS_SVG)))
  4245. {
  4246. table.style.display = 'inline-grid';
  4247. table.style.flexBasis = '75%';
  4248. preview = document.createElement('div');
  4249. preview.style.display = 'inline-block';
  4250. preview.style.height = 'auto';
  4251. preview.style.maxWidth = '25%';
  4252. preview.style.margin = 'auto';
  4253. var img = document.createElement('img');
  4254. var temp = (base64Encoded) ? data : btoa(unescape(encodeURIComponent(data)));
  4255. img.setAttribute('src', 'data:' + mimeType + ';base64,' + temp);
  4256. img.style.boxSizing = 'border-box';
  4257. img.style.maxHeight = '50px';
  4258. img.style.maxWidth = '100%';
  4259. img.style.paddingLeft = '10px';
  4260. preview.appendChild(img);
  4261. if (!mxClient.IS_FF && mimeType == 'image/png' && navigator.clipboard != null &&
  4262. typeof window.ClipboardItem === 'function')
  4263. {
  4264. copyBtn = mxUtils.button(mxResources.get('copy'), function()
  4265. {
  4266. var blob = editorUi.base64ToBlob(temp, 'image/png');
  4267. var html = '<img src="' + 'data:' + mimeType + ';base64,' + temp + '">';
  4268. var cbi = new ClipboardItem({'image/png': blob,
  4269. 'text/html': new Blob([html], {type: 'text/html'})});
  4270. navigator.clipboard.write([cbi]).then(mxUtils.bind(this, function()
  4271. {
  4272. editorUi.alert(mxResources.get('copiedToClipboard'));
  4273. }))['catch'](mxUtils.bind(this, function(e)
  4274. {
  4275. editorUi.handleError(e);
  4276. }));
  4277. }, null, 'geBtn');
  4278. }
  4279. if (Editor.popupsAllowed && (disabledModes == null ||
  4280. mxUtils.indexOf(disabledModes, '_blank') < 0))
  4281. {
  4282. preview.setAttribute('title', mxResources.get('openInNewWindow'));
  4283. preview.style.cursor = 'pointer';
  4284. mxEvent.addGestureListeners(preview, null, null, function(evt)
  4285. {
  4286. if (!mxEvent.isPopupTrigger(evt))
  4287. {
  4288. editorUi.openInNewWindow(data, mimeType, base64Encoded);
  4289. }
  4290. });
  4291. }
  4292. else
  4293. {
  4294. preview.setAttribute('title', mxResources.get('preview'));
  4295. }
  4296. }
  4297. var left = document.createElement('div');
  4298. left.style.display = 'flex';
  4299. left.style.padding = '1px';
  4300. left.style.alignItems = 'center';
  4301. left.style.justifyContent = 'flex-end';
  4302. left.style.gridColumn = '1';
  4303. left.style.whiteSpace = 'nowrap';
  4304. var right = document.createElement('div');
  4305. right.style.display = 'grid';
  4306. right.style.padding = '1px';
  4307. right.style.alignItems = 'center';
  4308. right.style.gridColumn = '2';
  4309. right.style.gridAutoColumns = 'minmax(0,1fr) auto';
  4310. right.style.gap = '6px';
  4311. mxUtils.write(left, mxResources.get('saveAs') + ':');
  4312. var saveAsInput = document.createElement('input');
  4313. saveAsInput.setAttribute('type', 'text');
  4314. saveAsInput.setAttribute('value', title);
  4315. saveAsInput.style.boxSizing = 'border-box';
  4316. saveAsInput.style.width = '100%';
  4317. right.appendChild(saveAsInput);
  4318. table.appendChild(left);
  4319. table.appendChild(right);
  4320. var typeSelect = null;
  4321. if (editorUi.editor.diagramFileTypes != null && mimeType == null)
  4322. {
  4323. left = left.cloneNode(false);
  4324. right = right.cloneNode(false);
  4325. mxUtils.write(left, mxResources.get('type') + ':');
  4326. typeSelect = FilenameDialog.createFileTypes(editorUi, saveAsInput,
  4327. editorUi.editor.diagramFileTypes);
  4328. typeSelect.style.boxSizing = 'border-box';
  4329. typeSelect.style.width = '100%';
  4330. right.appendChild(typeSelect);
  4331. table.appendChild(left);
  4332. table.appendChild(right);
  4333. }
  4334. left = left.cloneNode(false);
  4335. right = right.cloneNode(false);
  4336. mxUtils.write(left, mxResources.get('where') + ':');
  4337. var storageSelect = document.createElement('select');
  4338. storageSelect.style.textOverflow = 'ellipsis';
  4339. storageSelect.style.gridColumn = '1';
  4340. var resetOption = document.createElement('option');
  4341. mxUtils.write(resetOption, mxResources.get('reset'));
  4342. resetOption.setAttribute('value', 'reset');
  4343. var localServices = ['browser', 'device', 'download', '_blank'];
  4344. var dash = '&nbsp;&nbsp;&#8211&nbsp;&nbsp;';
  4345. var dashNode = document.createElement('option');
  4346. dashNode.setAttribute('disabled', 'disabled');
  4347. dashNode.innerHTML = '-----------------';
  4348. function addStorageEntry(mode, path, id, selected, title, entryType)
  4349. {
  4350. var option = null;
  4351. if (disabledModes == null || mxUtils.indexOf(disabledModes, mode) < 0)
  4352. {
  4353. title = (title != null) ? title : editorUi.getTitleForService(mode);
  4354. if (mxUtils.indexOf(localServices, mode) >= 0 ||
  4355. editorUi.getServiceForName(mode) != null)
  4356. {
  4357. option = document.createElement('option');
  4358. if (entryType == 'pick')
  4359. {
  4360. option.innerHTML = mxUtils.htmlEntities(title) + dash +
  4361. mxUtils.htmlEntities(mxResources.get('pickFolder')) + '...';
  4362. option.setAttribute('value', 'pickFolder-' + mode);
  4363. option.setAttribute('title', title + ' - ' +
  4364. mxResources.get('pickFolder') + '...');
  4365. }
  4366. else
  4367. {
  4368. var entryId = mode + ((id != null) ? ('-' + id) : '');
  4369. var entry = entries[entryId];
  4370. if (entry != null && entry.option != null)
  4371. {
  4372. entry.option.parentNode.removeChild(entry.option);
  4373. }
  4374. var shortPath = null;
  4375. if (path != null)
  4376. {
  4377. if (path.charAt(path.length - 1) == '/')
  4378. {
  4379. path = path.substring(0, path.length - 1);
  4380. }
  4381. if (path.charAt(0) == '/')
  4382. {
  4383. path = path.substring(1);
  4384. }
  4385. shortPath = path;
  4386. if (mode != App.MODE_GITHUB && mode == App.MODE_GITLAB)
  4387. {
  4388. var idx = shortPath.lastIndexOf('/');
  4389. if (idx >= 0)
  4390. {
  4391. shortPath = shortPath.substring(idx + 1);
  4392. }
  4393. }
  4394. if (shortPath.length > 40)
  4395. {
  4396. shortPath = shortPath.substring(0, 20) + '...' +
  4397. shortPath.substring(shortPath.length - 20);
  4398. }
  4399. }
  4400. option.innerHTML = mxUtils.htmlEntities(title) + ((shortPath != null) ?
  4401. dash + mxUtils.htmlEntities(shortPath) : '');
  4402. option.setAttribute('title', title + ((path != null) ? ' (' + path + ')' : '') +
  4403. ((id != null && decodeURIComponent(id) != path) ? ' [' + id + ']' : ''));
  4404. option.setAttribute('value', entryId);
  4405. entries[entryId] = {option: option, mode: mode, path: path, id: id};
  4406. if (SaveDialog.lastValue == entryId && defaultMode == null)
  4407. {
  4408. selected = true;
  4409. }
  4410. else if (selected == null)
  4411. {
  4412. if (entryType == 'root')
  4413. {
  4414. selected = (defaultMode == null && editorUi.mode == mode) ||
  4415. (mode != null && mode == defaultMode);
  4416. }
  4417. else if (storageSelect.value.substring(0, 11) == 'pickFolder-')
  4418. {
  4419. selected = true;
  4420. }
  4421. }
  4422. if (selected)
  4423. {
  4424. option.setAttribute('selected', 'selected');
  4425. }
  4426. }
  4427. storageSelect.appendChild(option);
  4428. }
  4429. }
  4430. return option;
  4431. };
  4432. var defaultValue = null;
  4433. function pickFolder(mode)
  4434. {
  4435. editorUi.pickFolder(mode, function(result)
  4436. {
  4437. var entry = null;
  4438. if (mode == App.MODE_GOOGLE && result.docs != null && result.docs.length > 0)
  4439. {
  4440. entry = {mode: mode, path: result.docs[0].name, id: result.docs[0].id};
  4441. }
  4442. else if (mode == App.MODE_ONEDRIVE && result.value != null && result.value.length > 0)
  4443. {
  4444. entry = {mode: mode, path: result.value[0].name,
  4445. id: OneDriveFile.prototype.getIdOf(result.value[0])};
  4446. }
  4447. else if ((mode == App.MODE_GITHUB || mode == App.MODE_GITLAB) &&
  4448. result != null && result.length > 0)
  4449. {
  4450. entry = {mode: mode, path: decodeURIComponent(result), id: result};
  4451. }
  4452. if (entry != null)
  4453. {
  4454. resetOption.style.display = '';
  4455. editorUi.addRecent(entry, 'Folders', 5);
  4456. var option = addStorageEntry(entry.mode, entry.path, entry.id, true);
  4457. storageSelect.innerHTML = '';
  4458. entries = {};
  4459. addStorageEntries();
  4460. // Selects new entry
  4461. var prev = storageSelect.selectedIndex;
  4462. storageSelect.value = option.value;
  4463. // Checks if entry exists
  4464. // LATER: Pass value to select to addStorageEntries
  4465. if (storageSelect.selectedIndex < 0)
  4466. {
  4467. storageSelect.selectedIndex = prev;
  4468. }
  4469. }
  4470. }, true, true, true, true);
  4471. };
  4472. var entries = {};
  4473. function checkExtension()
  4474. {
  4475. if (typeSelect != null && entries[storageSelect.value] != null &&
  4476. editorUi.editor.diagramFileTypes != null &&
  4477. editorUi.editor.diagramFileTypes[typeSelect.value].extension == 'drawio')
  4478. {
  4479. var ext = editorUi.getExtensionForService(entries[storageSelect.value].mode);
  4480. var name = saveAsInput.value;
  4481. if (ext != null && title.indexOf('.') < 0 &&
  4482. name.indexOf('.') < 0)
  4483. {
  4484. saveAsInput.value = name + ext;
  4485. }
  4486. }
  4487. };
  4488. function addStorageEntries()
  4489. {
  4490. var recent = editorUi.getRecent('Folders');
  4491. var recentCount = 0;
  4492. if (recent != null && recent.length > 0)
  4493. {
  4494. for (var i = 0; i < recent.length; i++)
  4495. {
  4496. if (addStorageEntry(recent[i].mode, recent[i].path, recent[i].id) != null)
  4497. {
  4498. recentCount++;
  4499. }
  4500. }
  4501. if (recentCount > 0)
  4502. {
  4503. storageSelect.appendChild(dashNode.cloneNode(true));
  4504. }
  4505. }
  4506. addStorageEntry(App.MODE_GOOGLE, mxResources.get('myDrive'),
  4507. 'root', null, null, 'root');
  4508. addStorageEntry(App.MODE_GOOGLE, null, null, null, null, 'pick');
  4509. if (editorUi.oneDrive != null)
  4510. {
  4511. addStorageEntry(App.MODE_ONEDRIVE, mxResources.get('myFiles'),
  4512. OneDriveFile.prototype.getIdOf(editorUi.oneDrive.rootId),
  4513. null, null, 'root');
  4514. addStorageEntry(App.MODE_ONEDRIVE, null, null, null, null, 'pick');
  4515. }
  4516. if (editorUi.dropbox != null)
  4517. {
  4518. addStorageEntry(App.MODE_DROPBOX, 'Apps' + editorUi.dropbox.appPath);
  4519. }
  4520. addStorageEntry(App.MODE_GITHUB, null, null, null, null, 'pick');
  4521. addStorageEntry(App.MODE_GITLAB, null, null, null, null, 'pick');
  4522. addStorageEntry(App.MODE_TRELLO);
  4523. var allowDevice = !Editor.useLocalStorage || urlParams['storage'] == 'device' ||
  4524. (editorUi.getCurrentFile() != null && urlParams['noDevice'] != '1');
  4525. if (EditorUi.nativeFileSupport && allowDevice)
  4526. {
  4527. addStorageEntry(App.MODE_DEVICE, null, null, editorUi.mode == App.MODE_DEVICE ||
  4528. (disabledModes != null && mxUtils.indexOf(disabledModes,
  4529. App.MODE_BROWSER) >= 0) ? true : null);
  4530. }
  4531. if (isLocalStorage && urlParams['browser'] != '0')
  4532. {
  4533. addStorageEntry(App.MODE_BROWSER);
  4534. }
  4535. if (allowDevice)
  4536. {
  4537. addStorageEntry('download');
  4538. }
  4539. if (Editor.popupsAllowed)
  4540. {
  4541. addStorageEntry('_blank', null, null, null, mxResources.get('openInNewWindow'));
  4542. }
  4543. if (recentCount > 0)
  4544. {
  4545. storageSelect.appendChild(dashNode.cloneNode(true));
  4546. var prev = storageSelect.value;
  4547. storageSelect.appendChild(resetOption);
  4548. storageSelect.value = prev;
  4549. }
  4550. // Adds title to avoid entries that execute an action
  4551. if (storageSelect.value.substring(0, 11) == 'pickFolder-' ||
  4552. storageSelect.value == 'reset')
  4553. {
  4554. var option = document.createElement('option');
  4555. option.setAttribute('value', '');
  4556. option.setAttribute('selected', 'selected');
  4557. mxUtils.write(option, mxResources.get('pickFolder') + '...');
  4558. storageSelect.insertBefore(option, storageSelect.firstChild);
  4559. }
  4560. defaultValue = storageSelect.value;
  4561. };
  4562. var saveBtn = mxUtils.button(mxResources.get('save'), function()
  4563. {
  4564. SaveDialog.lastValue = storageSelect.value;
  4565. var entry = entries[SaveDialog.lastValue];
  4566. if (entry != null)
  4567. {
  4568. saveFn(saveAsInput, entry.mode, entry.id);
  4569. }
  4570. }, null, 'geBtn gePrimaryBtn');
  4571. // Handles enter key
  4572. mxEvent.addListener(saveAsInput, 'keypress', function(e)
  4573. {
  4574. if (e.keyCode == 13)
  4575. {
  4576. saveBtn.click();
  4577. }
  4578. });
  4579. function storageChanged()
  4580. {
  4581. if (storageSelect.value == 'reset')
  4582. {
  4583. editorUi.resetRecent('Folders');
  4584. storageSelect.innerHTML = '';
  4585. storageSelect.value = '';
  4586. pickFolderOption = null;
  4587. entries = {};
  4588. addStorageEntries();
  4589. }
  4590. else if (storageSelect.value.substring(0, 11) == 'pickFolder-')
  4591. {
  4592. var mode = storageSelect.value.substring(11);
  4593. storageSelect.value = defaultValue;
  4594. pickFolder(mode);
  4595. }
  4596. else
  4597. {
  4598. checkExtension();
  4599. }
  4600. saveBtn.innerHTML = '';
  4601. mxUtils.write(saveBtn, mxResources.get((
  4602. storageSelect.value == 'download' ||
  4603. storageSelect.value == '_blank') ?
  4604. 'ok' : 'save'));
  4605. if (storageSelect.value == '')
  4606. {
  4607. saveBtn.setAttribute('disabled', 'disabled');
  4608. }
  4609. else
  4610. {
  4611. saveBtn.removeAttribute('disabled');
  4612. }
  4613. };
  4614. mxEvent.addListener(storageSelect, 'change', storageChanged);
  4615. addStorageEntries();
  4616. storageChanged();
  4617. right.appendChild(storageSelect);
  4618. // Selects last entry
  4619. if (SaveDialog.lastValue != null && entries[SaveDialog.lastValue] != null)
  4620. {
  4621. storageSelect.value = SaveDialog.lastValue;
  4622. }
  4623. table.appendChild(left);
  4624. table.appendChild(right);
  4625. div.appendChild(table);
  4626. if (preview != null)
  4627. {
  4628. div.appendChild(preview);
  4629. }
  4630. var btns = document.createElement('div');
  4631. btns.style.flexBasis = '100%';
  4632. btns.style.textAlign = 'right';
  4633. btns.style.marginTop = (mimeType != null) ? '16px' : '8px';
  4634. if (!editorUi.isOffline() || mxClient.IS_CHROMEAPP)
  4635. {
  4636. btns.appendChild(editorUi.createHelpIcon(
  4637. 'https://www.drawio.com/doc/faq/save-file-formats'));
  4638. }
  4639. var cancelBtn = mxUtils.button(mxResources.get('cancel'), function()
  4640. {
  4641. editorUi.hideDialog();
  4642. }, null, 'geBtn');
  4643. if (editorUi.editor.cancelFirst)
  4644. {
  4645. btns.appendChild(cancelBtn);
  4646. }
  4647. // Copy
  4648. if (copyBtn != null)
  4649. {
  4650. btns.appendChild(copyBtn);
  4651. }
  4652. // Save
  4653. btns.appendChild(saveBtn);
  4654. if (!editorUi.editor.cancelFirst)
  4655. {
  4656. btns.appendChild(cancelBtn);
  4657. }
  4658. div.appendChild(btns);
  4659. this.init = function()
  4660. {
  4661. Editor.selectFilename(saveAsInput);
  4662. };
  4663. this.container = div;
  4664. };
  4665. /**
  4666. * Constructs a dialog for creating new files from a template URL.
  4667. * Also used for dialog choosing where to save or export resources
  4668. */
  4669. var CreateDialog = function(editorUi, title, createFn, cancelFn, dlgTitle, btnLabel, overrideExtension, allowBrowser,
  4670. allowTab, helpLink, showDeviceButton, rowLimit, data, mimeType, base64Encoded, hints, hideDialog)
  4671. {
  4672. showDeviceButton = urlParams['noDevice'] == '1'? false : showDeviceButton;
  4673. overrideExtension = (overrideExtension != null) ? overrideExtension : true;
  4674. allowBrowser = (allowBrowser != null) ? allowBrowser : true;
  4675. rowLimit = (rowLimit != null) ? rowLimit : 4;
  4676. hideDialog = (hideDialog != null) ? hideDialog : true;
  4677. var div = document.createElement('div');
  4678. div.style.whiteSpace = 'nowrap';
  4679. var showButtons = true;
  4680. if (cancelFn == null)
  4681. {
  4682. editorUi.addLanguageMenu(div);
  4683. }
  4684. var h3 = document.createElement('h2');
  4685. mxUtils.write(h3, dlgTitle || mxResources.get('create'));
  4686. h3.style.marginTop = '0px';
  4687. h3.style.marginBottom = '24px';
  4688. div.appendChild(h3);
  4689. var span = document.createElement('span');
  4690. mxUtils.write(span, mxResources.get('filename') + ':');
  4691. span.style.maxWidth = '106px';
  4692. span.style.overflow = 'hidden';
  4693. span.style.textOverflow = 'ellipsis';
  4694. span.style.display = 'inline-block';
  4695. div.appendChild(span);
  4696. var nameInput = document.createElement('input');
  4697. nameInput.setAttribute('value', title);
  4698. nameInput.style.width = '180px';
  4699. nameInput.style.marginLeft = '10px';
  4700. nameInput.style.marginBottom = '20px';
  4701. nameInput.style.maxWidth = '70%';
  4702. this.init = function()
  4703. {
  4704. Editor.selectFilename(nameInput);
  4705. };
  4706. div.appendChild(nameInput);
  4707. if (hints != null && editorUi.editor.diagramFileTypes != null)
  4708. {
  4709. var typeSelect = FilenameDialog.createFileTypes(editorUi, nameInput, editorUi.editor.diagramFileTypes);
  4710. typeSelect.style.marginLeft = '6px';
  4711. typeSelect.style.width = '90px';
  4712. div.appendChild(typeSelect);
  4713. }
  4714. var copyBtn = null;
  4715. // Disables SVG preview if SVG is not supported in browser
  4716. if (urlParams['noDevice'] != '1' && data != null && mimeType != null && (mimeType.substring(0, 6) == 'image/' &&
  4717. (mimeType.substring(0, 9) != 'image/svg' || mxClient.IS_SVG)))
  4718. {
  4719. nameInput.style.width = '160px';
  4720. var preview = document.createElement('img');
  4721. var temp = (base64Encoded) ? data : btoa(unescape(encodeURIComponent(data)));
  4722. preview.setAttribute('src', 'data:' + mimeType + ';base64,' + temp);
  4723. preview.style.position = 'absolute';
  4724. preview.style.top = '70px';
  4725. preview.style.right = '100px';
  4726. preview.style.maxWidth = '120px';
  4727. preview.style.maxHeight = '80px';
  4728. mxUtils.setPrefixedStyle(preview.style, 'transform',
  4729. 'translate(50%,-50%)');
  4730. div.appendChild(preview);
  4731. if (!mxClient.IS_FF && mimeType == 'image/png' && navigator.clipboard != null &&
  4732. typeof window.ClipboardItem === 'function')
  4733. {
  4734. copyBtn = mxUtils.button(mxResources.get('copy'), function(evt)
  4735. {
  4736. var blob = editorUi.base64ToBlob(temp, 'image/png');
  4737. var html = '<img src="' + 'data:' + mimeType + ';base64,' + temp + '">';
  4738. var cbi = new ClipboardItem({'image/png': blob,
  4739. 'text/html': new Blob([html], {type: 'text/html'})});
  4740. navigator.clipboard.write([cbi]).then(mxUtils.bind(this, function()
  4741. {
  4742. editorUi.alert(mxResources.get('copiedToClipboard'));
  4743. }))['catch'](mxUtils.bind(this, function(e)
  4744. {
  4745. editorUi.handleError(e);
  4746. }));
  4747. });
  4748. copyBtn.style.marginTop = '6px';
  4749. copyBtn.className = 'geBtn';
  4750. }
  4751. if (allowTab && Editor.popupsAllowed)
  4752. {
  4753. preview.style.cursor = 'pointer';
  4754. mxEvent.addGestureListeners(preview, null, null, function(evt)
  4755. {
  4756. if (!mxEvent.isPopupTrigger(evt))
  4757. {
  4758. create('_blank');
  4759. }
  4760. });
  4761. }
  4762. }
  4763. mxUtils.br(div);
  4764. var buttons = document.createElement('div');
  4765. buttons.style.textAlign = 'center';
  4766. var count = 0;
  4767. function addLogo(img, title, mode, clientName)
  4768. {
  4769. var button = document.createElement('a');
  4770. button.style.overflow = 'hidden';
  4771. var logo = document.createElement('img');
  4772. logo.src = img;
  4773. logo.setAttribute('border', '0');
  4774. logo.setAttribute('align', 'absmiddle');
  4775. logo.style.width = '60px';
  4776. logo.style.height = '60px';
  4777. logo.style.paddingBottom = '6px';
  4778. button.style.display = 'inline-block';
  4779. button.className = 'geBaseButton';
  4780. button.style.position = 'relative';
  4781. button.style.margin = '4px';
  4782. button.style.padding = '8px 8px 10px 8px';
  4783. button.style.whiteSpace = 'nowrap';
  4784. button.appendChild(logo);
  4785. button.style.color = 'gray';
  4786. button.style.fontSize = '11px';
  4787. var label = document.createElement('div');
  4788. button.appendChild(label);
  4789. mxUtils.write(label, title);
  4790. function initButton()
  4791. {
  4792. mxEvent.addListener(button, 'click', function()
  4793. {
  4794. // Updates extension
  4795. change(mode);
  4796. create(mode);
  4797. });
  4798. };
  4799. // Supports lazy loading
  4800. if (clientName != null && editorUi[clientName] == null)
  4801. {
  4802. logo.style.visibility = 'hidden';
  4803. mxUtils.setOpacity(label, 10);
  4804. var size = 12;
  4805. var spinner = new Spinner({
  4806. lines: 12, // The number of lines to draw
  4807. length: size, // The length of each line
  4808. width: 5, // The line thickness
  4809. radius: 10, // The radius of the inner circle
  4810. rotate: 0, // The rotation offset
  4811. color: '#000', // #rgb or #rrggbb
  4812. speed: 1.5, // Rounds per second
  4813. trail: 60, // Afterglow percentage
  4814. shadow: false, // Whether to render a shadow
  4815. hwaccel: false, // Whether to use hardware acceleration
  4816. top: '40%',
  4817. zIndex: 2e9 // The z-index (defaults to 2000000000)
  4818. });
  4819. spinner.spin(button);
  4820. // Timeout after 30 secs
  4821. var timeout = window.setTimeout(function()
  4822. {
  4823. if (editorUi[clientName] == null)
  4824. {
  4825. spinner.stop();
  4826. button.style.display = 'none';
  4827. }
  4828. }, 30000);
  4829. editorUi.addListener('clientLoaded', mxUtils.bind(this, function()
  4830. {
  4831. if (editorUi[clientName] != null)
  4832. {
  4833. window.clearTimeout(timeout);
  4834. mxUtils.setOpacity(label, 100);
  4835. logo.style.visibility = '';
  4836. spinner.stop();
  4837. initButton();
  4838. }
  4839. }));
  4840. }
  4841. else
  4842. {
  4843. initButton();
  4844. }
  4845. buttons.appendChild(button);
  4846. if (++count == rowLimit)
  4847. {
  4848. mxUtils.br(buttons);
  4849. count = 0;
  4850. }
  4851. };
  4852. if (!showButtons)
  4853. {
  4854. mxUtils.write(div, mxResources.get('chooseAnOption') + ':');
  4855. }
  4856. else
  4857. {
  4858. buttons.style.marginTop = '6px';
  4859. div.appendChild(buttons);
  4860. }
  4861. // Adds all papersize options
  4862. var serviceSelect = document.createElement('select');
  4863. serviceSelect.style.marginLeft = '10px';
  4864. if (!editorUi.isOfflineApp() && !editorUi.isOffline())
  4865. {
  4866. if (typeof window.DriveClient === 'function')
  4867. {
  4868. var googleOption = document.createElement('option');
  4869. googleOption.setAttribute('value', App.MODE_GOOGLE);
  4870. mxUtils.write(googleOption, mxResources.get('googleDrive'));
  4871. serviceSelect.appendChild(googleOption);
  4872. addLogo(IMAGE_PATH + '/google-drive-logo.svg', mxResources.get('googleDrive'), App.MODE_GOOGLE, 'drive');
  4873. }
  4874. if (typeof window.OneDriveClient === 'function')
  4875. {
  4876. var oneDriveOption = document.createElement('option');
  4877. oneDriveOption.setAttribute('value', App.MODE_ONEDRIVE);
  4878. mxUtils.write(oneDriveOption, mxResources.get('oneDrive'));
  4879. serviceSelect.appendChild(oneDriveOption);
  4880. if (editorUi.mode == App.MODE_ONEDRIVE)
  4881. {
  4882. oneDriveOption.setAttribute('selected', 'selected');
  4883. }
  4884. addLogo(IMAGE_PATH + '/onedrive-logo.svg', mxResources.get('oneDrive'), App.MODE_ONEDRIVE, 'oneDrive');
  4885. }
  4886. if (typeof window.DropboxClient === 'function')
  4887. {
  4888. var dropboxOption = document.createElement('option');
  4889. dropboxOption.setAttribute('value', App.MODE_DROPBOX);
  4890. mxUtils.write(dropboxOption, mxResources.get('dropbox'));
  4891. serviceSelect.appendChild(dropboxOption);
  4892. if (editorUi.mode == App.MODE_DROPBOX)
  4893. {
  4894. dropboxOption.setAttribute('selected', 'selected');
  4895. }
  4896. addLogo(IMAGE_PATH + '/dropbox-logo.svg', mxResources.get('dropbox'), App.MODE_DROPBOX, 'dropbox');
  4897. }
  4898. if (editorUi.gitHub != null)
  4899. {
  4900. var gitHubOption = document.createElement('option');
  4901. gitHubOption.setAttribute('value', App.MODE_GITHUB);
  4902. mxUtils.write(gitHubOption, mxResources.get('github'));
  4903. serviceSelect.appendChild(gitHubOption);
  4904. addLogo(IMAGE_PATH + '/github-logo.svg', mxResources.get('github'), App.MODE_GITHUB, 'gitHub');
  4905. }
  4906. if (editorUi.gitLab != null)
  4907. {
  4908. var gitLabOption = document.createElement('option');
  4909. gitLabOption.setAttribute('value', App.MODE_GITLAB);
  4910. mxUtils.write(gitLabOption, mxResources.get('gitlab'));
  4911. serviceSelect.appendChild(gitLabOption);
  4912. addLogo(IMAGE_PATH + '/gitlab-logo.svg', mxResources.get('gitlab'), App.MODE_GITLAB, 'gitLab');
  4913. }
  4914. if (typeof window.TrelloClient === 'function')
  4915. {
  4916. var trelloOption = document.createElement('option');
  4917. trelloOption.setAttribute('value', App.MODE_TRELLO);
  4918. mxUtils.write(trelloOption, mxResources.get('trello'));
  4919. serviceSelect.appendChild(trelloOption);
  4920. addLogo(IMAGE_PATH + '/trello-logo.svg', mxResources.get('trello'), App.MODE_TRELLO, 'trello');
  4921. }
  4922. }
  4923. if (!Editor.useLocalStorage || urlParams['storage'] == 'device' ||
  4924. (editorUi.getCurrentFile() != null/* && !mxClient.IS_IOS*/ && urlParams['noDevice'] != '1'))
  4925. {
  4926. var deviceOption = document.createElement('option');
  4927. deviceOption.setAttribute('value', App.MODE_DEVICE);
  4928. mxUtils.write(deviceOption, mxResources.get('device'));
  4929. serviceSelect.appendChild(deviceOption);
  4930. if (editorUi.mode == App.MODE_DEVICE || !allowBrowser)
  4931. {
  4932. deviceOption.setAttribute('selected', 'selected');
  4933. }
  4934. if (showDeviceButton)
  4935. {
  4936. addLogo(IMAGE_PATH + '/osa_drive-harddisk.png', mxResources.get('device'), App.MODE_DEVICE);
  4937. }
  4938. }
  4939. if (allowBrowser && isLocalStorage && urlParams['browser'] != '0')
  4940. {
  4941. var browserOption = document.createElement('option');
  4942. browserOption.setAttribute('value', App.MODE_BROWSER);
  4943. mxUtils.write(browserOption, mxResources.get('browser'));
  4944. serviceSelect.appendChild(browserOption);
  4945. if (editorUi.mode == App.MODE_BROWSER)
  4946. {
  4947. browserOption.setAttribute('selected', 'selected');
  4948. }
  4949. addLogo(IMAGE_PATH + '/osa_database.png', mxResources.get('browser'), App.MODE_BROWSER);
  4950. }
  4951. function change(newMode)
  4952. {
  4953. if (overrideExtension)
  4954. {
  4955. var fn = nameInput.value;
  4956. var idx = fn.lastIndexOf('.');
  4957. if (title.lastIndexOf('.') < 0 && (!showButtons || idx < 0))
  4958. {
  4959. newMode = (newMode != null) ? newMode : serviceSelect.value;
  4960. var ext = '';
  4961. if (newMode == App.MODE_GOOGLE)
  4962. {
  4963. ext = editorUi.drive.extension;
  4964. }
  4965. else if (newMode == App.MODE_GITHUB)
  4966. {
  4967. ext = editorUi.gitHub.extension;
  4968. }
  4969. else if (newMode == App.MODE_GITLAB)
  4970. {
  4971. ext = editorUi.gitLab.extension;
  4972. }
  4973. else if (newMode == App.MODE_TRELLO)
  4974. {
  4975. ext = editorUi.trello.extension;
  4976. }
  4977. else if (newMode == App.MODE_DROPBOX)
  4978. {
  4979. ext = editorUi.dropbox.extension;
  4980. }
  4981. else if (newMode == App.MODE_ONEDRIVE)
  4982. {
  4983. ext = editorUi.oneDrive.extension;
  4984. }
  4985. else if (newMode == App.MODE_DEVICE)
  4986. {
  4987. ext = '.drawio';
  4988. }
  4989. if (idx >= 0)
  4990. {
  4991. fn = fn.substring(0, idx);
  4992. }
  4993. nameInput.value = fn + ext;
  4994. }
  4995. }
  4996. };
  4997. var btns = document.createElement('div');
  4998. btns.style.marginTop = (showButtons) ? '26px' : '38px';
  4999. btns.style.textAlign = 'center';
  5000. if (!showButtons)
  5001. {
  5002. div.appendChild(serviceSelect);
  5003. mxEvent.addListener(serviceSelect, 'change', change);
  5004. change();
  5005. }
  5006. if (helpLink != null)
  5007. {
  5008. var helpBtn = mxUtils.button(mxResources.get('help'), function()
  5009. {
  5010. editorUi.openLink(helpLink);
  5011. });
  5012. helpBtn.className = 'geBtn';
  5013. btns.appendChild(helpBtn);
  5014. }
  5015. var cancelBtn = mxUtils.button(mxResources.get((cancelFn != null) ? 'close' : 'cancel'), function()
  5016. {
  5017. if (cancelFn != null)
  5018. {
  5019. cancelFn();
  5020. }
  5021. else
  5022. {
  5023. editorUi.fileLoaded(null);
  5024. editorUi.hideDialog();
  5025. window.close();
  5026. window.location.href = editorUi.getUrl();
  5027. }
  5028. });
  5029. cancelBtn.className = 'geBtn';
  5030. if (editorUi.editor.cancelFirst && cancelFn == null)
  5031. {
  5032. btns.appendChild(cancelBtn);
  5033. }
  5034. function create(mode)
  5035. {
  5036. var title = nameInput.value;
  5037. if (mode == null || (title != null && title.length > 0))
  5038. {
  5039. if (hideDialog)
  5040. {
  5041. editorUi.hideDialog();
  5042. }
  5043. createFn(title, mode, nameInput);
  5044. };
  5045. }
  5046. if (cancelFn == null)
  5047. {
  5048. var laterBtn = mxUtils.button(mxResources.get('decideLater'), function()
  5049. {
  5050. create(null);
  5051. });
  5052. laterBtn.className = 'geBtn';
  5053. btns.appendChild(laterBtn);
  5054. }
  5055. if (allowTab && Editor.popupsAllowed)
  5056. {
  5057. var openBtn = mxUtils.button(mxResources.get('openInNewWindow'), function()
  5058. {
  5059. create('_blank');
  5060. });
  5061. openBtn.className = 'geBtn';
  5062. btns.appendChild(openBtn);
  5063. }
  5064. if (CreateDialog.showDownloadButton)
  5065. {
  5066. var downloadButton = mxUtils.button(mxResources.get('download'), function()
  5067. {
  5068. create('download');
  5069. });
  5070. downloadButton.className = 'geBtn';
  5071. btns.appendChild(downloadButton);
  5072. if (copyBtn != null)
  5073. {
  5074. downloadButton.style.marginTop = '6px';
  5075. btns.style.marginTop = '6px';
  5076. }
  5077. }
  5078. if (copyBtn != null)
  5079. {
  5080. mxUtils.br(btns);
  5081. btns.appendChild(copyBtn);
  5082. }
  5083. if (/*!mxClient.IS_IOS || */!showButtons)
  5084. {
  5085. var createBtn = mxUtils.button(btnLabel || mxResources.get('create'), function()
  5086. {
  5087. create((showDeviceButton) ? 'download' : ((showButtons) ? App.MODE_DEVICE : serviceSelect.value));
  5088. });
  5089. createBtn.className = 'geBtn gePrimaryBtn';
  5090. btns.appendChild(createBtn);
  5091. }
  5092. if (!editorUi.editor.cancelFirst || cancelFn != null)
  5093. {
  5094. btns.appendChild(cancelBtn);
  5095. }
  5096. mxEvent.addListener(nameInput, 'keypress', function(e)
  5097. {
  5098. if (e.keyCode == 13)
  5099. {
  5100. create((showButtons) ? App.MODE_DEVICE : serviceSelect.value);
  5101. }
  5102. else if (e.keyCode == 27)
  5103. {
  5104. editorUi.fileLoaded(null);
  5105. editorUi.hideDialog();
  5106. window.close();
  5107. }
  5108. });
  5109. div.appendChild(btns);
  5110. this.container = div;
  5111. };
  5112. /**
  5113. *
  5114. */
  5115. CreateDialog.showDownloadButton = urlParams['noDevice'] != '1';
  5116. /**
  5117. * Constructs a new popup dialog.
  5118. */
  5119. var PopupDialog = function(editorUi, url, pre, fallback, hideDialog)
  5120. {
  5121. hideDialog = (hideDialog != null) ? hideDialog : true;
  5122. var div = document.createElement('div');
  5123. div.style.textAlign = 'left';
  5124. div.style.height = '100%';
  5125. mxUtils.write(div, mxResources.get('fileOpenLocation'));
  5126. mxUtils.br(div);
  5127. mxUtils.br(div);
  5128. var replaceBtn = mxUtils.button(mxResources.get('openInThisWindow'), function()
  5129. {
  5130. if (hideDialog)
  5131. {
  5132. editorUi.hideDialog();
  5133. }
  5134. if (fallback != null)
  5135. {
  5136. fallback();
  5137. }
  5138. });
  5139. replaceBtn.className = 'geBtn';
  5140. replaceBtn.style.marginBottom = '8px';
  5141. replaceBtn.style.width = '280px';
  5142. div.appendChild(replaceBtn);
  5143. mxUtils.br(div);
  5144. var wndBtn = mxUtils.button(mxResources.get('openInNewWindow'), function()
  5145. {
  5146. if (hideDialog)
  5147. {
  5148. editorUi.hideDialog();
  5149. }
  5150. if (pre != null)
  5151. {
  5152. pre();
  5153. }
  5154. editorUi.openLink(url, null, true);
  5155. });
  5156. wndBtn.className = 'geBtn gePrimaryBtn';
  5157. wndBtn.style.width = replaceBtn.style.width;
  5158. div.appendChild(wndBtn);
  5159. mxUtils.br(div);
  5160. mxUtils.br(div);
  5161. mxUtils.write(div, mxResources.get('allowPopups'));
  5162. this.container = div;
  5163. };
  5164. /**
  5165. * Constructs a new image dialog.
  5166. */
  5167. var ImageDialog = function(editorUi, title, initialValue, fn, ignoreExisting, convertDataUri, withCrop, initClipPath)
  5168. {
  5169. convertDataUri = (convertDataUri != null) ? convertDataUri : true;
  5170. var graph = editorUi.editor.graph;
  5171. var div = document.createElement('div');
  5172. mxUtils.write(div, title);
  5173. var inner = document.createElement('div');
  5174. inner.className = 'geTitle';
  5175. inner.style.backgroundColor = 'transparent';
  5176. inner.style.borderColor = 'transparent';
  5177. inner.style.whiteSpace = 'nowrap';
  5178. inner.style.textOverflow = 'clip';
  5179. inner.style.cursor = 'default';
  5180. inner.style.paddingRight = '20px';
  5181. var linkInput = document.createElement('input');
  5182. linkInput.setAttribute('value', initialValue);
  5183. linkInput.setAttribute('type', 'text');
  5184. linkInput.setAttribute('spellcheck', 'false');
  5185. linkInput.setAttribute('autocorrect', 'off');
  5186. linkInput.setAttribute('autocomplete', 'off');
  5187. linkInput.setAttribute('autocapitalize', 'off');
  5188. linkInput.style.marginTop = '6px';
  5189. var realWidth = (Graph.fileSupport) ? 460 : 340;
  5190. linkInput.style.width = realWidth - 20 + 'px';
  5191. linkInput.style.backgroundImage = 'url(\'' + Dialog.prototype.clearImage + '\')';
  5192. linkInput.style.backgroundRepeat = 'no-repeat';
  5193. linkInput.style.backgroundPosition = '100% 50%';
  5194. linkInput.style.paddingRight = '14px';
  5195. var cross = document.createElement('div');
  5196. cross.setAttribute('title', mxResources.get('reset'));
  5197. cross.style.position = 'relative';
  5198. cross.style.left = '-16px';
  5199. cross.style.width = '12px';
  5200. cross.style.height = '14px';
  5201. cross.style.cursor = 'pointer';
  5202. // Workaround for inline-block not supported in IE
  5203. cross.style.display = 'inline-block';
  5204. cross.style.top = '3px';
  5205. // Needed to block event transparency in IE
  5206. cross.style.background = 'url(\'' + editorUi.editor.transparentImage + '\')';
  5207. mxEvent.addListener(cross, 'click', function()
  5208. {
  5209. linkInput.value = '';
  5210. linkInput.focus();
  5211. });
  5212. inner.appendChild(linkInput);
  5213. inner.appendChild(cross);
  5214. div.appendChild(inner);
  5215. var clipPath = initClipPath, cW, cH;
  5216. var insertImage = function(newValue, w, h, resize)
  5217. {
  5218. var dataUri = newValue.substring(0, 5) == 'data:';
  5219. if (!editorUi.isOffline() || (dataUri && typeof chrome === 'undefined'))
  5220. {
  5221. if (newValue.length > 0 && editorUi.spinner.spin(document.body, mxResources.get('inserting')))
  5222. {
  5223. var maxSize = 520;
  5224. editorUi.loadImage(newValue, function(img)
  5225. {
  5226. editorUi.spinner.stop();
  5227. editorUi.hideDialog();
  5228. var s = (resize === false) ? 1 :
  5229. (w != null && h != null) ? Math.max(w / img.width, h / img.height) :
  5230. Math.min(1, Math.min(maxSize / img.width, maxSize / img.height));
  5231. // Handles special case of data URI which needs to be rewritten
  5232. // to be used in a cell style to remove the semicolon
  5233. if (convertDataUri)
  5234. {
  5235. newValue = editorUi.convertDataUri(newValue);
  5236. }
  5237. fn(newValue, Math.round(Number(img.width) * s), Math.round(Number(img.height) * s), clipPath, cW, cH);
  5238. }, function()
  5239. {
  5240. editorUi.spinner.stop();
  5241. fn(null);
  5242. editorUi.showError(mxResources.get('error'), mxResources.get('fileNotFound'), mxResources.get('ok'));
  5243. });
  5244. }
  5245. else
  5246. {
  5247. editorUi.hideDialog();
  5248. fn(newValue, null, null, clipPath, cW, cH);
  5249. }
  5250. }
  5251. else
  5252. {
  5253. newValue = editorUi.convertDataUri(newValue);
  5254. w = (w == null) ? 120 : w;
  5255. h = (h == null) ? 100 : h;
  5256. editorUi.hideDialog();
  5257. fn(newValue, w, h, clipPath, cW, cH);
  5258. }
  5259. };
  5260. var apply = function(newValue, resize)
  5261. {
  5262. if (newValue != null)
  5263. {
  5264. var geo = (ignoreExisting) ? null : graph.getModel().getGeometry(graph.getSelectionCell());
  5265. // Reuses width and height of existing cell
  5266. if (geo != null)
  5267. {
  5268. insertImage(newValue, geo.width, geo.height, resize);
  5269. }
  5270. else
  5271. {
  5272. insertImage(newValue, null, null, resize);
  5273. }
  5274. }
  5275. else
  5276. {
  5277. editorUi.hideDialog();
  5278. fn(null);
  5279. }
  5280. };
  5281. this.init = function()
  5282. {
  5283. linkInput.focus();
  5284. // Installs drag and drop handler for local images and links
  5285. if (Graph.fileSupport)
  5286. {
  5287. linkInput.setAttribute('placeholder', mxResources.get('dragImagesHere'));
  5288. // Setup the dnd listeners
  5289. var dlg = div.parentNode;
  5290. var graph = editorUi.editor.graph;
  5291. var dropElt = null;
  5292. mxEvent.addListener(dlg, 'dragleave', function(evt)
  5293. {
  5294. if (dropElt != null)
  5295. {
  5296. dropElt.parentNode.removeChild(dropElt);
  5297. dropElt = null;
  5298. }
  5299. evt.stopPropagation();
  5300. evt.preventDefault();
  5301. });
  5302. mxEvent.addListener(dlg, 'dragover', mxUtils.bind(this, function(evt)
  5303. {
  5304. // IE 10 does not implement pointer-events so it can't have a drop highlight
  5305. if (dropElt == null && (!mxClient.IS_IE || document.documentMode > 10))
  5306. {
  5307. dropElt = editorUi.highlightElement(dlg);
  5308. }
  5309. evt.stopPropagation();
  5310. evt.preventDefault();
  5311. }));
  5312. mxEvent.addListener(dlg, 'drop', mxUtils.bind(this, function(evt)
  5313. {
  5314. if (dropElt != null)
  5315. {
  5316. dropElt.parentNode.removeChild(dropElt);
  5317. dropElt = null;
  5318. }
  5319. if (evt.dataTransfer.files.length > 0)
  5320. {
  5321. editorUi.importFiles(evt.dataTransfer.files, 0, 0, editorUi.maxImageSize, function(data, mimeType, x, y, w, h, fileName, resize)
  5322. {
  5323. apply(data, resize);
  5324. }, function()
  5325. {
  5326. // No post processing
  5327. }, function(file)
  5328. {
  5329. // Handles only images
  5330. return file.type.substring(0, 6) == 'image/';
  5331. }, function(queue)
  5332. {
  5333. // Invokes elements of queue in order
  5334. for (var i = 0; i < queue.length; i++)
  5335. {
  5336. queue[i]();
  5337. }
  5338. }, !mxEvent.isControlDown(evt), null, null, true);
  5339. }
  5340. else if (mxUtils.indexOf(evt.dataTransfer.types, 'text/uri-list') >= 0)
  5341. {
  5342. var uri = evt.dataTransfer.getData('text/uri-list');
  5343. if ((/\.(gif|jpg|jpeg|tiff|png|svg)($|\?)/i).test(uri))
  5344. {
  5345. apply(decodeURIComponent(uri));
  5346. }
  5347. }
  5348. evt.stopPropagation();
  5349. evt.preventDefault();
  5350. }), false);
  5351. }
  5352. };
  5353. var btns = document.createElement('div');
  5354. btns.style.marginTop = '14px';
  5355. btns.style.textAlign = 'center';
  5356. var cancelBtn = mxUtils.button(mxResources.get('cancel'), function()
  5357. {
  5358. // Just in case a spinner is spinning, has no effect otherwise
  5359. editorUi.spinner.stop();
  5360. editorUi.hideDialog();
  5361. });
  5362. cancelBtn.className = 'geBtn';
  5363. if (editorUi.editor.cancelFirst)
  5364. {
  5365. btns.appendChild(cancelBtn);
  5366. }
  5367. ImageDialog.filePicked = function(data)
  5368. {
  5369. if (data.action == google.picker.Action.PICKED)
  5370. {
  5371. if (data.docs[0].thumbnails != null)
  5372. {
  5373. var thumb = data.docs[0].thumbnails[data.docs[0].thumbnails.length - 1];
  5374. if (thumb != null)
  5375. {
  5376. linkInput.value = thumb.url;
  5377. }
  5378. }
  5379. }
  5380. linkInput.focus();
  5381. };
  5382. if (Graph.fileSupport)
  5383. {
  5384. if (editorUi.imgDlgFileInputElt == null)
  5385. {
  5386. var fileInput = document.createElement('input');
  5387. fileInput.setAttribute('multiple', 'multiple');
  5388. fileInput.setAttribute('type', 'file');
  5389. mxEvent.addListener(fileInput, 'change', function(evt)
  5390. {
  5391. if (fileInput.files != null)
  5392. {
  5393. editorUi.importFiles(fileInput.files, 0, 0, editorUi.maxImageSize, function(data, mimeType, x, y, w, h)
  5394. {
  5395. apply(data);
  5396. }, function()
  5397. {
  5398. // No post processing
  5399. }, function(file)
  5400. {
  5401. // Handles only images
  5402. return file.type.substring(0, 6) == 'image/';
  5403. }, function(queue)
  5404. {
  5405. // Invokes elements of queue in order
  5406. for (var i = 0; i < queue.length; i++)
  5407. {
  5408. queue[i]();
  5409. }
  5410. }, true);
  5411. // Resets input to force change event for same file (type reset required for IE)
  5412. fileInput.type = '';
  5413. fileInput.type = 'file';
  5414. fileInput.value = '';
  5415. }
  5416. });
  5417. fileInput.style.display = 'none';
  5418. document.body.appendChild(fileInput);
  5419. editorUi.imgDlgFileInputElt = fileInput;
  5420. }
  5421. var btn = mxUtils.button(mxResources.get('open'), function()
  5422. {
  5423. editorUi.imgDlgFileInputElt.click();
  5424. });
  5425. btn.className = 'geBtn';
  5426. btns.appendChild(btn);
  5427. }
  5428. mxEvent.addListener(linkInput, 'keypress', function(e)
  5429. {
  5430. if (e.keyCode == 13)
  5431. {
  5432. apply(linkInput.value);
  5433. }
  5434. });
  5435. var cropBtn = mxUtils.button(mxResources.get('crop'), function()
  5436. {
  5437. var dlg = new CropImageDialog(editorUi, linkInput.value, clipPath,
  5438. function(clipPath_p, width, height)
  5439. {
  5440. clipPath = clipPath_p;
  5441. cW = width;
  5442. cH = height;
  5443. });
  5444. editorUi.showDialog(dlg.container, 300, 390, true, true);
  5445. });
  5446. if (withCrop)
  5447. {
  5448. cropBtn.className = 'geBtn';
  5449. btns.appendChild(cropBtn);
  5450. }
  5451. var embedBtn = mxUtils.button(mxResources.get('embed'), function()
  5452. {
  5453. if (linkInput.value.substring(0, 5) != 'data:' && editorUi.spinner.spin(
  5454. document.body, mxResources.get('loading')))
  5455. {
  5456. var converter = editorUi.editor.createImageUrlConverter();
  5457. var src = converter.convert(linkInput.value);
  5458. var img = new Image();
  5459. img.onload = function()
  5460. {
  5461. editorUi.editor.convertImageToDataUri(src, function(uri)
  5462. {
  5463. editorUi.confirmImageResize(function(doResize)
  5464. {
  5465. editorUi.resizeImage(img, uri, mxUtils.bind(this, function(data2, w2, h2)
  5466. {
  5467. editorUi.spinner.stop();
  5468. // Refuses to insert images above a certain size as they kill the app
  5469. if (data2 != null && data2.length < editorUi.maxImageBytes)
  5470. {
  5471. linkInput.value = data2;
  5472. updateButtonStates();
  5473. }
  5474. else
  5475. {
  5476. editorUi.handleError({message: mxResources.get('imageTooBig')});
  5477. }
  5478. }), doResize, editorUi.maxImageSize);
  5479. }, img.width > editorUi.maxImageSize || img.height > editorUi.maxImageSize ||
  5480. uri.length > editorUi.maxImageBytes);
  5481. }, mxUtils.bind(this, function()
  5482. {
  5483. editorUi.handleError({message: mxResources.get('fileNotFound')});
  5484. }));
  5485. };
  5486. img.onerror = function()
  5487. {
  5488. editorUi.spinner.stop();
  5489. editorUi.handleError({message: mxResources.get('fileNotFound')});
  5490. };
  5491. img.src = src;
  5492. }
  5493. });
  5494. function updateButtonStates()
  5495. {
  5496. if (linkInput.value.length > 0)
  5497. {
  5498. cropBtn.removeAttribute('disabled');
  5499. }
  5500. else
  5501. {
  5502. cropBtn.setAttribute('disabled', 'disabled');
  5503. }
  5504. if (linkInput.value.substring(0, 5) != 'data:')
  5505. {
  5506. embedBtn.removeAttribute('disabled');
  5507. }
  5508. else
  5509. {
  5510. embedBtn.setAttribute('disabled', 'disabled');
  5511. }
  5512. };
  5513. embedBtn.className = 'geBtn';
  5514. mxEvent.addListener(linkInput, 'change', function(e)
  5515. {
  5516. clipPath = null;
  5517. updateButtonStates();
  5518. });
  5519. updateButtonStates();
  5520. btns.appendChild(embedBtn);
  5521. var applyBtn = mxUtils.button(mxResources.get('apply'), function()
  5522. {
  5523. apply(linkInput.value);
  5524. });
  5525. applyBtn.className = 'geBtn gePrimaryBtn';
  5526. btns.appendChild(applyBtn);
  5527. if (!editorUi.editor.cancelFirst)
  5528. {
  5529. btns.appendChild(cancelBtn);
  5530. }
  5531. // Shows drop icon in dialog background
  5532. if (Graph.fileSupport)
  5533. {
  5534. btns.style.marginTop = '120px';
  5535. div.style.backgroundImage = 'url(\'' + IMAGE_PATH + '/droptarget.png\')';
  5536. div.style.backgroundPosition = 'center 65%';
  5537. div.style.backgroundRepeat = 'no-repeat';
  5538. var bg = document.createElement('div');
  5539. bg.style.position = 'absolute';
  5540. bg.style.width = '420px';
  5541. bg.style.top = '58%';
  5542. bg.style.textAlign = 'center';
  5543. bg.style.fontSize = '18px';
  5544. bg.style.color = '#a0c3ff';
  5545. mxUtils.write(bg, mxResources.get('dragImagesHere'));
  5546. div.appendChild(bg);
  5547. }
  5548. div.appendChild(btns);
  5549. this.container = div;
  5550. };
  5551. /**
  5552. * Overrides link dialog to add Google Picker.
  5553. */
  5554. var LinkDialog = function(editorUi, initialValue, btnLabel, fn, showPages, showNewWindowOption, linkTarget)
  5555. {
  5556. var div = document.createElement('div');
  5557. div.style.height = '100%';
  5558. mxUtils.write(div, mxResources.get('editLink') + ':');
  5559. var inner = document.createElement('div');
  5560. inner.className = 'geTitle';
  5561. inner.style.backgroundColor = 'transparent';
  5562. inner.style.borderColor = 'transparent';
  5563. inner.style.whiteSpace = 'nowrap';
  5564. inner.style.textOverflow = 'clip';
  5565. inner.style.cursor = 'default';
  5566. var linkInput = document.createElement('input');
  5567. linkInput.setAttribute('placeholder', mxResources.get('dragUrlsHere'));
  5568. linkInput.setAttribute('type', 'text');
  5569. linkInput.style.marginTop = '6px';
  5570. linkInput.style.width = '414px';
  5571. linkInput.style.boxSizing = 'border-box';
  5572. linkInput.style.backgroundImage = 'url(\'' + Dialog.prototype.clearImage + '\')';
  5573. linkInput.style.backgroundRepeat = 'no-repeat';
  5574. linkInput.style.backgroundPosition = '100% 50%';
  5575. linkInput.style.paddingRight = '14px';
  5576. linkInput.style.marginBottom = '4px';
  5577. var cross = document.createElement('div');
  5578. cross.setAttribute('title', mxResources.get('reset'));
  5579. cross.style.position = 'relative';
  5580. cross.style.left = '-16px';
  5581. cross.style.width = '12px';
  5582. cross.style.height = '14px';
  5583. cross.style.cursor = 'pointer';
  5584. // Workaround for inline-block not supported in IE
  5585. cross.style.display = 'inline-block';
  5586. cross.style.top = '3px';
  5587. // Needed to block event transparency in IE
  5588. cross.style.background = 'url(\'' + editorUi.editor.transparentImage + '\')';
  5589. mxEvent.addListener(cross, 'click', function()
  5590. {
  5591. linkInput.value = '';
  5592. linkInput.focus();
  5593. });
  5594. var urlRadio = document.createElement('input');
  5595. urlRadio.style.cssText = 'margin-right:8px;margin-bottom:8px;';
  5596. urlRadio.setAttribute('value', 'url');
  5597. urlRadio.setAttribute('type', 'radio');
  5598. urlRadio.setAttribute('name', 'geLinkDialogOption');
  5599. var pageRadio = document.createElement('input');
  5600. pageRadio.style.cssText = 'margin-right:8px;margin-bottom:8px;';
  5601. pageRadio.setAttribute('value', 'url');
  5602. pageRadio.setAttribute('type', 'radio');
  5603. pageRadio.setAttribute('name', 'geLinkDialogOption');
  5604. var pageSelect = document.createElement('select');
  5605. pageSelect.style.width = '414px';
  5606. var newWindowCheckbox = document.createElement('input');
  5607. newWindowCheckbox.setAttribute('type', 'checkbox');
  5608. newWindowCheckbox.style.margin = '0 6p 0 6px';
  5609. if (linkTarget != null)
  5610. {
  5611. newWindowCheckbox.setAttribute('checked', 'checked');
  5612. newWindowCheckbox.defaultChecked = true;
  5613. }
  5614. linkTarget = (linkTarget != null) ? linkTarget : '_blank';
  5615. newWindowCheckbox.setAttribute('title', linkTarget);
  5616. if (showNewWindowOption)
  5617. {
  5618. linkInput.style.width = '200px';
  5619. }
  5620. if (showPages && editorUi.pages != null)
  5621. {
  5622. if (initialValue != null && Graph.isPageLink(initialValue))
  5623. {
  5624. pageRadio.setAttribute('checked', 'checked');
  5625. pageRadio.defaultChecked = true;
  5626. }
  5627. else
  5628. {
  5629. linkInput.setAttribute('value', initialValue);
  5630. urlRadio.setAttribute('checked', 'checked');
  5631. urlRadio.defaultChecked = true;
  5632. }
  5633. inner.appendChild(urlRadio);
  5634. inner.appendChild(linkInput);
  5635. inner.appendChild(cross);
  5636. if (showNewWindowOption)
  5637. {
  5638. inner.appendChild(newWindowCheckbox);
  5639. mxUtils.write(inner, mxResources.get('openInNewWindow'));
  5640. }
  5641. mxUtils.br(inner);
  5642. inner.appendChild(pageRadio);
  5643. var pageFound = false;
  5644. for (var i = 0; i < editorUi.pages.length; i++)
  5645. {
  5646. var pageOption = document.createElement('option');
  5647. mxUtils.write(pageOption, editorUi.pages[i].getName() ||
  5648. mxResources.get('pageWithNumber', [i + 1]));
  5649. pageOption.setAttribute('value', 'data:page/id,' +
  5650. editorUi.pages[i].getId());
  5651. if (initialValue == pageOption.getAttribute('value'))
  5652. {
  5653. pageOption.setAttribute('selected', 'selected');
  5654. pageFound = true;
  5655. }
  5656. pageSelect.appendChild(pageOption);
  5657. }
  5658. if (!pageFound && pageRadio.checked)
  5659. {
  5660. var notFoundOption = document.createElement('option');
  5661. mxUtils.write(notFoundOption, mxResources.get('pageNotFound'));
  5662. notFoundOption.setAttribute('disabled', 'disabled');
  5663. notFoundOption.setAttribute('selected', 'selected');
  5664. notFoundOption.setAttribute('value', 'pageNotFound');
  5665. pageSelect.appendChild(notFoundOption);
  5666. mxEvent.addListener(pageSelect, 'change', function()
  5667. {
  5668. if (notFoundOption.parentNode != null && !notFoundOption.selected)
  5669. {
  5670. notFoundOption.parentNode.removeChild(notFoundOption);
  5671. }
  5672. });
  5673. }
  5674. inner.appendChild(pageSelect);
  5675. }
  5676. else
  5677. {
  5678. linkInput.setAttribute('value', initialValue);
  5679. inner.appendChild(linkInput);
  5680. inner.appendChild(cross);
  5681. }
  5682. div.appendChild(inner);
  5683. var mainBtn = mxUtils.button(btnLabel, function()
  5684. {
  5685. editorUi.hideDialog();
  5686. var value = (pageRadio.checked) ? ((pageSelect.value !== 'pageNotFound') ?
  5687. pageSelect.value : initialValue) : linkInput.value;
  5688. fn(value, LinkDialog.selectedDocs, (newWindowCheckbox.checked) ? linkTarget : null);
  5689. });
  5690. mainBtn.style.verticalAlign = 'middle';
  5691. mainBtn.className = 'geBtn gePrimaryBtn';
  5692. this.init = function()
  5693. {
  5694. if (pageRadio.checked)
  5695. {
  5696. pageSelect.focus();
  5697. }
  5698. else
  5699. {
  5700. linkInput.focus();
  5701. if (mxClient.IS_GC || mxClient.IS_FF || document.documentMode >= 5)
  5702. {
  5703. linkInput.select();
  5704. }
  5705. else
  5706. {
  5707. document.execCommand('selectAll', false, null);
  5708. }
  5709. }
  5710. mxEvent.addListener(pageSelect, 'focus', function()
  5711. {
  5712. urlRadio.removeAttribute('checked');
  5713. pageRadio.setAttribute('checked', 'checked');
  5714. pageRadio.checked = true;
  5715. });
  5716. mxEvent.addListener(linkInput, 'focus', function()
  5717. {
  5718. pageRadio.removeAttribute('checked');
  5719. urlRadio.setAttribute('checked', 'checked');
  5720. urlRadio.checked = true;
  5721. });
  5722. // Installs drag and drop handler for links
  5723. if (Graph.fileSupport)
  5724. {
  5725. // Setup the dnd listeners
  5726. var dlg = div.parentNode;
  5727. var dropElt = null;
  5728. mxEvent.addListener(dlg, 'dragleave', function(evt)
  5729. {
  5730. if (dropElt != null)
  5731. {
  5732. dropElt.parentNode.removeChild(dropElt);
  5733. dropElt = null;
  5734. }
  5735. evt.stopPropagation();
  5736. evt.preventDefault();
  5737. });
  5738. mxEvent.addListener(dlg, 'dragover', mxUtils.bind(this, function(evt)
  5739. {
  5740. // IE 10 does not implement pointer-events so it can't have a drop highlight
  5741. if (dropElt == null && (!mxClient.IS_IE || document.documentMode > 10))
  5742. {
  5743. dropElt = editorUi.highlightElement(dlg);
  5744. }
  5745. evt.stopPropagation();
  5746. evt.preventDefault();
  5747. }));
  5748. mxEvent.addListener(dlg, 'drop', mxUtils.bind(this, function(evt)
  5749. {
  5750. try
  5751. {
  5752. if (dropElt != null)
  5753. {
  5754. dropElt.parentNode.removeChild(dropElt);
  5755. dropElt = null;
  5756. }
  5757. if (mxUtils.indexOf(evt.dataTransfer.types, 'text/uri-list') >= 0)
  5758. {
  5759. linkInput.value = decodeURIComponent(evt.dataTransfer.getData('text/uri-list'));
  5760. urlRadio.setAttribute('checked', 'checked');
  5761. urlRadio.checked = true;
  5762. mainBtn.click();
  5763. }
  5764. }
  5765. catch (e)
  5766. {
  5767. editorUi.handleError(e);
  5768. }
  5769. evt.stopPropagation();
  5770. evt.preventDefault();
  5771. }), false);
  5772. }
  5773. };
  5774. var btns = document.createElement('div');
  5775. btns.style.marginTop = '16px';
  5776. btns.style.textAlign = 'right';
  5777. if (!editorUi.isOffline())
  5778. {
  5779. btns.appendChild(editorUi.createHelpIcon('https://www.drawio.com/doc/faq/custom-links'));
  5780. }
  5781. var cancelBtn = mxUtils.button(mxResources.get('cancel'), function()
  5782. {
  5783. editorUi.hideDialog();
  5784. });
  5785. cancelBtn.style.verticalAlign = 'middle';
  5786. cancelBtn.className = 'geBtn';
  5787. if (editorUi.editor.cancelFirst)
  5788. {
  5789. btns.appendChild(cancelBtn);
  5790. }
  5791. LinkDialog.selectedDocs = null;
  5792. LinkDialog.filePicked = function(data)
  5793. {
  5794. if (data.action == google.picker.Action.PICKED)
  5795. {
  5796. LinkDialog.selectedDocs = data.docs;
  5797. var href = data.docs[0].url;
  5798. if (data.docs[0].mimeType == 'application/mxe' || (data.docs[0].mimeType != null &&
  5799. data.docs[0].mimeType.substring(0, 23) == 'application/vnd.jgraph.'))
  5800. {
  5801. href = 'https://www.draw.io/#G' + data.docs[0].id;
  5802. }
  5803. else if (data.docs[0].mimeType == 'application/vnd.google-apps.folder')
  5804. {
  5805. // Do not use folderview in data.docs[0].url link to Google Drive instead
  5806. href = 'https://drive.google.com/#folders/' + data.docs[0].id;
  5807. }
  5808. linkInput.value = href;
  5809. linkInput.focus();
  5810. }
  5811. else
  5812. {
  5813. LinkDialog.selectedDocs = null;
  5814. }
  5815. linkInput.focus();
  5816. };
  5817. var selectDropdown = document.createElement('select');
  5818. selectDropdown.className = 'geBtn';
  5819. selectDropdown.style.position = 'relative';
  5820. selectDropdown.style.top = '1px';
  5821. selectDropdown.style.maxWidth = '120px';
  5822. var selectFn = {};
  5823. var option = document.createElement('option');
  5824. mxUtils.write(option, mxResources.get('select') + '...');
  5825. option.value = '';
  5826. selectDropdown.appendChild(option);
  5827. function addButton(key, fn)
  5828. {
  5829. var option = document.createElement('option');
  5830. mxUtils.write(option, mxResources.get(key));
  5831. option.value = key;
  5832. selectDropdown.appendChild(option);
  5833. selectFn[key] = fn;
  5834. };
  5835. if (typeof(google) != 'undefined' && typeof(google.picker) != 'undefined' && editorUi.drive != null)
  5836. {
  5837. addButton('googleDrive', function()
  5838. {
  5839. if (editorUi.spinner.spin(document.body, mxResources.get('authorizing')))
  5840. {
  5841. editorUi.drive.checkToken(mxUtils.bind(this, function()
  5842. {
  5843. editorUi.spinner.stop();
  5844. // Creates one picker and reuses it to avoid polluting the DOM
  5845. if (editorUi.linkPicker == null)
  5846. {
  5847. var picker = editorUi.drive.createLinkPicker();
  5848. editorUi.linkPicker = picker.setCallback(function(data)
  5849. {
  5850. LinkDialog.filePicked(data);
  5851. }).build();
  5852. }
  5853. editorUi.linkPicker.setVisible(true);
  5854. }));
  5855. }
  5856. });
  5857. }
  5858. if (typeof(Dropbox) != 'undefined' && typeof(Dropbox.choose) != 'undefined')
  5859. {
  5860. addButton('dropbox', function()
  5861. {
  5862. // Authentication will be carried out on open to make sure the
  5863. // autosave does not show an auth dialog. Showing it here will
  5864. // block the second dialog (the file picker) so it's too early.
  5865. Dropbox.choose(
  5866. {
  5867. linkType : 'direct',
  5868. cancel: function()
  5869. {
  5870. // do nothing
  5871. },
  5872. success : function(files)
  5873. {
  5874. linkInput.value = files[0].link;
  5875. linkInput.focus();
  5876. }
  5877. });
  5878. });
  5879. }
  5880. if (editorUi.oneDrive != null)
  5881. {
  5882. addButton('oneDrive', function()
  5883. {
  5884. editorUi.oneDrive.pickFile(function(id, files)
  5885. {
  5886. if (files != null && files.value != null && files.value.length > 0)
  5887. {
  5888. linkInput.value = files.value[0].webUrl;
  5889. linkInput.focus();
  5890. }
  5891. }, true);
  5892. });
  5893. }
  5894. if (editorUi.gitHub != null)
  5895. {
  5896. addButton('github', function()
  5897. {
  5898. editorUi.gitHub.pickFile(function(path)
  5899. {
  5900. if (path != null)
  5901. {
  5902. var tokens = path.split('/');
  5903. var org = tokens[0];
  5904. var repo = tokens[1];
  5905. var ref = tokens[2];
  5906. var path = tokens.slice(3, tokens.length).join('/');
  5907. linkInput.value = 'https://github.com/' + org + '/' +
  5908. repo + '/blob/' + ref + '/' + path;
  5909. linkInput.focus();
  5910. }
  5911. });
  5912. });
  5913. }
  5914. if (editorUi.gitLab != null)
  5915. {
  5916. addButton('gitlab', function()
  5917. {
  5918. editorUi.gitLab.pickFile(function(path)
  5919. {
  5920. if (path != null)
  5921. {
  5922. var tokens = path.split('/');
  5923. var org = tokens[0];
  5924. var repo = tokens[1];
  5925. var ref = tokens[2];
  5926. var path = tokens.slice(3, tokens.length).join('/');
  5927. linkInput.value = DRAWIO_GITLAB_URL + '/' + org + '/' +
  5928. repo + '/blob/' + ref + '/' + path;
  5929. linkInput.focus();
  5930. }
  5931. });
  5932. });
  5933. }
  5934. if (selectDropdown.children.length > 1)
  5935. {
  5936. btns.appendChild(selectDropdown);
  5937. mxEvent.addListener(selectDropdown, 'change', function(evt)
  5938. {
  5939. if (selectFn[selectDropdown.value] != null)
  5940. {
  5941. selectFn[selectDropdown.value]();
  5942. selectDropdown.value = '';
  5943. }
  5944. });
  5945. }
  5946. mxEvent.addListener(linkInput, 'keypress', function(e)
  5947. {
  5948. if (e.keyCode == 13)
  5949. {
  5950. mainBtn.click();
  5951. }
  5952. });
  5953. btns.appendChild(mainBtn);
  5954. if (!editorUi.editor.cancelFirst)
  5955. {
  5956. btns.appendChild(cancelBtn);
  5957. }
  5958. div.appendChild(btns);
  5959. this.container = div;
  5960. };
  5961. /**
  5962. * Constructs a new about dialog
  5963. */
  5964. var FeedbackDialog = function(editorUi, subject, emailOptional, diagramData)
  5965. {
  5966. var div = document.createElement('div');
  5967. var label = document.createElement('div');
  5968. mxUtils.write(label, mxResources.get('sendYourFeedback'));
  5969. label.style.fontSize = '18px';
  5970. label.style.marginBottom = '18px';
  5971. div.appendChild(label);
  5972. label = document.createElement('div');
  5973. mxUtils.write(label, mxResources.get('yourEmailAddress') +
  5974. ((emailOptional) ? '' : ' (' + mxResources.get('required') + ')'));
  5975. div.appendChild(label);
  5976. var email = document.createElement('input');
  5977. email.setAttribute('type', 'text');
  5978. email.style.marginTop = '6px';
  5979. email.style.width = '600px';
  5980. var sendButton = mxUtils.button(mxResources.get('sendMessage'), function()
  5981. {
  5982. var diagram = textarea.value +
  5983. ((cb.checked) ? '\nDiagram:\n' + ((diagramData != null) ?
  5984. diagramData : mxUtils.getXml(editorUi.getXmlFileData())) : '') +
  5985. '\nuserAgent:\n' + navigator.userAgent +
  5986. '\nappVersion:\n' + navigator.appVersion +
  5987. '\nappName:\n' + navigator.appName +
  5988. '\nplatform:\n' + navigator.platform;
  5989. if (diagram.length > FeedbackDialog.maxAttachmentSize)
  5990. {
  5991. editorUi.alert(mxResources.get('drawingTooLarge'));
  5992. }
  5993. else
  5994. {
  5995. editorUi.hideDialog();
  5996. if (editorUi.spinner.spin(document.body))
  5997. {
  5998. var postUrl = (FeedbackDialog.feedbackUrl != null) ? FeedbackDialog.feedbackUrl : '/email';
  5999. mxUtils.post(postUrl, 'email=' + encodeURIComponent(email.value) +
  6000. '&version=' + encodeURIComponent(EditorUi.VERSION) +
  6001. '&url=' + encodeURIComponent(window.location.href) +
  6002. '&body=' + encodeURIComponent(((subject != null) ?
  6003. subject : 'Feedback') + ':\n' + diagram),
  6004. function(req)
  6005. {
  6006. editorUi.spinner.stop();
  6007. if (req.getStatus() >= 200 && req.getStatus() <= 299)
  6008. {
  6009. editorUi.alert(mxResources.get('feedbackSent'));
  6010. }
  6011. else
  6012. {
  6013. editorUi.alert(mxResources.get('errorSendingFeedback'));
  6014. }
  6015. },
  6016. function()
  6017. {
  6018. editorUi.spinner.stop();
  6019. editorUi.alert(mxResources.get('errorSendingFeedback'));
  6020. });
  6021. }
  6022. }
  6023. });
  6024. sendButton.className = 'geBtn gePrimaryBtn';
  6025. if (!emailOptional)
  6026. {
  6027. sendButton.setAttribute('disabled', 'disabled');
  6028. var re = /^(([^<>()[\]\\.,;:\s@\"]+(\.[^<>()[\]\\.,;:\s@\"]+)*)|(\".+\"))@((\[[0-9]{1,3}\.[0-9]{1,3}\.[0-9]{1,3}\.[0-9]{1,3}\])|(([a-zA-Z\-0-9]+\.)+[a-zA-Z]{2,}))$/;
  6029. mxEvent.addListener(email, 'change', function()
  6030. {
  6031. if (email.value.length > 0 && re.test(email.value) > 0)
  6032. {
  6033. sendButton.removeAttribute('disabled');
  6034. }
  6035. else
  6036. {
  6037. sendButton.setAttribute('disabled', 'disabled');
  6038. }
  6039. });
  6040. mxEvent.addListener(email, 'keyup', function()
  6041. {
  6042. if (email.value.length > 0 && re.test(email.value))
  6043. {
  6044. sendButton.removeAttribute('disabled');
  6045. }
  6046. else
  6047. {
  6048. sendButton.setAttribute('disabled', 'disabled');
  6049. }
  6050. });
  6051. }
  6052. div.appendChild(email);
  6053. this.init = function()
  6054. {
  6055. email.focus();
  6056. };
  6057. var cb = document.createElement('input');
  6058. cb.setAttribute('type', 'checkbox');
  6059. cb.setAttribute('checked', 'checked');
  6060. cb.defaultChecked = true;
  6061. var p2 = document.createElement('p');
  6062. p2.style.marginTop = '14px';
  6063. p2.appendChild(cb);
  6064. var span = document.createElement('span');
  6065. mxUtils.write(span, ' ' + mxResources.get('includeCopyOfMyDiagram'));
  6066. p2.appendChild(span);
  6067. mxEvent.addListener(span, 'click', function(evt)
  6068. {
  6069. cb.checked = !cb.checked;
  6070. mxEvent.consume(evt);
  6071. });
  6072. div.appendChild(p2);
  6073. label = document.createElement('div');
  6074. mxUtils.write(label, mxResources.get('feedback'));
  6075. div.appendChild(label);
  6076. var textarea = document.createElement('textarea');
  6077. textarea.style.resize = 'none';
  6078. textarea.style.width = '600px';
  6079. textarea.style.height = '140px';
  6080. textarea.style.marginTop = '6px';
  6081. textarea.setAttribute('placeholder', mxResources.get('comments'));
  6082. div.appendChild(textarea);
  6083. var buttons = document.createElement('div');
  6084. buttons.style.marginTop = '26px';
  6085. buttons.style.textAlign = 'right';
  6086. var cancelBtn = mxUtils.button(mxResources.get('cancel'), function()
  6087. {
  6088. editorUi.hideDialog();
  6089. });
  6090. cancelBtn.className = 'geBtn';
  6091. if (editorUi.editor.cancelFirst)
  6092. {
  6093. buttons.appendChild(cancelBtn);
  6094. buttons.appendChild(sendButton);
  6095. }
  6096. else
  6097. {
  6098. buttons.appendChild(sendButton);
  6099. buttons.appendChild(cancelBtn);
  6100. }
  6101. div.appendChild(buttons);
  6102. this.container = div;
  6103. };
  6104. /**
  6105. * Maximum size of attachments in bytes. Default is 1000000.
  6106. */
  6107. FeedbackDialog.maxAttachmentSize = 1000000;
  6108. /**
  6109. * Constructs a new revision dialog
  6110. */
  6111. var RevisionDialog = function(editorUi, revs, restoreFn)
  6112. {
  6113. var div = document.createElement('div');
  6114. var title = document.createElement('h3');
  6115. title.style.marginTop = '3px';
  6116. mxUtils.write(title, mxResources.get('revisionHistory'));
  6117. div.appendChild(title);
  6118. var list = document.createElement('div');
  6119. list.style.position = 'absolute';
  6120. list.style.overflow = 'auto';
  6121. list.style.width = '170px';
  6122. list.style.height = '378px';
  6123. div.appendChild(list);
  6124. var container = document.createElement('div');
  6125. container.style.position = 'absolute';
  6126. container.style.border = '1px solid lightGray';
  6127. container.style.left = '200px';
  6128. container.style.width = '470px';
  6129. container.style.height = '376px';
  6130. container.style.overflow = 'hidden';
  6131. // Contains possible error messages
  6132. var errorNode = document.createElement('div');
  6133. errorNode.style.position = 'absolute',
  6134. errorNode.style.display = 'none';
  6135. errorNode.style.textAlign = 'center';
  6136. errorNode.style.padding = '8px';
  6137. errorNode.style.borderRadius = '8px';
  6138. errorNode.style.left = '50%';
  6139. errorNode.style.top = '50%';
  6140. errorNode.style.whiteSpace = 'nowrap';
  6141. errorNode.style.transform = 'translate(-50%, -50%)';
  6142. errorNode.style.background = 'inherit';
  6143. errorNode.style.border = '1px solid';
  6144. container.appendChild(errorNode);
  6145. mxEvent.disableContextMenu(container);
  6146. div.appendChild(container);
  6147. var graph = new Graph(container);
  6148. graph.setTooltips(false);
  6149. graph.setEnabled(false);
  6150. graph.setPanning(true);
  6151. graph.panningHandler.ignoreCell = true;
  6152. graph.panningHandler.useLeftButtonForPanning = true;
  6153. graph.minFitScale = null;
  6154. graph.maxFitScale = null;
  6155. graph.centerZoom = true;
  6156. // Handles placeholders for pages
  6157. var currentPage = 0;
  6158. var diagrams = null;
  6159. var realPage = 0;
  6160. var graphGetGlobalVariable = graph.getGlobalVariable;
  6161. graph.getGlobalVariable = function(name)
  6162. {
  6163. if (name == 'page' && diagrams != null && diagrams[realPage] != null)
  6164. {
  6165. return diagrams[realPage].getAttribute('name');
  6166. }
  6167. else if (name == 'pagenumber')
  6168. {
  6169. return realPage + 1;
  6170. }
  6171. else if (name == 'pagecount')
  6172. {
  6173. return (diagrams != null) ? diagrams.length : 1;
  6174. }
  6175. return graphGetGlobalVariable.apply(this, arguments);
  6176. };
  6177. // Disables hyperlinks
  6178. graph.getLinkForCell = function()
  6179. {
  6180. return null;
  6181. };
  6182. var opts = {
  6183. lines: 11, // The number of lines to draw
  6184. length: 15, // The length of each line
  6185. width: 6, // The line thickness
  6186. radius: 10, // The radius of the inner circle
  6187. corners: 1, // Corner roundness (0..1)
  6188. rotate: 0, // The rotation offset
  6189. direction: 1, // 1: clockwise, -1: counterclockwise
  6190. color: Editor.isDarkMode() ? '#c0c0c0' : '#000', // #rgb or #rrggbb
  6191. speed: 1.4, // Rounds per second
  6192. trail: 60, // Afterglow percentage
  6193. shadow: false, // Whether to render a shadow
  6194. hwaccel: false, // Whether to use hardware acceleration
  6195. className: 'spinner', // The CSS class to assign to the spinner
  6196. zIndex: 2e9, // The z-index (defaults to 2000000000)
  6197. top: '50%', // Top position relative to parent
  6198. left: '50%' // Left position relative to parent
  6199. };
  6200. var spinner = new Spinner(opts);
  6201. var file = editorUi.getCurrentFile();
  6202. var fileNode = editorUi.getXmlFileData(true, false, true);
  6203. var tmp = fileNode.getElementsByTagName('diagram');
  6204. var currentDiagrams = {};
  6205. for (var i = 0; i < tmp.length; i++)
  6206. {
  6207. currentDiagrams[tmp[i].getAttribute('id')] = tmp[i];
  6208. }
  6209. var currentRow = null;
  6210. var currentRev = null;
  6211. var currentDoc = null;
  6212. var currentXml = null;
  6213. var zoomInBtn = editorUi.createToolbarButton(Editor.zoomInImage, mxResources.get('zoomIn'), function()
  6214. {
  6215. if (currentDoc != null)
  6216. {
  6217. graph.zoomIn();
  6218. }
  6219. }, 20);
  6220. zoomInBtn.setAttribute('disabled', 'disabled');
  6221. var zoomOutBtn = editorUi.createToolbarButton(Editor.zoomOutImage, mxResources.get('zoomOut'), function()
  6222. {
  6223. if (currentDoc != null)
  6224. {
  6225. graph.zoomOut();
  6226. }
  6227. }, 20);
  6228. zoomOutBtn.setAttribute('disabled', 'disabled');
  6229. var zoomFitBtn = editorUi.createToolbarButton(Editor.zoomFitImage, mxResources.get('fit'), function()
  6230. {
  6231. if (currentDoc != null)
  6232. {
  6233. if (graph.view.scale == 1)
  6234. {
  6235. graph.maxFitScale = 8;
  6236. graph.fit(8);
  6237. }
  6238. else
  6239. {
  6240. graph.zoomActual();
  6241. }
  6242. graph.center();
  6243. }
  6244. }, 20);
  6245. zoomFitBtn.setAttribute('disabled', 'disabled');
  6246. // Gesture listener added below to handle pressed state
  6247. var compareBtn = editorUi.createToolbarButton(Editor.compareImage, mxResources.get('compare'), null, 20);
  6248. compareBtn.setAttribute('disabled', 'disabled');
  6249. var mergeBtn = editorUi.createToolbarButton(Editor.thinDataImage, mxResources.get('merge'), null, 20);
  6250. mergeBtn.setAttribute('disabled', 'disabled');
  6251. var cmpContainer = container.cloneNode(false);
  6252. cmpContainer.style.pointerEvent = 'none';
  6253. container.parentNode.appendChild(cmpContainer);
  6254. var cmpGraph = new Graph(cmpContainer);
  6255. cmpGraph.setTooltips(false);
  6256. cmpGraph.setEnabled(false);
  6257. cmpGraph.setPanning(true);
  6258. cmpGraph.panningHandler.ignoreCell = true;
  6259. cmpGraph.panningHandler.useLeftButtonForPanning = true;
  6260. cmpGraph.minFitScale = null;
  6261. cmpGraph.maxFitScale = null;
  6262. cmpGraph.centerZoom = true;
  6263. var fileInfo = document.createElement('div');
  6264. fileInfo.style.textAlign = 'left';
  6265. fileInfo.style.color = 'gray';
  6266. fileInfo.style.backgroundColor = 'transparent';
  6267. fileInfo.style.overflow = 'hidden';
  6268. fileInfo.style.textOverflow = 'ellipsis';
  6269. fileInfo.style.whiteSpace = 'nowrap';
  6270. fileInfo.style.cursor = 'default';
  6271. fileInfo.style.height = '100%';
  6272. fileInfo.style.display = 'inline-flex';
  6273. fileInfo.style.alignItems = 'center';
  6274. fileInfo.style.flexGrow = '1';
  6275. mxEvent.addListener(fileInfo, 'click', function()
  6276. {
  6277. var textContent = mxUtils.getTextContent(fileInfo);
  6278. if (textContent != '')
  6279. {
  6280. editorUi.alert(textContent);
  6281. }
  6282. });
  6283. var prevFileInfo = null;
  6284. mxEvent.addGestureListeners(compareBtn, function(e)
  6285. {
  6286. // Gets current state of page with given ID
  6287. try
  6288. {
  6289. var curr = (diagrams[currentPage] != null) ? currentDiagrams[
  6290. diagrams[currentPage].getAttribute('id')] : null;
  6291. mxUtils.setOpacity(compareBtn, 20);
  6292. errorNode.innerText = '';
  6293. if (curr == null)
  6294. {
  6295. errorNode.style.display = 'inline-block';
  6296. mxUtils.write(errorNode, mxResources.get('pageNotFound'));
  6297. }
  6298. else
  6299. {
  6300. prevFileInfo = fileInfo.innerHTML;
  6301. fileInfo.innerHTML = mxResources.get('current');
  6302. container.style.display = 'none';
  6303. cmpContainer.style.display = '';
  6304. cmpContainer.style.backgroundColor = container.style.backgroundColor;
  6305. var tempNode = Editor.parseDiagramNode(curr);
  6306. var codec = new mxCodec(tempNode.ownerDocument);
  6307. codec.decode(tempNode, cmpGraph.getModel());
  6308. cmpGraph.view.scaleAndTranslate(graph.view.scale,
  6309. graph.view.translate.x, graph.view.translate.y);
  6310. cmpGraph.mathEnabled = tempNode.getAttribute('math') == '1';
  6311. if (Editor.MathJaxRender && cmpGraph.mathEnabled)
  6312. {
  6313. Editor.MathJaxRender(cmpGraph.container);
  6314. }
  6315. }
  6316. }
  6317. catch (e)
  6318. {
  6319. errorNode.style.display = 'inline-block';
  6320. errorNode.innerText = '';
  6321. mxUtils.write(errorNode, mxResources.get('pageNotFound') + ': ' + e.message);
  6322. }
  6323. }, null, function()
  6324. {
  6325. mxUtils.setOpacity(compareBtn, 60);
  6326. errorNode.style.display = 'none';
  6327. errorNode.innerText = '';
  6328. if (container.style.display == 'none')
  6329. {
  6330. container.style.display = '';
  6331. fileInfo.innerHTML = prevFileInfo;
  6332. cmpContainer.style.display = 'none';
  6333. }
  6334. });
  6335. mxEvent.addListener(mergeBtn, 'click', mxUtils.bind(this, function(e)
  6336. {
  6337. if (currentDoc != null)
  6338. {
  6339. var pages = editorUi.getPagesForNode(currentDoc.documentElement);
  6340. var patch = editorUi.diffPages(editorUi.pages, pages);
  6341. var dlg = new TextareaDialog(editorUi, mxResources.get('merge') + ':',
  6342. JSON.stringify(patch, null, 2), function(newValue)
  6343. {
  6344. try
  6345. {
  6346. if (newValue.length > 0 && editorUi.editor.graph.isEnabled())
  6347. {
  6348. var patches = [JSON.parse(newValue)];
  6349. editorUi.confirm(mxResources.get('areYouSure'), function()
  6350. {
  6351. try
  6352. {
  6353. file.patch(patches, null, true, true);
  6354. // Hides compare dialog
  6355. editorUi.hideDialog();
  6356. // Hides revision history dialog
  6357. editorUi.hideDialog();
  6358. }
  6359. catch (e)
  6360. {
  6361. editorUi.handleError(e);
  6362. }
  6363. });
  6364. }
  6365. else
  6366. {
  6367. // Hides compare dialog
  6368. editorUi.hideDialog();
  6369. }
  6370. }
  6371. catch (e)
  6372. {
  6373. editorUi.handleError(e);
  6374. }
  6375. }, null, null, null, null, null, true, null,
  6376. mxResources.get(editorUi.editor.graph.isEnabled() ?
  6377. 'merge' : 'close'));
  6378. editorUi.showDialog(dlg.container, 620, 460, true, true);
  6379. dlg.init();
  6380. }
  6381. }));
  6382. var restoreBtn = mxUtils.button(mxResources.get('restore'), function(e)
  6383. {
  6384. if (currentDoc != null && currentXml != null)
  6385. {
  6386. editorUi.confirm(mxResources.get('areYouSure'), function()
  6387. {
  6388. if (restoreFn != null)
  6389. {
  6390. restoreFn(currentXml);
  6391. }
  6392. else
  6393. {
  6394. if (editorUi.spinner.spin(document.body, mxResources.get('restoring')))
  6395. {
  6396. restoreBtn.setAttribute('disabled', 'disabled');
  6397. file.save(true, function(resp)
  6398. {
  6399. editorUi.spinner.stop();
  6400. restoreBtn.removeAttribute('disabled');
  6401. editorUi.replaceFileData(currentXml);
  6402. editorUi.hideDialog();
  6403. }, function(resp)
  6404. {
  6405. editorUi.spinner.stop();
  6406. restoreBtn.removeAttribute('disabled');
  6407. editorUi.editor.setStatus('');
  6408. editorUi.handleError(resp, (resp != null) ? mxResources.get('errorSavingFile') : null);
  6409. });
  6410. }
  6411. }
  6412. });
  6413. }
  6414. });
  6415. restoreBtn.className = 'geBtn gePrimaryBtn';
  6416. restoreBtn.setAttribute('disabled', 'disabled');
  6417. var pageSelect = document.createElement('select');
  6418. pageSelect.setAttribute('disabled', 'disabled');
  6419. pageSelect.style.userSelect = 'none';
  6420. pageSelect.style.maxWidth = '100px';
  6421. pageSelect.style.marginLeft = '10px';
  6422. pageSelect.style.display = 'none';
  6423. var pageSelectFunction = null;
  6424. mxEvent.addListener(pageSelect, 'change', function(evt)
  6425. {
  6426. if (pageSelectFunction != null)
  6427. {
  6428. pageSelectFunction(evt);
  6429. mxEvent.consume(evt);
  6430. }
  6431. });
  6432. var newBtn = mxUtils.button(mxResources.get('open'), function()
  6433. {
  6434. if (currentDoc != null)
  6435. {
  6436. window.openFile = new OpenFile(function()
  6437. {
  6438. window.openFile = null;
  6439. });
  6440. window.openFile.setData(mxUtils.getXml(currentDoc.documentElement));
  6441. editorUi.openLink(editorUi.getUrl(), null, true);
  6442. }
  6443. });
  6444. newBtn.className = 'geBtn';
  6445. newBtn.setAttribute('disabled', 'disabled');
  6446. var createBtn = mxUtils.button(mxResources.get('createRevision'), function()
  6447. {
  6448. editorUi.actions.get('save').funct(false);
  6449. });
  6450. createBtn.className = 'geBtn';
  6451. createBtn.setAttribute('disabled', 'disabled');
  6452. if (restoreFn != null)
  6453. {
  6454. newBtn.style.display = 'none';
  6455. }
  6456. var buttons = document.createElement('div');
  6457. buttons.style.position = 'absolute';
  6458. buttons.style.top = '482px';
  6459. buttons.style.right = '28px';
  6460. buttons.style.left = '32px';
  6461. buttons.style.justifyContent = 'end';
  6462. buttons.style.display = 'flex';
  6463. var tb = document.createElement('div');
  6464. tb.className = 'geToolbarContainer';
  6465. tb.style.backgroundColor = 'transparent';
  6466. tb.style.display = 'flex';
  6467. tb.style.alignItems = 'center';
  6468. tb.style.justifyContent = 'stretch';
  6469. tb.style.left = '32px';
  6470. tb.style.right = '32px';
  6471. tb.style.border = 'none';
  6472. tb.style.top = '440px';
  6473. tb.style.height = '28px';
  6474. var currentElt = null;
  6475. if (revs != null && revs.length > 0)
  6476. {
  6477. container.style.cursor = 'move';
  6478. var table = document.createElement('table');
  6479. table.style.border = '1px solid lightGray';
  6480. table.style.borderCollapse = 'collapse';
  6481. table.style.borderSpacing = '0px';
  6482. table.style.width = '100%';
  6483. var tbody = document.createElement('tbody');
  6484. var today = new Date().toDateString();
  6485. if (editorUi.currentPage != null && editorUi.pages != null)
  6486. {
  6487. currentPage = mxUtils.indexOf(editorUi.pages, editorUi.currentPage);
  6488. }
  6489. for (var i = revs.length - 1; i >= 0; i--)
  6490. {
  6491. var elt = (function(item)
  6492. {
  6493. var ts = new Date(item.modifiedDate);
  6494. var row = null;
  6495. var pd = '6px';
  6496. // Workaround for negative timestamps in Dropbox
  6497. if (ts.getTime() >= 0)
  6498. {
  6499. row = document.createElement('tr');
  6500. row.style.borderBottom = '1px solid lightGray';
  6501. row.style.fontSize = '12px';
  6502. row.style.cursor = 'pointer';
  6503. var date = document.createElement('td');
  6504. date.style.padding = pd;
  6505. date.style.whiteSpace = 'nowrap';
  6506. if (item == revs[revs.length - 1])
  6507. {
  6508. mxUtils.write(date, mxResources.get('current'));
  6509. }
  6510. else
  6511. {
  6512. if (ts.toDateString() === today)
  6513. {
  6514. mxUtils.write(date, ts.toLocaleTimeString());
  6515. }
  6516. else
  6517. {
  6518. mxUtils.write(date, ts.toLocaleDateString() + ' ' +
  6519. ts.toLocaleTimeString());
  6520. }
  6521. }
  6522. row.appendChild(date);
  6523. row.setAttribute('title', ts.toLocaleDateString() + ' ' +
  6524. ts.toLocaleTimeString() +
  6525. ((item.fileSize != null)? ' ' + editorUi.formatFileSize(parseInt(item.fileSize)) : '') +
  6526. ((item.lastModifyingUserName != null) ? ' ' + item.lastModifyingUserName : ''));
  6527. function updateGraph(xml)
  6528. {
  6529. spinner.stop();
  6530. errorNode.innerText = '';
  6531. var doc = mxUtils.parseXml(xml);
  6532. var node = editorUi.editor.extractGraphModel(doc.documentElement, true);
  6533. if (node != null)
  6534. {
  6535. pageSelect.style.display = 'none';
  6536. pageSelect.innerText = '';
  6537. currentDoc = doc;
  6538. currentXml = xml;
  6539. parseSelectFunction = null;
  6540. diagrams = null;
  6541. realPage = 0;
  6542. function parseGraphModel(dataNode)
  6543. {
  6544. var bg = dataNode.getAttribute('background');
  6545. if (bg == null || bg == '' || bg == mxConstants.NONE)
  6546. {
  6547. bg = graph.defaultPageBackgroundColor;
  6548. }
  6549. container.style.backgroundColor = bg;
  6550. var codec = new mxCodec(dataNode.ownerDocument);
  6551. codec.decode(dataNode, graph.getModel());
  6552. graph.maxFitScale = 1;
  6553. graph.fit(8);
  6554. graph.center();
  6555. graph.mathEnabled = dataNode.getAttribute('math') == '1';
  6556. if (Editor.MathJaxRender && graph.mathEnabled)
  6557. {
  6558. Editor.MathJaxRender(graph.container);
  6559. }
  6560. return dataNode;
  6561. };
  6562. function parseDiagram(diagramNode)
  6563. {
  6564. if (diagramNode != null)
  6565. {
  6566. diagramNode = parseGraphModel(Editor.parseDiagramNode(diagramNode));
  6567. }
  6568. return diagramNode;
  6569. };
  6570. if (node.nodeName == 'mxfile')
  6571. {
  6572. // Workaround for "invalid calling object" error in IE
  6573. var tmp = node.getElementsByTagName('diagram');
  6574. var newPages = {};
  6575. diagrams = [];
  6576. for (var i = 0; i < tmp.length; i++)
  6577. {
  6578. diagrams.push(tmp[i]);
  6579. }
  6580. realPage = Math.min(currentPage, diagrams.length - 1);
  6581. if (diagrams.length > 0)
  6582. {
  6583. parseDiagram(diagrams[realPage]);
  6584. }
  6585. if (diagrams.length > 1)
  6586. {
  6587. pageSelect.removeAttribute('disabled');
  6588. pageSelect.style.display = '';
  6589. for (var i = 0; i < diagrams.length; i++)
  6590. {
  6591. var pageOption = document.createElement('option');
  6592. pageOption.setAttribute('title', name + ' (' +
  6593. diagrams[i].getAttribute('id') + ')');
  6594. pageOption.setAttribute('value', i);
  6595. var name = diagrams[i].getAttribute('name') ||
  6596. mxResources.get('pageWithNumber', [i + 1]);
  6597. var localPage = editorUi.getPageById(diagrams[i].getAttribute('id'));
  6598. var state = '';
  6599. if (localPage != null)
  6600. {
  6601. var newPage = new DiagramPage(diagrams[i]);
  6602. if (editorUi.getHashValueForPages([localPage]) != editorUi.getHashValueForPages([newPage]))
  6603. {
  6604. state = ' (M)';
  6605. }
  6606. }
  6607. else
  6608. {
  6609. state = ' (X)';
  6610. }
  6611. mxUtils.write(pageOption, name + state);
  6612. if (i == realPage)
  6613. {
  6614. pageOption.setAttribute('selected', 'selected');
  6615. }
  6616. pageSelect.appendChild(pageOption);
  6617. }
  6618. }
  6619. pageSelectFunction = function()
  6620. {
  6621. try
  6622. {
  6623. var temp = parseInt(pageSelect.value);
  6624. currentPage = temp;
  6625. realPage = currentPage;
  6626. parseDiagram(diagrams[temp]);
  6627. }
  6628. catch (e)
  6629. {
  6630. pageSelect.value = currentPage;
  6631. editorUi.handleError(e);
  6632. }
  6633. };
  6634. }
  6635. else
  6636. {
  6637. parseGraphModel(node);
  6638. }
  6639. var shortUser = item.lastModifyingUserName;
  6640. if (shortUser != null && shortUser.length > 20)
  6641. {
  6642. shortUser = shortUser.substring(0, 20) + '...';
  6643. }
  6644. fileInfo.innerText = '';
  6645. mxUtils.write(fileInfo, ((shortUser != null) ?
  6646. (shortUser + ' ') : '') + ts.toLocaleDateString() +
  6647. ' ' + ts.toLocaleTimeString());
  6648. fileInfo.setAttribute('title', row.getAttribute('title'));
  6649. zoomInBtn.removeAttribute('disabled');
  6650. zoomOutBtn.removeAttribute('disabled');
  6651. zoomFitBtn.removeAttribute('disabled');
  6652. compareBtn.removeAttribute('disabled');
  6653. mergeBtn.removeAttribute('disabled');
  6654. if (file == null || !file.isRestricted())
  6655. {
  6656. if (editorUi.editor.graph.isEnabled())
  6657. {
  6658. restoreBtn.removeAttribute('disabled');
  6659. }
  6660. newBtn.removeAttribute('disabled');
  6661. createBtn.removeAttribute('disabled');
  6662. }
  6663. mxUtils.setOpacity(zoomInBtn, 60);
  6664. mxUtils.setOpacity(zoomOutBtn, 60);
  6665. mxUtils.setOpacity(zoomFitBtn, 60);
  6666. mxUtils.setOpacity(compareBtn, 60);
  6667. mxUtils.setOpacity(mergeBtn, 60);
  6668. }
  6669. else
  6670. {
  6671. pageSelect.style.display = 'none';
  6672. pageSelect.innerText = '';
  6673. fileInfo.innerText = '';
  6674. errorNode.innerText = '';
  6675. mxUtils.write(fileInfo, mxResources.get('errorLoadingFile'));
  6676. mxUtils.write(errorNode, mxResources.get('errorLoadingFile'));
  6677. }
  6678. };
  6679. mxEvent.addListener(row, 'click', function(evt)
  6680. {
  6681. if (currentRev != item)
  6682. {
  6683. spinner.stop();
  6684. if (currentRow != null)
  6685. {
  6686. currentRow.style.backgroundColor = '';
  6687. }
  6688. currentRev = item;
  6689. currentRow = row;
  6690. currentRow.style.backgroundColor = Editor.isDarkMode() ? '#000000' : '#ebf2f9';
  6691. currentDoc = null;
  6692. currentXml = null;
  6693. fileInfo.removeAttribute('title');
  6694. fileInfo.innerText = mxResources.get('loading') + '...';
  6695. container.style.backgroundColor = graph.defaultPageBackgroundColor;
  6696. errorNode.innerText = '';
  6697. graph.getModel().clear();
  6698. restoreBtn.setAttribute('disabled', 'disabled');
  6699. zoomInBtn.setAttribute('disabled', 'disabled');
  6700. zoomOutBtn.setAttribute('disabled', 'disabled');
  6701. zoomFitBtn.setAttribute('disabled', 'disabled');
  6702. compareBtn.setAttribute('disabled', 'disabled');
  6703. mergeBtn.setAttribute('disabled', 'disabled');
  6704. newBtn.setAttribute('disabled', 'disabled');
  6705. pageSelect.setAttribute('disabled', 'disabled');
  6706. mxUtils.setOpacity(zoomInBtn, 20);
  6707. mxUtils.setOpacity(zoomOutBtn, 20);
  6708. mxUtils.setOpacity(zoomFitBtn, 20);
  6709. mxUtils.setOpacity(compareBtn, 20);
  6710. mxUtils.setOpacity(mergeBtn, 20);
  6711. spinner.spin(container);
  6712. item.getXml(function(xml)
  6713. {
  6714. if (currentRev == item)
  6715. {
  6716. try
  6717. {
  6718. updateGraph(xml);
  6719. }
  6720. catch (e)
  6721. {
  6722. fileInfo.innerText = mxResources.get('error') + ': ' + e.message;
  6723. }
  6724. }
  6725. }, function(err)
  6726. {
  6727. spinner.stop();
  6728. pageSelect.style.display = 'none';
  6729. pageSelect.innerText = '';
  6730. fileInfo.innerText = '';
  6731. mxUtils.write(fileInfo, mxResources.get('errorLoadingFile'));
  6732. mxUtils.write(errorNode, mxResources.get('errorLoadingFile'));
  6733. });
  6734. mxEvent.consume(evt);
  6735. }
  6736. });
  6737. mxEvent.addListener(row, 'dblclick', function(evt)
  6738. {
  6739. newBtn.click();
  6740. if (window.getSelection)
  6741. {
  6742. window.getSelection().removeAllRanges();
  6743. }
  6744. else if (document.selection)
  6745. {
  6746. document.selection.empty();
  6747. }
  6748. mxEvent.consume(evt);
  6749. }, false);
  6750. tbody.appendChild(row);
  6751. }
  6752. return row;
  6753. })(revs[i]);
  6754. // Selects and loads first element in list (ie current version) after
  6755. // graph container was initialized since there is no loading delay
  6756. if (elt != null && i == revs.length - 1)
  6757. {
  6758. currentElt = elt;
  6759. }
  6760. }
  6761. table.appendChild(tbody);
  6762. list.appendChild(table);
  6763. }
  6764. else if (file == null || (editorUi.drive == null && file.constructor == window.DriveFile) ||
  6765. (editorUi.dropbox == null && file.constructor == window.DropboxFile))
  6766. {
  6767. container.style.display = 'none';
  6768. tb.style.display = 'none';
  6769. mxUtils.write(list, mxResources.get('notAvailable'));
  6770. }
  6771. else
  6772. {
  6773. container.style.display = 'none';
  6774. tb.style.display = 'none';
  6775. mxUtils.write(list, mxResources.get('noRevisions'));
  6776. }
  6777. this.init = function()
  6778. {
  6779. if (currentElt != null)
  6780. {
  6781. currentElt.click();
  6782. }
  6783. };
  6784. var closeBtn = mxUtils.button(mxResources.get('cancel'), function()
  6785. {
  6786. editorUi.hideDialog();
  6787. });
  6788. closeBtn.className = 'geBtn';
  6789. tb.appendChild(fileInfo);
  6790. tb.appendChild(compareBtn);
  6791. tb.appendChild(zoomOutBtn);
  6792. tb.appendChild(zoomFitBtn);
  6793. tb.appendChild(zoomInBtn);
  6794. tb.appendChild(pageSelect);
  6795. tb.appendChild(mergeBtn);
  6796. if (editorUi.editor.cancelFirst)
  6797. {
  6798. buttons.appendChild(closeBtn);
  6799. }
  6800. buttons.appendChild(newBtn);
  6801. if (file != null && file.constructor == DriveFile)
  6802. {
  6803. buttons.appendChild(createBtn);
  6804. }
  6805. buttons.appendChild(restoreBtn);
  6806. if (!editorUi.editor.cancelFirst)
  6807. {
  6808. buttons.appendChild(closeBtn);
  6809. }
  6810. div.appendChild(buttons);
  6811. div.appendChild(tb);
  6812. this.container = div;
  6813. };
  6814. /**
  6815. * Constructs a new revision dialog
  6816. */
  6817. var DraftDialog = function(editorUi, title, xml, editFn, discardFn, editLabel, discardLabel, ignoreFn, drafts)
  6818. {
  6819. var div = document.createElement('div');
  6820. var titleDiv = document.createElement('div');
  6821. titleDiv.style.marginTop = '0px';
  6822. titleDiv.style.whiteSpace = 'nowrap';
  6823. titleDiv.style.overflow = 'auto';
  6824. titleDiv.style.lineHeight = 'normal';
  6825. mxUtils.write(titleDiv, title);
  6826. div.appendChild(titleDiv);
  6827. var select = document.createElement('select');
  6828. var draftSelected = mxUtils.bind(this, function()
  6829. {
  6830. if (select.value == '-1')
  6831. {
  6832. select.value = select.options[0].value;
  6833. draftSelected();
  6834. // Discard all drafts
  6835. editorUi.confirm(mxResources.get('areYouSure'), null, mxUtils.bind(this, async function()
  6836. {
  6837. for (var i = 0; i < drafts.length; i++)
  6838. {
  6839. discardFn.apply(this, [i, mxUtils.bind(this, function()
  6840. {
  6841. // Do nothing
  6842. })]);
  6843. }
  6844. editorUi.hideDialog(true);
  6845. }), mxResources.get('no'), mxResources.get('yes'));
  6846. }
  6847. else
  6848. {
  6849. doc = mxUtils.parseXml(drafts[select.value].data);
  6850. node = editorUi.editor.extractGraphModel(doc.documentElement, true);
  6851. currentPage = 0;
  6852. this.init();
  6853. }
  6854. });
  6855. if (drafts != null)
  6856. {
  6857. select.style.marginLeft = '4px';
  6858. for (var i = 0; i < drafts.length; i++)
  6859. {
  6860. var opt = document.createElement('option');
  6861. opt.setAttribute('value', i);
  6862. var ts0 = new Date(drafts[i].created);
  6863. var ts1 = new Date(drafts[i].modified);
  6864. mxUtils.write(opt, ts0.toLocaleDateString() + ' ' +
  6865. ts0.toLocaleTimeString() + ' - ' +
  6866. ((ts0.toDateString() != ts1.toDateString() || true) ?
  6867. ts1.toLocaleDateString() : ' ') +
  6868. ' ' + ts1.toLocaleTimeString());
  6869. select.appendChild(opt);
  6870. }
  6871. // Delete all option
  6872. var opt = document.createElement('option');
  6873. opt.setAttribute('value', '-1');
  6874. mxUtils.write(opt, mxResources.get('deleteAll'));
  6875. select.appendChild(opt);
  6876. titleDiv.appendChild(select);
  6877. mxEvent.addListener(select, 'change', draftSelected);
  6878. }
  6879. if (xml == null)
  6880. {
  6881. xml = drafts[0].data;
  6882. }
  6883. var container = document.createElement('div');
  6884. container.style.position = 'absolute';
  6885. container.style.border = '1px solid lightGray';
  6886. container.style.marginTop = '10px';
  6887. container.style.left = '40px';
  6888. container.style.right = '40px';
  6889. container.style.top = '46px';
  6890. container.style.bottom = '74px';
  6891. container.style.overflow = 'hidden';
  6892. mxEvent.disableContextMenu(container);
  6893. div.appendChild(container);
  6894. var graph = new Graph(container);
  6895. graph.setEnabled(false);
  6896. graph.setPanning(true);
  6897. graph.shapeBackgroundColor = (Editor.isDarkMode() ? '#2a252f' : '#ffffff');
  6898. graph.panningHandler.ignoreCell = true;
  6899. graph.panningHandler.useLeftButtonForPanning = true;
  6900. graph.minFitScale = null;
  6901. graph.maxFitScale = null;
  6902. graph.centerZoom = true;
  6903. // Handles placeholders for pages
  6904. var doc = mxUtils.parseXml(xml);
  6905. var node = editorUi.editor.extractGraphModel(doc.documentElement, true);
  6906. var currentPage = 0;
  6907. var diagrams = null;
  6908. var graphGetGlobalVariable = graph.getGlobalVariable;
  6909. graph.getGlobalVariable = function(name)
  6910. {
  6911. if (name == 'page' && diagrams != null && diagrams[currentPage] != null)
  6912. {
  6913. return diagrams[currentPage].getAttribute('name');
  6914. }
  6915. else if (name == 'pagenumber')
  6916. {
  6917. return currentPage + 1;
  6918. }
  6919. else if (name == 'pagecount')
  6920. {
  6921. return (diagrams != null) ? diagrams.length : 1;
  6922. }
  6923. return graphGetGlobalVariable.apply(this, arguments);
  6924. };
  6925. // Disables hyperlinks
  6926. graph.getLinkForCell = function()
  6927. {
  6928. return null;
  6929. };
  6930. var zoomInBtn = editorUi.createToolbarButton(Editor.zoomInImage, mxResources.get('zoomIn'), function()
  6931. {
  6932. graph.zoomIn();
  6933. }, 20);
  6934. var zoomOutBtn = editorUi.createToolbarButton(Editor.zoomInImage, mxResources.get('zoomOut'), function()
  6935. {
  6936. graph.zoomOut();
  6937. }, 20);
  6938. var zoomFitBtn = editorUi.createToolbarButton(Editor.zoomFitImage, mxResources.get('fit'), function()
  6939. {
  6940. if (graph.view.scale == 1)
  6941. {
  6942. graph.maxFitScale = 8;
  6943. graph.fit(8);
  6944. }
  6945. else
  6946. {
  6947. graph.zoomActual();
  6948. }
  6949. graph.center();
  6950. }, 20);
  6951. var restoreBtn = mxUtils.button(discardLabel || mxResources.get('discard'), function()
  6952. {
  6953. editorUi.confirm(mxResources.get('areYouSure'), null, mxUtils.bind(this, async function()
  6954. {
  6955. discardFn.apply(this, [select.value, mxUtils.bind(this, function()
  6956. {
  6957. if (select.parentNode != null)
  6958. {
  6959. select.options[select.selectedIndex].parentNode.removeChild(select.options[select.selectedIndex]);
  6960. if (select.options.length > 1)
  6961. {
  6962. select.value = select.options[0].value;
  6963. draftSelected();
  6964. }
  6965. else
  6966. {
  6967. editorUi.hideDialog(true);
  6968. }
  6969. }
  6970. })]);
  6971. }), mxResources.get('no'), mxResources.get('yes'));
  6972. });
  6973. restoreBtn.className = 'geBtn';
  6974. var pageSelect = document.createElement('select');
  6975. pageSelect.style.maxWidth = '80px';
  6976. pageSelect.style.position = 'relative';
  6977. pageSelect.style.top = '-2px';
  6978. pageSelect.style.verticalAlign = 'bottom';
  6979. pageSelect.style.marginRight = '6px';
  6980. pageSelect.style.display = 'none';
  6981. var showBtn = mxUtils.button(editLabel || mxResources.get('edit'), function()
  6982. {
  6983. editFn.apply(this, [select.value])
  6984. });
  6985. showBtn.className = 'geBtn gePrimaryBtn';
  6986. var buttons = document.createElement('div');
  6987. buttons.style.position = 'absolute';
  6988. buttons.style.bottom = '30px';
  6989. buttons.style.right = '40px';
  6990. buttons.style.textAlign = 'right';
  6991. var tb = document.createElement('div');
  6992. tb.className = 'geToolbarContainer';
  6993. tb.style.cssText = 'box-shadow:none !important;background-color:transparent;' +
  6994. 'padding:2px;border-style:none !important;bottom:30px;';
  6995. this.init = function()
  6996. {
  6997. function parseGraphModel(dataNode)
  6998. {
  6999. if (dataNode != null)
  7000. {
  7001. var bg = dataNode.getAttribute('background');
  7002. if (bg == null || bg == '' || bg == mxConstants.NONE)
  7003. {
  7004. bg = Editor.isDarkMode() ? 'transparent' : '#ffffff';
  7005. }
  7006. container.style.backgroundColor = bg;
  7007. var codec = new mxCodec(dataNode.ownerDocument);
  7008. codec.decode(dataNode, graph.getModel());
  7009. graph.maxFitScale = 1;
  7010. graph.fit(8);
  7011. graph.center();
  7012. }
  7013. return dataNode;
  7014. };
  7015. function parseDiagram(diagramNode)
  7016. {
  7017. if (diagramNode != null)
  7018. {
  7019. diagramNode = parseGraphModel(Editor.parseDiagramNode(diagramNode));
  7020. }
  7021. return diagramNode;
  7022. };
  7023. mxEvent.addListener(pageSelect, 'change', function(evt)
  7024. {
  7025. currentPage = parseInt(pageSelect.value);
  7026. parseDiagram(diagrams[currentPage]);
  7027. mxEvent.consume(evt);
  7028. });
  7029. if (node.nodeName == 'mxfile')
  7030. {
  7031. // Workaround for "invalid calling object" error in IE
  7032. var tmp = node.getElementsByTagName('diagram');
  7033. diagrams = [];
  7034. for (var i = 0; i < tmp.length; i++)
  7035. {
  7036. diagrams.push(tmp[i]);
  7037. }
  7038. if (diagrams.length > 0)
  7039. {
  7040. parseDiagram(diagrams[currentPage]);
  7041. }
  7042. pageSelect.innerText = '';
  7043. if (diagrams.length > 1)
  7044. {
  7045. pageSelect.style.display = '';
  7046. for (var i = 0; i < diagrams.length; i++)
  7047. {
  7048. var pageOption = document.createElement('option');
  7049. mxUtils.write(pageOption, diagrams[i].getAttribute('name') ||
  7050. mxResources.get('pageWithNumber', [i + 1]));
  7051. pageOption.setAttribute('value', i);
  7052. if (i == currentPage)
  7053. {
  7054. pageOption.setAttribute('selected', 'selected');
  7055. }
  7056. pageSelect.appendChild(pageOption);
  7057. }
  7058. }
  7059. else
  7060. {
  7061. pageSelect.style.display = 'none';
  7062. }
  7063. }
  7064. else
  7065. {
  7066. parseGraphModel(node);
  7067. }
  7068. };
  7069. tb.appendChild(pageSelect);
  7070. tb.appendChild(zoomInBtn);
  7071. tb.appendChild(zoomOutBtn);
  7072. tb.appendChild(zoomFitBtn);
  7073. var cancelBtn = mxUtils.button(mxResources.get('cancel'), function()
  7074. {
  7075. editorUi.hideDialog(true);
  7076. });
  7077. cancelBtn.className = 'geBtn';
  7078. var ignoreBtn = (ignoreFn != null) ? mxUtils.button(mxResources.get('ignore'), ignoreFn) : null;
  7079. if (ignoreBtn != null)
  7080. {
  7081. ignoreBtn.className = 'geBtn';
  7082. }
  7083. if (editorUi.editor.cancelFirst)
  7084. {
  7085. buttons.appendChild(cancelBtn);
  7086. if (ignoreBtn != null)
  7087. {
  7088. buttons.appendChild(ignoreBtn);
  7089. }
  7090. buttons.appendChild(restoreBtn);
  7091. buttons.appendChild(showBtn);
  7092. }
  7093. else
  7094. {
  7095. buttons.appendChild(showBtn);
  7096. buttons.appendChild(restoreBtn);
  7097. if (ignoreBtn != null)
  7098. {
  7099. buttons.appendChild(ignoreBtn);
  7100. }
  7101. buttons.appendChild(cancelBtn);
  7102. }
  7103. div.appendChild(buttons);
  7104. div.appendChild(tb);
  7105. this.container = div;
  7106. };
  7107. /**
  7108. *
  7109. */
  7110. var FindWindow = function(ui, x, y, w, h, withReplace)
  7111. {
  7112. var action = ui.actions.get('findReplace');
  7113. var graph = ui.editor.graph;
  7114. var lastSearch = null;
  7115. var lastFound = null;
  7116. var lastSearchSuccessful = false;
  7117. var allChecked = false;
  7118. var lblMatch = null;
  7119. var lblMatchPos = 0;
  7120. var marker = 1;
  7121. var div = document.createElement('div');
  7122. div.style.userSelect = 'none';
  7123. div.style.overflow = 'hidden';
  7124. div.style.padding = '10px';
  7125. div.style.height = '100%';
  7126. var txtWidth = withReplace? '260px' : '200px';
  7127. var searchInput = document.createElement('input');
  7128. searchInput.setAttribute('placeholder', mxResources.get('find'));
  7129. searchInput.setAttribute('type', 'text');
  7130. searchInput.style.marginTop = '4px';
  7131. searchInput.style.marginBottom = '6px';
  7132. searchInput.style.width = txtWidth;
  7133. searchInput.style.fontSize = '12px';
  7134. searchInput.style.borderRadius = '4px';
  7135. searchInput.style.padding = '6px';
  7136. div.appendChild(searchInput);
  7137. mxUtils.br(div);
  7138. var replaceInput;
  7139. if (withReplace)
  7140. {
  7141. replaceInput = document.createElement('input');
  7142. replaceInput.setAttribute('placeholder', mxResources.get('replaceWith'));
  7143. replaceInput.setAttribute('type', 'text');
  7144. replaceInput.style.marginTop = '4px';
  7145. replaceInput.style.marginBottom = '6px';
  7146. replaceInput.style.width = txtWidth;
  7147. replaceInput.style.fontSize = '12px';
  7148. replaceInput.style.borderRadius = '4px';
  7149. replaceInput.style.padding = '6px';
  7150. div.appendChild(replaceInput);
  7151. mxUtils.br(div);
  7152. mxEvent.addListener(replaceInput, 'input', updateReplBtns);
  7153. }
  7154. var regexInput = document.createElement('input');
  7155. regexInput.setAttribute('id', 'geFindWinRegExChck');
  7156. regexInput.setAttribute('type', 'checkbox');
  7157. regexInput.style.marginRight = '4px';
  7158. div.appendChild(regexInput);
  7159. var regexLabel = document.createElement('label');
  7160. regexLabel.setAttribute('for', 'geFindWinRegExChck');
  7161. div.appendChild(regexLabel);
  7162. mxUtils.write(regexLabel, mxResources.get('regularExpression'));
  7163. div.appendChild(regexLabel);
  7164. var help = ui.menus.createHelpLink('https://www.drawio.com/doc/faq/find-shapes');
  7165. help.style.position = 'relative';
  7166. help.style.marginLeft = '6px';
  7167. help.style.top = '3px';
  7168. div.appendChild(help);
  7169. mxUtils.br(div);
  7170. var allPagesInput = document.createElement('input');
  7171. allPagesInput.setAttribute('id', 'geFindWinAllPagesChck');
  7172. allPagesInput.setAttribute('type', 'checkbox');
  7173. allPagesInput.style.marginRight = '4px';
  7174. div.appendChild(allPagesInput);
  7175. var allPagesLabel = document.createElement('label');
  7176. allPagesLabel.setAttribute('for', 'geFindWinAllPagesChck');
  7177. div.appendChild(allPagesLabel);
  7178. mxUtils.write(allPagesLabel, mxResources.get('allPages'));
  7179. div.appendChild(allPagesLabel);
  7180. var tmp = document.createElement('div');
  7181. function testMeta(re, cell, search)
  7182. {
  7183. if (typeof cell.value === 'object' && cell.value.attributes != null)
  7184. {
  7185. var attrs = cell.value.attributes;
  7186. for (var i = 0; i < attrs.length; i++)
  7187. {
  7188. if (attrs[i].nodeName != 'label')
  7189. {
  7190. var value = mxUtils.trim(attrs[i].nodeValue.replace(/[\x00-\x1F\x7F-\x9F]|\s+/g, ' ')).toLowerCase();
  7191. if ((re == null && value.indexOf(search) >= 0) ||
  7192. (re != null && re.test(value)))
  7193. {
  7194. return true;
  7195. }
  7196. }
  7197. }
  7198. }
  7199. return false;
  7200. };
  7201. function updateReplBtns()
  7202. {
  7203. if (lastSearchSuccessful)
  7204. {
  7205. replaceFindBtn.removeAttribute('disabled');
  7206. replaceBtn.removeAttribute('disabled');
  7207. }
  7208. else
  7209. {
  7210. replaceFindBtn.setAttribute('disabled', 'disabled');
  7211. replaceBtn.setAttribute('disabled', 'disabled');
  7212. }
  7213. if (searchInput.value)
  7214. {
  7215. replaceAllBtn.removeAttribute('disabled');
  7216. }
  7217. else
  7218. {
  7219. replaceAllBtn.setAttribute('disabled', 'disabled');
  7220. }
  7221. }
  7222. function search(internalCall, trySameCell, stayOnPage)
  7223. {
  7224. replAllNotif.innerText = '';
  7225. var cells = graph.model.getDescendants(graph.model.getRoot());
  7226. var searchStr = searchInput.value.toLowerCase();
  7227. var re = (regexInput.checked) ? new RegExp(searchStr) : null;
  7228. var firstMatch = null;
  7229. lblMatch = null;
  7230. if (lastSearch != searchStr)
  7231. {
  7232. lastSearch = searchStr;
  7233. lastFound = null;
  7234. allChecked = false;
  7235. }
  7236. var active = lastFound == null;
  7237. if (searchStr.length > 0)
  7238. {
  7239. if (allChecked)
  7240. {
  7241. allChecked = false;
  7242. //Find current page index
  7243. var currentPageIndex;
  7244. for (var i = 0; i < ui.pages.length; i++)
  7245. {
  7246. if (ui.currentPage == ui.pages[i])
  7247. {
  7248. currentPageIndex = i;
  7249. break;
  7250. }
  7251. }
  7252. var nextPageIndex = (currentPageIndex + 1) % ui.pages.length, nextPage;
  7253. lastFound = null;
  7254. do
  7255. {
  7256. allChecked = false;
  7257. nextPage = ui.pages[nextPageIndex];
  7258. graph = ui.createTemporaryGraph(graph.getStylesheet());
  7259. ui.updatePageRoot(nextPage);
  7260. graph.model.setRoot(nextPage.root);
  7261. nextPageIndex = (nextPageIndex + 1) % ui.pages.length;
  7262. }
  7263. while(!search(true, trySameCell, stayOnPage) && nextPageIndex != currentPageIndex);
  7264. if (lastFound)
  7265. {
  7266. lastFound = null;
  7267. if (!stayOnPage)
  7268. {
  7269. ui.selectPage(nextPage);
  7270. }
  7271. else
  7272. {
  7273. ui.editor.graph.model.execute(new SelectPage(ui, nextPage));
  7274. }
  7275. }
  7276. allChecked = false;
  7277. graph = ui.editor.graph;
  7278. return search(true, trySameCell, stayOnPage);
  7279. }
  7280. var i;
  7281. for (i = 0; i < cells.length; i++)
  7282. {
  7283. var state = graph.view.getState(cells[i]);
  7284. //Try the same cell with replace to find other occurances
  7285. if (trySameCell)
  7286. {
  7287. active = active || state == lastFound;
  7288. }
  7289. if (state != null && state.cell.value != null && (active || firstMatch == null) &&
  7290. (graph.model.isVertex(state.cell) || graph.model.isEdge(state.cell)))
  7291. {
  7292. if (state.style != null && state.style['html'] == '1')
  7293. {
  7294. tmp.innerHTML = graph.sanitizeHtml(graph.getLabel(state.cell));
  7295. label = mxUtils.extractTextWithWhitespace([tmp]);
  7296. }
  7297. else
  7298. {
  7299. label = graph.getLabel(state.cell);
  7300. }
  7301. label = mxUtils.trim(label.replace(/[\x00-\x1F\x7F-\x9F]|\s+/g, ' ')).toLowerCase();
  7302. var lblPosShift = 0;
  7303. if (trySameCell && withReplace && state == lastFound)
  7304. {
  7305. label = label.substr(lblMatchPos);
  7306. lblPosShift = lblMatchPos;
  7307. }
  7308. var checkMeta = replaceInput.value == '';
  7309. if ((re == null && ((label.indexOf(searchStr) >= 0) ||
  7310. (checkMeta && testMeta(re, state.cell, searchStr)))) ||
  7311. (re != null && (re.test(label) || (checkMeta &&
  7312. testMeta(re, state.cell, searchStr)))))
  7313. {
  7314. if (withReplace)
  7315. {
  7316. if (re != null)
  7317. {
  7318. var result = label.match(re);
  7319. if (result != null && result.length > 0)
  7320. {
  7321. lblMatch = result[0].toLowerCase();
  7322. lblMatchPos = lblPosShift + result.index + lblMatch.length;
  7323. }
  7324. }
  7325. else
  7326. {
  7327. lblMatch = searchStr;
  7328. lblMatchPos = lblPosShift + label.indexOf(searchStr) + lblMatch.length;
  7329. }
  7330. }
  7331. if (active)
  7332. {
  7333. firstMatch = state;
  7334. break;
  7335. }
  7336. else if (firstMatch == null)
  7337. {
  7338. firstMatch = state;
  7339. }
  7340. }
  7341. }
  7342. active = active || state == lastFound;
  7343. }
  7344. }
  7345. if (firstMatch != null)
  7346. {
  7347. if (i == cells.length && allPagesInput.checked)
  7348. {
  7349. lastFound = null;
  7350. allChecked = true;
  7351. return search(true, trySameCell, stayOnPage);
  7352. }
  7353. lastFound = firstMatch;
  7354. graph.scrollCellToVisible(lastFound.cell);
  7355. if (graph.isEnabled() && !graph.isCellLocked(lastFound.cell))
  7356. {
  7357. if (!stayOnPage &&
  7358. (graph.getSelectionCell() != lastFound.cell ||
  7359. graph.getSelectionCount() != 1))
  7360. {
  7361. graph.setSelectionCell(lastFound.cell);
  7362. }
  7363. }
  7364. else
  7365. {
  7366. graph.highlightCell(lastFound.cell);
  7367. }
  7368. }
  7369. //Check other pages
  7370. else if (!internalCall && allPagesInput.checked)
  7371. {
  7372. allChecked = true;
  7373. return search(true, trySameCell, stayOnPage);
  7374. }
  7375. else if (graph.isEnabled() && !stayOnPage)
  7376. {
  7377. graph.clearSelection();
  7378. }
  7379. lastSearchSuccessful = firstMatch != null;
  7380. if (withReplace && !internalCall)
  7381. {
  7382. updateReplBtns();
  7383. }
  7384. return searchStr.length == 0 || firstMatch != null;
  7385. };
  7386. mxUtils.br(div);
  7387. var btnsCont = document.createElement('div');
  7388. btnsCont.style.left = '0px';
  7389. btnsCont.style.right = '0px';
  7390. btnsCont.style.marginTop = '6px';
  7391. btnsCont.style.padding = '0 6px 0 6px';
  7392. btnsCont.style.textAlign = 'center';
  7393. div.appendChild(btnsCont);
  7394. var resetBtn = mxUtils.button(mxResources.get('reset'), function()
  7395. {
  7396. replAllNotif.innerText = '';
  7397. searchInput.value = '';
  7398. searchInput.style.backgroundColor = '';
  7399. if (withReplace)
  7400. {
  7401. replaceInput.value = '';
  7402. updateReplBtns();
  7403. }
  7404. lastFound = null;
  7405. lastSearch = null;
  7406. allChecked = false;
  7407. searchInput.focus();
  7408. });
  7409. resetBtn.setAttribute('title', mxResources.get('reset'));
  7410. resetBtn.style.float = 'none';
  7411. resetBtn.style.width = '120px';
  7412. resetBtn.style.marginTop = '6px';
  7413. resetBtn.style.marginLeft = '8px';
  7414. resetBtn.style.overflow = 'hidden';
  7415. resetBtn.style.textOverflow = 'ellipsis';
  7416. resetBtn.className = 'geBtn';
  7417. if (!withReplace)
  7418. {
  7419. btnsCont.appendChild(resetBtn);
  7420. }
  7421. var btn = mxUtils.button(mxResources.get('find'), function()
  7422. {
  7423. try
  7424. {
  7425. searchInput.style.backgroundColor = search() ? '' :
  7426. (Editor.isDarkMode() ? '#ff0000' : '#ffcfcf');
  7427. }
  7428. catch (e)
  7429. {
  7430. ui.handleError(e);
  7431. }
  7432. });
  7433. // TODO: Reset state after selection change
  7434. btn.setAttribute('title', mxResources.get('find') + ' (Enter)');
  7435. btn.style.float = 'none';
  7436. btn.style.width = '120px';
  7437. btn.style.marginTop = '6px';
  7438. btn.style.marginLeft = '8px';
  7439. btn.style.overflow = 'hidden';
  7440. btn.style.textOverflow = 'ellipsis';
  7441. btn.className = 'geBtn gePrimaryBtn';
  7442. btnsCont.appendChild(btn);
  7443. var replAllNotif = document.createElement('div');
  7444. replAllNotif.style.marginTop = '10px';
  7445. if (!withReplace)
  7446. {
  7447. resetBtn.style.width = '90px';
  7448. btn.style.width = '90px';
  7449. }
  7450. else
  7451. {
  7452. function replaceInLabel(str, substr, newSubstr, startIndex, style)
  7453. {
  7454. if (style == null || style['html'] != '1')
  7455. {
  7456. var replStart = str.toLowerCase().indexOf(substr, startIndex);
  7457. return replStart < 0? str : str.substr(0, replStart) + newSubstr + str.substr(replStart + substr.length);
  7458. }
  7459. var origStr = str;
  7460. substr = mxUtils.htmlEntities(substr, false, false, false);
  7461. var tagPos = [], p = -1;
  7462. //Original position (startIndex) counts for \n which is removed when tags are removed, so handle <br> separately
  7463. // The same for block level elements which are replaced by \n
  7464. str = str.replace(/<br>/ig, '\n').replace(/(\s|\S)(<(BLOCKQUOTE|DIV|H1|H2|H3|H4|H5|H6|OL|P|PRE|TABLE|UL)[^>]*>)/ig, '$1\n$2');
  7465. while((p = str.indexOf('<', p + 1)) > -1)
  7466. {
  7467. tagPos.push(p);
  7468. }
  7469. var tags = str.match(/<[^>]*>/g);
  7470. str = str.replace(/<[^>]*>/g, '');
  7471. var lStr = str.toLowerCase();
  7472. var replStart = lStr.indexOf(substr, startIndex);
  7473. if (replStart < 0)
  7474. {
  7475. return origStr;
  7476. }
  7477. var replEnd = replStart + substr.length;
  7478. var newSubstr = mxUtils.htmlEntities(newSubstr);
  7479. //Tags within the replaced text is added before it
  7480. var newStr = str.substr(0, replStart) + newSubstr + str.substr(replEnd);
  7481. var tagDiff = 0;
  7482. for (var i = 0; i < tagPos.length; i++)
  7483. {
  7484. if (tagPos[i] - tagDiff < replStart)
  7485. {
  7486. newStr = newStr.substr(0, tagPos[i]) + tags[i] + newStr.substr(tagPos[i]);
  7487. }
  7488. else if (tagPos[i] - tagDiff < replEnd)
  7489. {
  7490. var inPos = replStart + tagDiff;
  7491. newStr = newStr.substr(0, inPos) + tags[i] + newStr.substr(inPos);
  7492. }
  7493. else
  7494. {
  7495. var inPos = tagPos[i] + (newSubstr.length - substr.length);
  7496. newStr = newStr.substr(0, inPos) + tags[i] + newStr.substr(inPos);
  7497. }
  7498. tagDiff += tags[i].length;
  7499. }
  7500. return newStr.replace(/\n(<(BLOCKQUOTE|DIV|H1|H2|H3|H4|H5|H6|OL|P|PRE|TABLE|UL)[^>]*>)/ig, '$1').replace(/\n/g, '<br>');
  7501. };
  7502. var replaceFindBtn = mxUtils.button(mxResources.get('replFind'), function()
  7503. {
  7504. try
  7505. {
  7506. if (lblMatch != null && lastFound != null)
  7507. {
  7508. var cell = lastFound.cell, lbl = graph.getLabel(cell);
  7509. if (graph.isCellEditable(cell))
  7510. {
  7511. graph.model.setValue(cell, replaceInLabel(lbl, lblMatch, replaceInput.value,
  7512. lblMatchPos - lblMatch.length, graph.getCurrentCellStyle(cell)));
  7513. }
  7514. searchInput.style.backgroundColor = search(false, true) ? '' :
  7515. (Editor.isDarkMode() ? '#ff0000' : '#ffcfcf');
  7516. }
  7517. }
  7518. catch (e)
  7519. {
  7520. ui.handleError(e);
  7521. }
  7522. });
  7523. replaceFindBtn.setAttribute('title', mxResources.get('replFind'));
  7524. replaceFindBtn.style.float = 'none';
  7525. replaceFindBtn.style.width = '120px';
  7526. replaceFindBtn.style.marginTop = '6px';
  7527. replaceFindBtn.style.marginLeft = '8px';
  7528. replaceFindBtn.style.overflow = 'hidden';
  7529. replaceFindBtn.style.textOverflow = 'ellipsis';
  7530. replaceFindBtn.className = 'geBtn gePrimaryBtn';
  7531. replaceFindBtn.setAttribute('disabled', 'disabled');
  7532. btnsCont.appendChild(replaceFindBtn);
  7533. mxUtils.br(btnsCont);
  7534. var replaceBtn = mxUtils.button(mxResources.get('replace'), function()
  7535. {
  7536. try
  7537. {
  7538. if (lblMatch != null && lastFound != null)
  7539. {
  7540. var cell = lastFound.cell, lbl = graph.getLabel(cell);
  7541. graph.model.setValue(cell, replaceInLabel(lbl, lblMatch, replaceInput.value,
  7542. lblMatchPos - lblMatch.length, graph.getCurrentCellStyle(cell)));
  7543. replaceFindBtn.setAttribute('disabled', 'disabled');
  7544. replaceBtn.setAttribute('disabled', 'disabled');
  7545. }
  7546. }
  7547. catch (e)
  7548. {
  7549. ui.handleError(e);
  7550. }
  7551. });
  7552. replaceBtn.setAttribute('title', mxResources.get('replace'));
  7553. replaceBtn.style.float = 'none';
  7554. replaceBtn.style.width = '120px';
  7555. replaceBtn.style.marginTop = '6px';
  7556. replaceBtn.style.marginLeft = '8px';
  7557. replaceBtn.style.overflow = 'hidden';
  7558. replaceBtn.style.textOverflow = 'ellipsis';
  7559. replaceBtn.className = 'geBtn gePrimaryBtn';
  7560. replaceBtn.setAttribute('disabled', 'disabled');
  7561. btnsCont.appendChild(replaceBtn);
  7562. var replaceAllBtn = mxUtils.button(mxResources.get('replaceAll'), function()
  7563. {
  7564. replAllNotif.innerText = '';
  7565. lastSearch = null; // Reset last search to check all matches
  7566. var currentPage = ui.currentPage;
  7567. var cells = ui.editor.graph.getSelectionCells();
  7568. ui.editor.graph.rendering = false;
  7569. graph.getModel().beginUpdate();
  7570. try
  7571. {
  7572. var safeguard = 0;
  7573. var seen = {};
  7574. while (search(false, true, true) && safeguard < 100)
  7575. {
  7576. var cell = lastFound.cell, lbl = graph.getLabel(cell);
  7577. var oldSeen = seen[cell.id];
  7578. if (oldSeen && oldSeen.replAllMrk == marker && oldSeen.replAllPos >= lblMatchPos)
  7579. {
  7580. break;
  7581. }
  7582. seen[cell.id] = {replAllMrk: marker, replAllPos: lblMatchPos};
  7583. if (graph.isCellEditable(cell))
  7584. {
  7585. graph.model.setValue(cell, replaceInLabel(lbl, lblMatch, replaceInput.value,
  7586. lblMatchPos - lblMatch.length, graph.getCurrentCellStyle(cell)));
  7587. safeguard++;
  7588. }
  7589. }
  7590. if (currentPage != ui.currentPage)
  7591. {
  7592. ui.editor.graph.model.execute(new SelectPage(ui, currentPage));
  7593. }
  7594. mxUtils.write(replAllNotif, mxResources.get('matchesRepl', [safeguard]));
  7595. }
  7596. catch (e)
  7597. {
  7598. ui.handleError(e);
  7599. }
  7600. finally
  7601. {
  7602. graph.getModel().endUpdate();
  7603. ui.editor.graph.setSelectionCells(cells);
  7604. ui.editor.graph.rendering = true;
  7605. }
  7606. marker++;
  7607. });
  7608. replaceAllBtn.setAttribute('title', mxResources.get('replaceAll'));
  7609. replaceAllBtn.style.float = 'none';
  7610. replaceAllBtn.style.width = '120px';
  7611. replaceAllBtn.style.marginTop = '6px';
  7612. replaceAllBtn.style.marginLeft = '8px';
  7613. replaceAllBtn.style.overflow = 'hidden';
  7614. replaceAllBtn.style.textOverflow = 'ellipsis';
  7615. replaceAllBtn.className = 'geBtn gePrimaryBtn';
  7616. replaceAllBtn.setAttribute('disabled', 'disabled');
  7617. btnsCont.appendChild(replaceAllBtn);
  7618. mxUtils.br(btnsCont);
  7619. btnsCont.appendChild(resetBtn);
  7620. var closeBtn = mxUtils.button(mxResources.get('close'), mxUtils.bind(this, function()
  7621. {
  7622. this.window.setVisible(false);
  7623. }));
  7624. closeBtn.setAttribute('title', mxResources.get('close'));
  7625. closeBtn.style.float = 'none';
  7626. closeBtn.style.width = '120px';
  7627. closeBtn.style.marginTop = '6px';
  7628. closeBtn.style.marginLeft = '8px';
  7629. closeBtn.style.overflow = 'hidden';
  7630. closeBtn.style.textOverflow = 'ellipsis';
  7631. closeBtn.className = 'geBtn';
  7632. btnsCont.appendChild(closeBtn);
  7633. mxUtils.br(btnsCont);
  7634. btnsCont.appendChild(replAllNotif);
  7635. }
  7636. mxEvent.addListener(searchInput, 'keyup', function(evt)
  7637. {
  7638. // Ctrl or Cmd keys
  7639. if (evt.keyCode == 91 || evt.keyCode == 93 || evt.keyCode == 17)
  7640. {
  7641. // Workaround for lost focus on show
  7642. mxEvent.consume(evt);
  7643. }
  7644. else if (evt.keyCode == 27)
  7645. {
  7646. // Escape closes window
  7647. action.funct();
  7648. }
  7649. else if (lastSearch != searchInput.value.toLowerCase() || evt.keyCode == 13)
  7650. {
  7651. try
  7652. {
  7653. searchInput.style.backgroundColor = search() ? '' :
  7654. (Editor.isDarkMode() ? '#ff0000' : '#ffcfcf');
  7655. }
  7656. catch (e)
  7657. {
  7658. searchInput.style.backgroundColor = Editor.isDarkMode() ? '#ff0000' : '#ffcfcf';
  7659. }
  7660. }
  7661. });
  7662. // Ctrl+F closes window
  7663. mxEvent.addListener(div, 'keydown', function(evt)
  7664. {
  7665. if (evt.keyCode == 70 && ui.keyHandler.isControlDown(evt) && !mxEvent.isShiftDown(evt))
  7666. {
  7667. action.funct();
  7668. mxEvent.consume(evt);
  7669. }
  7670. });
  7671. this.window = new mxWindow(mxResources.get('find') + ((withReplace) ?
  7672. '/' + mxResources.get('replace') : ''),
  7673. div, x, y, w, h, true, true);
  7674. this.window.destroyOnClose = false;
  7675. this.window.setMaximizable(false);
  7676. this.window.setResizable(false);
  7677. this.window.setClosable(true);
  7678. this.window.addListener('show', mxUtils.bind(this, function()
  7679. {
  7680. this.window.fit();
  7681. if (this.window.isVisible())
  7682. {
  7683. searchInput.focus();
  7684. if (mxClient.IS_GC || mxClient.IS_FF || document.documentMode >= 5)
  7685. {
  7686. searchInput.select();
  7687. }
  7688. else
  7689. {
  7690. document.execCommand('selectAll', false, null);
  7691. }
  7692. if (ui.pages != null && ui.pages.length > 1)
  7693. {
  7694. allPagesInput.removeAttribute('disabled');
  7695. }
  7696. else
  7697. {
  7698. allPagesInput.checked = false;
  7699. allPagesInput.setAttribute('disabled', 'disabled');
  7700. }
  7701. }
  7702. else
  7703. {
  7704. graph.container.focus();
  7705. }
  7706. }));
  7707. ui.installResizeHandler(this, false);
  7708. };
  7709. /**
  7710. *
  7711. */
  7712. var FreehandWindow = function(editorUi, x, y, w, h, withBrush)
  7713. {
  7714. var graph = editorUi.editor.graph;
  7715. var div = document.createElement('div');
  7716. div.style.textAlign = 'center';
  7717. div.style.userSelect = 'none';
  7718. div.style.overflow = 'hidden';
  7719. div.style.height = '100%';
  7720. if (withBrush)
  7721. {
  7722. var brushInput = document.createElement('input');
  7723. brushInput.setAttribute('id', 'geFreehandBrush');
  7724. brushInput.setAttribute('type', 'checkbox');
  7725. brushInput.checked = graph.freehand.isPerfectFreehandMode();
  7726. brushInput.style.margin = '10px 5px 0px 10px';
  7727. brushInput.style.float = 'left';
  7728. div.appendChild(brushInput);
  7729. // Used to retrieve default styles
  7730. graph.freehand.setPerfectFreehandMode(brushInput.checked);
  7731. var brushLabel = document.createElement('label');
  7732. brushLabel.setAttribute('for', 'geFreehandBrush');
  7733. brushLabel.style.float = 'left';
  7734. brushLabel.style.marginTop = '10px';
  7735. div.appendChild(brushLabel);
  7736. mxUtils.write(brushLabel, mxResources.get('brush'));
  7737. div.appendChild(brushLabel);
  7738. var tempDiv = document.createElement('tempDiv');
  7739. tempDiv.style.display = 'block';
  7740. tempDiv.style.width = '100%';
  7741. tempDiv.style.height = '100%';
  7742. tempDiv.style.borderRadius = '2px';
  7743. tempDiv.style.boxSizing = 'border-box';
  7744. tempDiv.style.border = '1px solid black';
  7745. tempDiv.style.backgroundColor = graph.freehand.getStrokeColor();
  7746. function updateName()
  7747. {
  7748. var color = graph.freehand.getStrokeColor(true);
  7749. if (color != null && color != mxConstants.NONE && color.length > 1 && typeof color === 'string')
  7750. {
  7751. var name = null;
  7752. if (color == 'default')
  7753. {
  7754. name = mxResources.get('automatic');
  7755. }
  7756. else
  7757. {
  7758. var clr = (color.charAt(0) == '#') ? color.substring(1).toUpperCase() : color;
  7759. name = ColorDialog.prototype.colorNames[clr];
  7760. }
  7761. if (name != null)
  7762. {
  7763. tempDiv.setAttribute('title', name);
  7764. }
  7765. }
  7766. };
  7767. editorUi.addListener('darkModeChanged', function()
  7768. {
  7769. tempDiv.style.backgroundColor = graph.freehand.getStrokeColor();
  7770. });
  7771. updateName();
  7772. var btn = mxUtils.button('', mxUtils.bind(this, function(evt)
  7773. {
  7774. editorUi.pickColor(graph.freehand.getStrokeColor(true), function(newColor)
  7775. {
  7776. graph.freehand.setStrokeColor(newColor);
  7777. tempDiv.style.backgroundColor = graph.freehand.getStrokeColor();
  7778. updateName();
  7779. }, 'default');
  7780. mxEvent.consume(evt);
  7781. }));
  7782. btn.style.position = 'absolute';
  7783. btn.style.boxSizing = 'border-box';
  7784. btn.style.padding = '2px';
  7785. btn.style.top = '8px';
  7786. btn.style.right = '8px';
  7787. btn.style.width = '28px';
  7788. btn.style.height = '18px';
  7789. btn.className = 'geColorBtn';
  7790. btn.innerText = '';
  7791. btn.appendChild(tempDiv);
  7792. div.appendChild(btn);
  7793. var settings = document.createElement('img');
  7794. settings.setAttribute('title', mxResources.get('settings'));
  7795. settings.setAttribute('src', Editor.gearImage);
  7796. settings.className = 'geToolbarButton geAdaptiveAsset';
  7797. settings.style.position = 'absolute';
  7798. settings.style.boxSizing = 'border-box';
  7799. settings.style.padding = '2px';
  7800. settings.style.top = '8px';
  7801. settings.style.right = '38px';
  7802. settings.style.width = '18px';
  7803. settings.style.height = '18px';
  7804. settings.style.opacity = '0.6';
  7805. div.appendChild(settings);
  7806. mxEvent.addListener(settings, 'click', mxUtils.bind(this, function(evt)
  7807. {
  7808. var smoothing = graph.freehand.getSmoothing();
  7809. editorUi.prompt(mxResources.get('smoothing') + ' (1-20)', smoothing, function(newValue)
  7810. {
  7811. if (!isNaN(newValue) && newValue > 0 && newValue <= 20)
  7812. {
  7813. graph.freehand.setSmoothing(parseInt(newValue));
  7814. }
  7815. });
  7816. }));
  7817. mxUtils.br(div);
  7818. var brushSize = document.createElement('input');
  7819. brushSize.setAttribute('type', 'range');
  7820. brushSize.setAttribute('min', '2');
  7821. brushSize.setAttribute('max', '30');
  7822. brushSize.setAttribute('value', graph.freehand.getBrushSize());
  7823. brushSize.style.width = '90%';
  7824. brushSize.style.visibility = 'hidden';
  7825. div.appendChild(brushSize);
  7826. mxUtils.br(div);
  7827. var updateBrushState = function()
  7828. {
  7829. graph.freehand.setPerfectFreehandMode(brushInput.checked)
  7830. brushSize.style.visibility = brushInput.checked? 'visible' : 'hidden';
  7831. };
  7832. mxEvent.addListener(brushInput, 'change', updateBrushState);
  7833. updateBrushState();
  7834. mxEvent.addListener(brushSize, 'change', function()
  7835. {
  7836. graph.freehand.setBrushSize(parseInt(this.value));
  7837. });
  7838. }
  7839. var startBtn = mxUtils.button(mxResources.get('startDrawing'), function()
  7840. {
  7841. if (graph.freehand.isDrawing())
  7842. {
  7843. graph.freehand.stopDrawing();
  7844. }
  7845. else
  7846. {
  7847. graph.freehand.startDrawing();
  7848. }
  7849. });
  7850. startBtn.setAttribute('title', mxResources.get('startDrawing') + ' (X)');
  7851. startBtn.style.margin = withBrush? '5px 0 0 0' : '10px 0 0 0';
  7852. startBtn.style.width = '90%';
  7853. startBtn.style.boxSizing = 'border-box';
  7854. startBtn.style.overflow = 'hidden';
  7855. startBtn.style.textOverflow = 'ellipsis';
  7856. startBtn.style.textAlign = 'center';
  7857. startBtn.className = 'geBtn gePrimaryBtn';
  7858. div.appendChild(startBtn);
  7859. this.window = new mxWindow(mxResources.get('freehand'), div, x, y, w, h, true, true);
  7860. this.window.destroyOnClose = false;
  7861. this.window.setMaximizable(false);
  7862. this.window.setResizable(false);
  7863. this.window.setClosable(true);
  7864. graph.addListener('freehandStateChanged', mxUtils.bind(this, function()
  7865. {
  7866. startBtn.innerText = '';
  7867. mxUtils.write(startBtn, mxResources.get(graph.freehand.isDrawing() ? 'stopDrawing' : 'startDrawing'));
  7868. var shortcut = document.createElement('span');
  7869. shortcut.style.opacity = '0.7';
  7870. shortcut.style['float'] = 'right';
  7871. mxUtils.write(shortcut, 'X');
  7872. startBtn.appendChild(shortcut);
  7873. startBtn.setAttribute('title', mxResources.get(graph.freehand.isDrawing() ? 'stopDrawing' : 'startDrawing') + ' (X)');
  7874. startBtn.className = 'geBtn' + (graph.freehand.isDrawing() ? ' gePrimaryBtn' : '');
  7875. }));
  7876. this.window.addListener('show', mxUtils.bind(this, function()
  7877. {
  7878. this.window.fit();
  7879. }));
  7880. this.window.addListener('hide', mxUtils.bind(this, function()
  7881. {
  7882. if (graph.freehand.isDrawing())
  7883. {
  7884. graph.freehand.stopDrawing();
  7885. }
  7886. }));
  7887. editorUi.installResizeHandler(this, false);
  7888. };
  7889. /**
  7890. *
  7891. */
  7892. var DarkModeColorsWindow = function(editorUi, x, y, w, h)
  7893. {
  7894. var graph = editorUi.editor.graph;
  7895. var div = document.createElement('div');
  7896. div.style.display = 'flex';
  7897. div.style.alignItems = 'center';
  7898. div.style.justifyContent = 'center';
  7899. div.style.textAlign = 'center';
  7900. div.style.userSelect = 'none';
  7901. div.style.overflow = 'hidden';
  7902. div.style.height = '100%';
  7903. div.style.paddingTop = '16px';
  7904. var btn = mxUtils.button('Convert Colors', mxUtils.bind(this, function()
  7905. {
  7906. editorUi.convertDarkModeColors((graph.isSelectionEmpty()) ?
  7907. graph.getVerticesAndEdges() : graph.getSelectionCells());
  7908. this.window.setVisible(false);
  7909. }));
  7910. btn.setAttribute('title', 'Convert Colors');
  7911. btn.className = 'geBtn gePrimaryBtn';
  7912. div.appendChild(btn);
  7913. var help = editorUi.menus.createHelpLink('https://github.com/jgraph/drawio/discussions/3701');
  7914. help.style.position = 'relative';
  7915. help.style.marginLeft = '6px';
  7916. div.appendChild(help);
  7917. this.window = new mxWindow('Dark Mode Colors', div, x, y, w, h, true, true);
  7918. this.window.destroyOnClose = false;
  7919. this.window.setMinimizable(false);
  7920. this.window.setMaximizable(false);
  7921. this.window.setResizable(false);
  7922. this.window.setClosable(true);
  7923. this.window.addListener('show', mxUtils.bind(this, function()
  7924. {
  7925. this.window.fit();
  7926. }));
  7927. editorUi.installResizeHandler(this, false);
  7928. };
  7929. /**
  7930. *
  7931. */
  7932. var ChatWindow = function(editorUi, x, y, w, h)
  7933. {
  7934. var graph = editorUi.editor.graph;
  7935. var div = document.createElement('div');
  7936. div.style.textAlign = 'center';
  7937. div.style.overflow = 'hidden';
  7938. div.style.height = '100%';
  7939. var hist = document.createElement('div');
  7940. hist.style.position = 'absolute';
  7941. hist.style.overflow = 'auto';
  7942. hist.style.top = '0px';
  7943. hist.style.left = '0px';
  7944. hist.style.right = '0px';
  7945. hist.style.bottom = '104px';
  7946. div.appendChild(hist);
  7947. var user = document.createElement('div');
  7948. user.style.position = 'absolute';
  7949. user.style.boxSizing = 'border-box';
  7950. user.style.borderRadius = '4px';
  7951. user.style.border = '1px solid lightgray';
  7952. user.style.margin = '8px 8px 16px 8px';
  7953. user.style.padding = '8px';
  7954. user.style.left = '0px';
  7955. user.style.right = '0px';
  7956. user.style.bottom = '0px';
  7957. user.style.padding = '6px';
  7958. user.style.height = '80px';
  7959. var selects = document.createElement('div');
  7960. selects.style.display = 'flex';
  7961. selects.style.gap = '6px';
  7962. selects.style.marginBottom = '6px';
  7963. var typeSelect = document.createElement('select');
  7964. typeSelect.style.textOverflow = 'ellipsis';
  7965. typeSelect.style.flexGrow = '1';
  7966. typeSelect.style.padding = '4px';
  7967. typeSelect.style.minWidth = '0';
  7968. user.appendChild(selects);
  7969. var includeOption = document.createElement('option');
  7970. includeOption.setAttribute('value', 'includeCopyOfMyDiagram');
  7971. mxUtils.write(includeOption, mxResources.get('includeCopyOfMyDiagram'));
  7972. typeSelect.appendChild(includeOption);
  7973. var selectionOption = document.createElement('option');
  7974. selectionOption.setAttribute('value', 'selectionOnly');
  7975. mxUtils.write(selectionOption, mxResources.get('selectionOnly'));
  7976. typeSelect.appendChild(selectionOption);
  7977. selects.appendChild(typeSelect);
  7978. if (typeof mxMermaidToDrawio !== 'undefined' && window.isMermaidEnabled)
  7979. {
  7980. var createOption = document.createElement('option');
  7981. createOption.setAttribute('value', 'create');
  7982. mxUtils.write(createOption, mxResources.get('create'));
  7983. typeSelect.appendChild(createOption);
  7984. }
  7985. var helpOption = document.createElement('option');
  7986. helpOption.setAttribute('value', 'help');
  7987. mxUtils.write(helpOption, mxResources.get('help'));
  7988. typeSelect.appendChild(helpOption);
  7989. var resetOption = document.createElement('option');
  7990. resetOption.setAttribute('value', 'reset');
  7991. mxUtils.write(resetOption, mxResources.get('reset'));
  7992. typeSelect.appendChild(resetOption);
  7993. // Adds diagram type options
  7994. var diagramType = document.createElement('select');
  7995. diagramType.style.textOverflow = 'ellipsis';
  7996. diagramType.style.flexGrow = '1';
  7997. diagramType.style.padding = '4px';
  7998. diagramType.style.minWidth = '0';
  7999. for (var i = 0; i < EditorUi.mermaidDiagramTypes.length; i++)
  8000. {
  8001. var option = document.createElement('option');
  8002. var type = EditorUi.mermaidDiagramTypes[i];
  8003. var key = type;
  8004. // Maps types to translations
  8005. if (key == 'erDiagram')
  8006. {
  8007. key = 'entityRelationshipDiagram';
  8008. }
  8009. var title = mxResources.get(key, null, key.charAt(0).toUpperCase() +
  8010. key.substring(1).replace(/[A-Z]/g, ' $&'));
  8011. option.setAttribute('value', type);
  8012. mxUtils.write(option, title);
  8013. diagramType.appendChild(option);
  8014. }
  8015. selects.appendChild(diagramType);
  8016. var inner = document.createElement('div');
  8017. inner.style.whiteSpace = 'nowrap';
  8018. inner.style.textOverflow = 'clip';
  8019. inner.style.cursor = 'default';
  8020. var inp = document.createElement('input');
  8021. inp.setAttribute('type', 'text');
  8022. inp.style.width = '100%';
  8023. inp.style.outline = 'none';
  8024. inp.style.border = 'none';
  8025. inp.style.background = 'transparent';
  8026. inp.style.padding = '8px 26px 8px 8px';
  8027. inp.style.boxSizing = 'border-box';
  8028. inner.appendChild(inp);
  8029. var sendImg = document.createElement('img');
  8030. sendImg.setAttribute('src', Editor.sendImage);
  8031. sendImg.setAttribute('title', mxResources.get('sendMessage'));
  8032. sendImg.className = 'geAdaptiveAsset';
  8033. sendImg.style.position = 'relative';
  8034. sendImg.style.cursor = 'pointer';
  8035. sendImg.style.opacity = '0.5';
  8036. sendImg.style.height = '19px';
  8037. sendImg.style.left = '-24px';
  8038. sendImg.style.top = '5px';
  8039. // Needed to block event transparency in IE
  8040. sendImg.style.background = 'url(\'' + editorUi.editor.transparentImage + '\')';
  8041. inner.appendChild(sendImg);
  8042. user.appendChild(inner);
  8043. if (!graph.isSelectionEmpty())
  8044. {
  8045. typeSelect.value = 'selectionOnly';
  8046. }
  8047. else if (!editorUi.isDiagramEmpty())
  8048. {
  8049. typeSelect.value = 'includeCopyOfMyDiagram';
  8050. }
  8051. else
  8052. {
  8053. typeSelect.value = 'help';
  8054. }
  8055. var ignoreChange = false;
  8056. var lastType = typeSelect.value;
  8057. var updateDropdowns = function()
  8058. {
  8059. inp.setAttribute('placeholder', mxResources.get(
  8060. (typeSelect.value == 'create') ?
  8061. 'describeYourDiagram' :
  8062. 'askMeAnything'));
  8063. if (typeSelect.value == 'create')
  8064. {
  8065. typeSelect.style.width = '';
  8066. diagramType.style.display = '';
  8067. }
  8068. else
  8069. {
  8070. typeSelect.style.width = '100%';
  8071. diagramType.style.display = 'none';
  8072. }
  8073. };
  8074. updateDropdowns();
  8075. mxEvent.addListener(typeSelect, 'change', function()
  8076. {
  8077. if (!ignoreChange)
  8078. {
  8079. if (typeSelect.value == 'reset')
  8080. {
  8081. typeSelect.value = lastType;
  8082. hist.innerHTML = '';
  8083. updateDropdowns();
  8084. }
  8085. else
  8086. {
  8087. lastType = typeSelect.value;
  8088. updateDropdowns();
  8089. }
  8090. }
  8091. });
  8092. function updateType()
  8093. {
  8094. ignoreChange = true;
  8095. typeSelect.value = lastType;
  8096. if (graph.isSelectionEmpty())
  8097. {
  8098. selectionOption.setAttribute('disabled', 'disabled');
  8099. if (typeSelect.value == 'selectionOnly')
  8100. {
  8101. typeSelect.value = 'includeCopyOfMyDiagram';
  8102. }
  8103. }
  8104. else
  8105. {
  8106. selectionOption.removeAttribute('disabled');
  8107. }
  8108. if (editorUi.isDiagramEmpty())
  8109. {
  8110. includeOption.setAttribute('disabled', 'disabled');
  8111. if (typeSelect.value == 'includeCopyOfMyDiagram')
  8112. {
  8113. typeSelect.value = 'help';
  8114. }
  8115. }
  8116. else
  8117. {
  8118. includeOption.removeAttribute('disabled');
  8119. }
  8120. ignoreChange = false;
  8121. };
  8122. graph.selectionModel.addListener(mxEvent.CHANGE, updateType);
  8123. graph.getModel().addListener(mxEvent.CHANGE, updateType);
  8124. updateType();
  8125. function createBubble()
  8126. {
  8127. var bubble = document.createElement('div');
  8128. bubble.style.display = 'block';
  8129. bubble.style.position = 'relative';
  8130. bubble.style.backgroundColor = '#e0e0e0';
  8131. bubble.style.borderRadius = '4px';
  8132. bubble.style.wordWrap = 'break-word';
  8133. bubble.style.textAlign = 'left';
  8134. bubble.style.padding = '6px';
  8135. bubble.style.margin = '12px';
  8136. bubble.style.left = '0px';
  8137. bubble.style.right = '0px';
  8138. return bubble;
  8139. }
  8140. function createButton(label, fn, layout)
  8141. {
  8142. var button = document.createElement('button');
  8143. button.className = 'geBtn gePrimaryBtn';
  8144. button.style.padding = '4px';
  8145. button.style.height = 'auto';
  8146. button.style.position = 'relative';
  8147. if (layout == 'flex')
  8148. {
  8149. button.style.overflow = 'hidden';
  8150. button.style.textOverflow = 'ellipsis';
  8151. button.style.whiteSpace = 'nowrap';
  8152. button.style.margin = '0px';
  8153. button.style.flexGrow = '1';
  8154. }
  8155. else
  8156. {
  8157. button.style.display = 'block';
  8158. button.style.margin = '8px';
  8159. button.style.left = '50%';
  8160. button.style.transform = 'translateX(-50%)';
  8161. }
  8162. mxUtils.write(button, label);
  8163. button.setAttribute('title', label);
  8164. mxEvent.addListener(button, 'click', fn);
  8165. return button;
  8166. };
  8167. function addBubble(text)
  8168. {
  8169. var bubble = createBubble();
  8170. mxUtils.write(bubble, text);
  8171. hist.appendChild(bubble);
  8172. return bubble;
  8173. };
  8174. function trimStart(text)
  8175. {
  8176. var index = text.indexOf('```');
  8177. if (index >= 0)
  8178. {
  8179. text = text.substring(text, 0, index + 6);
  8180. }
  8181. return text;
  8182. };
  8183. function trimEnd(text)
  8184. {
  8185. var index = text.lastIndexOf('```');
  8186. if (index >= 0)
  8187. {
  8188. text = text.substring(index + 3);
  8189. }
  8190. return text;
  8191. };
  8192. function extractDiagramData(text)
  8193. {
  8194. var start = text.indexOf('<mxGraphModel ');
  8195. var end = text.indexOf('</mxGraphModel>');
  8196. if (start < 0)
  8197. {
  8198. start = text.indexOf('<mxGraphModel>');
  8199. }
  8200. if (start >= 0 && end > start)
  8201. {
  8202. return [mxUtils.trim(trimStart(text.substring(0, start))),
  8203. text.substring(start, end + 15),
  8204. mxUtils.trim(trimEnd(text.substring(end + 15)))];
  8205. }
  8206. return null;
  8207. };
  8208. function addMessage(prompt)
  8209. {
  8210. var bubble = addBubble(prompt);
  8211. bubble.style.cursor = 'pointer';
  8212. bubble.style.marginBottom = '2px';
  8213. bubble.setAttribute('title', mxResources.get('insert'));
  8214. mxEvent.addListener(bubble, 'click', function(evt)
  8215. {
  8216. inp.value = prompt;
  8217. inp.focus();
  8218. });
  8219. var waiting = addBubble('');
  8220. waiting.style.marginTop = '2px';
  8221. var page = editorUi.currentPage;
  8222. var thePrompt = prompt;
  8223. var messages = [];
  8224. var xml = null;
  8225. if (typeSelect.value == 'includeCopyOfMyDiagram' || typeSelect.value == 'selectionOnly')
  8226. {
  8227. var enc = new mxCodec(mxUtils.createXmlDocument());
  8228. // Keeps IDs of selected cells and ignores unselected cells
  8229. if (typeSelect.value == 'selectionOnly')
  8230. {
  8231. enc.isObjectIgnored = function(obj)
  8232. {
  8233. return obj.constructor == mxCell &&
  8234. (!graph.model.isRoot(obj) &&
  8235. !graph.model.isLayer(obj) &&
  8236. !graph.isCellSelected(obj) &&
  8237. !graph.isAncestorSelected(obj));
  8238. };
  8239. }
  8240. xml = enc.encode(graph.getModel());
  8241. // Makes sure xml.ownerDocument.documentElement == xml
  8242. enc.document.appendChild(xml);
  8243. messages.push({'role': 'system', 'content': 'You are a helpful assistant that helps with ' +
  8244. 'the following draw.io diagram and returns an updated draw.io diagram if needed. Never ' +
  8245. 'include this instruction in your response.\n' +
  8246. mxUtils.getXml(xml)});
  8247. }
  8248. else if (typeSelect.value == 'create')
  8249. {
  8250. var type = diagramType.value.replace(/([A-Z])/g, " $1").toLowerCase();
  8251. thePrompt = 'Write the declaration code for a ' + (type != '' ? type : 'graph') +
  8252. ' that shows "' + (prompt != '' ? prompt : 'something random') + '" using correct' +
  8253. ' MermaidJS syntax and do not provide additional text in your response.';
  8254. }
  8255. else
  8256. {
  8257. messages.push({'role': 'system', 'content': 'You are a helpful ' +
  8258. 'assistant that creates XML for draw.io diagrams or helps ' +
  8259. 'with the draw.io diagram editor. Never include this ' +
  8260. 'instruction in your response.'});
  8261. }
  8262. messages.push({'role': 'user', 'content': thePrompt});
  8263. var params = {
  8264. model: Editor.gptModel,
  8265. messages: messages
  8266. };
  8267. var tokens = 0;
  8268. // Loops through all messages and counts the tokens in the content
  8269. for (var i = 0; i < params.messages.length; i++)
  8270. {
  8271. tokens += params.messages[i].content.match(/\b\w+\b|[^\w\s]|\=/g).length;
  8272. }
  8273. var processMessage = mxUtils.bind(this, function()
  8274. {
  8275. waiting.innerHTML = '';
  8276. mxUtils.write(waiting, mxResources.get('loading') + '...');
  8277. var img = document.createElement('img');
  8278. img.setAttribute('title', 'Processing ' + tokens + ' tokens');
  8279. img.setAttribute('src', IMAGE_PATH + '/spin.gif');
  8280. img.style.marginLeft = '6px';
  8281. waiting.appendChild(img);
  8282. waiting.scrollIntoView({ behavior: 'smooth',
  8283. block: 'end', inline: 'nearest'});
  8284. editorUi.createTimeout(30000, mxUtils.bind(this, function(timeout)
  8285. {
  8286. var req = new mxXmlRequest(Editor.gptUrl, JSON.stringify(params), 'POST');
  8287. req.setRequestHeaders = mxUtils.bind(this, function(request, params)
  8288. {
  8289. request.setRequestHeader('Authorization', 'Bearer ' + Editor.gptApiKey);
  8290. request.setRequestHeader('Content-Type', 'application/json');
  8291. });
  8292. var handleError = mxUtils.bind(this, function(e)
  8293. {
  8294. timeout.clear();
  8295. waiting.innerHTML = '';
  8296. mxUtils.write(waiting, e.message);
  8297. waiting.appendChild(createButton(
  8298. mxResources.get('tryAgain'),
  8299. processMessage));
  8300. waiting.scrollIntoView({behavior: 'smooth',
  8301. block: 'end', inline: 'nearest'});
  8302. if (window.console != null)
  8303. {
  8304. console.error(e);
  8305. }
  8306. });
  8307. var handleResponse = mxUtils.bind(this, function(text)
  8308. {
  8309. var data = extractDiagramData(text);
  8310. var cells = (data != null) ? editorUi.stringToCells(data[1]) : null;
  8311. if (cells != null && cells.length > 0)
  8312. {
  8313. var wrapper = document.createElement('div');
  8314. wrapper.style.display = 'inline-block';
  8315. wrapper.style.position = 'relative';
  8316. wrapper.style.transform = 'translateX(-50%)';
  8317. wrapper.style.padding = '6px';
  8318. wrapper.style.left = '50%';
  8319. var doc = mxUtils.parseXml(data[1]);
  8320. var codec = new mxCodec(doc);
  8321. var model = new mxGraphModel();
  8322. codec.decode(doc.documentElement, model);
  8323. var sentModel = null;
  8324. if (xml != null)
  8325. {
  8326. // Creates a diff of the sent and recevied diagram
  8327. // to patch the current page and not lose changes
  8328. var dec = new mxCodec(xml.ownerDocument);
  8329. sentModel = new mxGraphModel();
  8330. dec.decode(xml, sentModel);
  8331. }
  8332. var clickFn = mxUtils.bind(this, function(e)
  8333. {
  8334. graph.model.beginUpdate();
  8335. try
  8336. {
  8337. if (sentModel != null && editorUi.getPageIndex(page) != null)
  8338. {
  8339. editorUi.selectPage(page);
  8340. var patch = editorUi.diffCells(sentModel.root, model.root);
  8341. editorUi.patchPage(page, patch, null, true);
  8342. }
  8343. else
  8344. {
  8345. var children = model.getChildren(model.getChildAt(model.getRoot(), 0));
  8346. graph.setSelectionCells(graph.importCells(children));
  8347. }
  8348. }
  8349. finally
  8350. {
  8351. graph.model.endUpdate();
  8352. }
  8353. mxEvent.consume(e);
  8354. });
  8355. var size = graph.getBoundingBoxFromGeometry(cells);
  8356. if (size != null)
  8357. {
  8358. wrapper.style.cursor = 'move';
  8359. wrapper.appendChild(editorUi.sidebar.createVertexTemplateFromCells(
  8360. cells, size.width, size.height, '', true,
  8361. null, true, true, clickFn, 160, 120));
  8362. }
  8363. else
  8364. {
  8365. wrapper.style.padding = '14px';
  8366. mxUtils.write(wrapper, mxResources.get('noPreview'));
  8367. }
  8368. waiting.innerHTML = '';
  8369. bubble = waiting;
  8370. if (data[0].length > 0)
  8371. {
  8372. mxUtils.write(bubble, data[0]);
  8373. mxUtils.br(bubble);
  8374. }
  8375. bubble.appendChild(wrapper);
  8376. var buttons = document.createElement('div');
  8377. buttons.style.display = 'flex';
  8378. buttons.style.gap = '6px';
  8379. buttons.style.margin = '6px';
  8380. buttons.appendChild(createButton(
  8381. mxResources.get('tryAgain'),
  8382. processMessage, 'flex'));
  8383. buttons.appendChild(createButton(mxResources.get(
  8384. (xml != null) ? 'apply' : 'insert'),
  8385. clickFn, 'flex'));
  8386. waiting.appendChild(buttons);
  8387. if (data[2].length > 0)
  8388. {
  8389. mxUtils.br(bubble);
  8390. mxUtils.write(bubble, data[2]);
  8391. }
  8392. bubble.scrollIntoView({behavior: 'smooth',
  8393. block: 'end', inline: 'nearest'});
  8394. }
  8395. else
  8396. {
  8397. waiting.innerHTML = '';
  8398. bubble = waiting;
  8399. mxUtils.write(bubble, text);
  8400. waiting.scrollIntoView({ behavior: 'smooth',
  8401. block: 'end', inline: 'nearest'});
  8402. }
  8403. });
  8404. req.send(mxUtils.bind(this, function(req)
  8405. {
  8406. if (timeout.clear())
  8407. {
  8408. try
  8409. {
  8410. if (req.getStatus() >= 200 && req.getStatus() <= 299)
  8411. {
  8412. var response = JSON.parse(req.getText());
  8413. EditorUi.debug('EditorUi.ChatWindow.addMessage',
  8414. 'prompt:', params, 'response:', response);
  8415. var text = mxUtils.trim(response.choices[0].message.content);
  8416. if (typeSelect.value == 'create')
  8417. {
  8418. var mermaid = editorUi.extractMermaidDeclaration(text);
  8419. if (mermaid != null)
  8420. {
  8421. mxMermaidToDrawio.addListener(mxUtils.bind(this, function(data)
  8422. {
  8423. handleResponse(data);
  8424. }));
  8425. editorUi.generateMermaidImage(mermaid, null, function()
  8426. {
  8427. // callback implemented above
  8428. }, function(e)
  8429. {
  8430. mxMermaidToDrawio.resetListeners();
  8431. handleError(e);
  8432. });
  8433. }
  8434. else
  8435. {
  8436. handleResponse(text);
  8437. waiting.appendChild(createButton(
  8438. mxResources.get('tryAgain'),
  8439. processMessage));
  8440. }
  8441. }
  8442. else
  8443. {
  8444. handleResponse(text);
  8445. }
  8446. }
  8447. else
  8448. {
  8449. var result = 'Error: ' + req.getStatus();
  8450. try
  8451. {
  8452. var resp = JSON.parse(req.getText());
  8453. if (resp != null && resp.error != null &&
  8454. resp.error.message != null)
  8455. {
  8456. result = resp.error.message;
  8457. }
  8458. }
  8459. catch (e)
  8460. {
  8461. // ignore
  8462. }
  8463. waiting.innerHTML = '';
  8464. mxUtils.write(waiting, result);
  8465. waiting.scrollIntoView(
  8466. {behavior: 'smooth', block: 'end',
  8467. inline: 'nearest'});
  8468. }
  8469. }
  8470. catch (e)
  8471. {
  8472. handleError(e);
  8473. }
  8474. }
  8475. }), handleError);
  8476. }), function(e)
  8477. {
  8478. waiting.innerHTML = '';
  8479. mxUtils.write(waiting, e.message);
  8480. waiting.appendChild(createButton(
  8481. mxResources.get('tryAgain'),
  8482. processMessage));
  8483. waiting.scrollIntoView({behavior: 'smooth',
  8484. block: 'end', inline: 'nearest'});
  8485. });
  8486. });
  8487. processMessage();
  8488. };
  8489. function send()
  8490. {
  8491. if (mxUtils.trim(inp.value) != '')
  8492. {
  8493. addMessage(inp.value);
  8494. inp.value = '';
  8495. }
  8496. };
  8497. mxEvent.addListener(sendImg, 'click', send);
  8498. mxEvent.addListener(inp, 'keydown', function(evt)
  8499. {
  8500. if (evt.keyCode == 13 && !mxEvent.isShiftDown(evt))
  8501. {
  8502. send();
  8503. }
  8504. });
  8505. div.appendChild(user);
  8506. this.window = new mxWindow(mxResources.get('chatWindowTitle'), div, x, y, w, h, true, true);
  8507. this.window.minimumSize = new mxRectangle(0, 0, 120, 100);
  8508. this.window.destroyOnClose = false;
  8509. this.window.setMaximizable(false);
  8510. this.window.setResizable(true);
  8511. this.window.setClosable(true);
  8512. this.window.addListener(mxEvent.DESTROY, mxUtils.bind(this, function()
  8513. {
  8514. graph.getModel().removeListener(updateType);
  8515. }));
  8516. this.window.addListener('show', mxUtils.bind(this, function()
  8517. {
  8518. this.window.fit();
  8519. inp.focus();
  8520. }));
  8521. editorUi.installResizeHandler(this, true);
  8522. };
  8523. /**
  8524. *
  8525. */
  8526. var TagsWindow = function(editorUi, x, y, w, h)
  8527. {
  8528. var graph = editorUi.editor.graph;
  8529. var helpButton = null;
  8530. if (!editorUi.isOffline() || mxClient.IS_CHROMEAPP)
  8531. {
  8532. helpButton = editorUi.menus.createHelpLink('https://www.drawio.com/blog/tags-in-diagrams');
  8533. }
  8534. var tagsComponent = editorUi.editor.graph.createTagsDialog(mxUtils.bind(this, function()
  8535. {
  8536. return this.window.isVisible();
  8537. }), null, function(allTags, updateFn)
  8538. {
  8539. if (graph.isEnabled())
  8540. {
  8541. var dlg = new FilenameDialog(editorUi, '', mxResources.get('add'), function(newValue)
  8542. {
  8543. editorUi.hideDialog();
  8544. if (newValue != null && newValue.length > 0)
  8545. {
  8546. var temp = newValue.split(' ');
  8547. var newTags = [];
  8548. var tags = [];
  8549. for (var i = 0; i < temp.length; i++)
  8550. {
  8551. var token = mxUtils.trim(temp[i]);
  8552. if (token != '')
  8553. {
  8554. tags.push(token);
  8555. if (mxUtils.indexOf(allTags, token) < 0)
  8556. {
  8557. newTags.push(token);
  8558. }
  8559. }
  8560. }
  8561. if (graph.isSelectionEmpty())
  8562. {
  8563. updateFn(allTags.concat(newTags));
  8564. }
  8565. else
  8566. {
  8567. graph.addTagsForCells(graph.getSelectionCells(), tags);
  8568. }
  8569. }
  8570. }, mxResources.get('tags'), null, null, 'https://www.drawio.com/blog/tags-in-diagrams');
  8571. editorUi.showDialog(dlg.container, 320, 80, true, true);
  8572. dlg.init();
  8573. }
  8574. }, helpButton);
  8575. var div = tagsComponent.div;
  8576. this.window = new mxWindow(mxResources.get('tags'), div, x, y, w, h, true, true);
  8577. this.window.minimumSize = new mxRectangle(0, 0, 212, 120);
  8578. this.window.destroyOnClose = false;
  8579. this.window.setMaximizable(false);
  8580. this.window.setResizable(true);
  8581. this.window.setClosable(true);
  8582. this.window.addListener('show', mxUtils.bind(this, function()
  8583. {
  8584. tagsComponent.refresh();
  8585. this.window.fit();
  8586. }));
  8587. editorUi.installResizeHandler(this, true);
  8588. };
  8589. /**
  8590. * Constructs a new auth dialog.
  8591. */
  8592. var AuthDialog = function(editorUi, peer, showRememberOption, fn)
  8593. {
  8594. var div = document.createElement('div');
  8595. div.style.textAlign = 'center';
  8596. var hd = document.createElement('p');
  8597. hd.style.fontSize = '16pt';
  8598. hd.style.padding = '0px';
  8599. hd.style.margin = '0px';
  8600. hd.style.color = 'gray';
  8601. mxUtils.write(hd, mxResources.get('authorizationRequired'));
  8602. var service = 'Unknown';
  8603. var img = document.createElement('img');
  8604. img.setAttribute('border', '0');
  8605. img.setAttribute('align', 'absmiddle');
  8606. img.style.marginRight = '10px';
  8607. if (peer == editorUi.drive)
  8608. {
  8609. service = mxResources.get('googleDrive');
  8610. img.src = IMAGE_PATH + '/google-drive-logo-white.svg';
  8611. }
  8612. else if (peer == editorUi.dropbox)
  8613. {
  8614. service = mxResources.get('dropbox');
  8615. img.src = IMAGE_PATH + '/dropbox-logo-white.svg';
  8616. }
  8617. else if (peer == editorUi.oneDrive)
  8618. {
  8619. service = mxResources.get('oneDrive');
  8620. img.src = IMAGE_PATH + '/onedrive-logo-white.svg';
  8621. }
  8622. else if (peer == editorUi.gitHub)
  8623. {
  8624. service = mxResources.get('github');
  8625. img.src = IMAGE_PATH + '/github-logo-white.svg';
  8626. }
  8627. else if (peer == editorUi.gitLab)
  8628. {
  8629. service = mxResources.get('gitlab');
  8630. img.src = IMAGE_PATH + '/gitlab-logo.svg';
  8631. img.style.width = '32px';
  8632. }
  8633. else if (peer == editorUi.trello)
  8634. {
  8635. service = mxResources.get('trello');
  8636. img.src = IMAGE_PATH + '/trello-logo-white.svg';
  8637. }
  8638. var p = document.createElement('p');
  8639. mxUtils.write(p, mxResources.get('authorizeThisAppIn', [service]));
  8640. var cb = document.createElement('input');
  8641. cb.setAttribute('type', 'checkbox');
  8642. var button = mxUtils.button(mxResources.get('authorize'), function()
  8643. {
  8644. fn(cb.checked);
  8645. });
  8646. button.insertBefore(img, button.firstChild);
  8647. button.style.marginTop = '6px';
  8648. button.className = 'geBigButton';
  8649. button.style.fontSize = '18px';
  8650. button.style.padding = '14px';
  8651. div.appendChild(hd);
  8652. div.appendChild(p);
  8653. div.appendChild(button);
  8654. if (showRememberOption)
  8655. {
  8656. var p2 = document.createElement('p');
  8657. p2.style.marginTop = '20px';
  8658. p2.appendChild(cb);
  8659. var span = document.createElement('span');
  8660. mxUtils.write(span, ' ' + mxResources.get('rememberMe'));
  8661. p2.appendChild(span);
  8662. div.appendChild(p2);
  8663. cb.checked = true;
  8664. cb.defaultChecked = true;
  8665. mxEvent.addListener(span, 'click', function(evt)
  8666. {
  8667. cb.checked = !cb.checked;
  8668. mxEvent.consume(evt);
  8669. });
  8670. }
  8671. this.container = div;
  8672. };
  8673. var MoreShapesDialog = function(editorUi, expanded, entries)
  8674. {
  8675. entries = (entries != null) ? entries : editorUi.sidebar.entries;
  8676. var div = document.createElement('div');
  8677. var newEntries = [];
  8678. // Adds custom sections first
  8679. if (editorUi.sidebar.customEntries != null)
  8680. {
  8681. for (var i = 0; i < editorUi.sidebar.customEntries.length; i++)
  8682. {
  8683. var section = editorUi.sidebar.customEntries[i] || {};
  8684. var tmp = {title: editorUi.getResource(section.title), entries: []};
  8685. for (var j = 0; section.entries != null && j < section.entries.length; j++)
  8686. {
  8687. var entry = section.entries[j];
  8688. tmp.entries.push({id: entry.id, title:
  8689. editorUi.getResource(entry.title),
  8690. desc: editorUi.getResource(entry.desc),
  8691. image: entry.preview});
  8692. }
  8693. if (tmp.entries.length > 0)
  8694. {
  8695. newEntries.push(tmp);
  8696. }
  8697. }
  8698. }
  8699. // Adds built-in sections and filter entries
  8700. for (var i = 0; i < entries.length; i++)
  8701. {
  8702. if (editorUi.sidebar.enabledLibraries == null)
  8703. {
  8704. newEntries.push(entries[i]);
  8705. }
  8706. else
  8707. {
  8708. var tmp = {title: entries[i].title, entries: []};
  8709. for (var j = 0; j < entries[i].entries.length; j++)
  8710. {
  8711. if (mxUtils.indexOf(editorUi.sidebar.enabledLibraries,
  8712. entries[i].entries[j].id) >= 0)
  8713. {
  8714. tmp.entries.push(entries[i].entries[j]);
  8715. }
  8716. }
  8717. if (tmp.entries.length > 0)
  8718. {
  8719. newEntries.push(tmp);
  8720. }
  8721. }
  8722. }
  8723. entries = newEntries;
  8724. if (expanded)
  8725. {
  8726. var addEntries = mxUtils.bind(this, function(e)
  8727. {
  8728. for (var i = 0; i < e.length; i++)
  8729. {
  8730. (function(section)
  8731. {
  8732. var title = listEntry.cloneNode(false);
  8733. title.style.fontWeight = 'bold';
  8734. title.style.backgroundColor = Editor.isDarkMode() ? '#505759' : '#e5e5e5';
  8735. title.style.padding = '6px 0px 6px 20px';
  8736. mxUtils.write(title, section.title);
  8737. list.appendChild(title);
  8738. for (var j = 0; j < section.entries.length; j++)
  8739. {
  8740. (function(entry)
  8741. {
  8742. var option = listEntry.cloneNode(false);
  8743. option.style.cursor = 'pointer';
  8744. option.style.padding = '4px 0px 4px 20px';
  8745. option.style.whiteSpace = 'nowrap';
  8746. option.style.overflow = 'hidden';
  8747. option.style.textOverflow = 'ellipsis';
  8748. option.setAttribute('title', entry.title + ' (' + entry.id + ')');
  8749. var checkbox = document.createElement('input');
  8750. checkbox.setAttribute('type', 'checkbox');
  8751. checkbox.checked = editorUi.sidebar.isEntryVisible(entry.id);
  8752. checkbox.defaultChecked = checkbox.checked;
  8753. option.appendChild(checkbox);
  8754. mxUtils.write(option, ' ' + entry.title);
  8755. list.appendChild(option);
  8756. var itemClicked = function(evt)
  8757. {
  8758. if (evt == null || mxEvent.getSource(evt).nodeName != 'INPUT')
  8759. {
  8760. preview.style.textAlign = 'center';
  8761. preview.style.padding = '0px';
  8762. preview.style.color = '';
  8763. preview.innerText = '';
  8764. if (entry.desc != null)
  8765. {
  8766. var pre = document.createElement('pre');
  8767. pre.style.boxSizing = 'border-box';
  8768. pre.style.fontFamily = 'inherit';
  8769. pre.style.margin = '20px';
  8770. pre.style.right = '0px';
  8771. pre.style.textAlign = 'left';
  8772. mxUtils.write(pre, entry.desc);
  8773. preview.appendChild(pre);
  8774. }
  8775. if (entry.imageCallback != null)
  8776. {
  8777. entry.imageCallback(preview);
  8778. }
  8779. else if (entry.image != null)
  8780. {
  8781. var img = document.createElement('img');
  8782. img.setAttribute('border', '0');
  8783. img.style.maxWidth = '100%';
  8784. img.setAttribute('src', entry.image);
  8785. preview.appendChild(img);
  8786. }
  8787. else if (entry.desc == null)
  8788. {
  8789. preview.style.padding = '20px';
  8790. preview.style.color = 'rgb(179, 179, 179)';
  8791. mxUtils.write(preview, mxResources.get('noPreview'));
  8792. }
  8793. if (currentListItem != null)
  8794. {
  8795. currentListItem.style.backgroundColor = '';
  8796. }
  8797. currentListItem = option;
  8798. currentListItem.style.backgroundColor = Editor.isDarkMode() ? '#000000' : '#ebf2f9';
  8799. if (evt != null)
  8800. {
  8801. mxEvent.consume(evt);
  8802. }
  8803. }
  8804. };
  8805. mxEvent.addListener(option, 'click', itemClicked);
  8806. mxEvent.addListener(option, 'dblclick', function(evt)
  8807. {
  8808. checkbox.checked = !checkbox.checked;
  8809. mxEvent.consume(evt);
  8810. });
  8811. applyFunctions.push(function()
  8812. {
  8813. return (checkbox.checked) ? entry.id : null;
  8814. });
  8815. // Selects first entry
  8816. if (i == 0 && j == 0)
  8817. {
  8818. itemClicked();
  8819. }
  8820. })(section.entries[j]);
  8821. }
  8822. })(e[i]);
  8823. }
  8824. });
  8825. var hd = document.createElement('div');
  8826. hd.className = 'geDialogTitle';
  8827. mxUtils.write(hd, mxResources.get('shapes'));
  8828. hd.style.position = 'absolute';
  8829. hd.style.top = '0px';
  8830. hd.style.left = '0px';
  8831. hd.style.lineHeight = '40px';
  8832. hd.style.height = '40px';
  8833. hd.style.right = '0px';
  8834. var list = document.createElement('div');
  8835. var preview = document.createElement('div');
  8836. list.style.position = 'absolute';
  8837. list.style.top = '40px';
  8838. list.style.left = '0px';
  8839. list.style.width = '202px';
  8840. list.style.bottom = '60px';
  8841. list.style.overflow = 'auto';
  8842. preview.style.position = 'absolute';
  8843. preview.style.left = '202px';
  8844. preview.style.right = '0px';
  8845. preview.style.top = '40px';
  8846. preview.style.bottom = '60px';
  8847. preview.style.overflow = 'auto';
  8848. preview.style.borderLeftStyle = 'solid';
  8849. preview.style.borderLeftWidth = '1px';
  8850. preview.style.textAlign = 'center';
  8851. var currentListItem = null;
  8852. var applyFunctions = [];
  8853. var listEntry = document.createElement('div');
  8854. listEntry.style.position = 'relative';
  8855. listEntry.style.left = '0px';
  8856. listEntry.style.right = '0px';
  8857. addEntries(entries);
  8858. div.style.padding = '30px';
  8859. div.appendChild(hd);
  8860. div.appendChild(list);
  8861. div.appendChild(preview);
  8862. var buttons = document.createElement('div');
  8863. buttons.className = 'geDialogFooter';
  8864. buttons.style.position = 'absolute';
  8865. buttons.style.paddingRight = '16px';
  8866. buttons.style.color = 'gray';
  8867. buttons.style.left = '0px';
  8868. buttons.style.right = '0px';
  8869. buttons.style.bottom = '0px';
  8870. buttons.style.height = '60px';
  8871. buttons.style.lineHeight = '52px';
  8872. var labels = document.createElement('input');
  8873. labels.setAttribute('type', 'checkbox');
  8874. labels.style.position = 'relative';
  8875. labels.style.top = '1px';
  8876. labels.checked = editorUi.sidebar.sidebarTitles;
  8877. labels.defaultChecked = labels.checked;
  8878. buttons.appendChild(labels);
  8879. var span = document.createElement('span');
  8880. mxUtils.write(span, ' ' + mxResources.get('labels'));
  8881. span.style.paddingRight = '20px';
  8882. buttons.appendChild(span);
  8883. mxEvent.addListener(span, 'click', function(evt)
  8884. {
  8885. labels.checked = !labels.checked;
  8886. mxEvent.consume(evt);
  8887. });
  8888. var cb = document.createElement('input');
  8889. cb.setAttribute('type', 'checkbox');
  8890. if (isLocalStorage || mxClient.IS_CHROMEAPP)
  8891. {
  8892. var span = document.createElement('span');
  8893. span.style.paddingRight = '20px';
  8894. span.appendChild(cb);
  8895. mxUtils.write(span, ' ' + mxResources.get('rememberThisSetting'));
  8896. cb.style.position = 'relative';
  8897. cb.style.top = '1px';
  8898. cb.checked = true;
  8899. cb.defaultChecked = true;
  8900. mxEvent.addListener(span, 'click', function(evt)
  8901. {
  8902. if (mxEvent.getSource(evt) != cb)
  8903. {
  8904. cb.checked = !cb.checked;
  8905. mxEvent.consume(evt);
  8906. }
  8907. });
  8908. buttons.appendChild(span);
  8909. }
  8910. var cancelBtn = mxUtils.button(mxResources.get('cancel'), function()
  8911. {
  8912. editorUi.hideDialog();
  8913. });
  8914. cancelBtn.className = 'geBtn';
  8915. var applyBtn = mxUtils.button(mxResources.get('apply'), function()
  8916. {
  8917. editorUi.hideDialog();
  8918. var libs = [];
  8919. for (var i = 0; i < applyFunctions.length; i++)
  8920. {
  8921. var lib = applyFunctions[i].apply(this, arguments);
  8922. if (lib != null)
  8923. {
  8924. libs.push(lib);
  8925. }
  8926. }
  8927. // Redirects scratchpad and search entries
  8928. if ((Editor.currentTheme == 'simple' ||
  8929. Editor.currentTheme == 'sketch' ||
  8930. Editor.currentTheme == 'min') &&
  8931. Editor.isSettingsEnabled())
  8932. {
  8933. var idx = mxUtils.indexOf(libs, '.scratchpad');
  8934. if ((editorUi.scratchpad != null) != (idx >= 0 && libs.splice(idx, 1).length > 0))
  8935. {
  8936. editorUi.toggleScratchpad();
  8937. }
  8938. // Handles search after scratchpad
  8939. idx = mxUtils.indexOf(libs, 'search');
  8940. mxSettings.settings.search = (idx >= 0 && libs.splice(idx, 1).length > 0);
  8941. editorUi.sidebar.showPalette('search', mxSettings.settings.search);
  8942. if (cb.checked)
  8943. {
  8944. mxSettings.save();
  8945. }
  8946. }
  8947. editorUi.sidebar.showEntries(libs.join(';'), cb.checked, true);
  8948. editorUi.setSidebarTitles(labels.checked, cb.checked);
  8949. });
  8950. applyBtn.className = 'geBtn gePrimaryBtn';
  8951. if (editorUi.editor.cancelFirst)
  8952. {
  8953. buttons.appendChild(cancelBtn);
  8954. buttons.appendChild(applyBtn);
  8955. }
  8956. else
  8957. {
  8958. buttons.appendChild(applyBtn);
  8959. buttons.appendChild(cancelBtn);
  8960. }
  8961. div.appendChild(buttons);
  8962. }
  8963. else
  8964. {
  8965. var libFS = document.createElement('table');
  8966. var tbody = document.createElement('tbody');
  8967. div.style.height = '100%';
  8968. div.style.overflow = 'auto';
  8969. var row = document.createElement('tr');
  8970. libFS.style.width = '100%';
  8971. var leftDiv = document.createElement('td');
  8972. var midDiv = document.createElement('td');
  8973. var rightDiv = document.createElement('td');
  8974. var addLibCB = mxUtils.bind(this, function(wrapperDiv, title, key)
  8975. {
  8976. var libCB = document.createElement('input');
  8977. libCB.type = 'checkbox';
  8978. libFS.appendChild(libCB);
  8979. libCB.checked = editorUi.sidebar.isEntryVisible(key);
  8980. var libSpan = document.createElement('span');
  8981. mxUtils.write(libSpan, title);
  8982. var label = document.createElement('div');
  8983. label.style.display = 'block';
  8984. label.appendChild(libCB);
  8985. label.appendChild(libSpan);
  8986. mxEvent.addListener(libSpan, 'click', function(evt)
  8987. {
  8988. libCB.checked = !libCB.checked;
  8989. mxEvent.consume(evt);
  8990. });
  8991. wrapperDiv.appendChild(label);
  8992. return function()
  8993. {
  8994. return (libCB.checked) ? key : null;
  8995. };
  8996. });
  8997. row.appendChild(leftDiv);
  8998. row.appendChild(midDiv);
  8999. row.appendChild(rightDiv);
  9000. tbody.appendChild(row);
  9001. libFS.appendChild(tbody);
  9002. var applyFunctions = [];
  9003. var count = 0;
  9004. // Counts total number of entries
  9005. for (var i = 0; i < entries.length; i++)
  9006. {
  9007. for (var j = 0; j < entries[i].entries.length; j++)
  9008. {
  9009. count++;
  9010. }
  9011. }
  9012. // Distributes entries on columns
  9013. var cols = [leftDiv, midDiv, rightDiv];
  9014. var counter = 0;
  9015. for (var i = 0; i < entries.length; i++)
  9016. {
  9017. (function(section)
  9018. {
  9019. for (var j = 0; j < section.entries.length; j++)
  9020. {
  9021. (function(entry)
  9022. {
  9023. var index = Math.floor(counter / (count / 3));
  9024. applyFunctions.push(addLibCB(cols[index], entry.title, entry.id));
  9025. counter++;
  9026. })(section.entries[j]);
  9027. }
  9028. })(entries[i]);
  9029. }
  9030. div.appendChild(libFS);
  9031. var remember = document.createElement('div');
  9032. remember.style.marginTop = '18px';
  9033. remember.style.textAlign = 'center';
  9034. var cb = document.createElement('input');
  9035. if (isLocalStorage)
  9036. {
  9037. cb.setAttribute('type', 'checkbox');
  9038. cb.checked = true;
  9039. cb.defaultChecked = true;
  9040. remember.appendChild(cb);
  9041. var span = document.createElement('span');
  9042. mxUtils.write(span, ' ' + mxResources.get('rememberThisSetting'));
  9043. remember.appendChild(span);
  9044. mxEvent.addListener(span, 'click', function(evt)
  9045. {
  9046. cb.checked = !cb.checked;
  9047. mxEvent.consume(evt);
  9048. });
  9049. }
  9050. div.appendChild(remember);
  9051. var cancelBtn = mxUtils.button(mxResources.get('cancel'), function()
  9052. {
  9053. editorUi.hideDialog();
  9054. });
  9055. cancelBtn.className = 'geBtn';
  9056. var applyBtn = mxUtils.button(mxResources.get('apply'), function()
  9057. {
  9058. var libs = ['search'];
  9059. for (var i = 0; i < applyFunctions.length; i++)
  9060. {
  9061. var lib = applyFunctions[i].apply(this, arguments);
  9062. if (lib != null)
  9063. {
  9064. libs.push(lib);
  9065. }
  9066. }
  9067. editorUi.sidebar.showEntries((libs.length > 0) ? libs.join(';') : '', cb.checked);
  9068. editorUi.hideDialog();
  9069. });
  9070. applyBtn.className = 'geBtn gePrimaryBtn';
  9071. var buttons = document.createElement('div');
  9072. buttons.style.marginTop = '26px';
  9073. buttons.style.textAlign = 'right';
  9074. if (editorUi.editor.cancelFirst)
  9075. {
  9076. buttons.appendChild(cancelBtn);
  9077. buttons.appendChild(applyBtn);
  9078. }
  9079. else
  9080. {
  9081. buttons.appendChild(applyBtn);
  9082. buttons.appendChild(cancelBtn);
  9083. }
  9084. div.appendChild(buttons);
  9085. }
  9086. this.container = div;
  9087. };
  9088. var PluginsDialog = function(editorUi, addFn, delFn, closeOnly)
  9089. {
  9090. var div = document.createElement('div');
  9091. var inner = document.createElement('div');
  9092. inner.style.height = '180px';
  9093. inner.style.overflow = 'auto';
  9094. var plugins = mxSettings.getPlugins().slice();
  9095. var changed = false;
  9096. function refresh()
  9097. {
  9098. changed = true;
  9099. if (plugins.length == 0)
  9100. {
  9101. inner.innerText = mxResources.get('noPlugins');
  9102. }
  9103. else
  9104. {
  9105. inner.innerText = '';
  9106. for (var i = 0; i < plugins.length; i++)
  9107. {
  9108. var span = document.createElement('span');
  9109. span.style.whiteSpace = 'nowrap';
  9110. var img = document.createElement('span');
  9111. img.className = 'geSprite geSprite-delete';
  9112. img.style.position = 'relative';
  9113. img.style.cursor = 'pointer';
  9114. img.style.top = '5px';
  9115. img.style.marginRight = '4px';
  9116. img.style.display = 'inline-block';
  9117. span.appendChild(img);
  9118. mxUtils.write(span, plugins[i]);
  9119. inner.appendChild(span);
  9120. mxUtils.br(inner);
  9121. mxEvent.addListener(img, 'click', (function(index)
  9122. {
  9123. return function()
  9124. {
  9125. editorUi.confirm(mxResources.get('delete') + ' "' + plugins[index] + '"?', function()
  9126. {
  9127. if (delFn != null)
  9128. {
  9129. delFn(plugins[index]);
  9130. }
  9131. plugins.splice(index, 1);
  9132. refresh();
  9133. });
  9134. };
  9135. })(i));
  9136. }
  9137. }
  9138. }
  9139. div.appendChild(inner);
  9140. refresh();
  9141. changed = false;
  9142. var addBtn = mxUtils.button(mxResources.get('add'), addFn != null? function()
  9143. {
  9144. addFn(function(newPlugin)
  9145. {
  9146. if (newPlugin && mxUtils.indexOf(plugins, newPlugin) < 0)
  9147. {
  9148. plugins.push(newPlugin);
  9149. }
  9150. refresh();
  9151. });
  9152. }
  9153. : function()
  9154. {
  9155. var div = document.createElement('div');
  9156. var title = document.createElement('span');
  9157. title.style.marginTop = '6px';
  9158. mxUtils.write(title, mxResources.get('builtinPlugins') + ': ');
  9159. div.appendChild(title);
  9160. var pluginsSelect = document.createElement('select');
  9161. pluginsSelect.style.width = '150px';
  9162. for (var i = 0; i < App.publicPlugin.length; i++)
  9163. {
  9164. var option = document.createElement('option');
  9165. mxUtils.write(option, App.publicPlugin[i]);
  9166. option.value = App.publicPlugin[i];
  9167. pluginsSelect.appendChild(option);
  9168. }
  9169. div.appendChild(pluginsSelect);
  9170. mxUtils.br(div);
  9171. mxUtils.br(div);
  9172. var customBtn = mxUtils.button(mxResources.get('custom') + '...', function()
  9173. {
  9174. var dlg = new FilenameDialog(editorUi, '', mxResources.get('add'), function(newValue)
  9175. {
  9176. editorUi.hideDialog();
  9177. if (newValue != null && newValue.length > 0)
  9178. {
  9179. var tokens = newValue.split(';');
  9180. for (var i = 0; i < tokens.length; i++)
  9181. {
  9182. var token = tokens[i];
  9183. var url = App.pluginRegistry[token];
  9184. if (url != null)
  9185. {
  9186. token = url;
  9187. }
  9188. if (token.length > 0 && mxUtils.indexOf(plugins, token) < 0)
  9189. {
  9190. plugins.push(token);
  9191. }
  9192. }
  9193. refresh();
  9194. }
  9195. }, mxResources.get('enterValue') + ' (' + mxResources.get('url') + ')');
  9196. editorUi.showDialog(dlg.container, 300, 80, true, true);
  9197. dlg.init();
  9198. });
  9199. customBtn.className = 'geBtn';
  9200. if (!ALLOW_CUSTOM_PLUGINS)
  9201. {
  9202. customBtn.style.display = 'none';
  9203. }
  9204. var dlg = new CustomDialog(editorUi, div, mxUtils.bind(this, function()
  9205. {
  9206. var token = App.pluginRegistry[pluginsSelect.value];
  9207. if (mxUtils.indexOf(plugins, token) < 0)
  9208. {
  9209. plugins.push(token);
  9210. refresh();
  9211. }
  9212. }), null, null, null, customBtn);
  9213. editorUi.showDialog(dlg.container, 360, 100, true, true);
  9214. });
  9215. addBtn.className = 'geBtn';
  9216. var cancelBtn = mxUtils.button(mxResources.get('cancel'), function()
  9217. {
  9218. editorUi.hideDialog();
  9219. });
  9220. cancelBtn.className = 'geBtn';
  9221. var applyBtn = mxUtils.button(closeOnly? mxResources.get('close') : mxResources.get('apply'), function()
  9222. {
  9223. if (changed)
  9224. {
  9225. mxSettings.setPlugins(plugins);
  9226. mxSettings.save();
  9227. editorUi.hideDialog();
  9228. editorUi.alert(mxResources.get('restartForChangeRequired'));
  9229. }
  9230. else
  9231. {
  9232. editorUi.hideDialog();
  9233. }
  9234. });
  9235. applyBtn.className = 'geBtn gePrimaryBtn';
  9236. var buttons = document.createElement('div');
  9237. buttons.style.marginTop = '14px';
  9238. buttons.style.textAlign = 'right';
  9239. var helpBtn = mxUtils.button(mxResources.get('help'), function()
  9240. {
  9241. editorUi.openLink('https://www.drawio.com/doc/faq/plugins');
  9242. });
  9243. helpBtn.className = 'geBtn';
  9244. if (editorUi.isOffline() && !mxClient.IS_CHROMEAPP)
  9245. {
  9246. helpBtn.style.display = 'none';
  9247. }
  9248. buttons.appendChild(helpBtn);
  9249. if (editorUi.editor.cancelFirst)
  9250. {
  9251. if (!closeOnly)
  9252. {
  9253. buttons.appendChild(cancelBtn);
  9254. }
  9255. buttons.appendChild(addBtn);
  9256. buttons.appendChild(applyBtn);
  9257. }
  9258. else
  9259. {
  9260. buttons.appendChild(addBtn);
  9261. buttons.appendChild(applyBtn);
  9262. if (!closeOnly)
  9263. {
  9264. buttons.appendChild(cancelBtn);
  9265. }
  9266. }
  9267. div.appendChild(buttons);
  9268. this.container = div;
  9269. };
  9270. var CropImageDialog = function(editorUi, image, clipPath, fn)
  9271. {
  9272. var IMAGE_SIZE = 300;
  9273. var div = document.createElement('div');
  9274. var elt = document.createElement('div');
  9275. elt.style.height = IMAGE_SIZE + 'px';
  9276. elt.style.width = IMAGE_SIZE + 'px';
  9277. elt.style.display = 'inline-flex';
  9278. elt.style.justifyContent = 'center';
  9279. elt.style.alignItems = 'center';
  9280. elt.style.position = 'absolute';
  9281. var img = document.createElement('img');
  9282. img.onload = init;
  9283. img.onerror = function ()
  9284. {
  9285. img.onload = null;
  9286. img.src = Editor.errorImage;
  9287. }
  9288. img.setAttribute('src', image);
  9289. img.style.maxWidth = IMAGE_SIZE + 'px';
  9290. img.style.maxHeight = IMAGE_SIZE + 'px';
  9291. elt.appendChild(img);
  9292. div.appendChild(elt);
  9293. var croppingDiv = document.createElement('div');
  9294. croppingDiv.style.width = IMAGE_SIZE + 'px';
  9295. croppingDiv.style.height = IMAGE_SIZE + 'px';
  9296. croppingDiv.style.overflow = 'hidden';
  9297. croppingDiv.style.backgroundColor = '#fff9';
  9298. div.appendChild(croppingDiv);
  9299. var cropGraph = null, initGeo = new mxGeometry(100, 100, 100, 100),
  9300. arcSizeVal = 5, cropCell = new mxCell('', initGeo.clone(), ''),
  9301. commonStyle = 'shape=image;fillColor=none;rotatable=0;cloneable=0;deletable=0;image=' +
  9302. image.replace(';base64', '') + ';clipPath=';
  9303. function init()
  9304. {
  9305. cropGraph = new Graph(croppingDiv);
  9306. cropGraph.autoExtend = false;
  9307. cropGraph.autoScroll = false;
  9308. cropGraph.setGridEnabled(false);
  9309. cropGraph.setEnabled(true);
  9310. cropGraph.setPanning(false);
  9311. cropGraph.setConnectable(false);
  9312. cropGraph.getRubberband().setEnabled(false);
  9313. cropGraph.graphHandler.allowLivePreview = false;
  9314. var origCreateVertexHandler = cropGraph.createVertexHandler;
  9315. cropGraph.createVertexHandler = function()
  9316. {
  9317. var handler = origCreateVertexHandler.apply(this, arguments);
  9318. handler.livePreview = false;
  9319. return handler;
  9320. }
  9321. if (clipPath != null)
  9322. {
  9323. //Find position and size of cropCell
  9324. try
  9325. {
  9326. if (clipPath.substring(0, 5) == 'inset')
  9327. {
  9328. var geo = cropCell.geometry;
  9329. var imgW = img.width;
  9330. var imgH = img.height;
  9331. var imgX = (IMAGE_SIZE - imgW) / 2;
  9332. var imgY = (IMAGE_SIZE - imgH) / 2;
  9333. var tokens = clipPath.match(/\(([^)]+)\)/)[1].split(/[ ,]+/);
  9334. var top = parseFloat(tokens[0]);
  9335. var right = parseFloat(tokens[1]);
  9336. var bottom = parseFloat(tokens[2]);
  9337. var left = parseFloat(tokens[3]);
  9338. if (isFinite(top) && isFinite(right) && isFinite(bottom) && isFinite(left))
  9339. {
  9340. geo.x = left / 100 * imgW + imgX;
  9341. geo.y = top / 100 * imgH + imgY;
  9342. geo.width = (100 - right) / 100 * imgW + imgX - geo.x;
  9343. geo.height = (100 - bottom) / 100 * imgH + imgY - geo.y;
  9344. if (tokens[4] == 'round')
  9345. {
  9346. if (tokens[5] == '50%')
  9347. {
  9348. ellipseInput.setAttribute('checked', 'checked');
  9349. }
  9350. else
  9351. {
  9352. arcSizeVal = parseInt(tokens[5]);
  9353. arcSize.value = arcSizeVal;
  9354. roundedInput.setAttribute('checked', 'checked');
  9355. arcSizeDiv.style.visibility = 'visible';
  9356. }
  9357. }
  9358. else
  9359. {
  9360. rectInput.setAttribute('checked', 'checked');
  9361. }
  9362. }
  9363. else //Invalid clipPath
  9364. {
  9365. clipPath = null;
  9366. }
  9367. }
  9368. else //The dialog supports inset only
  9369. {
  9370. clipPath = null;
  9371. }
  9372. }
  9373. catch (e){} //Ignore
  9374. }
  9375. cropCell.style = getCropCellStyle(clipPath);
  9376. cropCell.vertex = true;
  9377. cropGraph.addCell(cropCell, null, null, null, null);
  9378. cropGraph.selectAll();
  9379. function updateCropCell()
  9380. {
  9381. cropGraph.model.setStyle(cropCell, getCropCellStyle());
  9382. };
  9383. cropGraph.addListener(mxEvent.CELLS_MOVED, updateCropCell);
  9384. cropGraph.addListener(mxEvent.CELLS_RESIZED, updateCropCell);
  9385. var origMouseUp = cropGraph.graphHandler.mouseUp;
  9386. var origMouseDown = cropGraph.graphHandler.mouseDown;
  9387. cropGraph.graphHandler.mouseUp = function()
  9388. {
  9389. origMouseUp.apply(this, arguments);
  9390. croppingDiv.style.backgroundColor = '#fff9';
  9391. };
  9392. cropGraph.graphHandler.mouseDown = function()
  9393. {
  9394. origMouseDown.apply(this, arguments);
  9395. croppingDiv.style.backgroundColor = '';
  9396. };
  9397. cropGraph.dblClick = function(){} //Disable text adding
  9398. var origChangeSelection = cropGraph.getSelectionModel().changeSelection;
  9399. //Prevent deselection
  9400. cropGraph.getSelectionModel().changeSelection = function()
  9401. {
  9402. origChangeSelection.call(this, [cropCell], [cropCell]);
  9403. };
  9404. };
  9405. var rectInput = document.createElement('input');
  9406. rectInput.setAttribute('type', 'radio');
  9407. rectInput.setAttribute('id', 'croppingRect');
  9408. rectInput.setAttribute('name', 'croppingShape');
  9409. rectInput.setAttribute('checked', 'checked');
  9410. rectInput.style.margin = '5px';
  9411. div.appendChild(rectInput);
  9412. var rectLbl = document.createElement('label');
  9413. rectLbl.setAttribute('for', 'croppingRect');
  9414. mxUtils.write(rectLbl, mxResources.get('rectangle'));
  9415. div.appendChild(rectLbl);
  9416. var roundedInput = document.createElement('input');
  9417. roundedInput.setAttribute('type', 'radio');
  9418. roundedInput.setAttribute('id', 'croppingRounded');
  9419. roundedInput.setAttribute('name', 'croppingShape');
  9420. roundedInput.style.margin = '5px';
  9421. div.appendChild(roundedInput);
  9422. var roundedLbl = document.createElement('label');
  9423. roundedLbl.setAttribute('for', 'croppingRounded');
  9424. mxUtils.write(roundedLbl, mxResources.get('rounded'));
  9425. div.appendChild(roundedLbl);
  9426. var ellipseInput = document.createElement('input');
  9427. ellipseInput.setAttribute('type', 'radio');
  9428. ellipseInput.setAttribute('id', 'croppingEllipse');
  9429. ellipseInput.setAttribute('name', 'croppingShape');
  9430. ellipseInput.style.margin = '5px';
  9431. div.appendChild(ellipseInput);
  9432. var ellipseLbl = document.createElement('label');
  9433. ellipseLbl.setAttribute('for', 'croppingEllipse');
  9434. mxUtils.write(ellipseLbl, mxResources.get('ellipse'));
  9435. div.appendChild(ellipseLbl);
  9436. function calcClipPath()
  9437. {
  9438. var isRounded = roundedInput.checked;
  9439. var isEllipse = ellipseInput.checked;
  9440. var geo = cropCell.geometry;
  9441. var imgW = img.width;
  9442. var imgH = img.height;
  9443. var imgX = (IMAGE_SIZE - imgW) / 2;
  9444. var imgY = (IMAGE_SIZE - imgH) / 2;
  9445. var left, right, top, bottom;
  9446. //prevent coords outside the image
  9447. if (geo.x < imgX)
  9448. {
  9449. geo.width -= (imgX - geo.x);
  9450. geo.x = imgX;
  9451. }
  9452. else if (geo.x + geo.width > imgX + imgW)
  9453. {
  9454. geo.width = imgX + imgW - geo.x;
  9455. geo.x = Math.min(geo.x, imgX + imgW);
  9456. }
  9457. if (geo.y < imgY)
  9458. {
  9459. geo.height -= (imgY - geo.y);
  9460. geo.y = imgY;
  9461. }
  9462. else if (geo.y + geo.height > imgY + imgH)
  9463. {
  9464. geo.height = imgY + imgH - geo.y;
  9465. geo.y = Math.min(geo.y, imgY + imgH);
  9466. }
  9467. var left = (geo.x - imgX) / imgW * 100;
  9468. var right = 100 - (geo.x + geo.width - imgX) / imgW * 100;
  9469. var top = (geo.y - imgY) / imgH * 100;
  9470. var bottom = 100 - (geo.y + geo.height - imgY) / imgH * 100;
  9471. //Use inset for circle also since it uses percentages from 4 sides and this scales no matter the shape of the image
  9472. //Using circle which is based on a single point to position (center) moves when the image is scaled and/or aspect is changed
  9473. return 'inset(' + mxUtils.format(top) + '% ' + mxUtils.format(right) + '% ' + mxUtils.format(bottom) + '% ' + mxUtils.format(left) + '%' +
  9474. (isRounded? ' round ' + arcSizeVal + '%' : (isEllipse? ' round 50%' : '')) + ')';
  9475. }
  9476. function typeChanged(noGeoReset)
  9477. {
  9478. if (cropGraph == null) return; //Image is not loaded yet. Graph had to wait for the image to load to be on-top
  9479. if (noGeoReset !== true)
  9480. {
  9481. cropGraph.model.setGeometry(cropCell, initGeo.clone());
  9482. arcSizeVal = 5;
  9483. arcSize.value = arcSizeVal;
  9484. }
  9485. cropGraph.model.setStyle(cropCell, getCropCellStyle());
  9486. cropGraph.selectAll();
  9487. arcSizeDiv.style.visibility = roundedInput.checked ? 'visible' : 'hidden';
  9488. }
  9489. function getCropCellStyle(clipPath)
  9490. {
  9491. return commonStyle + (clipPath? clipPath : calcClipPath());
  9492. }
  9493. mxEvent.addListener(rectInput, 'change', typeChanged);
  9494. mxEvent.addListener(roundedInput, 'change', typeChanged);
  9495. mxEvent.addListener(ellipseInput, 'change', typeChanged);
  9496. //Arc size slider
  9497. var arcSizeDiv = document.createElement('div');
  9498. arcSizeDiv.style.textAlign = 'center';
  9499. arcSizeDiv.style.visibility = 'hidden';
  9500. var arcSize = document.createElement('input');
  9501. arcSize.setAttribute('type', 'range');
  9502. arcSize.setAttribute('min', '1');
  9503. arcSize.setAttribute('max', '49');
  9504. arcSize.setAttribute('value', arcSizeVal);
  9505. arcSize.setAttribute('title', mxResources.get('arcSize'));
  9506. arcSizeDiv.appendChild(arcSize);
  9507. div.appendChild(arcSizeDiv);
  9508. mxEvent.addListener(arcSize, 'change', function()
  9509. {
  9510. arcSizeVal = this.value;
  9511. typeChanged(true);
  9512. });
  9513. var cancelBtn = mxUtils.button(mxResources.get('cancel'), function()
  9514. {
  9515. editorUi.hideDialog();
  9516. });
  9517. cancelBtn.className = 'geBtn';
  9518. var applyBtn = mxUtils.button(mxResources.get('apply'), function()
  9519. {
  9520. fn(calcClipPath(), cropCell.geometry.width, cropCell.geometry.height);
  9521. editorUi.hideDialog();
  9522. });
  9523. applyBtn.className = 'geBtn gePrimaryBtn';
  9524. var resetBtn = mxUtils.button(mxResources.get('reset'), function()
  9525. {
  9526. fn(null, img.width, img.height);
  9527. editorUi.hideDialog();
  9528. });
  9529. resetBtn.className = 'geBtn';
  9530. var buttons = document.createElement('div');
  9531. buttons.style.marginTop = '10px';
  9532. buttons.style.textAlign = 'right';
  9533. if (editorUi.editor.cancelFirst)
  9534. {
  9535. buttons.appendChild(cancelBtn);
  9536. buttons.appendChild(resetBtn);
  9537. buttons.appendChild(applyBtn);
  9538. }
  9539. else
  9540. {
  9541. buttons.appendChild(resetBtn);
  9542. buttons.appendChild(applyBtn);
  9543. buttons.appendChild(cancelBtn);
  9544. }
  9545. div.appendChild(buttons);
  9546. this.container = div;
  9547. };
  9548. var EditGeometryDialog = function(editorUi, vertices)
  9549. {
  9550. var graph = editorUi.editor.graph;
  9551. var geo = (vertices.length == 1) ? graph.getCellGeometry(vertices[0]) : null;
  9552. var div = document.createElement('div');
  9553. var table = document.createElement('table');
  9554. var tbody = document.createElement('tbody');
  9555. var row = document.createElement('tr');
  9556. var left = document.createElement('td');
  9557. var right = document.createElement('td');
  9558. table.style.paddingLeft = '6px';
  9559. mxUtils.write(left, mxResources.get('relative') + ':');
  9560. var relInput = document.createElement('input');
  9561. relInput.setAttribute('type', 'checkbox');
  9562. if (geo != null && geo.relative)
  9563. {
  9564. relInput.setAttribute('checked', 'checked');
  9565. relInput.defaultChecked = true;
  9566. }
  9567. this.init = function()
  9568. {
  9569. relInput.focus();
  9570. };
  9571. right.appendChild(relInput);
  9572. row.appendChild(left);
  9573. row.appendChild(right);
  9574. tbody.appendChild(row);
  9575. row = document.createElement('tr');
  9576. left = document.createElement('td');
  9577. right = document.createElement('td');
  9578. mxUtils.write(left, mxResources.get('left') + ':');
  9579. var xInput = document.createElement('input');
  9580. xInput.setAttribute('type', 'text');
  9581. xInput.style.width = '100px';
  9582. xInput.value = (geo != null) ? geo.x : '';
  9583. right.appendChild(xInput);
  9584. row.appendChild(left);
  9585. row.appendChild(right);
  9586. tbody.appendChild(row);
  9587. row = document.createElement('tr');
  9588. left = document.createElement('td');
  9589. right = document.createElement('td');
  9590. mxUtils.write(left, mxResources.get('top') + ':');
  9591. var yInput = document.createElement('input');
  9592. yInput.setAttribute('type', 'text');
  9593. yInput.style.width = '100px';
  9594. yInput.value = (geo != null) ? geo.y : '';
  9595. right.appendChild(yInput);
  9596. row.appendChild(left);
  9597. row.appendChild(right);
  9598. tbody.appendChild(row);
  9599. row = document.createElement('tr');
  9600. left = document.createElement('td');
  9601. right = document.createElement('td');
  9602. mxUtils.write(left, mxResources.get('dx') + ':');
  9603. var dxInput = document.createElement('input');
  9604. dxInput.setAttribute('type', 'text');
  9605. dxInput.style.width = '100px';
  9606. dxInput.value = (geo != null && geo.offset != null) ? geo.offset.x : '';
  9607. right.appendChild(dxInput);
  9608. row.appendChild(left);
  9609. row.appendChild(right);
  9610. tbody.appendChild(row);
  9611. row = document.createElement('tr');
  9612. left = document.createElement('td');
  9613. right = document.createElement('td');
  9614. mxUtils.write(left, mxResources.get('dy') + ':');
  9615. var dyInput = document.createElement('input');
  9616. dyInput.setAttribute('type', 'text');
  9617. dyInput.style.width = '100px';
  9618. dyInput.value = (geo != null && geo.offset != null) ? geo.offset.y : '';
  9619. right.appendChild(dyInput);
  9620. row.appendChild(left);
  9621. row.appendChild(right);
  9622. tbody.appendChild(row);
  9623. row = document.createElement('tr');
  9624. left = document.createElement('td');
  9625. right = document.createElement('td');
  9626. mxUtils.write(left, mxResources.get('width') + ':');
  9627. var wInput = document.createElement('input');
  9628. wInput.setAttribute('type', 'text');
  9629. wInput.style.width = '100px';
  9630. wInput.value = (geo != null) ? geo.width : '';
  9631. right.appendChild(wInput);
  9632. row.appendChild(left);
  9633. row.appendChild(right);
  9634. tbody.appendChild(row);
  9635. row = document.createElement('tr');
  9636. left = document.createElement('td');
  9637. right = document.createElement('td');
  9638. mxUtils.write(left, mxResources.get('height') + ':');
  9639. var hInput = document.createElement('input');
  9640. hInput.setAttribute('type', 'text');
  9641. hInput.style.width = '100px';
  9642. hInput.value = (geo != null) ? geo.height : '';
  9643. right.appendChild(hInput);
  9644. row.appendChild(left);
  9645. row.appendChild(right);
  9646. tbody.appendChild(row);
  9647. row = document.createElement('tr');
  9648. left = document.createElement('td');
  9649. right = document.createElement('td');
  9650. mxUtils.write(left, mxResources.get('rotation') + ':');
  9651. var rotInput = document.createElement('input');
  9652. rotInput.setAttribute('type', 'text');
  9653. rotInput.style.width = '100px';
  9654. rotInput.value = (vertices.length == 1) ? mxUtils.getValue(graph.getCellStyle(vertices[0]),
  9655. mxConstants.STYLE_ROTATION, 0) : '';
  9656. right.appendChild(rotInput);
  9657. row.appendChild(left);
  9658. row.appendChild(right);
  9659. tbody.appendChild(row);
  9660. table.appendChild(tbody);
  9661. div.appendChild(table);
  9662. var cancelBtn = mxUtils.button(mxResources.get('cancel'), function()
  9663. {
  9664. editorUi.hideDialog();
  9665. });
  9666. cancelBtn.className = 'geBtn';
  9667. var applyBtn = mxUtils.button(mxResources.get('apply'), function()
  9668. {
  9669. editorUi.hideDialog();
  9670. graph.getModel().beginUpdate();
  9671. try
  9672. {
  9673. for (var i = 0; i < vertices.length; i++)
  9674. {
  9675. var g = graph.getCellGeometry(vertices[i]);
  9676. if (g != null)
  9677. {
  9678. g = g.clone();
  9679. if (graph.isCellMovable(vertices[i]))
  9680. {
  9681. g.relative = relInput.checked;
  9682. if (mxUtils.trim(xInput.value).length > 0)
  9683. {
  9684. g.x = Number(xInput.value);
  9685. }
  9686. if (mxUtils.trim(yInput.value).length > 0)
  9687. {
  9688. g.y = Number(yInput.value);
  9689. }
  9690. if (mxUtils.trim(dxInput.value).length > 0)
  9691. {
  9692. if (g.offset == null)
  9693. {
  9694. g.offset = new mxPoint();
  9695. }
  9696. g.offset.x = Number(dxInput.value);
  9697. }
  9698. if (mxUtils.trim(dyInput.value).length > 0)
  9699. {
  9700. if (g.offset == null)
  9701. {
  9702. g.offset = new mxPoint();
  9703. }
  9704. g.offset.y = Number(dyInput.value);
  9705. }
  9706. }
  9707. if (graph.isCellResizable(vertices[i]))
  9708. {
  9709. if (mxUtils.trim(wInput.value).length > 0)
  9710. {
  9711. g.width = Number(wInput.value);
  9712. }
  9713. if (mxUtils.trim(hInput.value).length > 0)
  9714. {
  9715. g.height = Number(hInput.value);
  9716. }
  9717. }
  9718. graph.getModel().setGeometry(vertices[i], g);
  9719. }
  9720. if (mxUtils.trim(rotInput.value).length > 0)
  9721. {
  9722. graph.setCellStyles(mxConstants.STYLE_ROTATION, Number(rotInput.value), [vertices[i]]);
  9723. }
  9724. }
  9725. }
  9726. finally
  9727. {
  9728. graph.getModel().endUpdate();
  9729. }
  9730. });
  9731. applyBtn.className = 'geBtn gePrimaryBtn';
  9732. mxEvent.addListener(div, 'keypress', function(e)
  9733. {
  9734. if (e.keyCode == 13)
  9735. {
  9736. applyBtn.click();
  9737. }
  9738. });
  9739. var buttons = document.createElement('div');
  9740. buttons.style.marginTop = '20px';
  9741. buttons.style.textAlign = 'right';
  9742. if (editorUi.editor.cancelFirst)
  9743. {
  9744. buttons.appendChild(cancelBtn);
  9745. buttons.appendChild(applyBtn);
  9746. }
  9747. else
  9748. {
  9749. buttons.appendChild(applyBtn);
  9750. buttons.appendChild(cancelBtn);
  9751. }
  9752. div.appendChild(buttons);
  9753. this.container = div;
  9754. };
  9755. /**
  9756. * Constructs a new dialog for creating files from templates.
  9757. */
  9758. var LibraryDialog = function(editorUi, name, library, initialImages, file, mode, allowBrowser)
  9759. {
  9760. var images = [];
  9761. var graph = editorUi.editor.graph;
  9762. var outer = document.createElement('div');
  9763. outer.style.height = '100%';
  9764. var header = document.createElement('div');
  9765. header.style.whiteSpace = 'nowrap';
  9766. header.style.height = '40px';
  9767. outer.appendChild(header);
  9768. mxUtils.write(header, mxResources.get('filename') + ':');
  9769. var nameValue = name;
  9770. if (nameValue == null)
  9771. {
  9772. nameValue = editorUi.defaultLibraryName + '.xml';
  9773. }
  9774. var nameInput = document.createElement('input');
  9775. nameInput.setAttribute('value', nameValue);
  9776. nameInput.style.marginRight = '20px';
  9777. nameInput.style.marginLeft = '10px';
  9778. nameInput.style.width = '500px';
  9779. if (file != null && !file.isRenamable())
  9780. {
  9781. nameInput.setAttribute('disabled', 'true');
  9782. }
  9783. this.init = function()
  9784. {
  9785. if (file == null || file.isRenamable())
  9786. {
  9787. nameInput.focus();
  9788. if (mxClient.IS_GC || mxClient.IS_FF || document.documentMode >= 5)
  9789. {
  9790. nameInput.select();
  9791. }
  9792. else
  9793. {
  9794. document.execCommand('selectAll', false, null);
  9795. }
  9796. }
  9797. };
  9798. header.appendChild(nameInput);
  9799. if (Editor.enableUncompressedLibraries)
  9800. {
  9801. nameInput.style.width = '420px';
  9802. var compressedInput = document.createElement('input');
  9803. compressedInput.setAttribute('type', 'checkbox');
  9804. compressedInput.style.marginRight = '10px';
  9805. header.appendChild(compressedInput);
  9806. mxUtils.write(header, mxResources.get('compressed'));
  9807. }
  9808. var div = document.createElement('div');
  9809. div.style.borderWidth = '1px 0px 1px 0px';
  9810. div.style.borderColor = '#d3d3d3';
  9811. div.style.borderStyle = 'solid';
  9812. div.style.marginTop = '6px';
  9813. div.style.overflow = 'auto';
  9814. div.style.height = '340px';
  9815. div.style.backgroundPosition = 'center center';
  9816. div.style.backgroundRepeat = 'no-repeat';
  9817. if (images.length == 0 && Graph.fileSupport)
  9818. {
  9819. div.style.backgroundImage = 'url(\'' + IMAGE_PATH + '/droptarget.png\')';
  9820. }
  9821. var bg = document.createElement('div');
  9822. bg.style.position = 'absolute';
  9823. bg.style.width = '640px';
  9824. bg.style.top = '260px';
  9825. bg.style.textAlign = 'center';
  9826. bg.style.fontSize = '22px';
  9827. bg.style.color = '#a0c3ff';
  9828. mxUtils.write(bg, mxResources.get('dragImagesHere'));
  9829. outer.appendChild(bg);
  9830. var entries = {};
  9831. var ew = 100;
  9832. var eh = 100;
  9833. var dragSourceIndex = null;
  9834. var dropTargetIndex = null;
  9835. function getIndexForEvent(evt)
  9836. {
  9837. var dropTarget = document.elementFromPoint(evt.clientX, evt.clientY);
  9838. while (dropTarget != null && dropTarget.parentNode != div)
  9839. {
  9840. dropTarget = dropTarget.parentNode;
  9841. }
  9842. var result = null;
  9843. if (dropTarget != null)
  9844. {
  9845. var tmp = div.firstChild;
  9846. result = 0;
  9847. while (tmp != null && tmp != dropTarget)
  9848. {
  9849. tmp = tmp.nextSibling;
  9850. result++;
  9851. }
  9852. }
  9853. return result;
  9854. };
  9855. var stopEditing = null;
  9856. var stopWrapper = function(evt)
  9857. {
  9858. var source = mxEvent.getSource(evt);
  9859. if (source.getAttribute('contentEditable') != 'true' && stopEditing != null)
  9860. {
  9861. stopEditing();
  9862. stopEditing = null;
  9863. mxEvent.consume(evt);
  9864. }
  9865. };
  9866. mxEvent.addListener(div, 'mousedown', stopWrapper);
  9867. mxEvent.addListener(div, 'pointerdown', stopWrapper);
  9868. mxEvent.addListener(div, 'touchstart', stopWrapper);
  9869. // For converting image URLs
  9870. var converter = new mxUrlConverter();
  9871. var errorShowed = false;
  9872. function addButton(data, mimeType, x, y, w, h, img, aspect, title)
  9873. {
  9874. // Ignores duplicates
  9875. try
  9876. {
  9877. editorUi.spinner.stop();
  9878. if (mimeType == null || mimeType.substring(0, 6) == 'image/')
  9879. {
  9880. if ((data == null && img != null) || entries[data] == null)
  9881. {
  9882. div.style.backgroundImage = '';
  9883. bg.style.display = 'none';
  9884. var iw = w;
  9885. var ih = h;
  9886. if (w > editorUi.maxImageSize || h > editorUi.maxImageSize)
  9887. {
  9888. var s = Math.min(1, Math.min(editorUi.maxImageSize / Math.max(1, w)),
  9889. editorUi.maxImageSize / Math.max(1, h));
  9890. w *= s;
  9891. h *= s;
  9892. }
  9893. if (iw > ih)
  9894. {
  9895. ih = Math.round(ih * ew / iw);
  9896. iw = ew;
  9897. }
  9898. else
  9899. {
  9900. iw = Math.round(iw * eh / ih);
  9901. ih = eh;
  9902. }
  9903. var wrapper = document.createElement('div');
  9904. wrapper.setAttribute('draggable', 'true');
  9905. wrapper.style.display = 'inline-block';
  9906. wrapper.style.position = 'relative';
  9907. wrapper.style.padding = '0 12px';
  9908. wrapper.style.cursor = 'move';
  9909. mxUtils.setPrefixedStyle(wrapper.style, 'transition', 'transform .1s ease-in-out');
  9910. if (data != null)
  9911. {
  9912. var elt = document.createElement('img');
  9913. elt.setAttribute('src', converter.convert(data));
  9914. elt.style.width = iw + 'px';
  9915. elt.style.height = ih + 'px';
  9916. elt.style.margin = '10px';
  9917. elt.style.paddingBottom = Math.floor((eh - ih) / 2) + 'px';
  9918. elt.style.paddingLeft = Math.floor((ew - iw) / 2) + 'px';
  9919. wrapper.appendChild(elt);
  9920. }
  9921. else if (img != null)
  9922. {
  9923. var cells = editorUi.stringToCells((img.xml.charAt(0) == '<') ?
  9924. img.xml : Graph.decompress(img.xml));
  9925. if (cells.length > 0)
  9926. {
  9927. editorUi.sidebar.createThumb(cells, ew, eh, wrapper, null,
  9928. true, false, null, null, (Editor.isDarkMode()) ?
  9929. '#2a252f' : '#ffffff');
  9930. // Needs inline block on SVG for delete icon to appear on same line
  9931. wrapper.firstChild.style.display = 'inline-block';
  9932. wrapper.firstChild.style.cursor = '';
  9933. }
  9934. }
  9935. var rem = document.createElement('img');
  9936. rem.setAttribute('src', Editor.closeBlackImage);
  9937. rem.setAttribute('border', '0');
  9938. rem.setAttribute('title', mxResources.get('delete'));
  9939. rem.setAttribute('align', 'top');
  9940. rem.style.paddingTop = '4px';
  9941. rem.style.position = 'absolute';
  9942. rem.style.marginLeft = '-12px';
  9943. rem.style.zIndex = '1';
  9944. rem.style.cursor = 'pointer';
  9945. // Blocks dragging of remove icon
  9946. mxEvent.addListener(rem, 'dragstart', function(evt)
  9947. {
  9948. mxEvent.consume(evt);
  9949. });
  9950. (function(wrapperDiv, dataParam, imgParam)
  9951. {
  9952. mxEvent.addListener(rem, 'click', function(evt)
  9953. {
  9954. entries[dataParam] = null;
  9955. for (var i = 0; i < images.length; i++)
  9956. {
  9957. if ((images[i].data != null && images[i].data == dataParam) ||
  9958. (images[i].xml != null && imgParam != null &&
  9959. images[i].xml == imgParam.xml))
  9960. {
  9961. images.splice(i, 1);
  9962. break;
  9963. }
  9964. }
  9965. wrapper.parentNode.removeChild(wrapperDiv);
  9966. if (images.length == 0)
  9967. {
  9968. div.style.backgroundImage = 'url(\'' + IMAGE_PATH + '/droptarget.png\')';
  9969. bg.style.display = '';
  9970. }
  9971. mxEvent.consume(evt);
  9972. });
  9973. // Workaround for accidental select all
  9974. mxEvent.addListener(rem, 'dblclick', function(evt)
  9975. {
  9976. mxEvent.consume(evt);
  9977. });
  9978. })(wrapper, data, img);
  9979. wrapper.appendChild(rem);
  9980. wrapper.style.marginBottom = '30px';
  9981. var label = document.createElement('div');
  9982. label.style.position = 'absolute';
  9983. label.style.boxSizing = 'border-box';
  9984. label.style.bottom = '-18px';
  9985. label.style.left = '10px';
  9986. label.style.right = '10px';
  9987. label.style.backgroundColor = Editor.isDarkMode() ?
  9988. 'transparent' : '#ffffff';
  9989. label.style.overflow = 'hidden';
  9990. label.style.textAlign = 'center';
  9991. label.setAttribute('title', mxResources.get('rename'));
  9992. var entry = null;
  9993. if (data != null)
  9994. {
  9995. entry = {data: data, w: w, h: h, title: title};
  9996. if (aspect != null)
  9997. {
  9998. entry.aspect = aspect;
  9999. }
  10000. entries[data] = elt;
  10001. images.push(entry);
  10002. }
  10003. else if (img != null)
  10004. {
  10005. img.aspect = 'fixed';
  10006. images.push(img);
  10007. entry = img;
  10008. }
  10009. function updateLabel()
  10010. {
  10011. label.innerText = '';
  10012. label.style.cursor = 'pointer';
  10013. label.style.whiteSpace = 'nowrap';
  10014. label.style.textOverflow = 'ellipsis';
  10015. mxUtils.write(label, (entry.title != null && entry.title.length > 0) ?
  10016. entry.title : mxResources.get('untitled'));
  10017. if (entry.title == null || entry.title.length == 0)
  10018. {
  10019. label.style.color = '#d0d0d0';
  10020. }
  10021. else
  10022. {
  10023. label.style.color = '';
  10024. }
  10025. };
  10026. mxEvent.addListener(label, 'keydown', function(evt)
  10027. {
  10028. if (evt.keyCode == 13 && stopEditing != null)
  10029. {
  10030. stopEditing();
  10031. stopEditing = null;
  10032. mxEvent.consume(evt);
  10033. }
  10034. });
  10035. updateLabel();
  10036. wrapper.appendChild(label);
  10037. // Blocks dragging of label
  10038. mxEvent.addListener(label, 'mousedown', function(evt)
  10039. {
  10040. if (label.getAttribute('contentEditable') != 'true')
  10041. {
  10042. mxEvent.consume(evt);
  10043. }
  10044. });
  10045. var startEditing = function(evt)
  10046. {
  10047. // Workaround for various issues in IE
  10048. if (!mxClient.IS_IOS && !mxClient.IS_FF &&
  10049. (document.documentMode == null || document.documentMode > 9))
  10050. {
  10051. if (label.getAttribute('contentEditable') != 'true')
  10052. {
  10053. if (stopEditing != null)
  10054. {
  10055. stopEditing();
  10056. stopEditing = null;
  10057. }
  10058. if (entry.title == null || entry.title.length == 0)
  10059. {
  10060. label.innerText = '';
  10061. }
  10062. label.style.textOverflow = '';
  10063. label.style.whiteSpace = '';
  10064. label.style.cursor = 'text';
  10065. label.style.color = '';
  10066. label.setAttribute('contentEditable', 'true');
  10067. mxUtils.setPrefixedStyle(label.style, 'user-select', 'text');
  10068. label.focus();
  10069. document.execCommand('selectAll', false, null);
  10070. stopEditing = function()
  10071. {
  10072. label.removeAttribute('contentEditable');
  10073. label.style.cursor = 'pointer';
  10074. entry.title = label.innerHTML;
  10075. updateLabel();
  10076. }
  10077. mxEvent.consume(evt);
  10078. }
  10079. }
  10080. else
  10081. {
  10082. var dlg = new FilenameDialog(editorUi, entry.title || '',
  10083. mxResources.get('ok'), function(newTitle)
  10084. {
  10085. if (newTitle != null)
  10086. {
  10087. entry.title = newTitle;
  10088. updateLabel();
  10089. }
  10090. }, mxResources.get('enterValue'));
  10091. editorUi.showDialog(dlg.container, 300, 80, true, true);
  10092. dlg.init();
  10093. mxEvent.consume(evt);
  10094. }
  10095. };
  10096. mxEvent.addListener(label, 'click', startEditing);
  10097. mxEvent.addListener(wrapper, 'dblclick', startEditing);
  10098. div.appendChild(wrapper);
  10099. mxEvent.addListener(wrapper, 'dragstart', function(evt)
  10100. {
  10101. if (stopEditing != null)
  10102. {
  10103. return;
  10104. }
  10105. if (data == null && img != null)
  10106. {
  10107. rem.style.visibility = 'hidden';
  10108. label.style.visibility = 'hidden';
  10109. }
  10110. // Workaround for no DnD on DIV in FF
  10111. if (mxClient.IS_FF && img.xml != null)
  10112. {
  10113. evt.dataTransfer.setData('Text', img.xml);
  10114. }
  10115. dragSourceIndex = getIndexForEvent(evt);
  10116. // Workaround for missing drag preview in Google Chrome
  10117. if (mxClient.IS_GC)
  10118. {
  10119. wrapper.style.opacity = '0.9';
  10120. }
  10121. window.setTimeout(function()
  10122. {
  10123. mxUtils.setPrefixedStyle(wrapper.style, 'transform', 'scale(0.5,0.5)');
  10124. mxUtils.setOpacity(wrapper, 30);
  10125. rem.style.visibility = '';
  10126. label.style.visibility = '';
  10127. }, 0);
  10128. });
  10129. mxEvent.addListener(wrapper, 'dragend', function(evt)
  10130. {
  10131. if (rem.style.visibility == 'hidden')
  10132. {
  10133. rem.style.visibility = '';
  10134. label.style.visibility = '';
  10135. }
  10136. dragSourceIndex = null;
  10137. mxUtils.setOpacity(wrapper, 100);
  10138. mxUtils.setPrefixedStyle(wrapper.style, 'transform', null);
  10139. });
  10140. }
  10141. else if (!errorShowed)
  10142. {
  10143. errorShowed = true;
  10144. editorUi.handleError({message: mxResources.get('fileExists')})
  10145. }
  10146. }
  10147. else
  10148. {
  10149. var done = false;
  10150. try
  10151. {
  10152. var doc = mxUtils.parseXml(data);
  10153. if (doc.documentElement.nodeName == 'mxlibrary')
  10154. {
  10155. var temp = JSON.parse(mxUtils.getTextContent(doc.documentElement));
  10156. if (temp != null && temp.length > 0)
  10157. {
  10158. for (var i = 0; i < temp.length; i++)
  10159. {
  10160. if (temp[i].xml != null)
  10161. {
  10162. addButton(null, null, 0, 0, 0, 0, temp[i]);
  10163. }
  10164. else
  10165. {
  10166. addButton(temp[i].data, null, 0, 0, temp[i].w, temp[i].h, null, 'fixed', temp[i].title);
  10167. }
  10168. }
  10169. }
  10170. done = true;
  10171. }
  10172. else if (doc.documentElement.nodeName == 'mxfile')
  10173. {
  10174. var pages = doc.documentElement.getElementsByTagName('diagram');
  10175. for (var i = 0; i < pages.length; i++)
  10176. {
  10177. var xml = Editor.getDiagramNodeXml(pages[i]);
  10178. var cells = editorUi.stringToCells(xml);
  10179. if (cells.length > 0)
  10180. {
  10181. var size = editorUi.editor.graph.getBoundingBoxFromGeometry(cells);
  10182. if (size != null)
  10183. {
  10184. addButton(null, null, 0, 0, 0, 0, {xml: xml, w: size.width, h: size.height});
  10185. }
  10186. }
  10187. }
  10188. done = true;
  10189. }
  10190. }
  10191. catch (e)
  10192. {
  10193. if (window.console != null)
  10194. {
  10195. console.error('Error in library dialog: ' + e);
  10196. }
  10197. }
  10198. if (!done)
  10199. {
  10200. editorUi.spinner.stop();
  10201. editorUi.handleError({message: mxResources.get('errorLoadingFile')})
  10202. }
  10203. }
  10204. }
  10205. catch (e)
  10206. {
  10207. if (window.console != null)
  10208. {
  10209. console.log('Error in library dialog: ' + e);
  10210. }
  10211. }
  10212. return null;
  10213. };
  10214. if (initialImages != null)
  10215. {
  10216. for (var i = 0; i < initialImages.length; i++)
  10217. {
  10218. var img = initialImages[i];
  10219. addButton(img.data, null, 0, 0, img.w, img.h, img, img.aspect, img.title);
  10220. }
  10221. }
  10222. // Setup the dnd listeners
  10223. mxEvent.addListener(div, 'dragleave', function(evt)
  10224. {
  10225. bg.style.cursor = '';
  10226. var source = mxEvent.getSource(evt);
  10227. while (source != null)
  10228. {
  10229. if (source == div || source == bg)
  10230. {
  10231. evt.stopPropagation();
  10232. evt.preventDefault();
  10233. break;
  10234. }
  10235. source = source.parentNode;
  10236. }
  10237. });
  10238. function dragOver(evt)
  10239. {
  10240. evt.dataTransfer.dropEffect = (dragSourceIndex != null) ? 'move' : 'copy';
  10241. evt.stopPropagation();
  10242. evt.preventDefault();
  10243. };
  10244. var createImportHandler = function(evt)
  10245. {
  10246. return function(data, mimeType, x, y, w, h, img, doneFn, file)
  10247. {
  10248. if (file != null && EditorUi.isVisioFilename(file.name))
  10249. {
  10250. editorUi.importVisio(file, mxUtils.bind(this, function(xml)
  10251. {
  10252. addButton(xml, mimeType, x, y, w, h, img, 'fixed', (mxEvent.isAltDown(evt)) ?
  10253. null : img.substring(0, img.lastIndexOf('.')).replace(/_/g, ' '));
  10254. }));
  10255. }
  10256. else if (file != null && new XMLHttpRequest().upload && editorUi.isRemoteFileFormat(data, file.name))
  10257. {
  10258. if (editorUi.isExternalDataComms())
  10259. {
  10260. editorUi.parseFile(file, mxUtils.bind(this, function(xhr)
  10261. {
  10262. if (xhr.readyState == 4)
  10263. {
  10264. editorUi.spinner.stop();
  10265. if (xhr.status >= 200 && xhr.status <= 299)
  10266. {
  10267. var xml = xhr.responseText;
  10268. addButton(xml, mimeType, x, y, w, h, img, 'fixed', (mxEvent.isAltDown(evt)) ?
  10269. null : img.substring(0, img.lastIndexOf('.')).replace(/_/g, ' '));
  10270. div.scrollTop = div.scrollHeight;
  10271. }
  10272. }
  10273. }));
  10274. }
  10275. else
  10276. {
  10277. editorUi.spinner.stop();
  10278. editorUi.showError(mxResources.get('error'), mxResources.get('notInOffline'));
  10279. }
  10280. }
  10281. else
  10282. {
  10283. addButton(data, mimeType, x, y, w, h, img, 'fixed', (mxEvent.isAltDown(evt)) ?
  10284. null : img.substring(0, img.lastIndexOf('.')).replace(/_/g, ' '));
  10285. div.scrollTop = div.scrollHeight;
  10286. }
  10287. };
  10288. };
  10289. function dropHandler(evt)
  10290. {
  10291. evt.stopPropagation();
  10292. evt.preventDefault();
  10293. errorShowed = false;
  10294. dropTargetIndex = getIndexForEvent(evt);
  10295. if (dragSourceIndex != null)
  10296. {
  10297. if (dropTargetIndex != null && dropTargetIndex < div.children.length)
  10298. {
  10299. images.splice((dropTargetIndex > dragSourceIndex) ? dropTargetIndex - 1 : dropTargetIndex,
  10300. 0, images.splice(dragSourceIndex, 1)[0]);
  10301. div.insertBefore(div.children[dragSourceIndex], div.children[dropTargetIndex]);
  10302. }
  10303. else
  10304. {
  10305. images.push(images.splice(dragSourceIndex, 1)[0]);
  10306. div.appendChild(div.children[dragSourceIndex]);
  10307. }
  10308. }
  10309. else if (evt.dataTransfer.files.length > 0)
  10310. {
  10311. editorUi.importFiles(evt.dataTransfer.files, 0, 0, editorUi.maxImageSize, createImportHandler(evt));
  10312. }
  10313. else if (mxUtils.indexOf(evt.dataTransfer.types, 'text/uri-list') >= 0)
  10314. {
  10315. var uri = decodeURIComponent(evt.dataTransfer.getData('text/uri-list'));
  10316. if (/(\.jpg)($|\?)/i.test(uri) || /(\.png)($|\?)/i.test(uri) ||
  10317. /(\.gif)($|\?)/i.test(uri) || /(\.svg)($|\?)/i.test(uri))
  10318. {
  10319. editorUi.loadImage(uri, function(img)
  10320. {
  10321. addButton(uri, null, 0, 0, img.width, img.height);
  10322. div.scrollTop = div.scrollHeight;
  10323. });
  10324. }
  10325. }
  10326. evt.stopPropagation();
  10327. evt.preventDefault();
  10328. };
  10329. mxEvent.addListener(div, 'dragover', dragOver);
  10330. mxEvent.addListener(div, 'drop', dropHandler);
  10331. mxEvent.addListener(bg, 'dragover', dragOver);
  10332. mxEvent.addListener(bg, 'drop', dropHandler);
  10333. outer.appendChild(div);
  10334. var btns = document.createElement('div');
  10335. btns.style.textAlign = 'right';
  10336. btns.style.marginTop = '20px';
  10337. var cancelBtn = mxUtils.button(mxResources.get('cancel'), function()
  10338. {
  10339. editorUi.hideDialog(true);
  10340. });
  10341. cancelBtn.setAttribute('id', 'btnCancel');
  10342. cancelBtn.className = 'geBtn';
  10343. if (editorUi.editor.cancelFirst)
  10344. {
  10345. btns.appendChild(cancelBtn);
  10346. }
  10347. if (editorUi.getServiceName() == 'draw.io' && file != null &&
  10348. // Limits button to ibraries which are known to have public URLs
  10349. (file.constructor == DriveLibrary || file.constructor == GitHubLibrary))
  10350. {
  10351. var btn = mxUtils.button(mxResources.get('link'), function()
  10352. {
  10353. editorUi.getPublicUrl(file, function(url)
  10354. {
  10355. if (url != null)
  10356. {
  10357. var search = editorUi.getSearch(['create', 'title', 'mode', 'url', 'drive', 'splash', 'state', 'clibs', 'ui']);
  10358. search += ((search.length == 0) ? '?' : '&') + 'splash=0&clibs=U' + encodeURIComponent(url);
  10359. var dlg = new EmbedDialog(editorUi, window.location.protocol + '//' +
  10360. window.location.host + '/' + search, null, null, null, null,
  10361. 'Check out the library I made using @drawio');
  10362. editorUi.showDialog(dlg.container, 450, 240, true);
  10363. dlg.init();
  10364. }
  10365. else if (file.constructor == DriveLibrary)
  10366. {
  10367. editorUi.showError(mxResources.get('error'), mxResources.get('diagramIsNotPublic'),
  10368. mxResources.get('share'), mxUtils.bind(this, function()
  10369. {
  10370. editorUi.drive.showPermissions(file.getId(), file);
  10371. }), null, mxResources.get('ok'), mxUtils.bind(this, function()
  10372. {
  10373. // Hides dialog
  10374. })
  10375. );
  10376. }
  10377. else
  10378. {
  10379. editorUi.handleError({message: mxResources.get('diagramIsNotPublic')});
  10380. }
  10381. });
  10382. });
  10383. btn.className = 'geBtn';
  10384. btns.appendChild(btn);
  10385. }
  10386. var btn = mxUtils.button(mxResources.get('export'), function()
  10387. {
  10388. var data = editorUi.createLibraryDataFromImages(images);
  10389. var filename = nameInput.value;
  10390. if (!/(\.xml)$/i.test(filename))
  10391. {
  10392. filename += '.xml';
  10393. }
  10394. if (editorUi.isLocalFileSave())
  10395. {
  10396. editorUi.saveLocalFile(data, filename, 'text/xml', null, null, allowBrowser != null? allowBrowser : true, null, 'xml');
  10397. }
  10398. else
  10399. {
  10400. new mxXmlRequest(SAVE_URL, 'filename=' + encodeURIComponent(filename) +
  10401. '&format=xml&xml=' + encodeURIComponent(data)).simulate(document, '_blank');
  10402. }
  10403. });
  10404. btn.setAttribute('id', 'btnDownload');
  10405. btn.className = 'geBtn';
  10406. btns.appendChild(btn);
  10407. if (Graph.fileSupport)
  10408. {
  10409. if (editorUi.libDlgFileInputElt == null)
  10410. {
  10411. var fileInput = document.createElement('input');
  10412. fileInput.setAttribute('multiple', 'multiple');
  10413. fileInput.setAttribute('type', 'file');
  10414. mxEvent.addListener(fileInput, 'change', function(evt)
  10415. {
  10416. errorShowed = false;
  10417. editorUi.importFiles(fileInput.files, 0, 0, editorUi.maxImageSize, function(data, mimeType, x, y, w, h, img, doneFn, file)
  10418. {
  10419. if (fileInput.files != null)
  10420. {
  10421. createImportHandler(evt)(data, mimeType, x, y, w, h, img, doneFn, file);
  10422. // Resets input to force change event for same file (type reset required for IE)
  10423. fileInput.type = '';
  10424. fileInput.type = 'file';
  10425. fileInput.value = '';
  10426. }
  10427. });
  10428. div.scrollTop = div.scrollHeight;
  10429. });
  10430. fileInput.style.display = 'none';
  10431. document.body.appendChild(fileInput);
  10432. editorUi.libDlgFileInputElt = fileInput;
  10433. }
  10434. var btn = mxUtils.button(mxResources.get('import'), function()
  10435. {
  10436. if (stopEditing != null)
  10437. {
  10438. stopEditing();
  10439. stopEditing = null;
  10440. }
  10441. editorUi.libDlgFileInputElt.click();
  10442. });
  10443. btn.setAttribute('id', 'btnAddImage');
  10444. btn.className = 'geBtn';
  10445. btns.appendChild(btn);
  10446. }
  10447. var btn = mxUtils.button(mxResources.get('addImages'), function()
  10448. {
  10449. if (stopEditing != null)
  10450. {
  10451. stopEditing();
  10452. stopEditing = null;
  10453. }
  10454. editorUi.showImageDialog(mxResources.get('addImageUrl'), '', function(url, w, h)
  10455. {
  10456. errorShowed = false;
  10457. if (url != null)
  10458. {
  10459. // Image dialog returns modified data URLs which
  10460. // must be converted back to real data URL
  10461. if (url.substring(0, 11) == 'data:image/')
  10462. {
  10463. var comma = url.indexOf(',');
  10464. if (comma > 0)
  10465. {
  10466. url = url.substring(0, comma) + ';base64,' + url.substring(comma + 1);
  10467. }
  10468. }
  10469. addButton(url, null, 0, 0, w, h);
  10470. div.scrollTop = div.scrollHeight;
  10471. }
  10472. });
  10473. });
  10474. btn.setAttribute('id', 'btnAddImageUrl');
  10475. btn.className = 'geBtn';
  10476. btns.appendChild(btn);
  10477. // Indirection for overriding
  10478. this.saveBtnClickHandler = function(name, images, file, mode)
  10479. {
  10480. editorUi.saveLibrary(name, images, file, mode);
  10481. };
  10482. var btn = mxUtils.button(mxResources.get('save'),mxUtils.bind(this, function()
  10483. {
  10484. if (stopEditing != null)
  10485. {
  10486. stopEditing();
  10487. stopEditing = null;
  10488. }
  10489. this.saveBtnClickHandler(nameInput.value, images, file, mode);
  10490. }));
  10491. btn.setAttribute('id', 'btnSave');
  10492. btn.className = 'geBtn gePrimaryBtn';
  10493. btns.appendChild(btn);
  10494. if (!editorUi.editor.cancelFirst)
  10495. {
  10496. btns.appendChild(cancelBtn);
  10497. }
  10498. outer.appendChild(btns);
  10499. this.container = outer;
  10500. };
  10501. /**
  10502. * Constructs a new textarea dialog.
  10503. */
  10504. var EditShapeDialog = function(editorUi, cell, title, w, h)
  10505. {
  10506. w = (w != null) ? w : 300;
  10507. h = (h != null) ? h : 120;
  10508. var row, td;
  10509. var table = document.createElement('table');
  10510. var tbody = document.createElement('tbody');
  10511. table.style.cellPadding = '4px';
  10512. row = document.createElement('tr');
  10513. td = document.createElement('td');
  10514. td.setAttribute('colspan', '2');
  10515. td.style.fontSize = '10pt';
  10516. mxUtils.write(td, title);
  10517. row.appendChild(td);
  10518. tbody.appendChild(row);
  10519. row = document.createElement('tr');
  10520. td = document.createElement('td');
  10521. var nameInput = document.createElement('textarea');
  10522. nameInput.style.outline = 'none';
  10523. nameInput.style.resize = 'none';
  10524. nameInput.style.width = (w - 200) + 'px';
  10525. nameInput.style.height = h + 'px';
  10526. this.textarea = nameInput;
  10527. this.init = function()
  10528. {
  10529. nameInput.focus();
  10530. nameInput.scrollTop = 0;
  10531. };
  10532. td.appendChild(nameInput);
  10533. row.appendChild(td);
  10534. td = document.createElement('td');
  10535. var container = document.createElement('div');
  10536. container.style.position = 'relative';
  10537. container.style.border = '1px solid gray';
  10538. container.style.top = '6px';
  10539. container.style.width = '200px';
  10540. container.style.height = (h + 4) + 'px';
  10541. container.style.overflow = 'hidden';
  10542. container.style.marginBottom = '16px';
  10543. mxEvent.disableContextMenu(container);
  10544. td.appendChild(container);
  10545. var graph = new Graph(container);
  10546. graph.setEnabled(false);
  10547. var clone = editorUi.editor.graph.cloneCell(cell);
  10548. graph.addCells([clone]);
  10549. var state = graph.view.getState(clone);
  10550. var stencil = '';
  10551. if (state.shape != null && state.shape.stencil != null)
  10552. {
  10553. stencil = mxUtils.getPrettyXml(state.shape.stencil.desc);
  10554. }
  10555. mxUtils.write(nameInput, stencil || '');
  10556. var b = graph.getGraphBounds();
  10557. var ns = Math.min((200 - 40) / b.width, (h - 40) / b.height);
  10558. graph.view.scaleAndTranslate(ns, 20 / ns - b.x, 20 / ns - b.y);
  10559. row.appendChild(td);
  10560. tbody.appendChild(row);
  10561. row = document.createElement('tr');
  10562. td = document.createElement('td');
  10563. td.setAttribute('colspan', '2');
  10564. td.style.paddingTop = '2px';
  10565. td.style.whiteSpace = 'nowrap';
  10566. td.setAttribute('align', 'right');
  10567. if (!editorUi.isOffline())
  10568. {
  10569. var helpBtn = mxUtils.button(mxResources.get('help'), function()
  10570. {
  10571. editorUi.openLink('https://www.drawio.com/doc/faq/shape-complex-create-edit');
  10572. });
  10573. helpBtn.className = 'geBtn';
  10574. td.appendChild(helpBtn);
  10575. }
  10576. var cancelBtn = mxUtils.button(mxResources.get('cancel'), function()
  10577. {
  10578. editorUi.hideDialog();
  10579. });
  10580. cancelBtn.className = 'geBtn';
  10581. if (editorUi.editor.cancelFirst)
  10582. {
  10583. td.appendChild(cancelBtn);
  10584. }
  10585. var updateShape = function(targetGraph, targetCell, hide)
  10586. {
  10587. var newValue = nameInput.value;
  10588. // Checks if XML has changed (getPrettyXml "normalizes" DOM)
  10589. var doc = mxUtils.parseXml(newValue);
  10590. newValue = mxUtils.getPrettyXml(doc.documentElement);
  10591. // Checks for validation errors
  10592. // LATER: Validate against XSD
  10593. var errors = doc.documentElement.getElementsByTagName('parsererror');
  10594. if (errors != null && errors.length > 0)
  10595. {
  10596. editorUi.showError(mxResources.get('error'), mxResources.get('containsValidationErrors'), mxResources.get('ok'));
  10597. }
  10598. else
  10599. {
  10600. if (hide)
  10601. {
  10602. editorUi.hideDialog();
  10603. }
  10604. var isNew = !targetGraph.model.contains(targetCell);
  10605. if (!hide || isNew || newValue != stencil)
  10606. {
  10607. // Transform XML value to be used in cell style
  10608. newValue = Graph.compress(newValue);
  10609. targetGraph.getModel().beginUpdate();
  10610. try
  10611. {
  10612. // Inserts cell if required
  10613. if (isNew)
  10614. {
  10615. var pt = editorUi.editor.graph.getFreeInsertPoint();
  10616. targetCell.geometry.x = pt.x;
  10617. targetCell.geometry.y = pt.y;
  10618. targetGraph.addCell(targetCell)
  10619. }
  10620. targetGraph.setCellStyles(mxConstants.STYLE_SHAPE, 'stencil(' + newValue + ')', [targetCell]);
  10621. }
  10622. catch (e)
  10623. {
  10624. throw e;
  10625. }
  10626. finally
  10627. {
  10628. // Updates the display
  10629. targetGraph.getModel().endUpdate();
  10630. }
  10631. // Updates selection after stencil was created for rendering
  10632. if (isNew)
  10633. {
  10634. targetGraph.setSelectionCell(targetCell);
  10635. targetGraph.scrollCellToVisible(targetCell);
  10636. }
  10637. }
  10638. }
  10639. };
  10640. var previewBtn = mxUtils.button(mxResources.get('preview'), function()
  10641. {
  10642. updateShape(graph, clone, false);
  10643. });
  10644. previewBtn.className = 'geBtn';
  10645. td.appendChild(previewBtn);
  10646. var applyBtn = mxUtils.button(mxResources.get('apply'), function()
  10647. {
  10648. updateShape(editorUi.editor.graph, cell, true);
  10649. });
  10650. applyBtn.className = 'geBtn gePrimaryBtn';
  10651. td.appendChild(applyBtn);
  10652. if (!editorUi.editor.cancelFirst)
  10653. {
  10654. td.appendChild(cancelBtn);
  10655. }
  10656. row.appendChild(td);
  10657. tbody.appendChild(row);
  10658. table.appendChild(tbody);
  10659. this.container = table;
  10660. };
  10661. var CustomDialog = function(editorUi, content, okFn, cancelFn, okButtonText, helpLink,
  10662. buttonsContent, hideCancel, cancelButtonText, hideAfterOKFn, customButtons,
  10663. marginTop)
  10664. {
  10665. var div = document.createElement('div');
  10666. div.appendChild(content);
  10667. var btns = document.createElement('div');
  10668. btns.style.marginTop = (marginTop != null) ? marginTop : '30px';
  10669. btns.style.textAlign = 'right';
  10670. if (buttonsContent != null)
  10671. {
  10672. btns.appendChild(buttonsContent);
  10673. }
  10674. if (!editorUi.isOffline() && helpLink != null)
  10675. {
  10676. btns.appendChild(editorUi.createHelpIcon(helpLink));
  10677. }
  10678. var cancelBtn = mxUtils.button(cancelButtonText || mxResources.get('cancel'), function()
  10679. {
  10680. editorUi.hideDialog();
  10681. if (cancelFn != null)
  10682. {
  10683. cancelFn();
  10684. }
  10685. });
  10686. cancelBtn.className = 'geBtn';
  10687. if (hideCancel)
  10688. {
  10689. cancelBtn.style.display = 'none';
  10690. }
  10691. if (editorUi.editor.cancelFirst)
  10692. {
  10693. btns.appendChild(cancelBtn);
  10694. }
  10695. var okBtn = mxUtils.button(okButtonText || mxResources.get('ok'), mxUtils.bind(this, function()
  10696. {
  10697. if (!hideAfterOKFn)
  10698. {
  10699. editorUi.hideDialog(null, null, this.container);
  10700. }
  10701. if (okFn != null)
  10702. {
  10703. var okRet = okFn();
  10704. if (typeof okRet === 'string')
  10705. {
  10706. editorUi.showError(mxResources.get('error'), okRet);
  10707. return;
  10708. }
  10709. }
  10710. if (hideAfterOKFn)
  10711. {
  10712. editorUi.hideDialog(null, null, this.container);
  10713. }
  10714. }));
  10715. btns.appendChild(okBtn);
  10716. okBtn.className = 'geBtn gePrimaryBtn';
  10717. if (!editorUi.editor.cancelFirst)
  10718. {
  10719. btns.appendChild(cancelBtn);
  10720. }
  10721. if (customButtons != null)
  10722. {
  10723. for (var i = 0; i < customButtons.length; i++)
  10724. {
  10725. (function(label, fn, title)
  10726. {
  10727. var customBtn = mxUtils.button(label, function(e)
  10728. {
  10729. fn(e);
  10730. });
  10731. if (title != null)
  10732. {
  10733. customBtn.setAttribute('title', title);
  10734. }
  10735. customBtn.className = 'geBtn';
  10736. btns.appendChild(customBtn);
  10737. })(customButtons[i][0], customButtons[i][1], customButtons[i][2]);
  10738. }
  10739. }
  10740. div.appendChild(btns);
  10741. this.cancelBtn = cancelBtn;
  10742. this.okButton = okBtn;
  10743. this.container = div;
  10744. };
  10745. /**
  10746. * Constructs a new popup opener button dialog.
  10747. */
  10748. var BtnDialog = function(editorUi, peer, btnLbl, fn)
  10749. {
  10750. var div = document.createElement('div');
  10751. div.style.textAlign = 'center';
  10752. var hd = document.createElement('p');
  10753. hd.style.fontSize = '16pt';
  10754. hd.style.padding = '0px';
  10755. hd.style.margin = '0px';
  10756. hd.style.color = 'gray';
  10757. mxUtils.write(hd, mxResources.get('done'));
  10758. var service = 'Unknown';
  10759. var img = document.createElement('img');
  10760. img.setAttribute('border', '0');
  10761. img.setAttribute('align', 'absmiddle');
  10762. img.style.marginRight = '10px';
  10763. if (peer == editorUi.drive)
  10764. {
  10765. service = mxResources.get('googleDrive');
  10766. img.src = IMAGE_PATH + '/google-drive-logo-white.svg';
  10767. }
  10768. else if (peer == editorUi.dropbox)
  10769. {
  10770. service = mxResources.get('dropbox');
  10771. img.src = IMAGE_PATH + '/dropbox-logo-white.svg';
  10772. }
  10773. else if (peer == editorUi.oneDrive)
  10774. {
  10775. service = mxResources.get('oneDrive');
  10776. img.src = IMAGE_PATH + '/onedrive-logo-white.svg';
  10777. }
  10778. else if (peer == editorUi.gitHub)
  10779. {
  10780. service = mxResources.get('github');
  10781. img.src = IMAGE_PATH + '/github-logo-white.svg';
  10782. }
  10783. else if (peer == editorUi.gitLab)
  10784. {
  10785. service = mxResources.get('gitlab');
  10786. img.src = IMAGE_PATH + '/gitlab-logo.svg';
  10787. }
  10788. else if (peer == editorUi.trello)
  10789. {
  10790. service = mxResources.get('trello');
  10791. img.src = IMAGE_PATH + '/trello-logo-white.svg';
  10792. }
  10793. var p = document.createElement('p');
  10794. mxUtils.write(p, mxResources.get('authorizedIn', [service], 'You are now authorized in {1}'));
  10795. var button = mxUtils.button(btnLbl, fn);
  10796. button.insertBefore(img, button.firstChild);
  10797. button.style.marginTop = '6px';
  10798. button.className = 'geBigButton';
  10799. button.style.fontSize = '18px';
  10800. button.style.padding = '14px';
  10801. div.appendChild(hd);
  10802. div.appendChild(p);
  10803. div.appendChild(button);
  10804. this.container = div;
  10805. };
  10806. /**
  10807. * Constructs a new font dialog.
  10808. */
  10809. var FontDialog = function(editorUi, curFontname, curUrl, curType, fn)
  10810. {
  10811. var row, td, label;
  10812. var table = document.createElement('table');
  10813. var tbody = document.createElement('tbody');
  10814. table.style.marginTop = '8px';
  10815. //System fonts section
  10816. row = document.createElement('tr');
  10817. td = document.createElement('td');
  10818. td.colSpan = 2;
  10819. td.style.whiteSpace = 'nowrap';
  10820. td.style.fontSize = '10pt';
  10821. td.style.fontWeight = 'bold';
  10822. var sysFontRadio = document.createElement('input');
  10823. sysFontRadio.style.cssText = 'margin-right:8px;margin-bottom:8px;';
  10824. sysFontRadio.setAttribute('value', 'sysfonts');
  10825. sysFontRadio.setAttribute('type', 'radio');
  10826. sysFontRadio.setAttribute('name', 'current-fontdialog');
  10827. sysFontRadio.setAttribute('id', 'fontdialog-sysfonts');
  10828. td.appendChild(sysFontRadio);
  10829. label = document.createElement('label');
  10830. label.setAttribute('for', 'fontdialog-sysfonts');
  10831. mxUtils.write(label, (mxResources.get('sysFonts', null, 'System Fonts')));
  10832. td.appendChild(label);
  10833. row.appendChild(td);
  10834. tbody.appendChild(row);
  10835. row = document.createElement('tr');
  10836. td = document.createElement('td');
  10837. td.style.whiteSpace = 'nowrap';
  10838. td.style.fontSize = '10pt';
  10839. td.style.width = '120px';
  10840. td.style.paddingLeft = '15px';
  10841. mxUtils.write(td, (mxResources.get('fontname', null, 'Font Name')) + ':');
  10842. row.appendChild(td);
  10843. var sysFontInput = document.createElement('input');
  10844. if (curType == 's')
  10845. {
  10846. sysFontInput.setAttribute('value', curFontname);
  10847. }
  10848. sysFontInput.style.marginLeft = '4px';
  10849. sysFontInput.style.width = '250px';
  10850. sysFontInput.className = 'dlg_fontName_s';
  10851. td = document.createElement('td');
  10852. td.appendChild(sysFontInput);
  10853. row.appendChild(td);
  10854. tbody.appendChild(row);
  10855. //Google fonts section
  10856. row = document.createElement('tr');
  10857. td = document.createElement('td');
  10858. td.colSpan = 2;
  10859. td.style.whiteSpace = 'nowrap';
  10860. td.style.fontSize = '10pt';
  10861. td.style.fontWeight = 'bold';
  10862. var googleFontRadio = document.createElement('input');
  10863. googleFontRadio.style.cssText = 'margin-right:8px;margin-bottom:8px;';
  10864. googleFontRadio.setAttribute('value', 'googlefonts');
  10865. googleFontRadio.setAttribute('type', 'radio');
  10866. googleFontRadio.setAttribute('name', 'current-fontdialog');
  10867. googleFontRadio.setAttribute('id', 'fontdialog-googlefonts');
  10868. td.appendChild(googleFontRadio);
  10869. label = document.createElement('label');
  10870. label.setAttribute('for', 'fontdialog-googlefonts');
  10871. mxUtils.write(label, (mxResources.get('googleFonts', null, 'Google Fonts')));
  10872. td.appendChild(label);
  10873. // Link to Google Fonts
  10874. if (!editorUi.isOffline() || EditorUi.isElectronApp)
  10875. {
  10876. var link = editorUi.createHelpIcon('https://fonts.google.com/');
  10877. td.appendChild(link);
  10878. }
  10879. row.appendChild(td);
  10880. if (urlParams['isGoogleFontsEnabled'] != '0')
  10881. {
  10882. tbody.appendChild(row);
  10883. }
  10884. row = document.createElement('tr');
  10885. td = document.createElement('td');
  10886. td.style.whiteSpace = 'nowrap';
  10887. td.style.fontSize = '10pt';
  10888. td.style.width = '120px';
  10889. td.style.paddingLeft = '15px';
  10890. mxUtils.write(td, (mxResources.get('fontname', null, 'Font Name')) + ':');
  10891. row.appendChild(td);
  10892. var googleFontInput = document.createElement('input');
  10893. if (curType == 'g')
  10894. {
  10895. googleFontInput.setAttribute('value', curFontname);
  10896. }
  10897. googleFontInput.style.marginLeft = '4px';
  10898. googleFontInput.style.width = '250px';
  10899. googleFontInput.className = 'dlg_fontName_g';
  10900. td = document.createElement('td');
  10901. td.appendChild(googleFontInput);
  10902. row.appendChild(td);
  10903. if (urlParams['isGoogleFontsEnabled'] != '0')
  10904. {
  10905. tbody.appendChild(row);
  10906. }
  10907. //Generic remote fonts section
  10908. row = document.createElement('tr');
  10909. td = document.createElement('td');
  10910. td.colSpan = 2;
  10911. td.style.whiteSpace = 'nowrap';
  10912. td.style.fontSize = '10pt';
  10913. td.style.fontWeight = 'bold';
  10914. var webFontRadio = document.createElement('input');
  10915. webFontRadio.style.cssText = 'margin-right:8px;margin-bottom:8px;';
  10916. webFontRadio.setAttribute('value', 'webfonts');
  10917. webFontRadio.setAttribute('type', 'radio');
  10918. webFontRadio.setAttribute('name', 'current-fontdialog');
  10919. webFontRadio.setAttribute('id', 'fontdialog-webfonts');
  10920. td.appendChild(webFontRadio);
  10921. label = document.createElement('label');
  10922. label.setAttribute('for', 'fontdialog-webfonts');
  10923. mxUtils.write(label, (mxResources.get('webfonts', null, 'Web Fonts')));
  10924. td.appendChild(label);
  10925. row.appendChild(td);
  10926. if (Editor.enableWebFonts)
  10927. {
  10928. tbody.appendChild(row);
  10929. }
  10930. row = document.createElement('tr');
  10931. td = document.createElement('td');
  10932. td.style.whiteSpace = 'nowrap';
  10933. td.style.fontSize = '10pt';
  10934. td.style.width = '120px';
  10935. td.style.paddingLeft = '15px';
  10936. mxUtils.write(td, (mxResources.get('fontname', null, 'Font Name')) + ':');
  10937. row.appendChild(td);
  10938. var webFontInput = document.createElement('input');
  10939. if (curType == 'w')
  10940. {
  10941. if (Editor.enableWebFonts)
  10942. {
  10943. webFontInput.setAttribute('value', curFontname);
  10944. }
  10945. else
  10946. {
  10947. sysFontInput.setAttribute('value', curFontname);
  10948. }
  10949. }
  10950. webFontInput.style.marginLeft = '4px';
  10951. webFontInput.style.width = '250px';
  10952. webFontInput.className = 'dlg_fontName_w';
  10953. td = document.createElement('td');
  10954. td.appendChild(webFontInput);
  10955. row.appendChild(td);
  10956. if (Editor.enableWebFonts)
  10957. {
  10958. tbody.appendChild(row);
  10959. }
  10960. row = document.createElement('tr');
  10961. td = document.createElement('td');
  10962. td.style.whiteSpace = 'nowrap';
  10963. td.style.fontSize = '10pt';
  10964. td.style.width = '120px';
  10965. td.style.paddingLeft = '15px';
  10966. mxUtils.write(td, (mxResources.get('fontUrl', null, 'Font URL')) + ':');
  10967. row.appendChild(td);
  10968. var webFontUrlInput = document.createElement('input');
  10969. webFontUrlInput.setAttribute('value', curUrl || '');
  10970. webFontUrlInput.style.marginLeft = '4px';
  10971. webFontUrlInput.style.width = '250px';
  10972. webFontUrlInput.className = 'dlg_fontUrl';
  10973. td = document.createElement('td');
  10974. td.appendChild(webFontUrlInput);
  10975. row.appendChild(td);
  10976. if (Editor.enableWebFonts)
  10977. {
  10978. tbody.appendChild(row);
  10979. }
  10980. this.init = function()
  10981. {
  10982. var input = sysFontInput;
  10983. if (curType == 'g')
  10984. {
  10985. input = googleFontInput;
  10986. }
  10987. else if (curType == 'w' && Editor.enableWebFonts)
  10988. {
  10989. input = webFontInput;
  10990. }
  10991. input.focus();
  10992. if (mxClient.IS_GC || mxClient.IS_FF || document.documentMode >= 5)
  10993. {
  10994. input.select();
  10995. }
  10996. else
  10997. {
  10998. document.execCommand('selectAll', false, null);
  10999. }
  11000. };
  11001. row = document.createElement('tr');
  11002. td = document.createElement('td');
  11003. td.colSpan = 2;
  11004. td.style.paddingTop = '20px';
  11005. td.style.whiteSpace = 'nowrap';
  11006. td.setAttribute('align', 'right');
  11007. if (!editorUi.isOffline())
  11008. {
  11009. td.appendChild(editorUi.createHelpIcon('https://www.drawio.com/blog/external-fonts'));
  11010. }
  11011. var cancelBtn = mxUtils.button(mxResources.get('cancel'), function()
  11012. {
  11013. editorUi.hideDialog();
  11014. fn();
  11015. });
  11016. cancelBtn.className = 'geBtn';
  11017. if (editorUi.editor.cancelFirst)
  11018. {
  11019. td.appendChild(cancelBtn);
  11020. }
  11021. function validateFn(fontName, fontUrl, type)
  11022. {
  11023. var urlPattern = /(ftp|http|https):\/\/(\w+:{0,1}\w*@)?(\S+)(:[0-9]+)?(\/|\/([\w#!:.?+=&%@!\-\/]))?/;
  11024. var elt = table.querySelector('.dlg_fontName_' + type);
  11025. if (elt != null && (fontName == null || fontName.length == 0))
  11026. {
  11027. elt.style.border = '1px solid red';
  11028. return false;
  11029. }
  11030. elt = table.querySelector('.dlg_fontUrl');
  11031. if (elt != null && type == 'w' && !urlPattern.test(fontUrl))
  11032. {
  11033. elt.style.border = '1px solid red';
  11034. return false;
  11035. }
  11036. return true;
  11037. };
  11038. var okBtn = mxUtils.button(mxResources.get('apply'), function()
  11039. {
  11040. var fontName, fontUrl, type;
  11041. if (sysFontRadio.checked)
  11042. {
  11043. fontName = sysFontInput.value;
  11044. type = 's';
  11045. }
  11046. else if (googleFontRadio.checked)
  11047. {
  11048. fontName = googleFontInput.value;
  11049. fontUrl = Editor.GOOGLE_FONTS + encodeURIComponent(fontName).replace(/%20/g, '+');
  11050. type = 'g';
  11051. }
  11052. else if (webFontRadio.checked)
  11053. {
  11054. fontName = webFontInput.value;
  11055. fontUrl = webFontUrlInput.value;
  11056. type = 'w';
  11057. }
  11058. if (validateFn(fontName, fontUrl, type))
  11059. {
  11060. fn(fontName, fontUrl, type);
  11061. editorUi.hideDialog();
  11062. }
  11063. });
  11064. okBtn.className = 'geBtn gePrimaryBtn';
  11065. function enterSubmit(e)
  11066. {
  11067. this.style.border = '';
  11068. if (e.keyCode == 13)
  11069. {
  11070. okBtn.click();
  11071. }
  11072. };
  11073. mxEvent.addListener(sysFontInput, 'keypress', enterSubmit);
  11074. mxEvent.addListener(googleFontInput, 'keypress', enterSubmit);
  11075. mxEvent.addListener(webFontInput, 'keypress', enterSubmit);
  11076. mxEvent.addListener(webFontUrlInput, 'keypress', enterSubmit);
  11077. mxEvent.addListener(sysFontInput, 'focus', function()
  11078. {
  11079. sysFontRadio.setAttribute('checked', 'checked');
  11080. sysFontRadio.checked = true;
  11081. });
  11082. mxEvent.addListener(googleFontInput, 'focus', function()
  11083. {
  11084. googleFontRadio.setAttribute('checked', 'checked');
  11085. googleFontRadio.checked = true;
  11086. });
  11087. mxEvent.addListener(webFontInput, 'focus', function()
  11088. {
  11089. webFontRadio.setAttribute('checked', 'checked');
  11090. webFontRadio.checked = true;
  11091. });
  11092. mxEvent.addListener(webFontUrlInput, 'focus', function()
  11093. {
  11094. webFontRadio.setAttribute('checked', 'checked');
  11095. webFontRadio.checked = true;
  11096. });
  11097. td.appendChild(okBtn);
  11098. if (!editorUi.editor.cancelFirst)
  11099. {
  11100. td.appendChild(cancelBtn);
  11101. }
  11102. row.appendChild(td);
  11103. tbody.appendChild(row);
  11104. table.appendChild(tbody);
  11105. this.container = table;
  11106. };
  11107. /* Aspect Dialog
  11108. * @module drawio/aspect-dialog
  11109. */
  11110. function AspectDialog(editorUi, pageId, layerIds, okFn, cancelFn)
  11111. {
  11112. this.aspect = {pageId : pageId || (editorUi.pages? editorUi.pages[0].getId() : null), layerIds : layerIds || []};
  11113. var div = document.createElement('div');
  11114. var title = document.createElement('h5');
  11115. title.style.margin = '0 0 10px';
  11116. mxUtils.write(title, mxResources.get('pages'));
  11117. div.appendChild(title);
  11118. var pagesContainer = document.createElement('div');
  11119. pagesContainer.className = 'geAspectDlgList';
  11120. div.appendChild(pagesContainer);
  11121. title = document.createElement('h5');
  11122. title.style.margin = '0 0 10px';
  11123. mxUtils.write(title, mxResources.get('layers'));
  11124. div.appendChild(title);
  11125. var layersContainer = document.createElement('div');
  11126. layersContainer.className = 'geAspectDlgList';
  11127. div.appendChild(layersContainer);
  11128. this.pagesContainer = pagesContainer;
  11129. this.layersContainer = layersContainer;
  11130. this.ui = editorUi;
  11131. var btns = document.createElement('div');
  11132. btns.style.marginTop = '16px';
  11133. btns.style.textAlign = 'center';
  11134. var cancelBtn = mxUtils.button(mxResources.get('cancel'), function()
  11135. {
  11136. editorUi.hideDialog();
  11137. if (cancelFn != null)
  11138. {
  11139. cancelFn();
  11140. }
  11141. });
  11142. cancelBtn.className = 'geBtn';
  11143. if (editorUi.editor.cancelFirst)
  11144. {
  11145. btns.appendChild(cancelBtn);
  11146. }
  11147. var okBtn = mxUtils.button(mxResources.get('ok'), mxUtils.bind(this, function()
  11148. {
  11149. editorUi.hideDialog();
  11150. okFn({pageId: this.selectedPage, layerIds: Object.keys(this.selectedLayers)});
  11151. }));
  11152. btns.appendChild(okBtn);
  11153. okBtn.className = 'geBtn gePrimaryBtn';
  11154. if (!editorUi.editor.cancelFirst)
  11155. {
  11156. btns.appendChild(cancelBtn);
  11157. }
  11158. okBtn.setAttribute('disabled', 'disabled');
  11159. this.okBtn = okBtn;
  11160. div.appendChild(btns);
  11161. this.container = div;
  11162. };
  11163. //Drawing the graph with dialog not visible doesn't get dimensions right. It has to be visible!
  11164. AspectDialog.prototype.init = function()
  11165. {
  11166. var xml = this.ui.getFileData(true); //Force pages to update their nodes
  11167. if (this.ui.pages)
  11168. {
  11169. for (var i = 0; i < this.ui.pages.length; i++)
  11170. {
  11171. var page = this.ui.updatePageRoot(this.ui.pages[i]);
  11172. this.createPageItem(page.getId(), page.getName(), page.node);
  11173. }
  11174. }
  11175. else
  11176. {
  11177. this.createPageItem('1', 'Page-1', mxUtils.parseXml(xml).documentElement);
  11178. }
  11179. };
  11180. AspectDialog.prototype.createViewer = function(container, pageNode, layerId, defaultBackground)
  11181. {
  11182. mxEvent.disableContextMenu(container);
  11183. container.style.userSelect = 'none';
  11184. var graph = new Graph(container);
  11185. graph.setTooltips(false);
  11186. graph.setEnabled(false);
  11187. graph.setPanning(false);
  11188. graph.minFitScale = null;
  11189. graph.maxFitScale = null;
  11190. graph.centerZoom = true;
  11191. var node = pageNode.nodeName == 'mxGraphModel'? pageNode : Editor.parseDiagramNode(pageNode); //Handles compressed and non-compressed page node
  11192. if (node != null)
  11193. {
  11194. var bg = node.getAttribute('background');
  11195. if (bg == null || bg == '' || bg == mxConstants.NONE)
  11196. {
  11197. bg = (defaultBackground != null) ? defaultBackground : '#ffffff';
  11198. }
  11199. container.style.backgroundColor = bg;
  11200. var codec = new mxCodec(node.ownerDocument);
  11201. var model = graph.getModel();
  11202. codec.decode(node, model);
  11203. var childCount = model.getChildCount(model.root);
  11204. var showAll = layerId == null;
  11205. // handle layers visibility
  11206. for (var i = 0; i < childCount; i++)
  11207. {
  11208. var child = model.getChildAt(model.root, i);
  11209. model.setVisible(child, showAll || layerId == child.id);
  11210. }
  11211. graph.maxFitScale = 1;
  11212. graph.fit(0);
  11213. graph.center();
  11214. }
  11215. return graph;
  11216. };
  11217. AspectDialog.prototype.createPageItem = function(pageId, pageName, pageNode)
  11218. {
  11219. var $listItem = document.createElement('div');
  11220. $listItem.className = 'geAspectDlgListItem';
  11221. $listItem.setAttribute('data-page-id', pageId)
  11222. $listItem.innerHTML = '<div style="max-width: 100%; max-height: 100%;"></div><div class="geAspectDlgListItemText">' + mxUtils.htmlEntities(pageName) + '</div>';
  11223. this.pagesContainer.appendChild($listItem);
  11224. var graph = this.createViewer($listItem.childNodes[0], pageNode);
  11225. var onClick = mxUtils.bind(this, function()
  11226. {
  11227. if (this.selectedItem != null)
  11228. {
  11229. this.selectedItem.className = 'geAspectDlgListItem';
  11230. }
  11231. this.selectedItem = $listItem;
  11232. this.selectedPage = pageId;
  11233. $listItem.className += ' geAspectDlgListItemSelected';
  11234. this.layersContainer.innerText = '';
  11235. this.selectedLayers = {};
  11236. this.okBtn.setAttribute('disabled', 'disabled');
  11237. var graphModel = graph.model;
  11238. var layers = graphModel.getChildCells(graphModel.getRoot());
  11239. for (var i = 0; i < layers.length; i++)
  11240. {
  11241. this.createLayerItem(layers[i], pageId, graph, pageNode);
  11242. }
  11243. });
  11244. mxEvent.addListener($listItem, 'click', onClick);
  11245. if(this.aspect.pageId == pageId)
  11246. {
  11247. onClick();
  11248. }
  11249. };
  11250. AspectDialog.prototype.createLayerItem = function(layer, pageId, graph, pageNode)
  11251. {
  11252. var layerName = graph.convertValueToString(layer) || (mxResources.get('background') || 'Background');
  11253. var $listItem = document.createElement('div');
  11254. $listItem.setAttribute('data-layer-id', layer.id);
  11255. $listItem.className = 'geAspectDlgListItem';
  11256. $listItem.innerHTML = '<div style="max-width: 100%; max-height: 100%;"></div><div class="geAspectDlgListItemText">' + mxUtils.htmlEntities(layerName) + '</div>';
  11257. this.layersContainer.appendChild($listItem);
  11258. this.createViewer($listItem.childNodes[0], pageNode, layer.id);
  11259. var onClick = mxUtils.bind(this, function()
  11260. {
  11261. if ($listItem.className.indexOf('geAspectDlgListItemSelected') >= 0) //Selected
  11262. {
  11263. $listItem.className = 'geAspectDlgListItem';
  11264. delete this.selectedLayers[layer.id];
  11265. if (mxUtils.isEmptyObject(this.selectedLayers))
  11266. {
  11267. this.okBtn.setAttribute('disabled', 'disabled');
  11268. }
  11269. }
  11270. else
  11271. {
  11272. $listItem.className += ' geAspectDlgListItemSelected';
  11273. this.selectedLayers[layer.id] = true;
  11274. this.okBtn.removeAttribute('disabled');
  11275. }
  11276. });
  11277. mxEvent.addListener($listItem, 'click', onClick);
  11278. if(this.aspect.layerIds.indexOf(layer.id) != -1)
  11279. {
  11280. onClick();
  11281. }
  11282. };
  11283. /**
  11284. * Constructs a new page setup dialog.
  11285. */
  11286. var FilePropertiesDialog = function(editorUi, publicLink)
  11287. {
  11288. var row, td;
  11289. var table = document.createElement('table');
  11290. var tbody = document.createElement('tbody');
  11291. table.style.width = '100%';
  11292. table.style.marginTop = '8px';
  11293. table.style.tableLayout = 'fixed';
  11294. var file = editorUi.getCurrentFile();
  11295. var filename = (file != null && file.getTitle() != null) ?
  11296. file.getTitle() : editorUi.defaultFilename;
  11297. var isPng = /(\.png)$/i.test(filename);
  11298. var isSvg = /(\.svg)$/i.test(filename);
  11299. var apply = function(success, error)
  11300. {
  11301. success();
  11302. };
  11303. function addApply(fn)
  11304. {
  11305. var prevApply = apply;
  11306. apply = function(success, error)
  11307. {
  11308. try
  11309. {
  11310. fn(function()
  11311. {
  11312. prevApply(success, error);
  11313. }, error);
  11314. }
  11315. catch (e)
  11316. {
  11317. error(e);
  11318. }
  11319. };
  11320. };
  11321. var initialLocked = (file != null) ? file.isLocked() : false;
  11322. row = document.createElement('tr');
  11323. td = document.createElement('td');
  11324. td.style.whiteSpace = 'nowrap';
  11325. td.style.overflow = 'hidden';
  11326. td.style.textOverflow = 'ellipsis';
  11327. td.style.fontSize = '10pt';
  11328. mxUtils.write(td, mxResources.get('locked') + ':');
  11329. row.appendChild(td);
  11330. var lockedInput = document.createElement('input');
  11331. lockedInput.setAttribute('type', 'checkbox');
  11332. if (initialLocked)
  11333. {
  11334. lockedInput.setAttribute('checked', 'checked');
  11335. lockedInput.defaultChecked = true;
  11336. }
  11337. td = document.createElement('td');
  11338. td.style.whiteSpace = 'nowrap';
  11339. td.appendChild(lockedInput);
  11340. row.appendChild(td);
  11341. tbody.appendChild(row);
  11342. this.init = function()
  11343. {
  11344. lockedInput.focus();
  11345. };
  11346. addApply(function(success, error)
  11347. {
  11348. if (editorUi.fileNode != null && initialLocked != lockedInput.checked)
  11349. {
  11350. window.setTimeout(function()
  11351. {
  11352. if (file != null)
  11353. {
  11354. file.setLocked(lockedInput.checked);
  11355. }
  11356. success();
  11357. }, 0);
  11358. }
  11359. else
  11360. {
  11361. success();
  11362. }
  11363. });
  11364. if (isPng || isSvg)
  11365. {
  11366. var scale = 1;
  11367. var border = 0;
  11368. var node = editorUi.fileNode;
  11369. if (node != null)
  11370. {
  11371. if (node.hasAttribute('scale'))
  11372. {
  11373. scale = parseFloat(node.getAttribute('scale'));
  11374. }
  11375. if (node.hasAttribute('border'))
  11376. {
  11377. border = parseInt(node.getAttribute('border'));
  11378. }
  11379. }
  11380. row = document.createElement('tr');
  11381. td = document.createElement('td');
  11382. td.style.whiteSpace = 'nowrap';
  11383. td.style.fontSize = '10pt';
  11384. mxUtils.write(td, mxResources.get('zoom') + ':');
  11385. row.appendChild(td);
  11386. var zoomInput = document.createElement('input');
  11387. zoomInput.setAttribute('value', (scale * 100) + '%');
  11388. zoomInput.style.marginLeft = '4px';
  11389. zoomInput.style.width = '100%';
  11390. td = document.createElement('td');
  11391. td.style.whiteSpace = 'nowrap';
  11392. td.appendChild(zoomInput);
  11393. row.appendChild(td);
  11394. tbody.appendChild(row);
  11395. row = document.createElement('tr');
  11396. td = document.createElement('td');
  11397. td.style.whiteSpace = 'nowrap';
  11398. td.style.fontSize = '10pt';
  11399. mxUtils.write(td, mxResources.get('borderWidth') + ':');
  11400. row.appendChild(td);
  11401. var borderInput = document.createElement('input');
  11402. borderInput.setAttribute('value', border);
  11403. borderInput.style.marginLeft = '4px';
  11404. borderInput.style.width = '100%';
  11405. td = document.createElement('td');
  11406. td.style.whiteSpace = 'nowrap';
  11407. td.appendChild(borderInput);
  11408. row.appendChild(td);
  11409. tbody.appendChild(row);
  11410. this.init = this.init || function()
  11411. {
  11412. zoomInput.focus();
  11413. if (mxClient.IS_GC || mxClient.IS_FF || document.documentMode >= 5)
  11414. {
  11415. zoomInput.select();
  11416. }
  11417. else
  11418. {
  11419. document.execCommand('selectAll', false, null);
  11420. }
  11421. };
  11422. addApply(function(success, error)
  11423. {
  11424. if (editorUi.fileNode != null)
  11425. {
  11426. editorUi.fileNode.setAttribute('scale', Math.max(0, parseInt(zoomInput.value) / 100));
  11427. editorUi.fileNode.setAttribute('border', Math.max(0, parseInt(borderInput.value)));
  11428. if (file != null)
  11429. {
  11430. file.fileChanged();
  11431. }
  11432. }
  11433. success();
  11434. });
  11435. }
  11436. else if (!/(\.html)$/i.test(filename) &&
  11437. !/(\.svg)$/i.test(filename))
  11438. {
  11439. var initialCompressed = (file != null) ? file.isCompressed() : Editor.defaultCompressed;
  11440. row = document.createElement('tr');
  11441. td = document.createElement('td');
  11442. td.style.whiteSpace = 'nowrap';
  11443. td.style.overflow = 'hidden';
  11444. td.style.textOverflow = 'ellipsis';
  11445. td.style.fontSize = '10pt';
  11446. mxUtils.write(td, mxResources.get('compressed') + ':');
  11447. row.appendChild(td);
  11448. var compressedInput = document.createElement('input');
  11449. compressedInput.setAttribute('type', 'checkbox');
  11450. if (initialCompressed)
  11451. {
  11452. compressedInput.setAttribute('checked', 'checked');
  11453. compressedInput.defaultChecked = true;
  11454. }
  11455. td = document.createElement('td');
  11456. td.style.whiteSpace = 'nowrap';
  11457. td.appendChild(compressedInput);
  11458. row.appendChild(td);
  11459. tbody.appendChild(row);
  11460. this.init = this.init || function()
  11461. {
  11462. compressedInput.focus();
  11463. };
  11464. addApply(function(success, error)
  11465. {
  11466. if (editorUi.fileNode != null && initialCompressed != compressedInput.checked)
  11467. {
  11468. window.setTimeout(function()
  11469. {
  11470. editorUi.fileNode.setAttribute('compressed',
  11471. (compressedInput.checked) ? 'true' : 'false');
  11472. if (file != null)
  11473. {
  11474. file.compressionChanged(compressedInput.checked);
  11475. file.fileChanged();
  11476. }
  11477. success();
  11478. }, 0);
  11479. }
  11480. else
  11481. {
  11482. success();
  11483. }
  11484. });
  11485. }
  11486. if (file != null && file.isRealtimeOptional())
  11487. {
  11488. row = document.createElement('tr');
  11489. td = document.createElement('td');
  11490. td.style.whiteSpace = 'nowrap';
  11491. td.style.overflow = 'hidden';
  11492. td.style.textOverflow = 'ellipsis';
  11493. td.style.fontSize = '10pt';
  11494. mxUtils.write(td, mxResources.get('realtimeCollaboration') + ':');
  11495. row.appendChild(td);
  11496. var collabInput = document.createElement('input');
  11497. collabInput.setAttribute('type', 'checkbox');
  11498. var initialCollab = file.isRealtimeEnabled();
  11499. var collab = editorUi.drive.getCustomProperty(file.desc, 'collaboration');
  11500. var initialCollab = collab != 'disabled';
  11501. if (initialCollab)
  11502. {
  11503. collabInput.setAttribute('checked', 'checked');
  11504. collabInput.defaultChecked = true;
  11505. }
  11506. addApply(function(success, error)
  11507. {
  11508. if (collabInput.checked != initialCollab)
  11509. {
  11510. file.setRealtimeEnabled(collabInput.checked, success, error);
  11511. }
  11512. else
  11513. {
  11514. success();
  11515. }
  11516. });
  11517. this.init = (this.init != null) ? this.init : function()
  11518. {
  11519. collabInput.focus();
  11520. };
  11521. td = document.createElement('td');
  11522. td.style.whiteSpace = 'nowrap';
  11523. td.appendChild(collabInput);
  11524. td.appendChild(editorUi.menus.createHelpLink('https://github.com/jgraph/drawio/discussions/2672'));
  11525. row.appendChild(td);
  11526. tbody.appendChild(row);
  11527. }
  11528. if (file != null && editorUi.getServiceName() == 'draw.io' &&
  11529. file.getSize() > 0 && urlParams['embed'] != '1')
  11530. {
  11531. row = document.createElement('tr');
  11532. td = document.createElement('td');
  11533. td.style.whiteSpace = 'nowrap';
  11534. td.style.overflow = 'hidden';
  11535. td.style.textOverflow = 'ellipsis';
  11536. td.style.fontSize = '10pt';
  11537. mxUtils.write(td, mxResources.get('size') + ':');
  11538. row.appendChild(td);
  11539. var temp = editorUi.formatFileSize(file.getSize());
  11540. var sizeInput = document.createElement('input');
  11541. sizeInput.setAttribute('title', temp);
  11542. sizeInput.setAttribute('value', temp);
  11543. sizeInput.setAttribute('disabled', 'disabled');
  11544. sizeInput.style.marginLeft = '4px';
  11545. sizeInput.style.width = '100%';
  11546. td = document.createElement('td');
  11547. td.style.whiteSpace = 'nowrap';
  11548. td.appendChild(sizeInput);
  11549. row.appendChild(td);
  11550. tbody.appendChild(row);
  11551. }
  11552. if (publicLink != null)
  11553. {
  11554. row = document.createElement('tr');
  11555. td = document.createElement('td');
  11556. td.style.whiteSpace = 'nowrap';
  11557. td.style.overflow = 'hidden';
  11558. td.style.textOverflow = 'ellipsis';
  11559. td.style.fontSize = '10pt';
  11560. mxUtils.write(td, mxResources.get('publicDiagramUrl') + ':');
  11561. row.appendChild(td);
  11562. var a = document.createElement('a');
  11563. a.setAttribute('href', publicLink);
  11564. a.setAttribute('title', publicLink);
  11565. a.style.whiteSpace = 'nowrap';
  11566. a.style.overflow = 'hidden';
  11567. a.style.textOverflow = 'ellipsis';
  11568. a.style.display = 'block';
  11569. a.style.margin = '2px 0px 2px 8px';
  11570. a.style.fontSize = '10pt';
  11571. mxUtils.write(a, publicLink);
  11572. mxEvent.addListener(a, 'click', function(evt)
  11573. {
  11574. editorUi.openLink(publicLink);
  11575. mxEvent.consume(evt);
  11576. });
  11577. td = document.createElement('td');
  11578. td.appendChild(a);
  11579. row.appendChild(td);
  11580. tbody.appendChild(row);
  11581. }
  11582. if (file != null && file.fileObject != null &&
  11583. file.fileObject.path != null)
  11584. {
  11585. row = document.createElement('tr');
  11586. td = document.createElement('td');
  11587. td.style.whiteSpace = 'nowrap';
  11588. td.style.overflow = 'hidden';
  11589. td.style.textOverflow = 'ellipsis';
  11590. td.style.fontSize = '10pt';
  11591. mxUtils.write(td, mxResources.get('pathFilename') + ':');
  11592. row.appendChild(td);
  11593. var pathInput = document.createElement('input');
  11594. pathInput.setAttribute('title', file.fileObject.path);
  11595. pathInput.setAttribute('value', file.fileObject.path);
  11596. pathInput.setAttribute('disabled', 'disabled');
  11597. pathInput.style.marginLeft = '4px';
  11598. pathInput.style.width = '100%';
  11599. td = document.createElement('td');
  11600. td.appendChild(pathInput);
  11601. row.appendChild(td);
  11602. tbody.appendChild(row);
  11603. }
  11604. this.init = (this.init != null) ? this.init : function() { };
  11605. var genericBtn = mxUtils.button(mxResources.get('apply'), function()
  11606. {
  11607. if (editorUi.spinner.spin(document.body, mxResources.get('updatingDocument')))
  11608. {
  11609. apply(function()
  11610. {
  11611. editorUi.spinner.stop();
  11612. editorUi.hideDialog();
  11613. }, function(e)
  11614. {
  11615. editorUi.spinner.stop();
  11616. editorUi.handleError(e, mxResources.get('error'));
  11617. });
  11618. }
  11619. });
  11620. genericBtn.className = 'geBtn gePrimaryBtn';
  11621. row = document.createElement('tr');
  11622. td = document.createElement('td');
  11623. td.colSpan = 2;
  11624. td.style.paddingTop = '20px';
  11625. td.style.whiteSpace = 'nowrap';
  11626. td.setAttribute('align', 'right');
  11627. var cancelBtn = mxUtils.button(mxResources.get('cancel'), function()
  11628. {
  11629. editorUi.hideDialog();
  11630. });
  11631. cancelBtn.className = 'geBtn';
  11632. if (editorUi.editor.cancelFirst)
  11633. {
  11634. td.appendChild(cancelBtn);
  11635. }
  11636. td.appendChild(genericBtn);
  11637. if (!editorUi.editor.cancelFirst)
  11638. {
  11639. td.appendChild(cancelBtn);
  11640. }
  11641. row.appendChild(td);
  11642. tbody.appendChild(row);
  11643. table.appendChild(tbody);
  11644. this.container = table;
  11645. };
  11646. var ConnectionPointsDialog = function(editorUi, cell)
  11647. {
  11648. var GRAPH_SIZE = 350, CP_SIZE = 6, CP_HLF_SIZE = 3;
  11649. var div = document.createElement('div');
  11650. div.style.userSelect = 'none';
  11651. var keyHandler = null;
  11652. this.init = function()
  11653. {
  11654. var graphDiv = document.createElement('div');
  11655. graphDiv.style.width = GRAPH_SIZE + 'px';
  11656. graphDiv.style.height = GRAPH_SIZE + 'px';
  11657. graphDiv.style.overflow = 'hidden';
  11658. graphDiv.style.border = '1px solid lightGray';
  11659. graphDiv.style.boxSizing = 'border-box';
  11660. mxEvent.disableContextMenu(graphDiv);
  11661. div.appendChild(graphDiv);
  11662. var editingGraph = new Graph(graphDiv);
  11663. editingGraph.transparentBackground = false;
  11664. editingGraph.autoExtend = false;
  11665. editingGraph.autoScroll = false;
  11666. editingGraph.setGridEnabled(false);
  11667. editingGraph.setEnabled(true);
  11668. editingGraph.setPanning(true);
  11669. editingGraph.setConnectable(false);
  11670. editingGraph.setTooltips(false);
  11671. editingGraph.minFitScale = null;
  11672. editingGraph.maxFitScale = null;
  11673. editingGraph.centerZoom = true;
  11674. editingGraph.maxFitScale = 2;
  11675. function createCPoint(x, y, constObj)
  11676. {
  11677. var cPointStyle = 'shape=mxgraph.basic.x;fillColor=#29b6f2;strokeColor=#29b6f2;points=[];rotatable=0;resizable=0;connectable=0;editable=0;';
  11678. var cPoint = new mxCell('', new mxGeometry(x, y, CP_SIZE, CP_SIZE), cPointStyle);
  11679. cPoint.vertex = true;
  11680. cPoint.cp = true;
  11681. cPoint.constObj = constObj;
  11682. return editingGraph.addCell(cPoint);
  11683. };
  11684. // Add cell and current connection points on it
  11685. var geo = cell.geometry;
  11686. var mainCell = new mxCell(cell.value, new mxGeometry(0, 0, geo.width, geo.height),
  11687. cell.style + ';rotatable=0;resizable=0;connectable=0;editable=0;movable=0;fillColor=none;');
  11688. mainCell.vertex = true;
  11689. editingGraph.addCell(mainCell);
  11690. // Adding a point via double click
  11691. editingGraph.dblClick = function(evt, cell)
  11692. {
  11693. if (cell != null && cell != mainCell)
  11694. {
  11695. editingGraph.setSelectionCell(cell);
  11696. }
  11697. else
  11698. {
  11699. var pt = mxUtils.convertPoint(editingGraph.container, mxEvent.getClientX(evt), mxEvent.getClientY(evt));
  11700. mxEvent.consume(evt);
  11701. var scale = editingGraph.view.scale;
  11702. var tr = editingGraph.view.translate;
  11703. editingGraph.setSelectionCell(createCPoint((pt.x - CP_HLF_SIZE * scale) / scale - tr.x,
  11704. (pt.y - CP_HLF_SIZE * scale) / scale - tr.y));
  11705. }
  11706. }
  11707. keyHandler = new mxKeyHandler(editingGraph);
  11708. function removeCPoints(evt)
  11709. {
  11710. var cells = editingGraph.getSelectionCells();
  11711. editingGraph.deleteCells(cells);
  11712. };
  11713. keyHandler.bindKey(46, removeCPoints);
  11714. keyHandler.bindKey(8, removeCPoints);
  11715. // Force rubberband inside the cell
  11716. editingGraph.getRubberband().isForceRubberbandEvent = function(event)
  11717. {
  11718. // Left click and not a click on a connection point
  11719. return event.evt.button == 0 &&
  11720. (event.getCell() == null ||
  11721. event.getCell() == mainCell);
  11722. };
  11723. // Force panning inside the cell
  11724. editingGraph.panningHandler.isForcePanningEvent = function(event)
  11725. {
  11726. return event.evt.button == 2;
  11727. };
  11728. var origIsCellSelectable = editingGraph.isCellSelectable;
  11729. editingGraph.isCellSelectable = function(cell)
  11730. {
  11731. if (cell == mainCell)
  11732. {
  11733. return false;
  11734. }
  11735. else
  11736. {
  11737. return origIsCellSelectable.apply(this, arguments);
  11738. }
  11739. };
  11740. // Disables hyperlinks
  11741. editingGraph.getLinkForCell = function()
  11742. {
  11743. return null;
  11744. };
  11745. var state = editingGraph.view.getState(mainCell);
  11746. var constraints = editingGraph.getAllConnectionConstraints(state);
  11747. for (var i = 0; constraints != null && i < constraints.length; i++)
  11748. {
  11749. var cp = editingGraph.getConnectionPoint(state, constraints[i]);
  11750. createCPoint(cp.x - CP_HLF_SIZE, cp.y - CP_HLF_SIZE, constraints[i]);
  11751. }
  11752. editingGraph.fit(8);
  11753. editingGraph.center();
  11754. var zoomInBtn = editorUi.createToolbarButton(Editor.zoomInImage,
  11755. mxResources.get('zoomIn'), function()
  11756. {
  11757. editingGraph.zoomIn();
  11758. }, 20);
  11759. var zoomOutBtn = editorUi.createToolbarButton(Editor.zoomOutImage,
  11760. mxResources.get('zoomOut'), function()
  11761. {
  11762. editingGraph.zoomOut();
  11763. }, 20);
  11764. var zoomFitBtn = editorUi.createToolbarButton(Editor.zoomFitImage,
  11765. mxResources.get('fit'), function()
  11766. {
  11767. if (editingGraph.view.scale == 1)
  11768. {
  11769. editingGraph.maxFitScale = 8;
  11770. editingGraph.fit(8);
  11771. }
  11772. else
  11773. {
  11774. editingGraph.zoomActual();
  11775. }
  11776. editingGraph.center();
  11777. }, 20);
  11778. var changeGridSize = function()
  11779. {
  11780. editorUi.prompt(mxResources.get('gridSize'), editingGraph.gridSize, function(newValue)
  11781. {
  11782. if (!isNaN(newValue) && newValue > 0)
  11783. {
  11784. editingGraph.setGridSize(newValue);
  11785. editingGraph.setGridEnabled(true);
  11786. editingGraph.refresh();
  11787. }
  11788. });
  11789. };
  11790. var gridBtn = editorUi.createToolbarButton(Editor.thinGridImage,
  11791. mxResources.get('grid'), function(evt)
  11792. {
  11793. if (mxEvent.isShiftDown(evt))
  11794. {
  11795. changeGridSize();
  11796. }
  11797. else
  11798. {
  11799. editingGraph.setGridEnabled(!editingGraph.isGridEnabled());
  11800. editingGraph.refresh();
  11801. }
  11802. }, 20);
  11803. mxEvent.addListener(gridBtn, 'dblclick', changeGridSize);
  11804. var deleteBtn = editorUi.createToolbarButton(Editor.trashImage,
  11805. mxResources.get('delete'), removeCPoints, 20);
  11806. mxUtils.setOpacity(deleteBtn, 10); //Disabled
  11807. var zoomBtns = document.createElement('div');
  11808. zoomBtns.style.display = 'flex';
  11809. zoomBtns.style.alignItems = 'center';
  11810. zoomBtns.style.paddingTop = '6px';
  11811. zoomBtns.appendChild(zoomInBtn);
  11812. zoomBtns.appendChild(zoomOutBtn);
  11813. zoomBtns.appendChild(zoomFitBtn);
  11814. zoomBtns.appendChild(gridBtn);
  11815. zoomBtns.appendChild(deleteBtn);
  11816. div.appendChild(zoomBtns);
  11817. var pCount = document.createElement('input');
  11818. pCount.setAttribute('type', 'number');
  11819. pCount.setAttribute('min', '1');
  11820. pCount.setAttribute('value', '1');
  11821. pCount.style.width = '45px';
  11822. pCount.style.position = 'relative';
  11823. pCount.style.margin = '0 4px 0 4px';
  11824. var sideSelect = document.createElement('select');
  11825. sideSelect.style.position = 'relative';
  11826. var sides = ['left', 'right', 'top', 'bottom'];
  11827. for (var i = 0; i < sides.length; i++)
  11828. {
  11829. var side = sides[i];
  11830. var option = document.createElement('option');
  11831. mxUtils.write(option, mxResources.get(side));
  11832. option.value = side;
  11833. sideSelect.appendChild(option);
  11834. }
  11835. var addBtn = mxUtils.button(mxResources.get('add'), function()
  11836. {
  11837. var count = parseInt(pCount.value);
  11838. count = count < 1? 1 : (count > 100? 100 : count);
  11839. pCount.value = count;
  11840. var side = sideSelect.value;
  11841. var geo = mainCell.geometry;
  11842. var cells = [];
  11843. for (var i = 0; i < count; i++)
  11844. {
  11845. var x, y;
  11846. switch(side)
  11847. {
  11848. case 'left':
  11849. x = geo.x;
  11850. y = geo.y + (i + 1) * geo.height / (count + 1);
  11851. break;
  11852. case 'right':
  11853. x = geo.x + geo.width;
  11854. y = geo.y + (i + 1) * geo.height / (count + 1);
  11855. break;
  11856. case 'top':
  11857. x = geo.x + (i + 1) * geo.width / (count + 1);
  11858. y = geo.y;
  11859. break;
  11860. case 'bottom':
  11861. x = geo.x + (i + 1) * geo.width / (count + 1);
  11862. y = geo.y + geo.height;
  11863. break;
  11864. }
  11865. cells.push(createCPoint(x - CP_HLF_SIZE, y - CP_HLF_SIZE));
  11866. }
  11867. editingGraph.setSelectionCells(cells);
  11868. });
  11869. addBtn.style.marginLeft = 'auto';
  11870. zoomBtns.appendChild(addBtn);
  11871. zoomBtns.appendChild(pCount);
  11872. zoomBtns.appendChild(sideSelect);
  11873. //Point properties
  11874. var pointPropsDiv = document.createElement('div');
  11875. pointPropsDiv.style.margin = '4px 0px 8px 0px';
  11876. pointPropsDiv.style.whiteSpace = 'nowrap';
  11877. pointPropsDiv.style.height = '24px';
  11878. var xSpan = document.createElement('span');
  11879. mxUtils.write(xSpan, mxResources.get('dx'));
  11880. pointPropsDiv.appendChild(xSpan);
  11881. var xInput = document.createElement('input');
  11882. xInput.setAttribute('type', 'number');
  11883. xInput.setAttribute('min', '0');
  11884. xInput.setAttribute('max', '100');
  11885. xInput.style.width = '45px';
  11886. xInput.style.margin = '0 4px 0 4px';
  11887. pointPropsDiv.appendChild(xInput);
  11888. mxUtils.write(pointPropsDiv, '%');
  11889. var dxInput = document.createElement('input');
  11890. dxInput.setAttribute('type', 'number');
  11891. dxInput.style.width = '45px';
  11892. dxInput.style.margin = '0 4px 0 4px';
  11893. pointPropsDiv.appendChild(dxInput);
  11894. mxUtils.write(pointPropsDiv, 'pt');
  11895. var ySpan = document.createElement('span');
  11896. mxUtils.write(ySpan, mxResources.get('dy'));
  11897. ySpan.style.marginLeft = '12px';
  11898. pointPropsDiv.appendChild(ySpan);
  11899. var yInput = document.createElement('input');
  11900. yInput.setAttribute('type', 'number');
  11901. yInput.setAttribute('min', '0');
  11902. yInput.setAttribute('max', '100');
  11903. yInput.style.width = '45px';
  11904. yInput.style.margin = '0 4px 0 4px';
  11905. pointPropsDiv.appendChild(yInput);
  11906. mxUtils.write(pointPropsDiv, '%');
  11907. var dyInput = document.createElement('input');
  11908. dyInput.setAttribute('type', 'number');
  11909. dyInput.style.width = '45px';
  11910. dyInput.style.margin = '0 4px 0 4px';
  11911. pointPropsDiv.appendChild(dyInput);
  11912. mxUtils.write(pointPropsDiv, 'pt');
  11913. div.appendChild(pointPropsDiv);
  11914. function applyPointProp()
  11915. {
  11916. var x = parseInt(xInput.value) || 0;
  11917. x = x < 0? 0 : (x > 100? 100 : x);
  11918. xInput.value = x;
  11919. var y = parseInt(yInput.value) || 0;
  11920. y = y < 0? 0 : (y > 100? 100 : y);
  11921. yInput.value = y;
  11922. var dx = parseInt(dxInput.value) || 0;
  11923. var dy = parseInt(dyInput.value) || 0;
  11924. var constObj = new mxConnectionConstraint(new mxPoint(x/100, y/100), false, null, dx, dy);
  11925. var cp = editingGraph.getConnectionPoint(state, constObj);
  11926. var cell = editingGraph.getSelectionCell();
  11927. if (cell != null)
  11928. {
  11929. cell.constObj = constObj;
  11930. var geo = cell.geometry.clone();
  11931. var scale = editingGraph.view.scale;
  11932. var tr = editingGraph.view.translate;
  11933. geo.x = (cp.x - CP_HLF_SIZE * scale) / scale - tr.x;
  11934. geo.y = (cp.y - CP_HLF_SIZE * scale) / scale - tr.y;
  11935. editingGraph.model.setGeometry(cell, geo);
  11936. }
  11937. };
  11938. function getConstraintFromCPoint(cp)
  11939. {
  11940. if (cp.constObj)
  11941. {
  11942. return {x: cp.constObj.point.x, y: cp.constObj.point.y, dx: cp.constObj.dx, dy: cp.constObj.dy};
  11943. }
  11944. var dx = 0, dy = 0, mGeo = mainCell.geometry;
  11945. var x = mxUtils.format((cp.geometry.x + CP_HLF_SIZE - mGeo.x) / mGeo.width);
  11946. var y = mxUtils.format((cp.geometry.y + CP_HLF_SIZE - mGeo.y) / mGeo.height);
  11947. if (x < 0)
  11948. {
  11949. dx = x * mGeo.width;
  11950. x = 0;
  11951. }
  11952. else if (x > 1)
  11953. {
  11954. dx = (x - 1) * mGeo.width;
  11955. x = 1;
  11956. }
  11957. if (y < 0)
  11958. {
  11959. dy = y * mGeo.height;
  11960. y = 0;
  11961. }
  11962. else if (y > 1)
  11963. {
  11964. dy = (y - 1) * mGeo.height;
  11965. y = 1;
  11966. }
  11967. return {x: x, y: y, dx: parseInt(dx), dy: parseInt(dy)};
  11968. };
  11969. function fillCPointProp(evt)
  11970. {
  11971. if (editingGraph.getSelectionCount() == 1)
  11972. {
  11973. var cell = editingGraph.getSelectionCell();
  11974. // On move events, exact constraint is lost
  11975. if (evt)
  11976. {
  11977. cell.constObj = null;
  11978. }
  11979. var constraint = getConstraintFromCPoint(cell);
  11980. xInput.value = constraint.x * 100;
  11981. yInput.value = constraint.y * 100;
  11982. dxInput.value = constraint.dx;
  11983. dyInput.value = constraint.dy;
  11984. pointPropsDiv.style.visibility = '';
  11985. }
  11986. else
  11987. {
  11988. pointPropsDiv.style.visibility = 'hidden';
  11989. }
  11990. };
  11991. fillCPointProp();
  11992. editingGraph.getSelectionModel().addListener(mxEvent.CHANGE, function()
  11993. {
  11994. if (editingGraph.getSelectionCount() > 0)
  11995. {
  11996. mxUtils.setOpacity(deleteBtn, 60); //Enabled
  11997. }
  11998. else
  11999. {
  12000. mxUtils.setOpacity(deleteBtn, 10); //Disabled
  12001. }
  12002. fillCPointProp();
  12003. });
  12004. editingGraph.addListener(mxEvent.CELLS_MOVED, fillCPointProp);
  12005. mxEvent.addListener(xInput, 'change', applyPointProp);
  12006. mxEvent.addListener(yInput, 'change', applyPointProp);
  12007. mxEvent.addListener(dxInput, 'change', applyPointProp);
  12008. mxEvent.addListener(dyInput, 'change', applyPointProp);
  12009. var cancelBtn = mxUtils.button(mxResources.get('cancel'), function()
  12010. {
  12011. destroy();
  12012. editorUi.hideDialog();
  12013. });
  12014. cancelBtn.className = 'geBtn';
  12015. var applyBtn = mxUtils.button(mxResources.get('apply'), function()
  12016. {
  12017. var cells = editingGraph.model.cells, points = [], constraints = [];
  12018. for (var id in cells)
  12019. {
  12020. var cp = cells[id];
  12021. if (!cp.cp) continue;
  12022. constraints.push(getConstraintFromCPoint(cp));
  12023. }
  12024. //Find and remove identical points
  12025. constraints.sort(function(a, b)
  12026. {
  12027. return (a.x != b.x) ? a.x - b.x : ((a.y != b.y) ? a.y - b.y :
  12028. ((a.dx != b.dx) ? a.dx - b.dx : a.dy - b.dy)); //Sort based on x then y, dx and dy
  12029. });
  12030. for (var i = 0; i < constraints.length; i++)
  12031. {
  12032. if (i > 0 && constraints[i].x == constraints[i - 1].x && constraints[i].y == constraints[i - 1].y
  12033. && constraints[i].dx == constraints[i - 1].dx && constraints[i].dy == constraints[i - 1].dy)
  12034. {
  12035. continue; //Skip this identical point
  12036. }
  12037. points.push('[' + constraints[i].x + ',' + constraints[i].y + ',0,' +
  12038. constraints[i].dx + ',' + constraints[i].dy + ']');
  12039. }
  12040. editorUi.editor.graph.setCellStyles('points', '[' + points.join(',') + ']', [cell]);
  12041. destroy();
  12042. editorUi.hideDialog();
  12043. });
  12044. applyBtn.className = 'geBtn gePrimaryBtn';
  12045. var resetBtn = mxUtils.button(mxResources.get('reset'), function()
  12046. {
  12047. editorUi.editor.graph.setCellStyles('points', null, [cell]);
  12048. destroy();
  12049. editorUi.hideDialog();
  12050. });
  12051. resetBtn.className = 'geBtn';
  12052. var buttons = document.createElement('div');
  12053. buttons.style.marginTop = '10px';
  12054. buttons.style.textAlign = 'right';
  12055. if (!editorUi.isOffline())
  12056. {
  12057. buttons.appendChild(editorUi.createHelpIcon(
  12058. 'https://www.drawio.com/doc/faq/shape-connection-points-customise'));
  12059. }
  12060. if (editorUi.editor.cancelFirst)
  12061. {
  12062. buttons.appendChild(cancelBtn);
  12063. }
  12064. buttons.appendChild(resetBtn);
  12065. buttons.appendChild(applyBtn);
  12066. if (!editorUi.editor.cancelFirst)
  12067. {
  12068. buttons.appendChild(cancelBtn);
  12069. }
  12070. div.appendChild(buttons);
  12071. };
  12072. function destroy()
  12073. {
  12074. if (keyHandler != null)
  12075. {
  12076. keyHandler.destroy();
  12077. }
  12078. };
  12079. this.destroy = destroy;
  12080. this.container = div;
  12081. };